openbcm

Git mirror of https://github.com/Broadcom-Network-Switching-Software/OpenBCM
git clone git://git.finwo.net/mirror/broadcom/openbcm
Log | Files | Refs | README

probe.c (1853B)


      1 /*
      2  * 
      3  * This license is set out in https://raw.githubusercontent.com/Broadcom-Network-Switching-Software/OpenBCM/master/Legal/LICENSE file.
      4  * 
      5  * Copyright 2007-2019 Broadcom Inc. All rights reserved.
      6  *
      7  * File:        probe.c
      8  * Purpose:     Board Probe functions
      9  */
     10 
     11 #include <sal/core/alloc.h>
     12 #include <sal/core/libc.h>
     13 #include <bcm/init.h>
     14 #include <bcm/error.h>
     15 #include <board/board.h>
     16 #include <board_int/support.h>
     17 
     18 /*
     19  * Function:
     20  *     board_probe_get
     21  * Purpose:
     22  *     Returns an array of bcm_info_t corresponding to the devices on
     23  *     the board. If max_num is zero, then actual will contain the
     24  *     number of element required to be allocated for info. If max_num
     25  *     is greater than zero, then populate info up to max_num elements,
     26  *     returning the number populated in actual.
     27  * Parameters:
     28  *     max_num  - (IN)  maximum length of info, or 0 to request length
     29  *     info     - (OUT) array of bcm_info_t
     30  *     actual   - (OUT) length of array
     31  * Returns:
     32  *     BCM_E_NONE - success
     33  *     BCM_E_XXX - failed
     34  */
     35 int
     36 board_probe_get(int max_num, bcm_info_t *info, int *actual)
     37 {
     38     int unit, limit, rv, probed;
     39 
     40     limit = board_num_devices();
     41 
     42     /* handle query */
     43     if (max_num == 0) {
     44         if (actual) {
     45             *actual = limit;
     46         }
     47         return actual ? BCM_E_NONE : BCM_E_PARAM;
     48     }
     49 
     50     probed = 0;
     51     limit = limit < BCM_LOCAL_UNITS_MAX ? limit : BCM_LOCAL_UNITS_MAX;
     52     limit = max_num < limit ? max_num : limit;
     53     for (unit=0;  unit < limit; unit++ ) {
     54         rv = board_device_info(unit, &info[unit]);
     55         if (rv == BCM_E_UNAVAIL) {
     56             continue;
     57         } else if (BCM_FAILURE(rv)) {
     58             return rv;
     59         } else {
     60             probed++;
     61         }
     62     }
     63 
     64     if (actual) {
     65         *actual = unit;
     66     }
     67 
     68     return probed ? BCM_E_NONE : BCM_E_NOT_FOUND;
     69 }