1 /* $NetBSD: config.c,v 1.4 2007/03/26 23:08:29 hubertf 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
57 * from FreeBSD: config.c,v 1.2 2000/04/11 23:04:17 msmith Exp
61 #include <sys/cdefs.h>
62 __RCSID("$NetBSD: config.c,v 1.4 2007/03/26 23:08:29 hubertf Exp $");
65 #include <sys/types.h>
66 #include <sys/param.h>
67 #include <sys/ioctl.h>
68 #include <sys/queue.h>
70 #include <dev/ic/mlxreg.h>
71 #include <dev/ic/mlxio.h>
82 struct conf_phys_drv
{
83 TAILQ_ENTRY(conf_phys_drv
) pd_link
;
86 struct mlx_phys_drv pd_drv
;
90 TAILQ_ENTRY(conf_span
) s_link
;
91 struct conf_phys_drv
*s_drvs
[8];
92 struct mlx_sys_drv_span s_span
;
96 TAILQ_ENTRY(conf_sys_drv
) sd_link
;
97 struct conf_span
*sd_spans
[4];
98 struct mlx_sys_drv sd_drv
;
102 TAILQ_HEAD(,conf_phys_drv
) cc_phys_drvs
;
103 TAILQ_HEAD(,conf_span
) cc_spans
;
104 TAILQ_HEAD(,conf_sys_drv
) cc_sys_drvs
;
105 struct conf_sys_drv
*cc_drives
[32];
106 struct mlx_core_cfg cc_cfg
;
109 static void print_span(struct mlx_sys_drv_span
*, int);
110 static void print_sys_drive(struct conf_config
*, int);
111 static void print_phys_drive(struct conf_config
*, int, int);
114 * Get the configuration from the selected controller.
116 * config <controller>
117 * Print the configuration for <controller>
119 * XXX update to support adding/deleting drives.
122 cmd_config(char **argv
)
124 char hostname
[MAXHOSTNAMELEN
];
125 struct conf_config conf
;
128 if (ci
.ci_firmware_id
[0] < 3) {
129 warnx("action not supported by this firmware version");
133 memset(&conf
.cc_cfg
, 0, sizeof(conf
.cc_cfg
));
134 mlx_configuration(&conf
.cc_cfg
, 0);
136 gethostname(hostname
, sizeof(hostname
));
137 printf("# controller %s on %s\n", mlxname
, hostname
);
139 printf("#\n# physical devices connected:\n");
140 for (i
= 0; i
< 5; i
++)
141 for (j
= 0; j
< 16; j
++)
142 print_phys_drive(&conf
, i
, j
);
144 printf("#\n# system drives defined:\n");
145 for (i
= 0; i
< conf
.cc_cfg
.cc_num_sys_drives
; i
++)
146 print_sys_drive(&conf
, i
);
152 * Print details for the system drive (drvno) in a format that we will be
153 * able to parse later.
155 * drive?? <raidlevel> <writemode>
156 * span? 0x????????-0x???????? ????blks on <disk> [...]
160 print_span(struct mlx_sys_drv_span
*span
, int arms
)
164 printf("0x%08x-0x%08x %u blks on", span
->sp_start_lba
,
165 span
->sp_start_lba
+ span
->sp_nblks
, span
->sp_nblks
);
167 for (i
= 0; i
< arms
; i
++)
168 printf(" disk%02d%02d", span
->sp_arm
[i
] >> 4,
169 span
->sp_arm
[i
] & 0x0f);
175 print_sys_drive(struct conf_config
*conf
, int drvno
)
177 struct mlx_sys_drv
*drv
;
180 drv
= &conf
->cc_cfg
.cc_sys_drives
[drvno
];
182 printf("drive%02d ", drvno
);
184 switch(drv
->sd_raidlevel
& 0xf) {
185 case MLX_SYS_DRV_RAID0
:
188 case MLX_SYS_DRV_RAID1
:
191 case MLX_SYS_DRV_RAID3
:
194 case MLX_SYS_DRV_RAID5
:
197 case MLX_SYS_DRV_RAID6
:
200 case MLX_SYS_DRV_JBOD
:
209 drv
->sd_raidlevel
& MLX_SYS_DRV_WRITEBACK
? "back" : "through");
211 for (i
= 0; i
< drv
->sd_valid_spans
; i
++) {
212 printf(" span%d ", i
);
213 print_span(&drv
->sd_span
[i
], drv
->sd_valid_arms
);
218 * Print details for the physical drive at chn/targ in a format suitable for
222 print_phys_drive(struct conf_config
*conf
, int chn
, int targ
)
224 struct mlx_phys_drv
*pd
;
226 pd
= &conf
->cc_cfg
.cc_phys_drives
[chn
* 16 + targ
];
228 /* If the drive isn't present, don't print it. */
229 if ((pd
->pd_flags1
& MLX_PHYS_DRV_PRESENT
) == 0)
232 mlx_print_phys_drv(pd
, chn
, targ
, "# ");