1*1258Smlf /* 2*1258Smlf * CDDL HEADER START 3*1258Smlf * 4*1258Smlf * The contents of this file are subject to the terms of the 5*1258Smlf * Common Development and Distribution License (the "License"). 6*1258Smlf * You may not use this file except in compliance with the License. 7*1258Smlf * 8*1258Smlf * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 9*1258Smlf * or http://www.opensolaris.org/os/licensing. 10*1258Smlf * See the License for the specific language governing permissions 11*1258Smlf * and limitations under the License. 12*1258Smlf * 13*1258Smlf * When distributing Covered Code, include this CDDL HEADER in each 14*1258Smlf * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 15*1258Smlf * If applicable, add the following below this CDDL HEADER, with the 16*1258Smlf * fields enclosed by brackets "[]" replaced with your own identifying 17*1258Smlf * information: Portions Copyright [yyyy] [name of copyright owner] 18*1258Smlf * 19*1258Smlf * CDDL HEADER END 20*1258Smlf */ 21*1258Smlf 22*1258Smlf /* 23*1258Smlf * Copyright 2005 Sun Microsystems, Inc. All rights reserved. 24*1258Smlf * Use is subject to license terms. 25*1258Smlf */ 26*1258Smlf 27*1258Smlf #ifndef _CFGA_SATA_H 28*1258Smlf #define _CFGA_SATA_H 29*1258Smlf 30*1258Smlf #pragma ident "%Z%%M% %I% %E% SMI" 31*1258Smlf 32*1258Smlf #ifdef __cplusplus 33*1258Smlf extern "C" { 34*1258Smlf #endif 35*1258Smlf 36*1258Smlf #include <stdlib.h> 37*1258Smlf #include <strings.h> 38*1258Smlf #include <fcntl.h> 39*1258Smlf #include <ctype.h> 40*1258Smlf #include <unistd.h> 41*1258Smlf #include <libintl.h> 42*1258Smlf #include <libdevice.h> 43*1258Smlf #include <sys/varargs.h> 44*1258Smlf 45*1258Smlf #include <sys/sata/sata_cfgadm.h> 46*1258Smlf 47*1258Smlf #include <libdevinfo.h> 48*1258Smlf #include <libdevice.h> 49*1258Smlf #include <librcm.h> 50*1258Smlf #include <synch.h> 51*1258Smlf #include <thread.h> 52*1258Smlf #include <assert.h> 53*1258Smlf 54*1258Smlf #define CFGA_PLUGIN_LIB 55*1258Smlf #include <config_admin.h> 56*1258Smlf 57*1258Smlf /* 58*1258Smlf * Debug stuff 59*1258Smlf */ 60*1258Smlf #ifdef DEBUG 61*1258Smlf #define DPRINTF printf 62*1258Smlf #else 63*1258Smlf #define DPRINTF 0 && 64*1258Smlf #endif /* DEBUG */ 65*1258Smlf 66*1258Smlf typedef enum { 67*1258Smlf CFGA_SATA_TERMINATE = 0, 68*1258Smlf CFGA_SATA_CONTINUE 69*1258Smlf } sata_cfga_recur_t; 70*1258Smlf 71*1258Smlf /* for walking links */ 72*1258Smlf typedef struct walk_link { 73*1258Smlf char *path; 74*1258Smlf char len; 75*1258Smlf char **linkpp; 76*1258Smlf } walk_link_t; 77*1258Smlf 78*1258Smlf #define MATCH_MINOR_NAME 1 79*1258Smlf 80*1258Smlf /* Misc text strings */ 81*1258Smlf #define CFGA_DEV_DIR "/dev/cfg" 82*1258Smlf #define MINOR_SEP ":" 83*1258Smlf #define DYN_SEP "::" 84*1258Smlf #define PORT "port" 85*1258Smlf #define PORT_SEPARATOR "." 86*1258Smlf #define SATA "sata" 87*1258Smlf #define CFGA_DEVCTL_NODE ":devctl" 88*1258Smlf #define SATA_CFGADM_DEFAULT_AP_TYPE "unknown" 89*1258Smlf #define SLICE "s" 90*1258Smlf #define PARTITION "p" 91*1258Smlf #define PATH_SEP "/" 92*1258Smlf 93*1258Smlf /* these set of defines are -lav listing */ 94*1258Smlf #define SATA_UNDEF_STR "<undef>" 95*1258Smlf #define SATA_NO_CFG_STR "<no cfg str descr>" 96*1258Smlf 97*1258Smlf /* -x commands */ 98*1258Smlf #define SATA_RESET_ALL "sata_reset_all" 99*1258Smlf #define SATA_RESET_PORT "sata_reset_port" 100*1258Smlf #define SATA_RESET_DEVICE "sata_reset_device" 101*1258Smlf #define SATA_PORT_DEACTIVATE "sata_port_deactivate" 102*1258Smlf #define SATA_PORT_ACTIVATE "sata_port_activate" 103*1258Smlf #define SATA_PORT_SELF_TEST "sata_port_self_test" 104*1258Smlf 105*1258Smlf /* -t command */ 106*1258Smlf #define SATA_CNTRL_SELF_TEST "sata_cntrl_self_test" 107*1258Smlf 108*1258Smlf /* for confirm operation */ 109*1258Smlf #define SATA_CONFIRM_DEVICE "the device at: " 110*1258Smlf #define SATA_CONFIRM_DEVICE_SUSPEND \ 111*1258Smlf "This operation will suspend activity on the SATA device\nContinue" 112*1258Smlf #define SATA_CONFIRM_DEVICE_ABORT \ 113*1258Smlf "This operation will arbitrarily abort all commands " \ 114*1258Smlf "on SATA device\nContinue" 115*1258Smlf #define SATA_CONFIRM_CONTROLLER "the controller: " 116*1258Smlf #define SATA_CONFIRM_CONTROLLER_ABORT \ 117*1258Smlf "This operation will arbitrarirly abort all commands " \ 118*1258Smlf "on the SATA controller\nContinue" 119*1258Smlf #define SATA_CONFIRM_PORT "the port: " 120*1258Smlf #define SATA_CONFIRM_PORT_DISABLE \ 121*1258Smlf "This operation will disable activity on the SATA port\nContinue" 122*1258Smlf #define SATA_CONFIRM_PORT_ENABLE \ 123*1258Smlf "This operation will enable activity on the SATA port\nContinue" 124*1258Smlf 125*1258Smlf #define S_FREE(x) (((x) != NULL) ? \ 126*1258Smlf (free(x), (x) = NULL) : (void *)0) 127*1258Smlf 128*1258Smlf #define GET_DYN(a) (((a) != NULL) ? \ 129*1258Smlf strstr((a), DYN_SEP) : (void *)0) 130*1258Smlf 131*1258Smlf typedef struct sata_apid { 132*1258Smlf char *hba_phys; 133*1258Smlf char *dyncomp; 134*1258Smlf char *path; 135*1258Smlf uint_t flags; 136*1258Smlf } sata_apid_t; 137*1258Smlf 138*1258Smlf 139*1258Smlf /* Messages */ 140*1258Smlf 141*1258Smlf typedef struct msgcvt { 142*1258Smlf int intl; /* Flag: if 1, internationalize */ 143*1258Smlf cfga_err_t cfga_err; /* Error code libcfgadm understands */ 144*1258Smlf const char *msgstr; 145*1258Smlf } msgcvt_t; 146*1258Smlf 147*1258Smlf #define NO_CVT 0 148*1258Smlf #define CVT 1 149*1258Smlf 150*1258Smlf #define MSG_TBL_SZ(table) (sizeof ((table)) / sizeof (msgcvt_t)) 151*1258Smlf 152*1258Smlf typedef enum { 153*1258Smlf SATA_CFGA_ERR = -2, 154*1258Smlf SATA_CFGA_LIB_ERR, 155*1258Smlf SATA_CFGA_OK, 156*1258Smlf SATA_CFGA_BUSY, 157*1258Smlf SATA_CFGA_NO_REC 158*1258Smlf } sata_cfga_ret_t; 159*1258Smlf 160*1258Smlf /* Messages */ 161*1258Smlf 162*1258Smlf 163*1258Smlf /* Error message ids (and indices into sata_error_msgs) */ 164*1258Smlf typedef enum { 165*1258Smlf CFGA_SATA_OK = 0, 166*1258Smlf CFGA_SATA_NACK, 167*1258Smlf CFGA_SATA_DEVICE_UNCONFIGURED, 168*1258Smlf CFGA_SATA_UNKNOWN, 169*1258Smlf CFGA_SATA_INTERNAL_ERROR, 170*1258Smlf CFGA_SATA_DATA_ERROR, 171*1258Smlf CFGA_SATA_OPTIONS, 172*1258Smlf CFGA_SATA_HWOPNOTSUPP, 173*1258Smlf CFGA_SATA_DYNAMIC_AP, 174*1258Smlf CFGA_SATA_AP, 175*1258Smlf CFGA_SATA_PORT, 176*1258Smlf CFGA_SATA_DEVCTL, 177*1258Smlf CFGA_SATA_DEV_CONFIGURE, 178*1258Smlf CFGA_SATA_DEV_UNCONFIGURE, 179*1258Smlf CFGA_SATA_DISCONNECTED, 180*1258Smlf CFGA_SATA_NOT_CONNECTED, 181*1258Smlf CFGA_SATA_NOT_CONFIGURED, 182*1258Smlf CFGA_SATA_ALREADY_CONNECTED, 183*1258Smlf CFGA_SATA_ALREADY_CONFIGURED, 184*1258Smlf CFGA_SATA_INVALID_DEVNAME, 185*1258Smlf CFGA_SATA_OPEN, 186*1258Smlf CFGA_SATA_IOCTL, 187*1258Smlf CFGA_SATA_BUSY, 188*1258Smlf CFGA_SATA_ALLOC_FAIL, 189*1258Smlf CFGA_SATA_OPNOTSUPP, 190*1258Smlf CFGA_SATA_DEVLINK, 191*1258Smlf CFGA_SATA_STATE, 192*1258Smlf CFGA_SATA_PRIV, 193*1258Smlf CFGA_SATA_NVLIST, 194*1258Smlf CFGA_SATA_ZEROLEN, 195*1258Smlf 196*1258Smlf /* RCM Errors */ 197*1258Smlf CFGA_SATA_RCM_HANDLE, 198*1258Smlf CFGA_SATA_RCM_ONLINE, 199*1258Smlf CFGA_SATA_RCM_OFFLINE, 200*1258Smlf CFGA_SATA_RCM_INFO 201*1258Smlf 202*1258Smlf } cfga_sata_ret_t; 203*1258Smlf 204*1258Smlf /* 205*1258Smlf * Given an error msg index, look up the associated string, and 206*1258Smlf * convert it to the current locale if required. 207*1258Smlf */ 208*1258Smlf #define ERR_STR(msg_idx) \ 209*1258Smlf (get_msg((msg_idx), sata_msgs, MSG_TBL_SZ(sata_msgs))) 210*1258Smlf 211*1258Smlf /* Prototypes */ 212*1258Smlf 213*1258Smlf cfga_err_t sata_err_msg(char **, cfga_sata_ret_t, const char *, int); 214*1258Smlf cfga_sata_ret_t sata_rcm_offline(const char *, char **, char *, cfga_flags_t); 215*1258Smlf cfga_sata_ret_t sata_rcm_online(const char *, char **, char *, cfga_flags_t); 216*1258Smlf cfga_sata_ret_t sata_rcm_remove(const char *, char **, char *, cfga_flags_t); 217*1258Smlf 218*1258Smlf 219*1258Smlf #ifdef __cplusplus 220*1258Smlf } 221*1258Smlf #endif 222*1258Smlf 223*1258Smlf #endif /* _CFGA_SATA_H */ 224