~ubuntu-branches/ubuntu/vivid/openipmi/vivid

« back to all changes in this revision

Viewing changes to lib/domain.c

  • Committer: Bazaar Package Importer
  • Author(s): Noèl Köthe
  • Date: 2006-09-15 17:56:24 UTC
  • mfrom: (1.1.2 upstream) (2.1.1 etch)
  • Revision ID: james.westby@ubuntu.com-20060915175624-ljk0mg3xtcm65tvm
Tags: 2.0.7-1
* new upstream release from 2006-06-08
  Thanks to John Wright <john.wright hp.com> for initial work
  (closes: Bug#380149)
* updated Standards Version
* new binaries openipmicmd, openipmish, rmcp_ping

Show diffs side-by-side

added added

removed removed

Lines of Context:
33
33
 
34
34
#include <string.h>
35
35
#include <stdio.h>
 
36
#include <stdlib.h>
36
37
 
37
38
#include <OpenIPMI/ipmi_conn.h>
38
39
#include <OpenIPMI/ipmiif.h>
213
214
    ipmi_domain_shutdown_cb shutdown_handler;
214
215
 
215
216
    /* Are we in the middle of an MC bus scan? */
216
 
    int scanning_bus;
 
217
    int scanning_bus_count;
217
218
 
218
219
    ipmi_entity_info_t    *entities;
219
220
    ipmi_lock_t           *entities_lock;
222
223
    int           working_conn;
223
224
    ipmi_con_t    *conn[MAX_CONS];
224
225
    int           con_active[MAX_CONS];
225
 
    unsigned char con_ipmb_addr[MAX_CONS];
 
226
    unsigned char con_ipmb_addr[MAX_CONS][MAX_IPMI_USED_CHANNELS];
226
227
 
227
228
    int           con_up[MAX_CONS];
228
229
 
232
233
    /* Are any low-level connections up? */
233
234
    int connection_up;
234
235
 
 
236
    /* If we got some type of invalid return from the BMC, we mark
 
237
       this and retry at audit intervals. */
 
238
    int got_invalid_dev_id;
 
239
 
235
240
    /* Are we in the process of connecting? */
236
241
    int connecting;
237
242
 
312
317
    ipmi_domain_entity_cb cruft_entity_update_handler;
313
318
    void                  *cruft_entity_update_cb_data;
314
319
 
 
320
    ipmi_ll_stat_info_t *con_stat_info;
 
321
 
315
322
    /* Option processing */
316
323
    unsigned int option_all : 1;
317
324
    unsigned int option_SDRs : 1;
322
329
    unsigned int option_set_event_rcvr : 1;
323
330
    unsigned int option_set_sel_time : 1;
324
331
    unsigned int option_activate_if_possible : 1;
 
332
    unsigned int option_local_only : 1;
 
333
    unsigned int option_local_only_set : 1;
325
334
};
326
335
 
327
336
/* A list of all domains in the system. */
329
338
 
330
339
static void domain_audit(void *cb_data, os_hnd_timer_id_t *id);
331
340
 
 
341
static int domain_send_mc_id(ipmi_domain_t *domain);
 
342
 
332
343
static void cancel_domain_oem_check(ipmi_domain_t *domain);
333
344
 
334
345
static void real_close_connection(ipmi_domain_t *domain);
341
352
                           int          still_connected,
342
353
                           void         *cb_data);
343
354
 
344
 
static void ll_addr_changed(ipmi_con_t   *ipmi,
345
 
                            int          err,
346
 
                            unsigned int ipmb,
347
 
                            int          active,
348
 
                            unsigned int hacks,
349
 
                            void         *cb_data);
 
355
static void ll_addr_changed(ipmi_con_t    *ipmi,
 
356
                            int           err,
 
357
                            const unsigned char ipmb_addr[],
 
358
                            unsigned int  num_ipmb_addr,
 
359
                            int           active,
 
360
                            unsigned int  hacks,
 
361
                            void          *cb_data);
350
362
 
351
363
/***********************************************************************
352
364
 *
417
429
 *
418
430
 **********************************************************************/
419
431
void
420
 
_ipmi_get_domain_fully_up(ipmi_domain_t *domain)
 
432
_ipmi_get_domain_fully_up(ipmi_domain_t *domain, char *name)
421
433
{
422
434
    if (!domain->domain_fully_up)
423
435
        return;
427
439
}
428
440
 
429
441
void
430
 
_ipmi_put_domain_fully_up(ipmi_domain_t *domain)
 
442
_ipmi_put_domain_fully_up(ipmi_domain_t *domain, char *name)
431
443
{
432
444
    if (!domain->domain_fully_up)
433
445
        return;
499
511
    locked_list_iterate(domain_change_handlers, iterate_domain_changes, &info);
500
512
}
501
513
 
 
514
int
 
515
_ipmi_domain_in_shutdown(ipmi_domain_t *domain)
 
516
{
 
517
    return domain->in_shutdown;
 
518
}
 
519
 
