Merge commit 'b1e7e97d3b60469b243b3b2e22c7d8cbd11c7c90'
[unleashed.git] / usr / src / lib / cfgadm_plugins / ib / common / cfga_ib.c
blob2e6cf8fd44e664c6d58bb08ba843b01bb24a8614
1 /*
2 * CDDL HEADER START
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]
19 * CDDL HEADER END
22 * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
23 * Use is subject to license terms.
24 * Copyright 2018 OmniOS Community Edition (OmniOSce) Association.
27 #include "cfga_ib.h"
30 * cfga_ib.c:
31 * All cfgadm entry points that are defined in the config_admin(3X)
32 * needed for InfiniBand support are described here. These cfgadm
33 * interfaces issue ioctl(s) to the IB nexus driver. Attachment points
34 * supported are - IOC, VPPA, Port, HCA_SVC and Pseudo dynamic ap_ids,
35 * the HCA static ap_id, and the IB static ap_id.
37 * Given InfiniBand bus is fabric based, #of dynamic ap_ids present are
38 * unknown at any given point of time. Hence this plugin uses a
39 * packed nvlist data structure to hold ap_id related information.
40 * The IB nexus driver allocates the nvlist data in the kernel
41 * and this plugin processes the data (it is freed by IB nexus driver).
45 /* function prototypes */
46 static int ib_get_link(di_devlink_t, void *);
47 static icfga_ret_t ib_physpath_to_devlink(char *, char **, int *);
48 static const char *ib_get_msg(uint_t, msgcvt_t *, uint_t);
49 static void ib_set_msg(char **, ...);
50 static cfga_err_t ib_err_msg(char **, cfga_ib_ret_t, const char *, int);
51 static int ib_verify_valid_apid(const char *);
52 static cfga_ib_ret_t ib_verify_params(const char *, const char *, char **);
53 static void ib_cleanup_after_devctl_cmd(devctl_hdl_t, nvlist_t *);
54 static cfga_ib_ret_t ib_setup_for_devctl_cmd(char *, boolean_t,
55 devctl_hdl_t *, nvlist_t **);
56 static cfga_ib_ret_t ib_device_configured(devctl_hdl_t, nvlist_t *,
57 ap_rstate_t *);
58 static cfga_ib_ret_t ib_device_connected(devctl_hdl_t, nvlist_t *,
59 ap_ostate_t *);
60 static cfga_ib_ret_t ib_do_control_ioctl(char *, uint_t, uint_t, uint_t,
61 void **, size_t *);
62 cfga_err_t cfga_change_state(cfga_cmd_t, const char *,
63 const char *, struct cfga_confirm *,
64 struct cfga_msg *, char **, cfga_flags_t);
65 cfga_err_t cfga_private_func(const char *, const char *,
66 const char *, struct cfga_confirm *,
67 struct cfga_msg *, char **, cfga_flags_t);
68 cfga_err_t cfga_test(const char *, const char *, struct cfga_msg *,
69 char **, cfga_flags_t);
70 static cfga_ib_ret_t ib_fill_static_apids(char *, cfga_list_data_t *);
71 cfga_err_t cfga_list_ext(const char *, cfga_list_data_t **, int *,
72 const char *, const char *, char **, cfga_flags_t);
73 void cfga_msg(struct cfga_msg *, const char *);
74 cfga_err_t cfga_help(struct cfga_msg *, const char *,
75 cfga_flags_t);
76 static int ib_confirm(struct cfga_confirm *, char *);
77 static char *ib_get_devicepath(const char *);
80 /* External function prototypes */
81 extern cfga_ib_ret_t ib_rcm_offline(const char *, char **, char *,
82 cfga_flags_t);
83 extern cfga_ib_ret_t ib_rcm_online(const char *, char **, char *,
84 cfga_flags_t);
85 extern cfga_ib_ret_t ib_rcm_remove(const char *, char **, char *,
86 cfga_flags_t);
87 extern int ib_add_service(char **);
88 extern int ib_delete_service(char **);
89 extern int ib_list_services(struct cfga_msg *, char **);
92 /* Globals */
93 int cfga_version = CFGA_HSL_V2; /* Set the version number for */
94 /* the cfgadm library's use. */
96 static char *ib_help[] = { /* Help messages */
97 NULL,
98 /* CFGA_IB_HELP_HEADER */ "IB specific commands:\n",
99 /* CFGA_IB_HELP_CONFIG */ "cfgadm -c [configure|unconfigure] "
100 "ap_id [ap_id...]\n",
101 /* CFGA_IB_HELP_LIST */ "cfgadm -x list_clients hca_ap_id "
102 "[hca_ap_id...]\n",
103 /* CFGA_IB_HELP_UPD_PKEY */ "cfgadm -x update_pkey_tbls ib\n",
104 /* CFGA_IB_HELP_CONF_FILE1 */ "cfgadm -o comm=[port|vppa|hca-svc],"
105 "service=<name> -x [add_service|delete_service] ib\n",
106 /* CFGA_IB_HELP_CONF_FILE2 */ "cfgadm -x list_services ib\n",
107 /* CFGA_IB_HELP_UPD_IOC_CONF */ "cfgadm -x update_ioc_config "
108 "[ib | ioc_apid]\n",
109 /* CFGA_IB_HELP_UNCFG_CLNTS */ "cfgadm -x unconfig_clients hca_ap_id "
110 "[hca_ap_id...]\n",
111 /* CFGA_IB_HELP_UNKNOWN */ "\tunknown command or option: ",
112 NULL
115 static msgcvt_t ib_error_msgs[] = { /* Error messages */
116 /* CFGA_IB_OK */ { CVT, CFGA_OK, "ok" },
117 /* CFGA_IB_UNKNOWN */ { CVT, CFGA_LIB_ERROR,
118 "Unknown message; internal error " },
119 /* CFGA_IB_INTERNAL_ERR */ { CVT, CFGA_LIB_ERROR,
120 "Internal error " },
121 /* CFGA_IB_INVAL_ARG_ERR */ { CVT, CFGA_LIB_ERROR,
122 "Invalid input args " },
123 /* CFGA_IB_OPTIONS_ERR */ { CVT, CFGA_ERROR,
124 "Hardware specific options not supported " },
125 /* CFGA_IB_AP_ERR */ { CVT, CFGA_APID_NOEXIST, "" },
126 /* CFGA_IB_DEVCTL_ERR */ { CVT, CFGA_LIB_ERROR,
127 "Cannot issue devctl to " },
128 /* CFGA_IB_NOT_CONNECTED */ { CVT, CFGA_INSUFFICENT_CONDITION,
129 "No device connected to " },
130 /* CFGA_IB_NOT_CONFIGURED */ { CVT, CFGA_INSUFFICENT_CONDITION,
131 "No device configured to " },
132 /* CFGA_IB_ALREADY_CONNECTED */ { CVT, CFGA_INSUFFICENT_CONDITION,
133 "already connected; cannot connect again " },
134 /* CFGA_IB_ALREADY_CONFIGURED */ { CVT, CFGA_INSUFFICENT_CONDITION,
135 "already configured " },
136 /* CFGA_IB_CONFIG_OP_ERR */ { CVT, CFGA_ERROR,
137 "configure operation failed " },
138 /* CFGA_IB_UNCONFIG_OP_ERR */ { CVT, CFGA_ERROR,
139 "unconfigure operation failed " },
140 /* CFGA_IB_OPEN_ERR */ { CVT, CFGA_LIB_ERROR, "Cannot open " },
141 /* CFGA_IB_IOCTL_ERR */ { CVT, CFGA_LIB_ERROR,
142 "Driver ioctl failed " },
143 /* CFGA_IB_BUSY_ERR */ { CVT, CFGA_SYSTEM_BUSY, " " },
144 /* CFGA_IB_ALLOC_FAIL */ { CVT, CFGA_LIB_ERROR,
145 "Memory allocation failure " },
146 /* CFGA_IB_OPNOTSUPP */ { CVT, CFGA_OPNOTSUPP,
147 "Operation not supported " },
148 /* CFGA_IB_INVAL_APID_ERR */ { CVT, CFGA_LIB_ERROR,
149 "Invalid ap_id supplied " },
150 /* CFGA_IB_DEVLINK_ERR */ { CVT, CFGA_LIB_ERROR,
151 "Could not find /dev/cfg link for " },
152 /* CFGA_IB_PRIV_ERR */ { CVT, CFGA_PRIV, " " },
153 /* CFGA_IB_NVLIST_ERR */ { CVT, CFGA_ERROR,
154 "Internal error (nvlist) " },
155 /* CFGA_IB_HCA_LIST_ERR */ { CVT, CFGA_ERROR,
156 "Listing HCA's clients failed " },
157 /* CFGA_IB_HCA_UNCONFIG_ERR */ { CVT, CFGA_ERROR,
158 "Unconfiguring HCA's clients failed " },
159 /* CFGA_IB_UPD_PKEY_TBLS_ERR */ { CVT, CFGA_ERROR,
160 "Updating P_Key tables failed " },
161 /* CFGA_IB_RCM_HANDLE_ERR */ { CVT, CFGA_ERROR,
162 "Opening ib.conf file failed " },
163 /* CFGA_IB_LOCK_FILE_ERR */ { CVT, CFGA_LIB_ERROR,
164 "Locking ib.conf file failed " },
165 /* CFGA_IB_UNLOCK_FILE_ERR */ { CVT, CFGA_LIB_ERROR,
166 "Unlocking ib.conf file failed " },
167 /* CFGA_IB_COMM_INVAL_ERR */ { CVT, CFGA_INVAL,
168 "Communication type incorrectly specified " },
169 /* CFGA_IB_SVC_INVAL_ERR */ { CVT, CFGA_INVAL,
170 "Service name incorrectly specified " },
171 /* CFGA_IB_SVC_LEN_ERR_ERR */ { CVT, CFGA_INVAL,
172 "Service name len should be <= to 4, " },
173 /* CFGA_IB_SVC_EXISTS_ERR */ { CVT, CFGA_INVAL, " "},
174 /* CFGA_IB_SVC_NO_EXIST_ERR */ { CVT, CFGA_INVAL, " " },
175 /* CFGA_IB_UCFG_CLNTS_ERR */ { CVT, CFGA_INVAL,
176 "unconfig_clients failed for HCA " },
177 /* CFGA_IB_INVALID_OP_ERR */ { CVT, CFGA_OPNOTSUPP, "on " },
178 /* CFGA_IB_RCM_HANDLE */ { CVT, CFGA_ERROR,
179 "cannot get RCM handle "},
180 /* CFGA_IB_RCM_ONLINE_ERR */ { CVT, CFGA_SYSTEM_BUSY,
181 "failed to online: "},
182 /* CFGA_IB_RCM_OFFLINE_ERR */ { CVT, CFGA_SYSTEM_BUSY,
183 "failed to offline: "}
187 * these are the only valid sub-options for services.
189 static char *ib_service_subopts[] = {
190 "comm",
191 "service",
192 NULL
195 /* Communication Service name : "port" or "vppa" or "hca-svc" */
196 static char *comm_name = NULL;
198 char *service_name = NULL; /* service name */
199 ib_service_type_t service_type = IB_NONE; /* service type */
202 /* ========================================================================= */
204 * The next two funcs are imported from cfgadm_scsi.
205 * ib_physpath_to_devlink is the only func directly used by cfgadm_ib.
206 * ib_get_link supports it.
210 * Function:
211 * ib_get_link
212 * Input:
213 * devlink - devlink for the device path
214 * arg - argument passed to this "walker" function
215 * Output:
216 * NONE
217 * Returns:
218 * Continue "walking" or not
219 * Description:
220 * Routine to search the /dev directory or a subtree of /dev.
222 static int
223 ib_get_link(di_devlink_t devlink, void *arg)
225 walk_link_t *larg = (walk_link_t *)arg;
228 * When path is specified, it's the node path without minor
229 * name. Therefore, the ../.. prefixes needs to be stripped.
231 if (larg->path) {
232 char *content = (char *)di_devlink_content(devlink);
233 char *start = strstr(content, "/devices/");
235 /* line content must have minor node */
236 if (start == NULL ||
237 strncmp(start, larg->path, larg->len) != 0 ||
238 start[larg->len] != ':') {
239 return (DI_WALK_CONTINUE);
243 *(larg->linkpp) = strdup(di_devlink_path(devlink));
244 return (DI_WALK_TERMINATE);
249 * Function:
250 * ib_physpath_to_devlink
251 * Input:
252 * node_path - Physical path of the ap_id node
253 * Output:
254 * logpp - Logical path to the ap_id node
255 * l_errnop - "errno"
256 * Returns:
257 * ICFGA_OK if everything was fine; otherwise an error with
258 * l_errnop set.
259 * Description:
260 * Given a physical path to an ap_id ensure that it exists
262 /* ARGSUSED */
263 static icfga_ret_t
264 ib_physpath_to_devlink(char *node_path, char **logpp, int *l_errnop)
266 char *minor_path;
267 walk_link_t larg;
268 di_devlink_handle_t hdl;
270 if ((hdl = di_devlink_init(NULL, 0)) == NULL) {
271 *l_errnop = errno;
272 return (ICFGA_LIB_ERR);
275 *logpp = NULL;
276 larg.linkpp = logpp;
277 minor_path = (char *)node_path + strlen("/devices");
278 larg.path = NULL;
279 larg.len = 0;
281 (void) di_devlink_walk(hdl, "^cfg/", minor_path, DI_PRIMARY_LINK,
282 (void *)&larg, ib_get_link);
284 di_devlink_fini(&hdl);
286 if (*logpp == NULL) {
287 *l_errnop = errno;
288 return (ICFGA_LIB_ERR);
291 return (ICFGA_OK);
295 /* ========================================================================= */
296 /* Utilities */
299 * Function:
300 * ib_get_msg
301 * Input:
302 * msg_index - Index into the message table
303 * msg_tbl - the message table
304 * tbl_size - size of the message table
305 * Output:
306 * NONE
307 * Returns:
308 * Message string if valid, otherwise an error
309 * Description:
310 * Given the index into a table (msgcvt_t) of messages,
311 * get the message string, converting it to the proper
312 * locale if necessary.
314 * NOTE: See cfga_ib.h
316 static const char *
317 ib_get_msg(uint_t msg_index, msgcvt_t *msg_tbl, uint_t tbl_size)
319 if (msg_index >= tbl_size) {
320 DPRINTF("get_error_msg: bad error msg index: %d\n", msg_index);
321 msg_index = CFGA_IB_UNKNOWN;
324 return ((msg_tbl[msg_index].intl) ?
325 dgettext(TEXT_DOMAIN, msg_tbl[msg_index].msgstr) :
326 msg_tbl[msg_index].msgstr);
331 * Function:
332 * ib_set_msg
333 * Input:
334 * NONE
335 * Output:
336 * ret_str - Returned "message" string.
337 * Returns:
338 * NONE
339 * Description:
340 * Allocates and creates a message string (in *ret_str),
341 * by concatenating all the (char *) args together, in order.
342 * Last arg MUST be NULL.
344 static void
345 ib_set_msg(char **ret_str, ...)
347 char *str;
348 size_t total_len, ret_str_len;
349 va_list valist;
351 va_start(valist, ret_str);
353 total_len = (*ret_str == NULL) ? 0 : strlen(*ret_str);
355 while ((str = va_arg(valist, char *)) != NULL) {
356 size_t len = strlen(str);
357 char *old_str = *ret_str;
359 ret_str_len = total_len + len + 1;
360 *ret_str = (char *)realloc(*ret_str, ret_str_len);
361 if (*ret_str == NULL) {
362 free(old_str);
363 DPRINTF("ib_set_msg: realloc failed.\n");
364 va_end(valist);
365 return;
368 (void) strlcpy(*ret_str + total_len, str, ret_str_len);
369 total_len += len;
372 va_end(valist);
377 * Function:
378 * ib_err_msg
379 * Input:
380 * ap_id - The attachment point of an IB fabric
381 * Output:
382 * errstring - Fill in the error msg string
383 * l_errno - The "errno" to be filled in.
384 * Returns:
385 * CFGA_IB_OK if we are able to fill in error msg;
386 * otherwise emit an error.
387 * Description:
388 * Error message handling.
390 * For the rv passed in, looks up the corresponding error message
391 * string(s), internationalized it if necessary, and concatenates
392 * it into a new memory buffer, and points *errstring to it.
393 * Note not all "rv"s will result in an error message return, as
394 * not all error conditions warrant a IB-specific error message.
396 * Some messages may display ap_id or errno, which is why they are
397 * passed in.
399 static cfga_err_t
400 ib_err_msg(char **errstring, cfga_ib_ret_t rv, const char *ap_id, int l_errno)
402 char *errno_str;
404 if (errstring == NULL) {
405 return (ib_error_msgs[rv].cfga_err);
408 /* Generate the appropriate IB-specific error message(s) (if any). */
409 switch (rv) {
410 case CFGA_IB_OK: /* Special case - do nothing. */
411 break;
412 case CFGA_IB_AP_ERR:
413 case CFGA_IB_UNKNOWN:
414 case CFGA_IB_INTERNAL_ERR:
415 case CFGA_IB_OPTIONS_ERR:
416 case CFGA_IB_ALLOC_FAIL:
417 /* These messages require no additional strings passed. */
418 ib_set_msg(errstring, ERR_STR(rv), NULL);
419 break;
420 case CFGA_IB_NOT_CONNECTED:
421 case CFGA_IB_NOT_CONFIGURED:
422 case CFGA_IB_ALREADY_CONNECTED:
423 case CFGA_IB_ALREADY_CONFIGURED:
424 case CFGA_IB_CONFIG_OP_ERR:
425 case CFGA_IB_UNCONFIG_OP_ERR:
426 case CFGA_IB_BUSY_ERR:
427 case CFGA_IB_DEVLINK_ERR:
428 case CFGA_IB_RCM_HANDLE_ERR:
429 case CFGA_IB_RCM_ONLINE_ERR:
430 case CFGA_IB_RCM_OFFLINE_ERR:
431 case CFGA_IB_DEVCTL_ERR:
432 case CFGA_IB_COMM_INVAL_ERR:
433 case CFGA_IB_SVC_INVAL_ERR:
434 case CFGA_IB_SVC_LEN_ERR:
435 case CFGA_IB_SVC_EXISTS_ERR:
436 case CFGA_IB_SVC_NO_EXIST_ERR:
437 case CFGA_IB_LOCK_FILE_ERR:
438 case CFGA_IB_CONFIG_FILE_ERR:
439 case CFGA_IB_UNLOCK_FILE_ERR:
440 case CFGA_IB_UCFG_CLNTS_ERR:
441 case CFGA_IB_INVALID_OP_ERR:
442 /* These messages also print ap_id. */
443 ib_set_msg(errstring, ERR_STR(rv), "ap_id: ", ap_id, "", NULL);
444 break;
445 case CFGA_IB_IOCTL_ERR: /* These messages also print errno. */
446 case CFGA_IB_NVLIST_ERR:
447 errno_str = l_errno ? strerror(l_errno) : "";
448 ib_set_msg(errstring, ERR_STR(rv), errno_str,
449 l_errno ? "\n" : "", NULL);
450 break;
451 case CFGA_IB_OPEN_ERR: /* This messages also prints apid and errno. */
452 case CFGA_IB_PRIV_ERR:
453 case CFGA_IB_HCA_LIST_ERR:
454 case CFGA_IB_OPNOTSUPP:
455 case CFGA_IB_INVAL_ARG_ERR:
456 case CFGA_IB_INVAL_APID_ERR:
457 case CFGA_IB_HCA_UNCONFIG_ERR:
458 case CFGA_IB_UPD_PKEY_TBLS_ERR:
459 errno_str = l_errno ? strerror(l_errno) : "";
460 ib_set_msg(errstring, ERR_STR(rv), "ap_id: ", ap_id, "\n",
461 errno_str, l_errno ? "\n" : "", NULL);
462 break;
463 default:
464 DPRINTF("ib_err_msg: Unrecognized message index: %d\n", rv);
465 ib_set_msg(errstring, ERR_STR(CFGA_IB_INTERNAL_ERR), NULL);
469 * Determine the proper error code to send back to the cfgadm library.
471 return (ib_error_msgs[rv].cfga_err);
476 * Function:
477 * ib_verify_valid_apid
478 * Input:
479 * ap_id - The attachment point of an IB fabric
480 * Output:
481 * NONE
482 * Returns:
483 * 0 if ap_id is valid; otherwise -1
484 * Description:
485 * Check if ap_id is valid or not.
486 * Ensure the ap_id passed is in the correct (physical ap_id) form:
487 * path/device:xx[.xx]+
488 * where xx is a one or two-digit number.
490 * Note the library always calls the plugin with a physical ap_id.
491 * Called by ib_verify_params().
493 static int
494 ib_verify_valid_apid(const char *ap_id)
496 char *l_ap_id;
498 if (ap_id == NULL) {
499 return (-1);
502 l_ap_id = strchr(ap_id, *MINOR_SEP);
503 l_ap_id++;
505 /* fabric apids */
506 if (strstr((char *)ap_id, IBNEX_FABRIC) != NULL) {
507 DPRINTF("ib_valid_apid: l_apid = %s\n", l_ap_id);
508 /* if the ap_id is "ib::" then report an error */
509 if ((strlen(l_ap_id) == strlen(IBNEX_FABRIC) + 1) ||
510 (strlen(l_ap_id) == strlen(IBNEX_FABRIC) + 2)) {
511 return (-1);
514 if (strstr(l_ap_id, "...") != NULL) {
515 return (-1);
518 } else { /* HCA ap_ids */
519 /* ap_id has 1..2 or more than 2 dots */
520 if (strstr(l_ap_id, "..") != NULL) {
521 return (-1);
525 return (0);
530 * Function:
531 * ib_verify_params
532 * Input:
533 * ap_id - The attachment point of an IB fabric
534 * options - command options passed by the cfgadm(8)
535 * errstring - This contains error msg if command fails
536 * Output:
537 * NONE
538 * Returns:
539 * CFGA_IB_OK if parameters are valid; otherwise emit an error.
540 * Description:
541 * Check if "options" and "errstring" are valid and if ap_id is
542 * valid or not.
544 static cfga_ib_ret_t
545 ib_verify_params(const char *ap_id, const char *options, char **errstring)
547 if (errstring != NULL) {
548 *errstring = NULL;
551 if (options != NULL) {
552 DPRINTF("ib_verify_params: h/w-specific options not "
553 "supported.\n");
554 return (CFGA_IB_OPTIONS_ERR);
557 if (ib_verify_valid_apid(ap_id) != 0) {
558 DPRINTF("ib_verify_params: not an IB ap_id.\n");
559 return (CFGA_IB_AP_ERR);
561 return (CFGA_IB_OK);
566 * Function:
567 * ib_cleanup_after_devctl_cmd
568 * Input:
569 * devctl_hdl - Handler to devctl
570 * user_nvlistp - Name-value-pair list pointer
571 * Output:
572 * NONE
573 * Returns:
574 * NONE
575 * Description:
576 * Cleanup an initialization/setup done in the next function i.e.
577 * ib_setup_for_devctl_cmd().
579 static void
580 ib_cleanup_after_devctl_cmd(devctl_hdl_t devctl_hdl, nvlist_t *user_nvlist)
582 nvlist_free(user_nvlist);
584 devctl_release(devctl_hdl);
589 * Function:
590 * ib_setup_for_devctl_cmd
591 * Input:
592 * ap_id - Attachment point for the IB device in question
593 * use_static_ap_id - Whether to use static ap_id or not flag
594 * Output:
595 * devctl_hdl - Handler to devctl
596 * user_nvlistp - Name-value-pair list pointer
597 * Returns:
598 * CFGA_IB_OK if it succeeds or an appropriate error.
599 * Description:
600 * For any IB device that is doing a cfgadm operation this function
601 * sets up a devctl_hdl and allocates a nvlist_t. The devctl_hdl
602 * is acquired using libdevice APIs. The nvlist_t is filled up with
603 * the ap_id (as a string). This nvlist_t is looked up in the kernel
604 * to figure out which ap_id we are currently dealing with.
606 * "use_static_ap_id" flag tells if one should do a devctl_ap_acquire
607 * with IB_STATIC_APID or not. NOTE: We need an actual file-system
608 * vnode to do a devctl_ap_acquire.
610 * NOTE: always call ib_cleanup_after_devctl_cmd() after this function.
612 static cfga_ib_ret_t
613 ib_setup_for_devctl_cmd(char *ap_id, boolean_t use_static_ap_id,
614 devctl_hdl_t *devctl_hdl, nvlist_t **user_nvlistp)
616 char *apid = (use_static_ap_id == B_TRUE) ? IB_STATIC_APID : ap_id;
618 /* Get a handle to the ap */
619 if ((*devctl_hdl = devctl_ap_acquire(apid, 0)) == NULL) {
620 DPRINTF("ib_setup_for_devctl_cmd: devctl_ap_acquire "
621 "errno: %d\n", errno);
622 ib_cleanup_after_devctl_cmd(*devctl_hdl, *user_nvlistp);
623 return (CFGA_IB_DEVCTL_ERR);
626 /* Set up to pass dynamic ap_id down to driver */
627 if (nvlist_alloc(user_nvlistp, NV_UNIQUE_NAME_TYPE, 0) != 0) {
628 DPRINTF("ib_setup_for_devctl: nvlist_alloc errno: %d\n", errno);
629 *user_nvlistp = NULL; /* Prevent possible incorrect free in */
630 /* ib_cleanup_after_devctl_cmd */
631 ib_cleanup_after_devctl_cmd(*devctl_hdl, *user_nvlistp);
632 return (CFGA_IB_NVLIST_ERR);
635 /* create a "string" entry */
636 if (nvlist_add_string(*user_nvlistp, IB_APID, ap_id) == -1) {
637 DPRINTF("ib_setup_for_devctl_cmd: nvlist_add_string failed. "
638 "errno: %d\n", errno);
639 ib_cleanup_after_devctl_cmd(*devctl_hdl, *user_nvlistp);
640 return (CFGA_IB_NVLIST_ERR);
643 return (CFGA_IB_OK);
648 * Function:
649 * ib_device_configured
650 * Input:
651 * hdl - Handler to devctl
652 * nvl - Name-value-pair list pointer
653 * Output:
654 * rstate - Receptacle state for the apid
655 * Returns:
656 * CFGA_IB_OK if it succeeds or an appropriate error.
657 * Description:
658 * Checks if there is a device actually configured to the ap? If so,
659 * issues a "devctl" to get the Receptacle state for that ap_id.
660 * If the ap_id is already configured it returns CFGA_IB_OK.
661 * Otherwise it returns a failure.
663 static cfga_ib_ret_t
664 ib_device_configured(devctl_hdl_t hdl, nvlist_t *nvl, ap_rstate_t *rstate)
666 cfga_ib_ret_t rv;
667 devctl_ap_state_t devctl_ap_state;
669 /* get ap_id's "devctl_ap_state" first */
670 if (devctl_ap_getstate(hdl, nvl, &devctl_ap_state) == -1) {
671 DPRINTF("ib_device_configured failed, errno: %d\n", errno);
672 return (CFGA_IB_DEVCTL_ERR);
675 rv = CFGA_IB_ALREADY_CONFIGURED;
676 *rstate = devctl_ap_state.ap_rstate;
677 if (devctl_ap_state.ap_ostate != AP_OSTATE_CONFIGURED) {
678 return (CFGA_IB_NOT_CONFIGURED);
681 return (rv);
686 * Function:
687 * ib_device_connected
688 * Input:
689 * hdl - Handler to devctl
690 * nvl - Name-value-pair list pointer
691 * Output:
692 * ostate - Occupant state for the apid
693 * Returns:
694 * CFGA_IB_OK if it succeeds or an appropriate error.
695 * Description:
696 * Checks if there is a device actually connected to the ap? If so,
697 * issues a "devctl" to get the Occupant state for that ap_id.
698 * If the ap_id is already connected it returns CFGA_IB_OK.
699 * Otherwise it returns a failure.
701 static cfga_ib_ret_t
702 ib_device_connected(devctl_hdl_t hdl, nvlist_t *list, ap_ostate_t *ostate)
704 cfga_ib_ret_t rv = CFGA_IB_ALREADY_CONNECTED;
705 devctl_ap_state_t devctl_ap_state;
707 if (devctl_ap_getstate(hdl, list, &devctl_ap_state) == -1) {
708 DPRINTF("ib_device_connected failed, errno: %d\n", errno);
709 return (CFGA_IB_DEVCTL_ERR);
712 *ostate = devctl_ap_state.ap_ostate;
713 if (devctl_ap_state.ap_rstate != AP_RSTATE_CONNECTED) {
714 return (CFGA_IB_NOT_CONNECTED);
717 return (rv);
722 * Function:
723 * ib_do_control_ioctl
724 * Input:
725 * ap_id - The dynamic attachment point of an IB device
726 * sub_cmd1 - Sub Command 1 to DEVCTL_AP_CONTROL devctl
727 * sub_cmd2 - Sub Command 2 to DEVCTL_AP_CONTROL devctl
728 * (Mandatory except for IBNEX_NUM_HCA_NODES,
729 * IBNEX_NUM_DEVICE_NODES,
730 * IBNEX_UPDATE_PKEY_TBLS &
731 * IBNEX_UPDATE_IOC_CONF)
732 * misc_arg - optional arguments to DEVCTL_AP_CONTROL devctl
733 * Output:
734 * descrp - Buffer containing data back from kernel
735 * sizep - Length of the buffer back from kernel
736 * Returns:
737 * CFGA_IB_OK if it succeeds or an appropriate error.
738 * Description:
739 * Issues DEVCTL_AP_CONTROL devctl with sub_cmd1 first which actually
740 * queries the IBNEX module in the kernel on the size of the data to
741 * be returned.
743 * Next issues DEVCTL_AP_CONTROL devctl with a buffer of that much
744 * size and gets the actual data back.
745 * Passes the data and the size back to caller.
747 static cfga_ib_ret_t
748 ib_do_control_ioctl(char *ap_id, uint_t sub_cmd1, uint_t sub_cmd2,
749 uint_t misc_arg, void **descrp, size_t *sizep)
751 int fd = -1;
752 uint32_t local_size = 0;
753 cfga_ib_ret_t rv = CFGA_IB_OK;
754 struct ibnex_ioctl_data ioctl_data;
756 /* try to open the ONLY static ap_id */
757 if ((fd = open(IB_STATIC_APID, O_RDONLY)) == -1) {
758 DPRINTF("ib_do_control_ioctl: open failed: "
759 "errno = %d\n", errno);
760 /* Provides a more useful error msg */
761 rv = (errno == EBUSY) ? CFGA_IB_BUSY_ERR : CFGA_IB_OPEN_ERR;
762 return (rv);
766 * Find out first how large a buffer is needed?
767 * NOTE: Ioctls only accept/return a 32-bit int for a get_size
768 * to avoid 32/64 and BE/LE issues.
770 ioctl_data.cmd = sub_cmd1;
771 ioctl_data.misc_arg = (uint_t)misc_arg;
772 ioctl_data.buf = (caddr_t)&local_size;
773 ioctl_data.bufsiz = sizeof (local_size);
775 /* Pass "ap_id" up for all other commands */
776 if (sub_cmd1 != IBNEX_NUM_DEVICE_NODES &&
777 sub_cmd1 != IBNEX_NUM_HCA_NODES &&
778 sub_cmd1 != IBNEX_UPDATE_PKEY_TBLS) {
779 ioctl_data.ap_id = (caddr_t)ap_id;
780 ioctl_data.ap_id_len = strlen(ap_id);
782 } else {
783 ioctl_data.ap_id = NULL;
784 ioctl_data.ap_id_len = 0;
787 if (ioctl(fd, DEVCTL_AP_CONTROL, &ioctl_data) != 0) {
788 DPRINTF("ib_do_control_ioctl: size ioctl ERR, errno: %d\n",
789 errno);
790 (void) close(fd);
791 rv = (errno == EBUSY) ? CFGA_IB_BUSY_ERR : CFGA_IB_IOCTL_ERR;
792 return (rv);
794 *sizep = local_size;
797 * Don't do the second ioctl only in these cases
798 * (NOTE: the data is returned in the first ioctl itself; if any)
800 if (sub_cmd1 == IBNEX_NUM_DEVICE_NODES ||
801 sub_cmd1 == IBNEX_NUM_HCA_NODES ||
802 sub_cmd1 == IBNEX_UPDATE_PKEY_TBLS ||
803 sub_cmd1 == IBNEX_UPDATE_IOC_CONF) {
804 (void) close(fd);
805 return (rv);
808 if (local_size == 0 || (*descrp = malloc(*sizep)) == NULL) {
809 DPRINTF("ib_do_control_ioctl: malloc failed\n");
810 (void) close(fd);
811 return (CFGA_IB_ALLOC_FAIL);
814 /* Get the data */
815 ioctl_data.cmd = sub_cmd2;
816 ioctl_data.buf = (caddr_t)*descrp;
817 ioctl_data.bufsiz = *sizep;
819 if (ioctl(fd, DEVCTL_AP_CONTROL, &ioctl_data) != 0) {
820 DPRINTF("ib_do_control_ioctl: ioctl failed: errno:%d\n", errno);
821 if (*descrp != NULL) {
822 free(*descrp);
823 *descrp = NULL;
825 rv = (errno == EBUSY) ? CFGA_IB_BUSY_ERR : CFGA_IB_IOCTL_ERR;
828 (void) close(fd);
829 return (rv);
833 /* ========================================================================== */
834 /* Entry points */
837 * Function:
838 * cfga_change_state
839 * Input:
840 * state_change_cmd - Argument to the cfgadm -c command
841 * ap_id - The attachment point of an IB fabric
842 * options - State Change command options passed by the cfgadm(8)
843 * confp - Whether this command requires confirmation?
844 * msgp - cfgadm error message for this plugin
845 * errstring - This contains error msg if command fails
846 * flags - Cfgadm(1m) flags
847 * Output:
848 * NONE
849 * Returns:
850 * If the command succeeded perform the cfgadm -c <cmd>;
851 * otherwise emit an error
852 * Description:
853 * Do cfgadm -c <cmd>
855 /*ARGSUSED*/
856 cfga_err_t
857 cfga_change_state(cfga_cmd_t state_change_cmd, const char *ap_id,
858 const char *options, struct cfga_confirm *confp, struct cfga_msg *msgp,
859 char **errstring, cfga_flags_t flags)
861 int ret;
862 char *devpath;
863 nvlist_t *nvl = NULL;
864 boolean_t static_ap_id = B_TRUE;
865 ap_rstate_t rstate;
866 ap_ostate_t ostate;
867 devctl_hdl_t hdl = NULL;
868 cfga_ib_ret_t rv = CFGA_IB_OK;
870 if ((rv = ib_verify_params(ap_id, options, errstring)) != CFGA_IB_OK) {
871 (void) cfga_help(msgp, options, flags);
872 return (ib_err_msg(errstring, CFGA_IB_INVAL_APID_ERR,
873 ap_id, errno));
877 * All subcommands which can change state of device require
878 * root privileges.
880 if (geteuid() != 0) {
881 return (ib_err_msg(errstring, CFGA_IB_PRIV_ERR, ap_id, errno));
884 if (strstr((char *)ap_id, IB_FABRIC_APID_STR) == NULL)
885 static_ap_id = B_FALSE;
887 if ((rv = ib_setup_for_devctl_cmd((char *)ap_id, static_ap_id,
888 &hdl, &nvl)) != CFGA_IB_OK) {
889 ib_cleanup_after_devctl_cmd(hdl, nvl);
890 return (ib_err_msg(errstring, rv, ap_id, errno));
893 switch (state_change_cmd) {
894 case CFGA_CMD_CONFIGURE:
895 rv = ib_device_connected(hdl, nvl, &ostate);
896 if (rv != CFGA_IB_ALREADY_CONNECTED) {
897 ret = (rv != CFGA_IB_NOT_CONNECTED) ?
898 CFGA_IB_CONFIG_OP_ERR : rv;
899 ib_cleanup_after_devctl_cmd(hdl, nvl);
900 return (ib_err_msg(errstring, ret, ap_id, errno));
903 if (rv == CFGA_IB_ALREADY_CONNECTED) {
905 * special case handling for
906 * SLM based cfgadm disconnects
908 if (ostate == AP_OSTATE_CONFIGURED) {
909 ib_cleanup_after_devctl_cmd(hdl, nvl);
910 return (ib_err_msg(errstring,
911 CFGA_IB_ALREADY_CONFIGURED, ap_id,
912 errno));
917 rv = CFGA_IB_OK; /* Other status don't matter */
919 if (devctl_ap_configure(hdl, nvl) != 0) {
920 DPRINTF("cfga_change_state: devctl_ap_configure "
921 "failed. errno: %d\n", errno);
922 rv = CFGA_IB_CONFIG_OP_ERR;
923 break;
926 devpath = ib_get_devicepath(ap_id);
927 if (devpath == NULL) {
928 int i;
931 * try for some time as IB hotplug thread
932 * takes a while to create the path
933 * and then eventually give up
935 for (i = 0;
936 i < IB_RETRY_DEVPATH && (devpath == NULL); i++) {
937 sleep(IB_MAX_DEVPATH_DELAY);
938 devpath = ib_get_devicepath(ap_id);
941 if (devpath == NULL) {
942 DPRINTF("cfga_change_state: get device "
943 "path failed i = %d\n", i);
944 rv = CFGA_IB_CONFIG_OP_ERR;
945 break;
948 S_FREE(devpath);
949 break;
951 case CFGA_CMD_UNCONFIGURE:
952 if ((rv = ib_device_connected(hdl, nvl, &ostate)) !=
953 CFGA_IB_ALREADY_CONNECTED) {
954 ib_cleanup_after_devctl_cmd(hdl, nvl);
955 if (rv == CFGA_IB_DEVCTL_ERR)
956 rv = CFGA_IB_INVALID_OP_ERR;
957 return (ib_err_msg(errstring, rv, ap_id, errno));
960 /* check if it is already unconfigured */
961 if ((rv = ib_device_configured(hdl, nvl, &rstate)) ==
962 CFGA_IB_NOT_CONFIGURED) {
963 ib_cleanup_after_devctl_cmd(hdl, nvl);
964 return (ib_err_msg(errstring, rv, ap_id, errno));
967 rv = CFGA_IB_OK; /* Other statuses don't matter */
969 if (!ib_confirm(confp, IB_CONFIRM1)) {
970 ib_cleanup_after_devctl_cmd(hdl, nvl);
971 return (CFGA_NACK);
974 devpath = ib_get_devicepath(ap_id);
975 if (devpath == NULL) {
976 DPRINTF("cfga_change_state: get device path failed\n");
977 rv = CFGA_IB_UNCONFIG_OP_ERR;
978 break;
981 if ((rv = ib_rcm_offline(ap_id, errstring, devpath, flags)) !=
982 CFGA_IB_OK) {
983 S_FREE(devpath);
984 break;
987 ret = devctl_ap_unconfigure(hdl, nvl);
988 if (ret != 0) {
989 DPRINTF("cfga_change_state: devctl_ap_unconfigure "
990 "failed with errno: %d\n", errno);
991 rv = CFGA_IB_UNCONFIG_OP_ERR;
992 if (errno == EBUSY) {
993 rv = CFGA_IB_BUSY_ERR;
995 (void) ib_rcm_online(ap_id, errstring, devpath, flags);
997 } else {
998 (void) ib_rcm_remove(ap_id, errstring, devpath, flags);
1001 S_FREE(devpath);
1002 break;
1004 case CFGA_CMD_LOAD:
1005 case CFGA_CMD_UNLOAD:
1006 case CFGA_CMD_CONNECT:
1007 case CFGA_CMD_DISCONNECT:
1008 (void) cfga_help(msgp, options, flags);
1009 rv = CFGA_IB_OPNOTSUPP;
1010 break;
1012 case CFGA_CMD_NONE:
1013 default:
1014 (void) cfga_help(msgp, options, flags);
1015 rv = CFGA_IB_INTERNAL_ERR;
1018 ib_cleanup_after_devctl_cmd(hdl, nvl);
1019 return (ib_err_msg(errstring, rv, ap_id, errno));
1024 * Function:
1025 * cfga_private_func
1026 * Input:
1027 * func - The private function (passed w/ -x option)
1028 * ap_id - The attachment point of an IB fabric
1029 * options - Private function command options passed
1030 * by the cfgadm(8)
1031 * confp - Whether this command requires confirmation?
1032 * msgp - cfgadm error message for this plugin
1033 * errstring - This contains error msg if command fails
1034 * flags - Cfgadm(1m) flags
1035 * Output:
1036 * NONE
1037 * Returns:
1038 * If the command succeeded perform the 'cfgadm -x <func>'; otherwise
1039 * return failure.
1040 * Description:
1041 * Do cfgadm -x <func>
1043 /*ARGSUSED*/
1044 cfga_err_t
1045 cfga_private_func(const char *func, const char *ap_id, const char *options,
1046 struct cfga_confirm *confp, struct cfga_msg *msgp, char **errstring,
1047 cfga_flags_t flags)
1049 int len, ret, count = 0;
1050 char *clnt_name = NULL, *alt_hca = NULL;
1051 char *clnt_apid = NULL, *clnt_devpath = NULL;
1052 char *name, *msg = NULL;
1053 char *fab_apid = strstr((char *)ap_id, IBNEX_FABRIC);
1054 size_t info_len = 0;
1055 uchar_t *info = NULL;
1056 nvlist_t *nvl;
1057 nvpair_t *nvp = NULL;
1058 ap_rstate_t rstate;
1059 devctl_hdl_t hdl = NULL;
1060 cfga_ib_ret_t rv;
1062 if ((rv = ib_verify_params(ap_id, NULL, errstring)) != CFGA_IB_OK) {
1063 DPRINTF("cfga_private_func: ib_verify_params "
1064 "failed with rv: %d\n", rv);
1065 return (ib_err_msg(errstring, rv, ap_id, errno));
1068 if (func == NULL) {
1069 DPRINTF("cfga_private_func: func is NULL\n");
1070 return (ib_err_msg(errstring, CFGA_IB_INVAL_ARG_ERR, ap_id,
1071 errno));
1075 * check first if IB static ap_id is "configured" for use
1077 if (fab_apid != NULL) {
1078 if ((rv = ib_setup_for_devctl_cmd(fab_apid, B_TRUE, &hdl,
1079 &nvl)) != CFGA_IB_OK) {
1080 ib_cleanup_after_devctl_cmd(hdl, nvl);
1081 return (ib_err_msg(errstring, rv, ap_id, errno));
1083 if ((rv = ib_device_configured(hdl, nvl, &rstate)) ==
1084 CFGA_IB_NOT_CONFIGURED) {
1085 return (ib_err_msg(errstring, rv, ap_id, errno));
1087 ib_cleanup_after_devctl_cmd(hdl, nvl);
1090 rv = CFGA_IB_OK;
1091 DPRINTF("cfga_private_func: func is %s\n", func);
1092 if (strcmp(func, IB_LIST_HCA_CLIENTS) == 0) { /* -x list_clients */
1094 /* only supported on HCA ap_ids */
1095 if (fab_apid != NULL) {
1096 DPRINTF("cfga_private_func: fabric apid supplied\n");
1097 return (ib_err_msg(errstring, CFGA_IB_INVALID_OP_ERR,
1098 ap_id, errno));
1101 if ((msg = (char *)calloc(256, 1)) == NULL) {
1102 DPRINTF("cfga_private_func: malloc for msg failed. "
1103 "errno: %d\n", errno);
1104 return (ib_err_msg(errstring, CFGA_IB_ALLOC_FAIL,
1105 ap_id, errno));
1108 if ((rv = ib_do_control_ioctl((char *)ap_id, IBNEX_HCA_LIST_SZ,
1109 IBNEX_HCA_LIST_INFO, 0, (void **)&info, &info_len)) != 0) {
1110 DPRINTF("cfga_private_func: "
1111 "ib_do_control_ioctl list failed :%d\n", rv);
1112 S_FREE(msg);
1113 return (ib_err_msg(errstring, CFGA_IB_HCA_LIST_ERR,
1114 ap_id, errno));
1117 if (nvlist_unpack((char *)info, info_len, &nvl, 0)) {
1118 DPRINTF("cfga_private_func: "
1119 "nvlist_unpack 2 failed %p\n", info);
1120 S_FREE(info);
1121 S_FREE(msg);
1122 return (ib_err_msg(errstring, CFGA_IB_NVLIST_ERR, ap_id,
1123 errno));
1126 (void) snprintf(msg, 256, "Ap_Id\t\t\t IB Client\t\t "
1127 "Alternate HCA\n");
1128 cfga_msg(msgp, msg);
1130 /* Walk the NVPAIR data */
1131 while (nvp = nvlist_next_nvpair(nvl, nvp)) {
1132 name = nvpair_name(nvp);
1133 if (strcmp(name, "Client") == 0) {
1134 (void) nvpair_value_string(nvp, &clnt_name);
1135 ++count;
1136 } else if (strcmp(name, "Alt_HCA") == 0) {
1137 (void) nvpair_value_string(nvp, &alt_hca);
1138 ++count;
1139 } else if (strcmp(name, "ApID") == 0) {
1140 (void) nvpair_value_string(nvp, &clnt_apid);
1141 ++count;
1144 /* check at the end; print message per client found */
1145 if (count == 3) {
1146 count = 0;
1147 (void) snprintf(msg, 256, "%-30s %-25s %s\n",
1148 clnt_apid, clnt_name, alt_hca);
1149 cfga_msg(msgp, msg);
1151 } /* end of while */
1153 S_FREE(info);
1154 S_FREE(msg);
1155 nvlist_free(nvl);
1157 /* -x unconfig_clients */
1158 } else if (strcmp(func, IB_UNCONFIG_HCA_CLIENTS) == 0) {
1160 * -x unconfig_clients changes state by calling into RCM.
1161 * It needs root privileges.
1163 if (geteuid() != 0) {
1164 return (ib_err_msg(errstring, CFGA_IB_PRIV_ERR, ap_id,
1165 errno));
1168 /* only supported on HCA ap_ids */
1169 if (fab_apid != NULL) {
1170 DPRINTF("cfga_private_func: fabric apid supplied\n");
1171 return (ib_err_msg(errstring, CFGA_IB_INVALID_OP_ERR,
1172 ap_id, errno));
1176 * Check w/ user if it is ok to do this operation
1177 * If the user fails to confirm, bailout
1179 if (!ib_confirm(confp, IB_CONFIRM3))
1180 return (CFGA_NACK);
1182 /* Get device-paths of all the IOC/Port/Pseudo devices */
1183 rv = ib_do_control_ioctl((char *)ap_id, IBNEX_UNCFG_CLNTS_SZ,
1184 IBNEX_UNCFG_CLNTS_INFO, 0, (void **)&info, &info_len);
1185 if (rv != 0) {
1186 DPRINTF("cfga_private_func: ib_do_control_ioctl "
1187 "failed :%d\n", rv);
1188 return (ib_err_msg(errstring, CFGA_IB_HCA_UNCONFIG_ERR,
1189 ap_id, errno));
1192 if (nvlist_unpack((char *)info, info_len, &nvl, 0)) {
1193 DPRINTF("cfga_private_func: nvlist_unpack failed %p\n",
1194 info);
1195 S_FREE(info);
1196 return (ib_err_msg(errstring, CFGA_IB_NVLIST_ERR, ap_id,
1197 errno));
1200 ret = 0;
1202 /* Call RCM Offline on all device paths */
1203 while (nvp = nvlist_next_nvpair(nvl, nvp)) {
1204 name = nvpair_name(nvp);
1205 if (strcmp(name, "devpath") == 0) {
1206 (void) nvpair_value_string(nvp, &clnt_devpath);
1207 ++count;
1208 } else if (strcmp(name, "ApID") == 0) {
1209 (void) nvpair_value_string(nvp, &clnt_apid);
1210 ++count;
1213 /* handle the client unconfigure now */
1214 if (count == 2) {
1215 count = 0; /* reset count */
1217 DPRINTF("cfga_private_func: client apid = %s, "
1218 "DevPath = %s\n", clnt_apid, clnt_devpath);
1219 if ((rv = ib_setup_for_devctl_cmd(clnt_apid,
1220 B_TRUE, &hdl, &nvl)) != CFGA_IB_OK) {
1221 ib_cleanup_after_devctl_cmd(hdl, nvl);
1222 return (ib_err_msg(errstring, rv,
1223 clnt_apid, errno));
1226 if ((rv = ib_device_configured(hdl, nvl,
1227 &rstate)) == CFGA_IB_NOT_CONFIGURED)
1228 continue;
1230 if ((rv = ib_rcm_offline(clnt_apid, errstring,
1231 clnt_devpath, flags)) != CFGA_IB_OK) {
1232 DPRINTF("cfga_private_func: client rcm "
1233 "offline failed for %s, with %d\n",
1234 clnt_devpath, rv);
1235 ret = rv;
1236 continue;
1239 if (devctl_ap_unconfigure(hdl, nvl) != 0) {
1240 DPRINTF("cfga_private_func: client "
1241 "unconfigure failed: errno %d\n",
1242 errno);
1243 ret = CFGA_IB_UNCONFIG_OP_ERR;
1244 if (errno == EBUSY)
1245 ret = CFGA_IB_BUSY_ERR;
1246 (void) ib_rcm_online(clnt_apid,
1247 errstring, clnt_devpath, flags);
1248 continue;
1249 } else {
1250 (void) ib_rcm_remove(clnt_apid,
1251 errstring, clnt_devpath, flags);
1253 ib_cleanup_after_devctl_cmd(hdl, nvl);
1255 } /* end of if count == 2 */
1257 } /* end of while */
1259 S_FREE(info);
1260 nvlist_free(nvl);
1261 if (ret) {
1262 DPRINTF("cfga_private_func: unconfig_clients of %s "
1263 "failed with %d\n", ap_id, ret);
1264 return (ib_err_msg(errstring, CFGA_IB_UCFG_CLNTS_ERR,
1265 ap_id, errno));
1268 /* -x update_pkey_tbls */
1269 } else if (strcmp(func, IB_UPDATE_PKEY_TBLS) == 0) {
1271 * Check for root privileges.
1273 if (geteuid() != 0) {
1274 return (ib_err_msg(errstring, CFGA_IB_PRIV_ERR, ap_id,
1275 errno));
1278 /* CHECK: Only supported on fabric ap_ids */
1279 if (fab_apid == NULL || strcmp(fab_apid, IBNEX_FABRIC) != 0) {
1280 DPRINTF("cfga_private_func: fabric apid needed\n");
1281 return (ib_err_msg(errstring, CFGA_IB_INVALID_OP_ERR,
1282 ap_id, errno));
1285 /* Check w/ user if it is ok to do this operation */
1286 len = strlen(IB_CONFIRM4) + 10;
1287 if ((msg = (char *)calloc(len, 1)) != NULL) {
1288 (void) snprintf(msg, len, "%s\nContinue", IB_CONFIRM4);
1291 /* If the user fails to confirm, return */
1292 if (!ib_confirm(confp, msg)) {
1293 free(msg);
1294 return (CFGA_NACK);
1296 free(msg);
1298 /* Update P_Key tables for all ports of all HCAs */
1299 rv = ib_do_control_ioctl((char *)ap_id, IBNEX_UPDATE_PKEY_TBLS,
1300 0, 0, 0, &info_len);
1302 if (rv != 0) {
1303 DPRINTF("cfga_private_func: ib_do_control_ioctl "
1304 "failed :%d\n", rv);
1305 return (ib_err_msg(errstring, CFGA_IB_UPD_PKEY_TBLS_ERR,
1306 ap_id, errno));
1309 /* -x [add_service|delete_service] */
1310 } else if ((strncmp(func, IB_ADD_SERVICE, 12) == 0) ||
1311 (strncmp(func, IB_DELETE_SERVICE, 15) == 0)) {
1312 char *subopts, *val;
1313 uint8_t cmd;
1315 /* check: Only supported on fabric ap_ids */
1316 if (fab_apid == NULL || strcmp(fab_apid, IBNEX_FABRIC) != 0) {
1317 DPRINTF("cfga_private_func: fabric apid needed\n");
1318 return (ib_err_msg(errstring, CFGA_IB_INVALID_OP_ERR,
1319 ap_id, errno));
1322 /* Check for root privileges. */
1323 if (geteuid() != 0) {
1324 return (ib_err_msg(errstring, CFGA_IB_PRIV_ERR, ap_id,
1325 errno));
1328 /* return error if no options are specified */
1329 subopts = (char *)options;
1330 if (subopts == NULL) {
1331 DPRINTF("cfga_private_func: no sub-options\n");
1332 (void) cfga_help(msgp, options, flags);
1333 return (ib_err_msg(errstring, CFGA_IB_INVAL_ARG_ERR,
1334 ap_id, errno));
1337 /* parse options specified */
1338 while (*subopts != '\0') {
1339 switch (getsubopt(&subopts, ib_service_subopts, &val)) {
1340 case 0: /* comm */
1341 if (val == NULL) {
1342 (void) cfga_help(msgp, options, flags);
1343 S_FREE(service_name);
1344 return (ib_err_msg(errstring,
1345 CFGA_IB_INVAL_ARG_ERR,
1346 ap_id, errno));
1347 } else {
1348 comm_name = strdup(val);
1349 if (comm_name == NULL) {
1350 DPRINTF("comm sub-opt invalid "
1351 "arg\n");
1352 S_FREE(service_name);
1353 return (ib_err_msg(errstring,
1354 CFGA_IB_COMM_INVAL_ERR,
1355 ap_id, errno));
1358 break;
1360 case 1: /* service */
1361 if (val == NULL) {
1362 (void) cfga_help(msgp, options, flags);
1363 S_FREE(comm_name);
1364 return (ib_err_msg(errstring,
1365 CFGA_IB_INVAL_ARG_ERR,
1366 ap_id, errno));
1367 } else {
1368 /* service can be upto 4 long */
1369 if (strlen(val) == 0 ||
1370 strlen(val) > 4) {
1371 DPRINTF("comm sub-opt invalid "
1372 "service passed\n");
1373 S_FREE(comm_name);
1374 return (ib_err_msg(errstring,
1375 CFGA_IB_SVC_LEN_ERR,
1376 ap_id, errno));
1378 service_name = strdup(val);
1379 if (service_name == NULL) {
1380 DPRINTF("comm sub-opt "
1381 "internal error\n");
1382 S_FREE(comm_name);
1383 return (ib_err_msg(errstring,
1384 CFGA_IB_SVC_INVAL_ERR,
1385 ap_id, errno));
1388 break;
1390 default:
1391 (void) cfga_help(msgp, options, flags);
1392 S_FREE(comm_name);
1393 S_FREE(service_name);
1394 return (ib_err_msg(errstring,
1395 CFGA_IB_INVAL_ARG_ERR, ap_id, errno));
1399 /* figure out the "operation" */
1400 if (strncasecmp(func, IB_ADD_SERVICE, 11) == 0)
1401 cmd = IBCONF_ADD_ENTRY;
1402 else if (strncasecmp(func, IB_DELETE_SERVICE, 14) == 0)
1403 cmd = IBCONF_DELETE_ENTRY;
1404 DPRINTF("Service = %s, Comm = %s, Operation = %s\n",
1405 service_name, comm_name, func);
1407 if (strncasecmp(comm_name, IBNEX_PORT_STR, 4) == 0)
1408 service_type = IB_PORT_SERVICE;
1409 else if (strncasecmp(comm_name, IBNEX_VPPA_STR, 4) == 0)
1410 service_type = IB_VPPA_SERVICE;
1411 else if (strncasecmp(comm_name, IBNEX_HCASVC_STR, 4) == 0)
1412 service_type = IB_HCASVC_SERVICE;
1413 else {
1414 (void) cfga_help(msgp, options, flags);
1415 S_FREE(comm_name);
1416 S_FREE(service_name);
1417 return (ib_err_msg(errstring, CFGA_IB_INVAL_ARG_ERR,
1418 ap_id, errno));
1421 /* do the add/delete entry to the service */
1422 if (cmd == IBCONF_ADD_ENTRY) {
1423 if ((rv = ib_add_service(errstring)) != CFGA_IB_OK)
1424 DPRINTF("cfga_private_func: add failed\n");
1425 } else if (cmd == IBCONF_DELETE_ENTRY) {
1426 if ((rv = ib_delete_service(errstring)) != CFGA_IB_OK)
1427 DPRINTF("cfga_private_func: delete failed\n");
1430 S_FREE(comm_name);
1431 S_FREE(service_name);
1432 return (ib_err_msg(errstring, rv, ap_id, errno));
1434 } else if (strncmp(func, IB_LIST_SERVICES, 13) == 0) {
1436 /* check: Only supported on fabric ap_ids */
1437 if (fab_apid == NULL || strcmp(fab_apid, IBNEX_FABRIC) != 0) {
1438 DPRINTF("cfga_private_func: fabric apid needed\n");
1439 return (ib_err_msg(errstring, CFGA_IB_INVALID_OP_ERR,
1440 ap_id, errno));
1443 /* do the list services */
1444 rv = ib_list_services(msgp, errstring);
1445 if (rv != CFGA_IB_OK) {
1446 DPRINTF("cfga_private_func: ib_list_services failed\n");
1447 return (ib_err_msg(errstring, rv, ap_id, errno));
1450 /* -x update_ioc_conf */
1451 } else if (strncmp(func, IB_UPDATE_IOC_CONF, 17) == 0) {
1452 uint_t misc_arg;
1454 /* Supported only with root privilege */
1455 if (geteuid() != 0) {
1456 return (ib_err_msg(errstring, CFGA_IB_PRIV_ERR, ap_id,
1457 errno));
1461 * check: Only supported on fabric ap_id or IOC APID
1462 * IOC APID does not have any commas in it.
1464 if (fab_apid == NULL ||
1465 (fab_apid != NULL && strstr(fab_apid, ",") != NULL)) {
1466 DPRINTF("cfga_private_func: fabric/IOC apid needed\n");
1467 return (ib_err_msg(errstring, CFGA_IB_INVALID_OP_ERR,
1468 ap_id, errno));
1471 /* Check w/ user if it is ok to do this operation */
1472 len = strlen(IB_CONFIRM5) + 10;
1473 if ((msg = (char *)calloc(len, 1)) != NULL) {
1474 (void) snprintf(msg, len, "%s\nContinue", IB_CONFIRM5);
1477 /* If the user fails to confirm, return */
1478 if (!ib_confirm(confp, msg)) {
1479 free(msg);
1480 return (CFGA_NACK);
1482 free(msg);
1484 misc_arg = (strcmp(fab_apid, IBNEX_FABRIC) == 0) ?
1485 IBNEX_BASE_APID : IBNEX_DYN_APID;
1487 /* Reprobe and update IOC(s) configuration */
1488 rv = ib_do_control_ioctl((char *)ap_id, IBNEX_UPDATE_IOC_CONF,
1489 0, misc_arg, 0, &info_len);
1491 if (rv != 0) {
1492 DPRINTF("cfga_private_func: ib_do_control_ioctl "
1493 "failed :%d\n", rv);
1494 return (ib_err_msg(errstring, CFGA_IB_DEVCTL_ERR,
1495 ap_id, errno));
1497 } else {
1498 DPRINTF("cfga_private_func: unrecognized command.\n");
1499 (void) cfga_help(msgp, options, flags);
1500 errno = EINVAL;
1501 return (CFGA_INVAL);
1504 return (ib_err_msg(errstring, rv, ap_id, errno));
1509 * Function:
1510 * cfga_test
1511 * Input:
1512 * ap_id - The attachment point of an IB fabric
1513 * options - Test command options passed by the cfgadm(8)
1514 * msgp - cfgadm error message for this plugin
1515 * errstring - This contains error msg if command fails
1516 * flags - Cfgadm(1m) flags
1517 * Output:
1518 * NONE
1519 * Returns:
1520 * CFGA_OPNOTSUPP
1521 * Description:
1522 * Do "cfgadm -t"
1524 /*ARGSUSED*/
1525 cfga_err_t
1526 cfga_test(const char *ap_id, const char *options, struct cfga_msg *msgp,
1527 char **errstring, cfga_flags_t flags)
1529 (void) cfga_help(msgp, options, flags);
1530 return (CFGA_OPNOTSUPP);
1535 * Function:
1536 * ib_fill_static_apids
1537 * Input:
1538 * ap_id - The static attachment point of an IB device
1539 * clp - The returned "list" information array
1540 * Output:
1541 * NONE
1542 * Returns:
1543 * Fills up the "list" information array for the static attachment point
1544 * Description:
1545 * IB fabric supports two types of static attachment points.
1546 * One is fabric and other is for the HCAs. This fills up
1547 * "cfga_list_data_t" for static attachment points.
1549 static cfga_ib_ret_t
1550 ib_fill_static_apids(char *ap_id, cfga_list_data_t *clp)
1552 int rv, l_err;
1553 char *ap_id_log = NULL;
1555 /* Get /dev/cfg path to corresponding to the physical ap_id */
1556 /* Remember ap_id_log must be freed */
1557 if (ib_physpath_to_devlink(ap_id, &ap_id_log,
1558 &l_err) != ICFGA_OK) {
1559 DPRINTF("ib_fill_static_apids: "
1560 "ib_physpath_to_devlink failed\n");
1561 return (CFGA_IB_DEVLINK_ERR);
1563 assert(ap_id_log != NULL);
1565 /* Get logical ap-id corresponding to the physical */
1566 if (strstr(ap_id_log, CFGA_DEV_DIR) == NULL) {
1567 DPRINTF("ib_fill_static_apids: devlink doesn't contain "
1568 "/dev/cfg\n");
1569 free(ap_id_log);
1570 return (CFGA_IB_DEVLINK_ERR);
1573 clp->ap_cond = CFGA_COND_OK;
1574 clp->ap_r_state = CFGA_STAT_CONNECTED;
1575 clp->ap_o_state = CFGA_STAT_CONFIGURED;
1576 clp->ap_class[0] = '\0'; /* Filled by libcfgadm */
1577 clp->ap_busy = 0;
1578 clp->ap_status_time = (time_t)-1;
1579 (void) snprintf(clp->ap_log_id, sizeof (clp->ap_log_id), "%s",
1580 /* Strip off /dev/cfg/ */ ap_id_log + strlen(CFGA_DEV_DIR) + 1);
1581 (void) strlcpy(clp->ap_phys_id, ap_id, sizeof (clp->ap_phys_id));
1583 /* Static IB apid */
1584 if (strstr((char *)ap_id, IB_FABRIC_APID_STR) != NULL) {
1585 (void) strlcpy(clp->ap_type, IB_FABRIC_TYPE,
1586 sizeof (clp->ap_type)); /* Fill in type */
1587 (void) strlcpy(clp->ap_info, IB_FABRIC_INFO,
1588 sizeof (clp->ap_info));
1590 } else { /* Static HCA apid */
1591 size_t size = 0;
1592 uchar_t *data = NULL;
1594 (void) strlcpy(clp->ap_type, IB_HCA_TYPE,
1595 sizeof (clp->ap_type)); /* Fill in type */
1597 rv = ib_do_control_ioctl(ap_id, IBNEX_HCA_VERBOSE_SZ,
1598 IBNEX_HCA_VERBOSE_INFO, 0, (void **)&data, &size);
1599 if (rv != 0) {
1600 DPRINTF("ib_fill_static_apids: ib_do_control_ioctl "
1601 "failed :%d\n", rv);
1602 free(ap_id_log);
1603 S_FREE(data);
1604 return (CFGA_IB_IOCTL_ERR);
1607 (void) strlcpy(clp->ap_info, (char *)data,
1608 sizeof (clp->ap_info));
1609 S_FREE(data);
1611 free(ap_id_log);
1612 return (CFGA_IB_OK);
1617 * Function:
1618 * cfga_list_ext
1619 * Input:
1620 * ap_id - The attachment point of an IB fabric
1621 * ap_id_list - The returned "list" information array
1622 * nlistp - Number of elements in the "list" information array
1623 * options - List command options passed by the cfgadm(8)
1624 * listopts - "-s" specific options
1625 * errstring - This contains error msg if command fails
1626 * flags - Cfgadm(1m) flags
1627 * Output:
1628 * NONE
1629 * Returns:
1630 * If the command succeeded, cfgadm -l output otherwise an error
1631 * Description:
1632 * Do cfgadm -l
1634 /*ARGSUSED*/
1635 cfga_err_t
1636 cfga_list_ext(const char *ap_id, cfga_list_data_t **ap_id_list, int *nlistp,
1637 const char *options, const char *listopts, char **errstring,
1638 cfga_flags_t flags)
1640 int expand = 0;
1641 int i, index, count;
1642 int show_dynamic = 0;
1643 size_t num_devices = 0;
1644 size_t num_hcas = 0;
1645 size_t snap_size = 0;
1646 uchar_t *snap_data = NULL;
1647 nvpair_t *nvp = NULL; /* for lint purposes */
1648 nvlist_t *nvl = NULL;
1649 boolean_t apid_matched = B_FALSE; /* for valid ap_id */
1650 cfga_ib_ret_t rv = CFGA_IB_OK;
1651 cfga_list_data_t *clp = NULL;
1653 if ((rv = ib_verify_params(ap_id, options, errstring)) != CFGA_IB_OK) {
1654 return (ib_err_msg(errstring, rv, ap_id, errno));
1657 /* make sure we have a valid ap_id_list */
1658 if (ap_id_list == NULL || nlistp == NULL) {
1659 DPRINTF("cfga_list_ext: list = NULL or nlistp = NULL\n");
1660 return (ib_err_msg(errstring, CFGA_IB_INVAL_ARG_ERR,
1661 ap_id, errno));
1664 DPRINTF("cfga_list_ext: ap_id = %s\n", ap_id);
1666 if ((flags & CFGA_FLAG_LIST_ALL) == CFGA_FLAG_LIST_ALL) {
1667 expand = 1; /* -a flag passed */
1670 if (GET_DYN(ap_id) != NULL) {
1671 show_dynamic = 1;
1674 if ((expand == 1) && /* -a option passed */
1675 (strstr((char *)ap_id, IB_FABRIC_APID_STR) != NULL)) {
1677 * Figure out how many IOC/Port/Pseudo
1678 * devices exist in the system?
1680 if ((rv = ib_do_control_ioctl((char *)ap_id,
1681 IBNEX_NUM_DEVICE_NODES, 0, 0, 0, &num_devices)) !=
1682 CFGA_IB_OK) {
1683 DPRINTF("cfga_list_ext: ib_do_control_ioctl "
1684 "IBNEX_NUM_DEVICE_NODES failed :%d\n", rv);
1685 if (errno == ENOENT)
1686 return (CFGA_APID_NOEXIST);
1687 return (ib_err_msg(errstring, rv, ap_id, errno));
1690 DPRINTF("cfga_list_ext: num_devices = %d\n", num_devices);
1693 /* Figure out how many HCA nodes exist in the system. */
1694 if ((rv = ib_do_control_ioctl((char *)ap_id, IBNEX_NUM_HCA_NODES, 0, 0,
1695 0, &num_hcas)) != CFGA_IB_OK) {
1696 DPRINTF("cfga_list_ext: ib_do_control_ioctl "
1697 "IBNEX_NUM_HCA_NODES failed :%d\n", rv);
1698 if (errno == ENOENT)
1699 return (CFGA_APID_NOEXIST);
1700 return (ib_err_msg(errstring, rv, ap_id, errno));
1702 DPRINTF("cfga_list_ext: num_hcas = %d\n", num_hcas);
1705 * No HCAs or IOC/VPPA/Port/HCA_SVC/Pseudo devices seen (non-IB system)
1707 if (!(num_hcas || num_devices)) {
1708 DPRINTF("cfga_list_ext: no IB devices found\n");
1709 return (CFGA_APID_NOEXIST);
1713 * *nlistp contains to how many APIDs to show w/ cfgadm -l.
1714 * If ap_id is "fabric" then
1715 * *nlistp is all Dynamic Apids + One more for "fabric"
1716 * If ap_id is "HCA" ap_id then
1717 * *nlistp is 1
1718 * Note that each HCA is a static APID, so nlistp will be 1 always
1719 * and this function will be called N times for each of the N HCAs
1720 * in the host.
1722 if (strstr((char *)ap_id, IB_FABRIC_APID_STR) != NULL) {
1723 *nlistp = num_devices + 1;
1725 } else {
1726 /* Assume it as a HCA ap_id */
1727 *nlistp = 1;
1730 /* Allocate storage for passing "list" info back */
1731 if ((*ap_id_list = (cfga_list_data_t *)calloc(*nlistp,
1732 sizeof (cfga_list_data_t))) == NULL) {
1733 DPRINTF("cfga_list_ext: malloc for cfga_list_data_t failed. "
1734 "errno: %d\n", errno);
1735 return (ib_err_msg(errstring, CFGA_IB_ALLOC_FAIL,
1736 ap_id, errno));
1740 * Only static ap_id is ib_fabric:
1741 * If -a options isn't specified then only show the static ap_id.
1743 if (!show_dynamic) {
1744 clp = &(*ap_id_list[0]);
1746 if ((rv = ib_fill_static_apids((char *)ap_id, clp)) !=
1747 CFGA_IB_OK) {
1748 S_FREE(*ap_id_list);
1749 return (ib_err_msg(errstring, rv, ap_id, errno));
1751 apid_matched = B_TRUE;
1755 * No -a specified
1756 * No HCAs or IOC/VPPA/HCA_SVC/Port/Pseudo devices seen (non-IB system)
1758 if (!expand || (!num_hcas && !num_devices)) {
1759 if (!show_dynamic)
1760 return (CFGA_OK);
1763 if (strstr((char *)ap_id, IB_FABRIC_APID_STR) != NULL) {
1764 rv = ib_do_control_ioctl((char *)ap_id, IBNEX_SNAPSHOT_SIZE,
1765 IBNEX_GET_SNAPSHOT, IBNEX_DONOT_PROBE_FLAG,
1766 (void **)&snap_data, &snap_size);
1767 if (rv != 0) {
1768 DPRINTF("cfga_list_ext: ib_do_control_ioctl "
1769 "failed :%d\n", rv);
1770 S_FREE(*ap_id_list);
1771 S_FREE(snap_data);
1772 return (ib_err_msg(errstring, rv, ap_id, errno));
1775 if (nvlist_unpack((char *)snap_data, snap_size, &nvl, 0)) {
1776 DPRINTF("cfga_list_ext: nvlist_unpack 1 failed %p\n",
1777 snap_data);
1778 S_FREE(*ap_id_list);
1779 S_FREE(snap_data);
1780 return (ib_err_msg(errstring, CFGA_IB_NVLIST_ERR,
1781 ap_id, errno));
1785 * In kernel a nvlist is build per ap_id which contains
1786 * information that is displayed using cfgadm -l.
1787 * For IB devices only these 6 items are shown:
1788 * ap_id, type, occupant, receptacle, condition and info
1790 * In addition, one could specify a dynamic ap_id from
1791 * command-line. Then cfgadm -l should show only that
1792 * ap_id and skip rest.
1794 index = 1; count = 0;
1795 while (nvp = nvlist_next_nvpair(nvl, nvp)) {
1796 int32_t intval = 0;
1797 int32_t node_type;
1798 char *info;
1799 char *nv_apid;
1800 char *name = nvpair_name(nvp);
1802 /* start of with next device */
1803 if (count == IB_NUM_NVPAIRS) {
1804 count = 0;
1805 ++index;
1809 * Check if the index doesn't go beyond the
1810 * device number. If it goes, stop the loop
1811 * here not to cause the heap corruption.
1813 if (show_dynamic == 0 && index > num_devices)
1814 break;
1816 /* fill up data into "clp" */
1817 clp = (show_dynamic != 0) ? &(*ap_id_list[0]) :
1818 &(ap_id_list[0][index]);
1820 /* First nvlist entry is "ap_id" always */
1821 if (strcmp(name, IBNEX_NODE_APID_NVL) == 0) {
1822 (void) nvpair_value_string(nvp, &nv_apid);
1823 DPRINTF("cfga_list_ext: Name = %s, apid = %s\n",
1824 name, nv_apid);
1827 * If a dynamic ap_id is specified in the
1828 * command-line, skip all entries until
1829 * the one needed matches.
1831 if (show_dynamic &&
1832 strstr(ap_id, nv_apid) == NULL) {
1833 DPRINTF("cfga_list_ext: NO MATCH\n");
1836 * skip rest of the entries of this
1837 * device.
1839 for (i = 0; i < IB_NUM_NVPAIRS - 1; i++)
1840 nvp = nvlist_next_nvpair(nvl,
1841 nvp);
1842 count = 0; /* reset it */
1843 continue;
1846 apid_matched = B_TRUE;
1848 /* build the physical ap_id */
1849 if (strstr(ap_id, DYN_SEP) == NULL) {
1850 (void) snprintf(clp->ap_phys_id,
1851 sizeof (clp->ap_phys_id), "%s%s%s",
1852 ap_id, DYN_SEP, nv_apid);
1853 } else {
1854 (void) snprintf(clp->ap_phys_id,
1855 sizeof (clp->ap_phys_id), "%s",
1856 ap_id);
1859 /* ensure that this is a valid apid */
1860 if (ib_verify_valid_apid(clp->ap_phys_id) !=
1861 0) {
1862 DPRINTF("cfga_list_ext: "
1863 "not a valid IB ap_id\n");
1864 S_FREE(*ap_id_list);
1865 S_FREE(snap_data);
1866 nvlist_free(nvl);
1867 return (ib_err_msg(errstring,
1868 CFGA_IB_AP_ERR, ap_id, errno));
1871 /* build the logical ap_id */
1872 (void) snprintf(clp->ap_log_id,
1873 sizeof (clp->ap_log_id), "ib%s%s",
1874 DYN_SEP, nv_apid);
1875 DPRINTF("cfga_list_ext: ap_pi = %s, ap_li = %s,"
1876 "\nap_info = %s\n", clp->ap_phys_id,
1877 clp->ap_log_id, clp->ap_info);
1878 ++count;
1880 } else if (strcmp(name, IBNEX_NODE_INFO_NVL) == 0) {
1881 (void) nvpair_value_string(nvp, &info);
1882 DPRINTF("cfga_list_ext: Name = %s, info = %s\n",
1883 name, info);
1884 (void) snprintf(clp->ap_info,
1885 sizeof (clp->ap_info), "%s", info);
1886 ++count;
1888 } else if (strcmp(name, IBNEX_NODE_TYPE_NVL) == 0) {
1889 (void) nvpair_value_int32(nvp, &node_type);
1890 if (node_type == IBNEX_PORT_NODE_TYPE) {
1891 (void) snprintf(clp->ap_type,
1892 sizeof (clp->ap_type), "%s",
1893 IB_PORT_TYPE);
1894 } else if (node_type == IBNEX_VPPA_NODE_TYPE) {
1895 (void) snprintf(clp->ap_type,
1896 sizeof (clp->ap_type), "%s",
1897 IB_VPPA_TYPE);
1898 } else if (node_type ==
1899 IBNEX_HCASVC_NODE_TYPE) {
1900 (void) snprintf(clp->ap_type,
1901 sizeof (clp->ap_type), "%s",
1902 IB_HCASVC_TYPE);
1903 } else if (node_type == IBNEX_IOC_NODE_TYPE) {
1904 (void) snprintf(clp->ap_type,
1905 sizeof (clp->ap_type), "%s",
1906 IB_IOC_TYPE);
1907 } else if (node_type ==
1908 IBNEX_PSEUDO_NODE_TYPE) {
1909 (void) snprintf(clp->ap_type,
1910 sizeof (clp->ap_type), "%s",
1911 IB_PSEUDO_TYPE);
1913 DPRINTF("cfga_list_ext: Name = %s, type = %x\n",
1914 name, intval);
1915 ++count;
1917 } else if (strcmp(name, IBNEX_NODE_RSTATE_NVL) == 0) {
1918 (void) nvpair_value_int32(nvp, &intval);
1920 if (intval == AP_RSTATE_EMPTY)
1921 clp->ap_r_state = CFGA_STAT_EMPTY;
1922 else if (intval == AP_RSTATE_DISCONNECTED)
1923 clp->ap_r_state =
1924 CFGA_STAT_DISCONNECTED;
1925 else if (intval == AP_RSTATE_CONNECTED)
1926 clp->ap_r_state = CFGA_STAT_CONNECTED;
1927 DPRINTF("cfga_list_ext: Name = %s, "
1928 "rstate = %x\n", name, intval);
1929 ++count;
1931 } else if (strcmp(name, IBNEX_NODE_OSTATE_NVL) == 0) {
1932 (void) nvpair_value_int32(nvp, &intval);
1934 if (intval == AP_OSTATE_CONFIGURED)
1935 clp->ap_o_state = CFGA_STAT_CONFIGURED;
1936 else if (intval == AP_OSTATE_UNCONFIGURED)
1937 clp->ap_o_state =
1938 CFGA_STAT_UNCONFIGURED;
1939 DPRINTF("cfga_list_ext: Name = %s, "
1940 "ostate = %x\n", name, intval);
1941 ++count;
1943 } else if (strcmp(name, IBNEX_NODE_COND_NVL) == 0) {
1944 (void) nvpair_value_int32(nvp, &intval);
1946 if (intval == AP_COND_OK)
1947 clp->ap_cond = CFGA_COND_OK;
1948 else if (intval == AP_COND_FAILING)
1949 clp->ap_cond = CFGA_COND_FAILING;
1950 else if (intval == AP_COND_FAILED)
1951 clp->ap_cond = CFGA_COND_FAILED;
1952 else if (intval == AP_COND_UNUSABLE)
1953 clp->ap_cond = CFGA_COND_UNUSABLE;
1954 else if (intval == AP_COND_UNKNOWN)
1955 clp->ap_cond = CFGA_COND_UNKNOWN;
1956 DPRINTF("cfga_list_ext: Name = %s, "
1957 "condition = %x\n", name, intval);
1958 ++count;
1961 clp->ap_class[0] = '\0'; /* Filled by libcfgadm */
1962 clp->ap_busy = 0;
1963 clp->ap_status_time = (time_t)-1;
1964 } /* end of while */
1967 S_FREE(snap_data);
1968 nvlist_free(nvl);
1971 * if a cmdline specified ap_id doesn't match the known list of ap_ids
1972 * then report an error right away
1974 rv = (apid_matched == B_TRUE) ? CFGA_IB_OK : CFGA_IB_AP_ERR;
1975 return (ib_err_msg(errstring, rv, ap_id, errno));
1980 * Function:
1981 * cfga_msg
1982 * Input:
1983 * msgp - cfgadm error message for this plugin
1984 * str - string to be passed on to the message
1985 * Output:
1986 * NONE
1987 * Returns:
1988 * NONE
1989 * Description:
1990 * This routine accepts a variable number of message IDs and
1991 * constructs a corresponding error string which is printed
1992 * via the message print routine argument.
1994 void
1995 cfga_msg(struct cfga_msg *msgp, const char *str)
1997 int len;
1998 char *q;
2000 if (msgp == NULL || msgp->message_routine == NULL) {
2001 DPRINTF("cfga_msg: msg\n");
2002 return;
2005 if ((len = strlen(str)) == 0) {
2006 DPRINTF("cfga_msg: null str\n");
2007 return;
2010 if ((q = (char *)calloc(len + 1, 1)) == NULL) {
2011 DPRINTF("cfga_msg: null q\n");
2012 return;
2015 (void) strlcpy(q, str, len + 1);
2016 (*msgp->message_routine)(msgp->appdata_ptr, q);
2018 free(q);
2023 * Function:
2024 * cfga_help
2025 * Input:
2026 * msgp - Help message passed on to cfgadm(8)
2027 * options - Help message options passed on to cfgadm(8)
2028 * flags - Cfgadm(1m) flags
2029 * Output:
2030 * NONE
2031 * Returns:
2032 * Were we able to print cfgadm help or not for this plugin
2033 * Description:
2034 * Print cfgadm help for this plugin
2036 /* ARGSUSED */
2037 cfga_err_t
2038 cfga_help(struct cfga_msg *msgp, const char *options, cfga_flags_t flags)
2040 DPRINTF("cfga_help:\n");
2042 if (options) {
2043 cfga_msg(msgp, dgettext(TEXT_DOMAIN, ib_help[
2044 CFGA_IB_HELP_UNKNOWN]));
2045 cfga_msg(msgp, options);
2048 /* Print messages array */
2049 cfga_msg(msgp, dgettext(TEXT_DOMAIN, ib_help[CFGA_IB_HELP_HEADER]));
2050 cfga_msg(msgp, ib_help[CFGA_IB_HELP_CONFIG]);
2051 cfga_msg(msgp, ib_help[CFGA_IB_HELP_LIST]);
2052 cfga_msg(msgp, ib_help[CFGA_IB_HELP_UPD_PKEY]);
2053 cfga_msg(msgp, ib_help[CFGA_IB_HELP_CONF_FILE1]);
2054 cfga_msg(msgp, ib_help[CFGA_IB_HELP_CONF_FILE2]);
2055 cfga_msg(msgp, ib_help[CFGA_IB_HELP_UPD_IOC_CONF]);
2056 cfga_msg(msgp, ib_help[CFGA_IB_HELP_UNCFG_CLNTS]);
2058 return (CFGA_OK);
2063 * Function:
2064 * ib_confirm
2065 * Input:
2066 * confp - The "cfga" structure that confirms a cfgadm query
2067 * msg - The message that needs confirmation
2068 * Output:
2069 * None
2070 * Returns:
2071 * If a user entered YES or NO
2072 * Description:
2073 * Queries a user if it is ok to proceed with an operation or not.
2074 * Returns user's response.
2076 static int
2077 ib_confirm(struct cfga_confirm *confp, char *msg)
2079 int rval;
2081 /* check that "confirm" function exists */
2082 if (confp == NULL || confp->confirm == NULL) {
2083 return (0);
2086 /* Call cfgadm provided "confirm" function */
2087 rval = (*confp->confirm)(confp->appdata_ptr, msg);
2088 DPRINTF("ib_confirm: %d\n", rval);
2090 return (rval);
2095 * Function:
2096 * ib_get_devicepath
2097 * Input:
2098 * ap_id - The dynamic attachment point of an IB device
2099 * Output:
2100 * None
2101 * Returns:
2102 * devpath if it exists; otherwise NULL
2103 * Description:
2104 * Returns the devicepath for a dynamic attachment point of an IB device
2106 static char *
2107 ib_get_devicepath(const char *ap_id)
2109 char *devpath = NULL;
2110 size_t size;
2112 /* Get device path sizes */
2113 if (ib_do_control_ioctl((char *)ap_id, IBNEX_DEVICE_PATH_SZ,
2114 IBNEX_GET_DEVICE_PATH, 0, (void **)&devpath, &size) == CFGA_IB_OK) {
2115 DPRINTF("ib_get_devicepath: get device path ioctl ok\n");
2116 return (devpath);
2118 } else {
2119 DPRINTF("ib_get_devicepath: get device path ioctl failed\n");
2120 return (NULL);