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_path *path,
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 ata_device_transport(periph->path);
253 probeschedule(periph);
258 probeschedule(struct cam_periph *periph)
263 softc = (probe_softc *)periph->softc;
264 ccb = (union ccb *)TAILQ_FIRST(&softc->request_ccbs);
266 if ((periph->path->device->flags & CAM_DEV_UNCONFIGURED) ||
267 periph->path->device->protocol == PROTO_SATAPM ||
268 periph->path->device->protocol == PROTO_SEMB)
269 PROBE_SET_ACTION(softc, PROBE_RESET);
271 PROBE_SET_ACTION(softc, PROBE_IDENTIFY);
273 if (ccb->crcn.flags & CAM_EXPECT_INQ_CHANGE)
274 softc->flags |= PROBE_NO_ANNOUNCE;
276 softc->flags &= ~PROBE_NO_ANNOUNCE;
278 xpt_schedule(periph, CAM_PRIORITY_XPT);
282 probestart(struct cam_periph *periph, union ccb *start_ccb)
284 struct ccb_trans_settings cts;
285 struct ccb_ataio *ataio;
286 struct ccb_scsiio *csio;
288 struct cam_path *path;
289 struct ata_params *ident_buf;
291 CAM_DEBUG(start_ccb->ccb_h.path, CAM_DEBUG_TRACE, ("probestart\n"));
293 softc = (probe_softc *)periph->softc;
294 path = start_ccb->ccb_h.path;
295 ataio = &start_ccb->ataio;
296 csio = &start_ccb->csio;
297 ident_buf = &periph->path->device->ident_data;
299 if (softc->restart) {
301 if ((path->device->flags & CAM_DEV_UNCONFIGURED) ||
302 path->device->protocol == PROTO_SATAPM ||
303 path->device->protocol == PROTO_SEMB)
304 softc->action = PROBE_RESET;
306 softc->action = PROBE_IDENTIFY;
308 switch (softc->action) {
310 cam_fill_ataio(ataio,
313 /*flags*/CAM_DIR_NONE,
318 ata_reset_cmd(ataio);
321 cam_fill_ataio(ataio,
326 /*data_ptr*/(u_int8_t *)&softc->ident_data,
327 /*dxfer_len*/sizeof(softc->ident_data),
329 if (periph->path->device->protocol == PROTO_ATA)
330 ata_28bit_cmd(ataio, ATA_ATA_IDENTIFY, 0, 0, 0);
332 ata_28bit_cmd(ataio, ATA_ATAPI_IDENTIFY, 0, 0, 0);
336 xpt_print(path, "Spinning up device\n");
337 cam_fill_ataio(ataio,
340 /*flags*/CAM_DIR_NONE | CAM_HIGH_POWER,
345 ata_28bit_cmd(ataio, ATA_SETFEATURES, ATA_SF_PUIS_SPINUP, 0, 0);
352 /* Fetch user modes from SIM. */
353 bzero(&cts, sizeof(cts));
354 xpt_setup_ccb(&cts.ccb_h, path, CAM_PRIORITY_NONE);
355 cts.ccb_h.func_code = XPT_GET_TRAN_SETTINGS;
356 cts.type = CTS_TYPE_USER_SETTINGS;
357 xpt_action((union ccb *)&cts);
358 if (path->device->transport == XPORT_ATA) {
359 if (cts.xport_specific.ata.valid & CTS_ATA_VALID_MODE)
360 mode = cts.xport_specific.ata.mode;
362 if (cts.xport_specific.sata.valid & CTS_SATA_VALID_MODE)
363 mode = cts.xport_specific.sata.mode;
365 if (periph->path->device->protocol == PROTO_ATA) {
366 if (ata_dma == 0 && (mode == 0 || mode > ATA_PIO_MAX))
369 if (atapi_dma == 0 && (mode == 0 || mode > ATA_PIO_MAX))
373 /* Honor device capabilities. */
374 wantmode = mode = ata_max_mode(ident_buf, mode);
375 /* Report modes to SIM. */
376 bzero(&cts, sizeof(cts));
377 xpt_setup_ccb(&cts.ccb_h, path, CAM_PRIORITY_NONE);
378 cts.ccb_h.func_code = XPT_SET_TRAN_SETTINGS;
379 cts.type = CTS_TYPE_CURRENT_SETTINGS;
380 if (path->device->transport == XPORT_ATA) {
381 cts.xport_specific.ata.mode = mode;
382 cts.xport_specific.ata.valid = CTS_ATA_VALID_MODE;
384 cts.xport_specific.sata.mode = mode;
385 cts.xport_specific.sata.valid = CTS_SATA_VALID_MODE;
387 xpt_action((union ccb *)&cts);
388 /* Fetch current modes from SIM. */
389 bzero(&cts, sizeof(cts));
390 xpt_setup_ccb(&cts.ccb_h, path, CAM_PRIORITY_NONE);
391 cts.ccb_h.func_code = XPT_GET_TRAN_SETTINGS;
392 cts.type = CTS_TYPE_CURRENT_SETTINGS;
393 xpt_action((union ccb *)&cts);
394 if (path->device->transport == XPORT_ATA) {
395 if (cts.xport_specific.ata.valid & CTS_ATA_VALID_MODE)
396 mode = cts.xport_specific.ata.mode;
398 if (cts.xport_specific.ata.valid & CTS_SATA_VALID_MODE)
399 mode = cts.xport_specific.sata.mode;
401 /* If SIM disagree - renegotiate. */
402 if (mode != wantmode)
404 /* Remember what transport thinks about DMA. */
406 path->device->inq_flags &= ~SID_DMA;
408 path->device->inq_flags |= SID_DMA;
409 xpt_async(AC_GETDEV_CHANGED, path, NULL);
410 cam_fill_ataio(ataio,
413 /*flags*/CAM_DIR_NONE,
418 ata_28bit_cmd(ataio, ATA_SETFEATURES, ATA_SF_SETXFER, 0, mode);
422 cam_fill_ataio(ataio,
430 ata_28bit_cmd(ataio, ATA_SETFEATURES,
431 (softc->caps & CTS_SATA_CAPS_H_PMREQ) ? 0x10 : 0x90,
435 cam_fill_ataio(ataio,
443 ata_28bit_cmd(ataio, ATA_SETFEATURES,
444 (softc->caps & CTS_SATA_CAPS_H_APST) ? 0x10 : 0x90,
448 cam_fill_ataio(ataio,
456 ata_28bit_cmd(ataio, ATA_SETFEATURES,
457 (softc->caps & CTS_SATA_CAPS_H_DMAAA) ? 0x10 : 0x90,
461 /* Remember what transport thinks about AEN. */
462 if (softc->caps & CTS_SATA_CAPS_H_AN)
463 path->device->inq_flags |= SID_AEN;
465 path->device->inq_flags &= ~SID_AEN;
466 xpt_async(AC_GETDEV_CHANGED, path, NULL);
467 cam_fill_ataio(ataio,
475 ata_28bit_cmd(ataio, ATA_SETFEATURES,
476 (softc->caps & CTS_SATA_CAPS_H_AN) ? 0x10 : 0x90,
479 case PROBE_SET_MULTI:
481 u_int sectors, bytecount;
483 bytecount = 8192; /* SATA maximum */
484 /* Fetch user bytecount from SIM. */
485 bzero(&cts, sizeof(cts));
486 xpt_setup_ccb(&cts.ccb_h, path, CAM_PRIORITY_NONE);
487 cts.ccb_h.func_code = XPT_GET_TRAN_SETTINGS;
488 cts.type = CTS_TYPE_USER_SETTINGS;
489 xpt_action((union ccb *)&cts);
490 if (path->device->transport == XPORT_ATA) {
491 if (cts.xport_specific.ata.valid & CTS_ATA_VALID_BYTECOUNT)
492 bytecount = cts.xport_specific.ata.bytecount;
494 if (cts.xport_specific.sata.valid & CTS_SATA_VALID_BYTECOUNT)
495 bytecount = cts.xport_specific.sata.bytecount;
497 /* Honor device capabilities. */
498 sectors = max(1, min(ident_buf->sectors_intr & 0xff,
499 bytecount / ata_logical_sector_size(ident_buf)));
500 /* Report bytecount to SIM. */
501 bzero(&cts, sizeof(cts));
502 xpt_setup_ccb(&cts.ccb_h, path, CAM_PRIORITY_NONE);
503 cts.ccb_h.func_code = XPT_SET_TRAN_SETTINGS;
504 cts.type = CTS_TYPE_CURRENT_SETTINGS;
505 if (path->device->transport == XPORT_ATA) {
506 cts.xport_specific.ata.bytecount = sectors *
507 ata_logical_sector_size(ident_buf);
508 cts.xport_specific.ata.valid = CTS_ATA_VALID_BYTECOUNT;
510 cts.xport_specific.sata.bytecount = sectors *
511 ata_logical_sector_size(ident_buf);
512 cts.xport_specific.sata.valid = CTS_SATA_VALID_BYTECOUNT;
514 xpt_action((union ccb *)&cts);
515 /* Fetch current bytecount from SIM. */
516 bzero(&cts, sizeof(cts));
517 xpt_setup_ccb(&cts.ccb_h, path, CAM_PRIORITY_NONE);
518 cts.ccb_h.func_code = XPT_GET_TRAN_SETTINGS;
519 cts.type = CTS_TYPE_CURRENT_SETTINGS;
520 xpt_action((union ccb *)&cts);
521 if (path->device->transport == XPORT_ATA) {
522 if (cts.xport_specific.ata.valid & CTS_ATA_VALID_BYTECOUNT)
523 bytecount = cts.xport_specific.ata.bytecount;
525 if (cts.xport_specific.sata.valid & CTS_SATA_VALID_BYTECOUNT)
526 bytecount = cts.xport_specific.sata.bytecount;
528 sectors = bytecount / ata_logical_sector_size(ident_buf);
530 cam_fill_ataio(ataio,
538 ata_28bit_cmd(ataio, ATA_SET_MULTI, 0, 0, sectors);
545 bytecount = 8192; /* SATA maximum */
546 /* Fetch user bytecount from SIM. */
547 bzero(&cts, sizeof(cts));
548 xpt_setup_ccb(&cts.ccb_h, path, CAM_PRIORITY_NONE);
549 cts.ccb_h.func_code = XPT_GET_TRAN_SETTINGS;
550 cts.type = CTS_TYPE_USER_SETTINGS;
551 xpt_action((union ccb *)&cts);
552 if (path->device->transport == XPORT_ATA) {
553 if (cts.xport_specific.ata.valid & CTS_ATA_VALID_BYTECOUNT)
554 bytecount = cts.xport_specific.ata.bytecount;
556 if (cts.xport_specific.sata.valid & CTS_SATA_VALID_BYTECOUNT)
557 bytecount = cts.xport_specific.sata.bytecount;
559 /* Honor device capabilities. */
561 bytecount = max(2, min(65534, bytecount));
562 if (ident_buf->satacapabilities != 0x0000 &&
563 ident_buf->satacapabilities != 0xffff) {
564 bytecount = min(8192, bytecount);
566 /* Report bytecount to SIM. */
567 bzero(&cts, sizeof(cts));
568 xpt_setup_ccb(&cts.ccb_h, path, CAM_PRIORITY_NONE);
569 cts.ccb_h.func_code = XPT_SET_TRAN_SETTINGS;
570 cts.type = CTS_TYPE_CURRENT_SETTINGS;
571 if (path->device->transport == XPORT_ATA) {
572 cts.xport_specific.ata.bytecount = bytecount;
573 cts.xport_specific.ata.valid = CTS_ATA_VALID_BYTECOUNT;
575 cts.xport_specific.sata.bytecount = bytecount;
576 cts.xport_specific.sata.valid = CTS_SATA_VALID_BYTECOUNT;
578 xpt_action((union ccb *)&cts);
581 case PROBE_FULL_INQUIRY:
584 struct scsi_inquiry_data *inq_buf =
585 &periph->path->device->inq_data;
587 if (softc->action == PROBE_INQUIRY)
588 inquiry_len = SHORT_INQUIRY_LENGTH;
590 inquiry_len = SID_ADDITIONAL_LENGTH(inq_buf);
592 * Some parallel SCSI devices fail to send an
593 * ignore wide residue message when dealing with
594 * odd length inquiry requests. Round up to be
597 inquiry_len = roundup2(inquiry_len, 2);
607 /*timeout*/60 * 1000);
611 cam_fill_ataio(ataio,
614 /*flags*/CAM_DIR_NONE,
619 ata_pm_read_cmd(ataio, 0, 15);
622 cam_fill_ataio(ataio,
625 /*flags*/CAM_DIR_NONE,
630 ata_pm_read_cmd(ataio, 1, 15);
632 case PROBE_IDENTIFY_SES:
633 cam_fill_ataio(ataio,
638 /*data_ptr*/(u_int8_t *)&softc->ident_data,
639 /*dxfer_len*/sizeof(softc->ident_data),
641 ata_28bit_cmd(ataio, ATA_SEP_ATTN, 0xEC, 0x02,
642 sizeof(softc->ident_data) / 4);
644 case PROBE_IDENTIFY_SAFTE:
645 cam_fill_ataio(ataio,
650 /*data_ptr*/(u_int8_t *)&softc->ident_data,
651 /*dxfer_len*/sizeof(softc->ident_data),
653 ata_28bit_cmd(ataio, ATA_SEP_ATTN, 0xEC, 0x00,
654 sizeof(softc->ident_data) / 4);
657 panic("probestart: invalid action state 0x%x\n", softc->action);
659 start_ccb->ccb_h.flags |= CAM_DEV_QFREEZE;
660 xpt_action(start_ccb);
664 proberequestdefaultnegotiation(struct cam_periph *periph)
666 struct ccb_trans_settings cts;
668 xpt_setup_ccb(&cts.ccb_h, periph->path, CAM_PRIORITY_NONE);
669 cts.ccb_h.func_code = XPT_GET_TRAN_SETTINGS;
670 cts.type = CTS_TYPE_USER_SETTINGS;
671 xpt_action((union ccb *)&cts);
672 if ((cts.ccb_h.status & CAM_STATUS_MASK) != CAM_REQ_CMP)
674 cts.xport_specific.valid = 0;
675 cts.ccb_h.func_code = XPT_SET_TRAN_SETTINGS;
676 cts.type = CTS_TYPE_CURRENT_SETTINGS;
677 xpt_action((union ccb *)&cts);
681 probedone(struct cam_periph *periph, union ccb *done_ccb)
683 struct ccb_trans_settings cts;
684 struct ata_params *ident_buf;
685 struct scsi_inquiry_data *inq_buf;
687 struct cam_path *path;
691 int changed = 1, found = 1;
692 static const uint8_t fake_device_id_hdr[8] =
693 {0, SVPD_DEVICE_ID, 0, 12,
694 SVPD_ID_CODESET_BINARY, SVPD_ID_TYPE_NAA, 0, 8};
696 CAM_DEBUG(done_ccb->ccb_h.path, CAM_DEBUG_TRACE, ("probedone\n"));
698 softc = (probe_softc *)periph->softc;
699 path = done_ccb->ccb_h.path;
700 priority = done_ccb->ccb_h.pinfo.priority;
701 ident_buf = &path->device->ident_data;
702 inq_buf = &path->device->inq_data;
704 if ((done_ccb->ccb_h.status & CAM_STATUS_MASK) != CAM_REQ_CMP) {
705 if (cam_periph_error(done_ccb,
706 0, softc->restart ? (SF_NO_RECOVERY | SF_NO_RETRY) : 0,
709 /* Drop freeze taken due to CAM_DEV_QFREEZE flag set. */
710 cam_release_devq(path, 0, 0, 0, FALSE);
713 if ((done_ccb->ccb_h.status & CAM_DEV_QFRZN) != 0) {
714 /* Don't wedge the queue */
715 xpt_release_devq(path, /*count*/1, /*run_queue*/TRUE);
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);
911 ata_bswap(path->device->device_id + 8, 8);
915 path->device->flags |= CAM_DEV_IDENTIFY_DATA_VALID;
916 xpt_async(AC_GETDEV_CHANGED, path, NULL);
918 if (ident_buf->satacapabilities & ATA_SUPPORT_NCQ) {
919 path->device->mintags = 2;
920 path->device->maxtags =
921 ATA_QUEUE_LEN(ident_buf->queue) + 1;
923 ata_find_quirk(path->device);
924 if (path->device->mintags != 0 &&
925 path->bus->sim->max_tagged_dev_openings != 0) {
926 /* Check if the SIM does not want queued commands. */
927 bzero(&cpi, sizeof(cpi));
928 xpt_setup_ccb(&cpi.ccb_h, path, CAM_PRIORITY_NONE);
929 cpi.ccb_h.func_code = XPT_PATH_INQ;
930 xpt_action((union ccb *)&cpi);
931 if (cpi.ccb_h.status == CAM_REQ_CMP &&
932 (cpi.hba_inquiry & PI_TAG_ABLE)) {
933 /* Report SIM which tags are allowed. */
934 bzero(&cts, sizeof(cts));
935 xpt_setup_ccb(&cts.ccb_h, path, CAM_PRIORITY_NONE);
936 cts.ccb_h.func_code = XPT_SET_TRAN_SETTINGS;
937 cts.type = CTS_TYPE_CURRENT_SETTINGS;
938 cts.xport_specific.sata.tags = path->device->maxtags;
939 cts.xport_specific.sata.valid = CTS_SATA_VALID_TAGS;
940 xpt_action((union ccb *)&cts);
943 ata_device_transport(path);
945 proberequestdefaultnegotiation(periph);
946 PROBE_SET_ACTION(softc, PROBE_SETMODE);
947 xpt_release_ccb(done_ccb);
948 xpt_schedule(periph, priority);
953 xpt_print(path, "Spin-up done\n");
955 PROBE_SET_ACTION(softc, PROBE_IDENTIFY);
956 xpt_release_ccb(done_ccb);
957 xpt_schedule(periph, priority);
960 /* Set supported bits. */
961 bzero(&cts, sizeof(cts));
962 xpt_setup_ccb(&cts.ccb_h, path, CAM_PRIORITY_NONE);
963 cts.ccb_h.func_code = XPT_GET_TRAN_SETTINGS;
964 cts.type = CTS_TYPE_CURRENT_SETTINGS;
965 xpt_action((union ccb *)&cts);
966 if (path->device->transport == XPORT_SATA &&
967 cts.xport_specific.sata.valid & CTS_SATA_VALID_CAPS)
968 caps = cts.xport_specific.sata.caps & CTS_SATA_CAPS_H;
969 else if (path->device->transport == XPORT_ATA &&
970 cts.xport_specific.ata.valid & CTS_ATA_VALID_CAPS)
971 caps = cts.xport_specific.ata.caps & CTS_ATA_CAPS_H;
974 if (path->device->transport == XPORT_SATA &&
975 ident_buf->satacapabilities != 0xffff) {
976 if (ident_buf->satacapabilities & ATA_SUPPORT_IFPWRMNGTRCV)
977 caps |= CTS_SATA_CAPS_D_PMREQ;
978 if (ident_buf->satacapabilities & ATA_SUPPORT_HAPST)
979 caps |= CTS_SATA_CAPS_D_APST;
981 /* Mask unwanted bits. */
982 bzero(&cts, sizeof(cts));
983 xpt_setup_ccb(&cts.ccb_h, path, CAM_PRIORITY_NONE);
984 cts.ccb_h.func_code = XPT_GET_TRAN_SETTINGS;
985 cts.type = CTS_TYPE_USER_SETTINGS;
986 xpt_action((union ccb *)&cts);
987 if (path->device->transport == XPORT_SATA &&
988 cts.xport_specific.sata.valid & CTS_SATA_VALID_CAPS)
989 caps &= cts.xport_specific.sata.caps;
990 else if (path->device->transport == XPORT_ATA &&
991 cts.xport_specific.ata.valid & CTS_ATA_VALID_CAPS)
992 caps &= cts.xport_specific.ata.caps;
996 * Remember what transport thinks about 48-bit DMA. If
997 * capability information is not provided or transport is
998 * SATA, we take support for granted.
1000 if (!(path->device->inq_flags & SID_DMA) ||
1001 (path->device->transport == XPORT_ATA &&
1002 (cts.xport_specific.ata.valid & CTS_ATA_VALID_CAPS) &&
1003 !(caps & CTS_ATA_CAPS_H_DMA48)))
1004 path->device->inq_flags &= ~SID_DMA48;
1006 path->device->inq_flags |= SID_DMA48;
1007 /* Store result to SIM. */
1008 bzero(&cts, sizeof(cts));
1009 xpt_setup_ccb(&cts.ccb_h, path, CAM_PRIORITY_NONE);
1010 cts.ccb_h.func_code = XPT_SET_TRAN_SETTINGS;
1011 cts.type = CTS_TYPE_CURRENT_SETTINGS;
1012 if (path->device->transport == XPORT_SATA) {
1013 cts.xport_specific.sata.caps = caps;
1014 cts.xport_specific.sata.valid = CTS_SATA_VALID_CAPS;
1016 cts.xport_specific.ata.caps = caps;
1017 cts.xport_specific.ata.valid = CTS_ATA_VALID_CAPS;
1019 xpt_action((union ccb *)&cts);
1021 if (path->device->transport != XPORT_SATA)
1023 if ((ident_buf->satasupport & ATA_SUPPORT_IFPWRMNGT) &&
1024 (!(softc->caps & CTS_SATA_CAPS_H_PMREQ)) !=
1025 (!(ident_buf->sataenabled & ATA_SUPPORT_IFPWRMNGT))) {
1026 PROBE_SET_ACTION(softc, PROBE_SETPM);
1027 xpt_release_ccb(done_ccb);
1028 xpt_schedule(periph, priority);
1033 if (ident_buf->satacapabilities != 0xffff &&
1034 (ident_buf->satacapabilities & ATA_SUPPORT_DAPST) &&
1035 (!(softc->caps & CTS_SATA_CAPS_H_APST)) !=
1036 (!(ident_buf->sataenabled & ATA_ENABLED_DAPST))) {
1037 PROBE_SET_ACTION(softc, PROBE_SETAPST);
1038 xpt_release_ccb(done_ccb);
1039 xpt_schedule(periph, priority);
1044 if ((ident_buf->satasupport & ATA_SUPPORT_AUTOACTIVATE) &&
1045 (!(softc->caps & CTS_SATA_CAPS_H_DMAAA)) !=
1046 (!(ident_buf->sataenabled & ATA_SUPPORT_AUTOACTIVATE))) {
1047 PROBE_SET_ACTION(softc, PROBE_SETDMAAA);
1048 xpt_release_ccb(done_ccb);
1049 xpt_schedule(periph, priority);
1053 case PROBE_SETDMAAA:
1054 if (path->device->protocol != PROTO_ATA &&
1055 (ident_buf->satasupport & ATA_SUPPORT_ASYNCNOTIF) &&
1056 (!(softc->caps & CTS_SATA_CAPS_H_AN)) !=
1057 (!(ident_buf->sataenabled & ATA_SUPPORT_ASYNCNOTIF))) {
1058 PROBE_SET_ACTION(softc, PROBE_SETAN);
1059 xpt_release_ccb(done_ccb);
1060 xpt_schedule(periph, priority);
1066 if (path->device->protocol == PROTO_ATA) {
1067 PROBE_SET_ACTION(softc, PROBE_SET_MULTI);
1069 PROBE_SET_ACTION(softc, PROBE_INQUIRY);
1071 xpt_release_ccb(done_ccb);
1072 xpt_schedule(periph, priority);
1074 case PROBE_SET_MULTI:
1075 if (periph->path->device->flags & CAM_DEV_UNCONFIGURED) {
1076 path->device->flags &= ~CAM_DEV_UNCONFIGURED;
1077 xpt_acquire_device(path->device);
1078 done_ccb->ccb_h.func_code = XPT_GDEV_TYPE;
1079 xpt_action(done_ccb);
1080 xpt_async(AC_FOUND_DEVICE, path, done_ccb);
1082 PROBE_SET_ACTION(softc, PROBE_DONE);
1085 case PROBE_FULL_INQUIRY:
1087 u_int8_t periph_qual, len;
1089 path->device->flags |= CAM_DEV_INQUIRY_DATA_VALID;
1091 periph_qual = SID_QUAL(inq_buf);
1093 if (periph_qual != SID_QUAL_LU_CONNECTED)
1097 * We conservatively request only
1098 * SHORT_INQUIRY_LEN bytes of inquiry
1099 * information during our first try
1100 * at sending an INQUIRY. If the device
1101 * has more information to give,
1102 * perform a second request specifying
1103 * the amount of information the device
1104 * is willing to give.
1106 len = inq_buf->additional_length
1107 + offsetof(struct scsi_inquiry_data, additional_length) + 1;
1108 if (softc->action == PROBE_INQUIRY
1109 && len > SHORT_INQUIRY_LENGTH) {
1110 PROBE_SET_ACTION(softc, PROBE_FULL_INQUIRY);
1111 xpt_release_ccb(done_ccb);
1112 xpt_schedule(periph, priority);
1116 ata_device_transport(path);
1117 if (periph->path->device->flags & CAM_DEV_UNCONFIGURED) {
1118 path->device->flags &= ~CAM_DEV_UNCONFIGURED;
1119 xpt_acquire_device(path->device);
1120 done_ccb->ccb_h.func_code = XPT_GDEV_TYPE;
1121 xpt_action(done_ccb);
1122 xpt_async(AC_FOUND_DEVICE, path, done_ccb);
1124 PROBE_SET_ACTION(softc, PROBE_DONE);
1128 if ((path->device->flags & CAM_DEV_IDENTIFY_DATA_VALID) == 0)
1129 bzero(ident_buf, sizeof(*ident_buf));
1130 softc->pm_pid = (done_ccb->ataio.res.lba_high << 24) +
1131 (done_ccb->ataio.res.lba_mid << 16) +
1132 (done_ccb->ataio.res.lba_low << 8) +
1133 done_ccb->ataio.res.sector_count;
1134 ((uint32_t *)ident_buf)[0] = softc->pm_pid;
1135 snprintf(ident_buf->model, sizeof(ident_buf->model),
1136 "Port Multiplier %08x", softc->pm_pid);
1137 PROBE_SET_ACTION(softc, PROBE_PM_PRV);
1138 xpt_release_ccb(done_ccb);
1139 xpt_schedule(periph, priority);
1142 softc->pm_prv = (done_ccb->ataio.res.lba_high << 24) +
1143 (done_ccb->ataio.res.lba_mid << 16) +
1144 (done_ccb->ataio.res.lba_low << 8) +
1145 done_ccb->ataio.res.sector_count;
1146 ((uint32_t *)ident_buf)[1] = softc->pm_prv;
1147 snprintf(ident_buf->revision, sizeof(ident_buf->revision),
1148 "%04x", softc->pm_prv);
1149 path->device->flags |= CAM_DEV_IDENTIFY_DATA_VALID;
1150 ata_device_transport(path);
1151 if (periph->path->device->flags & CAM_DEV_UNCONFIGURED)
1152 proberequestdefaultnegotiation(periph);
1153 /* Set supported bits. */
1154 bzero(&cts, sizeof(cts));
1155 xpt_setup_ccb(&cts.ccb_h, path, CAM_PRIORITY_NONE);
1156 cts.ccb_h.func_code = XPT_GET_TRAN_SETTINGS;
1157 cts.type = CTS_TYPE_CURRENT_SETTINGS;
1158 xpt_action((union ccb *)&cts);
1159 if (cts.xport_specific.sata.valid & CTS_SATA_VALID_CAPS)
1160 caps = cts.xport_specific.sata.caps & CTS_SATA_CAPS_H;
1163 /* All PMPs must support PM requests. */
1164 caps |= CTS_SATA_CAPS_D_PMREQ;
1165 /* Mask unwanted bits. */
1166 bzero(&cts, sizeof(cts));
1167 xpt_setup_ccb(&cts.ccb_h, path, CAM_PRIORITY_NONE);
1168 cts.ccb_h.func_code = XPT_GET_TRAN_SETTINGS;
1169 cts.type = CTS_TYPE_USER_SETTINGS;
1170 xpt_action((union ccb *)&cts);
1171 if (cts.xport_specific.sata.valid & CTS_SATA_VALID_CAPS)
1172 caps &= cts.xport_specific.sata.caps;
1175 /* Remember what transport thinks about AEN. */
1176 if ((caps & CTS_SATA_CAPS_H_AN) && path->device->protocol != PROTO_ATA)
1177 path->device->inq_flags |= SID_AEN;
1179 path->device->inq_flags &= ~SID_AEN;
1180 /* Store result to SIM. */
1181 bzero(&cts, sizeof(cts));
1182 xpt_setup_ccb(&cts.ccb_h, path, CAM_PRIORITY_NONE);
1183 cts.ccb_h.func_code = XPT_SET_TRAN_SETTINGS;
1184 cts.type = CTS_TYPE_CURRENT_SETTINGS;
1185 cts.xport_specific.sata.caps = caps;
1186 cts.xport_specific.sata.valid = CTS_SATA_VALID_CAPS;
1187 xpt_action((union ccb *)&cts);
1189 xpt_async(AC_GETDEV_CHANGED, path, NULL);
1190 if (periph->path->device->flags & CAM_DEV_UNCONFIGURED) {
1191 path->device->flags &= ~CAM_DEV_UNCONFIGURED;
1192 xpt_acquire_device(path->device);
1193 done_ccb->ccb_h.func_code = XPT_GDEV_TYPE;
1194 xpt_action(done_ccb);
1195 xpt_async(AC_FOUND_DEVICE, path, done_ccb);
1197 done_ccb->ccb_h.func_code = XPT_GDEV_TYPE;
1198 xpt_action(done_ccb);
1199 xpt_async(AC_SCSI_AEN, path, done_ccb);
1201 PROBE_SET_ACTION(softc, PROBE_DONE);
1203 case PROBE_IDENTIFY_SES:
1204 case PROBE_IDENTIFY_SAFTE:
1205 if ((periph->path->device->flags & CAM_DEV_UNCONFIGURED) == 0) {
1206 /* Check that it is the same device. */
1207 if (bcmp(&softc->ident_data, ident_buf, 53)) {
1208 /* Device changed. */
1209 xpt_async(AC_LOST_DEVICE, path, NULL);
1211 bcopy(&softc->ident_data, ident_buf, sizeof(struct ata_params));
1216 bcopy(&softc->ident_data, ident_buf, sizeof(struct ata_params));
1217 /* Clean up from previous instance of this device */
1218 if (path->device->device_id != NULL) {
1219 free(path->device->device_id, M_CAMXPT);
1220 path->device->device_id = NULL;
1221 path->device->device_id_len = 0;
1223 path->device->device_id =
1224 malloc(16, M_CAMXPT, M_NOWAIT);
1225 if (path->device->device_id != NULL) {
1226 path->device->device_id_len = 16;
1227 bcopy(&fake_device_id_hdr,
1228 path->device->device_id, 8);
1229 bcopy(((uint8_t*)ident_buf) + 2,
1230 path->device->device_id + 8, 8);
1233 path->device->flags |= CAM_DEV_IDENTIFY_DATA_VALID;
1235 ata_device_transport(path);
1237 proberequestdefaultnegotiation(periph);
1239 if (periph->path->device->flags & CAM_DEV_UNCONFIGURED) {
1240 path->device->flags &= ~CAM_DEV_UNCONFIGURED;
1241 xpt_acquire_device(path->device);
1242 done_ccb->ccb_h.func_code = XPT_GDEV_TYPE;
1243 xpt_action(done_ccb);
1244 xpt_async(AC_FOUND_DEVICE, path, done_ccb);
1246 PROBE_SET_ACTION(softc, PROBE_DONE);
1249 panic("probedone: invalid action state 0x%x\n", softc->action);
1252 if (softc->restart) {
1254 xpt_release_ccb(done_ccb);
1255 probeschedule(periph);
1258 xpt_release_ccb(done_ccb);
1259 CAM_DEBUG(periph->path, CAM_DEBUG_PROBE, ("Probe completed\n"));
1260 while ((done_ccb = (union ccb *)TAILQ_FIRST(&softc->request_ccbs))) {
1261 TAILQ_REMOVE(&softc->request_ccbs,
1262 &done_ccb->ccb_h, periph_links.tqe);
1263 done_ccb->ccb_h.status = found ? CAM_REQ_CMP : CAM_REQ_CMP_ERR;
1266 /* Drop freeze taken due to CAM_DEV_QFREEZE flag set. */
1267 cam_release_devq(path, 0, 0, 0, FALSE);
1268 cam_periph_invalidate(periph);
1269 cam_periph_release_locked(periph);
1273 probecleanup(struct cam_periph *periph)
1275 free(periph->softc, M_CAMXPT);
1279 ata_find_quirk(struct cam_ed *device)
1281 struct ata_quirk_entry *quirk;
1284 match = cam_quirkmatch((caddr_t)&device->ident_data,
1285 (caddr_t)ata_quirk_table,
1286 ata_quirk_table_size,
1287 sizeof(*ata_quirk_table), ata_identify_match);
1290 panic("xpt_find_quirk: device didn't match wildcard entry!!");
1292 quirk = (struct ata_quirk_entry *)match;
1293 device->quirk = quirk;
1294 if (quirk->quirks & CAM_QUIRK_MAXTAGS) {
1295 device->mintags = quirk->mintags;
1296 device->maxtags = quirk->maxtags;
1301 union ccb *request_ccb;
1302 struct ccb_pathinq *cpi;
1304 } ata_scan_bus_info;
1307 * To start a scan, request_ccb is an XPT_SCAN_BUS ccb.
1308 * As the scan progresses, xpt_scan_bus is used as the
1309 * callback on completion function.
1312 ata_scan_bus(struct cam_periph *periph, union ccb *request_ccb)
1314 struct cam_path *path;
1315 ata_scan_bus_info *scan_info;
1316 union ccb *work_ccb, *reset_ccb;
1320 CAM_DEBUG(request_ccb->ccb_h.path, CAM_DEBUG_TRACE,
1321 ("xpt_scan_bus\n"));
1322 switch (request_ccb->ccb_h.func_code) {
1325 /* Find out the characteristics of the bus */
1326 work_ccb = xpt_alloc_ccb_nowait();
1327 if (work_ccb == NULL) {
1328 request_ccb->ccb_h.status = CAM_RESRC_UNAVAIL;
1329 xpt_done(request_ccb);
1332 xpt_setup_ccb(&work_ccb->ccb_h, request_ccb->ccb_h.path,
1333 request_ccb->ccb_h.pinfo.priority);
1334 work_ccb->ccb_h.func_code = XPT_PATH_INQ;
1335 xpt_action(work_ccb);
1336 if (work_ccb->ccb_h.status != CAM_REQ_CMP) {
1337 request_ccb->ccb_h.status = work_ccb->ccb_h.status;
1338 xpt_free_ccb(work_ccb);
1339 xpt_done(request_ccb);
1343 /* We may need to reset bus first, if we haven't done it yet. */
1344 if ((work_ccb->cpi.hba_inquiry &
1345 (PI_WIDE_32|PI_WIDE_16|PI_SDTR_ABLE)) &&
1346 !(work_ccb->cpi.hba_misc & PIM_NOBUSRESET) &&
1347 !timevalisset(&request_ccb->ccb_h.path->bus->last_reset)) {
1348 reset_ccb = xpt_alloc_ccb_nowait();
1349 if (reset_ccb == NULL) {
1350 request_ccb->ccb_h.status = CAM_RESRC_UNAVAIL;
1351 xpt_free_ccb(work_ccb);
1352 xpt_done(request_ccb);
1355 xpt_setup_ccb(&reset_ccb->ccb_h, request_ccb->ccb_h.path,
1357 reset_ccb->ccb_h.func_code = XPT_RESET_BUS;
1358 xpt_action(reset_ccb);
1359 if (reset_ccb->ccb_h.status != CAM_REQ_CMP) {
1360 request_ccb->ccb_h.status = reset_ccb->ccb_h.status;
1361 xpt_free_ccb(reset_ccb);
1362 xpt_free_ccb(work_ccb);
1363 xpt_done(request_ccb);
1366 xpt_free_ccb(reset_ccb);
1369 /* Save some state for use while we probe for devices */
1370 scan_info = (ata_scan_bus_info *)
1371 malloc(sizeof(ata_scan_bus_info), M_CAMXPT, M_NOWAIT);
1372 if (scan_info == NULL) {
1373 request_ccb->ccb_h.status = CAM_RESRC_UNAVAIL;
1374 xpt_free_ccb(work_ccb);
1375 xpt_done(request_ccb);
1378 scan_info->request_ccb = request_ccb;
1379 scan_info->cpi = &work_ccb->cpi;
1380 /* If PM supported, probe it first. */
1381 if (scan_info->cpi->hba_inquiry & PI_SATAPM)
1382 scan_info->counter = scan_info->cpi->max_target;
1384 scan_info->counter = 0;
1386 work_ccb = xpt_alloc_ccb_nowait();
1387 if (work_ccb == NULL) {
1388 free(scan_info, M_CAMXPT);
1389 request_ccb->ccb_h.status = CAM_RESRC_UNAVAIL;
1390 xpt_done(request_ccb);
1393 mtx = xpt_path_mtx(scan_info->request_ccb->ccb_h.path);
1396 work_ccb = request_ccb;
1397 /* Reuse the same CCB to query if a device was really found */
1398 scan_info = (ata_scan_bus_info *)work_ccb->ccb_h.ppriv_ptr0;
1399 mtx = xpt_path_mtx(scan_info->request_ccb->ccb_h.path);
1401 /* If there is PMP... */
1402 if ((scan_info->cpi->hba_inquiry & PI_SATAPM) &&
1403 (scan_info->counter == scan_info->cpi->max_target)) {
1404 if (work_ccb->ccb_h.status == CAM_REQ_CMP) {
1405 /* everything else will be probed by it */
1406 /* Free the current request path- we're done with it. */
1407 xpt_free_path(work_ccb->ccb_h.path);
1410 struct ccb_trans_settings cts;
1412 /* Report SIM that PM is absent. */
1413 bzero(&cts, sizeof(cts));
1414 xpt_setup_ccb(&cts.ccb_h,
1415 work_ccb->ccb_h.path, CAM_PRIORITY_NONE);
1416 cts.ccb_h.func_code = XPT_SET_TRAN_SETTINGS;
1417 cts.type = CTS_TYPE_CURRENT_SETTINGS;
1418 cts.xport_specific.sata.pm_present = 0;
1419 cts.xport_specific.sata.valid = CTS_SATA_VALID_PM;
1420 xpt_action((union ccb *)&cts);
1423 /* Free the current request path- we're done with it. */
1424 xpt_free_path(work_ccb->ccb_h.path);
1425 if (scan_info->counter ==
1426 ((scan_info->cpi->hba_inquiry & PI_SATAPM) ?
1427 0 : scan_info->cpi->max_target)) {
1430 xpt_free_ccb(work_ccb);
1431 xpt_free_ccb((union ccb *)scan_info->cpi);
1432 request_ccb = scan_info->request_ccb;
1433 free(scan_info, M_CAMXPT);
1434 request_ccb->ccb_h.status = CAM_REQ_CMP;
1435 xpt_done(request_ccb);
1438 /* Take next device. Wrap from max (PMP) to 0. */
1439 scan_info->counter = (scan_info->counter + 1 ) %
1440 (scan_info->cpi->max_target + 1);
1442 status = xpt_create_path(&path, NULL,
1443 scan_info->request_ccb->ccb_h.path_id,
1444 scan_info->counter, 0);
1445 if (status != CAM_REQ_CMP) {
1446 if (request_ccb->ccb_h.func_code == XPT_SCAN_LUN)
1448 printf("xpt_scan_bus: xpt_create_path failed"
1449 " with status %#x, bus scan halted\n",
1451 xpt_free_ccb(work_ccb);
1452 xpt_free_ccb((union ccb *)scan_info->cpi);
1453 request_ccb = scan_info->request_ccb;
1454 free(scan_info, M_CAMXPT);
1455 request_ccb->ccb_h.status = status;
1456 xpt_done(request_ccb);
1459 xpt_setup_ccb(&work_ccb->ccb_h, path,
1460 scan_info->request_ccb->ccb_h.pinfo.priority);
1461 work_ccb->ccb_h.func_code = XPT_SCAN_LUN;
1462 work_ccb->ccb_h.cbfcnp = ata_scan_bus;
1463 work_ccb->ccb_h.flags |= CAM_UNLOCKED;
1464 work_ccb->ccb_h.ppriv_ptr0 = scan_info;
1465 work_ccb->crcn.flags = scan_info->request_ccb->crcn.flags;
1467 if (request_ccb->ccb_h.func_code == XPT_SCAN_LUN)
1469 xpt_action(work_ccb);
1479 ata_scan_lun(struct cam_periph *periph, struct cam_path *path,
1480 cam_flags flags, union ccb *request_ccb)
1482 struct ccb_pathinq cpi;
1484 struct cam_path *new_path;
1485 struct cam_periph *old_periph;
1488 CAM_DEBUG(path, CAM_DEBUG_TRACE, ("xpt_scan_lun\n"));
1490 xpt_setup_ccb(&cpi.ccb_h, path, CAM_PRIORITY_NONE);
1491 cpi.ccb_h.func_code = XPT_PATH_INQ;
1492 xpt_action((union ccb *)&cpi);
1494 if (cpi.ccb_h.status != CAM_REQ_CMP) {
1495 if (request_ccb != NULL) {
1496 request_ccb->ccb_h.status = cpi.ccb_h.status;
1497 xpt_done(request_ccb);
1502 if (request_ccb == NULL) {
1503 request_ccb = xpt_alloc_ccb_nowait();
1504 if (request_ccb == NULL) {
1505 xpt_print(path, "xpt_scan_lun: can't allocate CCB, "
1506 "can't continue\n");
1509 status = xpt_create_path(&new_path, NULL,
1511 path->target->target_id,
1512 path->device->lun_id);
1513 if (status != CAM_REQ_CMP) {
1514 xpt_print(path, "xpt_scan_lun: can't create path, "
1515 "can't continue\n");
1516 xpt_free_ccb(request_ccb);
1519 xpt_setup_ccb(&request_ccb->ccb_h, new_path, CAM_PRIORITY_XPT);
1520 request_ccb->ccb_h.cbfcnp = xptscandone;
1521 request_ccb->ccb_h.flags |= CAM_UNLOCKED;
1522 request_ccb->ccb_h.func_code = XPT_SCAN_LUN;
1523 request_ccb->crcn.flags = flags;
1526 lock = (xpt_path_owned(path) == 0);
1528 xpt_path_lock(path);
1529 if ((old_periph = cam_periph_find(path, "aprobe")) != NULL) {
1530 if ((old_periph->flags & CAM_PERIPH_INVALID) == 0) {
1533 softc = (probe_softc *)old_periph->softc;
1534 TAILQ_INSERT_TAIL(&softc->request_ccbs,
1535 &request_ccb->ccb_h, periph_links.tqe);
1538 request_ccb->ccb_h.status = CAM_REQ_CMP_ERR;
1539 xpt_done(request_ccb);
1542 status = cam_periph_alloc(proberegister, NULL, probecleanup,
1543 probestart, "aprobe",
1545 request_ccb->ccb_h.path, NULL, 0,
1548 if (status != CAM_REQ_CMP) {
1549 xpt_print(path, "xpt_scan_lun: cam_alloc_periph "
1550 "returned an error, can't continue probe\n");
1551 request_ccb->ccb_h.status = status;
1552 xpt_done(request_ccb);
1556 xpt_path_unlock(path);
1560 xptscandone(struct cam_periph *periph, union ccb *done_ccb)
1563 xpt_free_path(done_ccb->ccb_h.path);
1564 xpt_free_ccb(done_ccb);
1567 static struct cam_ed *
1568 ata_alloc_device(struct cam_eb *bus, struct cam_et *target, lun_id_t lun_id)
1570 struct ata_quirk_entry *quirk;
1571 struct cam_ed *device;
1573 device = xpt_alloc_device(bus, target, lun_id);
1578 * Take the default quirk entry until we have inquiry
1579 * data and can determine a better quirk to use.
1581 quirk = &ata_quirk_table[ata_quirk_table_size - 1];
1582 device->quirk = (void *)quirk;
1583 device->mintags = 0;
1584 device->maxtags = 0;
1585 bzero(&device->inq_data, sizeof(device->inq_data));
1586 device->inq_flags = 0;
1587 device->queue_flags = 0;
1588 device->serial_num = NULL;
1589 device->serial_num_len = 0;
1594 ata_device_transport(struct cam_path *path)
1596 struct ccb_pathinq cpi;
1597 struct ccb_trans_settings cts;
1598 struct scsi_inquiry_data *inq_buf = NULL;
1599 struct ata_params *ident_buf = NULL;
1601 /* Get transport information from the SIM */
1602 xpt_setup_ccb(&cpi.ccb_h, path, CAM_PRIORITY_NONE);
1603 cpi.ccb_h.func_code = XPT_PATH_INQ;
1604 xpt_action((union ccb *)&cpi);
1606 path->device->transport = cpi.transport;
1607 if ((path->device->flags & CAM_DEV_INQUIRY_DATA_VALID) != 0)
1608 inq_buf = &path->device->inq_data;
1609 if ((path->device->flags & CAM_DEV_IDENTIFY_DATA_VALID) != 0)
1610 ident_buf = &path->device->ident_data;
1611 if (path->device->protocol == PROTO_ATA) {
1612 path->device->protocol_version = ident_buf ?
1613 ata_version(ident_buf->version_major) : cpi.protocol_version;
1614 } else if (path->device->protocol == PROTO_SCSI) {
1615 path->device->protocol_version = inq_buf ?
1616 SID_ANSI_REV(inq_buf) : cpi.protocol_version;
1618 path->device->transport_version = ident_buf ?
1619 ata_version(ident_buf->version_major) : cpi.transport_version;
1621 /* Tell the controller what we think */
1622 xpt_setup_ccb(&cts.ccb_h, path, CAM_PRIORITY_NONE);
1623 cts.ccb_h.func_code = XPT_SET_TRAN_SETTINGS;
1624 cts.type = CTS_TYPE_CURRENT_SETTINGS;
1625 cts.transport = path->device->transport;
1626 cts.transport_version = path->device->transport_version;
1627 cts.protocol = path->device->protocol;
1628 cts.protocol_version = path->device->protocol_version;
1629 cts.proto_specific.valid = 0;
1631 if (path->device->transport == XPORT_ATA) {
1632 cts.xport_specific.ata.atapi =
1633 (ident_buf->config == ATA_PROTO_CFA) ? 0 :
1634 ((ident_buf->config & ATA_PROTO_MASK) == ATA_PROTO_ATAPI_16) ? 16 :
1635 ((ident_buf->config & ATA_PROTO_MASK) == ATA_PROTO_ATAPI_12) ? 12 : 0;
1636 cts.xport_specific.ata.valid = CTS_ATA_VALID_ATAPI;
1638 cts.xport_specific.sata.atapi =
1639 (ident_buf->config == ATA_PROTO_CFA) ? 0 :
1640 ((ident_buf->config & ATA_PROTO_MASK) == ATA_PROTO_ATAPI_16) ? 16 :
1641 ((ident_buf->config & ATA_PROTO_MASK) == ATA_PROTO_ATAPI_12) ? 12 : 0;
1642 cts.xport_specific.sata.valid = CTS_SATA_VALID_ATAPI;
1645 cts.xport_specific.valid = 0;
1646 xpt_action((union ccb *)&cts);
1650 ata_dev_advinfo(union ccb *start_ccb)
1652 struct cam_ed *device;
1653 struct ccb_dev_advinfo *cdai;
1656 start_ccb->ccb_h.status = CAM_REQ_INVALID;
1657 device = start_ccb->ccb_h.path->device;
1658 cdai = &start_ccb->cdai;
1659 switch(cdai->buftype) {
1660 case CDAI_TYPE_SCSI_DEVID:
1661 if (cdai->flags & CDAI_FLAG_STORE)
1663 cdai->provsiz = device->device_id_len;
1664 if (device->device_id_len == 0)
1666 amt = device->device_id_len;
1667 if (cdai->provsiz > cdai->bufsiz)
1669 memcpy(cdai->buf, device->device_id, amt);
1671 case CDAI_TYPE_SERIAL_NUM:
1672 if (cdai->flags & CDAI_FLAG_STORE)
1674 cdai->provsiz = device->serial_num_len;
1675 if (device->serial_num_len == 0)
1677 amt = device->serial_num_len;
1678 if (cdai->provsiz > cdai->bufsiz)
1680 memcpy(cdai->buf, device->serial_num, amt);
1682 case CDAI_TYPE_PHYS_PATH:
1683 if (cdai->flags & CDAI_FLAG_STORE) {
1684 if (device->physpath != NULL)
1685 free(device->physpath, M_CAMXPT);
1686 device->physpath_len = cdai->bufsiz;
1687 /* Clear existing buffer if zero length */
1688 if (cdai->bufsiz == 0)
1690 device->physpath = malloc(cdai->bufsiz, M_CAMXPT, M_NOWAIT);
1691 if (device->physpath == NULL) {
1692 start_ccb->ccb_h.status = CAM_REQ_ABORTED;
1695 memcpy(device->physpath, cdai->buf, cdai->bufsiz);
1697 cdai->provsiz = device->physpath_len;
1698 if (device->physpath_len == 0)
1700 amt = device->physpath_len;
1701 if (cdai->provsiz > cdai->bufsiz)
1703 memcpy(cdai->buf, device->physpath, amt);
1709 start_ccb->ccb_h.status = CAM_REQ_CMP;
1711 if (cdai->flags & CDAI_FLAG_STORE) {
1712 xpt_async(AC_ADVINFO_CHANGED, start_ccb->ccb_h.path,
1713 (void *)(uintptr_t)cdai->buftype);
1718 ata_action(union ccb *start_ccb)
1721 switch (start_ccb->ccb_h.func_code) {
1722 case XPT_SET_TRAN_SETTINGS:
1724 ata_set_transfer_settings(&start_ccb->cts,
1725 start_ccb->ccb_h.path,
1726 /*async_update*/FALSE);
1731 ata_scan_bus(start_ccb->ccb_h.path->periph, start_ccb);
1734 ata_scan_lun(start_ccb->ccb_h.path->periph,
1735 start_ccb->ccb_h.path, start_ccb->crcn.flags,
1738 case XPT_GET_TRAN_SETTINGS:
1740 ata_get_transfer_settings(&start_ccb->cts);
1745 struct cam_ed *device;
1748 device = start_ccb->ccb_h.path->device;
1749 if (device->protocol == PROTO_SCSI &&
1750 (device->flags & CAM_DEV_IDENTIFY_DATA_VALID)) {
1752 device->ident_data.config & ATA_PROTO_MASK;
1755 (device->ident_data.config == ATA_PROTO_CFA) ? 0 :
1756 (p == ATA_PROTO_ATAPI_16) ? 16 :
1757 (p == ATA_PROTO_ATAPI_12) ? 12 : 0;
1759 if (start_ccb->csio.cdb_len > maxlen) {
1760 start_ccb->ccb_h.status = CAM_REQ_INVALID;
1761 xpt_done(start_ccb);
1764 xpt_action_default(start_ccb);
1767 case XPT_DEV_ADVINFO:
1769 ata_dev_advinfo(start_ccb);
1773 xpt_action_default(start_ccb);
1779 ata_get_transfer_settings(struct ccb_trans_settings *cts)
1781 struct ccb_trans_settings_ata *ata;
1782 struct ccb_trans_settings_scsi *scsi;
1783 struct cam_ed *device;
1785 device = cts->ccb_h.path->device;
1786 xpt_action_default((union ccb *)cts);
1788 if (cts->protocol == PROTO_UNKNOWN ||
1789 cts->protocol == PROTO_UNSPECIFIED) {
1790 cts->protocol = device->protocol;
1791 cts->protocol_version = device->protocol_version;
1794 if (cts->protocol == PROTO_ATA) {
1795 ata = &cts->proto_specific.ata;
1796 if ((ata->valid & CTS_ATA_VALID_TQ) == 0) {
1797 ata->valid |= CTS_ATA_VALID_TQ;
1798 if (cts->type == CTS_TYPE_USER_SETTINGS ||
1799 (device->flags & CAM_DEV_TAG_AFTER_COUNT) != 0 ||
1800 (device->inq_flags & SID_CmdQue) != 0)
1801 ata->flags |= CTS_ATA_FLAGS_TAG_ENB;
1804 if (cts->protocol == PROTO_SCSI) {
1805 scsi = &cts->proto_specific.scsi;
1806 if ((scsi->valid & CTS_SCSI_VALID_TQ) == 0) {
1807 scsi->valid |= CTS_SCSI_VALID_TQ;
1808 if (cts->type == CTS_TYPE_USER_SETTINGS ||
1809 (device->flags & CAM_DEV_TAG_AFTER_COUNT) != 0 ||
1810 (device->inq_flags & SID_CmdQue) != 0)
1811 scsi->flags |= CTS_SCSI_FLAGS_TAG_ENB;
1815 if (cts->transport == XPORT_UNKNOWN ||
1816 cts->transport == XPORT_UNSPECIFIED) {
1817 cts->transport = device->transport;
1818 cts->transport_version = device->transport_version;
1823 ata_set_transfer_settings(struct ccb_trans_settings *cts, struct cam_path *path,
1826 struct ccb_pathinq cpi;
1827 struct ccb_trans_settings_ata *ata;
1828 struct ccb_trans_settings_scsi *scsi;
1829 struct ata_params *ident_data;
1830 struct scsi_inquiry_data *inq_data;
1831 struct cam_ed *device;
1833 if (path == NULL || (device = path->device) == NULL) {
1834 cts->ccb_h.status = CAM_PATH_INVALID;
1835 xpt_done((union ccb *)cts);
1839 if (cts->protocol == PROTO_UNKNOWN
1840 || cts->protocol == PROTO_UNSPECIFIED) {
1841 cts->protocol = device->protocol;
1842 cts->protocol_version = device->protocol_version;
1845 if (cts->protocol_version == PROTO_VERSION_UNKNOWN
1846 || cts->protocol_version == PROTO_VERSION_UNSPECIFIED)
1847 cts->protocol_version = device->protocol_version;
1849 if (cts->protocol != device->protocol) {
1850 xpt_print(path, "Uninitialized Protocol %x:%x?\n",
1851 cts->protocol, device->protocol);
1852 cts->protocol = device->protocol;
1855 if (cts->protocol_version > device->protocol_version) {
1857 xpt_print(path, "Down reving Protocol "
1858 "Version from %d to %d?\n", cts->protocol_version,
1859 device->protocol_version);
1861 cts->protocol_version = device->protocol_version;
1864 if (cts->transport == XPORT_UNKNOWN
1865 || cts->transport == XPORT_UNSPECIFIED) {
1866 cts->transport = device->transport;
1867 cts->transport_version = device->transport_version;
1870 if (cts->transport_version == XPORT_VERSION_UNKNOWN
1871 || cts->transport_version == XPORT_VERSION_UNSPECIFIED)
1872 cts->transport_version = device->transport_version;
1874 if (cts->transport != device->transport) {
1875 xpt_print(path, "Uninitialized Transport %x:%x?\n",
1876 cts->transport, device->transport);
1877 cts->transport = device->transport;
1880 if (cts->transport_version > device->transport_version) {
1882 xpt_print(path, "Down reving Transport "
1883 "Version from %d to %d?\n", cts->transport_version,
1884 device->transport_version);
1886 cts->transport_version = device->transport_version;
1889 ident_data = &device->ident_data;
1890 inq_data = &device->inq_data;
1891 if (cts->protocol == PROTO_ATA)
1892 ata = &cts->proto_specific.ata;
1895 if (cts->protocol == PROTO_SCSI)
1896 scsi = &cts->proto_specific.scsi;
1899 xpt_setup_ccb(&cpi.ccb_h, path, CAM_PRIORITY_NONE);
1900 cpi.ccb_h.func_code = XPT_PATH_INQ;
1901 xpt_action((union ccb *)&cpi);
1903 /* Sanity checking */
1904 if ((cpi.hba_inquiry & PI_TAG_ABLE) == 0
1905 || (ata && (ident_data->satacapabilities & ATA_SUPPORT_NCQ) == 0)
1906 || (scsi && (INQ_DATA_TQ_ENABLED(inq_data)) == 0)
1907 || (device->queue_flags & SCP_QUEUE_DQUE) != 0
1908 || (device->mintags == 0)) {
1910 * Can't tag on hardware that doesn't support tags,
1911 * doesn't have it enabled, or has broken tag support.
1914 ata->flags &= ~CTS_ATA_FLAGS_TAG_ENB;
1916 scsi->flags &= ~CTS_SCSI_FLAGS_TAG_ENB;
1919 /* Start/stop tags use. */
1920 if (cts->type == CTS_TYPE_CURRENT_SETTINGS &&
1921 ((ata && (ata->valid & CTS_ATA_VALID_TQ) != 0) ||
1922 (scsi && (scsi->valid & CTS_SCSI_VALID_TQ) != 0))) {
1925 nowt = ((device->flags & CAM_DEV_TAG_AFTER_COUNT) != 0 ||
1926 (device->inq_flags & SID_CmdQue) != 0);
1928 newt = (ata->flags & CTS_ATA_FLAGS_TAG_ENB) != 0;
1930 newt = (scsi->flags & CTS_SCSI_FLAGS_TAG_ENB) != 0;
1932 if (newt && !nowt) {
1934 * Delay change to use tags until after a
1935 * few commands have gone to this device so
1936 * the controller has time to perform transfer
1937 * negotiations without tagged messages getting
1940 device->tag_delay_count = CAM_TAG_DELAY_COUNT;
1941 device->flags |= CAM_DEV_TAG_AFTER_COUNT;
1942 } else if (nowt && !newt)
1943 xpt_stop_tags(path);
1946 if (async_update == FALSE)
1947 xpt_action_default((union ccb *)cts);
1951 * Handle any per-device event notifications that require action by the XPT.
1954 ata_dev_async(u_int32_t async_code, struct cam_eb *bus, struct cam_et *target,
1955 struct cam_ed *device, void *async_arg)
1958 struct cam_path newpath;
1961 * We only need to handle events for real devices.
1963 if (target->target_id == CAM_TARGET_WILDCARD
1964 || device->lun_id == CAM_LUN_WILDCARD)
1968 * We need our own path with wildcards expanded to
1969 * handle certain types of events.
1971 if ((async_code == AC_SENT_BDR)
1972 || (async_code == AC_BUS_RESET)
1973 || (async_code == AC_INQ_CHANGED))
1974 status = xpt_compile_path(&newpath, NULL,
1979 status = CAM_REQ_CMP_ERR;
1981 if (status == CAM_REQ_CMP) {
1982 if (async_code == AC_INQ_CHANGED) {
1984 * We've sent a start unit command, or
1985 * something similar to a device that
1986 * may have caused its inquiry data to
1987 * change. So we re-scan the device to
1988 * refresh the inquiry data for it.
1990 ata_scan_lun(newpath.periph, &newpath,
1991 CAM_EXPECT_INQ_CHANGE, NULL);
1993 /* We need to reinitialize device after reset. */
1994 ata_scan_lun(newpath.periph, &newpath,
1997 xpt_release_path(&newpath);
1998 } else if (async_code == AC_LOST_DEVICE &&
1999 (device->flags & CAM_DEV_UNCONFIGURED) == 0) {
2000 device->flags |= CAM_DEV_UNCONFIGURED;
2001 xpt_release_device(device);
2002 } else if (async_code == AC_TRANSFER_NEG) {
2003 struct ccb_trans_settings *settings;
2004 struct cam_path path;
2006 settings = (struct ccb_trans_settings *)async_arg;
2007 xpt_compile_path(&path, NULL, bus->path_id, target->target_id,
2009 ata_set_transfer_settings(settings, &path,
2010 /*async_update*/TRUE);
2011 xpt_release_path(&path);
2016 ata_announce_periph(struct cam_periph *periph)
2018 struct ccb_pathinq cpi;
2019 struct ccb_trans_settings cts;
2020 struct cam_path *path = periph->path;
2024 cam_periph_assert(periph, MA_OWNED);
2026 xpt_setup_ccb(&cts.ccb_h, path, CAM_PRIORITY_NORMAL);
2027 cts.ccb_h.func_code = XPT_GET_TRAN_SETTINGS;
2028 cts.type = CTS_TYPE_CURRENT_SETTINGS;
2029 xpt_action((union ccb*)&cts);
2030 if ((cts.ccb_h.status & CAM_STATUS_MASK) != CAM_REQ_CMP)
2032 /* Ask the SIM for its base transfer speed */
2033 xpt_setup_ccb(&cpi.ccb_h, path, CAM_PRIORITY_NORMAL);
2034 cpi.ccb_h.func_code = XPT_PATH_INQ;
2035 xpt_action((union ccb *)&cpi);
2036 /* Report connection speed */
2037 speed = cpi.base_transfer_speed;
2038 if (cts.ccb_h.status == CAM_REQ_CMP && cts.transport == XPORT_ATA) {
2039 struct ccb_trans_settings_pata *pata =
2040 &cts.xport_specific.ata;
2042 if (pata->valid & CTS_ATA_VALID_MODE)
2043 speed = ata_mode2speed(pata->mode);
2045 if (cts.ccb_h.status == CAM_REQ_CMP && cts.transport == XPORT_SATA) {
2046 struct ccb_trans_settings_sata *sata =
2047 &cts.xport_specific.sata;
2049 if (sata->valid & CTS_SATA_VALID_REVISION)
2050 speed = ata_revision2speed(sata->revision);
2054 printf("%s%d: %d.%03dMB/s transfers",
2055 periph->periph_name, periph->unit_number,
2058 printf("%s%d: %dKB/s transfers", periph->periph_name,
2059 periph->unit_number, speed);
2060 /* Report additional information about connection */
2061 if (cts.ccb_h.status == CAM_REQ_CMP && cts.transport == XPORT_ATA) {
2062 struct ccb_trans_settings_pata *pata =
2063 &cts.xport_specific.ata;
2066 if (pata->valid & CTS_ATA_VALID_MODE)
2067 printf("%s, ", ata_mode2string(pata->mode));
2068 if ((pata->valid & CTS_ATA_VALID_ATAPI) && pata->atapi != 0)
2069 printf("ATAPI %dbytes, ", pata->atapi);
2070 if (pata->valid & CTS_ATA_VALID_BYTECOUNT)
2071 printf("PIO %dbytes", pata->bytecount);
2074 if (cts.ccb_h.status == CAM_REQ_CMP && cts.transport == XPORT_SATA) {
2075 struct ccb_trans_settings_sata *sata =
2076 &cts.xport_specific.sata;
2079 if (sata->valid & CTS_SATA_VALID_REVISION)
2080 printf("SATA %d.x, ", sata->revision);
2083 if (sata->valid & CTS_SATA_VALID_MODE)
2084 printf("%s, ", ata_mode2string(sata->mode));
2085 if ((sata->valid & CTS_ATA_VALID_ATAPI) && sata->atapi != 0)
2086 printf("ATAPI %dbytes, ", sata->atapi);
2087 if (sata->valid & CTS_SATA_VALID_BYTECOUNT)
2088 printf("PIO %dbytes", sata->bytecount);