502
520
static void
503
521
iterate_cleanup_mc(ipmi_domain_t *domain, ipmi_mc_t *mc, void *cb_data)
504
522
{
518
536
static void
519
537
cleanup_domain(ipmi_domain_t *domain)
520
538
{
521
 
    int i;
522
 
    int rv;
 
539
    unsigned int i;
 
540
    int          rv;
523
541
 
524
542
    /* This must be first, so that nuking the oustanding messages will
525
543
       cause the right thing to happen. */
720
738
    if (domain->entities_lock)
721
739
        ipmi_destroy_lock(domain->entities_lock);
722
740
 
723
 
    /* If it has not been reported yet, in_startup will be true and we
724
 
       don't want to report the delete. */
725
 
    if (!domain->in_startup)
726
 
        call_domain_change(domain, IPMI_DELETED);
 
741
    call_domain_change(domain, IPMI_DELETED);
727
742
 
728
743
    /* The MC list should no longer have anything in it. */
729
744
    if (domain->mc_upd_handlers)
741
756
    if (domain->oem_data && domain->oem_data_destroyer)
742
757
        domain->oem_data_destroyer(domain, domain->oem_data);
743
758
 
 
759
    if (domain->con_stat_info)
 
760
        ipmi_ll_con_free_stat_info(domain->con_stat_info);
 
761
 
744
762
    /* Locks must be last, because they can be used by many things. */
745
763
    if (domain->ipmb_ignores_lock)
746
764
        ipmi_destroy_lock(domain->ipmb_ignores_lock);
757
775
    ipmi_mem_free(domain);
758
776
}
759
777
 
 
778
static int con_register_stat(ipmi_ll_stat_info_t *info,
 
779
                             const char          *name,
 
780
                             const char          *instance,
 
781
                             void                **stat)
 
782
{
 
783
    ipmi_domain_stat_t *rstat;
 
784
    int                rv;
 
785
    ipmi_domain_t      *domain = ipmi_ll_con_stat_get_user_data(info);
 
786
 
 
787
    rv = ipmi_domain_stat_register(domain, name, instance, &rstat);
 
788
    if (!rv)
 
789
        *stat = rstat;
 
790
    return rv;
 
791
}
 
792
 
 
793
static void con_add_stat(ipmi_ll_stat_info_t *info,
 
794
                         void                *stat,
 
795
                         int                 value)
 
796
{
 
797
    ipmi_domain_stat_add(stat, value);
 
798
}
 
799
 
 
800
static void con_unregister_stat(ipmi_ll_stat_info_t *info,
 
801
                                void                *stat)
 
802
{
 
803
    ipmi_domain_stat_put(stat);
 
804
}
 
805
 
760
806
static int
761
807
setup_domain(char          *name,
762
808
             ipmi_con_t    *ipmi[],
784
830
    domain->option_set_event_rcvr = 1;
785
831
    domain->option_set_sel_time = 1;
786
832
    domain->option_activate_if_possible = 1;
 
833
    domain->option_local_only = 0;
 
834
    domain->option_local_only_set = 0;
787
835
 
788
836
    strncpy(domain->name, name, sizeof(domain->name)-2);
789
837
    i = strlen(domain->name);
798
846
    domain->in_shutdown = 0;
799
847
    domain->usecount = 1;
800
848
 
 
849
    domain->stats = locked_list_alloc(domain->os_hnd);
 
850
    if (!domain->stats) {
 
851
        ipmi_mem_free(domain);
 
852
        return ENOMEM;
 
853
    }
 
854
 
 
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);
 
859
        return ENOMEM;
 
860
    }
 
861
    ipmi_ll_con_stat_info_set_register(domain->con_stat_info,
 
862
                                       con_register_stat);
 
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);
 
867
 
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;
810
879
 
811
880
        for (j=0; j<MAX_PORTS_PER_CON; j++)
812
881
            domain->port_up[j][i] = -1;
 
882
 
 
883
        if (ipmi[i]->register_stat_handler)
 
884
            ipmi[i]->register_stat_handler(ipmi[i], domain->con_stat_info);
813
885
    }
814
886
 
815
887
    domain->connection_up = 0;
869
941
        goto out_err;
870
942
    }
871
943
 
872
 
    domain->stats = locked_list_alloc(domain->os_hnd);
873
 
    if (!domain->stats) {
874
 
        rv = ENOMEM;
875
 
        goto out_err;
876
 
    }
877
 
 
878
944
    domain->do_bus_scan = 1;
879
945
 
880
946
    si.addr_type = IPMI_SYSTEM_INTERFACE_ADDR_TYPE;
887
953
        goto out_err;
888
954
    _ipmi_mc_use(domain->si_mc);
889
955
 
 
956
    /* Force this one to always be active, so anything that uses it is
 
957
       always ready to go.  Since it represents the connection, it
 
958
       really can't ever go inactive. */
 
959
    _ipmi_mc_force_active(domain->si_mc, 1);
 
960
 
890
961
    rv = ipmi_sdr_info_alloc(domain, domain->si_mc, 0, 0, &domain->main_sdrs);
891
962
    if (rv)
892
963
        goto out_err;
968
1039
    if (domain->si_mc)
969
1040
        _ipmi_mc_put(domain->si_mc);
970
1041
 
971
 
    if (rv)
 
1042
    if (rv) {
 
1043
        for (i=0; i<num_con; i++) {
 
1044
            if (ipmi[i]->register_stat_handler)
 
1045
                ipmi[i]->unregister_stat_handler(ipmi[i],
 
1046
                                                 domain->con_stat_info);
 
1047
        }
972
1048
        cleanup_domain(domain);
973
 
    else
 
1049
    } else
974
1050
        *new_domain = domain;
975
1051
 
976
1052
    return rv;
1412
1488
}
1413
1489
 
1414
1490
static int
1415
 
in_ipmb_ignores(ipmi_domain_t *domain, unsigned char ipmb_addr)
 
1491
in_ipmb_ignores(ipmi_domain_t *domain,
 
1492
                unsigned char channel,
 
1493
                unsigned char ipmb_addr)
1416
1494
{
1417
1495
    unsigned long addr;
1418
 
    unsigned char first, last;
 
1496
    unsigned char first, last, ichan;
1419
1497
    ilist_iter_t iter;
1420
1498
    int          rv = 0;
1421
1499
 
1426
1504
        addr = (unsigned long) ilist_get(&iter);
1427
1505
        first = addr & 0xff;
1428
1506
        last = (addr >> 8) & 0xff;
1429
 
        if ((ipmb_addr >= first) && (ipmb_addr <= last))
 
1507
        ichan = (addr >> 16) & 0xff;
 
1508
        if ((ichan == channel) && (ipmb_addr >= first) && (ipmb_addr <= last))
1430
1509
            rv = 1;
1431
1510
    }
