/*
* 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 2004 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#include <assert.h>
#include <ctype.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <macros.h>
#include <dirent.h>
#include <libgen.h>
#include <libdevinfo.h>
#define CFGA_PLUGIN_LIB
#include <config_admin.h>
#include "ap.h"
#ifdef __x86
#include <libscf_priv.h>
static int fastreboot_disabled;
#endif /* __x86 */
static cfga_err_t
{
int c;
int rc;
int skip;
int check;
/*
* Check if any of the steps in the sequence
* may require a suspension of service and ask
* the user to confirm.
*/
continue;
return (rc);
/*
* If a suspend is required, ask for user confirmation.
* The force flag overrides the user confirmation.
*/
return (CFGA_NACK);
}
return (CFGA_OK);
}
#define AP_SEQ_OK 0
/*
* Sequence a cfgadm state change command into driver commands.
* The rstate and ostate of the AP are needed at this point
* in order to compute the proper sequence.
*/
static int
{
int done = 0;
int f = CMD_NONE;
int l = CMD_NONE;
switch (rs) {
case CFGA_STAT_EMPTY:
switch (os) {
case CFGA_STAT_UNCONFIGURED:
switch (cmd) {
case CMD_UNCONFIGURE:
done++;
break;
default:
break;
}
break;
default:
break;
}
break;
case CFGA_STAT_DISCONNECTED:
switch (os) {
case CFGA_STAT_UNCONFIGURED:
switch (cmd) {
case CMD_DISCONNECT:
/*
* skip the disconnect command since
* the rstate is already disconnected
*/
f = CMD_DISCONNECT;
l = CMD_UNASSIGN;
break;
case CMD_UNCONFIGURE:
done++;
break;
case CMD_CONNECT:
f = CMD_ASSIGN;
l = CMD_CONNECT;
break;
case CMD_CONFIGURE:
f = CMD_ASSIGN;
l = CMD_RCM_CAP_ADD;
break;
default:
break;
}
break;
default:
break;
}
break;
case CFGA_STAT_CONNECTED:
switch (os) {
case CFGA_STAT_UNCONFIGURED:
switch (cmd) {
case CMD_CONNECT:
case CMD_UNCONFIGURE:
done++;
break;
case CMD_DISCONNECT:
f = CMD_DISCONNECT;
l = CMD_UNASSIGN;
break;
case CMD_CONFIGURE:
f = CMD_CONFIGURE;
l = CMD_RCM_CAP_ADD;
break;
default:
break;
}
break;
case CFGA_STAT_CONFIGURED:
switch (cmd) {
case CMD_CONNECT:
done++;
break;
case CMD_DISCONNECT:
f = CMD_SUSPEND_CHECK;
l = CMD_UNASSIGN;
break;
case CMD_CONFIGURE:
f = CMD_CONFIGURE;
l = CMD_RCM_CAP_ADD;
break;
case CMD_UNCONFIGURE:
f = CMD_SUSPEND_CHECK;
l = CMD_RCM_CAP_NOTIFY;
break;
default:
break;
}
break;
default:
break;
}
break;
default:
break;
}
if (f == CMD_NONE) {
if (done)
return (AP_SEQ_NULL);
return (AP_SEQ_FAIL);
}
*first = f;
*last = l;
DBG("ap_seq(%d, %d, %d, %p, %p) = (%d, %d)\n",
return (AP_SEQ_OK);
}
#define DBG_RECOVER_MSG(f, l) \
DBG("Sequencing recovery: first = %s, last = %s\n", \
ap_cmd_name(f), ap_cmd_name(l))
{
int c;
int skip;
int suspend;
int resume;
suspend = 0;
resume = 0;
/*
* The unassign step is skipped unless explicity requested
* either by a -x request or as an option to a disconnect
* request.
*/
/*
* Check for platform options
*/
goto done;
}
continue;
}
/*
* If the suspend operation does not
* succeed, resume any devices already
* suspended as well as the device on
* which the operation failed.
*/
switch (c) {
case CMD_SUSPEND_CHECK:
/*
* Check whether the user allows a suspend
* operation if the suspend is required.
* Next step is to allow RCM clients to
* interpose on the suspend operation.
*/
break;
case CMD_RCM_SUSPEND:
/*
* Mark the fact that a suspend operation
* is required, and that RCM clients have
* allowed the suspend.
*/
ap_setopt(a, OPT_SUSPEND_OK);
resume++;
}
break;
case CMD_RCM_RESUME:
if (resume) {
(void) ap_rcm_ctl(a, c);
resume--;
}
break;
case CMD_RCM_OFFLINE:
case CMD_RCM_CAP_DEL:
rc = ap_rcm_ctl(a, c);
break;
case CMD_RCM_ONLINE:
case CMD_RCM_CAP_ADD:
case CMD_RCM_REMOVE:
case CMD_RCM_CAP_NOTIFY:
(void) ap_rcm_ctl(a, c);
break;
#ifdef __x86
/*
* Note: this is a temporary solution and will be revised when
* future.
*
* ACPI BIOS generates some static ACPI tables, such as MADT,
* SRAT and SLIT, to describe the system hardware configuration
* static tables won't be updated and will become stale.
*
* If we reset the system by fast reboot, BIOS will have no
* chance to regenerate those staled static tables. Fast reboot
* can't tolerate such inconsistency between staled ACPI tables
* and real hardware configuration yet.
*
* A temporary solution is introduced to disable fast reboot if
* DR operations.
*/
case CMD_ASSIGN:
case CMD_POWERON:
case CMD_POWEROFF:
case CMD_UNASSIGN:
if (!fastreboot_disabled &&
SCF_SUCCESS) {
fastreboot_disabled = 1;
}
/* FALLTHROUGH */
#endif /* __x86 */
default:
break;
}
break;
}
done:
if (resume)
(void) ap_rcm_ctl(a, CMD_RCM_RESUME);
/*
* Check if any operations failed. If so, attempt to rollback
* to previously known states.
* Note: The rollback is currently limited to RCM operations.
*/
if (c == CMD_UNCONFIGURE ||
c == CMD_RCM_OFFLINE ||
c == CMD_RCM_CAP_DEL) {
switch (c) {
case CMD_UNCONFIGURE:
/*
* If the unconfigure operation fails, perform
* an RCM_ONLINE and RCM_CAP_NOTIFY only. This
* keeps RCM clients consistent with the domain.
*/
break;
case CMD_RCM_OFFLINE:
break;
case CMD_RCM_CAP_DEL:
break;
default:
break;
}
DBG("recovery complete!\n");
}
}
return (rc);
}
{
}
{
case AP_SEQ_OK:
break;
case AP_SEQ_NULL:
break;
case AP_SEQ_FAIL:
default:
rc = CFGA_LIB_ERROR;
break;
}
return (rc);
}