/******************************************************************************* * Name: gen_validate_relative_path * Purpose: validate relative path * Input: * pszFullName: path name * Output: * Return: * success: 0 * failed : -1 * Note: Created by Percy Wang 2007-12-21 ******************************************************************************/ int gen_validate_relative_path(char *pszFullName) { int nCnt = 0; int nRet = 0; int nIdx = 0; rootdir_t *rdir = NULL; char *pszTmpName; int nValLen = 0; if (NULL == pszFullName) { return -1; } if (sal_strlen(pszFullName) > M_FULLPATH_MAX_LEN) { return -1; } pszTmpName = pszFullName; if (sal_strchr (pszFullName, ':') != NULL) { 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(pszFullName, rdir->show_name, sal_strlen(rdir->show_name))) { if (!sal_strcmp(pszFullName, rdir->show_name)) { return 0; } else { pszTmpName = pszFullName + nValLen; break; } } } } nRet = gen_validate_path(pszTmpName); return nRet; }
int syscmd_check_actual_directory_exist(char * filename) { int nIdx = 0; int nValLen = 0; int nCnt = sizeof(actual_root_dir)/sizeof(actual_root_dir[0]); rootdir_t * rdir = NULL; for(nIdx = 0; nIdx < nCnt; nIdx ++) { rdir = & actual_root_dir[nIdx]; nValLen = sal_strlen(filename); if(!sal_strncmp(filename, rdir->real_name, nValLen)) { if(syscmd_is_directory(filename)) { return 0; } else { return -1; } } } return 0; }
/* * Function: * tlv_msg_string_get * Purpose: * Gets a string value from given message object. * Parameters: * msg - (IN/OUT) Message object where to get string from * value_max - Size of array * value - (OUT) String value * Returns: * BCM_E_NONE - Success * BCM_E_XXX - Failure */ int tlv_msg_string_get(tlv_msg_t *msg, int value_max, char *value) { return (_tlv_msg_value_get(msg, (void *)value, sal_strlen((const char *) msg->cur_ptr) + 1, value_max, _tlv_msg_string_unpack)); }
int _ct_echo_pkt_create(_echo_payload_t *ep, char *str, int mode, int cte_flags, int minlen) { int payload_len, len, len_str; uint32 pkt_flags = 0; uint8 *pkt_buf, *payload_buf; int alloc_hdr_here = cte_flags & CTE_FLAGS_ALLOC_HDR_HERE; sal_memset(ep, 0, sizeof(*ep)); if (str == NULL) { cli_out("Null string\n"); return 0; } pkt_flags = mode; len_str = sal_strlen(str); len = len_str + 1; len += ECHO_STR_OFFSET; /* To store depth, flags */ len += sizeof(uint32); /* CRC at end of payload */ if (cte_flags & CTE_FLAGS_CRC_REGEN) { pkt_flags |= CTE_FLAGS_CRC_REGEN; len += sizeof(uint32); /* CRC at end of Ethernet frame */ } len = minlen > len ? minlen : len; /* Take min length if set */ payload_len = len; if (alloc_hdr_here) { len += CPUTRANS_HEADER_BYTES; pkt_flags |= CTE_FLAGS_ALLOC_HDR_HERE; } /* Create packet */ pkt_buf = sal_dma_alloc(len, "ct_echo"); if (pkt_buf == NULL) { cli_out("Could not alloc packet buffer\n"); return 0; } /* Pack the string into the payload past depth, flags */ payload_buf = pkt_buf; if (alloc_hdr_here) { payload_buf += CPUTRANS_HEADER_BYTES; } sal_strncpy((char *)&payload_buf[ECHO_STR_OFFSET], str, len_str); if (len_str) *(char*)&payload_buf[ECHO_STR_OFFSET+len_str] = '\0'; ep->pkt_buf = pkt_buf; ep->pkt_flags = pkt_flags; ep->payload_buf = payload_buf; ep->payload_len = payload_len; return 1; }
cmd_result_t cmd_dpm(int unit, args_t *a) { char *function = ARG_GET(a); char *interval, *p, *v; uint32 delay = 5; /* Report stats every 5 seconds */ int pol = -1; float volt = -1; if (!sh_check_attached(ARG_CMD(a), unit)) return CMD_FAIL; if (!function) { return CMD_USAGE; } else if (!sal_strncasecmp(function, "show", sal_strlen(function))) { soc_bsc_zm73xx_show(unit); } else if (!sal_strncasecmp(function,"watch",sal_strlen(function)) ){ interval = ARG_GET(a); if (interval) { delay = parse_integer(interval); } soc_bsc_zm73xx_watch(unit, TRUE, delay); } else if (!sal_strncasecmp(function,"nowatch",sal_strlen(function)) ){ soc_bsc_zm73xx_watch(unit, FALSE, delay); } else if (!sal_strncasecmp(function,"setpol",sal_strlen(function))) { p = ARG_GET(a); v = ARG_GET(a); if (p) { pol = parse_integer(p); } if (v) { sscanf(v, "%f", &volt); } if ((pol < 0) || (pol > 31) || (volt < 0.5) || (volt > 5.5)) { return CMD_USAGE; } soc_bsc_zm73xx_set(unit, pol, volt); } else { return CMD_USAGE; } return CMD_OK; }
/******************************************************************************* * Name: gen_validate_path * Purpose: validate full path * Input: * pszPath: path name * Output: * Return: * success: 0 * failed : -1 * Note: ******************************************************************************/ int gen_validate_path(char *pszPath) { char **ppNameArr = NULL; unsigned long nCnt = 0; int i = 0; int nRet = 0; if (NULL == pszPath) { return -1; } if (sal_strlen(pszPath) > M_FULLPATH_MAX_LEN) { return -1; } if (NULL != sal_strstr(pszPath, "//")) { return -1; } if (split_tokens(pszPath, sal_strlen(pszPath), M_FULLPATH_DEPTH_MAX, "/", &nCnt, &ppNameArr) != 0) { return -1; } for (i = 0; i < nCnt; i++) { if (NULL == ppNameArr[i]) { continue; } if (check_filename(ppNameArr[i]) != 0) { nRet = -1; break; } } free_tokens(&ppNameArr); return nRet; }
/******************************************************************************* * 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; }
STATIC void _tlv_msg_string_unpack(const void *buffer, void *value) { int len_buffer = 0; len_buffer = sal_strlen((const char*)buffer); sal_strncpy((char *)value, (const char *)buffer, len_buffer); if (len_buffer) *((char*)value + len_buffer) = '\0'; return; }
STATIC void _tlv_msg_string_pack(void *buffer, const void *value) { int len_value = 0; len_value = sal_strlen((const char*)value); sal_strncpy((char *)buffer, (const char *)value, len_value); if(len_value) *((char*)buffer+ len_value) = '\0'; return; }
int printk_file_open(char *filename, int append) { #ifndef NO_FILEIO if (file_nm) { printk_file_close(); } if ((file_fp = sal_fopen(filename, append ? "a" : "w")) == 0) { perror("Error opening file"); return -1; } file_nm = sal_strcpy((char *)sal_alloc(sal_strlen(filename) + 1, __FILE__), filename); #endif /* NO_FILEIO */ return 0; }
cmd_result_t cmd_sensor(int unit, args_t *a) { char *function = ARG_GET(a); char *interval = ARG_GET(a); uint32 delay = 5; /* Report stats every 5 seconds */ if (!sh_check_attached(ARG_CMD(a), unit)) return CMD_FAIL; if (!function || !sal_strncasecmp(function, "show", sal_strlen(function)) ){ soc_bsc_max6653_show(unit); } else if (!sal_strncasecmp(function,"watch",sal_strlen(function)) ){ if (interval) { delay = parse_integer(interval); } soc_bsc_max6653_watch(unit, TRUE, delay); } else if (!sal_strncasecmp(function,"nowatch",sal_strlen(function)) ){ soc_bsc_max6653_watch(unit, FALSE, delay); } else { return CMD_USAGE; } return CMD_OK; }
static int __strlen(char* c) { return sal_strlen(c); }
int phy_wc40_config_init(phy_ctrl_t *pc) { WC40_DEV_CFG_t *pCfg; WC40_DEV_INFO_t *pInfo; WC40_DEV_DESC_t *pDesc; soc_phy_info_t *pi; int len; uint16 serdes_id0; int unit; int port; int i; WC40_TX_DRIVE_t *p_tx; pDesc = (WC40_DEV_DESC_t *)(pc + 1); pCfg = &pDesc->cfg; pInfo = &pDesc->info; unit = pc->unit; port = pc->port; if (SOC_IS_HELIX4(unit)) { soc_info_t *si; int phy_port; /* physical port number */ si = &SOC_INFO(unit); phy_port = si->port_l2p_mapping[port]; pc->lane_num = SOC_PORT_BINDEX(unit, phy_port); pc->chip_num = SOC_BLOCK_NUMBER(unit, SOC_PORT_BLOCK(unit, phy_port)); /* convert to phy_ctrl macros */ if (si->port_num_lanes[port] == 4) { pc->phy_mode = PHYCTRL_QUAD_LANE_PORT; } else if (si->port_num_lanes[port] == 2) { pc->phy_mode = PHYCTRL_DUAL_LANE_PORT; pc->flags |= PHYCTRL_MDIO_ADDR_SHARE; } else if (si->port_num_lanes[port] == 1) { pc->phy_mode = PHYCTRL_ONE_LANE_PORT; pc->flags |= PHYCTRL_MDIO_ADDR_SHARE; } pc->lane_num = (phy_port-1) % 4; pc->chip_num = (phy_port-1) / 4; } #if defined(BCM_TRIDENT_SUPPORT) if (SOC_IS_TD_TT(unit)) { soc_info_t *si; int phy_port; /* physical port number */ si = &SOC_INFO(unit); phy_port = si->port_l2p_mapping[port]; pc->lane_num = SOC_PORT_BINDEX(unit, phy_port); pc->chip_num = SOC_BLOCK_NUMBER(unit, SOC_PORT_BLOCK(unit, phy_port)); /* convert to phy_ctrl macros */ if (si->port_num_lanes[port] == 4) { pc->phy_mode = PHYCTRL_QUAD_LANE_PORT; } else if (si->port_num_lanes[port] == 2) { pc->phy_mode = PHYCTRL_DUAL_LANE_PORT; pc->flags |= PHYCTRL_MDIO_ADDR_SHARE; } else if (si->port_num_lanes[port] == 1) { pc->phy_mode = PHYCTRL_ONE_LANE_PORT; pc->flags |= PHYCTRL_MDIO_ADDR_SHARE; } /* warpcore intstance number and lane number */ pc->lane_num = (phy_port - 1) % 4; pc->chip_num = (phy_port - 1) / 4; } #endif #ifdef BCM_SHADOW_SUPPORT if (SOC_IS_SHADOW(unit)) { soc_info_t *si; int phy_port; /* physical port number */ si = &SOC_INFO(unit); if (soc_feature(unit, soc_feature_logical_port_num)) { phy_port = si->port_l2p_mapping[port]; } else { phy_port = port; } pc->lane_num = SOC_PORT_BINDEX(unit, phy_port); pc->chip_num = SOC_BLOCK_NUMBER(unit, SOC_PORT_BLOCK(unit, phy_port)); /* convert to phy_ctrl macros */ if (si->port_num_lanes[port] == 4) { pc->phy_mode = PHYCTRL_QUAD_LANE_PORT; } else if (si->port_num_lanes[port] == 2) { pc->phy_mode = PHYCTRL_DUAL_LANE_PORT; pc->flags |= PHYCTRL_MDIO_ADDR_SHARE; } else if (si->port_num_lanes[port] == 1) { pc->phy_mode = PHYCTRL_ONE_LANE_PORT; pc->flags |= PHYCTRL_MDIO_ADDR_SHARE; } if (phy_port > 8) { if ((soc_property_get(unit, spn_BCM88732_2X40_1X40, 0)) || (soc_property_get(unit, spn_BCM88732_2X40_2X40, 0)) || (soc_property_get(unit, spn_BCM88732_8X10_1X40, 0)) || (soc_property_get(unit, spn_BCM88732_8X10_2X40, 0))) { pc->phy_mode = PHYCTRL_LANE_MODE_CUSTOM; pc->flags |= PHYCTRL_MDIO_ADDR_SHARE; } else if (soc_property_get(unit, spn_BCM88732_2X40_2X40,0)) { pc->phy_mode = PHYCTRL_LANE_MODE_CUSTOM; pc->flags |= PHYCTRL_MDIO_ADDR_SHARE; } else if ((soc_property_get(unit,spn_BCM88732_1X40_4X10,0)) || (soc_property_get(unit, spn_BCM88732_4X10_4X10, 0))) { pc->phy_mode = PHYCTRL_QUAD_LANE_PORT; } else if ((soc_property_get(unit,spn_BCM88732_2X40_8X12,0)) || (soc_property_get(unit, spn_BCM88732_1X40_4X10_8X12, 0)) || (soc_property_get(unit, spn_BCM88732_4X10_1X40_8X12, 0)) || (soc_property_get(unit, spn_BCM88732_8X10_8X12, 0)) || (soc_property_get(unit, spn_BCM88732_8X10_4X12, 0)) || (soc_property_get(unit, spn_BCM88732_6X10_2X12, 0)) || (soc_property_get(unit, spn_BCM88732_8X10_2X12, 0))) { pc->phy_mode = PHYCTRL_LANE_MODE_CUSTOM1; } else if (soc_property_get(unit, spn_BCM88732_2X40_8X10, 0) || soc_property_get(unit, spn_BCM88732_8X10_8X10, 0)) { pc->phy_mode = PHYCTRL_ONE_LANE_PORT; pc->flags |= PHYCTRL_MDIO_ADDR_SHARE; } else { SOC_DEBUG_PRINT((DK_WARN, "Board configuration not found: u=%d p=%d\n", unit,port)); } } else { /* convert to phy_ctrl macros */ if (si->port_num_lanes[port] == 4) { pc->phy_mode = PHYCTRL_QUAD_LANE_PORT; } else if (si->port_num_lanes[port] == 2) { pc->phy_mode = PHYCTRL_DUAL_LANE_PORT; pc->flags |= PHYCTRL_MDIO_ADDR_SHARE; } else if (si->port_num_lanes[port] == 1) { pc->phy_mode = PHYCTRL_ONE_LANE_PORT; pc->flags |= PHYCTRL_MDIO_ADDR_SHARE; } } if (phy_port > 8) { if (soc_property_get(unit, "IL3125", 0)) { pc->phy_mode |= PHYCTRL_LANE_MODE_CUSTOM_3p125MHZ; } } } #endif /* retrieve chip level information for warpcore */ pi = &SOC_PHY_INFO(unit, port); serdes_id0 = pInfo->serdes_id0; sal_strcpy(pInfo->name,"WC-"); len = sal_strlen(pInfo->name); /* add rev letter */ pInfo->name[len++] = 'A' + ((serdes_id0 >> SERDESID_SERDESID0_REV_LETTER_SHIFT) & 0x3); /* add rev number */ pInfo->name[len++] = '0' + ((serdes_id0 >> SERDESID_SERDESID0_REV_NUMBER_SHIFT) & 0x7); pInfo->name[len++] = '/'; pInfo->name[len++] = (pc->chip_num/10)%10 + '0'; pInfo->name[len++] = pc->chip_num%10 + '0'; pInfo->name[len++] = '/'; /* phy_mode: 0 single port mode, port uses all four lanes of Warpcore * 1 dual port mode, port uses 2 lanes * 2 quad port mode, port uses 1 lane */ if (IS_DUAL_LANE_PORT(pc)) { /* dual-xgxs mode */ if (pc->lane_num < 2) { /* the first dual-xgxs port */ pInfo->name[len++] = '0'; pInfo->name[len++] = '-'; pInfo->name[len++] = '1'; } else { pInfo->name[len++] = '2'; pInfo->name[len++] = '-'; pInfo->name[len++] = '3'; } PHY_FLAGS_SET(unit, port, PHY_FLAGS_INDEPENDENT_LANE); } else if (pc->phy_mode == PHYCTRL_ONE_LANE_PORT || CUSTOM_MODE(pc)) { PHY_FLAGS_SET(unit, port, PHY_FLAGS_INDEPENDENT_LANE); pInfo->name[len++] = pc->lane_num + '0'; } else { pInfo->name[len++] = '4'; PHY_FLAGS_CLR(unit, port, PHY_FLAGS_INDEPENDENT_LANE); } pInfo->name[len] = 0; /* string terminator */ if (len > WC40_LANE_NAME_LEN) { SOC_DEBUG_PRINT((DK_ERR, "WC info string length %d exceeds max length 0x%x: u=%d p=%d\n", len,WC40_LANE_NAME_LEN,unit, port)); return SOC_E_MEMORY; } if (!PHY_EXTERNAL_MODE(unit, port)) { pi->phy_name = pInfo->name; } if (CUSTOM_MODE(pc)) { pCfg->custom = pc->phy_mode; } if (CUSTOM1_MODE(pc)) { pCfg->custom1 = pc->phy_mode; } if (PHY_INDEPENDENT_LANE_MODE(unit, port)) { if (PHY_EXTERNAL_MODE(unit, port)) { pCfg->line_intf = WC40_IF_XFI; } else { pCfg->line_intf = WC40_IF_SFI; } pCfg->auto_medium = FALSE; if (CUSTOM_MODE(pc) || CUSTOM1_MODE(pc)) { pCfg->lane_mode = xgxs_operationModes_IndLane_OS5; } else { pCfg->lane_mode = xgxs_operationModes_Indlane_OS8; } } else { pCfg->line_intf = WC40_IF_XLAUI; pCfg->auto_medium = TRUE; pCfg->lane_mode = xgxs_operationModes_ComboCoreMode; pc->lane_num = 0; /* make sure lane_num is 0 */ } if ((PHY_FIBER_MODE(unit, port) && !PHY_EXTERNAL_MODE(unit, port)) || (PHY_PASSTHRU_MODE(unit, port)) || (!PHY_INDEPENDENT_LANE_MODE(unit, port)) || (pc->speed_max >= 10000)) { pCfg->fiber_pref = TRUE; } else { pCfg->fiber_pref = FALSE; } if (PHY_INDEPENDENT_LANE_MODE(unit, port)) { pCfg->cl73an = WC40_CL73_AND_CL73BAM; /*WC40_CL73_WO_CL73BAM; */ } else { if (IS_HG_PORT(unit, port)) { pCfg->cl73an = FALSE; } else { pCfg->cl73an = WC40_CL73_AND_CL73BAM; } } /* Default setting for CL37 */ pCfg->cl37an = WC40_CL37_AND_CL37BAM; if ((PHY_FIBER_MODE(unit, port) && !PHY_EXTERNAL_MODE(unit, port)) || PHY_PASSTHRU_MODE(unit, port) || PHY_SGMII_AUTONEG_MODE(unit, port)) { pCfg->pdetect1000x = TRUE; } else { pCfg->pdetect1000x = FALSE; } /* populate the default TX drive value for each speed mode */ #if defined(BCM_TRIDENT_SUPPORT) if (SOC_IS_TD_TT(unit)) { /* XFI */ p_tx = &pCfg->tx_drive[TXDRV_XFI_INX]; p_tx->u.tap.post = 0x08; p_tx->u.tap.main = 0x37; p_tx->u.tap.pre = 0x00; p_tx->u.tap.force = 0x01; p_tx->post2 = 0x00; p_tx->idrive = 0x02; p_tx->ipredrive = 0x03; /* SFI SR */ p_tx = &pCfg->tx_drive[TXDRV_SFI_INX]; p_tx->u.tap.post = 0x12; p_tx->u.tap.main = 0x2d; p_tx->u.tap.pre = 0x00; p_tx->u.tap.force = 0x01; p_tx->post2 = 0x02; p_tx->idrive = 0x02; p_tx->ipredrive = 0x02; /* SFI DAC */ p_tx = &pCfg->tx_drive[TXDRV_SFIDAC_INX]; p_tx->u.tap.post = 0x12; p_tx->u.tap.main = 0x2d; p_tx->u.tap.pre = 0x00; p_tx->u.tap.force = 0x01; p_tx->post2 = 0x02; p_tx->idrive = 0x02; p_tx->ipredrive = 0x02; /* SR4 */ p_tx = &pCfg->tx_drive[TXDRV_SR4_INX]; p_tx->u.tap.post = 0x13; p_tx->u.tap.main = 0x2c; p_tx->u.tap.pre = 0x00; p_tx->u.tap.force = 0x01; p_tx->post2 = 0x02; p_tx->idrive = 0x05; p_tx->ipredrive = 0x05; /* XLAUI */ p_tx = &pCfg->tx_drive[TXDRV_XLAUI_INX]; p_tx->u.tap.post = 0x18; p_tx->u.tap.main = 0x27; p_tx->u.tap.pre = 0x00; p_tx->u.tap.force = 0x01; p_tx->post2 = 0x02; p_tx->idrive = 0x04; p_tx->ipredrive = 0x04; /* TXDRV_6GOS1_INX */ p_tx = &pCfg->tx_drive[TXDRV_6GOS1_INX]; p_tx->u.tap.post = 0x00; p_tx->u.tap.main = 0x00; p_tx->u.tap.pre = 0x00; p_tx->u.tap.force = 0x01; p_tx->post2 = 0x00; p_tx->idrive = 0x09; p_tx->ipredrive = 0x09; /* TXDRV_6GOS2_INX */ p_tx = &pCfg->tx_drive[TXDRV_6GOS2_INX]; p_tx->u.tap.post = 0x00; p_tx->u.tap.main = 0x3f; p_tx->u.tap.pre = 0x00; p_tx->u.tap.force = 0x01; p_tx->post2 = 0x00; p_tx->idrive = 0x09; p_tx->ipredrive = 0x09; /* TXDRV_6GOS2_CX4_INX */ p_tx = &pCfg->tx_drive[TXDRV_6GOS2_CX4_INX]; p_tx->u.tap.post = 0x0e; p_tx->u.tap.main = 0x31; p_tx->u.tap.pre = 0x00; p_tx->u.tap.force = 0x01; p_tx->post2 = 0x00; p_tx->idrive = 0x08; p_tx->ipredrive = 0x08; /* Autoneg */ p_tx = &pCfg->tx_drive[TXDRV_AN_INX]; p_tx->u.tap.post = 0x00; p_tx->u.tap.main = 0x00; p_tx->u.tap.pre = 0x00; p_tx->u.tap.force = 0x00; p_tx->post2 = 0x02; p_tx->idrive = 0x06; p_tx->ipredrive = 0x09; /* default */ p_tx = &pCfg->tx_drive[TXDRV_DFT_INX]; p_tx->u.tap.post = 0x00; p_tx->u.tap.main = 0x00; p_tx->u.tap.pre = 0x00; p_tx->u.tap.force = 0x00; p_tx->post2 = 0x00; p_tx->idrive = 0x09; p_tx->ipredrive = 0x09; } #endif /* populate the default TX drive value for each speed mode */ #if defined(BCM_TRIUMPH3_SUPPORT) if (SOC_IS_HELIX4(unit)) { /* XFI */ p_tx = &pCfg->tx_drive[TXDRV_XFI_INX]; p_tx->u.tap.post = 0x08; p_tx->u.tap.main = 0x37; p_tx->u.tap.pre = 0x00; p_tx->u.tap.force = 0x01; p_tx->post2 = 0x00; p_tx->idrive = 0x02; p_tx->ipredrive = 0x03; /* SFI SR */ p_tx = &pCfg->tx_drive[TXDRV_SFI_INX]; p_tx->u.tap.post = 0x12; p_tx->u.tap.main = 0x2d; p_tx->u.tap.pre = 0x00; p_tx->u.tap.force = 0x01; p_tx->post2 = 0x02; p_tx->idrive = 0x02; p_tx->ipredrive = 0x02; /* SFI DAC */ p_tx = &pCfg->tx_drive[TXDRV_SFIDAC_INX]; p_tx->u.tap.post = 0x12; p_tx->u.tap.main = 0x2d; p_tx->u.tap.pre = 0x00; p_tx->u.tap.force = 0x01; p_tx->post2 = 0x02; p_tx->idrive = 0x02; p_tx->ipredrive = 0x02; /* SR4 */ p_tx = &pCfg->tx_drive[TXDRV_SR4_INX]; p_tx->u.tap.post = 0x13; p_tx->u.tap.main = 0x2c; p_tx->u.tap.pre = 0x00; p_tx->u.tap.force = 0x01; p_tx->post2 = 0x02; p_tx->idrive = 0x05; p_tx->ipredrive = 0x05; /* XLAUI */ p_tx = &pCfg->tx_drive[TXDRV_XLAUI_INX]; p_tx->u.tap.post = 0x18; p_tx->u.tap.main = 0x27; p_tx->u.tap.pre = 0x00; p_tx->u.tap.force = 0x01; p_tx->post2 = 0x02; p_tx->idrive = 0x04; p_tx->ipredrive = 0x04; /* TXDRV_6GOS1_INX */ p_tx = &pCfg->tx_drive[TXDRV_6GOS1_INX]; p_tx->u.tap.post = 0x00; p_tx->u.tap.main = 0x00; p_tx->u.tap.pre = 0x00; p_tx->u.tap.force = 0x01; p_tx->post2 = 0x00; p_tx->idrive = 0x09; p_tx->ipredrive = 0x09; /* TXDRV_6GOS2_INX */ p_tx = &pCfg->tx_drive[TXDRV_6GOS2_INX]; p_tx->u.tap.post = 0x00; p_tx->u.tap.main = 0x3f; p_tx->u.tap.pre = 0x00; p_tx->u.tap.force = 0x01; p_tx->post2 = 0x00; p_tx->idrive = 0x09; p_tx->ipredrive = 0x09; /* TXDRV_6GOS2_CX4_INX */ p_tx = &pCfg->tx_drive[TXDRV_6GOS2_CX4_INX]; p_tx->u.tap.post = 0x0e; p_tx->u.tap.main = 0x31; p_tx->u.tap.pre = 0x00; p_tx->u.tap.force = 0x01; p_tx->post2 = 0x00; p_tx->idrive = 0x08; p_tx->ipredrive = 0x08; /* Autoneg */ p_tx = &pCfg->tx_drive[TXDRV_AN_INX]; p_tx->u.tap.post = 0x00; p_tx->u.tap.main = 0x00; p_tx->u.tap.pre = 0x00; p_tx->u.tap.force = 0x00; p_tx->post2 = 0x02; p_tx->idrive = 0x06; p_tx->ipredrive = 0x09; /* default */ p_tx = &pCfg->tx_drive[TXDRV_DFT_INX]; p_tx->u.tap.post = 0x00; p_tx->u.tap.main = 0x00; p_tx->u.tap.pre = 0x00; p_tx->u.tap.force = 0x00; p_tx->post2 = 0x00; p_tx->idrive = 0x09; p_tx->ipredrive = 0x09; } #endif #if defined(BCM_KATANA2_SUPPORT) if (SOC_IS_KATANA2(unit)) { /* XFI */ p_tx = &pCfg->tx_drive[TXDRV_XFI_INX]; p_tx->u.tap.post = 0x08; p_tx->u.tap.main = 0x37; p_tx->u.tap.pre = 0x00; p_tx->u.tap.force = 0x01; p_tx->post2 = 0x00; p_tx->idrive = 0x02; p_tx->ipredrive = 0x03; /* SFI SR */ p_tx = &pCfg->tx_drive[TXDRV_SFI_INX]; p_tx->u.tap.post = 0x12; p_tx->u.tap.main = 0x2d; p_tx->u.tap.pre = 0x00; p_tx->u.tap.force = 0x01; p_tx->post2 = 0x02; p_tx->idrive = 0x02; p_tx->ipredrive = 0x02; /* SFI DAC */ p_tx = &pCfg->tx_drive[TXDRV_SFIDAC_INX]; p_tx->u.tap.post = 0x12; p_tx->u.tap.main = 0x2d; p_tx->u.tap.pre = 0x00; p_tx->u.tap.force = 0x01; p_tx->post2 = 0x02; p_tx->idrive = 0x02; p_tx->ipredrive = 0x02; /* SR4 */ p_tx = &pCfg->tx_drive[TXDRV_SR4_INX]; p_tx->u.tap.post = 0x13; p_tx->u.tap.main = 0x2c; p_tx->u.tap.pre = 0x00; p_tx->u.tap.force = 0x01; p_tx->post2 = 0x02; p_tx->idrive = 0x05; p_tx->ipredrive = 0x05; /* XLAUI */ p_tx = &pCfg->tx_drive[TXDRV_XLAUI_INX]; p_tx->u.tap.post = 0x18; p_tx->u.tap.main = 0x27; p_tx->u.tap.pre = 0x00; p_tx->u.tap.force = 0x01; p_tx->post2 = 0x02; p_tx->idrive = 0x04; p_tx->ipredrive = 0x04; /* TXDRV_6GOS1_INX */ p_tx = &pCfg->tx_drive[TXDRV_6GOS1_INX]; p_tx->u.tap.post = 0x00; p_tx->u.tap.main = 0x00; p_tx->u.tap.pre = 0x00; p_tx->u.tap.force = 0x01; p_tx->post2 = 0x00; p_tx->idrive = 0x09; p_tx->ipredrive = 0x09; /* TXDRV_6GOS2_INX */ p_tx = &pCfg->tx_drive[TXDRV_6GOS2_INX]; p_tx->u.tap.post = 0x00; p_tx->u.tap.main = 0x3f; p_tx->u.tap.pre = 0x00; p_tx->u.tap.force = 0x01; p_tx->post2 = 0x00; p_tx->idrive = 0x09; p_tx->ipredrive = 0x09; /* TXDRV_6GOS2_CX4_INX */ p_tx = &pCfg->tx_drive[TXDRV_6GOS2_CX4_INX]; p_tx->u.tap.post = 0x0e; p_tx->u.tap.main = 0x31; p_tx->u.tap.pre = 0x00; p_tx->u.tap.force = 0x01; p_tx->post2 = 0x00; p_tx->idrive = 0x08; p_tx->ipredrive = 0x08; /* Autoneg */ p_tx = &pCfg->tx_drive[TXDRV_AN_INX]; p_tx->u.tap.post = 0x00; p_tx->u.tap.main = 0x00; p_tx->u.tap.pre = 0x00; p_tx->u.tap.force = 0x00; p_tx->post2 = 0x02; p_tx->idrive = 0x06; p_tx->ipredrive = 0x09; /* default */ p_tx = &pCfg->tx_drive[TXDRV_DFT_INX]; p_tx->u.tap.post = 0x00; p_tx->u.tap.main = 0x00; p_tx->u.tap.pre = 0x00; p_tx->u.tap.force = 0x00; p_tx->post2 = 0x00; p_tx->idrive = 0x09; p_tx->ipredrive = 0x09; } #endif #ifdef BCM_SHADOW_SUPPORT if (SOC_IS_SHADOW(unit)) { /* XFI */ p_tx = &pCfg->tx_drive[TXDRV_XFI_INX]; p_tx->u.tap.post = 0x06; p_tx->u.tap.main = 0x39; p_tx->u.tap.pre = 0x00; p_tx->u.tap.force = 0x01; p_tx->post2 = 0x00; p_tx->idrive = 0x01; p_tx->ipredrive = 0x03; /* SFI SR */ p_tx = &pCfg->tx_drive[TXDRV_SFI_INX]; p_tx->u.tap.post = 0x12; p_tx->u.tap.main = 0x2d; p_tx->u.tap.pre = 0x00; p_tx->u.tap.force = 0x01; p_tx->post2 = 0x02; p_tx->idrive = 0x02; p_tx->ipredrive = 0x02; /* SFI DAC */ p_tx = &pCfg->tx_drive[TXDRV_SFIDAC_INX]; p_tx->u.tap.post = 0x12; p_tx->u.tap.main = 0x2d; p_tx->u.tap.pre = 0x00; p_tx->u.tap.force = 0x01; p_tx->post2 = 0x02; p_tx->idrive = 0x02; p_tx->ipredrive = 0x02; /* SR4 */ p_tx = &pCfg->tx_drive[TXDRV_SR4_INX]; p_tx->u.tap.post = 0x00; p_tx->u.tap.main = 0x00; p_tx->u.tap.pre = 0x00; p_tx->u.tap.force = 0x01; p_tx->post2 = 0x02; p_tx->idrive = 0x06; p_tx->ipredrive = 0x09; /* XLAUI */ p_tx = &pCfg->tx_drive[TXDRV_XLAUI_INX]; p_tx->u.tap.post = 0x18; p_tx->u.tap.main = 0x27; p_tx->u.tap.pre = 0x00; p_tx->u.tap.force = 0x01; p_tx->post2 = 0x00; p_tx->idrive = 0x01; p_tx->ipredrive = 0x03; /* TXDRV_6GOS1_INX */ p_tx = &pCfg->tx_drive[TXDRV_6GOS1_INX]; p_tx->u.tap.post = 0x08; p_tx->u.tap.main = 0x37; p_tx->u.tap.pre = 0x00; p_tx->u.tap.force = 0x01; p_tx->post2 = 0x00; p_tx->idrive = 0x00; p_tx->ipredrive = 0x01; /* TXDRV_6GOS2_INX */ p_tx = &pCfg->tx_drive[TXDRV_6GOS2_INX]; p_tx->u.tap.post = 0x00; p_tx->u.tap.main = 0x3f; p_tx->u.tap.pre = 0x00; p_tx->u.tap.force = 0x01; p_tx->post2 = 0x00; p_tx->idrive = 0x09; p_tx->ipredrive = 0x09; /* TXDRV_6GOS2_CX4_INX */ p_tx = &pCfg->tx_drive[TXDRV_6GOS2_CX4_INX]; p_tx->u.tap.post = 0x00; p_tx->u.tap.main = 0x00; p_tx->u.tap.pre = 0x00; p_tx->u.tap.force = 0x01; p_tx->post2 = 0x02; p_tx->idrive = 0x06; p_tx->ipredrive = 0x09; /* Autoneg */ p_tx = &pCfg->tx_drive[TXDRV_AN_INX]; p_tx->u.tap.post = 0x00; p_tx->u.tap.main = 0x00; p_tx->u.tap.pre = 0x00; p_tx->u.tap.force = 0x00; p_tx->post2 = 0x02; p_tx->idrive = 0x06; p_tx->ipredrive = 0x09; /* default */ p_tx = &pCfg->tx_drive[TXDRV_DFT_INX]; p_tx->u.tap.post = 0x00; p_tx->u.tap.main = 0x00; p_tx->u.tap.pre = 0x00; p_tx->u.tap.force = 0x00; p_tx->post2 = 0x00; p_tx->idrive = 0x09; p_tx->ipredrive = 0x09; } #endif /* config property overrides */ for (i = 0; i < NUM_LANES; i++) { pCfg->preemph[i] = soc_property_port_get(unit, port, spn_SERDES_PREEMPHASIS, pCfg->preemph[i]); pCfg->idriver[i] = soc_property_port_get(unit, port, spn_SERDES_DRIVER_CURRENT, pCfg->idriver[i]); pCfg->pdriver[i] = soc_property_port_get(unit, port, spn_SERDES_PRE_DRIVER_CURRENT, pCfg->pdriver[i]); } pCfg->auto_medium = soc_property_port_get(unit, port, spn_SERDES_AUTOMEDIUM, pCfg->auto_medium); pCfg->fiber_pref = soc_property_port_get(unit, port, spn_SERDES_FIBER_PREF, pCfg->fiber_pref); pCfg->sgmii_mstr = soc_property_port_get(unit, port, spn_SERDES_SGMII_MASTER, pCfg->sgmii_mstr); pCfg->pdetect10g = soc_property_port_get(unit, port, spn_XGXS_PDETECT_10G, pCfg->pdetect10g); pCfg->cx42hg = soc_property_port_get(unit, port, spn_CX4_TO_HIGIG, pCfg->cx42hg); pCfg->rxlane_map = soc_property_port_get(unit, port, spn_XGXS_RX_LANE_MAP, pCfg->rxlane_map); pCfg->txlane_map = soc_property_port_get(unit, port, spn_XGXS_TX_LANE_MAP, pCfg->txlane_map); pCfg->cl73an = soc_property_port_get(unit, port, spn_PHY_AN_C73, pCfg->cl73an); pCfg->cl37an = soc_property_port_get(unit, port, spn_PHY_AN_C37, pCfg->cl37an); pCfg->rxaui = soc_property_port_get(unit, port, spn_SERDES_2WIRE_XAUI, FALSE); pCfg->txpol = soc_property_port_get(unit, port, spn_PHY_XAUI_TX_POLARITY_FLIP, pCfg->txpol); pCfg->rxpol = soc_property_port_get(unit, port, spn_PHY_XAUI_RX_POLARITY_FLIP, pCfg->rxpol); pCfg->rx_los = soc_property_port_get(unit, port, spn_SERDES_RX_LOS, pCfg->rx_los); pCfg->rx_los_invert = soc_property_port_get(unit, port, spn_SERDES_RX_LOS_INVERT, pCfg->rx_los_invert); if (PHY_EXTERNAL_MODE(unit, port)) { PHY_FLAGS_CLR(unit, port, PHY_FLAGS_PASSTHRU); pCfg->phy_passthru = soc_property_port_get(unit, port, spn_PHY_PCS_REPEATER, pCfg->phy_passthru); if (pCfg->phy_passthru) { PHY_FLAGS_SET(unit, port, PHY_FLAGS_PASSTHRU); } } if (PHY_INDEPENDENT_LANE_MODE(unit, port)) { pCfg->lane_mode = soc_property_port_get(unit, port, spn_PHY_HL65_1LANE_MODE, pCfg->lane_mode); } pCfg->cx4_10g = soc_property_port_get(unit, port, spn_10G_IS_CX4, pCfg->cx4_10g); pCfg->lane0_rst = soc_property_get(unit, spn_SERDES_LANE0_RESET, pCfg->lane0_rst); /* XXX internal use for now */ pCfg->refclk = soc_property_port_get(unit,port, "wc_refclk_speed", pCfg->refclk); pCfg->hg_mode = IS_HG_PORT(unit,port); if (PHY_EXTERNAL_MODE(unit, port)) { /* default: always IEEE speed mode if connected with an external PHY */ pCfg->hg_mode = FALSE; /* exception: combo mode && passthru */ if ((!PHY_INDEPENDENT_LANE_MODE(unit, port)) && pCfg->phy_passthru) { pCfg->hg_mode = IS_HG_PORT(unit,port); } } if (!PHY_EXTERNAL_MODE(unit, port)) { if (pCfg->fiber_pref) { PHY_FLAGS_SET(unit, port, PHY_FLAGS_FIBER); } else { PHY_FLAGS_CLR(unit, port, PHY_FLAGS_FIBER); } if (pCfg->cl73an) { PHY_FLAGS_SET(unit, port, PHY_FLAGS_C73); } } /* For HG mode or BAM mode, cl37 BAM should be enabled WARN if not */ if((pCfg->cl37an != WC40_CL37_AND_CL37BAM) && ((pCfg->hg_mode) || (pCfg->cl73an == WC40_CL73_AND_CL73BAM))) { SOC_DEBUG_PRINT((DK_WARN, "WC config init, CL37 BAM is not enabled with HG/BAM mode: u=%d p=%d\n", unit,port)); } return SOC_E_NONE; }
bcm_rx_t ab_echo_cb(cpudb_key_t src_key, int client_id, bcm_pkt_t *pkt, uint8 *payload, int payload_len, void *cookie) { uint16 depth; int async_free; uint32 pkt_flags; bcm_rx_t rv = BCM_RX_HANDLED; int offset = 0; int mode; int len; CallbackOptions *options = (CallbackOptions *)cookie; if (payload == NULL) { /* Just use first segment for string */ if (pkt == NULL) { cli_out("CT echo error: payload and pkt both NULL, cli %d\n", client_id); return BCM_RX_NOT_HANDLED; } payload = pkt->pkt_data[1].data; len = pkt->pkt_data[1].len; cli_out("CT echo warning: \n"); cli_out(" Segmented packet; segmentation not maintained on echo\n"); } else { len = payload_len; } UNPACK_SHORT(payload, depth); offset += sizeof(uint16); UNPACK_LONG(payload + offset, pkt_flags); offset += sizeof(uint32); async_free = pkt_flags & CTE_FLAGS_ASYNC_FREE; mode = client_id - ECHO_BASE_CLI_ID; if (mode < 0 || mode > 4) { cli_out("CT echo error: Bad client id: %d\n", client_id); return BCM_RX_NOT_HANDLED; } if (sal_strlen((char *)&payload[offset]) > len) { cli_out("CT echo error: Unterminated string in first segment\n"); return BCM_RX_HANDLED; } if (_shr_crc32(~0, payload, len) != _SHR_CRC32_CORRECT) { cli_out("CT echo error: Echo payload CRC failure.\n"); } if (options->verbose) { cli_out("%s echo request from " CPUDB_KEY_FMT ": %s\n", cte_mode_list[mode], CPUDB_KEY_DISP(src_key), &payload[offset]); cli_out(" Depth %d, flags 0x%x, len %d. (total %d)\n", depth, pkt_flags, len - offset, payload_len); } if (depth > 0) { /* Return echo: one less depth, clear async flag */ pkt_flags &= ~CTE_FLAGS_ASYNC_FREE; pkt_flags &= ~CTE_FLAGS_CRC_REGEN; _send_echo_pkt(client_id, payload, len, depth - 1, pkt_flags, mode, options->verbose, src_key, NULL); } if (async_free) { rv = BCM_RX_HANDLED_OWNED; sal_dpc(echo_free_buf, payload, pkt, NULL, NULL, NULL); } else { rv = BCM_RX_HANDLED; } return rv; }
char * sal_readline(char *prompt, char *buf, int bufsize, char *defl) { char *s, *full_prompt, *cont_prompt; #ifdef INCLUDE_EDITLINE extern void rl_prompt_set(CONST char *prompt); #else char *t; #endif int len; if (bufsize == 0) return NULL; cont_prompt = prompt[0] ? "? " : ""; full_prompt = sal_alloc(sal_strlen(prompt) + (defl ? sal_strlen(defl) : 0) + 8, __FILE__); sal_strcpy(full_prompt, prompt); if (defl) sal_sprintf(full_prompt + sal_strlen(full_prompt), "[%s] ", defl); #ifdef INCLUDE_EDITLINE printk_file("%s", full_prompt); s = readline(full_prompt); #else /* !INCLUDE_EDITLINE */ t = sal_alloc(bufsize, __FILE__); #if defined(KEYSTONE) && defined(__ECOS) diag_printf("%s", full_prompt); #else printk("%s", full_prompt); #endif if ((s = sal_console_gets(t, bufsize)) == 0) { sal_free(t); } else { s[bufsize - 1] = 0; if ((t = strchr(s, '\n')) != 0) { *t = 0; /* Replace garbage characters with spaces */ } for (t = s; *t; t++) { if (*t < 32 && *t != 7 && *t != 9) { *t = ' '; } } } #endif /* !INCLUDE_EDITLINE */ if (s == 0) { /* Handle Control-D */ buf[0] = 0; /* EOF */ buf = 0; goto done; } else { printk_file("%s\n", s); } len = 0; if (s[0] == 0) { if (defl && buf != defl) { if ((len = sal_strlen(defl)) >= bufsize) { len = bufsize - 1; } sal_memcpy(buf, defl, len); } } else { if ((len = sal_strlen(s)) >= bufsize) { len = bufsize - 1; printk("WARNING: input line truncated to %d chars\n", len); } sal_memcpy(buf, s, len); } buf[len] = 0; sal_free(s); /* * If line ends in a backslash, perform a continuation prompt. */ if (sal_strlen(buf) != 0) { /* * Ensure that there is atleast one character available */ s = buf + sal_strlen(buf) - 1; if (*s == '\\' && sal_readline(cont_prompt, s, bufsize - (s - buf), 0) == 0) { buf = 0; } } done: #ifdef INCLUDE_EDITLINE rl_prompt_set(NULL); #endif sal_free(full_prompt); return buf; }
/******************************************************************************* * 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; }
cmd_result_t cmd_bsc(int unit, args_t *a) { char *function, *tmp; int retv, chan, devno, len, i; uint8 *buf; uint32 addr, data, rlen; if (!sh_check_attached(ARG_CMD(a), unit)) return CMD_FAIL; function = ARG_GET(a); if (!function) { return CMD_USAGE; } else if (!sal_strncasecmp(function, "setmux", sal_strlen(function))) { tmp = ARG_GET(a); if (!tmp) { return CMD_USAGE; } chan = parse_integer(tmp); if ((chan < 0) || (chan > 7)) { return CMD_USAGE; } soc_bsc_setmux(unit, chan); } else if (!sal_strncasecmp(function, "readmax", sal_strlen(function))) { soc_bsc_readmax(unit); } else if (!sal_strncasecmp(function, "readdpm", sal_strlen(function))) { soc_bsc_readdpm(unit); } else if (!sal_strncasecmp(function,"probe", sal_strlen(function))) { retv = soc_bsc_probe(unit); /* Will attach if not yet attached */ if (retv < 0) { LOG_ERROR(BSL_LS_SOC_COMMON, (BSL_META_U(unit, "%s: ERROR: probe failed: %s\n"), ARG_CMD(a), bcm_errmsg(retv))); } else { cli_out("%s: detected %d device%s\n", ARG_CMD(a), retv, retv==1 ? "" : "s"); } } else if (!sal_strncasecmp(function,"show", sal_strlen(function))) { soc_bsc_show(unit); /* Will attach if not yet attached */ } else if (!sal_strncasecmp(function,"epr", sal_strlen(function))) { char buf_tmp[17]; buf_tmp[16] = '\0'; buf_tmp[0] = '\0'; tmp = ARG_GET(a); if (!tmp) { return CMD_USAGE; } addr = parse_integer(tmp); tmp = ARG_GET(a); if (tmp) { len = parse_integer(tmp); } else { len = 0x20; } if (addr + len > AT24C64_DEVICE_RW_SIZE) { cli_out("at24c64_read error: addr + len > %d\n", AT24C64_DEVICE_RW_SIZE); return CMD_OK; } buf = (uint8*)sal_alloc(len, "bsc"); if (buf == NULL) { cli_out("No memory\n"); return CMD_OK; } devno = soc_bsc_devopen(unit, BSC_AT24C32_NAME); if (devno < 0) { cli_out("%s: cannot open I2C device %s: %s\n", ARG_CMD(a), BSC_AT24C32_NAME, bcm_errmsg(devno)); sal_free(buf); return CMD_FAIL; } cli_out("0x%04x:", addr); rlen = len; retv = soc_eep24c64_read(unit, devno, addr, buf, &rlen); if ((rlen != len) || (retv != SOC_E_NONE)) { sal_free(buf); return CMD_OK; } for (i = 0; i < len; i++) { data = buf[i]; if (i && ((i % 8) == 0)) { cli_out(" "); } if (i && ((i % 16) == 0)) { cli_out("%s", buf_tmp); cli_out("\n0x%04x:", addr + i); buf_tmp[0] = '\0'; } buf_tmp[i % 16] = (isprint(data)) ? buf[i] : '.'; cli_out(" %02x", data); } if (i && (i % 16)) { buf_tmp[i % 16] = '\0'; } cli_out(" %s", buf_tmp); sal_free(buf); cli_out("\n"); } else if (!sal_strncasecmp(function,"epw", sal_strlen(function))) { tmp = ARG_GET(a); if (!tmp) { return CMD_USAGE; } addr = parse_integer(tmp); tmp = ARG_GET(a); if (!tmp) { return CMD_USAGE; } devno = soc_bsc_devopen(unit, BSC_AT24C32_NAME); if (devno < 0) { cli_out("%s: cannot open I2C device %s: %s\n", ARG_CMD(a), BSC_AT24C32_NAME, bcm_errmsg(devno)); return CMD_FAIL; } retv = soc_eep24c64_write(unit, devno, addr, (uint8 *)tmp, sal_strlen(tmp)); } else if (!sal_strncasecmp(function,"eptest", sal_strlen(function))) { devno = soc_bsc_devopen(unit, BSC_AT24C32_NAME); if (devno < 0) { cli_out("%s: cannot open I2C device %s: %s\n", ARG_CMD(a), BSC_AT24C32_NAME, bcm_errmsg(devno)); return CMD_FAIL; } soc_eep24c64_test(unit, devno); } else if (!sal_strncasecmp(function,"sfpread", sal_strlen(function))) { char sfp_dev_name[16]; tmp = ARG_GET(a); if (!tmp) { return CMD_USAGE; } addr = parse_integer(tmp); sal_sprintf(sfp_dev_name, "%s%d", BSC_SFP_NAME, addr); tmp = ARG_GET(a); if (!tmp) { return CMD_USAGE; } addr = parse_integer(tmp); tmp = ARG_GET(a); if (tmp) { len = parse_integer(tmp); } else { len = 0x20; } if (addr + len > SFP_DEVICE_SIZE) { cli_out("sfp_read error: addr + len > %d\n", SFP_DEVICE_SIZE); return CMD_OK; } buf = (uint8*)sal_alloc(len, "bsc"); if (buf == NULL) { cli_out("No memory\n"); return CMD_OK; } devno = soc_bsc_devopen(unit, sfp_dev_name); if (devno < 0) { cli_out("%s: cannot open I2C device %s: %s\n", ARG_CMD(a), sfp_dev_name, bcm_errmsg(devno)); sal_free(buf); return CMD_FAIL; } cli_out("0x%04x:", addr); rlen = len; retv = soc_sfp_read(unit, devno, addr, buf, &rlen); if ((rlen != len) || (retv != SOC_E_NONE)) { sal_free(buf); return CMD_OK; } for (i = 0; i < len; i++) { data = buf[i]; if (i && ((i % 8) == 0)) { cli_out(" "); } if (i && ((i % 16) == 0)) { cli_out("\n0x%04x:", addr + i); } cli_out(" %02x", data); } sal_free(buf); cli_out("\n"); } else if (!sal_strncasecmp(function,"sfpwrite", sal_strlen(function))) { char sfp_dev_name[16]; uint8 db; tmp = ARG_GET(a); if (!tmp) { return CMD_USAGE; } addr = parse_integer(tmp); sal_sprintf(sfp_dev_name, "%s%d", BSC_SFP_NAME, addr); tmp = ARG_GET(a); if (!tmp) { return CMD_USAGE; } addr = parse_integer(tmp); tmp = ARG_GET(a); if (!tmp) { return CMD_USAGE; } db = (uint8)parse_integer(tmp); devno = soc_bsc_devopen(unit, sfp_dev_name); if (devno < 0) { cli_out("%s: cannot open I2C device %s: %s\n", ARG_CMD(a), sfp_dev_name, bcm_errmsg(devno)); return CMD_FAIL; } retv = soc_sfp_write(unit, devno, addr, (uint8 *)&db, 1); } else { return CMD_USAGE; } return CMD_OK; }