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 asprintf(&prefix, "Foreign configuration preview %d", cfgidx);
191 asprintf(&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);
206 foreign_display(int ac, char **av)
208 struct mfi_foreign_scan_info info;
213 warnx("foreign display: extra arguments");
217 fd = mfi_open(mfi_unit);
224 if (mfi_dcmd_command(fd, MFI_DCMD_CFG_FOREIGN_SCAN, &info,
225 sizeof(info), NULL, 0, NULL) < 0) {
227 warn("Failed to scan foreign configuration");
232 if (0 == info.count) {
233 warnx("foreign display: no foreign configs found");
239 for (i = 0; i < info.count; i++) {
240 error = foreign_show_cfg(fd,
241 MFI_DCMD_CFG_FOREIGN_DISPLAY, i);
246 if (i < info.count - 1)
249 } else if (2 == ac) {
250 error = foreign_show_cfg(fd,
251 MFI_DCMD_CFG_FOREIGN_DISPLAY, atoi(av[1]));
261 MFI_COMMAND(foreign, display, foreign_display);
264 foreign_preview(int ac, char **av)
266 struct mfi_foreign_scan_info info;
271 warnx("foreign preview: extra arguments");
275 fd = mfi_open(mfi_unit);
282 if (mfi_dcmd_command(fd, MFI_DCMD_CFG_FOREIGN_SCAN, &info,
283 sizeof(info), NULL, 0, NULL) < 0) {
285 warn("Failed to scan foreign configuration");
290 if (0 == info.count) {
291 warnx("foreign preview: no foreign configs found");
297 for (i = 0; i < info.count; i++) {
298 error = foreign_show_cfg(fd,
299 MFI_DCMD_CFG_FOREIGN_PREVIEW, i);
304 if (i < info.count - 1)
307 } else if (2 == ac) {
308 error = foreign_show_cfg(fd,
309 MFI_DCMD_CFG_FOREIGN_PREVIEW, atoi(av[1]));
319 MFI_COMMAND(foreign, preview, foreign_preview);
322 foreign_import(int ac, char **av)
324 struct mfi_foreign_scan_info info;
330 warnx("foreign preview: extra arguments");
334 fd = mfi_open(mfi_unit);
341 if (mfi_dcmd_command(fd, MFI_DCMD_CFG_FOREIGN_SCAN, &info,
342 sizeof(info), NULL, 0, NULL) < 0) {
344 warn("Failed to scan foreign configuration");
349 if (0 == info.count) {
350 warnx("foreign import: no foreign configs found");
357 printf("Are you sure you wish to import ALL foreign "
358 "configurations on mfi%u? [y/N] ", mfi_unit);
361 * While this is docmmented for MegaCli this failed with
362 * exit code 0x03 on the test controller which was a Supermicro
363 * SMC2108 with firmware 12.12.0-0095 which is a LSI 2108 based
366 cfgidx = atoi(av[1]);
367 if (cfgidx >= info.count) {
368 warnx("Invalid foreign config %d specified max is %d",
369 cfgidx, info.count - 1);
373 printf("Are you sure you wish to import the foreign "
374 "configuration %d on mfi%u? [y/N] ", cfgidx, mfi_unit);
378 if (ch != 'y' && ch != 'Y') {
379 printf("\nAborting\n");
384 bzero(mbox, sizeof(mbox));
386 if (mfi_dcmd_command(fd, MFI_DCMD_CFG_FOREIGN_IMPORT, NULL, 0, mbox,
387 sizeof(mbox), NULL) < 0) {
389 warn("Failed to import foreign configuration");
395 printf("mfi%d: All foreign configurations imported\n",
398 printf("mfi%d: Foreign configuration %d imported\n", mfi_unit,
403 MFI_COMMAND(foreign, import, foreign_import);