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.28 2007/12/01 22:21:18 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"
51 #include "scsi_message.h"
52 #include <sys/ioccom.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;
194 struct cam_path *path;
197 * Create our extend array for storing the devices we attach to.
199 sesperiphs = cam_extend_new();
200 if (sesperiphs == NULL) {
201 kprintf("ses: Failed to alloc extend array!\n");
206 * Install a global async callback. This callback will
207 * receive async callbacks like "new device found".
209 status = xpt_create_path(&path, NULL, CAM_XPT_PATH_ID,
210 CAM_TARGET_WILDCARD, CAM_LUN_WILDCARD);
212 if (status == CAM_REQ_CMP) {
213 struct ccb_setasync csa;
215 xpt_setup_ccb(&csa.ccb_h, path, 5);
216 csa.ccb_h.func_code = XPT_SASYNC_CB;
217 csa.event_enable = AC_FOUND_DEVICE;
218 csa.callback = sesasync;
219 csa.callback_arg = NULL;
220 xpt_action((union ccb *)&csa);
221 status = csa.ccb_h.status;
225 if (status != CAM_REQ_CMP) {
226 kprintf("ses: Failed to attach master async callback "
227 "due to status 0x%x!\n", status);
232 sesoninvalidate(struct cam_periph *periph)
234 struct ses_softc *softc;
235 struct ccb_setasync csa;
237 softc = (struct ses_softc *)periph->softc;
240 * Unregister any async callbacks.
242 xpt_setup_ccb(&csa.ccb_h, periph->path, 5);
243 csa.ccb_h.func_code = XPT_SASYNC_CB;
244 csa.event_enable = 0;
245 csa.callback = sesasync;
246 csa.callback_arg = periph;
247 xpt_action((union ccb *)&csa);
249 softc->ses_flags |= SES_FLAG_INVALID;
251 xpt_print_path(periph->path);
252 kprintf("lost device\n");
256 sescleanup(struct cam_periph *periph)
258 struct ses_softc *softc;
260 softc = (struct ses_softc *)periph->softc;
262 cam_extend_release(sesperiphs, periph->unit_number);
263 xpt_print_path(periph->path);
264 kprintf("removing device entry\n");
265 dev_ops_remove(&ses_ops, -1, periph->unit_number);
266 kfree(softc, M_SCSISES);
270 sesasync(void *callback_arg, u_int32_t code, struct cam_path *path, void *arg)
272 struct cam_periph *periph;
274 periph = (struct cam_periph *)callback_arg;
277 case AC_FOUND_DEVICE:
280 struct ccb_getdev *cgd;
283 cgd = (struct ccb_getdev *)arg;
288 inq_len = cgd->inq_data.additional_length + 4;
291 * PROBLEM: WE NEED TO LOOK AT BYTES 48-53 TO SEE IF THIS IS
292 * PROBLEM: IS A SAF-TE DEVICE.
294 switch (ses_type(&cgd->inq_data, inq_len)) {
297 case SES_SES_PASSTHROUGH:
305 status = cam_periph_alloc(sesregister, sesoninvalidate,
306 sescleanup, sesstart, "ses", CAM_PERIPH_BIO,
307 cgd->ccb_h.path, sesasync, AC_FOUND_DEVICE, cgd);
309 if (status != CAM_REQ_CMP && status != CAM_REQ_INPROG) {
310 kprintf("sesasync: Unable to probe new device due to "
311 "status 0x%x\n", status);
316 cam_periph_async(periph, code, path, arg);
322 sesregister(struct cam_periph *periph, void *arg)
324 struct ses_softc *softc;
325 struct ccb_setasync csa;
326 struct ccb_getdev *cgd;
329 cgd = (struct ccb_getdev *)arg;
330 if (periph == NULL) {
331 kprintf("sesregister: periph was NULL!!\n");
332 return (CAM_REQ_CMP_ERR);
336 kprintf("sesregister: no getdev CCB, can't register device\n");
337 return (CAM_REQ_CMP_ERR);
340 softc = kmalloc(sizeof (struct ses_softc), M_SCSISES, M_INTWAIT | M_ZERO);
341 periph->softc = softc;
342 softc->periph = periph;
344 softc->ses_type = ses_type(&cgd->inq_data, sizeof (cgd->inq_data));
346 switch (softc->ses_type) {
349 case SES_SES_PASSTHROUGH:
350 softc->ses_vec.softc_init = ses_softc_init;
351 softc->ses_vec.init_enc = ses_init_enc;
352 softc->ses_vec.get_encstat = ses_get_encstat;
353 softc->ses_vec.set_encstat = ses_set_encstat;
354 softc->ses_vec.get_objstat = ses_get_objstat;
355 softc->ses_vec.set_objstat = ses_set_objstat;
358 softc->ses_vec.softc_init = safte_softc_init;
359 softc->ses_vec.init_enc = safte_init_enc;
360 softc->ses_vec.get_encstat = safte_get_encstat;
361 softc->ses_vec.set_encstat = safte_set_encstat;
362 softc->ses_vec.get_objstat = safte_get_objstat;
363 softc->ses_vec.set_objstat = safte_set_objstat;
369 kfree(softc, M_SCSISES);
370 return (CAM_REQ_CMP_ERR);
373 cam_extend_set(sesperiphs, periph->unit_number, periph);
375 dev_ops_add(&ses_ops, -1, periph->unit_number);
376 make_dev(&ses_ops, periph->unit_number,
377 UID_ROOT, GID_OPERATOR, 0600, "%s%d",
378 periph->periph_name, periph->unit_number);
381 * Add an async callback so that we get
382 * notified if this device goes away.
384 xpt_setup_ccb(&csa.ccb_h, periph->path, 5);
385 csa.ccb_h.func_code = XPT_SASYNC_CB;
386 csa.event_enable = AC_LOST_DEVICE;
387 csa.callback = sesasync;
388 csa.callback_arg = periph;
389 xpt_action((union ccb *)&csa);
391 switch (softc->ses_type) {
394 tname = "No SES device";
397 tname = "SCSI-2 SES Device";
400 tname = "SCSI-3 SES Device";
402 case SES_SES_PASSTHROUGH:
403 tname = "SES Passthrough Device";
406 tname = "UNISYS SEN Device (NOT HANDLED YET)";
409 tname = "SAF-TE Compliant Device";
412 xpt_announce_periph(periph, tname);
413 return (CAM_REQ_CMP);
417 sesopen(struct dev_open_args *ap)
419 cdev_t dev = ap->a_head.a_dev;
420 struct cam_periph *periph;
421 struct ses_softc *softc;
425 periph = cam_extend_get(sesperiphs, SESUNIT(dev));
426 if (periph == NULL) {
430 if ((error = cam_periph_lock(periph, PCATCH)) != 0) {
436 if (cam_periph_acquire(periph) != CAM_REQ_CMP) {
437 cam_periph_unlock(periph);
441 softc = (struct ses_softc *)periph->softc;
443 if (softc->ses_flags & SES_FLAG_INVALID) {
447 if (softc->ses_flags & SES_FLAG_OPEN) {
451 if (softc->ses_vec.softc_init == NULL) {
456 softc->ses_flags |= SES_FLAG_OPEN;
457 if ((softc->ses_flags & SES_FLAG_INITIALIZED) == 0) {
458 error = (*softc->ses_vec.softc_init)(softc, 1);
460 softc->ses_flags &= ~SES_FLAG_OPEN;
462 softc->ses_flags |= SES_FLAG_INITIALIZED;
467 cam_periph_release(periph);
469 cam_periph_unlock(periph);
474 sesclose(struct dev_close_args *ap)
476 cdev_t dev = ap->a_head.a_dev;
477 struct cam_periph *periph;
478 struct ses_softc *softc;
484 periph = cam_extend_get(sesperiphs, unit);
488 softc = (struct ses_softc *)periph->softc;
490 if ((error = cam_periph_lock(periph, 0)) != 0)
493 softc->ses_flags &= ~SES_FLAG_OPEN;
495 cam_periph_unlock(periph);
496 cam_periph_release(periph);
502 sesstart(struct cam_periph *p, union ccb *sccb)
505 if (p->immediate_priority <= p->pinfo.priority) {
506 SLIST_INSERT_HEAD(&p->ccb_list, &sccb->ccb_h, periph_links.sle);
507 p->immediate_priority = CAM_PRIORITY_NONE;
508 wakeup(&p->ccb_list);
514 sesdone(struct cam_periph *periph, union ccb *dccb)
516 wakeup(&dccb->ccb_h.cbfcnp);
520 seserror(union ccb *ccb, u_int32_t cflags, u_int32_t sflags)
522 struct ses_softc *softc;
523 struct cam_periph *periph;
525 periph = xpt_path_periph(ccb->ccb_h.path);
526 softc = (struct ses_softc *)periph->softc;
528 return (cam_periph_error(ccb, cflags, sflags, &softc->ses_saved_ccb));
532 sesioctl(struct dev_ioctl_args *ap)
534 cdev_t dev = ap->a_head.a_dev;
535 struct cam_periph *periph;
538 ses_object obj, *uobj;
539 struct ses_softc *ssc;
545 addr = *((caddr_t *)ap->a_data);
549 periph = cam_extend_get(sesperiphs, SESUNIT(dev));
553 CAM_DEBUG(periph->path, CAM_DEBUG_TRACE, ("entering sesioctl\n"));
555 ssc = (struct ses_softc *)periph->softc;
558 * Now check to see whether we're initialized or not.
560 if ((ssc->ses_flags & SES_FLAG_INITIALIZED) == 0) {
566 CAM_DEBUG(periph->path, CAM_DEBUG_TRACE,
567 ("trying to do ioctl %#lx\n", ap->a_cmd));
570 * If this command can change the device's state,
571 * we must have the device open for writing.
575 case SESIOC_GETOBJMAP:
576 case SESIOC_GETENCSTAT:
577 case SESIOC_GETOBJSTAT:
580 if ((ap->a_fflag & FWRITE) == 0) {
587 error = copyout(&ssc->ses_nobjects, addr,
588 sizeof (ssc->ses_nobjects));
591 case SESIOC_GETOBJMAP:
592 for (uobj = addr, i = 0; i != ssc->ses_nobjects; i++, uobj++) {
594 obj.subencid = ssc->ses_objmap[i].subenclosure;
595 obj.object_type = ssc->ses_objmap[i].enctype;
596 error = copyout(&obj, uobj, sizeof (ses_object));
603 case SESIOC_GETENCSTAT:
604 error = (*ssc->ses_vec.get_encstat)(ssc, 1);
607 tmp = ssc->ses_encstat & ~ENCI_SVALID;
608 error = copyout(&tmp, addr, sizeof (ses_encstat));
609 ssc->ses_encstat = tmp;
612 case SESIOC_SETENCSTAT:
613 error = copyin(addr, &tmp, sizeof (ses_encstat));
616 error = (*ssc->ses_vec.set_encstat)(ssc, tmp, 1);
619 case SESIOC_GETOBJSTAT:
620 error = copyin(addr, &objs, sizeof (ses_objstat));
623 if (objs.obj_id >= ssc->ses_nobjects) {
627 error = (*ssc->ses_vec.get_objstat)(ssc, &objs, 1);
630 error = copyout(&objs, addr, sizeof (ses_objstat));
632 * Always (for now) invalidate entry.
634 ssc->ses_objmap[objs.obj_id].svalid = 0;
637 case SESIOC_SETOBJSTAT:
638 error = copyin(addr, &objs, sizeof (ses_objstat));
642 if (objs.obj_id >= ssc->ses_nobjects) {
646 error = (*ssc->ses_vec.set_objstat)(ssc, &objs, 1);
649 * Always (for now) invalidate entry.
651 ssc->ses_objmap[objs.obj_id].svalid = 0;
656 error = (*ssc->ses_vec.init_enc)(ssc);
660 error = cam_periph_ioctl(periph, ap->a_cmd, ap->a_data, seserror);
666 #define SES_CFLAGS CAM_RETRY_SELTO
667 #define SES_FLAGS SF_NO_PRINT | SF_RETRY_UA
669 ses_runcmd(struct ses_softc *ssc, char *cdb, int cdbl, char *dptr, int *dlenp)
676 if ((dlen = *dlenp) < 0) {
687 if (cdbl > IOCDBLEN) {
691 ccb = cam_periph_getccb(ssc->periph, 1);
692 cam_fill_csio(&ccb->csio, 0, sesdone, ddf, MSG_SIMPLE_Q_TAG, dptr,
693 dlen, sizeof (struct scsi_sense_data), cdbl, 60 * 1000);
694 bcopy(cdb, ccb->csio.cdb_io.cdb_bytes, cdbl);
696 error = cam_periph_runccb(ccb, seserror, SES_CFLAGS, SES_FLAGS, NULL);
697 if ((ccb->ccb_h.status & CAM_DEV_QFRZN) != 0)
698 cam_release_devq(ccb->ccb_h.path, 0, 0, 0, FALSE);
705 *dlenp = ccb->csio.resid;
708 xpt_release_ccb(ccb);
713 ses_log(struct ses_softc *ssc, const char *fmt, ...)
717 kprintf("%s%d: ", ssc->periph->periph_name, ssc->periph->unit_number);
724 * The code after this point runs on many platforms,
725 * so forgive the slightly awkward and nonconforming
730 * Is this a device that supports enclosure services?
732 * It's a a pretty simple ruleset- if it is device type 0x0D (13), it's
733 * an SES device. If it happens to be an old UNISYS SEN device, we can
737 #define SAFTE_START 44
739 #define SAFTE_LEN SAFTE_END-SAFTE_START
742 ses_type(void *buf, int buflen)
744 unsigned char *iqd = buf;
746 if (buflen < 8+SEN_ID_LEN)
749 if ((iqd[0] & 0x1f) == T_ENCLOSURE) {
750 if (STRNCMP(&iqd[8], SEN_ID, SEN_ID_LEN) == 0) {
752 } else if ((iqd[2] & 0x7) > 2) {
755 return (SES_SES_SCSI2);
760 #ifdef SES_ENABLE_PASSTHROUGH
761 if ((iqd[6] & 0x40) && (iqd[2] & 0x7) >= 2) {
763 * PassThrough Device.
765 return (SES_SES_PASSTHROUGH);
770 * The comparison is short for a reason-
771 * some vendors were chopping it short.
774 if (buflen < SAFTE_END - 2) {
778 if (STRNCMP((char *)&iqd[SAFTE_START], "SAF-TE", SAFTE_LEN - 2) == 0) {
785 * SES Native Type Device Support
789 * SES Diagnostic Page Codes
795 #define SesStatusPage SesControlPage
798 #define SesStringIn SesStringOut
800 #define SesThresholdIn SesThresholdOut
802 #define SesArrayStatus SesArrayControl
803 SesElementDescriptor,
812 * Minimum amount of data, starting from byte 0, to have
815 #define SES_CFGHDR_MINLEN 12
818 * Minimum amount of data, starting from byte 0, to have
819 * the config header and one enclosure header.
821 #define SES_ENCHDR_MINLEN 48
824 * Take this value, subtract it from VEnclen and you know
825 * the length of the vendor unique bytes.
827 #define SES_ENCHDR_VMIN 36
830 * SES Data Structures
834 uint32_t GenCode; /* Generation Code */
835 uint8_t Nsubenc; /* Number of Subenclosures */
839 uint8_t Subencid; /* SubEnclosure Identifier */
840 uint8_t Ntypes; /* # of supported types */
841 uint8_t VEnclen; /* Enclosure Descriptor Length */
845 uint8_t encWWN[8]; /* XXX- Not Right Yet */
853 uint8_t enc_type; /* type of element */
854 uint8_t enc_maxelt; /* maximum supported */
855 uint8_t enc_subenc; /* in SubEnc # N */
856 uint8_t enc_tlen; /* Type Descriptor Text Length */
870 uint8_t ses_ntypes; /* total number of types supported */
873 * We need to keep a type index as well as an
874 * object index for each object in an enclosure.
876 struct typidx *ses_typidx;
879 * We also need to keep track of the number of elements
880 * per type of element. This is needed later so that we
881 * can find precisely in the returned status data the
882 * status for the Nth element of the Kth type.
884 uint8_t * ses_eltmap;
889 * (de)canonicalization defines
891 #define sbyte(x, byte) ((((uint32_t)(x)) >> (byte * 8)) & 0xff)
892 #define sbit(x, bit) (((uint32_t)(x)) << bit)
893 #define sset8(outp, idx, sval) (((uint8_t *)(outp))[idx++]) = sbyte(sval, 0)
895 #define sset16(outp, idx, sval) \
896 (((uint8_t *)(outp))[idx++]) = sbyte(sval, 1), \
897 (((uint8_t *)(outp))[idx++]) = sbyte(sval, 0)
900 #define sset24(outp, idx, sval) \
901 (((uint8_t *)(outp))[idx++]) = sbyte(sval, 2), \
902 (((uint8_t *)(outp))[idx++]) = sbyte(sval, 1), \
903 (((uint8_t *)(outp))[idx++]) = sbyte(sval, 0)
906 #define sset32(outp, idx, sval) \
907 (((uint8_t *)(outp))[idx++]) = sbyte(sval, 3), \
908 (((uint8_t *)(outp))[idx++]) = sbyte(sval, 2), \
909 (((uint8_t *)(outp))[idx++]) = sbyte(sval, 1), \
910 (((uint8_t *)(outp))[idx++]) = sbyte(sval, 0)
912 #define gbyte(x, byte) ((((uint32_t)(x)) & 0xff) << (byte * 8))
913 #define gbit(lv, in, idx, shft, mask) lv = ((in[idx] >> shft) & mask)
914 #define sget8(inp, idx, lval) lval = (((uint8_t *)(inp))[idx++])
915 #define gget8(inp, idx, lval) lval = (((uint8_t *)(inp))[idx])
917 #define sget16(inp, idx, lval) \
918 lval = gbyte((((uint8_t *)(inp))[idx]), 1) | \
919 (((uint8_t *)(inp))[idx+1]), idx += 2
921 #define gget16(inp, idx, lval) \
922 lval = gbyte((((uint8_t *)(inp))[idx]), 1) | \
923 (((uint8_t *)(inp))[idx+1])
925 #define sget24(inp, idx, lval) \
926 lval = gbyte((((uint8_t *)(inp))[idx]), 2) | \
927 gbyte((((uint8_t *)(inp))[idx+1]), 1) | \
928 (((uint8_t *)(inp))[idx+2]), idx += 3
930 #define gget24(inp, idx, lval) \
931 lval = gbyte((((uint8_t *)(inp))[idx]), 2) | \
932 gbyte((((uint8_t *)(inp))[idx+1]), 1) | \
933 (((uint8_t *)(inp))[idx+2])
935 #define sget32(inp, idx, lval) \
936 lval = gbyte((((uint8_t *)(inp))[idx]), 3) | \
937 gbyte((((uint8_t *)(inp))[idx+1]), 2) | \
938 gbyte((((uint8_t *)(inp))[idx+2]), 1) | \
939 (((uint8_t *)(inp))[idx+3]), idx += 4
941 #define gget32(inp, idx, lval) \
942 lval = gbyte((((uint8_t *)(inp))[idx]), 3) | \
943 gbyte((((uint8_t *)(inp))[idx+1]), 2) | \
944 gbyte((((uint8_t *)(inp))[idx+2]), 1) | \
945 (((uint8_t *)(inp))[idx+3])
948 #define CFLEN (256 + SES_ENCHDR_MINLEN)
951 * Routines specific && private to SES only
954 static int ses_getconfig(ses_softc_t *);
955 static int ses_getputstat(ses_softc_t *, int, SesComStat *, int, int);
956 static int ses_cfghdr(uint8_t *, int, SesCfgHdr *);
957 static int ses_enchdr(uint8_t *, int, uint8_t, SesEncHdr *);
958 static int ses_encdesc(uint8_t *, int, uint8_t, SesEncDesc *);
959 static int ses_getthdr(uint8_t *, int, int, SesThdr *);
960 static int ses_decode(char *, int, uint8_t *, int, int, SesComStat *);
961 static int ses_encode(char *, int, uint8_t *, int, int, SesComStat *);
964 ses_softc_init(ses_softc_t *ssc, int doinit)
968 if (ssc->ses_nobjects) {
969 SES_FREE(ssc->ses_objmap,
970 ssc->ses_nobjects * sizeof (encobj));
971 ssc->ses_objmap = NULL;
973 if ((cc = ssc->ses_private) != NULL) {
974 if (cc->ses_eltmap && cc->ses_ntypes) {
975 SES_FREE(cc->ses_eltmap, cc->ses_ntypes);
976 cc->ses_eltmap = NULL;
979 if (cc->ses_typidx && ssc->ses_nobjects) {
980 SES_FREE(cc->ses_typidx,
981 ssc->ses_nobjects * sizeof (struct typidx));
982 cc->ses_typidx = NULL;
984 SES_FREE(cc, sizeof (struct sscfg));
985 ssc->ses_private = NULL;
987 ssc->ses_nobjects = 0;
990 if (ssc->ses_private == NULL) {
991 ssc->ses_private = SES_MALLOC(sizeof (struct sscfg));
993 if (ssc->ses_private == NULL) {
996 ssc->ses_nobjects = 0;
997 ssc->ses_encstat = 0;
998 return (ses_getconfig(ssc));
1002 ses_init_enc(ses_softc_t *ssc)
1008 ses_get_encstat(ses_softc_t *ssc, int slpflag)
1013 if ((status = ses_getputstat(ssc, -1, &ComStat, slpflag, 1)) != 0) {
1016 ssc->ses_encstat = ComStat.comstatus | ENCI_SVALID;
1021 ses_set_encstat(ses_softc_t *ssc, uint8_t encstat, int slpflag)
1026 ComStat.comstatus = encstat & 0xf;
1027 if ((status = ses_getputstat(ssc, -1, &ComStat, slpflag, 0)) != 0) {
1030 ssc->ses_encstat = encstat & 0xf; /* note no SVALID set */
1035 ses_get_objstat(ses_softc_t *ssc, ses_objstat *obp, int slpflag)
1037 int i = (int)obp->obj_id;
1039 if (ssc->ses_objmap[i].svalid == 0) {
1041 int err = ses_getputstat(ssc, i, &ComStat, slpflag, 1);
1044 ssc->ses_objmap[i].encstat[0] = ComStat.comstatus;
1045 ssc->ses_objmap[i].encstat[1] = ComStat.comstat[0];
1046 ssc->ses_objmap[i].encstat[2] = ComStat.comstat[1];
1047 ssc->ses_objmap[i].encstat[3] = ComStat.comstat[2];
1048 ssc->ses_objmap[i].svalid = 1;
1050 obp->cstat[0] = ssc->ses_objmap[i].encstat[0];
1051 obp->cstat[1] = ssc->ses_objmap[i].encstat[1];
1052 obp->cstat[2] = ssc->ses_objmap[i].encstat[2];
1053 obp->cstat[3] = ssc->ses_objmap[i].encstat[3];
1058 ses_set_objstat(ses_softc_t *ssc, ses_objstat *obp, int slpflag)
1063 * If this is clear, we don't do diddly.
1065 if ((obp->cstat[0] & SESCTL_CSEL) == 0) {
1068 ComStat.comstatus = obp->cstat[0];
1069 ComStat.comstat[0] = obp->cstat[1];
1070 ComStat.comstat[1] = obp->cstat[2];
1071 ComStat.comstat[2] = obp->cstat[3];
1072 err = ses_getputstat(ssc, (int)obp->obj_id, &ComStat, slpflag, 0);
1073 ssc->ses_objmap[(int)obp->obj_id].svalid = 0;
1078 ses_getconfig(ses_softc_t *ssc)
1085 int err, amt, i, nobj, ntype, maxima;
1086 char storage[CFLEN], *sdata;
1087 static char cdb[6] = {
1088 RECEIVE_DIAGNOSTIC, 0x1, SesConfigPage, SCSZ >> 8, SCSZ & 0xff, 0
1091 cc = ssc->ses_private;
1096 sdata = SES_MALLOC(SCSZ);
1101 err = ses_runcmd(ssc, cdb, 6, sdata, &amt);
1103 SES_FREE(sdata, SCSZ);
1108 if (ses_cfghdr((uint8_t *) sdata, amt, &cf)) {
1109 SES_LOG(ssc, "Unable to parse SES Config Header\n");
1110 SES_FREE(sdata, SCSZ);
1113 if (amt < SES_ENCHDR_MINLEN) {
1114 SES_LOG(ssc, "runt enclosure length (%d)\n", amt);
1115 SES_FREE(sdata, SCSZ);
1119 SES_VLOG(ssc, "GenCode %x %d Subenclosures\n", cf.GenCode, cf.Nsubenc);
1122 * Now waltz through all the subenclosures toting up the
1123 * number of types available in each. For this, we only
1124 * really need the enclosure header. However, we get the
1125 * enclosure descriptor for debug purposes, as well
1126 * as self-consistency checking purposes.
1129 maxima = cf.Nsubenc + 1;
1130 cdp = (SesEncDesc *) storage;
1131 for (ntype = i = 0; i < maxima; i++) {
1132 MEMZERO((caddr_t)cdp, sizeof (*cdp));
1133 if (ses_enchdr((uint8_t *) sdata, amt, i, &hd)) {
1134 SES_LOG(ssc, "Cannot Extract Enclosure Header %d\n", i);
1135 SES_FREE(sdata, SCSZ);
1138 SES_VLOG(ssc, " SubEnclosure ID %d, %d Types With this ID, En"
1139 "closure Length %d\n", hd.Subencid, hd.Ntypes, hd.VEnclen);
1141 if (ses_encdesc((uint8_t *)sdata, amt, i, cdp)) {
1142 SES_LOG(ssc, "Can't get Enclosure Descriptor %d\n", i);
1143 SES_FREE(sdata, SCSZ);
1146 SES_VLOG(ssc, " WWN: %02x%02x%02x%02x%02x%02x%02x%02x\n",
1147 cdp->encWWN[0], cdp->encWWN[1], cdp->encWWN[2],
1148 cdp->encWWN[3], cdp->encWWN[4], cdp->encWWN[5],
1149 cdp->encWWN[6], cdp->encWWN[7]);
1154 * Now waltz through all the types that are available, getting
1155 * the type header so we can start adding up the number of
1156 * objects available.
1158 for (nobj = i = 0; i < ntype; i++) {
1159 if (ses_getthdr((uint8_t *)sdata, amt, i, &thdr)) {
1160 SES_LOG(ssc, "Can't get Enclosure Type Header %d\n", i);
1161 SES_FREE(sdata, SCSZ);
1164 SES_LOG(ssc, " Type Desc[%d]: Type 0x%x, MaxElt %d, In Subenc "
1165 "%d, Text Length %d\n", i, thdr.enc_type, thdr.enc_maxelt,
1166 thdr.enc_subenc, thdr.enc_tlen);
1167 nobj += thdr.enc_maxelt;
1172 * Now allocate the object array and type map.
1175 ssc->ses_objmap = SES_MALLOC(nobj * sizeof (encobj));
1176 cc->ses_typidx = SES_MALLOC(nobj * sizeof (struct typidx));
1177 cc->ses_eltmap = SES_MALLOC(ntype);
1179 if (ssc->ses_objmap == NULL || cc->ses_typidx == NULL ||
1180 cc->ses_eltmap == NULL) {
1181 if (ssc->ses_objmap) {
1182 SES_FREE(ssc->ses_objmap, (nobj * sizeof (encobj)));
1183 ssc->ses_objmap = NULL;
1185 if (cc->ses_typidx) {
1186 SES_FREE(cc->ses_typidx,
1187 (nobj * sizeof (struct typidx)));
1188 cc->ses_typidx = NULL;
1190 if (cc->ses_eltmap) {
1191 SES_FREE(cc->ses_eltmap, ntype);
1192 cc->ses_eltmap = NULL;
1194 SES_FREE(sdata, SCSZ);
1197 MEMZERO(ssc->ses_objmap, nobj * sizeof (encobj));
1198 MEMZERO(cc->ses_typidx, nobj * sizeof (struct typidx));
1199 MEMZERO(cc->ses_eltmap, ntype);
1200 cc->ses_ntypes = (uint8_t) ntype;
1201 ssc->ses_nobjects = nobj;
1204 * Now waltz through the # of types again to fill in the types
1205 * (and subenclosure ids) of the allocated objects.
1208 for (i = 0; i < ntype; i++) {
1210 if (ses_getthdr((uint8_t *)sdata, amt, i, &thdr)) {
1213 cc->ses_eltmap[i] = thdr.enc_maxelt;
1214 for (j = 0; j < thdr.enc_maxelt; j++) {
1215 cc->ses_typidx[nobj].ses_tidx = i;
1216 cc->ses_typidx[nobj].ses_oidx = j;
1217 ssc->ses_objmap[nobj].subenclosure = thdr.enc_subenc;
1218 ssc->ses_objmap[nobj++].enctype = thdr.enc_type;
1221 SES_FREE(sdata, SCSZ);
1226 ses_getputstat(ses_softc_t *ssc, int objid, SesComStat *sp, int slp, int in)
1229 int err, amt, bufsiz, tidx, oidx;
1230 char cdb[6], *sdata;
1232 cc = ssc->ses_private;
1238 * If we're just getting overall enclosure status,
1239 * we only need 2 bytes of data storage.
1241 * If we're getting anything else, we know how much
1242 * storage we need by noting that starting at offset
1243 * 8 in returned data, all object status bytes are 4
1244 * bytes long, and are stored in chunks of types(M)
1245 * and nth+1 instances of type M.
1250 bufsiz = (ssc->ses_nobjects * 4) + (cc->ses_ntypes * 4) + 8;
1252 sdata = SES_MALLOC(bufsiz);
1256 cdb[0] = RECEIVE_DIAGNOSTIC;
1258 cdb[2] = SesStatusPage;
1259 cdb[3] = bufsiz >> 8;
1260 cdb[4] = bufsiz & 0xff;
1263 err = ses_runcmd(ssc, cdb, 6, sdata, &amt);
1265 SES_FREE(sdata, bufsiz);
1274 tidx = cc->ses_typidx[objid].ses_tidx;
1275 oidx = cc->ses_typidx[objid].ses_oidx;
1278 if (ses_decode(sdata, amt, cc->ses_eltmap, tidx, oidx, sp)) {
1282 if (ses_encode(sdata, amt, cc->ses_eltmap, tidx, oidx, sp)) {
1285 cdb[0] = SEND_DIAGNOSTIC;
1288 cdb[3] = bufsiz >> 8;
1289 cdb[4] = bufsiz & 0xff;
1292 err = ses_runcmd(ssc, cdb, 6, sdata, &amt);
1295 SES_FREE(sdata, bufsiz);
1301 * Routines to parse returned SES data structures.
1302 * Architecture and compiler independent.
1306 ses_cfghdr(uint8_t *buffer, int buflen, SesCfgHdr *cfp)
1308 if (buflen < SES_CFGHDR_MINLEN) {
1311 gget8(buffer, 1, cfp->Nsubenc);
1312 gget32(buffer, 4, cfp->GenCode);
1317 ses_enchdr(uint8_t *buffer, int amt, uint8_t SubEncId, SesEncHdr *chp)
1320 for (s = 0; s < SubEncId; s++) {
1323 off += buffer[off+3] + 4;
1325 if (off + 3 > amt) {
1328 gget8(buffer, off+1, chp->Subencid);
1329 gget8(buffer, off+2, chp->Ntypes);
1330 gget8(buffer, off+3, chp->VEnclen);
1335 ses_encdesc(uint8_t *buffer, int amt, uint8_t SubEncId, SesEncDesc *cdp)
1337 int s, e, enclen, off = 8;
1338 for (s = 0; s < SubEncId; s++) {
1341 off += buffer[off+3] + 4;
1343 if (off + 3 > amt) {
1346 gget8(buffer, off+3, enclen);
1355 MEMCPY(cdp, &buffer[off], e - off);
1360 ses_getthdr(uint8_t *buffer, int amt, int nth, SesThdr *thp)
1364 if (amt < SES_CFGHDR_MINLEN) {
1367 for (s = 0; s < buffer[1]; s++) {
1370 off += buffer[off+3] + 4;
1372 if (off + 3 > amt) {
1375 off += buffer[off+3] + 4 + (nth * 4);
1376 if (amt < (off + 4))
1379 gget8(buffer, off++, thp->enc_type);
1380 gget8(buffer, off++, thp->enc_maxelt);
1381 gget8(buffer, off++, thp->enc_subenc);
1382 gget8(buffer, off, thp->enc_tlen);
1387 * This function needs a little explanation.
1389 * The arguments are:
1394 * These describes the raw input SES status data and length.
1398 * This is a map of the number of types for each element type
1403 * This is the element type being sought. If elt is -1,
1404 * then overall enclosure status is being sought.
1408 * This is the ordinal Mth element of type elt being sought.
1412 * This is the output area to store the status for
1413 * the Mth element of type Elt.
1417 ses_decode(char *b, int amt, uint8_t *ep, int elt, int elm, SesComStat *sp)
1422 * If it's overall enclosure status being sought, get that.
1423 * We need at least 2 bytes of status data to get that.
1428 gget8(b, 1, sp->comstatus);
1436 * Check to make sure that the Mth element is legal for type Elt.
1443 * Starting at offset 8, start skipping over the storage
1444 * for the element types we're not interested in.
1446 for (idx = 8, i = 0; i < elt; i++) {
1447 idx += ((ep[i] + 1) * 4);
1451 * Skip over Overall status for this element type.
1456 * And skip to the index for the Mth element that we're going for.
1461 * Make sure we haven't overflowed the buffer.
1467 * Retrieve the status.
1469 gget8(b, idx++, sp->comstatus);
1470 gget8(b, idx++, sp->comstat[0]);
1471 gget8(b, idx++, sp->comstat[1]);
1472 gget8(b, idx++, sp->comstat[2]);
1474 PRINTF("Get Elt 0x%x Elm 0x%x (idx %d)\n", elt, elm, idx-4);
1480 * This is the mirror function to ses_decode, but we set the 'select'
1481 * bit for the object which we're interested in. All other objects,
1482 * after a status fetch, should have that bit off. Hmm. It'd be easy
1483 * enough to ensure this, so we will.
1487 ses_encode(char *b, int amt, uint8_t *ep, int elt, int elm, SesComStat *sp)
1492 * If it's overall enclosure status being sought, get that.
1493 * We need at least 2 bytes of status data to get that.
1500 sset8(b, i, sp->comstatus & 0xf);
1502 PRINTF("set EncStat %x\n", sp->comstatus);
1508 * Check to make sure that the Mth element is legal for type Elt.
1515 * Starting at offset 8, start skipping over the storage
1516 * for the element types we're not interested in.
1518 for (idx = 8, i = 0; i < elt; i++) {
1519 idx += ((ep[i] + 1) * 4);
1523 * Skip over Overall status for this element type.
1528 * And skip to the index for the Mth element that we're going for.
1533 * Make sure we haven't overflowed the buffer.
1541 sset8(b, idx, sp->comstatus);
1542 sset8(b, idx, sp->comstat[0]);
1543 sset8(b, idx, sp->comstat[1]);
1544 sset8(b, idx, sp->comstat[2]);
1548 PRINTF("Set Elt 0x%x Elm 0x%x (idx %d) with %x %x %x %x\n",
1549 elt, elm, idx, sp->comstatus, sp->comstat[0],
1550 sp->comstat[1], sp->comstat[2]);
1554 * Now make sure all other 'Select' bits are off.
1556 for (i = 8; i < amt; i += 4) {
1561 * And make sure the INVOP bit is clear.
1569 * SAF-TE Type Device Emulation
1572 static int safte_getconfig(ses_softc_t *);
1573 static int safte_rdstat(ses_softc_t *, int);
1574 static int set_objstat_sel(ses_softc_t *, ses_objstat *, int);
1575 static int wrbuf16(ses_softc_t *, uint8_t, uint8_t, uint8_t, uint8_t, int);
1576 static void wrslot_stat(ses_softc_t *, int);
1577 static int perf_slotop(ses_softc_t *, uint8_t, uint8_t, int);
1579 #define ALL_ENC_STAT (SES_ENCSTAT_CRITICAL | SES_ENCSTAT_UNRECOV | \
1580 SES_ENCSTAT_NONCRITICAL | SES_ENCSTAT_INFO)
1582 * SAF-TE specific defines- Mandatory ones only...
1586 * READ BUFFER ('get' commands) IDs- placed in offset 2 of cdb
1588 #define SAFTE_RD_RDCFG 0x00 /* read enclosure configuration */
1589 #define SAFTE_RD_RDESTS 0x01 /* read enclosure status */
1590 #define SAFTE_RD_RDDSTS 0x04 /* read drive slot status */
1593 * WRITE BUFFER ('set' commands) IDs- placed in offset 0 of databuf
1595 #define SAFTE_WT_DSTAT 0x10 /* write device slot status */
1596 #define SAFTE_WT_SLTOP 0x12 /* perform slot operation */
1597 #define SAFTE_WT_FANSPD 0x13 /* set fan speed */
1598 #define SAFTE_WT_ACTPWS 0x14 /* turn on/off power supply */
1599 #define SAFTE_WT_GLOBAL 0x15 /* send global command */
1602 #define SAFT_SCRATCH 64
1603 #define NPSEUDO_THERM 16
1604 #define NPSEUDO_ALARM 1
1607 * Cached Configuration
1609 uint8_t Nfans; /* Number of Fans */
1610 uint8_t Npwr; /* Number of Power Supplies */
1611 uint8_t Nslots; /* Number of Device Slots */
1612 uint8_t DoorLock; /* Door Lock Installed */
1613 uint8_t Ntherm; /* Number of Temperature Sensors */
1614 uint8_t Nspkrs; /* Number of Speakers */
1615 uint8_t Nalarm; /* Number of Alarms (at least one) */
1617 * Cached Flag Bytes for Global Status
1622 * What object index ID is where various slots start.
1626 #define SAFT_ALARM_OFFSET(cc) (cc)->slotoff - 1
1629 #define SAFT_FLG1_ALARM 0x1
1630 #define SAFT_FLG1_GLOBFAIL 0x2
1631 #define SAFT_FLG1_GLOBWARN 0x4
1632 #define SAFT_FLG1_ENCPWROFF 0x8
1633 #define SAFT_FLG1_ENCFANFAIL 0x10
1634 #define SAFT_FLG1_ENCPWRFAIL 0x20
1635 #define SAFT_FLG1_ENCDRVFAIL 0x40
1636 #define SAFT_FLG1_ENCDRVWARN 0x80
1638 #define SAFT_FLG2_LOCKDOOR 0x4
1639 #define SAFT_PRIVATE sizeof (struct scfg)
1641 static char *safte_2little = "Too Little Data Returned (%d) at line %d\n";
1642 #define SAFT_BAIL(r, x, k, l) \
1644 SES_LOG(ssc, safte_2little, x, __LINE__);\
1645 SES_FREE((k), (l)); \
1651 safte_softc_init(ses_softc_t *ssc, int doinit)
1657 if (ssc->ses_nobjects) {
1658 if (ssc->ses_objmap) {
1659 SES_FREE(ssc->ses_objmap,
1660 ssc->ses_nobjects * sizeof (encobj));
1661 ssc->ses_objmap = NULL;
1663 ssc->ses_nobjects = 0;
1665 if (ssc->ses_private) {
1666 SES_FREE(ssc->ses_private, SAFT_PRIVATE);
1667 ssc->ses_private = NULL;
1672 if (ssc->ses_private == NULL) {
1673 ssc->ses_private = SES_MALLOC(SAFT_PRIVATE);
1674 if (ssc->ses_private == NULL) {
1677 MEMZERO(ssc->ses_private, SAFT_PRIVATE);
1680 ssc->ses_nobjects = 0;
1681 ssc->ses_encstat = 0;
1683 if ((err = safte_getconfig(ssc)) != 0) {
1688 * The number of objects here, as well as that reported by the
1689 * READ_BUFFER/GET_CONFIG call, are the over-temperature flags (15)
1690 * that get reported during READ_BUFFER/READ_ENC_STATUS.
1692 cc = ssc->ses_private;
1693 ssc->ses_nobjects = cc->Nfans + cc->Npwr + cc->Nslots + cc->DoorLock +
1694 cc->Ntherm + cc->Nspkrs + NPSEUDO_THERM + NPSEUDO_ALARM;
1695 ssc->ses_objmap = (encobj *)
1696 SES_MALLOC(ssc->ses_nobjects * sizeof (encobj));
1697 if (ssc->ses_objmap == NULL) {
1700 MEMZERO(ssc->ses_objmap, ssc->ses_nobjects * sizeof (encobj));
1704 * Note that this is all arranged for the convenience
1705 * in later fetches of status.
1707 for (i = 0; i < cc->Nfans; i++)
1708 ssc->ses_objmap[r++].enctype = SESTYP_FAN;
1709 cc->pwroff = (uint8_t) r;
1710 for (i = 0; i < cc->Npwr; i++)
1711 ssc->ses_objmap[r++].enctype = SESTYP_POWER;
1712 for (i = 0; i < cc->DoorLock; i++)
1713 ssc->ses_objmap[r++].enctype = SESTYP_DOORLOCK;
1714 for (i = 0; i < cc->Nspkrs; i++)
1715 ssc->ses_objmap[r++].enctype = SESTYP_ALARM;
1716 for (i = 0; i < cc->Ntherm; i++)
1717 ssc->ses_objmap[r++].enctype = SESTYP_THERM;
1718 for (i = 0; i < NPSEUDO_THERM; i++)
1719 ssc->ses_objmap[r++].enctype = SESTYP_THERM;
1720 ssc->ses_objmap[r++].enctype = SESTYP_ALARM;
1721 cc->slotoff = (uint8_t) r;
1722 for (i = 0; i < cc->Nslots; i++)
1723 ssc->ses_objmap[r++].enctype = SESTYP_DEVICE;
1728 safte_init_enc(ses_softc_t *ssc)
1731 static char cdb0[6] = { SEND_DIAGNOSTIC };
1733 err = ses_runcmd(ssc, cdb0, 6, NULL, 0);
1738 err = wrbuf16(ssc, SAFTE_WT_GLOBAL, 0, 0, 0, 1);
1743 safte_get_encstat(ses_softc_t *ssc, int slpflg)
1745 return (safte_rdstat(ssc, slpflg));
1749 safte_set_encstat(ses_softc_t *ssc, uint8_t encstat, int slpflg)
1751 struct scfg *cc = ssc->ses_private;
1755 * Since SAF-TE devices aren't necessarily sticky in terms
1756 * of state, make our soft copy of enclosure status 'sticky'-
1757 * that is, things set in enclosure status stay set (as implied
1758 * by conditions set in reading object status) until cleared.
1760 ssc->ses_encstat &= ~ALL_ENC_STAT;
1761 ssc->ses_encstat |= (encstat & ALL_ENC_STAT);
1762 ssc->ses_encstat |= ENCI_SVALID;
1763 cc->flag1 &= ~(SAFT_FLG1_ALARM|SAFT_FLG1_GLOBFAIL|SAFT_FLG1_GLOBWARN);
1764 if ((encstat & (SES_ENCSTAT_CRITICAL|SES_ENCSTAT_UNRECOV)) != 0) {
1765 cc->flag1 |= SAFT_FLG1_ALARM|SAFT_FLG1_GLOBFAIL;
1766 } else if ((encstat & SES_ENCSTAT_NONCRITICAL) != 0) {
1767 cc->flag1 |= SAFT_FLG1_GLOBWARN;
1769 return (wrbuf16(ssc, SAFTE_WT_GLOBAL, cc->flag1, cc->flag2, 0, slpflg));
1773 safte_get_objstat(ses_softc_t *ssc, ses_objstat *obp, int slpflg)
1775 int i = (int)obp->obj_id;
1777 if ((ssc->ses_encstat & ENCI_SVALID) == 0 ||
1778 (ssc->ses_objmap[i].svalid) == 0) {
1779 int err = safte_rdstat(ssc, slpflg);
1783 obp->cstat[0] = ssc->ses_objmap[i].encstat[0];
1784 obp->cstat[1] = ssc->ses_objmap[i].encstat[1];
1785 obp->cstat[2] = ssc->ses_objmap[i].encstat[2];
1786 obp->cstat[3] = ssc->ses_objmap[i].encstat[3];
1792 safte_set_objstat(ses_softc_t *ssc, ses_objstat *obp, int slp)
1799 SES_DLOG(ssc, "safte_set_objstat(%d): %x %x %x %x\n",
1800 (int)obp->obj_id, obp->cstat[0], obp->cstat[1], obp->cstat[2],
1804 * If this is clear, we don't do diddly.
1806 if ((obp->cstat[0] & SESCTL_CSEL) == 0) {
1812 * Check to see if the common bits are set and do them first.
1814 if (obp->cstat[0] & ~SESCTL_CSEL) {
1815 err = set_objstat_sel(ssc, obp, slp);
1820 cc = ssc->ses_private;
1824 idx = (int)obp->obj_id;
1825 ep = &ssc->ses_objmap[idx];
1827 switch (ep->enctype) {
1832 * XXX: I should probably cache the previous state
1833 * XXX: of SESCTL_DEVOFF so that when it goes from
1834 * XXX: true to false I can then set PREPARE FOR OPERATION
1835 * XXX: flag in PERFORM SLOT OPERATION write buffer command.
1837 if (obp->cstat[2] & (SESCTL_RQSINS|SESCTL_RQSRMV)) {
1840 if (obp->cstat[2] & SESCTL_RQSID) {
1843 err = perf_slotop(ssc, (uint8_t) idx - (uint8_t) cc->slotoff,
1847 if (obp->cstat[3] & SESCTL_RQSFLT) {
1852 if (ep->priv & 0xc6) {
1855 ep->priv |= 0x1; /* no errors */
1857 wrslot_stat(ssc, slp);
1861 if (obp->cstat[3] & SESCTL_RQSTFAIL) {
1862 cc->flag1 |= SAFT_FLG1_ENCPWRFAIL;
1864 cc->flag1 &= ~SAFT_FLG1_ENCPWRFAIL;
1866 err = wrbuf16(ssc, SAFTE_WT_GLOBAL, cc->flag1,
1870 if (obp->cstat[3] & SESCTL_RQSTON) {
1871 wrbuf16(ssc, SAFTE_WT_ACTPWS,
1872 idx - cc->pwroff, 0, 0, slp);
1874 wrbuf16(ssc, SAFTE_WT_ACTPWS,
1875 idx - cc->pwroff, 0, 1, slp);
1879 if (obp->cstat[3] & SESCTL_RQSTFAIL) {
1880 cc->flag1 |= SAFT_FLG1_ENCFANFAIL;
1882 cc->flag1 &= ~SAFT_FLG1_ENCFANFAIL;
1884 err = wrbuf16(ssc, SAFTE_WT_GLOBAL, cc->flag1,
1888 if (obp->cstat[3] & SESCTL_RQSTON) {
1890 if ((obp->cstat[3] & 0x7) == 7) {
1892 } else if ((obp->cstat[3] & 0x7) == 6) {
1894 } else if ((obp->cstat[3] & 0x7) == 4) {
1899 wrbuf16(ssc, SAFTE_WT_FANSPD, idx, fsp, 0, slp);
1901 wrbuf16(ssc, SAFTE_WT_FANSPD, idx, 0, 0, slp);
1904 case SESTYP_DOORLOCK:
1905 if (obp->cstat[3] & 0x1) {
1906 cc->flag2 &= ~SAFT_FLG2_LOCKDOOR;
1908 cc->flag2 |= SAFT_FLG2_LOCKDOOR;
1910 wrbuf16(ssc, SAFTE_WT_GLOBAL, cc->flag1, cc->flag2, 0, slp);
1914 * On all nonzero but the 'muted' bit, we turn on the alarm,
1916 obp->cstat[3] &= ~0xa;
1917 if (obp->cstat[3] & 0x40) {
1918 cc->flag2 &= ~SAFT_FLG1_ALARM;
1919 } else if (obp->cstat[3] != 0) {
1920 cc->flag2 |= SAFT_FLG1_ALARM;
1922 cc->flag2 &= ~SAFT_FLG1_ALARM;
1924 ep->priv = obp->cstat[3];
1925 wrbuf16(ssc, SAFTE_WT_GLOBAL, cc->flag1, cc->flag2, 0, slp);
1935 safte_getconfig(ses_softc_t *ssc)
1940 static char cdb[10] =
1941 { READ_BUFFER, 1, SAFTE_RD_RDCFG, 0, 0, 0, 0, 0, SAFT_SCRATCH, 0 };
1943 cfg = ssc->ses_private;
1947 sdata = SES_MALLOC(SAFT_SCRATCH);
1952 err = ses_runcmd(ssc, cdb, 10, sdata, &amt);
1954 SES_FREE(sdata, SAFT_SCRATCH);
1957 amt = SAFT_SCRATCH - amt;
1959 SES_LOG(ssc, "too little data (%d) for configuration\n", amt);
1960 SES_FREE(sdata, SAFT_SCRATCH);
1963 SES_VLOG(ssc, "Nfans %d Npwr %d Nslots %d Lck %d Ntherm %d Nspkrs %d\n",
1964 sdata[0], sdata[1], sdata[2], sdata[3], sdata[4], sdata[5]);
1965 cfg->Nfans = sdata[0];
1966 cfg->Npwr = sdata[1];
1967 cfg->Nslots = sdata[2];
1968 cfg->DoorLock = sdata[3];
1969 cfg->Ntherm = sdata[4];
1970 cfg->Nspkrs = sdata[5];
1971 cfg->Nalarm = NPSEUDO_ALARM;
1972 SES_FREE(sdata, SAFT_SCRATCH);
1977 safte_rdstat(ses_softc_t *ssc, int slpflg)
1979 int err, oid, r, i, hiwater, nitems, amt;
1982 uint8_t status, oencstat;
1983 char *sdata, cdb[10];
1984 struct scfg *cc = ssc->ses_private;
1988 * The number of objects overstates things a bit,
1989 * both for the bogus 'thermometer' entries and
1990 * the drive status (which isn't read at the same
1991 * time as the enclosure status), but that's okay.
1993 buflen = 4 * cc->Nslots;
1994 if (ssc->ses_nobjects > buflen)
1995 buflen = ssc->ses_nobjects;
1996 sdata = SES_MALLOC(buflen);
2000 cdb[0] = READ_BUFFER;
2002 cdb[2] = SAFTE_RD_RDESTS;
2007 cdb[7] = (buflen >> 8) & 0xff;
2008 cdb[8] = buflen & 0xff;
2011 err = ses_runcmd(ssc, cdb, 10, sdata, &amt);
2013 SES_FREE(sdata, buflen);
2016 hiwater = buflen - amt;
2020 * invalidate all status bits.
2022 for (i = 0; i < ssc->ses_nobjects; i++)
2023 ssc->ses_objmap[i].svalid = 0;
2024 oencstat = ssc->ses_encstat & ALL_ENC_STAT;
2025 ssc->ses_encstat = 0;
2029 * Now parse returned buffer.
2030 * If we didn't get enough data back,
2031 * that's considered a fatal error.
2035 for (nitems = i = 0; i < cc->Nfans; i++) {
2036 SAFT_BAIL(r, hiwater, sdata, buflen);
2038 * 0 = Fan Operational
2039 * 1 = Fan is malfunctioning
2040 * 2 = Fan is not present
2041 * 0x80 = Unknown or Not Reportable Status
2043 ssc->ses_objmap[oid].encstat[1] = 0; /* resvd */
2044 ssc->ses_objmap[oid].encstat[2] = 0; /* resvd */
2045 switch ((int)(uint8_t)sdata[r]) {
2048 ssc->ses_objmap[oid].encstat[0] = SES_OBJSTAT_OK;
2050 * We could get fancier and cache
2051 * fan speeds that we have set, but
2052 * that isn't done now.
2054 ssc->ses_objmap[oid].encstat[3] = 7;
2058 ssc->ses_objmap[oid].encstat[0] = SES_OBJSTAT_CRIT;
2060 * FAIL and FAN STOPPED synthesized
2062 ssc->ses_objmap[oid].encstat[3] = 0x40;
2064 * Enclosure marked with CRITICAL error
2065 * if only one fan or no thermometers,
2066 * else the NONCRITICAL error is set.
2068 if (cc->Nfans == 1 || cc->Ntherm == 0)
2069 ssc->ses_encstat |= SES_ENCSTAT_CRITICAL;
2071 ssc->ses_encstat |= SES_ENCSTAT_NONCRITICAL;
2074 ssc->ses_objmap[oid].encstat[0] =
2075 SES_OBJSTAT_NOTINSTALLED;
2076 ssc->ses_objmap[oid].encstat[3] = 0;
2078 * Enclosure marked with CRITICAL error
2079 * if only one fan or no thermometers,
2080 * else the NONCRITICAL error is set.
2083 ssc->ses_encstat |= SES_ENCSTAT_CRITICAL;
2085 ssc->ses_encstat |= SES_ENCSTAT_NONCRITICAL;
2088 ssc->ses_objmap[oid].encstat[0] = SES_OBJSTAT_UNKNOWN;
2089 ssc->ses_objmap[oid].encstat[3] = 0;
2090 ssc->ses_encstat |= SES_ENCSTAT_INFO;
2093 ssc->ses_objmap[oid].encstat[0] =
2094 SES_OBJSTAT_UNSUPPORTED;
2095 SES_LOG(ssc, "Unknown fan%d status 0x%x\n", i,
2099 ssc->ses_objmap[oid++].svalid = 1;
2104 * No matter how you cut it, no cooling elements when there
2105 * should be some there is critical.
2107 if (cc->Nfans && nitems == 0) {
2108 ssc->ses_encstat |= SES_ENCSTAT_CRITICAL;
2112 for (i = 0; i < cc->Npwr; i++) {
2113 SAFT_BAIL(r, hiwater, sdata, buflen);
2114 ssc->ses_objmap[oid].encstat[0] = SES_OBJSTAT_UNKNOWN;
2115 ssc->ses_objmap[oid].encstat[1] = 0; /* resvd */
2116 ssc->ses_objmap[oid].encstat[2] = 0; /* resvd */
2117 ssc->ses_objmap[oid].encstat[3] = 0x20; /* requested on */
2118 switch ((uint8_t)sdata[r]) {
2119 case 0x00: /* pws operational and on */
2120 ssc->ses_objmap[oid].encstat[0] = SES_OBJSTAT_OK;
2122 case 0x01: /* pws operational and off */
2123 ssc->ses_objmap[oid].encstat[0] = SES_OBJSTAT_OK;
2124 ssc->ses_objmap[oid].encstat[3] = 0x10;
2125 ssc->ses_encstat |= SES_ENCSTAT_INFO;
2127 case 0x10: /* pws is malfunctioning and commanded on */
2128 ssc->ses_objmap[oid].encstat[0] = SES_OBJSTAT_CRIT;
2129 ssc->ses_objmap[oid].encstat[3] = 0x61;
2130 ssc->ses_encstat |= SES_ENCSTAT_NONCRITICAL;
2133 case 0x11: /* pws is malfunctioning and commanded off */
2134 ssc->ses_objmap[oid].encstat[0] = SES_OBJSTAT_NONCRIT;
2135 ssc->ses_objmap[oid].encstat[3] = 0x51;
2136 ssc->ses_encstat |= SES_ENCSTAT_NONCRITICAL;
2138 case 0x20: /* pws is not present */
2139 ssc->ses_objmap[oid].encstat[0] =
2140 SES_OBJSTAT_NOTINSTALLED;
2141 ssc->ses_objmap[oid].encstat[3] = 0;
2142 ssc->ses_encstat |= SES_ENCSTAT_INFO;
2144 case 0x21: /* pws is present */
2146 * This is for enclosures that cannot tell whether the
2147 * device is on or malfunctioning, but know that it is
2148 * present. Just fall through.
2151 case 0x80: /* Unknown or Not Reportable Status */
2152 ssc->ses_objmap[oid].encstat[0] = SES_OBJSTAT_UNKNOWN;
2153 ssc->ses_objmap[oid].encstat[3] = 0;
2154 ssc->ses_encstat |= SES_ENCSTAT_INFO;
2157 SES_LOG(ssc, "unknown power supply %d status (0x%x)\n",
2158 i, sdata[r] & 0xff);
2161 ssc->ses_objmap[oid++].svalid = 1;
2166 * Skip over Slot SCSI IDs
2171 * We always have doorlock status, no matter what,
2172 * but we only save the status if we have one.
2174 SAFT_BAIL(r, hiwater, sdata, buflen);
2178 * 1 = Door Unlocked, or no Lock Installed
2179 * 0x80 = Unknown or Not Reportable Status
2181 ssc->ses_objmap[oid].encstat[1] = 0;
2182 ssc->ses_objmap[oid].encstat[2] = 0;
2183 switch ((uint8_t)sdata[r]) {
2185 ssc->ses_objmap[oid].encstat[0] = SES_OBJSTAT_OK;
2186 ssc->ses_objmap[oid].encstat[3] = 0;
2189 ssc->ses_objmap[oid].encstat[0] = SES_OBJSTAT_OK;
2190 ssc->ses_objmap[oid].encstat[3] = 1;
2193 ssc->ses_objmap[oid].encstat[0] = SES_OBJSTAT_UNKNOWN;
2194 ssc->ses_objmap[oid].encstat[3] = 0;
2195 ssc->ses_encstat |= SES_ENCSTAT_INFO;
2198 ssc->ses_objmap[oid].encstat[0] =
2199 SES_OBJSTAT_UNSUPPORTED;
2200 SES_LOG(ssc, "unknown lock status 0x%x\n",
2204 ssc->ses_objmap[oid++].svalid = 1;
2209 * We always have speaker status, no matter what,
2210 * but we only save the status if we have one.
2212 SAFT_BAIL(r, hiwater, sdata, buflen);
2214 ssc->ses_objmap[oid].encstat[1] = 0;
2215 ssc->ses_objmap[oid].encstat[2] = 0;
2216 if (sdata[r] == 1) {
2218 * We need to cache tone urgency indicators.
2221 ssc->ses_objmap[oid].encstat[0] = SES_OBJSTAT_NONCRIT;
2222 ssc->ses_objmap[oid].encstat[3] = 0x8;
2223 ssc->ses_encstat |= SES_ENCSTAT_NONCRITICAL;
2224 } else if (sdata[r] == 0) {
2225 ssc->ses_objmap[oid].encstat[0] = SES_OBJSTAT_OK;
2226 ssc->ses_objmap[oid].encstat[3] = 0;
2228 ssc->ses_objmap[oid].encstat[0] =
2229 SES_OBJSTAT_UNSUPPORTED;
2230 ssc->ses_objmap[oid].encstat[3] = 0;
2231 SES_LOG(ssc, "unknown spkr status 0x%x\n",
2234 ssc->ses_objmap[oid++].svalid = 1;
2238 for (i = 0; i < cc->Ntherm; i++) {
2239 SAFT_BAIL(r, hiwater, sdata, buflen);
2241 * Status is a range from -10 to 245 deg Celsius,
2242 * which we need to normalize to -20 to -245 according
2243 * to the latest SCSI spec, which makes little
2244 * sense since this would overflow an 8bit value.
2245 * Well, still, the base normalization is -20,
2246 * not -10, so we have to adjust.
2248 * So what's over and under temperature?
2249 * Hmm- we'll state that 'normal' operating
2250 * is 10 to 40 deg Celsius.
2254 * Actually.... All of the units that people out in the world
2255 * seem to have do not come even close to setting a value that
2256 * complies with this spec.
2258 * The closest explanation I could find was in an
2259 * LSI-Logic manual, which seemed to indicate that
2260 * this value would be set by whatever the I2C code
2261 * would interpolate from the output of an LM75
2262 * temperature sensor.
2264 * This means that it is impossible to use the actual
2265 * numeric value to predict anything. But we don't want
2266 * to lose the value. So, we'll propagate the *uncorrected*
2267 * value and set SES_OBJSTAT_NOTAVAIL. We'll depend on the
2268 * temperature flags for warnings.
2270 ssc->ses_objmap[oid].encstat[0] = SES_OBJSTAT_NOTAVAIL;
2271 ssc->ses_objmap[oid].encstat[1] = 0;
2272 ssc->ses_objmap[oid].encstat[2] = sdata[r];
2273 ssc->ses_objmap[oid].encstat[3] = 0;
2274 ssc->ses_objmap[oid++].svalid = 1;
2279 * Now, for "pseudo" thermometers, we have two bytes
2280 * of information in enclosure status- 16 bits. Actually,
2281 * the MSB is a single TEMP ALERT flag indicating whether
2282 * any other bits are set, but, thanks to fuzzy thinking,
2283 * in the SAF-TE spec, this can also be set even if no
2284 * other bits are set, thus making this really another
2285 * binary temperature sensor.
2288 SAFT_BAIL(r, hiwater, sdata, buflen);
2289 tempflags = sdata[r++];
2290 SAFT_BAIL(r, hiwater, sdata, buflen);
2291 tempflags |= (tempflags << 8) | sdata[r++];
2293 for (i = 0; i < NPSEUDO_THERM; i++) {
2294 ssc->ses_objmap[oid].encstat[1] = 0;
2295 if (tempflags & (1 << (NPSEUDO_THERM - i - 1))) {
2296 ssc->ses_objmap[oid].encstat[0] = SES_OBJSTAT_CRIT;
2297 ssc->ses_objmap[4].encstat[2] = 0xff;
2299 * Set 'over temperature' failure.
2301 ssc->ses_objmap[oid].encstat[3] = 8;
2302 ssc->ses_encstat |= SES_ENCSTAT_CRITICAL;
2305 * We used to say 'not available' and synthesize a
2306 * nominal 30 deg (C)- that was wrong. Actually,
2307 * Just say 'OK', and use the reserved value of
2310 ssc->ses_objmap[oid].encstat[0] = SES_OBJSTAT_OK;
2311 ssc->ses_objmap[oid].encstat[2] = 0;
2312 ssc->ses_objmap[oid].encstat[3] = 0;
2314 ssc->ses_objmap[oid++].svalid = 1;
2320 ssc->ses_objmap[oid].encstat[0] = SES_OBJSTAT_OK;
2321 ssc->ses_objmap[oid].encstat[3] = ssc->ses_objmap[oid].priv;
2322 ssc->ses_objmap[oid++].svalid = 1;
2325 * Now get drive slot status
2327 cdb[2] = SAFTE_RD_RDDSTS;
2329 err = ses_runcmd(ssc, cdb, 10, sdata, &amt);
2331 SES_FREE(sdata, buflen);
2334 hiwater = buflen - amt;
2335 for (r = i = 0; i < cc->Nslots; i++, r += 4) {
2336 SAFT_BAIL(r+3, hiwater, sdata, buflen);
2337 ssc->ses_objmap[oid].encstat[0] = SES_OBJSTAT_UNSUPPORTED;
2338 ssc->ses_objmap[oid].encstat[1] = (uint8_t) i;
2339 ssc->ses_objmap[oid].encstat[2] = 0;
2340 ssc->ses_objmap[oid].encstat[3] = 0;
2341 status = sdata[r+3];
2342 if ((status & 0x1) == 0) { /* no device */
2343 ssc->ses_objmap[oid].encstat[0] =
2344 SES_OBJSTAT_NOTINSTALLED;
2346 ssc->ses_objmap[oid].encstat[0] = SES_OBJSTAT_OK;
2349 ssc->ses_objmap[oid].encstat[2] = 0x8;
2351 if ((status & 0x4) == 0) {
2352 ssc->ses_objmap[oid].encstat[3] = 0x10;
2354 ssc->ses_objmap[oid++].svalid = 1;
2356 /* see comment below about sticky enclosure status */
2357 ssc->ses_encstat |= ENCI_SVALID | oencstat;
2358 SES_FREE(sdata, buflen);
2363 set_objstat_sel(ses_softc_t *ssc, ses_objstat *obp, int slp)
2367 struct scfg *cc = ssc->ses_private;
2372 idx = (int)obp->obj_id;
2373 ep = &ssc->ses_objmap[idx];
2375 switch (ep->enctype) {
2377 if (obp->cstat[0] & SESCTL_PRDFAIL) {
2380 /* SESCTL_RSTSWAP has no correspondence in SAF-TE */
2381 if (obp->cstat[0] & SESCTL_DISABLE) {
2384 * Hmm. Try to set the 'No Drive' flag.
2385 * Maybe that will count as a 'disable'.
2388 if (ep->priv & 0xc6) {
2391 ep->priv |= 0x1; /* no errors */
2393 wrslot_stat(ssc, slp);
2397 * Okay- the only one that makes sense here is to
2398 * do the 'disable' for a power supply.
2400 if (obp->cstat[0] & SESCTL_DISABLE) {
2401 wrbuf16(ssc, SAFTE_WT_ACTPWS,
2402 idx - cc->pwroff, 0, 0, slp);
2407 * Okay- the only one that makes sense here is to
2408 * set fan speed to zero on disable.
2410 if (obp->cstat[0] & SESCTL_DISABLE) {
2411 /* remember- fans are the first items, so idx works */
2412 wrbuf16(ssc, SAFTE_WT_FANSPD, idx, 0, 0, slp);
2415 case SESTYP_DOORLOCK:
2417 * Well, we can 'disable' the lock.
2419 if (obp->cstat[0] & SESCTL_DISABLE) {
2420 cc->flag2 &= ~SAFT_FLG2_LOCKDOOR;
2421 wrbuf16(ssc, SAFTE_WT_GLOBAL, cc->flag1,
2427 * Well, we can 'disable' the alarm.
2429 if (obp->cstat[0] & SESCTL_DISABLE) {
2430 cc->flag2 &= ~SAFT_FLG1_ALARM;
2431 ep->priv |= 0x40; /* Muted */
2432 wrbuf16(ssc, SAFTE_WT_GLOBAL, cc->flag1,
2444 * This function handles all of the 16 byte WRITE BUFFER commands.
2447 wrbuf16(ses_softc_t *ssc, uint8_t op, uint8_t b1, uint8_t b2,
2448 uint8_t b3, int slp)
2452 struct scfg *cc = ssc->ses_private;
2453 static char cdb[10] = { WRITE_BUFFER, 1, 0, 0, 0, 0, 0, 0, 16, 0 };
2458 sdata = SES_MALLOC(16);
2462 SES_DLOG(ssc, "saf_wrbuf16 %x %x %x %x\n", op, b1, b2, b3);
2468 MEMZERO(&sdata[4], 12);
2470 err = ses_runcmd(ssc, cdb, 10, sdata, &amt);
2471 SES_FREE(sdata, 16);
2476 * This function updates the status byte for the device slot described.
2478 * Since this is an optional SAF-TE command, there's no point in
2479 * returning an error.
2482 wrslot_stat(ses_softc_t *ssc, int slp)
2486 char cdb[10], *sdata;
2487 struct scfg *cc = ssc->ses_private;
2492 SES_DLOG(ssc, "saf_wrslot\n");
2493 cdb[0] = WRITE_BUFFER;
2501 cdb[8] = cc->Nslots * 3 + 1;
2504 sdata = SES_MALLOC(cc->Nslots * 3 + 1);
2507 MEMZERO(sdata, cc->Nslots * 3 + 1);
2509 sdata[0] = SAFTE_WT_DSTAT;
2510 for (i = 0; i < cc->Nslots; i++) {
2511 ep = &ssc->ses_objmap[cc->slotoff + i];
2512 SES_DLOG(ssc, "saf_wrslot %d <- %x\n", i, ep->priv & 0xff);
2513 sdata[1 + (3 * i)] = ep->priv & 0xff;
2515 amt = -(cc->Nslots * 3 + 1);
2516 ses_runcmd(ssc, cdb, 10, sdata, &amt);
2517 SES_FREE(sdata, cc->Nslots * 3 + 1);
2521 * This function issues the "PERFORM SLOT OPERATION" command.
2524 perf_slotop(ses_softc_t *ssc, uint8_t slot, uint8_t opflag, int slp)
2528 struct scfg *cc = ssc->ses_private;
2529 static char cdb[10] =
2530 { WRITE_BUFFER, 1, 0, 0, 0, 0, 0, 0, SAFT_SCRATCH, 0 };
2535 sdata = SES_MALLOC(SAFT_SCRATCH);
2538 MEMZERO(sdata, SAFT_SCRATCH);
2540 sdata[0] = SAFTE_WT_SLTOP;
2543 SES_DLOG(ssc, "saf_slotop slot %d op %x\n", slot, opflag);
2544 amt = -SAFT_SCRATCH;
2545 err = ses_runcmd(ssc, cdb, 10, sdata, &amt);
2546 SES_FREE(sdata, SAFT_SCRATCH);