/* IBM_PROLOG_BEGIN_TAG                                                   */
/* This is an automatically generated prolog.                             */
/*                                                                        */
/* bos72Q src/bos/kernel/sys/cluster.h 1.11.2.16                          */
/*                                                                        */
/* Licensed Materials - Property of IBM                                   */
/*                                                                        */
/* Restricted Materials of IBM                                            */
/*                                                                        */
/* COPYRIGHT International Business Machines Corp. 2010,2019              */
/* All Rights Reserved                                                    */
/*                                                                        */
/* US Government Users Restricted Rights - Use, duplication or            */
/* disclosure restricted by GSA ADP Schedule Contract with IBM Corp.      */
/*                                                                        */
/* IBM_PROLOG_END_TAG                                                     */
/* @(#)22       1.11.2.16  src/bos/kernel/sys/cluster.h, syscluster, bos72Q, q2019_33B4 8/9/19 13:28:40 */

#ifndef _CLUSTER_H
#define _CLUSTER_H

#include <sys/types.h>
#include <sys/ndd.h>
#include <net/if.h>
#include <lvm.h>

#ifdef __cplusplus
extern "C" {
#endif

/* for 128 bit wwid, change #if 0, to #if 1 */
#if 1
#define _128_WWID_T
#endif

typedef u_int16_t       clustid_t, *clustid_p;

#define LOCAL_CLUSTER 0x00000001
#define ALL_NODES 0xFFFF
#define ALL_CLUST 0xFFFFFFFFFFFFFFFF
#define CMD_AHAFS       1
#define _WWID_NULL      0
#define _WWID_LOCAL_CLUSTER LOCAL_CLUSTER
#define _WWID_ALL_CLUST     ALL_CLUST
#define _WWID_DEFAULT_LINK      111

/*
 * Used in conjunction with _kcluster_sendmsg. 
 */

#define ALL_SITES       0xFFFF
#define LOCAL_SITE      0xFFFE
#define REMOTE_SITES    0xFFFD

#ifdef  _128_WWID_T

#ifdef _KERNEL
typedef struct t_wwid
{
    union
    {
        uint64_t    dw[2];
        char        str[16];
    } un;
} t_wwid_t, *t_wwid_p;

typedef struct event_generation
{
    int type;
    unsigned value: 3;
    unsigned send_flag: 1;
    unsigned fam_send: 16;
    unsigned only_lnk_send: 1;
    unsigned pad: 11;
    int rc_evprod;
    void *address1;
    void *address2;
    void *address3;
    t_wwid_t *node;
    t_wwid_t *clust_id;
    t_wwid_t *site_id;
    uint16_t node16;
    uint16_t site16;
    char * additional_infop;
} event_generation_t, *event_generation_p;
#define WWID_NULL       (t_wwid_t){.un.dw[0] = _WWID_NULL, .un.dw[1] = _WWID_NULL}
#define WWID_ALL_CLUSTERS   (t_wwid_t){.un.dw[0] = _WWID_ALL_CLUST, .un.dw[1] = _WWID_ALL_CLUST}
#define WWID_LOCAL_CLUSTER  (t_wwid_t){.un.dw[0] = _WWID_LOCAL_CLUSTER, .un.dw[1] = _WWID_LOCAL_CLUSTER}
#define WWID_DEFAULT_LINK   (t_wwid_t){.un.dw[0] = _WWID_DEFAULT_LINK, .un.dw[1] = _WWID_DEFAULT_LINK}
#define WWID_IS_NULL(uuid)  ((uuid).un.dw[0] == 0 && (uuid).un.dw[1] == 0)
#define WWID_SET(uuid, d0, d1)  (uuid).un.dw[0] = (d0); (uuid).un.dw[1] = (d1)
#define WWID_CMP(s, d)      (bcmp((s).un.str, (d).un.str, sizeof(t_wwid_t)))
#define WWID_CPY(s, d)      (bcopy((s).un.str, (d).un.str, sizeof(t_wwid_t)))
#define WWID_UNKNOWN        (t_wwid_t){.un.dw[0] = 0x000055554944105fLL, .un.dw[1] = 0x80554e4b4e4f574eLL}

#else /* !_KERNEL */

#include <uuid.h>
typedef uuid_t t_wwid_t, *t_wwid_p;
#define WWID_NULL       UUID_NIL
#define WWID_ALL_CLUSTERS   force a compilation error
/* NOT a valid UUID.  Do not use with uuid.h APIs. */
#define WWID_LOCAL_CLUSTER  (t_wwid_t){0x00000000, 0x0000, 0x0001, 0x00, 0x00, {0x00, 0x00, 0x00, 0x00, 0x00, 0x01}}
/* NOT a valid UUID.  Do not use with uuid.h APIs. */
#define WWID_DEFAULT_LINK   (t_wwid_t){0x00000000, 0x0000, 0x006F, 0x00, 0x00, {0x00, 0x00, 0x00, 0x00, 0x00, 0x6F}}
#define WWID_IS_NULL(uuid)  force a compilation error
#define WWID_SET(uuid, d0, d1)  force a compilation error
#define WWID_CMP(s, d)      force a compilation error
#define WWID_CPY(s, d)      force a compilation error

#endif /* _KERNEL */


#else /* !_128_WWID_T */

#ifdef _KERNEL

typedef struct t_wwid
{
    union
    {
        uint64_t    dw[1];
        char        str[8];
    } un;
} t_wwid_t, *t_wwid_p;
#define WWID_NULL       (t_wwid_t){.un.dw[0] = _WWID_NULL}
#define WWID_ALL_CLUSTERS   (t_wwid_t){.un.dw[0] = _WWID_ALL_CLUST}
#define WWID_LOCAL_CLUSTER  (t_wwid_t){.un.dw[0] = _WWID_LOCAL_CLUSTER}
#define WWID_DEFAULT_LINK   (t_wwid_t){.un.dw[0] = _WWID_DEFAULT_LINK}
#define WWID_IS_NULL(uuid)  ((uuid).un.dw[0] == 0)
#define WWID_SET(uuid, d0, d1)  (uuid).un.dw[0] = (d1)
#define WWID_CMP(s, d)      (bcmp((s).un.str, (d).un.str, sizeof(t_wwid_t)))
#define WWID_CPY(s, d)      (bcopy((s).un.str, (d).un.str, sizeof(t_wwid_t)))
#else /* !_KERNEL */
typedef uint64_t        t_wwid_t, *t_wwid_p;
#define WWID_NULL       (t_wwid_t)_WWID_NULL
#define WWID_ALL_CLUSTERS   (t_wwid_t)_WWID_ALL_CLUST
#define WWID_LOCAL_CLUSTER  (t_wwid_t)_WWID_LOCAL_CLUSTER
#define WWID_DEFAULT_LINK   (t_wwid_t)_WWID_DEFAULT_LINK
#define WWID_IS_NULL(uuid)  ((uuid) == 0)
#define WWID_SET(uuid, d0, d1)  ((uuid) = (d1))
#define WWID_CMP(s, d)      ((s) != (d))
#define WWID_CPY(s, d)      ((d) = (s))

#endif /* _KERNEL */

#endif /* _128_WWID_T */

/* System Calls */
clustid_t  get_clusterid(void);
int incluster(int);
int cluster_check(void);

#ifdef _KERNEL
/* definitions for callouts */

extern int cluster_active(void);
extern int cluster_seen(void);
extern int set_cluster(int, t_wwid_t *, t_wwid_t *,  u_int16_t);

/*
 * FFDC struct used by kernext. Only used to pass and map to cl_message_header
 * to send to clusterconf.
 */
#define FFDC_FROM_FILE_BUFLEN   32
#define NODE_ARRAYS  20
typedef struct ffdc
{
    int             notify;
    uint16_t        by_me;
    uint16_t        by_comp;
    tid_t           wait_here;
    Simple_lock     obj_lock;     /* To serialize notify */
    uint64_t        seqno;
    uint32_t	    rc[NODE_ARRAYS];
    uint16_t        rc_count;
    tid_t           event_word;
    uint16_t        priority;
    uint16_t        verbosity;
    uint32_t        lineno;
    char            file[FFDC_FROM_FILE_BUFLEN];
    uint16_t        subtype;
    uint16_t        version;
    clustid_t       initiator;
    uint16_t        staged;
    uint16_t        correlator;
    uint16_t        repo_down;
    uint16_t        pad2[10];

} ffdc_t, *ffdc_p;
extern int cluster_notify_clusterconf(char *, ffdc_p cl_ffdc);

typedef struct kif_args_reset
{
    uint    cmd;
    struct  ifnet   *ifp;
    struct  ifaddr  *ifa;
} kif_args_reset_t, *kif_args_reset_p;

typedef struct kif_args_phy_link_state
{
    uint    flag;
    char    ndd_name[NDD_MAXNAMELEN];
} kif_args_phy_link_state_t, *kif_args_phy_link_state_p;


typedef struct klvmstat_args
{
    unsigned        status_vg: 2;
    unsigned        pad: 30; /* Pad to align the struct*/
    char            vg_name[LVM_NAMESIZ];
    struct unique_id vg_id;
    struct unique_id pv_id;
    char      name[LVM_NAMESIZ];
} klvmstat_args_t, *klvmstat_args_p;

enum
{
    NODEMON,
    ADDRMON,
    INTERFACEMON,
    CONNECTMON,
    NODELISTMON,
    CLDISKLISTMON,
    DISKSTATE_MON,
    VGSTATE_MON,
    SITEMON,
    REP_DISKSTATE_MON,
    CL_DISKSTATE_MON,
    CAPMON,
    HOSTNAMEMON,
    SFWMON
};

#define IS_CLUSTER_AWARE    (v.v_cluster_aware ^ 1)

#endif /*_KERNEL */

#ifdef __cplusplus
}
#endif

#endif /* _CLUSTER_H */
