void ohoi_entity_event(enum ipmi_update_e op, ipmi_domain_t *domain, ipmi_entity_t *entity, void *cb_data) { struct oh_handler_state *handler = cb_data; if (op == IPMI_ADDED) { add_entity_event(entity, handler); dbg("Entity added: %d.%d", ipmi_entity_get_entity_id(entity), ipmi_entity_get_entity_instance(entity)); ipmi_entity_add_hot_swap_handler(entity, ohoi_hot_swap_cb, cb_data); } else if (op == IPMI_DELETED) { /* we need to remove_entity */ dbg("Entity deleted: %d.%d", ipmi_entity_get_entity_id(entity), ipmi_entity_get_entity_instance(entity)); } else if (op == IPMI_CHANGED) { add_entity_event(entity, handler); dbg("Entity changed: %d.%d", ipmi_entity_get_entity_id(entity), ipmi_entity_get_entity_instance(entity)); } else { dbg("Entity: Unknow change?!"); } }
static void sensor_change(enum ipmi_update_e op, ipmi_entity_t *ent, ipmi_sensor_t *sensor, void *cb_data) { int id, instance, rv; char name[50]; id = ipmi_entity_get_entity_id(ent); instance = ipmi_entity_get_entity_instance(ent); ipmi_sensor_get_id(sensor, name, 50); if (op == IPMI_ADDED) { if (!strncmp(name, sname, 15)) { int val; val = ipmi_sensor_get_hysteresis_support(sensor); if (val == IPMI_HYSTERESIS_SUPPORT_SETTABLE) { printf("setting %s 's hysteresis...\n", name); rv = ipmi_sensor_set_hysteresis(sensor, 1, 1, set_data, &done); if (rv) printf("ipmi_sensor_set_hysteresis return :%d\n", rv); }else { printf("sensor don't support hysteresis set capability\n"); } } } }
static void get_entity_event(ipmi_entity_t *entity, SaHpiRptEntryT *entry, void *cb_data) { SaHpiEntityPathT entity_ep; struct ohoi_handler *ipmi_handler = cb_data; entry->ResourceInfo.ResourceRev = 0; entry->ResourceInfo.SpecificVer = 0; entry->ResourceInfo.DeviceSupport = 0; entry->ResourceInfo.ManufacturerId = 0; entry->ResourceInfo.ProductId = 0; entry->ResourceInfo.FirmwareMajorRev = 0; entry->ResourceInfo.FirmwareMinorRev = 0; entry->ResourceInfo.AuxFirmwareRev = 0; entry->ResourceEntity.Entry[0].EntityType = ipmi_entity_get_entity_id(entity); entry->ResourceEntity.Entry[0].EntityLocation = ipmi_entity_get_entity_instance(entity); entry->ResourceEntity.Entry[1].EntityType = SAHPI_ENT_ROOT; entry->ResourceEntity.Entry[1].EntityLocation = 0; /* let's append entity_root from config */ string2entitypath(ipmi_handler->entity_root, &entity_ep); ep_concat(&entry->ResourceEntity, &entity_ep); entry->EntryId = 0; entry->ResourceId = oh_uid_from_entity_path(&entry->ResourceEntity); entry->ResourceCapabilities = SAHPI_CAPABILITY_RESOURCE; if (ipmi_entity_hot_swappable(entity)) { entry->ResourceCapabilities |= SAHPI_CAPABILITY_MANAGED_HOTSWAP | SAHPI_CAPABILITY_FRU; } if(ipmi_entity_get_is_fru(entity)) { entry->ResourceCapabilities |= SAHPI_CAPABILITY_FRU | SAHPI_CAPABILITY_INVENTORY_DATA; } entry->ResourceSeverity = SAHPI_OK; #if 0 entry->DomainId = 0; #endif entry->ResourceTag.DataType = SAHPI_TL_TYPE_ASCII6; entry->ResourceTag.Language = SAHPI_LANG_ENGLISH; entry->ResourceTag.DataLength = (SaHpiUint32T) ipmi_entity_get_id_length(entity); ipmi_entity_get_id(entity, entry->ResourceTag.Data, SAHPI_MAX_TEXT_BUFFER_LENGTH); if ((strlen(entry->ResourceTag.Data) == 0) || (!strcmp(entry->ResourceTag.Data, "invalid"))) { char *str; str = ipmi_entity_get_entity_id_string(entity); memcpy(entry->ResourceTag.Data, str, strlen(str) + 1); } }
/* callback function invoked from OpenIPMI */ static void got_discrete_states(ipmi_sensor_t *sensor, int err, ipmi_states_t *states, void *cb_data) { const char *__function_name = "got_discrete_states"; char id_str[2 * IPMI_SENSOR_ID_SZ + 1]; int id, i, val, ret, is_state_set; ipmi_entity_t *ent; zbx_ipmi_host_t *h = cb_data; zbx_ipmi_sensor_t *s; zabbix_log(LOG_LEVEL_DEBUG, "In %s()", __function_name); s = get_ipmi_sensor(h, sensor); if (NULL == s) { THIS_SHOULD_NEVER_HAPPEN; h->err = zbx_strdup(h->err, "fatal error"); h->ret = NOTSUPPORTED; goto out; } if (0 != err) { h->err = zbx_dsprintf(h->err, "error 0x%x while reading a discrete sensor %s@[%s]:%d", err, sensor_id_to_str(id_str, sizeof(id_str), s->id, s->id_type, s->id_sz), h->ip, h->port); h->ret = NOTSUPPORTED; goto out; } ent = ipmi_sensor_get_entity(sensor); id = ipmi_entity_get_entity_id(ent); /* Discrete values are 16-bit. We're storing them into a 64-bit uint. */ #define MAX_DISCRETE_STATES 15 s->value.discrete = 0; for (i = 0; i < MAX_DISCRETE_STATES; i++) { ret = ipmi_sensor_discrete_event_readable(sensor, i, &val); if (0 != ret || 0 == val) continue; is_state_set = ipmi_is_state_set(states, i); zabbix_log(LOG_LEVEL_DEBUG, "State [%s | %s | %s | %s | state %d value is %d]", sensor_id_to_str(id_str, sizeof(id_str), s->id, s->id_type, s->id_sz), ipmi_get_entity_id_string(id), ipmi_sensor_get_sensor_type_string(sensor), ipmi_sensor_get_event_reading_type_string(sensor), i, is_state_set); if (0 != is_state_set) s->value.discrete |= 1 << i; } #undef MAX_DISCRETE_STATES out: h->done = 1; zabbix_log(LOG_LEVEL_DEBUG, "End of %s():%s", __function_name, zbx_result_string(h->ret)); }
static void change_entity(struct oh_handler_state *handler, ipmi_entity_t *entity) { struct ohoi_handler *ipmi_handler = handler->data; ipmi_entity_id_t entity_id = ipmi_entity_convert_to_id(entity); SaHpiRptEntryT *rpt; SaHpiResourceIdT slot_id; struct ohoi_resource_info *s_r_info; struct ohoi_resource_info *res_info; unsigned int dummy; rpt = ohoi_get_resource_by_entityid(handler->rptcache, &entity_id); if (rpt == NULL) { dbg("Couldn't find out resource by entity %d.%.d.%d.%d %s", ipmi_entity_get_entity_id(entity), ipmi_entity_get_entity_instance(entity), ipmi_entity_get_device_channel(entity), ipmi_entity_get_device_address(entity), ipmi_entity_get_entity_id_string(entity)); trace_ipmi_entity("CAN NOT CHANGE RESOURCE. NO RPT", 0, entity); return; } res_info = oh_get_resource_data(handler->rptcache, rpt->ResourceId); update_resource_capabilities(entity, rpt, res_info); entity_rpt_set_updated(res_info, ipmi_handler); if (ipmi_handler->d_type != IPMI_DOMAIN_TYPE_ATCA) { return; } if (ipmi_entity_get_physical_slot_num(entity, &dummy)) { // entity does not have a slot return; } #if 0 if (ipmi_entity_get_type(entity) == IPMI_ENTITY_MC) { if (!(res_info->type & OHOI_MC_RESET_CONTROL_CREATED)) { ohoi_create_fru_mc_reset_control(handler, rpt->ResourceId); } if (!(res_info->type & OHOI_MC_IPMB0_CONTROL_CREATED) && (res_info->max_ipmb0_link >= 0)) { ohoi_create_ipmb0_controls(handler, entity, (SaHpiCtrlStateAnalogT)res_info->max_ipmb0_link); } } #endif slot_id = ohoi_get_parent_id(rpt); s_r_info = oh_get_resource_data(handler->rptcache, slot_id); if (s_r_info && (s_r_info->type & OHOI_RESOURCE_SLOT)) { s_r_info->u.slot.devid = ipmi_entity_get_fru_device_id(entity); s_r_info->u.slot.addr = ipmi_entity_get_device_address(entity); } else { dbg("No res_info(%p) for slot %d", s_r_info, slot_id); } }
static void trace_ipmi_fru(char *str, ipmi_entity_t *entity) { if (!getenv("OHOI_TRACE_FRU") && !IHOI_TRACE_ALL) { return; } fprintf(stderr, "*** FRU %s: for (%d,%d,%d,%d) %s\n", str, ipmi_entity_get_entity_id(entity), ipmi_entity_get_entity_instance(entity), ipmi_entity_get_device_channel(entity), ipmi_entity_get_device_address(entity), ipmi_entity_get_entity_id_string(entity)); }
static void trace_ipmi_entity(char *str, int inst, ipmi_entity_t *entity) { if (!getenv("OHOI_TRACE_ENTITY") && !IHOI_TRACE_ALL) { return; } char *type; char logical[24]; logical[0] = 0; switch (ipmi_entity_get_type(entity)) { case IPMI_ENTITY_UNKNOWN: type = "UNKNOWN"; break; case IPMI_ENTITY_MC: type = "MC"; break; case IPMI_ENTITY_FRU: type = "FRU"; if (ipmi_entity_get_is_logical_fru(entity)) { snprintf(logical, 24, " Logical (%d) ", ipmi_entity_get_fru_device_id(entity)); } else { snprintf(logical, 24, " NonLogic(%d) ", ipmi_entity_get_fru_device_id(entity)); } break; case IPMI_ENTITY_GENERIC: type = "GENERIC"; break; case IPMI_ENTITY_EAR: type = "EAR"; break; case IPMI_ENTITY_DREAR: type = "DREAR"; break; default : type = "INVALID"; break; } fprintf(stderr, "*** Entity %s %s %s: %d (%d.%d.%d.%d) (%s) entity = %p\n", type, logical, str, inst, ipmi_entity_get_entity_id(entity), ipmi_entity_get_entity_instance(entity), ipmi_entity_get_device_channel(entity), ipmi_entity_get_device_address(entity), ipmi_entity_get_entity_id_string(entity), entity); }
static void update_resource_capabilities(ipmi_entity_t *entity, SaHpiRptEntryT *entry, struct ohoi_resource_info *res_info) { if (ipmi_entity_supports_managed_hot_swap(entity)) { trace_ipmi("Entity is hot swapable"); entry->ResourceCapabilities |= SAHPI_CAPABILITY_MANAGED_HOTSWAP; /* if entity supports managed hot swap * check if it has indicator */ /* we need only return value from function */ if (!ipmi_entity_get_hot_swap_indicator(entity, NULL, NULL)) { trace_ipmi("setting SAHPI_HS_CAPABILITY_INDICATOR_SUPPORTED"); entry->HotSwapCapabilities |= SAHPI_HS_CAPABILITY_INDICATOR_SUPPORTED; } } else { entry->ResourceCapabilities &= ~SAHPI_CAPABILITY_MANAGED_HOTSWAP; entry->HotSwapCapabilities &= ~SAHPI_HS_CAPABILITY_INDICATOR_SUPPORTED; } /* OpenIPMI used ipmi_entity_hot_swappable to indicate it's FRU * do not use ipmi_entity_get_is_fru() * it's used only for checking if entity has FRU data */ if ((ipmi_entity_get_entity_id(entity) != 0xf0) || (ipmi_entity_get_device_channel(entity) != 0) || (ipmi_entity_get_device_address(entity) != 32)) { // this is not virtual shelf manager if(ipmi_entity_hot_swappable(entity)) { trace_ipmi("Entity supports simplified hotswap"); entry->ResourceCapabilities |= SAHPI_CAPABILITY_FRU; } else { entry->ResourceCapabilities &= ~SAHPI_CAPABILITY_FRU; } } ipmi_mcid_t mc_id; if (ipmi_entity_get_mc_id(entity, &mc_id) == 0) { res_info->u.entity.mc_id = mc_id; res_info->type |= OHOI_RESOURCE_MC; } else { res_info->type &= ~OHOI_RESOURCE_MC; } }
static void add_parent_ep(ipmi_entity_t *ent, ipmi_entity_t *parent, void *cb_data) { struct add_parent_ep_s *info = cb_data; ipmi_entity_id_t parent_id = ipmi_entity_convert_to_id(parent); SaHpiRptEntryT *pr_rpt; pr_rpt = ohoi_get_resource_by_entityid(info->handler->rptcache, &parent_id); if (pr_rpt == NULL) { dbg(" Couldn't find out res-info for parent: %d.%d.%d.%d %s", ipmi_entity_get_entity_id(parent), ipmi_entity_get_entity_instance(parent), ipmi_entity_get_device_channel(parent), ipmi_entity_get_device_address(parent), ipmi_entity_get_entity_id_string(parent)); trace_ipmi_entity("CAN NOT FIND OUT PARENT. NO RES_INFO", 0, parent); return; } append_parent_epath(info->entry, pr_rpt); return; }
static int ignore_sensor(ipmi_sensor_t *sensor) { ipmi_entity_t *ent; if (ipmi_sensor_get_ignore_if_no_entity(sensor)) { dbg("ignore if no entity"); return 0; } ent = ipmi_sensor_get_entity(sensor); if (ent == NULL) { dbg("ipmi_sensor_get_entity = NULL"); return 1; } if (!ipmi_entity_is_present(ent)) { dbg("!ipmi_entity_is_present. (%d,%d,%d,%d) %s", ipmi_entity_get_entity_id(ent), ipmi_entity_get_entity_instance(ent), ipmi_entity_get_device_channel(ent), ipmi_entity_get_device_address(ent), ipmi_entity_get_entity_id_string(ent)); return 0; } return 0; }
/* Whenever the status of an entity changes, the function is called When a new entity is created, we search all sensors that belong to the entity */ static void entity_change(enum ipmi_update_e op, ipmi_domain_t *domain, ipmi_entity_t *entity, void *cb_data) { int rv; int id, instance; id = ipmi_entity_get_entity_id(entity); instance = ipmi_entity_get_entity_instance(entity); if (op == IPMI_ADDED) { printf("Entity added: %d.%d\n", id, instance); /* Register callback so that when the status of a sensor changes, sensor_change is called */ rv = ipmi_entity_set_sensor_update_handler(entity, sensor_change, entity); if (rv) { printf("ipmi_entity_set_sensor_update_handler: 0x%x", rv); exit(1); } } }
static void add_entity_event(ipmi_domain_t *domain, ipmi_entity_t *entity, struct oh_handler_state *handler) { struct ohoi_handler *ipmi_handler = handler->data; struct ohoi_resource_info *ohoi_res_info; SaHpiRptEntryT entry; int rv; int inst; inst = ipmi_entity_get_entity_instance(entity); if (inst >= 96) { inst -= 96; } memset(&entry, 0, sizeof (entry)); ohoi_res_info = malloc(sizeof(*ohoi_res_info)); if (!ohoi_res_info) { dbg("Out of memory"); trace_ipmi_entity("CAN NOT ADD ENTITY. OUT OF MEMORY", inst, entity); return; } memset(ohoi_res_info, 0, sizeof (*ohoi_res_info)); ohoi_res_info->max_ipmb0_link = -1; ohoi_res_info->type = OHOI_RESOURCE_ENTITY; ohoi_res_info->u.entity.entity_id= ipmi_entity_convert_to_id(entity); get_entity_event(entity, ohoi_res_info, &entry, handler); rv = oh_add_resource(handler->rptcache, &entry, ohoi_res_info, 1); if (rv) { dbg("oh_add_resource failed for %d = %s\n", entry.ResourceId, oh_lookup_error(rv)); trace_ipmi_entity("CAN NOT ADD ENTITY. ADD RESOURCE FAILED", inst, entity); return; } if (!IS_ATCA(ipmi_domain_get_type(domain))) { return; } if (entry.ResourceEntity.Entry[0].EntityType == SAHPI_ENT_SYSTEM_CHASSIS) { ipmi_handler->atca_shelf_id = entry.ResourceId; } if (ipmi_entity_get_type(entity) == IPMI_ENTITY_MC) { ohoi_create_fru_mc_reset_control(handler, entry.ResourceId); } switch (ipmi_entity_get_entity_id(entity)) { case 0xf0: // Shelf Manager if (ipmi_entity_get_device_address(entity) == 0x20) { // this is virtual shelf manager ipmi_handler->atca_vshm_id = entry.ResourceId; create_atca_virt_shmgr_rdrs(handler); // virtual shelf manager always present entity_rpt_set_presence(ohoi_res_info, handler->data, 1); } break; default: break; } }
static void get_entity_event(ipmi_entity_t *entity, struct ohoi_resource_info *ohoi_res_info, SaHpiRptEntryT *entry, void *cb_data) { SaHpiEntityPathT entity_ep; struct oh_handler_state *handler = cb_data; struct ohoi_handler *ipmi_handler = handler->data; // int rv; const char *str; int entity_id = ipmi_entity_get_entity_id(entity); int entity_instance = ipmi_entity_get_entity_instance(entity); SaHpiEntityPathT ep; unsigned char slot_n_str[8]; int no_slot = 1; unsigned int slot_val = 0; init_rpt(entry); entry->ResourceEntity.Entry[0].EntityType = entity_id; if(entity_instance >= 96) { entry->ResourceEntity.Entry[0].EntityLocation = entity_instance- 96; } else { entry->ResourceEntity.Entry[0].EntityLocation = entity_instance; } entry->ResourceEntity.Entry[1].EntityType = SAHPI_ENT_ROOT; entry->ResourceEntity.Entry[1].EntityLocation = 0; update_resource_capabilities(entity, entry, ohoi_res_info); if (entry->ResourceEntity.Entry[0].EntityType == SAHPI_ENT_SYSTEM_BOARD) { /* This is the BMC entry, so we need to add watchdog. */ if (!ipmi_handler->islan) { // no watchdog commands over lan entry->ResourceCapabilities |= SAHPI_CAPABILITY_WATCHDOG; } } if (ipmi_handler->d_type != IPMI_DOMAIN_TYPE_ATCA) { goto no_atca; } if (entry->ResourceEntity.Entry[0].EntityType == SAHPI_ENT_SYSTEM_CHASSIS) { entry->ResourceEntity.Entry[0].EntityType = SAHPI_ENT_ROOT; entry->ResourceEntity.Entry[0].EntityLocation = 0; oh_append_textbuffer(&entry->ResourceTag, "Shelf"); } /* Since OpenIPMI does not hand us a more descriptive tag which is an SDR issue in the chassis really, we'll over-ride it here until things change */ /* * If entity has a slot try to get it's number */ no_slot = ipmi_entity_get_physical_slot_num(entity, &slot_val); trace_ipmi_entity(" SLOT presence for Entity", no_slot ? 0 : 1, entity); if (no_slot) { /* will use device address */ goto end_of_slot; } { // create Resource for phisical blade slot if it hasn't already been created SaHpiEntityPathT rootep; SaHpiRptEntryT *rpt; struct ohoi_resource_info *s_r_info; char *name; switch (entity_id) { case 0xa0: // Blade ep.Entry[0].EntityType = SAHPI_ENT_PHYSICAL_SLOT; name = "Blade Slot "; break; case 0xf0: // Shelf Manager ep.Entry[0].EntityType = ATCAHPI_ENT_SHELF_MANAGER_SLOT; name = "Shelf Manager Slot "; break; case 0xf1: // Filtration Unit ep.Entry[0].EntityType = ATCAHPI_ENT_FAN_FILTER_TRAY_SLOT; name = "Fan Filter Tray Slot "; break; case 0x0a: // PEM ep.Entry[0].EntityType = ATCAHPI_ENT_POWER_ENTRY_MODULE_SLOT; name = "PEM Slot "; break; case 0xf2: // Shelf FRU ep.Entry[0].EntityType = ATCAHPI_ENT_SHELF_FRU_DEVICE_SLOT; name = "Shelf FRU Device Slot "; break; case 0x1e: // Fan Tray ep.Entry[0].EntityType = ATCAHPI_ENT_FAN_TRAY_SLOT; name = "Fan Tray Slot "; break; case 0xc0: // RTM ep.Entry[0].EntityType = ATCAHPI_ENT_RTM_SLOT; name = "RTM Slot "; break; default: no_slot = 1; goto end_of_slot; } ep.Entry[0].EntityLocation = slot_val; ep.Entry[1].EntityType = SAHPI_ENT_ROOT; ep.Entry[1].EntityLocation = 0; oh_encode_entitypath(ipmi_handler->entity_root, &rootep); oh_concat_ep(&ep, &rootep); rpt = oh_get_resource_by_ep(handler->rptcache, &ep); if (rpt == NULL) { // create rpt for slot SaHpiRptEntryT srpt; int i; init_rpt(&srpt); for (i = 0; i < SAHPI_MAX_ENTITY_PATH; i ++) { srpt.ResourceEntity.Entry[i].EntityLocation = ep.Entry[i].EntityLocation; srpt.ResourceEntity.Entry[i].EntityType = ep.Entry[i].EntityType; if (ep.Entry[i].EntityType == SAHPI_ENT_ROOT) { break; } } oh_append_textbuffer(&srpt.ResourceTag, name); snprintf((char *)slot_n_str, 8, "%d", slot_val); oh_append_textbuffer(&srpt.ResourceTag, (char *)slot_n_str); srpt.ResourceId = oh_uid_from_entity_path(&srpt.ResourceEntity); s_r_info = malloc(sizeof(*ohoi_res_info)); if (s_r_info == NULL) { dbg("Out of Memory"); goto end_of_slot; } memset(s_r_info, 0, sizeof(*ohoi_res_info)); s_r_info->type = OHOI_RESOURCE_SLOT; s_r_info->u.slot.devid = ipmi_entity_get_fru_device_id(entity); s_r_info->u.slot.addr = ipmi_entity_get_device_address(entity); s_r_info->u.slot.entity_id = ipmi_entity_convert_to_id(entity); if (oh_add_resource(handler->rptcache, &srpt, s_r_info, 1)) { dbg("couldn't add resource for slot %d", ep.Entry[0].EntityLocation); trace_ipmi_entity("COULD NOT CREATE SLOT for ", 0, entity); no_slot = 1; g_free(s_r_info); goto end_of_slot; } trace_ipmi_entity("CREATE SLOT for ", 0, entity); if (ipmi_entity_get_entity_id(entity) == 0xf0) { // this is not virtual shelf manager ipmi_handler->shmc_num++; } entity_rpt_set_presence(s_r_info, ipmi_handler, 1); rpt = oh_get_resource_by_ep(handler->rptcache, &ep); atca_create_slot_rdrs(handler, srpt.ResourceId); } else { s_r_info = oh_get_resource_data(handler->rptcache, rpt->ResourceId); if (s_r_info && (s_r_info->type & OHOI_RESOURCE_SLOT)) { s_r_info->u.slot.devid = ipmi_entity_get_fru_device_id(entity); s_r_info->u.slot.addr = ipmi_entity_get_device_address(entity); s_r_info->u.slot.entity_id = ipmi_entity_convert_to_id(entity); } else { dbg("Internal error. s_r_info == %p", s_r_info); } } } end_of_slot: if ((entity_id == 0xa0) && (entity_instance >= 96)) { // ATCA Board if ((ipmi_entity_get_device_address(entity) == 130) || (ipmi_entity_get_device_address(entity) == 132)) { oh_append_textbuffer(&entry->ResourceTag, "Switch "); entry->ResourceEntity.Entry[0].EntityType = SAHPI_ENT_SWITCH_BLADE; } else if (entity_instance == 102) { /* this is here for Force-made Storage blades * until we have access to latest hardware * DO NOT CHANGE */ oh_append_textbuffer(&entry->ResourceTag, "Storage/Disk Blade "); entry->ResourceEntity.Entry[0].EntityType = SAHPI_ENT_DISK_BLADE; } else { oh_append_textbuffer(&entry->ResourceTag, "Blade "); entry->ResourceEntity.Entry[0].EntityType = SAHPI_ENT_SBC_BLADE; } } if ((entity_id == 0x0a) && (entity_instance >= 96)) { // Power Unit oh_append_textbuffer(&entry->ResourceTag, "PEM "); } if ((entity_id == 0xf0) && (entity_instance >= 96)) { // Shelf Manager if ((ipmi_entity_get_device_channel(entity) != 0) || (ipmi_entity_get_device_address(entity) != 32)) { oh_append_textbuffer(&entry->ResourceTag, "Shelf Manager "); } else { oh_append_textbuffer(&entry->ResourceTag, "Virtual Shelf Manager"); no_slot = 1; // XXXX Temporary. Until SDRs fixed ohoi_res_info->type |= OHOI_RESOURCE_MC; ohoi_res_info->u.entity.mc_id = ipmi_handler->virt_mcid; // entry->ResourceCapabilities |= SAHPI_CAPABILITY_EVENT_LOG; } entry->ResourceEntity.Entry[0].EntityType = SAHPI_ENT_SHELF_MANAGER; } if ((entity_id == 0xf2) && (entity_instance >= 96)) { // Shelf FRU oh_append_textbuffer(&entry->ResourceTag, "Shelf FRU Device "); entry->ResourceEntity.Entry[0].EntityType = ATCAHPI_ENT_SHELF_FRU_DEVICE; } if ((entity_id == 0xf1) && (entity_instance >= 96)) { // Filtration Unit oh_append_textbuffer(&entry->ResourceTag, "Fan Filter Tray "); entry->ResourceEntity.Entry[0].EntityType = ATCAHPI_ENT_FILTRATION_UNIT; } if ((entity_id == 0x1e) && (entity_instance >= 96)) { // Fan Tray oh_append_textbuffer(&entry->ResourceTag, "Fan Tray "); } if ((entity_id == 0xc0) && (entity_instance >= 96)) { // Fan Tray oh_append_textbuffer(&entry->ResourceTag, "RTM "); } /* End AdvancedTCA Fix-ups */ if (!no_slot) { oh_append_textbuffer(&entry->ResourceTag, (char *)slot_n_str); } no_atca: if (entry->ResourceTag.DataLength == 0) { str = ipmi_entity_get_entity_id_string(entity); oh_append_textbuffer(&entry->ResourceTag, str); } if (!no_slot) { oh_concat_ep(&entry->ResourceEntity, &ep); } else if (ipmi_entity_get_is_child(entity)) { struct add_parent_ep_s info; info.handler = handler; info.entry = entry; ipmi_entity_iterate_parents(entity, add_parent_ep, &info); } else { oh_encode_entitypath(ipmi_handler->entity_root, &entity_ep); oh_concat_ep(&entry->ResourceEntity, &entity_ep); } entry->ResourceId = oh_uid_from_entity_path(&entry->ResourceEntity); }
int ohoi_hot_swap_cb(ipmi_entity_t *ent, enum ipmi_hot_swap_states last_state, enum ipmi_hot_swap_states curr_state, void *cb_data, ipmi_event_t *event) { struct oh_handler_state *handler = (struct oh_handler_state*)cb_data; struct ohoi_handler *ipmi_handler = (struct ohoi_handler *)handler->data; ipmi_entity_id_t entity_id; SaHpiRptEntryT *rpt_entry; struct ohoi_resource_info *res_info; struct oh_event *e; #if 0 if (event) { unsigned char data[IPMI_EVENT_DATA_MAX_LEN]; unsigned int dt_len, i; printf("event body : "); dt_len = ipmi_event_get_data(event, data, 0, IPMI_EVENT_DATA_MAX_LEN); for (i =0; i < dt_len; i++) printf(" 0x%02x", data[i]); printf("\n"); } #endif if (getenv("OHOI_TRACE_HOTSWAP") || IHOI_TRACE_ALL) { printf(" *** Hotswap HANDLER for entity %d,%d,%d,%d " "(%s). states 0x%x -> 0x%x. entity = %p\n", ipmi_entity_get_entity_id(ent), ipmi_entity_get_entity_instance(ent), ipmi_entity_get_device_channel(ent), ipmi_entity_get_device_address(ent), ipmi_entity_get_entity_id_string(ent), last_state, curr_state, ent); } trace_ipmi("HotSwap Handler called"); entity_id = ipmi_entity_convert_to_id(ent); rpt_entry = ohoi_get_resource_by_entityid(handler->rptcache, &entity_id); if (!rpt_entry) { err(" No rpt\n"); return IPMI_EVENT_HANDLED; } res_info = oh_get_resource_data(handler->rptcache, rpt_entry->ResourceId); if ((last_state == IPMI_HOT_SWAP_ACTIVATION_IN_PROGRESS) && (curr_state == IPMI_HOT_SWAP_DEACTIVATION_IN_PROGRESS)) { if (res_info) { res_info->hs_mark = 1; } return IPMI_EVENT_HANDLED; } e = malloc(sizeof(*e)); if (!e) { err("Out of space"); return IPMI_EVENT_HANDLED; } memset(e, 0, sizeof(*e)); e->event.Source = rpt_entry->ResourceId; if ((curr_state == IPMI_HOT_SWAP_OUT_OF_CON) && (last_state != IPMI_HOT_SWAP_NOT_PRESENT)) { // special case. connection to entity lost rpt_entry->ResourceFailed = SAHPI_TRUE; e->event.EventType = SAHPI_ET_RESOURCE; e->event.Severity = rpt_entry->ResourceSeverity; oh_gettimeofday(&e->event.Timestamp); e->event.Source = rpt_entry->ResourceId; e->event.EventDataUnion.ResourceEvent. ResourceEventType = SAHPI_RESE_RESOURCE_FAILURE; e->resource = *rpt_entry; e->hid = handler->hid; oh_evt_queue_push(handler->eventq, e); if (!IS_ATCA(ipmi_handler->d_type)) { return IPMI_EVENT_HANDLED; } if (ipmi_entity_get_entity_id(ent) == 0xf0) { // Shelf Manager. Handle ShM Redundancy Sensor if (ipmi_handler->fully_up) { ipmi_handler->shmc_present_num--; ohoi_send_vshmgr_redundancy_sensor_event( handler, 0); } } return IPMI_EVENT_HANDLED; } if ((curr_state != IPMI_HOT_SWAP_OUT_OF_CON) && rpt_entry->ResourceFailed) { // special case rpt_entry->ResourceFailed = SAHPI_FALSE; if (curr_state != IPMI_HOT_SWAP_NOT_PRESENT) { // connection to entity restored e->event.EventType = SAHPI_ET_RESOURCE; e->event.Severity = rpt_entry->ResourceSeverity; oh_gettimeofday(&e->event.Timestamp); e->event.Source = rpt_entry->ResourceId; e->event.EventDataUnion.ResourceEvent. ResourceEventType = SAHPI_RESE_RESOURCE_RESTORED; e->resource = *rpt_entry; e->hid = handler->hid; oh_evt_queue_push(handler->eventq, e); if (!IS_ATCA(ipmi_handler->d_type)) { return IPMI_EVENT_HANDLED; } if (ipmi_entity_get_entity_id(ent) == 0xf0) { // Shelf Manager. Handle ShM Redundancy Sensor if (ipmi_handler->fully_up) { ipmi_handler->shmc_present_num++; ohoi_send_vshmgr_redundancy_sensor_event( handler, 1); } } return IPMI_EVENT_HANDLED; } // XXX here must be handled M7->M0 transition } e->event.Source = rpt_entry->ResourceId; e->event.EventType = SAHPI_ET_HOTSWAP; e->event.Severity = get_severity(last_state, curr_state, rpt_entry, res_info); if (event != NULL) { e->event.Timestamp = (SaHpiTimeT)ipmi_event_get_timestamp(event); } else { e->event.Timestamp = SAHPI_TIME_UNSPECIFIED; } if (e->event.Timestamp == SAHPI_TIME_UNSPECIFIED) { oh_gettimeofday(&e->event.Timestamp); } e->event.EventDataUnion.HotSwapEvent.HotSwapState = _ipmi_to_hpi_state_conv(curr_state); e->event.EventDataUnion.HotSwapEvent.PreviousHotSwapState = _ipmi_to_hpi_state_conv(last_state); e->resource = *rpt_entry; if (e->event.EventDataUnion.HotSwapEvent.PreviousHotSwapState == e->event.EventDataUnion.HotSwapEvent.HotSwapState) { free(e); return IPMI_EVENT_HANDLED; } if (e->event.EventDataUnion.HotSwapEvent.HotSwapState == SAHPI_HS_STATE_INSERTION_PENDING) { res_info->hs_inspen_time = e->event.Timestamp; } else { res_info->hs_inspen_time = SAHPI_TIME_UNSPECIFIED; } if (e->event.EventDataUnion.HotSwapEvent.HotSwapState == SAHPI_HS_STATE_NOT_PRESENT) { trace_ipmi("HS_STATE NOT PRESENT, removing RPT"); e->hid = handler->hid; oh_evt_queue_push(handler->eventq, e); }else if (e->event.EventDataUnion.HotSwapEvent.HotSwapState == SAHPI_HS_STATE_ACTIVE) { trace_ipmi("HS_STATE ACTIVE"); e->hid = handler->hid; oh_evt_queue_push(handler->eventq, e); }else { e->hid = handler->hid; oh_evt_queue_push(handler->eventq, e); } // oh_wake_event_thread(0); if (!IS_ATCA(ipmi_handler->d_type) || !event) { return IPMI_EVENT_HANDLED; } unsigned char data[IPMI_EVENT_DATA_MAX_LEN]; unsigned int dt_len; dt_len = ipmi_event_get_data(event, data, 0, IPMI_EVENT_DATA_MAX_LEN); if (dt_len < 12) { err("event data len (%d) too short", dt_len); return IPMI_EVENT_HANDLED; } e = malloc(sizeof(*e)); if (!e) { err("Out of space"); return IPMI_EVENT_HANDLED; } memset(e, 0, sizeof(*e)); e->resource = *rpt_entry; e->event.Source = rpt_entry->ResourceId; e->event.Timestamp = (SaHpiTimeT)ipmi_event_get_timestamp(event); e->event.Severity = SAHPI_INFORMATIONAL; e->event.EventType = SAHPI_ET_OEM; e->event.EventDataUnion.OemEvent.MId = ATCAHPI_PICMG_MID; e->event.EventDataUnion.OemEvent.OemEventData.DataType = SAHPI_TL_TYPE_TEXT; e->event.EventDataUnion.OemEvent.OemEventData.Language = SAHPI_LANG_UNDEF; e->event.EventDataUnion.OemEvent.OemEventData.DataLength = 3; e->event.EventDataUnion.OemEvent.OemEventData.Data[0] = _ipmi_to_hpi_state_conv(curr_state); e->event.EventDataUnion.OemEvent.OemEventData.Data[1] = _ipmi_to_hpi_state_conv(last_state); e->event.EventDataUnion.OemEvent.OemEventData.Data[2] = _ipmi_to_hpi_cause_of_change_conv(data[11] >> 4); e->hid = handler->hid; oh_evt_queue_push(handler->eventq, e); return IPMI_EVENT_HANDLED; }
static void get_entity_event(ipmi_entity_t *entity, SaHpiRptEntryT *entry, void *cb_data) { SaHpiEntityPathT entity_ep; struct oh_handler_state *handler = cb_data; struct ohoi_handler *ipmi_handler = handler->data; int er, i; int rv; const char *str; g_static_rec_mutex_lock(&ipmi_handler->ohoih_lock); entry->ResourceInfo.ResourceRev = 0; entry->ResourceInfo.SpecificVer = 0; entry->ResourceInfo.DeviceSupport = 0; entry->ResourceInfo.ManufacturerId = 0; entry->ResourceInfo.ProductId = 0; entry->ResourceInfo.FirmwareMajorRev = 0; entry->ResourceInfo.FirmwareMinorRev = 0; for (i=0; i<15; i++) { entry->ResourceInfo.Guid[i] = 0; } entry->ResourceInfo.AuxFirmwareRev = 0; entry->ResourceEntity.Entry[0].EntityType = ipmi_entity_get_entity_id(entity); entry->ResourceEntity.Entry[0].EntityLocation = ipmi_entity_get_entity_instance(entity); if(ipmi_entity_get_entity_instance(entity) >= 96) { entry->ResourceEntity.Entry[0].EntityLocation = ipmi_entity_get_entity_instance(entity)- 96; } entry->ResourceEntity.Entry[1].EntityType = SAHPI_ENT_ROOT; entry->ResourceEntity.Entry[1].EntityLocation = 0; entry->EntryId = 0; entry->ResourceId = oh_uid_from_entity_path(&entry->ResourceEntity); entry->ResourceCapabilities = SAHPI_CAPABILITY_RESOURCE; entry->HotSwapCapabilities = 0; if (ipmi_entity_supports_managed_hot_swap(entity)) { trace_ipmi("Entity is hot swapable"); entry->ResourceCapabilities |= SAHPI_CAPABILITY_MANAGED_HOTSWAP; /* if entity supports managed hot swap * check if it has indicator */ /* we need only return value from function */ er = ipmi_entity_get_hot_swap_indicator(entity, NULL, NULL); if (!er) { entry->HotSwapCapabilities |= SAHPI_HS_CAPABILITY_INDICATOR_SUPPORTED; } } /* OpenIPMI used ipmi_entity_hot_swappable to indicate it's FRU * do not use ipmi_entity_get_is_fru() * it's used only for checking if entity has FRU data */ if(ipmi_entity_hot_swappable(entity)) { trace_ipmi("Entity supports simplified hotswap"); entry->ResourceCapabilities |= SAHPI_CAPABILITY_FRU; } // if (ipmi_entity_get_is_fru(entity)) { // dbg("Entity supports FRU Inventory Data"); // entry->ResourceCapabilities |= SAHPI_CAPABILITY_INVENTORY_DATA; // } if (entry->ResourceEntity.Entry[0].EntityType == SAHPI_ENT_SYSTEM_BOARD) { /* This is the BMC entry, so we need to add watchdog. */ entry->ResourceCapabilities |= SAHPI_CAPABILITY_WATCHDOG; } entry->ResourceSeverity = SAHPI_MAJOR; /* Default Value -- not related to IPMI */ entry->ResourceFailed = SAHPI_FALSE; entry->ResourceTag.DataType = SAHPI_TL_TYPE_TEXT; entry->ResourceTag.Language = SAHPI_LANG_ENGLISH; //ipmi_entity_get_id(entity, entry->ResourceTag.Data, SAHPI_MAX_TEXT_BUFFER_LENGTH); str = ipmi_entity_get_entity_id_string(entity); memcpy(entry->ResourceTag.Data,str, strlen(str) +1); entry->ResourceTag.DataLength = strlen(entry->ResourceTag.Data); #if 0 if ((strlen(entry->ResourceTag.Data) == 0) || (!strcmp(entry->ResourceTag.Data, "invalid")) || ((ipmi_entity_get_entity_id(entity) == 7 || 15))) { const char *str; char *str2; int inst; inst = ipmi_entity_get_entity_instance(entity); if (inst >= 96) inst = inst - 96; str = ipmi_entity_get_entity_id_string(entity); if (!(strcmp(str, "invalid"))) { dbg("entity_id_string is invlaid, bad SDR..stick to entity_id"); } else { /* Let's identify the entity-instance in the ResourceTag */ dbg("Instance for ResourceTag %d", inst); str2 = (char *)calloc(strlen(str) + 4, sizeof(char)); snprintf(str2, strlen(str) + 4, "%s-%d",str, inst); memcpy(entry->ResourceTag.Data, str2, strlen(str2) + 1); } } /* AdvancedTCA fix-up */ /* Here we start dealing with device relative entities */ #endif #if 0 if (ipmi_entity_get_entity_instance(entity) >= 96) { entry->ResourceEntity.Entry[0].EntityLocation = ipmi_entity_get_entity_instance(entity) - 96; entry->ResourceEntity.Entry[0].EntityType = ipmi_entity_get_entity_id(entity); entry->ResourceEntity.Entry[1].EntityType = SAHPI_ENT_PHYSICAL_SLOT; int rv; unsigned int val; rv = ipmi_entity_get_physical_slot_num(entity, &val); if (rv != 0) { entry->ResourceEntity.Entry[1].EntityLocation = ipmi_entity_get_device_address(entity); } else { entry->ResourceEntity.Entry[1].EntityLocation = val; } entry->ResourceEntity.Entry[2].EntityType = SAHPI_ENT_ROOT; entry->ResourceEntity.Entry[2].EntityLocation = 0; } #endif /* Since OpenIPMI does not hand us a more descriptive tag which is an SDR issue inthe chassis really, we'll over-ride it here until things change */ if ((ipmi_entity_get_entity_id(entity) == 160) && (ipmi_entity_get_entity_instance(entity) >= 96)) { dbg("SBC Blade"); const char sbc_tag[] = "SBC Blade"; memcpy(entry->ResourceTag.Data, sbc_tag, strlen(sbc_tag) + 1); entry->ResourceEntity.Entry[0].EntityLocation = ipmi_entity_get_entity_instance(entity) - 96; entry->ResourceEntity.Entry[0].EntityType = SAHPI_ENT_SBC_BLADE; entry->ResourceEntity.Entry[1].EntityType = SAHPI_ENT_PHYSICAL_SLOT; unsigned int val; rv = ipmi_entity_get_physical_slot_num(entity, &val); if (rv != 0) { entry->ResourceEntity.Entry[1].EntityLocation = ipmi_entity_get_device_address(entity); dbg("Erro getting Physical Slot Number"); } else { dbg("Physical lot Num: %d", val); entry->ResourceEntity.Entry[1].EntityLocation = val; } entry->ResourceEntity.Entry[2].EntityType = SAHPI_ENT_ROOT; entry->ResourceEntity.Entry[2].EntityLocation = 0; } if ((ipmi_entity_get_entity_id(entity) == 160) && ((ipmi_entity_get_device_address(entity) == 130) || (ipmi_entity_get_device_address(entity) == 132))) { dbg("Switch Blade"); const char switch_tag[] = "Switch Blade"; memcpy(entry->ResourceTag.Data, switch_tag, strlen(switch_tag) + 1); entry->ResourceEntity.Entry[0].EntityLocation = ipmi_entity_get_entity_instance(entity) - 96; entry->ResourceEntity.Entry[0].EntityType = SAHPI_ENT_SWITCH_BLADE; entry->ResourceEntity.Entry[1].EntityType = SAHPI_ENT_PHYSICAL_SLOT; unsigned int val; rv = ipmi_entity_get_physical_slot_num(entity, &val); if (rv != 0) entry->ResourceEntity.Entry[1].EntityLocation = ipmi_entity_get_device_address(entity); else entry->ResourceEntity.Entry[1].EntityLocation = val; dbg("Physical lot Num: %d", val); entry->ResourceEntity.Entry[2].EntityType = SAHPI_ENT_ROOT; entry->ResourceEntity.Entry[2].EntityLocation = 0; } //if ((ipmi_entity_get_entity_id(entity) == 10)) { //dbg("PowerSupply Device"); //entry->ResourceEntity.Entry[1].EntityLocation = 0; //entry->ResourceEntity.Entry[1].EntityType = //SAHPI_ENT_POWER_UNIT; //} if ((ipmi_entity_get_entity_id(entity) == 30)) { dbg("Cooling Device"); //const char disk_tag[] = "Cooling Unit"; //memcpy(entry->ResourceTag.Data, disk_tag, strlen(disk_tag) + 1); entry->ResourceEntity.Entry[0].EntityLocation = ipmi_entity_get_entity_instance(entity) - 96; entry->ResourceEntity.Entry[0].EntityType = ipmi_entity_get_entity_id(entity); } /* this is here for Force-made Storage blades * until we have access to latest hardware * DO NOT CHANGE */ if ((ipmi_entity_get_entity_id(entity) == 160) && (ipmi_entity_get_entity_instance(entity) == 102)) { dbg("DISK Blade"); const char disk_tag[] = "Storage/Disk Blade"; memcpy(entry->ResourceTag.Data, disk_tag, strlen(disk_tag) + 1); //entry->ResourceEntity.Entry[0].EntityLocation = //ipmi_entity_get_entity_instance(entity) - 96; entry->ResourceEntity.Entry[0].EntityType = SAHPI_ENT_DISK_BLADE; } /* End AdvancedTCA Fix-ups */ entry->ResourceTag.DataLength = (SaHpiUint32T)strlen(entry->ResourceTag.Data); oh_encode_entitypath(ipmi_handler->entity_root, &entity_ep); oh_concat_ep(&entry->ResourceEntity, &entity_ep); entry->ResourceId = oh_uid_from_entity_path(&entry->ResourceEntity); trace_ipmi("ResourceId: %d", entry->ResourceId); /* controls */ rv = ipmi_entity_add_control_update_handler(entity, ohoi_control_event, handler); if (rv) { dbg("ipmi_entity_set_control_update_handler: %#x", rv); return; } g_static_rec_mutex_unlock(&ipmi_handler->ohoih_lock); }
void ohoi_entity_event(enum ipmi_update_e op, ipmi_domain_t *domain, ipmi_entity_t *entity, void *cb_data) { struct oh_handler_state *handler = cb_data; struct ohoi_handler *ipmi_handler = handler->data; int rv; int inst=0; switch (op) { case IPMI_ADDED: g_static_rec_mutex_lock(&ipmi_handler->ohoih_lock); if ((ipmi_entity_get_entity_id(entity) == 3) && (ipmi_entity_get_entity_instance(entity) >= 96)) { dbg("We got a processor"); ipmi_entity_iterate_parents(entity, add_processor_event, handler); } else add_entity_event(entity, handler); inst=ipmi_entity_get_entity_instance(entity); if(inst >=96) { inst = inst - 96; } trace_ipmi("Entity added: %d.%d (%s)", ipmi_entity_get_entity_id(entity), inst, ipmi_entity_get_entity_id_string(entity)); /* entity presence overall */ rv = ipmi_entity_add_presence_handler(entity, entity_presence, handler); if (rv) dbg("ipmi_entity_set_presence_handler: %#x", rv); /* hotswap handler */ rv = ipmi_entity_add_hot_swap_handler(entity, ohoi_hot_swap_cb, cb_data); if(rv) dbg("Failed to set entity hot swap handler"); /* sensors */ rv= ipmi_entity_add_sensor_update_handler(entity, ohoi_sensor_event, handler); if (rv) { dbg("ipmi_entity_set_sensor_update_handler: %#x", rv); return; } /* inventory (a.k.a FRU) */ rv = ipmi_entity_add_fru_update_handler(entity, ohoi_inventory_event, handler); if (rv) { dbg("ipmi_entity_set_fru_update_handler: %#x", rv); return; } g_static_rec_mutex_unlock(&ipmi_handler->ohoih_lock); break; case IPMI_DELETED: return; /* we need to remove_entity */ dbg("Entity deleted: %d.%d", ipmi_entity_get_entity_id(entity), ipmi_entity_get_entity_instance(entity)); break; case IPMI_CHANGED: g_static_rec_mutex_lock(&ipmi_handler->ohoih_lock); //add_entity_event(entity, handler); inst = 0; inst=ipmi_entity_get_entity_instance(entity); if(inst >=96) { inst = inst - 96; } trace_ipmi("***Entity changed: %d.%d", ipmi_entity_get_entity_id(entity), inst); g_static_rec_mutex_unlock(&ipmi_handler->ohoih_lock); break; default: dbg("Entity: Unknow change?!"); } }
static void get_entity_event(ipmi_entity_t *entity, SaHpiRptEntryT *entry, void *cb_data) { SaHpiEntityPathT entity_ep; int er; struct ohoi_handler *ipmi_handler = cb_data; entry->ResourceInfo.ResourceRev = 0; entry->ResourceInfo.SpecificVer = 0; entry->ResourceInfo.DeviceSupport = 0; entry->ResourceInfo.ManufacturerId = 0; entry->ResourceInfo.ProductId = 0; entry->ResourceInfo.FirmwareMajorRev = 0; entry->ResourceInfo.FirmwareMinorRev = 0; entry->ResourceInfo.AuxFirmwareRev = 0; entry->ResourceEntity.Entry[0].EntityType = ipmi_entity_get_entity_id(entity); entry->ResourceEntity.Entry[0].EntityLocation = ipmi_entity_get_entity_instance(entity); entry->ResourceEntity.Entry[1].EntityType = SAHPI_ENT_ROOT; entry->ResourceEntity.Entry[1].EntityLocation = 0; /* AdvancedTCA fixe-up */ if (ipmi_entity_get_entity_instance(entity) >= 96) { entry->ResourceEntity.Entry[0].EntityLocation -= 96; //|ipmi_entity_get_device_channel(entity) //|ipmi_entity_get_device_address(entity); } if ((ipmi_entity_get_entity_id(entity) == 160) && (ipmi_entity_get_entity_instance(entity) == 96)) { dbg("SBC_Blade"); entry->ResourceEntity.Entry[0].EntityType = SAHPI_ENT_SBC_BLADE; } if ((ipmi_entity_get_entity_id(entity) == 160) && (ipmi_entity_get_entity_instance(entity) == 102)) { dbg("DISK Blade"); entry->ResourceEntity.Entry[0].EntityType = SAHPI_ENT_DISK_BLADE; } /* End AdvancedTCA Fix-ups */ /* let's append entity_root from config */ oh_encode_entitypath(ipmi_handler->entity_root, &entity_ep); oh_concat_ep(&entry->ResourceEntity, &entity_ep); entry->EntryId = 0; entry->ResourceId = oh_uid_from_entity_path(&entry->ResourceEntity); entry->ResourceCapabilities = SAHPI_CAPABILITY_RESOURCE; entry->HotSwapCapabilities = 0; if (ipmi_entity_supports_managed_hot_swap(entity)) { entry->ResourceCapabilities |= SAHPI_CAPABILITY_MANAGED_HOTSWAP; /* if entity supports managed hot swap * check if it has indicator */ dbg("Entity %d supports managed hotswap\n", entry->ResourceId); /* we need only return value from function */ er = ipmi_entity_get_hot_swap_indicator(entity, NULL, NULL); if (!er) { dbg("resource %d has HS Indicator\n", entry->ResourceId); entry->HotSwapCapabilities |= SAHPI_HS_CAPABILITY_INDICATOR_SUPPORTED; } } /* OpenIPMI used ipmi_entity_hot_swappable to indicate it's FRU * do not use ipmi_entity_get_is_fru() * it's used only for checking if entity has FRU data */ if(ipmi_entity_hot_swappable(entity)) { dbg("Entity supports simplified hotswap"); entry->ResourceCapabilities |= SAHPI_CAPABILITY_FRU; } if (ipmi_entity_get_is_fru(entity)) { dbg("Entity supports FRU Inventory Data"); entry->ResourceCapabilities |= SAHPI_CAPABILITY_INVENTORY_DATA; } if (entry->ResourceEntity.Entry[0].EntityType == SAHPI_ENT_SYSTEM_BOARD) { /* This is the BMC entry, so we need to add watchdog. */ entry->ResourceCapabilities |= SAHPI_CAPABILITY_WATCHDOG; } entry->ResourceSeverity = SAHPI_OK; /* Default Value -- not related to IPMI */ entry->ResourceTag.DataType = SAHPI_TL_TYPE_TEXT; entry->ResourceTag.Language = SAHPI_LANG_ENGLISH; ipmi_entity_get_id(entity, entry->ResourceTag.Data, SAHPI_MAX_TEXT_BUFFER_LENGTH); if ((strlen(entry->ResourceTag.Data) == 0) || (!strcmp(entry->ResourceTag.Data, "invalid")) || ((ipmi_entity_get_entity_id(entity) == 7 || 15))) { char *str; char *str2; str = ipmi_entity_get_entity_id_string(entity); if (!(strcmp(str, "invalid"))) { dbg("entity_id_string is invlaid, bad SDR..stick to entity_id"); } else { /* Let's identify the entity-instance in the ResourceTag */ str2 = (char *)calloc(strlen(str) + 3, sizeof(char)); snprintf(str2, strlen(str) + 3, "%s-%d",str, ipmi_entity_get_entity_instance(entity)); memcpy(entry->ResourceTag.Data, str2, strlen(str2) + 1); } } entry->ResourceTag.DataLength = (SaHpiUint32T)strlen(entry->ResourceTag.Data); }
void ohoi_entity_event(enum ipmi_update_e op, ipmi_domain_t *domain, ipmi_entity_t *entity, void *cb_data) { struct oh_handler_state *handler = cb_data; int rv; switch (op) { case IPMI_ADDED: add_entity_event(entity, handler); dbg("Entity added: %d.%d (%s)", ipmi_entity_get_entity_id(entity), ipmi_entity_get_entity_instance(entity), ipmi_entity_get_entity_id_string(entity)); /* entity presence overall */ rv = ipmi_entity_add_presence_handler(entity, entity_presence, handler); if (rv) dbg("ipmi_entity_set_presence_handler: %#x", rv); /* hotswap handler */ rv = ipmi_entity_add_hot_swap_handler(entity, ohoi_hot_swap_cb, cb_data); if(rv) dbg("Failed to set entity hot swap handler"); /* sensors */ rv= ipmi_entity_add_sensor_update_handler(entity, ohoi_sensor_event, handler); if (rv) { dbg("ipmi_entity_set_sensor_update_handler: %#x", rv); return; } /* controls */ rv = ipmi_entity_add_control_update_handler(entity, ohoi_control_event, handler); if (rv) { dbg("ipmi_entity_set_control_update_handler: %#x", rv); return; } /* inventory (a.k.a FRU) */ rv = ipmi_entity_add_fru_update_handler(entity, ohoi_inventory_event, handler); if (rv) { dbg("ipmi_entity_set_fru_update_handler: %#x", rv); return; } break; case IPMI_DELETED: return; /* we need to remove_entity */ dbg("Entity deleted: %d.%d", ipmi_entity_get_entity_id(entity), ipmi_entity_get_entity_instance(entity)); break; case IPMI_CHANGED: add_entity_event(entity, handler); dbg("Entity changed: %d.%d", ipmi_entity_get_entity_id(entity), ipmi_entity_get_entity_instance(entity)); break; default: dbg("Entity: Unknow change?!"); } }
void ohoi_control_event(enum ipmi_update_e op, ipmi_entity_t *ent, ipmi_control_t *control, void *cb_data) { struct oh_handler_state *handler = cb_data; struct ohoi_handler *ipmi_handler = handler->data; struct ohoi_resource_info *ohoi_res_info; int ctrl_type = ipmi_control_get_type(control); ipmi_control_id_t cid = ipmi_control_convert_to_id(control); ipmi_entity_id_t entity_id; SaHpiRptEntryT *rpt_entry; char str[24]; int rv; entity_id = ipmi_entity_convert_to_id(ent); rpt_entry = ohoi_get_resource_by_entityid(handler->rptcache, &entity_id); if (!rpt_entry) { dump_entity_id("Control with RPT Entry?!", entity_id); return; } g_static_rec_mutex_lock(&ipmi_handler->ohoih_lock); ohoi_res_info = oh_get_resource_data(handler->rptcache, rpt_entry->ResourceId); if (op == IPMI_ADDED) { trace_ipmi_control("ADD", control, rpt_entry); /* attach power and reset to chassis entity since IPMI provides them as such */ switch (ctrl_type) { case IPMI_CONTROL_ONE_SHOT_RESET: ohoi_res_info->reset_ctrl = cid; rpt_entry->ResourceCapabilities |= SAHPI_CAPABILITY_RESET; break; case IPMI_CONTROL_POWER: if ((ipmi_handler->d_type == IPMI_DOMAIN_TYPE_ATCA) && (ipmi_entity_get_entity_id(ent) == SAHPI_ENT_SYSTEM_CHASSIS)) { // never power off ATCA chassis break; } ohoi_res_info->power_ctrl = cid; rpt_entry->ResourceCapabilities |= SAHPI_CAPABILITY_POWER; break; case IPMI_CONTROL_ALARM: rv = add_alarm_rdrs(handler,rpt_entry,control); if (rv) { dbg("add_alarms_rdrs failed"); break; } rpt_entry->ResourceCapabilities |= SAHPI_CAPABILITY_CONTROL | SAHPI_CAPABILITY_RDR; break; case IPMI_CONTROL_IDENTIFIER: #if 0 rv = address_control_get(control,handler, ent, rpt_entry); if (rv) { dbg("address_control_get failed"); break; } rpt_entry->ResourceCapabilities |= SAHPI_CAPABILITY_CONTROL | SAHPI_CAPABILITY_RDR; #endif break; case IPMI_CONTROL_LIGHT: ipmi_control_get_id(control, str, 24); if (add_led_control_event(ent, control, handler, rpt_entry)) { break; } rpt_entry->ResourceCapabilities |= SAHPI_CAPABILITY_CONTROL | SAHPI_CAPABILITY_RDR; break; default: if (SA_OK != add_control_event(ent, control, handler, rpt_entry->ResourceEntity, rpt_entry->ResourceId)) { break; } rpt_entry->ResourceCapabilities |= SAHPI_CAPABILITY_CONTROL | SAHPI_CAPABILITY_RDR; break; } } else if (op == IPMI_DELETED) { trace_ipmi_control("DELETE", control, rpt_entry); switch (ctrl_type) { case IPMI_CONTROL_ONE_SHOT_RESET: ipmi_control_id_set_invalid( &ohoi_res_info->reset_ctrl); rpt_entry->ResourceCapabilities &= ~SAHPI_CAPABILITY_RESET; break; case IPMI_CONTROL_POWER: ipmi_control_id_set_invalid( &ohoi_res_info->power_ctrl); rpt_entry->ResourceCapabilities &= ~SAHPI_CAPABILITY_POWER; break; default: if (ohoi_delete_orig_control_rdr(handler, rpt_entry, &cid)) { // no more controlss for rpt rpt_entry->ResourceCapabilities &= ~SAHPI_CAPABILITY_CONTROL; ohoi_res_info->ctrl_count = 0; } break; } if ((oh_get_rdr_next(handler->rptcache, rpt_entry->ResourceId, SAHPI_FIRST_ENTRY) == NULL) && (ohoi_res_info->fru == NULL)) { // no more rdrs for rpt rpt_entry->ResourceCapabilities &= ~SAHPI_CAPABILITY_RDR; } } trace_ipmi("Set updated for res_info %p(%d). Control", ohoi_res_info, rpt_entry->ResourceId); entity_rpt_set_updated(ohoi_res_info, ipmi_handler); g_static_rec_mutex_unlock(&ipmi_handler->ohoih_lock); }
int entity_presence(ipmi_entity_t *entity, int present, void *cb_data, ipmi_event_t *event) { struct oh_handler_state *handler = (struct oh_handler_state *)cb_data; struct ohoi_handler *ipmi_handler = handler->data; SaHpiRptEntryT *rpt; SaHpiResourceIdT rid; ipmi_entity_id_t ent_id; struct ohoi_resource_info *res_info; ent_id = ipmi_entity_convert_to_id(entity); rpt = ohoi_get_resource_by_entityid(handler->rptcache, &ent_id); if (!rpt) { trace_ipmi_entity("SET PRESENCE. NO RPT", present, entity); dbg("No rpt"); return SA_ERR_HPI_NOT_PRESENT; } rid = rpt->ResourceId; res_info = oh_get_resource_data(handler->rptcache, rid); if (res_info->presence == present) { return SA_OK; } trace_ipmi_entity(present ? "PRESENT" : "NOT PRESENT", 0, entity); if (IS_ATCA(ipmi_handler->d_type)) { switch (ipmi_entity_get_entity_id(entity)) { case 0xa0: // Blade atca_slot_state_sensor_event_send(handler, rpt, present); break; case 0xf0: // Shelf Manager if ((ipmi_entity_get_device_channel(entity) == 0) && (ipmi_entity_get_device_address(entity) == 32)) { // Virtual ShM. Do nothing break; } if (present) { ipmi_handler->shmc_present_num++; } else { ipmi_handler->shmc_present_num--; } if (ipmi_handler->fully_up) { ohoi_send_vshmgr_redundancy_sensor_event( handler, present); } break; case 0x1e: // Fan Tray if (present) { ohoi_create_fan_control(handler, rpt->ResourceId); } break; default: break; } } entity_rpt_set_presence(res_info, handler->data, present); return SA_OK; }
static void add_processor_event(ipmi_entity_t *entity, ipmi_entity_t *parent, void *cb_data) { struct oh_handler_state *handler = cb_data; struct ohoi_handler *ipmi_handler = handler->data; struct ohoi_resource_info *res_info; SaHpiRptEntryT entry; SaHpiEntityPathT entity_ep; int rv, i; unsigned int parent_location; int inst; /* instance */ const char tag[] = "Processor"; char *str2; res_info = g_malloc0(sizeof(*res_info)); if (!res_info) { dbg("Out of memory"); return; } res_info->type = OHOI_RESOURCE_ENTITY; res_info->u.entity_id= ipmi_entity_convert_to_id(entity); inst = ipmi_entity_get_entity_instance(entity) - 96; entry.ResourceInfo.ResourceRev = 0; entry.ResourceInfo.SpecificVer = 0; entry.ResourceInfo.DeviceSupport = 0; entry.ResourceInfo.ManufacturerId = 0; entry.ResourceInfo.ProductId = 0; entry.ResourceInfo.FirmwareMajorRev = 0; entry.ResourceInfo.FirmwareMinorRev = 0; for (i=0; i<15; i++) { entry.ResourceInfo.Guid[i] = 0; } entry.ResourceEntity.Entry[0].EntityType = ipmi_entity_get_entity_id(entity); entry.ResourceEntity.Entry[0].EntityLocation = inst; rv = ipmi_entity_get_physical_slot_num(parent, &parent_location); if (rv != 0) { dbg("Processor parent address unavailable, using self address"); entry.ResourceEntity.Entry[1].EntityType = SAHPI_ENT_SBC_BLADE; entry.ResourceEntity.Entry[1].EntityLocation = ipmi_entity_get_device_address(entity); } else { dbg("Processor Parent Address %d", parent_location); entry.ResourceEntity.Entry[1].EntityType = SAHPI_ENT_SBC_BLADE; entry.ResourceEntity.Entry[1].EntityLocation = ipmi_entity_get_entity_instance(parent) - 96; } entry.ResourceEntity.Entry[2].EntityType = SAHPI_ENT_PHYSICAL_SLOT; entry.ResourceEntity.Entry[2].EntityLocation = parent_location; entry.ResourceEntity.Entry[3].EntityType = SAHPI_ENT_ROOT; entry.ResourceEntity.Entry[3].EntityLocation = 0; entry.EntryId = 0; entry.ResourceCapabilities = SAHPI_CAPABILITY_RESOURCE; entry.HotSwapCapabilities = 0; entry.ResourceSeverity = SAHPI_MAJOR; /* Default Value -- not related to IPMI */ entry.ResourceFailed = SAHPI_FALSE; entry.ResourceTag.DataType = SAHPI_TL_TYPE_TEXT; entry.ResourceTag.Language = SAHPI_LANG_ENGLISH; //ipmi_entity_get_id(entity, entry->ResourceTag.Data, SAHPI_MAX_TEXT_BUFFER_LENGTH); //str = ipmi_entity_get_entity_id_string(entity); /* Let's identify the entity-instance in the ResourceTag */ str2 = (char *)calloc(strlen(tag) + 3, sizeof(char)); snprintf(str2, strlen(tag) + 3, "%s-%d",tag, inst); memcpy(entry.ResourceTag.Data, str2, strlen(str2) + 1); trace_ipmi("ProcessorTag: %s", entry.ResourceTag.Data); entry.ResourceTag.DataLength = (SaHpiUint32T)strlen(entry.ResourceTag.Data); oh_encode_entitypath(ipmi_handler->entity_root, &entity_ep); oh_concat_ep(&entry.ResourceEntity, &entity_ep); entry.ResourceId = oh_uid_from_entity_path(&entry.ResourceEntity); trace_ipmi("Processor ResourceId: %d", entry.ResourceId); rv = oh_add_resource(handler->rptcache, &entry, res_info, 1); if (rv) { dbg("oh_add_resource failed for %d = %s\n", entry.ResourceId, oh_lookup_error(rv)); } }
int entity_presence(ipmi_entity_t *entity, int present, void *cb_data, ipmi_event_t *event) { struct oh_handler_state *handler = (struct oh_handler_state *)cb_data; struct ohoi_handler *ipmi_handler = handler->data; SaHpiRptEntryT *rpt; SaHpiResourceIdT rid; ipmi_entity_id_t ent_id; struct ohoi_resource_info *res_info; ent_id = ipmi_entity_convert_to_id(entity); g_static_rec_mutex_lock(&ipmi_handler->ohoih_lock); rpt = ohoi_get_resource_by_entityid(handler->rptcache, &ent_id); if (!rpt) { trace_ipmi_entity("SET PRESENCE. NO RPT", present, entity); dbg("No rpt"); g_static_rec_mutex_unlock(&ipmi_handler->ohoih_lock); return SA_ERR_HPI_NOT_PRESENT; } rid = rpt->ResourceId; if (!(rpt->ResourceCapabilities & SAHPI_CAPABILITY_FRU) && !present) { // This is a workaround trace_ipmi_entity("PRESENCE HANDLER CALLED FOR NOT FRU ENTITY", present, entity); g_static_rec_mutex_unlock(&ipmi_handler->ohoih_lock); return SA_ERR_HPI_NOT_PRESENT; } res_info = oh_get_resource_data(handler->rptcache, rid); if (res_info->presence == present) { g_static_rec_mutex_unlock(&ipmi_handler->ohoih_lock); return SA_OK; } trace_ipmi_entity(present ? "PRESENT" : "NOT PRESENT", present, entity); if (present && res_info->deleted) { // became not present and present again. res_info->deleted = 0; rpt->ResourceFailed = SAHPI_FALSE; } if (IS_ATCA(ipmi_handler->d_type)) { switch (ipmi_entity_get_entity_id(entity)) { case 0xa0: // Blade atca_slot_state_sensor_event_send(handler, rpt, present); break; case 0xf0: // Shelf Manager if ((ipmi_entity_get_device_channel(entity) == 0) && (ipmi_entity_get_device_address(entity) == 32)) { // Virtual ShM. Do nothing. It cannot be. break; } if (present) { ipmi_handler->shmc_present_num++; } else { if (rpt->ResourceFailed) { // it's already marked break; } ipmi_handler->shmc_present_num--; } if (ipmi_handler->fully_up) { ohoi_send_vshmgr_redundancy_sensor_event( handler, present); } break; case 0x1e: // Fan Tray if (present) { ohoi_create_fan_control(handler, rpt->ResourceId); } break; default: break; } } entity_rpt_set_presence(res_info, handler->data, present); if (!present) { res_info->deleted = 1; // send event to infrastructure but don't // touch our local structures while struct oh_event *event = malloc(sizeof(*event)); if (event != NULL) { memset(event, 0, sizeof(*event)); event->type = OH_ET_RESOURCE_DEL; memcpy(&event->u.res_event.entry, rpt, sizeof(SaHpiRptEntryT)); handler->eventq = g_slist_append(handler->eventq, event); } else { dbg("Out of memory"); } #if 0 while (SA_OK == oh_remove_rdr(handler->rptcache, rid, SAHPI_FIRST_ENTRY)); ohoi_delete_rpt_fru(res_info); res_info->type = OHOI_RESOURCE_ENTITY; // XXX free inventory area memory #endif } g_static_rec_mutex_unlock(&ipmi_handler->ohoih_lock); return SA_OK; }