Ejemplo n.º 1
0
ipmi_sensor_id_t
ipmi_event_get_generating_sensor_id(ipmi_domain_t       *domain,
			            ipmi_mc_t           *sel_mc,
			            const ipmi_event_t  *event)
{
    ipmi_sensor_id_t    id;
    ipmi_mc_t           *mc;
    const unsigned char *data;
    unsigned int        type = ipmi_event_get_type(event);


    if (type != 0x02)
	/* It's not a standard IPMI event. */
	goto out_invalid;

    mc = _ipmi_event_get_generating_mc(domain, sel_mc, event);
    if (!mc)
	goto out_invalid;

    data = ipmi_event_get_data_ptr(event);
    id.mcid = ipmi_mc_convert_to_id(mc);
    id.lun = data[5] & 0x3;
    id.sensor_num = data[8];

    _ipmi_mc_put(mc);

    return id;

 out_invalid:
    ipmi_sensor_id_set_invalid(&id);
    return id;
}
Ejemplo n.º 2
0
static void mc_add(ipmi_mc_t                    *mc,
                   struct oh_handler_state      *handler)
{
        struct ohoi_resource_info *ohoi_res_info;
        struct oh_event *e;

		struct ohoi_handler *ipmi_handler = handler->data;
        
        ohoi_res_info = g_malloc0(sizeof(*ohoi_res_info));
        if (!ohoi_res_info) {
                dbg("Out of space");
                return;
        }
        ohoi_res_info->type       = OHOI_RESOURCE_MC;
        ohoi_res_info->u.mc_id    = ipmi_mc_convert_to_id(mc);
                
	e = malloc(sizeof(*e));
	if (!e) {
		dbg("Out of space");   
		return;
	}
	memset(e, 0, sizeof(*e));

	e->type = OH_ET_RESOURCE;

	get_mc_entity_event(mc, &(e->u.res_event.entry), ipmi_handler);

	/* add to rptcache */
	oh_add_resource(handler->rptcache, &(e->u.res_event.entry), ohoi_res_info, 1);

}
Ejemplo n.º 3
0
void
ohoi_mc_event(enum ipmi_update_e op,
              ipmi_domain_t      *domain,
              ipmi_mc_t          *mc,
              void               *cb_data)
{

        struct oh_handler_state *handler = cb_data;
		struct ohoi_handler *ipmi_handler = handler->data;
		int rv;
		
	if ((ipmi_mc_get_channel(mc) == 0) && 
                 (ipmi_mc_get_address(mc) == 32) &&
		 ipmi_handler->d_type == IPMI_DOMAIN_TYPE_ATCA) {
		 	ipmi_handler->virt_mcid = ipmi_mc_convert_to_id(mc);
	}

	g_static_rec_mutex_lock(&ipmi_handler->ohoih_lock);			
        switch (op) {
                case IPMI_ADDED:
			/* if we get an MC but inactive, register a call to add
			it once it goes active */
			rv = ipmi_mc_add_active_handler(mc, mc_active, handler);
			rv = ipmi_mc_set_sdrs_first_read_handler(mc,
				mc_processed, handler);
			if(!ipmi_mc_is_active(mc)) {
				trace_ipmi_mc("ADDED but inactive...we ignore", mc);
				break;
			} else {
				mc_add(mc, handler);
				break;
			}
		case IPMI_DELETED:
			trace_ipmi_mc("DELETED, but nothing done", mc);
			break;

		case IPMI_CHANGED:
			if(!ipmi_mc_is_active(mc)) {
				trace_ipmi("CHANGED and is inactive: (%d %x)\n",
						ipmi_mc_get_address(mc), 
						ipmi_mc_get_channel(mc));
			} else {
				mc_add(mc, handler);
			}
			break;
		}
	g_static_rec_mutex_unlock(&ipmi_handler->ohoih_lock);

}
Ejemplo n.º 4
0
static
void process_sel_support(ipmi_mc_t *mc, struct oh_handler_state *handler)
{
        struct ohoi_resource_info *res_info;
	struct ohoi_handler *ipmi_handler = handler->data;
	ipmi_mcid_t mcid;
	SaHpiRptEntryT *rpt;
        

        mcid    = ipmi_mc_convert_to_id(mc);
	rpt = ohoi_get_resource_by_mcid(handler->rptcache, &mcid);
	if (rpt == NULL) {
		trace_ipmi_mc("COULDN'T FIND RPT", mc);
		dbg("couldn't find out resource");
		return;
	}
	res_info =  oh_get_resource_data(handler->rptcache, rpt->ResourceId);
	if (ipmi_mc_sel_device_support(mc)) {
		rpt->ResourceCapabilities |=
					SAHPI_CAPABILITY_EVENT_LOG;
		entity_rpt_set_updated(res_info, ipmi_handler);
	}
}
Ejemplo n.º 5
0
static void mc_remove(ipmi_mc_t                    *mc,
                   struct oh_handler_state      *handler)
{
	struct ohoi_handler *ipmi_handler = handler->data;
	ipmi_mcid_t mcid;
	SaHpiRptEntryT *rpt;

