Skip to content

Commit 865eddc

Browse files
committed
Merge branch 'mlx5-misc-enhancements-2025-03-04'
Tariq Toukan says: ==================== mlx5 misc enhancements 2025-03-04 This series introduces enhancements to the mlx5 core and Eth drivers. Patches 1-3 by Shahar introduce support for configuring lanes alongside speed when autonegotiation is disabled. The combination of speed and the number of lanes corresponds to a specific link mode (in the extended mask typically used in newer hardware), allowing the user to select a precise link mode when autonegotiation is off, instead of just choosing the speed. Patch 4 by Amir extends the multi-port LAG support. Patches 5-6 by Leon enhance IPsec matching logic. v1: https://lore.kernel.org/[email protected] ==================== Link: https://patch.msgid.link/[email protected] Signed-off-by: Jakub Kicinski <[email protected]>
2 parents 92d3690 + ca7992f commit 865eddc

File tree

9 files changed

+342
-274
lines changed

9 files changed

+342
-274
lines changed

drivers/net/ethernet/mellanox/mlx5/core/en/port.c

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ int mlx5_port_set_eth_ptys(struct mlx5_core_dev *dev, bool an_disable,
8080
int mlx5e_port_linkspeed(struct mlx5_core_dev *mdev, u32 *speed)
8181
{
8282
struct mlx5_port_eth_proto eproto;
83+
const struct mlx5_link_info *info;
8384
bool force_legacy = false;
8485
bool ext;
8586
int err;
@@ -94,9 +95,13 @@ int mlx5e_port_linkspeed(struct mlx5_core_dev *mdev, u32 *speed)
9495
if (err)
9596
goto out;
9697
}
97-
*speed = mlx5_port_ptys2speed(mdev, eproto.oper, force_legacy);
98-
if (!(*speed))
98+
info = mlx5_port_ptys2info(mdev, eproto.oper, force_legacy);
99+
if (!info) {
100+
*speed = SPEED_UNKNOWN;
99101
err = -EINVAL;
102+
goto out;
103+
}
104+
*speed = info->speed;
100105

101106
out:
102107
return err;

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

Lines changed: 66 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -277,12 +277,12 @@ static void mlx5e_ipsec_init_macs(struct mlx5e_ipsec_sa_entry *sa_entry,
277277
case XFRM_DEV_OFFLOAD_IN:
278278
src = attrs->dmac;
279279
dst = attrs->smac;
280-
pkey = &attrs->saddr.a4;
280+
pkey = &attrs->addrs.saddr.a4;
281281
break;
282282
case XFRM_DEV_OFFLOAD_OUT:
283283
src = attrs->smac;
284284
dst = attrs->dmac;
285-
pkey = &attrs->daddr.a4;
285+
pkey = &attrs->addrs.daddr.a4;
286286
break;
287287
default:
288288
return;
@@ -303,6 +303,16 @@ static void mlx5e_ipsec_init_macs(struct mlx5e_ipsec_sa_entry *sa_entry,
303303
neigh_release(n);
304304
}
305305

306+
static void mlx5e_ipsec_state_mask(struct mlx5e_ipsec_addr *addrs)
307+
{
308+
/*
309+
* State doesn't have subnet prefixes in outer headers.
310+
* The match is performed for exaxt source/destination addresses.
311+
*/
312+
memset(addrs->smask.m6, 0xFF, sizeof(__be32) * 4);
313+
memset(addrs->dmask.m6, 0xFF, sizeof(__be32) * 4);
314+
}
315+
306316
void mlx5e_ipsec_build_accel_xfrm_attrs(struct mlx5e_ipsec_sa_entry *sa_entry,
307317
struct mlx5_accel_esp_xfrm_attrs *attrs)
308318
{
@@ -374,9 +384,11 @@ void mlx5e_ipsec_build_accel_xfrm_attrs(struct mlx5e_ipsec_sa_entry *sa_entry,
374384
attrs->spi = be32_to_cpu(x->id.spi);
375385

376386
/* source , destination ips */
377-
memcpy(&attrs->saddr, x->props.saddr.a6, sizeof(attrs->saddr));
378-
memcpy(&attrs->daddr, x->id.daddr.a6, sizeof(attrs->daddr));
379-
attrs->family = x->props.family;
387+
memcpy(&attrs->addrs.saddr, x->props.saddr.a6,
388+
sizeof(attrs->addrs.saddr));
389+
memcpy(&attrs->addrs.daddr, x->id.daddr.a6, sizeof(attrs->addrs.daddr));
390+
attrs->addrs.family = x->props.family;
391+
mlx5e_ipsec_state_mask(&attrs->addrs);
380392
attrs->type = x->xso.type;
381393
attrs->reqid = x->props.reqid;
382394
attrs->upspec.dport = ntohs(x->sel.dport);
@@ -428,7 +440,8 @@ static int mlx5e_xfrm_validate_state(struct mlx5_core_dev *mdev,
428440
}
429441
if (x->encap) {
430442
if (!(mlx5_ipsec_device_caps(mdev) & MLX5_IPSEC_CAP_ESPINUDP)) {
431-
NL_SET_ERR_MSG_MOD(extack, "Encapsulation is not supported");
443+
NL_SET_ERR_MSG_MOD(extack,
444+
"Encapsulation is not supported");
432445
return -EINVAL;
433446
}
434447

@@ -853,13 +866,13 @@ static int mlx5e_ipsec_netevent_event(struct notifier_block *nb,
853866
xa_for_each_marked(&ipsec->sadb, idx, sa_entry, MLX5E_IPSEC_TUNNEL_SA) {
854867
attrs = &sa_entry->attrs;
855868

856-
if (attrs->family == AF_INET) {
857-
if (!neigh_key_eq32(n, &attrs->saddr.a4) &&
858-
!neigh_key_eq32(n, &attrs->daddr.a4))
869+
if (attrs->addrs.family == AF_INET) {
870+
if (!neigh_key_eq32(n, &attrs->addrs.saddr.a4) &&
871+
!neigh_key_eq32(n, &attrs->addrs.daddr.a4))
859872
continue;
860873
} else {
861-
if (!neigh_key_eq128(n, &attrs->saddr.a4) &&
862-
!neigh_key_eq128(n, &attrs->daddr.a4))
874+
if (!neigh_key_eq128(n, &attrs->addrs.saddr.a4) &&
875+
!neigh_key_eq128(n, &attrs->addrs.daddr.a4))
863876
continue;
864877
}
865878

@@ -1035,7 +1048,7 @@ static void mlx5e_xfrm_update_stats(struct xfrm_state *x)
10351048
* by removing always available headers.
10361049
*/
10371050
headers = sizeof(struct ethhdr);
1038-
if (sa_entry->attrs.family == AF_INET)
1051+
if (sa_entry->attrs.addrs.family == AF_INET)
10391052
headers += sizeof(struct iphdr);
10401053
else
10411054
headers += sizeof(struct ipv6hdr);
@@ -1044,6 +1057,43 @@ static void mlx5e_xfrm_update_stats(struct xfrm_state *x)
10441057
x->curlft.bytes += success_bytes - headers * success_packets;
10451058
}
10461059

1060+
static __be32 word_to_mask(int prefix)
1061+
{
1062+
if (prefix < 0)
1063+
return 0;
1064+
1065+
if (!prefix || prefix > 31)
1066+
return cpu_to_be32(0xFFFFFFFF);
1067+
1068+
return cpu_to_be32(((1U << prefix) - 1) << (32 - prefix));
1069+
}
1070+
1071+
static void mlx5e_ipsec_policy_mask(struct mlx5e_ipsec_addr *addrs,
1072+
struct xfrm_selector *sel)
1073+
{
1074+
int i;
1075+
1076+
if (addrs->family == AF_INET) {
1077+
addrs->smask.m4 = word_to_mask(sel->prefixlen_s);
1078+
addrs->saddr.a4 &= addrs->smask.m4;
1079+
addrs->dmask.m4 = word_to_mask(sel->prefixlen_d);
1080+
addrs->daddr.a4 &= addrs->dmask.m4;
1081+
return;
1082+
}
1083+
1084+
for (i = 0; i < 4; i++) {
1085+
if (sel->prefixlen_s != 32 * i)
1086+
addrs->smask.m6[i] =
1087+
word_to_mask(sel->prefixlen_s - 32 * i);
1088+
addrs->saddr.a6[i] &= addrs->smask.m6[i];
1089+
1090+
if (sel->prefixlen_d != 32 * i)
1091+
addrs->dmask.m6[i] =
1092+
word_to_mask(sel->prefixlen_d - 32 * i);
1093+
addrs->daddr.a6[i] &= addrs->dmask.m6[i];
1094+
}
1095+
}
1096+
10471097
static int mlx5e_xfrm_validate_policy(struct mlx5_core_dev *mdev,
10481098
struct xfrm_policy *x,
10491099
struct netlink_ext_ack *extack)
@@ -1116,9 +1166,10 @@ mlx5e_ipsec_build_accel_pol_attrs(struct mlx5e_ipsec_pol_entry *pol_entry,
11161166
sel = &x->selector;
11171167
memset(attrs, 0, sizeof(*attrs));
11181168

1119-
memcpy(&attrs->saddr, sel->saddr.a6, sizeof(attrs->saddr));
1120-
memcpy(&attrs->daddr, sel->daddr.a6, sizeof(attrs->daddr));
1121-
attrs->family = sel->family;
1169+
memcpy(&attrs->addrs.saddr, sel->saddr.a6, sizeof(attrs->addrs.saddr));
1170+
memcpy(&attrs->addrs.daddr, sel->daddr.a6, sizeof(attrs->addrs.daddr));
1171+
attrs->addrs.family = sel->family;
1172+
mlx5e_ipsec_policy_mask(&attrs->addrs, sel);
11221173
attrs->dir = x->xdo.dir;
11231174
attrs->action = x->action;
11241175
attrs->type = XFRM_DEV_OFFLOAD_PACKET;

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

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -76,27 +76,36 @@ struct mlx5_replay_esn {
7676
u8 trigger : 1;
7777
};
7878

79-
struct mlx5_accel_esp_xfrm_attrs {
80-
u32 spi;
81-
u32 mode;
82-
struct aes_gcm_keymat aes_gcm;
83-
79+
struct mlx5e_ipsec_addr {
8480
union {
8581
__be32 a4;
8682
__be32 a6[4];
8783
} saddr;
88-
84+
union {
85+
__be32 m4;
86+
__be32 m6[4];
87+
} smask;
8988
union {
9089
__be32 a4;
9190
__be32 a6[4];
9291
} daddr;
92+
union {
93+
__be32 m4;
94+
__be32 m6[4];
95+
} dmask;
96+
u8 family;
97+
};
9398

99+
struct mlx5_accel_esp_xfrm_attrs {
100+
u32 spi;
101+
u32 mode;
102+
struct aes_gcm_keymat aes_gcm;
103+
struct mlx5e_ipsec_addr addrs;
94104
struct upspec upspec;
95105
u8 dir : 2;
96106
u8 type : 2;
97107
u8 drop : 1;
98108
u8 encap : 1;
99-
u8 family;
100109
struct mlx5_replay_esn replay_esn;
101110
u32 authsize;
102111
u32 reqid;
@@ -279,18 +288,8 @@ struct mlx5e_ipsec_sa_entry {
279288
};
280289

281290
struct mlx5_accel_pol_xfrm_attrs {
282-
union {
283-
__be32 a4;
284-
__be32 a6[4];
285-
} saddr;
286-
287-
union {
288-
__be32 a4;
289-
__be32 a6[4];
290-
} daddr;
291-
291+
struct mlx5e_ipsec_addr addrs;
292292
struct upspec upspec;
293-
u8 family;
294293
u8 action;
295294
u8 type : 2;
296295
u8 dir : 2;

0 commit comments

Comments
 (0)