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"));
252 probeschedule(periph);
257 probeschedule(struct cam_periph *periph)
262 softc = (probe_softc *)periph->softc;
263 ccb = (union ccb *)TAILQ_FIRST(&softc->request_ccbs);
265 if ((periph->path->device->flags & CAM_DEV_UNCONFIGURED) ||
266 periph->path->device->protocol == PROTO_SATAPM ||
267 periph->path->device->protocol == PROTO_SEMB)
268 PROBE_SET_ACTION(softc, PROBE_RESET);
270 PROBE_SET_ACTION(softc, PROBE_IDENTIFY);
272 if (ccb->crcn.flags & CAM_EXPECT_INQ_CHANGE)
273 softc->flags |= PROBE_NO_ANNOUNCE;
275 softc->flags &= ~PROBE_NO_ANNOUNCE;
277 xpt_schedule(periph, CAM_PRIORITY_XPT);
281 probestart(struct cam_periph *periph, union ccb *start_ccb)
283 struct ccb_trans_settings cts;
284 struct ccb_ataio *ataio;
285 struct ccb_scsiio *csio;
287 struct cam_path *path;
288 struct ata_params *ident_buf;
290 CAM_DEBUG(start_ccb->ccb_h.path, CAM_DEBUG_TRACE, ("probestart\n"));
292 softc = (probe_softc *)periph->softc;
293 path = start_ccb->ccb_h.path;
294 ataio = &start_ccb->ataio;
295 csio = &start_ccb->csio;
296 ident_buf = &periph->path->device->ident_data;
298 if (softc->restart) {
300 if ((path->device->flags & CAM_DEV_UNCONFIGURED) ||
301 path->device->protocol == PROTO_SATAPM ||
302 path->device->protocol == PROTO_SEMB)
303 softc->action = PROBE_RESET;
305 softc->action = PROBE_IDENTIFY;
307 switch (softc->action) {
309 cam_fill_ataio(ataio,
312 /*flags*/CAM_DIR_NONE,
317 ata_reset_cmd(ataio);
320 cam_fill_ataio(ataio,
325 /*data_ptr*/(u_int8_t *)&softc->ident_data,
326 /*dxfer_len*/sizeof(softc->ident_data),
328 if (periph->path->device->protocol == PROTO_ATA)
329 ata_28bit_cmd(ataio, ATA_ATA_IDENTIFY, 0, 0, 0);
331 ata_28bit_cmd(ataio, ATA_ATAPI_IDENTIFY, 0, 0, 0);
335 xpt_print(path, "Spinning up device\n");
336 cam_fill_ataio(ataio,
339 /*flags*/CAM_DIR_NONE | CAM_HIGH_POWER,
344 ata_28bit_cmd(ataio, ATA_SETFEATURES, ATA_SF_PUIS_SPINUP, 0, 0);
351 /* Fetch user modes from SIM. */
352 bzero(&cts, sizeof(cts));
353 xpt_setup_ccb(&cts.ccb_h, path, CAM_PRIORITY_NONE);
354 cts.ccb_h.func_code = XPT_GET_TRAN_SETTINGS;
355 cts.type = CTS_TYPE_USER_SETTINGS;
356 xpt_action((union ccb *)&cts);
357 if (path->device->transport == XPORT_ATA) {
358 if (cts.xport_specific.ata.valid & CTS_ATA_VALID_MODE)
359 mode = cts.xport_specific.ata.mode;
361 if (cts.xport_specific.sata.valid & CTS_SATA_VALID_MODE)
362 mode = cts.xport_specific.sata.mode;
364 if (periph->path->device->protocol == PROTO_ATA) {
365 if (ata_dma == 0 && (mode == 0 || mode > ATA_PIO_MAX))
368 if (atapi_dma == 0 && (mode == 0 || mode > ATA_PIO_MAX))
372 /* Honor device capabilities. */
373 wantmode = mode = ata_max_mode(ident_buf, mode);
374 /* Report modes to SIM. */
375 bzero(&cts, sizeof(cts));
376 xpt_setup_ccb(&cts.ccb_h, path, CAM_PRIORITY_NONE);
377 cts.ccb_h.func_code = XPT_SET_TRAN_SETTINGS;
378 cts.type = CTS_TYPE_CURRENT_SETTINGS;
379 if (path->device->transport == XPORT_ATA) {
380 cts.xport_specific.ata.mode = mode;
381 cts.xport_specific.ata.valid = CTS_ATA_VALID_MODE;
383 cts.xport_specific.sata.mode = mode;
384 cts.xport_specific.sata.valid = CTS_SATA_VALID_MODE;
386 xpt_action((union ccb *)&cts);
387 /* Fetch current modes from SIM. */
388 bzero(&cts, sizeof(cts));
389 xpt_setup_ccb(&cts.ccb_h, path, CAM_PRIORITY_NONE);
390 cts.ccb_h.func_code = XPT_GET_TRAN_SETTINGS;
391 cts.type = CTS_TYPE_CURRENT_SETTINGS;
392 xpt_action((union ccb *)&cts);
393 if (path->device->transport == XPORT_ATA) {
394 if (cts.xport_specific.ata.valid & CTS_ATA_VALID_MODE)
395 mode = cts.xport_specific.ata.mode;
397 if (cts.xport_specific.ata.valid & CTS_SATA_VALID_MODE)
398 mode = cts.xport_specific.sata.mode;
400 /* If SIM disagree - renegotiate. */
401 if (mode != wantmode)
403 /* Remember what transport thinks about DMA. */
405 path->device->inq_flags &= ~SID_DMA;
407 path->device->inq_flags |= SID_DMA;
408 xpt_async(AC_GETDEV_CHANGED, path, NULL);
409 cam_fill_ataio(ataio,
412 /*flags*/CAM_DIR_NONE,
417 ata_28bit_cmd(ataio, ATA_SETFEATURES, ATA_SF_SETXFER, 0, mode);
421 cam_fill_ataio(ataio,
429 ata_28bit_cmd(ataio, ATA_SETFEATURES,
430 (softc->caps & CTS_SATA_CAPS_H_PMREQ) ? 0x10 : 0x90,
434 cam_fill_ataio(ataio,
442 ata_28bit_cmd(ataio, ATA_SETFEATURES,
443 (softc->caps & CTS_SATA_CAPS_H_APST) ? 0x10 : 0x90,
447 cam_fill_ataio(ataio,
455 ata_28bit_cmd(ataio, ATA_SETFEATURES,
456 (softc->caps & CTS_SATA_CAPS_H_DMAAA) ? 0x10 : 0x90,
460 /* Remember what transport thinks about AEN. */
461 if (softc->caps & CTS_SATA_CAPS_H_AN)
462 path->device->inq_flags |= SID_AEN;
464 path->device->inq_flags &= ~SID_AEN;
465 xpt_async(AC_GETDEV_CHANGED, path, NULL);
466 cam_fill_ataio(ataio,
474 ata_28bit_cmd(ataio, ATA_SETFEATURES,
475 (softc->caps & CTS_SATA_CAPS_H_AN) ? 0x10 : 0x90,
478 case PROBE_SET_MULTI:
480 u_int sectors, bytecount;
482 bytecount = 8192; /* SATA maximum */
483 /* Fetch user bytecount from SIM. */
484 bzero(&cts, sizeof(cts));
485 xpt_setup_ccb(&cts.ccb_h, path, CAM_PRIORITY_NONE);
486 cts.ccb_h.func_code = XPT_GET_TRAN_SETTINGS;
487 cts.type = CTS_TYPE_USER_SETTINGS;
488 xpt_action((union ccb *)&cts);
489 if (path->device->transport == XPORT_ATA) {
490 if (cts.xport_specific.ata.valid & CTS_ATA_VALID_BYTECOUNT)
491 bytecount = cts.xport_specific.ata.bytecount;
493 if (cts.xport_specific.sata.valid & CTS_SATA_VALID_BYTECOUNT)
494 bytecount = cts.xport_specific.sata.bytecount;
496 /* Honor device capabilities. */
497 sectors = max(1, min(ident_buf->sectors_intr & 0xff,
498 bytecount / ata_logical_sector_size(ident_buf)));
499 /* Report bytecount to SIM. */
500 bzero(&cts, sizeof(cts));
501 xpt_setup_ccb(&cts.ccb_h, path, CAM_PRIORITY_NONE);
502 cts.ccb_h.func_code = XPT_SET_TRAN_SETTINGS;
503 cts.type = CTS_TYPE_CURRENT_SETTINGS;
504 if (path->device->transport == XPORT_ATA) {
505 cts.xport_specific.ata.bytecount = sectors *
506 ata_logical_sector_size(ident_buf);
507 cts.xport_specific.ata.valid = CTS_ATA_VALID_BYTECOUNT;
509 cts.xport_specific.sata.bytecount = sectors *
510 ata_logical_sector_size(ident_buf);
511 cts.xport_specific.sata.valid = CTS_SATA_VALID_BYTECOUNT;
513 xpt_action((union ccb *)&cts);
514 /* Fetch current bytecount from SIM. */
515 bzero(&cts, sizeof(cts));
516 xpt_setup_ccb(&cts.ccb_h, path, CAM_PRIORITY_NONE);
517 cts.ccb_h.func_code = XPT_GET_TRAN_SETTINGS;
518 cts.type = CTS_TYPE_CURRENT_SETTINGS;
519 xpt_action((union ccb *)&cts);
520 if (path->device->transport == XPORT_ATA) {
521 if (cts.xport_specific.ata.valid & CTS_ATA_VALID_BYTECOUNT)
522 bytecount = cts.xport_specific.ata.bytecount;
524 if (cts.xport_specific.sata.valid & CTS_SATA_VALID_BYTECOUNT)
525 bytecount = cts.xport_specific.sata.bytecount;
527 sectors = bytecount / ata_logical_sector_size(ident_buf);
529 cam_fill_ataio(ataio,
537 ata_28bit_cmd(ataio, ATA_SET_MULTI, 0, 0, sectors);
544 bytecount = 8192; /* SATA maximum */
545 /* Fetch user bytecount from SIM. */
546 bzero(&cts, sizeof(cts));
547 xpt_setup_ccb(&cts.ccb_h, path, CAM_PRIORITY_NONE);
548 cts.ccb_h.func_code = XPT_GET_TRAN_SETTINGS;
549 cts.type = CTS_TYPE_USER_SETTINGS;
550 xpt_action((union ccb *)&cts);
551 if (path->device->transport == XPORT_ATA) {
552 if (cts.xport_specific.ata.valid & CTS_ATA_VALID_BYTECOUNT)
553 bytecount = cts.xport_specific.ata.bytecount;
555 if (cts.xport_specific.sata.valid & CTS_SATA_VALID_BYTECOUNT)
556 bytecount = cts.xport_specific.sata.bytecount;
558 /* Honor device capabilities. */
560 bytecount = max(2, min(65534, bytecount));
561 if (ident_buf->satacapabilities != 0x0000 &&
562 ident_buf->satacapabilities != 0xffff) {
563 bytecount = min(8192, bytecount);
565 /* Report bytecount to SIM. */
566 bzero(&cts, sizeof(cts));
567 xpt_setup_ccb(&cts.ccb_h, path, CAM_PRIORITY_NONE);
568 cts.ccb_h.func_code = XPT_SET_TRAN_SETTINGS;
569 cts.type = CTS_TYPE_CURRENT_SETTINGS;
570 if (path->device->transport == XPORT_ATA) {
571 cts.xport_specific.ata.bytecount = bytecount;
572 cts.xport_specific.ata.valid = CTS_ATA_VALID_BYTECOUNT;
574 cts.xport_specific.sata.bytecount = bytecount;
575 cts.xport_specific.sata.valid = CTS_SATA_VALID_BYTECOUNT;
577 xpt_action((union ccb *)&cts);
580 case PROBE_FULL_INQUIRY:
583 struct scsi_inquiry_data *inq_buf =
584 &periph->path->device->inq_data;
586 if (softc->action == PROBE_INQUIRY)
587 inquiry_len = SHORT_INQUIRY_LENGTH;
589 inquiry_len = SID_ADDITIONAL_LENGTH(inq_buf);
591 * Some parallel SCSI devices fail to send an
592 * ignore wide residue message when dealing with
593 * odd length inquiry requests. Round up to be
596 inquiry_len = roundup2(inquiry_len, 2);
606 /*timeout*/60 * 1000);
610 cam_fill_ataio(ataio,
613 /*flags*/CAM_DIR_NONE,
618 ata_pm_read_cmd(ataio, 0, 15);
621 cam_fill_ataio(ataio,
624 /*flags*/CAM_DIR_NONE,
629 ata_pm_read_cmd(ataio, 1, 15);
631 case PROBE_IDENTIFY_SES:
632 cam_fill_ataio(ataio,
637 /*data_ptr*/(u_int8_t *)&softc->ident_data,
638 /*dxfer_len*/sizeof(softc->ident_data),
640 ata_28bit_cmd(ataio, ATA_SEP_ATTN, 0xEC, 0x02,
641 sizeof(softc->ident_data) / 4);
643 case PROBE_IDENTIFY_SAFTE:
644 cam_fill_ataio(ataio,
649 /*data_ptr*/(u_int8_t *)&softc->ident_data,
650 /*dxfer_len*/sizeof(softc->ident_data),
652 ata_28bit_cmd(ataio, ATA_SEP_ATTN, 0xEC, 0x00,
653 sizeof(softc->ident_data) / 4);
656 panic("probestart: invalid action state 0x%x\n", softc->action);
658 start_ccb->ccb_h.flags |= CAM_DEV_QFREEZE;
659 xpt_action(start_ccb);
663 proberequestdefaultnegotiation(struct cam_periph *periph)
665 struct ccb_trans_settings cts;
667 xpt_setup_ccb(&cts.ccb_h, periph->path, CAM_PRIORITY_NONE);
668 cts.ccb_h.func_code = XPT_GET_TRAN_SETTINGS;
669 cts.type = CTS_TYPE_USER_SETTINGS;
670 xpt_action((union ccb *)&cts);
671 if ((cts.ccb_h.status & CAM_STATUS_MASK) != CAM_REQ_CMP)
673 cts.xport_specific.valid = 0;
674 cts.ccb_h.func_code = XPT_SET_TRAN_SETTINGS;
675 cts.type = CTS_TYPE_CURRENT_SETTINGS;
676 xpt_action((union ccb *)&cts);
680 probedone(struct cam_periph *periph, union ccb *done_ccb)
682 struct ccb_trans_settings cts;
683 struct ata_params *ident_buf;
684 struct scsi_inquiry_data *inq_buf;
686 struct cam_path *path;
690 int changed = 1, found = 1;
691 static const uint8_t fake_device_id_hdr[8] =
692 {0, SVPD_DEVICE_ID, 0, 12,
693 SVPD_ID_CODESET_BINARY, SVPD_ID_TYPE_NAA, 0, 8};
695 CAM_DEBUG(done_ccb->ccb_h.path, CAM_DEBUG_TRACE, ("probedone\n"));
697 softc = (probe_softc *)periph->softc;
698 path = done_ccb->ccb_h.path;
699 priority = done_ccb->ccb_h.pinfo.priority;
700 ident_buf = &path->device->ident_data;
701 inq_buf = &path->device->inq_data;
703 if ((done_ccb->ccb_h.status & CAM_STATUS_MASK) != CAM_REQ_CMP) {
704 if (cam_periph_error(done_ccb,
705 0, softc->restart ? (SF_NO_RECOVERY | SF_NO_RETRY) : 0,
708 /* Drop freeze taken due to CAM_DEV_QFREEZE flag set. */
709 cam_release_devq(path, 0, 0, 0, FALSE);
712 if ((done_ccb->ccb_h.status & CAM_DEV_QFRZN) != 0) {
713 /* Don't wedge the queue */
714 xpt_release_devq(path, /*count*/1, /*run_queue*/TRUE);
716 status = done_ccb->ccb_h.status & CAM_STATUS_MASK;
717 if (softc->restart) {
719 if ((done_ccb->ccb_h.status & CAM_STATUS_MASK) ==
722 if (softc->faults < 10)
727 /* Old PIO2 devices may not support mode setting. */
728 } else if (softc->action == PROBE_SETMODE &&
729 status == CAM_ATA_STATUS_ERROR &&
730 ata_max_pmode(ident_buf) <= ATA_PIO2 &&
731 (ident_buf->capabilities1 & ATA_SUPPORT_IORDY) == 0) {
735 * Some old WD SATA disks report supported and enabled
736 * device-initiated interface power management, but return
737 * ABORT on attempt to disable it.
739 } else if (softc->action == PROBE_SETPM &&
740 status == CAM_ATA_STATUS_ERROR) {
744 * Some HP SATA disks report supported DMA Auto-Activation,
745 * but return ABORT on attempt to enable it.
747 } else if (softc->action == PROBE_SETDMAAA &&
748 status == CAM_ATA_STATUS_ERROR) {
752 * Some Samsung SSDs report supported Asynchronous Notification,
753 * but return ABORT on attempt to enable it.
755 } else if (softc->action == PROBE_SETAN &&
756 status == CAM_ATA_STATUS_ERROR) {
760 * SES and SAF-TE SEPs have different IDENTIFY commands,
761 * but SATA specification doesn't tell how to identify them.
762 * Until better way found, just try another if first fail.
764 } else if (softc->action == PROBE_IDENTIFY_SES &&
765 status == CAM_ATA_STATUS_ERROR) {
766 PROBE_SET_ACTION(softc, PROBE_IDENTIFY_SAFTE);
767 xpt_release_ccb(done_ccb);
768 xpt_schedule(periph, priority);
773 * If we get to this point, we got an error status back
774 * from the inquiry and the error status doesn't require
775 * automatically retrying the command. Therefore, the
776 * inquiry failed. If we had inquiry information before
777 * for this device, but this latest inquiry command failed,
778 * the device has probably gone away. If this device isn't
779 * already marked unconfigured, notify the peripheral
780 * drivers that this device is no more.
782 device_fail: if ((path->device->flags & CAM_DEV_UNCONFIGURED) == 0)
783 xpt_async(AC_LOST_DEVICE, path, NULL);
784 PROBE_SET_ACTION(softc, PROBE_INVALID);
791 switch (softc->action) {
794 int sign = (done_ccb->ataio.res.lba_high << 8) +
795 done_ccb->ataio.res.lba_mid;
796 CAM_DEBUG(path, CAM_DEBUG_PROBE,
797 ("SIGNATURE: %04x\n", sign));
798 if (sign == 0x0000 &&
799 done_ccb->ccb_h.target_id != 15) {
800 path->device->protocol = PROTO_ATA;
801 PROBE_SET_ACTION(softc, PROBE_IDENTIFY);
802 } else if (sign == 0x9669 &&
803 done_ccb->ccb_h.target_id == 15) {
804 /* Report SIM that PM is present. */
805 bzero(&cts, sizeof(cts));
806 xpt_setup_ccb(&cts.ccb_h, path, CAM_PRIORITY_NONE);
807 cts.ccb_h.func_code = XPT_SET_TRAN_SETTINGS;
808 cts.type = CTS_TYPE_CURRENT_SETTINGS;
809 cts.xport_specific.sata.pm_present = 1;
810 cts.xport_specific.sata.valid = CTS_SATA_VALID_PM;
811 xpt_action((union ccb *)&cts);
812 path->device->protocol = PROTO_SATAPM;
813 PROBE_SET_ACTION(softc, PROBE_PM_PID);
814 } else if (sign == 0xc33c &&
815 done_ccb->ccb_h.target_id != 15) {
816 path->device->protocol = PROTO_SEMB;
817 PROBE_SET_ACTION(softc, PROBE_IDENTIFY_SES);
818 } else if (sign == 0xeb14 &&
819 done_ccb->ccb_h.target_id != 15) {
820 path->device->protocol = PROTO_SCSI;
821 PROBE_SET_ACTION(softc, PROBE_IDENTIFY);
823 if (done_ccb->ccb_h.target_id != 15) {
825 "Unexpected signature 0x%04x\n", sign);
829 xpt_release_ccb(done_ccb);
830 xpt_schedule(periph, priority);
835 struct ccb_pathinq cpi;
838 ident_buf = &softc->ident_data;
839 for (ptr = (int16_t *)ident_buf;
840 ptr < (int16_t *)ident_buf + sizeof(struct ata_params)/2; ptr++) {
841 *ptr = le16toh(*ptr);
843 if (strncmp(ident_buf->model, "FX", 2) &&
844 strncmp(ident_buf->model, "NEC", 3) &&
845 strncmp(ident_buf->model, "Pioneer", 7) &&
846 strncmp(ident_buf->model, "SHARP", 5)) {
847 ata_bswap(ident_buf->model, sizeof(ident_buf->model));
848 ata_bswap(ident_buf->revision, sizeof(ident_buf->revision));
849 ata_bswap(ident_buf->serial, sizeof(ident_buf->serial));
851 ata_btrim(ident_buf->model, sizeof(ident_buf->model));
852 ata_bpack(ident_buf->model, ident_buf->model, sizeof(ident_buf->model));
853 ata_btrim(ident_buf->revision, sizeof(ident_buf->revision));
854 ata_bpack(ident_buf->revision, ident_buf->revision, sizeof(ident_buf->revision));
855 ata_btrim(ident_buf->serial, sizeof(ident_buf->serial));
856 ata_bpack(ident_buf->serial, ident_buf->serial, sizeof(ident_buf->serial));
857 /* Device may need spin-up before IDENTIFY become valid. */
858 if ((ident_buf->specconf == 0x37c8 ||
859 ident_buf->specconf == 0x738c) &&
860 ((ident_buf->config & ATA_RESP_INCOMPLETE) ||
861 softc->spinup == 0)) {
862 PROBE_SET_ACTION(softc, PROBE_SPINUP);
863 xpt_release_ccb(done_ccb);
864 xpt_schedule(periph, priority);
867 ident_buf = &path->device->ident_data;
868 if ((periph->path->device->flags & CAM_DEV_UNCONFIGURED) == 0) {
869 /* Check that it is the same device. */
870 if (bcmp(softc->ident_data.model, ident_buf->model,
871 sizeof(ident_buf->model)) ||
872 bcmp(softc->ident_data.revision, ident_buf->revision,
873 sizeof(ident_buf->revision)) ||
874 bcmp(softc->ident_data.serial, ident_buf->serial,
875 sizeof(ident_buf->serial))) {
876 /* Device changed. */
877 xpt_async(AC_LOST_DEVICE, path, NULL);
879 bcopy(&softc->ident_data, ident_buf, sizeof(struct ata_params));
884 bcopy(&softc->ident_data, ident_buf, sizeof(struct ata_params));
885 /* Clean up from previous instance of this device */
886 if (path->device->serial_num != NULL) {
887 free(path->device->serial_num, M_CAMXPT);
888 path->device->serial_num = NULL;
889 path->device->serial_num_len = 0;
891 if (path->device->device_id != NULL) {
892 free(path->device->device_id, M_CAMXPT);
893 path->device->device_id = NULL;
894 path->device->device_id_len = 0;
896 path->device->serial_num =
897 (u_int8_t *)malloc((sizeof(ident_buf->serial) + 1),
899 if (path->device->serial_num != NULL) {
900 bcopy(ident_buf->serial,
901 path->device->serial_num,
902 sizeof(ident_buf->serial));
903 path->device->serial_num[sizeof(ident_buf->serial)]
905 path->device->serial_num_len =
906 strlen(path->device->serial_num);
908 if (ident_buf->enabled.extension &
909 ATA_SUPPORT_64BITWWN) {
910 path->device->device_id =
911 malloc(16, M_CAMXPT, M_NOWAIT);
912 if (path->device->device_id != NULL) {
913 path->device->device_id_len = 16;
914 bcopy(&fake_device_id_hdr,
915 path->device->device_id, 8);
916 bcopy(ident_buf->wwn,
917 path->device->device_id + 8, 8);
918 ata_bswap(path->device->device_id + 8, 8);
922 path->device->flags |= CAM_DEV_IDENTIFY_DATA_VALID;
923 xpt_async(AC_GETDEV_CHANGED, path, NULL);
925 if (ident_buf->satacapabilities & ATA_SUPPORT_NCQ) {
926 path->device->mintags = 2;
927 path->device->maxtags =
928 ATA_QUEUE_LEN(ident_buf->queue) + 1;
930 ata_find_quirk(path->device);
931 if (path->device->mintags != 0 &&
932 path->bus->sim->max_tagged_dev_openings != 0) {
933 /* Check if the SIM does not want queued commands. */
934 bzero(&cpi, sizeof(cpi));
935 xpt_setup_ccb(&cpi.ccb_h, path, CAM_PRIORITY_NONE);
936 cpi.ccb_h.func_code = XPT_PATH_INQ;
937 xpt_action((union ccb *)&cpi);
938 if (cpi.ccb_h.status == CAM_REQ_CMP &&
939 (cpi.hba_inquiry & PI_TAG_ABLE)) {
940 /* Report SIM which tags are allowed. */
941 bzero(&cts, sizeof(cts));
942 xpt_setup_ccb(&cts.ccb_h, path, CAM_PRIORITY_NONE);
943 cts.ccb_h.func_code = XPT_SET_TRAN_SETTINGS;
944 cts.type = CTS_TYPE_CURRENT_SETTINGS;
945 cts.xport_specific.sata.tags = path->device->maxtags;
946 cts.xport_specific.sata.valid = CTS_SATA_VALID_TAGS;
947 xpt_action((union ccb *)&cts);
950 ata_device_transport(path);
952 proberequestdefaultnegotiation(periph);
953 PROBE_SET_ACTION(softc, PROBE_SETMODE);
954 xpt_release_ccb(done_ccb);
955 xpt_schedule(periph, priority);
960 xpt_print(path, "Spin-up done\n");
962 PROBE_SET_ACTION(softc, PROBE_IDENTIFY);
963 xpt_release_ccb(done_ccb);
964 xpt_schedule(periph, priority);
967 /* Set supported bits. */
968 bzero(&cts, sizeof(cts));
969 xpt_setup_ccb(&cts.ccb_h, path, CAM_PRIORITY_NONE);
970 cts.ccb_h.func_code = XPT_GET_TRAN_SETTINGS;
971 cts.type = CTS_TYPE_CURRENT_SETTINGS;
972 xpt_action((union ccb *)&cts);
973 if (path->device->transport == XPORT_SATA &&
974 cts.xport_specific.sata.valid & CTS_SATA_VALID_CAPS)
975 caps = cts.xport_specific.sata.caps & CTS_SATA_CAPS_H;
976 else if (path->device->transport == XPORT_ATA &&
977 cts.xport_specific.ata.valid & CTS_ATA_VALID_CAPS)
978 caps = cts.xport_specific.ata.caps & CTS_ATA_CAPS_H;
981 if (path->device->transport == XPORT_SATA &&
982 ident_buf->satacapabilities != 0xffff) {
983 if (ident_buf->satacapabilities & ATA_SUPPORT_IFPWRMNGTRCV)
984 caps |= CTS_SATA_CAPS_D_PMREQ;
985 if (ident_buf->satacapabilities & ATA_SUPPORT_HAPST)
986 caps |= CTS_SATA_CAPS_D_APST;
988 /* Mask unwanted bits. */
989 bzero(&cts, sizeof(cts));
990 xpt_setup_ccb(&cts.ccb_h, path, CAM_PRIORITY_NONE);
991 cts.ccb_h.func_code = XPT_GET_TRAN_SETTINGS;
992 cts.type = CTS_TYPE_USER_SETTINGS;
993 xpt_action((union ccb *)&cts);
994 if (path->device->transport == XPORT_SATA &&
995 cts.xport_specific.sata.valid & CTS_SATA_VALID_CAPS)
996 caps &= cts.xport_specific.sata.caps;
997 else if (path->device->transport == XPORT_ATA &&
998 cts.xport_specific.ata.valid & CTS_ATA_VALID_CAPS)
999 caps &= cts.xport_specific.ata.caps;
1003 * Remember what transport thinks about 48-bit DMA. If
1004 * capability information is not provided or transport is
1005 * SATA, we take support for granted.
1007 if (!(path->device->inq_flags & SID_DMA) ||
1008 (path->device->transport == XPORT_ATA &&
1009 (cts.xport_specific.ata.valid & CTS_ATA_VALID_CAPS) &&
1010 !(caps & CTS_ATA_CAPS_H_DMA48)))
1011 path->device->inq_flags &= ~SID_DMA48;
1013 path->device->inq_flags |= SID_DMA48;
1014 /* Store result to SIM. */
1015 bzero(&cts, sizeof(cts));
1016 xpt_setup_ccb(&cts.ccb_h, path, CAM_PRIORITY_NONE);
1017 cts.ccb_h.func_code = XPT_SET_TRAN_SETTINGS;
1018 cts.type = CTS_TYPE_CURRENT_SETTINGS;
1019 if (path->device->transport == XPORT_SATA) {
1020 cts.xport_specific.sata.caps = caps;
1021 cts.xport_specific.sata.valid = CTS_SATA_VALID_CAPS;
1023 cts.xport_specific.ata.caps = caps;
1024 cts.xport_specific.ata.valid = CTS_ATA_VALID_CAPS;
1026 xpt_action((union ccb *)&cts);
1028 if (path->device->transport != XPORT_SATA)
1030 if ((ident_buf->satasupport & ATA_SUPPORT_IFPWRMNGT) &&
1031 (!(softc->caps & CTS_SATA_CAPS_H_PMREQ)) !=
1032 (!(ident_buf->sataenabled & ATA_SUPPORT_IFPWRMNGT))) {
1033 PROBE_SET_ACTION(softc, PROBE_SETPM);
1034 xpt_release_ccb(done_ccb);
1035 xpt_schedule(periph, priority);
1040 if (ident_buf->satacapabilities != 0xffff &&
1041 (ident_buf->satacapabilities & ATA_SUPPORT_DAPST) &&
1042 (!(softc->caps & CTS_SATA_CAPS_H_APST)) !=
1043 (!(ident_buf->sataenabled & ATA_ENABLED_DAPST))) {
1044 PROBE_SET_ACTION(softc, PROBE_SETAPST);
1045 xpt_release_ccb(done_ccb);
1046 xpt_schedule(periph, priority);
1051 if ((ident_buf->satasupport & ATA_SUPPORT_AUTOACTIVATE) &&
1052 (!(softc->caps & CTS_SATA_CAPS_H_DMAAA)) !=
1053 (!(ident_buf->sataenabled & ATA_SUPPORT_AUTOACTIVATE))) {
1054 PROBE_SET_ACTION(softc, PROBE_SETDMAAA);
1055 xpt_release_ccb(done_ccb);
1056 xpt_schedule(periph, priority);
1060 case PROBE_SETDMAAA:
1061 if ((ident_buf->satasupport & ATA_SUPPORT_ASYNCNOTIF) &&
1062 (!(softc->caps & CTS_SATA_CAPS_H_AN)) !=
1063 (!(ident_buf->sataenabled & ATA_SUPPORT_ASYNCNOTIF))) {
1064 PROBE_SET_ACTION(softc, PROBE_SETAN);
1065 xpt_release_ccb(done_ccb);
1066 xpt_schedule(periph, priority);
1072 if (path->device->protocol == PROTO_ATA) {
1073 PROBE_SET_ACTION(softc, PROBE_SET_MULTI);
1075 PROBE_SET_ACTION(softc, PROBE_INQUIRY);
1077 xpt_release_ccb(done_ccb);
1078 xpt_schedule(periph, priority);
1080 case PROBE_SET_MULTI:
1081 if (periph->path->device->flags & CAM_DEV_UNCONFIGURED) {
1082 path->device->flags &= ~CAM_DEV_UNCONFIGURED;
1083 xpt_acquire_device(path->device);
1084 done_ccb->ccb_h.func_code = XPT_GDEV_TYPE;
1085 xpt_action(done_ccb);
1086 xpt_async(AC_FOUND_DEVICE, path, done_ccb);
1088 PROBE_SET_ACTION(softc, PROBE_DONE);
1091 case PROBE_FULL_INQUIRY:
1093 u_int8_t periph_qual, len;
1095 path->device->flags |= CAM_DEV_INQUIRY_DATA_VALID;
1097 periph_qual = SID_QUAL(inq_buf);
1099 if (periph_qual != SID_QUAL_LU_CONNECTED)
1103 * We conservatively request only
1104 * SHORT_INQUIRY_LEN bytes of inquiry
1105 * information during our first try
1106 * at sending an INQUIRY. If the device
1107 * has more information to give,
1108 * perform a second request specifying
1109 * the amount of information the device
1110 * is willing to give.
1112 len = inq_buf->additional_length
1113 + offsetof(struct scsi_inquiry_data, additional_length) + 1;
1114 if (softc->action == PROBE_INQUIRY
1115 && len > SHORT_INQUIRY_LENGTH) {
1116 PROBE_SET_ACTION(softc, PROBE_FULL_INQUIRY);
1117 xpt_release_ccb(done_ccb);
1118 xpt_schedule(periph, priority);
1122 ata_device_transport(path);
1123 if (periph->path->device->flags & CAM_DEV_UNCONFIGURED) {
1124 path->device->flags &= ~CAM_DEV_UNCONFIGURED;
1125 xpt_acquire_device(path->device);
1126 done_ccb->ccb_h.func_code = XPT_GDEV_TYPE;
1127 xpt_action(done_ccb);
1128 xpt_async(AC_FOUND_DEVICE, path, done_ccb);
1130 PROBE_SET_ACTION(softc, PROBE_DONE);
1134 if ((path->device->flags & CAM_DEV_IDENTIFY_DATA_VALID) == 0)
1135 bzero(ident_buf, sizeof(*ident_buf));
1136 softc->pm_pid = (done_ccb->ataio.res.lba_high << 24) +
1137 (done_ccb->ataio.res.lba_mid << 16) +
1138 (done_ccb->ataio.res.lba_low << 8) +
1139 done_ccb->ataio.res.sector_count;
1140 ((uint32_t *)ident_buf)[0] = softc->pm_pid;
1141 snprintf(ident_buf->model, sizeof(ident_buf->model),
1142 "Port Multiplier %08x", softc->pm_pid);
1143 PROBE_SET_ACTION(softc, PROBE_PM_PRV);
1144 xpt_release_ccb(done_ccb);
1145 xpt_schedule(periph, priority);
1148 softc->pm_prv = (done_ccb->ataio.res.lba_high << 24) +
1149 (done_ccb->ataio.res.lba_mid << 16) +
1150 (done_ccb->ataio.res.lba_low << 8) +
1151 done_ccb->ataio.res.sector_count;
1152 ((uint32_t *)ident_buf)[1] = softc->pm_prv;
1153 snprintf(ident_buf->revision, sizeof(ident_buf->revision),
1154 "%04x", softc->pm_prv);
1155 path->device->flags |= CAM_DEV_IDENTIFY_DATA_VALID;
1156 ata_device_transport(path);
1157 if (periph->path->device->flags & CAM_DEV_UNCONFIGURED)
1158 proberequestdefaultnegotiation(periph);
1159 /* Set supported bits. */
1160 bzero(&cts, sizeof(cts));
1161 xpt_setup_ccb(&cts.ccb_h, path, CAM_PRIORITY_NONE);
1162 cts.ccb_h.func_code = XPT_GET_TRAN_SETTINGS;
1163 cts.type = CTS_TYPE_CURRENT_SETTINGS;
1164 xpt_action((union ccb *)&cts);
1165 if (cts.xport_specific.sata.valid & CTS_SATA_VALID_CAPS)
1166 caps = cts.xport_specific.sata.caps & CTS_SATA_CAPS_H;
1169 /* All PMPs must support PM requests. */
1170 caps |= CTS_SATA_CAPS_D_PMREQ;
1171 /* Mask unwanted bits. */
1172 bzero(&cts, sizeof(cts));
1173 xpt_setup_ccb(&cts.ccb_h, path, CAM_PRIORITY_NONE);
1174 cts.ccb_h.func_code = XPT_GET_TRAN_SETTINGS;
1175 cts.type = CTS_TYPE_USER_SETTINGS;
1176 xpt_action((union ccb *)&cts);
1177 if (cts.xport_specific.sata.valid & CTS_SATA_VALID_CAPS)
1178 caps &= cts.xport_specific.sata.caps;
1181 /* Remember what transport thinks about AEN. */
1182 if (caps & CTS_SATA_CAPS_H_AN)
1183 path->device->inq_flags |= SID_AEN;
1185 path->device->inq_flags &= ~SID_AEN;
1186 /* Store result to SIM. */
1187 bzero(&cts, sizeof(cts));
1188 xpt_setup_ccb(&cts.ccb_h, path, CAM_PRIORITY_NONE);
1189 cts.ccb_h.func_code = XPT_SET_TRAN_SETTINGS;
1190 cts.type = CTS_TYPE_CURRENT_SETTINGS;
1191 cts.xport_specific.sata.caps = caps;
1192 cts.xport_specific.sata.valid = CTS_SATA_VALID_CAPS;
1193 xpt_action((union ccb *)&cts);
1195 xpt_async(AC_GETDEV_CHANGED, path, NULL);
1196 if (periph->path->device->flags & CAM_DEV_UNCONFIGURED) {
1197 path->device->flags &= ~CAM_DEV_UNCONFIGURED;
1198 xpt_acquire_device(path->device);
1199 done_ccb->ccb_h.func_code = XPT_GDEV_TYPE;
1200 xpt_action(done_ccb);
1201 xpt_async(AC_FOUND_DEVICE, path, done_ccb);
1203 done_ccb->ccb_h.func_code = XPT_GDEV_TYPE;
1204 xpt_action(done_ccb);
1205 xpt_async(AC_SCSI_AEN, path, done_ccb);
1207 PROBE_SET_ACTION(softc, PROBE_DONE);
1209 case PROBE_IDENTIFY_SES:
1210 case PROBE_IDENTIFY_SAFTE:
1211 if ((periph->path->device->flags & CAM_DEV_UNCONFIGURED) == 0) {
1212 /* Check that it is the same device. */
1213 if (bcmp(&softc->ident_data, ident_buf, 53)) {
1214 /* Device changed. */
1215 xpt_async(AC_LOST_DEVICE, path, NULL);
1217 bcopy(&softc->ident_data, ident_buf, sizeof(struct ata_params));
1222 bcopy(&softc->ident_data, ident_buf, sizeof(struct ata_params));
1223 /* Clean up from previous instance of this device */
1224 if (path->device->device_id != NULL) {
1225 free(path->device->device_id, M_CAMXPT);
1226 path->device->device_id = NULL;
1227 path->device->device_id_len = 0;
1229 path->device->device_id =
1230 malloc(16, M_CAMXPT, M_NOWAIT);
1231 if (path->device->device_id != NULL) {
1232 path->device->device_id_len = 16;
1233 bcopy(&fake_device_id_hdr,
1234 path->device->device_id, 8);
1235 bcopy(((uint8_t*)ident_buf) + 2,
1236 path->device->device_id + 8, 8);
1239 path->device->flags |= CAM_DEV_IDENTIFY_DATA_VALID;
1241 ata_device_transport(path);
1243 proberequestdefaultnegotiation(periph);
1245 if (periph->path->device->flags & CAM_DEV_UNCONFIGURED) {
1246 path->device->flags &= ~CAM_DEV_UNCONFIGURED;
1247 xpt_acquire_device(path->device);
1248 done_ccb->ccb_h.func_code = XPT_GDEV_TYPE;
1249 xpt_action(done_ccb);
1250 xpt_async(AC_FOUND_DEVICE, path, done_ccb);
1252 PROBE_SET_ACTION(softc, PROBE_DONE);
1255 panic("probedone: invalid action state 0x%x\n", softc->action);
1258 if (softc->restart) {
1260 xpt_release_ccb(done_ccb);
1261 probeschedule(periph);
1264 xpt_release_ccb(done_ccb);
1265 CAM_DEBUG(periph->path, CAM_DEBUG_PROBE, ("Probe completed\n"));
1266 while ((done_ccb = (union ccb *)TAILQ_FIRST(&softc->request_ccbs))) {
1267 TAILQ_REMOVE(&softc->request_ccbs,
1268 &done_ccb->ccb_h, periph_links.tqe);
1269 done_ccb->ccb_h.status = found ? CAM_REQ_CMP : CAM_REQ_CMP_ERR;
1272 /* Drop freeze taken due to CAM_DEV_QFREEZE flag set. */
1273 cam_release_devq(path, 0, 0, 0, FALSE);
1274 cam_periph_invalidate(periph);
1275 cam_periph_release_locked(periph);
1279 probecleanup(struct cam_periph *periph)
1281 free(periph->softc, M_CAMXPT);
1285 ata_find_quirk(struct cam_ed *device)
1287 struct ata_quirk_entry *quirk;
1290 match = cam_quirkmatch((caddr_t)&device->ident_data,
1291 (caddr_t)ata_quirk_table,
1292 ata_quirk_table_size,
1293 sizeof(*ata_quirk_table), ata_identify_match);
1296 panic("xpt_find_quirk: device didn't match wildcard entry!!");
1298 quirk = (struct ata_quirk_entry *)match;
1299 device->quirk = quirk;
1300 if (quirk->quirks & CAM_QUIRK_MAXTAGS) {
1301 device->mintags = quirk->mintags;
1302 device->maxtags = quirk->maxtags;
1307 union ccb *request_ccb;
1308 struct ccb_pathinq *cpi;
1310 } ata_scan_bus_info;
1313 * To start a scan, request_ccb is an XPT_SCAN_BUS ccb.
1314 * As the scan progresses, xpt_scan_bus is used as the
1315 * callback on completion function.
1318 ata_scan_bus(struct cam_periph *periph, union ccb *request_ccb)
1320 struct cam_path *path;
1321 ata_scan_bus_info *scan_info;
1322 union ccb *work_ccb, *reset_ccb;
1325 CAM_DEBUG(request_ccb->ccb_h.path, CAM_DEBUG_TRACE,
1326 ("xpt_scan_bus\n"));
1327 switch (request_ccb->ccb_h.func_code) {
1330 /* Find out the characteristics of the bus */
1331 work_ccb = xpt_alloc_ccb_nowait();
1332 if (work_ccb == NULL) {
1333 request_ccb->ccb_h.status = CAM_RESRC_UNAVAIL;
1334 xpt_done(request_ccb);
1337 xpt_setup_ccb(&work_ccb->ccb_h, request_ccb->ccb_h.path,
1338 request_ccb->ccb_h.pinfo.priority);
1339 work_ccb->ccb_h.func_code = XPT_PATH_INQ;
1340 xpt_action(work_ccb);
1341 if (work_ccb->ccb_h.status != CAM_REQ_CMP) {
1342 request_ccb->ccb_h.status = work_ccb->ccb_h.status;
1343 xpt_free_ccb(work_ccb);
1344 xpt_done(request_ccb);
1348 /* We may need to reset bus first, if we haven't done it yet. */
1349 if ((work_ccb->cpi.hba_inquiry &
1350 (PI_WIDE_32|PI_WIDE_16|PI_SDTR_ABLE)) &&
1351 !(work_ccb->cpi.hba_misc & PIM_NOBUSRESET) &&
1352 !timevalisset(&request_ccb->ccb_h.path->bus->last_reset)) {
1353 reset_ccb = xpt_alloc_ccb_nowait();
1354 if (reset_ccb == NULL) {
1355 request_ccb->ccb_h.status = CAM_RESRC_UNAVAIL;
1356 xpt_free_ccb(work_ccb);
1357 xpt_done(request_ccb);
1360 xpt_setup_ccb(&reset_ccb->ccb_h, request_ccb->ccb_h.path,
1362 reset_ccb->ccb_h.func_code = XPT_RESET_BUS;
1363 xpt_action(reset_ccb);
1364 if (reset_ccb->ccb_h.status != CAM_REQ_CMP) {
1365 request_ccb->ccb_h.status = reset_ccb->ccb_h.status;
1366 xpt_free_ccb(reset_ccb);
1367 xpt_free_ccb(work_ccb);
1368 xpt_done(request_ccb);
1371 xpt_free_ccb(reset_ccb);
1374 /* Save some state for use while we probe for devices */
1375 scan_info = (ata_scan_bus_info *)
1376 malloc(sizeof(ata_scan_bus_info), M_CAMXPT, M_NOWAIT);
1377 if (scan_info == NULL) {
1378 request_ccb->ccb_h.status = CAM_RESRC_UNAVAIL;
1379 xpt_free_ccb(work_ccb);
1380 xpt_done(request_ccb);
1383 scan_info->request_ccb = request_ccb;
1384 scan_info->cpi = &work_ccb->cpi;
1385 /* If PM supported, probe it first. */
1386 if (scan_info->cpi->hba_inquiry & PI_SATAPM)
1387 scan_info->counter = scan_info->cpi->max_target;
1389 scan_info->counter = 0;
1391 work_ccb = xpt_alloc_ccb_nowait();
1392 if (work_ccb == NULL) {
1393 free(scan_info, M_CAMXPT);
1394 request_ccb->ccb_h.status = CAM_RESRC_UNAVAIL;
1395 xpt_done(request_ccb);
1400 work_ccb = request_ccb;
1401 /* Reuse the same CCB to query if a device was really found */
1402 scan_info = (ata_scan_bus_info *)work_ccb->ccb_h.ppriv_ptr0;
1403 /* If there is PMP... */
1404 if ((scan_info->cpi->hba_inquiry & PI_SATAPM) &&
1405 (scan_info->counter == scan_info->cpi->max_target)) {
1406 if (work_ccb->ccb_h.status == CAM_REQ_CMP) {
1407 /* everything else will be probed by it */
1408 /* Free the current request path- we're done with it. */
1409 xpt_free_path(work_ccb->ccb_h.path);
1412 struct ccb_trans_settings cts;
1414 /* Report SIM that PM is absent. */
1415 bzero(&cts, sizeof(cts));
1416 xpt_setup_ccb(&cts.ccb_h,
1417 work_ccb->ccb_h.path, CAM_PRIORITY_NONE);
1418 cts.ccb_h.func_code = XPT_SET_TRAN_SETTINGS;
1419 cts.type = CTS_TYPE_CURRENT_SETTINGS;
1420 cts.xport_specific.sata.pm_present = 0;
1421 cts.xport_specific.sata.valid = CTS_SATA_VALID_PM;
1422 xpt_action((union ccb *)&cts);
1425 /* Free the current request path- we're done with it. */
1426 xpt_free_path(work_ccb->ccb_h.path);
1427 if (scan_info->counter ==
1428 ((scan_info->cpi->hba_inquiry & PI_SATAPM) ?
1429 0 : scan_info->cpi->max_target)) {
1431 xpt_free_ccb(work_ccb);
1432 xpt_free_ccb((union ccb *)scan_info->cpi);
1433 request_ccb = scan_info->request_ccb;
1434 free(scan_info, M_CAMXPT);
1435 request_ccb->ccb_h.status = CAM_REQ_CMP;
1436 xpt_done(request_ccb);
1439 /* Take next device. Wrap from max (PMP) to 0. */
1440 scan_info->counter = (scan_info->counter + 1 ) %
1441 (scan_info->cpi->max_target + 1);
1443 status = xpt_create_path(&path, NULL,
1444 scan_info->request_ccb->ccb_h.path_id,
1445 scan_info->counter, 0);
1446 if (status != CAM_REQ_CMP) {
1447 printf("xpt_scan_bus: xpt_create_path failed"
1448 " with status %#x, bus scan halted\n",
1450 xpt_free_ccb(work_ccb);
1451 xpt_free_ccb((union ccb *)scan_info->cpi);
1452 request_ccb = scan_info->request_ccb;
1453 free(scan_info, M_CAMXPT);
1454 request_ccb->ccb_h.status = status;
1455 xpt_done(request_ccb);
1458 xpt_setup_ccb(&work_ccb->ccb_h, path,
1459 scan_info->request_ccb->ccb_h.pinfo.priority);
1460 work_ccb->ccb_h.func_code = XPT_SCAN_LUN;
1461 work_ccb->ccb_h.cbfcnp = ata_scan_bus;
1462 work_ccb->ccb_h.ppriv_ptr0 = scan_info;
1463 work_ccb->crcn.flags = scan_info->request_ccb->crcn.flags;
1464 xpt_action(work_ccb);
1472 ata_scan_lun(struct cam_periph *periph, struct cam_path *path,
1473 cam_flags flags, union ccb *request_ccb)
1475 struct ccb_pathinq cpi;
1477 struct cam_path *new_path;
1478 struct cam_periph *old_periph;
1480 CAM_DEBUG(path, CAM_DEBUG_TRACE, ("xpt_scan_lun\n"));
1482 xpt_setup_ccb(&cpi.ccb_h, path, CAM_PRIORITY_NONE);
1483 cpi.ccb_h.func_code = XPT_PATH_INQ;
1484 xpt_action((union ccb *)&cpi);
1486 if (cpi.ccb_h.status != CAM_REQ_CMP) {
1487 if (request_ccb != NULL) {
1488 request_ccb->ccb_h.status = cpi.ccb_h.status;
1489 xpt_done(request_ccb);
1494 if (request_ccb == NULL) {
1495 request_ccb = xpt_alloc_ccb_nowait();
1496 if (request_ccb == NULL) {
1497 xpt_print(path, "xpt_scan_lun: can't allocate CCB, "
1498 "can't continue\n");
1501 status = xpt_create_path(&new_path, NULL,
1503 path->target->target_id,
1504 path->device->lun_id);
1505 if (status != CAM_REQ_CMP) {
1506 xpt_print(path, "xpt_scan_lun: can't create path, "
1507 "can't continue\n");
1508 xpt_free_ccb(request_ccb);
1511 xpt_setup_ccb(&request_ccb->ccb_h, new_path, CAM_PRIORITY_XPT);
1512 request_ccb->ccb_h.cbfcnp = xptscandone;
1513 request_ccb->ccb_h.func_code = XPT_SCAN_LUN;
1514 request_ccb->crcn.flags = flags;
1517 if ((old_periph = cam_periph_find(path, "aprobe")) != NULL) {
1518 if ((old_periph->flags & CAM_PERIPH_INVALID) == 0) {
1521 softc = (probe_softc *)old_periph->softc;
1522 TAILQ_INSERT_TAIL(&softc->request_ccbs,
1523 &request_ccb->ccb_h, periph_links.tqe);
1526 request_ccb->ccb_h.status = CAM_REQ_CMP_ERR;
1527 xpt_done(request_ccb);
1530 status = cam_periph_alloc(proberegister, NULL, probecleanup,
1531 probestart, "aprobe",
1533 request_ccb->ccb_h.path, NULL, 0,
1536 if (status != CAM_REQ_CMP) {
1537 xpt_print(path, "xpt_scan_lun: cam_alloc_periph "
1538 "returned an error, can't continue probe\n");
1539 request_ccb->ccb_h.status = status;
1540 xpt_done(request_ccb);
1546 xptscandone(struct cam_periph *periph, union ccb *done_ccb)
1549 xpt_free_path(done_ccb->ccb_h.path);
1550 xpt_free_ccb(done_ccb);
1553 static struct cam_ed *
1554 ata_alloc_device(struct cam_eb *bus, struct cam_et *target, lun_id_t lun_id)
1556 struct cam_path path;
1557 struct ata_quirk_entry *quirk;
1558 struct cam_ed *device;
1560 device = xpt_alloc_device(bus, target, lun_id);
1565 * Take the default quirk entry until we have inquiry
1566 * data and can determine a better quirk to use.
1568 quirk = &ata_quirk_table[ata_quirk_table_size - 1];
1569 device->quirk = (void *)quirk;
1570 device->mintags = 0;
1571 device->maxtags = 0;
1572 bzero(&device->inq_data, sizeof(device->inq_data));
1573 device->inq_flags = 0;
1574 device->queue_flags = 0;
1575 device->serial_num = NULL;
1576 device->serial_num_len = 0;
1579 * XXX should be limited by number of CCBs this bus can
1582 bus->sim->max_ccbs += device->ccbq.devq_openings;
1583 if (lun_id != CAM_LUN_WILDCARD) {
1584 xpt_compile_path(&path,
1589 ata_device_transport(&path);
1590 xpt_release_path(&path);
1597 ata_device_transport(struct cam_path *path)
1599 struct ccb_pathinq cpi;
1600 struct ccb_trans_settings cts;
1601 struct scsi_inquiry_data *inq_buf = NULL;
1602 struct ata_params *ident_buf = NULL;
1604 /* Get transport information from the SIM */
1605 xpt_setup_ccb(&cpi.ccb_h, path, CAM_PRIORITY_NONE);
1606 cpi.ccb_h.func_code = XPT_PATH_INQ;
1607 xpt_action((union ccb *)&cpi);
1609 path->device->transport = cpi.transport;
1610 if ((path->device->flags & CAM_DEV_INQUIRY_DATA_VALID) != 0)
1611 inq_buf = &path->device->inq_data;
1612 if ((path->device->flags & CAM_DEV_IDENTIFY_DATA_VALID) != 0)
1613 ident_buf = &path->device->ident_data;
1614 if (path->device->protocol == PROTO_ATA) {
1615 path->device->protocol_version = ident_buf ?
1616 ata_version(ident_buf->version_major) : cpi.protocol_version;
1617 } else if (path->device->protocol == PROTO_SCSI) {
1618 path->device->protocol_version = inq_buf ?
1619 SID_ANSI_REV(inq_buf) : cpi.protocol_version;
1621 path->device->transport_version = ident_buf ?
1622 ata_version(ident_buf->version_major) : cpi.transport_version;
1624 /* Tell the controller what we think */
1625 xpt_setup_ccb(&cts.ccb_h, path, CAM_PRIORITY_NONE);
1626 cts.ccb_h.func_code = XPT_SET_TRAN_SETTINGS;
1627 cts.type = CTS_TYPE_CURRENT_SETTINGS;
1628 cts.transport = path->device->transport;
1629 cts.transport_version = path->device->transport_version;
1630 cts.protocol = path->device->protocol;
1631 cts.protocol_version = path->device->protocol_version;
1632 cts.proto_specific.valid = 0;
1634 if (path->device->transport == XPORT_ATA) {
1635 cts.xport_specific.ata.atapi =
1636 (ident_buf->config == ATA_PROTO_CFA) ? 0 :
1637 ((ident_buf->config & ATA_PROTO_MASK) == ATA_PROTO_ATAPI_16) ? 16 :
1638 ((ident_buf->config & ATA_PROTO_MASK) == ATA_PROTO_ATAPI_12) ? 12 : 0;
1639 cts.xport_specific.ata.valid = CTS_ATA_VALID_ATAPI;
1641 cts.xport_specific.sata.atapi =
1642 (ident_buf->config == ATA_PROTO_CFA) ? 0 :
1643 ((ident_buf->config & ATA_PROTO_MASK) == ATA_PROTO_ATAPI_16) ? 16 :
1644 ((ident_buf->config & ATA_PROTO_MASK) == ATA_PROTO_ATAPI_12) ? 12 : 0;
1645 cts.xport_specific.sata.valid = CTS_SATA_VALID_ATAPI;
1648 cts.xport_specific.valid = 0;
1649 xpt_action((union ccb *)&cts);
1653 ata_dev_advinfo(union ccb *start_ccb)
1655 struct cam_ed *device;
1656 struct ccb_dev_advinfo *cdai;
1659 start_ccb->ccb_h.status = CAM_REQ_INVALID;
1660 device = start_ccb->ccb_h.path->device;
1661 cdai = &start_ccb->cdai;
1662 switch(cdai->buftype) {
1663 case CDAI_TYPE_SCSI_DEVID:
1664 if (cdai->flags & CDAI_FLAG_STORE)
1666 cdai->provsiz = device->device_id_len;
1667 if (device->device_id_len == 0)
1669 amt = device->device_id_len;
1670 if (cdai->provsiz > cdai->bufsiz)
1672 memcpy(cdai->buf, device->device_id, amt);
1674 case CDAI_TYPE_SERIAL_NUM:
1675 if (cdai->flags & CDAI_FLAG_STORE)
1677 cdai->provsiz = device->serial_num_len;
1678 if (device->serial_num_len == 0)
1680 amt = device->serial_num_len;
1681 if (cdai->provsiz > cdai->bufsiz)
1683 memcpy(cdai->buf, device->serial_num, amt);
1685 case CDAI_TYPE_PHYS_PATH:
1686 if (cdai->flags & CDAI_FLAG_STORE) {
1687 if (device->physpath != NULL)
1688 free(device->physpath, M_CAMXPT);
1689 device->physpath_len = cdai->bufsiz;
1690 /* Clear existing buffer if zero length */
1691 if (cdai->bufsiz == 0)
1693 device->physpath = malloc(cdai->bufsiz, M_CAMXPT, M_NOWAIT);
1694 if (device->physpath == NULL) {
1695 start_ccb->ccb_h.status = CAM_REQ_ABORTED;
1698 memcpy(device->physpath, cdai->buf, cdai->bufsiz);
1700 cdai->provsiz = device->physpath_len;
1701 if (device->physpath_len == 0)
1703 amt = device->physpath_len;
1704 if (cdai->provsiz > cdai->bufsiz)
1706 memcpy(cdai->buf, device->physpath, amt);
1712 start_ccb->ccb_h.status = CAM_REQ_CMP;
1714 if (cdai->flags & CDAI_FLAG_STORE) {
1717 owned = mtx_owned(start_ccb->ccb_h.path->bus->sim->mtx);
1719 mtx_lock(start_ccb->ccb_h.path->bus->sim->mtx);
1720 xpt_async(AC_ADVINFO_CHANGED, start_ccb->ccb_h.path,
1721 (void *)(uintptr_t)cdai->buftype);
1723 mtx_unlock(start_ccb->ccb_h.path->bus->sim->mtx);
1728 ata_action(union ccb *start_ccb)
1731 switch (start_ccb->ccb_h.func_code) {
1732 case XPT_SET_TRAN_SETTINGS:
1734 ata_set_transfer_settings(&start_ccb->cts,
1735 start_ccb->ccb_h.path->device,
1736 /*async_update*/FALSE);
1741 ata_scan_bus(start_ccb->ccb_h.path->periph, start_ccb);
1744 ata_scan_lun(start_ccb->ccb_h.path->periph,
1745 start_ccb->ccb_h.path, start_ccb->crcn.flags,
1748 case XPT_GET_TRAN_SETTINGS:
1750 ata_get_transfer_settings(&start_ccb->cts);
1755 struct cam_ed *device;
1758 device = start_ccb->ccb_h.path->device;
1759 if (device->protocol == PROTO_SCSI &&
1760 (device->flags & CAM_DEV_IDENTIFY_DATA_VALID)) {
1762 device->ident_data.config & ATA_PROTO_MASK;
1765 (device->ident_data.config == ATA_PROTO_CFA) ? 0 :
1766 (p == ATA_PROTO_ATAPI_16) ? 16 :
1767 (p == ATA_PROTO_ATAPI_12) ? 12 : 0;
1769 if (start_ccb->csio.cdb_len > maxlen) {
1770 start_ccb->ccb_h.status = CAM_REQ_INVALID;
1771 xpt_done(start_ccb);
1774 xpt_action_default(start_ccb);
1777 case XPT_DEV_ADVINFO:
1779 ata_dev_advinfo(start_ccb);
1783 xpt_action_default(start_ccb);
1789 ata_get_transfer_settings(struct ccb_trans_settings *cts)
1791 struct ccb_trans_settings_ata *ata;
1792 struct ccb_trans_settings_scsi *scsi;
1793 struct cam_ed *device;
1794 struct cam_sim *sim;
1796 device = cts->ccb_h.path->device;
1797 sim = cts->ccb_h.path->bus->sim;
1798 (*(sim->sim_action))(sim, (union ccb *)cts);
1800 if (cts->protocol == PROTO_UNKNOWN ||
1801 cts->protocol == PROTO_UNSPECIFIED) {
1802 cts->protocol = device->protocol;
1803 cts->protocol_version = device->protocol_version;
1806 if (cts->protocol == PROTO_ATA) {
1807 ata = &cts->proto_specific.ata;
1808 if ((ata->valid & CTS_ATA_VALID_TQ) == 0) {
1809 ata->valid |= CTS_ATA_VALID_TQ;
1810 if (cts->type == CTS_TYPE_USER_SETTINGS ||
1811 (device->flags & CAM_DEV_TAG_AFTER_COUNT) != 0 ||
1812 (device->inq_flags & SID_CmdQue) != 0)
1813 ata->flags |= CTS_ATA_FLAGS_TAG_ENB;
1816 if (cts->protocol == PROTO_SCSI) {
1817 scsi = &cts->proto_specific.scsi;
1818 if ((scsi->valid & CTS_SCSI_VALID_TQ) == 0) {
1819 scsi->valid |= CTS_SCSI_VALID_TQ;
1820 if (cts->type == CTS_TYPE_USER_SETTINGS ||
1821 (device->flags & CAM_DEV_TAG_AFTER_COUNT) != 0 ||
1822 (device->inq_flags & SID_CmdQue) != 0)
1823 scsi->flags |= CTS_SCSI_FLAGS_TAG_ENB;
1827 if (cts->transport == XPORT_UNKNOWN ||
1828 cts->transport == XPORT_UNSPECIFIED) {
1829 cts->transport = device->transport;
1830 cts->transport_version = device->transport_version;
1835 ata_set_transfer_settings(struct ccb_trans_settings *cts, struct cam_ed *device,
1838 struct ccb_pathinq cpi;
1839 struct ccb_trans_settings_ata *ata;
1840 struct ccb_trans_settings_scsi *scsi;
1841 struct cam_sim *sim;
1842 struct ata_params *ident_data;
1843 struct scsi_inquiry_data *inq_data;
1845 if (device == NULL) {
1846 cts->ccb_h.status = CAM_PATH_INVALID;
1847 xpt_done((union ccb *)cts);
1851 if (cts->protocol == PROTO_UNKNOWN
1852 || cts->protocol == PROTO_UNSPECIFIED) {
1853 cts->protocol = device->protocol;
1854 cts->protocol_version = device->protocol_version;
1857 if (cts->protocol_version == PROTO_VERSION_UNKNOWN
1858 || cts->protocol_version == PROTO_VERSION_UNSPECIFIED)
1859 cts->protocol_version = device->protocol_version;
1861 if (cts->protocol != device->protocol) {
1862 xpt_print(cts->ccb_h.path, "Uninitialized Protocol %x:%x?\n",
1863 cts->protocol, device->protocol);
1864 cts->protocol = device->protocol;
1867 if (cts->protocol_version > device->protocol_version) {
1869 xpt_print(cts->ccb_h.path, "Down reving Protocol "
1870 "Version from %d to %d?\n", cts->protocol_version,
1871 device->protocol_version);
1873 cts->protocol_version = device->protocol_version;
1876 if (cts->transport == XPORT_UNKNOWN
1877 || cts->transport == XPORT_UNSPECIFIED) {
1878 cts->transport = device->transport;
1879 cts->transport_version = device->transport_version;
1882 if (cts->transport_version == XPORT_VERSION_UNKNOWN
1883 || cts->transport_version == XPORT_VERSION_UNSPECIFIED)
1884 cts->transport_version = device->transport_version;
1886 if (cts->transport != device->transport) {
1887 xpt_print(cts->ccb_h.path, "Uninitialized Transport %x:%x?\n",
1888 cts->transport, device->transport);
1889 cts->transport = device->transport;
1892 if (cts->transport_version > device->transport_version) {
1894 xpt_print(cts->ccb_h.path, "Down reving Transport "
1895 "Version from %d to %d?\n", cts->transport_version,
1896 device->transport_version);
1898 cts->transport_version = device->transport_version;
1901 sim = cts->ccb_h.path->bus->sim;
1902 ident_data = &device->ident_data;
1903 inq_data = &device->inq_data;
1904 if (cts->protocol == PROTO_ATA)
1905 ata = &cts->proto_specific.ata;
1908 if (cts->protocol == PROTO_SCSI)
1909 scsi = &cts->proto_specific.scsi;
1912 xpt_setup_ccb(&cpi.ccb_h, cts->ccb_h.path, CAM_PRIORITY_NONE);
1913 cpi.ccb_h.func_code = XPT_PATH_INQ;
1914 xpt_action((union ccb *)&cpi);
1916 /* Sanity checking */
1917 if ((cpi.hba_inquiry & PI_TAG_ABLE) == 0
1918 || (ata && (ident_data->satacapabilities & ATA_SUPPORT_NCQ) == 0)
1919 || (scsi && (INQ_DATA_TQ_ENABLED(inq_data)) == 0)
1920 || (device->queue_flags & SCP_QUEUE_DQUE) != 0
1921 || (device->mintags == 0)) {
1923 * Can't tag on hardware that doesn't support tags,
1924 * doesn't have it enabled, or has broken tag support.
1927 ata->flags &= ~CTS_ATA_FLAGS_TAG_ENB;
1929 scsi->flags &= ~CTS_SCSI_FLAGS_TAG_ENB;
1932 /* Start/stop tags use. */
1933 if (cts->type == CTS_TYPE_CURRENT_SETTINGS &&
1934 ((ata && (ata->valid & CTS_ATA_VALID_TQ) != 0) ||
1935 (scsi && (scsi->valid & CTS_SCSI_VALID_TQ) != 0))) {
1938 nowt = ((device->flags & CAM_DEV_TAG_AFTER_COUNT) != 0 ||
1939 (device->inq_flags & SID_CmdQue) != 0);
1941 newt = (ata->flags & CTS_ATA_FLAGS_TAG_ENB) != 0;
1943 newt = (scsi->flags & CTS_SCSI_FLAGS_TAG_ENB) != 0;
1945 if (newt && !nowt) {
1947 * Delay change to use tags until after a
1948 * few commands have gone to this device so
1949 * the controller has time to perform transfer
1950 * negotiations without tagged messages getting
1953 device->tag_delay_count = CAM_TAG_DELAY_COUNT;
1954 device->flags |= CAM_DEV_TAG_AFTER_COUNT;
1955 } else if (nowt && !newt)
1956 xpt_stop_tags(cts->ccb_h.path);
1959 if (async_update == FALSE)
1960 (*(sim->sim_action))(sim, (union ccb *)cts);
1964 * Handle any per-device event notifications that require action by the XPT.
1967 ata_dev_async(u_int32_t async_code, struct cam_eb *bus, struct cam_et *target,
1968 struct cam_ed *device, void *async_arg)
1971 struct cam_path newpath;
1974 * We only need to handle events for real devices.
1976 if (target->target_id == CAM_TARGET_WILDCARD
1977 || device->lun_id == CAM_LUN_WILDCARD)
1981 * We need our own path with wildcards expanded to
1982 * handle certain types of events.
1984 if ((async_code == AC_SENT_BDR)
1985 || (async_code == AC_BUS_RESET)
1986 || (async_code == AC_INQ_CHANGED))
1987 status = xpt_compile_path(&newpath, NULL,
1992 status = CAM_REQ_CMP_ERR;
1994 if (status == CAM_REQ_CMP) {
1995 if (async_code == AC_INQ_CHANGED) {
1997 * We've sent a start unit command, or
1998 * something similar to a device that
1999 * may have caused its inquiry data to
2000 * change. So we re-scan the device to
2001 * refresh the inquiry data for it.
2003 ata_scan_lun(newpath.periph, &newpath,
2004 CAM_EXPECT_INQ_CHANGE, NULL);
2006 /* We need to reinitialize device after reset. */
2007 ata_scan_lun(newpath.periph, &newpath,
2010 xpt_release_path(&newpath);
2011 } else if (async_code == AC_LOST_DEVICE &&
2012 (device->flags & CAM_DEV_UNCONFIGURED) == 0) {
2013 device->flags |= CAM_DEV_UNCONFIGURED;
2014 xpt_release_device(device);
2015 } else if (async_code == AC_TRANSFER_NEG) {
2016 struct ccb_trans_settings *settings;
2018 settings = (struct ccb_trans_settings *)async_arg;
2019 ata_set_transfer_settings(settings, device,
2020 /*async_update*/TRUE);
2025 ata_announce_periph(struct cam_periph *periph)
2027 struct ccb_pathinq cpi;
2028 struct ccb_trans_settings cts;
2029 struct cam_path *path = periph->path;
2033 mtx_assert(periph->sim->mtx, MA_OWNED);
2035 xpt_setup_ccb(&cts.ccb_h, path, CAM_PRIORITY_NORMAL);
2036 cts.ccb_h.func_code = XPT_GET_TRAN_SETTINGS;
2037 cts.type = CTS_TYPE_CURRENT_SETTINGS;
2038 xpt_action((union ccb*)&cts);
2039 if ((cts.ccb_h.status & CAM_STATUS_MASK) != CAM_REQ_CMP)
2041 /* Ask the SIM for its base transfer speed */
2042 xpt_setup_ccb(&cpi.ccb_h, path, CAM_PRIORITY_NORMAL);
2043 cpi.ccb_h.func_code = XPT_PATH_INQ;
2044 xpt_action((union ccb *)&cpi);
2045 /* Report connection speed */
2046 speed = cpi.base_transfer_speed;
2047 if (cts.ccb_h.status == CAM_REQ_CMP && cts.transport == XPORT_ATA) {
2048 struct ccb_trans_settings_pata *pata =
2049 &cts.xport_specific.ata;
2051 if (pata->valid & CTS_ATA_VALID_MODE)
2052 speed = ata_mode2speed(pata->mode);
2054 if (cts.ccb_h.status == CAM_REQ_CMP && cts.transport == XPORT_SATA) {
2055 struct ccb_trans_settings_sata *sata =
2056 &cts.xport_specific.sata;
2058 if (sata->valid & CTS_SATA_VALID_REVISION)
2059 speed = ata_revision2speed(sata->revision);
2063 printf("%s%d: %d.%03dMB/s transfers",
2064 periph->periph_name, periph->unit_number,
2067 printf("%s%d: %dKB/s transfers", periph->periph_name,
2068 periph->unit_number, speed);
2069 /* Report additional information about connection */
2070 if (cts.ccb_h.status == CAM_REQ_CMP && cts.transport == XPORT_ATA) {
2071 struct ccb_trans_settings_pata *pata =
2072 &cts.xport_specific.ata;
2075 if (pata->valid & CTS_ATA_VALID_MODE)
2076 printf("%s, ", ata_mode2string(pata->mode));
2077 if ((pata->valid & CTS_ATA_VALID_ATAPI) && pata->atapi != 0)
2078 printf("ATAPI %dbytes, ", pata->atapi);
2079 if (pata->valid & CTS_ATA_VALID_BYTECOUNT)
2080 printf("PIO %dbytes", pata->bytecount);
2083 if (cts.ccb_h.status == CAM_REQ_CMP && cts.transport == XPORT_SATA) {
2084 struct ccb_trans_settings_sata *sata =
2085 &cts.xport_specific.sata;
2088 if (sata->valid & CTS_SATA_VALID_REVISION)
2089 printf("SATA %d.x, ", sata->revision);
2092 if (sata->valid & CTS_SATA_VALID_MODE)
2093 printf("%s, ", ata_mode2string(sata->mode));
2094 if ((sata->valid & CTS_ATA_VALID_ATAPI) && sata->atapi != 0)
2095 printf("ATAPI %dbytes, ", sata->atapi);
2096 if (sata->valid & CTS_SATA_VALID_BYTECOUNT)
2097 printf("PIO %dbytes", sata->bytecount);