	trace_ipmi_mc("REMOVED (not present)", mc);
	if (!IS_ATCA(ipmi_handler->d_type)) {
		return;
	}
	g_static_rec_mutex_lock(&ipmi_handler->ohoih_lock);
	mcid    = ipmi_mc_convert_to_id(mc);
	ohoi_atca_delete_fru_rdrs(handler, mcid);
	rpt = ohoi_get_resource_by_mcid(handler->rptcache, &mcid);
	if (rpt == NULL) {
		trace_ipmi_mc("COULDN'T FIND RPT", mc);
		dbg("couldn't find out resource");
	} else {
		rpt->ResourceCapabilities &=
			SAHPI_CAPABILITY_EVENT_LOG;
	}
	g_static_rec_mutex_unlock(&ipmi_handler->ohoih_lock);
}
Ejemplo n.º 6
0
int
ipmi_solparm_alloc(ipmi_mc_t      *mc,
		   unsigned int   channel,
		   ipmi_solparm_t **new_solparm)
{
    ipmi_solparm_t     *solparm = NULL;
    int                rv = 0;
    ipmi_domain_t      *domain = ipmi_mc_get_domain(mc);
    int                p, len;
    locked_list_t      *solparml;
    ipmi_domain_attr_t *attr;

    CHECK_MC_LOCK(mc);

    rv = ipmi_domain_register_attribute(domain, IPMI_SOLPARM_ATTR_NAME,
					solparm_attr_init,
					solparm_attr_destroy,
					NULL,
					&attr);
    if (rv)
	return rv;
    solparml = ipmi_domain_attr_get_data(attr);

    solparm = ipmi_mem_alloc(sizeof(*solparm));
    if (!solparm) {
	rv = ENOMEM;
	goto out;
    }
    memset(solparm, 0, sizeof(*solparm));

    solparm->refcount = 1;
    solparm->in_list = 1;
    solparm->mc = ipmi_mc_convert_to_id(mc);
    solparm->domain = ipmi_domain_convert_to_id(domain);
    len = sizeof(solparm->name);
    p = ipmi_domain_get_name(domain, solparm->name, len);
    len -= p;
    snprintf(solparm->name+p, len, ".%d", ipmi_domain_get_unique_num(domain));
    solparm->os_hnd = ipmi_domain_get_os_hnd(domain);
    solparm->solparm_lock = NULL;
    solparm->channel = channel & 0xf;

    solparm->opq = opq_alloc(solparm->os_hnd);
    if (!solparm->opq) {
	rv = ENOMEM;
	goto out;
    }

    if (solparm->os_hnd->create_lock) {
	rv = solparm->os_hnd->create_lock(solparm->os_hnd,
					  &solparm->solparm_lock);
	if (rv)
	    goto out;
    }

    if (! locked_list_add(solparml, solparm, NULL)) {
	rv = ENOMEM;
	goto out;
    }

 out:
    if (rv) {
	if (solparm) {
	    if (solparm->opq)
		opq_destroy(solparm->opq);
	    if (solparm->solparm_lock)
		solparm->os_hnd->destroy_lock(solparm->os_hnd,
					      solparm->solparm_lock);
	    ipmi_mem_free(solparm);
	}
    } else {
	*new_solparm = solparm;
    }
    ipmi_domain_attr_put(attr);
    return rv;
}
Ejemplo n.º 7
0
int
ipmi_pet_create_mc(ipmi_mc_t        *mc,
		   unsigned int     channel,
		   struct in_addr   ip_addr,
		   unsigned char    mac_addr[6],
		   unsigned int     eft_sel,
		   unsigned int     policy_num,
		   unsigned int     apt_sel,
		   unsigned int     lan_dest_sel,
		   ipmi_pet_done_cb done,
		   void             *cb_data,
		   ipmi_pet_t       **ret_pet)
{
    ipmi_pet_t         *pet;
    int                rv;
    os_handler_t       *os_hnd;
    char               domain_name[IPMI_MC_NAME_LEN];
    ipmi_domain_t      *domain = ipmi_mc_get_domain(mc);
    ipmi_domain_attr_t *attr;
    locked_list_t      *pets;

    rv = ipmi_domain_register_attribute(domain, IPMI_PET_ATTR_NAME,
					pet_attr_init, pet_attr_destroy, NULL,
					&attr);
    if (rv)
	return rv;
    pets = ipmi_domain_attr_get_data(attr);

    pet = ipmi_mem_alloc(sizeof(*pet));
    if (!pet) {
	ipmi_domain_attr_put(attr);
	return ENOMEM;
    }
    memset(pet, 0, sizeof(*pet));

    ipmi_domain_get_name(domain, domain_name, sizeof(domain_name));
    snprintf(pet->name, sizeof(pet->name), "%s.%d", domain_name,
	     ipmi_domain_get_unique_num(domain));
    pet->refcount = 1;
    pet->in_list = 1;
    pet->mc = ipmi_mc_convert_to_id(mc);
    pet->domain = ipmi_domain_convert_to_id(domain);
    pet->channel = channel;
    pet->ip_addr = ip_addr;
    pet->policy_num = policy_num;
    pet->eft_sel = eft_sel;
    pet->apt_sel = apt_sel;
    pet->lan_dest_sel = lan_dest_sel;
    pet->done = done;
    pet->cb_data = cb_data;
    memcpy(pet->mac_addr, mac_addr, sizeof(pet->mac_addr));
    pet->in_progress = 0;

    /* Set up all the data we want in the PEF and LANPARMs
       configuration. */
    pet->pef_check[0].conf_num = IPMI_PEFPARM_CONTROL;
    pet->pef_check[0].data_len = 1;
    pet->pef_check[0].data[0] = 1;
    pet->pef_check[0].mask[0] = 1;
    pet->pef_check[1].conf_num = IPMI_PEFPARM_ACTION_GLOBAL_CONTROL;
    pet->pef_check[1].data_len = 1;
    pet->pef_check[1].data[0] = 1;
    pet->pef_check[1].mask[0] = 1;
    pet->pef_check[2].conf_num = IPMI_PEFPARM_EVENT_FILTER_TABLE;
    pet->pef_check[2].set = eft_sel;
    pet->pef_check[2].data_len = 21;
    memset(pet->pef_check[2].data, 0xff, 10);
    memset(pet->pef_check[2].data+10, 0, 21-9);
    memset(pet->pef_check[2].mask, 0xff, 21);
    pet->pef_check[2].data[0] = eft_sel;
    pet->pef_check[2].mask[0] = 0x7f;
    pet->pef_check[2].data[1] = 0x80;
    pet->pef_check[2].mask[1] = 0x80;
    pet->pef_check[2].data[2] = 0x01;
    pet->pef_check[2].mask[2] = 0x3f;
    pet->pef_check[2].data[3] = policy_num;
    pet->pef_check[2].mask[3] = 0x0f;
    pet->pef_check[2].data[4] = 0;
    pet->pef_check[2].data[10] = 0xff;
    pet->pef_check[2].data[11] = 0xff;
    pet->pef_check[3].conf_num = IPMI_PEFPARM_ALERT_POLICY_TABLE;
    pet->pef_check[3].set = apt_sel;
    pet->pef_check[3].data_len = 4;
    pet->pef_check[3].data[0] = apt_sel;
    pet->pef_check[3].mask[0] = 0x7f;
    pet->pef_check[3].data[1] = 0x08 | (policy_num << 4);
    pet->pef_check[3].mask[1] = 0xff;
    pet->pef_check[3].data[2] = (channel << 4) | lan_dest_sel;
    pet->pef_check[3].mask[2] = 0xff;
    pet->pef_check[3].data[3] = 0;
    pet->pef_check[3].mask[3] = 0xff;

    pet->lanparm_check[0].conf_num = IPMI_LANPARM_DEST_TYPE;
    pet->lanparm_check[0].set = lan_dest_sel;
    pet->lanparm_check[0].data_len = 4;
    pet->lanparm_check[0].data[0] = lan_dest_sel;
    pet->lanparm_check[0].mask[0] = 0x0f;
    pet->lanparm_check[0].data[1] = 0x80;
    pet->lanparm_check[0].mask[1] = 0x87;
    pet->lanparm_check[0].data[2] = IPMI_LANPARM_DEFAULT_ALERT_RETRY_TIMEOUT;
    pet->lanparm_check[0].mask[2] = 0xff;
    pet->lanparm_check[0].data[3] = IPMI_LANPARM_DEFAULT_ALERT_RETRIES;
    pet->lanparm_check[0].mask[3] = 0x07;
    pet->lanparm_check[1].conf_num = IPMI_LANPARM_DEST_ADDR;
    pet->lanparm_check[1].set = lan_dest_sel;
    pet->lanparm_check[1].data_len = 13;
    pet->lanparm_check[1].data[0] = lan_dest_sel;
    pet->lanparm_check[1].mask[0] = 0x0f;
    pet->lanparm_check[1].data[1] = 0x00;
    pet->lanparm_check[1].mask[1] = 0xf0;
    pet->lanparm_check[1].data[2] = 0x00;
    pet->lanparm_check[1].mask[2] = 0x01;
    memset(pet->lanparm_check[1].mask+3, 0xff, 10);
    memcpy(pet->lanparm_check[1].data+3, &ip_addr, 4);
    memcpy(pet->lanparm_check[1].data+7, mac_addr, 6);

    os_hnd = ipmi_domain_get_os_hnd(domain);
    pet->os_hnd = os_hnd;

    /* Start a timer for this PET to periodically check it. */
    pet->timer_info = ipmi_mem_alloc(sizeof(*(pet->timer_info)));
    if (!pet->timer_info) {
	rv = ENOMEM;
	goto out_err;
    }
    pet->timer_info->cancelled = 0;
    pet->timer_info->os_hnd = os_hnd;
    pet->timer_info->pet = pet;
    pet->timer_info->running = 0;
    pet->timer_info->lock = NULL;
    rv = os_hnd->alloc_timer(os_hnd, &pet->timer);
    if (rv)
	goto out_err;

    rv = ipmi_create_lock_os_hnd(os_hnd, &pet->timer_info->lock);
    if (rv)
	goto out_err;

    if (! locked_list_add(pets, pet, NULL)) {
	rv = ENOMEM;
	goto out_err;
    }

    ipmi_domain_attr_put(attr);

    rv = start_pet_setup(mc, pet);
    if (rv)
	goto out_err;

    if (ret_pet)
	*ret_pet = pet;

    return 0;

 out_err:
    locked_list_remove(pets, pet, NULL);
    ipmi_domain_attr_put(attr);
    if (pet->timer_info) {
	if (pet->timer) {
	    if (os_hnd->stop_timer(os_hnd, pet->timer) == 0) {
		if (pet->timer_info->lock)
		    ipmi_destroy_lock(pet->timer_info->lock);
		os_hnd->free_timer(os_hnd, pet->timer);
		ipmi_mem_free(pet->timer_info);
	    } else {
		pet->timer_info->cancelled = 1;
	    }
	} else
	    ipmi_mem_free(pet->timer_info);
    }
    ipmi_mem_free(pet);
    return rv;
}
Ejemplo n.º 8
0
static int
test_event_handler_0(ipmi_mc_t    *mc,
		     ipmi_event_t *event,
		     void         *cb_data)
{
    unsigned char    data[13];
    ipmi_domain_t    *domain = ipmi_mc_get_domain(mc);
    ipmi_mc_t        *src_mc;
    ipmi_ipmb_addr_t addr;

    if (ipmi_event_get_type(event) == 0xc0) {
	ipmi_control_id_t id;
	event_info_t      info;
	int               rv;
	ipmi_time_t       timestamp;

	if (ipmi_event_get_data(event, data, 0, 13) != 13)
	    return 0;

	timestamp = ipmi_get_uint32(&data[0]);

	if (timestamp < ipmi_mc_get_startup_SEL_time(mc))
	    /* It's an old event, ignore it. */
	    return 0;

	if (data[6] != 1)
	    /* Wrong version */
	    return 0;

	addr.addr_type = IPMI_IPMB_ADDR_TYPE;
	addr.channel = 0;
	addr.lun = 0;
	addr.slave_addr = data[4];

	/* Find the MC. */
	src_mc = _ipmi_find_mc_by_addr(domain,
				       (ipmi_addr_t *) &addr,
				       sizeof(addr));
	if (!src_mc)
	    return 0;

	id.mcid = ipmi_mc_convert_to_id(src_mc);
	id.lun = 4;
	id.control_num = POWER_CONTROL(data[8]);

	info.err = 0;
	info.event = event;
	info.valid_vals[0] = 1;
	info.vals[0] = data[10];
	info.handled = IPMI_EVENT_NOT_HANDLED;

	rv = ipmi_control_pointer_cb(id, event_control_cb, &info);
	if (!rv)
	    rv = info.err;

	_ipmi_mc_put(src_mc);

	if (!rv)
	    return 1;
    }

    return 0;
}