2 * Copyright (c) 2009 Alexander Motin <mav@FreeBSD.org>
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer,
10 * without modification, immediately at the beginning of the file.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
15 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
16 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
17 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
18 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
19 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
20 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
21 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
22 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
24 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 #include <sys/cdefs.h>
28 __FBSDID("$FreeBSD$");
30 #include <sys/param.h>
32 #include <sys/endian.h>
33 #include <sys/systm.h>
34 #include <sys/types.h>
35 #include <sys/malloc.h>
36 #include <sys/kernel.h>
39 #include <sys/fcntl.h>
40 #include <sys/interrupt.h>
43 #include <sys/eventhandler.h>
45 #include <sys/mutex.h>
46 #include <sys/sysctl.h>
49 #include <cam/cam_ccb.h>
50 #include <cam/cam_queue.h>
51 #include <cam/cam_periph.h>
52 #include <cam/cam_sim.h>
53 #include <cam/cam_xpt.h>
54 #include <cam/cam_xpt_sim.h>
55 #include <cam/cam_xpt_periph.h>
56 #include <cam/cam_xpt_internal.h>
57 #include <cam/cam_debug.h>
59 #include <cam/scsi/scsi_all.h>
60 #include <cam/scsi/scsi_message.h>
61 #include <cam/ata/ata_all.h>
62 #include <machine/stdarg.h> /* for xpt_print below */
65 struct ata_quirk_entry {
66 struct scsi_inquiry_pattern inq_pat;
68 #define CAM_QUIRK_MAXTAGS 0x01
73 static periph_init_t probe_periph_init;
75 static struct periph_driver probe_driver =
77 probe_periph_init, "aprobe",
78 TAILQ_HEAD_INITIALIZER(probe_driver.units), /* generation */ 0,
82 PERIPHDRIVER_DECLARE(aprobe, probe_driver);
104 static char *probe_action_text[] = {
115 "PROBE_FULL_INQUIRY",
118 "PROBE_IDENTIFY_SES",
119 "PROBE_IDENTIFY_SAFTE",
124 #define PROBE_SET_ACTION(softc, newaction) \
127 text = probe_action_text; \
128 CAM_DEBUG((softc)->periph->path, CAM_DEBUG_PROBE, \
129 ("Probe %s to %s\n", text[(softc)->action], \
130 text[(newaction)])); \
131 (softc)->action = (newaction); \
135 PROBE_NO_ANNOUNCE = 0x04
139 TAILQ_HEAD(, ccb_hdr) request_ccbs;
140 struct ata_params ident_data;
149 struct cam_periph *periph;
152 static struct ata_quirk_entry ata_quirk_table[] =
155 /* Default tagged queuing parameters for all devices */
157 T_ANY, SIP_MEDIA_REMOVABLE|SIP_MEDIA_FIXED,
158 /*vendor*/"*", /*product*/"*", /*revision*/"*"
160 /*quirks*/0, /*mintags*/0, /*maxtags*/0
164 static const int ata_quirk_table_size =
165 sizeof(ata_quirk_table) / sizeof(*ata_quirk_table);
167 static cam_status proberegister(struct cam_periph *periph,
169 static void probeschedule(struct cam_periph *probe_periph);
170 static void probestart(struct cam_periph *periph, union ccb *start_ccb);
171 static void proberequestdefaultnegotiation(struct cam_periph *periph);
172 static void probedone(struct cam_periph *periph, union ccb *done_ccb);
173 static void probecleanup(struct cam_periph *periph);
174 static void ata_find_quirk(struct cam_ed *device);
175 static void ata_scan_bus(struct cam_periph *periph, union ccb *ccb);
176 static void ata_scan_lun(struct cam_periph *periph,
177 struct cam_path *path, cam_flags flags,
179 static void xptscandone(struct cam_periph *periph, union ccb *done_ccb);
180 static struct cam_ed *
181 ata_alloc_device(struct cam_eb *bus, struct cam_et *target,
183 static void ata_device_transport(struct cam_path *path);
184 static void ata_get_transfer_settings(struct ccb_trans_settings *cts);
185 static void ata_set_transfer_settings(struct ccb_trans_settings *cts,
186 struct cam_path *path,
188 static void ata_dev_async(u_int32_t async_code,
190 struct cam_et *target,
191 struct cam_ed *device,
193 static void ata_action(union ccb *start_ccb);
194 static void ata_announce_periph(struct cam_periph *periph);
196 static int ata_dma = 1;
197 static int atapi_dma = 1;
199 TUNABLE_INT("hw.ata.ata_dma", &ata_dma);
200 TUNABLE_INT("hw.ata.atapi_dma", &atapi_dma);
202 static struct xpt_xport ata_xport = {
203 .alloc_device = ata_alloc_device,
204 .action = ata_action,
205 .async = ata_dev_async,
206 .announce = ata_announce_periph,
221 proberegister(struct cam_periph *periph, void *arg)
223 union ccb *request_ccb; /* CCB representing the probe request */
227 request_ccb = (union ccb *)arg;
228 if (request_ccb == NULL) {
229 printf("proberegister: no probe CCB, "
230 "can't register device\n");
231 return(CAM_REQ_CMP_ERR);
234 softc = (probe_softc *)malloc(sizeof(*softc), M_CAMXPT, M_ZERO | M_NOWAIT);
237 printf("proberegister: Unable to probe new device. "
238 "Unable to allocate softc\n");
239 return(CAM_REQ_CMP_ERR);
241 TAILQ_INIT(&softc->request_ccbs);
242 TAILQ_INSERT_TAIL(&softc->request_ccbs, &request_ccb->ccb_h,
245 periph->softc = softc;
246 softc->periph = periph;
247 softc->action = PROBE_INVALID;
248 status = cam_periph_acquire(periph);
249 if (status != CAM_REQ_CMP) {
252 CAM_DEBUG(periph->path, CAM_DEBUG_PROBE, ("Probe started\n"));
253 ata_device_transport(periph->path);
254 probeschedule(periph);
259 probeschedule(struct cam_periph *periph)
264 softc = (probe_softc *)periph->softc;
265 ccb = (union ccb *)TAILQ_FIRST(&softc->request_ccbs);
267 if ((periph->path->device->flags & CAM_DEV_UNCONFIGURED) ||
268 periph->path->device->protocol == PROTO_SATAPM ||
269 periph->path->device->protocol == PROTO_SEMB)
270 PROBE_SET_ACTION(softc, PROBE_RESET);
272 PROBE_SET_ACTION(softc, PROBE_IDENTIFY);
274 if (ccb->crcn.flags & CAM_EXPECT_INQ_CHANGE)
275 softc->flags |= PROBE_NO_ANNOUNCE;
277 softc->flags &= ~PROBE_NO_ANNOUNCE;
279 xpt_schedule(periph, CAM_PRIORITY_XPT);
283 probestart(struct cam_periph *periph, union ccb *start_ccb)
285 struct ccb_trans_settings cts;
286 struct ccb_ataio *ataio;
287 struct ccb_scsiio *csio;
289 struct cam_path *path;
290 struct ata_params *ident_buf;
292 CAM_DEBUG(start_ccb->ccb_h.path, CAM_DEBUG_TRACE, ("probestart\n"));
294 softc = (probe_softc *)periph->softc;
295 path = start_ccb->ccb_h.path;
296 ataio = &start_ccb->ataio;
297 csio = &start_ccb->csio;
298 ident_buf = &periph->path->device->ident_data;
300 if (softc->restart) {
302 if ((path->device->flags & CAM_DEV_UNCONFIGURED) ||
303 path->device->protocol == PROTO_SATAPM ||
304 path->device->protocol == PROTO_SEMB)
305 softc->action = PROBE_RESET;
307 softc->action = PROBE_IDENTIFY;
309 switch (softc->action) {
311 cam_fill_ataio(ataio,
314 /*flags*/CAM_DIR_NONE,
319 ata_reset_cmd(ataio);
322 cam_fill_ataio(ataio,
327 /*data_ptr*/(u_int8_t *)&softc->ident_data,
328 /*dxfer_len*/sizeof(softc->ident_data),
330 if (periph->path->device->protocol == PROTO_ATA)
331 ata_28bit_cmd(ataio, ATA_ATA_IDENTIFY, 0, 0, 0);
333 ata_28bit_cmd(ataio, ATA_ATAPI_IDENTIFY, 0, 0, 0);
337 xpt_print(path, "Spinning up device\n");
338 cam_fill_ataio(ataio,
341 /*flags*/CAM_DIR_NONE | CAM_HIGH_POWER,
346 ata_28bit_cmd(ataio, ATA_SETFEATURES, ATA_SF_PUIS_SPINUP, 0, 0);
353 /* Fetch user modes from SIM. */
354 bzero(&cts, sizeof(cts));
355 xpt_setup_ccb(&cts.ccb_h, path, CAM_PRIORITY_NONE);
356 cts.ccb_h.func_code = XPT_GET_TRAN_SETTINGS;
357 cts.type = CTS_TYPE_USER_SETTINGS;
358 xpt_action((union ccb *)&cts);
359 if (path->device->transport == XPORT_ATA) {
360 if (cts.xport_specific.ata.valid & CTS_ATA_VALID_MODE)
361 mode = cts.xport_specific.ata.mode;
363 if (cts.xport_specific.sata.valid & CTS_SATA_VALID_MODE)
364 mode = cts.xport_specific.sata.mode;
366 if (periph->path->device->protocol == PROTO_ATA) {
367 if (ata_dma == 0 && (mode == 0 || mode > ATA_PIO_MAX))
370 if (atapi_dma == 0 && (mode == 0 || mode > ATA_PIO_MAX))
374 /* Honor device capabilities. */
375 wantmode = mode = ata_max_mode(ident_buf, mode);
376 /* Report modes to SIM. */
377 bzero(&cts, sizeof(cts));
378 xpt_setup_ccb(&cts.ccb_h, path, CAM_PRIORITY_NONE);
379 cts.ccb_h.func_code = XPT_SET_TRAN_SETTINGS;
380 cts.type = CTS_TYPE_CURRENT_SETTINGS;
381 if (path->device->transport == XPORT_ATA) {
382 cts.xport_specific.ata.mode = mode;
383 cts.xport_specific.ata.valid = CTS_ATA_VALID_MODE;
385 cts.xport_specific.sata.mode = mode;
386 cts.xport_specific.sata.valid = CTS_SATA_VALID_MODE;
388 xpt_action((union ccb *)&cts);
389 /* Fetch current modes from SIM. */
390 bzero(&cts, sizeof(cts));
391 xpt_setup_ccb(&cts.ccb_h, path, CAM_PRIORITY_NONE);
392 cts.ccb_h.func_code = XPT_GET_TRAN_SETTINGS;
393 cts.type = CTS_TYPE_CURRENT_SETTINGS;
394 xpt_action((union ccb *)&cts);
395 if (path->device->transport == XPORT_ATA) {
396 if (cts.xport_specific.ata.valid & CTS_ATA_VALID_MODE)
397 mode = cts.xport_specific.ata.mode;
399 if (cts.xport_specific.ata.valid & CTS_SATA_VALID_MODE)
400 mode = cts.xport_specific.sata.mode;
402 /* If SIM disagree - renegotiate. */
403 if (mode != wantmode)
405 /* Remember what transport thinks about DMA. */
407 path->device->inq_flags &= ~SID_DMA;
409 path->device->inq_flags |= SID_DMA;
410 xpt_async(AC_GETDEV_CHANGED, path, NULL);
411 cam_fill_ataio(ataio,
414 /*flags*/CAM_DIR_NONE,
419 ata_28bit_cmd(ataio, ATA_SETFEATURES, ATA_SF_SETXFER, 0, mode);
423 cam_fill_ataio(ataio,
431 ata_28bit_cmd(ataio, ATA_SETFEATURES,
432 (softc->caps & CTS_SATA_CAPS_H_PMREQ) ? 0x10 : 0x90,
436 cam_fill_ataio(ataio,
444 ata_28bit_cmd(ataio, ATA_SETFEATURES,
445 (softc->caps & CTS_SATA_CAPS_H_APST) ? 0x10 : 0x90,
449 cam_fill_ataio(ataio,
457 ata_28bit_cmd(ataio, ATA_SETFEATURES,
458 (softc->caps & CTS_SATA_CAPS_H_DMAAA) ? 0x10 : 0x90,
462 /* Remember what transport thinks about AEN. */
463 if (softc->caps & CTS_SATA_CAPS_H_AN)
464 path->device->inq_flags |= SID_AEN;
466 path->device->inq_flags &= ~SID_AEN;
467 xpt_async(AC_GETDEV_CHANGED, path, NULL);
468 cam_fill_ataio(ataio,
476 ata_28bit_cmd(ataio, ATA_SETFEATURES,
477 (softc->caps & CTS_SATA_CAPS_H_AN) ? 0x10 : 0x90,
480 case PROBE_SET_MULTI:
482 u_int sectors, bytecount;
484 bytecount = 8192; /* SATA maximum */
485 /* Fetch user bytecount from SIM. */
486 bzero(&cts, sizeof(cts));
487 xpt_setup_ccb(&cts.ccb_h, path, CAM_PRIORITY_NONE);
488 cts.ccb_h.func_code = XPT_GET_TRAN_SETTINGS;
489 cts.type = CTS_TYPE_USER_SETTINGS;
490 xpt_action((union ccb *)&cts);
491 if (path->device->transport == XPORT_ATA) {
492 if (cts.xport_specific.ata.valid & CTS_ATA_VALID_BYTECOUNT)
493 bytecount = cts.xport_specific.ata.bytecount;
495 if (cts.xport_specific.sata.valid & CTS_SATA_VALID_BYTECOUNT)
496 bytecount = cts.xport_specific.sata.bytecount;
498 /* Honor device capabilities. */
499 sectors = max(1, min(ident_buf->sectors_intr & 0xff,
500 bytecount / ata_logical_sector_size(ident_buf)));
501 /* Report bytecount to SIM. */
502 bzero(&cts, sizeof(cts));
503 xpt_setup_ccb(&cts.ccb_h, path, CAM_PRIORITY_NONE);
504 cts.ccb_h.func_code = XPT_SET_TRAN_SETTINGS;
505 cts.type = CTS_TYPE_CURRENT_SETTINGS;
506 if (path->device->transport == XPORT_ATA) {
507 cts.xport_specific.ata.bytecount = sectors *
508 ata_logical_sector_size(ident_buf);
509 cts.xport_specific.ata.valid = CTS_ATA_VALID_BYTECOUNT;
511 cts.xport_specific.sata.bytecount = sectors *
512 ata_logical_sector_size(ident_buf);
513 cts.xport_specific.sata.valid = CTS_SATA_VALID_BYTECOUNT;
515 xpt_action((union ccb *)&cts);
516 /* Fetch current bytecount from SIM. */
517 bzero(&cts, sizeof(cts));
518 xpt_setup_ccb(&cts.ccb_h, path, CAM_PRIORITY_NONE);
519 cts.ccb_h.func_code = XPT_GET_TRAN_SETTINGS;
520 cts.type = CTS_TYPE_CURRENT_SETTINGS;
521 xpt_action((union ccb *)&cts);
522 if (path->device->transport == XPORT_ATA) {
523 if (cts.xport_specific.ata.valid & CTS_ATA_VALID_BYTECOUNT)
524 bytecount = cts.xport_specific.ata.bytecount;
526 if (cts.xport_specific.sata.valid & CTS_SATA_VALID_BYTECOUNT)
527 bytecount = cts.xport_specific.sata.bytecount;
529 sectors = bytecount / ata_logical_sector_size(ident_buf);
531 cam_fill_ataio(ataio,
539 ata_28bit_cmd(ataio, ATA_SET_MULTI, 0, 0, sectors);
546 bytecount = 8192; /* SATA maximum */
547 /* Fetch user bytecount from SIM. */
548 bzero(&cts, sizeof(cts));
549 xpt_setup_ccb(&cts.ccb_h, path, CAM_PRIORITY_NONE);
550 cts.ccb_h.func_code = XPT_GET_TRAN_SETTINGS;
551 cts.type = CTS_TYPE_USER_SETTINGS;
552 xpt_action((union ccb *)&cts);
553 if (path->device->transport == XPORT_ATA) {
554 if (cts.xport_specific.ata.valid & CTS_ATA_VALID_BYTECOUNT)
555 bytecount = cts.xport_specific.ata.bytecount;
557 if (cts.xport_specific.sata.valid & CTS_SATA_VALID_BYTECOUNT)
558 bytecount = cts.xport_specific.sata.bytecount;
560 /* Honor device capabilities. */
562 bytecount = max(2, min(65534, bytecount));
563 if (ident_buf->satacapabilities != 0x0000 &&
564 ident_buf->satacapabilities != 0xffff) {
565 bytecount = min(8192, bytecount);
567 /* Report bytecount to SIM. */
568 bzero(&cts, sizeof(cts));
569 xpt_setup_ccb(&cts.ccb_h, path, CAM_PRIORITY_NONE);
570 cts.ccb_h.func_code = XPT_SET_TRAN_SETTINGS;
571 cts.type = CTS_TYPE_CURRENT_SETTINGS;
572 if (path->device->transport == XPORT_ATA) {
573 cts.xport_specific.ata.bytecount = bytecount;
574 cts.xport_specific.ata.valid = CTS_ATA_VALID_BYTECOUNT;
576 cts.xport_specific.sata.bytecount = bytecount;
577 cts.xport_specific.sata.valid = CTS_SATA_VALID_BYTECOUNT;
579 xpt_action((union ccb *)&cts);
582 case PROBE_FULL_INQUIRY:
585 struct scsi_inquiry_data *inq_buf =
586 &periph->path->device->inq_data;
588 if (softc->action == PROBE_INQUIRY)
589 inquiry_len = SHORT_INQUIRY_LENGTH;
591 inquiry_len = SID_ADDITIONAL_LENGTH(inq_buf);
593 * Some parallel SCSI devices fail to send an
594 * ignore wide residue message when dealing with
595 * odd length inquiry requests. Round up to be
598 inquiry_len = roundup2(inquiry_len, 2);
608 /*timeout*/60 * 1000);
612 cam_fill_ataio(ataio,
615 /*flags*/CAM_DIR_NONE,
620 ata_pm_read_cmd(ataio, 0, 15);
623 cam_fill_ataio(ataio,
626 /*flags*/CAM_DIR_NONE,
631 ata_pm_read_cmd(ataio, 1, 15);
633 case PROBE_IDENTIFY_SES:
634 cam_fill_ataio(ataio,
639 /*data_ptr*/(u_int8_t *)&softc->ident_data,
640 /*dxfer_len*/sizeof(softc->ident_data),
642 ata_28bit_cmd(ataio, ATA_SEP_ATTN, 0xEC, 0x02,
643 sizeof(softc->ident_data) / 4);
645 case PROBE_IDENTIFY_SAFTE:
646 cam_fill_ataio(ataio,
651 /*data_ptr*/(u_int8_t *)&softc->ident_data,
652 /*dxfer_len*/sizeof(softc->ident_data),
654 ata_28bit_cmd(ataio, ATA_SEP_ATTN, 0xEC, 0x00,
655 sizeof(softc->ident_data) / 4);
658 panic("probestart: invalid action state 0x%x\n", softc->action);
660 start_ccb->ccb_h.flags |= CAM_DEV_QFREEZE;
661 xpt_action(start_ccb);
665 proberequestdefaultnegotiation(struct cam_periph *periph)
667 struct ccb_trans_settings cts;
669 xpt_setup_ccb(&cts.ccb_h, periph->path, CAM_PRIORITY_NONE);
670 cts.ccb_h.func_code = XPT_GET_TRAN_SETTINGS;
671 cts.type = CTS_TYPE_USER_SETTINGS;
672 xpt_action((union ccb *)&cts);
673 if ((cts.ccb_h.status & CAM_STATUS_MASK) != CAM_REQ_CMP)
675 cts.xport_specific.valid = 0;
676 cts.ccb_h.func_code = XPT_SET_TRAN_SETTINGS;
677 cts.type = CTS_TYPE_CURRENT_SETTINGS;
678 xpt_action((union ccb *)&cts);
682 probedone(struct cam_periph *periph, union ccb *done_ccb)
684 struct ccb_trans_settings cts;
685 struct ata_params *ident_buf;
686 struct scsi_inquiry_data *inq_buf;
688 struct cam_path *path;
692 int changed = 1, found = 1;
693 static const uint8_t fake_device_id_hdr[8] =
694 {0, SVPD_DEVICE_ID, 0, 12,
695 SVPD_ID_CODESET_BINARY, SVPD_ID_TYPE_NAA, 0, 8};
697 CAM_DEBUG(done_ccb->ccb_h.path, CAM_DEBUG_TRACE, ("probedone\n"));
699 softc = (probe_softc *)periph->softc;
700 path = done_ccb->ccb_h.path;
701 priority = done_ccb->ccb_h.pinfo.priority;
702 ident_buf = &path->device->ident_data;
703 inq_buf = &path->device->inq_data;
705 if ((done_ccb->ccb_h.status & CAM_STATUS_MASK) != CAM_REQ_CMP) {
706 if (cam_periph_error(done_ccb,
707 0, softc->restart ? (SF_NO_RECOVERY | SF_NO_RETRY) : 0,
710 /* Drop freeze taken due to CAM_DEV_QFREEZE flag set. */
711 cam_release_devq(path, 0, 0, 0, FALSE);
714 if ((done_ccb->ccb_h.status & CAM_DEV_QFRZN) != 0) {
715 /* Don't wedge the queue */
716 xpt_release_devq(path, /*count*/1, /*run_queue*/TRUE);
718 status = done_ccb->ccb_h.status & CAM_STATUS_MASK;
719 if (softc->restart) {
721 if ((done_ccb->ccb_h.status & CAM_STATUS_MASK) ==
724 if (softc->faults < 10)
729 /* Old PIO2 devices may not support mode setting. */
730 } else if (softc->action == PROBE_SETMODE &&
731 status == CAM_ATA_STATUS_ERROR &&
732 ata_max_pmode(ident_buf) <= ATA_PIO2 &&
733 (ident_buf->capabilities1 & ATA_SUPPORT_IORDY) == 0) {
737 * Some old WD SATA disks report supported and enabled
738 * device-initiated interface power management, but return
739 * ABORT on attempt to disable it.
741 } else if (softc->action == PROBE_SETPM &&
742 status == CAM_ATA_STATUS_ERROR) {
746 * Some HP SATA disks report supported DMA Auto-Activation,
747 * but return ABORT on attempt to enable it.
749 } else if (softc->action == PROBE_SETDMAAA &&
750 status == CAM_ATA_STATUS_ERROR) {
754 * SES and SAF-TE SEPs have different IDENTIFY commands,
755 * but SATA specification doesn't tell how to identify them.
756 * Until better way found, just try another if first fail.
758 } else if (softc->action == PROBE_IDENTIFY_SES &&
759 status == CAM_ATA_STATUS_ERROR) {
760 PROBE_SET_ACTION(softc, PROBE_IDENTIFY_SAFTE);
761 xpt_release_ccb(done_ccb);
762 xpt_schedule(periph, priority);
767 * If we get to this point, we got an error status back
768 * from the inquiry and the error status doesn't require
769 * automatically retrying the command. Therefore, the
770 * inquiry failed. If we had inquiry information before
771 * for this device, but this latest inquiry command failed,
772 * the device has probably gone away. If this device isn't
773 * already marked unconfigured, notify the peripheral
774 * drivers that this device is no more.
776 device_fail: if ((path->device->flags & CAM_DEV_UNCONFIGURED) == 0)
777 xpt_async(AC_LOST_DEVICE, path, NULL);
778 PROBE_SET_ACTION(softc, PROBE_INVALID);
785 switch (softc->action) {
788 int sign = (done_ccb->ataio.res.lba_high << 8) +
789 done_ccb->ataio.res.lba_mid;
790 CAM_DEBUG(path, CAM_DEBUG_PROBE,
791 ("SIGNATURE: %04x\n", sign));
792 if (sign == 0x0000 &&
793 done_ccb->ccb_h.target_id != 15) {
794 path->device->protocol = PROTO_ATA;
795 PROBE_SET_ACTION(softc, PROBE_IDENTIFY);
796 } else if (sign == 0x9669 &&
797 done_ccb->ccb_h.target_id == 15) {
798 /* Report SIM that PM is present. */
799 bzero(&cts, sizeof(cts));
800 xpt_setup_ccb(&cts.ccb_h, path, CAM_PRIORITY_NONE);
801 cts.ccb_h.func_code = XPT_SET_TRAN_SETTINGS;
802 cts.type = CTS_TYPE_CURRENT_SETTINGS;
803 cts.xport_specific.sata.pm_present = 1;
804 cts.xport_specific.sata.valid = CTS_SATA_VALID_PM;
805 xpt_action((union ccb *)&cts);
806 path->device->protocol = PROTO_SATAPM;
807 PROBE_SET_ACTION(softc, PROBE_PM_PID);
808 } else if (sign == 0xc33c &&
809 done_ccb->ccb_h.target_id != 15) {
810 path->device->protocol = PROTO_SEMB;
811 PROBE_SET_ACTION(softc, PROBE_IDENTIFY_SES);
812 } else if (sign == 0xeb14 &&
813 done_ccb->ccb_h.target_id != 15) {
814 path->device->protocol = PROTO_SCSI;
815 PROBE_SET_ACTION(softc, PROBE_IDENTIFY);
817 if (done_ccb->ccb_h.target_id != 15) {
819 "Unexpected signature 0x%04x\n", sign);
823 xpt_release_ccb(done_ccb);
824 xpt_schedule(periph, priority);
829 struct ccb_pathinq cpi;
833 ident_buf = &softc->ident_data;
834 for (ptr = (int16_t *)ident_buf;
835 ptr < (int16_t *)ident_buf + sizeof(struct ata_params)/2; ptr++) {
836 *ptr = le16toh(*ptr);
838 EVENTHANDLER_INVOKE(ada_probe_veto, path, ident_buf, &veto);
843 if (strncmp(ident_buf->model, "FX", 2) &&
844 strncmp(ident_buf->model, "NEC", 3) &&
845 strncmp(ident_buf->model, "Pioneer", 7) &&
846 strncmp(ident_buf->model, "SHARP", 5)) {
847 ata_bswap(ident_buf->model, sizeof(ident_buf->model));
848 ata_bswap(ident_buf->revision, sizeof(ident_buf->revision));
849 ata_bswap(ident_buf->serial, sizeof(ident_buf->serial));
851 ata_btrim(ident_buf->model, sizeof(ident_buf->model));
852 ata_bpack(ident_buf->model, ident_buf->model, sizeof(ident_buf->model));
853 ata_btrim(ident_buf->revision, sizeof(ident_buf->revision));
854 ata_bpack(ident_buf->revision, ident_buf->revision, sizeof(ident_buf->revision));
855 ata_btrim(ident_buf->serial, sizeof(ident_buf->serial));
856 ata_bpack(ident_buf->serial, ident_buf->serial, sizeof(ident_buf->serial));
857 /* Device may need spin-up before IDENTIFY become valid. */
858 if ((ident_buf->specconf == 0x37c8 ||
859 ident_buf->specconf == 0x738c) &&
860 ((ident_buf->config & ATA_RESP_INCOMPLETE) ||
861 softc->spinup == 0)) {
862 PROBE_SET_ACTION(softc, PROBE_SPINUP);
863 xpt_release_ccb(done_ccb);
864 xpt_schedule(periph, priority);
867 ident_buf = &path->device->ident_data;
868 if ((periph->path->device->flags & CAM_DEV_UNCONFIGURED) == 0) {
869 /* Check that it is the same device. */
870 if (bcmp(softc->ident_data.model, ident_buf->model,
871 sizeof(ident_buf->model)) ||
872 bcmp(softc->ident_data.revision, ident_buf->revision,
873 sizeof(ident_buf->revision)) ||
874 bcmp(softc->ident_data.serial, ident_buf->serial,
875 sizeof(ident_buf->serial))) {
876 /* Device changed. */
877 xpt_async(AC_LOST_DEVICE, path, NULL);
879 bcopy(&softc->ident_data, ident_buf, sizeof(struct ata_params));
884 bcopy(&softc->ident_data, ident_buf, sizeof(struct ata_params));
885 /* Clean up from previous instance of this device */
886 if (path->device->serial_num != NULL) {
887 free(path->device->serial_num, M_CAMXPT);
888 path->device->serial_num = NULL;
889 path->device->serial_num_len = 0;
891 if (path->device->device_id != NULL) {
892 free(path->device->device_id, M_CAMXPT);
893 path->device->device_id = NULL;
894 path->device->device_id_len = 0;
896 path->device->serial_num =
897 (u_int8_t *)malloc((sizeof(ident_buf->serial) + 1),
899 if (path->device->serial_num != NULL) {
900 bcopy(ident_buf->serial,
901 path->device->serial_num,
902 sizeof(ident_buf->serial));
903 path->device->serial_num[sizeof(ident_buf->serial)]
905 path->device->serial_num_len =
906 strlen(path->device->serial_num);
908 if (ident_buf->enabled.extension &
909 ATA_SUPPORT_64BITWWN) {
910 path->device->device_id =
911 malloc(16, M_CAMXPT, M_NOWAIT);
912 if (path->device->device_id != NULL) {
913 path->device->device_id_len = 16;
914 bcopy(&fake_device_id_hdr,
915 path->device->device_id, 8);
916 bcopy(ident_buf->wwn,
917 path->device->device_id + 8, 8);
918 ata_bswap(path->device->device_id + 8, 8);
922 path->device->flags |= CAM_DEV_IDENTIFY_DATA_VALID;
923 xpt_async(AC_GETDEV_CHANGED, path, NULL);
925 if (ident_buf->satacapabilities & ATA_SUPPORT_NCQ) {
926 path->device->mintags = 2;
927 path->device->maxtags =
928 ATA_QUEUE_LEN(ident_buf->queue) + 1;
930 ata_find_quirk(path->device);
931 if (path->device->mintags != 0 &&
932 path->bus->sim->max_tagged_dev_openings != 0) {
933 /* Check if the SIM does not want queued commands. */
934 bzero(&cpi, sizeof(cpi));
935 xpt_setup_ccb(&cpi.ccb_h, path, CAM_PRIORITY_NONE);
936 cpi.ccb_h.func_code = XPT_PATH_INQ;
937 xpt_action((union ccb *)&cpi);
938 if (cpi.ccb_h.status == CAM_REQ_CMP &&
939 (cpi.hba_inquiry & PI_TAG_ABLE)) {
940 /* Report SIM which tags are allowed. */
941 bzero(&cts, sizeof(cts));
942 xpt_setup_ccb(&cts.ccb_h, path, CAM_PRIORITY_NONE);
943 cts.ccb_h.func_code = XPT_SET_TRAN_SETTINGS;
944 cts.type = CTS_TYPE_CURRENT_SETTINGS;
945 cts.xport_specific.sata.tags = path->device->maxtags;
946 cts.xport_specific.sata.valid = CTS_SATA_VALID_TAGS;
947 xpt_action((union ccb *)&cts);
950 ata_device_transport(path);
952 proberequestdefaultnegotiation(periph);
953 PROBE_SET_ACTION(softc, PROBE_SETMODE);
954 xpt_release_ccb(done_ccb);
955 xpt_schedule(periph, priority);
960 xpt_print(path, "Spin-up done\n");
962 PROBE_SET_ACTION(softc, PROBE_IDENTIFY);
963 xpt_release_ccb(done_ccb);
964 xpt_schedule(periph, priority);
967 /* Set supported bits. */
968 bzero(&cts, sizeof(cts));
969 xpt_setup_ccb(&cts.ccb_h, path, CAM_PRIORITY_NONE);
970 cts.ccb_h.func_code = XPT_GET_TRAN_SETTINGS;
971 cts.type = CTS_TYPE_CURRENT_SETTINGS;
972 xpt_action((union ccb *)&cts);
973 if (path->device->transport == XPORT_SATA &&
974 cts.xport_specific.sata.valid & CTS_SATA_VALID_CAPS)
975 caps = cts.xport_specific.sata.caps & CTS_SATA_CAPS_H;
976 else if (path->device->transport == XPORT_ATA &&
977 cts.xport_specific.ata.valid & CTS_ATA_VALID_CAPS)
978 caps = cts.xport_specific.ata.caps & CTS_ATA_CAPS_H;
981 if (path->device->transport == XPORT_SATA &&
982 ident_buf->satacapabilities != 0xffff) {
983 if (ident_buf->satacapabilities & ATA_SUPPORT_IFPWRMNGTRCV)
984 caps |= CTS_SATA_CAPS_D_PMREQ;
985 if (ident_buf->satacapabilities & ATA_SUPPORT_HAPST)
986 caps |= CTS_SATA_CAPS_D_APST;
988 /* Mask unwanted bits. */
989 bzero(&cts, sizeof(cts));
990 xpt_setup_ccb(&cts.ccb_h, path, CAM_PRIORITY_NONE);
991 cts.ccb_h.func_code = XPT_GET_TRAN_SETTINGS;
992 cts.type = CTS_TYPE_USER_SETTINGS;
993 xpt_action((union ccb *)&cts);
994 if (path->device->transport == XPORT_SATA &&
995 cts.xport_specific.sata.valid & CTS_SATA_VALID_CAPS)
996 caps &= cts.xport_specific.sata.caps;
997 else if (path->device->transport == XPORT_ATA &&
998 cts.xport_specific.ata.valid & CTS_ATA_VALID_CAPS)
999 caps &= cts.xport_specific.ata.caps;
1003 * Remember what transport thinks about 48-bit DMA. If
1004 * capability information is not provided or transport is
1005 * SATA, we take support for granted.
1007 if (!(path->device->inq_flags & SID_DMA) ||
1008 (path->device->transport == XPORT_ATA &&
1009 (cts.xport_specific.ata.valid & CTS_ATA_VALID_CAPS) &&
1010 !(caps & CTS_ATA_CAPS_H_DMA48)))
1011 path->device->inq_flags &= ~SID_DMA48;
1013 path->device->inq_flags |= SID_DMA48;
1014 /* Store result to SIM. */
1015 bzero(&cts, sizeof(cts));
1016 xpt_setup_ccb(&cts.ccb_h, path, CAM_PRIORITY_NONE);
1017 cts.ccb_h.func_code = XPT_SET_TRAN_SETTINGS;
1018 cts.type = CTS_TYPE_CURRENT_SETTINGS;
1019 if (path->device->transport == XPORT_SATA) {
1020 cts.xport_specific.sata.caps = caps;
1021 cts.xport_specific.sata.valid = CTS_SATA_VALID_CAPS;
1023 cts.xport_specific.ata.caps = caps;
1024 cts.xport_specific.ata.valid = CTS_ATA_VALID_CAPS;
1026 xpt_action((union ccb *)&cts);
1028 if (path->device->transport != XPORT_SATA)
1030 if ((ident_buf->satasupport & ATA_SUPPORT_IFPWRMNGT) &&
1031 (!(softc->caps & CTS_SATA_CAPS_H_PMREQ)) !=
1032 (!(ident_buf->sataenabled & ATA_SUPPORT_IFPWRMNGT))) {
1033 PROBE_SET_ACTION(softc, PROBE_SETPM);
1034 xpt_release_ccb(done_ccb);
1035 xpt_schedule(periph, priority);
1040 if (ident_buf->satacapabilities != 0xffff &&
1041 (ident_buf->satacapabilities & ATA_SUPPORT_DAPST) &&
1042 (!(softc->caps & CTS_SATA_CAPS_H_APST)) !=
1043 (!(ident_buf->sataenabled & ATA_ENABLED_DAPST))) {
1044 PROBE_SET_ACTION(softc, PROBE_SETAPST);
1045 xpt_release_ccb(done_ccb);
1046 xpt_schedule(periph, priority);
1051 if ((ident_buf->satasupport & ATA_SUPPORT_AUTOACTIVATE) &&
1052 (!(softc->caps & CTS_SATA_CAPS_H_DMAAA)) !=
1053 (!(ident_buf->sataenabled & ATA_SUPPORT_AUTOACTIVATE))) {
1054 PROBE_SET_ACTION(softc, PROBE_SETDMAAA);
1055 xpt_release_ccb(done_ccb);
1056 xpt_schedule(periph, priority);
1060 case PROBE_SETDMAAA:
1061 if (path->device->protocol != PROTO_ATA &&
1062 (ident_buf->satasupport & ATA_SUPPORT_ASYNCNOTIF) &&
1063 (!(softc->caps & CTS_SATA_CAPS_H_AN)) !=
1064 (!(ident_buf->sataenabled & ATA_SUPPORT_ASYNCNOTIF))) {
1065 PROBE_SET_ACTION(softc, PROBE_SETAN);
1066 xpt_release_ccb(done_ccb);
1067 xpt_schedule(periph, priority);
1073 if (path->device->protocol == PROTO_ATA) {
1074 PROBE_SET_ACTION(softc, PROBE_SET_MULTI);
1076 PROBE_SET_ACTION(softc, PROBE_INQUIRY);
1078 xpt_release_ccb(done_ccb);
1079 xpt_schedule(periph, priority);
1081 case PROBE_SET_MULTI:
1082 if (periph->path->device->flags & CAM_DEV_UNCONFIGURED) {
1083 path->device->flags &= ~CAM_DEV_UNCONFIGURED;
1084 xpt_acquire_device(path->device);
1085 done_ccb->ccb_h.func_code = XPT_GDEV_TYPE;
1086 xpt_action(done_ccb);
1087 xpt_async(AC_FOUND_DEVICE, path, done_ccb);
1089 PROBE_SET_ACTION(softc, PROBE_DONE);
1092 case PROBE_FULL_INQUIRY:
1094 u_int8_t periph_qual, len;
1096 path->device->flags |= CAM_DEV_INQUIRY_DATA_VALID;
1098 periph_qual = SID_QUAL(inq_buf);
1100 if (periph_qual != SID_QUAL_LU_CONNECTED &&
1101 periph_qual != SID_QUAL_LU_OFFLINE)
1105 * We conservatively request only
1106 * SHORT_INQUIRY_LEN bytes of inquiry
1107 * information during our first try
1108 * at sending an INQUIRY. If the device
1109 * has more information to give,
1110 * perform a second request specifying
1111 * the amount of information the device
1112 * is willing to give.
1114 len = inq_buf->additional_length
1115 + offsetof(struct scsi_inquiry_data, additional_length) + 1;
1116 if (softc->action == PROBE_INQUIRY
1117 && len > SHORT_INQUIRY_LENGTH) {
1118 PROBE_SET_ACTION(softc, PROBE_FULL_INQUIRY);
1119 xpt_release_ccb(done_ccb);
1120 xpt_schedule(periph, priority);
1124 ata_device_transport(path);
1125 if (periph->path->device->flags & CAM_DEV_UNCONFIGURED) {
1126 path->device->flags &= ~CAM_DEV_UNCONFIGURED;
1127 xpt_acquire_device(path->device);
1128 done_ccb->ccb_h.func_code = XPT_GDEV_TYPE;
1129 xpt_action(done_ccb);
1130 xpt_async(AC_FOUND_DEVICE, path, done_ccb);
1132 PROBE_SET_ACTION(softc, PROBE_DONE);
1136 if ((path->device->flags & CAM_DEV_IDENTIFY_DATA_VALID) == 0)
1137 bzero(ident_buf, sizeof(*ident_buf));
1138 softc->pm_pid = (done_ccb->ataio.res.lba_high << 24) +
1139 (done_ccb->ataio.res.lba_mid << 16) +
1140 (done_ccb->ataio.res.lba_low << 8) +
1141 done_ccb->ataio.res.sector_count;
1142 ((uint32_t *)ident_buf)[0] = softc->pm_pid;
1143 snprintf(ident_buf->model, sizeof(ident_buf->model),
1144 "Port Multiplier %08x", softc->pm_pid);
1145 PROBE_SET_ACTION(softc, PROBE_PM_PRV);
1146 xpt_release_ccb(done_ccb);
1147 xpt_schedule(periph, priority);
1150 softc->pm_prv = (done_ccb->ataio.res.lba_high << 24) +
1151 (done_ccb->ataio.res.lba_mid << 16) +
1152 (done_ccb->ataio.res.lba_low << 8) +
1153 done_ccb->ataio.res.sector_count;
1154 ((uint32_t *)ident_buf)[1] = softc->pm_prv;
1155 snprintf(ident_buf->revision, sizeof(ident_buf->revision),
1156 "%04x", softc->pm_prv);
1157 path->device->flags |= CAM_DEV_IDENTIFY_DATA_VALID;
1158 ata_device_transport(path);
1159 if (periph->path->device->flags & CAM_DEV_UNCONFIGURED)
1160 proberequestdefaultnegotiation(periph);
1161 /* Set supported bits. */
1162 bzero(&cts, sizeof(cts));
1163 xpt_setup_ccb(&cts.ccb_h, path, CAM_PRIORITY_NONE);
1164 cts.ccb_h.func_code = XPT_GET_TRAN_SETTINGS;
1165 cts.type = CTS_TYPE_CURRENT_SETTINGS;
1166 xpt_action((union ccb *)&cts);
1167 if (cts.xport_specific.sata.valid & CTS_SATA_VALID_CAPS)
1168 caps = cts.xport_specific.sata.caps & CTS_SATA_CAPS_H;
1171 /* All PMPs must support PM requests. */
1172 caps |= CTS_SATA_CAPS_D_PMREQ;
1173 /* Mask unwanted bits. */
1174 bzero(&cts, sizeof(cts));
1175 xpt_setup_ccb(&cts.ccb_h, path, CAM_PRIORITY_NONE);
1176 cts.ccb_h.func_code = XPT_GET_TRAN_SETTINGS;
1177 cts.type = CTS_TYPE_USER_SETTINGS;
1178 xpt_action((union ccb *)&cts);
1179 if (cts.xport_specific.sata.valid & CTS_SATA_VALID_CAPS)
1180 caps &= cts.xport_specific.sata.caps;
1183 /* Remember what transport thinks about AEN. */
1184 if ((caps & CTS_SATA_CAPS_H_AN) && path->device->protocol != PROTO_ATA)
1185 path->device->inq_flags |= SID_AEN;
1187 path->device->inq_flags &= ~SID_AEN;
1188 /* Store result to SIM. */
1189 bzero(&cts, sizeof(cts));
1190 xpt_setup_ccb(&cts.ccb_h, path, CAM_PRIORITY_NONE);
1191 cts.ccb_h.func_code = XPT_SET_TRAN_SETTINGS;
1192 cts.type = CTS_TYPE_CURRENT_SETTINGS;
1193 cts.xport_specific.sata.caps = caps;
1194 cts.xport_specific.sata.valid = CTS_SATA_VALID_CAPS;
1195 xpt_action((union ccb *)&cts);
1197 xpt_async(AC_GETDEV_CHANGED, path, NULL);
1198 if (periph->path->device->flags & CAM_DEV_UNCONFIGURED) {
1199 path->device->flags &= ~CAM_DEV_UNCONFIGURED;
1200 xpt_acquire_device(path->device);
1201 done_ccb->ccb_h.func_code = XPT_GDEV_TYPE;
1202 xpt_action(done_ccb);
1203 xpt_async(AC_FOUND_DEVICE, path, done_ccb);
1205 done_ccb->ccb_h.func_code = XPT_GDEV_TYPE;
1206 xpt_action(done_ccb);
1207 xpt_async(AC_SCSI_AEN, path, done_ccb);
1209 PROBE_SET_ACTION(softc, PROBE_DONE);
1211 case PROBE_IDENTIFY_SES:
1212 case PROBE_IDENTIFY_SAFTE:
1213 if ((periph->path->device->flags & CAM_DEV_UNCONFIGURED) == 0) {
1214 /* Check that it is the same device. */
1215 if (bcmp(&softc->ident_data, ident_buf, 53)) {
1216 /* Device changed. */
1217 xpt_async(AC_LOST_DEVICE, path, NULL);
1219 bcopy(&softc->ident_data, ident_buf, sizeof(struct ata_params));
1224 bcopy(&softc->ident_data, ident_buf, sizeof(struct ata_params));
1225 /* Clean up from previous instance of this device */
1226 if (path->device->device_id != NULL) {
1227 free(path->device->device_id, M_CAMXPT);
1228 path->device->device_id = NULL;
1229 path->device->device_id_len = 0;
1231 path->device->device_id =
1232 malloc(16, M_CAMXPT, M_NOWAIT);
1233 if (path->device->device_id != NULL) {
1234 path->device->device_id_len = 16;
1235 bcopy(&fake_device_id_hdr,
1236 path->device->device_id, 8);
1237 bcopy(((uint8_t*)ident_buf) + 2,
1238 path->device->device_id + 8, 8);
1241 path->device->flags |= CAM_DEV_IDENTIFY_DATA_VALID;
1243 ata_device_transport(path);
1245 proberequestdefaultnegotiation(periph);
1247 if (periph->path->device->flags & CAM_DEV_UNCONFIGURED) {
1248 path->device->flags &= ~CAM_DEV_UNCONFIGURED;
1249 xpt_acquire_device(path->device);
1250 done_ccb->ccb_h.func_code = XPT_GDEV_TYPE;
1251 xpt_action(done_ccb);
1252 xpt_async(AC_FOUND_DEVICE, path, done_ccb);
1254 PROBE_SET_ACTION(softc, PROBE_DONE);
1257 panic("probedone: invalid action state 0x%x\n", softc->action);
1260 if (softc->restart) {
1262 xpt_release_ccb(done_ccb);
1263 probeschedule(periph);
1266 xpt_release_ccb(done_ccb);
1267 CAM_DEBUG(periph->path, CAM_DEBUG_PROBE, ("Probe completed\n"));
1268 while ((done_ccb = (union ccb *)TAILQ_FIRST(&softc->request_ccbs))) {
1269 TAILQ_REMOVE(&softc->request_ccbs,
1270 &done_ccb->ccb_h, periph_links.tqe);
1271 done_ccb->ccb_h.status = found ? CAM_REQ_CMP : CAM_REQ_CMP_ERR;
1274 /* Drop freeze taken due to CAM_DEV_QFREEZE flag set. */
1275 cam_release_devq(path, 0, 0, 0, FALSE);
1276 cam_periph_invalidate(periph);
1277 cam_periph_release_locked(periph);
1281 probecleanup(struct cam_periph *periph)
1283 free(periph->softc, M_CAMXPT);
1287 ata_find_quirk(struct cam_ed *device)
1289 struct ata_quirk_entry *quirk;
1292 match = cam_quirkmatch((caddr_t)&device->ident_data,
1293 (caddr_t)ata_quirk_table,
1294 ata_quirk_table_size,
1295 sizeof(*ata_quirk_table), ata_identify_match);
1298 panic("xpt_find_quirk: device didn't match wildcard entry!!");
1300 quirk = (struct ata_quirk_entry *)match;
1301 device->quirk = quirk;
1302 if (quirk->quirks & CAM_QUIRK_MAXTAGS) {
1303 device->mintags = quirk->mintags;
1304 device->maxtags = quirk->maxtags;
1309 union ccb *request_ccb;
1310 struct ccb_pathinq *cpi;
1312 } ata_scan_bus_info;
1315 * To start a scan, request_ccb is an XPT_SCAN_BUS ccb.
1316 * As the scan progresses, xpt_scan_bus is used as the
1317 * callback on completion function.
1320 ata_scan_bus(struct cam_periph *periph, union ccb *request_ccb)
1322 struct cam_path *path;
1323 ata_scan_bus_info *scan_info;
1324 union ccb *work_ccb, *reset_ccb;
1328 CAM_DEBUG(request_ccb->ccb_h.path, CAM_DEBUG_TRACE,
1329 ("xpt_scan_bus\n"));
1330 switch (request_ccb->ccb_h.func_code) {
1333 /* Find out the characteristics of the bus */
1334 work_ccb = xpt_alloc_ccb_nowait();
1335 if (work_ccb == NULL) {
1336 request_ccb->ccb_h.status = CAM_RESRC_UNAVAIL;
1337 xpt_done(request_ccb);
1340 xpt_setup_ccb(&work_ccb->ccb_h, request_ccb->ccb_h.path,
1341 request_ccb->ccb_h.pinfo.priority);
1342 work_ccb->ccb_h.func_code = XPT_PATH_INQ;
1343 xpt_action(work_ccb);
1344 if (work_ccb->ccb_h.status != CAM_REQ_CMP) {
1345 request_ccb->ccb_h.status = work_ccb->ccb_h.status;
1346 xpt_free_ccb(work_ccb);
1347 xpt_done(request_ccb);
1351 /* We may need to reset bus first, if we haven't done it yet. */
1352 if ((work_ccb->cpi.hba_inquiry &
1353 (PI_WIDE_32|PI_WIDE_16|PI_SDTR_ABLE)) &&
1354 !(work_ccb->cpi.hba_misc & PIM_NOBUSRESET) &&
1355 !timevalisset(&request_ccb->ccb_h.path->bus->last_reset)) {
1356 reset_ccb = xpt_alloc_ccb_nowait();
1357 if (reset_ccb == NULL) {
1358 request_ccb->ccb_h.status = CAM_RESRC_UNAVAIL;
1359 xpt_free_ccb(work_ccb);
1360 xpt_done(request_ccb);
1363 xpt_setup_ccb(&reset_ccb->ccb_h, request_ccb->ccb_h.path,
1365 reset_ccb->ccb_h.func_code = XPT_RESET_BUS;
1366 xpt_action(reset_ccb);
1367 if (reset_ccb->ccb_h.status != CAM_REQ_CMP) {
1368 request_ccb->ccb_h.status = reset_ccb->ccb_h.status;
1369 xpt_free_ccb(reset_ccb);
1370 xpt_free_ccb(work_ccb);
1371 xpt_done(request_ccb);
1374 xpt_free_ccb(reset_ccb);
1377 /* Save some state for use while we probe for devices */
1378 scan_info = (ata_scan_bus_info *)
1379 malloc(sizeof(ata_scan_bus_info), M_CAMXPT, M_NOWAIT);
1380 if (scan_info == NULL) {
1381 request_ccb->ccb_h.status = CAM_RESRC_UNAVAIL;
1382 xpt_free_ccb(work_ccb);
1383 xpt_done(request_ccb);
1386 scan_info->request_ccb = request_ccb;
1387 scan_info->cpi = &work_ccb->cpi;
1388 /* If PM supported, probe it first. */
1389 if (scan_info->cpi->hba_inquiry & PI_SATAPM)
1390 scan_info->counter = scan_info->cpi->max_target;
1392 scan_info->counter = 0;
1394 work_ccb = xpt_alloc_ccb_nowait();
1395 if (work_ccb == NULL) {
1396 free(scan_info, M_CAMXPT);
1397 request_ccb->ccb_h.status = CAM_RESRC_UNAVAIL;
1398 xpt_done(request_ccb);
1401 mtx = xpt_path_mtx(scan_info->request_ccb->ccb_h.path);
1404 work_ccb = request_ccb;
1405 /* Reuse the same CCB to query if a device was really found */
1406 scan_info = (ata_scan_bus_info *)work_ccb->ccb_h.ppriv_ptr0;
1407 mtx = xpt_path_mtx(scan_info->request_ccb->ccb_h.path);
1409 /* If there is PMP... */
1410 if ((scan_info->cpi->hba_inquiry & PI_SATAPM) &&
1411 (scan_info->counter == scan_info->cpi->max_target)) {
1412 if (work_ccb->ccb_h.status == CAM_REQ_CMP) {
1413 /* everything else will be probed by it */
1414 /* Free the current request path- we're done with it. */
1415 xpt_free_path(work_ccb->ccb_h.path);
1418 struct ccb_trans_settings cts;
1420 /* Report SIM that PM is absent. */
1421 bzero(&cts, sizeof(cts));
1422 xpt_setup_ccb(&cts.ccb_h,
1423 work_ccb->ccb_h.path, CAM_PRIORITY_NONE);
1424 cts.ccb_h.func_code = XPT_SET_TRAN_SETTINGS;
1425 cts.type = CTS_TYPE_CURRENT_SETTINGS;
1426 cts.xport_specific.sata.pm_present = 0;
1427 cts.xport_specific.sata.valid = CTS_SATA_VALID_PM;
1428 xpt_action((union ccb *)&cts);
1431 /* Free the current request path- we're done with it. */
1432 xpt_free_path(work_ccb->ccb_h.path);
1433 if (scan_info->counter ==
1434 ((scan_info->cpi->hba_inquiry & PI_SATAPM) ?
1435 0 : scan_info->cpi->max_target)) {
1438 xpt_free_ccb(work_ccb);
1439 xpt_free_ccb((union ccb *)scan_info->cpi);
1440 request_ccb = scan_info->request_ccb;
1441 free(scan_info, M_CAMXPT);
1442 request_ccb->ccb_h.status = CAM_REQ_CMP;
1443 xpt_done(request_ccb);
1446 /* Take next device. Wrap from max (PMP) to 0. */
1447 scan_info->counter = (scan_info->counter + 1 ) %
1448 (scan_info->cpi->max_target + 1);
1450 status = xpt_create_path(&path, NULL,
1451 scan_info->request_ccb->ccb_h.path_id,
1452 scan_info->counter, 0);
1453 if (status != CAM_REQ_CMP) {
1454 if (request_ccb->ccb_h.func_code == XPT_SCAN_LUN)
1456 printf("xpt_scan_bus: xpt_create_path failed"
1457 " with status %#x, bus scan halted\n",
1459 xpt_free_ccb(work_ccb);
1460 xpt_free_ccb((union ccb *)scan_info->cpi);
1461 request_ccb = scan_info->request_ccb;
1462 free(scan_info, M_CAMXPT);
1463 request_ccb->ccb_h.status = status;
1464 xpt_done(request_ccb);
1467 xpt_setup_ccb(&work_ccb->ccb_h, path,
1468 scan_info->request_ccb->ccb_h.pinfo.priority);
1469 work_ccb->ccb_h.func_code = XPT_SCAN_LUN;
1470 work_ccb->ccb_h.cbfcnp = ata_scan_bus;
1471 work_ccb->ccb_h.flags |= CAM_UNLOCKED;
1472 work_ccb->ccb_h.ppriv_ptr0 = scan_info;
1473 work_ccb->crcn.flags = scan_info->request_ccb->crcn.flags;
1475 if (request_ccb->ccb_h.func_code == XPT_SCAN_LUN)
1477 xpt_action(work_ccb);
1487 ata_scan_lun(struct cam_periph *periph, struct cam_path *path,
1488 cam_flags flags, union ccb *request_ccb)
1490 struct ccb_pathinq cpi;
1492 struct cam_path *new_path;
1493 struct cam_periph *old_periph;
1496 CAM_DEBUG(path, CAM_DEBUG_TRACE, ("xpt_scan_lun\n"));
1498 xpt_setup_ccb(&cpi.ccb_h, path, CAM_PRIORITY_NONE);
1499 cpi.ccb_h.func_code = XPT_PATH_INQ;
1500 xpt_action((union ccb *)&cpi);
1502 if (cpi.ccb_h.status != CAM_REQ_CMP) {
1503 if (request_ccb != NULL) {
1504 request_ccb->ccb_h.status = cpi.ccb_h.status;
1505 xpt_done(request_ccb);
1510 if (request_ccb == NULL) {
1511 request_ccb = xpt_alloc_ccb_nowait();
1512 if (request_ccb == NULL) {
1513 xpt_print(path, "xpt_scan_lun: can't allocate CCB, "
1514 "can't continue\n");
1517 status = xpt_create_path(&new_path, NULL,
1519 path->target->target_id,
1520 path->device->lun_id);
1521 if (status != CAM_REQ_CMP) {
1522 xpt_print(path, "xpt_scan_lun: can't create path, "
1523 "can't continue\n");
1524 xpt_free_ccb(request_ccb);
1527 xpt_setup_ccb(&request_ccb->ccb_h, new_path, CAM_PRIORITY_XPT);
1528 request_ccb->ccb_h.cbfcnp = xptscandone;
1529 request_ccb->ccb_h.flags |= CAM_UNLOCKED;
1530 request_ccb->ccb_h.func_code = XPT_SCAN_LUN;
1531 request_ccb->crcn.flags = flags;
1534 lock = (xpt_path_owned(path) == 0);
1536 xpt_path_lock(path);
1537 if ((old_periph = cam_periph_find(path, "aprobe")) != NULL) {
1538 if ((old_periph->flags & CAM_PERIPH_INVALID) == 0) {
1541 softc = (probe_softc *)old_periph->softc;
1542 TAILQ_INSERT_TAIL(&softc->request_ccbs,
1543 &request_ccb->ccb_h, periph_links.tqe);
1546 request_ccb->ccb_h.status = CAM_REQ_CMP_ERR;
1547 xpt_done(request_ccb);
1550 status = cam_periph_alloc(proberegister, NULL, probecleanup,
1551 probestart, "aprobe",
1553 request_ccb->ccb_h.path, NULL, 0,
1556 if (status != CAM_REQ_CMP) {
1557 xpt_print(path, "xpt_scan_lun: cam_alloc_periph "
1558 "returned an error, can't continue probe\n");
1559 request_ccb->ccb_h.status = status;
1560 xpt_done(request_ccb);
1564 xpt_path_unlock(path);
1568 xptscandone(struct cam_periph *periph, union ccb *done_ccb)
1571 xpt_free_path(done_ccb->ccb_h.path);
1572 xpt_free_ccb(done_ccb);
1575 static struct cam_ed *
1576 ata_alloc_device(struct cam_eb *bus, struct cam_et *target, lun_id_t lun_id)
1578 struct ata_quirk_entry *quirk;
1579 struct cam_ed *device;
1581 device = xpt_alloc_device(bus, target, lun_id);
1586 * Take the default quirk entry until we have inquiry
1587 * data and can determine a better quirk to use.
1589 quirk = &ata_quirk_table[ata_quirk_table_size - 1];
1590 device->quirk = (void *)quirk;
1591 device->mintags = 0;
1592 device->maxtags = 0;
1593 bzero(&device->inq_data, sizeof(device->inq_data));
1594 device->inq_flags = 0;
1595 device->queue_flags = 0;
1596 device->serial_num = NULL;
1597 device->serial_num_len = 0;
1602 ata_device_transport(struct cam_path *path)
1604 struct ccb_pathinq cpi;
1605 struct ccb_trans_settings cts;
1606 struct scsi_inquiry_data *inq_buf = NULL;
1607 struct ata_params *ident_buf = NULL;
1609 /* Get transport information from the SIM */
1610 xpt_setup_ccb(&cpi.ccb_h, path, CAM_PRIORITY_NONE);
1611 cpi.ccb_h.func_code = XPT_PATH_INQ;
1612 xpt_action((union ccb *)&cpi);
1614 path->device->transport = cpi.transport;
1615 if ((path->device->flags & CAM_DEV_INQUIRY_DATA_VALID) != 0)
1616 inq_buf = &path->device->inq_data;
1617 if ((path->device->flags & CAM_DEV_IDENTIFY_DATA_VALID) != 0)
1618 ident_buf = &path->device->ident_data;
1619 if (path->device->protocol == PROTO_ATA) {
1620 path->device->protocol_version = ident_buf ?
1621 ata_version(ident_buf->version_major) : cpi.protocol_version;
1622 } else if (path->device->protocol == PROTO_SCSI) {
1623 path->device->protocol_version = inq_buf ?
1624 SID_ANSI_REV(inq_buf) : cpi.protocol_version;
1626 path->device->transport_version = ident_buf ?
1627 ata_version(ident_buf->version_major) : cpi.transport_version;
1629 /* Tell the controller what we think */
1630 xpt_setup_ccb(&cts.ccb_h, path, CAM_PRIORITY_NONE);
1631 cts.ccb_h.func_code = XPT_SET_TRAN_SETTINGS;
1632 cts.type = CTS_TYPE_CURRENT_SETTINGS;
1633 cts.transport = path->device->transport;
1634 cts.transport_version = path->device->transport_version;
1635 cts.protocol = path->device->protocol;
1636 cts.protocol_version = path->device->protocol_version;
1637 cts.proto_specific.valid = 0;
1639 if (path->device->transport == XPORT_ATA) {
1640 cts.xport_specific.ata.atapi =
1641 (ident_buf->config == ATA_PROTO_CFA) ? 0 :
1642 ((ident_buf->config & ATA_PROTO_MASK) == ATA_PROTO_ATAPI_16) ? 16 :
1643 ((ident_buf->config & ATA_PROTO_MASK) == ATA_PROTO_ATAPI_12) ? 12 : 0;
1644 cts.xport_specific.ata.valid = CTS_ATA_VALID_ATAPI;
1646 cts.xport_specific.sata.atapi =
1647 (ident_buf->config == ATA_PROTO_CFA) ? 0 :
1648 ((ident_buf->config & ATA_PROTO_MASK) == ATA_PROTO_ATAPI_16) ? 16 :
1649 ((ident_buf->config & ATA_PROTO_MASK) == ATA_PROTO_ATAPI_12) ? 12 : 0;
1650 cts.xport_specific.sata.valid = CTS_SATA_VALID_ATAPI;
1653 cts.xport_specific.valid = 0;
1654 xpt_action((union ccb *)&cts);
1658 ata_dev_advinfo(union ccb *start_ccb)
1660 struct cam_ed *device;
1661 struct ccb_dev_advinfo *cdai;
1664 start_ccb->ccb_h.status = CAM_REQ_INVALID;
1665 device = start_ccb->ccb_h.path->device;
1666 cdai = &start_ccb->cdai;
1667 switch(cdai->buftype) {
1668 case CDAI_TYPE_SCSI_DEVID:
1669 if (cdai->flags & CDAI_FLAG_STORE)
1671 cdai->provsiz = device->device_id_len;
1672 if (device->device_id_len == 0)
1674 amt = device->device_id_len;
1675 if (cdai->provsiz > cdai->bufsiz)
1677 memcpy(cdai->buf, device->device_id, amt);
1679 case CDAI_TYPE_SERIAL_NUM:
1680 if (cdai->flags & CDAI_FLAG_STORE)
1682 cdai->provsiz = device->serial_num_len;
1683 if (device->serial_num_len == 0)
1685 amt = device->serial_num_len;
1686 if (cdai->provsiz > cdai->bufsiz)
1688 memcpy(cdai->buf, device->serial_num, amt);
1690 case CDAI_TYPE_PHYS_PATH:
1691 if (cdai->flags & CDAI_FLAG_STORE) {
1692 if (device->physpath != NULL)
1693 free(device->physpath, M_CAMXPT);
1694 device->physpath_len = cdai->bufsiz;
1695 /* Clear existing buffer if zero length */
1696 if (cdai->bufsiz == 0)
1698 device->physpath = malloc(cdai->bufsiz, M_CAMXPT, M_NOWAIT);
1699 if (device->physpath == NULL) {
1700 start_ccb->ccb_h.status = CAM_REQ_ABORTED;
1703 memcpy(device->physpath, cdai->buf, cdai->bufsiz);
1705 cdai->provsiz = device->physpath_len;
1706 if (device->physpath_len == 0)
1708 amt = device->physpath_len;
1709 if (cdai->provsiz > cdai->bufsiz)
1711 memcpy(cdai->buf, device->physpath, amt);
1717 start_ccb->ccb_h.status = CAM_REQ_CMP;
1719 if (cdai->flags & CDAI_FLAG_STORE) {
1720 xpt_async(AC_ADVINFO_CHANGED, start_ccb->ccb_h.path,
1721 (void *)(uintptr_t)cdai->buftype);
1726 ata_action(union ccb *start_ccb)
1729 switch (start_ccb->ccb_h.func_code) {
1730 case XPT_SET_TRAN_SETTINGS:
1732 ata_set_transfer_settings(&start_ccb->cts,
1733 start_ccb->ccb_h.path,
1734 /*async_update*/FALSE);
1739 ata_scan_bus(start_ccb->ccb_h.path->periph, start_ccb);
1742 ata_scan_lun(start_ccb->ccb_h.path->periph,
1743 start_ccb->ccb_h.path, start_ccb->crcn.flags,
1746 case XPT_GET_TRAN_SETTINGS:
1748 ata_get_transfer_settings(&start_ccb->cts);
1753 struct cam_ed *device;
1756 device = start_ccb->ccb_h.path->device;
1757 if (device->protocol == PROTO_SCSI &&
1758 (device->flags & CAM_DEV_IDENTIFY_DATA_VALID)) {
1760 device->ident_data.config & ATA_PROTO_MASK;
1763 (device->ident_data.config == ATA_PROTO_CFA) ? 0 :
1764 (p == ATA_PROTO_ATAPI_16) ? 16 :
1765 (p == ATA_PROTO_ATAPI_12) ? 12 : 0;
1767 if (start_ccb->csio.cdb_len > maxlen) {
1768 start_ccb->ccb_h.status = CAM_REQ_INVALID;
1769 xpt_done(start_ccb);
1772 xpt_action_default(start_ccb);
1775 case XPT_DEV_ADVINFO:
1777 ata_dev_advinfo(start_ccb);
1781 xpt_action_default(start_ccb);
1787 ata_get_transfer_settings(struct ccb_trans_settings *cts)
1789 struct ccb_trans_settings_ata *ata;
1790 struct ccb_trans_settings_scsi *scsi;
1791 struct cam_ed *device;
1793 device = cts->ccb_h.path->device;
1794 xpt_action_default((union ccb *)cts);
1796 if (cts->protocol == PROTO_UNKNOWN ||
1797 cts->protocol == PROTO_UNSPECIFIED) {
1798 cts->protocol = device->protocol;
1799 cts->protocol_version = device->protocol_version;
1802 if (cts->protocol == PROTO_ATA) {
1803 ata = &cts->proto_specific.ata;
1804 if ((ata->valid & CTS_ATA_VALID_TQ) == 0) {
1805 ata->valid |= CTS_ATA_VALID_TQ;
1806 if (cts->type == CTS_TYPE_USER_SETTINGS ||
1807 (device->flags & CAM_DEV_TAG_AFTER_COUNT) != 0 ||
1808 (device->inq_flags & SID_CmdQue) != 0)
1809 ata->flags |= CTS_ATA_FLAGS_TAG_ENB;
1812 if (cts->protocol == PROTO_SCSI) {
1813 scsi = &cts->proto_specific.scsi;
1814 if ((scsi->valid & CTS_SCSI_VALID_TQ) == 0) {
1815 scsi->valid |= CTS_SCSI_VALID_TQ;
1816 if (cts->type == CTS_TYPE_USER_SETTINGS ||
1817 (device->flags & CAM_DEV_TAG_AFTER_COUNT) != 0 ||
1818 (device->inq_flags & SID_CmdQue) != 0)
1819 scsi->flags |= CTS_SCSI_FLAGS_TAG_ENB;
1823 if (cts->transport == XPORT_UNKNOWN ||
1824 cts->transport == XPORT_UNSPECIFIED) {
1825 cts->transport = device->transport;
1826 cts->transport_version = device->transport_version;
1831 ata_set_transfer_settings(struct ccb_trans_settings *cts, struct cam_path *path,
1834 struct ccb_pathinq cpi;
1835 struct ccb_trans_settings_ata *ata;
1836 struct ccb_trans_settings_scsi *scsi;
1837 struct ata_params *ident_data;
1838 struct scsi_inquiry_data *inq_data;
1839 struct cam_ed *device;
1841 if (path == NULL || (device = path->device) == NULL) {
1842 cts->ccb_h.status = CAM_PATH_INVALID;
1843 xpt_done((union ccb *)cts);
1847 if (cts->protocol == PROTO_UNKNOWN
1848 || cts->protocol == PROTO_UNSPECIFIED) {
1849 cts->protocol = device->protocol;
1850 cts->protocol_version = device->protocol_version;
1853 if (cts->protocol_version == PROTO_VERSION_UNKNOWN
1854 || cts->protocol_version == PROTO_VERSION_UNSPECIFIED)
1855 cts->protocol_version = device->protocol_version;
1857 if (cts->protocol != device->protocol) {
1858 xpt_print(path, "Uninitialized Protocol %x:%x?\n",
1859 cts->protocol, device->protocol);
1860 cts->protocol = device->protocol;
1863 if (cts->protocol_version > device->protocol_version) {
1865 xpt_print(path, "Down reving Protocol "
1866 "Version from %d to %d?\n", cts->protocol_version,
1867 device->protocol_version);
1869 cts->protocol_version = device->protocol_version;
1872 if (cts->transport == XPORT_UNKNOWN
1873 || cts->transport == XPORT_UNSPECIFIED) {
1874 cts->transport = device->transport;
1875 cts->transport_version = device->transport_version;
1878 if (cts->transport_version == XPORT_VERSION_UNKNOWN
1879 || cts->transport_version == XPORT_VERSION_UNSPECIFIED)
1880 cts->transport_version = device->transport_version;
1882 if (cts->transport != device->transport) {
1883 xpt_print(path, "Uninitialized Transport %x:%x?\n",
1884 cts->transport, device->transport);
1885 cts->transport = device->transport;
1888 if (cts->transport_version > device->transport_version) {
1890 xpt_print(path, "Down reving Transport "
1891 "Version from %d to %d?\n", cts->transport_version,
1892 device->transport_version);
1894 cts->transport_version = device->transport_version;
1897 ident_data = &device->ident_data;
1898 inq_data = &device->inq_data;
1899 if (cts->protocol == PROTO_ATA)
1900 ata = &cts->proto_specific.ata;
1903 if (cts->protocol == PROTO_SCSI)
1904 scsi = &cts->proto_specific.scsi;
1907 xpt_setup_ccb(&cpi.ccb_h, path, CAM_PRIORITY_NONE);
1908 cpi.ccb_h.func_code = XPT_PATH_INQ;
1909 xpt_action((union ccb *)&cpi);
1911 /* Sanity checking */
1912 if ((cpi.hba_inquiry & PI_TAG_ABLE) == 0
1913 || (ata && (ident_data->satacapabilities & ATA_SUPPORT_NCQ) == 0)
1914 || (scsi && (INQ_DATA_TQ_ENABLED(inq_data)) == 0)
1915 || (device->queue_flags & SCP_QUEUE_DQUE) != 0
1916 || (device->mintags == 0)) {
1918 * Can't tag on hardware that doesn't support tags,
1919 * doesn't have it enabled, or has broken tag support.
1922 ata->flags &= ~CTS_ATA_FLAGS_TAG_ENB;
1924 scsi->flags &= ~CTS_SCSI_FLAGS_TAG_ENB;
1927 /* Start/stop tags use. */
1928 if (cts->type == CTS_TYPE_CURRENT_SETTINGS &&
1929 ((ata && (ata->valid & CTS_ATA_VALID_TQ) != 0) ||
1930 (scsi && (scsi->valid & CTS_SCSI_VALID_TQ) != 0))) {
1933 nowt = ((device->flags & CAM_DEV_TAG_AFTER_COUNT) != 0 ||
1934 (device->inq_flags & SID_CmdQue) != 0);
1936 newt = (ata->flags & CTS_ATA_FLAGS_TAG_ENB) != 0;
1938 newt = (scsi->flags & CTS_SCSI_FLAGS_TAG_ENB) != 0;
1940 if (newt && !nowt) {
1942 * Delay change to use tags until after a
1943 * few commands have gone to this device so
1944 * the controller has time to perform transfer
1945 * negotiations without tagged messages getting
1948 device->tag_delay_count = CAM_TAG_DELAY_COUNT;
1949 device->flags |= CAM_DEV_TAG_AFTER_COUNT;
1950 } else if (nowt && !newt)
1951 xpt_stop_tags(path);
1954 if (async_update == FALSE)
1955 xpt_action_default((union ccb *)cts);
1959 * Handle any per-device event notifications that require action by the XPT.
1962 ata_dev_async(u_int32_t async_code, struct cam_eb *bus, struct cam_et *target,
1963 struct cam_ed *device, void *async_arg)
1966 struct cam_path newpath;
1969 * We only need to handle events for real devices.
1971 if (target->target_id == CAM_TARGET_WILDCARD
1972 || device->lun_id == CAM_LUN_WILDCARD)
1976 * We need our own path with wildcards expanded to
1977 * handle certain types of events.
1979 if ((async_code == AC_SENT_BDR)
1980 || (async_code == AC_BUS_RESET)
1981 || (async_code == AC_INQ_CHANGED))
1982 status = xpt_compile_path(&newpath, NULL,
1987 status = CAM_REQ_CMP_ERR;
1989 if (status == CAM_REQ_CMP) {
1990 if (async_code == AC_INQ_CHANGED) {
1992 * We've sent a start unit command, or
1993 * something similar to a device that
1994 * may have caused its inquiry data to
1995 * change. So we re-scan the device to
1996 * refresh the inquiry data for it.
1998 ata_scan_lun(newpath.periph, &newpath,
1999 CAM_EXPECT_INQ_CHANGE, NULL);
2001 /* We need to reinitialize device after reset. */
2002 ata_scan_lun(newpath.periph, &newpath,
2005 xpt_release_path(&newpath);
2006 } else if (async_code == AC_LOST_DEVICE &&
2007 (device->flags & CAM_DEV_UNCONFIGURED) == 0) {
2008 device->flags |= CAM_DEV_UNCONFIGURED;
2009 xpt_release_device(device);
2010 } else if (async_code == AC_TRANSFER_NEG) {
2011 struct ccb_trans_settings *settings;
2012 struct cam_path path;
2014 settings = (struct ccb_trans_settings *)async_arg;
2015 xpt_compile_path(&path, NULL, bus->path_id, target->target_id,
2017 ata_set_transfer_settings(settings, &path,
2018 /*async_update*/TRUE);
2019 xpt_release_path(&path);
2024 ata_announce_periph(struct cam_periph *periph)
2026 struct ccb_pathinq cpi;
2027 struct ccb_trans_settings cts;
2028 struct cam_path *path = periph->path;
2032 cam_periph_assert(periph, MA_OWNED);
2034 xpt_setup_ccb(&cts.ccb_h, path, CAM_PRIORITY_NORMAL);
2035 cts.ccb_h.func_code = XPT_GET_TRAN_SETTINGS;
2036 cts.type = CTS_TYPE_CURRENT_SETTINGS;
2037 xpt_action((union ccb*)&cts);
2038 if ((cts.ccb_h.status & CAM_STATUS_MASK) != CAM_REQ_CMP)
2040 /* Ask the SIM for its base transfer speed */
2041 xpt_setup_ccb(&cpi.ccb_h, path, CAM_PRIORITY_NORMAL);
2042 cpi.ccb_h.func_code = XPT_PATH_INQ;
2043 xpt_action((union ccb *)&cpi);
2044 /* Report connection speed */
2045 speed = cpi.base_transfer_speed;
2046 if (cts.ccb_h.status == CAM_REQ_CMP && cts.transport == XPORT_ATA) {
2047 struct ccb_trans_settings_pata *pata =
2048 &cts.xport_specific.ata;
2050 if (pata->valid & CTS_ATA_VALID_MODE)
2051 speed = ata_mode2speed(pata->mode);
2053 if (cts.ccb_h.status == CAM_REQ_CMP && cts.transport == XPORT_SATA) {
2054 struct ccb_trans_settings_sata *sata =
2055 &cts.xport_specific.sata;
2057 if (sata->valid & CTS_SATA_VALID_REVISION)
2058 speed = ata_revision2speed(sata->revision);
2062 printf("%s%d: %d.%03dMB/s transfers",
2063 periph->periph_name, periph->unit_number,
2066 printf("%s%d: %dKB/s transfers", periph->periph_name,
2067 periph->unit_number, speed);
2068 /* Report additional information about connection */
2069 if (cts.ccb_h.status == CAM_REQ_CMP && cts.transport == XPORT_ATA) {
2070 struct ccb_trans_settings_pata *pata =
2071 &cts.xport_specific.ata;
2074 if (pata->valid & CTS_ATA_VALID_MODE)
2075 printf("%s, ", ata_mode2string(pata->mode));
2076 if ((pata->valid & CTS_ATA_VALID_ATAPI) && pata->atapi != 0)
2077 printf("ATAPI %dbytes, ", pata->atapi);
2078 if (pata->valid & CTS_ATA_VALID_BYTECOUNT)
2079 printf("PIO %dbytes", pata->bytecount);
2082 if (cts.ccb_h.status == CAM_REQ_CMP && cts.transport == XPORT_SATA) {
2083 struct ccb_trans_settings_sata *sata =
2084 &cts.xport_specific.sata;
2087 if (sata->valid & CTS_SATA_VALID_REVISION)
2088 printf("SATA %d.x, ", sata->revision);
2091 if (sata->valid & CTS_SATA_VALID_MODE)
2092 printf("%s, ", ata_mode2string(sata->mode));
2093 if ((sata->valid & CTS_ATA_VALID_ATAPI) && sata->atapi != 0)
2094 printf("ATAPI %dbytes, ", sata->atapi);
2095 if (sata->valid & CTS_SATA_VALID_BYTECOUNT)
2096 printf("PIO %dbytes", sata->bytecount);