201
203
int presence_possibly_changed;
202
204
unsigned int presence_event_count; /* Changed when presence
203
205
events are reported. */
206
/* Only allow one presence check at a time. */
207
int in_presence_check;
205
209
/* If the presence changes while the entity is in use, we store it
206
210
in here and the count instead of actually changing it. Then we
297
301
locked_list_t *entities;
300
static void call_fru_handlers(ipmi_entity_t *ent, enum ipmi_update_e op);
304
#define ent_lock(e) ipmi_lock(e->elock)
305
#define ent_unlock(e) ipmi_unlock(e->elock)
301
307
static void entity_mc_active(ipmi_mc_t *mc, int active, void *cb_data);
302
static int call_presence_handlers(ipmi_entity_t *ent, int present,
303
int handled, ipmi_event_t **event);
308
static void call_presence_handlers(ipmi_entity_t *ent, int present);
305
310
/***********************************************************************
518
523
entity_destroy_timer(ent->hot_swap_deact_info);
520
525
if (ent->frudev_present) {
526
_ipmi_domain_mc_lock(ent->domain);
527
_ipmi_mc_get(ent->frudev_mc);
528
_ipmi_domain_mc_unlock(ent->domain);
521
529
ipmi_mc_remove_active_handler(ent->frudev_mc, entity_mc_active, ent);
522
530
_ipmi_mc_release(ent->frudev_mc);
531
_ipmi_mc_put(ent->frudev_mc);
525
534
if (ent->oem_info_cleanup_handler)
653
662
int length = sizeof(entity->name);
655
ipmi_lock(entity->lock);
656
665
length = ipmi_domain_get_name(entity->domain, entity->name, length);
657
666
entity->name[length] = '(';
659
if (entity->info.entity_instance >= 0x60) {
668
if (entity->key.entity_instance >= 0x60) {
660
669
length += snprintf(entity->name+length, IPMI_ENTITY_NAME_LEN-length-3,
662
entity->info.device_num.channel,
663
entity->info.device_num.address,
664
entity->info.entity_id,
665
entity->info.entity_instance - 0x60);
671
entity->key.device_num.channel,
672
entity->key.device_num.address,
673
entity->key.entity_id,
674
entity->key.entity_instance - 0x60);
667
676
length += snprintf(entity->name+length, IPMI_ENTITY_NAME_LEN-length-3,
668
"%d.%d", entity->info.entity_id,
669
entity->info.entity_instance);
677
"%d.%d", entity->key.entity_id,
678
entity->key.entity_instance);
671
680
entity->name[length] = ')';
745
754
_ipmi_entity_put(ipmi_entity_t *ent)
747
756
ipmi_domain_t *domain = ent->domain;
757
int entity_fru_fetch = 0;
748
758
_ipmi_domain_entity_lock(domain);
750
760
if (ent->usecount == 1) {
753
763
ent->info = ent->pending_info;
754
764
/* If the entity became a fru and is present, get its fru info. */
755
765
if (!was_fru && ipmi_entity_get_is_fru(ent) && ent->present)
756
ipmi_entity_fetch_frus(ent);
766
entity_fru_fetch = 1;
757
767
entity_set_name(ent);
758
768
ent->pending_info_ready = 0;
797
if (ent->presence_possibly_changed) {
798
_ipmi_domain_entity_unlock(domain);
799
ipmi_detect_entity_presence_change(ent, 0);
800
_ipmi_domain_entity_lock(domain);
802
if (ent->usecount != 1)
787
806
while (ent->present_change_count) {
789
808
ent->present = !ent->present;
790
809
present = ent->present;
791
810
ent->present_change_count--;
792
811
_ipmi_domain_entity_unlock(domain);
793
call_presence_handlers(ent, present, IPMI_EVENT_NOT_HANDLED, NULL);
812
call_presence_handlers(ent, present);
794
813
_ipmi_domain_entity_lock(domain);
796
815
/* Something grabbed the entity while the lock wasn't
836
/* Wait till here to start fetching FRUs, as we want to report the
837
entity first before we start the fetch. */
838
if (entity_fru_fetch) {
840
ipmi_entity_fetch_frus(ent);
817
843
_ipmi_domain_entity_unlock(domain);
821
847
_ipmi_entity_add_ref(ipmi_entity_t *ent)
823
ipmi_lock(ent->lock);
824
850
ent->ref_count++;
825
ipmi_unlock(ent->lock);
830
856
_ipmi_entity_remove_ref(ipmi_entity_t *ent)
832
ipmi_lock(ent->lock);
833
859
ent->ref_count--;
834
ipmi_unlock(ent->lock);
871
895
search_info_t *info = (search_info_t *) cb_data;
874
same = ((ent->info.device_num.channel == info->device_num.channel)
875
&& (ent->info.device_num.address == info->device_num.address)
876
&& (ent->info.entity_id == info->entity_id)
877
&& (ent->info.entity_instance == info->entity_instance));
898
same = ((ent->key.device_num.channel == info->key.device_num.channel)
899
&& (ent->key.device_num.address == info->key.device_num.address)
900
&& (ent->key.entity_id == info->key.entity_id)
901
&& (ent->key.entity_instance == info->key.entity_instance));
880
904
return LOCKED_LIST_ITER_STOP;
889
913
int entity_instance,
890
914
ipmi_entity_t **found_ent)
892
search_info_t info = {device_num, entity_id, entity_instance, NULL};
916
search_info_t info = { {device_num, entity_id, entity_instance}, NULL};
895
919
locked_list_iterate_nolock(ents->entities, search_entity, &info);
1053
1077
ent->ents = ents;
1055
1079
ent->info.type = IPMI_ENTITY_UNKNOWN;
1056
ent->info.device_num = device_num;
1057
ent->info.entity_id = entity_id;
1058
ent->info.entity_instance = entity_instance;
1080
ent->key.device_num = device_num;
1081
ent->key.entity_id = entity_id;
1082
ent->key.entity_instance = entity_instance;
1059
1083
ent->info.id_type = IPMI_ASCII_STR;
1061
1085
ent->entity_id_string = ipmi_get_entity_id_string(entity_id);
1083
1107
entity_destroy_timer(ent->hot_swap_act_info);
1084
1108
if (ent->hot_swap_deact_info)
1085
1109
entity_destroy_timer(ent->hot_swap_deact_info);
1087
ipmi_destroy_lock(ent->lock);
1111
ipmi_destroy_lock(ent->elock);
1088
1112
if (ent->presence_handlers)
1089
1113
locked_list_destroy(ent->presence_handlers);
1090
1114
if (ent->waitq)
1364
1386
presence_handler_info_t *info = cb_data;
1365
1387
ipmi_entity_presence_change_cb handler = item1;
1368
handled = handler(info->ent, info->present, item2, info->event);
1369
if (handled == IPMI_EVENT_HANDLED) {
1370
info->handled = handled;
1389
handler(info->ent, info->present, item2, NULL);
1373
1390
return LOCKED_LIST_ITER_CONTINUE;
1377
call_presence_handlers(ipmi_entity_t *ent, int present,
1378
int handled, ipmi_event_t **event)
1394
call_presence_handlers(ipmi_entity_t *ent, int present)
1380
1396
presence_handler_info_t info;
1382
1398
info.ent = ent;
1383
1399
info.present = present;
1387
info.event = *event;
1388
info.handled = handled;
1389
ipmi_lock(ent->lock);
1390
1401
if (ent->cruft_presence_handler) {
1391
1402
ipmi_entity_presence_nd_cb handler = ent->cruft_presence_handler;
1392
1403
void *cb_data = ent->cruft_presence_cb_data;
1393
ipmi_unlock(ent->lock);
1394
handler(ent, info.present, cb_data, info.event);
1395
info.handled = IPMI_EVENT_HANDLED;
1405
handler(ent, info.present, cb_data, NULL);
1397
ipmi_unlock(ent->lock);
1398
1408
locked_list_iterate(ent->presence_handlers, call_presence_handler,
1401
*event = info.event;
1402
return info.handled;
1405
1412
/* This is for iterating the parents when a sensor's presence changes.
1420
presence_changed(ipmi_entity_t *ent,
1422
ipmi_event_t *event)
1427
presence_changed(ipmi_entity_t *ent, int present)
1424
int handled = IPMI_EVENT_NOT_HANDLED;
1425
1429
ipmi_fru_t *fru;
1426
1430
ipmi_domain_t *domain = ent->domain;
1436
1440
/* Do internal presence handling if we have the internal
1437
1441
hot-swap machine installed. */
1438
handled = handle_hot_swap_presence(ent, present, event);
1442
handle_hot_swap_presence(ent, present, NULL);
1441
1445
/* When the entity becomes present or absent, fetch or destroy
1448
1452
ent->fru = NULL;
1449
1453
ipmi_fru_destroy_internal(fru, NULL, NULL);
1451
call_fru_handlers(ent, IPMI_DELETED);
1455
_ipmi_entity_call_fru_handlers(ent, IPMI_DELETED);
1459
1463
if (ent->usecount == 1) {
1460
1464
ent->present = !ent->present;
1461
1465
_ipmi_domain_entity_unlock(domain);
1462
handled = call_presence_handlers(ent, present, handled, &event);
1466
call_presence_handlers(ent, present);
1463
1467
_ipmi_domain_entity_lock(domain);
1464
1468
while ((ent->usecount == 1) && (ent->present_change_count)) {
1465
1469
ent->present = !ent->present;
1466
1470
present = ent->present;
1467
1471
ent->present_change_count--;
1468
1472
_ipmi_domain_entity_unlock(domain);
1469
call_presence_handlers(ent, present, handled, NULL);
1473
call_presence_handlers(ent, present);
1470
1474
_ipmi_domain_entity_lock(domain);
1478
1482
rescan them. */
1479
1483
ipmi_entity_iterate_parents(ent, presence_parent_handler, NULL);
1482
if (event && (handled == IPMI_EVENT_NOT_HANDLED))
1483
ipmi_handle_unhandled_event(domain, event);
1508
1512
/* zero offset is the "present" offset, 1 or 2 means it absent or
1509
1513
disabled, coupled with the assertion/deassertion. */
1510
1514
if (dir == IPMI_ASSERTION)
1511
presence_changed(ent, offset == 0, event);
1515
presence_changed(ent, offset == 0);
1512
1516
else if (dir == IPMI_DEASSERTION)
1513
presence_changed(ent, offset != 0, event);
1517
presence_changed(ent, offset != 0);
1514
1518
return IPMI_EVENT_NOT_HANDLED;
1531
1535
/* Assertion means present. */
1532
1536
if (dir == IPMI_ASSERTION)
1533
presence_changed(ent, 1, event);
1537
presence_changed(ent, 1);
1534
1538
else if (dir == IPMI_DEASSERTION)
1535
presence_changed(ent, 0, event);
1539
presence_changed(ent, 0);
1536
1540
return IPMI_EVENT_NOT_HANDLED;
1553
1557
} ent_active_detect_t;
1556
detect_cleanup(ent_active_detect_t *info, ipmi_domain_t *domain)
1560
detect_cleanup(ent_active_detect_t *info, ipmi_entity_t *ent,
1561
ipmi_domain_t *domain)
1558
1563
ipmi_unlock(info->lock);
1559
1564
ipmi_destroy_lock(info->lock);
1560
1565
ipmi_mem_free(info);
1561
_ipmi_put_domain_fully_up(domain);
1567
ent->in_presence_check = 0;
1568
_ipmi_put_domain_fully_up(domain, "detect_cleanup");
1565
1572
detect_done(ipmi_entity_t *ent, ent_active_detect_t *info)
1567
1574
ipmi_unlock(info->lock);
1568
presence_changed(ent, info->present, NULL);
1575
presence_changed(ent, info->present);
1569
1576
ipmi_destroy_lock(info->lock);
1570
1577
ipmi_mem_free(info);
1571
_ipmi_put_domain_fully_up(ent->domain);
1578
ent->in_presence_check = 0;
1579
_ipmi_put_domain_fully_up(ent->domain, "detect_done");
1583
1591
set present and we detect it as not present. However, it
1584
1592
is not possible to detect it as present and for something
1585
1593
else to set it not present. */
1586
detect_cleanup(info, ent->domain);
1594
detect_cleanup(info, ent, ent->domain);
1601
1609
ent_active_detect_t *info = rsp_data;
1604
1611
ipmi_lock(info->lock);
1605
1612
info->msg = rsp;
1606
1613
if (ipmi_entity_pointer_cb(info->ent_id, detect_frudev_handler, info))
1607
detect_cleanup(info, ipmi_mc_get_domain(mc));
1614
/* We cheat and pull the domain from the entity id. The domain
1615
* still has to be around in the place, but we can't rely on the
1616
* MC as it may have gone away if it failed or the domain is in
1618
detect_cleanup(info, NULL, info->ent_id.domain_id.domain);
1610
1621
/* This is the end of the line on checks. We have to report something
1632
1643
/* Send a message to the FRU device and see if we can get some
1645
_ipmi_domain_mc_lock(ent->domain);
1634
1646
_ipmi_mc_get(ent->frudev_mc);
1647
_ipmi_domain_mc_unlock(ent->domain);
1635
1648
rv = ipmi_mc_send_command(ent->frudev_mc, ent->info.lun, &msg,
1636
1649
detect_frudev, info);
1638
_ipmi_mc_put(ent->frudev_mc);
1650
_ipmi_mc_put(ent->frudev_mc);
1639
1652
detect_done(ent, info);
1641
1654
ipmi_unlock(info->lock);
1665
1678
set present and we detect it as not present. However, it
1666
1679
is not possible to detect it as present and for something
1667
1680
else to set it not present. */
1668
detect_cleanup(info, ent->domain);
1681
detect_cleanup(info, ent, ent->domain);
1696
1709
info->done_count++;
1697
1710
if (info->try_count == info->done_count) {
1698
1711
if (ipmi_entity_pointer_cb(info->ent_id, control_detect_handler, info))
1699
detect_cleanup(info, ipmi_control_get_domain(control));
1712
detect_cleanup(info, NULL, ipmi_control_get_domain(control));
1701
1714
ipmi_unlock(info->lock);
1716
1729
info->done_count++;
1717
1730
if (info->try_count == info->done_count) {
1718
1731
if (ipmi_entity_pointer_cb(info->ent_id, control_detect_handler, info))
1719
detect_cleanup(info, ipmi_control_get_domain(control));
1732
detect_cleanup(info, NULL, ipmi_control_get_domain(control));
1721
1734
ipmi_unlock(info->lock);
1737
1750
info->done_count++;
1738
1751
if (info->try_count == info->done_count) {
1739
1752
if (ipmi_entity_pointer_cb(info->ent_id, control_detect_handler, info))
1740
detect_cleanup(info, ipmi_control_get_domain(control));
1753
detect_cleanup(info, NULL, ipmi_control_get_domain(control));
1742
1755
ipmi_unlock(info->lock);
1758
1771
info->done_count++;
1759
1772
if (info->try_count == info->done_count) {
1760
1773
if (ipmi_entity_pointer_cb(info->ent_id, control_detect_handler, info))
1761
detect_cleanup(info, ipmi_control_get_domain(control));
1774
detect_cleanup(info, NULL, ipmi_control_get_domain(control));
1763
1776
ipmi_unlock(info->lock);
1805
1818
info->done_count = 0;
1806
1819
ipmi_entity_iterate_controls(ent, control_detect_send, info);
1808
/* I couldn't message any sensors, go on. */
1821
/* I couldn't message any controls, go on. */
1809
1822
if (info->try_count == 1)
1811
1824
info->done_count++;
1829
1842
set present and we detect it as not present. However, it
1830
1843
is not possible to detect it as present and for something
1831
1844
else to set it not present. */
1832
detect_cleanup(info, ent->domain);
1845
detect_cleanup(info, ent, ent->domain);
1862
1875
info->done_count++;
1863
1876
if (info->try_count == info->done_count) {
1864
1877
if (ipmi_entity_pointer_cb(info->ent_id, sensor_detect_handler, info))
1865
detect_cleanup(info, ipmi_sensor_get_domain(sensor));
1878
detect_cleanup(info, NULL, ipmi_sensor_get_domain(sensor));
1867
1880
ipmi_unlock(info->lock);
1885
1898
info->done_count++;
1886
1899
if (info->try_count == info->done_count) {
1887
1900
if (ipmi_entity_pointer_cb(info->ent_id, sensor_detect_handler, info))
1888
detect_cleanup(info, ipmi_sensor_get_domain(sensor));
1901
detect_cleanup(info, NULL, ipmi_sensor_get_domain(sensor));
1890
1903
ipmi_unlock(info->lock);
1948
1961
detect = ipmi_mem_alloc(sizeof(*detect));
1950
_ipmi_put_domain_fully_up(ent->domain);
1963
ent->in_presence_check = 0;
1964
_ipmi_put_domain_fully_up(ent->domain,
1965
"detect_no_presence_sensor_presence");
1953
1968
rv = ipmi_create_lock(ent->domain, &detect->lock);
1955
_ipmi_put_domain_fully_up(ent->domain);
1970
ent->in_presence_check = 0;
1971
_ipmi_put_domain_fully_up(ent->domain,
1972
"detect_no_presence_sensor_presence(2)");
1956
1973
ipmi_mem_free(detect);
2001
2022
/* The present bit is supported. */
2002
2023
present = ipmi_is_state_set(states, 0);
2004
presence_changed(ent, present, NULL);
2005
_ipmi_put_domain_fully_up(ipmi_sensor_get_domain(sensor));
2025
presence_changed(ent, present);
2026
ent->in_presence_check = 0;
2027
_ipmi_put_domain_fully_up(ipmi_sensor_get_domain(sensor), "states_read");
2015
2037
ipmi_entity_t *ent = cb_data;
2040
_ipmi_domain_entity_lock(ent->domain);
2041
_ipmi_entity_get(ent);
2042
_ipmi_domain_entity_unlock(ent->domain);
2018
2043
detect_no_presence_sensor_presence(ent);
2044
_ipmi_entity_put(ent);
2022
2048
present = ipmi_is_state_set(states, ent->presence_bit_offset);
2023
presence_changed(ent, present, NULL);
2024
_ipmi_put_domain_fully_up(ipmi_sensor_get_domain(sensor));
2049
presence_changed(ent, present);
2050
ent->in_presence_check = 0;
2051
_ipmi_put_domain_fully_up(ipmi_sensor_get_domain(sensor),
2030
2058
ent_detect_info_t *info = cb_data;
2033
if ((!info->force) && (! ent->presence_possibly_changed))
2062
if (ent->in_presence_check
2063
|| ((!info->force) && (! ent->presence_possibly_changed)))
2035
2068
ent->presence_possibly_changed = 0;
2069
ent->in_presence_check = 1;
2037
if (ent->hot_swappable)
2071
if (ent->hot_swappable) {
2038
2073
ipmi_entity_check_hot_swap_state(ent);
2040
_ipmi_get_domain_fully_up(ent->domain);
2077
_ipmi_get_domain_fully_up(ent->domain, "ent_detect_presence");
2041
2078
if (ent->presence_sensor) {
2042
2079
/* Presence sensor overrides everything. */
2043
rv = ipmi_sensor_id_get_states(ent->presence_sensor_id,
2046
_ipmi_put_domain_fully_up(ent->domain);
2080
ipmi_sensor_id_t psi = ent->presence_sensor_id;
2082
rv = ipmi_sensor_id_get_states(psi, states_read, ent);
2084
ent->in_presence_check = 0;
2085
_ipmi_put_domain_fully_up(ent->domain, "ent_detect_presence(2)");
2047
2087
} else if (ent->presence_bit_sensor) {
2048
2088
/* Presence bit sensor overrides everything but a presence sensor. */
2049
rv = ipmi_sensor_id_get_states(ent->presence_bit_sensor_id,
2050
states_bit_read, ent);
2052
_ipmi_put_domain_fully_up(ent->domain);
2089
ipmi_sensor_id_t psi = ent->presence_bit_sensor_id;
2091
rv = ipmi_sensor_id_get_states(psi, states_bit_read, ent);
2093
ent->in_presence_check = 0;
2094
_ipmi_put_domain_fully_up(ent->domain, "ent_detect_presence(3)");
2054
2098
detect_no_presence_sensor_presence(ent);
2111
2158
ent->presence_sensor_id = ipmi_sensor_convert_to_id(sensor);
2159
ent->presence_sensor = sensor;
2113
2161
/* If we have a presence sensor, remove the presence bit sensor. */
2114
2162
if (ent->presence_bit_sensor) {
2163
ent->presence_bit_sensor = NULL;
2115
2164
ipmi_sensor_remove_discrete_event_handler(ent->presence_bit_sensor,
2116
2165
presence_sensor_changed,
2118
ent->presence_bit_sensor = NULL;
2121
2169
event_support = ipmi_sensor_get_event_support(sensor);
2154
2202
ipmi_discrete_event_set(&events, 1, IPMI_DEASSERTION);
2157
2206
ipmi_sensor_set_event_enables(sensor, &events, NULL, NULL);
2160
2210
ent->presence_possibly_changed = 1;
2220
/* Must be called with the entity lock held. May release and reclaim it. */
2171
handle_new_presence_bit_sensor(ipmi_entity_t *ent, ipmi_sensor_t *sensor)
2222
handle_new_presence_bit_sensor(ipmi_entity_t *ent, ipmi_sensor_t *sensor,
2173
2225
ipmi_event_state_t events;
2174
2226
int event_support;
2228
ent->presence_bit_sensor = sensor;
2229
ent->presence_bit_offset = bit;
2176
2230
ent->presence_bit_sensor_id = ipmi_sensor_convert_to_id(sensor);
2178
2232
event_support = ipmi_sensor_get_event_support(sensor);
2485
2541
CHECK_ENTITY_LOCK(ent);
2487
2544
if (is_presence_sensor(sensor) && (ent->presence_sensor == NULL)
2488
2545
&& (ent->presence_bit_sensor == NULL))
2490
2547
/* It's the presence sensor and we don't already have one. We
2491
2548
keep this special. */
2492
ent->presence_sensor = sensor;
2493
2549
handle_new_presence_sensor(ent, sensor);
2494
2550
} else if ((ent->presence_sensor == NULL)
2495
2551
&& (ent->presence_bit_sensor == NULL)
2496
2552
&& is_presence_bit_sensor(sensor, &bit))
2498
2554
/* If it's a sensor with a presence bit, we use it. */
2499
ent->presence_bit_sensor = sensor;
2500
ent->presence_bit_offset = bit;
2501
handle_new_presence_bit_sensor(ent, sensor);
2555
handle_new_presence_bit_sensor(ent, sensor, bit);
2504
2558
if (is_hot_swap_requester(sensor) && (ent->hot_swap_requester == NULL)) {
2505
2559
handle_new_hot_swap_requester(ent, sensor);
2508
2563
locked_list_add_entry(ent->sensors, sensor, NULL, link);
2553
2607
info->is_presence = is_presence_bit_sensor(sensor, &info->bit);
2554
2608
if (info->is_presence) {
2555
2609
info->sensor = sensor;
2556
ent->presence_bit_sensor = sensor;
2557
ent->presence_bit_offset = info->bit;
2558
handle_new_presence_bit_sensor(ent, sensor);
2610
handle_new_presence_bit_sensor(ent, sensor, info->bit);
2614
/* Must be called with the entity lock held. May release and reclaim it. */
2563
2616
check_for_another_presence_sensor(ipmi_entity_t *ent, ipmi_sensor_t *old)
2602
2656
if (sensor == ent->hot_swap_requester) {
2603
2657
ent->hot_swap_requester = NULL;
2606
2661
if (! locked_list_remove(ent->sensors, sensor, NULL)) {
2607
2662
ipmi_log(IPMI_LOG_WARNING,
2621
2676
CHECK_ENTITY_LOCK(ent);
2623
2679
if (is_hot_swap_power(control))
2624
2680
handle_new_hot_swap_power(ent, control);
2625
2681
if (is_hot_swap_indicator(control))
2626
2682
handle_new_hot_swap_indicator(ent, control);
2628
2685
locked_list_add_entry(ent->controls, control, NULL, link);
2629
2686
ent->presence_possibly_changed = 1;
2648
2706
if (control == ent->hot_swap_indicator)
2649
2707
ent->hot_swap_indicator = NULL;
2651
2710
if (! locked_list_remove(ent->controls, control, NULL)) {
2652
2711
ipmi_log(IPMI_LOG_WARNING,
2674
2733
ipmi_sensor_t *sensor = item1;
2676
2735
ipmi_mc_t *mc = ipmi_sensor_get_mc(sensor);
2736
ipmi_domain_t *domain;
2740
domain = ipmi_mc_get_domain(mc);
2741
_ipmi_domain_mc_lock(domain);
2680
2742
rv = _ipmi_mc_get(mc);
2743
_ipmi_domain_mc_unlock(domain);
2683
2746
rv = _ipmi_sensor_get(sensor);
2738
2801
ipmi_control_t *control = item1;
2740
2803
ipmi_mc_t *mc = ipmi_control_get_mc(control);
2804
ipmi_domain_t *domain = ipmi_mc_get_domain(mc);
2808
_ipmi_domain_mc_lock(domain);
2744
2809
rv = _ipmi_mc_get(mc);
2810
_ipmi_domain_mc_unlock(domain);
2747
2813
rv = _ipmi_control_get(control);
2858
2924
gdlr_output(ipmi_entity_t *ent, ipmi_sdr_info_t *sdrs, void *cb_data)
2862
dlr_info_t *info = &ent->info;
2928
dlr_info_t *info = &ent->info;
2864
2930
memset(&sdr, 0, sizeof(sdr));
2921
2988
info->entity_instance = sdr->data[8];
2922
2989
info->oem = sdr->data[9];
2923
2990
str = sdr->data + 10;
2924
info->id_len = ipmi_get_device_string(&str, sdr->length-10,
2925
info->id, IPMI_STR_SDR_SEMANTICS, 0,
2926
&info->id_type, ENTITY_ID_LEN);
2991
rv = ipmi_get_device_string(&str, sdr->length-10,
2992
info->id, IPMI_STR_SDR_SEMANTICS, 0,
2993
&info->id_type, ENTITY_ID_LEN, &info->id_len);
2932
2999
frudlr_output(ipmi_entity_t *ent, ipmi_sdr_info_t *sdrs, void *cb_data)
2936
dlr_info_t *info = &ent->info;
3003
dlr_info_t *info = &ent->info;
2938
3005
memset(&sdr, 0, sizeof(sdr));
2992
3060
info->entity_id = sdr->data[7];
2993
3061
info->entity_instance = sdr->data[8];
2994
3062
str = sdr->data + 10;
2995
info->id_len = ipmi_get_device_string(&str,
2997
info->id, IPMI_STR_SDR_SEMANTICS, 0,
2998
&info->id_type, ENTITY_ID_LEN);
3063
rv = ipmi_get_device_string(&str,
3065
info->id, IPMI_STR_SDR_SEMANTICS, 0,
3066
&info->id_type, ENTITY_ID_LEN, &info->id_len);
3004
3072
mcdlr_output(ipmi_entity_t *ent, ipmi_sdr_info_t *sdrs, void *cb_data)
3008
dlr_info_t *info = &ent->info;
3076
dlr_info_t *info = &ent->info;
3010
3078
memset(&sdr, 0, sizeof(sdr));
3031
3099
sdr.data[4] = 0;
3032
3100
sdr.data[5] = 0;
3033
3101
sdr.data[6] = 0;
3034
sdr.data[7] = ent->info.entity_id;
3035
sdr.data[8] = ent->info.entity_instance;
3102
sdr.data[7] = ent->key.entity_id;
3103
sdr.data[8] = ent->key.entity_instance;
3036
3104
sdr.data[9] = info->oem;
3038
3106
ipmi_set_device_string(info->id,
3100
3169
info->oem = sdr->data[9];
3101
3170
str = sdr->data + 10;
3102
info->id_len = ipmi_get_device_string(&str,
3104
info->id, IPMI_STR_SDR_SEMANTICS, 0,
3105
&info->id_type, ENTITY_ID_LEN);
3171
rv = ipmi_get_device_string(&str,
3173
info->id, IPMI_STR_SDR_SEMANTICS, 0,
3174
&info->id_type, ENTITY_ID_LEN, &info->id_len);
3108
3177
/* Make sure the FRU fetch stuff works. */
3281
3350
ent = found->ent;
3282
3351
while ((j > 0) && (ent == (infos->found+j)->ent)) {
3284
3352
if ((infos->found+j)->found)
3286
3354
if ((infos->dlrs[j]->type != IPMI_ENTITY_EAR)
3287
3355
&& (infos->dlrs[j]->type != IPMI_ENTITY_DREAR))
3289
3357
found = infos->found+j;
3291
3359
/* Since this is an EAR and we are putting it's entries in
3292
3360
another place, ignore this one. */
3293
3361
(infos->found+i)->found = 1;
3296
3366
if (infos->dlrs[i]->is_ranges) {
3344
3414
put_entities(entity_sdr_info_t *infos)
3346
3416
entity_found_t *found;
3349
3419
for (i=0; i<infos->next; i++) {
3350
3420
found = infos->found+i;
3355
3422
if (found->ent)
3356
3423
_ipmi_entity_put(found->ent);
3425
/* Still put the entity even if found, as it was refcounted by
3358
3430
for (j=0; j<found->cent_next; j++)
3359
3431
_ipmi_entity_put(found->cent[j]);
4178
ipmi_entity_get_mc_id(ipmi_entity_t *ent, ipmi_mcid_t *mc_id)
4180
ipmi_ipmb_addr_t sa;
4183
if ((ent->info.type != IPMI_ENTITY_MC)
4184
&& (ent->info.type != IPMI_ENTITY_GENERIC))
4189
sa.addr_type = IPMI_IPMB_ADDR_TYPE;
4190
sa.channel = ent->info.channel;
4191
sa.slave_addr = ent->info.slave_address;
4192
sa.lun = ent->info.lun;
4194
mc = _ipmi_find_mc_by_addr(ent->domain, (ipmi_addr_t *) &sa, sizeof(sa));
4198
*mc_id = ipmi_mc_convert_to_id(mc);
4106
4205
ipmi_entity_get_lun(ipmi_entity_t *ent)
4108
4207
CHECK_ENTITY_LOCK(ent);
4355
4454
if (length > ENTITY_ID_LEN)
4356
4455
length = ENTITY_ID_LEN;
4358
ipmi_lock(ent->lock);
4359
4458
memcpy(ent->info.id, id, length);
4360
4459
ent->info.id_type = type;
4361
4460
ent->info.id_len = length;
4362
ipmi_unlock(ent->lock);
4363
4462
entity_set_name(ent);
4695
4794
CHECK_ENTITY_LOCK(ent);
4697
4796
val.domain_id = ent->domain_id;
4698
val.entity_id = ent->info.entity_id;
4699
val.entity_instance = ent->info.entity_instance;
4700
val.channel = ent->info.device_num.channel;
4701
val.address = ent->info.device_num.address;
4797
val.entity_id = ent->key.entity_id;
4798
val.entity_instance = ent->key.entity_instance;
4799
val.channel = ent->key.device_num.channel;
4800
val.address = ent->key.device_num.address;
4702
4801
val.seq = ent->seq;
4955
5054
ent->fru = info->fru;
4957
call_fru_handlers(ent, op);
5056
_ipmi_entity_call_fru_handlers(ent, op);
4959
5058
ipmi_log(IPMI_LOG_WARNING,
4960
5059
"%sentity.c(fru_fetched_ent_cb):"
4961
5060
"Error fetching entity %d.%d FRU: %x",
4962
5061
ENTITY_NAME(ent),
4963
ent->info.entity_id, ent->info.entity_instance, info->err);
5062
ent->key.entity_id, ent->key.entity_instance, info->err);
4964
5063
if ((ent->fru) && (info->fru))
4965
5064
/* Keep the old FRU on errors. */
4966
5065
ipmi_fru_destroy_internal(info->fru, NULL, NULL);
4968
5067
/* Keep it if we got it, it might have some useful
4969
5068
information. */
4970
5069
ent->fru = info->fru;
4971
call_fru_handlers(ent, IPMI_CHANGED);
5070
_ipmi_entity_call_fru_handlers(ent, IPMI_CHANGED);
4989
5088
ipmi_fru_destroy_internal(fru, NULL, NULL);
4991
5090
ipmi_mem_free(ent_id);
4992
_ipmi_put_domain_fully_up(domain);
5092
_ipmi_put_domain_fully_up(domain, "fru_fetched_handler");
5039
5139
return ent->fru;
5143
_ipmi_entity_set_fru(ipmi_entity_t *ent, ipmi_fru_t *fru)
5145
CHECK_ENTITY_LOCK(ent);
5148
ipmi_fru_destroy_internal(ent->fru, NULL, NULL);
5042
5152
/***************************************************************************
5133
5243
handled = handler(info->ent, info->last_state, info->curr_state,
5134
5244
item2, *(info->event));
5135
if (handled == IPMI_EVENT_HANDLED) {
5136
info->handled = handled;
5137
*(info->event) = NULL;
5245
if (handled != IPMI_EVENT_NOT_HANDLED) {
5246
if (info->handled != IPMI_EVENT_HANDLED)
5247
/* Allow handled to override handled_pass, but not the
5249
info->handled = handled;
5250
if (handled == IPMI_EVENT_HANDLED)
5251
*(info->event) = NULL;
5139
5253
return LOCKED_LIST_ITER_CONTINUE;
5152
5266
info.last_state = last_state;
5153
5267
info.curr_state = curr_state;
5154
5268
info.event = event;
5155
info.handled = IPMI_EVENT_NOT_HANDLED;
5270
info.handled = *handled;
5272
info.handled = IPMI_EVENT_NOT_HANDLED;
5156
5273
locked_list_iterate(ent->hot_swap_handlers, call_hot_swap_handler, &info);
5158
5275
*handled = info.handled;
5322
ipmi_entity_supports_auto_deactivate_time(ipmi_entity_t *ent)
5324
return (ent->hot_swappable && ent->hs_cb.get_auto_activate);
5199
5328
ipmi_entity_set_auto_deactivate_time(ipmi_entity_t *ent,
5200
5329
ipmi_timeout_t auto_deact,
5201
5330
ipmi_entity_cb done,
5534
5663
" Unable to set the hot swap power: %x",
5535
5664
CONTROL_NAME(control), err);
5537
ipmi_lock(ent->lock);
5538
5667
set_hot_swap_state(ent, IPMI_HOT_SWAP_ACTIVE, NULL);
5539
ipmi_unlock(ent->lock);
5551
5680
" Unable to set the hot swap power: %x",
5552
5681
CONTROL_NAME(control), err);
5554
ipmi_lock(ent->lock);
5555
5684
set_hot_swap_state(ent, IPMI_HOT_SWAP_INACTIVE, NULL);
5556
ipmi_unlock(ent->lock);
5576
5705
" Unable to set the hot swap power: %x",
5577
5706
CONTROL_NAME(control), err);
5579
ipmi_lock(ent->lock);
5580
5709
set_hot_swap_state(ent, IPMI_HOT_SWAP_ACTIVE, NULL);
5581
ipmi_unlock(ent->lock);
5584
5713
if (info->handler)
5598
5727
" Unable to set the hot swap power: %x",
5599
5728
CONTROL_NAME(control), err);
5601
ipmi_lock(ent->lock);
5602
5731
set_hot_swap_state(ent, IPMI_HOT_SWAP_INACTIVE, NULL);
5603
ipmi_unlock(ent->lock);
5606
5735
if (info->handler)
5838
5971
if (old_state != state) {
5839
5972
ent->hot_swap_state = state;
5840
ipmi_unlock(ent->lock);
5841
5974
ipmi_entity_call_hot_swap_handlers(ent, old_state, state, &event,
5843
ipmi_lock(ent->lock);
5846
5979
return handled;
5955
6087
&ent->hot_swap_ind_req_deact,
5956
6088
&ent->hot_swap_ind_inact);
5958
ipmi_lock(ent->lock);
5959
6090
ent->hot_swap_indicator_id = ipmi_control_convert_to_id(control);
5960
6091
ent->hot_swap_indicator = control;
5961
6092
switch (ent->hot_swap_state)
5982
6113
val = ent->hot_swap_ind_inact;
5985
ipmi_unlock(ent->lock);
5987
6118
rv = ipmi_control_set_val(control, &val, NULL, NULL);
5989
6121
ipmi_log(IPMI_LOG_SEVERE,
5990
6122
"%sentity.c(handle_new_hot_swap_indicator): Unable to"
6044
ipmi_lock(ent->lock);
6046
6178
set_hot_swap_state(ent, IPMI_HOT_SWAP_ACTIVE, NULL);
6048
6180
set_hot_swap_state(ent, IPMI_HOT_SWAP_INACTIVE, NULL);
6050
6182
if (ent->hot_swap_requester) {
6051
rv = ipmi_sensor_id_get_states(ent->hot_swap_requester_id,
6183
ipmi_sensor_id_t hsr = ent->hot_swap_requester_id;
6185
rv = ipmi_sensor_id_get_states(hsr, requester_checked, ent);
6055
6187
ipmi_log(IPMI_LOG_SEVERE,
6056
6188
"%sentity.c(power_checked): Unable to"
6057
6189
" request requester status, error %x",
6058
6190
SENSOR_NAME(ent->hot_swap_requester), rv);
6061
ipmi_unlock(ent->lock);
6086
6217
ipmi_entity_set_supports_managed_hot_swap(ent, 1);
6088
6219
if (ent->hot_swappable) {
6089
6221
rv = ipmi_control_get_val(control, power_checked, ent);
6091
6224
ipmi_log(IPMI_LOG_SEVERE,
6092
6225
"%sentity.c(handle_new_hot_swap_power): Unable to"
6158
6291
IPMI_DEASSERTION);
6161
6295
ipmi_sensor_set_event_enables(sensor, &events, NULL, NULL);
6163
6298
if (ent->hot_swappable) {
6164
rv = ipmi_sensor_id_get_states(ent->hot_swap_requester_id,
6299
ipmi_sensor_id_t hsr = ent->hot_swap_requester_id;
6301
rv = ipmi_sensor_id_get_states(hsr, requester_checked, ent);
6168
6304
ipmi_log(IPMI_LOG_SEVERE,
6169
6305
"%sentity.c(handle_new_hot_swap_requester): Unable to"
6193
6328
/* No power control or immediate timeout, it goes straight
6195
6330
handled = set_hot_swap_state(ent, IPMI_HOT_SWAP_ACTIVE, event);
6197
rv = ipmi_control_id_get_val(ent->hot_swap_power_id, power_checked,
6333
ipmi_control_id_t hsp = ent->hot_swap_power_id;
6335
rv = ipmi_control_id_get_val(hsp, power_checked, ent);
6200
6337
ipmi_log(IPMI_LOG_SEVERE,
6201
6338
"%sentity.c(handle_hot_swap_presence): Unable to"
6434
ipmi_lock(info->ent->lock);
6571
ent_lock(info->ent);
6435
6572
if (ipmi_is_state_set(states, info->ent->hot_swap_offset)
6436
6573
== info->ent->hot_swap_requesting_val)
6440
ipmi_unlock(info->ent->lock);
6577
ent_unlock(info->ent);
6442
6579
info->handler(info->ent, err, val, info->cb_data);
6443
6580
ipmi_mem_free(info);
6533
6670
ipmi_log(IPMI_LOG_SEVERE,
6534
"%sentity.c(power_chedked): Unable to"
6671
"%sentity.c(check_power): Unable to"
6535
6672
" get power value, error %x",
6536
6673
CONTROL_NAME(control), err);
6537
6674
ipmi_mem_free(info);
6541
6678
info->power = val[0];
6543
ipmi_lock(ent->lock);
6544
6681
if (ent->hot_swap_requester) {
6545
rv = ipmi_sensor_id_get_states(ent->hot_swap_requester_id,
6682
ipmi_sensor_id_t hsr = ent->hot_swap_requester_id;
6684
rv = ipmi_sensor_id_get_states(hsr, check_requester, info);
6549
6686
ipmi_log(IPMI_LOG_SEVERE,
6550
"%sentity.c(power_checked): Unable to"
6687
"%sentity.c(check_power): Unable to"
6551
6688
" request requester status, error %x",
6552
6689
SENSOR_NAME(ent->hot_swap_requester), rv);
6553
6690
ipmi_mem_free(info);
6557
6694
set_hot_swap_state(ent, IPMI_HOT_SWAP_ACTIVE, NULL);
6559
6696
set_hot_swap_state(ent, IPMI_HOT_SWAP_INACTIVE, NULL);
6560
6698
ipmi_mem_free(info);
6562
ipmi_unlock(ent->lock);
6566
6703
e_check_hot_swap_state(ipmi_entity_t *ent)
6568
6705
hs_check_t *info;
6570
6708
info = ipmi_mem_alloc(sizeof(*info));
6574
6712
info->entity = ent;
6575
6713
info->power = 1; /* Assume power is on if no power control. */
6577
ipmi_lock(ent->lock);
6578
if (ent->hot_swap_power)
6579
ipmi_control_id_get_val(ent->hot_swap_power_id, check_power, info);
6580
else if (ent->hot_swap_requester)
6581
ipmi_sensor_id_get_states(ent->hot_swap_requester_id, check_requester,
6584
ipmi_mem_free(info);
6585
ipmi_unlock(ent->lock);
6716
if (ent->hot_swap_power) {
6717
ipmi_control_id_t hsp = ent->hot_swap_power_id;
6719
rv = ipmi_control_id_get_val(hsp, check_power, info);
6720
} else if (ent->hot_swap_requester) {
6721
ipmi_sensor_id_t hsr = ent->hot_swap_requester_id;
6723
rv = ipmi_sensor_id_get_states(hsr, check_requester, info);
6726
ipmi_mem_free(info);
6730
ipmi_mem_free(info);
6746
6891
info->__handler(entity, 0, info->__cb_data);
6750
6895
entity_opq_ready(void *cb_data, int shutdown)
6752
6897
ipmi_entity_op_info_t *info = cb_data;
6760
6905
ENTITY_NAME(info->__entity));
6761
6906
if (info->__handler)
6762
6907
info->__handler(info->__entity, ECANCELED, info->__cb_data);
6908
return OPQ_HANDLER_STARTED;
6766
6911
rv = ipmi_entity_pointer_cb(info->__entity_id, entity_opq_ready2, info);
6837
6984
"Could not convert entity id to a pointer, entity was"
6838
6985
" probably destroyed while operation was in progress",
6840
if (info->__rsp_handler)
6987
if (info->__rsp_handler) {
6988
_ipmi_domain_entity_lock(info->__entity->domain);
6989
info->__entity->usecount++;
6990
_ipmi_domain_entity_unlock(info->__entity->domain);
6841
6991
info->__rsp_handler(info->__entity, rv, NULL, info->__cb_data);
6992
_ipmi_entity_put(info->__entity);