net: dsa: felix: psfp support on vsc9959
Subsystems (4)
v2 cover net: dsa: felix: psfp support on vsc9959
VSC9959 hardware supports Per-Stream Filtering and Policing(PSFP). This patch series add PSFP support on tc flower offload of ocelot driver. Use chain 30000 to distinguish PSFP from VCAP blocks. Add gate and police set to support PSFP in VSC9959 driver.
v1->v2 changes:
- Use tc flower offload of ocelot driver to support PSFP add and delete.
- Add PSFP tables add/del functions in felix_vsc9959.c.
- Use list_for_each_entry to simplify the code.
- Fix PSFP tables add/del issue.
Vladimir Oltean (1):
net: mscc: ocelot: add MAC table write and lookup operations
Xiaoliang Yang (7):
net: mscc: ocelot: export MAC table lookup and write
net: mscc: ocelot: set vcap IS2 chain to goto PSFP chain
net: mscc: ocelot: add gate and police action offload to PSFP
net: dsa: felix: support psfp filter on vsc9959
net: dsa: felix: add stream gate settings for psfp
net: mscc: ocelot: use index to set vcap policer
net: dsa: felix: use vcap policer to set flow meter for psfp
drivers/net/dsa/ocelot/felix.c | 2 + drivers/net/dsa/ocelot/felix.h | 10 + drivers/net/dsa/ocelot/felix_vsc9959.c | 692 ++++++++++++++++++++- drivers/net/ethernet/mscc/ocelot.c | 53 +- drivers/net/ethernet/mscc/ocelot.h | 13 - drivers/net/ethernet/mscc/ocelot_flower.c | 74 ++- drivers/net/ethernet/mscc/ocelot_vcap.c | 103 +-- drivers/net/ethernet/mscc/ocelot_vsc7514.c | 7 + include/soc/mscc/ocelot.h | 39 +- include/soc/mscc/ocelot_ana.h | 10 + include/soc/mscc/ocelot_vcap.h | 1 + 11 files changed, 932 insertions(+), 72 deletions(-)
Signature · 1 line
2.17.1
RFC v2 1/8 net: mscc: ocelot: add MAC table write and lookup operations
From: Vladimir Oltean <[email protected]>
ocelot_mact_write() can be used for directly modifying an FDB entry situated at a given row and column, as opposed to the current ocelot_mact_learn() which calculates the row and column indices automatically (based on a 11-bit hash derived from the {DMAC, VID} key).
ocelot_mact_lookup() can be used to retrieve the row and column at which an FDB entry with the given {DMAC, VID} key is found.
--- drivers/net/ethernet/mscc/ocelot.c | 47 ++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+)
drivers/net/ethernet/mscc/ocelot.c +47 -0
@@ -102,6 +102,53 @@ int ocelot_mact_forget(struct ocelot *ocelot, }EXPORT_SYMBOL (ocelot_mact_forget); +int ocelot_mact_lookup (struct ocelot *ocelot,const unsigned char mac[ETH_ALEN ], +unsigned int vid,int *row,int *col) +{ +int val; + +ocelot_mact_select (ocelot, mac, vid); + +/* Issue a read command with MACACCESS_VALID=1. */ +ocelot_write (ocelot,ANA_TABLES_MACACCESS_VALID | +ANA_TABLES_MACACCESS_MAC_TABLE_CMD (MACACCESS_CMD_READ ), +ANA_TABLES_MACACCESS ); + +if (ocelot_mact_wait_for_completion (ocelot)) +return -ETIMEDOUT ; + +/* Read back the entry flags */ + val =ocelot_read (ocelot,ANA_TABLES_MACACCESS ); +if (!(val &ANA_TABLES_MACACCESS_VALID )) +return -ENOENT ; + +ocelot_field_read (ocelot,ANA_TABLES_MACTINDX_M_INDEX , row); +ocelot_field_read (ocelot,ANA_TABLES_MACTINDX_BUCKET , col); + +return 0 ; +} +EXPORT_SYMBOL (ocelot_mact_lookup); + +/* Like ocelot_mact_learn, except at a specific row and col. */ +void ocelot_mact_write (struct ocelot *ocelot,int port, +const struct ocelot_mact_entry *entry, +int row,int col) +{ +ocelot_mact_select (ocelot, entry->mac, entry->vid); + +ocelot_field_write (ocelot,ANA_TABLES_MACTINDX_M_INDEX , row); +ocelot_field_write (ocelot,ANA_TABLES_MACTINDX_BUCKET , col); + +ocelot_write (ocelot,ANA_TABLES_MACACCESS_VALID | +ANA_TABLES_MACACCESS_ENTRYTYPE (entry->type) | +ANA_TABLES_MACACCESS_DEST_IDX (port) | +ANA_TABLES_MACACCESS_MAC_TABLE_CMD (MACACCESS_CMD_WRITE ), +ANA_TABLES_MACACCESS ); + +ocelot_mact_wait_for_completion (ocelot); +} +EXPORT_SYMBOL (ocelot_mact_write); +static void ocelot_mact_init (struct ocelot *ocelot) {/* Configure the learning mode entries attributes:
Signature · 1 line
2.17.1
Vladimir Oltean
maintainerRe: [RFC v2 net-next 1/8] net: mscc: ocelot: add MAC table write and lookup operations
Quoted 7 lines · Xiaoliang Yang
From: Vladimir Oltean <[email protected]>
ocelot_mact_write()can be used for directly modifying an FDB entry situated at a given row and column, as opposed to the currentocelot_mact_learn()which calculates the row and column indices automatically (based on a 11-bit hash derived from the {DMAC, VID} key).
Quoted 5 lines
ocelot_mact_lookup()can be used to retrieve the row and column at which an FDB entry with the given {DMAC, VID} key is found.Signed-off-by Vladimir Oltean <[email protected]>---
This patch needs your Signed-off-by tag too.
And I think the functions need their prototype defined in a header too, otherwise the compiler will complain that they are unused and that they are non-static but also no previous prototype.
RFC v2 2/8 net: mscc: ocelot: export MAC table lookup and write
In reply to Xiaoliang YangFelix DSA needs to use these operations as well, for its stream identification functions, so export them in preparation of that.
--- drivers/net/ethernet/mscc/ocelot.c | 6 ------ drivers/net/ethernet/mscc/ocelot.h | 13 ------------- include/soc/mscc/ocelot.h | 24 ++++++++++++++++++++++++ 3 files changed, 24 insertions(+), 19 deletions(-)
drivers/net/ethernet/mscc/ocelot.c +0 -6
@@ -14,12 +14,6 @@#define TABLE_UPDATE_SLEEP_US 10#define TABLE_UPDATE_TIMEOUT_US 100000 -struct ocelot_mact_entry { -u8 mac[ETH_ALEN ]; -u16 vid; -enum macaccess_entry_type type; -}; -static inline u32 ocelot_mact_read_macaccess (struct ocelot *ocelot) {return ocelot_read (ocelot,ANA_TABLES_MACACCESS );
drivers/net/ethernet/mscc/ocelot.h +0 -13
@@ -57,19 +57,6 @@ struct ocelot_dump_ctx {int idx; }; -/* MAC table entry types. -* ENTRYTYPE_NORMAL is subject to aging. -* ENTRYTYPE_LOCKED is not subject to aging. -* ENTRYTYPE_MACv4 is not subject to aging. For IPv4 multicast. -* ENTRYTYPE_MACv6 is not subject to aging. For IPv6 multicast. -*/ -enum macaccess_entry_type { -ENTRYTYPE_NORMAL =0 , -ENTRYTYPE_LOCKED , - ENTRYTYPE_MACv4, - ENTRYTYPE_MACv6, -}; -/* A (PGID) port mask structure, encoding the 2^ocelot->num_phys_ports * possibilities of egress port masks for L2 multicast traffic. * For a switch with 9 user ports, there are 512 possible port masks, but the
include/soc/mscc/ocelot.h +24 -0
@@ -695,6 +695,25 @@ struct ocelot_skb_cb {u8 ts_id; }; +/* MAC table entry types. +* ENTRYTYPE_NORMAL is subject to aging. +* ENTRYTYPE_LOCKED is not subject to aging. +* ENTRYTYPE_MACv4 is not subject to aging. For IPv4 multicast. +* ENTRYTYPE_MACv6 is not subject to aging. For IPv6 multicast. +*/ +enum macaccess_entry_type { +ENTRYTYPE_NORMAL =0 , +ENTRYTYPE_LOCKED , + ENTRYTYPE_MACv4, + ENTRYTYPE_MACv6, +}; + +struct ocelot_mact_entry { +u8 mac[ETH_ALEN ]; +u16 vid; +enum macaccess_entry_type type; +}; +#define OCELOT_SKB_CB (skb) \ ((struct ocelot_skb_cb *)((skb)->cb))
@@ -893,6 +912,11 @@ int ocelot_sb_occ_tc_port_bind_get(struct ocelot *ocelot, int port, unsigned int sb_index, u16 tc_index, enum devlink_sb_pool_type pool_type, u32 *p_cur, u32 *p_max); +int ocelot_mact_lookup (struct ocelot *ocelot,const unsigned char mac[ETH_ALEN ], +unsigned int vid,int *row,int *col); +void ocelot_mact_write (struct ocelot *ocelot,int port, +const struct ocelot_mact_entry *entry, +int row,int col);#if IS_ENABLED (CONFIG_BRIDGE_MRP ) int ocelot_mrp_add(struct ocelot *ocelot, int port,
Signature · 1 line
2.17.1
Vladimir Oltean
maintainerRe: [RFC v2 net-next 2/8] net: mscc: ocelot: export MAC table lookup and write
Quoted 6 lines · Xiaoliang Yang
Felix DSA needs to use these operations as well, for its stream identification functions, so export them in preparation of that.
Signed-off-by Vladimir Oltean <[email protected]>Signed-off-by Xiaoliang Yang <[email protected]>---
So maybe reorder the patches, first export struct ocelot_mact_entry and enum macaccess_entry_type, then introduce the ocelot_mact_lookup and ocelot_mact_write functions directly as exported?
Vladimir Oltean
maintainerRe: [RFC v2 net-next 2/8] net: mscc: ocelot: export MAC table lookup and write
In reply to Xiaoliang YangQuoted 6 lines · Xiaoliang Yang
Felix DSA needs to use these operations as well, for its stream identification functions, so export them in preparation of that.
Signed-off-by Vladimir Oltean <[email protected]>Signed-off-by Xiaoliang Yang <[email protected]>---
Also, this patch misses a tag:
From: Vladimir Oltean <[email protected]>
The first sign-off is also the patch author.
RFC v2 3/8 net: mscc: ocelot: set vcap IS2 chain to goto PSFP chain
In reply to Xiaoliang YangSome chips in the ocelot series such as VSC9959 support Per-Stream Filtering and Policing(PSFP), which is processing after VCAP blocks. We set this block on chain 30000 and set vcap IS2 chain to goto PSFP chain if hardware support.
--- drivers/net/ethernet/mscc/ocelot_flower.c | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-)
drivers/net/ethernet/mscc/ocelot_flower.c +14 -3
@@ -20,6 +20,9 @@ (1 * VCAP_BLOCK + (lookup) * VCAP_LOOKUP)#define VCAP_IS2_CHAIN (lookup, pag) \ (2 * VCAP_BLOCK + (lookup) * VCAP_LOOKUP + (pag)) +/* PSFP chain and block ID */ +#define PSFP_BLOCK_ID OCELOT_NUM_VCAP_BLOCKS +#define OCELOT_PSFP_CHAIN (3 * VCAP_BLOCK)static int ocelot_chain_to_block (int chain,bool ingress) {
@@ -46,6 +49,9 @@ static int ocelot_chain_to_block(int chain, bool ingress)if (chain ==VCAP_IS2_CHAIN (lookup, pag))return VCAP_IS2 ; +if (chain ==OCELOT_PSFP_CHAIN ) +return PSFP_BLOCK_ID ; +return -EOPNOTSUPP ; }
@@ -84,7 +90,8 @@ static bool ocelot_is_goto_target_valid(int goto_target, int chain, goto_target ==VCAP_IS1_CHAIN (1 ) || goto_target ==VCAP_IS1_CHAIN (2 ) || goto_target ==VCAP_IS2_CHAIN (0 ,0 ) || - goto_target == VCAP_IS2_CHAIN(1, 0)); + goto_target ==VCAP_IS2_CHAIN (1 ,0 ) || + goto_target == OCELOT_PSFP_CHAIN);if (chain ==VCAP_IS1_CHAIN (0 ))return (goto_target ==VCAP_IS1_CHAIN (1 ));
@@ -111,7 +118,11 @@ static bool ocelot_is_goto_target_valid(int goto_target, int chain,if (chain ==VCAP_IS2_CHAIN (0 , pag))return (goto_target ==VCAP_IS2_CHAIN (1 , pag)); -/* VCAP IS2 lookup 1 cannot jump anywhere */ +/* VCAP IS2 lookup 1 can goto to PSFP block if hardware support */ +for (pag =0 ; pag <VCAP_IS2_NUM_PAG ; pag++) +if (chain ==VCAP_IS2_CHAIN (1 , pag)) +return (goto_target ==OCELOT_PSFP_CHAIN ); +return false; }
@@ -353,7 +364,7 @@ static int ocelot_flower_parse_action(struct ocelot *ocelot, int port,if (filter->goto_target ==-1 ) {if ((filter->block_id ==VCAP_IS2 && filter->lookup ==1 ) || - chain ==0 ) { + chain ==0 || filter->block_id ==PSFP_BLOCK_ID ) { allow_missing_goto_target = true; }else {NL_SET_ERR_MSG_MOD (extack,"Missing GOTO action" );
Signature · 1 line
2.17.1
Vladimir Oltean
maintainerRe: [RFC v2 net-next 3/8] net: mscc: ocelot: set vcap IS2 chain to goto PSFP chain
drivers/net/ethernet/mscc/ocelot_flower.c static int ocelot_flower_parse_action(struct ocelot *ocelot, int port, · line 368
Quoted 7 lines · Xiaoliang Yang
drivers/net/ethernet/mscc/ocelot_flower.c +1
-1@@ -353,7 +364,7 @@ static int ocelot_flower_parse_action(struct ocelot *ocelot, int port,if (filter->goto_target ==-1 ) {if ((filter->block_id ==VCAP_IS2 && filter->lookup ==1 ) || - chain ==0 ) { + chain ==0 || filter->block_id ==PSFP_BLOCK_ID ) { allow_missing_goto_target = true;
I would like to not allow missing "goto" targets for new filter chains.
Due to legacy support we must keep support for VCAP IS2 on chain 0, but ever since we added the ability to offload multiple chains corresponding to multiple hardware blocks, we should really use that precise chain ID, and chain 0 should just goto the first used chain in the pipeline.
Makes sense?
Quoted 5 lines
drivers/net/ethernet/mscc/ocelot_flower.c +0
-0}else {NL_SET_ERR_MSG_MOD (extack,"Missing GOTO action" );Signature · 1 line
2.17.1
RE: [RFC v2 net-next 3/8] net: mscc: ocelot: set vcap IS2 chain to goto PSFP chain
Quoted 11 lines · Vladimir Oltean
drivers/net/ethernet/mscc/ocelot_flower.c static int ocelot_flower_parse_action(struct · line 369
Quoted 8 lines
drivers/net/ethernet/mscc/ocelot_flower.c +1
-1@@ -353,7 +364,7 @@ static int ocelot_flower_parse_action(struct ocelot *ocelot, int port, if (filter->goto_target == -1) { if ((filter->block_id == VCAP_IS2 && filter->lookup == 1) || - chain == 0) { + chain == 0 || filter->block_id == PSFP_BLOCK_ID) { allow_missing_goto_target = true;I would like to not allow missing "goto" targets for new filter chains.
Quoted 7 lines
Due to legacy support we must keep support for VCAP IS2 on chain 0, but ever since we added the ability to offload multiple chains corresponding to multiple hardware blocks, we should really use that precise chain ID, and chain 0 should just goto the first used chain in the pipeline.
Makes sense?
Because the PSFP chain is the last chain now, I allow missing "goto" targets. Once we add a new chain like FRER, I will delete this allow missing "goto" for PSFP block chain.
Thanks,
Xiaoliang
RFC v2 4/8 net: mscc: ocelot: add gate and police action offload to PSFP
In reply to Xiaoliang YangPSFP support gate and police action. This patch add the gate and police action to flower parse action, check chain ID to determine which block to offload. Adding psfp callback functions to add, delete and update gate and police in PSFP table if hardware supports it.
--- drivers/net/ethernet/mscc/ocelot_flower.c | 52 ++++++++++++++++++++++- include/soc/mscc/ocelot.h | 4 ++ include/soc/mscc/ocelot_vcap.h | 1 + 3 files changed, 55 insertions(+), 2 deletions(-)
drivers/net/ethernet/mscc/ocelot_flower.c +50 -2
@@ -220,10 +220,14 @@ static int ocelot_flower_parse_action(struct ocelot *ocelot, int port, filter->type =OCELOT_VCAP_FILTER_OFFLOAD ;break ;case FLOW_ACTION_POLICE : +if (filter->block_id ==PSFP_BLOCK_ID ) { + filter->type =OCELOT_PSFP_FILTER_OFFLOAD ; +break ; + }if (filter->block_id !=VCAP_IS2 || filter->lookup !=0 ) {NL_SET_ERR_MSG_MOD (extack, -"Police action can only be offloaded to VCAP IS2 lookup 0" ); +"Police action can only be offloaded to VCAP IS2 lookup 0 or PSFP" );return -EOPNOTSUPP ; }if (filter->goto_target !=-1 ) {
@@ -356,6 +360,14 @@ static int ocelot_flower_parse_action(struct ocelot *ocelot, int port, filter->action.pcp_a_val = a->vlan.prio; filter->type =OCELOT_VCAP_FILTER_OFFLOAD ;break ; +case FLOW_ACTION_GATE : +if (filter->block_id !=PSFP_BLOCK_ID ) { +NL_SET_ERR_MSG_MOD (extack, +"Gate action can only be offloaded to PSFP chain" ); +return -EOPNOTSUPP ; + } + filter->type =OCELOT_PSFP_FILTER_OFFLOAD ; +break ;default :NL_SET_ERR_MSG_MOD (extack,"Cannot offload action" );return -EOPNOTSUPP ;
@@ -646,6 +658,10 @@ static int ocelot_flower_parse(struct ocelot *ocelot, int port, bool ingress,if (ret)return ret; +/* PSFP filter need to parse key by stream identification function. */ +if (filter->type ==OCELOT_PSFP_FILTER_OFFLOAD ) +return 0 ; +return ocelot_flower_parse_key (ocelot, port, ingress, f, filter); }
@@ -718,6 +734,15 @@ int ocelot_cls_flower_replace(struct ocelot *ocelot, int port,if (filter->type ==OCELOT_VCAP_FILTER_DUMMY )return ocelot_vcap_dummy_filter_add (ocelot, filter); +if (filter->type ==OCELOT_PSFP_FILTER_OFFLOAD ) { +kfree (filter); +if (ocelot->ops->psfp_filter_add) +return ocelot->ops->psfp_filter_add (ocelot, f); + +NL_SET_ERR_MSG_MOD (extack,"PSFP chain is not supported in HW" ); +return -EOPNOTSUPP ; + } +return ocelot_vcap_filter_add (ocelot, filter, f->common.extack); }EXPORT_SYMBOL_GPL (ocelot_cls_flower_replace);
@@ -733,6 +758,13 @@ int ocelot_cls_flower_destroy(struct ocelot *ocelot, int port,if (block_id <0 )return 0 ; +if (block_id ==PSFP_BLOCK_ID ) { +if (ocelot->ops->psfp_filter_del) +return ocelot->ops->psfp_filter_del (ocelot, f); + +return -EOPNOTSUPP ; + } + block = &ocelot->block[block_id]; filter =ocelot_vcap_block_find_filter_by_id (block, f->cookie, true);
@@ -751,12 +783,25 @@ int ocelot_cls_flower_stats(struct ocelot *ocelot, int port, {struct ocelot_vcap_filter *filter;struct ocelot_vcap_block *block; +struct flow_stats stats;int block_id, ret; block_id =ocelot_chain_to_block (f->common.chain_index, ingress);if (block_id <0 )return 0 ; +if (block_id ==PSFP_BLOCK_ID ) { +if (ocelot->ops->psfp_stats_get) { + ret = ocelot->ops->psfp_stats_get (ocelot, f, &stats); +if (ret) +return ret; + + goto stats_update; + } + +return -EOPNOTSUPP ; + } + block = &ocelot->block[block_id]; filter =ocelot_vcap_block_find_filter_by_id (block, f->cookie, true);
@@ -767,7 +812,10 @@ int ocelot_cls_flower_stats(struct ocelot *ocelot, int port,if (ret)return ret; -flow_stats_update (&f->stats,0x0 , filter->stats.pkts,0 ,0x0 , + stats.pkts = filter->stats.pkts; + +stats_update: +flow_stats_update (&f->stats,0x0 , stats.pkts,0 ,0x0 ,FLOW_ACTION_HW_STATS_IMMEDIATE );return 0 ; }
include/soc/mscc/ocelot.h +4 -0
@@ -564,6 +564,10 @@ struct ocelot_ops {u16 (*wm_enc)(u16 value);u16 (*wm_dec)(u16 value);void (*wm_stat)(u32 val,u32 *inuse,u32 *maxuse); +int (*psfp_filter_add)(struct ocelot *ocelot,struct flow_cls_offload *f); +int (*psfp_filter_del)(struct ocelot *ocelot,struct flow_cls_offload *f); +int (*psfp_stats_get)(struct ocelot *ocelot,struct flow_cls_offload *f, +struct flow_stats *stats); };struct ocelot_vcap_block {
include/soc/mscc/ocelot_vcap.h +1 -0
@@ -646,6 +646,7 @@ enum ocelot_vcap_filter_type {OCELOT_VCAP_FILTER_DUMMY ,OCELOT_VCAP_FILTER_PAG ,OCELOT_VCAP_FILTER_OFFLOAD , + OCELOT_PSFP_FILTER_OFFLOAD, }; struct ocelot_vcap_id {
Signature · 1 line
2.17.1
Vladimir Oltean
maintainerRe: [RFC v2 net-next 4/8] net: mscc: ocelot: add gate and police action offload to PSFP
Quoted 5 lines · Xiaoliang Yang
drivers/net/ethernet/mscc/ocelot_flower.c +1
-0@@ -718,6 +734,15 @@ int ocelot_cls_flower_replace(struct ocelot *ocelot, int port,if (filter->type ==OCELOT_VCAP_FILTER_DUMMY )return ocelot_vcap_dummy_filter_add (ocelot, filter); +if (filter->type ==OCELOT_PSFP_FILTER_OFFLOAD ) {
drivers/net/ethernet/mscc/ocelot_flower.c int ocelot_cls_flower_replace(struct ocelot *ocelot, int port, · line 747
Quoted 10 lines
drivers/net/ethernet/mscc/ocelot_flower.c +8
-0+kfree (filter); +if (ocelot->ops->psfp_filter_add) +return ocelot->ops->psfp_filter_add (ocelot, f); + +NL_SET_ERR_MSG_MOD (extack,"PSFP chain is not supported in HW" ); +return -EOPNOTSUPP ; + } +return ocelot_vcap_filter_add (ocelot, filter, f->common.extack); }
Hmm, I don't really like the idea of allocating an ocelot_vcap_filter which we don't need for PSFP filters, just to kfree it later.
Is it that much more complicated to not allocate it at all in the first place, add a bunch of "if" conditions that allocate a VCAP filter only if we are offloading a VCAP chain?
And that means, don't create ocelot_vcap_filter::type == OCELOT_PSFP_FILTER_OFFLOAD, because PSFP filters are not VCAP filters.
RE: [RFC v2 net-next 4/8] net: mscc: ocelot: add gate and police action offload to PSFP
Hi Vladimir,
Quoted 20 lines · Vladimir Oltean
Review int ocelot_cls_flower_replace(struct ocelot *ocelot,
Quoted 1 line
(quoted diff) +0
-0@@ -718,6 +734,15 @@ int ocelot_cls_flower_replace(struct ocelot *ocelot,int port,
drivers/net/ethernet/mscc/ocelot_flower.c int ocelot_cls_flower_replace(struct ocelot *ocelot, int port,
Quoted 9 lines
drivers/net/ethernet/mscc/ocelot_flower.c +6
-0if (filter->type ==OCELOT_VCAP_FILTER_DUMMY )return ocelot_vcap_dummy_filter_add (ocelot, filter); +if (filter->type ==OCELOT_PSFP_FILTER_OFFLOAD ) { +kfree (filter); +if (ocelot->ops->psfp_filter_add) +return ocelot->ops->psfp_filter_add (ocelot, f); + + NL_SET_ERR_MSG_MOD(extack, "PSFP chain is not supported inHW");
drivers/net/ethernet/mscc/ocelot_flower.c int ocelot_cls_flower_replace(struct ocelot *ocelot, int port,
Quoted 4 lines
drivers/net/ethernet/mscc/ocelot_flower.c +3
-0+return -EOPNOTSUPP ; + } +return ocelot_vcap_filter_add (ocelot, filter, f->common.extack); }Hmm, I don't really like the idea of allocating an
ocelot_vcap_filterwhich we don't need for PSFP filters, just to kfree it later.
Quoted 6 lines
Is it that much more complicated to not allocate it at all in the first place, add a bunch of "if" conditions that allocate a VCAP filter only if we are offloading a VCAP chain?
And that means, don't create
ocelot_vcap_filter::type==OCELOT_PSFP_FILTER_OFFLOAD, because PSFP filters are not VCAP filters.
The "vcap filter" variable need to be created and use ocelot_flower_parse() to get the type. If the rule is checked as a OCELOT_VCAP_FILTER_DUMMY, the chain 30000 dummy rule will be added in vcap_dummy_filter. And not offload to PSFP filter function. So I created the "vcap filter" and free it before offload to PSFP filter function.
Thanks,
xiaoliang
RFC v2 5/8 net: dsa: felix: support psfp filter on vsc9959
In reply to Xiaoliang YangVSC9959 supports Per-Stream Filtering and Policing(PSFP) that complies with the IEEE 802.1Qci standard. The stream is identified by Null stream identification(DMAC and VLAN ID) defined in IEEE802.1CB.
For PSFP, four tables need to be set up: stream table, stream filter table, stream gate table, and flow meter table. Identify the stream by parsing the tc flower keys and add it to the stream table. The stream filter table is automatically maintained, and its index is determined by SGID(flow gate index) and FMID(flow meter index).
--- drivers/net/dsa/ocelot/felix.h | 8 + drivers/net/dsa/ocelot/felix_vsc9959.c | 462 ++++++++++++++++++++++++- include/soc/mscc/ocelot_ana.h | 10 + 3 files changed, 470 insertions(+), 10 deletions(-)
drivers/net/dsa/ocelot/felix.h +8 -0
@@ -6,6 +6,12 @@#define ocelot_to_felix (o) container_of((o), struct felix, ocelot) +struct felix_psfp_list { +struct list_head stream_list; +struct list_head sfi_list; +struct list_head sgi_list; +}; +/* Platform-specific information */ struct felix_info {const struct resource *target_io_res;
@@ -36,6 +42,8 @@ struct felix_info {*/ bool quirk_no_xtr_irq; +struct felix_psfp_list *psfp; +int (*mdio_bus_alloc)(struct ocelot *ocelot);void (*mdio_bus_free)(struct ocelot *ocelot); void (*phylink_validate)(struct ocelot *ocelot, int port,
drivers/net/dsa/ocelot/felix_vsc9959.c +452 -10
498 lines not on this page · raw message
include/soc/mscc/ocelot_ana.h +10 -0
@@ -227,6 +227,11 @@#define ANA_TABLES_SFIDACCESS_SFID_TBL_CMD (x) ((x) & GENMASK(1, 0))#define ANA_TABLES_SFIDACCESS_SFID_TBL_CMD_M GENMASK(1, 0) +#define SFIDACCESS_CMD_IDLE 0 +#define SFIDACCESS_CMD_READ 1 +#define SFIDACCESS_CMD_WRITE 2 +#define SFIDACCESS_CMD_INIT 3 +#define ANA_TABLES_SFIDTIDX_SGID_VALID BIT(26)#define ANA_TABLES_SFIDTIDX_SGID (x) (((x) << 18) & GENMASK(25, 18))#define ANA_TABLES_SFIDTIDX_SGID_M GENMASK(25, 18)
@@ -255,6 +260,11 @@#define ANA_SG_CONFIG_REG_3_INIT_IPS (x) (((x) << 21) & GENMASK(24, 21))#define ANA_SG_CONFIG_REG_3_INIT_IPS_M GENMASK(24, 21)#define ANA_SG_CONFIG_REG_3_INIT_IPS_X (x) (((x) & GENMASK(24, 21)) >> 21) +#define ANA_SG_CONFIG_REG_3_IPV_VALID BIT(24) +#define ANA_SG_CONFIG_REG_3_IPV_INVALID (x) (((x) << 24) & GENMASK(24, 24)) +#define ANA_SG_CONFIG_REG_3_INIT_IPV (x) (((x) << 21) & GENMASK(23, 21)) +#define ANA_SG_CONFIG_REG_3_INIT_IPV_M GENMASK(23, 21) +#define ANA_SG_CONFIG_REG_3_INIT_IPV_X (x) (((x) & GENMASK(23, 21)) >> 21)#define ANA_SG_CONFIG_REG_3_INIT_GATE_STATE BIT(25)#define ANA_SG_GCL_GS_CONFIG_RSZ 0x4
Signature · 1 line
2.17.1
Vladimir Oltean
maintainerRe: [RFC v2 net-next 5/8] net: dsa: felix: support psfp filter on vsc9959
drivers/net/dsa/ocelot/felix.h line 14
Quoted 6 lines · Xiaoliang Yang
drivers/net/dsa/ocelot/felix.h +6
-0+struct felix_psfp_list { +struct list_head stream_list; +struct list_head sfi_list; +struct list_head sgi_list; +}; +
Hmm, is there any reason why this data structure is not part of struct ocelot? Three empty list_head items should not consume that much memory. To reiterate, now we're trying to minimize the stuff that sits in DSA vs what is in the ocelot library itself.
Microchip people, please shout if you have other hardware with this TSN implementation that can be supported by the ocelot driver.
Quoted 16 lines
/* Platform-specific information */
structfelix_info{drivers/net/dsa/ocelot/felix.h +2
-0const struct resource *target_io_res;@@ -36,6 +42,8 @@ struct felix_info {*/ bool quirk_no_xtr_irq; +struct felix_psfp_list *psfp; +int (*mdio_bus_alloc)(struct ocelot *ocelot);void (*mdio_bus_free)(struct ocelot *ocelot); void (*phylink_validate)(struct ocelot *ocelot, int port,drivers/net/dsa/ocelot/felix_vsc9959.c +0
-0
drivers/net/dsa/ocelot/felix_vsc9959.c static int vsc9959_port_setup_tc(struct dsa_switch *ds, int port, · line 1376
Quoted 8 lines
drivers/net/dsa/ocelot/felix_vsc9959.c +8
-0+struct felix_stream_filter_counters { +u32 match; +u32 not_pass_gate; +u32 not_pass_sdu; +u32 red; +}; + +static struct felix_psfp_list vsc9959_psfp;
You cannot just do that, instantiate a singleton structure in a driver that can potentially probe on more than one switch in a system. It is just not proper driver design. Just put the lists
drivers/net/dsa/ocelot/felix_vsc9959.c static int vsc9959_port_setup_tc(struct dsa_switch *ds, int port, · line 1497
Quoted 11 lines
drivers/net/dsa/ocelot/felix_vsc9959.c +11
-0+static bool vsc9959_stream_table_lookup (struct list_head *stream_list, +struct felix_stream *stream) +{ +struct felix_stream *tmp; + +list_for_each_entry (tmp, stream_list, list) +if (ether_addr_equal (tmp->dmac, stream->dmac) && + tmp->vid == stream->vid) +return 1 ; + +return 0 ;
A function that returns bool should return true or false.
drivers/net/dsa/ocelot/felix_vsc9959.c static int vsc9959_port_setup_tc(struct dsa_switch *ds, int port, · line 1510
Quoted 13 lines
drivers/net/dsa/ocelot/felix_vsc9959.c +13
-0+} + +static struct felix_stream * +vsc9959_stream_table_get (struct list_head *stream_list,unsigned long id) +{ +struct felix_stream *tmp; + +list_for_each_entry (tmp, stream_list, list) +if (tmp->id == id) +return tmp; + +return NULL ; +}
I mostly don't have a problem with the rest of the patch. When you send v3 you can just drop the RFC tag.
RFC v2 6/8 net: dsa: felix: add stream gate settings for psfp
In reply to Xiaoliang YangThis patch adds stream gate settings for PSFP. Use SGI table to store stream gate entries. Disable the gate entry when it is not used by any stream.
--- drivers/net/dsa/ocelot/felix_vsc9959.c | 207 ++++++++++++++++++++++++- 1 file changed, 203 insertions(+), 4 deletions(-)
drivers/net/dsa/ocelot/felix_vsc9959.c +203 -4
@@ -8,6 +8,7 @@#include <soc/mscc/ocelot_ana.h> #include <soc/mscc/ocelot_ptp.h> #include <soc/mscc/ocelot_sys.h> +#include <net/tc_act/tc_gate.h> #include <soc/mscc/ocelot.h> #include <linux/dsa/ocelot.h> #include <linux/pcs-lynx.h>
@@ -1341,6 +1342,8 @@ static int vsc9959_port_setup_tc(struct dsa_switch *ds, int port,#define VSC9959_PSFP_SFID_MAX 175#define VSC9959_PSFP_GATE_ID_MAX 183#define VSC9959_PSFP_POLICER_MAX 383 +#define VSC9959_PSFP_GATE_LIST_NUM 4 +#define VSC9959_PSFP_GATE_CYCLETIME_MIN 5000struct felix_stream {struct list_head list;
@@ -1374,6 +1377,24 @@ struct felix_stream_filter_counters {u32 red; }; +struct felix_stream_gate { +u32 index; +u8 enable; +u8 ipv_valid; +u8 init_ipv; +u64 basetime; +u64 cycletime; +u64 cycletime_ext; +u32 num_entries; +struct action_gate_entry entries[0 ]; +}; + +struct felix_stream_gate_entry { +struct list_head list; +refcount_t refcount; +u32 index; +}; +static struct felix_psfp_list vsc9959_psfp; static int vsc9959_stream_identify(struct flow_cls_offload *f,
@@ -1651,6 +1672,154 @@ static void vsc9959_psfp_sfi_table_del(struct ocelot *ocelot, u32 index) } } +static void vsc9959_psfp_parse_gate (const struct flow_action_entry *entry, +struct felix_stream_gate *sgi) +{ + sgi->index = entry->gate.index; + sgi->ipv_valid = (entry->gate.prio <0 ) ?0 :1 ; + sgi->init_ipv = (sgi->ipv_valid) ? entry->gate.prio :0 ; + sgi->basetime = entry->gate.basetime; + sgi->cycletime = entry->gate.cycletime; + sgi->num_entries = entry->gate.num_entries; + sgi->enable =1 ; + +memcpy (sgi->entries, entry->gate.entries, + entry->gate.num_entries *sizeof (struct action_gate_entry )); +} + +static u32 vsc9959_sgi_cfg_status (struct ocelot *ocelot) +{ +return ocelot_read (ocelot,ANA_SG_ACCESS_CTRL ); +} + +static int vsc9959_psfp_sgi_set (struct ocelot *ocelot, +struct felix_stream_gate *sgi) +{ +struct action_gate_entry *e; +struct timespec64 base_ts; +u32 interval_sum =0 ; +u32 val; +int i; + +if (sgi->index >VSC9959_PSFP_GATE_ID_MAX ) +return -EINVAL ; + +ocelot_write (ocelot,ANA_SG_ACCESS_CTRL_SGID (sgi->index), +ANA_SG_ACCESS_CTRL ); + +if (!sgi->enable) { +ocelot_rmw (ocelot,ANA_SG_CONFIG_REG_3_INIT_GATE_STATE , +ANA_SG_CONFIG_REG_3_INIT_GATE_STATE | +ANA_SG_CONFIG_REG_3_GATE_ENABLE , +ANA_SG_CONFIG_REG_3 ); + +return 0 ; + } + +if (sgi->cycletime <VSC9959_PSFP_GATE_CYCLETIME_MIN || + sgi->cycletime >NSEC_PER_SEC ) +return -EINVAL ; + +if (sgi->num_entries >VSC9959_PSFP_GATE_LIST_NUM ) +return -EINVAL ; + +vsc9959_new_base_time (ocelot, sgi->basetime, sgi->cycletime, &base_ts); +ocelot_write (ocelot, base_ts.tv_nsec,ANA_SG_CONFIG_REG_1 ); + val =lower_32_bits (base_ts.tv_sec); +ocelot_write (ocelot, val,ANA_SG_CONFIG_REG_2 ); + + val =upper_32_bits (base_ts.tv_sec); +ocelot_write (ocelot, + (sgi->ipv_valid ?ANA_SG_CONFIG_REG_3_IPV_VALID :0 ) | +ANA_SG_CONFIG_REG_3_INIT_IPV (sgi->init_ipv) | +ANA_SG_CONFIG_REG_3_GATE_ENABLE | +ANA_SG_CONFIG_REG_3_LIST_LENGTH (sgi->num_entries) | +ANA_SG_CONFIG_REG_3_INIT_GATE_STATE | +ANA_SG_CONFIG_REG_3_BASE_TIME_SEC_MSB (val), +ANA_SG_CONFIG_REG_3 ); + +ocelot_write (ocelot, sgi->cycletime,ANA_SG_CONFIG_REG_4 ); + + e = sgi->entries; +for (i =0 ; i < sgi->num_entries; i++) { +u32 ips = (e[i].ipv <0 ) ?0 : (e[i].ipv +8 ); + +ocelot_write_rix (ocelot,ANA_SG_GCL_GS_CONFIG_IPS (ips) | + (e[i].gate_state ? +ANA_SG_GCL_GS_CONFIG_GATE_STATE :0 ), +ANA_SG_GCL_GS_CONFIG , i); + + interval_sum += e[i].interval; +ocelot_write_rix (ocelot, interval_sum,ANA_SG_GCL_TI_CONFIG , i); + } + +ocelot_rmw (ocelot,ANA_SG_ACCESS_CTRL_CONFIG_CHANGE , +ANA_SG_ACCESS_CTRL_CONFIG_CHANGE , +ANA_SG_ACCESS_CTRL ); + +return readx_poll_timeout (vsc9959_sgi_cfg_status, ocelot, val, + (!(ANA_SG_ACCESS_CTRL_CONFIG_CHANGE & val)), +10 ,100000 ); +} + +static int vsc9959_psfp_sgi_table_add (struct ocelot *ocelot, +struct felix_stream_gate *sgi) +{ +struct felix *felix =ocelot_to_felix (ocelot); +struct felix_stream_gate_entry *tmp; +struct felix_psfp_list *psfp; +int ret; + + psfp = felix->info->psfp; + +list_for_each_entry (tmp, &psfp->sgi_list, list) +if (tmp->index == sgi->index) { +refcount_inc (&tmp->refcount); +return 0 ; + } + + tmp =kzalloc (sizeof (*tmp),GFP_KERNEL ); +if (!tmp) +return -ENOMEM ; + + ret =vsc9959_psfp_sgi_set (ocelot, sgi); +if (ret) { +kfree (tmp); +return ret; + } + + tmp->index = sgi->index; +refcount_set (&tmp->refcount,1 ); +list_add_tail (&tmp->list, &psfp->sgi_list); + +return 0 ; +} + +static void vsc9959_psfp_sgi_table_del (struct ocelot *ocelot, +u32 index) +{ +struct felix *felix =ocelot_to_felix (ocelot); +struct felix_stream_gate_entry *tmp, *n; +struct felix_stream_gate sgi = {0 }; +struct felix_psfp_list *psfp; +u8 z; + + psfp = felix->info->psfp; + +list_for_each_entry_safe (tmp, n, &psfp->sgi_list, list) +if (tmp->index == index) { + z =refcount_dec_and_test (&tmp->refcount); +if (z) { + sgi.index = index; + sgi.enable =0 ; +vsc9959_psfp_sgi_set (ocelot, &sgi); +list_del (&tmp->list); +kfree (tmp); + } +break ; + } +} +static void vsc9959_psfp_counters_get (struct ocelot *ocelot,u32 index,struct felix_stream_filter_counters *counters) {
@@ -1672,8 +1841,9 @@ static int vsc9959_psfp_filter_add(struct ocelot *ocelot,struct felix_stream_filter sfi = {0 };const struct flow_action_entry *a;struct felix_stream stream = {0 }; +struct felix_stream_gate *sgi;struct felix_psfp_list *psfp; -int ret, i; +int ret, i, size; psfp = felix->info->psfp;
@@ -1686,6 +1856,18 @@ static int vsc9959_psfp_filter_add(struct ocelot *ocelot,flow_action_for_each (i, a, &f->rule->action) {switch (a->id) {case FLOW_ACTION_GATE : + size =struct_size (sgi, entries, a->gate.num_entries); + sgi =kzalloc (size,GFP_KERNEL ); +vsc9959_psfp_parse_gate (a, sgi); + ret =vsc9959_psfp_sgi_table_add (ocelot, sgi); +if (ret) { +kfree (sgi); +return ret; + } + sfi.sg_valid =1 ; + sfi.sgid = sgi->index; +kfree (sgi); +break ;case FLOW_ACTION_POLICE :default :return -EOPNOTSUPP ;
@@ -1696,7 +1878,8 @@ static int vsc9959_psfp_filter_add(struct ocelot *ocelot, ret =vsc9959_stream_table_lookup (&psfp->stream_list, &stream);if (ret) {NL_SET_ERR_MSG_MOD (extack,"This stream is already added" ); -return -EEXIST ; + ret = -EEXIST ; + goto err; } sfi.prio_valid = (stream.prio <0 ?0 :1 );
@@ -1705,14 +1888,22 @@ static int vsc9959_psfp_filter_add(struct ocelot *ocelot, ret =vsc9959_psfp_sfi_table_add (ocelot, &sfi);if (ret) -return ret; + goto err; stream.sfid = sfi.index; stream.sfid_valid =1 ; ret =vsc9959_stream_table_add (ocelot, &psfp->stream_list, &stream, extack); -if (ret) +if (ret) {vsc9959_psfp_sfi_table_del (ocelot, stream.sfid); + goto err; + } + +return 0 ; + +err: +if (sfi.sg_valid) +vsc9959_psfp_sgi_table_del (ocelot, sfi.sgid);return ret; }
@@ -1721,6 +1912,7 @@ static int vsc9959_psfp_filter_del(struct ocelot *ocelot, struct flow_cls_offload *f) {struct felix *felix =ocelot_to_felix (ocelot); +static struct felix_stream_filter *sfi;struct felix_psfp_list *psfp;struct felix_stream *stream;
@@ -1730,6 +1922,13 @@ static int vsc9959_psfp_filter_del(struct ocelot *ocelot,if (!stream)return -ENOMEM ; + sfi =vsc9959_psfp_sfi_table_get (&psfp->sfi_list, stream->sfid); +if (!sfi) +return -ENOMEM ; + +if (sfi->sg_valid) +vsc9959_psfp_sgi_table_del (ocelot, sfi->sgid); +vsc9959_psfp_sfi_table_del (ocelot, stream->sfid); stream->sfid_valid =0 ;
Signature · 1 line
2.17.1
RFC v2 7/8 net: mscc: ocelot: use index to set vcap policer
In reply to Xiaoliang YangPolicer was previously automatically assigned from the highest index to the lowest index from policer pool. But police action of tc flower now uses index to set an police entry. This patch uses the police index to set vcap policers, so that one policer can be shared by multiple rules.
--- drivers/net/dsa/ocelot/felix.c | 2 + drivers/net/dsa/ocelot/felix.h | 2 + drivers/net/dsa/ocelot/felix_vsc9959.c | 4 + drivers/net/ethernet/mscc/ocelot_flower.c | 5 + drivers/net/ethernet/mscc/ocelot_vcap.c | 103 +++++++++++++-------- drivers/net/ethernet/mscc/ocelot_vsc7514.c | 7 ++ include/soc/mscc/ocelot.h | 11 ++- 7 files changed, 96 insertions(+), 38 deletions(-)
drivers/net/dsa/ocelot/felix.c +2 -0
@@ -1079,6 +1079,8 @@ static int felix_init_structs(struct felix *felix, int num_phys_ports) ocelot->num_stats = felix->info->num_stats; ocelot->num_mact_rows = felix->info->num_mact_rows; ocelot->vcap = felix->info->vcap; + ocelot->vcap_pol.base = felix->info->vcap_pol_base; + ocelot->vcap_pol.max = felix->info->vcap_pol_max; ocelot->ops = felix->info->ops; ocelot->npi_inj_prefix =OCELOT_TAG_PREFIX_SHORT ; ocelot->npi_xtr_prefix =OCELOT_TAG_PREFIX_SHORT ;
drivers/net/dsa/ocelot/felix.h +2 -0
@@ -26,6 +26,8 @@ struct felix_info {int num_ports;int num_tx_queues;struct vcap_props *vcap; +u16 vcap_pol_base; +u16 vcap_pol_max;int switch_pci_bar;int imdio_pci_bar;const struct ptp_clock_info *ptp_caps;
drivers/net/dsa/ocelot/felix_vsc9959.c +4 -0
@@ -19,6 +19,8 @@#include "felix.h" #define VSC9959_TAS_GCL_ENTRY_MAX 63 +#define VSC9959_VCAP_POLICER_BASE 63 +#define VSC9959_VCAP_POLICER_MAX 383static const u32 vsc9959_ana_regmap[] = {REG (ANA_ADVLEARN ,0x0089a0 ),
@@ -1991,6 +1993,8 @@ static const struct felix_info felix_info_vsc9959 = { .stats_layout = vsc9959_stats_layout, .num_stats = ARRAY_SIZE(vsc9959_stats_layout), .vcap = vsc9959_vcap_props, + .vcap_pol_base = VSC9959_VCAP_POLICER_BASE, + .vcap_pol_max = VSC9959_VCAP_POLICER_MAX, .num_mact_rows = 2048, .num_ports = 6, .num_tx_queues = OCELOT_NUM_TC,
drivers/net/ethernet/mscc/ocelot_flower.c +5 -0
@@ -241,6 +241,11 @@ static int ocelot_flower_parse_action(struct ocelot *ocelot, int port,return -EOPNOTSUPP ; } filter->action.police_ena = true; + filter->action.pol_ix = a->police.index + + ocelot->vcap_pol.base; +if (filter->action.pol_ix > ocelot->vcap_pol.max) +return -EINVAL ; + rate = a->police.rate_bytes_ps; filter->action.pol.rate =div_u64 (rate,1000 ) *8 ; filter->action.pol.burst = a->police.burst;
drivers/net/ethernet/mscc/ocelot_vcap.c +66 -37
173 lines not on this page · raw message
drivers/net/ethernet/mscc/ocelot_vsc7514.c +7 -0
@@ -19,6 +19,9 @@#include <soc/mscc/ocelot_hsio.h> #include "ocelot.h" +#define VSC7514_VCAP_POLICER_BASE 128 +#define VSC7514_VCAP_POLICER_MAX 191 +static const u32 ocelot_ana_regmap[] = {REG (ANA_ADVLEARN ,0x009000 ),REG (ANA_VLANMASK ,0x009004 ),
@@ -1181,6 +1184,10 @@ static int mscc_ocelot_probe(struct platform_device *pdev) ocelot->num_flooding_pgids =1 ; ocelot->vcap = vsc7514_vcap_props; + + ocelot->vcap_pol.base =VSC7514_VCAP_POLICER_BASE ; + ocelot->vcap_pol.max =VSC7514_VCAP_POLICER_MAX ; + ocelot->npi =-1 ; err =ocelot_init (ocelot);
include/soc/mscc/ocelot.h +10 -1
@@ -570,10 +570,15 @@ struct ocelot_ops { struct flow_stats *stats); }; +struct ocelot_vcap_policer { +struct list_head pol_list; +u16 base; +u16 max; +}; +struct ocelot_vcap_block {struct list_head rules;int count; -int pol_lpr; };struct ocelot_vlan {
@@ -667,6 +672,7 @@ struct ocelot {struct list_head dummy_rules;struct ocelot_vcap_block block[3 ]; +struct ocelot_vcap_policer vcap_pol;struct vcap_props *vcap;/* Workqueue to check statistics for overflow with its lock */
@@ -921,6 +927,9 @@ int ocelot_mact_lookup(struct ocelot *ocelot, const unsigned char mac[ETH_ALEN],void ocelot_mact_write (struct ocelot *ocelot,int port,const struct ocelot_mact_entry *entry,int row,int col); +int ocelot_vcap_policer_add (struct ocelot *ocelot,u32 pol_ix, +struct ocelot_policer *pol); +int ocelot_vcap_policer_del (struct ocelot *ocelot,u32 pol_ix);#if IS_ENABLED (CONFIG_BRIDGE_MRP ) int ocelot_mrp_add(struct ocelot *ocelot, int port,
Signature · 1 line
2.17.1
RFC v2 8/8 net: dsa: felix: use vcap policer to set flow meter for psfp
In reply to Xiaoliang YangThis patch add police action to set flow meter table which is defined in IEEE802.1Qci. Flow metering is two rates two buckets and three color marker to policing the frames, we only enable one rate one bucket in this patch.
Flow metering shares a same policer pool with VCAP policers, so the PSFP policer calls ocelot_vcap_policer_add() and ocelot_vcap_policer_del() to set flow meter police.
--- drivers/net/dsa/ocelot/felix_vsc9959.c | 32 +++++++++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-)
drivers/net/dsa/ocelot/felix_vsc9959.c +31 -1
@@ -1343,6 +1343,7 @@ static int vsc9959_port_setup_tc(struct dsa_switch *ds, int port,#define VSC9959_PSFP_SFID_MAX 175#define VSC9959_PSFP_GATE_ID_MAX 183 +#define VSC9959_PSFP_POLICER_BASE 63#define VSC9959_PSFP_POLICER_MAX 383#define VSC9959_PSFP_GATE_LIST_NUM 4#define VSC9959_PSFP_GATE_CYCLETIME_MIN 5000
@@ -1845,7 +1846,10 @@ static int vsc9959_psfp_filter_add(struct ocelot *ocelot,struct felix_stream stream = {0 };struct felix_stream_gate *sgi;struct felix_psfp_list *psfp; +struct ocelot_policer pol;int ret, i, size; +u64 rate, burst; +u32 index; psfp = felix->info->psfp;
@@ -1864,13 +1868,33 @@ static int vsc9959_psfp_filter_add(struct ocelot *ocelot, ret =vsc9959_psfp_sgi_table_add (ocelot, sgi);if (ret) {kfree (sgi); -return ret; + goto err; } sfi.sg_valid =1 ; sfi.sgid = sgi->index;kfree (sgi);break ;case FLOW_ACTION_POLICE : + index = a->police.index +VSC9959_PSFP_POLICER_BASE ; +if (index >VSC9959_PSFP_POLICER_MAX ) { + ret = -EINVAL ; + goto err; + } + + rate = a->police.rate_bytes_ps; + burst = rate *PSCHED_NS2TICKS (a->police.burst); + pol = (struct ocelot_policer ) { + .burst =div_u64 (burst,PSCHED_TICKS_PER_SEC ), + .rate =div_u64 (rate,1000 ) *8 , + }; + ret =ocelot_vcap_policer_add (ocelot, index, &pol); +if (ret) + goto err; + + sfi.fm_valid =1 ; + sfi.fmid = index; + sfi.maxsdu = a->police.mtu; +break ;default :return -EOPNOTSUPP ; }
@@ -1907,6 +1931,9 @@ static int vsc9959_psfp_filter_add(struct ocelot *ocelot,if (sfi.sg_valid)vsc9959_psfp_sgi_table_del (ocelot, sfi.sgid); +if (sfi.fm_valid) +ocelot_vcap_policer_del (ocelot, sfi.fmid); +return ret; }
@@ -1931,6 +1958,9 @@ static int vsc9959_psfp_filter_del(struct ocelot *ocelot,if (sfi->sg_valid)vsc9959_psfp_sgi_table_del (ocelot, sfi->sgid); +if (sfi->fm_valid) +ocelot_vcap_policer_del (ocelot, sfi->fmid); +vsc9959_psfp_sfi_table_del (ocelot, stream->sfid); stream->sfid_valid =0 ;
Signature · 1 line
2.17.1