DPDK patches and discussions
 help / color / mirror / Atom feed
From: Hemant Agrawal <hemant.agrawal@oss.nxp.com>
To: Jiawen Wu <jiawenwu@trustnetic.com>,
	dev@dpdk.org, "gakhil@marvell.com" <gakhil@marvell.com>
Subject: Re: [dpdk-dev] [PATCH 28/32] net/ngbe: add IPsec context creation
Date: Thu, 16 Sep 2021 14:34:48 +0530	[thread overview]
Message-ID: <c651c92e-5020-14f0-80b1-3073637af4bb@oss.nxp.com> (raw)
In-Reply-To: <20210908083758.312055-29-jiawenwu@trustnetic.com>


On 9/8/2021 2:07 PM, Jiawen Wu wrote:
> Initialize securiry context, and support to get security
> capabilities.
>
> Signed-off-by: Jiawen Wu <jiawenwu@trustnetic.com>
> ---
>   doc/guides/nics/features/ngbe.ini |   1 +
>   drivers/net/ngbe/meson.build      |   3 +-
>   drivers/net/ngbe/ngbe_ethdev.c    |  10 ++
>   drivers/net/ngbe/ngbe_ethdev.h    |   4 +
>   drivers/net/ngbe/ngbe_ipsec.c     | 178 ++++++++++++++++++++++++++++++
>   5 files changed, 195 insertions(+), 1 deletion(-)
>   create mode 100644 drivers/net/ngbe/ngbe_ipsec.c
>
> diff --git a/doc/guides/nics/features/ngbe.ini b/doc/guides/nics/features/ngbe.ini
> index 56d5d71ea8..facdb5f006 100644
> --- a/doc/guides/nics/features/ngbe.ini
> +++ b/doc/guides/nics/features/ngbe.ini
> @@ -23,6 +23,7 @@ RSS reta update      = Y
>   SR-IOV               = Y
>   VLAN filter          = Y
>   Flow control         = Y
> +Inline crypto        = Y
>   CRC offload          = P
>   VLAN offload         = P
>   QinQ offload         = P
> diff --git a/drivers/net/ngbe/meson.build b/drivers/net/ngbe/meson.build
> index b276ec3341..f222595b19 100644
> --- a/drivers/net/ngbe/meson.build
> +++ b/drivers/net/ngbe/meson.build
> @@ -12,12 +12,13 @@ objs = [base_objs]
>   
>   sources = files(
>           'ngbe_ethdev.c',
> +        'ngbe_ipsec.c',

Ideally you shall be creating a crypto/security driver and have your 
ipsec related functions there.

@akhil - what is your opinion here?


>           'ngbe_ptypes.c',
>           'ngbe_pf.c',
>           'ngbe_rxtx.c',
>   )
>   
> -deps += ['hash']
> +deps += ['hash', 'security']
>   
>   includes += include_directories('base')
>   
> diff --git a/drivers/net/ngbe/ngbe_ethdev.c b/drivers/net/ngbe/ngbe_ethdev.c
> index 4eaf9b0724..b0e0f7411e 100644
> --- a/drivers/net/ngbe/ngbe_ethdev.c
> +++ b/drivers/net/ngbe/ngbe_ethdev.c
> @@ -430,6 +430,12 @@ eth_ngbe_dev_init(struct rte_eth_dev *eth_dev, void *init_params __rte_unused)
>   	/* Unlock any pending hardware semaphore */
>   	ngbe_swfw_lock_reset(hw);
>   
> +#ifdef RTE_LIB_SECURITY
> +	/* Initialize security_ctx only for primary process*/
> +	if (ngbe_ipsec_ctx_create(eth_dev))
> +		return -ENOMEM;
> +#endif
> +
>   	/* Get Hardware Flow Control setting */
>   	hw->fc.requested_mode = ngbe_fc_full;
>   	hw->fc.current_mode = ngbe_fc_full;
> @@ -1282,6 +1288,10 @@ ngbe_dev_close(struct rte_eth_dev *dev)
>   	rte_free(dev->data->hash_mac_addrs);
>   	dev->data->hash_mac_addrs = NULL;
>   
> +#ifdef RTE_LIB_SECURITY
> +	rte_free(dev->security_ctx);
> +#endif
> +
>   	return ret;
>   }
>   
> diff --git a/drivers/net/ngbe/ngbe_ethdev.h b/drivers/net/ngbe/ngbe_ethdev.h
> index aacc0b68b2..9eda024d65 100644
> --- a/drivers/net/ngbe/ngbe_ethdev.h
> +++ b/drivers/net/ngbe/ngbe_ethdev.h
> @@ -264,6 +264,10 @@ void ngbe_pf_mbx_process(struct rte_eth_dev *eth_dev);
>   
>   int ngbe_pf_host_configure(struct rte_eth_dev *eth_dev);
>   
> +#ifdef RTE_LIB_SECURITY
> +int ngbe_ipsec_ctx_create(struct rte_eth_dev *dev);
> +#endif
> +
>   /* High threshold controlling when to start sending XOFF frames. */
>   #define NGBE_FC_XOFF_HITH              128 /*KB*/
>   /* Low threshold controlling when to start sending XON frames. */
> diff --git a/drivers/net/ngbe/ngbe_ipsec.c b/drivers/net/ngbe/ngbe_ipsec.c
> new file mode 100644
> index 0000000000..5f8b0bab29
> --- /dev/null
> +++ b/drivers/net/ngbe/ngbe_ipsec.c
> @@ -0,0 +1,178 @@
> +/* SPDX-License-Identifier: BSD-3-Clause
> + * Copyright(c) 2018-2021 Beijing WangXun Technology Co., Ltd.
> + * Copyright(c) 2010-2017 Intel Corporation
> + */
> +
> +#include <ethdev_pci.h>
> +#include <rte_security_driver.h>
> +#include <rte_cryptodev.h>
> +
> +#include "base/ngbe.h"
> +#include "ngbe_ethdev.h"
> +
> +static const struct rte_security_capability *
> +ngbe_crypto_capabilities_get(void *device __rte_unused)
> +{
> +	static const struct rte_cryptodev_capabilities
> +	aes_gcm_gmac_crypto_capabilities[] = {
> +		{	/* AES GMAC (128-bit) */
> +			.op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
> +			{.sym = {
> +				.xform_type = RTE_CRYPTO_SYM_XFORM_AUTH,
> +				{.auth = {
> +					.algo = RTE_CRYPTO_AUTH_AES_GMAC,
> +					.block_size = 16,
> +					.key_size = {
> +						.min = 16,
> +						.max = 16,
> +						.increment = 0
> +					},
> +					.digest_size = {
> +						.min = 16,
> +						.max = 16,
> +						.increment = 0
> +					},
> +					.iv_size = {
> +						.min = 12,
> +						.max = 12,
> +						.increment = 0
> +					}
> +				}, }
> +			}, }
> +		},
> +		{	/* AES GCM (128-bit) */
> +			.op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
> +			{.sym = {
> +				.xform_type = RTE_CRYPTO_SYM_XFORM_AEAD,
> +				{.aead = {
> +					.algo = RTE_CRYPTO_AEAD_AES_GCM,
> +					.block_size = 16,
> +					.key_size = {
> +						.min = 16,
> +						.max = 16,
> +						.increment = 0
> +					},
> +					.digest_size = {
> +						.min = 16,
> +						.max = 16,
> +						.increment = 0
> +					},
> +					.aad_size = {
> +						.min = 0,
> +						.max = 65535,
> +						.increment = 1
> +					},
> +					.iv_size = {
> +						.min = 12,
> +						.max = 12,
> +						.increment = 0
> +					}
> +				}, }
> +			}, }
> +		},
> +		{
> +			.op = RTE_CRYPTO_OP_TYPE_UNDEFINED,
> +			{.sym = {
> +				.xform_type = RTE_CRYPTO_SYM_XFORM_NOT_SPECIFIED
> +			}, }
> +		},
> +	};
> +
> +	static const struct rte_security_capability
> +	ngbe_security_capabilities[] = {
> +		{ /* IPsec Inline Crypto ESP Transport Egress */
> +			.action = RTE_SECURITY_ACTION_TYPE_INLINE_CRYPTO,
> +			.protocol = RTE_SECURITY_PROTOCOL_IPSEC,
> +			{.ipsec = {
> +				.proto = RTE_SECURITY_IPSEC_SA_PROTO_ESP,
> +				.mode = RTE_SECURITY_IPSEC_SA_MODE_TRANSPORT,
> +				.direction = RTE_SECURITY_IPSEC_SA_DIR_EGRESS,
> +				.options = { 0 }
> +			} },
> +			.crypto_capabilities = aes_gcm_gmac_crypto_capabilities,
> +			.ol_flags = RTE_SECURITY_TX_OLOAD_NEED_MDATA
> +		},
> +		{ /* IPsec Inline Crypto ESP Transport Ingress */
> +			.action = RTE_SECURITY_ACTION_TYPE_INLINE_CRYPTO,
> +			.protocol = RTE_SECURITY_PROTOCOL_IPSEC,
> +			{.ipsec = {
> +				.proto = RTE_SECURITY_IPSEC_SA_PROTO_ESP,
> +				.mode = RTE_SECURITY_IPSEC_SA_MODE_TRANSPORT,
> +				.direction = RTE_SECURITY_IPSEC_SA_DIR_INGRESS,
> +				.options = { 0 }
> +			} },
> +			.crypto_capabilities = aes_gcm_gmac_crypto_capabilities,
> +			.ol_flags = 0
> +		},
> +		{ /* IPsec Inline Crypto ESP Tunnel Egress */
> +			.action = RTE_SECURITY_ACTION_TYPE_INLINE_CRYPTO,
> +			.protocol = RTE_SECURITY_PROTOCOL_IPSEC,
> +			{.ipsec = {
> +				.proto = RTE_SECURITY_IPSEC_SA_PROTO_ESP,
> +				.mode = RTE_SECURITY_IPSEC_SA_MODE_TUNNEL,
> +				.direction = RTE_SECURITY_IPSEC_SA_DIR_EGRESS,
> +				.options = { 0 }
> +			} },
> +			.crypto_capabilities = aes_gcm_gmac_crypto_capabilities,
> +			.ol_flags = RTE_SECURITY_TX_OLOAD_NEED_MDATA
> +		},
> +		{ /* IPsec Inline Crypto ESP Tunnel Ingress */
> +			.action = RTE_SECURITY_ACTION_TYPE_INLINE_CRYPTO,
> +			.protocol = RTE_SECURITY_PROTOCOL_IPSEC,
> +			{.ipsec = {
> +				.proto = RTE_SECURITY_IPSEC_SA_PROTO_ESP,
> +				.mode = RTE_SECURITY_IPSEC_SA_MODE_TUNNEL,
> +				.direction = RTE_SECURITY_IPSEC_SA_DIR_INGRESS,
> +				.options = { 0 }
> +			} },
> +			.crypto_capabilities = aes_gcm_gmac_crypto_capabilities,
> +			.ol_flags = 0
> +		},
> +		{
> +			.action = RTE_SECURITY_ACTION_TYPE_NONE
> +		}
> +	};
> +
> +	return ngbe_security_capabilities;
> +}
> +
> +static struct rte_security_ops ngbe_security_ops = {
> +	.capabilities_get = ngbe_crypto_capabilities_get
> +};
> +
> +static int
> +ngbe_crypto_capable(struct rte_eth_dev *dev)
> +{
> +	struct ngbe_hw *hw = ngbe_dev_hw(dev);
> +	uint32_t reg_i, reg, capable = 1;
> +	/* test if rx crypto can be enabled and then write back initial value*/
> +	reg_i = rd32(hw, NGBE_SECRXCTL);
> +	wr32m(hw, NGBE_SECRXCTL, NGBE_SECRXCTL_ODSA, 0);
> +	reg = rd32m(hw, NGBE_SECRXCTL, NGBE_SECRXCTL_ODSA);
> +	if (reg != 0)
> +		capable = 0;
> +	wr32(hw, NGBE_SECRXCTL, reg_i);
> +	return capable;
> +}
> +
> +int
> +ngbe_ipsec_ctx_create(struct rte_eth_dev *dev)
> +{
> +	struct rte_security_ctx *ctx = NULL;
> +
> +	if (ngbe_crypto_capable(dev)) {
> +		ctx = rte_malloc("rte_security_instances_ops",
> +				 sizeof(struct rte_security_ctx), 0);
> +		if (ctx) {
> +			ctx->device = (void *)dev;
> +			ctx->ops = &ngbe_security_ops;
> +			ctx->sess_cnt = 0;
> +			dev->security_ctx = ctx;
> +		} else {
> +			return -ENOMEM;
> +		}
> +	}
> +	if (rte_security_dynfield_register() < 0)
> +		return -rte_errno;
> +	return 0;
> +}

  parent reply	other threads:[~2021-09-16  9:04 UTC|newest]

