798
846
domain->in_shutdown = 0;
799
847
domain->usecount = 1;
849
domain->stats = locked_list_alloc(domain->os_hnd);
850
if (!domain->stats) {
851
ipmi_mem_free(domain);
855
domain->con_stat_info = ipmi_ll_con_alloc_stat_info();
856
if (!domain->con_stat_info) {
857
locked_list_destroy(domain->stats);
858
ipmi_mem_free(domain);
861
ipmi_ll_con_stat_info_set_register(domain->con_stat_info,
863
ipmi_ll_con_stat_info_set_adder(domain->con_stat_info, con_add_stat);
864
ipmi_ll_con_stat_info_set_unregister(domain->con_stat_info,
865
con_unregister_stat);
866
ipmi_ll_con_stat_set_user_data(domain->con_stat_info, domain);
801
868
for (i=0; i<num_con; i++) {
869
int len1 = strlen(domain->name);
802
870
domain->conn[i] = ipmi[i];
803
domain->con_ipmb_addr[i] = 0x20; /* Assume this until told othersize */
871
for (j=0; j<MAX_IPMI_USED_CHANNELS; j++)
872
domain->con_ipmb_addr[i][j] = 0x20;
804
873
domain->con_active[i] = 1;
805
874
domain->con_up[i] = 0;
806
ipmi[i]->name = ipmi_mem_alloc(10);
875
ipmi[i]->name = ipmi_mem_alloc(len1 + 11);
807
876
if (ipmi[i]->name)
808
snprintf(ipmi[i]->name, 10, "%d", i);
877
snprintf(ipmi[i]->name, len1 + 11, "%s%d ", domain->name, i);
809
878
ipmi[i]->user_data = domain;
811
880
for (j=0; j<MAX_PORTS_PER_CON; j++)
812
881
domain->port_up[j][i] = -1;
883
if (ipmi[i]->register_stat_handler)
884
ipmi[i]->register_stat_handler(ipmi[i], domain->con_stat_info);
815
887
domain->connection_up = 0;
2463
2561
void *bus_scan_handler_cb_data;
2465
2563
ipmi_lock(domain->mc_lock);
2466
domain->scanning_bus = 0;
2564
domain->scanning_bus_count--;
2565
if (domain->scanning_bus_count) {
2566
_ipmi_put_domain_fully_up(domain, "mc_scan_done");
2567
ipmi_unlock(domain->mc_lock);
2467
2571
bus_scan_handler = domain->bus_scan_handler;
2468
2572
bus_scan_handler_cb_data = domain->bus_scan_handler_cb_data;
2469
2573
ipmi_unlock(domain->mc_lock);
2470
2574
if (bus_scan_handler)
2471
2575
bus_scan_handler(domain, 0,
2472
2576
bus_scan_handler_cb_data);
2473
_ipmi_put_domain_fully_up(domain);
2477
_ipmi_mc_scan_done(ipmi_domain_t *domain)
2479
mc_scan_done(domain, 0, NULL);
2484
start_mc_scan(ipmi_domain_t *domain)
2577
_ipmi_put_domain_fully_up(domain, "mc_scan_done");
2581
_ipmi_start_mc_scan_one(ipmi_domain_t *domain, int chan, int first, int last)
2585
_ipmi_get_domain_fully_up(domain, "_ipmi_start_mc_scan_one");
2586
domain->scanning_bus_count++;
2587
rv = ipmi_start_ipmb_mc_scan(domain, chan, first, last,
2588
mc_scan_done, NULL);
2590
domain->scanning_bus_count--;
2591
_ipmi_put_domain_fully_up(domain, "_ipmi_start_mc_scan_one");
2596
cmp_int(const void *v1, const void *v2)
2609
ipmi_domain_start_full_ipmb_scan(ipmi_domain_t *domain)
2615
if (domain->in_shutdown)
2488
2618
ipmi_lock(domain->mc_lock);
2489
2619
if (!domain->do_bus_scan || (!ipmi_option_IPMB_scan(domain))) {
2490
2620
/* Always scan the local BMC(s). */
2492
2621
for (i=0; i<MAX_CONS; i++) {
2493
2622
if (!domain->conn[i])
2495
_ipmi_get_domain_fully_up(domain);
2496
ipmi_start_ipmb_mc_scan(domain, 0, domain->con_ipmb_addr[i],
2497
domain->con_ipmb_addr[i], bmc_scan_done,
2624
for (j=0; j<MAX_IPMI_USED_CHANNELS; j++) {
2625
if (domain->chan[j].medium != IPMI_CHANNEL_MEDIUM_IPMB)
2627
_ipmi_start_mc_scan_one(domain, j,
2628
domain->con_ipmb_addr[i][j],
2629
domain->con_ipmb_addr[i][j]);
2632
if (j == MAX_IPMI_USED_CHANNELS) {
2633
/* Didn't find a valid channel, just scan 0 to get one. */
2634
_ipmi_start_mc_scan_one(domain, 0,
2635
domain->con_ipmb_addr[i][0],
2636
domain->con_ipmb_addr[i][0]);
2500
2639
ipmi_unlock(domain->mc_lock);
2504
if (domain->scanning_bus) {
2643
if (domain->scanning_bus_count) {
2505
2644
ipmi_unlock(domain->mc_lock);
2509
domain->scanning_bus = 1;
2510
ipmi_unlock(domain->mc_lock);
2512
2648
/* If a connections supports sysaddress scanning, then scan the
2513
2649
system address for that connection. */
2514
2650
for (i=0; i<MAX_CONS; i++) {
2515
2651
if ((domain->con_up[i]) && domain->conn[i]->scan_sysaddr) {
2516
_ipmi_get_domain_fully_up(domain);
2517
ipmi_start_si_scan(domain, i, mc_scan_done, NULL);
2652
_ipmi_get_domain_fully_up(domain,
2653
"ipmi_domain_start_full_ipmb_scan");
2654
domain->scanning_bus_count++;
2655
rv = ipmi_start_si_scan(domain, i, mc_scan_done, NULL);
2657
domain->scanning_bus_count--;
2658
_ipmi_put_domain_fully_up(domain,
2659
"ipmi_domain_start_full_ipmb_scan");
2521
2664
/* Now start the IPMB scans. */
2522
2665
for (i=0; i<MAX_IPMI_USED_CHANNELS; i++) {
2523
if (domain->chan[i].medium == 1) { /* IPMB */
2524
/* Always scan the normal BMC first, but don't report scan
2526
_ipmi_get_domain_fully_up(domain);
2527
ipmi_start_ipmb_mc_scan(domain, i, 0x20, 0x20, bmc_scan_done,
2529
_ipmi_get_domain_fully_up(domain);
2530
ipmi_start_ipmb_mc_scan(domain, i, 0x10, 0xf0, mc_scan_done, NULL);
2666
if (domain->chan[i].medium == IPMI_CHANNEL_MEDIUM_IPMB) {
2669
/* Always scan the normal BMC first. */
2670
_ipmi_start_mc_scan_one(domain, i, 0x20, 0x20);
2671
_ipmi_start_mc_scan_one(domain, i, 0x10, 0xf0);
2673
/* This is unfortunately complicated. We only want
2674
the BMC to show up in one place, so we only scan
2675
the BMC's address on the first one. If we have a
2676
system with two connections (two BMCs), we want to
2677
make sure they don't show up on each others lists.
2678
So except for the first IPMB, we ignore all BMC
2680
int ignore_addr[MAX_CONS];
2683
for (j=0; j<MAX_CONS; j++) {
2684
if (! domain->conn[j])
2686
ignore_addr[num_ignore] = domain->con_ipmb_addr[j][i];
2689
qsort(ignore_addr, num_ignore, sizeof(int), cmp_int);
2690
for (j=0; j<num_ignore; j++) {
2691
_ipmi_start_mc_scan_one(domain, i,
2692
cstart, ignore_addr[j]-1);
2693
cstart = ignore_addr[j]+1;
2696
_ipmi_start_mc_scan_one(domain, i, cstart, 0xf0);
2700
ipmi_unlock(domain->mc_lock);
2663
2839
if ((type == 0x02) && !ipmi_event_is_old(event)) {
2664
2840
/* It's a standard IPMI event. */
2666
ipmi_ipmb_addr_t addr;
2667
2842
ipmi_sensor_id_t id;
2668
2843
event_sensor_info_t info;
2669
2844
const unsigned char *data;
2671
data = ipmi_event_get_data_ptr(event);
2672
addr.addr_type = IPMI_IPMB_ADDR_TYPE;
2673
/* See if the MC has an OEM handler for this. */
2674
if (data[6] == 0x03) {
2677
addr.channel = data[5] >> 4;
2679
if ((data[4] & 0x01) == 0) {
2680
addr.slave_addr = data[4];
2682
/* A software ID, assume it comes from the MC where we go it. */
2685
ipmi_mc_get_ipmi_address(ev_mc, &iaddr, NULL);
2686
addr.slave_addr = ipmi_addr_get_slave_addr(&iaddr);
2687
if (addr.slave_addr == 0)
2688
/* A system interface, just assume it's the BMC. */
2689
addr.slave_addr = 0x20;
2693
mc = _ipmi_find_mc_by_addr(domain, (ipmi_addr_t *) &addr, sizeof(addr));
2846
mc = _ipmi_event_get_generating_mc(domain, ev_mc, event);
4500
ipmi_domain_get_connection_args(ipmi_domain_t *domain,
4503
CHECK_DOMAIN_LOCK(domain);
4505
if (con >= MAX_CONS)
4508
if (!domain->conn[con])
4511
if (! domain->conn[con]->get_startup_args)
4514
return domain->conn[con]->get_startup_args(domain->conn[con]);
4518
ipmi_domain_get_connection_type(ipmi_domain_t *domain,
4519
unsigned int connection)
4521
CHECK_DOMAIN_LOCK(domain);
4523
if (connection >= MAX_CONS)
4526
if (!domain->conn[connection])
4529
return domain->conn[connection]->con_type;
4533
ipmi_domain_get_connection(ipmi_domain_t *domain,
4534
unsigned int connection)
4536
CHECK_DOMAIN_LOCK(domain);
4538
if (connection >= MAX_CONS)
4541
if (!domain->conn[connection])
4544
if (! domain->conn[connection]->use_connection)
4547
domain->conn[connection]->use_connection(domain->conn[connection]);
4548
return domain->conn[connection];
4325
4551
/* If the activate timer is not running, then start it. This
4326
4552
allows some time for other connections to become active before
4327
4553
we go off and start activating things. We wait a random amount
4376
4604
goto out_unlock;
4378
old_addr = domain->con_ipmb_addr[u];
4606
memcpy(old_addr, domain->con_ipmb_addr[u], sizeof(old_addr));
4380
domain->con_ipmb_addr[u] = ipmb;
4608
for (i=0; i<num_ipmb_addr && i<MAX_IPMI_USED_CHANNELS; i++) {
4611
domain->con_ipmb_addr[u][i] = ipmb_addr[i];
4382
4614
if (!domain->in_startup) {
4383
4615
/* Only scan the IPMBs if we are not in startup. Otherwise things
4384
4616
get reported before we are ready. */
4385
if (ipmb != old_addr) {
4386
/* First scan the old address to remove it. */
4387
if (domain->con_ipmb_addr[u] != 0)
4388
ipmi_start_ipmb_mc_scan(domain, 0, old_addr, old_addr,
4617
for (i=0; i<num_ipmb_addr && i<MAX_IPMI_USED_CHANNELS; i++) {
4620
if (ipmb_addr[i] != old_addr[i]) {
4621
/* First scan the old address to remove it. */
4622
if (domain->con_ipmb_addr[u] != 0)
4623
ipmi_start_ipmb_mc_scan(domain, i,
4624
old_addr[i], old_addr[i],
4628
/* Scan the new address. Even though the address may not have
4629
changed, it may have changed modes and need to be rescanned. */
4630
ipmi_start_ipmb_mc_scan(domain, i, ipmb_addr[i], ipmb_addr[i],
4392
/* Scan the new address. Even though the address may not have
4393
changed, it may have changed modes and need to be rescanned. */
4394
ipmi_start_ipmb_mc_scan(domain, 0, ipmb, ipmb, NULL, NULL);
4397
4635
/* If we are not activating connections, just use whatever we get