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, 0,
82 "CAM Enclosure Services driver");
84 static struct periph_driver encdriver = {
86 TAILQ_HEAD_INITIALIZER(encdriver.units), /* generation */ 0
89 PERIPHDRIVER_DECLARE(enc, encdriver);
91 static struct cdevsw enc_cdevsw = {
92 .d_version = D_VERSION,
97 .d_flags = D_TRACKCLOSE,
106 * Install a global async callback. This callback will
107 * receive async callbacks like "new device found".
109 status = xpt_register_async(AC_FOUND_DEVICE, enc_async, NULL, NULL);
111 if (status != CAM_REQ_CMP) {
112 printf("enc: Failed to attach master async callback "
113 "due to status 0x%x!\n", status);
118 enc_devgonecb(void *arg)
120 struct cam_periph *periph;
121 struct enc_softc *enc;
125 periph = (struct cam_periph *)arg;
126 mtx = cam_periph_mtx(periph);
128 enc = (struct enc_softc *)periph->softc;
131 * When we get this callback, we will get no more close calls from
132 * devfs. So if we have any dangling opens, we need to release the
133 * reference held for that particular context.
135 for (i = 0; i < enc->open_count; i++)
136 cam_periph_release_locked(periph);
141 * Release the reference held for the device node, it is gone now.
143 cam_periph_release_locked(periph);
146 * We reference the lock directly here, instead of using
147 * cam_periph_unlock(). The reason is that the final call to
148 * cam_periph_release_locked() above could result in the periph
149 * getting freed. If that is the case, dereferencing the periph
150 * with a cam_periph_unlock() call would cause a page fault.
156 enc_oninvalidate(struct cam_periph *periph)
158 struct enc_softc *enc;
162 enc->enc_flags |= ENC_FLAG_INVALID;
164 /* If the sub-driver has an invalidate routine, call it */
165 if (enc->enc_vec.softc_invalidate != NULL)
166 enc->enc_vec.softc_invalidate(enc);
169 * Unregister any async callbacks.
171 xpt_register_async(0, enc_async, periph, periph->path);
174 * Shutdown our daemon.
176 enc->enc_flags |= ENC_FLAG_SHUTDOWN;
177 if (enc->enc_daemon != NULL) {
178 /* Signal the ses daemon to terminate. */
179 wakeup(enc->enc_daemon);
181 callout_drain(&enc->status_updater);
183 destroy_dev_sched_cb(enc->enc_dev, enc_devgonecb, periph);
187 enc_dtor(struct cam_periph *periph)
189 struct enc_softc *enc;
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, NULL, "ses", CAM_PERIPH_BIO,
250 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 (cam_periph_acquire(periph) != 0)
275 cam_periph_lock(periph);
277 softc = (struct enc_softc *)periph->softc;
279 if ((softc->enc_flags & ENC_FLAG_INITIALIZED) == 0) {
283 if (softc->enc_flags & ENC_FLAG_INVALID) {
289 cam_periph_release_locked(periph);
293 cam_periph_unlock(periph);
299 enc_close(struct cdev *dev, int flag, int fmt, struct thread *td)
301 struct cam_periph *periph;
302 struct enc_softc *enc;
305 periph = (struct cam_periph *)dev->si_drv1;
306 mtx = cam_periph_mtx(periph);
312 cam_periph_release_locked(periph);
315 * We reference the lock directly here, instead of using
316 * cam_periph_unlock(). The reason is that the call to
317 * cam_periph_release_locked() above could result in the periph
318 * getting freed. If that is the case, dereferencing the periph
319 * with a cam_periph_unlock() call would cause a page fault.
321 * cam_periph_release() avoids this problem using the same method,
322 * but we're manually acquiring and dropping the lock here to
323 * protect the open count and avoid another lock acquisition and
332 enc_error(union ccb *ccb, uint32_t cflags, uint32_t sflags)
334 struct enc_softc *softc;
335 struct cam_periph *periph;
337 periph = xpt_path_periph(ccb->ccb_h.path);
338 softc = (struct enc_softc *)periph->softc;
340 return (cam_periph_error(ccb, cflags, sflags));
344 enc_ioctl(struct cdev *dev, u_long cmd, caddr_t arg_addr, int flag,
347 struct cam_periph *periph;
348 encioc_enc_status_t tmp;
349 encioc_string_t sstr;
350 encioc_elm_status_t elms;
351 encioc_elm_desc_t elmd;
352 encioc_elm_devnames_t elmdn;
353 encioc_element_t *uelm;
359 #ifdef COMPAT_FREEBSD32
360 if (SV_PROC_FLAG(td->td_proc, SV_ILP32))
365 addr = *((caddr_t *) arg_addr);
369 periph = (struct cam_periph *)dev->si_drv1;
370 CAM_DEBUG(periph->path, CAM_DEBUG_TRACE, ("entering encioctl\n"));
372 cam_periph_lock(periph);
373 enc = (struct enc_softc *)periph->softc;
374 cache = &enc->enc_cache;
377 * Now check to see whether we're initialized or not.
378 * This actually should never fail as we're not supposed
379 * to get past enc_open w/o successfully initializing
382 if ((enc->enc_flags & ENC_FLAG_INITIALIZED) == 0) {
383 cam_periph_unlock(periph);
386 cam_periph_unlock(periph);
390 CAM_DEBUG(periph->path, CAM_DEBUG_TRACE,
391 ("trying to do ioctl %#lx\n", cmd));
394 * If this command can change the device's state,
395 * we must have the device open for writing.
397 * For commands that get information about the
398 * device- we don't need to lock the peripheral
399 * if we aren't running a command. The periph
400 * also can't go away while a user process has
405 case ENCIOC_GETELMMAP:
406 case ENCIOC_GETENCSTAT:
407 case ENCIOC_GETELMSTAT:
408 case ENCIOC_GETELMDESC:
409 case ENCIOC_GETELMDEVNAMES:
410 case ENCIOC_GETENCNAME:
411 case ENCIOC_GETENCID:
414 if ((flag & FWRITE) == 0) {
420 * XXX The values read here are only valid for the current
421 * configuration generation. We need these ioctls
422 * to also pass in/out a generation number.
424 sx_slock(&enc->enc_cache_lock);
427 error = copyout(&cache->nelms, addr, sizeof (cache->nelms));
430 case ENCIOC_GETELMMAP:
431 for (uelm = addr, i = 0; i != cache->nelms; i++) {
432 encioc_element_t kelm;
434 kelm.elm_subenc_id = cache->elm_map[i].subenclosure;
435 kelm.elm_type = cache->elm_map[i].enctype;
436 error = copyout(&kelm, &uelm[i], sizeof(kelm));
442 case ENCIOC_GETENCSTAT:
443 cam_periph_lock(periph);
444 error = enc->enc_vec.get_enc_status(enc, 1);
446 cam_periph_unlock(periph);
449 tmp = cache->enc_status;
450 cam_periph_unlock(periph);
451 error = copyout(&tmp, addr, sizeof(tmp));
452 cache->enc_status = tmp;
455 case ENCIOC_SETENCSTAT:
456 error = copyin(addr, &tmp, sizeof(tmp));
459 cam_periph_lock(periph);
460 error = enc->enc_vec.set_enc_status(enc, tmp, 1);
461 cam_periph_unlock(periph);
464 case ENCIOC_GETSTRING:
465 case ENCIOC_SETSTRING:
466 case ENCIOC_GETENCNAME:
467 case ENCIOC_GETENCID:
468 if (enc->enc_vec.handle_string == NULL) {
472 error = copyin(addr, &sstr, sizeof(sstr));
475 cam_periph_lock(periph);
476 error = enc->enc_vec.handle_string(enc, &sstr, cmd);
477 cam_periph_unlock(periph);
480 case ENCIOC_GETELMSTAT:
481 error = copyin(addr, &elms, sizeof(elms));
484 if (elms.elm_idx >= cache->nelms) {
488 cam_periph_lock(periph);
489 error = enc->enc_vec.get_elm_status(enc, &elms, 1);
490 cam_periph_unlock(periph);
493 error = copyout(&elms, addr, sizeof(elms));
496 case ENCIOC_GETELMDESC:
497 error = copyin(addr, &elmd, sizeof(elmd));
500 if (elmd.elm_idx >= cache->nelms) {
504 if (enc->enc_vec.get_elm_desc != NULL) {
505 error = enc->enc_vec.get_elm_desc(enc, &elmd);
509 elmd.elm_desc_len = 0;
510 error = copyout(&elmd, addr, sizeof(elmd));
513 case ENCIOC_GETELMDEVNAMES:
514 if (enc->enc_vec.get_elm_devnames == NULL) {
518 error = copyin(addr, &elmdn, sizeof(elmdn));
521 if (elmdn.elm_idx >= cache->nelms) {
525 cam_periph_lock(periph);
526 error = (*enc->enc_vec.get_elm_devnames)(enc, &elmdn);
527 cam_periph_unlock(periph);
530 error = copyout(&elmdn, addr, sizeof(elmdn));
533 case ENCIOC_SETELMSTAT:
534 error = copyin(addr, &elms, sizeof(elms));
538 if (elms.elm_idx >= cache->nelms) {
542 cam_periph_lock(periph);
543 error = enc->enc_vec.set_elm_status(enc, &elms, 1);
544 cam_periph_unlock(periph);
550 cam_periph_lock(periph);
551 error = enc->enc_vec.init_enc(enc);
552 cam_periph_unlock(periph);
556 cam_periph_lock(periph);
557 error = cam_periph_ioctl(periph, cmd, arg_addr, enc_error);
558 cam_periph_unlock(periph);
561 sx_sunlock(&enc->enc_cache_lock);
566 enc_runcmd(struct enc_softc *enc, char *cdb, int cdbl, char *dptr, int *dlenp)
568 int error, dlen, tdlen;
572 CAM_DEBUG(enc->periph->path, CAM_DEBUG_TRACE,
573 ("entering enc_runcmd\n"));
575 if ((dlen = *dlenp) < 0) {
586 if (cdbl > IOCDBLEN) {
590 ccb = cam_periph_getccb(enc->periph, CAM_PRIORITY_NORMAL);
591 if (enc->enc_type == ENC_SEMB_SES || enc->enc_type == ENC_SEMB_SAFT) {
592 tdlen = min(dlen, 1020);
593 tdlen = (tdlen + 3) & ~3;
594 cam_fill_ataio(&ccb->ataio, 0, NULL, ddf, 0, dptr, tdlen,
596 if (cdb[0] == RECEIVE_DIAGNOSTIC)
597 ata_28bit_cmd(&ccb->ataio,
598 ATA_SEP_ATTN, cdb[2], 0x02, tdlen / 4);
599 else if (cdb[0] == SEND_DIAGNOSTIC)
600 ata_28bit_cmd(&ccb->ataio,
601 ATA_SEP_ATTN, dlen > 0 ? dptr[0] : 0,
603 else if (cdb[0] == READ_BUFFER)
604 ata_28bit_cmd(&ccb->ataio,
605 ATA_SEP_ATTN, cdb[2], 0x00, tdlen / 4);
607 ata_28bit_cmd(&ccb->ataio,
608 ATA_SEP_ATTN, dlen > 0 ? dptr[0] : 0,
612 cam_fill_csio(&ccb->csio, 0, NULL, ddf, MSG_SIMPLE_Q_TAG,
613 dptr, dlen, sizeof (struct scsi_sense_data), cdbl,
615 bcopy(cdb, ccb->csio.cdb_io.cdb_bytes, cdbl);
618 error = cam_periph_runccb(ccb, enc_error, ENC_CFLAGS, ENC_FLAGS, NULL);
625 if (ccb->ccb_h.func_code == XPT_ATA_IO)
626 *dlenp = ccb->ataio.resid;
628 *dlenp = ccb->csio.resid;
629 *dlenp += tdlen - dlen;
632 xpt_release_ccb(ccb);
633 CAM_DEBUG(enc->periph->path, CAM_DEBUG_SUBTRACE,
634 ("exiting enc_runcmd: *dlenp = %d\n", *dlenp));
639 enc_log(struct enc_softc *enc, const char *fmt, ...)
643 printf("%s%d: ", enc->periph->periph_name, enc->periph->unit_number);
650 * The code after this point runs on many platforms,
651 * so forgive the slightly awkward and nonconforming
656 * Is this a device that supports enclosure services?
658 * It's a pretty simple ruleset- if it is device type
659 * 0x0D (13), it's an ENCLOSURE device.
662 #define SAFTE_START 44
664 #define SAFTE_LEN SAFTE_END-SAFTE_START
667 enc_type(struct ccb_getdev *cgd)
672 if (cgd->protocol == PROTO_SEMB) {
673 iqd = (unsigned char *)&cgd->ident_data;
674 if (STRNCMP(iqd + 43, "S-E-S", 5) == 0)
675 return (ENC_SEMB_SES);
676 else if (STRNCMP(iqd + 43, "SAF-TE", 6) == 0)
677 return (ENC_SEMB_SAFT);
680 } else if (cgd->protocol != PROTO_SCSI)
683 iqd = (unsigned char *)&cgd->inq_data;
684 buflen = min(sizeof(cgd->inq_data),
685 SID_ADDITIONAL_LENGTH(&cgd->inq_data));
687 if ((iqd[0] & 0x1f) == T_ENCLOSURE) {
688 if ((iqd[2] & 0x7) > 2) {
691 return (ENC_SES_SCSI2);
696 #ifdef SES_ENABLE_PASSTHROUGH
697 if ((iqd[6] & 0x40) && (iqd[2] & 0x7) >= 2) {
699 * PassThrough Device.
701 return (ENC_SES_PASSTHROUGH);
706 * The comparison is short for a reason-
707 * some vendors were chopping it short.
710 if (buflen < SAFTE_END - 2) {
714 if (STRNCMP((char *)&iqd[SAFTE_START], "SAF-TE", SAFTE_LEN - 2) == 0) {
720 /*================== Enclosure Monitoring/Processing Daemon ==================*/
722 * \brief Queue an update request for a given action, if needed.
724 * \param enc SES softc to queue the request for.
725 * \param action Action requested.
728 enc_update_request(enc_softc_t *enc, uint32_t action)
730 if ((enc->pending_actions & (0x1 << action)) == 0) {
731 enc->pending_actions |= (0x1 << action);
732 ENC_DLOG(enc, "%s: queing requested action %d\n",
734 if (enc->current_action == ENC_UPDATE_NONE)
735 wakeup(enc->enc_daemon);
737 ENC_DLOG(enc, "%s: ignoring requested action %d - "
738 "Already queued\n", __func__, action);
743 * \brief Invoke the handler of the highest priority pending
744 * state in the SES state machine.
746 * \param enc The SES instance invoking the state machine.
749 enc_fsm_step(enc_softc_t *enc)
753 struct enc_fsm_state *cur_state;
757 ENC_DLOG(enc, "%s enter %p\n", __func__, enc);
759 enc->current_action = ffs(enc->pending_actions) - 1;
760 enc->pending_actions &= ~(0x1 << enc->current_action);
762 cur_state = &enc->enc_fsm_states[enc->current_action];
765 if (cur_state->buf_size != 0) {
766 cam_periph_unlock(enc->periph);
767 buf = malloc(cur_state->buf_size, M_SCSIENC, M_WAITOK|M_ZERO);
768 cam_periph_lock(enc->periph);
773 if (cur_state->fill != NULL) {
774 ccb = cam_periph_getccb(enc->periph, CAM_PRIORITY_NORMAL);
776 error = cur_state->fill(enc, cur_state, ccb, buf);
780 error = cam_periph_runccb(ccb, cur_state->error,
782 ENC_FLAGS|SF_QUIET_IR, NULL);
786 if (ccb->ccb_h.func_code == XPT_ATA_IO)
787 xfer_len = ccb->ataio.dxfer_len - ccb->ataio.resid;
789 xfer_len = ccb->csio.dxfer_len - ccb->csio.resid;
793 cam_periph_unlock(enc->periph);
794 cur_state->done(enc, cur_state, ccb, &buf, error, xfer_len);
795 cam_periph_lock(enc->periph);
798 ENC_DLOG(enc, "%s exit - result %d\n", __func__, error);
799 ENC_FREE_AND_NULL(buf);
801 xpt_release_ccb(ccb);
805 * \invariant Called with cam_periph mutex held.
808 enc_status_updater(void *arg)
813 if (enc->enc_vec.poll_status != NULL)
814 enc->enc_vec.poll_status(enc);
818 enc_daemon(void *arg)
824 cam_periph_lock(enc->periph);
825 while ((enc->enc_flags & ENC_FLAG_SHUTDOWN) == 0) {
826 if (enc->pending_actions == 0) {
827 struct intr_config_hook *hook;
830 * Reset callout and msleep, or
831 * issue timed task completion
834 enc->current_action = ENC_UPDATE_NONE;
837 * We've been through our state machine at least
838 * once. Allow the transition to userland.
840 hook = &enc->enc_boot_hold_ch;
841 if (hook->ich_func != NULL) {
842 config_intrhook_disestablish(hook);
843 hook->ich_func = NULL;
846 callout_reset(&enc->status_updater, 60*hz,
847 enc_status_updater, enc);
849 cam_periph_sleep(enc->periph, enc->enc_daemon,
855 enc->enc_daemon = NULL;
856 cam_periph_unlock(enc->periph);
857 cam_periph_release(enc->periph);
862 enc_kproc_init(enc_softc_t *enc)
866 callout_init_mtx(&enc->status_updater, cam_periph_mtx(enc->periph), 0);
868 if (cam_periph_acquire(enc->periph) != 0)
871 result = kproc_create(enc_daemon, enc, &enc->enc_daemon, /*flags*/0,
872 /*stackpgs*/0, "enc_daemon%d",
873 enc->periph->unit_number);
875 /* Do an initial load of all page data. */
876 cam_periph_lock(enc->periph);
877 enc->enc_vec.poll_status(enc);
878 cam_periph_unlock(enc->periph);
880 cam_periph_release(enc->periph);
885 * \brief Interrupt configuration hook callback associated with
888 * Since interrupts are always functional at the time of enclosure
889 * configuration, there is nothing to be done when the callback occurs.
890 * This hook is only registered to hold up boot processing while initial
891 * eclosure processing occurs.
893 * \param arg The enclosure softc, but currently unused in this callback.
896 enc_nop_confighook_cb(void *arg __unused)
901 enc_ctor(struct cam_periph *periph, void *arg)
903 cam_status status = CAM_REQ_CMP_ERR;
906 struct ccb_getdev *cgd;
908 struct make_dev_args args;
911 cgd = (struct ccb_getdev *)arg;
913 printf("enc_ctor: no getdev CCB, can't register device\n");
917 enc = ENC_MALLOCZ(sizeof(*enc));
919 printf("enc_ctor: Unable to probe new device. "
920 "Unable to allocate enc\n");
923 enc->periph = periph;
924 enc->current_action = ENC_UPDATE_INVALID;
926 enc->enc_type = enc_type(cgd);
927 sx_init(&enc->enc_cache_lock, "enccache");
929 switch (enc->enc_type) {
932 case ENC_SES_PASSTHROUGH:
934 err = ses_softc_init(enc);
938 err = safte_softc_init(enc);
943 return (CAM_REQ_CMP_ERR);
947 xpt_print(periph->path, "error %d initializing\n", err);
952 * Hold off userland until we have made at least one pass
953 * through our state machine so that physical path data is
956 if (enc->enc_vec.poll_status != NULL) {
957 enc->enc_boot_hold_ch.ich_func = enc_nop_confighook_cb;
958 enc->enc_boot_hold_ch.ich_arg = enc;
959 config_intrhook_establish(&enc->enc_boot_hold_ch);
963 * The softc field is set only once the enc is fully initialized
964 * so that we can rely on this field to detect partially
965 * initialized periph objects in the AC_FOUND_DEVICE handler.
969 cam_periph_unlock(periph);
970 if (enc->enc_vec.poll_status != NULL) {
971 err = enc_kproc_init(enc);
973 xpt_print(periph->path,
974 "error %d starting enc_daemon\n", err);
980 * Acquire a reference to the periph before we create the devfs
981 * instance for it. We'll release this reference once the devfs
982 * instance has been freed.
984 if (cam_periph_acquire(periph) != 0) {
985 xpt_print(periph->path, "%s: lost periph during "
986 "registration!\n", __func__);
987 cam_periph_lock(periph);
989 return (CAM_REQ_CMP_ERR);
992 make_dev_args_init(&args);
993 args.mda_devsw = &enc_cdevsw;
994 args.mda_unit = periph->unit_number;
995 args.mda_uid = UID_ROOT;
996 args.mda_gid = GID_OPERATOR;
997 args.mda_mode = 0600;
998 args.mda_si_drv1 = periph;
999 err = make_dev_s(&args, &enc->enc_dev, "%s%d", periph->periph_name,
1000 periph->unit_number);
1001 cam_periph_lock(periph);
1003 cam_periph_release_locked(periph);
1004 return (CAM_REQ_CMP_ERR);
1007 enc->enc_flags |= ENC_FLAG_INITIALIZED;
1010 * Add an async callback so that we get notified if this
1013 xpt_register_async(AC_LOST_DEVICE, enc_async, periph, periph->path);
1015 switch (enc->enc_type) {
1018 tname = "No ENC device";
1021 tname = "SCSI-2 ENC Device";
1024 tname = "SCSI-3 ENC Device";
1026 case ENC_SES_PASSTHROUGH:
1027 tname = "ENC Passthrough Device";
1030 tname = "SAF-TE Compliant Device";
1033 tname = "SEMB SES Device";
1036 tname = "SEMB SAF-TE Device";
1040 sbuf_new(&sb, enc->announce_buf, ENC_ANNOUNCE_SZ, SBUF_FIXEDLEN);
1041 xpt_announce_periph_sbuf(periph, &sb, tname);
1045 status = CAM_REQ_CMP;
1048 if (status != CAM_REQ_CMP)