2 * Copyright (c) 2009 Alexander Motin <mav@FreeBSD.org>
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer,
10 * without modification, immediately at the beginning of the file.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
15 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
16 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
17 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
18 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
19 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
20 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
21 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
22 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
24 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 #include <sys/cdefs.h>
28 __FBSDID("$FreeBSD$");
30 #include <sys/param.h>
32 #include <sys/endian.h>
33 #include <sys/systm.h>
34 #include <sys/types.h>
35 #include <sys/malloc.h>
36 #include <sys/kernel.h>
39 #include <sys/fcntl.h>
41 #include <sys/interrupt.h>
45 #include <sys/mutex.h>
46 #include <sys/sysctl.h>
49 #include <pc98/pc98/pc98_machdep.h> /* geometry translation */
53 #include <cam/cam_ccb.h>
54 #include <cam/cam_queue.h>
55 #include <cam/cam_periph.h>
56 #include <cam/cam_sim.h>
57 #include <cam/cam_xpt.h>
58 #include <cam/cam_xpt_sim.h>
59 #include <cam/cam_xpt_periph.h>
60 #include <cam/cam_xpt_internal.h>
61 #include <cam/cam_debug.h>
63 #include <cam/scsi/scsi_all.h>
64 #include <cam/scsi/scsi_message.h>
65 #include <cam/ata/ata_all.h>
66 #include <machine/stdarg.h> /* for xpt_print below */
69 struct ata_quirk_entry {
70 struct scsi_inquiry_pattern inq_pat;
72 #define CAM_QUIRK_MAXTAGS 0x01
76 static periph_init_t probe_periph_init;
78 static struct periph_driver probe_driver =
80 probe_periph_init, "aprobe",
81 TAILQ_HEAD_INITIALIZER(probe_driver.units), /* generation */ 0,
85 PERIPHDRIVER_DECLARE(aprobe, probe_driver);
99 static char *probe_action_text[] = {
105 "PROBE_FULL_INQUIRY",
111 #define PROBE_SET_ACTION(softc, newaction) \
114 text = probe_action_text; \
115 CAM_DEBUG((softc)->periph->path, CAM_DEBUG_INFO, \
116 ("Probe %s to %s\n", text[(softc)->action], \
117 text[(newaction)])); \
118 (softc)->action = (newaction); \
122 PROBE_NO_ANNOUNCE = 0x04
126 TAILQ_HEAD(, ccb_hdr) request_ccbs;
134 struct cam_periph *periph;
137 static struct ata_quirk_entry ata_quirk_table[] =
140 /* Default tagged queuing parameters for all devices */
142 T_ANY, SIP_MEDIA_REMOVABLE|SIP_MEDIA_FIXED,
143 /*vendor*/"*", /*product*/"*", /*revision*/"*"
145 /*quirks*/0, /*maxtags*/0
149 static const int ata_quirk_table_size =
150 sizeof(ata_quirk_table) / sizeof(*ata_quirk_table);
152 static cam_status proberegister(struct cam_periph *periph,
154 static void probeschedule(struct cam_periph *probe_periph);
155 static void probestart(struct cam_periph *periph, union ccb *start_ccb);
156 //static void proberequestdefaultnegotiation(struct cam_periph *periph);
157 //static int proberequestbackoff(struct cam_periph *periph,
158 // struct cam_ed *device);
159 static void probedone(struct cam_periph *periph, union ccb *done_ccb);
160 static void probecleanup(struct cam_periph *periph);
161 static void ata_find_quirk(struct cam_ed *device);
162 static void ata_scan_bus(struct cam_periph *periph, union ccb *ccb);
163 static void ata_scan_lun(struct cam_periph *periph,
164 struct cam_path *path, cam_flags flags,
166 static void xptscandone(struct cam_periph *periph, union ccb *done_ccb);
167 static struct cam_ed *
168 ata_alloc_device(struct cam_eb *bus, struct cam_et *target,
170 static void ata_device_transport(struct cam_path *path);
171 static void ata_set_transfer_settings(struct ccb_trans_settings *cts,
172 struct cam_ed *device,
174 static void ata_dev_async(u_int32_t async_code,
176 struct cam_et *target,
177 struct cam_ed *device,
179 static void ata_action(union ccb *start_ccb);
181 static struct xpt_xport ata_xport = {
182 .alloc_device = ata_alloc_device,
183 .action = ata_action,
184 .async = ata_dev_async,
199 proberegister(struct cam_periph *periph, void *arg)
201 union ccb *request_ccb; /* CCB representing the probe request */
205 request_ccb = (union ccb *)arg;
206 if (periph == NULL) {
207 printf("proberegister: periph was NULL!!\n");
208 return(CAM_REQ_CMP_ERR);
211 if (request_ccb == NULL) {
212 printf("proberegister: no probe CCB, "
213 "can't register device\n");
214 return(CAM_REQ_CMP_ERR);
217 softc = (probe_softc *)malloc(sizeof(*softc), M_CAMXPT, M_NOWAIT);
220 printf("proberegister: Unable to probe new device. "
221 "Unable to allocate softc\n");
222 return(CAM_REQ_CMP_ERR);
224 TAILQ_INIT(&softc->request_ccbs);
225 TAILQ_INSERT_TAIL(&softc->request_ccbs, &request_ccb->ccb_h,
228 periph->softc = softc;
229 softc->periph = periph;
230 softc->action = PROBE_INVALID;
231 status = cam_periph_acquire(periph);
232 if (status != CAM_REQ_CMP) {
236 * Ensure nobody slip in until probe finish.
238 cam_freeze_devq_arg(periph->path,
239 RELSIM_RELEASE_RUNLEVEL, CAM_RL_XPT + 1);
240 probeschedule(periph);
245 probeschedule(struct cam_periph *periph)
250 softc = (probe_softc *)periph->softc;
251 ccb = (union ccb *)TAILQ_FIRST(&softc->request_ccbs);
253 if ((periph->path->device->flags & CAM_DEV_UNCONFIGURED) ||
254 periph->path->device->protocol == PROTO_SATAPM)
255 PROBE_SET_ACTION(softc, PROBE_RESET);
257 PROBE_SET_ACTION(softc, PROBE_IDENTIFY);
259 if (ccb->crcn.flags & CAM_EXPECT_INQ_CHANGE)
260 softc->flags |= PROBE_NO_ANNOUNCE;
262 softc->flags &= ~PROBE_NO_ANNOUNCE;
264 xpt_schedule(periph, CAM_PRIORITY_XPT);
268 probestart(struct cam_periph *periph, union ccb *start_ccb)
270 struct ccb_trans_settings cts;
271 struct ccb_ataio *ataio;
272 struct ccb_scsiio *csio;
274 struct cam_path *path;
275 struct ata_params *ident_buf;
277 CAM_DEBUG(start_ccb->ccb_h.path, CAM_DEBUG_TRACE, ("probestart\n"));
279 softc = (probe_softc *)periph->softc;
280 path = start_ccb->ccb_h.path;
281 ataio = &start_ccb->ataio;
282 csio = &start_ccb->csio;
283 ident_buf = &periph->path->device->ident_data;
285 if (softc->restart) {
287 if ((path->device->flags & CAM_DEV_UNCONFIGURED) ||
288 path->device->protocol == PROTO_SATAPM)
289 softc->action = PROBE_RESET;
291 softc->action = PROBE_IDENTIFY;
293 switch (softc->action) {
295 cam_fill_ataio(ataio,
298 /*flags*/CAM_DIR_NONE,
303 ata_reset_cmd(ataio);
306 if ((periph->path->device->flags & CAM_DEV_UNCONFIGURED) == 0) {
307 /* Prepare check that it is the same device. */
312 (unsigned char *)ident_buf->model,
313 sizeof(ident_buf->model));
315 (unsigned char *)ident_buf->revision,
316 sizeof(ident_buf->revision));
318 (unsigned char *)ident_buf->serial,
319 sizeof(ident_buf->serial));
320 MD5Final(softc->digest, &context);
322 cam_fill_ataio(ataio,
327 /*data_ptr*/(u_int8_t *)ident_buf,
328 /*dxfer_len*/sizeof(struct ata_params),
330 if (periph->path->device->protocol == PROTO_ATA)
331 ata_28bit_cmd(ataio, ATA_ATA_IDENTIFY, 0, 0, 0);
333 ata_28bit_cmd(ataio, ATA_ATAPI_IDENTIFY, 0, 0, 0);
340 /* Fetch user modes from SIM. */
341 bzero(&cts, sizeof(cts));
342 xpt_setup_ccb(&cts.ccb_h, path, CAM_PRIORITY_NONE);
343 cts.ccb_h.func_code = XPT_GET_TRAN_SETTINGS;
344 cts.type = CTS_TYPE_USER_SETTINGS;
345 xpt_action((union ccb *)&cts);
346 if (path->device->transport == XPORT_ATA) {
347 if (cts.xport_specific.ata.valid & CTS_ATA_VALID_MODE)
348 mode = cts.xport_specific.ata.mode;
350 if (cts.xport_specific.sata.valid & CTS_SATA_VALID_MODE)
351 mode = cts.xport_specific.sata.mode;
354 /* Honor device capabilities. */
355 wantmode = mode = ata_max_mode(ident_buf, mode);
356 /* Report modes to SIM. */
357 bzero(&cts, sizeof(cts));
358 xpt_setup_ccb(&cts.ccb_h, path, CAM_PRIORITY_NONE);
359 cts.ccb_h.func_code = XPT_SET_TRAN_SETTINGS;
360 cts.type = CTS_TYPE_CURRENT_SETTINGS;
361 if (path->device->transport == XPORT_ATA) {
362 cts.xport_specific.ata.mode = mode;
363 cts.xport_specific.ata.valid = CTS_ATA_VALID_MODE;
365 cts.xport_specific.sata.mode = mode;
366 cts.xport_specific.sata.valid = CTS_SATA_VALID_MODE;
368 xpt_action((union ccb *)&cts);
369 /* Fetch current modes from SIM. */
370 bzero(&cts, sizeof(cts));
371 xpt_setup_ccb(&cts.ccb_h, path, CAM_PRIORITY_NONE);
372 cts.ccb_h.func_code = XPT_GET_TRAN_SETTINGS;
373 cts.type = CTS_TYPE_CURRENT_SETTINGS;
374 xpt_action((union ccb *)&cts);
375 if (path->device->transport == XPORT_ATA) {
376 if (cts.xport_specific.ata.valid & CTS_ATA_VALID_MODE)
377 mode = cts.xport_specific.ata.mode;
379 if (cts.xport_specific.ata.valid & CTS_SATA_VALID_MODE)
380 mode = cts.xport_specific.sata.mode;
382 /* If SIM disagree - renegotiate. */
383 if (mode != wantmode)
385 cam_fill_ataio(ataio,
388 /*flags*/CAM_DIR_NONE,
393 ata_28bit_cmd(ataio, ATA_SETFEATURES, ATA_SF_SETXFER, 0, mode);
396 case PROBE_SET_MULTI:
398 u_int sectors, bytecount;
400 bytecount = 8192; /* SATA maximum */
401 /* Fetch user bytecount from SIM. */
402 bzero(&cts, sizeof(cts));
403 xpt_setup_ccb(&cts.ccb_h, path, CAM_PRIORITY_NONE);
404 cts.ccb_h.func_code = XPT_GET_TRAN_SETTINGS;
405 cts.type = CTS_TYPE_USER_SETTINGS;
406 xpt_action((union ccb *)&cts);
407 if (path->device->transport == XPORT_ATA) {
408 if (cts.xport_specific.ata.valid & CTS_ATA_VALID_BYTECOUNT)
409 bytecount = cts.xport_specific.ata.bytecount;
411 if (cts.xport_specific.sata.valid & CTS_SATA_VALID_BYTECOUNT)
412 bytecount = cts.xport_specific.sata.bytecount;
414 /* Honor device capabilities. */
415 sectors = max(1, min(ident_buf->sectors_intr & 0xff,
416 bytecount / ata_logical_sector_size(ident_buf)));
417 /* Report bytecount to SIM. */
418 bzero(&cts, sizeof(cts));
419 xpt_setup_ccb(&cts.ccb_h, path, CAM_PRIORITY_NONE);
420 cts.ccb_h.func_code = XPT_SET_TRAN_SETTINGS;
421 cts.type = CTS_TYPE_CURRENT_SETTINGS;
422 if (path->device->transport == XPORT_ATA) {
423 cts.xport_specific.ata.bytecount = sectors *
424 ata_logical_sector_size(ident_buf);
425 cts.xport_specific.ata.valid = CTS_ATA_VALID_BYTECOUNT;
427 cts.xport_specific.sata.bytecount = sectors *
428 ata_logical_sector_size(ident_buf);
429 cts.xport_specific.sata.valid = CTS_SATA_VALID_BYTECOUNT;
431 xpt_action((union ccb *)&cts);
432 /* Fetch current bytecount from SIM. */
433 bzero(&cts, sizeof(cts));
434 xpt_setup_ccb(&cts.ccb_h, path, CAM_PRIORITY_NONE);
435 cts.ccb_h.func_code = XPT_GET_TRAN_SETTINGS;
436 cts.type = CTS_TYPE_CURRENT_SETTINGS;
437 xpt_action((union ccb *)&cts);
438 if (path->device->transport == XPORT_ATA) {
439 if (cts.xport_specific.ata.valid & CTS_ATA_VALID_BYTECOUNT)
440 bytecount = cts.xport_specific.ata.bytecount;
442 if (cts.xport_specific.sata.valid & CTS_SATA_VALID_BYTECOUNT)
443 bytecount = cts.xport_specific.sata.bytecount;
445 sectors = bytecount / ata_logical_sector_size(ident_buf);
447 cam_fill_ataio(ataio,
455 ata_28bit_cmd(ataio, ATA_SET_MULTI, 0, 0, sectors);
462 bytecount = 8192; /* SATA maximum */
463 /* Fetch user bytecount from SIM. */
464 bzero(&cts, sizeof(cts));
465 xpt_setup_ccb(&cts.ccb_h, path, CAM_PRIORITY_NONE);
466 cts.ccb_h.func_code = XPT_GET_TRAN_SETTINGS;
467 cts.type = CTS_TYPE_USER_SETTINGS;
468 xpt_action((union ccb *)&cts);
469 if (path->device->transport == XPORT_ATA) {
470 if (cts.xport_specific.ata.valid & CTS_ATA_VALID_BYTECOUNT)
471 bytecount = cts.xport_specific.ata.bytecount;
473 if (cts.xport_specific.sata.valid & CTS_SATA_VALID_BYTECOUNT)
474 bytecount = cts.xport_specific.sata.bytecount;
476 /* Honor device capabilities. */
478 bytecount = max(2, min(65534, bytecount));
479 if (ident_buf->satacapabilities != 0x0000 &&
480 ident_buf->satacapabilities != 0xffff) {
481 bytecount = min(8192, bytecount);
483 /* Report bytecount to SIM. */
484 bzero(&cts, sizeof(cts));
485 xpt_setup_ccb(&cts.ccb_h, path, CAM_PRIORITY_NONE);
486 cts.ccb_h.func_code = XPT_SET_TRAN_SETTINGS;
487 cts.type = CTS_TYPE_CURRENT_SETTINGS;
488 if (path->device->transport == XPORT_ATA) {
489 cts.xport_specific.ata.bytecount = bytecount;
490 cts.xport_specific.ata.valid = CTS_ATA_VALID_BYTECOUNT;
492 cts.xport_specific.sata.bytecount = bytecount;
493 cts.xport_specific.sata.valid = CTS_SATA_VALID_BYTECOUNT;
495 xpt_action((union ccb *)&cts);
498 case PROBE_FULL_INQUIRY:
501 struct scsi_inquiry_data *inq_buf =
502 &periph->path->device->inq_data;
504 if (softc->action == PROBE_INQUIRY)
505 inquiry_len = SHORT_INQUIRY_LENGTH;
507 inquiry_len = SID_ADDITIONAL_LENGTH(inq_buf);
509 * Some parallel SCSI devices fail to send an
510 * ignore wide residue message when dealing with
511 * odd length inquiry requests. Round up to be
514 inquiry_len = roundup2(inquiry_len, 2);
524 /*timeout*/60 * 1000);
528 cam_fill_ataio(ataio,
531 /*flags*/CAM_DIR_NONE,
536 ata_pm_read_cmd(ataio, 0, 15);
539 cam_fill_ataio(ataio,
542 /*flags*/CAM_DIR_NONE,
547 ata_pm_read_cmd(ataio, 1, 15);
550 CAM_DEBUG(path, CAM_DEBUG_INFO,
551 ("probestart: invalid action state\n"));
555 xpt_action(start_ccb);
559 proberequestdefaultnegotiation(struct cam_periph *periph)
561 struct ccb_trans_settings cts;
563 xpt_setup_ccb(&cts.ccb_h, periph->path, CAM_PRIORITY_NONE);
564 cts.ccb_h.func_code = XPT_GET_TRAN_SETTINGS;
565 cts.type = CTS_TYPE_USER_SETTINGS;
566 xpt_action((union ccb *)&cts);
567 if ((cts.ccb_h.status & CAM_STATUS_MASK) != CAM_REQ_CMP) {
570 cts.ccb_h.func_code = XPT_SET_TRAN_SETTINGS;
571 cts.type = CTS_TYPE_CURRENT_SETTINGS;
572 xpt_action((union ccb *)&cts);
576 * Backoff Negotiation Code- only pertinent for SPI devices.
579 proberequestbackoff(struct cam_periph *periph, struct cam_ed *device)
581 struct ccb_trans_settings cts;
582 struct ccb_trans_settings_spi *spi;
584 memset(&cts, 0, sizeof (cts));
585 xpt_setup_ccb(&cts.ccb_h, periph->path, CAM_PRIORITY_NONE);
586 cts.ccb_h.func_code = XPT_GET_TRAN_SETTINGS;
587 cts.type = CTS_TYPE_CURRENT_SETTINGS;
588 xpt_action((union ccb *)&cts);
589 if ((cts.ccb_h.status & CAM_STATUS_MASK) != CAM_REQ_CMP) {
591 xpt_print(periph->path,
592 "failed to get current device settings\n");
596 if (cts.transport != XPORT_SPI) {
598 xpt_print(periph->path, "not SPI transport\n");
602 spi = &cts.xport_specific.spi;
605 * We cannot renegotiate sync rate if we don't have one.
607 if ((spi->valid & CTS_SPI_VALID_SYNC_RATE) == 0) {
609 xpt_print(periph->path, "no sync rate known\n");
615 * We'll assert that we don't have to touch PPR options- the
616 * SIM will see what we do with period and offset and adjust
617 * the PPR options as appropriate.
621 * A sync rate with unknown or zero offset is nonsensical.
622 * A sync period of zero means Async.
624 if ((spi->valid & CTS_SPI_VALID_SYNC_OFFSET) == 0
625 || spi->sync_offset == 0 || spi->sync_period == 0) {
627 xpt_print(periph->path, "no sync rate available\n");
632 if (device->flags & CAM_DEV_DV_HIT_BOTTOM) {
633 CAM_DEBUG(periph->path, CAM_DEBUG_INFO,
634 ("hit async: giving up on DV\n"));
640 * Jump sync_period up by one, but stop at 5MHz and fall back to Async.
641 * We don't try to remember 'last' settings to see if the SIM actually
642 * gets into the speed we want to set. We check on the SIM telling
643 * us that a requested speed is bad, but otherwise don't try and
644 * check the speed due to the asynchronous and handshake nature
647 spi->valid = CTS_SPI_VALID_SYNC_RATE | CTS_SPI_VALID_SYNC_OFFSET;
650 if (spi->sync_period >= 0xf) {
651 spi->sync_period = 0;
652 spi->sync_offset = 0;
653 CAM_DEBUG(periph->path, CAM_DEBUG_INFO,
654 ("setting to async for DV\n"));
656 * Once we hit async, we don't want to try
659 device->flags |= CAM_DEV_DV_HIT_BOTTOM;
660 } else if (bootverbose) {
661 CAM_DEBUG(periph->path, CAM_DEBUG_INFO,
662 ("DV: period 0x%x\n", spi->sync_period));
663 printf("setting period to 0x%x\n", spi->sync_period);
665 cts.ccb_h.func_code = XPT_SET_TRAN_SETTINGS;
666 cts.type = CTS_TYPE_CURRENT_SETTINGS;
667 xpt_action((union ccb *)&cts);
668 if ((cts.ccb_h.status & CAM_STATUS_MASK) == CAM_REQ_CMP) {
671 CAM_DEBUG(periph->path, CAM_DEBUG_INFO,
672 ("DV: failed to set period 0x%x\n", spi->sync_period));
673 if (spi->sync_period == 0) {
681 probedone(struct cam_periph *periph, union ccb *done_ccb)
683 struct ccb_trans_settings cts;
684 struct ata_params *ident_buf;
686 struct cam_path *path;
690 CAM_DEBUG(done_ccb->ccb_h.path, CAM_DEBUG_TRACE, ("probedone\n"));
692 softc = (probe_softc *)periph->softc;
693 path = done_ccb->ccb_h.path;
694 priority = done_ccb->ccb_h.pinfo.priority;
695 ident_buf = &path->device->ident_data;
697 if ((done_ccb->ccb_h.status & CAM_STATUS_MASK) != CAM_REQ_CMP) {
698 device_fail: if (cam_periph_error(done_ccb, 0, 0,
699 &softc->saved_ccb) == ERESTART) {
701 } else if ((done_ccb->ccb_h.status & CAM_DEV_QFRZN) != 0) {
702 /* Don't wedge the queue */
703 xpt_release_devq(done_ccb->ccb_h.path, /*count*/1,
706 /* Old PIO2 devices may not support mode setting. */
707 if (softc->action == PROBE_SETMODE &&
708 ata_max_pmode(ident_buf) <= ATA_PIO2 &&
709 (ident_buf->capabilities1 & ATA_SUPPORT_IORDY) == 0)
712 * If we get to this point, we got an error status back
713 * from the inquiry and the error status doesn't require
714 * automatically retrying the command. Therefore, the
715 * inquiry failed. If we had inquiry information before
716 * for this device, but this latest inquiry command failed,
717 * the device has probably gone away. If this device isn't
718 * already marked unconfigured, notify the peripheral
719 * drivers that this device is no more.
721 if ((path->device->flags & CAM_DEV_UNCONFIGURED) == 0)
722 xpt_async(AC_LOST_DEVICE, path, NULL);
727 switch (softc->action) {
730 int sign = (done_ccb->ataio.res.lba_high << 8) +
731 done_ccb->ataio.res.lba_mid;
733 xpt_print(path, "SIGNATURE: %04x\n", sign);
734 if (sign == 0x0000 &&
735 done_ccb->ccb_h.target_id != 15) {
736 path->device->protocol = PROTO_ATA;
737 PROBE_SET_ACTION(softc, PROBE_IDENTIFY);
738 } else if (sign == 0x9669 &&
739 done_ccb->ccb_h.target_id == 15) {
740 /* Report SIM that PM is present. */
741 bzero(&cts, sizeof(cts));
742 xpt_setup_ccb(&cts.ccb_h, path, CAM_PRIORITY_NONE);
743 cts.ccb_h.func_code = XPT_SET_TRAN_SETTINGS;
744 cts.type = CTS_TYPE_CURRENT_SETTINGS;
745 cts.xport_specific.sata.pm_present = 1;
746 cts.xport_specific.sata.valid = CTS_SATA_VALID_PM;
747 xpt_action((union ccb *)&cts);
748 path->device->protocol = PROTO_SATAPM;
749 PROBE_SET_ACTION(softc, PROBE_PM_PID);
750 } else if (sign == 0xeb14 &&
751 done_ccb->ccb_h.target_id != 15) {
752 path->device->protocol = PROTO_SCSI;
753 PROBE_SET_ACTION(softc, PROBE_IDENTIFY);
755 if (done_ccb->ccb_h.target_id != 15) {
757 "Unexpected signature 0x%04x\n", sign);
761 xpt_release_ccb(done_ccb);
762 xpt_schedule(periph, priority);
769 for (ptr = (int16_t *)ident_buf;
770 ptr < (int16_t *)ident_buf + sizeof(struct ata_params)/2; ptr++) {
771 *ptr = le16toh(*ptr);
773 if (strncmp(ident_buf->model, "FX", 2) &&
774 strncmp(ident_buf->model, "NEC", 3) &&
775 strncmp(ident_buf->model, "Pioneer", 7) &&
776 strncmp(ident_buf->model, "SHARP", 5)) {
777 ata_bswap(ident_buf->model, sizeof(ident_buf->model));
778 ata_bswap(ident_buf->revision, sizeof(ident_buf->revision));
779 ata_bswap(ident_buf->serial, sizeof(ident_buf->serial));
781 ata_btrim(ident_buf->model, sizeof(ident_buf->model));
782 ata_bpack(ident_buf->model, ident_buf->model, sizeof(ident_buf->model));
783 ata_btrim(ident_buf->revision, sizeof(ident_buf->revision));
784 ata_bpack(ident_buf->revision, ident_buf->revision, sizeof(ident_buf->revision));
785 ata_btrim(ident_buf->serial, sizeof(ident_buf->serial));
786 ata_bpack(ident_buf->serial, ident_buf->serial, sizeof(ident_buf->serial));
788 if ((periph->path->device->flags & CAM_DEV_UNCONFIGURED) == 0) {
789 /* Check that it is the same device. */
795 (unsigned char *)ident_buf->model,
796 sizeof(ident_buf->model));
798 (unsigned char *)ident_buf->revision,
799 sizeof(ident_buf->revision));
801 (unsigned char *)ident_buf->serial,
802 sizeof(ident_buf->serial));
803 MD5Final(digest, &context);
804 if (bcmp(digest, softc->digest, sizeof(digest))) {
805 /* Device changed. */
806 xpt_async(AC_LOST_DEVICE, path, NULL);
809 /* Clean up from previous instance of this device */
810 if (path->device->serial_num != NULL) {
811 free(path->device->serial_num, M_CAMXPT);
812 path->device->serial_num = NULL;
813 path->device->serial_num_len = 0;
815 path->device->serial_num =
816 (u_int8_t *)malloc((sizeof(ident_buf->serial) + 1),
818 if (path->device->serial_num != NULL) {
819 bcopy(ident_buf->serial,
820 path->device->serial_num,
821 sizeof(ident_buf->serial));
822 path->device->serial_num[sizeof(ident_buf->serial)]
824 path->device->serial_num_len =
825 strlen(path->device->serial_num);
828 path->device->flags |= CAM_DEV_IDENTIFY_DATA_VALID;
830 if (ident_buf->satacapabilities & ATA_SUPPORT_NCQ) {
831 path->device->mintags = path->device->maxtags =
832 ATA_QUEUE_LEN(ident_buf->queue) + 1;
834 ata_find_quirk(path->device);
835 if (path->device->mintags != 0 &&
836 path->bus->sim->max_tagged_dev_openings != 0) {
837 /* Report SIM which tags are allowed. */
838 bzero(&cts, sizeof(cts));
839 xpt_setup_ccb(&cts.ccb_h, path, CAM_PRIORITY_NONE);
840 cts.ccb_h.func_code = XPT_SET_TRAN_SETTINGS;
841 cts.type = CTS_TYPE_CURRENT_SETTINGS;
842 cts.xport_specific.sata.tags = path->device->maxtags;
843 cts.xport_specific.sata.valid = CTS_SATA_VALID_TAGS;
844 xpt_action((union ccb *)&cts);
845 /* Reconfigure queues for tagged queueing. */
846 xpt_start_tags(path);
848 ata_device_transport(path);
849 PROBE_SET_ACTION(softc, PROBE_SETMODE);
850 xpt_release_ccb(done_ccb);
851 xpt_schedule(periph, priority);
855 if (path->device->protocol == PROTO_ATA) {
856 PROBE_SET_ACTION(softc, PROBE_SET_MULTI);
858 PROBE_SET_ACTION(softc, PROBE_INQUIRY);
860 xpt_release_ccb(done_ccb);
861 xpt_schedule(periph, priority);
863 case PROBE_SET_MULTI:
864 if (periph->path->device->flags & CAM_DEV_UNCONFIGURED) {
865 path->device->flags &= ~CAM_DEV_UNCONFIGURED;
866 xpt_acquire_device(path->device);
867 done_ccb->ccb_h.func_code = XPT_GDEV_TYPE;
868 xpt_action(done_ccb);
869 xpt_async(AC_FOUND_DEVICE, done_ccb->ccb_h.path,
874 case PROBE_FULL_INQUIRY:
876 struct scsi_inquiry_data *inq_buf;
877 u_int8_t periph_qual, len;
879 path->device->flags |= CAM_DEV_INQUIRY_DATA_VALID;
880 inq_buf = &path->device->inq_data;
882 periph_qual = SID_QUAL(inq_buf);
884 if (periph_qual != SID_QUAL_LU_CONNECTED)
888 * We conservatively request only
889 * SHORT_INQUIRY_LEN bytes of inquiry
890 * information during our first try
891 * at sending an INQUIRY. If the device
892 * has more information to give,
893 * perform a second request specifying
894 * the amount of information the device
895 * is willing to give.
897 len = inq_buf->additional_length
898 + offsetof(struct scsi_inquiry_data, additional_length) + 1;
899 if (softc->action == PROBE_INQUIRY
900 && len > SHORT_INQUIRY_LENGTH) {
901 PROBE_SET_ACTION(softc, PROBE_FULL_INQUIRY);
902 xpt_release_ccb(done_ccb);
903 xpt_schedule(periph, priority);
907 ata_device_transport(path);
908 if (periph->path->device->flags & CAM_DEV_UNCONFIGURED) {
909 path->device->flags &= ~CAM_DEV_UNCONFIGURED;
910 xpt_acquire_device(path->device);
911 done_ccb->ccb_h.func_code = XPT_GDEV_TYPE;
912 xpt_action(done_ccb);
913 xpt_async(AC_FOUND_DEVICE, done_ccb->ccb_h.path, done_ccb);
918 if ((path->device->flags & CAM_DEV_IDENTIFY_DATA_VALID) == 0)
919 bzero(ident_buf, sizeof(*ident_buf));
920 softc->pm_pid = (done_ccb->ataio.res.lba_high << 24) +
921 (done_ccb->ataio.res.lba_mid << 16) +
922 (done_ccb->ataio.res.lba_low << 8) +
923 done_ccb->ataio.res.sector_count;
924 ((uint32_t *)ident_buf)[0] = softc->pm_pid;
925 snprintf(ident_buf->model, sizeof(ident_buf->model),
926 "Port Multiplier %08x", softc->pm_pid);
927 PROBE_SET_ACTION(softc, PROBE_PM_PRV);
928 xpt_release_ccb(done_ccb);
929 xpt_schedule(periph, priority);
932 softc->pm_prv = (done_ccb->ataio.res.lba_high << 24) +
933 (done_ccb->ataio.res.lba_mid << 16) +
934 (done_ccb->ataio.res.lba_low << 8) +
935 done_ccb->ataio.res.sector_count;
936 ((uint32_t *)ident_buf)[1] = softc->pm_prv;
937 snprintf(ident_buf->revision, sizeof(ident_buf->revision),
938 "%04x", softc->pm_prv);
939 path->device->flags |= CAM_DEV_IDENTIFY_DATA_VALID;
940 if (periph->path->device->flags & CAM_DEV_UNCONFIGURED) {
941 path->device->flags &= ~CAM_DEV_UNCONFIGURED;
942 xpt_acquire_device(path->device);
943 done_ccb->ccb_h.func_code = XPT_GDEV_TYPE;
944 xpt_action(done_ccb);
945 xpt_async(AC_FOUND_DEVICE, done_ccb->ccb_h.path,
948 done_ccb->ccb_h.func_code = XPT_GDEV_TYPE;
949 xpt_action(done_ccb);
950 xpt_async(AC_SCSI_AEN, done_ccb->ccb_h.path, done_ccb);
954 CAM_DEBUG(done_ccb->ccb_h.path, CAM_DEBUG_INFO,
955 ("probedone: invalid action state\n"));
960 if (softc->restart) {
962 xpt_release_ccb(done_ccb);
963 probeschedule(periph);
966 xpt_release_ccb(done_ccb);
967 while ((done_ccb = (union ccb *)TAILQ_FIRST(&softc->request_ccbs))) {
968 TAILQ_REMOVE(&softc->request_ccbs,
969 &done_ccb->ccb_h, periph_links.tqe);
970 done_ccb->ccb_h.status = found ? CAM_REQ_CMP : CAM_REQ_CMP_ERR;
973 cam_release_devq(periph->path,
974 RELSIM_RELEASE_RUNLEVEL, 0, CAM_RL_XPT + 1, FALSE);
975 cam_periph_invalidate(periph);
976 cam_periph_release_locked(periph);
980 probecleanup(struct cam_periph *periph)
982 free(periph->softc, M_CAMXPT);
986 ata_find_quirk(struct cam_ed *device)
988 struct ata_quirk_entry *quirk;
991 match = cam_quirkmatch((caddr_t)&device->ident_data,
992 (caddr_t)ata_quirk_table,
993 ata_quirk_table_size,
994 sizeof(*ata_quirk_table), ata_identify_match);
997 panic("xpt_find_quirk: device didn't match wildcard entry!!");
999 quirk = (struct ata_quirk_entry *)match;
1000 device->quirk = quirk;
1001 if (quirk->quirks & CAM_QUIRK_MAXTAGS)
1002 device->mintags = device->maxtags = quirk->maxtags;
1006 union ccb *request_ccb;
1007 struct ccb_pathinq *cpi;
1009 } ata_scan_bus_info;
1012 * To start a scan, request_ccb is an XPT_SCAN_BUS ccb.
1013 * As the scan progresses, xpt_scan_bus is used as the
1014 * callback on completion function.
1017 ata_scan_bus(struct cam_periph *periph, union ccb *request_ccb)
1019 struct cam_path *path;
1020 ata_scan_bus_info *scan_info;
1021 union ccb *work_ccb, *reset_ccb;
1024 CAM_DEBUG(request_ccb->ccb_h.path, CAM_DEBUG_TRACE,
1025 ("xpt_scan_bus\n"));
1026 switch (request_ccb->ccb_h.func_code) {
1028 /* Find out the characteristics of the bus */
1029 work_ccb = xpt_alloc_ccb_nowait();
1030 if (work_ccb == NULL) {
1031 request_ccb->ccb_h.status = CAM_RESRC_UNAVAIL;
1032 xpt_done(request_ccb);
1035 xpt_setup_ccb(&work_ccb->ccb_h, request_ccb->ccb_h.path,
1036 request_ccb->ccb_h.pinfo.priority);
1037 work_ccb->ccb_h.func_code = XPT_PATH_INQ;
1038 xpt_action(work_ccb);
1039 if (work_ccb->ccb_h.status != CAM_REQ_CMP) {
1040 request_ccb->ccb_h.status = work_ccb->ccb_h.status;
1041 xpt_free_ccb(work_ccb);
1042 xpt_done(request_ccb);
1046 /* We may need to reset bus first, if we haven't done it yet. */
1047 if ((work_ccb->cpi.hba_inquiry &
1048 (PI_WIDE_32|PI_WIDE_16|PI_SDTR_ABLE)) &&
1049 !(work_ccb->cpi.hba_misc & PIM_NOBUSRESET) &&
1050 !timevalisset(&request_ccb->ccb_h.path->bus->last_reset)) {
1051 reset_ccb = xpt_alloc_ccb_nowait();
1052 xpt_setup_ccb(&reset_ccb->ccb_h, request_ccb->ccb_h.path,
1054 reset_ccb->ccb_h.func_code = XPT_RESET_BUS;
1055 xpt_action(reset_ccb);
1056 if (reset_ccb->ccb_h.status != CAM_REQ_CMP) {
1057 request_ccb->ccb_h.status = reset_ccb->ccb_h.status;
1058 xpt_free_ccb(reset_ccb);
1059 xpt_free_ccb(work_ccb);
1060 xpt_done(request_ccb);
1063 xpt_free_ccb(reset_ccb);
1066 /* Save some state for use while we probe for devices */
1067 scan_info = (ata_scan_bus_info *)
1068 malloc(sizeof(ata_scan_bus_info), M_CAMXPT, M_NOWAIT);
1069 if (scan_info == NULL) {
1070 request_ccb->ccb_h.status = CAM_RESRC_UNAVAIL;
1071 xpt_done(request_ccb);
1074 scan_info->request_ccb = request_ccb;
1075 scan_info->cpi = &work_ccb->cpi;
1076 /* If PM supported, probe it first. */
1077 if (scan_info->cpi->hba_inquiry & PI_SATAPM)
1078 scan_info->counter = scan_info->cpi->max_target;
1080 scan_info->counter = 0;
1082 work_ccb = xpt_alloc_ccb_nowait();
1083 if (work_ccb == NULL) {
1084 free(scan_info, M_CAMXPT);
1085 request_ccb->ccb_h.status = CAM_RESRC_UNAVAIL;
1086 xpt_done(request_ccb);
1091 work_ccb = request_ccb;
1092 /* Reuse the same CCB to query if a device was really found */
1093 scan_info = (ata_scan_bus_info *)work_ccb->ccb_h.ppriv_ptr0;
1094 /* Free the current request path- we're done with it. */
1095 xpt_free_path(work_ccb->ccb_h.path);
1096 /* If there is PMP... */
1097 if ((scan_info->cpi->hba_inquiry & PI_SATAPM) &&
1098 (scan_info->counter == scan_info->cpi->max_target)) {
1099 if (work_ccb->ccb_h.status == CAM_REQ_CMP) {
1100 /* everything else willbe probed by it */
1103 struct ccb_trans_settings cts;
1105 /* Report SIM that PM is absent. */
1106 bzero(&cts, sizeof(cts));
1107 xpt_setup_ccb(&cts.ccb_h,
1108 scan_info->request_ccb->ccb_h.path, 1);
1109 cts.ccb_h.func_code = XPT_SET_TRAN_SETTINGS;
1110 cts.type = CTS_TYPE_CURRENT_SETTINGS;
1111 cts.xport_specific.sata.pm_present = 0;
1112 cts.xport_specific.sata.valid = CTS_SATA_VALID_PM;
1113 xpt_action((union ccb *)&cts);
1116 if (scan_info->counter ==
1117 ((scan_info->cpi->hba_inquiry & PI_SATAPM) ?
1118 0 : scan_info->cpi->max_target)) {
1120 xpt_free_ccb(work_ccb);
1121 xpt_free_ccb((union ccb *)scan_info->cpi);
1122 request_ccb = scan_info->request_ccb;
1123 free(scan_info, M_CAMXPT);
1124 request_ccb->ccb_h.status = CAM_REQ_CMP;
1125 xpt_done(request_ccb);
1128 /* Take next device. Wrap from max (PMP) to 0. */
1129 scan_info->counter = (scan_info->counter + 1 ) %
1130 (scan_info->cpi->max_target + 1);
1132 status = xpt_create_path(&path, xpt_periph,
1133 scan_info->request_ccb->ccb_h.path_id,
1134 scan_info->counter, 0);
1135 if (status != CAM_REQ_CMP) {
1136 printf("xpt_scan_bus: xpt_create_path failed"
1137 " with status %#x, bus scan halted\n",
1139 xpt_free_ccb(work_ccb);
1140 xpt_free_ccb((union ccb *)scan_info->cpi);
1141 request_ccb = scan_info->request_ccb;
1142 free(scan_info, M_CAMXPT);
1143 request_ccb->ccb_h.status = status;
1144 xpt_done(request_ccb);
1147 xpt_setup_ccb(&work_ccb->ccb_h, path,
1148 scan_info->request_ccb->ccb_h.pinfo.priority);
1149 work_ccb->ccb_h.func_code = XPT_SCAN_LUN;
1150 work_ccb->ccb_h.cbfcnp = ata_scan_bus;
1151 work_ccb->ccb_h.ppriv_ptr0 = scan_info;
1152 work_ccb->crcn.flags = scan_info->request_ccb->crcn.flags;
1153 xpt_action(work_ccb);
1161 ata_scan_lun(struct cam_periph *periph, struct cam_path *path,
1162 cam_flags flags, union ccb *request_ccb)
1164 struct ccb_pathinq cpi;
1166 struct cam_path *new_path;
1167 struct cam_periph *old_periph;
1169 CAM_DEBUG(path, CAM_DEBUG_TRACE, ("xpt_scan_lun\n"));
1171 xpt_setup_ccb(&cpi.ccb_h, path, CAM_PRIORITY_NONE);
1172 cpi.ccb_h.func_code = XPT_PATH_INQ;
1173 xpt_action((union ccb *)&cpi);
1175 if (cpi.ccb_h.status != CAM_REQ_CMP) {
1176 if (request_ccb != NULL) {
1177 request_ccb->ccb_h.status = cpi.ccb_h.status;
1178 xpt_done(request_ccb);
1183 if (request_ccb == NULL) {
1184 request_ccb = malloc(sizeof(union ccb), M_CAMXPT, M_NOWAIT);
1185 if (request_ccb == NULL) {
1186 xpt_print(path, "xpt_scan_lun: can't allocate CCB, "
1187 "can't continue\n");
1190 new_path = malloc(sizeof(*new_path), M_CAMXPT, M_NOWAIT);
1191 if (new_path == NULL) {
1192 xpt_print(path, "xpt_scan_lun: can't allocate path, "
1193 "can't continue\n");
1194 free(request_ccb, M_CAMXPT);
1197 status = xpt_compile_path(new_path, xpt_periph,
1199 path->target->target_id,
1200 path->device->lun_id);
1202 if (status != CAM_REQ_CMP) {
1203 xpt_print(path, "xpt_scan_lun: can't compile path, "
1204 "can't continue\n");
1205 free(request_ccb, M_CAMXPT);
1206 free(new_path, M_CAMXPT);
1209 xpt_setup_ccb(&request_ccb->ccb_h, new_path, CAM_PRIORITY_XPT);
1210 request_ccb->ccb_h.cbfcnp = xptscandone;
1211 request_ccb->ccb_h.func_code = XPT_SCAN_LUN;
1212 request_ccb->crcn.flags = flags;
1215 if ((old_periph = cam_periph_find(path, "aprobe")) != NULL) {
1218 softc = (probe_softc *)old_periph->softc;
1219 TAILQ_INSERT_TAIL(&softc->request_ccbs, &request_ccb->ccb_h,
1223 status = cam_periph_alloc(proberegister, NULL, probecleanup,
1224 probestart, "aprobe",
1226 request_ccb->ccb_h.path, NULL, 0,
1229 if (status != CAM_REQ_CMP) {
1230 xpt_print(path, "xpt_scan_lun: cam_alloc_periph "
1231 "returned an error, can't continue probe\n");
1232 request_ccb->ccb_h.status = status;
1233 xpt_done(request_ccb);
1239 xptscandone(struct cam_periph *periph, union ccb *done_ccb)
1241 xpt_release_path(done_ccb->ccb_h.path);
1242 free(done_ccb->ccb_h.path, M_CAMXPT);
1243 free(done_ccb, M_CAMXPT);
1246 static struct cam_ed *
1247 ata_alloc_device(struct cam_eb *bus, struct cam_et *target, lun_id_t lun_id)
1249 struct cam_path path;
1250 struct ata_quirk_entry *quirk;
1251 struct cam_ed *device;
1252 struct cam_ed *cur_device;
1254 device = xpt_alloc_device(bus, target, lun_id);
1259 * Take the default quirk entry until we have inquiry
1260 * data and can determine a better quirk to use.
1262 quirk = &ata_quirk_table[ata_quirk_table_size - 1];
1263 device->quirk = (void *)quirk;
1264 device->mintags = 0;
1265 device->maxtags = 0;
1266 bzero(&device->inq_data, sizeof(device->inq_data));
1267 device->inq_flags = 0;
1268 device->queue_flags = 0;
1269 device->serial_num = NULL;
1270 device->serial_num_len = 0;
1273 * XXX should be limited by number of CCBs this bus can
1276 bus->sim->max_ccbs += device->ccbq.devq_openings;
1277 /* Insertion sort into our target's device list */
1278 cur_device = TAILQ_FIRST(&target->ed_entries);
1279 while (cur_device != NULL && cur_device->lun_id < lun_id)
1280 cur_device = TAILQ_NEXT(cur_device, links);
1281 if (cur_device != NULL) {
1282 TAILQ_INSERT_BEFORE(cur_device, device, links);
1284 TAILQ_INSERT_TAIL(&target->ed_entries, device, links);
1286 target->generation++;
1287 if (lun_id != CAM_LUN_WILDCARD) {
1288 xpt_compile_path(&path,
1293 ata_device_transport(&path);
1294 xpt_release_path(&path);
1301 ata_device_transport(struct cam_path *path)
1303 struct ccb_pathinq cpi;
1304 struct ccb_trans_settings cts;
1305 struct scsi_inquiry_data *inq_buf = NULL;
1306 struct ata_params *ident_buf = NULL;
1308 /* Get transport information from the SIM */
1309 xpt_setup_ccb(&cpi.ccb_h, path, CAM_PRIORITY_NONE);
1310 cpi.ccb_h.func_code = XPT_PATH_INQ;
1311 xpt_action((union ccb *)&cpi);
1313 path->device->transport = cpi.transport;
1314 if ((path->device->flags & CAM_DEV_INQUIRY_DATA_VALID) != 0)
1315 inq_buf = &path->device->inq_data;
1316 if ((path->device->flags & CAM_DEV_IDENTIFY_DATA_VALID) != 0)
1317 ident_buf = &path->device->ident_data;
1318 if (path->device->protocol == PROTO_ATA) {
1319 path->device->protocol_version = ident_buf ?
1320 ata_version(ident_buf->version_major) : cpi.protocol_version;
1321 } else if (path->device->protocol == PROTO_SCSI) {
1322 path->device->protocol_version = inq_buf ?
1323 SID_ANSI_REV(inq_buf) : cpi.protocol_version;
1325 path->device->transport_version = ident_buf ?
1326 ata_version(ident_buf->version_major) : cpi.transport_version;
1328 /* Tell the controller what we think */
1329 xpt_setup_ccb(&cts.ccb_h, path, CAM_PRIORITY_NONE);
1330 cts.ccb_h.func_code = XPT_SET_TRAN_SETTINGS;
1331 cts.type = CTS_TYPE_CURRENT_SETTINGS;
1332 cts.transport = path->device->transport;
1333 cts.transport_version = path->device->transport_version;
1334 cts.protocol = path->device->protocol;
1335 cts.protocol_version = path->device->protocol_version;
1336 cts.proto_specific.valid = 0;
1338 if (path->device->transport == XPORT_ATA) {
1339 cts.xport_specific.ata.atapi =
1340 ((ident_buf->config & ATA_PROTO_MASK) == ATA_PROTO_ATAPI_16) ? 16 :
1341 ((ident_buf->config & ATA_PROTO_MASK) == ATA_PROTO_ATAPI_12) ? 12 : 0;
1342 cts.xport_specific.ata.valid = CTS_ATA_VALID_ATAPI;
1344 cts.xport_specific.sata.atapi =
1345 ((ident_buf->config & ATA_PROTO_MASK) == ATA_PROTO_ATAPI_16) ? 16 :
1346 ((ident_buf->config & ATA_PROTO_MASK) == ATA_PROTO_ATAPI_12) ? 12 : 0;
1347 cts.xport_specific.sata.valid = CTS_SATA_VALID_ATAPI;
1350 cts.xport_specific.valid = 0;
1351 xpt_action((union ccb *)&cts);
1355 ata_action(union ccb *start_ccb)
1358 switch (start_ccb->ccb_h.func_code) {
1359 case XPT_SET_TRAN_SETTINGS:
1361 ata_set_transfer_settings(&start_ccb->cts,
1362 start_ccb->ccb_h.path->device,
1363 /*async_update*/FALSE);
1367 ata_scan_bus(start_ccb->ccb_h.path->periph, start_ccb);
1370 ata_scan_lun(start_ccb->ccb_h.path->periph,
1371 start_ccb->ccb_h.path, start_ccb->crcn.flags,
1374 case XPT_GET_TRAN_SETTINGS:
1376 struct cam_sim *sim;
1378 sim = start_ccb->ccb_h.path->bus->sim;
1379 (*(sim->sim_action))(sim, start_ccb);
1384 struct cam_ed *device;
1387 device = start_ccb->ccb_h.path->device;
1388 if (device->protocol == PROTO_SCSI &&
1389 (device->flags & CAM_DEV_IDENTIFY_DATA_VALID)) {
1391 device->ident_data.config & ATA_PROTO_MASK;
1393 maxlen = (p == ATA_PROTO_ATAPI_16) ? 16 :
1394 (p == ATA_PROTO_ATAPI_12) ? 12 : 0;
1396 if (start_ccb->csio.cdb_len > maxlen) {
1397 start_ccb->ccb_h.status = CAM_REQ_INVALID;
1398 xpt_done(start_ccb);
1404 xpt_action_default(start_ccb);
1410 ata_set_transfer_settings(struct ccb_trans_settings *cts, struct cam_ed *device,
1413 struct ccb_pathinq cpi;
1414 struct ccb_trans_settings cur_cts;
1415 struct ccb_trans_settings_scsi *scsi;
1416 struct ccb_trans_settings_scsi *cur_scsi;
1417 struct cam_sim *sim;
1418 struct scsi_inquiry_data *inq_data;
1420 if (device == NULL) {
1421 cts->ccb_h.status = CAM_PATH_INVALID;
1422 xpt_done((union ccb *)cts);
1426 if (cts->protocol == PROTO_UNKNOWN
1427 || cts->protocol == PROTO_UNSPECIFIED) {
1428 cts->protocol = device->protocol;
1429 cts->protocol_version = device->protocol_version;
1432 if (cts->protocol_version == PROTO_VERSION_UNKNOWN
1433 || cts->protocol_version == PROTO_VERSION_UNSPECIFIED)
1434 cts->protocol_version = device->protocol_version;
1436 if (cts->protocol != device->protocol) {
1437 xpt_print(cts->ccb_h.path, "Uninitialized Protocol %x:%x?\n",
1438 cts->protocol, device->protocol);
1439 cts->protocol = device->protocol;
1442 if (cts->protocol_version > device->protocol_version) {
1444 xpt_print(cts->ccb_h.path, "Down reving Protocol "
1445 "Version from %d to %d?\n", cts->protocol_version,
1446 device->protocol_version);
1448 cts->protocol_version = device->protocol_version;
1451 if (cts->transport == XPORT_UNKNOWN
1452 || cts->transport == XPORT_UNSPECIFIED) {
1453 cts->transport = device->transport;
1454 cts->transport_version = device->transport_version;
1457 if (cts->transport_version == XPORT_VERSION_UNKNOWN
1458 || cts->transport_version == XPORT_VERSION_UNSPECIFIED)
1459 cts->transport_version = device->transport_version;
1461 if (cts->transport != device->transport) {
1462 xpt_print(cts->ccb_h.path, "Uninitialized Transport %x:%x?\n",
1463 cts->transport, device->transport);
1464 cts->transport = device->transport;
1467 if (cts->transport_version > device->transport_version) {
1469 xpt_print(cts->ccb_h.path, "Down reving Transport "
1470 "Version from %d to %d?\n", cts->transport_version,
1471 device->transport_version);
1473 cts->transport_version = device->transport_version;
1476 sim = cts->ccb_h.path->bus->sim;
1479 * Nothing more of interest to do unless
1480 * this is a device connected via the
1483 if (cts->protocol != PROTO_SCSI) {
1484 if (async_update == FALSE)
1485 (*(sim->sim_action))(sim, (union ccb *)cts);
1489 inq_data = &device->inq_data;
1490 scsi = &cts->proto_specific.scsi;
1491 xpt_setup_ccb(&cpi.ccb_h, cts->ccb_h.path, CAM_PRIORITY_NONE);
1492 cpi.ccb_h.func_code = XPT_PATH_INQ;
1493 xpt_action((union ccb *)&cpi);
1495 /* SCSI specific sanity checking */
1496 if ((cpi.hba_inquiry & PI_TAG_ABLE) == 0
1497 || (INQ_DATA_TQ_ENABLED(inq_data)) == 0
1498 || (device->queue_flags & SCP_QUEUE_DQUE) != 0
1499 || (device->mintags == 0)) {
1501 * Can't tag on hardware that doesn't support tags,
1502 * doesn't have it enabled, or has broken tag support.
1504 scsi->flags &= ~CTS_SCSI_FLAGS_TAG_ENB;
1507 if (async_update == FALSE) {
1509 * Perform sanity checking against what the
1510 * controller and device can do.
1512 xpt_setup_ccb(&cur_cts.ccb_h, cts->ccb_h.path, CAM_PRIORITY_NONE);
1513 cur_cts.ccb_h.func_code = XPT_GET_TRAN_SETTINGS;
1514 cur_cts.type = cts->type;
1515 xpt_action((union ccb *)&cur_cts);
1516 if ((cur_cts.ccb_h.status & CAM_STATUS_MASK) != CAM_REQ_CMP) {
1519 cur_scsi = &cur_cts.proto_specific.scsi;
1520 if ((scsi->valid & CTS_SCSI_VALID_TQ) == 0) {
1521 scsi->flags &= ~CTS_SCSI_FLAGS_TAG_ENB;
1522 scsi->flags |= cur_scsi->flags & CTS_SCSI_FLAGS_TAG_ENB;
1524 if ((cur_scsi->valid & CTS_SCSI_VALID_TQ) == 0)
1525 scsi->flags &= ~CTS_SCSI_FLAGS_TAG_ENB;
1528 if (cts->type == CTS_TYPE_CURRENT_SETTINGS
1529 && (scsi->valid & CTS_SCSI_VALID_TQ) != 0) {
1533 * If we are transitioning from tags to no-tags or
1534 * vice-versa, we need to carefully freeze and restart
1535 * the queue so that we don't overlap tagged and non-tagged
1536 * commands. We also temporarily stop tags if there is
1537 * a change in transfer negotiation settings to allow
1538 * "tag-less" negotiation.
1540 if ((device->flags & CAM_DEV_TAG_AFTER_COUNT) != 0
1541 || (device->inq_flags & SID_CmdQue) != 0)
1542 device_tagenb = TRUE;
1544 device_tagenb = FALSE;
1546 if (((scsi->flags & CTS_SCSI_FLAGS_TAG_ENB) != 0
1547 && device_tagenb == FALSE)
1548 || ((scsi->flags & CTS_SCSI_FLAGS_TAG_ENB) == 0
1549 && device_tagenb == TRUE)) {
1551 if ((scsi->flags & CTS_SCSI_FLAGS_TAG_ENB) != 0) {
1553 * Delay change to use tags until after a
1554 * few commands have gone to this device so
1555 * the controller has time to perform transfer
1556 * negotiations without tagged messages getting
1559 device->tag_delay_count = CAM_TAG_DELAY_COUNT;
1560 device->flags |= CAM_DEV_TAG_AFTER_COUNT;
1562 xpt_stop_tags(cts->ccb_h.path);
1566 if (async_update == FALSE)
1567 (*(sim->sim_action))(sim, (union ccb *)cts);
1571 * Handle any per-device event notifications that require action by the XPT.
1574 ata_dev_async(u_int32_t async_code, struct cam_eb *bus, struct cam_et *target,
1575 struct cam_ed *device, void *async_arg)
1578 struct cam_path newpath;
1581 * We only need to handle events for real devices.
1583 if (target->target_id == CAM_TARGET_WILDCARD
1584 || device->lun_id == CAM_LUN_WILDCARD)
1588 * We need our own path with wildcards expanded to
1589 * handle certain types of events.
1591 if ((async_code == AC_SENT_BDR)
1592 || (async_code == AC_BUS_RESET)
1593 || (async_code == AC_INQ_CHANGED))
1594 status = xpt_compile_path(&newpath, NULL,
1599 status = CAM_REQ_CMP_ERR;
1601 if (status == CAM_REQ_CMP) {
1602 if (async_code == AC_INQ_CHANGED) {
1604 * We've sent a start unit command, or
1605 * something similar to a device that
1606 * may have caused its inquiry data to
1607 * change. So we re-scan the device to
1608 * refresh the inquiry data for it.
1610 ata_scan_lun(newpath.periph, &newpath,
1611 CAM_EXPECT_INQ_CHANGE, NULL);
1613 /* We need to reinitialize device after reset. */
1614 ata_scan_lun(newpath.periph, &newpath,
1617 xpt_release_path(&newpath);
1618 } else if (async_code == AC_LOST_DEVICE &&
1619 (device->flags & CAM_DEV_UNCONFIGURED) == 0) {
1620 device->flags |= CAM_DEV_UNCONFIGURED;
1621 xpt_release_device(device);
1622 } else if (async_code == AC_TRANSFER_NEG) {
1623 struct ccb_trans_settings *settings;
1625 settings = (struct ccb_trans_settings *)async_arg;
1626 ata_set_transfer_settings(settings, device,
1627 /*async_update*/TRUE);