Skip to content

Commit 9f6708a

Browse files
author
Paolo Abeni
committed
Merge tag 'mlx5-updates-2023-08-22' of git://git.kernel.org/pub/scm/linux/kernel/git/saeed/linux
Saeed Mahameed says: ==================== mlx5-updates-2023-08-22 1) Patches #1..#13 From Jiri: The goal of this patchset is to make the SF code cleaner. Benefit from previously introduced devlink_port struct containerization to avoid unnecessary lookups in devlink port ops. Also, benefit from the devlink locking changes and avoid unnecessary reference counting. 2) Patches #14,#15: Add ability to configure proto both UDP and TCP selectors in RX and TX directions. * tag 'mlx5-updates-2023-08-22' of git://git.kernel.org/pub/scm/linux/kernel/git/saeed/linux: net/mlx5e: Support IPsec upper TCP protocol selector net/mlx5e: Support IPsec upper protocol selector field offload for RX net/mlx5: Store vport in struct mlx5_devlink_port and use it in port ops net/mlx5: Check vhca_resource_manager capability in each op and add extack msg net/mlx5: Relax mlx5_devlink_eswitch_get() return value checking net/mlx5: Return -EOPNOTSUPP in mlx5_devlink_port_fn_migratable_set() directly net/mlx5: Reduce number of vport lookups passing vport pointer instead of index net/mlx5: Embed struct devlink_port into driver structure net/mlx5: Don't register ops for non-PF/VF/SF port and avoid checks in ops net/mlx5: Remove no longer used mlx5_esw_offloads_sf_vport_enable/disable() net/mlx5: Introduce mlx5_eswitch_load/unload_sf_vport() and use it from SF code net/mlx5: Allow mlx5_esw_offloads_devlink_port_register() to register SFs net/mlx5: Push devlink port PF/VF init/cleanup calls out of devlink_port_register/unregister() net/mlx5: Push out SF devlink port init and cleanup code to separate helpers net/mlx5: Rework devlink port alloc/free into init/cleanup ==================== Link: https://lore.kernel.org/all/20230823051012.162483-1-saeed@kernel.org/ Signed-off-by: Paolo Abeni <pabeni@redhat.com>
2 parents 23c167a + b8c697e commit 9f6708a

File tree

7 files changed

+371
-303
lines changed

7 files changed

+371
-303
lines changed

drivers/net/ethernet/mellanox/mlx5/core/en_accel/ipsec.c

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -440,9 +440,9 @@ static int mlx5e_xfrm_validate_state(struct mlx5_core_dev *mdev,
440440
return -EINVAL;
441441
}
442442

