ses.c revision 1.8.2.2 1 1.8.2.2 bouyer /* $NetBSD: ses.c,v 1.8.2.2 2000/11/20 09:59:28 bouyer Exp $ */
2 1.8.2.2 bouyer /*
3 1.8.2.2 bouyer * Copyright (C) 2000 National Aeronautics & Space Administration
4 1.8.2.2 bouyer * All rights reserved.
5 1.8.2.2 bouyer *
6 1.8.2.2 bouyer * Redistribution and use in source and binary forms, with or without
7 1.8.2.2 bouyer * modification, are permitted provided that the following conditions
8 1.8.2.2 bouyer * are met:
9 1.8.2.2 bouyer * 1. Redistributions of source code must retain the above copyright
10 1.8.2.2 bouyer * notice, this list of conditions and the following disclaimer.
11 1.8.2.2 bouyer * 2. The name of the author may not be used to endorse or promote products
12 1.8.2.2 bouyer * derived from this software without specific prior written permission
13 1.8.2.2 bouyer *
14 1.8.2.2 bouyer * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
15 1.8.2.2 bouyer * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
16 1.8.2.2 bouyer * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
17 1.8.2.2 bouyer * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
18 1.8.2.2 bouyer * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
19 1.8.2.2 bouyer * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
20 1.8.2.2 bouyer * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
21 1.8.2.2 bouyer * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22 1.8.2.2 bouyer * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
23 1.8.2.2 bouyer * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24 1.8.2.2 bouyer *
25 1.8.2.2 bouyer * Author: mjacob (at) nas.nasa.gov
26 1.8.2.2 bouyer */
27 1.8.2.2 bouyer
28 1.8.2.2 bouyer
29 1.8.2.2 bouyer #include "opt_scsi.h"
30 1.8.2.2 bouyer
31 1.8.2.2 bouyer #include <sys/types.h>
32 1.8.2.2 bouyer #include <sys/param.h>
33 1.8.2.2 bouyer #include <sys/systm.h>
34 1.8.2.2 bouyer #include <sys/kernel.h>
35 1.8.2.2 bouyer #include <sys/file.h>
36 1.8.2.2 bouyer #include <sys/stat.h>
37 1.8.2.2 bouyer #include <sys/ioctl.h>
38 1.8.2.2 bouyer #include <sys/scsiio.h>
39 1.8.2.2 bouyer #include <sys/buf.h>
40 1.8.2.2 bouyer #include <sys/uio.h>
41 1.8.2.2 bouyer #include <sys/malloc.h>
42 1.8.2.2 bouyer #include <sys/errno.h>
43 1.8.2.2 bouyer #include <sys/device.h>
44 1.8.2.2 bouyer #include <sys/disklabel.h>
45 1.8.2.2 bouyer #include <sys/disk.h>
46 1.8.2.2 bouyer #include <sys/proc.h>
47 1.8.2.2 bouyer #include <sys/conf.h>
48 1.8.2.2 bouyer #include <sys/vnode.h>
49 1.8.2.2 bouyer #include <machine/stdarg.h>
50 1.8.2.2 bouyer
51 1.8.2.2 bouyer #include <dev/scsipi/scsipi_all.h>
52 1.8.2.2 bouyer #include <dev/scsipi/scsi_all.h>
53 1.8.2.2 bouyer #include <dev/scsipi/scsipi_disk.h>
54 1.8.2.2 bouyer #include <dev/scsipi/scsi_disk.h>
55 1.8.2.2 bouyer #include <dev/scsipi/scsiconf.h>
56 1.8.2.2 bouyer #include <dev/scsipi/ses.h>
57 1.8.2.2 bouyer
58 1.8.2.2 bouyer /*
59 1.8.2.2 bouyer * Platform Independent Driver Internal Definitions for SES devices.
60 1.8.2.2 bouyer */
61 1.8.2.2 bouyer typedef enum {
62 1.8.2.2 bouyer SES_NONE,
63 1.8.2.2 bouyer SES_SES_SCSI2,
64 1.8.2.2 bouyer SES_SES,
65 1.8.2.2 bouyer SES_SES_PASSTHROUGH,
66 1.8.2.2 bouyer SES_SEN,
67 1.8.2.2 bouyer SES_SAFT
68 1.8.2.2 bouyer } enctyp;
69 1.8.2.2 bouyer
70 1.8.2.2 bouyer struct ses_softc;
71 1.8.2.2 bouyer typedef struct ses_softc ses_softc_t;
72 1.8.2.2 bouyer typedef struct {
73 1.8.2.2 bouyer int (*softc_init) __P((ses_softc_t *, int));
74 1.8.2.2 bouyer int (*init_enc) __P((ses_softc_t *));
75 1.8.2.2 bouyer int (*get_encstat) __P((ses_softc_t *, int));
76 1.8.2.2 bouyer int (*set_encstat) __P((ses_softc_t *, ses_encstat, int));
77 1.8.2.2 bouyer int (*get_objstat) __P((ses_softc_t *, ses_objstat *, int));
78 1.8.2.2 bouyer int (*set_objstat) __P((ses_softc_t *, ses_objstat *, int));
79 1.8.2.2 bouyer } encvec;
80 1.8.2.2 bouyer
81 1.8.2.2 bouyer #define ENCI_SVALID 0x80
82 1.8.2.2 bouyer
83 1.8.2.2 bouyer typedef struct {
84 1.8.2.2 bouyer uint32_t
85 1.8.2.2 bouyer enctype : 8, /* enclosure type */
86 1.8.2.2 bouyer subenclosure : 8, /* subenclosure id */
87 1.8.2.2 bouyer svalid : 1, /* enclosure information valid */
88 1.8.2.2 bouyer priv : 15; /* private data, per object */
89 1.8.2.2 bouyer uint8_t encstat[4]; /* state && stats */
90 1.8.2.2 bouyer } encobj;
91 1.8.2.2 bouyer
92 1.8.2.2 bouyer #define SEN_ID "UNISYS SUN_SEN"
93 1.8.2.2 bouyer #define SEN_ID_LEN 24
94 1.8.2.2 bouyer
95 1.8.2.2 bouyer static enctyp ses_type __P((struct scsipi_inquiry_data *));
96 1.8.2.2 bouyer
97 1.8.2.2 bouyer
98 1.8.2.2 bouyer /* Forward reference to Enclosure Functions */
99 1.8.2.2 bouyer static int ses_softc_init __P((ses_softc_t *, int));
100 1.8.2.2 bouyer static int ses_init_enc __P((ses_softc_t *));
101 1.8.2.2 bouyer static int ses_get_encstat __P((ses_softc_t *, int));
102 1.8.2.2 bouyer static int ses_set_encstat __P((ses_softc_t *, uint8_t, int));
103 1.8.2.2 bouyer static int ses_get_objstat __P((ses_softc_t *, ses_objstat *, int));
104 1.8.2.2 bouyer static int ses_set_objstat __P((ses_softc_t *, ses_objstat *, int));
105 1.8.2.2 bouyer
106 1.8.2.2 bouyer static int safte_softc_init __P((ses_softc_t *, int));
107 1.8.2.2 bouyer static int safte_init_enc __P((ses_softc_t *));
108 1.8.2.2 bouyer static int safte_get_encstat __P((ses_softc_t *, int));
109 1.8.2.2 bouyer static int safte_set_encstat __P((ses_softc_t *, uint8_t, int));
110 1.8.2.2 bouyer static int safte_get_objstat __P((ses_softc_t *, ses_objstat *, int));
111 1.8.2.2 bouyer static int safte_set_objstat __P((ses_softc_t *, ses_objstat *, int));
112 1.8.2.2 bouyer
113 1.8.2.2 bouyer /*
114 1.8.2.2 bouyer * Platform implementation defines/functions for SES internal kernel stuff
115 1.8.2.2 bouyer */
116 1.8.2.2 bouyer
117 1.8.2.2 bouyer #define STRNCMP strncmp
118 1.8.2.2 bouyer #define PRINTF printf
119 1.8.2.2 bouyer #define SES_LOG ses_log
120 1.8.2.2 bouyer #if defined(DEBUG) || defined(SCSIDEBUG)
121 1.8.2.2 bouyer #define SES_VLOG ses_log
122 1.8.2.2 bouyer #else
123 1.8.2.2 bouyer #define SES_VLOG if (0) ses_log
124 1.8.2.2 bouyer #endif
125 1.8.2.2 bouyer #define SES_MALLOC(amt) malloc(amt, M_DEVBUF, M_NOWAIT)
126 1.8.2.2 bouyer #define SES_FREE(ptr, amt) free(ptr, M_DEVBUF)
127 1.8.2.2 bouyer #define MEMZERO bzero
128 1.8.2.2 bouyer #define MEMCPY(dest, src, amt) bcopy(src, dest, amt)
129 1.8.2.2 bouyer #define RECEIVE_DIAGNOSTIC 0x1c
130 1.8.2.2 bouyer #define SEND_DIAGNOSTIC 0x1d
131 1.8.2.2 bouyer #define WRITE_BUFFER 0x3b
132 1.8.2.2 bouyer #define READ_BUFFER 0x3c
133 1.8.2.2 bouyer
134 1.8.2.2 bouyer int sesopen __P((dev_t, int, int, struct proc *));
135 1.8.2.2 bouyer int sesclose __P((dev_t, int, int, struct proc *));
136 1.8.2.2 bouyer int sesioctl __P((dev_t, u_long, caddr_t, int, struct proc *));
137 1.8.2.2 bouyer
138 1.8.2.2 bouyer static int ses_runcmd __P((struct ses_softc *, char *, int, char *, int *));
139 1.8.2.2 bouyer static void ses_log __P((struct ses_softc *, const char *, ...))
140 1.8.2.2 bouyer __attribute__((__format__(__printf__, 2, 3)));
141 1.8.2.2 bouyer
142 1.8.2.2 bouyer /*
143 1.8.2.2 bouyer * General NetBSD kernel stuff.
144 1.8.2.2 bouyer */
145 1.8.2.2 bouyer
146 1.8.2.2 bouyer struct ses_softc {
147 1.8.2.2 bouyer struct device sc_device;
148 1.8.2.2 bouyer struct scsipi_periph *sc_periph;
149 1.8.2.2 bouyer enctyp ses_type; /* type of enclosure */
150 1.8.2.2 bouyer encvec ses_vec; /* vector to handlers */
151 1.8.2.2 bouyer void * ses_private; /* per-type private data */
152 1.8.2.2 bouyer encobj * ses_objmap; /* objects */
153 1.8.2.2 bouyer u_int32_t ses_nobjects; /* number of objects */
154 1.8.2.2 bouyer ses_encstat ses_encstat; /* overall status */
155 1.8.2.2 bouyer u_int8_t ses_flags;
156 1.8.2.2 bouyer };
157 1.8.2.2 bouyer #define SES_FLAG_INVALID 0x01
158 1.8.2.2 bouyer #define SES_FLAG_OPEN 0x02
159 1.8.2.2 bouyer #define SES_FLAG_INITIALIZED 0x04
160 1.8.2.2 bouyer
161 1.8.2.2 bouyer #define SESUNIT(x) (minor((x)))
162 1.8.2.2 bouyer
163 1.8.2.2 bouyer static int ses_match __P((struct device *, struct cfdata *, void *));
164 1.8.2.2 bouyer static void ses_attach __P((struct device *, struct device *, void *));
165 1.8.2.2 bouyer static enctyp ses_device_type __P((struct scsipibus_attach_args *));
166 1.8.2.2 bouyer
167 1.8.2.2 bouyer struct cfattach ses_ca = {
168 1.8.2.2 bouyer sizeof (struct ses_softc), ses_match, ses_attach
169 1.8.2.2 bouyer };
170 1.8.2.2 bouyer extern struct cfdriver ses_cd;
171 1.8.2.2 bouyer
172 1.8.2.2 bouyer const struct scsipi_periphsw ses_switch = {
173 1.8.2.2 bouyer NULL,
174 1.8.2.2 bouyer NULL,
175 1.8.2.2 bouyer NULL,
176 1.8.2.2 bouyer NULL
177 1.8.2.2 bouyer };
178 1.8.2.2 bouyer
179 1.8.2.2 bouyer
180 1.8.2.2 bouyer int
181 1.8.2.2 bouyer ses_match(parent, match, aux)
182 1.8.2.2 bouyer struct device *parent;
183 1.8.2.2 bouyer struct cfdata *match;
184 1.8.2.2 bouyer void *aux;
185 1.8.2.2 bouyer {
186 1.8.2.2 bouyer struct scsipibus_attach_args *sa = aux;
187 1.8.2.2 bouyer
188 1.8.2.2 bouyer switch (ses_device_type(sa)) {
189 1.8.2.2 bouyer case SES_SES:
190 1.8.2.2 bouyer case SES_SES_SCSI2:
191 1.8.2.2 bouyer case SES_SEN:
192 1.8.2.2 bouyer case SES_SAFT:
193 1.8.2.2 bouyer case SES_SES_PASSTHROUGH:
194 1.8.2.2 bouyer /*
195 1.8.2.2 bouyer * For these devices, it's a perfect match.
196 1.8.2.2 bouyer */
197 1.8.2.2 bouyer return (24);
198 1.8.2.2 bouyer default:
199 1.8.2.2 bouyer return (0);
200 1.8.2.2 bouyer }
201 1.8.2.2 bouyer }
202 1.8.2.2 bouyer
203 1.8.2.2 bouyer
204 1.8.2.2 bouyer /*
205 1.8.2.2 bouyer * Complete the attachment.
206 1.8.2.2 bouyer *
207 1.8.2.2 bouyer * We have to repeat the rerun of INQUIRY data as above because
208 1.8.2.2 bouyer * it's not until the return from the match routine that we have
209 1.8.2.2 bouyer * the softc available to set stuff in.
210 1.8.2.2 bouyer */
211 1.8.2.2 bouyer void
212 1.8.2.2 bouyer ses_attach(parent, self, aux)
213 1.8.2.2 bouyer struct device *parent;
214 1.8.2.2 bouyer struct device *self;
215 1.8.2.2 bouyer void *aux;
216 1.8.2.2 bouyer {
217 1.8.2.2 bouyer char *tname;
218 1.8.2.2 bouyer struct ses_softc *softc = (void *)self;
219 1.8.2.2 bouyer struct scsipibus_attach_args *sa = aux;
220 1.8.2.2 bouyer struct scsipi_periph *periph = sa->sa_periph;
221 1.8.2.2 bouyer
222 1.8.2.2 bouyer SC_DEBUG(periph, SCSIPI_DB2, ("ssattach: "));
223 1.8.2.2 bouyer softc->sc_periph = periph;
224 1.8.2.2 bouyer periph->periph_dev = &softc->sc_device;
225 1.8.2.2 bouyer periph->periph_switch = &ses_switch;
226 1.8.2.2 bouyer periph->periph_openings = 1;
227 1.8.2.2 bouyer
228 1.8.2.2 bouyer softc->ses_type = ses_device_type(sa);
229 1.8.2.2 bouyer switch (softc->ses_type) {
230 1.8.2.2 bouyer case SES_SES:
231 1.8.2.2 bouyer case SES_SES_SCSI2:
232 1.8.2.2 bouyer case SES_SES_PASSTHROUGH:
233 1.8.2.2 bouyer softc->ses_vec.softc_init = ses_softc_init;
234 1.8.2.2 bouyer softc->ses_vec.init_enc = ses_init_enc;
235 1.8.2.2 bouyer softc->ses_vec.get_encstat = ses_get_encstat;
236 1.8.2.2 bouyer softc->ses_vec.set_encstat = ses_set_encstat;
237 1.8.2.2 bouyer softc->ses_vec.get_objstat = ses_get_objstat;
238 1.8.2.2 bouyer softc->ses_vec.set_objstat = ses_set_objstat;
239 1.8.2.2 bouyer break;
240 1.8.2.2 bouyer case SES_SAFT:
241 1.8.2.2 bouyer softc->ses_vec.softc_init = safte_softc_init;
242 1.8.2.2 bouyer softc->ses_vec.init_enc = safte_init_enc;
243 1.8.2.2 bouyer softc->ses_vec.get_encstat = safte_get_encstat;
244 1.8.2.2 bouyer softc->ses_vec.set_encstat = safte_set_encstat;
245 1.8.2.2 bouyer softc->ses_vec.get_objstat = safte_get_objstat;
246 1.8.2.2 bouyer softc->ses_vec.set_objstat = safte_set_objstat;
247 1.8.2.2 bouyer break;
248 1.8.2.2 bouyer case SES_SEN:
249 1.8.2.2 bouyer break;
250 1.8.2.2 bouyer case SES_NONE:
251 1.8.2.2 bouyer default:
252 1.8.2.2 bouyer break;
253 1.8.2.2 bouyer }
254 1.8.2.2 bouyer
255 1.8.2.2 bouyer switch (softc->ses_type) {
256 1.8.2.2 bouyer default:
257 1.8.2.2 bouyer case SES_NONE:
258 1.8.2.2 bouyer tname = "No SES device";
259 1.8.2.2 bouyer break;
260 1.8.2.2 bouyer case SES_SES_SCSI2:
261 1.8.2.2 bouyer tname = "SCSI-2 SES Device";
262 1.8.2.2 bouyer break;
263 1.8.2.2 bouyer case SES_SES:
264 1.8.2.2 bouyer tname = "SCSI-3 SES Device";
265 1.8.2.2 bouyer break;
266 1.8.2.2 bouyer case SES_SES_PASSTHROUGH:
267 1.8.2.2 bouyer tname = "SES Passthrough Device";
268 1.8.2.2 bouyer break;
269 1.8.2.2 bouyer case SES_SEN:
270 1.8.2.2 bouyer tname = "UNISYS SEN Device (NOT HANDLED YET)";
271 1.8.2.2 bouyer break;
272 1.8.2.2 bouyer case SES_SAFT:
273 1.8.2.2 bouyer tname = "SAF-TE Compliant Device";
274 1.8.2.2 bouyer break;
275 1.8.2.2 bouyer }
276 1.8.2.2 bouyer printf("\n%s: %s\n", softc->sc_device.dv_xname, tname);
277 1.8.2.2 bouyer }
278 1.8.2.2 bouyer
279 1.8.2.2 bouyer
280 1.8.2.2 bouyer static enctyp
281 1.8.2.2 bouyer ses_device_type(sa)
282 1.8.2.2 bouyer struct scsipibus_attach_args *sa;
283 1.8.2.2 bouyer {
284 1.8.2.2 bouyer struct scsipi_inquiry_data *inqp = sa->sa_inqptr;
285 1.8.2.2 bouyer
286 1.8.2.2 bouyer if (inqp == NULL)
287 1.8.2.2 bouyer return (SES_NONE);
288 1.8.2.2 bouyer
289 1.8.2.2 bouyer return (ses_type(inqp));
290 1.8.2.2 bouyer }
291 1.8.2.2 bouyer
292 1.8.2.2 bouyer int
293 1.8.2.2 bouyer sesopen(dev, flags, fmt, p)
294 1.8.2.2 bouyer dev_t dev;
295 1.8.2.2 bouyer int flags;
296 1.8.2.2 bouyer int fmt;
297 1.8.2.2 bouyer struct proc *p;
298 1.8.2.2 bouyer {
299 1.8.2.2 bouyer struct ses_softc *softc;
300 1.8.2.2 bouyer int error, unit;
301 1.8.2.2 bouyer
302 1.8.2.2 bouyer unit = SESUNIT(dev);
303 1.8.2.2 bouyer if (unit >= ses_cd.cd_ndevs)
304 1.8.2.2 bouyer return (ENXIO);
305 1.8.2.2 bouyer softc = ses_cd.cd_devs[unit];
306 1.8.2.2 bouyer if (softc == NULL)
307 1.8.2.2 bouyer return (ENXIO);
308 1.8.2.2 bouyer
309 1.8.2.2 bouyer if (softc->ses_flags & SES_FLAG_INVALID) {
310 1.8.2.2 bouyer error = ENXIO;
311 1.8.2.2 bouyer goto out;
312 1.8.2.2 bouyer }
313 1.8.2.2 bouyer if (softc->ses_flags & SES_FLAG_OPEN) {
314 1.8.2.2 bouyer error = EBUSY;
315 1.8.2.2 bouyer goto out;
316 1.8.2.2 bouyer }
317 1.8.2.2 bouyer if (softc->ses_vec.softc_init == NULL) {
318 1.8.2.2 bouyer error = ENXIO;
319 1.8.2.2 bouyer goto out;
320 1.8.2.2 bouyer }
321 1.8.2.2 bouyer error = scsipi_adapter_addref(
322 1.8.2.2 bouyer softc->sc_periph->periph_channel->chan_adapter);
323 1.8.2.2 bouyer if (error != 0)
324 1.8.2.2 bouyer goto out;
325 1.8.2.2 bouyer
326 1.8.2.2 bouyer
327 1.8.2.2 bouyer softc->ses_flags |= SES_FLAG_OPEN;
328 1.8.2.2 bouyer if ((softc->ses_flags & SES_FLAG_INITIALIZED) == 0) {
329 1.8.2.2 bouyer error = (*softc->ses_vec.softc_init)(softc, 1);
330 1.8.2.2 bouyer if (error)
331 1.8.2.2 bouyer softc->ses_flags &= ~SES_FLAG_OPEN;
332 1.8.2.2 bouyer else
333 1.8.2.2 bouyer softc->ses_flags |= SES_FLAG_INITIALIZED;
334 1.8.2.2 bouyer }
335 1.8.2.2 bouyer
336 1.8.2.2 bouyer out:
337 1.8.2.2 bouyer return (error);
338 1.8.2.2 bouyer }
339 1.8.2.2 bouyer
340 1.8.2.2 bouyer int
341 1.8.2.2 bouyer sesclose(dev, flags, fmt, p)
342 1.8.2.2 bouyer dev_t dev;
343 1.8.2.2 bouyer int flags;
344 1.8.2.2 bouyer int fmt;
345 1.8.2.2 bouyer struct proc *p;
346 1.8.2.2 bouyer {
347 1.8.2.2 bouyer struct ses_softc *softc;
348 1.8.2.2 bouyer int unit;
349 1.8.2.2 bouyer
350 1.8.2.2 bouyer unit = SESUNIT(dev);
351 1.8.2.2 bouyer if (unit >= ses_cd.cd_ndevs)
352 1.8.2.2 bouyer return (ENXIO);
353 1.8.2.2 bouyer softc = ses_cd.cd_devs[unit];
354 1.8.2.2 bouyer if (softc == NULL)
355 1.8.2.2 bouyer return (ENXIO);
356 1.8.2.2 bouyer
357 1.8.2.2 bouyer scsipi_wait_drain(softc->sc_periph);
358 1.8.2.2 bouyer scsipi_adapter_delref(softc->sc_periph->periph_channel->chan_adapter);
359 1.8.2.2 bouyer softc->ses_flags &= ~SES_FLAG_OPEN;
360 1.8.2.2 bouyer return (0);
361 1.8.2.2 bouyer }
362 1.8.2.2 bouyer
363 1.8.2.2 bouyer int
364 1.8.2.2 bouyer sesioctl(dev, cmd, arg_addr, flag, p)
365 1.8.2.2 bouyer dev_t dev;
366 1.8.2.2 bouyer u_long cmd;
367 1.8.2.2 bouyer caddr_t arg_addr;
368 1.8.2.2 bouyer int flag;
369 1.8.2.2 bouyer struct proc *p;
370 1.8.2.2 bouyer {
371 1.8.2.2 bouyer ses_encstat tmp;
372 1.8.2.2 bouyer ses_objstat objs;
373 1.8.2.2 bouyer ses_object obj, *uobj;
374 1.8.2.2 bouyer struct ses_softc *ssc = ses_cd.cd_devs[SESUNIT(dev)];
375 1.8.2.2 bouyer void *addr;
376 1.8.2.2 bouyer int error, i;
377 1.8.2.2 bouyer
378 1.8.2.2 bouyer
379 1.8.2.2 bouyer if (arg_addr)
380 1.8.2.2 bouyer addr = *((caddr_t *) arg_addr);
381 1.8.2.2 bouyer else
382 1.8.2.2 bouyer addr = NULL;
383 1.8.2.2 bouyer
384 1.8.2.2 bouyer SC_DEBUG(ssc->sc_periph, SCSIPI_DB2, ("sesioctl 0x%lx ", cmd));
385 1.8.2.2 bouyer
386 1.8.2.2 bouyer /*
387 1.8.2.2 bouyer * Now check to see whether we're initialized or not.
388 1.8.2.2 bouyer */
389 1.8.2.2 bouyer if ((ssc->ses_flags & SES_FLAG_INITIALIZED) == 0) {
390 1.8.2.2 bouyer return (ENODEV);
391 1.8.2.2 bouyer }
392 1.8.2.2 bouyer
393 1.8.2.2 bouyer error = 0;
394 1.8.2.2 bouyer
395 1.8.2.2 bouyer /*
396 1.8.2.2 bouyer * If this command can change the device's state,
397 1.8.2.2 bouyer * we must have the device open for writing.
398 1.8.2.2 bouyer */
399 1.8.2.2 bouyer switch (cmd) {
400 1.8.2.2 bouyer case SESIOC_GETNOBJ:
401 1.8.2.2 bouyer case SESIOC_GETOBJMAP:
402 1.8.2.2 bouyer case SESIOC_GETENCSTAT:
403 1.8.2.2 bouyer case SESIOC_GETOBJSTAT:
404 1.8.2.2 bouyer break;
405 1.8.2.2 bouyer default:
406 1.8.2.2 bouyer if ((flag & FWRITE) == 0) {
407 1.8.2.2 bouyer return (EBADF);
408 1.8.2.2 bouyer }
409 1.8.2.2 bouyer }
410 1.8.2.2 bouyer
411 1.8.2.2 bouyer switch (cmd) {
412 1.8.2.2 bouyer case SESIOC_GETNOBJ:
413 1.8.2.2 bouyer error = copyout(&ssc->ses_nobjects, addr,
414 1.8.2.2 bouyer sizeof (ssc->ses_nobjects));
415 1.8.2.2 bouyer break;
416 1.8.2.2 bouyer
417 1.8.2.2 bouyer case SESIOC_GETOBJMAP:
418 1.8.2.2 bouyer for (uobj = addr, i = 0; i != ssc->ses_nobjects; i++, uobj++) {
419 1.8.2.2 bouyer obj.obj_id = i;
420 1.8.2.2 bouyer obj.subencid = ssc->ses_objmap[i].subenclosure;
421 1.8.2.2 bouyer obj.object_type = ssc->ses_objmap[i].enctype;
422 1.8.2.2 bouyer error = copyout(&obj, uobj, sizeof (ses_object));
423 1.8.2.2 bouyer if (error) {
424 1.8.2.2 bouyer break;
425 1.8.2.2 bouyer }
426 1.8.2.2 bouyer }
427 1.8.2.2 bouyer break;
428 1.8.2.2 bouyer
429 1.8.2.2 bouyer case SESIOC_GETENCSTAT:
430 1.8.2.2 bouyer error = (*ssc->ses_vec.get_encstat)(ssc, 1);
431 1.8.2.2 bouyer if (error)
432 1.8.2.2 bouyer break;
433 1.8.2.2 bouyer tmp = ssc->ses_encstat & ~ENCI_SVALID;
434 1.8.2.2 bouyer error = copyout(&tmp, addr, sizeof (ses_encstat));
435 1.8.2.2 bouyer ssc->ses_encstat = tmp;
436 1.8.2.2 bouyer break;
437 1.8.2.2 bouyer
438 1.8.2.2 bouyer case SESIOC_SETENCSTAT:
439 1.8.2.2 bouyer error = copyin(addr, &tmp, sizeof (ses_encstat));
440 1.8.2.2 bouyer if (error)
441 1.8.2.2 bouyer break;
442 1.8.2.2 bouyer error = (*ssc->ses_vec.set_encstat)(ssc, tmp, 1);
443 1.8.2.2 bouyer break;
444 1.8.2.2 bouyer
445 1.8.2.2 bouyer case SESIOC_GETOBJSTAT:
446 1.8.2.2 bouyer error = copyin(addr, &objs, sizeof (ses_objstat));
447 1.8.2.2 bouyer if (error)
448 1.8.2.2 bouyer break;
449 1.8.2.2 bouyer if (objs.obj_id >= ssc->ses_nobjects) {
450 1.8.2.2 bouyer error = EINVAL;
451 1.8.2.2 bouyer break;
452 1.8.2.2 bouyer }
453 1.8.2.2 bouyer error = (*ssc->ses_vec.get_objstat)(ssc, &objs, 1);
454 1.8.2.2 bouyer if (error)
455 1.8.2.2 bouyer break;
456 1.8.2.2 bouyer error = copyout(&objs, addr, sizeof (ses_objstat));
457 1.8.2.2 bouyer /*
458 1.8.2.2 bouyer * Always (for now) invalidate entry.
459 1.8.2.2 bouyer */
460 1.8.2.2 bouyer ssc->ses_objmap[objs.obj_id].svalid = 0;
461 1.8.2.2 bouyer break;
462 1.8.2.2 bouyer
463 1.8.2.2 bouyer case SESIOC_SETOBJSTAT:
464 1.8.2.2 bouyer error = copyin(addr, &objs, sizeof (ses_objstat));
465 1.8.2.2 bouyer if (error)
466 1.8.2.2 bouyer break;
467 1.8.2.2 bouyer
468 1.8.2.2 bouyer if (objs.obj_id >= ssc->ses_nobjects) {
469 1.8.2.2 bouyer error = EINVAL;
470 1.8.2.2 bouyer break;
471 1.8.2.2 bouyer }
472 1.8.2.2 bouyer error = (*ssc->ses_vec.set_objstat)(ssc, &objs, 1);
473 1.8.2.2 bouyer
474 1.8.2.2 bouyer /*
475 1.8.2.2 bouyer * Always (for now) invalidate entry.
476 1.8.2.2 bouyer */
477 1.8.2.2 bouyer ssc->ses_objmap[objs.obj_id].svalid = 0;
478 1.8.2.2 bouyer break;
479 1.8.2.2 bouyer
480 1.8.2.2 bouyer case SESIOC_INIT:
481 1.8.2.2 bouyer
482 1.8.2.2 bouyer error = (*ssc->ses_vec.init_enc)(ssc);
483 1.8.2.2 bouyer break;
484 1.8.2.2 bouyer
485 1.8.2.2 bouyer default:
486 1.8.2.2 bouyer error = scsipi_do_ioctl(ssc->sc_periph,
487 1.8.2.2 bouyer dev, cmd, addr, flag, p);
488 1.8.2.2 bouyer break;
489 1.8.2.2 bouyer }
490 1.8.2.2 bouyer return (error);
491 1.8.2.2 bouyer }
492 1.8.2.2 bouyer
493 1.8.2.2 bouyer static int
494 1.8.2.2 bouyer ses_runcmd(struct ses_softc *ssc, char *cdb, int cdbl, char *dptr, int *dlenp)
495 1.8.2.2 bouyer {
496 1.8.2.2 bouyer struct scsipi_generic sgen;
497 1.8.2.2 bouyer int dl, flg, error;
498 1.8.2.2 bouyer
499 1.8.2.2 bouyer if (dptr) {
500 1.8.2.2 bouyer if ((dl = *dlenp) < 0) {
501 1.8.2.2 bouyer dl = -dl;
502 1.8.2.2 bouyer flg = XS_CTL_DATA_OUT;
503 1.8.2.2 bouyer } else {
504 1.8.2.2 bouyer flg = XS_CTL_DATA_IN;
505 1.8.2.2 bouyer }
506 1.8.2.2 bouyer } else {
507 1.8.2.2 bouyer dl = 0;
508 1.8.2.2 bouyer flg = 0;
509 1.8.2.2 bouyer }
510 1.8.2.2 bouyer
511 1.8.2.2 bouyer if (cdbl > sizeof (struct scsipi_generic)) {
512 1.8.2.2 bouyer cdbl = sizeof (struct scsipi_generic);
513 1.8.2.2 bouyer }
514 1.8.2.2 bouyer bcopy(cdb, &sgen, cdbl);
515 1.8.2.2 bouyer #ifndef SCSIDEBUG
516 1.8.2.2 bouyer flg |= XS_CTL_SILENT;
517 1.8.2.2 bouyer #endif
518 1.8.2.2 bouyer error = scsipi_command(ssc->sc_periph, &sgen, cdbl,
519 1.8.2.2 bouyer (u_char *) dptr, dl, SCSIPIRETRIES, 30000, NULL, flg);
520 1.8.2.2 bouyer
521 1.8.2.2 bouyer if (error == 0 && dptr)
522 1.8.2.2 bouyer *dlenp = 0;
523 1.8.2.2 bouyer
524 1.8.2.2 bouyer return (error);
525 1.8.2.2 bouyer }
526 1.8.2.2 bouyer
527 1.8.2.2 bouyer #ifdef __STDC__
528 1.8.2.2 bouyer static void
529 1.8.2.2 bouyer ses_log(struct ses_softc *ssc, const char *fmt, ...)
530 1.8.2.2 bouyer {
531 1.8.2.2 bouyer va_list ap;
532 1.8.2.2 bouyer
533 1.8.2.2 bouyer printf("%s: ", ssc->sc_device.dv_xname);
534 1.8.2.2 bouyer va_start(ap, fmt);
535 1.8.2.2 bouyer vprintf(fmt, ap);
536 1.8.2.2 bouyer va_end(ap);
537 1.8.2.2 bouyer }
538 1.8.2.2 bouyer #else
539 1.8.2.2 bouyer static void
540 1.8.2.2 bouyer ses_log(ssc, fmt, va_alist)
541 1.8.2.2 bouyer struct ses_softc *ssc;
542 1.8.2.2 bouyer char *fmt;
543 1.8.2.2 bouyer va_dcl
544 1.8.2.2 bouyer {
545 1.8.2.2 bouyer va_list ap;
546 1.8.2.2 bouyer
547 1.8.2.2 bouyer printf("%s: ", ssc->sc_device.dv_xname);
548 1.8.2.2 bouyer va_start(ap, fmt);
549 1.8.2.2 bouyer vprintf(fmt, ap);
550 1.8.2.2 bouyer va_end(ap);
551 1.8.2.2 bouyer }
552 1.8.2.2 bouyer #endif
553 1.8.2.2 bouyer
554 1.8.2.2 bouyer /*
555 1.8.2.2 bouyer * The code after this point runs on many platforms,
556 1.8.2.2 bouyer * so forgive the slightly awkward and nonconforming
557 1.8.2.2 bouyer * appearance.
558 1.8.2.2 bouyer */
559 1.8.2.2 bouyer
560 1.8.2.2 bouyer /*
561 1.8.2.2 bouyer * Is this a device that supports enclosure services?
562 1.8.2.2 bouyer *
563 1.8.2.2 bouyer * It's a a pretty simple ruleset- if it is device type 0x0D (13), it's
564 1.8.2.2 bouyer * an SES device. If it happens to be an old UNISYS SEN device, we can
565 1.8.2.2 bouyer * handle that too.
566 1.8.2.2 bouyer */
567 1.8.2.2 bouyer
568 1.8.2.2 bouyer #define SAFTE_START 44
569 1.8.2.2 bouyer #define SAFTE_END 50
570 1.8.2.2 bouyer #define SAFTE_LEN SAFTE_END-SAFTE_START
571 1.8.2.2 bouyer
572 1.8.2.2 bouyer static enctyp
573 1.8.2.2 bouyer ses_type(inqp)
574 1.8.2.2 bouyer struct scsipi_inquiry_data *inqp;
575 1.8.2.2 bouyer {
576 1.8.2.2 bouyer size_t given_len = inqp->additional_length + 4;
577 1.8.2.2 bouyer
578 1.8.2.2 bouyer if (given_len < 8+SEN_ID_LEN)
579 1.8.2.2 bouyer return (SES_NONE);
580 1.8.2.2 bouyer
581 1.8.2.2 bouyer if ((inqp->device & SID_TYPE) == T_ENCLOSURE) {
582 1.8.2.2 bouyer if (STRNCMP(inqp->vendor, SEN_ID, SEN_ID_LEN) == 0) {
583 1.8.2.2 bouyer return (SES_SEN);
584 1.8.2.2 bouyer } else if ((inqp->version & SID_ANSII) > 2) {
585 1.8.2.2 bouyer return (SES_SES);
586 1.8.2.2 bouyer } else {
587 1.8.2.2 bouyer return (SES_SES_SCSI2);
588 1.8.2.2 bouyer }
589 1.8.2.2 bouyer return (SES_NONE);
590 1.8.2.2 bouyer }
591 1.8.2.2 bouyer
592 1.8.2.2 bouyer #ifdef SES_ENABLE_PASSTHROUGH
593 1.8.2.2 bouyer if ((inqp->flags2 & SID_EncServ) && (inqp->version & SID_ANSII) >= 2) {
594 1.8.2.2 bouyer /*
595 1.8.2.2 bouyer * PassThrough Device.
596 1.8.2.2 bouyer */
597 1.8.2.2 bouyer return (SES_SES_PASSTHROUGH);
598 1.8.2.2 bouyer }
599 1.8.2.2 bouyer #endif
600 1.8.2.2 bouyer
601 1.8.2.2 bouyer /*
602 1.8.2.2 bouyer * The comparison is short for a reason-
603 1.8.2.2 bouyer * some vendors were chopping it short.
604 1.8.2.2 bouyer */
605 1.8.2.2 bouyer
606 1.8.2.2 bouyer if (given_len < SAFTE_END - 2) {
607 1.8.2.2 bouyer return (SES_NONE);
608 1.8.2.2 bouyer }
609 1.8.2.2 bouyer
610 1.8.2.2 bouyer if (STRNCMP((char *)&inqp->vendor_specific[8], "SAF-TE",
611 1.8.2.2 bouyer SAFTE_LEN - 2) == 0) {
612 1.8.2.2 bouyer return (SES_SAFT);
613 1.8.2.2 bouyer }
614 1.8.2.2 bouyer
615 1.8.2.2 bouyer return (SES_NONE);
616 1.8.2.2 bouyer }
617 1.8.2.2 bouyer
618 1.8.2.2 bouyer /*
619 1.8.2.2 bouyer * SES Native Type Device Support
620 1.8.2.2 bouyer */
621 1.8.2.2 bouyer
622 1.8.2.2 bouyer /*
623 1.8.2.2 bouyer * SES Diagnostic Page Codes
624 1.8.2.2 bouyer */
625 1.8.2.2 bouyer
626 1.8.2.2 bouyer typedef enum {
627 1.8.2.2 bouyer SesConfigPage = 0x1,
628 1.8.2.2 bouyer SesControlPage,
629 1.8.2.2 bouyer #define SesStatusPage SesControlPage
630 1.8.2.2 bouyer SesHelpTxt,
631 1.8.2.2 bouyer SesStringOut,
632 1.8.2.2 bouyer #define SesStringIn SesStringOut
633 1.8.2.2 bouyer SesThresholdOut,
634 1.8.2.2 bouyer #define SesThresholdIn SesThresholdOut
635 1.8.2.2 bouyer SesArrayControl,
636 1.8.2.2 bouyer #define SesArrayStatus SesArrayControl
637 1.8.2.2 bouyer SesElementDescriptor,
638 1.8.2.2 bouyer SesShortStatus
639 1.8.2.2 bouyer } SesDiagPageCodes;
640 1.8.2.2 bouyer
641 1.8.2.2 bouyer /*
642 1.8.2.2 bouyer * minimal amounts
643 1.8.2.2 bouyer */
644 1.8.2.2 bouyer
645 1.8.2.2 bouyer /*
646 1.8.2.2 bouyer * Minimum amount of data, starting from byte 0, to have
647 1.8.2.2 bouyer * the config header.
648 1.8.2.2 bouyer */
649 1.8.2.2 bouyer #define SES_CFGHDR_MINLEN 12
650 1.8.2.2 bouyer
651 1.8.2.2 bouyer /*
652 1.8.2.2 bouyer * Minimum amount of data, starting from byte 0, to have
653 1.8.2.2 bouyer * the config header and one enclosure header.
654 1.8.2.2 bouyer */
655 1.8.2.2 bouyer #define SES_ENCHDR_MINLEN 48
656 1.8.2.2 bouyer
657 1.8.2.2 bouyer /*
658 1.8.2.2 bouyer * Take this value, subtract it from VEnclen and you know
659 1.8.2.2 bouyer * the length of the vendor unique bytes.
660 1.8.2.2 bouyer */
661 1.8.2.2 bouyer #define SES_ENCHDR_VMIN 36
662 1.8.2.2 bouyer
663 1.8.2.2 bouyer /*
664 1.8.2.2 bouyer * SES Data Structures
665 1.8.2.2 bouyer */
666 1.8.2.2 bouyer
667 1.8.2.2 bouyer typedef struct {
668 1.8.2.2 bouyer uint32_t GenCode; /* Generation Code */
669 1.8.2.2 bouyer uint8_t Nsubenc; /* Number of Subenclosures */
670 1.8.2.2 bouyer } SesCfgHdr;
671 1.8.2.2 bouyer
672 1.8.2.2 bouyer typedef struct {
673 1.8.2.2 bouyer uint8_t Subencid; /* SubEnclosure Identifier */
674 1.8.2.2 bouyer uint8_t Ntypes; /* # of supported types */
675 1.8.2.2 bouyer uint8_t VEnclen; /* Enclosure Descriptor Length */
676 1.8.2.2 bouyer } SesEncHdr;
677 1.8.2.2 bouyer
678 1.8.2.2 bouyer typedef struct {
679 1.8.2.2 bouyer uint8_t encWWN[8]; /* XXX- Not Right Yet */
680 1.8.2.2 bouyer uint8_t encVid[8];
681 1.8.2.2 bouyer uint8_t encPid[16];
682 1.8.2.2 bouyer uint8_t encRev[4];
683 1.8.2.2 bouyer uint8_t encVen[1];
684 1.8.2.2 bouyer } SesEncDesc;
685 1.8.2.2 bouyer
686 1.8.2.2 bouyer typedef struct {
687 1.8.2.2 bouyer uint8_t enc_type; /* type of element */
688 1.8.2.2 bouyer uint8_t enc_maxelt; /* maximum supported */
689 1.8.2.2 bouyer uint8_t enc_subenc; /* in SubEnc # N */
690 1.8.2.2 bouyer uint8_t enc_tlen; /* Type Descriptor Text Length */
691 1.8.2.2 bouyer } SesThdr;
692 1.8.2.2 bouyer
693 1.8.2.2 bouyer typedef struct {
694 1.8.2.2 bouyer uint8_t comstatus;
695 1.8.2.2 bouyer uint8_t comstat[3];
696 1.8.2.2 bouyer } SesComStat;
697 1.8.2.2 bouyer
698 1.8.2.2 bouyer struct typidx {
699 1.8.2.2 bouyer int ses_tidx;
700 1.8.2.2 bouyer int ses_oidx;
701 1.8.2.2 bouyer };
702 1.8.2.2 bouyer
703 1.8.2.2 bouyer struct sscfg {
704 1.8.2.2 bouyer uint8_t ses_ntypes; /* total number of types supported */
705 1.8.2.2 bouyer
706 1.8.2.2 bouyer /*
707 1.8.2.2 bouyer * We need to keep a type index as well as an
708 1.8.2.2 bouyer * object index for each object in an enclosure.
709 1.8.2.2 bouyer */
710 1.8.2.2 bouyer struct typidx *ses_typidx;
711 1.8.2.2 bouyer
712 1.8.2.2 bouyer /*
713 1.8.2.2 bouyer * We also need to keep track of the number of elements
714 1.8.2.2 bouyer * per type of element. This is needed later so that we
715 1.8.2.2 bouyer * can find precisely in the returned status data the
716 1.8.2.2 bouyer * status for the Nth element of the Kth type.
717 1.8.2.2 bouyer */
718 1.8.2.2 bouyer uint8_t * ses_eltmap;
719 1.8.2.2 bouyer };
720 1.8.2.2 bouyer
721 1.8.2.2 bouyer
722 1.8.2.2 bouyer /*
723 1.8.2.2 bouyer * (de)canonicalization defines
724 1.8.2.2 bouyer */
725 1.8.2.2 bouyer #define sbyte(x, byte) ((((uint32_t)(x)) >> (byte * 8)) & 0xff)
726 1.8.2.2 bouyer #define sbit(x, bit) (((uint32_t)(x)) << bit)
727 1.8.2.2 bouyer #define sset8(outp, idx, sval) (((uint8_t *)(outp))[idx++]) = sbyte(sval, 0)
728 1.8.2.2 bouyer
729 1.8.2.2 bouyer #define sset16(outp, idx, sval) \
730 1.8.2.2 bouyer (((uint8_t *)(outp))[idx++]) = sbyte(sval, 1), \
731 1.8.2.2 bouyer (((uint8_t *)(outp))[idx++]) = sbyte(sval, 0)
732 1.8.2.2 bouyer
733 1.8.2.2 bouyer
734 1.8.2.2 bouyer #define sset24(outp, idx, sval) \
735 1.8.2.2 bouyer (((uint8_t *)(outp))[idx++]) = sbyte(sval, 2), \
736 1.8.2.2 bouyer (((uint8_t *)(outp))[idx++]) = sbyte(sval, 1), \
737 1.8.2.2 bouyer (((uint8_t *)(outp))[idx++]) = sbyte(sval, 0)
738 1.8.2.2 bouyer
739 1.8.2.2 bouyer
740 1.8.2.2 bouyer #define sset32(outp, idx, sval) \
741 1.8.2.2 bouyer (((uint8_t *)(outp))[idx++]) = sbyte(sval, 3), \
742 1.8.2.2 bouyer (((uint8_t *)(outp))[idx++]) = sbyte(sval, 2), \
743 1.8.2.2 bouyer (((uint8_t *)(outp))[idx++]) = sbyte(sval, 1), \
744 1.8.2.2 bouyer (((uint8_t *)(outp))[idx++]) = sbyte(sval, 0)
745 1.8.2.2 bouyer
746 1.8.2.2 bouyer #define gbyte(x, byte) ((((uint32_t)(x)) & 0xff) << (byte * 8))
747 1.8.2.2 bouyer #define gbit(lv, in, idx, shft, mask) lv = ((in[idx] >> shft) & mask)
748 1.8.2.2 bouyer #define sget8(inp, idx, lval) lval = (((uint8_t *)(inp))[idx++])
749 1.8.2.2 bouyer #define gget8(inp, idx, lval) lval = (((uint8_t *)(inp))[idx])
750 1.8.2.2 bouyer
751 1.8.2.2 bouyer #define sget16(inp, idx, lval) \
752 1.8.2.2 bouyer lval = gbyte((((uint8_t *)(inp))[idx]), 1) | \
753 1.8.2.2 bouyer (((uint8_t *)(inp))[idx+1]), idx += 2
754 1.8.2.2 bouyer
755 1.8.2.2 bouyer #define gget16(inp, idx, lval) \
756 1.8.2.2 bouyer lval = gbyte((((uint8_t *)(inp))[idx]), 1) | \
757 1.8.2.2 bouyer (((uint8_t *)(inp))[idx+1])
758 1.8.2.2 bouyer
759 1.8.2.2 bouyer #define sget24(inp, idx, lval) \
760 1.8.2.2 bouyer lval = gbyte((((uint8_t *)(inp))[idx]), 2) | \
761 1.8.2.2 bouyer gbyte((((uint8_t *)(inp))[idx+1]), 1) | \
762 1.8.2.2 bouyer (((uint8_t *)(inp))[idx+2]), idx += 3
763 1.8.2.2 bouyer
764 1.8.2.2 bouyer #define gget24(inp, idx, lval) \
765 1.8.2.2 bouyer lval = gbyte((((uint8_t *)(inp))[idx]), 2) | \
766 1.8.2.2 bouyer gbyte((((uint8_t *)(inp))[idx+1]), 1) | \
767 1.8.2.2 bouyer (((uint8_t *)(inp))[idx+2])
768 1.8.2.2 bouyer
769 1.8.2.2 bouyer #define sget32(inp, idx, lval) \
770 1.8.2.2 bouyer lval = gbyte((((uint8_t *)(inp))[idx]), 3) | \
771 1.8.2.2 bouyer gbyte((((uint8_t *)(inp))[idx+1]), 2) | \
772 1.8.2.2 bouyer gbyte((((uint8_t *)(inp))[idx+2]), 1) | \
773 1.8.2.2 bouyer (((uint8_t *)(inp))[idx+3]), idx += 4
774 1.8.2.2 bouyer
775 1.8.2.2 bouyer #define gget32(inp, idx, lval) \
776 1.8.2.2 bouyer lval = gbyte((((uint8_t *)(inp))[idx]), 3) | \
777 1.8.2.2 bouyer gbyte((((uint8_t *)(inp))[idx+1]), 2) | \
778 1.8.2.2 bouyer gbyte((((uint8_t *)(inp))[idx+2]), 1) | \
779 1.8.2.2 bouyer (((uint8_t *)(inp))[idx+3])
780 1.8.2.2 bouyer
781 1.8.2.2 bouyer #define SCSZ 0x2000
782 1.8.2.2 bouyer #define CFLEN (256 + SES_ENCHDR_MINLEN)
783 1.8.2.2 bouyer
784 1.8.2.2 bouyer /*
785 1.8.2.2 bouyer * Routines specific && private to SES only
786 1.8.2.2 bouyer */
787 1.8.2.2 bouyer
788 1.8.2.2 bouyer static int ses_getconfig(ses_softc_t *);
789 1.8.2.2 bouyer static int ses_getputstat(ses_softc_t *, int, SesComStat *, int, int);
790 1.8.2.2 bouyer static int ses_cfghdr(uint8_t *, int, SesCfgHdr *);
791 1.8.2.2 bouyer static int ses_enchdr(uint8_t *, int, uint8_t, SesEncHdr *);
792 1.8.2.2 bouyer static int ses_encdesc(uint8_t *, int, uint8_t, SesEncDesc *);
793 1.8.2.2 bouyer static int ses_getthdr(uint8_t *, int, int, SesThdr *);
794 1.8.2.2 bouyer static int ses_decode(char *, int, uint8_t *, int, int, SesComStat *);
795 1.8.2.2 bouyer static int ses_encode(char *, int, uint8_t *, int, int, SesComStat *);
796 1.8.2.2 bouyer
797 1.8.2.2 bouyer static int
798 1.8.2.2 bouyer ses_softc_init(ses_softc_t *ssc, int doinit)
799 1.8.2.2 bouyer {
800 1.8.2.2 bouyer if (doinit == 0) {
801 1.8.2.2 bouyer struct sscfg *cc;
802 1.8.2.2 bouyer if (ssc->ses_nobjects) {
803 1.8.2.2 bouyer SES_FREE(ssc->ses_objmap,
804 1.8.2.2 bouyer ssc->ses_nobjects * sizeof (encobj));
805 1.8.2.2 bouyer ssc->ses_objmap = NULL;
806 1.8.2.2 bouyer }
807 1.8.2.2 bouyer if ((cc = ssc->ses_private) != NULL) {
808 1.8.2.2 bouyer if (cc->ses_eltmap && cc->ses_ntypes) {
809 1.8.2.2 bouyer SES_FREE(cc->ses_eltmap, cc->ses_ntypes);
810 1.8.2.2 bouyer cc->ses_eltmap = NULL;
811 1.8.2.2 bouyer cc->ses_ntypes = 0;
812 1.8.2.2 bouyer }
813 1.8.2.2 bouyer if (cc->ses_typidx && ssc->ses_nobjects) {
814 1.8.2.2 bouyer SES_FREE(cc->ses_typidx,
815 1.8.2.2 bouyer ssc->ses_nobjects * sizeof (struct typidx));
816 1.8.2.2 bouyer cc->ses_typidx = NULL;
817 1.8.2.2 bouyer }
818 1.8.2.2 bouyer SES_FREE(cc, sizeof (struct sscfg));
819 1.8.2.2 bouyer ssc->ses_private = NULL;
820 1.8.2.2 bouyer }
821 1.8.2.2 bouyer ssc->ses_nobjects = 0;
822 1.8.2.2 bouyer return (0);
823 1.8.2.2 bouyer }
824 1.8.2.2 bouyer if (ssc->ses_private == NULL) {
825 1.8.2.2 bouyer ssc->ses_private = SES_MALLOC(sizeof (struct sscfg));
826 1.8.2.2 bouyer }
827 1.8.2.2 bouyer if (ssc->ses_private == NULL) {
828 1.8.2.2 bouyer return (ENOMEM);
829 1.8.2.2 bouyer }
830 1.8.2.2 bouyer ssc->ses_nobjects = 0;
831 1.8.2.2 bouyer ssc->ses_encstat = 0;
832 1.8.2.2 bouyer return (ses_getconfig(ssc));
833 1.8.2.2 bouyer }
834 1.8.2.2 bouyer
835 1.8.2.2 bouyer static int
836 1.8.2.2 bouyer ses_init_enc(ses_softc_t *ssc)
837 1.8.2.2 bouyer {
838 1.8.2.2 bouyer return (0);
839 1.8.2.2 bouyer }
840 1.8.2.2 bouyer
841 1.8.2.2 bouyer static int
842 1.8.2.2 bouyer ses_get_encstat(ses_softc_t *ssc, int slpflag)
843 1.8.2.2 bouyer {
844 1.8.2.2 bouyer SesComStat ComStat;
845 1.8.2.2 bouyer int status;
846 1.8.2.2 bouyer
847 1.8.2.2 bouyer if ((status = ses_getputstat(ssc, -1, &ComStat, slpflag, 1)) != 0) {
848 1.8.2.2 bouyer return (status);
849 1.8.2.2 bouyer }
850 1.8.2.2 bouyer ssc->ses_encstat = ComStat.comstatus | ENCI_SVALID;
851 1.8.2.2 bouyer return (0);
852 1.8.2.2 bouyer }
853 1.8.2.2 bouyer
854 1.8.2.2 bouyer static int
855 1.8.2.2 bouyer ses_set_encstat(ses_softc_t *ssc, uint8_t encstat, int slpflag)
856 1.8.2.2 bouyer {
857 1.8.2.2 bouyer SesComStat ComStat;
858 1.8.2.2 bouyer int status;
859 1.8.2.2 bouyer
860 1.8.2.2 bouyer ComStat.comstatus = encstat & 0xf;
861 1.8.2.2 bouyer if ((status = ses_getputstat(ssc, -1, &ComStat, slpflag, 0)) != 0) {
862 1.8.2.2 bouyer return (status);
863 1.8.2.2 bouyer }
864 1.8.2.2 bouyer ssc->ses_encstat = encstat & 0xf; /* note no SVALID set */
865 1.8.2.2 bouyer return (0);
866 1.8.2.2 bouyer }
867 1.8.2.2 bouyer
868 1.8.2.2 bouyer static int
869 1.8.2.2 bouyer ses_get_objstat(ses_softc_t *ssc, ses_objstat *obp, int slpflag)
870 1.8.2.2 bouyer {
871 1.8.2.2 bouyer int i = (int)obp->obj_id;
872 1.8.2.2 bouyer
873 1.8.2.2 bouyer if (ssc->ses_objmap[i].svalid == 0) {
874 1.8.2.2 bouyer SesComStat ComStat;
875 1.8.2.2 bouyer int err = ses_getputstat(ssc, i, &ComStat, slpflag, 1);
876 1.8.2.2 bouyer if (err)
877 1.8.2.2 bouyer return (err);
878 1.8.2.2 bouyer ssc->ses_objmap[i].encstat[0] = ComStat.comstatus;
879 1.8.2.2 bouyer ssc->ses_objmap[i].encstat[1] = ComStat.comstat[0];
880 1.8.2.2 bouyer ssc->ses_objmap[i].encstat[2] = ComStat.comstat[1];
881 1.8.2.2 bouyer ssc->ses_objmap[i].encstat[3] = ComStat.comstat[2];
882 1.8.2.2 bouyer ssc->ses_objmap[i].svalid = 1;
883 1.8.2.2 bouyer }
884 1.8.2.2 bouyer obp->cstat[0] = ssc->ses_objmap[i].encstat[0];
885 1.8.2.2 bouyer obp->cstat[1] = ssc->ses_objmap[i].encstat[1];
886 1.8.2.2 bouyer obp->cstat[2] = ssc->ses_objmap[i].encstat[2];
887 1.8.2.2 bouyer obp->cstat[3] = ssc->ses_objmap[i].encstat[3];
888 1.8.2.2 bouyer return (0);
889 1.8.2.2 bouyer }
890 1.8.2.2 bouyer
891 1.8.2.2 bouyer static int
892 1.8.2.2 bouyer ses_set_objstat(ses_softc_t *ssc, ses_objstat *obp, int slpflag)
893 1.8.2.2 bouyer {
894 1.8.2.2 bouyer SesComStat ComStat;
895 1.8.2.2 bouyer int err;
896 1.8.2.2 bouyer /*
897 1.8.2.2 bouyer * If this is clear, we don't do diddly.
898 1.8.2.2 bouyer */
899 1.8.2.2 bouyer if ((obp->cstat[0] & SESCTL_CSEL) == 0) {
900 1.8.2.2 bouyer return (0);
901 1.8.2.2 bouyer }
902 1.8.2.2 bouyer ComStat.comstatus = obp->cstat[0];
903 1.8.2.2 bouyer ComStat.comstat[0] = obp->cstat[1];
904 1.8.2.2 bouyer ComStat.comstat[1] = obp->cstat[2];
905 1.8.2.2 bouyer ComStat.comstat[2] = obp->cstat[3];
906 1.8.2.2 bouyer err = ses_getputstat(ssc, (int)obp->obj_id, &ComStat, slpflag, 0);
907 1.8.2.2 bouyer ssc->ses_objmap[(int)obp->obj_id].svalid = 0;
908 1.8.2.2 bouyer return (err);
909 1.8.2.2 bouyer }
910 1.8.2.2 bouyer
911 1.8.2.2 bouyer static int
912 1.8.2.2 bouyer ses_getconfig(ses_softc_t *ssc)
913 1.8.2.2 bouyer {
914 1.8.2.2 bouyer struct sscfg *cc;
915 1.8.2.2 bouyer SesCfgHdr cf;
916 1.8.2.2 bouyer SesEncHdr hd;
917 1.8.2.2 bouyer SesEncDesc *cdp;
918 1.8.2.2 bouyer SesThdr thdr;
919 1.8.2.2 bouyer int err, amt, i, nobj, ntype, maxima;
920 1.8.2.2 bouyer char storage[CFLEN], *sdata;
921 1.8.2.2 bouyer static char cdb[6] = {
922 1.8.2.2 bouyer RECEIVE_DIAGNOSTIC, 0x1, SesConfigPage, SCSZ >> 8, SCSZ & 0xff, 0
923 1.8.2.2 bouyer };
924 1.8.2.2 bouyer
925 1.8.2.2 bouyer cc = ssc->ses_private;
926 1.8.2.2 bouyer if (cc == NULL) {
927 1.8.2.2 bouyer return (ENXIO);
928 1.8.2.2 bouyer }
929 1.8.2.2 bouyer
930 1.8.2.2 bouyer sdata = SES_MALLOC(SCSZ);
931 1.8.2.2 bouyer if (sdata == NULL)
932 1.8.2.2 bouyer return (ENOMEM);
933 1.8.2.2 bouyer
934 1.8.2.2 bouyer amt = SCSZ;
935 1.8.2.2 bouyer err = ses_runcmd(ssc, cdb, 6, sdata, &amt);
936 1.8.2.2 bouyer if (err) {
937 1.8.2.2 bouyer SES_FREE(sdata, SCSZ);
938 1.8.2.2 bouyer return (err);
939 1.8.2.2 bouyer }
940 1.8.2.2 bouyer amt = SCSZ - amt;
941 1.8.2.2 bouyer
942 1.8.2.2 bouyer if (ses_cfghdr((uint8_t *) sdata, amt, &cf)) {
943 1.8.2.2 bouyer SES_LOG(ssc, "Unable to parse SES Config Header\n");
944 1.8.2.2 bouyer SES_FREE(sdata, SCSZ);
945 1.8.2.2 bouyer return (EIO);
946 1.8.2.2 bouyer }
947 1.8.2.2 bouyer if (amt < SES_ENCHDR_MINLEN) {
948 1.8.2.2 bouyer SES_LOG(ssc, "runt enclosure length (%d)\n", amt);
949 1.8.2.2 bouyer SES_FREE(sdata, SCSZ);
950 1.8.2.2 bouyer return (EIO);
951 1.8.2.2 bouyer }
952 1.8.2.2 bouyer
953 1.8.2.2 bouyer SES_VLOG(ssc, "GenCode %x %d Subenclosures\n", cf.GenCode, cf.Nsubenc);
954 1.8.2.2 bouyer
955 1.8.2.2 bouyer /*
956 1.8.2.2 bouyer * Now waltz through all the subenclosures toting up the
957 1.8.2.2 bouyer * number of types available in each. For this, we only
958 1.8.2.2 bouyer * really need the enclosure header. However, we get the
959 1.8.2.2 bouyer * enclosure descriptor for debug purposes, as well
960 1.8.2.2 bouyer * as self-consistency checking purposes.
961 1.8.2.2 bouyer */
962 1.8.2.2 bouyer
963 1.8.2.2 bouyer maxima = cf.Nsubenc + 1;
964 1.8.2.2 bouyer cdp = (SesEncDesc *) storage;
965 1.8.2.2 bouyer for (ntype = i = 0; i < maxima; i++) {
966 1.8.2.2 bouyer MEMZERO((caddr_t)cdp, sizeof (*cdp));
967 1.8.2.2 bouyer if (ses_enchdr((uint8_t *) sdata, amt, i, &hd)) {
968 1.8.2.2 bouyer SES_LOG(ssc, "Cannot Extract Enclosure Header %d\n", i);
969 1.8.2.2 bouyer SES_FREE(sdata, SCSZ);
970 1.8.2.2 bouyer return (EIO);
971 1.8.2.2 bouyer }
972 1.8.2.2 bouyer SES_VLOG(ssc, " SubEnclosure ID %d, %d Types With this ID, En"
973 1.8.2.2 bouyer "closure Length %d\n", hd.Subencid, hd.Ntypes, hd.VEnclen);
974 1.8.2.2 bouyer
975 1.8.2.2 bouyer if (ses_encdesc((uint8_t *)sdata, amt, i, cdp)) {
976 1.8.2.2 bouyer SES_LOG(ssc, "Can't get Enclosure Descriptor %d\n", i);
977 1.8.2.2 bouyer SES_FREE(sdata, SCSZ);
978 1.8.2.2 bouyer return (EIO);
979 1.8.2.2 bouyer }
980 1.8.2.2 bouyer SES_VLOG(ssc, " WWN: %02x%02x%02x%02x%02x%02x%02x%02x\n",
981 1.8.2.2 bouyer cdp->encWWN[0], cdp->encWWN[1], cdp->encWWN[2],
982 1.8.2.2 bouyer cdp->encWWN[3], cdp->encWWN[4], cdp->encWWN[5],
983 1.8.2.2 bouyer cdp->encWWN[6], cdp->encWWN[7]);
984 1.8.2.2 bouyer ntype += hd.Ntypes;
985 1.8.2.2 bouyer }
986 1.8.2.2 bouyer
987 1.8.2.2 bouyer /*
988 1.8.2.2 bouyer * Now waltz through all the types that are available, getting
989 1.8.2.2 bouyer * the type header so we can start adding up the number of
990 1.8.2.2 bouyer * objects available.
991 1.8.2.2 bouyer */
992 1.8.2.2 bouyer for (nobj = i = 0; i < ntype; i++) {
993 1.8.2.2 bouyer if (ses_getthdr((uint8_t *)sdata, amt, i, &thdr)) {
994 1.8.2.2 bouyer SES_LOG(ssc, "Can't get Enclosure Type Header %d\n", i);
995 1.8.2.2 bouyer SES_FREE(sdata, SCSZ);
996 1.8.2.2 bouyer return (EIO);
997 1.8.2.2 bouyer }
998 1.8.2.2 bouyer SES_LOG(ssc, " Type Desc[%d]: Type 0x%x, MaxElt %d, In Subenc "
999 1.8.2.2 bouyer "%d, Text Length %d\n", i, thdr.enc_type, thdr.enc_maxelt,
1000 1.8.2.2 bouyer thdr.enc_subenc, thdr.enc_tlen);
1001 1.8.2.2 bouyer nobj += thdr.enc_maxelt;
1002 1.8.2.2 bouyer }
1003 1.8.2.2 bouyer
1004 1.8.2.2 bouyer
1005 1.8.2.2 bouyer /*
1006 1.8.2.2 bouyer * Now allocate the object array and type map.
1007 1.8.2.2 bouyer */
1008 1.8.2.2 bouyer
1009 1.8.2.2 bouyer ssc->ses_objmap = SES_MALLOC(nobj * sizeof (encobj));
1010 1.8.2.2 bouyer cc->ses_typidx = SES_MALLOC(nobj * sizeof (struct typidx));
1011 1.8.2.2 bouyer cc->ses_eltmap = SES_MALLOC(ntype);
1012 1.8.2.2 bouyer
1013 1.8.2.2 bouyer if (ssc->ses_objmap == NULL || cc->ses_typidx == NULL ||
1014 1.8.2.2 bouyer cc->ses_eltmap == NULL) {
1015 1.8.2.2 bouyer if (ssc->ses_objmap) {
1016 1.8.2.2 bouyer SES_FREE(ssc->ses_objmap, (nobj * sizeof (encobj)));
1017 1.8.2.2 bouyer ssc->ses_objmap = NULL;
1018 1.8.2.2 bouyer }
1019 1.8.2.2 bouyer if (cc->ses_typidx) {
1020 1.8.2.2 bouyer SES_FREE(cc->ses_typidx,
1021 1.8.2.2 bouyer (nobj * sizeof (struct typidx)));
1022 1.8.2.2 bouyer cc->ses_typidx = NULL;
1023 1.8.2.2 bouyer }
1024 1.8.2.2 bouyer if (cc->ses_eltmap) {
1025 1.8.2.2 bouyer SES_FREE(cc->ses_eltmap, ntype);
1026 1.8.2.2 bouyer cc->ses_eltmap = NULL;
1027 1.8.2.2 bouyer }
1028 1.8.2.2 bouyer SES_FREE(sdata, SCSZ);
1029 1.8.2.2 bouyer return (ENOMEM);
1030 1.8.2.2 bouyer }
1031 1.8.2.2 bouyer MEMZERO(ssc->ses_objmap, nobj * sizeof (encobj));
1032 1.8.2.2 bouyer MEMZERO(cc->ses_typidx, nobj * sizeof (struct typidx));
1033 1.8.2.2 bouyer MEMZERO(cc->ses_eltmap, ntype);
1034 1.8.2.2 bouyer cc->ses_ntypes = (uint8_t) ntype;
1035 1.8.2.2 bouyer ssc->ses_nobjects = nobj;
1036 1.8.2.2 bouyer
1037 1.8.2.2 bouyer /*
1038 1.8.2.2 bouyer * Now waltz through the # of types again to fill in the types
1039 1.8.2.2 bouyer * (and subenclosure ids) of the allocated objects.
1040 1.8.2.2 bouyer */
1041 1.8.2.2 bouyer nobj = 0;
1042 1.8.2.2 bouyer for (i = 0; i < ntype; i++) {
1043 1.8.2.2 bouyer int j;
1044 1.8.2.2 bouyer if (ses_getthdr((uint8_t *)sdata, amt, i, &thdr)) {
1045 1.8.2.2 bouyer continue;
1046 1.8.2.2 bouyer }
1047 1.8.2.2 bouyer cc->ses_eltmap[i] = thdr.enc_maxelt;
1048 1.8.2.2 bouyer for (j = 0; j < thdr.enc_maxelt; j++) {
1049 1.8.2.2 bouyer cc->ses_typidx[nobj].ses_tidx = i;
1050 1.8.2.2 bouyer cc->ses_typidx[nobj].ses_oidx = j;
1051 1.8.2.2 bouyer ssc->ses_objmap[nobj].subenclosure = thdr.enc_subenc;
1052 1.8.2.2 bouyer ssc->ses_objmap[nobj++].enctype = thdr.enc_type;
1053 1.8.2.2 bouyer }
1054 1.8.2.2 bouyer }
1055 1.8.2.2 bouyer SES_FREE(sdata, SCSZ);
1056 1.8.2.2 bouyer return (0);
1057 1.8.2.2 bouyer }
1058 1.8.2.2 bouyer
1059 1.8.2.2 bouyer static int
1060 1.8.2.2 bouyer ses_getputstat(ses_softc_t *ssc, int objid, SesComStat *sp, int slp, int in)
1061 1.8.2.2 bouyer {
1062 1.8.2.2 bouyer struct sscfg *cc;
1063 1.8.2.2 bouyer int err, amt, bufsiz, tidx, oidx;
1064 1.8.2.2 bouyer char cdb[6], *sdata;
1065 1.8.2.2 bouyer
1066 1.8.2.2 bouyer cc = ssc->ses_private;
1067 1.8.2.2 bouyer if (cc == NULL) {
1068 1.8.2.2 bouyer return (ENXIO);
1069 1.8.2.2 bouyer }
1070 1.8.2.2 bouyer
1071 1.8.2.2 bouyer /*
1072 1.8.2.2 bouyer * If we're just getting overall enclosure status,
1073 1.8.2.2 bouyer * we only need 2 bytes of data storage.
1074 1.8.2.2 bouyer *
1075 1.8.2.2 bouyer * If we're getting anything else, we know how much
1076 1.8.2.2 bouyer * storage we need by noting that starting at offset
1077 1.8.2.2 bouyer * 8 in returned data, all object status bytes are 4
1078 1.8.2.2 bouyer * bytes long, and are stored in chunks of types(M)
1079 1.8.2.2 bouyer * and nth+1 instances of type M.
1080 1.8.2.2 bouyer */
1081 1.8.2.2 bouyer if (objid == -1) {
1082 1.8.2.2 bouyer bufsiz = 2;
1083 1.8.2.2 bouyer } else {
1084 1.8.2.2 bouyer bufsiz = (ssc->ses_nobjects * 4) + (cc->ses_ntypes * 4) + 8;
1085 1.8.2.2 bouyer }
1086 1.8.2.2 bouyer sdata = SES_MALLOC(bufsiz);
1087 1.8.2.2 bouyer if (sdata == NULL)
1088 1.8.2.2 bouyer return (ENOMEM);
1089 1.8.2.2 bouyer
1090 1.8.2.2 bouyer cdb[0] = RECEIVE_DIAGNOSTIC;
1091 1.8.2.2 bouyer cdb[1] = 1;
1092 1.8.2.2 bouyer cdb[2] = SesStatusPage;
1093 1.8.2.2 bouyer cdb[3] = bufsiz >> 8;
1094 1.8.2.2 bouyer cdb[4] = bufsiz & 0xff;
1095 1.8.2.2 bouyer cdb[5] = 0;
1096 1.8.2.2 bouyer amt = bufsiz;
1097 1.8.2.2 bouyer err = ses_runcmd(ssc, cdb, 6, sdata, &amt);
1098 1.8.2.2 bouyer if (err) {
1099 1.8.2.2 bouyer SES_FREE(sdata, bufsiz);
1100 1.8.2.2 bouyer return (err);
1101 1.8.2.2 bouyer }
1102 1.8.2.2 bouyer amt = bufsiz - amt;
1103 1.8.2.2 bouyer
1104 1.8.2.2 bouyer if (objid == -1) {
1105 1.8.2.2 bouyer tidx = -1;
1106 1.8.2.2 bouyer oidx = -1;
1107 1.8.2.2 bouyer } else {
1108 1.8.2.2 bouyer tidx = cc->ses_typidx[objid].ses_tidx;
1109 1.8.2.2 bouyer oidx = cc->ses_typidx[objid].ses_oidx;
1110 1.8.2.2 bouyer }
1111 1.8.2.2 bouyer if (in) {
1112 1.8.2.2 bouyer if (ses_decode(sdata, amt, cc->ses_eltmap, tidx, oidx, sp)) {
1113 1.8.2.2 bouyer err = ENODEV;
1114 1.8.2.2 bouyer }
1115 1.8.2.2 bouyer } else {
1116 1.8.2.2 bouyer if (ses_encode(sdata, amt, cc->ses_eltmap, tidx, oidx, sp)) {
1117 1.8.2.2 bouyer err = ENODEV;
1118 1.8.2.2 bouyer } else {
1119 1.8.2.2 bouyer cdb[0] = SEND_DIAGNOSTIC;
1120 1.8.2.2 bouyer cdb[1] = 0x10;
1121 1.8.2.2 bouyer cdb[2] = 0;
1122 1.8.2.2 bouyer cdb[3] = bufsiz >> 8;
1123 1.8.2.2 bouyer cdb[4] = bufsiz & 0xff;
1124 1.8.2.2 bouyer cdb[5] = 0;
1125 1.8.2.2 bouyer amt = -bufsiz;
1126 1.8.2.2 bouyer err = ses_runcmd(ssc, cdb, 6, sdata, &amt);
1127 1.8.2.2 bouyer }
1128 1.8.2.2 bouyer }
1129 1.8.2.2 bouyer SES_FREE(sdata, bufsiz);
1130 1.8.2.2 bouyer return (0);
1131 1.8.2.2 bouyer }
1132 1.8.2.2 bouyer
1133 1.8.2.2 bouyer
1134 1.8.2.2 bouyer /*
1135 1.8.2.2 bouyer * Routines to parse returned SES data structures.
1136 1.8.2.2 bouyer * Architecture and compiler independent.
1137 1.8.2.2 bouyer */
1138 1.8.2.2 bouyer
1139 1.8.2.2 bouyer static int
1140 1.8.2.2 bouyer ses_cfghdr(uint8_t *buffer, int buflen, SesCfgHdr *cfp)
1141 1.8.2.2 bouyer {
1142 1.8.2.2 bouyer if (buflen < SES_CFGHDR_MINLEN) {
1143 1.8.2.2 bouyer return (-1);
1144 1.8.2.2 bouyer }
1145 1.8.2.2 bouyer gget8(buffer, 1, cfp->Nsubenc);
1146 1.8.2.2 bouyer gget32(buffer, 4, cfp->GenCode);
1147 1.8.2.2 bouyer return (0);
1148 1.8.2.2 bouyer }
1149 1.8.2.2 bouyer
1150 1.8.2.2 bouyer static int
1151 1.8.2.2 bouyer ses_enchdr(uint8_t *buffer, int amt, uint8_t SubEncId, SesEncHdr *chp)
1152 1.8.2.2 bouyer {
1153 1.8.2.2 bouyer int s, off = 8;
1154 1.8.2.2 bouyer for (s = 0; s < SubEncId; s++) {
1155 1.8.2.2 bouyer if (off + 3 > amt)
1156 1.8.2.2 bouyer return (-1);
1157 1.8.2.2 bouyer off += buffer[off+3] + 4;
1158 1.8.2.2 bouyer }
1159 1.8.2.2 bouyer if (off + 3 > amt) {
1160 1.8.2.2 bouyer return (-1);
1161 1.8.2.2 bouyer }
1162 1.8.2.2 bouyer gget8(buffer, off+1, chp->Subencid);
1163 1.8.2.2 bouyer gget8(buffer, off+2, chp->Ntypes);
1164 1.8.2.2 bouyer gget8(buffer, off+3, chp->VEnclen);
1165 1.8.2.2 bouyer return (0);
1166 1.8.2.2 bouyer }
1167 1.8.2.2 bouyer
1168 1.8.2.2 bouyer static int
1169 1.8.2.2 bouyer ses_encdesc(uint8_t *buffer, int amt, uint8_t SubEncId, SesEncDesc *cdp)
1170 1.8.2.2 bouyer {
1171 1.8.2.2 bouyer int s, e, enclen, off = 8;
1172 1.8.2.2 bouyer for (s = 0; s < SubEncId; s++) {
1173 1.8.2.2 bouyer if (off + 3 > amt)
1174 1.8.2.2 bouyer return (-1);
1175 1.8.2.2 bouyer off += buffer[off+3] + 4;
1176 1.8.2.2 bouyer }
1177 1.8.2.2 bouyer if (off + 3 > amt) {
1178 1.8.2.2 bouyer return (-1);
1179 1.8.2.2 bouyer }
1180 1.8.2.2 bouyer gget8(buffer, off+3, enclen);
1181 1.8.2.2 bouyer off += 4;
1182 1.8.2.2 bouyer if (off >= amt)
1183 1.8.2.2 bouyer return (-1);
1184 1.8.2.2 bouyer
1185 1.8.2.2 bouyer e = off + enclen;
1186 1.8.2.2 bouyer if (e > amt) {
1187 1.8.2.2 bouyer e = amt;
1188 1.8.2.2 bouyer }
1189 1.8.2.2 bouyer MEMCPY(cdp, &buffer[off], e - off);
1190 1.8.2.2 bouyer return (0);
1191 1.8.2.2 bouyer }
1192 1.8.2.2 bouyer
1193 1.8.2.2 bouyer static int
1194 1.8.2.2 bouyer ses_getthdr(uint8_t *buffer, int amt, int nth, SesThdr *thp)
1195 1.8.2.2 bouyer {
1196 1.8.2.2 bouyer int s, off = 8;
1197 1.8.2.2 bouyer
1198 1.8.2.2 bouyer if (amt < SES_CFGHDR_MINLEN) {
1199 1.8.2.2 bouyer return (-1);
1200 1.8.2.2 bouyer }
1201 1.8.2.2 bouyer for (s = 0; s < buffer[1]; s++) {
1202 1.8.2.2 bouyer if (off + 3 > amt)
1203 1.8.2.2 bouyer return (-1);
1204 1.8.2.2 bouyer off += buffer[off+3] + 4;
1205 1.8.2.2 bouyer }
1206 1.8.2.2 bouyer if (off + 3 > amt) {
1207 1.8.2.2 bouyer return (-1);
1208 1.8.2.2 bouyer }
1209 1.8.2.2 bouyer off += buffer[off+3] + 4 + (nth * 4);
1210 1.8.2.2 bouyer if (amt < (off + 4))
1211 1.8.2.2 bouyer return (-1);
1212 1.8.2.2 bouyer
1213 1.8.2.2 bouyer gget8(buffer, off++, thp->enc_type);
1214 1.8.2.2 bouyer gget8(buffer, off++, thp->enc_maxelt);
1215 1.8.2.2 bouyer gget8(buffer, off++, thp->enc_subenc);
1216 1.8.2.2 bouyer gget8(buffer, off, thp->enc_tlen);
1217 1.8.2.2 bouyer return (0);
1218 1.8.2.2 bouyer }
1219 1.8.2.2 bouyer
1220 1.8.2.2 bouyer /*
1221 1.8.2.2 bouyer * This function needs a little explanation.
1222 1.8.2.2 bouyer *
1223 1.8.2.2 bouyer * The arguments are:
1224 1.8.2.2 bouyer *
1225 1.8.2.2 bouyer *
1226 1.8.2.2 bouyer * char *b, int amt
1227 1.8.2.2 bouyer *
1228 1.8.2.2 bouyer * These describes the raw input SES status data and length.
1229 1.8.2.2 bouyer *
1230 1.8.2.2 bouyer * uint8_t *ep
1231 1.8.2.2 bouyer *
1232 1.8.2.2 bouyer * This is a map of the number of types for each element type
1233 1.8.2.2 bouyer * in the enclosure.
1234 1.8.2.2 bouyer *
1235 1.8.2.2 bouyer * int elt
1236 1.8.2.2 bouyer *
1237 1.8.2.2 bouyer * This is the element type being sought. If elt is -1,
1238 1.8.2.2 bouyer * then overall enclosure status is being sought.
1239 1.8.2.2 bouyer *
1240 1.8.2.2 bouyer * int elm
1241 1.8.2.2 bouyer *
1242 1.8.2.2 bouyer * This is the ordinal Mth element of type elt being sought.
1243 1.8.2.2 bouyer *
1244 1.8.2.2 bouyer * SesComStat *sp
1245 1.8.2.2 bouyer *
1246 1.8.2.2 bouyer * This is the output area to store the status for
1247 1.8.2.2 bouyer * the Mth element of type Elt.
1248 1.8.2.2 bouyer */
1249 1.8.2.2 bouyer
1250 1.8.2.2 bouyer static int
1251 1.8.2.2 bouyer ses_decode(char *b, int amt, uint8_t *ep, int elt, int elm, SesComStat *sp)
1252 1.8.2.2 bouyer {
1253 1.8.2.2 bouyer int idx, i;
1254 1.8.2.2 bouyer
1255 1.8.2.2 bouyer /*
1256 1.8.2.2 bouyer * If it's overall enclosure status being sought, get that.
1257 1.8.2.2 bouyer * We need at least 2 bytes of status data to get that.
1258 1.8.2.2 bouyer */
1259 1.8.2.2 bouyer if (elt == -1) {
1260 1.8.2.2 bouyer if (amt < 2)
1261 1.8.2.2 bouyer return (-1);
1262 1.8.2.2 bouyer gget8(b, 1, sp->comstatus);
1263 1.8.2.2 bouyer sp->comstat[0] = 0;
1264 1.8.2.2 bouyer sp->comstat[1] = 0;
1265 1.8.2.2 bouyer sp->comstat[2] = 0;
1266 1.8.2.2 bouyer return (0);
1267 1.8.2.2 bouyer }
1268 1.8.2.2 bouyer
1269 1.8.2.2 bouyer /*
1270 1.8.2.2 bouyer * Check to make sure that the Mth element is legal for type Elt.
1271 1.8.2.2 bouyer */
1272 1.8.2.2 bouyer
1273 1.8.2.2 bouyer if (elm >= ep[elt])
1274 1.8.2.2 bouyer return (-1);
1275 1.8.2.2 bouyer
1276 1.8.2.2 bouyer /*
1277 1.8.2.2 bouyer * Starting at offset 8, start skipping over the storage
1278 1.8.2.2 bouyer * for the element types we're not interested in.
1279 1.8.2.2 bouyer */
1280 1.8.2.2 bouyer for (idx = 8, i = 0; i < elt; i++) {
1281 1.8.2.2 bouyer idx += ((ep[i] + 1) * 4);
1282 1.8.2.2 bouyer }
1283 1.8.2.2 bouyer
1284 1.8.2.2 bouyer /*
1285 1.8.2.2 bouyer * Skip over Overall status for this element type.
1286 1.8.2.2 bouyer */
1287 1.8.2.2 bouyer idx += 4;
1288 1.8.2.2 bouyer
1289 1.8.2.2 bouyer /*
1290 1.8.2.2 bouyer * And skip to the index for the Mth element that we're going for.
1291 1.8.2.2 bouyer */
1292 1.8.2.2 bouyer idx += (4 * elm);
1293 1.8.2.2 bouyer
1294 1.8.2.2 bouyer /*
1295 1.8.2.2 bouyer * Make sure we haven't overflowed the buffer.
1296 1.8.2.2 bouyer */
1297 1.8.2.2 bouyer if (idx+4 > amt)
1298 1.8.2.2 bouyer return (-1);
1299 1.8.2.2 bouyer
1300 1.8.2.2 bouyer /*
1301 1.8.2.2 bouyer * Retrieve the status.
1302 1.8.2.2 bouyer */
1303 1.8.2.2 bouyer gget8(b, idx++, sp->comstatus);
1304 1.8.2.2 bouyer gget8(b, idx++, sp->comstat[0]);
1305 1.8.2.2 bouyer gget8(b, idx++, sp->comstat[1]);
1306 1.8.2.2 bouyer gget8(b, idx++, sp->comstat[2]);
1307 1.8.2.2 bouyer #if 0
1308 1.8.2.2 bouyer PRINTF("Get Elt 0x%x Elm 0x%x (idx %d)\n", elt, elm, idx-4);
1309 1.8.2.2 bouyer #endif
1310 1.8.2.2 bouyer return (0);
1311 1.8.2.2 bouyer }
1312 1.8.2.2 bouyer
1313 1.8.2.2 bouyer /*
1314 1.8.2.2 bouyer * This is the mirror function to ses_decode, but we set the 'select'
1315 1.8.2.2 bouyer * bit for the object which we're interested in. All other objects,
1316 1.8.2.2 bouyer * after a status fetch, should have that bit off. Hmm. It'd be easy
1317 1.8.2.2 bouyer * enough to ensure this, so we will.
1318 1.8.2.2 bouyer */
1319 1.8.2.2 bouyer
1320 1.8.2.2 bouyer static int
1321 1.8.2.2 bouyer ses_encode(char *b, int amt, uint8_t *ep, int elt, int elm, SesComStat *sp)
1322 1.8.2.2 bouyer {
1323 1.8.2.2 bouyer int idx, i;
1324 1.8.2.2 bouyer
1325 1.8.2.2 bouyer /*
1326 1.8.2.2 bouyer * If it's overall enclosure status being sought, get that.
1327 1.8.2.2 bouyer * We need at least 2 bytes of status data to get that.
1328 1.8.2.2 bouyer */
1329 1.8.2.2 bouyer if (elt == -1) {
1330 1.8.2.2 bouyer if (amt < 2)
1331 1.8.2.2 bouyer return (-1);
1332 1.8.2.2 bouyer i = 0;
1333 1.8.2.2 bouyer sset8(b, i, 0);
1334 1.8.2.2 bouyer sset8(b, i, sp->comstatus & 0xf);
1335 1.8.2.2 bouyer #if 0
1336 1.8.2.2 bouyer PRINTF("set EncStat %x\n", sp->comstatus);
1337 1.8.2.2 bouyer #endif
1338 1.8.2.2 bouyer return (0);
1339 1.8.2.2 bouyer }
1340 1.8.2.2 bouyer
1341 1.8.2.2 bouyer /*
1342 1.8.2.2 bouyer * Check to make sure that the Mth element is legal for type Elt.
1343 1.8.2.2 bouyer */
1344 1.8.2.2 bouyer
1345 1.8.2.2 bouyer if (elm >= ep[elt])
1346 1.8.2.2 bouyer return (-1);
1347 1.8.2.2 bouyer
1348 1.8.2.2 bouyer /*
1349 1.8.2.2 bouyer * Starting at offset 8, start skipping over the storage
1350 1.8.2.2 bouyer * for the element types we're not interested in.
1351 1.8.2.2 bouyer */
1352 1.8.2.2 bouyer for (idx = 8, i = 0; i < elt; i++) {
1353 1.8.2.2 bouyer idx += ((ep[i] + 1) * 4);
1354 1.8.2.2 bouyer }
1355 1.8.2.2 bouyer
1356 1.8.2.2 bouyer /*
1357 1.8.2.2 bouyer * Skip over Overall status for this element type.
1358 1.8.2.2 bouyer */
1359 1.8.2.2 bouyer idx += 4;
1360 1.8.2.2 bouyer
1361 1.8.2.2 bouyer /*
1362 1.8.2.2 bouyer * And skip to the index for the Mth element that we're going for.
1363 1.8.2.2 bouyer */
1364 1.8.2.2 bouyer idx += (4 * elm);
1365 1.8.2.2 bouyer
1366 1.8.2.2 bouyer /*
1367 1.8.2.2 bouyer * Make sure we haven't overflowed the buffer.
1368 1.8.2.2 bouyer */
1369 1.8.2.2 bouyer if (idx+4 > amt)
1370 1.8.2.2 bouyer return (-1);
1371 1.8.2.2 bouyer
1372 1.8.2.2 bouyer /*
1373 1.8.2.2 bouyer * Set the status.
1374 1.8.2.2 bouyer */
1375 1.8.2.2 bouyer sset8(b, idx, sp->comstatus);
1376 1.8.2.2 bouyer sset8(b, idx, sp->comstat[0]);
1377 1.8.2.2 bouyer sset8(b, idx, sp->comstat[1]);
1378 1.8.2.2 bouyer sset8(b, idx, sp->comstat[2]);
1379 1.8.2.2 bouyer idx -= 4;
1380 1.8.2.2 bouyer
1381 1.8.2.2 bouyer #if 0
1382 1.8.2.2 bouyer PRINTF("Set Elt 0x%x Elm 0x%x (idx %d) with %x %x %x %x\n",
1383 1.8.2.2 bouyer elt, elm, idx, sp->comstatus, sp->comstat[0],
1384 1.8.2.2 bouyer sp->comstat[1], sp->comstat[2]);
1385 1.8.2.2 bouyer #endif
1386 1.8.2.2 bouyer
1387 1.8.2.2 bouyer /*
1388 1.8.2.2 bouyer * Now make sure all other 'Select' bits are off.
1389 1.8.2.2 bouyer */
1390 1.8.2.2 bouyer for (i = 8; i < amt; i += 4) {
1391 1.8.2.2 bouyer if (i != idx)
1392 1.8.2.2 bouyer b[i] &= ~0x80;
1393 1.8.2.2 bouyer }
1394 1.8.2.2 bouyer /*
1395 1.8.2.2 bouyer * And make sure the INVOP bit is clear.
1396 1.8.2.2 bouyer */
1397 1.8.2.2 bouyer b[2] &= ~0x10;
1398 1.8.2.2 bouyer
1399 1.8.2.2 bouyer return (0);
1400 1.8.2.2 bouyer }
1401 1.8.2.2 bouyer
1402 1.8.2.2 bouyer /*
1403 1.8.2.2 bouyer * SAF-TE Type Device Emulation
1404 1.8.2.2 bouyer */
1405 1.8.2.2 bouyer
1406 1.8.2.2 bouyer static int safte_getconfig(ses_softc_t *);
1407 1.8.2.2 bouyer static int safte_rdstat(ses_softc_t *, int);;
1408 1.8.2.2 bouyer static int set_objstat_sel(ses_softc_t *, ses_objstat *, int);
1409 1.8.2.2 bouyer static int wrbuf16(ses_softc_t *, uint8_t, uint8_t, uint8_t, uint8_t, int);
1410 1.8.2.2 bouyer static void wrslot_stat(ses_softc_t *, int);
1411 1.8.2.2 bouyer static int perf_slotop(ses_softc_t *, uint8_t, uint8_t, int);
1412 1.8.2.2 bouyer
1413 1.8.2.2 bouyer #define ALL_ENC_STAT (SES_ENCSTAT_CRITICAL | SES_ENCSTAT_UNRECOV | \
1414 1.8.2.2 bouyer SES_ENCSTAT_NONCRITICAL | SES_ENCSTAT_INFO)
1415 1.8.2.2 bouyer /*
1416 1.8.2.2 bouyer * SAF-TE specific defines- Mandatory ones only...
1417 1.8.2.2 bouyer */
1418 1.8.2.2 bouyer
1419 1.8.2.2 bouyer /*
1420 1.8.2.2 bouyer * READ BUFFER ('get' commands) IDs- placed in offset 2 of cdb
1421 1.8.2.2 bouyer */
1422 1.8.2.2 bouyer #define SAFTE_RD_RDCFG 0x00 /* read enclosure configuration */
1423 1.8.2.2 bouyer #define SAFTE_RD_RDESTS 0x01 /* read enclosure status */
1424 1.8.2.2 bouyer #define SAFTE_RD_RDDSTS 0x04 /* read drive slot status */
1425 1.8.2.2 bouyer
1426 1.8.2.2 bouyer /*
1427 1.8.2.2 bouyer * WRITE BUFFER ('set' commands) IDs- placed in offset 0 of databuf
1428 1.8.2.2 bouyer */
1429 1.8.2.2 bouyer #define SAFTE_WT_DSTAT 0x10 /* write device slot status */
1430 1.8.2.2 bouyer #define SAFTE_WT_SLTOP 0x12 /* perform slot operation */
1431 1.8.2.2 bouyer #define SAFTE_WT_FANSPD 0x13 /* set fan speed */
1432 1.8.2.2 bouyer #define SAFTE_WT_ACTPWS 0x14 /* turn on/off power supply */
1433 1.8.2.2 bouyer #define SAFTE_WT_GLOBAL 0x15 /* send global command */
1434 1.8.2.2 bouyer
1435 1.8.2.2 bouyer
1436 1.8.2.2 bouyer #define SAFT_SCRATCH 64
1437 1.8.2.2 bouyer #define NPSEUDO_THERM 16
1438 1.8.2.2 bouyer #define NPSEUDO_ALARM 1
1439 1.8.2.2 bouyer struct scfg {
1440 1.8.2.2 bouyer /*
1441 1.8.2.2 bouyer * Cached Configuration
1442 1.8.2.2 bouyer */
1443 1.8.2.2 bouyer uint8_t Nfans; /* Number of Fans */
1444 1.8.2.2 bouyer uint8_t Npwr; /* Number of Power Supplies */
1445 1.8.2.2 bouyer uint8_t Nslots; /* Number of Device Slots */
1446 1.8.2.2 bouyer uint8_t DoorLock; /* Door Lock Installed */
1447 1.8.2.2 bouyer uint8_t Ntherm; /* Number of Temperature Sensors */
1448 1.8.2.2 bouyer uint8_t Nspkrs; /* Number of Speakers */
1449 1.8.2.2 bouyer uint8_t Nalarm; /* Number of Alarms (at least one) */
1450 1.8.2.2 bouyer /*
1451 1.8.2.2 bouyer * Cached Flag Bytes for Global Status
1452 1.8.2.2 bouyer */
1453 1.8.2.2 bouyer uint8_t flag1;
1454 1.8.2.2 bouyer uint8_t flag2;
1455 1.8.2.2 bouyer /*
1456 1.8.2.2 bouyer * What object index ID is where various slots start.
1457 1.8.2.2 bouyer */
1458 1.8.2.2 bouyer uint8_t pwroff;
1459 1.8.2.2 bouyer uint8_t slotoff;
1460 1.8.2.2 bouyer #define SAFT_ALARM_OFFSET(cc) (cc)->slotoff - 1
1461 1.8.2.2 bouyer };
1462 1.8.2.2 bouyer
1463 1.8.2.2 bouyer #define SAFT_FLG1_ALARM 0x1
1464 1.8.2.2 bouyer #define SAFT_FLG1_GLOBFAIL 0x2
1465 1.8.2.2 bouyer #define SAFT_FLG1_GLOBWARN 0x4
1466 1.8.2.2 bouyer #define SAFT_FLG1_ENCPWROFF 0x8
1467 1.8.2.2 bouyer #define SAFT_FLG1_ENCFANFAIL 0x10
1468 1.8.2.2 bouyer #define SAFT_FLG1_ENCPWRFAIL 0x20
1469 1.8.2.2 bouyer #define SAFT_FLG1_ENCDRVFAIL 0x40
1470 1.8.2.2 bouyer #define SAFT_FLG1_ENCDRVWARN 0x80
1471 1.8.2.2 bouyer
1472 1.8.2.2 bouyer #define SAFT_FLG2_LOCKDOOR 0x4
1473 1.8.2.2 bouyer #define SAFT_PRIVATE sizeof (struct scfg)
1474 1.8.2.2 bouyer
1475 1.8.2.2 bouyer static const char safte_2little[] = "Too Little Data Returned (%d) at line %d\n";
1476 1.8.2.2 bouyer #define SAFT_BAIL(r, x, k, l) \
1477 1.8.2.2 bouyer if (r >= x) { \
1478 1.8.2.2 bouyer SES_LOG(ssc, safte_2little, x, __LINE__);\
1479 1.8.2.2 bouyer SES_FREE(k, l); \
1480 1.8.2.2 bouyer return (EIO); \
1481 1.8.2.2 bouyer }
1482 1.8.2.2 bouyer
1483 1.8.2.2 bouyer
1484 1.8.2.2 bouyer int
1485 1.8.2.2 bouyer safte_softc_init(ses_softc_t *ssc, int doinit)
1486 1.8.2.2 bouyer {
1487 1.8.2.2 bouyer int err, i, r;
1488 1.8.2.2 bouyer struct scfg *cc;
1489 1.8.2.2 bouyer
1490 1.8.2.2 bouyer if (doinit == 0) {
1491 1.8.2.2 bouyer if (ssc->ses_nobjects) {
1492 1.8.2.2 bouyer if (ssc->ses_objmap) {
1493 1.8.2.2 bouyer SES_FREE(ssc->ses_objmap,
1494 1.8.2.2 bouyer ssc->ses_nobjects * sizeof (encobj));
1495 1.8.2.2 bouyer ssc->ses_objmap = NULL;
1496 1.8.2.2 bouyer }
1497 1.8.2.2 bouyer ssc->ses_nobjects = 0;
1498 1.8.2.2 bouyer }
1499 1.8.2.2 bouyer if (ssc->ses_private) {
1500 1.8.2.2 bouyer SES_FREE(ssc->ses_private, SAFT_PRIVATE);
1501 1.8.2.2 bouyer ssc->ses_private = NULL;
1502 1.8.2.2 bouyer }
1503 1.8.2.2 bouyer return (0);
1504 1.8.2.2 bouyer }
1505 1.8.2.2 bouyer
1506 1.8.2.2 bouyer if (ssc->ses_private == NULL) {
1507 1.8.2.2 bouyer ssc->ses_private = SES_MALLOC(SAFT_PRIVATE);
1508 1.8.2.2 bouyer if (ssc->ses_private == NULL) {
1509 1.8.2.2 bouyer return (ENOMEM);
1510 1.8.2.2 bouyer }
1511 1.8.2.2 bouyer MEMZERO(ssc->ses_private, SAFT_PRIVATE);
1512 1.8.2.2 bouyer }
1513 1.8.2.2 bouyer
1514 1.8.2.2 bouyer ssc->ses_nobjects = 0;
1515 1.8.2.2 bouyer ssc->ses_encstat = 0;
1516 1.8.2.2 bouyer
1517 1.8.2.2 bouyer if ((err = safte_getconfig(ssc)) != 0) {
1518 1.8.2.2 bouyer return (err);
1519 1.8.2.2 bouyer }
1520 1.8.2.2 bouyer
1521 1.8.2.2 bouyer /*
1522 1.8.2.2 bouyer * The number of objects here, as well as that reported by the
1523 1.8.2.2 bouyer * READ_BUFFER/GET_CONFIG call, are the over-temperature flags (15)
1524 1.8.2.2 bouyer * that get reported during READ_BUFFER/READ_ENC_STATUS.
1525 1.8.2.2 bouyer */
1526 1.8.2.2 bouyer cc = ssc->ses_private;
1527 1.8.2.2 bouyer ssc->ses_nobjects = cc->Nfans + cc->Npwr + cc->Nslots + cc->DoorLock +
1528 1.8.2.2 bouyer cc->Ntherm + cc->Nspkrs + NPSEUDO_THERM + NPSEUDO_ALARM;
1529 1.8.2.2 bouyer ssc->ses_objmap = (encobj *)
1530 1.8.2.2 bouyer SES_MALLOC(ssc->ses_nobjects * sizeof (encobj));
1531 1.8.2.2 bouyer if (ssc->ses_objmap == NULL) {
1532 1.8.2.2 bouyer return (ENOMEM);
1533 1.8.2.2 bouyer }
1534 1.8.2.2 bouyer MEMZERO(ssc->ses_objmap, ssc->ses_nobjects * sizeof (encobj));
1535 1.8.2.2 bouyer
1536 1.8.2.2 bouyer r = 0;
1537 1.8.2.2 bouyer /*
1538 1.8.2.2 bouyer * Note that this is all arranged for the convenience
1539 1.8.2.2 bouyer * in later fetches of status.
1540 1.8.2.2 bouyer */
1541 1.8.2.2 bouyer for (i = 0; i < cc->Nfans; i++)
1542 1.8.2.2 bouyer ssc->ses_objmap[r++].enctype = SESTYP_FAN;
1543 1.8.2.2 bouyer cc->pwroff = (uint8_t) r;
1544 1.8.2.2 bouyer for (i = 0; i < cc->Npwr; i++)
1545 1.8.2.2 bouyer ssc->ses_objmap[r++].enctype = SESTYP_POWER;
1546 1.8.2.2 bouyer for (i = 0; i < cc->DoorLock; i++)
1547 1.8.2.2 bouyer ssc->ses_objmap[r++].enctype = SESTYP_DOORLOCK;
1548 1.8.2.2 bouyer for (i = 0; i < cc->Nspkrs; i++)
1549 1.8.2.2 bouyer ssc->ses_objmap[r++].enctype = SESTYP_ALARM;
1550 1.8.2.2 bouyer for (i = 0; i < cc->Ntherm; i++)
1551 1.8.2.2 bouyer ssc->ses_objmap[r++].enctype = SESTYP_THERM;
1552 1.8.2.2 bouyer for (i = 0; i < NPSEUDO_THERM; i++)
1553 1.8.2.2 bouyer ssc->ses_objmap[r++].enctype = SESTYP_THERM;
1554 1.8.2.2 bouyer ssc->ses_objmap[r++].enctype = SESTYP_ALARM;
1555 1.8.2.2 bouyer cc->slotoff = (uint8_t) r;
1556 1.8.2.2 bouyer for (i = 0; i < cc->Nslots; i++)
1557 1.8.2.2 bouyer ssc->ses_objmap[r++].enctype = SESTYP_DEVICE;
1558 1.8.2.2 bouyer return (0);
1559 1.8.2.2 bouyer }
1560 1.8.2.2 bouyer
1561 1.8.2.2 bouyer int
1562 1.8.2.2 bouyer safte_init_enc(ses_softc_t *ssc)
1563 1.8.2.2 bouyer {
1564 1.8.2.2 bouyer int err, amt;
1565 1.8.2.2 bouyer char *sdata;
1566 1.8.2.2 bouyer static char cdb0[6] = { SEND_DIAGNOSTIC };
1567 1.8.2.2 bouyer static char cdb[10] =
1568 1.8.2.2 bouyer { WRITE_BUFFER, 1, 0, 0, 0, 0, 0, 0, 16, 0 };
1569 1.8.2.2 bouyer
1570 1.8.2.2 bouyer sdata = SES_MALLOC(SAFT_SCRATCH);
1571 1.8.2.2 bouyer if (sdata == NULL)
1572 1.8.2.2 bouyer return (ENOMEM);
1573 1.8.2.2 bouyer
1574 1.8.2.2 bouyer err = ses_runcmd(ssc, cdb0, 6, NULL, 0);
1575 1.8.2.2 bouyer if (err) {
1576 1.8.2.2 bouyer SES_FREE(sdata, SAFT_SCRATCH);
1577 1.8.2.2 bouyer return (err);
1578 1.8.2.2 bouyer }
1579 1.8.2.2 bouyer sdata[0] = SAFTE_WT_GLOBAL;
1580 1.8.2.2 bouyer MEMZERO(&sdata[1], 15);
1581 1.8.2.2 bouyer amt = -SAFT_SCRATCH;
1582 1.8.2.2 bouyer err = ses_runcmd(ssc, cdb, 10, sdata, &amt);
1583 1.8.2.2 bouyer SES_FREE(sdata, SAFT_SCRATCH);
1584 1.8.2.2 bouyer return (err);
1585 1.8.2.2 bouyer }
1586 1.8.2.2 bouyer
1587 1.8.2.2 bouyer int
1588 1.8.2.2 bouyer safte_get_encstat(ses_softc_t *ssc, int slpflg)
1589 1.8.2.2 bouyer {
1590 1.8.2.2 bouyer return (safte_rdstat(ssc, slpflg));
1591 1.8.2.2 bouyer }
1592 1.8.2.2 bouyer
1593 1.8.2.2 bouyer int
1594 1.8.2.2 bouyer safte_set_encstat(ses_softc_t *ssc, uint8_t encstat, int slpflg)
1595 1.8.2.2 bouyer {
1596 1.8.2.2 bouyer struct scfg *cc = ssc->ses_private;
1597 1.8.2.2 bouyer if (cc == NULL)
1598 1.8.2.2 bouyer return (0);
1599 1.8.2.2 bouyer /*
1600 1.8.2.2 bouyer * Since SAF-TE devices aren't necessarily sticky in terms
1601 1.8.2.2 bouyer * of state, make our soft copy of enclosure status 'sticky'-
1602 1.8.2.2 bouyer * that is, things set in enclosure status stay set (as implied
1603 1.8.2.2 bouyer * by conditions set in reading object status) until cleared.
1604 1.8.2.2 bouyer */
1605 1.8.2.2 bouyer ssc->ses_encstat &= ~ALL_ENC_STAT;
1606 1.8.2.2 bouyer ssc->ses_encstat |= (encstat & ALL_ENC_STAT);
1607 1.8.2.2 bouyer ssc->ses_encstat |= ENCI_SVALID;
1608 1.8.2.2 bouyer cc->flag1 &= ~(SAFT_FLG1_ALARM|SAFT_FLG1_GLOBFAIL|SAFT_FLG1_GLOBWARN);
1609 1.8.2.2 bouyer if ((encstat & (SES_ENCSTAT_CRITICAL|SES_ENCSTAT_UNRECOV)) != 0) {
1610 1.8.2.2 bouyer cc->flag1 |= SAFT_FLG1_ALARM|SAFT_FLG1_GLOBFAIL;
1611 1.8.2.2 bouyer } else if ((encstat & SES_ENCSTAT_NONCRITICAL) != 0) {
1612 1.8.2.2 bouyer cc->flag1 |= SAFT_FLG1_GLOBWARN;
1613 1.8.2.2 bouyer }
1614 1.8.2.2 bouyer return (wrbuf16(ssc, SAFTE_WT_GLOBAL, cc->flag1, cc->flag2, 0, slpflg));
1615 1.8.2.2 bouyer }
1616 1.8.2.2 bouyer
1617 1.8.2.2 bouyer int
1618 1.8.2.2 bouyer safte_get_objstat(ses_softc_t *ssc, ses_objstat *obp, int slpflg)
1619 1.8.2.2 bouyer {
1620 1.8.2.2 bouyer int i = (int)obp->obj_id;
1621 1.8.2.2 bouyer
1622 1.8.2.2 bouyer if ((ssc->ses_encstat & ENCI_SVALID) == 0 ||
1623 1.8.2.2 bouyer (ssc->ses_objmap[i].svalid) == 0) {
1624 1.8.2.2 bouyer int err = safte_rdstat(ssc, slpflg);
1625 1.8.2.2 bouyer if (err)
1626 1.8.2.2 bouyer return (err);
1627 1.8.2.2 bouyer }
1628 1.8.2.2 bouyer obp->cstat[0] = ssc->ses_objmap[i].encstat[0];
1629 1.8.2.2 bouyer obp->cstat[1] = ssc->ses_objmap[i].encstat[1];
1630 1.8.2.2 bouyer obp->cstat[2] = ssc->ses_objmap[i].encstat[2];
1631 1.8.2.2 bouyer obp->cstat[3] = ssc->ses_objmap[i].encstat[3];
1632 1.8.2.2 bouyer return (0);
1633 1.8.2.2 bouyer }
1634 1.8.2.2 bouyer
1635 1.8.2.2 bouyer
1636 1.8.2.2 bouyer int
1637 1.8.2.2 bouyer safte_set_objstat(ses_softc_t *ssc, ses_objstat *obp, int slp)
1638 1.8.2.2 bouyer {
1639 1.8.2.2 bouyer int idx, err;
1640 1.8.2.2 bouyer encobj *ep;
1641 1.8.2.2 bouyer struct scfg *cc;
1642 1.8.2.2 bouyer
1643 1.8.2.2 bouyer
1644 1.8.2.2 bouyer SES_VLOG(ssc, "safte_set_objstat(%d): %x %x %x %x\n",
1645 1.8.2.2 bouyer (int)obp->obj_id, obp->cstat[0], obp->cstat[1], obp->cstat[2],
1646 1.8.2.2 bouyer obp->cstat[3]);
1647 1.8.2.2 bouyer
1648 1.8.2.2 bouyer /*
1649 1.8.2.2 bouyer * If this is clear, we don't do diddly.
1650 1.8.2.2 bouyer */
1651 1.8.2.2 bouyer if ((obp->cstat[0] & SESCTL_CSEL) == 0) {
1652 1.8.2.2 bouyer return (0);
1653 1.8.2.2 bouyer }
1654 1.8.2.2 bouyer
1655 1.8.2.2 bouyer err = 0;
1656 1.8.2.2 bouyer /*
1657 1.8.2.2 bouyer * Check to see if the common bits are set and do them first.
1658 1.8.2.2 bouyer */
1659 1.8.2.2 bouyer if (obp->cstat[0] & ~SESCTL_CSEL) {
1660 1.8.2.2 bouyer err = set_objstat_sel(ssc, obp, slp);
1661 1.8.2.2 bouyer if (err)
1662 1.8.2.2 bouyer return (err);
1663 1.8.2.2 bouyer }
1664 1.8.2.2 bouyer
1665 1.8.2.2 bouyer cc = ssc->ses_private;
1666 1.8.2.2 bouyer if (cc == NULL)
1667 1.8.2.2 bouyer return (0);
1668 1.8.2.2 bouyer
1669 1.8.2.2 bouyer idx = (int)obp->obj_id;
1670 1.8.2.2 bouyer ep = &ssc->ses_objmap[idx];
1671 1.8.2.2 bouyer
1672 1.8.2.2 bouyer switch (ep->enctype) {
1673 1.8.2.2 bouyer case SESTYP_DEVICE:
1674 1.8.2.2 bouyer {
1675 1.8.2.2 bouyer uint8_t slotop = 0;
1676 1.8.2.2 bouyer /*
1677 1.8.2.2 bouyer * XXX: I should probably cache the previous state
1678 1.8.2.2 bouyer * XXX: of SESCTL_DEVOFF so that when it goes from
1679 1.8.2.2 bouyer * XXX: true to false I can then set PREPARE FOR OPERATION
1680 1.8.2.2 bouyer * XXX: flag in PERFORM SLOT OPERATION write buffer command.
1681 1.8.2.2 bouyer */
1682 1.8.2.2 bouyer if (obp->cstat[2] & (SESCTL_RQSINS|SESCTL_RQSRMV)) {
1683 1.8.2.2 bouyer slotop |= 0x2;
1684 1.8.2.2 bouyer }
1685 1.8.2.2 bouyer if (obp->cstat[2] & SESCTL_RQSID) {
1686 1.8.2.2 bouyer slotop |= 0x4;
1687 1.8.2.2 bouyer }
1688 1.8.2.2 bouyer err = perf_slotop(ssc, (uint8_t) idx - (uint8_t) cc->slotoff,
1689 1.8.2.2 bouyer slotop, slp);
1690 1.8.2.2 bouyer if (err)
1691 1.8.2.2 bouyer return (err);
1692 1.8.2.2 bouyer if (obp->cstat[3] & SESCTL_RQSFLT) {
1693 1.8.2.2 bouyer ep->priv |= 0x2;
1694 1.8.2.2 bouyer } else {
1695 1.8.2.2 bouyer ep->priv &= ~0x2;
1696 1.8.2.2 bouyer }
1697 1.8.2.2 bouyer if (ep->priv & 0xc6) {
1698 1.8.2.2 bouyer ep->priv &= ~0x1;
1699 1.8.2.2 bouyer } else {
1700 1.8.2.2 bouyer ep->priv |= 0x1; /* no errors */
1701 1.8.2.2 bouyer }
1702 1.8.2.2 bouyer wrslot_stat(ssc, slp);
1703 1.8.2.2 bouyer break;
1704 1.8.2.2 bouyer }
1705 1.8.2.2 bouyer case SESTYP_POWER:
1706 1.8.2.2 bouyer if (obp->cstat[3] & SESCTL_RQSTFAIL) {
1707 1.8.2.2 bouyer cc->flag1 |= SAFT_FLG1_ENCPWRFAIL;
1708 1.8.2.2 bouyer } else {
1709 1.8.2.2 bouyer cc->flag1 &= ~SAFT_FLG1_ENCPWRFAIL;
1710 1.8.2.2 bouyer }
1711 1.8.2.2 bouyer err = wrbuf16(ssc, SAFTE_WT_GLOBAL, cc->flag1,
1712 1.8.2.2 bouyer cc->flag2, 0, slp);
1713 1.8.2.2 bouyer if (err)
1714 1.8.2.2 bouyer return (err);
1715 1.8.2.2 bouyer if (obp->cstat[3] & SESCTL_RQSTON) {
1716 1.8.2.2 bouyer (void) wrbuf16(ssc, SAFTE_WT_ACTPWS,
1717 1.8.2.2 bouyer idx - cc->pwroff, 0, 0, slp);
1718 1.8.2.2 bouyer } else {
1719 1.8.2.2 bouyer (void) wrbuf16(ssc, SAFTE_WT_ACTPWS,
1720 1.8.2.2 bouyer idx - cc->pwroff, 0, 1, slp);
1721 1.8.2.2 bouyer }
1722 1.8.2.2 bouyer break;
1723 1.8.2.2 bouyer case SESTYP_FAN:
1724 1.8.2.2 bouyer if (obp->cstat[3] & SESCTL_RQSTFAIL) {
1725 1.8.2.2 bouyer cc->flag1 |= SAFT_FLG1_ENCFANFAIL;
1726 1.8.2.2 bouyer } else {
1727 1.8.2.2 bouyer cc->flag1 &= ~SAFT_FLG1_ENCFANFAIL;
1728 1.8.2.2 bouyer }
1729 1.8.2.2 bouyer err = wrbuf16(ssc, SAFTE_WT_GLOBAL, cc->flag1,
1730 1.8.2.2 bouyer cc->flag2, 0, slp);
1731 1.8.2.2 bouyer if (err)
1732 1.8.2.2 bouyer return (err);
1733 1.8.2.2 bouyer if (obp->cstat[3] & SESCTL_RQSTON) {
1734 1.8.2.2 bouyer uint8_t fsp;
1735 1.8.2.2 bouyer if ((obp->cstat[3] & 0x7) == 7) {
1736 1.8.2.2 bouyer fsp = 4;
1737 1.8.2.2 bouyer } else if ((obp->cstat[3] & 0x7) == 6) {
1738 1.8.2.2 bouyer fsp = 3;
1739 1.8.2.2 bouyer } else if ((obp->cstat[3] & 0x7) == 4) {
1740 1.8.2.2 bouyer fsp = 2;
1741 1.8.2.2 bouyer } else {
1742 1.8.2.2 bouyer fsp = 1;
1743 1.8.2.2 bouyer }
1744 1.8.2.2 bouyer (void) wrbuf16(ssc, SAFTE_WT_FANSPD, idx, fsp, 0, slp);
1745 1.8.2.2 bouyer } else {
1746 1.8.2.2 bouyer (void) wrbuf16(ssc, SAFTE_WT_FANSPD, idx, 0, 0, slp);
1747 1.8.2.2 bouyer }
1748 1.8.2.2 bouyer break;
1749 1.8.2.2 bouyer case SESTYP_DOORLOCK:
1750 1.8.2.2 bouyer if (obp->cstat[3] & 0x1) {
1751 1.8.2.2 bouyer cc->flag2 &= ~SAFT_FLG2_LOCKDOOR;
1752 1.8.2.2 bouyer } else {
1753 1.8.2.2 bouyer cc->flag2 |= SAFT_FLG2_LOCKDOOR;
1754 1.8.2.2 bouyer }
1755 1.8.2.2 bouyer (void) wrbuf16(ssc, SAFTE_WT_GLOBAL, cc->flag1,
1756 1.8.2.2 bouyer cc->flag2, 0, slp);
1757 1.8.2.2 bouyer break;
1758 1.8.2.2 bouyer case SESTYP_ALARM:
1759 1.8.2.2 bouyer /*
1760 1.8.2.2 bouyer * On all nonzero but the 'muted' bit, we turn on the alarm,
1761 1.8.2.2 bouyer */
1762 1.8.2.2 bouyer obp->cstat[3] &= ~0xa;
1763 1.8.2.2 bouyer if (obp->cstat[3] & 0x40) {
1764 1.8.2.2 bouyer cc->flag2 &= ~SAFT_FLG1_ALARM;
1765 1.8.2.2 bouyer } else if (obp->cstat[3] != 0) {
1766 1.8.2.2 bouyer cc->flag2 |= SAFT_FLG1_ALARM;
1767 1.8.2.2 bouyer } else {
1768 1.8.2.2 bouyer cc->flag2 &= ~SAFT_FLG1_ALARM;
1769 1.8.2.2 bouyer }
1770 1.8.2.2 bouyer ep->priv = obp->cstat[3];
1771 1.8.2.2 bouyer (void) wrbuf16(ssc, SAFTE_WT_GLOBAL, cc->flag1,
1772 1.8.2.2 bouyer cc->flag2, 0, slp);
1773 1.8.2.2 bouyer break;
1774 1.8.2.2 bouyer default:
1775 1.8.2.2 bouyer break;
1776 1.8.2.2 bouyer }
1777 1.8.2.2 bouyer ep->svalid = 0;
1778 1.8.2.2 bouyer return (0);
1779 1.8.2.2 bouyer }
1780 1.8.2.2 bouyer
1781 1.8.2.2 bouyer static int
1782 1.8.2.2 bouyer safte_getconfig(ses_softc_t *ssc)
1783 1.8.2.2 bouyer {
1784 1.8.2.2 bouyer struct scfg *cfg;
1785 1.8.2.2 bouyer int err, amt;
1786 1.8.2.2 bouyer char *sdata;
1787 1.8.2.2 bouyer static char cdb[10] =
1788 1.8.2.2 bouyer { READ_BUFFER, 1, SAFTE_RD_RDCFG, 0, 0, 0, 0, 0, SAFT_SCRATCH, 0 };
1789 1.8.2.2 bouyer
1790 1.8.2.2 bouyer cfg = ssc->ses_private;
1791 1.8.2.2 bouyer if (cfg == NULL)
1792 1.8.2.2 bouyer return (ENXIO);
1793 1.8.2.2 bouyer
1794 1.8.2.2 bouyer sdata = SES_MALLOC(SAFT_SCRATCH);
1795 1.8.2.2 bouyer if (sdata == NULL)
1796 1.8.2.2 bouyer return (ENOMEM);
1797 1.8.2.2 bouyer
1798 1.8.2.2 bouyer amt = SAFT_SCRATCH;
1799 1.8.2.2 bouyer err = ses_runcmd(ssc, cdb, 10, sdata, &amt);
1800 1.8.2.2 bouyer if (err) {
1801 1.8.2.2 bouyer SES_FREE(sdata, SAFT_SCRATCH);
1802 1.8.2.2 bouyer return (err);
1803 1.8.2.2 bouyer }
1804 1.8.2.2 bouyer amt = SAFT_SCRATCH - amt;
1805 1.8.2.2 bouyer if (amt < 6) {
1806 1.8.2.2 bouyer SES_LOG(ssc, "too little data (%d) for configuration\n", amt);
1807 1.8.2.2 bouyer SES_FREE(sdata, SAFT_SCRATCH);
1808 1.8.2.2 bouyer return (EIO);
1809 1.8.2.2 bouyer }
1810 1.8.2.2 bouyer SES_VLOG(ssc, "Nfans %d Npwr %d Nslots %d Lck %d Ntherm %d Nspkrs %d\n",
1811 1.8.2.2 bouyer sdata[0], sdata[1], sdata[2], sdata[3], sdata[4], sdata[5]);
1812 1.8.2.2 bouyer cfg->Nfans = sdata[0];
1813 1.8.2.2 bouyer cfg->Npwr = sdata[1];
1814 1.8.2.2 bouyer cfg->Nslots = sdata[2];
1815 1.8.2.2 bouyer cfg->DoorLock = sdata[3];
1816 1.8.2.2 bouyer cfg->Ntherm = sdata[4];
1817 1.8.2.2 bouyer cfg->Nspkrs = sdata[5];
1818 1.8.2.2 bouyer cfg->Nalarm = NPSEUDO_ALARM;
1819 1.8.2.2 bouyer SES_FREE(sdata, SAFT_SCRATCH);
1820 1.8.2.2 bouyer return (0);
1821 1.8.2.2 bouyer }
1822 1.8.2.2 bouyer
1823 1.8.2.2 bouyer static int
1824 1.8.2.2 bouyer safte_rdstat(ses_softc_t *ssc, int slpflg)
1825 1.8.2.2 bouyer {
1826 1.8.2.2 bouyer int err, oid, r, i, hiwater, nitems, amt;
1827 1.8.2.2 bouyer uint16_t tempflags;
1828 1.8.2.2 bouyer size_t buflen;
1829 1.8.2.2 bouyer uint8_t status, oencstat;
1830 1.8.2.2 bouyer char *sdata, cdb[10];
1831 1.8.2.2 bouyer struct scfg *cc = ssc->ses_private;
1832 1.8.2.2 bouyer
1833 1.8.2.2 bouyer
1834 1.8.2.2 bouyer /*
1835 1.8.2.2 bouyer * The number of objects overstates things a bit,
1836 1.8.2.2 bouyer * both for the bogus 'thermometer' entries and
1837 1.8.2.2 bouyer * the drive status (which isn't read at the same
1838 1.8.2.2 bouyer * time as the enclosure status), but that's okay.
1839 1.8.2.2 bouyer */
1840 1.8.2.2 bouyer buflen = 4 * cc->Nslots;
1841 1.8.2.2 bouyer if (ssc->ses_nobjects > buflen)
1842 1.8.2.2 bouyer buflen = ssc->ses_nobjects;
1843 1.8.2.2 bouyer sdata = SES_MALLOC(buflen);
1844 1.8.2.2 bouyer if (sdata == NULL)
1845 1.8.2.2 bouyer return (ENOMEM);
1846 1.8.2.2 bouyer
1847 1.8.2.2 bouyer cdb[0] = READ_BUFFER;
1848 1.8.2.2 bouyer cdb[1] = 1;
1849 1.8.2.2 bouyer cdb[2] = SAFTE_RD_RDESTS;
1850 1.8.2.2 bouyer cdb[3] = 0;
1851 1.8.2.2 bouyer cdb[4] = 0;
1852 1.8.2.2 bouyer cdb[5] = 0;
1853 1.8.2.2 bouyer cdb[6] = 0;
1854 1.8.2.2 bouyer cdb[7] = (buflen >> 8) & 0xff;
1855 1.8.2.2 bouyer cdb[8] = buflen & 0xff;
1856 1.8.2.2 bouyer cdb[9] = 0;
1857 1.8.2.2 bouyer amt = buflen;
1858 1.8.2.2 bouyer err = ses_runcmd(ssc, cdb, 10, sdata, &amt);
1859 1.8.2.2 bouyer if (err) {
1860 1.8.2.2 bouyer SES_FREE(sdata, buflen);
1861 1.8.2.2 bouyer return (err);
1862 1.8.2.2 bouyer }
1863 1.8.2.2 bouyer hiwater = buflen - amt;
1864 1.8.2.2 bouyer
1865 1.8.2.2 bouyer
1866 1.8.2.2 bouyer /*
1867 1.8.2.2 bouyer * invalidate all status bits.
1868 1.8.2.2 bouyer */
1869 1.8.2.2 bouyer for (i = 0; i < ssc->ses_nobjects; i++)
1870 1.8.2.2 bouyer ssc->ses_objmap[i].svalid = 0;
1871 1.8.2.2 bouyer oencstat = ssc->ses_encstat & ALL_ENC_STAT;
1872 1.8.2.2 bouyer ssc->ses_encstat = 0;
1873 1.8.2.2 bouyer
1874 1.8.2.2 bouyer
1875 1.8.2.2 bouyer /*
1876 1.8.2.2 bouyer * Now parse returned buffer.
1877 1.8.2.2 bouyer * If we didn't get enough data back,
1878 1.8.2.2 bouyer * that's considered a fatal error.
1879 1.8.2.2 bouyer */
1880 1.8.2.2 bouyer oid = r = 0;
1881 1.8.2.2 bouyer
1882 1.8.2.2 bouyer for (nitems = i = 0; i < cc->Nfans; i++) {
1883 1.8.2.2 bouyer SAFT_BAIL(r, hiwater, sdata, buflen);
1884 1.8.2.2 bouyer /*
1885 1.8.2.2 bouyer * 0 = Fan Operational
1886 1.8.2.2 bouyer * 1 = Fan is malfunctioning
1887 1.8.2.2 bouyer * 2 = Fan is not present
1888 1.8.2.2 bouyer * 0x80 = Unknown or Not Reportable Status
1889 1.8.2.2 bouyer */
1890 1.8.2.2 bouyer ssc->ses_objmap[oid].encstat[1] = 0; /* resvd */
1891 1.8.2.2 bouyer ssc->ses_objmap[oid].encstat[2] = 0; /* resvd */
1892 1.8.2.2 bouyer switch ((int)(uint8_t)sdata[r]) {
1893 1.8.2.2 bouyer case 0:
1894 1.8.2.2 bouyer nitems++;
1895 1.8.2.2 bouyer ssc->ses_objmap[oid].encstat[0] = SES_OBJSTAT_OK;
1896 1.8.2.2 bouyer /*
1897 1.8.2.2 bouyer * We could get fancier and cache
1898 1.8.2.2 bouyer * fan speeds that we have set, but
1899 1.8.2.2 bouyer * that isn't done now.
1900 1.8.2.2 bouyer */
1901 1.8.2.2 bouyer ssc->ses_objmap[oid].encstat[3] = 7;
1902 1.8.2.2 bouyer break;
1903 1.8.2.2 bouyer
1904 1.8.2.2 bouyer case 1:
1905 1.8.2.2 bouyer ssc->ses_objmap[oid].encstat[0] = SES_OBJSTAT_CRIT;
1906 1.8.2.2 bouyer /*
1907 1.8.2.2 bouyer * FAIL and FAN STOPPED synthesized
1908 1.8.2.2 bouyer */
1909 1.8.2.2 bouyer ssc->ses_objmap[oid].encstat[3] = 0x40;
1910 1.8.2.2 bouyer /*
1911 1.8.2.2 bouyer * Enclosure marked with CRITICAL error
1912 1.8.2.2 bouyer * if only one fan or no thermometers,
1913 1.8.2.2 bouyer * else the NONCRITICAL error is set.
1914 1.8.2.2 bouyer */
1915 1.8.2.2 bouyer if (cc->Nfans == 1 || cc->Ntherm == 0)
1916 1.8.2.2 bouyer ssc->ses_encstat |= SES_ENCSTAT_CRITICAL;
1917 1.8.2.2 bouyer else
1918 1.8.2.2 bouyer ssc->ses_encstat |= SES_ENCSTAT_NONCRITICAL;
1919 1.8.2.2 bouyer break;
1920 1.8.2.2 bouyer case 2:
1921 1.8.2.2 bouyer ssc->ses_objmap[oid].encstat[0] =
1922 1.8.2.2 bouyer SES_OBJSTAT_NOTINSTALLED;
1923 1.8.2.2 bouyer ssc->ses_objmap[oid].encstat[3] = 0;
1924 1.8.2.2 bouyer /*
1925 1.8.2.2 bouyer * Enclosure marked with CRITICAL error
1926 1.8.2.2 bouyer * if only one fan or no thermometers,
1927 1.8.2.2 bouyer * else the NONCRITICAL error is set.
1928 1.8.2.2 bouyer */
1929 1.8.2.2 bouyer if (cc->Nfans == 1)
1930 1.8.2.2 bouyer ssc->ses_encstat |= SES_ENCSTAT_CRITICAL;
1931 1.8.2.2 bouyer else
1932 1.8.2.2 bouyer ssc->ses_encstat |= SES_ENCSTAT_NONCRITICAL;
1933 1.8.2.2 bouyer break;
1934 1.8.2.2 bouyer case 0x80:
1935 1.8.2.2 bouyer ssc->ses_objmap[oid].encstat[0] = SES_OBJSTAT_UNKNOWN;
1936 1.8.2.2 bouyer ssc->ses_objmap[oid].encstat[3] = 0;
1937 1.8.2.2 bouyer ssc->ses_encstat |= SES_ENCSTAT_INFO;
1938 1.8.2.2 bouyer break;
1939 1.8.2.2 bouyer default:
1940 1.8.2.2 bouyer ssc->ses_objmap[oid].encstat[0] =
1941 1.8.2.2 bouyer SES_OBJSTAT_UNSUPPORTED;
1942 1.8.2.2 bouyer SES_LOG(ssc, "Unknown fan%d status 0x%x\n", i,
1943 1.8.2.2 bouyer sdata[r] & 0xff);
1944 1.8.2.2 bouyer break;
1945 1.8.2.2 bouyer }
1946 1.8.2.2 bouyer ssc->ses_objmap[oid++].svalid = 1;
1947 1.8.2.2 bouyer r++;
1948 1.8.2.2 bouyer }
1949 1.8.2.2 bouyer
1950 1.8.2.2 bouyer /*
1951 1.8.2.2 bouyer * No matter how you cut it, no cooling elements when there
1952 1.8.2.2 bouyer * should be some there is critical.
1953 1.8.2.2 bouyer */
1954 1.8.2.2 bouyer if (cc->Nfans && nitems == 0) {
1955 1.8.2.2 bouyer ssc->ses_encstat |= SES_ENCSTAT_CRITICAL;
1956 1.8.2.2 bouyer }
1957 1.8.2.2 bouyer
1958 1.8.2.2 bouyer
1959 1.8.2.2 bouyer for (i = 0; i < cc->Npwr; i++) {
1960 1.8.2.2 bouyer SAFT_BAIL(r, hiwater, sdata, buflen);
1961 1.8.2.2 bouyer ssc->ses_objmap[oid].encstat[0] = SES_OBJSTAT_UNKNOWN;
1962 1.8.2.2 bouyer ssc->ses_objmap[oid].encstat[1] = 0; /* resvd */
1963 1.8.2.2 bouyer ssc->ses_objmap[oid].encstat[2] = 0; /* resvd */
1964 1.8.2.2 bouyer ssc->ses_objmap[oid].encstat[3] = 0x20; /* requested on */
1965 1.8.2.2 bouyer switch ((uint8_t)sdata[r]) {
1966 1.8.2.2 bouyer case 0x00: /* pws operational and on */
1967 1.8.2.2 bouyer ssc->ses_objmap[oid].encstat[0] = SES_OBJSTAT_OK;
1968 1.8.2.2 bouyer break;
1969 1.8.2.2 bouyer case 0x01: /* pws operational and off */
1970 1.8.2.2 bouyer ssc->ses_objmap[oid].encstat[0] = SES_OBJSTAT_OK;
1971 1.8.2.2 bouyer ssc->ses_objmap[oid].encstat[3] = 0x10;
1972 1.8.2.2 bouyer ssc->ses_encstat |= SES_ENCSTAT_INFO;
1973 1.8.2.2 bouyer break;
1974 1.8.2.2 bouyer case 0x10: /* pws is malfunctioning and commanded on */
1975 1.8.2.2 bouyer ssc->ses_objmap[oid].encstat[0] = SES_OBJSTAT_CRIT;
1976 1.8.2.2 bouyer ssc->ses_objmap[oid].encstat[3] = 0x61;
1977 1.8.2.2 bouyer ssc->ses_encstat |= SES_ENCSTAT_NONCRITICAL;
1978 1.8.2.2 bouyer break;
1979 1.8.2.2 bouyer
1980 1.8.2.2 bouyer case 0x11: /* pws is malfunctioning and commanded off */
1981 1.8.2.2 bouyer ssc->ses_objmap[oid].encstat[0] = SES_OBJSTAT_NONCRIT;
1982 1.8.2.2 bouyer ssc->ses_objmap[oid].encstat[3] = 0x51;
1983 1.8.2.2 bouyer ssc->ses_encstat |= SES_ENCSTAT_NONCRITICAL;
1984 1.8.2.2 bouyer break;
1985 1.8.2.2 bouyer case 0x20: /* pws is not present */
1986 1.8.2.2 bouyer ssc->ses_objmap[oid].encstat[0] =
1987 1.8.2.2 bouyer SES_OBJSTAT_NOTINSTALLED;
1988 1.8.2.2 bouyer ssc->ses_objmap[oid].encstat[3] = 0;
1989 1.8.2.2 bouyer ssc->ses_encstat |= SES_ENCSTAT_INFO;
1990 1.8.2.2 bouyer break;
1991 1.8.2.2 bouyer case 0x21: /* pws is present */
1992 1.8.2.2 bouyer /*
1993 1.8.2.2 bouyer * This is for enclosures that cannot tell whether the
1994 1.8.2.2 bouyer * device is on or malfunctioning, but know that it is
1995 1.8.2.2 bouyer * present. Just fall through.
1996 1.8.2.2 bouyer */
1997 1.8.2.2 bouyer /* FALLTHROUGH */
1998 1.8.2.2 bouyer case 0x80: /* Unknown or Not Reportable Status */
1999 1.8.2.2 bouyer ssc->ses_objmap[oid].encstat[0] = SES_OBJSTAT_UNKNOWN;
2000 1.8.2.2 bouyer ssc->ses_objmap[oid].encstat[3] = 0;
2001 1.8.2.2 bouyer ssc->ses_encstat |= SES_ENCSTAT_INFO;
2002 1.8.2.2 bouyer break;
2003 1.8.2.2 bouyer default:
2004 1.8.2.2 bouyer SES_LOG(ssc, "unknown power supply %d status (0x%x)\n",
2005 1.8.2.2 bouyer i, sdata[r] & 0xff);
2006 1.8.2.2 bouyer break;
2007 1.8.2.2 bouyer }
2008 1.8.2.2 bouyer ssc->ses_objmap[oid++].svalid = 1;
2009 1.8.2.2 bouyer r++;
2010 1.8.2.2 bouyer }
2011 1.8.2.2 bouyer
2012 1.8.2.2 bouyer /*
2013 1.8.2.2 bouyer * Skip over Slot SCSI IDs
2014 1.8.2.2 bouyer */
2015 1.8.2.2 bouyer r += cc->Nslots;
2016 1.8.2.2 bouyer
2017 1.8.2.2 bouyer /*
2018 1.8.2.2 bouyer * We always have doorlock status, no matter what,
2019 1.8.2.2 bouyer * but we only save the status if we have one.
2020 1.8.2.2 bouyer */
2021 1.8.2.2 bouyer SAFT_BAIL(r, hiwater, sdata, buflen);
2022 1.8.2.2 bouyer if (cc->DoorLock) {
2023 1.8.2.2 bouyer /*
2024 1.8.2.2 bouyer * 0 = Door Locked
2025 1.8.2.2 bouyer * 1 = Door Unlocked, or no Lock Installed
2026 1.8.2.2 bouyer * 0x80 = Unknown or Not Reportable Status
2027 1.8.2.2 bouyer */
2028 1.8.2.2 bouyer ssc->ses_objmap[oid].encstat[1] = 0;
2029 1.8.2.2 bouyer ssc->ses_objmap[oid].encstat[2] = 0;
2030 1.8.2.2 bouyer switch ((uint8_t)sdata[r]) {
2031 1.8.2.2 bouyer case 0:
2032 1.8.2.2 bouyer ssc->ses_objmap[oid].encstat[0] = SES_OBJSTAT_OK;
2033 1.8.2.2 bouyer ssc->ses_objmap[oid].encstat[3] = 0;
2034 1.8.2.2 bouyer break;
2035 1.8.2.2 bouyer case 1:
2036 1.8.2.2 bouyer ssc->ses_objmap[oid].encstat[0] = SES_OBJSTAT_OK;
2037 1.8.2.2 bouyer ssc->ses_objmap[oid].encstat[3] = 1;
2038 1.8.2.2 bouyer break;
2039 1.8.2.2 bouyer case 0x80:
2040 1.8.2.2 bouyer ssc->ses_objmap[oid].encstat[0] = SES_OBJSTAT_UNKNOWN;
2041 1.8.2.2 bouyer ssc->ses_objmap[oid].encstat[3] = 0;
2042 1.8.2.2 bouyer ssc->ses_encstat |= SES_ENCSTAT_INFO;
2043 1.8.2.2 bouyer break;
2044 1.8.2.2 bouyer default:
2045 1.8.2.2 bouyer ssc->ses_objmap[oid].encstat[0] =
2046 1.8.2.2 bouyer SES_OBJSTAT_UNSUPPORTED;
2047 1.8.2.2 bouyer SES_LOG(ssc, "unknown lock status 0x%x\n",
2048 1.8.2.2 bouyer sdata[r] & 0xff);
2049 1.8.2.2 bouyer break;
2050 1.8.2.2 bouyer }
2051 1.8.2.2 bouyer ssc->ses_objmap[oid++].svalid = 1;
2052 1.8.2.2 bouyer }
2053 1.8.2.2 bouyer r++;
2054 1.8.2.2 bouyer
2055 1.8.2.2 bouyer /*
2056 1.8.2.2 bouyer * We always have speaker status, no matter what,
2057 1.8.2.2 bouyer * but we only save the status if we have one.
2058 1.8.2.2 bouyer */
2059 1.8.2.2 bouyer SAFT_BAIL(r, hiwater, sdata, buflen);
2060 1.8.2.2 bouyer if (cc->Nspkrs) {
2061 1.8.2.2 bouyer ssc->ses_objmap[oid].encstat[1] = 0;
2062 1.8.2.2 bouyer ssc->ses_objmap[oid].encstat[2] = 0;
2063 1.8.2.2 bouyer if (sdata[r] == 1) {
2064 1.8.2.2 bouyer /*
2065 1.8.2.2 bouyer * We need to cache tone urgency indicators.
2066 1.8.2.2 bouyer * Someday.
2067 1.8.2.2 bouyer */
2068 1.8.2.2 bouyer ssc->ses_objmap[oid].encstat[0] = SES_OBJSTAT_NONCRIT;
2069 1.8.2.2 bouyer ssc->ses_objmap[oid].encstat[3] = 0x8;
2070 1.8.2.2 bouyer ssc->ses_encstat |= SES_ENCSTAT_NONCRITICAL;
2071 1.8.2.2 bouyer } else if (sdata[r] == 0) {
2072 1.8.2.2 bouyer ssc->ses_objmap[oid].encstat[0] = SES_OBJSTAT_OK;
2073 1.8.2.2 bouyer ssc->ses_objmap[oid].encstat[3] = 0;
2074 1.8.2.2 bouyer } else {
2075 1.8.2.2 bouyer ssc->ses_objmap[oid].encstat[0] =
2076 1.8.2.2 bouyer SES_OBJSTAT_UNSUPPORTED;
2077 1.8.2.2 bouyer ssc->ses_objmap[oid].encstat[3] = 0;
2078 1.8.2.2 bouyer SES_LOG(ssc, "unknown spkr status 0x%x\n",
2079 1.8.2.2 bouyer sdata[r] & 0xff);
2080 1.8.2.2 bouyer }
2081 1.8.2.2 bouyer ssc->ses_objmap[oid++].svalid = 1;
2082 1.8.2.2 bouyer }
2083 1.8.2.2 bouyer r++;
2084 1.8.2.2 bouyer
2085 1.8.2.2 bouyer for (i = 0; i < cc->Ntherm; i++) {
2086 1.8.2.2 bouyer SAFT_BAIL(r, hiwater, sdata, buflen);
2087 1.8.2.2 bouyer /*
2088 1.8.2.2 bouyer * Status is a range from -10 to 245 deg Celsius,
2089 1.8.2.2 bouyer * which we need to normalize to -20 to -245 according
2090 1.8.2.2 bouyer * to the latest SCSI spec, which makes little
2091 1.8.2.2 bouyer * sense since this would overflow an 8bit value.
2092 1.8.2.2 bouyer * Well, still, the base normalization is -20,
2093 1.8.2.2 bouyer * not -10, so we have to adjust.
2094 1.8.2.2 bouyer *
2095 1.8.2.2 bouyer * So what's over and under temperature?
2096 1.8.2.2 bouyer * Hmm- we'll state that 'normal' operating
2097 1.8.2.2 bouyer * is 10 to 40 deg Celsius.
2098 1.8.2.2 bouyer */
2099 1.8.2.2 bouyer
2100 1.8.2.2 bouyer /*
2101 1.8.2.2 bouyer * Actually.... All of the units that people out in the world
2102 1.8.2.2 bouyer * seem to have do not come even close to setting a value that
2103 1.8.2.2 bouyer * complies with this spec.
2104 1.8.2.2 bouyer *
2105 1.8.2.2 bouyer * The closest explanation I could find was in an
2106 1.8.2.2 bouyer * LSI-Logic manual, which seemed to indicate that
2107 1.8.2.2 bouyer * this value would be set by whatever the I2C code
2108 1.8.2.2 bouyer * would interpolate from the output of an LM75
2109 1.8.2.2 bouyer * temperature sensor.
2110 1.8.2.2 bouyer *
2111 1.8.2.2 bouyer * This means that it is impossible to use the actual
2112 1.8.2.2 bouyer * numeric value to predict anything. But we don't want
2113 1.8.2.2 bouyer * to lose the value. So, we'll propagate the *uncorrected*
2114 1.8.2.2 bouyer * value and set SES_OBJSTAT_NOTAVAIL. We'll depend on the
2115 1.8.2.2 bouyer * temperature flags for warnings.
2116 1.8.2.2 bouyer */
2117 1.8.2.2 bouyer ssc->ses_objmap[oid].encstat[0] = SES_OBJSTAT_NOTAVAIL;
2118 1.8.2.2 bouyer ssc->ses_objmap[oid].encstat[1] = 0;
2119 1.8.2.2 bouyer ssc->ses_objmap[oid].encstat[2] = sdata[r];
2120 1.8.2.2 bouyer ssc->ses_objmap[oid].encstat[3] = 0;;
2121 1.8.2.2 bouyer ssc->ses_objmap[oid++].svalid = 1;
2122 1.8.2.2 bouyer r++;
2123 1.8.2.2 bouyer }
2124 1.8.2.2 bouyer
2125 1.8.2.2 bouyer /*
2126 1.8.2.2 bouyer * Now, for "pseudo" thermometers, we have two bytes
2127 1.8.2.2 bouyer * of information in enclosure status- 16 bits. Actually,
2128 1.8.2.2 bouyer * the MSB is a single TEMP ALERT flag indicating whether
2129 1.8.2.2 bouyer * any other bits are set, but, thanks to fuzzy thinking,
2130 1.8.2.2 bouyer * in the SAF-TE spec, this can also be set even if no
2131 1.8.2.2 bouyer * other bits are set, thus making this really another
2132 1.8.2.2 bouyer * binary temperature sensor.
2133 1.8.2.2 bouyer */
2134 1.8.2.2 bouyer
2135 1.8.2.2 bouyer SAFT_BAIL(r, hiwater, sdata, buflen);
2136 1.8.2.2 bouyer tempflags = sdata[r++];
2137 1.8.2.2 bouyer SAFT_BAIL(r, hiwater, sdata, buflen);
2138 1.8.2.2 bouyer tempflags |= (tempflags << 8) | sdata[r++];
2139 1.8.2.2 bouyer
2140 1.8.2.2 bouyer for (i = 0; i < NPSEUDO_THERM; i++) {
2141 1.8.2.2 bouyer ssc->ses_objmap[oid].encstat[1] = 0;
2142 1.8.2.2 bouyer if (tempflags & (1 << (NPSEUDO_THERM - i - 1))) {
2143 1.8.2.2 bouyer ssc->ses_objmap[oid].encstat[0] = SES_OBJSTAT_CRIT;
2144 1.8.2.2 bouyer ssc->ses_objmap[4].encstat[2] = 0xff;
2145 1.8.2.2 bouyer /*
2146 1.8.2.2 bouyer * Set 'over temperature' failure.
2147 1.8.2.2 bouyer */
2148 1.8.2.2 bouyer ssc->ses_objmap[oid].encstat[3] = 8;
2149 1.8.2.2 bouyer ssc->ses_encstat |= SES_ENCSTAT_CRITICAL;
2150 1.8.2.2 bouyer } else {
2151 1.8.2.2 bouyer /*
2152 1.8.2.2 bouyer * We used to say 'not available' and synthesize a
2153 1.8.2.2 bouyer * nominal 30 deg (C)- that was wrong. Actually,
2154 1.8.2.2 bouyer * Just say 'OK', and use the reserved value of
2155 1.8.2.2 bouyer * zero.
2156 1.8.2.2 bouyer */
2157 1.8.2.2 bouyer ssc->ses_objmap[oid].encstat[0] = SES_OBJSTAT_OK;
2158 1.8.2.2 bouyer ssc->ses_objmap[oid].encstat[2] = 0;
2159 1.8.2.2 bouyer ssc->ses_objmap[oid].encstat[3] = 0;
2160 1.8.2.2 bouyer }
2161 1.8.2.2 bouyer ssc->ses_objmap[oid++].svalid = 1;
2162 1.8.2.2 bouyer }
2163 1.8.2.2 bouyer
2164 1.8.2.2 bouyer /*
2165 1.8.2.2 bouyer * Get alarm status.
2166 1.8.2.2 bouyer */
2167 1.8.2.2 bouyer ssc->ses_objmap[oid].encstat[0] = SES_OBJSTAT_OK;
2168 1.8.2.2 bouyer ssc->ses_objmap[oid].encstat[3] = ssc->ses_objmap[oid].priv;
2169 1.8.2.2 bouyer ssc->ses_objmap[oid++].svalid = 1;
2170 1.8.2.2 bouyer
2171 1.8.2.2 bouyer /*
2172 1.8.2.2 bouyer * Now get drive slot status
2173 1.8.2.2 bouyer */
2174 1.8.2.2 bouyer cdb[2] = SAFTE_RD_RDDSTS;
2175 1.8.2.2 bouyer amt = buflen;
2176 1.8.2.2 bouyer err = ses_runcmd(ssc, cdb, 10, sdata, &amt);
2177 1.8.2.2 bouyer if (err) {
2178 1.8.2.2 bouyer SES_FREE(sdata, buflen);
2179 1.8.2.2 bouyer return (err);
2180 1.8.2.2 bouyer }
2181 1.8.2.2 bouyer hiwater = buflen - amt;
2182 1.8.2.2 bouyer for (r = i = 0; i < cc->Nslots; i++, r += 4) {
2183 1.8.2.2 bouyer SAFT_BAIL(r+3, hiwater, sdata, buflen);
2184 1.8.2.2 bouyer ssc->ses_objmap[oid].encstat[0] = SES_OBJSTAT_UNSUPPORTED;
2185 1.8.2.2 bouyer ssc->ses_objmap[oid].encstat[1] = (uint8_t) i;
2186 1.8.2.2 bouyer ssc->ses_objmap[oid].encstat[2] = 0;
2187 1.8.2.2 bouyer ssc->ses_objmap[oid].encstat[3] = 0;
2188 1.8.2.2 bouyer status = sdata[r+3];
2189 1.8.2.2 bouyer if ((status & 0x1) == 0) { /* no device */
2190 1.8.2.2 bouyer ssc->ses_objmap[oid].encstat[0] =
2191 1.8.2.2 bouyer SES_OBJSTAT_NOTINSTALLED;
2192 1.8.2.2 bouyer } else {
2193 1.8.2.2 bouyer ssc->ses_objmap[oid].encstat[0] = SES_OBJSTAT_OK;
2194 1.8.2.2 bouyer }
2195 1.8.2.2 bouyer if (status & 0x2) {
2196 1.8.2.2 bouyer ssc->ses_objmap[oid].encstat[2] = 0x8;
2197 1.8.2.2 bouyer }
2198 1.8.2.2 bouyer if ((status & 0x4) == 0) {
2199 1.8.2.2 bouyer ssc->ses_objmap[oid].encstat[3] = 0x10;
2200 1.8.2.2 bouyer }
2201 1.8.2.2 bouyer ssc->ses_objmap[oid++].svalid = 1;
2202 1.8.2.2 bouyer }
2203 1.8.2.2 bouyer /* see comment below about sticky enclosure status */
2204 1.8.2.2 bouyer ssc->ses_encstat |= ENCI_SVALID | oencstat;
2205 1.8.2.2 bouyer SES_FREE(sdata, buflen);
2206 1.8.2.2 bouyer return (0);
2207 1.8.2.2 bouyer }
2208 1.8.2.2 bouyer
2209 1.8.2.2 bouyer static int
2210 1.8.2.2 bouyer set_objstat_sel(ses_softc_t *ssc, ses_objstat *obp, int slp)
2211 1.8.2.2 bouyer {
2212 1.8.2.2 bouyer int idx;
2213 1.8.2.2 bouyer encobj *ep;
2214 1.8.2.2 bouyer struct scfg *cc = ssc->ses_private;
2215 1.8.2.2 bouyer
2216 1.8.2.2 bouyer if (cc == NULL)
2217 1.8.2.2 bouyer return (0);
2218 1.8.2.2 bouyer
2219 1.8.2.2 bouyer idx = (int)obp->obj_id;
2220 1.8.2.2 bouyer ep = &ssc->ses_objmap[idx];
2221 1.8.2.2 bouyer
2222 1.8.2.2 bouyer switch (ep->enctype) {
2223 1.8.2.2 bouyer case SESTYP_DEVICE:
2224 1.8.2.2 bouyer if (obp->cstat[0] & SESCTL_PRDFAIL) {
2225 1.8.2.2 bouyer ep->priv |= 0x40;
2226 1.8.2.2 bouyer }
2227 1.8.2.2 bouyer /* SESCTL_RSTSWAP has no correspondence in SAF-TE */
2228 1.8.2.2 bouyer if (obp->cstat[0] & SESCTL_DISABLE) {
2229 1.8.2.2 bouyer ep->priv |= 0x80;
2230 1.8.2.2 bouyer /*
2231 1.8.2.2 bouyer * Hmm. Try to set the 'No Drive' flag.
2232 1.8.2.2 bouyer * Maybe that will count as a 'disable'.
2233 1.8.2.2 bouyer */
2234 1.8.2.2 bouyer }
2235 1.8.2.2 bouyer if (ep->priv & 0xc6) {
2236 1.8.2.2 bouyer ep->priv &= ~0x1;
2237 1.8.2.2 bouyer } else {
2238 1.8.2.2 bouyer ep->priv |= 0x1; /* no errors */
2239 1.8.2.2 bouyer }
2240 1.8.2.2 bouyer wrslot_stat(ssc, slp);
2241 1.8.2.2 bouyer break;
2242 1.8.2.2 bouyer case SESTYP_POWER:
2243 1.8.2.2 bouyer /*
2244 1.8.2.2 bouyer * Okay- the only one that makes sense here is to
2245 1.8.2.2 bouyer * do the 'disable' for a power supply.
2246 1.8.2.2 bouyer */
2247 1.8.2.2 bouyer if (obp->cstat[0] & SESCTL_DISABLE) {
2248 1.8.2.2 bouyer (void) wrbuf16(ssc, SAFTE_WT_ACTPWS,
2249 1.8.2.2 bouyer idx - cc->pwroff, 0, 0, slp);
2250 1.8.2.2 bouyer }
2251 1.8.2.2 bouyer break;
2252 1.8.2.2 bouyer case SESTYP_FAN:
2253 1.8.2.2 bouyer /*
2254 1.8.2.2 bouyer * Okay- the only one that makes sense here is to
2255 1.8.2.2 bouyer * set fan speed to zero on disable.
2256 1.8.2.2 bouyer */
2257 1.8.2.2 bouyer if (obp->cstat[0] & SESCTL_DISABLE) {
2258 1.8.2.2 bouyer /* remember- fans are the first items, so idx works */
2259 1.8.2.2 bouyer (void) wrbuf16(ssc, SAFTE_WT_FANSPD, idx, 0, 0, slp);
2260 1.8.2.2 bouyer }
2261 1.8.2.2 bouyer break;
2262 1.8.2.2 bouyer case SESTYP_DOORLOCK:
2263 1.8.2.2 bouyer /*
2264 1.8.2.2 bouyer * Well, we can 'disable' the lock.
2265 1.8.2.2 bouyer */
2266 1.8.2.2 bouyer if (obp->cstat[0] & SESCTL_DISABLE) {
2267 1.8.2.2 bouyer cc->flag2 &= ~SAFT_FLG2_LOCKDOOR;
2268 1.8.2.2 bouyer (void) wrbuf16(ssc, SAFTE_WT_GLOBAL, cc->flag1,
2269 1.8.2.2 bouyer cc->flag2, 0, slp);
2270 1.8.2.2 bouyer }
2271 1.8.2.2 bouyer break;
2272 1.8.2.2 bouyer case SESTYP_ALARM:
2273 1.8.2.2 bouyer /*
2274 1.8.2.2 bouyer * Well, we can 'disable' the alarm.
2275 1.8.2.2 bouyer */
2276 1.8.2.2 bouyer if (obp->cstat[0] & SESCTL_DISABLE) {
2277 1.8.2.2 bouyer cc->flag2 &= ~SAFT_FLG1_ALARM;
2278 1.8.2.2 bouyer ep->priv |= 0x40; /* Muted */
2279 1.8.2.2 bouyer (void) wrbuf16(ssc, SAFTE_WT_GLOBAL, cc->flag1,
2280 1.8.2.2 bouyer cc->flag2, 0, slp);
2281 1.8.2.2 bouyer }
2282 1.8.2.2 bouyer break;
2283 1.8.2.2 bouyer default:
2284 1.8.2.2 bouyer break;
2285 1.8.2.2 bouyer }
2286 1.8.2.2 bouyer ep->svalid = 0;
2287 1.8.2.2 bouyer return (0);
2288 1.8.2.2 bouyer }
2289 1.8.2.2 bouyer
2290 1.8.2.2 bouyer /*
2291 1.8.2.2 bouyer * This function handles all of the 16 byte WRITE BUFFER commands.
2292 1.8.2.2 bouyer */
2293 1.8.2.2 bouyer static int
2294 1.8.2.2 bouyer wrbuf16(ses_softc_t *ssc, uint8_t op, uint8_t b1, uint8_t b2,
2295 1.8.2.2 bouyer uint8_t b3, int slp)
2296 1.8.2.2 bouyer {
2297 1.8.2.2 bouyer int err, amt;
2298 1.8.2.2 bouyer char *sdata;
2299 1.8.2.2 bouyer struct scfg *cc = ssc->ses_private;
2300 1.8.2.2 bouyer static char cdb[10] = { WRITE_BUFFER, 1, 0, 0, 0, 0, 0, 0, 16, 0 };
2301 1.8.2.2 bouyer
2302 1.8.2.2 bouyer if (cc == NULL)
2303 1.8.2.2 bouyer return (0);
2304 1.8.2.2 bouyer
2305 1.8.2.2 bouyer sdata = SES_MALLOC(16);
2306 1.8.2.2 bouyer if (sdata == NULL)
2307 1.8.2.2 bouyer return (ENOMEM);
2308 1.8.2.2 bouyer
2309 1.8.2.2 bouyer SES_VLOG(ssc, "saf_wrbuf16 %x %x %x %x\n", op, b1, b2, b3);
2310 1.8.2.2 bouyer
2311 1.8.2.2 bouyer sdata[0] = op;
2312 1.8.2.2 bouyer sdata[1] = b1;
2313 1.8.2.2 bouyer sdata[2] = b2;
2314 1.8.2.2 bouyer sdata[3] = b3;
2315 1.8.2.2 bouyer MEMZERO(&sdata[4], 12);
2316 1.8.2.2 bouyer amt = -16;
2317 1.8.2.2 bouyer err = ses_runcmd(ssc, cdb, 10, sdata, &amt);
2318 1.8.2.2 bouyer SES_FREE(sdata, 16);
2319 1.8.2.2 bouyer return (err);
2320 1.8.2.2 bouyer }
2321 1.8.2.2 bouyer
2322 1.8.2.2 bouyer /*
2323 1.8.2.2 bouyer * This function updates the status byte for the device slot described.
2324 1.8.2.2 bouyer *
2325 1.8.2.2 bouyer * Since this is an optional SAF-TE command, there's no point in
2326 1.8.2.2 bouyer * returning an error.
2327 1.8.2.2 bouyer */
2328 1.8.2.2 bouyer static void
2329 1.8.2.2 bouyer wrslot_stat(ses_softc_t *ssc, int slp)
2330 1.8.2.2 bouyer {
2331 1.8.2.2 bouyer int i, amt;
2332 1.8.2.2 bouyer encobj *ep;
2333 1.8.2.2 bouyer char cdb[10], *sdata;
2334 1.8.2.2 bouyer struct scfg *cc = ssc->ses_private;
2335 1.8.2.2 bouyer
2336 1.8.2.2 bouyer if (cc == NULL)
2337 1.8.2.2 bouyer return;
2338 1.8.2.2 bouyer
2339 1.8.2.2 bouyer SES_VLOG(ssc, "saf_wrslot\n");
2340 1.8.2.2 bouyer cdb[0] = WRITE_BUFFER;
2341 1.8.2.2 bouyer cdb[1] = 1;
2342 1.8.2.2 bouyer cdb[2] = 0;
2343 1.8.2.2 bouyer cdb[3] = 0;
2344 1.8.2.2 bouyer cdb[4] = 0;
2345 1.8.2.2 bouyer cdb[5] = 0;
2346 1.8.2.2 bouyer cdb[6] = 0;
2347 1.8.2.2 bouyer cdb[7] = 0;
2348 1.8.2.2 bouyer cdb[8] = cc->Nslots * 3 + 1;
2349 1.8.2.2 bouyer cdb[9] = 0;
2350 1.8.2.2 bouyer
2351 1.8.2.2 bouyer sdata = SES_MALLOC(cc->Nslots * 3 + 1);
2352 1.8.2.2 bouyer if (sdata == NULL)
2353 1.8.2.2 bouyer return;
2354 1.8.2.2 bouyer MEMZERO(sdata, cc->Nslots * 3 + 1);
2355 1.8.2.2 bouyer
2356 1.8.2.2 bouyer sdata[0] = SAFTE_WT_DSTAT;
2357 1.8.2.2 bouyer for (i = 0; i < cc->Nslots; i++) {
2358 1.8.2.2 bouyer ep = &ssc->ses_objmap[cc->slotoff + i];
2359 1.8.2.2 bouyer SES_VLOG(ssc, "saf_wrslot %d <- %x\n", i, ep->priv & 0xff);
2360 1.8.2.2 bouyer sdata[1 + (3 * i)] = ep->priv & 0xff;
2361 1.8.2.2 bouyer }
2362 1.8.2.2 bouyer amt = -(cc->Nslots * 3 + 1);
2363 1.8.2.2 bouyer (void) ses_runcmd(ssc, cdb, 10, sdata, &amt);
2364 1.8.2.2 bouyer SES_FREE(sdata, cc->Nslots * 3 + 1);
2365 1.8.2.2 bouyer }
2366 1.8.2.2 bouyer
2367 1.8.2.2 bouyer /*
2368 1.8.2.2 bouyer * This function issues the "PERFORM SLOT OPERATION" command.
2369 1.8.2.2 bouyer */
2370 1.8.2.2 bouyer static int
2371 1.8.2.2 bouyer perf_slotop(ses_softc_t *ssc, uint8_t slot, uint8_t opflag, int slp)
2372 1.8.2.2 bouyer {
2373 1.8.2.2 bouyer int err, amt;
2374 1.8.2.2 bouyer char *sdata;
2375 1.8.2.2 bouyer struct scfg *cc = ssc->ses_private;
2376 1.8.2.2 bouyer static char cdb[10] =
2377 1.8.2.2 bouyer { WRITE_BUFFER, 1, 0, 0, 0, 0, 0, 0, SAFT_SCRATCH, 0 };
2378 1.8.2.2 bouyer
2379 1.8.2.2 bouyer if (cc == NULL)
2380 1.8.2.2 bouyer return (0);
2381 1.8.2.2 bouyer
2382 1.8.2.2 bouyer sdata = SES_MALLOC(SAFT_SCRATCH);
2383 1.8.2.2 bouyer if (sdata == NULL)
2384 1.8.2.2 bouyer return (ENOMEM);
2385 1.8.2.2 bouyer MEMZERO(sdata, SAFT_SCRATCH);
2386 1.8.2.2 bouyer
2387 1.8.2.2 bouyer sdata[0] = SAFTE_WT_SLTOP;
2388 1.8.2.2 bouyer sdata[1] = slot;
2389 1.8.2.2 bouyer sdata[2] = opflag;
2390 1.8.2.2 bouyer SES_VLOG(ssc, "saf_slotop slot %d op %x\n", slot, opflag);
2391 1.8.2.2 bouyer amt = -SAFT_SCRATCH;
2392 1.8.2.2 bouyer err = ses_runcmd(ssc, cdb, 10, sdata, &amt);
2393 1.8.2.2 bouyer SES_FREE(sdata, SAFT_SCRATCH);
2394 1.8.2.2 bouyer return (err);
2395 1.8.2.2 bouyer }
2396