sw_error_t athena_vlan_reset(a_uint32_t dev_id) { #ifdef HSL_STANDALONG a_int16_t i; v_array_t *p_v_array; HSL_DEV_ID_CHECK(dev_id); aos_mem_zero(p_vlan_table[dev_id], MAX_VLAN_ENTRY * (sizeof (v_array_t))); p_v_array = p_vlan_table[dev_id]; for (i = 0; i < MAX_VLAN_ENTRY; i++) { p_v_array[i].active = A_FALSE; } #endif return SW_OK; }
static sw_error_t _shiva_led_ctrl_pattern_get(a_uint32_t dev_id, led_pattern_group_t group, led_pattern_id_t id, led_ctrl_pattern_t * pattern) { a_uint32_t data = 0, reg, tmp; a_uint32_t addr; sw_error_t rv; HSL_DEV_ID_CHECK(dev_id); if (group >= LED_GROUP_BUTT) { return SW_BAD_PARAM; } if (id > MAX_LED_PATTERN_ID) { return SW_BAD_PARAM; } if ((LED_MAC_PORT_GROUP == group) && (0 != id)) { return SW_BAD_PARAM; } aos_mem_zero(pattern, sizeof(led_ctrl_pattern_t)); if (LED_MAC_PORT_GROUP == group) { addr = LED_PATTERN_ADDR + 8; } else { addr = LED_PATTERN_ADDR + (id << 2); } HSL_REG_ENTRY_GEN_GET(rv, dev_id, addr, sizeof (a_uint32_t), (a_uint8_t *) (®), sizeof (a_uint32_t)); SW_RTN_ON_ERROR(rv); if (LED_WAN_PORT_GROUP == group) { data = (reg >> 16) & 0xffff; } else {
sw_error_t athena_vlan_init(a_uint32_t dev_id) { #ifdef HSL_STANDALONG a_int16_t i; v_array_t *p_v_array; v_array_t *p_mem; HSL_DEV_ID_CHECK(dev_id); /* allocate memory for vlan info */ p_mem = aos_mem_alloc(MAX_VLAN_ENTRY * (sizeof (v_array_t))); if (p_mem == NULL) return SW_OUT_OF_MEM; aos_mem_zero(p_mem, MAX_VLAN_ENTRY * (sizeof (v_array_t))); /* start address for vlan info */ p_vlan_table[dev_id] = p_v_array = p_mem; for (i = 0; i < MAX_VLAN_ENTRY; i++) { p_v_array[i].active = A_FALSE; } #endif #ifndef HSL_STANDALONG hsl_api_t *p_api; SW_RTN_ON_NULL (p_api = hsl_api_ptr_get(dev_id)); p_api->vlan_entry_append = athena_vlan_entry_append; p_api->vlan_creat = athena_vlan_create; p_api->vlan_delete = athena_vlan_delete; #endif return SW_OK; }
sw_error_t cmd_show_fdb(a_uint32_t *arg_val) { if (ssdk_cfg.init_cfg.chip_type == CHIP_ISIS) { sw_error_t rtn; a_uint32_t cnt = 0; fal_fdb_op_t *fdb_op = (fal_fdb_op_t *) (ioctl_buf + sizeof(sw_error_t) / 4); fal_fdb_entry_t *fdb_entry = (fal_fdb_entry_t *) (ioctl_buf + sizeof(sw_error_t) / 4 + sizeof(fal_fdb_op_t) / 4); aos_mem_zero(fdb_op, sizeof (fal_fdb_op_t)); aos_mem_zero(fdb_entry, sizeof (fal_fdb_entry_t)); arg_val[0] = SW_API_FDB_EXTEND_FIRST; while (1) { arg_val[1] = (a_uint32_t) ioctl_buf; arg_val[2] = get_devid(); arg_val[3] = (a_uint32_t) fdb_op; arg_val[4] = (a_uint32_t) fdb_entry; rtn = cmd_exec_api(arg_val); if ((SW_OK != rtn) || (SW_OK != (sw_error_t) (*ioctl_buf))) { break; } arg_val[0] = SW_API_FDB_EXTEND_NEXT; cnt++; } if((rtn != SW_OK) && (rtn != SW_NO_MORE)) cmd_print_error(rtn); else dprintf("\ntotal %d entries\n", cnt); }else if ((ssdk_cfg.init_cfg.chip_type == CHIP_ISISC) || (ssdk_cfg.init_cfg.chip_type == CHIP_DESS)) { sw_error_t rtn; a_uint32_t cnt = 0; fal_fdb_op_t *fdb_op = (fal_fdb_op_t *) (ioctl_buf + sizeof(sw_error_t) / 4); fal_fdb_entry_t *fdb_entry = (fal_fdb_entry_t *) (ioctl_buf + sizeof(sw_error_t) / 4 + sizeof(fal_fdb_op_t) / 4); aos_mem_zero(fdb_op, sizeof (fal_fdb_op_t)); aos_mem_zero(fdb_entry, sizeof (fal_fdb_entry_t)); arg_val[0] = SW_API_FDB_EXTEND_FIRST; while (1) { arg_val[1] = (a_uint32_t) ioctl_buf; arg_val[2] = get_devid(); arg_val[3] = (a_uint32_t) fdb_op; arg_val[4] = (a_uint32_t) fdb_entry; rtn = cmd_exec_api(arg_val); if ((SW_OK != rtn) || (SW_OK != (sw_error_t) (*ioctl_buf))) { break; } arg_val[0] = SW_API_FDB_EXTEND_NEXT; cnt++; } if((rtn != SW_OK) && (rtn != SW_NO_MORE)) cmd_print_error(rtn); else dprintf("\ntotal %d entries\n", cnt); }else if (ssdk_cfg.init_cfg.chip_type == CHIP_SHIVA) { sw_error_t rtn; a_uint32_t cnt = 0; fal_fdb_entry_t *fdb_entry = (fal_fdb_entry_t *) (ioctl_buf + 2); memset(fdb_entry, 0, sizeof (fal_fdb_entry_t)); arg_val[0] = SW_API_FDB_ITERATE; *(ioctl_buf + 1) = 0; while (1) { arg_val[1] = (a_uint32_t) ioctl_buf; arg_val[2] = get_devid(); arg_val[3] = (a_uint32_t) (ioctl_buf + 1); arg_val[4] = (a_uint32_t) fdb_entry; rtn = cmd_exec_api(arg_val); if ((SW_OK != rtn) || (SW_OK != (sw_error_t) (*ioctl_buf))) { break; } cnt++; } if((rtn != SW_OK) && (rtn != SW_NO_MORE)) cmd_print_error(rtn); else dprintf("\ntotal %d entries\n", cnt); }else { sw_error_t rtn; a_uint32_t rtn_size = 1, cnt = 0; fal_fdb_entry_t *fdb_entry = (fal_fdb_entry_t *) (ioctl_buf + rtn_size); memset(fdb_entry, 0, sizeof (fal_fdb_entry_t)); arg_val[0] = SW_API_FDB_FIRST; while (1) { arg_val[1] = (a_uint32_t) ioctl_buf; arg_val[2] = get_devid(); arg_val[3] = (a_uint32_t) fdb_entry; rtn = cmd_exec_api(arg_val); if ((SW_OK != rtn) || (SW_OK != (sw_error_t) (*ioctl_buf))) { break; } arg_val[0] = SW_API_FDB_NEXT; cnt++; } if((rtn != SW_OK) && (rtn != SW_NO_MORE)) cmd_print_error(rtn); else dprintf("\ntotal %d entries\n", cnt); } return SW_OK; }
static sw_error_t _isis_acl_rule_delete(a_uint32_t dev_id, a_uint32_t list_id, a_uint32_t rule_id, a_uint32_t rule_nr) { isis_acl_rule_t *sw_rule; isis_acl_list_t *sw_list; a_uint32_t i, flt_idx = 0, src_idx, dst_idx, del_nr = 0, flt_nr = 0; sw_error_t rv; HSL_DEV_ID_CHECK(dev_id); if (ISIS_MAX_LIST_ID < list_id) { return SW_NOT_SUPPORTED; } sw_list = _isis_acl_list_loc(dev_id, list_id); if (NULL == sw_list) { return SW_NOT_FOUND; } if (sw_list->rule_nr < (rule_id + rule_nr)) { return SW_BAD_PARAM; } aos_mem_zero(hw_rule_tmp[dev_id], ISIS_HW_RULE_TMP_CNT * sizeof (isis_acl_rule_t)); aos_mem_zero(sw_rule_tmp[dev_id], ISIS_MAX_FILTER * sizeof (isis_acl_rule_t)); for (i = 0; i < ISIS_MAX_FILTER; i++) { sw_rule = &(sw_rule_ent[dev_id][i]); if ((ENT_USED & sw_rule->status) && (sw_rule->list_id == list_id)) { if (!flt_nr) { flt_idx = i; } if ((sw_rule->rule_id >= rule_id) && (sw_rule->rule_id < (rule_id + rule_nr))) { del_nr++; } else { aos_mem_copy(&(hw_rule_tmp[dev_id][flt_idx + flt_nr]), sw_rule, sizeof (isis_acl_rule_t)); } flt_nr++; } } if (!del_nr) { return SW_NOT_FOUND; } _isis_acl_sw_rule_dump("hw rule before del", hw_rule_tmp[dev_id]); for (i = 0; i < flt_nr; i++) { sw_rule = &(hw_rule_tmp[dev_id][i]); if (ENT_USED & sw_rule->status) { break; } } if (i != flt_nr) { src_idx = flt_idx + i; dst_idx = flt_idx; rv = _isis_acl_list_insert(dev_id, &src_idx, &dst_idx, hw_rule_tmp[dev_id], sw_rule_tmp[dev_id]); SW_RTN_ON_ERROR(rv); } _isis_acl_rule_sync(dev_id, flt_idx, flt_nr); sw_list->rule_nr -= rule_nr; _isis_acl_sw_rule_dump("sw rule after del", sw_rule_ent[dev_id]); return SW_OK; }
static sw_error_t _isis_acl_rule_add(a_uint32_t dev_id, a_uint32_t list_id, a_uint32_t rule_id, a_uint32_t rule_nr, fal_acl_rule_t * rule) { sw_error_t rv; isis_acl_list_t *sw_list; isis_acl_rule_t *sw_rule; a_uint32_t i, free_flt_nr, old_flt_nr, old_flt_idx, new_flt_nr, bind_pts; HSL_DEV_ID_CHECK(dev_id); if (ISIS_MAX_LIST_ID < list_id) { return SW_NOT_SUPPORTED; } if ((0 == rule_nr) || (NULL == rule)) { return SW_BAD_PARAM; } sw_list = _isis_acl_list_loc(dev_id, list_id); if (NULL == sw_list) { return SW_NOT_FOUND; } if (rule_id != sw_list->rule_nr) { return SW_BAD_PARAM; } old_flt_idx = 0; old_flt_nr = 0; free_flt_nr = 0; aos_mem_zero(hw_rule_tmp[dev_id], ISIS_HW_RULE_TMP_CNT * sizeof (isis_acl_rule_t)); aos_mem_zero(sw_rule_tmp[dev_id], ISIS_MAX_FILTER * sizeof (isis_acl_rule_t)); for (i = 0; i < ISIS_MAX_FILTER; i++) { sw_rule = &(sw_rule_ent[dev_id][i]); if (ENT_USED & sw_rule->status) { if (sw_rule->list_id == sw_list->list_id) { aos_mem_copy(&(hw_rule_tmp[dev_id][old_flt_nr]), sw_rule, sizeof (isis_acl_rule_t)); if (!old_flt_nr) { old_flt_idx = i; } old_flt_nr++; } } else { free_flt_nr++; } } if (!free_flt_nr) { return SW_NO_RESOURCE; } /* parse rule entry and alloc rule resource */ new_flt_nr = old_flt_nr; for (i = 0; i < rule_nr; i++) { rv = _isis_acl_rule_sw_to_hw(dev_id, &rule[i], hw_rule_tmp[dev_id], &new_flt_nr); SW_RTN_ON_ERROR(rv); } if (free_flt_nr < (new_flt_nr - old_flt_nr)) { return SW_NO_RESOURCE; } for (i = old_flt_nr; i < new_flt_nr; i++) { hw_rule_tmp[dev_id][i].status |= ENT_USED; hw_rule_tmp[dev_id][i].list_id = sw_list->list_id; hw_rule_tmp[dev_id][i].list_pri = sw_list->list_pri; bind_pts = sw_list->bind_pts; SW_SET_REG_BY_FIELD(MAC_RUL_V4, SRC_PT, bind_pts, (hw_rule_tmp[dev_id][i].filter.vlu[4])); } for (i = 0; i < old_flt_nr; i++) { sw_rule = &(sw_rule_ent[dev_id][old_flt_idx + i]); sw_rule->status &= (~ENT_USED); sw_rule->status |= (ENT_TMP); } rv = _isis_acl_rule_alloc(dev_id, sw_list, new_flt_nr); if (SW_OK != rv) { aos_mem_zero(sw_rule_tmp[dev_id], ISIS_MAX_FILTER * sizeof (isis_acl_rule_t)); rv = _isis_acl_rule_reorder(dev_id, sw_list); } for (i = 0; i < old_flt_nr; i++) { sw_rule = &(sw_rule_ent[dev_id][i + old_flt_idx]); sw_rule->status |= (ENT_USED); sw_rule->status &= (~ENT_TMP); } SW_RTN_ON_ERROR(rv); _isis_acl_rule_sync(dev_id, 0, ISIS_MAX_FILTER); sw_list->rule_nr += rule_nr; _isis_acl_sw_rule_dump("sw rule after add", sw_rule_ent[dev_id]); return SW_OK; }
sw_error_t isis_acl_init(a_uint32_t dev_id) { HSL_DEV_ID_CHECK(dev_id); sw_list_ent[dev_id] = (isis_acl_list_t *) aos_mem_alloc(ISIS_MAX_FILTER * sizeof (isis_acl_list_t)); if (NULL == sw_list_ent[dev_id]) { return SW_NO_RESOURCE; } aos_mem_zero(sw_list_ent[dev_id], ISIS_MAX_FILTER * sizeof (isis_acl_list_t)); sw_rule_ent[dev_id] = (isis_acl_rule_t *) aos_mem_alloc(ISIS_MAX_FILTER * sizeof (isis_acl_rule_t)); if (NULL == sw_rule_ent[dev_id]) { return SW_NO_RESOURCE; } aos_mem_zero(sw_rule_ent[dev_id], ISIS_MAX_FILTER * sizeof (isis_acl_rule_t)); hw_rule_tmp[dev_id] = (isis_acl_rule_t *) aos_mem_alloc(ISIS_HW_RULE_TMP_CNT * sizeof (isis_acl_rule_t)); if (NULL == hw_rule_tmp[dev_id]) { return SW_NO_RESOURCE; } sw_rule_tmp[dev_id] = (isis_acl_rule_t *) aos_mem_alloc(ISIS_MAX_FILTER * sizeof (isis_acl_rule_t)); if (NULL == sw_rule_tmp[dev_id]) { return SW_NO_RESOURCE; } #ifdef ISIS_SW_ENTRY sw_filter_mem = aos_mem_alloc(ISIS_MAX_FILTER * sizeof (hw_filter_t)); if (NULL == sw_filter_mem) { return SW_NO_RESOURCE; } aos_mem_zero(sw_filter_mem, ISIS_MAX_FILTER * sizeof (hw_filter_t)); #endif #ifndef HSL_STANDALONG { hsl_api_t *p_api; SW_RTN_ON_NULL(p_api = hsl_api_ptr_get(dev_id)); p_api->acl_list_creat = isis_acl_list_creat; p_api->acl_list_destroy = isis_acl_list_destroy; p_api->acl_list_bind = isis_acl_list_bind; p_api->acl_list_unbind = isis_acl_list_unbind; p_api->acl_rule_add = isis_acl_rule_add; p_api->acl_rule_delete = isis_acl_rule_delete; p_api->acl_rule_query = isis_acl_rule_query; p_api->acl_status_set = isis_acl_status_set; p_api->acl_status_get = isis_acl_status_get; p_api->acl_list_dump = isis_acl_list_dump; p_api->acl_rule_dump = isis_acl_rule_dump; p_api->acl_port_udf_profile_set = isis_acl_port_udf_profile_set; p_api->acl_port_udf_profile_get = isis_acl_port_udf_profile_get; } #endif return SW_OK; }
HSL_LOCAL sw_error_t isis_acl_rule_dump(a_uint32_t dev_id) { a_uint32_t flt_idx, i; sw_error_t rv; hw_filter_t filter; aos_printk("\nisis_acl_rule_dump:\n"); for (flt_idx = 0; flt_idx < ISIS_MAX_FILTER; flt_idx++) { aos_mem_zero(&filter, sizeof (hw_filter_t)); rv = _isis_filter_up_to_sw(dev_id, &filter, flt_idx); if (SW_OK != rv) { continue; } aos_printk("\n%d filter dump:", flt_idx); aos_printk("\nhardware content:"); aos_printk("\nact:"); for (i = 0; i < (sizeof (filter.act) / sizeof (a_uint32_t)); i++) { aos_printk("%08x ", filter.act[i]); } aos_printk("\nvlu:"); for (i = 0; i < (sizeof (filter.vlu) / sizeof (a_uint32_t)); i++) { aos_printk("%08x ", filter.vlu[i]); } aos_printk("\nmsk:"); for (i = 0; i < (sizeof (filter.msk) / sizeof (a_uint32_t)); i++) { aos_printk("%08x ", filter.msk[i]); } aos_printk("\nsoftware content:"); aos_printk("\nact:"); for (i = 0; i < (sizeof (filter.act) / sizeof (a_uint32_t)); i++) { aos_printk("%08x ", sw_rule_ent[dev_id][flt_idx].filter.act[i]); } aos_printk("\nvlu:"); for (i = 0; i < (sizeof (filter.vlu) / sizeof (a_uint32_t)); i++) { aos_printk("%08x ", sw_rule_ent[dev_id][flt_idx].filter.vlu[i]); } aos_printk("\nmsk:"); for (i = 0; i < (sizeof (filter.msk) / sizeof (a_uint32_t)); i++) { aos_printk("%08x ", sw_rule_ent[dev_id][flt_idx].filter.msk[i]); } aos_printk("\nctl:status[%02d] list_id[%02d] rule_id[%02d]", sw_rule_ent[dev_id][flt_idx].status, sw_rule_ent[dev_id][flt_idx].list_id, sw_rule_ent[dev_id][flt_idx].rule_id); aos_printk("\n\n"); } return SW_OK; }
static void _shiva_fdb_hw_to_sw(a_uint32_t tbl[3], fal_fdb_entry_t * entry) { a_uint32_t i, data; aos_mem_zero(entry, sizeof (fal_fdb_entry_t)); entry->dacmd = FAL_MAC_FRWRD; SW_GET_FIELD_BY_REG(FDB_TABLE_FUNC2, FDB_CPYCPU_EN, data, tbl[2]); if (1 == data) { entry->dacmd = FAL_MAC_CPY_TO_CPU; } SW_GET_FIELD_BY_REG(FDB_TABLE_FUNC2, FDB_RDTCPU_EN, data, tbl[2]); if (1 == data) { entry->dacmd = FAL_MAC_RDT_TO_CPU; } entry->leaky_en = A_FALSE; SW_GET_FIELD_BY_REG(FDB_TABLE_FUNC2, FDB_LEANKY_EN, data, tbl[2]); if (1 == data) { entry->leaky_en = A_TRUE; } entry->static_en = A_FALSE; SW_GET_FIELD_BY_REG(FDB_TABLE_FUNC2, FDB_STATUS, data, tbl[2]); if (0xf == data) { entry->static_en = A_TRUE; } entry->clone_en = A_FALSE; SW_GET_FIELD_BY_REG(FDB_TABLE_FUNC1, FDB_MACCLONE_EN, data, tbl[1]); if (1 == data) { entry->clone_en = A_TRUE; } entry->sacmd = FAL_MAC_FRWRD; SW_GET_FIELD_BY_REG(FDB_TABLE_FUNC1, FDB_SADROP_EN, data, tbl[1]); if (1 == data) { entry->sacmd = FAL_MAC_DROP; } entry->mirror_en = A_FALSE; SW_GET_FIELD_BY_REG(FDB_TABLE_FUNC1, FDB_MIRROR_EN, data, tbl[1]); if (1 == data) { entry->mirror_en = A_TRUE; } entry->da_pri_en = A_FALSE; SW_GET_FIELD_BY_REG(FDB_TABLE_FUNC1, FDB_PRIORITY_EN, data, tbl[1]); if (1 == data) { SW_GET_FIELD_BY_REG(FDB_TABLE_FUNC1, FDB_PRIORITY, data, tbl[1]); entry->da_pri_en = A_TRUE; entry->da_queue = data & 0x3; } entry->cross_pt_state = A_FALSE; SW_GET_FIELD_BY_REG(FDB_TABLE_FUNC1, FDB_CROSS_STATE, data, tbl[1]); if (1 == data) { entry->cross_pt_state = A_TRUE; } SW_GET_FIELD_BY_REG(FDB_TABLE_FUNC1, FDB_DES_PORT, data, tbl[1]); entry->portmap_en = A_TRUE; entry->port.map = data; for (i = 2; i < 6; i++) { entry->addr.uc[i] = (tbl[0] >> ((5 - i) << 3)) & 0xff; } for (i = 0; i < 2; i++) { entry->addr.uc[i] = (tbl[1] >> ((1 - i) << 3)) & 0xff; } }
static void shiva_atu_hw_to_sw(const a_uint32_t reg[], fal_fdb_entry_t * entry) { a_uint32_t i, data; aos_mem_zero(entry, sizeof (fal_fdb_entry_t)); entry->dacmd = FAL_MAC_FRWRD; SW_GET_FIELD_BY_REG(ADDR_TABLE_FUNC2, COPY_TO_CPU, data, reg[2]); if (1 == data) { entry->dacmd = FAL_MAC_CPY_TO_CPU; } SW_GET_FIELD_BY_REG(ADDR_TABLE_FUNC2, REDRCT_TO_CPU, data, reg[2]); if (1 == data) { entry->dacmd = FAL_MAC_RDT_TO_CPU; } entry->sacmd = FAL_MAC_FRWRD; SW_GET_FIELD_BY_REG(ADDR_TABLE_FUNC2, SA_DROP_EN, data, reg[2]); if (1 == data) { entry->sacmd = FAL_MAC_DROP; } entry->leaky_en = A_FALSE; SW_GET_FIELD_BY_REG(ADDR_TABLE_FUNC2, LEAKY_EN, data, reg[2]); if (1 == data) { entry->leaky_en = A_TRUE; } entry->static_en = A_FALSE; SW_GET_FIELD_BY_REG(ADDR_TABLE_FUNC2, AT_STATUS, data, reg[2]); if (0xf == data) { entry->static_en = A_TRUE; } entry->mirror_en = A_FALSE; SW_GET_FIELD_BY_REG(ADDR_TABLE_FUNC2, MIRROR_EN, data, reg[2]); if (1 == data) { entry->mirror_en = A_TRUE; } entry->clone_en = A_FALSE; SW_GET_FIELD_BY_REG(ADDR_TABLE_FUNC2, CLONE_EN, data, reg[2]); if (1 == data) { entry->clone_en = A_TRUE; } entry->da_pri_en = A_FALSE; SW_GET_FIELD_BY_REG(ADDR_TABLE_FUNC2, AT_PRI_EN, data, reg[2]); if (1 == data) { SW_GET_FIELD_BY_REG(ADDR_TABLE_FUNC2, AT_PRI, data, reg[2]); entry->da_pri_en = A_TRUE; entry->da_queue = data & 0x3; } entry->cross_pt_state = A_FALSE; SW_GET_FIELD_BY_REG(ADDR_TABLE_FUNC2, CROSS_PT, data, reg[2]); if (1 == data) { entry->cross_pt_state = A_TRUE; } SW_GET_FIELD_BY_REG(ADDR_TABLE_FUNC2, DES_PORT, data, reg[2]); entry->portmap_en = A_TRUE; entry->port.map = data; for (i = 0; i < 4; i++) { entry->addr.uc[i] = (reg[1] >> ((3 - i) << 3)) & 0xff; } for (i = 4; i < 6; i++) { entry->addr.uc[i] = (reg[0] >> ((7 - i) << 3)) & 0xff; } return; }