FreeBSD kernel CAM code
ata_xpt.c
Go to the documentation of this file.
1/*-
2 * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
3 *
4 * Copyright (c) 2009 Alexander Motin <mav@FreeBSD.org>
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
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.
16 *
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.
27 */
28
29#include <sys/cdefs.h>
30__FBSDID("$FreeBSD$");
31
32#include <sys/param.h>
33#include <sys/bus.h>
34#include <sys/endian.h>
35#include <sys/systm.h>
36#include <sys/types.h>
37#include <sys/malloc.h>
38#include <sys/kernel.h>
39#include <sys/time.h>
40#include <sys/conf.h>
41#include <sys/fcntl.h>
42#include <sys/sbuf.h>
43
44#include <sys/eventhandler.h>
45#include <sys/lock.h>
46#include <sys/mutex.h>
47#include <sys/sysctl.h>
48
49#include <cam/cam.h>
50#include <cam/cam_ccb.h>
51#include <cam/cam_queue.h>
52#include <cam/cam_periph.h>
53#include <cam/cam_sim.h>
54#include <cam/cam_xpt.h>
55#include <cam/cam_xpt_sim.h>
56#include <cam/cam_xpt_periph.h>
58#include <cam/cam_debug.h>
59
60#include <cam/scsi/scsi_all.h>
62#include <cam/ata/ata_all.h>
63#include <machine/stdarg.h> /* for xpt_print below */
64#include "opt_cam.h"
65
68 u_int8_t quirks;
69#define CAM_QUIRK_MAXTAGS 0x01
70 u_int mintags;
71 u_int maxtags;
72};
73
75
77{
78 aprobe_periph_init, "aprobe",
79 TAILQ_HEAD_INITIALIZER(aprobe_driver.units), /* generation */ 0,
81};
82
84
85typedef enum {
104
105static char *probe_action_text[] = {
106 "PROBE_RESET",
107 "PROBE_IDENTIFY",
108 "PROBE_SPINUP",
109 "PROBE_SETMODE",
110 "PROBE_SETPM",
111 "PROBE_SETAPST",
112 "PROBE_SETDMAAA",
113 "PROBE_SETAN",
114 "PROBE_SET_MULTI",
115 "PROBE_INQUIRY",
116 "PROBE_FULL_INQUIRY",
117 "PROBE_PM_PID",
118 "PROBE_PM_PRV",
119 "PROBE_IDENTIFY_SES",
120 "PROBE_IDENTIFY_SAFTE",
121 "PROBE_DONE",
122 "PROBE_INVALID"
123};
124
125#define PROBE_SET_ACTION(softc, newaction) \
126do { \
127 char **text; \
128 text = probe_action_text; \
129 CAM_DEBUG((softc)->periph->path, CAM_DEBUG_PROBE, \
130 ("Probe %s to %s\n", text[(softc)->action], \
131 text[(newaction)])); \
132 (softc)->action = (newaction); \
133} while(0)
134
135typedef enum {
136 PROBE_NO_ANNOUNCE = 0x04
138
139typedef struct {
140 TAILQ_HEAD(, ccb_hdr) request_ccbs;
141 struct ata_params ident_data;
142 aprobe_action action;
144 uint32_t pm_pid;
145 uint32_t pm_prv;
146 int restart;
147 int spinup;
148 int faults;
149 u_int caps;
150 struct cam_periph *periph;
152
154{
155 {
156 /* Default tagged queuing parameters for all devices */
157 {
159 /*vendor*/"*", /*product*/"*", /*revision*/"*"
160 },
161 /*quirks*/0, /*mintags*/0, /*maxtags*/0
162 },
163};
164
165static cam_status aproberegister(struct cam_periph *periph, void *arg);
166static void aprobeschedule(struct cam_periph *probe_periph);
167static void aprobestart(struct cam_periph *periph, union ccb *start_ccb);
168static void aproberequestdefaultnegotiation(struct cam_periph *periph);
169static void aprobedone(struct cam_periph *periph, union ccb *done_ccb);
170static void aprobecleanup(struct cam_periph *periph);
171static void ata_find_quirk(struct cam_ed *device);
172static void ata_scan_bus(struct cam_periph *periph, union ccb *ccb);
173static void ata_scan_lun(struct cam_periph *periph,
174 struct cam_path *path, cam_flags flags,
175 union ccb *ccb);
176static void axptscandone(struct cam_periph *periph, union ccb *done_ccb);
177static struct cam_ed *
178 ata_alloc_device(struct cam_eb *bus, struct cam_et *target,
180static void ata_device_transport(struct cam_path *path);
183 struct cam_path *path,
184 int async_update);
185static void ata_dev_async(u_int32_t async_code,
186 struct cam_eb *bus,
187 struct cam_et *target,
188 struct cam_ed *device,
189 void *async_arg);
190static void ata_action(union ccb *start_ccb);
191static void ata_announce_periph(struct cam_periph *periph);
192static void ata_announce_periph_sbuf(struct cam_periph *periph, struct sbuf *sb);
193static void ata_proto_announce(struct cam_ed *device);
194static void ata_proto_announce_sbuf(struct cam_ed *device, struct sbuf *sb);
195static void ata_proto_denounce(struct cam_ed *device);
196static void ata_proto_denounce_sbuf(struct cam_ed *device, struct sbuf *sb);
197static void ata_proto_debug_out(union ccb *ccb);
198static void semb_proto_announce(struct cam_ed *device);
199static void semb_proto_announce_sbuf(struct cam_ed *device, struct sbuf *sb);
200static void semb_proto_denounce(struct cam_ed *device);
201static void semb_proto_denounce_sbuf(struct cam_ed *device, struct sbuf *sb);
202
203static int ata_dma = 1;
204static int atapi_dma = 1;
205
206TUNABLE_INT("hw.ata.ata_dma", &ata_dma);
207TUNABLE_INT("hw.ata.atapi_dma", &atapi_dma);
208
211 .action = ata_action,
212 .async = ata_dev_async,
213 .announce = ata_announce_periph,
214 .announce_sbuf = ata_announce_periph_sbuf,
215};
216#define ATA_XPT_XPORT(x, X) \
217static struct xpt_xport ata_xport_ ## x = { \
218 .xport = XPORT_ ## X, \
219 .name = #x, \
220 .ops = &ata_xport_ops, \
221}; \
222CAM_XPT_XPORT(ata_xport_ ## x);
223
225ATA_XPT_XPORT(sata, SATA);
226
227#undef ATA_XPORT_XPORT
228
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,
235};
236static struct xpt_proto ata_proto_ata = {
237 .proto = PROTO_ATA,
238 .name = "ata",
239 .ops = &ata_proto_ops_ata,
240};
241
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,
248};
251 .name = "satapm",
252 .ops = &ata_proto_ops_satapm,
253};
254
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,
261};
262static struct xpt_proto ata_proto_semb = {
263 .proto = PROTO_SEMB,
264 .name = "semb",
265 .ops = &ata_proto_ops_semb,
266};
267
271
272static void
274{
275}
276
277static cam_status
278aproberegister(struct cam_periph *periph, void *arg)
279{
280 union ccb *request_ccb; /* CCB representing the probe request */
281 aprobe_softc *softc;
282
283 request_ccb = (union ccb *)arg;
284 if (request_ccb == NULL) {
285 printf("proberegister: no probe CCB, "
286 "can't register device\n");
287 return(CAM_REQ_CMP_ERR);
288 }
289
290 softc = (aprobe_softc *)malloc(sizeof(*softc), M_CAMXPT, M_ZERO | M_NOWAIT);
291
292 if (softc == NULL) {
293 printf("proberegister: Unable to probe new device. "
294 "Unable to allocate softc\n");
295 return(CAM_REQ_CMP_ERR);
296 }
297 TAILQ_INIT(&softc->request_ccbs);
298 TAILQ_INSERT_TAIL(&softc->request_ccbs, &request_ccb->ccb_h,
299 periph_links.tqe);
300 softc->flags = 0;
301 periph->softc = softc;
302 softc->periph = periph;
303 softc->action = PROBE_INVALID;
304 if (cam_periph_acquire(periph) != 0)
305 return (CAM_REQ_CMP_ERR);
306
307 CAM_DEBUG(periph->path, CAM_DEBUG_PROBE, ("Probe started\n"));
308 ata_device_transport(periph->path);
309 aprobeschedule(periph);
310 return(CAM_REQ_CMP);
311}
312
313static void
315{
316 union ccb *ccb;
317 aprobe_softc *softc;
318
319 softc = (aprobe_softc *)periph->softc;
320 ccb = (union ccb *)TAILQ_FIRST(&softc->request_ccbs);
321
322 if ((periph->path->device->flags & CAM_DEV_UNCONFIGURED) ||
323 periph->path->device->protocol == PROTO_SATAPM ||
324 periph->path->device->protocol == PROTO_SEMB)
326 else
328
330 softc->flags |= PROBE_NO_ANNOUNCE;
331 else
332 softc->flags &= ~PROBE_NO_ANNOUNCE;
333
335}
336
337static void
338aprobestart(struct cam_periph *periph, union ccb *start_ccb)
339{
340 struct ccb_trans_settings cts;
341 struct ccb_ataio *ataio;
342 struct ccb_scsiio *csio;
343 aprobe_softc *softc;
344 struct cam_path *path;
345 struct ata_params *ident_buf;
346 u_int oif;
347
348 CAM_DEBUG(start_ccb->ccb_h.path, CAM_DEBUG_TRACE, ("aprobestart\n"));
349
350 softc = (aprobe_softc *)periph->softc;
351 path = start_ccb->ccb_h.path;
352 ataio = &start_ccb->ataio;
353 csio = &start_ccb->csio;
354 ident_buf = &periph->path->device->ident_data;
355
356 if (softc->restart) {
357 softc->restart = 0;
358 if ((path->device->flags & CAM_DEV_UNCONFIGURED) ||
359 path->device->protocol == PROTO_SATAPM ||
360 path->device->protocol == PROTO_SEMB)
361 softc->action = PROBE_RESET;
362 else
363 softc->action = PROBE_IDENTIFY;
364 }
365 switch (softc->action) {
366 case PROBE_RESET:
367 cam_fill_ataio(ataio,
368 0,
370 /*flags*/CAM_DIR_NONE,
371 0,
372 /*data_ptr*/NULL,
373 /*dxfer_len*/0,
374 15 * 1000);
375 ata_reset_cmd(ataio);
376 break;
377 case PROBE_IDENTIFY:
378 cam_fill_ataio(ataio,
379 1,
381 /*flags*/CAM_DIR_IN,
382 0,
383 /*data_ptr*/(u_int8_t *)&softc->ident_data,
384 /*dxfer_len*/sizeof(softc->ident_data),
385 30 * 1000);
386 if (path->device->protocol == PROTO_ATA)
387 ata_28bit_cmd(ataio, ATA_ATA_IDENTIFY, 0, 0, 0);
388 else
389 ata_28bit_cmd(ataio, ATA_ATAPI_IDENTIFY, 0, 0, 0);
390 break;
391 case PROBE_SPINUP:
392 if (bootverbose)
393 xpt_print(path, "Spinning up device\n");
394 cam_fill_ataio(ataio,
395 1,
397 /*flags*/CAM_DIR_NONE | CAM_HIGH_POWER,
398 0,
399 /*data_ptr*/NULL,
400 /*dxfer_len*/0,
401 30 * 1000);
402 ata_28bit_cmd(ataio, ATA_SETFEATURES, ATA_SF_PUIS_SPINUP, 0, 0);
403 break;
404 case PROBE_SETMODE:
405 {
406 int mode, wantmode;
407
408 mode = 0;
409 /* Fetch user modes from SIM. */
410 bzero(&cts, sizeof(cts));
411 xpt_setup_ccb(&cts.ccb_h, path, CAM_PRIORITY_NONE);
412 cts.ccb_h.func_code = XPT_GET_TRAN_SETTINGS;
414 xpt_action((union ccb *)&cts);
415 if (path->device->transport == XPORT_ATA) {
416 if (cts.xport_specific.ata.valid & CTS_ATA_VALID_MODE)
417 mode = cts.xport_specific.ata.mode;
418 } else {
419 if (cts.xport_specific.sata.valid & CTS_SATA_VALID_MODE)
420 mode = cts.xport_specific.sata.mode;
421 }
422 if (path->device->protocol == PROTO_ATA) {
423 if (ata_dma == 0 && (mode == 0 || mode > ATA_PIO_MAX))
424 mode = ATA_PIO_MAX;
425 } else {
426 if (atapi_dma == 0 && (mode == 0 || mode > ATA_PIO_MAX))
427 mode = ATA_PIO_MAX;
428 }
429negotiate:
430 /* Honor device capabilities. */
431 wantmode = mode = ata_max_mode(ident_buf, mode);
432 /* Report modes to SIM. */
433 bzero(&cts, sizeof(cts));
434 xpt_setup_ccb(&cts.ccb_h, path, CAM_PRIORITY_NONE);
435 cts.ccb_h.func_code = XPT_SET_TRAN_SETTINGS;
437 if (path->device->transport == XPORT_ATA) {
438 cts.xport_specific.ata.mode = mode;
439 cts.xport_specific.ata.valid = CTS_ATA_VALID_MODE;
440 } else {
441 cts.xport_specific.sata.mode = mode;
442 cts.xport_specific.sata.valid = CTS_SATA_VALID_MODE;
443 }
444 xpt_action((union ccb *)&cts);
445 /* Fetch current modes from SIM. */
446 bzero(&cts, sizeof(cts));
447 xpt_setup_ccb(&cts.ccb_h, path, CAM_PRIORITY_NONE);
448 cts.ccb_h.func_code = XPT_GET_TRAN_SETTINGS;
450 xpt_action((union ccb *)&cts);
451 if (path->device->transport == XPORT_ATA) {
452 if (cts.xport_specific.ata.valid & CTS_ATA_VALID_MODE)
453 mode = cts.xport_specific.ata.mode;
454 } else {
455 if (cts.xport_specific.sata.valid & CTS_SATA_VALID_MODE)
456 mode = cts.xport_specific.sata.mode;
457 }
458 /* If SIM disagree - renegotiate. */
459 if (mode != wantmode)
460 goto negotiate;
461 /* Remember what transport thinks about DMA. */
462 oif = path->device->inq_flags;
463 if (mode < ATA_DMA)
464 path->device->inq_flags &= ~SID_DMA;
465 else
466 path->device->inq_flags |= SID_DMA;
467 if (path->device->inq_flags != oif)
468 xpt_async(AC_GETDEV_CHANGED, path, NULL);
469 cam_fill_ataio(ataio,
470 1,
472 /*flags*/CAM_DIR_NONE,
473 0,
474 /*data_ptr*/NULL,
475 /*dxfer_len*/0,
476 30 * 1000);
477 ata_28bit_cmd(ataio, ATA_SETFEATURES, ATA_SF_SETXFER, 0, mode);
478 break;
479 }
480 case PROBE_SETPM:
481 cam_fill_ataio(ataio,
482 1,
485 0,
486 NULL,
487 0,
488 30*1000);
489 ata_28bit_cmd(ataio, ATA_SETFEATURES,
490 (softc->caps & CTS_SATA_CAPS_H_PMREQ) ? 0x10 : 0x90,
491 0, 0x03);
492 break;
493 case PROBE_SETAPST:
494 cam_fill_ataio(ataio,
495 1,
498 0,
499 NULL,
500 0,
501 30*1000);
502 ata_28bit_cmd(ataio, ATA_SETFEATURES,
503 (softc->caps & CTS_SATA_CAPS_H_APST) ? 0x10 : 0x90,
504 0, 0x07);
505 break;
506 case PROBE_SETDMAAA:
507 cam_fill_ataio(ataio,
508 1,
511 0,
512 NULL,
513 0,
514 30*1000);
515 ata_28bit_cmd(ataio, ATA_SETFEATURES,
516 (softc->caps & CTS_SATA_CAPS_H_DMAAA) ? 0x10 : 0x90,
517 0, 0x02);
518 break;
519 case PROBE_SETAN:
520 /* Remember what transport thinks about AEN. */
521 oif = path->device->inq_flags;
522 if (softc->caps & CTS_SATA_CAPS_H_AN)
523 path->device->inq_flags |= SID_AEN;
524 else
525 path->device->inq_flags &= ~SID_AEN;
526 if (path->device->inq_flags != oif)
527 xpt_async(AC_GETDEV_CHANGED, path, NULL);
528 cam_fill_ataio(ataio,
529 1,
532 0,
533 NULL,
534 0,
535 30*1000);
536 ata_28bit_cmd(ataio, ATA_SETFEATURES,
537 (softc->caps & CTS_SATA_CAPS_H_AN) ? 0x10 : 0x90,
538 0, 0x05);
539 break;
540 case PROBE_SET_MULTI:
541 {
542 u_int sectors, bytecount;
543
544 bytecount = 8192; /* SATA maximum */
545 /* Fetch user bytecount from SIM. */
546 bzero(&cts, sizeof(cts));
547 xpt_setup_ccb(&cts.ccb_h, path, CAM_PRIORITY_NONE);
548 cts.ccb_h.func_code = XPT_GET_TRAN_SETTINGS;
550 xpt_action((union ccb *)&cts);
551 if (path->device->transport == XPORT_ATA) {
552 if (cts.xport_specific.ata.valid & CTS_ATA_VALID_BYTECOUNT)
553 bytecount = cts.xport_specific.ata.bytecount;
554 } else {
555 if (cts.xport_specific.sata.valid & CTS_SATA_VALID_BYTECOUNT)
556 bytecount = cts.xport_specific.sata.bytecount;
557 }
558 /* Honor device capabilities. */
559 sectors = max(1, min(ident_buf->sectors_intr & 0xff,
560 bytecount / ata_logical_sector_size(ident_buf)));
561 /* Report bytecount to SIM. */
562 bzero(&cts, sizeof(cts));
563 xpt_setup_ccb(&cts.ccb_h, path, CAM_PRIORITY_NONE);
564 cts.ccb_h.func_code = XPT_SET_TRAN_SETTINGS;
566 if (path->device->transport == XPORT_ATA) {
567 cts.xport_specific.ata.bytecount = sectors *
568 ata_logical_sector_size(ident_buf);
569 cts.xport_specific.ata.valid = CTS_ATA_VALID_BYTECOUNT;
570 } else {
571 cts.xport_specific.sata.bytecount = sectors *
572 ata_logical_sector_size(ident_buf);
573 cts.xport_specific.sata.valid = CTS_SATA_VALID_BYTECOUNT;
574 }
575 xpt_action((union ccb *)&cts);
576 /* Fetch current bytecount from SIM. */
577 bzero(&cts, sizeof(cts));
578 xpt_setup_ccb(&cts.ccb_h, path, CAM_PRIORITY_NONE);
579 cts.ccb_h.func_code = XPT_GET_TRAN_SETTINGS;
581 xpt_action((union ccb *)&cts);
582 if (path->device->transport == XPORT_ATA) {
583 if (cts.xport_specific.ata.valid & CTS_ATA_VALID_BYTECOUNT)
584 bytecount = cts.xport_specific.ata.bytecount;
585 } else {
586 if (cts.xport_specific.sata.valid & CTS_SATA_VALID_BYTECOUNT)
587 bytecount = cts.xport_specific.sata.bytecount;
588 }
589 sectors = bytecount / ata_logical_sector_size(ident_buf);
590
591 cam_fill_ataio(ataio,
592 1,
595 0,
596 NULL,
597 0,
598 30*1000);
599 ata_28bit_cmd(ataio, ATA_SET_MULTI, 0, 0, sectors);
600 break;
601 }
602 case PROBE_INQUIRY:
603 {
604 u_int bytecount;
605
606 bytecount = 8192; /* SATA maximum */
607 /* Fetch user bytecount from SIM. */
608 bzero(&cts, sizeof(cts));
609 xpt_setup_ccb(&cts.ccb_h, path, CAM_PRIORITY_NONE);
610 cts.ccb_h.func_code = XPT_GET_TRAN_SETTINGS;
612 xpt_action((union ccb *)&cts);
613 if (path->device->transport == XPORT_ATA) {
614 if (cts.xport_specific.ata.valid & CTS_ATA_VALID_BYTECOUNT)
615 bytecount = cts.xport_specific.ata.bytecount;
616 } else {
617 if (cts.xport_specific.sata.valid & CTS_SATA_VALID_BYTECOUNT)
618 bytecount = cts.xport_specific.sata.bytecount;
619 }
620 /* Honor device capabilities. */
621 bytecount &= ~1;
622 bytecount = max(2, min(65534, bytecount));
623 if (ident_buf->satacapabilities != 0x0000 &&
624 ident_buf->satacapabilities != 0xffff) {
625 bytecount = min(8192, bytecount);
626 }
627 /* Report bytecount to SIM. */
628 bzero(&cts, sizeof(cts));
629 xpt_setup_ccb(&cts.ccb_h, path, CAM_PRIORITY_NONE);
630 cts.ccb_h.func_code = XPT_SET_TRAN_SETTINGS;
632 if (path->device->transport == XPORT_ATA) {
633 cts.xport_specific.ata.bytecount = bytecount;
634 cts.xport_specific.ata.valid = CTS_ATA_VALID_BYTECOUNT;
635 } else {
636 cts.xport_specific.sata.bytecount = bytecount;
637 cts.xport_specific.sata.valid = CTS_SATA_VALID_BYTECOUNT;
638 }
639 xpt_action((union ccb *)&cts);
640 /* FALLTHROUGH */
641 }
643 {
644 u_int inquiry_len;
645 struct scsi_inquiry_data *inq_buf =
646 &path->device->inq_data;
647
648 if (softc->action == PROBE_INQUIRY)
649 inquiry_len = SHORT_INQUIRY_LENGTH;
650 else
651 inquiry_len = SID_ADDITIONAL_LENGTH(inq_buf);
652 /*
653 * Some parallel SCSI devices fail to send an
654 * ignore wide residue message when dealing with
655 * odd length inquiry requests. Round up to be
656 * safe.
657 */
658 inquiry_len = roundup2(inquiry_len, 2);
659 scsi_inquiry(csio,
660 /*retries*/1,
663 (u_int8_t *)inq_buf,
664 inquiry_len,
665 /*evpd*/FALSE,
666 /*page_code*/0,
668 /*timeout*/60 * 1000);
669 break;
670 }
671 case PROBE_PM_PID:
672 cam_fill_ataio(ataio,
673 1,
675 /*flags*/CAM_DIR_NONE,
676 0,
677 /*data_ptr*/NULL,
678 /*dxfer_len*/0,
679 10 * 1000);
680 ata_pm_read_cmd(ataio, 0, 15);
681 break;
682 case PROBE_PM_PRV:
683 cam_fill_ataio(ataio,
684 1,
686 /*flags*/CAM_DIR_NONE,
687 0,
688 /*data_ptr*/NULL,
689 /*dxfer_len*/0,
690 10 * 1000);
691 ata_pm_read_cmd(ataio, 1, 15);
692 break;
694 cam_fill_ataio(ataio,
695 1,
697 /*flags*/CAM_DIR_IN,
698 0,
699 /*data_ptr*/(u_int8_t *)&softc->ident_data,
700 /*dxfer_len*/sizeof(softc->ident_data),
701 30 * 1000);
702 ata_28bit_cmd(ataio, ATA_SEP_ATTN, 0xEC, 0x02,
703 sizeof(softc->ident_data) / 4);
704 break;
706 cam_fill_ataio(ataio,
707 1,
709 /*flags*/CAM_DIR_IN,
710 0,
711 /*data_ptr*/(u_int8_t *)&softc->ident_data,
712 /*dxfer_len*/sizeof(softc->ident_data),
713 30 * 1000);
714 ata_28bit_cmd(ataio, ATA_SEP_ATTN, 0xEC, 0x00,
715 sizeof(softc->ident_data) / 4);
716 break;
717 default:
718 panic("aprobestart: invalid action state 0x%x\n", softc->action);
719 }
720 start_ccb->ccb_h.flags |= CAM_DEV_QFREEZE;
721 xpt_action(start_ccb);
722}
723
724static void
726{
727 struct ccb_trans_settings cts;
728
729 bzero(&cts, sizeof(cts));
730 xpt_setup_ccb(&cts.ccb_h, periph->path, CAM_PRIORITY_NONE);
731 cts.ccb_h.func_code = XPT_GET_TRAN_SETTINGS;
733 xpt_action((union ccb *)&cts);
734 if ((cts.ccb_h.status & CAM_STATUS_MASK) != CAM_REQ_CMP)
735 return;
736 cts.xport_specific.valid = 0;
737 cts.ccb_h.func_code = XPT_SET_TRAN_SETTINGS;
739 xpt_action((union ccb *)&cts);
740}
741
742static void
743aprobedone(struct cam_periph *periph, union ccb *done_ccb)
744{
745 struct ccb_trans_settings cts;
746 struct ata_params *ident_buf;
747 struct scsi_inquiry_data *inq_buf;
748 aprobe_softc *softc;
749 struct cam_path *path;
750 cam_status status;
751 u_int32_t priority;
752 u_int caps, oif;
753 int changed, found = 1;
754 static const uint8_t fake_device_id_hdr[8] =
755 {0, SVPD_DEVICE_ID, 0, 12,
757
758 CAM_DEBUG(done_ccb->ccb_h.path, CAM_DEBUG_TRACE, ("aprobedone\n"));
759
760 softc = (aprobe_softc *)periph->softc;
761 path = done_ccb->ccb_h.path;
762 priority = done_ccb->ccb_h.pinfo.priority;
763 ident_buf = &path->device->ident_data;
764 inq_buf = &path->device->inq_data;
765
766 if ((done_ccb->ccb_h.status & CAM_STATUS_MASK) != CAM_REQ_CMP) {
767 if (cam_periph_error(done_ccb,
768 0, softc->restart ? (SF_NO_RECOVERY | SF_NO_RETRY) : 0
769 ) == ERESTART) {
770out:
771 /* Drop freeze taken due to CAM_DEV_QFREEZE flag set. */
772 cam_release_devq(path, 0, 0, 0, FALSE);
773 return;
774 }
775 if ((done_ccb->ccb_h.status & CAM_DEV_QFRZN) != 0) {
776 /* Don't wedge the queue */
777 xpt_release_devq(path, /*count*/1, /*run_queue*/TRUE);
778 }
779 status = done_ccb->ccb_h.status & CAM_STATUS_MASK;
780 if (softc->restart) {
781 softc->faults++;
782 if ((done_ccb->ccb_h.status & CAM_STATUS_MASK) ==
784 softc->faults += 4;
785 if (softc->faults < 10)
786 goto done;
787 else
788 softc->restart = 0;
789
790 /* Old PIO2 devices may not support mode setting. */
791 } else if (softc->action == PROBE_SETMODE &&
792 status == CAM_ATA_STATUS_ERROR &&
793 ata_max_pmode(ident_buf) <= ATA_PIO2 &&
794 (ident_buf->capabilities1 & ATA_SUPPORT_IORDY) == 0) {
795 goto noerror;
796
797 /*
798 * Some old WD SATA disks report supported and enabled
799 * device-initiated interface power management, but return
800 * ABORT on attempt to disable it.
801 */
802 } else if (softc->action == PROBE_SETPM &&
803 status == CAM_ATA_STATUS_ERROR) {
804 goto noerror;
805
806 /*
807 * Some old WD SATA disks have broken SPINUP handling.
808 * If we really fail to spin up the disk, then there will be
809 * some media access errors later on, but at least we will
810 * have a device to interact with for recovery attempts.
811 */
812 } else if (softc->action == PROBE_SPINUP &&
813 status == CAM_ATA_STATUS_ERROR) {
814 goto noerror;
815
816 /*
817 * Some HP SATA disks report supported DMA Auto-Activation,
818 * but return ABORT on attempt to enable it.
819 */
820 } else if (softc->action == PROBE_SETDMAAA &&
821 status == CAM_ATA_STATUS_ERROR) {
822 goto noerror;
823
824 /*
825 * SES and SAF-TE SEPs have different IDENTIFY commands,
826 * but SATA specification doesn't tell how to identify them.
827 * Until better way found, just try another if first fail.
828 */
829 } else if (softc->action == PROBE_IDENTIFY_SES &&
830 status == CAM_ATA_STATUS_ERROR) {
832 xpt_release_ccb(done_ccb);
833 xpt_schedule(periph, priority);
834 goto out;
835 }
836
837 /*
838 * If we get to this point, we got an error status back
839 * from the inquiry and the error status doesn't require
840 * automatically retrying the command. Therefore, the
841 * inquiry failed. If we had inquiry information before
842 * for this device, but this latest inquiry command failed,
843 * the device has probably gone away. If this device isn't
844 * already marked unconfigured, notify the peripheral
845 * drivers that this device is no more.
846 */
847device_fail: if ((path->device->flags & CAM_DEV_UNCONFIGURED) == 0)
848 xpt_async(AC_LOST_DEVICE, path, NULL);
850 found = 0;
851 goto done;
852 }
853noerror:
854 if (softc->restart)
855 goto done;
856 switch (softc->action) {
857 case PROBE_RESET:
858 {
859 int sign = (done_ccb->ataio.res.lba_high << 8) +
860 done_ccb->ataio.res.lba_mid;
862 ("SIGNATURE: %04x\n", sign));
863 if (sign == 0x0000 &&
864 done_ccb->ccb_h.target_id != 15) {
865 path->device->protocol = PROTO_ATA;
867 } else if (sign == 0x9669 &&
868 done_ccb->ccb_h.target_id == 15) {
869 /* Report SIM that PM is present. */
870 bzero(&cts, sizeof(cts));
871 xpt_setup_ccb(&cts.ccb_h, path, CAM_PRIORITY_NONE);
872 cts.ccb_h.func_code = XPT_SET_TRAN_SETTINGS;
874 cts.xport_specific.sata.pm_present = 1;
875 cts.xport_specific.sata.valid = CTS_SATA_VALID_PM;
876 xpt_action((union ccb *)&cts);
879 } else if (sign == 0xc33c &&
880 done_ccb->ccb_h.target_id != 15) {
881 path->device->protocol = PROTO_SEMB;
883 } else if (sign == 0xeb14 &&
884 done_ccb->ccb_h.target_id != 15) {
885 path->device->protocol = PROTO_SCSI;
887 } else {
888 if (done_ccb->ccb_h.target_id != 15) {
889 xpt_print(path,
890 "Unexpected signature 0x%04x\n", sign);
891 }
892 goto device_fail;
893 }
894 xpt_release_ccb(done_ccb);
895 xpt_schedule(periph, priority);
896 goto out;
897 }
898 case PROBE_IDENTIFY:
899 {
900 struct ccb_pathinq cpi;
901 int veto = 0;
902
903 /*
904 * Convert to host byte order, and fix the strings.
905 */
906 ident_buf = &softc->ident_data;
907 ata_param_fixup(ident_buf);
908
909 /*
910 * Allow others to veto this ATA disk attachment. This
911 * is mainly used by VMs, whose disk controllers may
912 * share the disks with the simulated ATA controllers.
913 */
914 EVENTHANDLER_INVOKE(ada_probe_veto, path, ident_buf, &veto);
915 if (veto) {
916 goto device_fail;
917 }
918
919 /* Device may need spin-up before IDENTIFY become valid. */
920 if ((ident_buf->specconf == 0x37c8 ||
921 ident_buf->specconf == 0x738c) &&
922 ((ident_buf->config & ATA_RESP_INCOMPLETE) ||
923 softc->spinup == 0)) {
925 xpt_release_ccb(done_ccb);
926 xpt_schedule(periph, priority);
927 goto out;
928 }
929 ident_buf = &path->device->ident_data;
930
931 /* Check that it is the same device as we know. */
932 if ((periph->path->device->flags & CAM_DEV_UNCONFIGURED) == 0) {
933 if (bcmp(softc->ident_data.model, ident_buf->model,
934 sizeof(ident_buf->model)) ||
935 bcmp(softc->ident_data.serial, ident_buf->serial,
936 sizeof(ident_buf->serial))) {
937 /* The device was replaced. */
938 changed = 2;
939 xpt_async(AC_LOST_DEVICE, path, NULL);
940 } else if (bcmp(&softc->ident_data, ident_buf,
941 sizeof(*ident_buf))) {
942 /* The device is the same, but has changed. */
943 changed = 1;
944 } else {
945 /* Nothing has changed. */
946 changed = 0;
947 }
948 } else {
949 /* This is a new device. */
950 changed = 2;
951 }
952
953 if (changed != 0)
954 bcopy(&softc->ident_data, ident_buf, sizeof(struct ata_params));
955 if (changed == 2) {
956 /* Clean up from previous instance of this device */
957 if (path->device->serial_num != NULL) {
958 free(path->device->serial_num, M_CAMXPT);
959 path->device->serial_num = NULL;
960 path->device->serial_num_len = 0;
961 }
962 if (path->device->device_id != NULL) {
963 free(path->device->device_id, M_CAMXPT);
964 path->device->device_id = NULL;
965 path->device->device_id_len = 0;
966 }
967 path->device->serial_num =
968 (u_int8_t *)malloc((sizeof(ident_buf->serial) + 1),
969 M_CAMXPT, M_NOWAIT);
970 if (path->device->serial_num != NULL) {
971 bcopy(ident_buf->serial,
972 path->device->serial_num,
973 sizeof(ident_buf->serial));
974 path->device->serial_num[sizeof(ident_buf->serial)]
975 = '\0';
976 path->device->serial_num_len =
977 strlen(path->device->serial_num);
978 }
979 if (ident_buf->enabled.extension &
980 ATA_SUPPORT_64BITWWN) {
981 path->device->device_id =
982 malloc(16, M_CAMXPT, M_NOWAIT);
983 if (path->device->device_id != NULL) {
984 path->device->device_id_len = 16;
985 bcopy(&fake_device_id_hdr,
986 path->device->device_id, 8);
987 bcopy(ident_buf->wwn,
988 path->device->device_id + 8, 8);
989 ata_bswap(path->device->device_id + 8, 8);
990 }
991 }
993 }
994 if (changed == 1)
995 xpt_async(AC_GETDEV_CHANGED, path, NULL);
996 if (ident_buf->satacapabilities & ATA_SUPPORT_NCQ) {
997 path->device->mintags = 2;
998 path->device->maxtags =
999 ATA_QUEUE_LEN(ident_buf->queue) + 1;
1000 }
1001 ata_find_quirk(path->device);
1002 if (path->device->mintags != 0 &&
1003 path->bus->sim->max_tagged_dev_openings != 0) {
1004 /* Check if the SIM does not want queued commands. */
1005 xpt_path_inq(&cpi, path);
1006 if (cpi.ccb_h.status == CAM_REQ_CMP &&
1007 (cpi.hba_inquiry & PI_TAG_ABLE)) {
1008 /* Report SIM which tags are allowed. */
1009 bzero(&cts, sizeof(cts));
1010 xpt_setup_ccb(&cts.ccb_h, path, CAM_PRIORITY_NONE);
1011 cts.ccb_h.func_code = XPT_SET_TRAN_SETTINGS;
1013 cts.xport_specific.sata.tags = path->device->maxtags;
1014 cts.xport_specific.sata.valid = CTS_SATA_VALID_TAGS;
1015 xpt_action((union ccb *)&cts);
1016 }
1017 }
1019 if (changed == 2)
1022 xpt_release_ccb(done_ccb);
1023 xpt_schedule(periph, priority);
1024 goto out;
1025 }
1026 case PROBE_SPINUP:
1027 if (bootverbose)
1028 xpt_print(path, "Spin-up done\n");
1029 softc->spinup = 1;
1031 xpt_release_ccb(done_ccb);
1032 xpt_schedule(periph, priority);
1033 goto out;
1034 case PROBE_SETMODE:
1035 /* Set supported bits. */
1036 bzero(&cts, sizeof(cts));
1037 xpt_setup_ccb(&cts.ccb_h, path, CAM_PRIORITY_NONE);
1038 cts.ccb_h.func_code = XPT_GET_TRAN_SETTINGS;
1040 xpt_action((union ccb *)&cts);
1041 if (path->device->transport == XPORT_SATA &&
1042 cts.xport_specific.sata.valid & CTS_SATA_VALID_CAPS)
1043 caps = cts.xport_specific.sata.caps & CTS_SATA_CAPS_H;
1044 else if (path->device->transport == XPORT_ATA &&
1045 cts.xport_specific.ata.valid & CTS_ATA_VALID_CAPS)
1046 caps = cts.xport_specific.ata.caps & CTS_ATA_CAPS_H;
1047 else
1048 caps = 0;
1049 if (path->device->transport == XPORT_SATA &&
1050 ident_buf->satacapabilities != 0xffff) {
1051 if (ident_buf->satacapabilities & ATA_SUPPORT_IFPWRMNGTRCV)
1052 caps |= CTS_SATA_CAPS_D_PMREQ;
1053 if (ident_buf->satacapabilities & ATA_SUPPORT_HAPST)
1054 caps |= CTS_SATA_CAPS_D_APST;
1055 }
1056 /* Mask unwanted bits. */
1057 bzero(&cts, sizeof(cts));
1058 xpt_setup_ccb(&cts.ccb_h, path, CAM_PRIORITY_NONE);
1059 cts.ccb_h.func_code = XPT_GET_TRAN_SETTINGS;
1061 xpt_action((union ccb *)&cts);
1062 if (path->device->transport == XPORT_SATA &&
1063 cts.xport_specific.sata.valid & CTS_SATA_VALID_CAPS)
1064 caps &= cts.xport_specific.sata.caps;
1065 else if (path->device->transport == XPORT_ATA &&
1066 cts.xport_specific.ata.valid & CTS_ATA_VALID_CAPS)
1067 caps &= cts.xport_specific.ata.caps;
1068 else
1069 caps = 0;
1070 /*
1071 * Remember what transport thinks about 48-bit DMA. If
1072 * capability information is not provided or transport is
1073 * SATA, we take support for granted.
1074 */
1075 oif = path->device->inq_flags;
1076 if (!(path->device->inq_flags & SID_DMA) ||
1077 (path->device->transport == XPORT_ATA &&
1078 (cts.xport_specific.ata.valid & CTS_ATA_VALID_CAPS) &&
1079 !(caps & CTS_ATA_CAPS_H_DMA48)))
1080 path->device->inq_flags &= ~SID_DMA48;
1081 else
1082 path->device->inq_flags |= SID_DMA48;
1083 if (path->device->inq_flags != oif)
1084 xpt_async(AC_GETDEV_CHANGED, path, NULL);
1085 /* Store result to SIM. */
1086 bzero(&cts, sizeof(cts));
1087 xpt_setup_ccb(&cts.ccb_h, path, CAM_PRIORITY_NONE);
1088 cts.ccb_h.func_code = XPT_SET_TRAN_SETTINGS;
1090 if (path->device->transport == XPORT_SATA) {
1091 cts.xport_specific.sata.caps = caps;
1092 cts.xport_specific.sata.valid = CTS_SATA_VALID_CAPS;
1093 } else {
1094 cts.xport_specific.ata.caps = caps;
1095 cts.xport_specific.ata.valid = CTS_ATA_VALID_CAPS;
1096 }
1097 xpt_action((union ccb *)&cts);
1098 softc->caps = caps;
1099 if (path->device->transport != XPORT_SATA)
1100 goto notsata;
1101 if ((ident_buf->satasupport & ATA_SUPPORT_IFPWRMNGT) &&
1102 (!(softc->caps & CTS_SATA_CAPS_H_PMREQ)) !=
1103 (!(ident_buf->sataenabled & ATA_SUPPORT_IFPWRMNGT))) {
1105 xpt_release_ccb(done_ccb);
1106 xpt_schedule(periph, priority);
1107 goto out;
1108 }
1109 /* FALLTHROUGH */
1110 case PROBE_SETPM:
1111 if (ident_buf->satacapabilities != 0xffff &&
1112 (ident_buf->satacapabilities & ATA_SUPPORT_DAPST) &&
1113 (!(softc->caps & CTS_SATA_CAPS_H_APST)) !=
1114 (!(ident_buf->sataenabled & ATA_ENABLED_DAPST))) {
1116 xpt_release_ccb(done_ccb);
1117 xpt_schedule(periph, priority);
1118 goto out;
1119 }
1120 /* FALLTHROUGH */
1121 case PROBE_SETAPST:
1122 if ((ident_buf->satasupport & ATA_SUPPORT_AUTOACTIVATE) &&
1123 (!(softc->caps & CTS_SATA_CAPS_H_DMAAA)) !=
1124 (!(ident_buf->sataenabled & ATA_SUPPORT_AUTOACTIVATE))) {
1126 xpt_release_ccb(done_ccb);
1127 xpt_schedule(periph, priority);
1128 goto out;
1129 }
1130 /* FALLTHROUGH */
1131 case PROBE_SETDMAAA:
1132 if (path->device->protocol != PROTO_ATA &&
1133 (ident_buf->satasupport & ATA_SUPPORT_ASYNCNOTIF) &&
1134 (!(softc->caps & CTS_SATA_CAPS_H_AN)) !=
1135 (!(ident_buf->sataenabled & ATA_SUPPORT_ASYNCNOTIF))) {
1137 xpt_release_ccb(done_ccb);
1138 xpt_schedule(periph, priority);
1139 goto out;
1140 }
1141 /* FALLTHROUGH */
1142 case PROBE_SETAN:
1143notsata:
1144 if (path->device->protocol == PROTO_ATA) {
1146 } else {
1148 }
1149 xpt_release_ccb(done_ccb);
1150 xpt_schedule(periph, priority);
1151 goto out;
1152 case PROBE_SET_MULTI:
1153 if (periph->path->device->flags & CAM_DEV_UNCONFIGURED) {
1154 path->device->flags &= ~CAM_DEV_UNCONFIGURED;
1156 done_ccb->ccb_h.func_code = XPT_GDEV_TYPE;
1157 xpt_action(done_ccb);
1158 xpt_async(AC_FOUND_DEVICE, path, done_ccb);
1159 }
1161 break;
1162 case PROBE_INQUIRY:
1163 case PROBE_FULL_INQUIRY:
1164 {
1165 u_int8_t periph_qual, len;
1166
1168
1169 periph_qual = SID_QUAL(inq_buf);
1170
1171 if (periph_qual != SID_QUAL_LU_CONNECTED &&
1172 periph_qual != SID_QUAL_LU_OFFLINE)
1173 break;
1174
1175 /*
1176 * We conservatively request only
1177 * SHORT_INQUIRY_LEN bytes of inquiry
1178 * information during our first try
1179 * at sending an INQUIRY. If the device
1180 * has more information to give,
1181 * perform a second request specifying
1182 * the amount of information the device
1183 * is willing to give.
1184 */
1185 len = inq_buf->additional_length
1186 + offsetof(struct scsi_inquiry_data, additional_length) + 1;
1187 if (softc->action == PROBE_INQUIRY
1188 && len > SHORT_INQUIRY_LENGTH) {
1190 xpt_release_ccb(done_ccb);
1191 xpt_schedule(periph, priority);
1192 goto out;
1193 }
1194
1196 if (periph->path->device->flags & CAM_DEV_UNCONFIGURED) {
1197 path->device->flags &= ~CAM_DEV_UNCONFIGURED;
1199 done_ccb->ccb_h.func_code = XPT_GDEV_TYPE;
1200 xpt_action(done_ccb);
1201 xpt_async(AC_FOUND_DEVICE, path, done_ccb);
1202 }
1204 break;
1205 }
1206 case PROBE_PM_PID:
1207 if ((path->device->flags & CAM_DEV_IDENTIFY_DATA_VALID) == 0)
1208 bzero(ident_buf, sizeof(*ident_buf));
1209 softc->pm_pid = (done_ccb->ataio.res.lba_high << 24) +
1210 (done_ccb->ataio.res.lba_mid << 16) +
1211 (done_ccb->ataio.res.lba_low << 8) +
1212 done_ccb->ataio.res.sector_count;
1213 ((uint32_t *)ident_buf)[0] = softc->pm_pid;
1214 snprintf(ident_buf->model, sizeof(ident_buf->model),
1215 "Port Multiplier %08x", softc->pm_pid);
1217 xpt_release_ccb(done_ccb);
1218 xpt_schedule(periph, priority);
1219 goto out;
1220 case PROBE_PM_PRV:
1221 softc->pm_prv = (done_ccb->ataio.res.lba_high << 24) +
1222 (done_ccb->ataio.res.lba_mid << 16) +
1223 (done_ccb->ataio.res.lba_low << 8) +
1224 done_ccb->ataio.res.sector_count;
1225 ((uint32_t *)ident_buf)[1] = softc->pm_prv;
1226 snprintf(ident_buf->revision, sizeof(ident_buf->revision),
1227 "%04x", softc->pm_prv);
1230 if (periph->path->device->flags & CAM_DEV_UNCONFIGURED)
1232 /* Set supported bits. */
1233 bzero(&cts, sizeof(cts));
1234 xpt_setup_ccb(&cts.ccb_h, path, CAM_PRIORITY_NONE);
1235 cts.ccb_h.func_code = XPT_GET_TRAN_SETTINGS;
1237 xpt_action((union ccb *)&cts);
1238 if (cts.xport_specific.sata.valid & CTS_SATA_VALID_CAPS)
1239 caps = cts.xport_specific.sata.caps & CTS_SATA_CAPS_H;
1240 else
1241 caps = 0;
1242 /* All PMPs must support PM requests. */
1243 caps |= CTS_SATA_CAPS_D_PMREQ;
1244 /* Mask unwanted bits. */
1245 bzero(&cts, sizeof(cts));
1246 xpt_setup_ccb(&cts.ccb_h, path, CAM_PRIORITY_NONE);
1247 cts.ccb_h.func_code = XPT_GET_TRAN_SETTINGS;
1249 xpt_action((union ccb *)&cts);
1250 if (cts.xport_specific.sata.valid & CTS_SATA_VALID_CAPS)
1251 caps &= cts.xport_specific.sata.caps;
1252 else
1253 caps = 0;
1254 /* Remember what transport thinks about AEN. */
1255 oif = path->device->inq_flags;
1256 if ((caps & CTS_SATA_CAPS_H_AN) && path->device->protocol != PROTO_ATA)
1257 path->device->inq_flags |= SID_AEN;
1258 else
1259 path->device->inq_flags &= ~SID_AEN;
1260 /* Store result to SIM. */
1261 bzero(&cts, sizeof(cts));
1262 xpt_setup_ccb(&cts.ccb_h, path, CAM_PRIORITY_NONE);
1263 cts.ccb_h.func_code = XPT_SET_TRAN_SETTINGS;
1265 cts.xport_specific.sata.caps = caps;
1266 cts.xport_specific.sata.valid = CTS_SATA_VALID_CAPS;
1267 xpt_action((union ccb *)&cts);
1268 softc->caps = caps;
1269 if (periph->path->device->flags & CAM_DEV_UNCONFIGURED) {
1270 path->device->flags &= ~CAM_DEV_UNCONFIGURED;
1272 done_ccb->ccb_h.func_code = XPT_GDEV_TYPE;
1273 xpt_action(done_ccb);
1274 xpt_async(AC_FOUND_DEVICE, path, done_ccb);
1275 } else {
1276 if (path->device->inq_flags != oif)
1277 xpt_async(AC_GETDEV_CHANGED, path, NULL);
1278 done_ccb->ccb_h.func_code = XPT_GDEV_TYPE;
1279 xpt_action(done_ccb);
1280 xpt_async(AC_SCSI_AEN, path, done_ccb);
1281 }
1283 break;
1284 case PROBE_IDENTIFY_SES:
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 changed = 2;
1291 xpt_async(AC_LOST_DEVICE, path, NULL);
1292 } else {
1293 bcopy(&softc->ident_data, ident_buf, sizeof(struct ata_params));
1294 changed = 0;
1295 }
1296 } else
1297 changed = 2;
1298 if (changed) {
1299 bcopy(&softc->ident_data, ident_buf, sizeof(struct ata_params));
1300 /* Clean up from previous instance of this device */
1301 if (path->device->device_id != NULL) {
1302 free(path->device->device_id, M_CAMXPT);
1303 path->device->device_id = NULL;
1304 path->device->device_id_len = 0;
1305 }
1306 path->device->device_id =
1307 malloc(16, M_CAMXPT, M_NOWAIT);
1308 if (path->device->device_id != NULL) {
1309 path->device->device_id_len = 16;
1310 bcopy(&fake_device_id_hdr,
1311 path->device->device_id, 8);
1312 bcopy(((uint8_t*)ident_buf) + 2,
1313 path->device->device_id + 8, 8);
1314 }
1315
1317 }
1319 if (changed)
1321
1322 if (periph->path->device->flags & CAM_DEV_UNCONFIGURED) {
1323 path->device->flags &= ~CAM_DEV_UNCONFIGURED;
1325 done_ccb->ccb_h.func_code = XPT_GDEV_TYPE;
1326 xpt_action(done_ccb);
1327 xpt_async(AC_FOUND_DEVICE, path, done_ccb);
1328 }
1330 break;
1331 default:
1332 panic("aprobedone: invalid action state 0x%x\n", softc->action);
1333 }
1334done:
1335 if (softc->restart) {
1336 softc->restart = 0;
1337 xpt_release_ccb(done_ccb);
1338 aprobeschedule(periph);
1339 goto out;
1340 }
1341 xpt_release_ccb(done_ccb);
1342 CAM_DEBUG(periph->path, CAM_DEBUG_PROBE, ("Probe completed\n"));
1343 while ((done_ccb = (union ccb *)TAILQ_FIRST(&softc->request_ccbs))) {
1344 TAILQ_REMOVE(&softc->request_ccbs,
1345 &done_ccb->ccb_h, periph_links.tqe);
1346 done_ccb->ccb_h.status = found ? CAM_REQ_CMP : CAM_REQ_CMP_ERR;
1347 xpt_done(done_ccb);
1348 }
1349 /* Drop freeze taken due to CAM_DEV_QFREEZE flag set. */
1350 cam_release_devq(path, 0, 0, 0, FALSE);
1351 cam_periph_invalidate(periph);
1353}
1354
1355static void
1357{
1358 free(periph->softc, M_CAMXPT);
1359}
1360
1361static void
1362ata_find_quirk(struct cam_ed *device)
1363{
1364 struct ata_quirk_entry *quirk;
1365 caddr_t match;
1366
1367 match = cam_quirkmatch((caddr_t)&device->ident_data,
1368 (caddr_t)ata_quirk_table,
1369 nitems(ata_quirk_table),
1371
1372 if (match == NULL)
1373 panic("xpt_find_quirk: device didn't match wildcard entry!!");
1374
1375 quirk = (struct ata_quirk_entry *)match;
1376 device->quirk = quirk;
1377 if (quirk->quirks & CAM_QUIRK_MAXTAGS) {
1378 device->mintags = quirk->mintags;
1379 device->maxtags = quirk->maxtags;
1380 }
1381}
1382
1383typedef struct {
1388
1389/*
1390 * To start a scan, request_ccb is an XPT_SCAN_BUS ccb.
1391 * As the scan progresses, xpt_scan_bus is used as the
1392 * callback on completion function.
1393 */
1394static void
1395ata_scan_bus(struct cam_periph *periph, union ccb *request_ccb)
1396{
1397 struct cam_path *path;
1398 ata_scan_bus_info *scan_info;
1399 union ccb *work_ccb, *reset_ccb;
1400 struct mtx *mtx;
1401 cam_status status;
1402
1403 CAM_DEBUG(request_ccb->ccb_h.path, CAM_DEBUG_TRACE,
1404 ("xpt_scan_bus\n"));
1405 switch (request_ccb->ccb_h.func_code) {
1406 case XPT_SCAN_BUS:
1407 case XPT_SCAN_TGT:
1408 /* Find out the characteristics of the bus */
1409 work_ccb = xpt_alloc_ccb_nowait();
1410 if (work_ccb == NULL) {
1411 request_ccb->ccb_h.status = CAM_RESRC_UNAVAIL;
1412 xpt_done(request_ccb);
1413 return;
1414 }
1415 xpt_path_inq(&work_ccb->cpi, request_ccb->ccb_h.path);
1416 if (work_ccb->ccb_h.status != CAM_REQ_CMP) {
1417 request_ccb->ccb_h.status = work_ccb->ccb_h.status;
1418 xpt_free_ccb(work_ccb);
1419 xpt_done(request_ccb);
1420 return;
1421 }
1422
1423 /* We may need to reset bus first, if we haven't done it yet. */
1424 if ((work_ccb->cpi.hba_inquiry &
1426 !(work_ccb->cpi.hba_misc & PIM_NOBUSRESET) &&
1427 !timevalisset(&request_ccb->ccb_h.path->bus->last_reset)) {
1428 reset_ccb = xpt_alloc_ccb_nowait();
1429 if (reset_ccb == NULL) {
1430 request_ccb->ccb_h.status = CAM_RESRC_UNAVAIL;
1431 xpt_free_ccb(work_ccb);
1432 xpt_done(request_ccb);
1433 return;
1434 }
1435 xpt_setup_ccb(&reset_ccb->ccb_h, request_ccb->ccb_h.path,
1437 reset_ccb->ccb_h.func_code = XPT_RESET_BUS;
1438 xpt_action(reset_ccb);
1439 if (reset_ccb->ccb_h.status != CAM_REQ_CMP) {
1440 request_ccb->ccb_h.status = reset_ccb->ccb_h.status;
1441 xpt_free_ccb(reset_ccb);
1442 xpt_free_ccb(work_ccb);
1443 xpt_done(request_ccb);
1444 return;
1445 }
1446 xpt_free_ccb(reset_ccb);
1447 }
1448
1449 /* Save some state for use while we probe for devices */
1450 scan_info = (ata_scan_bus_info *)
1451 malloc(sizeof(ata_scan_bus_info), M_CAMXPT, M_NOWAIT);
1452 if (scan_info == NULL) {
1453 request_ccb->ccb_h.status = CAM_RESRC_UNAVAIL;
1454 xpt_free_ccb(work_ccb);
1455 xpt_done(request_ccb);
1456 return;
1457 }
1458 scan_info->request_ccb = request_ccb;
1459 scan_info->cpi = &work_ccb->cpi;
1460 /* If PM supported, probe it first. */
1461 if (scan_info->cpi->hba_inquiry & PI_SATAPM)
1462 scan_info->counter = scan_info->cpi->max_target;
1463 else
1464 scan_info->counter = 0;
1465
1466 work_ccb = xpt_alloc_ccb_nowait();
1467 if (work_ccb == NULL) {
1468 free(scan_info, M_CAMXPT);
1469 request_ccb->ccb_h.status = CAM_RESRC_UNAVAIL;
1470 xpt_done(request_ccb);
1471 break;
1472 }
1473 mtx = xpt_path_mtx(scan_info->request_ccb->ccb_h.path);
1474 goto scan_next;
1475 case XPT_SCAN_LUN:
1476 work_ccb = request_ccb;
1477 /* Reuse the same CCB to query if a device was really found */
1478 scan_info = (ata_scan_bus_info *)work_ccb->ccb_h.ppriv_ptr0;
1479 mtx = xpt_path_mtx(scan_info->request_ccb->ccb_h.path);
1480 mtx_lock(mtx);
1481 /* If there is PMP... */
1482 if ((scan_info->cpi->hba_inquiry & PI_SATAPM) &&
1483 (scan_info->counter == scan_info->cpi->max_target)) {
1484 if (work_ccb->ccb_h.status == CAM_REQ_CMP) {
1485 /* everything else will be probed by it */
1486 /* Free the current request path- we're done with it. */
1487 xpt_free_path(work_ccb->ccb_h.path);
1488 goto done;
1489 } else {
1490 struct ccb_trans_settings cts;
1491
1492 /* Report SIM that PM is absent. */
1493 bzero(&cts, sizeof(cts));
1494 xpt_setup_ccb(&cts.ccb_h,
1495 work_ccb->ccb_h.path, CAM_PRIORITY_NONE);
1496 cts.ccb_h.func_code = XPT_SET_TRAN_SETTINGS;
1498 cts.xport_specific.sata.pm_present = 0;
1499 cts.xport_specific.sata.valid = CTS_SATA_VALID_PM;
1500 xpt_action((union ccb *)&cts);
1501 }
1502 }
1503 /* Free the current request path- we're done with it. */
1504 xpt_free_path(work_ccb->ccb_h.path);
1505 if (scan_info->counter ==
1506 ((scan_info->cpi->hba_inquiry & PI_SATAPM) ?
1507 0 : scan_info->cpi->max_target)) {
1508done:
1509 mtx_unlock(mtx);
1510 xpt_free_ccb(work_ccb);
1511 xpt_free_ccb((union ccb *)scan_info->cpi);
1512 request_ccb = scan_info->request_ccb;
1513 free(scan_info, M_CAMXPT);
1514 request_ccb->ccb_h.status = CAM_REQ_CMP;
1515 xpt_done(request_ccb);
1516 break;
1517 }
1518 /* Take next device. Wrap from max (PMP) to 0. */
1519 scan_info->counter = (scan_info->counter + 1 ) %
1520 (scan_info->cpi->max_target + 1);
1521scan_next:
1522 status = xpt_create_path(&path, NULL,
1523 scan_info->request_ccb->ccb_h.path_id,
1524 scan_info->counter, 0);
1525 if (status != CAM_REQ_CMP) {
1526 if (request_ccb->ccb_h.func_code == XPT_SCAN_LUN)
1527 mtx_unlock(mtx);
1528 printf("xpt_scan_bus: xpt_create_path failed"
1529 " with status %#x, bus scan halted\n",
1530 status);
1531 xpt_free_ccb(work_ccb);
1532 xpt_free_ccb((union ccb *)scan_info->cpi);
1533 request_ccb = scan_info->request_ccb;
1534 free(scan_info, M_CAMXPT);
1535 request_ccb->ccb_h.status = status;
1536 xpt_done(request_ccb);
1537 break;
1538 }
1539 xpt_setup_ccb(&work_ccb->ccb_h, path,
1540 scan_info->request_ccb->ccb_h.pinfo.priority);
1541 work_ccb->ccb_h.func_code = XPT_SCAN_LUN;
1542 work_ccb->ccb_h.cbfcnp = ata_scan_bus;
1543 work_ccb->ccb_h.flags |= CAM_UNLOCKED;
1544 work_ccb->ccb_h.ppriv_ptr0 = scan_info;
1545 work_ccb->crcn.flags = scan_info->request_ccb->crcn.flags;
1546 mtx_unlock(mtx);
1547 if (request_ccb->ccb_h.func_code == XPT_SCAN_LUN)
1548 mtx = NULL;
1549 xpt_action(work_ccb);
1550 if (mtx != NULL)
1551 mtx_lock(mtx);
1552 break;
1553 default:
1554 break;
1555 }
1556}
1557
1558static void
1559ata_scan_lun(struct cam_periph *periph, struct cam_path *path,
1560 cam_flags flags, union ccb *request_ccb)
1561{
1562 struct ccb_pathinq cpi;
1563 cam_status status;
1564 struct cam_path *new_path;
1565 struct cam_periph *old_periph;
1566 int lock;
1567
1568 CAM_DEBUG(path, CAM_DEBUG_TRACE, ("xpt_scan_lun\n"));
1569
1570 xpt_path_inq(&cpi, path);
1571 if (cpi.ccb_h.status != CAM_REQ_CMP) {
1572 if (request_ccb != NULL) {
1573 request_ccb->ccb_h.status = cpi.ccb_h.status;
1574 xpt_done(request_ccb);
1575 }
1576 return;
1577 }
1578
1579 if (request_ccb == NULL) {
1580 request_ccb = xpt_alloc_ccb_nowait();
1581 if (request_ccb == NULL) {
1582 xpt_print(path, "xpt_scan_lun: can't allocate CCB, "
1583 "can't continue\n");
1584 return;
1585 }
1586 status = xpt_create_path(&new_path, NULL,
1587 path->bus->path_id,
1589 path->device->lun_id);
1590 if (status != CAM_REQ_CMP) {
1591 xpt_print(path, "xpt_scan_lun: can't create path, "
1592 "can't continue\n");
1593 xpt_free_ccb(request_ccb);
1594 return;
1595 }
1596 xpt_setup_ccb(&request_ccb->ccb_h, new_path, CAM_PRIORITY_XPT);
1597 request_ccb->ccb_h.cbfcnp = axptscandone;
1598 request_ccb->ccb_h.flags |= CAM_UNLOCKED;
1599 request_ccb->ccb_h.func_code = XPT_SCAN_LUN;
1600 request_ccb->crcn.flags = flags;
1601 }
1602
1603 lock = (xpt_path_owned(path) == 0);
1604 if (lock)
1606 if ((old_periph = cam_periph_find(path, "aprobe")) != NULL) {
1607 if ((old_periph->flags & CAM_PERIPH_INVALID) == 0) {
1609
1610 softc = (aprobe_softc *)old_periph->softc;
1611 TAILQ_INSERT_TAIL(&softc->request_ccbs,
1612 &request_ccb->ccb_h, periph_links.tqe);
1613 softc->restart = 1;
1614 } else {
1615 request_ccb->ccb_h.status = CAM_REQ_CMP_ERR;
1616 xpt_done(request_ccb);
1617 }
1618 } else {
1620 aprobestart, "aprobe",
1622 request_ccb->ccb_h.path, NULL, 0,
1623 request_ccb);
1624
1625 if (status != CAM_REQ_CMP) {
1626 xpt_print(path, "xpt_scan_lun: cam_alloc_periph "
1627 "returned an error, can't continue probe\n");
1628 request_ccb->ccb_h.status = status;
1629 xpt_done(request_ccb);
1630 }
1631 }
1632 if (lock)
1634}
1635
1636static void
1637axptscandone(struct cam_periph *periph, union ccb *done_ccb)
1638{
1639
1640 xpt_free_path(done_ccb->ccb_h.path);
1641 xpt_free_ccb(done_ccb);
1642}
1643
1644static struct cam_ed *
1646{
1647 struct ata_quirk_entry *quirk;
1648 struct cam_ed *device;
1649
1650 device = xpt_alloc_device(bus, target, lun_id);
1651 if (device == NULL)
1652 return (NULL);
1653
1654 /*
1655 * Take the default quirk entry until we have inquiry
1656 * data and can determine a better quirk to use.
1657 */
1658 quirk = &ata_quirk_table[nitems(ata_quirk_table) - 1];
1659 device->quirk = (void *)quirk;
1660 device->mintags = 0;
1661 device->maxtags = 0;
1662 bzero(&device->inq_data, sizeof(device->inq_data));
1663 device->inq_flags = 0;
1664 device->queue_flags = 0;
1665 device->serial_num = NULL;
1666 device->serial_num_len = 0;
1667 return (device);
1668}
1669
1670static void
1672{
1673 struct ccb_pathinq cpi;
1674 struct ccb_trans_settings cts;
1675 struct scsi_inquiry_data *inq_buf = NULL;
1676 struct ata_params *ident_buf = NULL;
1677
1678 /* Get transport information from the SIM */
1679 xpt_path_inq(&cpi, path);
1680
1681 path->device->transport = cpi.transport;
1682 if ((path->device->flags & CAM_DEV_INQUIRY_DATA_VALID) != 0)
1683 inq_buf = &path->device->inq_data;
1684 if ((path->device->flags & CAM_DEV_IDENTIFY_DATA_VALID) != 0)
1685 ident_buf = &path->device->ident_data;
1686 if (path->device->protocol == PROTO_ATA) {
1687 path->device->protocol_version = ident_buf ?
1688 ata_version(ident_buf->version_major) : cpi.protocol_version;
1689 } else if (path->device->protocol == PROTO_SCSI) {
1690 path->device->protocol_version = inq_buf ?
1691 SID_ANSI_REV(inq_buf) : cpi.protocol_version;
1692 }
1693 path->device->transport_version = ident_buf ?
1694 ata_version(ident_buf->version_major) : cpi.transport_version;
1695
1696 /* Tell the controller what we think */
1697 bzero(&cts, sizeof(cts));
1698 xpt_setup_ccb(&cts.ccb_h, path, CAM_PRIORITY_NONE);
1699 cts.ccb_h.func_code = XPT_SET_TRAN_SETTINGS;
1701 cts.transport = path->device->transport;
1702 cts.transport_version = path->device->transport_version;
1703 cts.protocol = path->device->protocol;
1704 cts.protocol_version = path->device->protocol_version;
1705 cts.proto_specific.valid = 0;
1706 if (ident_buf) {
1707 if (path->device->transport == XPORT_ATA) {
1708 cts.xport_specific.ata.atapi =
1709 (ident_buf->config == ATA_PROTO_CFA) ? 0 :
1710 ((ident_buf->config & ATA_PROTO_MASK) == ATA_PROTO_ATAPI_16) ? 16 :
1711 ((ident_buf->config & ATA_PROTO_MASK) == ATA_PROTO_ATAPI_12) ? 12 : 0;
1712 cts.xport_specific.ata.valid = CTS_ATA_VALID_ATAPI;
1713 } else {
1714 cts.xport_specific.sata.atapi =
1715 (ident_buf->config == ATA_PROTO_CFA) ? 0 :
1716 ((ident_buf->config & ATA_PROTO_MASK) == ATA_PROTO_ATAPI_16) ? 16 :
1717 ((ident_buf->config & ATA_PROTO_MASK) == ATA_PROTO_ATAPI_12) ? 12 : 0;
1718 cts.xport_specific.sata.valid = CTS_SATA_VALID_ATAPI;
1719 }
1720 } else
1721 cts.xport_specific.valid = 0;
1722 xpt_action((union ccb *)&cts);
1723}
1724
1725static void
1726ata_dev_advinfo(union ccb *start_ccb)
1727{
1728 struct cam_ed *device;
1729 struct ccb_dev_advinfo *cdai;
1730 off_t amt;
1731
1732 xpt_path_assert(start_ccb->ccb_h.path, MA_OWNED);
1733 start_ccb->ccb_h.status = CAM_REQ_INVALID;
1734 device = start_ccb->ccb_h.path->device;
1735 cdai = &start_ccb->cdai;
1736 switch(cdai->buftype) {
1738 if (cdai->flags & CDAI_FLAG_STORE)
1739 return;
1740 cdai->provsiz = device->device_id_len;
1741 if (device->device_id_len == 0)
1742 break;
1743 amt = device->device_id_len;
1744 if (cdai->provsiz > cdai->bufsiz)
1745 amt = cdai->bufsiz;
1746 memcpy(cdai->buf, device->device_id, amt);
1747 break;
1749 if (cdai->flags & CDAI_FLAG_STORE)
1750 return;
1751 cdai->provsiz = device->serial_num_len;
1752 if (device->serial_num_len == 0)
1753 break;
1754 amt = device->serial_num_len;
1755 if (cdai->provsiz > cdai->bufsiz)
1756 amt = cdai->bufsiz;
1757 memcpy(cdai->buf, device->serial_num, amt);
1758 break;
1760 if (cdai->flags & CDAI_FLAG_STORE) {
1761 if (device->physpath != NULL) {
1762 free(device->physpath, M_CAMXPT);
1763 device->physpath = NULL;
1764 device->physpath_len = 0;
1765 }
1766 /* Clear existing buffer if zero length */
1767 if (cdai->bufsiz == 0)
1768 break;
1769 device->physpath = malloc(cdai->bufsiz, M_CAMXPT, M_NOWAIT);
1770 if (device->physpath == NULL) {
1771 start_ccb->ccb_h.status = CAM_REQ_ABORTED;
1772 return;
1773 }
1774 device->physpath_len = cdai->bufsiz;
1775 memcpy(device->physpath, cdai->buf, cdai->bufsiz);
1776 } else {
1777 cdai->provsiz = device->physpath_len;
1778 if (device->physpath_len == 0)
1779 break;
1780 amt = device->physpath_len;
1781 if (cdai->provsiz > cdai->bufsiz)
1782 amt = cdai->bufsiz;
1783 memcpy(cdai->buf, device->physpath, amt);
1784 }
1785 break;
1786 default:
1787 return;
1788 }
1789 start_ccb->ccb_h.status = CAM_REQ_CMP;
1790
1791 if (cdai->flags & CDAI_FLAG_STORE) {
1793 (void *)(uintptr_t)cdai->buftype);
1794 }
1795}
1796
1797static void
1798ata_action(union ccb *start_ccb)
1799{
1800
1801 if (start_ccb->ccb_h.func_code != XPT_ATA_IO) {
1802 KASSERT((start_ccb->ccb_h.alloc_flags & CAM_CCB_FROM_UMA) == 0,
1803 ("%s: ccb %p, func_code %#x should not be allocated "
1804 "from UMA zone\n",
1805 __func__, start_ccb, start_ccb->ccb_h.func_code));
1806 }
1807
1808 switch (start_ccb->ccb_h.func_code) {
1810 {
1811 ata_set_transfer_settings(&start_ccb->cts,
1812 start_ccb->ccb_h.path,
1813 /*async_update*/FALSE);
1814 break;
1815 }
1816 case XPT_SCAN_BUS:
1817 case XPT_SCAN_TGT:
1818 ata_scan_bus(start_ccb->ccb_h.path->periph, start_ccb);
1819 break;
1820 case XPT_SCAN_LUN:
1821 ata_scan_lun(start_ccb->ccb_h.path->periph,
1822 start_ccb->ccb_h.path, start_ccb->crcn.flags,
1823 start_ccb);
1824 break;
1826 {
1827 ata_get_transfer_settings(&start_ccb->cts);
1828 break;
1829 }
1830 case XPT_SCSI_IO:
1831 {
1832 struct cam_ed *device;
1833 u_int maxlen = 0;
1834
1835 device = start_ccb->ccb_h.path->device;
1836 if (device->protocol == PROTO_SCSI &&
1837 (device->flags & CAM_DEV_IDENTIFY_DATA_VALID)) {
1838 uint16_t p =
1839 device->ident_data.config & ATA_PROTO_MASK;
1840
1841 maxlen =
1842 (device->ident_data.config == ATA_PROTO_CFA) ? 0 :
1843 (p == ATA_PROTO_ATAPI_16) ? 16 :
1844 (p == ATA_PROTO_ATAPI_12) ? 12 : 0;
1845 }
1846 if (start_ccb->csio.cdb_len > maxlen) {
1847 start_ccb->ccb_h.status = CAM_REQ_INVALID;
1848 xpt_done(start_ccb);
1849 break;
1850 }
1851 xpt_action_default(start_ccb);
1852 break;
1853 }
1854 case XPT_DEV_ADVINFO:
1855 {
1856 ata_dev_advinfo(start_ccb);
1857 break;
1858 }
1859 default:
1860 xpt_action_default(start_ccb);
1861 break;
1862 }
1863}
1864
1865static void
1867{
1868 struct ccb_trans_settings_ata *ata;
1869 struct ccb_trans_settings_scsi *scsi;
1870 struct cam_ed *device;
1871
1872 device = cts->ccb_h.path->device;
1873 xpt_action_default((union ccb *)cts);
1874
1875 if (cts->protocol == PROTO_UNKNOWN ||
1876 cts->protocol == PROTO_UNSPECIFIED) {
1877 cts->protocol = device->protocol;
1878 cts->protocol_version = device->protocol_version;
1879 }
1880
1881 if (cts->protocol == PROTO_ATA) {
1882 ata = &cts->proto_specific.ata;
1883 if ((ata->valid & CTS_ATA_VALID_TQ) == 0) {
1884 ata->valid |= CTS_ATA_VALID_TQ;
1885 if (cts->type == CTS_TYPE_USER_SETTINGS ||
1886 (device->flags & CAM_DEV_TAG_AFTER_COUNT) != 0 ||
1887 (device->inq_flags & SID_CmdQue) != 0)
1889 }
1890 }
1891 if (cts->protocol == PROTO_SCSI) {
1892 scsi = &cts->proto_specific.scsi;
1893 if ((scsi->valid & CTS_SCSI_VALID_TQ) == 0) {
1894 scsi->valid |= CTS_SCSI_VALID_TQ;
1895 if (cts->type == CTS_TYPE_USER_SETTINGS ||
1896 (device->flags & CAM_DEV_TAG_AFTER_COUNT) != 0 ||
1897 (device->inq_flags & SID_CmdQue) != 0)
1899 }
1900 }
1901
1902 if (cts->transport == XPORT_UNKNOWN ||
1903 cts->transport == XPORT_UNSPECIFIED) {
1904 cts->transport = device->transport;
1905 cts->transport_version = device->transport_version;
1906 }
1907}
1908
1909static void
1911 int async_update)
1912{
1913 struct ccb_pathinq cpi;
1914 struct ccb_trans_settings_ata *ata;
1915 struct ccb_trans_settings_scsi *scsi;
1916 struct ata_params *ident_data;
1917 struct scsi_inquiry_data *inq_data;
1918 struct cam_ed *device;
1919
1920 if (path == NULL || (device = path->device) == NULL) {
1921 cts->ccb_h.status = CAM_PATH_INVALID;
1922 xpt_done((union ccb *)cts);
1923 return;
1924 }
1925
1926 if (cts->protocol == PROTO_UNKNOWN
1927 || cts->protocol == PROTO_UNSPECIFIED) {
1928 cts->protocol = device->protocol;
1929 cts->protocol_version = device->protocol_version;
1930 }
1931
1932 if (cts->protocol_version == PROTO_VERSION_UNKNOWN
1933 || cts->protocol_version == PROTO_VERSION_UNSPECIFIED)
1934 cts->protocol_version = device->protocol_version;
1935
1936 if (cts->protocol != device->protocol) {
1937 xpt_print(path, "Uninitialized Protocol %x:%x?\n",
1938 cts->protocol, device->protocol);
1939 cts->protocol = device->protocol;
1940 }
1941
1942 if (cts->protocol_version > device->protocol_version) {
1943 if (bootverbose) {
1944 xpt_print(path, "Down reving Protocol "
1945 "Version from %d to %d?\n", cts->protocol_version,
1946 device->protocol_version);
1947 }
1948 cts->protocol_version = device->protocol_version;
1949 }
1950
1951 if (cts->transport == XPORT_UNKNOWN
1952 || cts->transport == XPORT_UNSPECIFIED) {
1953 cts->transport = device->transport;
1954 cts->transport_version = device->transport_version;
1955 }
1956
1957 if (cts->transport_version == XPORT_VERSION_UNKNOWN
1958 || cts->transport_version == XPORT_VERSION_UNSPECIFIED)
1959 cts->transport_version = device->transport_version;
1960
1961 if (cts->transport != device->transport) {
1962 xpt_print(path, "Uninitialized Transport %x:%x?\n",
1963 cts->transport, device->transport);
1964 cts->transport = device->transport;
1965 }
1966
1967 if (cts->transport_version > device->transport_version) {
1968 if (bootverbose) {
1969 xpt_print(path, "Down reving Transport "
1970 "Version from %d to %d?\n", cts->transport_version,
1971 device->transport_version);
1972 }
1973 cts->transport_version = device->transport_version;
1974 }
1975
1976 ident_data = &device->ident_data;
1977 inq_data = &device->inq_data;
1978 if (cts->protocol == PROTO_ATA)
1979 ata = &cts->proto_specific.ata;
1980 else
1981 ata = NULL;
1982 if (cts->protocol == PROTO_SCSI)
1983 scsi = &cts->proto_specific.scsi;
1984 else
1985 scsi = NULL;
1986 xpt_path_inq(&cpi, path);
1987
1988 /* Sanity checking */
1989 if ((cpi.hba_inquiry & PI_TAG_ABLE) == 0
1990 || (ata && (ident_data->satacapabilities & ATA_SUPPORT_NCQ) == 0)
1991 || (scsi && (INQ_DATA_TQ_ENABLED(inq_data)) == 0)
1992 || (device->queue_flags & SCP_QUEUE_DQUE) != 0
1993 || (device->mintags == 0)) {
1994 /*
1995 * Can't tag on hardware that doesn't support tags,
1996 * doesn't have it enabled, or has broken tag support.
1997 */
1998 if (ata)
1999 ata->flags &= ~CTS_ATA_FLAGS_TAG_ENB;
2000 if (scsi)
2001 scsi->flags &= ~CTS_SCSI_FLAGS_TAG_ENB;
2002 }
2003
2004 /* Start/stop tags use. */
2005 if (cts->type == CTS_TYPE_CURRENT_SETTINGS &&
2006 ((ata && (ata->valid & CTS_ATA_VALID_TQ) != 0) ||
2007 (scsi && (scsi->valid & CTS_SCSI_VALID_TQ) != 0))) {
2008 int nowt, newt = 0;
2009
2010 nowt = ((device->flags & CAM_DEV_TAG_AFTER_COUNT) != 0 ||
2011 (device->inq_flags & SID_CmdQue) != 0);
2012 if (ata)
2013 newt = (ata->flags & CTS_ATA_FLAGS_TAG_ENB) != 0;
2014 if (scsi)
2015 newt = (scsi->flags & CTS_SCSI_FLAGS_TAG_ENB) != 0;
2016
2017 if (newt && !nowt) {
2018 /*
2019 * Delay change to use tags until after a
2020 * few commands have gone to this device so
2021 * the controller has time to perform transfer
2022 * negotiations without tagged messages getting
2023 * in the way.
2024 */
2026 device->flags |= CAM_DEV_TAG_AFTER_COUNT;
2027 } else if (nowt && !newt)
2028 xpt_stop_tags(path);
2029 }
2030
2031 if (async_update == FALSE)
2032 xpt_action_default((union ccb *)cts);
2033}
2034
2035/*
2036 * Handle any per-device event notifications that require action by the XPT.
2037 */
2038static void
2039ata_dev_async(u_int32_t async_code, struct cam_eb *bus, struct cam_et *target,
2040 struct cam_ed *device, void *async_arg)
2041{
2042 cam_status status;
2043 struct cam_path newpath;
2044
2045 /*
2046 * We only need to handle events for real devices.
2047 */
2050 return;
2051
2052 /*
2053 * We need our own path with wildcards expanded to
2054 * handle certain types of events.
2055 */
2056 if ((async_code == AC_SENT_BDR)
2057 || (async_code == AC_BUS_RESET)
2058 || (async_code == AC_INQ_CHANGED))
2059 status = xpt_compile_path(&newpath, NULL,
2060 bus->path_id,
2062 device->lun_id);
2063 else
2064 status = CAM_REQ_CMP_ERR;
2065
2066 if (status == CAM_REQ_CMP) {
2067 if (async_code == AC_INQ_CHANGED) {
2068 /*
2069 * We've sent a start unit command, or
2070 * something similar to a device that
2071 * may have caused its inquiry data to
2072 * change. So we re-scan the device to
2073 * refresh the inquiry data for it.
2074 */
2075 ata_scan_lun(newpath.periph, &newpath,
2076 CAM_EXPECT_INQ_CHANGE, NULL);
2077 } else {
2078 /* We need to reinitialize device after reset. */
2079 ata_scan_lun(newpath.periph, &newpath,
2080 0, NULL);
2081 }
2082 xpt_release_path(&newpath);
2083 } else if (async_code == AC_LOST_DEVICE &&
2084 (device->flags & CAM_DEV_UNCONFIGURED) == 0) {
2087 } else if (async_code == AC_TRANSFER_NEG) {
2088 struct ccb_trans_settings *settings;
2089 struct cam_path path;
2090
2091 settings = (struct ccb_trans_settings *)async_arg;
2092 xpt_compile_path(&path, NULL, bus->path_id, target->target_id,
2093 device->lun_id);
2094 ata_set_transfer_settings(settings, &path,
2095 /*async_update*/TRUE);
2096 xpt_release_path(&path);
2097 }
2098}
2099
2100static void
2101_ata_announce_periph(struct cam_periph *periph, struct ccb_trans_settings *cts, u_int *speed)
2102{
2103 struct ccb_pathinq cpi;
2104 struct cam_path *path = periph->path;
2105
2106 cam_periph_assert(periph, MA_OWNED);
2107
2108 xpt_setup_ccb(&cts->ccb_h, path, CAM_PRIORITY_NORMAL);
2109 cts->ccb_h.func_code = XPT_GET_TRAN_SETTINGS;
2111 xpt_action((union ccb*)cts);
2112 if ((cts->ccb_h.status & CAM_STATUS_MASK) != CAM_REQ_CMP)
2113 return;
2114 /* Ask the SIM for its base transfer speed */
2115 xpt_path_inq(&cpi, path);
2116 /* Report connection speed */
2117 *speed = cpi.base_transfer_speed;
2118 if (cts->transport == XPORT_ATA) {
2119 struct ccb_trans_settings_pata *pata =
2120 &cts->xport_specific.ata;
2121
2122 if (pata->valid & CTS_ATA_VALID_MODE)
2123 *speed = ata_mode2speed(pata->mode);
2124 }
2125 if (cts->transport == XPORT_SATA) {
2126 struct ccb_trans_settings_sata *sata =
2127 &cts->xport_specific.sata;
2128
2129 if (sata->valid & CTS_SATA_VALID_REVISION)
2130 *speed = ata_revision2speed(sata->revision);
2131 }
2132}
2133
2134static void
2136{
2137 struct ccb_trans_settings cts;
2138 u_int speed, mb;
2139
2140 bzero(&cts, sizeof(cts));
2141 _ata_announce_periph(periph, &cts, &speed);
2142 if ((cts.ccb_h.status & CAM_STATUS_MASK) != CAM_REQ_CMP)
2143 return;
2144
2145 mb = speed / 1000;
2146 if (mb > 0)
2147 printf("%s%d: %d.%03dMB/s transfers",
2148 periph->periph_name, periph->unit_number,
2149 mb, speed % 1000);
2150 else
2151 printf("%s%d: %dKB/s transfers", periph->periph_name,
2152 periph->unit_number, speed);
2153 /* Report additional information about connection */
2154 if (cts.transport == XPORT_ATA) {
2155 struct ccb_trans_settings_pata *pata =
2156 &cts.xport_specific.ata;
2157
2158 printf(" (");
2159 if (pata->valid & CTS_ATA_VALID_MODE)
2160 printf("%s, ", ata_mode2string(pata->mode));
2161 if ((pata->valid & CTS_ATA_VALID_ATAPI) && pata->atapi != 0)
2162 printf("ATAPI %dbytes, ", pata->atapi);
2163 if (pata->valid & CTS_ATA_VALID_BYTECOUNT)
2164 printf("PIO %dbytes", pata->bytecount);
2165 printf(")");
2166 }
2167 if (cts.transport == XPORT_SATA) {
2168 struct ccb_trans_settings_sata *sata =
2169 &cts.xport_specific.sata;
2170
2171 printf(" (");
2172 if (sata->valid & CTS_SATA_VALID_REVISION)
2173 printf("SATA %d.x, ", sata->revision);
2174 else
2175 printf("SATA, ");
2176 if (sata->valid & CTS_SATA_VALID_MODE)
2177 printf("%s, ", ata_mode2string(sata->mode));
2178 if ((sata->valid & CTS_ATA_VALID_ATAPI) && sata->atapi != 0)
2179 printf("ATAPI %dbytes, ", sata->atapi);
2180 if (sata->valid & CTS_SATA_VALID_BYTECOUNT)
2181 printf("PIO %dbytes", sata->bytecount);
2182 printf(")");
2183 }
2184 printf("\n");
2185}
2186
2187static void
2188ata_announce_periph_sbuf(struct cam_periph *periph, struct sbuf *sb)
2189{
2190 struct ccb_trans_settings cts;
2191 u_int speed, mb;
2192
2193 bzero(&cts, sizeof(cts));
2194 _ata_announce_periph(periph, &cts, &speed);
2195 if ((cts.ccb_h.status & CAM_STATUS_MASK) != CAM_REQ_CMP)
2196 return;
2197
2198 mb = speed / 1000;
2199 if (mb > 0)
2200 sbuf_printf(sb, "%s%d: %d.%03dMB/s transfers",
2201 periph->periph_name, periph->unit_number,
2202 mb, speed % 1000);
2203 else
2204 sbuf_printf(sb, "%s%d: %dKB/s transfers", periph->periph_name,
2205 periph->unit_number, speed);
2206 /* Report additional information about connection */
2207 if (cts.transport == XPORT_ATA) {
2208 struct ccb_trans_settings_pata *pata =
2209 &cts.xport_specific.ata;
2210
2211 sbuf_printf(sb, " (");
2212 if (pata->valid & CTS_ATA_VALID_MODE)
2213 sbuf_printf(sb, "%s, ", ata_mode2string(pata->mode));
2214 if ((pata->valid & CTS_ATA_VALID_ATAPI) && pata->atapi != 0)
2215 sbuf_printf(sb, "ATAPI %dbytes, ", pata->atapi);
2216 if (pata->valid & CTS_ATA_VALID_BYTECOUNT)
2217 sbuf_printf(sb, "PIO %dbytes", pata->bytecount);
2218 sbuf_printf(sb, ")");
2219 }
2220 if (cts.transport == XPORT_SATA) {
2221 struct ccb_trans_settings_sata *sata =
2222 &cts.xport_specific.sata;
2223
2224 sbuf_printf(sb, " (");
2225 if (sata->valid & CTS_SATA_VALID_REVISION)
2226 sbuf_printf(sb, "SATA %d.x, ", sata->revision);
2227 else
2228 sbuf_printf(sb, "SATA, ");
2229 if (sata->valid & CTS_SATA_VALID_MODE)
2230 sbuf_printf(sb, "%s, ", ata_mode2string(sata->mode));
2231 if ((sata->valid & CTS_ATA_VALID_ATAPI) && sata->atapi != 0)
2232 sbuf_printf(sb, "ATAPI %dbytes, ", sata->atapi);
2233 if (sata->valid & CTS_SATA_VALID_BYTECOUNT)
2234 sbuf_printf(sb, "PIO %dbytes", sata->bytecount);
2235 sbuf_printf(sb, ")");
2236 }
2237 sbuf_printf(sb, "\n");
2238}
2239
2240static void
2241ata_proto_announce_sbuf(struct cam_ed *device, struct sbuf *sb)
2242{
2243 ata_print_ident_sbuf(&device->ident_data, sb);
2244}
2245
2246static void
2248{
2249 ata_print_ident(&device->ident_data);
2250}
2251
2252static void
2254{
2256}
2257
2258static void
2259ata_proto_denounce_sbuf(struct cam_ed *device, struct sbuf *sb)
2260{
2262}
2263
2264static void
2265semb_proto_announce_sbuf(struct cam_ed *device, struct sbuf *sb)
2266{
2267 semb_print_ident_sbuf((struct sep_identify_data *)&device->ident_data, sb);
2268}
2269
2270static void
2272{
2273 semb_print_ident((struct sep_identify_data *)&device->ident_data);
2274}
2275
2276static void
2278{
2280}
2281
2282static void
2283semb_proto_denounce_sbuf(struct cam_ed *device, struct sbuf *sb)
2284{
2286}
2287
2288static void
2290{
2291 char cdb_str[(sizeof(struct ata_cmd) * 3) + 1];
2292
2293 if (ccb->ccb_h.func_code != XPT_ATA_IO)
2294 return;
2295
2297 CAM_DEBUG_CDB,("%s. ACB: %s\n", ata_op_string(&ccb->ataio.cmd),
2298 ata_cmd_string(&ccb->ataio.cmd, cdb_str, sizeof(cdb_str))));
2299}
void semb_print_ident_short(struct sep_identify_data *ident_data)
Definition: ata_all.c:559
void ata_pm_read_cmd(struct ccb_ataio *ataio, int reg, int port)
Definition: ata_all.c:708
char * ata_cmd_string(struct ata_cmd *cmd, char *cmd_string, size_t len)
Definition: ata_all.c:309
u_int ata_revision2speed(int revision)
Definition: ata_all.c:972
void ata_bswap(int8_t *buf, int len)
Definition: ata_all.c:762
void ata_print_ident(struct ata_params *ident_data)
Definition: ata_all.c:429
char * ata_mode2string(int mode)
Definition: ata_all.c:877
void ata_param_fixup(struct ata_params *ident_buf)
Definition: ata_all.c:1266
void ata_reset_cmd(struct ccb_ataio *ataio)
Definition: ata_all.c:700
void semb_print_ident(struct sep_identify_data *ident_data)
Definition: ata_all.c:535
void semb_print_ident_short_sbuf(struct sep_identify_data *ident_data, struct sbuf *sb)
Definition: ata_all.c:571
void ata_print_ident_short(struct ata_params *ident_data)
Definition: ata_all.c:512
void ata_print_ident_sbuf(struct ata_params *ident_data, struct sbuf *sb)
Definition: ata_all.c:464
void ata_print_ident_short_sbuf(struct ata_params *ident_data, struct sbuf *sb)
Definition: ata_all.c:524
int ata_identify_match(caddr_t identbuffer, caddr_t table_entry)
Definition: ata_all.c:1003
int ata_max_pmode(struct ata_params *ap)
Definition: ata_all.c:806
uint32_t ata_logical_sector_size(struct ata_params *ident_data)
Definition: ata_all.c:586
char * ata_op_string(struct ata_cmd *cmd)
Definition: ata_all.c:74
int ata_version(int ver)
Definition: ata_all.c:61
int ata_max_mode(struct ata_params *ap, int maxmode)
Definition: ata_all.c:864
void semb_print_ident_sbuf(struct sep_identify_data *ident_data, struct sbuf *sb)
Definition: ata_all.c:546
void ata_28bit_cmd(struct ccb_ataio *ataio, uint8_t cmd, uint8_t features, uint32_t lba, uint8_t sector_count)
Definition: ata_all.c:621
u_int ata_mode2speed(int mode)
Definition: ata_all.c:934
#define SID_DMA
Definition: ata_all.h:42
#define SID_DMA48
Definition: ata_all.h:40
#define SID_AEN
Definition: ata_all.h:41
static void aprobestart(struct cam_periph *periph, union ccb *start_ccb)
Definition: ata_xpt.c:338
static void ata_proto_denounce(struct cam_ed *device)
Definition: ata_xpt.c:2253
static void aprobedone(struct cam_periph *periph, union ccb *done_ccb)
Definition: ata_xpt.c:743
static void ata_device_transport(struct cam_path *path)
Definition: ata_xpt.c:1671
static struct periph_driver aprobe_driver
Definition: ata_xpt.c:76
static char * probe_action_text[]
Definition: ata_xpt.c:105
static void ata_scan_lun(struct cam_periph *periph, struct cam_path *path, cam_flags flags, union ccb *ccb)
Definition: ata_xpt.c:1559
static struct xpt_xport_ops ata_xport_ops
Definition: ata_xpt.c:209
static struct xpt_proto ata_proto_satapm
Definition: ata_xpt.c:249
static void ata_dev_async(u_int32_t async_code, struct cam_eb *bus, struct cam_et *target, struct cam_ed *device, void *async_arg)
Definition: ata_xpt.c:2039
static void semb_proto_announce_sbuf(struct cam_ed *device, struct sbuf *sb)
Definition: ata_xpt.c:2265
static void ata_announce_periph_sbuf(struct cam_periph *periph, struct sbuf *sb)
Definition: ata_xpt.c:2188
static struct xpt_proto ata_proto_semb
Definition: ata_xpt.c:262
static void semb_proto_announce(struct cam_ed *device)
Definition: ata_xpt.c:2271
static void axptscandone(struct cam_periph *periph, union ccb *done_ccb)
Definition: ata_xpt.c:1637
static void aprobeschedule(struct cam_periph *probe_periph)
Definition: ata_xpt.c:314
static void ata_get_transfer_settings(struct ccb_trans_settings *cts)
Definition: ata_xpt.c:1866
static struct xpt_proto_ops ata_proto_ops_semb
Definition: ata_xpt.c:255
static void ata_find_quirk(struct cam_ed *device)
Definition: ata_xpt.c:1362
static void ata_proto_debug_out(union ccb *ccb)
Definition: ata_xpt.c:2289
#define CAM_QUIRK_MAXTAGS
Definition: ata_xpt.c:69
static struct cam_ed * ata_alloc_device(struct cam_eb *bus, struct cam_et *target, lun_id_t lun_id)
Definition: ata_xpt.c:1645
TUNABLE_INT("hw.ata.ata_dma", &ata_dma)
static void ata_action(union ccb *start_ccb)
Definition: ata_xpt.c:1798
static void aprobecleanup(struct cam_periph *periph)
Definition: ata_xpt.c:1356
CAM_XPT_PROTO(ata_proto_ata)
#define ATA_XPT_XPORT(x, X)
Definition: ata_xpt.c:216
static void ata_proto_announce_sbuf(struct cam_ed *device, struct sbuf *sb)
Definition: ata_xpt.c:2241
__FBSDID("$FreeBSD$")
aprobe_flags
Definition: ata_xpt.c:135
@ PROBE_NO_ANNOUNCE
Definition: ata_xpt.c:136
PERIPHDRIVER_DECLARE(aprobe, aprobe_driver)
static cam_status aproberegister(struct cam_periph *periph, void *arg)
Definition: ata_xpt.c:278
static int ata_dma
Definition: ata_xpt.c:203
static periph_init_t aprobe_periph_init
Definition: ata_xpt.c:74
static void ata_proto_denounce_sbuf(struct cam_ed *device, struct sbuf *sb)
Definition: ata_xpt.c:2259
static void aproberequestdefaultnegotiation(struct cam_periph *periph)
Definition: ata_xpt.c:725
static void _ata_announce_periph(struct cam_periph *periph, struct ccb_trans_settings *cts, u_int *speed)
Definition: ata_xpt.c:2101
static void semb_proto_denounce(struct cam_ed *device)
Definition: ata_xpt.c:2277
static struct xpt_proto ata_proto_ata
Definition: ata_xpt.c:236
static struct ata_quirk_entry ata_quirk_table[]
Definition: ata_xpt.c:153
static void semb_proto_denounce_sbuf(struct cam_ed *device, struct sbuf *sb)
Definition: ata_xpt.c:2283
static void ata_scan_bus(struct cam_periph *periph, union ccb *ccb)
Definition: ata_xpt.c:1395
static void ata_dev_advinfo(union ccb *start_ccb)
Definition: ata_xpt.c:1726
aprobe_action
Definition: ata_xpt.c:85
@ PROBE_PM_PRV
Definition: ata_xpt.c:98
@ PROBE_SETDMAAA
Definition: ata_xpt.c:92
@ PROBE_SETPM
Definition: ata_xpt.c:90
@ PROBE_INQUIRY
Definition: ata_xpt.c:95
@ PROBE_IDENTIFY
Definition: ata_xpt.c:87
@ PROBE_SPINUP
Definition: ata_xpt.c:88
@ PROBE_FULL_INQUIRY
Definition: ata_xpt.c:96
@ PROBE_SETMODE
Definition: ata_xpt.c:89
@ PROBE_PM_PID
Definition: ata_xpt.c:97
@ PROBE_IDENTIFY_SES
Definition: ata_xpt.c:99
@ PROBE_IDENTIFY_SAFTE
Definition: ata_xpt.c:100
@ PROBE_SETAN
Definition: ata_xpt.c:93
@ PROBE_SET_MULTI
Definition: ata_xpt.c:94
@ PROBE_DONE
Definition: ata_xpt.c:101
@ PROBE_RESET
Definition: ata_xpt.c:86
@ PROBE_SETAPST
Definition: ata_xpt.c:91
@ PROBE_INVALID
Definition: ata_xpt.c:102
static void ata_proto_announce(struct cam_ed *device)
Definition: ata_xpt.c:2247
#define PROBE_SET_ACTION(softc, newaction)
Definition: ata_xpt.c:125
static int atapi_dma
Definition: ata_xpt.c:204
static struct xpt_proto_ops ata_proto_ops_ata
Definition: ata_xpt.c:229
static struct xpt_proto_ops ata_proto_ops_satapm
Definition: ata_xpt.c:242
static void ata_set_transfer_settings(struct ccb_trans_settings *cts, struct cam_path *path, int async_update)
Definition: ata_xpt.c:1910
static void ata_announce_periph(struct cam_periph *periph)
Definition: ata_xpt.c:2135
caddr_t cam_quirkmatch(caddr_t target, caddr_t quirk_table, int num_entries, int entry_size, cam_quirkmatch_t *comp_func)
Definition: cam.c:281
@ SF_NO_RETRY
Definition: cam.h:127
@ SF_NO_RECOVERY
Definition: cam.h:126
#define CAM_TARGET_WILDCARD
Definition: cam.h:48
cam_flags
Definition: cam.h:115
@ CAM_EXPECT_INQ_CHANGE
Definition: cam.h:117
#define CAM_LUN_WILDCARD
Definition: cam.h:49
#define CAM_PRIORITY_NORMAL
Definition: cam.h:92
#define CAM_PRIORITY_NONE
Definition: cam.h:93
#define CAM_PRIORITY_XPT
Definition: cam.h:89
cam_status
Definition: cam.h:132
@ CAM_ATA_STATUS_ERROR
Definition: cam.h:225
@ CAM_PATH_INVALID
Definition: cam.h:155
@ CAM_REQ_INVALID
Definition: cam.h:152
@ CAM_REQ_CMP
Definition: cam.h:137
@ CAM_CMD_TIMEOUT
Definition: cam.h:167
@ CAM_RESRC_UNAVAIL
Definition: cam.h:247
@ CAM_REQ_CMP_ERR
Definition: cam.h:146
@ CAM_STATUS_MASK
Definition: cam.h:302
@ CAM_REQ_ABORTED
Definition: cam.h:140
@ CAM_DEV_QFRZN
Definition: cam.h:287
u_int64_t lun_id_t
Definition: cam.h:44
#define CTS_SATA_CAPS_H_DMAAA
Definition: cam_ccb.h:1033
@ AC_ADVINFO_CHANGED
Definition: cam_ccb.h:868
@ AC_FOUND_DEVICE
Definition: cam_ccb.h:874
@ AC_SCSI_AEN
Definition: cam_ccb.h:878
@ AC_BUS_RESET
Definition: cam_ccb.h:880
@ AC_GETDEV_CHANGED
Definition: cam_ccb.h:870
@ AC_TRANSFER_NEG
Definition: cam_ccb.h:872
@ AC_INQ_CHANGED
Definition: cam_ccb.h:871
@ AC_LOST_DEVICE
Definition: cam_ccb.h:873
@ AC_SENT_BDR
Definition: cam_ccb.h:877
@ PI_SATAPM
Definition: cam_ccb.h:602
@ PI_SDTR_ABLE
Definition: cam_ccb.h:600
@ PI_TAG_ABLE
Definition: cam_ccb.h:603
@ PI_WIDE_32
Definition: cam_ccb.h:598
@ PI_WIDE_16
Definition: cam_ccb.h:599
#define CTS_ATA_VALID_MODE
Definition: cam_ccb.h:1001
#define CTS_SATA_CAPS_H
Definition: cam_ccb.h:1030
static __inline void cam_fill_ataio(struct ccb_ataio *ataio, u_int32_t retries, void(*cbfcnp)(struct cam_periph *, union ccb *), u_int32_t flags, u_int tag_action __unused, u_int8_t *data_ptr, u_int32_t dxfer_len, u_int32_t timeout)
Definition: cam_ccb.h:1436
#define CDAI_FLAG_STORE
Definition: cam_ccb.h:1312
@ PROTO_SEMB
Definition: cam_ccb.h:283
@ PROTO_ATA
Definition: cam_ccb.h:280
@ PROTO_SCSI
Definition: cam_ccb.h:279
@ PROTO_UNSPECIFIED
Definition: cam_ccb.h:278
@ PROTO_UNKNOWN
Definition: cam_ccb.h:277
@ PROTO_SATAPM
Definition: cam_ccb.h:282
#define CTS_SATA_VALID_BYTECOUNT
Definition: cam_ccb.h:1017
#define CTS_SCSI_FLAGS_TAG_ENB
Definition: cam_ccb.h:954
#define PROTO_VERSION_UNSPECIFIED
Definition: cam_ccb.h:315
@ CTS_TYPE_CURRENT_SETTINGS
Definition: cam_ccb.h:945
@ CTS_TYPE_USER_SETTINGS
Definition: cam_ccb.h:946
#define CTS_SATA_CAPS_D_PMREQ
Definition: cam_ccb.h:1036
#define CTS_SCSI_VALID_TQ
Definition: cam_ccb.h:952
@ PIM_NOBUSRESET
Definition: cam_ccb.h:622
#define CTS_SATA_VALID_CAPS
Definition: cam_ccb.h:1022
#define CTS_ATA_FLAGS_TAG_ENB
Definition: cam_ccb.h:962
#define CTS_SATA_VALID_MODE
Definition: cam_ccb.h:1016
#define CTS_SATA_VALID_TAGS
Definition: cam_ccb.h:1020
#define XPORT_VERSION_UNSPECIFIED
Definition: cam_ccb.h:317
#define CTS_SATA_CAPS_D_APST
Definition: cam_ccb.h:1037
@ XPORT_ATA
Definition: cam_ccb.h:296
@ XPORT_UNKNOWN
Definition: cam_ccb.h:289
@ XPORT_SATA
Definition: cam_ccb.h:298
@ XPORT_UNSPECIFIED
Definition: cam_ccb.h:290
#define CTS_SATA_CAPS_H_AN
Definition: cam_ccb.h:1034
@ CAM_DIR_IN
Definition: cam_ccb.h:79
@ CAM_DIR_NONE
Definition: cam_ccb.h:81
@ CAM_DEV_QFREEZE
Definition: cam_ccb.h:92
@ CAM_HIGH_POWER
Definition: cam_ccb.h:93
@ CAM_UNLOCKED
Definition: cam_ccb.h:119
#define CTS_SATA_CAPS_H_PMREQ
Definition: cam_ccb.h:1031
#define CTS_SATA_VALID_PM
Definition: cam_ccb.h:1019
#define PROTO_VERSION_UNKNOWN
Definition: cam_ccb.h:314
#define CTS_SATA_VALID_REVISION
Definition: cam_ccb.h:1018
@ XPT_DEV_ADVINFO
Definition: cam_ccb.h:166
@ XPT_RESET_BUS
Definition: cam_ccb.h:174
@ XPT_GET_TRAN_SETTINGS
Definition: cam_ccb.h:183
@ XPT_SCSI_IO
Definition: cam_ccb.h:141
@ XPT_SCAN_TGT
Definition: cam_ccb.h:223
@ XPT_SCAN_BUS
Definition: cam_ccb.h:155
@ XPT_SET_TRAN_SETTINGS
Definition: cam_ccb.h:188
@ XPT_SCAN_LUN
Definition: cam_ccb.h:180
@ XPT_ATA_IO
Definition: cam_ccb.h:199
@ XPT_GDEV_TYPE
Definition: cam_ccb.h:143
@ CAM_CCB_FROM_UMA
Definition: cam_ccb.h:64
#define CTS_ATA_VALID_ATAPI
Definition: cam_ccb.h:1003
#define CTS_ATA_VALID_CAPS
Definition: cam_ccb.h:1004
#define CTS_SATA_VALID_ATAPI
Definition: cam_ccb.h:1021
#define CDAI_TYPE_SERIAL_NUM
Definition: cam_ccb.h:1316
#define CTS_ATA_VALID_TQ
Definition: cam_ccb.h:960
#define CTS_ATA_VALID_BYTECOUNT
Definition: cam_ccb.h:1002
#define CDAI_TYPE_PHYS_PATH
Definition: cam_ccb.h:1317
#define XPORT_VERSION_UNKNOWN
Definition: cam_ccb.h:316
#define CTS_ATA_CAPS_H_DMA48
Definition: cam_ccb.h:1010
#define CTS_SATA_CAPS_H_APST
Definition: cam_ccb.h:1032
#define CTS_ATA_CAPS_H
Definition: cam_ccb.h:1009
#define CDAI_TYPE_SCSI_DEVID
Definition: cam_ccb.h:1315
@ CAM_DEBUG_TRACE
Definition: cam_debug.h:41
@ CAM_DEBUG_PROBE
Definition: cam_debug.h:46
@ CAM_DEBUG_CDB
Definition: cam_debug.h:43
#define CAM_DEBUG(path, flag, printfargs)
Definition: cam_debug.h:93
void cam_periph_release_locked(struct cam_periph *periph)
Definition: cam_periph.c:453
struct cam_periph * cam_periph_find(struct cam_path *path, char *name)
Definition: cam_periph.c:340
u_int32_t cam_release_devq(struct cam_path *path, u_int32_t relsim_flags, u_int32_t openings, u_int32_t arg, int getcount_only)
Definition: cam_periph.c:1342
int cam_periph_acquire(struct cam_periph *periph)
Definition: cam_periph.c:413
void cam_periph_invalidate(struct cam_periph *periph)
Definition: cam_periph.c:655
int cam_periph_error(union ccb *ccb, cam_flags camflags, u_int32_t sense_flags)
Definition: cam_periph.c:1864
cam_status cam_periph_alloc(periph_ctor_t *periph_ctor, periph_oninv_t *periph_oninvalidate, periph_dtor_t *periph_dtor, periph_start_t *periph_start, char *name, cam_periph_type type, struct cam_path *path, ac_callback_t *ac_callback, ac_code code, void *arg)
Definition: cam_periph.c:197
#define CAM_PERIPH_INVALID
Definition: cam_periph.h:133
#define cam_periph_assert(periph, what)
Definition: cam_periph.h:230
#define CAM_PERIPH_DRV_EARLY
Definition: cam_periph.h:99
@ CAM_PERIPH_BIO
Definition: cam_periph.h:104
void() periph_init_t(void)
Definition: cam_periph.h:85
void xpt_acquire_device(struct cam_ed *device)
Definition: cam_xpt.c:4897
struct mtx * xpt_path_mtx(struct cam_path *path)
Definition: cam_xpt.c:5328
void xpt_schedule(struct cam_periph *periph, u_int32_t new_priority)
Definition: cam_xpt.c:3243
cam_status xpt_create_path(struct cam_path **new_path_ptr, struct cam_periph *perph, path_id_t path_id, target_id_t target_id, lun_id_t lun_id)
Definition: cam_xpt.c:3527
void xpt_release_device(struct cam_ed *device)
Definition: cam_xpt.c:4907
void xpt_print(struct cam_path *path, const char *fmt,...)
Definition: cam_xpt.c:3814
void xpt_release_path(struct cam_path *path)
Definition: cam_xpt.c:3654
void xpt_async(u_int32_t async_code, struct cam_path *path, void *async_arg)
Definition: cam_xpt.c:4350
void xpt_setup_ccb(struct ccb_hdr *ccb_h, struct cam_path *path, u_int32_t priority)
Definition: cam_xpt.c:3520
void xpt_action(union ccb *start_ccb)
Definition: cam_xpt.c:2601
void xpt_done(union ccb *done_ccb)
Definition: cam_xpt.c:4562
union ccb * xpt_alloc_ccb_nowait(void)
Definition: cam_xpt.c:4621
void xpt_free_path(struct cam_path *path)
Definition: cam_xpt.c:3672
void xpt_action_default(union ccb *start_ccb)
Definition: cam_xpt.c:2613
cam_status xpt_compile_path(struct cam_path *new_path, struct cam_periph *perph, path_id_t path_id, target_id_t target_id, lun_id_t lun_id)
Definition: cam_xpt.c:3559
void xpt_stop_tags(struct cam_path *path)
Definition: cam_xpt.c:5057
void xpt_release_ccb(union ccb *free_ccb)
Definition: cam_xpt.c:3924
struct cam_ed * xpt_alloc_device(struct cam_eb *bus, struct cam_et *target, lun_id_t lun_id)
Definition: cam_xpt.c:4840
void xpt_release_devq(struct cam_path *path, u_int count, int run_queue)
Definition: cam_xpt.c:4480
void xpt_free_ccb(union ccb *free_ccb)
Definition: cam_xpt.c:4630
#define xpt_path_unlock(path)
Definition: cam_xpt.h:129
#define xpt_path_owned(path)
Definition: cam_xpt.h:131
#define xpt_path_lock(path)
Definition: cam_xpt.h:128
#define xpt_path_assert(path, what)
Definition: cam_xpt.h:130
static void xpt_path_inq(struct ccb_pathinq *cpi, struct cam_path *path)
Definition: cam_xpt.h:156
#define CAM_DEV_UNCONFIGURED
#define CAM_DEV_INQUIRY_DATA_VALID
#define CAM_DEV_TAG_AFTER_COUNT
#define CAM_TAG_DELAY_COUNT
#define CAM_DEV_IDENTIFY_DATA_VALID
union ccb * ccb
Definition: mmc_sim_if.m:53
struct ccb_trans_settings_mmc * cts
Definition: mmc_sim_if.m:43
void scsi_inquiry(struct ccb_scsiio *csio, u_int32_t retries, void(*cbfcnp)(struct cam_periph *, union ccb *), u_int8_t tag_action, u_int8_t *inq_buf, u_int32_t inq_len, int evpd, u_int8_t page_code, u_int8_t sense_len, u_int32_t timeout)
Definition: scsi_all.c:7595
#define SSD_MIN_SIZE
Definition: scsi_all.h:3256
#define SID_CmdQue
Definition: scsi_all.h:2262
#define SID_ADDITIONAL_LENGTH(iqd)
Definition: scsi_all.h:2237
#define SIP_MEDIA_REMOVABLE
Definition: scsi_all.h:3706
#define SVPD_ID_CODESET_BINARY
Definition: scsi_all.h:2369
#define SHORT_INQUIRY_LENGTH
Definition: scsi_all.h:2201
#define SIP_MEDIA_FIXED
Definition: scsi_all.h:3707
#define SCP_QUEUE_DQUE
Definition: scsi_all.h:726
#define SVPD_ID_TYPE_NAA
Definition: scsi_all.h:2382
#define SID_QUAL_LU_CONNECTED
Definition: scsi_all.h:2208
#define INQ_DATA_TQ_ENABLED(iqd)
Definition: scsi_all.h:2255
#define T_ANY
Definition: scsi_all.h:2190
#define SID_ANSI_REV(inq_data)
Definition: scsi_all.h:2219
#define SID_QUAL_LU_OFFLINE
Definition: scsi_all.h:2209
#define SID_QUAL(inq_data)
Definition: scsi_all.h:2207
#define SVPD_DEVICE_ID
Definition: scsi_all.h:2354
#define MSG_SIMPLE_Q_TAG
Definition: scsi_message.h:35
Definition: ata_xpt.c:66
u_int mintags
Definition: ata_xpt.c:70
u_int maxtags
Definition: ata_xpt.c:71
u_int8_t quirks
Definition: ata_xpt.c:68
struct scsi_inquiry_pattern inq_pat
Definition: ata_xpt.c:67
u_int8_t lba_mid
Definition: ata_all.h:78
u_int8_t lba_high
Definition: ata_all.h:79
u_int8_t lba_low
Definition: ata_all.h:77
u_int8_t sector_count
Definition: ata_all.h:86
union ccb * request_ccb
Definition: ata_xpt.c:1384
struct ccb_pathinq * cpi
Definition: ata_xpt.c:1385
struct timeval last_reset
path_id_t path_id
struct cam_sim * sim
u_int protocol_version
u_int maxtags
uint8_t physpath_len
u_int32_t tag_delay_count
u_int8_t queue_flags
u_int8_t * serial_num
u_int mintags
struct cam_et * target
u_int8_t serial_num_len
lun_id_t lun_id
u_int8_t inq_flags
struct ata_params ident_data
uint8_t * device_id
u_int transport_version
uint8_t * physpath
void * quirk
cam_proto protocol
uint32_t device_id_len
cam_xport transport
u_int32_t flags
struct scsi_inquiry_data inq_data
target_id_t target_id
struct cam_ed * device
struct cam_et * target
struct cam_eb * bus
struct cam_periph * periph
char * periph_name
Definition: cam_periph.h:123
u_int32_t unit_number
Definition: cam_periph.h:127
void * softc
Definition: cam_periph.h:125
struct cam_path * path
Definition: cam_periph.h:124
u_int32_t flags
Definition: cam_periph.h:129
u_int32_t priority
Definition: cam.h:86
int max_tagged_dev_openings
Definition: cam_sim.h:101
struct ata_res res
Definition: cam_ccb.h:795
struct ata_cmd cmd
Definition: cam_ccb.h:794
uint32_t buftype
Definition: cam_ccb.h:1313
uint8_t * buf
Definition: cam_ccb.h:1326
uint32_t flags
Definition: cam_ccb.h:1310
u_int32_t flags
Definition: cam_ccb.h:368
path_id_t path_id
Definition: cam_ccb.h:365
struct cam_path * path
Definition: cam_ccb.h:364
cam_pinfo pinfo
Definition: cam_ccb.h:349
u_int16_t alloc_flags
Definition: cam_ccb.h:355
xpt_opcode func_code
Definition: cam_ccb.h:362
u_int32_t status
Definition: cam_ccb.h:363
target_id_t target_id
Definition: cam_ccb.h:366
void(* cbfcnp)(struct cam_periph *, union ccb *)
Definition: cam_ccb.h:360
u_int32_t max_target
Definition: cam_ccb.h:669
u_int protocol_version
Definition: cam_ccb.h:681
u_int32_t hba_misc
Definition: cam_ccb.h:665
u_int8_t hba_inquiry
Definition: cam_ccb.h:663
struct ccb_hdr ccb_h
Definition: cam_ccb.h:661
u_int32_t base_transfer_speed
Definition: cam_ccb.h:679
cam_xport transport
Definition: cam_ccb.h:682
u_int transport_version
Definition: cam_ccb.h:683
cam_flags flags
Definition: cam_ccb.h:1191
u_int8_t cdb_len
Definition: cam_ccb.h:758
TAILQ_HEAD(, cam_periph) units
u_int8_t additional_length
Definition: scsi_all.h:2236
xpt_proto_announce_func announce
cam_proto proto
xpt_alloc_device_func alloc_device
Definition: cam_ccb.h:1345
struct ccb_trans_settings cts
Definition: cam_ccb.h:1357
struct ccb_dev_advinfo cdai
Definition: cam_ccb.h:1377
struct ccb_hdr ccb_h
Definition: cam_ccb.h:1346
struct ccb_scsiio csio
Definition: cam_ccb.h:1347
struct ccb_rescan crcn
Definition: cam_ccb.h:1374
struct ccb_pathinq cpi
Definition: cam_ccb.h:1350
struct ccb_ataio ataio
Definition: cam_ccb.h:1376