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_arg(dpath,
197 RELSIM_RELEASE_RUNLEVEL, CAM_RL_BUS + 1);
198 xpt_free_path(dpath);
204 pmprelease(struct cam_periph *periph, int mask)
206 struct pmp_softc *softc = (struct pmp_softc *)periph->softc;
207 struct cam_path *dpath;
210 mask &= softc->frozen;
211 for (i = 0; i < 15; i++) {
212 if ((mask & (1 << i)) == 0)
214 if (xpt_create_path(&dpath, periph,
215 xpt_path_path_id(periph->path),
216 i, 0) == CAM_REQ_CMP) {
217 softc->frozen &= ~(1 << i);
218 cam_release_devq(dpath,
219 RELSIM_RELEASE_RUNLEVEL, 0, CAM_RL_BUS + 1, FALSE);
220 xpt_release_device(dpath->device);
221 xpt_free_path(dpath);
227 pmponinvalidate(struct cam_periph *periph)
229 struct cam_path *dpath;
233 * De-register any async callbacks.
235 xpt_register_async(0, pmpasync, periph, periph->path);
237 for (i = 0; i < 15; i++) {
238 if (xpt_create_path(&dpath, periph,
239 xpt_path_path_id(periph->path),
240 i, 0) == CAM_REQ_CMP) {
241 xpt_async(AC_LOST_DEVICE, dpath, NULL);
242 xpt_free_path(dpath);
245 pmprelease(periph, -1);
246 xpt_print(periph->path, "lost device\n");
250 pmpcleanup(struct cam_periph *periph)
252 struct pmp_softc *softc;
254 softc = (struct pmp_softc *)periph->softc;
256 xpt_print(periph->path, "removing device entry\n");
257 cam_periph_unlock(periph);
260 * If we can't free the sysctl tree, oh well...
262 if ((softc->flags & PMP_FLAG_SCTX_INIT) != 0
263 && sysctl_ctx_free(&softc->sysctl_ctx) != 0) {
264 xpt_print(periph->path, "can't remove sysctl context\n");
267 free(softc, M_DEVBUF);
268 cam_periph_lock(periph);
272 pmpasync(void *callback_arg, u_int32_t code,
273 struct cam_path *path, void *arg)
275 struct cam_periph *periph;
276 struct pmp_softc *softc;
278 periph = (struct cam_periph *)callback_arg;
280 case AC_FOUND_DEVICE:
282 struct ccb_getdev *cgd;
285 cgd = (struct ccb_getdev *)arg;
289 if (cgd->protocol != PROTO_SATAPM)
293 * Allocate a peripheral instance for
294 * this device and start the probe
297 status = cam_periph_alloc(pmpregister, pmponinvalidate,
298 pmpcleanup, pmpstart,
299 "pmp", CAM_PERIPH_BIO,
300 cgd->ccb_h.path, pmpasync,
301 AC_FOUND_DEVICE, cgd);
303 if (status != CAM_REQ_CMP
304 && status != CAM_REQ_INPROG)
305 printf("pmpasync: Unable to attach to new device "
306 "due to status 0x%x\n", status);
312 softc = (struct pmp_softc *)periph->softc;
313 cam_periph_async(periph, code, path, arg);
314 if (code == AC_SCSI_AEN)
315 softc->events |= PMP_EV_RESCAN;
317 softc->events |= PMP_EV_RESET;
318 if (code == AC_SCSI_AEN && softc->state != PMP_STATE_NORMAL)
321 pmpfreeze(periph, softc->found);
322 if (code == AC_SENT_BDR || code == AC_BUS_RESET)
323 softc->found = 0; /* We have to reset everything. */
324 if (softc->state == PMP_STATE_NORMAL) {
325 if (softc->pm_pid == 0x37261095 ||
326 softc->pm_pid == 0x38261095)
327 softc->state = PMP_STATE_PM_QUIRKS_1;
329 softc->state = PMP_STATE_PRECONFIG;
330 cam_periph_acquire(periph);
331 xpt_schedule(periph, CAM_PRIORITY_DEV);
336 cam_periph_async(periph, code, path, arg);
342 pmpsysctlinit(void *context, int pending)
344 struct cam_periph *periph;
345 struct pmp_softc *softc;
346 char tmpstr[80], tmpstr2[80];
348 periph = (struct cam_periph *)context;
349 if (cam_periph_acquire(periph) != CAM_REQ_CMP)
352 softc = (struct pmp_softc *)periph->softc;
353 snprintf(tmpstr, sizeof(tmpstr), "CAM PMP unit %d", periph->unit_number);
354 snprintf(tmpstr2, sizeof(tmpstr2), "%d", periph->unit_number);
356 sysctl_ctx_init(&softc->sysctl_ctx);
357 softc->flags |= PMP_FLAG_SCTX_INIT;
358 softc->sysctl_tree = SYSCTL_ADD_NODE(&softc->sysctl_ctx,
359 SYSCTL_STATIC_CHILDREN(_kern_cam_pmp), OID_AUTO, tmpstr2,
360 CTLFLAG_RD, 0, tmpstr);
361 if (softc->sysctl_tree == NULL) {
362 printf("pmpsysctlinit: unable to allocate sysctl tree\n");
363 cam_periph_release(periph);
367 cam_periph_release(periph);
371 pmpregister(struct cam_periph *periph, void *arg)
373 struct pmp_softc *softc;
374 struct ccb_getdev *cgd;
376 cgd = (struct ccb_getdev *)arg;
378 printf("pmpregister: no getdev CCB, can't register device\n");
379 return(CAM_REQ_CMP_ERR);
382 softc = (struct pmp_softc *)malloc(sizeof(*softc), M_DEVBUF,
386 printf("pmpregister: Unable to probe new device. "
387 "Unable to allocate softc\n");
388 return(CAM_REQ_CMP_ERR);
390 periph->softc = softc;
392 softc->pm_pid = ((uint32_t *)&cgd->ident_data)[0];
393 softc->pm_prv = ((uint32_t *)&cgd->ident_data)[1];
394 TASK_INIT(&softc->sysctl_task, 0, pmpsysctlinit, periph);
396 xpt_announce_periph(periph, NULL);
399 * Add async callbacks for bus reset and
400 * bus device reset calls. I don't bother
401 * checking if this fails as, in most cases,
402 * the system will function just fine without
403 * them and the only alternative would be to
404 * not attach the device on failure.
406 xpt_register_async(AC_SENT_BDR | AC_BUS_RESET | AC_LOST_DEVICE |
407 AC_SCSI_AEN, pmpasync, periph, periph->path);
410 * Take an exclusive refcount on the periph while pmpstart is called
411 * to finish the probe. The reference will be dropped in pmpdone at
414 (void)cam_periph_acquire(periph);
416 softc->state = PMP_STATE_PORTS;
417 softc->events = PMP_EV_RESCAN;
418 xpt_schedule(periph, CAM_PRIORITY_DEV);
424 pmpstart(struct cam_periph *periph, union ccb *start_ccb)
426 struct ccb_trans_settings cts;
427 struct ccb_ataio *ataio;
428 struct pmp_softc *softc;
429 struct cam_path *dpath;
432 softc = (struct pmp_softc *)periph->softc;
433 ataio = &start_ccb->ataio;
435 CAM_DEBUG(periph->path, CAM_DEBUG_TRACE, ("pmpstart\n"));
437 if (softc->restart) {
439 if (softc->pm_pid == 0x37261095 || softc->pm_pid == 0x38261095)
440 softc->state = min(softc->state, PMP_STATE_PM_QUIRKS_1);
442 softc->state = min(softc->state, PMP_STATE_PRECONFIG);
444 /* Fetch user wanted device speed. */
445 if (softc->state == PMP_STATE_RESET ||
446 softc->state == PMP_STATE_CONNECT) {
447 if (xpt_create_path(&dpath, periph,
448 xpt_path_path_id(periph->path),
449 softc->pm_step, 0) == CAM_REQ_CMP) {
450 bzero(&cts, sizeof(cts));
451 xpt_setup_ccb(&cts.ccb_h, dpath, CAM_PRIORITY_NONE);
452 cts.ccb_h.func_code = XPT_GET_TRAN_SETTINGS;
453 cts.type = CTS_TYPE_USER_SETTINGS;
454 xpt_action((union ccb *)&cts);
455 if (cts.xport_specific.sata.valid & CTS_SATA_VALID_REVISION)
456 revision = cts.xport_specific.sata.revision;
457 xpt_free_path(dpath);
460 switch (softc->state) {
461 case PMP_STATE_PORTS:
462 cam_fill_ataio(ataio,
465 /*flags*/CAM_DIR_NONE,
469 pmp_default_timeout * 1000);
470 ata_pm_read_cmd(ataio, 2, 15);
473 case PMP_STATE_PM_QUIRKS_1:
474 case PMP_STATE_PM_QUIRKS_3:
475 cam_fill_ataio(ataio,
478 /*flags*/CAM_DIR_NONE,
482 pmp_default_timeout * 1000);
483 ata_pm_read_cmd(ataio, 129, 15);
486 case PMP_STATE_PM_QUIRKS_2:
487 cam_fill_ataio(ataio,
490 /*flags*/CAM_DIR_NONE,
494 pmp_default_timeout * 1000);
495 ata_pm_write_cmd(ataio, 129, 15, softc->caps & ~0x1);
498 case PMP_STATE_PRECONFIG:
499 /* Get/update host SATA capabilities. */
500 bzero(&cts, sizeof(cts));
501 xpt_setup_ccb(&cts.ccb_h, periph->path, CAM_PRIORITY_NONE);
502 cts.ccb_h.func_code = XPT_GET_TRAN_SETTINGS;
503 cts.type = CTS_TYPE_CURRENT_SETTINGS;
504 xpt_action((union ccb *)&cts);
505 if (cts.xport_specific.sata.valid & CTS_SATA_VALID_CAPS)
506 softc->caps = cts.xport_specific.sata.caps;
509 cam_fill_ataio(ataio,
512 /*flags*/CAM_DIR_NONE,
516 pmp_default_timeout * 1000);
517 ata_pm_write_cmd(ataio, 0x60, 15, 0x0);
519 case PMP_STATE_RESET:
520 cam_fill_ataio(ataio,
523 /*flags*/CAM_DIR_NONE,
527 pmp_default_timeout * 1000);
528 ata_pm_write_cmd(ataio, 2, softc->pm_step,
530 ((softc->found & (1 << softc->pm_step)) ? 0 : 1));
532 case PMP_STATE_CONNECT:
533 cam_fill_ataio(ataio,
536 /*flags*/CAM_DIR_NONE,
540 pmp_default_timeout * 1000);
541 ata_pm_write_cmd(ataio, 2, softc->pm_step,
544 case PMP_STATE_CHECK:
545 cam_fill_ataio(ataio,
548 /*flags*/CAM_DIR_NONE,
552 pmp_default_timeout * 1000);
553 ata_pm_read_cmd(ataio, 0, softc->pm_step);
555 case PMP_STATE_CLEAR:
557 cam_fill_ataio(ataio,
560 /*flags*/CAM_DIR_NONE,
564 pmp_default_timeout * 1000);
565 ata_pm_write_cmd(ataio, 1, softc->pm_step, 0xFFFFFFFF);
567 case PMP_STATE_CONFIG:
568 cam_fill_ataio(ataio,
571 /*flags*/CAM_DIR_NONE,
575 pmp_default_timeout * 1000);
576 ata_pm_write_cmd(ataio, 0x60, 15, 0x07 |
577 ((softc->caps & CTS_SATA_CAPS_H_AN) ? 0x08 : 0));
582 xpt_action(start_ccb);
586 pmpdone(struct cam_periph *periph, union ccb *done_ccb)
588 struct ccb_trans_settings cts;
589 struct pmp_softc *softc;
590 struct ccb_ataio *ataio;
591 struct cam_path *dpath;
592 u_int32_t priority, res;
595 softc = (struct pmp_softc *)periph->softc;
596 ataio = &done_ccb->ataio;
598 CAM_DEBUG(periph->path, CAM_DEBUG_TRACE, ("pmpdone\n"));
600 priority = done_ccb->ccb_h.pinfo.priority;
602 if ((done_ccb->ccb_h.status & CAM_STATUS_MASK) != CAM_REQ_CMP) {
603 if (cam_periph_error(done_ccb, 0, 0, NULL) == ERESTART) {
605 } else if ((done_ccb->ccb_h.status & CAM_DEV_QFRZN) != 0) {
606 cam_release_devq(done_ccb->ccb_h.path,
615 if (softc->restart) {
617 xpt_release_ccb(done_ccb);
618 if (softc->pm_pid == 0x37261095 || softc->pm_pid == 0x38261095)
619 softc->state = min(softc->state, PMP_STATE_PM_QUIRKS_1);
621 softc->state = min(softc->state, PMP_STATE_PRECONFIG);
622 xpt_schedule(periph, priority);
626 switch (softc->state) {
627 case PMP_STATE_PORTS:
628 softc->pm_ports = (ataio->res.lba_high << 24) +
629 (ataio->res.lba_mid << 16) +
630 (ataio->res.lba_low << 8) +
631 ataio->res.sector_count;
632 if (pmp_hide_special) {
634 * This PMP declares 6 ports, while only 5 of them
635 * are real. Port 5 is a SEMB port, probing which
636 * causes timeouts if external SEP is not connected
639 if ((softc->pm_pid == 0x37261095 ||
640 softc->pm_pid == 0x38261095) &&
641 softc->pm_ports == 6)
645 * This PMP declares 7 ports, while only 5 of them
646 * are real. Port 5 is a fake "Config Disk" with
647 * 640 sectors size. Port 6 is a SEMB port.
649 if (softc->pm_pid == 0x47261095 && softc->pm_ports == 7)
653 * These PMPs have extra configuration port.
655 if (softc->pm_pid == 0x57231095 ||
656 softc->pm_pid == 0x57331095 ||
657 softc->pm_pid == 0x57341095 ||
658 softc->pm_pid == 0x57441095)
661 printf("%s%d: %d fan-out ports\n",
662 periph->periph_name, periph->unit_number,
664 if (softc->pm_pid == 0x37261095 || softc->pm_pid == 0x38261095)
665 softc->state = PMP_STATE_PM_QUIRKS_1;
667 softc->state = PMP_STATE_PRECONFIG;
668 xpt_release_ccb(done_ccb);
669 xpt_schedule(periph, priority);
672 case PMP_STATE_PM_QUIRKS_1:
673 softc->caps = (ataio->res.lba_high << 24) +
674 (ataio->res.lba_mid << 16) +
675 (ataio->res.lba_low << 8) +
676 ataio->res.sector_count;
677 if (softc->caps & 0x1)
678 softc->state = PMP_STATE_PM_QUIRKS_2;
680 softc->state = PMP_STATE_PRECONFIG;
681 xpt_release_ccb(done_ccb);
682 xpt_schedule(periph, priority);
685 case PMP_STATE_PM_QUIRKS_2:
687 softc->state = PMP_STATE_PM_QUIRKS_3;
689 softc->state = PMP_STATE_PRECONFIG;
690 xpt_release_ccb(done_ccb);
691 xpt_schedule(periph, priority);
694 case PMP_STATE_PM_QUIRKS_3:
695 res = (ataio->res.lba_high << 24) +
696 (ataio->res.lba_mid << 16) +
697 (ataio->res.lba_low << 8) +
698 ataio->res.sector_count;
699 printf("%s%d: Disabling SiI3x26 R_OK in GSCR_POLL: %x->%x\n",
700 periph->periph_name, periph->unit_number, softc->caps, res);
701 softc->state = PMP_STATE_PRECONFIG;
702 xpt_release_ccb(done_ccb);
703 xpt_schedule(periph, priority);
706 case PMP_STATE_PRECONFIG:
708 softc->state = PMP_STATE_RESET;
709 softc->reset |= ~softc->found;
710 xpt_release_ccb(done_ccb);
711 xpt_schedule(periph, priority);
713 case PMP_STATE_RESET:
715 if (softc->pm_step >= softc->pm_ports) {
717 cam_freeze_devq(periph->path);
718 cam_release_devq(periph->path,
719 RELSIM_RELEASE_AFTER_TIMEOUT,
723 softc->state = PMP_STATE_CONNECT;
725 xpt_release_ccb(done_ccb);
726 xpt_schedule(periph, priority);
728 case PMP_STATE_CONNECT:
730 if (softc->pm_step >= softc->pm_ports) {
733 cam_freeze_devq(periph->path);
734 cam_release_devq(periph->path,
735 RELSIM_RELEASE_AFTER_TIMEOUT,
739 softc->state = PMP_STATE_CHECK;
741 xpt_release_ccb(done_ccb);
742 xpt_schedule(periph, priority);
744 case PMP_STATE_CHECK:
745 res = (ataio->res.lba_high << 24) +
746 (ataio->res.lba_mid << 16) +
747 (ataio->res.lba_low << 8) +
748 ataio->res.sector_count;
749 if (((res & 0xf0f) == 0x103 && (res & 0x0f0) != 0) ||
750 (res & 0x600) != 0) {
752 printf("%s%d: port %d status: %08x\n",
753 periph->periph_name, periph->unit_number,
754 softc->pm_step, res);
756 /* Report device speed if it is online. */
757 if ((res & 0xf0f) == 0x103 &&
758 xpt_create_path(&dpath, periph,
759 xpt_path_path_id(periph->path),
760 softc->pm_step, 0) == CAM_REQ_CMP) {
761 bzero(&cts, sizeof(cts));
762 xpt_setup_ccb(&cts.ccb_h, dpath, CAM_PRIORITY_NONE);
763 cts.ccb_h.func_code = XPT_SET_TRAN_SETTINGS;
764 cts.type = CTS_TYPE_CURRENT_SETTINGS;
765 cts.xport_specific.sata.revision = (res & 0x0f0) >> 4;
766 cts.xport_specific.sata.valid = CTS_SATA_VALID_REVISION;
767 cts.xport_specific.sata.caps = softc->caps &
768 (CTS_SATA_CAPS_H_PMREQ |
769 CTS_SATA_CAPS_H_DMAAA |
771 cts.xport_specific.sata.valid |= CTS_SATA_VALID_CAPS;
772 xpt_action((union ccb *)&cts);
773 xpt_free_path(dpath);
775 softc->found |= (1 << softc->pm_step);
778 if (softc->pm_try < 10) {
779 cam_freeze_devq(periph->path);
780 cam_release_devq(periph->path,
781 RELSIM_RELEASE_AFTER_TIMEOUT,
788 printf("%s%d: port %d status: %08x\n",
789 periph->periph_name, periph->unit_number,
790 softc->pm_step, res);
792 softc->found &= ~(1 << softc->pm_step);
793 if (xpt_create_path(&dpath, periph,
794 done_ccb->ccb_h.path_id,
795 softc->pm_step, 0) == CAM_REQ_CMP) {
796 xpt_async(AC_LOST_DEVICE, dpath, NULL);
797 xpt_free_path(dpath);
802 if (softc->pm_step >= softc->pm_ports) {
803 if (softc->reset & softc->found) {
804 cam_freeze_devq(periph->path);
805 cam_release_devq(periph->path,
806 RELSIM_RELEASE_AFTER_TIMEOUT,
811 softc->state = PMP_STATE_CLEAR;
814 xpt_release_ccb(done_ccb);
815 xpt_schedule(periph, priority);
817 case PMP_STATE_CLEAR:
819 if (softc->pm_step >= softc->pm_ports) {
820 softc->state = PMP_STATE_CONFIG;
823 xpt_release_ccb(done_ccb);
824 xpt_schedule(periph, priority);
826 case PMP_STATE_CONFIG:
827 for (i = 0; i < softc->pm_ports; i++) {
830 if ((softc->found & (1 << i)) == 0)
832 if (xpt_create_path(&dpath, periph,
833 xpt_path_path_id(periph->path),
834 i, 0) != CAM_REQ_CMP) {
835 printf("pmpdone: xpt_create_path failed\n");
838 /* If we did hard reset to this device, inform XPT. */
839 if ((softc->reset & softc->found & (1 << i)) != 0)
840 xpt_async(AC_SENT_BDR, dpath, NULL);
841 /* If rescan requested, scan this device. */
842 if (softc->events & PMP_EV_RESCAN) {
843 ccb = xpt_alloc_ccb_nowait();
845 xpt_free_path(dpath);
848 xpt_setup_ccb(&ccb->ccb_h, dpath, CAM_PRIORITY_XPT);
851 xpt_free_path(dpath);
858 xpt_release_ccb(done_ccb);
859 softc->state = PMP_STATE_NORMAL;
862 pmprelease(periph, -1);
863 cam_periph_release_locked(periph);