2 * Copyright (c) 2009 Alexander Motin <mav@FreeBSD.org>
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer,
10 * without modification, immediately at the beginning of the file.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
15 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
16 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
17 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
18 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
19 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
20 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
21 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
22 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
24 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 #include <sys/cdefs.h>
28 __FBSDID("$FreeBSD$");
30 #include <sys/param.h>
32 #include <sys/endian.h>
33 #include <sys/systm.h>
34 #include <sys/types.h>
35 #include <sys/malloc.h>
36 #include <sys/kernel.h>
39 #include <sys/fcntl.h>
40 #include <sys/interrupt.h>
43 #include <sys/eventhandler.h>
45 #include <sys/mutex.h>
46 #include <sys/sysctl.h>
49 #include <cam/cam_ccb.h>
50 #include <cam/cam_queue.h>
51 #include <cam/cam_periph.h>
52 #include <cam/cam_sim.h>
53 #include <cam/cam_xpt.h>
54 #include <cam/cam_xpt_sim.h>
55 #include <cam/cam_xpt_periph.h>
56 #include <cam/cam_xpt_internal.h>
57 #include <cam/cam_debug.h>
59 #include <cam/scsi/scsi_all.h>
60 #include <cam/scsi/scsi_message.h>
61 #include <cam/ata/ata_all.h>
62 #include <machine/stdarg.h> /* for xpt_print below */
65 struct ata_quirk_entry {
66 struct scsi_inquiry_pattern inq_pat;
68 #define CAM_QUIRK_MAXTAGS 0x01
73 static periph_init_t probe_periph_init;
75 static struct periph_driver probe_driver =
77 probe_periph_init, "aprobe",
78 TAILQ_HEAD_INITIALIZER(probe_driver.units), /* generation */ 0,
82 PERIPHDRIVER_DECLARE(aprobe, probe_driver);
104 static char *probe_action_text[] = {
115 "PROBE_FULL_INQUIRY",
118 "PROBE_IDENTIFY_SES",
119 "PROBE_IDENTIFY_SAFTE",
124 #define PROBE_SET_ACTION(softc, newaction) \
127 text = probe_action_text; \
128 CAM_DEBUG((softc)->periph->path, CAM_DEBUG_PROBE, \
129 ("Probe %s to %s\n", text[(softc)->action], \
130 text[(newaction)])); \
131 (softc)->action = (newaction); \
135 PROBE_NO_ANNOUNCE = 0x04
139 TAILQ_HEAD(, ccb_hdr) request_ccbs;
140 struct ata_params ident_data;
149 struct cam_periph *periph;
152 static struct ata_quirk_entry ata_quirk_table[] =
155 /* Default tagged queuing parameters for all devices */
157 T_ANY, SIP_MEDIA_REMOVABLE|SIP_MEDIA_FIXED,
158 /*vendor*/"*", /*product*/"*", /*revision*/"*"
160 /*quirks*/0, /*mintags*/0, /*maxtags*/0
164 static cam_status proberegister(struct cam_periph *periph,
166 static void probeschedule(struct cam_periph *probe_periph);
167 static void probestart(struct cam_periph *periph, union ccb *start_ccb);
168 static void proberequestdefaultnegotiation(struct cam_periph *periph);
169 static void probedone(struct cam_periph *periph, union ccb *done_ccb);
170 static void probecleanup(struct cam_periph *periph);
171 static void ata_find_quirk(struct cam_ed *device);
172 static void ata_scan_bus(struct cam_periph *periph, union ccb *ccb);
173 static void ata_scan_lun(struct cam_periph *periph,
174 struct cam_path *path, cam_flags flags,
176 static void xptscandone(struct cam_periph *periph, union ccb *done_ccb);
177 static struct cam_ed *
178 ata_alloc_device(struct cam_eb *bus, struct cam_et *target,
180 static void ata_device_transport(struct cam_path *path);
181 static void ata_get_transfer_settings(struct ccb_trans_settings *cts);
182 static void ata_set_transfer_settings(struct ccb_trans_settings *cts,
183 struct cam_path *path,
185 static void ata_dev_async(u_int32_t async_code,
187 struct cam_et *target,
188 struct cam_ed *device,
190 static void ata_action(union ccb *start_ccb);
191 static void ata_announce_periph(struct cam_periph *periph);
192 static void ata_announce_periph_sbuf(struct cam_periph *periph, struct sbuf *sb);
193 static void ata_proto_announce(struct cam_ed *device);
194 static void ata_proto_announce_sbuf(struct cam_ed *device, struct sbuf *sb);
195 static void ata_proto_denounce(struct cam_ed *device);
196 static void ata_proto_denounce_sbuf(struct cam_ed *device, struct sbuf *sb);
197 static void ata_proto_debug_out(union ccb *ccb);
198 static void semb_proto_announce(struct cam_ed *device);
199 static void semb_proto_announce_sbuf(struct cam_ed *device, struct sbuf *sb);
200 static void semb_proto_denounce(struct cam_ed *device);
201 static void semb_proto_denounce_sbuf(struct cam_ed *device, struct sbuf *sb);
203 static int ata_dma = 1;
204 static int atapi_dma = 1;
206 TUNABLE_INT("hw.ata.ata_dma", &ata_dma);
207 TUNABLE_INT("hw.ata.atapi_dma", &atapi_dma);
209 static struct xpt_xport_ops ata_xport_ops = {
210 .alloc_device = ata_alloc_device,
211 .action = ata_action,
212 .async = ata_dev_async,
213 .announce = ata_announce_periph,
214 .announce_sbuf = ata_announce_periph_sbuf,
216 #define ATA_XPT_XPORT(x, X) \
217 static struct xpt_xport ata_xport_ ## x = { \
218 .xport = XPORT_ ## X, \
220 .ops = &ata_xport_ops, \
222 CAM_XPT_XPORT(ata_xport_ ## x);
224 ATA_XPT_XPORT(ata, ATA);
225 ATA_XPT_XPORT(sata, SATA);
227 #undef ATA_XPORT_XPORT
229 static struct xpt_proto_ops ata_proto_ops_ata = {
230 .announce = ata_proto_announce,
231 .announce_sbuf = ata_proto_announce_sbuf,
232 .denounce = ata_proto_denounce,
233 .denounce_sbuf = ata_proto_denounce_sbuf,
234 .debug_out = ata_proto_debug_out,
236 static struct xpt_proto ata_proto_ata = {
239 .ops = &ata_proto_ops_ata,
242 static struct xpt_proto_ops ata_proto_ops_satapm = {
243 .announce = ata_proto_announce,
244 .announce_sbuf = ata_proto_announce_sbuf,
245 .denounce = ata_proto_denounce,
246 .denounce_sbuf = ata_proto_denounce_sbuf,
247 .debug_out = ata_proto_debug_out,
249 static struct xpt_proto ata_proto_satapm = {
250 .proto = PROTO_SATAPM,
252 .ops = &ata_proto_ops_satapm,
255 static struct xpt_proto_ops ata_proto_ops_semb = {
256 .announce = semb_proto_announce,
257 .announce_sbuf = semb_proto_announce_sbuf,
258 .denounce = semb_proto_denounce,
259 .denounce_sbuf = semb_proto_denounce_sbuf,
260 .debug_out = ata_proto_debug_out,
262 static struct xpt_proto ata_proto_semb = {
265 .ops = &ata_proto_ops_semb,
268 CAM_XPT_PROTO(ata_proto_ata);
269 CAM_XPT_PROTO(ata_proto_satapm);
270 CAM_XPT_PROTO(ata_proto_semb);
278 proberegister(struct cam_periph *periph, void *arg)
280 union ccb *request_ccb; /* CCB representing the probe request */
284 request_ccb = (union ccb *)arg;
285 if (request_ccb == NULL) {
286 printf("proberegister: no probe CCB, "
287 "can't register device\n");
288 return(CAM_REQ_CMP_ERR);
291 softc = (probe_softc *)malloc(sizeof(*softc), M_CAMXPT, M_ZERO | M_NOWAIT);
294 printf("proberegister: Unable to probe new device. "
295 "Unable to allocate softc\n");
296 return(CAM_REQ_CMP_ERR);
298 TAILQ_INIT(&softc->request_ccbs);
299 TAILQ_INSERT_TAIL(&softc->request_ccbs, &request_ccb->ccb_h,
302 periph->softc = softc;
303 softc->periph = periph;
304 softc->action = PROBE_INVALID;
305 status = cam_periph_acquire(periph);
306 if (status != CAM_REQ_CMP) {
309 CAM_DEBUG(periph->path, CAM_DEBUG_PROBE, ("Probe started\n"));
310 ata_device_transport(periph->path);
311 probeschedule(periph);
316 probeschedule(struct cam_periph *periph)
321 softc = (probe_softc *)periph->softc;
322 ccb = (union ccb *)TAILQ_FIRST(&softc->request_ccbs);
324 if ((periph->path->device->flags & CAM_DEV_UNCONFIGURED) ||
325 periph->path->device->protocol == PROTO_SATAPM ||
326 periph->path->device->protocol == PROTO_SEMB)
327 PROBE_SET_ACTION(softc, PROBE_RESET);
329 PROBE_SET_ACTION(softc, PROBE_IDENTIFY);
331 if (ccb->crcn.flags & CAM_EXPECT_INQ_CHANGE)
332 softc->flags |= PROBE_NO_ANNOUNCE;
334 softc->flags &= ~PROBE_NO_ANNOUNCE;
336 xpt_schedule(periph, CAM_PRIORITY_XPT);
340 probestart(struct cam_periph *periph, union ccb *start_ccb)
342 struct ccb_trans_settings cts;
343 struct ccb_ataio *ataio;
344 struct ccb_scsiio *csio;
346 struct cam_path *path;
347 struct ata_params *ident_buf;
349 CAM_DEBUG(start_ccb->ccb_h.path, CAM_DEBUG_TRACE, ("probestart\n"));
351 softc = (probe_softc *)periph->softc;
352 path = start_ccb->ccb_h.path;
353 ataio = &start_ccb->ataio;
354 csio = &start_ccb->csio;
355 ident_buf = &periph->path->device->ident_data;
357 if (softc->restart) {
359 if ((path->device->flags & CAM_DEV_UNCONFIGURED) ||
360 path->device->protocol == PROTO_SATAPM ||
361 path->device->protocol == PROTO_SEMB)
362 softc->action = PROBE_RESET;
364 softc->action = PROBE_IDENTIFY;
366 switch (softc->action) {
368 cam_fill_ataio(ataio,
371 /*flags*/CAM_DIR_NONE,
376 ata_reset_cmd(ataio);
379 cam_fill_ataio(ataio,
384 /*data_ptr*/(u_int8_t *)&softc->ident_data,
385 /*dxfer_len*/sizeof(softc->ident_data),
387 if (periph->path->device->protocol == PROTO_ATA)
388 ata_28bit_cmd(ataio, ATA_ATA_IDENTIFY, 0, 0, 0);
390 ata_28bit_cmd(ataio, ATA_ATAPI_IDENTIFY, 0, 0, 0);
394 xpt_print(path, "Spinning up device\n");
395 cam_fill_ataio(ataio,
398 /*flags*/CAM_DIR_NONE | CAM_HIGH_POWER,
403 ata_28bit_cmd(ataio, ATA_SETFEATURES, ATA_SF_PUIS_SPINUP, 0, 0);
410 /* Fetch user modes from SIM. */
411 bzero(&cts, sizeof(cts));
412 xpt_setup_ccb(&cts.ccb_h, path, CAM_PRIORITY_NONE);
413 cts.ccb_h.func_code = XPT_GET_TRAN_SETTINGS;
414 cts.type = CTS_TYPE_USER_SETTINGS;
415 xpt_action((union ccb *)&cts);
416 if (path->device->transport == XPORT_ATA) {
417 if (cts.xport_specific.ata.valid & CTS_ATA_VALID_MODE)
418 mode = cts.xport_specific.ata.mode;
420 if (cts.xport_specific.sata.valid & CTS_SATA_VALID_MODE)
421 mode = cts.xport_specific.sata.mode;
423 if (periph->path->device->protocol == PROTO_ATA) {
424 if (ata_dma == 0 && (mode == 0 || mode > ATA_PIO_MAX))
427 if (atapi_dma == 0 && (mode == 0 || mode > ATA_PIO_MAX))
431 /* Honor device capabilities. */
432 wantmode = mode = ata_max_mode(ident_buf, mode);
433 /* Report modes to SIM. */
434 bzero(&cts, sizeof(cts));
435 xpt_setup_ccb(&cts.ccb_h, path, CAM_PRIORITY_NONE);
436 cts.ccb_h.func_code = XPT_SET_TRAN_SETTINGS;
437 cts.type = CTS_TYPE_CURRENT_SETTINGS;
438 if (path->device->transport == XPORT_ATA) {
439 cts.xport_specific.ata.mode = mode;
440 cts.xport_specific.ata.valid = CTS_ATA_VALID_MODE;
442 cts.xport_specific.sata.mode = mode;
443 cts.xport_specific.sata.valid = CTS_SATA_VALID_MODE;
445 xpt_action((union ccb *)&cts);
446 /* Fetch current modes from SIM. */
447 bzero(&cts, sizeof(cts));
448 xpt_setup_ccb(&cts.ccb_h, path, CAM_PRIORITY_NONE);
449 cts.ccb_h.func_code = XPT_GET_TRAN_SETTINGS;
450 cts.type = CTS_TYPE_CURRENT_SETTINGS;
451 xpt_action((union ccb *)&cts);
452 if (path->device->transport == XPORT_ATA) {
453 if (cts.xport_specific.ata.valid & CTS_ATA_VALID_MODE)
454 mode = cts.xport_specific.ata.mode;
456 if (cts.xport_specific.ata.valid & CTS_SATA_VALID_MODE)
457 mode = cts.xport_specific.sata.mode;
459 /* If SIM disagree - renegotiate. */
460 if (mode != wantmode)
462 /* Remember what transport thinks about DMA. */
464 path->device->inq_flags &= ~SID_DMA;
466 path->device->inq_flags |= SID_DMA;
467 xpt_async(AC_GETDEV_CHANGED, path, NULL);
468 cam_fill_ataio(ataio,
471 /*flags*/CAM_DIR_NONE,
476 ata_28bit_cmd(ataio, ATA_SETFEATURES, ATA_SF_SETXFER, 0, mode);
480 cam_fill_ataio(ataio,
488 ata_28bit_cmd(ataio, ATA_SETFEATURES,
489 (softc->caps & CTS_SATA_CAPS_H_PMREQ) ? 0x10 : 0x90,
493 cam_fill_ataio(ataio,
501 ata_28bit_cmd(ataio, ATA_SETFEATURES,
502 (softc->caps & CTS_SATA_CAPS_H_APST) ? 0x10 : 0x90,
506 cam_fill_ataio(ataio,
514 ata_28bit_cmd(ataio, ATA_SETFEATURES,
515 (softc->caps & CTS_SATA_CAPS_H_DMAAA) ? 0x10 : 0x90,
519 /* Remember what transport thinks about AEN. */
520 if (softc->caps & CTS_SATA_CAPS_H_AN)
521 path->device->inq_flags |= SID_AEN;
523 path->device->inq_flags &= ~SID_AEN;
524 xpt_async(AC_GETDEV_CHANGED, path, NULL);
525 cam_fill_ataio(ataio,
533 ata_28bit_cmd(ataio, ATA_SETFEATURES,
534 (softc->caps & CTS_SATA_CAPS_H_AN) ? 0x10 : 0x90,
537 case PROBE_SET_MULTI:
539 u_int sectors, bytecount;
541 bytecount = 8192; /* SATA maximum */
542 /* Fetch user bytecount from SIM. */
543 bzero(&cts, sizeof(cts));
544 xpt_setup_ccb(&cts.ccb_h, path, CAM_PRIORITY_NONE);
545 cts.ccb_h.func_code = XPT_GET_TRAN_SETTINGS;
546 cts.type = CTS_TYPE_USER_SETTINGS;
547 xpt_action((union ccb *)&cts);
548 if (path->device->transport == XPORT_ATA) {
549 if (cts.xport_specific.ata.valid & CTS_ATA_VALID_BYTECOUNT)
550 bytecount = cts.xport_specific.ata.bytecount;
552 if (cts.xport_specific.sata.valid & CTS_SATA_VALID_BYTECOUNT)
553 bytecount = cts.xport_specific.sata.bytecount;
555 /* Honor device capabilities. */
556 sectors = max(1, min(ident_buf->sectors_intr & 0xff,
557 bytecount / ata_logical_sector_size(ident_buf)));
558 /* Report bytecount to SIM. */
559 bzero(&cts, sizeof(cts));
560 xpt_setup_ccb(&cts.ccb_h, path, CAM_PRIORITY_NONE);
561 cts.ccb_h.func_code = XPT_SET_TRAN_SETTINGS;
562 cts.type = CTS_TYPE_CURRENT_SETTINGS;
563 if (path->device->transport == XPORT_ATA) {
564 cts.xport_specific.ata.bytecount = sectors *
565 ata_logical_sector_size(ident_buf);
566 cts.xport_specific.ata.valid = CTS_ATA_VALID_BYTECOUNT;
568 cts.xport_specific.sata.bytecount = sectors *
569 ata_logical_sector_size(ident_buf);
570 cts.xport_specific.sata.valid = CTS_SATA_VALID_BYTECOUNT;
572 xpt_action((union ccb *)&cts);
573 /* Fetch current bytecount from SIM. */
574 bzero(&cts, sizeof(cts));
575 xpt_setup_ccb(&cts.ccb_h, path, CAM_PRIORITY_NONE);
576 cts.ccb_h.func_code = XPT_GET_TRAN_SETTINGS;
577 cts.type = CTS_TYPE_CURRENT_SETTINGS;
578 xpt_action((union ccb *)&cts);
579 if (path->device->transport == XPORT_ATA) {
580 if (cts.xport_specific.ata.valid & CTS_ATA_VALID_BYTECOUNT)
581 bytecount = cts.xport_specific.ata.bytecount;
583 if (cts.xport_specific.sata.valid & CTS_SATA_VALID_BYTECOUNT)
584 bytecount = cts.xport_specific.sata.bytecount;
586 sectors = bytecount / ata_logical_sector_size(ident_buf);
588 cam_fill_ataio(ataio,
596 ata_28bit_cmd(ataio, ATA_SET_MULTI, 0, 0, sectors);
603 bytecount = 8192; /* SATA maximum */
604 /* Fetch user bytecount from SIM. */
605 bzero(&cts, sizeof(cts));
606 xpt_setup_ccb(&cts.ccb_h, path, CAM_PRIORITY_NONE);
607 cts.ccb_h.func_code = XPT_GET_TRAN_SETTINGS;
608 cts.type = CTS_TYPE_USER_SETTINGS;
609 xpt_action((union ccb *)&cts);
610 if (path->device->transport == XPORT_ATA) {
611 if (cts.xport_specific.ata.valid & CTS_ATA_VALID_BYTECOUNT)
612 bytecount = cts.xport_specific.ata.bytecount;
614 if (cts.xport_specific.sata.valid & CTS_SATA_VALID_BYTECOUNT)
615 bytecount = cts.xport_specific.sata.bytecount;
617 /* Honor device capabilities. */
619 bytecount = max(2, min(65534, bytecount));
620 if (ident_buf->satacapabilities != 0x0000 &&
621 ident_buf->satacapabilities != 0xffff) {
622 bytecount = min(8192, bytecount);
624 /* Report bytecount to SIM. */
625 bzero(&cts, sizeof(cts));
626 xpt_setup_ccb(&cts.ccb_h, path, CAM_PRIORITY_NONE);
627 cts.ccb_h.func_code = XPT_SET_TRAN_SETTINGS;
628 cts.type = CTS_TYPE_CURRENT_SETTINGS;
629 if (path->device->transport == XPORT_ATA) {
630 cts.xport_specific.ata.bytecount = bytecount;
631 cts.xport_specific.ata.valid = CTS_ATA_VALID_BYTECOUNT;
633 cts.xport_specific.sata.bytecount = bytecount;
634 cts.xport_specific.sata.valid = CTS_SATA_VALID_BYTECOUNT;
636 xpt_action((union ccb *)&cts);
639 case PROBE_FULL_INQUIRY:
642 struct scsi_inquiry_data *inq_buf =
643 &periph->path->device->inq_data;
645 if (softc->action == PROBE_INQUIRY)
646 inquiry_len = SHORT_INQUIRY_LENGTH;
648 inquiry_len = SID_ADDITIONAL_LENGTH(inq_buf);
650 * Some parallel SCSI devices fail to send an
651 * ignore wide residue message when dealing with
652 * odd length inquiry requests. Round up to be
655 inquiry_len = roundup2(inquiry_len, 2);
665 /*timeout*/60 * 1000);
669 cam_fill_ataio(ataio,
672 /*flags*/CAM_DIR_NONE,
677 ata_pm_read_cmd(ataio, 0, 15);
680 cam_fill_ataio(ataio,
683 /*flags*/CAM_DIR_NONE,
688 ata_pm_read_cmd(ataio, 1, 15);
690 case PROBE_IDENTIFY_SES:
691 cam_fill_ataio(ataio,
696 /*data_ptr*/(u_int8_t *)&softc->ident_data,
697 /*dxfer_len*/sizeof(softc->ident_data),
699 ata_28bit_cmd(ataio, ATA_SEP_ATTN, 0xEC, 0x02,
700 sizeof(softc->ident_data) / 4);
702 case PROBE_IDENTIFY_SAFTE:
703 cam_fill_ataio(ataio,
708 /*data_ptr*/(u_int8_t *)&softc->ident_data,
709 /*dxfer_len*/sizeof(softc->ident_data),
711 ata_28bit_cmd(ataio, ATA_SEP_ATTN, 0xEC, 0x00,
712 sizeof(softc->ident_data) / 4);
715 panic("probestart: invalid action state 0x%x\n", softc->action);
717 start_ccb->ccb_h.flags |= CAM_DEV_QFREEZE;
718 xpt_action(start_ccb);
722 proberequestdefaultnegotiation(struct cam_periph *periph)
724 struct ccb_trans_settings cts;
726 xpt_setup_ccb(&cts.ccb_h, periph->path, CAM_PRIORITY_NONE);
727 cts.ccb_h.func_code = XPT_GET_TRAN_SETTINGS;
728 cts.type = CTS_TYPE_USER_SETTINGS;
729 xpt_action((union ccb *)&cts);
730 if ((cts.ccb_h.status & CAM_STATUS_MASK) != CAM_REQ_CMP)
732 cts.xport_specific.valid = 0;
733 cts.ccb_h.func_code = XPT_SET_TRAN_SETTINGS;
734 cts.type = CTS_TYPE_CURRENT_SETTINGS;
735 xpt_action((union ccb *)&cts);
739 probedone(struct cam_periph *periph, union ccb *done_ccb)
741 struct ccb_trans_settings cts;
742 struct ata_params *ident_buf;
743 struct scsi_inquiry_data *inq_buf;
745 struct cam_path *path;
749 int changed = 1, found = 1;
750 static const uint8_t fake_device_id_hdr[8] =
751 {0, SVPD_DEVICE_ID, 0, 12,
752 SVPD_ID_CODESET_BINARY, SVPD_ID_TYPE_NAA, 0, 8};
754 CAM_DEBUG(done_ccb->ccb_h.path, CAM_DEBUG_TRACE, ("probedone\n"));
756 softc = (probe_softc *)periph->softc;
757 path = done_ccb->ccb_h.path;
758 priority = done_ccb->ccb_h.pinfo.priority;
759 ident_buf = &path->device->ident_data;
760 inq_buf = &path->device->inq_data;
762 if ((done_ccb->ccb_h.status & CAM_STATUS_MASK) != CAM_REQ_CMP) {
763 if (cam_periph_error(done_ccb,
764 0, softc->restart ? (SF_NO_RECOVERY | SF_NO_RETRY) : 0,
767 /* Drop freeze taken due to CAM_DEV_QFREEZE flag set. */
768 cam_release_devq(path, 0, 0, 0, FALSE);
771 if ((done_ccb->ccb_h.status & CAM_DEV_QFRZN) != 0) {
772 /* Don't wedge the queue */
773 xpt_release_devq(path, /*count*/1, /*run_queue*/TRUE);
775 status = done_ccb->ccb_h.status & CAM_STATUS_MASK;
776 if (softc->restart) {
778 if ((done_ccb->ccb_h.status & CAM_STATUS_MASK) ==
781 if (softc->faults < 10)
786 /* Old PIO2 devices may not support mode setting. */
787 } else if (softc->action == PROBE_SETMODE &&
788 status == CAM_ATA_STATUS_ERROR &&
789 ata_max_pmode(ident_buf) <= ATA_PIO2 &&
790 (ident_buf->capabilities1 & ATA_SUPPORT_IORDY) == 0) {
794 * Some old WD SATA disks report supported and enabled
795 * device-initiated interface power management, but return
796 * ABORT on attempt to disable it.
798 } else if (softc->action == PROBE_SETPM &&
799 status == CAM_ATA_STATUS_ERROR) {
803 * Some old WD SATA disks have broken SPINUP handling.
804 * If we really fail to spin up the disk, then there will be
805 * some media access errors later on, but at least we will
806 * have a device to interact with for recovery attempts.
808 } else if (softc->action == PROBE_SPINUP &&
809 status == CAM_ATA_STATUS_ERROR) {
813 * Some HP SATA disks report supported DMA Auto-Activation,
814 * but return ABORT on attempt to enable it.
816 } else if (softc->action == PROBE_SETDMAAA &&
817 status == CAM_ATA_STATUS_ERROR) {
821 * SES and SAF-TE SEPs have different IDENTIFY commands,
822 * but SATA specification doesn't tell how to identify them.
823 * Until better way found, just try another if first fail.
825 } else if (softc->action == PROBE_IDENTIFY_SES &&
826 status == CAM_ATA_STATUS_ERROR) {
827 PROBE_SET_ACTION(softc, PROBE_IDENTIFY_SAFTE);
828 xpt_release_ccb(done_ccb);
829 xpt_schedule(periph, priority);
834 * If we get to this point, we got an error status back
835 * from the inquiry and the error status doesn't require
836 * automatically retrying the command. Therefore, the
837 * inquiry failed. If we had inquiry information before
838 * for this device, but this latest inquiry command failed,
839 * the device has probably gone away. If this device isn't
840 * already marked unconfigured, notify the peripheral
841 * drivers that this device is no more.
843 device_fail: if ((path->device->flags & CAM_DEV_UNCONFIGURED) == 0)
844 xpt_async(AC_LOST_DEVICE, path, NULL);
845 PROBE_SET_ACTION(softc, PROBE_INVALID);
852 switch (softc->action) {
855 int sign = (done_ccb->ataio.res.lba_high << 8) +
856 done_ccb->ataio.res.lba_mid;
857 CAM_DEBUG(path, CAM_DEBUG_PROBE,
858 ("SIGNATURE: %04x\n", sign));
859 if (sign == 0x0000 &&
860 done_ccb->ccb_h.target_id != 15) {
861 path->device->protocol = PROTO_ATA;
862 PROBE_SET_ACTION(softc, PROBE_IDENTIFY);
863 } else if (sign == 0x9669 &&
864 done_ccb->ccb_h.target_id == 15) {
865 /* Report SIM that PM is present. */
866 bzero(&cts, sizeof(cts));
867 xpt_setup_ccb(&cts.ccb_h, path, CAM_PRIORITY_NONE);
868 cts.ccb_h.func_code = XPT_SET_TRAN_SETTINGS;
869 cts.type = CTS_TYPE_CURRENT_SETTINGS;
870 cts.xport_specific.sata.pm_present = 1;
871 cts.xport_specific.sata.valid = CTS_SATA_VALID_PM;
872 xpt_action((union ccb *)&cts);
873 path->device->protocol = PROTO_SATAPM;
874 PROBE_SET_ACTION(softc, PROBE_PM_PID);
875 } else if (sign == 0xc33c &&
876 done_ccb->ccb_h.target_id != 15) {
877 path->device->protocol = PROTO_SEMB;
878 PROBE_SET_ACTION(softc, PROBE_IDENTIFY_SES);
879 } else if (sign == 0xeb14 &&
880 done_ccb->ccb_h.target_id != 15) {
881 path->device->protocol = PROTO_SCSI;
882 PROBE_SET_ACTION(softc, PROBE_IDENTIFY);
884 if (done_ccb->ccb_h.target_id != 15) {
886 "Unexpected signature 0x%04x\n", sign);
890 xpt_release_ccb(done_ccb);
891 xpt_schedule(periph, priority);
896 struct ccb_pathinq cpi;
900 ident_buf = &softc->ident_data;
901 for (ptr = (int16_t *)ident_buf;
902 ptr < (int16_t *)ident_buf + sizeof(struct ata_params)/2; ptr++) {
903 *ptr = le16toh(*ptr);
907 * Allow others to veto this ATA disk attachment. This
908 * is mainly used by VMs, whose disk controllers may
909 * share the disks with the simulated ATA controllers.
911 EVENTHANDLER_INVOKE(ada_probe_veto, path, ident_buf, &veto);
916 if (strncmp(ident_buf->model, "FX", 2) &&
917 strncmp(ident_buf->model, "NEC", 3) &&
918 strncmp(ident_buf->model, "Pioneer", 7) &&
919 strncmp(ident_buf->model, "SHARP", 5)) {
920 ata_bswap(ident_buf->model, sizeof(ident_buf->model));
921 ata_bswap(ident_buf->revision, sizeof(ident_buf->revision));
922 ata_bswap(ident_buf->serial, sizeof(ident_buf->serial));
924 ata_btrim(ident_buf->model, sizeof(ident_buf->model));
925 ata_bpack(ident_buf->model, ident_buf->model, sizeof(ident_buf->model));
926 ata_btrim(ident_buf->revision, sizeof(ident_buf->revision));
927 ata_bpack(ident_buf->revision, ident_buf->revision, sizeof(ident_buf->revision));
928 ata_btrim(ident_buf->serial, sizeof(ident_buf->serial));
929 ata_bpack(ident_buf->serial, ident_buf->serial, sizeof(ident_buf->serial));
930 /* Device may need spin-up before IDENTIFY become valid. */
931 if ((ident_buf->specconf == 0x37c8 ||
932 ident_buf->specconf == 0x738c) &&
933 ((ident_buf->config & ATA_RESP_INCOMPLETE) ||
934 softc->spinup == 0)) {
935 PROBE_SET_ACTION(softc, PROBE_SPINUP);
936 xpt_release_ccb(done_ccb);
937 xpt_schedule(periph, priority);
940 ident_buf = &path->device->ident_data;
941 if ((periph->path->device->flags & CAM_DEV_UNCONFIGURED) == 0) {
942 /* Check that it is the same device. */
943 if (bcmp(softc->ident_data.model, ident_buf->model,
944 sizeof(ident_buf->model)) ||
945 bcmp(softc->ident_data.revision, ident_buf->revision,
946 sizeof(ident_buf->revision)) ||
947 bcmp(softc->ident_data.serial, ident_buf->serial,
948 sizeof(ident_buf->serial))) {
949 /* Device changed. */
950 xpt_async(AC_LOST_DEVICE, path, NULL);
952 bcopy(&softc->ident_data, ident_buf, sizeof(struct ata_params));
957 bcopy(&softc->ident_data, ident_buf, sizeof(struct ata_params));
958 /* Clean up from previous instance of this device */
959 if (path->device->serial_num != NULL) {
960 free(path->device->serial_num, M_CAMXPT);
961 path->device->serial_num = NULL;
962 path->device->serial_num_len = 0;
964 if (path->device->device_id != NULL) {
965 free(path->device->device_id, M_CAMXPT);
966 path->device->device_id = NULL;
967 path->device->device_id_len = 0;
969 path->device->serial_num =
970 (u_int8_t *)malloc((sizeof(ident_buf->serial) + 1),
972 if (path->device->serial_num != NULL) {
973 bcopy(ident_buf->serial,
974 path->device->serial_num,
975 sizeof(ident_buf->serial));
976 path->device->serial_num[sizeof(ident_buf->serial)]
978 path->device->serial_num_len =
979 strlen(path->device->serial_num);
981 if (ident_buf->enabled.extension &
982 ATA_SUPPORT_64BITWWN) {
983 path->device->device_id =
984 malloc(16, M_CAMXPT, M_NOWAIT);
985 if (path->device->device_id != NULL) {
986 path->device->device_id_len = 16;
987 bcopy(&fake_device_id_hdr,
988 path->device->device_id, 8);
989 bcopy(ident_buf->wwn,
990 path->device->device_id + 8, 8);
991 ata_bswap(path->device->device_id + 8, 8);
995 path->device->flags |= CAM_DEV_IDENTIFY_DATA_VALID;
996 xpt_async(AC_GETDEV_CHANGED, path, NULL);
998 if (ident_buf->satacapabilities & ATA_SUPPORT_NCQ) {
999 path->device->mintags = 2;
1000 path->device->maxtags =
1001 ATA_QUEUE_LEN(ident_buf->queue) + 1;
1003 ata_find_quirk(path->device);
1004 if (path->device->mintags != 0 &&
1005 path->bus->sim->max_tagged_dev_openings != 0) {
1006 /* Check if the SIM does not want queued commands. */
1007 bzero(&cpi, sizeof(cpi));
1008 xpt_setup_ccb(&cpi.ccb_h, path, CAM_PRIORITY_NONE);
1009 cpi.ccb_h.func_code = XPT_PATH_INQ;
1010 xpt_action((union ccb *)&cpi);
1011 if (cpi.ccb_h.status == CAM_REQ_CMP &&
1012 (cpi.hba_inquiry & PI_TAG_ABLE)) {
1013 /* Report SIM which tags are allowed. */
1014 bzero(&cts, sizeof(cts));
1015 xpt_setup_ccb(&cts.ccb_h, path, CAM_PRIORITY_NONE);
1016 cts.ccb_h.func_code = XPT_SET_TRAN_SETTINGS;
1017 cts.type = CTS_TYPE_CURRENT_SETTINGS;
1018 cts.xport_specific.sata.tags = path->device->maxtags;
1019 cts.xport_specific.sata.valid = CTS_SATA_VALID_TAGS;
1020 xpt_action((union ccb *)&cts);
1023 ata_device_transport(path);
1025 proberequestdefaultnegotiation(periph);
1026 PROBE_SET_ACTION(softc, PROBE_SETMODE);
1027 xpt_release_ccb(done_ccb);
1028 xpt_schedule(periph, priority);
1033 xpt_print(path, "Spin-up done\n");
1035 PROBE_SET_ACTION(softc, PROBE_IDENTIFY);
1036 xpt_release_ccb(done_ccb);
1037 xpt_schedule(periph, priority);
1040 /* Set supported bits. */
1041 bzero(&cts, sizeof(cts));
1042 xpt_setup_ccb(&cts.ccb_h, path, CAM_PRIORITY_NONE);
1043 cts.ccb_h.func_code = XPT_GET_TRAN_SETTINGS;
1044 cts.type = CTS_TYPE_CURRENT_SETTINGS;
1045 xpt_action((union ccb *)&cts);
1046 if (path->device->transport == XPORT_SATA &&
1047 cts.xport_specific.sata.valid & CTS_SATA_VALID_CAPS)
1048 caps = cts.xport_specific.sata.caps & CTS_SATA_CAPS_H;
1049 else if (path->device->transport == XPORT_ATA &&
1050 cts.xport_specific.ata.valid & CTS_ATA_VALID_CAPS)
1051 caps = cts.xport_specific.ata.caps & CTS_ATA_CAPS_H;
1054 if (path->device->transport == XPORT_SATA &&
1055 ident_buf->satacapabilities != 0xffff) {
1056 if (ident_buf->satacapabilities & ATA_SUPPORT_IFPWRMNGTRCV)
1057 caps |= CTS_SATA_CAPS_D_PMREQ;
1058 if (ident_buf->satacapabilities & ATA_SUPPORT_HAPST)
1059 caps |= CTS_SATA_CAPS_D_APST;
1061 /* Mask unwanted bits. */
1062 bzero(&cts, sizeof(cts));
1063 xpt_setup_ccb(&cts.ccb_h, path, CAM_PRIORITY_NONE);
1064 cts.ccb_h.func_code = XPT_GET_TRAN_SETTINGS;
1065 cts.type = CTS_TYPE_USER_SETTINGS;
1066 xpt_action((union ccb *)&cts);
1067 if (path->device->transport == XPORT_SATA &&
1068 cts.xport_specific.sata.valid & CTS_SATA_VALID_CAPS)
1069 caps &= cts.xport_specific.sata.caps;
1070 else if (path->device->transport == XPORT_ATA &&
1071 cts.xport_specific.ata.valid & CTS_ATA_VALID_CAPS)
1072 caps &= cts.xport_specific.ata.caps;
1076 * Remember what transport thinks about 48-bit DMA. If
1077 * capability information is not provided or transport is
1078 * SATA, we take support for granted.
1080 if (!(path->device->inq_flags & SID_DMA) ||
1081 (path->device->transport == XPORT_ATA &&
1082 (cts.xport_specific.ata.valid & CTS_ATA_VALID_CAPS) &&
1083 !(caps & CTS_ATA_CAPS_H_DMA48)))
1084 path->device->inq_flags &= ~SID_DMA48;
1086 path->device->inq_flags |= SID_DMA48;
1087 /* Store result to SIM. */
1088 bzero(&cts, sizeof(cts));
1089 xpt_setup_ccb(&cts.ccb_h, path, CAM_PRIORITY_NONE);
1090 cts.ccb_h.func_code = XPT_SET_TRAN_SETTINGS;
1091 cts.type = CTS_TYPE_CURRENT_SETTINGS;
1092 if (path->device->transport == XPORT_SATA) {
1093 cts.xport_specific.sata.caps = caps;
1094 cts.xport_specific.sata.valid = CTS_SATA_VALID_CAPS;
1096 cts.xport_specific.ata.caps = caps;
1097 cts.xport_specific.ata.valid = CTS_ATA_VALID_CAPS;
1099 xpt_action((union ccb *)&cts);
1101 if (path->device->transport != XPORT_SATA)
1103 if ((ident_buf->satasupport & ATA_SUPPORT_IFPWRMNGT) &&
1104 (!(softc->caps & CTS_SATA_CAPS_H_PMREQ)) !=
1105 (!(ident_buf->sataenabled & ATA_SUPPORT_IFPWRMNGT))) {
1106 PROBE_SET_ACTION(softc, PROBE_SETPM);
1107 xpt_release_ccb(done_ccb);
1108 xpt_schedule(periph, priority);
1113 if (ident_buf->satacapabilities != 0xffff &&
1114 (ident_buf->satacapabilities & ATA_SUPPORT_DAPST) &&
1115 (!(softc->caps & CTS_SATA_CAPS_H_APST)) !=
1116 (!(ident_buf->sataenabled & ATA_ENABLED_DAPST))) {
1117 PROBE_SET_ACTION(softc, PROBE_SETAPST);
1118 xpt_release_ccb(done_ccb);
1119 xpt_schedule(periph, priority);
1124 if ((ident_buf->satasupport & ATA_SUPPORT_AUTOACTIVATE) &&
1125 (!(softc->caps & CTS_SATA_CAPS_H_DMAAA)) !=
1126 (!(ident_buf->sataenabled & ATA_SUPPORT_AUTOACTIVATE))) {
1127 PROBE_SET_ACTION(softc, PROBE_SETDMAAA);
1128 xpt_release_ccb(done_ccb);
1129 xpt_schedule(periph, priority);
1133 case PROBE_SETDMAAA:
1134 if (path->device->protocol != PROTO_ATA &&
1135 (ident_buf->satasupport & ATA_SUPPORT_ASYNCNOTIF) &&
1136 (!(softc->caps & CTS_SATA_CAPS_H_AN)) !=
1137 (!(ident_buf->sataenabled & ATA_SUPPORT_ASYNCNOTIF))) {
1138 PROBE_SET_ACTION(softc, PROBE_SETAN);
1139 xpt_release_ccb(done_ccb);
1140 xpt_schedule(periph, priority);
1146 if (path->device->protocol == PROTO_ATA) {
1147 PROBE_SET_ACTION(softc, PROBE_SET_MULTI);
1149 PROBE_SET_ACTION(softc, PROBE_INQUIRY);
1151 xpt_release_ccb(done_ccb);
1152 xpt_schedule(periph, priority);
1154 case PROBE_SET_MULTI:
1155 if (periph->path->device->flags & CAM_DEV_UNCONFIGURED) {
1156 path->device->flags &= ~CAM_DEV_UNCONFIGURED;
1157 xpt_acquire_device(path->device);
1158 done_ccb->ccb_h.func_code = XPT_GDEV_TYPE;
1159 xpt_action(done_ccb);
1160 xpt_async(AC_FOUND_DEVICE, path, done_ccb);
1162 PROBE_SET_ACTION(softc, PROBE_DONE);
1165 case PROBE_FULL_INQUIRY:
1167 u_int8_t periph_qual, len;
1169 path->device->flags |= CAM_DEV_INQUIRY_DATA_VALID;
1171 periph_qual = SID_QUAL(inq_buf);
1173 if (periph_qual != SID_QUAL_LU_CONNECTED &&
1174 periph_qual != SID_QUAL_LU_OFFLINE)
1178 * We conservatively request only
1179 * SHORT_INQUIRY_LEN bytes of inquiry
1180 * information during our first try
1181 * at sending an INQUIRY. If the device
1182 * has more information to give,
1183 * perform a second request specifying
1184 * the amount of information the device
1185 * is willing to give.
1187 len = inq_buf->additional_length
1188 + offsetof(struct scsi_inquiry_data, additional_length) + 1;
1189 if (softc->action == PROBE_INQUIRY
1190 && len > SHORT_INQUIRY_LENGTH) {
1191 PROBE_SET_ACTION(softc, PROBE_FULL_INQUIRY);
1192 xpt_release_ccb(done_ccb);
1193 xpt_schedule(periph, priority);
1197 ata_device_transport(path);
1198 if (periph->path->device->flags & CAM_DEV_UNCONFIGURED) {
1199 path->device->flags &= ~CAM_DEV_UNCONFIGURED;
1200 xpt_acquire_device(path->device);
1201 done_ccb->ccb_h.func_code = XPT_GDEV_TYPE;
1202 xpt_action(done_ccb);
1203 xpt_async(AC_FOUND_DEVICE, path, done_ccb);
1205 PROBE_SET_ACTION(softc, PROBE_DONE);
1209 if ((path->device->flags & CAM_DEV_IDENTIFY_DATA_VALID) == 0)
1210 bzero(ident_buf, sizeof(*ident_buf));
1211 softc->pm_pid = (done_ccb->ataio.res.lba_high << 24) +
1212 (done_ccb->ataio.res.lba_mid << 16) +
1213 (done_ccb->ataio.res.lba_low << 8) +
1214 done_ccb->ataio.res.sector_count;
1215 ((uint32_t *)ident_buf)[0] = softc->pm_pid;
1216 snprintf(ident_buf->model, sizeof(ident_buf->model),
1217 "Port Multiplier %08x", softc->pm_pid);
1218 PROBE_SET_ACTION(softc, PROBE_PM_PRV);
1219 xpt_release_ccb(done_ccb);
1220 xpt_schedule(periph, priority);
1223 softc->pm_prv = (done_ccb->ataio.res.lba_high << 24) +
1224 (done_ccb->ataio.res.lba_mid << 16) +
1225 (done_ccb->ataio.res.lba_low << 8) +
1226 done_ccb->ataio.res.sector_count;
1227 ((uint32_t *)ident_buf)[1] = softc->pm_prv;
1228 snprintf(ident_buf->revision, sizeof(ident_buf->revision),
1229 "%04x", softc->pm_prv);
1230 path->device->flags |= CAM_DEV_IDENTIFY_DATA_VALID;
1231 ata_device_transport(path);
1232 if (periph->path->device->flags & CAM_DEV_UNCONFIGURED)
1233 proberequestdefaultnegotiation(periph);
1234 /* Set supported bits. */
1235 bzero(&cts, sizeof(cts));
1236 xpt_setup_ccb(&cts.ccb_h, path, CAM_PRIORITY_NONE);
1237 cts.ccb_h.func_code = XPT_GET_TRAN_SETTINGS;
1238 cts.type = CTS_TYPE_CURRENT_SETTINGS;
1239 xpt_action((union ccb *)&cts);
1240 if (cts.xport_specific.sata.valid & CTS_SATA_VALID_CAPS)
1241 caps = cts.xport_specific.sata.caps & CTS_SATA_CAPS_H;
1244 /* All PMPs must support PM requests. */
1245 caps |= CTS_SATA_CAPS_D_PMREQ;
1246 /* Mask unwanted bits. */
1247 bzero(&cts, sizeof(cts));
1248 xpt_setup_ccb(&cts.ccb_h, path, CAM_PRIORITY_NONE);
1249 cts.ccb_h.func_code = XPT_GET_TRAN_SETTINGS;
1250 cts.type = CTS_TYPE_USER_SETTINGS;
1251 xpt_action((union ccb *)&cts);
1252 if (cts.xport_specific.sata.valid & CTS_SATA_VALID_CAPS)
1253 caps &= cts.xport_specific.sata.caps;
1256 /* Remember what transport thinks about AEN. */
1257 if ((caps & CTS_SATA_CAPS_H_AN) && path->device->protocol != PROTO_ATA)
1258 path->device->inq_flags |= SID_AEN;
1260 path->device->inq_flags &= ~SID_AEN;
1261 /* Store result to SIM. */
1262 bzero(&cts, sizeof(cts));
1263 xpt_setup_ccb(&cts.ccb_h, path, CAM_PRIORITY_NONE);
1264 cts.ccb_h.func_code = XPT_SET_TRAN_SETTINGS;
1265 cts.type = CTS_TYPE_CURRENT_SETTINGS;
1266 cts.xport_specific.sata.caps = caps;
1267 cts.xport_specific.sata.valid = CTS_SATA_VALID_CAPS;
1268 xpt_action((union ccb *)&cts);
1270 xpt_async(AC_GETDEV_CHANGED, path, NULL);
1271 if (periph->path->device->flags & CAM_DEV_UNCONFIGURED) {
1272 path->device->flags &= ~CAM_DEV_UNCONFIGURED;
1273 xpt_acquire_device(path->device);
1274 done_ccb->ccb_h.func_code = XPT_GDEV_TYPE;
1275 xpt_action(done_ccb);
1276 xpt_async(AC_FOUND_DEVICE, path, done_ccb);
1278 done_ccb->ccb_h.func_code = XPT_GDEV_TYPE;
1279 xpt_action(done_ccb);
1280 xpt_async(AC_SCSI_AEN, path, done_ccb);
1282 PROBE_SET_ACTION(softc, PROBE_DONE);
1284 case PROBE_IDENTIFY_SES:
1285 case PROBE_IDENTIFY_SAFTE:
1286 if ((periph->path->device->flags & CAM_DEV_UNCONFIGURED) == 0) {
1287 /* Check that it is the same device. */
1288 if (bcmp(&softc->ident_data, ident_buf, 53)) {
1289 /* Device changed. */
1290 xpt_async(AC_LOST_DEVICE, path, NULL);
1292 bcopy(&softc->ident_data, ident_buf, sizeof(struct ata_params));
1297 bcopy(&softc->ident_data, ident_buf, sizeof(struct ata_params));
1298 /* Clean up from previous instance of this device */
1299 if (path->device->device_id != NULL) {
1300 free(path->device->device_id, M_CAMXPT);
1301 path->device->device_id = NULL;
1302 path->device->device_id_len = 0;
1304 path->device->device_id =
1305 malloc(16, M_CAMXPT, M_NOWAIT);
1306 if (path->device->device_id != NULL) {
1307 path->device->device_id_len = 16;
1308 bcopy(&fake_device_id_hdr,
1309 path->device->device_id, 8);
1310 bcopy(((uint8_t*)ident_buf) + 2,
1311 path->device->device_id + 8, 8);
1314 path->device->flags |= CAM_DEV_IDENTIFY_DATA_VALID;
1316 ata_device_transport(path);
1318 proberequestdefaultnegotiation(periph);
1320 if (periph->path->device->flags & CAM_DEV_UNCONFIGURED) {
1321 path->device->flags &= ~CAM_DEV_UNCONFIGURED;
1322 xpt_acquire_device(path->device);
1323 done_ccb->ccb_h.func_code = XPT_GDEV_TYPE;
1324 xpt_action(done_ccb);
1325 xpt_async(AC_FOUND_DEVICE, path, done_ccb);
1327 PROBE_SET_ACTION(softc, PROBE_DONE);
1330 panic("probedone: invalid action state 0x%x\n", softc->action);
1333 if (softc->restart) {
1335 xpt_release_ccb(done_ccb);
1336 probeschedule(periph);
1339 xpt_release_ccb(done_ccb);
1340 CAM_DEBUG(periph->path, CAM_DEBUG_PROBE, ("Probe completed\n"));
1341 while ((done_ccb = (union ccb *)TAILQ_FIRST(&softc->request_ccbs))) {
1342 TAILQ_REMOVE(&softc->request_ccbs,
1343 &done_ccb->ccb_h, periph_links.tqe);
1344 done_ccb->ccb_h.status = found ? CAM_REQ_CMP : CAM_REQ_CMP_ERR;
1347 /* Drop freeze taken due to CAM_DEV_QFREEZE flag set. */
1348 cam_release_devq(path, 0, 0, 0, FALSE);
1349 cam_periph_invalidate(periph);
1350 cam_periph_release_locked(periph);
1354 probecleanup(struct cam_periph *periph)
1356 free(periph->softc, M_CAMXPT);
1360 ata_find_quirk(struct cam_ed *device)
1362 struct ata_quirk_entry *quirk;
1365 match = cam_quirkmatch((caddr_t)&device->ident_data,
1366 (caddr_t)ata_quirk_table,
1367 nitems(ata_quirk_table),
1368 sizeof(*ata_quirk_table), ata_identify_match);
1371 panic("xpt_find_quirk: device didn't match wildcard entry!!");
1373 quirk = (struct ata_quirk_entry *)match;
1374 device->quirk = quirk;
1375 if (quirk->quirks & CAM_QUIRK_MAXTAGS) {
1376 device->mintags = quirk->mintags;
1377 device->maxtags = quirk->maxtags;
1382 union ccb *request_ccb;
1383 struct ccb_pathinq *cpi;
1385 } ata_scan_bus_info;
1388 * To start a scan, request_ccb is an XPT_SCAN_BUS ccb.
1389 * As the scan progresses, xpt_scan_bus is used as the
1390 * callback on completion function.
1393 ata_scan_bus(struct cam_periph *periph, union ccb *request_ccb)
1395 struct cam_path *path;
1396 ata_scan_bus_info *scan_info;
1397 union ccb *work_ccb, *reset_ccb;
1401 CAM_DEBUG(request_ccb->ccb_h.path, CAM_DEBUG_TRACE,
1402 ("xpt_scan_bus\n"));
1403 switch (request_ccb->ccb_h.func_code) {
1406 /* Find out the characteristics of the bus */
1407 work_ccb = xpt_alloc_ccb_nowait();
1408 if (work_ccb == NULL) {
1409 request_ccb->ccb_h.status = CAM_RESRC_UNAVAIL;
1410 xpt_done(request_ccb);
1413 xpt_setup_ccb(&work_ccb->ccb_h, request_ccb->ccb_h.path,
1414 request_ccb->ccb_h.pinfo.priority);
1415 work_ccb->ccb_h.func_code = XPT_PATH_INQ;
1416 xpt_action(work_ccb);
1417 if (work_ccb->ccb_h.status != CAM_REQ_CMP) {
1418 request_ccb->ccb_h.status = work_ccb->ccb_h.status;
1419 xpt_free_ccb(work_ccb);
1420 xpt_done(request_ccb);
1424 /* We may need to reset bus first, if we haven't done it yet. */
1425 if ((work_ccb->cpi.hba_inquiry &
1426 (PI_WIDE_32|PI_WIDE_16|PI_SDTR_ABLE)) &&
1427 !(work_ccb->cpi.hba_misc & PIM_NOBUSRESET) &&
1428 !timevalisset(&request_ccb->ccb_h.path->bus->last_reset)) {
1429 reset_ccb = xpt_alloc_ccb_nowait();
1430 if (reset_ccb == NULL) {
1431 request_ccb->ccb_h.status = CAM_RESRC_UNAVAIL;
1432 xpt_free_ccb(work_ccb);
1433 xpt_done(request_ccb);
1436 xpt_setup_ccb(&reset_ccb->ccb_h, request_ccb->ccb_h.path,
1438 reset_ccb->ccb_h.func_code = XPT_RESET_BUS;
1439 xpt_action(reset_ccb);
1440 if (reset_ccb->ccb_h.status != CAM_REQ_CMP) {
1441 request_ccb->ccb_h.status = reset_ccb->ccb_h.status;
1442 xpt_free_ccb(reset_ccb);
1443 xpt_free_ccb(work_ccb);
1444 xpt_done(request_ccb);
1447 xpt_free_ccb(reset_ccb);
1450 /* Save some state for use while we probe for devices */
1451 scan_info = (ata_scan_bus_info *)
1452 malloc(sizeof(ata_scan_bus_info), M_CAMXPT, M_NOWAIT);
1453 if (scan_info == NULL) {
1454 request_ccb->ccb_h.status = CAM_RESRC_UNAVAIL;
1455 xpt_free_ccb(work_ccb);
1456 xpt_done(request_ccb);
1459 scan_info->request_ccb = request_ccb;
1460 scan_info->cpi = &work_ccb->cpi;
1461 /* If PM supported, probe it first. */
1462 if (scan_info->cpi->hba_inquiry & PI_SATAPM)
1463 scan_info->counter = scan_info->cpi->max_target;
1465 scan_info->counter = 0;
1467 work_ccb = xpt_alloc_ccb_nowait();
1468 if (work_ccb == NULL) {
1469 free(scan_info, M_CAMXPT);
1470 request_ccb->ccb_h.status = CAM_RESRC_UNAVAIL;
1471 xpt_done(request_ccb);
1474 mtx = xpt_path_mtx(scan_info->request_ccb->ccb_h.path);
1477 work_ccb = request_ccb;
1478 /* Reuse the same CCB to query if a device was really found */
1479 scan_info = (ata_scan_bus_info *)work_ccb->ccb_h.ppriv_ptr0;
1480 mtx = xpt_path_mtx(scan_info->request_ccb->ccb_h.path);
1482 /* If there is PMP... */
1483 if ((scan_info->cpi->hba_inquiry & PI_SATAPM) &&
1484 (scan_info->counter == scan_info->cpi->max_target)) {
1485 if (work_ccb->ccb_h.status == CAM_REQ_CMP) {
1486 /* everything else will be probed by it */
1487 /* Free the current request path- we're done with it. */
1488 xpt_free_path(work_ccb->ccb_h.path);
1491 struct ccb_trans_settings cts;
1493 /* Report SIM that PM is absent. */
1494 bzero(&cts, sizeof(cts));
1495 xpt_setup_ccb(&cts.ccb_h,
1496 work_ccb->ccb_h.path, CAM_PRIORITY_NONE);
1497 cts.ccb_h.func_code = XPT_SET_TRAN_SETTINGS;
1498 cts.type = CTS_TYPE_CURRENT_SETTINGS;
1499 cts.xport_specific.sata.pm_present = 0;
1500 cts.xport_specific.sata.valid = CTS_SATA_VALID_PM;
1501 xpt_action((union ccb *)&cts);
1504 /* Free the current request path- we're done with it. */
1505 xpt_free_path(work_ccb->ccb_h.path);
1506 if (scan_info->counter ==
1507 ((scan_info->cpi->hba_inquiry & PI_SATAPM) ?
1508 0 : scan_info->cpi->max_target)) {
1511 xpt_free_ccb(work_ccb);
1512 xpt_free_ccb((union ccb *)scan_info->cpi);
1513 request_ccb = scan_info->request_ccb;
1514 free(scan_info, M_CAMXPT);
1515 request_ccb->ccb_h.status = CAM_REQ_CMP;
1516 xpt_done(request_ccb);
1519 /* Take next device. Wrap from max (PMP) to 0. */
1520 scan_info->counter = (scan_info->counter + 1 ) %
1521 (scan_info->cpi->max_target + 1);
1523 status = xpt_create_path(&path, NULL,
1524 scan_info->request_ccb->ccb_h.path_id,
1525 scan_info->counter, 0);
1526 if (status != CAM_REQ_CMP) {
1527 if (request_ccb->ccb_h.func_code == XPT_SCAN_LUN)
1529 printf("xpt_scan_bus: xpt_create_path failed"
1530 " with status %#x, bus scan halted\n",
1532 xpt_free_ccb(work_ccb);
1533 xpt_free_ccb((union ccb *)scan_info->cpi);
1534 request_ccb = scan_info->request_ccb;
1535 free(scan_info, M_CAMXPT);
1536 request_ccb->ccb_h.status = status;
1537 xpt_done(request_ccb);
1540 xpt_setup_ccb(&work_ccb->ccb_h, path,
1541 scan_info->request_ccb->ccb_h.pinfo.priority);
1542 work_ccb->ccb_h.func_code = XPT_SCAN_LUN;
1543 work_ccb->ccb_h.cbfcnp = ata_scan_bus;
1544 work_ccb->ccb_h.flags |= CAM_UNLOCKED;
1545 work_ccb->ccb_h.ppriv_ptr0 = scan_info;
1546 work_ccb->crcn.flags = scan_info->request_ccb->crcn.flags;
1548 if (request_ccb->ccb_h.func_code == XPT_SCAN_LUN)
1550 xpt_action(work_ccb);
1560 ata_scan_lun(struct cam_periph *periph, struct cam_path *path,
1561 cam_flags flags, union ccb *request_ccb)
1563 struct ccb_pathinq cpi;
1565 struct cam_path *new_path;
1566 struct cam_periph *old_periph;
1569 CAM_DEBUG(path, CAM_DEBUG_TRACE, ("xpt_scan_lun\n"));
1571 xpt_setup_ccb(&cpi.ccb_h, path, CAM_PRIORITY_NONE);
1572 cpi.ccb_h.func_code = XPT_PATH_INQ;
1573 xpt_action((union ccb *)&cpi);
1575 if (cpi.ccb_h.status != CAM_REQ_CMP) {
1576 if (request_ccb != NULL) {
1577 request_ccb->ccb_h.status = cpi.ccb_h.status;
1578 xpt_done(request_ccb);
1583 if (request_ccb == NULL) {
1584 request_ccb = xpt_alloc_ccb_nowait();
1585 if (request_ccb == NULL) {
1586 xpt_print(path, "xpt_scan_lun: can't allocate CCB, "
1587 "can't continue\n");
1590 status = xpt_create_path(&new_path, NULL,
1592 path->target->target_id,
1593 path->device->lun_id);
1594 if (status != CAM_REQ_CMP) {
1595 xpt_print(path, "xpt_scan_lun: can't create path, "
1596 "can't continue\n");
1597 xpt_free_ccb(request_ccb);
1600 xpt_setup_ccb(&request_ccb->ccb_h, new_path, CAM_PRIORITY_XPT);
1601 request_ccb->ccb_h.cbfcnp = xptscandone;
1602 request_ccb->ccb_h.flags |= CAM_UNLOCKED;
1603 request_ccb->ccb_h.func_code = XPT_SCAN_LUN;
1604 request_ccb->crcn.flags = flags;
1607 lock = (xpt_path_owned(path) == 0);
1609 xpt_path_lock(path);
1610 if ((old_periph = cam_periph_find(path, "aprobe")) != NULL) {
1611 if ((old_periph->flags & CAM_PERIPH_INVALID) == 0) {
1614 softc = (probe_softc *)old_periph->softc;
1615 TAILQ_INSERT_TAIL(&softc->request_ccbs,
1616 &request_ccb->ccb_h, periph_links.tqe);
1619 request_ccb->ccb_h.status = CAM_REQ_CMP_ERR;
1620 xpt_done(request_ccb);
1623 status = cam_periph_alloc(proberegister, NULL, probecleanup,
1624 probestart, "aprobe",
1626 request_ccb->ccb_h.path, NULL, 0,
1629 if (status != CAM_REQ_CMP) {
1630 xpt_print(path, "xpt_scan_lun: cam_alloc_periph "
1631 "returned an error, can't continue probe\n");
1632 request_ccb->ccb_h.status = status;
1633 xpt_done(request_ccb);
1637 xpt_path_unlock(path);
1641 xptscandone(struct cam_periph *periph, union ccb *done_ccb)
1644 xpt_free_path(done_ccb->ccb_h.path);
1645 xpt_free_ccb(done_ccb);
1648 static struct cam_ed *
1649 ata_alloc_device(struct cam_eb *bus, struct cam_et *target, lun_id_t lun_id)
1651 struct ata_quirk_entry *quirk;
1652 struct cam_ed *device;
1654 device = xpt_alloc_device(bus, target, lun_id);
1659 * Take the default quirk entry until we have inquiry
1660 * data and can determine a better quirk to use.
1662 quirk = &ata_quirk_table[nitems(ata_quirk_table) - 1];
1663 device->quirk = (void *)quirk;
1664 device->mintags = 0;
1665 device->maxtags = 0;
1666 bzero(&device->inq_data, sizeof(device->inq_data));
1667 device->inq_flags = 0;
1668 device->queue_flags = 0;
1669 device->serial_num = NULL;
1670 device->serial_num_len = 0;
1675 ata_device_transport(struct cam_path *path)
1677 struct ccb_pathinq cpi;
1678 struct ccb_trans_settings cts;
1679 struct scsi_inquiry_data *inq_buf = NULL;
1680 struct ata_params *ident_buf = NULL;
1682 /* Get transport information from the SIM */
1683 xpt_setup_ccb(&cpi.ccb_h, path, CAM_PRIORITY_NONE);
1684 cpi.ccb_h.func_code = XPT_PATH_INQ;
1685 xpt_action((union ccb *)&cpi);
1687 path->device->transport = cpi.transport;
1688 if ((path->device->flags & CAM_DEV_INQUIRY_DATA_VALID) != 0)
1689 inq_buf = &path->device->inq_data;
1690 if ((path->device->flags & CAM_DEV_IDENTIFY_DATA_VALID) != 0)
1691 ident_buf = &path->device->ident_data;
1692 if (path->device->protocol == PROTO_ATA) {
1693 path->device->protocol_version = ident_buf ?
1694 ata_version(ident_buf->version_major) : cpi.protocol_version;
1695 } else if (path->device->protocol == PROTO_SCSI) {
1696 path->device->protocol_version = inq_buf ?
1697 SID_ANSI_REV(inq_buf) : cpi.protocol_version;
1699 path->device->transport_version = ident_buf ?
1700 ata_version(ident_buf->version_major) : cpi.transport_version;
1702 /* Tell the controller what we think */
1703 xpt_setup_ccb(&cts.ccb_h, path, CAM_PRIORITY_NONE);
1704 cts.ccb_h.func_code = XPT_SET_TRAN_SETTINGS;
1705 cts.type = CTS_TYPE_CURRENT_SETTINGS;
1706 cts.transport = path->device->transport;
1707 cts.transport_version = path->device->transport_version;
1708 cts.protocol = path->device->protocol;
1709 cts.protocol_version = path->device->protocol_version;
1710 cts.proto_specific.valid = 0;
1712 if (path->device->transport == XPORT_ATA) {
1713 cts.xport_specific.ata.atapi =
1714 (ident_buf->config == ATA_PROTO_CFA) ? 0 :
1715 ((ident_buf->config & ATA_PROTO_MASK) == ATA_PROTO_ATAPI_16) ? 16 :
1716 ((ident_buf->config & ATA_PROTO_MASK) == ATA_PROTO_ATAPI_12) ? 12 : 0;
1717 cts.xport_specific.ata.valid = CTS_ATA_VALID_ATAPI;
1719 cts.xport_specific.sata.atapi =
1720 (ident_buf->config == ATA_PROTO_CFA) ? 0 :
1721 ((ident_buf->config & ATA_PROTO_MASK) == ATA_PROTO_ATAPI_16) ? 16 :
1722 ((ident_buf->config & ATA_PROTO_MASK) == ATA_PROTO_ATAPI_12) ? 12 : 0;
1723 cts.xport_specific.sata.valid = CTS_SATA_VALID_ATAPI;
1726 cts.xport_specific.valid = 0;
1727 xpt_action((union ccb *)&cts);
1731 ata_dev_advinfo(union ccb *start_ccb)
1733 struct cam_ed *device;
1734 struct ccb_dev_advinfo *cdai;
1737 start_ccb->ccb_h.status = CAM_REQ_INVALID;
1738 device = start_ccb->ccb_h.path->device;
1739 cdai = &start_ccb->cdai;
1740 switch(cdai->buftype) {
1741 case CDAI_TYPE_SCSI_DEVID:
1742 if (cdai->flags & CDAI_FLAG_STORE)
1744 cdai->provsiz = device->device_id_len;
1745 if (device->device_id_len == 0)
1747 amt = device->device_id_len;
1748 if (cdai->provsiz > cdai->bufsiz)
1750 memcpy(cdai->buf, device->device_id, amt);
1752 case CDAI_TYPE_SERIAL_NUM:
1753 if (cdai->flags & CDAI_FLAG_STORE)
1755 cdai->provsiz = device->serial_num_len;
1756 if (device->serial_num_len == 0)
1758 amt = device->serial_num_len;
1759 if (cdai->provsiz > cdai->bufsiz)
1761 memcpy(cdai->buf, device->serial_num, amt);
1763 case CDAI_TYPE_PHYS_PATH:
1764 if (cdai->flags & CDAI_FLAG_STORE) {
1765 if (device->physpath != NULL)
1766 free(device->physpath, M_CAMXPT);
1767 device->physpath_len = cdai->bufsiz;
1768 /* Clear existing buffer if zero length */
1769 if (cdai->bufsiz == 0)
1771 device->physpath = malloc(cdai->bufsiz, M_CAMXPT, M_NOWAIT);
1772 if (device->physpath == NULL) {
1773 start_ccb->ccb_h.status = CAM_REQ_ABORTED;
1776 memcpy(device->physpath, cdai->buf, cdai->bufsiz);
1778 cdai->provsiz = device->physpath_len;
1779 if (device->physpath_len == 0)
1781 amt = device->physpath_len;
1782 if (cdai->provsiz > cdai->bufsiz)
1784 memcpy(cdai->buf, device->physpath, amt);
1790 start_ccb->ccb_h.status = CAM_REQ_CMP;
1792 if (cdai->flags & CDAI_FLAG_STORE) {
1793 xpt_async(AC_ADVINFO_CHANGED, start_ccb->ccb_h.path,
1794 (void *)(uintptr_t)cdai->buftype);
1799 ata_action(union ccb *start_ccb)
1802 switch (start_ccb->ccb_h.func_code) {
1803 case XPT_SET_TRAN_SETTINGS:
1805 ata_set_transfer_settings(&start_ccb->cts,
1806 start_ccb->ccb_h.path,
1807 /*async_update*/FALSE);
1812 ata_scan_bus(start_ccb->ccb_h.path->periph, start_ccb);
1815 ata_scan_lun(start_ccb->ccb_h.path->periph,
1816 start_ccb->ccb_h.path, start_ccb->crcn.flags,
1819 case XPT_GET_TRAN_SETTINGS:
1821 ata_get_transfer_settings(&start_ccb->cts);
1826 struct cam_ed *device;
1829 device = start_ccb->ccb_h.path->device;
1830 if (device->protocol == PROTO_SCSI &&
1831 (device->flags & CAM_DEV_IDENTIFY_DATA_VALID)) {
1833 device->ident_data.config & ATA_PROTO_MASK;
1836 (device->ident_data.config == ATA_PROTO_CFA) ? 0 :
1837 (p == ATA_PROTO_ATAPI_16) ? 16 :
1838 (p == ATA_PROTO_ATAPI_12) ? 12 : 0;
1840 if (start_ccb->csio.cdb_len > maxlen) {
1841 start_ccb->ccb_h.status = CAM_REQ_INVALID;
1842 xpt_done(start_ccb);
1845 xpt_action_default(start_ccb);
1848 case XPT_DEV_ADVINFO:
1850 ata_dev_advinfo(start_ccb);
1854 xpt_action_default(start_ccb);
1860 ata_get_transfer_settings(struct ccb_trans_settings *cts)
1862 struct ccb_trans_settings_ata *ata;
1863 struct ccb_trans_settings_scsi *scsi;
1864 struct cam_ed *device;
1866 device = cts->ccb_h.path->device;
1867 xpt_action_default((union ccb *)cts);
1869 if (cts->protocol == PROTO_UNKNOWN ||
1870 cts->protocol == PROTO_UNSPECIFIED) {
1871 cts->protocol = device->protocol;
1872 cts->protocol_version = device->protocol_version;
1875 if (cts->protocol == PROTO_ATA) {
1876 ata = &cts->proto_specific.ata;
1877 if ((ata->valid & CTS_ATA_VALID_TQ) == 0) {
1878 ata->valid |= CTS_ATA_VALID_TQ;
1879 if (cts->type == CTS_TYPE_USER_SETTINGS ||
1880 (device->flags & CAM_DEV_TAG_AFTER_COUNT) != 0 ||
1881 (device->inq_flags & SID_CmdQue) != 0)
1882 ata->flags |= CTS_ATA_FLAGS_TAG_ENB;
1885 if (cts->protocol == PROTO_SCSI) {
1886 scsi = &cts->proto_specific.scsi;
1887 if ((scsi->valid & CTS_SCSI_VALID_TQ) == 0) {
1888 scsi->valid |= CTS_SCSI_VALID_TQ;
1889 if (cts->type == CTS_TYPE_USER_SETTINGS ||
1890 (device->flags & CAM_DEV_TAG_AFTER_COUNT) != 0 ||
1891 (device->inq_flags & SID_CmdQue) != 0)
1892 scsi->flags |= CTS_SCSI_FLAGS_TAG_ENB;
1896 if (cts->transport == XPORT_UNKNOWN ||
1897 cts->transport == XPORT_UNSPECIFIED) {
1898 cts->transport = device->transport;
1899 cts->transport_version = device->transport_version;
1904 ata_set_transfer_settings(struct ccb_trans_settings *cts, struct cam_path *path,
1907 struct ccb_pathinq cpi;
1908 struct ccb_trans_settings_ata *ata;
1909 struct ccb_trans_settings_scsi *scsi;
1910 struct ata_params *ident_data;
1911 struct scsi_inquiry_data *inq_data;
1912 struct cam_ed *device;
1914 if (path == NULL || (device = path->device) == NULL) {
1915 cts->ccb_h.status = CAM_PATH_INVALID;
1916 xpt_done((union ccb *)cts);
1920 if (cts->protocol == PROTO_UNKNOWN
1921 || cts->protocol == PROTO_UNSPECIFIED) {
1922 cts->protocol = device->protocol;
1923 cts->protocol_version = device->protocol_version;
1926 if (cts->protocol_version == PROTO_VERSION_UNKNOWN
1927 || cts->protocol_version == PROTO_VERSION_UNSPECIFIED)
1928 cts->protocol_version = device->protocol_version;
1930 if (cts->protocol != device->protocol) {
1931 xpt_print(path, "Uninitialized Protocol %x:%x?\n",
1932 cts->protocol, device->protocol);
1933 cts->protocol = device->protocol;
1936 if (cts->protocol_version > device->protocol_version) {
1938 xpt_print(path, "Down reving Protocol "
1939 "Version from %d to %d?\n", cts->protocol_version,
1940 device->protocol_version);
1942 cts->protocol_version = device->protocol_version;
1945 if (cts->transport == XPORT_UNKNOWN
1946 || cts->transport == XPORT_UNSPECIFIED) {
1947 cts->transport = device->transport;
1948 cts->transport_version = device->transport_version;
1951 if (cts->transport_version == XPORT_VERSION_UNKNOWN
1952 || cts->transport_version == XPORT_VERSION_UNSPECIFIED)
1953 cts->transport_version = device->transport_version;
1955 if (cts->transport != device->transport) {
1956 xpt_print(path, "Uninitialized Transport %x:%x?\n",
1957 cts->transport, device->transport);
1958 cts->transport = device->transport;
1961 if (cts->transport_version > device->transport_version) {
1963 xpt_print(path, "Down reving Transport "
1964 "Version from %d to %d?\n", cts->transport_version,
1965 device->transport_version);
1967 cts->transport_version = device->transport_version;
1970 ident_data = &device->ident_data;
1971 inq_data = &device->inq_data;
1972 if (cts->protocol == PROTO_ATA)
1973 ata = &cts->proto_specific.ata;
1976 if (cts->protocol == PROTO_SCSI)
1977 scsi = &cts->proto_specific.scsi;
1980 xpt_setup_ccb(&cpi.ccb_h, path, CAM_PRIORITY_NONE);
1981 cpi.ccb_h.func_code = XPT_PATH_INQ;
1982 xpt_action((union ccb *)&cpi);
1984 /* Sanity checking */
1985 if ((cpi.hba_inquiry & PI_TAG_ABLE) == 0
1986 || (ata && (ident_data->satacapabilities & ATA_SUPPORT_NCQ) == 0)
1987 || (scsi && (INQ_DATA_TQ_ENABLED(inq_data)) == 0)
1988 || (device->queue_flags & SCP_QUEUE_DQUE) != 0
1989 || (device->mintags == 0)) {
1991 * Can't tag on hardware that doesn't support tags,
1992 * doesn't have it enabled, or has broken tag support.
1995 ata->flags &= ~CTS_ATA_FLAGS_TAG_ENB;
1997 scsi->flags &= ~CTS_SCSI_FLAGS_TAG_ENB;
2000 /* Start/stop tags use. */
2001 if (cts->type == CTS_TYPE_CURRENT_SETTINGS &&
2002 ((ata && (ata->valid & CTS_ATA_VALID_TQ) != 0) ||
2003 (scsi && (scsi->valid & CTS_SCSI_VALID_TQ) != 0))) {
2006 nowt = ((device->flags & CAM_DEV_TAG_AFTER_COUNT) != 0 ||
2007 (device->inq_flags & SID_CmdQue) != 0);
2009 newt = (ata->flags & CTS_ATA_FLAGS_TAG_ENB) != 0;
2011 newt = (scsi->flags & CTS_SCSI_FLAGS_TAG_ENB) != 0;
2013 if (newt && !nowt) {
2015 * Delay change to use tags until after a
2016 * few commands have gone to this device so
2017 * the controller has time to perform transfer
2018 * negotiations without tagged messages getting
2021 device->tag_delay_count = CAM_TAG_DELAY_COUNT;
2022 device->flags |= CAM_DEV_TAG_AFTER_COUNT;
2023 } else if (nowt && !newt)
2024 xpt_stop_tags(path);
2027 if (async_update == FALSE)
2028 xpt_action_default((union ccb *)cts);
2032 * Handle any per-device event notifications that require action by the XPT.
2035 ata_dev_async(u_int32_t async_code, struct cam_eb *bus, struct cam_et *target,
2036 struct cam_ed *device, void *async_arg)
2039 struct cam_path newpath;
2042 * We only need to handle events for real devices.
2044 if (target->target_id == CAM_TARGET_WILDCARD
2045 || device->lun_id == CAM_LUN_WILDCARD)
2049 * We need our own path with wildcards expanded to
2050 * handle certain types of events.
2052 if ((async_code == AC_SENT_BDR)
2053 || (async_code == AC_BUS_RESET)
2054 || (async_code == AC_INQ_CHANGED))
2055 status = xpt_compile_path(&newpath, NULL,
2060 status = CAM_REQ_CMP_ERR;
2062 if (status == CAM_REQ_CMP) {
2063 if (async_code == AC_INQ_CHANGED) {
2065 * We've sent a start unit command, or
2066 * something similar to a device that
2067 * may have caused its inquiry data to
2068 * change. So we re-scan the device to
2069 * refresh the inquiry data for it.
2071 ata_scan_lun(newpath.periph, &newpath,
2072 CAM_EXPECT_INQ_CHANGE, NULL);
2074 /* We need to reinitialize device after reset. */
2075 ata_scan_lun(newpath.periph, &newpath,
2078 xpt_release_path(&newpath);
2079 } else if (async_code == AC_LOST_DEVICE &&
2080 (device->flags & CAM_DEV_UNCONFIGURED) == 0) {
2081 device->flags |= CAM_DEV_UNCONFIGURED;
2082 xpt_release_device(device);
2083 } else if (async_code == AC_TRANSFER_NEG) {
2084 struct ccb_trans_settings *settings;
2085 struct cam_path path;
2087 settings = (struct ccb_trans_settings *)async_arg;
2088 xpt_compile_path(&path, NULL, bus->path_id, target->target_id,
2090 ata_set_transfer_settings(settings, &path,
2091 /*async_update*/TRUE);
2092 xpt_release_path(&path);
2097 _ata_announce_periph(struct cam_periph *periph, struct ccb_trans_settings *cts, u_int *speed)
2099 struct ccb_pathinq cpi;
2100 struct cam_path *path = periph->path;
2102 cam_periph_assert(periph, MA_OWNED);
2104 xpt_setup_ccb(&cts->ccb_h, path, CAM_PRIORITY_NORMAL);
2105 cts->ccb_h.func_code = XPT_GET_TRAN_SETTINGS;
2106 cts->type = CTS_TYPE_CURRENT_SETTINGS;
2107 xpt_action((union ccb*)cts);
2108 if ((cts->ccb_h.status & CAM_STATUS_MASK) != CAM_REQ_CMP)
2110 /* Ask the SIM for its base transfer speed */
2111 xpt_setup_ccb(&cpi.ccb_h, path, CAM_PRIORITY_NORMAL);
2112 cpi.ccb_h.func_code = XPT_PATH_INQ;
2113 xpt_action((union ccb *)&cpi);
2114 /* Report connection speed */
2115 *speed = cpi.base_transfer_speed;
2116 if (cts->transport == XPORT_ATA) {
2117 struct ccb_trans_settings_pata *pata =
2118 &cts->xport_specific.ata;
2120 if (pata->valid & CTS_ATA_VALID_MODE)
2121 *speed = ata_mode2speed(pata->mode);
2123 if (cts->transport == XPORT_SATA) {
2124 struct ccb_trans_settings_sata *sata =
2125 &cts->xport_specific.sata;
2127 if (sata->valid & CTS_SATA_VALID_REVISION)
2128 *speed = ata_revision2speed(sata->revision);
2133 ata_announce_periph(struct cam_periph *periph)
2135 struct ccb_trans_settings cts;
2138 _ata_announce_periph(periph, &cts, &speed);
2139 if ((cts.ccb_h.status & CAM_STATUS_MASK) != CAM_REQ_CMP)
2144 printf("%s%d: %d.%03dMB/s transfers",
2145 periph->periph_name, periph->unit_number,
2148 printf("%s%d: %dKB/s transfers", periph->periph_name,
2149 periph->unit_number, speed);
2150 /* Report additional information about connection */
2151 if (cts.transport == XPORT_ATA) {
2152 struct ccb_trans_settings_pata *pata =
2153 &cts.xport_specific.ata;
2156 if (pata->valid & CTS_ATA_VALID_MODE)
2157 printf("%s, ", ata_mode2string(pata->mode));
2158 if ((pata->valid & CTS_ATA_VALID_ATAPI) && pata->atapi != 0)
2159 printf("ATAPI %dbytes, ", pata->atapi);
2160 if (pata->valid & CTS_ATA_VALID_BYTECOUNT)
2161 printf("PIO %dbytes", pata->bytecount);
2164 if (cts.transport == XPORT_SATA) {
2165 struct ccb_trans_settings_sata *sata =
2166 &cts.xport_specific.sata;
2169 if (sata->valid & CTS_SATA_VALID_REVISION)
2170 printf("SATA %d.x, ", sata->revision);
2173 if (sata->valid & CTS_SATA_VALID_MODE)
2174 printf("%s, ", ata_mode2string(sata->mode));
2175 if ((sata->valid & CTS_ATA_VALID_ATAPI) && sata->atapi != 0)
2176 printf("ATAPI %dbytes, ", sata->atapi);
2177 if (sata->valid & CTS_SATA_VALID_BYTECOUNT)
2178 printf("PIO %dbytes", sata->bytecount);
2185 ata_announce_periph_sbuf(struct cam_periph *periph, struct sbuf *sb)
2187 struct ccb_trans_settings cts;
2190 _ata_announce_periph(periph, &cts, &speed);
2191 if ((cts.ccb_h.status & CAM_STATUS_MASK) != CAM_REQ_CMP)
2196 sbuf_printf(sb, "%s%d: %d.%03dMB/s transfers",
2197 periph->periph_name, periph->unit_number,
2200 sbuf_printf(sb, "%s%d: %dKB/s transfers", periph->periph_name,
2201 periph->unit_number, speed);
2202 /* Report additional information about connection */
2203 if (cts.transport == XPORT_ATA) {
2204 struct ccb_trans_settings_pata *pata =
2205 &cts.xport_specific.ata;
2207 sbuf_printf(sb, " (");
2208 if (pata->valid & CTS_ATA_VALID_MODE)
2209 sbuf_printf(sb, "%s, ", ata_mode2string(pata->mode));
2210 if ((pata->valid & CTS_ATA_VALID_ATAPI) && pata->atapi != 0)
2211 sbuf_printf(sb, "ATAPI %dbytes, ", pata->atapi);
2212 if (pata->valid & CTS_ATA_VALID_BYTECOUNT)
2213 sbuf_printf(sb, "PIO %dbytes", pata->bytecount);
2214 sbuf_printf(sb, ")");
2216 if (cts.transport == XPORT_SATA) {
2217 struct ccb_trans_settings_sata *sata =
2218 &cts.xport_specific.sata;
2220 sbuf_printf(sb, " (");
2221 if (sata->valid & CTS_SATA_VALID_REVISION)
2222 sbuf_printf(sb, "SATA %d.x, ", sata->revision);
2224 sbuf_printf(sb, "SATA, ");
2225 if (sata->valid & CTS_SATA_VALID_MODE)
2226 sbuf_printf(sb, "%s, ", ata_mode2string(sata->mode));
2227 if ((sata->valid & CTS_ATA_VALID_ATAPI) && sata->atapi != 0)
2228 sbuf_printf(sb, "ATAPI %dbytes, ", sata->atapi);
2229 if (sata->valid & CTS_SATA_VALID_BYTECOUNT)
2230 sbuf_printf(sb, "PIO %dbytes", sata->bytecount);
2231 sbuf_printf(sb, ")");
2233 sbuf_printf(sb, "\n");
2237 ata_proto_announce_sbuf(struct cam_ed *device, struct sbuf *sb)
2239 ata_print_ident_sbuf(&device->ident_data, sb);
2243 ata_proto_announce(struct cam_ed *device)
2245 ata_print_ident(&device->ident_data);
2249 ata_proto_denounce(struct cam_ed *device)
2251 ata_print_ident_short(&device->ident_data);
2255 ata_proto_denounce_sbuf(struct cam_ed *device, struct sbuf *sb)
2257 ata_print_ident_short_sbuf(&device->ident_data, sb);
2261 semb_proto_announce_sbuf(struct cam_ed *device, struct sbuf *sb)
2263 semb_print_ident_sbuf((struct sep_identify_data *)&device->ident_data, sb);
2267 semb_proto_announce(struct cam_ed *device)
2269 semb_print_ident((struct sep_identify_data *)&device->ident_data);
2273 semb_proto_denounce(struct cam_ed *device)
2275 semb_print_ident_short((struct sep_identify_data *)&device->ident_data);
2279 semb_proto_denounce_sbuf(struct cam_ed *device, struct sbuf *sb)
2281 semb_print_ident_short_sbuf((struct sep_identify_data *)&device->ident_data, sb);
2285 ata_proto_debug_out(union ccb *ccb)
2287 char cdb_str[(sizeof(struct ata_cmd) * 3) + 1];
2289 if (ccb->ccb_h.func_code != XPT_ATA_IO)
2292 CAM_DEBUG(ccb->ccb_h.path,
2293 CAM_DEBUG_CDB,("%s. ACB: %s\n", ata_op_string(&ccb->ataio.cmd),
2294 ata_cmd_string(&ccb->ataio.cmd, cdb_str, sizeof(cdb_str))));