1 /* $FreeBSD: src/sys/cam/scsi/scsi_ses.c,v 1.8.2.2 2000/08/08 23:19:21 mjacob Exp $ */
3 * Copyright (c) 2000 Matthew Jacob
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions, and the following disclaimer,
11 * without modification, immediately at the beginning of the file.
12 * 2. The name of the author may not be used to endorse or promote products
13 * derived from this software without specific prior written permission.
15 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
16 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR
19 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
28 #include <sys/param.h>
29 #include <sys/queue.h>
30 #include <sys/systm.h>
31 #include <sys/kernel.h>
32 #include <sys/types.h>
33 #include <sys/malloc.h>
34 #include <sys/fcntl.h>
37 #include <sys/errno.h>
38 #include <sys/devicestat.h>
39 #include <sys/thread2.h>
40 #include <machine/stdarg.h>
43 #include "../cam_ccb.h"
44 #include "../cam_extend.h"
45 #include "../cam_periph.h"
46 #include "../cam_xpt_periph.h"
47 #include "../cam_debug.h"
48 #include "../cam_sim.h"
51 #include "scsi_message.h"
56 MALLOC_DEFINE(M_SCSISES, "SCSI SES", "SCSI SES buffers");
59 * Platform Independent Driver Internal Definitions for SES devices.
71 typedef struct ses_softc ses_softc_t;
73 int (*softc_init)(ses_softc_t *, int);
74 int (*init_enc)(ses_softc_t *);
75 int (*get_encstat)(ses_softc_t *, int);
76 int (*set_encstat)(ses_softc_t *, ses_encstat, int);
77 int (*get_objstat)(ses_softc_t *, ses_objstat *, int);
78 int (*set_objstat)(ses_softc_t *, ses_objstat *, int);
81 #define ENCI_SVALID 0x80
85 enctype : 8, /* enclosure type */
86 subenclosure : 8, /* subenclosure id */
87 svalid : 1, /* enclosure information valid */
88 priv : 15; /* private data, per object */
89 uint8_t encstat[4]; /* state && stats */
92 #define SEN_ID "UNISYS SUN_SEN"
96 static enctyp ses_type(void *, int);
99 /* Forward reference to Enclosure Functions */
100 static int ses_softc_init(ses_softc_t *, int);
101 static int ses_init_enc(ses_softc_t *);
102 static int ses_get_encstat(ses_softc_t *, int);
103 static int ses_set_encstat(ses_softc_t *, uint8_t, int);
104 static int ses_get_objstat(ses_softc_t *, ses_objstat *, int);
105 static int ses_set_objstat(ses_softc_t *, ses_objstat *, int);
107 static int safte_softc_init(ses_softc_t *, int);
108 static int safte_init_enc(ses_softc_t *);
109 static int safte_get_encstat(ses_softc_t *, int);
110 static int safte_set_encstat(ses_softc_t *, uint8_t, int);
111 static int safte_get_objstat(ses_softc_t *, ses_objstat *, int);
112 static int safte_set_objstat(ses_softc_t *, ses_objstat *, int);
115 * Platform implementation defines/functions for SES internal kernel stuff
118 #define STRNCMP strncmp
119 #define PRINTF kprintf
120 #define SES_LOG ses_log
122 #define SES_DLOG ses_log
124 #define SES_DLOG if (0) ses_log
126 #define SES_VLOG if (bootverbose) ses_log
127 #define SES_MALLOC(amt) kmalloc(amt, M_SCSISES, M_INTWAIT)
128 #define SES_FREE(ptr, amt) kfree(ptr, M_SCSISES)
129 #define MEMZERO bzero
130 #define MEMCPY(dest, src, amt) bcopy(src, dest, amt)
132 static int ses_runcmd(struct ses_softc *, char *, int, char *, int *);
133 static void ses_log(struct ses_softc *, const char *, ...) __printflike(2, 3);
136 * Gerenal FreeBSD kernel stuff.
140 #define ccb_state ppriv_field0
141 #define ccb_bio ppriv_ptr1
144 enctyp ses_type; /* type of enclosure */
145 encvec ses_vec; /* vector to handlers */
146 void * ses_private; /* per-type private data */
147 encobj * ses_objmap; /* objects */
148 u_int32_t ses_nobjects; /* number of objects */
149 ses_encstat ses_encstat; /* overall status */
151 union ccb ses_saved_ccb;
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 *, u_int32_t, struct cam_path *, void *);
170 static void sesdone(struct cam_periph *, union ccb *);
171 static int seserror(union ccb *, u_int32_t, u_int32_t);
173 static struct periph_driver sesdriver = {
175 TAILQ_HEAD_INITIALIZER(sesdriver.units), /* generation */ 0
178 PERIPHDRIVER_DECLARE(ses, sesdriver);
180 static struct dev_ops ses_ops = {
186 static struct extend_array *sesperiphs;
194 * Create our extend array for storing the devices we attach to.
196 sesperiphs = cam_extend_new();
197 if (sesperiphs == NULL) {
198 kprintf("ses: Failed to alloc extend array!\n");
203 * Install a global async callback. This callback will
204 * receive async callbacks like "new device found".
206 status = xpt_register_async(AC_FOUND_DEVICE, sesasync, NULL, NULL);
208 if (status != CAM_REQ_CMP) {
209 kprintf("ses: Failed to attach master async callback "
210 "due to status 0x%x!\n", status);
215 sesoninvalidate(struct cam_periph *periph)
217 struct ses_softc *softc;
219 softc = (struct ses_softc *)periph->softc;
222 * Unregister any async callbacks.
224 xpt_register_async(0, sesasync, periph, periph->path);
226 softc->ses_flags |= SES_FLAG_INVALID;
228 xpt_print(periph->path, "lost device\n");
232 sescleanup(struct cam_periph *periph)
234 struct ses_softc *softc;
236 softc = (struct ses_softc *)periph->softc;
238 cam_extend_release(sesperiphs, periph->unit_number);
239 xpt_print(periph->path, "removing device entry\n");
240 dev_ops_remove_minor(&ses_ops, periph->unit_number);
241 kfree(softc, M_SCSISES);
245 sesasync(void *callback_arg, u_int32_t code, struct cam_path *path, void *arg)
247 struct cam_periph *periph;
249 periph = (struct cam_periph *)callback_arg;
252 case AC_FOUND_DEVICE:
255 struct ccb_getdev *cgd;
258 cgd = (struct ccb_getdev *)arg;
263 inq_len = cgd->inq_data.additional_length + 4;
266 * PROBLEM: WE NEED TO LOOK AT BYTES 48-53 TO SEE IF THIS IS
267 * PROBLEM: IS A SAF-TE DEVICE.
269 switch (ses_type(&cgd->inq_data, inq_len)) {
272 case SES_SES_PASSTHROUGH:
280 status = cam_periph_alloc(sesregister, sesoninvalidate,
281 sescleanup, sesstart, "ses", CAM_PERIPH_BIO,
282 cgd->ccb_h.path, sesasync, AC_FOUND_DEVICE, cgd);
284 if (status != CAM_REQ_CMP && status != CAM_REQ_INPROG) {
285 kprintf("sesasync: Unable to probe new device due to "
286 "status 0x%x\n", status);
291 cam_periph_async(periph, code, path, arg);
297 sesregister(struct cam_periph *periph, void *arg)
299 struct ses_softc *softc;
300 struct ccb_getdev *cgd;
303 cgd = (struct ccb_getdev *)arg;
304 if (periph == NULL) {
305 kprintf("sesregister: periph was NULL!!\n");
306 return (CAM_REQ_CMP_ERR);
310 kprintf("sesregister: no getdev CCB, can't register device\n");
311 return (CAM_REQ_CMP_ERR);
314 softc = kmalloc(sizeof (struct ses_softc), M_SCSISES, M_INTWAIT | M_ZERO);
315 periph->softc = softc;
316 softc->periph = periph;
318 softc->ses_type = ses_type(&cgd->inq_data, sizeof (cgd->inq_data));
320 switch (softc->ses_type) {
323 case SES_SES_PASSTHROUGH:
324 softc->ses_vec.softc_init = ses_softc_init;
325 softc->ses_vec.init_enc = ses_init_enc;
326 softc->ses_vec.get_encstat = ses_get_encstat;
327 softc->ses_vec.set_encstat = ses_set_encstat;
328 softc->ses_vec.get_objstat = ses_get_objstat;
329 softc->ses_vec.set_objstat = ses_set_objstat;
332 softc->ses_vec.softc_init = safte_softc_init;
333 softc->ses_vec.init_enc = safte_init_enc;
334 softc->ses_vec.get_encstat = safte_get_encstat;
335 softc->ses_vec.set_encstat = safte_set_encstat;
336 softc->ses_vec.get_objstat = safte_get_objstat;
337 softc->ses_vec.set_objstat = safte_set_objstat;
343 kfree(softc, M_SCSISES);
344 return (CAM_REQ_CMP_ERR);
347 cam_extend_set(sesperiphs, periph->unit_number, periph);
349 cam_periph_unlock(periph);
350 make_dev(&ses_ops, periph->unit_number,
351 UID_ROOT, GID_OPERATOR, 0600, "%s%d",
352 periph->periph_name, periph->unit_number);
353 cam_periph_lock(periph);
356 * Add an async callback so that we get
357 * notified if this device goes away.
359 xpt_register_async(AC_LOST_DEVICE, sesasync, periph, periph->path);
361 switch (softc->ses_type) {
364 tname = "No SES device";
367 tname = "SCSI-2 SES Device";
370 tname = "SCSI-3 SES Device";
372 case SES_SES_PASSTHROUGH:
373 tname = "SES Passthrough Device";
376 tname = "UNISYS SEN Device (NOT HANDLED YET)";
379 tname = "SAF-TE Compliant Device";
382 xpt_announce_periph(periph, tname);
383 return (CAM_REQ_CMP);
387 sesopen(struct dev_open_args *ap)
389 cdev_t dev = ap->a_head.a_dev;
390 struct cam_periph *periph;
391 struct ses_softc *softc;
394 periph = cam_extend_get(sesperiphs, SESUNIT(dev));
395 if (periph == NULL) {
399 if (cam_periph_acquire(periph) != CAM_REQ_CMP) {
400 cam_periph_unlock(periph);
404 cam_periph_lock(periph);
406 softc = (struct ses_softc *)periph->softc;
408 if (softc->ses_flags & SES_FLAG_INVALID) {
412 if (softc->ses_flags & SES_FLAG_OPEN) {
416 if (softc->ses_vec.softc_init == NULL) {
421 softc->ses_flags |= SES_FLAG_OPEN;
422 if ((softc->ses_flags & SES_FLAG_INITIALIZED) == 0) {
423 error = (*softc->ses_vec.softc_init)(softc, 1);
425 softc->ses_flags &= ~SES_FLAG_OPEN;
427 softc->ses_flags |= SES_FLAG_INITIALIZED;
431 cam_periph_unlock(periph);
433 cam_periph_release(periph);
439 sesclose(struct dev_close_args *ap)
441 cdev_t dev = ap->a_head.a_dev;
442 struct cam_periph *periph;
443 struct ses_softc *softc;
449 periph = cam_extend_get(sesperiphs, unit);
453 cam_periph_lock(periph);
455 softc = (struct ses_softc *)periph->softc;
456 softc->ses_flags &= ~SES_FLAG_OPEN;
458 cam_periph_unlock(periph);
459 cam_periph_release(periph);
465 sesstart(struct cam_periph *p, union ccb *sccb)
467 if (p->immediate_priority <= p->pinfo.priority) {
468 SLIST_INSERT_HEAD(&p->ccb_list, &sccb->ccb_h, periph_links.sle);
469 p->immediate_priority = CAM_PRIORITY_NONE;
470 wakeup(&p->ccb_list);
475 sesdone(struct cam_periph *periph, union ccb *dccb)
477 wakeup(&dccb->ccb_h.cbfcnp);
481 seserror(union ccb *ccb, u_int32_t cflags, u_int32_t sflags)
483 struct ses_softc *softc;
484 struct cam_periph *periph;
486 periph = xpt_path_periph(ccb->ccb_h.path);
487 softc = (struct ses_softc *)periph->softc;
489 return (cam_periph_error(ccb, cflags, sflags, &softc->ses_saved_ccb));
493 sesioctl(struct dev_ioctl_args *ap)
495 cdev_t dev = ap->a_head.a_dev;
496 struct cam_periph *periph;
499 ses_object obj, *uobj;
500 struct ses_softc *ssc;
506 addr = *((caddr_t *)ap->a_data);
510 periph = cam_extend_get(sesperiphs, SESUNIT(dev));
514 CAM_DEBUG(periph->path, CAM_DEBUG_TRACE, ("entering sesioctl\n"));
516 cam_periph_lock(periph);
517 ssc = (struct ses_softc *)periph->softc;
520 * Now check to see whether we're initialized or not.
522 if ((ssc->ses_flags & SES_FLAG_INITIALIZED) == 0) {
523 cam_periph_unlock(periph);
526 cam_periph_unlock(periph);
530 CAM_DEBUG(periph->path, CAM_DEBUG_TRACE,
531 ("trying to do ioctl %#lx\n", ap->a_cmd));
534 * If this command can change the device's state,
535 * we must have the device open for writing.
539 case SESIOC_GETOBJMAP:
540 case SESIOC_GETENCSTAT:
541 case SESIOC_GETOBJSTAT:
544 if ((ap->a_fflag & FWRITE) == 0) {
551 error = copyout(&ssc->ses_nobjects, addr,
552 sizeof (ssc->ses_nobjects));
555 case SESIOC_GETOBJMAP:
557 * XXX Dropping the lock while copying multiple segments is
560 cam_periph_lock(periph);
561 for (uobj = addr, i = 0; i != ssc->ses_nobjects; i++, uobj++) {
563 obj.subencid = ssc->ses_objmap[i].subenclosure;
564 obj.object_type = ssc->ses_objmap[i].enctype;
565 cam_periph_unlock(periph);
566 error = copyout(&obj, uobj, sizeof (ses_object));
567 cam_periph_lock(periph);
572 cam_periph_unlock(periph);
575 case SESIOC_GETENCSTAT:
576 cam_periph_lock(periph);
577 error = (*ssc->ses_vec.get_encstat)(ssc, 1);
579 cam_periph_unlock(periph);
582 tmp = ssc->ses_encstat & ~ENCI_SVALID;
583 cam_periph_unlock(periph);
584 error = copyout(&tmp, addr, sizeof (ses_encstat));
585 ssc->ses_encstat = tmp;
588 case SESIOC_SETENCSTAT:
589 error = copyin(addr, &tmp, sizeof (ses_encstat));
592 cam_periph_lock(periph);
593 error = (*ssc->ses_vec.set_encstat)(ssc, tmp, 1);
594 cam_periph_unlock(periph);
597 case SESIOC_GETOBJSTAT:
598 error = copyin(addr, &objs, sizeof (ses_objstat));
601 if (objs.obj_id >= ssc->ses_nobjects) {
605 cam_periph_lock(periph);
606 error = (*ssc->ses_vec.get_objstat)(ssc, &objs, 1);
607 cam_periph_unlock(periph);
610 error = copyout(&objs, addr, sizeof (ses_objstat));
612 * Always (for now) invalidate entry.
614 ssc->ses_objmap[objs.obj_id].svalid = 0;
617 case SESIOC_SETOBJSTAT:
618 error = copyin(addr, &objs, sizeof (ses_objstat));
622 if (objs.obj_id >= ssc->ses_nobjects) {
626 cam_periph_lock(periph);
627 error = (*ssc->ses_vec.set_objstat)(ssc, &objs, 1);
628 cam_periph_unlock(periph);
631 * Always (for now) invalidate entry.
633 ssc->ses_objmap[objs.obj_id].svalid = 0;
638 cam_periph_lock(periph);
639 error = (*ssc->ses_vec.init_enc)(ssc);
640 cam_periph_unlock(periph);
644 cam_periph_lock(periph);
645 error = cam_periph_ioctl(periph, ap->a_cmd, ap->a_data, seserror);
646 cam_periph_unlock(periph);
652 #define SES_CFLAGS CAM_RETRY_SELTO
653 #define SES_FLAGS SF_NO_PRINT | SF_RETRY_UA
655 ses_runcmd(struct ses_softc *ssc, char *cdb, int cdbl, char *dptr, int *dlenp)
662 if ((dlen = *dlenp) < 0) {
673 if (cdbl > IOCDBLEN) {
677 ccb = cam_periph_getccb(ssc->periph, 1);
678 cam_fill_csio(&ccb->csio, 0, sesdone, ddf, MSG_SIMPLE_Q_TAG, dptr,
679 dlen, sizeof (struct scsi_sense_data), cdbl, 60 * 1000);
680 bcopy(cdb, ccb->csio.cdb_io.cdb_bytes, cdbl);
682 error = cam_periph_runccb(ccb, seserror, SES_CFLAGS, SES_FLAGS, NULL);
683 if ((ccb->ccb_h.status & CAM_DEV_QFRZN) != 0)
684 cam_release_devq(ccb->ccb_h.path, 0, 0, 0, FALSE);
691 *dlenp = ccb->csio.resid;
694 xpt_release_ccb(ccb);
699 ses_log(struct ses_softc *ssc, const char *fmt, ...)
703 kprintf("%s%d: ", ssc->periph->periph_name, ssc->periph->unit_number);
710 * The code after this point runs on many platforms,
711 * so forgive the slightly awkward and nonconforming
716 * Is this a device that supports enclosure services?
718 * It's a a pretty simple ruleset- if it is device type 0x0D (13), it's
719 * an SES device. If it happens to be an old UNISYS SEN device, we can
723 #define SAFTE_START 44
725 #define SAFTE_LEN SAFTE_END-SAFTE_START
728 ses_type(void *buf, int buflen)
730 unsigned char *iqd = buf;
732 if (buflen < 8+SEN_ID_LEN)
735 if ((iqd[0] & 0x1f) == T_ENCLOSURE) {
736 if (STRNCMP(&iqd[8], SEN_ID, SEN_ID_LEN) == 0) {
738 } else if ((iqd[2] & 0x7) > 2) {
741 return (SES_SES_SCSI2);
746 #ifdef SES_ENABLE_PASSTHROUGH
747 if ((iqd[6] & 0x40) && (iqd[2] & 0x7) >= 2) {
749 * PassThrough Device.
751 return (SES_SES_PASSTHROUGH);
756 * The comparison is short for a reason-
757 * some vendors were chopping it short.
760 if (buflen < SAFTE_END - 2) {
764 if (STRNCMP((char *)&iqd[SAFTE_START], "SAF-TE", SAFTE_LEN - 2) == 0) {
771 * SES Native Type Device Support
775 * SES Diagnostic Page Codes
781 #define SesStatusPage SesControlPage
784 #define SesStringIn SesStringOut
786 #define SesThresholdIn SesThresholdOut
788 #define SesArrayStatus SesArrayControl
789 SesElementDescriptor,
798 * Minimum amount of data, starting from byte 0, to have
801 #define SES_CFGHDR_MINLEN 12
804 * Minimum amount of data, starting from byte 0, to have
805 * the config header and one enclosure header.
807 #define SES_ENCHDR_MINLEN 48
810 * Take this value, subtract it from VEnclen and you know
811 * the length of the vendor unique bytes.
813 #define SES_ENCHDR_VMIN 36
816 * SES Data Structures
820 uint32_t GenCode; /* Generation Code */
821 uint8_t Nsubenc; /* Number of Subenclosures */
825 uint8_t Subencid; /* SubEnclosure Identifier */
826 uint8_t Ntypes; /* # of supported types */
827 uint8_t VEnclen; /* Enclosure Descriptor Length */
831 uint8_t encWWN[8]; /* XXX- Not Right Yet */
839 uint8_t enc_type; /* type of element */
840 uint8_t enc_maxelt; /* maximum supported */
841 uint8_t enc_subenc; /* in SubEnc # N */
842 uint8_t enc_tlen; /* Type Descriptor Text Length */
856 uint8_t ses_ntypes; /* total number of types supported */
859 * We need to keep a type index as well as an
860 * object index for each object in an enclosure.
862 struct typidx *ses_typidx;
865 * We also need to keep track of the number of elements
866 * per type of element. This is needed later so that we
867 * can find precisely in the returned status data the
868 * status for the Nth element of the Kth type.
870 uint8_t * ses_eltmap;
875 * (de)canonicalization defines
877 #define sbyte(x, byte) ((((uint32_t)(x)) >> (byte * 8)) & 0xff)
878 #define sbit(x, bit) (((uint32_t)(x)) << bit)
879 #define sset8(outp, idx, sval) (((uint8_t *)(outp))[idx++]) = sbyte(sval, 0)
881 #define sset16(outp, idx, sval) \
882 (((uint8_t *)(outp))[idx++]) = sbyte(sval, 1), \
883 (((uint8_t *)(outp))[idx++]) = sbyte(sval, 0)
886 #define sset24(outp, idx, sval) \
887 (((uint8_t *)(outp))[idx++]) = sbyte(sval, 2), \
888 (((uint8_t *)(outp))[idx++]) = sbyte(sval, 1), \
889 (((uint8_t *)(outp))[idx++]) = sbyte(sval, 0)
892 #define sset32(outp, idx, sval) \
893 (((uint8_t *)(outp))[idx++]) = sbyte(sval, 3), \
894 (((uint8_t *)(outp))[idx++]) = sbyte(sval, 2), \
895 (((uint8_t *)(outp))[idx++]) = sbyte(sval, 1), \
896 (((uint8_t *)(outp))[idx++]) = sbyte(sval, 0)
898 #define gbyte(x, byte) ((((uint32_t)(x)) & 0xff) << (byte * 8))
899 #define gbit(lv, in, idx, shft, mask) lv = ((in[idx] >> shft) & mask)
900 #define sget8(inp, idx, lval) lval = (((uint8_t *)(inp))[idx++])
901 #define gget8(inp, idx, lval) lval = (((uint8_t *)(inp))[idx])
903 #define sget16(inp, idx, lval) \
904 lval = gbyte((((uint8_t *)(inp))[idx]), 1) | \
905 (((uint8_t *)(inp))[idx+1]), idx += 2
907 #define gget16(inp, idx, lval) \
908 lval = gbyte((((uint8_t *)(inp))[idx]), 1) | \
909 (((uint8_t *)(inp))[idx+1])
911 #define sget24(inp, idx, lval) \
912 lval = gbyte((((uint8_t *)(inp))[idx]), 2) | \
913 gbyte((((uint8_t *)(inp))[idx+1]), 1) | \
914 (((uint8_t *)(inp))[idx+2]), idx += 3
916 #define gget24(inp, idx, lval) \
917 lval = gbyte((((uint8_t *)(inp))[idx]), 2) | \
918 gbyte((((uint8_t *)(inp))[idx+1]), 1) | \
919 (((uint8_t *)(inp))[idx+2])
921 #define sget32(inp, idx, lval) \
922 lval = gbyte((((uint8_t *)(inp))[idx]), 3) | \
923 gbyte((((uint8_t *)(inp))[idx+1]), 2) | \
924 gbyte((((uint8_t *)(inp))[idx+2]), 1) | \
925 (((uint8_t *)(inp))[idx+3]), idx += 4
927 #define gget32(inp, idx, lval) \
928 lval = gbyte((((uint8_t *)(inp))[idx]), 3) | \
929 gbyte((((uint8_t *)(inp))[idx+1]), 2) | \
930 gbyte((((uint8_t *)(inp))[idx+2]), 1) | \
931 (((uint8_t *)(inp))[idx+3])
934 #define CFLEN (256 + SES_ENCHDR_MINLEN)
937 * Routines specific && private to SES only
940 static int ses_getconfig(ses_softc_t *);
941 static int ses_getputstat(ses_softc_t *, int, SesComStat *, int, int);
942 static int ses_cfghdr(uint8_t *, int, SesCfgHdr *);
943 static int ses_enchdr(uint8_t *, int, uint8_t, SesEncHdr *);
944 static int ses_encdesc(uint8_t *, int, uint8_t, SesEncDesc *);
945 static int ses_getthdr(uint8_t *, int, int, SesThdr *);
946 static int ses_decode(char *, int, uint8_t *, int, int, SesComStat *);
947 static int ses_encode(char *, int, uint8_t *, int, int, SesComStat *);
950 ses_softc_init(ses_softc_t *ssc, int doinit)
954 if (ssc->ses_nobjects) {
955 SES_FREE(ssc->ses_objmap,
956 ssc->ses_nobjects * sizeof (encobj));
957 ssc->ses_objmap = NULL;
959 if ((cc = ssc->ses_private) != NULL) {
960 if (cc->ses_eltmap && cc->ses_ntypes) {
961 SES_FREE(cc->ses_eltmap, cc->ses_ntypes);
962 cc->ses_eltmap = NULL;
965 if (cc->ses_typidx && ssc->ses_nobjects) {
966 SES_FREE(cc->ses_typidx,
967 ssc->ses_nobjects * sizeof (struct typidx));
968 cc->ses_typidx = NULL;
970 SES_FREE(cc, sizeof (struct sscfg));
971 ssc->ses_private = NULL;
973 ssc->ses_nobjects = 0;
976 if (ssc->ses_private == NULL) {
977 ssc->ses_private = SES_MALLOC(sizeof (struct sscfg));
979 if (ssc->ses_private == NULL) {
982 ssc->ses_nobjects = 0;
983 ssc->ses_encstat = 0;
984 return (ses_getconfig(ssc));
988 ses_init_enc(ses_softc_t *ssc)
994 ses_get_encstat(ses_softc_t *ssc, int slpflag)
999 if ((status = ses_getputstat(ssc, -1, &ComStat, slpflag, 1)) != 0) {
1002 ssc->ses_encstat = ComStat.comstatus | ENCI_SVALID;
1007 ses_set_encstat(ses_softc_t *ssc, uint8_t encstat, int slpflag)
1012 ComStat.comstatus = encstat & 0xf;
1013 if ((status = ses_getputstat(ssc, -1, &ComStat, slpflag, 0)) != 0) {
1016 ssc->ses_encstat = encstat & 0xf; /* note no SVALID set */
1021 ses_get_objstat(ses_softc_t *ssc, ses_objstat *obp, int slpflag)
1023 int i = (int)obp->obj_id;
1025 if (ssc->ses_objmap[i].svalid == 0) {
1027 int err = ses_getputstat(ssc, i, &ComStat, slpflag, 1);
1030 ssc->ses_objmap[i].encstat[0] = ComStat.comstatus;
1031 ssc->ses_objmap[i].encstat[1] = ComStat.comstat[0];
1032 ssc->ses_objmap[i].encstat[2] = ComStat.comstat[1];
1033 ssc->ses_objmap[i].encstat[3] = ComStat.comstat[2];
1034 ssc->ses_objmap[i].svalid = 1;
1036 obp->cstat[0] = ssc->ses_objmap[i].encstat[0];
1037 obp->cstat[1] = ssc->ses_objmap[i].encstat[1];
1038 obp->cstat[2] = ssc->ses_objmap[i].encstat[2];
1039 obp->cstat[3] = ssc->ses_objmap[i].encstat[3];
1044 ses_set_objstat(ses_softc_t *ssc, ses_objstat *obp, int slpflag)
1049 * If this is clear, we don't do diddly.
1051 if ((obp->cstat[0] & SESCTL_CSEL) == 0) {
1054 ComStat.comstatus = obp->cstat[0];
1055 ComStat.comstat[0] = obp->cstat[1];
1056 ComStat.comstat[1] = obp->cstat[2];
1057 ComStat.comstat[2] = obp->cstat[3];
1058 err = ses_getputstat(ssc, (int)obp->obj_id, &ComStat, slpflag, 0);
1059 ssc->ses_objmap[(int)obp->obj_id].svalid = 0;
1064 ses_getconfig(ses_softc_t *ssc)
1071 int err, amt, i, nobj, ntype, maxima;
1072 char storage[CFLEN], *sdata;
1073 static char cdb[6] = {
1074 RECEIVE_DIAGNOSTIC, 0x1, SesConfigPage, SCSZ >> 8, SCSZ & 0xff, 0
1077 cc = ssc->ses_private;
1082 sdata = SES_MALLOC(SCSZ);
1087 err = ses_runcmd(ssc, cdb, 6, sdata, &amt);
1089 SES_FREE(sdata, SCSZ);
1094 if (ses_cfghdr((uint8_t *) sdata, amt, &cf)) {
1095 SES_LOG(ssc, "Unable to parse SES Config Header\n");
1096 SES_FREE(sdata, SCSZ);
1099 if (amt < SES_ENCHDR_MINLEN) {
1100 SES_LOG(ssc, "runt enclosure length (%d)\n", amt);
1101 SES_FREE(sdata, SCSZ);
1105 SES_VLOG(ssc, "GenCode %x %d Subenclosures\n", cf.GenCode, cf.Nsubenc);
1108 * Now waltz through all the subenclosures toting up the
1109 * number of types available in each. For this, we only
1110 * really need the enclosure header. However, we get the
1111 * enclosure descriptor for debug purposes, as well
1112 * as self-consistency checking purposes.
1115 maxima = cf.Nsubenc + 1;
1116 cdp = (SesEncDesc *) storage;
1117 for (ntype = i = 0; i < maxima; i++) {
1118 MEMZERO((caddr_t)cdp, sizeof (*cdp));
1119 if (ses_enchdr((uint8_t *) sdata, amt, i, &hd)) {
1120 SES_LOG(ssc, "Cannot Extract Enclosure Header %d\n", i);
1121 SES_FREE(sdata, SCSZ);
1124 SES_VLOG(ssc, " SubEnclosure ID %d, %d Types With this ID, En"
1125 "closure Length %d\n", hd.Subencid, hd.Ntypes, hd.VEnclen);
1127 if (ses_encdesc((uint8_t *)sdata, amt, i, cdp)) {
1128 SES_LOG(ssc, "Can't get Enclosure Descriptor %d\n", i);
1129 SES_FREE(sdata, SCSZ);
1132 SES_VLOG(ssc, " WWN: %02x%02x%02x%02x%02x%02x%02x%02x\n",
1133 cdp->encWWN[0], cdp->encWWN[1], cdp->encWWN[2],
1134 cdp->encWWN[3], cdp->encWWN[4], cdp->encWWN[5],
1135 cdp->encWWN[6], cdp->encWWN[7]);
1140 * Now waltz through all the types that are available, getting
1141 * the type header so we can start adding up the number of
1142 * objects available.
1144 for (nobj = i = 0; i < ntype; i++) {
1145 if (ses_getthdr((uint8_t *)sdata, amt, i, &thdr)) {
1146 SES_LOG(ssc, "Can't get Enclosure Type Header %d\n", i);
1147 SES_FREE(sdata, SCSZ);
1150 SES_LOG(ssc, " Type Desc[%d]: Type 0x%x, MaxElt %d, In Subenc "
1151 "%d, Text Length %d\n", i, thdr.enc_type, thdr.enc_maxelt,
1152 thdr.enc_subenc, thdr.enc_tlen);
1153 nobj += thdr.enc_maxelt;
1158 * Now allocate the object array and type map.
1161 ssc->ses_objmap = SES_MALLOC(nobj * sizeof (encobj));
1162 cc->ses_typidx = SES_MALLOC(nobj * sizeof (struct typidx));
1163 cc->ses_eltmap = SES_MALLOC(ntype);
1165 if (ssc->ses_objmap == NULL || cc->ses_typidx == NULL ||
1166 cc->ses_eltmap == NULL) {
1167 if (ssc->ses_objmap) {
1168 SES_FREE(ssc->ses_objmap, (nobj * sizeof (encobj)));
1169 ssc->ses_objmap = NULL;
1171 if (cc->ses_typidx) {
1172 SES_FREE(cc->ses_typidx,
1173 (nobj * sizeof (struct typidx)));
1174 cc->ses_typidx = NULL;
1176 if (cc->ses_eltmap) {
1177 SES_FREE(cc->ses_eltmap, ntype);
1178 cc->ses_eltmap = NULL;
1180 SES_FREE(sdata, SCSZ);
1183 MEMZERO(ssc->ses_objmap, nobj * sizeof (encobj));
1184 MEMZERO(cc->ses_typidx, nobj * sizeof (struct typidx));
1185 MEMZERO(cc->ses_eltmap, ntype);
1186 cc->ses_ntypes = (uint8_t) ntype;
1187 ssc->ses_nobjects = nobj;
1190 * Now waltz through the # of types again to fill in the types
1191 * (and subenclosure ids) of the allocated objects.
1194 for (i = 0; i < ntype; i++) {
1196 if (ses_getthdr((uint8_t *)sdata, amt, i, &thdr)) {
1199 cc->ses_eltmap[i] = thdr.enc_maxelt;
1200 for (j = 0; j < thdr.enc_maxelt; j++) {
1201 cc->ses_typidx[nobj].ses_tidx = i;
1202 cc->ses_typidx[nobj].ses_oidx = j;
1203 ssc->ses_objmap[nobj].subenclosure = thdr.enc_subenc;
1204 ssc->ses_objmap[nobj++].enctype = thdr.enc_type;
1207 SES_FREE(sdata, SCSZ);
1212 ses_getputstat(ses_softc_t *ssc, int objid, SesComStat *sp, int slp, int in)
1215 int err, amt, bufsiz, tidx, oidx;
1216 char cdb[6], *sdata;
1218 cc = ssc->ses_private;
1224 * If we're just getting overall enclosure status,
1225 * we only need 2 bytes of data storage.
1227 * If we're getting anything else, we know how much
1228 * storage we need by noting that starting at offset
1229 * 8 in returned data, all object status bytes are 4
1230 * bytes long, and are stored in chunks of types(M)
1231 * and nth+1 instances of type M.
1236 bufsiz = (ssc->ses_nobjects * 4) + (cc->ses_ntypes * 4) + 8;
1238 sdata = SES_MALLOC(bufsiz);
1242 cdb[0] = RECEIVE_DIAGNOSTIC;
1244 cdb[2] = SesStatusPage;
1245 cdb[3] = bufsiz >> 8;
1246 cdb[4] = bufsiz & 0xff;
1249 err = ses_runcmd(ssc, cdb, 6, sdata, &amt);
1251 SES_FREE(sdata, bufsiz);
1260 tidx = cc->ses_typidx[objid].ses_tidx;
1261 oidx = cc->ses_typidx[objid].ses_oidx;
1264 if (ses_decode(sdata, amt, cc->ses_eltmap, tidx, oidx, sp)) {
1268 if (ses_encode(sdata, amt, cc->ses_eltmap, tidx, oidx, sp)) {
1271 cdb[0] = SEND_DIAGNOSTIC;
1274 cdb[3] = bufsiz >> 8;
1275 cdb[4] = bufsiz & 0xff;
1278 err = ses_runcmd(ssc, cdb, 6, sdata, &amt);
1281 SES_FREE(sdata, bufsiz);
1287 * Routines to parse returned SES data structures.
1288 * Architecture and compiler independent.
1292 ses_cfghdr(uint8_t *buffer, int buflen, SesCfgHdr *cfp)
1294 if (buflen < SES_CFGHDR_MINLEN) {
1297 gget8(buffer, 1, cfp->Nsubenc);
1298 gget32(buffer, 4, cfp->GenCode);
1303 ses_enchdr(uint8_t *buffer, int amt, uint8_t SubEncId, SesEncHdr *chp)
1306 for (s = 0; s < SubEncId; s++) {
1309 off += buffer[off+3] + 4;
1311 if (off + 3 > amt) {
1314 gget8(buffer, off+1, chp->Subencid);
1315 gget8(buffer, off+2, chp->Ntypes);
1316 gget8(buffer, off+3, chp->VEnclen);
1321 ses_encdesc(uint8_t *buffer, int amt, uint8_t SubEncId, SesEncDesc *cdp)
1323 int s, e, enclen, off = 8;
1324 for (s = 0; s < SubEncId; s++) {
1327 off += buffer[off+3] + 4;
1329 if (off + 3 > amt) {
1332 gget8(buffer, off+3, enclen);
1341 MEMCPY(cdp, &buffer[off], e - off);
1346 ses_getthdr(uint8_t *buffer, int amt, int nth, SesThdr *thp)
1350 if (amt < SES_CFGHDR_MINLEN) {
1353 for (s = 0; s < buffer[1]; s++) {
1356 off += buffer[off+3] + 4;
1358 if (off + 3 > amt) {
1361 off += buffer[off+3] + 4 + (nth * 4);
1362 if (amt < (off + 4))
1365 gget8(buffer, off++, thp->enc_type);
1366 gget8(buffer, off++, thp->enc_maxelt);
1367 gget8(buffer, off++, thp->enc_subenc);
1368 gget8(buffer, off, thp->enc_tlen);
1373 * This function needs a little explanation.
1375 * The arguments are:
1380 * These describes the raw input SES status data and length.
1384 * This is a map of the number of types for each element type
1389 * This is the element type being sought. If elt is -1,
1390 * then overall enclosure status is being sought.
1394 * This is the ordinal Mth element of type elt being sought.
1398 * This is the output area to store the status for
1399 * the Mth element of type Elt.
1403 ses_decode(char *b, int amt, uint8_t *ep, int elt, int elm, SesComStat *sp)
1408 * If it's overall enclosure status being sought, get that.
1409 * We need at least 2 bytes of status data to get that.
1414 gget8(b, 1, sp->comstatus);
1422 * Check to make sure that the Mth element is legal for type Elt.
1429 * Starting at offset 8, start skipping over the storage
1430 * for the element types we're not interested in.
1432 for (idx = 8, i = 0; i < elt; i++) {
1433 idx += ((ep[i] + 1) * 4);
1437 * Skip over Overall status for this element type.
1442 * And skip to the index for the Mth element that we're going for.
1447 * Make sure we haven't overflowed the buffer.
1453 * Retrieve the status.
1455 gget8(b, idx++, sp->comstatus);
1456 gget8(b, idx++, sp->comstat[0]);
1457 gget8(b, idx++, sp->comstat[1]);
1458 gget8(b, idx++, sp->comstat[2]);
1460 PRINTF("Get Elt 0x%x Elm 0x%x (idx %d)\n", elt, elm, idx-4);
1466 * This is the mirror function to ses_decode, but we set the 'select'
1467 * bit for the object which we're interested in. All other objects,
1468 * after a status fetch, should have that bit off. Hmm. It'd be easy
1469 * enough to ensure this, so we will.
1473 ses_encode(char *b, int amt, uint8_t *ep, int elt, int elm, SesComStat *sp)
1478 * If it's overall enclosure status being sought, get that.
1479 * We need at least 2 bytes of status data to get that.
1486 sset8(b, i, sp->comstatus & 0xf);
1488 PRINTF("set EncStat %x\n", sp->comstatus);
1494 * Check to make sure that the Mth element is legal for type Elt.
1501 * Starting at offset 8, start skipping over the storage
1502 * for the element types we're not interested in.
1504 for (idx = 8, i = 0; i < elt; i++) {
1505 idx += ((ep[i] + 1) * 4);
1509 * Skip over Overall status for this element type.
1514 * And skip to the index for the Mth element that we're going for.
1519 * Make sure we haven't overflowed the buffer.
1527 sset8(b, idx, sp->comstatus);
1528 sset8(b, idx, sp->comstat[0]);
1529 sset8(b, idx, sp->comstat[1]);
1530 sset8(b, idx, sp->comstat[2]);
1534 PRINTF("Set Elt 0x%x Elm 0x%x (idx %d) with %x %x %x %x\n",
1535 elt, elm, idx, sp->comstatus, sp->comstat[0],
1536 sp->comstat[1], sp->comstat[2]);
1540 * Now make sure all other 'Select' bits are off.
1542 for (i = 8; i < amt; i += 4) {
1547 * And make sure the INVOP bit is clear.
1555 * SAF-TE Type Device Emulation
1558 static int safte_getconfig(ses_softc_t *);
1559 static int safte_rdstat(ses_softc_t *, int);
1560 static int set_objstat_sel(ses_softc_t *, ses_objstat *, int);
1561 static int wrbuf16(ses_softc_t *, uint8_t, uint8_t, uint8_t, uint8_t, int);
1562 static void wrslot_stat(ses_softc_t *, int);
1563 static int perf_slotop(ses_softc_t *, uint8_t, uint8_t, int);
1565 #define ALL_ENC_STAT (SES_ENCSTAT_CRITICAL | SES_ENCSTAT_UNRECOV | \
1566 SES_ENCSTAT_NONCRITICAL | SES_ENCSTAT_INFO)
1568 * SAF-TE specific defines- Mandatory ones only...
1572 * READ BUFFER ('get' commands) IDs- placed in offset 2 of cdb
1574 #define SAFTE_RD_RDCFG 0x00 /* read enclosure configuration */
1575 #define SAFTE_RD_RDESTS 0x01 /* read enclosure status */
1576 #define SAFTE_RD_RDDSTS 0x04 /* read drive slot status */
1579 * WRITE BUFFER ('set' commands) IDs- placed in offset 0 of databuf
1581 #define SAFTE_WT_DSTAT 0x10 /* write device slot status */
1582 #define SAFTE_WT_SLTOP 0x12 /* perform slot operation */
1583 #define SAFTE_WT_FANSPD 0x13 /* set fan speed */
1584 #define SAFTE_WT_ACTPWS 0x14 /* turn on/off power supply */
1585 #define SAFTE_WT_GLOBAL 0x15 /* send global command */
1588 #define SAFT_SCRATCH 64
1589 #define NPSEUDO_THERM 16
1590 #define NPSEUDO_ALARM 1
1593 * Cached Configuration
1595 uint8_t Nfans; /* Number of Fans */
1596 uint8_t Npwr; /* Number of Power Supplies */
1597 uint8_t Nslots; /* Number of Device Slots */
1598 uint8_t DoorLock; /* Door Lock Installed */
1599 uint8_t Ntherm; /* Number of Temperature Sensors */
1600 uint8_t Nspkrs; /* Number of Speakers */
1601 uint8_t Nalarm; /* Number of Alarms (at least one) */
1603 * Cached Flag Bytes for Global Status
1608 * What object index ID is where various slots start.
1612 #define SAFT_ALARM_OFFSET(cc) (cc)->slotoff - 1
1615 #define SAFT_FLG1_ALARM 0x1
1616 #define SAFT_FLG1_GLOBFAIL 0x2
1617 #define SAFT_FLG1_GLOBWARN 0x4
1618 #define SAFT_FLG1_ENCPWROFF 0x8
1619 #define SAFT_FLG1_ENCFANFAIL 0x10
1620 #define SAFT_FLG1_ENCPWRFAIL 0x20
1621 #define SAFT_FLG1_ENCDRVFAIL 0x40
1622 #define SAFT_FLG1_ENCDRVWARN 0x80
1624 #define SAFT_FLG2_LOCKDOOR 0x4
1625 #define SAFT_PRIVATE sizeof (struct scfg)
1627 static char *safte_2little = "Too Little Data Returned (%d) at line %d\n";
1628 #define SAFT_BAIL(r, x, k, l) \
1630 SES_LOG(ssc, safte_2little, x, __LINE__);\
1631 SES_FREE((k), (l)); \
1637 safte_softc_init(ses_softc_t *ssc, int doinit)
1643 if (ssc->ses_nobjects) {
1644 if (ssc->ses_objmap) {
1645 SES_FREE(ssc->ses_objmap,
1646 ssc->ses_nobjects * sizeof (encobj));
1647 ssc->ses_objmap = NULL;
1649 ssc->ses_nobjects = 0;
1651 if (ssc->ses_private) {
1652 SES_FREE(ssc->ses_private, SAFT_PRIVATE);
1653 ssc->ses_private = NULL;
1658 if (ssc->ses_private == NULL) {
1659 ssc->ses_private = SES_MALLOC(SAFT_PRIVATE);
1660 if (ssc->ses_private == NULL) {
1663 MEMZERO(ssc->ses_private, SAFT_PRIVATE);
1666 ssc->ses_nobjects = 0;
1667 ssc->ses_encstat = 0;
1669 if ((err = safte_getconfig(ssc)) != 0) {
1674 * The number of objects here, as well as that reported by the
1675 * READ_BUFFER/GET_CONFIG call, are the over-temperature flags (15)
1676 * that get reported during READ_BUFFER/READ_ENC_STATUS.
1678 cc = ssc->ses_private;
1679 ssc->ses_nobjects = cc->Nfans + cc->Npwr + cc->Nslots + cc->DoorLock +
1680 cc->Ntherm + cc->Nspkrs + NPSEUDO_THERM + NPSEUDO_ALARM;
1681 ssc->ses_objmap = (encobj *)
1682 SES_MALLOC(ssc->ses_nobjects * sizeof (encobj));
1683 if (ssc->ses_objmap == NULL) {
1686 MEMZERO(ssc->ses_objmap, ssc->ses_nobjects * sizeof (encobj));
1690 * Note that this is all arranged for the convenience
1691 * in later fetches of status.
1693 for (i = 0; i < cc->Nfans; i++)
1694 ssc->ses_objmap[r++].enctype = SESTYP_FAN;
1695 cc->pwroff = (uint8_t) r;
1696 for (i = 0; i < cc->Npwr; i++)
1697 ssc->ses_objmap[r++].enctype = SESTYP_POWER;
1698 for (i = 0; i < cc->DoorLock; i++)
1699 ssc->ses_objmap[r++].enctype = SESTYP_DOORLOCK;
1700 for (i = 0; i < cc->Nspkrs; i++)
1701 ssc->ses_objmap[r++].enctype = SESTYP_ALARM;
1702 for (i = 0; i < cc->Ntherm; i++)
1703 ssc->ses_objmap[r++].enctype = SESTYP_THERM;
1704 for (i = 0; i < NPSEUDO_THERM; i++)
1705 ssc->ses_objmap[r++].enctype = SESTYP_THERM;
1706 ssc->ses_objmap[r++].enctype = SESTYP_ALARM;
1707 cc->slotoff = (uint8_t) r;
1708 for (i = 0; i < cc->Nslots; i++)
1709 ssc->ses_objmap[r++].enctype = SESTYP_DEVICE;
1714 safte_init_enc(ses_softc_t *ssc)
1717 static char cdb0[6] = { SEND_DIAGNOSTIC };
1719 err = ses_runcmd(ssc, cdb0, 6, NULL, 0);
1724 err = wrbuf16(ssc, SAFTE_WT_GLOBAL, 0, 0, 0, 1);
1729 safte_get_encstat(ses_softc_t *ssc, int slpflg)
1731 return (safte_rdstat(ssc, slpflg));
1735 safte_set_encstat(ses_softc_t *ssc, uint8_t encstat, int slpflg)
1737 struct scfg *cc = ssc->ses_private;
1741 * Since SAF-TE devices aren't necessarily sticky in terms
1742 * of state, make our soft copy of enclosure status 'sticky'-
1743 * that is, things set in enclosure status stay set (as implied
1744 * by conditions set in reading object status) until cleared.
1746 ssc->ses_encstat &= ~ALL_ENC_STAT;
1747 ssc->ses_encstat |= (encstat & ALL_ENC_STAT);
1748 ssc->ses_encstat |= ENCI_SVALID;
1749 cc->flag1 &= ~(SAFT_FLG1_ALARM|SAFT_FLG1_GLOBFAIL|SAFT_FLG1_GLOBWARN);
1750 if ((encstat & (SES_ENCSTAT_CRITICAL|SES_ENCSTAT_UNRECOV)) != 0) {
1751 cc->flag1 |= SAFT_FLG1_ALARM|SAFT_FLG1_GLOBFAIL;
1752 } else if ((encstat & SES_ENCSTAT_NONCRITICAL) != 0) {
1753 cc->flag1 |= SAFT_FLG1_GLOBWARN;
1755 return (wrbuf16(ssc, SAFTE_WT_GLOBAL, cc->flag1, cc->flag2, 0, slpflg));
1759 safte_get_objstat(ses_softc_t *ssc, ses_objstat *obp, int slpflg)
1761 int i = (int)obp->obj_id;
1763 if ((ssc->ses_encstat & ENCI_SVALID) == 0 ||
1764 (ssc->ses_objmap[i].svalid) == 0) {
1765 int err = safte_rdstat(ssc, slpflg);
1769 obp->cstat[0] = ssc->ses_objmap[i].encstat[0];
1770 obp->cstat[1] = ssc->ses_objmap[i].encstat[1];
1771 obp->cstat[2] = ssc->ses_objmap[i].encstat[2];
1772 obp->cstat[3] = ssc->ses_objmap[i].encstat[3];
1778 safte_set_objstat(ses_softc_t *ssc, ses_objstat *obp, int slp)
1785 SES_DLOG(ssc, "safte_set_objstat(%d): %x %x %x %x\n",
1786 (int)obp->obj_id, obp->cstat[0], obp->cstat[1], obp->cstat[2],
1790 * If this is clear, we don't do diddly.
1792 if ((obp->cstat[0] & SESCTL_CSEL) == 0) {
1798 * Check to see if the common bits are set and do them first.
1800 if (obp->cstat[0] & ~SESCTL_CSEL) {
1801 err = set_objstat_sel(ssc, obp, slp);
1806 cc = ssc->ses_private;
1810 idx = (int)obp->obj_id;
1811 ep = &ssc->ses_objmap[idx];
1813 switch (ep->enctype) {
1818 * XXX: I should probably cache the previous state
1819 * XXX: of SESCTL_DEVOFF so that when it goes from
1820 * XXX: true to false I can then set PREPARE FOR OPERATION
1821 * XXX: flag in PERFORM SLOT OPERATION write buffer command.
1823 if (obp->cstat[2] & (SESCTL_RQSINS|SESCTL_RQSRMV)) {
1826 if (obp->cstat[2] & SESCTL_RQSID) {
1829 err = perf_slotop(ssc, (uint8_t) idx - (uint8_t) cc->slotoff,
1833 if (obp->cstat[3] & SESCTL_RQSFLT) {
1838 if (ep->priv & 0xc6) {
1841 ep->priv |= 0x1; /* no errors */
1843 wrslot_stat(ssc, slp);
1847 if (obp->cstat[3] & SESCTL_RQSTFAIL) {
1848 cc->flag1 |= SAFT_FLG1_ENCPWRFAIL;
1850 cc->flag1 &= ~SAFT_FLG1_ENCPWRFAIL;
1852 err = wrbuf16(ssc, SAFTE_WT_GLOBAL, cc->flag1,
1856 if (obp->cstat[3] & SESCTL_RQSTON) {
1857 wrbuf16(ssc, SAFTE_WT_ACTPWS,
1858 idx - cc->pwroff, 0, 0, slp);
1860 wrbuf16(ssc, SAFTE_WT_ACTPWS,
1861 idx - cc->pwroff, 0, 1, slp);
1865 if (obp->cstat[3] & SESCTL_RQSTFAIL) {
1866 cc->flag1 |= SAFT_FLG1_ENCFANFAIL;
1868 cc->flag1 &= ~SAFT_FLG1_ENCFANFAIL;
1870 err = wrbuf16(ssc, SAFTE_WT_GLOBAL, cc->flag1,
1874 if (obp->cstat[3] & SESCTL_RQSTON) {
1876 if ((obp->cstat[3] & 0x7) == 7) {
1878 } else if ((obp->cstat[3] & 0x7) == 6) {
1880 } else if ((obp->cstat[3] & 0x7) == 4) {
1885 wrbuf16(ssc, SAFTE_WT_FANSPD, idx, fsp, 0, slp);
1887 wrbuf16(ssc, SAFTE_WT_FANSPD, idx, 0, 0, slp);
1890 case SESTYP_DOORLOCK:
1891 if (obp->cstat[3] & 0x1) {
1892 cc->flag2 &= ~SAFT_FLG2_LOCKDOOR;
1894 cc->flag2 |= SAFT_FLG2_LOCKDOOR;
1896 wrbuf16(ssc, SAFTE_WT_GLOBAL, cc->flag1, cc->flag2, 0, slp);
1900 * On all nonzero but the 'muted' bit, we turn on the alarm,
1902 obp->cstat[3] &= ~0xa;
1903 if (obp->cstat[3] & 0x40) {
1904 cc->flag2 &= ~SAFT_FLG1_ALARM;
1905 } else if (obp->cstat[3] != 0) {
1906 cc->flag2 |= SAFT_FLG1_ALARM;
1908 cc->flag2 &= ~SAFT_FLG1_ALARM;
1910 ep->priv = obp->cstat[3];
1911 wrbuf16(ssc, SAFTE_WT_GLOBAL, cc->flag1, cc->flag2, 0, slp);
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 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 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 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 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 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);