From: Leon Romanovsky <leon@kernel.org>
To: Simon Horman <simon.horman@corigine.com>
Cc: David Miller <davem@davemloft.net>,
Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>,
Steffen Klassert <steffen.klassert@secunet.com>,
Herbert Xu <herbert@gondor.apana.org.au>,
Chentian Liu <chengtian.liu@corigine.com>,
Huanhuan Wang <huanhuan.wang@corigine.com>,
Yinjun Zhang <yinjun.zhang@corigine.com>,
Louis Peens <louis.peens@corigine.com>,
netdev@vger.kernel.org, oss-drivers@corigine.com
Subject: Re: [PATCH net-next v3 3/3] nfp: implement xfrm callbacks and expose ipsec offload feature to upper layer
Date: Sun, 6 Nov 2022 21:48:10 +0200 [thread overview]
Message-ID: <Y2gPelnt3xfgDGYd@unreal> (raw)
In-Reply-To: <20221101110248.423966-4-simon.horman@corigine.com>
On Tue, Nov 01, 2022 at 12:02:48PM +0100, Simon Horman wrote:
> From: Huanhuan Wang <huanhuan.wang@corigine.com>
>
> Xfrm callbacks are implemented to offload SA info into firmware
> by mailbox. It supports 16K SA info in total.
>
> Expose ipsec offload feature to upper layer, this feature will
> signal the availability of the offload.
>
> Based on initial work of Norm Bagley <norman.bagley@netronome.com>.
>
> Signed-off-by: Huanhuan Wang <huanhuan.wang@corigine.com>
> Reviewed-by: Louis Peens <louis.peens@corigine.com>
> Signed-off-by: Simon Horman <simon.horman@corigine.com>
> ---
> .../net/ethernet/netronome/nfp/crypto/ipsec.c | 532 +++++++++++++++++-
> .../ethernet/netronome/nfp/nfp_net_common.c | 6 +
> .../net/ethernet/netronome/nfp/nfp_net_ctrl.h | 4 +-
> 3 files changed, 538 insertions(+), 4 deletions(-)
<...>
> static int nfp_net_xfrm_add_state(struct xfrm_state *x)
> {
> - return -EOPNOTSUPP;
> + struct net_device *netdev = x->xso.dev;
> + struct nfp_ipsec_cfg_mssg msg = {0};
I think that I already wrote it {0} -> {};
> + int i, key_len, trunc_len, err = 0;
> + struct nfp_ipsec_cfg_add_sa *cfg;
> + struct nfp_net *nn;
> + unsigned int saidx;
> + __be32 *p;
<...>
> + if (trunc_len == 96)
> + cfg->ctrl_word.hash = NFP_IPSEC_HASH_MD5_96;
> + else if (trunc_len == 128)
> + cfg->ctrl_word.hash = NFP_IPSEC_HASH_MD5_128;
> + else
> + trunc_len = 0;
IMHO, this is better to write as switch-case in separate function.
> + break;
> + case SADB_AALG_SHA1HMAC:
> + if (trunc_len == 96)
> + cfg->ctrl_word.hash = NFP_IPSEC_HASH_SHA1_96;
> + else if (trunc_len == 80)
> + cfg->ctrl_word.hash = NFP_IPSEC_HASH_SHA1_80;
> + else
> + trunc_len = 0;
> + break;
Ditto.
> + case SADB_X_AALG_SHA2_256HMAC:
> + if (trunc_len == 96)
> + cfg->ctrl_word.hash = NFP_IPSEC_HASH_SHA256_96;
> + else if (trunc_len == 128)
> + cfg->ctrl_word.hash = NFP_IPSEC_HASH_SHA256_128;
> + else
> + trunc_len = 0;
> + break;
> + case SADB_X_AALG_SHA2_384HMAC:
> + if (trunc_len == 96)
> + cfg->ctrl_word.hash = NFP_IPSEC_HASH_SHA384_96;
> + else if (trunc_len == 192)
> + cfg->ctrl_word.hash = NFP_IPSEC_HASH_SHA384_192;
> + else
> + trunc_len = 0;
> + break;
> + case SADB_X_AALG_SHA2_512HMAC:
> + if (trunc_len == 96)
> + cfg->ctrl_word.hash = NFP_IPSEC_HASH_SHA512_96;
> + else if (trunc_len == 256)
> + cfg->ctrl_word.hash = NFP_IPSEC_HASH_SHA512_256;
> + else
> + trunc_len = 0;
> + break;
> + default:
> + nn_err(nn, "Unsupported authentication algorithm\n");
> + return -EINVAL;
> + }
> +
> + if (!trunc_len) {
> + nn_err(nn, "Unsupported authentication algorithm trunc length\n");
> + return -EINVAL;
> + }
> +
> + if (x->aalg) {
> + p = (__be32 *)x->aalg->alg_key;
> + key_len = DIV_ROUND_UP(x->aalg->alg_key_len, BITS_PER_BYTE);
> + if (key_len > sizeof(cfg->auth_key)) {
> + nn_err(nn, "Insufficient space for offloaded auth key\n");
> + return -EINVAL;
> + }
> + for (i = 0; i < key_len / sizeof(cfg->auth_key[0]) ; i++)
> + cfg->auth_key[i] = ntohl(*p++);
I wonder if you can't declare p as u32 and use memcpy here instead of
u32->__be32->u32 conversions.
Thanks
next prev parent reply other threads:[~2022-11-06 19:48 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-11-01 11:02 [PATCH net-next v3 0/3] nfp: IPsec offload support Simon Horman
2022-11-01 11:02 ` [PATCH net-next v3 1/3] nfp: extend capability and control words Simon Horman
2022-11-06 19:39 ` Leon Romanovsky
2022-11-01 11:02 ` [PATCH net-next v3 2/3] nfp: add framework to support ipsec offloading Simon Horman
2022-11-06 19:39 ` Leon Romanovsky
2022-11-01 11:02 ` [PATCH net-next v3 3/3] nfp: implement xfrm callbacks and expose ipsec offload feature to upper layer Simon Horman
2022-11-06 19:48 ` Leon Romanovsky [this message]
2022-11-07 9:50 ` Yinjun Zhang
2022-11-07 6:14 ` Leon Romanovsky
2022-11-07 9:46 ` Yinjun Zhang
2022-11-07 12:40 ` Leon Romanovsky
2022-11-08 1:28 ` Yinjun Zhang
2022-11-08 18:42 ` Leon Romanovsky
2022-11-09 6:51 ` Yinjun Zhang
2022-11-09 6:58 ` Yinjun Zhang
2022-11-09 8:26 ` Leon Romanovsky
2022-11-09 12:09 ` Yinjun Zhang
2022-11-09 12:24 ` Leon Romanovsky
2022-11-04 3:48 ` [PATCH net-next v3 0/3] nfp: IPsec offload support Jakub Kicinski
2022-11-05 15:27 ` Steffen Klassert
2022-11-05 17:25 ` Leon Romanovsky
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=Y2gPelnt3xfgDGYd@unreal \
--to=leon@kernel.org \
--cc=chengtian.liu@corigine.com \
--cc=davem@davemloft.net \
--cc=herbert@gondor.apana.org.au \
--cc=huanhuan.wang@corigine.com \
--cc=kuba@kernel.org \
--cc=louis.peens@corigine.com \
--cc=netdev@vger.kernel.org \
--cc=oss-drivers@corigine.com \
--cc=pabeni@redhat.com \
--cc=simon.horman@corigine.com \
--cc=steffen.klassert@secunet.com \
--cc=yinjun.zhang@corigine.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).