4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
23 * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
47 #include <sys/types.h>
48 #include <sys/ioctl.h>
49 #include <sys/dditypes.h>
50 #include <sys/modctl.h>
51 #include <libdevinfo.h>
52 #include <libdevice.h>
57 #include <sys/ioctl.h>
58 #include <sys/byteorder.h>
59 #include <sys/scsi/scsi.h>
61 #include <sys/vfstab.h>
63 #include <sys/mnttab.h>
68 #include <sys/param.h>
76 #define CFGA_PLUGIN_LIB
77 #include <config_admin.h>
87 /* Return/error codes */
105 /* Commands used internally */
107 SCFGA_INVAL_CMD
= -1,
125 SCFGA_BUS_UNCONFIGURE
,
127 SCFGA_DEV_UNCONFIGURE
,
150 /* Structures for tree walking code */
154 int (*fcn
)(di_node_t node
, void *argp
);
158 const char *nodetype
;
159 int (*fcn
)(di_node_t node
, di_minor_t minor
, void *argp
);
163 walk_node_t node_args
;
164 walk_minor_t minor_args
;
175 typedef struct ldata_list
{
176 cfga_list_data_t ldata
;
177 struct ldata_list
*next
;
181 struct cfga_confirm
*confp
;
182 struct cfga_msg
*msgp
;
188 dyncomp_t dyntype
; /* is pathinfo or dev apid? */
189 char *path
; /* for apid with device dyn comp. */
193 /* Private hardware options */
194 #define OPT_DISABLE_RCM "disable_rcm"
195 #define OPT_USE_DIFORCE "use_diforce"
198 #define FLAG_DISABLE_RCM 0x01
199 #define FLAG_USE_DIFORCE 0x02
201 /* internal use for handling pathinfo */
202 #define FLAG_CLIENT_DEV 0x04
218 ERR_BUS_NOTCONNECTED
,
234 ERR_BUS_DEV_MISMATCH
,
238 /* Errors with arguments */
251 ERRARG_RCM_CLIENT_OFFLINE
,
269 /* Hotplug messages */
275 /* Hotplugging confirmation prompts */
284 /* HDD led/locator messages */
286 MSG_MISSING_LED_NAME
,
310 scfga_ret_t (*fcn
)(const char *, scfga_cmd_t
, apid_t
*, prompt_t
*,
311 cfga_flags_t
, char **);
316 int nargs
; /* Number of arguments following msgid */
317 int intl
; /* Flag: if 1, internationalize */
323 #define CFGA_DEV_DIR "/dev/cfg"
324 #define DEV_DIR "/dev"
325 #define DEVICES_DIR "/devices"
326 #define DEV_DSK "/dev/dsk"
327 #define DEV_RDSK "/dev/rdsk"
328 #define DEV_RMT "/dev/rmt"
329 #define DSK_DIR "dsk"
330 #define RDSK_DIR "rdsk"
331 #define RMT_DIR "rmt"
335 #define MINOR_SEP ":"
336 #define PATH_APID_DYN_SEP ","
338 #define S_FREE(x) (((x) != NULL) ? (free(x), (x) = NULL) : (void *)0)
339 #define S_STR(x) (((x) == NULL) ? "" : (x))
342 #define IS_STUB_NODE(s) (di_instance(s) == -1 && \
343 di_nodeid(s) == (DI_PROM_NODEID))
345 #define GET_MSG_STR(i) (str_tbl[msg_idx(i)].msgstr)
347 #define GET_DYN(a) (((a) != NULL) ? strstr((a), DYN_SEP) : (void *)0)
350 * The following macro removes the separator from the dynamic component.
352 #define DYN_TO_DYNCOMP(a) ((a) + strlen(DYN_SEP))
354 extern int _scfga_debug
;
357 * Tracing/debugging macros
359 #define CFGA_TRACE1(args) (void) ((_scfga_debug >= 1) ? fprintf args : 0)
360 #define CFGA_TRACE2(args) (void) ((_scfga_debug >= 2) ? fprintf args : 0)
361 #define CFGA_TRACE3(args) (void) ((_scfga_debug >= 3) ? fprintf args : 0)
363 /* Function prototypes */
365 /* bus/device ctl routines */
366 scfga_ret_t
bus_change_state(cfga_cmd_t state_change_cmd
,
367 apid_t
*apidp
, struct cfga_confirm
*confp
, cfga_flags_t flags
,
369 scfga_ret_t
dev_change_state(cfga_cmd_t state_change_cmd
,
370 apid_t
*apidp
, cfga_flags_t flags
, char **errstring
);
371 scfga_ret_t
dev_insert(const char *func
, scfga_cmd_t cmd
, apid_t
*apidp
,
372 prompt_t
*argsp
, cfga_flags_t flags
, char **errstring
);
373 scfga_ret_t
dev_replace(const char *func
, scfga_cmd_t cmd
, apid_t
*apidp
,
374 prompt_t
*argsp
, cfga_flags_t flags
, char **errstring
);
375 scfga_ret_t
dev_remove(const char *func
, scfga_cmd_t cmd
, apid_t
*apidp
,
376 prompt_t
*argsp
, cfga_flags_t flags
, char **errstring
);
377 scfga_ret_t
reset_common(const char *func
, scfga_cmd_t cmd
, apid_t
*apidp
,
378 prompt_t
*argsp
, cfga_flags_t flags
, char **errstring
);
379 scfga_ret_t
dev_led(const char *func
, scfga_cmd_t cmd
, apid_t
*apidp
,
380 prompt_t
*argsp
, cfga_flags_t flags
, char **errstring
);
381 scfga_ret_t
plat_dev_led(const char *func
, scfga_cmd_t cmd
, apid_t
*apidp
,
382 prompt_t
*argsp
, cfga_flags_t flags
, char **errstring
);
385 /* List related routines */
386 scfga_ret_t
do_list(apid_t
*apidp
, scfga_cmd_t cmd
,
387 ldata_list_t
**llpp
, int *nelem
, char **errstring
);
388 scfga_ret_t
list_ext_postprocess(ldata_list_t
**llpp
, int nelem
,
389 cfga_list_data_t
**ap_id_list
, int *nlistp
, char **errstring
);
390 int stat_path_info(di_node_t root
, void *arg
, int *l_errnop
);
393 /* Conversion routines */
394 scfga_ret_t
make_hba_logid(const char *hba_phys
, char **hba_logpp
,
396 scfga_ret_t
apid_to_path(const char *hba_phys
, const char *dyncomp
,
397 char **pathpp
, int *l_errnop
);
398 scfga_ret_t
make_dyncomp(di_node_t node
, const char *physpath
,
399 char **dyncompp
, int *l_errnop
);
400 scfga_ret_t
make_path_dyncomp(di_path_t path
, char **dyncomp
, int *l_errnop
);
404 scfga_ret_t
scsi_rcm_suspend(char **rsrclist
, char **errstring
,
405 cfga_flags_t flags
, int pflag
);
406 scfga_ret_t
scsi_rcm_resume(char **rsrclist
, char **errstring
,
407 cfga_flags_t flags
, int pflag
);
408 scfga_ret_t
scsi_rcm_offline(char **rsrclist
, char **errstring
,
410 scfga_ret_t
scsi_rcm_online(char **rsrclist
, char **errstring
,
412 scfga_ret_t
scsi_rcm_remove(char **rsrclist
, char **errstring
,
416 /* Utility routines */
417 scfga_ret_t
physpath_to_devlink(char *physpath
, char **linkpp
, int *l_errnop
,
419 scfga_ret_t
apidt_create(const char *ap_id
, apid_t
*apidp
,
421 void apidt_free(apid_t
*apidp
);
422 cfga_err_t
err_cvt(scfga_ret_t err
);
423 void list_free(ldata_list_t
**llpp
);
424 int known_state(di_node_t node
);
425 scfga_ret_t
devctl_cmd(const char *ap_id
, scfga_cmd_t cmd
,
426 uint_t
*statep
, int *l_errnop
);
427 scfga_ret_t
path_apid_state_change(apid_t
*apidp
, scfga_cmd_t cmd
,
428 cfga_flags_t flags
, char **errstring
, int *l_errnop
, msgid_t errid
);
429 scfga_ret_t
invoke_cmd(const char *func
, apid_t
*apidt
, prompt_t
*prp
,
430 cfga_flags_t flags
, char **errstring
);
432 void cfga_err(char **errstring
, int use_errno
, ...);
433 void cfga_msg(struct cfga_msg
*msgp
, ...);
434 void cfga_led_msg(struct cfga_msg
*msgp
, apid_t
*apidp
, led_strid_t
,
436 char *cfga_str(int append_newline
, ...);
437 int msg_idx(msgid_t msgid
);
438 scfga_ret_t
walk_tree(const char *physpath
, void *arg
, uint_t init_flags
,
439 walkarg_t
*up
, scfga_cmd_t cmd
, int *l_errnop
);
440 int hba_dev_cmp(const char *hba
, const char *dev
);
441 int dev_cmp(const char *dev1
, const char *dev2
, int match_minor
);
443 extern msgcvt_t str_tbl
[];
449 #endif /* _CFGA_SCSI_H */