36#include <sys/kernel.h>
37#include <sys/malloc.h>
42#include <sys/sysctl.h>
59#define ALL_ENC_STAT (SES_ENCSTAT_CRITICAL | SES_ENCSTAT_UNRECOV | \
60 SES_ENCSTAT_NONCRITICAL | SES_ENCSTAT_INFO)
68#define SAFTE_RD_RDCFG 0x00
69#define SAFTE_RD_RDESTS 0x01
70#define SAFTE_RD_RDDSTS 0x04
71#define SAFTE_RD_RDGFLG 0x05
76#define SAFTE_WT_DSTAT 0x10
77#define SAFTE_WT_SLTOP 0x12
78#define SAFTE_WT_FANSPD 0x13
79#define SAFTE_WT_ACTPWS 0x14
80#define SAFTE_WT_GLOBAL 0x15
82#define SAFT_SCRATCH 64
105 {
"SAFTE_UPDATE_NONE", 0, 0, 0, NULL, NULL, NULL },
107 "SAFTE_UPDATE_READCONFIG",
116 "SAFTE_UPDATE_READGFLAGS",
125 "SAFTE_UPDATE_READENCSTATUS",
134 "SAFTE_UPDATE_READSLOTSTATUS",
143 "SAFTE_PROCESS_CONTROL_REQS",
170 while ((req = TAILQ_FIRST(reqlist)) != NULL) {
171 TAILQ_REMOVE(reqlist, req, links);
198#define SAFT_ALARM_OFFSET(cc) (cc)->slotoff - 1
210#define SAFT_FLG1_ALARM 0x1
211#define SAFT_FLG1_GLOBFAIL 0x2
212#define SAFT_FLG1_GLOBWARN 0x4
213#define SAFT_FLG1_ENCPWROFF 0x8
214#define SAFT_FLG1_ENCFANFAIL 0x10
215#define SAFT_FLG1_ENCPWRFAIL 0x20
216#define SAFT_FLG1_ENCDRVFAIL 0x40
217#define SAFT_FLG1_ENCDRVWARN 0x80
219#define SAFT_FLG2_LOCKDOOR 0x4
220#define SAFT_PRIVATE sizeof (struct scfg)
223#define SAFT_BAIL(r, x) \
225 ENC_VLOG(enc, safte_2little, x, __LINE__);\
235 union ccb *
ccb, uint8_t *buf)
260 union ccb *
ccb, uint8_t **bufp,
int error,
int xfer_len)
263 uint8_t *buf = *bufp;
272 ENC_VLOG(enc,
"too little data (%d) for configuration\n",
286 ENC_VLOG(enc,
"Nfans %d Npwr %d Nslots %d Lck %d Ntherm %d Nspkrs %d "
296 M_SCSIENC, M_WAITOK|M_ZERO);
303 for (i = 0; i < cfg->
Nfans; i++)
305 cfg->
pwroff = (uint8_t) r;
306 for (i = 0; i < cfg->
Npwr; i++)
312 for (i = 0; i < cfg->
Ntherm; i++)
314 for (i = 0; i <= cfg->
Ntstats; i++)
317 for (i = 0; i < cfg->
Nslots; i++)
331 union ccb *
ccb, uint8_t **bufp,
int error,
int xfer_len)
334 uint8_t *buf = *bufp;
356 union ccb *
ccb, uint8_t **bufp,
int error,
int xfer_len)
359 uint8_t *buf = *bufp;
360 int oid, r, i, nitems;
373 for (nitems = i = 0; i < cfg->
Nfans; i++) {
387 switch ((
int)buf[r]) {
435 ENC_VLOG(enc,
"Unknown fan%d status 0x%x\n", i,
447 if (cfg->
Nfans && nitems == 0)
450 for (i = 0; i < cfg->
Npwr; i++) {
495 ENC_VLOG(enc,
"unknown power supply %d status (0x%x)\n",
506 for (i = 0; i < cfg->
Nslots; i++) {
543 ENC_VLOG(enc,
"unknown lock status 0x%x\n",
579 tempflags = buf[r + cfg->
Ntherm];
581 tempflags |= (tempflags << 8) | buf[r + cfg->
Ntherm + 1];
583 for (i = 0; i < cfg->
Ntherm; i++) {
615 if (tempflags & (1 << i)) {
627 for (i = 0; i <= cfg->
Ntstats; i++) {
629 if (tempflags & (1 <<
665 union ccb *
ccb, uint8_t **bufp,
int error,
int xfer_len)
668 uint8_t *buf = *bufp;
679 for (r = i = 0; i < cfg->
Nslots; i++, r += 4) {
685 if ((buf[r+3] & 0x01) == 0) {
687 }
else if (buf[r+0] & 0x02) {
690 }
else if (buf[r+0] & 0x40) {
696 if (buf[r+3] & 0x2) {
702 if ((buf[r+3] & 0x04) == 0)
734 union ccb *
ccb, uint8_t *buf)
739 int i, idx, xfer_len;
804 for (i = 0; i < cfg->
Nslots; i++) {
806 buf[1 + (3 * i)] = ep1->
priv;
807 buf[2 + (3 * i)] = ep1->
priv >> 8;
809 xfer_len = cfg->
Nslots * 3 + 1;
810#define DEVON(x) (!(((x)[2] & SESCTL_RQSINS) | \
811 ((x)[2] & SESCTL_RQSRMV) | \
812 ((x)[3] & SESCTL_DEVOFF)))
834 ep->
encstat[2] &= ~SESCTL_RQSID;
851 cfg->
flag1 &= ~SAFT_FLG1_ENCPWRFAIL;
861 buf[1] = idx - cfg->
pwroff;
880 cfg->
flag1 &= ~SAFT_FLG1_ENCFANFAIL;
893 else if ((req->
elm_stat[3] & 0x7) >= 5)
895 else if ((req->
elm_stat[3] & 0x7) >= 3)
910 cfg->
flag2 &= ~SAFT_FLG2_LOCKDOOR;
922 cfg->
flag2 &= ~SAFT_FLG1_ALARM;
923 }
else if ((req->
elm_stat[3] & 0x0f) != 0) {
926 cfg->
flag2 &= ~SAFT_FLG1_ALARM;
943 buf, xfer_len, state->
timeout);
955 union ccb *
ccb, uint8_t **bufp,
int error,
int xfer_len)
1040 TAILQ_INSERT_TAIL(&cfg->
requests, &req, links);
1077 TAILQ_INSERT_TAIL(&cfg->
requests, &req, links);
void semb_write_buffer(struct ccb_ataio *ataio, u_int32_t retries, void(*cbfcnp)(struct cam_periph *, union ccb *), uint8_t tag_action, uint8_t *data_ptr, uint16_t length, uint32_t timeout)
void semb_read_buffer(struct ccb_ataio *ataio, u_int32_t retries, void(*cbfcnp)(struct cam_periph *, union ccb *), uint8_t tag_action, uint8_t page_code, uint8_t *data_ptr, uint16_t length, uint32_t timeout)
#define cam_periph_sleep(periph, chan, priority, wmesg, timo)
void scsi_read_buffer(struct ccb_scsiio *csio, u_int32_t retries, void(*cbfcnp)(struct cam_periph *, union ccb *), uint8_t tag_action, int mode, uint8_t buffer_id, u_int32_t offset, uint8_t *data_ptr, uint32_t allocation_length, uint8_t sense_len, uint32_t timeout)
void scsi_write_buffer(struct ccb_scsiio *csio, u_int32_t retries, void(*cbfcnp)(struct cam_periph *, union ccb *), uint8_t tag_action, int mode, uint8_t buffer_id, u_int32_t offset, uint8_t *data_ptr, uint32_t param_list_length, uint8_t sense_len, uint32_t timeout)
int enc_runcmd(struct enc_softc *enc, char *cdb, int cdbl, char *dptr, int *dlenp)
void enc_update_request(enc_softc_t *enc, uint32_t action)
Queue an update request for a given action, if needed.
int enc_error(union ccb *ccb, uint32_t cflags, uint32_t sflags)
unsigned char encioc_enc_status_t
int fsm_fill_handler_t(enc_softc_t *ssc, struct enc_fsm_state *state, union ccb *ccb, uint8_t *buf)
int fsm_done_handler_t(enc_softc_t *ssc, struct enc_fsm_state *state, union ccb *ccb, uint8_t **bufp, int error, int xfer_len)
#define ENC_FREE_AND_NULL(ptr)
static int safte_init_enc(enc_softc_t *enc)
@ SAFTE_NUM_UPDATE_STATES
@ SAFTE_UPDATE_READENCSTATUS
@ SAFTE_UPDATE_READSLOTSTATUS
@ SAFTE_UPDATE_READCONFIG
@ SAFTE_UPDATE_READGFLAGS
@ SAFTE_PROCESS_CONTROL_REQS
static struct enc_vec safte_enc_vec
int safte_softc_init(enc_softc_t *enc)
static fsm_done_handler_t safte_process_config
static fsm_fill_handler_t safte_fill_read_buf_io
struct safte_control_request safte_control_request_t
static fsm_done_handler_t safte_process_control_request
static int safte_set_enc_status(enc_softc_t *enc, uint8_t encstat, int slpflag)
#define SAFT_FLG1_GLOBWARN
static int safte_set_elm_status(enc_softc_t *enc, encioc_elm_status_t *elms, int slpflag)
static fsm_fill_handler_t safte_fill_control_request
static fsm_done_handler_t safte_process_status
static void safte_terminate_control_requests(safte_control_reqlist_t *reqlist, int result)
static int safte_get_elm_status(enc_softc_t *enc, encioc_elm_status_t *elms, int slpflg)
static void safte_softc_invalidate(enc_softc_t *enc)
#define SAFT_FLG2_LOCKDOOR
SYSCTL_INT(_kern_cam_enc, OID_AUTO, emulate_array_devices, CTLFLAG_RWTUN, &emulate_array_devices, 0, "Emulate Array Devices for SAF-TE")
static struct enc_fsm_state enc_fsm_states[SAFTE_NUM_UPDATE_STATES]
#define SAFT_FLG1_ENCPWRFAIL
static void safte_poll_status(enc_softc_t *enc)
struct safte_control_reqlist safte_control_reqlist_t
static fsm_done_handler_t safte_process_slotstatus
static fsm_done_handler_t safte_process_gflags
int emulate_array_devices
TAILQ_HEAD(safte_control_reqlist, safte_control_request)
static char * safte_2little
#define SAFT_FLG1_ENCFANFAIL
#define SAFT_FLG1_GLOBFAIL
static void safte_softc_cleanup(enc_softc_t *enc)
#define SES_ENCSTAT_UNRECOV
#define SES_ENCSTAT_CRITICAL
#define SES_OBJSTAT_UNKNOWN
#define SES_OBJSTAT_UNSUPPORTED
#define SES_OBJSTAT_NONCRIT
#define SES_OBJSTAT_NOTINSTALLED
#define SES_ENCSTAT_NONCRITICAL
#define SES_OBJSTAT_NOTAVAIL
encioc_enc_status_t enc_status
struct cam_periph * periph
struct enc_fsm_state * enc_fsm_states
enc_softc_invalidate_t * softc_invalidate
safte_control_reqlist_t requests
safte_control_request_t * current_request
encioc_enc_status_t adm_status
int current_request_stages
encioc_enc_status_t enc_status
int current_request_stage
encioc_enc_status_t slot_status