1432
1511
    ipmi_unlock(domain->ipmb_ignores_lock);
1435
1514
}
1436
1515
 
1437
1516
int
1438
 
ipmi_domain_add_ipmb_ignore(ipmi_domain_t *domain, unsigned char ipmb_addr)
 
1517
ipmi_domain_add_ipmb_ignore(ipmi_domain_t *domain,
 
1518
                            unsigned char channel,
 
1519
                            unsigned char ipmb_addr)
1439
1520
{
1440
 
    unsigned long addr = ipmb_addr | (ipmb_addr << 8);
 
1521
    unsigned long addr = ipmb_addr | (ipmb_addr << 8) | (channel << 16);
1441
1522
    int           rv = 0;
1442
1523
 
1443
1524
    ipmi_lock(domain->ipmb_ignores_lock);
1450
1531
 
1451
1532
int
1452
1533
ipmi_domain_add_ipmb_ignore_range(ipmi_domain_t *domain,
 
1534
                                  unsigned char channel,
1453
1535
                                  unsigned char first_ipmb_addr,
1454
1536
                                  unsigned char last_ipmb_addr)
1455
1537
{
1456
 
    unsigned long addr = first_ipmb_addr | (last_ipmb_addr << 8);
 
1538
    unsigned long addr = (first_ipmb_addr | (last_ipmb_addr << 8)
 
1539
                          | (channel << 16));
1457
1540
    int           rv = 0;
1458
1541
 
1459
1542
    ipmi_lock(domain->ipmb_ignores_lock);
1739
1822
    rspi = nmsg->rsp_item;
1740
1823
    if (nmsg->rsp_handler) {
1741
1824
        ipmi_move_msg_item(rspi, orspi);
 
1825
        memcpy(&rspi->addr, &orspi->addr, orspi->addr_len);
 
1826
        rspi->addr_len = orspi->addr_len;
1742
1827
        deliver_rsp(domain, nmsg->rsp_handler, rspi);
1743
1828
    } else
1744
1829
        ipmi_free_msg_item(rspi);
1788
1873
        ipmi_ipmb_addr_t *ipmb = (ipmi_ipmb_addr_t *) addr;
1789
1874
        int              i;
1790
1875
 
1791
 
        if (ipmb->channel != 0)
 
1876
        if (ipmb->channel >= MAX_IPMI_USED_CHANNELS)
 
1877
            return 0;
 
1878
 
 
1879
        if (domain->chan[ipmb->channel].medium != IPMI_CHANNEL_MEDIUM_IPMB)
1792
1880
            return 0;
1793
1881
 
1794
1882
        for (i=0; i<MAX_CONS; i++) {
1795
1883
            if (domain->con_active[i]
1796
1884
                && domain->con_up[i]
1797
 
                && (domain->con_ipmb_addr[i] == ipmb->slave_addr)
 
1885
                && (domain->con_ipmb_addr[i][ipmb->channel]==ipmb->slave_addr)
1798
1886
                && domain->sys_intf_mcs[i])
1799
1887
            {
1800
1888
                si->addr_type = IPMI_SYSTEM_INTERFACE_ADDR_TYPE;
1915
2003
    rspi = ipmi_alloc_msg_item();
1916
2004
    if (!rspi) {
1917
2005
        rv = ENOMEM;
1918
 
        goto out;
 
2006
        goto out_unlock;
1919
2007
    }
1920
2008
 
1921
2009
    rspi->data1 = domain;
2024
2112
void
2025
2113
ipmi_domain_set_ipmb_rescan_time(ipmi_domain_t *domain, unsigned int seconds)
2026
2114
{
 
2115
    int            rv;
 
2116
    struct timeval timeout;
 
2117
 
2027
2118
    CHECK_DOMAIN_LOCK(domain);
2028
2119
 
 
2120
    ipmi_lock(domain->audit_domain_timer_info->lock);
2029
2121
    domain->audit_domain_interval = seconds;
 
2122
    rv = domain->os_hnd->stop_timer(domain->os_hnd,
 
2123
                                    domain->audit_domain_timer);
 
2124
    if (rv) {
 
2125
        /* If we can't stop the timer, that's ok, the timer is in the
 
2126
           wakeup and will handle the restart for us. */
 
2127
        ipmi_unlock(domain->audit_domain_timer_info->lock);
 
2128
        return;
 
2129
    }
 
2130
    timeout.tv_sec = domain->audit_domain_interval;
 
2131
    timeout.tv_usec = 0;
 
2132
    domain->os_hnd->start_timer(domain->os_hnd,
 
2133
                                domain->audit_domain_timer,
 
2134
                                &timeout,
 
2135
                                domain_audit,
 
2136
                                domain->audit_domain_timer_info);
 
2137
    ipmi_unlock(domain->audit_domain_timer_info->lock);
2030
2138
}
2031
2139
 
2032
2140
unsigned int
2119
2227
    }
2120
2228
    ipmb->slave_addr += 2;
2121
2229
    info->missed_responses = 0;
2122
 
    if (in_ipmb_ignores(domain, ipmb->slave_addr))
 
2230
    if (in_ipmb_ignores(domain, ipmb->channel, ipmb->slave_addr))
2123
2231
        goto next_addr_nolock;
2124
2232
 
2125
2233
 retry_addr:
2285
2393
    }
2286
2394
    ipmb->slave_addr += 2;
2287
2395
    info->missed_responses = 0;
2288
 
    if (in_ipmb_ignores(domain, ipmb->slave_addr))
 
2396
    if (in_ipmb_ignores(domain, ipmb->channel, ipmb->slave_addr))
2289
2397
        goto next_addr_nolock;
2290
2398
 
2291
2399
 retry_addr:
2355
2463
        goto out_err;
2356
2464
 
2357
2465
    /* Skip addresses we must ignore. */
2358
 
    while ((in_ipmb_ignores(domain, ipmb->slave_addr))
 
2466
    while ((in_ipmb_ignores(domain, ipmb->channel, ipmb->slave_addr))
2359
2467
           && (ipmb->slave_addr <= end_addr))
2360
2468
    {
2361
2469
        ipmb->slave_addr += 2;
2379
2487
    return 0;
2380
2488
 
2381
2489
 out_err:
2382
 
    if (info->done_handler)
2383
 
        info->done_handler(domain, rv, info->cb_data);
2384
2490
    if (info->timer)
2385
2491
        info->os_hnd->free_timer(info->os_hnd, info->timer);
2386
2492
    if (info->lock)
2390
2496
                 return true.  Bus scans always succeed. */
2391
2497
}
2392
2498
 
2393
 
void
 
2499
int
2394
2500
ipmi_start_si_scan(ipmi_domain_t  *domain,
2395
2501
                   int            si_num,
2396
2502
                   ipmi_domain_cb done_handler,
2402
2508
 
2403
2509
    info = ipmi_mem_alloc(sizeof(mc_ipmb_scan_info_t));
2404
2510
    if (!info) 
2405
 
        return;
 
2511
        return ENOMEM;
2406
2512
    memset(info, 0, sizeof(*info));
2407
2513
 
2408
2514
    info->domain = domain;
2433
2539
                                &(info->msg),
2434
2540
                                devid_bc_rsp_handler,
2435
2541
                                info, NULL);
2436
 
 
2437
2542
    if (rv)
2438
2543
        goto out_err;
2439
2544
    else
2440
2545
        add_bus_scans_running(domain, info);
2441
 
    return;
 
2546
    return 0;
2442
2547
 
2443
2548
 out_err:
2444
 
    if (info->done_handler)
2445
 
        info->done_handler(domain, rv, info->cb_data);
2446
2549
    if (info->timer)
2447
2550
        info->os_hnd->free_timer(info->os_hnd, info->timer);
2448
2551
    if (info->lock)
2449
2552
        ipmi_destroy_lock(info->lock);
2450
2553
    ipmi_mem_free(info);
2451
 
}
2452
 
 
2453
 
static void
2454
 
bmc_scan_done(ipmi_domain_t *domain, int err, void *cb_data)
2455
 
{
2456
 
    _ipmi_put_domain_fully_up(domain);
 
2554
    return rv;
2457
2555
}
2458
2556
 
2459
2557
static void
2463
2561
    void           *bus_scan_handler_cb_data;
2464
2562
 
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);
 
2568
        return;
 
2569
    }
 
