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>
43 #include <sys/systm.h>
44 #include <sys/sysctl.h>
45 #include <sys/types.h>
47 #include <machine/stdarg.h>
50 #include <cam/cam_ccb.h>
51 #include <cam/cam_debug.h>
52 #include <cam/cam_periph.h>
53 #include <cam/cam_xpt_periph.h>
55 #include <cam/scsi/scsi_all.h>
56 #include <cam/scsi/scsi_message.h>
57 #include <cam/scsi/scsi_enc.h>
58 #include <cam/scsi/scsi_enc_internal.h>
62 MALLOC_DEFINE(M_SCSIENC, "SCSI ENC", "SCSI ENC buffers");
64 /* Enclosure type independent driver */
66 static d_open_t enc_open;
67 static d_close_t enc_close;
68 static d_ioctl_t enc_ioctl;
69 static periph_init_t enc_init;
70 static periph_ctor_t enc_ctor;
71 static periph_oninv_t enc_oninvalidate;
72 static periph_dtor_t enc_dtor;
74 static void enc_async(void *, uint32_t, struct cam_path *, void *);
75 static enctyp enc_type(struct ccb_getdev *);
77 SYSCTL_NODE(_kern_cam, OID_AUTO, enc, CTLFLAG_RD, 0,
78 "CAM Enclosure Services driver");
80 static struct periph_driver encdriver = {
82 TAILQ_HEAD_INITIALIZER(encdriver.units), /* generation */ 0
85 PERIPHDRIVER_DECLARE(enc, encdriver);
87 static struct cdevsw enc_cdevsw = {
88 .d_version = D_VERSION,
93 .d_flags = D_TRACKCLOSE,
102 * Install a global async callback. This callback will
103 * receive async callbacks like "new device found".
105 status = xpt_register_async(AC_FOUND_DEVICE, enc_async, NULL, NULL);
107 if (status != CAM_REQ_CMP) {
108 printf("enc: Failed to attach master async callback "
109 "due to status 0x%x!\n", status);
114 enc_devgonecb(void *arg)
116 struct cam_periph *periph;
117 struct enc_softc *enc;
121 periph = (struct cam_periph *)arg;
122 mtx = cam_periph_mtx(periph);
124 enc = (struct enc_softc *)periph->softc;
127 * When we get this callback, we will get no more close calls from
128 * devfs. So if we have any dangling opens, we need to release the
129 * reference held for that particular context.
131 for (i = 0; i < enc->open_count; i++)
132 cam_periph_release_locked(periph);
137 * Release the reference held for the device node, it is gone now.
139 cam_periph_release_locked(periph);
142 * We reference the lock directly here, instead of using
143 * cam_periph_unlock(). The reason is that the final call to
144 * cam_periph_release_locked() above could result in the periph
145 * getting freed. If that is the case, dereferencing the periph
146 * with a cam_periph_unlock() call would cause a page fault.
152 enc_oninvalidate(struct cam_periph *periph)
154 struct enc_softc *enc;
158 enc->enc_flags |= ENC_FLAG_INVALID;
160 /* If the sub-driver has an invalidate routine, call it */
161 if (enc->enc_vec.softc_invalidate != NULL)
162 enc->enc_vec.softc_invalidate(enc);
165 * Unregister any async callbacks.
167 xpt_register_async(0, enc_async, periph, periph->path);
170 * Shutdown our daemon.
172 enc->enc_flags |= ENC_FLAG_SHUTDOWN;
173 if (enc->enc_daemon != NULL) {
174 /* Signal the ses daemon to terminate. */
175 wakeup(enc->enc_daemon);
177 callout_drain(&enc->status_updater);
179 destroy_dev_sched_cb(enc->enc_dev, enc_devgonecb, periph);
183 enc_dtor(struct cam_periph *periph)
185 struct enc_softc *enc;
189 /* If the sub-driver has a cleanup routine, call it */
190 if (enc->enc_vec.softc_cleanup != NULL)
191 enc->enc_vec.softc_cleanup(enc);
193 if (enc->enc_boot_hold_ch.ich_func != NULL) {
194 config_intrhook_disestablish(&enc->enc_boot_hold_ch);
195 enc->enc_boot_hold_ch.ich_func = NULL;
202 enc_async(void *callback_arg, uint32_t code, struct cam_path *path, void *arg)
204 struct cam_periph *periph;
206 periph = (struct cam_periph *)callback_arg;
209 case AC_FOUND_DEVICE:
211 struct ccb_getdev *cgd;
215 cgd = (struct ccb_getdev *)arg;
220 if (enc_type(cgd) == ENC_NONE) {
222 * Schedule announcement of the ENC bindings for
223 * this device if it is managed by a SEP.
225 path_id = xpt_path_path_id(path);
227 TAILQ_FOREACH(periph, &encdriver.units, unit_links) {
228 struct enc_softc *softc;
230 softc = (struct enc_softc *)periph->softc;
231 if (xpt_path_path_id(periph->path) != path_id
233 || (softc->enc_flags & ENC_FLAG_INITIALIZED)
235 || softc->enc_vec.device_found == NULL)
238 softc->enc_vec.device_found(softc);
244 status = cam_periph_alloc(enc_ctor, enc_oninvalidate,
245 enc_dtor, NULL, "ses", CAM_PERIPH_BIO,
246 path, enc_async, AC_FOUND_DEVICE, cgd);
248 if (status != CAM_REQ_CMP && status != CAM_REQ_INPROG) {
249 printf("enc_async: Unable to probe new device due to "
250 "status 0x%x\n", status);
255 cam_periph_async(periph, code, path, arg);
261 enc_open(struct cdev *dev, int flags, int fmt, struct thread *td)
263 struct cam_periph *periph;
264 struct enc_softc *softc;
267 periph = (struct cam_periph *)dev->si_drv1;
268 if (cam_periph_acquire(periph) != CAM_REQ_CMP)
271 cam_periph_lock(periph);
273 softc = (struct enc_softc *)periph->softc;
275 if ((softc->enc_flags & ENC_FLAG_INITIALIZED) == 0) {
279 if (softc->enc_flags & ENC_FLAG_INVALID) {
285 cam_periph_release_locked(periph);
289 cam_periph_unlock(periph);
295 enc_close(struct cdev *dev, int flag, int fmt, struct thread *td)
297 struct cam_periph *periph;
298 struct enc_softc *enc;
301 periph = (struct cam_periph *)dev->si_drv1;
302 mtx = cam_periph_mtx(periph);
308 cam_periph_release_locked(periph);
311 * We reference the lock directly here, instead of using
312 * cam_periph_unlock(). The reason is that the call to
313 * cam_periph_release_locked() above could result in the periph
314 * getting freed. If that is the case, dereferencing the periph
315 * with a cam_periph_unlock() call would cause a page fault.
317 * cam_periph_release() avoids this problem using the same method,
318 * but we're manually acquiring and dropping the lock here to
319 * protect the open count and avoid another lock acquisition and
328 enc_error(union ccb *ccb, uint32_t cflags, uint32_t sflags)
330 struct enc_softc *softc;
331 struct cam_periph *periph;
333 periph = xpt_path_periph(ccb->ccb_h.path);
334 softc = (struct enc_softc *)periph->softc;
336 return (cam_periph_error(ccb, cflags, sflags, &softc->saved_ccb));
340 enc_ioctl(struct cdev *dev, u_long cmd, caddr_t arg_addr, int flag,
343 struct cam_periph *periph;
344 encioc_enc_status_t tmp;
345 encioc_string_t sstr;
346 encioc_elm_status_t elms;
347 encioc_elm_desc_t elmd;
348 encioc_elm_devnames_t elmdn;
349 encioc_element_t *uelm;
357 addr = *((caddr_t *) arg_addr);
361 periph = (struct cam_periph *)dev->si_drv1;
362 CAM_DEBUG(periph->path, CAM_DEBUG_TRACE, ("entering encioctl\n"));
364 cam_periph_lock(periph);
365 enc = (struct enc_softc *)periph->softc;
366 cache = &enc->enc_cache;
369 * Now check to see whether we're initialized or not.
370 * This actually should never fail as we're not supposed
371 * to get past enc_open w/o successfully initializing
374 if ((enc->enc_flags & ENC_FLAG_INITIALIZED) == 0) {
375 cam_periph_unlock(periph);
378 cam_periph_unlock(periph);
382 CAM_DEBUG(periph->path, CAM_DEBUG_TRACE,
383 ("trying to do ioctl %#lx\n", cmd));
386 * If this command can change the device's state,
387 * we must have the device open for writing.
389 * For commands that get information about the
390 * device- we don't need to lock the peripheral
391 * if we aren't running a command. The periph
392 * also can't go away while a user process has
397 case ENCIOC_GETELMMAP:
398 case ENCIOC_GETENCSTAT:
399 case ENCIOC_GETELMSTAT:
400 case ENCIOC_GETELMDESC:
401 case ENCIOC_GETELMDEVNAMES:
402 case ENCIOC_GETENCNAME:
403 case ENCIOC_GETENCID:
406 if ((flag & FWRITE) == 0) {
412 * XXX The values read here are only valid for the current
413 * configuration generation. We need these ioctls
414 * to also pass in/out a generation number.
416 sx_slock(&enc->enc_cache_lock);
419 error = copyout(&cache->nelms, addr, sizeof (cache->nelms));
422 case ENCIOC_GETELMMAP:
423 for (uelm = addr, i = 0; i != cache->nelms; i++) {
424 encioc_element_t kelm;
426 kelm.elm_subenc_id = cache->elm_map[i].subenclosure;
427 kelm.elm_type = cache->elm_map[i].enctype;
428 error = copyout(&kelm, &uelm[i], sizeof(kelm));
434 case ENCIOC_GETENCSTAT:
435 cam_periph_lock(periph);
436 error = enc->enc_vec.get_enc_status(enc, 1);
438 cam_periph_unlock(periph);
441 tmp = cache->enc_status;
442 cam_periph_unlock(periph);
443 error = copyout(&tmp, addr, sizeof(tmp));
444 cache->enc_status = tmp;
447 case ENCIOC_SETENCSTAT:
448 error = copyin(addr, &tmp, sizeof(tmp));
451 cam_periph_lock(periph);
452 error = enc->enc_vec.set_enc_status(enc, tmp, 1);
453 cam_periph_unlock(periph);
456 case ENCIOC_GETSTRING:
457 case ENCIOC_SETSTRING:
458 case ENCIOC_GETENCNAME:
459 case ENCIOC_GETENCID:
460 if (enc->enc_vec.handle_string == NULL) {
464 error = copyin(addr, &sstr, sizeof(sstr));
467 cam_periph_lock(periph);
468 error = enc->enc_vec.handle_string(enc, &sstr, cmd);
469 cam_periph_unlock(periph);
472 case ENCIOC_GETELMSTAT:
473 error = copyin(addr, &elms, sizeof(elms));
476 if (elms.elm_idx >= cache->nelms) {
480 cam_periph_lock(periph);
481 error = enc->enc_vec.get_elm_status(enc, &elms, 1);
482 cam_periph_unlock(periph);
485 error = copyout(&elms, addr, sizeof(elms));
488 case ENCIOC_GETELMDESC:
489 error = copyin(addr, &elmd, sizeof(elmd));
492 if (elmd.elm_idx >= cache->nelms) {
496 if (enc->enc_vec.get_elm_desc != NULL) {
497 error = enc->enc_vec.get_elm_desc(enc, &elmd);
501 elmd.elm_desc_len = 0;
502 error = copyout(&elmd, addr, sizeof(elmd));
505 case ENCIOC_GETELMDEVNAMES:
506 if (enc->enc_vec.get_elm_devnames == NULL) {
510 error = copyin(addr, &elmdn, sizeof(elmdn));
513 if (elmdn.elm_idx >= cache->nelms) {
517 cam_periph_lock(periph);
518 error = (*enc->enc_vec.get_elm_devnames)(enc, &elmdn);
519 cam_periph_unlock(periph);
522 error = copyout(&elmdn, addr, sizeof(elmdn));
525 case ENCIOC_SETELMSTAT:
526 error = copyin(addr, &elms, sizeof(elms));
530 if (elms.elm_idx >= cache->nelms) {
534 cam_periph_lock(periph);
535 error = enc->enc_vec.set_elm_status(enc, &elms, 1);
536 cam_periph_unlock(periph);
542 cam_periph_lock(periph);
543 error = enc->enc_vec.init_enc(enc);
544 cam_periph_unlock(periph);
548 cam_periph_lock(periph);
549 error = cam_periph_ioctl(periph, cmd, arg_addr, enc_error);
550 cam_periph_unlock(periph);
553 sx_sunlock(&enc->enc_cache_lock);
558 enc_runcmd(struct enc_softc *enc, char *cdb, int cdbl, char *dptr, int *dlenp)
560 int error, dlen, tdlen;
564 CAM_DEBUG(enc->periph->path, CAM_DEBUG_TRACE,
565 ("entering enc_runcmd\n"));
567 if ((dlen = *dlenp) < 0) {
578 if (cdbl > IOCDBLEN) {
582 ccb = cam_periph_getccb(enc->periph, CAM_PRIORITY_NORMAL);
583 if (enc->enc_type == ENC_SEMB_SES || enc->enc_type == ENC_SEMB_SAFT) {
584 tdlen = min(dlen, 1020);
585 tdlen = (tdlen + 3) & ~3;
586 cam_fill_ataio(&ccb->ataio, 0, NULL, ddf, 0, dptr, tdlen,
588 if (cdb[0] == RECEIVE_DIAGNOSTIC)
589 ata_28bit_cmd(&ccb->ataio,
590 ATA_SEP_ATTN, cdb[2], 0x02, tdlen / 4);
591 else if (cdb[0] == SEND_DIAGNOSTIC)
592 ata_28bit_cmd(&ccb->ataio,
593 ATA_SEP_ATTN, dlen > 0 ? dptr[0] : 0,
595 else if (cdb[0] == READ_BUFFER)
596 ata_28bit_cmd(&ccb->ataio,
597 ATA_SEP_ATTN, cdb[2], 0x00, tdlen / 4);
599 ata_28bit_cmd(&ccb->ataio,
600 ATA_SEP_ATTN, dlen > 0 ? dptr[0] : 0,
604 cam_fill_csio(&ccb->csio, 0, NULL, ddf, MSG_SIMPLE_Q_TAG,
605 dptr, dlen, sizeof (struct scsi_sense_data), cdbl,
607 bcopy(cdb, ccb->csio.cdb_io.cdb_bytes, cdbl);
610 error = cam_periph_runccb(ccb, enc_error, ENC_CFLAGS, ENC_FLAGS, NULL);
617 if (ccb->ccb_h.func_code == XPT_ATA_IO)
618 *dlenp = ccb->ataio.resid;
620 *dlenp = ccb->csio.resid;
621 *dlenp += tdlen - dlen;
624 xpt_release_ccb(ccb);
625 CAM_DEBUG(enc->periph->path, CAM_DEBUG_SUBTRACE,
626 ("exiting enc_runcmd: *dlenp = %d\n", *dlenp));
631 enc_log(struct enc_softc *enc, const char *fmt, ...)
635 printf("%s%d: ", enc->periph->periph_name, enc->periph->unit_number);
642 * The code after this point runs on many platforms,
643 * so forgive the slightly awkward and nonconforming
648 * Is this a device that supports enclosure services?
650 * It's a pretty simple ruleset- if it is device type
651 * 0x0D (13), it's an ENCLOSURE device.
654 #define SAFTE_START 44
656 #define SAFTE_LEN SAFTE_END-SAFTE_START
659 enc_type(struct ccb_getdev *cgd)
664 if (cgd->protocol == PROTO_SEMB) {
665 iqd = (unsigned char *)&cgd->ident_data;
666 if (STRNCMP(iqd + 43, "S-E-S", 5) == 0)
667 return (ENC_SEMB_SES);
668 else if (STRNCMP(iqd + 43, "SAF-TE", 6) == 0)
669 return (ENC_SEMB_SAFT);
672 } else if (cgd->protocol != PROTO_SCSI)
675 iqd = (unsigned char *)&cgd->inq_data;
676 buflen = min(sizeof(cgd->inq_data),
677 SID_ADDITIONAL_LENGTH(&cgd->inq_data));
679 if ((iqd[0] & 0x1f) == T_ENCLOSURE) {
680 if ((iqd[2] & 0x7) > 2) {
683 return (ENC_SES_SCSI2);
688 #ifdef SES_ENABLE_PASSTHROUGH
689 if ((iqd[6] & 0x40) && (iqd[2] & 0x7) >= 2) {
691 * PassThrough Device.
693 return (ENC_SES_PASSTHROUGH);
698 * The comparison is short for a reason-
699 * some vendors were chopping it short.
702 if (buflen < SAFTE_END - 2) {
706 if (STRNCMP((char *)&iqd[SAFTE_START], "SAF-TE", SAFTE_LEN - 2) == 0) {
712 /*================== Enclosure Monitoring/Processing Daemon ==================*/
714 * \brief Queue an update request for a given action, if needed.
716 * \param enc SES softc to queue the request for.
717 * \param action Action requested.
720 enc_update_request(enc_softc_t *enc, uint32_t action)
722 if ((enc->pending_actions & (0x1 << action)) == 0) {
723 enc->pending_actions |= (0x1 << action);
724 ENC_DLOG(enc, "%s: queing requested action %d\n",
726 if (enc->current_action == ENC_UPDATE_NONE)
727 wakeup(enc->enc_daemon);
729 ENC_DLOG(enc, "%s: ignoring requested action %d - "
730 "Already queued\n", __func__, action);
735 * \brief Invoke the handler of the highest priority pending
736 * state in the SES state machine.
738 * \param enc The SES instance invoking the state machine.
741 enc_fsm_step(enc_softc_t *enc)
745 struct enc_fsm_state *cur_state;
749 ENC_DLOG(enc, "%s enter %p\n", __func__, enc);
751 enc->current_action = ffs(enc->pending_actions) - 1;
752 enc->pending_actions &= ~(0x1 << enc->current_action);
754 cur_state = &enc->enc_fsm_states[enc->current_action];
757 if (cur_state->buf_size != 0) {
758 cam_periph_unlock(enc->periph);
759 buf = malloc(cur_state->buf_size, M_SCSIENC, M_WAITOK|M_ZERO);
760 cam_periph_lock(enc->periph);
765 if (cur_state->fill != NULL) {
766 ccb = cam_periph_getccb(enc->periph, CAM_PRIORITY_NORMAL);
768 error = cur_state->fill(enc, cur_state, ccb, buf);
772 error = cam_periph_runccb(ccb, cur_state->error,
774 ENC_FLAGS|SF_QUIET_IR, NULL);
778 if (ccb->ccb_h.func_code == XPT_ATA_IO)
779 xfer_len = ccb->ataio.dxfer_len - ccb->ataio.resid;
781 xfer_len = ccb->csio.dxfer_len - ccb->csio.resid;
785 cam_periph_unlock(enc->periph);
786 cur_state->done(enc, cur_state, ccb, &buf, error, xfer_len);
787 cam_periph_lock(enc->periph);
790 ENC_DLOG(enc, "%s exit - result %d\n", __func__, error);
791 ENC_FREE_AND_NULL(buf);
793 xpt_release_ccb(ccb);
797 * \invariant Called with cam_periph mutex held.
800 enc_status_updater(void *arg)
805 if (enc->enc_vec.poll_status != NULL)
806 enc->enc_vec.poll_status(enc);
810 enc_daemon(void *arg)
816 cam_periph_lock(enc->periph);
817 while ((enc->enc_flags & ENC_FLAG_SHUTDOWN) == 0) {
818 if (enc->pending_actions == 0) {
819 struct intr_config_hook *hook;
822 * Reset callout and msleep, or
823 * issue timed task completion
826 enc->current_action = ENC_UPDATE_NONE;
829 * We've been through our state machine at least
830 * once. Allow the transition to userland.
832 hook = &enc->enc_boot_hold_ch;
833 if (hook->ich_func != NULL) {
834 config_intrhook_disestablish(hook);
835 hook->ich_func = NULL;
838 callout_reset(&enc->status_updater, 60*hz,
839 enc_status_updater, enc);
841 cam_periph_sleep(enc->periph, enc->enc_daemon,
847 enc->enc_daemon = NULL;
848 cam_periph_unlock(enc->periph);
849 cam_periph_release(enc->periph);
854 enc_kproc_init(enc_softc_t *enc)
858 callout_init_mtx(&enc->status_updater, cam_periph_mtx(enc->periph), 0);
860 if (cam_periph_acquire(enc->periph) != CAM_REQ_CMP)
863 result = kproc_create(enc_daemon, enc, &enc->enc_daemon, /*flags*/0,
864 /*stackpgs*/0, "enc_daemon%d",
865 enc->periph->unit_number);
867 /* Do an initial load of all page data. */
868 cam_periph_lock(enc->periph);
869 enc->enc_vec.poll_status(enc);
870 cam_periph_unlock(enc->periph);
872 cam_periph_release(enc->periph);
877 * \brief Interrupt configuration hook callback associated with
880 * Since interrupts are always functional at the time of enclosure
881 * configuration, there is nothing to be done when the callback occurs.
882 * This hook is only registered to hold up boot processing while initial
883 * eclosure processing occurs.
885 * \param arg The enclosure softc, but currently unused in this callback.
888 enc_nop_confighook_cb(void *arg __unused)
893 enc_ctor(struct cam_periph *periph, void *arg)
895 cam_status status = CAM_REQ_CMP_ERR;
898 struct ccb_getdev *cgd;
900 struct make_dev_args args;
903 cgd = (struct ccb_getdev *)arg;
905 printf("enc_ctor: no getdev CCB, can't register device\n");
909 enc = ENC_MALLOCZ(sizeof(*enc));
911 printf("enc_ctor: Unable to probe new device. "
912 "Unable to allocate enc\n");
915 enc->periph = periph;
916 enc->current_action = ENC_UPDATE_INVALID;
918 enc->enc_type = enc_type(cgd);
919 sx_init(&enc->enc_cache_lock, "enccache");
921 switch (enc->enc_type) {
924 case ENC_SES_PASSTHROUGH:
926 err = ses_softc_init(enc);
930 err = safte_softc_init(enc);
935 return (CAM_REQ_CMP_ERR);
939 xpt_print(periph->path, "error %d initializing\n", err);
944 * Hold off userland until we have made at least one pass
945 * through our state machine so that physical path data is
948 if (enc->enc_vec.poll_status != NULL) {
949 enc->enc_boot_hold_ch.ich_func = enc_nop_confighook_cb;
950 enc->enc_boot_hold_ch.ich_arg = enc;
951 config_intrhook_establish(&enc->enc_boot_hold_ch);
955 * The softc field is set only once the enc is fully initialized
956 * so that we can rely on this field to detect partially
957 * initialized periph objects in the AC_FOUND_DEVICE handler.
961 cam_periph_unlock(periph);
962 if (enc->enc_vec.poll_status != NULL) {
963 err = enc_kproc_init(enc);
965 xpt_print(periph->path,
966 "error %d starting enc_daemon\n", err);
972 * Acquire a reference to the periph before we create the devfs
973 * instance for it. We'll release this reference once the devfs
974 * instance has been freed.
976 if (cam_periph_acquire(periph) != CAM_REQ_CMP) {
977 xpt_print(periph->path, "%s: lost periph during "
978 "registration!\n", __func__);
979 cam_periph_lock(periph);
981 return (CAM_REQ_CMP_ERR);
984 make_dev_args_init(&args);
985 args.mda_devsw = &enc_cdevsw;
986 args.mda_unit = periph->unit_number;
987 args.mda_uid = UID_ROOT;
988 args.mda_gid = GID_OPERATOR;
989 args.mda_mode = 0600;
990 args.mda_si_drv1 = periph;
991 err = make_dev_s(&args, &enc->enc_dev, "%s%d", periph->periph_name,
992 periph->unit_number);
993 cam_periph_lock(periph);
995 cam_periph_release_locked(periph);
996 return (CAM_REQ_CMP_ERR);
999 enc->enc_flags |= ENC_FLAG_INITIALIZED;
1002 * Add an async callback so that we get notified if this
1005 xpt_register_async(AC_LOST_DEVICE, enc_async, periph, periph->path);
1007 switch (enc->enc_type) {
1010 tname = "No ENC device";
1013 tname = "SCSI-2 ENC Device";
1016 tname = "SCSI-3 ENC Device";
1018 case ENC_SES_PASSTHROUGH:
1019 tname = "ENC Passthrough Device";
1022 tname = "SAF-TE Compliant Device";
1025 tname = "SEMB SES Device";
1028 tname = "SEMB SAF-TE Device";
1032 sbuf_new(&sb, enc->announce_buf, ENC_ANNOUNCE_SZ, SBUF_FIXEDLEN);
1033 xpt_announce_periph_sbuf(periph, &sb, tname);
1037 status = CAM_REQ_CMP;
1040 if (status != CAM_REQ_CMP)