2 * Copyright (c) 2000 Michael Smith
3 * Copyright (c) 2000 BSDi
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/twe/twe.c,v 1.1.2.6 2002/03/07 09:57:02 msmith Exp $
28 * $DragonFly: src/sys/dev/raid/twe/twe.c,v 1.5 2004/01/05 17:40:00 drhodus Exp $
32 * Driver for the 3ware Escalade family of IDE RAID controllers.
35 #include "twe_compat.h"
39 #define TWE_DEFINE_TABLES
40 #include "twe_tables.h"
45 static int twe_get_param_1(struct twe_softc *sc, int table_id, int param_id, u_int8_t *result);
46 static int twe_get_param_2(struct twe_softc *sc, int table_id, int param_id, u_int16_t *result);
47 static int twe_get_param_4(struct twe_softc *sc, int table_id, int param_id, u_int32_t *result);
48 static void *twe_get_param(struct twe_softc *sc, int table_id, int parameter_id, size_t size,
49 void (* func)(struct twe_request *tr));
50 #ifdef TWE_SHUTDOWN_NOTIFICATION
51 static int twe_set_param_1(struct twe_softc *sc, int table_id, int param_id, u_int8_t value);
54 static int twe_set_param_2(struct twe_softc *sc, int table_id, int param_id, u_int16_t value);
55 static int twe_set_param_4(struct twe_softc *sc, int table_id, int param_id, u_int32_t value);
57 static int twe_set_param(struct twe_softc *sc, int table_id, int param_id, int param_size,
59 static int twe_init_connection(struct twe_softc *sc, int mode);
60 static int twe_wait_request(struct twe_request *tr);
61 static int twe_immediate_request(struct twe_request *tr);
62 static void twe_completeio(struct twe_request *tr);
63 static void twe_reset(struct twe_softc *sc);
64 static void twe_add_unit(struct twe_softc *sc, int unit);
65 static void twe_del_unit(struct twe_softc *sc, int unit);
68 * Command I/O to controller.
70 static int twe_start(struct twe_request *tr);
71 static void twe_done(struct twe_softc *sc);
72 static void twe_complete(struct twe_softc *sc);
73 static int twe_wait_status(struct twe_softc *sc, u_int32_t status, int timeout);
74 static int twe_drain_response_queue(struct twe_softc *sc);
75 static int twe_check_bits(struct twe_softc *sc, u_int32_t status_reg);
76 static int twe_soft_reset(struct twe_softc *sc);
81 static void twe_host_intr(struct twe_softc *sc);
82 static void twe_attention_intr(struct twe_softc *sc);
83 static void twe_command_intr(struct twe_softc *sc);
86 * Asynchronous event handling.
88 static int twe_fetch_aen(struct twe_softc *sc);
89 static void twe_handle_aen(struct twe_request *tr);
90 static void twe_enqueue_aen(struct twe_softc *sc, u_int16_t aen);
91 static int twe_dequeue_aen(struct twe_softc *sc);
92 static int twe_drain_aen_queue(struct twe_softc *sc);
93 static int twe_find_aen(struct twe_softc *sc, u_int16_t aen);
96 * Command buffer management.
98 static int twe_get_request(struct twe_softc *sc, struct twe_request **tr);
99 static void twe_release_request(struct twe_request *tr);
104 static char *twe_format_aen(struct twe_softc *sc, u_int16_t aen);
105 static int twe_report_request(struct twe_request *tr);
106 static void twe_panic(struct twe_softc *sc, char *reason);
108 /********************************************************************************
109 ********************************************************************************
111 ********************************************************************************
112 ********************************************************************************/
114 /********************************************************************************
115 * Initialise the controller, set up driver data structures.
118 twe_setup(struct twe_softc *sc)
120 struct twe_request *tr;
121 u_int32_t status_reg;
127 * Initialise request queues.
133 twe_initq_complete(sc);
134 sc->twe_wait_aen = -1;
137 * Allocate request structures up front.
139 for (i = 0; i < TWE_Q_LENGTH; i++) {
140 if ((tr = twe_allocate_request(sc)) == NULL)
143 * Set global defaults that won't change.
145 tr->tr_command.generic.host_id = sc->twe_host_id; /* controller-assigned host ID */
146 tr->tr_command.generic.request_id = i; /* our index number */
147 sc->twe_lookup[i] = tr;
150 * Put command onto the freelist.
152 twe_release_request(tr);
156 * Check status register for errors, clear them.
158 status_reg = TWE_STATUS(sc);
159 twe_check_bits(sc, status_reg);
162 * Wait for the controller to come ready.
164 if (twe_wait_status(sc, TWE_STATUS_MICROCONTROLLER_READY, 60)) {
165 twe_printf(sc, "microcontroller not ready\n");
170 * Disable interrupts from the card.
172 twe_disable_interrupts(sc);
175 * Soft reset the controller, look for the AEN acknowledging the reset,
176 * check for errors, drain the response queue.
178 for (i = 0; i < TWE_MAX_RESET_TRIES; i++) {
181 twe_printf(sc, "reset %d failed, trying again\n", i);
183 if (!twe_soft_reset(sc))
184 break; /* reset process complete */
186 /* did we give up? */
187 if (i >= TWE_MAX_RESET_TRIES) {
188 twe_printf(sc, "can't initialise controller, giving up\n");
196 twe_add_unit(struct twe_softc *sc, int unit)
198 struct twe_drive *dr;
201 TWE_Param *drives = NULL, *param = NULL;
202 TWE_Unit_Descriptor *ud;
204 if (unit < 0 || unit > TWE_MAX_UNITS)
208 * The controller is in a safe state, so try to find drives attached to it.
210 if ((drives = twe_get_param(sc, TWE_PARAM_UNITSUMMARY, TWE_PARAM_UNITSUMMARY_Status,
211 TWE_MAX_UNITS, NULL)) == NULL) {
212 twe_printf(sc, "can't detect attached units\n");
216 dr = &sc->twe_drive[unit];
217 /* check that the drive is online */
218 if (!(drives->data[unit] & TWE_PARAM_UNITSTATUS_Online))
221 table = TWE_PARAM_UNITINFO + unit;
223 if (twe_get_param_4(sc, table, TWE_PARAM_UNITINFO_Capacity, &dr->td_size)) {
224 twe_printf(sc, "error fetching capacity for unit %d\n", unit);
227 if (twe_get_param_1(sc, table, TWE_PARAM_UNITINFO_Status, &dr->td_state)) {
228 twe_printf(sc, "error fetching state for unit %d\n", unit);
231 if (twe_get_param_2(sc, table, TWE_PARAM_UNITINFO_DescriptorSize, &dsize)) {
232 twe_printf(sc, "error fetching descriptor size for unit %d\n", unit);
235 if ((param = twe_get_param(sc, table, TWE_PARAM_UNITINFO_Descriptor, dsize - 3, NULL)) == NULL) {
236 twe_printf(sc, "error fetching descriptor for unit %d\n", unit);
239 ud = (TWE_Unit_Descriptor *)param->data;
240 dr->td_type = ud->configuration;
242 /* build synthetic geometry as per controller internal rules */
243 if (dr->td_size > 0x200000) {
250 dr->td_cylinders = dr->td_size / (dr->td_heads * dr->td_sectors);
253 twe_attach_drive(sc, dr);
257 free(param, M_DEVBUF);
259 free(drives, M_DEVBUF);
263 twe_del_unit(struct twe_softc *sc, int unit)
266 if (unit < 0 || unit > TWE_MAX_UNITS)
269 twe_detach_drive(sc, unit);
272 /********************************************************************************
273 * Locate disk devices and attach children to them.
276 twe_init(struct twe_softc *sc)
283 for (i = 0; i < TWE_MAX_UNITS; i++)
287 * Initialise connection with controller.
289 twe_init_connection(sc, TWE_INIT_MESSAGE_CREDITS);
291 #ifdef TWE_SHUTDOWN_NOTIFICATION
293 * Tell the controller we support shutdown notification.
295 twe_set_param_1(sc, TWE_PARAM_FEATURES, TWE_PARAM_FEATURES_DriverShutdown, 1);
299 * Mark controller up and ready to run.
301 sc->twe_state &= ~TWE_STATE_SHUTDOWN;
304 * Finally enable interrupts.
306 twe_enable_interrupts(sc);
309 /********************************************************************************
310 * Stop the controller
313 twe_deinit(struct twe_softc *sc)
316 * Mark the controller as shutting down, and disable any further interrupts.
318 sc->twe_state |= TWE_STATE_SHUTDOWN;
319 twe_disable_interrupts(sc);
321 #ifdef TWE_SHUTDOWN_NOTIFICATION
323 * Disconnect from the controller
325 twe_init_connection(sc, TWE_SHUTDOWN_MESSAGE_CREDITS);
329 /*******************************************************************************
330 * Take an interrupt, or be poked by other code to look for interrupt-worthy
334 twe_intr(struct twe_softc *sc)
336 u_int32_t status_reg;
341 * Collect current interrupt status.
343 status_reg = TWE_STATUS(sc);
344 twe_check_bits(sc, status_reg);
347 * Dispatch based on interrupt status
349 if (status_reg & TWE_STATUS_HOST_INTERRUPT)
351 if (status_reg & TWE_STATUS_ATTENTION_INTERRUPT)
352 twe_attention_intr(sc);
353 if (status_reg & TWE_STATUS_COMMAND_INTERRUPT)
354 twe_command_intr(sc);
355 if (status_reg & TWE_STATUS_RESPONSE_INTERRUPT)
359 /********************************************************************************
360 * Pull as much work off the softc's work queue as possible and give it to the
364 twe_startio(struct twe_softc *sc)
366 struct twe_request *tr;
373 /* spin until something prevents us from doing any work */
376 /* try to get a command that's already ready to go */
377 tr = twe_dequeue_ready(sc);
379 /* build a command from an outstanding bio */
382 /* see if there's work to be done */
383 if ((bp = twe_dequeue_bio(sc)) == NULL)
386 /* get a command to handle the bio with */
387 if (twe_get_request(sc, &tr)) {
388 twe_enqueue_bio(sc, bp); /* failed, put the bio back */
392 /* connect the bio to the command */
393 tr->tr_complete = twe_completeio;
395 tr->tr_data = TWE_BIO_DATA(bp);
396 tr->tr_length = TWE_BIO_LENGTH(bp);
397 cmd = &tr->tr_command;
398 if (TWE_BIO_IS_READ(bp)) {
399 tr->tr_flags |= TWE_CMD_DATAIN;
400 cmd->io.opcode = TWE_OP_READ;
402 tr->tr_flags |= TWE_CMD_DATAOUT;
403 cmd->io.opcode = TWE_OP_WRITE;
406 /* build a suitable I/O command (assumes 512-byte rounded transfers) */
408 cmd->io.unit = TWE_BIO_UNIT(bp);
409 cmd->io.block_count = (tr->tr_length + TWE_BLOCK_SIZE - 1) / TWE_BLOCK_SIZE;
410 cmd->io.lba = TWE_BIO_LBA(bp);
412 /* map the command so the controller can work with it */
416 /* did we find something to do? */
420 /* try to give command to controller */
421 error = twe_start(tr);
424 if (error == EBUSY) {
425 twe_requeue_ready(tr); /* try it again later */
426 break; /* don't try anything more for now */
428 /* we don't support any other return from twe_start */
429 twe_panic(sc, "twe_start returned nonsense");
434 /********************************************************************************
435 * Write blocks from memory to disk, for system crash dumps.
438 twe_dump_blocks(struct twe_softc *sc, int unit, u_int32_t lba, void *data, int nblks)
440 struct twe_request *tr;
444 if (twe_get_request(sc, &tr))
448 tr->tr_status = TWE_CMD_SETUP;
449 tr->tr_length = nblks * TWE_BLOCK_SIZE;
450 tr->tr_flags = TWE_CMD_DATAOUT;
452 cmd = &tr->tr_command;
453 cmd->io.opcode = TWE_OP_WRITE;
456 cmd->io.block_count = nblks;
460 error = twe_immediate_request(tr);
462 if (twe_report_request(tr))
464 twe_release_request(tr);
468 /********************************************************************************
469 * Handle controller-specific control operations.
472 twe_ioctl(struct twe_softc *sc, int cmd, void *addr)
474 struct twe_usercommand *tu = (struct twe_usercommand *)addr;
475 struct twe_paramcommand *tp = (struct twe_paramcommand *)addr;
476 struct twe_drivecommand *td = (struct twe_drivecommand *)addr;
477 union twe_statrequest *ts = (union twe_statrequest *)addr;
480 int *arg = (int *)addr;
481 struct twe_request *tr;
487 /* handle a command from userspace */
490 while (twe_get_request(sc, &tr))
491 tsleep(NULL, PPAUSE, "twioctl", hz);
494 * Save the command's request ID, copy the user-supplied command in,
495 * restore the request ID.
497 srid = tr->tr_command.generic.request_id;
498 bcopy(&tu->tu_command, &tr->tr_command, sizeof(TWE_Command));
499 tr->tr_command.generic.request_id = srid;
502 * if there's a data buffer, allocate and copy it in.
503 * Must be in multipled of 512 bytes.
505 tr->tr_length = (tu->tu_size + 511) & ~511;
506 if (tr->tr_length > 0) {
507 if ((tr->tr_data = malloc(tr->tr_length, M_DEVBUF, M_WAITOK)) == NULL) {
511 if ((error = copyin(tu->tu_data, tr->tr_data, tu->tu_size)) != 0)
513 tr->tr_flags |= TWE_CMD_DATAIN | TWE_CMD_DATAOUT;
516 /* run the command */
518 twe_wait_request(tr);
520 /* copy the command out again */
521 bcopy(&tr->tr_command, &tu->tu_command, sizeof(TWE_Command));
523 /* if there was a data buffer, copy it out */
524 if (tr->tr_length > 0)
525 error = copyout(tr->tr_data, tu->tu_data, tu->tu_size);
529 if (tr->tr_data != NULL)
530 free(tr->tr_data, M_DEVBUF);
532 twe_release_request(tr);
536 /* fetch statistics counter */
538 switch (ts->ts_item) {
539 #ifdef TWE_PERFORMANCE_MONITOR
545 bcopy(&sc->twe_qstat[ts->ts_item], &ts->ts_qstat, sizeof(struct twe_qstat));
554 /* poll for an AEN */
556 *arg = twe_dequeue_aen(sc);
559 /* wait for another AEN to show up */
562 while ((*arg = twe_dequeue_aen(sc)) == TWE_AEN_QUEUE_EMPTY) {
563 error = tsleep(&sc->twe_aen_queue, PRIBIO | PCATCH, "tweaen", 0);
570 case TWEIO_GET_PARAM:
571 if ((param = twe_get_param(sc, tp->tp_table_id, tp->tp_param_id, tp->tp_size, NULL)) == NULL) {
572 twe_printf(sc, "TWEIO_GET_PARAM failed for 0x%x/0x%x/%d\n",
573 tp->tp_table_id, tp->tp_param_id, tp->tp_size);
576 if (param->parameter_size_bytes > tp->tp_size) {
577 twe_printf(sc, "TWEIO_GET_PARAM parameter too large (%d > %d)\n",
578 param->parameter_size_bytes, tp->tp_size);
581 error = copyout(param->data, tp->tp_data, param->parameter_size_bytes);
583 free(param, M_DEVBUF);
587 case TWEIO_SET_PARAM:
588 if ((data = malloc(tp->tp_size, M_DEVBUF, M_WAITOK)) == NULL) {
591 error = copyin(tp->tp_data, data, tp->tp_size);
593 error = twe_set_param(sc, tp->tp_table_id, tp->tp_param_id, tp->tp_size, data);
594 free(data, M_DEVBUF);
603 twe_add_unit(sc, td->td_unit);
607 twe_del_unit(sc, td->td_unit);
610 /* XXX implement ATA PASSTHROUGH */
612 /* nothing we understand */
620 /********************************************************************************
621 * Enable the useful interrupts from the controller.
624 twe_enable_interrupts(struct twe_softc *sc)
626 sc->twe_state |= TWE_STATE_INTEN;
628 TWE_CONTROL_CLEAR_ATTENTION_INTERRUPT |
629 TWE_CONTROL_UNMASK_RESPONSE_INTERRUPT |
630 TWE_CONTROL_ENABLE_INTERRUPTS);
633 /********************************************************************************
634 * Disable interrupts from the controller.
637 twe_disable_interrupts(struct twe_softc *sc)
639 TWE_CONTROL(sc, TWE_CONTROL_DISABLE_INTERRUPTS);
640 sc->twe_state &= ~TWE_STATE_INTEN;
643 /********************************************************************************
644 ********************************************************************************
646 ********************************************************************************
647 ********************************************************************************/
649 /********************************************************************************
650 * Read integer parameter table entries.
653 twe_get_param_1(struct twe_softc *sc, int table_id, int param_id, u_int8_t *result)
657 if ((param = twe_get_param(sc, table_id, param_id, 1, NULL)) == NULL)
659 *result = *(u_int8_t *)param->data;
660 free(param, M_DEVBUF);
665 twe_get_param_2(struct twe_softc *sc, int table_id, int param_id, u_int16_t *result)
669 if ((param = twe_get_param(sc, table_id, param_id, 2, NULL)) == NULL)
671 *result = *(u_int16_t *)param->data;
672 free(param, M_DEVBUF);
677 twe_get_param_4(struct twe_softc *sc, int table_id, int param_id, u_int32_t *result)
681 if ((param = twe_get_param(sc, table_id, param_id, 4, NULL)) == NULL)
683 *result = *(u_int32_t *)param->data;
684 free(param, M_DEVBUF);
688 /********************************************************************************
689 * Perform a TWE_OP_GET_PARAM command. If a callback function is provided, it
690 * will be called with the command when it's completed. If no callback is
691 * provided, we will wait for the command to complete and then return just the data.
692 * The caller is responsible for freeing the data when done with it.
695 twe_get_param(struct twe_softc *sc, int table_id, int param_id, size_t param_size,
696 void (* func)(struct twe_request *tr))
698 struct twe_request *tr;
709 if (twe_get_request(sc, &tr))
713 if ((param = (TWE_Param *)malloc(TWE_SECTOR_SIZE, M_DEVBUF, M_NOWAIT)) == NULL)
716 tr->tr_length = TWE_SECTOR_SIZE;
717 tr->tr_flags = TWE_CMD_DATAIN | TWE_CMD_DATAOUT;
719 /* build the command for the controller */
720 cmd = &tr->tr_command;
721 cmd->param.opcode = TWE_OP_GET_PARAM;
724 cmd->param.param_count = 1;
726 /* map the command/data into controller-visible space */
729 /* fill in the outbound parameter data */
730 param->table_id = table_id;
731 param->parameter_id = param_id;
732 param->parameter_size_bytes = param_size;
734 /* submit the command and either wait or let the callback handle it */
736 /* XXX could use twe_wait_request here if interrupts were enabled? */
737 error = twe_immediate_request(tr);
739 if (twe_report_request(tr))
742 twe_release_request(tr);
745 tr->tr_complete = func;
746 error = twe_start(tr);
751 /* something failed */
755 twe_release_request(tr);
757 free(param, M_DEVBUF);
761 /********************************************************************************
762 * Set integer parameter table entries.
764 #ifdef TWE_SHUTDOWN_NOTIFICATION
766 twe_set_param_1(struct twe_softc *sc, int table_id, int param_id, u_int8_t value)
768 return(twe_set_param(sc, table_id, param_id, sizeof(value), &value));
774 twe_set_param_2(struct twe_softc *sc, int table_id, int param_id, u_int16_t value)
776 return(twe_set_param(sc, table_id, param_id, sizeof(value), &value));
780 twe_set_param_4(struct twe_softc *sc, int table_id, int param_id, u_int32_t value)
782 return(twe_set_param(sc, table_id, param_id, sizeof(value), &value));
786 /********************************************************************************
787 * Perform a TWE_OP_SET_PARAM command, returns nonzero on error.
790 twe_set_param(struct twe_softc *sc, int table_id, int param_id, int param_size, void *data)
792 struct twe_request *tr;
804 if (twe_get_request(sc, &tr))
808 if ((param = (TWE_Param *)malloc(TWE_SECTOR_SIZE, M_DEVBUF, M_NOWAIT)) == NULL)
811 tr->tr_length = TWE_SECTOR_SIZE;
812 tr->tr_flags = TWE_CMD_DATAIN | TWE_CMD_DATAOUT;
814 /* build the command for the controller */
815 cmd = &tr->tr_command;
816 cmd->param.opcode = TWE_OP_SET_PARAM;
819 cmd->param.param_count = 1;
821 /* map the command/data into controller-visible space */
824 /* fill in the outbound parameter data */
825 param->table_id = table_id;
826 param->parameter_id = param_id;
827 param->parameter_size_bytes = param_size;
828 bcopy(data, param->data, param_size);
830 /* XXX could use twe_wait_request here if interrupts were enabled? */
831 error = twe_immediate_request(tr);
833 if (twe_report_request(tr))
839 twe_release_request(tr);
841 free(param, M_DEVBUF);
845 /********************************************************************************
846 * Perform a TWE_OP_INIT_CONNECTION command, returns nonzero on error.
848 * Typically called with interrupts disabled.
851 twe_init_connection(struct twe_softc *sc, int mode)
853 struct twe_request *tr;
860 if (twe_get_request(sc, &tr))
863 /* build the command */
864 cmd = &tr->tr_command;
865 cmd->initconnection.opcode = TWE_OP_INIT_CONNECTION;
866 cmd->initconnection.size = 3;
867 cmd->initconnection.host_id = 0;
868 cmd->initconnection.message_credits = mode;
869 cmd->initconnection.response_queue_pointer = 0;
871 /* map the command into controller-visible space */
874 /* submit the command */
875 error = twe_immediate_request(tr);
876 /* XXX check command result? */
877 twe_unmap_request(tr);
878 twe_release_request(tr);
880 if (mode == TWE_INIT_MESSAGE_CREDITS)
881 sc->twe_host_id = cmd->initconnection.host_id;
885 /********************************************************************************
886 * Start the command (tr) and sleep waiting for it to complete.
888 * Successfully completed commands are dequeued.
891 twe_wait_request(struct twe_request *tr)
897 tr->tr_flags |= TWE_CMD_SLEEPER;
898 tr->tr_status = TWE_CMD_BUSY;
899 twe_enqueue_ready(tr);
900 twe_startio(tr->tr_sc);
902 while (tr->tr_status == TWE_CMD_BUSY)
903 tsleep(tr, PRIBIO, "twewait", 0);
909 /********************************************************************************
910 * Start the command (tr) and busy-wait for it to complete.
911 * This should only be used when interrupts are actually disabled (although it
912 * will work if they are not).
915 twe_immediate_request(struct twe_request *tr)
923 if ((error = twe_start(tr)) != 0)
925 while (tr->tr_status == TWE_CMD_BUSY){
928 return(tr->tr_status != TWE_CMD_COMPLETE);
931 /********************************************************************************
932 * Handle completion of an I/O command.
935 twe_completeio(struct twe_request *tr)
937 struct twe_softc *sc = tr->tr_sc;
938 twe_bio *bp = (twe_bio *)tr->tr_private;
942 if (tr->tr_status == TWE_CMD_COMPLETE) {
944 if (twe_report_request(tr))
945 TWE_BIO_SET_ERROR(bp, EIO);
948 twe_panic(sc, "twe_completeio on incomplete command");
950 tr->tr_private = NULL;
952 twe_release_request(tr);
955 /********************************************************************************
956 * Reset the controller and pull all the active commands back onto the ready
957 * queue. Used to restart a controller that's exhibiting bad behaviour.
960 twe_reset(struct twe_softc *sc)
962 struct twe_request *tr;
966 * Sleep for a short period to allow AENs to be signalled.
968 tsleep(NULL, PRIBIO, "twereset", hz);
971 * Disable interrupts from the controller, and mask any accidental entry
972 * into our interrupt handler.
974 twe_printf(sc, "controller reset in progress...\n");
975 twe_disable_interrupts(sc);
979 * Try to soft-reset the controller.
981 for (i = 0; i < TWE_MAX_RESET_TRIES; i++) {
984 twe_printf(sc, "reset %d failed, trying again\n", i);
986 if (!twe_soft_reset(sc))
987 break; /* reset process complete */
989 /* did we give up? */
990 if (i >= TWE_MAX_RESET_TRIES) {
991 twe_printf(sc, "can't reset controller, giving up\n");
996 * Move all of the commands that were busy back to the ready queue.
999 while ((tr = twe_dequeue_busy(sc)) != NULL) {
1000 twe_enqueue_ready(tr);
1005 * Kick the controller to start things going again, then re-enable interrupts.
1008 twe_enable_interrupts(sc);
1009 twe_printf(sc, "controller reset done, %d commands restarted\n", i);
1013 twe_enable_interrupts(sc);
1016 /********************************************************************************
1017 ********************************************************************************
1018 Command I/O to Controller
1019 ********************************************************************************
1020 ********************************************************************************/
1022 /********************************************************************************
1023 * Try to deliver (tr) to the controller.
1025 * Can be called at any interrupt level, with or without interrupts enabled.
1028 twe_start(struct twe_request *tr)
1030 struct twe_softc *sc = tr->tr_sc;
1032 u_int32_t status_reg;
1036 /* mark the command as currently being processed */
1037 tr->tr_status = TWE_CMD_BUSY;
1040 * Spin briefly waiting for the controller to come ready
1042 * XXX it might be more efficient to return EBUSY immediately
1043 * and let the command be rescheduled.
1045 for (i = 100000, done = 0; (i > 0) && !done; i--) {
1048 /* check to see if we can post a command */
1049 status_reg = TWE_STATUS(sc);
1050 twe_check_bits(sc, status_reg);
1052 if (!(status_reg & TWE_STATUS_COMMAND_QUEUE_FULL)) {
1053 TWE_COMMAND_QUEUE(sc, tr->tr_cmdphys);
1055 /* move command to work queue */
1056 twe_enqueue_busy(tr);
1058 if (tr->tr_complete != NULL) {
1059 debug(3, "queued request %d with callback %p", tr->tr_command.generic.request_id, tr->tr_complete);
1060 } else if (tr->tr_flags & TWE_CMD_SLEEPER) {
1061 debug(3, "queued request %d with wait channel %p", tr->tr_command.generic.request_id, tr);
1063 debug(3, "queued request %d for polling caller", tr->tr_command.generic.request_id);
1067 splx(s); /* drop spl to allow completion interrupts */
1070 /* command is enqueued */
1075 * We couldn't get the controller to take the command; try submitting it again later.
1076 * This should only happen if something is wrong with the controller, or if we have
1077 * overestimated the number of commands it can accept. (Should we actually reject
1078 * the command at this point?)
1083 /********************************************************************************
1084 * Poll the controller (sc) for completed commands.
1086 * Can be called at any interrupt level, with or without interrupts enabled.
1089 twe_done(struct twe_softc *sc)
1091 TWE_Response_Queue rq;
1092 struct twe_request *tr;
1094 u_int32_t status_reg;
1098 /* loop collecting completed commands */
1102 status_reg = TWE_STATUS(sc);
1103 twe_check_bits(sc, status_reg); /* XXX should this fail? */
1105 if (!(status_reg & TWE_STATUS_RESPONSE_QUEUE_EMPTY)) {
1107 rq = TWE_RESPONSE_QUEUE(sc);
1108 tr = sc->twe_lookup[rq.u.response_id]; /* find command */
1109 if (tr->tr_status != TWE_CMD_BUSY)
1110 twe_printf(sc, "completion event for nonbusy command\n");
1111 tr->tr_status = TWE_CMD_COMPLETE;
1112 debug(3, "completed request id %d with status %d",
1113 tr->tr_command.generic.request_id, tr->tr_command.generic.status);
1114 /* move to completed queue */
1115 twe_remove_busy(tr);
1116 twe_enqueue_complete(tr);
1118 break; /* no response ready */
1123 /* if we've completed any commands, try posting some more */
1127 /* handle completion and timeouts */
1128 twe_complete(sc); /* XXX use deferred completion? */
1131 /********************************************************************************
1132 * Perform post-completion processing for commands on (sc).
1134 * This is split from twe_done as it can be safely deferred and run at a lower
1135 * priority level should facilities for such a thing become available.
1138 twe_complete(struct twe_softc *sc)
1140 struct twe_request *tr;
1145 * Pull commands off the completed list, dispatch them appropriately
1147 while ((tr = twe_dequeue_complete(sc)) != NULL) {
1149 /* unmap the command's data buffer */
1150 twe_unmap_request(tr);
1152 /* dispatch to suit command originator */
1153 if (tr->tr_complete != NULL) { /* completion callback */
1154 debug(2, "call completion handler %p", tr->tr_complete);
1155 tr->tr_complete(tr);
1157 } else if (tr->tr_flags & TWE_CMD_SLEEPER) { /* caller is asleep waiting */
1158 debug(2, "wake up command owner on %p", tr);
1161 } else { /* caller is polling command */
1162 debug(2, "command left for owner");
1167 /********************************************************************************
1168 * Wait for (status) to be set in the controller status register for up to
1169 * (timeout) seconds. Returns 0 if found, nonzero if we time out.
1171 * Note: this busy-waits, rather than sleeping, since we may be called with
1172 * eg. clock interrupts masked.
1175 twe_wait_status(struct twe_softc *sc, u_int32_t status, int timeout)
1178 u_int32_t status_reg;
1182 expiry = time_second + timeout;
1185 status_reg = TWE_STATUS(sc);
1186 if (status_reg & status) /* got the required bit(s)? */
1189 } while (time_second <= expiry);
1194 /********************************************************************************
1195 * Drain the response queue, which may contain responses to commands we know
1199 twe_drain_response_queue(struct twe_softc *sc)
1201 TWE_Response_Queue rq;
1202 u_int32_t status_reg;
1206 for (;;) { /* XXX give up eventually? */
1207 status_reg = TWE_STATUS(sc);
1208 if (twe_check_bits(sc, status_reg))
1210 if (status_reg & TWE_STATUS_RESPONSE_QUEUE_EMPTY)
1212 rq = TWE_RESPONSE_QUEUE(sc);
1216 /********************************************************************************
1217 * Soft-reset the controller
1220 twe_soft_reset(struct twe_softc *sc)
1222 u_int32_t status_reg;
1228 if (twe_wait_status(sc, TWE_STATUS_ATTENTION_INTERRUPT, 30)) {
1229 twe_printf(sc, "no attention interrupt\n");
1232 TWE_CONTROL(sc, TWE_CONTROL_CLEAR_ATTENTION_INTERRUPT);
1233 if (twe_drain_aen_queue(sc)) {
1234 twe_printf(sc, "can't drain AEN queue\n");
1237 if (twe_find_aen(sc, TWE_AEN_SOFT_RESET)) {
1238 twe_printf(sc, "reset not reported\n");
1241 status_reg = TWE_STATUS(sc);
1242 if (TWE_STATUS_ERRORS(status_reg) || twe_check_bits(sc, status_reg)) {
1243 twe_printf(sc, "controller errors detected\n");
1246 if (twe_drain_response_queue(sc)) {
1247 twe_printf(sc, "can't drain response queue\n");
1253 /********************************************************************************
1254 ********************************************************************************
1256 ********************************************************************************
1257 ********************************************************************************/
1259 /********************************************************************************
1262 * XXX what does this mean?
1265 twe_host_intr(struct twe_softc *sc)
1269 twe_printf(sc, "host interrupt\n");
1270 TWE_CONTROL(sc, TWE_CONTROL_CLEAR_HOST_INTERRUPT);
1273 /********************************************************************************
1274 * Attention interrupt.
1276 * Signalled when the controller has one or more AENs for us.
1279 twe_attention_intr(struct twe_softc *sc)
1283 /* instigate a poll for AENs */
1284 if (twe_fetch_aen(sc)) {
1285 twe_printf(sc, "error polling for signalled AEN\n");
1287 TWE_CONTROL(sc, TWE_CONTROL_CLEAR_ATTENTION_INTERRUPT);
1291 /********************************************************************************
1292 * Command interrupt.
1294 * Signalled when the controller can handle more commands.
1297 twe_command_intr(struct twe_softc *sc)
1302 * We don't use this, rather we try to submit commands when we receive
1303 * them, and when other commands have completed. Mask it so we don't get
1306 twe_printf(sc, "command interrupt\n");
1307 TWE_CONTROL(sc, TWE_CONTROL_MASK_COMMAND_INTERRUPT);
1310 /********************************************************************************
1311 ********************************************************************************
1312 Asynchronous Event Handling
1313 ********************************************************************************
1314 ********************************************************************************/
1316 /********************************************************************************
1317 * Request an AEN from the controller.
1320 twe_fetch_aen(struct twe_softc *sc)
1325 if ((twe_get_param(sc, TWE_PARAM_AEN, TWE_PARAM_AEN_UnitCode, 2, twe_handle_aen)) == NULL)
1330 /********************************************************************************
1331 * Handle an AEN returned by the controller.
1334 twe_handle_aen(struct twe_request *tr)
1336 struct twe_softc *sc = tr->tr_sc;
1342 /* XXX check for command success somehow? */
1344 param = (TWE_Param *)tr->tr_data;
1345 aen = *(u_int16_t *)(param->data);
1347 free(tr->tr_data, M_DEVBUF);
1348 twe_release_request(tr);
1349 twe_enqueue_aen(sc, aen);
1351 /* XXX poll for more AENs? */
1354 /********************************************************************************
1355 * Pull AENs out of the controller and park them in the queue, in a context where
1356 * interrupts aren't active. Return nonzero if we encounter any errors in the
1357 * process of obtaining all the available AENs.
1360 twe_drain_aen_queue(struct twe_softc *sc)
1365 if (twe_get_param_2(sc, TWE_PARAM_AEN, TWE_PARAM_AEN_UnitCode, &aen))
1367 if (aen == TWE_AEN_QUEUE_EMPTY)
1369 twe_enqueue_aen(sc, aen);
1373 /********************************************************************************
1374 * Push an AEN that we've received onto the queue.
1376 * Note that we have to lock this against reentrance, since it may be called
1377 * from both interrupt and non-interrupt context.
1379 * If someone is waiting for the AEN we have, wake them up.
1382 twe_enqueue_aen(struct twe_softc *sc, u_int16_t aen)
1385 int s, next, nextnext;
1389 if ((msg = twe_format_aen(sc, aen)) != NULL)
1390 twe_printf(sc, "AEN: <%s>\n", msg);
1393 /* enqueue the AEN */
1394 next = ((sc->twe_aen_head + 1) % TWE_Q_LENGTH);
1395 nextnext = ((sc->twe_aen_head + 2) % TWE_Q_LENGTH);
1397 /* check to see if this is the last free slot, and subvert the AEN if it is */
1398 if (nextnext == sc->twe_aen_tail)
1399 aen = TWE_AEN_QUEUE_FULL;
1401 /* look to see if there's room for this AEN */
1402 if (next != sc->twe_aen_tail) {
1403 sc->twe_aen_queue[sc->twe_aen_head] = aen;
1404 sc->twe_aen_head = next;
1407 /* wake up anyone asleep on the queue */
1408 wakeup(&sc->twe_aen_queue);
1410 /* anyone looking for this AEN? */
1411 if (sc->twe_wait_aen == aen) {
1412 sc->twe_wait_aen = -1;
1413 wakeup(&sc->twe_wait_aen);
1418 /********************************************************************************
1419 * Pop an AEN off the queue, or return -1 if there are none left.
1421 * We are more or less interrupt-safe, so don't block interrupts.
1424 twe_dequeue_aen(struct twe_softc *sc)
1430 if (sc->twe_aen_tail == sc->twe_aen_head) {
1431 result = TWE_AEN_QUEUE_EMPTY;
1433 result = sc->twe_aen_queue[sc->twe_aen_tail];
1434 sc->twe_aen_tail = ((sc->twe_aen_tail + 1) % TWE_Q_LENGTH);
1439 /********************************************************************************
1440 * Check to see if the requested AEN is in the queue.
1442 * XXX we could probably avoid masking interrupts here
1445 twe_find_aen(struct twe_softc *sc, u_int16_t aen)
1451 for (i = sc->twe_aen_tail; (i != sc->twe_aen_head) && missing; i = (i + 1) % TWE_Q_LENGTH) {
1452 if (sc->twe_aen_queue[i] == aen)
1460 #if 0 /* currently unused */
1461 /********************************************************************************
1462 * Sleep waiting for at least (timeout) seconds until we see (aen) as
1463 * requested. Returns nonzero on timeout or failure.
1465 * XXX: this should not be used in cases where there may be more than one sleeper
1466 * without a mechanism for registering multiple sleepers.
1469 twe_wait_aen(struct twe_softc *sc, int aen, int timeout)
1476 expiry = time_second + timeout;
1480 sc->twe_wait_aen = aen;
1483 tsleep(&sc->twe_wait_aen, PZERO, "twewaen", hz);
1484 if (sc->twe_wait_aen == -1)
1486 } while ((time_second <= expiry) && !found);
1492 /********************************************************************************
1493 ********************************************************************************
1494 Command Buffer Management
1495 ********************************************************************************
1496 ********************************************************************************/
1498 /********************************************************************************
1499 * Get a new command buffer.
1501 * This will return NULL if all command buffers are in use.
1504 twe_get_request(struct twe_softc *sc, struct twe_request **tr)
1508 /* try to reuse an old buffer */
1509 *tr = twe_dequeue_free(sc);
1511 /* initialise some fields to their defaults */
1513 (*tr)->tr_data = NULL;
1514 (*tr)->tr_private = NULL;
1515 (*tr)->tr_status = TWE_CMD_SETUP; /* command is in setup phase */
1516 (*tr)->tr_flags = 0;
1517 (*tr)->tr_complete = NULL;
1518 (*tr)->tr_command.generic.status = 0; /* before submission to controller */
1519 (*tr)->tr_command.generic.flags = 0; /* not used */
1521 return(*tr == NULL);
1524 /********************************************************************************
1525 * Release a command buffer for reuse.
1529 twe_release_request(struct twe_request *tr)
1533 if (tr->tr_private != NULL)
1534 twe_panic(tr->tr_sc, "tr_private != NULL");
1535 twe_enqueue_free(tr);
1538 /********************************************************************************
1539 ********************************************************************************
1541 ********************************************************************************
1542 ********************************************************************************/
1544 /********************************************************************************
1545 * Print some information about the controller
1548 twe_describe_controller(struct twe_softc *sc)
1557 /* get the port count */
1558 twe_get_param_1(sc, TWE_PARAM_CONTROLLER, TWE_PARAM_CONTROLLER_PortCount, &ports);
1560 /* get version strings */
1561 p[0] = twe_get_param(sc, TWE_PARAM_VERSION, TWE_PARAM_VERSION_Mon, 16, NULL);
1562 p[1] = twe_get_param(sc, TWE_PARAM_VERSION, TWE_PARAM_VERSION_FW, 16, NULL);
1563 p[2] = twe_get_param(sc, TWE_PARAM_VERSION, TWE_PARAM_VERSION_BIOS, 16, NULL);
1564 p[3] = twe_get_param(sc, TWE_PARAM_VERSION, TWE_PARAM_VERSION_PCB, 8, NULL);
1565 p[4] = twe_get_param(sc, TWE_PARAM_VERSION, TWE_PARAM_VERSION_ATA, 8, NULL);
1566 p[5] = twe_get_param(sc, TWE_PARAM_VERSION, TWE_PARAM_VERSION_PCI, 8, NULL);
1568 twe_printf(sc, "%d ports, Firmware %.16s, BIOS %.16s\n", ports, p[1]->data, p[2]->data);
1570 twe_printf(sc, "Monitor %.16s, PCB %.8s, Achip %.8s, Pchip %.8s\n", p[0]->data, p[3]->data,
1571 p[4]->data, p[5]->data);
1572 free(p[0], M_DEVBUF);
1573 free(p[1], M_DEVBUF);
1574 free(p[2], M_DEVBUF);
1575 free(p[3], M_DEVBUF);
1576 free(p[4], M_DEVBUF);
1577 free(p[5], M_DEVBUF);
1579 /* print attached drives */
1581 p[0] = twe_get_param(sc, TWE_PARAM_DRIVESUMMARY, TWE_PARAM_DRIVESUMMARY_Status, 16, NULL);
1582 for (i = 0; i < ports; i++) {
1583 if (p[0]->data[i] != TWE_PARAM_DRIVESTATUS_Present)
1585 twe_get_param_4(sc, TWE_PARAM_DRIVEINFO + i, TWE_PARAM_DRIVEINFO_Size, &size);
1586 p[1] = twe_get_param(sc, TWE_PARAM_DRIVEINFO + i, TWE_PARAM_DRIVEINFO_Model, 40, NULL);
1588 twe_printf(sc, "port %d: %.40s %dMB\n", i, p[1]->data, size / 2048);
1589 free(p[1], M_DEVBUF);
1591 twe_printf(sc, "port %d, drive status unavailable\n", i);
1594 free(p[0], M_DEVBUF);
1598 /********************************************************************************
1599 * Complain if the status bits aren't what we're expecting.
1601 * Rate-limit the complaints to at most one of each every five seconds, but
1602 * always return the correct status.
1605 twe_check_bits(struct twe_softc *sc, u_int32_t status_reg)
1608 static time_t lastwarn[2] = {0, 0};
1611 * This can be a little problematic, as twe_panic may call twe_reset if
1612 * TWE_DEBUG is not set, which will call us again as part of the soft reset.
1614 if ((status_reg & TWE_STATUS_PANIC_BITS) != 0) {
1615 twe_printf(sc, "FATAL STATUS BIT(S) %b\n", status_reg & TWE_STATUS_PANIC_BITS,
1616 TWE_STATUS_BITS_DESCRIPTION);
1617 twe_panic(sc, "fatal status bits");
1621 if ((status_reg & TWE_STATUS_EXPECTED_BITS) != TWE_STATUS_EXPECTED_BITS) {
1622 if (time_second > (lastwarn[0] + 5)) {
1623 twe_printf(sc, "missing expected status bit(s) %b\n", ~status_reg & TWE_STATUS_EXPECTED_BITS,
1624 TWE_STATUS_BITS_DESCRIPTION);
1625 lastwarn[0] = time_second;
1630 if ((status_reg & TWE_STATUS_UNEXPECTED_BITS) != 0) {
1631 if (time_second > (lastwarn[1] + 5)) {
1632 twe_printf(sc, "unexpected status bit(s) %b\n", status_reg & TWE_STATUS_UNEXPECTED_BITS,
1633 TWE_STATUS_BITS_DESCRIPTION);
1634 lastwarn[1] = time_second;
1637 if (status_reg & TWE_STATUS_PCI_PARITY_ERROR) {
1638 twe_printf(sc, "PCI parity error: Reseat card, move card or buggy device present.");
1639 twe_clear_pci_parity_error(sc);
1641 if (status_reg & TWE_STATUS_PCI_ABORT) {
1642 twe_printf(sc, "PCI abort, clearing.");
1643 twe_clear_pci_abort(sc);
1650 /********************************************************************************
1651 * Return a string describing (aen).
1653 * The low 8 bits of the aen are the code, the high 8 bits give the unit number
1654 * where an AEN is specific to a unit.
1656 * Note that we could expand this routine to handle eg. up/downgrading the status
1657 * of a drive if we had some idea of what the drive's initial status was.
1661 twe_format_aen(struct twe_softc *sc, u_int16_t aen)
1663 static char buf[80];
1667 code = twe_describe_code(twe_table_aen, TWE_AEN_CODE(aen));
1679 if ((child = sc->twe_drive[TWE_AEN_UNIT(aen)].td_disk) != NULL) {
1680 sprintf(buf, "twed%d: %s", device_get_unit(child), msg);
1682 sprintf(buf, "twe%d: %s for unknown unit %d", device_get_unit(sc->twe_dev),
1683 msg, TWE_AEN_UNIT(aen));
1688 sprintf(buf, "twe%d: port %d: %s", device_get_unit(sc->twe_dev), TWE_AEN_UNIT(aen),
1697 sprintf(buf, "unknown AEN 0x%x", aen);
1701 /********************************************************************************
1702 * Print a diagnostic if the status of the command warrants it, and return
1703 * either zero (command was ok) or nonzero (command failed).
1706 twe_report_request(struct twe_request *tr)
1708 struct twe_softc *sc = tr->tr_sc;
1709 TWE_Command *cmd = &tr->tr_command;
1713 * Check the command status value and handle accordingly.
1715 if (cmd->generic.status == TWE_STATUS_RESET) {
1717 * The status code 0xff requests a controller reset.
1719 twe_printf(sc, "command returned with controller rest request\n");
1722 } else if (cmd->generic.status > TWE_STATUS_FATAL) {
1724 * Fatal errors that don't require controller reset.
1726 * We know a few special flags values.
1728 switch (cmd->generic.flags) {
1730 device_printf(sc->twe_drive[cmd->generic.unit].td_disk,
1734 device_printf(sc->twe_drive[cmd->generic.unit].td_disk,
1735 "unrecoverable drive error");
1738 device_printf(sc->twe_drive[cmd->generic.unit].td_disk,
1739 "controller error - %s (flags = 0x%x)\n",
1740 twe_describe_code(twe_table_status, cmd->generic.status),
1741 cmd->generic.flags);
1744 } else if (cmd->generic.status > TWE_STATUS_WARNING) {
1746 * Warning level status.
1748 device_printf(sc->twe_drive[cmd->generic.unit].td_disk,
1749 "warning - %s (flags = 0x%x)\n",
1750 twe_describe_code(twe_table_status, cmd->generic.status),
1751 cmd->generic.flags);
1752 } else if (cmd->generic.status > 0x40) {
1754 * Info level status.
1756 device_printf(sc->twe_drive[cmd->generic.unit].td_disk,
1757 "attention - %s (flags = 0x%x)\n",
1758 twe_describe_code(twe_table_status, cmd->generic.status),
1759 cmd->generic.flags);
1765 /********************************************************************************
1766 * Print some controller state to aid in debugging error/panic conditions
1769 twe_print_controller(struct twe_softc *sc)
1771 u_int32_t status_reg;
1773 status_reg = TWE_STATUS(sc);
1774 twe_printf(sc, "status %b\n", status_reg, TWE_STATUS_BITS_DESCRIPTION);
1775 twe_printf(sc, " current max\n");
1776 twe_printf(sc, "free %04d %04d\n", sc->twe_qstat[TWEQ_FREE].q_length, sc->twe_qstat[TWEQ_FREE].q_max);
1777 twe_printf(sc, "ready %04d %04d\n", sc->twe_qstat[TWEQ_READY].q_length, sc->twe_qstat[TWEQ_READY].q_max);
1778 twe_printf(sc, "busy %04d %04d\n", sc->twe_qstat[TWEQ_BUSY].q_length, sc->twe_qstat[TWEQ_BUSY].q_max);
1779 twe_printf(sc, "complete %04d %04d\n", sc->twe_qstat[TWEQ_COMPLETE].q_length, sc->twe_qstat[TWEQ_COMPLETE].q_max);
1780 twe_printf(sc, "bioq %04d %04d\n", sc->twe_qstat[TWEQ_BIO].q_length, sc->twe_qstat[TWEQ_BIO].q_max);
1781 twe_printf(sc, "AEN queue head %d tail %d\n", sc->twe_aen_head, sc->twe_aen_tail);
1785 twe_panic(struct twe_softc *sc, char *reason)
1787 twe_print_controller(sc);
1796 /********************************************************************************
1797 * Print a request/command in human-readable format.
1800 twe_print_request(struct twe_request *tr)
1802 struct twe_softc *sc = tr->tr_sc;
1803 TWE_Command *cmd = &tr->tr_command;
1806 twe_printf(sc, "CMD: request_id %d opcode <%s> size %d unit %d host_id %d\n",
1807 cmd->generic.request_id, twe_describe_code(twe_table_opcode, cmd->generic.opcode), cmd->generic.size,
1808 cmd->generic.unit, cmd->generic.host_id);
1809 twe_printf(sc, " status %d flags 0x%x count %d sgl_offset %d\n",
1810 cmd->generic.status, cmd->generic.flags, cmd->generic.count, cmd->generic.sgl_offset);
1812 switch(cmd->generic.opcode) { /* XXX add more opcodes? */
1815 twe_printf(sc, " lba %d\n", cmd->io.lba);
1816 for (i = 0; (i < TWE_MAX_SGL_LENGTH) && (cmd->io.sgl[i].length != 0); i++)
1817 twe_printf(sc, " %d: 0x%x/%d\n",
1818 i, cmd->io.sgl[i].address, cmd->io.sgl[i].length);
1821 case TWE_OP_GET_PARAM:
1822 case TWE_OP_SET_PARAM:
1823 for (i = 0; (i < TWE_MAX_SGL_LENGTH) && (cmd->param.sgl[i].length != 0); i++)
1824 twe_printf(sc, " %d: 0x%x/%d\n",
1825 i, cmd->param.sgl[i].address, cmd->param.sgl[i].length);
1828 case TWE_OP_INIT_CONNECTION:
1829 twe_printf(sc, " response queue pointer 0x%x\n",
1830 cmd->initconnection.response_queue_pointer);
1836 twe_printf(sc, " tr_command %p/0x%x tr_data %p/0x%x,%d\n",
1837 tr, tr->tr_cmdphys, tr->tr_data, tr->tr_dataphys, tr->tr_length);
1838 twe_printf(sc, " tr_status %d tr_flags 0x%x tr_complete %p tr_private %p\n",
1839 tr->tr_status, tr->tr_flags, tr->tr_complete, tr->tr_private);