2570
 
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);
2474
 
}
2475
 
 
2476
 
void
2477
 
_ipmi_mc_scan_done(ipmi_domain_t *domain)
2478
 
{
2479
 
    mc_scan_done(domain, 0, NULL);
2480
 
}
2481
 
 
2482
 
 
2483
 
static void
2484
 
start_mc_scan(ipmi_domain_t *domain)
2485
 
{
2486
 
    int i;
 
2577
    _ipmi_put_domain_fully_up(domain, "mc_scan_done");
 
2578
}
 
2579
 
 
2580
void
 
2581
_ipmi_start_mc_scan_one(ipmi_domain_t *domain, int chan, int first, int last)
 
2582
{
 
2583
    int rv;
 
2584
 
 
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);
 
2589
    if (rv) {
 
2590
        domain->scanning_bus_count--;
 
2591
        _ipmi_put_domain_fully_up(domain, "_ipmi_start_mc_scan_one");
 
2592
    }
 
2593
}
 
2594
 
 
2595
static int
 
2596
cmp_int(const void *v1, const void *v2)
 
2597
{
 
2598
    const int *i1 = v1;
 
2599
    const int *i2 = v2;
 
2600
    if (*i1 < *i2)
 
2601
        return -1;
 
2602
    else if (*i2 > *i2)
 
2603
        return 1;
 
2604
    else
 
2605
        return 0;
 
2606
}
 
2607
 
 
2608
void
 
2609
ipmi_domain_start_full_ipmb_scan(ipmi_domain_t *domain)
 
2610
{
 
2611
    int i, j;
 
2612
    int rv;
 
2613
    int got_bmc = 0;
 
2614
 
 
2615
    if (domain->in_shutdown)
 
2616
        return;
2487
2617
 
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). */
2491
 
        int i;
2492
2621
        for (i=0; i<MAX_CONS; i++) {
2493
2622
            if (!domain->conn[i])
2494
2623
                continue;
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,
2498
 
                                    NULL);
 
2624
            for (j=0; j<MAX_IPMI_USED_CHANNELS; j++) {
 
2625
                if (domain->chan[j].medium != IPMI_CHANNEL_MEDIUM_IPMB)
 
2626
                    continue;
 
2627
                _ipmi_start_mc_scan_one(domain, j,
 
2628
                                        domain->con_ipmb_addr[i][j],
 
2629
                                        domain->con_ipmb_addr[i][j]);
 
2630
                break;
 
2631
            }
 
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]);
 
2637
            }
2499
2638
        }
2500
2639
        ipmi_unlock(domain->mc_lock);
2501
2640
        return;
2502
2641
    }
2503
2642
 
