2 * Copyright (c) 2000 Matthew Jacob
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. The name of the author may not be used to endorse or promote products
12 * derived from this software without specific prior written permission.
14 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR
18 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27 #include <sys/cdefs.h>
28 __FBSDID("$FreeBSD$");
30 #include <sys/param.h>
33 #include <sys/errno.h>
34 #include <sys/fcntl.h>
35 #include <sys/kernel.h>
36 #include <sys/kthread.h>
38 #include <sys/malloc.h>
39 #include <sys/mutex.h>
40 #include <sys/queue.h>
42 #include <sys/systm.h>
43 #include <sys/sysctl.h>
44 #include <sys/types.h>
46 #include <machine/stdarg.h>
49 #include <cam/cam_ccb.h>
50 #include <cam/cam_debug.h>
51 #include <cam/cam_periph.h>
52 #include <cam/cam_xpt_periph.h>
54 #include <cam/scsi/scsi_all.h>
55 #include <cam/scsi/scsi_message.h>
56 #include <cam/scsi/scsi_enc.h>
57 #include <cam/scsi/scsi_enc_internal.h>
59 MALLOC_DEFINE(M_SCSIENC, "SCSI ENC", "SCSI ENC buffers");
61 /* Enclosure type independent driver */
63 static d_open_t enc_open;
64 static d_close_t enc_close;
65 static d_ioctl_t enc_ioctl;
66 static periph_init_t enc_init;
67 static periph_ctor_t enc_ctor;
68 static periph_oninv_t enc_oninvalidate;
69 static periph_dtor_t enc_dtor;
70 static periph_start_t enc_start;
72 static void enc_async(void *, uint32_t, struct cam_path *, void *);
73 static enctyp enc_type(struct ccb_getdev *);
75 SYSCTL_NODE(_kern_cam, OID_AUTO, enc, CTLFLAG_RD, 0,
76 "CAM Enclosure Services driver");
78 static struct periph_driver encdriver = {
80 TAILQ_HEAD_INITIALIZER(encdriver.units), /* generation */ 0
83 PERIPHDRIVER_DECLARE(enc, encdriver);
85 static struct cdevsw enc_cdevsw = {
86 .d_version = D_VERSION,
91 .d_flags = D_TRACKCLOSE,
100 * Install a global async callback. This callback will
101 * receive async callbacks like "new device found".
103 status = xpt_register_async(AC_FOUND_DEVICE, enc_async, NULL, NULL);
105 if (status != CAM_REQ_CMP) {
106 printf("enc: Failed to attach master async callback "
107 "due to status 0x%x!\n", status);
112 enc_devgonecb(void *arg)
115 struct cam_periph *periph;
116 struct enc_softc *enc;
119 periph = (struct cam_periph *)arg;
121 enc = (struct enc_softc *)periph->softc;
126 * When we get this callback, we will get no more close calls from
127 * devfs. So if we have any dangling opens, we need to release the
128 * reference held for that particular context.
130 for (i = 0; i < enc->open_count; i++)
131 cam_periph_release_locked(periph);
136 * Release the reference held for the device node, it is gone now.
138 cam_periph_release_locked(periph);
141 * We reference the SIM lock directly here, instead of using
142 * cam_periph_unlock(). The reason is that the final call to
143 * cam_periph_release_locked() above could result in the periph
144 * getting freed. If that is the case, dereferencing the periph
145 * with a cam_periph_unlock() call would cause a page fault.
147 mtx_unlock(sim->mtx);
151 enc_oninvalidate(struct cam_periph *periph)
153 struct enc_softc *enc;
157 enc->enc_flags |= ENC_FLAG_INVALID;
159 /* If the sub-driver has an invalidate routine, call it */
160 if (enc->enc_vec.softc_invalidate != NULL)
161 enc->enc_vec.softc_invalidate(enc);
164 * Unregister any async callbacks.
166 xpt_register_async(0, enc_async, periph, periph->path);
169 * Shutdown our daemon.
171 enc->enc_flags |= ENC_FLAG_SHUTDOWN;
172 if (enc->enc_daemon != NULL) {
173 /* Signal the ses daemon to terminate. */
174 wakeup(enc->enc_daemon);
176 callout_drain(&enc->status_updater);
178 destroy_dev_sched_cb(enc->enc_dev, enc_devgonecb, periph);
180 xpt_print(periph->path, "lost device\n");
184 enc_dtor(struct cam_periph *periph)
186 struct enc_softc *enc;
190 xpt_print(periph->path, "removing device entry\n");
193 /* If the sub-driver has a cleanup routine, call it */
194 if (enc->enc_vec.softc_cleanup != NULL)
195 enc->enc_vec.softc_cleanup(enc);
197 if (enc->enc_boot_hold_ch.ich_func != NULL) {
198 config_intrhook_disestablish(&enc->enc_boot_hold_ch);
199 enc->enc_boot_hold_ch.ich_func = NULL;
206 enc_async(void *callback_arg, uint32_t code, struct cam_path *path, void *arg)
208 struct cam_periph *periph;
210 periph = (struct cam_periph *)callback_arg;
213 case AC_FOUND_DEVICE:
215 struct ccb_getdev *cgd;
219 cgd = (struct ccb_getdev *)arg;
224 if (enc_type(cgd) == ENC_NONE) {
226 * Schedule announcement of the ENC bindings for
227 * this device if it is managed by a SEP.
229 path_id = xpt_path_path_id(path);
231 TAILQ_FOREACH(periph, &encdriver.units, unit_links) {
232 struct enc_softc *softc;
234 softc = (struct enc_softc *)periph->softc;
235 if (xpt_path_path_id(periph->path) != path_id
237 || (softc->enc_flags & ENC_FLAG_INITIALIZED)
239 || softc->enc_vec.device_found == NULL)
242 softc->enc_vec.device_found(softc);
248 status = cam_periph_alloc(enc_ctor, enc_oninvalidate,
249 enc_dtor, enc_start, "ses", CAM_PERIPH_BIO,
250 cgd->ccb_h.path, enc_async, AC_FOUND_DEVICE, cgd);
252 if (status != CAM_REQ_CMP && status != CAM_REQ_INPROG) {
253 printf("enc_async: Unable to probe new device due to "
254 "status 0x%x\n", status);
259 cam_periph_async(periph, code, path, arg);
265 enc_open(struct cdev *dev, int flags, int fmt, struct thread *td)
267 struct cam_periph *periph;
268 struct enc_softc *softc;
271 periph = (struct cam_periph *)dev->si_drv1;
272 if (periph == NULL) {
276 if (cam_periph_acquire(periph) != CAM_REQ_CMP)
279 cam_periph_lock(periph);
281 softc = (struct enc_softc *)periph->softc;
283 if ((softc->enc_flags & ENC_FLAG_INITIALIZED) == 0) {
287 if (softc->enc_flags & ENC_FLAG_INVALID) {
293 cam_periph_release_locked(periph);
297 cam_periph_unlock(periph);
303 enc_close(struct cdev *dev, int flag, int fmt, struct thread *td)
306 struct cam_periph *periph;
307 struct enc_softc *enc;
309 periph = (struct cam_periph *)dev->si_drv1;
320 cam_periph_release_locked(periph);
323 * We reference the SIM lock directly here, instead of using
324 * cam_periph_unlock(). The reason is that the call to
325 * cam_periph_release_locked() above could result in the periph
326 * getting freed. If that is the case, dereferencing the periph
327 * with a cam_periph_unlock() call would cause a page fault.
329 * cam_periph_release() avoids this problem using the same method,
330 * but we're manually acquiring and dropping the lock here to
331 * protect the open count and avoid another lock acquisition and
334 mtx_unlock(sim->mtx);
340 enc_start(struct cam_periph *p, union ccb *sccb)
342 struct enc_softc *enc;
345 ENC_DLOG(enc, "%s enter imm=%d prio=%d\n",
346 __func__, p->immediate_priority, p->pinfo.priority);
347 if (p->immediate_priority <= p->pinfo.priority) {
348 SLIST_INSERT_HEAD(&p->ccb_list, &sccb->ccb_h, periph_links.sle);
349 p->immediate_priority = CAM_PRIORITY_NONE;
350 wakeup(&p->ccb_list);
352 xpt_release_ccb(sccb);
353 ENC_DLOG(enc, "%s exit\n", __func__);
357 enc_done(struct cam_periph *periph, union ccb *dccb)
359 wakeup(&dccb->ccb_h.cbfcnp);
363 enc_error(union ccb *ccb, uint32_t cflags, uint32_t sflags)
365 struct enc_softc *softc;
366 struct cam_periph *periph;
368 periph = xpt_path_periph(ccb->ccb_h.path);
369 softc = (struct enc_softc *)periph->softc;
371 return (cam_periph_error(ccb, cflags, sflags, &softc->saved_ccb));
375 enc_ioctl(struct cdev *dev, u_long cmd, caddr_t arg_addr, int flag,
378 struct cam_periph *periph;
379 encioc_enc_status_t tmp;
380 encioc_string_t sstr;
381 encioc_elm_status_t elms;
382 encioc_elm_desc_t elmd;
383 encioc_elm_devnames_t elmdn;
384 encioc_element_t *uelm;
392 addr = *((caddr_t *) arg_addr);
396 periph = (struct cam_periph *)dev->si_drv1;
400 CAM_DEBUG(periph->path, CAM_DEBUG_TRACE, ("entering encioctl\n"));
402 cam_periph_lock(periph);
403 enc = (struct enc_softc *)periph->softc;
404 cache = &enc->enc_cache;
407 * Now check to see whether we're initialized or not.
408 * This actually should never fail as we're not supposed
409 * to get past enc_open w/o successfully initializing
412 if ((enc->enc_flags & ENC_FLAG_INITIALIZED) == 0) {
413 cam_periph_unlock(periph);
416 cam_periph_unlock(periph);
420 CAM_DEBUG(periph->path, CAM_DEBUG_TRACE,
421 ("trying to do ioctl %#lx\n", cmd));
424 * If this command can change the device's state,
425 * we must have the device open for writing.
427 * For commands that get information about the
428 * device- we don't need to lock the peripheral
429 * if we aren't running a command. The periph
430 * also can't go away while a user process has
435 case ENCIOC_GETELMMAP:
436 case ENCIOC_GETENCSTAT:
437 case ENCIOC_GETELMSTAT:
438 case ENCIOC_GETELMDESC:
439 case ENCIOC_GETELMDEVNAMES:
442 if ((flag & FWRITE) == 0) {
448 * XXX The values read here are only valid for the current
449 * configuration generation. We need these ioctls
450 * to also pass in/out a generation number.
452 sx_slock(&enc->enc_cache_lock);
455 error = copyout(&cache->nelms, addr, sizeof (cache->nelms));
458 case ENCIOC_GETELMMAP:
459 for (uelm = addr, i = 0; i != cache->nelms; i++) {
460 encioc_element_t kelm;
462 kelm.elm_subenc_id = cache->elm_map[i].subenclosure;
463 kelm.elm_type = cache->elm_map[i].enctype;
464 error = copyout(&kelm, &uelm[i], sizeof(kelm));
470 case ENCIOC_GETENCSTAT:
471 cam_periph_lock(periph);
472 error = enc->enc_vec.get_enc_status(enc, 1);
474 cam_periph_unlock(periph);
477 tmp = cache->enc_status;
478 cam_periph_unlock(periph);
479 error = copyout(&tmp, addr, sizeof(tmp));
480 cache->enc_status = tmp;
483 case ENCIOC_SETENCSTAT:
484 error = copyin(addr, &tmp, sizeof(tmp));
487 cam_periph_lock(periph);
488 error = enc->enc_vec.set_enc_status(enc, tmp, 1);
489 cam_periph_unlock(periph);
492 case ENCIOC_GETSTRING:
493 case ENCIOC_SETSTRING:
494 if (enc->enc_vec.handle_string == NULL) {
498 error = copyin(addr, &sstr, sizeof(sstr));
501 cam_periph_lock(periph);
502 error = enc->enc_vec.handle_string(enc, &sstr, cmd);
503 cam_periph_unlock(periph);
506 case ENCIOC_GETELMSTAT:
507 error = copyin(addr, &elms, sizeof(elms));
510 if (elms.elm_idx >= cache->nelms) {
514 cam_periph_lock(periph);
515 error = enc->enc_vec.get_elm_status(enc, &elms, 1);
516 cam_periph_unlock(periph);
519 error = copyout(&elms, addr, sizeof(elms));
522 case ENCIOC_GETELMDESC:
523 error = copyin(addr, &elmd, sizeof(elmd));
526 if (elmd.elm_idx >= cache->nelms) {
530 if (enc->enc_vec.get_elm_desc != NULL) {
531 error = enc->enc_vec.get_elm_desc(enc, &elmd);
535 elmd.elm_desc_len = 0;
536 error = copyout(&elmd, addr, sizeof(elmd));
539 case ENCIOC_GETELMDEVNAMES:
540 if (enc->enc_vec.get_elm_devnames == NULL) {
544 error = copyin(addr, &elmdn, sizeof(elmdn));
547 if (elmdn.elm_idx >= cache->nelms) {
551 cam_periph_lock(periph);
552 error = (*enc->enc_vec.get_elm_devnames)(enc, &elmdn);
553 cam_periph_unlock(periph);
556 error = copyout(&elmdn, addr, sizeof(elmdn));
559 case ENCIOC_SETELMSTAT:
560 error = copyin(addr, &elms, sizeof(elms));
564 if (elms.elm_idx >= cache->nelms) {
568 cam_periph_lock(periph);
569 error = enc->enc_vec.set_elm_status(enc, &elms, 1);
570 cam_periph_unlock(periph);
576 cam_periph_lock(periph);
577 error = enc->enc_vec.init_enc(enc);
578 cam_periph_unlock(periph);
582 cam_periph_lock(periph);
583 error = cam_periph_ioctl(periph, cmd, arg_addr, enc_error);
584 cam_periph_unlock(periph);
587 sx_sunlock(&enc->enc_cache_lock);
592 enc_runcmd(struct enc_softc *enc, char *cdb, int cdbl, char *dptr, int *dlenp)
594 int error, dlen, tdlen;
598 CAM_DEBUG(enc->periph->path, CAM_DEBUG_TRACE,
599 ("entering enc_runcmd\n"));
601 if ((dlen = *dlenp) < 0) {
612 if (cdbl > IOCDBLEN) {
616 ccb = cam_periph_getccb(enc->periph, CAM_PRIORITY_NORMAL);
617 if (enc->enc_type == ENC_SEMB_SES || enc->enc_type == ENC_SEMB_SAFT) {
618 tdlen = min(dlen, 1020);
619 tdlen = (tdlen + 3) & ~3;
620 cam_fill_ataio(&ccb->ataio, 0, enc_done, ddf, 0, dptr, tdlen,
622 if (cdb[0] == RECEIVE_DIAGNOSTIC)
623 ata_28bit_cmd(&ccb->ataio,
624 ATA_SEP_ATTN, cdb[2], 0x02, tdlen / 4);
625 else if (cdb[0] == SEND_DIAGNOSTIC)
626 ata_28bit_cmd(&ccb->ataio,
627 ATA_SEP_ATTN, dlen > 0 ? dptr[0] : 0,
629 else if (cdb[0] == READ_BUFFER)
630 ata_28bit_cmd(&ccb->ataio,
631 ATA_SEP_ATTN, cdb[2], 0x00, tdlen / 4);
633 ata_28bit_cmd(&ccb->ataio,
634 ATA_SEP_ATTN, dlen > 0 ? dptr[0] : 0,
638 cam_fill_csio(&ccb->csio, 0, enc_done, ddf, MSG_SIMPLE_Q_TAG,
639 dptr, dlen, sizeof (struct scsi_sense_data), cdbl,
641 bcopy(cdb, ccb->csio.cdb_io.cdb_bytes, cdbl);
644 error = cam_periph_runccb(ccb, enc_error, ENC_CFLAGS, ENC_FLAGS, NULL);
651 if (ccb->ccb_h.func_code == XPT_ATA_IO)
652 *dlenp = ccb->ataio.resid;
654 *dlenp = ccb->csio.resid;
655 *dlenp += tdlen - dlen;
658 xpt_release_ccb(ccb);
659 CAM_DEBUG(enc->periph->path, CAM_DEBUG_SUBTRACE,
660 ("exiting enc_runcmd: *dlenp = %d\n", *dlenp));
665 enc_log(struct enc_softc *enc, const char *fmt, ...)
669 printf("%s%d: ", enc->periph->periph_name, enc->periph->unit_number);
676 * The code after this point runs on many platforms,
677 * so forgive the slightly awkward and nonconforming
682 * Is this a device that supports enclosure services?
684 * It's a a pretty simple ruleset- if it is device type
685 * 0x0D (13), it's an ENCLOSURE device.
688 #define SAFTE_START 44
690 #define SAFTE_LEN SAFTE_END-SAFTE_START
693 enc_type(struct ccb_getdev *cgd)
698 if (cgd->protocol == PROTO_SEMB) {
699 iqd = (unsigned char *)&cgd->ident_data;
700 if (STRNCMP(iqd + 43, "S-E-S", 5) == 0)
701 return (ENC_SEMB_SES);
702 else if (STRNCMP(iqd + 43, "SAF-TE", 6) == 0)
703 return (ENC_SEMB_SAFT);
706 } else if (cgd->protocol != PROTO_SCSI)
709 iqd = (unsigned char *)&cgd->inq_data;
710 buflen = min(sizeof(cgd->inq_data),
711 SID_ADDITIONAL_LENGTH(&cgd->inq_data));
713 if ((iqd[0] & 0x1f) == T_ENCLOSURE) {
714 if ((iqd[2] & 0x7) > 2) {
717 return (ENC_SES_SCSI2);
722 #ifdef ENC_ENABLE_PASSTHROUGH
723 if ((iqd[6] & 0x40) && (iqd[2] & 0x7) >= 2) {
725 * PassThrough Device.
727 return (ENC_ENC_PASSTHROUGH);
732 * The comparison is short for a reason-
733 * some vendors were chopping it short.
736 if (buflen < SAFTE_END - 2) {
740 if (STRNCMP((char *)&iqd[SAFTE_START], "SAF-TE", SAFTE_LEN - 2) == 0) {
746 /*================== Enclosure Monitoring/Processing Daemon ==================*/
748 * \brief Queue an update request for a given action, if needed.
750 * \param enc SES softc to queue the request for.
751 * \param action Action requested.
754 enc_update_request(enc_softc_t *enc, uint32_t action)
756 if ((enc->pending_actions & (0x1 << action)) == 0) {
757 enc->pending_actions |= (0x1 << action);
758 ENC_DLOG(enc, "%s: queing requested action %d\n",
760 if (enc->current_action == ENC_UPDATE_NONE)
761 wakeup(enc->enc_daemon);
763 ENC_DLOG(enc, "%s: ignoring requested action %d - "
764 "Already queued\n", __func__, action);
769 * \brief Invoke the handler of the highest priority pending
770 * state in the SES state machine.
772 * \param enc The SES instance invoking the state machine.
775 enc_fsm_step(enc_softc_t *enc)
779 struct enc_fsm_state *cur_state;
783 ENC_DLOG(enc, "%s enter %p\n", __func__, enc);
785 enc->current_action = ffs(enc->pending_actions) - 1;
786 enc->pending_actions &= ~(0x1 << enc->current_action);
788 cur_state = &enc->enc_fsm_states[enc->current_action];
791 if (cur_state->buf_size != 0) {
792 cam_periph_unlock(enc->periph);
793 buf = malloc(cur_state->buf_size, M_SCSIENC, M_WAITOK|M_ZERO);
794 cam_periph_lock(enc->periph);
799 if (cur_state->fill != NULL) {
800 ccb = cam_periph_getccb(enc->periph, CAM_PRIORITY_NORMAL);
802 error = cur_state->fill(enc, cur_state, ccb, buf);
806 error = cam_periph_runccb(ccb, cur_state->error,
808 ENC_FLAGS|SF_QUIET_IR, NULL);
812 if (ccb->ccb_h.func_code == XPT_ATA_IO)
813 xfer_len = ccb->ataio.dxfer_len - ccb->ataio.resid;
815 xfer_len = ccb->csio.dxfer_len - ccb->csio.resid;
819 cam_periph_unlock(enc->periph);
820 cur_state->done(enc, cur_state, ccb, &buf, error, xfer_len);
821 cam_periph_lock(enc->periph);
824 ENC_DLOG(enc, "%s exit - result %d\n", __func__, error);
825 ENC_FREE_AND_NULL(buf);
827 xpt_release_ccb(ccb);
831 * \invariant Called with cam_periph mutex held.
834 enc_status_updater(void *arg)
839 if (enc->enc_vec.poll_status != NULL)
840 enc->enc_vec.poll_status(enc);
844 enc_daemon(void *arg)
850 cam_periph_lock(enc->periph);
851 while ((enc->enc_flags & ENC_FLAG_SHUTDOWN) == 0) {
852 if (enc->pending_actions == 0) {
853 struct intr_config_hook *hook;
856 * Reset callout and msleep, or
857 * issue timed task completion
860 enc->current_action = ENC_UPDATE_NONE;
863 * We've been through our state machine at least
864 * once. Allow the transition to userland.
866 hook = &enc->enc_boot_hold_ch;
867 if (hook->ich_func != NULL) {
868 config_intrhook_disestablish(hook);
869 hook->ich_func = NULL;
872 callout_reset(&enc->status_updater, 60*hz,
873 enc_status_updater, enc);
875 cam_periph_sleep(enc->periph, enc->enc_daemon,
881 enc->enc_daemon = NULL;
882 cam_periph_unlock(enc->periph);
883 cam_periph_release(enc->periph);
888 enc_kproc_init(enc_softc_t *enc)
892 callout_init_mtx(&enc->status_updater, enc->periph->sim->mtx, 0);
894 if (cam_periph_acquire(enc->periph) != CAM_REQ_CMP)
897 result = kproc_create(enc_daemon, enc, &enc->enc_daemon, /*flags*/0,
898 /*stackpgs*/0, "enc_daemon%d",
899 enc->periph->unit_number);
901 /* Do an initial load of all page data. */
902 cam_periph_lock(enc->periph);
903 enc->enc_vec.poll_status(enc);
904 cam_periph_unlock(enc->periph);
906 cam_periph_release(enc->periph);
911 * \brief Interrupt configuration hook callback associated with
914 * Since interrupts are always functional at the time of enclosure
915 * configuration, there is nothing to be done when the callback occurs.
916 * This hook is only registered to hold up boot processing while initial
917 * eclosure processing occurs.
919 * \param arg The enclosure softc, but currently unused in this callback.
922 enc_nop_confighook_cb(void *arg __unused)
927 enc_ctor(struct cam_periph *periph, void *arg)
929 cam_status status = CAM_REQ_CMP_ERR;
932 struct ccb_getdev *cgd;
935 cgd = (struct ccb_getdev *)arg;
937 printf("enc_ctor: no getdev CCB, can't register device\n");
941 enc = ENC_MALLOCZ(sizeof(*enc));
943 printf("enc_ctor: Unable to probe new device. "
944 "Unable to allocate enc\n");
947 enc->periph = periph;
948 enc->current_action = ENC_UPDATE_INVALID;
950 enc->enc_type = enc_type(cgd);
951 sx_init(&enc->enc_cache_lock, "enccache");
953 switch (enc->enc_type) {
956 case ENC_SES_PASSTHROUGH:
958 err = ses_softc_init(enc);
962 err = safte_softc_init(enc);
967 return (CAM_REQ_CMP_ERR);
971 xpt_print(periph->path, "error %d initializing\n", err);
976 * Hold off userland until we have made at least one pass
977 * through our state machine so that physical path data is
980 if (enc->enc_vec.poll_status != NULL) {
981 enc->enc_boot_hold_ch.ich_func = enc_nop_confighook_cb;
982 enc->enc_boot_hold_ch.ich_arg = enc;
983 config_intrhook_establish(&enc->enc_boot_hold_ch);
987 * The softc field is set only once the enc is fully initialized
988 * so that we can rely on this field to detect partially
989 * initialized periph objects in the AC_FOUND_DEVICE handler.
993 cam_periph_unlock(periph);
994 if (enc->enc_vec.poll_status != NULL) {
995 err = enc_kproc_init(enc);
997 xpt_print(periph->path,
998 "error %d starting enc_daemon\n", err);
1004 * Acquire a reference to the periph before we create the devfs
1005 * instance for it. We'll release this reference once the devfs
1006 * instance has been freed.
1008 if (cam_periph_acquire(periph) != CAM_REQ_CMP) {
1009 xpt_print(periph->path, "%s: lost periph during "
1010 "registration!\n", __func__);
1011 cam_periph_lock(periph);
1013 return (CAM_REQ_CMP_ERR);
1016 enc->enc_dev = make_dev(&enc_cdevsw, periph->unit_number,
1017 UID_ROOT, GID_OPERATOR, 0600, "%s%d",
1018 periph->periph_name, periph->unit_number);
1020 cam_periph_lock(periph);
1021 enc->enc_dev->si_drv1 = periph;
1023 enc->enc_flags |= ENC_FLAG_INITIALIZED;
1026 * Add an async callback so that we get notified if this
1029 xpt_register_async(AC_LOST_DEVICE, enc_async, periph, periph->path);
1031 switch (enc->enc_type) {
1034 tname = "No ENC device";
1037 tname = "SCSI-2 ENC Device";
1040 tname = "SCSI-3 ENC Device";
1042 case ENC_SES_PASSTHROUGH:
1043 tname = "ENC Passthrough Device";
1046 tname = "SAF-TE Compliant Device";
1049 tname = "SEMB SES Device";
1052 tname = "SEMB SAF-TE Device";
1055 xpt_announce_periph(periph, tname);
1056 status = CAM_REQ_CMP;
1059 if (status != CAM_REQ_CMP)