2 * Copyright (c) 2008, 2009 Yahoo!, Inc.
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 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. The names of the authors may not be used to endorse or promote
14 * products derived from this software without specific prior written
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
21 * FOR 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
30 #include <sys/param.h>
40 MFI_TABLE(top
, foreign
);
42 /* We currently don't know the full details of the following struct */
43 struct mfi_foreign_scan_cfg
{
47 struct mfi_foreign_scan_info
{
48 uint32_t count
; /* Number of foreign configs found */
49 struct mfi_foreign_scan_cfg cfgs
[8];
53 foreign_drives(int ac __unused
, char **av __unused
)
55 struct mfi_pd_info info
;
56 struct mfi_pd_list
*list
;
59 fd
= mfi_open(mfi_unit
);
67 if (mfi_pd_get_list(fd
, &list
, NULL
) < 0) {
69 warn("Failed to get drive list");
72 /* List the drives. */
73 printf("mfi%d Foreign disks:\n", mfi_unit
);
74 for (i
= 0; i
< list
->count
; i
++) {
75 /* Skip non-hard disks. */
76 if (list
->addr
[i
].scsi_dev_type
!= 0)
78 /* Fetch details for this drive. */
79 if (mfi_pd_get_info(fd
, list
->addr
[i
].device_id
, &info
,
82 warn("Failed to fetch info for drive %u",
83 list
->addr
[i
].device_id
);
87 if (!info
.state
.ddf
.v
.pd_type
.is_foreign
)
90 printf("%s ", mfi_drive_name(&info
, list
->addr
[i
].device_id
,
91 MFI_DNAME_DEVICE_ID
));
93 printf(" %s\n", mfi_drive_name(&info
, list
->addr
[i
].device_id
,
103 MFI_COMMAND(foreign
, drives
, foreign_drives
);
106 foreign_clear(int ac __unused
, char **av __unused
)
110 fd
= mfi_open(mfi_unit
);
118 "Are you sure you wish to clear ALL foreign configurations"
119 " on mfi%u? [y/N] ", mfi_unit
);
122 if (ch
!= 'y' && ch
!= 'Y') {
123 printf("\nAborting\n");
128 if (mfi_dcmd_command(fd
, MFI_DCMD_CFG_FOREIGN_CLEAR
, NULL
, 0, NULL
,
131 warn("Failed to clear foreign configuration");
136 printf("mfi%d: Foreign configuration cleared\n", mfi_unit
);
140 MFI_COMMAND(foreign
, clear
, foreign_clear
);
143 foreign_scan(int ac __unused
, char **av __unused
)
145 struct mfi_foreign_scan_info info
;
148 fd
= mfi_open(mfi_unit
);
155 if (mfi_dcmd_command(fd
, MFI_DCMD_CFG_FOREIGN_SCAN
, &info
,
156 sizeof(info
), NULL
, 0, NULL
) < 0) {
158 warn("Failed to scan foreign configuration");
163 printf("mfi%d: Found %d foreign configurations\n", mfi_unit
,
168 MFI_COMMAND(foreign
, scan
, foreign_scan
);
171 foreign_show_cfg(int fd
, uint32_t opcode
, uint8_t cfgidx
)
173 struct mfi_config_data
*config
;
178 bzero(mbox
, sizeof(mbox
));
180 if (mfi_config_read_opcode(fd
, opcode
, &config
, mbox
, sizeof(mbox
))
183 warn("Failed to get foreign config %d", cfgidx
);
188 if (opcode
== MFI_DCMD_CFG_FOREIGN_PREVIEW
)
189 sprintf(prefix
, "Foreign configuration preview %d", cfgidx
);
191 sprintf(prefix
, "Foreign configuration %d", cfgidx
);
193 * MegaCli uses DCMD opcodes: 0x03100200 (which fails) followed by
194 * 0x1a721880 which returns what looks to be drive / volume info
195 * but we have no real information on what these are or what they do
196 * so we're currently relying solely on the config returned above
198 dump_config(fd
, config
, prefix
);
205 foreign_display(int ac
, char **av
)
207 struct mfi_foreign_scan_info info
;
212 warnx("foreign display: extra arguments");
216 fd
= mfi_open(mfi_unit
);
223 if (mfi_dcmd_command(fd
, MFI_DCMD_CFG_FOREIGN_SCAN
, &info
,
224 sizeof(info
), NULL
, 0, NULL
) < 0) {
226 warn("Failed to scan foreign configuration");
231 if (0 == info
.count
) {
232 warnx("foreign display: no foreign configs found");
238 for (i
= 0; i
< info
.count
; i
++) {
239 error
= foreign_show_cfg(fd
,
240 MFI_DCMD_CFG_FOREIGN_DISPLAY
, i
);
245 if (i
< info
.count
- 1)
248 } else if (2 == ac
) {
249 error
= foreign_show_cfg(fd
,
250 MFI_DCMD_CFG_FOREIGN_DISPLAY
, atoi(av
[1]));
260 MFI_COMMAND(foreign
, display
, foreign_display
);
263 foreign_preview(int ac
, char **av
)
265 struct mfi_foreign_scan_info info
;
270 warnx("foreign preview: extra arguments");
274 fd
= mfi_open(mfi_unit
);
281 if (mfi_dcmd_command(fd
, MFI_DCMD_CFG_FOREIGN_SCAN
, &info
,
282 sizeof(info
), NULL
, 0, NULL
) < 0) {
284 warn("Failed to scan foreign configuration");
289 if (0 == info
.count
) {
290 warnx("foreign preview: no foreign configs found");
296 for (i
= 0; i
< info
.count
; i
++) {
297 error
= foreign_show_cfg(fd
,
298 MFI_DCMD_CFG_FOREIGN_PREVIEW
, i
);
303 if (i
< info
.count
- 1)
306 } else if (2 == ac
) {
307 error
= foreign_show_cfg(fd
,
308 MFI_DCMD_CFG_FOREIGN_PREVIEW
, atoi(av
[1]));
318 MFI_COMMAND(foreign
, preview
, foreign_preview
);
321 foreign_import(int ac
, char **av
)
323 struct mfi_foreign_scan_info info
;
329 warnx("foreign preview: extra arguments");
333 fd
= mfi_open(mfi_unit
);
340 if (mfi_dcmd_command(fd
, MFI_DCMD_CFG_FOREIGN_SCAN
, &info
,
341 sizeof(info
), NULL
, 0, NULL
) < 0) {
343 warn("Failed to scan foreign configuration");
348 if (0 == info
.count
) {
349 warnx("foreign import: no foreign configs found");
356 printf("Are you sure you wish to import ALL foreign "
357 "configurations on mfi%u? [y/N] ", mfi_unit
);
360 * While this is docmmented for MegaCli this failed with
361 * exit code 0x03 on the test controller which was a Supermicro
362 * SMC2108 with firmware 12.12.0-0095 which is a LSI 2108 based
365 cfgidx
= atoi(av
[1]);
366 if (cfgidx
>= info
.count
) {
367 warnx("Invalid foreign config %d specified max is %d",
368 cfgidx
, info
.count
- 1);
372 printf("Are you sure you wish to import the foreign "
373 "configuration %d on mfi%u? [y/N] ", cfgidx
, mfi_unit
);
377 if (ch
!= 'y' && ch
!= 'Y') {
378 printf("\nAborting\n");
383 bzero(mbox
, sizeof(mbox
));
385 if (mfi_dcmd_command(fd
, MFI_DCMD_CFG_FOREIGN_IMPORT
, NULL
, 0, mbox
,
386 sizeof(mbox
), NULL
) < 0) {
388 warn("Failed to import foreign configuration");
394 printf("mfi%d: All foreign configurations imported\n",
397 printf("mfi%d: Foreign configuration %d imported\n", mfi_unit
,
402 MFI_COMMAND(foreign
, import
, foreign_import
);