2504
 
    if (domain->scanning_bus) {
 
2643
    if (domain->scanning_bus_count) {
2505
2644
        ipmi_unlock(domain->mc_lock);
2506
2645
        return;
2507
2646
    }
2508
2647
 
2509
 
    domain->scanning_bus = 1;
2510
 
    ipmi_unlock(domain->mc_lock);
2511
 
 
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);
 
2656
            if (rv) {
 
2657
                domain->scanning_bus_count--;
 
2658
                _ipmi_put_domain_fully_up(domain,
 
2659
                                          "ipmi_domain_start_full_ipmb_scan");
 
2660
            }
2518
2661
        }
2519
2662
    }
2520
2663
 
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
2525
 
               done on it. */
2526
 
            _ipmi_get_domain_fully_up(domain);
2527
 
            ipmi_start_ipmb_mc_scan(domain, i, 0x20, 0x20, bmc_scan_done,
2528
 
                                    NULL);
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) {
 
2667
            if (!got_bmc) {
 
2668
                got_bmc = 1;
 
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);
 
2672
            } else {
 
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
 
2679
                   IPMB addresses. */
 
2680
                int ignore_addr[MAX_CONS];
 
2681
                int num_ignore = 0;
 
2682
                int cstart = 0x10;
 
2683
                for (j=0; j<MAX_CONS; j++) {
 
2684
                    if (! domain->conn[j])
 
2685
                        continue;
 
2686
                    ignore_addr[num_ignore] = domain->con_ipmb_addr[j][i];
 
2687
                    num_ignore++;
 
2688
                }
 
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;
 
2694
                }
 
2695
                if (cstart <= 0xf0)
 
2696
                    _ipmi_start_mc_scan_one(domain, i, cstart, 0xf0);
 
2697
            }
2531
2698
        }
2532
2699
    }
 
2700
    ipmi_unlock(domain->mc_lock);
2533
2701
}
2534
2702
 
2535
2703
static void
2577
2745
    if (rv)
2578
2746
        goto out;
2579
2747
 
 
2748
    if (domain->got_invalid_dev_id) {
 
2749
        /* Failure getting device id, just try again. */
 
2750
        domain_send_mc_id(domain);
 
2751
        goto out_start_timer;
 
2752
    }
 
2753
 
2580
2754
    /* Only operate if we know a connection is up. */
2581
 
    if (domain->connection_up) {
2582
 
        /* Rescan all the presence sensors to make sure they are valid. */
2583
 
        ipmi_detect_domain_presence_changes(domain, 1);
2584
 
 
2585
 
        start_mc_scan(domain);
2586
 
 
2587
 
        /* Also check to see if the SDRs have changed. */
2588
 
        check_main_sdrs(domain);
2589
 
    }
2590
 
 
 
2755
    if (! domain->connection_up)
 
2756
        goto out_start_timer;
 
2757
 
 
2758
    /* Rescan all the presence sensors to make sure they are valid. */
 
2759
    ipmi_detect_domain_presence_changes(domain, 1);
 
2760
    
 
2761
    ipmi_domain_start_full_ipmb_scan(domain);
 
2762
 
 
2763
    /* Also check to see if the SDRs have changed. */
 
2764
    check_main_sdrs(domain);
 
2765
 
 
2766
 out_start_timer:
2591
2767
    timeout.tv_sec = domain->audit_domain_interval;
2592
2768
    timeout.tv_usec = 0;
2593
2769
    domain->os_hnd->start_timer(domain->os_hnd,
2663
2839
    if ((type == 0x02) && !ipmi_event_is_old(event)) {
2664
2840
        /* It's a standard IPMI event. */
2665
2841
        ipmi_mc_t           *mc;
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;
2670
2845
 
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) {
2675
 
            addr.channel = 0;
2676
 
        } else {
2677
 
            addr.channel = data[5] >> 4;
2678
 
        }
2679
 
        if ((data[4] & 0x01) == 0) {
2680
 
            addr.slave_addr = data[4];
2681
 
        } else {
2682
 
            /* A software ID, assume it comes from the MC where we go it. */
2683
 
            ipmi_addr_t iaddr;
2684
 
 
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;
2690
 
        }
2691
 
        addr.lun = 0;
2692
 
 
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);
2694
2847
        if (!mc)
2695
2848
            goto out;
2696
2849
 
2702
2855
        }
2703
2856
 
2704
2857
        /* The OEM code didn't handle it. */
 
2858
        data = ipmi_event_get_data_ptr(event);
2705
2859
        id.mcid = ipmi_mc_convert_to_id(mc);
2706
2860
        id.lun = data[5] & 0x3;
2707
2861
        id.sensor_num = data[8];
2746
2900
            if (domain->conn[i] == ipmi)
2747
2901
                break;
2748
2902
        }
 
2903
        if (i == MAX_CONS)
 
2904
            goto out;
2749
2905
        addr = (ipmi_addr_t *) &si;
2750
2906
        si.addr_type = IPMI_SYSTEM_INTERFACE_ADDR_TYPE;
2751
2907
        si.channel = i;
3620
3776
            domain->close_count++;
3621
3777
    }
3622
3778
    for (i=0; i<MAX_CONS; i++) {
3623
 
        if (ipmi[i])
 
3779
        if (ipmi[i]) {
 
3780
            if (ipmi[i]->register_stat_handler)
 
3781
                ipmi[i]->unregister_stat_handler(ipmi[i],
 
3782
                                                 domain->con_stat_info);
3624
3783
            ipmi[i]->close_connection_done(ipmi[i], conn_close, domain);
 
3784
        }
3625
3785
    }
3626
3786
}
3627
3787
 
