2 * Written by: David Jeffery
3 * Copyright (c) 2002 Adaptec Inc.
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
15 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
16 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
19 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27 * $FreeBSD: src/sys/dev/ips/ips_commands.c,v 1.8 2004/01/01 10:22:10 mbr
28 * $DragonFly: src/sys/dev/raid/ips/ips_commands.c,v 1.3 2004/02/26 14:07:21 joerg Exp $
31 #include <sys/cdefs.h>
33 #include <dev/raid/ips/ips.h>
36 ips_msleep(void *ident, struct ips_softc *sc, int priority, const char *wmesg,
42 r = tsleep(ident, priority, wmesg, timo);
48 * This is an interrupt callback. It is called from
49 * interrupt context when the adapter has completed the
50 * command. This very generic callback simply stores
51 * the command's return value in command->arg and wake's
52 * up anyone waiting on the command.
55 ips_wakeup_callback(ips_command_t *command)
57 ips_cmd_status_t *status;
59 status = command->arg;
60 status->value = command->status.value;
61 bus_dmamap_sync(command->sc->command_dmatag, command->command_dmamap,
62 BUS_DMASYNC_POSTWRITE);
63 IPS_LOCK(command->sc);
65 IPS_UNLOCK(command->sc);
67 /* Below are a series of functions for sending an IO request
68 * to the adapter. The flow order is: start, send, callback, finish.
69 * The caller must have already assembled an iorequest struct to hold
70 * the details of the IO request. */
71 static void ips_io_request_finish(ips_command_t *command)
73 struct bio *iobuf = command->arg;
75 if (ips_read_request(iobuf)) {
76 bus_dmamap_sync(command->data_dmatag, command->data_dmamap,
77 BUS_DMASYNC_POSTREAD);
79 bus_dmamap_sync(command->data_dmatag, command->data_dmamap,
80 BUS_DMASYNC_POSTWRITE);
82 bus_dmamap_unload(command->data_dmatag, command->data_dmamap);
83 bus_dmamap_destroy(command->data_dmatag, command->data_dmamap);
84 if (COMMAND_ERROR(&command->status)) {
85 iobuf->bio_flags |=BIO_ERROR;
86 iobuf->bio_error = EIO;
88 ips_insert_free_cmd(command->sc, command);
93 ips_io_request_callback(void *cmdptr, bus_dma_segment_t *segments, int segnum,
97 ips_command_t *command = cmdptr;
98 ips_sg_element_t *sg_list;
99 ips_io_cmd *command_struct;
100 struct bio *iobuf = command->arg;
106 printf("ips: error = %d in ips_sg_request_callback\n", error);
107 bus_dmamap_unload(command->data_dmatag, command->data_dmamap);
108 bus_dmamap_destroy(command->data_dmatag, command->data_dmamap);
109 iobuf->bio_flags |= BIO_ERROR;
110 iobuf->bio_error = ENOMEM;
111 ips_insert_free_cmd(sc, command);
115 command_struct = (ips_io_cmd *)command->command_buffer;
116 command_struct->id = command->id;
117 command_struct->drivenum = (uintptr_t)iobuf->bio_driver1;
119 if (ips_read_request(iobuf))
120 cmdtype = IPS_SG_READ_CMD;
122 cmdtype = IPS_SG_WRITE_CMD;
123 command_struct->segnum = segnum;
124 sg_list = (ips_sg_element_t *)((u_int8_t *)
125 command->command_buffer + IPS_COMMAND_LEN);
126 for (i = 0; i < segnum; i++) {
127 sg_list[i].addr = segments[i].ds_addr;
128 sg_list[i].len = segments[i].ds_len;
129 length += segments[i].ds_len;
131 command_struct->buffaddr =
132 (u_int32_t)command->command_phys_addr + IPS_COMMAND_LEN;
134 if (ips_read_request(iobuf))
135 cmdtype = IPS_READ_CMD;
137 cmdtype = IPS_WRITE_CMD;
138 command_struct->buffaddr = segments[0].ds_addr;
139 length = segments[0].ds_len;
141 command_struct->command = cmdtype;
142 command_struct->lba = iobuf->bio_pblkno;
143 length = (length + IPS_BLKSIZE - 1)/IPS_BLKSIZE;
144 command_struct->length = length;
145 bus_dmamap_sync(sc->command_dmatag, command->command_dmamap,
146 BUS_DMASYNC_PREWRITE);
147 if (ips_read_request(iobuf)) {
148 bus_dmamap_sync(command->data_dmatag, command->data_dmamap,
149 BUS_DMASYNC_PREREAD);
151 bus_dmamap_sync(command->data_dmatag, command->data_dmamap,
152 BUS_DMASYNC_PREWRITE);
155 * the cast to long long below is necessary because our b_pblkno
156 * is 32bit wide whereas it's 64bit on FreeBSD-CURRENT.
158 PRINTF(10, "ips test: command id: %d segments: %d "
159 "pblkno: %lld length: %d, ds_len: %d\n", command->id, segnum,
160 (long long)iobuf->bio_pblkno,
161 length, segments[0].ds_len);
163 sc->ips_issue_cmd(command);
168 ips_send_io_request(ips_command_t *command)
170 ips_softc_t *sc = command->sc;
171 struct bio *iobuf = command->arg;
172 command->data_dmatag = sc->sg_dmatag;
174 if (bus_dmamap_create(command->data_dmatag, 0, &command->data_dmamap)) {
175 device_printf(sc->dev, "dmamap failed\n");
176 iobuf->bio_flags |= BIO_ERROR;
177 iobuf->bio_error = ENOMEM;
178 ips_insert_free_cmd(sc, command);
182 command->callback = ips_io_request_finish;
183 PRINTF(10, "ips test: : bcount %ld\n", iobuf->bio_bcount);
184 bus_dmamap_load(command->data_dmatag, command->data_dmamap,
185 iobuf->bio_data, iobuf->bio_bcount,
186 ips_io_request_callback, command, 0);
191 ips_start_io_request(ips_softc_t *sc, struct bio *iobuf)
193 if (ips_get_free_cmd(sc, ips_send_io_request, iobuf, 0)) {
194 device_printf(sc->dev, "no mem for command slots!\n");
195 iobuf->bio_flags |= BIO_ERROR;
196 iobuf->bio_error = ENOMEM;
204 * Below are a series of functions for sending an adapter info request
205 * to the adapter. The flow order is: get, send, callback. It uses
206 * the generic finish callback at the top of this file.
207 * This can be used to get configuration/status info from the card
210 ips_adapter_info_callback(void *cmdptr, bus_dma_segment_t *segments,int segnum,
214 ips_command_t *command = cmdptr;
215 ips_adapter_info_cmd *command_struct;
218 ips_cmd_status_t * status = command->arg;
219 status->value = IPS_ERROR_STATUS; /* a lovely error value */
220 ips_insert_free_cmd(sc, command);
221 printf("ips: error = %d in ips_get_adapter_info\n", error);
224 command_struct = (ips_adapter_info_cmd *)command->command_buffer;
225 command_struct->command = IPS_ADAPTER_INFO_CMD;
226 command_struct->id = command->id;
227 command_struct->buffaddr = segments[0].ds_addr;
229 bus_dmamap_sync(sc->command_dmatag, command->command_dmamap,
230 BUS_DMASYNC_PREWRITE);
231 bus_dmamap_sync(command->data_dmatag, command->data_dmamap,
232 BUS_DMASYNC_PREREAD);
233 sc->ips_issue_cmd(command);
237 ips_send_adapter_info_cmd(ips_command_t *command)
239 ips_softc_t *sc = command->sc;
240 ips_cmd_status_t *status = command->arg;
243 if (bus_dma_tag_create( /* parent */ sc->adapter_dmatag,
246 /* lowaddr */ BUS_SPACE_MAXADDR_32BIT,
247 /* highaddr */ BUS_SPACE_MAXADDR,
249 /* filterarg */ NULL,
250 /* maxsize */ IPS_ADAPTER_INFO_LEN,
252 /* maxsegsize*/ IPS_ADAPTER_INFO_LEN,
254 &command->data_dmatag) != 0) {
255 printf("ips: can't alloc dma tag for adapter status\n");
259 if (bus_dmamem_alloc(command->data_dmatag, &command->data_buffer,
260 BUS_DMA_NOWAIT, &command->data_dmamap)) {
264 command->callback = ips_wakeup_callback;
266 bus_dmamap_load(command->data_dmatag, command->data_dmamap,
267 command->data_buffer, IPS_ADAPTER_INFO_LEN,
268 ips_adapter_info_callback, command, BUS_DMA_NOWAIT);
269 if ((status->value == IPS_ERROR_STATUS) ||
270 ips_msleep(status, sc, 0, "ips", 30 * hz) == EWOULDBLOCK)
274 bus_dmamap_sync(command->data_dmatag, command->data_dmamap,
275 BUS_DMASYNC_POSTREAD);
276 memcpy(&(sc->adapter_info), command->data_buffer,
277 IPS_ADAPTER_INFO_LEN);
279 bus_dmamap_unload(command->data_dmatag, command->data_dmamap);
281 /* I suppose I should clean up my memory allocations */
282 bus_dmamem_free(command->data_dmatag, command->data_buffer,
283 command->data_dmamap);
284 bus_dma_tag_destroy(command->data_dmatag);
285 ips_insert_free_cmd(sc, command);
290 ips_get_adapter_info(ips_softc_t *sc)
293 ips_cmd_status_t *status;
295 status = malloc(sizeof(ips_cmd_status_t), M_DEVBUF, M_NOWAIT | M_ZERO);
298 if (ips_get_free_cmd(sc, ips_send_adapter_info_cmd, status,
299 IPS_NOWAIT_FLAG) > 0) {
300 device_printf(sc->dev, "unable to get adapter configuration\n");
301 free(status, M_DEVBUF);
304 if (COMMAND_ERROR(status))
306 free(status, M_DEVBUF);
311 * Below are a series of functions for sending a drive info request
312 * to the adapter. The flow order is: get, send, callback. It uses
313 * the generic finish callback at the top of this file.
314 * This can be used to get drive status info from the card
317 ips_drive_info_callback(void *cmdptr, bus_dma_segment_t *segments, int segnum,
321 ips_command_t *command = cmdptr;
322 ips_drive_cmd *command_struct;
326 ips_cmd_status_t *status = command->arg;
328 status->value = IPS_ERROR_STATUS;
329 ips_insert_free_cmd(sc, command);
330 printf("ips: error = %d in ips_get_drive_info\n", error);
333 command_struct = (ips_drive_cmd *)command->command_buffer;
334 command_struct->command = IPS_DRIVE_INFO_CMD;
335 command_struct->id = command->id;
336 command_struct->buffaddr = segments[0].ds_addr;
337 bus_dmamap_sync(sc->command_dmatag, command->command_dmamap,
338 BUS_DMASYNC_PREWRITE);
339 bus_dmamap_sync(command->data_dmatag, command->data_dmamap,
340 BUS_DMASYNC_PREREAD);
341 sc->ips_issue_cmd(command);
345 ips_send_drive_info_cmd(ips_command_t *command)
348 ips_softc_t *sc = command->sc;
349 ips_cmd_status_t *status = command->arg;
350 ips_drive_info_t *driveinfo;
352 if (bus_dma_tag_create( /* parent */ sc->adapter_dmatag,
355 /* lowaddr */ BUS_SPACE_MAXADDR_32BIT,
356 /* highaddr */ BUS_SPACE_MAXADDR,
358 /* filterarg */ NULL,
359 /* maxsize */ IPS_DRIVE_INFO_LEN,
361 /* maxsegsize*/ IPS_DRIVE_INFO_LEN,
363 &command->data_dmatag) != 0) {
364 printf("ips: can't alloc dma tag for drive status\n");
368 if (bus_dmamem_alloc(command->data_dmatag, &command->data_buffer,
369 BUS_DMA_NOWAIT, &command->data_dmamap)) {
373 command->callback = ips_wakeup_callback;
375 bus_dmamap_load(command->data_dmatag, command->data_dmamap,
376 command->data_buffer,IPS_DRIVE_INFO_LEN,
377 ips_drive_info_callback, command, BUS_DMA_NOWAIT);
378 if ((status->value == IPS_ERROR_STATUS) ||
379 ips_msleep(status, sc, 0, "ips", 10 * hz) == EWOULDBLOCK)
384 bus_dmamap_sync(command->data_dmatag, command->data_dmamap,
385 BUS_DMASYNC_POSTREAD);
386 driveinfo = command->data_buffer;
387 memcpy(sc->drives, driveinfo->drives, sizeof(ips_drive_t) * 8);
388 sc->drivecount = driveinfo->drivecount;
389 device_printf(sc->dev, "logical drives: %d\n", sc->drivecount);
391 bus_dmamap_unload(command->data_dmatag, command->data_dmamap);
393 /* I suppose I should clean up my memory allocations */
394 bus_dmamem_free(command->data_dmatag, command->data_buffer,
395 command->data_dmamap);
396 bus_dma_tag_destroy(command->data_dmatag);
397 ips_insert_free_cmd(sc, command);
402 ips_get_drive_info(ips_softc_t *sc)
405 ips_cmd_status_t *status;
407 status = malloc(sizeof(ips_cmd_status_t), M_DEVBUF, M_NOWAIT | M_ZERO);
410 if (ips_get_free_cmd(sc, ips_send_drive_info_cmd, status,
411 IPS_NOWAIT_FLAG) > 0) {
412 free(status, M_DEVBUF);
413 device_printf(sc->dev, "unable to get drive configuration\n");
416 if (COMMAND_ERROR(status))
418 free(status, M_DEVBUF);
423 * Below is a pair of functions for making sure data is safely
424 * on disk by flushing the adapter's cache.
427 ips_send_flush_cache_cmd(ips_command_t *command)
429 ips_softc_t *sc = command->sc;
430 ips_cmd_status_t *status = command->arg;
431 ips_generic_cmd *command_struct;
433 PRINTF(10,"ips test: got a command, building flush command\n");
434 command->callback = ips_wakeup_callback;
435 command_struct = (ips_generic_cmd *)command->command_buffer;
436 command_struct->command = IPS_CACHE_FLUSH_CMD;
437 command_struct->id = command->id;
438 bus_dmamap_sync(sc->command_dmatag, command->command_dmamap,
439 BUS_DMASYNC_PREWRITE);
441 sc->ips_issue_cmd(command);
442 if (status->value != IPS_ERROR_STATUS)
443 ips_msleep(status, sc, 0, "flush2", 0);
445 ips_insert_free_cmd(sc, command);
450 ips_flush_cache(ips_softc_t *sc)
452 ips_cmd_status_t *status;
454 status = malloc(sizeof(ips_cmd_status_t), M_DEVBUF, M_NOWAIT | M_ZERO);
457 device_printf(sc->dev, "flushing cache\n");
458 if (ips_get_free_cmd(sc, ips_send_flush_cache_cmd, status,
460 free(status, M_DEVBUF);
461 device_printf(sc->dev, "ERROR: unable to get a command! "
462 "can't flush cache!\n");
465 if (COMMAND_ERROR(status)) {
466 free(status, M_DEVBUF);
467 device_printf(sc->dev, "ERROR: cache flush command failed!\n");
470 free(status, M_DEVBUF);
475 * Simplified localtime to provide timevalues for ffdc.
476 * Taken from libc/stdtime/localtime.c
479 ips_ffdc_settime(ips_adapter_ffdc_cmd *command, time_t sctime)
482 int yleap, *ip, month;
483 int year_lengths[2] = { IPS_DAYSPERNYEAR, IPS_DAYSPERLYEAR };
484 int mon_lengths[2][IPS_MONSPERYEAR] = {
485 { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 },
486 { 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }
489 days = sctime / IPS_SECSPERDAY;
490 rem = sctime % IPS_SECSPERDAY;
492 command->hour = rem / IPS_SECSPERHOUR;
493 rem = rem % IPS_SECSPERHOUR;
495 command->minute = rem / IPS_SECSPERMIN;
496 command->second = rem % IPS_SECSPERMIN;
499 while (days < 0 || days >= (long)year_lengths[yleap = ips_isleap(y)]) {
502 newy = y + days / IPS_DAYSPERNYEAR;
505 days -= (newy - y) * IPS_DAYSPERNYEAR +
506 IPS_LEAPS_THRU_END_OF(newy - 1) -
507 IPS_LEAPS_THRU_END_OF(y - 1);
510 command->yearH = y / 100;
511 command->yearL = y % 100;
512 ip = mon_lengths[yleap];
513 for (month = 0; days >= (long)ip[month]; ++month)
514 days = days - (long)ip[month];
515 command->month = month + 1;
516 command->day = days + 1;
520 ips_send_ffdc_reset_cmd(ips_command_t *command)
522 ips_softc_t *sc = command->sc;
523 ips_cmd_status_t *status = command->arg;
524 ips_adapter_ffdc_cmd *command_struct;
526 PRINTF(10, "ips test: got a command, building ffdc reset command\n");
527 command->callback = ips_wakeup_callback;
528 command_struct = (ips_adapter_ffdc_cmd *)command->command_buffer;
529 command_struct->command = IPS_FFDC_CMD;
530 command_struct->id = command->id;
531 command_struct->reset_count = sc->ffdc_resetcount;
532 command_struct->reset_type = 0x0;
533 ips_ffdc_settime(command_struct, sc->ffdc_resettime.tv_sec);
534 bus_dmamap_sync(sc->command_dmatag, command->command_dmamap,
535 BUS_DMASYNC_PREWRITE);
537 sc->ips_issue_cmd(command);
538 if (status->value != IPS_ERROR_STATUS)
539 ips_msleep(status, sc, 0, "ffdc", 0);
541 ips_insert_free_cmd(sc, command);
546 ips_ffdc_reset(ips_softc_t *sc)
548 ips_cmd_status_t *status;
550 status = malloc(sizeof(ips_cmd_status_t), M_DEVBUF, M_NOWAIT | M_ZERO);
553 if (ips_get_free_cmd(sc, ips_send_ffdc_reset_cmd, status,
555 free(status, M_DEVBUF);
556 device_printf(sc->dev, "ERROR: unable to get a command! "
557 "can't send ffdc reset!\n");
560 if (COMMAND_ERROR(status)) {
561 free(status, M_DEVBUF);
562 device_printf(sc->dev, "ERROR: ffdc reset command failed!\n");
565 free(status, M_DEVBUF);
570 ips_write_nvram(ips_command_t *command)
572 ips_softc_t *sc = command->sc;
573 ips_rw_nvram_cmd *command_struct;
574 ips_nvram_page5 *nvram;
576 /*FIXME check for error */
577 command->callback = ips_wakeup_callback;
578 command_struct = (ips_rw_nvram_cmd *)command->command_buffer;
579 command_struct->command = IPS_RW_NVRAM_CMD;
580 command_struct->id = command->id;
581 command_struct->pagenum = 5;
582 command_struct->rw = 1; /* write */
583 bus_dmamap_sync(command->data_dmatag, command->data_dmamap,
584 BUS_DMASYNC_POSTREAD);
585 nvram = command->data_buffer;
586 /* retrieve adapter info and save in sc */
587 sc->adapter_type = nvram->adapter_type;
588 strncpy(nvram->driver_high, IPS_VERSION_MAJOR, 4);
589 strncpy(nvram->driver_low, IPS_VERSION_MINOR, 4);
590 nvram->operating_system = IPS_OS_FREEBSD;
591 bus_dmamap_sync(sc->command_dmatag, command->command_dmamap,
592 BUS_DMASYNC_PREWRITE);
593 sc->ips_issue_cmd(command);
597 ips_read_nvram_callback(void *cmdptr, bus_dma_segment_t *segments, int segnum,
601 ips_command_t *command = cmdptr;
602 ips_rw_nvram_cmd *command_struct;
606 ips_cmd_status_t *status = command->arg;
608 status->value = IPS_ERROR_STATUS;
609 ips_insert_free_cmd(sc, command);
610 printf("ips: error = %d in ips_read_nvram_callback\n", error);
613 command_struct = (ips_rw_nvram_cmd *)command->command_buffer;
614 command_struct->command = IPS_RW_NVRAM_CMD;
615 command_struct->id = command->id;
616 command_struct->pagenum = 5;
617 command_struct->rw = 0;
618 command_struct->buffaddr = segments[0].ds_addr;
620 bus_dmamap_sync(sc->command_dmatag, command->command_dmamap,
621 BUS_DMASYNC_PREWRITE);
622 bus_dmamap_sync(command->data_dmatag, command->data_dmamap,
623 BUS_DMASYNC_PREREAD);
624 sc->ips_issue_cmd(command);
628 ips_read_nvram(ips_command_t *command)
631 ips_softc_t *sc = command->sc;
632 ips_cmd_status_t *status = command->arg;
634 if (bus_dma_tag_create( /* parent */ sc->adapter_dmatag,
637 /* lowaddr */ BUS_SPACE_MAXADDR_32BIT,
638 /* highaddr */ BUS_SPACE_MAXADDR,
640 /* filterarg */ NULL,
641 /* maxsize */ IPS_NVRAM_PAGE_SIZE,
643 /* maxsegsize*/ IPS_NVRAM_PAGE_SIZE,
645 &command->data_dmatag) != 0) {
646 printf("ips: can't alloc dma tag for nvram\n");
650 if (bus_dmamem_alloc(command->data_dmatag, &command->data_buffer,
651 BUS_DMA_NOWAIT, &command->data_dmamap)) {
655 command->callback = ips_write_nvram;
657 bus_dmamap_load(command->data_dmatag, command->data_dmamap,
658 command->data_buffer, IPS_NVRAM_PAGE_SIZE, ips_read_nvram_callback,
659 command, BUS_DMA_NOWAIT);
660 if ((status->value == IPS_ERROR_STATUS) ||
661 ips_msleep(status, sc, 0, "ips", 0) == EWOULDBLOCK)
665 bus_dmamap_sync(command->data_dmatag, command->data_dmamap,
666 BUS_DMASYNC_POSTWRITE);
668 bus_dmamap_unload(command->data_dmatag, command->data_dmamap);
670 bus_dmamem_free(command->data_dmatag, command->data_buffer,
671 command->data_dmamap);
672 bus_dma_tag_destroy(command->data_dmatag);
673 ips_insert_free_cmd(sc, command);
678 ips_update_nvram(ips_softc_t *sc)
680 ips_cmd_status_t *status;
682 status = malloc(sizeof(ips_cmd_status_t), M_DEVBUF, M_NOWAIT | M_ZERO);
685 if (ips_get_free_cmd(sc, ips_read_nvram, status, IPS_NOWAIT_FLAG)) {
686 free(status, M_DEVBUF);
687 device_printf(sc->dev, "ERROR: unable to get a command! "
688 "can't update nvram\n");
691 if (COMMAND_ERROR(status)) {
692 free(status, M_DEVBUF);
693 device_printf(sc->dev, "ERROR: nvram update command failed!\n");
696 free(status, M_DEVBUF);
701 ips_send_config_sync_cmd(ips_command_t *command)
703 ips_softc_t *sc = command->sc;
704 ips_cmd_status_t *status = command->arg;
705 ips_generic_cmd *command_struct;
707 PRINTF(10, "ips test: got a command, building flush command\n");
708 command->callback = ips_wakeup_callback;
709 command_struct = (ips_generic_cmd *)command->command_buffer;
710 command_struct->command = IPS_CONFIG_SYNC_CMD;
711 command_struct->id = command->id;
712 command_struct->reserve2 = IPS_POCL;
713 bus_dmamap_sync(sc->command_dmatag, command->command_dmamap,
714 BUS_DMASYNC_PREWRITE);
716 sc->ips_issue_cmd(command);
717 if (status->value != IPS_ERROR_STATUS)
718 ips_msleep(status, sc, 0, "ipssyn", 0);
720 ips_insert_free_cmd(sc, command);
725 ips_send_error_table_cmd(ips_command_t *command)
727 ips_softc_t *sc = command->sc;
728 ips_cmd_status_t *status = command->arg;
729 ips_generic_cmd *command_struct;
731 PRINTF(10, "ips test: got a command, building errortable command\n");
732 command->callback = ips_wakeup_callback;
733 command_struct = (ips_generic_cmd *)command->command_buffer;
734 command_struct->command = IPS_ERROR_TABLE_CMD;
735 command_struct->id = command->id;
736 command_struct->reserve2 = IPS_CSL;
737 bus_dmamap_sync(sc->command_dmatag, command->command_dmamap,
738 BUS_DMASYNC_PREWRITE);
740 sc->ips_issue_cmd(command);
741 if (status->value != IPS_ERROR_STATUS)
742 ips_msleep(status, sc, 0, "ipsetc", 0);
744 ips_insert_free_cmd(sc, command);
749 ips_clear_adapter(ips_softc_t *sc)
751 ips_cmd_status_t *status;
753 status = malloc(sizeof(ips_cmd_status_t), M_DEVBUF, M_NOWAIT | M_ZERO);
756 device_printf(sc->dev, "syncing config\n");
757 if (ips_get_free_cmd(sc, ips_send_config_sync_cmd, status,
759 free(status, M_DEVBUF);
760 device_printf(sc->dev, "ERROR: unable to get a command! "
761 "can't sync cache!\n");
764 if (COMMAND_ERROR(status)) {
765 free(status, M_DEVBUF);
766 device_printf(sc->dev, "ERROR: cache sync command failed!\n");
769 device_printf(sc->dev, "clearing error table\n");
770 if (ips_get_free_cmd(sc, ips_send_error_table_cmd, status,
772 free(status, M_DEVBUF);
773 device_printf(sc->dev, "ERROR: unable to get a command! "
774 "can't sync cache!\n");
777 if (COMMAND_ERROR(status)) {
778 device_printf(sc->dev, "ERROR: etable command failed!\n");
779 free(status, M_DEVBUF);
782 free(status, M_DEVBUF);