/* * 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; }
/* Initialize FCOE module */ int bcm_esw_fcoe_init(int unit) { if (soc_feature(unit, soc_feature_fcoe)) { if (fcoe_initialized[unit]) { BCM_IF_ERROR_RETURN(bcm_esw_fcoe_cleanup(unit)); } #if defined(BCM_TRIDENT2_SUPPORT) if (SOC_IS_TRIDENT2(unit)) { BCM_IF_ERROR_RETURN(bcm_td2_fcoe_init(unit)); } #endif /* BCM_TRIDENT2_SUPPORT */ if (fcoe_mutex[unit] == NULL) { fcoe_mutex[unit] = sal_mutex_create("fcoe mutex"); if (fcoe_mutex[unit] == NULL) { bcm_esw_fcoe_cleanup(unit); return BCM_E_MEMORY; } } fcoe_initialized[unit] = TRUE; return BCM_E_NONE; } return BCM_E_UNAVAIL; }
int sal_console_init(void) { console_mutex = sal_mutex_create("console mutex"); return 0; }
/* Do local initalization */ STATIC int _do_init(void) { ct_lock = sal_mutex_create("ct_tx_lock"); if (ct_lock == NULL) { return BCM_E_MEMORY; } return BCM_E_NONE; }
int sal_console_init(void) { console_mutex = sal_mutex_create("console mutex"); /* ^X is too dangerous; change monitor trap character to ^\ */ tyMonitorTrapSet('\\' & 037); return 0; }
int sal_spl_init(void) { /* Initialize spl */ spl_mutex = sal_mutex_create("spl mutex"); spl_level = 0; return 0; }
/* * 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; }
STATIC int _bcm_lock_init(int unit) { if (_bcm_lock[unit] == NULL) { _bcm_lock[unit] = sal_mutex_create("bcm_config_lock"); } if (_bcm_lock[unit] == NULL) { return BCM_E_MEMORY; } return BCM_E_NONE; }
/* * Function: * board_init * Purpose: * Initialize the board driver subsystem. * Parameters: * none * Returns: * BCM_E_NONE - success * BCM_E_XXX - board subsystem initialization failed */ int board_init(void) { int rv = BCM_E_INIT; rv = board_deinit(); if (BCM_SUCCESS(rv)) { board_lock = sal_mutex_create("board-lock"); if (board_lock != NULL) { rv = BCM_E_NONE; } } return rv; }
/** * Initialize timer manager */ sal_err_t sal_timer_init() { if(!is_inited) { sal_mutex_create(&timer_mutex); sal_event_create(&timer_event, TRUE); is_exit = FALSE; /* reduce thread stack memory */ sal_task_create(&timer_task,"timer manager",256*1024,sal_timer_check,NULL); is_inited = TRUE; SAL_LOG_INFO("time manager is opened successfully"); } else SAL_LOG_INFO("Notice!!!time manager has been opened"); return 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; }
/* * Function: * soc_linkctrl_init * Purpose: * Initialize SOC link control module. * Parameters: * unit - Device unit number * driver - Device functions * Returns: * SOC_E_XXX */ int soc_linkctrl_init(int unit, soc_linkctrl_driver_t *driver) { UNIT_VALID_CHECK(unit); PARAM_NULL_CHECK(driver); #ifdef BCM_LINKSCAN_LOCK_PER_UNIT if (soc_feature(unit, soc_feature_linkscan_lock_per_unit)) { SOC_CONTROL(unit)->linkscan_mutex = sal_mutex_create("Linkscan Lock"); } #endif SOC_PBMP_CLEAR(LINKCTRL(unit).link_fwd); LINKCTRL(unit).link_mask = PBMP_ALL(unit); LINKCTRL(unit).link_pause = 0; LINKCTRL(unit).driver = driver; return SOC_E_NONE; }
int bcm_board_topo_set(topo_cpu_t *tp_cpu) { topo_data_set = FALSE; if (!TD_INIT) { if ((topo_data_lock = sal_mutex_create("topo_data_lock")) == NULL) { return BCM_E_MEMORY; } } TOPO_DATA_LOCK; if (tp_cpu != NULL) { if (tp_cpu != &bcm_board_topo_data) { /* Only copy if not the default */ sal_memcpy(&bcm_board_topo_data, tp_cpu, sizeof(topo_cpu_t)); } topo_data_set = TRUE; } else { topo_data_set = FALSE; } TOPO_DATA_UNLOCK; return BCM_E_NONE; }
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; }
_bcm_ptp_mutex_t _bcm_ptp_mutex_create(char *desc) { return sal_mutex_create(desc); }
int topo_board_setup(cpudb_ref_t db_ref) { int rv = BCM_E_NONE; LOG_VERBOSE(BSL_LS_TKS_TOPOLOGY, (BSL_META("Topology board setup\n"))); topo_data_set = FALSE; if (!TD_INIT) { if ((topo_data_lock = sal_mutex_create("topo_data_lock")) == NULL) { return BCM_E_MEMORY; } } if (db_ref->local_entry == NULL || db_ref->num_cpus <= 0 || db_ref->num_cpus > CPUDB_CPU_MAX) { LOG_WARN(BSL_LS_TKS_TOPOLOGY, (BSL_META("TOPO SETUP: Local entry %p, num cpus %d\n"), db_ref->local_entry, db_ref->num_cpus)); return BCM_E_PARAM; } TOPO_DATA_LOCK; /* Clear current topo data */ sal_memset(&bcm_board_topo_data, 0, sizeof(topo_cpu_t)); if (db_ref->num_cpus == 1) { /* All local external stack ports have 0 mod id associations. */ if ((rv = cpudb_entry_copy(&bcm_board_topo_data.local_entry, db_ref->local_entry)) < 0) { LOG_WARN(BSL_LS_TKS_TOPOLOGY, (BSL_META("TOPO SETUP: Failed to copy entry\n"))); } else { bcm_board_topo_data.num_cpus = 1; topo_data_set = TRUE; if ((rv = topo_board_program(db_ref, &bcm_board_topo_data)) < 0) { LOG_WARN(BSL_LS_TKS_TOPOLOGY, (BSL_META("TOPO SETUP: Failed topo brd program: %s\n"), bcm_errmsg(rv))); } } } else { /* For now, use packet generate/parse */ static uint8 _pkt_buf[TOPO_PKT_BYTES_MAX]; int len; /* Generate topo pkt; then parse it to get topo cpu struct */ if ((rv = topo_pkt_gen(db_ref, db_ref->local_entry, _pkt_buf, TOPO_PKT_BYTES_MAX, &len)) < 0) { LOG_WARN(BSL_LS_TKS_TOPOLOGY, (BSL_META("TOPO SETUP: Failed pkt gen\n"))); } else if ((rv = topo_pkt_parse(db_ref, db_ref->local_entry, _pkt_buf, len, &bcm_board_topo_data, NULL)) < 0) { LOG_WARN(BSL_LS_TKS_TOPOLOGY, (BSL_META("TOPO SETUP: Failed pkt parse\n"))); } else { bcm_board_topo_data.num_cpus = db_ref->num_cpus; topo_data_set = TRUE; } } /* Set master seq num if present */ if (topo_data_set && db_ref->master_entry != NULL) { bcm_board_topo_data.master_seq_num = db_ref->master_entry->base.dseq_num; } TOPO_DATA_UNLOCK; LOG_VERBOSE(BSL_LS_TKS_TOPOLOGY, (BSL_META("TOPO SETUP: Exit rv %d, data set %d\n"), rv, topo_data_set)); return rv; }