2 * SPDX-License-Identifier: BSD-2-Clause
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 #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>
41 #include <sys/queue.h>
44 #include <sys/sysent.h>
45 #include <sys/systm.h>
46 #include <sys/sysctl.h>
47 #include <sys/types.h>
49 #include <machine/stdarg.h>
52 #include <cam/cam_ccb.h>
53 #include <cam/cam_debug.h>
54 #include <cam/cam_periph.h>
55 #include <cam/cam_xpt_periph.h>
57 #include <cam/scsi/scsi_all.h>
58 #include <cam/scsi/scsi_message.h>
59 #include <cam/scsi/scsi_enc.h>
60 #include <cam/scsi/scsi_enc_internal.h>
64 MALLOC_DEFINE(M_SCSIENC, "SCSI ENC", "SCSI ENC buffers");
66 /* Enclosure type independent driver */
68 static d_open_t enc_open;
69 static d_close_t enc_close;
70 static d_ioctl_t enc_ioctl;
71 static periph_init_t enc_init;
72 static periph_ctor_t enc_ctor;
73 static periph_oninv_t enc_oninvalidate;
74 static periph_dtor_t enc_dtor;
76 static void enc_async(void *, uint32_t, struct cam_path *, void *);
77 static enctyp enc_type(struct ccb_getdev *);
79 SYSCTL_NODE(_kern_cam, OID_AUTO, enc, CTLFLAG_RD | CTLFLAG_MPSAFE, 0,
80 "CAM Enclosure Services driver");
82 #if defined(DEBUG) || defined(ENC_DEBUG)
87 SYSCTL_INT(_kern_cam_enc, OID_AUTO, verbose, CTLFLAG_RWTUN,
88 &enc_verbose, 0, "Enable verbose logging");
90 const char *elm_type_names[] = ELM_TYPE_NAMES;
91 CTASSERT(nitems(elm_type_names) - 1 == ELMTYP_LAST);
93 static struct periph_driver encdriver = {
95 TAILQ_HEAD_INITIALIZER(encdriver.units), /* generation */ 0
98 PERIPHDRIVER_DECLARE(enc, encdriver);
100 static struct cdevsw enc_cdevsw = {
101 .d_version = D_VERSION,
103 .d_close = enc_close,
104 .d_ioctl = enc_ioctl,
106 .d_flags = D_TRACKCLOSE,
115 * Install a global async callback. This callback will
116 * receive async callbacks like "new device found".
118 status = xpt_register_async(AC_FOUND_DEVICE, enc_async, NULL, NULL);
120 if (status != CAM_REQ_CMP) {
121 printf("enc: Failed to attach master async callback "
122 "due to status 0x%x!\n", status);
127 enc_devgonecb(void *arg)
129 struct cam_periph *periph;
130 struct enc_softc *enc;
134 periph = (struct cam_periph *)arg;
135 mtx = cam_periph_mtx(periph);
137 enc = (struct enc_softc *)periph->softc;
140 * When we get this callback, we will get no more close calls from
141 * devfs. So if we have any dangling opens, we need to release the
142 * reference held for that particular context.
144 for (i = 0; i < enc->open_count; i++)
145 cam_periph_release_locked(periph);
150 * Release the reference held for the device node, it is gone now.
152 cam_periph_release_locked(periph);
155 * We reference the lock directly here, instead of using
156 * cam_periph_unlock(). The reason is that the final call to
157 * cam_periph_release_locked() above could result in the periph
158 * getting freed. If that is the case, dereferencing the periph
159 * with a cam_periph_unlock() call would cause a page fault.
165 enc_oninvalidate(struct cam_periph *periph)
167 struct enc_softc *enc;
171 enc->enc_flags |= ENC_FLAG_INVALID;
173 /* If the sub-driver has an invalidate routine, call it */
174 if (enc->enc_vec.softc_invalidate != NULL)
175 enc->enc_vec.softc_invalidate(enc);
178 * Unregister any async callbacks.
180 xpt_register_async(0, enc_async, periph, periph->path);
183 * Shutdown our daemon.
185 enc->enc_flags |= ENC_FLAG_SHUTDOWN;
186 if (enc->enc_daemon != NULL) {
187 /* Signal the ses daemon to terminate. */
188 wakeup(enc->enc_daemon);
190 callout_drain(&enc->status_updater);
192 destroy_dev_sched_cb(enc->enc_dev, enc_devgonecb, periph);
196 enc_dtor(struct cam_periph *periph)
198 struct enc_softc *enc;
202 /* If the sub-driver has a cleanup routine, call it */
203 if (enc->enc_vec.softc_cleanup != NULL)
204 enc->enc_vec.softc_cleanup(enc);
206 cam_periph_release_boot(periph);
212 enc_async(void *callback_arg, uint32_t code, struct cam_path *path, void *arg)
214 struct cam_periph *periph;
216 periph = (struct cam_periph *)callback_arg;
219 case AC_FOUND_DEVICE:
221 struct ccb_getdev *cgd;
225 cgd = (struct ccb_getdev *)arg;
230 if (enc_type(cgd) == ENC_NONE) {
232 * Schedule announcement of the ENC bindings for
233 * this device if it is managed by a SEP.
235 path_id = xpt_path_path_id(path);
237 TAILQ_FOREACH(periph, &encdriver.units, unit_links) {
238 struct enc_softc *softc;
240 softc = (struct enc_softc *)periph->softc;
242 /* Check this SEP is ready. */
243 if (softc == NULL || (softc->enc_flags &
244 ENC_FLAG_INITIALIZED) == 0 ||
245 softc->enc_vec.device_found == NULL)
248 /* Check this SEP may manage this device. */
249 if (xpt_path_path_id(periph->path) != path_id &&
250 (softc->enc_type != ENC_SEMB_SES ||
251 cgd->protocol != PROTO_ATA))
254 softc->enc_vec.device_found(softc);
260 status = cam_periph_alloc(enc_ctor, enc_oninvalidate,
261 enc_dtor, NULL, "ses", CAM_PERIPH_BIO,
262 path, enc_async, AC_FOUND_DEVICE, cgd);
264 if (status != CAM_REQ_CMP && status != CAM_REQ_INPROG) {
265 printf("enc_async: Unable to probe new device due to "
266 "status 0x%x\n", status);
271 cam_periph_async(periph, code, path, arg);
277 enc_open(struct cdev *dev, int flags, int fmt, struct thread *td)
279 struct cam_periph *periph;
280 struct enc_softc *softc;
283 periph = (struct cam_periph *)dev->si_drv1;
284 if (cam_periph_acquire(periph) != 0)
287 cam_periph_lock(periph);
289 softc = (struct enc_softc *)periph->softc;
291 if ((softc->enc_flags & ENC_FLAG_INITIALIZED) == 0) {
295 if (softc->enc_flags & ENC_FLAG_INVALID) {
301 cam_periph_release_locked(periph);
305 cam_periph_unlock(periph);
311 enc_close(struct cdev *dev, int flag, int fmt, struct thread *td)
313 struct cam_periph *periph;
314 struct enc_softc *enc;
317 periph = (struct cam_periph *)dev->si_drv1;
318 mtx = cam_periph_mtx(periph);
324 cam_periph_release_locked(periph);
327 * We reference the lock directly here, instead of using
328 * cam_periph_unlock(). The reason is that the call to
329 * cam_periph_release_locked() above could result in the periph
330 * getting freed. If that is the case, dereferencing the periph
331 * with a cam_periph_unlock() call would cause a page fault.
333 * cam_periph_release() avoids this problem using the same method,
334 * but we're manually acquiring and dropping the lock here to
335 * protect the open count and avoid another lock acquisition and
344 enc_error(union ccb *ccb, uint32_t cflags, uint32_t sflags)
347 return (cam_periph_error(ccb, cflags, sflags));
351 enc_ioctl(struct cdev *dev, u_long cmd, caddr_t arg_addr, int flag,
354 struct cam_periph *periph;
360 #ifdef COMPAT_FREEBSD32
361 if (SV_PROC_FLAG(td->td_proc, SV_ILP32))
366 addr = *((caddr_t *) arg_addr);
370 periph = (struct cam_periph *)dev->si_drv1;
371 CAM_DEBUG(periph->path, CAM_DEBUG_TRACE, ("entering encioctl\n"));
373 cam_periph_lock(periph);
374 enc = (struct enc_softc *)periph->softc;
375 cache = &enc->enc_cache;
378 * Now check to see whether we're initialized or not.
379 * This actually should never fail as we're not supposed
380 * to get past enc_open w/o successfully initializing
383 if ((enc->enc_flags & ENC_FLAG_INITIALIZED) == 0) {
384 cam_periph_unlock(periph);
387 cam_periph_unlock(periph);
391 CAM_DEBUG(periph->path, CAM_DEBUG_TRACE,
392 ("trying to do ioctl %#lx\n", cmd));
395 * If this command can change the device's state,
396 * we must have the device open for writing.
398 * For commands that get information about the
399 * device- we don't need to lock the peripheral
400 * if we aren't running a command. The periph
401 * also can't go away while a user process has
406 case ENCIOC_GETELMMAP:
407 case ENCIOC_GETENCSTAT:
408 case ENCIOC_GETELMSTAT:
409 case ENCIOC_GETELMDESC:
410 case ENCIOC_GETELMDEVNAMES:
411 case ENCIOC_GETENCNAME:
412 case ENCIOC_GETENCID:
415 if ((flag & FWRITE) == 0) {
421 * XXX The values read here are only valid for the current
422 * configuration generation. We need these ioctls
423 * to also pass in/out a generation number.
425 sx_slock(&enc->enc_cache_lock);
428 error = copyout(&cache->nelms, addr, sizeof (cache->nelms));
431 case ENCIOC_GETELMMAP: {
432 encioc_element_t *uelm;
434 for (uelm = addr, i = 0; i != cache->nelms; i++) {
435 encioc_element_t kelm;
437 kelm.elm_subenc_id = cache->elm_map[i].subenclosure;
438 kelm.elm_type = cache->elm_map[i].elm_type;
439 error = copyout(&kelm, &uelm[i], sizeof(kelm));
445 case ENCIOC_GETENCSTAT: {
446 error = copyout(&cache->enc_status, addr,
447 sizeof(cache->enc_status));
450 case ENCIOC_SETENCSTAT: {
451 encioc_enc_status_t tmp;
453 error = copyin(addr, &tmp, sizeof(tmp));
456 cam_periph_lock(periph);
457 error = enc->enc_vec.set_enc_status(enc, tmp, 1);
458 cam_periph_unlock(periph);
461 case ENCIOC_GETSTRING:
462 case ENCIOC_SETSTRING:
463 case ENCIOC_GETENCNAME:
464 case ENCIOC_GETENCID: {
465 encioc_string_t sstr;
467 if (enc->enc_vec.handle_string == NULL) {
471 error = copyin(addr, &sstr, sizeof(sstr));
474 cam_periph_lock(periph);
475 error = enc->enc_vec.handle_string(enc, &sstr, cmd);
476 cam_periph_unlock(periph);
477 if (error == 0 || error == ENOMEM)
478 (void)copyout(&sstr.bufsiz,
479 &((encioc_string_t *)addr)->bufsiz,
480 sizeof(sstr.bufsiz));
483 case ENCIOC_GETELMSTAT: {
484 encioc_elm_status_t elms;
486 error = copyin(addr, &elms, sizeof(elms));
489 if (elms.elm_idx >= cache->nelms) {
493 cam_periph_lock(periph);
494 error = enc->enc_vec.get_elm_status(enc, &elms, 1);
495 cam_periph_unlock(periph);
498 error = copyout(&elms, addr, sizeof(elms));
501 case ENCIOC_GETELMDESC: {
502 encioc_elm_desc_t elmd;
504 error = copyin(addr, &elmd, sizeof(elmd));
507 if (elmd.elm_idx >= cache->nelms) {
511 if (enc->enc_vec.get_elm_desc != NULL) {
512 error = enc->enc_vec.get_elm_desc(enc, &elmd);
516 elmd.elm_desc_len = 0;
517 error = copyout(&elmd, addr, sizeof(elmd));
520 case ENCIOC_GETELMDEVNAMES: {
521 encioc_elm_devnames_t elmdn;
523 if (enc->enc_vec.get_elm_devnames == NULL) {
527 error = copyin(addr, &elmdn, sizeof(elmdn));
530 if (elmdn.elm_idx >= cache->nelms) {
534 cam_periph_lock(periph);
535 error = (*enc->enc_vec.get_elm_devnames)(enc, &elmdn);
536 cam_periph_unlock(periph);
539 error = copyout(&elmdn, addr, sizeof(elmdn));
542 case ENCIOC_SETELMSTAT: {
543 encioc_elm_status_t elms;
545 error = copyin(addr, &elms, sizeof(elms));
549 if (elms.elm_idx >= cache->nelms) {
553 cam_periph_lock(periph);
554 error = enc->enc_vec.set_elm_status(enc, &elms, 1);
555 cam_periph_unlock(periph);
561 cam_periph_lock(periph);
562 error = enc->enc_vec.init_enc(enc);
563 cam_periph_unlock(periph);
567 cam_periph_lock(periph);
568 error = cam_periph_ioctl(periph, cmd, arg_addr, enc_error);
569 cam_periph_unlock(periph);
572 sx_sunlock(&enc->enc_cache_lock);
577 enc_runcmd(struct enc_softc *enc, char *cdb, int cdbl, char *dptr, int *dlenp)
579 int error, dlen, tdlen;
583 CAM_DEBUG(enc->periph->path, CAM_DEBUG_TRACE,
584 ("entering enc_runcmd\n"));
586 if ((dlen = *dlenp) < 0) {
597 if (cdbl > IOCDBLEN) {
601 ccb = cam_periph_getccb(enc->periph, CAM_PRIORITY_NORMAL);
602 if (enc->enc_type == ENC_SEMB_SES || enc->enc_type == ENC_SEMB_SAFT) {
603 tdlen = min(dlen, 1020);
604 tdlen = (tdlen + 3) & ~3;
605 cam_fill_ataio(&ccb->ataio, 0, NULL, ddf, 0, dptr, tdlen,
607 if (cdb[0] == RECEIVE_DIAGNOSTIC)
608 ata_28bit_cmd(&ccb->ataio,
609 ATA_SEP_ATTN, cdb[2], 0x02, tdlen / 4);
610 else if (cdb[0] == SEND_DIAGNOSTIC)
611 ata_28bit_cmd(&ccb->ataio,
612 ATA_SEP_ATTN, dlen > 0 ? dptr[0] : 0,
614 else if (cdb[0] == READ_BUFFER)
615 ata_28bit_cmd(&ccb->ataio,
616 ATA_SEP_ATTN, cdb[2], 0x00, tdlen / 4);
618 ata_28bit_cmd(&ccb->ataio,
619 ATA_SEP_ATTN, dlen > 0 ? dptr[0] : 0,
623 cam_fill_csio(&ccb->csio, 0, NULL, ddf, MSG_SIMPLE_Q_TAG,
624 dptr, dlen, sizeof (struct scsi_sense_data), cdbl,
626 bcopy(cdb, ccb->csio.cdb_io.cdb_bytes, cdbl);
629 error = cam_periph_runccb(ccb, enc_error, ENC_CFLAGS, ENC_FLAGS, NULL);
636 if (ccb->ccb_h.func_code == XPT_ATA_IO)
637 *dlenp = ccb->ataio.resid;
639 *dlenp = ccb->csio.resid;
640 *dlenp += tdlen - dlen;
643 xpt_release_ccb(ccb);
644 CAM_DEBUG(enc->periph->path, CAM_DEBUG_SUBTRACE,
645 ("exiting enc_runcmd: *dlenp = %d\n", *dlenp));
650 enc_log(struct enc_softc *enc, const char *fmt, ...)
654 printf("%s%d: ", enc->periph->periph_name, enc->periph->unit_number);
661 * The code after this point runs on many platforms,
662 * so forgive the slightly awkward and nonconforming
667 * Is this a device that supports enclosure services?
669 * It's a pretty simple ruleset- if it is device type
670 * 0x0D (13), it's an ENCLOSURE device.
673 #define SAFTE_START 44
675 #define SAFTE_LEN SAFTE_END-SAFTE_START
678 enc_type(struct ccb_getdev *cgd)
683 if (cgd->protocol == PROTO_SEMB) {
684 iqd = (unsigned char *)&cgd->ident_data;
685 if (STRNCMP(iqd + 43, "S-E-S", 5) == 0)
686 return (ENC_SEMB_SES);
687 else if (STRNCMP(iqd + 43, "SAF-TE", 6) == 0)
688 return (ENC_SEMB_SAFT);
691 } else if (cgd->protocol != PROTO_SCSI)
694 iqd = (unsigned char *)&cgd->inq_data;
695 buflen = min(sizeof(cgd->inq_data),
696 SID_ADDITIONAL_LENGTH(&cgd->inq_data));
698 if ((iqd[0] & 0x1f) == T_ENCLOSURE)
701 #ifdef SES_ENABLE_PASSTHROUGH
702 if ((iqd[6] & 0x40) && (iqd[2] & 0x7) >= 2) {
704 * PassThrough Device.
706 return (ENC_SES_PASSTHROUGH);
711 * The comparison is short for a reason-
712 * some vendors were chopping it short.
715 if (buflen < SAFTE_END - 2) {
719 if (STRNCMP((char *)&iqd[SAFTE_START], "SAF-TE", SAFTE_LEN - 2) == 0) {
725 /*================== Enclosure Monitoring/Processing Daemon ==================*/
727 * \brief Queue an update request for a given action, if needed.
729 * \param enc SES softc to queue the request for.
730 * \param action Action requested.
733 enc_update_request(enc_softc_t *enc, uint32_t action)
735 if ((enc->pending_actions & (0x1 << action)) == 0) {
736 enc->pending_actions |= (0x1 << action);
737 ENC_DLOG(enc, "%s: queing requested action %d\n",
739 if (enc->current_action == ENC_UPDATE_NONE)
740 wakeup(enc->enc_daemon);
742 ENC_DLOG(enc, "%s: ignoring requested action %d - "
743 "Already queued\n", __func__, action);
748 * \brief Invoke the handler of the highest priority pending
749 * state in the SES state machine.
751 * \param enc The SES instance invoking the state machine.
754 enc_fsm_step(enc_softc_t *enc)
758 struct enc_fsm_state *cur_state;
762 ENC_DLOG(enc, "%s enter %p\n", __func__, enc);
764 enc->current_action = ffs(enc->pending_actions) - 1;
765 enc->pending_actions &= ~(0x1 << enc->current_action);
767 cur_state = &enc->enc_fsm_states[enc->current_action];
770 if (cur_state->buf_size != 0) {
771 cam_periph_unlock(enc->periph);
772 buf = malloc(cur_state->buf_size, M_SCSIENC, M_WAITOK|M_ZERO);
773 cam_periph_lock(enc->periph);
778 if (cur_state->fill != NULL) {
779 ccb = cam_periph_getccb(enc->periph, CAM_PRIORITY_NORMAL);
781 error = cur_state->fill(enc, cur_state, ccb, buf);
785 error = cam_periph_runccb(ccb, cur_state->error,
787 ENC_FLAGS|SF_QUIET_IR, NULL);
791 if (ccb->ccb_h.func_code == XPT_ATA_IO)
792 xfer_len = ccb->ataio.dxfer_len - ccb->ataio.resid;
794 xfer_len = ccb->csio.dxfer_len - ccb->csio.resid;
798 cam_periph_unlock(enc->periph);
799 cur_state->done(enc, cur_state, ccb, &buf, error, xfer_len);
800 cam_periph_lock(enc->periph);
803 ENC_DLOG(enc, "%s exit - result %d\n", __func__, error);
804 ENC_FREE_AND_NULL(buf);
806 xpt_release_ccb(ccb);
810 * \invariant Called with cam_periph mutex held.
813 enc_status_updater(void *arg)
818 if (enc->enc_vec.poll_status != NULL)
819 enc->enc_vec.poll_status(enc);
823 enc_daemon(void *arg)
829 cam_periph_lock(enc->periph);
830 while ((enc->enc_flags & ENC_FLAG_SHUTDOWN) == 0) {
831 if (enc->pending_actions == 0) {
833 * Reset callout and msleep, or
834 * issue timed task completion
837 enc->current_action = ENC_UPDATE_NONE;
840 * We've been through our state machine at least
841 * once. Allow the transition to userland.
843 cam_periph_release_boot(enc->periph);
845 callout_reset_sbt(&enc->status_updater, 60 * SBT_1S, 0,
846 enc_status_updater, enc, C_PREL(1));
848 cam_periph_sleep(enc->periph, enc->enc_daemon,
854 enc->enc_daemon = NULL;
855 cam_periph_unlock(enc->periph);
856 cam_periph_release(enc->periph);
861 enc_kproc_init(enc_softc_t *enc)
865 callout_init_mtx(&enc->status_updater, cam_periph_mtx(enc->periph), 0);
867 if (cam_periph_acquire(enc->periph) != 0)
870 result = kproc_create(enc_daemon, enc, &enc->enc_daemon, /*flags*/0,
871 /*stackpgs*/0, "enc_daemon%d",
872 enc->periph->unit_number);
874 /* Do an initial load of all page data. */
875 cam_periph_lock(enc->periph);
876 enc->enc_vec.poll_status(enc);
877 cam_periph_unlock(enc->periph);
879 cam_periph_release(enc->periph);
884 enc_ctor(struct cam_periph *periph, void *arg)
886 cam_status status = CAM_REQ_CMP_ERR;
889 struct ccb_getdev *cgd;
891 struct make_dev_args args;
894 cgd = (struct ccb_getdev *)arg;
896 printf("enc_ctor: no getdev CCB, can't register device\n");
900 enc = ENC_MALLOCZ(sizeof(*enc));
902 printf("enc_ctor: Unable to probe new device. "
903 "Unable to allocate enc\n");
906 enc->periph = periph;
907 enc->current_action = ENC_UPDATE_INVALID;
909 enc->enc_type = enc_type(cgd);
910 sx_init(&enc->enc_cache_lock, "enccache");
912 switch (enc->enc_type) {
914 case ENC_SES_PASSTHROUGH:
916 err = ses_softc_init(enc);
920 err = safte_softc_init(enc);
925 return (CAM_REQ_CMP_ERR);
929 xpt_print(periph->path, "error %d initializing\n", err);
934 * Hold off userland until we have made at least one pass
935 * through our state machine so that physical path data is
938 if (enc->enc_vec.poll_status != NULL)
939 cam_periph_hold_boot(periph);
942 * The softc field is set only once the enc is fully initialized
943 * so that we can rely on this field to detect partially
944 * initialized periph objects in the AC_FOUND_DEVICE handler.
948 cam_periph_unlock(periph);
949 if (enc->enc_vec.poll_status != NULL) {
950 err = enc_kproc_init(enc);
952 xpt_print(periph->path,
953 "error %d starting enc_daemon\n", err);
959 * Acquire a reference to the periph before we create the devfs
960 * instance for it. We'll release this reference once the devfs
961 * instance has been freed.
963 if (cam_periph_acquire(periph) != 0) {
964 xpt_print(periph->path, "%s: lost periph during "
965 "registration!\n", __func__);
966 cam_periph_lock(periph);
968 return (CAM_REQ_CMP_ERR);
971 make_dev_args_init(&args);
972 args.mda_devsw = &enc_cdevsw;
973 args.mda_unit = periph->unit_number;
974 args.mda_uid = UID_ROOT;
975 args.mda_gid = GID_OPERATOR;
976 args.mda_mode = 0600;
977 args.mda_si_drv1 = periph;
978 err = make_dev_s(&args, &enc->enc_dev, "%s%d", periph->periph_name,
979 periph->unit_number);
980 cam_periph_lock(periph);
982 cam_periph_release_locked(periph);
983 return (CAM_REQ_CMP_ERR);
986 enc->enc_flags |= ENC_FLAG_INITIALIZED;
989 * Add an async callback so that we get notified if this
992 xpt_register_async(AC_LOST_DEVICE, enc_async, periph, periph->path);
994 switch (enc->enc_type) {
997 tname = "No ENC device";
1000 tname = "SES Device";
1002 case ENC_SES_PASSTHROUGH:
1003 tname = "SES Passthrough Device";
1006 tname = "SAF-TE Device";
1009 tname = "SEMB SES Device";
1012 tname = "SEMB SAF-TE Device";
1016 sbuf_new(&sb, enc->announce_buf, ENC_ANNOUNCE_SZ, SBUF_FIXEDLEN);
1017 xpt_announce_periph_sbuf(periph, &sb, tname);
1021 status = CAM_REQ_CMP;
1024 if (status != CAM_REQ_CMP)