cxgb4/chcr: Enable ktls settings at run time
Subsystems (5)
PATCH v3 1/1 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().
--- drivers/crypto/chelsio/chcr_core.c | 23 +++-- drivers/crypto/chelsio/chcr_core.h | 10 ++- drivers/crypto/chelsio/chcr_ktls.c | 59 ++++--------- drivers/crypto/chelsio/chcr_ktls.h | 2 - drivers/net/ethernet/chelsio/cxgb4/cxgb4.h | 4 + .../ethernet/chelsio/cxgb4/cxgb4_debugfs.c | 2 + .../net/ethernet/chelsio/cxgb4/cxgb4_main.c | 85 ++++++++++++++++++- .../net/ethernet/chelsio/cxgb4/cxgb4_uld.c | 71 +++++++++++----- .../net/ethernet/chelsio/cxgb4/cxgb4_uld.h | 7 ++ drivers/net/ethernet/chelsio/cxgb4/t4fw_api.h | 10 ++- 10 files changed, 188 insertions(+), 85 deletions(-)
drivers/crypto/chelsio/chcr_core.c +10 -13
@@ -33,6 +33,13 @@ static int cpl_fw6_pld_handler(struct adapter *adap, unsigned char *input);static void *chcr_uld_add (const struct cxgb4_lld_info *lld);static int chcr_uld_state_change (void *handle,enum cxgb4_state state); +#if defined(CONFIG_CHELSIO_TLS_DEVICE ) +static const struct tlsdev_ops chcr_ktls_ops = { + .tls_dev_add = chcr_ktls_dev_add, + .tls_dev_del = chcr_ktls_dev_del, +}; +#endif +#ifdef CONFIG_CHELSIO_IPSEC_INLINE static void update_netdev_features (void );#endif /* CONFIG_CHELSIO_IPSEC_INLINE */
@@ -56,6 +63,9 @@ static struct cxgb4_uld_info chcr_uld_info = {#if defined(CONFIG_CHELSIO_IPSEC_INLINE ) || defined(CONFIG_CHELSIO_TLS_DEVICE ) .tx_handler = chcr_uld_tx_handler,#endif /* CONFIG_CHELSIO_IPSEC_INLINE || CONFIG_CHELSIO_TLS_DEVICE */ +#if defined(CONFIG_CHELSIO_TLS_DEVICE ) + .tlsdev_ops = &chcr_ktls_ops, +#endif };static void detach_work_fn (struct work_struct *work)
@@ -207,11 +217,6 @@ static void *chcr_uld_add(const struct cxgb4_lld_info *lld) } u_ctx->lldi = *lld;chcr_dev_init (u_ctx); - -#ifdef CONFIG_CHELSIO_TLS_DEVICE -if (lld->ulp_crypto &ULP_CRYPTO_KTLS_INLINE ) -chcr_enable_ktls (padap (&u_ctx->dev)); -#endif out:return u_ctx; }
@@ -348,20 +353,12 @@ static void __exit chcr_crypto_exit(void)list_for_each_entry_safe (u_ctx, tmp, &drv_data.act_dev, entry) { adap =padap (&u_ctx->dev);memset (&adap->chcr_stats,0 ,sizeof (adap->chcr_stats)); -#ifdef CONFIG_CHELSIO_TLS_DEVICE -if (u_ctx->lldi.ulp_crypto &ULP_CRYPTO_KTLS_INLINE ) -chcr_disable_ktls (adap); -#endif list_del (&u_ctx->entry);kfree (u_ctx); }list_for_each_entry_safe (u_ctx, tmp, &drv_data.inact_dev, entry) { adap =padap (&u_ctx->dev);memset (&adap->chcr_stats,0 ,sizeof (adap->chcr_stats)); -#ifdef CONFIG_CHELSIO_TLS_DEVICE -if (u_ctx->lldi.ulp_crypto &ULP_CRYPTO_KTLS_INLINE ) -chcr_disable_ktls (adap); -#endif list_del (&u_ctx->entry);kfree (u_ctx); }
drivers/crypto/chelsio/chcr_core.h +8 -2
@@ -37,6 +37,7 @@#define __CHCR_CORE_H__#include <crypto/algapi.h> +#include <net/tls.h> #include "t4_hw.h" #include "cxgb4.h" #include "t4_msg.h"
@@ -223,10 +224,15 @@ int chcr_handle_resp(struct crypto_async_request *req, unsigned char *input,int chcr_ipsec_xmit (struct sk_buff *skb,struct net_device *dev);void chcr_add_xfrmops (const struct cxgb4_lld_info *lld);#ifdef CONFIG_CHELSIO_TLS_DEVICE -void chcr_enable_ktls (struct adapter *adap); -void chcr_disable_ktls (struct adapter *adap);int chcr_ktls_cpl_act_open_rpl (struct adapter *adap,unsigned char *input);int chcr_ktls_cpl_set_tcb_rpl (struct adapter *adap,unsigned char *input);int chcr_ktls_xmit (struct sk_buff *skb,struct net_device *dev); +int chcr_ktls_dev_add (struct net_device *netdev,struct sock *sk, +enum tls_offload_ctx_dir direction, +struct tls_crypto_info *crypto_info, +u32 start_offload_tcp_sn); +void chcr_ktls_dev_del (struct net_device *netdev, +struct tls_context *tls_ctx, +enum tls_offload_ctx_dir direction);#endif #endif /* __CHCR_CORE_H__ */
drivers/crypto/chelsio/chcr_ktls.c +15 -44
89 lines not on this page · raw message
drivers/crypto/chelsio/chcr_ktls.h +0 -2
@@ -89,8 +89,6 @@ static inline int chcr_get_first_rx_qid(struct adapter *adap)return u_ctx->lldi.rxq_ids[0 ]; } -void chcr_enable_ktls (struct adapter *adap); -void chcr_disable_ktls (struct adapter *adap);int chcr_ktls_cpl_act_open_rpl (struct adapter *adap,unsigned char *input);int chcr_ktls_cpl_set_tcb_rpl (struct adapter *adap,unsigned char *input);int chcr_ktls_xmit (struct sk_buff *skb,struct net_device *dev);
drivers/net/ethernet/chelsio/cxgb4/cxgb4.h +4 -0
@@ -1099,6 +1099,7 @@ struct adapter {/* TC u32 offload */ struct cxgb4_tc_u32_table *tc_u32; +struct chcr_ktls chcr_ktls;struct chcr_stats_debug chcr_stats;/* TC flower offload */
@@ -2060,4 +2061,7 @@ int cxgb_open(struct net_device *dev);int cxgb_close (struct net_device *dev);void cxgb4_enable_rx (struct adapter *adap,struct sge_rspq *q);void cxgb4_quiesce_rx (struct sge_rspq *q); +#ifdef CONFIG_CHELSIO_TLS_DEVICE +int cxgb4_set_ktls_feature (struct adapter *adap,bool enable); +#endif #endif /* __CXGB4_H__ */
drivers/net/ethernet/chelsio/cxgb4/cxgb4_debugfs.c +2 -0
@@ -3491,6 +3491,8 @@ static int chcr_stats_show(struct seq_file *seq, void *v) atomic_read(&adap->chcr_stats.tls_key));#ifdef CONFIG_CHELSIO_TLS_DEVICE seq_puts (seq,"\nChelsio KTLS Crypto Accelerator Stats\n" ); +seq_printf (seq,"Tx TLS offload refcount: %20u\n" , +refcount_read (&adap->chcr_ktls.ktls_refcount));seq_printf (seq,"Tx HW offload contexts added: %20llu\n" ,atomic64_read (&adap->chcr_stats.ktls_tx_ctx)); seq_printf(seq, "Tx connection created: %20llu\n",
drivers/net/ethernet/chelsio/cxgb4/cxgb4_main.c +84 -1
103 lines not on this page · raw message
drivers/net/ethernet/chelsio/cxgb4/cxgb4_uld.c +50 -21
97 lines not on this page · raw message
drivers/net/ethernet/chelsio/cxgb4/cxgb4_uld.h +7 -0
@@ -268,6 +268,10 @@ struct filter_ctx {u32 tid;/* to store tid */ }; +struct chcr_ktls { +refcount_t ktls_refcount; +}; +struct ch_filter_specification ; int cxgb4_get_free_ftid(struct net_device *dev, u8 family, bool hash_en,
@@ -464,6 +468,9 @@ struct cxgb4_uld_info { struct napi_struct *napi);void (*lro_flush)(struct t4_lro_mgr *);int (*tx_handler)(struct sk_buff *skb,struct net_device *dev); +#if IS_ENABLED (CONFIG_TLS_DEVICE ) +const struct tlsdev_ops *tlsdev_ops; +#endif };void cxgb4_uld_enable (struct adapter *adap);
drivers/net/ethernet/chelsio/cxgb4/t4fw_api.h +8 -2
@@ -1205,7 +1205,7 @@ enum fw_caps_config_crypto {FW_CAPS_CONFIG_CRYPTO_LOOKASIDE =0x00000001 ,FW_CAPS_CONFIG_TLS_INLINE =0x00000002 ,FW_CAPS_CONFIG_IPSEC_INLINE =0x00000004 , - FW_CAPS_CONFIG_TX_TLS_HW = 0x00000008, + FW_CAPS_CONFIG_TLS_HW = 0x00000008, }; enum fw_caps_config_fcoe {
@@ -1329,7 +1329,7 @@ enum fw_params_param_dev {FW_PARAMS_PARAM_DEV_DBQ_TIMERTICK =0x2A ,FW_PARAMS_PARAM_DEV_NUM_TM_CLASS =0x2B ,FW_PARAMS_PARAM_DEV_FILTER =0x2E , - FW_PARAMS_PARAM_DEV_KTLS_TX_HW = 0x31, + FW_PARAMS_PARAM_DEV_KTLS_HW = 0x31, };/*
@@ -1412,6 +1412,12 @@ enum fw_params_param_dmaq { FW_PARAMS_PARAM_DMAQ_CONM_CTXT = 0x20, }; +enum fw_params_param_dev_ktls_hw { +FW_PARAMS_PARAM_DEV_KTLS_HW_DISABLE =0x00 , +FW_PARAMS_PARAM_DEV_KTLS_HW_ENABLE =0x01 , +FW_PARAMS_PARAM_DEV_KTLS_HW_USER_ENABLE =0x01 , +}; +enum fw_params_param_dev_phyfw {FW_PARAMS_PARAM_DEV_PHYFW_DOWNLOAD =0x00 ,FW_PARAMS_PARAM_DEV_PHYFW_VERSION =0x01 ,
Signature · 1 line
2.18.1
kbuild test robot
build botI love your patch! Perhaps something to improve:
Hi Rohit,
I love your patch! Perhaps something to improve:
[auto build test WARNING on next-20200529]
[cannot apply to net/master cryptodev/master crypto/master linus/master ipvs/master v5.7-rc7 v5.7-rc6 v5.7-rc5 v5.7-rc7] [if your patch is applied to the wrong git tree, please drop us a note to help
improve the system. BTW, we also suggest to use '--base' option to specify the
base tree in git format-patch, please see https://stackoverflow.com/a/37406982]
url: https://github.com/0day-ci/linux/commits/Rohit-Maheshwari/cxgb4-chcr-Enable-ktls-settings-at-run-time/20200601-045155 base: e7b08814b16b80a0bf76eeca16317f8c2ed23b8c config: x86_64-allyesconfig (attached as .config) compiler: clang version 11.0.0 (https://github.com/llvm/llvm-project 2388a096e7865c043e83ece4e26654bd3d1a20d5)
reproduce (this is a W=1 build):
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross
# install x86_64 cross compiling tool for clang build
# apt-get install binutils-x86-64-linux-gnu
# save the attached .config to linux build tree
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross ARCH=x86_64
If you fix the issue, kindly add following tag as appropriate
All warnings (new ones prefixed by >>, old ones prefixed by <<):
>> drivers/crypto/chelsio/chcr_ktls.c:376:6: warning: no previous prototype for function 'chcr_ktls_dev_del' [-Wmissing-prototypes]
void chcr_ktls_dev_del(struct net_device *netdev,
^drivers/crypto/chelsio/chcr_ktls.c:376:1: note: declare 'static' if the function is not intended to be used outside of this translation unit void chcr_ktls_dev_del(struct net_device *netdev,
^
static
>> drivers/crypto/chelsio/chcr_ktls.c:427:5: warning: no previous prototype for function 'chcr_ktls_dev_add' [-Wmissing-prototypes]
int chcr_ktls_dev_add(struct net_device *netdev, struct sock *sk,
^drivers/crypto/chelsio/chcr_ktls.c:427:1: note: declare 'static' if the function is not intended to be used outside of this translation unit int chcr_ktls_dev_add(struct net_device *netdev, struct sock *sk,
^
static
2 warnings generated.
vim +/chcr_ktls_dev_del +376 drivers/crypto/chelsio/chcr_ktls.c
367
368 /*
369 * chcr_ktls_dev_del: call back for tls_dev_del.
370 * Remove the tid and l2t entry and close the connection.
371 * it per connection basis.
372 * @netdev - net device.
373 * @tls_cts - tls context.
374 * @direction - TX/RX crypto direction
375 */
> 376 void chcr_ktls_dev_del(struct net_device *netdev,
377 struct tls_context *tls_ctx,
378 enum tls_offload_ctx_dir direction)
379 {
380 struct chcr_ktls_ofld_ctx_tx *tx_ctx =
381 chcr_get_ktls_tx_context(tls_ctx);
382 struct chcr_ktls_info *tx_info = tx_ctx->chcr_info;
383 struct sock *sk;
384
385 if (!tx_info)
386 return;
387 sk = tx_info->sk;
388
389 spin_lock(&tx_info->lock);
390 tx_info->connection_state = KTLS_CONN_CLOSED;
391 spin_unlock(&tx_info->lock);
392
393 /* clear l2t entry */
394 if (tx_info->l2te)
395 cxgb4_l2t_release(tx_info->l2te);
396
397 /* clear clip entry */
398 if (tx_info->ip_family == AF_INET6)
399 cxgb4_clip_release(netdev,
400 (const u32 *)&sk->sk_v6_daddr.in6_u.u6_addr8,
401 1);
402
403 /* clear tid */
404 if (tx_info->tid != -1) {
405 /* clear tcb state and then release tid */
406 chcr_ktls_mark_tcb_close(tx_info);
407 cxgb4_remove_tid(&tx_info->adap->tids, tx_info->tx_chan,
408 tx_info->tid, tx_info->ip_family);
409 }
410
411 atomic64_inc(&tx_info->adap->chcr_stats.ktls_tx_connection_close);
412 kvfree(tx_info);
413 tx_ctx->chcr_info = NULL;
414 /* release module refcount */
415 module_put(THIS_MODULE);
416 }
417
418 /*
419 * chcr_ktls_dev_add: call back for tls_dev_add.
420 * Create a tcb entry for TP. Also add l2t entry for the connection. And
421 * generate keys & save those keys locally.
422 * @netdev - net device.
423 * @tls_cts - tls context.
424 * @direction - TX/RX crypto direction
425 * return: SUCCESS/FAILURE.
426 */
> 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) 431 {
432 struct tls_context *tls_ctx = tls_get_ctx(sk);
433 struct chcr_ktls_ofld_ctx_tx *tx_ctx;
434 struct chcr_ktls_info *tx_info;
435 struct dst_entry *dst;
436 struct adapter *adap;
437 struct port_info *pi;
438 struct neighbour *n;
439 u8 daaddr[16];
440 int ret = -1;
441
442 tx_ctx = chcr_get_ktls_tx_context(tls_ctx);
443
444 pi = netdev_priv(netdev);
445 adap = pi->adapter;
446 if (direction == TLS_OFFLOAD_CTX_DIR_RX) {
447 pr_err("not expecting for RX direction\n");
448 ret = -EINVAL;
449 goto out;
450 }
451 if (tx_ctx->chcr_info) {
452 ret = -EINVAL;
453 goto out;
454 }
455
456 tx_info = kvzalloc(sizeof(*tx_info), GFP_KERNEL);
457 if (!tx_info) {
458 ret = -ENOMEM;
459 goto out;
460 }
461
462 spin_lock_init(&tx_info->lock);
463
464 /* clear connection state */
465 spin_lock(&tx_info->lock);
466 tx_info->connection_state = KTLS_CONN_CLOSED;
467 spin_unlock(&tx_info->lock);
468
469 tx_info->sk = sk;
470 /* initialize tid and atid to -1, 0 is a also a valid id. */
471 tx_info->tid = -1;
472 tx_info->atid = -1;
473
474 tx_info->adap = adap;
475 tx_info->netdev = netdev;
476 tx_info->first_qset = pi->first_qset;
477 tx_info->tx_chan = pi->tx_chan;
478 tx_info->smt_idx = pi->smt_idx;
479 tx_info->port_id = pi->port_id;
480
481 tx_info->rx_qid = chcr_get_first_rx_qid(adap);
482 if (unlikely(tx_info->rx_qid < 0))
483 goto out2;
484
485 tx_info->prev_seq = start_offload_tcp_sn;
486 tx_info->tcp_start_seq_number = start_offload_tcp_sn;
487
488 /* save crypto keys */
489 ret = chcr_ktls_save_keys(tx_info, crypto_info, direction);
490 if (ret < 0)
491 goto out2;
492
493 /* get peer ip */
494 if (sk->sk_family == AF_INET ||
495 (sk->sk_family == AF_INET6 && !sk->sk_ipv6only &&
496 ipv6_addr_type(&sk->sk_v6_daddr) == IPV6_ADDR_MAPPED)) {
497 memcpy(daaddr, &sk->sk_daddr, 4);
498 } else {
499 memcpy(daaddr, sk->sk_v6_daddr.in6_u.u6_addr8, 16);
500 }
501
502 /* get the l2t index */
503 dst = sk_dst_get(sk);
504 if (!dst) {
505 pr_err("DST entry not found\n");
506 goto out2;
507 }
508 n = dst_neigh_lookup(dst, daaddr);
509 if (!n || !n->dev) {
510 pr_err("neighbour not found\n");
511 dst_release(dst);
512 goto out2;
513 }
514 tx_info->l2te = cxgb4_l2t_get(adap->l2t, n, n->dev, 0);
515
516 neigh_release(n);
517 dst_release(dst);
518
519 if (!tx_info->l2te) {
520 pr_err("l2t entry not found\n");
521 goto out2;
522 }
523
524 tx_ctx->chcr_info = tx_info;
525
526 /* create a filter and call cxgb4_l2t_send to send the packet out, which
527 * will take care of updating l2t entry in hw if not already done.
528 */
529 ret = chcr_setup_connection(sk, tx_info);
530 if (ret)
531 goto out2;
532
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
539 atomic64_inc(&adap->chcr_stats.ktls_tx_connection_open);
540 return 0;
541 out2:
542 kvfree(tx_info);
543 out:
544 atomic64_inc(&adap->chcr_stats.ktls_tx_connection_fail);
545 return ret;
546 }
547
---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org
kbuild test robot
build botI love your patch! Perhaps something to improve:
Hi Rohit,
I love your patch! Perhaps something to improve:
[auto build test WARNING on next-20200529]
[cannot apply to net/master cryptodev/master crypto/master linus/master ipvs/master v5.7-rc7 v5.7-rc6 v5.7-rc5 v5.7] [if your patch is applied to the wrong git tree, please drop us a note to help
improve the system. BTW, we also suggest to use '--base' option to specify the
base tree in git format-patch, please see https://stackoverflow.com/a/37406982]
url: https://github.com/0day-ci/linux/commits/Rohit-Maheshwari/cxgb4-chcr-Enable-ktls-settings-at-run-time/20200601-045155 base: e7b08814b16b80a0bf76eeca16317f8c2ed23b8c config: mips-allyesconfig (attached as .config) compiler: mips-linux-gcc (GCC) 9.3.0
reproduce (this is a W=1 build):
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross
# save the attached .config to linux build tree
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-9.3.0 make.cross ARCH=mips
If you fix the issue, kindly add following tag as appropriate
All warnings (new ones prefixed by >>, old ones prefixed by <<):
>> drivers/crypto/chelsio/chcr_ktls.c:376:6: warning: no previous prototype for 'chcr_ktls_dev_del' [-Wmissing-prototypes] 376 | void chcr_ktls_dev_del(struct net_device *netdev, | ^~~~~~~~~~~~~~~~~ >> drivers/crypto/chelsio/chcr_ktls.c:427:5: warning: no previous prototype for 'chcr_ktls_dev_add' [-Wmissing-prototypes]
427 | int chcr_ktls_dev_add(struct net_device *netdev, struct sock *sk,
| ^~~~~~~~~~~~~~~~~
vim +/chcr_ktls_dev_del +376 drivers/crypto/chelsio/chcr_ktls.c
367
368 /*
369 * chcr_ktls_dev_del: call back for tls_dev_del.
370 * Remove the tid and l2t entry and close the connection.
371 * it per connection basis.
372 * @netdev - net device.
373 * @tls_cts - tls context.
374 * @direction - TX/RX crypto direction
375 */
> 376 void chcr_ktls_dev_del(struct net_device *netdev,
377 struct tls_context *tls_ctx,
378 enum tls_offload_ctx_dir direction)
379 {
380 struct chcr_ktls_ofld_ctx_tx *tx_ctx =
381 chcr_get_ktls_tx_context(tls_ctx);
382 struct chcr_ktls_info *tx_info = tx_ctx->chcr_info;
383 struct sock *sk;
384
385 if (!tx_info)
386 return;
387 sk = tx_info->sk;
388
389 spin_lock(&tx_info->lock);
390 tx_info->connection_state = KTLS_CONN_CLOSED;
391 spin_unlock(&tx_info->lock);
392
393 /* clear l2t entry */
394 if (tx_info->l2te)
395 cxgb4_l2t_release(tx_info->l2te);
396
397 /* clear clip entry */
398 if (tx_info->ip_family == AF_INET6)
399 cxgb4_clip_release(netdev,
400 (const u32 *)&sk->sk_v6_daddr.in6_u.u6_addr8,
401 1);
402
403 /* clear tid */
404 if (tx_info->tid != -1) {
405 /* clear tcb state and then release tid */
406 chcr_ktls_mark_tcb_close(tx_info);
407 cxgb4_remove_tid(&tx_info->adap->tids, tx_info->tx_chan,
408 tx_info->tid, tx_info->ip_family);
409 }
410
411 atomic64_inc(&tx_info->adap->chcr_stats.ktls_tx_connection_close);
412 kvfree(tx_info);
413 tx_ctx->chcr_info = NULL;
414 /* release module refcount */
415 module_put(THIS_MODULE);
416 }
417
418 /*
419 * chcr_ktls_dev_add: call back for tls_dev_add.
420 * Create a tcb entry for TP. Also add l2t entry for the connection. And
421 * generate keys & save those keys locally.
422 * @netdev - net device.
423 * @tls_cts - tls context.
424 * @direction - TX/RX crypto direction
425 * return: SUCCESS/FAILURE.
426 */
> 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) 431 {
432 struct tls_context *tls_ctx = tls_get_ctx(sk);
433 struct chcr_ktls_ofld_ctx_tx *tx_ctx;
434 struct chcr_ktls_info *tx_info;
435 struct dst_entry *dst;
436 struct adapter *adap;
437 struct port_info *pi;
438 struct neighbour *n;
439 u8 daaddr[16];
440 int ret = -1;
441
442 tx_ctx = chcr_get_ktls_tx_context(tls_ctx);
443
444 pi = netdev_priv(netdev);
445 adap = pi->adapter;
446 if (direction == TLS_OFFLOAD_CTX_DIR_RX) {
447 pr_err("not expecting for RX direction\n");
448 ret = -EINVAL;
449 goto out;
450 }
451 if (tx_ctx->chcr_info) {
452 ret = -EINVAL;
453 goto out;
454 }
455
456 tx_info = kvzalloc(sizeof(*tx_info), GFP_KERNEL);
457 if (!tx_info) {
458 ret = -ENOMEM;
459 goto out;
460 }
461
462 spin_lock_init(&tx_info->lock);
463
464 /* clear connection state */
465 spin_lock(&tx_info->lock);
466 tx_info->connection_state = KTLS_CONN_CLOSED;
467 spin_unlock(&tx_info->lock);
468
469 tx_info->sk = sk;
470 /* initialize tid and atid to -1, 0 is a also a valid id. */
471 tx_info->tid = -1;
472 tx_info->atid = -1;
473
474 tx_info->adap = adap;
475 tx_info->netdev = netdev;
476 tx_info->first_qset = pi->first_qset;
477 tx_info->tx_chan = pi->tx_chan;
478 tx_info->smt_idx = pi->smt_idx;
479 tx_info->port_id = pi->port_id;
480
481 tx_info->rx_qid = chcr_get_first_rx_qid(adap);
482 if (unlikely(tx_info->rx_qid < 0))
483 goto out2;
484
485 tx_info->prev_seq = start_offload_tcp_sn;
486 tx_info->tcp_start_seq_number = start_offload_tcp_sn;
487
488 /* save crypto keys */
489 ret = chcr_ktls_save_keys(tx_info, crypto_info, direction);
490 if (ret < 0)
491 goto out2;
492
493 /* get peer ip */
494 if (sk->sk_family == AF_INET ||
495 (sk->sk_family == AF_INET6 && !sk->sk_ipv6only &&
496 ipv6_addr_type(&sk->sk_v6_daddr) == IPV6_ADDR_MAPPED)) {
497 memcpy(daaddr, &sk->sk_daddr, 4);
498 } else {
499 memcpy(daaddr, sk->sk_v6_daddr.in6_u.u6_addr8, 16);
500 }
501
502 /* get the l2t index */
503 dst = sk_dst_get(sk);
504 if (!dst) {
505 pr_err("DST entry not found\n");
506 goto out2;
507 }
508 n = dst_neigh_lookup(dst, daaddr);
509 if (!n || !n->dev) {
510 pr_err("neighbour not found\n");
511 dst_release(dst);
512 goto out2;
513 }
514 tx_info->l2te = cxgb4_l2t_get(adap->l2t, n, n->dev, 0);
515
516 neigh_release(n);
517 dst_release(dst);
518
519 if (!tx_info->l2te) {
520 pr_err("l2t entry not found\n");
521 goto out2;
522 }
523
524 tx_ctx->chcr_info = tx_info;
525
526 /* create a filter and call cxgb4_l2t_send to send the packet out, which
527 * will take care of updating l2t entry in hw if not already done.
528 */
529 ret = chcr_setup_connection(sk, tx_info);
530 if (ret)
531 goto out2;
532
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
539 atomic64_inc(&adap->chcr_stats.ktls_tx_connection_open);
540 return 0;
541 out2:
542 kvfree(tx_info);
543 out:
544 atomic64_inc(&adap->chcr_stats.ktls_tx_connection_fail);
545 return ret;
546 }
547
---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org