1 /* $NetBSD: util.c,v 1.6 2008/04/28 20:24:17 martin Exp $ */
4 * Copyright (c) 2001 The NetBSD Foundation, Inc.
7 * This code is derived from software contributed to The NetBSD Foundation
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
19 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 * POSSIBILITY OF SUCH DAMAGE.
33 * Copyright (c) 1999 Michael Smith
34 * All rights reserved.
36 * Redistribution and use in source and binary forms, with or without
37 * modification, are permitted provided that the following conditions
39 * 1. Redistributions of source code must retain the above copyright
40 * notice, this list of conditions and the following disclaimer.
41 * 2. Redistributions in binary form must reproduce the above copyright
42 * notice, this list of conditions and the following disclaimer in the
43 * documentation and/or other materials provided with the distribution.
45 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
46 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
47 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
48 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
49 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
50 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
51 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
52 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
53 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
54 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
59 #include <sys/cdefs.h>
60 __RCSID("$NetBSD: util.c,v 1.6 2008/04/28 20:24:17 martin Exp $");
63 #include <sys/types.h>
64 #include <sys/ioctl.h>
65 #include <sys/queue.h>
67 #include <dev/ic/mlxreg.h>
68 #include <dev/ic/mlxio.h>
70 #include <dev/scsipi/scsipi_all.h>
81 mlx_command(struct mlx_usercommand
*mu
, int bomb
)
85 if ((rv
= ioctl(mlxfd
, MLX_COMMAND
, mu
)) != 0 && bomb
)
86 err(EXIT_FAILURE
, "cmd 0x%02x failed",
93 mlx_enquiry(struct mlx_enquiry2
*enq
)
95 struct mlx_usercommand mu
;
96 struct mlx_enquiry_old meo
;
98 memset(&mu
, 0, sizeof(mu
));
100 mu
.mu_datasize
= sizeof(*enq
);
103 mu
.mu_bufdir
= MU_XFER_IN
;
104 mu
.mu_command
[0] = MLX_CMD_ENQUIRY2
;
109 * If we get back a firmware major of 0, this is (probably) an old
110 * controller, so we need to pull the firmware version from the old
113 if (enq
->me_firmware_id
[0] == 0) {
114 memset(&mu
, 0, sizeof(mu
));
116 mu
.mu_datasize
= sizeof(meo
);
119 mu
.mu_bufdir
= MU_XFER_IN
;
120 mu
.mu_command
[0] = MLX_CMD_ENQUIRY_OLD
;
124 enq
->me_firmware_id
[0] = meo
.me_fwmajor
;
125 enq
->me_firmware_id
[1] = meo
.me_fwminor
;
126 enq
->me_firmware_id
[2] = 0;
127 enq
->me_firmware_id
[3] = '0';
132 mlx_configuration(struct mlx_core_cfg
*cfg
, int wr
)
134 struct mlx_usercommand mu
;
136 memset(&mu
, 0, sizeof(mu
));
138 mu
.mu_datasize
= sizeof(*cfg
);
141 mu
.mu_bufdir
= (wr
? MU_XFER_OUT
: MU_XFER_IN
);
142 mu
.mu_command
[0] = (wr
? MLX_CMD_WRITE_CONFIG
: MLX_CMD_READ_CONFIG
);
148 mlx_get_device_state(int chan
, int targ
, struct mlx_phys_drv
*pd
)
150 struct mlx_usercommand mu
;
152 memset(&mu
, 0, sizeof(mu
));
154 mu
.mu_datasize
= sizeof(*pd
);
157 mu
.mu_bufdir
= MU_XFER_IN
;
158 mu
.mu_command
[0] = MLX_CMD_DEVICE_STATE
;
159 mu
.mu_command
[2] = chan
;
160 mu
.mu_command
[3] = targ
;
162 return (mlx_command(&mu
, 0));
166 mlx_scsi_inquiry(int chan
, int targ
, char **vendor
, char **device
,
169 struct mlx_usercommand mu
;
171 struct mlx_dcdb dcdb
;
172 struct scsipi_inquiry_data inq
;
174 struct scsipi_inquiry
*inq_cmd
;
177 inq_cmd
= (struct scsipi_inquiry
*)&dcdb_cmd
.dcdb
.dcdb_cdb
[0];
179 memset(&mu
, 0, sizeof(mu
));
180 mu
.mu_datasize
= sizeof(dcdb_cmd
);
181 mu
.mu_buf
= &dcdb_cmd
;
182 mu
.mu_command
[0] = MLX_CMD_DIRECT_CDB
;
183 mu
.mu_bufdir
= MU_XFER_IN
| MU_XFER_OUT
;
185 memset(&dcdb_cmd
, 0, sizeof(dcdb_cmd
));
186 dcdb_cmd
.dcdb
.dcdb_target
= (chan
<< 4) | targ
;
187 dcdb_cmd
.dcdb
.dcdb_flags
= MLX_DCDB_DATA_IN
| MLX_DCDB_TIMEOUT_10S
;
188 dcdb_cmd
.dcdb
.dcdb_datasize
= sizeof(dcdb_cmd
.inq
);
189 dcdb_cmd
.dcdb
.dcdb_length
= 6;
190 dcdb_cmd
.dcdb
.dcdb_sense_length
= 40;
192 inq_cmd
->opcode
= INQUIRY
;
193 inq_cmd
->length
= sizeof(dcdb_cmd
.inq
);
195 if ((rv
= mlx_command(&mu
, 0)) == 0) {
196 *vendor
= &dcdb_cmd
.inq
.vendor
[0];
197 *device
= &dcdb_cmd
.inq
.product
[0];
198 *revision
= &dcdb_cmd
.inq
.revision
[0];
205 mlx_print_phys_drv(struct mlx_phys_drv
*pd
, int chn
, int targ
,
209 char *device
, *vendor
, *revision
;
211 switch (pd
->pd_flags2
& 0x03) {
212 case MLX_PHYS_DRV_DISK
:
216 case MLX_PHYS_DRV_SEQUENTIAL
:
220 case MLX_PHYS_DRV_CDROM
:
224 case MLX_PHYS_DRV_OTHER
:
230 printf("%s%s%02d%02d ", prefix
, type
, chn
, targ
);
232 switch (pd
->pd_status
) {
233 case MLX_PHYS_DRV_DEAD
:
237 case MLX_PHYS_DRV_WRONLY
:
238 printf(" (write-only) ");
241 case MLX_PHYS_DRV_ONLINE
:
242 printf(" (online) ");
245 case MLX_PHYS_DRV_STANDBY
:
246 printf(" (standby) ");
250 printf(" (0x%02x) ", pd
->pd_status
);
258 printf("%s ", prefix
);
259 if (!mlx_scsi_inquiry(chn
, targ
, &vendor
, &device
, &revision
))
260 printf("'%8.8s' '%16.16s' '%4.4s'", vendor
, device
, revision
);
262 printf("<IDENTIFY FAILED>");
264 printf(" %dMB ", pd
->pd_config_size
/ 2048);
266 if ((pd
->pd_flags2
& MLX_PHYS_DRV_FAST20
) != 0)
268 else if ((pd
->pd_flags2
& MLX_PHYS_DRV_FAST
) != 0)
271 if ((pd
->pd_flags2
& MLX_PHYS_DRV_WIDE
) != 0)
274 if ((pd
->pd_flags2
& MLX_PHYS_DRV_SYNC
) != 0)
277 if ((pd
->pd_flags2
& MLX_PHYS_DRV_TAG
) != 0)
278 printf(" tag-enabled");