Exemplo n.º 1
0
/*
 * Function:
 *  soc_robo_dos_monitor_init (internal)
 * Purpose:
 *      dos monitor init
 * Parameters:
 *  unit     - unit number.
 *  interval - time between resynchronization passes
 * Returns:
 *  SOC_E_INTERNAL if can't create threads.
 */
int
soc_robo_dos_monitor_init(int unit)
{
    drv_robo_dos_monitor_t  *dm;
    
    if (drv_dm_control[unit] != NULL){
        SOC_IF_ERROR_RETURN(soc_robo_dos_monitor_deinit(unit));
    }
    if ((dm = sal_alloc(sizeof(drv_robo_dos_monitor_t), "dos_monitor")) == 
            NULL){
        return SOC_E_MEMORY;
    }
    
    /* allocate dm and set init value */
    sal_memset(dm, 0, sizeof (drv_robo_dos_monitor_t));
    
    dm->dm_lock = sal_mutex_create("soc_dos_monitor_lock");
    if (dm->dm_lock == NULL){
        sal_free(dm);
        return SOC_E_MEMORY;
    }

    dm->dm_sema = sal_sem_create("robo_HWDOS_MONITOR_SLEEP", 
                 sal_sem_BINARY, 0);
    if (dm->dm_sema == NULL) {
        sal_mutex_destroy(dm->dm_lock);
        sal_free(dm);
        return SOC_E_MEMORY;
    }
    dm->dm_thread = NULL;
    
    drv_dm_control[unit] = dm;

    return SOC_E_NONE;
}
Exemplo n.º 2
0
/*
 *  soc_robo_dos_monitor_deinit
 * Purpose:
 *      dos monitor de-init
 * Parameters:
 *  unit     - unit number.
 * Returns:
 *  
 */
int
soc_robo_dos_monitor_deinit(int unit)
{
    drv_robo_dos_monitor_t  *dm = drv_dm_control[unit];
    
    /* check if dm is null and dm thread running status */
    if (dm != NULL){
        
        SOC_IF_ERROR_RETURN(soc_robo_dos_monitor_enable_set(unit, 0));
        
        if (dm->dm_thread != NULL){
            soc_cm_debug(DK_ERR, 
                    "HW DOS monitor disabled but still exist!,thread(%p)\n",
                     (void *)dm->dm_thread);
        }
        
        if (dm->dm_sema != NULL) {
            sal_sem_destroy(dm->dm_sema);
            dm->dm_sema = NULL;
        }
        
        if (dm->dm_lock != NULL) {
            sal_mutex_destroy(dm->dm_lock);
            dm->dm_lock = NULL;
        }
        
        /* free dm  */
        drv_dm_control[unit] = NULL;
        sal_free(dm);
    }
    
    return SOC_E_NONE;
    
}
Exemplo n.º 3
0
Arquivo: fcoe.c Projeto: ariavie/bcm
/*
 * Function:    _bcm_esw_fcoe_free_resources
 * Purpose:     Free FCOE resources
 * Parameters:  unit - SOC unit number
 * Returns:     Nothing
 */
STATIC void
_bcm_esw_fcoe_free_resources(int unit)
{
    if (fcoe_mutex[unit]) {
        sal_mutex_destroy(fcoe_mutex[unit]);
        fcoe_mutex[unit] = NULL;
    }
}
Exemplo n.º 4
0
Arquivo: init.c Projeto: ariavie/bcm
STATIC int
_bcm_lock_deinit(int unit)
{
    if (_bcm_lock[unit] != NULL) {
        sal_mutex_destroy(_bcm_lock[unit]);
        _bcm_lock[unit] = NULL;
    }
    return BCM_E_NONE;
}
Exemplo n.º 5
0
Arquivo: oam.c Projeto: ariavie/bcm
/*
 * Function:
 *      bcm_esw_oam_init
 * Purpose:
 *      Initialize the OAM subsystem
 * Parameters:
 *      unit - (IN) Unit number.
 * result =s:
 *      BCM_E_XXX
 * Notes:
 */
