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.29 2008/05/18 20:30:20 pavalos 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>
38 #include <sys/errno.h>
39 #include <sys/devicestat.h>
40 #include <sys/thread2.h>
41 #include <machine/stdarg.h>
44 #include "../cam_ccb.h"
45 #include "../cam_extend.h"
46 #include "../cam_periph.h"
47 #include "../cam_xpt_periph.h"
48 #include "../cam_debug.h"
49 #include "../cam_sim.h"
52 #include "scsi_message.h"
53 #include <sys/ioccom.h>
58 MALLOC_DEFINE(M_SCSISES
, "SCSI SES", "SCSI SES buffers");
61 * Platform Independent Driver Internal Definitions for SES devices.
73 typedef struct ses_softc ses_softc_t
;
75 int (*softc_init
)(ses_softc_t
*, int);
76 int (*init_enc
)(ses_softc_t
*);
77 int (*get_encstat
)(ses_softc_t
*, int);
78 int (*set_encstat
)(ses_softc_t
*, ses_encstat
, int);
79 int (*get_objstat
)(ses_softc_t
*, ses_objstat
*, int);
80 int (*set_objstat
)(ses_softc_t
*, ses_objstat
*, int);
83 #define ENCI_SVALID 0x80
87 enctype
: 8, /* enclosure type */
88 subenclosure
: 8, /* subenclosure id */
89 svalid
: 1, /* enclosure information valid */
90 priv
: 15; /* private data, per object */
91 uint8_t encstat
[4]; /* state && stats */
94 #define SEN_ID "UNISYS SUN_SEN"
98 static enctyp
ses_type(void *, int);
101 /* Forward reference to Enclosure Functions */
102 static int ses_softc_init(ses_softc_t
*, int);
103 static int ses_init_enc(ses_softc_t
*);
104 static int ses_get_encstat(ses_softc_t
*, int);
105 static int ses_set_encstat(ses_softc_t
*, uint8_t, int);
106 static int ses_get_objstat(ses_softc_t
*, ses_objstat
*, int);
107 static int ses_set_objstat(ses_softc_t
*, ses_objstat
*, int);
109 static int safte_softc_init(ses_softc_t
*, int);
110 static int safte_init_enc(ses_softc_t
*);
111 static int safte_get_encstat(ses_softc_t
*, int);
112 static int safte_set_encstat(ses_softc_t
*, uint8_t, int);
113 static int safte_get_objstat(ses_softc_t
*, ses_objstat
*, int);
114 static int safte_set_objstat(ses_softc_t
*, ses_objstat
*, int);
117 * Platform implementation defines/functions for SES internal kernel stuff
120 #define STRNCMP strncmp
121 #define PRINTF kprintf
122 #define SES_LOG ses_log
124 #define SES_DLOG ses_log
126 #define SES_DLOG if (0) ses_log
128 #define SES_VLOG if (bootverbose) ses_log
129 #define SES_MALLOC(amt) kmalloc(amt, M_SCSISES, M_INTWAIT)
130 #define SES_FREE(ptr, amt) kfree(ptr, M_SCSISES)
131 #define MEMZERO bzero
132 #define MEMCPY(dest, src, amt) bcopy(src, dest, amt)
134 static int ses_runcmd(struct ses_softc
*, char *, int, char *, int *);
135 static void ses_log(struct ses_softc
*, const char *, ...);
138 * Gerenal FreeBSD kernel stuff.
142 #define ccb_state ppriv_field0
143 #define ccb_bio ppriv_ptr1
146 enctyp ses_type
; /* type of enclosure */
147 encvec ses_vec
; /* vector to handlers */
148 void * ses_private
; /* per-type private data */
149 encobj
* ses_objmap
; /* objects */
150 u_int32_t ses_nobjects
; /* number of objects */
151 ses_encstat ses_encstat
; /* overall status */
153 union ccb ses_saved_ccb
;
154 struct cam_periph
*periph
;
156 #define SES_FLAG_INVALID 0x01
157 #define SES_FLAG_OPEN 0x02
158 #define SES_FLAG_INITIALIZED 0x04
160 #define SESUNIT(x) (minor((x)))
161 #define SES_CDEV_MAJOR 110
163 static d_open_t sesopen
;
164 static d_close_t sesclose
;
165 static d_ioctl_t sesioctl
;
166 static periph_init_t sesinit
;
167 static periph_ctor_t sesregister
;
168 static periph_oninv_t sesoninvalidate
;
169 static periph_dtor_t sescleanup
;
170 static periph_start_t sesstart
;
172 static void sesasync(void *, u_int32_t
, struct cam_path
*, void *);
173 static void sesdone(struct cam_periph
*, union ccb
*);
174 static int seserror(union ccb
*, u_int32_t
, u_int32_t
);
176 static struct periph_driver sesdriver
= {
178 TAILQ_HEAD_INITIALIZER(sesdriver
.units
), /* generation */ 0
181 PERIPHDRIVER_DECLARE(ses
, sesdriver
);
183 static struct dev_ops ses_ops
= {
184 { "ses", SES_CDEV_MAJOR
, 0 },
189 static struct extend_array
*sesperiphs
;
197 * Create our extend array for storing the devices we attach to.
199 sesperiphs
= cam_extend_new();
200 if (sesperiphs
== NULL
) {
201 kprintf("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_register_async(AC_FOUND_DEVICE
, sesasync
, NULL
, NULL
);
211 if (status
!= CAM_REQ_CMP
) {
212 kprintf("ses: Failed to attach master async callback "
213 "due to status 0x%x!\n", status
);
218 sesoninvalidate(struct cam_periph
*periph
)
220 struct ses_softc
*softc
;
222 softc
= (struct ses_softc
*)periph
->softc
;
225 * Unregister any async callbacks.
227 xpt_register_async(0, sesasync
, periph
, periph
->path
);
229 softc
->ses_flags
|= SES_FLAG_INVALID
;
231 xpt_print(periph
->path
, "lost device\n");
235 sescleanup(struct cam_periph
*periph
)
237 struct ses_softc
*softc
;
239 softc
= (struct ses_softc
*)periph
->softc
;
241 cam_extend_release(sesperiphs
, periph
->unit_number
);
242 xpt_print(periph
->path
, "removing device entry\n");
243 dev_ops_remove(&ses_ops
, -1, periph
->unit_number
);
244 kfree(softc
, M_SCSISES
);
248 sesasync(void *callback_arg
, u_int32_t code
, struct cam_path
*path
, void *arg
)
250 struct cam_periph
*periph
;
252 periph
= (struct cam_periph
*)callback_arg
;
255 case AC_FOUND_DEVICE
:
258 struct ccb_getdev
*cgd
;
261 cgd
= (struct ccb_getdev
*)arg
;
266 inq_len
= cgd
->inq_data
.additional_length
+ 4;
269 * PROBLEM: WE NEED TO LOOK AT BYTES 48-53 TO SEE IF THIS IS
270 * PROBLEM: IS A SAF-TE DEVICE.
272 switch (ses_type(&cgd
->inq_data
, inq_len
)) {
275 case SES_SES_PASSTHROUGH
:
283 status
= cam_periph_alloc(sesregister
, sesoninvalidate
,
284 sescleanup
, sesstart
, "ses", CAM_PERIPH_BIO
,
285 cgd
->ccb_h
.path
, sesasync
, AC_FOUND_DEVICE
, cgd
);
287 if (status
!= CAM_REQ_CMP
&& status
!= CAM_REQ_INPROG
) {
288 kprintf("sesasync: Unable to probe new device due to "
289 "status 0x%x\n", status
);
294 cam_periph_async(periph
, code
, path
, arg
);
300 sesregister(struct cam_periph
*periph
, void *arg
)
302 struct ses_softc
*softc
;
303 struct ccb_getdev
*cgd
;
306 cgd
= (struct ccb_getdev
*)arg
;
307 if (periph
== NULL
) {
308 kprintf("sesregister: periph was NULL!!\n");
309 return (CAM_REQ_CMP_ERR
);
313 kprintf("sesregister: no getdev CCB, can't register device\n");
314 return (CAM_REQ_CMP_ERR
);
317 softc
= kmalloc(sizeof (struct ses_softc
), M_SCSISES
, M_INTWAIT
| M_ZERO
);
318 periph
->softc
= softc
;
319 softc
->periph
= periph
;
321 softc
->ses_type
= ses_type(&cgd
->inq_data
, sizeof (cgd
->inq_data
));
323 switch (softc
->ses_type
) {
326 case SES_SES_PASSTHROUGH
:
327 softc
->ses_vec
.softc_init
= ses_softc_init
;
328 softc
->ses_vec
.init_enc
= ses_init_enc
;
329 softc
->ses_vec
.get_encstat
= ses_get_encstat
;
330 softc
->ses_vec
.set_encstat
= ses_set_encstat
;
331 softc
->ses_vec
.get_objstat
= ses_get_objstat
;
332 softc
->ses_vec
.set_objstat
= ses_set_objstat
;
335 softc
->ses_vec
.softc_init
= safte_softc_init
;
336 softc
->ses_vec
.init_enc
= safte_init_enc
;
337 softc
->ses_vec
.get_encstat
= safte_get_encstat
;
338 softc
->ses_vec
.set_encstat
= safte_set_encstat
;
339 softc
->ses_vec
.get_objstat
= safte_get_objstat
;
340 softc
->ses_vec
.set_objstat
= safte_set_objstat
;
346 kfree(softc
, M_SCSISES
);
347 return (CAM_REQ_CMP_ERR
);
350 cam_extend_set(sesperiphs
, periph
->unit_number
, periph
);
352 cam_periph_unlock(periph
);
353 dev_ops_add(&ses_ops
, -1, periph
->unit_number
);
354 make_dev(&ses_ops
, periph
->unit_number
,
355 UID_ROOT
, GID_OPERATOR
, 0600, "%s%d",
356 periph
->periph_name
, periph
->unit_number
);
357 cam_periph_lock(periph
);
360 * Add an async callback so that we get
361 * notified if this device goes away.
363 xpt_register_async(AC_LOST_DEVICE
, sesasync
, periph
, periph
->path
);
365 switch (softc
->ses_type
) {
368 tname
= "No SES device";
371 tname
= "SCSI-2 SES Device";
374 tname
= "SCSI-3 SES Device";
376 case SES_SES_PASSTHROUGH
:
377 tname
= "SES Passthrough Device";
380 tname
= "UNISYS SEN Device (NOT HANDLED YET)";
383 tname
= "SAF-TE Compliant Device";
386 xpt_announce_periph(periph
, tname
);
387 return (CAM_REQ_CMP
);
391 sesopen(struct dev_open_args
*ap
)
393 cdev_t dev
= ap
->a_head
.a_dev
;
394 struct cam_periph
*periph
;
395 struct ses_softc
*softc
;
398 periph
= cam_extend_get(sesperiphs
, SESUNIT(dev
));
399 if (periph
== NULL
) {
403 if (cam_periph_acquire(periph
) != CAM_REQ_CMP
) {
404 cam_periph_unlock(periph
);
408 cam_periph_lock(periph
);
410 softc
= (struct ses_softc
*)periph
->softc
;
412 if (softc
->ses_flags
& SES_FLAG_INVALID
) {
416 if (softc
->ses_flags
& SES_FLAG_OPEN
) {
420 if (softc
->ses_vec
.softc_init
== NULL
) {
425 softc
->ses_flags
|= SES_FLAG_OPEN
;
426 if ((softc
->ses_flags
& SES_FLAG_INITIALIZED
) == 0) {
427 error
= (*softc
->ses_vec
.softc_init
)(softc
, 1);
429 softc
->ses_flags
&= ~SES_FLAG_OPEN
;
431 softc
->ses_flags
|= SES_FLAG_INITIALIZED
;
435 cam_periph_unlock(periph
);
437 cam_periph_release(periph
);
443 sesclose(struct dev_close_args
*ap
)
445 cdev_t dev
= ap
->a_head
.a_dev
;
446 struct cam_periph
*periph
;
447 struct ses_softc
*softc
;
453 periph
= cam_extend_get(sesperiphs
, unit
);
457 cam_periph_lock(periph
);
459 softc
= (struct ses_softc
*)periph
->softc
;
460 softc
->ses_flags
&= ~SES_FLAG_OPEN
;
462 cam_periph_unlock(periph
);
463 cam_periph_release(periph
);
469 sesstart(struct cam_periph
*p
, union ccb
*sccb
)
471 if (p
->immediate_priority
<= p
->pinfo
.priority
) {
472 SLIST_INSERT_HEAD(&p
->ccb_list
, &sccb
->ccb_h
, periph_links
.sle
);
473 p
->immediate_priority
= CAM_PRIORITY_NONE
;
474 wakeup(&p
->ccb_list
);
479 sesdone(struct cam_periph
*periph
, union ccb
*dccb
)
481 wakeup(&dccb
->ccb_h
.cbfcnp
);
485 seserror(union ccb
*ccb
, u_int32_t cflags
, u_int32_t sflags
)
487 struct ses_softc
*softc
;
488 struct cam_periph
*periph
;
490 periph
= xpt_path_periph(ccb
->ccb_h
.path
);
491 softc
= (struct ses_softc
*)periph
->softc
;
493 return (cam_periph_error(ccb
, cflags
, sflags
, &softc
->ses_saved_ccb
));
497 sesioctl(struct dev_ioctl_args
*ap
)
499 cdev_t dev
= ap
->a_head
.a_dev
;
500 struct cam_periph
*periph
;
503 ses_object obj
, *uobj
;
504 struct ses_softc
*ssc
;
510 addr
= *((caddr_t
*)ap
->a_data
);
514 periph
= cam_extend_get(sesperiphs
, SESUNIT(dev
));
518 CAM_DEBUG(periph
->path
, CAM_DEBUG_TRACE
, ("entering sesioctl\n"));
520 cam_periph_lock(periph
);
521 ssc
= (struct ses_softc
*)periph
->softc
;
524 * Now check to see whether we're initialized or not.
526 if ((ssc
->ses_flags
& SES_FLAG_INITIALIZED
) == 0) {
527 cam_periph_unlock(periph
);
530 cam_periph_unlock(periph
);
534 CAM_DEBUG(periph
->path
, CAM_DEBUG_TRACE
,
535 ("trying to do ioctl %#lx\n", ap
->a_cmd
));
538 * If this command can change the device's state,
539 * we must have the device open for writing.
543 case SESIOC_GETOBJMAP
:
544 case SESIOC_GETENCSTAT
:
545 case SESIOC_GETOBJSTAT
:
548 if ((ap
->a_fflag
& FWRITE
) == 0) {
555 error
= copyout(&ssc
->ses_nobjects
, addr
,
556 sizeof (ssc
->ses_nobjects
));
559 case SESIOC_GETOBJMAP
:
561 * XXX Dropping the lock while copying multiple segments is
564 cam_periph_lock(periph
);
565 for (uobj
= addr
, i
= 0; i
!= ssc
->ses_nobjects
; i
++, uobj
++) {
567 obj
.subencid
= ssc
->ses_objmap
[i
].subenclosure
;
568 obj
.object_type
= ssc
->ses_objmap
[i
].enctype
;
569 cam_periph_unlock(periph
);
570 error
= copyout(&obj
, uobj
, sizeof (ses_object
));
571 cam_periph_lock(periph
);
576 cam_periph_unlock(periph
);
579 case SESIOC_GETENCSTAT
:
580 cam_periph_lock(periph
);
581 error
= (*ssc
->ses_vec
.get_encstat
)(ssc
, 1);
583 cam_periph_unlock(periph
);
586 tmp
= ssc
->ses_encstat
& ~ENCI_SVALID
;
587 cam_periph_unlock(periph
);
588 error
= copyout(&tmp
, addr
, sizeof (ses_encstat
));
589 ssc
->ses_encstat
= tmp
;
592 case SESIOC_SETENCSTAT
:
593 error
= copyin(addr
, &tmp
, sizeof (ses_encstat
));
596 cam_periph_lock(periph
);
597 error
= (*ssc
->ses_vec
.set_encstat
)(ssc
, tmp
, 1);
598 cam_periph_unlock(periph
);
601 case SESIOC_GETOBJSTAT
:
602 error
= copyin(addr
, &objs
, sizeof (ses_objstat
));
605 if (objs
.obj_id
>= ssc
->ses_nobjects
) {
609 cam_periph_lock(periph
);
610 error
= (*ssc
->ses_vec
.get_objstat
)(ssc
, &objs
, 1);
611 cam_periph_unlock(periph
);
614 error
= copyout(&objs
, addr
, sizeof (ses_objstat
));
616 * Always (for now) invalidate entry.
618 ssc
->ses_objmap
[objs
.obj_id
].svalid
= 0;
621 case SESIOC_SETOBJSTAT
:
622 error
= copyin(addr
, &objs
, sizeof (ses_objstat
));
626 if (objs
.obj_id
>= ssc
->ses_nobjects
) {
630 cam_periph_lock(periph
);
631 error
= (*ssc
->ses_vec
.set_objstat
)(ssc
, &objs
, 1);
632 cam_periph_unlock(periph
);
635 * Always (for now) invalidate entry.
637 ssc
->ses_objmap
[objs
.obj_id
].svalid
= 0;
642 cam_periph_lock(periph
);
643 error
= (*ssc
->ses_vec
.init_enc
)(ssc
);
644 cam_periph_unlock(periph
);
648 cam_periph_lock(periph
);
649 error
= cam_periph_ioctl(periph
, ap
->a_cmd
, ap
->a_data
, seserror
);
650 cam_periph_unlock(periph
);
656 #define SES_CFLAGS CAM_RETRY_SELTO
657 #define SES_FLAGS SF_NO_PRINT | SF_RETRY_UA
659 ses_runcmd(struct ses_softc
*ssc
, char *cdb
, int cdbl
, char *dptr
, int *dlenp
)
666 if ((dlen
= *dlenp
) < 0) {
677 if (cdbl
> IOCDBLEN
) {
681 ccb
= cam_periph_getccb(ssc
->periph
, 1);
682 cam_fill_csio(&ccb
->csio
, 0, sesdone
, ddf
, MSG_SIMPLE_Q_TAG
, dptr
,
683 dlen
, sizeof (struct scsi_sense_data
), cdbl
, 60 * 1000);
684 bcopy(cdb
, ccb
->csio
.cdb_io
.cdb_bytes
, cdbl
);
686 error
= cam_periph_runccb(ccb
, seserror
, SES_CFLAGS
, SES_FLAGS
, NULL
);
687 if ((ccb
->ccb_h
.status
& CAM_DEV_QFRZN
) != 0)
688 cam_release_devq(ccb
->ccb_h
.path
, 0, 0, 0, FALSE
);
695 *dlenp
= ccb
->csio
.resid
;
698 xpt_release_ccb(ccb
);
703 ses_log(struct ses_softc
*ssc
, const char *fmt
, ...)
707 kprintf("%s%d: ", ssc
->periph
->periph_name
, ssc
->periph
->unit_number
);
714 * The code after this point runs on many platforms,
715 * so forgive the slightly awkward and nonconforming
720 * Is this a device that supports enclosure services?
722 * It's a a pretty simple ruleset- if it is device type 0x0D (13), it's
723 * an SES device. If it happens to be an old UNISYS SEN device, we can
727 #define SAFTE_START 44
729 #define SAFTE_LEN SAFTE_END-SAFTE_START
732 ses_type(void *buf
, int buflen
)
734 unsigned char *iqd
= buf
;
736 if (buflen
< 8+SEN_ID_LEN
)
739 if ((iqd
[0] & 0x1f) == T_ENCLOSURE
) {
740 if (STRNCMP(&iqd
[8], SEN_ID
, SEN_ID_LEN
) == 0) {
742 } else if ((iqd
[2] & 0x7) > 2) {
745 return (SES_SES_SCSI2
);
750 #ifdef SES_ENABLE_PASSTHROUGH
751 if ((iqd
[6] & 0x40) && (iqd
[2] & 0x7) >= 2) {
753 * PassThrough Device.
755 return (SES_SES_PASSTHROUGH
);
760 * The comparison is short for a reason-
761 * some vendors were chopping it short.
764 if (buflen
< SAFTE_END
- 2) {
768 if (STRNCMP((char *)&iqd
[SAFTE_START
], "SAF-TE", SAFTE_LEN
- 2) == 0) {
775 * SES Native Type Device Support
779 * SES Diagnostic Page Codes
785 #define SesStatusPage SesControlPage
788 #define SesStringIn SesStringOut
790 #define SesThresholdIn SesThresholdOut
792 #define SesArrayStatus SesArrayControl
793 SesElementDescriptor
,
802 * Minimum amount of data, starting from byte 0, to have
805 #define SES_CFGHDR_MINLEN 12
808 * Minimum amount of data, starting from byte 0, to have
809 * the config header and one enclosure header.
811 #define SES_ENCHDR_MINLEN 48
814 * Take this value, subtract it from VEnclen and you know
815 * the length of the vendor unique bytes.
817 #define SES_ENCHDR_VMIN 36
820 * SES Data Structures
824 uint32_t GenCode
; /* Generation Code */
825 uint8_t Nsubenc
; /* Number of Subenclosures */
829 uint8_t Subencid
; /* SubEnclosure Identifier */
830 uint8_t Ntypes
; /* # of supported types */
831 uint8_t VEnclen
; /* Enclosure Descriptor Length */
835 uint8_t encWWN
[8]; /* XXX- Not Right Yet */
843 uint8_t enc_type
; /* type of element */
844 uint8_t enc_maxelt
; /* maximum supported */
845 uint8_t enc_subenc
; /* in SubEnc # N */
846 uint8_t enc_tlen
; /* Type Descriptor Text Length */
860 uint8_t ses_ntypes
; /* total number of types supported */
863 * We need to keep a type index as well as an
864 * object index for each object in an enclosure.
866 struct typidx
*ses_typidx
;
869 * We also need to keep track of the number of elements
870 * per type of element. This is needed later so that we
871 * can find precisely in the returned status data the
872 * status for the Nth element of the Kth type.
874 uint8_t * ses_eltmap
;
879 * (de)canonicalization defines
881 #define sbyte(x, byte) ((((uint32_t)(x)) >> (byte * 8)) & 0xff)
882 #define sbit(x, bit) (((uint32_t)(x)) << bit)
883 #define sset8(outp, idx, sval) (((uint8_t *)(outp))[idx++]) = sbyte(sval, 0)
885 #define sset16(outp, idx, sval) \
886 (((uint8_t *)(outp))[idx++]) = sbyte(sval, 1), \
887 (((uint8_t *)(outp))[idx++]) = sbyte(sval, 0)
890 #define sset24(outp, idx, sval) \
891 (((uint8_t *)(outp))[idx++]) = sbyte(sval, 2), \
892 (((uint8_t *)(outp))[idx++]) = sbyte(sval, 1), \
893 (((uint8_t *)(outp))[idx++]) = sbyte(sval, 0)
896 #define sset32(outp, idx, sval) \
897 (((uint8_t *)(outp))[idx++]) = sbyte(sval, 3), \
898 (((uint8_t *)(outp))[idx++]) = sbyte(sval, 2), \
899 (((uint8_t *)(outp))[idx++]) = sbyte(sval, 1), \
900 (((uint8_t *)(outp))[idx++]) = sbyte(sval, 0)
902 #define gbyte(x, byte) ((((uint32_t)(x)) & 0xff) << (byte * 8))
903 #define gbit(lv, in, idx, shft, mask) lv = ((in[idx] >> shft) & mask)
904 #define sget8(inp, idx, lval) lval = (((uint8_t *)(inp))[idx++])
905 #define gget8(inp, idx, lval) lval = (((uint8_t *)(inp))[idx])
907 #define sget16(inp, idx, lval) \
908 lval = gbyte((((uint8_t *)(inp))[idx]), 1) | \
909 (((uint8_t *)(inp))[idx+1]), idx += 2
911 #define gget16(inp, idx, lval) \
912 lval = gbyte((((uint8_t *)(inp))[idx]), 1) | \
913 (((uint8_t *)(inp))[idx+1])
915 #define sget24(inp, idx, lval) \
916 lval = gbyte((((uint8_t *)(inp))[idx]), 2) | \
917 gbyte((((uint8_t *)(inp))[idx+1]), 1) | \
918 (((uint8_t *)(inp))[idx+2]), idx += 3
920 #define gget24(inp, idx, lval) \
921 lval = gbyte((((uint8_t *)(inp))[idx]), 2) | \
922 gbyte((((uint8_t *)(inp))[idx+1]), 1) | \
923 (((uint8_t *)(inp))[idx+2])
925 #define sget32(inp, idx, lval) \
926 lval = gbyte((((uint8_t *)(inp))[idx]), 3) | \
927 gbyte((((uint8_t *)(inp))[idx+1]), 2) | \
928 gbyte((((uint8_t *)(inp))[idx+2]), 1) | \
929 (((uint8_t *)(inp))[idx+3]), idx += 4
931 #define gget32(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])
938 #define CFLEN (256 + SES_ENCHDR_MINLEN)
941 * Routines specific && private to SES only
944 static int ses_getconfig(ses_softc_t
*);
945 static int ses_getputstat(ses_softc_t
*, int, SesComStat
*, int, int);
946 static int ses_cfghdr(uint8_t *, int, SesCfgHdr
*);
947 static int ses_enchdr(uint8_t *, int, uint8_t, SesEncHdr
*);
948 static int ses_encdesc(uint8_t *, int, uint8_t, SesEncDesc
*);
949 static int ses_getthdr(uint8_t *, int, int, SesThdr
*);
950 static int ses_decode(char *, int, uint8_t *, int, int, SesComStat
*);
951 static int ses_encode(char *, int, uint8_t *, int, int, SesComStat
*);
954 ses_softc_init(ses_softc_t
*ssc
, int doinit
)
958 if (ssc
->ses_nobjects
) {
959 SES_FREE(ssc
->ses_objmap
,
960 ssc
->ses_nobjects
* sizeof (encobj
));
961 ssc
->ses_objmap
= NULL
;
963 if ((cc
= ssc
->ses_private
) != NULL
) {
964 if (cc
->ses_eltmap
&& cc
->ses_ntypes
) {
965 SES_FREE(cc
->ses_eltmap
, cc
->ses_ntypes
);
966 cc
->ses_eltmap
= NULL
;
969 if (cc
->ses_typidx
&& ssc
->ses_nobjects
) {
970 SES_FREE(cc
->ses_typidx
,
971 ssc
->ses_nobjects
* sizeof (struct typidx
));
972 cc
->ses_typidx
= NULL
;
974 SES_FREE(cc
, sizeof (struct sscfg
));
975 ssc
->ses_private
= NULL
;
977 ssc
->ses_nobjects
= 0;
980 if (ssc
->ses_private
== NULL
) {
981 ssc
->ses_private
= SES_MALLOC(sizeof (struct sscfg
));
983 if (ssc
->ses_private
== NULL
) {
986 ssc
->ses_nobjects
= 0;
987 ssc
->ses_encstat
= 0;
988 return (ses_getconfig(ssc
));
992 ses_init_enc(ses_softc_t
*ssc
)
998 ses_get_encstat(ses_softc_t
*ssc
, int slpflag
)
1003 if ((status
= ses_getputstat(ssc
, -1, &ComStat
, slpflag
, 1)) != 0) {
1006 ssc
->ses_encstat
= ComStat
.comstatus
| ENCI_SVALID
;
1011 ses_set_encstat(ses_softc_t
*ssc
, uint8_t encstat
, int slpflag
)
1016 ComStat
.comstatus
= encstat
& 0xf;
1017 if ((status
= ses_getputstat(ssc
, -1, &ComStat
, slpflag
, 0)) != 0) {
1020 ssc
->ses_encstat
= encstat
& 0xf; /* note no SVALID set */
1025 ses_get_objstat(ses_softc_t
*ssc
, ses_objstat
*obp
, int slpflag
)
1027 int i
= (int)obp
->obj_id
;
1029 if (ssc
->ses_objmap
[i
].svalid
== 0) {
1031 int err
= ses_getputstat(ssc
, i
, &ComStat
, slpflag
, 1);
1034 ssc
->ses_objmap
[i
].encstat
[0] = ComStat
.comstatus
;
1035 ssc
->ses_objmap
[i
].encstat
[1] = ComStat
.comstat
[0];
1036 ssc
->ses_objmap
[i
].encstat
[2] = ComStat
.comstat
[1];
1037 ssc
->ses_objmap
[i
].encstat
[3] = ComStat
.comstat
[2];
1038 ssc
->ses_objmap
[i
].svalid
= 1;
1040 obp
->cstat
[0] = ssc
->ses_objmap
[i
].encstat
[0];
1041 obp
->cstat
[1] = ssc
->ses_objmap
[i
].encstat
[1];
1042 obp
->cstat
[2] = ssc
->ses_objmap
[i
].encstat
[2];
1043 obp
->cstat
[3] = ssc
->ses_objmap
[i
].encstat
[3];
1048 ses_set_objstat(ses_softc_t
*ssc
, ses_objstat
*obp
, int slpflag
)
1053 * If this is clear, we don't do diddly.
1055 if ((obp
->cstat
[0] & SESCTL_CSEL
) == 0) {
1058 ComStat
.comstatus
= obp
->cstat
[0];
1059 ComStat
.comstat
[0] = obp
->cstat
[1];
1060 ComStat
.comstat
[1] = obp
->cstat
[2];
1061 ComStat
.comstat
[2] = obp
->cstat
[3];
1062 err
= ses_getputstat(ssc
, (int)obp
->obj_id
, &ComStat
, slpflag
, 0);
1063 ssc
->ses_objmap
[(int)obp
->obj_id
].svalid
= 0;
1068 ses_getconfig(ses_softc_t
*ssc
)
1075 int err
, amt
, i
, nobj
, ntype
, maxima
;
1076 char storage
[CFLEN
], *sdata
;
1077 static char cdb
[6] = {
1078 RECEIVE_DIAGNOSTIC
, 0x1, SesConfigPage
, SCSZ
>> 8, SCSZ
& 0xff, 0
1081 cc
= ssc
->ses_private
;
1086 sdata
= SES_MALLOC(SCSZ
);
1091 err
= ses_runcmd(ssc
, cdb
, 6, sdata
, &amt
);
1093 SES_FREE(sdata
, SCSZ
);
1098 if (ses_cfghdr((uint8_t *) sdata
, amt
, &cf
)) {
1099 SES_LOG(ssc
, "Unable to parse SES Config Header\n");
1100 SES_FREE(sdata
, SCSZ
);
1103 if (amt
< SES_ENCHDR_MINLEN
) {
1104 SES_LOG(ssc
, "runt enclosure length (%d)\n", amt
);
1105 SES_FREE(sdata
, SCSZ
);
1109 SES_VLOG(ssc
, "GenCode %x %d Subenclosures\n", cf
.GenCode
, cf
.Nsubenc
);
1112 * Now waltz through all the subenclosures toting up the
1113 * number of types available in each. For this, we only
1114 * really need the enclosure header. However, we get the
1115 * enclosure descriptor for debug purposes, as well
1116 * as self-consistency checking purposes.
1119 maxima
= cf
.Nsubenc
+ 1;
1120 cdp
= (SesEncDesc
*) storage
;
1121 for (ntype
= i
= 0; i
< maxima
; i
++) {
1122 MEMZERO((caddr_t
)cdp
, sizeof (*cdp
));
1123 if (ses_enchdr((uint8_t *) sdata
, amt
, i
, &hd
)) {
1124 SES_LOG(ssc
, "Cannot Extract Enclosure Header %d\n", i
);
1125 SES_FREE(sdata
, SCSZ
);
1128 SES_VLOG(ssc
, " SubEnclosure ID %d, %d Types With this ID, En"
1129 "closure Length %d\n", hd
.Subencid
, hd
.Ntypes
, hd
.VEnclen
);
1131 if (ses_encdesc((uint8_t *)sdata
, amt
, i
, cdp
)) {
1132 SES_LOG(ssc
, "Can't get Enclosure Descriptor %d\n", i
);
1133 SES_FREE(sdata
, SCSZ
);
1136 SES_VLOG(ssc
, " WWN: %02x%02x%02x%02x%02x%02x%02x%02x\n",
1137 cdp
->encWWN
[0], cdp
->encWWN
[1], cdp
->encWWN
[2],
1138 cdp
->encWWN
[3], cdp
->encWWN
[4], cdp
->encWWN
[5],
1139 cdp
->encWWN
[6], cdp
->encWWN
[7]);
1144 * Now waltz through all the types that are available, getting
1145 * the type header so we can start adding up the number of
1146 * objects available.
1148 for (nobj
= i
= 0; i
< ntype
; i
++) {
1149 if (ses_getthdr((uint8_t *)sdata
, amt
, i
, &thdr
)) {
1150 SES_LOG(ssc
, "Can't get Enclosure Type Header %d\n", i
);
1151 SES_FREE(sdata
, SCSZ
);
1154 SES_LOG(ssc
, " Type Desc[%d]: Type 0x%x, MaxElt %d, In Subenc "
1155 "%d, Text Length %d\n", i
, thdr
.enc_type
, thdr
.enc_maxelt
,
1156 thdr
.enc_subenc
, thdr
.enc_tlen
);
1157 nobj
+= thdr
.enc_maxelt
;
1162 * Now allocate the object array and type map.
1165 ssc
->ses_objmap
= SES_MALLOC(nobj
* sizeof (encobj
));
1166 cc
->ses_typidx
= SES_MALLOC(nobj
* sizeof (struct typidx
));
1167 cc
->ses_eltmap
= SES_MALLOC(ntype
);
1169 if (ssc
->ses_objmap
== NULL
|| cc
->ses_typidx
== NULL
||
1170 cc
->ses_eltmap
== NULL
) {
1171 if (ssc
->ses_objmap
) {
1172 SES_FREE(ssc
->ses_objmap
, (nobj
* sizeof (encobj
)));
1173 ssc
->ses_objmap
= NULL
;
1175 if (cc
->ses_typidx
) {
1176 SES_FREE(cc
->ses_typidx
,
1177 (nobj
* sizeof (struct typidx
)));
1178 cc
->ses_typidx
= NULL
;
1180 if (cc
->ses_eltmap
) {
1181 SES_FREE(cc
->ses_eltmap
, ntype
);
1182 cc
->ses_eltmap
= NULL
;
1184 SES_FREE(sdata
, SCSZ
);
1187 MEMZERO(ssc
->ses_objmap
, nobj
* sizeof (encobj
));
1188 MEMZERO(cc
->ses_typidx
, nobj
* sizeof (struct typidx
));
1189 MEMZERO(cc
->ses_eltmap
, ntype
);
1190 cc
->ses_ntypes
= (uint8_t) ntype
;
1191 ssc
->ses_nobjects
= nobj
;
1194 * Now waltz through the # of types again to fill in the types
1195 * (and subenclosure ids) of the allocated objects.
1198 for (i
= 0; i
< ntype
; i
++) {
1200 if (ses_getthdr((uint8_t *)sdata
, amt
, i
, &thdr
)) {
1203 cc
->ses_eltmap
[i
] = thdr
.enc_maxelt
;
1204 for (j
= 0; j
< thdr
.enc_maxelt
; j
++) {
1205 cc
->ses_typidx
[nobj
].ses_tidx
= i
;
1206 cc
->ses_typidx
[nobj
].ses_oidx
= j
;
1207 ssc
->ses_objmap
[nobj
].subenclosure
= thdr
.enc_subenc
;
1208 ssc
->ses_objmap
[nobj
++].enctype
= thdr
.enc_type
;
1211 SES_FREE(sdata
, SCSZ
);
1216 ses_getputstat(ses_softc_t
*ssc
, int objid
, SesComStat
*sp
, int slp
, int in
)
1219 int err
, amt
, bufsiz
, tidx
, oidx
;
1220 char cdb
[6], *sdata
;
1222 cc
= ssc
->ses_private
;
1228 * If we're just getting overall enclosure status,
1229 * we only need 2 bytes of data storage.
1231 * If we're getting anything else, we know how much
1232 * storage we need by noting that starting at offset
1233 * 8 in returned data, all object status bytes are 4
1234 * bytes long, and are stored in chunks of types(M)
1235 * and nth+1 instances of type M.
1240 bufsiz
= (ssc
->ses_nobjects
* 4) + (cc
->ses_ntypes
* 4) + 8;
1242 sdata
= SES_MALLOC(bufsiz
);
1246 cdb
[0] = RECEIVE_DIAGNOSTIC
;
1248 cdb
[2] = SesStatusPage
;
1249 cdb
[3] = bufsiz
>> 8;
1250 cdb
[4] = bufsiz
& 0xff;
1253 err
= ses_runcmd(ssc
, cdb
, 6, sdata
, &amt
);
1255 SES_FREE(sdata
, bufsiz
);
1264 tidx
= cc
->ses_typidx
[objid
].ses_tidx
;
1265 oidx
= cc
->ses_typidx
[objid
].ses_oidx
;
1268 if (ses_decode(sdata
, amt
, cc
->ses_eltmap
, tidx
, oidx
, sp
)) {
1272 if (ses_encode(sdata
, amt
, cc
->ses_eltmap
, tidx
, oidx
, sp
)) {
1275 cdb
[0] = SEND_DIAGNOSTIC
;
1278 cdb
[3] = bufsiz
>> 8;
1279 cdb
[4] = bufsiz
& 0xff;
1282 err
= ses_runcmd(ssc
, cdb
, 6, sdata
, &amt
);
1285 SES_FREE(sdata
, bufsiz
);
1291 * Routines to parse returned SES data structures.
1292 * Architecture and compiler independent.
1296 ses_cfghdr(uint8_t *buffer
, int buflen
, SesCfgHdr
*cfp
)
1298 if (buflen
< SES_CFGHDR_MINLEN
) {
1301 gget8(buffer
, 1, cfp
->Nsubenc
);
1302 gget32(buffer
, 4, cfp
->GenCode
);
1307 ses_enchdr(uint8_t *buffer
, int amt
, uint8_t SubEncId
, SesEncHdr
*chp
)
1310 for (s
= 0; s
< SubEncId
; s
++) {
1313 off
+= buffer
[off
+3] + 4;
1315 if (off
+ 3 > amt
) {
1318 gget8(buffer
, off
+1, chp
->Subencid
);
1319 gget8(buffer
, off
+2, chp
->Ntypes
);
1320 gget8(buffer
, off
+3, chp
->VEnclen
);
1325 ses_encdesc(uint8_t *buffer
, int amt
, uint8_t SubEncId
, SesEncDesc
*cdp
)
1327 int s
, e
, enclen
, off
= 8;
1328 for (s
= 0; s
< SubEncId
; s
++) {
1331 off
+= buffer
[off
+3] + 4;
1333 if (off
+ 3 > amt
) {
1336 gget8(buffer
, off
+3, enclen
);
1345 MEMCPY(cdp
, &buffer
[off
], e
- off
);
1350 ses_getthdr(uint8_t *buffer
, int amt
, int nth
, SesThdr
*thp
)
1354 if (amt
< SES_CFGHDR_MINLEN
) {
1357 for (s
= 0; s
< buffer
[1]; s
++) {
1360 off
+= buffer
[off
+3] + 4;
1362 if (off
+ 3 > amt
) {
1365 off
+= buffer
[off
+3] + 4 + (nth
* 4);
1366 if (amt
< (off
+ 4))
1369 gget8(buffer
, off
++, thp
->enc_type
);
1370 gget8(buffer
, off
++, thp
->enc_maxelt
);
1371 gget8(buffer
, off
++, thp
->enc_subenc
);
1372 gget8(buffer
, off
, thp
->enc_tlen
);
1377 * This function needs a little explanation.
1379 * The arguments are:
1384 * These describes the raw input SES status data and length.
1388 * This is a map of the number of types for each element type
1393 * This is the element type being sought. If elt is -1,
1394 * then overall enclosure status is being sought.
1398 * This is the ordinal Mth element of type elt being sought.
1402 * This is the output area to store the status for
1403 * the Mth element of type Elt.
1407 ses_decode(char *b
, int amt
, uint8_t *ep
, int elt
, int elm
, SesComStat
*sp
)
1412 * If it's overall enclosure status being sought, get that.
1413 * We need at least 2 bytes of status data to get that.
1418 gget8(b
, 1, sp
->comstatus
);
1426 * Check to make sure that the Mth element is legal for type Elt.
1433 * Starting at offset 8, start skipping over the storage
1434 * for the element types we're not interested in.
1436 for (idx
= 8, i
= 0; i
< elt
; i
++) {
1437 idx
+= ((ep
[i
] + 1) * 4);
1441 * Skip over Overall status for this element type.
1446 * And skip to the index for the Mth element that we're going for.
1451 * Make sure we haven't overflowed the buffer.
1457 * Retrieve the status.
1459 gget8(b
, idx
++, sp
->comstatus
);
1460 gget8(b
, idx
++, sp
->comstat
[0]);
1461 gget8(b
, idx
++, sp
->comstat
[1]);
1462 gget8(b
, idx
++, sp
->comstat
[2]);
1464 PRINTF("Get Elt 0x%x Elm 0x%x (idx %d)\n", elt
, elm
, idx
-4);
1470 * This is the mirror function to ses_decode, but we set the 'select'
1471 * bit for the object which we're interested in. All other objects,
1472 * after a status fetch, should have that bit off. Hmm. It'd be easy
1473 * enough to ensure this, so we will.
1477 ses_encode(char *b
, int amt
, uint8_t *ep
, int elt
, int elm
, SesComStat
*sp
)
1482 * If it's overall enclosure status being sought, get that.
1483 * We need at least 2 bytes of status data to get that.
1490 sset8(b
, i
, sp
->comstatus
& 0xf);
1492 PRINTF("set EncStat %x\n", sp
->comstatus
);
1498 * Check to make sure that the Mth element is legal for type Elt.
1505 * Starting at offset 8, start skipping over the storage
1506 * for the element types we're not interested in.
1508 for (idx
= 8, i
= 0; i
< elt
; i
++) {
1509 idx
+= ((ep
[i
] + 1) * 4);
1513 * Skip over Overall status for this element type.
1518 * And skip to the index for the Mth element that we're going for.
1523 * Make sure we haven't overflowed the buffer.
1531 sset8(b
, idx
, sp
->comstatus
);
1532 sset8(b
, idx
, sp
->comstat
[0]);
1533 sset8(b
, idx
, sp
->comstat
[1]);
1534 sset8(b
, idx
, sp
->comstat
[2]);
1538 PRINTF("Set Elt 0x%x Elm 0x%x (idx %d) with %x %x %x %x\n",
1539 elt
, elm
, idx
, sp
->comstatus
, sp
->comstat
[0],
1540 sp
->comstat
[1], sp
->comstat
[2]);
1544 * Now make sure all other 'Select' bits are off.
1546 for (i
= 8; i
< amt
; i
+= 4) {
1551 * And make sure the INVOP bit is clear.
1559 * SAF-TE Type Device Emulation
1562 static int safte_getconfig(ses_softc_t
*);
1563 static int safte_rdstat(ses_softc_t
*, int);
1564 static int set_objstat_sel(ses_softc_t
*, ses_objstat
*, int);
1565 static int wrbuf16(ses_softc_t
*, uint8_t, uint8_t, uint8_t, uint8_t, int);
1566 static void wrslot_stat(ses_softc_t
*, int);
1567 static int perf_slotop(ses_softc_t
*, uint8_t, uint8_t, int);
1569 #define ALL_ENC_STAT (SES_ENCSTAT_CRITICAL | SES_ENCSTAT_UNRECOV | \
1570 SES_ENCSTAT_NONCRITICAL | SES_ENCSTAT_INFO)
1572 * SAF-TE specific defines- Mandatory ones only...
1576 * READ BUFFER ('get' commands) IDs- placed in offset 2 of cdb
1578 #define SAFTE_RD_RDCFG 0x00 /* read enclosure configuration */
1579 #define SAFTE_RD_RDESTS 0x01 /* read enclosure status */
1580 #define SAFTE_RD_RDDSTS 0x04 /* read drive slot status */
1583 * WRITE BUFFER ('set' commands) IDs- placed in offset 0 of databuf
1585 #define SAFTE_WT_DSTAT 0x10 /* write device slot status */
1586 #define SAFTE_WT_SLTOP 0x12 /* perform slot operation */
1587 #define SAFTE_WT_FANSPD 0x13 /* set fan speed */
1588 #define SAFTE_WT_ACTPWS 0x14 /* turn on/off power supply */
1589 #define SAFTE_WT_GLOBAL 0x15 /* send global command */
1592 #define SAFT_SCRATCH 64
1593 #define NPSEUDO_THERM 16
1594 #define NPSEUDO_ALARM 1
1597 * Cached Configuration
1599 uint8_t Nfans
; /* Number of Fans */
1600 uint8_t Npwr
; /* Number of Power Supplies */
1601 uint8_t Nslots
; /* Number of Device Slots */
1602 uint8_t DoorLock
; /* Door Lock Installed */
1603 uint8_t Ntherm
; /* Number of Temperature Sensors */
1604 uint8_t Nspkrs
; /* Number of Speakers */
1605 uint8_t Nalarm
; /* Number of Alarms (at least one) */
1607 * Cached Flag Bytes for Global Status
1612 * What object index ID is where various slots start.
1616 #define SAFT_ALARM_OFFSET(cc) (cc)->slotoff - 1
1619 #define SAFT_FLG1_ALARM 0x1
1620 #define SAFT_FLG1_GLOBFAIL 0x2
1621 #define SAFT_FLG1_GLOBWARN 0x4
1622 #define SAFT_FLG1_ENCPWROFF 0x8
1623 #define SAFT_FLG1_ENCFANFAIL 0x10
1624 #define SAFT_FLG1_ENCPWRFAIL 0x20
1625 #define SAFT_FLG1_ENCDRVFAIL 0x40
1626 #define SAFT_FLG1_ENCDRVWARN 0x80
1628 #define SAFT_FLG2_LOCKDOOR 0x4
1629 #define SAFT_PRIVATE sizeof (struct scfg)
1631 static char *safte_2little
= "Too Little Data Returned (%d) at line %d\n";
1632 #define SAFT_BAIL(r, x, k, l) \
1634 SES_LOG(ssc, safte_2little, x, __LINE__);\
1635 SES_FREE((k), (l)); \
1641 safte_softc_init(ses_softc_t
*ssc
, int doinit
)
1647 if (ssc
->ses_nobjects
) {
1648 if (ssc
->ses_objmap
) {
1649 SES_FREE(ssc
->ses_objmap
,
1650 ssc
->ses_nobjects
* sizeof (encobj
));
1651 ssc
->ses_objmap
= NULL
;
1653 ssc
->ses_nobjects
= 0;
1655 if (ssc
->ses_private
) {
1656 SES_FREE(ssc
->ses_private
, SAFT_PRIVATE
);
1657 ssc
->ses_private
= NULL
;
1662 if (ssc
->ses_private
== NULL
) {
1663 ssc
->ses_private
= SES_MALLOC(SAFT_PRIVATE
);
1664 if (ssc
->ses_private
== NULL
) {
1667 MEMZERO(ssc
->ses_private
, SAFT_PRIVATE
);
1670 ssc
->ses_nobjects
= 0;
1671 ssc
->ses_encstat
= 0;
1673 if ((err
= safte_getconfig(ssc
)) != 0) {
1678 * The number of objects here, as well as that reported by the
1679 * READ_BUFFER/GET_CONFIG call, are the over-temperature flags (15)
1680 * that get reported during READ_BUFFER/READ_ENC_STATUS.
1682 cc
= ssc
->ses_private
;
1683 ssc
->ses_nobjects
= cc
->Nfans
+ cc
->Npwr
+ cc
->Nslots
+ cc
->DoorLock
+
1684 cc
->Ntherm
+ cc
->Nspkrs
+ NPSEUDO_THERM
+ NPSEUDO_ALARM
;
1685 ssc
->ses_objmap
= (encobj
*)
1686 SES_MALLOC(ssc
->ses_nobjects
* sizeof (encobj
));
1687 if (ssc
->ses_objmap
== NULL
) {
1690 MEMZERO(ssc
->ses_objmap
, ssc
->ses_nobjects
* sizeof (encobj
));
1694 * Note that this is all arranged for the convenience
1695 * in later fetches of status.
1697 for (i
= 0; i
< cc
->Nfans
; i
++)
1698 ssc
->ses_objmap
[r
++].enctype
= SESTYP_FAN
;
1699 cc
->pwroff
= (uint8_t) r
;
1700 for (i
= 0; i
< cc
->Npwr
; i
++)
1701 ssc
->ses_objmap
[r
++].enctype
= SESTYP_POWER
;
1702 for (i
= 0; i
< cc
->DoorLock
; i
++)
1703 ssc
->ses_objmap
[r
++].enctype
= SESTYP_DOORLOCK
;
1704 for (i
= 0; i
< cc
->Nspkrs
; i
++)
1705 ssc
->ses_objmap
[r
++].enctype
= SESTYP_ALARM
;
1706 for (i
= 0; i
< cc
->Ntherm
; i
++)
1707 ssc
->ses_objmap
[r
++].enctype
= SESTYP_THERM
;
1708 for (i
= 0; i
< NPSEUDO_THERM
; i
++)
1709 ssc
->ses_objmap
[r
++].enctype
= SESTYP_THERM
;
1710 ssc
->ses_objmap
[r
++].enctype
= SESTYP_ALARM
;
1711 cc
->slotoff
= (uint8_t) r
;
1712 for (i
= 0; i
< cc
->Nslots
; i
++)
1713 ssc
->ses_objmap
[r
++].enctype
= SESTYP_DEVICE
;
1718 safte_init_enc(ses_softc_t
*ssc
)
1721 static char cdb0
[6] = { SEND_DIAGNOSTIC
};
1723 err
= ses_runcmd(ssc
, cdb0
, 6, NULL
, 0);
1728 err
= wrbuf16(ssc
, SAFTE_WT_GLOBAL
, 0, 0, 0, 1);
1733 safte_get_encstat(ses_softc_t
*ssc
, int slpflg
)
1735 return (safte_rdstat(ssc
, slpflg
));
1739 safte_set_encstat(ses_softc_t
*ssc
, uint8_t encstat
, int slpflg
)
1741 struct scfg
*cc
= ssc
->ses_private
;
1745 * Since SAF-TE devices aren't necessarily sticky in terms
1746 * of state, make our soft copy of enclosure status 'sticky'-
1747 * that is, things set in enclosure status stay set (as implied
1748 * by conditions set in reading object status) until cleared.
1750 ssc
->ses_encstat
&= ~ALL_ENC_STAT
;
1751 ssc
->ses_encstat
|= (encstat
& ALL_ENC_STAT
);
1752 ssc
->ses_encstat
|= ENCI_SVALID
;
1753 cc
->flag1
&= ~(SAFT_FLG1_ALARM
|SAFT_FLG1_GLOBFAIL
|SAFT_FLG1_GLOBWARN
);
1754 if ((encstat
& (SES_ENCSTAT_CRITICAL
|SES_ENCSTAT_UNRECOV
)) != 0) {
1755 cc
->flag1
|= SAFT_FLG1_ALARM
|SAFT_FLG1_GLOBFAIL
;
1756 } else if ((encstat
& SES_ENCSTAT_NONCRITICAL
) != 0) {
1757 cc
->flag1
|= SAFT_FLG1_GLOBWARN
;
1759 return (wrbuf16(ssc
, SAFTE_WT_GLOBAL
, cc
->flag1
, cc
->flag2
, 0, slpflg
));
1763 safte_get_objstat(ses_softc_t
*ssc
, ses_objstat
*obp
, int slpflg
)
1765 int i
= (int)obp
->obj_id
;
1767 if ((ssc
->ses_encstat
& ENCI_SVALID
) == 0 ||
1768 (ssc
->ses_objmap
[i
].svalid
) == 0) {
1769 int err
= safte_rdstat(ssc
, slpflg
);
1773 obp
->cstat
[0] = ssc
->ses_objmap
[i
].encstat
[0];
1774 obp
->cstat
[1] = ssc
->ses_objmap
[i
].encstat
[1];
1775 obp
->cstat
[2] = ssc
->ses_objmap
[i
].encstat
[2];
1776 obp
->cstat
[3] = ssc
->ses_objmap
[i
].encstat
[3];
1782 safte_set_objstat(ses_softc_t
*ssc
, ses_objstat
*obp
, int slp
)
1789 SES_DLOG(ssc
, "safte_set_objstat(%d): %x %x %x %x\n",
1790 (int)obp
->obj_id
, obp
->cstat
[0], obp
->cstat
[1], obp
->cstat
[2],
1794 * If this is clear, we don't do diddly.
1796 if ((obp
->cstat
[0] & SESCTL_CSEL
) == 0) {
1802 * Check to see if the common bits are set and do them first.
1804 if (obp
->cstat
[0] & ~SESCTL_CSEL
) {
1805 err
= set_objstat_sel(ssc
, obp
, slp
);
1810 cc
= ssc
->ses_private
;
1814 idx
= (int)obp
->obj_id
;
1815 ep
= &ssc
->ses_objmap
[idx
];
1817 switch (ep
->enctype
) {
1822 * XXX: I should probably cache the previous state
1823 * XXX: of SESCTL_DEVOFF so that when it goes from
1824 * XXX: true to false I can then set PREPARE FOR OPERATION
1825 * XXX: flag in PERFORM SLOT OPERATION write buffer command.
1827 if (obp
->cstat
[2] & (SESCTL_RQSINS
|SESCTL_RQSRMV
)) {
1830 if (obp
->cstat
[2] & SESCTL_RQSID
) {
1833 err
= perf_slotop(ssc
, (uint8_t) idx
- (uint8_t) cc
->slotoff
,
1837 if (obp
->cstat
[3] & SESCTL_RQSFLT
) {
1842 if (ep
->priv
& 0xc6) {
1845 ep
->priv
|= 0x1; /* no errors */
1847 wrslot_stat(ssc
, slp
);
1851 if (obp
->cstat
[3] & SESCTL_RQSTFAIL
) {
1852 cc
->flag1
|= SAFT_FLG1_ENCPWRFAIL
;
1854 cc
->flag1
&= ~SAFT_FLG1_ENCPWRFAIL
;
1856 err
= wrbuf16(ssc
, SAFTE_WT_GLOBAL
, cc
->flag1
,
1860 if (obp
->cstat
[3] & SESCTL_RQSTON
) {
1861 wrbuf16(ssc
, SAFTE_WT_ACTPWS
,
1862 idx
- cc
->pwroff
, 0, 0, slp
);
1864 wrbuf16(ssc
, SAFTE_WT_ACTPWS
,
1865 idx
- cc
->pwroff
, 0, 1, slp
);
1869 if (obp
->cstat
[3] & SESCTL_RQSTFAIL
) {
1870 cc
->flag1
|= SAFT_FLG1_ENCFANFAIL
;
1872 cc
->flag1
&= ~SAFT_FLG1_ENCFANFAIL
;
1874 err
= wrbuf16(ssc
, SAFTE_WT_GLOBAL
, cc
->flag1
,
1878 if (obp
->cstat
[3] & SESCTL_RQSTON
) {
1880 if ((obp
->cstat
[3] & 0x7) == 7) {
1882 } else if ((obp
->cstat
[3] & 0x7) == 6) {
1884 } else if ((obp
->cstat
[3] & 0x7) == 4) {
1889 wrbuf16(ssc
, SAFTE_WT_FANSPD
, idx
, fsp
, 0, slp
);
1891 wrbuf16(ssc
, SAFTE_WT_FANSPD
, idx
, 0, 0, slp
);
1894 case SESTYP_DOORLOCK
:
1895 if (obp
->cstat
[3] & 0x1) {
1896 cc
->flag2
&= ~SAFT_FLG2_LOCKDOOR
;
1898 cc
->flag2
|= SAFT_FLG2_LOCKDOOR
;
1900 wrbuf16(ssc
, SAFTE_WT_GLOBAL
, cc
->flag1
, cc
->flag2
, 0, slp
);
1904 * On all nonzero but the 'muted' bit, we turn on the alarm,
1906 obp
->cstat
[3] &= ~0xa;
1907 if (obp
->cstat
[3] & 0x40) {
1908 cc
->flag2
&= ~SAFT_FLG1_ALARM
;
1909 } else if (obp
->cstat
[3] != 0) {
1910 cc
->flag2
|= SAFT_FLG1_ALARM
;
1912 cc
->flag2
&= ~SAFT_FLG1_ALARM
;
1914 ep
->priv
= obp
->cstat
[3];
1915 wrbuf16(ssc
, SAFTE_WT_GLOBAL
, cc
->flag1
, cc
->flag2
, 0, slp
);
1925 safte_getconfig(ses_softc_t
*ssc
)
1930 static char cdb
[10] =
1931 { READ_BUFFER
, 1, SAFTE_RD_RDCFG
, 0, 0, 0, 0, 0, SAFT_SCRATCH
, 0 };
1933 cfg
= ssc
->ses_private
;
1937 sdata
= SES_MALLOC(SAFT_SCRATCH
);
1942 err
= ses_runcmd(ssc
, cdb
, 10, sdata
, &amt
);
1944 SES_FREE(sdata
, SAFT_SCRATCH
);
1947 amt
= SAFT_SCRATCH
- amt
;
1949 SES_LOG(ssc
, "too little data (%d) for configuration\n", amt
);
1950 SES_FREE(sdata
, SAFT_SCRATCH
);
1953 SES_VLOG(ssc
, "Nfans %d Npwr %d Nslots %d Lck %d Ntherm %d Nspkrs %d\n",
1954 sdata
[0], sdata
[1], sdata
[2], sdata
[3], sdata
[4], sdata
[5]);
1955 cfg
->Nfans
= sdata
[0];
1956 cfg
->Npwr
= sdata
[1];
1957 cfg
->Nslots
= sdata
[2];
1958 cfg
->DoorLock
= sdata
[3];
1959 cfg
->Ntherm
= sdata
[4];
1960 cfg
->Nspkrs
= sdata
[5];
1961 cfg
->Nalarm
= NPSEUDO_ALARM
;
1962 SES_FREE(sdata
, SAFT_SCRATCH
);
1967 safte_rdstat(ses_softc_t
*ssc
, int slpflg
)
1969 int err
, oid
, r
, i
, hiwater
, nitems
, amt
;
1972 uint8_t status
, oencstat
;
1973 char *sdata
, cdb
[10];
1974 struct scfg
*cc
= ssc
->ses_private
;
1978 * The number of objects overstates things a bit,
1979 * both for the bogus 'thermometer' entries and
1980 * the drive status (which isn't read at the same
1981 * time as the enclosure status), but that's okay.
1983 buflen
= 4 * cc
->Nslots
;
1984 if (ssc
->ses_nobjects
> buflen
)
1985 buflen
= ssc
->ses_nobjects
;
1986 sdata
= SES_MALLOC(buflen
);
1990 cdb
[0] = READ_BUFFER
;
1992 cdb
[2] = SAFTE_RD_RDESTS
;
1997 cdb
[7] = (buflen
>> 8) & 0xff;
1998 cdb
[8] = buflen
& 0xff;
2001 err
= ses_runcmd(ssc
, cdb
, 10, sdata
, &amt
);
2003 SES_FREE(sdata
, buflen
);
2006 hiwater
= buflen
- amt
;
2010 * invalidate all status bits.
2012 for (i
= 0; i
< ssc
->ses_nobjects
; i
++)
2013 ssc
->ses_objmap
[i
].svalid
= 0;
2014 oencstat
= ssc
->ses_encstat
& ALL_ENC_STAT
;
2015 ssc
->ses_encstat
= 0;
2019 * Now parse returned buffer.
2020 * If we didn't get enough data back,
2021 * that's considered a fatal error.
2025 for (nitems
= i
= 0; i
< cc
->Nfans
; i
++) {
2026 SAFT_BAIL(r
, hiwater
, sdata
, buflen
);
2028 * 0 = Fan Operational
2029 * 1 = Fan is malfunctioning
2030 * 2 = Fan is not present
2031 * 0x80 = Unknown or Not Reportable Status
2033 ssc
->ses_objmap
[oid
].encstat
[1] = 0; /* resvd */
2034 ssc
->ses_objmap
[oid
].encstat
[2] = 0; /* resvd */
2035 switch ((int)(uint8_t)sdata
[r
]) {
2038 ssc
->ses_objmap
[oid
].encstat
[0] = SES_OBJSTAT_OK
;
2040 * We could get fancier and cache
2041 * fan speeds that we have set, but
2042 * that isn't done now.
2044 ssc
->ses_objmap
[oid
].encstat
[3] = 7;
2048 ssc
->ses_objmap
[oid
].encstat
[0] = SES_OBJSTAT_CRIT
;
2050 * FAIL and FAN STOPPED synthesized
2052 ssc
->ses_objmap
[oid
].encstat
[3] = 0x40;
2054 * Enclosure marked with CRITICAL error
2055 * if only one fan or no thermometers,
2056 * else the NONCRITICAL error is set.
2058 if (cc
->Nfans
== 1 || cc
->Ntherm
== 0)
2059 ssc
->ses_encstat
|= SES_ENCSTAT_CRITICAL
;
2061 ssc
->ses_encstat
|= SES_ENCSTAT_NONCRITICAL
;
2064 ssc
->ses_objmap
[oid
].encstat
[0] =
2065 SES_OBJSTAT_NOTINSTALLED
;
2066 ssc
->ses_objmap
[oid
].encstat
[3] = 0;
2068 * Enclosure marked with CRITICAL error
2069 * if only one fan or no thermometers,
2070 * else the NONCRITICAL error is set.
2073 ssc
->ses_encstat
|= SES_ENCSTAT_CRITICAL
;
2075 ssc
->ses_encstat
|= SES_ENCSTAT_NONCRITICAL
;
2078 ssc
->ses_objmap
[oid
].encstat
[0] = SES_OBJSTAT_UNKNOWN
;
2079 ssc
->ses_objmap
[oid
].encstat
[3] = 0;
2080 ssc
->ses_encstat
|= SES_ENCSTAT_INFO
;
2083 ssc
->ses_objmap
[oid
].encstat
[0] =
2084 SES_OBJSTAT_UNSUPPORTED
;
2085 SES_LOG(ssc
, "Unknown fan%d status 0x%x\n", i
,
2089 ssc
->ses_objmap
[oid
++].svalid
= 1;
2094 * No matter how you cut it, no cooling elements when there
2095 * should be some there is critical.
2097 if (cc
->Nfans
&& nitems
== 0) {
2098 ssc
->ses_encstat
|= SES_ENCSTAT_CRITICAL
;
2102 for (i
= 0; i
< cc
->Npwr
; i
++) {
2103 SAFT_BAIL(r
, hiwater
, sdata
, buflen
);
2104 ssc
->ses_objmap
[oid
].encstat
[0] = SES_OBJSTAT_UNKNOWN
;
2105 ssc
->ses_objmap
[oid
].encstat
[1] = 0; /* resvd */
2106 ssc
->ses_objmap
[oid
].encstat
[2] = 0; /* resvd */
2107 ssc
->ses_objmap
[oid
].encstat
[3] = 0x20; /* requested on */
2108 switch ((uint8_t)sdata
[r
]) {
2109 case 0x00: /* pws operational and on */
2110 ssc
->ses_objmap
[oid
].encstat
[0] = SES_OBJSTAT_OK
;
2112 case 0x01: /* pws operational and off */
2113 ssc
->ses_objmap
[oid
].encstat
[0] = SES_OBJSTAT_OK
;
2114 ssc
->ses_objmap
[oid
].encstat
[3] = 0x10;
2115 ssc
->ses_encstat
|= SES_ENCSTAT_INFO
;
2117 case 0x10: /* pws is malfunctioning and commanded on */
2118 ssc
->ses_objmap
[oid
].encstat
[0] = SES_OBJSTAT_CRIT
;
2119 ssc
->ses_objmap
[oid
].encstat
[3] = 0x61;
2120 ssc
->ses_encstat
|= SES_ENCSTAT_NONCRITICAL
;
2123 case 0x11: /* pws is malfunctioning and commanded off */
2124 ssc
->ses_objmap
[oid
].encstat
[0] = SES_OBJSTAT_NONCRIT
;
2125 ssc
->ses_objmap
[oid
].encstat
[3] = 0x51;
2126 ssc
->ses_encstat
|= SES_ENCSTAT_NONCRITICAL
;
2128 case 0x20: /* pws is not present */
2129 ssc
->ses_objmap
[oid
].encstat
[0] =
2130 SES_OBJSTAT_NOTINSTALLED
;
2131 ssc
->ses_objmap
[oid
].encstat
[3] = 0;
2132 ssc
->ses_encstat
|= SES_ENCSTAT_INFO
;
2134 case 0x21: /* pws is present */
2136 * This is for enclosures that cannot tell whether the
2137 * device is on or malfunctioning, but know that it is
2138 * present. Just fall through.
2141 case 0x80: /* Unknown or Not Reportable Status */
2142 ssc
->ses_objmap
[oid
].encstat
[0] = SES_OBJSTAT_UNKNOWN
;
2143 ssc
->ses_objmap
[oid
].encstat
[3] = 0;
2144 ssc
->ses_encstat
|= SES_ENCSTAT_INFO
;
2147 SES_LOG(ssc
, "unknown power supply %d status (0x%x)\n",
2148 i
, sdata
[r
] & 0xff);
2151 ssc
->ses_objmap
[oid
++].svalid
= 1;
2156 * Skip over Slot SCSI IDs
2161 * We always have doorlock status, no matter what,
2162 * but we only save the status if we have one.
2164 SAFT_BAIL(r
, hiwater
, sdata
, buflen
);
2168 * 1 = Door Unlocked, or no Lock Installed
2169 * 0x80 = Unknown or Not Reportable Status
2171 ssc
->ses_objmap
[oid
].encstat
[1] = 0;
2172 ssc
->ses_objmap
[oid
].encstat
[2] = 0;
2173 switch ((uint8_t)sdata
[r
]) {
2175 ssc
->ses_objmap
[oid
].encstat
[0] = SES_OBJSTAT_OK
;
2176 ssc
->ses_objmap
[oid
].encstat
[3] = 0;
2179 ssc
->ses_objmap
[oid
].encstat
[0] = SES_OBJSTAT_OK
;
2180 ssc
->ses_objmap
[oid
].encstat
[3] = 1;
2183 ssc
->ses_objmap
[oid
].encstat
[0] = SES_OBJSTAT_UNKNOWN
;
2184 ssc
->ses_objmap
[oid
].encstat
[3] = 0;
2185 ssc
->ses_encstat
|= SES_ENCSTAT_INFO
;
2188 ssc
->ses_objmap
[oid
].encstat
[0] =
2189 SES_OBJSTAT_UNSUPPORTED
;
2190 SES_LOG(ssc
, "unknown lock status 0x%x\n",
2194 ssc
->ses_objmap
[oid
++].svalid
= 1;
2199 * We always have speaker status, no matter what,
2200 * but we only save the status if we have one.
2202 SAFT_BAIL(r
, hiwater
, sdata
, buflen
);
2204 ssc
->ses_objmap
[oid
].encstat
[1] = 0;
2205 ssc
->ses_objmap
[oid
].encstat
[2] = 0;
2206 if (sdata
[r
] == 1) {
2208 * We need to cache tone urgency indicators.
2211 ssc
->ses_objmap
[oid
].encstat
[0] = SES_OBJSTAT_NONCRIT
;
2212 ssc
->ses_objmap
[oid
].encstat
[3] = 0x8;
2213 ssc
->ses_encstat
|= SES_ENCSTAT_NONCRITICAL
;
2214 } else if (sdata
[r
] == 0) {
2215 ssc
->ses_objmap
[oid
].encstat
[0] = SES_OBJSTAT_OK
;
2216 ssc
->ses_objmap
[oid
].encstat
[3] = 0;
2218 ssc
->ses_objmap
[oid
].encstat
[0] =
2219 SES_OBJSTAT_UNSUPPORTED
;
2220 ssc
->ses_objmap
[oid
].encstat
[3] = 0;
2221 SES_LOG(ssc
, "unknown spkr status 0x%x\n",
2224 ssc
->ses_objmap
[oid
++].svalid
= 1;
2228 for (i
= 0; i
< cc
->Ntherm
; i
++) {
2229 SAFT_BAIL(r
, hiwater
, sdata
, buflen
);
2231 * Status is a range from -10 to 245 deg Celsius,
2232 * which we need to normalize to -20 to -245 according
2233 * to the latest SCSI spec, which makes little
2234 * sense since this would overflow an 8bit value.
2235 * Well, still, the base normalization is -20,
2236 * not -10, so we have to adjust.
2238 * So what's over and under temperature?
2239 * Hmm- we'll state that 'normal' operating
2240 * is 10 to 40 deg Celsius.
2244 * Actually.... All of the units that people out in the world
2245 * seem to have do not come even close to setting a value that
2246 * complies with this spec.
2248 * The closest explanation I could find was in an
2249 * LSI-Logic manual, which seemed to indicate that
2250 * this value would be set by whatever the I2C code
2251 * would interpolate from the output of an LM75
2252 * temperature sensor.
2254 * This means that it is impossible to use the actual
2255 * numeric value to predict anything. But we don't want
2256 * to lose the value. So, we'll propagate the *uncorrected*
2257 * value and set SES_OBJSTAT_NOTAVAIL. We'll depend on the
2258 * temperature flags for warnings.
2260 ssc
->ses_objmap
[oid
].encstat
[0] = SES_OBJSTAT_NOTAVAIL
;
2261 ssc
->ses_objmap
[oid
].encstat
[1] = 0;
2262 ssc
->ses_objmap
[oid
].encstat
[2] = sdata
[r
];
2263 ssc
->ses_objmap
[oid
].encstat
[3] = 0;
2264 ssc
->ses_objmap
[oid
++].svalid
= 1;
2269 * Now, for "pseudo" thermometers, we have two bytes
2270 * of information in enclosure status- 16 bits. Actually,
2271 * the MSB is a single TEMP ALERT flag indicating whether
2272 * any other bits are set, but, thanks to fuzzy thinking,
2273 * in the SAF-TE spec, this can also be set even if no
2274 * other bits are set, thus making this really another
2275 * binary temperature sensor.
2278 SAFT_BAIL(r
, hiwater
, sdata
, buflen
);
2279 tempflags
= sdata
[r
++];
2280 SAFT_BAIL(r
, hiwater
, sdata
, buflen
);
2281 tempflags
|= (tempflags
<< 8) | sdata
[r
++];
2283 for (i
= 0; i
< NPSEUDO_THERM
; i
++) {
2284 ssc
->ses_objmap
[oid
].encstat
[1] = 0;
2285 if (tempflags
& (1 << (NPSEUDO_THERM
- i
- 1))) {
2286 ssc
->ses_objmap
[oid
].encstat
[0] = SES_OBJSTAT_CRIT
;
2287 ssc
->ses_objmap
[4].encstat
[2] = 0xff;
2289 * Set 'over temperature' failure.
2291 ssc
->ses_objmap
[oid
].encstat
[3] = 8;
2292 ssc
->ses_encstat
|= SES_ENCSTAT_CRITICAL
;
2295 * We used to say 'not available' and synthesize a
2296 * nominal 30 deg (C)- that was wrong. Actually,
2297 * Just say 'OK', and use the reserved value of
2300 ssc
->ses_objmap
[oid
].encstat
[0] = SES_OBJSTAT_OK
;
2301 ssc
->ses_objmap
[oid
].encstat
[2] = 0;
2302 ssc
->ses_objmap
[oid
].encstat
[3] = 0;
2304 ssc
->ses_objmap
[oid
++].svalid
= 1;
2310 ssc
->ses_objmap
[oid
].encstat
[0] = SES_OBJSTAT_OK
;
2311 ssc
->ses_objmap
[oid
].encstat
[3] = ssc
->ses_objmap
[oid
].priv
;
2312 ssc
->ses_objmap
[oid
++].svalid
= 1;
2315 * Now get drive slot status
2317 cdb
[2] = SAFTE_RD_RDDSTS
;
2319 err
= ses_runcmd(ssc
, cdb
, 10, sdata
, &amt
);
2321 SES_FREE(sdata
, buflen
);
2324 hiwater
= buflen
- amt
;
2325 for (r
= i
= 0; i
< cc
->Nslots
; i
++, r
+= 4) {
2326 SAFT_BAIL(r
+3, hiwater
, sdata
, buflen
);
2327 ssc
->ses_objmap
[oid
].encstat
[0] = SES_OBJSTAT_UNSUPPORTED
;
2328 ssc
->ses_objmap
[oid
].encstat
[1] = (uint8_t) i
;
2329 ssc
->ses_objmap
[oid
].encstat
[2] = 0;
2330 ssc
->ses_objmap
[oid
].encstat
[3] = 0;
2331 status
= sdata
[r
+3];
2332 if ((status
& 0x1) == 0) { /* no device */
2333 ssc
->ses_objmap
[oid
].encstat
[0] =
2334 SES_OBJSTAT_NOTINSTALLED
;
2336 ssc
->ses_objmap
[oid
].encstat
[0] = SES_OBJSTAT_OK
;
2339 ssc
->ses_objmap
[oid
].encstat
[2] = 0x8;
2341 if ((status
& 0x4) == 0) {
2342 ssc
->ses_objmap
[oid
].encstat
[3] = 0x10;
2344 ssc
->ses_objmap
[oid
++].svalid
= 1;
2346 /* see comment below about sticky enclosure status */
2347 ssc
->ses_encstat
|= ENCI_SVALID
| oencstat
;
2348 SES_FREE(sdata
, buflen
);
2353 set_objstat_sel(ses_softc_t
*ssc
, ses_objstat
*obp
, int slp
)
2357 struct scfg
*cc
= ssc
->ses_private
;
2362 idx
= (int)obp
->obj_id
;
2363 ep
= &ssc
->ses_objmap
[idx
];
2365 switch (ep
->enctype
) {
2367 if (obp
->cstat
[0] & SESCTL_PRDFAIL
) {
2370 /* SESCTL_RSTSWAP has no correspondence in SAF-TE */
2371 if (obp
->cstat
[0] & SESCTL_DISABLE
) {
2374 * Hmm. Try to set the 'No Drive' flag.
2375 * Maybe that will count as a 'disable'.
2378 if (ep
->priv
& 0xc6) {
2381 ep
->priv
|= 0x1; /* no errors */
2383 wrslot_stat(ssc
, slp
);
2387 * Okay- the only one that makes sense here is to
2388 * do the 'disable' for a power supply.
2390 if (obp
->cstat
[0] & SESCTL_DISABLE
) {
2391 wrbuf16(ssc
, SAFTE_WT_ACTPWS
,
2392 idx
- cc
->pwroff
, 0, 0, slp
);
2397 * Okay- the only one that makes sense here is to
2398 * set fan speed to zero on disable.
2400 if (obp
->cstat
[0] & SESCTL_DISABLE
) {
2401 /* remember- fans are the first items, so idx works */
2402 wrbuf16(ssc
, SAFTE_WT_FANSPD
, idx
, 0, 0, slp
);
2405 case SESTYP_DOORLOCK
:
2407 * Well, we can 'disable' the lock.
2409 if (obp
->cstat
[0] & SESCTL_DISABLE
) {
2410 cc
->flag2
&= ~SAFT_FLG2_LOCKDOOR
;
2411 wrbuf16(ssc
, SAFTE_WT_GLOBAL
, cc
->flag1
,
2417 * Well, we can 'disable' the alarm.
2419 if (obp
->cstat
[0] & SESCTL_DISABLE
) {
2420 cc
->flag2
&= ~SAFT_FLG1_ALARM
;
2421 ep
->priv
|= 0x40; /* Muted */
2422 wrbuf16(ssc
, SAFTE_WT_GLOBAL
, cc
->flag1
,
2434 * This function handles all of the 16 byte WRITE BUFFER commands.
2437 wrbuf16(ses_softc_t
*ssc
, uint8_t op
, uint8_t b1
, uint8_t b2
,
2438 uint8_t b3
, int slp
)
2442 struct scfg
*cc
= ssc
->ses_private
;
2443 static char cdb
[10] = { WRITE_BUFFER
, 1, 0, 0, 0, 0, 0, 0, 16, 0 };
2448 sdata
= SES_MALLOC(16);
2452 SES_DLOG(ssc
, "saf_wrbuf16 %x %x %x %x\n", op
, b1
, b2
, b3
);
2458 MEMZERO(&sdata
[4], 12);
2460 err
= ses_runcmd(ssc
, cdb
, 10, sdata
, &amt
);
2461 SES_FREE(sdata
, 16);
2466 * This function updates the status byte for the device slot described.
2468 * Since this is an optional SAF-TE command, there's no point in
2469 * returning an error.
2472 wrslot_stat(ses_softc_t
*ssc
, int slp
)
2476 char cdb
[10], *sdata
;
2477 struct scfg
*cc
= ssc
->ses_private
;
2482 SES_DLOG(ssc
, "saf_wrslot\n");
2483 cdb
[0] = WRITE_BUFFER
;
2491 cdb
[8] = cc
->Nslots
* 3 + 1;
2494 sdata
= SES_MALLOC(cc
->Nslots
* 3 + 1);
2497 MEMZERO(sdata
, cc
->Nslots
* 3 + 1);
2499 sdata
[0] = SAFTE_WT_DSTAT
;
2500 for (i
= 0; i
< cc
->Nslots
; i
++) {
2501 ep
= &ssc
->ses_objmap
[cc
->slotoff
+ i
];
2502 SES_DLOG(ssc
, "saf_wrslot %d <- %x\n", i
, ep
->priv
& 0xff);
2503 sdata
[1 + (3 * i
)] = ep
->priv
& 0xff;
2505 amt
= -(cc
->Nslots
* 3 + 1);
2506 ses_runcmd(ssc
, cdb
, 10, sdata
, &amt
);
2507 SES_FREE(sdata
, cc
->Nslots
* 3 + 1);
2511 * This function issues the "PERFORM SLOT OPERATION" command.
2514 perf_slotop(ses_softc_t
*ssc
, uint8_t slot
, uint8_t opflag
, int slp
)
2518 struct scfg
*cc
= ssc
->ses_private
;
2519 static char cdb
[10] =
2520 { WRITE_BUFFER
, 1, 0, 0, 0, 0, 0, 0, SAFT_SCRATCH
, 0 };
2525 sdata
= SES_MALLOC(SAFT_SCRATCH
);
2528 MEMZERO(sdata
, SAFT_SCRATCH
);
2530 sdata
[0] = SAFTE_WT_SLTOP
;
2533 SES_DLOG(ssc
, "saf_slotop slot %d op %x\n", slot
, opflag
);
2534 amt
= -SAFT_SCRATCH
;
2535 err
= ses_runcmd(ssc
, cdb
, 10, sdata
, &amt
);
2536 SES_FREE(sdata
, SAFT_SCRATCH
);