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.6 2003/08/07 21:16:45 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_ccb.h"
45 #include "../cam_extend.h"
46 #include "../cam_periph.h"
47 #include "../cam_xpt_periph.h"
48 #include "../cam_queue.h"
49 #include "../cam_debug.h"
52 #include "scsi_message.h"
53 #include <sys/ioccom.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 = {
184 /* maj */ SES_CDEV_MAJOR,
190 /* close */ sesclose,
193 /* ioctl */ sesioctl,
196 /* strategy */ nostrategy,
200 static struct extend_array *sesperiphs;
206 struct cam_path *path;
209 * Create our extend array for storing the devices we attach to.
211 sesperiphs = cam_extend_new();
212 if (sesperiphs == NULL) {
213 printf("ses: Failed to alloc extend array!\n");
218 * Install a global async callback. This callback will
219 * receive async callbacks like "new device found".
221 status = xpt_create_path(&path, NULL, CAM_XPT_PATH_ID,
222 CAM_TARGET_WILDCARD, CAM_LUN_WILDCARD);
224 if (status == CAM_REQ_CMP) {
225 struct ccb_setasync csa;
227 xpt_setup_ccb(&csa.ccb_h, path, 5);
228 csa.ccb_h.func_code = XPT_SASYNC_CB;
229 csa.event_enable = AC_FOUND_DEVICE;
230 csa.callback = sesasync;
231 csa.callback_arg = NULL;
232 xpt_action((union ccb *)&csa);
233 status = csa.ccb_h.status;
237 if (status != CAM_REQ_CMP) {
238 printf("ses: Failed to attach master async callback "
239 "due to status 0x%x!\n", status);
244 sesoninvalidate(struct cam_periph *periph)
246 struct ses_softc *softc;
247 struct ccb_setasync csa;
249 softc = (struct ses_softc *)periph->softc;
252 * Unregister any async callbacks.
254 xpt_setup_ccb(&csa.ccb_h, periph->path, 5);
255 csa.ccb_h.func_code = XPT_SASYNC_CB;
256 csa.event_enable = 0;
257 csa.callback = sesasync;
258 csa.callback_arg = periph;
259 xpt_action((union ccb *)&csa);
261 softc->ses_flags |= SES_FLAG_INVALID;
263 xpt_print_path(periph->path);
264 printf("lost device\n");
268 sescleanup(struct cam_periph *periph)
270 struct ses_softc *softc;
272 softc = (struct ses_softc *)periph->softc;
274 destroy_dev(softc->ses_dev);
276 cam_extend_release(sesperiphs, periph->unit_number);
277 xpt_print_path(periph->path);
278 printf("removing device entry\n");
279 free(softc, M_DEVBUF);
283 sesasync(void *callback_arg, u_int32_t code, struct cam_path *path, void *arg)
285 struct cam_periph *periph;
287 periph = (struct cam_periph *)callback_arg;
290 case AC_FOUND_DEVICE:
293 struct ccb_getdev *cgd;
295 cgd = (struct ccb_getdev *)arg;
298 * PROBLEM: WE NEED TO LOOK AT BYTES 48-53 TO SEE IF THIS IS
299 * PROBLEM: IS A SAF-TE DEVICE.
301 switch (ses_type(&cgd->inq_data, cgd->inq_len)) {
304 case SES_SES_PASSTHROUGH:
312 status = cam_periph_alloc(sesregister, sesoninvalidate,
313 sescleanup, sesstart, "ses", CAM_PERIPH_BIO,
314 cgd->ccb_h.path, sesasync, AC_FOUND_DEVICE, cgd);
316 if (status != CAM_REQ_CMP && status != CAM_REQ_INPROG) {
317 printf("sesasync: Unable to probe new device due to "
318 "status 0x%x\n", status);
323 cam_periph_async(periph, code, path, arg);
329 sesregister(struct cam_periph *periph, void *arg)
331 struct ses_softc *softc;
332 struct ccb_setasync csa;
333 struct ccb_getdev *cgd;
336 cgd = (struct ccb_getdev *)arg;
337 if (periph == NULL) {
338 printf("sesregister: periph was NULL!!\n");
339 return (CAM_REQ_CMP_ERR);
343 printf("sesregister: no getdev CCB, can't register device\n");
344 return (CAM_REQ_CMP_ERR);
347 softc = malloc(sizeof (struct ses_softc), M_DEVBUF, M_NOWAIT);
349 printf("sesregister: Unable to probe new device. "
350 "Unable to allocate softc\n");
351 return (CAM_REQ_CMP_ERR);
353 bzero(softc, sizeof (struct ses_softc));
354 periph->softc = softc;
355 softc->periph = periph;
357 softc->ses_type = ses_type(&cgd->inq_data, sizeof (cgd->inq_data));
359 switch (softc->ses_type) {
362 case SES_SES_PASSTHROUGH:
363 softc->ses_vec.softc_init = ses_softc_init;
364 softc->ses_vec.init_enc = ses_init_enc;
365 softc->ses_vec.get_encstat = ses_get_encstat;
366 softc->ses_vec.set_encstat = ses_set_encstat;
367 softc->ses_vec.get_objstat = ses_get_objstat;
368 softc->ses_vec.set_objstat = ses_set_objstat;
371 softc->ses_vec.softc_init = safte_softc_init;
372 softc->ses_vec.init_enc = safte_init_enc;
373 softc->ses_vec.get_encstat = safte_get_encstat;
374 softc->ses_vec.set_encstat = safte_set_encstat;
375 softc->ses_vec.get_objstat = safte_get_objstat;
376 softc->ses_vec.set_objstat = safte_set_objstat;
382 free(softc, M_DEVBUF);
383 return (CAM_REQ_CMP_ERR);
386 cam_extend_set(sesperiphs, periph->unit_number, periph);
388 softc->ses_dev = make_dev(&ses_cdevsw, periph->unit_number,
389 UID_ROOT, GID_OPERATOR, 0600, "%s%d",
390 periph->periph_name, periph->unit_number);
393 * Add an async callback so that we get
394 * notified if this device goes away.
396 xpt_setup_ccb(&csa.ccb_h, periph->path, 5);
397 csa.ccb_h.func_code = XPT_SASYNC_CB;
398 csa.event_enable = AC_LOST_DEVICE;
399 csa.callback = sesasync;
400 csa.callback_arg = periph;
401 xpt_action((union ccb *)&csa);
403 switch (softc->ses_type) {
406 tname = "No SES device";
409 tname = "SCSI-2 SES Device";
412 tname = "SCSI-3 SES Device";
414 case SES_SES_PASSTHROUGH:
415 tname = "SES Passthrough Device";
418 tname = "UNISYS SEN Device (NOT HANDLED YET)";
421 tname = "SAF-TE Compliant Device";
424 xpt_announce_periph(periph, tname);
425 return (CAM_REQ_CMP);
429 sesopen(dev_t dev, int flags, int fmt, struct thread *td)
431 struct cam_periph *periph;
432 struct ses_softc *softc;
436 periph = cam_extend_get(sesperiphs, SESUNIT(dev));
437 if (periph == NULL) {
441 if ((error = cam_periph_lock(periph, PCATCH)) != 0) {
447 if (cam_periph_acquire(periph) != CAM_REQ_CMP) {
448 cam_periph_unlock(periph);
452 softc = (struct ses_softc *)periph->softc;
454 if (softc->ses_flags & SES_FLAG_INVALID) {
458 if (softc->ses_flags & SES_FLAG_OPEN) {
462 if (softc->ses_vec.softc_init == NULL) {
467 softc->ses_flags |= SES_FLAG_OPEN;
468 if ((softc->ses_flags & SES_FLAG_INITIALIZED) == 0) {
469 error = (*softc->ses_vec.softc_init)(softc, 1);
471 softc->ses_flags &= ~SES_FLAG_OPEN;
473 softc->ses_flags |= SES_FLAG_INITIALIZED;
478 cam_periph_release(periph);
480 cam_periph_unlock(periph);
485 sesclose(dev_t dev, int flag, int fmt, struct thread *td)
487 struct cam_periph *periph;
488 struct ses_softc *softc;
494 periph = cam_extend_get(sesperiphs, unit);
498 softc = (struct ses_softc *)periph->softc;
500 if ((error = cam_periph_lock(periph, 0)) != 0)
503 softc->ses_flags &= ~SES_FLAG_OPEN;
505 cam_periph_unlock(periph);
506 cam_periph_release(periph);
512 sesstart(struct cam_periph *p, union ccb *sccb)
515 if (p->immediate_priority <= p->pinfo.priority) {
516 SLIST_INSERT_HEAD(&p->ccb_list, &sccb->ccb_h, periph_links.sle);
517 p->immediate_priority = CAM_PRIORITY_NONE;
518 wakeup(&p->ccb_list);
524 sesdone(struct cam_periph *periph, union ccb *dccb)
526 wakeup(&dccb->ccb_h.cbfcnp);
530 seserror(union ccb *ccb, u_int32_t cflags, u_int32_t sflags)
532 struct ses_softc *softc;
533 struct cam_periph *periph;
535 periph = xpt_path_periph(ccb->ccb_h.path);
536 softc = (struct ses_softc *)periph->softc;
538 return (cam_periph_error(ccb, cflags, sflags, &softc->ses_saved_ccb));
542 sesioctl(dev_t dev, u_long cmd, caddr_t arg_addr, int flag, struct thread *td)
544 struct cam_periph *periph;
547 ses_object obj, *uobj;
548 struct ses_softc *ssc;
554 addr = *((caddr_t *) arg_addr);
558 periph = cam_extend_get(sesperiphs, SESUNIT(dev));
562 CAM_DEBUG(periph->path, CAM_DEBUG_TRACE, ("entering sesioctl\n"));
564 ssc = (struct ses_softc *)periph->softc;
567 * Now check to see whether we're initialized or not.
569 if ((ssc->ses_flags & SES_FLAG_INITIALIZED) == 0) {
575 CAM_DEBUG(periph->path, CAM_DEBUG_TRACE,
576 ("trying to do ioctl %#lx\n", cmd));
579 * If this command can change the device's state,
580 * we must have the device open for writing.
584 case SESIOC_GETOBJMAP:
585 case SESIOC_GETENCSTAT:
586 case SESIOC_GETOBJSTAT:
589 if ((flag & FWRITE) == 0) {
596 error = copyout(&ssc->ses_nobjects, addr,
597 sizeof (ssc->ses_nobjects));
600 case SESIOC_GETOBJMAP:
601 for (uobj = addr, i = 0; i != ssc->ses_nobjects; i++, uobj++) {
603 obj.subencid = ssc->ses_objmap[i].subenclosure;
604 obj.object_type = ssc->ses_objmap[i].enctype;
605 error = copyout(&obj, uobj, sizeof (ses_object));
612 case SESIOC_GETENCSTAT:
613 error = (*ssc->ses_vec.get_encstat)(ssc, 1);
616 tmp = ssc->ses_encstat & ~ENCI_SVALID;
617 error = copyout(&tmp, addr, sizeof (ses_encstat));
618 ssc->ses_encstat = tmp;
621 case SESIOC_SETENCSTAT:
622 error = copyin(addr, &tmp, sizeof (ses_encstat));
625 error = (*ssc->ses_vec.set_encstat)(ssc, tmp, 1);
628 case SESIOC_GETOBJSTAT:
629 error = copyin(addr, &objs, sizeof (ses_objstat));
632 if (objs.obj_id >= ssc->ses_nobjects) {
636 error = (*ssc->ses_vec.get_objstat)(ssc, &objs, 1);
639 error = copyout(&objs, addr, sizeof (ses_objstat));
641 * Always (for now) invalidate entry.
643 ssc->ses_objmap[objs.obj_id].svalid = 0;
646 case SESIOC_SETOBJSTAT:
647 error = copyin(addr, &objs, sizeof (ses_objstat));
651 if (objs.obj_id >= ssc->ses_nobjects) {
655 error = (*ssc->ses_vec.set_objstat)(ssc, &objs, 1);
658 * Always (for now) invalidate entry.
660 ssc->ses_objmap[objs.obj_id].svalid = 0;
665 error = (*ssc->ses_vec.init_enc)(ssc);
669 error = cam_periph_ioctl(periph, cmd, arg_addr, seserror);
675 #define SES_FLAGS SF_NO_PRINT | SF_RETRY_SELTO | SF_RETRY_UA
677 ses_runcmd(struct ses_softc *ssc, char *cdb, int cdbl, char *dptr, int *dlenp)
684 if ((dlen = *dlenp) < 0) {
695 if (cdbl > IOCDBLEN) {
699 ccb = cam_periph_getccb(ssc->periph, 1);
700 cam_fill_csio(&ccb->csio, 0, sesdone, ddf, MSG_SIMPLE_Q_TAG, dptr,
701 dlen, sizeof (struct scsi_sense_data), cdbl, 60 * 1000);
702 bcopy(cdb, ccb->csio.cdb_io.cdb_bytes, cdbl);
704 error = cam_periph_runccb(ccb, seserror, 0, SES_FLAGS, NULL);
705 if ((ccb->ccb_h.status & CAM_DEV_QFRZN) != 0)
706 cam_release_devq(ccb->ccb_h.path, 0, 0, 0, FALSE);
713 *dlenp = ccb->csio.resid;
716 xpt_release_ccb(ccb);
721 ses_log(struct ses_softc *ssc, const char *fmt, ...)
725 printf("%s%d: ", ssc->periph->periph_name, ssc->periph->unit_number);
732 * The code after this point runs on many platforms,
733 * so forgive the slightly awkward and nonconforming
738 * Is this a device that supports enclosure services?
740 * It's a a pretty simple ruleset- if it is device type 0x0D (13), it's
741 * an SES device. If it happens to be an old UNISYS SEN device, we can
745 #define SAFTE_START 44
747 #define SAFTE_LEN SAFTE_END-SAFTE_START
750 ses_type(void *buf, int buflen)
752 unsigned char *iqd = buf;
755 buflen = 256; /* per SPC-2 */
757 if (buflen < 8+SEN_ID_LEN)
760 if ((iqd[0] & 0x1f) == T_ENCLOSURE) {
761 if (STRNCMP(&iqd[8], SEN_ID, SEN_ID_LEN) == 0) {
763 } else if ((iqd[2] & 0x7) > 2) {
766 return (SES_SES_SCSI2);
771 #ifdef SES_ENABLE_PASSTHROUGH
772 if ((iqd[6] & 0x40) && (iqd[2] & 0x7) >= 2) {
774 * PassThrough Device.
776 return (SES_SES_PASSTHROUGH);
781 * The comparison is short for a reason-
782 * some vendors were chopping it short.
785 if (buflen < SAFTE_END - 2) {
789 if (STRNCMP((char *)&iqd[SAFTE_START], "SAF-TE", SAFTE_LEN - 2) == 0) {
796 * SES Native Type Device Support
800 * SES Diagnostic Page Codes
806 #define SesStatusPage SesControlPage
809 #define SesStringIn SesStringOut
811 #define SesThresholdIn SesThresholdOut
813 #define SesArrayStatus SesArrayControl
814 SesElementDescriptor,
823 * Minimum amount of data, starting from byte 0, to have
826 #define SES_CFGHDR_MINLEN 12
829 * Minimum amount of data, starting from byte 0, to have
830 * the config header and one enclosure header.
832 #define SES_ENCHDR_MINLEN 48
835 * Take this value, subtract it from VEnclen and you know
836 * the length of the vendor unique bytes.
838 #define SES_ENCHDR_VMIN 36
841 * SES Data Structures
845 uint32_t GenCode; /* Generation Code */
846 uint8_t Nsubenc; /* Number of Subenclosures */
850 uint8_t Subencid; /* SubEnclosure Identifier */
851 uint8_t Ntypes; /* # of supported types */
852 uint8_t VEnclen; /* Enclosure Descriptor Length */
856 uint8_t encWWN[8]; /* XXX- Not Right Yet */
864 uint8_t enc_type; /* type of element */
865 uint8_t enc_maxelt; /* maximum supported */
866 uint8_t enc_subenc; /* in SubEnc # N */
867 uint8_t enc_tlen; /* Type Descriptor Text Length */
881 uint8_t ses_ntypes; /* total number of types supported */
884 * We need to keep a type index as well as an
885 * object index for each object in an enclosure.
887 struct typidx *ses_typidx;
890 * We also need to keep track of the number of elements
891 * per type of element. This is needed later so that we
892 * can find precisely in the returned status data the
893 * status for the Nth element of the Kth type.
895 uint8_t * ses_eltmap;
900 * (de)canonicalization defines
902 #define sbyte(x, byte) ((((uint32_t)(x)) >> (byte * 8)) & 0xff)
903 #define sbit(x, bit) (((uint32_t)(x)) << bit)
904 #define sset8(outp, idx, sval) (((uint8_t *)(outp))[idx++]) = sbyte(sval, 0)
906 #define sset16(outp, idx, sval) \
907 (((uint8_t *)(outp))[idx++]) = sbyte(sval, 1), \
908 (((uint8_t *)(outp))[idx++]) = sbyte(sval, 0)
911 #define sset24(outp, idx, sval) \
912 (((uint8_t *)(outp))[idx++]) = sbyte(sval, 2), \
913 (((uint8_t *)(outp))[idx++]) = sbyte(sval, 1), \
914 (((uint8_t *)(outp))[idx++]) = sbyte(sval, 0)
917 #define sset32(outp, idx, sval) \
918 (((uint8_t *)(outp))[idx++]) = sbyte(sval, 3), \
919 (((uint8_t *)(outp))[idx++]) = sbyte(sval, 2), \
920 (((uint8_t *)(outp))[idx++]) = sbyte(sval, 1), \
921 (((uint8_t *)(outp))[idx++]) = sbyte(sval, 0)
923 #define gbyte(x, byte) ((((uint32_t)(x)) & 0xff) << (byte * 8))
924 #define gbit(lv, in, idx, shft, mask) lv = ((in[idx] >> shft) & mask)
925 #define sget8(inp, idx, lval) lval = (((uint8_t *)(inp))[idx++])
926 #define gget8(inp, idx, lval) lval = (((uint8_t *)(inp))[idx])
928 #define sget16(inp, idx, lval) \
929 lval = gbyte((((uint8_t *)(inp))[idx]), 1) | \
930 (((uint8_t *)(inp))[idx+1]), idx += 2
932 #define gget16(inp, idx, lval) \
933 lval = gbyte((((uint8_t *)(inp))[idx]), 1) | \
934 (((uint8_t *)(inp))[idx+1])
936 #define sget24(inp, idx, lval) \
937 lval = gbyte((((uint8_t *)(inp))[idx]), 2) | \
938 gbyte((((uint8_t *)(inp))[idx+1]), 1) | \
939 (((uint8_t *)(inp))[idx+2]), idx += 3
941 #define gget24(inp, idx, lval) \
942 lval = gbyte((((uint8_t *)(inp))[idx]), 2) | \
943 gbyte((((uint8_t *)(inp))[idx+1]), 1) | \
944 (((uint8_t *)(inp))[idx+2])
946 #define sget32(inp, idx, lval) \
947 lval = gbyte((((uint8_t *)(inp))[idx]), 3) | \
948 gbyte((((uint8_t *)(inp))[idx+1]), 2) | \
949 gbyte((((uint8_t *)(inp))[idx+2]), 1) | \
950 (((uint8_t *)(inp))[idx+3]), idx += 4
952 #define gget32(inp, idx, lval) \
953 lval = gbyte((((uint8_t *)(inp))[idx]), 3) | \
954 gbyte((((uint8_t *)(inp))[idx+1]), 2) | \
955 gbyte((((uint8_t *)(inp))[idx+2]), 1) | \
956 (((uint8_t *)(inp))[idx+3])
959 #define CFLEN (256 + SES_ENCHDR_MINLEN)
962 * Routines specific && private to SES only
965 static int ses_getconfig(ses_softc_t *);
966 static int ses_getputstat(ses_softc_t *, int, SesComStat *, int, int);
967 static int ses_cfghdr(uint8_t *, int, SesCfgHdr *);
968 static int ses_enchdr(uint8_t *, int, uint8_t, SesEncHdr *);
969 static int ses_encdesc(uint8_t *, int, uint8_t, SesEncDesc *);
970 static int ses_getthdr(uint8_t *, int, int, SesThdr *);
971 static int ses_decode(char *, int, uint8_t *, int, int, SesComStat *);
972 static int ses_encode(char *, int, uint8_t *, int, int, SesComStat *);
975 ses_softc_init(ses_softc_t *ssc, int doinit)
979 if (ssc->ses_nobjects) {
980 SES_FREE(ssc->ses_objmap,
981 ssc->ses_nobjects * sizeof (encobj));
982 ssc->ses_objmap = NULL;
984 if ((cc = ssc->ses_private) != NULL) {
985 if (cc->ses_eltmap && cc->ses_ntypes) {
986 SES_FREE(cc->ses_eltmap, cc->ses_ntypes);
987 cc->ses_eltmap = NULL;
990 if (cc->ses_typidx && ssc->ses_nobjects) {
991 SES_FREE(cc->ses_typidx,
992 ssc->ses_nobjects * sizeof (struct typidx));
993 cc->ses_typidx = NULL;
995 SES_FREE(cc, sizeof (struct sscfg));
996 ssc->ses_private = NULL;
998 ssc->ses_nobjects = 0;
1001 if (ssc->ses_private == NULL) {
1002 ssc->ses_private = SES_MALLOC(sizeof (struct sscfg));
1004 if (ssc->ses_private == NULL) {
1007 ssc->ses_nobjects = 0;
1008 ssc->ses_encstat = 0;
1009 return (ses_getconfig(ssc));
1013 ses_init_enc(ses_softc_t *ssc)
1019 ses_get_encstat(ses_softc_t *ssc, int slpflag)
1024 if ((status = ses_getputstat(ssc, -1, &ComStat, slpflag, 1)) != 0) {
1027 ssc->ses_encstat = ComStat.comstatus | ENCI_SVALID;
1032 ses_set_encstat(ses_softc_t *ssc, uint8_t encstat, int slpflag)
1037 ComStat.comstatus = encstat & 0xf;
1038 if ((status = ses_getputstat(ssc, -1, &ComStat, slpflag, 0)) != 0) {
1041 ssc->ses_encstat = encstat & 0xf; /* note no SVALID set */
1046 ses_get_objstat(ses_softc_t *ssc, ses_objstat *obp, int slpflag)
1048 int i = (int)obp->obj_id;
1050 if (ssc->ses_objmap[i].svalid == 0) {
1052 int err = ses_getputstat(ssc, i, &ComStat, slpflag, 1);
1055 ssc->ses_objmap[i].encstat[0] = ComStat.comstatus;
1056 ssc->ses_objmap[i].encstat[1] = ComStat.comstat[0];
1057 ssc->ses_objmap[i].encstat[2] = ComStat.comstat[1];
1058 ssc->ses_objmap[i].encstat[3] = ComStat.comstat[2];
1059 ssc->ses_objmap[i].svalid = 1;
1061 obp->cstat[0] = ssc->ses_objmap[i].encstat[0];
1062 obp->cstat[1] = ssc->ses_objmap[i].encstat[1];
1063 obp->cstat[2] = ssc->ses_objmap[i].encstat[2];
1064 obp->cstat[3] = ssc->ses_objmap[i].encstat[3];
1069 ses_set_objstat(ses_softc_t *ssc, ses_objstat *obp, int slpflag)
1074 * If this is clear, we don't do diddly.
1076 if ((obp->cstat[0] & SESCTL_CSEL) == 0) {
1079 ComStat.comstatus = obp->cstat[0];
1080 ComStat.comstat[0] = obp->cstat[1];
1081 ComStat.comstat[1] = obp->cstat[2];
1082 ComStat.comstat[2] = obp->cstat[3];
1083 err = ses_getputstat(ssc, (int)obp->obj_id, &ComStat, slpflag, 0);
1084 ssc->ses_objmap[(int)obp->obj_id].svalid = 0;
1089 ses_getconfig(ses_softc_t *ssc)
1096 int err, amt, i, nobj, ntype, maxima;
1097 char storage[CFLEN], *sdata;
1098 static char cdb[6] = {
1099 RECEIVE_DIAGNOSTIC, 0x1, SesConfigPage, SCSZ >> 8, SCSZ & 0xff, 0
1102 cc = ssc->ses_private;
1107 sdata = SES_MALLOC(SCSZ);
1112 err = ses_runcmd(ssc, cdb, 6, sdata, &amt);
1114 SES_FREE(sdata, SCSZ);
1119 if (ses_cfghdr((uint8_t *) sdata, amt, &cf)) {
1120 SES_LOG(ssc, "Unable to parse SES Config Header\n");
1121 SES_FREE(sdata, SCSZ);
1124 if (amt < SES_ENCHDR_MINLEN) {
1125 SES_LOG(ssc, "runt enclosure length (%d)\n", amt);
1126 SES_FREE(sdata, SCSZ);
1130 SES_VLOG(ssc, "GenCode %x %d Subenclosures\n", cf.GenCode, cf.Nsubenc);
1133 * Now waltz through all the subenclosures toting up the
1134 * number of types available in each. For this, we only
1135 * really need the enclosure header. However, we get the
1136 * enclosure descriptor for debug purposes, as well
1137 * as self-consistency checking purposes.
1140 maxima = cf.Nsubenc + 1;
1141 cdp = (SesEncDesc *) storage;
1142 for (ntype = i = 0; i < maxima; i++) {
1143 MEMZERO((caddr_t)cdp, sizeof (*cdp));
1144 if (ses_enchdr((uint8_t *) sdata, amt, i, &hd)) {
1145 SES_LOG(ssc, "Cannot Extract Enclosure Header %d\n", i);
1146 SES_FREE(sdata, SCSZ);
1149 SES_VLOG(ssc, " SubEnclosure ID %d, %d Types With this ID, En"
1150 "closure Length %d\n", hd.Subencid, hd.Ntypes, hd.VEnclen);
1152 if (ses_encdesc((uint8_t *)sdata, amt, i, cdp)) {
1153 SES_LOG(ssc, "Can't get Enclosure Descriptor %d\n", i);
1154 SES_FREE(sdata, SCSZ);
1157 SES_VLOG(ssc, " WWN: %02x%02x%02x%02x%02x%02x%02x%02x\n",
1158 cdp->encWWN[0], cdp->encWWN[1], cdp->encWWN[2],
1159 cdp->encWWN[3], cdp->encWWN[4], cdp->encWWN[5],
1160 cdp->encWWN[6], cdp->encWWN[7]);
1165 * Now waltz through all the types that are available, getting
1166 * the type header so we can start adding up the number of
1167 * objects available.
1169 for (nobj = i = 0; i < ntype; i++) {
1170 if (ses_getthdr((uint8_t *)sdata, amt, i, &thdr)) {
1171 SES_LOG(ssc, "Can't get Enclosure Type Header %d\n", i);
1172 SES_FREE(sdata, SCSZ);
1175 SES_LOG(ssc, " Type Desc[%d]: Type 0x%x, MaxElt %d, In Subenc "
1176 "%d, Text Length %d\n", i, thdr.enc_type, thdr.enc_maxelt,
1177 thdr.enc_subenc, thdr.enc_tlen);
1178 nobj += thdr.enc_maxelt;
1183 * Now allocate the object array and type map.
1186 ssc->ses_objmap = SES_MALLOC(nobj * sizeof (encobj));
1187 cc->ses_typidx = SES_MALLOC(nobj * sizeof (struct typidx));
1188 cc->ses_eltmap = SES_MALLOC(ntype);
1190 if (ssc->ses_objmap == NULL || cc->ses_typidx == NULL ||
1191 cc->ses_eltmap == NULL) {
1192 if (ssc->ses_objmap) {
1193 SES_FREE(ssc->ses_objmap, (nobj * sizeof (encobj)));
1194 ssc->ses_objmap = NULL;
1196 if (cc->ses_typidx) {
1197 SES_FREE(cc->ses_typidx,
1198 (nobj * sizeof (struct typidx)));
1199 cc->ses_typidx = NULL;
1201 if (cc->ses_eltmap) {
1202 SES_FREE(cc->ses_eltmap, ntype);
1203 cc->ses_eltmap = NULL;
1205 SES_FREE(sdata, SCSZ);
1208 MEMZERO(ssc->ses_objmap, nobj * sizeof (encobj));
1209 MEMZERO(cc->ses_typidx, nobj * sizeof (struct typidx));
1210 MEMZERO(cc->ses_eltmap, ntype);
1211 cc->ses_ntypes = (uint8_t) ntype;
1212 ssc->ses_nobjects = nobj;
1215 * Now waltz through the # of types again to fill in the types
1216 * (and subenclosure ids) of the allocated objects.
1219 for (i = 0; i < ntype; i++) {
1221 if (ses_getthdr((uint8_t *)sdata, amt, i, &thdr)) {
1224 cc->ses_eltmap[i] = thdr.enc_maxelt;
1225 for (j = 0; j < thdr.enc_maxelt; j++) {
1226 cc->ses_typidx[nobj].ses_tidx = i;
1227 cc->ses_typidx[nobj].ses_oidx = j;
1228 ssc->ses_objmap[nobj].subenclosure = thdr.enc_subenc;
1229 ssc->ses_objmap[nobj++].enctype = thdr.enc_type;
1232 SES_FREE(sdata, SCSZ);
1237 ses_getputstat(ses_softc_t *ssc, int objid, SesComStat *sp, int slp, int in)
1240 int err, amt, bufsiz, tidx, oidx;
1241 char cdb[6], *sdata;
1243 cc = ssc->ses_private;
1249 * If we're just getting overall enclosure status,
1250 * we only need 2 bytes of data storage.
1252 * If we're getting anything else, we know how much
1253 * storage we need by noting that starting at offset
1254 * 8 in returned data, all object status bytes are 4
1255 * bytes long, and are stored in chunks of types(M)
1256 * and nth+1 instances of type M.
1261 bufsiz = (ssc->ses_nobjects * 4) + (cc->ses_ntypes * 4) + 8;
1263 sdata = SES_MALLOC(bufsiz);
1267 cdb[0] = RECEIVE_DIAGNOSTIC;
1269 cdb[2] = SesStatusPage;
1270 cdb[3] = bufsiz >> 8;
1271 cdb[4] = bufsiz & 0xff;
1274 err = ses_runcmd(ssc, cdb, 6, sdata, &amt);
1276 SES_FREE(sdata, bufsiz);
1285 tidx = cc->ses_typidx[objid].ses_tidx;
1286 oidx = cc->ses_typidx[objid].ses_oidx;
1289 if (ses_decode(sdata, amt, cc->ses_eltmap, tidx, oidx, sp)) {
1293 if (ses_encode(sdata, amt, cc->ses_eltmap, tidx, oidx, sp)) {
1296 cdb[0] = SEND_DIAGNOSTIC;
1299 cdb[3] = bufsiz >> 8;
1300 cdb[4] = bufsiz & 0xff;
1303 err = ses_runcmd(ssc, cdb, 6, sdata, &amt);
1306 SES_FREE(sdata, bufsiz);
1312 * Routines to parse returned SES data structures.
1313 * Architecture and compiler independent.
1317 ses_cfghdr(uint8_t *buffer, int buflen, SesCfgHdr *cfp)
1319 if (buflen < SES_CFGHDR_MINLEN) {
1322 gget8(buffer, 1, cfp->Nsubenc);
1323 gget32(buffer, 4, cfp->GenCode);
1328 ses_enchdr(uint8_t *buffer, int amt, uint8_t SubEncId, SesEncHdr *chp)
1331 for (s = 0; s < SubEncId; s++) {
1334 off += buffer[off+3] + 4;
1336 if (off + 3 > amt) {
1339 gget8(buffer, off+1, chp->Subencid);
1340 gget8(buffer, off+2, chp->Ntypes);
1341 gget8(buffer, off+3, chp->VEnclen);
1346 ses_encdesc(uint8_t *buffer, int amt, uint8_t SubEncId, SesEncDesc *cdp)
1348 int s, e, enclen, off = 8;
1349 for (s = 0; s < SubEncId; s++) {
1352 off += buffer[off+3] + 4;
1354 if (off + 3 > amt) {
1357 gget8(buffer, off+3, enclen);
1366 MEMCPY(cdp, &buffer[off], e - off);
1371 ses_getthdr(uint8_t *buffer, int amt, int nth, SesThdr *thp)
1375 if (amt < SES_CFGHDR_MINLEN) {
1378 for (s = 0; s < buffer[1]; s++) {
1381 off += buffer[off+3] + 4;
1383 if (off + 3 > amt) {
1386 off += buffer[off+3] + 4 + (nth * 4);
1387 if (amt < (off + 4))
1390 gget8(buffer, off++, thp->enc_type);
1391 gget8(buffer, off++, thp->enc_maxelt);
1392 gget8(buffer, off++, thp->enc_subenc);
1393 gget8(buffer, off, thp->enc_tlen);
1398 * This function needs a little explanation.
1400 * The arguments are:
1405 * These describes the raw input SES status data and length.
1409 * This is a map of the number of types for each element type
1414 * This is the element type being sought. If elt is -1,
1415 * then overall enclosure status is being sought.
1419 * This is the ordinal Mth element of type elt being sought.
1423 * This is the output area to store the status for
1424 * the Mth element of type Elt.
1428 ses_decode(char *b, int amt, uint8_t *ep, int elt, int elm, SesComStat *sp)
1433 * If it's overall enclosure status being sought, get that.
1434 * We need at least 2 bytes of status data to get that.
1439 gget8(b, 1, sp->comstatus);
1447 * Check to make sure that the Mth element is legal for type Elt.
1454 * Starting at offset 8, start skipping over the storage
1455 * for the element types we're not interested in.
1457 for (idx = 8, i = 0; i < elt; i++) {
1458 idx += ((ep[i] + 1) * 4);
1462 * Skip over Overall status for this element type.
1467 * And skip to the index for the Mth element that we're going for.
1472 * Make sure we haven't overflowed the buffer.
1478 * Retrieve the status.
1480 gget8(b, idx++, sp->comstatus);
1481 gget8(b, idx++, sp->comstat[0]);
1482 gget8(b, idx++, sp->comstat[1]);
1483 gget8(b, idx++, sp->comstat[2]);
1485 PRINTF("Get Elt 0x%x Elm 0x%x (idx %d)\n", elt, elm, idx-4);
1491 * This is the mirror function to ses_decode, but we set the 'select'
1492 * bit for the object which we're interested in. All other objects,
1493 * after a status fetch, should have that bit off. Hmm. It'd be easy
1494 * enough to ensure this, so we will.
1498 ses_encode(char *b, int amt, uint8_t *ep, int elt, int elm, SesComStat *sp)
1503 * If it's overall enclosure status being sought, get that.
1504 * We need at least 2 bytes of status data to get that.
1511 sset8(b, i, sp->comstatus & 0xf);
1513 PRINTF("set EncStat %x\n", sp->comstatus);
1519 * Check to make sure that the Mth element is legal for type Elt.
1526 * Starting at offset 8, start skipping over the storage
1527 * for the element types we're not interested in.
1529 for (idx = 8, i = 0; i < elt; i++) {
1530 idx += ((ep[i] + 1) * 4);
1534 * Skip over Overall status for this element type.
1539 * And skip to the index for the Mth element that we're going for.
1544 * Make sure we haven't overflowed the buffer.
1552 sset8(b, idx, sp->comstatus);
1553 sset8(b, idx, sp->comstat[0]);
1554 sset8(b, idx, sp->comstat[1]);
1555 sset8(b, idx, sp->comstat[2]);
1559 PRINTF("Set Elt 0x%x Elm 0x%x (idx %d) with %x %x %x %x\n",
1560 elt, elm, idx, sp->comstatus, sp->comstat[0],
1561 sp->comstat[1], sp->comstat[2]);
1565 * Now make sure all other 'Select' bits are off.
1567 for (i = 8; i < amt; i += 4) {
1572 * And make sure the INVOP bit is clear.
1580 * SAF-TE Type Device Emulation
1583 static int safte_getconfig(ses_softc_t *);
1584 static int safte_rdstat(ses_softc_t *, int);;
1585 static int set_objstat_sel(ses_softc_t *, ses_objstat *, int);
1586 static int wrbuf16(ses_softc_t *, uint8_t, uint8_t, uint8_t, uint8_t, int);
1587 static void wrslot_stat(ses_softc_t *, int);
1588 static int perf_slotop(ses_softc_t *, uint8_t, uint8_t, int);
1590 #define ALL_ENC_STAT (SES_ENCSTAT_CRITICAL | SES_ENCSTAT_UNRECOV | \
1591 SES_ENCSTAT_NONCRITICAL | SES_ENCSTAT_INFO)
1593 * SAF-TE specific defines- Mandatory ones only...
1597 * READ BUFFER ('get' commands) IDs- placed in offset 2 of cdb
1599 #define SAFTE_RD_RDCFG 0x00 /* read enclosure configuration */
1600 #define SAFTE_RD_RDESTS 0x01 /* read enclosure status */
1601 #define SAFTE_RD_RDDSTS 0x04 /* read drive slot status */
1604 * WRITE BUFFER ('set' commands) IDs- placed in offset 0 of databuf
1606 #define SAFTE_WT_DSTAT 0x10 /* write device slot status */
1607 #define SAFTE_WT_SLTOP 0x12 /* perform slot operation */
1608 #define SAFTE_WT_FANSPD 0x13 /* set fan speed */
1609 #define SAFTE_WT_ACTPWS 0x14 /* turn on/off power supply */
1610 #define SAFTE_WT_GLOBAL 0x15 /* send global command */
1613 #define SAFT_SCRATCH 64
1614 #define NPSEUDO_THERM 16
1615 #define NPSEUDO_ALARM 1
1618 * Cached Configuration
1620 uint8_t Nfans; /* Number of Fans */
1621 uint8_t Npwr; /* Number of Power Supplies */
1622 uint8_t Nslots; /* Number of Device Slots */
1623 uint8_t DoorLock; /* Door Lock Installed */
1624 uint8_t Ntherm; /* Number of Temperature Sensors */
1625 uint8_t Nspkrs; /* Number of Speakers */
1626 uint8_t Nalarm; /* Number of Alarms (at least one) */
1628 * Cached Flag Bytes for Global Status
1633 * What object index ID is where various slots start.
1637 #define SAFT_ALARM_OFFSET(cc) (cc)->slotoff - 1
1640 #define SAFT_FLG1_ALARM 0x1
1641 #define SAFT_FLG1_GLOBFAIL 0x2
1642 #define SAFT_FLG1_GLOBWARN 0x4
1643 #define SAFT_FLG1_ENCPWROFF 0x8
1644 #define SAFT_FLG1_ENCFANFAIL 0x10
1645 #define SAFT_FLG1_ENCPWRFAIL 0x20
1646 #define SAFT_FLG1_ENCDRVFAIL 0x40
1647 #define SAFT_FLG1_ENCDRVWARN 0x80
1649 #define SAFT_FLG2_LOCKDOOR 0x4
1650 #define SAFT_PRIVATE sizeof (struct scfg)
1652 static char *safte_2little = "Too Little Data Returned (%d) at line %d\n";
1653 #define SAFT_BAIL(r, x, k, l) \
1655 SES_LOG(ssc, safte_2little, x, __LINE__);\
1662 safte_softc_init(ses_softc_t *ssc, int doinit)
1668 if (ssc->ses_nobjects) {
1669 if (ssc->ses_objmap) {
1670 SES_FREE(ssc->ses_objmap,
1671 ssc->ses_nobjects * sizeof (encobj));
1672 ssc->ses_objmap = NULL;
1674 ssc->ses_nobjects = 0;
1676 if (ssc->ses_private) {
1677 SES_FREE(ssc->ses_private, SAFT_PRIVATE);
1678 ssc->ses_private = NULL;
1683 if (ssc->ses_private == NULL) {
1684 ssc->ses_private = SES_MALLOC(SAFT_PRIVATE);
1685 if (ssc->ses_private == NULL) {
1688 MEMZERO(ssc->ses_private, SAFT_PRIVATE);
1691 ssc->ses_nobjects = 0;
1692 ssc->ses_encstat = 0;
1694 if ((err = safte_getconfig(ssc)) != 0) {
1699 * The number of objects here, as well as that reported by the
1700 * READ_BUFFER/GET_CONFIG call, are the over-temperature flags (15)
1701 * that get reported during READ_BUFFER/READ_ENC_STATUS.
1703 cc = ssc->ses_private;
1704 ssc->ses_nobjects = cc->Nfans + cc->Npwr + cc->Nslots + cc->DoorLock +
1705 cc->Ntherm + cc->Nspkrs + NPSEUDO_THERM + NPSEUDO_ALARM;
1706 ssc->ses_objmap = (encobj *)
1707 SES_MALLOC(ssc->ses_nobjects * sizeof (encobj));
1708 if (ssc->ses_objmap == NULL) {
1711 MEMZERO(ssc->ses_objmap, ssc->ses_nobjects * sizeof (encobj));
1715 * Note that this is all arranged for the convenience
1716 * in later fetches of status.
1718 for (i = 0; i < cc->Nfans; i++)
1719 ssc->ses_objmap[r++].enctype = SESTYP_FAN;
1720 cc->pwroff = (uint8_t) r;
1721 for (i = 0; i < cc->Npwr; i++)
1722 ssc->ses_objmap[r++].enctype = SESTYP_POWER;
1723 for (i = 0; i < cc->DoorLock; i++)
1724 ssc->ses_objmap[r++].enctype = SESTYP_DOORLOCK;
1725 for (i = 0; i < cc->Nspkrs; i++)
1726 ssc->ses_objmap[r++].enctype = SESTYP_ALARM;
1727 for (i = 0; i < cc->Ntherm; i++)
1728 ssc->ses_objmap[r++].enctype = SESTYP_THERM;
1729 for (i = 0; i < NPSEUDO_THERM; i++)
1730 ssc->ses_objmap[r++].enctype = SESTYP_THERM;
1731 ssc->ses_objmap[r++].enctype = SESTYP_ALARM;
1732 cc->slotoff = (uint8_t) r;
1733 for (i = 0; i < cc->Nslots; i++)
1734 ssc->ses_objmap[r++].enctype = SESTYP_DEVICE;
1739 safte_init_enc(ses_softc_t *ssc)
1742 static char cdb0[6] = { SEND_DIAGNOSTIC };
1744 err = ses_runcmd(ssc, cdb0, 6, NULL, 0);
1749 err = wrbuf16(ssc, SAFTE_WT_GLOBAL, 0, 0, 0, 1);
1754 safte_get_encstat(ses_softc_t *ssc, int slpflg)
1756 return (safte_rdstat(ssc, slpflg));
1760 safte_set_encstat(ses_softc_t *ssc, uint8_t encstat, int slpflg)
1762 struct scfg *cc = ssc->ses_private;
1766 * Since SAF-TE devices aren't necessarily sticky in terms
1767 * of state, make our soft copy of enclosure status 'sticky'-
1768 * that is, things set in enclosure status stay set (as implied
1769 * by conditions set in reading object status) until cleared.
1771 ssc->ses_encstat &= ~ALL_ENC_STAT;
1772 ssc->ses_encstat |= (encstat & ALL_ENC_STAT);
1773 ssc->ses_encstat |= ENCI_SVALID;
1774 cc->flag1 &= ~(SAFT_FLG1_ALARM|SAFT_FLG1_GLOBFAIL|SAFT_FLG1_GLOBWARN);
1775 if ((encstat & (SES_ENCSTAT_CRITICAL|SES_ENCSTAT_UNRECOV)) != 0) {
1776 cc->flag1 |= SAFT_FLG1_ALARM|SAFT_FLG1_GLOBFAIL;
1777 } else if ((encstat & SES_ENCSTAT_NONCRITICAL) != 0) {
1778 cc->flag1 |= SAFT_FLG1_GLOBWARN;
1780 return (wrbuf16(ssc, SAFTE_WT_GLOBAL, cc->flag1, cc->flag2, 0, slpflg));
1784 safte_get_objstat(ses_softc_t *ssc, ses_objstat *obp, int slpflg)
1786 int i = (int)obp->obj_id;
1788 if ((ssc->ses_encstat & ENCI_SVALID) == 0 ||
1789 (ssc->ses_objmap[i].svalid) == 0) {
1790 int err = safte_rdstat(ssc, slpflg);
1794 obp->cstat[0] = ssc->ses_objmap[i].encstat[0];
1795 obp->cstat[1] = ssc->ses_objmap[i].encstat[1];
1796 obp->cstat[2] = ssc->ses_objmap[i].encstat[2];
1797 obp->cstat[3] = ssc->ses_objmap[i].encstat[3];
1803 safte_set_objstat(ses_softc_t *ssc, ses_objstat *obp, int slp)
1810 SES_DLOG(ssc, "safte_set_objstat(%d): %x %x %x %x\n",
1811 (int)obp->obj_id, obp->cstat[0], obp->cstat[1], obp->cstat[2],
1815 * If this is clear, we don't do diddly.
1817 if ((obp->cstat[0] & SESCTL_CSEL) == 0) {
1823 * Check to see if the common bits are set and do them first.
1825 if (obp->cstat[0] & ~SESCTL_CSEL) {
1826 err = set_objstat_sel(ssc, obp, slp);
1831 cc = ssc->ses_private;
1835 idx = (int)obp->obj_id;
1836 ep = &ssc->ses_objmap[idx];
1838 switch (ep->enctype) {
1843 * XXX: I should probably cache the previous state
1844 * XXX: of SESCTL_DEVOFF so that when it goes from
1845 * XXX: true to false I can then set PREPARE FOR OPERATION
1846 * XXX: flag in PERFORM SLOT OPERATION write buffer command.
1848 if (obp->cstat[2] & (SESCTL_RQSINS|SESCTL_RQSRMV)) {
1851 if (obp->cstat[2] & SESCTL_RQSID) {
1854 err = perf_slotop(ssc, (uint8_t) idx - (uint8_t) cc->slotoff,
1858 if (obp->cstat[3] & SESCTL_RQSFLT) {
1863 if (ep->priv & 0xc6) {
1866 ep->priv |= 0x1; /* no errors */
1868 wrslot_stat(ssc, slp);
1872 if (obp->cstat[3] & SESCTL_RQSTFAIL) {
1873 cc->flag1 |= SAFT_FLG1_ENCPWRFAIL;
1875 cc->flag1 &= ~SAFT_FLG1_ENCPWRFAIL;
1877 err = wrbuf16(ssc, SAFTE_WT_GLOBAL, cc->flag1,
1881 if (obp->cstat[3] & SESCTL_RQSTON) {
1882 (void) wrbuf16(ssc, SAFTE_WT_ACTPWS,
1883 idx - cc->pwroff, 0, 0, slp);
1885 (void) wrbuf16(ssc, SAFTE_WT_ACTPWS,
1886 idx - cc->pwroff, 0, 1, slp);
1890 if (obp->cstat[3] & SESCTL_RQSTFAIL) {
1891 cc->flag1 |= SAFT_FLG1_ENCFANFAIL;
1893 cc->flag1 &= ~SAFT_FLG1_ENCFANFAIL;
1895 err = wrbuf16(ssc, SAFTE_WT_GLOBAL, cc->flag1,
1899 if (obp->cstat[3] & SESCTL_RQSTON) {
1901 if ((obp->cstat[3] & 0x7) == 7) {
1903 } else if ((obp->cstat[3] & 0x7) == 6) {
1905 } else if ((obp->cstat[3] & 0x7) == 4) {
1910 (void) wrbuf16(ssc, SAFTE_WT_FANSPD, idx, fsp, 0, slp);
1912 (void) wrbuf16(ssc, SAFTE_WT_FANSPD, idx, 0, 0, slp);
1915 case SESTYP_DOORLOCK:
1916 if (obp->cstat[3] & 0x1) {
1917 cc->flag2 &= ~SAFT_FLG2_LOCKDOOR;
1919 cc->flag2 |= SAFT_FLG2_LOCKDOOR;
1921 (void) wrbuf16(ssc, SAFTE_WT_GLOBAL, cc->flag1,
1926 * On all nonzero but the 'muted' bit, we turn on the alarm,
1928 obp->cstat[3] &= ~0xa;
1929 if (obp->cstat[3] & 0x40) {
1930 cc->flag2 &= ~SAFT_FLG1_ALARM;
1931 } else if (obp->cstat[3] != 0) {
1932 cc->flag2 |= SAFT_FLG1_ALARM;
1934 cc->flag2 &= ~SAFT_FLG1_ALARM;
1936 ep->priv = obp->cstat[3];
1937 (void) wrbuf16(ssc, SAFTE_WT_GLOBAL, cc->flag1,
1948 safte_getconfig(ses_softc_t *ssc)
1953 static char cdb[10] =
1954 { READ_BUFFER, 1, SAFTE_RD_RDCFG, 0, 0, 0, 0, 0, SAFT_SCRATCH, 0 };
1956 cfg = ssc->ses_private;
1960 sdata = SES_MALLOC(SAFT_SCRATCH);
1965 err = ses_runcmd(ssc, cdb, 10, sdata, &amt);
1967 SES_FREE(sdata, SAFT_SCRATCH);
1970 amt = SAFT_SCRATCH - amt;
1972 SES_LOG(ssc, "too little data (%d) for configuration\n", amt);
1973 SES_FREE(sdata, SAFT_SCRATCH);
1976 SES_VLOG(ssc, "Nfans %d Npwr %d Nslots %d Lck %d Ntherm %d Nspkrs %d\n",
1977 sdata[0], sdata[1], sdata[2], sdata[3], sdata[4], sdata[5]);
1978 cfg->Nfans = sdata[0];
1979 cfg->Npwr = sdata[1];
1980 cfg->Nslots = sdata[2];
1981 cfg->DoorLock = sdata[3];
1982 cfg->Ntherm = sdata[4];
1983 cfg->Nspkrs = sdata[5];
1984 cfg->Nalarm = NPSEUDO_ALARM;
1985 SES_FREE(sdata, SAFT_SCRATCH);
1990 safte_rdstat(ses_softc_t *ssc, int slpflg)
1992 int err, oid, r, i, hiwater, nitems, amt;
1995 uint8_t status, oencstat;
1996 char *sdata, cdb[10];
1997 struct scfg *cc = ssc->ses_private;
2001 * The number of objects overstates things a bit,
2002 * both for the bogus 'thermometer' entries and
2003 * the drive status (which isn't read at the same
2004 * time as the enclosure status), but that's okay.
2006 buflen = 4 * cc->Nslots;
2007 if (ssc->ses_nobjects > buflen)
2008 buflen = ssc->ses_nobjects;
2009 sdata = SES_MALLOC(buflen);
2013 cdb[0] = READ_BUFFER;
2015 cdb[2] = SAFTE_RD_RDESTS;
2020 cdb[7] = (buflen >> 8) & 0xff;
2021 cdb[8] = buflen & 0xff;
2024 err = ses_runcmd(ssc, cdb, 10, sdata, &amt);
2026 SES_FREE(sdata, buflen);
2029 hiwater = buflen - amt;
2033 * invalidate all status bits.
2035 for (i = 0; i < ssc->ses_nobjects; i++)
2036 ssc->ses_objmap[i].svalid = 0;
2037 oencstat = ssc->ses_encstat & ALL_ENC_STAT;
2038 ssc->ses_encstat = 0;
2042 * Now parse returned buffer.
2043 * If we didn't get enough data back,
2044 * that's considered a fatal error.
2048 for (nitems = i = 0; i < cc->Nfans; i++) {
2049 SAFT_BAIL(r, hiwater, sdata, buflen);
2051 * 0 = Fan Operational
2052 * 1 = Fan is malfunctioning
2053 * 2 = Fan is not present
2054 * 0x80 = Unknown or Not Reportable Status
2056 ssc->ses_objmap[oid].encstat[1] = 0; /* resvd */
2057 ssc->ses_objmap[oid].encstat[2] = 0; /* resvd */
2058 switch ((int)(uint8_t)sdata[r]) {
2061 ssc->ses_objmap[oid].encstat[0] = SES_OBJSTAT_OK;
2063 * We could get fancier and cache
2064 * fan speeds that we have set, but
2065 * that isn't done now.
2067 ssc->ses_objmap[oid].encstat[3] = 7;
2071 ssc->ses_objmap[oid].encstat[0] = SES_OBJSTAT_CRIT;
2073 * FAIL and FAN STOPPED synthesized
2075 ssc->ses_objmap[oid].encstat[3] = 0x40;
2077 * Enclosure marked with CRITICAL error
2078 * if only one fan or no thermometers,
2079 * else the NONCRITICAL error is set.
2081 if (cc->Nfans == 1 || cc->Ntherm == 0)
2082 ssc->ses_encstat |= SES_ENCSTAT_CRITICAL;
2084 ssc->ses_encstat |= SES_ENCSTAT_NONCRITICAL;
2087 ssc->ses_objmap[oid].encstat[0] =
2088 SES_OBJSTAT_NOTINSTALLED;
2089 ssc->ses_objmap[oid].encstat[3] = 0;
2091 * Enclosure marked with CRITICAL error
2092 * if only one fan or no thermometers,
2093 * else the NONCRITICAL error is set.
2096 ssc->ses_encstat |= SES_ENCSTAT_CRITICAL;
2098 ssc->ses_encstat |= SES_ENCSTAT_NONCRITICAL;
2101 ssc->ses_objmap[oid].encstat[0] = SES_OBJSTAT_UNKNOWN;
2102 ssc->ses_objmap[oid].encstat[3] = 0;
2103 ssc->ses_encstat |= SES_ENCSTAT_INFO;
2106 ssc->ses_objmap[oid].encstat[0] =
2107 SES_OBJSTAT_UNSUPPORTED;
2108 SES_LOG(ssc, "Unknown fan%d status 0x%x\n", i,
2112 ssc->ses_objmap[oid++].svalid = 1;
2117 * No matter how you cut it, no cooling elements when there
2118 * should be some there is critical.
2120 if (cc->Nfans && nitems == 0) {
2121 ssc->ses_encstat |= SES_ENCSTAT_CRITICAL;
2125 for (i = 0; i < cc->Npwr; i++) {
2126 SAFT_BAIL(r, hiwater, sdata, buflen);
2127 ssc->ses_objmap[oid].encstat[0] = SES_OBJSTAT_UNKNOWN;
2128 ssc->ses_objmap[oid].encstat[1] = 0; /* resvd */
2129 ssc->ses_objmap[oid].encstat[2] = 0; /* resvd */
2130 ssc->ses_objmap[oid].encstat[3] = 0x20; /* requested on */
2131 switch ((uint8_t)sdata[r]) {
2132 case 0x00: /* pws operational and on */
2133 ssc->ses_objmap[oid].encstat[0] = SES_OBJSTAT_OK;
2135 case 0x01: /* pws operational and off */
2136 ssc->ses_objmap[oid].encstat[0] = SES_OBJSTAT_OK;
2137 ssc->ses_objmap[oid].encstat[3] = 0x10;
2138 ssc->ses_encstat |= SES_ENCSTAT_INFO;
2140 case 0x10: /* pws is malfunctioning and commanded on */
2141 ssc->ses_objmap[oid].encstat[0] = SES_OBJSTAT_CRIT;
2142 ssc->ses_objmap[oid].encstat[3] = 0x61;
2143 ssc->ses_encstat |= SES_ENCSTAT_NONCRITICAL;
2146 case 0x11: /* pws is malfunctioning and commanded off */
2147 ssc->ses_objmap[oid].encstat[0] = SES_OBJSTAT_NONCRIT;
2148 ssc->ses_objmap[oid].encstat[3] = 0x51;
2149 ssc->ses_encstat |= SES_ENCSTAT_NONCRITICAL;
2151 case 0x20: /* pws is not present */
2152 ssc->ses_objmap[oid].encstat[0] =
2153 SES_OBJSTAT_NOTINSTALLED;
2154 ssc->ses_objmap[oid].encstat[3] = 0;
2155 ssc->ses_encstat |= SES_ENCSTAT_INFO;
2157 case 0x21: /* pws is present */
2159 * This is for enclosures that cannot tell whether the
2160 * device is on or malfunctioning, but know that it is
2161 * present. Just fall through.
2164 case 0x80: /* Unknown or Not Reportable Status */
2165 ssc->ses_objmap[oid].encstat[0] = SES_OBJSTAT_UNKNOWN;
2166 ssc->ses_objmap[oid].encstat[3] = 0;
2167 ssc->ses_encstat |= SES_ENCSTAT_INFO;
2170 SES_LOG(ssc, "unknown power supply %d status (0x%x)\n",
2171 i, sdata[r] & 0xff);
2174 ssc->ses_objmap[oid++].svalid = 1;
2179 * Skip over Slot SCSI IDs
2184 * We always have doorlock status, no matter what,
2185 * but we only save the status if we have one.
2187 SAFT_BAIL(r, hiwater, sdata, buflen);
2191 * 1 = Door Unlocked, or no Lock Installed
2192 * 0x80 = Unknown or Not Reportable Status
2194 ssc->ses_objmap[oid].encstat[1] = 0;
2195 ssc->ses_objmap[oid].encstat[2] = 0;
2196 switch ((uint8_t)sdata[r]) {
2198 ssc->ses_objmap[oid].encstat[0] = SES_OBJSTAT_OK;
2199 ssc->ses_objmap[oid].encstat[3] = 0;
2202 ssc->ses_objmap[oid].encstat[0] = SES_OBJSTAT_OK;
2203 ssc->ses_objmap[oid].encstat[3] = 1;
2206 ssc->ses_objmap[oid].encstat[0] = SES_OBJSTAT_UNKNOWN;
2207 ssc->ses_objmap[oid].encstat[3] = 0;
2208 ssc->ses_encstat |= SES_ENCSTAT_INFO;
2211 ssc->ses_objmap[oid].encstat[0] =
2212 SES_OBJSTAT_UNSUPPORTED;
2213 SES_LOG(ssc, "unknown lock status 0x%x\n",
2217 ssc->ses_objmap[oid++].svalid = 1;
2222 * We always have speaker status, no matter what,
2223 * but we only save the status if we have one.
2225 SAFT_BAIL(r, hiwater, sdata, buflen);
2227 ssc->ses_objmap[oid].encstat[1] = 0;
2228 ssc->ses_objmap[oid].encstat[2] = 0;
2229 if (sdata[r] == 1) {
2231 * We need to cache tone urgency indicators.
2234 ssc->ses_objmap[oid].encstat[0] = SES_OBJSTAT_NONCRIT;
2235 ssc->ses_objmap[oid].encstat[3] = 0x8;
2236 ssc->ses_encstat |= SES_ENCSTAT_NONCRITICAL;
2237 } else if (sdata[r] == 0) {
2238 ssc->ses_objmap[oid].encstat[0] = SES_OBJSTAT_OK;
2239 ssc->ses_objmap[oid].encstat[3] = 0;
2241 ssc->ses_objmap[oid].encstat[0] =
2242 SES_OBJSTAT_UNSUPPORTED;
2243 ssc->ses_objmap[oid].encstat[3] = 0;
2244 SES_LOG(ssc, "unknown spkr status 0x%x\n",
2247 ssc->ses_objmap[oid++].svalid = 1;
2251 for (i = 0; i < cc->Ntherm; i++) {
2252 SAFT_BAIL(r, hiwater, sdata, buflen);
2254 * Status is a range from -10 to 245 deg Celsius,
2255 * which we need to normalize to -20 to -245 according
2256 * to the latest SCSI spec, which makes little
2257 * sense since this would overflow an 8bit value.
2258 * Well, still, the base normalization is -20,
2259 * not -10, so we have to adjust.
2261 * So what's over and under temperature?
2262 * Hmm- we'll state that 'normal' operating
2263 * is 10 to 40 deg Celsius.
2267 * Actually.... All of the units that people out in the world
2268 * seem to have do not come even close to setting a value that
2269 * complies with this spec.
2271 * The closest explanation I could find was in an
2272 * LSI-Logic manual, which seemed to indicate that
2273 * this value would be set by whatever the I2C code
2274 * would interpolate from the output of an LM75
2275 * temperature sensor.
2277 * This means that it is impossible to use the actual
2278 * numeric value to predict anything. But we don't want
2279 * to lose the value. So, we'll propagate the *uncorrected*
2280 * value and set SES_OBJSTAT_NOTAVAIL. We'll depend on the
2281 * temperature flags for warnings.
2283 ssc->ses_objmap[oid].encstat[0] = SES_OBJSTAT_NOTAVAIL;
2284 ssc->ses_objmap[oid].encstat[1] = 0;
2285 ssc->ses_objmap[oid].encstat[2] = sdata[r];
2286 ssc->ses_objmap[oid].encstat[3] = 0;;
2287 ssc->ses_objmap[oid++].svalid = 1;
2292 * Now, for "pseudo" thermometers, we have two bytes
2293 * of information in enclosure status- 16 bits. Actually,
2294 * the MSB is a single TEMP ALERT flag indicating whether
2295 * any other bits are set, but, thanks to fuzzy thinking,
2296 * in the SAF-TE spec, this can also be set even if no
2297 * other bits are set, thus making this really another
2298 * binary temperature sensor.
2301 SAFT_BAIL(r, hiwater, sdata, buflen);
2302 tempflags = sdata[r++];
2303 SAFT_BAIL(r, hiwater, sdata, buflen);
2304 tempflags |= (tempflags << 8) | sdata[r++];
2306 for (i = 0; i < NPSEUDO_THERM; i++) {
2307 ssc->ses_objmap[oid].encstat[1] = 0;
2308 if (tempflags & (1 << (NPSEUDO_THERM - i - 1))) {
2309 ssc->ses_objmap[oid].encstat[0] = SES_OBJSTAT_CRIT;
2310 ssc->ses_objmap[4].encstat[2] = 0xff;
2312 * Set 'over temperature' failure.
2314 ssc->ses_objmap[oid].encstat[3] = 8;
2315 ssc->ses_encstat |= SES_ENCSTAT_CRITICAL;
2318 * We used to say 'not available' and synthesize a
2319 * nominal 30 deg (C)- that was wrong. Actually,
2320 * Just say 'OK', and use the reserved value of
2323 ssc->ses_objmap[oid].encstat[0] = SES_OBJSTAT_OK;
2324 ssc->ses_objmap[oid].encstat[2] = 0;
2325 ssc->ses_objmap[oid].encstat[3] = 0;
2327 ssc->ses_objmap[oid++].svalid = 1;
2333 ssc->ses_objmap[oid].encstat[0] = SES_OBJSTAT_OK;
2334 ssc->ses_objmap[oid].encstat[3] = ssc->ses_objmap[oid].priv;
2335 ssc->ses_objmap[oid++].svalid = 1;
2338 * Now get drive slot status
2340 cdb[2] = SAFTE_RD_RDDSTS;
2342 err = ses_runcmd(ssc, cdb, 10, sdata, &amt);
2344 SES_FREE(sdata, buflen);
2347 hiwater = buflen - amt;
2348 for (r = i = 0; i < cc->Nslots; i++, r += 4) {
2349 SAFT_BAIL(r+3, hiwater, sdata, buflen);
2350 ssc->ses_objmap[oid].encstat[0] = SES_OBJSTAT_UNSUPPORTED;
2351 ssc->ses_objmap[oid].encstat[1] = (uint8_t) i;
2352 ssc->ses_objmap[oid].encstat[2] = 0;
2353 ssc->ses_objmap[oid].encstat[3] = 0;
2354 status = sdata[r+3];
2355 if ((status & 0x1) == 0) { /* no device */
2356 ssc->ses_objmap[oid].encstat[0] =
2357 SES_OBJSTAT_NOTINSTALLED;
2359 ssc->ses_objmap[oid].encstat[0] = SES_OBJSTAT_OK;
2362 ssc->ses_objmap[oid].encstat[2] = 0x8;
2364 if ((status & 0x4) == 0) {
2365 ssc->ses_objmap[oid].encstat[3] = 0x10;
2367 ssc->ses_objmap[oid++].svalid = 1;
2369 /* see comment below about sticky enclosure status */
2370 ssc->ses_encstat |= ENCI_SVALID | oencstat;
2371 SES_FREE(sdata, buflen);
2376 set_objstat_sel(ses_softc_t *ssc, ses_objstat *obp, int slp)
2380 struct scfg *cc = ssc->ses_private;
2385 idx = (int)obp->obj_id;
2386 ep = &ssc->ses_objmap[idx];
2388 switch (ep->enctype) {
2390 if (obp->cstat[0] & SESCTL_PRDFAIL) {
2393 /* SESCTL_RSTSWAP has no correspondence in SAF-TE */
2394 if (obp->cstat[0] & SESCTL_DISABLE) {
2397 * Hmm. Try to set the 'No Drive' flag.
2398 * Maybe that will count as a 'disable'.
2401 if (ep->priv & 0xc6) {
2404 ep->priv |= 0x1; /* no errors */
2406 wrslot_stat(ssc, slp);
2410 * Okay- the only one that makes sense here is to
2411 * do the 'disable' for a power supply.
2413 if (obp->cstat[0] & SESCTL_DISABLE) {
2414 (void) wrbuf16(ssc, SAFTE_WT_ACTPWS,
2415 idx - cc->pwroff, 0, 0, slp);
2420 * Okay- the only one that makes sense here is to
2421 * set fan speed to zero on disable.
2423 if (obp->cstat[0] & SESCTL_DISABLE) {
2424 /* remember- fans are the first items, so idx works */
2425 (void) wrbuf16(ssc, SAFTE_WT_FANSPD, idx, 0, 0, slp);
2428 case SESTYP_DOORLOCK:
2430 * Well, we can 'disable' the lock.
2432 if (obp->cstat[0] & SESCTL_DISABLE) {
2433 cc->flag2 &= ~SAFT_FLG2_LOCKDOOR;
2434 (void) wrbuf16(ssc, SAFTE_WT_GLOBAL, cc->flag1,
2440 * Well, we can 'disable' the alarm.
2442 if (obp->cstat[0] & SESCTL_DISABLE) {
2443 cc->flag2 &= ~SAFT_FLG1_ALARM;
2444 ep->priv |= 0x40; /* Muted */
2445 (void) wrbuf16(ssc, SAFTE_WT_GLOBAL, cc->flag1,
2457 * This function handles all of the 16 byte WRITE BUFFER commands.
2460 wrbuf16(ses_softc_t *ssc, uint8_t op, uint8_t b1, uint8_t b2,
2461 uint8_t b3, int slp)
2465 struct scfg *cc = ssc->ses_private;
2466 static char cdb[10] = { WRITE_BUFFER, 1, 0, 0, 0, 0, 0, 0, 16, 0 };
2471 sdata = SES_MALLOC(16);
2475 SES_DLOG(ssc, "saf_wrbuf16 %x %x %x %x\n", op, b1, b2, b3);
2481 MEMZERO(&sdata[4], 12);
2483 err = ses_runcmd(ssc, cdb, 10, sdata, &amt);
2484 SES_FREE(sdata, 16);
2489 * This function updates the status byte for the device slot described.
2491 * Since this is an optional SAF-TE command, there's no point in
2492 * returning an error.
2495 wrslot_stat(ses_softc_t *ssc, int slp)
2499 char cdb[10], *sdata;
2500 struct scfg *cc = ssc->ses_private;
2505 SES_DLOG(ssc, "saf_wrslot\n");
2506 cdb[0] = WRITE_BUFFER;
2514 cdb[8] = cc->Nslots * 3 + 1;
2517 sdata = SES_MALLOC(cc->Nslots * 3 + 1);
2520 MEMZERO(sdata, cc->Nslots * 3 + 1);
2522 sdata[0] = SAFTE_WT_DSTAT;
2523 for (i = 0; i < cc->Nslots; i++) {
2524 ep = &ssc->ses_objmap[cc->slotoff + i];
2525 SES_DLOG(ssc, "saf_wrslot %d <- %x\n", i, ep->priv & 0xff);
2526 sdata[1 + (3 * i)] = ep->priv & 0xff;
2528 amt = -(cc->Nslots * 3 + 1);
2529 (void) ses_runcmd(ssc, cdb, 10, sdata, &amt);
2530 SES_FREE(sdata, cc->Nslots * 3 + 1);
2534 * This function issues the "PERFORM SLOT OPERATION" command.
2537 perf_slotop(ses_softc_t *ssc, uint8_t slot, uint8_t opflag, int slp)
2541 struct scfg *cc = ssc->ses_private;
2542 static char cdb[10] =
2543 { WRITE_BUFFER, 1, 0, 0, 0, 0, 0, 0, SAFT_SCRATCH, 0 };
2548 sdata = SES_MALLOC(SAFT_SCRATCH);
2551 MEMZERO(sdata, SAFT_SCRATCH);
2553 sdata[0] = SAFTE_WT_SLTOP;
2556 SES_DLOG(ssc, "saf_slotop slot %d op %x\n", slot, opflag);
2557 amt = -SAFT_SCRATCH;
2558 err = ses_runcmd(ssc, cdb, 10, sdata, &amt);
2559 SES_FREE(sdata, SAFT_SCRATCH);