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>
33 #include <sys/systm.h>
34 #include <sys/kernel.h>
36 #include <sys/sysctl.h>
37 #include <sys/taskqueue.h>
39 #include <sys/mutex.h>
41 #include <sys/devicestat.h>
42 #include <sys/eventhandler.h>
43 #include <sys/malloc.h>
45 #include <geom/geom_disk.h>
54 #include <cam/cam_ccb.h>
55 #include <cam/cam_periph.h>
56 #include <cam/cam_xpt_periph.h>
57 #include <cam/cam_xpt_internal.h>
58 #include <cam/cam_sim.h>
60 #include <cam/ata/ata_all.h>
67 PMP_STATE_PM_QUIRKS_1,
68 PMP_STATE_PM_QUIRKS_2,
69 PMP_STATE_PM_QUIRKS_3,
80 PMP_FLAG_SCTX_INIT = 0x200
87 /* Offsets into our private area for storing information */
88 #define ccb_state ppriv_field0
89 #define ccb_bp ppriv_ptr1
92 SLIST_ENTRY(pmp_softc) links;
105 #define PMP_EV_RESET 1
106 #define PMP_EV_RESCAN 2
108 struct task sysctl_task;
109 struct sysctl_ctx_list sysctl_ctx;
110 struct sysctl_oid *sysctl_tree;
113 static periph_init_t pmpinit;
114 static void pmpasync(void *callback_arg, u_int32_t code,
115 struct cam_path *path, void *arg);
116 static void pmpsysctlinit(void *context, int pending);
117 static periph_ctor_t pmpregister;
118 static periph_dtor_t pmpcleanup;
119 static periph_start_t pmpstart;
120 static periph_oninv_t pmponinvalidate;
121 static void pmpdone(struct cam_periph *periph,
122 union ccb *done_ccb);
124 #ifndef PMP_DEFAULT_TIMEOUT
125 #define PMP_DEFAULT_TIMEOUT 30 /* Timeout in seconds */
128 #ifndef PMP_DEFAULT_RETRY
129 #define PMP_DEFAULT_RETRY 1
132 #ifndef PMP_DEFAULT_HIDE_SPECIAL
133 #define PMP_DEFAULT_HIDE_SPECIAL 1
136 static int pmp_retry_count = PMP_DEFAULT_RETRY;
137 static int pmp_default_timeout = PMP_DEFAULT_TIMEOUT;
138 static int pmp_hide_special = PMP_DEFAULT_HIDE_SPECIAL;
140 static SYSCTL_NODE(_kern_cam, OID_AUTO, pmp, CTLFLAG_RD, 0,
141 "CAM Direct Access Disk driver");
142 SYSCTL_INT(_kern_cam_pmp, OID_AUTO, retry_count, CTLFLAG_RW,
143 &pmp_retry_count, 0, "Normal I/O retry count");
144 TUNABLE_INT("kern.cam.pmp.retry_count", &pmp_retry_count);
145 SYSCTL_INT(_kern_cam_pmp, OID_AUTO, default_timeout, CTLFLAG_RW,
146 &pmp_default_timeout, 0, "Normal I/O timeout (in seconds)");
147 TUNABLE_INT("kern.cam.pmp.default_timeout", &pmp_default_timeout);
148 SYSCTL_INT(_kern_cam_pmp, OID_AUTO, hide_special, CTLFLAG_RW,
149 &pmp_hide_special, 0, "Hide extra ports");
150 TUNABLE_INT("kern.cam.pmp.hide_special", &pmp_hide_special);
152 static struct periph_driver pmpdriver =
155 TAILQ_HEAD_INITIALIZER(pmpdriver.units), /* generation */ 0,
159 PERIPHDRIVER_DECLARE(pmp, pmpdriver);
161 static MALLOC_DEFINE(M_ATPMP, "ata_pmp", "ata_pmp buffers");
169 * Install a global async callback. This callback will
170 * receive async callbacks like "new device found".
172 status = xpt_register_async(AC_FOUND_DEVICE, pmpasync, NULL, NULL);
174 if (status != CAM_REQ_CMP) {
175 printf("pmp: Failed to attach master async callback "
176 "due to status 0x%x!\n", status);
181 pmpfreeze(struct cam_periph *periph, int mask)
183 struct pmp_softc *softc = (struct pmp_softc *)periph->softc;
184 struct cam_path *dpath;
187 mask &= ~softc->frozen;
188 for (i = 0; i < 15; i++) {
189 if ((mask & (1 << i)) == 0)
191 if (xpt_create_path(&dpath, periph,
192 xpt_path_path_id(periph->path),
193 i, 0) == CAM_REQ_CMP) {
194 softc->frozen |= (1 << i);
195 xpt_acquire_device(dpath->device);
196 cam_freeze_devq(dpath);
197 xpt_free_path(dpath);
203 pmprelease(struct cam_periph *periph, int mask)
205 struct pmp_softc *softc = (struct pmp_softc *)periph->softc;
206 struct cam_path *dpath;
209 mask &= softc->frozen;
210 for (i = 0; i < 15; i++) {
211 if ((mask & (1 << i)) == 0)
213 if (xpt_create_path(&dpath, periph,
214 xpt_path_path_id(periph->path),
215 i, 0) == CAM_REQ_CMP) {
216 softc->frozen &= ~(1 << i);
217 cam_release_devq(dpath, 0, 0, 0, FALSE);
218 xpt_release_device(dpath->device);
219 xpt_free_path(dpath);
225 pmponinvalidate(struct cam_periph *periph)
227 struct cam_path *dpath;
231 * De-register any async callbacks.
233 xpt_register_async(0, pmpasync, periph, periph->path);
235 for (i = 0; i < 15; i++) {
236 if (xpt_create_path(&dpath, periph,
237 xpt_path_path_id(periph->path),
238 i, 0) == CAM_REQ_CMP) {
239 xpt_async(AC_LOST_DEVICE, dpath, NULL);
240 xpt_free_path(dpath);
243 pmprelease(periph, -1);
244 xpt_print(periph->path, "lost device\n");
248 pmpcleanup(struct cam_periph *periph)
250 struct pmp_softc *softc;
252 softc = (struct pmp_softc *)periph->softc;
254 xpt_print(periph->path, "removing device entry\n");
255 cam_periph_unlock(periph);
258 * If we can't free the sysctl tree, oh well...
260 if ((softc->flags & PMP_FLAG_SCTX_INIT) != 0
261 && sysctl_ctx_free(&softc->sysctl_ctx) != 0) {
262 xpt_print(periph->path, "can't remove sysctl context\n");
265 free(softc, M_DEVBUF);
266 cam_periph_lock(periph);
270 pmpasync(void *callback_arg, u_int32_t code,
271 struct cam_path *path, void *arg)
273 struct cam_periph *periph;
274 struct pmp_softc *softc;
276 periph = (struct cam_periph *)callback_arg;
278 case AC_FOUND_DEVICE:
280 struct ccb_getdev *cgd;
283 cgd = (struct ccb_getdev *)arg;
287 if (cgd->protocol != PROTO_SATAPM)
291 * Allocate a peripheral instance for
292 * this device and start the probe
295 status = cam_periph_alloc(pmpregister, pmponinvalidate,
296 pmpcleanup, pmpstart,
297 "pmp", CAM_PERIPH_BIO,
298 cgd->ccb_h.path, pmpasync,
299 AC_FOUND_DEVICE, cgd);
301 if (status != CAM_REQ_CMP
302 && status != CAM_REQ_INPROG)
303 printf("pmpasync: Unable to attach to new device "
304 "due to status 0x%x\n", status);
310 softc = (struct pmp_softc *)periph->softc;
311 cam_periph_async(periph, code, path, arg);
312 if (code == AC_SCSI_AEN)
313 softc->events |= PMP_EV_RESCAN;
315 softc->events |= PMP_EV_RESET;
316 if (code == AC_SCSI_AEN && softc->state != PMP_STATE_NORMAL)
319 pmpfreeze(periph, softc->found);
320 if (code == AC_SENT_BDR || code == AC_BUS_RESET)
321 softc->found = 0; /* We have to reset everything. */
322 if (softc->state == PMP_STATE_NORMAL) {
323 if (softc->pm_pid == 0x37261095 ||
324 softc->pm_pid == 0x38261095)
325 softc->state = PMP_STATE_PM_QUIRKS_1;
327 softc->state = PMP_STATE_PRECONFIG;
328 cam_periph_acquire(periph);
329 xpt_schedule(periph, CAM_PRIORITY_DEV);
334 cam_periph_async(periph, code, path, arg);
340 pmpsysctlinit(void *context, int pending)
342 struct cam_periph *periph;
343 struct pmp_softc *softc;
344 char tmpstr[80], tmpstr2[80];
346 periph = (struct cam_periph *)context;
347 if (cam_periph_acquire(periph) != CAM_REQ_CMP)
350 softc = (struct pmp_softc *)periph->softc;
351 snprintf(tmpstr, sizeof(tmpstr), "CAM PMP unit %d", periph->unit_number);
352 snprintf(tmpstr2, sizeof(tmpstr2), "%d", periph->unit_number);
354 sysctl_ctx_init(&softc->sysctl_ctx);
355 softc->flags |= PMP_FLAG_SCTX_INIT;
356 softc->sysctl_tree = SYSCTL_ADD_NODE(&softc->sysctl_ctx,
357 SYSCTL_STATIC_CHILDREN(_kern_cam_pmp), OID_AUTO, tmpstr2,
358 CTLFLAG_RD, 0, tmpstr);
359 if (softc->sysctl_tree == NULL) {
360 printf("pmpsysctlinit: unable to allocate sysctl tree\n");
361 cam_periph_release(periph);
365 cam_periph_release(periph);
369 pmpregister(struct cam_periph *periph, void *arg)
371 struct pmp_softc *softc;
372 struct ccb_getdev *cgd;
374 cgd = (struct ccb_getdev *)arg;
376 printf("pmpregister: no getdev CCB, can't register device\n");
377 return(CAM_REQ_CMP_ERR);
380 softc = (struct pmp_softc *)malloc(sizeof(*softc), M_DEVBUF,
384 printf("pmpregister: Unable to probe new device. "
385 "Unable to allocate softc\n");
386 return(CAM_REQ_CMP_ERR);
388 periph->softc = softc;
390 softc->pm_pid = ((uint32_t *)&cgd->ident_data)[0];
391 softc->pm_prv = ((uint32_t *)&cgd->ident_data)[1];
392 TASK_INIT(&softc->sysctl_task, 0, pmpsysctlinit, periph);
394 xpt_announce_periph(periph, NULL);
397 * Add async callbacks for bus reset and
398 * bus device reset calls. I don't bother
399 * checking if this fails as, in most cases,
400 * the system will function just fine without
401 * them and the only alternative would be to
402 * not attach the device on failure.
404 xpt_register_async(AC_SENT_BDR | AC_BUS_RESET | AC_LOST_DEVICE |
405 AC_SCSI_AEN, pmpasync, periph, periph->path);
408 * Take an exclusive refcount on the periph while pmpstart is called
409 * to finish the probe. The reference will be dropped in pmpdone at
412 (void)cam_periph_acquire(periph);
414 softc->state = PMP_STATE_PORTS;
415 softc->events = PMP_EV_RESCAN;
416 xpt_schedule(periph, CAM_PRIORITY_DEV);
422 pmpstart(struct cam_periph *periph, union ccb *start_ccb)
424 struct ccb_trans_settings cts;
425 struct ccb_ataio *ataio;
426 struct pmp_softc *softc;
427 struct cam_path *dpath;
430 softc = (struct pmp_softc *)periph->softc;
431 ataio = &start_ccb->ataio;
433 CAM_DEBUG(periph->path, CAM_DEBUG_TRACE, ("pmpstart\n"));
435 if (softc->restart) {
437 if (softc->pm_pid == 0x37261095 || softc->pm_pid == 0x38261095)
438 softc->state = min(softc->state, PMP_STATE_PM_QUIRKS_1);
440 softc->state = min(softc->state, PMP_STATE_PRECONFIG);
442 /* Fetch user wanted device speed. */
443 if (softc->state == PMP_STATE_RESET ||
444 softc->state == PMP_STATE_CONNECT) {
445 if (xpt_create_path(&dpath, periph,
446 xpt_path_path_id(periph->path),
447 softc->pm_step, 0) == CAM_REQ_CMP) {
448 bzero(&cts, sizeof(cts));
449 xpt_setup_ccb(&cts.ccb_h, dpath, CAM_PRIORITY_NONE);
450 cts.ccb_h.func_code = XPT_GET_TRAN_SETTINGS;
451 cts.type = CTS_TYPE_USER_SETTINGS;
452 xpt_action((union ccb *)&cts);
453 if (cts.xport_specific.sata.valid & CTS_SATA_VALID_REVISION)
454 revision = cts.xport_specific.sata.revision;
455 xpt_free_path(dpath);
458 switch (softc->state) {
459 case PMP_STATE_PORTS:
460 cam_fill_ataio(ataio,
463 /*flags*/CAM_DIR_NONE,
467 pmp_default_timeout * 1000);
468 ata_pm_read_cmd(ataio, 2, 15);
471 case PMP_STATE_PM_QUIRKS_1:
472 case PMP_STATE_PM_QUIRKS_3:
473 cam_fill_ataio(ataio,
476 /*flags*/CAM_DIR_NONE,
480 pmp_default_timeout * 1000);
481 ata_pm_read_cmd(ataio, 129, 15);
484 case PMP_STATE_PM_QUIRKS_2:
485 cam_fill_ataio(ataio,
488 /*flags*/CAM_DIR_NONE,
492 pmp_default_timeout * 1000);
493 ata_pm_write_cmd(ataio, 129, 15, softc->caps & ~0x1);
496 case PMP_STATE_PRECONFIG:
497 /* Get/update host SATA capabilities. */
498 bzero(&cts, sizeof(cts));
499 xpt_setup_ccb(&cts.ccb_h, periph->path, CAM_PRIORITY_NONE);
500 cts.ccb_h.func_code = XPT_GET_TRAN_SETTINGS;
501 cts.type = CTS_TYPE_CURRENT_SETTINGS;
502 xpt_action((union ccb *)&cts);
503 if (cts.xport_specific.sata.valid & CTS_SATA_VALID_CAPS)
504 softc->caps = cts.xport_specific.sata.caps;
507 cam_fill_ataio(ataio,
510 /*flags*/CAM_DIR_NONE,
514 pmp_default_timeout * 1000);
515 ata_pm_write_cmd(ataio, 0x60, 15, 0x0);
517 case PMP_STATE_RESET:
518 cam_fill_ataio(ataio,
521 /*flags*/CAM_DIR_NONE,
525 pmp_default_timeout * 1000);
526 ata_pm_write_cmd(ataio, 2, softc->pm_step,
528 ((softc->found & (1 << softc->pm_step)) ? 0 : 1));
530 case PMP_STATE_CONNECT:
531 cam_fill_ataio(ataio,
534 /*flags*/CAM_DIR_NONE,
538 pmp_default_timeout * 1000);
539 ata_pm_write_cmd(ataio, 2, softc->pm_step,
542 case PMP_STATE_CHECK:
543 cam_fill_ataio(ataio,
546 /*flags*/CAM_DIR_NONE,
550 pmp_default_timeout * 1000);
551 ata_pm_read_cmd(ataio, 0, softc->pm_step);
553 case PMP_STATE_CLEAR:
555 cam_fill_ataio(ataio,
558 /*flags*/CAM_DIR_NONE,
562 pmp_default_timeout * 1000);
563 ata_pm_write_cmd(ataio, 1, softc->pm_step, 0xFFFFFFFF);
565 case PMP_STATE_CONFIG:
566 cam_fill_ataio(ataio,
569 /*flags*/CAM_DIR_NONE,
573 pmp_default_timeout * 1000);
574 ata_pm_write_cmd(ataio, 0x60, 15, 0x07 |
575 ((softc->caps & CTS_SATA_CAPS_H_AN) ? 0x08 : 0));
580 xpt_action(start_ccb);
584 pmpdone(struct cam_periph *periph, union ccb *done_ccb)
586 struct ccb_trans_settings cts;
587 struct pmp_softc *softc;
588 struct ccb_ataio *ataio;
589 struct cam_path *dpath;
590 u_int32_t priority, res;
593 softc = (struct pmp_softc *)periph->softc;
594 ataio = &done_ccb->ataio;
596 CAM_DEBUG(periph->path, CAM_DEBUG_TRACE, ("pmpdone\n"));
598 priority = done_ccb->ccb_h.pinfo.priority;
600 if ((done_ccb->ccb_h.status & CAM_STATUS_MASK) != CAM_REQ_CMP) {
601 if (cam_periph_error(done_ccb, 0, 0, NULL) == ERESTART) {
603 } else if ((done_ccb->ccb_h.status & CAM_DEV_QFRZN) != 0) {
604 cam_release_devq(done_ccb->ccb_h.path,
613 if (softc->restart) {
615 xpt_release_ccb(done_ccb);
616 if (softc->pm_pid == 0x37261095 || softc->pm_pid == 0x38261095)
617 softc->state = min(softc->state, PMP_STATE_PM_QUIRKS_1);
619 softc->state = min(softc->state, PMP_STATE_PRECONFIG);
620 xpt_schedule(periph, priority);
624 switch (softc->state) {
625 case PMP_STATE_PORTS:
626 softc->pm_ports = (ataio->res.lba_high << 24) +
627 (ataio->res.lba_mid << 16) +
628 (ataio->res.lba_low << 8) +
629 ataio->res.sector_count;
630 if (pmp_hide_special) {
632 * This PMP declares 6 ports, while only 5 of them
633 * are real. Port 5 is a SEMB port, probing which
634 * causes timeouts if external SEP is not connected
637 if ((softc->pm_pid == 0x37261095 ||
638 softc->pm_pid == 0x38261095) &&
639 softc->pm_ports == 6)
643 * This PMP declares 7 ports, while only 5 of them
644 * are real. Port 5 is a fake "Config Disk" with
645 * 640 sectors size. Port 6 is a SEMB port.
647 if (softc->pm_pid == 0x47261095 && softc->pm_ports == 7)
651 * These PMPs have extra configuration port.
653 if (softc->pm_pid == 0x57231095 ||
654 softc->pm_pid == 0x57331095 ||
655 softc->pm_pid == 0x57341095 ||
656 softc->pm_pid == 0x57441095)
659 printf("%s%d: %d fan-out ports\n",
660 periph->periph_name, periph->unit_number,
662 if (softc->pm_pid == 0x37261095 || softc->pm_pid == 0x38261095)
663 softc->state = PMP_STATE_PM_QUIRKS_1;
665 softc->state = PMP_STATE_PRECONFIG;
666 xpt_release_ccb(done_ccb);
667 xpt_schedule(periph, priority);
670 case PMP_STATE_PM_QUIRKS_1:
671 softc->caps = (ataio->res.lba_high << 24) +
672 (ataio->res.lba_mid << 16) +
673 (ataio->res.lba_low << 8) +
674 ataio->res.sector_count;
675 if (softc->caps & 0x1)
676 softc->state = PMP_STATE_PM_QUIRKS_2;
678 softc->state = PMP_STATE_PRECONFIG;
679 xpt_release_ccb(done_ccb);
680 xpt_schedule(periph, priority);
683 case PMP_STATE_PM_QUIRKS_2:
685 softc->state = PMP_STATE_PM_QUIRKS_3;
687 softc->state = PMP_STATE_PRECONFIG;
688 xpt_release_ccb(done_ccb);
689 xpt_schedule(periph, priority);
692 case PMP_STATE_PM_QUIRKS_3:
693 res = (ataio->res.lba_high << 24) +
694 (ataio->res.lba_mid << 16) +
695 (ataio->res.lba_low << 8) +
696 ataio->res.sector_count;
697 printf("%s%d: Disabling SiI3x26 R_OK in GSCR_POLL: %x->%x\n",
698 periph->periph_name, periph->unit_number, softc->caps, res);
699 softc->state = PMP_STATE_PRECONFIG;
700 xpt_release_ccb(done_ccb);
701 xpt_schedule(periph, priority);
704 case PMP_STATE_PRECONFIG:
706 softc->state = PMP_STATE_RESET;
707 softc->reset |= ~softc->found;
708 xpt_release_ccb(done_ccb);
709 xpt_schedule(periph, priority);
711 case PMP_STATE_RESET:
713 if (softc->pm_step >= softc->pm_ports) {
715 cam_freeze_devq(periph->path);
716 cam_release_devq(periph->path,
717 RELSIM_RELEASE_AFTER_TIMEOUT,
721 softc->state = PMP_STATE_CONNECT;
723 xpt_release_ccb(done_ccb);
724 xpt_schedule(periph, priority);
726 case PMP_STATE_CONNECT:
728 if (softc->pm_step >= softc->pm_ports) {
731 cam_freeze_devq(periph->path);
732 cam_release_devq(periph->path,
733 RELSIM_RELEASE_AFTER_TIMEOUT,
737 softc->state = PMP_STATE_CHECK;
739 xpt_release_ccb(done_ccb);
740 xpt_schedule(periph, priority);
742 case PMP_STATE_CHECK:
743 res = (ataio->res.lba_high << 24) +
744 (ataio->res.lba_mid << 16) +
745 (ataio->res.lba_low << 8) +
746 ataio->res.sector_count;
747 if (((res & 0xf0f) == 0x103 && (res & 0x0f0) != 0) ||
748 (res & 0x600) != 0) {
750 printf("%s%d: port %d status: %08x\n",
751 periph->periph_name, periph->unit_number,
752 softc->pm_step, res);
754 /* Report device speed if it is online. */
755 if ((res & 0xf0f) == 0x103 &&
756 xpt_create_path(&dpath, periph,
757 xpt_path_path_id(periph->path),
758 softc->pm_step, 0) == CAM_REQ_CMP) {
759 bzero(&cts, sizeof(cts));
760 xpt_setup_ccb(&cts.ccb_h, dpath, CAM_PRIORITY_NONE);
761 cts.ccb_h.func_code = XPT_SET_TRAN_SETTINGS;
762 cts.type = CTS_TYPE_CURRENT_SETTINGS;
763 cts.xport_specific.sata.revision = (res & 0x0f0) >> 4;
764 cts.xport_specific.sata.valid = CTS_SATA_VALID_REVISION;
765 cts.xport_specific.sata.caps = softc->caps &
766 (CTS_SATA_CAPS_H_PMREQ |
767 CTS_SATA_CAPS_H_DMAAA |
769 cts.xport_specific.sata.valid |= CTS_SATA_VALID_CAPS;
770 xpt_action((union ccb *)&cts);
771 xpt_free_path(dpath);
773 softc->found |= (1 << softc->pm_step);
776 if (softc->pm_try < 10) {
777 cam_freeze_devq(periph->path);
778 cam_release_devq(periph->path,
779 RELSIM_RELEASE_AFTER_TIMEOUT,
786 printf("%s%d: port %d status: %08x\n",
787 periph->periph_name, periph->unit_number,
788 softc->pm_step, res);
790 softc->found &= ~(1 << softc->pm_step);
791 if (xpt_create_path(&dpath, periph,
792 done_ccb->ccb_h.path_id,
793 softc->pm_step, 0) == CAM_REQ_CMP) {
794 xpt_async(AC_LOST_DEVICE, dpath, NULL);
795 xpt_free_path(dpath);
800 if (softc->pm_step >= softc->pm_ports) {
801 if (softc->reset & softc->found) {
802 cam_freeze_devq(periph->path);
803 cam_release_devq(periph->path,
804 RELSIM_RELEASE_AFTER_TIMEOUT,
809 softc->state = PMP_STATE_CLEAR;
812 xpt_release_ccb(done_ccb);
813 xpt_schedule(periph, priority);
815 case PMP_STATE_CLEAR:
817 if (softc->pm_step >= softc->pm_ports) {
818 softc->state = PMP_STATE_CONFIG;
821 xpt_release_ccb(done_ccb);
822 xpt_schedule(periph, priority);
824 case PMP_STATE_CONFIG:
825 for (i = 0; i < softc->pm_ports; i++) {
828 if ((softc->found & (1 << i)) == 0)
830 if (xpt_create_path(&dpath, periph,
831 xpt_path_path_id(periph->path),
832 i, 0) != CAM_REQ_CMP) {
833 printf("pmpdone: xpt_create_path failed\n");
836 /* If we did hard reset to this device, inform XPT. */
837 if ((softc->reset & softc->found & (1 << i)) != 0)
838 xpt_async(AC_SENT_BDR, dpath, NULL);
839 /* If rescan requested, scan this device. */
840 if (softc->events & PMP_EV_RESCAN) {
841 ccb = xpt_alloc_ccb_nowait();
843 xpt_free_path(dpath);
846 xpt_setup_ccb(&ccb->ccb_h, dpath, CAM_PRIORITY_XPT);
849 xpt_free_path(dpath);
856 xpt_release_ccb(done_ccb);
857 softc->state = PMP_STATE_NORMAL;
860 pmprelease(periph, -1);
861 cam_periph_release_locked(periph);