int 
bcm_esw_oam_init(int unit)
{
    int result = BCM_E_UNAVAIL;

#if defined(BCM_TRIUMPH2_SUPPORT) || defined(BCM_APOLLO_SUPPORT) || \
    defined(BCM_VALKYRIE2_SUPPORT)
    if (soc_feature(unit, soc_feature_oam))
    {
#if defined(BCM_TRIUMPH3_SUPPORT) || defined(BCM_HURRICANE2_SUPPORT) ||\
    defined(BCM_GREYHOUND_SUPPORT)
        if ((SOC_IS_TRIUMPH3(unit)) || SOC_IS_HURRICANE2(unit) ||
            SOC_IS_GREYHOUND(unit)) {
            result = bcm_tr3_oam_init(unit);
        } else
#endif
/* KT2 OAM */
#if defined(BCM_KATANA2_SUPPORT)
        if (SOC_IS_KATANA2(unit)) {
            result = bcm_kt2_oam_init(unit);
        } else
#endif
        {
            if (mutex[unit] == NULL)
            {
                mutex[unit] = sal_mutex_create("oam.mutex");

                if (mutex[unit] == NULL)
                {
                    result = BCM_E_MEMORY;
                }
            }
#if defined(BCM_ENDURO_SUPPORT)
            if (SOC_IS_ENDURO(unit) || SOC_IS_KATANAX(unit))
            {
                result = bcm_en_oam_init(unit);
            } else
#endif
            {
                result = bcm_tr2x_oam_init(unit);
            }

            if (BCM_FAILURE(result))
            {
                sal_mutex_destroy(mutex[unit]);

                mutex[unit] = NULL;
            }
        }
    }
#endif

    return result;
}
Exemplo n.º 6
0
Arquivo: board.c Projeto: ariavie/bcm
/*
 * Function:
 *     board_deinit
 * Purpose:
 *     Uninitialize the board subsystem and release any allocated resources.
 * Parameters:
 *     none
 * Returns:
 *     BCM_E_NONE - success
 *     BCM_E_XXX  - board subsystem de-initialization failed
 *
 */
int
board_deinit(void)
{
    if (board_lock) {
        sal_mutex_destroy(board_lock);
        board_lock = NULL;
    }
    driver_reg = NULL;
    current = NULL;

    return BCM_E_NONE;
}
Exemplo n.º 7
0
Arquivo: oam.c Projeto: ariavie/bcm
/*
 * Function:
 *      bcm_esw_oam_detach
 * Purpose:
 *      Shut down the OAM subsystem
 * Parameters:
 *      unit - (IN) Unit number.
 * result =s:
 *      BCM_E_XXX
 * Notes:
 */
int 
bcm_esw_oam_detach(int unit)
{
    int result = BCM_E_UNAVAIL;

#if defined(BCM_TRIUMPH2_SUPPORT) || defined(BCM_APOLLO_SUPPORT) || \
    defined(BCM_VALKYRIE2_SUPPORT)
    if (soc_feature(unit, soc_feature_oam))
    {
#if defined(BCM_TRIUMPH3_SUPPORT) || defined(BCM_HURRICANE2_SUPPORT) ||\
	defined(BCM_GREYHOUND_SUPPORT)
        if ((SOC_IS_TRIUMPH3(unit)) || SOC_IS_HURRICANE2(unit) ||
			SOC_IS_GREYHOUND(unit)) {
            result = bcm_tr3_oam_detach(unit);
        } else
#endif
/* KT2 OAM */
#if defined(BCM_KATANA2_SUPPORT)
        if (SOC_IS_KATANA2(unit)) {
            result = bcm_kt2_oam_detach(unit);
        } else
#endif
        {
            if (mutex[unit] == NULL)
            {
                return BCM_E_NONE;
            }

            BCM_IF_ERROR_RETURN(bcm_esw_oam_lock(unit));

#if defined(BCM_ENDURO_SUPPORT)
            if (SOC_IS_ENDURO(unit) || SOC_IS_KATANAX(unit))
            {
                result = bcm_en_oam_detach(unit);
            } else
#endif
            {
                result = bcm_tr2x_oam_detach(unit);
            }

            BCM_IF_ERROR_RETURN(bcm_esw_oam_unlock(unit));

            sal_mutex_destroy(mutex[unit]);

            mutex[unit] = NULL;
        }
    }
#endif

    return result;
}
Exemplo n.º 8
0
int
soc_linkctrl_deinit(int unit)
{

#ifdef BCM_LINKSCAN_LOCK_PER_UNIT
    if (soc_feature(unit, soc_feature_linkscan_lock_per_unit)) {
        if(NULL != SOC_CONTROL(unit)->linkscan_mutex) {
            sal_mutex_destroy(SOC_CONTROL(unit)->linkscan_mutex);
            SOC_CONTROL(unit)->linkscan_mutex = NULL;
        }
    }
#endif

    return SOC_E_NONE;

}
Exemplo n.º 9
0
/*
 * Function:
 *   shr_htb_destroy
 * Purpose:
 *   destroy a hash table and all associated entries.
 * Parameters:
 *   (in/out) ht  - hash table to operate
 *   (in)     cb  - callback function for each valid hash entry freed
 *                  may be NULL.
 * Returns:
 *   BCM_E_NONE upon success
 *   BCM_E_*    on failure
 * Notes:
 *  The CALLER is responsible for freeing all memory associated with data by
 *  supplying a callback function.  The callback is called for all entries 
 *  found in the hash table.
 *
 */
