19113a79cSeschrock /* 29113a79cSeschrock * CDDL HEADER START 39113a79cSeschrock * 49113a79cSeschrock * The contents of this file are subject to the terms of the 59113a79cSeschrock * Common Development and Distribution License (the "License"). 69113a79cSeschrock * You may not use this file except in compliance with the License. 79113a79cSeschrock * 89113a79cSeschrock * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 99113a79cSeschrock * or http://www.opensolaris.org/os/licensing. 109113a79cSeschrock * See the License for the specific language governing permissions 119113a79cSeschrock * and limitations under the License. 129113a79cSeschrock * 139113a79cSeschrock * When distributing Covered Code, include this CDDL HEADER in each 149113a79cSeschrock * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 159113a79cSeschrock * If applicable, add the following below this CDDL HEADER, with the 169113a79cSeschrock * fields enclosed by brackets "[]" replaced with your own identifying 179113a79cSeschrock * information: Portions Copyright [yyyy] [name of copyright owner] 189113a79cSeschrock * 199113a79cSeschrock * CDDL HEADER END 209113a79cSeschrock */ 219113a79cSeschrock /* 22*81d9f076SRobert Johnston * Copyright 2010 Sun Microsystems, Inc. All rights reserved. 239113a79cSeschrock * Use is subject to license terms. 249113a79cSeschrock */ 259113a79cSeschrock 269113a79cSeschrock #ifndef _IPMI_IMPL_H 279113a79cSeschrock #define _IPMI_IMPL_H 289113a79cSeschrock 299113a79cSeschrock #include <stdlib.h> 30*81d9f076SRobert Johnston #include <sys/nvpair.h> 312eeaed14Srobj #include <libipmi.h> 329113a79cSeschrock 339113a79cSeschrock #ifdef __cplusplus 349113a79cSeschrock extern "C" { 359113a79cSeschrock #endif 369113a79cSeschrock 372eeaed14Srobj typedef struct ipmi_list { 382eeaed14Srobj struct ipmi_list *l_prev; 392eeaed14Srobj struct ipmi_list *l_next; 402eeaed14Srobj } ipmi_list_t; 419113a79cSeschrock 422eeaed14Srobj typedef struct ipmi_hash_link { 432eeaed14Srobj ipmi_list_t ihl_list; /* next on list of all elements */ 442eeaed14Srobj struct ipmi_hash_link *ihl_next; /* next on this bucket */ 452eeaed14Srobj } ipmi_hash_link_t; 462eeaed14Srobj 472eeaed14Srobj typedef struct ipmi_hash { 482eeaed14Srobj ipmi_handle_t *ih_handle; /* handle to library state */ 492eeaed14Srobj ipmi_hash_link_t **ih_buckets; /* array of buckets */ 502eeaed14Srobj size_t ih_nbuckets; /* number of buckets */ 512eeaed14Srobj size_t ih_nelements; /* number of elements */ 522eeaed14Srobj ipmi_list_t ih_list; /* list of all elements */ 532eeaed14Srobj size_t ih_linkoffs; /* offset of ipmi_hash_link in elem */ 542eeaed14Srobj const void *(*ih_convert)(const void *); /* key conversion function */ 552eeaed14Srobj ulong_t (*ih_compute)(const void *); /* hash computing function */ 562eeaed14Srobj int (*ih_compare)(const void *, const void *); /* compare function */ 572eeaed14Srobj } ipmi_hash_t; 589113a79cSeschrock 599113a79cSeschrock typedef struct ipmi_transport { 60*81d9f076SRobert Johnston void * (*it_open)(struct ipmi_handle *, nvlist_t *); 619113a79cSeschrock void (*it_close)(void *); 629113a79cSeschrock int (*it_send)(void *, struct ipmi_cmd *, struct ipmi_cmd *, 639113a79cSeschrock int *); 649113a79cSeschrock } ipmi_transport_t; 659113a79cSeschrock 669113a79cSeschrock struct ipmi_handle { 679113a79cSeschrock ipmi_transport_t *ih_transport; 689113a79cSeschrock void *ih_tdata; 699113a79cSeschrock ipmi_cmd_t ih_response; 709113a79cSeschrock int ih_errno; 719113a79cSeschrock uint16_t ih_reservation; 729113a79cSeschrock int ih_retries; 732eeaed14Srobj ipmi_hash_t *ih_sdr_cache; 742eeaed14Srobj uint32_t ih_sdr_ts; 752eeaed14Srobj ipmi_deviceid_t *ih_deviceid; 762eeaed14Srobj uint32_t ih_deviceid_len; 772eeaed14Srobj char *ih_firmware_rev; 789113a79cSeschrock char ih_errmsg[1024]; 799113a79cSeschrock char ih_errbuf[1024]; 802eeaed14Srobj ipmi_list_t ih_users; 812eeaed14Srobj ipmi_hash_t *ih_entities; 82283bfb4dSEric Schrock int ih_completion; 839113a79cSeschrock }; 849113a79cSeschrock 859113a79cSeschrock /* 869113a79cSeschrock * Error handling 879113a79cSeschrock */ 889113a79cSeschrock extern int ipmi_set_error(ipmi_handle_t *, int, const char *, ...); 899113a79cSeschrock 909113a79cSeschrock /* 919113a79cSeschrock * Memory allocation 929113a79cSeschrock */ 939113a79cSeschrock extern void *ipmi_alloc(ipmi_handle_t *, size_t); 949113a79cSeschrock extern void *ipmi_zalloc(ipmi_handle_t *, size_t); 959113a79cSeschrock extern void ipmi_free(ipmi_handle_t *, void *); 969113a79cSeschrock extern void *impi_realloc(ipmi_handle_t *, void *, size_t); 971af98250Seschrock extern char *ipmi_strdup(ipmi_handle_t *, const char *); 989113a79cSeschrock 999113a79cSeschrock /* 1009113a79cSeschrock * Supported transports 1019113a79cSeschrock */ 1029113a79cSeschrock extern ipmi_transport_t ipmi_transport_bmc; 103*81d9f076SRobert Johnston extern ipmi_transport_t ipmi_transport_lan; 1049113a79cSeschrock 10592ba7109Seschrock /* 1062eeaed14Srobj * Primitives for converting 1072eeaed14Srobj */ 1082eeaed14Srobj typedef struct ipmi_name_trans { 1092eeaed14Srobj int int_value; 1102eeaed14Srobj const char *int_name; 1112eeaed14Srobj } ipmi_name_trans_t; 1122eeaed14Srobj 1132eeaed14Srobj typedef struct ipmi_sensor_trans { 1142eeaed14Srobj uint8_t ist_key; 1152eeaed14Srobj uint8_t ist_value; 1162eeaed14Srobj ipmi_name_trans_t ist_mask[1]; 1172eeaed14Srobj } ipmi_sensor_trans_t; 1182eeaed14Srobj 1192eeaed14Srobj extern ipmi_name_trans_t ipmi_entity_table[]; 1202eeaed14Srobj extern ipmi_name_trans_t ipmi_sensor_type_table[]; 1212eeaed14Srobj extern ipmi_name_trans_t ipmi_reading_type_table[]; 1222eeaed14Srobj extern ipmi_name_trans_t ipmi_errno_table[]; 1232eeaed14Srobj extern ipmi_name_trans_t ipmi_threshold_state_table[]; 124825ba0f2Srobj extern ipmi_name_trans_t ipmi_units_type_table[]; 1252eeaed14Srobj extern ipmi_sensor_trans_t ipmi_reading_state_table[]; 1262eeaed14Srobj extern ipmi_sensor_trans_t ipmi_specific_state_table[]; 1272eeaed14Srobj 1282eeaed14Srobj /* 12992ba7109Seschrock * Miscellaneous routines 13092ba7109Seschrock */ 1312eeaed14Srobj extern int ipmi_sdr_init(ipmi_handle_t *); 13292ba7109Seschrock extern void ipmi_sdr_clear(ipmi_handle_t *); 1332eeaed14Srobj extern void ipmi_sdr_fini(ipmi_handle_t *); 1341af98250Seschrock extern void ipmi_user_clear(ipmi_handle_t *); 1352eeaed14Srobj extern int ipmi_entity_init(ipmi_handle_t *); 1362eeaed14Srobj extern void ipmi_entity_clear(ipmi_handle_t *); 1372eeaed14Srobj extern void ipmi_entity_fini(ipmi_handle_t *); 1382eeaed14Srobj 1392eeaed14Srobj extern int ipmi_convert_bcd(int); 1402eeaed14Srobj extern void ipmi_decode_string(uint8_t type, uint8_t len, char *data, 1412eeaed14Srobj char *buf); 1422eeaed14Srobj extern boolean_t ipmi_is_sun_ilom(ipmi_deviceid_t *); 1432eeaed14Srobj 1442eeaed14Srobj /* 1452eeaed14Srobj * List routines 1462eeaed14Srobj */ 1472eeaed14Srobj 1482eeaed14Srobj #define ipmi_list_prev(elem) ((void *)(((ipmi_list_t *)(elem))->l_prev)) 1492eeaed14Srobj #define ipmi_list_next(elem) ((void *)(((ipmi_list_t *)(elem))->l_next)) 1502eeaed14Srobj 1512eeaed14Srobj extern void ipmi_list_append(ipmi_list_t *, void *); 1522eeaed14Srobj extern void ipmi_list_prepend(ipmi_list_t *, void *); 1532eeaed14Srobj extern void ipmi_list_insert_before(ipmi_list_t *, void *, void *); 1542eeaed14Srobj extern void ipmi_list_insert_after(ipmi_list_t *, void *, void *); 1552eeaed14Srobj extern void ipmi_list_delete(ipmi_list_t *, void *); 1562eeaed14Srobj 1572eeaed14Srobj /* 1582eeaed14Srobj * Hash table routines 1592eeaed14Srobj */ 1602eeaed14Srobj 1612eeaed14Srobj extern ipmi_hash_t *ipmi_hash_create(ipmi_handle_t *, size_t, 1622eeaed14Srobj const void *(*convert)(const void *), 1632eeaed14Srobj ulong_t (*compute)(const void *), 1642eeaed14Srobj int (*compare)(const void *, const void *)); 1652eeaed14Srobj 1662eeaed14Srobj extern void ipmi_hash_destroy(ipmi_hash_t *); 1672eeaed14Srobj extern void *ipmi_hash_lookup(ipmi_hash_t *, const void *); 1682eeaed14Srobj extern void ipmi_hash_insert(ipmi_hash_t *, void *); 1692eeaed14Srobj extern void ipmi_hash_remove(ipmi_hash_t *, void *); 1702eeaed14Srobj extern size_t ipmi_hash_count(ipmi_hash_t *); 1712eeaed14Srobj 1722eeaed14Srobj extern ulong_t ipmi_hash_strhash(const void *); 1732eeaed14Srobj extern int ipmi_hash_strcmp(const void *, const void *); 1742eeaed14Srobj 1752eeaed14Srobj extern ulong_t ipmi_hash_ptrhash(const void *); 1762eeaed14Srobj extern int ipmi_hash_ptrcmp(const void *, const void *); 1772eeaed14Srobj 1782eeaed14Srobj extern void *ipmi_hash_first(ipmi_hash_t *); 1792eeaed14Srobj extern void *ipmi_hash_next(ipmi_hash_t *, void *); 18092ba7109Seschrock 1819113a79cSeschrock #ifdef __cplusplus 1829113a79cSeschrock } 1839113a79cSeschrock #endif 1849113a79cSeschrock 1859113a79cSeschrock #endif /* _IPMI_IMPL_H */ 186