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.18 2006/09/10 01:26:32 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 <sys/thread2.h>
42 #include <machine/stdarg.h>
45 #include "../cam_ccb.h"
46 #include "../cam_extend.h"
47 #include "../cam_periph.h"
48 #include "../cam_xpt_periph.h"
49 #include "../cam_queue.h"
50 #include "../cam_debug.h"
53 #include "scsi_message.h"
54 #include <sys/ioccom.h>
60 * Platform Independent Driver Internal Definitions for SES devices.
72 typedef struct ses_softc ses_softc_t;
74 int (*softc_init)(ses_softc_t *, int);
75 int (*init_enc)(ses_softc_t *);
76 int (*get_encstat)(ses_softc_t *, int);
77 int (*set_encstat)(ses_softc_t *, ses_encstat, int);
78 int (*get_objstat)(ses_softc_t *, ses_objstat *, int);
79 int (*set_objstat)(ses_softc_t *, ses_objstat *, int);
82 #define ENCI_SVALID 0x80
86 enctype : 8, /* enclosure type */
87 subenclosure : 8, /* subenclosure id */
88 svalid : 1, /* enclosure information valid */
89 priv : 15; /* private data, per object */
90 uint8_t encstat[4]; /* state && stats */
93 #define SEN_ID "UNISYS SUN_SEN"
97 static enctyp ses_type(void *, int);
100 /* Forward reference to Enclosure Functions */
101 static int ses_softc_init(ses_softc_t *, int);
102 static int ses_init_enc(ses_softc_t *);
103 static int ses_get_encstat(ses_softc_t *, int);
104 static int ses_set_encstat(ses_softc_t *, uint8_t, int);
105 static int ses_get_objstat(ses_softc_t *, ses_objstat *, int);
106 static int ses_set_objstat(ses_softc_t *, ses_objstat *, int);
108 static int safte_softc_init(ses_softc_t *, int);
109 static int safte_init_enc(ses_softc_t *);
110 static int safte_get_encstat(ses_softc_t *, int);
111 static int safte_set_encstat(ses_softc_t *, uint8_t, int);
112 static int safte_get_objstat(ses_softc_t *, ses_objstat *, int);
113 static int safte_set_objstat(ses_softc_t *, ses_objstat *, int);
116 * Platform implementation defines/functions for SES internal kernel stuff
119 #define STRNCMP strncmp
120 #define PRINTF printf
121 #define SES_LOG ses_log
123 #define SES_DLOG ses_log
125 #define SES_DLOG if (0) ses_log
127 #define SES_VLOG if (bootverbose) ses_log
128 #define SES_MALLOC(amt) kmalloc(amt, M_DEVBUF, M_INTWAIT)
129 #define SES_FREE(ptr, amt) kfree(ptr, M_DEVBUF)
130 #define MEMZERO bzero
131 #define MEMCPY(dest, src, amt) bcopy(src, dest, amt)
133 static int ses_runcmd(struct ses_softc *, char *, int, char *, int *);
134 static void ses_log(struct ses_softc *, const char *, ...);
137 * Gerenal FreeBSD kernel stuff.
141 #define ccb_state ppriv_field0
142 #define ccb_bio ppriv_ptr1
145 enctyp ses_type; /* type of enclosure */
146 encvec ses_vec; /* vector to handlers */
147 void * ses_private; /* per-type private data */
148 encobj * ses_objmap; /* objects */
149 u_int32_t ses_nobjects; /* number of objects */
150 ses_encstat ses_encstat; /* overall status */
152 union ccb ses_saved_ccb;
153 struct cam_periph *periph;
155 #define SES_FLAG_INVALID 0x01
156 #define SES_FLAG_OPEN 0x02
157 #define SES_FLAG_INITIALIZED 0x04
159 #define SESUNIT(x) (minor((x)))
160 #define SES_CDEV_MAJOR 110
162 static d_open_t sesopen;
163 static d_close_t sesclose;
164 static d_ioctl_t sesioctl;
165 static periph_init_t sesinit;
166 static periph_ctor_t sesregister;
167 static periph_oninv_t sesoninvalidate;
168 static periph_dtor_t sescleanup;
169 static periph_start_t sesstart;
171 static void sesasync(void *, u_int32_t, struct cam_path *, void *);
172 static void sesdone(struct cam_periph *, union ccb *);
173 static int seserror(union ccb *, u_int32_t, u_int32_t);
175 static struct periph_driver sesdriver = {
177 TAILQ_HEAD_INITIALIZER(sesdriver.units), /* generation */ 0
180 DATA_SET(periphdriver_set, sesdriver);
182 static struct dev_ops ses_ops = {
183 { "ses", SES_CDEV_MAJOR, 0 },
188 static struct extend_array *sesperiphs;
194 struct cam_path *path;
197 * Create our extend array for storing the devices we attach to.
199 sesperiphs = cam_extend_new();
200 if (sesperiphs == NULL) {
201 printf("ses: Failed to alloc extend array!\n");
206 * Install a global async callback. This callback will
207 * receive async callbacks like "new device found".
209 status = xpt_create_path(&path, NULL, CAM_XPT_PATH_ID,
210 CAM_TARGET_WILDCARD, CAM_LUN_WILDCARD);
212 if (status == CAM_REQ_CMP) {
213 struct ccb_setasync csa;
215 xpt_setup_ccb(&csa.ccb_h, path, 5);
216 csa.ccb_h.func_code = XPT_SASYNC_CB;
217 csa.event_enable = AC_FOUND_DEVICE;
218 csa.callback = sesasync;
219 csa.callback_arg = NULL;
220 xpt_action((union ccb *)&csa);
221 status = csa.ccb_h.status;
225 if (status != CAM_REQ_CMP) {
226 printf("ses: Failed to attach master async callback "
227 "due to status 0x%x!\n", status);
232 sesoninvalidate(struct cam_periph *periph)
234 struct ses_softc *softc;
235 struct ccb_setasync csa;
237 softc = (struct ses_softc *)periph->softc;
240 * Unregister any async callbacks.
242 xpt_setup_ccb(&csa.ccb_h, periph->path, 5);
243 csa.ccb_h.func_code = XPT_SASYNC_CB;
244 csa.event_enable = 0;
245 csa.callback = sesasync;
246 csa.callback_arg = periph;
247 xpt_action((union ccb *)&csa);
249 softc->ses_flags |= SES_FLAG_INVALID;
251 xpt_print_path(periph->path);
252 printf("lost device\n");
256 sescleanup(struct cam_periph *periph)
258 struct ses_softc *softc;
260 softc = (struct ses_softc *)periph->softc;
262 cam_extend_release(sesperiphs, periph->unit_number);
263 xpt_print_path(periph->path);
264 printf("removing device entry\n");
265 dev_ops_remove(&ses_ops, -1, periph->unit_number);
266 kfree(softc, M_DEVBUF);
270 sesasync(void *callback_arg, u_int32_t code, struct cam_path *path, void *arg)
272 struct cam_periph *periph;
274 periph = (struct cam_periph *)callback_arg;
277 case AC_FOUND_DEVICE:
280 struct ccb_getdev *cgd;
282 cgd = (struct ccb_getdev *)arg;
285 * PROBLEM: WE NEED TO LOOK AT BYTES 48-53 TO SEE IF THIS IS
286 * PROBLEM: IS A SAF-TE DEVICE.
288 switch (ses_type(&cgd->inq_data, cgd->inq_len)) {
291 case SES_SES_PASSTHROUGH:
299 status = cam_periph_alloc(sesregister, sesoninvalidate,
300 sescleanup, sesstart, "ses", CAM_PERIPH_BIO,
301 cgd->ccb_h.path, sesasync, AC_FOUND_DEVICE, cgd);
303 if (status != CAM_REQ_CMP && status != CAM_REQ_INPROG) {
304 printf("sesasync: Unable to probe new device due to "
305 "status 0x%x\n", status);
310 cam_periph_async(periph, code, path, arg);
316 sesregister(struct cam_periph *periph, void *arg)
318 struct ses_softc *softc;
319 struct ccb_setasync csa;
320 struct ccb_getdev *cgd;
323 cgd = (struct ccb_getdev *)arg;
324 if (periph == NULL) {
325 printf("sesregister: periph was NULL!!\n");
326 return (CAM_REQ_CMP_ERR);
330 printf("sesregister: no getdev CCB, can't register device\n");
331 return (CAM_REQ_CMP_ERR);
334 softc = kmalloc(sizeof (struct ses_softc), M_DEVBUF, M_INTWAIT | M_ZERO);
335 periph->softc = softc;
336 softc->periph = periph;
338 softc->ses_type = ses_type(&cgd->inq_data, sizeof (cgd->inq_data));
340 switch (softc->ses_type) {
343 case SES_SES_PASSTHROUGH:
344 softc->ses_vec.softc_init = ses_softc_init;
345 softc->ses_vec.init_enc = ses_init_enc;
346 softc->ses_vec.get_encstat = ses_get_encstat;
347 softc->ses_vec.set_encstat = ses_set_encstat;
348 softc->ses_vec.get_objstat = ses_get_objstat;
349 softc->ses_vec.set_objstat = ses_set_objstat;
352 softc->ses_vec.softc_init = safte_softc_init;
353 softc->ses_vec.init_enc = safte_init_enc;
354 softc->ses_vec.get_encstat = safte_get_encstat;
355 softc->ses_vec.set_encstat = safte_set_encstat;
356 softc->ses_vec.get_objstat = safte_get_objstat;
357 softc->ses_vec.set_objstat = safte_set_objstat;
363 kfree(softc, M_DEVBUF);
364 return (CAM_REQ_CMP_ERR);
367 cam_extend_set(sesperiphs, periph->unit_number, periph);
369 dev_ops_add(&ses_ops, -1, periph->unit_number);
370 make_dev(&ses_ops, periph->unit_number,
371 UID_ROOT, GID_OPERATOR, 0600, "%s%d",
372 periph->periph_name, periph->unit_number);
375 * Add an async callback so that we get
376 * notified if this device goes away.
378 xpt_setup_ccb(&csa.ccb_h, periph->path, 5);
379 csa.ccb_h.func_code = XPT_SASYNC_CB;
380 csa.event_enable = AC_LOST_DEVICE;
381 csa.callback = sesasync;
382 csa.callback_arg = periph;
383 xpt_action((union ccb *)&csa);
385 switch (softc->ses_type) {
388 tname = "No SES device";
391 tname = "SCSI-2 SES Device";
394 tname = "SCSI-3 SES Device";
396 case SES_SES_PASSTHROUGH:
397 tname = "SES Passthrough Device";
400 tname = "UNISYS SEN Device (NOT HANDLED YET)";
403 tname = "SAF-TE Compliant Device";
406 xpt_announce_periph(periph, tname);
407 return (CAM_REQ_CMP);
411 sesopen(struct dev_open_args *ap)
413 cdev_t dev = ap->a_head.a_dev;
414 struct cam_periph *periph;
415 struct ses_softc *softc;
419 periph = cam_extend_get(sesperiphs, SESUNIT(dev));
420 if (periph == NULL) {
424 if ((error = cam_periph_lock(periph, PCATCH)) != 0) {
430 if (cam_periph_acquire(periph) != CAM_REQ_CMP) {
431 cam_periph_unlock(periph);
435 softc = (struct ses_softc *)periph->softc;
437 if (softc->ses_flags & SES_FLAG_INVALID) {
441 if (softc->ses_flags & SES_FLAG_OPEN) {
445 if (softc->ses_vec.softc_init == NULL) {
450 softc->ses_flags |= SES_FLAG_OPEN;
451 if ((softc->ses_flags & SES_FLAG_INITIALIZED) == 0) {
452 error = (*softc->ses_vec.softc_init)(softc, 1);
454 softc->ses_flags &= ~SES_FLAG_OPEN;
456 softc->ses_flags |= SES_FLAG_INITIALIZED;
461 cam_periph_release(periph);
463 cam_periph_unlock(periph);
468 sesclose(struct dev_close_args *ap)
470 cdev_t dev = ap->a_head.a_dev;
471 struct cam_periph *periph;
472 struct ses_softc *softc;
478 periph = cam_extend_get(sesperiphs, unit);
482 softc = (struct ses_softc *)periph->softc;
484 if ((error = cam_periph_lock(periph, 0)) != 0)
487 softc->ses_flags &= ~SES_FLAG_OPEN;
489 cam_periph_unlock(periph);
490 cam_periph_release(periph);
496 sesstart(struct cam_periph *p, union ccb *sccb)
499 if (p->immediate_priority <= p->pinfo.priority) {
500 SLIST_INSERT_HEAD(&p->ccb_list, &sccb->ccb_h, periph_links.sle);
501 p->immediate_priority = CAM_PRIORITY_NONE;
502 wakeup(&p->ccb_list);
508 sesdone(struct cam_periph *periph, union ccb *dccb)
510 wakeup(&dccb->ccb_h.cbfcnp);
514 seserror(union ccb *ccb, u_int32_t cflags, u_int32_t sflags)
516 struct ses_softc *softc;
517 struct cam_periph *periph;
519 periph = xpt_path_periph(ccb->ccb_h.path);
520 softc = (struct ses_softc *)periph->softc;
522 return (cam_periph_error(ccb, cflags, sflags, &softc->ses_saved_ccb));
526 sesioctl(struct dev_ioctl_args *ap)
528 cdev_t dev = ap->a_head.a_dev;
529 struct cam_periph *periph;
532 ses_object obj, *uobj;
533 struct ses_softc *ssc;
539 addr = *((caddr_t *)ap->a_data);
543 periph = cam_extend_get(sesperiphs, SESUNIT(dev));
547 CAM_DEBUG(periph->path, CAM_DEBUG_TRACE, ("entering sesioctl\n"));
549 ssc = (struct ses_softc *)periph->softc;
552 * Now check to see whether we're initialized or not.
554 if ((ssc->ses_flags & SES_FLAG_INITIALIZED) == 0) {
560 CAM_DEBUG(periph->path, CAM_DEBUG_TRACE,
561 ("trying to do ioctl %#lx\n", ap->a_cmd));
564 * If this command can change the device's state,
565 * we must have the device open for writing.
569 case SESIOC_GETOBJMAP:
570 case SESIOC_GETENCSTAT:
571 case SESIOC_GETOBJSTAT:
574 if ((ap->a_fflag & FWRITE) == 0) {
581 error = copyout(&ssc->ses_nobjects, addr,
582 sizeof (ssc->ses_nobjects));
585 case SESIOC_GETOBJMAP:
586 for (uobj = addr, i = 0; i != ssc->ses_nobjects; i++, uobj++) {
588 obj.subencid = ssc->ses_objmap[i].subenclosure;
589 obj.object_type = ssc->ses_objmap[i].enctype;
590 error = copyout(&obj, uobj, sizeof (ses_object));
597 case SESIOC_GETENCSTAT:
598 error = (*ssc->ses_vec.get_encstat)(ssc, 1);
601 tmp = ssc->ses_encstat & ~ENCI_SVALID;
602 error = copyout(&tmp, addr, sizeof (ses_encstat));
603 ssc->ses_encstat = tmp;
606 case SESIOC_SETENCSTAT:
607 error = copyin(addr, &tmp, sizeof (ses_encstat));
610 error = (*ssc->ses_vec.set_encstat)(ssc, tmp, 1);
613 case SESIOC_GETOBJSTAT:
614 error = copyin(addr, &objs, sizeof (ses_objstat));
617 if (objs.obj_id >= ssc->ses_nobjects) {
621 error = (*ssc->ses_vec.get_objstat)(ssc, &objs, 1);
624 error = copyout(&objs, addr, sizeof (ses_objstat));
626 * Always (for now) invalidate entry.
628 ssc->ses_objmap[objs.obj_id].svalid = 0;
631 case SESIOC_SETOBJSTAT:
632 error = copyin(addr, &objs, sizeof (ses_objstat));
636 if (objs.obj_id >= ssc->ses_nobjects) {
640 error = (*ssc->ses_vec.set_objstat)(ssc, &objs, 1);
643 * Always (for now) invalidate entry.
645 ssc->ses_objmap[objs.obj_id].svalid = 0;
650 error = (*ssc->ses_vec.init_enc)(ssc);
654 error = cam_periph_ioctl(periph, ap->a_cmd, ap->a_data, seserror);
660 #define SES_FLAGS SF_NO_PRINT | SF_RETRY_SELTO | SF_RETRY_UA
662 ses_runcmd(struct ses_softc *ssc, char *cdb, int cdbl, char *dptr, int *dlenp)
669 if ((dlen = *dlenp) < 0) {
680 if (cdbl > IOCDBLEN) {
684 ccb = cam_periph_getccb(ssc->periph, 1);
685 cam_fill_csio(&ccb->csio, 0, sesdone, ddf, MSG_SIMPLE_Q_TAG, dptr,
686 dlen, sizeof (struct scsi_sense_data), cdbl, 60 * 1000);
687 bcopy(cdb, ccb->csio.cdb_io.cdb_bytes, cdbl);
689 error = cam_periph_runccb(ccb, seserror, 0, SES_FLAGS, NULL);
690 if ((ccb->ccb_h.status & CAM_DEV_QFRZN) != 0)
691 cam_release_devq(ccb->ccb_h.path, 0, 0, 0, FALSE);
698 *dlenp = ccb->csio.resid;
701 xpt_release_ccb(ccb);
706 ses_log(struct ses_softc *ssc, const char *fmt, ...)
710 printf("%s%d: ", ssc->periph->periph_name, ssc->periph->unit_number);
717 * The code after this point runs on many platforms,
718 * so forgive the slightly awkward and nonconforming
723 * Is this a device that supports enclosure services?
725 * It's a a pretty simple ruleset- if it is device type 0x0D (13), it's
726 * an SES device. If it happens to be an old UNISYS SEN device, we can
730 #define SAFTE_START 44
732 #define SAFTE_LEN SAFTE_END-SAFTE_START
735 ses_type(void *buf, int buflen)
737 unsigned char *iqd = buf;
740 buflen = 256; /* per SPC-2 */
742 if (buflen < 8+SEN_ID_LEN)
745 if ((iqd[0] & 0x1f) == T_ENCLOSURE) {
746 if (STRNCMP(&iqd[8], SEN_ID, SEN_ID_LEN) == 0) {
748 } else if ((iqd[2] & 0x7) > 2) {
751 return (SES_SES_SCSI2);
756 #ifdef SES_ENABLE_PASSTHROUGH
757 if ((iqd[6] & 0x40) && (iqd[2] & 0x7) >= 2) {
759 * PassThrough Device.
761 return (SES_SES_PASSTHROUGH);
766 * The comparison is short for a reason-
767 * some vendors were chopping it short.
770 if (buflen < SAFTE_END - 2) {
774 if (STRNCMP((char *)&iqd[SAFTE_START], "SAF-TE", SAFTE_LEN - 2) == 0) {
781 * SES Native Type Device Support
785 * SES Diagnostic Page Codes
791 #define SesStatusPage SesControlPage
794 #define SesStringIn SesStringOut
796 #define SesThresholdIn SesThresholdOut
798 #define SesArrayStatus SesArrayControl
799 SesElementDescriptor,
808 * Minimum amount of data, starting from byte 0, to have
811 #define SES_CFGHDR_MINLEN 12
814 * Minimum amount of data, starting from byte 0, to have
815 * the config header and one enclosure header.
817 #define SES_ENCHDR_MINLEN 48
820 * Take this value, subtract it from VEnclen and you know
821 * the length of the vendor unique bytes.
823 #define SES_ENCHDR_VMIN 36
826 * SES Data Structures
830 uint32_t GenCode; /* Generation Code */
831 uint8_t Nsubenc; /* Number of Subenclosures */
835 uint8_t Subencid; /* SubEnclosure Identifier */
836 uint8_t Ntypes; /* # of supported types */
837 uint8_t VEnclen; /* Enclosure Descriptor Length */
841 uint8_t encWWN[8]; /* XXX- Not Right Yet */
849 uint8_t enc_type; /* type of element */
850 uint8_t enc_maxelt; /* maximum supported */
851 uint8_t enc_subenc; /* in SubEnc # N */
852 uint8_t enc_tlen; /* Type Descriptor Text Length */
866 uint8_t ses_ntypes; /* total number of types supported */
869 * We need to keep a type index as well as an
870 * object index for each object in an enclosure.
872 struct typidx *ses_typidx;
875 * We also need to keep track of the number of elements
876 * per type of element. This is needed later so that we
877 * can find precisely in the returned status data the
878 * status for the Nth element of the Kth type.
880 uint8_t * ses_eltmap;
885 * (de)canonicalization defines
887 #define sbyte(x, byte) ((((uint32_t)(x)) >> (byte * 8)) & 0xff)
888 #define sbit(x, bit) (((uint32_t)(x)) << bit)
889 #define sset8(outp, idx, sval) (((uint8_t *)(outp))[idx++]) = sbyte(sval, 0)
891 #define sset16(outp, idx, sval) \
892 (((uint8_t *)(outp))[idx++]) = sbyte(sval, 1), \
893 (((uint8_t *)(outp))[idx++]) = sbyte(sval, 0)
896 #define sset24(outp, idx, sval) \
897 (((uint8_t *)(outp))[idx++]) = sbyte(sval, 2), \
898 (((uint8_t *)(outp))[idx++]) = sbyte(sval, 1), \
899 (((uint8_t *)(outp))[idx++]) = sbyte(sval, 0)
902 #define sset32(outp, idx, sval) \
903 (((uint8_t *)(outp))[idx++]) = sbyte(sval, 3), \
904 (((uint8_t *)(outp))[idx++]) = sbyte(sval, 2), \
905 (((uint8_t *)(outp))[idx++]) = sbyte(sval, 1), \
906 (((uint8_t *)(outp))[idx++]) = sbyte(sval, 0)
908 #define gbyte(x, byte) ((((uint32_t)(x)) & 0xff) << (byte * 8))
909 #define gbit(lv, in, idx, shft, mask) lv = ((in[idx] >> shft) & mask)
910 #define sget8(inp, idx, lval) lval = (((uint8_t *)(inp))[idx++])
911 #define gget8(inp, idx, lval) lval = (((uint8_t *)(inp))[idx])
913 #define sget16(inp, idx, lval) \
914 lval = gbyte((((uint8_t *)(inp))[idx]), 1) | \
915 (((uint8_t *)(inp))[idx+1]), idx += 2
917 #define gget16(inp, idx, lval) \
918 lval = gbyte((((uint8_t *)(inp))[idx]), 1) | \
919 (((uint8_t *)(inp))[idx+1])
921 #define sget24(inp, idx, lval) \
922 lval = gbyte((((uint8_t *)(inp))[idx]), 2) | \
923 gbyte((((uint8_t *)(inp))[idx+1]), 1) | \
924 (((uint8_t *)(inp))[idx+2]), idx += 3
926 #define gget24(inp, idx, lval) \
927 lval = gbyte((((uint8_t *)(inp))[idx]), 2) | \
928 gbyte((((uint8_t *)(inp))[idx+1]), 1) | \
929 (((uint8_t *)(inp))[idx+2])
931 #define sget32(inp, idx, lval) \
932 lval = gbyte((((uint8_t *)(inp))[idx]), 3) | \
933 gbyte((((uint8_t *)(inp))[idx+1]), 2) | \
934 gbyte((((uint8_t *)(inp))[idx+2]), 1) | \
935 (((uint8_t *)(inp))[idx+3]), idx += 4
937 #define gget32(inp, idx, lval) \
938 lval = gbyte((((uint8_t *)(inp))[idx]), 3) | \
939 gbyte((((uint8_t *)(inp))[idx+1]), 2) | \
940 gbyte((((uint8_t *)(inp))[idx+2]), 1) | \
941 (((uint8_t *)(inp))[idx+3])
944 #define CFLEN (256 + SES_ENCHDR_MINLEN)
947 * Routines specific && private to SES only
950 static int ses_getconfig(ses_softc_t *);
951 static int ses_getputstat(ses_softc_t *, int, SesComStat *, int, int);
952 static int ses_cfghdr(uint8_t *, int, SesCfgHdr *);
953 static int ses_enchdr(uint8_t *, int, uint8_t, SesEncHdr *);
954 static int ses_encdesc(uint8_t *, int, uint8_t, SesEncDesc *);
955 static int ses_getthdr(uint8_t *, int, int, SesThdr *);
956 static int ses_decode(char *, int, uint8_t *, int, int, SesComStat *);
957 static int ses_encode(char *, int, uint8_t *, int, int, SesComStat *);
960 ses_softc_init(ses_softc_t *ssc, int doinit)
964 if (ssc->ses_nobjects) {
965 SES_FREE(ssc->ses_objmap,
966 ssc->ses_nobjects * sizeof (encobj));
967 ssc->ses_objmap = NULL;
969 if ((cc = ssc->ses_private) != NULL) {
970 if (cc->ses_eltmap && cc->ses_ntypes) {
971 SES_FREE(cc->ses_eltmap, cc->ses_ntypes);
972 cc->ses_eltmap = NULL;
975 if (cc->ses_typidx && ssc->ses_nobjects) {
976 SES_FREE(cc->ses_typidx,
977 ssc->ses_nobjects * sizeof (struct typidx));
978 cc->ses_typidx = NULL;
980 SES_FREE(cc, sizeof (struct sscfg));
981 ssc->ses_private = NULL;
983 ssc->ses_nobjects = 0;
986 if (ssc->ses_private == NULL) {
987 ssc->ses_private = SES_MALLOC(sizeof (struct sscfg));
989 if (ssc->ses_private == NULL) {
992 ssc->ses_nobjects = 0;
993 ssc->ses_encstat = 0;
994 return (ses_getconfig(ssc));
998 ses_init_enc(ses_softc_t *ssc)
1004 ses_get_encstat(ses_softc_t *ssc, int slpflag)
1009 if ((status = ses_getputstat(ssc, -1, &ComStat, slpflag, 1)) != 0) {
1012 ssc->ses_encstat = ComStat.comstatus | ENCI_SVALID;
1017 ses_set_encstat(ses_softc_t *ssc, uint8_t encstat, int slpflag)
1022 ComStat.comstatus = encstat & 0xf;
1023 if ((status = ses_getputstat(ssc, -1, &ComStat, slpflag, 0)) != 0) {
1026 ssc->ses_encstat = encstat & 0xf; /* note no SVALID set */
1031 ses_get_objstat(ses_softc_t *ssc, ses_objstat *obp, int slpflag)
1033 int i = (int)obp->obj_id;
1035 if (ssc->ses_objmap[i].svalid == 0) {
1037 int err = ses_getputstat(ssc, i, &ComStat, slpflag, 1);
1040 ssc->ses_objmap[i].encstat[0] = ComStat.comstatus;
1041 ssc->ses_objmap[i].encstat[1] = ComStat.comstat[0];
1042 ssc->ses_objmap[i].encstat[2] = ComStat.comstat[1];
1043 ssc->ses_objmap[i].encstat[3] = ComStat.comstat[2];
1044 ssc->ses_objmap[i].svalid = 1;
1046 obp->cstat[0] = ssc->ses_objmap[i].encstat[0];
1047 obp->cstat[1] = ssc->ses_objmap[i].encstat[1];
1048 obp->cstat[2] = ssc->ses_objmap[i].encstat[2];
1049 obp->cstat[3] = ssc->ses_objmap[i].encstat[3];
1054 ses_set_objstat(ses_softc_t *ssc, ses_objstat *obp, int slpflag)
1059 * If this is clear, we don't do diddly.
1061 if ((obp->cstat[0] & SESCTL_CSEL) == 0) {
1064 ComStat.comstatus = obp->cstat[0];
1065 ComStat.comstat[0] = obp->cstat[1];
1066 ComStat.comstat[1] = obp->cstat[2];
1067 ComStat.comstat[2] = obp->cstat[3];
1068 err = ses_getputstat(ssc, (int)obp->obj_id, &ComStat, slpflag, 0);
1069 ssc->ses_objmap[(int)obp->obj_id].svalid = 0;
1074 ses_getconfig(ses_softc_t *ssc)
1081 int err, amt, i, nobj, ntype, maxima;
1082 char storage[CFLEN], *sdata;
1083 static char cdb[6] = {
1084 RECEIVE_DIAGNOSTIC, 0x1, SesConfigPage, SCSZ >> 8, SCSZ & 0xff, 0
1087 cc = ssc->ses_private;
1092 sdata = SES_MALLOC(SCSZ);
1097 err = ses_runcmd(ssc, cdb, 6, sdata, &amt);
1099 SES_FREE(sdata, SCSZ);
1104 if (ses_cfghdr((uint8_t *) sdata, amt, &cf)) {
1105 SES_LOG(ssc, "Unable to parse SES Config Header\n");
1106 SES_FREE(sdata, SCSZ);
1109 if (amt < SES_ENCHDR_MINLEN) {
1110 SES_LOG(ssc, "runt enclosure length (%d)\n", amt);
1111 SES_FREE(sdata, SCSZ);
1115 SES_VLOG(ssc, "GenCode %x %d Subenclosures\n", cf.GenCode, cf.Nsubenc);
1118 * Now waltz through all the subenclosures toting up the
1119 * number of types available in each. For this, we only
1120 * really need the enclosure header. However, we get the
1121 * enclosure descriptor for debug purposes, as well
1122 * as self-consistency checking purposes.
1125 maxima = cf.Nsubenc + 1;
1126 cdp = (SesEncDesc *) storage;
1127 for (ntype = i = 0; i < maxima; i++) {
1128 MEMZERO((caddr_t)cdp, sizeof (*cdp));
1129 if (ses_enchdr((uint8_t *) sdata, amt, i, &hd)) {
1130 SES_LOG(ssc, "Cannot Extract Enclosure Header %d\n", i);
1131 SES_FREE(sdata, SCSZ);
1134 SES_VLOG(ssc, " SubEnclosure ID %d, %d Types With this ID, En"
1135 "closure Length %d\n", hd.Subencid, hd.Ntypes, hd.VEnclen);
1137 if (ses_encdesc((uint8_t *)sdata, amt, i, cdp)) {
1138 SES_LOG(ssc, "Can't get Enclosure Descriptor %d\n", i);
1139 SES_FREE(sdata, SCSZ);
1142 SES_VLOG(ssc, " WWN: %02x%02x%02x%02x%02x%02x%02x%02x\n",
1143 cdp->encWWN[0], cdp->encWWN[1], cdp->encWWN[2],
1144 cdp->encWWN[3], cdp->encWWN[4], cdp->encWWN[5],
1145 cdp->encWWN[6], cdp->encWWN[7]);
1150 * Now waltz through all the types that are available, getting
1151 * the type header so we can start adding up the number of
1152 * objects available.
1154 for (nobj = i = 0; i < ntype; i++) {
1155 if (ses_getthdr((uint8_t *)sdata, amt, i, &thdr)) {
1156 SES_LOG(ssc, "Can't get Enclosure Type Header %d\n", i);
1157 SES_FREE(sdata, SCSZ);
1160 SES_LOG(ssc, " Type Desc[%d]: Type 0x%x, MaxElt %d, In Subenc "
1161 "%d, Text Length %d\n", i, thdr.enc_type, thdr.enc_maxelt,
1162 thdr.enc_subenc, thdr.enc_tlen);
1163 nobj += thdr.enc_maxelt;
1168 * Now allocate the object array and type map.
1171 ssc->ses_objmap = SES_MALLOC(nobj * sizeof (encobj));
1172 cc->ses_typidx = SES_MALLOC(nobj * sizeof (struct typidx));
1173 cc->ses_eltmap = SES_MALLOC(ntype);
1175 if (ssc->ses_objmap == NULL || cc->ses_typidx == NULL ||
1176 cc->ses_eltmap == NULL) {
1177 if (ssc->ses_objmap) {
1178 SES_FREE(ssc->ses_objmap, (nobj * sizeof (encobj)));
1179 ssc->ses_objmap = NULL;
1181 if (cc->ses_typidx) {
1182 SES_FREE(cc->ses_typidx,
1183 (nobj * sizeof (struct typidx)));
1184 cc->ses_typidx = NULL;
1186 if (cc->ses_eltmap) {
1187 SES_FREE(cc->ses_eltmap, ntype);
1188 cc->ses_eltmap = NULL;
1190 SES_FREE(sdata, SCSZ);
1193 MEMZERO(ssc->ses_objmap, nobj * sizeof (encobj));
1194 MEMZERO(cc->ses_typidx, nobj * sizeof (struct typidx));
1195 MEMZERO(cc->ses_eltmap, ntype);
1196 cc->ses_ntypes = (uint8_t) ntype;
1197 ssc->ses_nobjects = nobj;
1200 * Now waltz through the # of types again to fill in the types
1201 * (and subenclosure ids) of the allocated objects.
1204 for (i = 0; i < ntype; i++) {
1206 if (ses_getthdr((uint8_t *)sdata, amt, i, &thdr)) {
1209 cc->ses_eltmap[i] = thdr.enc_maxelt;
1210 for (j = 0; j < thdr.enc_maxelt; j++) {
1211 cc->ses_typidx[nobj].ses_tidx = i;
1212 cc->ses_typidx[nobj].ses_oidx = j;
1213 ssc->ses_objmap[nobj].subenclosure = thdr.enc_subenc;
1214 ssc->ses_objmap[nobj++].enctype = thdr.enc_type;
1217 SES_FREE(sdata, SCSZ);
1222 ses_getputstat(ses_softc_t *ssc, int objid, SesComStat *sp, int slp, int in)
1225 int err, amt, bufsiz, tidx, oidx;
1226 char cdb[6], *sdata;
1228 cc = ssc->ses_private;
1234 * If we're just getting overall enclosure status,
1235 * we only need 2 bytes of data storage.
1237 * If we're getting anything else, we know how much
1238 * storage we need by noting that starting at offset
1239 * 8 in returned data, all object status bytes are 4
1240 * bytes long, and are stored in chunks of types(M)
1241 * and nth+1 instances of type M.
1246 bufsiz = (ssc->ses_nobjects * 4) + (cc->ses_ntypes * 4) + 8;
1248 sdata = SES_MALLOC(bufsiz);
1252 cdb[0] = RECEIVE_DIAGNOSTIC;
1254 cdb[2] = SesStatusPage;
1255 cdb[3] = bufsiz >> 8;
1256 cdb[4] = bufsiz & 0xff;
1259 err = ses_runcmd(ssc, cdb, 6, sdata, &amt);
1261 SES_FREE(sdata, bufsiz);
1270 tidx = cc->ses_typidx[objid].ses_tidx;
1271 oidx = cc->ses_typidx[objid].ses_oidx;
1274 if (ses_decode(sdata, amt, cc->ses_eltmap, tidx, oidx, sp)) {
1278 if (ses_encode(sdata, amt, cc->ses_eltmap, tidx, oidx, sp)) {
1281 cdb[0] = SEND_DIAGNOSTIC;
1284 cdb[3] = bufsiz >> 8;
1285 cdb[4] = bufsiz & 0xff;
1288 err = ses_runcmd(ssc, cdb, 6, sdata, &amt);
1291 SES_FREE(sdata, bufsiz);
1297 * Routines to parse returned SES data structures.
1298 * Architecture and compiler independent.
1302 ses_cfghdr(uint8_t *buffer, int buflen, SesCfgHdr *cfp)
1304 if (buflen < SES_CFGHDR_MINLEN) {
1307 gget8(buffer, 1, cfp->Nsubenc);
1308 gget32(buffer, 4, cfp->GenCode);
1313 ses_enchdr(uint8_t *buffer, int amt, uint8_t SubEncId, SesEncHdr *chp)
1316 for (s = 0; s < SubEncId; s++) {
1319 off += buffer[off+3] + 4;
1321 if (off + 3 > amt) {
1324 gget8(buffer, off+1, chp->Subencid);
1325 gget8(buffer, off+2, chp->Ntypes);
1326 gget8(buffer, off+3, chp->VEnclen);
1331 ses_encdesc(uint8_t *buffer, int amt, uint8_t SubEncId, SesEncDesc *cdp)
1333 int s, e, enclen, off = 8;
1334 for (s = 0; s < SubEncId; s++) {
1337 off += buffer[off+3] + 4;
1339 if (off + 3 > amt) {
1342 gget8(buffer, off+3, enclen);
1351 MEMCPY(cdp, &buffer[off], e - off);
1356 ses_getthdr(uint8_t *buffer, int amt, int nth, SesThdr *thp)
1360 if (amt < SES_CFGHDR_MINLEN) {
1363 for (s = 0; s < buffer[1]; s++) {
1366 off += buffer[off+3] + 4;
1368 if (off + 3 > amt) {
1371 off += buffer[off+3] + 4 + (nth * 4);
1372 if (amt < (off + 4))
1375 gget8(buffer, off++, thp->enc_type);
1376 gget8(buffer, off++, thp->enc_maxelt);
1377 gget8(buffer, off++, thp->enc_subenc);
1378 gget8(buffer, off, thp->enc_tlen);
1383 * This function needs a little explanation.
1385 * The arguments are:
1390 * These describes the raw input SES status data and length.
1394 * This is a map of the number of types for each element type
1399 * This is the element type being sought. If elt is -1,
1400 * then overall enclosure status is being sought.
1404 * This is the ordinal Mth element of type elt being sought.
1408 * This is the output area to store the status for
1409 * the Mth element of type Elt.
1413 ses_decode(char *b, int amt, uint8_t *ep, int elt, int elm, SesComStat *sp)
1418 * If it's overall enclosure status being sought, get that.
1419 * We need at least 2 bytes of status data to get that.
1424 gget8(b, 1, sp->comstatus);
1432 * Check to make sure that the Mth element is legal for type Elt.
1439 * Starting at offset 8, start skipping over the storage
1440 * for the element types we're not interested in.
1442 for (idx = 8, i = 0; i < elt; i++) {
1443 idx += ((ep[i] + 1) * 4);
1447 * Skip over Overall status for this element type.
1452 * And skip to the index for the Mth element that we're going for.
1457 * Make sure we haven't overflowed the buffer.
1463 * Retrieve the status.
1465 gget8(b, idx++, sp->comstatus);
1466 gget8(b, idx++, sp->comstat[0]);
1467 gget8(b, idx++, sp->comstat[1]);
1468 gget8(b, idx++, sp->comstat[2]);
1470 PRINTF("Get Elt 0x%x Elm 0x%x (idx %d)\n", elt, elm, idx-4);
1476 * This is the mirror function to ses_decode, but we set the 'select'
1477 * bit for the object which we're interested in. All other objects,
1478 * after a status fetch, should have that bit off. Hmm. It'd be easy
1479 * enough to ensure this, so we will.
1483 ses_encode(char *b, int amt, uint8_t *ep, int elt, int elm, SesComStat *sp)
1488 * If it's overall enclosure status being sought, get that.
1489 * We need at least 2 bytes of status data to get that.
1496 sset8(b, i, sp->comstatus & 0xf);
1498 PRINTF("set EncStat %x\n", sp->comstatus);
1504 * Check to make sure that the Mth element is legal for type Elt.
1511 * Starting at offset 8, start skipping over the storage
1512 * for the element types we're not interested in.
1514 for (idx = 8, i = 0; i < elt; i++) {
1515 idx += ((ep[i] + 1) * 4);
1519 * Skip over Overall status for this element type.
1524 * And skip to the index for the Mth element that we're going for.
1529 * Make sure we haven't overflowed the buffer.
1537 sset8(b, idx, sp->comstatus);
1538 sset8(b, idx, sp->comstat[0]);
1539 sset8(b, idx, sp->comstat[1]);
1540 sset8(b, idx, sp->comstat[2]);
1544 PRINTF("Set Elt 0x%x Elm 0x%x (idx %d) with %x %x %x %x\n",
1545 elt, elm, idx, sp->comstatus, sp->comstat[0],
1546 sp->comstat[1], sp->comstat[2]);
1550 * Now make sure all other 'Select' bits are off.
1552 for (i = 8; i < amt; i += 4) {
1557 * And make sure the INVOP bit is clear.
1565 * SAF-TE Type Device Emulation
1568 static int safte_getconfig(ses_softc_t *);
1569 static int safte_rdstat(ses_softc_t *, int);
1570 static int set_objstat_sel(ses_softc_t *, ses_objstat *, int);
1571 static int wrbuf16(ses_softc_t *, uint8_t, uint8_t, uint8_t, uint8_t, int);
1572 static void wrslot_stat(ses_softc_t *, int);
1573 static int perf_slotop(ses_softc_t *, uint8_t, uint8_t, int);
1575 #define ALL_ENC_STAT (SES_ENCSTAT_CRITICAL | SES_ENCSTAT_UNRECOV | \
1576 SES_ENCSTAT_NONCRITICAL | SES_ENCSTAT_INFO)
1578 * SAF-TE specific defines- Mandatory ones only...
1582 * READ BUFFER ('get' commands) IDs- placed in offset 2 of cdb
1584 #define SAFTE_RD_RDCFG 0x00 /* read enclosure configuration */
1585 #define SAFTE_RD_RDESTS 0x01 /* read enclosure status */
1586 #define SAFTE_RD_RDDSTS 0x04 /* read drive slot status */
1589 * WRITE BUFFER ('set' commands) IDs- placed in offset 0 of databuf
1591 #define SAFTE_WT_DSTAT 0x10 /* write device slot status */
1592 #define SAFTE_WT_SLTOP 0x12 /* perform slot operation */
1593 #define SAFTE_WT_FANSPD 0x13 /* set fan speed */
1594 #define SAFTE_WT_ACTPWS 0x14 /* turn on/off power supply */
1595 #define SAFTE_WT_GLOBAL 0x15 /* send global command */
1598 #define SAFT_SCRATCH 64
1599 #define NPSEUDO_THERM 16
1600 #define NPSEUDO_ALARM 1
1603 * Cached Configuration
1605 uint8_t Nfans; /* Number of Fans */
1606 uint8_t Npwr; /* Number of Power Supplies */
1607 uint8_t Nslots; /* Number of Device Slots */
1608 uint8_t DoorLock; /* Door Lock Installed */
1609 uint8_t Ntherm; /* Number of Temperature Sensors */
1610 uint8_t Nspkrs; /* Number of Speakers */
1611 uint8_t Nalarm; /* Number of Alarms (at least one) */
1613 * Cached Flag Bytes for Global Status
1618 * What object index ID is where various slots start.
1622 #define SAFT_ALARM_OFFSET(cc) (cc)->slotoff - 1
1625 #define SAFT_FLG1_ALARM 0x1
1626 #define SAFT_FLG1_GLOBFAIL 0x2
1627 #define SAFT_FLG1_GLOBWARN 0x4
1628 #define SAFT_FLG1_ENCPWROFF 0x8
1629 #define SAFT_FLG1_ENCFANFAIL 0x10
1630 #define SAFT_FLG1_ENCPWRFAIL 0x20
1631 #define SAFT_FLG1_ENCDRVFAIL 0x40
1632 #define SAFT_FLG1_ENCDRVWARN 0x80
1634 #define SAFT_FLG2_LOCKDOOR 0x4
1635 #define SAFT_PRIVATE sizeof (struct scfg)
1637 static char *safte_2little = "Too Little Data Returned (%d) at line %d\n";
1638 #define SAFT_BAIL(r, x, k, l) \
1640 SES_LOG(ssc, safte_2little, x, __LINE__);\
1647 safte_softc_init(ses_softc_t *ssc, int doinit)
1653 if (ssc->ses_nobjects) {
1654 if (ssc->ses_objmap) {
1655 SES_FREE(ssc->ses_objmap,
1656 ssc->ses_nobjects * sizeof (encobj));
1657 ssc->ses_objmap = NULL;
1659 ssc->ses_nobjects = 0;
1661 if (ssc->ses_private) {
1662 SES_FREE(ssc->ses_private, SAFT_PRIVATE);
1663 ssc->ses_private = NULL;
1668 if (ssc->ses_private == NULL) {
1669 ssc->ses_private = SES_MALLOC(SAFT_PRIVATE);
1670 if (ssc->ses_private == NULL) {
1673 MEMZERO(ssc->ses_private, SAFT_PRIVATE);
1676 ssc->ses_nobjects = 0;
1677 ssc->ses_encstat = 0;
1679 if ((err = safte_getconfig(ssc)) != 0) {
1684 * The number of objects here, as well as that reported by the
1685 * READ_BUFFER/GET_CONFIG call, are the over-temperature flags (15)
1686 * that get reported during READ_BUFFER/READ_ENC_STATUS.
1688 cc = ssc->ses_private;
1689 ssc->ses_nobjects = cc->Nfans + cc->Npwr + cc->Nslots + cc->DoorLock +
1690 cc->Ntherm + cc->Nspkrs + NPSEUDO_THERM + NPSEUDO_ALARM;
1691 ssc->ses_objmap = (encobj *)
1692 SES_MALLOC(ssc->ses_nobjects * sizeof (encobj));
1693 if (ssc->ses_objmap == NULL) {
1696 MEMZERO(ssc->ses_objmap, ssc->ses_nobjects * sizeof (encobj));
1700 * Note that this is all arranged for the convenience
1701 * in later fetches of status.
1703 for (i = 0; i < cc->Nfans; i++)
1704 ssc->ses_objmap[r++].enctype = SESTYP_FAN;
1705 cc->pwroff = (uint8_t) r;
1706 for (i = 0; i < cc->Npwr; i++)
1707 ssc->ses_objmap[r++].enctype = SESTYP_POWER;
1708 for (i = 0; i < cc->DoorLock; i++)
1709 ssc->ses_objmap[r++].enctype = SESTYP_DOORLOCK;
1710 for (i = 0; i < cc->Nspkrs; i++)
1711 ssc->ses_objmap[r++].enctype = SESTYP_ALARM;
1712 for (i = 0; i < cc->Ntherm; i++)
1713 ssc->ses_objmap[r++].enctype = SESTYP_THERM;
1714 for (i = 0; i < NPSEUDO_THERM; i++)
1715 ssc->ses_objmap[r++].enctype = SESTYP_THERM;
1716 ssc->ses_objmap[r++].enctype = SESTYP_ALARM;
1717 cc->slotoff = (uint8_t) r;
1718 for (i = 0; i < cc->Nslots; i++)
1719 ssc->ses_objmap[r++].enctype = SESTYP_DEVICE;
1724 safte_init_enc(ses_softc_t *ssc)
1727 static char cdb0[6] = { SEND_DIAGNOSTIC };
1729 err = ses_runcmd(ssc, cdb0, 6, NULL, 0);
1734 err = wrbuf16(ssc, SAFTE_WT_GLOBAL, 0, 0, 0, 1);
1739 safte_get_encstat(ses_softc_t *ssc, int slpflg)
1741 return (safte_rdstat(ssc, slpflg));
1745 safte_set_encstat(ses_softc_t *ssc, uint8_t encstat, int slpflg)
1747 struct scfg *cc = ssc->ses_private;
1751 * Since SAF-TE devices aren't necessarily sticky in terms
1752 * of state, make our soft copy of enclosure status 'sticky'-
1753 * that is, things set in enclosure status stay set (as implied
1754 * by conditions set in reading object status) until cleared.
1756 ssc->ses_encstat &= ~ALL_ENC_STAT;
1757 ssc->ses_encstat |= (encstat & ALL_ENC_STAT);
1758 ssc->ses_encstat |= ENCI_SVALID;
1759 cc->flag1 &= ~(SAFT_FLG1_ALARM|SAFT_FLG1_GLOBFAIL|SAFT_FLG1_GLOBWARN);
1760 if ((encstat & (SES_ENCSTAT_CRITICAL|SES_ENCSTAT_UNRECOV)) != 0) {
1761 cc->flag1 |= SAFT_FLG1_ALARM|SAFT_FLG1_GLOBFAIL;
1762 } else if ((encstat & SES_ENCSTAT_NONCRITICAL) != 0) {
1763 cc->flag1 |= SAFT_FLG1_GLOBWARN;
1765 return (wrbuf16(ssc, SAFTE_WT_GLOBAL, cc->flag1, cc->flag2, 0, slpflg));
1769 safte_get_objstat(ses_softc_t *ssc, ses_objstat *obp, int slpflg)
1771 int i = (int)obp->obj_id;
1773 if ((ssc->ses_encstat & ENCI_SVALID) == 0 ||
1774 (ssc->ses_objmap[i].svalid) == 0) {
1775 int err = safte_rdstat(ssc, slpflg);
1779 obp->cstat[0] = ssc->ses_objmap[i].encstat[0];
1780 obp->cstat[1] = ssc->ses_objmap[i].encstat[1];
1781 obp->cstat[2] = ssc->ses_objmap[i].encstat[2];
1782 obp->cstat[3] = ssc->ses_objmap[i].encstat[3];
1788 safte_set_objstat(ses_softc_t *ssc, ses_objstat *obp, int slp)
1795 SES_DLOG(ssc, "safte_set_objstat(%d): %x %x %x %x\n",
1796 (int)obp->obj_id, obp->cstat[0], obp->cstat[1], obp->cstat[2],
1800 * If this is clear, we don't do diddly.
1802 if ((obp->cstat[0] & SESCTL_CSEL) == 0) {
1808 * Check to see if the common bits are set and do them first.
1810 if (obp->cstat[0] & ~SESCTL_CSEL) {
1811 err = set_objstat_sel(ssc, obp, slp);
1816 cc = ssc->ses_private;
1820 idx = (int)obp->obj_id;
1821 ep = &ssc->ses_objmap[idx];
1823 switch (ep->enctype) {
1828 * XXX: I should probably cache the previous state
1829 * XXX: of SESCTL_DEVOFF so that when it goes from
1830 * XXX: true to false I can then set PREPARE FOR OPERATION
1831 * XXX: flag in PERFORM SLOT OPERATION write buffer command.
1833 if (obp->cstat[2] & (SESCTL_RQSINS|SESCTL_RQSRMV)) {
1836 if (obp->cstat[2] & SESCTL_RQSID) {
1839 err = perf_slotop(ssc, (uint8_t) idx - (uint8_t) cc->slotoff,
1843 if (obp->cstat[3] & SESCTL_RQSFLT) {
1848 if (ep->priv & 0xc6) {
1851 ep->priv |= 0x1; /* no errors */
1853 wrslot_stat(ssc, slp);
1857 if (obp->cstat[3] & SESCTL_RQSTFAIL) {
1858 cc->flag1 |= SAFT_FLG1_ENCPWRFAIL;
1860 cc->flag1 &= ~SAFT_FLG1_ENCPWRFAIL;
1862 err = wrbuf16(ssc, SAFTE_WT_GLOBAL, cc->flag1,
1866 if (obp->cstat[3] & SESCTL_RQSTON) {
1867 wrbuf16(ssc, SAFTE_WT_ACTPWS,
1868 idx - cc->pwroff, 0, 0, slp);
1870 wrbuf16(ssc, SAFTE_WT_ACTPWS,
1871 idx - cc->pwroff, 0, 1, slp);
1875 if (obp->cstat[3] & SESCTL_RQSTFAIL) {
1876 cc->flag1 |= SAFT_FLG1_ENCFANFAIL;
1878 cc->flag1 &= ~SAFT_FLG1_ENCFANFAIL;
1880 err = wrbuf16(ssc, SAFTE_WT_GLOBAL, cc->flag1,
1884 if (obp->cstat[3] & SESCTL_RQSTON) {
1886 if ((obp->cstat[3] & 0x7) == 7) {
1888 } else if ((obp->cstat[3] & 0x7) == 6) {
1890 } else if ((obp->cstat[3] & 0x7) == 4) {
1895 wrbuf16(ssc, SAFTE_WT_FANSPD, idx, fsp, 0, slp);
1897 wrbuf16(ssc, SAFTE_WT_FANSPD, idx, 0, 0, slp);
1900 case SESTYP_DOORLOCK:
1901 if (obp->cstat[3] & 0x1) {
1902 cc->flag2 &= ~SAFT_FLG2_LOCKDOOR;
1904 cc->flag2 |= SAFT_FLG2_LOCKDOOR;
1906 wrbuf16(ssc, SAFTE_WT_GLOBAL, cc->flag1, cc->flag2, 0, slp);
1910 * On all nonzero but the 'muted' bit, we turn on the alarm,
1912 obp->cstat[3] &= ~0xa;
1913 if (obp->cstat[3] & 0x40) {
1914 cc->flag2 &= ~SAFT_FLG1_ALARM;
1915 } else if (obp->cstat[3] != 0) {
1916 cc->flag2 |= SAFT_FLG1_ALARM;
1918 cc->flag2 &= ~SAFT_FLG1_ALARM;
1920 ep->priv = obp->cstat[3];
1921 wrbuf16(ssc, SAFTE_WT_GLOBAL, cc->flag1, cc->flag2, 0, slp);
1931 safte_getconfig(ses_softc_t *ssc)
1936 static char cdb[10] =
1937 { READ_BUFFER, 1, SAFTE_RD_RDCFG, 0, 0, 0, 0, 0, SAFT_SCRATCH, 0 };
1939 cfg = ssc->ses_private;
1943 sdata = SES_MALLOC(SAFT_SCRATCH);
1948 err = ses_runcmd(ssc, cdb, 10, sdata, &amt);
1950 SES_FREE(sdata, SAFT_SCRATCH);
1953 amt = SAFT_SCRATCH - amt;
1955 SES_LOG(ssc, "too little data (%d) for configuration\n", amt);
1956 SES_FREE(sdata, SAFT_SCRATCH);
1959 SES_VLOG(ssc, "Nfans %d Npwr %d Nslots %d Lck %d Ntherm %d Nspkrs %d\n",
1960 sdata[0], sdata[1], sdata[2], sdata[3], sdata[4], sdata[5]);
1961 cfg->Nfans = sdata[0];
1962 cfg->Npwr = sdata[1];
1963 cfg->Nslots = sdata[2];
1964 cfg->DoorLock = sdata[3];
1965 cfg->Ntherm = sdata[4];
1966 cfg->Nspkrs = sdata[5];
1967 cfg->Nalarm = NPSEUDO_ALARM;
1968 SES_FREE(sdata, SAFT_SCRATCH);
1973 safte_rdstat(ses_softc_t *ssc, int slpflg)
1975 int err, oid, r, i, hiwater, nitems, amt;
1978 uint8_t status, oencstat;
1979 char *sdata, cdb[10];
1980 struct scfg *cc = ssc->ses_private;
1984 * The number of objects overstates things a bit,
1985 * both for the bogus 'thermometer' entries and
1986 * the drive status (which isn't read at the same
1987 * time as the enclosure status), but that's okay.
1989 buflen = 4 * cc->Nslots;
1990 if (ssc->ses_nobjects > buflen)
1991 buflen = ssc->ses_nobjects;
1992 sdata = SES_MALLOC(buflen);
1996 cdb[0] = READ_BUFFER;
1998 cdb[2] = SAFTE_RD_RDESTS;
2003 cdb[7] = (buflen >> 8) & 0xff;
2004 cdb[8] = buflen & 0xff;
2007 err = ses_runcmd(ssc, cdb, 10, sdata, &amt);
2009 SES_FREE(sdata, buflen);
2012 hiwater = buflen - amt;
2016 * invalidate all status bits.
2018 for (i = 0; i < ssc->ses_nobjects; i++)
2019 ssc->ses_objmap[i].svalid = 0;
2020 oencstat = ssc->ses_encstat & ALL_ENC_STAT;
2021 ssc->ses_encstat = 0;
2025 * Now parse returned buffer.
2026 * If we didn't get enough data back,
2027 * that's considered a fatal error.
2031 for (nitems = i = 0; i < cc->Nfans; i++) {
2032 SAFT_BAIL(r, hiwater, sdata, buflen);
2034 * 0 = Fan Operational
2035 * 1 = Fan is malfunctioning
2036 * 2 = Fan is not present
2037 * 0x80 = Unknown or Not Reportable Status
2039 ssc->ses_objmap[oid].encstat[1] = 0; /* resvd */
2040 ssc->ses_objmap[oid].encstat[2] = 0; /* resvd */
2041 switch ((int)(uint8_t)sdata[r]) {
2044 ssc->ses_objmap[oid].encstat[0] = SES_OBJSTAT_OK;
2046 * We could get fancier and cache
2047 * fan speeds that we have set, but
2048 * that isn't done now.
2050 ssc->ses_objmap[oid].encstat[3] = 7;
2054 ssc->ses_objmap[oid].encstat[0] = SES_OBJSTAT_CRIT;
2056 * FAIL and FAN STOPPED synthesized
2058 ssc->ses_objmap[oid].encstat[3] = 0x40;
2060 * Enclosure marked with CRITICAL error
2061 * if only one fan or no thermometers,
2062 * else the NONCRITICAL error is set.
2064 if (cc->Nfans == 1 || cc->Ntherm == 0)
2065 ssc->ses_encstat |= SES_ENCSTAT_CRITICAL;
2067 ssc->ses_encstat |= SES_ENCSTAT_NONCRITICAL;
2070 ssc->ses_objmap[oid].encstat[0] =
2071 SES_OBJSTAT_NOTINSTALLED;
2072 ssc->ses_objmap[oid].encstat[3] = 0;
2074 * Enclosure marked with CRITICAL error
2075 * if only one fan or no thermometers,
2076 * else the NONCRITICAL error is set.
2079 ssc->ses_encstat |= SES_ENCSTAT_CRITICAL;
2081 ssc->ses_encstat |= SES_ENCSTAT_NONCRITICAL;
2084 ssc->ses_objmap[oid].encstat[0] = SES_OBJSTAT_UNKNOWN;
2085 ssc->ses_objmap[oid].encstat[3] = 0;
2086 ssc->ses_encstat |= SES_ENCSTAT_INFO;
2089 ssc->ses_objmap[oid].encstat[0] =
2090 SES_OBJSTAT_UNSUPPORTED;
2091 SES_LOG(ssc, "Unknown fan%d status 0x%x\n", i,
2095 ssc->ses_objmap[oid++].svalid = 1;
2100 * No matter how you cut it, no cooling elements when there
2101 * should be some there is critical.
2103 if (cc->Nfans && nitems == 0) {
2104 ssc->ses_encstat |= SES_ENCSTAT_CRITICAL;
2108 for (i = 0; i < cc->Npwr; i++) {
2109 SAFT_BAIL(r, hiwater, sdata, buflen);
2110 ssc->ses_objmap[oid].encstat[0] = SES_OBJSTAT_UNKNOWN;
2111 ssc->ses_objmap[oid].encstat[1] = 0; /* resvd */
2112 ssc->ses_objmap[oid].encstat[2] = 0; /* resvd */
2113 ssc->ses_objmap[oid].encstat[3] = 0x20; /* requested on */
2114 switch ((uint8_t)sdata[r]) {
2115 case 0x00: /* pws operational and on */
2116 ssc->ses_objmap[oid].encstat[0] = SES_OBJSTAT_OK;
2118 case 0x01: /* pws operational and off */
2119 ssc->ses_objmap[oid].encstat[0] = SES_OBJSTAT_OK;
2120 ssc->ses_objmap[oid].encstat[3] = 0x10;
2121 ssc->ses_encstat |= SES_ENCSTAT_INFO;
2123 case 0x10: /* pws is malfunctioning and commanded on */
2124 ssc->ses_objmap[oid].encstat[0] = SES_OBJSTAT_CRIT;
2125 ssc->ses_objmap[oid].encstat[3] = 0x61;
2126 ssc->ses_encstat |= SES_ENCSTAT_NONCRITICAL;
2129 case 0x11: /* pws is malfunctioning and commanded off */
2130 ssc->ses_objmap[oid].encstat[0] = SES_OBJSTAT_NONCRIT;
2131 ssc->ses_objmap[oid].encstat[3] = 0x51;
2132 ssc->ses_encstat |= SES_ENCSTAT_NONCRITICAL;
2134 case 0x20: /* pws is not present */
2135 ssc->ses_objmap[oid].encstat[0] =
2136 SES_OBJSTAT_NOTINSTALLED;
2137 ssc->ses_objmap[oid].encstat[3] = 0;
2138 ssc->ses_encstat |= SES_ENCSTAT_INFO;
2140 case 0x21: /* pws is present */
2142 * This is for enclosures that cannot tell whether the
2143 * device is on or malfunctioning, but know that it is
2144 * present. Just fall through.
2147 case 0x80: /* Unknown or Not Reportable Status */
2148 ssc->ses_objmap[oid].encstat[0] = SES_OBJSTAT_UNKNOWN;
2149 ssc->ses_objmap[oid].encstat[3] = 0;
2150 ssc->ses_encstat |= SES_ENCSTAT_INFO;
2153 SES_LOG(ssc, "unknown power supply %d status (0x%x)\n",
2154 i, sdata[r] & 0xff);
2157 ssc->ses_objmap[oid++].svalid = 1;
2162 * Skip over Slot SCSI IDs
2167 * We always have doorlock status, no matter what,
2168 * but we only save the status if we have one.
2170 SAFT_BAIL(r, hiwater, sdata, buflen);
2174 * 1 = Door Unlocked, or no Lock Installed
2175 * 0x80 = Unknown or Not Reportable Status
2177 ssc->ses_objmap[oid].encstat[1] = 0;
2178 ssc->ses_objmap[oid].encstat[2] = 0;
2179 switch ((uint8_t)sdata[r]) {
2181 ssc->ses_objmap[oid].encstat[0] = SES_OBJSTAT_OK;
2182 ssc->ses_objmap[oid].encstat[3] = 0;
2185 ssc->ses_objmap[oid].encstat[0] = SES_OBJSTAT_OK;
2186 ssc->ses_objmap[oid].encstat[3] = 1;
2189 ssc->ses_objmap[oid].encstat[0] = SES_OBJSTAT_UNKNOWN;
2190 ssc->ses_objmap[oid].encstat[3] = 0;
2191 ssc->ses_encstat |= SES_ENCSTAT_INFO;
2194 ssc->ses_objmap[oid].encstat[0] =
2195 SES_OBJSTAT_UNSUPPORTED;
2196 SES_LOG(ssc, "unknown lock status 0x%x\n",
2200 ssc->ses_objmap[oid++].svalid = 1;
2205 * We always have speaker status, no matter what,
2206 * but we only save the status if we have one.
2208 SAFT_BAIL(r, hiwater, sdata, buflen);
2210 ssc->ses_objmap[oid].encstat[1] = 0;
2211 ssc->ses_objmap[oid].encstat[2] = 0;
2212 if (sdata[r] == 1) {
2214 * We need to cache tone urgency indicators.
2217 ssc->ses_objmap[oid].encstat[0] = SES_OBJSTAT_NONCRIT;
2218 ssc->ses_objmap[oid].encstat[3] = 0x8;
2219 ssc->ses_encstat |= SES_ENCSTAT_NONCRITICAL;
2220 } else if (sdata[r] == 0) {
2221 ssc->ses_objmap[oid].encstat[0] = SES_OBJSTAT_OK;
2222 ssc->ses_objmap[oid].encstat[3] = 0;
2224 ssc->ses_objmap[oid].encstat[0] =
2225 SES_OBJSTAT_UNSUPPORTED;
2226 ssc->ses_objmap[oid].encstat[3] = 0;
2227 SES_LOG(ssc, "unknown spkr status 0x%x\n",
2230 ssc->ses_objmap[oid++].svalid = 1;
2234 for (i = 0; i < cc->Ntherm; i++) {
2235 SAFT_BAIL(r, hiwater, sdata, buflen);
2237 * Status is a range from -10 to 245 deg Celsius,
2238 * which we need to normalize to -20 to -245 according
2239 * to the latest SCSI spec, which makes little
2240 * sense since this would overflow an 8bit value.
2241 * Well, still, the base normalization is -20,
2242 * not -10, so we have to adjust.
2244 * So what's over and under temperature?
2245 * Hmm- we'll state that 'normal' operating
2246 * is 10 to 40 deg Celsius.
2250 * Actually.... All of the units that people out in the world
2251 * seem to have do not come even close to setting a value that
2252 * complies with this spec.
2254 * The closest explanation I could find was in an
2255 * LSI-Logic manual, which seemed to indicate that
2256 * this value would be set by whatever the I2C code
2257 * would interpolate from the output of an LM75
2258 * temperature sensor.
2260 * This means that it is impossible to use the actual
2261 * numeric value to predict anything. But we don't want
2262 * to lose the value. So, we'll propagate the *uncorrected*
2263 * value and set SES_OBJSTAT_NOTAVAIL. We'll depend on the
2264 * temperature flags for warnings.
2266 ssc->ses_objmap[oid].encstat[0] = SES_OBJSTAT_NOTAVAIL;
2267 ssc->ses_objmap[oid].encstat[1] = 0;
2268 ssc->ses_objmap[oid].encstat[2] = sdata[r];
2269 ssc->ses_objmap[oid].encstat[3] = 0;
2270 ssc->ses_objmap[oid++].svalid = 1;
2275 * Now, for "pseudo" thermometers, we have two bytes
2276 * of information in enclosure status- 16 bits. Actually,
2277 * the MSB is a single TEMP ALERT flag indicating whether
2278 * any other bits are set, but, thanks to fuzzy thinking,
2279 * in the SAF-TE spec, this can also be set even if no
2280 * other bits are set, thus making this really another
2281 * binary temperature sensor.
2284 SAFT_BAIL(r, hiwater, sdata, buflen);
2285 tempflags = sdata[r++];
2286 SAFT_BAIL(r, hiwater, sdata, buflen);
2287 tempflags |= (tempflags << 8) | sdata[r++];
2289 for (i = 0; i < NPSEUDO_THERM; i++) {
2290 ssc->ses_objmap[oid].encstat[1] = 0;
2291 if (tempflags & (1 << (NPSEUDO_THERM - i - 1))) {
2292 ssc->ses_objmap[oid].encstat[0] = SES_OBJSTAT_CRIT;
2293 ssc->ses_objmap[4].encstat[2] = 0xff;
2295 * Set 'over temperature' failure.
2297 ssc->ses_objmap[oid].encstat[3] = 8;
2298 ssc->ses_encstat |= SES_ENCSTAT_CRITICAL;
2301 * We used to say 'not available' and synthesize a
2302 * nominal 30 deg (C)- that was wrong. Actually,
2303 * Just say 'OK', and use the reserved value of
2306 ssc->ses_objmap[oid].encstat[0] = SES_OBJSTAT_OK;
2307 ssc->ses_objmap[oid].encstat[2] = 0;
2308 ssc->ses_objmap[oid].encstat[3] = 0;
2310 ssc->ses_objmap[oid++].svalid = 1;
2316 ssc->ses_objmap[oid].encstat[0] = SES_OBJSTAT_OK;
2317 ssc->ses_objmap[oid].encstat[3] = ssc->ses_objmap[oid].priv;
2318 ssc->ses_objmap[oid++].svalid = 1;
2321 * Now get drive slot status
2323 cdb[2] = SAFTE_RD_RDDSTS;
2325 err = ses_runcmd(ssc, cdb, 10, sdata, &amt);
2327 SES_FREE(sdata, buflen);
2330 hiwater = buflen - amt;
2331 for (r = i = 0; i < cc->Nslots; i++, r += 4) {
2332 SAFT_BAIL(r+3, hiwater, sdata, buflen);
2333 ssc->ses_objmap[oid].encstat[0] = SES_OBJSTAT_UNSUPPORTED;
2334 ssc->ses_objmap[oid].encstat[1] = (uint8_t) i;
2335 ssc->ses_objmap[oid].encstat[2] = 0;
2336 ssc->ses_objmap[oid].encstat[3] = 0;
2337 status = sdata[r+3];
2338 if ((status & 0x1) == 0) { /* no device */
2339 ssc->ses_objmap[oid].encstat[0] =
2340 SES_OBJSTAT_NOTINSTALLED;
2342 ssc->ses_objmap[oid].encstat[0] = SES_OBJSTAT_OK;
2345 ssc->ses_objmap[oid].encstat[2] = 0x8;
2347 if ((status & 0x4) == 0) {
2348 ssc->ses_objmap[oid].encstat[3] = 0x10;
2350 ssc->ses_objmap[oid++].svalid = 1;
2352 /* see comment below about sticky enclosure status */
2353 ssc->ses_encstat |= ENCI_SVALID | oencstat;
2354 SES_FREE(sdata, buflen);
2359 set_objstat_sel(ses_softc_t *ssc, ses_objstat *obp, int slp)
2363 struct scfg *cc = ssc->ses_private;
2368 idx = (int)obp->obj_id;
2369 ep = &ssc->ses_objmap[idx];
2371 switch (ep->enctype) {
2373 if (obp->cstat[0] & SESCTL_PRDFAIL) {
2376 /* SESCTL_RSTSWAP has no correspondence in SAF-TE */
2377 if (obp->cstat[0] & SESCTL_DISABLE) {
2380 * Hmm. Try to set the 'No Drive' flag.
2381 * Maybe that will count as a 'disable'.
2384 if (ep->priv & 0xc6) {
2387 ep->priv |= 0x1; /* no errors */
2389 wrslot_stat(ssc, slp);
2393 * Okay- the only one that makes sense here is to
2394 * do the 'disable' for a power supply.
2396 if (obp->cstat[0] & SESCTL_DISABLE) {
2397 wrbuf16(ssc, SAFTE_WT_ACTPWS,
2398 idx - cc->pwroff, 0, 0, slp);
2403 * Okay- the only one that makes sense here is to
2404 * set fan speed to zero on disable.
2406 if (obp->cstat[0] & SESCTL_DISABLE) {
2407 /* remember- fans are the first items, so idx works */
2408 wrbuf16(ssc, SAFTE_WT_FANSPD, idx, 0, 0, slp);
2411 case SESTYP_DOORLOCK:
2413 * Well, we can 'disable' the lock.
2415 if (obp->cstat[0] & SESCTL_DISABLE) {
2416 cc->flag2 &= ~SAFT_FLG2_LOCKDOOR;
2417 wrbuf16(ssc, SAFTE_WT_GLOBAL, cc->flag1,
2423 * Well, we can 'disable' the alarm.
2425 if (obp->cstat[0] & SESCTL_DISABLE) {
2426 cc->flag2 &= ~SAFT_FLG1_ALARM;
2427 ep->priv |= 0x40; /* Muted */
2428 wrbuf16(ssc, SAFTE_WT_GLOBAL, cc->flag1,
2440 * This function handles all of the 16 byte WRITE BUFFER commands.
2443 wrbuf16(ses_softc_t *ssc, uint8_t op, uint8_t b1, uint8_t b2,
2444 uint8_t b3, int slp)
2448 struct scfg *cc = ssc->ses_private;
2449 static char cdb[10] = { WRITE_BUFFER, 1, 0, 0, 0, 0, 0, 0, 16, 0 };
2454 sdata = SES_MALLOC(16);
2458 SES_DLOG(ssc, "saf_wrbuf16 %x %x %x %x\n", op, b1, b2, b3);
2464 MEMZERO(&sdata[4], 12);
2466 err = ses_runcmd(ssc, cdb, 10, sdata, &amt);
2467 SES_FREE(sdata, 16);
2472 * This function updates the status byte for the device slot described.
2474 * Since this is an optional SAF-TE command, there's no point in
2475 * returning an error.
2478 wrslot_stat(ses_softc_t *ssc, int slp)
2482 char cdb[10], *sdata;
2483 struct scfg *cc = ssc->ses_private;
2488 SES_DLOG(ssc, "saf_wrslot\n");
2489 cdb[0] = WRITE_BUFFER;
2497 cdb[8] = cc->Nslots * 3 + 1;
2500 sdata = SES_MALLOC(cc->Nslots * 3 + 1);
2503 MEMZERO(sdata, cc->Nslots * 3 + 1);
2505 sdata[0] = SAFTE_WT_DSTAT;
2506 for (i = 0; i < cc->Nslots; i++) {
2507 ep = &ssc->ses_objmap[cc->slotoff + i];
2508 SES_DLOG(ssc, "saf_wrslot %d <- %x\n", i, ep->priv & 0xff);
2509 sdata[1 + (3 * i)] = ep->priv & 0xff;
2511 amt = -(cc->Nslots * 3 + 1);
2512 ses_runcmd(ssc, cdb, 10, sdata, &amt);
2513 SES_FREE(sdata, cc->Nslots * 3 + 1);
2517 * This function issues the "PERFORM SLOT OPERATION" command.
2520 perf_slotop(ses_softc_t *ssc, uint8_t slot, uint8_t opflag, int slp)
2524 struct scfg *cc = ssc->ses_private;
2525 static char cdb[10] =
2526 { WRITE_BUFFER, 1, 0, 0, 0, 0, 0, 0, SAFT_SCRATCH, 0 };
2531 sdata = SES_MALLOC(SAFT_SCRATCH);
2534 MEMZERO(sdata, SAFT_SCRATCH);
2536 sdata[0] = SAFTE_WT_SLTOP;
2539 SES_DLOG(ssc, "saf_slotop slot %d op %x\n", slot, opflag);
2540 amt = -SAFT_SCRATCH;
2541 err = ses_runcmd(ssc, cdb, 10, sdata, &amt);
2542 SES_FREE(sdata, SAFT_SCRATCH);