From: Akhil Goyal <akhil.goyal@nxp.com>
To: dev@dpdk.org
Cc: hemant.agrawal@nxp.com, konstantin.ananyev@intel.com,
Akhil Goyal <akhil.goyal@nxp.com>
Subject: [dpdk-dev] [PATCH 2/3] crypto/dpaa2_sec: support IPv6 tunnel for protocol offload
Date: Mon, 5 Aug 2019 11:08:26 +0530 [thread overview]
Message-ID: <20190805053827.29066-2-akhil.goyal@nxp.com> (raw)
In-Reply-To: <20190805053827.29066-1-akhil.goyal@nxp.com>
outer IP header is formed at the time of session initialization
using the ipsec xform. This outer IP header will be appended by
hardware for each packet.
Signed-off-by: Akhil Goyal <akhil.goyal@nxp.com>
---
drivers/crypto/dpaa2_sec/dpaa2_sec_dpseci.c | 71 +++++++++++++++------
drivers/crypto/dpaa2_sec/dpaa2_sec_priv.h | 6 ++
2 files changed, 57 insertions(+), 20 deletions(-)
diff --git a/drivers/crypto/dpaa2_sec/dpaa2_sec_dpseci.c b/drivers/crypto/dpaa2_sec/dpaa2_sec_dpseci.c
index 26458e5d1..f1cc86812 100644
--- a/drivers/crypto/dpaa2_sec/dpaa2_sec_dpseci.c
+++ b/drivers/crypto/dpaa2_sec/dpaa2_sec_dpseci.c
@@ -9,6 +9,7 @@
#include <net/if.h>
#include <unistd.h>
+#include <rte_ip.h>
#include <rte_mbuf.h>
#include <rte_cryptodev.h>
#include <rte_malloc.h>
@@ -2465,23 +2466,9 @@ dpaa2_sec_set_ipsec_session(struct rte_cryptodev *dev,
session->ctxt_type = DPAA2_SEC_IPSEC;
if (ipsec_xform->direction == RTE_SECURITY_IPSEC_SA_DIR_EGRESS) {
- struct ip ip4_hdr;
+ uint8_t *hdr = NULL;
flc->dhr = SEC_FLC_DHR_OUTBOUND;
- ip4_hdr.ip_v = IPVERSION;
- ip4_hdr.ip_hl = 5;
- ip4_hdr.ip_len = rte_cpu_to_be_16(sizeof(ip4_hdr));
- ip4_hdr.ip_tos = ipsec_xform->tunnel.ipv4.dscp;
- ip4_hdr.ip_id = 0;
- ip4_hdr.ip_off = 0;
- ip4_hdr.ip_ttl = ipsec_xform->tunnel.ipv4.ttl;
- ip4_hdr.ip_p = IPPROTO_ESP;
- ip4_hdr.ip_sum = 0;
- ip4_hdr.ip_src = ipsec_xform->tunnel.ipv4.src_ip;
- ip4_hdr.ip_dst = ipsec_xform->tunnel.ipv4.dst_ip;
- ip4_hdr.ip_sum = calc_chksum((uint16_t *)(void *)&ip4_hdr,
- sizeof(struct ip));
-
/* For Sec Proto only one descriptor is required. */
memset(&encap_pdb, 0, sizeof(struct ipsec_encap_pdb));
encap_pdb.options = (IPVERSION << PDBNH_ESP_ENCAP_SHIFT) |
@@ -2490,18 +2477,62 @@ dpaa2_sec_set_ipsec_session(struct rte_cryptodev *dev,
PDBHMO_ESP_ENCAP_DTTL |
PDBHMO_ESP_SNR;
encap_pdb.spi = ipsec_xform->spi;
- encap_pdb.ip_hdr_len = sizeof(struct ip);
-
session->dir = DIR_ENC;
+
+ if (ipsec_xform->tunnel.type ==
+ RTE_SECURITY_IPSEC_TUNNEL_IPV4) {
+ struct ip ip4_hdr;
+
+ encap_pdb.ip_hdr_len = sizeof(struct ip);
+ ip4_hdr.ip_v = IPVERSION;
+ ip4_hdr.ip_hl = 5;
+ ip4_hdr.ip_len = rte_cpu_to_be_16(sizeof(ip4_hdr));
+ ip4_hdr.ip_tos = ipsec_xform->tunnel.ipv4.dscp;
+ ip4_hdr.ip_id = 0;
+ ip4_hdr.ip_off = 0;
+ ip4_hdr.ip_ttl = ipsec_xform->tunnel.ipv4.ttl;
+ ip4_hdr.ip_p = IPPROTO_ESP;
+ ip4_hdr.ip_sum = 0;
+ ip4_hdr.ip_src = ipsec_xform->tunnel.ipv4.src_ip;
+ ip4_hdr.ip_dst = ipsec_xform->tunnel.ipv4.dst_ip;
+ ip4_hdr.ip_sum = calc_chksum((uint16_t *)(void *)
+ &ip4_hdr, sizeof(struct ip));
+ hdr = (uint8_t *)&ip4_hdr;
+ } else if (ipsec_xform->tunnel.type ==
+ RTE_SECURITY_IPSEC_TUNNEL_IPV6) {
+ struct rte_ipv6_hdr ip6_hdr;
+
+ ip6_hdr.vtc_flow = rte_cpu_to_be_32(
+ DPAA2_IPv6_DEFAULT_VTC_FLOW |
+ ((ipsec_xform->tunnel.ipv6.dscp <<
+ IPv6_TC_SHIFT) & IPv6_TC_MASK) |
+ ((ipsec_xform->tunnel.ipv6.flabel <<
+ IPv6_FLOW_SHIFT) & IPv6_FLOW_MASK));
+ /* Payload length will be updated by HW */
+ ip6_hdr.payload_len = 0;
+ ip6_hdr.hop_limits =
+ ipsec_xform->tunnel.ipv6.hlimit;
+ ip6_hdr.proto = (ipsec_xform->proto ==
+ RTE_SECURITY_IPSEC_SA_PROTO_ESP) ?
+ IPPROTO_ESP : IPPROTO_AH;
+ memcpy(&ip6_hdr.src_addr,
+ &ipsec_xform->tunnel.ipv6.src_addr, 16);
+ memcpy(&ip6_hdr.dst_addr,
+ &ipsec_xform->tunnel.ipv6.dst_addr, 16);
+ encap_pdb.ip_hdr_len = sizeof(struct rte_ipv6_hdr);
+ hdr = (uint8_t *)&ip6_hdr;
+ }
bufsize = cnstr_shdsc_ipsec_new_encap(priv->flc_desc[0].desc,
1, 0, SHR_SERIAL, &encap_pdb,
- (uint8_t *)&ip4_hdr,
- &cipherdata, &authdata);
+ hdr, &cipherdata, &authdata);
} else if (ipsec_xform->direction ==
RTE_SECURITY_IPSEC_SA_DIR_INGRESS) {
flc->dhr = SEC_FLC_DHR_INBOUND;
memset(&decap_pdb, 0, sizeof(struct ipsec_decap_pdb));
- decap_pdb.options = sizeof(struct ip) << 16;
+ decap_pdb.options = (ipsec_xform->tunnel.type ==
+ RTE_SECURITY_IPSEC_TUNNEL_IPV4) ?
+ sizeof(struct ip) << 16 :
+ sizeof(struct rte_ipv6_hdr) << 16;
session->dir = DIR_DEC;
bufsize = cnstr_shdsc_ipsec_new_decap(priv->flc_desc[0].desc,
1, 0, SHR_SERIAL,
diff --git a/drivers/crypto/dpaa2_sec/dpaa2_sec_priv.h b/drivers/crypto/dpaa2_sec/dpaa2_sec_priv.h
index 51751103d..2a446be30 100644
--- a/drivers/crypto/dpaa2_sec/dpaa2_sec_priv.h
+++ b/drivers/crypto/dpaa2_sec/dpaa2_sec_priv.h
@@ -41,6 +41,12 @@ enum shr_desc_type {
#define DIR_ENC 1
#define DIR_DEC 0
+#define DPAA2_IPv6_DEFAULT_VTC_FLOW 0x60000000
+#define IPv6_TC_SHIFT 20
+#define IPv6_FLOW_SHIFT 0
+#define IPv6_TC_MASK 0x0FF00000
+#define IPv6_FLOW_MASK 0x000FFFFF
+
#define DPAA2_SET_FLC_EWS(flc) (flc->word1_bits23_16 |= 0x1)
#define DPAA2_SET_FLC_RSC(flc) (flc->word1_bits31_24 |= 0x1)
#define DPAA2_SET_FLC_REUSE_BS(flc) (flc->mode_bits |= 0x8000)
--
2.17.1
next prev parent reply other threads:[~2019-08-05 5:52 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-08-05 5:38 [dpdk-dev] [PATCH 1/3] crypto/dpaa_sec: " Akhil Goyal
2019-08-05 5:38 ` Akhil Goyal [this message]
2019-08-05 5:38 ` [dpdk-dev] [PATCH 3/3] examples/ipsec-secgw: support IPv6 tunnel for lookaside proto Akhil Goyal
2019-08-05 7:26 ` [dpdk-dev] [PATCH 1/3] crypto/dpaa_sec: support IPv6 tunnel for protocol offload Akhil Goyal
2019-08-05 8:22 ` [dpdk-dev] [PATCH v2 0/3] support IPv6 tunnel for lookaside crypto Akhil Goyal
2019-08-05 8:22 ` [dpdk-dev] [PATCH v2 1/3] crypto/dpaa_sec: support IPv6 tunnel for protocol offload Akhil Goyal
2019-08-05 8:22 ` [dpdk-dev] [PATCH v2 2/3] crypto/dpaa2_sec: " Akhil Goyal
2019-08-05 8:22 ` [dpdk-dev] [PATCH v2 3/3] examples/ipsec-secgw: support IPv6 tunnel for lookaside proto Akhil Goyal
2019-09-05 12:48 ` [dpdk-dev] [PATCH v3 0/3] support IPv6 tunnel for lookaside crypto Akhil Goyal
2019-09-05 12:48 ` [dpdk-dev] [PATCH v3 1/3] crypto/dpaa_sec: support IPv6 tunnel for protocol offload Akhil Goyal
2019-09-05 12:48 ` [dpdk-dev] [PATCH v3 2/3] crypto/dpaa2_sec: " Akhil Goyal
2019-09-05 12:48 ` [dpdk-dev] [PATCH v3 3/3] examples/ipsec-secgw: support IPv6 tunnel for lookaside proto Akhil Goyal
2019-09-19 15:17 ` Akhil Goyal
2019-09-24 11:25 ` Ananyev, Konstantin
2019-09-27 14:16 ` [dpdk-dev] [PATCH v3 0/3] support IPv6 tunnel for lookaside crypto Akhil Goyal
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=20190805053827.29066-2-akhil.goyal@nxp.com \
--to=akhil.goyal@nxp.com \
--cc=dev@dpdk.org \
--cc=hemant.agrawal@nxp.com \
--cc=konstantin.ananyev@intel.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).