1 /* $FreeBSD: src/sys/cam/scsi/scsi_ses.c,v 1.8.2.2 2000/08/08 23:19:21 mjacob Exp $ */
3 * Copyright (c) 2000 Matthew Jacob
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions, and the following disclaimer,
11 * without modification, immediately at the beginning of the file.
12 * 2. The name of the author may not be used to endorse or promote products
13 * derived from this software without specific prior written permission.
15 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
16 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR
19 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
28 #include <sys/param.h>
29 #include <sys/queue.h>
30 #include <sys/systm.h>
31 #include <sys/kernel.h>
32 #include <sys/types.h>
33 #include <sys/malloc.h>
34 #include <sys/fcntl.h>
38 #include <sys/errno.h>
39 #include <sys/devicestat.h>
40 #include <machine/stdarg.h>
43 #include <cam/cam_ccb.h>
44 #include <cam/cam_extend.h>
45 #include <cam/cam_periph.h>
46 #include <cam/cam_xpt_periph.h>
47 #include <cam/cam_queue.h>
48 #include <cam/cam_debug.h>
50 #include <cam/scsi/scsi_all.h>
51 #include <cam/scsi/scsi_message.h>
52 #include <sys/ioccom.h>
53 #include <cam/scsi/scsi_ses.h>
58 * Platform Independent Driver Internal Definitions for SES devices.
70 typedef struct ses_softc ses_softc_t;
72 int (*softc_init)(ses_softc_t *, int);
73 int (*init_enc)(ses_softc_t *);
74 int (*get_encstat)(ses_softc_t *, int);
75 int (*set_encstat)(ses_softc_t *, ses_encstat, int);
76 int (*get_objstat)(ses_softc_t *, ses_objstat *, int);
77 int (*set_objstat)(ses_softc_t *, ses_objstat *, int);
80 #define ENCI_SVALID 0x80
84 enctype : 8, /* enclosure type */
85 subenclosure : 8, /* subenclosure id */
86 svalid : 1, /* enclosure information valid */
87 priv : 15; /* private data, per object */
88 uint8_t encstat[4]; /* state && stats */
91 #define SEN_ID "UNISYS SUN_SEN"
95 static enctyp ses_type(void *, int);
98 /* Forward reference to Enclosure Functions */
99 static int ses_softc_init(ses_softc_t *, int);
100 static int ses_init_enc(ses_softc_t *);
101 static int ses_get_encstat(ses_softc_t *, int);
102 static int ses_set_encstat(ses_softc_t *, uint8_t, int);
103 static int ses_get_objstat(ses_softc_t *, ses_objstat *, int);
104 static int ses_set_objstat(ses_softc_t *, ses_objstat *, int);
106 static int safte_softc_init(ses_softc_t *, int);
107 static int safte_init_enc(ses_softc_t *);
108 static int safte_get_encstat(ses_softc_t *, int);
109 static int safte_set_encstat(ses_softc_t *, uint8_t, int);
110 static int safte_get_objstat(ses_softc_t *, ses_objstat *, int);
111 static int safte_set_objstat(ses_softc_t *, ses_objstat *, int);
114 * Platform implementation defines/functions for SES internal kernel stuff
117 #define STRNCMP strncmp
118 #define PRINTF printf
119 #define SES_LOG ses_log
121 #define SES_DLOG ses_log
123 #define SES_DLOG if (0) ses_log
125 #define SES_VLOG if (bootverbose) ses_log
126 #define SES_MALLOC(amt) malloc(amt, M_DEVBUF, M_NOWAIT)
127 #define SES_FREE(ptr, amt) free(ptr, M_DEVBUF)
128 #define MEMZERO bzero
129 #define MEMCPY(dest, src, amt) bcopy(src, dest, amt)
131 static int ses_runcmd(struct ses_softc *, char *, int, char *, int *);
132 static void ses_log(struct ses_softc *, const char *, ...);
135 * Gerenal FreeBSD kernel stuff.
139 #define ccb_state ppriv_field0
140 #define ccb_bp ppriv_ptr1
143 enctyp ses_type; /* type of enclosure */
144 encvec ses_vec; /* vector to handlers */
145 void * ses_private; /* per-type private data */
146 encobj * ses_objmap; /* objects */
147 u_int32_t ses_nobjects; /* number of objects */
148 ses_encstat ses_encstat; /* overall status */
150 union ccb ses_saved_ccb;
152 struct cam_periph *periph;
154 #define SES_FLAG_INVALID 0x01
155 #define SES_FLAG_OPEN 0x02
156 #define SES_FLAG_INITIALIZED 0x04
158 #define SESUNIT(x) (minor((x)))
159 #define SES_CDEV_MAJOR 110
161 static d_open_t sesopen;
162 static d_close_t sesclose;
163 static d_ioctl_t sesioctl;
164 static periph_init_t sesinit;
165 static periph_ctor_t sesregister;
166 static periph_oninv_t sesoninvalidate;
167 static periph_dtor_t sescleanup;
168 static periph_start_t sesstart;
170 static void sesasync(void *, u_int32_t, struct cam_path *, void *);
171 static void sesdone(struct cam_periph *, union ccb *);
172 static int seserror(union ccb *, u_int32_t, u_int32_t);
174 static struct periph_driver sesdriver = {
176 TAILQ_HEAD_INITIALIZER(sesdriver.units), /* generation */ 0
179 DATA_SET(periphdriver_set, sesdriver);
181 static struct cdevsw ses_cdevsw =
184 /* close */ sesclose,
187 /* ioctl */ sesioctl,
190 /* strategy */ nostrategy,
192 /* maj */ SES_CDEV_MAJOR,
198 static struct extend_array *sesperiphs;
204 struct cam_path *path;
207 * Create our extend array for storing the devices we attach to.
209 sesperiphs = cam_extend_new();
210 if (sesperiphs == NULL) {
211 printf("ses: Failed to alloc extend array!\n");
216 * Install a global async callback. This callback will
217 * receive async callbacks like "new device found".
219 status = xpt_create_path(&path, NULL, CAM_XPT_PATH_ID,
220 CAM_TARGET_WILDCARD, CAM_LUN_WILDCARD);
222 if (status == CAM_REQ_CMP) {
223 struct ccb_setasync csa;
225 xpt_setup_ccb(&csa.ccb_h, path, 5);
226 csa.ccb_h.func_code = XPT_SASYNC_CB;
227 csa.event_enable = AC_FOUND_DEVICE;
228 csa.callback = sesasync;
229 csa.callback_arg = NULL;
230 xpt_action((union ccb *)&csa);
231 status = csa.ccb_h.status;
235 if (status != CAM_REQ_CMP) {
236 printf("ses: Failed to attach master async callback "
237 "due to status 0x%x!\n", status);
242 sesoninvalidate(struct cam_periph *periph)
244 struct ses_softc *softc;
245 struct ccb_setasync csa;
247 softc = (struct ses_softc *)periph->softc;
250 * Unregister any async callbacks.
252 xpt_setup_ccb(&csa.ccb_h, periph->path, 5);
253 csa.ccb_h.func_code = XPT_SASYNC_CB;
254 csa.event_enable = 0;
255 csa.callback = sesasync;
256 csa.callback_arg = periph;
257 xpt_action((union ccb *)&csa);
259 softc->ses_flags |= SES_FLAG_INVALID;
261 xpt_print_path(periph->path);
262 printf("lost device\n");
266 sescleanup(struct cam_periph *periph)
268 struct ses_softc *softc;
270 softc = (struct ses_softc *)periph->softc;
272 destroy_dev(softc->ses_dev);
274 cam_extend_release(sesperiphs, periph->unit_number);
275 xpt_print_path(periph->path);
276 printf("removing device entry\n");
277 free(softc, M_DEVBUF);
281 sesasync(void *callback_arg, u_int32_t code, struct cam_path *path, void *arg)
283 struct cam_periph *periph;
285 periph = (struct cam_periph *)callback_arg;
288 case AC_FOUND_DEVICE:
291 struct ccb_getdev *cgd;
293 cgd = (struct ccb_getdev *)arg;
296 * PROBLEM: WE NEED TO LOOK AT BYTES 48-53 TO SEE IF THIS IS
297 * PROBLEM: IS A SAF-TE DEVICE.
299 switch (ses_type(&cgd->inq_data, cgd->inq_len)) {
302 case SES_SES_PASSTHROUGH:
310 status = cam_periph_alloc(sesregister, sesoninvalidate,
311 sescleanup, sesstart, "ses", CAM_PERIPH_BIO,
312 cgd->ccb_h.path, sesasync, AC_FOUND_DEVICE, cgd);
314 if (status != CAM_REQ_CMP && status != CAM_REQ_INPROG) {
315 printf("sesasync: Unable to probe new device due to "
316 "status 0x%x\n", status);
321 cam_periph_async(periph, code, path, arg);
327 sesregister(struct cam_periph *periph, void *arg)
329 struct ses_softc *softc;
330 struct ccb_setasync csa;
331 struct ccb_getdev *cgd;
334 cgd = (struct ccb_getdev *)arg;
335 if (periph == NULL) {
336 printf("sesregister: periph was NULL!!\n");
337 return (CAM_REQ_CMP_ERR);
341 printf("sesregister: no getdev CCB, can't register device\n");
342 return (CAM_REQ_CMP_ERR);
345 softc = malloc(sizeof (struct ses_softc), M_DEVBUF, M_NOWAIT);
347 printf("sesregister: Unable to probe new device. "
348 "Unable to allocate softc\n");
349 return (CAM_REQ_CMP_ERR);
351 bzero(softc, sizeof (struct ses_softc));
352 periph->softc = softc;
353 softc->periph = periph;
355 softc->ses_type = ses_type(&cgd->inq_data, sizeof (cgd->inq_data));
357 switch (softc->ses_type) {
360 case SES_SES_PASSTHROUGH:
361 softc->ses_vec.softc_init = ses_softc_init;
362 softc->ses_vec.init_enc = ses_init_enc;
363 softc->ses_vec.get_encstat = ses_get_encstat;
364 softc->ses_vec.set_encstat = ses_set_encstat;
365 softc->ses_vec.get_objstat = ses_get_objstat;
366 softc->ses_vec.set_objstat = ses_set_objstat;
369 softc->ses_vec.softc_init = safte_softc_init;
370 softc->ses_vec.init_enc = safte_init_enc;
371 softc->ses_vec.get_encstat = safte_get_encstat;
372 softc->ses_vec.set_encstat = safte_set_encstat;
373 softc->ses_vec.get_objstat = safte_get_objstat;
374 softc->ses_vec.set_objstat = safte_set_objstat;
380 free(softc, M_DEVBUF);
381 return (CAM_REQ_CMP_ERR);
384 cam_extend_set(sesperiphs, periph->unit_number, periph);
386 softc->ses_dev = make_dev(&ses_cdevsw, periph->unit_number,
387 UID_ROOT, GID_OPERATOR, 0600, "%s%d",
388 periph->periph_name, periph->unit_number);
391 * Add an async callback so that we get
392 * notified if this device goes away.
394 xpt_setup_ccb(&csa.ccb_h, periph->path, 5);
395 csa.ccb_h.func_code = XPT_SASYNC_CB;
396 csa.event_enable = AC_LOST_DEVICE;
397 csa.callback = sesasync;
398 csa.callback_arg = periph;
399 xpt_action((union ccb *)&csa);
401 switch (softc->ses_type) {
404 tname = "No SES device";
407 tname = "SCSI-2 SES Device";
410 tname = "SCSI-3 SES Device";
412 case SES_SES_PASSTHROUGH:
413 tname = "SES Passthrough Device";
416 tname = "UNISYS SEN Device (NOT HANDLED YET)";
419 tname = "SAF-TE Compliant Device";
422 xpt_announce_periph(periph, tname);
423 return (CAM_REQ_CMP);
427 sesopen(dev_t dev, int flags, int fmt, struct proc *p)
429 struct cam_periph *periph;
430 struct ses_softc *softc;
434 periph = cam_extend_get(sesperiphs, SESUNIT(dev));
435 if (periph == NULL) {
439 if ((error = cam_periph_lock(periph, PRIBIO | PCATCH)) != 0) {
445 if (cam_periph_acquire(periph) != CAM_REQ_CMP) {
446 cam_periph_unlock(periph);
450 softc = (struct ses_softc *)periph->softc;
452 if (softc->ses_flags & SES_FLAG_INVALID) {
456 if (softc->ses_flags & SES_FLAG_OPEN) {
460 if (softc->ses_vec.softc_init == NULL) {
465 softc->ses_flags |= SES_FLAG_OPEN;
466 if ((softc->ses_flags & SES_FLAG_INITIALIZED) == 0) {
467 error = (*softc->ses_vec.softc_init)(softc, 1);
469 softc->ses_flags &= ~SES_FLAG_OPEN;
471 softc->ses_flags |= SES_FLAG_INITIALIZED;
476 cam_periph_release(periph);
478 cam_periph_unlock(periph);
483 sesclose(dev_t dev, int flag, int fmt, struct proc *p)
485 struct cam_periph *periph;
486 struct ses_softc *softc;
492 periph = cam_extend_get(sesperiphs, unit);
496 softc = (struct ses_softc *)periph->softc;
498 if ((error = cam_periph_lock(periph, PRIBIO)) != 0)
501 softc->ses_flags &= ~SES_FLAG_OPEN;
503 cam_periph_unlock(periph);
504 cam_periph_release(periph);
510 sesstart(struct cam_periph *p, union ccb *sccb)
513 if (p->immediate_priority <= p->pinfo.priority) {
514 SLIST_INSERT_HEAD(&p->ccb_list, &sccb->ccb_h, periph_links.sle);
515 p->immediate_priority = CAM_PRIORITY_NONE;
516 wakeup(&p->ccb_list);
522 sesdone(struct cam_periph *periph, union ccb *dccb)
524 wakeup(&dccb->ccb_h.cbfcnp);
528 seserror(union ccb *ccb, u_int32_t cflags, u_int32_t sflags)
530 struct ses_softc *softc;
531 struct cam_periph *periph;
533 periph = xpt_path_periph(ccb->ccb_h.path);
534 softc = (struct ses_softc *)periph->softc;
536 return (cam_periph_error(ccb, cflags, sflags, &softc->ses_saved_ccb));
540 sesioctl(dev_t dev, u_long cmd, caddr_t arg_addr, int flag, struct proc *p)
542 struct cam_periph *periph;
545 ses_object obj, *uobj;
546 struct ses_softc *ssc;
552 addr = *((caddr_t *) arg_addr);
556 periph = cam_extend_get(sesperiphs, SESUNIT(dev));
560 CAM_DEBUG(periph->path, CAM_DEBUG_TRACE, ("entering sesioctl\n"));
562 ssc = (struct ses_softc *)periph->softc;
565 * Now check to see whether we're initialized or not.
567 if ((ssc->ses_flags & SES_FLAG_INITIALIZED) == 0) {
573 CAM_DEBUG(periph->path, CAM_DEBUG_TRACE,
574 ("trying to do ioctl %#lx\n", cmd));
577 * If this command can change the device's state,
578 * we must have the device open for writing.
582 case SESIOC_GETOBJMAP:
583 case SESIOC_GETENCSTAT:
584 case SESIOC_GETOBJSTAT:
587 if ((flag & FWRITE) == 0) {
594 error = copyout(&ssc->ses_nobjects, addr,
595 sizeof (ssc->ses_nobjects));
598 case SESIOC_GETOBJMAP:
599 for (uobj = addr, i = 0; i != ssc->ses_nobjects; i++, uobj++) {
601 obj.subencid = ssc->ses_objmap[i].subenclosure;
602 obj.object_type = ssc->ses_objmap[i].enctype;
603 error = copyout(&obj, uobj, sizeof (ses_object));
610 case SESIOC_GETENCSTAT:
611 error = (*ssc->ses_vec.get_encstat)(ssc, 1);
614 tmp = ssc->ses_encstat & ~ENCI_SVALID;
615 error = copyout(&tmp, addr, sizeof (ses_encstat));
616 ssc->ses_encstat = tmp;
619 case SESIOC_SETENCSTAT:
620 error = copyin(addr, &tmp, sizeof (ses_encstat));
623 error = (*ssc->ses_vec.set_encstat)(ssc, tmp, 1);
626 case SESIOC_GETOBJSTAT:
627 error = copyin(addr, &objs, sizeof (ses_objstat));
630 if (objs.obj_id >= ssc->ses_nobjects) {
634 error = (*ssc->ses_vec.get_objstat)(ssc, &objs, 1);
637 error = copyout(&objs, addr, sizeof (ses_objstat));
639 * Always (for now) invalidate entry.
641 ssc->ses_objmap[objs.obj_id].svalid = 0;
644 case SESIOC_SETOBJSTAT:
645 error = copyin(addr, &objs, sizeof (ses_objstat));
649 if (objs.obj_id >= ssc->ses_nobjects) {
653 error = (*ssc->ses_vec.set_objstat)(ssc, &objs, 1);
656 * Always (for now) invalidate entry.
658 ssc->ses_objmap[objs.obj_id].svalid = 0;
663 error = (*ssc->ses_vec.init_enc)(ssc);
667 error = cam_periph_ioctl(periph, cmd, arg_addr, seserror);
673 #define SES_FLAGS SF_NO_PRINT | SF_RETRY_SELTO | SF_RETRY_UA
675 ses_runcmd(struct ses_softc *ssc, char *cdb, int cdbl, char *dptr, int *dlenp)
682 if ((dlen = *dlenp) < 0) {
693 if (cdbl > IOCDBLEN) {
697 ccb = cam_periph_getccb(ssc->periph, 1);
698 cam_fill_csio(&ccb->csio, 0, sesdone, ddf, MSG_SIMPLE_Q_TAG, dptr,
699 dlen, sizeof (struct scsi_sense_data), cdbl, 60 * 1000);
700 bcopy(cdb, ccb->csio.cdb_io.cdb_bytes, cdbl);
702 error = cam_periph_runccb(ccb, seserror, 0, SES_FLAGS, NULL);
703 if ((ccb->ccb_h.status & CAM_DEV_QFRZN) != 0)
704 cam_release_devq(ccb->ccb_h.path, 0, 0, 0, FALSE);
711 *dlenp = ccb->csio.resid;
714 xpt_release_ccb(ccb);
719 ses_log(struct ses_softc *ssc, const char *fmt, ...)
723 printf("%s%d: ", ssc->periph->periph_name, ssc->periph->unit_number);
730 * The code after this point runs on many platforms,
731 * so forgive the slightly awkward and nonconforming
736 * Is this a device that supports enclosure services?
738 * It's a a pretty simple ruleset- if it is device type 0x0D (13), it's
739 * an SES device. If it happens to be an old UNISYS SEN device, we can
743 #define SAFTE_START 44
745 #define SAFTE_LEN SAFTE_END-SAFTE_START
748 ses_type(void *buf, int buflen)
750 unsigned char *iqd = buf;
753 buflen = 256; /* per SPC-2 */
755 if (buflen < 8+SEN_ID_LEN)
758 if ((iqd[0] & 0x1f) == T_ENCLOSURE) {
759 if (STRNCMP(&iqd[8], SEN_ID, SEN_ID_LEN) == 0) {
761 } else if ((iqd[2] & 0x7) > 2) {
764 return (SES_SES_SCSI2);
769 #ifdef SES_ENABLE_PASSTHROUGH
770 if ((iqd[6] & 0x40) && (iqd[2] & 0x7) >= 2) {
772 * PassThrough Device.
774 return (SES_SES_PASSTHROUGH);
779 * The comparison is short for a reason-
780 * some vendors were chopping it short.
783 if (buflen < SAFTE_END - 2) {
787 if (STRNCMP((char *)&iqd[SAFTE_START], "SAF-TE", SAFTE_LEN - 2) == 0) {
794 * SES Native Type Device Support
798 * SES Diagnostic Page Codes
804 #define SesStatusPage SesControlPage
807 #define SesStringIn SesStringOut
809 #define SesThresholdIn SesThresholdOut
811 #define SesArrayStatus SesArrayControl
812 SesElementDescriptor,
821 * Minimum amount of data, starting from byte 0, to have
824 #define SES_CFGHDR_MINLEN 12
827 * Minimum amount of data, starting from byte 0, to have
828 * the config header and one enclosure header.
830 #define SES_ENCHDR_MINLEN 48
833 * Take this value, subtract it from VEnclen and you know
834 * the length of the vendor unique bytes.
836 #define SES_ENCHDR_VMIN 36
839 * SES Data Structures
843 uint32_t GenCode; /* Generation Code */
844 uint8_t Nsubenc; /* Number of Subenclosures */
848 uint8_t Subencid; /* SubEnclosure Identifier */
849 uint8_t Ntypes; /* # of supported types */
850 uint8_t VEnclen; /* Enclosure Descriptor Length */
854 uint8_t encWWN[8]; /* XXX- Not Right Yet */
862 uint8_t enc_type; /* type of element */
863 uint8_t enc_maxelt; /* maximum supported */
864 uint8_t enc_subenc; /* in SubEnc # N */
865 uint8_t enc_tlen; /* Type Descriptor Text Length */
879 uint8_t ses_ntypes; /* total number of types supported */
882 * We need to keep a type index as well as an
883 * object index for each object in an enclosure.
885 struct typidx *ses_typidx;
888 * We also need to keep track of the number of elements
889 * per type of element. This is needed later so that we
890 * can find precisely in the returned status data the
891 * status for the Nth element of the Kth type.
893 uint8_t * ses_eltmap;
898 * (de)canonicalization defines
900 #define sbyte(x, byte) ((((uint32_t)(x)) >> (byte * 8)) & 0xff)
901 #define sbit(x, bit) (((uint32_t)(x)) << bit)
902 #define sset8(outp, idx, sval) (((uint8_t *)(outp))[idx++]) = sbyte(sval, 0)
904 #define sset16(outp, idx, sval) \
905 (((uint8_t *)(outp))[idx++]) = sbyte(sval, 1), \
906 (((uint8_t *)(outp))[idx++]) = sbyte(sval, 0)
909 #define sset24(outp, idx, sval) \
910 (((uint8_t *)(outp))[idx++]) = sbyte(sval, 2), \
911 (((uint8_t *)(outp))[idx++]) = sbyte(sval, 1), \
912 (((uint8_t *)(outp))[idx++]) = sbyte(sval, 0)
915 #define sset32(outp, idx, sval) \
916 (((uint8_t *)(outp))[idx++]) = sbyte(sval, 3), \
917 (((uint8_t *)(outp))[idx++]) = sbyte(sval, 2), \
918 (((uint8_t *)(outp))[idx++]) = sbyte(sval, 1), \
919 (((uint8_t *)(outp))[idx++]) = sbyte(sval, 0)
921 #define gbyte(x, byte) ((((uint32_t)(x)) & 0xff) << (byte * 8))
922 #define gbit(lv, in, idx, shft, mask) lv = ((in[idx] >> shft) & mask)
923 #define sget8(inp, idx, lval) lval = (((uint8_t *)(inp))[idx++])
924 #define gget8(inp, idx, lval) lval = (((uint8_t *)(inp))[idx])
926 #define sget16(inp, idx, lval) \
927 lval = gbyte((((uint8_t *)(inp))[idx]), 1) | \
928 (((uint8_t *)(inp))[idx+1]), idx += 2
930 #define gget16(inp, idx, lval) \
931 lval = gbyte((((uint8_t *)(inp))[idx]), 1) | \
932 (((uint8_t *)(inp))[idx+1])
934 #define sget24(inp, idx, lval) \
935 lval = gbyte((((uint8_t *)(inp))[idx]), 2) | \
936 gbyte((((uint8_t *)(inp))[idx+1]), 1) | \
937 (((uint8_t *)(inp))[idx+2]), idx += 3
939 #define gget24(inp, idx, lval) \
940 lval = gbyte((((uint8_t *)(inp))[idx]), 2) | \
941 gbyte((((uint8_t *)(inp))[idx+1]), 1) | \
942 (((uint8_t *)(inp))[idx+2])
944 #define sget32(inp, idx, lval) \
945 lval = gbyte((((uint8_t *)(inp))[idx]), 3) | \
946 gbyte((((uint8_t *)(inp))[idx+1]), 2) | \
947 gbyte((((uint8_t *)(inp))[idx+2]), 1) | \
948 (((uint8_t *)(inp))[idx+3]), idx += 4
950 #define gget32(inp, idx, lval) \
951 lval = gbyte((((uint8_t *)(inp))[idx]), 3) | \
952 gbyte((((uint8_t *)(inp))[idx+1]), 2) | \
953 gbyte((((uint8_t *)(inp))[idx+2]), 1) | \
954 (((uint8_t *)(inp))[idx+3])
957 #define CFLEN (256 + SES_ENCHDR_MINLEN)
960 * Routines specific && private to SES only
963 static int ses_getconfig(ses_softc_t *);
964 static int ses_getputstat(ses_softc_t *, int, SesComStat *, int, int);
965 static int ses_cfghdr(uint8_t *, int, SesCfgHdr *);
966 static int ses_enchdr(uint8_t *, int, uint8_t, SesEncHdr *);
967 static int ses_encdesc(uint8_t *, int, uint8_t, SesEncDesc *);
968 static int ses_getthdr(uint8_t *, int, int, SesThdr *);
969 static int ses_decode(char *, int, uint8_t *, int, int, SesComStat *);
970 static int ses_encode(char *, int, uint8_t *, int, int, SesComStat *);
973 ses_softc_init(ses_softc_t *ssc, int doinit)
977 if (ssc->ses_nobjects) {
978 SES_FREE(ssc->ses_objmap,
979 ssc->ses_nobjects * sizeof (encobj));
980 ssc->ses_objmap = NULL;
982 if ((cc = ssc->ses_private) != NULL) {
983 if (cc->ses_eltmap && cc->ses_ntypes) {
984 SES_FREE(cc->ses_eltmap, cc->ses_ntypes);
985 cc->ses_eltmap = NULL;
988 if (cc->ses_typidx && ssc->ses_nobjects) {
989 SES_FREE(cc->ses_typidx,
990 ssc->ses_nobjects * sizeof (struct typidx));
991 cc->ses_typidx = NULL;
993 SES_FREE(cc, sizeof (struct sscfg));
994 ssc->ses_private = NULL;
996 ssc->ses_nobjects = 0;
999 if (ssc->ses_private == NULL) {
1000 ssc->ses_private = SES_MALLOC(sizeof (struct sscfg));
1002 if (ssc->ses_private == NULL) {
1005 ssc->ses_nobjects = 0;
1006 ssc->ses_encstat = 0;
1007 return (ses_getconfig(ssc));
1011 ses_init_enc(ses_softc_t *ssc)
1017 ses_get_encstat(ses_softc_t *ssc, int slpflag)
1022 if ((status = ses_getputstat(ssc, -1, &ComStat, slpflag, 1)) != 0) {
1025 ssc->ses_encstat = ComStat.comstatus | ENCI_SVALID;
1030 ses_set_encstat(ses_softc_t *ssc, uint8_t encstat, int slpflag)
1035 ComStat.comstatus = encstat & 0xf;
1036 if ((status = ses_getputstat(ssc, -1, &ComStat, slpflag, 0)) != 0) {
1039 ssc->ses_encstat = encstat & 0xf; /* note no SVALID set */
1044 ses_get_objstat(ses_softc_t *ssc, ses_objstat *obp, int slpflag)
1046 int i = (int)obp->obj_id;
1048 if (ssc->ses_objmap[i].svalid == 0) {
1050 int err = ses_getputstat(ssc, i, &ComStat, slpflag, 1);
1053 ssc->ses_objmap[i].encstat[0] = ComStat.comstatus;
1054 ssc->ses_objmap[i].encstat[1] = ComStat.comstat[0];
1055 ssc->ses_objmap[i].encstat[2] = ComStat.comstat[1];
1056 ssc->ses_objmap[i].encstat[3] = ComStat.comstat[2];
1057 ssc->ses_objmap[i].svalid = 1;
1059 obp->cstat[0] = ssc->ses_objmap[i].encstat[0];
1060 obp->cstat[1] = ssc->ses_objmap[i].encstat[1];
1061 obp->cstat[2] = ssc->ses_objmap[i].encstat[2];
1062 obp->cstat[3] = ssc->ses_objmap[i].encstat[3];
1067 ses_set_objstat(ses_softc_t *ssc, ses_objstat *obp, int slpflag)
1072 * If this is clear, we don't do diddly.
1074 if ((obp->cstat[0] & SESCTL_CSEL) == 0) {
1077 ComStat.comstatus = obp->cstat[0];
1078 ComStat.comstat[0] = obp->cstat[1];
1079 ComStat.comstat[1] = obp->cstat[2];
1080 ComStat.comstat[2] = obp->cstat[3];
1081 err = ses_getputstat(ssc, (int)obp->obj_id, &ComStat, slpflag, 0);
1082 ssc->ses_objmap[(int)obp->obj_id].svalid = 0;
1087 ses_getconfig(ses_softc_t *ssc)
1094 int err, amt, i, nobj, ntype, maxima;
1095 char storage[CFLEN], *sdata;
1096 static char cdb[6] = {
1097 RECEIVE_DIAGNOSTIC, 0x1, SesConfigPage, SCSZ >> 8, SCSZ & 0xff, 0
1100 cc = ssc->ses_private;
1105 sdata = SES_MALLOC(SCSZ);
1110 err = ses_runcmd(ssc, cdb, 6, sdata, &amt);
1112 SES_FREE(sdata, SCSZ);
1117 if (ses_cfghdr((uint8_t *) sdata, amt, &cf)) {
1118 SES_LOG(ssc, "Unable to parse SES Config Header\n");
1119 SES_FREE(sdata, SCSZ);
1122 if (amt < SES_ENCHDR_MINLEN) {
1123 SES_LOG(ssc, "runt enclosure length (%d)\n", amt);
1124 SES_FREE(sdata, SCSZ);
1128 SES_VLOG(ssc, "GenCode %x %d Subenclosures\n", cf.GenCode, cf.Nsubenc);
1131 * Now waltz through all the subenclosures toting up the
1132 * number of types available in each. For this, we only
1133 * really need the enclosure header. However, we get the
1134 * enclosure descriptor for debug purposes, as well
1135 * as self-consistency checking purposes.
1138 maxima = cf.Nsubenc + 1;
1139 cdp = (SesEncDesc *) storage;
1140 for (ntype = i = 0; i < maxima; i++) {
1141 MEMZERO((caddr_t)cdp, sizeof (*cdp));
1142 if (ses_enchdr((uint8_t *) sdata, amt, i, &hd)) {
1143 SES_LOG(ssc, "Cannot Extract Enclosure Header %d\n", i);
1144 SES_FREE(sdata, SCSZ);
1147 SES_VLOG(ssc, " SubEnclosure ID %d, %d Types With this ID, En"
1148 "closure Length %d\n", hd.Subencid, hd.Ntypes, hd.VEnclen);
1150 if (ses_encdesc((uint8_t *)sdata, amt, i, cdp)) {
1151 SES_LOG(ssc, "Can't get Enclosure Descriptor %d\n", i);
1152 SES_FREE(sdata, SCSZ);
1155 SES_VLOG(ssc, " WWN: %02x%02x%02x%02x%02x%02x%02x%02x\n",
1156 cdp->encWWN[0], cdp->encWWN[1], cdp->encWWN[2],
1157 cdp->encWWN[3], cdp->encWWN[4], cdp->encWWN[5],
1158 cdp->encWWN[6], cdp->encWWN[7]);
1163 * Now waltz through all the types that are available, getting
1164 * the type header so we can start adding up the number of
1165 * objects available.
1167 for (nobj = i = 0; i < ntype; i++) {
1168 if (ses_getthdr((uint8_t *)sdata, amt, i, &thdr)) {
1169 SES_LOG(ssc, "Can't get Enclosure Type Header %d\n", i);
1170 SES_FREE(sdata, SCSZ);
1173 SES_LOG(ssc, " Type Desc[%d]: Type 0x%x, MaxElt %d, In Subenc "
1174 "%d, Text Length %d\n", i, thdr.enc_type, thdr.enc_maxelt,
1175 thdr.enc_subenc, thdr.enc_tlen);
1176 nobj += thdr.enc_maxelt;
1181 * Now allocate the object array and type map.
1184 ssc->ses_objmap = SES_MALLOC(nobj * sizeof (encobj));
1185 cc->ses_typidx = SES_MALLOC(nobj * sizeof (struct typidx));
1186 cc->ses_eltmap = SES_MALLOC(ntype);
1188 if (ssc->ses_objmap == NULL || cc->ses_typidx == NULL ||
1189 cc->ses_eltmap == NULL) {
1190 if (ssc->ses_objmap) {
1191 SES_FREE(ssc->ses_objmap, (nobj * sizeof (encobj)));
1192 ssc->ses_objmap = NULL;
1194 if (cc->ses_typidx) {
1195 SES_FREE(cc->ses_typidx,
1196 (nobj * sizeof (struct typidx)));
1197 cc->ses_typidx = NULL;
1199 if (cc->ses_eltmap) {
1200 SES_FREE(cc->ses_eltmap, ntype);
1201 cc->ses_eltmap = NULL;
1203 SES_FREE(sdata, SCSZ);
1206 MEMZERO(ssc->ses_objmap, nobj * sizeof (encobj));
1207 MEMZERO(cc->ses_typidx, nobj * sizeof (struct typidx));
1208 MEMZERO(cc->ses_eltmap, ntype);
1209 cc->ses_ntypes = (uint8_t) ntype;
1210 ssc->ses_nobjects = nobj;
1213 * Now waltz through the # of types again to fill in the types
1214 * (and subenclosure ids) of the allocated objects.
1217 for (i = 0; i < ntype; i++) {
1219 if (ses_getthdr((uint8_t *)sdata, amt, i, &thdr)) {
1222 cc->ses_eltmap[i] = thdr.enc_maxelt;
1223 for (j = 0; j < thdr.enc_maxelt; j++) {
1224 cc->ses_typidx[nobj].ses_tidx = i;
1225 cc->ses_typidx[nobj].ses_oidx = j;
1226 ssc->ses_objmap[nobj].subenclosure = thdr.enc_subenc;
1227 ssc->ses_objmap[nobj++].enctype = thdr.enc_type;
1230 SES_FREE(sdata, SCSZ);
1235 ses_getputstat(ses_softc_t *ssc, int objid, SesComStat *sp, int slp, int in)
1238 int err, amt, bufsiz, tidx, oidx;
1239 char cdb[6], *sdata;
1241 cc = ssc->ses_private;
1247 * If we're just getting overall enclosure status,
1248 * we only need 2 bytes of data storage.
1250 * If we're getting anything else, we know how much
1251 * storage we need by noting that starting at offset
1252 * 8 in returned data, all object status bytes are 4
1253 * bytes long, and are stored in chunks of types(M)
1254 * and nth+1 instances of type M.
1259 bufsiz = (ssc->ses_nobjects * 4) + (cc->ses_ntypes * 4) + 8;
1261 sdata = SES_MALLOC(bufsiz);
1265 cdb[0] = RECEIVE_DIAGNOSTIC;
1267 cdb[2] = SesStatusPage;
1268 cdb[3] = bufsiz >> 8;
1269 cdb[4] = bufsiz & 0xff;
1272 err = ses_runcmd(ssc, cdb, 6, sdata, &amt);
1274 SES_FREE(sdata, bufsiz);
1283 tidx = cc->ses_typidx[objid].ses_tidx;
1284 oidx = cc->ses_typidx[objid].ses_oidx;
1287 if (ses_decode(sdata, amt, cc->ses_eltmap, tidx, oidx, sp)) {
1291 if (ses_encode(sdata, amt, cc->ses_eltmap, tidx, oidx, sp)) {
1294 cdb[0] = SEND_DIAGNOSTIC;
1297 cdb[3] = bufsiz >> 8;
1298 cdb[4] = bufsiz & 0xff;
1301 err = ses_runcmd(ssc, cdb, 6, sdata, &amt);
1304 SES_FREE(sdata, bufsiz);
1310 * Routines to parse returned SES data structures.
1311 * Architecture and compiler independent.
1315 ses_cfghdr(uint8_t *buffer, int buflen, SesCfgHdr *cfp)
1317 if (buflen < SES_CFGHDR_MINLEN) {
1320 gget8(buffer, 1, cfp->Nsubenc);
1321 gget32(buffer, 4, cfp->GenCode);
1326 ses_enchdr(uint8_t *buffer, int amt, uint8_t SubEncId, SesEncHdr *chp)
1329 for (s = 0; s < SubEncId; s++) {
1332 off += buffer[off+3] + 4;
1334 if (off + 3 > amt) {
1337 gget8(buffer, off+1, chp->Subencid);
1338 gget8(buffer, off+2, chp->Ntypes);
1339 gget8(buffer, off+3, chp->VEnclen);
1344 ses_encdesc(uint8_t *buffer, int amt, uint8_t SubEncId, SesEncDesc *cdp)
1346 int s, e, enclen, off = 8;
1347 for (s = 0; s < SubEncId; s++) {
1350 off += buffer[off+3] + 4;
1352 if (off + 3 > amt) {
1355 gget8(buffer, off+3, enclen);
1364 MEMCPY(cdp, &buffer[off], e - off);
1369 ses_getthdr(uint8_t *buffer, int amt, int nth, SesThdr *thp)
1373 if (amt < SES_CFGHDR_MINLEN) {
1376 for (s = 0; s < buffer[1]; s++) {
1379 off += buffer[off+3] + 4;
1381 if (off + 3 > amt) {
1384 off += buffer[off+3] + 4 + (nth * 4);
1385 if (amt < (off + 4))
1388 gget8(buffer, off++, thp->enc_type);
1389 gget8(buffer, off++, thp->enc_maxelt);
1390 gget8(buffer, off++, thp->enc_subenc);
1391 gget8(buffer, off, thp->enc_tlen);
1396 * This function needs a little explanation.
1398 * The arguments are:
1403 * These describes the raw input SES status data and length.
1407 * This is a map of the number of types for each element type
1412 * This is the element type being sought. If elt is -1,
1413 * then overall enclosure status is being sought.
1417 * This is the ordinal Mth element of type elt being sought.
1421 * This is the output area to store the status for
1422 * the Mth element of type Elt.
1426 ses_decode(char *b, int amt, uint8_t *ep, int elt, int elm, SesComStat *sp)
1431 * If it's overall enclosure status being sought, get that.
1432 * We need at least 2 bytes of status data to get that.
1437 gget8(b, 1, sp->comstatus);
1445 * Check to make sure that the Mth element is legal for type Elt.
1452 * Starting at offset 8, start skipping over the storage
1453 * for the element types we're not interested in.
1455 for (idx = 8, i = 0; i < elt; i++) {
1456 idx += ((ep[i] + 1) * 4);
1460 * Skip over Overall status for this element type.
1465 * And skip to the index for the Mth element that we're going for.
1470 * Make sure we haven't overflowed the buffer.
1476 * Retrieve the status.
1478 gget8(b, idx++, sp->comstatus);
1479 gget8(b, idx++, sp->comstat[0]);
1480 gget8(b, idx++, sp->comstat[1]);
1481 gget8(b, idx++, sp->comstat[2]);
1483 PRINTF("Get Elt 0x%x Elm 0x%x (idx %d)\n", elt, elm, idx-4);
1489 * This is the mirror function to ses_decode, but we set the 'select'
1490 * bit for the object which we're interested in. All other objects,
1491 * after a status fetch, should have that bit off. Hmm. It'd be easy
1492 * enough to ensure this, so we will.
1496 ses_encode(char *b, int amt, uint8_t *ep, int elt, int elm, SesComStat *sp)
1501 * If it's overall enclosure status being sought, get that.
1502 * We need at least 2 bytes of status data to get that.
1509 sset8(b, i, sp->comstatus & 0xf);
1511 PRINTF("set EncStat %x\n", sp->comstatus);
1517 * Check to make sure that the Mth element is legal for type Elt.
1524 * Starting at offset 8, start skipping over the storage
1525 * for the element types we're not interested in.
1527 for (idx = 8, i = 0; i < elt; i++) {
1528 idx += ((ep[i] + 1) * 4);
1532 * Skip over Overall status for this element type.
1537 * And skip to the index for the Mth element that we're going for.
1542 * Make sure we haven't overflowed the buffer.
1550 sset8(b, idx, sp->comstatus);
1551 sset8(b, idx, sp->comstat[0]);
1552 sset8(b, idx, sp->comstat[1]);
1553 sset8(b, idx, sp->comstat[2]);
1557 PRINTF("Set Elt 0x%x Elm 0x%x (idx %d) with %x %x %x %x\n",
1558 elt, elm, idx, sp->comstatus, sp->comstat[0],
1559 sp->comstat[1], sp->comstat[2]);
1563 * Now make sure all other 'Select' bits are off.
1565 for (i = 8; i < amt; i += 4) {
1570 * And make sure the INVOP bit is clear.
1578 * SAF-TE Type Device Emulation
1581 static int safte_getconfig(ses_softc_t *);
1582 static int safte_rdstat(ses_softc_t *, int);;
1583 static int set_objstat_sel(ses_softc_t *, ses_objstat *, int);
1584 static int wrbuf16(ses_softc_t *, uint8_t, uint8_t, uint8_t, uint8_t, int);
1585 static void wrslot_stat(ses_softc_t *, int);
1586 static int perf_slotop(ses_softc_t *, uint8_t, uint8_t, int);
1588 #define ALL_ENC_STAT (SES_ENCSTAT_CRITICAL | SES_ENCSTAT_UNRECOV | \
1589 SES_ENCSTAT_NONCRITICAL | SES_ENCSTAT_INFO)
1591 * SAF-TE specific defines- Mandatory ones only...
1595 * READ BUFFER ('get' commands) IDs- placed in offset 2 of cdb
1597 #define SAFTE_RD_RDCFG 0x00 /* read enclosure configuration */
1598 #define SAFTE_RD_RDESTS 0x01 /* read enclosure status */
1599 #define SAFTE_RD_RDDSTS 0x04 /* read drive slot status */
1602 * WRITE BUFFER ('set' commands) IDs- placed in offset 0 of databuf
1604 #define SAFTE_WT_DSTAT 0x10 /* write device slot status */
1605 #define SAFTE_WT_SLTOP 0x12 /* perform slot operation */
1606 #define SAFTE_WT_FANSPD 0x13 /* set fan speed */
1607 #define SAFTE_WT_ACTPWS 0x14 /* turn on/off power supply */
1608 #define SAFTE_WT_GLOBAL 0x15 /* send global command */
1611 #define SAFT_SCRATCH 64
1612 #define NPSEUDO_THERM 16
1613 #define NPSEUDO_ALARM 1
1616 * Cached Configuration
1618 uint8_t Nfans; /* Number of Fans */
1619 uint8_t Npwr; /* Number of Power Supplies */
1620 uint8_t Nslots; /* Number of Device Slots */
1621 uint8_t DoorLock; /* Door Lock Installed */
1622 uint8_t Ntherm; /* Number of Temperature Sensors */
1623 uint8_t Nspkrs; /* Number of Speakers */
1624 uint8_t Nalarm; /* Number of Alarms (at least one) */
1626 * Cached Flag Bytes for Global Status
1631 * What object index ID is where various slots start.
1635 #define SAFT_ALARM_OFFSET(cc) (cc)->slotoff - 1
1638 #define SAFT_FLG1_ALARM 0x1
1639 #define SAFT_FLG1_GLOBFAIL 0x2
1640 #define SAFT_FLG1_GLOBWARN 0x4
1641 #define SAFT_FLG1_ENCPWROFF 0x8
1642 #define SAFT_FLG1_ENCFANFAIL 0x10
1643 #define SAFT_FLG1_ENCPWRFAIL 0x20
1644 #define SAFT_FLG1_ENCDRVFAIL 0x40
1645 #define SAFT_FLG1_ENCDRVWARN 0x80
1647 #define SAFT_FLG2_LOCKDOOR 0x4
1648 #define SAFT_PRIVATE sizeof (struct scfg)
1650 static char *safte_2little = "Too Little Data Returned (%d) at line %d\n";
1651 #define SAFT_BAIL(r, x, k, l) \
1653 SES_LOG(ssc, safte_2little, x, __LINE__);\
1660 safte_softc_init(ses_softc_t *ssc, int doinit)
1666 if (ssc->ses_nobjects) {
1667 if (ssc->ses_objmap) {
1668 SES_FREE(ssc->ses_objmap,
1669 ssc->ses_nobjects * sizeof (encobj));
1670 ssc->ses_objmap = NULL;
1672 ssc->ses_nobjects = 0;
1674 if (ssc->ses_private) {
1675 SES_FREE(ssc->ses_private, SAFT_PRIVATE);
1676 ssc->ses_private = NULL;
1681 if (ssc->ses_private == NULL) {
1682 ssc->ses_private = SES_MALLOC(SAFT_PRIVATE);
1683 if (ssc->ses_private == NULL) {
1686 MEMZERO(ssc->ses_private, SAFT_PRIVATE);
1689 ssc->ses_nobjects = 0;
1690 ssc->ses_encstat = 0;
1692 if ((err = safte_getconfig(ssc)) != 0) {
1697 * The number of objects here, as well as that reported by the
1698 * READ_BUFFER/GET_CONFIG call, are the over-temperature flags (15)
1699 * that get reported during READ_BUFFER/READ_ENC_STATUS.
1701 cc = ssc->ses_private;
1702 ssc->ses_nobjects = cc->Nfans + cc->Npwr + cc->Nslots + cc->DoorLock +
1703 cc->Ntherm + cc->Nspkrs + NPSEUDO_THERM + NPSEUDO_ALARM;
1704 ssc->ses_objmap = (encobj *)
1705 SES_MALLOC(ssc->ses_nobjects * sizeof (encobj));
1706 if (ssc->ses_objmap == NULL) {
1709 MEMZERO(ssc->ses_objmap, ssc->ses_nobjects * sizeof (encobj));
1713 * Note that this is all arranged for the convenience
1714 * in later fetches of status.
1716 for (i = 0; i < cc->Nfans; i++)
1717 ssc->ses_objmap[r++].enctype = SESTYP_FAN;
1718 cc->pwroff = (uint8_t) r;
1719 for (i = 0; i < cc->Npwr; i++)
1720 ssc->ses_objmap[r++].enctype = SESTYP_POWER;
1721 for (i = 0; i < cc->DoorLock; i++)
1722 ssc->ses_objmap[r++].enctype = SESTYP_DOORLOCK;
1723 for (i = 0; i < cc->Nspkrs; i++)
1724 ssc->ses_objmap[r++].enctype = SESTYP_ALARM;
1725 for (i = 0; i < cc->Ntherm; i++)
1726 ssc->ses_objmap[r++].enctype = SESTYP_THERM;
1727 for (i = 0; i < NPSEUDO_THERM; i++)
1728 ssc->ses_objmap[r++].enctype = SESTYP_THERM;
1729 ssc->ses_objmap[r++].enctype = SESTYP_ALARM;
1730 cc->slotoff = (uint8_t) r;
1731 for (i = 0; i < cc->Nslots; i++)
1732 ssc->ses_objmap[r++].enctype = SESTYP_DEVICE;
1737 safte_init_enc(ses_softc_t *ssc)
1740 static char cdb0[6] = { SEND_DIAGNOSTIC };
1742 err = ses_runcmd(ssc, cdb0, 6, NULL, 0);
1747 err = wrbuf16(ssc, SAFTE_WT_GLOBAL, 0, 0, 0, 1);
1752 safte_get_encstat(ses_softc_t *ssc, int slpflg)
1754 return (safte_rdstat(ssc, slpflg));
1758 safte_set_encstat(ses_softc_t *ssc, uint8_t encstat, int slpflg)
1760 struct scfg *cc = ssc->ses_private;
1764 * Since SAF-TE devices aren't necessarily sticky in terms
1765 * of state, make our soft copy of enclosure status 'sticky'-
1766 * that is, things set in enclosure status stay set (as implied
1767 * by conditions set in reading object status) until cleared.
1769 ssc->ses_encstat &= ~ALL_ENC_STAT;
1770 ssc->ses_encstat |= (encstat & ALL_ENC_STAT);
1771 ssc->ses_encstat |= ENCI_SVALID;
1772 cc->flag1 &= ~(SAFT_FLG1_ALARM|SAFT_FLG1_GLOBFAIL|SAFT_FLG1_GLOBWARN);
1773 if ((encstat & (SES_ENCSTAT_CRITICAL|SES_ENCSTAT_UNRECOV)) != 0) {
1774 cc->flag1 |= SAFT_FLG1_ALARM|SAFT_FLG1_GLOBFAIL;
1775 } else if ((encstat & SES_ENCSTAT_NONCRITICAL) != 0) {
1776 cc->flag1 |= SAFT_FLG1_GLOBWARN;
1778 return (wrbuf16(ssc, SAFTE_WT_GLOBAL, cc->flag1, cc->flag2, 0, slpflg));
1782 safte_get_objstat(ses_softc_t *ssc, ses_objstat *obp, int slpflg)
1784 int i = (int)obp->obj_id;
1786 if ((ssc->ses_encstat & ENCI_SVALID) == 0 ||
1787 (ssc->ses_objmap[i].svalid) == 0) {
1788 int err = safte_rdstat(ssc, slpflg);
1792 obp->cstat[0] = ssc->ses_objmap[i].encstat[0];
1793 obp->cstat[1] = ssc->ses_objmap[i].encstat[1];
1794 obp->cstat[2] = ssc->ses_objmap[i].encstat[2];
1795 obp->cstat[3] = ssc->ses_objmap[i].encstat[3];
1801 safte_set_objstat(ses_softc_t *ssc, ses_objstat *obp, int slp)
1808 SES_DLOG(ssc, "safte_set_objstat(%d): %x %x %x %x\n",
1809 (int)obp->obj_id, obp->cstat[0], obp->cstat[1], obp->cstat[2],
1813 * If this is clear, we don't do diddly.
1815 if ((obp->cstat[0] & SESCTL_CSEL) == 0) {
1821 * Check to see if the common bits are set and do them first.
1823 if (obp->cstat[0] & ~SESCTL_CSEL) {
1824 err = set_objstat_sel(ssc, obp, slp);
1829 cc = ssc->ses_private;
1833 idx = (int)obp->obj_id;
1834 ep = &ssc->ses_objmap[idx];
1836 switch (ep->enctype) {
1841 * XXX: I should probably cache the previous state
1842 * XXX: of SESCTL_DEVOFF so that when it goes from
1843 * XXX: true to false I can then set PREPARE FOR OPERATION
1844 * XXX: flag in PERFORM SLOT OPERATION write buffer command.
1846 if (obp->cstat[2] & (SESCTL_RQSINS|SESCTL_RQSRMV)) {
1849 if (obp->cstat[2] & SESCTL_RQSID) {
1852 err = perf_slotop(ssc, (uint8_t) idx - (uint8_t) cc->slotoff,
1856 if (obp->cstat[3] & SESCTL_RQSFLT) {
1861 if (ep->priv & 0xc6) {
1864 ep->priv |= 0x1; /* no errors */
1866 wrslot_stat(ssc, slp);
1870 if (obp->cstat[3] & SESCTL_RQSTFAIL) {
1871 cc->flag1 |= SAFT_FLG1_ENCPWRFAIL;
1873 cc->flag1 &= ~SAFT_FLG1_ENCPWRFAIL;
1875 err = wrbuf16(ssc, SAFTE_WT_GLOBAL, cc->flag1,
1879 if (obp->cstat[3] & SESCTL_RQSTON) {
1880 (void) wrbuf16(ssc, SAFTE_WT_ACTPWS,
1881 idx - cc->pwroff, 0, 0, slp);
1883 (void) wrbuf16(ssc, SAFTE_WT_ACTPWS,
1884 idx - cc->pwroff, 0, 1, slp);
1888 if (obp->cstat[3] & SESCTL_RQSTFAIL) {
1889 cc->flag1 |= SAFT_FLG1_ENCFANFAIL;
1891 cc->flag1 &= ~SAFT_FLG1_ENCFANFAIL;
1893 err = wrbuf16(ssc, SAFTE_WT_GLOBAL, cc->flag1,
1897 if (obp->cstat[3] & SESCTL_RQSTON) {
1899 if ((obp->cstat[3] & 0x7) == 7) {
1901 } else if ((obp->cstat[3] & 0x7) == 6) {
1903 } else if ((obp->cstat[3] & 0x7) == 4) {
1908 (void) wrbuf16(ssc, SAFTE_WT_FANSPD, idx, fsp, 0, slp);
1910 (void) wrbuf16(ssc, SAFTE_WT_FANSPD, idx, 0, 0, slp);
1913 case SESTYP_DOORLOCK:
1914 if (obp->cstat[3] & 0x1) {
1915 cc->flag2 &= ~SAFT_FLG2_LOCKDOOR;
1917 cc->flag2 |= SAFT_FLG2_LOCKDOOR;
1919 (void) wrbuf16(ssc, SAFTE_WT_GLOBAL, cc->flag1,
1924 * On all nonzero but the 'muted' bit, we turn on the alarm,
1926 obp->cstat[3] &= ~0xa;
1927 if (obp->cstat[3] & 0x40) {
1928 cc->flag2 &= ~SAFT_FLG1_ALARM;
1929 } else if (obp->cstat[3] != 0) {
1930 cc->flag2 |= SAFT_FLG1_ALARM;
1932 cc->flag2 &= ~SAFT_FLG1_ALARM;
1934 ep->priv = obp->cstat[3];
1935 (void) wrbuf16(ssc, SAFTE_WT_GLOBAL, cc->flag1,
1946 safte_getconfig(ses_softc_t *ssc)
1951 static char cdb[10] =
1952 { READ_BUFFER, 1, SAFTE_RD_RDCFG, 0, 0, 0, 0, 0, SAFT_SCRATCH, 0 };
1954 cfg = ssc->ses_private;
1958 sdata = SES_MALLOC(SAFT_SCRATCH);
1963 err = ses_runcmd(ssc, cdb, 10, sdata, &amt);
1965 SES_FREE(sdata, SAFT_SCRATCH);
1968 amt = SAFT_SCRATCH - amt;
1970 SES_LOG(ssc, "too little data (%d) for configuration\n", amt);
1971 SES_FREE(sdata, SAFT_SCRATCH);
1974 SES_VLOG(ssc, "Nfans %d Npwr %d Nslots %d Lck %d Ntherm %d Nspkrs %d\n",
1975 sdata[0], sdata[1], sdata[2], sdata[3], sdata[4], sdata[5]);
1976 cfg->Nfans = sdata[0];
1977 cfg->Npwr = sdata[1];
1978 cfg->Nslots = sdata[2];
1979 cfg->DoorLock = sdata[3];
1980 cfg->Ntherm = sdata[4];
1981 cfg->Nspkrs = sdata[5];
1982 cfg->Nalarm = NPSEUDO_ALARM;
1983 SES_FREE(sdata, SAFT_SCRATCH);
1988 safte_rdstat(ses_softc_t *ssc, int slpflg)
1990 int err, oid, r, i, hiwater, nitems, amt;
1993 uint8_t status, oencstat;
1994 char *sdata, cdb[10];
1995 struct scfg *cc = ssc->ses_private;
1999 * The number of objects overstates things a bit,
2000 * both for the bogus 'thermometer' entries and
2001 * the drive status (which isn't read at the same
2002 * time as the enclosure status), but that's okay.
2004 buflen = 4 * cc->Nslots;
2005 if (ssc->ses_nobjects > buflen)
2006 buflen = ssc->ses_nobjects;
2007 sdata = SES_MALLOC(buflen);
2011 cdb[0] = READ_BUFFER;
2013 cdb[2] = SAFTE_RD_RDESTS;
2018 cdb[7] = (buflen >> 8) & 0xff;
2019 cdb[8] = buflen & 0xff;
2022 err = ses_runcmd(ssc, cdb, 10, sdata, &amt);
2024 SES_FREE(sdata, buflen);
2027 hiwater = buflen - amt;
2031 * invalidate all status bits.
2033 for (i = 0; i < ssc->ses_nobjects; i++)
2034 ssc->ses_objmap[i].svalid = 0;
2035 oencstat = ssc->ses_encstat & ALL_ENC_STAT;
2036 ssc->ses_encstat = 0;
2040 * Now parse returned buffer.
2041 * If we didn't get enough data back,
2042 * that's considered a fatal error.
2046 for (nitems = i = 0; i < cc->Nfans; i++) {
2047 SAFT_BAIL(r, hiwater, sdata, buflen);
2049 * 0 = Fan Operational
2050 * 1 = Fan is malfunctioning
2051 * 2 = Fan is not present
2052 * 0x80 = Unknown or Not Reportable Status
2054 ssc->ses_objmap[oid].encstat[1] = 0; /* resvd */
2055 ssc->ses_objmap[oid].encstat[2] = 0; /* resvd */
2056 switch ((int)(uint8_t)sdata[r]) {
2059 ssc->ses_objmap[oid].encstat[0] = SES_OBJSTAT_OK;
2061 * We could get fancier and cache
2062 * fan speeds that we have set, but
2063 * that isn't done now.
2065 ssc->ses_objmap[oid].encstat[3] = 7;
2069 ssc->ses_objmap[oid].encstat[0] = SES_OBJSTAT_CRIT;
2071 * FAIL and FAN STOPPED synthesized
2073 ssc->ses_objmap[oid].encstat[3] = 0x40;
2075 * Enclosure marked with CRITICAL error
2076 * if only one fan or no thermometers,
2077 * else the NONCRITICAL error is set.
2079 if (cc->Nfans == 1 || cc->Ntherm == 0)
2080 ssc->ses_encstat |= SES_ENCSTAT_CRITICAL;
2082 ssc->ses_encstat |= SES_ENCSTAT_NONCRITICAL;
2085 ssc->ses_objmap[oid].encstat[0] =
2086 SES_OBJSTAT_NOTINSTALLED;
2087 ssc->ses_objmap[oid].encstat[3] = 0;
2089 * Enclosure marked with CRITICAL error
2090 * if only one fan or no thermometers,
2091 * else the NONCRITICAL error is set.
2094 ssc->ses_encstat |= SES_ENCSTAT_CRITICAL;
2096 ssc->ses_encstat |= SES_ENCSTAT_NONCRITICAL;
2099 ssc->ses_objmap[oid].encstat[0] = SES_OBJSTAT_UNKNOWN;
2100 ssc->ses_objmap[oid].encstat[3] = 0;
2101 ssc->ses_encstat |= SES_ENCSTAT_INFO;
2104 ssc->ses_objmap[oid].encstat[0] =
2105 SES_OBJSTAT_UNSUPPORTED;
2106 SES_LOG(ssc, "Unknown fan%d status 0x%x\n", i,
2110 ssc->ses_objmap[oid++].svalid = 1;
2115 * No matter how you cut it, no cooling elements when there
2116 * should be some there is critical.
2118 if (cc->Nfans && nitems == 0) {
2119 ssc->ses_encstat |= SES_ENCSTAT_CRITICAL;
2123 for (i = 0; i < cc->Npwr; i++) {
2124 SAFT_BAIL(r, hiwater, sdata, buflen);
2125 ssc->ses_objmap[oid].encstat[0] = SES_OBJSTAT_UNKNOWN;
2126 ssc->ses_objmap[oid].encstat[1] = 0; /* resvd */
2127 ssc->ses_objmap[oid].encstat[2] = 0; /* resvd */
2128 ssc->ses_objmap[oid].encstat[3] = 0x20; /* requested on */
2129 switch ((uint8_t)sdata[r]) {
2130 case 0x00: /* pws operational and on */
2131 ssc->ses_objmap[oid].encstat[0] = SES_OBJSTAT_OK;
2133 case 0x01: /* pws operational and off */
2134 ssc->ses_objmap[oid].encstat[0] = SES_OBJSTAT_OK;
2135 ssc->ses_objmap[oid].encstat[3] = 0x10;
2136 ssc->ses_encstat |= SES_ENCSTAT_INFO;
2138 case 0x10: /* pws is malfunctioning and commanded on */
2139 ssc->ses_objmap[oid].encstat[0] = SES_OBJSTAT_CRIT;
2140 ssc->ses_objmap[oid].encstat[3] = 0x61;
2141 ssc->ses_encstat |= SES_ENCSTAT_NONCRITICAL;
2144 case 0x11: /* pws is malfunctioning and commanded off */
2145 ssc->ses_objmap[oid].encstat[0] = SES_OBJSTAT_NONCRIT;
2146 ssc->ses_objmap[oid].encstat[3] = 0x51;
2147 ssc->ses_encstat |= SES_ENCSTAT_NONCRITICAL;
2149 case 0x20: /* pws is not present */
2150 ssc->ses_objmap[oid].encstat[0] =
2151 SES_OBJSTAT_NOTINSTALLED;
2152 ssc->ses_objmap[oid].encstat[3] = 0;
2153 ssc->ses_encstat |= SES_ENCSTAT_INFO;
2155 case 0x21: /* pws is present */
2157 * This is for enclosures that cannot tell whether the
2158 * device is on or malfunctioning, but know that it is
2159 * present. Just fall through.
2162 case 0x80: /* Unknown or Not Reportable Status */
2163 ssc->ses_objmap[oid].encstat[0] = SES_OBJSTAT_UNKNOWN;
2164 ssc->ses_objmap[oid].encstat[3] = 0;
2165 ssc->ses_encstat |= SES_ENCSTAT_INFO;
2168 SES_LOG(ssc, "unknown power supply %d status (0x%x)\n",
2169 i, sdata[r] & 0xff);
2172 ssc->ses_objmap[oid++].svalid = 1;
2177 * Skip over Slot SCSI IDs
2182 * We always have doorlock status, no matter what,
2183 * but we only save the status if we have one.
2185 SAFT_BAIL(r, hiwater, sdata, buflen);
2189 * 1 = Door Unlocked, or no Lock Installed
2190 * 0x80 = Unknown or Not Reportable Status
2192 ssc->ses_objmap[oid].encstat[1] = 0;
2193 ssc->ses_objmap[oid].encstat[2] = 0;
2194 switch ((uint8_t)sdata[r]) {
2196 ssc->ses_objmap[oid].encstat[0] = SES_OBJSTAT_OK;
2197 ssc->ses_objmap[oid].encstat[3] = 0;
2200 ssc->ses_objmap[oid].encstat[0] = SES_OBJSTAT_OK;
2201 ssc->ses_objmap[oid].encstat[3] = 1;
2204 ssc->ses_objmap[oid].encstat[0] = SES_OBJSTAT_UNKNOWN;
2205 ssc->ses_objmap[oid].encstat[3] = 0;
2206 ssc->ses_encstat |= SES_ENCSTAT_INFO;
2209 ssc->ses_objmap[oid].encstat[0] =
2210 SES_OBJSTAT_UNSUPPORTED;
2211 SES_LOG(ssc, "unknown lock status 0x%x\n",
2215 ssc->ses_objmap[oid++].svalid = 1;
2220 * We always have speaker status, no matter what,
2221 * but we only save the status if we have one.
2223 SAFT_BAIL(r, hiwater, sdata, buflen);
2225 ssc->ses_objmap[oid].encstat[1] = 0;
2226 ssc->ses_objmap[oid].encstat[2] = 0;
2227 if (sdata[r] == 1) {
2229 * We need to cache tone urgency indicators.
2232 ssc->ses_objmap[oid].encstat[0] = SES_OBJSTAT_NONCRIT;
2233 ssc->ses_objmap[oid].encstat[3] = 0x8;
2234 ssc->ses_encstat |= SES_ENCSTAT_NONCRITICAL;
2235 } else if (sdata[r] == 0) {
2236 ssc->ses_objmap[oid].encstat[0] = SES_OBJSTAT_OK;
2237 ssc->ses_objmap[oid].encstat[3] = 0;
2239 ssc->ses_objmap[oid].encstat[0] =
2240 SES_OBJSTAT_UNSUPPORTED;
2241 ssc->ses_objmap[oid].encstat[3] = 0;
2242 SES_LOG(ssc, "unknown spkr status 0x%x\n",
2245 ssc->ses_objmap[oid++].svalid = 1;
2249 for (i = 0; i < cc->Ntherm; i++) {
2250 SAFT_BAIL(r, hiwater, sdata, buflen);
2252 * Status is a range from -10 to 245 deg Celsius,
2253 * which we need to normalize to -20 to -245 according
2254 * to the latest SCSI spec, which makes little
2255 * sense since this would overflow an 8bit value.
2256 * Well, still, the base normalization is -20,
2257 * not -10, so we have to adjust.
2259 * So what's over and under temperature?
2260 * Hmm- we'll state that 'normal' operating
2261 * is 10 to 40 deg Celsius.
2265 * Actually.... All of the units that people out in the world
2266 * seem to have do not come even close to setting a value that
2267 * complies with this spec.
2269 * The closest explanation I could find was in an
2270 * LSI-Logic manual, which seemed to indicate that
2271 * this value would be set by whatever the I2C code
2272 * would interpolate from the output of an LM75
2273 * temperature sensor.
2275 * This means that it is impossible to use the actual
2276 * numeric value to predict anything. But we don't want
2277 * to lose the value. So, we'll propagate the *uncorrected*
2278 * value and set SES_OBJSTAT_NOTAVAIL. We'll depend on the
2279 * temperature flags for warnings.
2281 ssc->ses_objmap[oid].encstat[0] = SES_OBJSTAT_NOTAVAIL;
2282 ssc->ses_objmap[oid].encstat[1] = 0;
2283 ssc->ses_objmap[oid].encstat[2] = sdata[r];
2284 ssc->ses_objmap[oid].encstat[3] = 0;;
2285 ssc->ses_objmap[oid++].svalid = 1;
2290 * Now, for "pseudo" thermometers, we have two bytes
2291 * of information in enclosure status- 16 bits. Actually,
2292 * the MSB is a single TEMP ALERT flag indicating whether
2293 * any other bits are set, but, thanks to fuzzy thinking,
2294 * in the SAF-TE spec, this can also be set even if no
2295 * other bits are set, thus making this really another
2296 * binary temperature sensor.
2299 SAFT_BAIL(r, hiwater, sdata, buflen);
2300 tempflags = sdata[r++];
2301 SAFT_BAIL(r, hiwater, sdata, buflen);
2302 tempflags |= (tempflags << 8) | sdata[r++];
2304 for (i = 0; i < NPSEUDO_THERM; i++) {
2305 ssc->ses_objmap[oid].encstat[1] = 0;
2306 if (tempflags & (1 << (NPSEUDO_THERM - i - 1))) {
2307 ssc->ses_objmap[oid].encstat[0] = SES_OBJSTAT_CRIT;
2308 ssc->ses_objmap[4].encstat[2] = 0xff;
2310 * Set 'over temperature' failure.
2312 ssc->ses_objmap[oid].encstat[3] = 8;
2313 ssc->ses_encstat |= SES_ENCSTAT_CRITICAL;
2316 * We used to say 'not available' and synthesize a
2317 * nominal 30 deg (C)- that was wrong. Actually,
2318 * Just say 'OK', and use the reserved value of
2321 ssc->ses_objmap[oid].encstat[0] = SES_OBJSTAT_OK;
2322 ssc->ses_objmap[oid].encstat[2] = 0;
2323 ssc->ses_objmap[oid].encstat[3] = 0;
2325 ssc->ses_objmap[oid++].svalid = 1;
2331 ssc->ses_objmap[oid].encstat[0] = SES_OBJSTAT_OK;
2332 ssc->ses_objmap[oid].encstat[3] = ssc->ses_objmap[oid].priv;
2333 ssc->ses_objmap[oid++].svalid = 1;
2336 * Now get drive slot status
2338 cdb[2] = SAFTE_RD_RDDSTS;
2340 err = ses_runcmd(ssc, cdb, 10, sdata, &amt);
2342 SES_FREE(sdata, buflen);
2345 hiwater = buflen - amt;
2346 for (r = i = 0; i < cc->Nslots; i++, r += 4) {
2347 SAFT_BAIL(r+3, hiwater, sdata, buflen);
2348 ssc->ses_objmap[oid].encstat[0] = SES_OBJSTAT_UNSUPPORTED;
2349 ssc->ses_objmap[oid].encstat[1] = (uint8_t) i;
2350 ssc->ses_objmap[oid].encstat[2] = 0;
2351 ssc->ses_objmap[oid].encstat[3] = 0;
2352 status = sdata[r+3];
2353 if ((status & 0x1) == 0) { /* no device */
2354 ssc->ses_objmap[oid].encstat[0] =
2355 SES_OBJSTAT_NOTINSTALLED;
2357 ssc->ses_objmap[oid].encstat[0] = SES_OBJSTAT_OK;
2360 ssc->ses_objmap[oid].encstat[2] = 0x8;
2362 if ((status & 0x4) == 0) {
2363 ssc->ses_objmap[oid].encstat[3] = 0x10;
2365 ssc->ses_objmap[oid++].svalid = 1;
2367 /* see comment below about sticky enclosure status */
2368 ssc->ses_encstat |= ENCI_SVALID | oencstat;
2369 SES_FREE(sdata, buflen);
2374 set_objstat_sel(ses_softc_t *ssc, ses_objstat *obp, int slp)
2378 struct scfg *cc = ssc->ses_private;
2383 idx = (int)obp->obj_id;
2384 ep = &ssc->ses_objmap[idx];
2386 switch (ep->enctype) {
2388 if (obp->cstat[0] & SESCTL_PRDFAIL) {
2391 /* SESCTL_RSTSWAP has no correspondence in SAF-TE */
2392 if (obp->cstat[0] & SESCTL_DISABLE) {
2395 * Hmm. Try to set the 'No Drive' flag.
2396 * Maybe that will count as a 'disable'.
2399 if (ep->priv & 0xc6) {
2402 ep->priv |= 0x1; /* no errors */
2404 wrslot_stat(ssc, slp);
2408 * Okay- the only one that makes sense here is to
2409 * do the 'disable' for a power supply.
2411 if (obp->cstat[0] & SESCTL_DISABLE) {
2412 (void) wrbuf16(ssc, SAFTE_WT_ACTPWS,
2413 idx - cc->pwroff, 0, 0, slp);
2418 * Okay- the only one that makes sense here is to
2419 * set fan speed to zero on disable.
2421 if (obp->cstat[0] & SESCTL_DISABLE) {
2422 /* remember- fans are the first items, so idx works */
2423 (void) wrbuf16(ssc, SAFTE_WT_FANSPD, idx, 0, 0, slp);
2426 case SESTYP_DOORLOCK:
2428 * Well, we can 'disable' the lock.
2430 if (obp->cstat[0] & SESCTL_DISABLE) {
2431 cc->flag2 &= ~SAFT_FLG2_LOCKDOOR;
2432 (void) wrbuf16(ssc, SAFTE_WT_GLOBAL, cc->flag1,
2438 * Well, we can 'disable' the alarm.
2440 if (obp->cstat[0] & SESCTL_DISABLE) {
2441 cc->flag2 &= ~SAFT_FLG1_ALARM;
2442 ep->priv |= 0x40; /* Muted */
2443 (void) wrbuf16(ssc, SAFTE_WT_GLOBAL, cc->flag1,
2455 * This function handles all of the 16 byte WRITE BUFFER commands.
2458 wrbuf16(ses_softc_t *ssc, uint8_t op, uint8_t b1, uint8_t b2,
2459 uint8_t b3, int slp)
2463 struct scfg *cc = ssc->ses_private;
2464 static char cdb[10] = { WRITE_BUFFER, 1, 0, 0, 0, 0, 0, 0, 16, 0 };
2469 sdata = SES_MALLOC(16);
2473 SES_DLOG(ssc, "saf_wrbuf16 %x %x %x %x\n", op, b1, b2, b3);
2479 MEMZERO(&sdata[4], 12);
2481 err = ses_runcmd(ssc, cdb, 10, sdata, &amt);
2482 SES_FREE(sdata, 16);
2487 * This function updates the status byte for the device slot described.
2489 * Since this is an optional SAF-TE command, there's no point in
2490 * returning an error.
2493 wrslot_stat(ses_softc_t *ssc, int slp)
2497 char cdb[10], *sdata;
2498 struct scfg *cc = ssc->ses_private;
2503 SES_DLOG(ssc, "saf_wrslot\n");
2504 cdb[0] = WRITE_BUFFER;
2512 cdb[8] = cc->Nslots * 3 + 1;
2515 sdata = SES_MALLOC(cc->Nslots * 3 + 1);
2518 MEMZERO(sdata, cc->Nslots * 3 + 1);
2520 sdata[0] = SAFTE_WT_DSTAT;
2521 for (i = 0; i < cc->Nslots; i++) {
2522 ep = &ssc->ses_objmap[cc->slotoff + i];
2523 SES_DLOG(ssc, "saf_wrslot %d <- %x\n", i, ep->priv & 0xff);
2524 sdata[1 + (3 * i)] = ep->priv & 0xff;
2526 amt = -(cc->Nslots * 3 + 1);
2527 (void) ses_runcmd(ssc, cdb, 10, sdata, &amt);
2528 SES_FREE(sdata, cc->Nslots * 3 + 1);
2532 * This function issues the "PERFORM SLOT OPERATION" command.
2535 perf_slotop(ses_softc_t *ssc, uint8_t slot, uint8_t opflag, int slp)
2539 struct scfg *cc = ssc->ses_private;
2540 static char cdb[10] =
2541 { WRITE_BUFFER, 1, 0, 0, 0, 0, 0, 0, SAFT_SCRATCH, 0 };
2546 sdata = SES_MALLOC(SAFT_SCRATCH);
2549 MEMZERO(sdata, SAFT_SCRATCH);
2551 sdata[0] = SAFTE_WT_SLTOP;
2554 SES_DLOG(ssc, "saf_slotop slot %d op %x\n", slot, opflag);
2555 amt = -SAFT_SCRATCH;
2556 err = ses_runcmd(ssc, cdb, 10, sdata, &amt);
2557 SES_FREE(sdata, SAFT_SCRATCH);