int
shr_htb_destroy(shr_htb_hash_table_t *ht, shr_htb_data_free_f cb)
{
    int i;
    int rv = _SHR_E_NONE;
    _hash_entry_t *entry, *next;
    shr_htb_hash_table_t prv_ht = *ht;

    /* for each entry in the table, 
     *   for each entry in the collision chain,
     *     call supplied callback
     *     return the entry to the free list
     */
    HTBL_LOCK(prv_ht);
    for (i=0; i < prv_ht->max_num_entries; i++) {
        entry = prv_ht->table[i];
        while (entry) {
            if (cb) {
                cb(entry->data);
            }
            next = entry->next;
            _htb_entry_free(prv_ht, &entry);   
            entry = next;
        }
    }

    /* free the free list */
    for (i=0; i < prv_ht->num_free; i++) {
        entry = _htb_free_list_pop(prv_ht);
        
        /* shouldn't happen.  free list accounting error if does */
        if (entry == NULL) {
            rv = _SHR_E_INTERNAL;
        } else {
            sal_free(entry);
        }
    }
    HTBL_UNLOCK(prv_ht);
    
    sal_mutex_destroy(prv_ht->lock);
    sal_free(prv_ht->table);
    sal_free(prv_ht);
    *ht = NULL;
    
    return rv;
}
Exemplo n.º 10
0
/*
 * Function:
 *   shr_htb_create
 * Purpose:
 *   Create and initialize a hash table.
 * Parameters:
 *   (out) ht              - hash table to operate
 *   (in)  max_num_entries - maximum number of hash table entries, power of 2
 *   (in)  key_size        - size of keys used in hash function
 *   (in)  tbl_name        - name of table
 * Returns:
 *   BCM_E_NONE upon success
 *   BCM_E_*    on failure
 * Notes:
 *
 */
int
shr_htb_create(shr_htb_hash_table_t *ht, int max_num_entries, int key_size,
               char* tbl_name) 
{
    int rv = _SHR_E_NONE;
    int table_mem_size;
    shr_htb_hash_table_t prv_ht;

    /* table size must be a power of 2 */
    if((max_num_entries & (max_num_entries - 1)) != 0) {
        return _SHR_E_PARAM;
    }

    prv_ht = sal_alloc(sizeof(struct hash_table_s), "_hash_tbl_");
    if (prv_ht == NULL) {
        return _SHR_E_MEMORY;
    }
    sal_memset(prv_ht, 0, sizeof(struct hash_table_s));

    prv_ht->lock = sal_mutex_create(tbl_name);
    if (prv_ht->lock == NULL) {
        sal_free(prv_ht);
        return _SHR_E_RESOURCE;
    }

    prv_ht->max_num_entries = max_num_entries;
    prv_ht->key_size        = key_size;
    prv_ht->alloc_blk_cnt   = HTB_DEFAULT_ALLOC_BLK_CNT;
    prv_ht->hash_f          = htb_default_hash_f;
    prv_ht->key_cmp_f       = htb_default_key_cmp_f;
    prv_ht->cast_key_f      = htb_default_cast_key_f;

    /* hash table is an array of pointers */
    table_mem_size = max_num_entries * sizeof(_hash_entry_t*);
    prv_ht->table = sal_alloc(table_mem_size, tbl_name);
    if (prv_ht->table == NULL) {
        sal_mutex_destroy(prv_ht->lock);
        sal_free(prv_ht);
        return _SHR_E_MEMORY;
    }

    sal_memset(prv_ht->table, 0, table_mem_size);

    *ht = prv_ht;
    return rv;
}
Exemplo n.º 11
0
int
_shr_resource_uninit(int unit)
{
    uint32                     i;
    int                        status, ret;
    _shr_res_handle_t     *res_handle;


    BCM_IF_ERROR_RETURN(_SHR_RESOURCE_LOCK(unit));
    ret = BCM_E_NONE;

    for (i = SHR_HW_RES_RES0;
         i < SHR_HW_RES_MAX; i++) {
         res_handle         = &_g_shr_res_handles[unit][i];
         if (res_handle->alloc_style == SHR_ALLOC_STYLE_VERSATILE) {
             status = shr_aidxres_list_destroy(res_handle->aidx_handle);
         } else {
             status = shr_idxres_list_destroy(res_handle->idx_handle);
         }
         if (status != BCM_E_NONE) {
             ret = status;
         }
    }
    

    _SHR_RESOURCE_UNLOCK(unit);
    if (_shr_resource_mlock[unit] != NULL) {
        sal_mutex_destroy(_shr_resource_mlock[unit]);
        _shr_resource_mlock[unit] = NULL;
    }

    /**
     * No use send error here.. we have destroyed the lock,
     * _init() needs to be done
     */
    if (ret != BCM_E_NONE) {
        ret = BCM_E_NONE;
    }
    return ret;
}
Exemplo n.º 12
0
/**
 * Deinitialize timer manager
 */
