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 (periph == NULL) {
228 printf("proberegister: periph was NULL!!\n");
229 return(CAM_REQ_CMP_ERR);
232 if (request_ccb == NULL) {
233 printf("proberegister: no probe CCB, "
234 "can't register device\n");
235 return(CAM_REQ_CMP_ERR);
238 softc = (probe_softc *)malloc(sizeof(*softc), M_CAMXPT, M_ZERO | M_NOWAIT);
241 printf("proberegister: Unable to probe new device. "
242 "Unable to allocate softc\n");
243 return(CAM_REQ_CMP_ERR);
245 TAILQ_INIT(&softc->request_ccbs);
246 TAILQ_INSERT_TAIL(&softc->request_ccbs, &request_ccb->ccb_h,
249 periph->softc = softc;
250 softc->periph = periph;
251 softc->action = PROBE_INVALID;
252 status = cam_periph_acquire(periph);
253 if (status != CAM_REQ_CMP) {
256 CAM_DEBUG(periph->path, CAM_DEBUG_PROBE, ("Probe started\n"));
259 * Ensure nobody slip in until probe finish.
261 cam_freeze_devq_arg(periph->path,
262 RELSIM_RELEASE_RUNLEVEL, CAM_RL_XPT + 1);
263 probeschedule(periph);
268 probeschedule(struct cam_periph *periph)
273 softc = (probe_softc *)periph->softc;
274 ccb = (union ccb *)TAILQ_FIRST(&softc->request_ccbs);
276 if ((periph->path->device->flags & CAM_DEV_UNCONFIGURED) ||
277 periph->path->device->protocol == PROTO_SATAPM ||
278 periph->path->device->protocol == PROTO_SEMB)
279 PROBE_SET_ACTION(softc, PROBE_RESET);
281 PROBE_SET_ACTION(softc, PROBE_IDENTIFY);
283 if (ccb->crcn.flags & CAM_EXPECT_INQ_CHANGE)
284 softc->flags |= PROBE_NO_ANNOUNCE;
286 softc->flags &= ~PROBE_NO_ANNOUNCE;
288 xpt_schedule(periph, CAM_PRIORITY_XPT);
292 probestart(struct cam_periph *periph, union ccb *start_ccb)
294 struct ccb_trans_settings cts;
295 struct ccb_ataio *ataio;
296 struct ccb_scsiio *csio;
298 struct cam_path *path;
299 struct ata_params *ident_buf;
301 CAM_DEBUG(start_ccb->ccb_h.path, CAM_DEBUG_TRACE, ("probestart\n"));
303 softc = (probe_softc *)periph->softc;
304 path = start_ccb->ccb_h.path;
305 ataio = &start_ccb->ataio;
306 csio = &start_ccb->csio;
307 ident_buf = &periph->path->device->ident_data;
309 if (softc->restart) {
311 if ((path->device->flags & CAM_DEV_UNCONFIGURED) ||
312 path->device->protocol == PROTO_SATAPM ||
313 path->device->protocol == PROTO_SEMB)
314 softc->action = PROBE_RESET;
316 softc->action = PROBE_IDENTIFY;
318 switch (softc->action) {
320 cam_fill_ataio(ataio,
323 /*flags*/CAM_DIR_NONE,
328 ata_reset_cmd(ataio);
331 cam_fill_ataio(ataio,
336 /*data_ptr*/(u_int8_t *)&softc->ident_data,
337 /*dxfer_len*/sizeof(softc->ident_data),
339 if (periph->path->device->protocol == PROTO_ATA)
340 ata_28bit_cmd(ataio, ATA_ATA_IDENTIFY, 0, 0, 0);
342 ata_28bit_cmd(ataio, ATA_ATAPI_IDENTIFY, 0, 0, 0);
346 xpt_print(path, "Spinning up device\n");
347 cam_fill_ataio(ataio,
350 /*flags*/CAM_DIR_NONE | CAM_HIGH_POWER,
355 ata_28bit_cmd(ataio, ATA_SETFEATURES, ATA_SF_PUIS_SPINUP, 0, 0);
362 /* Fetch user modes from SIM. */
363 bzero(&cts, sizeof(cts));
364 xpt_setup_ccb(&cts.ccb_h, path, CAM_PRIORITY_NONE);
365 cts.ccb_h.func_code = XPT_GET_TRAN_SETTINGS;
366 cts.type = CTS_TYPE_USER_SETTINGS;
367 xpt_action((union ccb *)&cts);
368 if (path->device->transport == XPORT_ATA) {
369 if (cts.xport_specific.ata.valid & CTS_ATA_VALID_MODE)
370 mode = cts.xport_specific.ata.mode;
372 if (cts.xport_specific.sata.valid & CTS_SATA_VALID_MODE)
373 mode = cts.xport_specific.sata.mode;
375 if (periph->path->device->protocol == PROTO_ATA) {
376 if (ata_dma == 0 && (mode == 0 || mode > ATA_PIO_MAX))
379 if (atapi_dma == 0 && (mode == 0 || mode > ATA_PIO_MAX))
383 /* Honor device capabilities. */
384 wantmode = mode = ata_max_mode(ident_buf, mode);
385 /* Report modes to SIM. */
386 bzero(&cts, sizeof(cts));
387 xpt_setup_ccb(&cts.ccb_h, path, CAM_PRIORITY_NONE);
388 cts.ccb_h.func_code = XPT_SET_TRAN_SETTINGS;
389 cts.type = CTS_TYPE_CURRENT_SETTINGS;
390 if (path->device->transport == XPORT_ATA) {
391 cts.xport_specific.ata.mode = mode;
392 cts.xport_specific.ata.valid = CTS_ATA_VALID_MODE;
394 cts.xport_specific.sata.mode = mode;
395 cts.xport_specific.sata.valid = CTS_SATA_VALID_MODE;
397 xpt_action((union ccb *)&cts);
398 /* Fetch current modes from SIM. */
399 bzero(&cts, sizeof(cts));
400 xpt_setup_ccb(&cts.ccb_h, path, CAM_PRIORITY_NONE);
401 cts.ccb_h.func_code = XPT_GET_TRAN_SETTINGS;
402 cts.type = CTS_TYPE_CURRENT_SETTINGS;
403 xpt_action((union ccb *)&cts);
404 if (path->device->transport == XPORT_ATA) {
405 if (cts.xport_specific.ata.valid & CTS_ATA_VALID_MODE)
406 mode = cts.xport_specific.ata.mode;
408 if (cts.xport_specific.ata.valid & CTS_SATA_VALID_MODE)
409 mode = cts.xport_specific.sata.mode;
411 /* If SIM disagree - renegotiate. */
412 if (mode != wantmode)
414 /* Remember what transport thinks about DMA. */
416 path->device->inq_flags &= ~SID_DMA;
418 path->device->inq_flags |= SID_DMA;
419 xpt_async(AC_GETDEV_CHANGED, path, NULL);
420 cam_fill_ataio(ataio,
423 /*flags*/CAM_DIR_NONE,
428 ata_28bit_cmd(ataio, ATA_SETFEATURES, ATA_SF_SETXFER, 0, mode);
432 cam_fill_ataio(ataio,
440 ata_28bit_cmd(ataio, ATA_SETFEATURES,
441 (softc->caps & CTS_SATA_CAPS_H_PMREQ) ? 0x10 : 0x90,
445 cam_fill_ataio(ataio,
453 ata_28bit_cmd(ataio, ATA_SETFEATURES,
454 (softc->caps & CTS_SATA_CAPS_H_APST) ? 0x10 : 0x90,
458 cam_fill_ataio(ataio,
466 ata_28bit_cmd(ataio, ATA_SETFEATURES,
467 (softc->caps & CTS_SATA_CAPS_H_DMAAA) ? 0x10 : 0x90,
471 cam_fill_ataio(ataio,
479 ata_28bit_cmd(ataio, ATA_SETFEATURES,
480 (softc->caps & CTS_SATA_CAPS_H_AN) ? 0x10 : 0x90,
483 case PROBE_SET_MULTI:
485 u_int sectors, bytecount;
487 bytecount = 8192; /* SATA maximum */
488 /* Fetch user bytecount from SIM. */
489 bzero(&cts, sizeof(cts));
490 xpt_setup_ccb(&cts.ccb_h, path, CAM_PRIORITY_NONE);
491 cts.ccb_h.func_code = XPT_GET_TRAN_SETTINGS;
492 cts.type = CTS_TYPE_USER_SETTINGS;
493 xpt_action((union ccb *)&cts);
494 if (path->device->transport == XPORT_ATA) {
495 if (cts.xport_specific.ata.valid & CTS_ATA_VALID_BYTECOUNT)
496 bytecount = cts.xport_specific.ata.bytecount;
498 if (cts.xport_specific.sata.valid & CTS_SATA_VALID_BYTECOUNT)
499 bytecount = cts.xport_specific.sata.bytecount;
501 /* Honor device capabilities. */
502 sectors = max(1, min(ident_buf->sectors_intr & 0xff,
503 bytecount / ata_logical_sector_size(ident_buf)));
504 /* Report bytecount to SIM. */
505 bzero(&cts, sizeof(cts));
506 xpt_setup_ccb(&cts.ccb_h, path, CAM_PRIORITY_NONE);
507 cts.ccb_h.func_code = XPT_SET_TRAN_SETTINGS;
508 cts.type = CTS_TYPE_CURRENT_SETTINGS;
509 if (path->device->transport == XPORT_ATA) {
510 cts.xport_specific.ata.bytecount = sectors *
511 ata_logical_sector_size(ident_buf);
512 cts.xport_specific.ata.valid = CTS_ATA_VALID_BYTECOUNT;
514 cts.xport_specific.sata.bytecount = sectors *
515 ata_logical_sector_size(ident_buf);
516 cts.xport_specific.sata.valid = CTS_SATA_VALID_BYTECOUNT;
518 xpt_action((union ccb *)&cts);
519 /* Fetch current bytecount from SIM. */
520 bzero(&cts, sizeof(cts));
521 xpt_setup_ccb(&cts.ccb_h, path, CAM_PRIORITY_NONE);
522 cts.ccb_h.func_code = XPT_GET_TRAN_SETTINGS;
523 cts.type = CTS_TYPE_CURRENT_SETTINGS;
524 xpt_action((union ccb *)&cts);
525 if (path->device->transport == XPORT_ATA) {
526 if (cts.xport_specific.ata.valid & CTS_ATA_VALID_BYTECOUNT)
527 bytecount = cts.xport_specific.ata.bytecount;
529 if (cts.xport_specific.sata.valid & CTS_SATA_VALID_BYTECOUNT)
530 bytecount = cts.xport_specific.sata.bytecount;
532 sectors = bytecount / ata_logical_sector_size(ident_buf);
534 cam_fill_ataio(ataio,
542 ata_28bit_cmd(ataio, ATA_SET_MULTI, 0, 0, sectors);
549 bytecount = 8192; /* SATA maximum */
550 /* Fetch user bytecount from SIM. */
551 bzero(&cts, sizeof(cts));
552 xpt_setup_ccb(&cts.ccb_h, path, CAM_PRIORITY_NONE);
553 cts.ccb_h.func_code = XPT_GET_TRAN_SETTINGS;
554 cts.type = CTS_TYPE_USER_SETTINGS;
555 xpt_action((union ccb *)&cts);
556 if (path->device->transport == XPORT_ATA) {
557 if (cts.xport_specific.ata.valid & CTS_ATA_VALID_BYTECOUNT)
558 bytecount = cts.xport_specific.ata.bytecount;
560 if (cts.xport_specific.sata.valid & CTS_SATA_VALID_BYTECOUNT)
561 bytecount = cts.xport_specific.sata.bytecount;
563 /* Honor device capabilities. */
565 bytecount = max(2, min(65534, bytecount));
566 if (ident_buf->satacapabilities != 0x0000 &&
567 ident_buf->satacapabilities != 0xffff) {
568 bytecount = min(8192, bytecount);
570 /* Report bytecount to SIM. */
571 bzero(&cts, sizeof(cts));
572 xpt_setup_ccb(&cts.ccb_h, path, CAM_PRIORITY_NONE);
573 cts.ccb_h.func_code = XPT_SET_TRAN_SETTINGS;
574 cts.type = CTS_TYPE_CURRENT_SETTINGS;
575 if (path->device->transport == XPORT_ATA) {
576 cts.xport_specific.ata.bytecount = bytecount;
577 cts.xport_specific.ata.valid = CTS_ATA_VALID_BYTECOUNT;
579 cts.xport_specific.sata.bytecount = bytecount;
580 cts.xport_specific.sata.valid = CTS_SATA_VALID_BYTECOUNT;
582 xpt_action((union ccb *)&cts);
585 case PROBE_FULL_INQUIRY:
588 struct scsi_inquiry_data *inq_buf =
589 &periph->path->device->inq_data;
591 if (softc->action == PROBE_INQUIRY)
592 inquiry_len = SHORT_INQUIRY_LENGTH;
594 inquiry_len = SID_ADDITIONAL_LENGTH(inq_buf);
596 * Some parallel SCSI devices fail to send an
597 * ignore wide residue message when dealing with
598 * odd length inquiry requests. Round up to be
601 inquiry_len = roundup2(inquiry_len, 2);
611 /*timeout*/60 * 1000);
615 cam_fill_ataio(ataio,
618 /*flags*/CAM_DIR_NONE,
623 ata_pm_read_cmd(ataio, 0, 15);
626 cam_fill_ataio(ataio,
629 /*flags*/CAM_DIR_NONE,
634 ata_pm_read_cmd(ataio, 1, 15);
636 case PROBE_IDENTIFY_SES:
637 cam_fill_ataio(ataio,
642 /*data_ptr*/(u_int8_t *)&softc->ident_data,
643 /*dxfer_len*/sizeof(softc->ident_data),
645 ata_28bit_cmd(ataio, ATA_SEP_ATTN, 0xEC, 0x02,
646 sizeof(softc->ident_data) / 4);
648 case PROBE_IDENTIFY_SAFTE:
649 cam_fill_ataio(ataio,
654 /*data_ptr*/(u_int8_t *)&softc->ident_data,
655 /*dxfer_len*/sizeof(softc->ident_data),
657 ata_28bit_cmd(ataio, ATA_SEP_ATTN, 0xEC, 0x00,
658 sizeof(softc->ident_data) / 4);
661 panic("probestart: invalid action state 0x%x\n", softc->action);
663 xpt_action(start_ccb);
667 proberequestdefaultnegotiation(struct cam_periph *periph)
669 struct ccb_trans_settings cts;
671 xpt_setup_ccb(&cts.ccb_h, periph->path, CAM_PRIORITY_NONE);
672 cts.ccb_h.func_code = XPT_GET_TRAN_SETTINGS;
673 cts.type = CTS_TYPE_USER_SETTINGS;
674 xpt_action((union ccb *)&cts);
675 if ((cts.ccb_h.status & CAM_STATUS_MASK) != CAM_REQ_CMP)
677 cts.xport_specific.valid = 0;
678 cts.ccb_h.func_code = XPT_SET_TRAN_SETTINGS;
679 cts.type = CTS_TYPE_CURRENT_SETTINGS;
680 xpt_action((union ccb *)&cts);
684 probedone(struct cam_periph *periph, union ccb *done_ccb)
686 struct ccb_trans_settings cts;
687 struct ata_params *ident_buf;
688 struct scsi_inquiry_data *inq_buf;
690 struct cam_path *path;
694 int changed = 1, found = 1;
695 static const uint8_t fake_device_id_hdr[8] =
696 {0, SVPD_DEVICE_ID, 0, 12,
697 SVPD_ID_CODESET_BINARY, SVPD_ID_TYPE_NAA, 0, 8};
699 CAM_DEBUG(done_ccb->ccb_h.path, CAM_DEBUG_TRACE, ("probedone\n"));
701 softc = (probe_softc *)periph->softc;
702 path = done_ccb->ccb_h.path;
703 priority = done_ccb->ccb_h.pinfo.priority;
704 ident_buf = &path->device->ident_data;
705 inq_buf = &path->device->inq_data;
707 if ((done_ccb->ccb_h.status & CAM_STATUS_MASK) != CAM_REQ_CMP) {
708 if (cam_periph_error(done_ccb,
709 0, softc->restart ? (SF_NO_RECOVERY | SF_NO_RETRY) : 0,
712 if ((done_ccb->ccb_h.status & CAM_DEV_QFRZN) != 0) {
713 /* Don't wedge the queue */
714 xpt_release_devq(done_ccb->ccb_h.path, /*count*/1,
717 status = done_ccb->ccb_h.status & CAM_STATUS_MASK;
718 if (softc->restart) {
720 if ((done_ccb->ccb_h.status & CAM_STATUS_MASK) ==
723 if (softc->faults < 10)
728 /* Old PIO2 devices may not support mode setting. */
729 } else if (softc->action == PROBE_SETMODE &&
730 status == CAM_ATA_STATUS_ERROR &&
731 ata_max_pmode(ident_buf) <= ATA_PIO2 &&
732 (ident_buf->capabilities1 & ATA_SUPPORT_IORDY) == 0) {
736 * Some old WD SATA disks report supported and enabled
737 * device-initiated interface power management, but return
738 * ABORT on attempt to disable it.
740 } else if (softc->action == PROBE_SETPM &&
741 status == CAM_ATA_STATUS_ERROR) {
745 * Some HP SATA disks report supported DMA Auto-Activation,
746 * but return ABORT on attempt to enable it.
748 } else if (softc->action == PROBE_SETDMAAA &&
749 status == CAM_ATA_STATUS_ERROR) {
753 * SES and SAF-TE SEPs have different IDENTIFY commands,
754 * but SATA specification doesn't tell how to identify them.
755 * Until better way found, just try another if first fail.
757 } else if (softc->action == PROBE_IDENTIFY_SES &&
758 status == CAM_ATA_STATUS_ERROR) {
759 PROBE_SET_ACTION(softc, PROBE_IDENTIFY_SAFTE);
760 xpt_release_ccb(done_ccb);
761 xpt_schedule(periph, priority);
766 * If we get to this point, we got an error status back
767 * from the inquiry and the error status doesn't require
768 * automatically retrying the command. Therefore, the
769 * inquiry failed. If we had inquiry information before
770 * for this device, but this latest inquiry command failed,
771 * the device has probably gone away. If this device isn't
772 * already marked unconfigured, notify the peripheral
773 * drivers that this device is no more.
775 device_fail: if ((path->device->flags & CAM_DEV_UNCONFIGURED) == 0)
776 xpt_async(AC_LOST_DEVICE, path, NULL);
777 PROBE_SET_ACTION(softc, PROBE_INVALID);
784 switch (softc->action) {
787 int sign = (done_ccb->ataio.res.lba_high << 8) +
788 done_ccb->ataio.res.lba_mid;
789 CAM_DEBUG(path, CAM_DEBUG_PROBE,
790 ("SIGNATURE: %04x\n", sign));
791 if (sign == 0x0000 &&
792 done_ccb->ccb_h.target_id != 15) {
793 path->device->protocol = PROTO_ATA;
794 PROBE_SET_ACTION(softc, PROBE_IDENTIFY);
795 } else if (sign == 0x9669 &&
796 done_ccb->ccb_h.target_id == 15) {
797 /* Report SIM that PM is present. */
798 bzero(&cts, sizeof(cts));
799 xpt_setup_ccb(&cts.ccb_h, path, CAM_PRIORITY_NONE);
800 cts.ccb_h.func_code = XPT_SET_TRAN_SETTINGS;
801 cts.type = CTS_TYPE_CURRENT_SETTINGS;
802 cts.xport_specific.sata.pm_present = 1;
803 cts.xport_specific.sata.valid = CTS_SATA_VALID_PM;
804 xpt_action((union ccb *)&cts);
805 path->device->protocol = PROTO_SATAPM;
806 PROBE_SET_ACTION(softc, PROBE_PM_PID);
807 } else if (sign == 0xc33c &&
808 done_ccb->ccb_h.target_id != 15) {
809 path->device->protocol = PROTO_SEMB;
810 PROBE_SET_ACTION(softc, PROBE_IDENTIFY_SES);
811 } else if (sign == 0xeb14 &&
812 done_ccb->ccb_h.target_id != 15) {
813 path->device->protocol = PROTO_SCSI;
814 PROBE_SET_ACTION(softc, PROBE_IDENTIFY);
816 if (done_ccb->ccb_h.target_id != 15) {
818 "Unexpected signature 0x%04x\n", sign);
822 xpt_release_ccb(done_ccb);
823 xpt_schedule(periph, priority);
828 struct ccb_pathinq cpi;
831 ident_buf = &softc->ident_data;
832 for (ptr = (int16_t *)ident_buf;
833 ptr < (int16_t *)ident_buf + sizeof(struct ata_params)/2; ptr++) {
834 *ptr = le16toh(*ptr);
836 if (strncmp(ident_buf->model, "FX", 2) &&
837 strncmp(ident_buf->model, "NEC", 3) &&
838 strncmp(ident_buf->model, "Pioneer", 7) &&
839 strncmp(ident_buf->model, "SHARP", 5)) {
840 ata_bswap(ident_buf->model, sizeof(ident_buf->model));
841 ata_bswap(ident_buf->revision, sizeof(ident_buf->revision));
842 ata_bswap(ident_buf->serial, sizeof(ident_buf->serial));
844 ata_btrim(ident_buf->model, sizeof(ident_buf->model));
845 ata_bpack(ident_buf->model, ident_buf->model, sizeof(ident_buf->model));
846 ata_btrim(ident_buf->revision, sizeof(ident_buf->revision));
847 ata_bpack(ident_buf->revision, ident_buf->revision, sizeof(ident_buf->revision));
848 ata_btrim(ident_buf->serial, sizeof(ident_buf->serial));
849 ata_bpack(ident_buf->serial, ident_buf->serial, sizeof(ident_buf->serial));
850 /* Device may need spin-up before IDENTIFY become valid. */
851 if ((ident_buf->specconf == 0x37c8 ||
852 ident_buf->specconf == 0x738c) &&
853 ((ident_buf->config & ATA_RESP_INCOMPLETE) ||
854 softc->spinup == 0)) {
855 PROBE_SET_ACTION(softc, PROBE_SPINUP);
856 xpt_release_ccb(done_ccb);
857 xpt_schedule(periph, priority);
860 ident_buf = &path->device->ident_data;
861 if ((periph->path->device->flags & CAM_DEV_UNCONFIGURED) == 0) {
862 /* Check that it is the same device. */
863 if (bcmp(softc->ident_data.model, ident_buf->model,
864 sizeof(ident_buf->model)) ||
865 bcmp(softc->ident_data.revision, ident_buf->revision,
866 sizeof(ident_buf->revision)) ||
867 bcmp(softc->ident_data.serial, ident_buf->serial,
868 sizeof(ident_buf->serial))) {
869 /* Device changed. */
870 xpt_async(AC_LOST_DEVICE, path, NULL);
872 bcopy(&softc->ident_data, ident_buf, sizeof(struct ata_params));
877 bcopy(&softc->ident_data, ident_buf, sizeof(struct ata_params));
878 /* Clean up from previous instance of this device */
879 if (path->device->serial_num != NULL) {
880 free(path->device->serial_num, M_CAMXPT);
881 path->device->serial_num = NULL;
882 path->device->serial_num_len = 0;
884 if (path->device->device_id != NULL) {
885 free(path->device->device_id, M_CAMXPT);
886 path->device->device_id = NULL;
887 path->device->device_id_len = 0;
889 path->device->serial_num =
890 (u_int8_t *)malloc((sizeof(ident_buf->serial) + 1),
892 if (path->device->serial_num != NULL) {
893 bcopy(ident_buf->serial,
894 path->device->serial_num,
895 sizeof(ident_buf->serial));
896 path->device->serial_num[sizeof(ident_buf->serial)]
898 path->device->serial_num_len =
899 strlen(path->device->serial_num);
901 if (ident_buf->enabled.extension &
902 ATA_SUPPORT_64BITWWN) {
903 path->device->device_id =
904 malloc(16, M_CAMXPT, M_NOWAIT);
905 if (path->device->device_id != NULL) {
906 path->device->device_id_len = 16;
907 bcopy(&fake_device_id_hdr,
908 path->device->device_id, 8);
909 bcopy(ident_buf->wwn,
910 path->device->device_id + 8, 8);
914 path->device->flags |= CAM_DEV_IDENTIFY_DATA_VALID;
915 xpt_async(AC_GETDEV_CHANGED, path, NULL);
917 if (ident_buf->satacapabilities & ATA_SUPPORT_NCQ) {
918 path->device->mintags = 2;
919 path->device->maxtags =
920 ATA_QUEUE_LEN(ident_buf->queue) + 1;
922 ata_find_quirk(path->device);
923 if (path->device->mintags != 0 &&
924 path->bus->sim->max_tagged_dev_openings != 0) {
925 /* Check if the SIM does not want queued commands. */
926 bzero(&cpi, sizeof(cpi));
927 xpt_setup_ccb(&cpi.ccb_h, path, CAM_PRIORITY_NONE);
928 cpi.ccb_h.func_code = XPT_PATH_INQ;
929 xpt_action((union ccb *)&cpi);
930 if (cpi.ccb_h.status == CAM_REQ_CMP &&
931 (cpi.hba_inquiry & PI_TAG_ABLE)) {
932 /* Report SIM which tags are allowed. */
933 bzero(&cts, sizeof(cts));
934 xpt_setup_ccb(&cts.ccb_h, path, CAM_PRIORITY_NONE);
935 cts.ccb_h.func_code = XPT_SET_TRAN_SETTINGS;
936 cts.type = CTS_TYPE_CURRENT_SETTINGS;
937 cts.xport_specific.sata.tags = path->device->maxtags;
938 cts.xport_specific.sata.valid = CTS_SATA_VALID_TAGS;
939 xpt_action((union ccb *)&cts);
942 ata_device_transport(path);
944 proberequestdefaultnegotiation(periph);
945 PROBE_SET_ACTION(softc, PROBE_SETMODE);
946 xpt_release_ccb(done_ccb);
947 xpt_schedule(periph, priority);
952 xpt_print(path, "Spin-up done\n");
954 PROBE_SET_ACTION(softc, PROBE_IDENTIFY);
955 xpt_release_ccb(done_ccb);
956 xpt_schedule(periph, priority);
959 if (path->device->transport != XPORT_SATA)
961 /* Set supported bits. */
962 bzero(&cts, sizeof(cts));
963 xpt_setup_ccb(&cts.ccb_h, path, CAM_PRIORITY_NONE);
964 cts.ccb_h.func_code = XPT_GET_TRAN_SETTINGS;
965 cts.type = CTS_TYPE_CURRENT_SETTINGS;
966 xpt_action((union ccb *)&cts);
967 if (cts.xport_specific.sata.valid & CTS_SATA_VALID_CAPS)
968 caps = cts.xport_specific.sata.caps & CTS_SATA_CAPS_H;
971 if (ident_buf->satacapabilities != 0xffff) {
972 if (ident_buf->satacapabilities & ATA_SUPPORT_IFPWRMNGTRCV)
973 caps |= CTS_SATA_CAPS_D_PMREQ;
974 if (ident_buf->satacapabilities & ATA_SUPPORT_HAPST)
975 caps |= CTS_SATA_CAPS_D_APST;
977 /* Mask unwanted bits. */
978 bzero(&cts, sizeof(cts));
979 xpt_setup_ccb(&cts.ccb_h, path, CAM_PRIORITY_NONE);
980 cts.ccb_h.func_code = XPT_GET_TRAN_SETTINGS;
981 cts.type = CTS_TYPE_USER_SETTINGS;
982 xpt_action((union ccb *)&cts);
983 if (cts.xport_specific.sata.valid & CTS_SATA_VALID_CAPS)
984 caps &= cts.xport_specific.sata.caps;
987 /* Store result to SIM. */
988 bzero(&cts, sizeof(cts));
989 xpt_setup_ccb(&cts.ccb_h, path, CAM_PRIORITY_NONE);
990 cts.ccb_h.func_code = XPT_SET_TRAN_SETTINGS;
991 cts.type = CTS_TYPE_CURRENT_SETTINGS;
992 cts.xport_specific.sata.caps = caps;
993 cts.xport_specific.sata.valid = CTS_SATA_VALID_CAPS;
994 xpt_action((union ccb *)&cts);
996 if ((ident_buf->satasupport & ATA_SUPPORT_IFPWRMNGT) &&
997 (!(softc->caps & CTS_SATA_CAPS_H_PMREQ)) !=
998 (!(ident_buf->sataenabled & ATA_SUPPORT_IFPWRMNGT))) {
999 PROBE_SET_ACTION(softc, PROBE_SETPM);
1000 xpt_release_ccb(done_ccb);
1001 xpt_schedule(periph, priority);
1006 if (ident_buf->satacapabilities != 0xffff &&
1007 (ident_buf->satacapabilities & ATA_SUPPORT_DAPST) &&
1008 (!(softc->caps & CTS_SATA_CAPS_H_APST)) !=
1009 (!(ident_buf->sataenabled & ATA_ENABLED_DAPST))) {
1010 PROBE_SET_ACTION(softc, PROBE_SETAPST);
1011 xpt_release_ccb(done_ccb);
1012 xpt_schedule(periph, priority);
1017 if ((ident_buf->satasupport & ATA_SUPPORT_AUTOACTIVATE) &&
1018 (!(softc->caps & CTS_SATA_CAPS_H_DMAAA)) !=
1019 (!(ident_buf->sataenabled & ATA_SUPPORT_AUTOACTIVATE))) {
1020 PROBE_SET_ACTION(softc, PROBE_SETDMAAA);
1021 xpt_release_ccb(done_ccb);
1022 xpt_schedule(periph, priority);
1026 case PROBE_SETDMAAA:
1027 if ((ident_buf->satasupport & ATA_SUPPORT_ASYNCNOTIF) &&
1028 (!(softc->caps & CTS_SATA_CAPS_H_AN)) !=
1029 (!(ident_buf->sataenabled & ATA_SUPPORT_ASYNCNOTIF))) {
1030 PROBE_SET_ACTION(softc, PROBE_SETAN);
1031 xpt_release_ccb(done_ccb);
1032 xpt_schedule(periph, priority);
1038 if (path->device->protocol == PROTO_ATA) {
1039 PROBE_SET_ACTION(softc, PROBE_SET_MULTI);
1041 PROBE_SET_ACTION(softc, PROBE_INQUIRY);
1043 xpt_release_ccb(done_ccb);
1044 xpt_schedule(periph, priority);
1046 case PROBE_SET_MULTI:
1047 if (periph->path->device->flags & CAM_DEV_UNCONFIGURED) {
1048 path->device->flags &= ~CAM_DEV_UNCONFIGURED;
1049 xpt_acquire_device(path->device);
1050 done_ccb->ccb_h.func_code = XPT_GDEV_TYPE;
1051 xpt_action(done_ccb);
1052 xpt_async(AC_FOUND_DEVICE, done_ccb->ccb_h.path,
1055 PROBE_SET_ACTION(softc, PROBE_DONE);
1058 case PROBE_FULL_INQUIRY:
1060 u_int8_t periph_qual, len;
1062 path->device->flags |= CAM_DEV_INQUIRY_DATA_VALID;
1064 periph_qual = SID_QUAL(inq_buf);
1066 if (periph_qual != SID_QUAL_LU_CONNECTED)
1070 * We conservatively request only
1071 * SHORT_INQUIRY_LEN bytes of inquiry
1072 * information during our first try
1073 * at sending an INQUIRY. If the device
1074 * has more information to give,
1075 * perform a second request specifying
1076 * the amount of information the device
1077 * is willing to give.
1079 len = inq_buf->additional_length
1080 + offsetof(struct scsi_inquiry_data, additional_length) + 1;
1081 if (softc->action == PROBE_INQUIRY
1082 && len > SHORT_INQUIRY_LENGTH) {
1083 PROBE_SET_ACTION(softc, PROBE_FULL_INQUIRY);
1084 xpt_release_ccb(done_ccb);
1085 xpt_schedule(periph, priority);
1089 ata_device_transport(path);
1090 if (periph->path->device->flags & CAM_DEV_UNCONFIGURED) {
1091 path->device->flags &= ~CAM_DEV_UNCONFIGURED;
1092 xpt_acquire_device(path->device);
1093 done_ccb->ccb_h.func_code = XPT_GDEV_TYPE;
1094 xpt_action(done_ccb);
1095 xpt_async(AC_FOUND_DEVICE, done_ccb->ccb_h.path, done_ccb);
1097 PROBE_SET_ACTION(softc, PROBE_DONE);
1101 if ((path->device->flags & CAM_DEV_IDENTIFY_DATA_VALID) == 0)
1102 bzero(ident_buf, sizeof(*ident_buf));
1103 softc->pm_pid = (done_ccb->ataio.res.lba_high << 24) +
1104 (done_ccb->ataio.res.lba_mid << 16) +
1105 (done_ccb->ataio.res.lba_low << 8) +
1106 done_ccb->ataio.res.sector_count;
1107 ((uint32_t *)ident_buf)[0] = softc->pm_pid;
1108 snprintf(ident_buf->model, sizeof(ident_buf->model),
1109 "Port Multiplier %08x", softc->pm_pid);
1110 PROBE_SET_ACTION(softc, PROBE_PM_PRV);
1111 xpt_release_ccb(done_ccb);
1112 xpt_schedule(periph, priority);
1115 softc->pm_prv = (done_ccb->ataio.res.lba_high << 24) +
1116 (done_ccb->ataio.res.lba_mid << 16) +
1117 (done_ccb->ataio.res.lba_low << 8) +
1118 done_ccb->ataio.res.sector_count;
1119 ((uint32_t *)ident_buf)[1] = softc->pm_prv;
1120 snprintf(ident_buf->revision, sizeof(ident_buf->revision),
1121 "%04x", softc->pm_prv);
1122 path->device->flags |= CAM_DEV_IDENTIFY_DATA_VALID;
1123 ata_device_transport(path);
1124 if (periph->path->device->flags & CAM_DEV_UNCONFIGURED)
1125 proberequestdefaultnegotiation(periph);
1126 /* Set supported bits. */
1127 bzero(&cts, sizeof(cts));
1128 xpt_setup_ccb(&cts.ccb_h, path, CAM_PRIORITY_NONE);
1129 cts.ccb_h.func_code = XPT_GET_TRAN_SETTINGS;
1130 cts.type = CTS_TYPE_CURRENT_SETTINGS;
1131 xpt_action((union ccb *)&cts);
1132 if (cts.xport_specific.sata.valid & CTS_SATA_VALID_CAPS)
1133 caps = cts.xport_specific.sata.caps & CTS_SATA_CAPS_H;
1136 /* All PMPs must support PM requests. */
1137 caps |= CTS_SATA_CAPS_D_PMREQ;
1138 /* Mask unwanted bits. */
1139 bzero(&cts, sizeof(cts));
1140 xpt_setup_ccb(&cts.ccb_h, path, CAM_PRIORITY_NONE);
1141 cts.ccb_h.func_code = XPT_GET_TRAN_SETTINGS;
1142 cts.type = CTS_TYPE_USER_SETTINGS;
1143 xpt_action((union ccb *)&cts);
1144 if (cts.xport_specific.sata.valid & CTS_SATA_VALID_CAPS)
1145 caps &= cts.xport_specific.sata.caps;
1148 /* Store result to SIM. */
1149 bzero(&cts, sizeof(cts));
1150 xpt_setup_ccb(&cts.ccb_h, path, CAM_PRIORITY_NONE);
1151 cts.ccb_h.func_code = XPT_SET_TRAN_SETTINGS;
1152 cts.type = CTS_TYPE_CURRENT_SETTINGS;
1153 cts.xport_specific.sata.caps = caps;
1154 cts.xport_specific.sata.valid = CTS_SATA_VALID_CAPS;
1155 xpt_action((union ccb *)&cts);
1157 if (periph->path->device->flags & CAM_DEV_UNCONFIGURED) {
1158 path->device->flags &= ~CAM_DEV_UNCONFIGURED;
1159 xpt_acquire_device(path->device);
1160 done_ccb->ccb_h.func_code = XPT_GDEV_TYPE;
1161 xpt_action(done_ccb);
1162 xpt_async(AC_FOUND_DEVICE, done_ccb->ccb_h.path,
1165 done_ccb->ccb_h.func_code = XPT_GDEV_TYPE;
1166 xpt_action(done_ccb);
1167 xpt_async(AC_SCSI_AEN, done_ccb->ccb_h.path, done_ccb);
1169 PROBE_SET_ACTION(softc, PROBE_DONE);
1171 case PROBE_IDENTIFY_SES:
1172 case PROBE_IDENTIFY_SAFTE:
1173 if ((periph->path->device->flags & CAM_DEV_UNCONFIGURED) == 0) {
1174 /* Check that it is the same device. */
1175 if (bcmp(&softc->ident_data, ident_buf, 53)) {
1176 /* Device changed. */
1177 xpt_async(AC_LOST_DEVICE, path, NULL);
1179 bcopy(&softc->ident_data, ident_buf, sizeof(struct ata_params));
1184 bcopy(&softc->ident_data, ident_buf, sizeof(struct ata_params));
1185 /* Clean up from previous instance of this device */
1186 if (path->device->device_id != NULL) {
1187 free(path->device->device_id, M_CAMXPT);
1188 path->device->device_id = NULL;
1189 path->device->device_id_len = 0;
1191 path->device->device_id =
1192 malloc(16, M_CAMXPT, M_NOWAIT);
1193 if (path->device->device_id != NULL) {
1194 path->device->device_id_len = 16;
1195 bcopy(&fake_device_id_hdr,
1196 path->device->device_id, 8);
1197 bcopy(((uint8_t*)ident_buf) + 2,
1198 path->device->device_id + 8, 8);
1201 path->device->flags |= CAM_DEV_IDENTIFY_DATA_VALID;
1203 ata_device_transport(path);
1205 proberequestdefaultnegotiation(periph);
1207 if (periph->path->device->flags & CAM_DEV_UNCONFIGURED) {
1208 path->device->flags &= ~CAM_DEV_UNCONFIGURED;
1209 xpt_acquire_device(path->device);
1210 done_ccb->ccb_h.func_code = XPT_GDEV_TYPE;
1211 xpt_action(done_ccb);
1212 xpt_async(AC_FOUND_DEVICE, done_ccb->ccb_h.path,
1215 PROBE_SET_ACTION(softc, PROBE_DONE);
1218 panic("probedone: invalid action state 0x%x\n", softc->action);
1221 if (softc->restart) {
1223 xpt_release_ccb(done_ccb);
1224 probeschedule(periph);
1227 xpt_release_ccb(done_ccb);
1228 CAM_DEBUG(periph->path, CAM_DEBUG_PROBE, ("Probe completed\n"));
1229 while ((done_ccb = (union ccb *)TAILQ_FIRST(&softc->request_ccbs))) {
1230 TAILQ_REMOVE(&softc->request_ccbs,
1231 &done_ccb->ccb_h, periph_links.tqe);
1232 done_ccb->ccb_h.status = found ? CAM_REQ_CMP : CAM_REQ_CMP_ERR;
1235 cam_periph_invalidate(periph);
1236 cam_release_devq(periph->path,
1237 RELSIM_RELEASE_RUNLEVEL, 0, CAM_RL_XPT + 1, FALSE);
1238 cam_periph_release_locked(periph);
1242 probecleanup(struct cam_periph *periph)
1244 free(periph->softc, M_CAMXPT);
1248 ata_find_quirk(struct cam_ed *device)
1250 struct ata_quirk_entry *quirk;
1253 match = cam_quirkmatch((caddr_t)&device->ident_data,
1254 (caddr_t)ata_quirk_table,
1255 ata_quirk_table_size,
1256 sizeof(*ata_quirk_table), ata_identify_match);
1259 panic("xpt_find_quirk: device didn't match wildcard entry!!");
1261 quirk = (struct ata_quirk_entry *)match;
1262 device->quirk = quirk;
1263 if (quirk->quirks & CAM_QUIRK_MAXTAGS) {
1264 device->mintags = quirk->mintags;
1265 device->maxtags = quirk->maxtags;
1270 union ccb *request_ccb;
1271 struct ccb_pathinq *cpi;
1273 } ata_scan_bus_info;
1276 * To start a scan, request_ccb is an XPT_SCAN_BUS ccb.
1277 * As the scan progresses, xpt_scan_bus is used as the
1278 * callback on completion function.
1281 ata_scan_bus(struct cam_periph *periph, union ccb *request_ccb)
1283 struct cam_path *path;
1284 ata_scan_bus_info *scan_info;
1285 union ccb *work_ccb, *reset_ccb;
1288 CAM_DEBUG(request_ccb->ccb_h.path, CAM_DEBUG_TRACE,
1289 ("xpt_scan_bus\n"));
1290 switch (request_ccb->ccb_h.func_code) {
1293 /* Find out the characteristics of the bus */
1294 work_ccb = xpt_alloc_ccb_nowait();
1295 if (work_ccb == NULL) {
1296 request_ccb->ccb_h.status = CAM_RESRC_UNAVAIL;
1297 xpt_done(request_ccb);
1300 xpt_setup_ccb(&work_ccb->ccb_h, request_ccb->ccb_h.path,
1301 request_ccb->ccb_h.pinfo.priority);
1302 work_ccb->ccb_h.func_code = XPT_PATH_INQ;
1303 xpt_action(work_ccb);
1304 if (work_ccb->ccb_h.status != CAM_REQ_CMP) {
1305 request_ccb->ccb_h.status = work_ccb->ccb_h.status;
1306 xpt_free_ccb(work_ccb);
1307 xpt_done(request_ccb);
1311 /* We may need to reset bus first, if we haven't done it yet. */
1312 if ((work_ccb->cpi.hba_inquiry &
1313 (PI_WIDE_32|PI_WIDE_16|PI_SDTR_ABLE)) &&
1314 !(work_ccb->cpi.hba_misc & PIM_NOBUSRESET) &&
1315 !timevalisset(&request_ccb->ccb_h.path->bus->last_reset)) {
1316 reset_ccb = xpt_alloc_ccb_nowait();
1317 if (reset_ccb == NULL) {
1318 request_ccb->ccb_h.status = CAM_RESRC_UNAVAIL;
1319 xpt_free_ccb(work_ccb);
1320 xpt_done(request_ccb);
1323 xpt_setup_ccb(&reset_ccb->ccb_h, request_ccb->ccb_h.path,
1325 reset_ccb->ccb_h.func_code = XPT_RESET_BUS;
1326 xpt_action(reset_ccb);
1327 if (reset_ccb->ccb_h.status != CAM_REQ_CMP) {
1328 request_ccb->ccb_h.status = reset_ccb->ccb_h.status;
1329 xpt_free_ccb(reset_ccb);
1330 xpt_free_ccb(work_ccb);
1331 xpt_done(request_ccb);
1334 xpt_free_ccb(reset_ccb);
1337 /* Save some state for use while we probe for devices */
1338 scan_info = (ata_scan_bus_info *)
1339 malloc(sizeof(ata_scan_bus_info), M_CAMXPT, M_NOWAIT);
1340 if (scan_info == NULL) {
1341 request_ccb->ccb_h.status = CAM_RESRC_UNAVAIL;
1342 xpt_free_ccb(work_ccb);
1343 xpt_done(request_ccb);
1346 scan_info->request_ccb = request_ccb;
1347 scan_info->cpi = &work_ccb->cpi;
1348 /* If PM supported, probe it first. */
1349 if (scan_info->cpi->hba_inquiry & PI_SATAPM)
1350 scan_info->counter = scan_info->cpi->max_target;
1352 scan_info->counter = 0;
1354 work_ccb = xpt_alloc_ccb_nowait();
1355 if (work_ccb == NULL) {
1356 free(scan_info, M_CAMXPT);
1357 request_ccb->ccb_h.status = CAM_RESRC_UNAVAIL;
1358 xpt_done(request_ccb);
1363 work_ccb = request_ccb;
1364 /* Reuse the same CCB to query if a device was really found */
1365 scan_info = (ata_scan_bus_info *)work_ccb->ccb_h.ppriv_ptr0;
1366 /* If there is PMP... */
1367 if ((scan_info->cpi->hba_inquiry & PI_SATAPM) &&
1368 (scan_info->counter == scan_info->cpi->max_target)) {
1369 if (work_ccb->ccb_h.status == CAM_REQ_CMP) {
1370 /* everything else will be probed by it */
1371 /* Free the current request path- we're done with it. */
1372 xpt_free_path(work_ccb->ccb_h.path);
1375 struct ccb_trans_settings cts;
1377 /* Report SIM that PM is absent. */
1378 bzero(&cts, sizeof(cts));
1379 xpt_setup_ccb(&cts.ccb_h,
1380 work_ccb->ccb_h.path, CAM_PRIORITY_NONE);
1381 cts.ccb_h.func_code = XPT_SET_TRAN_SETTINGS;
1382 cts.type = CTS_TYPE_CURRENT_SETTINGS;
1383 cts.xport_specific.sata.pm_present = 0;
1384 cts.xport_specific.sata.valid = CTS_SATA_VALID_PM;
1385 xpt_action((union ccb *)&cts);
1388 /* Free the current request path- we're done with it. */
1389 xpt_free_path(work_ccb->ccb_h.path);
1390 if (scan_info->counter ==
1391 ((scan_info->cpi->hba_inquiry & PI_SATAPM) ?
1392 0 : scan_info->cpi->max_target)) {
1394 xpt_free_ccb(work_ccb);
1395 xpt_free_ccb((union ccb *)scan_info->cpi);
1396 request_ccb = scan_info->request_ccb;
1397 free(scan_info, M_CAMXPT);
1398 request_ccb->ccb_h.status = CAM_REQ_CMP;
1399 xpt_done(request_ccb);
1402 /* Take next device. Wrap from max (PMP) to 0. */
1403 scan_info->counter = (scan_info->counter + 1 ) %
1404 (scan_info->cpi->max_target + 1);
1406 status = xpt_create_path(&path, xpt_periph,
1407 scan_info->request_ccb->ccb_h.path_id,
1408 scan_info->counter, 0);
1409 if (status != CAM_REQ_CMP) {
1410 printf("xpt_scan_bus: xpt_create_path failed"
1411 " with status %#x, bus scan halted\n",
1413 xpt_free_ccb(work_ccb);
1414 xpt_free_ccb((union ccb *)scan_info->cpi);
1415 request_ccb = scan_info->request_ccb;
1416 free(scan_info, M_CAMXPT);
1417 request_ccb->ccb_h.status = status;
1418 xpt_done(request_ccb);
1421 xpt_setup_ccb(&work_ccb->ccb_h, path,
1422 scan_info->request_ccb->ccb_h.pinfo.priority);
1423 work_ccb->ccb_h.func_code = XPT_SCAN_LUN;
1424 work_ccb->ccb_h.cbfcnp = ata_scan_bus;
1425 work_ccb->ccb_h.ppriv_ptr0 = scan_info;
1426 work_ccb->crcn.flags = scan_info->request_ccb->crcn.flags;
1427 xpt_action(work_ccb);
1435 ata_scan_lun(struct cam_periph *periph, struct cam_path *path,
1436 cam_flags flags, union ccb *request_ccb)
1438 struct ccb_pathinq cpi;
1440 struct cam_path *new_path;
1441 struct cam_periph *old_periph;
1443 CAM_DEBUG(path, CAM_DEBUG_TRACE, ("xpt_scan_lun\n"));
1445 xpt_setup_ccb(&cpi.ccb_h, path, CAM_PRIORITY_NONE);
1446 cpi.ccb_h.func_code = XPT_PATH_INQ;
1447 xpt_action((union ccb *)&cpi);
1449 if (cpi.ccb_h.status != CAM_REQ_CMP) {
1450 if (request_ccb != NULL) {
1451 request_ccb->ccb_h.status = cpi.ccb_h.status;
1452 xpt_done(request_ccb);
1457 if (request_ccb == NULL) {
1458 request_ccb = malloc(sizeof(union ccb), M_CAMXPT, M_NOWAIT);
1459 if (request_ccb == NULL) {
1460 xpt_print(path, "xpt_scan_lun: can't allocate CCB, "
1461 "can't continue\n");
1464 new_path = malloc(sizeof(*new_path), M_CAMXPT, M_NOWAIT);
1465 if (new_path == NULL) {
1466 xpt_print(path, "xpt_scan_lun: can't allocate path, "
1467 "can't continue\n");
1468 free(request_ccb, M_CAMXPT);
1471 status = xpt_compile_path(new_path, xpt_periph,
1473 path->target->target_id,
1474 path->device->lun_id);
1476 if (status != CAM_REQ_CMP) {
1477 xpt_print(path, "xpt_scan_lun: can't compile path, "
1478 "can't continue\n");
1479 free(request_ccb, M_CAMXPT);
1480 free(new_path, M_CAMXPT);
1483 xpt_setup_ccb(&request_ccb->ccb_h, new_path, CAM_PRIORITY_XPT);
1484 request_ccb->ccb_h.cbfcnp = xptscandone;
1485 request_ccb->ccb_h.func_code = XPT_SCAN_LUN;
1486 request_ccb->crcn.flags = flags;
1489 if ((old_periph = cam_periph_find(path, "aprobe")) != NULL) {
1490 if ((old_periph->flags & CAM_PERIPH_INVALID) == 0) {
1493 softc = (probe_softc *)old_periph->softc;
1494 TAILQ_INSERT_TAIL(&softc->request_ccbs,
1495 &request_ccb->ccb_h, periph_links.tqe);
1498 request_ccb->ccb_h.status = CAM_REQ_CMP_ERR;
1499 xpt_done(request_ccb);
1502 status = cam_periph_alloc(proberegister, NULL, probecleanup,
1503 probestart, "aprobe",
1505 request_ccb->ccb_h.path, NULL, 0,
1508 if (status != CAM_REQ_CMP) {
1509 xpt_print(path, "xpt_scan_lun: cam_alloc_periph "
1510 "returned an error, can't continue probe\n");
1511 request_ccb->ccb_h.status = status;
1512 xpt_done(request_ccb);
1518 xptscandone(struct cam_periph *periph, union ccb *done_ccb)
1520 xpt_release_path(done_ccb->ccb_h.path);
1521 free(done_ccb->ccb_h.path, M_CAMXPT);
1522 free(done_ccb, M_CAMXPT);
1525 static struct cam_ed *
1526 ata_alloc_device(struct cam_eb *bus, struct cam_et *target, lun_id_t lun_id)
1528 struct cam_path path;
1529 struct ata_quirk_entry *quirk;
1530 struct cam_ed *device;
1531 struct cam_ed *cur_device;
1533 device = xpt_alloc_device(bus, target, lun_id);
1538 * Take the default quirk entry until we have inquiry
1539 * data and can determine a better quirk to use.
1541 quirk = &ata_quirk_table[ata_quirk_table_size - 1];
1542 device->quirk = (void *)quirk;
1543 device->mintags = 0;
1544 device->maxtags = 0;
1545 bzero(&device->inq_data, sizeof(device->inq_data));
1546 device->inq_flags = 0;
1547 device->queue_flags = 0;
1548 device->serial_num = NULL;
1549 device->serial_num_len = 0;
1552 * XXX should be limited by number of CCBs this bus can
1555 bus->sim->max_ccbs += device->ccbq.devq_openings;
1556 /* Insertion sort into our target's device list */
1557 cur_device = TAILQ_FIRST(&target->ed_entries);
1558 while (cur_device != NULL && cur_device->lun_id < lun_id)
1559 cur_device = TAILQ_NEXT(cur_device, links);
1560 if (cur_device != NULL) {
1561 TAILQ_INSERT_BEFORE(cur_device, device, links);
1563 TAILQ_INSERT_TAIL(&target->ed_entries, device, links);
1565 target->generation++;
1566 if (lun_id != CAM_LUN_WILDCARD) {
1567 xpt_compile_path(&path,
1572 ata_device_transport(&path);
1573 xpt_release_path(&path);
1580 ata_device_transport(struct cam_path *path)
1582 struct ccb_pathinq cpi;
1583 struct ccb_trans_settings cts;
1584 struct scsi_inquiry_data *inq_buf = NULL;
1585 struct ata_params *ident_buf = NULL;
1587 /* Get transport information from the SIM */
1588 xpt_setup_ccb(&cpi.ccb_h, path, CAM_PRIORITY_NONE);
1589 cpi.ccb_h.func_code = XPT_PATH_INQ;
1590 xpt_action((union ccb *)&cpi);
1592 path->device->transport = cpi.transport;
1593 if ((path->device->flags & CAM_DEV_INQUIRY_DATA_VALID) != 0)
1594 inq_buf = &path->device->inq_data;
1595 if ((path->device->flags & CAM_DEV_IDENTIFY_DATA_VALID) != 0)
1596 ident_buf = &path->device->ident_data;
1597 if (path->device->protocol == PROTO_ATA) {
1598 path->device->protocol_version = ident_buf ?
1599 ata_version(ident_buf->version_major) : cpi.protocol_version;
1600 } else if (path->device->protocol == PROTO_SCSI) {
1601 path->device->protocol_version = inq_buf ?
1602 SID_ANSI_REV(inq_buf) : cpi.protocol_version;
1604 path->device->transport_version = ident_buf ?
1605 ata_version(ident_buf->version_major) : cpi.transport_version;
1607 /* Tell the controller what we think */
1608 xpt_setup_ccb(&cts.ccb_h, path, CAM_PRIORITY_NONE);
1609 cts.ccb_h.func_code = XPT_SET_TRAN_SETTINGS;
1610 cts.type = CTS_TYPE_CURRENT_SETTINGS;
1611 cts.transport = path->device->transport;
1612 cts.transport_version = path->device->transport_version;
1613 cts.protocol = path->device->protocol;
1614 cts.protocol_version = path->device->protocol_version;
1615 cts.proto_specific.valid = 0;
1617 if (path->device->transport == XPORT_ATA) {
1618 cts.xport_specific.ata.atapi =
1619 (ident_buf->config == ATA_PROTO_CFA) ? 0 :
1620 ((ident_buf->config & ATA_PROTO_MASK) == ATA_PROTO_ATAPI_16) ? 16 :
1621 ((ident_buf->config & ATA_PROTO_MASK) == ATA_PROTO_ATAPI_12) ? 12 : 0;
1622 cts.xport_specific.ata.valid = CTS_ATA_VALID_ATAPI;
1624 cts.xport_specific.sata.atapi =
1625 (ident_buf->config == ATA_PROTO_CFA) ? 0 :
1626 ((ident_buf->config & ATA_PROTO_MASK) == ATA_PROTO_ATAPI_16) ? 16 :
1627 ((ident_buf->config & ATA_PROTO_MASK) == ATA_PROTO_ATAPI_12) ? 12 : 0;
1628 cts.xport_specific.sata.valid = CTS_SATA_VALID_ATAPI;
1631 cts.xport_specific.valid = 0;
1632 xpt_action((union ccb *)&cts);
1636 ata_dev_advinfo(union ccb *start_ccb)
1638 struct cam_ed *device;
1639 struct ccb_dev_advinfo *cdai;
1642 start_ccb->ccb_h.status = CAM_REQ_INVALID;
1643 device = start_ccb->ccb_h.path->device;
1644 cdai = &start_ccb->cdai;
1645 switch(cdai->buftype) {
1646 case CDAI_TYPE_SCSI_DEVID:
1647 if (cdai->flags & CDAI_FLAG_STORE)
1649 cdai->provsiz = device->device_id_len;
1650 if (device->device_id_len == 0)
1652 amt = device->device_id_len;
1653 if (cdai->provsiz > cdai->bufsiz)
1655 memcpy(cdai->buf, device->device_id, amt);
1657 case CDAI_TYPE_SERIAL_NUM:
1658 if (cdai->flags & CDAI_FLAG_STORE)
1660 cdai->provsiz = device->serial_num_len;
1661 if (device->serial_num_len == 0)
1663 amt = device->serial_num_len;
1664 if (cdai->provsiz > cdai->bufsiz)
1666 memcpy(cdai->buf, device->serial_num, amt);
1668 case CDAI_TYPE_PHYS_PATH:
1669 if (cdai->flags & CDAI_FLAG_STORE) {
1670 if (device->physpath != NULL)
1671 free(device->physpath, M_CAMXPT);
1672 device->physpath_len = cdai->bufsiz;
1673 /* Clear existing buffer if zero length */
1674 if (cdai->bufsiz == 0)
1676 device->physpath = malloc(cdai->bufsiz, M_CAMXPT, M_NOWAIT);
1677 if (device->physpath == NULL) {
1678 start_ccb->ccb_h.status = CAM_REQ_ABORTED;
1681 memcpy(device->physpath, cdai->buf, cdai->bufsiz);
1683 cdai->provsiz = device->physpath_len;
1684 if (device->physpath_len == 0)
1686 amt = device->physpath_len;
1687 if (cdai->provsiz > cdai->bufsiz)
1689 memcpy(cdai->buf, device->physpath, amt);
1695 start_ccb->ccb_h.status = CAM_REQ_CMP;
1697 if (cdai->flags & CDAI_FLAG_STORE) {
1700 owned = mtx_owned(start_ccb->ccb_h.path->bus->sim->mtx);
1702 mtx_lock(start_ccb->ccb_h.path->bus->sim->mtx);
1703 xpt_async(AC_ADVINFO_CHANGED, start_ccb->ccb_h.path,
1704 (void *)(uintptr_t)cdai->buftype);
1706 mtx_unlock(start_ccb->ccb_h.path->bus->sim->mtx);
1711 ata_action(union ccb *start_ccb)
1714 switch (start_ccb->ccb_h.func_code) {
1715 case XPT_SET_TRAN_SETTINGS:
1717 ata_set_transfer_settings(&start_ccb->cts,
1718 start_ccb->ccb_h.path->device,
1719 /*async_update*/FALSE);
1724 ata_scan_bus(start_ccb->ccb_h.path->periph, start_ccb);
1727 ata_scan_lun(start_ccb->ccb_h.path->periph,
1728 start_ccb->ccb_h.path, start_ccb->crcn.flags,
1731 case XPT_GET_TRAN_SETTINGS:
1733 ata_get_transfer_settings(&start_ccb->cts);
1738 struct cam_ed *device;
1741 device = start_ccb->ccb_h.path->device;
1742 if (device->protocol == PROTO_SCSI &&
1743 (device->flags & CAM_DEV_IDENTIFY_DATA_VALID)) {
1745 device->ident_data.config & ATA_PROTO_MASK;
1748 (device->ident_data.config == ATA_PROTO_CFA) ? 0 :
1749 (p == ATA_PROTO_ATAPI_16) ? 16 :
1750 (p == ATA_PROTO_ATAPI_12) ? 12 : 0;
1752 if (start_ccb->csio.cdb_len > maxlen) {
1753 start_ccb->ccb_h.status = CAM_REQ_INVALID;
1754 xpt_done(start_ccb);
1757 xpt_action_default(start_ccb);
1760 case XPT_DEV_ADVINFO:
1762 ata_dev_advinfo(start_ccb);
1766 xpt_action_default(start_ccb);
1772 ata_get_transfer_settings(struct ccb_trans_settings *cts)
1774 struct ccb_trans_settings_ata *ata;
1775 struct ccb_trans_settings_scsi *scsi;
1776 struct cam_ed *device;
1777 struct cam_sim *sim;
1779 device = cts->ccb_h.path->device;
1780 sim = cts->ccb_h.path->bus->sim;
1781 (*(sim->sim_action))(sim, (union ccb *)cts);
1783 if (cts->protocol == PROTO_UNKNOWN ||
1784 cts->protocol == PROTO_UNSPECIFIED) {
1785 cts->protocol = device->protocol;
1786 cts->protocol_version = device->protocol_version;
1789 if (cts->protocol == PROTO_ATA) {
1790 ata = &cts->proto_specific.ata;
1791 if ((ata->valid & CTS_ATA_VALID_TQ) == 0) {
1792 ata->valid |= CTS_ATA_VALID_TQ;
1793 if (cts->type == CTS_TYPE_USER_SETTINGS ||
1794 (device->flags & CAM_DEV_TAG_AFTER_COUNT) != 0 ||
1795 (device->inq_flags & SID_CmdQue) != 0)
1796 ata->flags |= CTS_ATA_FLAGS_TAG_ENB;
1799 if (cts->protocol == PROTO_SCSI) {
1800 scsi = &cts->proto_specific.scsi;
1801 if ((scsi->valid & CTS_SCSI_VALID_TQ) == 0) {
1802 scsi->valid |= CTS_SCSI_VALID_TQ;
1803 if (cts->type == CTS_TYPE_USER_SETTINGS ||
1804 (device->flags & CAM_DEV_TAG_AFTER_COUNT) != 0 ||
1805 (device->inq_flags & SID_CmdQue) != 0)
1806 scsi->flags |= CTS_SCSI_FLAGS_TAG_ENB;
1810 if (cts->transport == XPORT_UNKNOWN ||
1811 cts->transport == XPORT_UNSPECIFIED) {
1812 cts->transport = device->transport;
1813 cts->transport_version = device->transport_version;
1818 ata_set_transfer_settings(struct ccb_trans_settings *cts, struct cam_ed *device,
1821 struct ccb_pathinq cpi;
1822 struct ccb_trans_settings_ata *ata;
1823 struct ccb_trans_settings_scsi *scsi;
1824 struct cam_sim *sim;
1825 struct ata_params *ident_data;
1826 struct scsi_inquiry_data *inq_data;
1828 if (device == NULL) {
1829 cts->ccb_h.status = CAM_PATH_INVALID;
1830 xpt_done((union ccb *)cts);
1834 if (cts->protocol == PROTO_UNKNOWN
1835 || cts->protocol == PROTO_UNSPECIFIED) {
1836 cts->protocol = device->protocol;
1837 cts->protocol_version = device->protocol_version;
1840 if (cts->protocol_version == PROTO_VERSION_UNKNOWN
1841 || cts->protocol_version == PROTO_VERSION_UNSPECIFIED)
1842 cts->protocol_version = device->protocol_version;
1844 if (cts->protocol != device->protocol) {
1845 xpt_print(cts->ccb_h.path, "Uninitialized Protocol %x:%x?\n",
1846 cts->protocol, device->protocol);
1847 cts->protocol = device->protocol;
1850 if (cts->protocol_version > device->protocol_version) {
1852 xpt_print(cts->ccb_h.path, "Down reving Protocol "
1853 "Version from %d to %d?\n", cts->protocol_version,
1854 device->protocol_version);
1856 cts->protocol_version = device->protocol_version;
1859 if (cts->transport == XPORT_UNKNOWN
1860 || cts->transport == XPORT_UNSPECIFIED) {
1861 cts->transport = device->transport;
1862 cts->transport_version = device->transport_version;
1865 if (cts->transport_version == XPORT_VERSION_UNKNOWN
1866 || cts->transport_version == XPORT_VERSION_UNSPECIFIED)
1867 cts->transport_version = device->transport_version;
1869 if (cts->transport != device->transport) {
1870 xpt_print(cts->ccb_h.path, "Uninitialized Transport %x:%x?\n",
1871 cts->transport, device->transport);
1872 cts->transport = device->transport;
1875 if (cts->transport_version > device->transport_version) {
1877 xpt_print(cts->ccb_h.path, "Down reving Transport "
1878 "Version from %d to %d?\n", cts->transport_version,
1879 device->transport_version);
1881 cts->transport_version = device->transport_version;
1884 sim = cts->ccb_h.path->bus->sim;
1885 ident_data = &device->ident_data;
1886 inq_data = &device->inq_data;
1887 if (cts->protocol == PROTO_ATA)
1888 ata = &cts->proto_specific.ata;
1891 if (cts->protocol == PROTO_SCSI)
1892 scsi = &cts->proto_specific.scsi;
1895 xpt_setup_ccb(&cpi.ccb_h, cts->ccb_h.path, CAM_PRIORITY_NONE);
1896 cpi.ccb_h.func_code = XPT_PATH_INQ;
1897 xpt_action((union ccb *)&cpi);
1899 /* Sanity checking */
1900 if ((cpi.hba_inquiry & PI_TAG_ABLE) == 0
1901 || (ata && (ident_data->satacapabilities & ATA_SUPPORT_NCQ) == 0)
1902 || (scsi && (INQ_DATA_TQ_ENABLED(inq_data)) == 0)
1903 || (device->queue_flags & SCP_QUEUE_DQUE) != 0
1904 || (device->mintags == 0)) {
1906 * Can't tag on hardware that doesn't support tags,
1907 * doesn't have it enabled, or has broken tag support.
1910 ata->flags &= ~CTS_ATA_FLAGS_TAG_ENB;
1912 scsi->flags &= ~CTS_SCSI_FLAGS_TAG_ENB;
1915 /* Start/stop tags use. */
1916 if (cts->type == CTS_TYPE_CURRENT_SETTINGS &&
1917 ((ata && (ata->valid & CTS_ATA_VALID_TQ) != 0) ||
1918 (scsi && (scsi->valid & CTS_SCSI_VALID_TQ) != 0))) {
1921 nowt = ((device->flags & CAM_DEV_TAG_AFTER_COUNT) != 0 ||
1922 (device->inq_flags & SID_CmdQue) != 0);
1924 newt = (ata->flags & CTS_ATA_FLAGS_TAG_ENB) != 0;
1926 newt = (scsi->flags & CTS_SCSI_FLAGS_TAG_ENB) != 0;
1928 if (newt && !nowt) {
1930 * Delay change to use tags until after a
1931 * few commands have gone to this device so
1932 * the controller has time to perform transfer
1933 * negotiations without tagged messages getting
1936 device->tag_delay_count = CAM_TAG_DELAY_COUNT;
1937 device->flags |= CAM_DEV_TAG_AFTER_COUNT;
1938 } else if (nowt && !newt)
1939 xpt_stop_tags(cts->ccb_h.path);
1942 if (async_update == FALSE)
1943 (*(sim->sim_action))(sim, (union ccb *)cts);
1947 * Handle any per-device event notifications that require action by the XPT.
1950 ata_dev_async(u_int32_t async_code, struct cam_eb *bus, struct cam_et *target,
1951 struct cam_ed *device, void *async_arg)
1954 struct cam_path newpath;
1957 * We only need to handle events for real devices.
1959 if (target->target_id == CAM_TARGET_WILDCARD
1960 || device->lun_id == CAM_LUN_WILDCARD)
1964 * We need our own path with wildcards expanded to
1965 * handle certain types of events.
1967 if ((async_code == AC_SENT_BDR)
1968 || (async_code == AC_BUS_RESET)
1969 || (async_code == AC_INQ_CHANGED))
1970 status = xpt_compile_path(&newpath, NULL,
1975 status = CAM_REQ_CMP_ERR;
1977 if (status == CAM_REQ_CMP) {
1978 if (async_code == AC_INQ_CHANGED) {
1980 * We've sent a start unit command, or
1981 * something similar to a device that
1982 * may have caused its inquiry data to
1983 * change. So we re-scan the device to
1984 * refresh the inquiry data for it.
1986 ata_scan_lun(newpath.periph, &newpath,
1987 CAM_EXPECT_INQ_CHANGE, NULL);
1989 /* We need to reinitialize device after reset. */
1990 ata_scan_lun(newpath.periph, &newpath,
1993 xpt_release_path(&newpath);
1994 } else if (async_code == AC_LOST_DEVICE &&
1995 (device->flags & CAM_DEV_UNCONFIGURED) == 0) {
1996 device->flags |= CAM_DEV_UNCONFIGURED;
1997 xpt_release_device(device);
1998 } else if (async_code == AC_TRANSFER_NEG) {
1999 struct ccb_trans_settings *settings;
2001 settings = (struct ccb_trans_settings *)async_arg;
2002 ata_set_transfer_settings(settings, device,
2003 /*async_update*/TRUE);
2008 ata_announce_periph(struct cam_periph *periph)
2010 struct ccb_pathinq cpi;
2011 struct ccb_trans_settings cts;
2012 struct cam_path *path = periph->path;
2016 mtx_assert(periph->sim->mtx, MA_OWNED);
2018 xpt_setup_ccb(&cts.ccb_h, path, CAM_PRIORITY_NORMAL);
2019 cts.ccb_h.func_code = XPT_GET_TRAN_SETTINGS;
2020 cts.type = CTS_TYPE_CURRENT_SETTINGS;
2021 xpt_action((union ccb*)&cts);
2022 if ((cts.ccb_h.status & CAM_STATUS_MASK) != CAM_REQ_CMP)
2024 /* Ask the SIM for its base transfer speed */
2025 xpt_setup_ccb(&cpi.ccb_h, path, CAM_PRIORITY_NORMAL);
2026 cpi.ccb_h.func_code = XPT_PATH_INQ;
2027 xpt_action((union ccb *)&cpi);
2028 /* Report connection speed */
2029 speed = cpi.base_transfer_speed;
2030 if (cts.ccb_h.status == CAM_REQ_CMP && cts.transport == XPORT_ATA) {
2031 struct ccb_trans_settings_pata *pata =
2032 &cts.xport_specific.ata;
2034 if (pata->valid & CTS_ATA_VALID_MODE)
2035 speed = ata_mode2speed(pata->mode);
2037 if (cts.ccb_h.status == CAM_REQ_CMP && cts.transport == XPORT_SATA) {
2038 struct ccb_trans_settings_sata *sata =
2039 &cts.xport_specific.sata;
2041 if (sata->valid & CTS_SATA_VALID_REVISION)
2042 speed = ata_revision2speed(sata->revision);
2046 printf("%s%d: %d.%03dMB/s transfers",
2047 periph->periph_name, periph->unit_number,
2050 printf("%s%d: %dKB/s transfers", periph->periph_name,
2051 periph->unit_number, speed);
2052 /* Report additional information about connection */
2053 if (cts.ccb_h.status == CAM_REQ_CMP && cts.transport == XPORT_ATA) {
2054 struct ccb_trans_settings_pata *pata =
2055 &cts.xport_specific.ata;
2058 if (pata->valid & CTS_ATA_VALID_MODE)
2059 printf("%s, ", ata_mode2string(pata->mode));
2060 if ((pata->valid & CTS_ATA_VALID_ATAPI) && pata->atapi != 0)
2061 printf("ATAPI %dbytes, ", pata->atapi);
2062 if (pata->valid & CTS_ATA_VALID_BYTECOUNT)
2063 printf("PIO %dbytes", pata->bytecount);
2066 if (cts.ccb_h.status == CAM_REQ_CMP && cts.transport == XPORT_SATA) {
2067 struct ccb_trans_settings_sata *sata =
2068 &cts.xport_specific.sata;
2071 if (sata->valid & CTS_SATA_VALID_REVISION)
2072 printf("SATA %d.x, ", sata->revision);
2075 if (sata->valid & CTS_SATA_VALID_MODE)
2076 printf("%s, ", ata_mode2string(sata->mode));
2077 if ((sata->valid & CTS_ATA_VALID_ATAPI) && sata->atapi != 0)
2078 printf("ATAPI %dbytes, ", sata->atapi);
2079 if (sata->valid & CTS_SATA_VALID_BYTECOUNT)
2080 printf("PIO %dbytes", sata->bytecount);