2 * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
4 * Copyright (c) 2000 Matthew Jacob
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions, and the following disclaimer,
12 * without modification, immediately at the beginning of the file.
13 * 2. The name of the author may not be used to endorse or promote products
14 * derived from this software without specific prior written permission.
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
17 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR
20 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29 #include <sys/cdefs.h>
30 __FBSDID("$FreeBSD$");
32 #include <sys/param.h>
35 #include <sys/errno.h>
36 #include <sys/fcntl.h>
37 #include <sys/kernel.h>
38 #include <sys/kthread.h>
40 #include <sys/malloc.h>
41 #include <sys/mutex.h>
43 #include <sys/queue.h>
46 #include <sys/sysent.h>
47 #include <sys/systm.h>
48 #include <sys/sysctl.h>
49 #include <sys/types.h>
51 #include <machine/stdarg.h>
54 #include <cam/cam_ccb.h>
55 #include <cam/cam_debug.h>
56 #include <cam/cam_periph.h>
57 #include <cam/cam_xpt_periph.h>
59 #include <cam/scsi/scsi_all.h>
60 #include <cam/scsi/scsi_message.h>
61 #include <cam/scsi/scsi_enc.h>
62 #include <cam/scsi/scsi_enc_internal.h>
66 MALLOC_DEFINE(M_SCSIENC, "SCSI ENC", "SCSI ENC buffers");
68 /* Enclosure type independent driver */
70 static d_open_t enc_open;
71 static d_close_t enc_close;
72 static d_ioctl_t enc_ioctl;
73 static periph_init_t enc_init;
74 static periph_ctor_t enc_ctor;
75 static periph_oninv_t enc_oninvalidate;
76 static periph_dtor_t enc_dtor;
78 static void enc_async(void *, uint32_t, struct cam_path *, void *);
79 static enctyp enc_type(struct ccb_getdev *);
81 SYSCTL_NODE(_kern_cam, OID_AUTO, enc, CTLFLAG_RD | CTLFLAG_MPSAFE, 0,
82 "CAM Enclosure Services driver");
84 #if defined(DEBUG) || defined(ENC_DEBUG)
89 SYSCTL_INT(_kern_cam_enc, OID_AUTO, verbose, CTLFLAG_RWTUN,
90 &enc_verbose, 0, "Enable verbose logging");
92 const char *elm_type_names[] = ELM_TYPE_NAMES;
93 CTASSERT(nitems(elm_type_names) - 1 == ELMTYP_LAST);
95 static struct periph_driver encdriver = {
97 TAILQ_HEAD_INITIALIZER(encdriver.units), /* generation */ 0
100 PERIPHDRIVER_DECLARE(enc, encdriver);
102 static struct cdevsw enc_cdevsw = {
103 .d_version = D_VERSION,
105 .d_close = enc_close,
106 .d_ioctl = enc_ioctl,
108 .d_flags = D_TRACKCLOSE,
117 * Install a global async callback. This callback will
118 * receive async callbacks like "new device found".
120 status = xpt_register_async(AC_FOUND_DEVICE, enc_async, NULL, NULL);
122 if (status != CAM_REQ_CMP) {
123 printf("enc: Failed to attach master async callback "
124 "due to status 0x%x!\n", status);
129 enc_devgonecb(void *arg)
131 struct cam_periph *periph;
132 struct enc_softc *enc;
136 periph = (struct cam_periph *)arg;
137 mtx = cam_periph_mtx(periph);
139 enc = (struct enc_softc *)periph->softc;
142 * When we get this callback, we will get no more close calls from
143 * devfs. So if we have any dangling opens, we need to release the
144 * reference held for that particular context.
146 for (i = 0; i < enc->open_count; i++)
147 cam_periph_release_locked(periph);
152 * Release the reference held for the device node, it is gone now.
154 cam_periph_release_locked(periph);
157 * We reference the lock directly here, instead of using
158 * cam_periph_unlock(). The reason is that the final call to
159 * cam_periph_release_locked() above could result in the periph
160 * getting freed. If that is the case, dereferencing the periph
161 * with a cam_periph_unlock() call would cause a page fault.
167 enc_oninvalidate(struct cam_periph *periph)
169 struct enc_softc *enc;
173 enc->enc_flags |= ENC_FLAG_INVALID;
175 /* If the sub-driver has an invalidate routine, call it */
176 if (enc->enc_vec.softc_invalidate != NULL)
177 enc->enc_vec.softc_invalidate(enc);
180 * Unregister any async callbacks.
182 xpt_register_async(0, enc_async, periph, periph->path);
185 * Shutdown our daemon.
187 enc->enc_flags |= ENC_FLAG_SHUTDOWN;
188 if (enc->enc_daemon != NULL) {
189 /* Signal the ses daemon to terminate. */
190 wakeup(enc->enc_daemon);
192 callout_drain(&enc->status_updater);
194 destroy_dev_sched_cb(enc->enc_dev, enc_devgonecb, periph);
198 enc_dtor(struct cam_periph *periph)
200 struct enc_softc *enc;
204 /* If the sub-driver has a cleanup routine, call it */
205 if (enc->enc_vec.softc_cleanup != NULL)
206 enc->enc_vec.softc_cleanup(enc);
208 root_mount_rel(&enc->enc_rootmount);
214 enc_async(void *callback_arg, uint32_t code, struct cam_path *path, void *arg)
216 struct cam_periph *periph;
218 periph = (struct cam_periph *)callback_arg;
221 case AC_FOUND_DEVICE:
223 struct ccb_getdev *cgd;
227 cgd = (struct ccb_getdev *)arg;
232 if (enc_type(cgd) == ENC_NONE) {
234 * Schedule announcement of the ENC bindings for
235 * this device if it is managed by a SEP.
237 path_id = xpt_path_path_id(path);
239 TAILQ_FOREACH(periph, &encdriver.units, unit_links) {
240 struct enc_softc *softc;
242 softc = (struct enc_softc *)periph->softc;
244 /* Check this SEP is ready. */
245 if (softc == NULL || (softc->enc_flags &
246 ENC_FLAG_INITIALIZED) == 0 ||
247 softc->enc_vec.device_found == NULL)
250 /* Check this SEP may manage this device. */
251 if (xpt_path_path_id(periph->path) != path_id &&
252 (softc->enc_type != ENC_SEMB_SES ||
253 cgd->protocol != PROTO_ATA))
256 softc->enc_vec.device_found(softc);
262 status = cam_periph_alloc(enc_ctor, enc_oninvalidate,
263 enc_dtor, NULL, "ses", CAM_PERIPH_BIO,
264 path, enc_async, AC_FOUND_DEVICE, cgd);
266 if (status != CAM_REQ_CMP && status != CAM_REQ_INPROG) {
267 printf("enc_async: Unable to probe new device due to "
268 "status 0x%x\n", status);
273 cam_periph_async(periph, code, path, arg);
279 enc_open(struct cdev *dev, int flags, int fmt, struct thread *td)
281 struct cam_periph *periph;
282 struct enc_softc *softc;
285 periph = (struct cam_periph *)dev->si_drv1;
286 if (cam_periph_acquire(periph) != 0)
289 cam_periph_lock(periph);
291 softc = (struct enc_softc *)periph->softc;
293 if ((softc->enc_flags & ENC_FLAG_INITIALIZED) == 0) {
297 if (softc->enc_flags & ENC_FLAG_INVALID) {
303 cam_periph_release_locked(periph);
307 cam_periph_unlock(periph);
313 enc_close(struct cdev *dev, int flag, int fmt, struct thread *td)
315 struct cam_periph *periph;
316 struct enc_softc *enc;
319 periph = (struct cam_periph *)dev->si_drv1;
320 mtx = cam_periph_mtx(periph);
326 cam_periph_release_locked(periph);
329 * We reference the lock directly here, instead of using
330 * cam_periph_unlock(). The reason is that the call to
331 * cam_periph_release_locked() above could result in the periph
332 * getting freed. If that is the case, dereferencing the periph
333 * with a cam_periph_unlock() call would cause a page fault.
335 * cam_periph_release() avoids this problem using the same method,
336 * but we're manually acquiring and dropping the lock here to
337 * protect the open count and avoid another lock acquisition and
346 enc_error(union ccb *ccb, uint32_t cflags, uint32_t sflags)
349 return (cam_periph_error(ccb, cflags, sflags));
353 enc_ioctl(struct cdev *dev, u_long cmd, caddr_t arg_addr, int flag,
356 struct cam_periph *periph;
357 encioc_enc_status_t tmp;
358 encioc_string_t sstr;
359 encioc_elm_status_t elms;
360 encioc_elm_desc_t elmd;
361 encioc_elm_devnames_t elmdn;
362 encioc_element_t *uelm;
368 #ifdef COMPAT_FREEBSD32
369 if (SV_PROC_FLAG(td->td_proc, SV_ILP32))
374 addr = *((caddr_t *) arg_addr);
378 periph = (struct cam_periph *)dev->si_drv1;
379 CAM_DEBUG(periph->path, CAM_DEBUG_TRACE, ("entering encioctl\n"));
381 cam_periph_lock(periph);
382 enc = (struct enc_softc *)periph->softc;
383 cache = &enc->enc_cache;
386 * Now check to see whether we're initialized or not.
387 * This actually should never fail as we're not supposed
388 * to get past enc_open w/o successfully initializing
391 if ((enc->enc_flags & ENC_FLAG_INITIALIZED) == 0) {
392 cam_periph_unlock(periph);
395 cam_periph_unlock(periph);
399 CAM_DEBUG(periph->path, CAM_DEBUG_TRACE,
400 ("trying to do ioctl %#lx\n", cmd));
403 * If this command can change the device's state,
404 * we must have the device open for writing.
406 * For commands that get information about the
407 * device- we don't need to lock the peripheral
408 * if we aren't running a command. The periph
409 * also can't go away while a user process has
414 case ENCIOC_GETELMMAP:
415 case ENCIOC_GETENCSTAT:
416 case ENCIOC_GETELMSTAT:
417 case ENCIOC_GETELMDESC:
418 case ENCIOC_GETELMDEVNAMES:
419 case ENCIOC_GETENCNAME:
420 case ENCIOC_GETENCID:
423 if ((flag & FWRITE) == 0) {
429 * XXX The values read here are only valid for the current
430 * configuration generation. We need these ioctls
431 * to also pass in/out a generation number.
433 sx_slock(&enc->enc_cache_lock);
436 error = copyout(&cache->nelms, addr, sizeof (cache->nelms));
439 case ENCIOC_GETELMMAP:
440 for (uelm = addr, i = 0; i != cache->nelms; i++) {
441 encioc_element_t kelm;
443 kelm.elm_subenc_id = cache->elm_map[i].subenclosure;
444 kelm.elm_type = cache->elm_map[i].elm_type;
445 error = copyout(&kelm, &uelm[i], sizeof(kelm));
451 case ENCIOC_GETENCSTAT:
452 cam_periph_lock(periph);
453 error = enc->enc_vec.get_enc_status(enc, 1);
455 cam_periph_unlock(periph);
458 tmp = cache->enc_status;
459 cam_periph_unlock(periph);
460 error = copyout(&tmp, addr, sizeof(tmp));
461 cache->enc_status = tmp;
464 case ENCIOC_SETENCSTAT:
465 error = copyin(addr, &tmp, sizeof(tmp));
468 cam_periph_lock(periph);
469 error = enc->enc_vec.set_enc_status(enc, tmp, 1);
470 cam_periph_unlock(periph);
473 case ENCIOC_GETSTRING:
474 case ENCIOC_SETSTRING:
475 case ENCIOC_GETENCNAME:
476 case ENCIOC_GETENCID:
477 if (enc->enc_vec.handle_string == NULL) {
481 error = copyin(addr, &sstr, sizeof(sstr));
484 cam_periph_lock(periph);
485 error = enc->enc_vec.handle_string(enc, &sstr, cmd);
486 cam_periph_unlock(periph);
487 if (error == 0 || error == ENOMEM)
488 (void)copyout(&sstr.bufsiz,
489 &((encioc_string_t *)addr)->bufsiz,
490 sizeof(sstr.bufsiz));
493 case ENCIOC_GETELMSTAT:
494 error = copyin(addr, &elms, sizeof(elms));
497 if (elms.elm_idx >= cache->nelms) {
501 cam_periph_lock(periph);
502 error = enc->enc_vec.get_elm_status(enc, &elms, 1);
503 cam_periph_unlock(periph);
506 error = copyout(&elms, addr, sizeof(elms));
509 case ENCIOC_GETELMDESC:
510 error = copyin(addr, &elmd, sizeof(elmd));
513 if (elmd.elm_idx >= cache->nelms) {
517 if (enc->enc_vec.get_elm_desc != NULL) {
518 error = enc->enc_vec.get_elm_desc(enc, &elmd);
522 elmd.elm_desc_len = 0;
523 error = copyout(&elmd, addr, sizeof(elmd));
526 case ENCIOC_GETELMDEVNAMES:
527 if (enc->enc_vec.get_elm_devnames == NULL) {
531 error = copyin(addr, &elmdn, sizeof(elmdn));
534 if (elmdn.elm_idx >= cache->nelms) {
538 cam_periph_lock(periph);
539 error = (*enc->enc_vec.get_elm_devnames)(enc, &elmdn);
540 cam_periph_unlock(periph);
543 error = copyout(&elmdn, addr, sizeof(elmdn));
546 case ENCIOC_SETELMSTAT:
547 error = copyin(addr, &elms, sizeof(elms));
551 if (elms.elm_idx >= cache->nelms) {
555 cam_periph_lock(periph);
556 error = enc->enc_vec.set_elm_status(enc, &elms, 1);
557 cam_periph_unlock(periph);
563 cam_periph_lock(periph);
564 error = enc->enc_vec.init_enc(enc);
565 cam_periph_unlock(periph);
569 cam_periph_lock(periph);
570 error = cam_periph_ioctl(periph, cmd, arg_addr, enc_error);
571 cam_periph_unlock(periph);
574 sx_sunlock(&enc->enc_cache_lock);
579 enc_runcmd(struct enc_softc *enc, char *cdb, int cdbl, char *dptr, int *dlenp)
581 int error, dlen, tdlen;
585 CAM_DEBUG(enc->periph->path, CAM_DEBUG_TRACE,
586 ("entering enc_runcmd\n"));
588 if ((dlen = *dlenp) < 0) {
599 if (cdbl > IOCDBLEN) {
603 ccb = cam_periph_getccb(enc->periph, CAM_PRIORITY_NORMAL);
604 if (enc->enc_type == ENC_SEMB_SES || enc->enc_type == ENC_SEMB_SAFT) {
605 tdlen = min(dlen, 1020);
606 tdlen = (tdlen + 3) & ~3;
607 cam_fill_ataio(&ccb->ataio, 0, NULL, ddf, 0, dptr, tdlen,
609 if (cdb[0] == RECEIVE_DIAGNOSTIC)
610 ata_28bit_cmd(&ccb->ataio,
611 ATA_SEP_ATTN, cdb[2], 0x02, tdlen / 4);
612 else if (cdb[0] == SEND_DIAGNOSTIC)
613 ata_28bit_cmd(&ccb->ataio,
614 ATA_SEP_ATTN, dlen > 0 ? dptr[0] : 0,
616 else if (cdb[0] == READ_BUFFER)
617 ata_28bit_cmd(&ccb->ataio,
618 ATA_SEP_ATTN, cdb[2], 0x00, tdlen / 4);
620 ata_28bit_cmd(&ccb->ataio,
621 ATA_SEP_ATTN, dlen > 0 ? dptr[0] : 0,
625 cam_fill_csio(&ccb->csio, 0, NULL, ddf, MSG_SIMPLE_Q_TAG,
626 dptr, dlen, sizeof (struct scsi_sense_data), cdbl,
628 bcopy(cdb, ccb->csio.cdb_io.cdb_bytes, cdbl);
631 error = cam_periph_runccb(ccb, enc_error, ENC_CFLAGS, ENC_FLAGS, NULL);
638 if (ccb->ccb_h.func_code == XPT_ATA_IO)
639 *dlenp = ccb->ataio.resid;
641 *dlenp = ccb->csio.resid;
642 *dlenp += tdlen - dlen;
645 xpt_release_ccb(ccb);
646 CAM_DEBUG(enc->periph->path, CAM_DEBUG_SUBTRACE,
647 ("exiting enc_runcmd: *dlenp = %d\n", *dlenp));
652 enc_log(struct enc_softc *enc, const char *fmt, ...)
656 printf("%s%d: ", enc->periph->periph_name, enc->periph->unit_number);
663 * The code after this point runs on many platforms,
664 * so forgive the slightly awkward and nonconforming
669 * Is this a device that supports enclosure services?
671 * It's a pretty simple ruleset- if it is device type
672 * 0x0D (13), it's an ENCLOSURE device.
675 #define SAFTE_START 44
677 #define SAFTE_LEN SAFTE_END-SAFTE_START
680 enc_type(struct ccb_getdev *cgd)
685 if (cgd->protocol == PROTO_SEMB) {
686 iqd = (unsigned char *)&cgd->ident_data;
687 if (STRNCMP(iqd + 43, "S-E-S", 5) == 0)
688 return (ENC_SEMB_SES);
689 else if (STRNCMP(iqd + 43, "SAF-TE", 6) == 0)
690 return (ENC_SEMB_SAFT);
693 } else if (cgd->protocol != PROTO_SCSI)
696 iqd = (unsigned char *)&cgd->inq_data;
697 buflen = min(sizeof(cgd->inq_data),
698 SID_ADDITIONAL_LENGTH(&cgd->inq_data));
700 if ((iqd[0] & 0x1f) == T_ENCLOSURE)
703 #ifdef SES_ENABLE_PASSTHROUGH
704 if ((iqd[6] & 0x40) && (iqd[2] & 0x7) >= 2) {
706 * PassThrough Device.
708 return (ENC_SES_PASSTHROUGH);
713 * The comparison is short for a reason-
714 * some vendors were chopping it short.
717 if (buflen < SAFTE_END - 2) {
721 if (STRNCMP((char *)&iqd[SAFTE_START], "SAF-TE", SAFTE_LEN - 2) == 0) {
727 /*================== Enclosure Monitoring/Processing Daemon ==================*/
729 * \brief Queue an update request for a given action, if needed.
731 * \param enc SES softc to queue the request for.
732 * \param action Action requested.
735 enc_update_request(enc_softc_t *enc, uint32_t action)
737 if ((enc->pending_actions & (0x1 << action)) == 0) {
738 enc->pending_actions |= (0x1 << action);
739 ENC_DLOG(enc, "%s: queing requested action %d\n",
741 if (enc->current_action == ENC_UPDATE_NONE)
742 wakeup(enc->enc_daemon);
744 ENC_DLOG(enc, "%s: ignoring requested action %d - "
745 "Already queued\n", __func__, action);
750 * \brief Invoke the handler of the highest priority pending
751 * state in the SES state machine.
753 * \param enc The SES instance invoking the state machine.
756 enc_fsm_step(enc_softc_t *enc)
760 struct enc_fsm_state *cur_state;
764 ENC_DLOG(enc, "%s enter %p\n", __func__, enc);
766 enc->current_action = ffs(enc->pending_actions) - 1;
767 enc->pending_actions &= ~(0x1 << enc->current_action);
769 cur_state = &enc->enc_fsm_states[enc->current_action];
772 if (cur_state->buf_size != 0) {
773 cam_periph_unlock(enc->periph);
774 buf = malloc(cur_state->buf_size, M_SCSIENC, M_WAITOK|M_ZERO);
775 cam_periph_lock(enc->periph);
780 if (cur_state->fill != NULL) {
781 ccb = cam_periph_getccb(enc->periph, CAM_PRIORITY_NORMAL);
783 error = cur_state->fill(enc, cur_state, ccb, buf);
787 error = cam_periph_runccb(ccb, cur_state->error,
789 ENC_FLAGS|SF_QUIET_IR, NULL);
793 if (ccb->ccb_h.func_code == XPT_ATA_IO)
794 xfer_len = ccb->ataio.dxfer_len - ccb->ataio.resid;
796 xfer_len = ccb->csio.dxfer_len - ccb->csio.resid;
800 cam_periph_unlock(enc->periph);
801 cur_state->done(enc, cur_state, ccb, &buf, error, xfer_len);
802 cam_periph_lock(enc->periph);
805 ENC_DLOG(enc, "%s exit - result %d\n", __func__, error);
806 ENC_FREE_AND_NULL(buf);
808 xpt_release_ccb(ccb);
812 * \invariant Called with cam_periph mutex held.
815 enc_status_updater(void *arg)
820 if (enc->enc_vec.poll_status != NULL)
821 enc->enc_vec.poll_status(enc);
825 enc_daemon(void *arg)
831 cam_periph_lock(enc->periph);
832 while ((enc->enc_flags & ENC_FLAG_SHUTDOWN) == 0) {
833 if (enc->pending_actions == 0) {
835 * Reset callout and msleep, or
836 * issue timed task completion
839 enc->current_action = ENC_UPDATE_NONE;
842 * We've been through our state machine at least
843 * once. Allow the transition to userland.
845 root_mount_rel(&enc->enc_rootmount);
847 callout_reset(&enc->status_updater, 60*hz,
848 enc_status_updater, enc);
850 cam_periph_sleep(enc->periph, enc->enc_daemon,
856 enc->enc_daemon = NULL;
857 cam_periph_unlock(enc->periph);
858 cam_periph_release(enc->periph);
863 enc_kproc_init(enc_softc_t *enc)
867 callout_init_mtx(&enc->status_updater, cam_periph_mtx(enc->periph), 0);
869 if (cam_periph_acquire(enc->periph) != 0)
872 result = kproc_create(enc_daemon, enc, &enc->enc_daemon, /*flags*/0,
873 /*stackpgs*/0, "enc_daemon%d",
874 enc->periph->unit_number);
876 /* Do an initial load of all page data. */
877 cam_periph_lock(enc->periph);
878 enc->enc_vec.poll_status(enc);
879 cam_periph_unlock(enc->periph);
881 cam_periph_release(enc->periph);
886 enc_ctor(struct cam_periph *periph, void *arg)
888 cam_status status = CAM_REQ_CMP_ERR;
891 struct ccb_getdev *cgd;
893 struct make_dev_args args;
896 cgd = (struct ccb_getdev *)arg;
898 printf("enc_ctor: no getdev CCB, can't register device\n");
902 enc = ENC_MALLOCZ(sizeof(*enc));
904 printf("enc_ctor: Unable to probe new device. "
905 "Unable to allocate enc\n");
908 enc->periph = periph;
909 enc->current_action = ENC_UPDATE_INVALID;
911 enc->enc_type = enc_type(cgd);
912 sx_init(&enc->enc_cache_lock, "enccache");
914 switch (enc->enc_type) {
916 case ENC_SES_PASSTHROUGH:
918 err = ses_softc_init(enc);
922 err = safte_softc_init(enc);
927 return (CAM_REQ_CMP_ERR);
931 xpt_print(periph->path, "error %d initializing\n", err);
936 * Hold off userland until we have made at least one pass
937 * through our state machine so that physical path data is
940 if (enc->enc_vec.poll_status != NULL) {
941 root_mount_hold_token(periph->periph_name, &enc->enc_rootmount);
945 * The softc field is set only once the enc is fully initialized
946 * so that we can rely on this field to detect partially
947 * initialized periph objects in the AC_FOUND_DEVICE handler.
951 cam_periph_unlock(periph);
952 if (enc->enc_vec.poll_status != NULL) {
953 err = enc_kproc_init(enc);
955 xpt_print(periph->path,
956 "error %d starting enc_daemon\n", err);
962 * Acquire a reference to the periph before we create the devfs
963 * instance for it. We'll release this reference once the devfs
964 * instance has been freed.
966 if (cam_periph_acquire(periph) != 0) {
967 xpt_print(periph->path, "%s: lost periph during "
968 "registration!\n", __func__);
969 cam_periph_lock(periph);
971 return (CAM_REQ_CMP_ERR);
974 make_dev_args_init(&args);
975 args.mda_devsw = &enc_cdevsw;
976 args.mda_unit = periph->unit_number;
977 args.mda_uid = UID_ROOT;
978 args.mda_gid = GID_OPERATOR;
979 args.mda_mode = 0600;
980 args.mda_si_drv1 = periph;
981 err = make_dev_s(&args, &enc->enc_dev, "%s%d", periph->periph_name,
982 periph->unit_number);
983 cam_periph_lock(periph);
985 cam_periph_release_locked(periph);
986 return (CAM_REQ_CMP_ERR);
989 enc->enc_flags |= ENC_FLAG_INITIALIZED;
992 * Add an async callback so that we get notified if this
995 xpt_register_async(AC_LOST_DEVICE, enc_async, periph, periph->path);
997 switch (enc->enc_type) {
1000 tname = "No ENC device";
1003 tname = "SES Device";
1005 case ENC_SES_PASSTHROUGH:
1006 tname = "SES Passthrough Device";
1009 tname = "SAF-TE Device";
1012 tname = "SEMB SES Device";
1015 tname = "SEMB SAF-TE Device";
1019 sbuf_new(&sb, enc->announce_buf, ENC_ANNOUNCE_SZ, SBUF_FIXEDLEN);
1020 xpt_announce_periph_sbuf(periph, &sb, tname);
1024 status = CAM_REQ_CMP;
1027 if (status != CAM_REQ_CMP)