Skip to content

Commit c83294b

Browse files
Ilya Lesokhindavem330
authored andcommitted
net/mlx5e: TLS, Add Innova TLS TX support
Add NETIF_F_HW_TLS_TX capability and expose tlsdev_ops to work with the TLS generic NIC offload infrastructure. The NETIF_F_HW_TLS_TX capability will be added in the next patch. Signed-off-by: Ilya Lesokhin <[email protected]> Signed-off-by: Boris Pismenny <[email protected]> Acked-by: Saeed Mahameed <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 1ae1732 commit c83294b

File tree

5 files changed

+254
-0
lines changed

5 files changed

+254
-0
lines changed

drivers/net/ethernet/mellanox/mlx5/core/Kconfig

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,3 +86,14 @@ config MLX5_EN_IPSEC
8686
Build support for IPsec cryptography-offload accelaration in the NIC.
8787
Note: Support for hardware with this capability needs to be selected
8888
for this option to become available.
89+
90+
config MLX5_EN_TLS
91+
bool "TLS cryptography-offload accelaration"
92+
depends on MLX5_CORE_EN
93+
depends on TLS_DEVICE
94+
depends on MLX5_ACCEL
95+
default n
96+
---help---
97+
Build support for TLS cryptography-offload accelaration in the NIC.
98+
Note: Support for hardware with this capability needs to be selected
99+
for this option to become available.

drivers/net/ethernet/mellanox/mlx5/core/Makefile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,6 @@ mlx5_core-$(CONFIG_MLX5_CORE_IPOIB) += ipoib/ipoib.o ipoib/ethtool.o ipoib/ipoib
2828
mlx5_core-$(CONFIG_MLX5_EN_IPSEC) += en_accel/ipsec.o en_accel/ipsec_rxtx.o \
2929
en_accel/ipsec_stats.o
3030

