cfga.c revision 48c888ec5f47088ca17290c8fa6552bdf6f0bb5e
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "License").
* You may not use this file except in compliance with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 2006 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#pragma ident "%Z%%M% %I% %E% SMI"
/*
* Plugin Library for PCI Hot-Plug Controller
*/
#include <stddef.h>
#include <locale.h>
#include <ctype.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <fcntl.h>
#include <unistd.h>
#include <errno.h>
#include <locale.h>
#include <langinfo.h>
#include <time.h>
#include <stdarg.h>
#include <libdevinfo.h>
#include <libdevice.h>
#define CFGA_PLUGIN_LIB
#include <config_admin.h>
#include <sys/dditypes.h>
#include <libintl.h>
#include <dirent.h>
#include <limits.h>
#include <librcm.h>
#include "../../../../common/pci/pci_strings.h"
extern const struct pci_class_strings_s class_pci[];
extern int class_pci_items;
/*
* Set the version number
*/
int cfga_version = CFGA_HSL_V2;
#ifdef DEBUG
#define PCIHP_DBG 1
#endif
#if !defined(TEXT_DOMAIN)
#define TEXT_DOMAIN "SYS_TEST"
#endif
/*
* DEBUGING LEVEL
*
* External routines: 1 - 2
* Internal routines: 3 - 4
*/
#ifdef PCIHP_DBG
int pcihp_debug = 1;
#else
#endif
#define CMD_ACQUIRE 0
#define CMD_GETSTAT 1
#define CMD_LIST 2
#define CMD_SLOT_CONNECT 3
#define CMD_SLOT_DISCONNECT 4
#define CMD_SLOT_CONFIGURE 5
#define CMD_SLOT_UNCONFIGURE 6
#define CMD_SLOT_INSERT 7
#define CMD_SLOT_REMOVE 8
#define CMD_OPEN 9
#define CMD_FSTAT 10
#define ERR_CMD_INVAL 11
#define ERR_AP_INVAL 12
#define ERR_AP_ERR 13
#define ERR_OPT_INVAL 14
static char *
cfga_errstrs[] = {
/* n */ "acquire ",
/* n */ "get-status ",
/* n */ "list ",
/* n */ "connect ",
/* n */ "disconnect ",
/* n */ "configure ",
/* n */ "unconfigure ",
/* n */ "insert ",
/* n */ "remove ",
/* n */ "open ",
/* n */ "fstat ",
/* y */ "invalid command ",
/* y */ "invalid attachment point ",
/* y */ "invalid transition ",
/* y */ "invalid option ",
};
#define HELP_HEADER 1
#define HELP_CONFIG 2
#define HELP_ENABLE_SLOT 3
#define HELP_DISABLE_SLOT 4
#define HELP_ENABLE_AUTOCONF 5
#define HELP_DISABLE_AUTOCONF 6
#define HELP_LED_CNTRL 7
#define HELP_UNKNOWN 8
#define SUCCESS 9
#define FAILED 10
#define UNKNOWN 11
#define MAXLINE 256
/* for type string assembly in get_type() */
extern int errno;
void *retdata);
static char *
cfga_strs[] = {
NULL,
"\nPCI hotplug specific commands:",
"\t-c [connect|disconnect|configure|unconfigure|insert|remove] "
"ap_id [ap_id...]",
"\t-x enable_slot ap_id [ap_id...]",
"\t-x disable_slot ap_id [ap_id...]",
"\t-x enable_autoconfig ap_id [ap_id...]",
"\t-x disable_autoconfig ap_id [ap_id...]",
"\t-x led[=[fault|power|active|attn],mode=[on|off|blink]] ap_id [ap_id...]",
"\tunknown command or option: ",
"success ",
"failed ",
"unknown",
};
#define MAX_FORMAT 80
#define ENABLE_SLOT 0
#define DISABLE_SLOT 1
#define ENABLE_AUTOCNF 2
#define DISABLE_AUTOCNF 3
#define LED 4
#define MODE 5
/*
* Board Type
*/
static char *
board_strs[] = {
/* n */ "???", /* HPC_BOARD_UNKNOWN */
/* n */ "hp", /* HPC_BOARD_PCI_HOTPLUG */
/* n */ "nhs", /* HPC_BOARD_CPCI_NON_HS */
/* n */ "bhs", /* HPC_BOARD_CPCI_BASIC_HS */
/* n */ "fhs", /* HPC_BOARD_CPCI_FULL_HS */
/* n */ "hs", /* HPC_BOARD_CPCI_HS */
/* n */ NULL
};
/*
* HW functions
*/
static char *
func_strs[] = {
/* n */ "enable_slot",
/* n */ "disable_slot",
/* n */ "enable_autoconfig",
/* n */ "disable_autoconfig",
/* n */ "led",
/* n */ "mode",
/* n */ NULL
};
/*
* LED strings
*/
static char *
led_strs[] = {
/* n */ "fault", /* HPC_FAULT_LED */
/* n */ "power", /* HPC_POWER_LED */
/* n */ "attn", /* HPC_ATTN_LED */
/* n */ "active", /* HPC_ACTIVE_LED */
/* n */ NULL
};
#define FAULT 0
#define POWER 1
#define ATTN 2
#define ACTIVE 3
static char *
mode_strs[] = {
/* n */ "off", /* HPC_LED_OFF */
/* n */ "on", /* HPC_LED_ON */
/* n */ "blink", /* HPC_LED_BLINK */
/* n */ NULL
};
#define OFF 0
#define ON 1
#define BLINK 2
#define cfga_errstrs(i) cfga_errstrs[(i)]
#define cfga_eid(a, b) (((a) << 8) + (b))
#define MAXDEVS 32
typedef enum {
struct searcharg {
char *devpath;
int minor;
};
static void *private_check;
static int
{
int rv;
int fd;
char *prop_data;
char *tmp;
char *ptr;
return (CFGA_ERROR);
}
return (CFGA_ERROR);
}
*ptr = '\0';
if (ap_node == DI_NODE_NIL) {
return (CFGA_ERROR);
}
#ifdef PCIHP_DBG
#endif
&prop_data)) == -1) {
return (CFGA_ERROR);
}
occupant->i = 0;
return (CFGA_OK);
}
occupant->i--;
break;
}
}
return (CFGA_OK);
}
/*
* let rcm know that the device has indeed been removed and clean
* up rcm data
*/
static void
{
if (occupant->i == 0) /* nothing was found to ask rcm about */
return;
(void) rcm_free_handle(rhandle);
}
static void
{
if (occupant->i == 0) /* nothing was found to ask rcm about */
return;
(void) rcm_free_handle(rhandle);
}
/*
* copied from scsi_rcm_info_table
*
* Takes an opaque rcm_info_t pointer and a character pointer, and appends
* the rcm_info_t data in the form of a table to the given character pointer.
*/
static void
{
int i;
size_t w;
size_t table_size = 0;
char *rsrc;
char *info;
char *newtable;
static char format[MAX_FORMAT];
const char *infostr;
/* Protect against invalid arguments */
return;
/* Set localized table header strings */
/* A first pass, to size up the RCM information */
tuples++;
w_rsrc = w;
w_info = w;
}
}
/* If nothing was sized up above, stop early */
if (tuples == 0)
return;
/* Adjust column widths for column headings */
w_rsrc = w;
else if ((w_rsrc - w) % 2)
w_rsrc++;
w_info = w;
else if ((w_info - w) % 2)
w_info++;
/*
* Compute the total line width of each line,
* accounting for intercolumn spacing.
*/
/* Allocate space for the table */
/* zero fill for the strcat() call below */
return;
} else {
return;
else
}
/* Place a table header into the string */
/* The resource header */
for (i = 0; i < ((w_rsrc - w) / 2); i++)
for (i = 0; i < ((w_rsrc - w) / 2); i++)
/* The information header */
for (i = 0; i < ((w_info - w) / 2); i++)
for (i = 0; i < ((w_info - w) / 2); i++)
/* Underline the headers */
for (i = 0; i < w_rsrc; i++)
for (i = 0; i < w_info; i++)
/* Construct the format string */
/* Add the tuples to the table string */
infostr);
}
}
}
/*
* Figure out what device is about to be unconfigured or disconnected
* and make sure rcm is ok with it.
* hangs on to a list of handles so they can then be confirmed or denied
* if either getting the occupant list or talking to rcm fails
* return CFGA_ERROR so that things can go on without rcm
*/
static int
{
int rv;
return (CFGA_ERROR);
}
if (occupant->i == 0) {
return (CFGA_OK);
}
!= RCM_SUCCESS) {
return (CFGA_ERROR);
}
if (rv == RCM_FAILURE) {
return (CFGA_BUSY);
}
if (rv == RCM_CONFLICT) {
rcm_info_pid(rinfo)));
(void) rcm_free_handle(rhandle);
return (CFGA_BUSY);
}
/* else */
return (CFGA_OK);
}
/*
* Transitional Diagram:
*
* empty unconfigure
* (remove) ^| (physically insert card)
* |V
* disconnect configure
* "-c DISCONNECT" ^| "-c CONNECT"
* |V "-c CONFIGURE"
* connect unconfigure -> connect configure
* <-
* "-c UNCONFIGURE"
*
*/
/*ARGSUSED*/
{
int rv;
return (rv);
}
} else
rv = CFGA_ERROR;
return (rv);
}
else
rv = CFGA_ERROR;
return (rv);
}
switch (state_change_cmd) {
case CFGA_CMD_CONNECT:
if ((rs == AP_RSTATE_EMPTY) ||
(rs == AP_RSTATE_CONNECTED) ||
(os == AP_OSTATE_CONFIGURED)) {
rv = CFGA_INVAL;
} else {
/* Lets connect the slot */
rv = CFGA_ERROR;
CMD_SLOT_CONNECT, 0);
}
}
break;
case CFGA_CMD_DISCONNECT:
if (os == AP_OSTATE_CONFIGURED) {
break;
else
rv = CFGA_ERROR;
CMD_SLOT_DISCONNECT, 0);
break;
} else {
}
} else { /* rv == CFGA_ERROR */
else
rv = CFGA_ERROR;
break;
} else {
}
}
}
if (rs == AP_RSTATE_CONNECTED) {
rv = CFGA_ERROR;
break;
}
} else {
rv = CFGA_INVAL;
}
break;
case CFGA_CMD_CONFIGURE:
if (rs == AP_RSTATE_DISCONNECTED) {
rv = CFGA_ERROR;
break;
}
}
/*
* for multi-func device we allow multiple
* configure on the same slot because one
* func can be configured and other one won't
*/
rv = CFGA_ERROR;
if ((rs == AP_RSTATE_DISCONNECTED) &&
== -1)) {
rv = CFGA_ERROR;
CMD_SLOT_CONFIGURE, 0);
}
break;
}
break;
case CFGA_CMD_UNCONFIGURE:
if (os == AP_OSTATE_CONFIGURED) {
break;
else {
rv = CFGA_OPNOTSUPP;
else
rv = CFGA_ERROR;
}
CMD_SLOT_UNCONFIGURE, 0);
} else {
}
} else { /* rv == CFGA_ERROR */
else {
rv = CFGA_OPNOTSUPP;
else
rv = CFGA_ERROR;
}
CMD_SLOT_UNCONFIGURE, 0);
} else {
}
}
} else {
rv = CFGA_INVAL;
}
break;
case CFGA_CMD_LOAD:
if ((os == AP_OSTATE_UNCONFIGURED) &&
(rs == AP_RSTATE_DISCONNECTED)) {
rv = CFGA_ERROR;
}
} else {
rv = CFGA_INVAL;
}
break;
case CFGA_CMD_UNLOAD:
if ((os == AP_OSTATE_UNCONFIGURED) &&
(rs == AP_RSTATE_DISCONNECTED)) {
rv = CFGA_ERROR;
}
} else {
rv = CFGA_INVAL;
}
break;
default:
rv = CFGA_OPNOTSUPP;
break;
}
return (rv);
}
/*
* Building iocdatat to pass it to nexus
*
* iocdata->cmd == HPC_CTRL_ENABLE_SLOT/HPC_CTRL_DISABLE_SLOT
* HPC_CTRL_GET_BOARD_TYPE
*
*/
static void
void *retdata)
{
}
/*
* building logical name from ap_id
*/
/*ARGSUSED2*/
static void
{
return;
}
/* needs to look for last /, not first */
*bufptr = '\0';
}
*bufptr = '\0';
bufptr++;
}
}
static cfga_err_t
{
struct hpc_control_data iocdata;
char *buff;
int fd;
if (!repeat)
return (CFGA_ERROR);
}
return (CFGA_ERROR);
}
return (CFGA_ERROR);
}
(void *)&slot_info);
} else {
/*
* the driver will report back things like hpc0_slot0
* this needs to be changed to things like pci1:hpc0_slot0
*/
return (CFGA_ERROR);
}
}
} else {
}
} else {
}
} else {
}
} else {
}
return (CFGA_OK);
}
/*ARGSUSED*/
{
char *str;
char buf[MAXNAMELEN];
char ptr;
struct hpc_control_data iocdata;
return (rv);
}
if (private_check == confp)
repeat = 1;
else
private_check = (void*)confp;
/* XXX change const 6 to func_str[i] != NULL */
break;
}
switch (i) {
case ENABLE_SLOT:
HPC_CTRL_ENABLE_SLOT, 0);
break;
case DISABLE_SLOT:
break;
case ENABLE_AUTOCNF:
break;
case DISABLE_AUTOCNF:
break;
case LED:
/* set mode */
if (ptr == '=') {
i++, str++) {
if (i == (MAXNAMELEN - 1))
break;
}
/* ACTIVE=3,ATTN=2,POWER=1,FAULT=0 */
else return (CFGA_INVAL);
}
}
buf[i] = '\0';
/* ON = 1, OFF = 0 */
else return (CFGA_INVAL);
/* sendin */
(void *)&led_info);
break;
} else if (ptr == '\0') {
/* print mode */
msgp));
}
default:
return (CFGA_INVAL);
}
return (CFGA_ERROR);
}
return (CFGA_ERROR);
}
return (CFGA_OK);
}
/*ARGSUSED*/
{
return (rv);
}
/* will need to implement pci CTRL command */
return (CFGA_NOTSUPP);
}
static int
{
/*
* The slot-names property describes the external labeling of add-in slots.
* This property is an encoded array, an integer followed by a list of
* strings. The return value from di_prop_lookup_ints for slot-names is -1.
* The expected return value should be the number of elements.
* Di_prop_decode_common does not decode encoded data from software,
* such as the solaris device tree, unlike from the prom.
* Di_prop_decode_common takes the size of the encoded data and mods
* it with the size of int. The size of the encoded data for slot-names is 9
* and the size of int is 4, yielding a non zero result. A value of -1 is used
* to indicate that the number of elements can not be determined.
* Di_prop_decode_common can be modified to decode encoded data from the solaris
* device tree.
*/
return (DI_WALK_TERMINATE);
} else {
int i;
if (i >= MAXDEVS)
return (DI_WALK_TERMINATE);
if ((*intp >> i) & 1) {
/* assign tmptr */
tmptr);
/* wind tmptr to next \0 */
while (*tmptr != '\0') {
tmptr++;
}
tmptr++;
} else {
/* point at unknown string */
"unknown");
}
}
}
return (DI_WALK_TERMINATE);
}
static int
{
char *devname;
char fulldevname[MAXNAMELEN];
}
/*
* Check the Solaris device tree first
* in the case of a DR operation
*/
while (solaris_prop != DI_PROP_NIL) {
== 0) {
}
}
/*
* Check the prom device tree which is populated at boot.
* If this fails, give up and set the slot name to null.
*/
while (prom_prop != DI_PROM_PROP_NIL) {
== 0) {
}
}
return (DI_WALK_TERMINATE);
} else
return (DI_WALK_CONTINUE);
}
static int
{
== DI_NODE_NIL) {
return (NULL);
}
return (NULL);
}
0, (void *)slotarg, find_slotname);
return (0);
else
return (-1);
}
static void
{
int i;
TPCT("unknown");
return;
}
for (i = 0; i < class_pci_items; i++) {
break;
}
}
if (i == class_pci_items)
TPCT("unknown");
TPCT("/");
switch (boardtype) {
case HPC_BOARD_PCI_HOTPLUG:
case HPC_BOARD_CPCI_NON_HS:
case HPC_BOARD_CPCI_BASIC_HS:
case HPC_BOARD_CPCI_FULL_HS:
case HPC_BOARD_CPCI_HS:
break;
case HPC_BOARD_UNKNOWN:
default:
}
}
/*
* call-back function for di_devlink_walk
*/
static int
{
return (DI_WALK_TERMINATE);
}
return (DI_WALK_CONTINUE);
}
/*
* Walk throught the cached /dev link tree looking for links to the ap
* if none are found return an error
*/
static cfga_err_t
{
/* ap_id is a valid minor_path with /devices prepended */
(void *)ap_log_id, found_devlink);
} else {
return (CFGA_ERROR);
}
(void) di_devlink_fini(&hdl);
if (ap_log_id[0] != '\0')
return (CFGA_OK);
else
return (CFGA_ERROR);
}
/*
* most of this is needed to compensate for
* differences between various platforms
*/
static cfga_err_t
char **errstring)
{
char *buf;
char *tmp;
char *ptr;
ap_log_id[0] = '\0';
return (CFGA_OK);
return (CFGA_ERROR);
}
ptr[0] = '\0';
if (ap_node == DI_NODE_NIL) {
return (CFGA_ERROR);
}
return (CFGA_OK);
}
/*ARGSUSED*/
{
struct hpc_control_data iocdata;
struct searcharg slotname_arg;
int fd;
return (rv);
}
rv = CFGA_ERROR;
return (rv);
}
*nlist = 1;
rv = CFGA_ERROR;
return (rv);
}
rv = CFGA_ERROR;
return (rv);
}
rv = CFGA_ERROR;
return (rv);
}
case AP_RSTATE_EMPTY:
break;
case AP_RSTATE_DISCONNECTED:
break;
case AP_RSTATE_CONNECTED:
break;
default:
rv = CFGA_ERROR;
return (rv);
}
case AP_OSTATE_CONFIGURED:
break;
case AP_OSTATE_UNCONFIGURED:
break;
default:
rv = CFGA_ERROR;
return (rv);
}
switch (state.ap_condition) {
case AP_COND_OK:
break;
case AP_COND_FAILING:
break;
case AP_COND_FAILED:
break;
case AP_COND_UNUSABLE:
break;
case AP_COND_UNKNOWN:
break;
default:
rv = CFGA_ERROR;
return (rv);
}
(*cs)->ap_status_time = 0;
goto cont;
}
/* need board type and a way to get to hpc_slot_info */
(void *)&boardtype);
}
(void *)&slot_info);
} else {
/*
* the driver will report back things like hpc0_slot0
* this needs to be changed to things like pci1:hpc0_slot0
*/
}
(void *)&cardinfo);
}
cont:
/* slot_names of bus node */
/* class_code/subclass/boardtype */
return (rv);
}
/*
* This routine prints a single line of help message
*/
static void
{
return;
}
static cfga_err_t
check_options(const char *options)
{
if (options) {
return (CFGA_INVAL);
}
return (CFGA_OK);
}
/*ARGSUSED*/
{
if (options) {
}
return (CFGA_OK);
}
/*
* cfga_err() accepts a variable number of message IDs and constructs
* a corresponding error string which is returned via the errstring argument.
* cfga_err() calls gettext() to internationalize proper messages.
*/
static void
{
int a;
int i;
int n;
int len;
int flen;
char *p;
char *q;
char *s[32];
char *failed;
/*
* If errstring is null it means user in not interested in getting
* error status. So we don't do all the work
*/
return;
}
switch (a) {
case CMD_GETSTAT:
case CMD_LIST:
case CMD_SLOT_CONNECT:
case CMD_SLOT_DISCONNECT:
case CMD_SLOT_CONFIGURE:
case CMD_SLOT_UNCONFIGURE:
p = cfga_errstrs(a);
s[n] = p;
break;
case ERR_CMD_INVAL:
case ERR_AP_INVAL:
case ERR_OPT_INVAL:
case ERR_AP_ERR:
switch (a) {
case ERR_CMD_INVAL:
p = dgettext(TEXT_DOMAIN,
break;
case ERR_AP_INVAL:
p = dgettext(TEXT_DOMAIN,
break;
case ERR_OPT_INVAL:
p = dgettext(TEXT_DOMAIN,
break;
case ERR_AP_ERR:
p = dgettext(TEXT_DOMAIN,
break;
}
s[n] = p;
s[++n] = q;
break;
} else {
s[n] = p;
}
break;
default:
n--;
break;
}
}
return;
for (i = 0; i < n; i++) {
}
*errstring = p;
#ifdef DEBUG
#endif
}
/*
* cfga_ap_id_cmp -- use default_ap_id_cmp() in libcfgadm
*/