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>
31 #include <sys/queue.h>
32 #include <sys/systm.h>
33 #include <sys/kernel.h>
34 #include <sys/types.h>
35 #include <sys/malloc.h>
36 #include <sys/fcntl.h>
38 #include <sys/errno.h>
39 #include <machine/stdarg.h>
42 #include <cam/cam_ccb.h>
43 #include <cam/cam_periph.h>
44 #include <cam/cam_xpt_periph.h>
45 #include <cam/cam_debug.h>
46 #include <cam/cam_sim.h>
48 #include <cam/scsi/scsi_all.h>
49 #include <cam/scsi/scsi_message.h>
50 #include <sys/ioccom.h>
51 #include <cam/scsi/scsi_ses.h>
55 MALLOC_DEFINE(M_SCSISES, "SCSI SES", "SCSI SES buffers");
58 * Platform Independent Driver Internal Definitions for SES devices.
70 typedef struct ses_softc ses_softc_t;
72 int (*softc_init)(ses_softc_t *, int);
73 int (*init_enc)(ses_softc_t *);
74 int (*get_encstat)(ses_softc_t *, int);
75 int (*set_encstat)(ses_softc_t *, ses_encstat, int);
76 int (*get_objstat)(ses_softc_t *, ses_objstat *, int);
77 int (*set_objstat)(ses_softc_t *, ses_objstat *, int);
80 #define ENCI_SVALID 0x80
84 enctype : 8, /* enclosure type */
85 subenclosure : 8, /* subenclosure id */
86 svalid : 1, /* enclosure information valid */
87 priv : 15; /* private data, per object */
88 uint8_t encstat[4]; /* state && stats */
91 #define SEN_ID "UNISYS SUN_SEN"
95 static enctyp ses_type(void *, int);
98 /* Forward reference to Enclosure Functions */
99 static int ses_softc_init(ses_softc_t *, int);
100 static int ses_init_enc(ses_softc_t *);
101 static int ses_get_encstat(ses_softc_t *, int);
102 static int ses_set_encstat(ses_softc_t *, uint8_t, int);
103 static int ses_get_objstat(ses_softc_t *, ses_objstat *, int);
104 static int ses_set_objstat(ses_softc_t *, ses_objstat *, int);
106 static int safte_softc_init(ses_softc_t *, int);
107 static int safte_init_enc(ses_softc_t *);
108 static int safte_get_encstat(ses_softc_t *, int);
109 static int safte_set_encstat(ses_softc_t *, uint8_t, int);
110 static int safte_get_objstat(ses_softc_t *, ses_objstat *, int);
111 static int safte_set_objstat(ses_softc_t *, ses_objstat *, int);
114 * Platform implementation defines/functions for SES internal kernel stuff
117 #define STRNCMP strncmp
118 #define PRINTF printf
119 #define SES_LOG ses_log
121 #define SES_DLOG ses_log
123 #define SES_DLOG if (0) ses_log
125 #define SES_VLOG if (bootverbose) ses_log
126 #define SES_MALLOC(amt) malloc(amt, M_SCSISES, M_NOWAIT)
127 #define SES_FREE(ptr, amt) free(ptr, M_SCSISES)
128 #define MEMZERO bzero
129 #define MEMCPY(dest, src, amt) bcopy(src, dest, amt)
131 static int ses_runcmd(struct ses_softc *, char *, int, char *, int *);
132 static void ses_log(struct ses_softc *, const char *, ...);
135 * Gerenal FreeBSD kernel stuff.
139 #define ccb_state ppriv_field0
140 #define ccb_bp ppriv_ptr1
143 enctyp ses_type; /* type of enclosure */
144 encvec ses_vec; /* vector to handlers */
145 void * ses_private; /* per-type private data */
146 encobj * ses_objmap; /* objects */
147 uint32_t ses_nobjects; /* number of objects */
148 ses_encstat ses_encstat; /* overall status */
150 union ccb ses_saved_ccb;
151 struct cdev *ses_dev;
152 struct cam_periph *periph;
154 #define SES_FLAG_INVALID 0x01
155 #define SES_FLAG_OPEN 0x02
156 #define SES_FLAG_INITIALIZED 0x04
158 #define SESUNIT(x) (minor((x)))
160 static d_open_t sesopen;
161 static d_close_t sesclose;
162 static d_ioctl_t sesioctl;
163 static periph_init_t sesinit;
164 static periph_ctor_t sesregister;
165 static periph_oninv_t sesoninvalidate;
166 static periph_dtor_t sescleanup;
167 static periph_start_t sesstart;
169 static void sesasync(void *, uint32_t, struct cam_path *, void *);
170 static void sesdone(struct cam_periph *, union ccb *);
171 static int seserror(union ccb *, uint32_t, uint32_t);
173 static struct periph_driver sesdriver = {
175 TAILQ_HEAD_INITIALIZER(sesdriver.units), /* generation */ 0
178 PERIPHDRIVER_DECLARE(ses, sesdriver);
180 static struct cdevsw ses_cdevsw = {
181 .d_version = D_VERSION,
195 * Install a global async callback. This callback will
196 * receive async callbacks like "new device found".
198 status = xpt_register_async(AC_FOUND_DEVICE, sesasync, NULL, NULL);
200 if (status != CAM_REQ_CMP) {
201 printf("ses: Failed to attach master async callback "
202 "due to status 0x%x!\n", status);
207 sesoninvalidate(struct cam_periph *periph)
209 struct ses_softc *softc;
211 softc = (struct ses_softc *)periph->softc;
214 * Unregister any async callbacks.
216 xpt_register_async(0, sesasync, periph, periph->path);
218 softc->ses_flags |= SES_FLAG_INVALID;
220 xpt_print(periph->path, "lost device\n");
224 sescleanup(struct cam_periph *periph)
226 struct ses_softc *softc;
228 softc = (struct ses_softc *)periph->softc;
230 xpt_print(periph->path, "removing device entry\n");
231 cam_periph_unlock(periph);
232 destroy_dev(softc->ses_dev);
233 cam_periph_lock(periph);
234 free(softc, M_SCSISES);
238 sesasync(void *callback_arg, uint32_t code, struct cam_path *path, void *arg)
240 struct cam_periph *periph;
242 periph = (struct cam_periph *)callback_arg;
245 case AC_FOUND_DEVICE:
248 struct ccb_getdev *cgd;
251 cgd = (struct ccb_getdev *)arg;
256 inq_len = cgd->inq_data.additional_length + 4;
259 * PROBLEM: WE NEED TO LOOK AT BYTES 48-53 TO SEE IF THIS IS
260 * PROBLEM: IS A SAF-TE DEVICE.
262 switch (ses_type(&cgd->inq_data, inq_len)) {
265 case SES_SES_PASSTHROUGH:
273 status = cam_periph_alloc(sesregister, sesoninvalidate,
274 sescleanup, sesstart, "ses", CAM_PERIPH_BIO,
275 cgd->ccb_h.path, sesasync, AC_FOUND_DEVICE, cgd);
277 if (status != CAM_REQ_CMP && status != CAM_REQ_INPROG) {
278 printf("sesasync: Unable to probe new device due to "
279 "status 0x%x\n", status);
284 cam_periph_async(periph, code, path, arg);
290 sesregister(struct cam_periph *periph, void *arg)
292 struct ses_softc *softc;
293 struct ccb_getdev *cgd;
296 cgd = (struct ccb_getdev *)arg;
297 if (periph == NULL) {
298 printf("sesregister: periph was NULL!!\n");
299 return (CAM_REQ_CMP_ERR);
303 printf("sesregister: no getdev CCB, can't register device\n");
304 return (CAM_REQ_CMP_ERR);
307 softc = SES_MALLOC(sizeof (struct ses_softc));
309 printf("sesregister: Unable to probe new device. "
310 "Unable to allocate softc\n");
311 return (CAM_REQ_CMP_ERR);
313 bzero(softc, sizeof (struct ses_softc));
314 periph->softc = softc;
315 softc->periph = periph;
317 softc->ses_type = ses_type(&cgd->inq_data, sizeof (cgd->inq_data));
319 switch (softc->ses_type) {
322 case SES_SES_PASSTHROUGH:
323 softc->ses_vec.softc_init = ses_softc_init;
324 softc->ses_vec.init_enc = ses_init_enc;
325 softc->ses_vec.get_encstat = ses_get_encstat;
326 softc->ses_vec.set_encstat = ses_set_encstat;
327 softc->ses_vec.get_objstat = ses_get_objstat;
328 softc->ses_vec.set_objstat = ses_set_objstat;
331 softc->ses_vec.softc_init = safte_softc_init;
332 softc->ses_vec.init_enc = safte_init_enc;
333 softc->ses_vec.get_encstat = safte_get_encstat;
334 softc->ses_vec.set_encstat = safte_set_encstat;
335 softc->ses_vec.get_objstat = safte_get_objstat;
336 softc->ses_vec.set_objstat = safte_set_objstat;
342 free(softc, M_SCSISES);
343 return (CAM_REQ_CMP_ERR);
346 cam_periph_unlock(periph);
347 softc->ses_dev = make_dev(&ses_cdevsw, unit2minor(periph->unit_number),
348 UID_ROOT, GID_OPERATOR, 0600, "%s%d",
349 periph->periph_name, periph->unit_number);
350 cam_periph_lock(periph);
351 softc->ses_dev->si_drv1 = periph;
354 * Add an async callback so that we get
355 * notified if this device goes away.
357 xpt_register_async(AC_LOST_DEVICE, sesasync, periph, periph->path);
359 switch (softc->ses_type) {
362 tname = "No SES device";
365 tname = "SCSI-2 SES Device";
368 tname = "SCSI-3 SES Device";
370 case SES_SES_PASSTHROUGH:
371 tname = "SES Passthrough Device";
374 tname = "UNISYS SEN Device (NOT HANDLED YET)";
377 tname = "SAF-TE Compliant Device";
380 xpt_announce_periph(periph, tname);
381 return (CAM_REQ_CMP);
385 sesopen(struct cdev *dev, int flags, int fmt, struct thread *td)
387 struct cam_periph *periph;
388 struct ses_softc *softc;
391 periph = (struct cam_periph *)dev->si_drv1;
392 if (periph == NULL) {
396 if (cam_periph_acquire(periph) != CAM_REQ_CMP) {
397 cam_periph_unlock(periph);
401 cam_periph_lock(periph);
403 softc = (struct ses_softc *)periph->softc;
405 if (softc->ses_flags & SES_FLAG_INVALID) {
409 if (softc->ses_flags & SES_FLAG_OPEN) {
413 if (softc->ses_vec.softc_init == NULL) {
418 softc->ses_flags |= SES_FLAG_OPEN;
419 if ((softc->ses_flags & SES_FLAG_INITIALIZED) == 0) {
420 error = (*softc->ses_vec.softc_init)(softc, 1);
422 softc->ses_flags &= ~SES_FLAG_OPEN;
424 softc->ses_flags |= SES_FLAG_INITIALIZED;
428 cam_periph_unlock(periph);
430 cam_periph_release(periph);
436 sesclose(struct cdev *dev, int flag, int fmt, struct thread *td)
438 struct cam_periph *periph;
439 struct ses_softc *softc;
444 periph = (struct cam_periph *)dev->si_drv1;
448 cam_periph_lock(periph);
450 softc = (struct ses_softc *)periph->softc;
451 softc->ses_flags &= ~SES_FLAG_OPEN;
453 cam_periph_unlock(periph);
454 cam_periph_release(periph);
460 sesstart(struct cam_periph *p, union ccb *sccb)
462 if (p->immediate_priority <= p->pinfo.priority) {
463 SLIST_INSERT_HEAD(&p->ccb_list, &sccb->ccb_h, periph_links.sle);
464 p->immediate_priority = CAM_PRIORITY_NONE;
465 wakeup(&p->ccb_list);
470 sesdone(struct cam_periph *periph, union ccb *dccb)
472 wakeup(&dccb->ccb_h.cbfcnp);
476 seserror(union ccb *ccb, uint32_t cflags, uint32_t sflags)
478 struct ses_softc *softc;
479 struct cam_periph *periph;
481 periph = xpt_path_periph(ccb->ccb_h.path);
482 softc = (struct ses_softc *)periph->softc;
484 return (cam_periph_error(ccb, cflags, sflags, &softc->ses_saved_ccb));
488 sesioctl(struct cdev *dev, u_long cmd, caddr_t arg_addr, int flag, struct thread *td)
490 struct cam_periph *periph;
494 struct ses_softc *ssc;
500 addr = *((caddr_t *) arg_addr);
504 periph = (struct cam_periph *)dev->si_drv1;
508 CAM_DEBUG(periph->path, CAM_DEBUG_TRACE, ("entering sesioctl\n"));
510 cam_periph_lock(periph);
511 ssc = (struct ses_softc *)periph->softc;
514 * Now check to see whether we're initialized or not.
515 * This actually should never fail as we're not supposed
516 * to get past ses_open w/o successfully initializing
519 if ((ssc->ses_flags & SES_FLAG_INITIALIZED) == 0) {
520 cam_periph_unlock(periph);
523 cam_periph_unlock(periph);
527 CAM_DEBUG(periph->path, CAM_DEBUG_TRACE,
528 ("trying to do ioctl %#lx\n", cmd));
531 * If this command can change the device's state,
532 * we must have the device open for writing.
534 * For commands that get information about the
535 * device- we don't need to lock the peripheral
536 * if we aren't running a command. The number
537 * of objects and the contents will stay stable
538 * after the first open that does initialization.
539 * The periph also can't go away while a user
540 * process has it open.
544 case SESIOC_GETOBJMAP:
545 case SESIOC_GETENCSTAT:
546 case SESIOC_GETOBJSTAT:
549 if ((flag & FWRITE) == 0) {
556 error = copyout(&ssc->ses_nobjects, addr,
557 sizeof (ssc->ses_nobjects));
560 case SESIOC_GETOBJMAP:
561 for (uobj = addr, i = 0; i != ssc->ses_nobjects; i++) {
564 kobj.subencid = ssc->ses_objmap[i].subenclosure;
565 kobj.object_type = ssc->ses_objmap[i].enctype;
566 error = copyout(&kobj, &uobj[i], sizeof (ses_object));
573 case SESIOC_GETENCSTAT:
574 cam_periph_lock(periph);
575 error = (*ssc->ses_vec.get_encstat)(ssc, 1);
577 cam_periph_unlock(periph);
580 tmp = ssc->ses_encstat & ~ENCI_SVALID;
581 cam_periph_unlock(periph);
582 error = copyout(&tmp, addr, sizeof (ses_encstat));
583 ssc->ses_encstat = tmp;
586 case SESIOC_SETENCSTAT:
587 error = copyin(addr, &tmp, sizeof (ses_encstat));
590 cam_periph_lock(periph);
591 error = (*ssc->ses_vec.set_encstat)(ssc, tmp, 1);
592 cam_periph_unlock(periph);
595 case SESIOC_GETOBJSTAT:
596 error = copyin(addr, &objs, sizeof (ses_objstat));
599 if (objs.obj_id >= ssc->ses_nobjects) {
603 cam_periph_lock(periph);
604 error = (*ssc->ses_vec.get_objstat)(ssc, &objs, 1);
605 cam_periph_unlock(periph);
608 error = copyout(&objs, addr, sizeof (ses_objstat));
610 * Always (for now) invalidate entry.
612 ssc->ses_objmap[objs.obj_id].svalid = 0;
615 case SESIOC_SETOBJSTAT:
616 error = copyin(addr, &objs, sizeof (ses_objstat));
620 if (objs.obj_id >= ssc->ses_nobjects) {
624 cam_periph_lock(periph);
625 error = (*ssc->ses_vec.set_objstat)(ssc, &objs, 1);
626 cam_periph_unlock(periph);
629 * Always (for now) invalidate entry.
631 ssc->ses_objmap[objs.obj_id].svalid = 0;
636 cam_periph_lock(periph);
637 error = (*ssc->ses_vec.init_enc)(ssc);
638 cam_periph_unlock(periph);
642 cam_periph_lock(periph);
643 error = cam_periph_ioctl(periph, cmd, arg_addr, seserror);
644 cam_periph_unlock(periph);
650 #define SES_CFLAGS CAM_RETRY_SELTO
651 #define SES_FLAGS SF_NO_PRINT | SF_RETRY_UA
653 ses_runcmd(struct ses_softc *ssc, char *cdb, int cdbl, char *dptr, int *dlenp)
660 if ((dlen = *dlenp) < 0) {
671 if (cdbl > IOCDBLEN) {
675 ccb = cam_periph_getccb(ssc->periph, 1);
676 cam_fill_csio(&ccb->csio, 0, sesdone, ddf, MSG_SIMPLE_Q_TAG, dptr,
677 dlen, sizeof (struct scsi_sense_data), cdbl, 60 * 1000);
678 bcopy(cdb, ccb->csio.cdb_io.cdb_bytes, cdbl);
680 error = cam_periph_runccb(ccb, seserror, SES_CFLAGS, SES_FLAGS, NULL);
681 if ((ccb->ccb_h.status & CAM_DEV_QFRZN) != 0)
682 cam_release_devq(ccb->ccb_h.path, 0, 0, 0, FALSE);
689 *dlenp = ccb->csio.resid;
692 xpt_release_ccb(ccb);
697 ses_log(struct ses_softc *ssc, const char *fmt, ...)
701 printf("%s%d: ", ssc->periph->periph_name, ssc->periph->unit_number);
708 * The code after this point runs on many platforms,
709 * so forgive the slightly awkward and nonconforming
714 * Is this a device that supports enclosure services?
716 * It's a a pretty simple ruleset- if it is device type 0x0D (13), it's
717 * an SES device. If it happens to be an old UNISYS SEN device, we can
721 #define SAFTE_START 44
723 #define SAFTE_LEN SAFTE_END-SAFTE_START
726 ses_type(void *buf, int buflen)
728 unsigned char *iqd = buf;
730 if (buflen < 8+SEN_ID_LEN)
733 if ((iqd[0] & 0x1f) == T_ENCLOSURE) {
734 if (STRNCMP(&iqd[8], SEN_ID, SEN_ID_LEN) == 0) {
736 } else if ((iqd[2] & 0x7) > 2) {
739 return (SES_SES_SCSI2);
744 #ifdef SES_ENABLE_PASSTHROUGH
745 if ((iqd[6] & 0x40) && (iqd[2] & 0x7) >= 2) {
747 * PassThrough Device.
749 return (SES_SES_PASSTHROUGH);
754 * The comparison is short for a reason-
755 * some vendors were chopping it short.
758 if (buflen < SAFTE_END - 2) {
762 if (STRNCMP((char *)&iqd[SAFTE_START], "SAF-TE", SAFTE_LEN - 2) == 0) {
769 * SES Native Type Device Support
773 * SES Diagnostic Page Codes
779 #define SesStatusPage SesControlPage
782 #define SesStringIn SesStringOut
784 #define SesThresholdIn SesThresholdOut
786 #define SesArrayStatus SesArrayControl
787 SesElementDescriptor,
796 * Minimum amount of data, starting from byte 0, to have
799 #define SES_CFGHDR_MINLEN 12
802 * Minimum amount of data, starting from byte 0, to have
803 * the config header and one enclosure header.
805 #define SES_ENCHDR_MINLEN 48
808 * Take this value, subtract it from VEnclen and you know
809 * the length of the vendor unique bytes.
811 #define SES_ENCHDR_VMIN 36
814 * SES Data Structures
818 uint32_t GenCode; /* Generation Code */
819 uint8_t Nsubenc; /* Number of Subenclosures */
823 uint8_t Subencid; /* SubEnclosure Identifier */
824 uint8_t Ntypes; /* # of supported types */
825 uint8_t VEnclen; /* Enclosure Descriptor Length */
829 uint8_t encWWN[8]; /* XXX- Not Right Yet */
837 uint8_t enc_type; /* type of element */
838 uint8_t enc_maxelt; /* maximum supported */
839 uint8_t enc_subenc; /* in SubEnc # N */
840 uint8_t enc_tlen; /* Type Descriptor Text Length */
854 uint8_t ses_ntypes; /* total number of types supported */
857 * We need to keep a type index as well as an
858 * object index for each object in an enclosure.
860 struct typidx *ses_typidx;
863 * We also need to keep track of the number of elements
864 * per type of element. This is needed later so that we
865 * can find precisely in the returned status data the
866 * status for the Nth element of the Kth type.
868 uint8_t * ses_eltmap;
873 * (de)canonicalization defines
875 #define sbyte(x, byte) ((((uint32_t)(x)) >> (byte * 8)) & 0xff)
876 #define sbit(x, bit) (((uint32_t)(x)) << bit)
877 #define sset8(outp, idx, sval) (((uint8_t *)(outp))[idx++]) = sbyte(sval, 0)
879 #define sset16(outp, idx, sval) \
880 (((uint8_t *)(outp))[idx++]) = sbyte(sval, 1), \
881 (((uint8_t *)(outp))[idx++]) = sbyte(sval, 0)
884 #define sset24(outp, idx, sval) \
885 (((uint8_t *)(outp))[idx++]) = sbyte(sval, 2), \
886 (((uint8_t *)(outp))[idx++]) = sbyte(sval, 1), \
887 (((uint8_t *)(outp))[idx++]) = sbyte(sval, 0)
890 #define sset32(outp, idx, sval) \
891 (((uint8_t *)(outp))[idx++]) = sbyte(sval, 3), \
892 (((uint8_t *)(outp))[idx++]) = sbyte(sval, 2), \
893 (((uint8_t *)(outp))[idx++]) = sbyte(sval, 1), \
894 (((uint8_t *)(outp))[idx++]) = sbyte(sval, 0)
896 #define gbyte(x, byte) ((((uint32_t)(x)) & 0xff) << (byte * 8))
897 #define gbit(lv, in, idx, shft, mask) lv = ((in[idx] >> shft) & mask)
898 #define sget8(inp, idx, lval) lval = (((uint8_t *)(inp))[idx++])
899 #define gget8(inp, idx, lval) lval = (((uint8_t *)(inp))[idx])
901 #define sget16(inp, idx, lval) \
902 lval = gbyte((((uint8_t *)(inp))[idx]), 1) | \
903 (((uint8_t *)(inp))[idx+1]), idx += 2
905 #define gget16(inp, idx, lval) \
906 lval = gbyte((((uint8_t *)(inp))[idx]), 1) | \
907 (((uint8_t *)(inp))[idx+1])
909 #define sget24(inp, idx, lval) \
910 lval = gbyte((((uint8_t *)(inp))[idx]), 2) | \
911 gbyte((((uint8_t *)(inp))[idx+1]), 1) | \
912 (((uint8_t *)(inp))[idx+2]), idx += 3
914 #define gget24(inp, idx, lval) \
915 lval = gbyte((((uint8_t *)(inp))[idx]), 2) | \
916 gbyte((((uint8_t *)(inp))[idx+1]), 1) | \
917 (((uint8_t *)(inp))[idx+2])
919 #define sget32(inp, idx, lval) \
920 lval = gbyte((((uint8_t *)(inp))[idx]), 3) | \
921 gbyte((((uint8_t *)(inp))[idx+1]), 2) | \
922 gbyte((((uint8_t *)(inp))[idx+2]), 1) | \
923 (((uint8_t *)(inp))[idx+3]), idx += 4
925 #define gget32(inp, idx, lval) \
926 lval = gbyte((((uint8_t *)(inp))[idx]), 3) | \
927 gbyte((((uint8_t *)(inp))[idx+1]), 2) | \
928 gbyte((((uint8_t *)(inp))[idx+2]), 1) | \
929 (((uint8_t *)(inp))[idx+3])
932 #define CFLEN (256 + SES_ENCHDR_MINLEN)
935 * Routines specific && private to SES only
938 static int ses_getconfig(ses_softc_t *);
939 static int ses_getputstat(ses_softc_t *, int, SesComStat *, int, int);
940 static int ses_cfghdr(uint8_t *, int, SesCfgHdr *);
941 static int ses_enchdr(uint8_t *, int, uint8_t, SesEncHdr *);
942 static int ses_encdesc(uint8_t *, int, uint8_t, SesEncDesc *);
943 static int ses_getthdr(uint8_t *, int, int, SesThdr *);
944 static int ses_decode(char *, int, uint8_t *, int, int, SesComStat *);
945 static int ses_encode(char *, int, uint8_t *, int, int, SesComStat *);
948 ses_softc_init(ses_softc_t *ssc, int doinit)
952 if (ssc->ses_nobjects) {
953 SES_FREE(ssc->ses_objmap,
954 ssc->ses_nobjects * sizeof (encobj));
955 ssc->ses_objmap = NULL;
957 if ((cc = ssc->ses_private) != NULL) {
958 if (cc->ses_eltmap && cc->ses_ntypes) {
959 SES_FREE(cc->ses_eltmap, cc->ses_ntypes);
960 cc->ses_eltmap = NULL;
963 if (cc->ses_typidx && ssc->ses_nobjects) {
964 SES_FREE(cc->ses_typidx,
965 ssc->ses_nobjects * sizeof (struct typidx));
966 cc->ses_typidx = NULL;
968 SES_FREE(cc, sizeof (struct sscfg));
969 ssc->ses_private = NULL;
971 ssc->ses_nobjects = 0;
974 if (ssc->ses_private == NULL) {
975 ssc->ses_private = SES_MALLOC(sizeof (struct sscfg));
977 if (ssc->ses_private == NULL) {
980 ssc->ses_nobjects = 0;
981 ssc->ses_encstat = 0;
982 return (ses_getconfig(ssc));
986 ses_init_enc(ses_softc_t *ssc)
992 ses_get_encstat(ses_softc_t *ssc, int slpflag)
997 if ((status = ses_getputstat(ssc, -1, &ComStat, slpflag, 1)) != 0) {
1000 ssc->ses_encstat = ComStat.comstatus | ENCI_SVALID;
1005 ses_set_encstat(ses_softc_t *ssc, uint8_t encstat, int slpflag)
1010 ComStat.comstatus = encstat & 0xf;
1011 if ((status = ses_getputstat(ssc, -1, &ComStat, slpflag, 0)) != 0) {
1014 ssc->ses_encstat = encstat & 0xf; /* note no SVALID set */
1019 ses_get_objstat(ses_softc_t *ssc, ses_objstat *obp, int slpflag)
1021 int i = (int)obp->obj_id;
1023 if (ssc->ses_objmap[i].svalid == 0) {
1025 int err = ses_getputstat(ssc, i, &ComStat, slpflag, 1);
1028 ssc->ses_objmap[i].encstat[0] = ComStat.comstatus;
1029 ssc->ses_objmap[i].encstat[1] = ComStat.comstat[0];
1030 ssc->ses_objmap[i].encstat[2] = ComStat.comstat[1];
1031 ssc->ses_objmap[i].encstat[3] = ComStat.comstat[2];
1032 ssc->ses_objmap[i].svalid = 1;
1034 obp->cstat[0] = ssc->ses_objmap[i].encstat[0];
1035 obp->cstat[1] = ssc->ses_objmap[i].encstat[1];
1036 obp->cstat[2] = ssc->ses_objmap[i].encstat[2];
1037 obp->cstat[3] = ssc->ses_objmap[i].encstat[3];
1042 ses_set_objstat(ses_softc_t *ssc, ses_objstat *obp, int slpflag)
1047 * If this is clear, we don't do diddly.
1049 if ((obp->cstat[0] & SESCTL_CSEL) == 0) {
1052 ComStat.comstatus = obp->cstat[0];
1053 ComStat.comstat[0] = obp->cstat[1];
1054 ComStat.comstat[1] = obp->cstat[2];
1055 ComStat.comstat[2] = obp->cstat[3];
1056 err = ses_getputstat(ssc, (int)obp->obj_id, &ComStat, slpflag, 0);
1057 ssc->ses_objmap[(int)obp->obj_id].svalid = 0;
1062 ses_getconfig(ses_softc_t *ssc)
1069 int err, amt, i, nobj, ntype, maxima;
1070 char storage[CFLEN], *sdata;
1071 static char cdb[6] = {
1072 RECEIVE_DIAGNOSTIC, 0x1, SesConfigPage, SCSZ >> 8, SCSZ & 0xff, 0
1075 cc = ssc->ses_private;
1080 sdata = SES_MALLOC(SCSZ);
1085 err = ses_runcmd(ssc, cdb, 6, sdata, &amt);
1087 SES_FREE(sdata, SCSZ);
1092 if (ses_cfghdr((uint8_t *) sdata, amt, &cf)) {
1093 SES_LOG(ssc, "Unable to parse SES Config Header\n");
1094 SES_FREE(sdata, SCSZ);
1097 if (amt < SES_ENCHDR_MINLEN) {
1098 SES_LOG(ssc, "runt enclosure length (%d)\n", amt);
1099 SES_FREE(sdata, SCSZ);
1103 SES_VLOG(ssc, "GenCode %x %d Subenclosures\n", cf.GenCode, cf.Nsubenc);
1106 * Now waltz through all the subenclosures toting up the
1107 * number of types available in each. For this, we only
1108 * really need the enclosure header. However, we get the
1109 * enclosure descriptor for debug purposes, as well
1110 * as self-consistency checking purposes.
1113 maxima = cf.Nsubenc + 1;
1114 cdp = (SesEncDesc *) storage;
1115 for (ntype = i = 0; i < maxima; i++) {
1116 MEMZERO((caddr_t)cdp, sizeof (*cdp));
1117 if (ses_enchdr((uint8_t *) sdata, amt, i, &hd)) {
1118 SES_LOG(ssc, "Cannot Extract Enclosure Header %d\n", i);
1119 SES_FREE(sdata, SCSZ);
1122 SES_VLOG(ssc, " SubEnclosure ID %d, %d Types With this ID, En"
1123 "closure Length %d\n", hd.Subencid, hd.Ntypes, hd.VEnclen);
1125 if (ses_encdesc((uint8_t *)sdata, amt, i, cdp)) {
1126 SES_LOG(ssc, "Can't get Enclosure Descriptor %d\n", i);
1127 SES_FREE(sdata, SCSZ);
1130 SES_VLOG(ssc, " WWN: %02x%02x%02x%02x%02x%02x%02x%02x\n",
1131 cdp->encWWN[0], cdp->encWWN[1], cdp->encWWN[2],
1132 cdp->encWWN[3], cdp->encWWN[4], cdp->encWWN[5],
1133 cdp->encWWN[6], cdp->encWWN[7]);
1138 * Now waltz through all the types that are available, getting
1139 * the type header so we can start adding up the number of
1140 * objects available.
1142 for (nobj = i = 0; i < ntype; i++) {
1143 if (ses_getthdr((uint8_t *)sdata, amt, i, &thdr)) {
1144 SES_LOG(ssc, "Can't get Enclosure Type Header %d\n", i);
1145 SES_FREE(sdata, SCSZ);
1148 SES_LOG(ssc, " Type Desc[%d]: Type 0x%x, MaxElt %d, In Subenc "
1149 "%d, Text Length %d\n", i, thdr.enc_type, thdr.enc_maxelt,
1150 thdr.enc_subenc, thdr.enc_tlen);
1151 nobj += thdr.enc_maxelt;
1156 * Now allocate the object array and type map.
1159 ssc->ses_objmap = SES_MALLOC(nobj * sizeof (encobj));
1160 cc->ses_typidx = SES_MALLOC(nobj * sizeof (struct typidx));
1161 cc->ses_eltmap = SES_MALLOC(ntype);
1163 if (ssc->ses_objmap == NULL || cc->ses_typidx == NULL ||
1164 cc->ses_eltmap == NULL) {
1165 if (ssc->ses_objmap) {
1166 SES_FREE(ssc->ses_objmap, (nobj * sizeof (encobj)));
1167 ssc->ses_objmap = NULL;
1169 if (cc->ses_typidx) {
1170 SES_FREE(cc->ses_typidx,
1171 (nobj * sizeof (struct typidx)));
1172 cc->ses_typidx = NULL;
1174 if (cc->ses_eltmap) {
1175 SES_FREE(cc->ses_eltmap, ntype);
1176 cc->ses_eltmap = NULL;
1178 SES_FREE(sdata, SCSZ);
1181 MEMZERO(ssc->ses_objmap, nobj * sizeof (encobj));
1182 MEMZERO(cc->ses_typidx, nobj * sizeof (struct typidx));
1183 MEMZERO(cc->ses_eltmap, ntype);
1184 cc->ses_ntypes = (uint8_t) ntype;
1185 ssc->ses_nobjects = nobj;
1188 * Now waltz through the # of types again to fill in the types
1189 * (and subenclosure ids) of the allocated objects.
1192 for (i = 0; i < ntype; i++) {
1194 if (ses_getthdr((uint8_t *)sdata, amt, i, &thdr)) {
1197 cc->ses_eltmap[i] = thdr.enc_maxelt;
1198 for (j = 0; j < thdr.enc_maxelt; j++) {
1199 cc->ses_typidx[nobj].ses_tidx = i;
1200 cc->ses_typidx[nobj].ses_oidx = j;
1201 ssc->ses_objmap[nobj].subenclosure = thdr.enc_subenc;
1202 ssc->ses_objmap[nobj++].enctype = thdr.enc_type;
1205 SES_FREE(sdata, SCSZ);
1210 ses_getputstat(ses_softc_t *ssc, int objid, SesComStat *sp, int slp, int in)
1213 int err, amt, bufsiz, tidx, oidx;
1214 char cdb[6], *sdata;
1216 cc = ssc->ses_private;
1222 * If we're just getting overall enclosure status,
1223 * we only need 2 bytes of data storage.
1225 * If we're getting anything else, we know how much
1226 * storage we need by noting that starting at offset
1227 * 8 in returned data, all object status bytes are 4
1228 * bytes long, and are stored in chunks of types(M)
1229 * and nth+1 instances of type M.
1234 bufsiz = (ssc->ses_nobjects * 4) + (cc->ses_ntypes * 4) + 8;
1236 sdata = SES_MALLOC(bufsiz);
1240 cdb[0] = RECEIVE_DIAGNOSTIC;
1242 cdb[2] = SesStatusPage;
1243 cdb[3] = bufsiz >> 8;
1244 cdb[4] = bufsiz & 0xff;
1247 err = ses_runcmd(ssc, cdb, 6, sdata, &amt);
1249 SES_FREE(sdata, bufsiz);
1258 tidx = cc->ses_typidx[objid].ses_tidx;
1259 oidx = cc->ses_typidx[objid].ses_oidx;
1262 if (ses_decode(sdata, amt, cc->ses_eltmap, tidx, oidx, sp)) {
1266 if (ses_encode(sdata, amt, cc->ses_eltmap, tidx, oidx, sp)) {
1269 cdb[0] = SEND_DIAGNOSTIC;
1272 cdb[3] = bufsiz >> 8;
1273 cdb[4] = bufsiz & 0xff;
1276 err = ses_runcmd(ssc, cdb, 6, sdata, &amt);
1279 SES_FREE(sdata, bufsiz);
1285 * Routines to parse returned SES data structures.
1286 * Architecture and compiler independent.
1290 ses_cfghdr(uint8_t *buffer, int buflen, SesCfgHdr *cfp)
1292 if (buflen < SES_CFGHDR_MINLEN) {
1295 gget8(buffer, 1, cfp->Nsubenc);
1296 gget32(buffer, 4, cfp->GenCode);
1301 ses_enchdr(uint8_t *buffer, int amt, uint8_t SubEncId, SesEncHdr *chp)
1304 for (s = 0; s < SubEncId; s++) {
1307 off += buffer[off+3] + 4;
1309 if (off + 3 > amt) {
1312 gget8(buffer, off+1, chp->Subencid);
1313 gget8(buffer, off+2, chp->Ntypes);
1314 gget8(buffer, off+3, chp->VEnclen);
1319 ses_encdesc(uint8_t *buffer, int amt, uint8_t SubEncId, SesEncDesc *cdp)
1321 int s, e, enclen, off = 8;
1322 for (s = 0; s < SubEncId; s++) {
1325 off += buffer[off+3] + 4;
1327 if (off + 3 > amt) {
1330 gget8(buffer, off+3, enclen);
1339 MEMCPY(cdp, &buffer[off], e - off);
1344 ses_getthdr(uint8_t *buffer, int amt, int nth, SesThdr *thp)
1348 if (amt < SES_CFGHDR_MINLEN) {
1351 for (s = 0; s < buffer[1]; s++) {
1354 off += buffer[off+3] + 4;
1356 if (off + 3 > amt) {
1359 off += buffer[off+3] + 4 + (nth * 4);
1360 if (amt < (off + 4))
1363 gget8(buffer, off++, thp->enc_type);
1364 gget8(buffer, off++, thp->enc_maxelt);
1365 gget8(buffer, off++, thp->enc_subenc);
1366 gget8(buffer, off, thp->enc_tlen);
1371 * This function needs a little explanation.
1373 * The arguments are:
1378 * These describes the raw input SES status data and length.
1382 * This is a map of the number of types for each element type
1387 * This is the element type being sought. If elt is -1,
1388 * then overall enclosure status is being sought.
1392 * This is the ordinal Mth element of type elt being sought.
1396 * This is the output area to store the status for
1397 * the Mth element of type Elt.
1401 ses_decode(char *b, int amt, uint8_t *ep, int elt, int elm, SesComStat *sp)
1406 * If it's overall enclosure status being sought, get that.
1407 * We need at least 2 bytes of status data to get that.
1412 gget8(b, 1, sp->comstatus);
1420 * Check to make sure that the Mth element is legal for type Elt.
1427 * Starting at offset 8, start skipping over the storage
1428 * for the element types we're not interested in.
1430 for (idx = 8, i = 0; i < elt; i++) {
1431 idx += ((ep[i] + 1) * 4);
1435 * Skip over Overall status for this element type.
1440 * And skip to the index for the Mth element that we're going for.
1445 * Make sure we haven't overflowed the buffer.
1451 * Retrieve the status.
1453 gget8(b, idx++, sp->comstatus);
1454 gget8(b, idx++, sp->comstat[0]);
1455 gget8(b, idx++, sp->comstat[1]);
1456 gget8(b, idx++, sp->comstat[2]);
1458 PRINTF("Get Elt 0x%x Elm 0x%x (idx %d)\n", elt, elm, idx-4);
1464 * This is the mirror function to ses_decode, but we set the 'select'
1465 * bit for the object which we're interested in. All other objects,
1466 * after a status fetch, should have that bit off. Hmm. It'd be easy
1467 * enough to ensure this, so we will.
1471 ses_encode(char *b, int amt, uint8_t *ep, int elt, int elm, SesComStat *sp)
1476 * If it's overall enclosure status being sought, get that.
1477 * We need at least 2 bytes of status data to get that.
1484 sset8(b, i, sp->comstatus & 0xf);
1486 PRINTF("set EncStat %x\n", sp->comstatus);
1492 * Check to make sure that the Mth element is legal for type Elt.
1499 * Starting at offset 8, start skipping over the storage
1500 * for the element types we're not interested in.
1502 for (idx = 8, i = 0; i < elt; i++) {
1503 idx += ((ep[i] + 1) * 4);
1507 * Skip over Overall status for this element type.
1512 * And skip to the index for the Mth element that we're going for.
1517 * Make sure we haven't overflowed the buffer.
1525 sset8(b, idx, sp->comstatus);
1526 sset8(b, idx, sp->comstat[0]);
1527 sset8(b, idx, sp->comstat[1]);
1528 sset8(b, idx, sp->comstat[2]);
1532 PRINTF("Set Elt 0x%x Elm 0x%x (idx %d) with %x %x %x %x\n",
1533 elt, elm, idx, sp->comstatus, sp->comstat[0],
1534 sp->comstat[1], sp->comstat[2]);
1538 * Now make sure all other 'Select' bits are off.
1540 for (i = 8; i < amt; i += 4) {
1545 * And make sure the INVOP bit is clear.
1553 * SAF-TE Type Device Emulation
1556 static int safte_getconfig(ses_softc_t *);
1557 static int safte_rdstat(ses_softc_t *, int);;
1558 static int set_objstat_sel(ses_softc_t *, ses_objstat *, int);
1559 static int wrbuf16(ses_softc_t *, uint8_t, uint8_t, uint8_t, uint8_t, int);
1560 static void wrslot_stat(ses_softc_t *, int);
1561 static int perf_slotop(ses_softc_t *, uint8_t, uint8_t, int);
1563 #define ALL_ENC_STAT (SES_ENCSTAT_CRITICAL | SES_ENCSTAT_UNRECOV | \
1564 SES_ENCSTAT_NONCRITICAL | SES_ENCSTAT_INFO)
1566 * SAF-TE specific defines- Mandatory ones only...
1570 * READ BUFFER ('get' commands) IDs- placed in offset 2 of cdb
1572 #define SAFTE_RD_RDCFG 0x00 /* read enclosure configuration */
1573 #define SAFTE_RD_RDESTS 0x01 /* read enclosure status */
1574 #define SAFTE_RD_RDDSTS 0x04 /* read drive slot status */
1577 * WRITE BUFFER ('set' commands) IDs- placed in offset 0 of databuf
1579 #define SAFTE_WT_DSTAT 0x10 /* write device slot status */
1580 #define SAFTE_WT_SLTOP 0x12 /* perform slot operation */
1581 #define SAFTE_WT_FANSPD 0x13 /* set fan speed */
1582 #define SAFTE_WT_ACTPWS 0x14 /* turn on/off power supply */
1583 #define SAFTE_WT_GLOBAL 0x15 /* send global command */
1586 #define SAFT_SCRATCH 64
1587 #define NPSEUDO_THERM 16
1588 #define NPSEUDO_ALARM 1
1591 * Cached Configuration
1593 uint8_t Nfans; /* Number of Fans */
1594 uint8_t Npwr; /* Number of Power Supplies */
1595 uint8_t Nslots; /* Number of Device Slots */
1596 uint8_t DoorLock; /* Door Lock Installed */
1597 uint8_t Ntherm; /* Number of Temperature Sensors */
1598 uint8_t Nspkrs; /* Number of Speakers */
1599 uint8_t Nalarm; /* Number of Alarms (at least one) */
1601 * Cached Flag Bytes for Global Status
1606 * What object index ID is where various slots start.
1610 #define SAFT_ALARM_OFFSET(cc) (cc)->slotoff - 1
1613 #define SAFT_FLG1_ALARM 0x1
1614 #define SAFT_FLG1_GLOBFAIL 0x2
1615 #define SAFT_FLG1_GLOBWARN 0x4
1616 #define SAFT_FLG1_ENCPWROFF 0x8
1617 #define SAFT_FLG1_ENCFANFAIL 0x10
1618 #define SAFT_FLG1_ENCPWRFAIL 0x20
1619 #define SAFT_FLG1_ENCDRVFAIL 0x40
1620 #define SAFT_FLG1_ENCDRVWARN 0x80
1622 #define SAFT_FLG2_LOCKDOOR 0x4
1623 #define SAFT_PRIVATE sizeof (struct scfg)
1625 static char *safte_2little = "Too Little Data Returned (%d) at line %d\n";
1626 #define SAFT_BAIL(r, x, k, l) \
1628 SES_LOG(ssc, safte_2little, x, __LINE__);\
1629 SES_FREE((k), (l)); \
1635 safte_softc_init(ses_softc_t *ssc, int doinit)
1641 if (ssc->ses_nobjects) {
1642 if (ssc->ses_objmap) {
1643 SES_FREE(ssc->ses_objmap,
1644 ssc->ses_nobjects * sizeof (encobj));
1645 ssc->ses_objmap = NULL;
1647 ssc->ses_nobjects = 0;
1649 if (ssc->ses_private) {
1650 SES_FREE(ssc->ses_private, SAFT_PRIVATE);
1651 ssc->ses_private = NULL;
1656 if (ssc->ses_private == NULL) {
1657 ssc->ses_private = SES_MALLOC(SAFT_PRIVATE);
1658 if (ssc->ses_private == NULL) {
1661 MEMZERO(ssc->ses_private, SAFT_PRIVATE);
1664 ssc->ses_nobjects = 0;
1665 ssc->ses_encstat = 0;
1667 if ((err = safte_getconfig(ssc)) != 0) {
1672 * The number of objects here, as well as that reported by the
1673 * READ_BUFFER/GET_CONFIG call, are the over-temperature flags (15)
1674 * that get reported during READ_BUFFER/READ_ENC_STATUS.
1676 cc = ssc->ses_private;
1677 ssc->ses_nobjects = cc->Nfans + cc->Npwr + cc->Nslots + cc->DoorLock +
1678 cc->Ntherm + cc->Nspkrs + NPSEUDO_THERM + NPSEUDO_ALARM;
1679 ssc->ses_objmap = (encobj *)
1680 SES_MALLOC(ssc->ses_nobjects * sizeof (encobj));
1681 if (ssc->ses_objmap == NULL) {
1684 MEMZERO(ssc->ses_objmap, ssc->ses_nobjects * sizeof (encobj));
1688 * Note that this is all arranged for the convenience
1689 * in later fetches of status.
1691 for (i = 0; i < cc->Nfans; i++)
1692 ssc->ses_objmap[r++].enctype = SESTYP_FAN;
1693 cc->pwroff = (uint8_t) r;
1694 for (i = 0; i < cc->Npwr; i++)
1695 ssc->ses_objmap[r++].enctype = SESTYP_POWER;
1696 for (i = 0; i < cc->DoorLock; i++)
1697 ssc->ses_objmap[r++].enctype = SESTYP_DOORLOCK;
1698 for (i = 0; i < cc->Nspkrs; i++)
1699 ssc->ses_objmap[r++].enctype = SESTYP_ALARM;
1700 for (i = 0; i < cc->Ntherm; i++)
1701 ssc->ses_objmap[r++].enctype = SESTYP_THERM;
1702 for (i = 0; i < NPSEUDO_THERM; i++)
1703 ssc->ses_objmap[r++].enctype = SESTYP_THERM;
1704 ssc->ses_objmap[r++].enctype = SESTYP_ALARM;
1705 cc->slotoff = (uint8_t) r;
1706 for (i = 0; i < cc->Nslots; i++)
1707 ssc->ses_objmap[r++].enctype = SESTYP_DEVICE;
1712 safte_init_enc(ses_softc_t *ssc)
1715 static char cdb0[6] = { SEND_DIAGNOSTIC };
1717 err = ses_runcmd(ssc, cdb0, 6, NULL, 0);
1722 err = wrbuf16(ssc, SAFTE_WT_GLOBAL, 0, 0, 0, 1);
1727 safte_get_encstat(ses_softc_t *ssc, int slpflg)
1729 return (safte_rdstat(ssc, slpflg));
1733 safte_set_encstat(ses_softc_t *ssc, uint8_t encstat, int slpflg)
1735 struct scfg *cc = ssc->ses_private;
1739 * Since SAF-TE devices aren't necessarily sticky in terms
1740 * of state, make our soft copy of enclosure status 'sticky'-
1741 * that is, things set in enclosure status stay set (as implied
1742 * by conditions set in reading object status) until cleared.
1744 ssc->ses_encstat &= ~ALL_ENC_STAT;
1745 ssc->ses_encstat |= (encstat & ALL_ENC_STAT);
1746 ssc->ses_encstat |= ENCI_SVALID;
1747 cc->flag1 &= ~(SAFT_FLG1_ALARM|SAFT_FLG1_GLOBFAIL|SAFT_FLG1_GLOBWARN);
1748 if ((encstat & (SES_ENCSTAT_CRITICAL|SES_ENCSTAT_UNRECOV)) != 0) {
1749 cc->flag1 |= SAFT_FLG1_ALARM|SAFT_FLG1_GLOBFAIL;
1750 } else if ((encstat & SES_ENCSTAT_NONCRITICAL) != 0) {
1751 cc->flag1 |= SAFT_FLG1_GLOBWARN;
1753 return (wrbuf16(ssc, SAFTE_WT_GLOBAL, cc->flag1, cc->flag2, 0, slpflg));
1757 safte_get_objstat(ses_softc_t *ssc, ses_objstat *obp, int slpflg)
1759 int i = (int)obp->obj_id;
1761 if ((ssc->ses_encstat & ENCI_SVALID) == 0 ||
1762 (ssc->ses_objmap[i].svalid) == 0) {
1763 int err = safte_rdstat(ssc, slpflg);
1767 obp->cstat[0] = ssc->ses_objmap[i].encstat[0];
1768 obp->cstat[1] = ssc->ses_objmap[i].encstat[1];
1769 obp->cstat[2] = ssc->ses_objmap[i].encstat[2];
1770 obp->cstat[3] = ssc->ses_objmap[i].encstat[3];
1776 safte_set_objstat(ses_softc_t *ssc, ses_objstat *obp, int slp)
1783 SES_DLOG(ssc, "safte_set_objstat(%d): %x %x %x %x\n",
1784 (int)obp->obj_id, obp->cstat[0], obp->cstat[1], obp->cstat[2],
1788 * If this is clear, we don't do diddly.
1790 if ((obp->cstat[0] & SESCTL_CSEL) == 0) {
1796 * Check to see if the common bits are set and do them first.
1798 if (obp->cstat[0] & ~SESCTL_CSEL) {
1799 err = set_objstat_sel(ssc, obp, slp);
1804 cc = ssc->ses_private;
1808 idx = (int)obp->obj_id;
1809 ep = &ssc->ses_objmap[idx];
1811 switch (ep->enctype) {
1816 * XXX: I should probably cache the previous state
1817 * XXX: of SESCTL_DEVOFF so that when it goes from
1818 * XXX: true to false I can then set PREPARE FOR OPERATION
1819 * XXX: flag in PERFORM SLOT OPERATION write buffer command.
1821 if (obp->cstat[2] & (SESCTL_RQSINS|SESCTL_RQSRMV)) {
1824 if (obp->cstat[2] & SESCTL_RQSID) {
1827 err = perf_slotop(ssc, (uint8_t) idx - (uint8_t) cc->slotoff,
1831 if (obp->cstat[3] & SESCTL_RQSFLT) {
1836 if (ep->priv & 0xc6) {
1839 ep->priv |= 0x1; /* no errors */
1841 wrslot_stat(ssc, slp);
1845 if (obp->cstat[3] & SESCTL_RQSTFAIL) {
1846 cc->flag1 |= SAFT_FLG1_ENCPWRFAIL;
1848 cc->flag1 &= ~SAFT_FLG1_ENCPWRFAIL;
1850 err = wrbuf16(ssc, SAFTE_WT_GLOBAL, cc->flag1,
1854 if (obp->cstat[3] & SESCTL_RQSTON) {
1855 (void) wrbuf16(ssc, SAFTE_WT_ACTPWS,
1856 idx - cc->pwroff, 0, 0, slp);
1858 (void) wrbuf16(ssc, SAFTE_WT_ACTPWS,
1859 idx - cc->pwroff, 0, 1, slp);
1863 if (obp->cstat[3] & SESCTL_RQSTFAIL) {
1864 cc->flag1 |= SAFT_FLG1_ENCFANFAIL;
1866 cc->flag1 &= ~SAFT_FLG1_ENCFANFAIL;
1868 err = wrbuf16(ssc, SAFTE_WT_GLOBAL, cc->flag1,
1872 if (obp->cstat[3] & SESCTL_RQSTON) {
1874 if ((obp->cstat[3] & 0x7) == 7) {
1876 } else if ((obp->cstat[3] & 0x7) == 6) {
1878 } else if ((obp->cstat[3] & 0x7) == 4) {
1883 (void) wrbuf16(ssc, SAFTE_WT_FANSPD, idx, fsp, 0, slp);
1885 (void) wrbuf16(ssc, SAFTE_WT_FANSPD, idx, 0, 0, slp);
1888 case SESTYP_DOORLOCK:
1889 if (obp->cstat[3] & 0x1) {
1890 cc->flag2 &= ~SAFT_FLG2_LOCKDOOR;
1892 cc->flag2 |= SAFT_FLG2_LOCKDOOR;
1894 (void) wrbuf16(ssc, SAFTE_WT_GLOBAL, cc->flag1,
1899 * On all nonzero but the 'muted' bit, we turn on the alarm,
1901 obp->cstat[3] &= ~0xa;
1902 if (obp->cstat[3] & 0x40) {
1903 cc->flag2 &= ~SAFT_FLG1_ALARM;
1904 } else if (obp->cstat[3] != 0) {
1905 cc->flag2 |= SAFT_FLG1_ALARM;
1907 cc->flag2 &= ~SAFT_FLG1_ALARM;
1909 ep->priv = obp->cstat[3];
1910 (void) wrbuf16(ssc, SAFTE_WT_GLOBAL, cc->flag1,
1921 safte_getconfig(ses_softc_t *ssc)
1926 static char cdb[10] =
1927 { READ_BUFFER, 1, SAFTE_RD_RDCFG, 0, 0, 0, 0, 0, SAFT_SCRATCH, 0 };
1929 cfg = ssc->ses_private;
1933 sdata = SES_MALLOC(SAFT_SCRATCH);
1938 err = ses_runcmd(ssc, cdb, 10, sdata, &amt);
1940 SES_FREE(sdata, SAFT_SCRATCH);
1943 amt = SAFT_SCRATCH - amt;
1945 SES_LOG(ssc, "too little data (%d) for configuration\n", amt);
1946 SES_FREE(sdata, SAFT_SCRATCH);
1949 SES_VLOG(ssc, "Nfans %d Npwr %d Nslots %d Lck %d Ntherm %d Nspkrs %d\n",
1950 sdata[0], sdata[1], sdata[2], sdata[3], sdata[4], sdata[5]);
1951 cfg->Nfans = sdata[0];
1952 cfg->Npwr = sdata[1];
1953 cfg->Nslots = sdata[2];
1954 cfg->DoorLock = sdata[3];
1955 cfg->Ntherm = sdata[4];
1956 cfg->Nspkrs = sdata[5];
1957 cfg->Nalarm = NPSEUDO_ALARM;
1958 SES_FREE(sdata, SAFT_SCRATCH);
1963 safte_rdstat(ses_softc_t *ssc, int slpflg)
1965 int err, oid, r, i, hiwater, nitems, amt;
1968 uint8_t status, oencstat;
1969 char *sdata, cdb[10];
1970 struct scfg *cc = ssc->ses_private;
1974 * The number of objects overstates things a bit,
1975 * both for the bogus 'thermometer' entries and
1976 * the drive status (which isn't read at the same
1977 * time as the enclosure status), but that's okay.
1979 buflen = 4 * cc->Nslots;
1980 if (ssc->ses_nobjects > buflen)
1981 buflen = ssc->ses_nobjects;
1982 sdata = SES_MALLOC(buflen);
1986 cdb[0] = READ_BUFFER;
1988 cdb[2] = SAFTE_RD_RDESTS;
1993 cdb[7] = (buflen >> 8) & 0xff;
1994 cdb[8] = buflen & 0xff;
1997 err = ses_runcmd(ssc, cdb, 10, sdata, &amt);
1999 SES_FREE(sdata, buflen);
2002 hiwater = buflen - amt;
2006 * invalidate all status bits.
2008 for (i = 0; i < ssc->ses_nobjects; i++)
2009 ssc->ses_objmap[i].svalid = 0;
2010 oencstat = ssc->ses_encstat & ALL_ENC_STAT;
2011 ssc->ses_encstat = 0;
2015 * Now parse returned buffer.
2016 * If we didn't get enough data back,
2017 * that's considered a fatal error.
2021 for (nitems = i = 0; i < cc->Nfans; i++) {
2022 SAFT_BAIL(r, hiwater, sdata, buflen);
2024 * 0 = Fan Operational
2025 * 1 = Fan is malfunctioning
2026 * 2 = Fan is not present
2027 * 0x80 = Unknown or Not Reportable Status
2029 ssc->ses_objmap[oid].encstat[1] = 0; /* resvd */
2030 ssc->ses_objmap[oid].encstat[2] = 0; /* resvd */
2031 switch ((int)(uint8_t)sdata[r]) {
2034 ssc->ses_objmap[oid].encstat[0] = SES_OBJSTAT_OK;
2036 * We could get fancier and cache
2037 * fan speeds that we have set, but
2038 * that isn't done now.
2040 ssc->ses_objmap[oid].encstat[3] = 7;
2044 ssc->ses_objmap[oid].encstat[0] = SES_OBJSTAT_CRIT;
2046 * FAIL and FAN STOPPED synthesized
2048 ssc->ses_objmap[oid].encstat[3] = 0x40;
2050 * Enclosure marked with CRITICAL error
2051 * if only one fan or no thermometers,
2052 * else the NONCRITICAL error is set.
2054 if (cc->Nfans == 1 || cc->Ntherm == 0)
2055 ssc->ses_encstat |= SES_ENCSTAT_CRITICAL;
2057 ssc->ses_encstat |= SES_ENCSTAT_NONCRITICAL;
2060 ssc->ses_objmap[oid].encstat[0] =
2061 SES_OBJSTAT_NOTINSTALLED;
2062 ssc->ses_objmap[oid].encstat[3] = 0;
2064 * Enclosure marked with CRITICAL error
2065 * if only one fan or no thermometers,
2066 * else the NONCRITICAL error is set.
2069 ssc->ses_encstat |= SES_ENCSTAT_CRITICAL;
2071 ssc->ses_encstat |= SES_ENCSTAT_NONCRITICAL;
2074 ssc->ses_objmap[oid].encstat[0] = SES_OBJSTAT_UNKNOWN;
2075 ssc->ses_objmap[oid].encstat[3] = 0;
2076 ssc->ses_encstat |= SES_ENCSTAT_INFO;
2079 ssc->ses_objmap[oid].encstat[0] =
2080 SES_OBJSTAT_UNSUPPORTED;
2081 SES_LOG(ssc, "Unknown fan%d status 0x%x\n", i,
2085 ssc->ses_objmap[oid++].svalid = 1;
2090 * No matter how you cut it, no cooling elements when there
2091 * should be some there is critical.
2093 if (cc->Nfans && nitems == 0) {
2094 ssc->ses_encstat |= SES_ENCSTAT_CRITICAL;
2098 for (i = 0; i < cc->Npwr; i++) {
2099 SAFT_BAIL(r, hiwater, sdata, buflen);
2100 ssc->ses_objmap[oid].encstat[0] = SES_OBJSTAT_UNKNOWN;
2101 ssc->ses_objmap[oid].encstat[1] = 0; /* resvd */
2102 ssc->ses_objmap[oid].encstat[2] = 0; /* resvd */
2103 ssc->ses_objmap[oid].encstat[3] = 0x20; /* requested on */
2104 switch ((uint8_t)sdata[r]) {
2105 case 0x00: /* pws operational and on */
2106 ssc->ses_objmap[oid].encstat[0] = SES_OBJSTAT_OK;
2108 case 0x01: /* pws operational and off */
2109 ssc->ses_objmap[oid].encstat[0] = SES_OBJSTAT_OK;
2110 ssc->ses_objmap[oid].encstat[3] = 0x10;
2111 ssc->ses_encstat |= SES_ENCSTAT_INFO;
2113 case 0x10: /* pws is malfunctioning and commanded on */
2114 ssc->ses_objmap[oid].encstat[0] = SES_OBJSTAT_CRIT;
2115 ssc->ses_objmap[oid].encstat[3] = 0x61;
2116 ssc->ses_encstat |= SES_ENCSTAT_NONCRITICAL;
2119 case 0x11: /* pws is malfunctioning and commanded off */
2120 ssc->ses_objmap[oid].encstat[0] = SES_OBJSTAT_NONCRIT;
2121 ssc->ses_objmap[oid].encstat[3] = 0x51;
2122 ssc->ses_encstat |= SES_ENCSTAT_NONCRITICAL;
2124 case 0x20: /* pws is not present */
2125 ssc->ses_objmap[oid].encstat[0] =
2126 SES_OBJSTAT_NOTINSTALLED;
2127 ssc->ses_objmap[oid].encstat[3] = 0;
2128 ssc->ses_encstat |= SES_ENCSTAT_INFO;
2130 case 0x21: /* pws is present */
2132 * This is for enclosures that cannot tell whether the
2133 * device is on or malfunctioning, but know that it is
2134 * present. Just fall through.
2137 case 0x80: /* Unknown or Not Reportable Status */
2138 ssc->ses_objmap[oid].encstat[0] = SES_OBJSTAT_UNKNOWN;
2139 ssc->ses_objmap[oid].encstat[3] = 0;
2140 ssc->ses_encstat |= SES_ENCSTAT_INFO;
2143 SES_LOG(ssc, "unknown power supply %d status (0x%x)\n",
2144 i, sdata[r] & 0xff);
2147 ssc->ses_objmap[oid++].svalid = 1;
2152 * Skip over Slot SCSI IDs
2157 * We always have doorlock status, no matter what,
2158 * but we only save the status if we have one.
2160 SAFT_BAIL(r, hiwater, sdata, buflen);
2164 * 1 = Door Unlocked, or no Lock Installed
2165 * 0x80 = Unknown or Not Reportable Status
2167 ssc->ses_objmap[oid].encstat[1] = 0;
2168 ssc->ses_objmap[oid].encstat[2] = 0;
2169 switch ((uint8_t)sdata[r]) {
2171 ssc->ses_objmap[oid].encstat[0] = SES_OBJSTAT_OK;
2172 ssc->ses_objmap[oid].encstat[3] = 0;
2175 ssc->ses_objmap[oid].encstat[0] = SES_OBJSTAT_OK;
2176 ssc->ses_objmap[oid].encstat[3] = 1;
2179 ssc->ses_objmap[oid].encstat[0] = SES_OBJSTAT_UNKNOWN;
2180 ssc->ses_objmap[oid].encstat[3] = 0;
2181 ssc->ses_encstat |= SES_ENCSTAT_INFO;
2184 ssc->ses_objmap[oid].encstat[0] =
2185 SES_OBJSTAT_UNSUPPORTED;
2186 SES_LOG(ssc, "unknown lock status 0x%x\n",
2190 ssc->ses_objmap[oid++].svalid = 1;
2195 * We always have speaker status, no matter what,
2196 * but we only save the status if we have one.
2198 SAFT_BAIL(r, hiwater, sdata, buflen);
2200 ssc->ses_objmap[oid].encstat[1] = 0;
2201 ssc->ses_objmap[oid].encstat[2] = 0;
2202 if (sdata[r] == 1) {
2204 * We need to cache tone urgency indicators.
2207 ssc->ses_objmap[oid].encstat[0] = SES_OBJSTAT_NONCRIT;
2208 ssc->ses_objmap[oid].encstat[3] = 0x8;
2209 ssc->ses_encstat |= SES_ENCSTAT_NONCRITICAL;
2210 } else if (sdata[r] == 0) {
2211 ssc->ses_objmap[oid].encstat[0] = SES_OBJSTAT_OK;
2212 ssc->ses_objmap[oid].encstat[3] = 0;
2214 ssc->ses_objmap[oid].encstat[0] =
2215 SES_OBJSTAT_UNSUPPORTED;
2216 ssc->ses_objmap[oid].encstat[3] = 0;
2217 SES_LOG(ssc, "unknown spkr status 0x%x\n",
2220 ssc->ses_objmap[oid++].svalid = 1;
2224 for (i = 0; i < cc->Ntherm; i++) {
2225 SAFT_BAIL(r, hiwater, sdata, buflen);
2227 * Status is a range from -10 to 245 deg Celsius,
2228 * which we need to normalize to -20 to -245 according
2229 * to the latest SCSI spec, which makes little
2230 * sense since this would overflow an 8bit value.
2231 * Well, still, the base normalization is -20,
2232 * not -10, so we have to adjust.
2234 * So what's over and under temperature?
2235 * Hmm- we'll state that 'normal' operating
2236 * is 10 to 40 deg Celsius.
2240 * Actually.... All of the units that people out in the world
2241 * seem to have do not come even close to setting a value that
2242 * complies with this spec.
2244 * The closest explanation I could find was in an
2245 * LSI-Logic manual, which seemed to indicate that
2246 * this value would be set by whatever the I2C code
2247 * would interpolate from the output of an LM75
2248 * temperature sensor.
2250 * This means that it is impossible to use the actual
2251 * numeric value to predict anything. But we don't want
2252 * to lose the value. So, we'll propagate the *uncorrected*
2253 * value and set SES_OBJSTAT_NOTAVAIL. We'll depend on the
2254 * temperature flags for warnings.
2256 ssc->ses_objmap[oid].encstat[0] = SES_OBJSTAT_NOTAVAIL;
2257 ssc->ses_objmap[oid].encstat[1] = 0;
2258 ssc->ses_objmap[oid].encstat[2] = sdata[r];
2259 ssc->ses_objmap[oid].encstat[3] = 0;;
2260 ssc->ses_objmap[oid++].svalid = 1;
2265 * Now, for "pseudo" thermometers, we have two bytes
2266 * of information in enclosure status- 16 bits. Actually,
2267 * the MSB is a single TEMP ALERT flag indicating whether
2268 * any other bits are set, but, thanks to fuzzy thinking,
2269 * in the SAF-TE spec, this can also be set even if no
2270 * other bits are set, thus making this really another
2271 * binary temperature sensor.
2274 SAFT_BAIL(r, hiwater, sdata, buflen);
2275 tempflags = sdata[r++];
2276 SAFT_BAIL(r, hiwater, sdata, buflen);
2277 tempflags |= (tempflags << 8) | sdata[r++];
2279 for (i = 0; i < NPSEUDO_THERM; i++) {
2280 ssc->ses_objmap[oid].encstat[1] = 0;
2281 if (tempflags & (1 << (NPSEUDO_THERM - i - 1))) {
2282 ssc->ses_objmap[oid].encstat[0] = SES_OBJSTAT_CRIT;
2283 ssc->ses_objmap[4].encstat[2] = 0xff;
2285 * Set 'over temperature' failure.
2287 ssc->ses_objmap[oid].encstat[3] = 8;
2288 ssc->ses_encstat |= SES_ENCSTAT_CRITICAL;
2291 * We used to say 'not available' and synthesize a
2292 * nominal 30 deg (C)- that was wrong. Actually,
2293 * Just say 'OK', and use the reserved value of
2296 ssc->ses_objmap[oid].encstat[0] = SES_OBJSTAT_OK;
2297 ssc->ses_objmap[oid].encstat[2] = 0;
2298 ssc->ses_objmap[oid].encstat[3] = 0;
2300 ssc->ses_objmap[oid++].svalid = 1;
2306 ssc->ses_objmap[oid].encstat[0] = SES_OBJSTAT_OK;
2307 ssc->ses_objmap[oid].encstat[3] = ssc->ses_objmap[oid].priv;
2308 ssc->ses_objmap[oid++].svalid = 1;
2311 * Now get drive slot status
2313 cdb[2] = SAFTE_RD_RDDSTS;
2315 err = ses_runcmd(ssc, cdb, 10, sdata, &amt);
2317 SES_FREE(sdata, buflen);
2320 hiwater = buflen - amt;
2321 for (r = i = 0; i < cc->Nslots; i++, r += 4) {
2322 SAFT_BAIL(r+3, hiwater, sdata, buflen);
2323 ssc->ses_objmap[oid].encstat[0] = SES_OBJSTAT_UNSUPPORTED;
2324 ssc->ses_objmap[oid].encstat[1] = (uint8_t) i;
2325 ssc->ses_objmap[oid].encstat[2] = 0;
2326 ssc->ses_objmap[oid].encstat[3] = 0;
2327 status = sdata[r+3];
2328 if ((status & 0x1) == 0) { /* no device */
2329 ssc->ses_objmap[oid].encstat[0] =
2330 SES_OBJSTAT_NOTINSTALLED;
2332 ssc->ses_objmap[oid].encstat[0] = SES_OBJSTAT_OK;
2335 ssc->ses_objmap[oid].encstat[2] = 0x8;
2337 if ((status & 0x4) == 0) {
2338 ssc->ses_objmap[oid].encstat[3] = 0x10;
2340 ssc->ses_objmap[oid++].svalid = 1;
2342 /* see comment below about sticky enclosure status */
2343 ssc->ses_encstat |= ENCI_SVALID | oencstat;
2344 SES_FREE(sdata, buflen);
2349 set_objstat_sel(ses_softc_t *ssc, ses_objstat *obp, int slp)
2353 struct scfg *cc = ssc->ses_private;
2358 idx = (int)obp->obj_id;
2359 ep = &ssc->ses_objmap[idx];
2361 switch (ep->enctype) {
2363 if (obp->cstat[0] & SESCTL_PRDFAIL) {
2366 /* SESCTL_RSTSWAP has no correspondence in SAF-TE */
2367 if (obp->cstat[0] & SESCTL_DISABLE) {
2370 * Hmm. Try to set the 'No Drive' flag.
2371 * Maybe that will count as a 'disable'.
2374 if (ep->priv & 0xc6) {
2377 ep->priv |= 0x1; /* no errors */
2379 wrslot_stat(ssc, slp);
2383 * Okay- the only one that makes sense here is to
2384 * do the 'disable' for a power supply.
2386 if (obp->cstat[0] & SESCTL_DISABLE) {
2387 (void) wrbuf16(ssc, SAFTE_WT_ACTPWS,
2388 idx - cc->pwroff, 0, 0, slp);
2393 * Okay- the only one that makes sense here is to
2394 * set fan speed to zero on disable.
2396 if (obp->cstat[0] & SESCTL_DISABLE) {
2397 /* remember- fans are the first items, so idx works */
2398 (void) wrbuf16(ssc, SAFTE_WT_FANSPD, idx, 0, 0, slp);
2401 case SESTYP_DOORLOCK:
2403 * Well, we can 'disable' the lock.
2405 if (obp->cstat[0] & SESCTL_DISABLE) {
2406 cc->flag2 &= ~SAFT_FLG2_LOCKDOOR;
2407 (void) wrbuf16(ssc, SAFTE_WT_GLOBAL, cc->flag1,
2413 * Well, we can 'disable' the alarm.
2415 if (obp->cstat[0] & SESCTL_DISABLE) {
2416 cc->flag2 &= ~SAFT_FLG1_ALARM;
2417 ep->priv |= 0x40; /* Muted */
2418 (void) wrbuf16(ssc, SAFTE_WT_GLOBAL, cc->flag1,
2430 * This function handles all of the 16 byte WRITE BUFFER commands.
2433 wrbuf16(ses_softc_t *ssc, uint8_t op, uint8_t b1, uint8_t b2,
2434 uint8_t b3, int slp)
2438 struct scfg *cc = ssc->ses_private;
2439 static char cdb[10] = { WRITE_BUFFER, 1, 0, 0, 0, 0, 0, 0, 16, 0 };
2444 sdata = SES_MALLOC(16);
2448 SES_DLOG(ssc, "saf_wrbuf16 %x %x %x %x\n", op, b1, b2, b3);
2454 MEMZERO(&sdata[4], 12);
2456 err = ses_runcmd(ssc, cdb, 10, sdata, &amt);
2457 SES_FREE(sdata, 16);
2462 * This function updates the status byte for the device slot described.
2464 * Since this is an optional SAF-TE command, there's no point in
2465 * returning an error.
2468 wrslot_stat(ses_softc_t *ssc, int slp)
2472 char cdb[10], *sdata;
2473 struct scfg *cc = ssc->ses_private;
2478 SES_DLOG(ssc, "saf_wrslot\n");
2479 cdb[0] = WRITE_BUFFER;
2487 cdb[8] = cc->Nslots * 3 + 1;
2490 sdata = SES_MALLOC(cc->Nslots * 3 + 1);
2493 MEMZERO(sdata, cc->Nslots * 3 + 1);
2495 sdata[0] = SAFTE_WT_DSTAT;
2496 for (i = 0; i < cc->Nslots; i++) {
2497 ep = &ssc->ses_objmap[cc->slotoff + i];
2498 SES_DLOG(ssc, "saf_wrslot %d <- %x\n", i, ep->priv & 0xff);
2499 sdata[1 + (3 * i)] = ep->priv & 0xff;
2501 amt = -(cc->Nslots * 3 + 1);
2502 (void) ses_runcmd(ssc, cdb, 10, sdata, &amt);
2503 SES_FREE(sdata, cc->Nslots * 3 + 1);
2507 * This function issues the "PERFORM SLOT OPERATION" command.
2510 perf_slotop(ses_softc_t *ssc, uint8_t slot, uint8_t opflag, int slp)
2514 struct scfg *cc = ssc->ses_private;
2515 static char cdb[10] =
2516 { WRITE_BUFFER, 1, 0, 0, 0, 0, 0, 0, SAFT_SCRATCH, 0 };
2521 sdata = SES_MALLOC(SAFT_SCRATCH);
2524 MEMZERO(sdata, SAFT_SCRATCH);
2526 sdata[0] = SAFTE_WT_SLTOP;
2529 SES_DLOG(ssc, "saf_slotop slot %d op %x\n", slot, opflag);
2530 amt = -SAFT_SCRATCH;
2531 err = ses_runcmd(ssc, cdb, 10, sdata, &amt);
2532 SES_FREE(sdata, SAFT_SCRATCH);