Skip to content

Commit a3ac249

Browse files
rmchelsiodavem330
authored andcommitted
cxgb4/chcr: Enable ktls settings at run time
Current design enables ktls setting from start, which is not efficient. Now the feature will be enabled when user demands TLS offload on any interface. v1->v2: - taking ULD module refcount till any single connection exists. - taking rtnl_lock() before clearing tls_devops. v2->v3: - cxgb4 is now registering to tlsdev_ops. - module refcount inc/dec in chcr. - refcount is only for connections. - removed new code from cxgb_set_feature(). v3->v4: - fixed warning message. Signed-off-by: Rohit Maheshwari <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 79a1f0c commit a3ac249

File tree

10 files changed

+195
-85
lines changed

10 files changed

+195
-85
lines changed

drivers/crypto/chelsio/chcr_core.c

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,13 @@ static int cpl_fw6_pld_handler(struct adapter *adap, unsigned char *input);
3333
static void *chcr_uld_add(const struct cxgb4_lld_info *lld);
3434
static int chcr_uld_state_change(void *handle, enum cxgb4_state state);
3535

36+
#if defined(CONFIG_CHELSIO_TLS_DEVICE)
37+
static const struct tlsdev_ops chcr_ktls_ops = {
38+
.tls_dev_add = chcr_ktls_dev_add,
39+
.tls_dev_del = chcr_ktls_dev_del,
40+
};
41+
#endif
42+
3643
#ifdef CONFIG_CHELSIO_IPSEC_INLINE
3744
static void update_netdev_features(void);
3845
#endif /* CONFIG_CHELSIO_IPSEC_INLINE */
@@ -56,6 +63,9 @@ static struct cxgb4_uld_info chcr_uld_info = {
5663
#if defined(CONFIG_CHELSIO_IPSEC_INLINE) || defined(CONFIG_CHELSIO_TLS_DEVICE)
5764
.tx_handler = chcr_uld_tx_handler,
5865
#endif /* CONFIG_CHELSIO_IPSEC_INLINE || CONFIG_CHELSIO_TLS_DEVICE */
66+
#if defined(CONFIG_CHELSIO_TLS_DEVICE)
67+
.tlsdev_ops = &chcr_ktls_ops,
68+
#endif
5969
};
6070

6171
static void detach_work_fn(struct work_struct *work)
@@ -207,11 +217,6 @@ static void *chcr_uld_add(const struct cxgb4_lld_info *lld)
207217
}
208218
u_ctx->lldi = *lld;
209219
chcr_dev_init(u_ctx);
210-
211-
#ifdef CONFIG_CHELSIO_TLS_DEVICE
212-
if (lld->ulp_crypto & ULP_CRYPTO_KTLS_INLINE)
213-
chcr_enable_ktls(padap(&u_ctx->dev));
214-
#endif
215220
out:
216221
return u_ctx;
217222
}
@@ -348,20 +353,12 @@ static void __exit chcr_crypto_exit(void)
348353
list_for_each_entry_safe(u_ctx, tmp, &drv_data.act_dev, entry) {
349354
adap = padap(&u_ctx->dev);
350355
memset(&adap->chcr_stats, 0, sizeof(adap->chcr_stats));
351-
#ifdef CONFIG_CHELSIO_TLS_DEVICE
352-
if (u_ctx->lldi.ulp_crypto & ULP_CRYPTO_KTLS_INLINE)
353-
chcr_disable_ktls(adap);
354-
#endif
355356
list_del(&u_ctx->entry);
356357
kfree(u_ctx);
357358
}
358359
list_for_each_entry_safe(u_ctx, tmp, &drv_data.inact_dev, entry) {
359360
adap = padap(&u_ctx->dev);
360361
memset(&adap->chcr_stats, 0, sizeof(adap->chcr_stats));
361-
#ifdef CONFIG_CHELSIO_TLS_DEVICE
362-
if (u_ctx->lldi.ulp_crypto & ULP_CRYPTO_KTLS_INLINE)
363-
chcr_disable_ktls(adap);
364-
#endif
365362
list_del(&u_ctx->entry);
366363
kfree(u_ctx);
367364
}

drivers/crypto/chelsio/chcr_core.h

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
#define __CHCR_CORE_H__
3838

