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>
38 #include <sys/errno.h>
39 #include <sys/devicestat.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;
395 * Disallow CAM access if RESTRICTEDROOT
397 if (caps_priv_check_self(SYSCAP_RESTRICTEDROOT))
400 periph = cam_extend_get(sesperiphs, SESUNIT(dev));
401 if (periph == NULL) {
405 if (cam_periph_acquire(periph) != CAM_REQ_CMP) {
406 cam_periph_unlock(periph);
410 cam_periph_lock(periph);
412 softc = (struct ses_softc *)periph->softc;
414 if (softc->ses_flags & SES_FLAG_INVALID) {
418 if (softc->ses_flags & SES_FLAG_OPEN) {
422 if (softc->ses_vec.softc_init == NULL) {
427 softc->ses_flags |= SES_FLAG_OPEN;
428 if ((softc->ses_flags & SES_FLAG_INITIALIZED) == 0) {
429 error = (*softc->ses_vec.softc_init)(softc, 1);
431 softc->ses_flags &= ~SES_FLAG_OPEN;
433 softc->ses_flags |= SES_FLAG_INITIALIZED;
437 cam_periph_unlock(periph);
439 cam_periph_release(periph);
445 sesclose(struct dev_close_args *ap)
447 cdev_t dev = ap->a_head.a_dev;
448 struct cam_periph *periph;
449 struct ses_softc *softc;
453 periph = cam_extend_get(sesperiphs, unit);
457 cam_periph_lock(periph);
459 softc = (struct ses_softc *)periph->softc;
460 softc->ses_flags &= ~SES_FLAG_OPEN;
462 cam_periph_unlock(periph);
463 cam_periph_release(periph);
469 sesstart(struct cam_periph *p, union ccb *sccb)
471 if (p->immediate_priority <= p->pinfo.priority) {
472 SLIST_INSERT_HEAD(&p->ccb_list, &sccb->ccb_h, periph_links.sle);
473 p->immediate_priority = CAM_PRIORITY_NONE;
474 wakeup(&p->ccb_list);
479 sesdone(struct cam_periph *periph, union ccb *dccb)
481 wakeup(&dccb->ccb_h.cbfcnp);
485 seserror(union ccb *ccb, u_int32_t cflags, u_int32_t sflags)
487 struct ses_softc *softc;
488 struct cam_periph *periph;
490 periph = xpt_path_periph(ccb->ccb_h.path);
491 softc = (struct ses_softc *)periph->softc;
493 return (cam_periph_error(ccb, cflags, sflags, &softc->ses_saved_ccb));
497 sesioctl(struct dev_ioctl_args *ap)
499 cdev_t dev = ap->a_head.a_dev;
500 struct cam_periph *periph;
503 ses_object obj, *uobj;
504 struct ses_softc *ssc;
510 addr = *((caddr_t *)ap->a_data);
514 periph = cam_extend_get(sesperiphs, SESUNIT(dev));
518 CAM_DEBUG(periph->path, CAM_DEBUG_TRACE, ("entering sesioctl\n"));
520 cam_periph_lock(periph);
521 ssc = (struct ses_softc *)periph->softc;
524 * Now check to see whether we're initialized or not.
526 if ((ssc->ses_flags & SES_FLAG_INITIALIZED) == 0) {
527 cam_periph_unlock(periph);
530 cam_periph_unlock(periph);
534 CAM_DEBUG(periph->path, CAM_DEBUG_TRACE,
535 ("trying to do ioctl %#lx\n", ap->a_cmd));
538 * If this command can change the device's state,
539 * we must have the device open for writing.
543 case SESIOC_GETOBJMAP:
544 case SESIOC_GETENCSTAT:
545 case SESIOC_GETOBJSTAT:
548 if ((ap->a_fflag & FWRITE) == 0) {
555 error = copyout(&ssc->ses_nobjects, addr,
556 sizeof (ssc->ses_nobjects));
559 case SESIOC_GETOBJMAP:
561 * XXX Dropping the lock while copying multiple segments is
564 cam_periph_lock(periph);
565 for (uobj = addr, i = 0; i != ssc->ses_nobjects; i++, uobj++) {
567 obj.subencid = ssc->ses_objmap[i].subenclosure;
568 obj.object_type = ssc->ses_objmap[i].enctype;
569 cam_periph_unlock(periph);
570 error = copyout(&obj, uobj, sizeof (ses_object));
571 cam_periph_lock(periph);
576 cam_periph_unlock(periph);
579 case SESIOC_GETENCSTAT:
580 cam_periph_lock(periph);
581 error = (*ssc->ses_vec.get_encstat)(ssc, 1);
583 cam_periph_unlock(periph);
586 tmp = ssc->ses_encstat & ~ENCI_SVALID;
587 cam_periph_unlock(periph);
588 error = copyout(&tmp, addr, sizeof (ses_encstat));
589 ssc->ses_encstat = tmp;
592 case SESIOC_SETENCSTAT:
593 error = copyin(addr, &tmp, sizeof (ses_encstat));
596 cam_periph_lock(periph);
597 error = (*ssc->ses_vec.set_encstat)(ssc, tmp, 1);
598 cam_periph_unlock(periph);
601 case SESIOC_GETOBJSTAT:
602 error = copyin(addr, &objs, sizeof (ses_objstat));
605 if (objs.obj_id >= ssc->ses_nobjects) {
609 cam_periph_lock(periph);
610 error = (*ssc->ses_vec.get_objstat)(ssc, &objs, 1);
611 cam_periph_unlock(periph);
614 error = copyout(&objs, addr, sizeof (ses_objstat));
616 * Always (for now) invalidate entry.
618 ssc->ses_objmap[objs.obj_id].svalid = 0;
621 case SESIOC_SETOBJSTAT:
622 error = copyin(addr, &objs, sizeof (ses_objstat));
626 if (objs.obj_id >= ssc->ses_nobjects) {
630 cam_periph_lock(periph);
631 error = (*ssc->ses_vec.set_objstat)(ssc, &objs, 1);
632 cam_periph_unlock(periph);
635 * Always (for now) invalidate entry.
637 ssc->ses_objmap[objs.obj_id].svalid = 0;
642 cam_periph_lock(periph);
643 error = (*ssc->ses_vec.init_enc)(ssc);
644 cam_periph_unlock(periph);
648 cam_periph_lock(periph);
649 error = cam_periph_ioctl(periph, ap->a_cmd, ap->a_data, seserror);
650 cam_periph_unlock(periph);
656 #define SES_CFLAGS CAM_RETRY_SELTO
657 #define SES_FLAGS SF_NO_PRINT | SF_RETRY_UA
659 ses_runcmd(struct ses_softc *ssc, char *cdb, int cdbl, char *dptr, int *dlenp)
666 if ((dlen = *dlenp) < 0) {
677 if (cdbl > IOCDBLEN) {
681 ccb = cam_periph_getccb(ssc->periph, 1);
682 cam_fill_csio(&ccb->csio, 0, sesdone, ddf, MSG_SIMPLE_Q_TAG, dptr,
683 dlen, sizeof (struct scsi_sense_data), cdbl, 60 * 1000);
684 bcopy(cdb, ccb->csio.cdb_io.cdb_bytes, cdbl);
686 error = cam_periph_runccb(ccb, seserror, SES_CFLAGS, SES_FLAGS, NULL);
687 if ((ccb->ccb_h.status & CAM_DEV_QFRZN) != 0)
688 cam_release_devq(ccb->ccb_h.path, 0, 0, 0, FALSE);
695 *dlenp = ccb->csio.resid;
698 xpt_release_ccb(ccb);
703 ses_log(struct ses_softc *ssc, const char *fmt, ...)
707 kprintf("%s%d: ", ssc->periph->periph_name, ssc->periph->unit_number);
714 * The code after this point runs on many platforms,
715 * so forgive the slightly awkward and nonconforming
720 * Is this a device that supports enclosure services?
722 * It's a a pretty simple ruleset- if it is device type 0x0D (13), it's
723 * an SES device. If it happens to be an old UNISYS SEN device, we can
727 #define SAFTE_START 44
729 #define SAFTE_LEN SAFTE_END-SAFTE_START
732 ses_type(void *buf, int buflen)
734 unsigned char *iqd = buf;
736 if (buflen < 8+SEN_ID_LEN)
739 if ((iqd[0] & 0x1f) == T_ENCLOSURE) {
740 if (STRNCMP(&iqd[8], SEN_ID, SEN_ID_LEN) == 0) {
742 } else if ((iqd[2] & 0x7) > 2) {
745 return (SES_SES_SCSI2);
750 #ifdef SES_ENABLE_PASSTHROUGH
751 if ((iqd[6] & 0x40) && (iqd[2] & 0x7) >= 2) {
753 * PassThrough Device.
755 return (SES_SES_PASSTHROUGH);
760 * The comparison is short for a reason-
761 * some vendors were chopping it short.
764 if (buflen < SAFTE_END - 2) {
768 if (STRNCMP((char *)&iqd[SAFTE_START], "SAF-TE", SAFTE_LEN - 2) == 0) {
775 * SES Native Type Device Support
779 * SES Diagnostic Page Codes
785 #define SesStatusPage SesControlPage
788 #define SesStringIn SesStringOut
790 #define SesThresholdIn SesThresholdOut
792 #define SesArrayStatus SesArrayControl
793 SesElementDescriptor,
802 * Minimum amount of data, starting from byte 0, to have
805 #define SES_CFGHDR_MINLEN 12
808 * Minimum amount of data, starting from byte 0, to have
809 * the config header and one enclosure header.
811 #define SES_ENCHDR_MINLEN 48
814 * Take this value, subtract it from VEnclen and you know
815 * the length of the vendor unique bytes.
817 #define SES_ENCHDR_VMIN 36
820 * SES Data Structures
824 uint32_t GenCode; /* Generation Code */
825 uint8_t Nsubenc; /* Number of Subenclosures */
829 uint8_t Subencid; /* SubEnclosure Identifier */
830 uint8_t Ntypes; /* # of supported types */
831 uint8_t VEnclen; /* Enclosure Descriptor Length */
835 uint8_t encWWN[8]; /* XXX- Not Right Yet */
843 uint8_t enc_type; /* type of element */
844 uint8_t enc_maxelt; /* maximum supported */
845 uint8_t enc_subenc; /* in SubEnc # N */
846 uint8_t enc_tlen; /* Type Descriptor Text Length */
860 uint8_t ses_ntypes; /* total number of types supported */
863 * We need to keep a type index as well as an
864 * object index for each object in an enclosure.
866 struct typidx *ses_typidx;
869 * We also need to keep track of the number of elements
870 * per type of element. This is needed later so that we
871 * can find precisely in the returned status data the
872 * status for the Nth element of the Kth type.
874 uint8_t * ses_eltmap;
879 * (de)canonicalization defines
881 #define sbyte(x, byte) ((((uint32_t)(x)) >> (byte * 8)) & 0xff)
882 #define sbit(x, bit) (((uint32_t)(x)) << bit)
883 #define sset8(outp, idx, sval) (((uint8_t *)(outp))[idx++]) = sbyte(sval, 0)
885 #define sset16(outp, idx, sval) \
886 (((uint8_t *)(outp))[idx++]) = sbyte(sval, 1), \
887 (((uint8_t *)(outp))[idx++]) = sbyte(sval, 0)
890 #define sset24(outp, idx, sval) \
891 (((uint8_t *)(outp))[idx++]) = sbyte(sval, 2), \
892 (((uint8_t *)(outp))[idx++]) = sbyte(sval, 1), \
893 (((uint8_t *)(outp))[idx++]) = sbyte(sval, 0)
896 #define sset32(outp, idx, sval) \
897 (((uint8_t *)(outp))[idx++]) = sbyte(sval, 3), \
898 (((uint8_t *)(outp))[idx++]) = sbyte(sval, 2), \
899 (((uint8_t *)(outp))[idx++]) = sbyte(sval, 1), \
900 (((uint8_t *)(outp))[idx++]) = sbyte(sval, 0)
902 #define gbyte(x, byte) ((((uint32_t)(x)) & 0xff) << (byte * 8))
903 #define gbit(lv, in, idx, shft, mask) lv = ((in[idx] >> shft) & mask)
904 #define sget8(inp, idx, lval) lval = (((uint8_t *)(inp))[idx++])
905 #define gget8(inp, idx, lval) lval = (((uint8_t *)(inp))[idx])
907 #define sget16(inp, idx, lval) \
908 lval = gbyte((((uint8_t *)(inp))[idx]), 1) | \
909 (((uint8_t *)(inp))[idx+1]), idx += 2
911 #define gget16(inp, idx, lval) \
912 lval = gbyte((((uint8_t *)(inp))[idx]), 1) | \
913 (((uint8_t *)(inp))[idx+1])
915 #define sget24(inp, idx, lval) \
916 lval = gbyte((((uint8_t *)(inp))[idx]), 2) | \
917 gbyte((((uint8_t *)(inp))[idx+1]), 1) | \
918 (((uint8_t *)(inp))[idx+2]), idx += 3
920 #define gget24(inp, idx, lval) \
921 lval = gbyte((((uint8_t *)(inp))[idx]), 2) | \
922 gbyte((((uint8_t *)(inp))[idx+1]), 1) | \
923 (((uint8_t *)(inp))[idx+2])
925 #define sget32(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]), idx += 4
931 #define gget32(inp, idx, lval) \
932 lval = gbyte((((uint8_t *)(inp))[idx]), 3) | \
933 gbyte((((uint8_t *)(inp))[idx+1]), 2) | \
934 gbyte((((uint8_t *)(inp))[idx+2]), 1) | \
935 (((uint8_t *)(inp))[idx+3])
938 #define CFLEN (256 + SES_ENCHDR_MINLEN)
941 * Routines specific && private to SES only
944 static int ses_getconfig(ses_softc_t *);
945 static int ses_getputstat(ses_softc_t *, int, SesComStat *, int, int);
946 static int ses_cfghdr(uint8_t *, int, SesCfgHdr *);
947 static int ses_enchdr(uint8_t *, int, uint8_t, SesEncHdr *);
948 static int ses_encdesc(uint8_t *, int, uint8_t, SesEncDesc *);
949 static int ses_getthdr(uint8_t *, int, int, SesThdr *);
950 static int ses_decode(char *, int, uint8_t *, int, int, SesComStat *);
951 static int ses_encode(char *, int, uint8_t *, int, int, SesComStat *);
954 ses_softc_init(ses_softc_t *ssc, int doinit)
958 if (ssc->ses_nobjects) {
959 SES_FREE(ssc->ses_objmap,
960 ssc->ses_nobjects * sizeof (encobj));
961 ssc->ses_objmap = NULL;
963 if ((cc = ssc->ses_private) != NULL) {
964 if (cc->ses_eltmap && cc->ses_ntypes) {
965 SES_FREE(cc->ses_eltmap, cc->ses_ntypes);
966 cc->ses_eltmap = NULL;
969 if (cc->ses_typidx && ssc->ses_nobjects) {
970 SES_FREE(cc->ses_typidx,
971 ssc->ses_nobjects * sizeof (struct typidx));
972 cc->ses_typidx = NULL;
974 SES_FREE(cc, sizeof (struct sscfg));
975 ssc->ses_private = NULL;
977 ssc->ses_nobjects = 0;
980 if (ssc->ses_private == NULL) {
981 ssc->ses_private = SES_MALLOC(sizeof (struct sscfg));
983 if (ssc->ses_private == NULL) {
986 ssc->ses_nobjects = 0;
987 ssc->ses_encstat = 0;
988 return (ses_getconfig(ssc));
992 ses_init_enc(ses_softc_t *ssc)
998 ses_get_encstat(ses_softc_t *ssc, int slpflag)
1003 if ((status = ses_getputstat(ssc, -1, &ComStat, slpflag, 1)) != 0) {
1006 ssc->ses_encstat = ComStat.comstatus | ENCI_SVALID;
1011 ses_set_encstat(ses_softc_t *ssc, uint8_t encstat, int slpflag)
1016 ComStat.comstatus = encstat & 0xf;
1017 if ((status = ses_getputstat(ssc, -1, &ComStat, slpflag, 0)) != 0) {
1020 ssc->ses_encstat = encstat & 0xf; /* note no SVALID set */
1025 ses_get_objstat(ses_softc_t *ssc, ses_objstat *obp, int slpflag)
1027 int i = (int)obp->obj_id;
1029 if (ssc->ses_objmap[i].svalid == 0) {
1031 int err = ses_getputstat(ssc, i, &ComStat, slpflag, 1);
1034 ssc->ses_objmap[i].encstat[0] = ComStat.comstatus;
1035 ssc->ses_objmap[i].encstat[1] = ComStat.comstat[0];
1036 ssc->ses_objmap[i].encstat[2] = ComStat.comstat[1];
1037 ssc->ses_objmap[i].encstat[3] = ComStat.comstat[2];
1038 ssc->ses_objmap[i].svalid = 1;
1040 obp->cstat[0] = ssc->ses_objmap[i].encstat[0];
1041 obp->cstat[1] = ssc->ses_objmap[i].encstat[1];
1042 obp->cstat[2] = ssc->ses_objmap[i].encstat[2];
1043 obp->cstat[3] = ssc->ses_objmap[i].encstat[3];
1048 ses_set_objstat(ses_softc_t *ssc, ses_objstat *obp, int slpflag)
1053 * If this is clear, we don't do diddly.
1055 if ((obp->cstat[0] & SESCTL_CSEL) == 0) {
1058 ComStat.comstatus = obp->cstat[0];
1059 ComStat.comstat[0] = obp->cstat[1];
1060 ComStat.comstat[1] = obp->cstat[2];
1061 ComStat.comstat[2] = obp->cstat[3];
1062 err = ses_getputstat(ssc, (int)obp->obj_id, &ComStat, slpflag, 0);
1063 ssc->ses_objmap[(int)obp->obj_id].svalid = 0;
1068 ses_getconfig(ses_softc_t *ssc)
1075 int err, amt, i, nobj, ntype, maxima;
1076 char storage[CFLEN], *sdata;
1077 static char cdb[6] = {
1078 RECEIVE_DIAGNOSTIC, 0x1, SesConfigPage, SCSZ >> 8, SCSZ & 0xff, 0
1081 cc = ssc->ses_private;
1086 sdata = SES_MALLOC(SCSZ);
1091 err = ses_runcmd(ssc, cdb, 6, sdata, &amt);
1093 SES_FREE(sdata, SCSZ);
1098 if (ses_cfghdr((uint8_t *) sdata, amt, &cf)) {
1099 SES_LOG(ssc, "Unable to parse SES Config Header\n");
1100 SES_FREE(sdata, SCSZ);
1103 if (amt < SES_ENCHDR_MINLEN) {
1104 SES_LOG(ssc, "runt enclosure length (%d)\n", amt);
1105 SES_FREE(sdata, SCSZ);
1109 SES_VLOG(ssc, "GenCode %x %d Subenclosures\n", cf.GenCode, cf.Nsubenc);
1112 * Now waltz through all the subenclosures toting up the
1113 * number of types available in each. For this, we only
1114 * really need the enclosure header. However, we get the
1115 * enclosure descriptor for debug purposes, as well
1116 * as self-consistency checking purposes.
1119 maxima = cf.Nsubenc + 1;
1120 cdp = (SesEncDesc *) storage;
1121 for (ntype = i = 0; i < maxima; i++) {
1122 MEMZERO((caddr_t)cdp, sizeof (*cdp));
1123 if (ses_enchdr((uint8_t *) sdata, amt, i, &hd)) {
1124 SES_LOG(ssc, "Cannot Extract Enclosure Header %d\n", i);
1125 SES_FREE(sdata, SCSZ);
1128 SES_VLOG(ssc, " SubEnclosure ID %d, %d Types With this ID, En"
1129 "closure Length %d\n", hd.Subencid, hd.Ntypes, hd.VEnclen);
1131 if (ses_encdesc((uint8_t *)sdata, amt, i, cdp)) {
1132 SES_LOG(ssc, "Can't get Enclosure Descriptor %d\n", i);
1133 SES_FREE(sdata, SCSZ);
1136 SES_VLOG(ssc, " WWN: %02x%02x%02x%02x%02x%02x%02x%02x\n",
1137 cdp->encWWN[0], cdp->encWWN[1], cdp->encWWN[2],
1138 cdp->encWWN[3], cdp->encWWN[4], cdp->encWWN[5],
1139 cdp->encWWN[6], cdp->encWWN[7]);
1144 * Now waltz through all the types that are available, getting
1145 * the type header so we can start adding up the number of
1146 * objects available.
1148 for (nobj = i = 0; i < ntype; i++) {
1149 if (ses_getthdr((uint8_t *)sdata, amt, i, &thdr)) {
1150 SES_LOG(ssc, "Can't get Enclosure Type Header %d\n", i);
1151 SES_FREE(sdata, SCSZ);
1154 SES_LOG(ssc, " Type Desc[%d]: Type 0x%x, MaxElt %d, In Subenc "
1155 "%d, Text Length %d\n", i, thdr.enc_type, thdr.enc_maxelt,
1156 thdr.enc_subenc, thdr.enc_tlen);
1157 nobj += thdr.enc_maxelt;
1162 * Now allocate the object array and type map.
1165 ssc->ses_objmap = SES_MALLOC(nobj * sizeof (encobj));
1166 cc->ses_typidx = SES_MALLOC(nobj * sizeof (struct typidx));
1167 cc->ses_eltmap = SES_MALLOC(ntype);
1169 if (ssc->ses_objmap == NULL || cc->ses_typidx == NULL ||
1170 cc->ses_eltmap == NULL) {
1171 if (ssc->ses_objmap) {
1172 SES_FREE(ssc->ses_objmap, (nobj * sizeof (encobj)));
1173 ssc->ses_objmap = NULL;
1175 if (cc->ses_typidx) {
1176 SES_FREE(cc->ses_typidx,
1177 (nobj * sizeof (struct typidx)));
1178 cc->ses_typidx = NULL;
1180 if (cc->ses_eltmap) {
1181 SES_FREE(cc->ses_eltmap, ntype);
1182 cc->ses_eltmap = NULL;
1184 SES_FREE(sdata, SCSZ);
1187 MEMZERO(ssc->ses_objmap, nobj * sizeof (encobj));
1188 MEMZERO(cc->ses_typidx, nobj * sizeof (struct typidx));
1189 MEMZERO(cc->ses_eltmap, ntype);
1190 cc->ses_ntypes = (uint8_t) ntype;
1191 ssc->ses_nobjects = nobj;
1194 * Now waltz through the # of types again to fill in the types
1195 * (and subenclosure ids) of the allocated objects.
1198 for (i = 0; i < ntype; i++) {
1200 if (ses_getthdr((uint8_t *)sdata, amt, i, &thdr)) {
1203 cc->ses_eltmap[i] = thdr.enc_maxelt;
1204 for (j = 0; j < thdr.enc_maxelt; j++) {
1205 cc->ses_typidx[nobj].ses_tidx = i;
1206 cc->ses_typidx[nobj].ses_oidx = j;
1207 ssc->ses_objmap[nobj].subenclosure = thdr.enc_subenc;
1208 ssc->ses_objmap[nobj++].enctype = thdr.enc_type;
1211 SES_FREE(sdata, SCSZ);
1216 ses_getputstat(ses_softc_t *ssc, int objid, SesComStat *sp, int slp, int in)
1219 int err, amt, bufsiz, tidx, oidx;
1220 char cdb[6], *sdata;
1222 bzero(sp, sizeof(*sp));
1223 cc = ssc->ses_private;
1229 * If we're just getting overall enclosure status,
1230 * we only need 2 bytes of data storage.
1232 * If we're getting anything else, we know how much
1233 * storage we need by noting that starting at offset
1234 * 8 in returned data, all object status bytes are 4
1235 * bytes long, and are stored in chunks of types(M)
1236 * and nth+1 instances of type M.
1241 bufsiz = (ssc->ses_nobjects * 4) + (cc->ses_ntypes * 4) + 8;
1243 sdata = SES_MALLOC(bufsiz);
1247 cdb[0] = RECEIVE_DIAGNOSTIC;
1249 cdb[2] = SesStatusPage;
1250 cdb[3] = bufsiz >> 8;
1251 cdb[4] = bufsiz & 0xff;
1254 err = ses_runcmd(ssc, cdb, 6, sdata, &amt);
1256 SES_FREE(sdata, bufsiz);
1265 tidx = cc->ses_typidx[objid].ses_tidx;
1266 oidx = cc->ses_typidx[objid].ses_oidx;
1269 if (ses_decode(sdata, amt, cc->ses_eltmap, tidx, oidx, sp)) {
1273 if (ses_encode(sdata, amt, cc->ses_eltmap, tidx, oidx, sp)) {
1276 cdb[0] = SEND_DIAGNOSTIC;
1279 cdb[3] = bufsiz >> 8;
1280 cdb[4] = bufsiz & 0xff;
1283 err = ses_runcmd(ssc, cdb, 6, sdata, &amt);
1286 SES_FREE(sdata, bufsiz);
1292 * Routines to parse returned SES data structures.
1293 * Architecture and compiler independent.
1297 ses_cfghdr(uint8_t *buffer, int buflen, SesCfgHdr *cfp)
1299 if (buflen < SES_CFGHDR_MINLEN) {
1302 gget8(buffer, 1, cfp->Nsubenc);
1303 gget32(buffer, 4, cfp->GenCode);
1308 ses_enchdr(uint8_t *buffer, int amt, uint8_t SubEncId, SesEncHdr *chp)
1311 for (s = 0; s < SubEncId; s++) {
1314 off += buffer[off+3] + 4;
1316 if (off + 3 > amt) {
1319 gget8(buffer, off+1, chp->Subencid);
1320 gget8(buffer, off+2, chp->Ntypes);
1321 gget8(buffer, off+3, chp->VEnclen);
1326 ses_encdesc(uint8_t *buffer, int amt, uint8_t SubEncId, SesEncDesc *cdp)
1328 int s, e, enclen, off = 8;
1329 for (s = 0; s < SubEncId; s++) {
1332 off += buffer[off+3] + 4;
1334 if (off + 3 > amt) {
1337 gget8(buffer, off+3, enclen);
1346 MEMCPY(cdp, &buffer[off], e - off);
1351 ses_getthdr(uint8_t *buffer, int amt, int nth, SesThdr *thp)
1355 if (amt < SES_CFGHDR_MINLEN) {
1358 for (s = 0; s < buffer[1]; s++) {
1361 off += buffer[off+3] + 4;
1363 if (off + 3 > amt) {
1366 off += buffer[off+3] + 4 + (nth * 4);
1367 if (amt < (off + 4))
1370 gget8(buffer, off++, thp->enc_type);
1371 gget8(buffer, off++, thp->enc_maxelt);
1372 gget8(buffer, off++, thp->enc_subenc);
1373 gget8(buffer, off, thp->enc_tlen);
1378 * This function needs a little explanation.
1380 * The arguments are:
1385 * These describes the raw input SES status data and length.
1389 * This is a map of the number of types for each element type
1394 * This is the element type being sought. If elt is -1,
1395 * then overall enclosure status is being sought.
1399 * This is the ordinal Mth element of type elt being sought.
1403 * This is the output area to store the status for
1404 * the Mth element of type Elt.
1408 ses_decode(char *b, int amt, uint8_t *ep, int elt, int elm, SesComStat *sp)
1413 * If it's overall enclosure status being sought, get that.
1414 * We need at least 2 bytes of status data to get that.
1419 gget8(b, 1, sp->comstatus);
1427 * Check to make sure that the Mth element is legal for type Elt.
1434 * Starting at offset 8, start skipping over the storage
1435 * for the element types we're not interested in.
1437 for (idx = 8, i = 0; i < elt; i++) {
1438 idx += ((ep[i] + 1) * 4);
1442 * Skip over Overall status for this element type.
1447 * And skip to the index for the Mth element that we're going for.
1452 * Make sure we haven't overflowed the buffer.
1458 * Retrieve the status.
1460 gget8(b, idx++, sp->comstatus);
1461 gget8(b, idx++, sp->comstat[0]);
1462 gget8(b, idx++, sp->comstat[1]);
1463 gget8(b, idx++, sp->comstat[2]);
1465 PRINTF("Get Elt 0x%x Elm 0x%x (idx %d)\n", elt, elm, idx-4);
1471 * This is the mirror function to ses_decode, but we set the 'select'
1472 * bit for the object which we're interested in. All other objects,
1473 * after a status fetch, should have that bit off. Hmm. It'd be easy
1474 * enough to ensure this, so we will.
1478 ses_encode(char *b, int amt, uint8_t *ep, int elt, int elm, SesComStat *sp)
1483 * If it's overall enclosure status being sought, get that.
1484 * We need at least 2 bytes of status data to get that.
1491 sset8(b, i, sp->comstatus & 0xf);
1493 PRINTF("set EncStat %x\n", sp->comstatus);
1499 * Check to make sure that the Mth element is legal for type Elt.
1506 * Starting at offset 8, start skipping over the storage
1507 * for the element types we're not interested in.
1509 for (idx = 8, i = 0; i < elt; i++) {
1510 idx += ((ep[i] + 1) * 4);
1514 * Skip over Overall status for this element type.
1519 * And skip to the index for the Mth element that we're going for.
1524 * Make sure we haven't overflowed the buffer.
1532 sset8(b, idx, sp->comstatus);
1533 sset8(b, idx, sp->comstat[0]);
1534 sset8(b, idx, sp->comstat[1]);
1535 sset8(b, idx, sp->comstat[2]);
1539 PRINTF("Set Elt 0x%x Elm 0x%x (idx %d) with %x %x %x %x\n",
1540 elt, elm, idx, sp->comstatus, sp->comstat[0],
1541 sp->comstat[1], sp->comstat[2]);
1545 * Now make sure all other 'Select' bits are off.
1547 for (i = 8; i < amt; i += 4) {
1552 * And make sure the INVOP bit is clear.
1560 * SAF-TE Type Device Emulation
1563 static int safte_getconfig(ses_softc_t *);
1564 static int safte_rdstat(ses_softc_t *, int);
1565 static int set_objstat_sel(ses_softc_t *, ses_objstat *, int);
1566 static int wrbuf16(ses_softc_t *, uint8_t, uint8_t, uint8_t, uint8_t, int);
1567 static void wrslot_stat(ses_softc_t *, int);
1568 static int perf_slotop(ses_softc_t *, uint8_t, uint8_t, int);
1570 #define ALL_ENC_STAT (SES_ENCSTAT_CRITICAL | SES_ENCSTAT_UNRECOV | \
1571 SES_ENCSTAT_NONCRITICAL | SES_ENCSTAT_INFO)
1573 * SAF-TE specific defines- Mandatory ones only...
1577 * READ BUFFER ('get' commands) IDs- placed in offset 2 of cdb
1579 #define SAFTE_RD_RDCFG 0x00 /* read enclosure configuration */
1580 #define SAFTE_RD_RDESTS 0x01 /* read enclosure status */
1581 #define SAFTE_RD_RDDSTS 0x04 /* read drive slot status */
1584 * WRITE BUFFER ('set' commands) IDs- placed in offset 0 of databuf
1586 #define SAFTE_WT_DSTAT 0x10 /* write device slot status */
1587 #define SAFTE_WT_SLTOP 0x12 /* perform slot operation */
1588 #define SAFTE_WT_FANSPD 0x13 /* set fan speed */
1589 #define SAFTE_WT_ACTPWS 0x14 /* turn on/off power supply */
1590 #define SAFTE_WT_GLOBAL 0x15 /* send global command */
1593 #define SAFT_SCRATCH 64
1594 #define NPSEUDO_THERM 16
1595 #define NPSEUDO_ALARM 1
1598 * Cached Configuration
1600 uint8_t Nfans; /* Number of Fans */
1601 uint8_t Npwr; /* Number of Power Supplies */
1602 uint8_t Nslots; /* Number of Device Slots */
1603 uint8_t DoorLock; /* Door Lock Installed */
1604 uint8_t Ntherm; /* Number of Temperature Sensors */
1605 uint8_t Nspkrs; /* Number of Speakers */
1606 uint8_t Nalarm; /* Number of Alarms (at least one) */
1608 * Cached Flag Bytes for Global Status
1613 * What object index ID is where various slots start.
1617 #define SAFT_ALARM_OFFSET(cc) (cc)->slotoff - 1
1620 #define SAFT_FLG1_ALARM 0x1
1621 #define SAFT_FLG1_GLOBFAIL 0x2
1622 #define SAFT_FLG1_GLOBWARN 0x4
1623 #define SAFT_FLG1_ENCPWROFF 0x8
1624 #define SAFT_FLG1_ENCFANFAIL 0x10
1625 #define SAFT_FLG1_ENCPWRFAIL 0x20
1626 #define SAFT_FLG1_ENCDRVFAIL 0x40
1627 #define SAFT_FLG1_ENCDRVWARN 0x80
1629 #define SAFT_FLG2_LOCKDOOR 0x4
1630 #define SAFT_PRIVATE sizeof (struct scfg)
1632 static char *safte_2little = "Too Little Data Returned (%d) at line %d\n";
1633 #define SAFT_BAIL(r, x, k, l) \
1635 SES_LOG(ssc, safte_2little, x, __LINE__);\
1636 SES_FREE((k), (l)); \
1642 safte_softc_init(ses_softc_t *ssc, int doinit)
1648 if (ssc->ses_nobjects) {
1649 if (ssc->ses_objmap) {
1650 SES_FREE(ssc->ses_objmap,
1651 ssc->ses_nobjects * sizeof (encobj));
1652 ssc->ses_objmap = NULL;
1654 ssc->ses_nobjects = 0;
1656 if (ssc->ses_private) {
1657 SES_FREE(ssc->ses_private, SAFT_PRIVATE);
1658 ssc->ses_private = NULL;
1663 if (ssc->ses_private == NULL) {
1664 ssc->ses_private = SES_MALLOC(SAFT_PRIVATE);
1665 if (ssc->ses_private == NULL) {
1668 MEMZERO(ssc->ses_private, SAFT_PRIVATE);
1671 ssc->ses_nobjects = 0;
1672 ssc->ses_encstat = 0;
1674 if ((err = safte_getconfig(ssc)) != 0) {
1679 * The number of objects here, as well as that reported by the
1680 * READ_BUFFER/GET_CONFIG call, are the over-temperature flags (15)
1681 * that get reported during READ_BUFFER/READ_ENC_STATUS.
1683 cc = ssc->ses_private;
1684 ssc->ses_nobjects = cc->Nfans + cc->Npwr + cc->Nslots + cc->DoorLock +
1685 cc->Ntherm + cc->Nspkrs + NPSEUDO_THERM + NPSEUDO_ALARM;
1686 ssc->ses_objmap = (encobj *)
1687 SES_MALLOC(ssc->ses_nobjects * sizeof (encobj));
1688 if (ssc->ses_objmap == NULL) {
1691 MEMZERO(ssc->ses_objmap, ssc->ses_nobjects * sizeof (encobj));
1695 * Note that this is all arranged for the convenience
1696 * in later fetches of status.
1698 for (i = 0; i < cc->Nfans; i++)
1699 ssc->ses_objmap[r++].enctype = SESTYP_FAN;
1700 cc->pwroff = (uint8_t) r;
1701 for (i = 0; i < cc->Npwr; i++)
1702 ssc->ses_objmap[r++].enctype = SESTYP_POWER;
1703 for (i = 0; i < cc->DoorLock; i++)
1704 ssc->ses_objmap[r++].enctype = SESTYP_DOORLOCK;
1705 for (i = 0; i < cc->Nspkrs; i++)
1706 ssc->ses_objmap[r++].enctype = SESTYP_ALARM;
1707 for (i = 0; i < cc->Ntherm; i++)
1708 ssc->ses_objmap[r++].enctype = SESTYP_THERM;
1709 for (i = 0; i < NPSEUDO_THERM; i++)
1710 ssc->ses_objmap[r++].enctype = SESTYP_THERM;
1711 ssc->ses_objmap[r++].enctype = SESTYP_ALARM;
1712 cc->slotoff = (uint8_t) r;
1713 for (i = 0; i < cc->Nslots; i++)
1714 ssc->ses_objmap[r++].enctype = SESTYP_DEVICE;
1719 safte_init_enc(ses_softc_t *ssc)
1722 static char cdb0[6] = { SEND_DIAGNOSTIC };
1724 err = ses_runcmd(ssc, cdb0, 6, NULL, 0);
1729 err = wrbuf16(ssc, SAFTE_WT_GLOBAL, 0, 0, 0, 1);
1734 safte_get_encstat(ses_softc_t *ssc, int slpflg)
1736 return (safte_rdstat(ssc, slpflg));
1740 safte_set_encstat(ses_softc_t *ssc, uint8_t encstat, int slpflg)
1742 struct scfg *cc = ssc->ses_private;
1746 * Since SAF-TE devices aren't necessarily sticky in terms
1747 * of state, make our soft copy of enclosure status 'sticky'-
1748 * that is, things set in enclosure status stay set (as implied
1749 * by conditions set in reading object status) until cleared.
1751 ssc->ses_encstat &= ~ALL_ENC_STAT;
1752 ssc->ses_encstat |= (encstat & ALL_ENC_STAT);
1753 ssc->ses_encstat |= ENCI_SVALID;
1754 cc->flag1 &= ~(SAFT_FLG1_ALARM|SAFT_FLG1_GLOBFAIL|SAFT_FLG1_GLOBWARN);
1755 if ((encstat & (SES_ENCSTAT_CRITICAL|SES_ENCSTAT_UNRECOV)) != 0) {
1756 cc->flag1 |= SAFT_FLG1_ALARM|SAFT_FLG1_GLOBFAIL;
1757 } else if ((encstat & SES_ENCSTAT_NONCRITICAL) != 0) {
1758 cc->flag1 |= SAFT_FLG1_GLOBWARN;
1760 return (wrbuf16(ssc, SAFTE_WT_GLOBAL, cc->flag1, cc->flag2, 0, slpflg));
1764 safte_get_objstat(ses_softc_t *ssc, ses_objstat *obp, int slpflg)
1766 int i = (int)obp->obj_id;
1768 if ((ssc->ses_encstat & ENCI_SVALID) == 0 ||
1769 (ssc->ses_objmap[i].svalid) == 0) {
1770 int err = safte_rdstat(ssc, slpflg);
1774 obp->cstat[0] = ssc->ses_objmap[i].encstat[0];
1775 obp->cstat[1] = ssc->ses_objmap[i].encstat[1];
1776 obp->cstat[2] = ssc->ses_objmap[i].encstat[2];
1777 obp->cstat[3] = ssc->ses_objmap[i].encstat[3];
1783 safte_set_objstat(ses_softc_t *ssc, ses_objstat *obp, int slp)
1790 SES_DLOG(ssc, "safte_set_objstat(%d): %x %x %x %x\n",
1791 (int)obp->obj_id, obp->cstat[0], obp->cstat[1], obp->cstat[2],
1795 * If this is clear, we don't do diddly.
1797 if ((obp->cstat[0] & SESCTL_CSEL) == 0) {
1803 * Check to see if the common bits are set and do them first.
1805 if (obp->cstat[0] & ~SESCTL_CSEL) {
1806 err = set_objstat_sel(ssc, obp, slp);
1811 cc = ssc->ses_private;
1815 idx = (int)obp->obj_id;
1816 ep = &ssc->ses_objmap[idx];
1818 switch (ep->enctype) {
1823 * XXX: I should probably cache the previous state
1824 * XXX: of SESCTL_DEVOFF so that when it goes from
1825 * XXX: true to false I can then set PREPARE FOR OPERATION
1826 * XXX: flag in PERFORM SLOT OPERATION write buffer command.
1828 if (obp->cstat[2] & (SESCTL_RQSINS|SESCTL_RQSRMV)) {
1831 if (obp->cstat[2] & SESCTL_RQSID) {
1834 err = perf_slotop(ssc, (uint8_t) idx - (uint8_t) cc->slotoff,
1838 if (obp->cstat[3] & SESCTL_RQSFLT) {
1843 if (ep->priv & 0xc6) {
1846 ep->priv |= 0x1; /* no errors */
1848 wrslot_stat(ssc, slp);
1852 if (obp->cstat[3] & SESCTL_RQSTFAIL) {
1853 cc->flag1 |= SAFT_FLG1_ENCPWRFAIL;
1855 cc->flag1 &= ~SAFT_FLG1_ENCPWRFAIL;
1857 err = wrbuf16(ssc, SAFTE_WT_GLOBAL, cc->flag1,
1861 if (obp->cstat[3] & SESCTL_RQSTON) {
1862 wrbuf16(ssc, SAFTE_WT_ACTPWS,
1863 idx - cc->pwroff, 0, 0, slp);
1865 wrbuf16(ssc, SAFTE_WT_ACTPWS,
1866 idx - cc->pwroff, 0, 1, slp);
1870 if (obp->cstat[3] & SESCTL_RQSTFAIL) {
1871 cc->flag1 |= SAFT_FLG1_ENCFANFAIL;
1873 cc->flag1 &= ~SAFT_FLG1_ENCFANFAIL;
1875 err = wrbuf16(ssc, SAFTE_WT_GLOBAL, cc->flag1,
1879 if (obp->cstat[3] & SESCTL_RQSTON) {
1881 if ((obp->cstat[3] & 0x7) == 7) {
1883 } else if ((obp->cstat[3] & 0x7) == 6) {
1885 } else if ((obp->cstat[3] & 0x7) == 4) {
1890 wrbuf16(ssc, SAFTE_WT_FANSPD, idx, fsp, 0, slp);
1892 wrbuf16(ssc, SAFTE_WT_FANSPD, idx, 0, 0, slp);
1895 case SESTYP_DOORLOCK:
1896 if (obp->cstat[3] & 0x1) {
1897 cc->flag2 &= ~SAFT_FLG2_LOCKDOOR;
1899 cc->flag2 |= SAFT_FLG2_LOCKDOOR;
1901 wrbuf16(ssc, SAFTE_WT_GLOBAL, cc->flag1, cc->flag2, 0, slp);
1905 * On all nonzero but the 'muted' bit, we turn on the alarm,
1907 obp->cstat[3] &= ~0xa;
1908 if (obp->cstat[3] & 0x40) {
1909 cc->flag2 &= ~SAFT_FLG1_ALARM;
1910 } else if (obp->cstat[3] != 0) {
1911 cc->flag2 |= SAFT_FLG1_ALARM;
1913 cc->flag2 &= ~SAFT_FLG1_ALARM;
1915 ep->priv = obp->cstat[3];
1916 wrbuf16(ssc, SAFTE_WT_GLOBAL, cc->flag1, cc->flag2, 0, slp);
1926 safte_getconfig(ses_softc_t *ssc)
1931 static char cdb[10] =
1932 { READ_BUFFER, 1, SAFTE_RD_RDCFG, 0, 0, 0, 0, 0, SAFT_SCRATCH, 0 };
1934 cfg = ssc->ses_private;
1938 sdata = SES_MALLOC(SAFT_SCRATCH);
1943 err = ses_runcmd(ssc, cdb, 10, sdata, &amt);
1945 SES_FREE(sdata, SAFT_SCRATCH);
1948 amt = SAFT_SCRATCH - amt;
1950 SES_LOG(ssc, "too little data (%d) for configuration\n", amt);
1951 SES_FREE(sdata, SAFT_SCRATCH);
1954 SES_VLOG(ssc, "Nfans %d Npwr %d Nslots %d Lck %d Ntherm %d Nspkrs %d\n",
1955 sdata[0], sdata[1], sdata[2], sdata[3], sdata[4], sdata[5]);
1956 cfg->Nfans = sdata[0];
1957 cfg->Npwr = sdata[1];
1958 cfg->Nslots = sdata[2];
1959 cfg->DoorLock = sdata[3];
1960 cfg->Ntherm = sdata[4];
1961 cfg->Nspkrs = sdata[5];
1962 cfg->Nalarm = NPSEUDO_ALARM;
1963 SES_FREE(sdata, SAFT_SCRATCH);
1968 safte_rdstat(ses_softc_t *ssc, int slpflg)
1970 int err, oid, r, i, hiwater, nitems, amt;
1973 uint8_t status, oencstat;
1974 char *sdata, cdb[10];
1975 struct scfg *cc = ssc->ses_private;
1979 * The number of objects overstates things a bit,
1980 * both for the bogus 'thermometer' entries and
1981 * the drive status (which isn't read at the same
1982 * time as the enclosure status), but that's okay.
1984 buflen = 4 * cc->Nslots;
1985 if (ssc->ses_nobjects > buflen)
1986 buflen = ssc->ses_nobjects;
1987 sdata = SES_MALLOC(buflen);
1991 cdb[0] = READ_BUFFER;
1993 cdb[2] = SAFTE_RD_RDESTS;
1998 cdb[7] = (buflen >> 8) & 0xff;
1999 cdb[8] = buflen & 0xff;
2002 err = ses_runcmd(ssc, cdb, 10, sdata, &amt);
2004 SES_FREE(sdata, buflen);
2007 hiwater = buflen - amt;
2011 * invalidate all status bits.
2013 for (i = 0; i < ssc->ses_nobjects; i++)
2014 ssc->ses_objmap[i].svalid = 0;
2015 oencstat = ssc->ses_encstat & ALL_ENC_STAT;
2016 ssc->ses_encstat = 0;
2020 * Now parse returned buffer.
2021 * If we didn't get enough data back,
2022 * that's considered a fatal error.
2026 for (nitems = i = 0; i < cc->Nfans; i++) {
2027 SAFT_BAIL(r, hiwater, sdata, buflen);
2029 * 0 = Fan Operational
2030 * 1 = Fan is malfunctioning
2031 * 2 = Fan is not present
2032 * 0x80 = Unknown or Not Reportable Status
2034 ssc->ses_objmap[oid].encstat[1] = 0; /* resvd */
2035 ssc->ses_objmap[oid].encstat[2] = 0; /* resvd */
2036 switch ((int)(uint8_t)sdata[r]) {
2039 ssc->ses_objmap[oid].encstat[0] = SES_OBJSTAT_OK;
2041 * We could get fancier and cache
2042 * fan speeds that we have set, but
2043 * that isn't done now.
2045 ssc->ses_objmap[oid].encstat[3] = 7;
2049 ssc->ses_objmap[oid].encstat[0] = SES_OBJSTAT_CRIT;
2051 * FAIL and FAN STOPPED synthesized
2053 ssc->ses_objmap[oid].encstat[3] = 0x40;
2055 * Enclosure marked with CRITICAL error
2056 * if only one fan or no thermometers,
2057 * else the NONCRITICAL error is set.
2059 if (cc->Nfans == 1 || cc->Ntherm == 0)
2060 ssc->ses_encstat |= SES_ENCSTAT_CRITICAL;
2062 ssc->ses_encstat |= SES_ENCSTAT_NONCRITICAL;
2065 ssc->ses_objmap[oid].encstat[0] =
2066 SES_OBJSTAT_NOTINSTALLED;
2067 ssc->ses_objmap[oid].encstat[3] = 0;
2069 * Enclosure marked with CRITICAL error
2070 * if only one fan or no thermometers,
2071 * else the NONCRITICAL error is set.
2074 ssc->ses_encstat |= SES_ENCSTAT_CRITICAL;
2076 ssc->ses_encstat |= SES_ENCSTAT_NONCRITICAL;
2079 ssc->ses_objmap[oid].encstat[0] = SES_OBJSTAT_UNKNOWN;
2080 ssc->ses_objmap[oid].encstat[3] = 0;
2081 ssc->ses_encstat |= SES_ENCSTAT_INFO;
2084 ssc->ses_objmap[oid].encstat[0] =
2085 SES_OBJSTAT_UNSUPPORTED;
2086 SES_LOG(ssc, "Unknown fan%d status 0x%x\n", i,
2090 ssc->ses_objmap[oid++].svalid = 1;
2095 * No matter how you cut it, no cooling elements when there
2096 * should be some there is critical.
2098 if (cc->Nfans && nitems == 0) {
2099 ssc->ses_encstat |= SES_ENCSTAT_CRITICAL;
2103 for (i = 0; i < cc->Npwr; i++) {
2104 SAFT_BAIL(r, hiwater, sdata, buflen);
2105 ssc->ses_objmap[oid].encstat[0] = SES_OBJSTAT_UNKNOWN;
2106 ssc->ses_objmap[oid].encstat[1] = 0; /* resvd */
2107 ssc->ses_objmap[oid].encstat[2] = 0; /* resvd */
2108 ssc->ses_objmap[oid].encstat[3] = 0x20; /* requested on */
2109 switch ((uint8_t)sdata[r]) {
2110 case 0x00: /* pws operational and on */
2111 ssc->ses_objmap[oid].encstat[0] = SES_OBJSTAT_OK;
2113 case 0x01: /* pws operational and off */
2114 ssc->ses_objmap[oid].encstat[0] = SES_OBJSTAT_OK;
2115 ssc->ses_objmap[oid].encstat[3] = 0x10;
2116 ssc->ses_encstat |= SES_ENCSTAT_INFO;
2118 case 0x10: /* pws is malfunctioning and commanded on */
2119 ssc->ses_objmap[oid].encstat[0] = SES_OBJSTAT_CRIT;
2120 ssc->ses_objmap[oid].encstat[3] = 0x61;
2121 ssc->ses_encstat |= SES_ENCSTAT_NONCRITICAL;
2124 case 0x11: /* pws is malfunctioning and commanded off */
2125 ssc->ses_objmap[oid].encstat[0] = SES_OBJSTAT_NONCRIT;
2126 ssc->ses_objmap[oid].encstat[3] = 0x51;
2127 ssc->ses_encstat |= SES_ENCSTAT_NONCRITICAL;
2129 case 0x20: /* pws is not present */
2130 ssc->ses_objmap[oid].encstat[0] =
2131 SES_OBJSTAT_NOTINSTALLED;
2132 ssc->ses_objmap[oid].encstat[3] = 0;
2133 ssc->ses_encstat |= SES_ENCSTAT_INFO;
2135 case 0x21: /* pws is present */
2137 * This is for enclosures that cannot tell whether the
2138 * device is on or malfunctioning, but know that it is
2139 * present. Just fall through.
2142 case 0x80: /* Unknown or Not Reportable Status */
2143 ssc->ses_objmap[oid].encstat[0] = SES_OBJSTAT_UNKNOWN;
2144 ssc->ses_objmap[oid].encstat[3] = 0;
2145 ssc->ses_encstat |= SES_ENCSTAT_INFO;
2148 SES_LOG(ssc, "unknown power supply %d status (0x%x)\n",
2149 i, sdata[r] & 0xff);
2152 ssc->ses_objmap[oid++].svalid = 1;
2157 * Skip over Slot SCSI IDs
2162 * We always have doorlock status, no matter what,
2163 * but we only save the status if we have one.
2165 SAFT_BAIL(r, hiwater, sdata, buflen);
2169 * 1 = Door Unlocked, or no Lock Installed
2170 * 0x80 = Unknown or Not Reportable Status
2172 ssc->ses_objmap[oid].encstat[1] = 0;
2173 ssc->ses_objmap[oid].encstat[2] = 0;
2174 switch ((uint8_t)sdata[r]) {
2176 ssc->ses_objmap[oid].encstat[0] = SES_OBJSTAT_OK;
2177 ssc->ses_objmap[oid].encstat[3] = 0;
2180 ssc->ses_objmap[oid].encstat[0] = SES_OBJSTAT_OK;
2181 ssc->ses_objmap[oid].encstat[3] = 1;
2184 ssc->ses_objmap[oid].encstat[0] = SES_OBJSTAT_UNKNOWN;
2185 ssc->ses_objmap[oid].encstat[3] = 0;
2186 ssc->ses_encstat |= SES_ENCSTAT_INFO;
2189 ssc->ses_objmap[oid].encstat[0] =
2190 SES_OBJSTAT_UNSUPPORTED;
2191 SES_LOG(ssc, "unknown lock status 0x%x\n",
2195 ssc->ses_objmap[oid++].svalid = 1;
2200 * We always have speaker status, no matter what,
2201 * but we only save the status if we have one.
2203 SAFT_BAIL(r, hiwater, sdata, buflen);
2205 ssc->ses_objmap[oid].encstat[1] = 0;
2206 ssc->ses_objmap[oid].encstat[2] = 0;
2207 if (sdata[r] == 1) {
2209 * We need to cache tone urgency indicators.
2212 ssc->ses_objmap[oid].encstat[0] = SES_OBJSTAT_NONCRIT;
2213 ssc->ses_objmap[oid].encstat[3] = 0x8;
2214 ssc->ses_encstat |= SES_ENCSTAT_NONCRITICAL;
2215 } else if (sdata[r] == 0) {
2216 ssc->ses_objmap[oid].encstat[0] = SES_OBJSTAT_OK;
2217 ssc->ses_objmap[oid].encstat[3] = 0;
2219 ssc->ses_objmap[oid].encstat[0] =
2220 SES_OBJSTAT_UNSUPPORTED;
2221 ssc->ses_objmap[oid].encstat[3] = 0;
2222 SES_LOG(ssc, "unknown spkr status 0x%x\n",
2225 ssc->ses_objmap[oid++].svalid = 1;
2229 for (i = 0; i < cc->Ntherm; i++) {
2230 SAFT_BAIL(r, hiwater, sdata, buflen);
2232 * Status is a range from -10 to 245 deg Celsius,
2233 * which we need to normalize to -20 to -245 according
2234 * to the latest SCSI spec, which makes little
2235 * sense since this would overflow an 8bit value.
2236 * Well, still, the base normalization is -20,
2237 * not -10, so we have to adjust.
2239 * So what's over and under temperature?
2240 * Hmm- we'll state that 'normal' operating
2241 * is 10 to 40 deg Celsius.
2245 * Actually.... All of the units that people out in the world
2246 * seem to have do not come even close to setting a value that
2247 * complies with this spec.
2249 * The closest explanation I could find was in an
2250 * LSI-Logic manual, which seemed to indicate that
2251 * this value would be set by whatever the I2C code
2252 * would interpolate from the output of an LM75
2253 * temperature sensor.
2255 * This means that it is impossible to use the actual
2256 * numeric value to predict anything. But we don't want
2257 * to lose the value. So, we'll propagate the *uncorrected*
2258 * value and set SES_OBJSTAT_NOTAVAIL. We'll depend on the
2259 * temperature flags for warnings.
2261 ssc->ses_objmap[oid].encstat[0] = SES_OBJSTAT_NOTAVAIL;
2262 ssc->ses_objmap[oid].encstat[1] = 0;
2263 ssc->ses_objmap[oid].encstat[2] = sdata[r];
2264 ssc->ses_objmap[oid].encstat[3] = 0;
2265 ssc->ses_objmap[oid++].svalid = 1;
2270 * Now, for "pseudo" thermometers, we have two bytes
2271 * of information in enclosure status- 16 bits. Actually,
2272 * the MSB is a single TEMP ALERT flag indicating whether
2273 * any other bits are set, but, thanks to fuzzy thinking,
2274 * in the SAF-TE spec, this can also be set even if no
2275 * other bits are set, thus making this really another
2276 * binary temperature sensor.
2279 SAFT_BAIL(r, hiwater, sdata, buflen);
2280 tempflags = sdata[r++];
2281 SAFT_BAIL(r, hiwater, sdata, buflen);
2282 tempflags |= (tempflags << 8) | sdata[r++];
2284 for (i = 0; i < NPSEUDO_THERM; i++) {
2285 ssc->ses_objmap[oid].encstat[1] = 0;
2286 if (tempflags & (1 << (NPSEUDO_THERM - i - 1))) {
2287 ssc->ses_objmap[oid].encstat[0] = SES_OBJSTAT_CRIT;
2288 ssc->ses_objmap[4].encstat[2] = 0xff;
2290 * Set 'over temperature' failure.
2292 ssc->ses_objmap[oid].encstat[3] = 8;
2293 ssc->ses_encstat |= SES_ENCSTAT_CRITICAL;
2296 * We used to say 'not available' and synthesize a
2297 * nominal 30 deg (C)- that was wrong. Actually,
2298 * Just say 'OK', and use the reserved value of
2301 ssc->ses_objmap[oid].encstat[0] = SES_OBJSTAT_OK;
2302 ssc->ses_objmap[oid].encstat[2] = 0;
2303 ssc->ses_objmap[oid].encstat[3] = 0;
2305 ssc->ses_objmap[oid++].svalid = 1;
2311 ssc->ses_objmap[oid].encstat[0] = SES_OBJSTAT_OK;
2312 ssc->ses_objmap[oid].encstat[3] = ssc->ses_objmap[oid].priv;
2313 ssc->ses_objmap[oid++].svalid = 1;
2316 * Now get drive slot status
2318 cdb[2] = SAFTE_RD_RDDSTS;
2320 err = ses_runcmd(ssc, cdb, 10, sdata, &amt);
2322 SES_FREE(sdata, buflen);
2325 hiwater = buflen - amt;
2326 for (r = i = 0; i < cc->Nslots; i++, r += 4) {
2327 SAFT_BAIL(r+3, hiwater, sdata, buflen);
2328 ssc->ses_objmap[oid].encstat[0] = SES_OBJSTAT_UNSUPPORTED;
2329 ssc->ses_objmap[oid].encstat[1] = (uint8_t) i;
2330 ssc->ses_objmap[oid].encstat[2] = 0;
2331 ssc->ses_objmap[oid].encstat[3] = 0;
2332 status = sdata[r+3];
2333 if ((status & 0x1) == 0) { /* no device */
2334 ssc->ses_objmap[oid].encstat[0] =
2335 SES_OBJSTAT_NOTINSTALLED;
2337 ssc->ses_objmap[oid].encstat[0] = SES_OBJSTAT_OK;
2340 ssc->ses_objmap[oid].encstat[2] = 0x8;
2342 if ((status & 0x4) == 0) {
2343 ssc->ses_objmap[oid].encstat[3] = 0x10;
2345 ssc->ses_objmap[oid++].svalid = 1;
2347 /* see comment below about sticky enclosure status */
2348 ssc->ses_encstat |= ENCI_SVALID | oencstat;
2349 SES_FREE(sdata, buflen);
2354 set_objstat_sel(ses_softc_t *ssc, ses_objstat *obp, int slp)
2358 struct scfg *cc = ssc->ses_private;
2363 idx = (int)obp->obj_id;
2364 ep = &ssc->ses_objmap[idx];
2366 switch (ep->enctype) {
2368 if (obp->cstat[0] & SESCTL_PRDFAIL) {
2371 /* SESCTL_RSTSWAP has no correspondence in SAF-TE */
2372 if (obp->cstat[0] & SESCTL_DISABLE) {
2375 * Hmm. Try to set the 'No Drive' flag.
2376 * Maybe that will count as a 'disable'.
2379 if (ep->priv & 0xc6) {
2382 ep->priv |= 0x1; /* no errors */
2384 wrslot_stat(ssc, slp);
2388 * Okay- the only one that makes sense here is to
2389 * do the 'disable' for a power supply.
2391 if (obp->cstat[0] & SESCTL_DISABLE) {
2392 wrbuf16(ssc, SAFTE_WT_ACTPWS,
2393 idx - cc->pwroff, 0, 0, slp);
2398 * Okay- the only one that makes sense here is to
2399 * set fan speed to zero on disable.
2401 if (obp->cstat[0] & SESCTL_DISABLE) {
2402 /* remember- fans are the first items, so idx works */
2403 wrbuf16(ssc, SAFTE_WT_FANSPD, idx, 0, 0, slp);
2406 case SESTYP_DOORLOCK:
2408 * Well, we can 'disable' the lock.
2410 if (obp->cstat[0] & SESCTL_DISABLE) {
2411 cc->flag2 &= ~SAFT_FLG2_LOCKDOOR;
2412 wrbuf16(ssc, SAFTE_WT_GLOBAL, cc->flag1,
2418 * Well, we can 'disable' the alarm.
2420 if (obp->cstat[0] & SESCTL_DISABLE) {
2421 cc->flag2 &= ~SAFT_FLG1_ALARM;
2422 ep->priv |= 0x40; /* Muted */
2423 wrbuf16(ssc, SAFTE_WT_GLOBAL, cc->flag1,
2435 * This function handles all of the 16 byte WRITE BUFFER commands.
2438 wrbuf16(ses_softc_t *ssc, uint8_t op, uint8_t b1, uint8_t b2,
2439 uint8_t b3, int slp)
2443 struct scfg *cc = ssc->ses_private;
2444 static char cdb[10] = { WRITE_BUFFER, 1, 0, 0, 0, 0, 0, 0, 16, 0 };
2449 sdata = SES_MALLOC(16);
2453 SES_DLOG(ssc, "saf_wrbuf16 %x %x %x %x\n", op, b1, b2, b3);
2459 MEMZERO(&sdata[4], 12);
2461 err = ses_runcmd(ssc, cdb, 10, sdata, &amt);
2462 SES_FREE(sdata, 16);
2467 * This function updates the status byte for the device slot described.
2469 * Since this is an optional SAF-TE command, there's no point in
2470 * returning an error.
2473 wrslot_stat(ses_softc_t *ssc, int slp)
2477 char cdb[10], *sdata;
2478 struct scfg *cc = ssc->ses_private;
2483 SES_DLOG(ssc, "saf_wrslot\n");
2484 cdb[0] = WRITE_BUFFER;
2492 cdb[8] = cc->Nslots * 3 + 1;
2495 sdata = SES_MALLOC(cc->Nslots * 3 + 1);
2498 MEMZERO(sdata, cc->Nslots * 3 + 1);
2500 sdata[0] = SAFTE_WT_DSTAT;
2501 for (i = 0; i < cc->Nslots; i++) {
2502 ep = &ssc->ses_objmap[cc->slotoff + i];
2503 SES_DLOG(ssc, "saf_wrslot %d <- %x\n", i, ep->priv & 0xff);
2504 sdata[1 + (3 * i)] = ep->priv & 0xff;
2506 amt = -(cc->Nslots * 3 + 1);
2507 ses_runcmd(ssc, cdb, 10, sdata, &amt);
2508 SES_FREE(sdata, cc->Nslots * 3 + 1);
2512 * This function issues the "PERFORM SLOT OPERATION" command.
2515 perf_slotop(ses_softc_t *ssc, uint8_t slot, uint8_t opflag, int slp)
2519 struct scfg *cc = ssc->ses_private;
2520 static char cdb[10] =
2521 { WRITE_BUFFER, 1, 0, 0, 0, 0, 0, 0, SAFT_SCRATCH, 0 };
2526 sdata = SES_MALLOC(SAFT_SCRATCH);
2529 MEMZERO(sdata, SAFT_SCRATCH);
2531 sdata[0] = SAFTE_WT_SLTOP;
2534 SES_DLOG(ssc, "saf_slotop slot %d op %x\n", slot, opflag);
2535 amt = -SAFT_SCRATCH;
2536 err = ses_runcmd(ssc, cdb, 10, sdata, &amt);
2537 SES_FREE(sdata, SAFT_SCRATCH);