1 /* $FreeBSD: src/sys/cam/scsi/scsi_ses.c,v 1.8.2.2 2000/08/08 23:19:21 mjacob Exp $ */
2 /* $DragonFly: src/sys/bus/cam/scsi/scsi_ses.c,v 1.29 2008/05/18 20:30:20 pavalos Exp $ */
4 * Copyright (c) 2000 Matthew Jacob
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions, and the following disclaimer,
12 * without modification, immediately at the beginning of the file.
13 * 2. The name of the author may not be used to endorse or promote products
14 * derived from this software without specific prior written permission.
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
17 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR
20 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29 #include <sys/param.h>
30 #include <sys/queue.h>
31 #include <sys/systm.h>
32 #include <sys/kernel.h>
33 #include <sys/types.h>
34 #include <sys/malloc.h>
35 #include <sys/fcntl.h>
38 #include <sys/errno.h>
39 #include <sys/devicestat.h>
40 #include <sys/thread2.h>
41 #include <machine/stdarg.h>
44 #include "../cam_ccb.h"
45 #include "../cam_extend.h"
46 #include "../cam_periph.h"
47 #include "../cam_xpt_periph.h"
48 #include "../cam_debug.h"
49 #include "../cam_sim.h"
52 #include "scsi_message.h"
57 MALLOC_DEFINE(M_SCSISES, "SCSI SES", "SCSI SES buffers");
60 * Platform Independent Driver Internal Definitions for SES devices.
72 typedef struct ses_softc ses_softc_t;
74 int (*softc_init)(ses_softc_t *, int);
75 int (*init_enc)(ses_softc_t *);
76 int (*get_encstat)(ses_softc_t *, int);
77 int (*set_encstat)(ses_softc_t *, ses_encstat, int);
78 int (*get_objstat)(ses_softc_t *, ses_objstat *, int);
79 int (*set_objstat)(ses_softc_t *, ses_objstat *, int);
82 #define ENCI_SVALID 0x80
86 enctype : 8, /* enclosure type */
87 subenclosure : 8, /* subenclosure id */
88 svalid : 1, /* enclosure information valid */
89 priv : 15; /* private data, per object */
90 uint8_t encstat[4]; /* state && stats */
93 #define SEN_ID "UNISYS SUN_SEN"
97 static enctyp ses_type(void *, int);
100 /* Forward reference to Enclosure Functions */
101 static int ses_softc_init(ses_softc_t *, int);
102 static int ses_init_enc(ses_softc_t *);
103 static int ses_get_encstat(ses_softc_t *, int);
104 static int ses_set_encstat(ses_softc_t *, uint8_t, int);
105 static int ses_get_objstat(ses_softc_t *, ses_objstat *, int);
106 static int ses_set_objstat(ses_softc_t *, ses_objstat *, int);
108 static int safte_softc_init(ses_softc_t *, int);
109 static int safte_init_enc(ses_softc_t *);
110 static int safte_get_encstat(ses_softc_t *, int);
111 static int safte_set_encstat(ses_softc_t *, uint8_t, int);
112 static int safte_get_objstat(ses_softc_t *, ses_objstat *, int);
113 static int safte_set_objstat(ses_softc_t *, ses_objstat *, int);
116 * Platform implementation defines/functions for SES internal kernel stuff
119 #define STRNCMP strncmp
120 #define PRINTF kprintf
121 #define SES_LOG ses_log
123 #define SES_DLOG ses_log
125 #define SES_DLOG if (0) ses_log
127 #define SES_VLOG if (bootverbose) ses_log
128 #define SES_MALLOC(amt) kmalloc(amt, M_SCSISES, M_INTWAIT)
129 #define SES_FREE(ptr, amt) kfree(ptr, M_SCSISES)
130 #define MEMZERO bzero
131 #define MEMCPY(dest, src, amt) bcopy(src, dest, amt)
133 static int ses_runcmd(struct ses_softc *, char *, int, char *, int *);
134 static void ses_log(struct ses_softc *, const char *, ...);
137 * Gerenal FreeBSD kernel stuff.
141 #define ccb_state ppriv_field0
142 #define ccb_bio ppriv_ptr1
145 enctyp ses_type; /* type of enclosure */
146 encvec ses_vec; /* vector to handlers */
147 void * ses_private; /* per-type private data */
148 encobj * ses_objmap; /* objects */
149 u_int32_t ses_nobjects; /* number of objects */
150 ses_encstat ses_encstat; /* overall status */
152 union ccb ses_saved_ccb;
153 struct cam_periph *periph;
155 #define SES_FLAG_INVALID 0x01
156 #define SES_FLAG_OPEN 0x02
157 #define SES_FLAG_INITIALIZED 0x04
159 #define SESUNIT(x) (minor((x)))
160 #define SES_CDEV_MAJOR 110
162 static d_open_t sesopen;
163 static d_close_t sesclose;
164 static d_ioctl_t sesioctl;
165 static periph_init_t sesinit;
166 static periph_ctor_t sesregister;
167 static periph_oninv_t sesoninvalidate;
168 static periph_dtor_t sescleanup;
169 static periph_start_t sesstart;
171 static void sesasync(void *, u_int32_t, struct cam_path *, void *);
172 static void sesdone(struct cam_periph *, union ccb *);
173 static int seserror(union ccb *, u_int32_t, u_int32_t);
175 static struct periph_driver sesdriver = {
177 TAILQ_HEAD_INITIALIZER(sesdriver.units), /* generation */ 0
180 PERIPHDRIVER_DECLARE(ses, sesdriver);
182 static struct dev_ops ses_ops = {
183 { "ses", SES_CDEV_MAJOR, 0 },
188 static struct extend_array *sesperiphs;
196 * Create our extend array for storing the devices we attach to.
198 sesperiphs = cam_extend_new();
199 if (sesperiphs == NULL) {
200 kprintf("ses: Failed to alloc extend array!\n");
205 * Install a global async callback. This callback will
206 * receive async callbacks like "new device found".
208 status = xpt_register_async(AC_FOUND_DEVICE, sesasync, NULL, NULL);
210 if (status != CAM_REQ_CMP) {
211 kprintf("ses: Failed to attach master async callback "
212 "due to status 0x%x!\n", status);
217 sesoninvalidate(struct cam_periph *periph)
219 struct ses_softc *softc;
221 softc = (struct ses_softc *)periph->softc;
224 * Unregister any async callbacks.
226 xpt_register_async(0, sesasync, periph, periph->path);
228 softc->ses_flags |= SES_FLAG_INVALID;
230 xpt_print(periph->path, "lost device\n");
234 sescleanup(struct cam_periph *periph)
236 struct ses_softc *softc;
238 softc = (struct ses_softc *)periph->softc;
240 cam_extend_release(sesperiphs, periph->unit_number);
241 xpt_print(periph->path, "removing device entry\n");
242 dev_ops_remove(&ses_ops, -1, periph->unit_number);
243 kfree(softc, M_SCSISES);
247 sesasync(void *callback_arg, u_int32_t code, struct cam_path *path, void *arg)
249 struct cam_periph *periph;
251 periph = (struct cam_periph *)callback_arg;
254 case AC_FOUND_DEVICE:
257 struct ccb_getdev *cgd;
260 cgd = (struct ccb_getdev *)arg;
265 inq_len = cgd->inq_data.additional_length + 4;
268 * PROBLEM: WE NEED TO LOOK AT BYTES 48-53 TO SEE IF THIS IS
269 * PROBLEM: IS A SAF-TE DEVICE.
271 switch (ses_type(&cgd->inq_data, inq_len)) {
274 case SES_SES_PASSTHROUGH:
282 status = cam_periph_alloc(sesregister, sesoninvalidate,
283 sescleanup, sesstart, "ses", CAM_PERIPH_BIO,
284 cgd->ccb_h.path, sesasync, AC_FOUND_DEVICE, cgd);
286 if (status != CAM_REQ_CMP && status != CAM_REQ_INPROG) {
287 kprintf("sesasync: Unable to probe new device due to "
288 "status 0x%x\n", status);
293 cam_periph_async(periph, code, path, arg);
299 sesregister(struct cam_periph *periph, void *arg)
301 struct ses_softc *softc;
302 struct ccb_getdev *cgd;
305 cgd = (struct ccb_getdev *)arg;
306 if (periph == NULL) {
307 kprintf("sesregister: periph was NULL!!\n");
308 return (CAM_REQ_CMP_ERR);
312 kprintf("sesregister: no getdev CCB, can't register device\n");
313 return (CAM_REQ_CMP_ERR);
316 softc = kmalloc(sizeof (struct ses_softc), M_SCSISES, M_INTWAIT | M_ZERO);
317 periph->softc = softc;
318 softc->periph = periph;
320 softc->ses_type = ses_type(&cgd->inq_data, sizeof (cgd->inq_data));
322 switch (softc->ses_type) {
325 case SES_SES_PASSTHROUGH:
326 softc->ses_vec.softc_init = ses_softc_init;
327 softc->ses_vec.init_enc = ses_init_enc;
328 softc->ses_vec.get_encstat = ses_get_encstat;
329 softc->ses_vec.set_encstat = ses_set_encstat;
330 softc->ses_vec.get_objstat = ses_get_objstat;
331 softc->ses_vec.set_objstat = ses_set_objstat;
334 softc->ses_vec.softc_init = safte_softc_init;
335 softc->ses_vec.init_enc = safte_init_enc;
336 softc->ses_vec.get_encstat = safte_get_encstat;
337 softc->ses_vec.set_encstat = safte_set_encstat;
338 softc->ses_vec.get_objstat = safte_get_objstat;
339 softc->ses_vec.set_objstat = safte_set_objstat;
345 kfree(softc, M_SCSISES);
346 return (CAM_REQ_CMP_ERR);
349 cam_extend_set(sesperiphs, periph->unit_number, periph);
351 cam_periph_unlock(periph);
352 dev_ops_add(&ses_ops, -1, periph->unit_number);
353 make_dev(&ses_ops, periph->unit_number,
354 UID_ROOT, GID_OPERATOR, 0600, "%s%d",
355 periph->periph_name, periph->unit_number);
356 cam_periph_lock(periph);
359 * Add an async callback so that we get
360 * notified if this device goes away.
362 xpt_register_async(AC_LOST_DEVICE, sesasync, periph, periph->path);
364 switch (softc->ses_type) {
367 tname = "No SES device";
370 tname = "SCSI-2 SES Device";
373 tname = "SCSI-3 SES Device";
375 case SES_SES_PASSTHROUGH:
376 tname = "SES Passthrough Device";
379 tname = "UNISYS SEN Device (NOT HANDLED YET)";
382 tname = "SAF-TE Compliant Device";
385 xpt_announce_periph(periph, tname);
386 return (CAM_REQ_CMP);
390 sesopen(struct dev_open_args *ap)
392 cdev_t dev = ap->a_head.a_dev;
393 struct cam_periph *periph;
394 struct ses_softc *softc;
397 periph = cam_extend_get(sesperiphs, SESUNIT(dev));
398 if (periph == NULL) {
402 if (cam_periph_acquire(periph) != CAM_REQ_CMP) {
403 cam_periph_unlock(periph);
407 cam_periph_lock(periph);
409 softc = (struct ses_softc *)periph->softc;
411 if (softc->ses_flags & SES_FLAG_INVALID) {
415 if (softc->ses_flags & SES_FLAG_OPEN) {
419 if (softc->ses_vec.softc_init == NULL) {
424 softc->ses_flags |= SES_FLAG_OPEN;
425 if ((softc->ses_flags & SES_FLAG_INITIALIZED) == 0) {
426 error = (*softc->ses_vec.softc_init)(softc, 1);
428 softc->ses_flags &= ~SES_FLAG_OPEN;
430 softc->ses_flags |= SES_FLAG_INITIALIZED;
434 cam_periph_unlock(periph);
436 cam_periph_release(periph);
442 sesclose(struct dev_close_args *ap)
444 cdev_t dev = ap->a_head.a_dev;
445 struct cam_periph *periph;
446 struct ses_softc *softc;
452 periph = cam_extend_get(sesperiphs, unit);
456 cam_periph_lock(periph);
458 softc = (struct ses_softc *)periph->softc;
459 softc->ses_flags &= ~SES_FLAG_OPEN;
461 cam_periph_unlock(periph);
462 cam_periph_release(periph);
468 sesstart(struct cam_periph *p, union ccb *sccb)
470 if (p->immediate_priority <= p->pinfo.priority) {
471 SLIST_INSERT_HEAD(&p->ccb_list, &sccb->ccb_h, periph_links.sle);
472 p->immediate_priority = CAM_PRIORITY_NONE;
473 wakeup(&p->ccb_list);
478 sesdone(struct cam_periph *periph, union ccb *dccb)
480 wakeup(&dccb->ccb_h.cbfcnp);
484 seserror(union ccb *ccb, u_int32_t cflags, u_int32_t sflags)
486 struct ses_softc *softc;
487 struct cam_periph *periph;
489 periph = xpt_path_periph(ccb->ccb_h.path);
490 softc = (struct ses_softc *)periph->softc;
492 return (cam_periph_error(ccb, cflags, sflags, &softc->ses_saved_ccb));
496 sesioctl(struct dev_ioctl_args *ap)
498 cdev_t dev = ap->a_head.a_dev;
499 struct cam_periph *periph;
502 ses_object obj, *uobj;
503 struct ses_softc *ssc;
509 addr = *((caddr_t *)ap->a_data);
513 periph = cam_extend_get(sesperiphs, SESUNIT(dev));
517 CAM_DEBUG(periph->path, CAM_DEBUG_TRACE, ("entering sesioctl\n"));
519 cam_periph_lock(periph);
520 ssc = (struct ses_softc *)periph->softc;
523 * Now check to see whether we're initialized or not.
525 if ((ssc->ses_flags & SES_FLAG_INITIALIZED) == 0) {
526 cam_periph_unlock(periph);
529 cam_periph_unlock(periph);
533 CAM_DEBUG(periph->path, CAM_DEBUG_TRACE,
534 ("trying to do ioctl %#lx\n", ap->a_cmd));
537 * If this command can change the device's state,
538 * we must have the device open for writing.
542 case SESIOC_GETOBJMAP:
543 case SESIOC_GETENCSTAT:
544 case SESIOC_GETOBJSTAT:
547 if ((ap->a_fflag & FWRITE) == 0) {
554 error = copyout(&ssc->ses_nobjects, addr,
555 sizeof (ssc->ses_nobjects));
558 case SESIOC_GETOBJMAP:
560 * XXX Dropping the lock while copying multiple segments is
563 cam_periph_lock(periph);
564 for (uobj = addr, i = 0; i != ssc->ses_nobjects; i++, uobj++) {
566 obj.subencid = ssc->ses_objmap[i].subenclosure;
567 obj.object_type = ssc->ses_objmap[i].enctype;
568 cam_periph_unlock(periph);
569 error = copyout(&obj, uobj, sizeof (ses_object));
570 cam_periph_lock(periph);
575 cam_periph_unlock(periph);
578 case SESIOC_GETENCSTAT:
579 cam_periph_lock(periph);
580 error = (*ssc->ses_vec.get_encstat)(ssc, 1);
582 cam_periph_unlock(periph);
585 tmp = ssc->ses_encstat & ~ENCI_SVALID;
586 cam_periph_unlock(periph);
587 error = copyout(&tmp, addr, sizeof (ses_encstat));
588 ssc->ses_encstat = tmp;
591 case SESIOC_SETENCSTAT:
592 error = copyin(addr, &tmp, sizeof (ses_encstat));
595 cam_periph_lock(periph);
596 error = (*ssc->ses_vec.set_encstat)(ssc, tmp, 1);
597 cam_periph_unlock(periph);
600 case SESIOC_GETOBJSTAT:
601 error = copyin(addr, &objs, sizeof (ses_objstat));
604 if (objs.obj_id >= ssc->ses_nobjects) {
608 cam_periph_lock(periph);
609 error = (*ssc->ses_vec.get_objstat)(ssc, &objs, 1);
610 cam_periph_unlock(periph);
613 error = copyout(&objs, addr, sizeof (ses_objstat));
615 * Always (for now) invalidate entry.
617 ssc->ses_objmap[objs.obj_id].svalid = 0;
620 case SESIOC_SETOBJSTAT:
621 error = copyin(addr, &objs, sizeof (ses_objstat));
625 if (objs.obj_id >= ssc->ses_nobjects) {
629 cam_periph_lock(periph);
630 error = (*ssc->ses_vec.set_objstat)(ssc, &objs, 1);
631 cam_periph_unlock(periph);
634 * Always (for now) invalidate entry.
636 ssc->ses_objmap[objs.obj_id].svalid = 0;
641 cam_periph_lock(periph);
642 error = (*ssc->ses_vec.init_enc)(ssc);
643 cam_periph_unlock(periph);
647 cam_periph_lock(periph);
648 error = cam_periph_ioctl(periph, ap->a_cmd, ap->a_data, seserror);
649 cam_periph_unlock(periph);
655 #define SES_CFLAGS CAM_RETRY_SELTO
656 #define SES_FLAGS SF_NO_PRINT | SF_RETRY_UA
658 ses_runcmd(struct ses_softc *ssc, char *cdb, int cdbl, char *dptr, int *dlenp)
665 if ((dlen = *dlenp) < 0) {
676 if (cdbl > IOCDBLEN) {
680 ccb = cam_periph_getccb(ssc->periph, 1);
681 cam_fill_csio(&ccb->csio, 0, sesdone, ddf, MSG_SIMPLE_Q_TAG, dptr,
682 dlen, sizeof (struct scsi_sense_data), cdbl, 60 * 1000);
683 bcopy(cdb, ccb->csio.cdb_io.cdb_bytes, cdbl);
685 error = cam_periph_runccb(ccb, seserror, SES_CFLAGS, SES_FLAGS, NULL);
686 if ((ccb->ccb_h.status & CAM_DEV_QFRZN) != 0)
687 cam_release_devq(ccb->ccb_h.path, 0, 0, 0, FALSE);
694 *dlenp = ccb->csio.resid;
697 xpt_release_ccb(ccb);
702 ses_log(struct ses_softc *ssc, const char *fmt, ...)
706 kprintf("%s%d: ", ssc->periph->periph_name, ssc->periph->unit_number);
713 * The code after this point runs on many platforms,
714 * so forgive the slightly awkward and nonconforming
719 * Is this a device that supports enclosure services?
721 * It's a a pretty simple ruleset- if it is device type 0x0D (13), it's
722 * an SES device. If it happens to be an old UNISYS SEN device, we can
726 #define SAFTE_START 44
728 #define SAFTE_LEN SAFTE_END-SAFTE_START
731 ses_type(void *buf, int buflen)
733 unsigned char *iqd = buf;
735 if (buflen < 8+SEN_ID_LEN)
738 if ((iqd[0] & 0x1f) == T_ENCLOSURE) {
739 if (STRNCMP(&iqd[8], SEN_ID, SEN_ID_LEN) == 0) {
741 } else if ((iqd[2] & 0x7) > 2) {
744 return (SES_SES_SCSI2);
749 #ifdef SES_ENABLE_PASSTHROUGH
750 if ((iqd[6] & 0x40) && (iqd[2] & 0x7) >= 2) {
752 * PassThrough Device.
754 return (SES_SES_PASSTHROUGH);
759 * The comparison is short for a reason-
760 * some vendors were chopping it short.
763 if (buflen < SAFTE_END - 2) {
767 if (STRNCMP((char *)&iqd[SAFTE_START], "SAF-TE", SAFTE_LEN - 2) == 0) {
774 * SES Native Type Device Support
778 * SES Diagnostic Page Codes
784 #define SesStatusPage SesControlPage
787 #define SesStringIn SesStringOut
789 #define SesThresholdIn SesThresholdOut
791 #define SesArrayStatus SesArrayControl
792 SesElementDescriptor,
801 * Minimum amount of data, starting from byte 0, to have
804 #define SES_CFGHDR_MINLEN 12
807 * Minimum amount of data, starting from byte 0, to have
808 * the config header and one enclosure header.
810 #define SES_ENCHDR_MINLEN 48
813 * Take this value, subtract it from VEnclen and you know
814 * the length of the vendor unique bytes.
816 #define SES_ENCHDR_VMIN 36
819 * SES Data Structures
823 uint32_t GenCode; /* Generation Code */
824 uint8_t Nsubenc; /* Number of Subenclosures */
828 uint8_t Subencid; /* SubEnclosure Identifier */
829 uint8_t Ntypes; /* # of supported types */
830 uint8_t VEnclen; /* Enclosure Descriptor Length */
834 uint8_t encWWN[8]; /* XXX- Not Right Yet */
842 uint8_t enc_type; /* type of element */
843 uint8_t enc_maxelt; /* maximum supported */
844 uint8_t enc_subenc; /* in SubEnc # N */
845 uint8_t enc_tlen; /* Type Descriptor Text Length */
859 uint8_t ses_ntypes; /* total number of types supported */
862 * We need to keep a type index as well as an
863 * object index for each object in an enclosure.
865 struct typidx *ses_typidx;
868 * We also need to keep track of the number of elements
869 * per type of element. This is needed later so that we
870 * can find precisely in the returned status data the
871 * status for the Nth element of the Kth type.
873 uint8_t * ses_eltmap;
878 * (de)canonicalization defines
880 #define sbyte(x, byte) ((((uint32_t)(x)) >> (byte * 8)) & 0xff)
881 #define sbit(x, bit) (((uint32_t)(x)) << bit)
882 #define sset8(outp, idx, sval) (((uint8_t *)(outp))[idx++]) = sbyte(sval, 0)
884 #define sset16(outp, idx, sval) \
885 (((uint8_t *)(outp))[idx++]) = sbyte(sval, 1), \
886 (((uint8_t *)(outp))[idx++]) = sbyte(sval, 0)
889 #define sset24(outp, idx, sval) \
890 (((uint8_t *)(outp))[idx++]) = sbyte(sval, 2), \
891 (((uint8_t *)(outp))[idx++]) = sbyte(sval, 1), \
892 (((uint8_t *)(outp))[idx++]) = sbyte(sval, 0)
895 #define sset32(outp, idx, sval) \
896 (((uint8_t *)(outp))[idx++]) = sbyte(sval, 3), \
897 (((uint8_t *)(outp))[idx++]) = sbyte(sval, 2), \
898 (((uint8_t *)(outp))[idx++]) = sbyte(sval, 1), \
899 (((uint8_t *)(outp))[idx++]) = sbyte(sval, 0)
901 #define gbyte(x, byte) ((((uint32_t)(x)) & 0xff) << (byte * 8))
902 #define gbit(lv, in, idx, shft, mask) lv = ((in[idx] >> shft) & mask)
903 #define sget8(inp, idx, lval) lval = (((uint8_t *)(inp))[idx++])
904 #define gget8(inp, idx, lval) lval = (((uint8_t *)(inp))[idx])
906 #define sget16(inp, idx, lval) \
907 lval = gbyte((((uint8_t *)(inp))[idx]), 1) | \
908 (((uint8_t *)(inp))[idx+1]), idx += 2
910 #define gget16(inp, idx, lval) \
911 lval = gbyte((((uint8_t *)(inp))[idx]), 1) | \
912 (((uint8_t *)(inp))[idx+1])
914 #define sget24(inp, idx, lval) \
915 lval = gbyte((((uint8_t *)(inp))[idx]), 2) | \
916 gbyte((((uint8_t *)(inp))[idx+1]), 1) | \
917 (((uint8_t *)(inp))[idx+2]), idx += 3
919 #define gget24(inp, idx, lval) \
920 lval = gbyte((((uint8_t *)(inp))[idx]), 2) | \
921 gbyte((((uint8_t *)(inp))[idx+1]), 1) | \
922 (((uint8_t *)(inp))[idx+2])
924 #define sget32(inp, idx, lval) \
925 lval = gbyte((((uint8_t *)(inp))[idx]), 3) | \
926 gbyte((((uint8_t *)(inp))[idx+1]), 2) | \
927 gbyte((((uint8_t *)(inp))[idx+2]), 1) | \
928 (((uint8_t *)(inp))[idx+3]), idx += 4
930 #define gget32(inp, idx, lval) \
931 lval = gbyte((((uint8_t *)(inp))[idx]), 3) | \
932 gbyte((((uint8_t *)(inp))[idx+1]), 2) | \
933 gbyte((((uint8_t *)(inp))[idx+2]), 1) | \
934 (((uint8_t *)(inp))[idx+3])
937 #define CFLEN (256 + SES_ENCHDR_MINLEN)
940 * Routines specific && private to SES only
943 static int ses_getconfig(ses_softc_t *);
944 static int ses_getputstat(ses_softc_t *, int, SesComStat *, int, int);
945 static int ses_cfghdr(uint8_t *, int, SesCfgHdr *);
946 static int ses_enchdr(uint8_t *, int, uint8_t, SesEncHdr *);
947 static int ses_encdesc(uint8_t *, int, uint8_t, SesEncDesc *);
948 static int ses_getthdr(uint8_t *, int, int, SesThdr *);
949 static int ses_decode(char *, int, uint8_t *, int, int, SesComStat *);
950 static int ses_encode(char *, int, uint8_t *, int, int, SesComStat *);
953 ses_softc_init(ses_softc_t *ssc, int doinit)
957 if (ssc->ses_nobjects) {
958 SES_FREE(ssc->ses_objmap,
959 ssc->ses_nobjects * sizeof (encobj));
960 ssc->ses_objmap = NULL;
962 if ((cc = ssc->ses_private) != NULL) {
963 if (cc->ses_eltmap && cc->ses_ntypes) {
964 SES_FREE(cc->ses_eltmap, cc->ses_ntypes);
965 cc->ses_eltmap = NULL;
968 if (cc->ses_typidx && ssc->ses_nobjects) {
969 SES_FREE(cc->ses_typidx,
970 ssc->ses_nobjects * sizeof (struct typidx));
971 cc->ses_typidx = NULL;
973 SES_FREE(cc, sizeof (struct sscfg));
974 ssc->ses_private = NULL;
976 ssc->ses_nobjects = 0;
979 if (ssc->ses_private == NULL) {
980 ssc->ses_private = SES_MALLOC(sizeof (struct sscfg));
982 if (ssc->ses_private == NULL) {
985 ssc->ses_nobjects = 0;
986 ssc->ses_encstat = 0;
987 return (ses_getconfig(ssc));
991 ses_init_enc(ses_softc_t *ssc)
997 ses_get_encstat(ses_softc_t *ssc, int slpflag)
1002 if ((status = ses_getputstat(ssc, -1, &ComStat, slpflag, 1)) != 0) {
1005 ssc->ses_encstat = ComStat.comstatus | ENCI_SVALID;
1010 ses_set_encstat(ses_softc_t *ssc, uint8_t encstat, int slpflag)
1015 ComStat.comstatus = encstat & 0xf;
1016 if ((status = ses_getputstat(ssc, -1, &ComStat, slpflag, 0)) != 0) {
1019 ssc->ses_encstat = encstat & 0xf; /* note no SVALID set */
1024 ses_get_objstat(ses_softc_t *ssc, ses_objstat *obp, int slpflag)
1026 int i = (int)obp->obj_id;
1028 if (ssc->ses_objmap[i].svalid == 0) {
1030 int err = ses_getputstat(ssc, i, &ComStat, slpflag, 1);
1033 ssc->ses_objmap[i].encstat[0] = ComStat.comstatus;
1034 ssc->ses_objmap[i].encstat[1] = ComStat.comstat[0];
1035 ssc->ses_objmap[i].encstat[2] = ComStat.comstat[1];
1036 ssc->ses_objmap[i].encstat[3] = ComStat.comstat[2];
1037 ssc->ses_objmap[i].svalid = 1;
1039 obp->cstat[0] = ssc->ses_objmap[i].encstat[0];
1040 obp->cstat[1] = ssc->ses_objmap[i].encstat[1];
1041 obp->cstat[2] = ssc->ses_objmap[i].encstat[2];
1042 obp->cstat[3] = ssc->ses_objmap[i].encstat[3];
1047 ses_set_objstat(ses_softc_t *ssc, ses_objstat *obp, int slpflag)
1052 * If this is clear, we don't do diddly.
1054 if ((obp->cstat[0] & SESCTL_CSEL) == 0) {
1057 ComStat.comstatus = obp->cstat[0];
1058 ComStat.comstat[0] = obp->cstat[1];
1059 ComStat.comstat[1] = obp->cstat[2];
1060 ComStat.comstat[2] = obp->cstat[3];
1061 err = ses_getputstat(ssc, (int)obp->obj_id, &ComStat, slpflag, 0);
1062 ssc->ses_objmap[(int)obp->obj_id].svalid = 0;
1067 ses_getconfig(ses_softc_t *ssc)
1074 int err, amt, i, nobj, ntype, maxima;
1075 char storage[CFLEN], *sdata;
1076 static char cdb[6] = {
1077 RECEIVE_DIAGNOSTIC, 0x1, SesConfigPage, SCSZ >> 8, SCSZ & 0xff, 0
1080 cc = ssc->ses_private;
1085 sdata = SES_MALLOC(SCSZ);
1090 err = ses_runcmd(ssc, cdb, 6, sdata, &amt);
1092 SES_FREE(sdata, SCSZ);
1097 if (ses_cfghdr((uint8_t *) sdata, amt, &cf)) {
1098 SES_LOG(ssc, "Unable to parse SES Config Header\n");
1099 SES_FREE(sdata, SCSZ);
1102 if (amt < SES_ENCHDR_MINLEN) {
1103 SES_LOG(ssc, "runt enclosure length (%d)\n", amt);
1104 SES_FREE(sdata, SCSZ);
1108 SES_VLOG(ssc, "GenCode %x %d Subenclosures\n", cf.GenCode, cf.Nsubenc);
1111 * Now waltz through all the subenclosures toting up the
1112 * number of types available in each. For this, we only
1113 * really need the enclosure header. However, we get the
1114 * enclosure descriptor for debug purposes, as well
1115 * as self-consistency checking purposes.
1118 maxima = cf.Nsubenc + 1;
1119 cdp = (SesEncDesc *) storage;
1120 for (ntype = i = 0; i < maxima; i++) {
1121 MEMZERO((caddr_t)cdp, sizeof (*cdp));
1122 if (ses_enchdr((uint8_t *) sdata, amt, i, &hd)) {
1123 SES_LOG(ssc, "Cannot Extract Enclosure Header %d\n", i);
1124 SES_FREE(sdata, SCSZ);
1127 SES_VLOG(ssc, " SubEnclosure ID %d, %d Types With this ID, En"
1128 "closure Length %d\n", hd.Subencid, hd.Ntypes, hd.VEnclen);
1130 if (ses_encdesc((uint8_t *)sdata, amt, i, cdp)) {
1131 SES_LOG(ssc, "Can't get Enclosure Descriptor %d\n", i);
1132 SES_FREE(sdata, SCSZ);
1135 SES_VLOG(ssc, " WWN: %02x%02x%02x%02x%02x%02x%02x%02x\n",
1136 cdp->encWWN[0], cdp->encWWN[1], cdp->encWWN[2],
1137 cdp->encWWN[3], cdp->encWWN[4], cdp->encWWN[5],
1138 cdp->encWWN[6], cdp->encWWN[7]);
1143 * Now waltz through all the types that are available, getting
1144 * the type header so we can start adding up the number of
1145 * objects available.
1147 for (nobj = i = 0; i < ntype; i++) {
1148 if (ses_getthdr((uint8_t *)sdata, amt, i, &thdr)) {
1149 SES_LOG(ssc, "Can't get Enclosure Type Header %d\n", i);
1150 SES_FREE(sdata, SCSZ);
1153 SES_LOG(ssc, " Type Desc[%d]: Type 0x%x, MaxElt %d, In Subenc "
1154 "%d, Text Length %d\n", i, thdr.enc_type, thdr.enc_maxelt,
1155 thdr.enc_subenc, thdr.enc_tlen);
1156 nobj += thdr.enc_maxelt;
1161 * Now allocate the object array and type map.
1164 ssc->ses_objmap = SES_MALLOC(nobj * sizeof (encobj));
1165 cc->ses_typidx = SES_MALLOC(nobj * sizeof (struct typidx));
1166 cc->ses_eltmap = SES_MALLOC(ntype);
1168 if (ssc->ses_objmap == NULL || cc->ses_typidx == NULL ||
1169 cc->ses_eltmap == NULL) {
1170 if (ssc->ses_objmap) {
1171 SES_FREE(ssc->ses_objmap, (nobj * sizeof (encobj)));
1172 ssc->ses_objmap = NULL;
1174 if (cc->ses_typidx) {
1175 SES_FREE(cc->ses_typidx,
1176 (nobj * sizeof (struct typidx)));
1177 cc->ses_typidx = NULL;
1179 if (cc->ses_eltmap) {
1180 SES_FREE(cc->ses_eltmap, ntype);
1181 cc->ses_eltmap = NULL;
1183 SES_FREE(sdata, SCSZ);
1186 MEMZERO(ssc->ses_objmap, nobj * sizeof (encobj));
1187 MEMZERO(cc->ses_typidx, nobj * sizeof (struct typidx));
1188 MEMZERO(cc->ses_eltmap, ntype);
1189 cc->ses_ntypes = (uint8_t) ntype;
1190 ssc->ses_nobjects = nobj;
1193 * Now waltz through the # of types again to fill in the types
1194 * (and subenclosure ids) of the allocated objects.
1197 for (i = 0; i < ntype; i++) {
1199 if (ses_getthdr((uint8_t *)sdata, amt, i, &thdr)) {
1202 cc->ses_eltmap[i] = thdr.enc_maxelt;
1203 for (j = 0; j < thdr.enc_maxelt; j++) {
1204 cc->ses_typidx[nobj].ses_tidx = i;
1205 cc->ses_typidx[nobj].ses_oidx = j;
1206 ssc->ses_objmap[nobj].subenclosure = thdr.enc_subenc;
1207 ssc->ses_objmap[nobj++].enctype = thdr.enc_type;
1210 SES_FREE(sdata, SCSZ);
1215 ses_getputstat(ses_softc_t *ssc, int objid, SesComStat *sp, int slp, int in)
1218 int err, amt, bufsiz, tidx, oidx;
1219 char cdb[6], *sdata;
1221 cc = ssc->ses_private;
1227 * If we're just getting overall enclosure status,
1228 * we only need 2 bytes of data storage.
1230 * If we're getting anything else, we know how much
1231 * storage we need by noting that starting at offset
1232 * 8 in returned data, all object status bytes are 4
1233 * bytes long, and are stored in chunks of types(M)
1234 * and nth+1 instances of type M.
1239 bufsiz = (ssc->ses_nobjects * 4) + (cc->ses_ntypes * 4) + 8;
1241 sdata = SES_MALLOC(bufsiz);
1245 cdb[0] = RECEIVE_DIAGNOSTIC;
1247 cdb[2] = SesStatusPage;
1248 cdb[3] = bufsiz >> 8;
1249 cdb[4] = bufsiz & 0xff;
1252 err = ses_runcmd(ssc, cdb, 6, sdata, &amt);
1254 SES_FREE(sdata, bufsiz);
1263 tidx = cc->ses_typidx[objid].ses_tidx;
1264 oidx = cc->ses_typidx[objid].ses_oidx;
1267 if (ses_decode(sdata, amt, cc->ses_eltmap, tidx, oidx, sp)) {
1271 if (ses_encode(sdata, amt, cc->ses_eltmap, tidx, oidx, sp)) {
1274 cdb[0] = SEND_DIAGNOSTIC;
1277 cdb[3] = bufsiz >> 8;
1278 cdb[4] = bufsiz & 0xff;
1281 err = ses_runcmd(ssc, cdb, 6, sdata, &amt);
1284 SES_FREE(sdata, bufsiz);
1290 * Routines to parse returned SES data structures.
1291 * Architecture and compiler independent.
1295 ses_cfghdr(uint8_t *buffer, int buflen, SesCfgHdr *cfp)
1297 if (buflen < SES_CFGHDR_MINLEN) {
1300 gget8(buffer, 1, cfp->Nsubenc);
1301 gget32(buffer, 4, cfp->GenCode);
1306 ses_enchdr(uint8_t *buffer, int amt, uint8_t SubEncId, SesEncHdr *chp)
1309 for (s = 0; s < SubEncId; s++) {
1312 off += buffer[off+3] + 4;
1314 if (off + 3 > amt) {
1317 gget8(buffer, off+1, chp->Subencid);
1318 gget8(buffer, off+2, chp->Ntypes);
1319 gget8(buffer, off+3, chp->VEnclen);
1324 ses_encdesc(uint8_t *buffer, int amt, uint8_t SubEncId, SesEncDesc *cdp)
1326 int s, e, enclen, off = 8;
1327 for (s = 0; s < SubEncId; s++) {
1330 off += buffer[off+3] + 4;
1332 if (off + 3 > amt) {
1335 gget8(buffer, off+3, enclen);
1344 MEMCPY(cdp, &buffer[off], e - off);
1349 ses_getthdr(uint8_t *buffer, int amt, int nth, SesThdr *thp)
1353 if (amt < SES_CFGHDR_MINLEN) {
1356 for (s = 0; s < buffer[1]; s++) {
1359 off += buffer[off+3] + 4;
1361 if (off + 3 > amt) {
1364 off += buffer[off+3] + 4 + (nth * 4);
1365 if (amt < (off + 4))
1368 gget8(buffer, off++, thp->enc_type);
1369 gget8(buffer, off++, thp->enc_maxelt);
1370 gget8(buffer, off++, thp->enc_subenc);
1371 gget8(buffer, off, thp->enc_tlen);
1376 * This function needs a little explanation.
1378 * The arguments are:
1383 * These describes the raw input SES status data and length.
1387 * This is a map of the number of types for each element type
1392 * This is the element type being sought. If elt is -1,
1393 * then overall enclosure status is being sought.
1397 * This is the ordinal Mth element of type elt being sought.
1401 * This is the output area to store the status for
1402 * the Mth element of type Elt.
1406 ses_decode(char *b, int amt, uint8_t *ep, int elt, int elm, SesComStat *sp)
1411 * If it's overall enclosure status being sought, get that.
1412 * We need at least 2 bytes of status data to get that.
1417 gget8(b, 1, sp->comstatus);
1425 * Check to make sure that the Mth element is legal for type Elt.
1432 * Starting at offset 8, start skipping over the storage
1433 * for the element types we're not interested in.
1435 for (idx = 8, i = 0; i < elt; i++) {
1436 idx += ((ep[i] + 1) * 4);
1440 * Skip over Overall status for this element type.
1445 * And skip to the index for the Mth element that we're going for.
1450 * Make sure we haven't overflowed the buffer.
1456 * Retrieve the status.
1458 gget8(b, idx++, sp->comstatus);
1459 gget8(b, idx++, sp->comstat[0]);
1460 gget8(b, idx++, sp->comstat[1]);
1461 gget8(b, idx++, sp->comstat[2]);
1463 PRINTF("Get Elt 0x%x Elm 0x%x (idx %d)\n", elt, elm, idx-4);
1469 * This is the mirror function to ses_decode, but we set the 'select'
1470 * bit for the object which we're interested in. All other objects,
1471 * after a status fetch, should have that bit off. Hmm. It'd be easy
1472 * enough to ensure this, so we will.
1476 ses_encode(char *b, int amt, uint8_t *ep, int elt, int elm, SesComStat *sp)
1481 * If it's overall enclosure status being sought, get that.
1482 * We need at least 2 bytes of status data to get that.
1489 sset8(b, i, sp->comstatus & 0xf);
1491 PRINTF("set EncStat %x\n", sp->comstatus);
1497 * Check to make sure that the Mth element is legal for type Elt.
1504 * Starting at offset 8, start skipping over the storage
1505 * for the element types we're not interested in.
1507 for (idx = 8, i = 0; i < elt; i++) {
1508 idx += ((ep[i] + 1) * 4);
1512 * Skip over Overall status for this element type.
1517 * And skip to the index for the Mth element that we're going for.
1522 * Make sure we haven't overflowed the buffer.
1530 sset8(b, idx, sp->comstatus);
1531 sset8(b, idx, sp->comstat[0]);
1532 sset8(b, idx, sp->comstat[1]);
1533 sset8(b, idx, sp->comstat[2]);
1537 PRINTF("Set Elt 0x%x Elm 0x%x (idx %d) with %x %x %x %x\n",
1538 elt, elm, idx, sp->comstatus, sp->comstat[0],
1539 sp->comstat[1], sp->comstat[2]);
1543 * Now make sure all other 'Select' bits are off.
1545 for (i = 8; i < amt; i += 4) {
1550 * And make sure the INVOP bit is clear.
1558 * SAF-TE Type Device Emulation
1561 static int safte_getconfig(ses_softc_t *);
1562 static int safte_rdstat(ses_softc_t *, int);
1563 static int set_objstat_sel(ses_softc_t *, ses_objstat *, int);
1564 static int wrbuf16(ses_softc_t *, uint8_t, uint8_t, uint8_t, uint8_t, int);
1565 static void wrslot_stat(ses_softc_t *, int);
1566 static int perf_slotop(ses_softc_t *, uint8_t, uint8_t, int);
1568 #define ALL_ENC_STAT (SES_ENCSTAT_CRITICAL | SES_ENCSTAT_UNRECOV | \
1569 SES_ENCSTAT_NONCRITICAL | SES_ENCSTAT_INFO)
1571 * SAF-TE specific defines- Mandatory ones only...
1575 * READ BUFFER ('get' commands) IDs- placed in offset 2 of cdb
1577 #define SAFTE_RD_RDCFG 0x00 /* read enclosure configuration */
1578 #define SAFTE_RD_RDESTS 0x01 /* read enclosure status */
1579 #define SAFTE_RD_RDDSTS 0x04 /* read drive slot status */
1582 * WRITE BUFFER ('set' commands) IDs- placed in offset 0 of databuf
1584 #define SAFTE_WT_DSTAT 0x10 /* write device slot status */
1585 #define SAFTE_WT_SLTOP 0x12 /* perform slot operation */
1586 #define SAFTE_WT_FANSPD 0x13 /* set fan speed */
1587 #define SAFTE_WT_ACTPWS 0x14 /* turn on/off power supply */
1588 #define SAFTE_WT_GLOBAL 0x15 /* send global command */
1591 #define SAFT_SCRATCH 64
1592 #define NPSEUDO_THERM 16
1593 #define NPSEUDO_ALARM 1
1596 * Cached Configuration
1598 uint8_t Nfans; /* Number of Fans */
1599 uint8_t Npwr; /* Number of Power Supplies */
1600 uint8_t Nslots; /* Number of Device Slots */
1601 uint8_t DoorLock; /* Door Lock Installed */
1602 uint8_t Ntherm; /* Number of Temperature Sensors */
1603 uint8_t Nspkrs; /* Number of Speakers */
1604 uint8_t Nalarm; /* Number of Alarms (at least one) */
1606 * Cached Flag Bytes for Global Status
1611 * What object index ID is where various slots start.
1615 #define SAFT_ALARM_OFFSET(cc) (cc)->slotoff - 1
1618 #define SAFT_FLG1_ALARM 0x1
1619 #define SAFT_FLG1_GLOBFAIL 0x2
1620 #define SAFT_FLG1_GLOBWARN 0x4
1621 #define SAFT_FLG1_ENCPWROFF 0x8
1622 #define SAFT_FLG1_ENCFANFAIL 0x10
1623 #define SAFT_FLG1_ENCPWRFAIL 0x20
1624 #define SAFT_FLG1_ENCDRVFAIL 0x40
1625 #define SAFT_FLG1_ENCDRVWARN 0x80
1627 #define SAFT_FLG2_LOCKDOOR 0x4
1628 #define SAFT_PRIVATE sizeof (struct scfg)
1630 static char *safte_2little = "Too Little Data Returned (%d) at line %d\n";
1631 #define SAFT_BAIL(r, x, k, l) \
1633 SES_LOG(ssc, safte_2little, x, __LINE__);\
1634 SES_FREE((k), (l)); \
1640 safte_softc_init(ses_softc_t *ssc, int doinit)
1646 if (ssc->ses_nobjects) {
1647 if (ssc->ses_objmap) {
1648 SES_FREE(ssc->ses_objmap,
1649 ssc->ses_nobjects * sizeof (encobj));
1650 ssc->ses_objmap = NULL;
1652 ssc->ses_nobjects = 0;
1654 if (ssc->ses_private) {
1655 SES_FREE(ssc->ses_private, SAFT_PRIVATE);
1656 ssc->ses_private = NULL;
1661 if (ssc->ses_private == NULL) {
1662 ssc->ses_private = SES_MALLOC(SAFT_PRIVATE);
1663 if (ssc->ses_private == NULL) {
1666 MEMZERO(ssc->ses_private, SAFT_PRIVATE);
1669 ssc->ses_nobjects = 0;
1670 ssc->ses_encstat = 0;
1672 if ((err = safte_getconfig(ssc)) != 0) {
1677 * The number of objects here, as well as that reported by the
1678 * READ_BUFFER/GET_CONFIG call, are the over-temperature flags (15)
1679 * that get reported during READ_BUFFER/READ_ENC_STATUS.
1681 cc = ssc->ses_private;
1682 ssc->ses_nobjects = cc->Nfans + cc->Npwr + cc->Nslots + cc->DoorLock +
1683 cc->Ntherm + cc->Nspkrs + NPSEUDO_THERM + NPSEUDO_ALARM;
1684 ssc->ses_objmap = (encobj *)
1685 SES_MALLOC(ssc->ses_nobjects * sizeof (encobj));
1686 if (ssc->ses_objmap == NULL) {
1689 MEMZERO(ssc->ses_objmap, ssc->ses_nobjects * sizeof (encobj));
1693 * Note that this is all arranged for the convenience
1694 * in later fetches of status.
1696 for (i = 0; i < cc->Nfans; i++)
1697 ssc->ses_objmap[r++].enctype = SESTYP_FAN;
1698 cc->pwroff = (uint8_t) r;
1699 for (i = 0; i < cc->Npwr; i++)
1700 ssc->ses_objmap[r++].enctype = SESTYP_POWER;
1701 for (i = 0; i < cc->DoorLock; i++)
1702 ssc->ses_objmap[r++].enctype = SESTYP_DOORLOCK;
1703 for (i = 0; i < cc->Nspkrs; i++)
1704 ssc->ses_objmap[r++].enctype = SESTYP_ALARM;
1705 for (i = 0; i < cc->Ntherm; i++)
1706 ssc->ses_objmap[r++].enctype = SESTYP_THERM;
1707 for (i = 0; i < NPSEUDO_THERM; i++)
1708 ssc->ses_objmap[r++].enctype = SESTYP_THERM;
1709 ssc->ses_objmap[r++].enctype = SESTYP_ALARM;
1710 cc->slotoff = (uint8_t) r;
1711 for (i = 0; i < cc->Nslots; i++)
1712 ssc->ses_objmap[r++].enctype = SESTYP_DEVICE;
1717 safte_init_enc(ses_softc_t *ssc)
1720 static char cdb0[6] = { SEND_DIAGNOSTIC };
1722 err = ses_runcmd(ssc, cdb0, 6, NULL, 0);
1727 err = wrbuf16(ssc, SAFTE_WT_GLOBAL, 0, 0, 0, 1);
1732 safte_get_encstat(ses_softc_t *ssc, int slpflg)
1734 return (safte_rdstat(ssc, slpflg));
1738 safte_set_encstat(ses_softc_t *ssc, uint8_t encstat, int slpflg)
1740 struct scfg *cc = ssc->ses_private;
1744 * Since SAF-TE devices aren't necessarily sticky in terms
1745 * of state, make our soft copy of enclosure status 'sticky'-
1746 * that is, things set in enclosure status stay set (as implied
1747 * by conditions set in reading object status) until cleared.
1749 ssc->ses_encstat &= ~ALL_ENC_STAT;
1750 ssc->ses_encstat |= (encstat & ALL_ENC_STAT);
1751 ssc->ses_encstat |= ENCI_SVALID;
1752 cc->flag1 &= ~(SAFT_FLG1_ALARM|SAFT_FLG1_GLOBFAIL|SAFT_FLG1_GLOBWARN);
1753 if ((encstat & (SES_ENCSTAT_CRITICAL|SES_ENCSTAT_UNRECOV)) != 0) {
1754 cc->flag1 |= SAFT_FLG1_ALARM|SAFT_FLG1_GLOBFAIL;
1755 } else if ((encstat & SES_ENCSTAT_NONCRITICAL) != 0) {
1756 cc->flag1 |= SAFT_FLG1_GLOBWARN;
1758 return (wrbuf16(ssc, SAFTE_WT_GLOBAL, cc->flag1, cc->flag2, 0, slpflg));
1762 safte_get_objstat(ses_softc_t *ssc, ses_objstat *obp, int slpflg)
1764 int i = (int)obp->obj_id;
1766 if ((ssc->ses_encstat & ENCI_SVALID) == 0 ||
1767 (ssc->ses_objmap[i].svalid) == 0) {
1768 int err = safte_rdstat(ssc, slpflg);
1772 obp->cstat[0] = ssc->ses_objmap[i].encstat[0];
1773 obp->cstat[1] = ssc->ses_objmap[i].encstat[1];
1774 obp->cstat[2] = ssc->ses_objmap[i].encstat[2];
1775 obp->cstat[3] = ssc->ses_objmap[i].encstat[3];
1781 safte_set_objstat(ses_softc_t *ssc, ses_objstat *obp, int slp)
1788 SES_DLOG(ssc, "safte_set_objstat(%d): %x %x %x %x\n",
1789 (int)obp->obj_id, obp->cstat[0], obp->cstat[1], obp->cstat[2],
1793 * If this is clear, we don't do diddly.
1795 if ((obp->cstat[0] & SESCTL_CSEL) == 0) {
1801 * Check to see if the common bits are set and do them first.
1803 if (obp->cstat[0] & ~SESCTL_CSEL) {
1804 err = set_objstat_sel(ssc, obp, slp);
1809 cc = ssc->ses_private;
1813 idx = (int)obp->obj_id;
1814 ep = &ssc->ses_objmap[idx];
1816 switch (ep->enctype) {
1821 * XXX: I should probably cache the previous state
1822 * XXX: of SESCTL_DEVOFF so that when it goes from
1823 * XXX: true to false I can then set PREPARE FOR OPERATION
1824 * XXX: flag in PERFORM SLOT OPERATION write buffer command.
1826 if (obp->cstat[2] & (SESCTL_RQSINS|SESCTL_RQSRMV)) {
1829 if (obp->cstat[2] & SESCTL_RQSID) {
1832 err = perf_slotop(ssc, (uint8_t) idx - (uint8_t) cc->slotoff,
1836 if (obp->cstat[3] & SESCTL_RQSFLT) {
1841 if (ep->priv & 0xc6) {
1844 ep->priv |= 0x1; /* no errors */
1846 wrslot_stat(ssc, slp);
1850 if (obp->cstat[3] & SESCTL_RQSTFAIL) {
1851 cc->flag1 |= SAFT_FLG1_ENCPWRFAIL;
1853 cc->flag1 &= ~SAFT_FLG1_ENCPWRFAIL;
1855 err = wrbuf16(ssc, SAFTE_WT_GLOBAL, cc->flag1,
1859 if (obp->cstat[3] & SESCTL_RQSTON) {
1860 wrbuf16(ssc, SAFTE_WT_ACTPWS,
1861 idx - cc->pwroff, 0, 0, slp);
1863 wrbuf16(ssc, SAFTE_WT_ACTPWS,
1864 idx - cc->pwroff, 0, 1, slp);
1868 if (obp->cstat[3] & SESCTL_RQSTFAIL) {
1869 cc->flag1 |= SAFT_FLG1_ENCFANFAIL;
1871 cc->flag1 &= ~SAFT_FLG1_ENCFANFAIL;
1873 err = wrbuf16(ssc, SAFTE_WT_GLOBAL, cc->flag1,
1877 if (obp->cstat[3] & SESCTL_RQSTON) {
1879 if ((obp->cstat[3] & 0x7) == 7) {
1881 } else if ((obp->cstat[3] & 0x7) == 6) {
1883 } else if ((obp->cstat[3] & 0x7) == 4) {
1888 wrbuf16(ssc, SAFTE_WT_FANSPD, idx, fsp, 0, slp);
1890 wrbuf16(ssc, SAFTE_WT_FANSPD, idx, 0, 0, slp);
1893 case SESTYP_DOORLOCK:
1894 if (obp->cstat[3] & 0x1) {
1895 cc->flag2 &= ~SAFT_FLG2_LOCKDOOR;
1897 cc->flag2 |= SAFT_FLG2_LOCKDOOR;
1899 wrbuf16(ssc, SAFTE_WT_GLOBAL, cc->flag1, cc->flag2, 0, slp);
1903 * On all nonzero but the 'muted' bit, we turn on the alarm,
1905 obp->cstat[3] &= ~0xa;
1906 if (obp->cstat[3] & 0x40) {
1907 cc->flag2 &= ~SAFT_FLG1_ALARM;
1908 } else if (obp->cstat[3] != 0) {
1909 cc->flag2 |= SAFT_FLG1_ALARM;
1911 cc->flag2 &= ~SAFT_FLG1_ALARM;
1913 ep->priv = obp->cstat[3];
1914 wrbuf16(ssc, SAFTE_WT_GLOBAL, cc->flag1, cc->flag2, 0, slp);
1924 safte_getconfig(ses_softc_t *ssc)
1929 static char cdb[10] =
1930 { READ_BUFFER, 1, SAFTE_RD_RDCFG, 0, 0, 0, 0, 0, SAFT_SCRATCH, 0 };
1932 cfg = ssc->ses_private;
1936 sdata = SES_MALLOC(SAFT_SCRATCH);
1941 err = ses_runcmd(ssc, cdb, 10, sdata, &amt);
1943 SES_FREE(sdata, SAFT_SCRATCH);
1946 amt = SAFT_SCRATCH - amt;
1948 SES_LOG(ssc, "too little data (%d) for configuration\n", amt);
1949 SES_FREE(sdata, SAFT_SCRATCH);
1952 SES_VLOG(ssc, "Nfans %d Npwr %d Nslots %d Lck %d Ntherm %d Nspkrs %d\n",
1953 sdata[0], sdata[1], sdata[2], sdata[3], sdata[4], sdata[5]);
1954 cfg->Nfans = sdata[0];
1955 cfg->Npwr = sdata[1];
1956 cfg->Nslots = sdata[2];
1957 cfg->DoorLock = sdata[3];
1958 cfg->Ntherm = sdata[4];
1959 cfg->Nspkrs = sdata[5];
1960 cfg->Nalarm = NPSEUDO_ALARM;
1961 SES_FREE(sdata, SAFT_SCRATCH);
1966 safte_rdstat(ses_softc_t *ssc, int slpflg)
1968 int err, oid, r, i, hiwater, nitems, amt;
1971 uint8_t status, oencstat;
1972 char *sdata, cdb[10];
1973 struct scfg *cc = ssc->ses_private;
1977 * The number of objects overstates things a bit,
1978 * both for the bogus 'thermometer' entries and
1979 * the drive status (which isn't read at the same
1980 * time as the enclosure status), but that's okay.
1982 buflen = 4 * cc->Nslots;
1983 if (ssc->ses_nobjects > buflen)
1984 buflen = ssc->ses_nobjects;
1985 sdata = SES_MALLOC(buflen);
1989 cdb[0] = READ_BUFFER;
1991 cdb[2] = SAFTE_RD_RDESTS;
1996 cdb[7] = (buflen >> 8) & 0xff;
1997 cdb[8] = buflen & 0xff;
2000 err = ses_runcmd(ssc, cdb, 10, sdata, &amt);
2002 SES_FREE(sdata, buflen);
2005 hiwater = buflen - amt;
2009 * invalidate all status bits.
2011 for (i = 0; i < ssc->ses_nobjects; i++)
2012 ssc->ses_objmap[i].svalid = 0;
2013 oencstat = ssc->ses_encstat & ALL_ENC_STAT;
2014 ssc->ses_encstat = 0;
2018 * Now parse returned buffer.
2019 * If we didn't get enough data back,
2020 * that's considered a fatal error.
2024 for (nitems = i = 0; i < cc->Nfans; i++) {
2025 SAFT_BAIL(r, hiwater, sdata, buflen);
2027 * 0 = Fan Operational
2028 * 1 = Fan is malfunctioning
2029 * 2 = Fan is not present
2030 * 0x80 = Unknown or Not Reportable Status
2032 ssc->ses_objmap[oid].encstat[1] = 0; /* resvd */
2033 ssc->ses_objmap[oid].encstat[2] = 0; /* resvd */
2034 switch ((int)(uint8_t)sdata[r]) {
2037 ssc->ses_objmap[oid].encstat[0] = SES_OBJSTAT_OK;
2039 * We could get fancier and cache
2040 * fan speeds that we have set, but
2041 * that isn't done now.
2043 ssc->ses_objmap[oid].encstat[3] = 7;
2047 ssc->ses_objmap[oid].encstat[0] = SES_OBJSTAT_CRIT;
2049 * FAIL and FAN STOPPED synthesized
2051 ssc->ses_objmap[oid].encstat[3] = 0x40;
2053 * Enclosure marked with CRITICAL error
2054 * if only one fan or no thermometers,
2055 * else the NONCRITICAL error is set.
2057 if (cc->Nfans == 1 || cc->Ntherm == 0)
2058 ssc->ses_encstat |= SES_ENCSTAT_CRITICAL;
2060 ssc->ses_encstat |= SES_ENCSTAT_NONCRITICAL;
2063 ssc->ses_objmap[oid].encstat[0] =
2064 SES_OBJSTAT_NOTINSTALLED;
2065 ssc->ses_objmap[oid].encstat[3] = 0;
2067 * Enclosure marked with CRITICAL error
2068 * if only one fan or no thermometers,
2069 * else the NONCRITICAL error is set.
2072 ssc->ses_encstat |= SES_ENCSTAT_CRITICAL;
2074 ssc->ses_encstat |= SES_ENCSTAT_NONCRITICAL;
2077 ssc->ses_objmap[oid].encstat[0] = SES_OBJSTAT_UNKNOWN;
2078 ssc->ses_objmap[oid].encstat[3] = 0;
2079 ssc->ses_encstat |= SES_ENCSTAT_INFO;
2082 ssc->ses_objmap[oid].encstat[0] =
2083 SES_OBJSTAT_UNSUPPORTED;
2084 SES_LOG(ssc, "Unknown fan%d status 0x%x\n", i,
2088 ssc->ses_objmap[oid++].svalid = 1;
2093 * No matter how you cut it, no cooling elements when there
2094 * should be some there is critical.
2096 if (cc->Nfans && nitems == 0) {
2097 ssc->ses_encstat |= SES_ENCSTAT_CRITICAL;
2101 for (i = 0; i < cc->Npwr; i++) {
2102 SAFT_BAIL(r, hiwater, sdata, buflen);
2103 ssc->ses_objmap[oid].encstat[0] = SES_OBJSTAT_UNKNOWN;
2104 ssc->ses_objmap[oid].encstat[1] = 0; /* resvd */
2105 ssc->ses_objmap[oid].encstat[2] = 0; /* resvd */
2106 ssc->ses_objmap[oid].encstat[3] = 0x20; /* requested on */
2107 switch ((uint8_t)sdata[r]) {
2108 case 0x00: /* pws operational and on */
2109 ssc->ses_objmap[oid].encstat[0] = SES_OBJSTAT_OK;
2111 case 0x01: /* pws operational and off */
2112 ssc->ses_objmap[oid].encstat[0] = SES_OBJSTAT_OK;
2113 ssc->ses_objmap[oid].encstat[3] = 0x10;
2114 ssc->ses_encstat |= SES_ENCSTAT_INFO;
2116 case 0x10: /* pws is malfunctioning and commanded on */
2117 ssc->ses_objmap[oid].encstat[0] = SES_OBJSTAT_CRIT;
2118 ssc->ses_objmap[oid].encstat[3] = 0x61;
2119 ssc->ses_encstat |= SES_ENCSTAT_NONCRITICAL;
2122 case 0x11: /* pws is malfunctioning and commanded off */
2123 ssc->ses_objmap[oid].encstat[0] = SES_OBJSTAT_NONCRIT;
2124 ssc->ses_objmap[oid].encstat[3] = 0x51;
2125 ssc->ses_encstat |= SES_ENCSTAT_NONCRITICAL;
2127 case 0x20: /* pws is not present */
2128 ssc->ses_objmap[oid].encstat[0] =
2129 SES_OBJSTAT_NOTINSTALLED;
2130 ssc->ses_objmap[oid].encstat[3] = 0;
2131 ssc->ses_encstat |= SES_ENCSTAT_INFO;
2133 case 0x21: /* pws is present */
2135 * This is for enclosures that cannot tell whether the
2136 * device is on or malfunctioning, but know that it is
2137 * present. Just fall through.
2140 case 0x80: /* Unknown or Not Reportable Status */
2141 ssc->ses_objmap[oid].encstat[0] = SES_OBJSTAT_UNKNOWN;
2142 ssc->ses_objmap[oid].encstat[3] = 0;
2143 ssc->ses_encstat |= SES_ENCSTAT_INFO;
2146 SES_LOG(ssc, "unknown power supply %d status (0x%x)\n",
2147 i, sdata[r] & 0xff);
2150 ssc->ses_objmap[oid++].svalid = 1;
2155 * Skip over Slot SCSI IDs
2160 * We always have doorlock status, no matter what,
2161 * but we only save the status if we have one.
2163 SAFT_BAIL(r, hiwater, sdata, buflen);
2167 * 1 = Door Unlocked, or no Lock Installed
2168 * 0x80 = Unknown or Not Reportable Status
2170 ssc->ses_objmap[oid].encstat[1] = 0;
2171 ssc->ses_objmap[oid].encstat[2] = 0;
2172 switch ((uint8_t)sdata[r]) {
2174 ssc->ses_objmap[oid].encstat[0] = SES_OBJSTAT_OK;
2175 ssc->ses_objmap[oid].encstat[3] = 0;
2178 ssc->ses_objmap[oid].encstat[0] = SES_OBJSTAT_OK;
2179 ssc->ses_objmap[oid].encstat[3] = 1;
2182 ssc->ses_objmap[oid].encstat[0] = SES_OBJSTAT_UNKNOWN;
2183 ssc->ses_objmap[oid].encstat[3] = 0;
2184 ssc->ses_encstat |= SES_ENCSTAT_INFO;
2187 ssc->ses_objmap[oid].encstat[0] =
2188 SES_OBJSTAT_UNSUPPORTED;
2189 SES_LOG(ssc, "unknown lock status 0x%x\n",
2193 ssc->ses_objmap[oid++].svalid = 1;
2198 * We always have speaker status, no matter what,
2199 * but we only save the status if we have one.
2201 SAFT_BAIL(r, hiwater, sdata, buflen);
2203 ssc->ses_objmap[oid].encstat[1] = 0;
2204 ssc->ses_objmap[oid].encstat[2] = 0;
2205 if (sdata[r] == 1) {
2207 * We need to cache tone urgency indicators.
2210 ssc->ses_objmap[oid].encstat[0] = SES_OBJSTAT_NONCRIT;
2211 ssc->ses_objmap[oid].encstat[3] = 0x8;
2212 ssc->ses_encstat |= SES_ENCSTAT_NONCRITICAL;
2213 } else if (sdata[r] == 0) {
2214 ssc->ses_objmap[oid].encstat[0] = SES_OBJSTAT_OK;
2215 ssc->ses_objmap[oid].encstat[3] = 0;
2217 ssc->ses_objmap[oid].encstat[0] =
2218 SES_OBJSTAT_UNSUPPORTED;
2219 ssc->ses_objmap[oid].encstat[3] = 0;
2220 SES_LOG(ssc, "unknown spkr status 0x%x\n",
2223 ssc->ses_objmap[oid++].svalid = 1;
2227 for (i = 0; i < cc->Ntherm; i++) {
2228 SAFT_BAIL(r, hiwater, sdata, buflen);
2230 * Status is a range from -10 to 245 deg Celsius,
2231 * which we need to normalize to -20 to -245 according
2232 * to the latest SCSI spec, which makes little
2233 * sense since this would overflow an 8bit value.
2234 * Well, still, the base normalization is -20,
2235 * not -10, so we have to adjust.
2237 * So what's over and under temperature?
2238 * Hmm- we'll state that 'normal' operating
2239 * is 10 to 40 deg Celsius.
2243 * Actually.... All of the units that people out in the world
2244 * seem to have do not come even close to setting a value that
2245 * complies with this spec.
2247 * The closest explanation I could find was in an
2248 * LSI-Logic manual, which seemed to indicate that
2249 * this value would be set by whatever the I2C code
2250 * would interpolate from the output of an LM75
2251 * temperature sensor.
2253 * This means that it is impossible to use the actual
2254 * numeric value to predict anything. But we don't want
2255 * to lose the value. So, we'll propagate the *uncorrected*
2256 * value and set SES_OBJSTAT_NOTAVAIL. We'll depend on the
2257 * temperature flags for warnings.
2259 ssc->ses_objmap[oid].encstat[0] = SES_OBJSTAT_NOTAVAIL;
2260 ssc->ses_objmap[oid].encstat[1] = 0;
2261 ssc->ses_objmap[oid].encstat[2] = sdata[r];
2262 ssc->ses_objmap[oid].encstat[3] = 0;
2263 ssc->ses_objmap[oid++].svalid = 1;
2268 * Now, for "pseudo" thermometers, we have two bytes
2269 * of information in enclosure status- 16 bits. Actually,
2270 * the MSB is a single TEMP ALERT flag indicating whether
2271 * any other bits are set, but, thanks to fuzzy thinking,
2272 * in the SAF-TE spec, this can also be set even if no
2273 * other bits are set, thus making this really another
2274 * binary temperature sensor.
2277 SAFT_BAIL(r, hiwater, sdata, buflen);
2278 tempflags = sdata[r++];
2279 SAFT_BAIL(r, hiwater, sdata, buflen);
2280 tempflags |= (tempflags << 8) | sdata[r++];
2282 for (i = 0; i < NPSEUDO_THERM; i++) {
2283 ssc->ses_objmap[oid].encstat[1] = 0;
2284 if (tempflags & (1 << (NPSEUDO_THERM - i - 1))) {
2285 ssc->ses_objmap[oid].encstat[0] = SES_OBJSTAT_CRIT;
2286 ssc->ses_objmap[4].encstat[2] = 0xff;
2288 * Set 'over temperature' failure.
2290 ssc->ses_objmap[oid].encstat[3] = 8;
2291 ssc->ses_encstat |= SES_ENCSTAT_CRITICAL;
2294 * We used to say 'not available' and synthesize a
2295 * nominal 30 deg (C)- that was wrong. Actually,
2296 * Just say 'OK', and use the reserved value of
2299 ssc->ses_objmap[oid].encstat[0] = SES_OBJSTAT_OK;
2300 ssc->ses_objmap[oid].encstat[2] = 0;
2301 ssc->ses_objmap[oid].encstat[3] = 0;
2303 ssc->ses_objmap[oid++].svalid = 1;
2309 ssc->ses_objmap[oid].encstat[0] = SES_OBJSTAT_OK;
2310 ssc->ses_objmap[oid].encstat[3] = ssc->ses_objmap[oid].priv;
2311 ssc->ses_objmap[oid++].svalid = 1;
2314 * Now get drive slot status
2316 cdb[2] = SAFTE_RD_RDDSTS;
2318 err = ses_runcmd(ssc, cdb, 10, sdata, &amt);
2320 SES_FREE(sdata, buflen);
2323 hiwater = buflen - amt;
2324 for (r = i = 0; i < cc->Nslots; i++, r += 4) {
2325 SAFT_BAIL(r+3, hiwater, sdata, buflen);
2326 ssc->ses_objmap[oid].encstat[0] = SES_OBJSTAT_UNSUPPORTED;
2327 ssc->ses_objmap[oid].encstat[1] = (uint8_t) i;
2328 ssc->ses_objmap[oid].encstat[2] = 0;
2329 ssc->ses_objmap[oid].encstat[3] = 0;
2330 status = sdata[r+3];
2331 if ((status & 0x1) == 0) { /* no device */
2332 ssc->ses_objmap[oid].encstat[0] =
2333 SES_OBJSTAT_NOTINSTALLED;
2335 ssc->ses_objmap[oid].encstat[0] = SES_OBJSTAT_OK;
2338 ssc->ses_objmap[oid].encstat[2] = 0x8;
2340 if ((status & 0x4) == 0) {
2341 ssc->ses_objmap[oid].encstat[3] = 0x10;
2343 ssc->ses_objmap[oid++].svalid = 1;
2345 /* see comment below about sticky enclosure status */
2346 ssc->ses_encstat |= ENCI_SVALID | oencstat;
2347 SES_FREE(sdata, buflen);
2352 set_objstat_sel(ses_softc_t *ssc, ses_objstat *obp, int slp)
2356 struct scfg *cc = ssc->ses_private;
2361 idx = (int)obp->obj_id;
2362 ep = &ssc->ses_objmap[idx];
2364 switch (ep->enctype) {
2366 if (obp->cstat[0] & SESCTL_PRDFAIL) {
2369 /* SESCTL_RSTSWAP has no correspondence in SAF-TE */
2370 if (obp->cstat[0] & SESCTL_DISABLE) {
2373 * Hmm. Try to set the 'No Drive' flag.
2374 * Maybe that will count as a 'disable'.
2377 if (ep->priv & 0xc6) {
2380 ep->priv |= 0x1; /* no errors */
2382 wrslot_stat(ssc, slp);
2386 * Okay- the only one that makes sense here is to
2387 * do the 'disable' for a power supply.
2389 if (obp->cstat[0] & SESCTL_DISABLE) {
2390 wrbuf16(ssc, SAFTE_WT_ACTPWS,
2391 idx - cc->pwroff, 0, 0, slp);
2396 * Okay- the only one that makes sense here is to
2397 * set fan speed to zero on disable.
2399 if (obp->cstat[0] & SESCTL_DISABLE) {
2400 /* remember- fans are the first items, so idx works */
2401 wrbuf16(ssc, SAFTE_WT_FANSPD, idx, 0, 0, slp);
2404 case SESTYP_DOORLOCK:
2406 * Well, we can 'disable' the lock.
2408 if (obp->cstat[0] & SESCTL_DISABLE) {
2409 cc->flag2 &= ~SAFT_FLG2_LOCKDOOR;
2410 wrbuf16(ssc, SAFTE_WT_GLOBAL, cc->flag1,
2416 * Well, we can 'disable' the alarm.
2418 if (obp->cstat[0] & SESCTL_DISABLE) {
2419 cc->flag2 &= ~SAFT_FLG1_ALARM;
2420 ep->priv |= 0x40; /* Muted */
2421 wrbuf16(ssc, SAFTE_WT_GLOBAL, cc->flag1,
2433 * This function handles all of the 16 byte WRITE BUFFER commands.
2436 wrbuf16(ses_softc_t *ssc, uint8_t op, uint8_t b1, uint8_t b2,
2437 uint8_t b3, int slp)
2441 struct scfg *cc = ssc->ses_private;
2442 static char cdb[10] = { WRITE_BUFFER, 1, 0, 0, 0, 0, 0, 0, 16, 0 };
2447 sdata = SES_MALLOC(16);
2451 SES_DLOG(ssc, "saf_wrbuf16 %x %x %x %x\n", op, b1, b2, b3);
2457 MEMZERO(&sdata[4], 12);
2459 err = ses_runcmd(ssc, cdb, 10, sdata, &amt);
2460 SES_FREE(sdata, 16);
2465 * This function updates the status byte for the device slot described.
2467 * Since this is an optional SAF-TE command, there's no point in
2468 * returning an error.
2471 wrslot_stat(ses_softc_t *ssc, int slp)
2475 char cdb[10], *sdata;
2476 struct scfg *cc = ssc->ses_private;
2481 SES_DLOG(ssc, "saf_wrslot\n");
2482 cdb[0] = WRITE_BUFFER;
2490 cdb[8] = cc->Nslots * 3 + 1;
2493 sdata = SES_MALLOC(cc->Nslots * 3 + 1);
2496 MEMZERO(sdata, cc->Nslots * 3 + 1);
2498 sdata[0] = SAFTE_WT_DSTAT;
2499 for (i = 0; i < cc->Nslots; i++) {
2500 ep = &ssc->ses_objmap[cc->slotoff + i];
2501 SES_DLOG(ssc, "saf_wrslot %d <- %x\n", i, ep->priv & 0xff);
2502 sdata[1 + (3 * i)] = ep->priv & 0xff;
2504 amt = -(cc->Nslots * 3 + 1);
2505 ses_runcmd(ssc, cdb, 10, sdata, &amt);
2506 SES_FREE(sdata, cc->Nslots * 3 + 1);
2510 * This function issues the "PERFORM SLOT OPERATION" command.
2513 perf_slotop(ses_softc_t *ssc, uint8_t slot, uint8_t opflag, int slp)
2517 struct scfg *cc = ssc->ses_private;
2518 static char cdb[10] =
2519 { WRITE_BUFFER, 1, 0, 0, 0, 0, 0, 0, SAFT_SCRATCH, 0 };
2524 sdata = SES_MALLOC(SAFT_SCRATCH);
2527 MEMZERO(sdata, SAFT_SCRATCH);
2529 sdata[0] = SAFTE_WT_SLTOP;
2532 SES_DLOG(ssc, "saf_slotop slot %d op %x\n", slot, opflag);
2533 amt = -SAFT_SCRATCH;
2534 err = ses_runcmd(ssc, cdb, 10, sdata, &amt);
2535 SES_FREE(sdata, SAFT_SCRATCH);