3717
3877
    } else if (domain->in_startup) {
3718
3878
        domain->in_startup = 0;
3719
3879
        ipmi_unlock(domain->con_lock);
3720
 
 
3721
 
        /* We have to call the domain change before we call the
3722
 
           connection change handlers.  This way, the user is informed
3723
 
           of the domain before any OEM handlers get called to start
3724
 
           adding entities and the like. */
3725
 
        call_domain_change(domain, IPMI_ADDED);
3726
3880
    } else
3727
3881
        ipmi_unlock(domain->con_lock);
3728
3882
 
3738
3892
    ipmi_domain_cb     SDRs_read_handler;
3739
3893
    void               *SDRs_read_handler_cb_data;
3740
3894
 
 
3895
    if (domain->in_shutdown)
 
3896
        return;
 
3897
 
3741
3898
    /* This is an unusual looking piece of code, but is required for
3742
3899
       systems that do not have an IPMB.  If they don't have an IPMB,
3743
3900
       then we won't scan them and thus won't find anything.  So we
3749
3906
    if (i == MAX_IPMI_USED_CHANNELS) {
3750
3907
        domain->chan[0].medium = 1;
3751
3908
        /* If these fail it's really no big deal. */
3752
 
        ipmi_domain_add_ipmb_ignore_range(domain, 0x00, 0x1e);
3753
 
        ipmi_domain_add_ipmb_ignore_range(domain, 0x22, 0xfe);
 
3909
        ipmi_domain_add_ipmb_ignore_range(domain, 0, 0x00, 0x1e);
 
3910
        ipmi_domain_add_ipmb_ignore_range(domain, 0, 0x22, 0xfe);
3754
3911
    }
3755
3912
 
3756
3913
    domain->connection_up = 1;
3772
3929
    if (con_up_handler)
3773
3930
        con_up_handler(domain, con_up_handler_cb_data);
3774
3931
 
3775
 
    start_mc_scan(domain);
 
3932
    ipmi_domain_start_full_ipmb_scan(domain);
3776
3933
 
3777
3934
    ipmi_detect_ents_presence_changes(domain->entities, 1);
3778
3935
 
3784
3941
    ipmi_unlock(domain->domain_lock);
3785
3942
    if (SDRs_read_handler)
3786
3943
        SDRs_read_handler(domain, 0, SDRs_read_handler_cb_data);
3787
 
    _ipmi_put_domain_fully_up(domain);
 
3944
    _ipmi_put_domain_fully_up(domain, "con_up_complete");
3788
3945
}
3789
3946
 
3790
3947
static void
4016
4173
                         "IPMI version of the BMC is %d.%d, which is older"
4017
4174
                         " than OpenIPMI supports",
4018
4175
                         DOMAIN_NAME(domain), major_version, minor_version);
 
4176
                domain->got_invalid_dev_id = 1;
4019
4177
                call_con_fails(domain, ENOSYS, 0, 0, 0);
4020
4178
                return;
4021
4179
            }
4025
4183
                 "Invalid return from IPMI Get Device ID, something is"
4026
4184
                 " seriously wrong with the BMC",
4027
4185
                 DOMAIN_NAME(domain));
 
4186
        domain->got_invalid_dev_id = 1;
4028
4187
        call_con_fails(domain, rv, 0, 0, 0);
4029
4188
        return;
4030
4189
    }
4031
4190
 
 
4191
    domain->got_invalid_dev_id = 0;
 
4192
 
4032
4193
    /* Get the information from the MC, not the message, since it may have
4033
4194
       been fixed up. */
4034
4195
    domain->major_version = ipmi_mc_major_version(mc);
4053
4214
 
4054
4215
    if (domain->major_version < 1) {
4055
4216
        /* We only support 1.0 and greater. */
 
4217
        domain->got_invalid_dev_id = 0;
4056
4218
        call_con_fails(domain, EINVAL, 0, 0, 0);
4057
4219
        return;
4058
4220
    }
4101
4263
static void start_activate_timer(ipmi_domain_t *domain);
4102
4264
 
4103
4265
static void
4104
 
initial_ipmb_addr_cb(ipmi_con_t   *ipmi,
4105
 
                     int          err,
4106
 
                     unsigned int ipmb,
4107
 
                     int          active,
4108
 
                     unsigned int hacks,
4109
 
                     void         *cb_data)
 
4266
initial_ipmb_addr_cb(ipmi_con_t    *ipmi,
 
4267
                     int           err,
 
4268
                     const unsigned char ipmb_addr[],
 
4269
                     unsigned int  num_ipmb_addr,
 
4270
                     int           active,
 
4271
                     unsigned int  hacks,
 
4272
                     void          *cb_data)
4110
4273
{
4111
4274
    ipmi_domain_t *domain = cb_data;
4112
4275
    int           u;
4307
4470
    return 0;
4308
4471
}
4309
4472
 
 
4473
int
 
4474
_ipmi_domain_get_connection(ipmi_domain_t *domain,
 
4475
                            int           con_num,
 
4476
                            ipmi_con_t    **con)
 
4477
{
 
4478
    if (con_num >= MAX_CONS)
 
4479
        return EINVAL;
 
4480
    *con = domain->conn[con_num];
 
4481
    return 0;
 
4482
}
 
4483
 
4310
4484
void
4311
4485
ipmi_domain_iterate_connections(ipmi_domain_t          *domain,
4312
4486
                                ipmi_connection_ptr_cb handler,
4322
4496
    }
4323
4497
}
4324
4498
 
 
4499
ipmi_args_t *
 
4500
ipmi_domain_get_connection_args(ipmi_domain_t *domain,
 
4501
                                unsigned int  con)
 