void sal_timer_fini()
{
    if(is_inited)
    {
        if(head==NULL)
        {
            is_exit = TRUE;
            sal_event_set(timer_event);
            sal_task_destroy(timer_task);
            sal_mutex_destroy(timer_mutex);
            sal_event_destroy(timer_event);
            is_inited = FALSE;
            SAL_LOG_INFO("time manager is closed successfully");
        }
        else
            SAL_LOG_INFO("Notice!!!Please close all timers before closing timer manager");
    }
    else
    {
        SAL_LOG_INFO("Notice!!!no manager is opened");
    }
}
Exemplo n.º 13
0
cmd_result_t
cmd_esw_rx_mon(int unit, args_t *args)
/*
 * Function:    rx
 * Purpose:     Perform simple RX test
 * Parameters:  unit - unit number
 *              args - arguments
 * Returns:     CMD_XX
 */
{
    char                *c;
    uint32              active;
    int                 r;
    int rv = CMD_OK;

    if (!sh_check_attached(ARG_CMD(args), unit)) {
        return(CMD_FAIL);
    }

    bcm_rx_channels_running(unit, &active);

    c = ARG_GET(args);
    if (c == NULL) {
        printk("Active bitmap for RX is %x.\n", active);
        return CMD_OK;
    }

    if (sal_strcasecmp(c, "init") == 0) {
        if (_init_rx_api(unit) < 0) {
            return CMD_FAIL;
        } else {
            return CMD_OK;
        }
    } else if (sal_strcasecmp(c, "enqueue") == 0) {
        if (pkt_queue_lock[unit] == NULL) { /* Init free pkt stuff */
            pkt_queue_lock[unit] = sal_mutex_create("rxmon");
            pkts_are_ready[unit] = sal_sem_create("rxmon", sal_sem_BINARY, 0);
            if (sal_thread_create("rxmon", SAL_THREAD_STKSZ, 80, rx_free_pkts,
                                  INT_TO_PTR(unit)) == SAL_THREAD_ERROR) {
                printk("FAILED to start rxmon packet free thread\n");
                sal_mutex_destroy(pkt_queue_lock[unit]);
                pkt_queue_lock[unit] = NULL;
                sal_sem_destroy(pkts_are_ready[unit]);
                pkts_are_ready[unit] = NULL;
                return CMD_FAIL;
            }
        }
        enqueue_pkts[unit] = 1;
        if ((c = ARG_GET(args)) != NULL) {
            enqueue_pkts[unit] = strtoul(c, NULL, 0);
        }
    } else if (sal_strcasecmp(c, "-enqueue") == 0) {
        enqueue_pkts[unit] = 0;
    } else if (sal_strcasecmp(c, "start") == 0) {
        rx_cb_count = 0;

        if (!bcm_rx_active(unit)) { /* Try to initialize */
            if (_init_rx_api(unit) < 0) {
                printk("Warning:  init failed.  Will attempt register\n");
            }
        }

        /* Register to accept all cos */
        if ((r = bcm_rx_register(unit, "RX CMD", rx_cb_handler,
                    BASIC_PRIO, NULL, BCM_RCO_F_ALL_COS)) < 0) {
            printk("%s: bcm_rx_register failed: %s\n",
                   ARG_CMD(args), bcm_errmsg(r));
            return CMD_FAIL;
        }

        printk("NOTE:  'debugmod diag rx' required for rxmon output\n");

    } else if (sal_strcasecmp(c, "stop") == 0) {
        if ((r = bcm_rx_stop(unit, &rx_cfg)) < 0) {
            printk("%s: Error: Cannot stop RX: %s.  Is it running?\n",
                   ARG_CMD(args), bcm_errmsg(r));
            return CMD_FAIL;
        }
        /* Unregister handler */
        if ((r = bcm_rx_unregister(unit, rx_cb_handler, BASIC_PRIO)) < 0) {
            printk("%s: bcm_rx_unregister failed: %s\n",
                   ARG_CMD(args), bcm_errmsg(r));
            return CMD_FAIL;
        }

    } else if (sal_strcasecmp(c, "show") == 0) {
#ifdef	BROADCOM_DEBUG
        bcm_rx_show(unit);
#else
	printk("%s: ERROR: cannot show in non-BROADCOM_DEBUG compilation\n",
	       ARG_CMD(args));
	return CMD_FAIL;
#endif	/* BROADCOM_DEBUG */
    } else {
        return CMD_USAGE;
    }

    return rv;
}
Exemplo n.º 14
0
void
_bcm_ptp_mutex_destroy(_bcm_ptp_mutex_t m)
{
    sal_mutex_destroy(m);
}