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.14 2006/02/17 19:17:42 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) malloc(amt, M_DEVBUF, M_INTWAIT)
129 #define SES_FREE(ptr, amt) free(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 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 cam_extend_release(sesperiphs, periph->unit_number);
275 xpt_print_path(periph->path);
276 printf("removing device entry\n");
277 cdevsw_remove(&ses_cdevsw, -1, periph->unit_number);
278 free(softc, M_DEVBUF);
282 sesasync(void *callback_arg, u_int32_t code, struct cam_path *path, void *arg)
284 struct cam_periph *periph;
286 periph = (struct cam_periph *)callback_arg;
289 case AC_FOUND_DEVICE:
292 struct ccb_getdev *cgd;
294 cgd = (struct ccb_getdev *)arg;
297 * PROBLEM: WE NEED TO LOOK AT BYTES 48-53 TO SEE IF THIS IS
298 * PROBLEM: IS A SAF-TE DEVICE.
300 switch (ses_type(&cgd->inq_data, cgd->inq_len)) {
303 case SES_SES_PASSTHROUGH:
311 status = cam_periph_alloc(sesregister, sesoninvalidate,
312 sescleanup, sesstart, "ses", CAM_PERIPH_BIO,
313 cgd->ccb_h.path, sesasync, AC_FOUND_DEVICE, cgd);
315 if (status != CAM_REQ_CMP && status != CAM_REQ_INPROG) {
316 printf("sesasync: Unable to probe new device due to "
317 "status 0x%x\n", status);
322 cam_periph_async(periph, code, path, arg);
328 sesregister(struct cam_periph *periph, void *arg)
330 struct ses_softc *softc;
331 struct ccb_setasync csa;
332 struct ccb_getdev *cgd;
335 cgd = (struct ccb_getdev *)arg;
336 if (periph == NULL) {
337 printf("sesregister: periph was NULL!!\n");
338 return (CAM_REQ_CMP_ERR);
342 printf("sesregister: no getdev CCB, can't register device\n");
343 return (CAM_REQ_CMP_ERR);
346 softc = malloc(sizeof (struct ses_softc), M_DEVBUF, M_INTWAIT | M_ZERO);
347 periph->softc = softc;
348 softc->periph = periph;
350 softc->ses_type = ses_type(&cgd->inq_data, sizeof (cgd->inq_data));
352 switch (softc->ses_type) {
355 case SES_SES_PASSTHROUGH:
356 softc->ses_vec.softc_init = ses_softc_init;
357 softc->ses_vec.init_enc = ses_init_enc;
358 softc->ses_vec.get_encstat = ses_get_encstat;
359 softc->ses_vec.set_encstat = ses_set_encstat;
360 softc->ses_vec.get_objstat = ses_get_objstat;
361 softc->ses_vec.set_objstat = ses_set_objstat;
364 softc->ses_vec.softc_init = safte_softc_init;
365 softc->ses_vec.init_enc = safte_init_enc;
366 softc->ses_vec.get_encstat = safte_get_encstat;
367 softc->ses_vec.set_encstat = safte_set_encstat;
368 softc->ses_vec.get_objstat = safte_get_objstat;
369 softc->ses_vec.set_objstat = safte_set_objstat;
375 free(softc, M_DEVBUF);
376 return (CAM_REQ_CMP_ERR);
379 cam_extend_set(sesperiphs, periph->unit_number, periph);
381 cdevsw_add(&ses_cdevsw, -1, periph->unit_number);
382 make_dev(&ses_cdevsw, periph->unit_number,
383 UID_ROOT, GID_OPERATOR, 0600, "%s%d",
384 periph->periph_name, periph->unit_number);
387 * Add an async callback so that we get
388 * notified if this device goes away.
390 xpt_setup_ccb(&csa.ccb_h, periph->path, 5);
391 csa.ccb_h.func_code = XPT_SASYNC_CB;
392 csa.event_enable = AC_LOST_DEVICE;
393 csa.callback = sesasync;
394 csa.callback_arg = periph;
395 xpt_action((union ccb *)&csa);
397 switch (softc->ses_type) {
400 tname = "No SES device";
403 tname = "SCSI-2 SES Device";
406 tname = "SCSI-3 SES Device";
408 case SES_SES_PASSTHROUGH:
409 tname = "SES Passthrough Device";
412 tname = "UNISYS SEN Device (NOT HANDLED YET)";
415 tname = "SAF-TE Compliant Device";
418 xpt_announce_periph(periph, tname);
419 return (CAM_REQ_CMP);
423 sesopen(dev_t dev, int flags, int fmt, struct thread *td)
425 struct cam_periph *periph;
426 struct ses_softc *softc;
430 periph = cam_extend_get(sesperiphs, SESUNIT(dev));
431 if (periph == NULL) {
435 if ((error = cam_periph_lock(periph, PCATCH)) != 0) {
441 if (cam_periph_acquire(periph) != CAM_REQ_CMP) {
442 cam_periph_unlock(periph);
446 softc = (struct ses_softc *)periph->softc;
448 if (softc->ses_flags & SES_FLAG_INVALID) {
452 if (softc->ses_flags & SES_FLAG_OPEN) {
456 if (softc->ses_vec.softc_init == NULL) {
461 softc->ses_flags |= SES_FLAG_OPEN;
462 if ((softc->ses_flags & SES_FLAG_INITIALIZED) == 0) {
463 error = (*softc->ses_vec.softc_init)(softc, 1);
465 softc->ses_flags &= ~SES_FLAG_OPEN;
467 softc->ses_flags |= SES_FLAG_INITIALIZED;
472 cam_periph_release(periph);
474 cam_periph_unlock(periph);
479 sesclose(dev_t dev, int flag, int fmt, struct thread *td)
481 struct cam_periph *periph;
482 struct ses_softc *softc;
488 periph = cam_extend_get(sesperiphs, unit);
492 softc = (struct ses_softc *)periph->softc;
494 if ((error = cam_periph_lock(periph, 0)) != 0)
497 softc->ses_flags &= ~SES_FLAG_OPEN;
499 cam_periph_unlock(periph);
500 cam_periph_release(periph);
506 sesstart(struct cam_periph *p, union ccb *sccb)
509 if (p->immediate_priority <= p->pinfo.priority) {
510 SLIST_INSERT_HEAD(&p->ccb_list, &sccb->ccb_h, periph_links.sle);
511 p->immediate_priority = CAM_PRIORITY_NONE;
512 wakeup(&p->ccb_list);
518 sesdone(struct cam_periph *periph, union ccb *dccb)
520 wakeup(&dccb->ccb_h.cbfcnp);
524 seserror(union ccb *ccb, u_int32_t cflags, u_int32_t sflags)
526 struct ses_softc *softc;
527 struct cam_periph *periph;
529 periph = xpt_path_periph(ccb->ccb_h.path);
530 softc = (struct ses_softc *)periph->softc;
532 return (cam_periph_error(ccb, cflags, sflags, &softc->ses_saved_ccb));
536 sesioctl(dev_t dev, u_long cmd, caddr_t arg_addr, int flag, struct thread *td)
538 struct cam_periph *periph;
541 ses_object obj, *uobj;
542 struct ses_softc *ssc;
548 addr = *((caddr_t *) arg_addr);
552 periph = cam_extend_get(sesperiphs, SESUNIT(dev));
556 CAM_DEBUG(periph->path, CAM_DEBUG_TRACE, ("entering sesioctl\n"));
558 ssc = (struct ses_softc *)periph->softc;
561 * Now check to see whether we're initialized or not.
563 if ((ssc->ses_flags & SES_FLAG_INITIALIZED) == 0) {
569 CAM_DEBUG(periph->path, CAM_DEBUG_TRACE,
570 ("trying to do ioctl %#lx\n", cmd));
573 * If this command can change the device's state,
574 * we must have the device open for writing.
578 case SESIOC_GETOBJMAP:
579 case SESIOC_GETENCSTAT:
580 case SESIOC_GETOBJSTAT:
583 if ((flag & FWRITE) == 0) {
590 error = copyout(&ssc->ses_nobjects, addr,
591 sizeof (ssc->ses_nobjects));
594 case SESIOC_GETOBJMAP:
595 for (uobj = addr, i = 0; i != ssc->ses_nobjects; i++, uobj++) {
597 obj.subencid = ssc->ses_objmap[i].subenclosure;
598 obj.object_type = ssc->ses_objmap[i].enctype;
599 error = copyout(&obj, uobj, sizeof (ses_object));
606 case SESIOC_GETENCSTAT:
607 error = (*ssc->ses_vec.get_encstat)(ssc, 1);
610 tmp = ssc->ses_encstat & ~ENCI_SVALID;
611 error = copyout(&tmp, addr, sizeof (ses_encstat));
612 ssc->ses_encstat = tmp;
615 case SESIOC_SETENCSTAT:
616 error = copyin(addr, &tmp, sizeof (ses_encstat));
619 error = (*ssc->ses_vec.set_encstat)(ssc, tmp, 1);
622 case SESIOC_GETOBJSTAT:
623 error = copyin(addr, &objs, sizeof (ses_objstat));
626 if (objs.obj_id >= ssc->ses_nobjects) {
630 error = (*ssc->ses_vec.get_objstat)(ssc, &objs, 1);
633 error = copyout(&objs, addr, sizeof (ses_objstat));
635 * Always (for now) invalidate entry.
637 ssc->ses_objmap[objs.obj_id].svalid = 0;
640 case SESIOC_SETOBJSTAT:
641 error = copyin(addr, &objs, sizeof (ses_objstat));
645 if (objs.obj_id >= ssc->ses_nobjects) {
649 error = (*ssc->ses_vec.set_objstat)(ssc, &objs, 1);
652 * Always (for now) invalidate entry.
654 ssc->ses_objmap[objs.obj_id].svalid = 0;
659 error = (*ssc->ses_vec.init_enc)(ssc);
663 error = cam_periph_ioctl(periph, cmd, arg_addr, seserror);
669 #define SES_FLAGS SF_NO_PRINT | SF_RETRY_SELTO | SF_RETRY_UA
671 ses_runcmd(struct ses_softc *ssc, char *cdb, int cdbl, char *dptr, int *dlenp)
678 if ((dlen = *dlenp) < 0) {
689 if (cdbl > IOCDBLEN) {
693 ccb = cam_periph_getccb(ssc->periph, 1);
694 cam_fill_csio(&ccb->csio, 0, sesdone, ddf, MSG_SIMPLE_Q_TAG, dptr,
695 dlen, sizeof (struct scsi_sense_data), cdbl, 60 * 1000);
696 bcopy(cdb, ccb->csio.cdb_io.cdb_bytes, cdbl);
698 error = cam_periph_runccb(ccb, seserror, 0, SES_FLAGS, NULL);
699 if ((ccb->ccb_h.status & CAM_DEV_QFRZN) != 0)
700 cam_release_devq(ccb->ccb_h.path, 0, 0, 0, FALSE);
707 *dlenp = ccb->csio.resid;
710 xpt_release_ccb(ccb);
715 ses_log(struct ses_softc *ssc, const char *fmt, ...)
719 printf("%s%d: ", ssc->periph->periph_name, ssc->periph->unit_number);
726 * The code after this point runs on many platforms,
727 * so forgive the slightly awkward and nonconforming
732 * Is this a device that supports enclosure services?
734 * It's a a pretty simple ruleset- if it is device type 0x0D (13), it's
735 * an SES device. If it happens to be an old UNISYS SEN device, we can
739 #define SAFTE_START 44
741 #define SAFTE_LEN SAFTE_END-SAFTE_START
744 ses_type(void *buf, int buflen)
746 unsigned char *iqd = buf;
749 buflen = 256; /* per SPC-2 */
751 if (buflen < 8+SEN_ID_LEN)
754 if ((iqd[0] & 0x1f) == T_ENCLOSURE) {
755 if (STRNCMP(&iqd[8], SEN_ID, SEN_ID_LEN) == 0) {
757 } else if ((iqd[2] & 0x7) > 2) {
760 return (SES_SES_SCSI2);
765 #ifdef SES_ENABLE_PASSTHROUGH
766 if ((iqd[6] & 0x40) && (iqd[2] & 0x7) >= 2) {
768 * PassThrough Device.
770 return (SES_SES_PASSTHROUGH);
775 * The comparison is short for a reason-
776 * some vendors were chopping it short.
779 if (buflen < SAFTE_END - 2) {
783 if (STRNCMP((char *)&iqd[SAFTE_START], "SAF-TE", SAFTE_LEN - 2) == 0) {
790 * SES Native Type Device Support
794 * SES Diagnostic Page Codes
800 #define SesStatusPage SesControlPage
803 #define SesStringIn SesStringOut
805 #define SesThresholdIn SesThresholdOut
807 #define SesArrayStatus SesArrayControl
808 SesElementDescriptor,
817 * Minimum amount of data, starting from byte 0, to have
820 #define SES_CFGHDR_MINLEN 12
823 * Minimum amount of data, starting from byte 0, to have
824 * the config header and one enclosure header.
826 #define SES_ENCHDR_MINLEN 48
829 * Take this value, subtract it from VEnclen and you know
830 * the length of the vendor unique bytes.
832 #define SES_ENCHDR_VMIN 36
835 * SES Data Structures
839 uint32_t GenCode; /* Generation Code */
840 uint8_t Nsubenc; /* Number of Subenclosures */
844 uint8_t Subencid; /* SubEnclosure Identifier */
845 uint8_t Ntypes; /* # of supported types */
846 uint8_t VEnclen; /* Enclosure Descriptor Length */
850 uint8_t encWWN[8]; /* XXX- Not Right Yet */
858 uint8_t enc_type; /* type of element */
859 uint8_t enc_maxelt; /* maximum supported */
860 uint8_t enc_subenc; /* in SubEnc # N */
861 uint8_t enc_tlen; /* Type Descriptor Text Length */
875 uint8_t ses_ntypes; /* total number of types supported */
878 * We need to keep a type index as well as an
879 * object index for each object in an enclosure.
881 struct typidx *ses_typidx;
884 * We also need to keep track of the number of elements
885 * per type of element. This is needed later so that we
886 * can find precisely in the returned status data the
887 * status for the Nth element of the Kth type.
889 uint8_t * ses_eltmap;
894 * (de)canonicalization defines
896 #define sbyte(x, byte) ((((uint32_t)(x)) >> (byte * 8)) & 0xff)
897 #define sbit(x, bit) (((uint32_t)(x)) << bit)
898 #define sset8(outp, idx, sval) (((uint8_t *)(outp))[idx++]) = sbyte(sval, 0)
900 #define sset16(outp, idx, sval) \
901 (((uint8_t *)(outp))[idx++]) = sbyte(sval, 1), \
902 (((uint8_t *)(outp))[idx++]) = sbyte(sval, 0)
905 #define sset24(outp, idx, sval) \
906 (((uint8_t *)(outp))[idx++]) = sbyte(sval, 2), \
907 (((uint8_t *)(outp))[idx++]) = sbyte(sval, 1), \
908 (((uint8_t *)(outp))[idx++]) = sbyte(sval, 0)
911 #define sset32(outp, idx, sval) \
912 (((uint8_t *)(outp))[idx++]) = sbyte(sval, 3), \
913 (((uint8_t *)(outp))[idx++]) = sbyte(sval, 2), \
914 (((uint8_t *)(outp))[idx++]) = sbyte(sval, 1), \
915 (((uint8_t *)(outp))[idx++]) = sbyte(sval, 0)
917 #define gbyte(x, byte) ((((uint32_t)(x)) & 0xff) << (byte * 8))
918 #define gbit(lv, in, idx, shft, mask) lv = ((in[idx] >> shft) & mask)
919 #define sget8(inp, idx, lval) lval = (((uint8_t *)(inp))[idx++])
920 #define gget8(inp, idx, lval) lval = (((uint8_t *)(inp))[idx])
922 #define sget16(inp, idx, lval) \
923 lval = gbyte((((uint8_t *)(inp))[idx]), 1) | \
924 (((uint8_t *)(inp))[idx+1]), idx += 2
926 #define gget16(inp, idx, lval) \
927 lval = gbyte((((uint8_t *)(inp))[idx]), 1) | \
928 (((uint8_t *)(inp))[idx+1])
930 #define sget24(inp, idx, lval) \
931 lval = gbyte((((uint8_t *)(inp))[idx]), 2) | \
932 gbyte((((uint8_t *)(inp))[idx+1]), 1) | \
933 (((uint8_t *)(inp))[idx+2]), idx += 3
935 #define gget24(inp, idx, lval) \
936 lval = gbyte((((uint8_t *)(inp))[idx]), 2) | \
937 gbyte((((uint8_t *)(inp))[idx+1]), 1) | \
938 (((uint8_t *)(inp))[idx+2])
940 #define sget32(inp, idx, lval) \
941 lval = gbyte((((uint8_t *)(inp))[idx]), 3) | \
942 gbyte((((uint8_t *)(inp))[idx+1]), 2) | \
943 gbyte((((uint8_t *)(inp))[idx+2]), 1) | \
944 (((uint8_t *)(inp))[idx+3]), idx += 4
946 #define gget32(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])
953 #define CFLEN (256 + SES_ENCHDR_MINLEN)
956 * Routines specific && private to SES only
959 static int ses_getconfig(ses_softc_t *);
960 static int ses_getputstat(ses_softc_t *, int, SesComStat *, int, int);
961 static int ses_cfghdr(uint8_t *, int, SesCfgHdr *);
962 static int ses_enchdr(uint8_t *, int, uint8_t, SesEncHdr *);
963 static int ses_encdesc(uint8_t *, int, uint8_t, SesEncDesc *);
964 static int ses_getthdr(uint8_t *, int, int, SesThdr *);
965 static int ses_decode(char *, int, uint8_t *, int, int, SesComStat *);
966 static int ses_encode(char *, int, uint8_t *, int, int, SesComStat *);
969 ses_softc_init(ses_softc_t *ssc, int doinit)
973 if (ssc->ses_nobjects) {
974 SES_FREE(ssc->ses_objmap,
975 ssc->ses_nobjects * sizeof (encobj));
976 ssc->ses_objmap = NULL;
978 if ((cc = ssc->ses_private) != NULL) {
979 if (cc->ses_eltmap && cc->ses_ntypes) {
980 SES_FREE(cc->ses_eltmap, cc->ses_ntypes);
981 cc->ses_eltmap = NULL;
984 if (cc->ses_typidx && ssc->ses_nobjects) {
985 SES_FREE(cc->ses_typidx,
986 ssc->ses_nobjects * sizeof (struct typidx));
987 cc->ses_typidx = NULL;
989 SES_FREE(cc, sizeof (struct sscfg));
990 ssc->ses_private = NULL;
992 ssc->ses_nobjects = 0;
995 if (ssc->ses_private == NULL) {
996 ssc->ses_private = SES_MALLOC(sizeof (struct sscfg));
998 if (ssc->ses_private == NULL) {
1001 ssc->ses_nobjects = 0;
1002 ssc->ses_encstat = 0;
1003 return (ses_getconfig(ssc));
1007 ses_init_enc(ses_softc_t *ssc)
1013 ses_get_encstat(ses_softc_t *ssc, int slpflag)
1018 if ((status = ses_getputstat(ssc, -1, &ComStat, slpflag, 1)) != 0) {
1021 ssc->ses_encstat = ComStat.comstatus | ENCI_SVALID;
1026 ses_set_encstat(ses_softc_t *ssc, uint8_t encstat, int slpflag)
1031 ComStat.comstatus = encstat & 0xf;
1032 if ((status = ses_getputstat(ssc, -1, &ComStat, slpflag, 0)) != 0) {
1035 ssc->ses_encstat = encstat & 0xf; /* note no SVALID set */
1040 ses_get_objstat(ses_softc_t *ssc, ses_objstat *obp, int slpflag)
1042 int i = (int)obp->obj_id;
1044 if (ssc->ses_objmap[i].svalid == 0) {
1046 int err = ses_getputstat(ssc, i, &ComStat, slpflag, 1);
1049 ssc->ses_objmap[i].encstat[0] = ComStat.comstatus;
1050 ssc->ses_objmap[i].encstat[1] = ComStat.comstat[0];
1051 ssc->ses_objmap[i].encstat[2] = ComStat.comstat[1];
1052 ssc->ses_objmap[i].encstat[3] = ComStat.comstat[2];
1053 ssc->ses_objmap[i].svalid = 1;
1055 obp->cstat[0] = ssc->ses_objmap[i].encstat[0];
1056 obp->cstat[1] = ssc->ses_objmap[i].encstat[1];
1057 obp->cstat[2] = ssc->ses_objmap[i].encstat[2];
1058 obp->cstat[3] = ssc->ses_objmap[i].encstat[3];
1063 ses_set_objstat(ses_softc_t *ssc, ses_objstat *obp, int slpflag)
1068 * If this is clear, we don't do diddly.
1070 if ((obp->cstat[0] & SESCTL_CSEL) == 0) {
1073 ComStat.comstatus = obp->cstat[0];
1074 ComStat.comstat[0] = obp->cstat[1];
1075 ComStat.comstat[1] = obp->cstat[2];
1076 ComStat.comstat[2] = obp->cstat[3];
1077 err = ses_getputstat(ssc, (int)obp->obj_id, &ComStat, slpflag, 0);
1078 ssc->ses_objmap[(int)obp->obj_id].svalid = 0;
1083 ses_getconfig(ses_softc_t *ssc)
1090 int err, amt, i, nobj, ntype, maxima;
1091 char storage[CFLEN], *sdata;
1092 static char cdb[6] = {
1093 RECEIVE_DIAGNOSTIC, 0x1, SesConfigPage, SCSZ >> 8, SCSZ & 0xff, 0
1096 cc = ssc->ses_private;
1101 sdata = SES_MALLOC(SCSZ);
1106 err = ses_runcmd(ssc, cdb, 6, sdata, &amt);
1108 SES_FREE(sdata, SCSZ);
1113 if (ses_cfghdr((uint8_t *) sdata, amt, &cf)) {
1114 SES_LOG(ssc, "Unable to parse SES Config Header\n");
1115 SES_FREE(sdata, SCSZ);
1118 if (amt < SES_ENCHDR_MINLEN) {
1119 SES_LOG(ssc, "runt enclosure length (%d)\n", amt);
1120 SES_FREE(sdata, SCSZ);
1124 SES_VLOG(ssc, "GenCode %x %d Subenclosures\n", cf.GenCode, cf.Nsubenc);
1127 * Now waltz through all the subenclosures toting up the
1128 * number of types available in each. For this, we only
1129 * really need the enclosure header. However, we get the
1130 * enclosure descriptor for debug purposes, as well
1131 * as self-consistency checking purposes.
1134 maxima = cf.Nsubenc + 1;
1135 cdp = (SesEncDesc *) storage;
1136 for (ntype = i = 0; i < maxima; i++) {
1137 MEMZERO((caddr_t)cdp, sizeof (*cdp));
1138 if (ses_enchdr((uint8_t *) sdata, amt, i, &hd)) {
1139 SES_LOG(ssc, "Cannot Extract Enclosure Header %d\n", i);
1140 SES_FREE(sdata, SCSZ);
1143 SES_VLOG(ssc, " SubEnclosure ID %d, %d Types With this ID, En"
1144 "closure Length %d\n", hd.Subencid, hd.Ntypes, hd.VEnclen);
1146 if (ses_encdesc((uint8_t *)sdata, amt, i, cdp)) {
1147 SES_LOG(ssc, "Can't get Enclosure Descriptor %d\n", i);
1148 SES_FREE(sdata, SCSZ);
1151 SES_VLOG(ssc, " WWN: %02x%02x%02x%02x%02x%02x%02x%02x\n",
1152 cdp->encWWN[0], cdp->encWWN[1], cdp->encWWN[2],
1153 cdp->encWWN[3], cdp->encWWN[4], cdp->encWWN[5],
1154 cdp->encWWN[6], cdp->encWWN[7]);
1159 * Now waltz through all the types that are available, getting
1160 * the type header so we can start adding up the number of
1161 * objects available.
1163 for (nobj = i = 0; i < ntype; i++) {
1164 if (ses_getthdr((uint8_t *)sdata, amt, i, &thdr)) {
1165 SES_LOG(ssc, "Can't get Enclosure Type Header %d\n", i);
1166 SES_FREE(sdata, SCSZ);
1169 SES_LOG(ssc, " Type Desc[%d]: Type 0x%x, MaxElt %d, In Subenc "
1170 "%d, Text Length %d\n", i, thdr.enc_type, thdr.enc_maxelt,
1171 thdr.enc_subenc, thdr.enc_tlen);
1172 nobj += thdr.enc_maxelt;
1177 * Now allocate the object array and type map.
1180 ssc->ses_objmap = SES_MALLOC(nobj * sizeof (encobj));
1181 cc->ses_typidx = SES_MALLOC(nobj * sizeof (struct typidx));
1182 cc->ses_eltmap = SES_MALLOC(ntype);
1184 if (ssc->ses_objmap == NULL || cc->ses_typidx == NULL ||
1185 cc->ses_eltmap == NULL) {
1186 if (ssc->ses_objmap) {
1187 SES_FREE(ssc->ses_objmap, (nobj * sizeof (encobj)));
1188 ssc->ses_objmap = NULL;
1190 if (cc->ses_typidx) {
1191 SES_FREE(cc->ses_typidx,
1192 (nobj * sizeof (struct typidx)));
1193 cc->ses_typidx = NULL;
1195 if (cc->ses_eltmap) {
1196 SES_FREE(cc->ses_eltmap, ntype);
1197 cc->ses_eltmap = NULL;
1199 SES_FREE(sdata, SCSZ);
1202 MEMZERO(ssc->ses_objmap, nobj * sizeof (encobj));
1203 MEMZERO(cc->ses_typidx, nobj * sizeof (struct typidx));
1204 MEMZERO(cc->ses_eltmap, ntype);
1205 cc->ses_ntypes = (uint8_t) ntype;
1206 ssc->ses_nobjects = nobj;
1209 * Now waltz through the # of types again to fill in the types
1210 * (and subenclosure ids) of the allocated objects.
1213 for (i = 0; i < ntype; i++) {
1215 if (ses_getthdr((uint8_t *)sdata, amt, i, &thdr)) {
1218 cc->ses_eltmap[i] = thdr.enc_maxelt;
1219 for (j = 0; j < thdr.enc_maxelt; j++) {
1220 cc->ses_typidx[nobj].ses_tidx = i;
1221 cc->ses_typidx[nobj].ses_oidx = j;
1222 ssc->ses_objmap[nobj].subenclosure = thdr.enc_subenc;
1223 ssc->ses_objmap[nobj++].enctype = thdr.enc_type;
1226 SES_FREE(sdata, SCSZ);
1231 ses_getputstat(ses_softc_t *ssc, int objid, SesComStat *sp, int slp, int in)
1234 int err, amt, bufsiz, tidx, oidx;
1235 char cdb[6], *sdata;
1237 cc = ssc->ses_private;
1243 * If we're just getting overall enclosure status,
1244 * we only need 2 bytes of data storage.
1246 * If we're getting anything else, we know how much
1247 * storage we need by noting that starting at offset
1248 * 8 in returned data, all object status bytes are 4
1249 * bytes long, and are stored in chunks of types(M)
1250 * and nth+1 instances of type M.
1255 bufsiz = (ssc->ses_nobjects * 4) + (cc->ses_ntypes * 4) + 8;
1257 sdata = SES_MALLOC(bufsiz);
1261 cdb[0] = RECEIVE_DIAGNOSTIC;
1263 cdb[2] = SesStatusPage;
1264 cdb[3] = bufsiz >> 8;
1265 cdb[4] = bufsiz & 0xff;
1268 err = ses_runcmd(ssc, cdb, 6, sdata, &amt);
1270 SES_FREE(sdata, bufsiz);
1279 tidx = cc->ses_typidx[objid].ses_tidx;
1280 oidx = cc->ses_typidx[objid].ses_oidx;
1283 if (ses_decode(sdata, amt, cc->ses_eltmap, tidx, oidx, sp)) {
1287 if (ses_encode(sdata, amt, cc->ses_eltmap, tidx, oidx, sp)) {
1290 cdb[0] = SEND_DIAGNOSTIC;
1293 cdb[3] = bufsiz >> 8;
1294 cdb[4] = bufsiz & 0xff;
1297 err = ses_runcmd(ssc, cdb, 6, sdata, &amt);
1300 SES_FREE(sdata, bufsiz);
1306 * Routines to parse returned SES data structures.
1307 * Architecture and compiler independent.
1311 ses_cfghdr(uint8_t *buffer, int buflen, SesCfgHdr *cfp)
1313 if (buflen < SES_CFGHDR_MINLEN) {
1316 gget8(buffer, 1, cfp->Nsubenc);
1317 gget32(buffer, 4, cfp->GenCode);
1322 ses_enchdr(uint8_t *buffer, int amt, uint8_t SubEncId, SesEncHdr *chp)
1325 for (s = 0; s < SubEncId; s++) {
1328 off += buffer[off+3] + 4;
1330 if (off + 3 > amt) {
1333 gget8(buffer, off+1, chp->Subencid);
1334 gget8(buffer, off+2, chp->Ntypes);
1335 gget8(buffer, off+3, chp->VEnclen);
1340 ses_encdesc(uint8_t *buffer, int amt, uint8_t SubEncId, SesEncDesc *cdp)
1342 int s, e, enclen, off = 8;
1343 for (s = 0; s < SubEncId; s++) {
1346 off += buffer[off+3] + 4;
1348 if (off + 3 > amt) {
1351 gget8(buffer, off+3, enclen);
1360 MEMCPY(cdp, &buffer[off], e - off);
1365 ses_getthdr(uint8_t *buffer, int amt, int nth, SesThdr *thp)
1369 if (amt < SES_CFGHDR_MINLEN) {
1372 for (s = 0; s < buffer[1]; s++) {
1375 off += buffer[off+3] + 4;
1377 if (off + 3 > amt) {
1380 off += buffer[off+3] + 4 + (nth * 4);
1381 if (amt < (off + 4))
1384 gget8(buffer, off++, thp->enc_type);
1385 gget8(buffer, off++, thp->enc_maxelt);
1386 gget8(buffer, off++, thp->enc_subenc);
1387 gget8(buffer, off, thp->enc_tlen);
1392 * This function needs a little explanation.
1394 * The arguments are:
1399 * These describes the raw input SES status data and length.
1403 * This is a map of the number of types for each element type
1408 * This is the element type being sought. If elt is -1,
1409 * then overall enclosure status is being sought.
1413 * This is the ordinal Mth element of type elt being sought.
1417 * This is the output area to store the status for
1418 * the Mth element of type Elt.
1422 ses_decode(char *b, int amt, uint8_t *ep, int elt, int elm, SesComStat *sp)
1427 * If it's overall enclosure status being sought, get that.
1428 * We need at least 2 bytes of status data to get that.
1433 gget8(b, 1, sp->comstatus);
1441 * Check to make sure that the Mth element is legal for type Elt.
1448 * Starting at offset 8, start skipping over the storage
1449 * for the element types we're not interested in.
1451 for (idx = 8, i = 0; i < elt; i++) {
1452 idx += ((ep[i] + 1) * 4);
1456 * Skip over Overall status for this element type.
1461 * And skip to the index for the Mth element that we're going for.
1466 * Make sure we haven't overflowed the buffer.
1472 * Retrieve the status.
1474 gget8(b, idx++, sp->comstatus);
1475 gget8(b, idx++, sp->comstat[0]);
1476 gget8(b, idx++, sp->comstat[1]);
1477 gget8(b, idx++, sp->comstat[2]);
1479 PRINTF("Get Elt 0x%x Elm 0x%x (idx %d)\n", elt, elm, idx-4);
1485 * This is the mirror function to ses_decode, but we set the 'select'
1486 * bit for the object which we're interested in. All other objects,
1487 * after a status fetch, should have that bit off. Hmm. It'd be easy
1488 * enough to ensure this, so we will.
1492 ses_encode(char *b, int amt, uint8_t *ep, int elt, int elm, SesComStat *sp)
1497 * If it's overall enclosure status being sought, get that.
1498 * We need at least 2 bytes of status data to get that.
1505 sset8(b, i, sp->comstatus & 0xf);
1507 PRINTF("set EncStat %x\n", sp->comstatus);
1513 * Check to make sure that the Mth element is legal for type Elt.
1520 * Starting at offset 8, start skipping over the storage
1521 * for the element types we're not interested in.
1523 for (idx = 8, i = 0; i < elt; i++) {
1524 idx += ((ep[i] + 1) * 4);
1528 * Skip over Overall status for this element type.
1533 * And skip to the index for the Mth element that we're going for.
1538 * Make sure we haven't overflowed the buffer.
1546 sset8(b, idx, sp->comstatus);
1547 sset8(b, idx, sp->comstat[0]);
1548 sset8(b, idx, sp->comstat[1]);
1549 sset8(b, idx, sp->comstat[2]);
1553 PRINTF("Set Elt 0x%x Elm 0x%x (idx %d) with %x %x %x %x\n",
1554 elt, elm, idx, sp->comstatus, sp->comstat[0],
1555 sp->comstat[1], sp->comstat[2]);
1559 * Now make sure all other 'Select' bits are off.
1561 for (i = 8; i < amt; i += 4) {
1566 * And make sure the INVOP bit is clear.
1574 * SAF-TE Type Device Emulation
1577 static int safte_getconfig(ses_softc_t *);
1578 static int safte_rdstat(ses_softc_t *, int);;
1579 static int set_objstat_sel(ses_softc_t *, ses_objstat *, int);
1580 static int wrbuf16(ses_softc_t *, uint8_t, uint8_t, uint8_t, uint8_t, int);
1581 static void wrslot_stat(ses_softc_t *, int);
1582 static int perf_slotop(ses_softc_t *, uint8_t, uint8_t, int);
1584 #define ALL_ENC_STAT (SES_ENCSTAT_CRITICAL | SES_ENCSTAT_UNRECOV | \
1585 SES_ENCSTAT_NONCRITICAL | SES_ENCSTAT_INFO)
1587 * SAF-TE specific defines- Mandatory ones only...
1591 * READ BUFFER ('get' commands) IDs- placed in offset 2 of cdb
1593 #define SAFTE_RD_RDCFG 0x00 /* read enclosure configuration */
1594 #define SAFTE_RD_RDESTS 0x01 /* read enclosure status */
1595 #define SAFTE_RD_RDDSTS 0x04 /* read drive slot status */
1598 * WRITE BUFFER ('set' commands) IDs- placed in offset 0 of databuf
1600 #define SAFTE_WT_DSTAT 0x10 /* write device slot status */
1601 #define SAFTE_WT_SLTOP 0x12 /* perform slot operation */
1602 #define SAFTE_WT_FANSPD 0x13 /* set fan speed */
1603 #define SAFTE_WT_ACTPWS 0x14 /* turn on/off power supply */
1604 #define SAFTE_WT_GLOBAL 0x15 /* send global command */
1607 #define SAFT_SCRATCH 64
1608 #define NPSEUDO_THERM 16
1609 #define NPSEUDO_ALARM 1
1612 * Cached Configuration
1614 uint8_t Nfans; /* Number of Fans */
1615 uint8_t Npwr; /* Number of Power Supplies */
1616 uint8_t Nslots; /* Number of Device Slots */
1617 uint8_t DoorLock; /* Door Lock Installed */
1618 uint8_t Ntherm; /* Number of Temperature Sensors */
1619 uint8_t Nspkrs; /* Number of Speakers */
1620 uint8_t Nalarm; /* Number of Alarms (at least one) */
1622 * Cached Flag Bytes for Global Status
1627 * What object index ID is where various slots start.
1631 #define SAFT_ALARM_OFFSET(cc) (cc)->slotoff - 1
1634 #define SAFT_FLG1_ALARM 0x1
1635 #define SAFT_FLG1_GLOBFAIL 0x2
1636 #define SAFT_FLG1_GLOBWARN 0x4
1637 #define SAFT_FLG1_ENCPWROFF 0x8
1638 #define SAFT_FLG1_ENCFANFAIL 0x10
1639 #define SAFT_FLG1_ENCPWRFAIL 0x20
1640 #define SAFT_FLG1_ENCDRVFAIL 0x40
1641 #define SAFT_FLG1_ENCDRVWARN 0x80
1643 #define SAFT_FLG2_LOCKDOOR 0x4
1644 #define SAFT_PRIVATE sizeof (struct scfg)
1646 static char *safte_2little = "Too Little Data Returned (%d) at line %d\n";
1647 #define SAFT_BAIL(r, x, k, l) \
1649 SES_LOG(ssc, safte_2little, x, __LINE__);\
1656 safte_softc_init(ses_softc_t *ssc, int doinit)
1662 if (ssc->ses_nobjects) {
1663 if (ssc->ses_objmap) {
1664 SES_FREE(ssc->ses_objmap,
1665 ssc->ses_nobjects * sizeof (encobj));
1666 ssc->ses_objmap = NULL;
1668 ssc->ses_nobjects = 0;
1670 if (ssc->ses_private) {
1671 SES_FREE(ssc->ses_private, SAFT_PRIVATE);
1672 ssc->ses_private = NULL;
1677 if (ssc->ses_private == NULL) {
1678 ssc->ses_private = SES_MALLOC(SAFT_PRIVATE);
1679 if (ssc->ses_private == NULL) {
1682 MEMZERO(ssc->ses_private, SAFT_PRIVATE);
1685 ssc->ses_nobjects = 0;
1686 ssc->ses_encstat = 0;
1688 if ((err = safte_getconfig(ssc)) != 0) {
1693 * The number of objects here, as well as that reported by the
1694 * READ_BUFFER/GET_CONFIG call, are the over-temperature flags (15)
1695 * that get reported during READ_BUFFER/READ_ENC_STATUS.
1697 cc = ssc->ses_private;
1698 ssc->ses_nobjects = cc->Nfans + cc->Npwr + cc->Nslots + cc->DoorLock +
1699 cc->Ntherm + cc->Nspkrs + NPSEUDO_THERM + NPSEUDO_ALARM;
1700 ssc->ses_objmap = (encobj *)
1701 SES_MALLOC(ssc->ses_nobjects * sizeof (encobj));
1702 if (ssc->ses_objmap == NULL) {
1705 MEMZERO(ssc->ses_objmap, ssc->ses_nobjects * sizeof (encobj));
1709 * Note that this is all arranged for the convenience
1710 * in later fetches of status.
1712 for (i = 0; i < cc->Nfans; i++)
1713 ssc->ses_objmap[r++].enctype = SESTYP_FAN;
1714 cc->pwroff = (uint8_t) r;
1715 for (i = 0; i < cc->Npwr; i++)
1716 ssc->ses_objmap[r++].enctype = SESTYP_POWER;
1717 for (i = 0; i < cc->DoorLock; i++)
1718 ssc->ses_objmap[r++].enctype = SESTYP_DOORLOCK;
1719 for (i = 0; i < cc->Nspkrs; i++)
1720 ssc->ses_objmap[r++].enctype = SESTYP_ALARM;
1721 for (i = 0; i < cc->Ntherm; i++)
1722 ssc->ses_objmap[r++].enctype = SESTYP_THERM;
1723 for (i = 0; i < NPSEUDO_THERM; i++)
1724 ssc->ses_objmap[r++].enctype = SESTYP_THERM;
1725 ssc->ses_objmap[r++].enctype = SESTYP_ALARM;
1726 cc->slotoff = (uint8_t) r;
1727 for (i = 0; i < cc->Nslots; i++)
1728 ssc->ses_objmap[r++].enctype = SESTYP_DEVICE;
1733 safte_init_enc(ses_softc_t *ssc)
1736 static char cdb0[6] = { SEND_DIAGNOSTIC };
1738 err = ses_runcmd(ssc, cdb0, 6, NULL, 0);
1743 err = wrbuf16(ssc, SAFTE_WT_GLOBAL, 0, 0, 0, 1);
1748 safte_get_encstat(ses_softc_t *ssc, int slpflg)
1750 return (safte_rdstat(ssc, slpflg));
1754 safte_set_encstat(ses_softc_t *ssc, uint8_t encstat, int slpflg)
1756 struct scfg *cc = ssc->ses_private;
1760 * Since SAF-TE devices aren't necessarily sticky in terms
1761 * of state, make our soft copy of enclosure status 'sticky'-
1762 * that is, things set in enclosure status stay set (as implied
1763 * by conditions set in reading object status) until cleared.
1765 ssc->ses_encstat &= ~ALL_ENC_STAT;
1766 ssc->ses_encstat |= (encstat & ALL_ENC_STAT);
1767 ssc->ses_encstat |= ENCI_SVALID;
1768 cc->flag1 &= ~(SAFT_FLG1_ALARM|SAFT_FLG1_GLOBFAIL|SAFT_FLG1_GLOBWARN);
1769 if ((encstat & (SES_ENCSTAT_CRITICAL|SES_ENCSTAT_UNRECOV)) != 0) {
1770 cc->flag1 |= SAFT_FLG1_ALARM|SAFT_FLG1_GLOBFAIL;
1771 } else if ((encstat & SES_ENCSTAT_NONCRITICAL) != 0) {
1772 cc->flag1 |= SAFT_FLG1_GLOBWARN;
1774 return (wrbuf16(ssc, SAFTE_WT_GLOBAL, cc->flag1, cc->flag2, 0, slpflg));
1778 safte_get_objstat(ses_softc_t *ssc, ses_objstat *obp, int slpflg)
1780 int i = (int)obp->obj_id;
1782 if ((ssc->ses_encstat & ENCI_SVALID) == 0 ||
1783 (ssc->ses_objmap[i].svalid) == 0) {
1784 int err = safte_rdstat(ssc, slpflg);
1788 obp->cstat[0] = ssc->ses_objmap[i].encstat[0];
1789 obp->cstat[1] = ssc->ses_objmap[i].encstat[1];
1790 obp->cstat[2] = ssc->ses_objmap[i].encstat[2];
1791 obp->cstat[3] = ssc->ses_objmap[i].encstat[3];
1797 safte_set_objstat(ses_softc_t *ssc, ses_objstat *obp, int slp)
1804 SES_DLOG(ssc, "safte_set_objstat(%d): %x %x %x %x\n",
1805 (int)obp->obj_id, obp->cstat[0], obp->cstat[1], obp->cstat[2],
1809 * If this is clear, we don't do diddly.
1811 if ((obp->cstat[0] & SESCTL_CSEL) == 0) {
1817 * Check to see if the common bits are set and do them first.
1819 if (obp->cstat[0] & ~SESCTL_CSEL) {
1820 err = set_objstat_sel(ssc, obp, slp);
1825 cc = ssc->ses_private;
1829 idx = (int)obp->obj_id;
1830 ep = &ssc->ses_objmap[idx];
1832 switch (ep->enctype) {
1837 * XXX: I should probably cache the previous state
1838 * XXX: of SESCTL_DEVOFF so that when it goes from
1839 * XXX: true to false I can then set PREPARE FOR OPERATION
1840 * XXX: flag in PERFORM SLOT OPERATION write buffer command.
1842 if (obp->cstat[2] & (SESCTL_RQSINS|SESCTL_RQSRMV)) {
1845 if (obp->cstat[2] & SESCTL_RQSID) {
1848 err = perf_slotop(ssc, (uint8_t) idx - (uint8_t) cc->slotoff,
1852 if (obp->cstat[3] & SESCTL_RQSFLT) {
1857 if (ep->priv & 0xc6) {
1860 ep->priv |= 0x1; /* no errors */
1862 wrslot_stat(ssc, slp);
1866 if (obp->cstat[3] & SESCTL_RQSTFAIL) {
1867 cc->flag1 |= SAFT_FLG1_ENCPWRFAIL;
1869 cc->flag1 &= ~SAFT_FLG1_ENCPWRFAIL;
1871 err = wrbuf16(ssc, SAFTE_WT_GLOBAL, cc->flag1,
1875 if (obp->cstat[3] & SESCTL_RQSTON) {
1876 wrbuf16(ssc, SAFTE_WT_ACTPWS,
1877 idx - cc->pwroff, 0, 0, slp);
1879 wrbuf16(ssc, SAFTE_WT_ACTPWS,
1880 idx - cc->pwroff, 0, 1, slp);
1884 if (obp->cstat[3] & SESCTL_RQSTFAIL) {
1885 cc->flag1 |= SAFT_FLG1_ENCFANFAIL;
1887 cc->flag1 &= ~SAFT_FLG1_ENCFANFAIL;
1889 err = wrbuf16(ssc, SAFTE_WT_GLOBAL, cc->flag1,
1893 if (obp->cstat[3] & SESCTL_RQSTON) {
1895 if ((obp->cstat[3] & 0x7) == 7) {
1897 } else if ((obp->cstat[3] & 0x7) == 6) {
1899 } else if ((obp->cstat[3] & 0x7) == 4) {
1904 wrbuf16(ssc, SAFTE_WT_FANSPD, idx, fsp, 0, slp);
1906 wrbuf16(ssc, SAFTE_WT_FANSPD, idx, 0, 0, slp);
1909 case SESTYP_DOORLOCK:
1910 if (obp->cstat[3] & 0x1) {
1911 cc->flag2 &= ~SAFT_FLG2_LOCKDOOR;
1913 cc->flag2 |= SAFT_FLG2_LOCKDOOR;
1915 wrbuf16(ssc, SAFTE_WT_GLOBAL, cc->flag1, cc->flag2, 0, slp);
1919 * On all nonzero but the 'muted' bit, we turn on the alarm,
1921 obp->cstat[3] &= ~0xa;
1922 if (obp->cstat[3] & 0x40) {
1923 cc->flag2 &= ~SAFT_FLG1_ALARM;
1924 } else if (obp->cstat[3] != 0) {
1925 cc->flag2 |= SAFT_FLG1_ALARM;
1927 cc->flag2 &= ~SAFT_FLG1_ALARM;
1929 ep->priv = obp->cstat[3];
1930 wrbuf16(ssc, SAFTE_WT_GLOBAL, cc->flag1, cc->flag2, 0, slp);
1940 safte_getconfig(ses_softc_t *ssc)
1945 static char cdb[10] =
1946 { READ_BUFFER, 1, SAFTE_RD_RDCFG, 0, 0, 0, 0, 0, SAFT_SCRATCH, 0 };
1948 cfg = ssc->ses_private;
1952 sdata = SES_MALLOC(SAFT_SCRATCH);
1957 err = ses_runcmd(ssc, cdb, 10, sdata, &amt);
1959 SES_FREE(sdata, SAFT_SCRATCH);
1962 amt = SAFT_SCRATCH - amt;
1964 SES_LOG(ssc, "too little data (%d) for configuration\n", amt);
1965 SES_FREE(sdata, SAFT_SCRATCH);
1968 SES_VLOG(ssc, "Nfans %d Npwr %d Nslots %d Lck %d Ntherm %d Nspkrs %d\n",
1969 sdata[0], sdata[1], sdata[2], sdata[3], sdata[4], sdata[5]);
1970 cfg->Nfans = sdata[0];
1971 cfg->Npwr = sdata[1];
1972 cfg->Nslots = sdata[2];
1973 cfg->DoorLock = sdata[3];
1974 cfg->Ntherm = sdata[4];
1975 cfg->Nspkrs = sdata[5];
1976 cfg->Nalarm = NPSEUDO_ALARM;
1977 SES_FREE(sdata, SAFT_SCRATCH);
1982 safte_rdstat(ses_softc_t *ssc, int slpflg)
1984 int err, oid, r, i, hiwater, nitems, amt;
1987 uint8_t status, oencstat;
1988 char *sdata, cdb[10];
1989 struct scfg *cc = ssc->ses_private;
1993 * The number of objects overstates things a bit,
1994 * both for the bogus 'thermometer' entries and
1995 * the drive status (which isn't read at the same
1996 * time as the enclosure status), but that's okay.
1998 buflen = 4 * cc->Nslots;
1999 if (ssc->ses_nobjects > buflen)
2000 buflen = ssc->ses_nobjects;
2001 sdata = SES_MALLOC(buflen);
2005 cdb[0] = READ_BUFFER;
2007 cdb[2] = SAFTE_RD_RDESTS;
2012 cdb[7] = (buflen >> 8) & 0xff;
2013 cdb[8] = buflen & 0xff;
2016 err = ses_runcmd(ssc, cdb, 10, sdata, &amt);
2018 SES_FREE(sdata, buflen);
2021 hiwater = buflen - amt;
2025 * invalidate all status bits.
2027 for (i = 0; i < ssc->ses_nobjects; i++)
2028 ssc->ses_objmap[i].svalid = 0;
2029 oencstat = ssc->ses_encstat & ALL_ENC_STAT;
2030 ssc->ses_encstat = 0;
2034 * Now parse returned buffer.
2035 * If we didn't get enough data back,
2036 * that's considered a fatal error.
2040 for (nitems = i = 0; i < cc->Nfans; i++) {
2041 SAFT_BAIL(r, hiwater, sdata, buflen);
2043 * 0 = Fan Operational
2044 * 1 = Fan is malfunctioning
2045 * 2 = Fan is not present
2046 * 0x80 = Unknown or Not Reportable Status
2048 ssc->ses_objmap[oid].encstat[1] = 0; /* resvd */
2049 ssc->ses_objmap[oid].encstat[2] = 0; /* resvd */
2050 switch ((int)(uint8_t)sdata[r]) {
2053 ssc->ses_objmap[oid].encstat[0] = SES_OBJSTAT_OK;
2055 * We could get fancier and cache
2056 * fan speeds that we have set, but
2057 * that isn't done now.
2059 ssc->ses_objmap[oid].encstat[3] = 7;
2063 ssc->ses_objmap[oid].encstat[0] = SES_OBJSTAT_CRIT;
2065 * FAIL and FAN STOPPED synthesized
2067 ssc->ses_objmap[oid].encstat[3] = 0x40;
2069 * Enclosure marked with CRITICAL error
2070 * if only one fan or no thermometers,
2071 * else the NONCRITICAL error is set.
2073 if (cc->Nfans == 1 || cc->Ntherm == 0)
2074 ssc->ses_encstat |= SES_ENCSTAT_CRITICAL;
2076 ssc->ses_encstat |= SES_ENCSTAT_NONCRITICAL;
2079 ssc->ses_objmap[oid].encstat[0] =
2080 SES_OBJSTAT_NOTINSTALLED;
2081 ssc->ses_objmap[oid].encstat[3] = 0;
2083 * Enclosure marked with CRITICAL error
2084 * if only one fan or no thermometers,
2085 * else the NONCRITICAL error is set.
2088 ssc->ses_encstat |= SES_ENCSTAT_CRITICAL;
2090 ssc->ses_encstat |= SES_ENCSTAT_NONCRITICAL;
2093 ssc->ses_objmap[oid].encstat[0] = SES_OBJSTAT_UNKNOWN;
2094 ssc->ses_objmap[oid].encstat[3] = 0;
2095 ssc->ses_encstat |= SES_ENCSTAT_INFO;
2098 ssc->ses_objmap[oid].encstat[0] =
2099 SES_OBJSTAT_UNSUPPORTED;
2100 SES_LOG(ssc, "Unknown fan%d status 0x%x\n", i,
2104 ssc->ses_objmap[oid++].svalid = 1;
2109 * No matter how you cut it, no cooling elements when there
2110 * should be some there is critical.
2112 if (cc->Nfans && nitems == 0) {
2113 ssc->ses_encstat |= SES_ENCSTAT_CRITICAL;
2117 for (i = 0; i < cc->Npwr; i++) {
2118 SAFT_BAIL(r, hiwater, sdata, buflen);
2119 ssc->ses_objmap[oid].encstat[0] = SES_OBJSTAT_UNKNOWN;
2120 ssc->ses_objmap[oid].encstat[1] = 0; /* resvd */
2121 ssc->ses_objmap[oid].encstat[2] = 0; /* resvd */
2122 ssc->ses_objmap[oid].encstat[3] = 0x20; /* requested on */
2123 switch ((uint8_t)sdata[r]) {
2124 case 0x00: /* pws operational and on */
2125 ssc->ses_objmap[oid].encstat[0] = SES_OBJSTAT_OK;
2127 case 0x01: /* pws operational and off */
2128 ssc->ses_objmap[oid].encstat[0] = SES_OBJSTAT_OK;
2129 ssc->ses_objmap[oid].encstat[3] = 0x10;
2130 ssc->ses_encstat |= SES_ENCSTAT_INFO;
2132 case 0x10: /* pws is malfunctioning and commanded on */
2133 ssc->ses_objmap[oid].encstat[0] = SES_OBJSTAT_CRIT;
2134 ssc->ses_objmap[oid].encstat[3] = 0x61;
2135 ssc->ses_encstat |= SES_ENCSTAT_NONCRITICAL;
2138 case 0x11: /* pws is malfunctioning and commanded off */
2139 ssc->ses_objmap[oid].encstat[0] = SES_OBJSTAT_NONCRIT;
2140 ssc->ses_objmap[oid].encstat[3] = 0x51;
2141 ssc->ses_encstat |= SES_ENCSTAT_NONCRITICAL;
2143 case 0x20: /* pws is not present */
2144 ssc->ses_objmap[oid].encstat[0] =
2145 SES_OBJSTAT_NOTINSTALLED;
2146 ssc->ses_objmap[oid].encstat[3] = 0;
2147 ssc->ses_encstat |= SES_ENCSTAT_INFO;
2149 case 0x21: /* pws is present */
2151 * This is for enclosures that cannot tell whether the
2152 * device is on or malfunctioning, but know that it is
2153 * present. Just fall through.
2156 case 0x80: /* Unknown or Not Reportable Status */
2157 ssc->ses_objmap[oid].encstat[0] = SES_OBJSTAT_UNKNOWN;
2158 ssc->ses_objmap[oid].encstat[3] = 0;
2159 ssc->ses_encstat |= SES_ENCSTAT_INFO;
2162 SES_LOG(ssc, "unknown power supply %d status (0x%x)\n",
2163 i, sdata[r] & 0xff);
2166 ssc->ses_objmap[oid++].svalid = 1;
2171 * Skip over Slot SCSI IDs
2176 * We always have doorlock status, no matter what,
2177 * but we only save the status if we have one.
2179 SAFT_BAIL(r, hiwater, sdata, buflen);
2183 * 1 = Door Unlocked, or no Lock Installed
2184 * 0x80 = Unknown or Not Reportable Status
2186 ssc->ses_objmap[oid].encstat[1] = 0;
2187 ssc->ses_objmap[oid].encstat[2] = 0;
2188 switch ((uint8_t)sdata[r]) {
2190 ssc->ses_objmap[oid].encstat[0] = SES_OBJSTAT_OK;
2191 ssc->ses_objmap[oid].encstat[3] = 0;
2194 ssc->ses_objmap[oid].encstat[0] = SES_OBJSTAT_OK;
2195 ssc->ses_objmap[oid].encstat[3] = 1;
2198 ssc->ses_objmap[oid].encstat[0] = SES_OBJSTAT_UNKNOWN;
2199 ssc->ses_objmap[oid].encstat[3] = 0;
2200 ssc->ses_encstat |= SES_ENCSTAT_INFO;
2203 ssc->ses_objmap[oid].encstat[0] =
2204 SES_OBJSTAT_UNSUPPORTED;
2205 SES_LOG(ssc, "unknown lock status 0x%x\n",
2209 ssc->ses_objmap[oid++].svalid = 1;
2214 * We always have speaker status, no matter what,
2215 * but we only save the status if we have one.
2217 SAFT_BAIL(r, hiwater, sdata, buflen);
2219 ssc->ses_objmap[oid].encstat[1] = 0;
2220 ssc->ses_objmap[oid].encstat[2] = 0;
2221 if (sdata[r] == 1) {
2223 * We need to cache tone urgency indicators.
2226 ssc->ses_objmap[oid].encstat[0] = SES_OBJSTAT_NONCRIT;
2227 ssc->ses_objmap[oid].encstat[3] = 0x8;
2228 ssc->ses_encstat |= SES_ENCSTAT_NONCRITICAL;
2229 } else if (sdata[r] == 0) {
2230 ssc->ses_objmap[oid].encstat[0] = SES_OBJSTAT_OK;
2231 ssc->ses_objmap[oid].encstat[3] = 0;
2233 ssc->ses_objmap[oid].encstat[0] =
2234 SES_OBJSTAT_UNSUPPORTED;
2235 ssc->ses_objmap[oid].encstat[3] = 0;
2236 SES_LOG(ssc, "unknown spkr status 0x%x\n",
2239 ssc->ses_objmap[oid++].svalid = 1;
2243 for (i = 0; i < cc->Ntherm; i++) {
2244 SAFT_BAIL(r, hiwater, sdata, buflen);
2246 * Status is a range from -10 to 245 deg Celsius,
2247 * which we need to normalize to -20 to -245 according
2248 * to the latest SCSI spec, which makes little
2249 * sense since this would overflow an 8bit value.
2250 * Well, still, the base normalization is -20,
2251 * not -10, so we have to adjust.
2253 * So what's over and under temperature?
2254 * Hmm- we'll state that 'normal' operating
2255 * is 10 to 40 deg Celsius.
2259 * Actually.... All of the units that people out in the world
2260 * seem to have do not come even close to setting a value that
2261 * complies with this spec.
2263 * The closest explanation I could find was in an
2264 * LSI-Logic manual, which seemed to indicate that
2265 * this value would be set by whatever the I2C code
2266 * would interpolate from the output of an LM75
2267 * temperature sensor.
2269 * This means that it is impossible to use the actual
2270 * numeric value to predict anything. But we don't want
2271 * to lose the value. So, we'll propagate the *uncorrected*
2272 * value and set SES_OBJSTAT_NOTAVAIL. We'll depend on the
2273 * temperature flags for warnings.
2275 ssc->ses_objmap[oid].encstat[0] = SES_OBJSTAT_NOTAVAIL;
2276 ssc->ses_objmap[oid].encstat[1] = 0;
2277 ssc->ses_objmap[oid].encstat[2] = sdata[r];
2278 ssc->ses_objmap[oid].encstat[3] = 0;;
2279 ssc->ses_objmap[oid++].svalid = 1;
2284 * Now, for "pseudo" thermometers, we have two bytes
2285 * of information in enclosure status- 16 bits. Actually,
2286 * the MSB is a single TEMP ALERT flag indicating whether
2287 * any other bits are set, but, thanks to fuzzy thinking,
2288 * in the SAF-TE spec, this can also be set even if no
2289 * other bits are set, thus making this really another
2290 * binary temperature sensor.
2293 SAFT_BAIL(r, hiwater, sdata, buflen);
2294 tempflags = sdata[r++];
2295 SAFT_BAIL(r, hiwater, sdata, buflen);
2296 tempflags |= (tempflags << 8) | sdata[r++];
2298 for (i = 0; i < NPSEUDO_THERM; i++) {
2299 ssc->ses_objmap[oid].encstat[1] = 0;
2300 if (tempflags & (1 << (NPSEUDO_THERM - i - 1))) {
2301 ssc->ses_objmap[oid].encstat[0] = SES_OBJSTAT_CRIT;
2302 ssc->ses_objmap[4].encstat[2] = 0xff;
2304 * Set 'over temperature' failure.
2306 ssc->ses_objmap[oid].encstat[3] = 8;
2307 ssc->ses_encstat |= SES_ENCSTAT_CRITICAL;
2310 * We used to say 'not available' and synthesize a
2311 * nominal 30 deg (C)- that was wrong. Actually,
2312 * Just say 'OK', and use the reserved value of
2315 ssc->ses_objmap[oid].encstat[0] = SES_OBJSTAT_OK;
2316 ssc->ses_objmap[oid].encstat[2] = 0;
2317 ssc->ses_objmap[oid].encstat[3] = 0;
2319 ssc->ses_objmap[oid++].svalid = 1;
2325 ssc->ses_objmap[oid].encstat[0] = SES_OBJSTAT_OK;
2326 ssc->ses_objmap[oid].encstat[3] = ssc->ses_objmap[oid].priv;
2327 ssc->ses_objmap[oid++].svalid = 1;
2330 * Now get drive slot status
2332 cdb[2] = SAFTE_RD_RDDSTS;
2334 err = ses_runcmd(ssc, cdb, 10, sdata, &amt);
2336 SES_FREE(sdata, buflen);
2339 hiwater = buflen - amt;
2340 for (r = i = 0; i < cc->Nslots; i++, r += 4) {
2341 SAFT_BAIL(r+3, hiwater, sdata, buflen);
2342 ssc->ses_objmap[oid].encstat[0] = SES_OBJSTAT_UNSUPPORTED;
2343 ssc->ses_objmap[oid].encstat[1] = (uint8_t) i;
2344 ssc->ses_objmap[oid].encstat[2] = 0;
2345 ssc->ses_objmap[oid].encstat[3] = 0;
2346 status = sdata[r+3];
2347 if ((status & 0x1) == 0) { /* no device */
2348 ssc->ses_objmap[oid].encstat[0] =
2349 SES_OBJSTAT_NOTINSTALLED;
2351 ssc->ses_objmap[oid].encstat[0] = SES_OBJSTAT_OK;
2354 ssc->ses_objmap[oid].encstat[2] = 0x8;
2356 if ((status & 0x4) == 0) {
2357 ssc->ses_objmap[oid].encstat[3] = 0x10;
2359 ssc->ses_objmap[oid++].svalid = 1;
2361 /* see comment below about sticky enclosure status */
2362 ssc->ses_encstat |= ENCI_SVALID | oencstat;
2363 SES_FREE(sdata, buflen);
2368 set_objstat_sel(ses_softc_t *ssc, ses_objstat *obp, int slp)
2372 struct scfg *cc = ssc->ses_private;
2377 idx = (int)obp->obj_id;
2378 ep = &ssc->ses_objmap[idx];
2380 switch (ep->enctype) {
2382 if (obp->cstat[0] & SESCTL_PRDFAIL) {
2385 /* SESCTL_RSTSWAP has no correspondence in SAF-TE */
2386 if (obp->cstat[0] & SESCTL_DISABLE) {
2389 * Hmm. Try to set the 'No Drive' flag.
2390 * Maybe that will count as a 'disable'.
2393 if (ep->priv & 0xc6) {
2396 ep->priv |= 0x1; /* no errors */
2398 wrslot_stat(ssc, slp);
2402 * Okay- the only one that makes sense here is to
2403 * do the 'disable' for a power supply.
2405 if (obp->cstat[0] & SESCTL_DISABLE) {
2406 wrbuf16(ssc, SAFTE_WT_ACTPWS,
2407 idx - cc->pwroff, 0, 0, slp);
2412 * Okay- the only one that makes sense here is to
2413 * set fan speed to zero on disable.
2415 if (obp->cstat[0] & SESCTL_DISABLE) {
2416 /* remember- fans are the first items, so idx works */
2417 wrbuf16(ssc, SAFTE_WT_FANSPD, idx, 0, 0, slp);
2420 case SESTYP_DOORLOCK:
2422 * Well, we can 'disable' the lock.
2424 if (obp->cstat[0] & SESCTL_DISABLE) {
2425 cc->flag2 &= ~SAFT_FLG2_LOCKDOOR;
2426 wrbuf16(ssc, SAFTE_WT_GLOBAL, cc->flag1,
2432 * Well, we can 'disable' the alarm.
2434 if (obp->cstat[0] & SESCTL_DISABLE) {
2435 cc->flag2 &= ~SAFT_FLG1_ALARM;
2436 ep->priv |= 0x40; /* Muted */
2437 wrbuf16(ssc, SAFTE_WT_GLOBAL, cc->flag1,
2449 * This function handles all of the 16 byte WRITE BUFFER commands.
2452 wrbuf16(ses_softc_t *ssc, uint8_t op, uint8_t b1, uint8_t b2,
2453 uint8_t b3, int slp)
2457 struct scfg *cc = ssc->ses_private;
2458 static char cdb[10] = { WRITE_BUFFER, 1, 0, 0, 0, 0, 0, 0, 16, 0 };
2463 sdata = SES_MALLOC(16);
2467 SES_DLOG(ssc, "saf_wrbuf16 %x %x %x %x\n", op, b1, b2, b3);
2473 MEMZERO(&sdata[4], 12);
2475 err = ses_runcmd(ssc, cdb, 10, sdata, &amt);
2476 SES_FREE(sdata, 16);
2481 * This function updates the status byte for the device slot described.
2483 * Since this is an optional SAF-TE command, there's no point in
2484 * returning an error.
2487 wrslot_stat(ses_softc_t *ssc, int slp)
2491 char cdb[10], *sdata;
2492 struct scfg *cc = ssc->ses_private;
2497 SES_DLOG(ssc, "saf_wrslot\n");
2498 cdb[0] = WRITE_BUFFER;
2506 cdb[8] = cc->Nslots * 3 + 1;
2509 sdata = SES_MALLOC(cc->Nslots * 3 + 1);
2512 MEMZERO(sdata, cc->Nslots * 3 + 1);
2514 sdata[0] = SAFTE_WT_DSTAT;
2515 for (i = 0; i < cc->Nslots; i++) {
2516 ep = &ssc->ses_objmap[cc->slotoff + i];
2517 SES_DLOG(ssc, "saf_wrslot %d <- %x\n", i, ep->priv & 0xff);
2518 sdata[1 + (3 * i)] = ep->priv & 0xff;
2520 amt = -(cc->Nslots * 3 + 1);
2521 ses_runcmd(ssc, cdb, 10, sdata, &amt);
2522 SES_FREE(sdata, cc->Nslots * 3 + 1);
2526 * This function issues the "PERFORM SLOT OPERATION" command.
2529 perf_slotop(ses_softc_t *ssc, uint8_t slot, uint8_t opflag, int slp)
2533 struct scfg *cc = ssc->ses_private;
2534 static char cdb[10] =
2535 { WRITE_BUFFER, 1, 0, 0, 0, 0, 0, 0, SAFT_SCRATCH, 0 };
2540 sdata = SES_MALLOC(SAFT_SCRATCH);
2543 MEMZERO(sdata, SAFT_SCRATCH);
2545 sdata[0] = SAFTE_WT_SLTOP;
2548 SES_DLOG(ssc, "saf_slotop slot %d op %x\n", slot, opflag);
2549 amt = -SAFT_SCRATCH;
2550 err = ses_runcmd(ssc, cdb, 10, sdata, &amt);
2551 SES_FREE(sdata, SAFT_SCRATCH);