13c83654fSVladimir Oltean // SPDX-License-Identifier: (GPL-2.0 OR MIT) 23c83654fSVladimir Oltean /* Microsemi Ocelot Switch driver 33c83654fSVladimir Oltean * Copyright (c) 2019 Microsemi Corporation 43c83654fSVladimir Oltean */ 53c83654fSVladimir Oltean 63c83654fSVladimir Oltean #include <linux/iopoll.h> 73c83654fSVladimir Oltean #include <linux/proc_fs.h> 83c83654fSVladimir Oltean 93c83654fSVladimir Oltean #include <soc/mscc/ocelot_vcap.h> 103c83654fSVladimir Oltean #include "ocelot_police.h" 113c83654fSVladimir Oltean #include "ocelot_vcap.h" 123c83654fSVladimir Oltean #include "ocelot_s2.h" 133c83654fSVladimir Oltean 143c83654fSVladimir Oltean #define OCELOT_POLICER_DISCARD 0x17f 153c83654fSVladimir Oltean #define ENTRY_WIDTH 32 163c83654fSVladimir Oltean 173c83654fSVladimir Oltean enum vcap_sel { 183c83654fSVladimir Oltean VCAP_SEL_ENTRY = 0x1, 193c83654fSVladimir Oltean VCAP_SEL_ACTION = 0x2, 203c83654fSVladimir Oltean VCAP_SEL_COUNTER = 0x4, 213c83654fSVladimir Oltean VCAP_SEL_ALL = 0x7, 223c83654fSVladimir Oltean }; 233c83654fSVladimir Oltean 243c83654fSVladimir Oltean enum vcap_cmd { 253c83654fSVladimir Oltean VCAP_CMD_WRITE = 0, /* Copy from Cache to TCAM */ 263c83654fSVladimir Oltean VCAP_CMD_READ = 1, /* Copy from TCAM to Cache */ 273c83654fSVladimir Oltean VCAP_CMD_MOVE_UP = 2, /* Move <count> up */ 283c83654fSVladimir Oltean VCAP_CMD_MOVE_DOWN = 3, /* Move <count> down */ 293c83654fSVladimir Oltean VCAP_CMD_INITIALIZE = 4, /* Write all (from cache) */ 303c83654fSVladimir Oltean }; 313c83654fSVladimir Oltean 323c83654fSVladimir Oltean #define VCAP_ENTRY_WIDTH 12 /* Max entry width (32bit words) */ 333c83654fSVladimir Oltean #define VCAP_COUNTER_WIDTH 4 /* Max counter width (32bit words) */ 343c83654fSVladimir Oltean 353c83654fSVladimir Oltean struct vcap_data { 363c83654fSVladimir Oltean u32 entry[VCAP_ENTRY_WIDTH]; /* ENTRY_DAT */ 373c83654fSVladimir Oltean u32 mask[VCAP_ENTRY_WIDTH]; /* MASK_DAT */ 383c83654fSVladimir Oltean u32 action[VCAP_ENTRY_WIDTH]; /* ACTION_DAT */ 393c83654fSVladimir Oltean u32 counter[VCAP_COUNTER_WIDTH]; /* CNT_DAT */ 403c83654fSVladimir Oltean u32 tg; /* TG_DAT */ 413c83654fSVladimir Oltean u32 type; /* Action type */ 423c83654fSVladimir Oltean u32 tg_sw; /* Current type-group */ 433c83654fSVladimir Oltean u32 cnt; /* Current counter */ 443c83654fSVladimir Oltean u32 key_offset; /* Current entry offset */ 453c83654fSVladimir Oltean u32 action_offset; /* Current action offset */ 463c83654fSVladimir Oltean u32 counter_offset; /* Current counter offset */ 473c83654fSVladimir Oltean u32 tg_value; /* Current type-group value */ 483c83654fSVladimir Oltean u32 tg_mask; /* Current type-group mask */ 493c83654fSVladimir Oltean }; 503c83654fSVladimir Oltean 513c83654fSVladimir Oltean static u32 vcap_s2_read_update_ctrl(struct ocelot *ocelot) 523c83654fSVladimir Oltean { 533c83654fSVladimir Oltean return ocelot_read(ocelot, S2_CORE_UPDATE_CTRL); 543c83654fSVladimir Oltean } 553c83654fSVladimir Oltean 563c83654fSVladimir Oltean static void vcap_cmd(struct ocelot *ocelot, u16 ix, int cmd, int sel) 573c83654fSVladimir Oltean { 583c83654fSVladimir Oltean const struct vcap_props *vcap_is2 = &ocelot->vcap[VCAP_IS2]; 593c83654fSVladimir Oltean 603c83654fSVladimir Oltean u32 value = (S2_CORE_UPDATE_CTRL_UPDATE_CMD(cmd) | 613c83654fSVladimir Oltean S2_CORE_UPDATE_CTRL_UPDATE_ADDR(ix) | 623c83654fSVladimir Oltean S2_CORE_UPDATE_CTRL_UPDATE_SHOT); 633c83654fSVladimir Oltean 643c83654fSVladimir Oltean if ((sel & VCAP_SEL_ENTRY) && ix >= vcap_is2->entry_count) 653c83654fSVladimir Oltean return; 663c83654fSVladimir Oltean 673c83654fSVladimir Oltean if (!(sel & VCAP_SEL_ENTRY)) 683c83654fSVladimir Oltean value |= S2_CORE_UPDATE_CTRL_UPDATE_ENTRY_DIS; 693c83654fSVladimir Oltean 703c83654fSVladimir Oltean if (!(sel & VCAP_SEL_ACTION)) 713c83654fSVladimir Oltean value |= S2_CORE_UPDATE_CTRL_UPDATE_ACTION_DIS; 723c83654fSVladimir Oltean 733c83654fSVladimir Oltean if (!(sel & VCAP_SEL_COUNTER)) 743c83654fSVladimir Oltean value |= S2_CORE_UPDATE_CTRL_UPDATE_CNT_DIS; 753c83654fSVladimir Oltean 763c83654fSVladimir Oltean ocelot_write(ocelot, value, S2_CORE_UPDATE_CTRL); 773c83654fSVladimir Oltean readx_poll_timeout(vcap_s2_read_update_ctrl, ocelot, value, 783c83654fSVladimir Oltean (value & S2_CORE_UPDATE_CTRL_UPDATE_SHOT) == 0, 793c83654fSVladimir Oltean 10, 100000); 803c83654fSVladimir Oltean } 813c83654fSVladimir Oltean 823c83654fSVladimir Oltean /* Convert from 0-based row to VCAP entry row and run command */ 833c83654fSVladimir Oltean static void vcap_row_cmd(struct ocelot *ocelot, u32 row, int cmd, int sel) 843c83654fSVladimir Oltean { 853c83654fSVladimir Oltean const struct vcap_props *vcap_is2 = &ocelot->vcap[VCAP_IS2]; 863c83654fSVladimir Oltean 873c83654fSVladimir Oltean vcap_cmd(ocelot, vcap_is2->entry_count - row - 1, cmd, sel); 883c83654fSVladimir Oltean } 893c83654fSVladimir Oltean 903c83654fSVladimir Oltean static void vcap_entry2cache(struct ocelot *ocelot, struct vcap_data *data) 913c83654fSVladimir Oltean { 923c83654fSVladimir Oltean const struct vcap_props *vcap_is2 = &ocelot->vcap[VCAP_IS2]; 933c83654fSVladimir Oltean u32 entry_words, i; 943c83654fSVladimir Oltean 953c83654fSVladimir Oltean entry_words = DIV_ROUND_UP(vcap_is2->entry_width, ENTRY_WIDTH); 963c83654fSVladimir Oltean 973c83654fSVladimir Oltean for (i = 0; i < entry_words; i++) { 983c83654fSVladimir Oltean ocelot_write_rix(ocelot, data->entry[i], S2_CACHE_ENTRY_DAT, i); 993c83654fSVladimir Oltean ocelot_write_rix(ocelot, ~data->mask[i], S2_CACHE_MASK_DAT, i); 1003c83654fSVladimir Oltean } 1013c83654fSVladimir Oltean ocelot_write(ocelot, data->tg, S2_CACHE_TG_DAT); 1023c83654fSVladimir Oltean } 1033c83654fSVladimir Oltean 1043c83654fSVladimir Oltean static void vcap_cache2entry(struct ocelot *ocelot, struct vcap_data *data) 1053c83654fSVladimir Oltean { 1063c83654fSVladimir Oltean const struct vcap_props *vcap_is2 = &ocelot->vcap[VCAP_IS2]; 1073c83654fSVladimir Oltean u32 entry_words, i; 1083c83654fSVladimir Oltean 1093c83654fSVladimir Oltean entry_words = DIV_ROUND_UP(vcap_is2->entry_width, ENTRY_WIDTH); 1103c83654fSVladimir Oltean 1113c83654fSVladimir Oltean for (i = 0; i < entry_words; i++) { 1123c83654fSVladimir Oltean data->entry[i] = ocelot_read_rix(ocelot, S2_CACHE_ENTRY_DAT, i); 1133c83654fSVladimir Oltean // Invert mask 1143c83654fSVladimir Oltean data->mask[i] = ~ocelot_read_rix(ocelot, S2_CACHE_MASK_DAT, i); 1153c83654fSVladimir Oltean } 1163c83654fSVladimir Oltean data->tg = ocelot_read(ocelot, S2_CACHE_TG_DAT); 1173c83654fSVladimir Oltean } 1183c83654fSVladimir Oltean 1193c83654fSVladimir Oltean static void vcap_action2cache(struct ocelot *ocelot, struct vcap_data *data) 1203c83654fSVladimir Oltean { 1213c83654fSVladimir Oltean const struct vcap_props *vcap_is2 = &ocelot->vcap[VCAP_IS2]; 1223c83654fSVladimir Oltean u32 action_words, mask; 1233c83654fSVladimir Oltean int i, width; 1243c83654fSVladimir Oltean 1253c83654fSVladimir Oltean /* Encode action type */ 1263c83654fSVladimir Oltean width = vcap_is2->action_type_width; 1273c83654fSVladimir Oltean if (width) { 1283c83654fSVladimir Oltean mask = GENMASK(width, 0); 1293c83654fSVladimir Oltean data->action[0] = ((data->action[0] & ~mask) | data->type); 1303c83654fSVladimir Oltean } 1313c83654fSVladimir Oltean 1323c83654fSVladimir Oltean action_words = DIV_ROUND_UP(vcap_is2->action_width, ENTRY_WIDTH); 1333c83654fSVladimir Oltean 1343c83654fSVladimir Oltean for (i = 0; i < action_words; i++) 1353c83654fSVladimir Oltean ocelot_write_rix(ocelot, data->action[i], S2_CACHE_ACTION_DAT, 1363c83654fSVladimir Oltean i); 1373c83654fSVladimir Oltean 1383c83654fSVladimir Oltean for (i = 0; i < vcap_is2->counter_words; i++) 1393c83654fSVladimir Oltean ocelot_write_rix(ocelot, data->counter[i], S2_CACHE_CNT_DAT, i); 1403c83654fSVladimir Oltean } 1413c83654fSVladimir Oltean 1423c83654fSVladimir Oltean static void vcap_cache2action(struct ocelot *ocelot, struct vcap_data *data) 1433c83654fSVladimir Oltean { 1443c83654fSVladimir Oltean const struct vcap_props *vcap_is2 = &ocelot->vcap[VCAP_IS2]; 1453c83654fSVladimir Oltean u32 action_words; 1463c83654fSVladimir Oltean int i, width; 1473c83654fSVladimir Oltean 1483c83654fSVladimir Oltean action_words = DIV_ROUND_UP(vcap_is2->action_width, ENTRY_WIDTH); 1493c83654fSVladimir Oltean 1503c83654fSVladimir Oltean for (i = 0; i < action_words; i++) 1513c83654fSVladimir Oltean data->action[i] = ocelot_read_rix(ocelot, S2_CACHE_ACTION_DAT, 1523c83654fSVladimir Oltean i); 1533c83654fSVladimir Oltean 1543c83654fSVladimir Oltean for (i = 0; i < vcap_is2->counter_words; i++) 1553c83654fSVladimir Oltean data->counter[i] = ocelot_read_rix(ocelot, S2_CACHE_CNT_DAT, i); 1563c83654fSVladimir Oltean 1573c83654fSVladimir Oltean /* Extract action type */ 1583c83654fSVladimir Oltean width = vcap_is2->action_type_width; 1593c83654fSVladimir Oltean data->type = (width ? (data->action[0] & GENMASK(width, 0)) : 0); 1603c83654fSVladimir Oltean } 1613c83654fSVladimir Oltean 1623c83654fSVladimir Oltean /* Calculate offsets for entry */ 1633c83654fSVladimir Oltean static void is2_data_get(struct ocelot *ocelot, struct vcap_data *data, int ix) 1643c83654fSVladimir Oltean { 1653c83654fSVladimir Oltean const struct vcap_props *vcap_is2 = &ocelot->vcap[VCAP_IS2]; 1663c83654fSVladimir Oltean int i, col, offset, count, cnt, base; 1673c83654fSVladimir Oltean int width = vcap_is2->tg_width; 1683c83654fSVladimir Oltean 1693c83654fSVladimir Oltean count = (data->tg_sw == VCAP_TG_HALF ? 2 : 4); 1703c83654fSVladimir Oltean col = (ix % 2); 1713c83654fSVladimir Oltean cnt = (vcap_is2->sw_count / count); 1723c83654fSVladimir Oltean base = (vcap_is2->sw_count - col * cnt - cnt); 1733c83654fSVladimir Oltean data->tg_value = 0; 1743c83654fSVladimir Oltean data->tg_mask = 0; 1753c83654fSVladimir Oltean for (i = 0; i < cnt; i++) { 1763c83654fSVladimir Oltean offset = ((base + i) * width); 1773c83654fSVladimir Oltean data->tg_value |= (data->tg_sw << offset); 1783c83654fSVladimir Oltean data->tg_mask |= GENMASK(offset + width - 1, offset); 1793c83654fSVladimir Oltean } 1803c83654fSVladimir Oltean 1813c83654fSVladimir Oltean /* Calculate key/action/counter offsets */ 1823c83654fSVladimir Oltean col = (count - col - 1); 1833c83654fSVladimir Oltean data->key_offset = (base * vcap_is2->entry_width) / vcap_is2->sw_count; 1843c83654fSVladimir Oltean data->counter_offset = (cnt * col * vcap_is2->counter_width); 1853c83654fSVladimir Oltean i = data->type; 1863c83654fSVladimir Oltean width = vcap_is2->action_table[i].width; 1873c83654fSVladimir Oltean cnt = vcap_is2->action_table[i].count; 1883c83654fSVladimir Oltean data->action_offset = 1893c83654fSVladimir Oltean (((cnt * col * width) / count) + vcap_is2->action_type_width); 1903c83654fSVladimir Oltean } 1913c83654fSVladimir Oltean 1923c83654fSVladimir Oltean static void vcap_data_set(u32 *data, u32 offset, u32 len, u32 value) 1933c83654fSVladimir Oltean { 1943c83654fSVladimir Oltean u32 i, v, m; 1953c83654fSVladimir Oltean 1963c83654fSVladimir Oltean for (i = 0; i < len; i++, offset++) { 1973c83654fSVladimir Oltean v = data[offset / ENTRY_WIDTH]; 1983c83654fSVladimir Oltean m = (1 << (offset % ENTRY_WIDTH)); 1993c83654fSVladimir Oltean if (value & (1 << i)) 2003c83654fSVladimir Oltean v |= m; 2013c83654fSVladimir Oltean else 2023c83654fSVladimir Oltean v &= ~m; 2033c83654fSVladimir Oltean data[offset / ENTRY_WIDTH] = v; 2043c83654fSVladimir Oltean } 2053c83654fSVladimir Oltean } 2063c83654fSVladimir Oltean 2073c83654fSVladimir Oltean static u32 vcap_data_get(u32 *data, u32 offset, u32 len) 2083c83654fSVladimir Oltean { 2093c83654fSVladimir Oltean u32 i, v, m, value = 0; 2103c83654fSVladimir Oltean 2113c83654fSVladimir Oltean for (i = 0; i < len; i++, offset++) { 2123c83654fSVladimir Oltean v = data[offset / ENTRY_WIDTH]; 2133c83654fSVladimir Oltean m = (1 << (offset % ENTRY_WIDTH)); 2143c83654fSVladimir Oltean if (v & m) 2153c83654fSVladimir Oltean value |= (1 << i); 2163c83654fSVladimir Oltean } 2173c83654fSVladimir Oltean return value; 2183c83654fSVladimir Oltean } 2193c83654fSVladimir Oltean 2203c83654fSVladimir Oltean static void vcap_key_field_set(struct vcap_data *data, u32 offset, u32 width, 2213c83654fSVladimir Oltean u32 value, u32 mask) 2223c83654fSVladimir Oltean { 2233c83654fSVladimir Oltean vcap_data_set(data->entry, offset + data->key_offset, width, value); 2243c83654fSVladimir Oltean vcap_data_set(data->mask, offset + data->key_offset, width, mask); 2253c83654fSVladimir Oltean } 2263c83654fSVladimir Oltean 2273c83654fSVladimir Oltean static void vcap_key_set(struct ocelot *ocelot, struct vcap_data *data, 2283c83654fSVladimir Oltean enum vcap_is2_half_key_field field, 2293c83654fSVladimir Oltean u32 value, u32 mask) 2303c83654fSVladimir Oltean { 2313c83654fSVladimir Oltean u32 offset = ocelot->vcap_is2_keys[field].offset; 2323c83654fSVladimir Oltean u32 length = ocelot->vcap_is2_keys[field].length; 2333c83654fSVladimir Oltean 2343c83654fSVladimir Oltean vcap_key_field_set(data, offset, length, value, mask); 2353c83654fSVladimir Oltean } 2363c83654fSVladimir Oltean 2373c83654fSVladimir Oltean static void vcap_key_bytes_set(struct ocelot *ocelot, struct vcap_data *data, 2383c83654fSVladimir Oltean enum vcap_is2_half_key_field field, 2393c83654fSVladimir Oltean u8 *val, u8 *msk) 2403c83654fSVladimir Oltean { 2413c83654fSVladimir Oltean u32 offset = ocelot->vcap_is2_keys[field].offset; 2423c83654fSVladimir Oltean u32 count = ocelot->vcap_is2_keys[field].length; 2433c83654fSVladimir Oltean u32 i, j, n = 0, value = 0, mask = 0; 2443c83654fSVladimir Oltean 2453c83654fSVladimir Oltean WARN_ON(count % 8); 2463c83654fSVladimir Oltean 2473c83654fSVladimir Oltean /* Data wider than 32 bits are split up in chunks of maximum 32 bits. 2483c83654fSVladimir Oltean * The 32 LSB of the data are written to the 32 MSB of the TCAM. 2493c83654fSVladimir Oltean */ 2503c83654fSVladimir Oltean offset += count; 2513c83654fSVladimir Oltean count /= 8; 2523c83654fSVladimir Oltean 2533c83654fSVladimir Oltean for (i = 0; i < count; i++) { 2543c83654fSVladimir Oltean j = (count - i - 1); 2553c83654fSVladimir Oltean value += (val[j] << n); 2563c83654fSVladimir Oltean mask += (msk[j] << n); 2573c83654fSVladimir Oltean n += 8; 2583c83654fSVladimir Oltean if (n == ENTRY_WIDTH || (i + 1) == count) { 2593c83654fSVladimir Oltean offset -= n; 2603c83654fSVladimir Oltean vcap_key_field_set(data, offset, n, value, mask); 2613c83654fSVladimir Oltean n = 0; 2623c83654fSVladimir Oltean value = 0; 2633c83654fSVladimir Oltean mask = 0; 2643c83654fSVladimir Oltean } 2653c83654fSVladimir Oltean } 2663c83654fSVladimir Oltean } 2673c83654fSVladimir Oltean 2683c83654fSVladimir Oltean static void vcap_key_l4_port_set(struct ocelot *ocelot, struct vcap_data *data, 2693c83654fSVladimir Oltean enum vcap_is2_half_key_field field, 2703c83654fSVladimir Oltean struct ocelot_vcap_udp_tcp *port) 2713c83654fSVladimir Oltean { 2723c83654fSVladimir Oltean u32 offset = ocelot->vcap_is2_keys[field].offset; 2733c83654fSVladimir Oltean u32 length = ocelot->vcap_is2_keys[field].length; 2743c83654fSVladimir Oltean 2753c83654fSVladimir Oltean WARN_ON(length != 16); 2763c83654fSVladimir Oltean 2773c83654fSVladimir Oltean vcap_key_field_set(data, offset, length, port->value, port->mask); 2783c83654fSVladimir Oltean } 2793c83654fSVladimir Oltean 2803c83654fSVladimir Oltean static void vcap_key_bit_set(struct ocelot *ocelot, struct vcap_data *data, 2813c83654fSVladimir Oltean enum vcap_is2_half_key_field field, 2823c83654fSVladimir Oltean enum ocelot_vcap_bit val) 2833c83654fSVladimir Oltean { 2843c83654fSVladimir Oltean u32 offset = ocelot->vcap_is2_keys[field].offset; 2853c83654fSVladimir Oltean u32 length = ocelot->vcap_is2_keys[field].length; 2863c83654fSVladimir Oltean u32 value = (val == OCELOT_VCAP_BIT_1 ? 1 : 0); 2873c83654fSVladimir Oltean u32 msk = (val == OCELOT_VCAP_BIT_ANY ? 0 : 1); 2883c83654fSVladimir Oltean 2893c83654fSVladimir Oltean WARN_ON(length != 1); 2903c83654fSVladimir Oltean 2913c83654fSVladimir Oltean vcap_key_field_set(data, offset, length, value, msk); 2923c83654fSVladimir Oltean } 2933c83654fSVladimir Oltean 2943c83654fSVladimir Oltean static void vcap_action_set(struct ocelot *ocelot, struct vcap_data *data, 2953c83654fSVladimir Oltean enum vcap_is2_action_field field, u32 value) 2963c83654fSVladimir Oltean { 2973c83654fSVladimir Oltean int offset = ocelot->vcap_is2_actions[field].offset; 2983c83654fSVladimir Oltean int length = ocelot->vcap_is2_actions[field].length; 2993c83654fSVladimir Oltean 3003c83654fSVladimir Oltean vcap_data_set(data->action, offset + data->action_offset, length, 3013c83654fSVladimir Oltean value); 3023c83654fSVladimir Oltean } 3033c83654fSVladimir Oltean 3043c83654fSVladimir Oltean static void is2_action_set(struct ocelot *ocelot, struct vcap_data *data, 305aae4e500SVladimir Oltean struct ocelot_vcap_filter *filter) 3063c83654fSVladimir Oltean { 307aae4e500SVladimir Oltean switch (filter->action) { 308aae4e500SVladimir Oltean case OCELOT_VCAP_ACTION_DROP: 3093c83654fSVladimir Oltean vcap_action_set(ocelot, data, VCAP_IS2_ACT_PORT_MASK, 0); 3103c83654fSVladimir Oltean vcap_action_set(ocelot, data, VCAP_IS2_ACT_MASK_MODE, 1); 3113c83654fSVladimir Oltean vcap_action_set(ocelot, data, VCAP_IS2_ACT_POLICE_ENA, 1); 3123c83654fSVladimir Oltean vcap_action_set(ocelot, data, VCAP_IS2_ACT_POLICE_IDX, 3133c83654fSVladimir Oltean OCELOT_POLICER_DISCARD); 3143c83654fSVladimir Oltean vcap_action_set(ocelot, data, VCAP_IS2_ACT_CPU_QU_NUM, 0); 3153c83654fSVladimir Oltean vcap_action_set(ocelot, data, VCAP_IS2_ACT_CPU_COPY_ENA, 0); 3163c83654fSVladimir Oltean break; 317aae4e500SVladimir Oltean case OCELOT_VCAP_ACTION_TRAP: 3183c83654fSVladimir Oltean vcap_action_set(ocelot, data, VCAP_IS2_ACT_PORT_MASK, 0); 3193c83654fSVladimir Oltean vcap_action_set(ocelot, data, VCAP_IS2_ACT_MASK_MODE, 1); 3203c83654fSVladimir Oltean vcap_action_set(ocelot, data, VCAP_IS2_ACT_POLICE_ENA, 0); 3213c83654fSVladimir Oltean vcap_action_set(ocelot, data, VCAP_IS2_ACT_POLICE_IDX, 0); 3223c83654fSVladimir Oltean vcap_action_set(ocelot, data, VCAP_IS2_ACT_CPU_QU_NUM, 0); 3233c83654fSVladimir Oltean vcap_action_set(ocelot, data, VCAP_IS2_ACT_CPU_COPY_ENA, 1); 3243c83654fSVladimir Oltean break; 325aae4e500SVladimir Oltean case OCELOT_VCAP_ACTION_POLICE: 3263c83654fSVladimir Oltean vcap_action_set(ocelot, data, VCAP_IS2_ACT_PORT_MASK, 0); 3273c83654fSVladimir Oltean vcap_action_set(ocelot, data, VCAP_IS2_ACT_MASK_MODE, 0); 3283c83654fSVladimir Oltean vcap_action_set(ocelot, data, VCAP_IS2_ACT_POLICE_ENA, 1); 3293c83654fSVladimir Oltean vcap_action_set(ocelot, data, VCAP_IS2_ACT_POLICE_IDX, 330aae4e500SVladimir Oltean filter->pol_ix); 3313c83654fSVladimir Oltean vcap_action_set(ocelot, data, VCAP_IS2_ACT_CPU_QU_NUM, 0); 3323c83654fSVladimir Oltean vcap_action_set(ocelot, data, VCAP_IS2_ACT_CPU_COPY_ENA, 0); 3333c83654fSVladimir Oltean break; 3343c83654fSVladimir Oltean } 3353c83654fSVladimir Oltean } 3363c83654fSVladimir Oltean 3373c83654fSVladimir Oltean static void is2_entry_set(struct ocelot *ocelot, int ix, 338aae4e500SVladimir Oltean struct ocelot_vcap_filter *filter) 3393c83654fSVladimir Oltean { 3403c83654fSVladimir Oltean const struct vcap_props *vcap_is2 = &ocelot->vcap[VCAP_IS2]; 341aae4e500SVladimir Oltean struct ocelot_vcap_key_vlan *tag = &filter->vlan; 3423c83654fSVladimir Oltean u32 val, msk, type, type_mask = 0xf, i, count; 3433c83654fSVladimir Oltean struct ocelot_vcap_u64 payload; 3443c83654fSVladimir Oltean struct vcap_data data; 3453c83654fSVladimir Oltean int row = (ix / 2); 3463c83654fSVladimir Oltean 3473c83654fSVladimir Oltean memset(&payload, 0, sizeof(payload)); 3483c83654fSVladimir Oltean memset(&data, 0, sizeof(data)); 3493c83654fSVladimir Oltean 3503c83654fSVladimir Oltean /* Read row */ 3513c83654fSVladimir Oltean vcap_row_cmd(ocelot, row, VCAP_CMD_READ, VCAP_SEL_ALL); 3523c83654fSVladimir Oltean vcap_cache2entry(ocelot, &data); 3533c83654fSVladimir Oltean vcap_cache2action(ocelot, &data); 3543c83654fSVladimir Oltean 3553c83654fSVladimir Oltean data.tg_sw = VCAP_TG_HALF; 3563c83654fSVladimir Oltean is2_data_get(ocelot, &data, ix); 3573c83654fSVladimir Oltean data.tg = (data.tg & ~data.tg_mask); 358aae4e500SVladimir Oltean if (filter->prio != 0) 3593c83654fSVladimir Oltean data.tg |= data.tg_value; 3603c83654fSVladimir Oltean 3613c83654fSVladimir Oltean data.type = IS2_ACTION_TYPE_NORMAL; 3623c83654fSVladimir Oltean 3633c83654fSVladimir Oltean vcap_key_set(ocelot, &data, VCAP_IS2_HK_PAG, 0, 0); 3643c83654fSVladimir Oltean vcap_key_set(ocelot, &data, VCAP_IS2_HK_IGR_PORT_MASK, 0, 365aae4e500SVladimir Oltean ~filter->ingress_port_mask); 3663c83654fSVladimir Oltean vcap_key_bit_set(ocelot, &data, VCAP_IS2_HK_FIRST, OCELOT_VCAP_BIT_1); 3673c83654fSVladimir Oltean vcap_key_bit_set(ocelot, &data, VCAP_IS2_HK_HOST_MATCH, 3683c83654fSVladimir Oltean OCELOT_VCAP_BIT_ANY); 369aae4e500SVladimir Oltean vcap_key_bit_set(ocelot, &data, VCAP_IS2_HK_L2_MC, filter->dmac_mc); 370aae4e500SVladimir Oltean vcap_key_bit_set(ocelot, &data, VCAP_IS2_HK_L2_BC, filter->dmac_bc); 3713c83654fSVladimir Oltean vcap_key_bit_set(ocelot, &data, VCAP_IS2_HK_VLAN_TAGGED, tag->tagged); 3723c83654fSVladimir Oltean vcap_key_set(ocelot, &data, VCAP_IS2_HK_VID, 3733c83654fSVladimir Oltean tag->vid.value, tag->vid.mask); 3743c83654fSVladimir Oltean vcap_key_set(ocelot, &data, VCAP_IS2_HK_PCP, 3753c83654fSVladimir Oltean tag->pcp.value[0], tag->pcp.mask[0]); 3763c83654fSVladimir Oltean vcap_key_bit_set(ocelot, &data, VCAP_IS2_HK_DEI, tag->dei); 3773c83654fSVladimir Oltean 378aae4e500SVladimir Oltean switch (filter->key_type) { 379aae4e500SVladimir Oltean case OCELOT_VCAP_KEY_ETYPE: { 380aae4e500SVladimir Oltean struct ocelot_vcap_key_etype *etype = &filter->key.etype; 3813c83654fSVladimir Oltean 3823c83654fSVladimir Oltean type = IS2_TYPE_ETYPE; 3833c83654fSVladimir Oltean vcap_key_bytes_set(ocelot, &data, VCAP_IS2_HK_L2_DMAC, 3843c83654fSVladimir Oltean etype->dmac.value, etype->dmac.mask); 3853c83654fSVladimir Oltean vcap_key_bytes_set(ocelot, &data, VCAP_IS2_HK_L2_SMAC, 3863c83654fSVladimir Oltean etype->smac.value, etype->smac.mask); 3873c83654fSVladimir Oltean vcap_key_bytes_set(ocelot, &data, VCAP_IS2_HK_MAC_ETYPE_ETYPE, 3883c83654fSVladimir Oltean etype->etype.value, etype->etype.mask); 3893c83654fSVladimir Oltean /* Clear unused bits */ 3903c83654fSVladimir Oltean vcap_key_set(ocelot, &data, VCAP_IS2_HK_MAC_ETYPE_L2_PAYLOAD0, 3913c83654fSVladimir Oltean 0, 0); 3923c83654fSVladimir Oltean vcap_key_set(ocelot, &data, VCAP_IS2_HK_MAC_ETYPE_L2_PAYLOAD1, 3933c83654fSVladimir Oltean 0, 0); 3943c83654fSVladimir Oltean vcap_key_set(ocelot, &data, VCAP_IS2_HK_MAC_ETYPE_L2_PAYLOAD2, 3953c83654fSVladimir Oltean 0, 0); 3963c83654fSVladimir Oltean vcap_key_bytes_set(ocelot, &data, 3973c83654fSVladimir Oltean VCAP_IS2_HK_MAC_ETYPE_L2_PAYLOAD0, 3983c83654fSVladimir Oltean etype->data.value, etype->data.mask); 3993c83654fSVladimir Oltean break; 4003c83654fSVladimir Oltean } 401aae4e500SVladimir Oltean case OCELOT_VCAP_KEY_LLC: { 402aae4e500SVladimir Oltean struct ocelot_vcap_key_llc *llc = &filter->key.llc; 4033c83654fSVladimir Oltean 4043c83654fSVladimir Oltean type = IS2_TYPE_LLC; 4053c83654fSVladimir Oltean vcap_key_bytes_set(ocelot, &data, VCAP_IS2_HK_L2_DMAC, 4063c83654fSVladimir Oltean llc->dmac.value, llc->dmac.mask); 4073c83654fSVladimir Oltean vcap_key_bytes_set(ocelot, &data, VCAP_IS2_HK_L2_SMAC, 4083c83654fSVladimir Oltean llc->smac.value, llc->smac.mask); 4093c83654fSVladimir Oltean for (i = 0; i < 4; i++) { 4103c83654fSVladimir Oltean payload.value[i] = llc->llc.value[i]; 4113c83654fSVladimir Oltean payload.mask[i] = llc->llc.mask[i]; 4123c83654fSVladimir Oltean } 4133c83654fSVladimir Oltean vcap_key_bytes_set(ocelot, &data, VCAP_IS2_HK_MAC_LLC_L2_LLC, 4143c83654fSVladimir Oltean payload.value, payload.mask); 4153c83654fSVladimir Oltean break; 4163c83654fSVladimir Oltean } 417aae4e500SVladimir Oltean case OCELOT_VCAP_KEY_SNAP: { 418aae4e500SVladimir Oltean struct ocelot_vcap_key_snap *snap = &filter->key.snap; 4193c83654fSVladimir Oltean 4203c83654fSVladimir Oltean type = IS2_TYPE_SNAP; 4213c83654fSVladimir Oltean vcap_key_bytes_set(ocelot, &data, VCAP_IS2_HK_L2_DMAC, 4223c83654fSVladimir Oltean snap->dmac.value, snap->dmac.mask); 4233c83654fSVladimir Oltean vcap_key_bytes_set(ocelot, &data, VCAP_IS2_HK_L2_SMAC, 4243c83654fSVladimir Oltean snap->smac.value, snap->smac.mask); 4253c83654fSVladimir Oltean vcap_key_bytes_set(ocelot, &data, VCAP_IS2_HK_MAC_SNAP_L2_SNAP, 426aae4e500SVladimir Oltean filter->key.snap.snap.value, 427aae4e500SVladimir Oltean filter->key.snap.snap.mask); 4283c83654fSVladimir Oltean break; 4293c83654fSVladimir Oltean } 430aae4e500SVladimir Oltean case OCELOT_VCAP_KEY_ARP: { 431aae4e500SVladimir Oltean struct ocelot_vcap_key_arp *arp = &filter->key.arp; 4323c83654fSVladimir Oltean 4333c83654fSVladimir Oltean type = IS2_TYPE_ARP; 4343c83654fSVladimir Oltean vcap_key_bytes_set(ocelot, &data, VCAP_IS2_HK_MAC_ARP_SMAC, 4353c83654fSVladimir Oltean arp->smac.value, arp->smac.mask); 4363c83654fSVladimir Oltean vcap_key_bit_set(ocelot, &data, 4373c83654fSVladimir Oltean VCAP_IS2_HK_MAC_ARP_ADDR_SPACE_OK, 4383c83654fSVladimir Oltean arp->ethernet); 4393c83654fSVladimir Oltean vcap_key_bit_set(ocelot, &data, 4403c83654fSVladimir Oltean VCAP_IS2_HK_MAC_ARP_PROTO_SPACE_OK, 4413c83654fSVladimir Oltean arp->ip); 4423c83654fSVladimir Oltean vcap_key_bit_set(ocelot, &data, 4433c83654fSVladimir Oltean VCAP_IS2_HK_MAC_ARP_LEN_OK, 4443c83654fSVladimir Oltean arp->length); 4453c83654fSVladimir Oltean vcap_key_bit_set(ocelot, &data, 4463c83654fSVladimir Oltean VCAP_IS2_HK_MAC_ARP_TARGET_MATCH, 4473c83654fSVladimir Oltean arp->dmac_match); 4483c83654fSVladimir Oltean vcap_key_bit_set(ocelot, &data, 4493c83654fSVladimir Oltean VCAP_IS2_HK_MAC_ARP_SENDER_MATCH, 4503c83654fSVladimir Oltean arp->smac_match); 4513c83654fSVladimir Oltean vcap_key_bit_set(ocelot, &data, 4523c83654fSVladimir Oltean VCAP_IS2_HK_MAC_ARP_OPCODE_UNKNOWN, 4533c83654fSVladimir Oltean arp->unknown); 4543c83654fSVladimir Oltean 4553c83654fSVladimir Oltean /* OPCODE is inverse, bit 0 is reply flag, bit 1 is RARP flag */ 4563c83654fSVladimir Oltean val = ((arp->req == OCELOT_VCAP_BIT_0 ? 1 : 0) | 4573c83654fSVladimir Oltean (arp->arp == OCELOT_VCAP_BIT_0 ? 2 : 0)); 4583c83654fSVladimir Oltean msk = ((arp->req == OCELOT_VCAP_BIT_ANY ? 0 : 1) | 4593c83654fSVladimir Oltean (arp->arp == OCELOT_VCAP_BIT_ANY ? 0 : 2)); 4603c83654fSVladimir Oltean vcap_key_set(ocelot, &data, VCAP_IS2_HK_MAC_ARP_OPCODE, 4613c83654fSVladimir Oltean val, msk); 4623c83654fSVladimir Oltean vcap_key_bytes_set(ocelot, &data, 4633c83654fSVladimir Oltean VCAP_IS2_HK_MAC_ARP_L3_IP4_DIP, 4643c83654fSVladimir Oltean arp->dip.value.addr, arp->dip.mask.addr); 4653c83654fSVladimir Oltean vcap_key_bytes_set(ocelot, &data, 4663c83654fSVladimir Oltean VCAP_IS2_HK_MAC_ARP_L3_IP4_SIP, 4673c83654fSVladimir Oltean arp->sip.value.addr, arp->sip.mask.addr); 4683c83654fSVladimir Oltean vcap_key_set(ocelot, &data, VCAP_IS2_HK_MAC_ARP_DIP_EQ_SIP, 4693c83654fSVladimir Oltean 0, 0); 4703c83654fSVladimir Oltean break; 4713c83654fSVladimir Oltean } 472aae4e500SVladimir Oltean case OCELOT_VCAP_KEY_IPV4: 473aae4e500SVladimir Oltean case OCELOT_VCAP_KEY_IPV6: { 4743c83654fSVladimir Oltean enum ocelot_vcap_bit sip_eq_dip, sport_eq_dport, seq_zero, tcp; 4753c83654fSVladimir Oltean enum ocelot_vcap_bit ttl, fragment, options, tcp_ack, tcp_urg; 4763c83654fSVladimir Oltean enum ocelot_vcap_bit tcp_fin, tcp_syn, tcp_rst, tcp_psh; 477aae4e500SVladimir Oltean struct ocelot_vcap_key_ipv4 *ipv4 = NULL; 478aae4e500SVladimir Oltean struct ocelot_vcap_key_ipv6 *ipv6 = NULL; 4793c83654fSVladimir Oltean struct ocelot_vcap_udp_tcp *sport, *dport; 4803c83654fSVladimir Oltean struct ocelot_vcap_ipv4 sip, dip; 4813c83654fSVladimir Oltean struct ocelot_vcap_u8 proto, ds; 4823c83654fSVladimir Oltean struct ocelot_vcap_u48 *ip_data; 4833c83654fSVladimir Oltean 484aae4e500SVladimir Oltean if (filter->key_type == OCELOT_VCAP_KEY_IPV4) { 485aae4e500SVladimir Oltean ipv4 = &filter->key.ipv4; 4863c83654fSVladimir Oltean ttl = ipv4->ttl; 4873c83654fSVladimir Oltean fragment = ipv4->fragment; 4883c83654fSVladimir Oltean options = ipv4->options; 4893c83654fSVladimir Oltean proto = ipv4->proto; 4903c83654fSVladimir Oltean ds = ipv4->ds; 4913c83654fSVladimir Oltean ip_data = &ipv4->data; 4923c83654fSVladimir Oltean sip = ipv4->sip; 4933c83654fSVladimir Oltean dip = ipv4->dip; 4943c83654fSVladimir Oltean sport = &ipv4->sport; 4953c83654fSVladimir Oltean dport = &ipv4->dport; 4963c83654fSVladimir Oltean tcp_fin = ipv4->tcp_fin; 4973c83654fSVladimir Oltean tcp_syn = ipv4->tcp_syn; 4983c83654fSVladimir Oltean tcp_rst = ipv4->tcp_rst; 4993c83654fSVladimir Oltean tcp_psh = ipv4->tcp_psh; 5003c83654fSVladimir Oltean tcp_ack = ipv4->tcp_ack; 5013c83654fSVladimir Oltean tcp_urg = ipv4->tcp_urg; 5023c83654fSVladimir Oltean sip_eq_dip = ipv4->sip_eq_dip; 5033c83654fSVladimir Oltean sport_eq_dport = ipv4->sport_eq_dport; 5043c83654fSVladimir Oltean seq_zero = ipv4->seq_zero; 5053c83654fSVladimir Oltean } else { 506aae4e500SVladimir Oltean ipv6 = &filter->key.ipv6; 5073c83654fSVladimir Oltean ttl = ipv6->ttl; 5083c83654fSVladimir Oltean fragment = OCELOT_VCAP_BIT_ANY; 5093c83654fSVladimir Oltean options = OCELOT_VCAP_BIT_ANY; 5103c83654fSVladimir Oltean proto = ipv6->proto; 5113c83654fSVladimir Oltean ds = ipv6->ds; 5123c83654fSVladimir Oltean ip_data = &ipv6->data; 5133c83654fSVladimir Oltean for (i = 0; i < 8; i++) { 5143c83654fSVladimir Oltean val = ipv6->sip.value[i + 8]; 5153c83654fSVladimir Oltean msk = ipv6->sip.mask[i + 8]; 5163c83654fSVladimir Oltean if (i < 4) { 5173c83654fSVladimir Oltean dip.value.addr[i] = val; 5183c83654fSVladimir Oltean dip.mask.addr[i] = msk; 5193c83654fSVladimir Oltean } else { 5203c83654fSVladimir Oltean sip.value.addr[i - 4] = val; 5213c83654fSVladimir Oltean sip.mask.addr[i - 4] = msk; 5223c83654fSVladimir Oltean } 5233c83654fSVladimir Oltean } 5243c83654fSVladimir Oltean sport = &ipv6->sport; 5253c83654fSVladimir Oltean dport = &ipv6->dport; 5263c83654fSVladimir Oltean tcp_fin = ipv6->tcp_fin; 5273c83654fSVladimir Oltean tcp_syn = ipv6->tcp_syn; 5283c83654fSVladimir Oltean tcp_rst = ipv6->tcp_rst; 5293c83654fSVladimir Oltean tcp_psh = ipv6->tcp_psh; 5303c83654fSVladimir Oltean tcp_ack = ipv6->tcp_ack; 5313c83654fSVladimir Oltean tcp_urg = ipv6->tcp_urg; 5323c83654fSVladimir Oltean sip_eq_dip = ipv6->sip_eq_dip; 5333c83654fSVladimir Oltean sport_eq_dport = ipv6->sport_eq_dport; 5343c83654fSVladimir Oltean seq_zero = ipv6->seq_zero; 5353c83654fSVladimir Oltean } 5363c83654fSVladimir Oltean 5373c83654fSVladimir Oltean vcap_key_bit_set(ocelot, &data, VCAP_IS2_HK_IP4, 5383c83654fSVladimir Oltean ipv4 ? OCELOT_VCAP_BIT_1 : OCELOT_VCAP_BIT_0); 5393c83654fSVladimir Oltean vcap_key_bit_set(ocelot, &data, VCAP_IS2_HK_L3_FRAGMENT, 5403c83654fSVladimir Oltean fragment); 5413c83654fSVladimir Oltean vcap_key_set(ocelot, &data, VCAP_IS2_HK_L3_FRAG_OFS_GT0, 0, 0); 5423c83654fSVladimir Oltean vcap_key_bit_set(ocelot, &data, VCAP_IS2_HK_L3_OPTIONS, 5433c83654fSVladimir Oltean options); 5443c83654fSVladimir Oltean vcap_key_bit_set(ocelot, &data, VCAP_IS2_HK_IP4_L3_TTL_GT0, 5453c83654fSVladimir Oltean ttl); 5463c83654fSVladimir Oltean vcap_key_bytes_set(ocelot, &data, VCAP_IS2_HK_L3_TOS, 5473c83654fSVladimir Oltean ds.value, ds.mask); 5483c83654fSVladimir Oltean vcap_key_bytes_set(ocelot, &data, VCAP_IS2_HK_L3_IP4_DIP, 5493c83654fSVladimir Oltean dip.value.addr, dip.mask.addr); 5503c83654fSVladimir Oltean vcap_key_bytes_set(ocelot, &data, VCAP_IS2_HK_L3_IP4_SIP, 5513c83654fSVladimir Oltean sip.value.addr, sip.mask.addr); 5523c83654fSVladimir Oltean vcap_key_bit_set(ocelot, &data, VCAP_IS2_HK_DIP_EQ_SIP, 5533c83654fSVladimir Oltean sip_eq_dip); 5543c83654fSVladimir Oltean val = proto.value[0]; 5553c83654fSVladimir Oltean msk = proto.mask[0]; 5563c83654fSVladimir Oltean type = IS2_TYPE_IP_UDP_TCP; 5573c83654fSVladimir Oltean if (msk == 0xff && (val == 6 || val == 17)) { 5583c83654fSVladimir Oltean /* UDP/TCP protocol match */ 5593c83654fSVladimir Oltean tcp = (val == 6 ? 5603c83654fSVladimir Oltean OCELOT_VCAP_BIT_1 : OCELOT_VCAP_BIT_0); 5613c83654fSVladimir Oltean vcap_key_bit_set(ocelot, &data, VCAP_IS2_HK_TCP, tcp); 5623c83654fSVladimir Oltean vcap_key_l4_port_set(ocelot, &data, 5633c83654fSVladimir Oltean VCAP_IS2_HK_L4_DPORT, dport); 5643c83654fSVladimir Oltean vcap_key_l4_port_set(ocelot, &data, 5653c83654fSVladimir Oltean VCAP_IS2_HK_L4_SPORT, sport); 5663c83654fSVladimir Oltean vcap_key_set(ocelot, &data, VCAP_IS2_HK_L4_RNG, 0, 0); 5673c83654fSVladimir Oltean vcap_key_bit_set(ocelot, &data, 5683c83654fSVladimir Oltean VCAP_IS2_HK_L4_SPORT_EQ_DPORT, 5693c83654fSVladimir Oltean sport_eq_dport); 5703c83654fSVladimir Oltean vcap_key_bit_set(ocelot, &data, 5713c83654fSVladimir Oltean VCAP_IS2_HK_L4_SEQUENCE_EQ0, 5723c83654fSVladimir Oltean seq_zero); 5733c83654fSVladimir Oltean vcap_key_bit_set(ocelot, &data, VCAP_IS2_HK_L4_FIN, 5743c83654fSVladimir Oltean tcp_fin); 5753c83654fSVladimir Oltean vcap_key_bit_set(ocelot, &data, VCAP_IS2_HK_L4_SYN, 5763c83654fSVladimir Oltean tcp_syn); 5773c83654fSVladimir Oltean vcap_key_bit_set(ocelot, &data, VCAP_IS2_HK_L4_RST, 5783c83654fSVladimir Oltean tcp_rst); 5793c83654fSVladimir Oltean vcap_key_bit_set(ocelot, &data, VCAP_IS2_HK_L4_PSH, 5803c83654fSVladimir Oltean tcp_psh); 5813c83654fSVladimir Oltean vcap_key_bit_set(ocelot, &data, VCAP_IS2_HK_L4_ACK, 5823c83654fSVladimir Oltean tcp_ack); 5833c83654fSVladimir Oltean vcap_key_bit_set(ocelot, &data, VCAP_IS2_HK_L4_URG, 5843c83654fSVladimir Oltean tcp_urg); 5853c83654fSVladimir Oltean vcap_key_set(ocelot, &data, VCAP_IS2_HK_L4_1588_DOM, 5863c83654fSVladimir Oltean 0, 0); 5873c83654fSVladimir Oltean vcap_key_set(ocelot, &data, VCAP_IS2_HK_L4_1588_VER, 5883c83654fSVladimir Oltean 0, 0); 5893c83654fSVladimir Oltean } else { 5903c83654fSVladimir Oltean if (msk == 0) { 5913c83654fSVladimir Oltean /* Any IP protocol match */ 5923c83654fSVladimir Oltean type_mask = IS2_TYPE_MASK_IP_ANY; 5933c83654fSVladimir Oltean } else { 5943c83654fSVladimir Oltean /* Non-UDP/TCP protocol match */ 5953c83654fSVladimir Oltean type = IS2_TYPE_IP_OTHER; 5963c83654fSVladimir Oltean for (i = 0; i < 6; i++) { 5973c83654fSVladimir Oltean payload.value[i] = ip_data->value[i]; 5983c83654fSVladimir Oltean payload.mask[i] = ip_data->mask[i]; 5993c83654fSVladimir Oltean } 6003c83654fSVladimir Oltean } 6013c83654fSVladimir Oltean vcap_key_bytes_set(ocelot, &data, 6023c83654fSVladimir Oltean VCAP_IS2_HK_IP4_L3_PROTO, 6033c83654fSVladimir Oltean proto.value, proto.mask); 6043c83654fSVladimir Oltean vcap_key_bytes_set(ocelot, &data, 6053c83654fSVladimir Oltean VCAP_IS2_HK_L3_PAYLOAD, 6063c83654fSVladimir Oltean payload.value, payload.mask); 6073c83654fSVladimir Oltean } 6083c83654fSVladimir Oltean break; 6093c83654fSVladimir Oltean } 610aae4e500SVladimir Oltean case OCELOT_VCAP_KEY_ANY: 6113c83654fSVladimir Oltean default: 6123c83654fSVladimir Oltean type = 0; 6133c83654fSVladimir Oltean type_mask = 0; 6143c83654fSVladimir Oltean count = vcap_is2->entry_width / 2; 6153c83654fSVladimir Oltean /* Iterate over the non-common part of the key and 6163c83654fSVladimir Oltean * clear entry data 6173c83654fSVladimir Oltean */ 6183c83654fSVladimir Oltean for (i = ocelot->vcap_is2_keys[VCAP_IS2_HK_L2_DMAC].offset; 6193c83654fSVladimir Oltean i < count; i += ENTRY_WIDTH) { 6203c83654fSVladimir Oltean vcap_key_field_set(&data, i, min(32u, count - i), 0, 0); 6213c83654fSVladimir Oltean } 6223c83654fSVladimir Oltean break; 6233c83654fSVladimir Oltean } 6243c83654fSVladimir Oltean 6253c83654fSVladimir Oltean vcap_key_set(ocelot, &data, VCAP_IS2_TYPE, type, type_mask); 626aae4e500SVladimir Oltean is2_action_set(ocelot, &data, filter); 6273c83654fSVladimir Oltean vcap_data_set(data.counter, data.counter_offset, 628aae4e500SVladimir Oltean vcap_is2->counter_width, filter->stats.pkts); 6293c83654fSVladimir Oltean 6303c83654fSVladimir Oltean /* Write row */ 6313c83654fSVladimir Oltean vcap_entry2cache(ocelot, &data); 6323c83654fSVladimir Oltean vcap_action2cache(ocelot, &data); 6333c83654fSVladimir Oltean vcap_row_cmd(ocelot, row, VCAP_CMD_WRITE, VCAP_SEL_ALL); 6343c83654fSVladimir Oltean } 6353c83654fSVladimir Oltean 636aae4e500SVladimir Oltean static void is2_entry_get(struct ocelot *ocelot, struct ocelot_vcap_filter *filter, 6373c83654fSVladimir Oltean int ix) 6383c83654fSVladimir Oltean { 6393c83654fSVladimir Oltean const struct vcap_props *vcap_is2 = &ocelot->vcap[VCAP_IS2]; 6403c83654fSVladimir Oltean struct vcap_data data; 6413c83654fSVladimir Oltean int row = (ix / 2); 6423c83654fSVladimir Oltean u32 cnt; 6433c83654fSVladimir Oltean 6443c83654fSVladimir Oltean vcap_row_cmd(ocelot, row, VCAP_CMD_READ, VCAP_SEL_COUNTER); 6453c83654fSVladimir Oltean vcap_cache2action(ocelot, &data); 6463c83654fSVladimir Oltean data.tg_sw = VCAP_TG_HALF; 6473c83654fSVladimir Oltean is2_data_get(ocelot, &data, ix); 6483c83654fSVladimir Oltean cnt = vcap_data_get(data.counter, data.counter_offset, 6493c83654fSVladimir Oltean vcap_is2->counter_width); 6503c83654fSVladimir Oltean 651aae4e500SVladimir Oltean filter->stats.pkts = cnt; 6523c83654fSVladimir Oltean } 6533c83654fSVladimir Oltean 654c73b0ad3SVladimir Oltean static int ocelot_vcap_policer_add(struct ocelot *ocelot, u32 pol_ix, 655c73b0ad3SVladimir Oltean struct ocelot_policer *pol) 656c73b0ad3SVladimir Oltean { 657c73b0ad3SVladimir Oltean struct qos_policer_conf pp = { 0 }; 658c73b0ad3SVladimir Oltean 659c73b0ad3SVladimir Oltean if (!pol) 660c73b0ad3SVladimir Oltean return -EINVAL; 661c73b0ad3SVladimir Oltean 662c73b0ad3SVladimir Oltean pp.mode = MSCC_QOS_RATE_MODE_DATA; 663c73b0ad3SVladimir Oltean pp.pir = pol->rate; 664c73b0ad3SVladimir Oltean pp.pbs = pol->burst; 665c73b0ad3SVladimir Oltean 666c73b0ad3SVladimir Oltean return qos_policer_conf_set(ocelot, 0, pol_ix, &pp); 667c73b0ad3SVladimir Oltean } 668c73b0ad3SVladimir Oltean 669c73b0ad3SVladimir Oltean static void ocelot_vcap_policer_del(struct ocelot *ocelot, 670c73b0ad3SVladimir Oltean struct ocelot_vcap_block *block, 671c73b0ad3SVladimir Oltean u32 pol_ix) 672c73b0ad3SVladimir Oltean { 673c73b0ad3SVladimir Oltean struct ocelot_vcap_filter *filter; 674c73b0ad3SVladimir Oltean struct qos_policer_conf pp = {0}; 675c73b0ad3SVladimir Oltean int index = -1; 676c73b0ad3SVladimir Oltean 677c73b0ad3SVladimir Oltean if (pol_ix < block->pol_lpr) 678c73b0ad3SVladimir Oltean return; 679c73b0ad3SVladimir Oltean 680c73b0ad3SVladimir Oltean list_for_each_entry(filter, &block->rules, list) { 681c73b0ad3SVladimir Oltean index++; 682c73b0ad3SVladimir Oltean if (filter->action == OCELOT_VCAP_ACTION_POLICE && 683c73b0ad3SVladimir Oltean filter->pol_ix < pol_ix) { 684c73b0ad3SVladimir Oltean filter->pol_ix += 1; 685c73b0ad3SVladimir Oltean ocelot_vcap_policer_add(ocelot, filter->pol_ix, 686c73b0ad3SVladimir Oltean &filter->pol); 687c73b0ad3SVladimir Oltean is2_entry_set(ocelot, index, filter); 688c73b0ad3SVladimir Oltean } 689c73b0ad3SVladimir Oltean } 690c73b0ad3SVladimir Oltean 691c73b0ad3SVladimir Oltean pp.mode = MSCC_QOS_RATE_MODE_DISABLED; 692c73b0ad3SVladimir Oltean qos_policer_conf_set(ocelot, 0, pol_ix, &pp); 693c73b0ad3SVladimir Oltean 694c73b0ad3SVladimir Oltean block->pol_lpr++; 695c73b0ad3SVladimir Oltean } 696c73b0ad3SVladimir Oltean 697aae4e500SVladimir Oltean static void ocelot_vcap_filter_add_to_block(struct ocelot *ocelot, 698aae4e500SVladimir Oltean struct ocelot_vcap_block *block, 699aae4e500SVladimir Oltean struct ocelot_vcap_filter *filter) 7003c83654fSVladimir Oltean { 701aae4e500SVladimir Oltean struct ocelot_vcap_filter *tmp; 7023c83654fSVladimir Oltean struct list_head *pos, *n; 7033c83654fSVladimir Oltean 704aae4e500SVladimir Oltean if (filter->action == OCELOT_VCAP_ACTION_POLICE) { 7053c83654fSVladimir Oltean block->pol_lpr--; 706aae4e500SVladimir Oltean filter->pol_ix = block->pol_lpr; 707aae4e500SVladimir Oltean ocelot_vcap_policer_add(ocelot, filter->pol_ix, &filter->pol); 7083c83654fSVladimir Oltean } 7093c83654fSVladimir Oltean 7103c83654fSVladimir Oltean block->count++; 7113c83654fSVladimir Oltean 7123c83654fSVladimir Oltean if (list_empty(&block->rules)) { 713aae4e500SVladimir Oltean list_add(&filter->list, &block->rules); 7143c83654fSVladimir Oltean return; 7153c83654fSVladimir Oltean } 7163c83654fSVladimir Oltean 7173c83654fSVladimir Oltean list_for_each_safe(pos, n, &block->rules) { 718aae4e500SVladimir Oltean tmp = list_entry(pos, struct ocelot_vcap_filter, list); 719aae4e500SVladimir Oltean if (filter->prio < tmp->prio) 7203c83654fSVladimir Oltean break; 7213c83654fSVladimir Oltean } 722aae4e500SVladimir Oltean list_add(&filter->list, pos->prev); 7233c83654fSVladimir Oltean } 7243c83654fSVladimir Oltean 725aae4e500SVladimir Oltean static int ocelot_vcap_block_get_filter_index(struct ocelot_vcap_block *block, 726aae4e500SVladimir Oltean struct ocelot_vcap_filter *filter) 7273c83654fSVladimir Oltean { 728aae4e500SVladimir Oltean struct ocelot_vcap_filter *tmp; 729ed5672d8SXiaoliang Yang int index = 0; 7303c83654fSVladimir Oltean 7313c83654fSVladimir Oltean list_for_each_entry(tmp, &block->rules, list) { 732aae4e500SVladimir Oltean if (filter->id == tmp->id) 7333c83654fSVladimir Oltean return index; 734ed5672d8SXiaoliang Yang index++; 735ed5672d8SXiaoliang Yang } 736ed5672d8SXiaoliang Yang 737ed5672d8SXiaoliang Yang return -ENOENT; 7383c83654fSVladimir Oltean } 7393c83654fSVladimir Oltean 740aae4e500SVladimir Oltean static struct ocelot_vcap_filter* 741aae4e500SVladimir Oltean ocelot_vcap_block_find_filter(struct ocelot_vcap_block *block, 742aae4e500SVladimir Oltean int index) 7433c83654fSVladimir Oltean { 744aae4e500SVladimir Oltean struct ocelot_vcap_filter *tmp; 7453c83654fSVladimir Oltean int i = 0; 7463c83654fSVladimir Oltean 7473c83654fSVladimir Oltean list_for_each_entry(tmp, &block->rules, list) { 7483c83654fSVladimir Oltean if (i == index) 7493c83654fSVladimir Oltean return tmp; 7503c83654fSVladimir Oltean ++i; 7513c83654fSVladimir Oltean } 7523c83654fSVladimir Oltean 7533c83654fSVladimir Oltean return NULL; 7543c83654fSVladimir Oltean } 7553c83654fSVladimir Oltean 7563c83654fSVladimir Oltean /* If @on=false, then SNAP, ARP, IP and OAM frames will not match on keys based 7573c83654fSVladimir Oltean * on destination and source MAC addresses, but only on higher-level protocol 7583c83654fSVladimir Oltean * information. The only frame types to match on keys containing MAC addresses 7593c83654fSVladimir Oltean * in this case are non-SNAP, non-ARP, non-IP and non-OAM frames. 7603c83654fSVladimir Oltean * 7613c83654fSVladimir Oltean * If @on=true, then the above frame types (SNAP, ARP, IP and OAM) will match 7623c83654fSVladimir Oltean * on MAC_ETYPE keys such as destination and source MAC on this ingress port. 7633c83654fSVladimir Oltean * However the setting has the side effect of making these frames not matching 7643c83654fSVladimir Oltean * on any _other_ keys than MAC_ETYPE ones. 7653c83654fSVladimir Oltean */ 7663c83654fSVladimir Oltean static void ocelot_match_all_as_mac_etype(struct ocelot *ocelot, int port, 7673c83654fSVladimir Oltean bool on) 7683c83654fSVladimir Oltean { 7693c83654fSVladimir Oltean u32 val = 0; 7703c83654fSVladimir Oltean 7713c83654fSVladimir Oltean if (on) 7723c83654fSVladimir Oltean val = ANA_PORT_VCAP_S2_CFG_S2_SNAP_DIS(3) | 7733c83654fSVladimir Oltean ANA_PORT_VCAP_S2_CFG_S2_ARP_DIS(3) | 7743c83654fSVladimir Oltean ANA_PORT_VCAP_S2_CFG_S2_IP_TCPUDP_DIS(3) | 7753c83654fSVladimir Oltean ANA_PORT_VCAP_S2_CFG_S2_IP_OTHER_DIS(3) | 7763c83654fSVladimir Oltean ANA_PORT_VCAP_S2_CFG_S2_OAM_DIS(3); 7773c83654fSVladimir Oltean 7783c83654fSVladimir Oltean ocelot_rmw_gix(ocelot, val, 7793c83654fSVladimir Oltean ANA_PORT_VCAP_S2_CFG_S2_SNAP_DIS_M | 7803c83654fSVladimir Oltean ANA_PORT_VCAP_S2_CFG_S2_ARP_DIS_M | 7813c83654fSVladimir Oltean ANA_PORT_VCAP_S2_CFG_S2_IP_TCPUDP_DIS_M | 7823c83654fSVladimir Oltean ANA_PORT_VCAP_S2_CFG_S2_IP_OTHER_DIS_M | 7833c83654fSVladimir Oltean ANA_PORT_VCAP_S2_CFG_S2_OAM_DIS_M, 7843c83654fSVladimir Oltean ANA_PORT_VCAP_S2_CFG, port); 7853c83654fSVladimir Oltean } 7863c83654fSVladimir Oltean 787aae4e500SVladimir Oltean static bool 788aae4e500SVladimir Oltean ocelot_vcap_is_problematic_mac_etype(struct ocelot_vcap_filter *filter) 7893c83654fSVladimir Oltean { 7903c83654fSVladimir Oltean u16 proto, mask; 7913c83654fSVladimir Oltean 792aae4e500SVladimir Oltean if (filter->key_type != OCELOT_VCAP_KEY_ETYPE) 7933c83654fSVladimir Oltean return false; 7943c83654fSVladimir Oltean 795aae4e500SVladimir Oltean proto = ntohs(*(__be16 *)filter->key.etype.etype.value); 796aae4e500SVladimir Oltean mask = ntohs(*(__be16 *)filter->key.etype.etype.mask); 7973c83654fSVladimir Oltean 7983c83654fSVladimir Oltean /* ETH_P_ALL match, so all protocols below are included */ 7993c83654fSVladimir Oltean if (mask == 0) 8003c83654fSVladimir Oltean return true; 8013c83654fSVladimir Oltean if (proto == ETH_P_ARP) 8023c83654fSVladimir Oltean return true; 8033c83654fSVladimir Oltean if (proto == ETH_P_IP) 8043c83654fSVladimir Oltean return true; 8053c83654fSVladimir Oltean if (proto == ETH_P_IPV6) 8063c83654fSVladimir Oltean return true; 8073c83654fSVladimir Oltean 8083c83654fSVladimir Oltean return false; 8093c83654fSVladimir Oltean } 8103c83654fSVladimir Oltean 811aae4e500SVladimir Oltean static bool 812aae4e500SVladimir Oltean ocelot_vcap_is_problematic_non_mac_etype(struct ocelot_vcap_filter *filter) 8133c83654fSVladimir Oltean { 814aae4e500SVladimir Oltean if (filter->key_type == OCELOT_VCAP_KEY_SNAP) 8153c83654fSVladimir Oltean return true; 816aae4e500SVladimir Oltean if (filter->key_type == OCELOT_VCAP_KEY_ARP) 8173c83654fSVladimir Oltean return true; 818aae4e500SVladimir Oltean if (filter->key_type == OCELOT_VCAP_KEY_IPV4) 8193c83654fSVladimir Oltean return true; 820aae4e500SVladimir Oltean if (filter->key_type == OCELOT_VCAP_KEY_IPV6) 8213c83654fSVladimir Oltean return true; 8223c83654fSVladimir Oltean return false; 8233c83654fSVladimir Oltean } 8243c83654fSVladimir Oltean 825aae4e500SVladimir Oltean static bool 826aae4e500SVladimir Oltean ocelot_exclusive_mac_etype_filter_rules(struct ocelot *ocelot, 827aae4e500SVladimir Oltean struct ocelot_vcap_filter *filter) 8283c83654fSVladimir Oltean { 829aae4e500SVladimir Oltean struct ocelot_vcap_block *block = &ocelot->block; 830aae4e500SVladimir Oltean struct ocelot_vcap_filter *tmp; 8313c83654fSVladimir Oltean unsigned long port; 8323c83654fSVladimir Oltean int i; 8333c83654fSVladimir Oltean 834aae4e500SVladimir Oltean if (ocelot_vcap_is_problematic_mac_etype(filter)) { 8353c83654fSVladimir Oltean /* Search for any non-MAC_ETYPE rules on the port */ 8363c83654fSVladimir Oltean for (i = 0; i < block->count; i++) { 837aae4e500SVladimir Oltean tmp = ocelot_vcap_block_find_filter(block, i); 838aae4e500SVladimir Oltean if (tmp->ingress_port_mask & filter->ingress_port_mask && 839aae4e500SVladimir Oltean ocelot_vcap_is_problematic_non_mac_etype(tmp)) 8403c83654fSVladimir Oltean return false; 8413c83654fSVladimir Oltean } 8423c83654fSVladimir Oltean 843aae4e500SVladimir Oltean for_each_set_bit(port, &filter->ingress_port_mask, 8443c83654fSVladimir Oltean ocelot->num_phys_ports) 8453c83654fSVladimir Oltean ocelot_match_all_as_mac_etype(ocelot, port, true); 846aae4e500SVladimir Oltean } else if (ocelot_vcap_is_problematic_non_mac_etype(filter)) { 8473c83654fSVladimir Oltean /* Search for any MAC_ETYPE rules on the port */ 8483c83654fSVladimir Oltean for (i = 0; i < block->count; i++) { 849aae4e500SVladimir Oltean tmp = ocelot_vcap_block_find_filter(block, i); 850aae4e500SVladimir Oltean if (tmp->ingress_port_mask & filter->ingress_port_mask && 851aae4e500SVladimir Oltean ocelot_vcap_is_problematic_mac_etype(tmp)) 8523c83654fSVladimir Oltean return false; 8533c83654fSVladimir Oltean } 8543c83654fSVladimir Oltean 855aae4e500SVladimir Oltean for_each_set_bit(port, &filter->ingress_port_mask, 8563c83654fSVladimir Oltean ocelot->num_phys_ports) 8573c83654fSVladimir Oltean ocelot_match_all_as_mac_etype(ocelot, port, false); 8583c83654fSVladimir Oltean } 8593c83654fSVladimir Oltean 8603c83654fSVladimir Oltean return true; 8613c83654fSVladimir Oltean } 8623c83654fSVladimir Oltean 863aae4e500SVladimir Oltean int ocelot_vcap_filter_add(struct ocelot *ocelot, 864aae4e500SVladimir Oltean struct ocelot_vcap_filter *filter, 8653c83654fSVladimir Oltean struct netlink_ext_ack *extack) 8663c83654fSVladimir Oltean { 867aae4e500SVladimir Oltean struct ocelot_vcap_block *block = &ocelot->block; 8683c83654fSVladimir Oltean int i, index; 8693c83654fSVladimir Oltean 870aae4e500SVladimir Oltean if (!ocelot_exclusive_mac_etype_filter_rules(ocelot, filter)) { 8713c83654fSVladimir Oltean NL_SET_ERR_MSG_MOD(extack, 8723c83654fSVladimir Oltean "Cannot mix MAC_ETYPE with non-MAC_ETYPE rules"); 8733c83654fSVladimir Oltean return -EBUSY; 8743c83654fSVladimir Oltean } 8753c83654fSVladimir Oltean 876aae4e500SVladimir Oltean /* Add filter to the linked list */ 877aae4e500SVladimir Oltean ocelot_vcap_filter_add_to_block(ocelot, block, filter); 8783c83654fSVladimir Oltean 879aae4e500SVladimir Oltean /* Get the index of the inserted filter */ 880aae4e500SVladimir Oltean index = ocelot_vcap_block_get_filter_index(block, filter); 881ed5672d8SXiaoliang Yang if (index < 0) 882ed5672d8SXiaoliang Yang return index; 8833c83654fSVladimir Oltean 884aae4e500SVladimir Oltean /* Move down the rules to make place for the new filter */ 8853c83654fSVladimir Oltean for (i = block->count - 1; i > index; i--) { 886aae4e500SVladimir Oltean struct ocelot_vcap_filter *tmp; 887aae4e500SVladimir Oltean 888aae4e500SVladimir Oltean tmp = ocelot_vcap_block_find_filter(block, i); 889aae4e500SVladimir Oltean is2_entry_set(ocelot, i, tmp); 8903c83654fSVladimir Oltean } 8913c83654fSVladimir Oltean 892aae4e500SVladimir Oltean /* Now insert the new filter */ 893aae4e500SVladimir Oltean is2_entry_set(ocelot, index, filter); 8943c83654fSVladimir Oltean return 0; 8953c83654fSVladimir Oltean } 8963c83654fSVladimir Oltean 897aae4e500SVladimir Oltean static void ocelot_vcap_block_remove_filter(struct ocelot *ocelot, 898aae4e500SVladimir Oltean struct ocelot_vcap_block *block, 899aae4e500SVladimir Oltean struct ocelot_vcap_filter *filter) 9003c83654fSVladimir Oltean { 901aae4e500SVladimir Oltean struct ocelot_vcap_filter *tmp; 9023c83654fSVladimir Oltean struct list_head *pos, *q; 9033c83654fSVladimir Oltean 9043c83654fSVladimir Oltean list_for_each_safe(pos, q, &block->rules) { 905aae4e500SVladimir Oltean tmp = list_entry(pos, struct ocelot_vcap_filter, list); 906aae4e500SVladimir Oltean if (tmp->id == filter->id) { 907aae4e500SVladimir Oltean if (tmp->action == OCELOT_VCAP_ACTION_POLICE) 908c73b0ad3SVladimir Oltean ocelot_vcap_policer_del(ocelot, block, 9093c83654fSVladimir Oltean tmp->pol_ix); 9103c83654fSVladimir Oltean 9113c83654fSVladimir Oltean list_del(pos); 9123c83654fSVladimir Oltean kfree(tmp); 9133c83654fSVladimir Oltean } 9143c83654fSVladimir Oltean } 9153c83654fSVladimir Oltean 9163c83654fSVladimir Oltean block->count--; 9173c83654fSVladimir Oltean } 9183c83654fSVladimir Oltean 919aae4e500SVladimir Oltean int ocelot_vcap_filter_del(struct ocelot *ocelot, 920aae4e500SVladimir Oltean struct ocelot_vcap_filter *filter) 9213c83654fSVladimir Oltean { 922aae4e500SVladimir Oltean struct ocelot_vcap_block *block = &ocelot->block; 923aae4e500SVladimir Oltean struct ocelot_vcap_filter del_filter; 9243c83654fSVladimir Oltean int i, index; 9253c83654fSVladimir Oltean 926aae4e500SVladimir Oltean memset(&del_filter, 0, sizeof(del_filter)); 9273c83654fSVladimir Oltean 928aae4e500SVladimir Oltean /* Gets index of the filter */ 929aae4e500SVladimir Oltean index = ocelot_vcap_block_get_filter_index(block, filter); 930ed5672d8SXiaoliang Yang if (index < 0) 931ed5672d8SXiaoliang Yang return index; 9323c83654fSVladimir Oltean 933aae4e500SVladimir Oltean /* Delete filter */ 934aae4e500SVladimir Oltean ocelot_vcap_block_remove_filter(ocelot, block, filter); 9353c83654fSVladimir Oltean 936aae4e500SVladimir Oltean /* Move up all the blocks over the deleted filter */ 9373c83654fSVladimir Oltean for (i = index; i < block->count; i++) { 938aae4e500SVladimir Oltean struct ocelot_vcap_filter *tmp; 939aae4e500SVladimir Oltean 940aae4e500SVladimir Oltean tmp = ocelot_vcap_block_find_filter(block, i); 941aae4e500SVladimir Oltean is2_entry_set(ocelot, i, tmp); 9423c83654fSVladimir Oltean } 9433c83654fSVladimir Oltean 944aae4e500SVladimir Oltean /* Now delete the last filter, because it is duplicated */ 945aae4e500SVladimir Oltean is2_entry_set(ocelot, block->count, &del_filter); 9463c83654fSVladimir Oltean 9473c83654fSVladimir Oltean return 0; 9483c83654fSVladimir Oltean } 9493c83654fSVladimir Oltean 950aae4e500SVladimir Oltean int ocelot_vcap_filter_stats_update(struct ocelot *ocelot, 951aae4e500SVladimir Oltean struct ocelot_vcap_filter *filter) 9523c83654fSVladimir Oltean { 953aae4e500SVladimir Oltean struct ocelot_vcap_block *block = &ocelot->block; 954aae4e500SVladimir Oltean struct ocelot_vcap_filter *tmp; 9553c83654fSVladimir Oltean int index; 9563c83654fSVladimir Oltean 957aae4e500SVladimir Oltean index = ocelot_vcap_block_get_filter_index(block, filter); 958ed5672d8SXiaoliang Yang if (index < 0) 959ed5672d8SXiaoliang Yang return index; 960ed5672d8SXiaoliang Yang 961aae4e500SVladimir Oltean is2_entry_get(ocelot, filter, index); 9623c83654fSVladimir Oltean 9633c83654fSVladimir Oltean /* After we get the result we need to clear the counters */ 964aae4e500SVladimir Oltean tmp = ocelot_vcap_block_find_filter(block, index); 9653c83654fSVladimir Oltean tmp->stats.pkts = 0; 9663c83654fSVladimir Oltean is2_entry_set(ocelot, index, tmp); 9673c83654fSVladimir Oltean 9683c83654fSVladimir Oltean return 0; 9693c83654fSVladimir Oltean } 9703c83654fSVladimir Oltean 971aae4e500SVladimir Oltean int ocelot_vcap_init(struct ocelot *ocelot) 9723c83654fSVladimir Oltean { 9733c83654fSVladimir Oltean const struct vcap_props *vcap_is2 = &ocelot->vcap[VCAP_IS2]; 974aae4e500SVladimir Oltean struct ocelot_vcap_block *block = &ocelot->block; 9753c83654fSVladimir Oltean struct vcap_data data; 9763c83654fSVladimir Oltean 9773c83654fSVladimir Oltean memset(&data, 0, sizeof(data)); 9783c83654fSVladimir Oltean 9793c83654fSVladimir Oltean vcap_entry2cache(ocelot, &data); 9803c83654fSVladimir Oltean ocelot_write(ocelot, vcap_is2->entry_count, S2_CORE_MV_CFG); 9813c83654fSVladimir Oltean vcap_cmd(ocelot, 0, VCAP_CMD_INITIALIZE, VCAP_SEL_ENTRY); 9823c83654fSVladimir Oltean 9833c83654fSVladimir Oltean vcap_action2cache(ocelot, &data); 9843c83654fSVladimir Oltean ocelot_write(ocelot, vcap_is2->action_count, S2_CORE_MV_CFG); 9853c83654fSVladimir Oltean vcap_cmd(ocelot, 0, VCAP_CMD_INITIALIZE, 9863c83654fSVladimir Oltean VCAP_SEL_ACTION | VCAP_SEL_COUNTER); 9873c83654fSVladimir Oltean 9883c83654fSVladimir Oltean /* Create a policer that will drop the frames for the cpu. 9893c83654fSVladimir Oltean * This policer will be used as action in the acl rules to drop 9903c83654fSVladimir Oltean * frames. 9913c83654fSVladimir Oltean */ 9923c83654fSVladimir Oltean ocelot_write_gix(ocelot, 0x299, ANA_POL_MODE_CFG, 9933c83654fSVladimir Oltean OCELOT_POLICER_DISCARD); 9943c83654fSVladimir Oltean ocelot_write_gix(ocelot, 0x1, ANA_POL_PIR_CFG, 9953c83654fSVladimir Oltean OCELOT_POLICER_DISCARD); 9963c83654fSVladimir Oltean ocelot_write_gix(ocelot, 0x3fffff, ANA_POL_PIR_STATE, 9973c83654fSVladimir Oltean OCELOT_POLICER_DISCARD); 9983c83654fSVladimir Oltean ocelot_write_gix(ocelot, 0x0, ANA_POL_CIR_CFG, 9993c83654fSVladimir Oltean OCELOT_POLICER_DISCARD); 10003c83654fSVladimir Oltean ocelot_write_gix(ocelot, 0x3fffff, ANA_POL_CIR_STATE, 10013c83654fSVladimir Oltean OCELOT_POLICER_DISCARD); 10023c83654fSVladimir Oltean 10033c83654fSVladimir Oltean block->pol_lpr = OCELOT_POLICER_DISCARD - 1; 10043c83654fSVladimir Oltean 1005aae4e500SVladimir Oltean INIT_LIST_HEAD(&ocelot->block.rules); 10063c83654fSVladimir Oltean 10073c83654fSVladimir Oltean return 0; 10083c83654fSVladimir Oltean } 1009