4502
{
 
4503
    CHECK_DOMAIN_LOCK(domain);
 
4504
 
 
4505
    if (con >= MAX_CONS)
 
4506
        return NULL;
 
4507
 
 
4508
    if (!domain->conn[con])
 
4509
        return NULL;
 
4510
 
 
4511
    if (! domain->conn[con]->get_startup_args)
 
4512
        return NULL;
 
4513
 
 
4514
    return domain->conn[con]->get_startup_args(domain->conn[con]);
 
4515
}
 
4516
 
 
4517
char *
 
4518
ipmi_domain_get_connection_type(ipmi_domain_t *domain,
 
4519
                                unsigned int  connection)
 
4520
{
 
4521
    CHECK_DOMAIN_LOCK(domain);
 
4522
 
 
4523
    if (connection >= MAX_CONS)
 
4524
        return NULL;
 
4525
 
 
4526
    if (!domain->conn[connection])
 
4527
        return NULL;
 
4528
 
 
4529
    return domain->conn[connection]->con_type;
 
4530
}
 
4531
 
 
4532
ipmi_con_t *
 
4533
ipmi_domain_get_connection(ipmi_domain_t *domain,
 
4534
                           unsigned int  connection)
 
4535
{
 
4536
    CHECK_DOMAIN_LOCK(domain);
 
4537
 
 
4538
    if (connection >= MAX_CONS)
 
4539
        return NULL;
 
4540
 
 
4541
    if (!domain->conn[connection])
 
4542
        return NULL;
 
4543
 
 
4544
    if (! domain->conn[connection]->use_connection)
 
4545
        return NULL;
 
4546
 
 
4547
    domain->conn[connection]->use_connection(domain->conn[connection]);
 
4548
    return domain->conn[connection];
 
4549
}
 
4550
 
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
4350
4576
}
4351
4577
 
4352
4578
static void
4353
 
ll_addr_changed(ipmi_con_t   *ipmi,
4354
 
                int          err,
4355
 
                unsigned int ipmb,
4356
 
                int          active,
4357
 
                unsigned int hacks,
4358
 
                void         *cb_data)
 
4579
ll_addr_changed(ipmi_con_t    *ipmi,
 
4580
                int           err,
 
4581
                const unsigned char ipmb_addr[],
 
4582
                unsigned int  num_ipmb_addr,
 
4583
                int           active,
 
4584
                unsigned int  hacks,
 
4585
                void          *cb_data)
4359
4586
{
4360
4587
    ipmi_domain_t *domain = cb_data;
4361
4588
    int           rv;
4362
4589
    int           u;
4363
4590
    int           start_connection;
4364
 
    unsigned char old_addr;
 
4591
    unsigned char old_addr[MAX_IPMI_USED_CHANNELS];
 
4592
    unsigned int  i;
4365
4593
 
4366
4594
    rv = _ipmi_domain_get(domain);
4367
4595
    if (rv)
4375
4603
    if (u == -1)
4376
4604
        goto out_unlock;
4377
4605
 
4378
 
    old_addr = domain->con_ipmb_addr[u];
 
4606
    memcpy(old_addr, domain->con_ipmb_addr[u], sizeof(old_addr));
4379
4607
 
4380
 
    domain->con_ipmb_addr[u] = ipmb;
 
4608
    for (i=0; i<num_ipmb_addr && i<MAX_IPMI_USED_CHANNELS; i++) {
 
4609
        if (! ipmb_addr[i])
 
4610
            continue;
 
4611
        domain->con_ipmb_addr[u][i] = ipmb_addr[i];
 
4612
    }
4381
4613
 
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,
4389
 
                                        NULL, NULL);
 
4617
        for (i=0; i<num_ipmb_addr && i<MAX_IPMI_USED_CHANNELS; i++) {
 
4618
            if (! ipmb_addr[i])
 
4619
                continue;
 
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],
 
4625
                                            NULL, NULL);
 
4626
            }
 
4627
 
 
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],
 
4631
                                    NULL, NULL);
4390
4632
        }
4391
 
 
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);
4395
4633
    }
4396
4634
 
4397
4635
    /* If we are not activating connections, just use whatever we get
4593
4831
    return domain->option_activate_if_possible;
4594
4832
}
4595
4833
 
 
4834
int
 
4835
ipmi_option_local_only(ipmi_domain_t *domain)
 
4836
{
 
4837
    return domain->option_local_only;
 
4838
}
 
4839
 
 
4840
void
 
4841
_ipmi_option_set_local_only_if_not_specified(ipmi_domain_t *domain, int val)
 
4842
{
 
4843
    if (domain->option_local_only_set)
 
4844
        return;
 
4845
    domain->option_local_only = val != 0;
 
4846
}
 
4847
 
4596
4848
 
4597
4849
static int
4598
4850
process_options(ipmi_domain_t      *domain, 
4599
4851
                ipmi_open_option_t *options,
4600
4852
                unsigned int       num_options)
4601
4853
{
4602
 
    int i;
 
4854
    unsigned int i;
4603
4855
 
4604
4856
    /* Option processing. */
4605
4857
    for (i=0; i<num_options; i++) {
4631
4883
        case IPMI_OPEN_OPTION_ACTIVATE_IF_POSSIBLE:
4632
4884
            domain->option_activate_if_possible = options[i].ival != 0;
4633
4885
            break;
 
4886
        case IPMI_OPEN_OPTION_LOCAL_ONLY:
 
4887
            domain->option_local_only = options[i].ival != 0;
 
4888
            domain->option_local_only_set = 1;
 
4889
            break;
4634
4890
        default:
4635
4891
            return EINVAL;
4636
4892
        }
4639
4895
    return 0;
4640
4896
}
4641
4897
 
4642
 
int con_register_stat(void *user_data, char *name,
4643
 
                      char *instance,  void **stat)
4644
 
