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.2 2003/06/17 04:28:19 dillon 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>
39 #include <sys/errno.h>
40 #include <sys/devicestat.h>
41 #include <machine/stdarg.h>
44 #include <cam/cam_ccb.h>
45 #include <cam/cam_extend.h>
46 #include <cam/cam_periph.h>
47 #include <cam/cam_xpt_periph.h>
48 #include <cam/cam_queue.h>
49 #include <cam/cam_debug.h>
51 #include <cam/scsi/scsi_all.h>
52 #include <cam/scsi/scsi_message.h>
53 #include <sys/ioccom.h>
54 #include <cam/scsi/scsi_ses.h>
59 * Platform Independent Driver Internal Definitions for SES devices.
71 typedef struct ses_softc ses_softc_t;
73 int (*softc_init)(ses_softc_t *, int);
74 int (*init_enc)(ses_softc_t *);
75 int (*get_encstat)(ses_softc_t *, int);
76 int (*set_encstat)(ses_softc_t *, ses_encstat, int);
77 int (*get_objstat)(ses_softc_t *, ses_objstat *, int);
78 int (*set_objstat)(ses_softc_t *, ses_objstat *, int);
81 #define ENCI_SVALID 0x80
85 enctype : 8, /* enclosure type */
86 subenclosure : 8, /* subenclosure id */
87 svalid : 1, /* enclosure information valid */
88 priv : 15; /* private data, per object */
89 uint8_t encstat[4]; /* state && stats */
92 #define SEN_ID "UNISYS SUN_SEN"
96 static enctyp ses_type(void *, int);
99 /* Forward reference to Enclosure Functions */
100 static int ses_softc_init(ses_softc_t *, int);
101 static int ses_init_enc(ses_softc_t *);
102 static int ses_get_encstat(ses_softc_t *, int);
103 static int ses_set_encstat(ses_softc_t *, uint8_t, int);
104 static int ses_get_objstat(ses_softc_t *, ses_objstat *, int);
105 static int ses_set_objstat(ses_softc_t *, ses_objstat *, int);
107 static int safte_softc_init(ses_softc_t *, int);
108 static int safte_init_enc(ses_softc_t *);
109 static int safte_get_encstat(ses_softc_t *, int);
110 static int safte_set_encstat(ses_softc_t *, uint8_t, int);
111 static int safte_get_objstat(ses_softc_t *, ses_objstat *, int);
112 static int safte_set_objstat(ses_softc_t *, ses_objstat *, int);
115 * Platform implementation defines/functions for SES internal kernel stuff
118 #define STRNCMP strncmp
119 #define PRINTF printf
120 #define SES_LOG ses_log
122 #define SES_DLOG ses_log
124 #define SES_DLOG if (0) ses_log
126 #define SES_VLOG if (bootverbose) ses_log
127 #define SES_MALLOC(amt) malloc(amt, M_DEVBUF, M_NOWAIT)
128 #define SES_FREE(ptr, amt) free(ptr, M_DEVBUF)
129 #define MEMZERO bzero
130 #define MEMCPY(dest, src, amt) bcopy(src, dest, amt)
132 static int ses_runcmd(struct ses_softc *, char *, int, char *, int *);
133 static void ses_log(struct ses_softc *, const char *, ...);
136 * Gerenal FreeBSD kernel stuff.
140 #define ccb_state ppriv_field0
141 #define ccb_bp ppriv_ptr1
144 enctyp ses_type; /* type of enclosure */
145 encvec ses_vec; /* vector to handlers */
146 void * ses_private; /* per-type private data */
147 encobj * ses_objmap; /* objects */
148 u_int32_t ses_nobjects; /* number of objects */
149 ses_encstat ses_encstat; /* overall status */
151 union ccb ses_saved_ccb;
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 DATA_SET(periphdriver_set, sesdriver);
182 static struct cdevsw ses_cdevsw =
185 /* close */ sesclose,
188 /* ioctl */ sesioctl,
191 /* strategy */ nostrategy,
193 /* maj */ SES_CDEV_MAJOR,
199 static struct extend_array *sesperiphs;
205 struct cam_path *path;
208 * Create our extend array for storing the devices we attach to.
210 sesperiphs = cam_extend_new();
211 if (sesperiphs == NULL) {
212 printf("ses: Failed to alloc extend array!\n");
217 * Install a global async callback. This callback will
218 * receive async callbacks like "new device found".
220 status = xpt_create_path(&path, NULL, CAM_XPT_PATH_ID,
221 CAM_TARGET_WILDCARD, CAM_LUN_WILDCARD);
223 if (status == CAM_REQ_CMP) {
224 struct ccb_setasync csa;
226 xpt_setup_ccb(&csa.ccb_h, path, 5);
227 csa.ccb_h.func_code = XPT_SASYNC_CB;
228 csa.event_enable = AC_FOUND_DEVICE;
229 csa.callback = sesasync;
230 csa.callback_arg = NULL;
231 xpt_action((union ccb *)&csa);
232 status = csa.ccb_h.status;
236 if (status != CAM_REQ_CMP) {
237 printf("ses: Failed to attach master async callback "
238 "due to status 0x%x!\n", status);
243 sesoninvalidate(struct cam_periph *periph)
245 struct ses_softc *softc;
246 struct ccb_setasync csa;
248 softc = (struct ses_softc *)periph->softc;
251 * Unregister any async callbacks.
253 xpt_setup_ccb(&csa.ccb_h, periph->path, 5);
254 csa.ccb_h.func_code = XPT_SASYNC_CB;
255 csa.event_enable = 0;
256 csa.callback = sesasync;
257 csa.callback_arg = periph;
258 xpt_action((union ccb *)&csa);
260 softc->ses_flags |= SES_FLAG_INVALID;
262 xpt_print_path(periph->path);
263 printf("lost device\n");
267 sescleanup(struct cam_periph *periph)
269 struct ses_softc *softc;
271 softc = (struct ses_softc *)periph->softc;
273 destroy_dev(softc->ses_dev);
275 cam_extend_release(sesperiphs, periph->unit_number);
276 xpt_print_path(periph->path);
277 printf("removing device entry\n");
278 free(softc, M_DEVBUF);
282 sesasync(void *callback_arg, u_int32_t code, struct cam_path *path, void *arg)
284 struct cam_periph *periph;
286 periph = (struct cam_periph *)callback_arg;
289 case AC_FOUND_DEVICE:
292 struct ccb_getdev *cgd;
294 cgd = (struct ccb_getdev *)arg;
297 * PROBLEM: WE NEED TO LOOK AT BYTES 48-53 TO SEE IF THIS IS
298 * PROBLEM: IS A SAF-TE DEVICE.
300 switch (ses_type(&cgd->inq_data, cgd->inq_len)) {
303 case SES_SES_PASSTHROUGH:
311 status = cam_periph_alloc(sesregister, sesoninvalidate,
312 sescleanup, sesstart, "ses", CAM_PERIPH_BIO,
313 cgd->ccb_h.path, sesasync, AC_FOUND_DEVICE, cgd);
315 if (status != CAM_REQ_CMP && status != CAM_REQ_INPROG) {
316 printf("sesasync: Unable to probe new device due to "
317 "status 0x%x\n", status);
322 cam_periph_async(periph, code, path, arg);
328 sesregister(struct cam_periph *periph, void *arg)
330 struct ses_softc *softc;
331 struct ccb_setasync csa;
332 struct ccb_getdev *cgd;
335 cgd = (struct ccb_getdev *)arg;
336 if (periph == NULL) {
337 printf("sesregister: periph was NULL!!\n");
338 return (CAM_REQ_CMP_ERR);
342 printf("sesregister: no getdev CCB, can't register device\n");
343 return (CAM_REQ_CMP_ERR);
346 softc = malloc(sizeof (struct ses_softc), M_DEVBUF, M_NOWAIT);
348 printf("sesregister: Unable to probe new device. "
349 "Unable to allocate softc\n");
350 return (CAM_REQ_CMP_ERR);
352 bzero(softc, sizeof (struct ses_softc));
353 periph->softc = softc;
354 softc->periph = periph;
356 softc->ses_type = ses_type(&cgd->inq_data, sizeof (cgd->inq_data));
358 switch (softc->ses_type) {
361 case SES_SES_PASSTHROUGH:
362 softc->ses_vec.softc_init = ses_softc_init;
363 softc->ses_vec.init_enc = ses_init_enc;
364 softc->ses_vec.get_encstat = ses_get_encstat;
365 softc->ses_vec.set_encstat = ses_set_encstat;
366 softc->ses_vec.get_objstat = ses_get_objstat;
367 softc->ses_vec.set_objstat = ses_set_objstat;
370 softc->ses_vec.softc_init = safte_softc_init;
371 softc->ses_vec.init_enc = safte_init_enc;
372 softc->ses_vec.get_encstat = safte_get_encstat;
373 softc->ses_vec.set_encstat = safte_set_encstat;
374 softc->ses_vec.get_objstat = safte_get_objstat;
375 softc->ses_vec.set_objstat = safte_set_objstat;
381 free(softc, M_DEVBUF);
382 return (CAM_REQ_CMP_ERR);
385 cam_extend_set(sesperiphs, periph->unit_number, periph);
387 softc->ses_dev = make_dev(&ses_cdevsw, periph->unit_number,
388 UID_ROOT, GID_OPERATOR, 0600, "%s%d",
389 periph->periph_name, periph->unit_number);
392 * Add an async callback so that we get
393 * notified if this device goes away.
395 xpt_setup_ccb(&csa.ccb_h, periph->path, 5);
396 csa.ccb_h.func_code = XPT_SASYNC_CB;
397 csa.event_enable = AC_LOST_DEVICE;
398 csa.callback = sesasync;
399 csa.callback_arg = periph;
400 xpt_action((union ccb *)&csa);
402 switch (softc->ses_type) {
405 tname = "No SES device";
408 tname = "SCSI-2 SES Device";
411 tname = "SCSI-3 SES Device";
413 case SES_SES_PASSTHROUGH:
414 tname = "SES Passthrough Device";
417 tname = "UNISYS SEN Device (NOT HANDLED YET)";
420 tname = "SAF-TE Compliant Device";
423 xpt_announce_periph(periph, tname);
424 return (CAM_REQ_CMP);
428 sesopen(dev_t dev, int flags, int fmt, struct proc *p)
430 struct cam_periph *periph;
431 struct ses_softc *softc;
435 periph = cam_extend_get(sesperiphs, SESUNIT(dev));
436 if (periph == NULL) {
440 if ((error = cam_periph_lock(periph, PRIBIO | PCATCH)) != 0) {
446 if (cam_periph_acquire(periph) != CAM_REQ_CMP) {
447 cam_periph_unlock(periph);
451 softc = (struct ses_softc *)periph->softc;
453 if (softc->ses_flags & SES_FLAG_INVALID) {
457 if (softc->ses_flags & SES_FLAG_OPEN) {
461 if (softc->ses_vec.softc_init == NULL) {
466 softc->ses_flags |= SES_FLAG_OPEN;
467 if ((softc->ses_flags & SES_FLAG_INITIALIZED) == 0) {
468 error = (*softc->ses_vec.softc_init)(softc, 1);
470 softc->ses_flags &= ~SES_FLAG_OPEN;
472 softc->ses_flags |= SES_FLAG_INITIALIZED;
477 cam_periph_release(periph);
479 cam_periph_unlock(periph);
484 sesclose(dev_t dev, int flag, int fmt, struct proc *p)
486 struct cam_periph *periph;
487 struct ses_softc *softc;
493 periph = cam_extend_get(sesperiphs, unit);
497 softc = (struct ses_softc *)periph->softc;
499 if ((error = cam_periph_lock(periph, PRIBIO)) != 0)
502 softc->ses_flags &= ~SES_FLAG_OPEN;
504 cam_periph_unlock(periph);
505 cam_periph_release(periph);
511 sesstart(struct cam_periph *p, union ccb *sccb)
514 if (p->immediate_priority <= p->pinfo.priority) {
515 SLIST_INSERT_HEAD(&p->ccb_list, &sccb->ccb_h, periph_links.sle);
516 p->immediate_priority = CAM_PRIORITY_NONE;
517 wakeup(&p->ccb_list);
523 sesdone(struct cam_periph *periph, union ccb *dccb)
525 wakeup(&dccb->ccb_h.cbfcnp);
529 seserror(union ccb *ccb, u_int32_t cflags, u_int32_t sflags)
531 struct ses_softc *softc;
532 struct cam_periph *periph;
534 periph = xpt_path_periph(ccb->ccb_h.path);
535 softc = (struct ses_softc *)periph->softc;
537 return (cam_periph_error(ccb, cflags, sflags, &softc->ses_saved_ccb));
541 sesioctl(dev_t dev, u_long cmd, caddr_t arg_addr, int flag, struct proc *p)
543 struct cam_periph *periph;
546 ses_object obj, *uobj;
547 struct ses_softc *ssc;
553 addr = *((caddr_t *) arg_addr);
557 periph = cam_extend_get(sesperiphs, SESUNIT(dev));
561 CAM_DEBUG(periph->path, CAM_DEBUG_TRACE, ("entering sesioctl\n"));
563 ssc = (struct ses_softc *)periph->softc;
566 * Now check to see whether we're initialized or not.
568 if ((ssc->ses_flags & SES_FLAG_INITIALIZED) == 0) {
574 CAM_DEBUG(periph->path, CAM_DEBUG_TRACE,
575 ("trying to do ioctl %#lx\n", cmd));
578 * If this command can change the device's state,
579 * we must have the device open for writing.
583 case SESIOC_GETOBJMAP:
584 case SESIOC_GETENCSTAT:
585 case SESIOC_GETOBJSTAT:
588 if ((flag & FWRITE) == 0) {
595 error = copyout(&ssc->ses_nobjects, addr,
596 sizeof (ssc->ses_nobjects));
599 case SESIOC_GETOBJMAP:
600 for (uobj = addr, i = 0; i != ssc->ses_nobjects; i++, uobj++) {
602 obj.subencid = ssc->ses_objmap[i].subenclosure;
603 obj.object_type = ssc->ses_objmap[i].enctype;
604 error = copyout(&obj, uobj, sizeof (ses_object));
611 case SESIOC_GETENCSTAT:
612 error = (*ssc->ses_vec.get_encstat)(ssc, 1);
615 tmp = ssc->ses_encstat & ~ENCI_SVALID;
616 error = copyout(&tmp, addr, sizeof (ses_encstat));
617 ssc->ses_encstat = tmp;
620 case SESIOC_SETENCSTAT:
621 error = copyin(addr, &tmp, sizeof (ses_encstat));
624 error = (*ssc->ses_vec.set_encstat)(ssc, tmp, 1);
627 case SESIOC_GETOBJSTAT:
628 error = copyin(addr, &objs, sizeof (ses_objstat));
631 if (objs.obj_id >= ssc->ses_nobjects) {
635 error = (*ssc->ses_vec.get_objstat)(ssc, &objs, 1);
638 error = copyout(&objs, addr, sizeof (ses_objstat));
640 * Always (for now) invalidate entry.
642 ssc->ses_objmap[objs.obj_id].svalid = 0;
645 case SESIOC_SETOBJSTAT:
646 error = copyin(addr, &objs, sizeof (ses_objstat));
650 if (objs.obj_id >= ssc->ses_nobjects) {
654 error = (*ssc->ses_vec.set_objstat)(ssc, &objs, 1);
657 * Always (for now) invalidate entry.
659 ssc->ses_objmap[objs.obj_id].svalid = 0;
664 error = (*ssc->ses_vec.init_enc)(ssc);
668 error = cam_periph_ioctl(periph, cmd, arg_addr, seserror);
674 #define SES_FLAGS SF_NO_PRINT | SF_RETRY_SELTO | SF_RETRY_UA
676 ses_runcmd(struct ses_softc *ssc, char *cdb, int cdbl, char *dptr, int *dlenp)
683 if ((dlen = *dlenp) < 0) {
694 if (cdbl > IOCDBLEN) {
698 ccb = cam_periph_getccb(ssc->periph, 1);
699 cam_fill_csio(&ccb->csio, 0, sesdone, ddf, MSG_SIMPLE_Q_TAG, dptr,
700 dlen, sizeof (struct scsi_sense_data), cdbl, 60 * 1000);
701 bcopy(cdb, ccb->csio.cdb_io.cdb_bytes, cdbl);
703 error = cam_periph_runccb(ccb, seserror, 0, SES_FLAGS, NULL);
704 if ((ccb->ccb_h.status & CAM_DEV_QFRZN) != 0)
705 cam_release_devq(ccb->ccb_h.path, 0, 0, 0, FALSE);
712 *dlenp = ccb->csio.resid;
715 xpt_release_ccb(ccb);
720 ses_log(struct ses_softc *ssc, const char *fmt, ...)
724 printf("%s%d: ", ssc->periph->periph_name, ssc->periph->unit_number);
731 * The code after this point runs on many platforms,
732 * so forgive the slightly awkward and nonconforming
737 * Is this a device that supports enclosure services?
739 * It's a a pretty simple ruleset- if it is device type 0x0D (13), it's
740 * an SES device. If it happens to be an old UNISYS SEN device, we can
744 #define SAFTE_START 44
746 #define SAFTE_LEN SAFTE_END-SAFTE_START
749 ses_type(void *buf, int buflen)
751 unsigned char *iqd = buf;
754 buflen = 256; /* per SPC-2 */
756 if (buflen < 8+SEN_ID_LEN)
759 if ((iqd[0] & 0x1f) == T_ENCLOSURE) {
760 if (STRNCMP(&iqd[8], SEN_ID, SEN_ID_LEN) == 0) {
762 } else if ((iqd[2] & 0x7) > 2) {
765 return (SES_SES_SCSI2);
770 #ifdef SES_ENABLE_PASSTHROUGH
771 if ((iqd[6] & 0x40) && (iqd[2] & 0x7) >= 2) {
773 * PassThrough Device.
775 return (SES_SES_PASSTHROUGH);
780 * The comparison is short for a reason-
781 * some vendors were chopping it short.
784 if (buflen < SAFTE_END - 2) {
788 if (STRNCMP((char *)&iqd[SAFTE_START], "SAF-TE", SAFTE_LEN - 2) == 0) {
795 * SES Native Type Device Support
799 * SES Diagnostic Page Codes
805 #define SesStatusPage SesControlPage
808 #define SesStringIn SesStringOut
810 #define SesThresholdIn SesThresholdOut
812 #define SesArrayStatus SesArrayControl
813 SesElementDescriptor,
822 * Minimum amount of data, starting from byte 0, to have
825 #define SES_CFGHDR_MINLEN 12
828 * Minimum amount of data, starting from byte 0, to have
829 * the config header and one enclosure header.
831 #define SES_ENCHDR_MINLEN 48
834 * Take this value, subtract it from VEnclen and you know
835 * the length of the vendor unique bytes.
837 #define SES_ENCHDR_VMIN 36
840 * SES Data Structures
844 uint32_t GenCode; /* Generation Code */
845 uint8_t Nsubenc; /* Number of Subenclosures */
849 uint8_t Subencid; /* SubEnclosure Identifier */
850 uint8_t Ntypes; /* # of supported types */
851 uint8_t VEnclen; /* Enclosure Descriptor Length */
855 uint8_t encWWN[8]; /* XXX- Not Right Yet */
863 uint8_t enc_type; /* type of element */
864 uint8_t enc_maxelt; /* maximum supported */
865 uint8_t enc_subenc; /* in SubEnc # N */
866 uint8_t enc_tlen; /* Type Descriptor Text Length */
880 uint8_t ses_ntypes; /* total number of types supported */
883 * We need to keep a type index as well as an
884 * object index for each object in an enclosure.
886 struct typidx *ses_typidx;
889 * We also need to keep track of the number of elements
890 * per type of element. This is needed later so that we
891 * can find precisely in the returned status data the
892 * status for the Nth element of the Kth type.
894 uint8_t * ses_eltmap;
899 * (de)canonicalization defines
901 #define sbyte(x, byte) ((((uint32_t)(x)) >> (byte * 8)) & 0xff)
902 #define sbit(x, bit) (((uint32_t)(x)) << bit)
903 #define sset8(outp, idx, sval) (((uint8_t *)(outp))[idx++]) = sbyte(sval, 0)
905 #define sset16(outp, idx, sval) \
906 (((uint8_t *)(outp))[idx++]) = sbyte(sval, 1), \
907 (((uint8_t *)(outp))[idx++]) = sbyte(sval, 0)
910 #define sset24(outp, idx, sval) \
911 (((uint8_t *)(outp))[idx++]) = sbyte(sval, 2), \
912 (((uint8_t *)(outp))[idx++]) = sbyte(sval, 1), \
913 (((uint8_t *)(outp))[idx++]) = sbyte(sval, 0)
916 #define sset32(outp, idx, sval) \
917 (((uint8_t *)(outp))[idx++]) = sbyte(sval, 3), \
918 (((uint8_t *)(outp))[idx++]) = sbyte(sval, 2), \
919 (((uint8_t *)(outp))[idx++]) = sbyte(sval, 1), \
920 (((uint8_t *)(outp))[idx++]) = sbyte(sval, 0)
922 #define gbyte(x, byte) ((((uint32_t)(x)) & 0xff) << (byte * 8))
923 #define gbit(lv, in, idx, shft, mask) lv = ((in[idx] >> shft) & mask)
924 #define sget8(inp, idx, lval) lval = (((uint8_t *)(inp))[idx++])
925 #define gget8(inp, idx, lval) lval = (((uint8_t *)(inp))[idx])
927 #define sget16(inp, idx, lval) \
928 lval = gbyte((((uint8_t *)(inp))[idx]), 1) | \
929 (((uint8_t *)(inp))[idx+1]), idx += 2
931 #define gget16(inp, idx, lval) \
932 lval = gbyte((((uint8_t *)(inp))[idx]), 1) | \
933 (((uint8_t *)(inp))[idx+1])
935 #define sget24(inp, idx, lval) \
936 lval = gbyte((((uint8_t *)(inp))[idx]), 2) | \
937 gbyte((((uint8_t *)(inp))[idx+1]), 1) | \
938 (((uint8_t *)(inp))[idx+2]), idx += 3
940 #define gget24(inp, idx, lval) \
941 lval = gbyte((((uint8_t *)(inp))[idx]), 2) | \
942 gbyte((((uint8_t *)(inp))[idx+1]), 1) | \
943 (((uint8_t *)(inp))[idx+2])
945 #define sget32(inp, idx, lval) \
946 lval = gbyte((((uint8_t *)(inp))[idx]), 3) | \
947 gbyte((((uint8_t *)(inp))[idx+1]), 2) | \
948 gbyte((((uint8_t *)(inp))[idx+2]), 1) | \
949 (((uint8_t *)(inp))[idx+3]), idx += 4
951 #define gget32(inp, idx, lval) \
952 lval = gbyte((((uint8_t *)(inp))[idx]), 3) | \
953 gbyte((((uint8_t *)(inp))[idx+1]), 2) | \
954 gbyte((((uint8_t *)(inp))[idx+2]), 1) | \
955 (((uint8_t *)(inp))[idx+3])
958 #define CFLEN (256 + SES_ENCHDR_MINLEN)
961 * Routines specific && private to SES only
964 static int ses_getconfig(ses_softc_t *);
965 static int ses_getputstat(ses_softc_t *, int, SesComStat *, int, int);
966 static int ses_cfghdr(uint8_t *, int, SesCfgHdr *);
967 static int ses_enchdr(uint8_t *, int, uint8_t, SesEncHdr *);
968 static int ses_encdesc(uint8_t *, int, uint8_t, SesEncDesc *);
969 static int ses_getthdr(uint8_t *, int, int, SesThdr *);
970 static int ses_decode(char *, int, uint8_t *, int, int, SesComStat *);
971 static int ses_encode(char *, int, uint8_t *, int, int, SesComStat *);
974 ses_softc_init(ses_softc_t *ssc, int doinit)
978 if (ssc->ses_nobjects) {
979 SES_FREE(ssc->ses_objmap,
980 ssc->ses_nobjects * sizeof (encobj));
981 ssc->ses_objmap = NULL;
983 if ((cc = ssc->ses_private) != NULL) {
984 if (cc->ses_eltmap && cc->ses_ntypes) {
985 SES_FREE(cc->ses_eltmap, cc->ses_ntypes);
986 cc->ses_eltmap = NULL;
989 if (cc->ses_typidx && ssc->ses_nobjects) {
990 SES_FREE(cc->ses_typidx,
991 ssc->ses_nobjects * sizeof (struct typidx));
992 cc->ses_typidx = NULL;
994 SES_FREE(cc, sizeof (struct sscfg));
995 ssc->ses_private = NULL;
997 ssc->ses_nobjects = 0;
1000 if (ssc->ses_private == NULL) {
1001 ssc->ses_private = SES_MALLOC(sizeof (struct sscfg));
1003 if (ssc->ses_private == NULL) {
1006 ssc->ses_nobjects = 0;
1007 ssc->ses_encstat = 0;
1008 return (ses_getconfig(ssc));
1012 ses_init_enc(ses_softc_t *ssc)
1018 ses_get_encstat(ses_softc_t *ssc, int slpflag)
1023 if ((status = ses_getputstat(ssc, -1, &ComStat, slpflag, 1)) != 0) {
1026 ssc->ses_encstat = ComStat.comstatus | ENCI_SVALID;
1031 ses_set_encstat(ses_softc_t *ssc, uint8_t encstat, int slpflag)
1036 ComStat.comstatus = encstat & 0xf;
1037 if ((status = ses_getputstat(ssc, -1, &ComStat, slpflag, 0)) != 0) {
1040 ssc->ses_encstat = encstat & 0xf; /* note no SVALID set */
1045 ses_get_objstat(ses_softc_t *ssc, ses_objstat *obp, int slpflag)
1047 int i = (int)obp->obj_id;
1049 if (ssc->ses_objmap[i].svalid == 0) {
1051 int err = ses_getputstat(ssc, i, &ComStat, slpflag, 1);
1054 ssc->ses_objmap[i].encstat[0] = ComStat.comstatus;
1055 ssc->ses_objmap[i].encstat[1] = ComStat.comstat[0];
1056 ssc->ses_objmap[i].encstat[2] = ComStat.comstat[1];
1057 ssc->ses_objmap[i].encstat[3] = ComStat.comstat[2];
1058 ssc->ses_objmap[i].svalid = 1;
1060 obp->cstat[0] = ssc->ses_objmap[i].encstat[0];
1061 obp->cstat[1] = ssc->ses_objmap[i].encstat[1];
1062 obp->cstat[2] = ssc->ses_objmap[i].encstat[2];
1063 obp->cstat[3] = ssc->ses_objmap[i].encstat[3];
1068 ses_set_objstat(ses_softc_t *ssc, ses_objstat *obp, int slpflag)
1073 * If this is clear, we don't do diddly.
1075 if ((obp->cstat[0] & SESCTL_CSEL) == 0) {
1078 ComStat.comstatus = obp->cstat[0];
1079 ComStat.comstat[0] = obp->cstat[1];
1080 ComStat.comstat[1] = obp->cstat[2];
1081 ComStat.comstat[2] = obp->cstat[3];
1082 err = ses_getputstat(ssc, (int)obp->obj_id, &ComStat, slpflag, 0);
1083 ssc->ses_objmap[(int)obp->obj_id].svalid = 0;
1088 ses_getconfig(ses_softc_t *ssc)
1095 int err, amt, i, nobj, ntype, maxima;
1096 char storage[CFLEN], *sdata;
1097 static char cdb[6] = {
1098 RECEIVE_DIAGNOSTIC, 0x1, SesConfigPage, SCSZ >> 8, SCSZ & 0xff, 0
1101 cc = ssc->ses_private;
1106 sdata = SES_MALLOC(SCSZ);
1111 err = ses_runcmd(ssc, cdb, 6, sdata, &amt);
1113 SES_FREE(sdata, SCSZ);
1118 if (ses_cfghdr((uint8_t *) sdata, amt, &cf)) {
1119 SES_LOG(ssc, "Unable to parse SES Config Header\n");
1120 SES_FREE(sdata, SCSZ);
1123 if (amt < SES_ENCHDR_MINLEN) {
1124 SES_LOG(ssc, "runt enclosure length (%d)\n", amt);
1125 SES_FREE(sdata, SCSZ);
1129 SES_VLOG(ssc, "GenCode %x %d Subenclosures\n", cf.GenCode, cf.Nsubenc);
1132 * Now waltz through all the subenclosures toting up the
1133 * number of types available in each. For this, we only
1134 * really need the enclosure header. However, we get the
1135 * enclosure descriptor for debug purposes, as well
1136 * as self-consistency checking purposes.
1139 maxima = cf.Nsubenc + 1;
1140 cdp = (SesEncDesc *) storage;
1141 for (ntype = i = 0; i < maxima; i++) {
1142 MEMZERO((caddr_t)cdp, sizeof (*cdp));
1143 if (ses_enchdr((uint8_t *) sdata, amt, i, &hd)) {
1144 SES_LOG(ssc, "Cannot Extract Enclosure Header %d\n", i);
1145 SES_FREE(sdata, SCSZ);
1148 SES_VLOG(ssc, " SubEnclosure ID %d, %d Types With this ID, En"
1149 "closure Length %d\n", hd.Subencid, hd.Ntypes, hd.VEnclen);
1151 if (ses_encdesc((uint8_t *)sdata, amt, i, cdp)) {
1152 SES_LOG(ssc, "Can't get Enclosure Descriptor %d\n", i);
1153 SES_FREE(sdata, SCSZ);
1156 SES_VLOG(ssc, " WWN: %02x%02x%02x%02x%02x%02x%02x%02x\n",
1157 cdp->encWWN[0], cdp->encWWN[1], cdp->encWWN[2],
1158 cdp->encWWN[3], cdp->encWWN[4], cdp->encWWN[5],
1159 cdp->encWWN[6], cdp->encWWN[7]);
1164 * Now waltz through all the types that are available, getting
1165 * the type header so we can start adding up the number of
1166 * objects available.
1168 for (nobj = i = 0; i < ntype; i++) {
1169 if (ses_getthdr((uint8_t *)sdata, amt, i, &thdr)) {
1170 SES_LOG(ssc, "Can't get Enclosure Type Header %d\n", i);
1171 SES_FREE(sdata, SCSZ);
1174 SES_LOG(ssc, " Type Desc[%d]: Type 0x%x, MaxElt %d, In Subenc "
1175 "%d, Text Length %d\n", i, thdr.enc_type, thdr.enc_maxelt,
1176 thdr.enc_subenc, thdr.enc_tlen);
1177 nobj += thdr.enc_maxelt;
1182 * Now allocate the object array and type map.
1185 ssc->ses_objmap = SES_MALLOC(nobj * sizeof (encobj));
1186 cc->ses_typidx = SES_MALLOC(nobj * sizeof (struct typidx));
1187 cc->ses_eltmap = SES_MALLOC(ntype);
1189 if (ssc->ses_objmap == NULL || cc->ses_typidx == NULL ||
1190 cc->ses_eltmap == NULL) {
1191 if (ssc->ses_objmap) {
1192 SES_FREE(ssc->ses_objmap, (nobj * sizeof (encobj)));
1193 ssc->ses_objmap = NULL;
1195 if (cc->ses_typidx) {
1196 SES_FREE(cc->ses_typidx,
1197 (nobj * sizeof (struct typidx)));
1198 cc->ses_typidx = NULL;
1200 if (cc->ses_eltmap) {
1201 SES_FREE(cc->ses_eltmap, ntype);
1202 cc->ses_eltmap = NULL;
1204 SES_FREE(sdata, SCSZ);
1207 MEMZERO(ssc->ses_objmap, nobj * sizeof (encobj));
1208 MEMZERO(cc->ses_typidx, nobj * sizeof (struct typidx));
1209 MEMZERO(cc->ses_eltmap, ntype);
1210 cc->ses_ntypes = (uint8_t) ntype;
1211 ssc->ses_nobjects = nobj;
1214 * Now waltz through the # of types again to fill in the types
1215 * (and subenclosure ids) of the allocated objects.
1218 for (i = 0; i < ntype; i++) {
1220 if (ses_getthdr((uint8_t *)sdata, amt, i, &thdr)) {
1223 cc->ses_eltmap[i] = thdr.enc_maxelt;
1224 for (j = 0; j < thdr.enc_maxelt; j++) {
1225 cc->ses_typidx[nobj].ses_tidx = i;
1226 cc->ses_typidx[nobj].ses_oidx = j;
1227 ssc->ses_objmap[nobj].subenclosure = thdr.enc_subenc;
1228 ssc->ses_objmap[nobj++].enctype = thdr.enc_type;
1231 SES_FREE(sdata, SCSZ);
1236 ses_getputstat(ses_softc_t *ssc, int objid, SesComStat *sp, int slp, int in)
1239 int err, amt, bufsiz, tidx, oidx;
1240 char cdb[6], *sdata;
1242 cc = ssc->ses_private;
1248 * If we're just getting overall enclosure status,
1249 * we only need 2 bytes of data storage.
1251 * If we're getting anything else, we know how much
1252 * storage we need by noting that starting at offset
1253 * 8 in returned data, all object status bytes are 4
1254 * bytes long, and are stored in chunks of types(M)
1255 * and nth+1 instances of type M.
1260 bufsiz = (ssc->ses_nobjects * 4) + (cc->ses_ntypes * 4) + 8;
1262 sdata = SES_MALLOC(bufsiz);
1266 cdb[0] = RECEIVE_DIAGNOSTIC;
1268 cdb[2] = SesStatusPage;
1269 cdb[3] = bufsiz >> 8;
1270 cdb[4] = bufsiz & 0xff;
1273 err = ses_runcmd(ssc, cdb, 6, sdata, &amt);
1275 SES_FREE(sdata, bufsiz);
1284 tidx = cc->ses_typidx[objid].ses_tidx;
1285 oidx = cc->ses_typidx[objid].ses_oidx;
1288 if (ses_decode(sdata, amt, cc->ses_eltmap, tidx, oidx, sp)) {
1292 if (ses_encode(sdata, amt, cc->ses_eltmap, tidx, oidx, sp)) {
1295 cdb[0] = SEND_DIAGNOSTIC;
1298 cdb[3] = bufsiz >> 8;
1299 cdb[4] = bufsiz & 0xff;
1302 err = ses_runcmd(ssc, cdb, 6, sdata, &amt);
1305 SES_FREE(sdata, bufsiz);
1311 * Routines to parse returned SES data structures.
1312 * Architecture and compiler independent.
1316 ses_cfghdr(uint8_t *buffer, int buflen, SesCfgHdr *cfp)
1318 if (buflen < SES_CFGHDR_MINLEN) {
1321 gget8(buffer, 1, cfp->Nsubenc);
1322 gget32(buffer, 4, cfp->GenCode);
1327 ses_enchdr(uint8_t *buffer, int amt, uint8_t SubEncId, SesEncHdr *chp)
1330 for (s = 0; s < SubEncId; s++) {
1333 off += buffer[off+3] + 4;
1335 if (off + 3 > amt) {
1338 gget8(buffer, off+1, chp->Subencid);
1339 gget8(buffer, off+2, chp->Ntypes);
1340 gget8(buffer, off+3, chp->VEnclen);
1345 ses_encdesc(uint8_t *buffer, int amt, uint8_t SubEncId, SesEncDesc *cdp)
1347 int s, e, enclen, off = 8;
1348 for (s = 0; s < SubEncId; s++) {
1351 off += buffer[off+3] + 4;
1353 if (off + 3 > amt) {
1356 gget8(buffer, off+3, enclen);
1365 MEMCPY(cdp, &buffer[off], e - off);
1370 ses_getthdr(uint8_t *buffer, int amt, int nth, SesThdr *thp)
1374 if (amt < SES_CFGHDR_MINLEN) {
1377 for (s = 0; s < buffer[1]; s++) {
1380 off += buffer[off+3] + 4;
1382 if (off + 3 > amt) {
1385 off += buffer[off+3] + 4 + (nth * 4);
1386 if (amt < (off + 4))
1389 gget8(buffer, off++, thp->enc_type);
1390 gget8(buffer, off++, thp->enc_maxelt);
1391 gget8(buffer, off++, thp->enc_subenc);
1392 gget8(buffer, off, thp->enc_tlen);
1397 * This function needs a little explanation.
1399 * The arguments are:
1404 * These describes the raw input SES status data and length.
1408 * This is a map of the number of types for each element type
1413 * This is the element type being sought. If elt is -1,
1414 * then overall enclosure status is being sought.
1418 * This is the ordinal Mth element of type elt being sought.
1422 * This is the output area to store the status for
1423 * the Mth element of type Elt.
1427 ses_decode(char *b, int amt, uint8_t *ep, int elt, int elm, SesComStat *sp)
1432 * If it's overall enclosure status being sought, get that.
1433 * We need at least 2 bytes of status data to get that.
1438 gget8(b, 1, sp->comstatus);
1446 * Check to make sure that the Mth element is legal for type Elt.
1453 * Starting at offset 8, start skipping over the storage
1454 * for the element types we're not interested in.
1456 for (idx = 8, i = 0; i < elt; i++) {
1457 idx += ((ep[i] + 1) * 4);
1461 * Skip over Overall status for this element type.
1466 * And skip to the index for the Mth element that we're going for.
1471 * Make sure we haven't overflowed the buffer.
1477 * Retrieve the status.
1479 gget8(b, idx++, sp->comstatus);
1480 gget8(b, idx++, sp->comstat[0]);
1481 gget8(b, idx++, sp->comstat[1]);
1482 gget8(b, idx++, sp->comstat[2]);
1484 PRINTF("Get Elt 0x%x Elm 0x%x (idx %d)\n", elt, elm, idx-4);
1490 * This is the mirror function to ses_decode, but we set the 'select'
1491 * bit for the object which we're interested in. All other objects,
1492 * after a status fetch, should have that bit off. Hmm. It'd be easy
1493 * enough to ensure this, so we will.
1497 ses_encode(char *b, int amt, uint8_t *ep, int elt, int elm, SesComStat *sp)
1502 * If it's overall enclosure status being sought, get that.
1503 * We need at least 2 bytes of status data to get that.
1510 sset8(b, i, sp->comstatus & 0xf);
1512 PRINTF("set EncStat %x\n", sp->comstatus);
1518 * Check to make sure that the Mth element is legal for type Elt.
1525 * Starting at offset 8, start skipping over the storage
1526 * for the element types we're not interested in.
1528 for (idx = 8, i = 0; i < elt; i++) {
1529 idx += ((ep[i] + 1) * 4);
1533 * Skip over Overall status for this element type.
1538 * And skip to the index for the Mth element that we're going for.
1543 * Make sure we haven't overflowed the buffer.
1551 sset8(b, idx, sp->comstatus);
1552 sset8(b, idx, sp->comstat[0]);
1553 sset8(b, idx, sp->comstat[1]);
1554 sset8(b, idx, sp->comstat[2]);
1558 PRINTF("Set Elt 0x%x Elm 0x%x (idx %d) with %x %x %x %x\n",
1559 elt, elm, idx, sp->comstatus, sp->comstat[0],
1560 sp->comstat[1], sp->comstat[2]);
1564 * Now make sure all other 'Select' bits are off.
1566 for (i = 8; i < amt; i += 4) {
1571 * And make sure the INVOP bit is clear.
1579 * SAF-TE Type Device Emulation
1582 static int safte_getconfig(ses_softc_t *);
1583 static int safte_rdstat(ses_softc_t *, int);;
1584 static int set_objstat_sel(ses_softc_t *, ses_objstat *, int);
1585 static int wrbuf16(ses_softc_t *, uint8_t, uint8_t, uint8_t, uint8_t, int);
1586 static void wrslot_stat(ses_softc_t *, int);
1587 static int perf_slotop(ses_softc_t *, uint8_t, uint8_t, int);
1589 #define ALL_ENC_STAT (SES_ENCSTAT_CRITICAL | SES_ENCSTAT_UNRECOV | \
1590 SES_ENCSTAT_NONCRITICAL | SES_ENCSTAT_INFO)
1592 * SAF-TE specific defines- Mandatory ones only...
1596 * READ BUFFER ('get' commands) IDs- placed in offset 2 of cdb
1598 #define SAFTE_RD_RDCFG 0x00 /* read enclosure configuration */
1599 #define SAFTE_RD_RDESTS 0x01 /* read enclosure status */
1600 #define SAFTE_RD_RDDSTS 0x04 /* read drive slot status */
1603 * WRITE BUFFER ('set' commands) IDs- placed in offset 0 of databuf
1605 #define SAFTE_WT_DSTAT 0x10 /* write device slot status */
1606 #define SAFTE_WT_SLTOP 0x12 /* perform slot operation */
1607 #define SAFTE_WT_FANSPD 0x13 /* set fan speed */
1608 #define SAFTE_WT_ACTPWS 0x14 /* turn on/off power supply */
1609 #define SAFTE_WT_GLOBAL 0x15 /* send global command */
1612 #define SAFT_SCRATCH 64
1613 #define NPSEUDO_THERM 16
1614 #define NPSEUDO_ALARM 1
1617 * Cached Configuration
1619 uint8_t Nfans; /* Number of Fans */
1620 uint8_t Npwr; /* Number of Power Supplies */
1621 uint8_t Nslots; /* Number of Device Slots */
1622 uint8_t DoorLock; /* Door Lock Installed */
1623 uint8_t Ntherm; /* Number of Temperature Sensors */
1624 uint8_t Nspkrs; /* Number of Speakers */
1625 uint8_t Nalarm; /* Number of Alarms (at least one) */
1627 * Cached Flag Bytes for Global Status
1632 * What object index ID is where various slots start.
1636 #define SAFT_ALARM_OFFSET(cc) (cc)->slotoff - 1
1639 #define SAFT_FLG1_ALARM 0x1
1640 #define SAFT_FLG1_GLOBFAIL 0x2
1641 #define SAFT_FLG1_GLOBWARN 0x4
1642 #define SAFT_FLG1_ENCPWROFF 0x8
1643 #define SAFT_FLG1_ENCFANFAIL 0x10
1644 #define SAFT_FLG1_ENCPWRFAIL 0x20
1645 #define SAFT_FLG1_ENCDRVFAIL 0x40
1646 #define SAFT_FLG1_ENCDRVWARN 0x80
1648 #define SAFT_FLG2_LOCKDOOR 0x4
1649 #define SAFT_PRIVATE sizeof (struct scfg)
1651 static char *safte_2little = "Too Little Data Returned (%d) at line %d\n";
1652 #define SAFT_BAIL(r, x, k, l) \
1654 SES_LOG(ssc, safte_2little, x, __LINE__);\
1661 safte_softc_init(ses_softc_t *ssc, int doinit)
1667 if (ssc->ses_nobjects) {
1668 if (ssc->ses_objmap) {
1669 SES_FREE(ssc->ses_objmap,
1670 ssc->ses_nobjects * sizeof (encobj));
1671 ssc->ses_objmap = NULL;
1673 ssc->ses_nobjects = 0;
1675 if (ssc->ses_private) {
1676 SES_FREE(ssc->ses_private, SAFT_PRIVATE);
1677 ssc->ses_private = NULL;
1682 if (ssc->ses_private == NULL) {
1683 ssc->ses_private = SES_MALLOC(SAFT_PRIVATE);
1684 if (ssc->ses_private == NULL) {
1687 MEMZERO(ssc->ses_private, SAFT_PRIVATE);
1690 ssc->ses_nobjects = 0;
1691 ssc->ses_encstat = 0;
1693 if ((err = safte_getconfig(ssc)) != 0) {
1698 * The number of objects here, as well as that reported by the
1699 * READ_BUFFER/GET_CONFIG call, are the over-temperature flags (15)
1700 * that get reported during READ_BUFFER/READ_ENC_STATUS.
1702 cc = ssc->ses_private;
1703 ssc->ses_nobjects = cc->Nfans + cc->Npwr + cc->Nslots + cc->DoorLock +
1704 cc->Ntherm + cc->Nspkrs + NPSEUDO_THERM + NPSEUDO_ALARM;
1705 ssc->ses_objmap = (encobj *)
1706 SES_MALLOC(ssc->ses_nobjects * sizeof (encobj));
1707 if (ssc->ses_objmap == NULL) {
1710 MEMZERO(ssc->ses_objmap, ssc->ses_nobjects * sizeof (encobj));
1714 * Note that this is all arranged for the convenience
1715 * in later fetches of status.
1717 for (i = 0; i < cc->Nfans; i++)
1718 ssc->ses_objmap[r++].enctype = SESTYP_FAN;
1719 cc->pwroff = (uint8_t) r;
1720 for (i = 0; i < cc->Npwr; i++)
1721 ssc->ses_objmap[r++].enctype = SESTYP_POWER;
1722 for (i = 0; i < cc->DoorLock; i++)
1723 ssc->ses_objmap[r++].enctype = SESTYP_DOORLOCK;
1724 for (i = 0; i < cc->Nspkrs; i++)
1725 ssc->ses_objmap[r++].enctype = SESTYP_ALARM;
1726 for (i = 0; i < cc->Ntherm; i++)
1727 ssc->ses_objmap[r++].enctype = SESTYP_THERM;
1728 for (i = 0; i < NPSEUDO_THERM; i++)
1729 ssc->ses_objmap[r++].enctype = SESTYP_THERM;
1730 ssc->ses_objmap[r++].enctype = SESTYP_ALARM;
1731 cc->slotoff = (uint8_t) r;
1732 for (i = 0; i < cc->Nslots; i++)
1733 ssc->ses_objmap[r++].enctype = SESTYP_DEVICE;
1738 safte_init_enc(ses_softc_t *ssc)
1741 static char cdb0[6] = { SEND_DIAGNOSTIC };
1743 err = ses_runcmd(ssc, cdb0, 6, NULL, 0);
1748 err = wrbuf16(ssc, SAFTE_WT_GLOBAL, 0, 0, 0, 1);
1753 safte_get_encstat(ses_softc_t *ssc, int slpflg)
1755 return (safte_rdstat(ssc, slpflg));
1759 safte_set_encstat(ses_softc_t *ssc, uint8_t encstat, int slpflg)
1761 struct scfg *cc = ssc->ses_private;
1765 * Since SAF-TE devices aren't necessarily sticky in terms
1766 * of state, make our soft copy of enclosure status 'sticky'-
1767 * that is, things set in enclosure status stay set (as implied
1768 * by conditions set in reading object status) until cleared.
1770 ssc->ses_encstat &= ~ALL_ENC_STAT;
1771 ssc->ses_encstat |= (encstat & ALL_ENC_STAT);
1772 ssc->ses_encstat |= ENCI_SVALID;
1773 cc->flag1 &= ~(SAFT_FLG1_ALARM|SAFT_FLG1_GLOBFAIL|SAFT_FLG1_GLOBWARN);
1774 if ((encstat & (SES_ENCSTAT_CRITICAL|SES_ENCSTAT_UNRECOV)) != 0) {
1775 cc->flag1 |= SAFT_FLG1_ALARM|SAFT_FLG1_GLOBFAIL;
1776 } else if ((encstat & SES_ENCSTAT_NONCRITICAL) != 0) {
1777 cc->flag1 |= SAFT_FLG1_GLOBWARN;
1779 return (wrbuf16(ssc, SAFTE_WT_GLOBAL, cc->flag1, cc->flag2, 0, slpflg));
1783 safte_get_objstat(ses_softc_t *ssc, ses_objstat *obp, int slpflg)
1785 int i = (int)obp->obj_id;
1787 if ((ssc->ses_encstat & ENCI_SVALID) == 0 ||
1788 (ssc->ses_objmap[i].svalid) == 0) {
1789 int err = safte_rdstat(ssc, slpflg);
1793 obp->cstat[0] = ssc->ses_objmap[i].encstat[0];
1794 obp->cstat[1] = ssc->ses_objmap[i].encstat[1];
1795 obp->cstat[2] = ssc->ses_objmap[i].encstat[2];
1796 obp->cstat[3] = ssc->ses_objmap[i].encstat[3];
1802 safte_set_objstat(ses_softc_t *ssc, ses_objstat *obp, int slp)
1809 SES_DLOG(ssc, "safte_set_objstat(%d): %x %x %x %x\n",
1810 (int)obp->obj_id, obp->cstat[0], obp->cstat[1], obp->cstat[2],
1814 * If this is clear, we don't do diddly.
1816 if ((obp->cstat[0] & SESCTL_CSEL) == 0) {
1822 * Check to see if the common bits are set and do them first.
1824 if (obp->cstat[0] & ~SESCTL_CSEL) {
1825 err = set_objstat_sel(ssc, obp, slp);
1830 cc = ssc->ses_private;
1834 idx = (int)obp->obj_id;
1835 ep = &ssc->ses_objmap[idx];
1837 switch (ep->enctype) {
1842 * XXX: I should probably cache the previous state
1843 * XXX: of SESCTL_DEVOFF so that when it goes from
1844 * XXX: true to false I can then set PREPARE FOR OPERATION
1845 * XXX: flag in PERFORM SLOT OPERATION write buffer command.
1847 if (obp->cstat[2] & (SESCTL_RQSINS|SESCTL_RQSRMV)) {
1850 if (obp->cstat[2] & SESCTL_RQSID) {
1853 err = perf_slotop(ssc, (uint8_t) idx - (uint8_t) cc->slotoff,
1857 if (obp->cstat[3] & SESCTL_RQSFLT) {
1862 if (ep->priv & 0xc6) {
1865 ep->priv |= 0x1; /* no errors */
1867 wrslot_stat(ssc, slp);
1871 if (obp->cstat[3] & SESCTL_RQSTFAIL) {
1872 cc->flag1 |= SAFT_FLG1_ENCPWRFAIL;
1874 cc->flag1 &= ~SAFT_FLG1_ENCPWRFAIL;
1876 err = wrbuf16(ssc, SAFTE_WT_GLOBAL, cc->flag1,
1880 if (obp->cstat[3] & SESCTL_RQSTON) {
1881 (void) wrbuf16(ssc, SAFTE_WT_ACTPWS,
1882 idx - cc->pwroff, 0, 0, slp);
1884 (void) wrbuf16(ssc, SAFTE_WT_ACTPWS,
1885 idx - cc->pwroff, 0, 1, slp);
1889 if (obp->cstat[3] & SESCTL_RQSTFAIL) {
1890 cc->flag1 |= SAFT_FLG1_ENCFANFAIL;
1892 cc->flag1 &= ~SAFT_FLG1_ENCFANFAIL;
1894 err = wrbuf16(ssc, SAFTE_WT_GLOBAL, cc->flag1,
1898 if (obp->cstat[3] & SESCTL_RQSTON) {
1900 if ((obp->cstat[3] & 0x7) == 7) {
1902 } else if ((obp->cstat[3] & 0x7) == 6) {
1904 } else if ((obp->cstat[3] & 0x7) == 4) {
1909 (void) wrbuf16(ssc, SAFTE_WT_FANSPD, idx, fsp, 0, slp);
1911 (void) wrbuf16(ssc, SAFTE_WT_FANSPD, idx, 0, 0, slp);
1914 case SESTYP_DOORLOCK:
1915 if (obp->cstat[3] & 0x1) {
1916 cc->flag2 &= ~SAFT_FLG2_LOCKDOOR;
1918 cc->flag2 |= SAFT_FLG2_LOCKDOOR;
1920 (void) wrbuf16(ssc, SAFTE_WT_GLOBAL, cc->flag1,
1925 * On all nonzero but the 'muted' bit, we turn on the alarm,
1927 obp->cstat[3] &= ~0xa;
1928 if (obp->cstat[3] & 0x40) {
1929 cc->flag2 &= ~SAFT_FLG1_ALARM;
1930 } else if (obp->cstat[3] != 0) {
1931 cc->flag2 |= SAFT_FLG1_ALARM;
1933 cc->flag2 &= ~SAFT_FLG1_ALARM;
1935 ep->priv = obp->cstat[3];
1936 (void) wrbuf16(ssc, SAFTE_WT_GLOBAL, cc->flag1,
1947 safte_getconfig(ses_softc_t *ssc)
1952 static char cdb[10] =
1953 { READ_BUFFER, 1, SAFTE_RD_RDCFG, 0, 0, 0, 0, 0, SAFT_SCRATCH, 0 };
1955 cfg = ssc->ses_private;
1959 sdata = SES_MALLOC(SAFT_SCRATCH);
1964 err = ses_runcmd(ssc, cdb, 10, sdata, &amt);
1966 SES_FREE(sdata, SAFT_SCRATCH);
1969 amt = SAFT_SCRATCH - amt;
1971 SES_LOG(ssc, "too little data (%d) for configuration\n", amt);
1972 SES_FREE(sdata, SAFT_SCRATCH);
1975 SES_VLOG(ssc, "Nfans %d Npwr %d Nslots %d Lck %d Ntherm %d Nspkrs %d\n",
1976 sdata[0], sdata[1], sdata[2], sdata[3], sdata[4], sdata[5]);
1977 cfg->Nfans = sdata[0];
1978 cfg->Npwr = sdata[1];
1979 cfg->Nslots = sdata[2];
1980 cfg->DoorLock = sdata[3];
1981 cfg->Ntherm = sdata[4];
1982 cfg->Nspkrs = sdata[5];
1983 cfg->Nalarm = NPSEUDO_ALARM;
1984 SES_FREE(sdata, SAFT_SCRATCH);
1989 safte_rdstat(ses_softc_t *ssc, int slpflg)
1991 int err, oid, r, i, hiwater, nitems, amt;
1994 uint8_t status, oencstat;
1995 char *sdata, cdb[10];
1996 struct scfg *cc = ssc->ses_private;
2000 * The number of objects overstates things a bit,
2001 * both for the bogus 'thermometer' entries and
2002 * the drive status (which isn't read at the same
2003 * time as the enclosure status), but that's okay.
2005 buflen = 4 * cc->Nslots;
2006 if (ssc->ses_nobjects > buflen)
2007 buflen = ssc->ses_nobjects;
2008 sdata = SES_MALLOC(buflen);
2012 cdb[0] = READ_BUFFER;
2014 cdb[2] = SAFTE_RD_RDESTS;
2019 cdb[7] = (buflen >> 8) & 0xff;
2020 cdb[8] = buflen & 0xff;
2023 err = ses_runcmd(ssc, cdb, 10, sdata, &amt);
2025 SES_FREE(sdata, buflen);
2028 hiwater = buflen - amt;
2032 * invalidate all status bits.
2034 for (i = 0; i < ssc->ses_nobjects; i++)
2035 ssc->ses_objmap[i].svalid = 0;
2036 oencstat = ssc->ses_encstat & ALL_ENC_STAT;
2037 ssc->ses_encstat = 0;
2041 * Now parse returned buffer.
2042 * If we didn't get enough data back,
2043 * that's considered a fatal error.
2047 for (nitems = i = 0; i < cc->Nfans; i++) {
2048 SAFT_BAIL(r, hiwater, sdata, buflen);
2050 * 0 = Fan Operational
2051 * 1 = Fan is malfunctioning
2052 * 2 = Fan is not present
2053 * 0x80 = Unknown or Not Reportable Status
2055 ssc->ses_objmap[oid].encstat[1] = 0; /* resvd */
2056 ssc->ses_objmap[oid].encstat[2] = 0; /* resvd */
2057 switch ((int)(uint8_t)sdata[r]) {
2060 ssc->ses_objmap[oid].encstat[0] = SES_OBJSTAT_OK;
2062 * We could get fancier and cache
2063 * fan speeds that we have set, but
2064 * that isn't done now.
2066 ssc->ses_objmap[oid].encstat[3] = 7;
2070 ssc->ses_objmap[oid].encstat[0] = SES_OBJSTAT_CRIT;
2072 * FAIL and FAN STOPPED synthesized
2074 ssc->ses_objmap[oid].encstat[3] = 0x40;
2076 * Enclosure marked with CRITICAL error
2077 * if only one fan or no thermometers,
2078 * else the NONCRITICAL error is set.
2080 if (cc->Nfans == 1 || cc->Ntherm == 0)
2081 ssc->ses_encstat |= SES_ENCSTAT_CRITICAL;
2083 ssc->ses_encstat |= SES_ENCSTAT_NONCRITICAL;
2086 ssc->ses_objmap[oid].encstat[0] =
2087 SES_OBJSTAT_NOTINSTALLED;
2088 ssc->ses_objmap[oid].encstat[3] = 0;
2090 * Enclosure marked with CRITICAL error
2091 * if only one fan or no thermometers,
2092 * else the NONCRITICAL error is set.
2095 ssc->ses_encstat |= SES_ENCSTAT_CRITICAL;
2097 ssc->ses_encstat |= SES_ENCSTAT_NONCRITICAL;
2100 ssc->ses_objmap[oid].encstat[0] = SES_OBJSTAT_UNKNOWN;
2101 ssc->ses_objmap[oid].encstat[3] = 0;
2102 ssc->ses_encstat |= SES_ENCSTAT_INFO;
2105 ssc->ses_objmap[oid].encstat[0] =
2106 SES_OBJSTAT_UNSUPPORTED;
2107 SES_LOG(ssc, "Unknown fan%d status 0x%x\n", i,
2111 ssc->ses_objmap[oid++].svalid = 1;
2116 * No matter how you cut it, no cooling elements when there
2117 * should be some there is critical.
2119 if (cc->Nfans && nitems == 0) {
2120 ssc->ses_encstat |= SES_ENCSTAT_CRITICAL;
2124 for (i = 0; i < cc->Npwr; i++) {
2125 SAFT_BAIL(r, hiwater, sdata, buflen);
2126 ssc->ses_objmap[oid].encstat[0] = SES_OBJSTAT_UNKNOWN;
2127 ssc->ses_objmap[oid].encstat[1] = 0; /* resvd */
2128 ssc->ses_objmap[oid].encstat[2] = 0; /* resvd */
2129 ssc->ses_objmap[oid].encstat[3] = 0x20; /* requested on */
2130 switch ((uint8_t)sdata[r]) {
2131 case 0x00: /* pws operational and on */
2132 ssc->ses_objmap[oid].encstat[0] = SES_OBJSTAT_OK;
2134 case 0x01: /* pws operational and off */
2135 ssc->ses_objmap[oid].encstat[0] = SES_OBJSTAT_OK;
2136 ssc->ses_objmap[oid].encstat[3] = 0x10;
2137 ssc->ses_encstat |= SES_ENCSTAT_INFO;
2139 case 0x10: /* pws is malfunctioning and commanded on */
2140 ssc->ses_objmap[oid].encstat[0] = SES_OBJSTAT_CRIT;
2141 ssc->ses_objmap[oid].encstat[3] = 0x61;
2142 ssc->ses_encstat |= SES_ENCSTAT_NONCRITICAL;
2145 case 0x11: /* pws is malfunctioning and commanded off */
2146 ssc->ses_objmap[oid].encstat[0] = SES_OBJSTAT_NONCRIT;
2147 ssc->ses_objmap[oid].encstat[3] = 0x51;
2148 ssc->ses_encstat |= SES_ENCSTAT_NONCRITICAL;
2150 case 0x20: /* pws is not present */
2151 ssc->ses_objmap[oid].encstat[0] =
2152 SES_OBJSTAT_NOTINSTALLED;
2153 ssc->ses_objmap[oid].encstat[3] = 0;
2154 ssc->ses_encstat |= SES_ENCSTAT_INFO;
2156 case 0x21: /* pws is present */
2158 * This is for enclosures that cannot tell whether the
2159 * device is on or malfunctioning, but know that it is
2160 * present. Just fall through.
2163 case 0x80: /* Unknown or Not Reportable Status */
2164 ssc->ses_objmap[oid].encstat[0] = SES_OBJSTAT_UNKNOWN;
2165 ssc->ses_objmap[oid].encstat[3] = 0;
2166 ssc->ses_encstat |= SES_ENCSTAT_INFO;
2169 SES_LOG(ssc, "unknown power supply %d status (0x%x)\n",
2170 i, sdata[r] & 0xff);
2173 ssc->ses_objmap[oid++].svalid = 1;
2178 * Skip over Slot SCSI IDs
2183 * We always have doorlock status, no matter what,
2184 * but we only save the status if we have one.
2186 SAFT_BAIL(r, hiwater, sdata, buflen);
2190 * 1 = Door Unlocked, or no Lock Installed
2191 * 0x80 = Unknown or Not Reportable Status
2193 ssc->ses_objmap[oid].encstat[1] = 0;
2194 ssc->ses_objmap[oid].encstat[2] = 0;
2195 switch ((uint8_t)sdata[r]) {
2197 ssc->ses_objmap[oid].encstat[0] = SES_OBJSTAT_OK;
2198 ssc->ses_objmap[oid].encstat[3] = 0;
2201 ssc->ses_objmap[oid].encstat[0] = SES_OBJSTAT_OK;
2202 ssc->ses_objmap[oid].encstat[3] = 1;
2205 ssc->ses_objmap[oid].encstat[0] = SES_OBJSTAT_UNKNOWN;
2206 ssc->ses_objmap[oid].encstat[3] = 0;
2207 ssc->ses_encstat |= SES_ENCSTAT_INFO;
2210 ssc->ses_objmap[oid].encstat[0] =
2211 SES_OBJSTAT_UNSUPPORTED;
2212 SES_LOG(ssc, "unknown lock status 0x%x\n",
2216 ssc->ses_objmap[oid++].svalid = 1;
2221 * We always have speaker status, no matter what,
2222 * but we only save the status if we have one.
2224 SAFT_BAIL(r, hiwater, sdata, buflen);
2226 ssc->ses_objmap[oid].encstat[1] = 0;
2227 ssc->ses_objmap[oid].encstat[2] = 0;
2228 if (sdata[r] == 1) {
2230 * We need to cache tone urgency indicators.
2233 ssc->ses_objmap[oid].encstat[0] = SES_OBJSTAT_NONCRIT;
2234 ssc->ses_objmap[oid].encstat[3] = 0x8;
2235 ssc->ses_encstat |= SES_ENCSTAT_NONCRITICAL;
2236 } else if (sdata[r] == 0) {
2237 ssc->ses_objmap[oid].encstat[0] = SES_OBJSTAT_OK;
2238 ssc->ses_objmap[oid].encstat[3] = 0;
2240 ssc->ses_objmap[oid].encstat[0] =
2241 SES_OBJSTAT_UNSUPPORTED;
2242 ssc->ses_objmap[oid].encstat[3] = 0;
2243 SES_LOG(ssc, "unknown spkr status 0x%x\n",
2246 ssc->ses_objmap[oid++].svalid = 1;
2250 for (i = 0; i < cc->Ntherm; i++) {
2251 SAFT_BAIL(r, hiwater, sdata, buflen);
2253 * Status is a range from -10 to 245 deg Celsius,
2254 * which we need to normalize to -20 to -245 according
2255 * to the latest SCSI spec, which makes little
2256 * sense since this would overflow an 8bit value.
2257 * Well, still, the base normalization is -20,
2258 * not -10, so we have to adjust.
2260 * So what's over and under temperature?
2261 * Hmm- we'll state that 'normal' operating
2262 * is 10 to 40 deg Celsius.
2266 * Actually.... All of the units that people out in the world
2267 * seem to have do not come even close to setting a value that
2268 * complies with this spec.
2270 * The closest explanation I could find was in an
2271 * LSI-Logic manual, which seemed to indicate that
2272 * this value would be set by whatever the I2C code
2273 * would interpolate from the output of an LM75
2274 * temperature sensor.
2276 * This means that it is impossible to use the actual
2277 * numeric value to predict anything. But we don't want
2278 * to lose the value. So, we'll propagate the *uncorrected*
2279 * value and set SES_OBJSTAT_NOTAVAIL. We'll depend on the
2280 * temperature flags for warnings.
2282 ssc->ses_objmap[oid].encstat[0] = SES_OBJSTAT_NOTAVAIL;
2283 ssc->ses_objmap[oid].encstat[1] = 0;
2284 ssc->ses_objmap[oid].encstat[2] = sdata[r];
2285 ssc->ses_objmap[oid].encstat[3] = 0;;
2286 ssc->ses_objmap[oid++].svalid = 1;
2291 * Now, for "pseudo" thermometers, we have two bytes
2292 * of information in enclosure status- 16 bits. Actually,
2293 * the MSB is a single TEMP ALERT flag indicating whether
2294 * any other bits are set, but, thanks to fuzzy thinking,
2295 * in the SAF-TE spec, this can also be set even if no
2296 * other bits are set, thus making this really another
2297 * binary temperature sensor.
2300 SAFT_BAIL(r, hiwater, sdata, buflen);
2301 tempflags = sdata[r++];
2302 SAFT_BAIL(r, hiwater, sdata, buflen);
2303 tempflags |= (tempflags << 8) | sdata[r++];
2305 for (i = 0; i < NPSEUDO_THERM; i++) {
2306 ssc->ses_objmap[oid].encstat[1] = 0;
2307 if (tempflags & (1 << (NPSEUDO_THERM - i - 1))) {
2308 ssc->ses_objmap[oid].encstat[0] = SES_OBJSTAT_CRIT;
2309 ssc->ses_objmap[4].encstat[2] = 0xff;
2311 * Set 'over temperature' failure.
2313 ssc->ses_objmap[oid].encstat[3] = 8;
2314 ssc->ses_encstat |= SES_ENCSTAT_CRITICAL;
2317 * We used to say 'not available' and synthesize a
2318 * nominal 30 deg (C)- that was wrong. Actually,
2319 * Just say 'OK', and use the reserved value of
2322 ssc->ses_objmap[oid].encstat[0] = SES_OBJSTAT_OK;
2323 ssc->ses_objmap[oid].encstat[2] = 0;
2324 ssc->ses_objmap[oid].encstat[3] = 0;
2326 ssc->ses_objmap[oid++].svalid = 1;
2332 ssc->ses_objmap[oid].encstat[0] = SES_OBJSTAT_OK;
2333 ssc->ses_objmap[oid].encstat[3] = ssc->ses_objmap[oid].priv;
2334 ssc->ses_objmap[oid++].svalid = 1;
2337 * Now get drive slot status
2339 cdb[2] = SAFTE_RD_RDDSTS;
2341 err = ses_runcmd(ssc, cdb, 10, sdata, &amt);
2343 SES_FREE(sdata, buflen);
2346 hiwater = buflen - amt;
2347 for (r = i = 0; i < cc->Nslots; i++, r += 4) {
2348 SAFT_BAIL(r+3, hiwater, sdata, buflen);
2349 ssc->ses_objmap[oid].encstat[0] = SES_OBJSTAT_UNSUPPORTED;
2350 ssc->ses_objmap[oid].encstat[1] = (uint8_t) i;
2351 ssc->ses_objmap[oid].encstat[2] = 0;
2352 ssc->ses_objmap[oid].encstat[3] = 0;
2353 status = sdata[r+3];
2354 if ((status & 0x1) == 0) { /* no device */
2355 ssc->ses_objmap[oid].encstat[0] =
2356 SES_OBJSTAT_NOTINSTALLED;
2358 ssc->ses_objmap[oid].encstat[0] = SES_OBJSTAT_OK;
2361 ssc->ses_objmap[oid].encstat[2] = 0x8;
2363 if ((status & 0x4) == 0) {
2364 ssc->ses_objmap[oid].encstat[3] = 0x10;
2366 ssc->ses_objmap[oid++].svalid = 1;
2368 /* see comment below about sticky enclosure status */
2369 ssc->ses_encstat |= ENCI_SVALID | oencstat;
2370 SES_FREE(sdata, buflen);
2375 set_objstat_sel(ses_softc_t *ssc, ses_objstat *obp, int slp)
2379 struct scfg *cc = ssc->ses_private;
2384 idx = (int)obp->obj_id;
2385 ep = &ssc->ses_objmap[idx];
2387 switch (ep->enctype) {
2389 if (obp->cstat[0] & SESCTL_PRDFAIL) {
2392 /* SESCTL_RSTSWAP has no correspondence in SAF-TE */
2393 if (obp->cstat[0] & SESCTL_DISABLE) {
2396 * Hmm. Try to set the 'No Drive' flag.
2397 * Maybe that will count as a 'disable'.
2400 if (ep->priv & 0xc6) {
2403 ep->priv |= 0x1; /* no errors */
2405 wrslot_stat(ssc, slp);
2409 * Okay- the only one that makes sense here is to
2410 * do the 'disable' for a power supply.
2412 if (obp->cstat[0] & SESCTL_DISABLE) {
2413 (void) wrbuf16(ssc, SAFTE_WT_ACTPWS,
2414 idx - cc->pwroff, 0, 0, slp);
2419 * Okay- the only one that makes sense here is to
2420 * set fan speed to zero on disable.
2422 if (obp->cstat[0] & SESCTL_DISABLE) {
2423 /* remember- fans are the first items, so idx works */
2424 (void) wrbuf16(ssc, SAFTE_WT_FANSPD, idx, 0, 0, slp);
2427 case SESTYP_DOORLOCK:
2429 * Well, we can 'disable' the lock.
2431 if (obp->cstat[0] & SESCTL_DISABLE) {
2432 cc->flag2 &= ~SAFT_FLG2_LOCKDOOR;
2433 (void) wrbuf16(ssc, SAFTE_WT_GLOBAL, cc->flag1,
2439 * Well, we can 'disable' the alarm.
2441 if (obp->cstat[0] & SESCTL_DISABLE) {
2442 cc->flag2 &= ~SAFT_FLG1_ALARM;
2443 ep->priv |= 0x40; /* Muted */
2444 (void) wrbuf16(ssc, SAFTE_WT_GLOBAL, cc->flag1,
2456 * This function handles all of the 16 byte WRITE BUFFER commands.
2459 wrbuf16(ses_softc_t *ssc, uint8_t op, uint8_t b1, uint8_t b2,
2460 uint8_t b3, int slp)
2464 struct scfg *cc = ssc->ses_private;
2465 static char cdb[10] = { WRITE_BUFFER, 1, 0, 0, 0, 0, 0, 0, 16, 0 };
2470 sdata = SES_MALLOC(16);
2474 SES_DLOG(ssc, "saf_wrbuf16 %x %x %x %x\n", op, b1, b2, b3);
2480 MEMZERO(&sdata[4], 12);
2482 err = ses_runcmd(ssc, cdb, 10, sdata, &amt);
2483 SES_FREE(sdata, 16);
2488 * This function updates the status byte for the device slot described.
2490 * Since this is an optional SAF-TE command, there's no point in
2491 * returning an error.
2494 wrslot_stat(ses_softc_t *ssc, int slp)
2498 char cdb[10], *sdata;
2499 struct scfg *cc = ssc->ses_private;
2504 SES_DLOG(ssc, "saf_wrslot\n");
2505 cdb[0] = WRITE_BUFFER;
2513 cdb[8] = cc->Nslots * 3 + 1;
2516 sdata = SES_MALLOC(cc->Nslots * 3 + 1);
2519 MEMZERO(sdata, cc->Nslots * 3 + 1);
2521 sdata[0] = SAFTE_WT_DSTAT;
2522 for (i = 0; i < cc->Nslots; i++) {
2523 ep = &ssc->ses_objmap[cc->slotoff + i];
2524 SES_DLOG(ssc, "saf_wrslot %d <- %x\n", i, ep->priv & 0xff);
2525 sdata[1 + (3 * i)] = ep->priv & 0xff;
2527 amt = -(cc->Nslots * 3 + 1);
2528 (void) ses_runcmd(ssc, cdb, 10, sdata, &amt);
2529 SES_FREE(sdata, cc->Nslots * 3 + 1);
2533 * This function issues the "PERFORM SLOT OPERATION" command.
2536 perf_slotop(ses_softc_t *ssc, uint8_t slot, uint8_t opflag, int slp)
2540 struct scfg *cc = ssc->ses_private;
2541 static char cdb[10] =
2542 { WRITE_BUFFER, 1, 0, 0, 0, 0, 0, 0, SAFT_SCRATCH, 0 };
2547 sdata = SES_MALLOC(SAFT_SCRATCH);
2550 MEMZERO(sdata, SAFT_SCRATCH);
2552 sdata[0] = SAFTE_WT_SLTOP;
2555 SES_DLOG(ssc, "saf_slotop slot %d op %x\n", slot, opflag);
2556 amt = -SAFT_SCRATCH;
2557 err = ses_runcmd(ssc, cdb, 10, sdata, &amt);
2558 SES_FREE(sdata, SAFT_SCRATCH);