Skip to content

Commit d54b70f

Browse files
Arkadi Sharshevskydavem330
authored andcommitted
mlxsw: spectrum: Add definition for egress rif table
Add definition for egress router interface table. This table describes the final part in the routing pipeline. This table matches the egress interface index (rif index, which is set by the previous stages and determine the out port) and makes the decision of forwarding the packet towards the L2 logic or dropping it. The metadata header is added to represent this internal information. The rif index field is mapped logically to netdevice ifindex. Signed-off-by: Arkadi Sharshevsky <arkadis@mellanox.com> Signed-off-by: Jiri Pirko <jiri@mellanox.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent 230ead0 commit d54b70f

2 files changed

Lines changed: 115 additions & 4 deletions

File tree

‎drivers/net/ethernet/mellanox/mlxsw/spectrum_dpipe.c‎

Lines changed: 113 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,20 +38,129 @@
3838
#include "spectrum.h"
3939
#include "spectrum_dpipe.h"
4040

41-
static struct devlink_dpipe_header *mlxsw_dpipe_headers[] = {};
41+
enum mlxsw_sp_field_metadata_id {
42+
MLXSW_SP_DPIPE_FIELD_METADATA_ERIF_PORT,
43+
MLXSW_SP_DPIPE_FIELD_METADATA_L3_FORWARD,
44+
MLXSW_SP_DPIPE_FIELD_METADATA_L3_DROP,
45+
};
46+
47+
static struct devlink_dpipe_field mlxsw_sp_dpipe_fields_metadata[] = {
48+
{ .name = "erif_port",
49+
.id = MLXSW_SP_DPIPE_FIELD_METADATA_ERIF_PORT,
50+
.bitwidth = 32,
51+
.mapping_type = DEVLINK_DPIPE_FIELD_MAPPING_TYPE_IFINDEX,
52+
},
53+
{ .name = "l3_forward",
54+
.id = MLXSW_SP_DPIPE_FIELD_METADATA_L3_FORWARD,
55+
.bitwidth = 1,
56+
},
57+
{ .name = "l3_drop",
58+
.id = MLXSW_SP_DPIPE_FIELD_METADATA_L3_DROP,
59+
.bitwidth = 1,
60+
},
61+
};
62+
63+
enum mlxsw_sp_dpipe_header_id {
64+
MLXSW_SP_DPIPE_HEADER_METADATA,
65+
};
66+
67+
static struct devlink_dpipe_header mlxsw_sp_dpipe_header_metadata = {
68+
.name = "mlxsw_meta",
69+
.id = MLXSW_SP_DPIPE_HEADER_METADATA,
70+
.fields = mlxsw_sp_dpipe_fields_metadata,
71+
.fields_count = ARRAY_SIZE(mlxsw_sp_dpipe_fields_metadata),
72+
};
73+
74+
static struct devlink_dpipe_header *mlxsw_dpipe_headers[] = {
75+
&mlxsw_sp_dpipe_header_metadata,
76+
};
4277

4378
static struct devlink_dpipe_headers mlxsw_sp_dpipe_headers = {
4479
.headers = mlxsw_dpipe_headers,
4580
.headers_count = ARRAY_SIZE(mlxsw_dpipe_headers),
4681
};
4782

