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>
44 #include <sys/mutex.h>
45 #include <sys/sysctl.h>
48 #include <cam/cam_ccb.h>
49 #include <cam/cam_queue.h>
50 #include <cam/cam_periph.h>
51 #include <cam/cam_sim.h>
52 #include <cam/cam_xpt.h>
53 #include <cam/cam_xpt_sim.h>
54 #include <cam/cam_xpt_periph.h>
55 #include <cam/cam_xpt_internal.h>
56 #include <cam/cam_debug.h>
58 #include <cam/scsi/scsi_all.h>
59 #include <cam/scsi/scsi_message.h>
60 #include <cam/ata/ata_all.h>
61 #include <machine/stdarg.h> /* for xpt_print below */
64 struct ata_quirk_entry {
65 struct scsi_inquiry_pattern inq_pat;
67 #define CAM_QUIRK_MAXTAGS 0x01
72 static periph_init_t probe_periph_init;
74 static struct periph_driver probe_driver =
76 probe_periph_init, "aprobe",
77 TAILQ_HEAD_INITIALIZER(probe_driver.units), /* generation */ 0,
81 PERIPHDRIVER_DECLARE(aprobe, probe_driver);
103 static char *probe_action_text[] = {
114 "PROBE_FULL_INQUIRY",
117 "PROBE_IDENTIFY_SES",
118 "PROBE_IDENTIFY_SAFTE",
123 #define PROBE_SET_ACTION(softc, newaction) \
126 text = probe_action_text; \
127 CAM_DEBUG((softc)->periph->path, CAM_DEBUG_PROBE, \
128 ("Probe %s to %s\n", text[(softc)->action], \
129 text[(newaction)])); \
130 (softc)->action = (newaction); \
134 PROBE_NO_ANNOUNCE = 0x04
138 TAILQ_HEAD(, ccb_hdr) request_ccbs;
139 struct ata_params ident_data;
148 struct cam_periph *periph;
151 static struct ata_quirk_entry ata_quirk_table[] =
154 /* Default tagged queuing parameters for all devices */
156 T_ANY, SIP_MEDIA_REMOVABLE|SIP_MEDIA_FIXED,
157 /*vendor*/"*", /*product*/"*", /*revision*/"*"
159 /*quirks*/0, /*mintags*/0, /*maxtags*/0
163 static const int ata_quirk_table_size =
164 sizeof(ata_quirk_table) / sizeof(*ata_quirk_table);
166 static cam_status proberegister(struct cam_periph *periph,
168 static void probeschedule(struct cam_periph *probe_periph);
169 static void probestart(struct cam_periph *periph, union ccb *start_ccb);
170 static void proberequestdefaultnegotiation(struct cam_periph *periph);
171 static void probedone(struct cam_periph *periph, union ccb *done_ccb);
172 static void probecleanup(struct cam_periph *periph);
173 static void ata_find_quirk(struct cam_ed *device);
174 static void ata_scan_bus(struct cam_periph *periph, union ccb *ccb);
175 static void ata_scan_lun(struct cam_periph *periph,
176 struct cam_path *path, cam_flags flags,
178 static void xptscandone(struct cam_periph *periph, union ccb *done_ccb);
179 static struct cam_ed *
180 ata_alloc_device(struct cam_eb *bus, struct cam_et *target,
182 static void ata_device_transport(struct cam_path *path);
183 static void ata_get_transfer_settings(struct ccb_trans_settings *cts);
184 static void ata_set_transfer_settings(struct ccb_trans_settings *cts,
185 struct cam_ed *device,
187 static void ata_dev_async(u_int32_t async_code,
189 struct cam_et *target,
190 struct cam_ed *device,
192 static void ata_action(union ccb *start_ccb);
193 static void ata_announce_periph(struct cam_periph *periph);
195 static int ata_dma = 1;
196 static int atapi_dma = 1;
198 TUNABLE_INT("hw.ata.ata_dma", &ata_dma);
199 TUNABLE_INT("hw.ata.atapi_dma", &atapi_dma);
201 static struct xpt_xport ata_xport = {
202 .alloc_device = ata_alloc_device,
203 .action = ata_action,
204 .async = ata_dev_async,
205 .announce = ata_announce_periph,
220 proberegister(struct cam_periph *periph, void *arg)
222 union ccb *request_ccb; /* CCB representing the probe request */
226 request_ccb = (union ccb *)arg;
227 if (request_ccb == NULL) {
228 printf("proberegister: no probe CCB, "
229 "can't register device\n");
230 return(CAM_REQ_CMP_ERR);
233 softc = (probe_softc *)malloc(sizeof(*softc), M_CAMXPT, M_ZERO | M_NOWAIT);
236 printf("proberegister: Unable to probe new device. "
237 "Unable to allocate softc\n");
238 return(CAM_REQ_CMP_ERR);
240 TAILQ_INIT(&softc->request_ccbs);
241 TAILQ_INSERT_TAIL(&softc->request_ccbs, &request_ccb->ccb_h,
244 periph->softc = softc;
245 softc->periph = periph;
246 softc->action = PROBE_INVALID;
247 status = cam_periph_acquire(periph);
248 if (status != CAM_REQ_CMP) {
251 CAM_DEBUG(periph->path, CAM_DEBUG_PROBE, ("Probe started\n"));
254 * Ensure nobody slip in until probe finish.
256 cam_freeze_devq_arg(periph->path,
257 RELSIM_RELEASE_RUNLEVEL, CAM_RL_XPT + 1);
258 probeschedule(periph);
263 probeschedule(struct cam_periph *periph)
268 softc = (probe_softc *)periph->softc;
269 ccb = (union ccb *)TAILQ_FIRST(&softc->request_ccbs);
271 if ((periph->path->device->flags & CAM_DEV_UNCONFIGURED) ||
272 periph->path->device->protocol == PROTO_SATAPM ||
273 periph->path->device->protocol == PROTO_SEMB)
274 PROBE_SET_ACTION(softc, PROBE_RESET);
276 PROBE_SET_ACTION(softc, PROBE_IDENTIFY);
278 if (ccb->crcn.flags & CAM_EXPECT_INQ_CHANGE)
279 softc->flags |= PROBE_NO_ANNOUNCE;
281 softc->flags &= ~PROBE_NO_ANNOUNCE;
283 xpt_schedule(periph, CAM_PRIORITY_XPT);
287 probestart(struct cam_periph *periph, union ccb *start_ccb)
289 struct ccb_trans_settings cts;
290 struct ccb_ataio *ataio;
291 struct ccb_scsiio *csio;
293 struct cam_path *path;
294 struct ata_params *ident_buf;
296 CAM_DEBUG(start_ccb->ccb_h.path, CAM_DEBUG_TRACE, ("probestart\n"));
298 softc = (probe_softc *)periph->softc;
299 path = start_ccb->ccb_h.path;
300 ataio = &start_ccb->ataio;
301 csio = &start_ccb->csio;
302 ident_buf = &periph->path->device->ident_data;
304 if (softc->restart) {
306 if ((path->device->flags & CAM_DEV_UNCONFIGURED) ||
307 path->device->protocol == PROTO_SATAPM ||
308 path->device->protocol == PROTO_SEMB)
309 softc->action = PROBE_RESET;
311 softc->action = PROBE_IDENTIFY;
313 switch (softc->action) {
315 cam_fill_ataio(ataio,
318 /*flags*/CAM_DIR_NONE,
323 ata_reset_cmd(ataio);
326 cam_fill_ataio(ataio,
331 /*data_ptr*/(u_int8_t *)&softc->ident_data,
332 /*dxfer_len*/sizeof(softc->ident_data),
334 if (periph->path->device->protocol == PROTO_ATA)
335 ata_28bit_cmd(ataio, ATA_ATA_IDENTIFY, 0, 0, 0);
337 ata_28bit_cmd(ataio, ATA_ATAPI_IDENTIFY, 0, 0, 0);
341 xpt_print(path, "Spinning up device\n");
342 cam_fill_ataio(ataio,
345 /*flags*/CAM_DIR_NONE | CAM_HIGH_POWER,
350 ata_28bit_cmd(ataio, ATA_SETFEATURES, ATA_SF_PUIS_SPINUP, 0, 0);
357 /* Fetch user modes from SIM. */
358 bzero(&cts, sizeof(cts));
359 xpt_setup_ccb(&cts.ccb_h, path, CAM_PRIORITY_NONE);
360 cts.ccb_h.func_code = XPT_GET_TRAN_SETTINGS;
361 cts.type = CTS_TYPE_USER_SETTINGS;
362 xpt_action((union ccb *)&cts);
363 if (path->device->transport == XPORT_ATA) {
364 if (cts.xport_specific.ata.valid & CTS_ATA_VALID_MODE)
365 mode = cts.xport_specific.ata.mode;
367 if (cts.xport_specific.sata.valid & CTS_SATA_VALID_MODE)
368 mode = cts.xport_specific.sata.mode;
370 if (periph->path->device->protocol == PROTO_ATA) {
371 if (ata_dma == 0 && (mode == 0 || mode > ATA_PIO_MAX))
374 if (atapi_dma == 0 && (mode == 0 || mode > ATA_PIO_MAX))
378 /* Honor device capabilities. */
379 wantmode = mode = ata_max_mode(ident_buf, mode);
380 /* Report modes to SIM. */
381 bzero(&cts, sizeof(cts));
382 xpt_setup_ccb(&cts.ccb_h, path, CAM_PRIORITY_NONE);
383 cts.ccb_h.func_code = XPT_SET_TRAN_SETTINGS;
384 cts.type = CTS_TYPE_CURRENT_SETTINGS;
385 if (path->device->transport == XPORT_ATA) {
386 cts.xport_specific.ata.mode = mode;
387 cts.xport_specific.ata.valid = CTS_ATA_VALID_MODE;
389 cts.xport_specific.sata.mode = mode;
390 cts.xport_specific.sata.valid = CTS_SATA_VALID_MODE;
392 xpt_action((union ccb *)&cts);
393 /* Fetch current modes from SIM. */
394 bzero(&cts, sizeof(cts));
395 xpt_setup_ccb(&cts.ccb_h, path, CAM_PRIORITY_NONE);
396 cts.ccb_h.func_code = XPT_GET_TRAN_SETTINGS;
397 cts.type = CTS_TYPE_CURRENT_SETTINGS;
398 xpt_action((union ccb *)&cts);
399 if (path->device->transport == XPORT_ATA) {
400 if (cts.xport_specific.ata.valid & CTS_ATA_VALID_MODE)
401 mode = cts.xport_specific.ata.mode;
403 if (cts.xport_specific.ata.valid & CTS_SATA_VALID_MODE)
404 mode = cts.xport_specific.sata.mode;
406 /* If SIM disagree - renegotiate. */
407 if (mode != wantmode)
409 /* Remember what transport thinks about DMA. */
411 path->device->inq_flags &= ~SID_DMA;
413 path->device->inq_flags |= SID_DMA;
414 xpt_async(AC_GETDEV_CHANGED, path, NULL);
415 cam_fill_ataio(ataio,
418 /*flags*/CAM_DIR_NONE,
423 ata_28bit_cmd(ataio, ATA_SETFEATURES, ATA_SF_SETXFER, 0, mode);
427 cam_fill_ataio(ataio,
435 ata_28bit_cmd(ataio, ATA_SETFEATURES,
436 (softc->caps & CTS_SATA_CAPS_H_PMREQ) ? 0x10 : 0x90,
440 cam_fill_ataio(ataio,
448 ata_28bit_cmd(ataio, ATA_SETFEATURES,
449 (softc->caps & CTS_SATA_CAPS_H_APST) ? 0x10 : 0x90,
453 cam_fill_ataio(ataio,
461 ata_28bit_cmd(ataio, ATA_SETFEATURES,
462 (softc->caps & CTS_SATA_CAPS_H_DMAAA) ? 0x10 : 0x90,
466 /* Remember what transport thinks about AEN. */
467 if (softc->caps & CTS_SATA_CAPS_H_AN)
468 path->device->inq_flags |= SID_AEN;
470 path->device->inq_flags &= ~SID_AEN;
471 xpt_async(AC_GETDEV_CHANGED, path, NULL);
472 cam_fill_ataio(ataio,
480 ata_28bit_cmd(ataio, ATA_SETFEATURES,
481 (softc->caps & CTS_SATA_CAPS_H_AN) ? 0x10 : 0x90,
484 case PROBE_SET_MULTI:
486 u_int sectors, bytecount;
488 bytecount = 8192; /* SATA maximum */
489 /* Fetch user bytecount from SIM. */
490 bzero(&cts, sizeof(cts));
491 xpt_setup_ccb(&cts.ccb_h, path, CAM_PRIORITY_NONE);
492 cts.ccb_h.func_code = XPT_GET_TRAN_SETTINGS;
493 cts.type = CTS_TYPE_USER_SETTINGS;
494 xpt_action((union ccb *)&cts);
495 if (path->device->transport == XPORT_ATA) {
496 if (cts.xport_specific.ata.valid & CTS_ATA_VALID_BYTECOUNT)
497 bytecount = cts.xport_specific.ata.bytecount;
499 if (cts.xport_specific.sata.valid & CTS_SATA_VALID_BYTECOUNT)
500 bytecount = cts.xport_specific.sata.bytecount;
502 /* Honor device capabilities. */
503 sectors = max(1, min(ident_buf->sectors_intr & 0xff,
504 bytecount / ata_logical_sector_size(ident_buf)));
505 /* Report bytecount to SIM. */
506 bzero(&cts, sizeof(cts));
507 xpt_setup_ccb(&cts.ccb_h, path, CAM_PRIORITY_NONE);
508 cts.ccb_h.func_code = XPT_SET_TRAN_SETTINGS;
509 cts.type = CTS_TYPE_CURRENT_SETTINGS;
510 if (path->device->transport == XPORT_ATA) {
511 cts.xport_specific.ata.bytecount = sectors *
512 ata_logical_sector_size(ident_buf);
513 cts.xport_specific.ata.valid = CTS_ATA_VALID_BYTECOUNT;
515 cts.xport_specific.sata.bytecount = sectors *
516 ata_logical_sector_size(ident_buf);
517 cts.xport_specific.sata.valid = CTS_SATA_VALID_BYTECOUNT;
519 xpt_action((union ccb *)&cts);
520 /* Fetch current bytecount from SIM. */
521 bzero(&cts, sizeof(cts));
522 xpt_setup_ccb(&cts.ccb_h, path, CAM_PRIORITY_NONE);
523 cts.ccb_h.func_code = XPT_GET_TRAN_SETTINGS;
524 cts.type = CTS_TYPE_CURRENT_SETTINGS;
525 xpt_action((union ccb *)&cts);
526 if (path->device->transport == XPORT_ATA) {
527 if (cts.xport_specific.ata.valid & CTS_ATA_VALID_BYTECOUNT)
528 bytecount = cts.xport_specific.ata.bytecount;
530 if (cts.xport_specific.sata.valid & CTS_SATA_VALID_BYTECOUNT)
531 bytecount = cts.xport_specific.sata.bytecount;
533 sectors = bytecount / ata_logical_sector_size(ident_buf);
535 cam_fill_ataio(ataio,
543 ata_28bit_cmd(ataio, ATA_SET_MULTI, 0, 0, sectors);
550 bytecount = 8192; /* SATA maximum */
551 /* Fetch user bytecount from SIM. */
552 bzero(&cts, sizeof(cts));
553 xpt_setup_ccb(&cts.ccb_h, path, CAM_PRIORITY_NONE);
554 cts.ccb_h.func_code = XPT_GET_TRAN_SETTINGS;
555 cts.type = CTS_TYPE_USER_SETTINGS;
556 xpt_action((union ccb *)&cts);
557 if (path->device->transport == XPORT_ATA) {
558 if (cts.xport_specific.ata.valid & CTS_ATA_VALID_BYTECOUNT)
559 bytecount = cts.xport_specific.ata.bytecount;
561 if (cts.xport_specific.sata.valid & CTS_SATA_VALID_BYTECOUNT)
562 bytecount = cts.xport_specific.sata.bytecount;
564 /* Honor device capabilities. */
566 bytecount = max(2, min(65534, bytecount));
567 if (ident_buf->satacapabilities != 0x0000 &&
568 ident_buf->satacapabilities != 0xffff) {
569 bytecount = min(8192, bytecount);
571 /* Report bytecount to SIM. */
572 bzero(&cts, sizeof(cts));
573 xpt_setup_ccb(&cts.ccb_h, path, CAM_PRIORITY_NONE);
574 cts.ccb_h.func_code = XPT_SET_TRAN_SETTINGS;
575 cts.type = CTS_TYPE_CURRENT_SETTINGS;
576 if (path->device->transport == XPORT_ATA) {
577 cts.xport_specific.ata.bytecount = bytecount;
578 cts.xport_specific.ata.valid = CTS_ATA_VALID_BYTECOUNT;
580 cts.xport_specific.sata.bytecount = bytecount;
581 cts.xport_specific.sata.valid = CTS_SATA_VALID_BYTECOUNT;
583 xpt_action((union ccb *)&cts);
586 case PROBE_FULL_INQUIRY:
589 struct scsi_inquiry_data *inq_buf =
590 &periph->path->device->inq_data;
592 if (softc->action == PROBE_INQUIRY)
593 inquiry_len = SHORT_INQUIRY_LENGTH;
595 inquiry_len = SID_ADDITIONAL_LENGTH(inq_buf);
597 * Some parallel SCSI devices fail to send an
598 * ignore wide residue message when dealing with
599 * odd length inquiry requests. Round up to be
602 inquiry_len = roundup2(inquiry_len, 2);
612 /*timeout*/60 * 1000);
616 cam_fill_ataio(ataio,
619 /*flags*/CAM_DIR_NONE,
624 ata_pm_read_cmd(ataio, 0, 15);
627 cam_fill_ataio(ataio,
630 /*flags*/CAM_DIR_NONE,
635 ata_pm_read_cmd(ataio, 1, 15);
637 case PROBE_IDENTIFY_SES:
638 cam_fill_ataio(ataio,
643 /*data_ptr*/(u_int8_t *)&softc->ident_data,
644 /*dxfer_len*/sizeof(softc->ident_data),
646 ata_28bit_cmd(ataio, ATA_SEP_ATTN, 0xEC, 0x02,
647 sizeof(softc->ident_data) / 4);
649 case PROBE_IDENTIFY_SAFTE:
650 cam_fill_ataio(ataio,
655 /*data_ptr*/(u_int8_t *)&softc->ident_data,
656 /*dxfer_len*/sizeof(softc->ident_data),
658 ata_28bit_cmd(ataio, ATA_SEP_ATTN, 0xEC, 0x00,
659 sizeof(softc->ident_data) / 4);
662 panic("probestart: invalid action state 0x%x\n", softc->action);
664 xpt_action(start_ccb);
668 proberequestdefaultnegotiation(struct cam_periph *periph)
670 struct ccb_trans_settings cts;
672 xpt_setup_ccb(&cts.ccb_h, periph->path, CAM_PRIORITY_NONE);
673 cts.ccb_h.func_code = XPT_GET_TRAN_SETTINGS;
674 cts.type = CTS_TYPE_USER_SETTINGS;
675 xpt_action((union ccb *)&cts);
676 if ((cts.ccb_h.status & CAM_STATUS_MASK) != CAM_REQ_CMP)
678 cts.xport_specific.valid = 0;
679 cts.ccb_h.func_code = XPT_SET_TRAN_SETTINGS;
680 cts.type = CTS_TYPE_CURRENT_SETTINGS;
681 xpt_action((union ccb *)&cts);
685 probedone(struct cam_periph *periph, union ccb *done_ccb)
687 struct ccb_trans_settings cts;
688 struct ata_params *ident_buf;
689 struct scsi_inquiry_data *inq_buf;
691 struct cam_path *path;
695 int changed = 1, found = 1;
696 static const uint8_t fake_device_id_hdr[8] =
697 {0, SVPD_DEVICE_ID, 0, 12,
698 SVPD_ID_CODESET_BINARY, SVPD_ID_TYPE_NAA, 0, 8};
700 CAM_DEBUG(done_ccb->ccb_h.path, CAM_DEBUG_TRACE, ("probedone\n"));
702 softc = (probe_softc *)periph->softc;
703 path = done_ccb->ccb_h.path;
704 priority = done_ccb->ccb_h.pinfo.priority;
705 ident_buf = &path->device->ident_data;
706 inq_buf = &path->device->inq_data;
708 if ((done_ccb->ccb_h.status & CAM_STATUS_MASK) != CAM_REQ_CMP) {
709 if (cam_periph_error(done_ccb,
710 0, softc->restart ? (SF_NO_RECOVERY | SF_NO_RETRY) : 0,
713 if ((done_ccb->ccb_h.status & CAM_DEV_QFRZN) != 0) {
714 /* Don't wedge the queue */
715 xpt_release_devq(done_ccb->ccb_h.path, /*count*/1,
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 * Some Samsung SSDs report supported Asynchronous Notification,
755 * but return ABORT on attempt to enable it.
757 } else if (softc->action == PROBE_SETAN &&
758 status == CAM_ATA_STATUS_ERROR) {
762 * SES and SAF-TE SEPs have different IDENTIFY commands,
763 * but SATA specification doesn't tell how to identify them.
764 * Until better way found, just try another if first fail.
766 } else if (softc->action == PROBE_IDENTIFY_SES &&
767 status == CAM_ATA_STATUS_ERROR) {
768 PROBE_SET_ACTION(softc, PROBE_IDENTIFY_SAFTE);
769 xpt_release_ccb(done_ccb);
770 xpt_schedule(periph, priority);
775 * If we get to this point, we got an error status back
776 * from the inquiry and the error status doesn't require
777 * automatically retrying the command. Therefore, the
778 * inquiry failed. If we had inquiry information before
779 * for this device, but this latest inquiry command failed,
780 * the device has probably gone away. If this device isn't
781 * already marked unconfigured, notify the peripheral
782 * drivers that this device is no more.
784 device_fail: if ((path->device->flags & CAM_DEV_UNCONFIGURED) == 0)
785 xpt_async(AC_LOST_DEVICE, path, NULL);
786 PROBE_SET_ACTION(softc, PROBE_INVALID);
793 switch (softc->action) {
796 int sign = (done_ccb->ataio.res.lba_high << 8) +
797 done_ccb->ataio.res.lba_mid;
798 CAM_DEBUG(path, CAM_DEBUG_PROBE,
799 ("SIGNATURE: %04x\n", sign));
800 if (sign == 0x0000 &&
801 done_ccb->ccb_h.target_id != 15) {
802 path->device->protocol = PROTO_ATA;
803 PROBE_SET_ACTION(softc, PROBE_IDENTIFY);
804 } else if (sign == 0x9669 &&
805 done_ccb->ccb_h.target_id == 15) {
806 /* Report SIM that PM is present. */
807 bzero(&cts, sizeof(cts));
808 xpt_setup_ccb(&cts.ccb_h, path, CAM_PRIORITY_NONE);
809 cts.ccb_h.func_code = XPT_SET_TRAN_SETTINGS;
810 cts.type = CTS_TYPE_CURRENT_SETTINGS;
811 cts.xport_specific.sata.pm_present = 1;
812 cts.xport_specific.sata.valid = CTS_SATA_VALID_PM;
813 xpt_action((union ccb *)&cts);
814 path->device->protocol = PROTO_SATAPM;
815 PROBE_SET_ACTION(softc, PROBE_PM_PID);
816 } else if (sign == 0xc33c &&
817 done_ccb->ccb_h.target_id != 15) {
818 path->device->protocol = PROTO_SEMB;
819 PROBE_SET_ACTION(softc, PROBE_IDENTIFY_SES);
820 } else if (sign == 0xeb14 &&
821 done_ccb->ccb_h.target_id != 15) {
822 path->device->protocol = PROTO_SCSI;
823 PROBE_SET_ACTION(softc, PROBE_IDENTIFY);
825 if (done_ccb->ccb_h.target_id != 15) {
827 "Unexpected signature 0x%04x\n", sign);
831 xpt_release_ccb(done_ccb);
832 xpt_schedule(periph, priority);
837 struct ccb_pathinq cpi;
840 ident_buf = &softc->ident_data;
841 for (ptr = (int16_t *)ident_buf;
842 ptr < (int16_t *)ident_buf + sizeof(struct ata_params)/2; ptr++) {
843 *ptr = le16toh(*ptr);
845 if (strncmp(ident_buf->model, "FX", 2) &&
846 strncmp(ident_buf->model, "NEC", 3) &&
847 strncmp(ident_buf->model, "Pioneer", 7) &&
848 strncmp(ident_buf->model, "SHARP", 5)) {
849 ata_bswap(ident_buf->model, sizeof(ident_buf->model));
850 ata_bswap(ident_buf->revision, sizeof(ident_buf->revision));
851 ata_bswap(ident_buf->serial, sizeof(ident_buf->serial));
853 ata_btrim(ident_buf->model, sizeof(ident_buf->model));
854 ata_bpack(ident_buf->model, ident_buf->model, sizeof(ident_buf->model));
855 ata_btrim(ident_buf->revision, sizeof(ident_buf->revision));
856 ata_bpack(ident_buf->revision, ident_buf->revision, sizeof(ident_buf->revision));
857 ata_btrim(ident_buf->serial, sizeof(ident_buf->serial));
858 ata_bpack(ident_buf->serial, ident_buf->serial, sizeof(ident_buf->serial));
859 /* Device may need spin-up before IDENTIFY become valid. */
860 if ((ident_buf->specconf == 0x37c8 ||
861 ident_buf->specconf == 0x738c) &&
862 ((ident_buf->config & ATA_RESP_INCOMPLETE) ||
863 softc->spinup == 0)) {
864 PROBE_SET_ACTION(softc, PROBE_SPINUP);
865 xpt_release_ccb(done_ccb);
866 xpt_schedule(periph, priority);
869 ident_buf = &path->device->ident_data;
870 if ((periph->path->device->flags & CAM_DEV_UNCONFIGURED) == 0) {
871 /* Check that it is the same device. */
872 if (bcmp(softc->ident_data.model, ident_buf->model,
873 sizeof(ident_buf->model)) ||
874 bcmp(softc->ident_data.revision, ident_buf->revision,
875 sizeof(ident_buf->revision)) ||
876 bcmp(softc->ident_data.serial, ident_buf->serial,
877 sizeof(ident_buf->serial))) {
878 /* Device changed. */
879 xpt_async(AC_LOST_DEVICE, path, NULL);
881 bcopy(&softc->ident_data, ident_buf, sizeof(struct ata_params));
886 bcopy(&softc->ident_data, ident_buf, sizeof(struct ata_params));
887 /* Clean up from previous instance of this device */
888 if (path->device->serial_num != NULL) {
889 free(path->device->serial_num, M_CAMXPT);
890 path->device->serial_num = NULL;
891 path->device->serial_num_len = 0;
893 if (path->device->device_id != NULL) {
894 free(path->device->device_id, M_CAMXPT);
895 path->device->device_id = NULL;
896 path->device->device_id_len = 0;
898 path->device->serial_num =
899 (u_int8_t *)malloc((sizeof(ident_buf->serial) + 1),
901 if (path->device->serial_num != NULL) {
902 bcopy(ident_buf->serial,
903 path->device->serial_num,
904 sizeof(ident_buf->serial));
905 path->device->serial_num[sizeof(ident_buf->serial)]
907 path->device->serial_num_len =
908 strlen(path->device->serial_num);
910 if (ident_buf->enabled.extension &
911 ATA_SUPPORT_64BITWWN) {
912 path->device->device_id =
913 malloc(16, M_CAMXPT, M_NOWAIT);
914 if (path->device->device_id != NULL) {
915 path->device->device_id_len = 16;
916 bcopy(&fake_device_id_hdr,
917 path->device->device_id, 8);
918 bcopy(ident_buf->wwn,
919 path->device->device_id + 8, 8);
920 ata_bswap(path->device->device_id + 8, 8);
924 path->device->flags |= CAM_DEV_IDENTIFY_DATA_VALID;
925 xpt_async(AC_GETDEV_CHANGED, path, NULL);
927 if (ident_buf->satacapabilities & ATA_SUPPORT_NCQ) {
928 path->device->mintags = 2;
929 path->device->maxtags =
930 ATA_QUEUE_LEN(ident_buf->queue) + 1;
932 ata_find_quirk(path->device);
933 if (path->device->mintags != 0 &&
934 path->bus->sim->max_tagged_dev_openings != 0) {
935 /* Check if the SIM does not want queued commands. */
936 bzero(&cpi, sizeof(cpi));
937 xpt_setup_ccb(&cpi.ccb_h, path, CAM_PRIORITY_NONE);
938 cpi.ccb_h.func_code = XPT_PATH_INQ;
939 xpt_action((union ccb *)&cpi);
940 if (cpi.ccb_h.status == CAM_REQ_CMP &&
941 (cpi.hba_inquiry & PI_TAG_ABLE)) {
942 /* Report SIM which tags are allowed. */
943 bzero(&cts, sizeof(cts));
944 xpt_setup_ccb(&cts.ccb_h, path, CAM_PRIORITY_NONE);
945 cts.ccb_h.func_code = XPT_SET_TRAN_SETTINGS;
946 cts.type = CTS_TYPE_CURRENT_SETTINGS;
947 cts.xport_specific.sata.tags = path->device->maxtags;
948 cts.xport_specific.sata.valid = CTS_SATA_VALID_TAGS;
949 xpt_action((union ccb *)&cts);
952 ata_device_transport(path);
954 proberequestdefaultnegotiation(periph);
955 PROBE_SET_ACTION(softc, PROBE_SETMODE);
956 xpt_release_ccb(done_ccb);
957 xpt_schedule(periph, priority);
962 xpt_print(path, "Spin-up done\n");
964 PROBE_SET_ACTION(softc, PROBE_IDENTIFY);
965 xpt_release_ccb(done_ccb);
966 xpt_schedule(periph, priority);
969 /* Set supported bits. */
970 bzero(&cts, sizeof(cts));
971 xpt_setup_ccb(&cts.ccb_h, path, CAM_PRIORITY_NONE);
972 cts.ccb_h.func_code = XPT_GET_TRAN_SETTINGS;
973 cts.type = CTS_TYPE_CURRENT_SETTINGS;
974 xpt_action((union ccb *)&cts);
975 if (path->device->transport == XPORT_SATA &&
976 cts.xport_specific.sata.valid & CTS_SATA_VALID_CAPS)
977 caps = cts.xport_specific.sata.caps & CTS_SATA_CAPS_H;
978 else if (path->device->transport == XPORT_ATA &&
979 cts.xport_specific.ata.valid & CTS_ATA_VALID_CAPS)
980 caps = cts.xport_specific.ata.caps & CTS_ATA_CAPS_H;
983 if (path->device->transport == XPORT_SATA &&
984 ident_buf->satacapabilities != 0xffff) {
985 if (ident_buf->satacapabilities & ATA_SUPPORT_IFPWRMNGTRCV)
986 caps |= CTS_SATA_CAPS_D_PMREQ;
987 if (ident_buf->satacapabilities & ATA_SUPPORT_HAPST)
988 caps |= CTS_SATA_CAPS_D_APST;
990 /* Mask unwanted bits. */
991 bzero(&cts, sizeof(cts));
992 xpt_setup_ccb(&cts.ccb_h, path, CAM_PRIORITY_NONE);
993 cts.ccb_h.func_code = XPT_GET_TRAN_SETTINGS;
994 cts.type = CTS_TYPE_USER_SETTINGS;
995 xpt_action((union ccb *)&cts);
996 if (path->device->transport == XPORT_SATA &&
997 cts.xport_specific.sata.valid & CTS_SATA_VALID_CAPS)
998 caps &= cts.xport_specific.sata.caps;
999 else if (path->device->transport == XPORT_ATA &&
1000 cts.xport_specific.ata.valid & CTS_ATA_VALID_CAPS)
1001 caps &= cts.xport_specific.ata.caps;
1005 * Remember what transport thinks about 48-bit DMA. If
1006 * capability information is not provided or transport is
1007 * SATA, we take support for granted.
1009 if (!(path->device->inq_flags & SID_DMA) ||
1010 (path->device->transport == XPORT_ATA &&
1011 (cts.xport_specific.ata.valid & CTS_ATA_VALID_CAPS) &&
1012 !(caps & CTS_ATA_CAPS_H_DMA48)))
1013 path->device->inq_flags &= ~SID_DMA48;
1015 path->device->inq_flags |= SID_DMA48;
1016 /* Store result to SIM. */
1017 bzero(&cts, sizeof(cts));
1018 xpt_setup_ccb(&cts.ccb_h, path, CAM_PRIORITY_NONE);
1019 cts.ccb_h.func_code = XPT_SET_TRAN_SETTINGS;
1020 cts.type = CTS_TYPE_CURRENT_SETTINGS;
1021 if (path->device->transport == XPORT_SATA) {
1022 cts.xport_specific.sata.caps = caps;
1023 cts.xport_specific.sata.valid = CTS_SATA_VALID_CAPS;
1025 cts.xport_specific.ata.caps = caps;
1026 cts.xport_specific.ata.valid = CTS_ATA_VALID_CAPS;
1028 xpt_action((union ccb *)&cts);
1030 if (path->device->transport != XPORT_SATA)
1032 if ((ident_buf->satasupport & ATA_SUPPORT_IFPWRMNGT) &&
1033 (!(softc->caps & CTS_SATA_CAPS_H_PMREQ)) !=
1034 (!(ident_buf->sataenabled & ATA_SUPPORT_IFPWRMNGT))) {
1035 PROBE_SET_ACTION(softc, PROBE_SETPM);
1036 xpt_release_ccb(done_ccb);
1037 xpt_schedule(periph, priority);
1042 if (ident_buf->satacapabilities != 0xffff &&
1043 (ident_buf->satacapabilities & ATA_SUPPORT_DAPST) &&
1044 (!(softc->caps & CTS_SATA_CAPS_H_APST)) !=
1045 (!(ident_buf->sataenabled & ATA_ENABLED_DAPST))) {
1046 PROBE_SET_ACTION(softc, PROBE_SETAPST);
1047 xpt_release_ccb(done_ccb);
1048 xpt_schedule(periph, priority);
1053 if ((ident_buf->satasupport & ATA_SUPPORT_AUTOACTIVATE) &&
1054 (!(softc->caps & CTS_SATA_CAPS_H_DMAAA)) !=
1055 (!(ident_buf->sataenabled & ATA_SUPPORT_AUTOACTIVATE))) {
1056 PROBE_SET_ACTION(softc, PROBE_SETDMAAA);
1057 xpt_release_ccb(done_ccb);
1058 xpt_schedule(periph, priority);
1062 case PROBE_SETDMAAA:
1063 if ((ident_buf->satasupport & ATA_SUPPORT_ASYNCNOTIF) &&
1064 (!(softc->caps & CTS_SATA_CAPS_H_AN)) !=
1065 (!(ident_buf->sataenabled & ATA_SUPPORT_ASYNCNOTIF))) {
1066 PROBE_SET_ACTION(softc, PROBE_SETAN);
1067 xpt_release_ccb(done_ccb);
1068 xpt_schedule(periph, priority);
1074 if (path->device->protocol == PROTO_ATA) {
1075 PROBE_SET_ACTION(softc, PROBE_SET_MULTI);
1077 PROBE_SET_ACTION(softc, PROBE_INQUIRY);
1079 xpt_release_ccb(done_ccb);
1080 xpt_schedule(periph, priority);
1082 case PROBE_SET_MULTI:
1083 if (periph->path->device->flags & CAM_DEV_UNCONFIGURED) {
1084 path->device->flags &= ~CAM_DEV_UNCONFIGURED;
1085 xpt_acquire_device(path->device);
1086 done_ccb->ccb_h.func_code = XPT_GDEV_TYPE;
1087 xpt_action(done_ccb);
1088 xpt_async(AC_FOUND_DEVICE, done_ccb->ccb_h.path,
1091 PROBE_SET_ACTION(softc, PROBE_DONE);
1094 case PROBE_FULL_INQUIRY:
1096 u_int8_t periph_qual, len;
1098 path->device->flags |= CAM_DEV_INQUIRY_DATA_VALID;
1100 periph_qual = SID_QUAL(inq_buf);
1102 if (periph_qual != SID_QUAL_LU_CONNECTED)
1106 * We conservatively request only
1107 * SHORT_INQUIRY_LEN bytes of inquiry
1108 * information during our first try
1109 * at sending an INQUIRY. If the device
1110 * has more information to give,
1111 * perform a second request specifying
1112 * the amount of information the device
1113 * is willing to give.
1115 len = inq_buf->additional_length
1116 + offsetof(struct scsi_inquiry_data, additional_length) + 1;
1117 if (softc->action == PROBE_INQUIRY
1118 && len > SHORT_INQUIRY_LENGTH) {
1119 PROBE_SET_ACTION(softc, PROBE_FULL_INQUIRY);
1120 xpt_release_ccb(done_ccb);
1121 xpt_schedule(periph, priority);
1125 ata_device_transport(path);
1126 if (periph->path->device->flags & CAM_DEV_UNCONFIGURED) {
1127 path->device->flags &= ~CAM_DEV_UNCONFIGURED;
1128 xpt_acquire_device(path->device);
1129 done_ccb->ccb_h.func_code = XPT_GDEV_TYPE;
1130 xpt_action(done_ccb);
1131 xpt_async(AC_FOUND_DEVICE, done_ccb->ccb_h.path, done_ccb);
1133 PROBE_SET_ACTION(softc, PROBE_DONE);
1137 if ((path->device->flags & CAM_DEV_IDENTIFY_DATA_VALID) == 0)
1138 bzero(ident_buf, sizeof(*ident_buf));
1139 softc->pm_pid = (done_ccb->ataio.res.lba_high << 24) +
1140 (done_ccb->ataio.res.lba_mid << 16) +
1141 (done_ccb->ataio.res.lba_low << 8) +
1142 done_ccb->ataio.res.sector_count;
1143 ((uint32_t *)ident_buf)[0] = softc->pm_pid;
1144 snprintf(ident_buf->model, sizeof(ident_buf->model),
1145 "Port Multiplier %08x", softc->pm_pid);
1146 PROBE_SET_ACTION(softc, PROBE_PM_PRV);
1147 xpt_release_ccb(done_ccb);
1148 xpt_schedule(periph, priority);
1151 softc->pm_prv = (done_ccb->ataio.res.lba_high << 24) +
1152 (done_ccb->ataio.res.lba_mid << 16) +
1153 (done_ccb->ataio.res.lba_low << 8) +
1154 done_ccb->ataio.res.sector_count;
1155 ((uint32_t *)ident_buf)[1] = softc->pm_prv;
1156 snprintf(ident_buf->revision, sizeof(ident_buf->revision),
1157 "%04x", softc->pm_prv);
1158 path->device->flags |= CAM_DEV_IDENTIFY_DATA_VALID;
1159 ata_device_transport(path);
1160 if (periph->path->device->flags & CAM_DEV_UNCONFIGURED)
1161 proberequestdefaultnegotiation(periph);
1162 /* Set supported bits. */
1163 bzero(&cts, sizeof(cts));
1164 xpt_setup_ccb(&cts.ccb_h, path, CAM_PRIORITY_NONE);
1165 cts.ccb_h.func_code = XPT_GET_TRAN_SETTINGS;
1166 cts.type = CTS_TYPE_CURRENT_SETTINGS;
1167 xpt_action((union ccb *)&cts);
1168 if (cts.xport_specific.sata.valid & CTS_SATA_VALID_CAPS)
1169 caps = cts.xport_specific.sata.caps & CTS_SATA_CAPS_H;
1172 /* All PMPs must support PM requests. */
1173 caps |= CTS_SATA_CAPS_D_PMREQ;
1174 /* Mask unwanted bits. */
1175 bzero(&cts, sizeof(cts));
1176 xpt_setup_ccb(&cts.ccb_h, path, CAM_PRIORITY_NONE);
1177 cts.ccb_h.func_code = XPT_GET_TRAN_SETTINGS;
1178 cts.type = CTS_TYPE_USER_SETTINGS;
1179 xpt_action((union ccb *)&cts);
1180 if (cts.xport_specific.sata.valid & CTS_SATA_VALID_CAPS)
1181 caps &= cts.xport_specific.sata.caps;
1184 /* Remember what transport thinks about AEN. */
1185 if (caps & CTS_SATA_CAPS_H_AN)
1186 path->device->inq_flags |= SID_AEN;
1188 path->device->inq_flags &= ~SID_AEN;
1189 /* Store result to SIM. */
1190 bzero(&cts, sizeof(cts));
1191 xpt_setup_ccb(&cts.ccb_h, path, CAM_PRIORITY_NONE);
1192 cts.ccb_h.func_code = XPT_SET_TRAN_SETTINGS;
1193 cts.type = CTS_TYPE_CURRENT_SETTINGS;
1194 cts.xport_specific.sata.caps = caps;
1195 cts.xport_specific.sata.valid = CTS_SATA_VALID_CAPS;
1196 xpt_action((union ccb *)&cts);
1198 xpt_async(AC_GETDEV_CHANGED, path, NULL);
1199 if (periph->path->device->flags & CAM_DEV_UNCONFIGURED) {
1200 path->device->flags &= ~CAM_DEV_UNCONFIGURED;
1201 xpt_acquire_device(path->device);
1202 done_ccb->ccb_h.func_code = XPT_GDEV_TYPE;
1203 xpt_action(done_ccb);
1204 xpt_async(AC_FOUND_DEVICE, done_ccb->ccb_h.path,
1207 done_ccb->ccb_h.func_code = XPT_GDEV_TYPE;
1208 xpt_action(done_ccb);
1209 xpt_async(AC_SCSI_AEN, done_ccb->ccb_h.path, done_ccb);
1211 PROBE_SET_ACTION(softc, PROBE_DONE);
1213 case PROBE_IDENTIFY_SES:
1214 case PROBE_IDENTIFY_SAFTE:
1215 if ((periph->path->device->flags & CAM_DEV_UNCONFIGURED) == 0) {
1216 /* Check that it is the same device. */
1217 if (bcmp(&softc->ident_data, ident_buf, 53)) {
1218 /* Device changed. */
1219 xpt_async(AC_LOST_DEVICE, path, NULL);
1221 bcopy(&softc->ident_data, ident_buf, sizeof(struct ata_params));
1226 bcopy(&softc->ident_data, ident_buf, sizeof(struct ata_params));
1227 /* Clean up from previous instance of this device */
1228 if (path->device->device_id != NULL) {
1229 free(path->device->device_id, M_CAMXPT);
1230 path->device->device_id = NULL;
1231 path->device->device_id_len = 0;
1233 path->device->device_id =
1234 malloc(16, M_CAMXPT, M_NOWAIT);
1235 if (path->device->device_id != NULL) {
1236 path->device->device_id_len = 16;
1237 bcopy(&fake_device_id_hdr,
1238 path->device->device_id, 8);
1239 bcopy(((uint8_t*)ident_buf) + 2,
1240 path->device->device_id + 8, 8);
1243 path->device->flags |= CAM_DEV_IDENTIFY_DATA_VALID;
1245 ata_device_transport(path);
1247 proberequestdefaultnegotiation(periph);
1249 if (periph->path->device->flags & CAM_DEV_UNCONFIGURED) {
1250 path->device->flags &= ~CAM_DEV_UNCONFIGURED;
1251 xpt_acquire_device(path->device);
1252 done_ccb->ccb_h.func_code = XPT_GDEV_TYPE;
1253 xpt_action(done_ccb);
1254 xpt_async(AC_FOUND_DEVICE, done_ccb->ccb_h.path,
1257 PROBE_SET_ACTION(softc, PROBE_DONE);
1260 panic("probedone: invalid action state 0x%x\n", softc->action);
1263 if (softc->restart) {
1265 xpt_release_ccb(done_ccb);
1266 probeschedule(periph);
1269 xpt_release_ccb(done_ccb);
1270 CAM_DEBUG(periph->path, CAM_DEBUG_PROBE, ("Probe completed\n"));
1271 while ((done_ccb = (union ccb *)TAILQ_FIRST(&softc->request_ccbs))) {
1272 TAILQ_REMOVE(&softc->request_ccbs,
1273 &done_ccb->ccb_h, periph_links.tqe);
1274 done_ccb->ccb_h.status = found ? CAM_REQ_CMP : CAM_REQ_CMP_ERR;
1277 cam_periph_invalidate(periph);
1278 cam_release_devq(periph->path,
1279 RELSIM_RELEASE_RUNLEVEL, 0, CAM_RL_XPT + 1, FALSE);
1280 cam_periph_release_locked(periph);
1284 probecleanup(struct cam_periph *periph)
1286 free(periph->softc, M_CAMXPT);
1290 ata_find_quirk(struct cam_ed *device)
1292 struct ata_quirk_entry *quirk;
1295 match = cam_quirkmatch((caddr_t)&device->ident_data,
1296 (caddr_t)ata_quirk_table,
1297 ata_quirk_table_size,
1298 sizeof(*ata_quirk_table), ata_identify_match);
1301 panic("xpt_find_quirk: device didn't match wildcard entry!!");
1303 quirk = (struct ata_quirk_entry *)match;
1304 device->quirk = quirk;
1305 if (quirk->quirks & CAM_QUIRK_MAXTAGS) {
1306 device->mintags = quirk->mintags;
1307 device->maxtags = quirk->maxtags;
1312 union ccb *request_ccb;
1313 struct ccb_pathinq *cpi;
1315 } ata_scan_bus_info;
1318 * To start a scan, request_ccb is an XPT_SCAN_BUS ccb.
1319 * As the scan progresses, xpt_scan_bus is used as the
1320 * callback on completion function.
1323 ata_scan_bus(struct cam_periph *periph, union ccb *request_ccb)
1325 struct cam_path *path;
1326 ata_scan_bus_info *scan_info;
1327 union ccb *work_ccb, *reset_ccb;
1330 CAM_DEBUG(request_ccb->ccb_h.path, CAM_DEBUG_TRACE,
1331 ("xpt_scan_bus\n"));
1332 switch (request_ccb->ccb_h.func_code) {
1335 /* Find out the characteristics of the bus */
1336 work_ccb = xpt_alloc_ccb_nowait();
1337 if (work_ccb == NULL) {
1338 request_ccb->ccb_h.status = CAM_RESRC_UNAVAIL;
1339 xpt_done(request_ccb);
1342 xpt_setup_ccb(&work_ccb->ccb_h, request_ccb->ccb_h.path,
1343 request_ccb->ccb_h.pinfo.priority);
1344 work_ccb->ccb_h.func_code = XPT_PATH_INQ;
1345 xpt_action(work_ccb);
1346 if (work_ccb->ccb_h.status != CAM_REQ_CMP) {
1347 request_ccb->ccb_h.status = work_ccb->ccb_h.status;
1348 xpt_free_ccb(work_ccb);
1349 xpt_done(request_ccb);
1353 /* We may need to reset bus first, if we haven't done it yet. */
1354 if ((work_ccb->cpi.hba_inquiry &
1355 (PI_WIDE_32|PI_WIDE_16|PI_SDTR_ABLE)) &&
1356 !(work_ccb->cpi.hba_misc & PIM_NOBUSRESET) &&
1357 !timevalisset(&request_ccb->ccb_h.path->bus->last_reset)) {
1358 reset_ccb = xpt_alloc_ccb_nowait();
1359 if (reset_ccb == NULL) {
1360 request_ccb->ccb_h.status = CAM_RESRC_UNAVAIL;
1361 xpt_free_ccb(work_ccb);
1362 xpt_done(request_ccb);
1365 xpt_setup_ccb(&reset_ccb->ccb_h, request_ccb->ccb_h.path,
1367 reset_ccb->ccb_h.func_code = XPT_RESET_BUS;
1368 xpt_action(reset_ccb);
1369 if (reset_ccb->ccb_h.status != CAM_REQ_CMP) {
1370 request_ccb->ccb_h.status = reset_ccb->ccb_h.status;
1371 xpt_free_ccb(reset_ccb);
1372 xpt_free_ccb(work_ccb);
1373 xpt_done(request_ccb);
1376 xpt_free_ccb(reset_ccb);
1379 /* Save some state for use while we probe for devices */
1380 scan_info = (ata_scan_bus_info *)
1381 malloc(sizeof(ata_scan_bus_info), M_CAMXPT, M_NOWAIT);
1382 if (scan_info == NULL) {
1383 request_ccb->ccb_h.status = CAM_RESRC_UNAVAIL;
1384 xpt_free_ccb(work_ccb);
1385 xpt_done(request_ccb);
1388 scan_info->request_ccb = request_ccb;
1389 scan_info->cpi = &work_ccb->cpi;
1390 /* If PM supported, probe it first. */
1391 if (scan_info->cpi->hba_inquiry & PI_SATAPM)
1392 scan_info->counter = scan_info->cpi->max_target;
1394 scan_info->counter = 0;
1396 work_ccb = xpt_alloc_ccb_nowait();
1397 if (work_ccb == NULL) {
1398 free(scan_info, M_CAMXPT);
1399 request_ccb->ccb_h.status = CAM_RESRC_UNAVAIL;
1400 xpt_done(request_ccb);
1405 work_ccb = request_ccb;
1406 /* Reuse the same CCB to query if a device was really found */
1407 scan_info = (ata_scan_bus_info *)work_ccb->ccb_h.ppriv_ptr0;
1408 /* If there is PMP... */
1409 if ((scan_info->cpi->hba_inquiry & PI_SATAPM) &&
1410 (scan_info->counter == scan_info->cpi->max_target)) {
1411 if (work_ccb->ccb_h.status == CAM_REQ_CMP) {
1412 /* everything else will be probed by it */
1413 /* Free the current request path- we're done with it. */
1414 xpt_free_path(work_ccb->ccb_h.path);
1417 struct ccb_trans_settings cts;
1419 /* Report SIM that PM is absent. */
1420 bzero(&cts, sizeof(cts));
1421 xpt_setup_ccb(&cts.ccb_h,
1422 work_ccb->ccb_h.path, CAM_PRIORITY_NONE);
1423 cts.ccb_h.func_code = XPT_SET_TRAN_SETTINGS;
1424 cts.type = CTS_TYPE_CURRENT_SETTINGS;
1425 cts.xport_specific.sata.pm_present = 0;
1426 cts.xport_specific.sata.valid = CTS_SATA_VALID_PM;
1427 xpt_action((union ccb *)&cts);
1430 /* Free the current request path- we're done with it. */
1431 xpt_free_path(work_ccb->ccb_h.path);
1432 if (scan_info->counter ==
1433 ((scan_info->cpi->hba_inquiry & PI_SATAPM) ?
1434 0 : scan_info->cpi->max_target)) {
1436 xpt_free_ccb(work_ccb);
1437 xpt_free_ccb((union ccb *)scan_info->cpi);
1438 request_ccb = scan_info->request_ccb;
1439 free(scan_info, M_CAMXPT);
1440 request_ccb->ccb_h.status = CAM_REQ_CMP;
1441 xpt_done(request_ccb);
1444 /* Take next device. Wrap from max (PMP) to 0. */
1445 scan_info->counter = (scan_info->counter + 1 ) %
1446 (scan_info->cpi->max_target + 1);
1448 status = xpt_create_path(&path, NULL,
1449 scan_info->request_ccb->ccb_h.path_id,
1450 scan_info->counter, 0);
1451 if (status != CAM_REQ_CMP) {
1452 printf("xpt_scan_bus: xpt_create_path failed"
1453 " with status %#x, bus scan halted\n",
1455 xpt_free_ccb(work_ccb);
1456 xpt_free_ccb((union ccb *)scan_info->cpi);
1457 request_ccb = scan_info->request_ccb;
1458 free(scan_info, M_CAMXPT);
1459 request_ccb->ccb_h.status = status;
1460 xpt_done(request_ccb);
1463 xpt_setup_ccb(&work_ccb->ccb_h, path,
1464 scan_info->request_ccb->ccb_h.pinfo.priority);
1465 work_ccb->ccb_h.func_code = XPT_SCAN_LUN;
1466 work_ccb->ccb_h.cbfcnp = ata_scan_bus;
1467 work_ccb->ccb_h.ppriv_ptr0 = scan_info;
1468 work_ccb->crcn.flags = scan_info->request_ccb->crcn.flags;
1469 xpt_action(work_ccb);
1477 ata_scan_lun(struct cam_periph *periph, struct cam_path *path,
1478 cam_flags flags, union ccb *request_ccb)
1480 struct ccb_pathinq cpi;
1482 struct cam_path *new_path;
1483 struct cam_periph *old_periph;
1485 CAM_DEBUG(path, CAM_DEBUG_TRACE, ("xpt_scan_lun\n"));
1487 xpt_setup_ccb(&cpi.ccb_h, path, CAM_PRIORITY_NONE);
1488 cpi.ccb_h.func_code = XPT_PATH_INQ;
1489 xpt_action((union ccb *)&cpi);
1491 if (cpi.ccb_h.status != CAM_REQ_CMP) {
1492 if (request_ccb != NULL) {
1493 request_ccb->ccb_h.status = cpi.ccb_h.status;
1494 xpt_done(request_ccb);
1499 if (request_ccb == NULL) {
1500 request_ccb = xpt_alloc_ccb_nowait();
1501 if (request_ccb == NULL) {
1502 xpt_print(path, "xpt_scan_lun: can't allocate CCB, "
1503 "can't continue\n");
1506 status = xpt_create_path(&new_path, NULL,
1508 path->target->target_id,
1509 path->device->lun_id);
1510 if (status != CAM_REQ_CMP) {
1511 xpt_print(path, "xpt_scan_lun: can't create path, "
1512 "can't continue\n");
1513 xpt_free_ccb(request_ccb);
1516 xpt_setup_ccb(&request_ccb->ccb_h, new_path, CAM_PRIORITY_XPT);
1517 request_ccb->ccb_h.cbfcnp = xptscandone;
1518 request_ccb->ccb_h.func_code = XPT_SCAN_LUN;
1519 request_ccb->crcn.flags = flags;
1522 if ((old_periph = cam_periph_find(path, "aprobe")) != NULL) {
1523 if ((old_periph->flags & CAM_PERIPH_INVALID) == 0) {
1526 softc = (probe_softc *)old_periph->softc;
1527 TAILQ_INSERT_TAIL(&softc->request_ccbs,
1528 &request_ccb->ccb_h, periph_links.tqe);
1531 request_ccb->ccb_h.status = CAM_REQ_CMP_ERR;
1532 xpt_done(request_ccb);
1535 status = cam_periph_alloc(proberegister, NULL, probecleanup,
1536 probestart, "aprobe",
1538 request_ccb->ccb_h.path, NULL, 0,
1541 if (status != CAM_REQ_CMP) {
1542 xpt_print(path, "xpt_scan_lun: cam_alloc_periph "
1543 "returned an error, can't continue probe\n");
1544 request_ccb->ccb_h.status = status;
1545 xpt_done(request_ccb);
1551 xptscandone(struct cam_periph *periph, union ccb *done_ccb)
1554 xpt_free_path(done_ccb->ccb_h.path);
1555 xpt_free_ccb(done_ccb);
1558 static struct cam_ed *
1559 ata_alloc_device(struct cam_eb *bus, struct cam_et *target, lun_id_t lun_id)
1561 struct cam_path path;
1562 struct ata_quirk_entry *quirk;
1563 struct cam_ed *device;
1565 device = xpt_alloc_device(bus, target, lun_id);
1570 * Take the default quirk entry until we have inquiry
1571 * data and can determine a better quirk to use.
1573 quirk = &ata_quirk_table[ata_quirk_table_size - 1];
1574 device->quirk = (void *)quirk;
1575 device->mintags = 0;
1576 device->maxtags = 0;
1577 bzero(&device->inq_data, sizeof(device->inq_data));
1578 device->inq_flags = 0;
1579 device->queue_flags = 0;
1580 device->serial_num = NULL;
1581 device->serial_num_len = 0;
1584 * XXX should be limited by number of CCBs this bus can
1587 bus->sim->max_ccbs += device->ccbq.devq_openings;
1588 if (lun_id != CAM_LUN_WILDCARD) {
1589 xpt_compile_path(&path,
1594 ata_device_transport(&path);
1595 xpt_release_path(&path);
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) {
1722 owned = mtx_owned(start_ccb->ccb_h.path->bus->sim->mtx);
1724 mtx_lock(start_ccb->ccb_h.path->bus->sim->mtx);
1725 xpt_async(AC_ADVINFO_CHANGED, start_ccb->ccb_h.path,
1726 (void *)(uintptr_t)cdai->buftype);
1728 mtx_unlock(start_ccb->ccb_h.path->bus->sim->mtx);
1733 ata_action(union ccb *start_ccb)
1736 switch (start_ccb->ccb_h.func_code) {
1737 case XPT_SET_TRAN_SETTINGS:
1739 ata_set_transfer_settings(&start_ccb->cts,
1740 start_ccb->ccb_h.path->device,
1741 /*async_update*/FALSE);
1746 ata_scan_bus(start_ccb->ccb_h.path->periph, start_ccb);
1749 ata_scan_lun(start_ccb->ccb_h.path->periph,
1750 start_ccb->ccb_h.path, start_ccb->crcn.flags,
1753 case XPT_GET_TRAN_SETTINGS:
1755 ata_get_transfer_settings(&start_ccb->cts);
1760 struct cam_ed *device;
1763 device = start_ccb->ccb_h.path->device;
1764 if (device->protocol == PROTO_SCSI &&
1765 (device->flags & CAM_DEV_IDENTIFY_DATA_VALID)) {
1767 device->ident_data.config & ATA_PROTO_MASK;
1770 (device->ident_data.config == ATA_PROTO_CFA) ? 0 :
1771 (p == ATA_PROTO_ATAPI_16) ? 16 :
1772 (p == ATA_PROTO_ATAPI_12) ? 12 : 0;
1774 if (start_ccb->csio.cdb_len > maxlen) {
1775 start_ccb->ccb_h.status = CAM_REQ_INVALID;
1776 xpt_done(start_ccb);
1779 xpt_action_default(start_ccb);
1782 case XPT_DEV_ADVINFO:
1784 ata_dev_advinfo(start_ccb);
1788 xpt_action_default(start_ccb);
1794 ata_get_transfer_settings(struct ccb_trans_settings *cts)
1796 struct ccb_trans_settings_ata *ata;
1797 struct ccb_trans_settings_scsi *scsi;
1798 struct cam_ed *device;
1799 struct cam_sim *sim;
1801 device = cts->ccb_h.path->device;
1802 sim = cts->ccb_h.path->bus->sim;
1803 (*(sim->sim_action))(sim, (union ccb *)cts);
1805 if (cts->protocol == PROTO_UNKNOWN ||
1806 cts->protocol == PROTO_UNSPECIFIED) {
1807 cts->protocol = device->protocol;
1808 cts->protocol_version = device->protocol_version;
1811 if (cts->protocol == PROTO_ATA) {
1812 ata = &cts->proto_specific.ata;
1813 if ((ata->valid & CTS_ATA_VALID_TQ) == 0) {
1814 ata->valid |= CTS_ATA_VALID_TQ;
1815 if (cts->type == CTS_TYPE_USER_SETTINGS ||
1816 (device->flags & CAM_DEV_TAG_AFTER_COUNT) != 0 ||
1817 (device->inq_flags & SID_CmdQue) != 0)
1818 ata->flags |= CTS_ATA_FLAGS_TAG_ENB;
1821 if (cts->protocol == PROTO_SCSI) {
1822 scsi = &cts->proto_specific.scsi;
1823 if ((scsi->valid & CTS_SCSI_VALID_TQ) == 0) {
1824 scsi->valid |= CTS_SCSI_VALID_TQ;
1825 if (cts->type == CTS_TYPE_USER_SETTINGS ||
1826 (device->flags & CAM_DEV_TAG_AFTER_COUNT) != 0 ||
1827 (device->inq_flags & SID_CmdQue) != 0)
1828 scsi->flags |= CTS_SCSI_FLAGS_TAG_ENB;
1832 if (cts->transport == XPORT_UNKNOWN ||
1833 cts->transport == XPORT_UNSPECIFIED) {
1834 cts->transport = device->transport;
1835 cts->transport_version = device->transport_version;
1840 ata_set_transfer_settings(struct ccb_trans_settings *cts, struct cam_ed *device,
1843 struct ccb_pathinq cpi;
1844 struct ccb_trans_settings_ata *ata;
1845 struct ccb_trans_settings_scsi *scsi;
1846 struct cam_sim *sim;
1847 struct ata_params *ident_data;
1848 struct scsi_inquiry_data *inq_data;
1850 if (device == NULL) {
1851 cts->ccb_h.status = CAM_PATH_INVALID;
1852 xpt_done((union ccb *)cts);
1856 if (cts->protocol == PROTO_UNKNOWN
1857 || cts->protocol == PROTO_UNSPECIFIED) {
1858 cts->protocol = device->protocol;
1859 cts->protocol_version = device->protocol_version;
1862 if (cts->protocol_version == PROTO_VERSION_UNKNOWN
1863 || cts->protocol_version == PROTO_VERSION_UNSPECIFIED)
1864 cts->protocol_version = device->protocol_version;
1866 if (cts->protocol != device->protocol) {
1867 xpt_print(cts->ccb_h.path, "Uninitialized Protocol %x:%x?\n",
1868 cts->protocol, device->protocol);
1869 cts->protocol = device->protocol;
1872 if (cts->protocol_version > device->protocol_version) {
1874 xpt_print(cts->ccb_h.path, "Down reving Protocol "
1875 "Version from %d to %d?\n", cts->protocol_version,
1876 device->protocol_version);
1878 cts->protocol_version = device->protocol_version;
1881 if (cts->transport == XPORT_UNKNOWN
1882 || cts->transport == XPORT_UNSPECIFIED) {
1883 cts->transport = device->transport;
1884 cts->transport_version = device->transport_version;
1887 if (cts->transport_version == XPORT_VERSION_UNKNOWN
1888 || cts->transport_version == XPORT_VERSION_UNSPECIFIED)
1889 cts->transport_version = device->transport_version;
1891 if (cts->transport != device->transport) {
1892 xpt_print(cts->ccb_h.path, "Uninitialized Transport %x:%x?\n",
1893 cts->transport, device->transport);
1894 cts->transport = device->transport;
1897 if (cts->transport_version > device->transport_version) {
1899 xpt_print(cts->ccb_h.path, "Down reving Transport "
1900 "Version from %d to %d?\n", cts->transport_version,
1901 device->transport_version);
1903 cts->transport_version = device->transport_version;
1906 sim = cts->ccb_h.path->bus->sim;
1907 ident_data = &device->ident_data;
1908 inq_data = &device->inq_data;
1909 if (cts->protocol == PROTO_ATA)
1910 ata = &cts->proto_specific.ata;
1913 if (cts->protocol == PROTO_SCSI)
1914 scsi = &cts->proto_specific.scsi;
1917 xpt_setup_ccb(&cpi.ccb_h, cts->ccb_h.path, CAM_PRIORITY_NONE);
1918 cpi.ccb_h.func_code = XPT_PATH_INQ;
1919 xpt_action((union ccb *)&cpi);
1921 /* Sanity checking */
1922 if ((cpi.hba_inquiry & PI_TAG_ABLE) == 0
1923 || (ata && (ident_data->satacapabilities & ATA_SUPPORT_NCQ) == 0)
1924 || (scsi && (INQ_DATA_TQ_ENABLED(inq_data)) == 0)
1925 || (device->queue_flags & SCP_QUEUE_DQUE) != 0
1926 || (device->mintags == 0)) {
1928 * Can't tag on hardware that doesn't support tags,
1929 * doesn't have it enabled, or has broken tag support.
1932 ata->flags &= ~CTS_ATA_FLAGS_TAG_ENB;
1934 scsi->flags &= ~CTS_SCSI_FLAGS_TAG_ENB;
1937 /* Start/stop tags use. */
1938 if (cts->type == CTS_TYPE_CURRENT_SETTINGS &&
1939 ((ata && (ata->valid & CTS_ATA_VALID_TQ) != 0) ||
1940 (scsi && (scsi->valid & CTS_SCSI_VALID_TQ) != 0))) {
1943 nowt = ((device->flags & CAM_DEV_TAG_AFTER_COUNT) != 0 ||
1944 (device->inq_flags & SID_CmdQue) != 0);
1946 newt = (ata->flags & CTS_ATA_FLAGS_TAG_ENB) != 0;
1948 newt = (scsi->flags & CTS_SCSI_FLAGS_TAG_ENB) != 0;
1950 if (newt && !nowt) {
1952 * Delay change to use tags until after a
1953 * few commands have gone to this device so
1954 * the controller has time to perform transfer
1955 * negotiations without tagged messages getting
1958 device->tag_delay_count = CAM_TAG_DELAY_COUNT;
1959 device->flags |= CAM_DEV_TAG_AFTER_COUNT;
1960 } else if (nowt && !newt)
1961 xpt_stop_tags(cts->ccb_h.path);
1964 if (async_update == FALSE)
1965 (*(sim->sim_action))(sim, (union ccb *)cts);
1969 * Handle any per-device event notifications that require action by the XPT.
1972 ata_dev_async(u_int32_t async_code, struct cam_eb *bus, struct cam_et *target,
1973 struct cam_ed *device, void *async_arg)
1976 struct cam_path newpath;
1979 * We only need to handle events for real devices.
1981 if (target->target_id == CAM_TARGET_WILDCARD
1982 || device->lun_id == CAM_LUN_WILDCARD)
1986 * We need our own path with wildcards expanded to
1987 * handle certain types of events.
1989 if ((async_code == AC_SENT_BDR)
1990 || (async_code == AC_BUS_RESET)
1991 || (async_code == AC_INQ_CHANGED))
1992 status = xpt_compile_path(&newpath, NULL,
1997 status = CAM_REQ_CMP_ERR;
1999 if (status == CAM_REQ_CMP) {
2000 if (async_code == AC_INQ_CHANGED) {
2002 * We've sent a start unit command, or
2003 * something similar to a device that
2004 * may have caused its inquiry data to
2005 * change. So we re-scan the device to
2006 * refresh the inquiry data for it.
2008 ata_scan_lun(newpath.periph, &newpath,
2009 CAM_EXPECT_INQ_CHANGE, NULL);
2011 /* We need to reinitialize device after reset. */
2012 ata_scan_lun(newpath.periph, &newpath,
2015 xpt_release_path(&newpath);
2016 } else if (async_code == AC_LOST_DEVICE &&
2017 (device->flags & CAM_DEV_UNCONFIGURED) == 0) {
2018 device->flags |= CAM_DEV_UNCONFIGURED;
2019 xpt_release_device(device);
2020 } else if (async_code == AC_TRANSFER_NEG) {
2021 struct ccb_trans_settings *settings;
2023 settings = (struct ccb_trans_settings *)async_arg;
2024 ata_set_transfer_settings(settings, device,
2025 /*async_update*/TRUE);
2030 ata_announce_periph(struct cam_periph *periph)
2032 struct ccb_pathinq cpi;
2033 struct ccb_trans_settings cts;
2034 struct cam_path *path = periph->path;
2038 mtx_assert(periph->sim->mtx, MA_OWNED);
2040 xpt_setup_ccb(&cts.ccb_h, path, CAM_PRIORITY_NORMAL);
2041 cts.ccb_h.func_code = XPT_GET_TRAN_SETTINGS;
2042 cts.type = CTS_TYPE_CURRENT_SETTINGS;
2043 xpt_action((union ccb*)&cts);
2044 if ((cts.ccb_h.status & CAM_STATUS_MASK) != CAM_REQ_CMP)
2046 /* Ask the SIM for its base transfer speed */
2047 xpt_setup_ccb(&cpi.ccb_h, path, CAM_PRIORITY_NORMAL);
2048 cpi.ccb_h.func_code = XPT_PATH_INQ;
2049 xpt_action((union ccb *)&cpi);
2050 /* Report connection speed */
2051 speed = cpi.base_transfer_speed;
2052 if (cts.ccb_h.status == CAM_REQ_CMP && cts.transport == XPORT_ATA) {
2053 struct ccb_trans_settings_pata *pata =
2054 &cts.xport_specific.ata;
2056 if (pata->valid & CTS_ATA_VALID_MODE)
2057 speed = ata_mode2speed(pata->mode);
2059 if (cts.ccb_h.status == CAM_REQ_CMP && cts.transport == XPORT_SATA) {
2060 struct ccb_trans_settings_sata *sata =
2061 &cts.xport_specific.sata;
2063 if (sata->valid & CTS_SATA_VALID_REVISION)
2064 speed = ata_revision2speed(sata->revision);
2068 printf("%s%d: %d.%03dMB/s transfers",
2069 periph->periph_name, periph->unit_number,
2072 printf("%s%d: %dKB/s transfers", periph->periph_name,
2073 periph->unit_number, speed);
2074 /* Report additional information about connection */
2075 if (cts.ccb_h.status == CAM_REQ_CMP && cts.transport == XPORT_ATA) {
2076 struct ccb_trans_settings_pata *pata =
2077 &cts.xport_specific.ata;
2080 if (pata->valid & CTS_ATA_VALID_MODE)
2081 printf("%s, ", ata_mode2string(pata->mode));
2082 if ((pata->valid & CTS_ATA_VALID_ATAPI) && pata->atapi != 0)
2083 printf("ATAPI %dbytes, ", pata->atapi);
2084 if (pata->valid & CTS_ATA_VALID_BYTECOUNT)
2085 printf("PIO %dbytes", pata->bytecount);
2088 if (cts.ccb_h.status == CAM_REQ_CMP && cts.transport == XPORT_SATA) {
2089 struct ccb_trans_settings_sata *sata =
2090 &cts.xport_specific.sata;
2093 if (sata->valid & CTS_SATA_VALID_REVISION)
2094 printf("SATA %d.x, ", sata->revision);
2097 if (sata->valid & CTS_SATA_VALID_MODE)
2098 printf("%s, ", ata_mode2string(sata->mode));
2099 if ((sata->valid & CTS_ATA_VALID_ATAPI) && sata->atapi != 0)
2100 printf("ATAPI %dbytes, ", sata->atapi);
2101 if (sata->valid & CTS_SATA_VALID_BYTECOUNT)
2102 printf("PIO %dbytes", sata->bytecount);