#ifndef _FCAL_LEDS_H
#define _FCAL_LEDS_H
#include <picl.h>
#include <picltree.h>
#include <picldefs.h>
#ifdef __cplusplus
extern "C" {
#endif
#define SYSLOG syslog
#define EM_CANT_OPEN \
gettext("SUNW_fcal_leds: open fail: %s\n")
#define EM_NONALF_TOK \
gettext("SUNW_fcal_leds: line %d token begins non-alpha\n")
#define EM_LONG_TOK \
gettext("SUNW_fcal_leds: line %d token too long\n")
#define EM_UNKN_TOK \
gettext("SUNW_fcal_leds: line %d unknown token\n")
#define EM_INVAL_TOK \
gettext("SUNW_fcal_leds: line %d invalid token at start of line\n")
#define EM_NOCOLON \
gettext("SUNW_fcal_leds: line %d leading token not followed by ':'\n")
#define EM_NOVERS \
gettext("SUNW_fcal_leds: first token not VERSION\n")
#define EM_NUM_TERM \
gettext("SUNW_fcal_leds: invalid number terminator\n")
#define EM_LOGIC_LVL \
gettext("SUNW_fcal_leds: logic level specified as neither 0 nor 1\n")
#define EM_NOTPOS \
gettext("SUNW_fcal_leds: numeric field greater than 0 expected\n")
#define EM_DISK_RANGE \
gettext("SUNW_fcal_leds: disk number out of range\n")
#define EM_NDISKS_DBL \
gettext("SUNW_fcal_leds: number of disks defined twice\n")
#define EM_NO_DISKS \
gettext("SUNW_fcal_leds: no disks defined\n")
#define EM_VER_FRMT \
gettext("SUNW_fcal_leds: format error in VERSION string\n")
#define EM_WRNGVER \
gettext("SUNW_fcal_leds: config version %d.%d not supported\n")
#define EM_REL_PATH \
gettext("SUNW_fcal_leds: path names must be absolute\n")
#define EM_ERRLINE \
gettext("SUNW_fcal_leds: error on line %d\n")
#define EM_NO_LED_PROP \
gettext("SUNW_fcal_leds: LED property name missing\n")
#define EM_PROP_TERM \
gettext("SUNW_fcal_leds: expected comma (',') after property name\n")
#define EM_STR_NOT_SET \
gettext("SUNW_fcal_leds: %s not defined")
#define EM_I2C_GET_PORT \
gettext("SUNW_fcal_leds: I2C_GET_PORT: %s\n")
#define EM_DI_INIT_FAIL \
gettext("SUNW_fcal_leds: di_init failed: %s\n")
#define EM_THREAD_CREATE_FAILED \
gettext("SUNW_fcal_leds: pthread_create() call failed: %s\n")
#define EM_MUTEX_FAIL \
gettext("SUNW_fcal_leds: pthread_mutex_lock returned: %s\n")
#define EM_CONDWAITFAIL \
gettext("SUNW_fcal_leds: pthread_cond_wait returned: %s\n")
#define EM_SPURIOUS_FP \
gettext("SUNW_fcal_leds: deleting spurious PICL fp node\n")
#define EM_NO_FP_NODE \
gettext( \
"SUNW_fcal_leds: cannot get PICL disk node for hot plug disk %d\n")
#define EM_POLL_FAIL \
gettext("SUNW_fcal_leds: poll() returned: %s, no more timed events\n")
#define FCAL_LEDS_CONF_FILE "fcal_leds.conf"
#define HW_PROP_TARGET "target"
#define HW_PROP_PORT "port-wwn"
#define FCAL_PICL_DISK_UNIT "disk-unit"
#define FCAL_PICL_REF "_"
#define FCAL_PICL_PROP_BUS_ADDR "bus-addr"
#define FCAL_PICL_PROP_TARGET "target"
#define FCAL_PICL_LED_REF FCAL_PICL_REF PICL_CLASS_LED FCAL_PICL_REF
#define FCAL_PICL_BLOCK_REF FCAL_PICL_REF PICL_CLASS_BLOCK FCAL_PICL_REF
#define FCAL_PICL_LED_ON "on"
#define FCAL_PICL_LED_OFF "off"
#define FCAL_PICL_LED_TEST "led test"
#define MAX_LEN_LED_STATE 9
#define MAX_LEN_UNIT_ADDRESS 34
#define FCAL_DEVTABLE_NCOLS 2
#define FCAL_LED_CNT 3
#define I2C_IOCTL_FAIL (-1)
#define I2C_IOCTL_INIT (-2)
#define MINORS_UNKNOWN (-1)
#define NO_MINORS 0
#define HAS_MINORS 1
#define FCAL_EV_POLL 1
#define FCAL_EV_CONFIG 2
#define DFLT_SLOW_POLL 59
#define DFLT_FAST_POLL 2
#define DFLT_RELAX_TIME 300
#define DFLT_TEST_TIME 10
typedef enum token {
NO_TOKEN,
TOKEN_ERROR,
FCAL_VERSION,
LED_PROPS_START,
FCAL_REMOK_LED,
FCAL_FAULT_LED,
FCAL_READY_LED,
LED_PROPS_END,
LINE_DEFS,
FCAL_LEDS_BOARD,
FCAL_STATUS_BOARD,
FCAL_DISK_DRIVER,
FCAL_N_DISKS,
FCAL_ASSERT_PRESENT,
FCAL_ASSERT_FAULT,
FCAL_LED_ON,
FCAL_DISK_PRESENT,
FCAL_DISK_FAULT,
FCAL_LED_ID,
FCAL_SLOW_POLL,
FCAL_FAST_POLL,
FCAL_RELAX_INTERVAL,
FCAL_TEST_INTERVAL,
FCAL_DISK_PARENT,
FCAL_UNIT_PARENT,
FCAL_LED_NODES
} token_t;
typedef enum led_state_enum {
LED_STATE_OFF,
LED_STATE_ON,
LED_STATE_TEST
} led_state_t;
typedef char *str;
typedef const char *cstr;
typedef struct led_dtls {
int ver_maj;
int ver_min;
cstr fcal_leds;
cstr fcal_status;
cstr fcal_driver;
int n_disks;
int *presence;
int *faults;
int *disk_detected;
int *disk_ready;
int *disk_prev;
volatile int *led_test_end;
boolean_t *picl_retry;
uchar_t **disk_port;
int assert_presence;
int assert_fault;
int assert_led_on;
uint_t *led_addr[FCAL_LED_CNT];
led_state_t *led_state[FCAL_LED_CNT];
boolean_t led_retry;
volatile boolean_t polling;
volatile int fast_poll_end;
int fast_poll;
int slow_poll_ticks;
int relax_time_ticks;
int led_test_time;
cstr fcal_disk_parent;
cstr disk_unit_parent;
cstr disk_led_nodes;
} led_dtls_t;
typedef int (*actfun_t)(str *p_str, led_dtls_t *dtls);
typedef struct lookup {
token_t tok;
cstr tok_str;
actfun_t action;
} lookup_t;
extern led_dtls_t *g_led_dtls;
extern pthread_cond_t g_cv;
extern pthread_cond_t g_cv_ack;
extern pthread_mutex_t g_mutex;
extern volatile int g_event_flag;
extern volatile boolean_t g_finish_now;
extern volatile boolean_t g_leds_thread_ack;
extern volatile boolean_t g_poll_thread_ack;
char *mystrerror(int err);
void *fcal_leds_thread(void *args);
int fc_led_parse(FILE *fp, led_dtls_t **p_dtls);
void free_led_dtls(led_dtls_t *dtls);
int find_disk_slot(led_dtls_t *dtls, int disk, picl_nodehdl_t *nodeh);
void delete_disk_unit(led_dtls_t *dtls, int disk);
boolean_t is_led_test(led_dtls_t *dtls);
int create_Device_table(picl_prophdl_t *tbl_h, picl_prophdl_t *tableh);
void clr_led(int diskNo, token_t led_tok, led_dtls_t *dtls);
#ifdef __cplusplus
}
#endif
#endif