2 * SPDX-License-Identifier: BSD-2-Clause
4 * Copyright (c) 2009 Alexander Motin <mav@FreeBSD.org>
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer,
12 * without modification, immediately at the beginning of the file.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 #include <sys/param.h>
31 #include <sys/endian.h>
32 #include <sys/systm.h>
33 #include <sys/types.h>
34 #include <sys/malloc.h>
35 #include <sys/kernel.h>
38 #include <sys/fcntl.h>
41 #include <sys/eventhandler.h>
43 #include <sys/mutex.h>
44 #include <sys/sysctl.h>
47 #include <cam/cam_ccb.h>
48 #include <cam/cam_queue.h>
49 #include <cam/cam_periph.h>
50 #include <cam/cam_sim.h>
51 #include <cam/cam_xpt.h>
52 #include <cam/cam_xpt_sim.h>
53 #include <cam/cam_xpt_periph.h>
54 #include <cam/cam_xpt_internal.h>
55 #include <cam/cam_debug.h>
57 #include <cam/scsi/scsi_all.h>
58 #include <cam/scsi/scsi_message.h>
59 #include <cam/ata/ata_all.h>
60 #include <machine/stdarg.h> /* for xpt_print below */
62 struct ata_quirk_entry {
63 struct scsi_inquiry_pattern inq_pat;
65 #define CAM_QUIRK_MAXTAGS 0x01
70 static periph_init_t aprobe_periph_init;
72 static struct periph_driver aprobe_driver =
74 aprobe_periph_init, "aprobe",
75 TAILQ_HEAD_INITIALIZER(aprobe_driver.units), /* generation */ 0,
79 PERIPHDRIVER_DECLARE(aprobe, aprobe_driver);
101 static char *probe_action_text[] = {
112 "PROBE_FULL_INQUIRY",
115 "PROBE_IDENTIFY_SES",
116 "PROBE_IDENTIFY_SAFTE",
121 #define PROBE_SET_ACTION(softc, newaction) \
124 text = probe_action_text; \
125 CAM_DEBUG((softc)->periph->path, CAM_DEBUG_PROBE, \
126 ("Probe %s to %s\n", text[(softc)->action], \
127 text[(newaction)])); \
128 (softc)->action = (newaction); \
132 PROBE_NO_ANNOUNCE = 0x04
136 TAILQ_HEAD(, ccb_hdr) request_ccbs;
137 struct ata_params ident_data;
138 aprobe_action action;
146 struct cam_periph *periph;
149 static struct ata_quirk_entry ata_quirk_table[] =
152 /* Default tagged queuing parameters for all devices */
154 T_ANY, SIP_MEDIA_REMOVABLE|SIP_MEDIA_FIXED,
155 /*vendor*/"*", /*product*/"*", /*revision*/"*"
157 /*quirks*/0, /*mintags*/0, /*maxtags*/0
161 static cam_status aproberegister(struct cam_periph *periph, void *arg);
162 static void aprobeschedule(struct cam_periph *probe_periph);
163 static void aprobestart(struct cam_periph *periph, union ccb *start_ccb);
164 static void aproberequestdefaultnegotiation(struct cam_periph *periph);
165 static void aprobedone(struct cam_periph *periph, union ccb *done_ccb);
166 static void aprobecleanup(struct cam_periph *periph);
167 static void ata_find_quirk(struct cam_ed *device);
168 static void ata_scan_bus(struct cam_periph *periph, union ccb *ccb);
169 static void ata_scan_lun(struct cam_periph *periph,
170 struct cam_path *path, cam_flags flags,
172 static void axptscandone(struct cam_periph *periph, union ccb *done_ccb);
173 static struct cam_ed *
174 ata_alloc_device(struct cam_eb *bus, struct cam_et *target,
176 static void ata_device_transport(struct cam_path *path);
177 static void ata_get_transfer_settings(struct ccb_trans_settings *cts);
178 static void ata_set_transfer_settings(struct ccb_trans_settings *cts,
179 struct cam_path *path,
181 static void ata_dev_async(uint32_t async_code,
183 struct cam_et *target,
184 struct cam_ed *device,
186 static void ata_action(union ccb *start_ccb);
187 static void ata_announce_periph_sbuf(struct cam_periph *periph, struct sbuf *sb);
188 static void ata_proto_announce_sbuf(struct cam_ed *device, struct sbuf *sb);
189 static void ata_proto_denounce_sbuf(struct cam_ed *device, struct sbuf *sb);
190 static void ata_proto_debug_out(union ccb *ccb);
191 static void semb_proto_announce_sbuf(struct cam_ed *device, struct sbuf *sb);
192 static void semb_proto_denounce_sbuf(struct cam_ed *device, struct sbuf *sb);
194 static int ata_dma = 1;
195 static int atapi_dma = 1;
197 TUNABLE_INT("hw.ata.ata_dma", &ata_dma);
198 TUNABLE_INT("hw.ata.atapi_dma", &atapi_dma);
200 static struct xpt_xport_ops ata_xport_ops = {
201 .alloc_device = ata_alloc_device,
202 .action = ata_action,
203 .async = ata_dev_async,
204 .announce_sbuf = ata_announce_periph_sbuf,
206 #define ATA_XPT_XPORT(x, X) \
207 static struct xpt_xport ata_xport_ ## x = { \
208 .xport = XPORT_ ## X, \
210 .ops = &ata_xport_ops, \
212 CAM_XPT_XPORT(ata_xport_ ## x);
214 ATA_XPT_XPORT(ata, ATA);
215 ATA_XPT_XPORT(sata, SATA);
217 #undef ATA_XPORT_XPORT
219 static struct xpt_proto_ops ata_proto_ops_ata = {
220 .announce_sbuf = ata_proto_announce_sbuf,
221 .denounce_sbuf = ata_proto_denounce_sbuf,
222 .debug_out = ata_proto_debug_out,
224 static struct xpt_proto ata_proto_ata = {
227 .ops = &ata_proto_ops_ata,
230 static struct xpt_proto_ops ata_proto_ops_satapm = {
231 .announce_sbuf = ata_proto_announce_sbuf,
232 .denounce_sbuf = ata_proto_denounce_sbuf,
233 .debug_out = ata_proto_debug_out,
235 static struct xpt_proto ata_proto_satapm = {
236 .proto = PROTO_SATAPM,
238 .ops = &ata_proto_ops_satapm,
241 static struct xpt_proto_ops ata_proto_ops_semb = {
242 .announce_sbuf = semb_proto_announce_sbuf,
243 .denounce_sbuf = semb_proto_denounce_sbuf,
244 .debug_out = ata_proto_debug_out,
246 static struct xpt_proto ata_proto_semb = {
249 .ops = &ata_proto_ops_semb,
252 CAM_XPT_PROTO(ata_proto_ata);
253 CAM_XPT_PROTO(ata_proto_satapm);
254 CAM_XPT_PROTO(ata_proto_semb);
257 aprobe_periph_init(void)
262 aproberegister(struct cam_periph *periph, void *arg)
264 union ccb *request_ccb; /* CCB representing the probe request */
267 request_ccb = (union ccb *)arg;
268 if (request_ccb == NULL) {
269 printf("proberegister: no probe CCB, "
270 "can't register device\n");
271 return(CAM_REQ_CMP_ERR);
274 softc = (aprobe_softc *)malloc(sizeof(*softc), M_CAMXPT, M_ZERO | M_NOWAIT);
277 printf("proberegister: Unable to probe new device. "
278 "Unable to allocate softc\n");
279 return(CAM_REQ_CMP_ERR);
281 TAILQ_INIT(&softc->request_ccbs);
282 TAILQ_INSERT_TAIL(&softc->request_ccbs, &request_ccb->ccb_h,
285 periph->softc = softc;
286 softc->periph = periph;
287 softc->action = PROBE_INVALID;
288 if (cam_periph_acquire(periph) != 0)
289 return (CAM_REQ_CMP_ERR);
291 CAM_DEBUG(periph->path, CAM_DEBUG_PROBE, ("Probe started\n"));
292 ata_device_transport(periph->path);
293 aprobeschedule(periph);
298 aprobeschedule(struct cam_periph *periph)
303 softc = (aprobe_softc *)periph->softc;
304 ccb = (union ccb *)TAILQ_FIRST(&softc->request_ccbs);
306 if ((periph->path->device->flags & CAM_DEV_UNCONFIGURED) ||
307 periph->path->device->protocol == PROTO_SATAPM ||
308 periph->path->device->protocol == PROTO_SEMB)
309 PROBE_SET_ACTION(softc, PROBE_RESET);
311 PROBE_SET_ACTION(softc, PROBE_IDENTIFY);
313 if (ccb->crcn.flags & CAM_EXPECT_INQ_CHANGE)
314 softc->flags |= PROBE_NO_ANNOUNCE;
316 softc->flags &= ~PROBE_NO_ANNOUNCE;
318 xpt_schedule(periph, CAM_PRIORITY_XPT);
322 aprobestart(struct cam_periph *periph, union ccb *start_ccb)
324 struct ccb_trans_settings cts;
325 struct ccb_ataio *ataio;
326 struct ccb_scsiio *csio;
328 struct cam_path *path;
329 struct ata_params *ident_buf;
332 CAM_DEBUG(start_ccb->ccb_h.path, CAM_DEBUG_TRACE, ("aprobestart\n"));
334 softc = (aprobe_softc *)periph->softc;
335 path = start_ccb->ccb_h.path;
336 ataio = &start_ccb->ataio;
337 csio = &start_ccb->csio;
338 ident_buf = &periph->path->device->ident_data;
340 if (softc->restart) {
342 if ((path->device->flags & CAM_DEV_UNCONFIGURED) ||
343 path->device->protocol == PROTO_SATAPM ||
344 path->device->protocol == PROTO_SEMB)
345 softc->action = PROBE_RESET;
347 softc->action = PROBE_IDENTIFY;
349 switch (softc->action) {
351 cam_fill_ataio(ataio,
354 /*flags*/CAM_DIR_NONE,
359 ata_reset_cmd(ataio);
362 cam_fill_ataio(ataio,
367 /*data_ptr*/(uint8_t *)&softc->ident_data,
368 /*dxfer_len*/sizeof(softc->ident_data),
370 if (path->device->protocol == PROTO_ATA)
371 ata_28bit_cmd(ataio, ATA_ATA_IDENTIFY, 0, 0, 0);
373 ata_28bit_cmd(ataio, ATA_ATAPI_IDENTIFY, 0, 0, 0);
377 xpt_print(path, "Spinning up device\n");
378 cam_fill_ataio(ataio,
381 /*flags*/CAM_DIR_NONE | CAM_HIGH_POWER,
386 ata_28bit_cmd(ataio, ATA_SETFEATURES, ATA_SF_PUIS_SPINUP, 0, 0);
393 /* Fetch user modes from SIM. */
394 bzero(&cts, sizeof(cts));
395 xpt_setup_ccb(&cts.ccb_h, path, CAM_PRIORITY_NONE);
396 cts.ccb_h.func_code = XPT_GET_TRAN_SETTINGS;
397 cts.type = CTS_TYPE_USER_SETTINGS;
398 xpt_action((union ccb *)&cts);
399 if (path->device->transport == XPORT_ATA) {
400 if (cts.xport_specific.ata.valid & CTS_ATA_VALID_MODE)
401 mode = cts.xport_specific.ata.mode;
403 if (cts.xport_specific.sata.valid & CTS_SATA_VALID_MODE)
404 mode = cts.xport_specific.sata.mode;
406 if (path->device->protocol == PROTO_ATA) {
407 if (ata_dma == 0 && (mode == 0 || mode > ATA_PIO_MAX))
410 if (atapi_dma == 0 && (mode == 0 || mode > ATA_PIO_MAX))
414 /* Honor device capabilities. */
415 wantmode = mode = ata_max_mode(ident_buf, mode);
416 /* Report modes to SIM. */
417 bzero(&cts, sizeof(cts));
418 xpt_setup_ccb(&cts.ccb_h, path, CAM_PRIORITY_NONE);
419 cts.ccb_h.func_code = XPT_SET_TRAN_SETTINGS;
420 cts.type = CTS_TYPE_CURRENT_SETTINGS;
421 if (path->device->transport == XPORT_ATA) {
422 cts.xport_specific.ata.mode = mode;
423 cts.xport_specific.ata.valid = CTS_ATA_VALID_MODE;
425 cts.xport_specific.sata.mode = mode;
426 cts.xport_specific.sata.valid = CTS_SATA_VALID_MODE;
428 xpt_action((union ccb *)&cts);
429 /* Fetch current modes from SIM. */
430 bzero(&cts, sizeof(cts));
431 xpt_setup_ccb(&cts.ccb_h, path, CAM_PRIORITY_NONE);
432 cts.ccb_h.func_code = XPT_GET_TRAN_SETTINGS;
433 cts.type = CTS_TYPE_CURRENT_SETTINGS;
434 xpt_action((union ccb *)&cts);
435 if (path->device->transport == XPORT_ATA) {
436 if (cts.xport_specific.ata.valid & CTS_ATA_VALID_MODE)
437 mode = cts.xport_specific.ata.mode;
439 if (cts.xport_specific.sata.valid & CTS_SATA_VALID_MODE)
440 mode = cts.xport_specific.sata.mode;
442 /* If SIM disagree - renegotiate. */
443 if (mode != wantmode)
445 /* Remember what transport thinks about DMA. */
446 oif = path->device->inq_flags;
448 path->device->inq_flags &= ~SID_DMA;
450 path->device->inq_flags |= SID_DMA;
451 if (path->device->inq_flags != oif)
452 xpt_async(AC_GETDEV_CHANGED, path, NULL);
453 cam_fill_ataio(ataio,
456 /*flags*/CAM_DIR_NONE,
461 ata_28bit_cmd(ataio, ATA_SETFEATURES, ATA_SF_SETXFER, 0, mode);
465 cam_fill_ataio(ataio,
473 ata_28bit_cmd(ataio, ATA_SETFEATURES,
474 (softc->caps & CTS_SATA_CAPS_H_PMREQ) ? 0x10 : 0x90,
478 cam_fill_ataio(ataio,
486 ata_28bit_cmd(ataio, ATA_SETFEATURES,
487 (softc->caps & CTS_SATA_CAPS_H_APST) ? 0x10 : 0x90,
491 cam_fill_ataio(ataio,
499 ata_28bit_cmd(ataio, ATA_SETFEATURES,
500 (softc->caps & CTS_SATA_CAPS_H_DMAAA) ? 0x10 : 0x90,
504 /* Remember what transport thinks about AEN. */
505 oif = path->device->inq_flags;
506 if (softc->caps & CTS_SATA_CAPS_H_AN)
507 path->device->inq_flags |= SID_AEN;
509 path->device->inq_flags &= ~SID_AEN;
510 if (path->device->inq_flags != oif)
511 xpt_async(AC_GETDEV_CHANGED, path, NULL);
512 cam_fill_ataio(ataio,
520 ata_28bit_cmd(ataio, ATA_SETFEATURES,
521 (softc->caps & CTS_SATA_CAPS_H_AN) ? 0x10 : 0x90,
524 case PROBE_SET_MULTI:
526 u_int sectors, bytecount;
528 bytecount = 8192; /* SATA maximum */
529 /* Fetch user bytecount from SIM. */
530 bzero(&cts, sizeof(cts));
531 xpt_setup_ccb(&cts.ccb_h, path, CAM_PRIORITY_NONE);
532 cts.ccb_h.func_code = XPT_GET_TRAN_SETTINGS;
533 cts.type = CTS_TYPE_USER_SETTINGS;
534 xpt_action((union ccb *)&cts);
535 if (path->device->transport == XPORT_ATA) {
536 if (cts.xport_specific.ata.valid & CTS_ATA_VALID_BYTECOUNT)
537 bytecount = cts.xport_specific.ata.bytecount;
539 if (cts.xport_specific.sata.valid & CTS_SATA_VALID_BYTECOUNT)
540 bytecount = cts.xport_specific.sata.bytecount;
542 /* Honor device capabilities. */
543 sectors = max(1, min(ident_buf->sectors_intr & 0xff,
544 bytecount / ata_logical_sector_size(ident_buf)));
545 /* Report bytecount to SIM. */
546 bzero(&cts, sizeof(cts));
547 xpt_setup_ccb(&cts.ccb_h, path, CAM_PRIORITY_NONE);
548 cts.ccb_h.func_code = XPT_SET_TRAN_SETTINGS;
549 cts.type = CTS_TYPE_CURRENT_SETTINGS;
550 if (path->device->transport == XPORT_ATA) {
551 cts.xport_specific.ata.bytecount = sectors *
552 ata_logical_sector_size(ident_buf);
553 cts.xport_specific.ata.valid = CTS_ATA_VALID_BYTECOUNT;
555 cts.xport_specific.sata.bytecount = sectors *
556 ata_logical_sector_size(ident_buf);
557 cts.xport_specific.sata.valid = CTS_SATA_VALID_BYTECOUNT;
559 xpt_action((union ccb *)&cts);
560 /* Fetch current bytecount from SIM. */
561 bzero(&cts, sizeof(cts));
562 xpt_setup_ccb(&cts.ccb_h, path, CAM_PRIORITY_NONE);
563 cts.ccb_h.func_code = XPT_GET_TRAN_SETTINGS;
564 cts.type = CTS_TYPE_CURRENT_SETTINGS;
565 xpt_action((union ccb *)&cts);
566 if (path->device->transport == XPORT_ATA) {
567 if (cts.xport_specific.ata.valid & CTS_ATA_VALID_BYTECOUNT)
568 bytecount = cts.xport_specific.ata.bytecount;
570 if (cts.xport_specific.sata.valid & CTS_SATA_VALID_BYTECOUNT)
571 bytecount = cts.xport_specific.sata.bytecount;
573 sectors = bytecount / ata_logical_sector_size(ident_buf);
575 cam_fill_ataio(ataio,
583 ata_28bit_cmd(ataio, ATA_SET_MULTI, 0, 0, sectors);
590 bytecount = 8192; /* SATA maximum */
591 /* Fetch user bytecount from SIM. */
592 bzero(&cts, sizeof(cts));
593 xpt_setup_ccb(&cts.ccb_h, path, CAM_PRIORITY_NONE);
594 cts.ccb_h.func_code = XPT_GET_TRAN_SETTINGS;
595 cts.type = CTS_TYPE_USER_SETTINGS;
596 xpt_action((union ccb *)&cts);
597 if (path->device->transport == XPORT_ATA) {
598 if (cts.xport_specific.ata.valid & CTS_ATA_VALID_BYTECOUNT)
599 bytecount = cts.xport_specific.ata.bytecount;
601 if (cts.xport_specific.sata.valid & CTS_SATA_VALID_BYTECOUNT)
602 bytecount = cts.xport_specific.sata.bytecount;
604 /* Honor device capabilities. */
606 bytecount = max(2, min(65534, bytecount));
607 if (ident_buf->satacapabilities != 0x0000 &&
608 ident_buf->satacapabilities != 0xffff) {
609 bytecount = min(8192, bytecount);
611 /* Report bytecount to SIM. */
612 bzero(&cts, sizeof(cts));
613 xpt_setup_ccb(&cts.ccb_h, path, CAM_PRIORITY_NONE);
614 cts.ccb_h.func_code = XPT_SET_TRAN_SETTINGS;
615 cts.type = CTS_TYPE_CURRENT_SETTINGS;
616 if (path->device->transport == XPORT_ATA) {
617 cts.xport_specific.ata.bytecount = bytecount;
618 cts.xport_specific.ata.valid = CTS_ATA_VALID_BYTECOUNT;
620 cts.xport_specific.sata.bytecount = bytecount;
621 cts.xport_specific.sata.valid = CTS_SATA_VALID_BYTECOUNT;
623 xpt_action((union ccb *)&cts);
626 case PROBE_FULL_INQUIRY:
629 struct scsi_inquiry_data *inq_buf =
630 &path->device->inq_data;
632 if (softc->action == PROBE_INQUIRY)
633 inquiry_len = SHORT_INQUIRY_LENGTH;
635 inquiry_len = SID_ADDITIONAL_LENGTH(inq_buf);
637 * Some parallel SCSI devices fail to send an
638 * ignore wide residue message when dealing with
639 * odd length inquiry requests. Round up to be
642 inquiry_len = roundup2(inquiry_len, 2);
652 /*timeout*/60 * 1000);
656 cam_fill_ataio(ataio,
659 /*flags*/CAM_DIR_NONE,
664 ata_pm_read_cmd(ataio, 0, 15);
667 cam_fill_ataio(ataio,
670 /*flags*/CAM_DIR_NONE,
675 ata_pm_read_cmd(ataio, 1, 15);
677 case PROBE_IDENTIFY_SES:
678 cam_fill_ataio(ataio,
683 /*data_ptr*/(uint8_t *)&softc->ident_data,
684 /*dxfer_len*/sizeof(softc->ident_data),
686 ata_28bit_cmd(ataio, ATA_SEP_ATTN, 0xEC, 0x02,
687 sizeof(softc->ident_data) / 4);
689 case PROBE_IDENTIFY_SAFTE:
690 cam_fill_ataio(ataio,
695 /*data_ptr*/(uint8_t *)&softc->ident_data,
696 /*dxfer_len*/sizeof(softc->ident_data),
698 ata_28bit_cmd(ataio, ATA_SEP_ATTN, 0xEC, 0x00,
699 sizeof(softc->ident_data) / 4);
702 panic("aprobestart: invalid action state 0x%x\n", softc->action);
704 start_ccb->ccb_h.flags |= CAM_DEV_QFREEZE;
705 xpt_action(start_ccb);
709 aproberequestdefaultnegotiation(struct cam_periph *periph)
711 struct ccb_trans_settings cts;
713 bzero(&cts, sizeof(cts));
714 xpt_setup_ccb(&cts.ccb_h, periph->path, CAM_PRIORITY_NONE);
715 cts.ccb_h.func_code = XPT_GET_TRAN_SETTINGS;
716 cts.type = CTS_TYPE_USER_SETTINGS;
717 xpt_action((union ccb *)&cts);
718 if ((cts.ccb_h.status & CAM_STATUS_MASK) != CAM_REQ_CMP)
720 cts.xport_specific.valid = 0;
721 cts.ccb_h.func_code = XPT_SET_TRAN_SETTINGS;
722 cts.type = CTS_TYPE_CURRENT_SETTINGS;
723 xpt_action((union ccb *)&cts);
727 aprobedone(struct cam_periph *periph, union ccb *done_ccb)
729 struct ccb_trans_settings cts;
730 struct ata_params *ident_buf;
731 struct scsi_inquiry_data *inq_buf;
733 struct cam_path *path;
737 int changed, found = 1;
738 static const uint8_t fake_device_id_hdr[8] =
739 {0, SVPD_DEVICE_ID, 0, 12,
740 SVPD_ID_CODESET_BINARY, SVPD_ID_TYPE_NAA, 0, 8};
742 CAM_DEBUG(done_ccb->ccb_h.path, CAM_DEBUG_TRACE, ("aprobedone\n"));
744 softc = (aprobe_softc *)periph->softc;
745 path = done_ccb->ccb_h.path;
746 priority = done_ccb->ccb_h.pinfo.priority;
747 ident_buf = &path->device->ident_data;
748 inq_buf = &path->device->inq_data;
750 if ((done_ccb->ccb_h.status & CAM_STATUS_MASK) != CAM_REQ_CMP) {
751 if (cam_periph_error(done_ccb,
752 0, softc->restart ? (SF_NO_RECOVERY | SF_NO_RETRY) : 0
755 /* Drop freeze taken due to CAM_DEV_QFREEZE flag set. */
756 cam_release_devq(path, 0, 0, 0, FALSE);
759 if ((done_ccb->ccb_h.status & CAM_DEV_QFRZN) != 0) {
760 /* Don't wedge the queue */
761 xpt_release_devq(path, /*count*/1, /*run_queue*/TRUE);
763 status = done_ccb->ccb_h.status & CAM_STATUS_MASK;
764 if (softc->restart) {
766 if ((done_ccb->ccb_h.status & CAM_STATUS_MASK) ==
769 if (softc->faults < 10)
774 /* Old PIO2 devices may not support mode setting. */
775 } else if (softc->action == PROBE_SETMODE &&
776 status == CAM_ATA_STATUS_ERROR &&
777 ata_max_pmode(ident_buf) <= ATA_PIO2 &&
778 (ident_buf->capabilities1 & ATA_SUPPORT_IORDY) == 0) {
782 * Some old WD SATA disks report supported and enabled
783 * device-initiated interface power management, but return
784 * ABORT on attempt to disable it.
786 } else if (softc->action == PROBE_SETPM &&
787 status == CAM_ATA_STATUS_ERROR) {
791 * Some old WD SATA disks have broken SPINUP handling.
792 * If we really fail to spin up the disk, then there will be
793 * some media access errors later on, but at least we will
794 * have a device to interact with for recovery attempts.
796 } else if (softc->action == PROBE_SPINUP &&
797 status == CAM_ATA_STATUS_ERROR) {
801 * Some HP SATA disks report supported DMA Auto-Activation,
802 * but return ABORT on attempt to enable it.
804 } else if (softc->action == PROBE_SETDMAAA &&
805 status == CAM_ATA_STATUS_ERROR) {
809 * SES and SAF-TE SEPs have different IDENTIFY commands,
810 * but SATA specification doesn't tell how to identify them.
811 * Until better way found, just try another if first fail.
813 } else if (softc->action == PROBE_IDENTIFY_SES &&
814 status == CAM_ATA_STATUS_ERROR) {
815 PROBE_SET_ACTION(softc, PROBE_IDENTIFY_SAFTE);
816 xpt_release_ccb(done_ccb);
817 xpt_schedule(periph, priority);
822 * If we get to this point, we got an error status back
823 * from the inquiry and the error status doesn't require
824 * automatically retrying the command. Therefore, the
825 * inquiry failed. If we had inquiry information before
826 * for this device, but this latest inquiry command failed,
827 * the device has probably gone away. If this device isn't
828 * already marked unconfigured, notify the peripheral
829 * drivers that this device is no more.
831 device_fail: if ((path->device->flags & CAM_DEV_UNCONFIGURED) == 0)
832 xpt_async(AC_LOST_DEVICE, path, NULL);
833 PROBE_SET_ACTION(softc, PROBE_INVALID);
840 switch (softc->action) {
843 int sign = (done_ccb->ataio.res.lba_high << 8) +
844 done_ccb->ataio.res.lba_mid;
845 CAM_DEBUG(path, CAM_DEBUG_PROBE,
846 ("SIGNATURE: %04x\n", sign));
847 if (sign == 0x0000 &&
848 done_ccb->ccb_h.target_id != 15) {
849 path->device->protocol = PROTO_ATA;
850 PROBE_SET_ACTION(softc, PROBE_IDENTIFY);
851 } else if (sign == 0x9669 &&
852 done_ccb->ccb_h.target_id == 15) {
853 /* Report SIM that PM is present. */
854 bzero(&cts, sizeof(cts));
855 xpt_setup_ccb(&cts.ccb_h, path, CAM_PRIORITY_NONE);
856 cts.ccb_h.func_code = XPT_SET_TRAN_SETTINGS;
857 cts.type = CTS_TYPE_CURRENT_SETTINGS;
858 cts.xport_specific.sata.pm_present = 1;
859 cts.xport_specific.sata.valid = CTS_SATA_VALID_PM;
860 xpt_action((union ccb *)&cts);
861 path->device->protocol = PROTO_SATAPM;
862 PROBE_SET_ACTION(softc, PROBE_PM_PID);
863 } else if (sign == 0xc33c &&
864 done_ccb->ccb_h.target_id != 15) {
865 path->device->protocol = PROTO_SEMB;
866 PROBE_SET_ACTION(softc, PROBE_IDENTIFY_SES);
867 } else if (sign == 0xeb14 &&
868 done_ccb->ccb_h.target_id != 15) {
869 path->device->protocol = PROTO_SCSI;
870 PROBE_SET_ACTION(softc, PROBE_IDENTIFY);
872 if (done_ccb->ccb_h.target_id != 15) {
874 "Unexpected signature 0x%04x\n", sign);
878 xpt_release_ccb(done_ccb);
879 xpt_schedule(periph, priority);
884 struct ccb_pathinq cpi;
888 * Convert to host byte order, and fix the strings.
890 ident_buf = &softc->ident_data;
891 ata_param_fixup(ident_buf);
894 * Allow others to veto this ATA disk attachment. This
895 * is mainly used by VMs, whose disk controllers may
896 * share the disks with the simulated ATA controllers.
898 EVENTHANDLER_INVOKE(ada_probe_veto, path, ident_buf, &veto);
903 /* Device may need spin-up before IDENTIFY become valid. */
904 if ((ident_buf->specconf == 0x37c8 ||
905 ident_buf->specconf == 0x738c) &&
906 ((ident_buf->config & ATA_RESP_INCOMPLETE) ||
907 softc->spinup == 0)) {
908 PROBE_SET_ACTION(softc, PROBE_SPINUP);
909 xpt_release_ccb(done_ccb);
910 xpt_schedule(periph, priority);
913 ident_buf = &path->device->ident_data;
915 /* Check that it is the same device as we know. */
916 if ((periph->path->device->flags & CAM_DEV_UNCONFIGURED) == 0) {
917 if (bcmp(softc->ident_data.model, ident_buf->model,
918 sizeof(ident_buf->model)) ||
919 bcmp(softc->ident_data.serial, ident_buf->serial,
920 sizeof(ident_buf->serial))) {
921 /* The device was replaced. */
923 xpt_async(AC_LOST_DEVICE, path, NULL);
924 } else if (bcmp(&softc->ident_data, ident_buf,
925 sizeof(*ident_buf))) {
926 /* The device is the same, but has changed. */
929 /* Nothing has changed. */
933 /* This is a new device. */
938 bcopy(&softc->ident_data, ident_buf, sizeof(struct ata_params));
940 /* Clean up from previous instance of this device */
941 if (path->device->serial_num != NULL) {
942 free(path->device->serial_num, M_CAMXPT);
943 path->device->serial_num = NULL;
944 path->device->serial_num_len = 0;
946 if (path->device->device_id != NULL) {
947 free(path->device->device_id, M_CAMXPT);
948 path->device->device_id = NULL;
949 path->device->device_id_len = 0;
951 path->device->serial_num =
952 (uint8_t *)malloc((sizeof(ident_buf->serial) + 1),
954 if (path->device->serial_num != NULL) {
955 bcopy(ident_buf->serial,
956 path->device->serial_num,
957 sizeof(ident_buf->serial));
958 path->device->serial_num[sizeof(ident_buf->serial)]
960 path->device->serial_num_len =
961 strlen(path->device->serial_num);
963 if (ident_buf->enabled.extension &
964 ATA_SUPPORT_64BITWWN) {
965 path->device->device_id =
966 malloc(16, M_CAMXPT, M_NOWAIT);
967 if (path->device->device_id != NULL) {
968 path->device->device_id_len = 16;
969 bcopy(&fake_device_id_hdr,
970 path->device->device_id, 8);
971 bcopy(ident_buf->wwn,
972 path->device->device_id + 8, 8);
973 ata_bswap(path->device->device_id + 8, 8);
976 path->device->flags |= CAM_DEV_IDENTIFY_DATA_VALID;
979 xpt_async(AC_GETDEV_CHANGED, path, NULL);
980 if (ident_buf->satacapabilities & ATA_SUPPORT_NCQ) {
981 path->device->mintags = 2;
982 path->device->maxtags =
983 ATA_QUEUE_LEN(ident_buf->queue) + 1;
985 ata_find_quirk(path->device);
986 if (path->device->mintags != 0 &&
987 path->bus->sim->max_tagged_dev_openings != 0) {
988 /* Check if the SIM does not want queued commands. */
989 xpt_path_inq(&cpi, path);
990 if (cam_ccb_success((union ccb *)&cpi) &&
991 (cpi.hba_inquiry & PI_TAG_ABLE)) {
992 /* Report SIM which tags are allowed. */
993 bzero(&cts, sizeof(cts));
994 xpt_setup_ccb(&cts.ccb_h, path, CAM_PRIORITY_NONE);
995 cts.ccb_h.func_code = XPT_SET_TRAN_SETTINGS;
996 cts.type = CTS_TYPE_CURRENT_SETTINGS;
997 cts.xport_specific.sata.tags = path->device->maxtags;
998 cts.xport_specific.sata.valid = CTS_SATA_VALID_TAGS;
999 xpt_action((union ccb *)&cts);
1002 ata_device_transport(path);
1004 aproberequestdefaultnegotiation(periph);
1005 PROBE_SET_ACTION(softc, PROBE_SETMODE);
1006 xpt_release_ccb(done_ccb);
1007 xpt_schedule(periph, priority);
1012 xpt_print(path, "Spin-up done\n");
1014 PROBE_SET_ACTION(softc, PROBE_IDENTIFY);
1015 xpt_release_ccb(done_ccb);
1016 xpt_schedule(periph, priority);
1019 /* Set supported bits. */
1020 bzero(&cts, sizeof(cts));
1021 xpt_setup_ccb(&cts.ccb_h, path, CAM_PRIORITY_NONE);
1022 cts.ccb_h.func_code = XPT_GET_TRAN_SETTINGS;
1023 cts.type = CTS_TYPE_CURRENT_SETTINGS;
1024 xpt_action((union ccb *)&cts);
1025 if (path->device->transport == XPORT_SATA &&
1026 cts.xport_specific.sata.valid & CTS_SATA_VALID_CAPS)
1027 caps = cts.xport_specific.sata.caps & CTS_SATA_CAPS_H;
1028 else if (path->device->transport == XPORT_ATA &&
1029 cts.xport_specific.ata.valid & CTS_ATA_VALID_CAPS)
1030 caps = cts.xport_specific.ata.caps & CTS_ATA_CAPS_H;
1033 if (path->device->transport == XPORT_SATA &&
1034 ident_buf->satacapabilities != 0xffff) {
1035 if (ident_buf->satacapabilities & ATA_SUPPORT_IFPWRMNGTRCV)
1036 caps |= CTS_SATA_CAPS_D_PMREQ;
1037 if (ident_buf->satacapabilities & ATA_SUPPORT_HAPST)
1038 caps |= CTS_SATA_CAPS_D_APST;
1040 /* Mask unwanted 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_USER_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;
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;
1055 * Remember what transport thinks about 48-bit DMA. If
1056 * capability information is not provided or transport is
1057 * SATA, we take support for granted.
1059 oif = path->device->inq_flags;
1060 if (!(path->device->inq_flags & SID_DMA) ||
1061 (path->device->transport == XPORT_ATA &&
1062 (cts.xport_specific.ata.valid & CTS_ATA_VALID_CAPS) &&
1063 !(caps & CTS_ATA_CAPS_H_DMA48)))
1064 path->device->inq_flags &= ~SID_DMA48;
1066 path->device->inq_flags |= SID_DMA48;
1067 if (path->device->inq_flags != oif)
1068 xpt_async(AC_GETDEV_CHANGED, path, NULL);
1069 /* Store result to SIM. */
1070 bzero(&cts, sizeof(cts));
1071 xpt_setup_ccb(&cts.ccb_h, path, CAM_PRIORITY_NONE);
1072 cts.ccb_h.func_code = XPT_SET_TRAN_SETTINGS;
1073 cts.type = CTS_TYPE_CURRENT_SETTINGS;
1074 if (path->device->transport == XPORT_SATA) {
1075 cts.xport_specific.sata.caps = caps;
1076 cts.xport_specific.sata.valid = CTS_SATA_VALID_CAPS;
1078 cts.xport_specific.ata.caps = caps;
1079 cts.xport_specific.ata.valid = CTS_ATA_VALID_CAPS;
1081 xpt_action((union ccb *)&cts);
1083 if (path->device->transport != XPORT_SATA)
1085 if ((ident_buf->satasupport & ATA_SUPPORT_IFPWRMNGT) &&
1086 (!(softc->caps & CTS_SATA_CAPS_H_PMREQ)) !=
1087 (!(ident_buf->sataenabled & ATA_SUPPORT_IFPWRMNGT))) {
1088 PROBE_SET_ACTION(softc, PROBE_SETPM);
1089 xpt_release_ccb(done_ccb);
1090 xpt_schedule(periph, priority);
1095 if (ident_buf->satacapabilities != 0xffff &&
1096 (ident_buf->satacapabilities & ATA_SUPPORT_DAPST) &&
1097 (!(softc->caps & CTS_SATA_CAPS_H_APST)) !=
1098 (!(ident_buf->sataenabled & ATA_ENABLED_DAPST))) {
1099 PROBE_SET_ACTION(softc, PROBE_SETAPST);
1100 xpt_release_ccb(done_ccb);
1101 xpt_schedule(periph, priority);
1106 if ((ident_buf->satasupport & ATA_SUPPORT_AUTOACTIVATE) &&
1107 (!(softc->caps & CTS_SATA_CAPS_H_DMAAA)) !=
1108 (!(ident_buf->sataenabled & ATA_SUPPORT_AUTOACTIVATE))) {
1109 PROBE_SET_ACTION(softc, PROBE_SETDMAAA);
1110 xpt_release_ccb(done_ccb);
1111 xpt_schedule(periph, priority);
1115 case PROBE_SETDMAAA:
1116 if (path->device->protocol != PROTO_ATA &&
1117 (ident_buf->satasupport & ATA_SUPPORT_ASYNCNOTIF) &&
1118 (!(softc->caps & CTS_SATA_CAPS_H_AN)) !=
1119 (!(ident_buf->sataenabled & ATA_SUPPORT_ASYNCNOTIF))) {
1120 PROBE_SET_ACTION(softc, PROBE_SETAN);
1121 xpt_release_ccb(done_ccb);
1122 xpt_schedule(periph, priority);
1128 if (path->device->protocol == PROTO_ATA) {
1129 PROBE_SET_ACTION(softc, PROBE_SET_MULTI);
1131 PROBE_SET_ACTION(softc, PROBE_INQUIRY);
1133 xpt_release_ccb(done_ccb);
1134 xpt_schedule(periph, priority);
1136 case PROBE_SET_MULTI:
1137 if (periph->path->device->flags & CAM_DEV_UNCONFIGURED) {
1138 path->device->flags &= ~CAM_DEV_UNCONFIGURED;
1139 xpt_acquire_device(path->device);
1140 done_ccb->ccb_h.func_code = XPT_GDEV_TYPE;
1141 xpt_action(done_ccb);
1142 xpt_async(AC_FOUND_DEVICE, path, done_ccb);
1144 PROBE_SET_ACTION(softc, PROBE_DONE);
1147 case PROBE_FULL_INQUIRY:
1149 uint8_t periph_qual, len;
1151 path->device->flags |= CAM_DEV_INQUIRY_DATA_VALID;
1153 periph_qual = SID_QUAL(inq_buf);
1155 if (periph_qual != SID_QUAL_LU_CONNECTED &&
1156 periph_qual != SID_QUAL_LU_OFFLINE)
1160 * We conservatively request only
1161 * SHORT_INQUIRY_LEN bytes of inquiry
1162 * information during our first try
1163 * at sending an INQUIRY. If the device
1164 * has more information to give,
1165 * perform a second request specifying
1166 * the amount of information the device
1167 * is willing to give.
1169 len = inq_buf->additional_length
1170 + offsetof(struct scsi_inquiry_data, additional_length) + 1;
1171 if (softc->action == PROBE_INQUIRY
1172 && len > SHORT_INQUIRY_LENGTH) {
1173 PROBE_SET_ACTION(softc, PROBE_FULL_INQUIRY);
1174 xpt_release_ccb(done_ccb);
1175 xpt_schedule(periph, priority);
1179 ata_device_transport(path);
1180 if (periph->path->device->flags & CAM_DEV_UNCONFIGURED) {
1181 path->device->flags &= ~CAM_DEV_UNCONFIGURED;
1182 xpt_acquire_device(path->device);
1183 done_ccb->ccb_h.func_code = XPT_GDEV_TYPE;
1184 xpt_action(done_ccb);
1185 xpt_async(AC_FOUND_DEVICE, path, done_ccb);
1187 PROBE_SET_ACTION(softc, PROBE_DONE);
1191 if ((path->device->flags & CAM_DEV_IDENTIFY_DATA_VALID) == 0)
1192 bzero(ident_buf, sizeof(*ident_buf));
1193 softc->pm_pid = (done_ccb->ataio.res.lba_high << 24) +
1194 (done_ccb->ataio.res.lba_mid << 16) +
1195 (done_ccb->ataio.res.lba_low << 8) +
1196 done_ccb->ataio.res.sector_count;
1197 ((uint32_t *)ident_buf)[0] = softc->pm_pid;
1198 snprintf(ident_buf->model, sizeof(ident_buf->model),
1199 "Port Multiplier %08x", softc->pm_pid);
1200 PROBE_SET_ACTION(softc, PROBE_PM_PRV);
1201 xpt_release_ccb(done_ccb);
1202 xpt_schedule(periph, priority);
1205 softc->pm_prv = (done_ccb->ataio.res.lba_high << 24) +
1206 (done_ccb->ataio.res.lba_mid << 16) +
1207 (done_ccb->ataio.res.lba_low << 8) +
1208 done_ccb->ataio.res.sector_count;
1209 ((uint32_t *)ident_buf)[1] = softc->pm_prv;
1210 snprintf(ident_buf->revision, sizeof(ident_buf->revision),
1211 "%04x", softc->pm_prv);
1212 path->device->flags |= CAM_DEV_IDENTIFY_DATA_VALID;
1213 ata_device_transport(path);
1214 if (periph->path->device->flags & CAM_DEV_UNCONFIGURED)
1215 aproberequestdefaultnegotiation(periph);
1216 /* Set supported bits. */
1217 bzero(&cts, sizeof(cts));
1218 xpt_setup_ccb(&cts.ccb_h, path, CAM_PRIORITY_NONE);
1219 cts.ccb_h.func_code = XPT_GET_TRAN_SETTINGS;
1220 cts.type = CTS_TYPE_CURRENT_SETTINGS;
1221 xpt_action((union ccb *)&cts);
1222 if (cts.xport_specific.sata.valid & CTS_SATA_VALID_CAPS)
1223 caps = cts.xport_specific.sata.caps & CTS_SATA_CAPS_H;
1226 /* All PMPs must support PM requests. */
1227 caps |= CTS_SATA_CAPS_D_PMREQ;
1228 /* Mask unwanted bits. */
1229 bzero(&cts, sizeof(cts));
1230 xpt_setup_ccb(&cts.ccb_h, path, CAM_PRIORITY_NONE);
1231 cts.ccb_h.func_code = XPT_GET_TRAN_SETTINGS;
1232 cts.type = CTS_TYPE_USER_SETTINGS;
1233 xpt_action((union ccb *)&cts);
1234 if (cts.xport_specific.sata.valid & CTS_SATA_VALID_CAPS)
1235 caps &= cts.xport_specific.sata.caps;
1238 /* Remember what transport thinks about AEN. */
1239 oif = path->device->inq_flags;
1240 if ((caps & CTS_SATA_CAPS_H_AN) && path->device->protocol != PROTO_ATA)
1241 path->device->inq_flags |= SID_AEN;
1243 path->device->inq_flags &= ~SID_AEN;
1244 /* Store result to SIM. */
1245 bzero(&cts, sizeof(cts));
1246 xpt_setup_ccb(&cts.ccb_h, path, CAM_PRIORITY_NONE);
1247 cts.ccb_h.func_code = XPT_SET_TRAN_SETTINGS;
1248 cts.type = CTS_TYPE_CURRENT_SETTINGS;
1249 cts.xport_specific.sata.caps = caps;
1250 cts.xport_specific.sata.valid = CTS_SATA_VALID_CAPS;
1251 xpt_action((union ccb *)&cts);
1253 if (periph->path->device->flags & CAM_DEV_UNCONFIGURED) {
1254 path->device->flags &= ~CAM_DEV_UNCONFIGURED;
1255 xpt_acquire_device(path->device);
1256 done_ccb->ccb_h.func_code = XPT_GDEV_TYPE;
1257 xpt_action(done_ccb);
1258 xpt_async(AC_FOUND_DEVICE, path, done_ccb);
1260 if (path->device->inq_flags != oif)
1261 xpt_async(AC_GETDEV_CHANGED, path, NULL);
1262 done_ccb->ccb_h.func_code = XPT_GDEV_TYPE;
1263 xpt_action(done_ccb);
1264 xpt_async(AC_SCSI_AEN, path, done_ccb);
1266 PROBE_SET_ACTION(softc, PROBE_DONE);
1268 case PROBE_IDENTIFY_SES:
1269 case PROBE_IDENTIFY_SAFTE:
1270 if ((periph->path->device->flags & CAM_DEV_UNCONFIGURED) == 0) {
1271 /* Check that it is the same device. */
1272 if (bcmp(&softc->ident_data, ident_buf, 53)) {
1273 /* Device changed. */
1275 xpt_async(AC_LOST_DEVICE, path, NULL);
1277 bcopy(&softc->ident_data, ident_buf, sizeof(struct ata_params));
1283 bcopy(&softc->ident_data, ident_buf, sizeof(struct ata_params));
1284 /* Clean up from previous instance of this device */
1285 if (path->device->device_id != NULL) {
1286 free(path->device->device_id, M_CAMXPT);
1287 path->device->device_id = NULL;
1288 path->device->device_id_len = 0;
1290 path->device->device_id =
1291 malloc(16, M_CAMXPT, M_NOWAIT);
1292 if (path->device->device_id != NULL) {
1293 path->device->device_id_len = 16;
1294 bcopy(&fake_device_id_hdr,
1295 path->device->device_id, 8);
1296 bcopy(((uint8_t*)ident_buf) + 2,
1297 path->device->device_id + 8, 8);
1300 path->device->flags |= CAM_DEV_IDENTIFY_DATA_VALID;
1302 ata_device_transport(path);
1304 aproberequestdefaultnegotiation(periph);
1306 if (periph->path->device->flags & CAM_DEV_UNCONFIGURED) {
1307 path->device->flags &= ~CAM_DEV_UNCONFIGURED;
1308 xpt_acquire_device(path->device);
1309 done_ccb->ccb_h.func_code = XPT_GDEV_TYPE;
1310 xpt_action(done_ccb);
1311 xpt_async(AC_FOUND_DEVICE, path, done_ccb);
1313 PROBE_SET_ACTION(softc, PROBE_DONE);
1316 panic("aprobedone: invalid action state 0x%x\n", softc->action);
1319 if (softc->restart) {
1321 xpt_release_ccb(done_ccb);
1322 aprobeschedule(periph);
1325 xpt_release_ccb(done_ccb);
1326 CAM_DEBUG(periph->path, CAM_DEBUG_PROBE, ("Probe completed\n"));
1327 while ((done_ccb = (union ccb *)TAILQ_FIRST(&softc->request_ccbs))) {
1328 TAILQ_REMOVE(&softc->request_ccbs,
1329 &done_ccb->ccb_h, periph_links.tqe);
1330 done_ccb->ccb_h.status = found ? CAM_REQ_CMP : CAM_REQ_CMP_ERR;
1333 /* Drop freeze taken due to CAM_DEV_QFREEZE flag set. */
1334 cam_release_devq(path, 0, 0, 0, FALSE);
1335 cam_periph_invalidate(periph);
1336 cam_periph_release_locked(periph);
1340 aprobecleanup(struct cam_periph *periph)
1342 free(periph->softc, M_CAMXPT);
1346 ata_find_quirk(struct cam_ed *device)
1348 struct ata_quirk_entry *quirk;
1351 match = cam_quirkmatch((caddr_t)&device->ident_data,
1352 (caddr_t)ata_quirk_table,
1353 nitems(ata_quirk_table),
1354 sizeof(*ata_quirk_table), ata_identify_match);
1357 panic("xpt_find_quirk: device didn't match wildcard entry!!");
1359 quirk = (struct ata_quirk_entry *)match;
1360 device->quirk = quirk;
1361 if (quirk->quirks & CAM_QUIRK_MAXTAGS) {
1362 device->mintags = quirk->mintags;
1363 device->maxtags = quirk->maxtags;
1368 union ccb *request_ccb;
1369 struct ccb_pathinq *cpi;
1371 } ata_scan_bus_info;
1374 * To start a scan, request_ccb is an XPT_SCAN_BUS ccb.
1375 * As the scan progresses, xpt_scan_bus is used as the
1376 * callback on completion function.
1379 ata_scan_bus(struct cam_periph *periph, union ccb *request_ccb)
1381 struct cam_path *path;
1382 ata_scan_bus_info *scan_info;
1383 union ccb *work_ccb, *reset_ccb;
1387 CAM_DEBUG(request_ccb->ccb_h.path, CAM_DEBUG_TRACE,
1388 ("xpt_scan_bus\n"));
1389 switch (request_ccb->ccb_h.func_code) {
1392 /* Find out the characteristics of the bus */
1393 work_ccb = xpt_alloc_ccb_nowait();
1394 if (work_ccb == NULL) {
1395 request_ccb->ccb_h.status = CAM_RESRC_UNAVAIL;
1396 xpt_done(request_ccb);
1399 xpt_path_inq(&work_ccb->cpi, request_ccb->ccb_h.path);
1400 if (work_ccb->ccb_h.status != CAM_REQ_CMP) {
1401 request_ccb->ccb_h.status = work_ccb->ccb_h.status;
1402 xpt_free_ccb(work_ccb);
1403 xpt_done(request_ccb);
1407 /* We may need to reset bus first, if we haven't done it yet. */
1408 if ((work_ccb->cpi.hba_inquiry &
1409 (PI_WIDE_32|PI_WIDE_16|PI_SDTR_ABLE)) &&
1410 !(work_ccb->cpi.hba_misc & PIM_NOBUSRESET) &&
1411 !timevalisset(&request_ccb->ccb_h.path->bus->last_reset)) {
1412 reset_ccb = xpt_alloc_ccb_nowait();
1413 if (reset_ccb == NULL) {
1414 request_ccb->ccb_h.status = CAM_RESRC_UNAVAIL;
1415 xpt_free_ccb(work_ccb);
1416 xpt_done(request_ccb);
1419 xpt_setup_ccb(&reset_ccb->ccb_h, request_ccb->ccb_h.path,
1421 reset_ccb->ccb_h.func_code = XPT_RESET_BUS;
1422 xpt_action(reset_ccb);
1423 if (reset_ccb->ccb_h.status != CAM_REQ_CMP) {
1424 request_ccb->ccb_h.status = reset_ccb->ccb_h.status;
1425 xpt_free_ccb(reset_ccb);
1426 xpt_free_ccb(work_ccb);
1427 xpt_done(request_ccb);
1430 xpt_free_ccb(reset_ccb);
1433 /* Save some state for use while we probe for devices */
1434 scan_info = (ata_scan_bus_info *)
1435 malloc(sizeof(ata_scan_bus_info), M_CAMXPT, M_NOWAIT);
1436 if (scan_info == NULL) {
1437 request_ccb->ccb_h.status = CAM_RESRC_UNAVAIL;
1438 xpt_free_ccb(work_ccb);
1439 xpt_done(request_ccb);
1442 scan_info->request_ccb = request_ccb;
1443 scan_info->cpi = &work_ccb->cpi;
1444 /* If PM supported, probe it first. */
1445 if (scan_info->cpi->hba_inquiry & PI_SATAPM)
1446 scan_info->counter = scan_info->cpi->max_target;
1448 scan_info->counter = 0;
1450 work_ccb = xpt_alloc_ccb_nowait();
1451 if (work_ccb == NULL) {
1452 free(scan_info, M_CAMXPT);
1453 request_ccb->ccb_h.status = CAM_RESRC_UNAVAIL;
1454 xpt_done(request_ccb);
1457 mtx = xpt_path_mtx(scan_info->request_ccb->ccb_h.path);
1460 work_ccb = request_ccb;
1461 /* Reuse the same CCB to query if a device was really found */
1462 scan_info = (ata_scan_bus_info *)work_ccb->ccb_h.ppriv_ptr0;
1463 mtx = xpt_path_mtx(scan_info->request_ccb->ccb_h.path);
1465 /* If there is PMP... */
1466 if ((scan_info->cpi->hba_inquiry & PI_SATAPM) &&
1467 (scan_info->counter == scan_info->cpi->max_target)) {
1468 if (cam_ccb_success(work_ccb)) {
1469 /* everything else will be probed by it */
1470 /* Free the current request path- we're done with it. */
1471 xpt_free_path(work_ccb->ccb_h.path);
1474 struct ccb_trans_settings cts;
1476 /* Report SIM that PM is absent. */
1477 bzero(&cts, sizeof(cts));
1478 xpt_setup_ccb(&cts.ccb_h,
1479 work_ccb->ccb_h.path, CAM_PRIORITY_NONE);
1480 cts.ccb_h.func_code = XPT_SET_TRAN_SETTINGS;
1481 cts.type = CTS_TYPE_CURRENT_SETTINGS;
1482 cts.xport_specific.sata.pm_present = 0;
1483 cts.xport_specific.sata.valid = CTS_SATA_VALID_PM;
1484 xpt_action((union ccb *)&cts);
1487 /* Free the current request path- we're done with it. */
1488 xpt_free_path(work_ccb->ccb_h.path);
1489 if (scan_info->counter ==
1490 ((scan_info->cpi->hba_inquiry & PI_SATAPM) ?
1491 0 : scan_info->cpi->max_target)) {
1494 xpt_free_ccb(work_ccb);
1495 xpt_free_ccb((union ccb *)scan_info->cpi);
1496 request_ccb = scan_info->request_ccb;
1497 free(scan_info, M_CAMXPT);
1498 request_ccb->ccb_h.status = CAM_REQ_CMP;
1499 xpt_done(request_ccb);
1502 /* Take next device. Wrap from max (PMP) to 0. */
1503 scan_info->counter = (scan_info->counter + 1 ) %
1504 (scan_info->cpi->max_target + 1);
1506 status = xpt_create_path(&path, NULL,
1507 scan_info->request_ccb->ccb_h.path_id,
1508 scan_info->counter, 0);
1509 if (status != CAM_REQ_CMP) {
1510 if (request_ccb->ccb_h.func_code == XPT_SCAN_LUN)
1512 printf("xpt_scan_bus: xpt_create_path failed"
1513 " with status %#x, bus scan halted\n",
1515 xpt_free_ccb(work_ccb);
1516 xpt_free_ccb((union ccb *)scan_info->cpi);
1517 request_ccb = scan_info->request_ccb;
1518 free(scan_info, M_CAMXPT);
1519 request_ccb->ccb_h.status = status;
1520 xpt_done(request_ccb);
1523 xpt_setup_ccb(&work_ccb->ccb_h, path,
1524 scan_info->request_ccb->ccb_h.pinfo.priority);
1525 work_ccb->ccb_h.func_code = XPT_SCAN_LUN;
1526 work_ccb->ccb_h.cbfcnp = ata_scan_bus;
1527 work_ccb->ccb_h.flags |= CAM_UNLOCKED;
1528 work_ccb->ccb_h.ppriv_ptr0 = scan_info;
1529 work_ccb->crcn.flags = scan_info->request_ccb->crcn.flags;
1531 if (request_ccb->ccb_h.func_code == XPT_SCAN_LUN)
1533 xpt_action(work_ccb);
1543 ata_scan_lun(struct cam_periph *periph, struct cam_path *path,
1544 cam_flags flags, union ccb *request_ccb)
1546 struct ccb_pathinq cpi;
1548 struct cam_path *new_path;
1549 struct cam_periph *old_periph;
1552 CAM_DEBUG(path, CAM_DEBUG_TRACE, ("xpt_scan_lun\n"));
1554 xpt_path_inq(&cpi, path);
1555 if (cpi.ccb_h.status != CAM_REQ_CMP) {
1556 if (request_ccb != NULL) {
1557 request_ccb->ccb_h.status = cpi.ccb_h.status;
1558 xpt_done(request_ccb);
1563 if (request_ccb == NULL) {
1564 request_ccb = xpt_alloc_ccb_nowait();
1565 if (request_ccb == NULL) {
1566 xpt_print(path, "xpt_scan_lun: can't allocate CCB, "
1567 "can't continue\n");
1570 status = xpt_create_path(&new_path, NULL,
1572 path->target->target_id,
1573 path->device->lun_id);
1574 if (status != CAM_REQ_CMP) {
1575 xpt_print(path, "xpt_scan_lun: can't create path, "
1576 "can't continue\n");
1577 xpt_free_ccb(request_ccb);
1580 xpt_setup_ccb(&request_ccb->ccb_h, new_path, CAM_PRIORITY_XPT);
1581 request_ccb->ccb_h.cbfcnp = axptscandone;
1582 request_ccb->ccb_h.flags |= CAM_UNLOCKED;
1583 request_ccb->ccb_h.func_code = XPT_SCAN_LUN;
1584 request_ccb->crcn.flags = flags;
1587 lock = (xpt_path_owned(path) == 0);
1589 xpt_path_lock(path);
1590 if ((old_periph = cam_periph_find(path, "aprobe")) != NULL) {
1591 if ((old_periph->flags & CAM_PERIPH_INVALID) == 0) {
1592 aprobe_softc *softc;
1594 softc = (aprobe_softc *)old_periph->softc;
1595 TAILQ_INSERT_TAIL(&softc->request_ccbs,
1596 &request_ccb->ccb_h, periph_links.tqe);
1599 request_ccb->ccb_h.status = CAM_REQ_CMP_ERR;
1600 xpt_done(request_ccb);
1603 status = cam_periph_alloc(aproberegister, NULL, aprobecleanup,
1604 aprobestart, "aprobe",
1606 request_ccb->ccb_h.path, NULL, 0,
1609 if (status != CAM_REQ_CMP) {
1610 xpt_print(path, "xpt_scan_lun: cam_alloc_periph "
1611 "returned an error, can't continue probe\n");
1612 request_ccb->ccb_h.status = status;
1613 xpt_done(request_ccb);
1617 xpt_path_unlock(path);
1621 axptscandone(struct cam_periph *periph, union ccb *done_ccb)
1624 xpt_free_path(done_ccb->ccb_h.path);
1625 xpt_free_ccb(done_ccb);
1628 static struct cam_ed *
1629 ata_alloc_device(struct cam_eb *bus, struct cam_et *target, lun_id_t lun_id)
1631 struct ata_quirk_entry *quirk;
1632 struct cam_ed *device;
1634 device = xpt_alloc_device(bus, target, lun_id);
1639 * Take the default quirk entry until we have inquiry
1640 * data and can determine a better quirk to use.
1642 quirk = &ata_quirk_table[nitems(ata_quirk_table) - 1];
1643 device->quirk = (void *)quirk;
1644 device->mintags = 0;
1645 device->maxtags = 0;
1646 bzero(&device->inq_data, sizeof(device->inq_data));
1647 device->inq_flags = 0;
1648 device->queue_flags = 0;
1649 device->serial_num = NULL;
1650 device->serial_num_len = 0;
1655 ata_device_transport(struct cam_path *path)
1657 struct ccb_pathinq cpi;
1658 struct ccb_trans_settings cts;
1659 struct scsi_inquiry_data *inq_buf = NULL;
1660 struct ata_params *ident_buf = NULL;
1662 /* Get transport information from the SIM */
1663 xpt_path_inq(&cpi, path);
1665 path->device->transport = cpi.transport;
1666 if ((path->device->flags & CAM_DEV_INQUIRY_DATA_VALID) != 0)
1667 inq_buf = &path->device->inq_data;
1668 if ((path->device->flags & CAM_DEV_IDENTIFY_DATA_VALID) != 0)
1669 ident_buf = &path->device->ident_data;
1670 if (path->device->protocol == PROTO_ATA) {
1671 path->device->protocol_version = ident_buf ?
1672 ata_version(ident_buf->version_major) : cpi.protocol_version;
1673 } else if (path->device->protocol == PROTO_SCSI) {
1674 path->device->protocol_version = inq_buf ?
1675 SID_ANSI_REV(inq_buf) : cpi.protocol_version;
1677 path->device->transport_version = ident_buf ?
1678 ata_version(ident_buf->version_major) : cpi.transport_version;
1680 /* Tell the controller what we think */
1681 bzero(&cts, sizeof(cts));
1682 xpt_setup_ccb(&cts.ccb_h, path, CAM_PRIORITY_NONE);
1683 cts.ccb_h.func_code = XPT_SET_TRAN_SETTINGS;
1684 cts.type = CTS_TYPE_CURRENT_SETTINGS;
1685 cts.transport = path->device->transport;
1686 cts.transport_version = path->device->transport_version;
1687 cts.protocol = path->device->protocol;
1688 cts.protocol_version = path->device->protocol_version;
1689 cts.proto_specific.valid = 0;
1691 if (path->device->transport == XPORT_ATA) {
1692 cts.xport_specific.ata.atapi =
1693 (ident_buf->config == ATA_PROTO_CFA) ? 0 :
1694 ((ident_buf->config & ATA_PROTO_MASK) == ATA_PROTO_ATAPI_16) ? 16 :
1695 ((ident_buf->config & ATA_PROTO_MASK) == ATA_PROTO_ATAPI_12) ? 12 : 0;
1696 cts.xport_specific.ata.valid = CTS_ATA_VALID_ATAPI;
1698 cts.xport_specific.sata.atapi =
1699 (ident_buf->config == ATA_PROTO_CFA) ? 0 :
1700 ((ident_buf->config & ATA_PROTO_MASK) == ATA_PROTO_ATAPI_16) ? 16 :
1701 ((ident_buf->config & ATA_PROTO_MASK) == ATA_PROTO_ATAPI_12) ? 12 : 0;
1702 cts.xport_specific.sata.valid = CTS_SATA_VALID_ATAPI;
1705 cts.xport_specific.valid = 0;
1706 xpt_action((union ccb *)&cts);
1710 ata_dev_advinfo(union ccb *start_ccb)
1712 struct cam_ed *device;
1713 struct ccb_dev_advinfo *cdai;
1716 xpt_path_assert(start_ccb->ccb_h.path, MA_OWNED);
1717 start_ccb->ccb_h.status = CAM_REQ_INVALID;
1718 device = start_ccb->ccb_h.path->device;
1719 cdai = &start_ccb->cdai;
1720 switch(cdai->buftype) {
1721 case CDAI_TYPE_SCSI_DEVID:
1722 if (cdai->flags & CDAI_FLAG_STORE)
1724 cdai->provsiz = device->device_id_len;
1725 if (device->device_id_len == 0)
1727 amt = device->device_id_len;
1728 if (cdai->provsiz > cdai->bufsiz)
1730 memcpy(cdai->buf, device->device_id, amt);
1732 case CDAI_TYPE_SERIAL_NUM:
1733 if (cdai->flags & CDAI_FLAG_STORE)
1735 cdai->provsiz = device->serial_num_len;
1736 if (device->serial_num_len == 0)
1738 amt = device->serial_num_len;
1739 if (cdai->provsiz > cdai->bufsiz)
1741 memcpy(cdai->buf, device->serial_num, amt);
1743 case CDAI_TYPE_PHYS_PATH:
1744 if (cdai->flags & CDAI_FLAG_STORE) {
1745 if (device->physpath != NULL) {
1746 free(device->physpath, M_CAMXPT);
1747 device->physpath = NULL;
1748 device->physpath_len = 0;
1750 /* Clear existing buffer if zero length */
1751 if (cdai->bufsiz == 0)
1753 device->physpath = malloc(cdai->bufsiz, M_CAMXPT, M_NOWAIT);
1754 if (device->physpath == NULL) {
1755 start_ccb->ccb_h.status = CAM_REQ_ABORTED;
1758 device->physpath_len = cdai->bufsiz;
1759 memcpy(device->physpath, cdai->buf, cdai->bufsiz);
1761 cdai->provsiz = device->physpath_len;
1762 if (device->physpath_len == 0)
1764 amt = device->physpath_len;
1765 if (cdai->provsiz > cdai->bufsiz)
1767 memcpy(cdai->buf, device->physpath, amt);
1773 start_ccb->ccb_h.status = CAM_REQ_CMP;
1775 if (cdai->flags & CDAI_FLAG_STORE) {
1776 xpt_async(AC_ADVINFO_CHANGED, start_ccb->ccb_h.path,
1777 (void *)(uintptr_t)cdai->buftype);
1782 ata_action(union ccb *start_ccb)
1785 if (start_ccb->ccb_h.func_code != XPT_ATA_IO) {
1786 KASSERT((start_ccb->ccb_h.alloc_flags & CAM_CCB_FROM_UMA) == 0,
1787 ("%s: ccb %p, func_code %#x should not be allocated "
1789 __func__, start_ccb, start_ccb->ccb_h.func_code));
1792 switch (start_ccb->ccb_h.func_code) {
1793 case XPT_SET_TRAN_SETTINGS:
1795 ata_set_transfer_settings(&start_ccb->cts,
1796 start_ccb->ccb_h.path,
1797 /*async_update*/FALSE);
1802 ata_scan_bus(start_ccb->ccb_h.path->periph, start_ccb);
1805 ata_scan_lun(start_ccb->ccb_h.path->periph,
1806 start_ccb->ccb_h.path, start_ccb->crcn.flags,
1809 case XPT_GET_TRAN_SETTINGS:
1811 ata_get_transfer_settings(&start_ccb->cts);
1816 struct cam_ed *device;
1819 device = start_ccb->ccb_h.path->device;
1820 if (device->protocol == PROTO_SCSI &&
1821 (device->flags & CAM_DEV_IDENTIFY_DATA_VALID)) {
1823 device->ident_data.config & ATA_PROTO_MASK;
1826 (device->ident_data.config == ATA_PROTO_CFA) ? 0 :
1827 (p == ATA_PROTO_ATAPI_16) ? 16 :
1828 (p == ATA_PROTO_ATAPI_12) ? 12 : 0;
1830 if (start_ccb->csio.cdb_len > maxlen) {
1831 start_ccb->ccb_h.status = CAM_REQ_INVALID;
1832 xpt_done(start_ccb);
1835 xpt_action_default(start_ccb);
1838 case XPT_DEV_ADVINFO:
1840 ata_dev_advinfo(start_ccb);
1844 xpt_action_default(start_ccb);
1850 ata_get_transfer_settings(struct ccb_trans_settings *cts)
1852 struct ccb_trans_settings_ata *ata;
1853 struct ccb_trans_settings_scsi *scsi;
1854 struct cam_ed *device;
1856 device = cts->ccb_h.path->device;
1857 xpt_action_default((union ccb *)cts);
1859 if (cts->protocol == PROTO_UNKNOWN ||
1860 cts->protocol == PROTO_UNSPECIFIED) {
1861 cts->protocol = device->protocol;
1862 cts->protocol_version = device->protocol_version;
1865 if (cts->protocol == PROTO_ATA) {
1866 ata = &cts->proto_specific.ata;
1867 if ((ata->valid & CTS_ATA_VALID_TQ) == 0) {
1868 ata->valid |= CTS_ATA_VALID_TQ;
1869 if (cts->type == CTS_TYPE_USER_SETTINGS ||
1870 (device->flags & CAM_DEV_TAG_AFTER_COUNT) != 0 ||
1871 (device->inq_flags & SID_CmdQue) != 0)
1872 ata->flags |= CTS_ATA_FLAGS_TAG_ENB;
1875 if (cts->protocol == PROTO_SCSI) {
1876 scsi = &cts->proto_specific.scsi;
1877 if ((scsi->valid & CTS_SCSI_VALID_TQ) == 0) {
1878 scsi->valid |= CTS_SCSI_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 scsi->flags |= CTS_SCSI_FLAGS_TAG_ENB;
1886 if (cts->transport == XPORT_UNKNOWN ||
1887 cts->transport == XPORT_UNSPECIFIED) {
1888 cts->transport = device->transport;
1889 cts->transport_version = device->transport_version;
1894 ata_set_transfer_settings(struct ccb_trans_settings *cts, struct cam_path *path,
1897 struct ccb_pathinq cpi;
1898 struct ccb_trans_settings_ata *ata;
1899 struct ccb_trans_settings_scsi *scsi;
1900 struct ata_params *ident_data;
1901 struct scsi_inquiry_data *inq_data;
1902 struct cam_ed *device;
1904 if (path == NULL || (device = path->device) == NULL) {
1905 cts->ccb_h.status = CAM_PATH_INVALID;
1906 xpt_done((union ccb *)cts);
1910 if (cts->protocol == PROTO_UNKNOWN
1911 || cts->protocol == PROTO_UNSPECIFIED) {
1912 cts->protocol = device->protocol;
1913 cts->protocol_version = device->protocol_version;
1916 if (cts->protocol_version == PROTO_VERSION_UNKNOWN
1917 || cts->protocol_version == PROTO_VERSION_UNSPECIFIED)
1918 cts->protocol_version = device->protocol_version;
1920 if (cts->protocol != device->protocol) {
1921 xpt_print(path, "Uninitialized Protocol %x:%x?\n",
1922 cts->protocol, device->protocol);
1923 cts->protocol = device->protocol;
1926 if (cts->protocol_version > device->protocol_version) {
1928 xpt_print(path, "Down reving Protocol "
1929 "Version from %d to %d?\n", cts->protocol_version,
1930 device->protocol_version);
1932 cts->protocol_version = device->protocol_version;
1935 if (cts->transport == XPORT_UNKNOWN
1936 || cts->transport == XPORT_UNSPECIFIED) {
1937 cts->transport = device->transport;
1938 cts->transport_version = device->transport_version;
1941 if (cts->transport_version == XPORT_VERSION_UNKNOWN
1942 || cts->transport_version == XPORT_VERSION_UNSPECIFIED)
1943 cts->transport_version = device->transport_version;
1945 if (cts->transport != device->transport) {
1946 xpt_print(path, "Uninitialized Transport %x:%x?\n",
1947 cts->transport, device->transport);
1948 cts->transport = device->transport;
1951 if (cts->transport_version > device->transport_version) {
1953 xpt_print(path, "Down reving Transport "
1954 "Version from %d to %d?\n", cts->transport_version,
1955 device->transport_version);
1957 cts->transport_version = device->transport_version;
1960 ident_data = &device->ident_data;
1961 inq_data = &device->inq_data;
1962 if (cts->protocol == PROTO_ATA)
1963 ata = &cts->proto_specific.ata;
1966 if (cts->protocol == PROTO_SCSI)
1967 scsi = &cts->proto_specific.scsi;
1970 xpt_path_inq(&cpi, path);
1972 /* Sanity checking */
1973 if ((cpi.hba_inquiry & PI_TAG_ABLE) == 0
1974 || (ata && (ident_data->satacapabilities & ATA_SUPPORT_NCQ) == 0)
1975 || (scsi && (INQ_DATA_TQ_ENABLED(inq_data)) == 0)
1976 || (device->queue_flags & SCP_QUEUE_DQUE) != 0
1977 || (device->mintags == 0)) {
1979 * Can't tag on hardware that doesn't support tags,
1980 * doesn't have it enabled, or has broken tag support.
1983 ata->flags &= ~CTS_ATA_FLAGS_TAG_ENB;
1985 scsi->flags &= ~CTS_SCSI_FLAGS_TAG_ENB;
1988 /* Start/stop tags use. */
1989 if (cts->type == CTS_TYPE_CURRENT_SETTINGS &&
1990 ((ata && (ata->valid & CTS_ATA_VALID_TQ) != 0) ||
1991 (scsi && (scsi->valid & CTS_SCSI_VALID_TQ) != 0))) {
1994 nowt = ((device->flags & CAM_DEV_TAG_AFTER_COUNT) != 0 ||
1995 (device->inq_flags & SID_CmdQue) != 0);
1997 newt = (ata->flags & CTS_ATA_FLAGS_TAG_ENB) != 0;
1999 newt = (scsi->flags & CTS_SCSI_FLAGS_TAG_ENB) != 0;
2001 if (newt && !nowt) {
2003 * Delay change to use tags until after a
2004 * few commands have gone to this device so
2005 * the controller has time to perform transfer
2006 * negotiations without tagged messages getting
2009 device->tag_delay_count = CAM_TAG_DELAY_COUNT;
2010 device->flags |= CAM_DEV_TAG_AFTER_COUNT;
2011 } else if (nowt && !newt)
2012 xpt_stop_tags(path);
2015 if (async_update == FALSE)
2016 xpt_action_default((union ccb *)cts);
2020 * Handle any per-device event notifications that require action by the XPT.
2023 ata_dev_async(uint32_t async_code, struct cam_eb *bus, struct cam_et *target,
2024 struct cam_ed *device, void *async_arg)
2027 * We only need to handle events for real devices.
2029 if (target->target_id == CAM_TARGET_WILDCARD ||
2030 device->lun_id == CAM_LUN_WILDCARD)
2033 switch (async_code) {
2036 case AC_INQ_CHANGED: {
2038 struct cam_path newpath;
2042 * We need our own path with wildcards expanded to handle these
2045 status = xpt_compile_path(&newpath, NULL,
2049 if (status != CAM_REQ_CMP)
2050 break; /* fail safe and just drop it */
2053 * For AC_INQ_CHANGED, we've sent a start unit command, or
2054 * something similar to a device that may have caused its
2055 * inquiry data to change. So we re-scan the device to refresh
2056 * the inquiry data for it, allowing changes. Otherwise we rescan
2057 * without allowing changes to respond to the reset, not allowing
2060 flags = async_code == AC_INQ_CHANGED ? CAM_EXPECT_INQ_CHANGE : 0;
2061 ata_scan_lun(newpath.periph, &newpath, flags, NULL);
2062 xpt_release_path(&newpath);
2065 case AC_TRANSFER_NEG: {
2066 struct ccb_trans_settings *settings;
2067 struct cam_path path;
2069 settings = (struct ccb_trans_settings *)async_arg;
2070 xpt_compile_path(&path, NULL, bus->path_id, target->target_id,
2072 ata_set_transfer_settings(settings, &path,
2073 /*async_update*/TRUE);
2074 xpt_release_path(&path);
2077 case AC_LOST_DEVICE:
2078 if ((device->flags & CAM_DEV_UNCONFIGURED) == 0) {
2079 device->flags |= CAM_DEV_UNCONFIGURED;
2080 xpt_release_device(device);
2087 _ata_announce_periph(struct cam_periph *periph, struct ccb_trans_settings *cts, u_int *speed)
2089 struct ccb_pathinq cpi;
2090 struct cam_path *path = periph->path;
2092 cam_periph_assert(periph, MA_OWNED);
2094 xpt_setup_ccb(&cts->ccb_h, path, CAM_PRIORITY_NORMAL);
2095 cts->ccb_h.func_code = XPT_GET_TRAN_SETTINGS;
2096 cts->type = CTS_TYPE_CURRENT_SETTINGS;
2097 xpt_action((union ccb*)cts);
2098 if ((cts->ccb_h.status & CAM_STATUS_MASK) != CAM_REQ_CMP)
2100 /* Ask the SIM for its base transfer speed */
2101 xpt_path_inq(&cpi, path);
2102 /* Report connection speed */
2103 *speed = cpi.base_transfer_speed;
2104 if (cts->transport == XPORT_ATA) {
2105 struct ccb_trans_settings_pata *pata =
2106 &cts->xport_specific.ata;
2108 if (pata->valid & CTS_ATA_VALID_MODE)
2109 *speed = ata_mode2speed(pata->mode);
2111 if (cts->transport == XPORT_SATA) {
2112 struct ccb_trans_settings_sata *sata =
2113 &cts->xport_specific.sata;
2115 if (sata->valid & CTS_SATA_VALID_REVISION)
2116 *speed = ata_revision2speed(sata->revision);
2121 ata_announce_periph_sbuf(struct cam_periph *periph, struct sbuf *sb)
2123 struct ccb_trans_settings cts;
2126 bzero(&cts, sizeof(cts));
2127 _ata_announce_periph(periph, &cts, &speed);
2128 if ((cts.ccb_h.status & CAM_STATUS_MASK) != CAM_REQ_CMP)
2133 sbuf_printf(sb, "%s%d: %d.%03dMB/s transfers",
2134 periph->periph_name, periph->unit_number,
2137 sbuf_printf(sb, "%s%d: %dKB/s transfers", periph->periph_name,
2138 periph->unit_number, speed);
2139 /* Report additional information about connection */
2140 if (cts.transport == XPORT_ATA) {
2141 struct ccb_trans_settings_pata *pata =
2142 &cts.xport_specific.ata;
2145 if (pata->valid & CTS_ATA_VALID_MODE)
2146 sbuf_printf(sb, "%s, ", ata_mode2string(pata->mode));
2147 if ((pata->valid & CTS_ATA_VALID_ATAPI) && pata->atapi != 0)
2148 sbuf_printf(sb, "ATAPI %dbytes, ", pata->atapi);
2149 if (pata->valid & CTS_ATA_VALID_BYTECOUNT)
2150 sbuf_printf(sb, "PIO %dbytes", pata->bytecount);
2153 if (cts.transport == XPORT_SATA) {
2154 struct ccb_trans_settings_sata *sata =
2155 &cts.xport_specific.sata;
2158 if (sata->valid & CTS_SATA_VALID_REVISION)
2159 sbuf_printf(sb, "SATA %d.x, ", sata->revision);
2161 sbuf_cat(sb, "SATA, ");
2162 if (sata->valid & CTS_SATA_VALID_MODE)
2163 sbuf_printf(sb, "%s, ", ata_mode2string(sata->mode));
2164 if ((sata->valid & CTS_ATA_VALID_ATAPI) && sata->atapi != 0)
2165 sbuf_printf(sb, "ATAPI %dbytes, ", sata->atapi);
2166 if (sata->valid & CTS_SATA_VALID_BYTECOUNT)
2167 sbuf_printf(sb, "PIO %dbytes", sata->bytecount);
2170 sbuf_putc(sb, '\n');
2174 ata_proto_announce_sbuf(struct cam_ed *device, struct sbuf *sb)
2176 ata_print_ident_sbuf(&device->ident_data, sb);
2180 ata_proto_denounce_sbuf(struct cam_ed *device, struct sbuf *sb)
2182 ata_print_ident_short_sbuf(&device->ident_data, sb);
2186 semb_proto_announce_sbuf(struct cam_ed *device, struct sbuf *sb)
2188 semb_print_ident_sbuf((struct sep_identify_data *)&device->ident_data, sb);
2192 semb_proto_denounce_sbuf(struct cam_ed *device, struct sbuf *sb)
2194 semb_print_ident_short_sbuf((struct sep_identify_data *)&device->ident_data, sb);
2198 ata_proto_debug_out(union ccb *ccb)
2200 char cdb_str[(sizeof(struct ata_cmd) * 3) + 1];
2202 if (ccb->ccb_h.func_code != XPT_ATA_IO)
2205 CAM_DEBUG(ccb->ccb_h.path,
2206 CAM_DEBUG_CDB,("%s. ACB: %s\n", ata_op_string(&ccb->ataio.cmd),
2207 ata_cmd_string(&ccb->ataio.cmd, cdb_str, sizeof(cdb_str))));