Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(88)

Side by Side Diff: safte.c

Issue 4279046: SCSI DMA correctness
Patch Set: diff #7 Created 14 years ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « ch.c ('k') | scsi_base.c » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* $OpenBSD: safte.c,v 1.46 2010/09/27 19:49:43 thib Exp $ */ 1 /* $OpenBSD: safte.c,v 1.46 2010/09/27 19:49:43 thib Exp $ */
2 2
3 /* 3 /*
4 * Copyright (c) 2005 David Gwynne <dlg@openbsd.org> 4 * Copyright (c) 2005 David Gwynne <dlg@openbsd.org>
5 * 5 *
6 * Permission to use, copy, modify, and distribute this software for any 6 * Permission to use, copy, modify, and distribute this software for any
7 * purpose with or without fee is hereby granted, provided that the above 7 * purpose with or without fee is hereby granted, provided that the above
8 * copyright notice and this permission notice appear in all copies. 8 * copyright notice and this permission notice appear in all copies.
9 * 9 *
10 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 10 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 11 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 12 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 13 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 14 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 15 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 16 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17 */ 17 */
18 18
19 #include "bio.h" 19 #include "bio.h"
20 20
21 #include <sys/param.h> 21 #include <sys/param.h>
22 #include <sys/systm.h> 22 #include <sys/systm.h>
23 #include <sys/device.h> 23 #include <sys/device.h>
24 #include <sys/scsiio.h> 24 #include <sys/scsiio.h>
25 #include <sys/malloc.h> 25 #include <sys/malloc.h>
26 #include <sys/pool.h>
26 #include <sys/proc.h> 27 #include <sys/proc.h>
27 #include <sys/rwlock.h> 28 #include <sys/rwlock.h>
28 #include <sys/queue.h> 29 #include <sys/queue.h>
29 #include <sys/sensors.h> 30 #include <sys/sensors.h>
30 31
31 #if NBIO > 0 32 #if NBIO > 0
32 #include <dev/biovar.h> 33 #include <dev/biovar.h>
33 #endif 34 #endif
34 35
35 #include <scsi/scsi_all.h> 36 #include <scsi/scsi_all.h>
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
101 #if NBIO > 0 102 #if NBIO > 0
102 int safte_ioctl(struct device *, u_long, caddr_t); 103 int safte_ioctl(struct device *, u_long, caddr_t);
103 int safte_bio_blink(struct safte_softc *, struct bioc_blink *); 104 int safte_bio_blink(struct safte_softc *, struct bioc_blink *);
104 #endif 105 #endif
105 106
106 int64_t safte_temp2uK(u_int8_t, int); 107 int64_t safte_temp2uK(u_int8_t, int);
107 108
108 int 109 int
109 safte_match(struct device *parent, void *match, void *aux) 110 safte_match(struct device *parent, void *match, void *aux)
110 { 111 {
111 » struct scsi_inquiry_data inqbuf; 112 » struct scsi_inquiry_data *inqbuf;
112 struct scsi_attach_args *sa = aux; 113 struct scsi_attach_args *sa = aux;
113 struct scsi_inquiry_data *inq = sa->sa_inqbuf; 114 struct scsi_inquiry_data *inq = sa->sa_inqbuf;
114 struct scsi_inquiry *cmd; 115 struct scsi_inquiry *cmd;
115 struct scsi_xfer *xs; 116 struct scsi_xfer *xs;
116 struct safte_inq *si; 117 struct safte_inq *si;
117 int error, flags = 0, length; 118 int error, flags = 0, length;
118 119
119 si = (struct safte_inq *)&inqbuf.extra;
120
121 if (inq == NULL) 120 if (inq == NULL)
122 return (0); 121 return (0);
123 122
124 /* match on dell enclosures */ 123 /* match on dell enclosures */
125 if ((inq->device & SID_TYPE) == T_PROCESSOR && 124 if ((inq->device & SID_TYPE) == T_PROCESSOR &&
126 SCSISPC(inq->version) == 3) 125 SCSISPC(inq->version) == 3)
127 return (2); 126 return (2);
128 127
129 » if ((inq->device & SID_TYPE) != T_PROCESSOR || 128 » if ((inq->device & SID_TYPE) != T_PROCESSOR ||
130 SCSISPC(inq->version) != 2 || 129 SCSISPC(inq->version) != 2 ||
131 (inq->response_format & SID_ANSII) != 2) 130 (inq->response_format & SID_ANSII) != 2)
132 return (0); 131 return (0);
133 132
134 length = inq->additional_length + SAFTE_EXTRA_OFFSET; 133 length = inq->additional_length + SAFTE_EXTRA_OFFSET;
135 if (length < SAFTE_INQ_LEN) 134 if (length < SAFTE_INQ_LEN)
136 return (0); 135 return (0);
137 » if (length > sizeof(inqbuf)) 136 » if (length > sizeof(*inqbuf))
138 » » length = sizeof(inqbuf); 137 » » length = sizeof(*inqbuf);
138
139 » inqbuf = dma_alloc(sizeof(*inqbuf), PR_NOWAIT | PR_ZERO);
140 » if (inqbuf == NULL)
141 » » return (0);
142
143 » memset(inqbuf->extra, ' ', sizeof(inqbuf->extra));
139 144
140 if (cold) 145 if (cold)
141 flags |= SCSI_AUTOCONF; 146 flags |= SCSI_AUTOCONF;
142 xs = scsi_xs_get(sa->sa_sc_link, flags | SCSI_DATA_IN); 147 xs = scsi_xs_get(sa->sa_sc_link, flags | SCSI_DATA_IN);
143 if (xs == NULL) 148 if (xs == NULL)
144 return (0); 149 return (0);
145 xs->cmdlen = sizeof(*cmd); 150 xs->cmdlen = sizeof(*cmd);
146 » xs->data = (void *)&inqbuf; 151 » xs->data = (void *)inqbuf;
147 xs->datalen = length; 152 xs->datalen = length;
148 xs->retries = 2; 153 xs->retries = 2;
149 xs->timeout = 10000; 154 xs->timeout = 10000;
150 155
151 cmd = (struct scsi_inquiry *)xs->cmd; 156 cmd = (struct scsi_inquiry *)xs->cmd;
152 cmd->opcode = INQUIRY; 157 cmd->opcode = INQUIRY;
153 _lto2b(length, cmd->length); 158 _lto2b(length, cmd->length);
154 159
155 memset(&inqbuf, 0, sizeof(inqbuf));
156 memset(&inqbuf.extra, ' ', sizeof(inqbuf.extra));
157
158 error = scsi_xs_sync(xs); 160 error = scsi_xs_sync(xs);
159 scsi_xs_put(xs); 161 scsi_xs_put(xs);
160 162
161 » if (error) 163 » if (error) {
164 » » dma_free(inqbuf, sizeof(*inqbuf));
162 return (0); 165 return (0);
166 }
163 167
164 » if (memcmp(si->ident, SAFTE_IDENT, sizeof(si->ident)) == 0) 168 » si = (struct safte_inq *)&inqbuf->extra;
169 » if (memcmp(si->ident, SAFTE_IDENT, sizeof(si->ident)) == 0) {
170 » » dma_free(inqbuf, sizeof(*inqbuf));
165 return (2); 171 return (2);
172 }
166 173
174 dma_free(inqbuf, sizeof(*inqbuf));
167 return (0); 175 return (0);
168 } 176 }
169 177
170 void 178 void
171 safte_attach(struct device *parent, struct device *self, void *aux) 179 safte_attach(struct device *parent, struct device *self, void *aux)
172 { 180 {
173 struct safte_softc *sc = (struct safte_softc *)self; 181 struct safte_softc *sc = (struct safte_softc *)self;
174 struct scsi_attach_args *sa = aux; 182 struct scsi_attach_args *sa = aux;
175 int i = 0; 183 int i = 0;
176 184
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
213 bio_register(self, safte_ioctl) != 0) { 221 bio_register(self, safte_ioctl) != 0) {
214 printf("%s: unable to register ioctl with bio\n", DEVNAME(sc)); 222 printf("%s: unable to register ioctl with bio\n", DEVNAME(sc));
215 sc->sc_nslots = 0; 223 sc->sc_nslots = 0;
216 } else 224 } else
217 i++; 225 i++;
218 #endif 226 #endif
219 227
220 if (i) /* if we're doing something, then preinit encbuf and sensors */ 228 if (i) /* if we're doing something, then preinit encbuf and sensors */
221 safte_read_encstat(sc); 229 safte_read_encstat(sc);
222 else { 230 else {
223 » » free(sc->sc_encbuf, M_DEVBUF); 231 » » dma_free(sc->sc_encbuf, sc->sc_encbuflen);
224 sc->sc_encbuf = NULL; 232 sc->sc_encbuf = NULL;
225 } 233 }
226 } 234 }
227 235
228 int 236 int
229 safte_detach(struct device *self, int flags) 237 safte_detach(struct device *self, int flags)
230 { 238 {
231 struct safte_softc *sc = (struct safte_softc *)self; 239 struct safte_softc *sc = (struct safte_softc *)self;
232 int i; 240 int i;
233 241
234 rw_enter_write(&sc->sc_lock); 242 rw_enter_write(&sc->sc_lock);
235 243
236 #if NBIO > 0 244 #if NBIO > 0
237 if (sc->sc_nslots > 0) 245 if (sc->sc_nslots > 0)
238 bio_unregister(self); 246 bio_unregister(self);
239 #endif 247 #endif
240 248
241 if (sc->sc_nsensors > 0) { 249 if (sc->sc_nsensors > 0) {
242 sensordev_deinstall(&sc->sc_sensordev); 250 sensordev_deinstall(&sc->sc_sensordev);
243 sensor_task_unregister(sc->sc_sensortask); 251 sensor_task_unregister(sc->sc_sensortask);
244 252
245 for (i = 0; i < sc->sc_nsensors; i++) 253 for (i = 0; i < sc->sc_nsensors; i++)
246 sensor_detach(&sc->sc_sensordev,· 254 sensor_detach(&sc->sc_sensordev,·
247 &sc->sc_sensors[i].se_sensor); 255 &sc->sc_sensors[i].se_sensor);
248 free(sc->sc_sensors, M_DEVBUF); 256 free(sc->sc_sensors, M_DEVBUF);
249 } 257 }
250 258
251 if (sc->sc_encbuf != NULL) 259 if (sc->sc_encbuf != NULL)
252 » » free(sc->sc_encbuf, M_DEVBUF); 260 » » dma_free(sc->sc_encbuf, sc->sc_encbuflen);
253 261
254 rw_exit_write(&sc->sc_lock); 262 rw_exit_write(&sc->sc_lock);
255 263
256 return (0); 264 return (0);
257 } 265 }
258 266
259 int 267 int
260 safte_read_config(struct safte_softc *sc) 268 safte_read_config(struct safte_softc *sc)
261 { 269 {
262 » struct safte_config config; 270 » struct safte_config *config = NULL;
263 struct safte_readbuf_cmd *cmd; 271 struct safte_readbuf_cmd *cmd;
264 struct safte_sensor *s; 272 struct safte_sensor *s;
265 struct scsi_xfer *xs; 273 struct scsi_xfer *xs;
266 » int error, flags = 0, i, j; 274 » int error = 0, flags = 0, i, j;
275
276 » config = dma_alloc(sizeof(*config), PR_NOWAIT);
277 » if (config == NULL)
278 » » return (1);
267 279
268 if (cold) 280 if (cold)
269 flags |= SCSI_AUTOCONF; 281 flags |= SCSI_AUTOCONF;
270 xs = scsi_xs_get(sc->sc_link, flags | SCSI_DATA_IN | SCSI_SILENT); 282 xs = scsi_xs_get(sc->sc_link, flags | SCSI_DATA_IN | SCSI_SILENT);
271 » if (xs == NULL) 283 » if (xs == NULL) {
272 » » return (1); 284 » » error = 1;
285 » » goto done;
286 » }
273 xs->cmdlen = sizeof(*cmd); 287 xs->cmdlen = sizeof(*cmd);
274 » xs->data = (void *)&config; 288 » xs->data = (void *)config;
275 » xs->datalen = sizeof(config); 289 » xs->datalen = sizeof(*config);
276 xs->retries = 2; 290 xs->retries = 2;
277 xs->timeout = 30000; 291 xs->timeout = 30000;
278 292
279 cmd = (struct safte_readbuf_cmd *)xs->cmd; 293 cmd = (struct safte_readbuf_cmd *)xs->cmd;
280 cmd->opcode = READ_BUFFER; 294 cmd->opcode = READ_BUFFER;
281 cmd->flags |= SAFTE_RD_MODE; 295 cmd->flags |= SAFTE_RD_MODE;
282 cmd->bufferid = SAFTE_RD_CONFIG; 296 cmd->bufferid = SAFTE_RD_CONFIG;
283 » cmd->length = htobe16(sizeof(config)); 297 » cmd->length = htobe16(sizeof(*config));
284 298
285 error = scsi_xs_sync(xs); 299 error = scsi_xs_sync(xs);
286 scsi_xs_put(xs); 300 scsi_xs_put(xs);
287 301
288 » if (error != 0) 302 » if (error != 0) {
289 » » return (1); 303 » » error = 1;
304 » » goto done;
305 » }
290 306
291 DPRINTF(("%s: nfans: %d npwrsup: %d nslots: %d doorlock: %d ntemps: %d" 307 DPRINTF(("%s: nfans: %d npwrsup: %d nslots: %d doorlock: %d ntemps: %d"
292 » " alarm: %d celsius: %d ntherm: %d\n", DEVNAME(sc), config.nfans, 308 » " alarm: %d celsius: %d ntherm: %d\n", DEVNAME(sc), config->nfans,
293 » config.npwrsup, config.nslots, config.doorlock, config.ntemps, 309 » config->npwrsup, config->nslots, config->doorlock, config->ntemps,
294 » config.alarm, SAFTE_CFG_CELSIUS(config.therm), 310 » config->alarm, SAFTE_CFG_CELSIUS(config->therm),
295 » SAFTE_CFG_NTHERM(config.therm))); 311 » SAFTE_CFG_NTHERM(config->therm)));
296 312
297 » sc->sc_encbuflen = config.nfans * sizeof(u_int8_t) + /* fan status */ 313 » sc->sc_encbuflen = config->nfans * sizeof(u_int8_t) + /* fan status */
298 » config.npwrsup * sizeof(u_int8_t) + /* power supply status */ 314 » config->npwrsup * sizeof(u_int8_t) + /* power supply status */
299 » config.nslots * sizeof(u_int8_t) + /* device scsi id (lun) */ 315 » config->nslots * sizeof(u_int8_t) + /* device scsi id (lun) */
300 sizeof(u_int8_t) + /* door lock status */ 316 sizeof(u_int8_t) + /* door lock status */
301 sizeof(u_int8_t) + /* speaker status */ 317 sizeof(u_int8_t) + /* speaker status */
302 » config.ntemps * sizeof(u_int8_t) + /* temp sensors */ 318 » config->ntemps * sizeof(u_int8_t) + /* temp sensors */
303 sizeof(u_int16_t); /* temp out of range sensors */ 319 sizeof(u_int16_t); /* temp out of range sensors */
304 320
305 » sc->sc_encbuf = malloc(sc->sc_encbuflen, M_DEVBUF, M_NOWAIT); 321 » sc->sc_encbuf = dma_alloc(sc->sc_encbuflen, PR_NOWAIT);
306 » if (sc->sc_encbuf == NULL) 322 » if (sc->sc_encbuf == NULL) {
307 » » return (1); 323 » » error = 1;
324 » » goto done;
325 » }
308 326
309 » sc->sc_nsensors = config.nfans + config.npwrsup + config.ntemps +· 327 » sc->sc_nsensors = config->nfans + config->npwrsup + config->ntemps +·
310 » » (config.doorlock ? 1 : 0) + (config.alarm ? 1 : 0); 328 » » (config->doorlock ? 1 : 0) + (config->alarm ? 1 : 0);
311 329
312 sc->sc_sensors = malloc(sc->sc_nsensors * sizeof(struct safte_sensor), 330 sc->sc_sensors = malloc(sc->sc_nsensors * sizeof(struct safte_sensor),
313 M_DEVBUF, M_NOWAIT | M_ZERO); 331 M_DEVBUF, M_NOWAIT | M_ZERO);
314 if (sc->sc_sensors == NULL) { 332 if (sc->sc_sensors == NULL) {
315 » » free(sc->sc_encbuf, M_DEVBUF); 333 » » dma_free(sc->sc_encbuf, sc->sc_encbuflen);
316 sc->sc_encbuf = NULL; 334 sc->sc_encbuf = NULL;
317 sc->sc_nsensors = 0; 335 sc->sc_nsensors = 0;
318 » » return (1); 336 » » error = 1;
337 » » goto done;
319 } 338 }
320 339
321 strlcpy(sc->sc_sensordev.xname, DEVNAME(sc), 340 strlcpy(sc->sc_sensordev.xname, DEVNAME(sc),
322 sizeof(sc->sc_sensordev.xname)); 341 sizeof(sc->sc_sensordev.xname));
323 342
324 s = sc->sc_sensors; 343 s = sc->sc_sensors;
325 344
326 » for (i = 0; i < config.nfans; i++) { 345 » for (i = 0; i < config->nfans; i++) {
327 s->se_type = SAFTE_T_FAN; 346 s->se_type = SAFTE_T_FAN;
328 s->se_field = (u_int8_t *)(sc->sc_encbuf + i); 347 s->se_field = (u_int8_t *)(sc->sc_encbuf + i);
329 s->se_sensor.type = SENSOR_INDICATOR; 348 s->se_sensor.type = SENSOR_INDICATOR;
330 snprintf(s->se_sensor.desc, sizeof(s->se_sensor.desc), 349 snprintf(s->se_sensor.desc, sizeof(s->se_sensor.desc),
331 "Fan%d", i); 350 "Fan%d", i);
332 351
333 s++; 352 s++;
334 } 353 }
335 » j = config.nfans; 354 » j = config->nfans;
336 355
337 » for (i = 0; i < config.npwrsup; i++) { 356 » for (i = 0; i < config->npwrsup; i++) {
338 s->se_type = SAFTE_T_PWRSUP; 357 s->se_type = SAFTE_T_PWRSUP;
339 s->se_field = (u_int8_t *)(sc->sc_encbuf + j + i); 358 s->se_field = (u_int8_t *)(sc->sc_encbuf + j + i);
340 s->se_sensor.type = SENSOR_INDICATOR; 359 s->se_sensor.type = SENSOR_INDICATOR;
341 snprintf(s->se_sensor.desc, sizeof(s->se_sensor.desc), 360 snprintf(s->se_sensor.desc, sizeof(s->se_sensor.desc),
342 "PSU%d", i); 361 "PSU%d", i);
343 362
344 s++; 363 s++;
345 } 364 }
346 » j += config.npwrsup; 365 » j += config->npwrsup;
347 366
348 #if NBIO > 0 367 #if NBIO > 0
349 » sc->sc_nslots = config.nslots; 368 » sc->sc_nslots = config->nslots;
350 sc->sc_slots = (u_int8_t *)(sc->sc_encbuf + j); 369 sc->sc_slots = (u_int8_t *)(sc->sc_encbuf + j);
351 #endif 370 #endif
352 » j += config.nslots; 371 » j += config->nslots;
353 372
354 » if (config.doorlock) { 373 » if (config->doorlock) {
355 s->se_type = SAFTE_T_DOORLOCK; 374 s->se_type = SAFTE_T_DOORLOCK;
356 s->se_field = (u_int8_t *)(sc->sc_encbuf + j); 375 s->se_field = (u_int8_t *)(sc->sc_encbuf + j);
357 s->se_sensor.type = SENSOR_INDICATOR; 376 s->se_sensor.type = SENSOR_INDICATOR;
358 strlcpy(s->se_sensor.desc, "doorlock", 377 strlcpy(s->se_sensor.desc, "doorlock",
359 sizeof(s->se_sensor.desc)); 378 sizeof(s->se_sensor.desc));
360 379
361 s++; 380 s++;
362 } 381 }
363 j++; 382 j++;
364 383
365 » if (config.alarm) { 384 » if (config->alarm) {
366 s->se_type = SAFTE_T_ALARM; 385 s->se_type = SAFTE_T_ALARM;
367 s->se_field = (u_int8_t *)(sc->sc_encbuf + j); 386 s->se_field = (u_int8_t *)(sc->sc_encbuf + j);
368 s->se_sensor.type = SENSOR_INDICATOR; 387 s->se_sensor.type = SENSOR_INDICATOR;
369 strlcpy(s->se_sensor.desc, "alarm", sizeof(s->se_sensor.desc)); 388 strlcpy(s->se_sensor.desc, "alarm", sizeof(s->se_sensor.desc));
370 389
371 s++; 390 s++;
372 } 391 }
373 j++; 392 j++;
374 393
375 /* 394 /*
376 * stash the temp info so we can get out of range status. limit the 395 * stash the temp info so we can get out of range status. limit the
377 * number so the out of temp checks cant go into memory it doesnt own 396 * number so the out of temp checks cant go into memory it doesnt own
378 */ 397 */
379 » sc->sc_ntemps = (config.ntemps > 15) ? 15 : config.ntemps; 398 » sc->sc_ntemps = (config->ntemps > 15) ? 15 : config->ntemps;
380 sc->sc_temps = s; 399 sc->sc_temps = s;
381 » sc->sc_celsius = SAFTE_CFG_CELSIUS(config.therm); 400 » sc->sc_celsius = SAFTE_CFG_CELSIUS(config->therm);
382 » for (i = 0; i < config.ntemps; i++) { 401 » for (i = 0; i < config->ntemps; i++) {
383 s->se_type = SAFTE_T_TEMP; 402 s->se_type = SAFTE_T_TEMP;
384 s->se_field = (u_int8_t *)(sc->sc_encbuf + j + i); 403 s->se_field = (u_int8_t *)(sc->sc_encbuf + j + i);
385 s->se_sensor.type = SENSOR_TEMP; 404 s->se_sensor.type = SENSOR_TEMP;
386 405
387 s++; 406 s++;
388 } 407 }
389 » j += config.ntemps; 408 » j += config->ntemps;
390 409
391 sc->sc_temperrs = (u_int8_t *)(sc->sc_encbuf + j); 410 sc->sc_temperrs = (u_int8_t *)(sc->sc_encbuf + j);
392 411 done:
393 » return (0); 412 » dma_free(config, sizeof(*config));
413 » return (error);
394 } 414 }
395 415
396 void 416 void
397 safte_read_encstat(void *arg) 417 safte_read_encstat(void *arg)
398 { 418 {
399 struct safte_readbuf_cmd *cmd; 419 struct safte_readbuf_cmd *cmd;
400 struct safte_sensor *s; 420 struct safte_sensor *s;
401 struct safte_softc *sc = (struct safte_softc *)arg; 421 struct safte_softc *sc = (struct safte_softc *)arg;
402 struct scsi_xfer *xs; 422 struct scsi_xfer *xs;
403 int error, i, flags = 0; 423 int error, i, flags = 0;
(...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after
576 rw_enter_read(&sc->sc_lock); 596 rw_enter_read(&sc->sc_lock);
577 for (slot = 0; slot < sc->sc_nslots; slot++) { 597 for (slot = 0; slot < sc->sc_nslots; slot++) {
578 if (sc->sc_slots[slot] == blink->bb_target) 598 if (sc->sc_slots[slot] == blink->bb_target)
579 break; 599 break;
580 } 600 }
581 rw_exit_read(&sc->sc_lock); 601 rw_exit_read(&sc->sc_lock);
582 602
583 if (slot >= sc->sc_nslots) 603 if (slot >= sc->sc_nslots)
584 return (ENODEV); 604 return (ENODEV);
585 605
586 » op = malloc(sizeof(*op), M_TEMP, M_WAITOK|M_ZERO); 606 » op = dma_alloc(sizeof(*op), PR_WAITOK | PR_ZERO);
587 607
588 op->opcode = SAFTE_WRITE_SLOTOP; 608 op->opcode = SAFTE_WRITE_SLOTOP;
589 op->slot = slot; 609 op->slot = slot;
590 op->flags |= wantblink ? SAFTE_SLOTOP_IDENTIFY : 0; 610 op->flags |= wantblink ? SAFTE_SLOTOP_IDENTIFY : 0;
591 611
592 if (cold) 612 if (cold)
593 flags |= SCSI_AUTOCONF; 613 flags |= SCSI_AUTOCONF;
594 xs = scsi_xs_get(sc->sc_link, flags | SCSI_DATA_OUT | SCSI_SILENT); 614 xs = scsi_xs_get(sc->sc_link, flags | SCSI_DATA_OUT | SCSI_SILENT);
595 if (xs == NULL) { 615 if (xs == NULL) {
596 » » free(op, M_TEMP); 616 » » dma_free(op, sizeof(*op));
597 return (ENOMEM); 617 return (ENOMEM);
598 } 618 }
599 xs->cmdlen = sizeof(*cmd); 619 xs->cmdlen = sizeof(*cmd);
600 xs->data = (void *)op; 620 xs->data = (void *)op;
601 xs->datalen = sizeof(*op); 621 xs->datalen = sizeof(*op);
602 xs->retries = 2;· 622 xs->retries = 2;·
603 xs->timeout = 30000; 623 xs->timeout = 30000;
604 624
605 cmd = (struct safte_writebuf_cmd *)xs->cmd; 625 cmd = (struct safte_writebuf_cmd *)xs->cmd;
606 cmd->opcode = WRITE_BUFFER; 626 cmd->opcode = WRITE_BUFFER;
607 cmd->flags |= SAFTE_WR_MODE; 627 cmd->flags |= SAFTE_WR_MODE;
608 cmd->length = htobe16(sizeof(struct safte_slotop)); 628 cmd->length = htobe16(sizeof(struct safte_slotop));
609 629
610 error = scsi_xs_sync(xs); 630 error = scsi_xs_sync(xs);
611 scsi_xs_put(xs); 631 scsi_xs_put(xs);
612 632
613 if (error != 0) { 633 if (error != 0) {
614 error = EIO; 634 error = EIO;
615 } 635 }
616 » free(op, M_TEMP); 636 » dma_free(op, sizeof(*op));
617 637
618 return (error); 638 return (error);
619 } 639 }
620 #endif /* NBIO > 0 */ 640 #endif /* NBIO > 0 */
621 641
622 int64_t 642 int64_t
623 safte_temp2uK(u_int8_t measured, int celsius) 643 safte_temp2uK(u_int8_t measured, int celsius)
624 { 644 {
625 int64_t temp; 645 int64_t temp;
626 646
627 temp = (int64_t)measured; 647 temp = (int64_t)measured;
628 temp += SAFTE_TEMP_OFFSET; 648 temp += SAFTE_TEMP_OFFSET;
629 temp *= 1000000; /* convert to micro (mu) degrees */ 649 temp *= 1000000; /* convert to micro (mu) degrees */
630 if (!celsius) 650 if (!celsius)
631 temp = ((temp - 32000000) * 5) / 9; /* convert to Celsius */ 651 temp = ((temp - 32000000) * 5) / 9; /* convert to Celsius */
632 652
633 temp += 273150000; /* convert to kelvin */ 653 temp += 273150000; /* convert to kelvin */
634 654
635 return (temp); 655 return (temp);
636 } 656 }
OLDNEW
« no previous file with comments | « ch.c ('k') | scsi_base.c » ('j') | no next file with comments »

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b