{
4645
 
    ipmi_domain_stat_t *rstat;
4646
 
    int                rv;
4647
 
 
4648
 
    rv = ipmi_domain_stat_register(user_data, name, instance, &rstat);
4649
 
    if (!rv)
4650
 
        *stat = rstat;
4651
 
    return rv;
4652
 
}
4653
 
 
4654
 
void con_add_stat(void *user_data, void *stat, int value)
4655
 
{
4656
 
    ipmi_domain_stat_add(stat, value);
4657
 
}
4658
 
 
4659
 
void con_finished_with_stat(void *user_data, void *stat)
4660
 
{
4661
 
    ipmi_domain_stat_put(stat);
4662
 
}
4663
 
 
4664
4898
int
4665
4899
ipmi_open_domain(char               *name,
4666
4900
                 ipmi_con_t         *con[],
4675
4909
{
4676
4910
    int           rv;
4677
4911
    ipmi_domain_t *domain = NULL;
4678
 
    int           i;
4679
 
    int           priv;
 
4912
    unsigned int  i;
 
4913
    unsigned int  priv;
4680
4914
 
4681
4915
    if ((num_con < 1) || (num_con > MAX_CONS))
4682
4916
        return EINVAL;
4691
4925
 
4692
4926
    priv = IPMI_PRIVILEGE_ADMIN;
4693
4927
    for (i=0; i<num_con; i++) {
4694
 
        con[i]->register_stat = con_register_stat;
4695
 
        con[i]->add_stat = con_add_stat;
4696
 
        con[i]->finished_with_stat = con_finished_with_stat;
4697
 
 
4698
4928
        /* Find the least-common demominator privilege for the
4699
4929
           connections. */
4700
4930
        if ((con[i]->priv_level != 0) && (con[i]->priv_level < priv))
4701
4931
            priv = con[i]->priv_level;
4702
4932
        rv = con[i]->add_con_change_handler(con[i], ll_con_changed, domain);
4703
4933
        if (rv)
4704
 
            return rv;
 
4934
            goto out_err;
4705
4935
        rv = con[i]->add_ipmb_addr_handler(con[i], ll_addr_changed, domain);
4706
4936
        if (rv)
4707
 
            return rv;
 
4937
            goto out_err;
4708
4938
    }
4709
4939
 
4710
4940
    /* Enable setting the event receiver (by default) if the privilege
4724
4954
            goto out_err;
4725
4955
    }
4726
4956
 
4727
 
    for (i=0; i<num_con; i++)
 
4957
    for (i=0; i<num_con; i++) {
 
4958
        /* Set the ports that we will have valid and unconnected. */
 
4959
        if (con[i]->get_num_ports) {
 
4960
            int m = con[i]->get_num_ports(con[i]);
 
4961
            int j;
 
4962
            for (j=0; j<m; j++)
 
4963
                domain->port_up[j][i] = 0;
 
4964
        } else
 
4965
            /* Only one port 0 */
 
4966
            domain->port_up[0][i] = 0;
4728
4967
        rv = con[i]->start_con(con[i]);
 
4968
        if (rv)
 
4969
            break;
 
4970
    }
4729
4971
    if (rv)
4730
4972
        goto out_err;
4731
4973
 
4739
4981
                 DOMAIN_NAME(domain));
4740
4982
    }
4741
4983
 
4742
 
 out:
 
4984
    call_domain_change(domain, IPMI_ADDED);
 
4985
 
4743
4986
    _ipmi_domain_put(domain);
4744
4987
    return rv;
4745
4988
 
4747
4990
    for (i=0; i<num_con; i++) {
4748
4991
        con[i]->remove_con_change_handler(con[i], ll_con_changed, domain);
4749
4992
        con[i]->remove_ipmb_addr_handler(con[i], ll_addr_changed, domain);
 
4993
        if (con[i]->register_stat_handler)
 
4994
            con[i]->unregister_stat_handler(con[i],
 
4995
                                            domain->con_stat_info);
4750
4996
    }
4751
4997
    remove_known_domain(domain);
4752
4998
    cleanup_domain(domain);
4753
 
    goto out;
 
4999
    return rv;
4754
5000
}
4755
5001
 
4756
5002
/***********************************************************************
4788
5034
 
4789
5035
    if (!handler)
4790
5036
        return;
 
5037
    if (!domains_list)
 
5038
        return;
4791
5039
 
4792
5040
    info.handler = handler;
4793
5041
    info.cb_data = cb_data;
5713
5961
{
5714
5962
    int           rv;
5715
5963
    ipmi_domain_t *domain;
5716
 
    int           i;
 
5964
    unsigned int  i;
5717
5965
 
5718
5966
    if ((num_con < 1) || (num_con > MAX_CONS))
5719
5967
        return EINVAL;
5724
5972
 
5725
5973
    domain->in_startup = 1;
5726
5974
    for (i=0; i<num_con; i++) {
5727
 
        con[i]->register_stat = con_register_stat;
5728
 
        con[i]->add_stat = con_add_stat;
5729
 
        con[i]->finished_with_stat = con_finished_with_stat;
5730
5975
        rv = con[i]->add_con_change_handler(con[i], ll_con_changed, domain);
5731
5976
        if (rv)
5732
5977
            return rv;
5768
6013
    for (i=0; i<num_con; i++) {
5769
6014
        con[i]->remove_con_change_handler(con[i], ll_con_changed, domain);
5770
6015
        con[i]->remove_ipmb_addr_handler(con[i], ll_addr_changed, domain);
 
6016
        if (con[i]->register_stat_handler)
 
6017
            con[i]->unregister_stat_handler(con[i],
 
6018
                                            domain->con_stat_info);
5771
6019
    }
5772
6020
    remove_known_domain(domain);
5773
6021
    cleanup_domain(domain);