443-
if (x->sel.proto != IPPROTO_IP &&
444-
(x->sel.proto != IPPROTO_UDP || x->xso.dir != XFRM_DEV_OFFLOAD_OUT)) {
445-
NL_SET_ERR_MSG_MOD(extack, "Device does not support upper protocol other than UDP, and only Tx direction");
443+
if (x->sel.proto != IPPROTO_IP && x->sel.proto != IPPROTO_UDP &&
444+
x->sel.proto != IPPROTO_TCP) {
445+
NL_SET_ERR_MSG_MOD(extack, "Device does not support upper protocol other than TCP/UDP");
446446
return -EINVAL;
447447
}
448448

@@ -983,9 +983,10 @@ static int mlx5e_xfrm_validate_policy(struct mlx5_core_dev *mdev,
983983
return -EINVAL;
984984
}
985985

986-
if (sel->proto != IPPROTO_IP &&
987-
(sel->proto != IPPROTO_UDP || x->xdo.dir != XFRM_DEV_OFFLOAD_OUT)) {
988-
NL_SET_ERR_MSG_MOD(extack, "Device does not support upper protocol other than UDP, and only Tx direction");
986+
if (x->selector.proto != IPPROTO_IP &&
987+
x->selector.proto != IPPROTO_UDP &&
988+
x->selector.proto != IPPROTO_TCP) {
989+
NL_SET_ERR_MSG_MOD(extack, "Device does not support upper protocol other than TCP/UDP");
989990
return -EINVAL;
990991
}
991992

drivers/net/ethernet/mellanox/mlx5/core/en_accel/ipsec_fs.c

Lines changed: 33 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -936,23 +936,42 @@ static void setup_fte_reg_c4(struct mlx5_flow_spec *spec, u32 reqid)
936936

937937
static void setup_fte_upper_proto_match(struct mlx5_flow_spec *spec, struct upspec *upspec)
938938
{
939-
if (upspec->proto != IPPROTO_UDP)
939+
switch (upspec->proto) {
940+
case IPPROTO_UDP:
941+
if (upspec->dport) {
942+
MLX5_SET(fte_match_set_lyr_2_4, spec->match_criteria,
943+
udp_dport, upspec->dport_mask);
944+
MLX5_SET(fte_match_set_lyr_2_4, spec->match_value,
945+
udp_dport, upspec->dport);
946+
}
947+
if (upspec->sport) {
948+
MLX5_SET(fte_match_set_lyr_2_4, spec->match_criteria,
949+
udp_sport, upspec->sport_mask);
950+
MLX5_SET(fte_match_set_lyr_2_4, spec->match_value,
951+
udp_sport, upspec->sport);
952+
}
953+
break;
954+
case IPPROTO_TCP:
955+
if (upspec->dport) {
956+
MLX5_SET(fte_match_set_lyr_2_4, spec->match_criteria,
957+
tcp_dport, upspec->dport_mask);
958+
MLX5_SET(fte_match_set_lyr_2_4, spec->match_value,
959+
tcp_dport, upspec->dport);
960+
}
961+
if (upspec->sport) {
962+
MLX5_SET(fte_match_set_lyr_2_4, spec->match_criteria,
963+
tcp_sport, upspec->sport_mask);
964+
MLX5_SET(fte_match_set_lyr_2_4, spec->match_value,
965+
tcp_sport, upspec->sport);
966+
}
967+
break;
968+
default:
940969
return;
970+
}
941971

942972
spec->match_criteria_enable |= MLX5_MATCH_OUTER_HEADERS;
943973
MLX5_SET_TO_ONES(fte_match_set_lyr_2_4, spec->match_criteria, ip_protocol);
944974
MLX5_SET(fte_match_set_lyr_2_4, spec->match_value, ip_protocol, upspec->proto);
945-
if (upspec->dport) {
946-
MLX5_SET(fte_match_set_lyr_2_4, spec->match_criteria, udp_dport,
947-
upspec->dport_mask);
948-
MLX5_SET(fte_match_set_lyr_2_4, spec->match_value, udp_dport, upspec->dport);
949-
}
950-
951-
if (upspec->sport) {
952-
MLX5_SET(fte_match_set_lyr_2_4, spec->match_criteria, udp_sport,
953-
upspec->sport_mask);
954-
MLX5_SET(fte_match_set_lyr_2_4, spec->match_value, udp_sport, upspec->sport);
955-
}
956975
}
957976

958977
static enum mlx5_flow_namespace_type ipsec_fs_get_ns(struct mlx5e_ipsec *ipsec,
@@ -1243,6 +1262,7 @@ static int rx_add_rule(struct mlx5e_ipsec_sa_entry *sa_entry)
12431262
setup_fte_spi(spec, attrs->spi);
12441263
setup_fte_esp(spec);
12451264
setup_fte_no_frags(spec);
1265+
setup_fte_upper_proto_match(spec, &attrs->upspec);
12461266

12471267
if (rx != ipsec->rx_esw)
12481268
err = setup_modify_header(ipsec, attrs->type,
@@ -1519,6 +1539,7 @@ static int rx_add_policy(struct mlx5e_ipsec_pol_entry *pol_entry)
15191539
setup_fte_addr6(spec, attrs->saddr.a6, attrs->daddr.a6);
15201540

15211541
setup_fte_no_frags(spec);
1542+
setup_fte_upper_proto_match(spec, &attrs->upspec);
15221543

15231544
switch (attrs->action) {
15241545
case XFRM_POLICY_ALLOW:

drivers/net/ethernet/mellanox/mlx5/core/esw/devlink_port.c

Lines changed: 80 additions & 89 deletions
Original file line numberDiff line numberDiff line change
@@ -21,19 +21,16 @@ static bool mlx5_esw_devlink_port_supported(struct mlx5_eswitch *esw, u16 vport_
2121
mlx5_core_is_ec_vf_vport(esw->dev, vport_num);
2222
}
2323

24-
static struct devlink_port *mlx5_esw_dl_port_alloc(struct mlx5_eswitch *esw, u16 vport_num)
24+
static void mlx5_esw_offloads_pf_vf_devlink_port_attrs_set(struct mlx5_eswitch *esw,
25+
u16 vport_num,
26+
struct devlink_port *dl_port)
2527
{
2628
struct mlx5_core_dev *dev = esw->dev;
2729
struct netdev_phys_item_id ppid = {};
28-
struct devlink_port *dl_port;
2930
u32 controller_num = 0;
3031
bool external;
3132
u16 pfnum;
3233

33-
dl_port = kzalloc(sizeof(*dl_port), GFP_KERNEL);
34-
if (!dl_port)
35-
return NULL;
36-
3734
mlx5_esw_get_port_parent_id(dev, &ppid);
3835
pfnum = mlx5_get_dev_index(dev);
3936
external = mlx5_core_is_ecpf_esw_manager(dev);
@@ -55,12 +52,37 @@ static struct devlink_port *mlx5_esw_dl_port_alloc(struct mlx5_eswitch *esw, u16
5552
devlink_port_attrs_pci_vf_set(dl_port, 0, pfnum,
5653
vport_num - 1, false);
5754
}
58-
return dl_port;
5955
}
6056

61-
static void mlx5_esw_dl_port_free(struct devlink_port *dl_port)
57+
int mlx5_esw_offloads_pf_vf_devlink_port_init(struct mlx5_eswitch *esw,
58+
struct mlx5_vport *vport)
6259
{
63-
kfree(dl_port);
60+
struct mlx5_devlink_port *dl_port;
61+
u16 vport_num = vport->vport;
62+
63+
if (!mlx5_esw_devlink_port_supported(esw, vport_num))
64+
return 0;
65+
66+
dl_port = kzalloc(sizeof(*dl_port), GFP_KERNEL);
67+
if (!dl_port)
68+
return -ENOMEM;
69+
70+
mlx5_esw_offloads_pf_vf_devlink_port_attrs_set(esw, vport_num,
71+
&dl_port->dl_port);
72+
73+
vport->dl_port = dl_port;
74+
mlx5_devlink_port_init(dl_port, vport);
75+
return 0;
76+
}
77+
78+
void mlx5_esw_offloads_pf_vf_devlink_port_cleanup(struct mlx5_eswitch *esw,
79+
struct mlx5_vport *vport)
80+
{
81+
if (!vport->dl_port)
82+
return;
83+
84+
kfree(vport->dl_port);
85+
vport->dl_port = NULL;
6486
}
6587

6688
static const struct devlink_port_ops mlx5_esw_pf_vf_dl_port_ops = {
@@ -72,74 +94,37 @@ static const struct devlink_port_ops mlx5_esw_pf_vf_dl_port_ops = {
7294
.port_fn_migratable_set = mlx5_devlink_port_fn_migratable_set,
7395
};
7496

75-
int mlx5_esw_offloads_devlink_port_register(struct mlx5_eswitch *esw, u16 vport_num)
97+
static void mlx5_esw_offloads_sf_devlink_port_attrs_set(struct mlx5_eswitch *esw,
98+
struct devlink_port *dl_port,
99+
u32 controller, u32 sfnum)
76100
{
77101
struct mlx5_core_dev *dev = esw->dev;
78-
struct devlink_port *dl_port;
79-
unsigned int dl_port_index;
80-
struct mlx5_vport *vport;
81-
struct devlink *devlink;
82-
int err;
83-
84-
if (!mlx5_esw_devlink_port_supported(esw, vport_num))
85-
return 0;
86-
87-
vport = mlx5_eswitch_get_vport(esw, vport_num);
88-
if (IS_ERR(vport))
89-
return PTR_ERR(vport);
90-
91-
dl_port = mlx5_esw_dl_port_alloc(esw, vport_num);
92-
if (!dl_port)
93-
return -ENOMEM;
102+
struct netdev_phys_item_id ppid = {};
103+
u16 pfnum;
94104

95-
devlink = priv_to_devlink(dev);
96-
dl_port_index = mlx5_esw_vport_to_devlink_port_index(dev, vport_num);
97-
err = devl_port_register_with_ops(devlink, dl_port, dl_port_index,
98-
&mlx5_esw_pf_vf_dl_port_ops);
99-
if (err)
100-
goto reg_err;
105+
pfnum = mlx5_get_dev_index(dev);
106+
mlx5_esw_get_port_parent_id(dev, &ppid);
107+
memcpy(dl_port->attrs.switch_id.id, &ppid.id[0], ppid.id_len);
108+
dl_port->attrs.switch_id.id_len = ppid.id_len;
109+
devlink_port_attrs_pci_sf_set(dl_port, controller, pfnum, sfnum, !!controller);
110+
}
101111

102-
err = devl_rate_leaf_create(dl_port, vport, NULL);
103-
if (err)
104-
goto rate_err;
112+
int mlx5_esw_offloads_sf_devlink_port_init(struct mlx5_eswitch *esw, struct mlx5_vport *vport,
113+
struct mlx5_devlink_port *dl_port,
114+
u32 controller, u32 sfnum)
115+
{
116+
mlx5_esw_offloads_sf_devlink_port_attrs_set(esw, &dl_port->dl_port, controller, sfnum);
105117

106118
vport->dl_port = dl_port;
119+
mlx5_devlink_port_init(dl_port, vport);
107120
return 0;
108-
109-
rate_err:
110-
devl_port_unregister(dl_port);
111-
reg_err:
112-
mlx5_esw_dl_port_free(dl_port);
113-
return err;
114121
}
115122

116-
void mlx5_esw_offloads_devlink_port_unregister(struct mlx5_eswitch *esw, u16 vport_num)
123+
void mlx5_esw_offloads_sf_devlink_port_cleanup(struct mlx5_eswitch *esw, struct mlx5_vport *vport)
117124
{
118-
struct mlx5_vport *vport;
119-
120-
if (!mlx5_esw_devlink_port_supported(esw, vport_num))
121-
return;
122-
123-
vport = mlx5_eswitch_get_vport(esw, vport_num);
124-
if (IS_ERR(vport))
125-
return;
126-
127-
mlx5_esw_qos_vport_update_group(esw, vport, NULL, NULL);
128-
devl_rate_leaf_destroy(vport->dl_port);
129-
130-
devl_port_unregister(vport->dl_port);
131-
mlx5_esw_dl_port_free(vport->dl_port);
132125
vport->dl_port = NULL;
133126
}
134127

135-
struct devlink_port *mlx5_esw_offloads_devlink_port(struct mlx5_eswitch *esw, u16 vport_num)
136-
{
137-
struct mlx5_vport *vport;
138-
139-
vport = mlx5_eswitch_get_vport(esw, vport_num);
140-
return IS_ERR(vport) ? ERR_CAST(vport) : vport->dl_port;
141-
}
142-
143128
static const struct devlink_port_ops mlx5_esw_dl_sf_port_ops = {
144129
#ifdef CONFIG_MLX5_SF_MANAGER
145130
.port_del = mlx5_devlink_sf_port_del,
@@ -154,56 +139,62 @@ static const struct devlink_port_ops mlx5_esw_dl_sf_port_ops = {
154139
#endif
155140
};
156141

157-
int mlx5_esw_devlink_sf_port_register(struct mlx5_eswitch *esw, struct devlink_port *dl_port,
158-
u16 vport_num, u32 controller, u32 sfnum)
142+
int mlx5_esw_offloads_devlink_port_register(struct mlx5_eswitch *esw, struct mlx5_vport *vport)
159143
{
160144
struct mlx5_core_dev *dev = esw->dev;
161-
struct netdev_phys_item_id ppid = {};
145+
const struct devlink_port_ops *ops;
146+
struct mlx5_devlink_port *dl_port;
147+
u16 vport_num = vport->vport;
162148
unsigned int dl_port_index;
163-
struct mlx5_vport *vport;
164149
struct devlink *devlink;
165-
u16 pfnum;
166150
int err;
167151

168-
vport = mlx5_eswitch_get_vport(esw, vport_num);
169-
if (IS_ERR(vport))
170-
return PTR_ERR(vport);
152+
dl_port = vport->dl_port;
153+
if (!dl_port)
154+
return 0;
155+
156+
if (mlx5_esw_is_sf_vport(esw, vport_num))
157+
ops = &mlx5_esw_dl_sf_port_ops;
158+
else if (mlx5_eswitch_is_pf_vf_vport(esw, vport_num))
159+
ops = &mlx5_esw_pf_vf_dl_port_ops;
160+
else
161+
ops = NULL;
171162

172-
pfnum = mlx5_get_dev_index(dev);
173-
mlx5_esw_get_port_parent_id(dev, &ppid);
174-
memcpy(dl_port->attrs.switch_id.id, &ppid.id[0], ppid.id_len);
175-
dl_port->attrs.switch_id.id_len = ppid.id_len;
176-
devlink_port_attrs_pci_sf_set(dl_port, controller, pfnum, sfnum, !!controller);
177163
devlink = priv_to_devlink(dev);
178164
dl_port_index = mlx5_esw_vport_to_devlink_port_index(dev, vport_num);
179-
err = devl_port_register_with_ops(devlink, dl_port, dl_port_index,
180-
&mlx5_esw_dl_sf_port_ops);
165+
err = devl_port_register_with_ops(devlink, &dl_port->dl_port, dl_port_index, ops);
181166
if (err)
182167
return err;
183168

184-
err = devl_rate_leaf_create(dl_port, vport, NULL);
169+
err = devl_rate_leaf_create(&dl_port->dl_port, vport, NULL);
185170
if (err)
186171
goto rate_err;
187172

188-
vport->dl_port = dl_port;
189173
return 0;
190174

191175
rate_err:
192-
devl_port_unregister(dl_port);
176+
devl_port_unregister(&dl_port->dl_port);
193177
return err;
194178
}
195179

196-
void mlx5_esw_devlink_sf_port_unregister(struct mlx5_eswitch *esw, u16 vport_num)
180+
void mlx5_esw_offloads_devlink_port_unregister(struct mlx5_eswitch *esw, struct mlx5_vport *vport)
197181
{
198-
struct mlx5_vport *vport;
182+
struct mlx5_devlink_port *dl_port;
199183

200-
vport = mlx5_eswitch_get_vport(esw, vport_num);
201-
if (IS_ERR(vport))
184+
if (!vport->dl_port)
202185
return;
186+
dl_port = vport->dl_port;
203187

204188
mlx5_esw_qos_vport_update_group(esw, vport, NULL, NULL);
205-
devl_rate_leaf_destroy(vport->dl_port);
189+
devl_rate_leaf_destroy(&dl_port->dl_port);
206190

207-
devl_port_unregister(vport->dl_port);
208-
vport->dl_port = NULL;
191+
devl_port_unregister(&dl_port->dl_port);
192+
}
193+
194+
struct devlink_port *mlx5_esw_offloads_devlink_port(struct mlx5_eswitch *esw, u16 vport_num)
195+
{
196+
struct mlx5_vport *vport;
197+
198+
vport = mlx5_eswitch_get_vport(esw, vport_num);
199+
return IS_ERR(vport) ? ERR_CAST(vport) : &vport->dl_port->dl_port;
209200
}

0 commit comments

Comments
 (0)