Thread overview: 54+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-09-08  8:37 [dpdk-dev] [PATCH 00/32] net/ngbe: add many features Jiawen Wu
2021-09-08  8:37 ` [dpdk-dev] [PATCH 01/32] net/ngbe: add packet type Jiawen Wu
2021-09-15 16:47   ` Ferruh Yigit
2021-09-22  8:01     ` Jiawen Wu
2021-09-08  8:37 ` [dpdk-dev] [PATCH 02/32] net/ngbe: support scattered Rx Jiawen Wu
2021-09-15 13:22   ` Ferruh Yigit
2021-09-08  8:37 ` [dpdk-dev] [PATCH 03/32] net/ngbe: support Rx checksum offload Jiawen Wu
2021-09-15 16:48   ` Ferruh Yigit
2021-09-08  8:37 ` [dpdk-dev] [PATCH 04/32] net/ngbe: support TSO Jiawen Wu
2021-09-15 16:57   ` Ferruh Yigit
2021-09-08  8:37 ` [dpdk-dev] [PATCH 05/32] net/ngbe: support CRC offload Jiawen Wu
2021-09-15 16:48   ` Ferruh Yigit
2021-09-08  8:37 ` [dpdk-dev] [PATCH 06/32] net/ngbe: support jumbo frame Jiawen Wu
2021-09-15 16:48   ` Ferruh Yigit
2021-09-08  8:37 ` [dpdk-dev] [PATCH 07/32] net/ngbe: support VLAN and QinQ offload Jiawen Wu
2021-09-08  8:37 ` [dpdk-dev] [PATCH 08/32] net/ngbe: support basic statistics Jiawen Wu
2021-09-15 16:50   ` Ferruh Yigit
2021-10-14  2:51     ` Jiawen Wu
2021-10-14  7:59       ` Ferruh Yigit
2021-09-08  8:37 ` [dpdk-dev] [PATCH 09/32] net/ngbe: support device xstats Jiawen Wu
2021-09-08  8:37 ` [dpdk-dev] [PATCH 10/32] net/ngbe: support MTU set Jiawen Wu
2021-09-15 16:52   ` Ferruh Yigit
2021-09-08  8:37 ` [dpdk-dev] [PATCH 11/32] net/ngbe: add device promiscuous and allmulticast mode Jiawen Wu
2021-09-08  8:37 ` [dpdk-dev] [PATCH 12/32] net/ngbe: support getting FW version Jiawen Wu
2021-09-15 16:53   ` Ferruh Yigit
2021-09-08  8:37 ` [dpdk-dev] [PATCH 13/32] net/ngbe: add loopback mode Jiawen Wu
2021-09-08  8:37 ` [dpdk-dev] [PATCH 14/32] net/ngbe: support Rx interrupt Jiawen Wu
2021-09-15 16:53   ` Ferruh Yigit
2021-10-14 10:11     ` Jiawen Wu
2021-09-08  8:37 ` [dpdk-dev] [PATCH 15/32] net/ngbe: support MAC filters Jiawen Wu
2021-09-08  8:37 ` [dpdk-dev] [PATCH 16/32] net/ngbe: support VLAN filter Jiawen Wu
2021-09-15 16:54   ` Ferruh Yigit
2021-09-08  8:37 ` [dpdk-dev] [PATCH 17/32] net/ngbe: support RSS hash Jiawen Wu
2021-09-08  8:37 ` [dpdk-dev] [PATCH 18/32] net/ngbe: support SRIOV Jiawen Wu
2021-09-08  8:37 ` [dpdk-dev] [PATCH 19/32] net/ngbe: add mailbox process operations Jiawen Wu
2021-09-15 16:56   ` Ferruh Yigit
2021-09-08  8:37 ` [dpdk-dev] [PATCH 20/32] net/ngbe: support flow control Jiawen Wu
2021-09-08  8:37 ` [dpdk-dev] [PATCH 21/32] net/ngbe: support device LED on and off Jiawen Wu
2021-09-08  8:37 ` [dpdk-dev] [PATCH 22/32] net/ngbe: support EEPROM dump Jiawen Wu
2021-09-08  8:37 ` [dpdk-dev] [PATCH 23/32] net/ngbe: support register dump Jiawen Wu
2021-09-08  8:37 ` [dpdk-dev] [PATCH 24/32] net/ngbe: support timesync Jiawen Wu
2021-09-08  8:37 ` [dpdk-dev] [PATCH 25/32] net/ngbe: add Rx and Tx queue info get Jiawen Wu
2021-09-08  8:37 ` [dpdk-dev] [PATCH 26/32] net/ngbe: add Rx and Tx descriptor status Jiawen Wu
2021-09-08  8:37 ` [dpdk-dev] [PATCH 27/32] net/ngbe: add Tx done cleanup Jiawen Wu
2021-09-08  8:37 ` [dpdk-dev] [PATCH 28/32] net/ngbe: add IPsec context creation Jiawen Wu
2021-09-15 16:58   ` Ferruh Yigit
2021-09-16  9:00     ` Hemant Agrawal
2021-09-16 17:15       ` Ferruh Yigit
2021-09-16  9:04   ` Hemant Agrawal [this message]
2021-09-08  8:37 ` [dpdk-dev] [PATCH 29/32] net/ngbe: create and destroy security session Jiawen Wu
2021-09-08  8:37 ` [dpdk-dev] [PATCH 30/32] net/ngbe: support security operations Jiawen Wu
2021-09-08  8:37 ` [dpdk-dev] [PATCH 31/32] net/ngbe: add security offload in Rx and Tx Jiawen Wu
2021-09-08  8:37 ` [dpdk-dev] [PATCH 32/32] doc: update for ngbe Jiawen Wu
2021-09-15 16:58   ` Ferruh Yigit

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=c651c92e-5020-14f0-80b1-3073637af4bb@oss.nxp.com \
    --to=hemant.agrawal@oss.nxp.com \
    --cc=dev@dpdk.org \
    --cc=gakhil@marvell.com \
    --cc=hemant.agrawal@nxp.com \
    --cc=jiawenwu@trustnetic.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).