static int bcm_regex_report_control(int unit, sal_usecs_t interval) { _bcm_ft_report_ctrl_t *rctrl = _bcm_ft_report_ctrl[unit]; char name[32]; rctrl = _bcm_ft_report_ctrl[unit]; sal_snprintf(name, sizeof(name), "bcmFtExportDma.%d", unit); rctrl->interval = interval; if (interval) { if (rctrl->pid == SAL_THREAD_ERROR) { rctrl->pid = sal_thread_create(name, SAL_THREAD_STKSZ, soc_property_get(unit, spn_BCM_FT_REPORT_THREAD_PRI, 50), _bcm_report_fifo_dma_thread, INT_TO_PTR(unit)); if (rctrl->pid == SAL_THREAD_ERROR) { LOG_ERROR(BSL_LS_BCM_COMMON, (BSL_META_U(unit, "%s: Could not start thread\n"), FUNCTION_NAME())); return BCM_E_MEMORY; } } } else { /* Wake up thread so it will check the changed interval value */ sal_sem_give(SOC_CONTROL(unit)->ftreportIntr); } return BCM_E_NONE; }
/******************************************************************************* * Name: gen_check_and_gen_showname * Purpose: check original path and build showing string * Input: * szOrig: absolute path * szShow: showing path * Output: * Return: * success: 0 * failed : -1 * Note: ******************************************************************************/ int gen_check_and_gen_showname(char *szOrig, char *szShow) { int nCnt = 0; int nIdx = 0; rootdir_t *rdir = NULL; if (NULL == szOrig || NULL == szShow) { return -1; } nCnt = sizeof(actual_root_dir) / sizeof(actual_root_dir[0]); for (nIdx = 0; nIdx < nCnt; nIdx++) { rdir = &actual_root_dir[nIdx]; if (!sal_strncmp(szOrig, rdir->real_name, sal_strlen(rdir->real_name))) { if (!sal_strcmp(szOrig, rdir->real_name)) { sal_snprintf(szShow, M_FULLPATH_MAX_LEN, "%s/", rdir->show_name); } else if ('/' == szOrig[sal_strlen(rdir->real_name)]) { sal_snprintf(szShow, M_FULLPATH_MAX_LEN, "%s%s", rdir->show_name, szOrig + sal_strlen(rdir->real_name)); } else { sal_snprintf(szShow, M_FULLPATH_MAX_LEN, "%s/%s", rdir->show_name, szOrig + sal_strlen(rdir->real_name)); } return 0; } } return -1; }
int soc_dport_map_update(int unit) { int idx, port, dport; soc_info_t *si = &SOC_INFO(unit); for (idx = 0; idx < COUNTOF(SOC_DPORT_RMAP(unit)); idx++) { SOC_DPORT_RMAP(unit)[idx] = -1; } for (idx = 0; idx < COUNTOF(SOC_DPORT_MAP(unit)); idx++) { port = SOC_DPORT_MAP(unit)[idx]; if (port >= 0) { SOC_DPORT_RMAP(unit)[port] = idx; } } idx = 0; SOC_DPORT_PBMP_ITER(unit, PBMP_FE_ALL(unit), dport, port) { sal_snprintf(si->port_name[port], sizeof(si->port_name[port]), "fe%d", soc_dport_from_dport_idx(unit, dport, idx++)); }
SOC_DPORT_PBMP_ITER(unit, PBMP_AXP_ALL(unit), dport, port) { sal_snprintf(si->port_name[port], sizeof(si->port_name[port]), "axp%d", soc_dport_from_dport_idx(unit, dport, idx++)); }
/* * Function: * soc_robo_dos_monitor_enable_set (internal) * Purpose: * Enable/disable DOS event monitor threads * Parameters: * unit - unit number. * interval - time between resynchronization passes * Returns: * SOC_E_INTERNAL if can't create threads. */ int soc_robo_dos_monitor_enable_set(int unit, sal_usecs_t interval) { drv_robo_dos_monitor_t *dm = drv_dm_control[unit]; sal_usecs_t us = interval; soc_timeout_t to; /* return if not init yet */ if (dm == NULL){ if (interval == 0){ /* no error return if set thread disable when dm not init */ return SOC_E_NONE; } else { /* init problem when enabling dm thread */ return SOC_E_INIT; } } sal_snprintf(dm->task_name, sizeof(dm->task_name), "robo_DOS_EVENT.%d", unit); if (us){ /* --- enabling thread --- */ us = (interval >= MIN_DRV_DOS_MONITOR_INTERVAL) ? us : MIN_DRV_DOS_MONITOR_INTERVAL; dm->interval = us; if (dm->dm_thread != NULL){ /* if thread is running, update the period and return */ sal_sem_give(dm->dm_sema); return SOC_E_NONE; } else { if (sal_thread_create(dm->task_name, SAL_THREAD_STKSZ, ROBO_HWDOS_MONITOR_PRI, (void (*)(void*))soc_robo_dos_monitor_thread, INT_TO_PTR(unit)) == SAL_THREAD_ERROR){ dm->interval = 0; dm->err_cnt = 0; soc_cm_debug(DK_ERR, "Thread is not created\n"); soc_event_generate(unit, SOC_SWITCH_EVENT_THREAD_ERROR, SOC_SWITCH_EVENT_THREAD_HWDOS_MONITOR, __LINE__, SOC_E_MEMORY); return SOC_E_MEMORY; } else { soc_timeout_init(&to, 3000000, 0); while (dm->dm_thread == NULL) { if (soc_timeout_check(&to)) { dm->interval = 0; dm->err_cnt = 0; soc_cm_debug(DK_ERR, "%s: Thread did not start\n", dm->task_name); soc_event_generate(unit, SOC_SWITCH_EVENT_THREAD_ERROR, SOC_SWITCH_EVENT_THREAD_HWDOS_MONITOR, __LINE__, SOC_E_INTERNAL); return SOC_E_INTERNAL; break; } } } } } else { /* disabling thread */ dm->interval = 0; sal_sem_give(dm->dm_sema); soc_timeout_init(&to, 3000000, 0); while (dm->dm_thread != NULL) { if (soc_timeout_check(&to)) { dm->interval = 0; dm->err_cnt = 0; soc_cm_debug(DK_ERR, "%s: Thread did not exit\n", dm->task_name); soc_event_generate(unit, SOC_SWITCH_EVENT_THREAD_ERROR, SOC_SWITCH_EVENT_THREAD_HWDOS_MONITOR, __LINE__, SOC_E_INTERNAL); return SOC_E_INTERNAL; break; } } } /* set interval if changed */ return SOC_E_NONE; }
NDASUSER_API ndas_error_t ndas_get_string_error(ndas_error_t code, char* dest, int len) { switch (code) { case NDAS_OK: sal_strncpy(dest,"NDAS_OK",len); break; case NDAS_ERROR: sal_strncpy(dest,"NDAS_ERROR",len); break; case NDAS_ERROR_DRIVER_NOT_LOADED: sal_strncpy(dest,"DRIVER_NOT_LOADED",len); break; case NDAS_ERROR_DRIVER_ALREADY_LOADED: sal_strncpy(dest,"DRIVER_ALREADY_LOADED",len); break; case NDAS_ERROR_LIBARARY_NOT_INITIALIZED: sal_strncpy(dest,"LIBARARY_NOT_INITIALIZED",len); break; case NDAS_ERROR_INVALID_NDAS_ID: sal_strncpy(dest,"INVALID_NDAS_ID",len); break; case NDAS_ERROR_INVALID_NDAS_KEY: sal_strncpy(dest,"INVALID_NDAS_KEY",len); break; case NDAS_ERROR_NOT_IMPLEMENTED: sal_strncpy(dest,"NOT_IMPLEMENTED",len); break; case NDAS_ERROR_INVALID_PARAMETER: sal_strncpy(dest,"INVALID_PARAMETER",len); break; case NDAS_ERROR_INVALID_SLOT_NUMBER: sal_strncpy(dest,"INVALID_SLOT_NUMBER",len); break; case NDAS_ERROR_INVALID_NAME: sal_strncpy(dest,"invalid name",len); break; case NDAS_ERROR_NO_DEVICE: sal_strncpy(dest,"NO_DEVICE",len); break; case NDAS_ERROR_ALREADY_REGISTERED_DEVICE: sal_strncpy(dest,"ALREADY_REGISTERED_DEVICE",len); break; case NDAS_ERROR_ALREADY_ENABLED_DEVICE: sal_strncpy(dest,"ALREADY_ENABLED_DEVICE",len); break; case NDAS_ERROR_ALREADY_REGISTERED_NAME: sal_strncpy(dest,"ALREADY_REGISTERED_NAME",len); break; case NDAS_ERROR_ALREADY_DISABLED_DEVICE: sal_strncpy(dest,"ALREADY_DISABLED_DEVICE",len); break; case NDAS_ERROR_ALREADY_STARTED: sal_strncpy(dest,"ALREADY_STARTED",len); break; case NDAS_ERROR_ALREADY_STOPPED: sal_strncpy(dest,"ALREADY_STOPPED",len); break; case NDAS_ERROR_NOT_ONLINE : sal_strncpy(dest,"the NDAS device is not online",len); break; case NDAS_ERROR_NOT_CONNECTED: sal_strncpy(dest,"the NDAS device is not connected",len); break; case NDAS_ERROR_INVALID_HANDLE: sal_strncpy(dest,"INVALID_HANDLE",len); break; case NDAS_ERROR_NO_WRITE_ACCESS_RIGHT: sal_strncpy(dest,"no access right to write the data",len); break; case NDAS_ERROR_WRITE_BUSY: sal_strncpy(dest,"WRITE_BUSY",len); break; case NDAS_ERROR_UNSUPPORTED_HARDWARE_VERSION: sal_strncpy(dest,"UNSUPPORTED_HARDWARE_VERSION",len); break; case NDAS_ERROR_UNSUPPORTED_SOFTWARE_VERSION: sal_strncpy(dest,"UNSUPPORTED_SOFTWARE_VERSION",len); break; case NDAS_ERROR_UNSUPPORTED_DISK_MODE: sal_strncpy(dest,"UNSUPPORTED_DISK_MODE",len); break; case NDAS_ERROR_UNSUPPORTED_FEATURE: sal_strncpy(dest,"UNSUPPORTED_FEATURE",len); break; case NDAS_ERROR_BUFFER_OVERFLOW: sal_strncpy(dest,"BUFFER_OVERFLOW",len); break; case NDAS_ERROR_NO_NETWORK_INTERFACE: sal_strncpy(dest,"NO_NETWORK_INTERFACE",len); break; case NDAS_ERROR_INVALID_OPERATION: sal_strncpy(dest,"INVALID_OPERATION",len); break; case NDAS_ERROR_NETWORK_DOWN: sal_strncpy(dest,"NETWORK_DOWN",len); break; case NDAS_ERROR_MEDIA_CHANGED: sal_strncpy(dest,"MEDIA_CHANGED",len); break; case NDAS_ERROR_TIME_OUT: sal_strncpy(dest,"Timed out",len); break; case NDAS_ERROR_READONLY: sal_strncpy(dest,"read-only",len); break; case NDAS_ERROR_OUT_OF_MEMORY: sal_strncpy(dest,"out of memory",len); break; case NDAS_ERROR_EXIST: sal_strncpy(dest,"EXIST",len); break; case NDAS_ERROR_SHUTDOWN: sal_strncpy(dest,"SHUTDOWN",len); break; case NDAS_ERROR_PROTO_REGISTRATION_FAIL: sal_strncpy(dest,"PROTO_REGISTRATION_FAIL",len); break; case NDAS_ERROR_SHUTDOWN_IN_PROGRESS: sal_strncpy(dest,"Shutdown is in progress", len); break; case NDAS_ERROR_ADDRESS_NOT_AVAIABLE: sal_strncpy(dest,"ADDRESS_NOT_AVAIABLE",len); break; case NDAS_ERROR_NOT_BOUND: sal_strncpy(dest,"NOT_BOUND",len); break; case NDAS_ERROR_NETWORK_FAIL: sal_strncpy(dest,"NETWORK_FAIL",len); break; case NDAS_ERROR_HDD_DMA2_NOT_SUPPORTED: sal_strncpy(dest,"Hard Disk Device does not support DMA 2 mode",len); break; case NDAS_ERROR_IDE_REMOTE_INITIATOR_NOT_EXIST: sal_strncpy(dest,"Remote Initiator not exists",len); break; case NDAS_ERROR_IDE_REMOTE_INITIATOR_BAD_COMMAND: sal_strncpy(dest,"Remote Initiator bad command",len); break; case NDAS_ERROR_IDE_REMOTE_COMMAND_FAILED: sal_strncpy(dest,"Remote Initiator command failed",len); break; case NDAS_ERROR_IDE_REMOTE_AUTH_FAILED: sal_strncpy(dest,"Remote Authorization failed",len); break; case NDAS_ERROR_IDE_TARGET_NOT_EXIST: sal_strncpy(dest,"Target not exists",len); break; case NDAS_ERROR_HARDWARE_DEFECT: sal_strncpy(dest,"Hardware defect",len); break; case NDAS_ERROR_BAD_SECTOR: sal_strncpy(dest,"Bad sector",len); break; case NDAS_ERROR_IDE_TARGET_BROKEN_DATA: sal_strncpy(dest,"Target broken data",len); break; case NDAS_ERROR_IDE_VENDOR_SPECIFIC: sal_strncpy(dest,"IDE vendor specific error",len); break; case NDAS_ERROR_INTERNAL: sal_strncpy(dest,"The error is caused by the internal framework bug",len); break; case NDAS_ERROR_MAX_USER_ERR_NUM: sal_strncpy(dest,"MAX_USER_ERR_NUM",len); break; case NDAS_ERROR_INVALID_RANGE_REQUEST: sal_strncpy(dest,"Invalid range of request",len); break; case NDAS_ERROR_INVALID_METADATA: sal_strncpy(dest,"Invalid metadata", len); break; case NDAS_ERROR_CONNECT_FAILED: sal_strncpy(dest,"Failed to connect", len); break; default: sal_snprintf(dest,len,"UNKNOWN CODE(%d)",code); break; } return NDAS_OK; }
/******************************************************************************* * Name: gen_check_and_get_filename * Purpose: check and return absolute filename * Input: * filename: file name start with drive * outsize: out buffer size * Output: * outfile: output file name * Return: * success: 0 * failed : -1 * Note: ******************************************************************************/ int gen_check_and_get_filename(char *filename, char *outfile, size_t outsize) { char szFullName[M_FULLPATH_MAX_LEN]; rootdir_t *rdir = NULL; int nValLen = 0; int nLen = 0; int nCnt = 0; int nIdx = 0; if (NULL == filename || NULL == outfile || 0 > outsize) { return -1; } if (sal_strlen(filename) >= M_FULLPATH_MAX_LEN) { ctc_cli_out("%% File or directory name length overflow.\n"); return -1; } sal_snprintf(szFullName, M_FULLPATH_MAX_LEN, filename); if (gen_validate_relative_path(szFullName) != 0) { return -1; } gen_path_getparents(szFullName); nLen = sal_strlen(szFullName); nCnt = sizeof(actual_root_dir) / sizeof(actual_root_dir[0]); for (nIdx = 0; nIdx < nCnt; nIdx++) { rdir = &actual_root_dir[nIdx]; nValLen = sal_strlen(rdir->show_name); if (!sal_strncmp(szFullName, rdir->show_name, sal_strlen(rdir->show_name))) { if (!sal_strcmp(szFullName, rdir->show_name)) { sal_snprintf(outfile, outsize, "%s", rdir->real_name); } else if ('/' == szFullName[nValLen]) { sal_snprintf(outfile, outsize, "%s%s", rdir->real_name, szFullName + nValLen); if ((sal_strlen(rdir->real_name) + sal_strlen(szFullName + nValLen)) >= M_FULLPATH_MAX_LEN) { ctc_cli_out("%% File or directory name length overflow.\n"); return -1; } } else { sal_snprintf(outfile, outsize, "%s/%s", rdir->real_name, szFullName + nValLen); if ((sal_strlen(rdir->real_name) + sal_strlen(szFullName + nValLen) + 1) >= M_FULLPATH_MAX_LEN) { ctc_cli_out("%% File or directory name length overflow.\n"); return -1; } } if (gen_validate_path(outfile) != 0) { return -1; } return 0; } } /* is it .. or . or raw path * let connect it with current working directory and check it */ szFullName[0] = '\0'; szFullName[M_FULLPATH_MAX_LEN - 1] = '\0'; if (getcwd(szFullName, M_FULLPATH_MAX_LEN) == NULL) { ctc_cli_out("%% Get current working directory failed: %s\n", sal_strerror(errno)); return -1; } nLen = sal_strlen(szFullName); if ('/' != filename[0]) { sal_snprintf(szFullName + nLen, M_FULLPATH_MAX_LEN - nLen, "/%s", filename); if ((nLen + sal_strlen(filename) + 1) >= M_FULLPATH_MAX_LEN) { ctc_cli_out("%% File or directory name length overflow.\n"); return -1; } } else { sal_snprintf(szFullName + nLen, M_FULLPATH_MAX_LEN - nLen, "%s", filename); if ((nLen + sal_strlen(filename)) >= M_FULLPATH_MAX_LEN) { ctc_cli_out("%% File or directory name length overflow.\n"); return -1; } } gen_path_getparents(szFullName); nLen = sal_strlen(szFullName); nCnt = sizeof(actual_root_dir) / sizeof(actual_root_dir[0]); for (nIdx = 0; nIdx < nCnt; nIdx++) { rdir = &actual_root_dir[nIdx]; nValLen = sal_strlen(rdir->real_name); if (!sal_strncmp(szFullName, rdir->real_name, sal_strlen(rdir->real_name))) { sal_snprintf(outfile, outsize, szFullName); if (gen_validate_path(outfile) != 0) { return -1; } return 0; } if (!sal_strncmp(szFullName, rdir->real_name, nLen)) { /* this directory not showing for user * setting it to root directory of this part */ return -1; } } return -1; }
/* Append minutes/seconds to prefix */ static int add_msval(char *buf, int max, int msval) { return sal_snprintf(buf, max, ":%02d", msval); }
/* Append decimal integer to prefix */ static int add_dval(char *buf, int max, int dval) { return sal_snprintf(buf, max, "%d", dval); }
/* Append string value to prefix */ static int add_string(char *buf, int max, const char *str) { return sal_snprintf(buf, max, "%s", str); }