83+
static int mlxsw_sp_dpipe_table_erif_actions_dump(void *priv,
84+
struct sk_buff *skb)
85+
{
86+
struct devlink_dpipe_action action = {0};
87+
int err;
88+
89+
action.type = DEVLINK_DPIPE_ACTION_TYPE_FIELD_MODIFY;
90+
action.header = &mlxsw_sp_dpipe_header_metadata;
91+
action.field_id = MLXSW_SP_DPIPE_FIELD_METADATA_L3_FORWARD;
92+
93+
err = devlink_dpipe_action_put(skb, &action);
94+
if (err)
95+
return err;
96+
97+
action.type = DEVLINK_DPIPE_ACTION_TYPE_FIELD_MODIFY;
98+
action.header = &mlxsw_sp_dpipe_header_metadata;
99+
action.field_id = MLXSW_SP_DPIPE_FIELD_METADATA_L3_DROP;
100+
101+
return devlink_dpipe_action_put(skb, &action);
102+
}
103+
104+
static int mlxsw_sp_dpipe_table_erif_matches_dump(void *priv,
105+
struct sk_buff *skb)
106+
{
107+
struct devlink_dpipe_match match = {0};
108+
109+
match.type = DEVLINK_DPIPE_MATCH_TYPE_FIELD_EXACT;
110+
match.header = &mlxsw_sp_dpipe_header_metadata;
111+
match.field_id = MLXSW_SP_DPIPE_FIELD_METADATA_ERIF_PORT;
112+
113+
return devlink_dpipe_match_put(skb, &match);
114+
}
115+
116+
static struct devlink_dpipe_table_ops mlxsw_sp_erif_ops = {
117+
.matches_dump = mlxsw_sp_dpipe_table_erif_matches_dump,
118+
.actions_dump = mlxsw_sp_dpipe_table_erif_actions_dump,
119+
};
120+
121+
static int mlxsw_sp_dpipe_erif_table_init(struct mlxsw_sp *mlxsw_sp)
122+
{
123+
struct devlink *devlink = priv_to_devlink(mlxsw_sp->core);
124+
u64 table_size;
125+
126+
table_size = MLXSW_CORE_RES_GET(mlxsw_sp->core, MAX_RIFS);
127+
return devlink_dpipe_table_register(devlink,
128+
MLXSW_SP_DPIPE_TABLE_NAME_ERIF,
129+
&mlxsw_sp_erif_ops,
130+
mlxsw_sp, table_size,
131+
false);
132+
}
133+
134+
static void mlxsw_sp_dpipe_erif_table_fini(struct mlxsw_sp *mlxsw_sp)
135+
{
136+
struct devlink *devlink = priv_to_devlink(mlxsw_sp->core);
137+
138+
devlink_dpipe_table_unregister(devlink, MLXSW_SP_DPIPE_TABLE_NAME_ERIF);
139+
}
140+
48141
int mlxsw_sp_dpipe_init(struct mlxsw_sp *mlxsw_sp)
49142
{
50-
return devlink_dpipe_headers_register(priv_to_devlink(mlxsw_sp->core),
51-
&mlxsw_sp_dpipe_headers);
143+
struct devlink *devlink = priv_to_devlink(mlxsw_sp->core);
144+
int err;
145+
146+
err = devlink_dpipe_headers_register(devlink,
147+
&mlxsw_sp_dpipe_headers);
148+
if (err)
149+
return err;
150+
err = mlxsw_sp_dpipe_erif_table_init(mlxsw_sp);
151+
if (err)
152+
goto err_erif_register;
153+
return 0;
154+
155+
err_erif_register:
156+
devlink_dpipe_headers_unregister(priv_to_devlink(mlxsw_sp->core));
157+
return err;
52158
}
53159

54160
void mlxsw_sp_dpipe_fini(struct mlxsw_sp *mlxsw_sp)
55161
{
56-
devlink_dpipe_headers_unregister(priv_to_devlink(mlxsw_sp->core));
162+
struct devlink *devlink = priv_to_devlink(mlxsw_sp->core);
163+
164+
mlxsw_sp_dpipe_erif_table_fini(mlxsw_sp);
165+
devlink_dpipe_headers_unregister(devlink);
57166
}

‎drivers/net/ethernet/mellanox/mlxsw/spectrum_dpipe.h‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,4 +38,6 @@
3838
int mlxsw_sp_dpipe_init(struct mlxsw_sp *mlxsw_sp);
3939
void mlxsw_sp_dpipe_fini(struct mlxsw_sp *mlxsw_sp);
4040

41+
#define MLXSW_SP_DPIPE_TABLE_NAME_ERIF "mlxsw_erif"
42+
4143
#endif /* _MLXSW_PIPELINE_H_*/

0 commit comments

Comments
 (0)