3939
#include <crypto/algapi.h>
40+
#include <net/tls.h>
4041
#include "t4_hw.h"
4142
#include "cxgb4.h"
4243
#include "t4_msg.h"
@@ -223,10 +224,15 @@ int chcr_handle_resp(struct crypto_async_request *req, unsigned char *input,
223224
int chcr_ipsec_xmit(struct sk_buff *skb, struct net_device *dev);
224225
void chcr_add_xfrmops(const struct cxgb4_lld_info *lld);
225226
#ifdef CONFIG_CHELSIO_TLS_DEVICE
226-
void chcr_enable_ktls(struct adapter *adap);
227-
void chcr_disable_ktls(struct adapter *adap);
228227
int chcr_ktls_cpl_act_open_rpl(struct adapter *adap, unsigned char *input);
229228
int chcr_ktls_cpl_set_tcb_rpl(struct adapter *adap, unsigned char *input);
230229
int chcr_ktls_xmit(struct sk_buff *skb, struct net_device *dev);
230+
extern int chcr_ktls_dev_add(struct net_device *netdev, struct sock *sk,
231+
enum tls_offload_ctx_dir direction,
232+
struct tls_crypto_info *crypto_info,
233+
u32 start_offload_tcp_sn);
234+
extern void chcr_ktls_dev_del(struct net_device *netdev,
235+
struct tls_context *tls_ctx,
236+
enum tls_offload_ctx_dir direction);
231237
#endif
232238
#endif /* __CHCR_CORE_H__ */

drivers/crypto/chelsio/chcr_ktls.c

Lines changed: 15 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -373,9 +373,9 @@ static int chcr_ktls_mark_tcb_close(struct chcr_ktls_info *tx_info)
373373
* @tls_cts - tls context.
374374
* @direction - TX/RX crypto direction
375375
*/
376-
static void chcr_ktls_dev_del(struct net_device *netdev,
377-
struct tls_context *tls_ctx,
378-
enum tls_offload_ctx_dir direction)
376+
void chcr_ktls_dev_del(struct net_device *netdev,
377+
struct tls_context *tls_ctx,
378+
enum tls_offload_ctx_dir direction)
379379
{
380380
struct chcr_ktls_ofld_ctx_tx *tx_ctx =
381381
chcr_get_ktls_tx_context(tls_ctx);
@@ -411,6 +411,8 @@ static void chcr_ktls_dev_del(struct net_device *netdev,
411411
atomic64_inc(&tx_info->adap->chcr_stats.ktls_tx_connection_close);
412412
kvfree(tx_info);
413413
tx_ctx->chcr_info = NULL;
414+
/* release module refcount */
415+
module_put(THIS_MODULE);
414416
}
415417

416418
/*
@@ -422,10 +424,10 @@ static void chcr_ktls_dev_del(struct net_device *netdev,
422424
* @direction - TX/RX crypto direction
423425
* return: SUCCESS/FAILURE.
424426
*/
425-
static int chcr_ktls_dev_add(struct net_device *netdev, struct sock *sk,
426-
enum tls_offload_ctx_dir direction,
427-
struct tls_crypto_info *crypto_info,
428-
u32 start_offload_tcp_sn)
427+
int chcr_ktls_dev_add(struct net_device *netdev, struct sock *sk,
428+
enum tls_offload_ctx_dir direction,
429+
struct tls_crypto_info *crypto_info,
430+
u32 start_offload_tcp_sn)
429431
{
430432
struct tls_context *tls_ctx = tls_get_ctx(sk);
431433
struct chcr_ktls_ofld_ctx_tx *tx_ctx;
@@ -528,6 +530,12 @@ static int chcr_ktls_dev_add(struct net_device *netdev, struct sock *sk,
528530
if (ret)
529531
goto out2;
530532

533+
/* Driver shouldn't be removed until any single connection exists */
534+
if (!try_module_get(THIS_MODULE)) {
535+
ret = -EINVAL;
536+
goto out2;
537+
}
538+
531539
atomic64_inc(&adap->chcr_stats.ktls_tx_connection_open);
532540
return 0;
533541
out2:
@@ -537,43 +545,6 @@ static int chcr_ktls_dev_add(struct net_device *netdev, struct sock *sk,
537545
return ret;
538546
}
539547

540-
static const struct tlsdev_ops chcr_ktls_ops = {
541-
.tls_dev_add = chcr_ktls_dev_add,
542-
.tls_dev_del = chcr_ktls_dev_del,
543-
};
544-
545-
/*
546-
* chcr_enable_ktls: add NETIF_F_HW_TLS_TX flag in all the ports.
547-
*/
548-
void chcr_enable_ktls(struct adapter *adap)
549-
{
550-
struct net_device *netdev;
551-
int i;
552-
553-
for_each_port(adap, i) {
554-
netdev = adap->port[i];
555-
netdev->features |= NETIF_F_HW_TLS_TX;
556-
netdev->hw_features |= NETIF_F_HW_TLS_TX;
557-
netdev->tlsdev_ops = &chcr_ktls_ops;
558-
}
559-
}
560-
561-
/*
562-
* chcr_disable_ktls: remove NETIF_F_HW_TLS_TX flag from all the ports.
563-
*/
564-
void chcr_disable_ktls(struct adapter *adap)
565-
{
566-
struct net_device *netdev;
567-
int i;
568-
569-
for_each_port(adap, i) {
570-
netdev = adap->port[i];
571-
netdev->features &= ~NETIF_F_HW_TLS_TX;
572-
netdev->hw_features &= ~NETIF_F_HW_TLS_TX;
573-
netdev->tlsdev_ops = NULL;
574-
}
575-
}
576-
577548
/*
578549
* chcr_init_tcb_fields: Initialize tcb fields to handle TCP seq number
579550
* handling.

drivers/crypto/chelsio/chcr_ktls.h

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,10 +89,15 @@ static inline int chcr_get_first_rx_qid(struct adapter *adap)
8989
return u_ctx->lldi.rxq_ids[0];
9090
}
9191

92-
void chcr_enable_ktls(struct adapter *adap);
93-
void chcr_disable_ktls(struct adapter *adap);
9492
int chcr_ktls_cpl_act_open_rpl(struct adapter *adap, unsigned char *input);
9593
int chcr_ktls_cpl_set_tcb_rpl(struct adapter *adap, unsigned char *input);
9694
int chcr_ktls_xmit(struct sk_buff *skb, struct net_device *dev);
95+
int chcr_ktls_dev_add(struct net_device *netdev, struct sock *sk,
96+
enum tls_offload_ctx_dir direction,
97+
struct tls_crypto_info *crypto_info,
98+
u32 start_offload_tcp_sn);
99+
void chcr_ktls_dev_del(struct net_device *netdev,
100+
struct tls_context *tls_ctx,
101+
enum tls_offload_ctx_dir direction);
97102
#endif /* CONFIG_CHELSIO_TLS_DEVICE */
98103
#endif /* __CHCR_KTLS_H__ */

drivers/net/ethernet/chelsio/cxgb4/cxgb4.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1099,6 +1099,7 @@ struct adapter {
10991099

11001100
/* TC u32 offload */
11011101
struct cxgb4_tc_u32_table *tc_u32;
1102+
struct chcr_ktls chcr_ktls;
11021103
struct chcr_stats_debug chcr_stats;
11031104

11041105
/* TC flower offload */
@@ -2060,4 +2061,7 @@ int cxgb_open(struct net_device *dev);
20602061
int cxgb_close(struct net_device *dev);
20612062
void cxgb4_enable_rx(struct adapter *adap, struct sge_rspq *q);
20622063
void cxgb4_quiesce_rx(struct sge_rspq *q);
2064+
#ifdef CONFIG_CHELSIO_TLS_DEVICE
2065+
int cxgb4_set_ktls_feature(struct adapter *adap, bool enable);
2066+
#endif
20632067
#endif /* __CXGB4_H__ */

drivers/net/ethernet/chelsio/cxgb4/cxgb4_debugfs.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3491,6 +3491,8 @@ static int chcr_stats_show(struct seq_file *seq, void *v)
34913491
atomic_read(&adap->chcr_stats.tls_key));
34923492
#ifdef CONFIG_CHELSIO_TLS_DEVICE
34933493
seq_puts(seq, "\nChelsio KTLS Crypto Accelerator Stats\n");
3494+
seq_printf(seq, "Tx TLS offload refcount: %20u\n",
3495+
refcount_read(&adap->chcr_ktls.ktls_refcount));
34943496
seq_printf(seq, "Tx HW offload contexts added: %20llu\n",
34953497
atomic64_read(&adap->chcr_stats.ktls_tx_ctx));
34963498
seq_printf(seq, "Tx connection created: %20llu\n",

drivers/net/ethernet/chelsio/cxgb4/cxgb4_main.c

Lines changed: 84 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,9 @@
6666
#include <linux/crash_dump.h>
6767
#include <net/udp_tunnel.h>
6868
#include <net/xfrm.h>
69+
#if defined(CONFIG_CHELSIO_TLS_DEVICE)
70+
#include <net/tls.h>
71+
#endif
6972

7073
#include "cxgb4.h"
7174
#include "cxgb4_filter.h"
@@ -6064,6 +6067,79 @@ static int cxgb4_iov_configure(struct pci_dev *pdev, int num_vfs)
60646067
}
60656068
#endif /* CONFIG_PCI_IOV */
60666069

6070+
#if defined(CONFIG_CHELSIO_TLS_DEVICE)
6071+
6072+
static int cxgb4_ktls_dev_add(struct net_device *netdev, struct sock *sk,
6073+
enum tls_offload_ctx_dir direction,
6074+
struct tls_crypto_info *crypto_info,
6075+
u32 tcp_sn)
6076+
{
6077+
struct adapter *adap = netdev2adap(netdev);
6078+
int ret = 0;
6079+
6080+
mutex_lock(&uld_mutex);
6081+
if (!adap->uld[CXGB4_ULD_CRYPTO].handle) {
6082+
dev_err(adap->pdev_dev, "chcr driver is not loaded\n");
6083+
ret = -EOPNOTSUPP;
6084+
goto out_unlock;
6085+
}
6086+
6087+
if (!adap->uld[CXGB4_ULD_CRYPTO].tlsdev_ops) {
6088+
dev_err(adap->pdev_dev,
6089+
"chcr driver has no registered tlsdev_ops()\n");
6090+
ret = -EOPNOTSUPP;
6091+
goto out_unlock;
6092+
}
6093+
6094+
ret = cxgb4_set_ktls_feature(adap, FW_PARAMS_PARAM_DEV_KTLS_HW_ENABLE);
6095+
if (ret)
6096+
goto out_unlock;
6097+
6098+
ret = adap->uld[CXGB4_ULD_CRYPTO].tlsdev_ops->tls_dev_add(netdev, sk,
6099+
direction,
6100+
crypto_info,
6101+
tcp_sn);
6102+
/* if there is a failure, clear the refcount */
6103+
if (ret)
6104+
cxgb4_set_ktls_feature(adap,
6105+
FW_PARAMS_PARAM_DEV_KTLS_HW_DISABLE);
6106+
out_unlock:
6107+
mutex_unlock(&uld_mutex);
6108+
return ret;
6109+
}
6110+
6111+
static void cxgb4_ktls_dev_del(struct net_device *netdev,
6112+
struct tls_context *tls_ctx,
6113+
enum tls_offload_ctx_dir direction)
6114+
{
6115+
struct adapter *adap = netdev2adap(netdev);
6116+
6117+
mutex_lock(&uld_mutex);
6118+
if (!adap->uld[CXGB4_ULD_CRYPTO].handle) {
6119+
dev_err(adap->pdev_dev, "chcr driver is not loaded\n");
6120+
goto out_unlock;
6121+
}
6122+
6123+
if (!adap->uld[CXGB4_ULD_CRYPTO].tlsdev_ops) {
6124+
dev_err(adap->pdev_dev,
6125+
"chcr driver has no registered tlsdev_ops\n");
6126+
goto out_unlock;
6127+
}
6128+
6129+
adap->uld[CXGB4_ULD_CRYPTO].tlsdev_ops->tls_dev_del(netdev, tls_ctx,
6130+
direction);
6131+
cxgb4_set_ktls_feature(adap, FW_PARAMS_PARAM_DEV_KTLS_HW_DISABLE);
6132+
6133+
out_unlock:
6134+
mutex_unlock(&uld_mutex);
6135+
}
6136+
6137+
static const struct tlsdev_ops cxgb4_ktls_ops = {
6138+
.tls_dev_add = cxgb4_ktls_dev_add,
6139+
.tls_dev_del = cxgb4_ktls_dev_del,
6140+
};
6141+
#endif /* CONFIG_CHELSIO_TLS_DEVICE */
6142+
60676143
static int init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
60686144
{
60696145
struct net_device *netdev;
@@ -6313,7 +6389,14 @@ static int init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
63136389
netdev->hw_features |= NETIF_F_HIGHDMA;
63146390
netdev->features |= netdev->hw_features;
63156391
netdev->vlan_features = netdev->features & VLAN_FEAT;
6316-
6392+
#if defined(CONFIG_CHELSIO_TLS_DEVICE)
6393+
if (pi->adapter->params.crypto & FW_CAPS_CONFIG_TLS_HW) {
6394+
netdev->hw_features |= NETIF_F_HW_TLS_TX;
6395+
netdev->tlsdev_ops = &cxgb4_ktls_ops;
6396+
/* initialize the refcount */
6397+
refcount_set(&pi->adapter->chcr_ktls.ktls_refcount, 0);
6398+
}
6399+
#endif
63176400
netdev->priv_flags |= IFF_UNICAST_FLT;
63186401

63196402
/* MTU range: 81 - 9600 */

0 commit comments

Comments
 (0)