2 * Copyright (c) 1997 by Simon Shapiro
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions, and the following disclaimer,
10 * without modification, immediately at the beginning of the file.
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.
14 * 3. The name of the author may not be used to endorse or promote products
15 * derived from this software without specific prior written permission.
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
18 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR
21 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29 * $FreeBSD: src/usr.sbin/dpt/dpt_softc/dpt_softc.c,v 1.3.2.1 2001/07/24 09:49:45 dd Exp $
30 * $DragonFly: src/usr.sbin/dpt/dpt_softc/dpt_softc.c,v 1.2 2003/06/17 04:29:53 dillon Exp $
33 /* dpt_softc.c: Dunp a DPT control structure */
42 #include <sys/queue.h>
43 #include <sys/ioctl.h>
44 #include <scsi/scsi_all.h>
45 #include <scsi/scsi_message.h>
46 #include <scsi/scsiconf.h>
49 * The following two defines alter the size and composition of dpt_softc_t.
50 * If useland does not match the kenel, disaster will ensue.
51 * Since we do not know how to pick up kernel options from here,
52 * and since we always use these options, we will enable them here.
54 * If you build a kernel without these options, edit here and recompile.
56 #define DPT_MEASURE_PERFORMANCE
60 static char i2bin_bitmap[48]; /* Used for binary dump of registers */
63 i2bin(unsigned int no, int length)
67 for (ndx = 0, rind = 0; ndx < 32; ndx++, rind++) {
68 i2bin_bitmap[rind] = (((no << ndx) & 0x80000000) ? '1' : '0');
71 i2bin_bitmap[++rind] = ' ';
75 i2bin_bitmap[rind - 1] = '\0';
77 i2bin_bitmap[rind] = '\0';
81 return (i2bin_bitmap + 30);
84 return (i2bin_bitmap + 20);
87 return (i2bin_bitmap + 10);
90 return (i2bin_bitmap);
92 return ("i2bin: Invalid length Specs");
97 main(int argc, char **argv, char **argp)
99 dpt_user_softc_t udpt;
103 if ( (fd = open(argv[1], O_RDWR, S_IRUSR | S_IWUSR)) == -1 ) {
104 (void)fprintf(stderr, "%s ERROR: Failed to open \"%s\" - %s\n",
105 argv[0], argv[1], strerror(errno));
109 if ( (result = ioctl(fd, DPT_IOCTL_SOFTC, &udpt)) != 0 ) {
110 (void)fprintf(stderr, "%s ERROR: Failed to send IOCTL %lx - %s\n",
111 argv[0], DPT_IOCTL_SOFTC,
116 (void)fprintf(stdout, "Counters:%d:%d:%d:%d:%d:%d:%d\n",
117 udpt.total_ccbs_count,
118 udpt.free_ccbs_count,
119 udpt.waiting_ccbs_count,
120 udpt.submitted_ccbs_count,
121 udpt.completed_ccbs_count,
122 udpt.commands_processed,
123 udpt.lost_interrupts);
125 (void)fprintf(stdout, "Queue Status:%s\n",
126 i2bin(udpt.queue_status, sizeof(udpt.queue_status) * 8));
128 (void)fprintf(stdout, "Free lock:%s\n",
129 i2bin(udpt.free_lock, sizeof(udpt.free_lock) * 8));
131 (void)fprintf(stdout, "Waiting lock:%s\n",
132 i2bin(udpt.waiting_lock, sizeof(udpt.waiting_lock) * 8));
134 (void)fprintf(stdout, "Submitted lock:%s\n",
135 i2bin(udpt.submitted_lock, sizeof(udpt.submitted_lock) * 8));
137 (void)fprintf(stdout, "Completed lock:%s\n",
138 i2bin(udpt.completed_lock, sizeof(udpt.completed_lock) * 8));
140 (void)fprintf(stdout, "Configuration:%s:%d:%d:%d:%x:%d:%d\n",
141 udpt.handle_interrupts ? "Yes" : "No",
149 (void)fprintf(stdout, "ID:%x:%x:%s:%s:%s:%s:%x\n",
150 udpt.board_data.deviceType,
151 udpt.board_data.rm_dtq,
152 udpt.board_data.vendor,
153 udpt.board_data.modelNum,
154 udpt.board_data.firmware,
155 udpt.board_data.protocol,
158 (void)fprintf(stdout,"Capabilities:%x:%d:%s:%s:%s:%s:%s\n",
161 i2bin((u_int32_t)udpt.state, sizeof(udpt.state) * 8),
162 udpt.primary ? "Yes" : "No",
163 udpt.more_support ? "Yes" : "No",
164 udpt.immediate_support ? "Yes" : "No",
165 udpt.broken_INQUIRY ? "Yes" : "No");
167 (void)fprintf(stdout,"More Config:%d:%d:%d:%d:%d:%d:%d:%d:%d:%d\n",
179 (void)fprintf(stdout,"Cache:%s:%d\n",
180 (udpt.cache_type == DPT_NO_CACHE)
182 : (udpt.cache_type == DPT_CACHE_WRITETHROUGH)
183 ? "Write-Through" : "Write-Back",