31+
mlx5_core-$(CONFIG_MLX5_EN_TLS) += en_accel/tls.o
32+
3133
CFLAGS_tracepoint.o := -I$(src)
Lines changed: 173 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,173 @@
1+
/*
2+
* Copyright (c) 2018 Mellanox Technologies. All rights reserved.
3+
*
4+
* This software is available to you under a choice of one of two
5+
* licenses. You may choose to be licensed under the terms of the GNU
6+
* General Public License (GPL) Version 2, available from the file
7+
* COPYING in the main directory of this source tree, or the
8+
* OpenIB.org BSD license below:
9+
*
10+
* Redistribution and use in source and binary forms, with or
11+
* without modification, are permitted provided that the following
12+
* conditions are met:
13+
*
14+
* - Redistributions of source code must retain the above
15+
* copyright notice, this list of conditions and the following
16+
* disclaimer.
17+
*
18+
* - Redistributions in binary form must reproduce the above
19+
* copyright notice, this list of conditions and the following
20+
* disclaimer in the documentation and/or other materials
21+
* provided with the distribution.
22+
*
23+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
24+
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
25+
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
26+
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
27+
* BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
28+
* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
29+
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
30+
* SOFTWARE.
31+
*
32+
*/
33+
34+
#include <linux/netdevice.h>
35+
#include <net/ipv6.h>
36+
#include "en_accel/tls.h"
37+
#include "accel/tls.h"
38+
39+
static void mlx5e_tls_set_ipv4_flow(void *flow, struct sock *sk)
40+
{
41+
struct inet_sock *inet = inet_sk(sk);
42+
43+
MLX5_SET(tls_flow, flow, ipv6, 0);
44+
memcpy(MLX5_ADDR_OF(tls_flow, flow, dst_ipv4_dst_ipv6.ipv4_layout.ipv4),
45+
&inet->inet_daddr, MLX5_FLD_SZ_BYTES(ipv4_layout, ipv4));
46+
memcpy(MLX5_ADDR_OF(tls_flow, flow, src_ipv4_src_ipv6.ipv4_layout.ipv4),
47+
&inet->inet_rcv_saddr, MLX5_FLD_SZ_BYTES(ipv4_layout, ipv4));
48+
}
49+
50+
#if IS_ENABLED(CONFIG_IPV6)
51+
static void mlx5e_tls_set_ipv6_flow(void *flow, struct sock *sk)
52+
{
53+
struct ipv6_pinfo *np = inet6_sk(sk);
54+
55+
MLX5_SET(tls_flow, flow, ipv6, 1);
56+
memcpy(MLX5_ADDR_OF(tls_flow, flow, dst_ipv4_dst_ipv6.ipv6_layout.ipv6),
57+
&sk->sk_v6_daddr, MLX5_FLD_SZ_BYTES(ipv6_layout, ipv6));
58+
memcpy(MLX5_ADDR_OF(tls_flow, flow, src_ipv4_src_ipv6.ipv6_layout.ipv6),
59+
&np->saddr, MLX5_FLD_SZ_BYTES(ipv6_layout, ipv6));
60+
}
61+
#endif
62+
63+
static void mlx5e_tls_set_flow_tcp_ports(void *flow, struct sock *sk)
64+
{
65+
struct inet_sock *inet = inet_sk(sk);
66+
67+
memcpy(MLX5_ADDR_OF(tls_flow, flow, src_port), &inet->inet_sport,
68+
MLX5_FLD_SZ_BYTES(tls_flow, src_port));
69+
memcpy(MLX5_ADDR_OF(tls_flow, flow, dst_port), &inet->inet_dport,
70+
MLX5_FLD_SZ_BYTES(tls_flow, dst_port));
71+
}
72+
73+
static int mlx5e_tls_set_flow(void *flow, struct sock *sk, u32 caps)
74+
{
75+
switch (sk->sk_family) {
76+
case AF_INET:
77+
mlx5e_tls_set_ipv4_flow(flow, sk);
78+
break;
79+
#if IS_ENABLED(CONFIG_IPV6)
80+
case AF_INET6:
81+
if (!sk->sk_ipv6only &&
82+
ipv6_addr_type(&sk->sk_v6_daddr) == IPV6_ADDR_MAPPED) {
83+
mlx5e_tls_set_ipv4_flow(flow, sk);
84+
break;
85+
}
86+
if (!(caps & MLX5_ACCEL_TLS_IPV6))
87+
goto error_out;
88+
89+
mlx5e_tls_set_ipv6_flow(flow, sk);
90+
break;
91+
#endif
92+
default:
93+
goto error_out;
94+
}
95+
96+
mlx5e_tls_set_flow_tcp_ports(flow, sk);
97+
return 0;
98+
error_out:
99+
return -EINVAL;
100+
}
101+
102+
static int mlx5e_tls_add(struct net_device *netdev, struct sock *sk,
103+
enum tls_offload_ctx_dir direction,
104+
struct tls_crypto_info *crypto_info,
105+
u32 start_offload_tcp_sn)
106+
{
107+
struct mlx5e_priv *priv = netdev_priv(netdev);
108+
struct tls_context *tls_ctx = tls_get_ctx(sk);
109+
struct mlx5_core_dev *mdev = priv->mdev;
110+
u32 caps = mlx5_accel_tls_device_caps(mdev);
111+
int ret = -ENOMEM;
112+
void *flow;
113+
114+
if (direction != TLS_OFFLOAD_CTX_DIR_TX)
115+
return -EINVAL;
116+
117+
flow = kzalloc(MLX5_ST_SZ_BYTES(tls_flow), GFP_KERNEL);
118+
if (!flow)
119+
return ret;
120+
121+
ret = mlx5e_tls_set_flow(flow, sk, caps);
122+
if (ret)
123+
goto free_flow;
124+
125+
if (direction == TLS_OFFLOAD_CTX_DIR_TX) {
126+
struct mlx5e_tls_offload_context *tx_ctx =
127+
mlx5e_get_tls_tx_context(tls_ctx);
128+
u32 swid;
129+
130+
ret = mlx5_accel_tls_add_tx_flow(mdev, flow, crypto_info,
131+
start_offload_tcp_sn, &swid);
132+
if (ret < 0)
133+
goto free_flow;
134+
135+
tx_ctx->swid = htonl(swid);
136+
tx_ctx->expected_seq = start_offload_tcp_sn;
137+
}
138+
139+
return 0;
140+
free_flow:
141+
kfree(flow);
142+
return ret;
143+
}
144+
145+
static void mlx5e_tls_del(struct net_device *netdev,
146+
struct tls_context *tls_ctx,
147+
enum tls_offload_ctx_dir direction)
148+
{
149+
struct mlx5e_priv *priv = netdev_priv(netdev);
150+
151+
if (direction == TLS_OFFLOAD_CTX_DIR_TX) {
152+
u32 swid = ntohl(mlx5e_get_tls_tx_context(tls_ctx)->swid);
153+
154+
mlx5_accel_tls_del_tx_flow(priv->mdev, swid);
155+
} else {
156+
netdev_err(netdev, "unsupported direction %d\n", direction);
157+
}
158+
}
159+
160+
static const struct tlsdev_ops mlx5e_tls_ops = {
161+
.tls_dev_add = mlx5e_tls_add,
162+
.tls_dev_del = mlx5e_tls_del,
163+
};
164+
165+
void mlx5e_tls_build_netdev(struct mlx5e_priv *priv)
166+
{
167+
struct net_device *netdev = priv->netdev;
168+
169+
if (!mlx5_accel_is_tls_device(priv->mdev))
170+
return;
171+
172+
netdev->tlsdev_ops = &mlx5e_tls_ops;
173+
}
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
/*
2+
* Copyright (c) 2018 Mellanox Technologies. All rights reserved.
3+
*
4+
* This software is available to you under a choice of one of two
5+
* licenses. You may choose to be licensed under the terms of the GNU
6+
* General Public License (GPL) Version 2, available from the file
7+
* COPYING in the main directory of this source tree, or the
8+
* OpenIB.org BSD license below:
9+
*
10+
* Redistribution and use in source and binary forms, with or
11+
* without modification, are permitted provided that the following
12+
* conditions are met:
13+
*
14+
* - Redistributions of source code must retain the above
15+
* copyright notice, this list of conditions and the following
16+
* disclaimer.
17+
*
18+
* - Redistributions in binary form must reproduce the above
19+
* copyright notice, this list of conditions and the following
20+
* disclaimer in the documentation and/or other materials
21+
* provided with the distribution.
22+
*
23+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
24+
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
25+
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
26+
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
27+
* BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
28+
* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
29+
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
30+
* SOFTWARE.
31+
*
32+
*/
33+
#ifndef __MLX5E_TLS_H__
34+
#define __MLX5E_TLS_H__
35+
36+
#ifdef CONFIG_MLX5_EN_TLS
37+
38+
#include <net/tls.h>
39+
#include "en.h"
40+
41+
struct mlx5e_tls_offload_context {
42+
struct tls_offload_context base;
43+
u32 expected_seq;
44+
__be32 swid;
45+
};
46+
47+
static inline struct mlx5e_tls_offload_context *
48+
mlx5e_get_tls_tx_context(struct tls_context *tls_ctx)
49+
{
50+
BUILD_BUG_ON(sizeof(struct mlx5e_tls_offload_context) >
51+
TLS_OFFLOAD_CONTEXT_SIZE);
52+
return container_of(tls_offload_ctx(tls_ctx),
53+
struct mlx5e_tls_offload_context,
54+
base);
55+
}
56+
57+
void mlx5e_tls_build_netdev(struct mlx5e_priv *priv);
58+
59+
#else
60+
61+
static inline void mlx5e_tls_build_netdev(struct mlx5e_priv *priv) { }
62+
63+
#endif
64+
65+
#endif /* __MLX5E_TLS_H__ */

drivers/net/ethernet/mellanox/mlx5/core/en_main.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,9 @@
4242
#include "en_rep.h"
4343
#include "en_accel/ipsec.h"
4444
#include "en_accel/ipsec_rxtx.h"
45+
#include "en_accel/tls.h"
4546
#include "accel/ipsec.h"
47+
#include "accel/tls.h"
4648
#include "vxlan.h"
4749

4850
struct mlx5e_rq_param {
@@ -4376,6 +4378,7 @@ static void mlx5e_build_nic_netdev(struct net_device *netdev)
43764378
#endif
43774379

43784380
mlx5e_ipsec_build_netdev(priv);
4381+
mlx5e_tls_build_netdev(priv);
43794382
}
43804383

43814384
static void mlx5e_create_q_counters(struct mlx5e_priv *priv)

0 commit comments

Comments
 (0)