Skip to contentSkip to conversation

security: support MACsec

PATCH Superseded Akhil Goyal 7 participants 166 messages Aug 14, 2022 – Jun 15, 2023 Page 1 of 2

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

cover security: support MACsec

Added support for MACsec in rte_security for offloading MACsec Protocol operation to inline NIC device or a crypto device.

To support MACsec we cannot just make one security session and send with the packet to process it. MACsec specifications suggest, it can have 3 different entities - SECY Entity, SC(secure channel) and SA(security association). And same SA can be used by multiple SCs and similarly many SECY can have same SCs. Hence, in order to support this many to one relationships between all entities, 2 new APIs are created - rte_security_macsec_sc_create and rte_security_sa_create. Flow of execution of the APIs would be as
- rte_security_macsec_sa_create
- rte_security_macsec_sc_create
- rte_security_session_create(for secy)
And in case of inline protocol processing rte_flow can be created with rte_security action similar to IPsec flows except that the flow item will be MACsec instead of IPsec.

A new flow item is added for MACsec header and a set of events are added to specify the errors occurred during inline protocol processing.

New APIs are also created for getting SC and SA stats.

Akhil Goyal (3):
net: add MACsec header
security: support MACsec
ethdev: add MACsec flow item

 doc/api/doxy-api-index.md              |   3 +-
 doc/guides/prog_guide/rte_security.rst | 107 +++++++-
 lib/ethdev/rte_ethdev.h                |  55 ++++
 lib/ethdev/rte_flow.h                  |  18 ++
 lib/net/meson.build                    |   1 +
 lib/net/rte_macsec.h                   |  56 ++++
 lib/security/rte_security.c            |  86 ++++++
 lib/security/rte_security.h            | 362 ++++++++++++++++++++++++-
 lib/security/rte_security_driver.h     |  86 ++++++
 lib/security/version.map               |   6 +
 10 files changed, 766 insertions(+), 14 deletions(-)
 create mode 100644 lib/net/rte_macsec.h
Signature · 1 line
2.25.1
#1 lore raw

PATCH 1/3 net: add MACsec header

Added MACsec protocol header to be used for supporting MACsec protocol offload in hardware or directly in the application.

---
 doc/api/doxy-api-index.md |  3 ++-
 lib/net/meson.build       |  1 +
 lib/net/rte_macsec.h      | 56 +++++++++++++++++++++++++++++++++++++++
 3 files changed, 59 insertions(+), 1 deletion(-)
 create mode 100644 lib/net/rte_macsec.h
doc/api/doxy-api-index.md +2 -1
index 186a258be4..99e49340d3 100644
@@ -126,7 +126,8 @@ The public API headers are grouped by topics:
   [Geneve](@ref rte_geneve.h),
   [eCPRI](@ref rte_ecpri.h),
   [L2TPv2](@ref rte_l2tpv2.h),
-  [PPP](@ref rte_ppp.h)
+  [PPP](@ref rte_ppp.h),
+  [MACsec](@ref rte_macsec.h)
 
 - **QoS**:
   [metering](@ref rte_meter.h),
lib/net/meson.build +1 -0
index e899846578..3e63abaca8 100644
@@ -21,6 +21,7 @@ headers = files(
         'rte_geneve.h',
         'rte_l2tpv2.h',
         'rte_ppp.h',
+        'rte_macsec.h',
 )
 
 sources = files(
lib/net/rte_macsec.h new file +56 -0

56 lines not on this page · raw message

Signature · 1 line
2.25.1
#2 lore raw

RE: [PATCH 1/3] net: add MACsec header

Hi Olivier,

Could you please review this patch?
Apologies. I missed to add you earlier.

Regards,
Akhil

Quoted 110 lines

Subject: [PATCH 1/3] net: add MACsec header

Added MACsec protocol header to be used for supporting MACsec protocol offload in hardware or directly in the application.

---
 doc/api/doxy-api-index.md |  3 ++-
 lib/net/meson.build       |  1 +
 lib/net/rte_macsec.h      | 56 +++++++++++++++++++++++++++++++++++++++
 3 files changed, 59 insertions(+), 1 deletion(-)
 create mode 100644 lib/net/rte_macsec.h
doc/api/doxy-api-index.md +2 -1
index 186a258be4..99e49340d3 100644
@@ -126,7 +126,8 @@ The public API headers are grouped by topics:
   [Geneve](@ref rte_geneve.h),
   [eCPRI](@ref rte_ecpri.h),
   [L2TPv2](@ref rte_l2tpv2.h),
-  [PPP](@ref rte_ppp.h)
+  [PPP](@ref rte_ppp.h),
+  [MACsec](@ref rte_macsec.h)
 
 - **QoS**:
   [metering](@ref rte_meter.h),
lib/net/meson.build +1 -0
index e899846578..3e63abaca8 100644
@@ -21,6 +21,7 @@ headers = files(
         'rte_geneve.h',
         'rte_l2tpv2.h',
         'rte_ppp.h',
+        'rte_macsec.h',
 )
 
 sources = files(
lib/net/rte_macsec.h new file +25 -0
new file mode 100644
index 0000000000..f1b59253f6
@@ -0,0 +1,56 @@
+/* SPDX-License-Identifier: BSD-3-Clause
+ * Copyright(C) 2022 Marvell.
+ */
+
+#ifndef _RTE_MACSEC_H_
+#define _RTE_MACSEC_H_
+
+/**
+ * @file
+ *
+ * MACsec-related defines
+ */
+
+#include <rte_byteorder.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+
+/* SecTAG length = macsec ether header without the optional SCI */
+#define RTE_MACSEC_TAG_LEN 6
+#define RTE_MACSEC_SCI_LEN 8
+
+#define RTE_MACSEC_TCI_VERSION	0x80 /**< Version mask for MACsec.

Should be 0. */

lib/net/rte_macsec.h new file +3 -0
+#define RTE_MACSEC_TCI_ES	0x40 /**< End station - SCI is not valid */
+#define RTE_MACSEC_TCI_SC	0x20 /**< SCI present */
+#define RTE_MACSEC_TCI_SCB	0x10 /**< Secure channel support EPON single

copy broadcast */

lib/net/rte_macsec.h new file +2 -0
+#define RTE_MACSEC_TCI_E	0x08 /**< User data is encrypted */
+#define RTE_MACSEC_TCI_C	0x04 /**< User data was changed (because of

encryption) */
+#define RTE_MACSEC_AN_MASK 0x03 /**< Association number mask in
tci_an */
+#define RTE_MACSEC_NUM_AN 4 /**< 2 bits for the association
number */

lib/net/rte_macsec.h new file +8 -0
+#define RTE_MACSEC_SALT_LEN	12   /**< Salt length for MACsec SA */
+
+/**
+ * MACsec Header
+ */
+struct rte_macsec_hdr {
+	/* SecTAG */
+	uint8_t  tci_an;	/**< Tag control information and Association number

of SC */

lib/net/rte_macsec.h new file +8 -0
+#if RTE_BYTE_ORDER == RTE_LITTLE_ENDIAN
+	uint8_t short_length : 6; /**< Short Length */
+	uint8_t unused : 2;
+#elif RTE_BYTE_ORDER == RTE_BIG_ENDIAN
+	uint8_t unused : 2;
+	uint8_t short_length : 6;
+#endif
+	rte_be32_t packet_number; /**< Packet number to support replay

protection */

lib/net/rte_macsec.h new file +8 -1
+	uint8_t secure_channel_id[8]; /* optional */
+} __rte_packed;
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* RTE_MACSEC_H_ */
--

2.25.1

#3 lore raw

Re: [PATCH 1/3] net: add MACsec header

In reply to Akhil Goyal

Hi Akhil,

Few comments below.

Quoted 55 lines · Akhil Goyal

Added MACsec protocol header to be used for supporting MACsec protocol offload in hardware or directly in the application.

---
 doc/api/doxy-api-index.md |  3 ++-
 lib/net/meson.build       |  1 +
 lib/net/rte_macsec.h      | 56 +++++++++++++++++++++++++++++++++++++++
 3 files changed, 59 insertions(+), 1 deletion(-)
 create mode 100644 lib/net/rte_macsec.h
doc/api/doxy-api-index.md +2 -1
index 186a258be4..99e49340d3 100644
@@ -126,7 +126,8 @@ The public API headers are grouped by topics:
   [Geneve](@ref rte_geneve.h),
   [eCPRI](@ref rte_ecpri.h),
   [L2TPv2](@ref rte_l2tpv2.h),
-  [PPP](@ref rte_ppp.h)
+  [PPP](@ref rte_ppp.h),
+  [MACsec](@ref rte_macsec.h)
 
 - **QoS**:
   [metering](@ref rte_meter.h),
lib/net/meson.build +1 -0
index e899846578..3e63abaca8 100644
@@ -21,6 +21,7 @@ headers = files(
         'rte_geneve.h',
         'rte_l2tpv2.h',
         'rte_ppp.h',
+        'rte_macsec.h',
 )
 
 sources = files(
lib/net/rte_macsec.h new file +12 -0
new file mode 100644
index 0000000000..f1b59253f6
@@ -0,0 +1,56 @@
+/* SPDX-License-Identifier: BSD-3-Clause
+ * Copyright(C) 2022 Marvell.
+ */
+
+#ifndef _RTE_MACSEC_H_
+#define _RTE_MACSEC_H_
+
+/**
+ * @file
+ *
+ * MACsec-related defines
+ */

lib/net/rte_macsec.h line 22

Quoted 10 lines
lib/net/rte_macsec.h new file +10 -0
+
+#include <rte_byteorder.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+
+/* SecTAG length = macsec ether header without the optional SCI */
+#define RTE_MACSEC_TAG_LEN 6

Use a doxygen-like comment.

Is this define required? In my understanding, it is the same as sizeof(struct rte_macsec_hdr).

lib/net/rte_macsec.h line 23

Quoted 1 line
lib/net/rte_macsec.h new file +1 -0
+#define RTE_MACSEC_SCI_LEN 8

Missing doxygen doc.

lib/net/rte_macsec.h line 28

Quoted 5 lines
lib/net/rte_macsec.h new file +5 -0
+
+#define RTE_MACSEC_TCI_VERSION	0x80 /**< Version mask for MACsec. Should be 0. */
+#define RTE_MACSEC_TCI_ES	0x40 /**< End station - SCI is not valid */
+#define RTE_MACSEC_TCI_SC	0x20 /**< SCI present */
+#define RTE_MACSEC_TCI_SCB	0x10 /**< Secure channel support EPON single copy broadcast */

support -> supports?

lib/net/rte_macsec.h line 30

Quoted 2 lines
lib/net/rte_macsec.h new file +2 -0
+#define RTE_MACSEC_TCI_E	0x08 /**< User data is encrypted */
+#define RTE_MACSEC_TCI_C	0x04 /**< User data was changed (because of encryption) */

In [1], I can read the following, which is not similar:

E and C bits used to determine if packet is encrypted
• E, C = 1, 1 – Encrypted
• E, C = 0, 0 – Authenticated-Only

Is there any reference paper for macsec header?

[1] https://www.marvell.com/content/dam/marvell/en/public-collateral/automotive-solutions/marvell-macsec-security-in-ethernet-based-vehicle-white-paper.pdf

lib/net/rte_macsec.h line 31

Quoted 1 line
lib/net/rte_macsec.h new file +1 -0
+#define RTE_MACSEC_AN_MASK	0x03 /**< Association number mask in tci_an */

nit: all comments should end with a dot.

lib/net/rte_macsec.h line 32

Quoted 2 lines
lib/net/rte_macsec.h new file +1 -0
+#define RTE_MACSEC_NUM_AN	4    /**< 2 bits for the association number */

I don't get how this defined is used. Can the comment be clarified?

lib/net/rte_macsec.h line 33

Quoted 1 line
lib/net/rte_macsec.h new file +1 -0
+#define RTE_MACSEC_SALT_LEN	12   /**< Salt length for MACsec SA */

Same here.

lib/net/rte_macsec.h line 39

Quoted 6 lines
lib/net/rte_macsec.h new file +6 -0
+
+/**
+ * MACsec Header
+ */
+struct rte_macsec_hdr {
+	/* SecTAG */

Is the SecTAG comment required? Or maybe it should be moved above the struct?

lib/net/rte_macsec.h line 40

Quoted 1 line
lib/net/rte_macsec.h new file +1 -0
+	uint8_t  tci_an;	/**< Tag control information and Association number of SC */

nit: duplicated spaces after uint8_t

Can we use a bitfield here for tci and an, like you did for short_length?

Like this:

	uint8_t tci:6;
	uint8_t an:2;

Or:

	uint8_t tci_version:1;
	uint8_t tci_es:1;
	uint8_t tci_sc:1;
	uint8_t tci_scb:1;
	uint8_t tci_e:1;
	uint8_t tci_c:1;
	uint8_t an:2;

I think the 2nd one is easier to use.

lib/net/rte_macsec.h line 43

Quoted 3 lines
lib/net/rte_macsec.h new file +3 -0
+#if RTE_BYTE_ORDER == RTE_LITTLE_ENDIAN
+	uint8_t short_length : 6; /**< Short Length */
+	uint8_t unused : 2;

nit: no spaces around ':'

lib/net/rte_macsec.h line 49

Quoted 6 lines
lib/net/rte_macsec.h new file +6 -0
+#elif RTE_BYTE_ORDER == RTE_BIG_ENDIAN
+	uint8_t unused : 2;
+	uint8_t short_length : 6;
+#endif
+	rte_be32_t packet_number; /**< Packet number to support replay protection */
+	uint8_t secure_channel_id[8]; /* optional */

8 -> RTE_MACSEC_SCI_LEN ?

I think it would be more convenient to have another struct for the secure_channel_id.

For instance, this pseudo code:

	struct struct rte_macsec_hdr *hdr = NULL;
	struct struct rte_macsec_sci_hdr *hdr_sci = NULL;

	if (seg_len(mbuf) < sizeof(*hdr))
		return -1;
	if (hdr.tci_sc) {
		if (seg_len(mbuf) < sizeof(*hdr_sci))
			return -1;
		hdr_sci = hdr;
	}

With only one struct, it is difficult to properly do the length check.

Quoted 10 lines
lib/net/rte_macsec.h new file +7 -0
+} __rte_packed;
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* RTE_MACSEC_H_ */
Signature · 1 line
2.25.1

Thanks,
Olivier

#4 lore raw

RE: [EXT] Re: [PATCH 1/3] net: add MACsec header

Hi Olivier,

Thanks for your review. I will fix the issues in next version.

Quoted 207 lines

Hi Akhil,

Few comments below.

Quoted 55 lines · Akhil Goyal

Added MACsec protocol header to be used for supporting MACsec protocol offload in hardware or directly in the application.

---
 doc/api/doxy-api-index.md |  3 ++-
 lib/net/meson.build       |  1 +
 lib/net/rte_macsec.h      | 56 +++++++++++++++++++++++++++++++++++++++
 3 files changed, 59 insertions(+), 1 deletion(-)
 create mode 100644 lib/net/rte_macsec.h
doc/api/doxy-api-index.md +2 -1
index 186a258be4..99e49340d3 100644
@@ -126,7 +126,8 @@ The public API headers are grouped by topics:
   [Geneve](@ref rte_geneve.h),
   [eCPRI](@ref rte_ecpri.h),
   [L2TPv2](@ref rte_l2tpv2.h),
-  [PPP](@ref rte_ppp.h)
+  [PPP](@ref rte_ppp.h),
+  [MACsec](@ref rte_macsec.h)
 
 - **QoS**:
   [metering](@ref rte_meter.h),
lib/net/meson.build +1 -0
index e899846578..3e63abaca8 100644
@@ -21,6 +21,7 @@ headers = files(
         'rte_geneve.h',
         'rte_l2tpv2.h',
         'rte_ppp.h',
+        'rte_macsec.h',
 )
 
 sources = files(
lib/net/rte_macsec.h new file +12 -0
new file mode 100644
index 0000000000..f1b59253f6
@@ -0,0 +1,56 @@
+/* SPDX-License-Identifier: BSD-3-Clause
+ * Copyright(C) 2022 Marvell.
+ */
+
+#ifndef _RTE_MACSEC_H_
+#define _RTE_MACSEC_H_
+
+/**
+ * @file
+ *
+ * MACsec-related defines
+ */

lib/net/rte_macsec.h line 22

Quoted 10 lines
lib/net/rte_macsec.h new file +10 -0
+
+#include <rte_byteorder.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+
+/* SecTAG length = macsec ether header without the optional SCI */
+#define RTE_MACSEC_TAG_LEN 6

Use a doxygen-like comment.

Is this define required? In my understanding, it is the same as sizeof(struct rte_macsec_hdr).

lib/net/rte_macsec.h line 23

Quoted 1 line
lib/net/rte_macsec.h new file +1 -0
+#define RTE_MACSEC_SCI_LEN 8

Missing doxygen doc.

lib/net/rte_macsec.h line 25

Quoted 2 lines
lib/net/rte_macsec.h new file +2 -0
+
+#define RTE_MACSEC_TCI_VERSION	0x80 /**< Version mask for MACsec.

Should be 0. */

lib/net/rte_macsec.h line 26

Quoted 1 line
lib/net/rte_macsec.h new file +1 -0
+#define RTE_MACSEC_TCI_ES	0x40 /**< End station - SCI is not valid

*/

lib/net/rte_macsec.h line 28

Quoted 2 lines
lib/net/rte_macsec.h new file +2 -0
+#define RTE_MACSEC_TCI_SC	0x20 /**< SCI present */
+#define RTE_MACSEC_TCI_SCB	0x10 /**< Secure channel support

EPON single copy broadcast */

support -> supports?

lib/net/rte_macsec.h line 30

Quoted 2 lines
lib/net/rte_macsec.h new file +2 -0
+#define RTE_MACSEC_TCI_E	0x08 /**< User data is encrypted */
+#define RTE_MACSEC_TCI_C	0x04 /**< User data was changed (because of

encryption) */

In [1], I can read the following, which is not similar:

E and C bits used to determine if packet is encrypted
• E, C = 1, 1 – Encrypted
• E, C = 0, 0 – Authenticated-Only

Is there any reference paper for macsec header?

[1] https://www.marvell.com/content/dam/marvell/en/public-
collateral/automotive-solutions/marvell-macsec-security-in-ethernet-based- vehicle-white-paper.pdf

lib/net/rte_macsec.h line 31

Quoted 1 line
lib/net/rte_macsec.h new file +1 -0
+#define RTE_MACSEC_AN_MASK	0x03 /**< Association number mask in

tci_an */

nit: all comments should end with a dot.

lib/net/rte_macsec.h line 32

Quoted 2 lines
lib/net/rte_macsec.h new file +1 -0
+#define RTE_MACSEC_NUM_AN	4    /**< 2 bits for the association

number */

I don't get how this defined is used. Can the comment be clarified?

lib/net/rte_macsec.h line 33

Quoted 1 line
lib/net/rte_macsec.h new file +1 -0
+#define RTE_MACSEC_SALT_LEN	12   /**< Salt length for MACsec SA */

Same here.

lib/net/rte_macsec.h line 39

Quoted 6 lines
lib/net/rte_macsec.h new file +6 -0
+
+/**
+ * MACsec Header
+ */
+struct rte_macsec_hdr {
+	/* SecTAG */

Is the SecTAG comment required? Or maybe it should be moved above the struct?

lib/net/rte_macsec.h line 40

Quoted 1 line
lib/net/rte_macsec.h new file +1 -0
+	uint8_t  tci_an;	/**< Tag control information and Association number

of SC */

nit: duplicated spaces after uint8_t

Can we use a bitfield here for tci and an, like you did for short_length?

Like this:

	uint8_t tci:6;
	uint8_t an:2;

Or:

	uint8_t tci_version:1;
	uint8_t tci_es:1;
	uint8_t tci_sc:1;
	uint8_t tci_scb:1;
	uint8_t tci_e:1;
	uint8_t tci_c:1;
	uint8_t an:2;

I think the 2nd one is easier to use.

lib/net/rte_macsec.h line 43

Quoted 3 lines
lib/net/rte_macsec.h new file +3 -0
+#if RTE_BYTE_ORDER == RTE_LITTLE_ENDIAN
+	uint8_t short_length : 6; /**< Short Length */
+	uint8_t unused : 2;

nit: no spaces around ':'

lib/net/rte_macsec.h

Quoted 5 lines
lib/net/rte_macsec.h new file +5 -0
+#elif RTE_BYTE_ORDER == RTE_BIG_ENDIAN
+	uint8_t unused : 2;
+	uint8_t short_length : 6;
+#endif
+	rte_be32_t packet_number; /**< Packet number to support replay

protection */

lib/net/rte_macsec.h line 49

Quoted 1 line
lib/net/rte_macsec.h new file +1 -0
+	uint8_t secure_channel_id[8]; /* optional */

8 -> RTE_MACSEC_SCI_LEN ?

I think it would be more convenient to have another struct for the secure_channel_id.

For instance, this pseudo code:

	struct struct rte_macsec_hdr *hdr = NULL;
	struct struct rte_macsec_sci_hdr *hdr_sci = NULL;

	if (seg_len(mbuf) < sizeof(*hdr))
		return -1;
	if (hdr.tci_sc) {
		if (seg_len(mbuf) < sizeof(*hdr_sci))
			return -1;
		hdr_sci = hdr;
	}

With only one struct, it is difficult to properly do the length check.

Quoted 10 lines
lib/net/rte_macsec.h new file +7 -1
+} __rte_packed;
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* RTE_MACSEC_H_ */
--

2.25.1

Thanks,
Olivier

#5 lore raw

RE: [EXT] Re: [PATCH 1/3] net: add MACsec header

In reply to Olivier Matz

Hi Olivier,

Quoted 4 lines

Review

Quoted 2 lines
(quoted diff) +2 -0
+#define RTE_MACSEC_TCI_E	0x08 /**< User data is encrypted */
+#define RTE_MACSEC_TCI_C	0x04 /**< User data was changed (because of

encryption) */

E bit means the user data is encrypted if set. Above defines are mask to each of the fields in tci_an. I would add a comment that these are masks to each of the fields.

C bit means the user data is changed (because of encryption)

Quoted 8 lines

In [1], I can read the following, which is not similar:

E and C bits used to determine if packet is encrypted
• E, C = 1, 1 – Encrypted
• E, C = 0, 0 – Authenticated-Only

Is there any reference paper for macsec header?

The reference is IEEE802.1AE standard.
https://ieeexplore.ieee.org/document/8585421

Quoted 9 lines

[1] https://www.marvell.com/content/dam/marvell/en/public-
collateral/automotive-solutions/marvell-macsec-security-in-ethernet-based- vehicle-white-paper.pdf

Quoted 1 line
Quoted 4 lines
Quoted 1 line

+#define RTE_MACSEC_NUM_AN 4 /**< 2 bits for the association

number */

I don't get how this defined is used. Can the comment be clarified?

In case of MACsec we can have 4 different SAs for each of the secure channel Based on the AN field.
RTE_MACSEC_NUM_AN is basically added to make an upper limit to the array of SAs. I will re-write the comment as
#define RTE_MACSEC_NUM_AN 4 /**< Max number of association numbers. */

Or shall I move it to rte_security?

Quoted 2 lines
Quoted 2 lines

+#define RTE_MACSEC_SALT_LEN 12 /**< Salt length for MACsec SA */

For MACsec SA configuration, Salt is used which has a fixed size of 12 bytes. Do you want me to move it to rte_security?

Quoted 13 lines

Same here.

lib/net/rte_macsec.h line 39

Quoted 6 lines
lib/net/rte_macsec.h new file +6 -0
+
+/**
+ * MACsec Header
+ */
+struct rte_macsec_hdr {
+	/* SecTAG */

Is the SecTAG comment required? Or maybe it should be moved above the struct?

Quoted 6 lines

Review

Quoted 1 line
(quoted diff) +1 -0
+	uint8_t  tci_an;	/**< Tag control information and Association number

of SC */

nit: duplicated spaces after uint8_t

Can we use a bitfield here for tci and an, like you did for short_length?

Would it be really necessary to split it to bitfields. Can we not use it like vtc_flow in rte_ipv6_hdr?

Quoted 30 lines

Like this:

	uint8_t tci:6;
	uint8_t an:2;

Or:

	uint8_t tci_version:1;
	uint8_t tci_es:1;
	uint8_t tci_sc:1;
	uint8_t tci_scb:1;
	uint8_t tci_e:1;
	uint8_t tci_c:1;
	uint8_t an:2;

I think the 2nd one is easier to use.

lib/net/rte_macsec.h line 43

Quoted 3 lines
lib/net/rte_macsec.h new file +3 -0
+#if RTE_BYTE_ORDER == RTE_LITTLE_ENDIAN
+	uint8_t short_length : 6; /**< Short Length */
+	uint8_t unused : 2;

nit: no spaces around ':'

lib/net/rte_macsec.h

Quoted 5 lines
lib/net/rte_macsec.h new file +5 -0
+#elif RTE_BYTE_ORDER == RTE_BIG_ENDIAN
+	uint8_t unused : 2;
+	uint8_t short_length : 6;
+#endif
+	rte_be32_t packet_number; /**< Packet number to support replay

protection */

Quoted 6 lines

lib/net/rte_macsec.h line 49

Quoted 1 line
lib/net/rte_macsec.h new file +1 -0
+	uint8_t secure_channel_id[8]; /* optional */

8 -> RTE_MACSEC_SCI_LEN ?

I think it would be more convenient to have another struct for the secure_channel_id.

Ok Can we use it like this

struct rte_macsec_sci_hdr {
uint8_t sci[RTE_MACSEC_SCI_LEN]; /**< Optional secure channel id. */
} __rte_packed;

struct rte_macsec_hdr {
uint8_t tci_an; /**< Tag control information and Association number of SC. */

#if RTE_BYTE_ORDER == RTE_LITTLE_ENDIAN
        uint8_t short_length:6; /**< Short Length. */
        uint8_t unused:2;
#elif RTE_BYTE_ORDER == RTE_BIG_ENDIAN
        uint8_t unused:2;
        uint8_t short_length:6; /**< Short Length. */
#endif
        rte_be32_t packet_number; /**< Packet number to support replay protection. */
        union {
                uint8_t payload[0];
                struct rte_macsec_sci_hdr sci[0];
        };
} __rte_packed;
#6 lore raw

PATCH 2/3 security: support MACsec

In reply to Akhil Goyal

Added support for MACsec in rte_security for offloading MACsec Protocol operation to inline NIC device or a crypto device.

To support MACsec we cannot just make one security session and send with the packet to process it. MACsec specifications suggest, it has 3 different entities - SECY Entity, SC(secure channel) and SA(security association). And same SA can be used by multiple SCs and similarly many SECY can have same SCs. Hence, in order to support this many to one relationships between all entities, 2 new APIs are created - rte_security_macsec_sc_create and rte_security_macsec_sa_create. Flow of execution of the APIs would be as
- rte_security_macsec_sa_create
- rte_security_macsec_sc_create
- rte_security_session_create(for secy)
And in case of inline protocol processing rte_flow can be created with rte_security action. A new flow item will be added for MACsec header. New APIs are also created for getting SC and SA stats.

---
 doc/guides/prog_guide/rte_security.rst | 107 +++++++-
 lib/security/rte_security.c            |  86 ++++++
 lib/security/rte_security.h            | 362 ++++++++++++++++++++++++-
 lib/security/rte_security_driver.h     |  86 ++++++
 lib/security/version.map               |   6 +
 5 files changed, 634 insertions(+), 13 deletions(-)
doc/guides/prog_guide/rte_security.rst +102 -5
index 72ca0bd330..1af4d60c75 100644
@@ -345,6 +345,55 @@ The CRC is Ethernet CRC-32 as specified in Ethernet/[ISO/IEC 8802-3].
     * Other DOCSIS protocol functionality such as Header Checksum (HCS)
       calculation may be added in the future.
 
+MACSEC Protocol
+~~~~~~~~~~~~~~~
+
+Media Access Control security (MACsec) provides point-to-point security on Ethernet
+links and is defined by IEEE standard 802.1AE. MACsec secures an Ethernet link for
+almost all traffic, including frames from the Link Layer Discovery Protocol (LLDP),
+Link Aggregation Control Protocol (LACP), Dynamic Host Configuration Protocol (DHCP),
+Address Resolution Protocol (ARP), and other protocols that are not typically secured
+on an Ethernet link because of limitations with other security solutions.
+
+.. code-block:: c
+
+             Receive                                                Transmit
+             -------                                                --------
+
+         Ethernet frame                                          Ethernet frame
+         from  network                                           towards network
+                |                                                      ^
+                ~                                                      |
+                |                                                      ~
+                V                                                      |
+    +-----------------------+      +------------------+      +-------------------------+
+    | Secure frame verify   |      | Cipher Suite(SA) |      | Secure Frame Generation |
+    +-----------------------+<-----+------------------+----->+-------------------------+
+    | SecTAG + ICV remove   |      |  SECY   |   SC   |      | SecTAG + ICV Added      |
+    +---+-------------------+      +------------------+      +-------------------------+
+                |                                                      ^
+                |                                                      |
+                V                                                      |
+        Packet to Core/App                                     Packet from core/App
+
+
+
+To configure MACsec on an inline NIC device or a lookaside crypto device, a security
+association(SA) and a secure channel(SC) are created before creating rte_security
+session.
+
+SA is created using API ``rte_security_macsec_sa_create`` which allows setting
+SA keys, salt, SSCI, packet number(PN) into the PMD and the API returns a handle
+which can be used to map it with a secure channel using the API
+``rte_security_macsec_sc_create``. Same SAs can be used for multiple SCs.
+The Rx SC will need a set of 4 SAs for each of the association numbers(AN).
+For Tx SC a single SA is set which will be used by hardware to process the packet.
+
+The API ``rte_security_macsec_sc_create`` returns a handle for SC and this handle
+is set in ``rte_security_macsec_xform`` to create a MACsec session using
+``rte_security_session_create``.
+
+
 Device Features and Capabilities
 ---------------------------------
 
@@ -517,6 +566,35 @@ protocol.
         RTE_CRYPTODEV_END_OF_CAPABILITIES_LIST()
     };
 
+Below is the example PMD capability for MACsec
+
+.. code-block:: c
+
+    static const struct rte_security_capability pmd_security_capabilities[] = {
+        { /* DOCSIS Uplink */
+                .action = RTE_SECURITY_ACTION_TYPE_INLINE_PROTOCOL,
+                .protocol = RTE_SECURITY_PROTOCOL_MACSEC,
+                .macsec = {
+                        .mtu = 1500,
+                        .alg = RTE_SECURITY_MACSEC_ALG_GCM_128,
+                        .max_nb_sc = 64,
+                        .max_nb_sa = 128,
+                        .max_nb_sess = 64,
+                        .replay_win_sz = 4096,
+                        .relative_sectag_insert = 1,
+                        .fixed_sectag_insert = 1,
+                        .icv_include_da_sa = 1,
+                        .ctrl_port_enable = 1,
+                        .preserve_sectag = 1,
+                        .preserve_icv = 1,
+                        .validate_frames = 1,
+                        .re_key = 1,
+                        .anti_replay = 1,
+                },
+                .crypto_capabilities = NULL,
+        },
+    };
+
 Capabilities Discovery
 ~~~~~~~~~~~~~~~~~~~~~~
 
@@ -661,6 +739,8 @@ which will be updated in the future.
 
 IPsec related configuration parameters are defined in ``rte_security_ipsec_xform``
 
+MACsec related configuration parameters are defined in ``rte_security_macsec_xform``
+
 PDCP related configuration parameters are defined in ``rte_security_pdcp_xform``
 
 DOCSIS related configuration parameters are defined in ``rte_security_docsis_xform``
@@ -682,7 +762,7 @@ The ingress/egress flow attribute should match that specified in the security
 session if the security session supports the definition of the direction.
 
 Multiple flows can be configured to use the same security session. For
-example if the security session specifies an egress IPsec SA, then multiple
+example if the security session specifies an egress IPsec/MACsec SA, then multiple
 flows can be specified to that SA. In the case of an ingress IPsec SA then
 it is only valid to have a single flow to map to that security session.
 
@@ -692,8 +772,8 @@ it is only valid to have a single flow to map to that security session.
                  |
         +--------|--------+
         |    Add/Remove   |
-        |     IPsec SA    |   <------ Build security flow action of
-        |        |        |           ipsec transform
+        | IPsec/MACsec SA |   <------ Build security flow action of
+        |        |        |           IPsec/MACsec transform
         |--------|--------|
                  |
         +--------V--------+
@@ -712,9 +792,9 @@ it is only valid to have a single flow to map to that security session.
         |                 |
         +--------|--------+
 
-* Add/Delete SA flow:
+* Add/Delete IPsec SA flow:
   To add a new inline SA construct a rte_flow_item for Ethernet + IP + ESP
-  using the SA selectors and the ``rte_crypto_ipsec_xform`` as the ``rte_flow_action``.
+  using the SA selectors and the ``rte_security_ipsec_xform`` as the ``rte_flow_action``.
   Note that any rte_flow_items may be empty, which means it is not checked.
 
 .. code-block:: console
@@ -729,6 +809,23 @@ it is only valid to have a single flow to map to that security session.
         |  Eth  | ->  ... -> |   ESP  | -> | END |
         +-------+            +--------+    +-----+
 
+* Add/Delete MACsec SA flow:
+  To add a new inline SA construct a rte_flow_item for Ethernet + SecTAG
+  using the SA selectors and the ``rte_security_macsec_xform`` as the ``rte_flow_action``.
+  Note that any rte_flow_items may be empty, which means it is not checked.
+
+.. code-block:: console
+
+    In its most basic form, MACsec flow specification is as follows:
+        +-------+     +----------+     +-----+
+        |  Eth  | ->  |  SecTag  |  -> | END |
+        +-------+     +----------+     +-----+
+
+    However, the API can represent, MACsec offload with any encapsulation:
+        +-------+            +--------+    +-----+
+        |  Eth  | ->  ... -> | SecTag | -> | END |
+        +-------+            +--------+    +-----+
+
 
 Telemetry support
 -----------------
lib/security/rte_security.c +86 -0

92 lines not on this page · raw message

lib/security/rte_security.h +354 -8

420 lines not on this page · raw message

lib/security/rte_security_driver.h +86 -0

104 lines not on this page · raw message

lib/security/version.map +6 -0
index c770b2e8f8..c0c3574dca 100644
@@ -16,6 +16,12 @@ EXPERIMENTAL {
 	__rte_security_get_userdata;
 	__rte_security_set_pkt_metadata;
 	rte_security_dynfield_offset;
+	rte_security_macsec_sa_create;
+	rte_security_macsec_sa_destroy;
+	rte_security_macsec_sa_stats_get;
+	rte_security_macsec_sc_create;
+	rte_security_macsec_sc_destroy;
+	rte_security_macsec_sc_stats_get;
 	rte_security_session_stats_get;
 	rte_security_session_update;
 };
Signature · 1 line
2.25.1
#7 lore raw

Hi txgbe/ixgbe maintainers,

I see that MACsec is supported by ixgbe and txgbe PMDs. Could you please review this patch?

Regards,
Akhil

Quoted 22 lines

Subject: [PATCH 2/3] security: support MACsec

Added support for MACsec in rte_security for offloading MACsec Protocol operation to inline NIC device or a crypto device.

To support MACsec we cannot just make one security session and send with the packet to process it. MACsec specifications suggest, it has 3 different entities - SECY Entity, SC(secure channel) and SA(security association). And same SA can be used by multiple SCs and similarly many SECY can have same SCs. Hence, in order to support this many to one relationships between all entities, 2 new APIs are created - rte_security_macsec_sc_create and rte_security_macsec_sa_create. Flow of execution of the APIs would be as
- rte_security_macsec_sa_create
- rte_security_macsec_sc_create
- rte_security_session_create(for secy)
And in case of inline protocol processing rte_flow can be created with rte_security action. A new flow item will be added for MACsec header. New APIs are also created for getting SC and SA stats.

---

#8 lore raw

PATCH 3/3 ethdev: add MACsec flow item

In reply to Akhil Goyal

A new flow item is defined for MACsec flows which can be offloaded to an inline device. If the flow matches with MACsec header, device will process as per the security session created using rte_security APIs.
If an error comes while MACsec processing in HW, PMD will notify with the events defined in this patch.

---
 lib/ethdev/rte_ethdev.h | 55 +++++++++++++++++++++++++++++++++++++++++
 lib/ethdev/rte_flow.h   | 18 ++++++++++++++
 2 files changed, 73 insertions(+)
lib/ethdev/rte_ethdev.h +55 -0
index de9e970d4d..24661b01e9 100644
@@ -3864,6 +3864,61 @@ rte_eth_tx_buffer_count_callback(struct rte_mbuf **pkts, uint16_t unsent,
 int
 rte_eth_tx_done_cleanup(uint16_t port_id, uint16_t queue_id, uint32_t free_cnt);
 
+/**
+ * Subtypes for MACsec offload event(@ref RTE_ETH_EVENT_MACSEC) raised by
+ * Ethernet device.
+ */
+enum rte_eth_macsec_event_subtype {
+	RTE_ETH_MACSEC_SUBEVENT_UNKNOWN,
+	/* subevents of RTE_ETH_MACSEC_EVENT_SECTAG_VAL_ERR sectag validation events
+	 * RTE_ETH_MACSEC_EVENT_RX_SECTAG_V_EQ1
+	 *	Validation check: SecTag.TCI.V = 1
+	 * RTE_ETH_MACSEC_EVENT_RX_SECTAG_E_EQ0_C_EQ1
+	 *	Validation check: SecTag.TCI.E = 0 && SecTag.TCI.C = 1
+	 * RTE_ETH_MACSEC_EVENT_RX_SECTAG_SL_GTE48
+	 *	Validation check: SecTag.SL >= 'd48
+	 * RTE_ETH_MACSEC_EVENT_RX_SECTAG_ES_EQ1_SC_EQ1
+	 *	Validation check: SecTag.TCI.ES = 1 && SecTag.TCI.SC = 1
+	 * RTE_ETH_MACSEC_EVENT_RX_SECTAG_SC_EQ1_SCB_EQ1
+	 *	Validation check: SecTag.TCI.SC = 1 && SecTag.TCI.SCB = 1
+	 */
+	RTE_ETH_MACSEC_SUBEVENT_RX_SECTAG_V_EQ1,
+	RTE_ETH_MACSEC_SUBEVENT_RX_SECTAG_E_EQ0_C_EQ1,
+	RTE_ETH_MACSEC_SUBEVENT_RX_SECTAG_SL_GTE48,
+	RTE_ETH_MACSEC_SUBEVENT_RX_SECTAG_ES_EQ1_SC_EQ1,
+	RTE_ETH_MACSEC_SUBEVENT_RX_SECTAG_SC_EQ1_SCB_EQ1,
+};
+
+enum rte_eth_macsec_event_type {
+	RTE_ETH_MACSEC_EVENT_UNKNOWN,
+	RTE_ETH_MACSEC_EVENT_SECTAG_VAL_ERR,
+	RTE_ETH_MACSEC_EVENT_RX_SA_PN_HARD_EXP,
+	RTE_ETH_MACSEC_EVENT_RX_SA_PN_SOFT_EXP,
+	RTE_ETH_MACSEC_EVENT_TX_SA_PN_HARD_EXP,
+	RTE_ETH_MACSEC_EVENT_TX_SA_PN_SOFT_EXP,
+	/* Notifies Invalid SA event */
+	RTE_ETH_MACSEC_EVENT_SA_NOT_VALID,
+};
+
+/**
+ * Descriptor for @ref RTE_ETH_EVENT_MACSEC event. Used by eth dev to send extra
+ * information of the MACsec offload event.
+ */
+struct rte_eth_event_macsec_desc {
+	enum rte_eth_macsec_event_type type;
+	enum rte_eth_macsec_event_subtype subtype;
+	/**
+	 * Event specific metadata.
+	 *
+	 * For the following events, *userdata* registered
+	 * with the *rte_security_session* would be returned
+	 * as metadata,
+	 *
+	 * @see struct rte_security_session_conf
+	 */
+	uint64_t metadata;
+};
+
 /**
  * Subtypes for IPsec offload event(@ref RTE_ETH_EVENT_IPSEC) raised by
  * eth device.
lib/ethdev/rte_flow.h +18 -0
index a79f1e7ef0..4114c84a02 100644
@@ -35,6 +35,7 @@
 #include <rte_l2tpv2.h>
 #include <rte_ppp.h>
 #include <rte_gre.h>
+#include <rte_macsec.h>
 
 #ifdef __cplusplus
 extern "C" {
@@ -668,6 +669,13 @@ enum rte_flow_item_type {
 	 * See struct rte_flow_item_gre_opt.
 	 */
 	RTE_FLOW_ITEM_TYPE_GRE_OPTION,
+
+	/**
+	 * Matches MACsec Ethernet Header.
+	 *
+	 * See struct rte_flow_item_macsec.
+	 */
+	RTE_FLOW_ITEM_TYPE_MACSEC,
 };
 
 /**
@@ -1214,6 +1222,16 @@ struct rte_flow_item_gre_opt {
 	struct rte_gre_hdr_opt_sequence sequence;
 };
 
+/**
+ * RTE_FLOW_ITEM_TYPE_MACSEC.
+ *
+ * Matches MACsec header.
+ */
+struct rte_flow_item_macsec {
+	struct rte_macsec_hdr macsec_hdr;
+};
+
+
 /**
  * RTE_FLOW_ITEM_TYPE_FUZZY
  *
Signature · 1 line
2.25.1
Acked-by on v1 3/3
#9 lore raw

RE: [PATCH 3/3] ethdev: add MACsec flow item

Quoted 135 lines

-----Original Message-----
From: Akhil Goyal <[email protected]>
Sent: Sunday, 14 August 2022 21:46

A new flow item is defined for MACsec flows which can be offloaded to an inline device. If the flow matches with MACsec header, device will process as per the security session created using rte_security APIs.
If an error comes while MACsec processing in HW, PMD will notify with the events defined in this patch.

---
 lib/ethdev/rte_ethdev.h | 55
+++++++++++++++++++++++++++++++++++++++++
 lib/ethdev/rte_flow.h   | 18 ++++++++++++++
 2 files changed, 73 insertions(+)
lib/ethdev/rte_ethdev.h +2 -0
index de9e970d4d..24661b01e9 100644
@@ -3864,6 +3864,61 @@ rte_eth_tx_buffer_count_callback(struct
 rte_mbuf **pkts, uint16_t unsent,
 int
 rte_eth_tx_done_cleanup(uint16_t port_id, uint16_t queue_id, uint32_t
 free_cnt);
 
+/**
+ * Subtypes for MACsec offload event(@ref RTE_ETH_EVENT_MACSEC)

raised by
+ * Ethernet device.
+ */

lib/ethdev/rte_ethdev.h +3 -0
+enum rte_eth_macsec_event_subtype {
+	RTE_ETH_MACSEC_SUBEVENT_UNKNOWN,
+	/* subevents of RTE_ETH_MACSEC_EVENT_SECTAG_VAL_ERR sectag

validation events

lib/ethdev/rte_ethdev.h +31 -0
+	 * RTE_ETH_MACSEC_EVENT_RX_SECTAG_V_EQ1
+	 *	Validation check: SecTag.TCI.V = 1
+	 * RTE_ETH_MACSEC_EVENT_RX_SECTAG_E_EQ0_C_EQ1
+	 *	Validation check: SecTag.TCI.E = 0 && SecTag.TCI.C = 1
+	 * RTE_ETH_MACSEC_EVENT_RX_SECTAG_SL_GTE48
+	 *	Validation check: SecTag.SL >= 'd48
+	 * RTE_ETH_MACSEC_EVENT_RX_SECTAG_ES_EQ1_SC_EQ1
+	 *	Validation check: SecTag.TCI.ES = 1 && SecTag.TCI.SC = 1
+	 * RTE_ETH_MACSEC_EVENT_RX_SECTAG_SC_EQ1_SCB_EQ1
+	 *	Validation check: SecTag.TCI.SC = 1 && SecTag.TCI.SCB = 1
+	 */
+	RTE_ETH_MACSEC_SUBEVENT_RX_SECTAG_V_EQ1,
+	RTE_ETH_MACSEC_SUBEVENT_RX_SECTAG_E_EQ0_C_EQ1,
+	RTE_ETH_MACSEC_SUBEVENT_RX_SECTAG_SL_GTE48,
+	RTE_ETH_MACSEC_SUBEVENT_RX_SECTAG_ES_EQ1_SC_EQ1,
+	RTE_ETH_MACSEC_SUBEVENT_RX_SECTAG_SC_EQ1_SCB_EQ1,
+};
+
+enum rte_eth_macsec_event_type {
+	RTE_ETH_MACSEC_EVENT_UNKNOWN,
+	RTE_ETH_MACSEC_EVENT_SECTAG_VAL_ERR,
+	RTE_ETH_MACSEC_EVENT_RX_SA_PN_HARD_EXP,
+	RTE_ETH_MACSEC_EVENT_RX_SA_PN_SOFT_EXP,
+	RTE_ETH_MACSEC_EVENT_TX_SA_PN_HARD_EXP,
+	RTE_ETH_MACSEC_EVENT_TX_SA_PN_SOFT_EXP,
+	/* Notifies Invalid SA event */
+	RTE_ETH_MACSEC_EVENT_SA_NOT_VALID,
+};
+
+/**
+ * Descriptor for @ref RTE_ETH_EVENT_MACSEC event. Used by eth dev to

send extra
+ * information of the MACsec offload event.
+ */

lib/ethdev/rte_ethdev.h +15 -0
+struct rte_eth_event_macsec_desc {
+	enum rte_eth_macsec_event_type type;
+	enum rte_eth_macsec_event_subtype subtype;
+	/**
+	 * Event specific metadata.
+	 *
+	 * For the following events, *userdata* registered
+	 * with the *rte_security_session* would be returned
+	 * as metadata,
+	 *
+	 * @see struct rte_security_session_conf
+	 */
+	uint64_t metadata;
+};
+
 /**
  * Subtypes for IPsec offload event(@ref RTE_ETH_EVENT_IPSEC) raised by
  * eth device.
lib/ethdev/rte_flow.h +18 -1
index a79f1e7ef0..4114c84a02 100644
@@ -35,6 +35,7 @@
 #include <rte_l2tpv2.h>
 #include <rte_ppp.h>
 #include <rte_gre.h>
+#include <rte_macsec.h>
 
 #ifdef __cplusplus
 extern "C" {
@@ -668,6 +669,13 @@ enum rte_flow_item_type {
 	 * See struct rte_flow_item_gre_opt.
 	 */
 	RTE_FLOW_ITEM_TYPE_GRE_OPTION,
+
+	/**
+	 * Matches MACsec Ethernet Header.
+	 *
+	 * See struct rte_flow_item_macsec.
+	 */
+	RTE_FLOW_ITEM_TYPE_MACSEC,
 };
 
 /**
@@ -1214,6 +1222,16 @@ struct rte_flow_item_gre_opt {
 	struct rte_gre_hdr_opt_sequence sequence;
 };
 
+/**
+ * RTE_FLOW_ITEM_TYPE_MACSEC.
+ *
+ * Matches MACsec header.
+ */
+struct rte_flow_item_macsec {
+	struct rte_macsec_hdr macsec_hdr;
+};
+
+
 /**
  * RTE_FLOW_ITEM_TYPE_FUZZY
  *
--
Quoted 1 line

2.25.1

Best,
Ori

#10 lore raw

v2 cover security: support MACsec

In reply to Akhil Goyal

Added support for MACsec in rte_security for offloading MACsec Protocol operation to inline NIC device or a crypto device.

To support MACsec we cannot just make one security session and send with the packet to process it. MACsec specifications suggest, it can have 3 different entities - SECY Entity, SC(secure channel) and SA(security association). And same SA can be used by multiple SCs and similarly many SECY can have same SCs. Hence, in order to support this many to one relationships between all entities, 2 new APIs are created - rte_security_macsec_sc_create and rte_security_sa_create. Flow of execution of the APIs would be as
- rte_security_macsec_sa_create
- rte_security_macsec_sc_create
- rte_security_session_create(for secy)
And in case of inline protocol processing rte_flow can be created with rte_security action similar to IPsec flows except that the flow item will be MACsec instead of IPsec.

A new flow item is added for MACsec header and a set of events are added to specify the errors occurred during inline protocol processing.

New APIs are also created for getting SC and SA stats.

Patches for PMD implementation and test app are submitted separately which can be separately applied after RC1.

Changes in v2:
- Incorporated comments from Olivier except the one to split tci_an into bitfields.
- added release notes and removed deprecation notice.
- added some missing fields in rte_security patch.

Akhil Goyal (3):
net: add MACsec header
ethdev: add MACsec flow item
security: support MACsec

 doc/api/doxy-api-index.md              |   3 +-
 doc/guides/prog_guide/rte_security.rst | 107 ++++++-
 doc/guides/rel_notes/deprecation.rst   |   5 -
 doc/guides/rel_notes/release_22_11.rst |  10 +
 lib/ethdev/rte_ethdev.h                |  55 ++++
 lib/ethdev/rte_flow.h                  |  18 ++
 lib/net/meson.build                    |   1 +
 lib/net/rte_macsec.h                   |  61 ++++
 lib/security/rte_security.c            |  86 ++++++
 lib/security/rte_security.h            | 370 ++++++++++++++++++++++++-
 lib/security/rte_security_driver.h     |  86 ++++++
 lib/security/version.map               |   6 +
 12 files changed, 789 insertions(+), 19 deletions(-)
 create mode 100644 lib/net/rte_macsec.h
Signature · 1 line
2.25.1
#11 lore raw

PATCH v2 1/3 net: add MACsec header

Added MACsec protocol header to be used for supporting MACsec protocol offload in hardware or directly in the application.

---
 doc/api/doxy-api-index.md |  3 +-
 lib/net/meson.build       |  1 +
 lib/net/rte_macsec.h      | 61 +++++++++++++++++++++++++++++++++++++++
 3 files changed, 64 insertions(+), 1 deletion(-)
 create mode 100644 lib/net/rte_macsec.h
doc/api/doxy-api-index.md +2 -1
index 186a258be4..99e49340d3 100644
@@ -126,7 +126,8 @@ The public API headers are grouped by topics:
   [Geneve](@ref rte_geneve.h),
   [eCPRI](@ref rte_ecpri.h),
   [L2TPv2](@ref rte_l2tpv2.h),
-  [PPP](@ref rte_ppp.h)
+  [PPP](@ref rte_ppp.h),
+  [MACsec](@ref rte_macsec.h)
 
 - **QoS**:
   [metering](@ref rte_meter.h),
lib/net/meson.build +1 -0
index e899846578..3e63abaca8 100644
@@ -21,6 +21,7 @@ headers = files(
         'rte_geneve.h',
         'rte_l2tpv2.h',
         'rte_ppp.h',
+        'rte_macsec.h',
 )
 
 sources = files(
lib/net/rte_macsec.h new file +61 -0

61 lines not on this page · raw message

Signature · 1 line
2.25.1
#13 lore raw

Re: [PATCH v2 1/3] net: add MACsec header

In reply to Akhil Goyal

28/09/2022 14:22, Akhil Goyal:

Quoted 4 lines
lib/net/rte_macsec.h new file +2 -0
+#ifndef _RTE_MACSEC_H_
+#define _RTE_MACSEC_H_

[...]

Quoted 1 line

+#endif /* RTE_MACSEC_H_ */

Discrepancy spotted here. Anyway no need of underscores at all. I'll rename to RTE_MACSEC_H while merging.

#15 lore raw

PATCH v2 2/3 ethdev: add MACsec flow item

In reply to Akhil Goyal

A new flow item is defined for MACsec flows which can be offloaded to an inline device. If the flow matches with MACsec header, device will process as per the security session created using rte_security APIs.
If an error comes while MACsec processing in HW, PMD will notify with the events defined in this patch.

---
 lib/ethdev/rte_ethdev.h | 55 +++++++++++++++++++++++++++++++++++++++++
 lib/ethdev/rte_flow.h   | 18 ++++++++++++++
 2 files changed, 73 insertions(+)
lib/ethdev/rte_ethdev.h +55 -0
index 19e2a8eb3f..733165ec6d 100644
@@ -3579,6 +3579,61 @@ rte_eth_tx_buffer_count_callback(struct rte_mbuf **pkts, uint16_t unsent,
 int
 rte_eth_tx_done_cleanup(uint16_t port_id, uint16_t queue_id, uint32_t free_cnt);
 
+/**
+ * Subtypes for MACsec offload event(@ref RTE_ETH_EVENT_MACSEC) raised by
+ * Ethernet device.
+ */
+enum rte_eth_macsec_event_subtype {
+	RTE_ETH_MACSEC_SUBEVENT_UNKNOWN,
+	/* subevents of RTE_ETH_MACSEC_EVENT_SECTAG_VAL_ERR sectag validation events
+	 * RTE_ETH_MACSEC_EVENT_RX_SECTAG_V_EQ1
+	 *	Validation check: SecTag.TCI.V = 1
+	 * RTE_ETH_MACSEC_EVENT_RX_SECTAG_E_EQ0_C_EQ1
+	 *	Validation check: SecTag.TCI.E = 0 && SecTag.TCI.C = 1
+	 * RTE_ETH_MACSEC_EVENT_RX_SECTAG_SL_GTE48
+	 *	Validation check: SecTag.SL >= 'd48
+	 * RTE_ETH_MACSEC_EVENT_RX_SECTAG_ES_EQ1_SC_EQ1
+	 *	Validation check: SecTag.TCI.ES = 1 && SecTag.TCI.SC = 1
+	 * RTE_ETH_MACSEC_EVENT_RX_SECTAG_SC_EQ1_SCB_EQ1
+	 *	Validation check: SecTag.TCI.SC = 1 && SecTag.TCI.SCB = 1
+	 */
+	RTE_ETH_MACSEC_SUBEVENT_RX_SECTAG_V_EQ1,
+	RTE_ETH_MACSEC_SUBEVENT_RX_SECTAG_E_EQ0_C_EQ1,
+	RTE_ETH_MACSEC_SUBEVENT_RX_SECTAG_SL_GTE48,
+	RTE_ETH_MACSEC_SUBEVENT_RX_SECTAG_ES_EQ1_SC_EQ1,
+	RTE_ETH_MACSEC_SUBEVENT_RX_SECTAG_SC_EQ1_SCB_EQ1,
+};
+
+enum rte_eth_macsec_event_type {
+	RTE_ETH_MACSEC_EVENT_UNKNOWN,
+	RTE_ETH_MACSEC_EVENT_SECTAG_VAL_ERR,
+	RTE_ETH_MACSEC_EVENT_RX_SA_PN_HARD_EXP,
+	RTE_ETH_MACSEC_EVENT_RX_SA_PN_SOFT_EXP,
+	RTE_ETH_MACSEC_EVENT_TX_SA_PN_HARD_EXP,
+	RTE_ETH_MACSEC_EVENT_TX_SA_PN_SOFT_EXP,
+	/* Notifies Invalid SA event */
+	RTE_ETH_MACSEC_EVENT_SA_NOT_VALID,
+};
+
+/**
+ * Descriptor for @ref RTE_ETH_EVENT_MACSEC event. Used by eth dev to send extra
+ * information of the MACsec offload event.
+ */
+struct rte_eth_event_macsec_desc {
+	enum rte_eth_macsec_event_type type;
+	enum rte_eth_macsec_event_subtype subtype;
+	/**
+	 * Event specific metadata.
+	 *
+	 * For the following events, *userdata* registered
+	 * with the *rte_security_session* would be returned
+	 * as metadata,
+	 *
+	 * @see struct rte_security_session_conf
+	 */
+	uint64_t metadata;
+};
+
 /**
  * Subtypes for IPsec offload event(@ref RTE_ETH_EVENT_IPSEC) raised by
  * eth device.
lib/ethdev/rte_flow.h +18 -0
index 96147a149a..e966488965 100644
@@ -35,6 +35,7 @@
 #include <rte_l2tpv2.h>
 #include <rte_ppp.h>
 #include <rte_gre.h>
+#include <rte_macsec.h>
 
 #ifdef __cplusplus
 extern "C" {
@@ -626,6 +627,13 @@ enum rte_flow_item_type {
 	 * See struct rte_flow_item_gre_opt.
 	 */
 	RTE_FLOW_ITEM_TYPE_GRE_OPTION,
+
+	/**
+	 * Matches MACsec Ethernet Header.
+	 *
+	 * See struct rte_flow_item_macsec.
+	 */
+	RTE_FLOW_ITEM_TYPE_MACSEC,
 };
 
 /**
@@ -1099,6 +1107,16 @@ struct rte_flow_item_gre_opt {
 	struct rte_gre_hdr_opt_sequence sequence;
 };
 
+/**
+ * RTE_FLOW_ITEM_TYPE_MACSEC.
+ *
+ * Matches MACsec header.
+ */
+struct rte_flow_item_macsec {
+	struct rte_macsec_hdr macsec_hdr;
+};
+
+
 /**
  * RTE_FLOW_ITEM_TYPE_FUZZY
  *
Signature · 1 line
2.25.1
#16 lore raw

PATCH v2 3/3 security: support MACsec

In reply to Akhil Goyal

Added support for MACsec in rte_security for offloading MACsec Protocol operation to inline NIC device or a crypto device.

To support MACsec we cannot just make one security session and send with the packet to process it. MACsec specifications suggest, it has 3 different entities - SECY Entity, SC(secure channel) and SA(security association). And same SA can be used by multiple SCs and similarly many SECY can have same SCs. Hence, in order to support this many to one relationships between all entities, 2 new APIs are created - rte_security_macsec_sc_create and rte_security_macsec_sa_create. Flow of execution of the APIs would be as
- rte_security_macsec_sa_create
- rte_security_macsec_sc_create
- rte_security_session_create(for secy)
And in case of inline protocol processing rte_flow can be created with rte_security action. A new flow item will be added for MACsec header. New APIs are also created for getting SC and SA stats.

---
 doc/guides/prog_guide/rte_security.rst | 107 ++++++-
 doc/guides/rel_notes/deprecation.rst   |   5 -
 doc/guides/rel_notes/release_22_11.rst |  10 +
 lib/security/rte_security.c            |  86 ++++++
 lib/security/rte_security.h            | 370 ++++++++++++++++++++++++-
 lib/security/rte_security_driver.h     |  86 ++++++
 lib/security/version.map               |   6 +
 7 files changed, 652 insertions(+), 18 deletions(-)
doc/guides/prog_guide/rte_security.rst +102 -5
index 277169a335..62e7b8d72e 100644
@@ -347,6 +347,55 @@ The CRC is Ethernet CRC-32 as specified in Ethernet/[ISO/IEC 8802-3].
     * Other DOCSIS protocol functionality such as Header Checksum (HCS)
       calculation may be added in the future.
 
+MACSEC Protocol
+~~~~~~~~~~~~~~~
+
+Media Access Control security (MACsec) provides point-to-point security on Ethernet
+links and is defined by IEEE standard 802.1AE. MACsec secures an Ethernet link for
+almost all traffic, including frames from the Link Layer Discovery Protocol (LLDP),
+Link Aggregation Control Protocol (LACP), Dynamic Host Configuration Protocol (DHCP),
+Address Resolution Protocol (ARP), and other protocols that are not typically secured
+on an Ethernet link because of limitations with other security solutions.
+
+.. code-block:: c
+
+             Receive                                                Transmit
+             -------                                                --------
+
+         Ethernet frame                                          Ethernet frame
+         from  network                                           towards network
+                |                                                      ^
+                ~                                                      |
+                |                                                      ~
+                V                                                      |
+    +-----------------------+      +------------------+      +-------------------------+
+    | Secure frame verify   |      | Cipher Suite(SA) |      | Secure Frame Generation |
+    +-----------------------+<-----+------------------+----->+-------------------------+
+    | SecTAG + ICV remove   |      |  SECY   |   SC   |      | SecTAG + ICV Added      |
+    +---+-------------------+      +------------------+      +-------------------------+
+                |                                                      ^
+                |                                                      |
+                V                                                      |
+        Packet to Core/App                                     Packet from core/App
+
+
+
+To configure MACsec on an inline NIC device or a lookaside crypto device, a security
+association(SA) and a secure channel(SC) are created before creating rte_security
+session.
+
+SA is created using API ``rte_security_macsec_sa_create`` which allows setting
+SA keys, salt, SSCI, packet number(PN) into the PMD and the API returns a handle
+which can be used to map it with a secure channel using the API
+``rte_security_macsec_sc_create``. Same SAs can be used for multiple SCs.
+The Rx SC will need a set of 4 SAs for each of the association numbers(AN).
+For Tx SC a single SA is set which will be used by hardware to process the packet.
+
+The API ``rte_security_macsec_sc_create`` returns a handle for SC and this handle
+is set in ``rte_security_macsec_xform`` to create a MACsec session using
+``rte_security_session_create``.
+
+
 Device Features and Capabilities
 ---------------------------------
 
@@ -519,6 +568,35 @@ protocol.
         RTE_CRYPTODEV_END_OF_CAPABILITIES_LIST()
     };
 
+Below is the example PMD capability for MACsec
+
+.. code-block:: c
+
+    static const struct rte_security_capability pmd_security_capabilities[] = {
+        {
+                .action = RTE_SECURITY_ACTION_TYPE_INLINE_PROTOCOL,
+                .protocol = RTE_SECURITY_PROTOCOL_MACSEC,
+                .macsec = {
+                        .mtu = 1500,
+                        .alg = RTE_SECURITY_MACSEC_ALG_GCM_128,
+                        .max_nb_sc = 64,
+                        .max_nb_sa = 128,
+                        .max_nb_sess = 64,
+                        .replay_win_sz = 4096,
+                        .relative_sectag_insert = 1,
+                        .fixed_sectag_insert = 1,
+                        .icv_include_da_sa = 1,
+                        .ctrl_port_enable = 1,
+                        .preserve_sectag = 1,
+                        .preserve_icv = 1,
+                        .validate_frames = 1,
+                        .re_key = 1,
+                        .anti_replay = 1,
+                },
+                .crypto_capabilities = NULL,
+        },
+    };
+
 Capabilities Discovery
 ~~~~~~~~~~~~~~~~~~~~~~
 
@@ -658,6 +736,8 @@ which will be updated in the future.
 
 IPsec related configuration parameters are defined in ``rte_security_ipsec_xform``
 
+MACsec related configuration parameters are defined in ``rte_security_macsec_xform``
+
 PDCP related configuration parameters are defined in ``rte_security_pdcp_xform``
 
 DOCSIS related configuration parameters are defined in ``rte_security_docsis_xform``
@@ -679,7 +759,7 @@ The ingress/egress flow attribute should match that specified in the security
 session if the security session supports the definition of the direction.
 
 Multiple flows can be configured to use the same security session. For
-example if the security session specifies an egress IPsec SA, then multiple
+example if the security session specifies an egress IPsec/MACsec SA, then multiple
 flows can be specified to that SA. In the case of an ingress IPsec SA then
 it is only valid to have a single flow to map to that security session.
 
@@ -689,8 +769,8 @@ it is only valid to have a single flow to map to that security session.
                  |
         +--------|--------+
         |    Add/Remove   |
-        |     IPsec SA    |   <------ Build security flow action of
-        |        |        |           ipsec transform
+        | IPsec/MACsec SA |   <------ Build security flow action of
+        |        |        |           IPsec/MACsec transform
         |--------|--------|
                  |
         +--------V--------+
@@ -709,9 +789,9 @@ it is only valid to have a single flow to map to that security session.
         |                 |
         +--------|--------+
 
-* Add/Delete SA flow:
+* Add/Delete IPsec SA flow:
   To add a new inline SA construct a rte_flow_item for Ethernet + IP + ESP
-  using the SA selectors and the ``rte_crypto_ipsec_xform`` as the ``rte_flow_action``.
+  using the SA selectors and the ``rte_security_ipsec_xform`` as the ``rte_flow_action``.
   Note that any rte_flow_items may be empty, which means it is not checked.
 
 .. code-block:: console
@@ -726,6 +806,23 @@ it is only valid to have a single flow to map to that security session.
         |  Eth  | ->  ... -> |   ESP  | -> | END |
         +-------+            +--------+    +-----+
 
+* Add/Delete MACsec SA flow:
+  To add a new inline SA construct a rte_flow_item for Ethernet + SecTAG
+  using the SA selectors and the ``rte_security_macsec_xform`` as the ``rte_flow_action``.
+  Note that any rte_flow_items may be empty, which means it is not checked.
+
+.. code-block:: console
+
+    In its most basic form, MACsec flow specification is as follows:
+        +-------+     +----------+     +-----+
+        |  Eth  | ->  |  SecTag  |  -> | END |
+        +-------+     +----------+     +-----+
+
+    However, the API can represent, MACsec offload with any encapsulation:
+        +-------+            +--------+    +-----+
+        |  Eth  | ->  ... -> | SecTag | -> | END |
+        +-------+            +--------+    +-----+
+
 
 Telemetry support
 -----------------
doc/guides/rel_notes/deprecation.rst +0 -5
index e83bc648fc..3915644501 100644
@@ -151,11 +151,6 @@ Deprecation Notices
   pointer for the private data to the application which can be attached
   to the packet while enqueuing.
 
-* security: MACsec support is planned to be added in DPDK 22.11,
-  which would result in updates to structures ``rte_security_macsec_xform``,
-  ``rte_security_macsec_stats`` and security capability structure
-  ``rte_security_capability`` to accommodate MACsec capabilities.
-
 * eventdev: The function ``rte_event_crypto_adapter_queue_pair_add`` will
   accept configuration of type ``rte_event_crypto_adapter_queue_conf`` instead
   of ``rte_event``, similar to ``rte_event_eth_rx_adapter_queue_add`` signature.
doc/guides/rel_notes/release_22_11.rst +10 -0
index 510485017d..701d25ffda 100644
@@ -72,6 +72,11 @@ New Features
   * Added AES-CCM support in lookaside protocol (IPsec) for CN9K & CN10K.
   * Added AES & DES DOCSIS algorithm support in lookaside crypto for CN9K.
 
+* **Added support for MACsec in rte_security.**
+
+  * Added MACsec transform for rte_security session and added new APIs to configure
+    security associations(SA) and secure channels(SC).
+
 * **Added eventdev adapter instance get API.**
 
   * Added ``rte_event_eth_rx_adapter_instance_get`` to get Rx adapter
@@ -209,6 +214,11 @@ API Changes
 * ethdev: Promoted ``rte_flow_pick_transfer_proxy()``
   from experimental to stable.
 
+* security: MACsec support is added which resulted in updates to
+  structures ``rte_security_macsec_xform``, ``rte_security_macsec_stats``
+  and security capability structure ``rte_security_capability`` to
+  accommodate MACsec capabilities.
+
 * telemetry: The allowed characters in names for dictionary values
   are now limited to alphanumeric characters and a small subset of additional
   printable characters.
lib/security/rte_security.c +86 -0

92 lines not on this page · raw message

lib/security/rte_security.h +362 -8

422 lines not on this page · raw message

lib/security/rte_security_driver.h +86 -0

104 lines not on this page · raw message

lib/security/version.map +6 -0
index 85ca7921e7..07dcce9ffb 100644
@@ -15,6 +15,12 @@ EXPERIMENTAL {
 
 	__rte_security_set_pkt_metadata;
 	rte_security_dynfield_offset;
+	rte_security_macsec_sa_create;
+	rte_security_macsec_sa_destroy;
+	rte_security_macsec_sa_stats_get;
+	rte_security_macsec_sc_create;
+	rte_security_macsec_sc_destroy;
+	rte_security_macsec_sc_stats_get;
 	rte_security_session_stats_get;
 	rte_security_session_update;
 };
Signature · 1 line
2.25.1
#17 lore raw

cover Support and test inline MACsec for cnxk

These patches implement the rte_security MACsec APIs for net/cnxk and also add test cases to test functionality.

MACsec APIs are introduced in http://patches.dpdk.org/project/dpdk/list/?series=24878

depends-on: http://patches.dpdk.org/project/dpdk/list/?series=24878

The patches are sent to showcase sample implementation and are not complete. Final patches will be sent in next few weeks.

Akhil Goyal (5):
common/cnxk: add ROC APIs for MACsec
common/cnxk: derive hash key for MACsec
net/cnxk: support MACsec
test/security: add inline MACsec cases
test/security: add more MACsec cases

 app/test/meson.build                          |    1 +
 app/test/test_security_inline_macsec.c        | 1126 +++++++
 .../test_security_inline_macsec_vectors.h     | 2639 +++++++++++++++++
 drivers/common/cnxk/meson.build               |    3 +
 drivers/common/cnxk/roc_aes.c                 |   17 +
 drivers/common/cnxk/roc_aes.h                 |    2 +
 drivers/common/cnxk/roc_api.h                 |    3 +
 drivers/common/cnxk/roc_dev.c                 |   86 +
 drivers/common/cnxk/roc_mbox.h                |  361 ++-
 drivers/common/cnxk/roc_mcs.c                 |  347 +++
 drivers/common/cnxk/roc_mcs.h                 |  431 +++
 drivers/common/cnxk/roc_mcs_priv.h            |   52 +
 drivers/common/cnxk/roc_mcs_sec_cfg.c         |  425 +++
 drivers/common/cnxk/roc_mcs_stats.c           |  230 ++
 drivers/common/cnxk/roc_priv.h                |    3 +
 drivers/common/cnxk/version.map               |   34 +
 drivers/net/cnxk/cn10k_ethdev_mcs.c           |  407 +++
 drivers/net/cnxk/cn10k_ethdev_mcs.h           |   59 +
 drivers/net/cnxk/cn10k_ethdev_sec.c           |   11 +-
 drivers/net/cnxk/cn10k_flow.c                 |   14 +
 drivers/net/cnxk/cnxk_ethdev.h                |   31 +
 drivers/net/cnxk/cnxk_ethdev_sec.c            |    2 +-
 drivers/net/cnxk/meson.build                  |    1 +
 23 files changed, 6280 insertions(+), 5 deletions(-)
 create mode 100644 app/test/test_security_inline_macsec.c
 create mode 100644 app/test/test_security_inline_macsec_vectors.h
 create mode 100644 drivers/common/cnxk/roc_mcs.c
 create mode 100644 drivers/common/cnxk/roc_mcs.h
 create mode 100644 drivers/common/cnxk/roc_mcs_priv.h
 create mode 100644 drivers/common/cnxk/roc_mcs_sec_cfg.c
 create mode 100644 drivers/common/cnxk/roc_mcs_stats.c
 create mode 100644 drivers/net/cnxk/cn10k_ethdev_mcs.c
 create mode 100644 drivers/net/cnxk/cn10k_ethdev_mcs.h
Signature · 1 line
2.25.1
#18 lore raw

PATCH 1/5 common/cnxk: add ROC APIs for MACsec

Added mbox related to configuration of MACsec.

---
 drivers/common/cnxk/meson.build       |   3 +
 drivers/common/cnxk/roc_api.h         |   3 +
 drivers/common/cnxk/roc_dev.c         |  86 +++++
 drivers/common/cnxk/roc_mbox.h        | 361 ++++++++++++++++++++-
 drivers/common/cnxk/roc_mcs.c         | 347 +++++++++++++++++++++
 drivers/common/cnxk/roc_mcs.h         | 431 ++++++++++++++++++++++++++
 drivers/common/cnxk/roc_mcs_priv.h    |  52 ++++
 drivers/common/cnxk/roc_mcs_sec_cfg.c | 425 +++++++++++++++++++++++++
 drivers/common/cnxk/roc_mcs_stats.c   | 230 ++++++++++++++
 drivers/common/cnxk/roc_priv.h        |   3 +
 drivers/common/cnxk/version.map       |  33 ++
 11 files changed, 1971 insertions(+), 3 deletions(-)
 create mode 100644 drivers/common/cnxk/roc_mcs.c
 create mode 100644 drivers/common/cnxk/roc_mcs.h
 create mode 100644 drivers/common/cnxk/roc_mcs_priv.h
 create mode 100644 drivers/common/cnxk/roc_mcs_sec_cfg.c
 create mode 100644 drivers/common/cnxk/roc_mcs_stats.c
drivers/common/cnxk/meson.build +3 -0
index 127fcbcdc5..02264016e3 100644
@@ -26,6 +26,9 @@ sources = files(
         'roc_irq.c',
         'roc_ie_ot.c',
         'roc_mbox.c',
+        'roc_mcs.c',
+	'roc_mcs_sec_cfg.c',
+        'roc_mcs_stats.c',
         'roc_model.c',
         'roc_nix.c',
         'roc_nix_bpf.c',
drivers/common/cnxk/roc_api.h +3 -0
index 072f16d77d..bcc8746927 100644
@@ -106,4 +106,7 @@
 /* NIX Inline dev */
 #include "roc_nix_inl.h"
 
+/* MACsec */
+#include "roc_mcs.h"
+
 #endif /* _ROC_API_H_ */
drivers/common/cnxk/roc_dev.c +86 -0

98 lines not on this page · raw message

drivers/common/cnxk/roc_mbox.h +358 -3

380 lines not on this page · raw message

drivers/common/cnxk/roc_mcs.c new file +347 -0

347 lines not on this page · raw message

drivers/common/cnxk/roc_mcs.h new file +431 -0

431 lines not on this page · raw message

drivers/common/cnxk/roc_mcs_priv.h new file +52 -0

52 lines not on this page · raw message

drivers/common/cnxk/roc_mcs_sec_cfg.c new file +425 -0

425 lines not on this page · raw message

drivers/common/cnxk/roc_mcs_stats.c new file +230 -0

230 lines not on this page · raw message

drivers/common/cnxk/roc_priv.h +3 -0
index 122d411fe7..b2b4aecedc 100644
@@ -44,6 +44,9 @@
 /* DPI */
 #include "roc_dpi_priv.h"
 
+/* MCS */
+#include "roc_mcs_priv.h"
+
 /* REE */
 #include "roc_ree_priv.h"
 
drivers/common/cnxk/version.map +33 -0
index 276fec3660..5cdc70e0e0 100644
@@ -99,6 +99,39 @@ INTERNAL {
 	roc_model;
 	roc_se_auth_key_set;
 	roc_se_ciph_key_set;
+	roc_mcs_active_lmac_set;
+	roc_mcs_alloc_rsrc;
+	roc_mcs_dev_init;
+	roc_mcs_dev_fini;
+	roc_mcs_dev_get;
+	roc_mcs_event_cb_register;
+	roc_mcs_event_cb_unregister;
+	roc_mcs_flowid_entry_enable;
+	roc_mcs_flowid_entry_read;
+	roc_mcs_flowid_entry_write;
+	roc_mcs_flowid_stats_get;
+	roc_mcs_free_rsrc;
+	roc_mcs_hw_info_get;
+	roc_mcs_intr_configure;
+	roc_mcs_lmac_mode_set;
+	roc_mcs_pn_table_write;
+	roc_mcs_pn_table_read;
+	roc_mcs_port_stats_get;
+	roc_mcs_rx_sc_cam_enable;
+	roc_mcs_rx_sc_cam_read;
+	roc_mcs_rx_sc_cam_write;
+	roc_mcs_rx_sc_sa_map_read;
+	roc_mcs_rx_sc_sa_map_write;
+	roc_mcs_sa_policy_read;
+	roc_mcs_sa_policy_write;
+	roc_mcs_sa_stats_get;
+	roc_mcs_sc_stats_get;
+	roc_mcs_secy_policy_read;
+	roc_mcs_secy_policy_write;
+	roc_mcs_secy_stats_get;
+	roc_mcs_stats_clear;
+	roc_mcs_tx_sc_sa_map_read;
+	roc_mcs_tx_sc_sa_map_write;
 	roc_nix_bpf_alloc;
 	roc_nix_bpf_config;
 	roc_nix_bpf_connect;
Signature · 1 line
2.25.1
#19 lore raw

PATCH 2/5 common/cnxk: derive hash key for MACsec

In reply to Akhil Goyal
---
 drivers/common/cnxk/roc_aes.c   | 17 +++++++++++++++++
 drivers/common/cnxk/roc_aes.h   |  2 ++
 drivers/common/cnxk/version.map |  1 +
 3 files changed, 20 insertions(+)
drivers/common/cnxk/roc_aes.c +17 -0
index f821c8b710..f69ecc1d58 100644
@@ -206,3 +206,20 @@ roc_aes_xcbc_key_derive(const uint8_t *auth_key, uint8_t *derived_key)
 
 	cipher(k3, derived_key, aes_ks);
 }
+
+void
+roc_aes_hash_key_derive(const uint8_t *key, uint16_t len, uint8_t hash_key[])
+{
+	uint32_t aes_ks[KEY_SCHEDULE_LEN] = {0};
+	uint8_t data[16] = {0x0};
+	int i;
+
+	if (len == 16) {
+		aes_key_expand(key, aes_ks);
+		cipher(data, hash_key, aes_ks);
+		for (i = 0; i < 16; i++)
+			plt_info(" 0x%x", hash_key[i]);
+	} else {
+		plt_err("\n AES-256 key conversion not supported");
+	}
+}
drivers/common/cnxk/roc_aes.h +2 -0
index 954039139f..e3f6160e7c 100644
@@ -10,5 +10,7 @@
  */
 void __roc_api roc_aes_xcbc_key_derive(const uint8_t *auth_key,
 				       uint8_t *derived_key);
+void __roc_api roc_aes_hash_key_derive(const uint8_t *key, uint16_t len,
+				       uint8_t *hash_key);
 
 #endif /* _ROC_AES_H_ */
drivers/common/cnxk/version.map +1 -0
index 5cdc70e0e0..38bf832388 100644
@@ -29,6 +29,7 @@ INTERNAL {
 	roc_ae_ec_grp_put;
 	roc_ae_fpm_get;
 	roc_ae_fpm_put;
+	roc_aes_hash_key_derive;
 	roc_aes_xcbc_key_derive;
 	roc_bphy_cgx_cpri_mode_change;
 	roc_bphy_cgx_cpri_mode_misc;
Signature · 1 line
2.25.1
#20 lore raw

PATCH 3/5 net/cnxk: support MACsec

In reply to Akhil Goyal
---
 drivers/net/cnxk/cn10k_ethdev_mcs.c | 407 ++++++++++++++++++++++++++++
 drivers/net/cnxk/cn10k_ethdev_mcs.h |  59 ++++
 drivers/net/cnxk/cn10k_ethdev_sec.c |  11 +-
 drivers/net/cnxk/cn10k_flow.c       |  14 +
 drivers/net/cnxk/cnxk_ethdev.h      |  31 +++
 drivers/net/cnxk/cnxk_ethdev_sec.c  |   2 +-
 drivers/net/cnxk/meson.build        |   1 +
 7 files changed, 523 insertions(+), 2 deletions(-)
 create mode 100644 drivers/net/cnxk/cn10k_ethdev_mcs.c
 create mode 100644 drivers/net/cnxk/cn10k_ethdev_mcs.h
drivers/net/cnxk/cn10k_ethdev_mcs.c new file +407 -0
new file mode 100644
index 0000000000..90363f8e17
@@ -0,0 +1,407 @@
+/* SPDX-License-Identifier: BSD-3-Clause
+ * Copyright(C) 2022 Marvell.
+ */
+
+#include <cnxk_ethdev.h>
+#include <cn10k_ethdev_mcs.h>
+#include <roc_mcs.h>
+
+static int
+mcs_resource_alloc(struct cnxk_mcs_dev *mcs_dev, enum rte_security_macsec_direction dir,
+		   uint8_t rsrc_id[], uint8_t rsrc_cnt, enum cnxk_mcs_rsrc_type type)
+{
+	struct roc_mcs_alloc_rsrc_req req = {0};
+	struct roc_mcs_alloc_rsrc_rsp rsp = {0};
+	int i;
+
+	req.rsrc_type = type;
+	req.rsrc_cnt = rsrc_cnt;
+	req.mcs_id = mcs_dev->idx;
+	req.dir = dir;
+
+	if (roc_mcs_alloc_rsrc(mcs_dev->mdev, &req, &rsp)) {
+		printf("error: Cannot allocate mcs resource.\n");
+		return -1;
+	}
+
+	for (i = 0; i < rsrc_cnt; i++) {
+		switch (rsp.rsrc_type) {
+		case CNXK_MCS_RSRC_TYPE_FLOWID:
+			rsrc_id[i] = rsp.flow_ids[i];
+			break;
+		case CNXK_MCS_RSRC_TYPE_SECY:
+			rsrc_id[i] = rsp.secy_ids[i];
+			break;
+		case CNXK_MCS_RSRC_TYPE_SC:
+			rsrc_id[i] = rsp.sc_ids[i];
+			break;
+		case CNXK_MCS_RSRC_TYPE_SA:
+			rsrc_id[i] = rsp.sa_ids[i];
+			break;
+		default :
+			printf("error: Invalid mcs resource allocated.\n");
+			return -1;
+		}
+	}
+	return 0;
+}
+
+int
+cn10k_eth_macsec_sa_create(void *device, struct rte_security_macsec_sa *conf)
+{
+	struct rte_eth_dev *eth_dev = (struct rte_eth_dev *)device;
+	struct cnxk_eth_dev *dev = cnxk_eth_pmd_priv(eth_dev);
+	struct cnxk_mcs_dev *mcs_dev = dev->mcs_dev;
+	struct roc_mcs_pn_table_write_req pn_req = {0};
+	struct roc_mcs_sa_plcy_write_req req = {0};
+	uint8_t hash_key[16] = {0};
+	uint8_t sa_id = 0;
+	int ret = 0;
+
+	ret = mcs_resource_alloc(mcs_dev, conf->dir, &sa_id, 1, CNXK_MCS_RSRC_TYPE_SA);
+	if (ret) {
+		printf("Failed to allocate SA id.\n");
+		return -ENOMEM;
+	}
+	req.sa_index[0] = sa_id;
+	req.sa_cnt = 1;
+	req.mcs_id = mcs_dev->idx;
+	req.dir = conf->dir;
+
+	if (conf->key.length != 16 || conf->key.length != 32)
+		return -EINVAL;
+
+	memcpy(&req.plcy[0][0], conf->key.data, conf->key.length);
+	roc_aes_hash_key_derive(conf->key.data, conf->key.length, hash_key);
+	memcpy(&req.plcy[0][4], hash_key, CNXK_MACSEC_HASH_KEY);
+	memcpy(&req.plcy[0][6], conf->salt, RTE_SECURITY_MACSEC_SALT_LEN);
+	req.plcy[0][7] |= (uint64_t)conf->ssci << 32;
+	req.plcy[0][8] = conf->an & 0x3;
+
+	ret = roc_mcs_sa_policy_write(mcs_dev->mdev, &req);
+	if (ret) {
+		printf("Failed to write SA policy.\n");
+		return -EINVAL;
+	}
+
+	pn_req.next_pn = conf->next_pn;
+	pn_req.pn_id = sa_id;
+	pn_req.mcs_id = mcs_dev->idx;
+	pn_req.dir = conf->dir;
+
+	ret = roc_mcs_pn_table_write(mcs_dev->mdev, &pn_req);
+	if (ret) {
+		printf("Failed to write PN table.\n");
+		return -EINVAL;
+	}
+
+	return sa_id;
+}
+
+int
+cn10k_eth_macsec_sa_destroy(void *device, uint16_t sa_id)
+{
+	RTE_SET_USED(device);
+	RTE_SET_USED(sa_id);
+
+	return 0;
+}
+
+int
+cn10k_eth_macsec_sc_create(void *device, struct rte_security_macsec_sc *conf)
+{
+	struct rte_eth_dev *eth_dev = (struct rte_eth_dev *)device;
+	struct cnxk_eth_dev *dev = cnxk_eth_pmd_priv(eth_dev);
+	struct cnxk_mcs_dev *mcs_dev = dev->mcs_dev;
+	uint8_t sc_id = 0;
+	int i, ret = 0;
+
+	ret = mcs_resource_alloc(mcs_dev, conf->dir, &sc_id, 1, CNXK_MCS_RSRC_TYPE_SC);
+	if (ret) {
+		printf("Failed to allocate SC id.\n");
+		return -ENOMEM;
+	}
+
+	if (conf->dir == RTE_SECURITY_MACSEC_DIR_TX) {
+		struct roc_mcs_tx_sc_sa_map req = {0};
+
+		req.mcs_id = mcs_dev->idx;
+		req.sa_index0 = conf->sc_tx.sa_id & 0x7F;
+		req.sa_index1 = conf->sc_tx.sa_id_rekey & 0x7F;
+		req.rekey_ena = conf->sc_tx.re_key_en;
+		req.sa_index0_vld = conf->sc_tx.active;
+		req.sa_index1_vld = conf->sc_tx.re_key_en && conf->sc_tx.active;
+		req.tx_sa_active = conf->sc_tx.active;
+		req.sectag_sci = conf->sc_tx.sci;
+		req.sc_id = sc_id;
+		req.mcs_id = mcs_dev->idx;
+
+		ret = roc_mcs_tx_sc_sa_map_write(mcs_dev->mdev, &req);
+		if (ret) {
+			printf("Failed to map TX SC-SA");
+			return -EINVAL;
+		}
+	} else {
+		for (i = 0; i < RTE_SECURITY_MACSEC_NUM_AN; i++) {
+			struct roc_mcs_rx_sc_sa_map req = {0};
+
+			req.mcs_id = mcs_dev->idx;
+			req.sa_index = conf->sc_rx.sa_id[i] & 0x7F;
+			req.sa_in_use = conf->sc_rx.sa_in_use[i];
+			req.sc_id = sc_id;
+			req.an = i & 0x3;
+			req.mcs_id = mcs_dev->idx;
+			ret = roc_mcs_rx_sc_sa_map_write(mcs_dev->mdev, &req);
+			if (ret) {
+				printf("Failed to map RX SC-SA");
+				return -EINVAL;
+			}
+		}
+	}
+	return sc_id;
+}
+
+int
+cn10k_eth_macsec_sc_destroy(void *device, uint16_t sc_id)
+{
+	RTE_SET_USED(device);
+	RTE_SET_USED(sc_id);
+
+	return 0;
+}
+
+struct cnxk_macsec_sess *
+cnxk_eth_macsec_sess_get_by_sess(struct cnxk_eth_dev *dev,
+				 const struct rte_security_session *sess)
+{
+	struct cnxk_macsec_sess *macsec_sess = NULL;
+
+	TAILQ_FOREACH(macsec_sess, &dev->mcs_list, entry) {
+		if (macsec_sess->sess == sess)
+			return macsec_sess;
+	}
+
+	return NULL;
+}
+
+int
+cn10k_eth_macsec_session_create(struct cnxk_eth_dev *dev,
+				struct rte_security_session_conf *conf,
+				struct rte_security_session *sess,
+				struct rte_mempool *mempool)
+{
+	struct rte_security_macsec_xform *xform = &conf->macsec;
+	struct cnxk_macsec_sess *macsec_sess_priv;
+	struct roc_mcs_secy_plcy_write_req req;
+	struct cnxk_mcs_dev *mcs_dev = dev->mcs_dev;
+	uint8_t secy_id = 0;
+	uint8_t sectag_tci = 0;
+	int ret = 0;
+
+	ret = mcs_resource_alloc(mcs_dev, xform->dir, &secy_id, 1, CNXK_MCS_RSRC_TYPE_SECY);
+	if (ret) {
+		printf("Failed to allocate SECY id.\n");
+		return -ENOMEM;
+	}
+
+	req.secy_id = secy_id;
+	req.mcs_id = mcs_dev->idx;
+	req.dir = xform->dir;
+	req.plcy = 0L;
+
+	if (xform->dir == RTE_SECURITY_MACSEC_DIR_TX) {
+		sectag_tci = ((uint8_t)xform->tx_secy.sectag_version << 5) |
+				((uint8_t)xform->tx_secy.end_station << 4) |
+				((uint8_t)xform->tx_secy.send_sci << 3) |
+				((uint8_t)xform->tx_secy.scb << 2) |
+				((uint8_t)xform->tx_secy.encrypt << 1) |
+				(uint8_t)xform->tx_secy.encrypt;
+		req.plcy = ((uint64_t)xform->tx_secy.mtu << 48) |
+			   (((uint64_t)sectag_tci & 0x3F) << 40) |
+			   (((uint64_t)xform->tx_secy.sectag_off & 0x7F) << 32) |
+			   ((uint64_t)xform->tx_secy.sectag_insert_mode << 30) |
+			   ((uint64_t)xform->tx_secy.icv_include_da_sa << 28) |
+			   (((uint64_t)xform->cipher_off & 0x7F) << 20) |
+			   ((uint64_t)xform->alg << 12) |
+			   ((uint64_t)xform->tx_secy.protect_frames << 4) |
+			   (uint64_t)xform->tx_secy.ctrl_port_enable;
+	} else {
+		req.plcy = ((uint64_t)xform->rx_secy.replay_win_sz << 32) |
+			   ((uint64_t)xform->rx_secy.replay_protect << 30) |
+			   ((uint64_t)xform->rx_secy.icv_include_da_sa << 28) |
+			   (((uint64_t)xform->cipher_off & 0x7F) << 20) |
+			   ((uint64_t)xform->alg << 12) |
+			   ((uint64_t)xform->rx_secy.preserve_sectag << 9) |
+			   ((uint64_t)xform->rx_secy.preserve_icv << 8) |
+			   ((uint64_t)xform->rx_secy.validate_frames << 4) |
+			   (uint64_t)xform->rx_secy.ctrl_port_enable;
+	}
+
+	ret = roc_mcs_secy_policy_write(mcs_dev->mdev, &req);
+	if (ret) {
+		printf("\n Failed to configure SECY");
+		return -EINVAL;
+	}
+
+	/*get session priv*/
+	if (rte_mempool_get(mempool, (void **)&macsec_sess_priv)) {
+		plt_err("Could not allocate security session private data");
+		return -ENOMEM;
+	}
+
+	macsec_sess_priv->sci = xform->sci;
+	macsec_sess_priv->sc_id = xform->sc_id;
+	macsec_sess_priv->secy_id = secy_id;
+	macsec_sess_priv->dir = xform->dir;
+
+	TAILQ_INSERT_TAIL(&dev->mcs_list, macsec_sess_priv, entry);
+	set_sec_session_private_data(sess, (void *)macsec_sess_priv);
+
+	return 0;
+}
+
+int
+cn10k_eth_macsec_session_destroy(void *device, struct rte_security_session *sess)
+{
+	RTE_SET_USED(device);
+	RTE_SET_USED(sess);
+
+	return 0;
+}
+
+int
+cn10k_mcs_flow_configure(struct rte_eth_dev *eth_dev,
+			 const struct rte_flow_attr *attr __rte_unused,
+			 const struct rte_flow_item pattern[],
+			 const struct rte_flow_action actions[],
+			 struct rte_flow_error *error __rte_unused,
+			 void **mcs_flow)
+{
+	struct cnxk_eth_dev *dev = cnxk_eth_pmd_priv(eth_dev);
+	struct roc_mcs_flowid_entry_write_req req = {0};
+	struct cnxk_mcs_dev *mcs_dev = dev->mcs_dev;
+	struct cnxk_mcs_flow_opts opts = {0};
+	struct cnxk_macsec_sess *sess = cnxk_eth_macsec_sess_get_by_sess(dev,
+			(const struct rte_security_session *)actions->conf);
+	const struct rte_flow_item_eth *eth_item = NULL;
+	struct rte_ether_addr src;
+	struct rte_ether_addr dst;
+	int ret;
+	int i = 0;
+
+	ret = mcs_resource_alloc(mcs_dev, sess->dir, &(sess->flow_id), 1, CNXK_MCS_RSRC_TYPE_FLOWID);
+	if (ret) {
+		printf("Failed to allocate FLow id.\n");
+		return -ENOMEM;
+	}
+	req.sci = sess->sci;
+	req.flow_id = sess->flow_id;
+	req.secy_id = sess->secy_id;
+	req.sc_id = sess->sc_id;
+	req.ena = 1;
+	req.ctr_pkt = 0; /* TBD */
+	req.mcs_id = mcs_dev->idx;
+	req.dir = sess->dir;
+
+	while (pattern[i].type != RTE_FLOW_ITEM_TYPE_END) {
+		if (pattern[i].type == RTE_FLOW_ITEM_TYPE_ETH)
+			eth_item = pattern[i].spec;
+		else
+			printf("%s:%d unhandled flow item : %d", __func__, __LINE__,
+					pattern[i].type);
+		i++;
+	}
+	if (eth_item) {
+		dst = eth_item->hdr.dst_addr;
+		src = eth_item->hdr.src_addr;
+
+		/* Find ways to fill opts */
+
+		req.data[0] = (uint64_t)dst.addr_bytes[0] << 40 | (uint64_t)dst.addr_bytes[1] << 32 |
+			      (uint64_t)dst.addr_bytes[2] << 24 | (uint64_t)dst.addr_bytes[3] << 16 |
+			      (uint64_t)dst.addr_bytes[4] << 8 | (uint64_t)dst.addr_bytes[5] |
+			      (uint64_t)src.addr_bytes[5] << 48 | (uint64_t)src.addr_bytes[4] << 56;
+		req.data[1] = (uint64_t)src.addr_bytes[3] | (uint64_t)src.addr_bytes[2] << 8 |
+			      (uint64_t)src.addr_bytes[1] << 16 | (uint64_t)src.addr_bytes[0] << 24 |
+			      (uint64_t)eth_item->hdr.ether_type << 32 |
+			      ((uint64_t)opts.outer_tag_id & 0xFFFF) << 48;
+		req.data[2] = ((uint64_t)opts.outer_tag_id & 0xF0000) |
+			      ((uint64_t)opts.outer_priority & 0xF) << 4 |
+			      ((uint64_t)opts.second_outer_tag_id & 0xFFFFF) << 8 |
+			      ((uint64_t)opts.second_outer_priority & 0xF) << 28 |
+			      ((uint64_t)opts.bonus_data << 32) |
+			      ((uint64_t)opts.tag_match_bitmap << 48) |
+			      ((uint64_t)opts.packet_type & 0xF) << 56 |
+			      ((uint64_t)opts.outer_vlan_type & 0x7) << 60 |
+			      ((uint64_t)opts.inner_vlan_type & 0x1) << 63;
+		req.data[3] = ((uint64_t)opts.inner_vlan_type & 0x6) |
+			      ((uint64_t)opts.num_tags & 0x7F) << 2 | ((uint64_t)opts.express & 1) << 9 |
+			      ((uint64_t)opts.port & 0x3) << 10 |
+			      ((uint64_t)opts.flowid_user & 0xF) << 12;
+
+		req.mask[0] = 0x0;
+		req.mask[1] = 0xFFFFFFFF00000000;
+		req.mask[2] = 0xFFFFFFFFFFFFFFFF;
+		req.mask[3] = 0xFFFFFFFFFFFFF3FF;
+
+		ret = roc_mcs_flowid_entry_write(mcs_dev->mdev, &req);
+		if (ret)
+			return ret;
+
+		*mcs_flow = &req;
+	} else {
+		printf("\nFlow not confirured");
+		return -EINVAL;
+	}
+	return 0;
+}
+
+int
+cn10k_eth_macsec_sa_stats_get(void *device, uint16_t sa_id,
+			    struct rte_security_macsec_sa_stats *stats)
+{
+	RTE_SET_USED(device);
+	RTE_SET_USED(sa_id);
+	RTE_SET_USED(stats);
+
+	return 0;
+}
+
+int
+cn10k_eth_macsec_sc_stats_get(void *device, uint16_t sc_id,
+			    struct rte_security_macsec_sc_stats *stats)
+{
+	RTE_SET_USED(device);
+	RTE_SET_USED(sc_id);
+	RTE_SET_USED(stats);
+
+	return 0;
+}
+
+void
+cnxk_mcs_dev_fini(struct cnxk_mcs_dev *mcs_dev)
+{
+	/* Cleanup MACsec dev */
+	roc_mcs_dev_fini(mcs_dev->mdev);
+
+	plt_free(mcs_dev);
+}
+
+struct cnxk_mcs_dev *
+cnxk_mcs_dev_init(uint8_t mcs_idx)
+{
+	struct cnxk_mcs_dev *mcs_dev;
+
+	mcs_dev = plt_zmalloc(sizeof(struct cnxk_mcs_dev), PLT_CACHE_LINE_SIZE);
+	if (!mcs_dev)
+		return NULL;
+
+	mcs_dev->mdev = roc_mcs_dev_init(mcs_dev->idx);
+	if (!mcs_dev->mdev) {
+		plt_free(mcs_dev);
+		return NULL;
+	}
+	mcs_dev->idx = mcs_idx;
+
+	return mcs_dev;
+}
drivers/net/cnxk/cn10k_ethdev_mcs.h new file +59 -0

59 lines not on this page · raw message

drivers/net/cnxk/cn10k_ethdev_sec.c +10 -1
index 3795b0c78b..70fb1eb39a 100644
@@ -9,6 +9,7 @@
 #include <rte_pmd_cnxk.h>
 
 #include <cn10k_ethdev.h>
+#include <cn10k_ethdev_mcs.h>
 #include <cnxk_security.h>
 #include <roc_priv.h>
 
@@ -601,7 +602,9 @@ cn10k_eth_sec_session_create(void *device,
 	if (conf->action_type != RTE_SECURITY_ACTION_TYPE_INLINE_PROTOCOL)
 		return -ENOTSUP;
 
-	if (conf->protocol != RTE_SECURITY_PROTOCOL_IPSEC)
+	if (conf->protocol == RTE_SECURITY_PROTOCOL_MACSEC)
+		return cn10k_eth_macsec_session_create(dev, conf, sess, mempool);
+	else if (conf->protocol != RTE_SECURITY_PROTOCOL_IPSEC)
 		return -ENOTSUP;
 
 	if (rte_security_dynfield_register() < 0)
@@ -1058,9 +1061,15 @@ cn10k_eth_sec_ops_override(void)
 	init_once = 1;
 
 	/* Update platform specific ops */
+	cnxk_eth_sec_ops.macsec_sa_create = cn10k_eth_macsec_sa_create;
+	cnxk_eth_sec_ops.macsec_sc_create = cn10k_eth_macsec_sc_create;
+	cnxk_eth_sec_ops.macsec_sa_destroy = cn10k_eth_macsec_sa_destroy;
+	cnxk_eth_sec_ops.macsec_sc_destroy = cn10k_eth_macsec_sc_destroy;
 	cnxk_eth_sec_ops.session_create = cn10k_eth_sec_session_create;
 	cnxk_eth_sec_ops.session_destroy = cn10k_eth_sec_session_destroy;
 	cnxk_eth_sec_ops.capabilities_get = cn10k_eth_sec_capabilities_get;
 	cnxk_eth_sec_ops.session_update = cn10k_eth_sec_session_update;
 	cnxk_eth_sec_ops.session_stats_get = cn10k_eth_sec_session_stats_get;
+	cnxk_eth_sec_ops.macsec_sc_stats_get = cn10k_eth_macsec_sc_stats_get;
+	cnxk_eth_sec_ops.macsec_sa_stats_get = cn10k_eth_macsec_sa_stats_get;
 }
drivers/net/cnxk/cn10k_flow.c +14 -0
index 7df879a2bb..e95a73ec55 100644
@@ -2,6 +2,7 @@
  * Copyright(C) 2020 Marvell.
  */
 #include <cnxk_flow.h>
+#include "cn10k_ethdev_mcs.h"
 #include "cn10k_flow.h"
 #include "cn10k_ethdev.h"
 #include "cn10k_rx.h"
@@ -133,6 +134,7 @@ cn10k_flow_create(struct rte_eth_dev *eth_dev, const struct rte_flow_attr *attr,
 	const struct rte_flow_action *act_q = NULL;
 	struct roc_npc *npc = &dev->npc;
 	struct roc_npc_flow *flow;
+	void *mcs_flow = NULL;
 	int vtag_actions = 0;
 	uint32_t req_act = 0;
 	int i, rc;
@@ -186,6 +188,18 @@ cn10k_flow_create(struct rte_eth_dev *eth_dev, const struct rte_flow_attr *attr,
 		}
 	}
 
+	if (actions[0].type == RTE_FLOW_ACTION_TYPE_SECURITY &&
+			cnxk_eth_macsec_sess_get_by_sess(dev, actions[0].conf) != NULL) {
+		rc = cn10k_mcs_flow_configure(eth_dev, attr, pattern, actions, error, &mcs_flow);
+		if (rc) {
+			rte_flow_error_set(error, rc,
+					RTE_FLOW_ERROR_TYPE_ACTION, NULL,
+					"Failed to configure mcs flow");
+			return NULL;
+		}
+		return (struct rte_flow *)mcs_flow;
+	}
+
 	flow = cnxk_flow_create(eth_dev, attr, pattern, actions, error);
 	if (!flow) {
 		if (mtr)
drivers/net/cnxk/cnxk_ethdev.h +31 -0
index c09e9bff8e..4ae64060f1 100644
@@ -337,6 +337,21 @@ struct cnxk_eth_dev_sec_outb {
 	rte_spinlock_t lock;
 };
 
+/* MACsec session private data */
+struct cnxk_macsec_sess {
+	/* List entry */
+	TAILQ_ENTRY(cnxk_macsec_sess) entry;
+
+	/* Back pointer to session */
+	struct rte_security_session *sess;
+	enum rte_security_macsec_direction dir;
+	uint64_t sci;
+	uint8_t secy_id;
+	uint8_t sc_id;
+	uint8_t flow_id;
+};
+TAILQ_HEAD(cnxk_macsec_sess_list, cnxk_macsec_sess);
+
 struct cnxk_eth_dev {
 	/* ROC NIX */
 	struct roc_nix nix;
@@ -437,6 +452,10 @@ struct cnxk_eth_dev {
 	/* Reassembly dynfield/flag offsets */
 	int reass_dynfield_off;
 	int reass_dynflag_bit;
+
+	/* MCS device */
+	struct cnxk_mcs_dev *mcs_dev;
+	struct cnxk_macsec_sess_list mcs_list;
 };
 
 struct cnxk_eth_rxq_sp {
@@ -649,6 +668,18 @@ cnxk_eth_sec_sess_get_by_sess(struct cnxk_eth_dev *dev,
 int cnxk_nix_inl_meta_pool_cb(uint64_t *aura_handle, uint32_t buf_sz, uint32_t nb_bufs,
 			      bool destroy);
 
+struct cnxk_mcs_dev * cnxk_mcs_dev_init(uint8_t mcs_idx);
+void cnxk_mcs_dev_fini(struct cnxk_mcs_dev *mcs_dev);
+
+struct cnxk_macsec_sess *
+cnxk_eth_macsec_sess_get_by_sess(struct cnxk_eth_dev *dev,
+				 const struct rte_security_session *sess);
+int cn10k_mcs_flow_configure(struct rte_eth_dev *eth_dev,
+			     const struct rte_flow_attr *attr,
+			     const struct rte_flow_item pattern[],
+			     const struct rte_flow_action actions[],
+			     struct rte_flow_error *error, void **mcs_flow);
+
 /* Other private functions */
 int nix_recalc_mtu(struct rte_eth_dev *eth_dev);
 int nix_mtr_validate(struct rte_eth_dev *dev, uint32_t id);
drivers/net/cnxk/cnxk_ethdev_sec.c +1 -1
index 9304b1465d..56fb2733a4 100644
@@ -203,7 +203,7 @@ cnxk_eth_sec_sess_get_by_sess(struct cnxk_eth_dev *dev,
 static unsigned int
 cnxk_eth_sec_session_get_size(void *device __rte_unused)
 {
-	return sizeof(struct cnxk_eth_sec_sess);
+	return RTE_MAX(sizeof(struct cnxk_macsec_sess), sizeof(struct cnxk_eth_sec_sess));
 }
 
 struct rte_security_ops cnxk_eth_sec_ops = {
drivers/net/cnxk/meson.build +1 -0
index f347e98fce..34bba3fb23 100644
@@ -106,6 +106,7 @@ sources += files(
 # CN10K
 sources += files(
         'cn10k_ethdev.c',
+        'cn10k_ethdev_mcs.c',
         'cn10k_ethdev_sec.c',
         'cn10k_flow.c',
         'cn10k_rx_select.c',
Signature · 1 line
2.25.1
#21 lore raw

PATCH 4/5 test/security: add inline MACsec cases

In reply to Akhil Goyal

Added MACsec inline cases for encryption cases.

---
 app/test/meson.build                          |    1 +
 app/test/test_security_inline_macsec.c        |  821 ++++++
 .../test_security_inline_macsec_vectors.h     | 2318 +++++++++++++++++
 3 files changed, 3140 insertions(+)
 create mode 100644 app/test/test_security_inline_macsec.c
 create mode 100644 app/test/test_security_inline_macsec_vectors.h
app/test/meson.build +1 -0
index d5cad72116..928df22014 100644
@@ -126,6 +126,7 @@ test_sources = files(
         'test_rwlock.c',
         'test_sched.c',
         'test_security.c',
+        'test_security_inline_macsec.c',
         'test_security_inline_proto.c',
         'test_seqlock.c',
         'test_service_cores.c',
app/test/test_security_inline_macsec.c new file +821 -0

821 lines not on this page · raw message

app/test/test_security_inline_macsec_vectors.h new file +2318 -0

2,172 lines not on this page · raw message

The rest of this diff is not shown. View the raw message.

Signature · 1 line
2.25.1

Part of the diff is not shown here. View the raw message.

#22 lore raw

cover Add MACsec unit test cases

Inline MACsec offload was supported in DPDK 22.11
using rte_security APIs.
This patchset adds few minor changes in the rte_security APIs to specify the direction of SA/SC and update the SC configuration to set packet number threshold.

The patchset also add functional test cases in dpdk-test app to verify MACsec functionality.

This patchset is pending from last release [1] due to lack of hardware to test. Now the test cases are verified on Marvell cnxk PMD and the pmd support is added as a separate patchset.

Akhil Goyal (10):
security: add direction in SA/SC configuration
security: add MACsec packet number threshold
test/security: add inline MACsec cases
test/security: add MACsec integrity cases
test/security: verify multi flow MACsec
test/security: add MACsec VLAN cases
test/security: add MACsec negative cases
test/security: verify MACsec stats
test/security: verify MACsec Tx HW rekey
test/security: remove no MACsec support case

Ankur Dwivedi (3):
test/security: verify MACsec interrupts
test/security: verify MACsec Rx rekey
test/security: verify MACsec anti replay

 app/test/meson.build                          |    1 +
 app/test/test_security.c                      |   37 -
 app/test/test_security_inline_macsec.c        | 2332 ++++++++++
 .../test_security_inline_macsec_vectors.h     | 3895 +++++++++++++++++
 lib/security/rte_security.c                   |   16 +-
 lib/security/rte_security.h                   |   24 +-
 lib/security/rte_security_driver.h            |   12 +-
 7 files changed, 6266 insertions(+), 51 deletions(-)
 create mode 100644 app/test/test_security_inline_macsec.c
 create mode 100644 app/test/test_security_inline_macsec_vectors.h
Signature · 1 line
2.25.1
#23 lore raw

PATCH 1/13 security: add direction in SA/SC configuration

MACsec SC/SA ids are created based on direction of the flow. Hence, added the missing field for configuration and cleanup of the SCs and SAs.

---
 lib/security/rte_security.c        | 16 ++++++++++------
 lib/security/rte_security.h        | 14 ++++++++++----
 lib/security/rte_security_driver.h | 12 ++++++++++--
 3 files changed, 30 insertions(+), 12 deletions(-)
lib/security/rte_security.c +10 -6
index e102c55e55..c4d64bb8e9 100644
@@ -164,13 +164,14 @@ rte_security_macsec_sa_create(struct rte_security_ctx *instance,
 }
 
 int
-rte_security_macsec_sc_destroy(struct rte_security_ctx *instance, uint16_t sc_id)
+rte_security_macsec_sc_destroy(struct rte_security_ctx *instance, uint16_t sc_id,
+			       enum rte_security_macsec_direction dir)
 {
 	int ret;
 
 	RTE_PTR_CHAIN3_OR_ERR_RET(instance, ops, macsec_sc_destroy, -EINVAL, -ENOTSUP);
 
-	ret = instance->ops->macsec_sc_destroy(instance->device, sc_id);
+	ret = instance->ops->macsec_sc_destroy(instance->device, sc_id, dir);
 	if (ret != 0)
 		return ret;
 
@@ -181,13 +182,14 @@ rte_security_macsec_sc_destroy(struct rte_security_ctx *instance, uint16_t sc_id
 }
 
 int
-rte_security_macsec_sa_destroy(struct rte_security_ctx *instance, uint16_t sa_id)
+rte_security_macsec_sa_destroy(struct rte_security_ctx *instance, uint16_t sa_id,
+			       enum rte_security_macsec_direction dir)
 {
 	int ret;
 
 	RTE_PTR_CHAIN3_OR_ERR_RET(instance, ops, macsec_sa_destroy, -EINVAL, -ENOTSUP);
 
-	ret = instance->ops->macsec_sa_destroy(instance->device, sa_id);
+	ret = instance->ops->macsec_sa_destroy(instance->device, sa_id, dir);
 	if (ret != 0)
 		return ret;
 
@@ -199,22 +201,24 @@ rte_security_macsec_sa_destroy(struct rte_security_ctx *instance, uint16_t sa_id
 
 int
 rte_security_macsec_sc_stats_get(struct rte_security_ctx *instance, uint16_t sc_id,
+				 enum rte_security_macsec_direction dir,
 				 struct rte_security_macsec_sc_stats *stats)
 {
 	RTE_PTR_CHAIN3_OR_ERR_RET(instance, ops, macsec_sc_stats_get, -EINVAL, -ENOTSUP);
 	RTE_PTR_OR_ERR_RET(stats, -EINVAL);
 
-	return instance->ops->macsec_sc_stats_get(instance->device, sc_id, stats);
+	return instance->ops->macsec_sc_stats_get(instance->device, sc_id, dir, stats);
 }
 
 int
 rte_security_macsec_sa_stats_get(struct rte_security_ctx *instance, uint16_t sa_id,
+				 enum rte_security_macsec_direction dir,
 				 struct rte_security_macsec_sa_stats *stats)
 {
 	RTE_PTR_CHAIN3_OR_ERR_RET(instance, ops, macsec_sa_stats_get, -EINVAL, -ENOTSUP);
 	RTE_PTR_OR_ERR_RET(stats, -EINVAL);
 
-	return instance->ops->macsec_sa_stats_get(instance->device, sa_id, stats);
+	return instance->ops->macsec_sa_stats_get(instance->device, sa_id, dir, stats);
 }
 
 int
lib/security/rte_security.h +10 -4
index 4bacf9fcd9..c7a523b6d6 100644
@@ -761,6 +761,7 @@ rte_security_macsec_sc_create(struct rte_security_ctx *instance,
  *
  * @param   instance	security instance
  * @param   sc_id	SC ID to be destroyed
+ * @param   dir		direction of the SC
  * @return
  *  - 0 if successful.
  *  - -EINVAL if sc_id is invalid or instance is NULL.
@@ -768,7 +769,8 @@ rte_security_macsec_sc_create(struct rte_security_ctx *instance,
  */
 __rte_experimental
 int
-rte_security_macsec_sc_destroy(struct rte_security_ctx *instance, uint16_t sc_id);
+rte_security_macsec_sc_destroy(struct rte_security_ctx *instance, uint16_t sc_id,
+			       enum rte_security_macsec_direction dir);
 
 /**
  * @warning
@@ -798,6 +800,7 @@ rte_security_macsec_sa_create(struct rte_security_ctx *instance,
  *
  * @param   instance	security instance
  * @param   sa_id	SA ID to be destroyed
+ * @param   dir		direction of the SA
  * @return
  *  - 0 if successful.
  *  - -EINVAL if sa_id is invalid or instance is NULL.
@@ -805,7 +808,8 @@ rte_security_macsec_sa_create(struct rte_security_ctx *instance,
  */
 __rte_experimental
 int
-rte_security_macsec_sa_destroy(struct rte_security_ctx *instance, uint16_t sa_id);
+rte_security_macsec_sa_destroy(struct rte_security_ctx *instance, uint16_t sa_id,
+			       enum rte_security_macsec_direction dir);
 
 /** Device-specific metadata field type */
 typedef uint64_t rte_security_dynfield_t;
@@ -1077,6 +1081,7 @@ rte_security_session_stats_get(struct rte_security_ctx *instance,
  *
  * @param	instance	security instance
  * @param	sa_id		SA ID for which stats are needed
+ * @param	dir		direction of the SA
  * @param	stats		statistics
  * @return
  *  - On success, return 0.
@@ -1085,7 +1090,7 @@ rte_security_session_stats_get(struct rte_security_ctx *instance,
 __rte_experimental
 int
 rte_security_macsec_sa_stats_get(struct rte_security_ctx *instance,
-				 uint16_t sa_id,
+				 uint16_t sa_id, enum rte_security_macsec_direction dir,
 				 struct rte_security_macsec_sa_stats *stats);
 
 /**
@@ -1096,6 +1101,7 @@ rte_security_macsec_sa_stats_get(struct rte_security_ctx *instance,
  *
  * @param	instance	security instance
  * @param	sc_id		SC ID for which stats are needed
+ * @param	dir		direction of the SC
  * @param	stats		SC statistics
  * @return
  *  - On success, return 0.
@@ -1104,7 +1110,7 @@ rte_security_macsec_sa_stats_get(struct rte_security_ctx *instance,
 __rte_experimental
 int
 rte_security_macsec_sc_stats_get(struct rte_security_ctx *instance,
-				 uint16_t sc_id,
+				 uint16_t sc_id, enum rte_security_macsec_direction dir,
 				 struct rte_security_macsec_sc_stats *stats);
 
 /**
lib/security/rte_security_driver.h +10 -2
index 421e6f7780..677c7d1f91 100644
@@ -106,8 +106,10 @@ typedef int (*security_macsec_sc_create_t)(void *device, struct rte_security_mac
  *
  * @param	device		Crypto/eth device pointer
  * @param	sc_id		MACsec SC ID
+ * @param	dir		Direction of SC
  */
-typedef int (*security_macsec_sc_destroy_t)(void *device, uint16_t sc_id);
+typedef int (*security_macsec_sc_destroy_t)(void *device, uint16_t sc_id,
+		enum rte_security_macsec_direction dir);
 
 /**
  * Configure a MACsec security Association (SA) on a device.
@@ -128,8 +130,10 @@ typedef int (*security_macsec_sa_create_t)(void *device, struct rte_security_mac
  *
  * @param	device		Crypto/eth device pointer
  * @param	sa_id		MACsec SA ID
+ * @param	dir		Direction of SA
  */
-typedef int (*security_macsec_sa_destroy_t)(void *device, uint16_t sa_id);
+typedef int (*security_macsec_sa_destroy_t)(void *device, uint16_t sa_id,
+		enum rte_security_macsec_direction dir);
 
 /**
  * Get the size of a security session
@@ -162,6 +166,7 @@ typedef int (*security_session_stats_get_t)(void *device,
  *
  * @param	device		Crypto/eth device pointer
  * @param	sc_id		secure channel ID created by rte_security_macsec_sc_create()
+ * @param	dir		direction of SC
  * @param	stats		SC stats of the driver
  *
  * @return
@@ -169,6 +174,7 @@ typedef int (*security_session_stats_get_t)(void *device,
  *  - -EINVAL if sc_id or device is invalid.
  */
 typedef int (*security_macsec_sc_stats_get_t)(void *device, uint16_t sc_id,
+		enum rte_security_macsec_direction dir,
 		struct rte_security_macsec_sc_stats *stats);
 
 /**
@@ -176,6 +182,7 @@ typedef int (*security_macsec_sc_stats_get_t)(void *device, uint16_t sc_id,
  *
  * @param	device		Crypto/eth device pointer
  * @param	sa_id		secure channel ID created by rte_security_macsec_sc_create()
+ * @param	dir		direction of SA
  * @param	stats		SC stats of the driver
  *
  * @return
@@ -183,6 +190,7 @@ typedef int (*security_macsec_sc_stats_get_t)(void *device, uint16_t sc_id,
  *  - -EINVAL if sa_id or device is invalid.
  */
 typedef int (*security_macsec_sa_stats_get_t)(void *device, uint16_t sa_id,
+		enum rte_security_macsec_direction dir,
 		struct rte_security_macsec_sa_stats *stats);
 
 
Signature · 1 line
2.25.1
#24 lore raw

PATCH 2/13 security: add MACsec packet number threshold

In reply to Akhil Goyal

Added Packet number threshold parameter in MACsec SC configuration to identify the maximum allowed threshold for packet number field in the packet.
A field is_xpn is also added to identify if the SAs are configured for extended packet number or not so that packet number threshold can be configured accordingly.

---
 lib/security/rte_security.h | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)
lib/security/rte_security.h +8 -2
index c7a523b6d6..30bac4e25a 100644
@@ -399,6 +399,8 @@ struct rte_security_macsec_sa {
 struct rte_security_macsec_sc {
 	/** Direction of SC */
 	enum rte_security_macsec_direction dir;
+	/** Packet number threshold */
+	uint64_t pn_threshold;
 	union {
 		struct {
 			/** SAs for each association number */
@@ -407,8 +409,10 @@ struct rte_security_macsec_sc {
 			uint8_t sa_in_use[RTE_SECURITY_MACSEC_NUM_AN];
 			/** Channel is active */
 			uint8_t active : 1;
+			/** Extended packet number is enabled for SAs */
+			uint8_t is_xpn : 1;
 			/** Reserved bitfields for future */
-			uint8_t reserved : 7;
+			uint8_t reserved : 6;
 		} sc_rx;
 		struct {
 			uint16_t sa_id; /**< SA ID to be used for encryption */
@@ -416,8 +420,10 @@ struct rte_security_macsec_sc {
 			uint64_t sci; /**< SCI value to be used if send_sci is set */
 			uint8_t active : 1; /**< Channel is active */
 			uint8_t re_key_en : 1; /**< Enable Rekeying */
+			/** Extended packet number is enabled for SAs */
+			uint8_t is_xpn : 1;
 			/** Reserved bitfields for future */
-			uint8_t reserved : 6;
+			uint8_t reserved : 5;
 		} sc_tx;
 	};
 };
Signature · 1 line
2.25.1
#25 lore raw

Re: [PATCH 02/13] security: add MACsec packet number threshold

Quoted 14 lines · On Wed, 24 May 2023 01:19:07 +0530 Akhil Goyal <[email protected]> wrote:
lib/security/rte_security.h +2 -0
index c7a523b6d6..30bac4e25a 100644
@@ -399,6 +399,8 @@ struct rte_security_macsec_sa {
 struct rte_security_macsec_sc {
 	/** Direction of SC */
 	enum rte_security_macsec_direction dir;
+	/** Packet number threshold */
+	uint64_t pn_threshold;
 	union {
 		struct {
 			/** SAs for each association number */

lib/security/rte_security.h struct rte_security_macsec_sc { · line 415

Quoted 8 lines
lib/security/rte_security.h +3 -1
@@ -407,8 +409,10 @@ struct rte_security_macsec_sc {
 			uint8_t sa_in_use[RTE_SECURITY_MACSEC_NUM_AN];
 			/** Channel is active */
 			uint8_t active : 1;
+			/** Extended packet number is enabled for SAs */
+			uint8_t is_xpn : 1;
 			/** Reserved bitfields for future */
-			uint8_t reserved : 7;
+			uint8

Is this an ABI change? If so needs to wait for 23.11 release

#26 lore raw

RE: [EXT] Re: [PATCH 02/13] security: add MACsec packet number threshold

Quoted 19 lines
Quoted 16 lines · On Wed, 24 May 2023 01:19:07 +0530 Akhil Goyal <[email protected]> wrote:
lib/security/rte_security.h +2 -0
index c7a523b6d6..30bac4e25a 100644
@@ -399,6 +399,8 @@ struct rte_security_macsec_sa {
 struct rte_security_macsec_sc {
 	/** Direction of SC */
 	enum rte_security_macsec_direction dir;
+	/** Packet number threshold */
+	uint64_t pn_threshold;
 	union {
 		struct {
 			/** SAs for each association number */
@@ -407,8 +409,10 @@ struct rte_security_macsec_sc {
 			uint8_t sa_in_use[RTE_SECURITY_MACSEC_NUM_AN];
 			/** Channel is active */
Quoted 8 lines

lib/security/rte_security.h struct rte_security_macsec_sc {

Quoted 6 lines
lib/security/rte_security.h +3 -1
 			uint8_t active : 1;
+			/** Extended packet number is enabled for SAs */
+			uint8_t is_xpn : 1;
 			/** Reserved bitfields for future */
-			uint8_t reserved : 7;
+			uint8

Is this an ABI change? If so needs to wait for 23.11 release

rte_security_macsec_sc/sa_create are experimental APIs. So, it won't be an issue I believe.

#27 lore raw

RE: [EXT] Re: [PATCH 02/13] security: add MACsec packet number threshold

Quoted 30 lines

Subject: RE: [EXT] Re: [PATCH 02/13] security: add MACsec packet number threshold

Quoted 19 lines
Quoted 16 lines · On Wed, 24 May 2023 01:19:07 +0530 Akhil Goyal <[email protected]> wrote:
lib/security/rte_security.h +2 -0
index c7a523b6d6..30bac4e25a 100644
@@ -399,6 +399,8 @@ struct rte_security_macsec_sa {
 struct rte_security_macsec_sc {
 	/** Direction of SC */
 	enum rte_security_macsec_direction dir;
+	/** Packet number threshold */
+	uint64_t pn_threshold;
 	union {
 		struct {
 			/** SAs for each association number */
@@ -407,8 +409,10 @@ struct rte_security_macsec_sc {
 			uint8_t sa_in_use[RTE_SECURITY_MACSEC_NUM_AN];
 			/** Channel is active */
Quoted 8 lines

lib/security/rte_security.h struct rte_security_macsec_sc {

Quoted 6 lines
lib/security/rte_security.h +3 -1
 			uint8_t active : 1;
+			/** Extended packet number is enabled for SAs */
+			uint8_t is_xpn : 1;
 			/** Reserved bitfields for future */
-			uint8_t reserved : 7;
+			uint8

Is this an ABI change? If so needs to wait for 23.11 release

Quoted 2 lines

rte_security_macsec_sc/sa_create are experimental APIs. So, it won't be an issue I believe.

Looking at the ABI issues reported for this patchset.
Even if these APIs are experimental, we cannot really change them. As all are part of rte_security_ctx which is exposed.
But, user is not required to know its contents and it should not be exposed. In next release I would make it internal like rte_security_session. For now, I would defer this MACsec support to next release.

#28 lore raw

PATCH 3/13 test/security: add inline MACsec cases

In reply to Akhil Goyal

Updated test app to verify Inline MACsec offload using rte_security APIs.
A couple of test cases are added to verify encap only and decap only of some known test vectors from MACsec specification.

---
 app/test/meson.build                          |    1 +
 app/test/test_security_inline_macsec.c        | 1108 +++++++++++++++++
 .../test_security_inline_macsec_vectors.h     | 1086 ++++++++++++++++
 3 files changed, 2195 insertions(+)
 create mode 100644 app/test/test_security_inline_macsec.c
 create mode 100644 app/test/test_security_inline_macsec_vectors.h
app/test/meson.build +1 -0
index b9b5432496..69c1d19f7b 100644
@@ -128,6 +128,7 @@ test_sources = files(
         'test_rwlock.c',
         'test_sched.c',
         'test_security.c',
+        'test_security_inline_macsec.c',
         'test_security_inline_proto.c',
         'test_seqlock.c',
         'test_service_cores.c',
app/test/test_security_inline_macsec.c new file +1108 -0

1,108 lines not on this page · raw message

app/test/test_security_inline_macsec_vectors.h new file +1086 -0

1,086 lines not on this page · raw message

Signature · 1 line
2.25.1
#29 lore raw

PATCH 4/13 test/security: add MACsec integrity cases

In reply to Akhil Goyal

Added test vectors and test cases to verify auth_only/verify_only and encap-decap/auth-verify to verify the complete TX-RX path using the loopback mode of ethdev.

---
 app/test/test_security_inline_macsec.c        | 153 +++
 .../test_security_inline_macsec_vectors.h     | 995 ++++++++++++++++++
 2 files changed, 1148 insertions(+)
app/test/test_security_inline_macsec.c +153 -0
index 22a54dd65b..9047b7adff 100644
@@ -937,6 +937,143 @@ test_inline_macsec_decap_all(const void *data __rte_unused)
 	return all_err;
 }
 
+static int
+test_inline_macsec_auth_only_all(const void *data __rte_unused)
+{
+	const struct mcs_test_vector *cur_td;
+	struct mcs_test_opts opts = {0};
+	int err, all_err = 0;
+	int i, size;
+
+	opts.val_frames = RTE_SECURITY_MACSEC_VALIDATE_STRICT;
+	opts.protect_frames = true;
+	opts.sa_in_use = 1;
+	opts.nb_td = 1;
+	opts.sectag_insert_mode = 1;
+	opts.mtu = RTE_ETHER_MTU;
+
+	size = (sizeof(list_mcs_integrity_vectors) / sizeof((list_mcs_integrity_vectors)[0]));
+
+	for (i = 0; i < size; i++) {
+		cur_td = &list_mcs_integrity_vectors[i];
+		err = test_macsec(&cur_td, MCS_AUTH_ONLY, &opts);
+		if (err) {
+			printf("\nAuth Generate case %d failed", cur_td->test_idx);
+			err = -1;
+		} else {
+			printf("\nAuth Generate case %d Passed", cur_td->test_idx);
+			err = 0;
+		}
+		all_err += err;
+	}
+	printf("\n%s: Success: %d, Failure: %d\n", __func__, size + all_err, -all_err);
+
+	return all_err;
+}
+
+static int
+test_inline_macsec_verify_only_all(const void *data __rte_unused)
+{
+	const struct mcs_test_vector *cur_td;
+	struct mcs_test_opts opts = {0};
+	int err, all_err = 0;
+	int i, size;
+
+	opts.val_frames = RTE_SECURITY_MACSEC_VALIDATE_STRICT;
+	opts.sa_in_use = 1;
+	opts.nb_td = 1;
+	opts.sectag_insert_mode = 1;
+	opts.mtu = RTE_ETHER_MTU;
+
+	size = (sizeof(list_mcs_integrity_vectors) / sizeof((list_mcs_integrity_vectors)[0]));
+
+	for (i = 0; i < size; i++) {
+		cur_td = &list_mcs_integrity_vectors[i];
+		err = test_macsec(&cur_td, MCS_VERIFY_ONLY, &opts);
+		if (err) {
+			printf("\nAuth Verify case %d failed", cur_td->test_idx);
+			err = -1;
+		} else {
+			printf("\nAuth Verify case %d Passed", cur_td->test_idx);
+			err = 0;
+		}
+		all_err += err;
+	}
+	printf("\n%s: Success: %d, Failure: %d\n", __func__, size + all_err, -all_err);
+
+	return all_err;
+}
+
+static int
+test_inline_macsec_encap_decap_all(const void *data __rte_unused)
+{
+	const struct mcs_test_vector *cur_td;
+	struct mcs_test_opts opts = {0};
+	int err, all_err = 0;
+	int i, size;
+
+	opts.val_frames = RTE_SECURITY_MACSEC_VALIDATE_STRICT;
+	opts.encrypt = true;
+	opts.protect_frames = true;
+	opts.sa_in_use = 1;
+	opts.nb_td = 1;
+	opts.sectag_insert_mode = 1;
+	opts.mtu = RTE_ETHER_MTU;
+
+	size = (sizeof(list_mcs_cipher_vectors) / sizeof((list_mcs_cipher_vectors)[0]));
+
+	for (i = 0; i < size; i++) {
+		cur_td = &list_mcs_cipher_vectors[i];
+		err = test_macsec(&cur_td, MCS_ENCAP_DECAP, &opts);
+		if (err) {
+			printf("\nCipher Auth Encap-decap case %d failed", cur_td->test_idx);
+			err = -1;
+		} else {
+			printf("\nCipher Auth Encap-decap case %d Passed", cur_td->test_idx);
+			err = 0;
+		}
+		all_err += err;
+	}
+	printf("\n%s: Success: %d, Failure: %d\n", __func__, size + all_err, -all_err);
+
+	return all_err;
+}
+
+
+static int
+test_inline_macsec_auth_verify_all(const void *data __rte_unused)
+{
+	const struct mcs_test_vector *cur_td;
+	struct mcs_test_opts opts = {0};
+	int err, all_err = 0;
+	int i, size;
+
+	opts.val_frames = RTE_SECURITY_MACSEC_VALIDATE_STRICT;
+	opts.protect_frames = true;
+	opts.sa_in_use = 1;
+	opts.nb_td = 1;
+	opts.sectag_insert_mode = 1;
+	opts.mtu = RTE_ETHER_MTU;
+
+	size = (sizeof(list_mcs_integrity_vectors) / sizeof((list_mcs_integrity_vectors)[0]));
+
+	for (i = 0; i < size; i++) {
+		cur_td = &list_mcs_integrity_vectors[i];
+		err = test_macsec(&cur_td, MCS_AUTH_VERIFY, &opts);
+		if (err) {
+			printf("\nAuth Generate + Verify case %d failed", cur_td->test_idx);
+			err = -1;
+		} else {
+			printf("\nAuth Generate + Verify case %d Passed", cur_td->test_idx);
+			err = 0;
+		}
+		all_err += err;
+	}
+	printf("\n%s: Success: %d, Failure: %d\n", __func__, size + all_err, -all_err);
+
+	return all_err;
+}
+
 static int
 ut_setup_inline_macsec(void)
 {
@@ -1090,6 +1227,22 @@ static struct unit_test_suite inline_macsec_testsuite  = {
 			"MACsec decap(De-cipher+verify) known vector",
 			ut_setup_inline_macsec, ut_teardown_inline_macsec,
 			test_inline_macsec_decap_all),
+		TEST_CASE_NAMED_ST(
+			"MACsec auth only known vector",
+			ut_setup_inline_macsec, ut_teardown_inline_macsec,
+			test_inline_macsec_auth_only_all),
+		TEST_CASE_NAMED_ST(
+			"MACsec verify only known vector",
+			ut_setup_inline_macsec, ut_teardown_inline_macsec,
+			test_inline_macsec_verify_only_all),
+		TEST_CASE_NAMED_ST(
+			"MACsec encap + decap known vector",
+			ut_setup_inline_macsec, ut_teardown_inline_macsec,
+			test_inline_macsec_encap_decap_all),
+		TEST_CASE_NAMED_ST(
+			"MACsec auth + verify known vector",
+			ut_setup_inline_macsec, ut_teardown_inline_macsec,
+			test_inline_macsec_auth_verify_all),
 
 		TEST_CASES_END() /**< NULL terminate unit test array */
 	},
app/test/test_security_inline_macsec_vectors.h +995 -0

999 lines not on this page · raw message

Signature · 1 line
2.25.1
#30 lore raw

PATCH 5/13 test/security: verify multi flow MACsec

In reply to Akhil Goyal

Added test case and test vectors to verify multiple flows of MACsec.

---
 app/test/test_security_inline_macsec.c        |  49 ++++++++
 .../test_security_inline_macsec_vectors.h     | 110 +++++++++++++++++-
 2 files changed, 158 insertions(+), 1 deletion(-)
app/test/test_security_inline_macsec.c +49 -0
index 9047b7adff..c32f747961 100644
@@ -1074,6 +1074,51 @@ test_inline_macsec_auth_verify_all(const void *data __rte_unused)
 	return all_err;
 }
 
+static int
+test_inline_macsec_multi_flow(const void *data __rte_unused)
+{
+	const struct mcs_test_vector *tv[MCS_MAX_FLOWS];
+	struct mcs_test_vector iter[MCS_MAX_FLOWS];
+	struct mcs_test_opts opts = {0};
+	int i, err;
+
+	opts.val_frames = RTE_SECURITY_MACSEC_VALIDATE_STRICT;
+	opts.encrypt = true;
+	opts.protect_frames = true;
+	opts.sa_in_use = 1;
+	opts.nb_td = MCS_MAX_FLOWS;
+	opts.sectag_insert_mode = 1;
+	opts.mtu = RTE_ETHER_MTU;
+
+	for (i = 0; i < MCS_MAX_FLOWS; i++) {
+		memcpy(&iter[i].sa_key.data, sa_key, MCS_MULTI_FLOW_TD_KEY_SZ);
+		memcpy(&iter[i].plain_pkt.data, eth_addrs[i], 2 * RTE_ETHER_ADDR_LEN);
+		memcpy(&iter[i].plain_pkt.data[2 * RTE_ETHER_ADDR_LEN], plain_user_data,
+		       MCS_MULTI_FLOW_TD_PLAIN_DATA_SZ);
+		memcpy(&iter[i].secure_pkt.data, eth_addrs[i], 2 * RTE_ETHER_ADDR_LEN);
+		memcpy(&iter[i].secure_pkt.data[2 * RTE_ETHER_ADDR_LEN], secure_user_data,
+		       MCS_MULTI_FLOW_TD_SECURE_DATA_SZ);
+		iter[i].sa_key.len = MCS_MULTI_FLOW_TD_KEY_SZ;
+		iter[i].plain_pkt.len = MCS_MULTI_FLOW_TD_PLAIN_DATA_SZ +
+					(2 * RTE_ETHER_ADDR_LEN);
+		iter[i].secure_pkt.len = MCS_MULTI_FLOW_TD_SECURE_DATA_SZ +
+					(2 * RTE_ETHER_ADDR_LEN);
+		iter[i].alg = RTE_SECURITY_MACSEC_ALG_GCM_128;
+		iter[i].ssci = 0x0;
+		iter[i].xpn = 0x0;
+		tv[i] = (const struct mcs_test_vector *)&iter[i];
+	}
+	err = test_macsec(tv, MCS_ENCAP_DECAP, &opts);
+	if (err) {
+		printf("\nCipher Auth Encryption multi flow failed");
+		err = -1;
+	} else {
+		printf("\nCipher Auth Encryption multi flow Passed");
+		err = 0;
+	}
+	return err;
+}
+
 static int
 ut_setup_inline_macsec(void)
 {
@@ -1219,6 +1264,10 @@ inline_macsec_testsuite_teardown(void)
 static struct unit_test_suite inline_macsec_testsuite  = {
 	.suite_name = "Inline MACsec Ethernet Device Unit Test Suite",
 	.unit_test_cases = {
+		TEST_CASE_NAMED_ST(
+			"MACsec Encap + decap Multi flow",
+			ut_setup_inline_macsec, ut_teardown_inline_macsec,
+			test_inline_macsec_multi_flow),
 		TEST_CASE_NAMED_ST(
 			"MACsec encap(Cipher+Auth) known vector",
 			ut_setup_inline_macsec, ut_teardown_inline_macsec,
app/test/test_security_inline_macsec_vectors.h +109 -1

120 lines not on this page · raw message

Signature · 1 line
2.25.1
#31 lore raw

PATCH 6/13 test/security: add MACsec VLAN cases

In reply to Akhil Goyal

Added cases to verify MACsec processing with VLAN
tags inserted. Vectors are added to verify 1/2/3
VLAN tags in clear or encrypted data.

---
 app/test/test_security_inline_macsec.c        |  67 ++++++
 .../test_security_inline_macsec_vectors.h     | 217 ++++++++++++++++++
 2 files changed, 284 insertions(+)
app/test/test_security_inline_macsec.c +67 -0
index c32f747961..353b07477e 100644
@@ -1119,6 +1119,69 @@ test_inline_macsec_multi_flow(const void *data __rte_unused)
 	return err;
 }
 
+static int
+test_inline_macsec_with_vlan(const void *data __rte_unused)
+{
+	const struct mcs_test_vector *cur_td;
+	struct mcs_test_opts opts = {0};
+	int err, all_err = 0;
+	int i, size;
+
+	opts.val_frames = RTE_SECURITY_MACSEC_VALIDATE_STRICT;
+	opts.protect_frames = true;
+	opts.sa_in_use = 1;
+	opts.nb_td = 1;
+	opts.mtu = RTE_ETHER_MTU;
+
+	size = (sizeof(list_mcs_vlan_vectors) / sizeof((list_mcs_vlan_vectors)[0]));
+
+	for (i = 0; i < size; i++) {
+		cur_td = &list_mcs_vlan_vectors[i];
+		if (i == 0) {
+			opts.sectag_insert_mode = 1;
+		} else if (i == 1) {
+			opts.sectag_insert_mode = 0; /* offset from special E-type */
+			opts.nb_vlan = 1;
+		} else if (i == 2) {
+			opts.sectag_insert_mode = 0; /* offset from special E-type */
+			opts.nb_vlan = 2;
+		}
+		err = test_macsec(&cur_td, MCS_ENCAP, &opts);
+		if (err) {
+			printf("\n VLAN Encap case %d failed", cur_td->test_idx);
+			err = -1;
+		} else {
+			printf("\n VLAN Encap case %d passed", cur_td->test_idx);
+			err = 0;
+		}
+		all_err += err;
+	}
+	for (i = 0; i < size; i++) {
+		cur_td = &list_mcs_vlan_vectors[i];
+		if (i == 0) {
+			opts.sectag_insert_mode = 1;
+		} else if (i == 1) {
+			opts.sectag_insert_mode = 0; /* offset from special E-type */
+			opts.nb_vlan = 1;
+		} else if (i == 2) {
+			opts.sectag_insert_mode = 0; /* offset from special E-type */
+			opts.nb_vlan = 2;
+		}
+		err = test_macsec(&cur_td, MCS_DECAP, &opts);
+		if (err) {
+			printf("\n VLAN Decap case %d failed", cur_td->test_idx);
+			err = -1;
+		} else {
+			printf("\n VLAN Decap case %d passed", cur_td->test_idx);
+			err = 0;
+		}
+		all_err += err;
+	}
+
+	printf("\n%s: Success: %d, Failure: %d\n", __func__, (2 * size) + all_err, -all_err);
+	return all_err;
+}
+
 static int
 ut_setup_inline_macsec(void)
 {
@@ -1292,6 +1355,10 @@ static struct unit_test_suite inline_macsec_testsuite  = {
 			"MACsec auth + verify known vector",
 			ut_setup_inline_macsec, ut_teardown_inline_macsec,
 			test_inline_macsec_auth_verify_all),
+		TEST_CASE_NAMED_ST(
+			"MACsec Encap and decap with VLAN",
+			ut_setup_inline_macsec, ut_teardown_inline_macsec,
+			test_inline_macsec_with_vlan),
 
 		TEST_CASES_END() /**< NULL terminate unit test array */
 	},
app/test/test_security_inline_macsec_vectors.h +217 -0

222 lines not on this page · raw message

Signature · 1 line
2.25.1
#32 lore raw

PATCH 7/13 test/security: add MACsec negative cases

In reply to Akhil Goyal

Added MACsec negative test cases to verify
pkt drop, untagged rx, bad tag rx, sa not in use,
out packets untagged, pkts too long.

---
 app/test/test_security_inline_macsec.c        | 346 +++++++++++++
 .../test_security_inline_macsec_vectors.h     | 475 ++++++++++++++++++
 2 files changed, 821 insertions(+)
app/test/test_security_inline_macsec.c +346 -0
index 353b07477e..9c4546fa38 100644
@@ -660,6 +660,103 @@ mcs_stats_dump(struct rte_security_ctx *ctx, enum mcs_op op,
 	}
 }
 
+static int
+mcs_stats_check(struct rte_security_ctx *ctx, enum mcs_op op,
+		const struct mcs_test_opts *opts,
+		const struct mcs_test_vector *td,
+		void *rx_sess, void *tx_sess,
+		uint8_t rx_sc_id, uint8_t tx_sc_id,
+		uint16_t rx_sa_id[], uint16_t tx_sa_id[])
+{
+	struct rte_security_stats sess_stats = {0};
+	struct rte_security_macsec_secy_stats *secy_stat;
+	struct rte_security_macsec_sc_stats sc_stat = {0};
+	struct rte_security_macsec_sa_stats sa_stat = {0};
+	int i;
+
+	if (op == MCS_DECAP || op == MCS_ENCAP_DECAP ||
+			op == MCS_VERIFY_ONLY || op == MCS_AUTH_VERIFY) {
+		rte_security_session_stats_get(ctx, rx_sess, &sess_stats);
+		secy_stat = &sess_stats.macsec;
+
+		if ((opts->check_untagged_rx && secy_stat->pkt_notag_cnt != 1) ||
+				(opts->check_untagged_rx && secy_stat->pkt_untaged_cnt != 1))
+			return TEST_FAILED;
+
+		if (opts->check_bad_tag_cnt && secy_stat->pkt_badtag_cnt != 1)
+			return TEST_FAILED;
+
+		if (opts->check_sa_not_in_use && secy_stat->pkt_nosaerror_cnt != 1)
+			return TEST_FAILED;
+
+		if (opts->check_decap_stats && secy_stat->octet_decrypted_cnt !=
+				(uint16_t)(td->plain_pkt.len - 2 * RTE_ETHER_ADDR_LEN))
+			return TEST_FAILED;
+
+		if (opts->check_verify_only_stats && secy_stat->octet_validated_cnt !=
+				(uint16_t)(td->plain_pkt.len - 2 * RTE_ETHER_ADDR_LEN))
+			return TEST_FAILED;
+
+		rte_security_macsec_sc_stats_get(ctx, rx_sc_id,
+				RTE_SECURITY_MACSEC_DIR_RX, &sc_stat);
+
+		if ((opts->check_decap_stats || opts->check_verify_only_stats) &&
+				sc_stat.pkt_ok_cnt != 1)
+			return TEST_FAILED;
+
+		if (opts->check_pkts_invalid_stats && sc_stat.pkt_notvalid_cnt != 1)
+			return TEST_FAILED;
+
+		if (opts->check_pkts_unchecked_stats && sc_stat.pkt_unchecked_cnt != 1)
+			return TEST_FAILED;
+
+		for (i = 0; i < RTE_SECURITY_MACSEC_NUM_AN; i++) {
+			memset(&sa_stat, 0, sizeof(struct rte_security_macsec_sa_stats));
+			rte_security_macsec_sa_stats_get(ctx, rx_sa_id[i],
+					RTE_SECURITY_MACSEC_DIR_RX, &sa_stat);
+
+		}
+	}
+
+	if (op == MCS_ENCAP || op == MCS_ENCAP_DECAP ||
+			op == MCS_AUTH_ONLY || op == MCS_AUTH_VERIFY) {
+		memset(&sess_stats, 0, sizeof(struct rte_security_stats));
+		rte_security_session_stats_get(ctx, tx_sess, &sess_stats);
+		secy_stat = &sess_stats.macsec;
+
+		if (opts->check_out_pkts_untagged && secy_stat->pkt_untagged_cnt != 1)
+			return TEST_FAILED;
+
+		if (opts->check_out_pkts_toolong && secy_stat->pkt_toolong_cnt != 1)
+			return TEST_FAILED;
+
+		if (opts->check_encap_stats && secy_stat->octet_encrypted_cnt !=
+				(uint16_t)(td->plain_pkt.len - 2 * RTE_ETHER_ADDR_LEN))
+			return TEST_FAILED;
+
+		if (opts->check_auth_only_stats && secy_stat->octet_protected_cnt !=
+				(uint16_t)(td->plain_pkt.len - 2 * RTE_ETHER_ADDR_LEN))
+			return TEST_FAILED;
+
+
+		memset(&sc_stat, 0, sizeof(struct rte_security_macsec_sc_stats));
+		rte_security_macsec_sc_stats_get(ctx, tx_sc_id, RTE_SECURITY_MACSEC_DIR_TX,
+						 &sc_stat);
+
+		if (opts->check_encap_stats && sc_stat.pkt_encrypt_cnt != 1)
+			return TEST_FAILED;
+
+		if (opts->check_auth_only_stats && sc_stat.pkt_protected_cnt != 1)
+			return TEST_FAILED;
+
+		memset(&sa_stat, 0, sizeof(struct rte_security_macsec_sa_stats));
+		rte_security_macsec_sa_stats_get(ctx, tx_sa_id[0],
+				RTE_SECURITY_MACSEC_DIR_TX, &sa_stat);
+	}
+
+	return 0;
+}
+
 static int
 test_macsec(const struct mcs_test_vector *td[], enum mcs_op op, const struct mcs_test_opts *opts)
 {
@@ -833,12 +930,23 @@ test_macsec(const struct mcs_test_vector *td[], enum mcs_op op, const struct mcs
 		rx_pkts_burst[i] = NULL;
 	}
 out:
+	if (opts->check_out_pkts_toolong == 1 ||
+			opts->check_sa_not_in_use == 1 ||
+			opts->check_bad_tag_cnt == 1)
+		ret = TEST_SUCCESS;
+
 	for (i = 0; i < opts->nb_td; i++) {
 		if (opts->dump_all_stats) {
 			mcs_stats_dump(ctx, op,
 					rx_sess[i], tx_sess[i],
 					rx_sc_id[i], tx_sc_id[i],
 					rx_sa_id[i], tx_sa_id[i]);
+		} else {
+			if (ret == TEST_SUCCESS)
+				ret = mcs_stats_check(ctx, op, opts, td[i],
+					rx_sess[i], tx_sess[i],
+					rx_sc_id[i], tx_sc_id[i],
+					rx_sa_id[i], tx_sa_id[i]);
 		}
 	}
 
@@ -1182,6 +1290,220 @@ test_inline_macsec_with_vlan(const void *data __rte_unused)
 	return all_err;
 }
 
+static int
+test_inline_macsec_pkt_drop(const void *data __rte_unused)
+{
+	const struct mcs_test_vector *cur_td;
+	struct mcs_test_opts opts = {0};
+	int err, all_err = 0;
+	int i, size;
+
+	opts.val_frames = RTE_SECURITY_MACSEC_VALIDATE_STRICT;
+	opts.encrypt = true;
+	opts.protect_frames = true;
+	opts.sa_in_use = 1;
+	opts.nb_td = 1;
+	opts.sectag_insert_mode = 1;
+	opts.mtu = RTE_ETHER_MTU;
+
+	size = (sizeof(list_mcs_err_cipher_vectors) / sizeof((list_mcs_err_cipher_vectors)[0]));
+
+	for (i = 0; i < size; i++) {
+		cur_td = &list_mcs_err_cipher_vectors[i];
+		err = test_macsec(&cur_td, MCS_DECAP, &opts);
+		if (err) {
+			printf("\nPacket drop case %d passed", cur_td->test_idx);
+			err = 0;
+		} else {
+			printf("\nPacket drop case %d failed", cur_td->test_idx);
+			err = -1;
+		}
+		all_err += err;
+	}
+	printf("\n%s: Success: %d, Failure: %d\n", __func__, size + all_err, -all_err);
+
+	return all_err;
+}
+
+static int
+test_inline_macsec_untagged_rx(const void *data __rte_unused)
+{
+	const struct mcs_test_vector *cur_td;
+	struct mcs_test_opts opts = {0};
+	int err, all_err = 0;
+	int i, size;
+
+	opts.val_frames = RTE_SECURITY_MACSEC_VALIDATE_STRICT;
+	opts.sa_in_use = 1;
+	opts.nb_td = 1;
+	opts.sectag_insert_mode = 1;
+	opts.mtu = RTE_ETHER_MTU;
+	opts.check_untagged_rx = 1;
+
+	size = (sizeof(list_mcs_untagged_cipher_vectors) /
+		sizeof((list_mcs_untagged_cipher_vectors)[0]));
+
+	for (i = 0; i < size; i++) {
+		cur_td = &list_mcs_untagged_cipher_vectors[i];
+		err = test_macsec(&cur_td, MCS_DECAP, &opts);
+		if (err)
+			err = 0;
+		else
+			err = -1;
+
+		all_err += err;
+	}
+
+	opts.val_frames = RTE_SECURITY_MACSEC_VALIDATE_NO_DISCARD;
+	for (i = 0; i < size; i++) {
+		cur_td = &list_mcs_untagged_cipher_vectors[i];
+		err = test_macsec(&cur_td, MCS_DECAP, &opts);
+		if (err)
+			err = 0;
+		else
+			err = -1;
+
+		all_err += err;
+	}
+	printf("\n%s: Success: %d, Failure: %d\n", __func__, size + all_err, -all_err);
+
+	return all_err;
+}
+
+static int
+test_inline_macsec_bad_tag_rx(const void *data __rte_unused)
+{
+	const struct mcs_test_vector *cur_td;
+	struct mcs_test_opts opts = {0};
+	int err, all_err = 0;
+	int i, size;
+
+	opts.val_frames = RTE_SECURITY_MACSEC_VALIDATE_STRICT;
+	opts.protect_frames = true;
+	opts.sa_in_use = 1;
+	opts.nb_td = 1;
+	opts.sectag_insert_mode = 1;
+	opts.mtu = RTE_ETHER_MTU;
+	opts.check_bad_tag_cnt = 1;
+
+	size = (sizeof(list_mcs_bad_tag_vectors) / sizeof((list_mcs_bad_tag_vectors)[0]));
+
+	for (i = 0; i < size; i++) {
+		cur_td = &list_mcs_bad_tag_vectors[i];
+		err = test_macsec(&cur_td, MCS_DECAP, &opts);
+		if (err)
+			err = -1;
+		else
+			err = 0;
+
+		all_err += err;
+	}
+
+	printf("\n%s: Success: %d, Failure: %d\n", __func__, size + all_err, -all_err);
+
+	return all_err;
+}
+
+static int
+test_inline_macsec_sa_not_in_use(const void *data __rte_unused)
+{
+	const struct mcs_test_vector *cur_td;
+	struct mcs_test_opts opts = {0};
+	int err, all_err = 0;
+	int i, size;
+
+	opts.val_frames = RTE_SECURITY_MACSEC_VALIDATE_STRICT;
+	opts.protect_frames = true;
+	opts.sa_in_use = 0;
+	opts.nb_td = 1;
+	opts.sectag_insert_mode = 1;
+	opts.mtu = RTE_ETHER_MTU;
+	opts.check_sa_not_in_use = 1;
+
+	size = (sizeof(list_mcs_cipher_vectors) / sizeof((list_mcs_cipher_vectors)[0]));
+
+	for (i = 0; i < size; i++) {
+		cur_td = &list_mcs_cipher_vectors[i];
+		err = test_macsec(&cur_td, MCS_DECAP, &opts);
+		if (err)
+			err = -1;
+		else
+			err = 0;
+
+		all_err += err;
+	}
+
+	printf("\n%s: Success: %d, Failure: %d\n", __func__, size + all_err, -all_err);
+
+	return all_err;
+}
+
+static int
+test_inline_macsec_out_pkts_untagged(const void *data __rte_unused)
+{
+	const struct mcs_test_vector *cur_td;
+	struct mcs_test_opts opts = {0};
+	int err, all_err = 0;
+	int i, size;
+
+	opts.val_frames = RTE_SECURITY_MACSEC_VALIDATE_STRICT;
+	opts.encrypt = false;
+	opts.protect_frames = false;
+	opts.sa_in_use = 1;
+	opts.nb_td = 1;
+	opts.sectag_insert_mode = 1;
+	opts.mtu = RTE_ETHER_MTU;
+	opts.check_out_pkts_untagged = 1;
+
+	size = (sizeof(list_mcs_cipher_vectors) / sizeof((list_mcs_cipher_vectors)[0]));
+	for (i = 0; i < size; i++) {
+		cur_td = &list_mcs_cipher_vectors[i];
+		err = test_macsec(&cur_td, MCS_ENCAP, &opts);
+		if (err)
+			err = -1;
+		else
+			err = 0;
+
+		all_err += err;
+	}
+
+	printf("\n%s: Success: %d, Failure: %d\n", __func__, size + all_err, -all_err);
+	return all_err;
+}
+
+static int
+test_inline_macsec_out_pkts_toolong(const void *data __rte_unused)
+{
+	const struct mcs_test_vector *cur_td;
+	struct mcs_test_opts opts = {0};
+	int err, all_err = 0;
+	int i, size;
+
+	opts.val_frames = RTE_SECURITY_MACSEC_VALIDATE_NO_DISCARD;
+	opts.encrypt = true;
+	opts.protect_frames = true;
+	opts.sa_in_use = 1;
+	opts.nb_td = 1;
+	opts.sectag_insert_mode = 1;
+	opts.mtu = 50;
+	opts.check_out_pkts_toolong = 1;
+
+	size = (sizeof(list_mcs_cipher_vectors) / sizeof((list_mcs_cipher_vectors)[0]));
+	for (i = 0; i < size; i++) {
+		cur_td = &list_mcs_cipher_vectors[i];
+		err = test_macsec(&cur_td, MCS_ENCAP, &opts);
+		if (err)
+			err = -1;
+		else
+			err = 0;
+
+		all_err += err;
+	}
+
+	printf("\n%s: Success: %d, Failure: %d\n", __func__, size + all_err, -all_err);
+	return all_err;
+}
+
 static int
 ut_setup_inline_macsec(void)
 {
@@ -1359,6 +1681,30 @@ static struct unit_test_suite inline_macsec_testsuite  = {
 			"MACsec Encap and decap with VLAN",
 			ut_setup_inline_macsec, ut_teardown_inline_macsec,
 			test_inline_macsec_with_vlan),
+		TEST_CASE_NAMED_ST(
+			"MACsec packet drop",
+			ut_setup_inline_macsec, ut_teardown_inline_macsec,
+			test_inline_macsec_pkt_drop),
+		TEST_CASE_NAMED_ST(
+			"MACsec untagged Rx",
+			ut_setup_inline_macsec, ut_teardown_inline_macsec,
+			test_inline_macsec_untagged_rx),
+		TEST_CASE_NAMED_ST(
+			"MACsec bad tag Rx",
+			ut_setup_inline_macsec, ut_teardown_inline_macsec,
+			test_inline_macsec_bad_tag_rx),
+		TEST_CASE_NAMED_ST(
+			"MACsec SA not in use",
+			ut_setup_inline_macsec, ut_teardown_inline_macsec,
+			test_inline_macsec_sa_not_in_use),
+		TEST_CASE_NAMED_ST(
+			"MACsec out pkts untagged",
+			ut_setup_inline_macsec, ut_teardown_inline_macsec,
+			test_inline_macsec_out_pkts_untagged),
+		TEST_CASE_NAMED_ST(
+			"MACsec out pkts too long",
+			ut_setup_inline_macsec, ut_teardown_inline_macsec,
+			test_inline_macsec_out_pkts_toolong),
 
 		TEST_CASES_END() /**< NULL terminate unit test array */
 	},
app/test/test_security_inline_macsec_vectors.h +475 -0

481 lines not on this page · raw message

Signature · 1 line
2.25.1
#33 lore raw

PATCH 8/13 test/security: verify MACsec stats

In reply to Akhil Goyal

Added cases to verify various stats of MACsec.

---
 app/test/test_security_inline_macsec.c | 222 +++++++++++++++++++++++++
 1 file changed, 222 insertions(+)
app/test/test_security_inline_macsec.c +222 -0
index 9c4546fa38..a6d23f2769 100644
@@ -1438,6 +1438,140 @@ test_inline_macsec_sa_not_in_use(const void *data __rte_unused)
 	return all_err;
 }
 
+static int
+test_inline_macsec_decap_stats(const void *data __rte_unused)
+{
+	const struct mcs_test_vector *cur_td;
+	struct mcs_test_opts opts = {0};
+	int err, all_err = 0;
+	int i, size;
+
+	opts.val_frames = RTE_SECURITY_MACSEC_VALIDATE_STRICT;
+	opts.protect_frames = true;
+	opts.sa_in_use = 1;
+	opts.nb_td = 1;
+	opts.sectag_insert_mode = 1;
+	opts.mtu = RTE_ETHER_MTU;
+	opts.check_decap_stats = 1;
+
+	size = (sizeof(list_mcs_cipher_vectors) / sizeof((list_mcs_cipher_vectors)[0]));
+
+	for (i = 0; i < size; i++) {
+		cur_td = &list_mcs_cipher_vectors[i];
+		err = test_macsec(&cur_td, MCS_DECAP, &opts);
+		if (err) {
+			printf("\nDecap stats case %d failed", cur_td->test_idx);
+			err = -1;
+		} else {
+			printf("\nDecap stats case %d passed", cur_td->test_idx);
+			err = 0;
+		}
+		all_err += err;
+	}
+	printf("\n%s: Success: %d, Failure: %d\n", __func__, size + all_err, -all_err);
+
+	return all_err;
+}
+
+static int
+test_inline_macsec_verify_only_stats(const void *data __rte_unused)
+{
+	const struct mcs_test_vector *cur_td;
+	struct mcs_test_opts opts = {0};
+	int err, all_err = 0;
+	int i, size;
+
+	opts.val_frames = RTE_SECURITY_MACSEC_VALIDATE_STRICT;
+	opts.protect_frames = true;
+	opts.sa_in_use = 1;
+	opts.nb_td = 1;
+	opts.sectag_insert_mode = 1;
+	opts.mtu = RTE_ETHER_MTU;
+	opts.check_verify_only_stats = 1;
+
+	size = (sizeof(list_mcs_integrity_vectors) / sizeof((list_mcs_integrity_vectors)[0]));
+
+	for (i = 0; i < size; i++) {
+		cur_td = &list_mcs_integrity_vectors[i];
+		err = test_macsec(&cur_td, MCS_VERIFY_ONLY, &opts);
+		if (err) {
+			printf("\nVerify only stats case %d failed", cur_td->test_idx);
+			err = -1;
+		} else {
+			printf("\nVerify only stats case %d Passed", cur_td->test_idx);
+			err = 0;
+		}
+		all_err += err;
+	}
+	printf("\n%s: Success: %d, Failure: %d\n", __func__, size + all_err, -all_err);
+
+	return all_err;
+}
+
+static int
+test_inline_macsec_pkts_invalid_stats(const void *data __rte_unused)
+{
+	const struct mcs_test_vector *cur_td;
+	struct mcs_test_opts opts = {0};
+	int err, all_err = 0;
+	int i, size;
+
+	opts.val_frames = RTE_SECURITY_MACSEC_VALIDATE_STRICT;
+	opts.protect_frames = true;
+	opts.sa_in_use = 1;
+	opts.nb_td = 1;
+	opts.sectag_insert_mode = 1;
+	opts.mtu = RTE_ETHER_MTU;
+
+	size = (sizeof(list_mcs_err_cipher_vectors) / sizeof((list_mcs_err_cipher_vectors)[0]));
+
+	for (i = 0; i < size; i++) {
+		cur_td = &list_mcs_err_cipher_vectors[i];
+		err = test_macsec(&cur_td, MCS_DECAP, &opts);
+		if (err)
+			err = 0;
+		else
+			err = -1;
+
+		all_err += err;
+	}
+	printf("\n%s: Success: %d, Failure: %d\n", __func__, size + all_err, -all_err);
+	return all_err;
+}
+
+static int
+test_inline_macsec_pkts_unchecked_stats(const void *data __rte_unused)
+{
+	const struct mcs_test_vector *cur_td;
+	struct mcs_test_opts opts = {0};
+	int err, all_err = 0;
+	int i, size;
+
+	opts.val_frames = RTE_SECURITY_MACSEC_VALIDATE_DISABLE;
+	opts.protect_frames = true;
+	opts.sa_in_use = 1;
+	opts.nb_td = 1;
+	opts.sectag_insert_mode = 1;
+	opts.mtu = RTE_ETHER_MTU;
+	opts.check_pkts_unchecked_stats = 1;
+
+	size = (sizeof(list_mcs_integrity_vectors) / sizeof((list_mcs_integrity_vectors)[0]));
+
+	for (i = 0; i < size; i++) {
+		cur_td = &list_mcs_integrity_vectors[i];
+		err = test_macsec(&cur_td, MCS_VERIFY_ONLY, &opts);
+		if (err)
+			err = -1;
+		else
+			err = 0;
+
+		all_err += err;
+	}
+
+	printf("\n%s: Success: %d, Failure: %d\n", __func__, size + all_err, -all_err);
+	return all_err;
+}
+
 static int
 test_inline_macsec_out_pkts_untagged(const void *data __rte_unused)
 {
@@ -1504,6 +1638,70 @@ test_inline_macsec_out_pkts_toolong(const void *data __rte_unused)
 	return all_err;
 }
 
+static int
+test_inline_macsec_encap_stats(const void *data __rte_unused)
+{
+	const struct mcs_test_vector *cur_td;
+	struct mcs_test_opts opts = {0};
+	int err, all_err = 0;
+	int i, size;
+
+	opts.val_frames = RTE_SECURITY_MACSEC_VALIDATE_STRICT;
+	opts.encrypt = true;
+	opts.protect_frames = true;
+	opts.sa_in_use = 1;
+	opts.nb_td = 1;
+	opts.sectag_insert_mode = 1;
+	opts.mtu = RTE_ETHER_MTU;
+	opts.check_encap_stats = 1;
+
+	size = (sizeof(list_mcs_cipher_vectors) / sizeof((list_mcs_cipher_vectors)[0]));
+	for (i = 0; i < size; i++) {
+		cur_td = &list_mcs_cipher_vectors[i];
+		err = test_macsec(&cur_td, MCS_ENCAP, &opts);
+		if (err)
+			err = -1;
+		else
+			err = 0;
+		all_err += err;
+	}
+
+	printf("\n%s: Success: %d, Failure: %d\n", __func__, size + all_err, -all_err);
+	return all_err;
+}
+
+static int
+test_inline_macsec_auth_only_stats(const void *data __rte_unused)
+{
+	const struct mcs_test_vector *cur_td;
+	struct mcs_test_opts opts = {0};
+	int err, all_err = 0;
+	int i, size;
+
+	opts.val_frames = RTE_SECURITY_MACSEC_VALIDATE_STRICT;
+	opts.protect_frames = true;
+	opts.sa_in_use = 1;
+	opts.nb_td = 1;
+	opts.sectag_insert_mode = 1;
+	opts.mtu = RTE_ETHER_MTU;
+	opts.check_auth_only_stats = 1;
+
+	size = (sizeof(list_mcs_integrity_vectors) / sizeof((list_mcs_integrity_vectors)[0]));
+
+	for (i = 0; i < size; i++) {
+		cur_td = &list_mcs_integrity_vectors[i];
+		err = test_macsec(&cur_td, MCS_AUTH_ONLY, &opts);
+		if (err)
+			err = -1;
+		else
+			err = 0;
+		all_err += err;
+	}
+
+	printf("\n%s: Success: %d, Failure: %d\n", __func__, size + all_err, -all_err);
+	return all_err;
+}
+
 static int
 ut_setup_inline_macsec(void)
 {
@@ -1697,6 +1895,22 @@ static struct unit_test_suite inline_macsec_testsuite  = {
 			"MACsec SA not in use",
 			ut_setup_inline_macsec, ut_teardown_inline_macsec,
 			test_inline_macsec_sa_not_in_use),
+		TEST_CASE_NAMED_ST(
+			"MACsec decap stats",
+			ut_setup_inline_macsec, ut_teardown_inline_macsec,
+			test_inline_macsec_decap_stats),
+		TEST_CASE_NAMED_ST(
+			"MACsec verify only stats",
+			ut_setup_inline_macsec, ut_teardown_inline_macsec,
+			test_inline_macsec_verify_only_stats),
+		TEST_CASE_NAMED_ST(
+			"MACsec pkts invalid stats",
+			ut_setup_inline_macsec, ut_teardown_inline_macsec,
+			test_inline_macsec_pkts_invalid_stats),
+		TEST_CASE_NAMED_ST(
+			"MACsec pkts unchecked stats",
+			ut_setup_inline_macsec, ut_teardown_inline_macsec,
+			test_inline_macsec_pkts_unchecked_stats),
 		TEST_CASE_NAMED_ST(
 			"MACsec out pkts untagged",
 			ut_setup_inline_macsec, ut_teardown_inline_macsec,
@@ -1705,6 +1919,14 @@ static struct unit_test_suite inline_macsec_testsuite  = {
 			"MACsec out pkts too long",
 			ut_setup_inline_macsec, ut_teardown_inline_macsec,
 			test_inline_macsec_out_pkts_toolong),
+		TEST_CASE_NAMED_ST(
+			"MACsec Encap stats",
+			ut_setup_inline_macsec, ut_teardown_inline_macsec,
+			test_inline_macsec_encap_stats),
+		TEST_CASE_NAMED_ST(
+			"MACsec auth only stats",
+			ut_setup_inline_macsec, ut_teardown_inline_macsec,
+			test_inline_macsec_auth_only_stats),
 
 		TEST_CASES_END() /**< NULL terminate unit test array */
 	},
Signature · 1 line
2.25.1
#34 lore raw

PATCH 9/13 test/security: verify MACsec interrupts

In reply to Akhil Goyal

From: Ankur Dwivedi <[email protected]>

This patch enables the test_inline_macsec_interrupts_all test case for MACSEC.

---
 app/test/test_security_inline_macsec.c        | 124 +++++++
 .../test_security_inline_macsec_vectors.h     | 306 +++++++++++++++++-
 2 files changed, 429 insertions(+), 1 deletion(-)
app/test/test_security_inline_macsec.c +124 -0
index a6d23f2769..4cb184b62c 100644
@@ -757,6 +757,71 @@ mcs_stats_check(struct rte_security_ctx *ctx, enum mcs_op op,
 	return 0;
 }
 
+static int
+test_macsec_event_callback(uint16_t port_id, enum rte_eth_event_type type,
+			   void *param, void *ret_param)
+{
+	struct mcs_err_vector *vector = (struct mcs_err_vector *)param;
+	struct rte_eth_event_macsec_desc *event_desc = NULL;
+
+	RTE_SET_USED(port_id);
+
+	if (type != RTE_ETH_EVENT_MACSEC)
+		return -1;
+
+	event_desc = ret_param;
+	if (event_desc == NULL) {
+		printf("Event descriptor not set\n");
+		return -1;
+	}
+	vector->notify_event = true;
+
+	switch (event_desc->type) {
+	case RTE_ETH_EVENT_MACSEC_SECTAG_VAL_ERR:
+		vector->event = RTE_ETH_EVENT_MACSEC_SECTAG_VAL_ERR;
+		switch (event_desc->subtype) {
+		case RTE_ETH_SUBEVENT_MACSEC_RX_SECTAG_V_EQ1:
+			vector->event_subtype = RTE_ETH_SUBEVENT_MACSEC_RX_SECTAG_V_EQ1;
+			break;
+		case RTE_ETH_SUBEVENT_MACSEC_RX_SECTAG_E_EQ0_C_EQ1:
+			vector->event_subtype = RTE_ETH_SUBEVENT_MACSEC_RX_SECTAG_E_EQ0_C_EQ1;
+			break;
+		case RTE_ETH_SUBEVENT_MACSEC_RX_SECTAG_SL_GTE48:
+			vector->event_subtype = RTE_ETH_SUBEVENT_MACSEC_RX_SECTAG_SL_GTE48;
+			break;
+		case RTE_ETH_SUBEVENT_MACSEC_RX_SECTAG_ES_EQ1_SC_EQ1:
+			vector->event_subtype = RTE_ETH_SUBEVENT_MACSEC_RX_SECTAG_ES_EQ1_SC_EQ1;
+			break;
+		case RTE_ETH_SUBEVENT_MACSEC_RX_SECTAG_SC_EQ1_SCB_EQ1:
+			vector->event_subtype = RTE_ETH_SUBEVENT_MACSEC_RX_SECTAG_SC_EQ1_SCB_EQ1;
+			break;
+		default:
+			printf("\nUnknown Macsec event subtype: %d", event_desc->subtype);
+		}
+		break;
+	case RTE_ETH_EVENT_MACSEC_RX_SA_PN_HARD_EXP:
+		vector->event = RTE_ETH_EVENT_MACSEC_RX_SA_PN_HARD_EXP;
+		break;
+	case RTE_ETH_EVENT_MACSEC_RX_SA_PN_SOFT_EXP:
+		vector->event = RTE_ETH_EVENT_MACSEC_RX_SA_PN_SOFT_EXP;
+		break;
+	case RTE_ETH_EVENT_MACSEC_TX_SA_PN_HARD_EXP:
+		vector->event = RTE_ETH_EVENT_MACSEC_TX_SA_PN_HARD_EXP;
+		break;
+	case RTE_ETH_EVENT_MACSEC_TX_SA_PN_SOFT_EXP:
+		vector->event = RTE_ETH_EVENT_MACSEC_TX_SA_PN_SOFT_EXP;
+		break;
+	case RTE_ETH_EVENT_MACSEC_SA_NOT_VALID:
+		vector->event = RTE_ETH_EVENT_MACSEC_SA_NOT_VALID;
+		break;
+	default:
+		printf("Invalid MACsec event reported\n");
+		return -1;
+	}
+
+	return 0;
+}
+
 static int
 test_macsec(const struct mcs_test_vector *td[], enum mcs_op op, const struct mcs_test_opts *opts)
 {
@@ -914,6 +979,8 @@ test_macsec(const struct mcs_test_vector *td[], enum mcs_op op, const struct mcs
 		while (--nb_rx >= 0)
 			rte_pktmbuf_free(rx_pkts_burst[nb_rx]);
 		ret = TEST_FAILED;
+		if (opts->check_sectag_interrupts == 1)
+			ret = TEST_SUCCESS;
 		goto out;
 	}
 
@@ -1702,6 +1769,59 @@ test_inline_macsec_auth_only_stats(const void *data __rte_unused)
 	return all_err;
 }
 
+static int
+test_inline_macsec_interrupts_all(const void *data __rte_unused)
+{
+	struct mcs_err_vector err_vector = {0};
+	const struct mcs_test_vector *cur_td;
+	struct mcs_test_opts opts = {0};
+	int i, size;
+	int err, all_err = 0;
+	enum rte_eth_event_macsec_subtype subtype[] =  {
+		RTE_ETH_SUBEVENT_MACSEC_RX_SECTAG_V_EQ1,
+		RTE_ETH_SUBEVENT_MACSEC_RX_SECTAG_E_EQ0_C_EQ1,
+		RTE_ETH_SUBEVENT_MACSEC_RX_SECTAG_SL_GTE48,
+		RTE_ETH_SUBEVENT_MACSEC_RX_SECTAG_ES_EQ1_SC_EQ1,
+		RTE_ETH_SUBEVENT_MACSEC_RX_SECTAG_SC_EQ1_SCB_EQ1,
+	};
+
+	opts.val_frames = RTE_SECURITY_MACSEC_VALIDATE_STRICT;
+	opts.protect_frames = true;
+	opts.sa_in_use = 1;
+	opts.nb_td = 1;
+	opts.sectag_insert_mode = 1;
+	opts.mtu = RTE_ETHER_MTU;
+	opts.check_sectag_interrupts = 1;
+
+	err_vector.event = RTE_ETH_EVENT_MACSEC_UNKNOWN;
+	err_vector.event_subtype = RTE_ETH_SUBEVENT_MACSEC_UNKNOWN;
+	rte_eth_dev_callback_register(port_id, RTE_ETH_EVENT_MACSEC,
+			test_macsec_event_callback, &err_vector);
+
+	size = (sizeof(list_mcs_intr_test_vectors) / sizeof((list_mcs_intr_test_vectors)[0]));
+
+	for (i = 0; i < size; i++) {
+		cur_td = &list_mcs_intr_test_vectors[i];
+		err = test_macsec(&cur_td, MCS_DECAP, &opts);
+		if ((err_vector.event == RTE_ETH_EVENT_MACSEC_SECTAG_VAL_ERR) &&
+		    (err_vector.event_subtype == subtype[i])) {
+			printf("\nSectag val err interrupt test case %d passed",
+			       cur_td->test_idx);
+			err = 0;
+		} else {
+			printf("\nSectag val err interrupt test case %d failed",
+			       cur_td->test_idx);
+			err = -1;
+		}
+		all_err += err;
+	}
+	rte_eth_dev_callback_unregister(port_id, RTE_ETH_EVENT_MACSEC,
+			test_macsec_event_callback, &err_vector);
+
+	printf("\n%s: Success: %d, Failure: %d\n", __func__, size + all_err, -all_err);
+	return all_err;
+}
+
 static int
 ut_setup_inline_macsec(void)
 {
@@ -1927,6 +2047,10 @@ static struct unit_test_suite inline_macsec_testsuite  = {
 			"MACsec auth only stats",
 			ut_setup_inline_macsec, ut_teardown_inline_macsec,
 			test_inline_macsec_auth_only_stats),
+		TEST_CASE_NAMED_ST(
+			"MACsec interrupts all",
+			ut_setup_inline_macsec, ut_teardown_inline_macsec,
+			test_inline_macsec_interrupts_all),
 
 		TEST_CASES_END() /**< NULL terminate unit test array */
 	},
app/test/test_security_inline_macsec_vectors.h +305 -1

317 lines not on this page · raw message

Signature · 1 line
2.25.1
#35 lore raw

PATCH 10/13 test/security: verify MACsec Tx HW rekey

In reply to Akhil Goyal

This patch enables the Tx HW rekey test case for MACSEC.

---
 app/test/test_security_inline_macsec.c        | 137 +++++++++-
 .../test_security_inline_macsec_vectors.h     | 243 ++++++++++++++++++
 2 files changed, 378 insertions(+), 2 deletions(-)
app/test/test_security_inline_macsec.c +135 -2
index 4cb184b62c..a4c64429b3 100644
@@ -207,6 +207,8 @@ fill_macsec_sc_conf(const struct mcs_test_vector *td,
 	uint8_t i;
 
 	sc_conf->dir = dir;
+	sc_conf->pn_threshold = ((uint64_t)td->xpn << 32) |
+		rte_be_to_cpu_32(*(const uint32_t *)(&td->secure_pkt.data[tci_off + 2]));
 	if (dir == RTE_SECURITY_MACSEC_DIR_TX) {
 		sc_conf->sc_tx.sa_id = sa_id[0];
 		if (sa_id[1] != MCS_INVALID_SA) {
@@ -232,12 +234,16 @@ fill_macsec_sc_conf(const struct mcs_test_vector *td,
 			/* use some default SCI */
 			sc_conf->sc_tx.sci = 0xf1341e023a2b1c5d;
 		}
+		if (td->xpn > 0)
+			sc_conf->sc_tx.is_xpn = 1;
 	} else {
 		for (i = 0; i < RTE_SECURITY_MACSEC_NUM_AN; i++) {
 			sc_conf->sc_rx.sa_id[i] = sa_id[i];
 			sc_conf->sc_rx.sa_in_use[i] = opts->sa_in_use;
 		}
 		sc_conf->sc_rx.active = 1;
+		if (td->xpn > 0)
+			sc_conf->sc_rx.is_xpn = 1;
 	}
 }
 
@@ -834,6 +840,7 @@ test_macsec(const struct mcs_test_vector *td[], enum mcs_op op, const struct mcs
 	struct rte_security_session_conf sess_conf = {0};
 	struct rte_security_macsec_sa sa_conf = {0};
 	struct rte_security_macsec_sc sc_conf = {0};
+	struct mcs_err_vector err_vector = {0};
 	struct rte_security_ctx *ctx;
 	int nb_rx = 0, nb_sent;
 	int i, j = 0, ret, id, an = 0;
@@ -868,6 +875,34 @@ test_macsec(const struct mcs_test_vector *td[], enum mcs_op op, const struct mcs
 		}
 		j++;
 
+		if (opts->rekey_en) {
+
+			err_vector.td = td[i];
+			err_vector.rekey_td = opts->rekey_td;
+			err_vector.event = RTE_ETH_EVENT_MACSEC_UNKNOWN;
+			err_vector.event_subtype = RTE_ETH_SUBEVENT_MACSEC_UNKNOWN;
+			rte_eth_dev_callback_register(port_id, RTE_ETH_EVENT_MACSEC,
+					test_macsec_event_callback, &err_vector);
+			if (op == MCS_DECAP || op == MCS_VERIFY_ONLY)
+				tx_pkts_burst[j] = init_packet(mbufpool,
+						opts->rekey_td->secure_pkt.data,
+						opts->rekey_td->secure_pkt.len);
+			else {
+				tx_pkts_burst[j] = init_packet(mbufpool,
+						opts->rekey_td->plain_pkt.data,
+						opts->rekey_td->plain_pkt.len);
+
+				tx_pkts_burst[j]->ol_flags |= RTE_MBUF_F_TX_MACSEC;
+			}
+			if (tx_pkts_burst[j] == NULL) {
+				while (j--)
+					rte_pktmbuf_free(tx_pkts_burst[j]);
+				ret = TEST_FAILED;
+				goto out;
+			}
+			j++;
+		}
+
 		if (op == MCS_DECAP || op == MCS_ENCAP_DECAP ||
 				op == MCS_VERIFY_ONLY || op == MCS_AUTH_VERIFY) {
 			for (an = 0; an < RTE_SECURITY_MACSEC_NUM_AN; an++) {
@@ -922,6 +957,20 @@ test_macsec(const struct mcs_test_vector *td[], enum mcs_op op, const struct mcs
 			}
 			tx_sa_id[i][0] = (uint16_t)id;
 			tx_sa_id[i][1] = MCS_INVALID_SA;
+			if (opts->rekey_en) {
+				memset(&sa_conf, 0, sizeof(struct rte_security_macsec_sa));
+				fill_macsec_sa_conf(opts->rekey_td, &sa_conf,
+					RTE_SECURITY_MACSEC_DIR_TX,
+					opts->rekey_td->secure_pkt.data[tci_off] &
+						RTE_MACSEC_AN_MASK,
+					tci_off);
+				id = rte_security_macsec_sa_create(ctx, &sa_conf);
+				if (id < 0) {
+					printf("MACsec rekey SA create failed : %d.\n", id);
+					goto out;
+				}
+				tx_sa_id[i][1] = (uint16_t)id;
+			}
 			fill_macsec_sc_conf(td[i], &sc_conf, opts,
 					RTE_SECURITY_MACSEC_DIR_TX, tx_sa_id[i], tci_off);
 			id = rte_security_macsec_sc_create(ctx, &sc_conf);
@@ -984,9 +1033,44 @@ test_macsec(const struct mcs_test_vector *td[], enum mcs_op op, const struct mcs
 		goto out;
 	}
 
+	if (opts->rekey_en) {
+		switch (err_vector.event) {
+		case RTE_ETH_EVENT_MACSEC_TX_SA_PN_SOFT_EXP:
+			printf("Received RTE_ETH_EVENT_MACSEC_TX_SA_PN_SOFT_EXP event\n");
+			/* The first sa is active now, so the 0th sa can be
+			 * reconfigured. Using the same key as zeroeth sa, but
+			 * other key can also be configured.
+			 */
+			rte_security_macsec_sa_destroy(ctx, tx_sa_id[0][0],
+					RTE_SECURITY_MACSEC_DIR_TX);
+			fill_macsec_sa_conf(td[0], &sa_conf,
+					RTE_SECURITY_MACSEC_DIR_TX,
+					td[0]->secure_pkt.data[tci_off] &
+					RTE_MACSEC_AN_MASK, tci_off);
+			id = rte_security_macsec_sa_create(ctx, &sa_conf);
+			if (id < 0) {
+				printf("MACsec SA create failed : %d.\n", id);
+				return TEST_FAILED;
+			}
+			tx_sa_id[0][0] = (uint16_t)id;
+			break;
+		default:
+			printf("Received unsupported event\n");
+		}
+	}
+
 	for (i = 0; i < nb_rx; i++) {
-		ret = test_macsec_post_process(rx_pkts_burst[i], td[i], op,
-				opts->check_out_pkts_untagged);
+		if (opts->rekey_en && i == 1) {
+			/* The second received packet is matched with
+			 * rekey td
+			 */
+			ret = test_macsec_post_process(rx_pkts_burst[i],
+					opts->rekey_td, op,
+					opts->check_out_pkts_untagged);
+		} else {
+			ret = test_macsec_post_process(rx_pkts_burst[i], td[i],
+					op, opts->check_out_pkts_untagged);
+		}
 		if (ret != TEST_SUCCESS) {
 			for ( ; i < nb_rx; i++)
 				rte_pktmbuf_free(rx_pkts_burst[i]);
@@ -1019,6 +1103,10 @@ test_macsec(const struct mcs_test_vector *td[], enum mcs_op op, const struct mcs
 
 	destroy_default_flow(port_id);
 
+	if (opts->rekey_en)
+		rte_eth_dev_callback_unregister(port_id, RTE_ETH_EVENT_MACSEC,
+					test_macsec_event_callback, &err_vector);
+
 	/* Destroy session so that other cases can create the session again */
 	for (i = 0; i < opts->nb_td; i++) {
 		if (op == MCS_ENCAP || op == MCS_ENCAP_DECAP ||
@@ -1029,6 +1117,10 @@ test_macsec(const struct mcs_test_vector *td[], enum mcs_op op, const struct mcs
 						RTE_SECURITY_MACSEC_DIR_TX);
 			rte_security_macsec_sa_destroy(ctx, tx_sa_id[i][0],
 						RTE_SECURITY_MACSEC_DIR_TX);
+			if (opts->rekey_en) {
+				rte_security_macsec_sa_destroy(ctx, tx_sa_id[i][1],
+						RTE_SECURITY_MACSEC_DIR_TX);
+			}
 		}
 		if (op == MCS_DECAP || op == MCS_ENCAP_DECAP ||
 				op == MCS_VERIFY_ONLY || op == MCS_AUTH_VERIFY) {
@@ -1822,6 +1914,43 @@ test_inline_macsec_interrupts_all(const void *data __rte_unused)
 	return all_err;
 }
 
+static int
+test_inline_macsec_rekey_tx(const void *data __rte_unused)
+{
+	const struct mcs_test_vector *cur_td;
+	struct mcs_test_opts opts = {0};
+	int err, all_err = 0;
+	int i, size;
+
+	opts.val_frames = RTE_SECURITY_MACSEC_VALIDATE_STRICT;
+	opts.protect_frames = true;
+	opts.encrypt = true;
+	opts.sa_in_use = 1;
+	opts.nb_td = 1;
+	opts.sectag_insert_mode = 1;
+	opts.mtu = RTE_ETHER_MTU;
+	opts.rekey_en = 1;
+
+	size = (sizeof(list_mcs_rekey_vectors) / sizeof((list_mcs_rekey_vectors)[0]));
+
+	for (i = 0; i < size; i++) {
+		cur_td = &list_mcs_rekey_vectors[i];
+		opts.rekey_td = &list_mcs_rekey_vectors[++i];
+		err = test_macsec(&cur_td, MCS_ENCAP, &opts);
+		if (err) {
+			printf("Tx hw rekey test case %d failed\n", i);
+			err = -1;
+		} else {
+			printf("Tx hw rekey test case %d passed\n", i);
+			err = 0;
+		}
+		all_err += err;
+	}
+
+	printf("\n%s: Success: %d, Failure: %d\n", __func__, size + all_err, -all_err);
+	return all_err;
+}
+
 static int
 ut_setup_inline_macsec(void)
 {
@@ -2051,6 +2180,10 @@ static struct unit_test_suite inline_macsec_testsuite  = {
 			"MACsec interrupts all",
 			ut_setup_inline_macsec, ut_teardown_inline_macsec,
 			test_inline_macsec_interrupts_all),
+		TEST_CASE_NAMED_ST(
+			"MACsec re-key Tx",
+			ut_setup_inline_macsec, ut_teardown_inline_macsec,
+			test_inline_macsec_rekey_tx),
 
 		TEST_CASES_END() /**< NULL terminate unit test array */
 	},
app/test/test_security_inline_macsec_vectors.h +243 -0

253 lines not on this page · raw message

Signature · 1 line
2.25.1
#36 lore raw

PATCH 11/13 test/security: verify MACsec Rx rekey

In reply to Akhil Goyal

From: Ankur Dwivedi <[email protected]>

This patch enables the Rx rekey test case for MACSEC.

---
 app/test/test_security_inline_macsec.c | 50 +++++++++++++++++++++++++-
 1 file changed, 49 insertions(+), 1 deletion(-)
app/test/test_security_inline_macsec.c +49 -1
index a4c64429b3..6f9cec333d 100644
@@ -906,8 +906,14 @@ test_macsec(const struct mcs_test_vector *td[], enum mcs_op op, const struct mcs
 		if (op == MCS_DECAP || op == MCS_ENCAP_DECAP ||
 				op == MCS_VERIFY_ONLY || op == MCS_AUTH_VERIFY) {
 			for (an = 0; an < RTE_SECURITY_MACSEC_NUM_AN; an++) {
+				if (opts->rekey_en && an ==
+						(opts->rekey_td->secure_pkt.data[tci_off] &
+						RTE_MACSEC_AN_MASK))
+					fill_macsec_sa_conf(opts->rekey_td, &sa_conf,
+						RTE_SECURITY_MACSEC_DIR_RX, an, tci_off);
+				else
 				/* For simplicity, using same SA conf for all AN */
-				fill_macsec_sa_conf(td[i], &sa_conf,
+					fill_macsec_sa_conf(td[i], &sa_conf,
 						RTE_SECURITY_MACSEC_DIR_RX, an, tci_off);
 				id = rte_security_macsec_sa_create(ctx, &sa_conf);
 				if (id < 0) {
@@ -1054,6 +1060,9 @@ test_macsec(const struct mcs_test_vector *td[], enum mcs_op op, const struct mcs
 			}
 			tx_sa_id[0][0] = (uint16_t)id;
 			break;
+		case RTE_ETH_EVENT_MACSEC_RX_SA_PN_SOFT_EXP:
+			printf("Received RTE_ETH_EVENT_MACSEC_RX_SA_PN_SOFT_EXP event\n");
+			break;
 		default:
 			printf("Received unsupported event\n");
 		}
@@ -1951,6 +1960,41 @@ test_inline_macsec_rekey_tx(const void *data __rte_unused)
 	return all_err;
 }
 
+static int
+test_inline_macsec_rekey_rx(const void *data __rte_unused)
+{
+	const struct mcs_test_vector *cur_td;
+	struct mcs_test_opts opts = {0};
+	int err, all_err = 0;
+	int i, size;
+
+	opts.val_frames = RTE_SECURITY_MACSEC_VALIDATE_STRICT;
+	opts.protect_frames = true;
+	opts.sa_in_use = 1;
+	opts.nb_td = 1;
+	opts.sectag_insert_mode = 1;
+	opts.mtu = RTE_ETHER_MTU;
+	opts.rekey_en = 1;
+
+	size = (sizeof(list_mcs_rekey_vectors) / sizeof((list_mcs_rekey_vectors)[0]));
+	for (i = 0; i < size; i++) {
+		cur_td = &list_mcs_rekey_vectors[i];
+		opts.rekey_td = &list_mcs_rekey_vectors[++i];
+		err = test_macsec(&cur_td, MCS_DECAP, &opts);
+		if (err) {
+			printf("Rx rekey test case %d failed\n", i);
+			err = -1;
+		} else {
+			printf("Rx rekey test case %d passed\n", i);
+			err = 0;
+		}
+		all_err += err;
+	}
+
+	printf("\n%s: Success: %d, Failure: %d\n", __func__, size + all_err, -all_err);
+	return all_err;
+}
+
 static int
 ut_setup_inline_macsec(void)
 {
@@ -2184,6 +2228,10 @@ static struct unit_test_suite inline_macsec_testsuite  = {
 			"MACsec re-key Tx",
 			ut_setup_inline_macsec, ut_teardown_inline_macsec,
 			test_inline_macsec_rekey_tx),
+		TEST_CASE_NAMED_ST(
+			"MACsec re-key Rx",
+			ut_setup_inline_macsec, ut_teardown_inline_macsec,
+			test_inline_macsec_rekey_rx),
 
 		TEST_CASES_END() /**< NULL terminate unit test array */
 	},
Signature · 1 line
2.25.1
#37 lore raw

PATCH 12/13 test/security: verify MACsec anti replay

In reply to Akhil Goyal

From: Ankur Dwivedi <[email protected]>

This patch enables anti replay test case for MACsec.

---
 app/test/test_security_inline_macsec.c        |  82 +++
 .../test_security_inline_macsec_vectors.h     | 467 ++++++++++++++++++
 2 files changed, 549 insertions(+)
app/test/test_security_inline_macsec.c +82 -0
index 6f9cec333d..de67744f78 100644
@@ -61,6 +61,7 @@ struct mcs_test_opts {
 	uint8_t replay_protect;
 	uint8_t rekey_en;
 	const struct mcs_test_vector *rekey_td;
+	const struct mcs_test_vector *ar_td[3];
 	bool dump_all_stats;
 	uint8_t check_untagged_rx;
 	uint8_t check_bad_tag_cnt;
@@ -716,6 +717,15 @@ mcs_stats_check(struct rte_security_ctx *ctx, enum mcs_op op,
 		if (opts->check_pkts_unchecked_stats && sc_stat.pkt_unchecked_cnt != 1)
 			return TEST_FAILED;
 
+		if (opts->replay_protect) {
+			if (opts->replay_win_sz == 0 &&
+					sc_stat.pkt_late_cnt != 2)
+				return TEST_FAILED;
+			else if (opts->replay_win_sz == 32 &&
+					sc_stat.pkt_late_cnt != 1)
+				return TEST_FAILED;
+		}
+
 		for (i = 0; i < RTE_SECURITY_MACSEC_NUM_AN; i++) {
 			memset(&sa_stat, 0, sizeof(struct rte_security_macsec_sa_stats));
 			rte_security_macsec_sa_stats_get(ctx, rx_sa_id[i],
@@ -845,6 +855,7 @@ test_macsec(const struct mcs_test_vector *td[], enum mcs_op op, const struct mcs
 	int nb_rx = 0, nb_sent;
 	int i, j = 0, ret, id, an = 0;
 	uint8_t tci_off;
+	int k;
 
 	memset(rx_pkts_burst, 0, sizeof(rx_pkts_burst[0]) * opts->nb_td);
 
@@ -875,6 +886,20 @@ test_macsec(const struct mcs_test_vector *td[], enum mcs_op op, const struct mcs
 		}
 		j++;
 
+		if (opts->replay_protect) {
+			for (k = 0; k < 3; k++, j++) {
+				tx_pkts_burst[j] = init_packet(mbufpool,
+					opts->ar_td[k]->secure_pkt.data,
+					opts->ar_td[k]->secure_pkt.len);
+				if (tx_pkts_burst[j] == NULL) {
+					while (j--)
+						rte_pktmbuf_free(tx_pkts_burst[j]);
+					ret = TEST_FAILED;
+					goto out;
+				}
+			}
+		}
+
 		if (opts->rekey_en) {
 
 			err_vector.td = td[i];
@@ -1068,6 +1093,15 @@ test_macsec(const struct mcs_test_vector *td[], enum mcs_op op, const struct mcs
 		}
 	}
 
+	if (opts->replay_protect) {
+		for (i = 0; i < nb_rx; i++) {
+			rte_pktmbuf_free(rx_pkts_burst[i]);
+			rx_pkts_burst[i] = NULL;
+		}
+		ret = TEST_SUCCESS;
+		goto out;
+	}
+
 	for (i = 0; i < nb_rx; i++) {
 		if (opts->rekey_en && i == 1) {
 			/* The second received packet is matched with
@@ -1995,6 +2029,50 @@ test_inline_macsec_rekey_rx(const void *data __rte_unused)
 	return all_err;
 }
 
+static int
+test_inline_macsec_anti_replay(const void *data __rte_unused)
+{
+	const struct mcs_test_vector *cur_td;
+	struct mcs_test_opts opts = {0};
+	uint16_t replay_win_sz[2] = {32, 0};
+	int err, all_err = 0;
+	int i, size;
+	int j;
+
+	opts.val_frames = RTE_SECURITY_MACSEC_VALIDATE_STRICT;
+	opts.sa_in_use = 1;
+	opts.nb_td = 1;
+	opts.sectag_insert_mode = 1;
+	opts.replay_protect = 1;
+
+	size = (sizeof(list_mcs_anti_replay_vectors) / sizeof((list_mcs_anti_replay_vectors)[0]));
+
+	for (j = 0; j < 2; j++) {
+		opts.replay_win_sz = replay_win_sz[j];
+
+		for (i = 0; i < size; i++) {
+			cur_td = &list_mcs_anti_replay_vectors[i];
+			opts.ar_td[0] = &list_mcs_anti_replay_vectors[++i];
+			opts.ar_td[1] = &list_mcs_anti_replay_vectors[++i];
+			opts.ar_td[2] = &list_mcs_anti_replay_vectors[++i];
+			err = test_macsec(&cur_td, MCS_DECAP, &opts);
+			if (err) {
+				printf("Replay window: %u, Anti replay test case %d failed\n",
+				       opts.replay_win_sz, i);
+				err = -1;
+			} else {
+				printf("Replay window: %u, Anti replay test case %d passed\n",
+				       opts.replay_win_sz, i);
+				err = 0;
+			}
+			all_err += err;
+		}
+	}
+
+	printf("\n%s: Success: %d, Failure: %d\n", __func__, size + all_err, -all_err);
+	return all_err;
+}
+
 static int
 ut_setup_inline_macsec(void)
 {
@@ -2232,6 +2310,10 @@ static struct unit_test_suite inline_macsec_testsuite  = {
 			"MACsec re-key Rx",
 			ut_setup_inline_macsec, ut_teardown_inline_macsec,
 			test_inline_macsec_rekey_rx),
+		TEST_CASE_NAMED_ST(
+			"MACsec anti-replay",
+			ut_setup_inline_macsec, ut_teardown_inline_macsec,
+			test_inline_macsec_anti_replay),
 
 		TEST_CASES_END() /**< NULL terminate unit test array */
 	},
app/test/test_security_inline_macsec_vectors.h +467 -0

471 lines not on this page · raw message

Signature · 1 line
2.25.1
#38 lore raw

PATCH 13/13 test/security: remove no MACsec support case

In reply to Akhil Goyal

Removed the test_capability_get_no_support_for_macsec case as MACsec is now supported and capability can have valid MACsec support.

---
 app/test/test_security.c | 37 -------------------------------------
 1 file changed, 37 deletions(-)
app/test/test_security.c +0 -37
index e4ddcefe40..4783cd0663 100644
@@ -1828,41 +1828,6 @@ test_capability_get_no_matching_protocol(void)
 	return TEST_SUCCESS;
 }
 
-/**
- * Test execution of rte_security_capability_get when macsec protocol
- * is searched and capabilities table contain proper entry.
- * However macsec records search is not supported in rte_security.
- */
-static int
-test_capability_get_no_support_for_macsec(void)
-{
-	struct security_unittest_params *ut_params = &unittest_params;
-	struct rte_security_capability_idx idx = {
-		.action = RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL,
-		.protocol = RTE_SECURITY_PROTOCOL_MACSEC,
-	};
-	struct rte_security_capability capabilities[] = {
-		{
-			.action = RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL,
-			.protocol = RTE_SECURITY_PROTOCOL_MACSEC,
-		},
-		{
-			.action = RTE_SECURITY_ACTION_TYPE_NONE,
-		},
-	};
-
-	mock_capabilities_get_exp.device = NULL;
-	mock_capabilities_get_exp.ret = capabilities;
-
-	const struct rte_security_capability *ret;
-	ret = rte_security_capability_get(&ut_params->ctx, &idx);
-	TEST_ASSERT_MOCK_FUNCTION_CALL_RET(rte_security_capability_get,
-			ret, NULL, "%p");
-	TEST_ASSERT_MOCK_CALLS(mock_capabilities_get_exp, 1);
-
-	return TEST_SUCCESS;
-}
-
 /**
  * Test execution of rte_security_capability_get when capabilities table
  * does not contain entry with matching ipsec proto field
@@ -2319,8 +2284,6 @@ static struct unit_test_suite security_testsuite  = {
 				test_capability_get_no_matching_action),
 		TEST_CASE_ST(ut_setup_with_session, ut_teardown,
 				test_capability_get_no_matching_protocol),
-		TEST_CASE_ST(ut_setup_with_session, ut_teardown,
-				test_capability_get_no_support_for_macsec),
 		TEST_CASE_ST(ut_setup_with_session, ut_teardown,
 				test_capability_get_ipsec_mismatch_proto),
 		TEST_CASE_ST(ut_setup_with_session, ut_teardown,
Signature · 1 line
2.25.1
#39 lore raw

v2 cover Add MACsec unit test cases

In reply to Akhil Goyal

Inline MACsec offload was supported in DPDK 22.11
using rte_security APIs.
This patchset adds few minor changes in the rte_security APIs to specify the direction of SA/SC and update the SC configuration to set packet number threshold.

The patchset also add functional test cases in dpdk-test app to verify MACsec functionality.

This patchset is pending from last release [1] due to lack of hardware to test. Now the test cases are verified on Marvell cnxk PMD and the pmd support is added as a separate patchset.

[1] https://patches.dpdk.org/project/dpdk/cover/[email protected]/

Changes in v2:
- Added abignore for experimental APIs
- Fixed build

Akhil Goyal (10):
security: add direction in SA/SC configuration
security: add MACsec packet number threshold
test/security: add inline MACsec cases
test/security: add MACsec integrity cases
test/security: verify multi flow MACsec
test/security: add MACsec VLAN cases
test/security: add MACsec negative cases
test/security: verify MACsec stats
test/security: verify MACsec Tx HW rekey
test/security: remove no MACsec support case

Ankur Dwivedi (3):
test/security: verify MACsec interrupts
test/security: verify MACsec Rx rekey
test/security: verify MACsec anti replay

 app/test/meson.build                          |    1 +
 app/test/test_security.c                      |   37 -
 app/test/test_security_inline_macsec.c        | 2332 ++++++++++
 .../test_security_inline_macsec_vectors.h     | 3895 +++++++++++++++++
 devtools/libabigail.abignore                  |    7 +
 lib/security/rte_security.c                   |   16 +-
 lib/security/rte_security.h                   |   24 +-
 lib/security/rte_security_driver.h            |   12 +-
 8 files changed, 6273 insertions(+), 51 deletions(-)
 create mode 100644 app/test/test_security_inline_macsec.c
 create mode 100644 app/test/test_security_inline_macsec_vectors.h
Signature · 1 line
2.25.1
#40 lore raw

PATCH v2 1/13 security: add direction in SA/SC configuration

MACsec SC/SA ids are created based on direction of the flow. Hence, added the missing field for configuration and cleanup of the SCs and SAs.

---
 devtools/libabigail.abignore       |  7 +++++++
 lib/security/rte_security.c        | 16 ++++++++++------
 lib/security/rte_security.h        | 14 ++++++++++----
 lib/security/rte_security_driver.h | 12 ++++++++++--
 4 files changed, 37 insertions(+), 12 deletions(-)
devtools/libabigail.abignore +7 -0
index c0361bfc7b..14d8fa4293 100644
@@ -37,6 +37,13 @@
 [suppress_type]
         type_kind = enum
         changed_enumerators = RTE_CRYPTO_ASYM_XFORM_ECPM, RTE_CRYPTO_ASYM_XFORM_TYPE_LIST_END
+; Ignore changes to rte_security_ops MACsec APIs which are experimental
+[suppress_type]
+        name = rte_security_ops
+        has_data_member_inserted_between =
+        {
+                offset_of(security_macsec_sc_create_t), offset_of(security_macsec_sa_stats_get_t)
+        }
 
 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
 ; Temporary exceptions till next major ABI version ;
lib/security/rte_security.c +10 -6
index e102c55e55..c4d64bb8e9 100644
@@ -164,13 +164,14 @@ rte_security_macsec_sa_create(struct rte_security_ctx *instance,
 }
 
 int
-rte_security_macsec_sc_destroy(struct rte_security_ctx *instance, uint16_t sc_id)
+rte_security_macsec_sc_destroy(struct rte_security_ctx *instance, uint16_t sc_id,
+			       enum rte_security_macsec_direction dir)
 {
 	int ret;
 
 	RTE_PTR_CHAIN3_OR_ERR_RET(instance, ops, macsec_sc_destroy, -EINVAL, -ENOTSUP);
 
-	ret = instance->ops->macsec_sc_destroy(instance->device, sc_id);
+	ret = instance->ops->macsec_sc_destroy(instance->device, sc_id, dir);
 	if (ret != 0)
 		return ret;
 
@@ -181,13 +182,14 @@ rte_security_macsec_sc_destroy(struct rte_security_ctx *instance, uint16_t sc_id
 }
 
 int
-rte_security_macsec_sa_destroy(struct rte_security_ctx *instance, uint16_t sa_id)
+rte_security_macsec_sa_destroy(struct rte_security_ctx *instance, uint16_t sa_id,
+			       enum rte_security_macsec_direction dir)
 {
 	int ret;
 
 	RTE_PTR_CHAIN3_OR_ERR_RET(instance, ops, macsec_sa_destroy, -EINVAL, -ENOTSUP);
 
-	ret = instance->ops->macsec_sa_destroy(instance->device, sa_id);
+	ret = instance->ops->macsec_sa_destroy(instance->device, sa_id, dir);
 	if (ret != 0)
 		return ret;
 
@@ -199,22 +201,24 @@ rte_security_macsec_sa_destroy(struct rte_security_ctx *instance, uint16_t sa_id
 
 int
 rte_security_macsec_sc_stats_get(struct rte_security_ctx *instance, uint16_t sc_id,
+				 enum rte_security_macsec_direction dir,
 				 struct rte_security_macsec_sc_stats *stats)
 {
 	RTE_PTR_CHAIN3_OR_ERR_RET(instance, ops, macsec_sc_stats_get, -EINVAL, -ENOTSUP);
 	RTE_PTR_OR_ERR_RET(stats, -EINVAL);
 
-	return instance->ops->macsec_sc_stats_get(instance->device, sc_id, stats);
+	return instance->ops->macsec_sc_stats_get(instance->device, sc_id, dir, stats);
 }
 
 int
 rte_security_macsec_sa_stats_get(struct rte_security_ctx *instance, uint16_t sa_id,
+				 enum rte_security_macsec_direction dir,
 				 struct rte_security_macsec_sa_stats *stats)
 {
 	RTE_PTR_CHAIN3_OR_ERR_RET(instance, ops, macsec_sa_stats_get, -EINVAL, -ENOTSUP);
 	RTE_PTR_OR_ERR_RET(stats, -EINVAL);
 
-	return instance->ops->macsec_sa_stats_get(instance->device, sa_id, stats);
+	return instance->ops->macsec_sa_stats_get(instance->device, sa_id, dir, stats);
 }
 
 int
lib/security/rte_security.h +10 -4
index 4bacf9fcd9..c7a523b6d6 100644
@@ -761,6 +761,7 @@ rte_security_macsec_sc_create(struct rte_security_ctx *instance,
  *
  * @param   instance	security instance
  * @param   sc_id	SC ID to be destroyed
+ * @param   dir		direction of the SC
  * @return
  *  - 0 if successful.
  *  - -EINVAL if sc_id is invalid or instance is NULL.
@@ -768,7 +769,8 @@ rte_security_macsec_sc_create(struct rte_security_ctx *instance,
  */
 __rte_experimental
 int
-rte_security_macsec_sc_destroy(struct rte_security_ctx *instance, uint16_t sc_id);
+rte_security_macsec_sc_destroy(struct rte_security_ctx *instance, uint16_t sc_id,
+			       enum rte_security_macsec_direction dir);
 
 /**
  * @warning
@@ -798,6 +800,7 @@ rte_security_macsec_sa_create(struct rte_security_ctx *instance,
  *
  * @param   instance	security instance
  * @param   sa_id	SA ID to be destroyed
+ * @param   dir		direction of the SA
  * @return
  *  - 0 if successful.
  *  - -EINVAL if sa_id is invalid or instance is NULL.
@@ -805,7 +808,8 @@ rte_security_macsec_sa_create(struct rte_security_ctx *instance,
  */
 __rte_experimental
 int
-rte_security_macsec_sa_destroy(struct rte_security_ctx *instance, uint16_t sa_id);
+rte_security_macsec_sa_destroy(struct rte_security_ctx *instance, uint16_t sa_id,
+			       enum rte_security_macsec_direction dir);
 
 /** Device-specific metadata field type */
 typedef uint64_t rte_security_dynfield_t;
@@ -1077,6 +1081,7 @@ rte_security_session_stats_get(struct rte_security_ctx *instance,
  *
  * @param	instance	security instance
  * @param	sa_id		SA ID for which stats are needed
+ * @param	dir		direction of the SA
  * @param	stats		statistics
  * @return
  *  - On success, return 0.
@@ -1085,7 +1090,7 @@ rte_security_session_stats_get(struct rte_security_ctx *instance,
 __rte_experimental
 int
 rte_security_macsec_sa_stats_get(struct rte_security_ctx *instance,
-				 uint16_t sa_id,
+				 uint16_t sa_id, enum rte_security_macsec_direction dir,
 				 struct rte_security_macsec_sa_stats *stats);
 
 /**
@@ -1096,6 +1101,7 @@ rte_security_macsec_sa_stats_get(struct rte_security_ctx *instance,
  *
  * @param	instance	security instance
  * @param	sc_id		SC ID for which stats are needed
+ * @param	dir		direction of the SC
  * @param	stats		SC statistics
  * @return
  *  - On success, return 0.
@@ -1104,7 +1110,7 @@ rte_security_macsec_sa_stats_get(struct rte_security_ctx *instance,
 __rte_experimental
 int
 rte_security_macsec_sc_stats_get(struct rte_security_ctx *instance,
-				 uint16_t sc_id,
+				 uint16_t sc_id, enum rte_security_macsec_direction dir,
 				 struct rte_security_macsec_sc_stats *stats);
 
 /**
lib/security/rte_security_driver.h +10 -2
index 421e6f7780..677c7d1f91 100644
@@ -106,8 +106,10 @@ typedef int (*security_macsec_sc_create_t)(void *device, struct rte_security_mac
  *
  * @param	device		Crypto/eth device pointer
  * @param	sc_id		MACsec SC ID
+ * @param	dir		Direction of SC
  */
-typedef int (*security_macsec_sc_destroy_t)(void *device, uint16_t sc_id);
+typedef int (*security_macsec_sc_destroy_t)(void *device, uint16_t sc_id,
+		enum rte_security_macsec_direction dir);
 
 /**
  * Configure a MACsec security Association (SA) on a device.
@@ -128,8 +130,10 @@ typedef int (*security_macsec_sa_create_t)(void *device, struct rte_security_mac
  *
  * @param	device		Crypto/eth device pointer
  * @param	sa_id		MACsec SA ID
+ * @param	dir		Direction of SA
  */
-typedef int (*security_macsec_sa_destroy_t)(void *device, uint16_t sa_id);
+typedef int (*security_macsec_sa_destroy_t)(void *device, uint16_t sa_id,
+		enum rte_security_macsec_direction dir);
 
 /**
  * Get the size of a security session
@@ -162,6 +166,7 @@ typedef int (*security_session_stats_get_t)(void *device,
  *
  * @param	device		Crypto/eth device pointer
  * @param	sc_id		secure channel ID created by rte_security_macsec_sc_create()
+ * @param	dir		direction of SC
  * @param	stats		SC stats of the driver
  *
  * @return
@@ -169,6 +174,7 @@ typedef int (*security_session_stats_get_t)(void *device,
  *  - -EINVAL if sc_id or device is invalid.
  */
 typedef int (*security_macsec_sc_stats_get_t)(void *device, uint16_t sc_id,
+		enum rte_security_macsec_direction dir,
 		struct rte_security_macsec_sc_stats *stats);
 
 /**
@@ -176,6 +182,7 @@ typedef int (*security_macsec_sc_stats_get_t)(void *device, uint16_t sc_id,
  *
  * @param	device		Crypto/eth device pointer
  * @param	sa_id		secure channel ID created by rte_security_macsec_sc_create()
+ * @param	dir		direction of SA
  * @param	stats		SC stats of the driver
  *
  * @return
@@ -183,6 +190,7 @@ typedef int (*security_macsec_sc_stats_get_t)(void *device, uint16_t sc_id,
  *  - -EINVAL if sa_id or device is invalid.
  */
 typedef int (*security_macsec_sa_stats_get_t)(void *device, uint16_t sa_id,
+		enum rte_security_macsec_direction dir,
 		struct rte_security_macsec_sa_stats *stats);
 
 
Signature · 1 line
2.25.1
#41 lore raw

RE: [PATCH v2 01/13] security: add direction in SA/SC configuration

Quoted 29 lines

Subject: [PATCH v2 01/13] security: add direction in SA/SC configuration

MACsec SC/SA ids are created based on direction of the flow. Hence, added the missing field for configuration and cleanup of the SCs and SAs.

---
 devtools/libabigail.abignore       |  7 +++++++
 lib/security/rte_security.c        | 16 ++++++++++------
 lib/security/rte_security.h        | 14 ++++++++++----
 lib/security/rte_security_driver.h | 12 ++++++++++--
 4 files changed, 37 insertions(+), 12 deletions(-)
devtools/libabigail.abignore +0 -0
index c0361bfc7b..14d8fa4293 100644
@@ -37,6 +37,13 @@
 [suppress_type]
         type_kind = enum
         changed_enumerators = RTE_CRYPTO_ASYM_XFORM_ECPM,

RTE_CRYPTO_ASYM_XFORM_TYPE_LIST_END

devtools/libabigail.abignore +6 -0
+; Ignore changes to rte_security_ops MACsec APIs which are experimental
+[suppress_type]
+        name = rte_security_ops
+        has_data_member_inserted_between =
+        {
+                offset_of(security_macsec_sc_create_t),
Quoted 2 lines

offset_of(security_macsec_sa_stats_get_t)
+ }

Thomas/David,

Please review the exception added for MACsec rte_security APIs.

Regards,
Akhil

#42 lore raw

Re: [PATCH v2 01/13] security: add direction in SA/SC configuration

In reply to Akhil Goyal
Quoted 5 lines · Akhil Goyal

MACsec SC/SA ids are created based on direction of the flow. Hence, added the missing field for configuration and cleanup of the SCs and SAs.

Quoted 8 lines
---
 devtools/libabigail.abignore       |  7 +++++++
 lib/security/rte_security.c        | 16 ++++++++++------
 lib/security/rte_security.h        | 14 ++++++++++----
 lib/security/rte_security_driver.h | 12 ++++++++++--
 4 files changed, 37 insertions(+), 12 deletions(-)

Looking at the report with no supression rule:

$ abidiff --suppr .../next-cryptodev/devtools/libabigail.abignore
--no-added-syms --headers-dir1
.../abi/v23.03/build-gcc-shared/usr/local/include --headers-dir2
.../next-cryptodev/build-gcc-shared/install/usr/local/include
.../abi/v23.03/build-gcc-shared/usr/local/lib64/librte_security.so.23.1
.../next-cryptodev/build-gcc-shared/install/usr/local/lib64/librte_security.so.23.2
Functions changes summary: 0 Removed, 1 Changed (13 filtered out), 0
Added functions
Variables changes summary: 0 Removed, 0 Changed, 0 Added variable

1 function with some indirect sub-type change:

[C] 'function const rte_security_capability*
rte_security_capabilities_get(rte_security_ctx*)' at rte_security.c:241:1 has some indirect sub-type changes:
parameter 1 of type 'rte_security_ctx*' has sub-type changes:
in pointed to type 'struct rte_security_ctx' at rte_security.h:69:1:
type size hasn't changed
1 data member change:
type of 'const rte_security_ops* ops' changed:
in pointed to type 'const rte_security_ops':
in unqualified underlying type 'struct rte_security_ops'
at rte_security_driver.h:230:1:
type size hasn't changed
4 data member changes (4 filtered):
type of 'security_macsec_sc_create_t
macsec_sc_create' changed:
underlying type 'int (void*,
rte_security_macsec_sc*)*' changed:
in pointed to type 'function type int (void*,
rte_security_macsec_sc*)':
parameter 2 of type 'rte_security_macsec_sc*'
has sub-type changes:
in pointed to type 'struct
rte_security_macsec_sc' at rte_security.h:399:1:
type size changed from 256 to 320 (in bits) 1 data member insertion:
'union {struct {uint16_t sa_id[4];
uint8_t sa_in_use[4]; uint8_t active; uint8_t is_xpn; uint8_t reserved;} sc_rx; struct {uint16_t sa_id; uint16_t sa_id_rekey; uint64_t sci; uint8_t active; uint8_t re_key_en; uint8_t is_xpn; uint8_t reserved;} sc_tx;}', at offset 128 (in bits)
1 data member change:
anonymous data member union {struct
{uint16_t sa_id[4]; uint8_t sa_in_use[4]; uint8_t active; uint8_t reserved;} sc_rx; struct {uint16_t sa_id; uint16_t sa_id_rekey; uint64_t sci; uint8_t active; uint8_t re_key_en; uint8_t reserved;} sc_tx;} at offset 64 (in bits) became data member 'uint64_t pn_threshold'
and size changed from 192 to 64 (in
bits) (by -128 bits)
type of 'security_macsec_sc_destroy_t
macsec_sc_destroy' changed:
underlying type 'int (void*, typedef uint16_t)*' changed:
in pointed to type 'function type int (void*,
typedef uint16_t)':
parameter 3 of type 'enum
rte_security_macsec_direction' was added
type of 'security_macsec_sc_stats_get_t
macsec_sc_stats_get' changed:
underlying type 'int (void*, typedef uint16_t,
rte_security_macsec_sc_stats*)*' changed:
in pointed to type 'function type int (void*,
typedef uint16_t, rte_security_macsec_sc_stats*)':
parameter 3 of type
'rte_security_macsec_sc_stats*' changed:
entity changed from
'rte_security_macsec_sc_stats*' to 'enum rte_security_macsec_direction' at rte_security.h:361:1
type size changed from 64 to 32 (in bits) type alignment changed from 0 to 32
parameter 4 of type
'rte_security_macsec_sc_stats*' was added
type of 'security_macsec_sa_stats_get_t
macsec_sa_stats_get' changed:
underlying type 'int (void*, typedef uint16_t,
rte_security_macsec_sa_stats*)*' changed:
in pointed to type 'function type int (void*,
typedef uint16_t, rte_security_macsec_sa_stats*)':
parameter 3 of type
'rte_security_macsec_sa_stats*' changed:
entity changed from
'rte_security_macsec_sa_stats*' to 'enum rte_security_macsec_direction' at rte_security.h:361:1
type size changed from 64 to 32 (in bits) type alignment changed from 0 to 32
parameter 4 of type
'rte_security_macsec_sa_stats*' was added

The report complains about the macsec ops type changes.

Quoted 5 lines
devtools/libabigail.abignore +0 -0
index c0361bfc7b..14d8fa4293 100644

devtools/libabigail.abignore line 46

Quoted 10 lines
devtools/libabigail.abignore +7 -0
@@ -37,6 +37,13 @@
 [suppress_type]
         type_kind = enum
         changed_enumerators = RTE_CRYPTO_ASYM_XFORM_ECPM, RTE_CRYPTO_ASYM_XFORM_TYPE_LIST_END
+; Ignore changes to rte_security_ops MACsec APIs which are experimental
+[suppress_type]
+        name = rte_security_ops
+        has_data_member_inserted_between =
+        {
+                offset_of(security_macsec_sc_create_t), offset_of(security_macsec_sa_stats_get_t)
+        }

So I don't get the intent with this rule.
There is no field named neither security_macsec_sc_create_t nor security_macsec_sa_stats_get_t in the rte_security_ops struct.

Now.. why is this rule making the check pass... it is a mystery to me. I already hit a case when libabigail ignored statements that are invalid or make no sense, so my guess is that this rule is actually applied as a simple:
[suppress_type]
name = rte_security_ops

And well, this rule is ok from my pov: this rte_security_ops struct does not change in size.
An application is not supposed to know about its content (that is defined in a driver header) and all accesses to those ops are supposed to be through symbols from the security library.
So I would go with this "larger" and simpler rule.

Just a small addition to this, as discussed offlist, this is going to be reworked in v23.11 and this rule on rte_security_ops will be unneccesary, so please move it in the relevant block (at the end) of the libabigail.abignore file.

Signature · 1 line
David Marchand
#43 lore raw

RE: [EXT] Re: [PATCH v2 01/13] security: add direction in SA/SC configuration

Quoted 137 lines · Akhil Goyal
Quoted 5 lines

MACsec SC/SA ids are created based on direction of the flow. Hence, added the missing field for configuration and cleanup of the SCs and SAs.

Quoted 8 lines
---
 devtools/libabigail.abignore       |  7 +++++++
 lib/security/rte_security.c        | 16 ++++++++++------
 lib/security/rte_security.h        | 14 ++++++++++----
 lib/security/rte_security_driver.h | 12 ++++++++++--
 4 files changed, 37 insertions(+), 12 deletions(-)

Looking at the report with no supression rule:

$ abidiff --suppr .../next-cryptodev/devtools/libabigail.abignore
--no-added-syms --headers-dir1
.../abi/v23.03/build-gcc-shared/usr/local/include --headers-dir2
.../next-cryptodev/build-gcc-shared/install/usr/local/include
.../abi/v23.03/build-gcc-shared/usr/local/lib64/librte_security.so.23.1
.../next-cryptodev/build-gcc-
shared/install/usr/local/lib64/librte_security.so.23.2
Functions changes summary: 0 Removed, 1 Changed (13 filtered out), 0
Added functions
Variables changes summary: 0 Removed, 0 Changed, 0 Added variable

1 function with some indirect sub-type change:

[C] 'function const rte_security_capability*
rte_security_capabilities_get(rte_security_ctx*)' at rte_security.c:241:1 has some indirect sub-type changes:
parameter 1 of type 'rte_security_ctx*' has sub-type changes:
in pointed to type 'struct rte_security_ctx' at rte_security.h:69:1:
type size hasn't changed
1 data member change:
type of 'const rte_security_ops* ops' changed:
in pointed to type 'const rte_security_ops':
in unqualified underlying type 'struct rte_security_ops'
at rte_security_driver.h:230:1:
type size hasn't changed
4 data member changes (4 filtered):
type of 'security_macsec_sc_create_t
macsec_sc_create' changed:
underlying type 'int (void*,
rte_security_macsec_sc*)*' changed:
in pointed to type 'function type int (void*,
rte_security_macsec_sc*)':
parameter 2 of type 'rte_security_macsec_sc*'
has sub-type changes:
in pointed to type 'struct
rte_security_macsec_sc' at rte_security.h:399:1:
type size changed from 256 to 320 (in bits) 1 data member insertion:
'union {struct {uint16_t sa_id[4];
uint8_t sa_in_use[4]; uint8_t active; uint8_t is_xpn; uint8_t reserved;} sc_rx; struct {uint16_t sa_id; uint16_t sa_id_rekey; uint64_t sci; uint8_t active; uint8_t re_key_en; uint8_t is_xpn; uint8_t reserved;} sc_tx;}', at offset 128 (in bits)
1 data member change:
anonymous data member union {struct
{uint16_t sa_id[4]; uint8_t sa_in_use[4]; uint8_t active; uint8_t reserved;} sc_rx; struct {uint16_t sa_id; uint16_t sa_id_rekey; uint64_t sci; uint8_t active; uint8_t re_key_en; uint8_t reserved;} sc_tx;} at offset 64 (in bits) became data member 'uint64_t pn_threshold'
and size changed from 192 to 64 (in
bits) (by -128 bits)
type of 'security_macsec_sc_destroy_t
macsec_sc_destroy' changed:
underlying type 'int (void*, typedef uint16_t)*' changed:
in pointed to type 'function type int (void*,
typedef uint16_t)':
parameter 3 of type 'enum
rte_security_macsec_direction' was added
type of 'security_macsec_sc_stats_get_t
macsec_sc_stats_get' changed:
underlying type 'int (void*, typedef uint16_t,
rte_security_macsec_sc_stats*)*' changed:
in pointed to type 'function type int (void*,
typedef uint16_t, rte_security_macsec_sc_stats*)':
parameter 3 of type
'rte_security_macsec_sc_stats*' changed:
entity changed from
'rte_security_macsec_sc_stats*' to 'enum rte_security_macsec_direction' at rte_security.h:361:1
type size changed from 64 to 32 (in bits) type alignment changed from 0 to 32
parameter 4 of type
'rte_security_macsec_sc_stats*' was added
type of 'security_macsec_sa_stats_get_t
macsec_sa_stats_get' changed:
underlying type 'int (void*, typedef uint16_t,
rte_security_macsec_sa_stats*)*' changed:
in pointed to type 'function type int (void*,
typedef uint16_t, rte_security_macsec_sa_stats*)':
parameter 3 of type
'rte_security_macsec_sa_stats*' changed:
entity changed from
'rte_security_macsec_sa_stats*' to 'enum rte_security_macsec_direction' at rte_security.h:361:1
type size changed from 64 to 32 (in bits) type alignment changed from 0 to 32
parameter 4 of type
'rte_security_macsec_sa_stats*' was added

The report complains about the macsec ops type changes.

devtools/libabigail.abignore line 39

Quoted 8 lines
devtools/libabigail.abignore +0 -0
index c0361bfc7b..14d8fa4293 100644
@@ -37,6 +37,13 @@
 [suppress_type]
         type_kind = enum
         changed_enumerators = RTE_CRYPTO_ASYM_XFORM_ECPM,

RTE_CRYPTO_ASYM_XFORM_TYPE_LIST_END

devtools/libabigail.abignore

Quoted 6 lines
devtools/libabigail.abignore +6 -0
+; Ignore changes to rte_security_ops MACsec APIs which are experimental
+[suppress_type]
+        name = rte_security_ops
+        has_data_member_inserted_between =
+        {
+                offset_of(security_macsec_sc_create_t),

offset_of(security_macsec_sa_stats_get_t)

devtools/libabigail.abignore line 46

Quoted 1 line
devtools/libabigail.abignore +1 -0
+        }

So I don't get the intent with this rule.
There is no field named neither security_macsec_sc_create_t nor security_macsec_sa_stats_get_t in the rte_security_ops struct.

Now.. why is this rule making the check pass... it is a mystery to me. I already hit a case when libabigail ignored statements that are invalid or make no sense, so my guess is that this rule is actually applied as a simple:
[suppress_type]
name = rte_security_ops

Quoted 6 lines

And well, this rule is ok from my pov: this rte_security_ops struct does not change in size.
An application is not supposed to know about its content (that is defined in a driver header) and all accesses to those ops are supposed to be through symbols from the security library.
So I would go with this "larger" and simpler rule.

The intent was to make it specific to MACsec APIs only.
I am ok with both as these are internal thing and would change it in next release. Updated the v3 as per your suggestion.

Quoted 6 lines

Just a small addition to this, as discussed offlist, this is going to be reworked in v23.11 and this rule on rte_security_ops will be unneccesary, so please move it in the relevant block (at the end) of the libabigail.abignore file.

Ack

#44 lore raw

PATCH v2 2/13 security: add MACsec packet number threshold

In reply to Akhil Goyal

Added Packet number threshold parameter in MACsec SC configuration to identify the maximum allowed threshold for packet number field in the packet.
A field is_xpn is also added to identify if the SAs are configured for extended packet number or not so that packet number threshold can be configured accordingly.

---
 lib/security/rte_security.h | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)
lib/security/rte_security.h +8 -2
index c7a523b6d6..30bac4e25a 100644
@@ -399,6 +399,8 @@ struct rte_security_macsec_sa {
 struct rte_security_macsec_sc {
 	/** Direction of SC */
 	enum rte_security_macsec_direction dir;
+	/** Packet number threshold */
+	uint64_t pn_threshold;
 	union {
 		struct {
 			/** SAs for each association number */
@@ -407,8 +409,10 @@ struct rte_security_macsec_sc {
 			uint8_t sa_in_use[RTE_SECURITY_MACSEC_NUM_AN];
 			/** Channel is active */
 			uint8_t active : 1;
+			/** Extended packet number is enabled for SAs */
+			uint8_t is_xpn : 1;
 			/** Reserved bitfields for future */
-			uint8_t reserved : 7;
+			uint8_t reserved : 6;
 		} sc_rx;
 		struct {
 			uint16_t sa_id; /**< SA ID to be used for encryption */
@@ -416,8 +420,10 @@ struct rte_security_macsec_sc {
 			uint64_t sci; /**< SCI value to be used if send_sci is set */
 			uint8_t active : 1; /**< Channel is active */
 			uint8_t re_key_en : 1; /**< Enable Rekeying */
+			/** Extended packet number is enabled for SAs */
+			uint8_t is_xpn : 1;
 			/** Reserved bitfields for future */
-			uint8_t reserved : 6;
+			uint8_t reserved : 5;
 		} sc_tx;
 	};
 };
Signature · 1 line
2.25.1
#45 lore raw

PATCH v2 3/13 test/security: add inline MACsec cases

In reply to Akhil Goyal

Updated test app to verify Inline MACsec offload using rte_security APIs.
A couple of test cases are added to verify encap only and decap only of some known test vectors from MACsec specification.

---
 app/test/meson.build                          |    1 +
 app/test/test_security_inline_macsec.c        | 1108 +++++++++++++++++
 .../test_security_inline_macsec_vectors.h     | 1086 ++++++++++++++++
 3 files changed, 2195 insertions(+)
 create mode 100644 app/test/test_security_inline_macsec.c
 create mode 100644 app/test/test_security_inline_macsec_vectors.h
app/test/meson.build +1 -0
index b9b5432496..69c1d19f7b 100644
@@ -128,6 +128,7 @@ test_sources = files(
         'test_rwlock.c',
         'test_sched.c',
         'test_security.c',
+        'test_security_inline_macsec.c',
         'test_security_inline_proto.c',
         'test_seqlock.c',
         'test_service_cores.c',
app/test/test_security_inline_macsec.c new file +1108 -0

1,108 lines not on this page · raw message

app/test/test_security_inline_macsec_vectors.h new file +1086 -0

1,086 lines not on this page · raw message

Signature · 1 line
2.25.1
#46 lore raw

PATCH v2 4/13 test/security: add MACsec integrity cases

In reply to Akhil Goyal

Added test vectors and test cases to verify auth_only/verify_only and encap-decap/auth-verify to verify the complete TX-RX path using the loopback mode of ethdev.

---
 app/test/test_security_inline_macsec.c        | 153 +++
 .../test_security_inline_macsec_vectors.h     | 995 ++++++++++++++++++
 2 files changed, 1148 insertions(+)
app/test/test_security_inline_macsec.c +153 -0
index 9ef967597b..7445b667e4 100644
@@ -937,6 +937,143 @@ test_inline_macsec_decap_all(const void *data __rte_unused)
 	return all_err;
 }
 
+static int
+test_inline_macsec_auth_only_all(const void *data __rte_unused)
+{
+	const struct mcs_test_vector *cur_td;
+	struct mcs_test_opts opts = {0};
+	int err, all_err = 0;
+	int i, size;
+
+	opts.val_frames = RTE_SECURITY_MACSEC_VALIDATE_STRICT;
+	opts.protect_frames = true;
+	opts.sa_in_use = 1;
+	opts.nb_td = 1;
+	opts.sectag_insert_mode = 1;
+	opts.mtu = RTE_ETHER_MTU;
+
+	size = (sizeof(list_mcs_integrity_vectors) / sizeof((list_mcs_integrity_vectors)[0]));
+
+	for (i = 0; i < size; i++) {
+		cur_td = &list_mcs_integrity_vectors[i];
+		err = test_macsec(&cur_td, MCS_AUTH_ONLY, &opts);
+		if (err) {
+			printf("\nAuth Generate case %d failed", cur_td->test_idx);
+			err = -1;
+		} else {
+			printf("\nAuth Generate case %d Passed", cur_td->test_idx);
+			err = 0;
+		}
+		all_err += err;
+	}
+	printf("\n%s: Success: %d, Failure: %d\n", __func__, size + all_err, -all_err);
+
+	return all_err;
+}
+
+static int
+test_inline_macsec_verify_only_all(const void *data __rte_unused)
+{
+	const struct mcs_test_vector *cur_td;
+	struct mcs_test_opts opts = {0};
+	int err, all_err = 0;
+	int i, size;
+
+	opts.val_frames = RTE_SECURITY_MACSEC_VALIDATE_STRICT;
+	opts.sa_in_use = 1;
+	opts.nb_td = 1;
+	opts.sectag_insert_mode = 1;
+	opts.mtu = RTE_ETHER_MTU;
+
+	size = (sizeof(list_mcs_integrity_vectors) / sizeof((list_mcs_integrity_vectors)[0]));
+
+	for (i = 0; i < size; i++) {
+		cur_td = &list_mcs_integrity_vectors[i];
+		err = test_macsec(&cur_td, MCS_VERIFY_ONLY, &opts);
+		if (err) {
+			printf("\nAuth Verify case %d failed", cur_td->test_idx);
+			err = -1;
+		} else {
+			printf("\nAuth Verify case %d Passed", cur_td->test_idx);
+			err = 0;
+		}
+		all_err += err;
+	}
+	printf("\n%s: Success: %d, Failure: %d\n", __func__, size + all_err, -all_err);
+
+	return all_err;
+}
+
+static int
+test_inline_macsec_encap_decap_all(const void *data __rte_unused)
+{
+	const struct mcs_test_vector *cur_td;
+	struct mcs_test_opts opts = {0};
+	int err, all_err = 0;
+	int i, size;
+
+	opts.val_frames = RTE_SECURITY_MACSEC_VALIDATE_STRICT;
+	opts.encrypt = true;
+	opts.protect_frames = true;
+	opts.sa_in_use = 1;
+	opts.nb_td = 1;
+	opts.sectag_insert_mode = 1;
+	opts.mtu = RTE_ETHER_MTU;
+
+	size = (sizeof(list_mcs_cipher_vectors) / sizeof((list_mcs_cipher_vectors)[0]));
+
+	for (i = 0; i < size; i++) {
+		cur_td = &list_mcs_cipher_vectors[i];
+		err = test_macsec(&cur_td, MCS_ENCAP_DECAP, &opts);
+		if (err) {
+			printf("\nCipher Auth Encap-decap case %d failed", cur_td->test_idx);
+			err = -1;
+		} else {
+			printf("\nCipher Auth Encap-decap case %d Passed", cur_td->test_idx);
+			err = 0;
+		}
+		all_err += err;
+	}
+	printf("\n%s: Success: %d, Failure: %d\n", __func__, size + all_err, -all_err);
+
+	return all_err;
+}
+
+
+static int
+test_inline_macsec_auth_verify_all(const void *data __rte_unused)
+{
+	const struct mcs_test_vector *cur_td;
+	struct mcs_test_opts opts = {0};
+	int err, all_err = 0;
+	int i, size;
+
+	opts.val_frames = RTE_SECURITY_MACSEC_VALIDATE_STRICT;
+	opts.protect_frames = true;
+	opts.sa_in_use = 1;
+	opts.nb_td = 1;
+	opts.sectag_insert_mode = 1;
+	opts.mtu = RTE_ETHER_MTU;
+
+	size = (sizeof(list_mcs_integrity_vectors) / sizeof((list_mcs_integrity_vectors)[0]));
+
+	for (i = 0; i < size; i++) {
+		cur_td = &list_mcs_integrity_vectors[i];
+		err = test_macsec(&cur_td, MCS_AUTH_VERIFY, &opts);
+		if (err) {
+			printf("\nAuth Generate + Verify case %d failed", cur_td->test_idx);
+			err = -1;
+		} else {
+			printf("\nAuth Generate + Verify case %d Passed", cur_td->test_idx);
+			err = 0;
+		}
+		all_err += err;
+	}
+	printf("\n%s: Success: %d, Failure: %d\n", __func__, size + all_err, -all_err);
+
+	return all_err;
+}
+
 static int
 ut_setup_inline_macsec(void)
 {
@@ -1090,6 +1227,22 @@ static struct unit_test_suite inline_macsec_testsuite  = {
 			"MACsec decap(De-cipher+verify) known vector",
 			ut_setup_inline_macsec, ut_teardown_inline_macsec,
 			test_inline_macsec_decap_all),
+		TEST_CASE_NAMED_ST(
+			"MACsec auth only known vector",
+			ut_setup_inline_macsec, ut_teardown_inline_macsec,
+			test_inline_macsec_auth_only_all),
+		TEST_CASE_NAMED_ST(
+			"MACsec verify only known vector",
+			ut_setup_inline_macsec, ut_teardown_inline_macsec,
+			test_inline_macsec_verify_only_all),
+		TEST_CASE_NAMED_ST(
+			"MACsec encap + decap known vector",
+			ut_setup_inline_macsec, ut_teardown_inline_macsec,
+			test_inline_macsec_encap_decap_all),
+		TEST_CASE_NAMED_ST(
+			"MACsec auth + verify known vector",
+			ut_setup_inline_macsec, ut_teardown_inline_macsec,
+			test_inline_macsec_auth_verify_all),
 
 		TEST_CASES_END() /**< NULL terminate unit test array */
 	},
app/test/test_security_inline_macsec_vectors.h +995 -0

999 lines not on this page · raw message

Signature · 1 line
2.25.1
#47 lore raw

PATCH v2 5/13 test/security: verify multi flow MACsec

In reply to Akhil Goyal

Added test case and test vectors to verify multiple flows of MACsec.

---
 app/test/test_security_inline_macsec.c        |  49 ++++++++
 .../test_security_inline_macsec_vectors.h     | 110 +++++++++++++++++-
 2 files changed, 158 insertions(+), 1 deletion(-)
app/test/test_security_inline_macsec.c +49 -0
index 7445b667e4..621074a928 100644
@@ -1074,6 +1074,51 @@ test_inline_macsec_auth_verify_all(const void *data __rte_unused)
 	return all_err;
 }
 
+static int
+test_inline_macsec_multi_flow(const void *data __rte_unused)
+{
+	const struct mcs_test_vector *tv[MCS_MAX_FLOWS];
+	struct mcs_test_vector iter[MCS_MAX_FLOWS];
+	struct mcs_test_opts opts = {0};
+	int i, err;
+
+	opts.val_frames = RTE_SECURITY_MACSEC_VALIDATE_STRICT;
+	opts.encrypt = true;
+	opts.protect_frames = true;
+	opts.sa_in_use = 1;
+	opts.nb_td = MCS_MAX_FLOWS;
+	opts.sectag_insert_mode = 1;
+	opts.mtu = RTE_ETHER_MTU;
+
+	for (i = 0; i < MCS_MAX_FLOWS; i++) {
+		memcpy(&iter[i].sa_key.data, sa_key, MCS_MULTI_FLOW_TD_KEY_SZ);
+		memcpy(&iter[i].plain_pkt.data, eth_addrs[i], 2 * RTE_ETHER_ADDR_LEN);
+		memcpy(&iter[i].plain_pkt.data[2 * RTE_ETHER_ADDR_LEN], plain_user_data,
+		       MCS_MULTI_FLOW_TD_PLAIN_DATA_SZ);
+		memcpy(&iter[i].secure_pkt.data, eth_addrs[i], 2 * RTE_ETHER_ADDR_LEN);
+		memcpy(&iter[i].secure_pkt.data[2 * RTE_ETHER_ADDR_LEN], secure_user_data,
+		       MCS_MULTI_FLOW_TD_SECURE_DATA_SZ);
+		iter[i].sa_key.len = MCS_MULTI_FLOW_TD_KEY_SZ;
+		iter[i].plain_pkt.len = MCS_MULTI_FLOW_TD_PLAIN_DATA_SZ +
+					(2 * RTE_ETHER_ADDR_LEN);
+		iter[i].secure_pkt.len = MCS_MULTI_FLOW_TD_SECURE_DATA_SZ +
+					(2 * RTE_ETHER_ADDR_LEN);
+		iter[i].alg = RTE_SECURITY_MACSEC_ALG_GCM_128;
+		iter[i].ssci = 0x0;
+		iter[i].xpn = 0x0;
+		tv[i] = (const struct mcs_test_vector *)&iter[i];
+	}
+	err = test_macsec(tv, MCS_ENCAP_DECAP, &opts);
+	if (err) {
+		printf("\nCipher Auth Encryption multi flow failed");
+		err = -1;
+	} else {
+		printf("\nCipher Auth Encryption multi flow Passed");
+		err = 0;
+	}
+	return err;
+}
+
 static int
 ut_setup_inline_macsec(void)
 {
@@ -1219,6 +1264,10 @@ inline_macsec_testsuite_teardown(void)
 static struct unit_test_suite inline_macsec_testsuite  = {
 	.suite_name = "Inline MACsec Ethernet Device Unit Test Suite",
 	.unit_test_cases = {
+		TEST_CASE_NAMED_ST(
+			"MACsec Encap + decap Multi flow",
+			ut_setup_inline_macsec, ut_teardown_inline_macsec,
+			test_inline_macsec_multi_flow),
 		TEST_CASE_NAMED_ST(
 			"MACsec encap(Cipher+Auth) known vector",
 			ut_setup_inline_macsec, ut_teardown_inline_macsec,
app/test/test_security_inline_macsec_vectors.h +109 -1

120 lines not on this page · raw message

Signature · 1 line
2.25.1
#48 lore raw

PATCH v2 6/13 test/security: add MACsec VLAN cases

In reply to Akhil Goyal

Added cases to verify MACsec processing with VLAN
tags inserted. Vectors are added to verify 1/2/3
VLAN tags in clear or encrypted data.

---
 app/test/test_security_inline_macsec.c        |  67 ++++++
 .../test_security_inline_macsec_vectors.h     | 217 ++++++++++++++++++
 2 files changed, 284 insertions(+)
app/test/test_security_inline_macsec.c +67 -0
index 621074a928..854ead75a0 100644
@@ -1119,6 +1119,69 @@ test_inline_macsec_multi_flow(const void *data __rte_unused)
 	return err;
 }
 
+static int
+test_inline_macsec_with_vlan(const void *data __rte_unused)
+{
+	const struct mcs_test_vector *cur_td;
+	struct mcs_test_opts opts = {0};
+	int err, all_err = 0;
+	int i, size;
+
+	opts.val_frames = RTE_SECURITY_MACSEC_VALIDATE_STRICT;
+	opts.protect_frames = true;
+	opts.sa_in_use = 1;
+	opts.nb_td = 1;
+	opts.mtu = RTE_ETHER_MTU;
+
+	size = (sizeof(list_mcs_vlan_vectors) / sizeof((list_mcs_vlan_vectors)[0]));
+
+	for (i = 0; i < size; i++) {
+		cur_td = &list_mcs_vlan_vectors[i];
+		if (i == 0) {
+			opts.sectag_insert_mode = 1;
+		} else if (i == 1) {
+			opts.sectag_insert_mode = 0; /* offset from special E-type */
+			opts.nb_vlan = 1;
+		} else if (i == 2) {
+			opts.sectag_insert_mode = 0; /* offset from special E-type */
+			opts.nb_vlan = 2;
+		}
+		err = test_macsec(&cur_td, MCS_ENCAP, &opts);
+		if (err) {
+			printf("\n VLAN Encap case %d failed", cur_td->test_idx);
+			err = -1;
+		} else {
+			printf("\n VLAN Encap case %d passed", cur_td->test_idx);
+			err = 0;
+		}
+		all_err += err;
+	}
+	for (i = 0; i < size; i++) {
+		cur_td = &list_mcs_vlan_vectors[i];
+		if (i == 0) {
+			opts.sectag_insert_mode = 1;
+		} else if (i == 1) {
+			opts.sectag_insert_mode = 0; /* offset from special E-type */
+			opts.nb_vlan = 1;
+		} else if (i == 2) {
+			opts.sectag_insert_mode = 0; /* offset from special E-type */
+			opts.nb_vlan = 2;
+		}
+		err = test_macsec(&cur_td, MCS_DECAP, &opts);
+		if (err) {
+			printf("\n VLAN Decap case %d failed", cur_td->test_idx);
+			err = -1;
+		} else {
+			printf("\n VLAN Decap case %d passed", cur_td->test_idx);
+			err = 0;
+		}
+		all_err += err;
+	}
+
+	printf("\n%s: Success: %d, Failure: %d\n", __func__, (2 * size) + all_err, -all_err);
+	return all_err;
+}
+
 static int
 ut_setup_inline_macsec(void)
 {
@@ -1292,6 +1355,10 @@ static struct unit_test_suite inline_macsec_testsuite  = {
 			"MACsec auth + verify known vector",
 			ut_setup_inline_macsec, ut_teardown_inline_macsec,
 			test_inline_macsec_auth_verify_all),
+		TEST_CASE_NAMED_ST(
+			"MACsec Encap and decap with VLAN",
+			ut_setup_inline_macsec, ut_teardown_inline_macsec,
+			test_inline_macsec_with_vlan),
 
 		TEST_CASES_END() /**< NULL terminate unit test array */
 	},
app/test/test_security_inline_macsec_vectors.h +217 -0

222 lines not on this page · raw message

Signature · 1 line
2.25.1
#49 lore raw

PATCH v2 7/13 test/security: add MACsec negative cases

In reply to Akhil Goyal

Added MACsec negative test cases to verify
pkt drop, untagged rx, bad tag rx, sa not in use,
out packets untagged, pkts too long.

---
 app/test/test_security_inline_macsec.c        | 346 +++++++++++++
 .../test_security_inline_macsec_vectors.h     | 475 ++++++++++++++++++
 2 files changed, 821 insertions(+)
app/test/test_security_inline_macsec.c +346 -0
index 854ead75a0..2a06f31f37 100644
@@ -660,6 +660,103 @@ mcs_stats_dump(struct rte_security_ctx *ctx, enum mcs_op op,
 	}
 }
 
+static int
+mcs_stats_check(struct rte_security_ctx *ctx, enum mcs_op op,
+		const struct mcs_test_opts *opts,
+		const struct mcs_test_vector *td,
+		void *rx_sess, void *tx_sess,
+		uint8_t rx_sc_id, uint8_t tx_sc_id,
+		uint16_t rx_sa_id[], uint16_t tx_sa_id[])
+{
+	struct rte_security_stats sess_stats = {0};
+	struct rte_security_macsec_secy_stats *secy_stat;
+	struct rte_security_macsec_sc_stats sc_stat = {0};
+	struct rte_security_macsec_sa_stats sa_stat = {0};
+	int i;
+
+	if (op == MCS_DECAP || op == MCS_ENCAP_DECAP ||
+			op == MCS_VERIFY_ONLY || op == MCS_AUTH_VERIFY) {
+		rte_security_session_stats_get(ctx, rx_sess, &sess_stats);
+		secy_stat = &sess_stats.macsec;
+
+		if ((opts->check_untagged_rx && secy_stat->pkt_notag_cnt != 1) ||
+				(opts->check_untagged_rx && secy_stat->pkt_untaged_cnt != 1))
+			return TEST_FAILED;
+
+		if (opts->check_bad_tag_cnt && secy_stat->pkt_badtag_cnt != 1)
+			return TEST_FAILED;
+
+		if (opts->check_sa_not_in_use && secy_stat->pkt_nosaerror_cnt != 1)
+			return TEST_FAILED;
+
+		if (opts->check_decap_stats && secy_stat->octet_decrypted_cnt !=
+				(uint16_t)(td->plain_pkt.len - 2 * RTE_ETHER_ADDR_LEN))
+			return TEST_FAILED;
+
+		if (opts->check_verify_only_stats && secy_stat->octet_validated_cnt !=
+				(uint16_t)(td->plain_pkt.len - 2 * RTE_ETHER_ADDR_LEN))
+			return TEST_FAILED;
+
+		rte_security_macsec_sc_stats_get(ctx, rx_sc_id,
+				RTE_SECURITY_MACSEC_DIR_RX, &sc_stat);
+
+		if ((opts->check_decap_stats || opts->check_verify_only_stats) &&
+				sc_stat.pkt_ok_cnt != 1)
+			return TEST_FAILED;
+
+		if (opts->check_pkts_invalid_stats && sc_stat.pkt_notvalid_cnt != 1)
+			return TEST_FAILED;
+
+		if (opts->check_pkts_unchecked_stats && sc_stat.pkt_unchecked_cnt != 1)
+			return TEST_FAILED;
+
+		for (i = 0; i < RTE_SECURITY_MACSEC_NUM_AN; i++) {
+			memset(&sa_stat, 0, sizeof(struct rte_security_macsec_sa_stats));
+			rte_security_macsec_sa_stats_get(ctx, rx_sa_id[i],
+					RTE_SECURITY_MACSEC_DIR_RX, &sa_stat);
+
+		}
+	}
+
+	if (op == MCS_ENCAP || op == MCS_ENCAP_DECAP ||
+			op == MCS_AUTH_ONLY || op == MCS_AUTH_VERIFY) {
+		memset(&sess_stats, 0, sizeof(struct rte_security_stats));
+		rte_security_session_stats_get(ctx, tx_sess, &sess_stats);
+		secy_stat = &sess_stats.macsec;
+
+		if (opts->check_out_pkts_untagged && secy_stat->pkt_untagged_cnt != 1)
+			return TEST_FAILED;
+
+		if (opts->check_out_pkts_toolong && secy_stat->pkt_toolong_cnt != 1)
+			return TEST_FAILED;
+
+		if (opts->check_encap_stats && secy_stat->octet_encrypted_cnt !=
+				(uint16_t)(td->plain_pkt.len - 2 * RTE_ETHER_ADDR_LEN))
+			return TEST_FAILED;
+
+		if (opts->check_auth_only_stats && secy_stat->octet_protected_cnt !=
+				(uint16_t)(td->plain_pkt.len - 2 * RTE_ETHER_ADDR_LEN))
+			return TEST_FAILED;
+
+
+		memset(&sc_stat, 0, sizeof(struct rte_security_macsec_sc_stats));
+		rte_security_macsec_sc_stats_get(ctx, tx_sc_id, RTE_SECURITY_MACSEC_DIR_TX,
+						 &sc_stat);
+
+		if (opts->check_encap_stats && sc_stat.pkt_encrypt_cnt != 1)
+			return TEST_FAILED;
+
+		if (opts->check_auth_only_stats && sc_stat.pkt_protected_cnt != 1)
+			return TEST_FAILED;
+
+		memset(&sa_stat, 0, sizeof(struct rte_security_macsec_sa_stats));
+		rte_security_macsec_sa_stats_get(ctx, tx_sa_id[0],
+				RTE_SECURITY_MACSEC_DIR_TX, &sa_stat);
+	}
+
+	return 0;
+}
+
 static int
 test_macsec(const struct mcs_test_vector *td[], enum mcs_op op, const struct mcs_test_opts *opts)
 {
@@ -833,12 +930,23 @@ test_macsec(const struct mcs_test_vector *td[], enum mcs_op op, const struct mcs
 		rx_pkts_burst[i] = NULL;
 	}
 out:
+	if (opts->check_out_pkts_toolong == 1 ||
+			opts->check_sa_not_in_use == 1 ||
+			opts->check_bad_tag_cnt == 1)
+		ret = TEST_SUCCESS;
+
 	for (i = 0; i < opts->nb_td; i++) {
 		if (opts->dump_all_stats) {
 			mcs_stats_dump(ctx, op,
 					rx_sess[i], tx_sess[i],
 					rx_sc_id[i], tx_sc_id[i],
 					rx_sa_id[i], tx_sa_id[i]);
+		} else {
+			if (ret == TEST_SUCCESS)
+				ret = mcs_stats_check(ctx, op, opts, td[i],
+					rx_sess[i], tx_sess[i],
+					rx_sc_id[i], tx_sc_id[i],
+					rx_sa_id[i], tx_sa_id[i]);
 		}
 	}
 
@@ -1182,6 +1290,220 @@ test_inline_macsec_with_vlan(const void *data __rte_unused)
 	return all_err;
 }
 
+static int
+test_inline_macsec_pkt_drop(const void *data __rte_unused)
+{
+	const struct mcs_test_vector *cur_td;
+	struct mcs_test_opts opts = {0};
+	int err, all_err = 0;
+	int i, size;
+
+	opts.val_frames = RTE_SECURITY_MACSEC_VALIDATE_STRICT;
+	opts.encrypt = true;
+	opts.protect_frames = true;
+	opts.sa_in_use = 1;
+	opts.nb_td = 1;
+	opts.sectag_insert_mode = 1;
+	opts.mtu = RTE_ETHER_MTU;
+
+	size = (sizeof(list_mcs_err_cipher_vectors) / sizeof((list_mcs_err_cipher_vectors)[0]));
+
+	for (i = 0; i < size; i++) {
+		cur_td = &list_mcs_err_cipher_vectors[i];
+		err = test_macsec(&cur_td, MCS_DECAP, &opts);
+		if (err) {
+			printf("\nPacket drop case %d passed", cur_td->test_idx);
+			err = 0;
+		} else {
+			printf("\nPacket drop case %d failed", cur_td->test_idx);
+			err = -1;
+		}
+		all_err += err;
+	}
+	printf("\n%s: Success: %d, Failure: %d\n", __func__, size + all_err, -all_err);
+
+	return all_err;
+}
+
+static int
+test_inline_macsec_untagged_rx(const void *data __rte_unused)
+{
+	const struct mcs_test_vector *cur_td;
+	struct mcs_test_opts opts = {0};
+	int err, all_err = 0;
+	int i, size;
+
+	opts.val_frames = RTE_SECURITY_MACSEC_VALIDATE_STRICT;
+	opts.sa_in_use = 1;
+	opts.nb_td = 1;
+	opts.sectag_insert_mode = 1;
+	opts.mtu = RTE_ETHER_MTU;
+	opts.check_untagged_rx = 1;
+
+	size = (sizeof(list_mcs_untagged_cipher_vectors) /
+		sizeof((list_mcs_untagged_cipher_vectors)[0]));
+
+	for (i = 0; i < size; i++) {
+		cur_td = &list_mcs_untagged_cipher_vectors[i];
+		err = test_macsec(&cur_td, MCS_DECAP, &opts);
+		if (err)
+			err = 0;
+		else
+			err = -1;
+
+		all_err += err;
+	}
+
+	opts.val_frames = RTE_SECURITY_MACSEC_VALIDATE_NO_DISCARD;
+	for (i = 0; i < size; i++) {
+		cur_td = &list_mcs_untagged_cipher_vectors[i];
+		err = test_macsec(&cur_td, MCS_DECAP, &opts);
+		if (err)
+			err = 0;
+		else
+			err = -1;
+
+		all_err += err;
+	}
+	printf("\n%s: Success: %d, Failure: %d\n", __func__, size + all_err, -all_err);
+
+	return all_err;
+}
+
+static int
+test_inline_macsec_bad_tag_rx(const void *data __rte_unused)
+{
+	const struct mcs_test_vector *cur_td;
+	struct mcs_test_opts opts = {0};
+	int err, all_err = 0;
+	int i, size;
+
+	opts.val_frames = RTE_SECURITY_MACSEC_VALIDATE_STRICT;
+	opts.protect_frames = true;
+	opts.sa_in_use = 1;
+	opts.nb_td = 1;
+	opts.sectag_insert_mode = 1;
+	opts.mtu = RTE_ETHER_MTU;
+	opts.check_bad_tag_cnt = 1;
+
+	size = (sizeof(list_mcs_bad_tag_vectors) / sizeof((list_mcs_bad_tag_vectors)[0]));
+
+	for (i = 0; i < size; i++) {
+		cur_td = &list_mcs_bad_tag_vectors[i];
+		err = test_macsec(&cur_td, MCS_DECAP, &opts);
+		if (err)
+			err = -1;
+		else
+			err = 0;
+
+		all_err += err;
+	}
+
+	printf("\n%s: Success: %d, Failure: %d\n", __func__, size + all_err, -all_err);
+
+	return all_err;
+}
+
+static int
+test_inline_macsec_sa_not_in_use(const void *data __rte_unused)
+{
+	const struct mcs_test_vector *cur_td;
+	struct mcs_test_opts opts = {0};
+	int err, all_err = 0;
+	int i, size;
+
+	opts.val_frames = RTE_SECURITY_MACSEC_VALIDATE_STRICT;
+	opts.protect_frames = true;
+	opts.sa_in_use = 0;
+	opts.nb_td = 1;
+	opts.sectag_insert_mode = 1;
+	opts.mtu = RTE_ETHER_MTU;
+	opts.check_sa_not_in_use = 1;
+
+	size = (sizeof(list_mcs_cipher_vectors) / sizeof((list_mcs_cipher_vectors)[0]));
+
+	for (i = 0; i < size; i++) {
+		cur_td = &list_mcs_cipher_vectors[i];
+		err = test_macsec(&cur_td, MCS_DECAP, &opts);
+		if (err)
+			err = -1;
+		else
+			err = 0;
+
+		all_err += err;
+	}
+
+	printf("\n%s: Success: %d, Failure: %d\n", __func__, size + all_err, -all_err);
+
+	return all_err;
+}
+
+static int
+test_inline_macsec_out_pkts_untagged(const void *data __rte_unused)
+{
+	const struct mcs_test_vector *cur_td;
+	struct mcs_test_opts opts = {0};
+	int err, all_err = 0;
+	int i, size;
+
+	opts.val_frames = RTE_SECURITY_MACSEC_VALIDATE_STRICT;
+	opts.encrypt = false;
+	opts.protect_frames = false;
+	opts.sa_in_use = 1;
+	opts.nb_td = 1;
+	opts.sectag_insert_mode = 1;
+	opts.mtu = RTE_ETHER_MTU;
+	opts.check_out_pkts_untagged = 1;
+
+	size = (sizeof(list_mcs_cipher_vectors) / sizeof((list_mcs_cipher_vectors)[0]));
+	for (i = 0; i < size; i++) {
+		cur_td = &list_mcs_cipher_vectors[i];
+		err = test_macsec(&cur_td, MCS_ENCAP, &opts);
+		if (err)
+			err = -1;
+		else
+			err = 0;
+
+		all_err += err;
+	}
+
+	printf("\n%s: Success: %d, Failure: %d\n", __func__, size + all_err, -all_err);
+	return all_err;
+}
+
+static int
+test_inline_macsec_out_pkts_toolong(const void *data __rte_unused)
+{
+	const struct mcs_test_vector *cur_td;
+	struct mcs_test_opts opts = {0};
+	int err, all_err = 0;
+	int i, size;
+
+	opts.val_frames = RTE_SECURITY_MACSEC_VALIDATE_NO_DISCARD;
+	opts.encrypt = true;
+	opts.protect_frames = true;
+	opts.sa_in_use = 1;
+	opts.nb_td = 1;
+	opts.sectag_insert_mode = 1;
+	opts.mtu = 50;
+	opts.check_out_pkts_toolong = 1;
+
+	size = (sizeof(list_mcs_cipher_vectors) / sizeof((list_mcs_cipher_vectors)[0]));
+	for (i = 0; i < size; i++) {
+		cur_td = &list_mcs_cipher_vectors[i];
+		err = test_macsec(&cur_td, MCS_ENCAP, &opts);
+		if (err)
+			err = -1;
+		else
+			err = 0;
+
+		all_err += err;
+	}
+
+	printf("\n%s: Success: %d, Failure: %d\n", __func__, size + all_err, -all_err);
+	return all_err;
+}
+
 static int
 ut_setup_inline_macsec(void)
 {
@@ -1359,6 +1681,30 @@ static struct unit_test_suite inline_macsec_testsuite  = {
 			"MACsec Encap and decap with VLAN",
 			ut_setup_inline_macsec, ut_teardown_inline_macsec,
 			test_inline_macsec_with_vlan),
+		TEST_CASE_NAMED_ST(
+			"MACsec packet drop",
+			ut_setup_inline_macsec, ut_teardown_inline_macsec,
+			test_inline_macsec_pkt_drop),
+		TEST_CASE_NAMED_ST(
+			"MACsec untagged Rx",
+			ut_setup_inline_macsec, ut_teardown_inline_macsec,
+			test_inline_macsec_untagged_rx),
+		TEST_CASE_NAMED_ST(
+			"MACsec bad tag Rx",
+			ut_setup_inline_macsec, ut_teardown_inline_macsec,
+			test_inline_macsec_bad_tag_rx),
+		TEST_CASE_NAMED_ST(
+			"MACsec SA not in use",
+			ut_setup_inline_macsec, ut_teardown_inline_macsec,
+			test_inline_macsec_sa_not_in_use),
+		TEST_CASE_NAMED_ST(
+			"MACsec out pkts untagged",
+			ut_setup_inline_macsec, ut_teardown_inline_macsec,
+			test_inline_macsec_out_pkts_untagged),
+		TEST_CASE_NAMED_ST(
+			"MACsec out pkts too long",
+			ut_setup_inline_macsec, ut_teardown_inline_macsec,
+			test_inline_macsec_out_pkts_toolong),
 
 		TEST_CASES_END() /**< NULL terminate unit test array */
 	},
app/test/test_security_inline_macsec_vectors.h +475 -0

481 lines not on this page · raw message

Signature · 1 line
2.25.1
#50 lore raw

PATCH v2 8/13 test/security: verify MACsec stats

In reply to Akhil Goyal

Added cases to verify various stats of MACsec.

---
 app/test/test_security_inline_macsec.c | 222 +++++++++++++++++++++++++
 1 file changed, 222 insertions(+)
app/test/test_security_inline_macsec.c +222 -0
index 2a06f31f37..9cab3253f4 100644
@@ -1438,6 +1438,140 @@ test_inline_macsec_sa_not_in_use(const void *data __rte_unused)
 	return all_err;
 }
 
+static int
+test_inline_macsec_decap_stats(const void *data __rte_unused)
+{
+	const struct mcs_test_vector *cur_td;
+	struct mcs_test_opts opts = {0};
+	int err, all_err = 0;
+	int i, size;
+
+	opts.val_frames = RTE_SECURITY_MACSEC_VALIDATE_STRICT;
+	opts.protect_frames = true;
+	opts.sa_in_use = 1;
+	opts.nb_td = 1;
+	opts.sectag_insert_mode = 1;
+	opts.mtu = RTE_ETHER_MTU;
+	opts.check_decap_stats = 1;
+
+	size = (sizeof(list_mcs_cipher_vectors) / sizeof((list_mcs_cipher_vectors)[0]));
+
+	for (i = 0; i < size; i++) {
+		cur_td = &list_mcs_cipher_vectors[i];
+		err = test_macsec(&cur_td, MCS_DECAP, &opts);
+		if (err) {
+			printf("\nDecap stats case %d failed", cur_td->test_idx);
+			err = -1;
+		} else {
+			printf("\nDecap stats case %d passed", cur_td->test_idx);
+			err = 0;
+		}
+		all_err += err;
+	}
+	printf("\n%s: Success: %d, Failure: %d\n", __func__, size + all_err, -all_err);
+
+	return all_err;
+}
+
+static int
+test_inline_macsec_verify_only_stats(const void *data __rte_unused)
+{
+	const struct mcs_test_vector *cur_td;
+	struct mcs_test_opts opts = {0};
+	int err, all_err = 0;
+	int i, size;
+
+	opts.val_frames = RTE_SECURITY_MACSEC_VALIDATE_STRICT;
+	opts.protect_frames = true;
+	opts.sa_in_use = 1;
+	opts.nb_td = 1;
+	opts.sectag_insert_mode = 1;
+	opts.mtu = RTE_ETHER_MTU;
+	opts.check_verify_only_stats = 1;
+
+	size = (sizeof(list_mcs_integrity_vectors) / sizeof((list_mcs_integrity_vectors)[0]));
+
+	for (i = 0; i < size; i++) {
+		cur_td = &list_mcs_integrity_vectors[i];
+		err = test_macsec(&cur_td, MCS_VERIFY_ONLY, &opts);
+		if (err) {
+			printf("\nVerify only stats case %d failed", cur_td->test_idx);
+			err = -1;
+		} else {
+			printf("\nVerify only stats case %d Passed", cur_td->test_idx);
+			err = 0;
+		}
+		all_err += err;
+	}
+	printf("\n%s: Success: %d, Failure: %d\n", __func__, size + all_err, -all_err);
+
+	return all_err;
+}
+
+static int
+test_inline_macsec_pkts_invalid_stats(const void *data __rte_unused)
+{
+	const struct mcs_test_vector *cur_td;
+	struct mcs_test_opts opts = {0};
+	int err, all_err = 0;
+	int i, size;
+
+	opts.val_frames = RTE_SECURITY_MACSEC_VALIDATE_STRICT;
+	opts.protect_frames = true;
+	opts.sa_in_use = 1;
+	opts.nb_td = 1;
+	opts.sectag_insert_mode = 1;
+	opts.mtu = RTE_ETHER_MTU;
+
+	size = (sizeof(list_mcs_err_cipher_vectors) / sizeof((list_mcs_err_cipher_vectors)[0]));
+
+	for (i = 0; i < size; i++) {
+		cur_td = &list_mcs_err_cipher_vectors[i];
+		err = test_macsec(&cur_td, MCS_DECAP, &opts);
+		if (err)
+			err = 0;
+		else
+			err = -1;
+
+		all_err += err;
+	}
+	printf("\n%s: Success: %d, Failure: %d\n", __func__, size + all_err, -all_err);
+	return all_err;
+}
+
+static int
+test_inline_macsec_pkts_unchecked_stats(const void *data __rte_unused)
+{
+	const struct mcs_test_vector *cur_td;
+	struct mcs_test_opts opts = {0};
+	int err, all_err = 0;
+	int i, size;
+
+	opts.val_frames = RTE_SECURITY_MACSEC_VALIDATE_DISABLE;
+	opts.protect_frames = true;
+	opts.sa_in_use = 1;
+	opts.nb_td = 1;
+	opts.sectag_insert_mode = 1;
+	opts.mtu = RTE_ETHER_MTU;
+	opts.check_pkts_unchecked_stats = 1;
+
+	size = (sizeof(list_mcs_integrity_vectors) / sizeof((list_mcs_integrity_vectors)[0]));
+
+	for (i = 0; i < size; i++) {
+		cur_td = &list_mcs_integrity_vectors[i];
+		err = test_macsec(&cur_td, MCS_VERIFY_ONLY, &opts);
+		if (err)
+			err = -1;
+		else
+			err = 0;
+
+		all_err += err;
+	}
+
+	printf("\n%s: Success: %d, Failure: %d\n", __func__, size + all_err, -all_err);
+	return all_err;
+}
+
 static int
 test_inline_macsec_out_pkts_untagged(const void *data __rte_unused)
 {
@@ -1504,6 +1638,70 @@ test_inline_macsec_out_pkts_toolong(const void *data __rte_unused)
 	return all_err;
 }
 
+static int
+test_inline_macsec_encap_stats(const void *data __rte_unused)
+{
+	const struct mcs_test_vector *cur_td;
+	struct mcs_test_opts opts = {0};
+	int err, all_err = 0;
+	int i, size;
+
+	opts.val_frames = RTE_SECURITY_MACSEC_VALIDATE_STRICT;
+	opts.encrypt = true;
+	opts.protect_frames = true;
+	opts.sa_in_use = 1;
+	opts.nb_td = 1;
+	opts.sectag_insert_mode = 1;
+	opts.mtu = RTE_ETHER_MTU;
+	opts.check_encap_stats = 1;
+
+	size = (sizeof(list_mcs_cipher_vectors) / sizeof((list_mcs_cipher_vectors)[0]));
+	for (i = 0; i < size; i++) {
+		cur_td = &list_mcs_cipher_vectors[i];
+		err = test_macsec(&cur_td, MCS_ENCAP, &opts);
+		if (err)
+			err = -1;
+		else
+			err = 0;
+		all_err += err;
+	}
+
+	printf("\n%s: Success: %d, Failure: %d\n", __func__, size + all_err, -all_err);
+	return all_err;
+}
+
+static int
+test_inline_macsec_auth_only_stats(const void *data __rte_unused)
+{
+	const struct mcs_test_vector *cur_td;
+	struct mcs_test_opts opts = {0};
+	int err, all_err = 0;
+	int i, size;
+
+	opts.val_frames = RTE_SECURITY_MACSEC_VALIDATE_STRICT;
+	opts.protect_frames = true;
+	opts.sa_in_use = 1;
+	opts.nb_td = 1;
+	opts.sectag_insert_mode = 1;
+	opts.mtu = RTE_ETHER_MTU;
+	opts.check_auth_only_stats = 1;
+
+	size = (sizeof(list_mcs_integrity_vectors) / sizeof((list_mcs_integrity_vectors)[0]));
+
+	for (i = 0; i < size; i++) {
+		cur_td = &list_mcs_integrity_vectors[i];
+		err = test_macsec(&cur_td, MCS_AUTH_ONLY, &opts);
+		if (err)
+			err = -1;
+		else
+			err = 0;
+		all_err += err;
+	}
+
+	printf("\n%s: Success: %d, Failure: %d\n", __func__, size + all_err, -all_err);
+	return all_err;
+}
+
 static int
 ut_setup_inline_macsec(void)
 {
@@ -1697,6 +1895,22 @@ static struct unit_test_suite inline_macsec_testsuite  = {
 			"MACsec SA not in use",
 			ut_setup_inline_macsec, ut_teardown_inline_macsec,
 			test_inline_macsec_sa_not_in_use),
+		TEST_CASE_NAMED_ST(
+			"MACsec decap stats",
+			ut_setup_inline_macsec, ut_teardown_inline_macsec,
+			test_inline_macsec_decap_stats),
+		TEST_CASE_NAMED_ST(
+			"MACsec verify only stats",
+			ut_setup_inline_macsec, ut_teardown_inline_macsec,
+			test_inline_macsec_verify_only_stats),
+		TEST_CASE_NAMED_ST(
+			"MACsec pkts invalid stats",
+			ut_setup_inline_macsec, ut_teardown_inline_macsec,
+			test_inline_macsec_pkts_invalid_stats),
+		TEST_CASE_NAMED_ST(
+			"MACsec pkts unchecked stats",
+			ut_setup_inline_macsec, ut_teardown_inline_macsec,
+			test_inline_macsec_pkts_unchecked_stats),
 		TEST_CASE_NAMED_ST(
 			"MACsec out pkts untagged",
 			ut_setup_inline_macsec, ut_teardown_inline_macsec,
@@ -1705,6 +1919,14 @@ static struct unit_test_suite inline_macsec_testsuite  = {
 			"MACsec out pkts too long",
 			ut_setup_inline_macsec, ut_teardown_inline_macsec,
 			test_inline_macsec_out_pkts_toolong),
+		TEST_CASE_NAMED_ST(
+			"MACsec Encap stats",
+			ut_setup_inline_macsec, ut_teardown_inline_macsec,
+			test_inline_macsec_encap_stats),
+		TEST_CASE_NAMED_ST(
+			"MACsec auth only stats",
+			ut_setup_inline_macsec, ut_teardown_inline_macsec,
+			test_inline_macsec_auth_only_stats),
 
 		TEST_CASES_END() /**< NULL terminate unit test array */
 	},
Signature · 1 line
2.25.1
#51 lore raw

PATCH v2 9/13 test/security: verify MACsec interrupts

In reply to Akhil Goyal

From: Ankur Dwivedi <[email protected]>

This patch enables the test_inline_macsec_interrupts_all test case for MACSEC.

---
 app/test/test_security_inline_macsec.c        | 124 +++++++
 .../test_security_inline_macsec_vectors.h     | 306 +++++++++++++++++-
 2 files changed, 429 insertions(+), 1 deletion(-)
app/test/test_security_inline_macsec.c +124 -0
index 9cab3253f4..12e3234cfb 100644
@@ -757,6 +757,71 @@ mcs_stats_check(struct rte_security_ctx *ctx, enum mcs_op op,
 	return 0;
 }
 
+static int
+test_macsec_event_callback(uint16_t port_id, enum rte_eth_event_type type,
+			   void *param, void *ret_param)
+{
+	struct mcs_err_vector *vector = (struct mcs_err_vector *)param;
+	struct rte_eth_event_macsec_desc *event_desc = NULL;
+
+	RTE_SET_USED(port_id);
+
+	if (type != RTE_ETH_EVENT_MACSEC)
+		return -1;
+
+	event_desc = ret_param;
+	if (event_desc == NULL) {
+		printf("Event descriptor not set\n");
+		return -1;
+	}
+	vector->notify_event = true;
+
+	switch (event_desc->type) {
+	case RTE_ETH_EVENT_MACSEC_SECTAG_VAL_ERR:
+		vector->event = RTE_ETH_EVENT_MACSEC_SECTAG_VAL_ERR;
+		switch (event_desc->subtype) {
+		case RTE_ETH_SUBEVENT_MACSEC_RX_SECTAG_V_EQ1:
+			vector->event_subtype = RTE_ETH_SUBEVENT_MACSEC_RX_SECTAG_V_EQ1;
+			break;
+		case RTE_ETH_SUBEVENT_MACSEC_RX_SECTAG_E_EQ0_C_EQ1:
+			vector->event_subtype = RTE_ETH_SUBEVENT_MACSEC_RX_SECTAG_E_EQ0_C_EQ1;
+			break;
+		case RTE_ETH_SUBEVENT_MACSEC_RX_SECTAG_SL_GTE48:
+			vector->event_subtype = RTE_ETH_SUBEVENT_MACSEC_RX_SECTAG_SL_GTE48;
+			break;
+		case RTE_ETH_SUBEVENT_MACSEC_RX_SECTAG_ES_EQ1_SC_EQ1:
+			vector->event_subtype = RTE_ETH_SUBEVENT_MACSEC_RX_SECTAG_ES_EQ1_SC_EQ1;
+			break;
+		case RTE_ETH_SUBEVENT_MACSEC_RX_SECTAG_SC_EQ1_SCB_EQ1:
+			vector->event_subtype = RTE_ETH_SUBEVENT_MACSEC_RX_SECTAG_SC_EQ1_SCB_EQ1;
+			break;
+		default:
+			printf("\nUnknown Macsec event subtype: %d", event_desc->subtype);
+		}
+		break;
+	case RTE_ETH_EVENT_MACSEC_RX_SA_PN_HARD_EXP:
+		vector->event = RTE_ETH_EVENT_MACSEC_RX_SA_PN_HARD_EXP;
+		break;
+	case RTE_ETH_EVENT_MACSEC_RX_SA_PN_SOFT_EXP:
+		vector->event = RTE_ETH_EVENT_MACSEC_RX_SA_PN_SOFT_EXP;
+		break;
+	case RTE_ETH_EVENT_MACSEC_TX_SA_PN_HARD_EXP:
+		vector->event = RTE_ETH_EVENT_MACSEC_TX_SA_PN_HARD_EXP;
+		break;
+	case RTE_ETH_EVENT_MACSEC_TX_SA_PN_SOFT_EXP:
+		vector->event = RTE_ETH_EVENT_MACSEC_TX_SA_PN_SOFT_EXP;
+		break;
+	case RTE_ETH_EVENT_MACSEC_SA_NOT_VALID:
+		vector->event = RTE_ETH_EVENT_MACSEC_SA_NOT_VALID;
+		break;
+	default:
+		printf("Invalid MACsec event reported\n");
+		return -1;
+	}
+
+	return 0;
+}
+
 static int
 test_macsec(const struct mcs_test_vector *td[], enum mcs_op op, const struct mcs_test_opts *opts)
 {
@@ -914,6 +979,8 @@ test_macsec(const struct mcs_test_vector *td[], enum mcs_op op, const struct mcs
 		while (--nb_rx >= 0)
 			rte_pktmbuf_free(rx_pkts_burst[nb_rx]);
 		ret = TEST_FAILED;
+		if (opts->check_sectag_interrupts == 1)
+			ret = TEST_SUCCESS;
 		goto out;
 	}
 
@@ -1702,6 +1769,59 @@ test_inline_macsec_auth_only_stats(const void *data __rte_unused)
 	return all_err;
 }
 
+static int
+test_inline_macsec_interrupts_all(const void *data __rte_unused)
+{
+	struct mcs_err_vector err_vector = {0};
+	const struct mcs_test_vector *cur_td;
+	struct mcs_test_opts opts = {0};
+	int i, size;
+	int err, all_err = 0;
+	enum rte_eth_event_macsec_subtype subtype[] =  {
+		RTE_ETH_SUBEVENT_MACSEC_RX_SECTAG_V_EQ1,
+		RTE_ETH_SUBEVENT_MACSEC_RX_SECTAG_E_EQ0_C_EQ1,
+		RTE_ETH_SUBEVENT_MACSEC_RX_SECTAG_SL_GTE48,
+		RTE_ETH_SUBEVENT_MACSEC_RX_SECTAG_ES_EQ1_SC_EQ1,
+		RTE_ETH_SUBEVENT_MACSEC_RX_SECTAG_SC_EQ1_SCB_EQ1,
+	};
+
+	opts.val_frames = RTE_SECURITY_MACSEC_VALIDATE_STRICT;
+	opts.protect_frames = true;
+	opts.sa_in_use = 1;
+	opts.nb_td = 1;
+	opts.sectag_insert_mode = 1;
+	opts.mtu = RTE_ETHER_MTU;
+	opts.check_sectag_interrupts = 1;
+
+	err_vector.event = RTE_ETH_EVENT_MACSEC_UNKNOWN;
+	err_vector.event_subtype = RTE_ETH_SUBEVENT_MACSEC_UNKNOWN;
+	rte_eth_dev_callback_register(port_id, RTE_ETH_EVENT_MACSEC,
+			test_macsec_event_callback, &err_vector);
+
+	size = (sizeof(list_mcs_intr_test_vectors) / sizeof((list_mcs_intr_test_vectors)[0]));
+
+	for (i = 0; i < size; i++) {
+		cur_td = &list_mcs_intr_test_vectors[i];
+		err = test_macsec(&cur_td, MCS_DECAP, &opts);
+		if ((err_vector.event == RTE_ETH_EVENT_MACSEC_SECTAG_VAL_ERR) &&
+		    (err_vector.event_subtype == subtype[i])) {
+			printf("\nSectag val err interrupt test case %d passed",
+			       cur_td->test_idx);
+			err = 0;
+		} else {
+			printf("\nSectag val err interrupt test case %d failed",
+			       cur_td->test_idx);
+			err = -1;
+		}
+		all_err += err;
+	}
+	rte_eth_dev_callback_unregister(port_id, RTE_ETH_EVENT_MACSEC,
+			test_macsec_event_callback, &err_vector);
+
+	printf("\n%s: Success: %d, Failure: %d\n", __func__, size + all_err, -all_err);
+	return all_err;
+}
+
 static int
 ut_setup_inline_macsec(void)
 {
@@ -1927,6 +2047,10 @@ static struct unit_test_suite inline_macsec_testsuite  = {
 			"MACsec auth only stats",
 			ut_setup_inline_macsec, ut_teardown_inline_macsec,
 			test_inline_macsec_auth_only_stats),
+		TEST_CASE_NAMED_ST(
+			"MACsec interrupts all",
+			ut_setup_inline_macsec, ut_teardown_inline_macsec,
+			test_inline_macsec_interrupts_all),
 
 		TEST_CASES_END() /**< NULL terminate unit test array */
 	},
app/test/test_security_inline_macsec_vectors.h +305 -1

317 lines not on this page · raw message

Signature · 1 line
2.25.1
#52 lore raw

PATCH v2 10/13 test/security: verify MACsec Tx HW rekey

In reply to Akhil Goyal

This patch enables the Tx HW rekey test case for MACSEC.

---
 app/test/test_security_inline_macsec.c        | 137 +++++++++-
 .../test_security_inline_macsec_vectors.h     | 243 ++++++++++++++++++
 2 files changed, 378 insertions(+), 2 deletions(-)
app/test/test_security_inline_macsec.c +135 -2
index 12e3234cfb..2172f61199 100644
@@ -207,6 +207,8 @@ fill_macsec_sc_conf(const struct mcs_test_vector *td,
 	uint8_t i;
 
 	sc_conf->dir = dir;
+	sc_conf->pn_threshold = ((uint64_t)td->xpn << 32) |
+		rte_be_to_cpu_32(*(const uint32_t *)(&td->secure_pkt.data[tci_off + 2]));
 	if (dir == RTE_SECURITY_MACSEC_DIR_TX) {
 		sc_conf->sc_tx.sa_id = sa_id[0];
 		if (sa_id[1] != MCS_INVALID_SA) {
@@ -232,12 +234,16 @@ fill_macsec_sc_conf(const struct mcs_test_vector *td,
 			/* use some default SCI */
 			sc_conf->sc_tx.sci = 0xf1341e023a2b1c5d;
 		}
+		if (td->xpn > 0)
+			sc_conf->sc_tx.is_xpn = 1;
 	} else {
 		for (i = 0; i < RTE_SECURITY_MACSEC_NUM_AN; i++) {
 			sc_conf->sc_rx.sa_id[i] = sa_id[i];
 			sc_conf->sc_rx.sa_in_use[i] = opts->sa_in_use;
 		}
 		sc_conf->sc_rx.active = 1;
+		if (td->xpn > 0)
+			sc_conf->sc_rx.is_xpn = 1;
 	}
 }
 
@@ -834,6 +840,7 @@ test_macsec(const struct mcs_test_vector *td[], enum mcs_op op, const struct mcs
 	struct rte_security_session_conf sess_conf = {0};
 	struct rte_security_macsec_sa sa_conf = {0};
 	struct rte_security_macsec_sc sc_conf = {0};
+	struct mcs_err_vector err_vector = {0};
 	struct rte_security_ctx *ctx;
 	int nb_rx = 0, nb_sent;
 	int i, j = 0, ret, id, an = 0;
@@ -868,6 +875,34 @@ test_macsec(const struct mcs_test_vector *td[], enum mcs_op op, const struct mcs
 		}
 		j++;
 
+		if (opts->rekey_en) {
+
+			err_vector.td = td[i];
+			err_vector.rekey_td = opts->rekey_td;
+			err_vector.event = RTE_ETH_EVENT_MACSEC_UNKNOWN;
+			err_vector.event_subtype = RTE_ETH_SUBEVENT_MACSEC_UNKNOWN;
+			rte_eth_dev_callback_register(port_id, RTE_ETH_EVENT_MACSEC,
+					test_macsec_event_callback, &err_vector);
+			if (op == MCS_DECAP || op == MCS_VERIFY_ONLY)
+				tx_pkts_burst[j] = init_packet(mbufpool,
+						opts->rekey_td->secure_pkt.data,
+						opts->rekey_td->secure_pkt.len);
+			else {
+				tx_pkts_burst[j] = init_packet(mbufpool,
+						opts->rekey_td->plain_pkt.data,
+						opts->rekey_td->plain_pkt.len);
+
+				tx_pkts_burst[j]->ol_flags |= RTE_MBUF_F_TX_MACSEC;
+			}
+			if (tx_pkts_burst[j] == NULL) {
+				while (j--)
+					rte_pktmbuf_free(tx_pkts_burst[j]);
+				ret = TEST_FAILED;
+				goto out;
+			}
+			j++;
+		}
+
 		if (op == MCS_DECAP || op == MCS_ENCAP_DECAP ||
 				op == MCS_VERIFY_ONLY || op == MCS_AUTH_VERIFY) {
 			for (an = 0; an < RTE_SECURITY_MACSEC_NUM_AN; an++) {
@@ -922,6 +957,20 @@ test_macsec(const struct mcs_test_vector *td[], enum mcs_op op, const struct mcs
 			}
 			tx_sa_id[i][0] = (uint16_t)id;
 			tx_sa_id[i][1] = MCS_INVALID_SA;
+			if (opts->rekey_en) {
+				memset(&sa_conf, 0, sizeof(struct rte_security_macsec_sa));
+				fill_macsec_sa_conf(opts->rekey_td, &sa_conf,
+					RTE_SECURITY_MACSEC_DIR_TX,
+					opts->rekey_td->secure_pkt.data[tci_off] &
+						RTE_MACSEC_AN_MASK,
+					tci_off);
+				id = rte_security_macsec_sa_create(ctx, &sa_conf);
+				if (id < 0) {
+					printf("MACsec rekey SA create failed : %d.\n", id);
+					goto out;
+				}
+				tx_sa_id[i][1] = (uint16_t)id;
+			}
 			fill_macsec_sc_conf(td[i], &sc_conf, opts,
 					RTE_SECURITY_MACSEC_DIR_TX, tx_sa_id[i], tci_off);
 			id = rte_security_macsec_sc_create(ctx, &sc_conf);
@@ -984,9 +1033,44 @@ test_macsec(const struct mcs_test_vector *td[], enum mcs_op op, const struct mcs
 		goto out;
 	}
 
+	if (opts->rekey_en) {
+		switch (err_vector.event) {
+		case RTE_ETH_EVENT_MACSEC_TX_SA_PN_SOFT_EXP:
+			printf("Received RTE_ETH_EVENT_MACSEC_TX_SA_PN_SOFT_EXP event\n");
+			/* The first sa is active now, so the 0th sa can be
+			 * reconfigured. Using the same key as zeroeth sa, but
+			 * other key can also be configured.
+			 */
+			rte_security_macsec_sa_destroy(ctx, tx_sa_id[0][0],
+					RTE_SECURITY_MACSEC_DIR_TX);
+			fill_macsec_sa_conf(td[0], &sa_conf,
+					RTE_SECURITY_MACSEC_DIR_TX,
+					td[0]->secure_pkt.data[tci_off] &
+					RTE_MACSEC_AN_MASK, tci_off);
+			id = rte_security_macsec_sa_create(ctx, &sa_conf);
+			if (id < 0) {
+				printf("MACsec SA create failed : %d.\n", id);
+				return TEST_FAILED;
+			}
+			tx_sa_id[0][0] = (uint16_t)id;
+			break;
+		default:
+			printf("Received unsupported event\n");
+		}
+	}
+
 	for (i = 0; i < nb_rx; i++) {
-		ret = test_macsec_post_process(rx_pkts_burst[i], td[i], op,
-				opts->check_out_pkts_untagged);
+		if (opts->rekey_en && i == 1) {
+			/* The second received packet is matched with
+			 * rekey td
+			 */
+			ret = test_macsec_post_process(rx_pkts_burst[i],
+					opts->rekey_td, op,
+					opts->check_out_pkts_untagged);
+		} else {
+			ret = test_macsec_post_process(rx_pkts_burst[i], td[i],
+					op, opts->check_out_pkts_untagged);
+		}
 		if (ret != TEST_SUCCESS) {
 			for ( ; i < nb_rx; i++)
 				rte_pktmbuf_free(rx_pkts_burst[i]);
@@ -1019,6 +1103,10 @@ test_macsec(const struct mcs_test_vector *td[], enum mcs_op op, const struct mcs
 
 	destroy_default_flow(port_id);
 
+	if (opts->rekey_en)
+		rte_eth_dev_callback_unregister(port_id, RTE_ETH_EVENT_MACSEC,
+					test_macsec_event_callback, &err_vector);
+
 	/* Destroy session so that other cases can create the session again */
 	for (i = 0; i < opts->nb_td; i++) {
 		if (op == MCS_ENCAP || op == MCS_ENCAP_DECAP ||
@@ -1029,6 +1117,10 @@ test_macsec(const struct mcs_test_vector *td[], enum mcs_op op, const struct mcs
 						RTE_SECURITY_MACSEC_DIR_TX);
 			rte_security_macsec_sa_destroy(ctx, tx_sa_id[i][0],
 						RTE_SECURITY_MACSEC_DIR_TX);
+			if (opts->rekey_en) {
+				rte_security_macsec_sa_destroy(ctx, tx_sa_id[i][1],
+						RTE_SECURITY_MACSEC_DIR_TX);
+			}
 		}
 		if (op == MCS_DECAP || op == MCS_ENCAP_DECAP ||
 				op == MCS_VERIFY_ONLY || op == MCS_AUTH_VERIFY) {
@@ -1822,6 +1914,43 @@ test_inline_macsec_interrupts_all(const void *data __rte_unused)
 	return all_err;
 }
 
+static int
+test_inline_macsec_rekey_tx(const void *data __rte_unused)
+{
+	const struct mcs_test_vector *cur_td;
+	struct mcs_test_opts opts = {0};
+	int err, all_err = 0;
+	int i, size;
+
+	opts.val_frames = RTE_SECURITY_MACSEC_VALIDATE_STRICT;
+	opts.protect_frames = true;
+	opts.encrypt = true;
+	opts.sa_in_use = 1;
+	opts.nb_td = 1;
+	opts.sectag_insert_mode = 1;
+	opts.mtu = RTE_ETHER_MTU;
+	opts.rekey_en = 1;
+
+	size = (sizeof(list_mcs_rekey_vectors) / sizeof((list_mcs_rekey_vectors)[0]));
+
+	for (i = 0; i < size; i++) {
+		cur_td = &list_mcs_rekey_vectors[i];
+		opts.rekey_td = &list_mcs_rekey_vectors[++i];
+		err = test_macsec(&cur_td, MCS_ENCAP, &opts);
+		if (err) {
+			printf("Tx hw rekey test case %d failed\n", i);
+			err = -1;
+		} else {
+			printf("Tx hw rekey test case %d passed\n", i);
+			err = 0;
+		}
+		all_err += err;
+	}
+
+	printf("\n%s: Success: %d, Failure: %d\n", __func__, size + all_err, -all_err);
+	return all_err;
+}
+
 static int
 ut_setup_inline_macsec(void)
 {
@@ -2051,6 +2180,10 @@ static struct unit_test_suite inline_macsec_testsuite  = {
 			"MACsec interrupts all",
 			ut_setup_inline_macsec, ut_teardown_inline_macsec,
 			test_inline_macsec_interrupts_all),
+		TEST_CASE_NAMED_ST(
+			"MACsec re-key Tx",
+			ut_setup_inline_macsec, ut_teardown_inline_macsec,
+			test_inline_macsec_rekey_tx),
 
 		TEST_CASES_END() /**< NULL terminate unit test array */
 	},
app/test/test_security_inline_macsec_vectors.h +243 -0

253 lines not on this page · raw message

Signature · 1 line
2.25.1
#53 lore raw

PATCH v2 11/13 test/security: verify MACsec Rx rekey

In reply to Akhil Goyal

From: Ankur Dwivedi <[email protected]>

This patch enables the Rx rekey test case for MACSEC.

---
 app/test/test_security_inline_macsec.c | 50 +++++++++++++++++++++++++-
 1 file changed, 49 insertions(+), 1 deletion(-)
app/test/test_security_inline_macsec.c +49 -1
index 2172f61199..d832dfc170 100644
@@ -906,8 +906,14 @@ test_macsec(const struct mcs_test_vector *td[], enum mcs_op op, const struct mcs
 		if (op == MCS_DECAP || op == MCS_ENCAP_DECAP ||
 				op == MCS_VERIFY_ONLY || op == MCS_AUTH_VERIFY) {
 			for (an = 0; an < RTE_SECURITY_MACSEC_NUM_AN; an++) {
+				if (opts->rekey_en && an ==
+						(opts->rekey_td->secure_pkt.data[tci_off] &
+						RTE_MACSEC_AN_MASK))
+					fill_macsec_sa_conf(opts->rekey_td, &sa_conf,
+						RTE_SECURITY_MACSEC_DIR_RX, an, tci_off);
+				else
 				/* For simplicity, using same SA conf for all AN */
-				fill_macsec_sa_conf(td[i], &sa_conf,
+					fill_macsec_sa_conf(td[i], &sa_conf,
 						RTE_SECURITY_MACSEC_DIR_RX, an, tci_off);
 				id = rte_security_macsec_sa_create(ctx, &sa_conf);
 				if (id < 0) {
@@ -1054,6 +1060,9 @@ test_macsec(const struct mcs_test_vector *td[], enum mcs_op op, const struct mcs
 			}
 			tx_sa_id[0][0] = (uint16_t)id;
 			break;
+		case RTE_ETH_EVENT_MACSEC_RX_SA_PN_SOFT_EXP:
+			printf("Received RTE_ETH_EVENT_MACSEC_RX_SA_PN_SOFT_EXP event\n");
+			break;
 		default:
 			printf("Received unsupported event\n");
 		}
@@ -1951,6 +1960,41 @@ test_inline_macsec_rekey_tx(const void *data __rte_unused)
 	return all_err;
 }
 
+static int
+test_inline_macsec_rekey_rx(const void *data __rte_unused)
+{
+	const struct mcs_test_vector *cur_td;
+	struct mcs_test_opts opts = {0};
+	int err, all_err = 0;
+	int i, size;
+
+	opts.val_frames = RTE_SECURITY_MACSEC_VALIDATE_STRICT;
+	opts.protect_frames = true;
+	opts.sa_in_use = 1;
+	opts.nb_td = 1;
+	opts.sectag_insert_mode = 1;
+	opts.mtu = RTE_ETHER_MTU;
+	opts.rekey_en = 1;
+
+	size = (sizeof(list_mcs_rekey_vectors) / sizeof((list_mcs_rekey_vectors)[0]));
+	for (i = 0; i < size; i++) {
+		cur_td = &list_mcs_rekey_vectors[i];
+		opts.rekey_td = &list_mcs_rekey_vectors[++i];
+		err = test_macsec(&cur_td, MCS_DECAP, &opts);
+		if (err) {
+			printf("Rx rekey test case %d failed\n", i);
+			err = -1;
+		} else {
+			printf("Rx rekey test case %d passed\n", i);
+			err = 0;
+		}
+		all_err += err;
+	}
+
+	printf("\n%s: Success: %d, Failure: %d\n", __func__, size + all_err, -all_err);
+	return all_err;
+}
+
 static int
 ut_setup_inline_macsec(void)
 {
@@ -2184,6 +2228,10 @@ static struct unit_test_suite inline_macsec_testsuite  = {
 			"MACsec re-key Tx",
 			ut_setup_inline_macsec, ut_teardown_inline_macsec,
 			test_inline_macsec_rekey_tx),
+		TEST_CASE_NAMED_ST(
+			"MACsec re-key Rx",
+			ut_setup_inline_macsec, ut_teardown_inline_macsec,
+			test_inline_macsec_rekey_rx),
 
 		TEST_CASES_END() /**< NULL terminate unit test array */
 	},
Signature · 1 line
2.25.1
#54 lore raw

PATCH v2 12/13 test/security: verify MACsec anti replay

In reply to Akhil Goyal

From: Ankur Dwivedi <[email protected]>

This patch enables anti replay test case for MACsec.

---
 app/test/test_security_inline_macsec.c        |  82 +++
 .../test_security_inline_macsec_vectors.h     | 467 ++++++++++++++++++
 2 files changed, 549 insertions(+)
app/test/test_security_inline_macsec.c +82 -0
index d832dfc170..f7fb1b6fd6 100644
@@ -61,6 +61,7 @@ struct mcs_test_opts {
 	uint8_t replay_protect;
 	uint8_t rekey_en;
 	const struct mcs_test_vector *rekey_td;
+	const struct mcs_test_vector *ar_td[3];
 	bool dump_all_stats;
 	uint8_t check_untagged_rx;
 	uint8_t check_bad_tag_cnt;
@@ -716,6 +717,15 @@ mcs_stats_check(struct rte_security_ctx *ctx, enum mcs_op op,
 		if (opts->check_pkts_unchecked_stats && sc_stat.pkt_unchecked_cnt != 1)
 			return TEST_FAILED;
 
+		if (opts->replay_protect) {
+			if (opts->replay_win_sz == 0 &&
+					sc_stat.pkt_late_cnt != 2)
+				return TEST_FAILED;
+			else if (opts->replay_win_sz == 32 &&
+					sc_stat.pkt_late_cnt != 1)
+				return TEST_FAILED;
+		}
+
 		for (i = 0; i < RTE_SECURITY_MACSEC_NUM_AN; i++) {
 			memset(&sa_stat, 0, sizeof(struct rte_security_macsec_sa_stats));
 			rte_security_macsec_sa_stats_get(ctx, rx_sa_id[i],
@@ -845,6 +855,7 @@ test_macsec(const struct mcs_test_vector *td[], enum mcs_op op, const struct mcs
 	int nb_rx = 0, nb_sent;
 	int i, j = 0, ret, id, an = 0;
 	uint8_t tci_off;
+	int k;
 
 	memset(rx_pkts_burst, 0, sizeof(rx_pkts_burst[0]) * opts->nb_td);
 
@@ -875,6 +886,20 @@ test_macsec(const struct mcs_test_vector *td[], enum mcs_op op, const struct mcs
 		}
 		j++;
 
+		if (opts->replay_protect) {
+			for (k = 0; k < 3; k++, j++) {
+				tx_pkts_burst[j] = init_packet(mbufpool,
+					opts->ar_td[k]->secure_pkt.data,
+					opts->ar_td[k]->secure_pkt.len);
+				if (tx_pkts_burst[j] == NULL) {
+					while (j--)
+						rte_pktmbuf_free(tx_pkts_burst[j]);
+					ret = TEST_FAILED;
+					goto out;
+				}
+			}
+		}
+
 		if (opts->rekey_en) {
 
 			err_vector.td = td[i];
@@ -1068,6 +1093,15 @@ test_macsec(const struct mcs_test_vector *td[], enum mcs_op op, const struct mcs
 		}
 	}
 
+	if (opts->replay_protect) {
+		for (i = 0; i < nb_rx; i++) {
+			rte_pktmbuf_free(rx_pkts_burst[i]);
+			rx_pkts_burst[i] = NULL;
+		}
+		ret = TEST_SUCCESS;
+		goto out;
+	}
+
 	for (i = 0; i < nb_rx; i++) {
 		if (opts->rekey_en && i == 1) {
 			/* The second received packet is matched with
@@ -1995,6 +2029,50 @@ test_inline_macsec_rekey_rx(const void *data __rte_unused)
 	return all_err;
 }
 
+static int
+test_inline_macsec_anti_replay(const void *data __rte_unused)
+{
+	const struct mcs_test_vector *cur_td;
+	struct mcs_test_opts opts = {0};
+	uint16_t replay_win_sz[2] = {32, 0};
+	int err, all_err = 0;
+	int i, size;
+	int j;
+
+	opts.val_frames = RTE_SECURITY_MACSEC_VALIDATE_STRICT;
+	opts.sa_in_use = 1;
+	opts.nb_td = 1;
+	opts.sectag_insert_mode = 1;
+	opts.replay_protect = 1;
+
+	size = (sizeof(list_mcs_anti_replay_vectors) / sizeof((list_mcs_anti_replay_vectors)[0]));
+
+	for (j = 0; j < 2; j++) {
+		opts.replay_win_sz = replay_win_sz[j];
+
+		for (i = 0; i < size; i++) {
+			cur_td = &list_mcs_anti_replay_vectors[i];
+			opts.ar_td[0] = &list_mcs_anti_replay_vectors[++i];
+			opts.ar_td[1] = &list_mcs_anti_replay_vectors[++i];
+			opts.ar_td[2] = &list_mcs_anti_replay_vectors[++i];
+			err = test_macsec(&cur_td, MCS_DECAP, &opts);
+			if (err) {
+				printf("Replay window: %u, Anti replay test case %d failed\n",
+				       opts.replay_win_sz, i);
+				err = -1;
+			} else {
+				printf("Replay window: %u, Anti replay test case %d passed\n",
+				       opts.replay_win_sz, i);
+				err = 0;
+			}
+			all_err += err;
+		}
+	}
+
+	printf("\n%s: Success: %d, Failure: %d\n", __func__, size + all_err, -all_err);
+	return all_err;
+}
+
 static int
 ut_setup_inline_macsec(void)
 {
@@ -2232,6 +2310,10 @@ static struct unit_test_suite inline_macsec_testsuite  = {
 			"MACsec re-key Rx",
 			ut_setup_inline_macsec, ut_teardown_inline_macsec,
 			test_inline_macsec_rekey_rx),
+		TEST_CASE_NAMED_ST(
+			"MACsec anti-replay",
+			ut_setup_inline_macsec, ut_teardown_inline_macsec,
+			test_inline_macsec_anti_replay),
 
 		TEST_CASES_END() /**< NULL terminate unit test array */
 	},
app/test/test_security_inline_macsec_vectors.h +467 -0

471 lines not on this page · raw message

Signature · 1 line
2.25.1
#55 lore raw

PATCH v2 13/13 test/security: remove no MACsec support case

In reply to Akhil Goyal

Removed the test_capability_get_no_support_for_macsec case as MACsec is now supported and capability can have valid MACsec support.

---
 app/test/test_security.c | 37 -------------------------------------
 1 file changed, 37 deletions(-)
app/test/test_security.c +0 -37
index e4ddcefe40..4783cd0663 100644
@@ -1828,41 +1828,6 @@ test_capability_get_no_matching_protocol(void)
 	return TEST_SUCCESS;
 }
 
-/**
- * Test execution of rte_security_capability_get when macsec protocol
- * is searched and capabilities table contain proper entry.
- * However macsec records search is not supported in rte_security.
- */
-static int
-test_capability_get_no_support_for_macsec(void)
-{
-	struct security_unittest_params *ut_params = &unittest_params;
-	struct rte_security_capability_idx idx = {
-		.action = RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL,
-		.protocol = RTE_SECURITY_PROTOCOL_MACSEC,
-	};
-	struct rte_security_capability capabilities[] = {
-		{
-			.action = RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL,
-			.protocol = RTE_SECURITY_PROTOCOL_MACSEC,
-		},
-		{
-			.action = RTE_SECURITY_ACTION_TYPE_NONE,
-		},
-	};
-
-	mock_capabilities_get_exp.device = NULL;
-	mock_capabilities_get_exp.ret = capabilities;
-
-	const struct rte_security_capability *ret;
-	ret = rte_security_capability_get(&ut_params->ctx, &idx);
-	TEST_ASSERT_MOCK_FUNCTION_CALL_RET(rte_security_capability_get,
-			ret, NULL, "%p");
-	TEST_ASSERT_MOCK_CALLS(mock_capabilities_get_exp, 1);
-
-	return TEST_SUCCESS;
-}
-
 /**
  * Test execution of rte_security_capability_get when capabilities table
  * does not contain entry with matching ipsec proto field
@@ -2319,8 +2284,6 @@ static struct unit_test_suite security_testsuite  = {
 				test_capability_get_no_matching_action),
 		TEST_CASE_ST(ut_setup_with_session, ut_teardown,
 				test_capability_get_no_matching_protocol),
-		TEST_CASE_ST(ut_setup_with_session, ut_teardown,
-				test_capability_get_no_support_for_macsec),
 		TEST_CASE_ST(ut_setup_with_session, ut_teardown,
 				test_capability_get_ipsec_mismatch_proto),
 		TEST_CASE_ST(ut_setup_with_session, ut_teardown,
Signature · 1 line
2.25.1
#56 lore raw

v3 cover Add MACsec unit test cases

In reply to Akhil Goyal

Inline MACsec offload was supported in DPDK 22.11
using rte_security APIs.
This patchset adds few minor changes in the rte_security APIs to specify the direction of SA/SC and update the SC configuration to set packet number threshold.

The patchset also add functional test cases in dpdk-test app to verify MACsec functionality.

This patchset is pending from last release [1] due to lack of hardware to test. Now the test cases are verified on Marvell cnxk PMD and the pmd support is added as a separate patchset.

[1] https://patches.dpdk.org/project/dpdk/cover/[email protected]/

Changes in v3:
- updated libabigail.abignore exception as suggested by David.

Changes in v2:
- Added abignore for experimental APIs
- Fixed build

Akhil Goyal (10):
security: add direction in SA/SC configuration
security: add MACsec packet number threshold
test/security: add inline MACsec cases
test/security: add MACsec integrity cases
test/security: verify multi flow MACsec
test/security: add MACsec VLAN cases
test/security: add MACsec negative cases
test/security: verify MACsec stats
test/security: verify MACsec Tx HW rekey
test/security: remove no MACsec support case

Ankur Dwivedi (3):
test/security: verify MACsec interrupts
test/security: verify MACsec Rx rekey
test/security: verify MACsec anti replay

 app/test/meson.build                          |    1 +
 app/test/test_security.c                      |   37 -
 app/test/test_security_inline_macsec.c        | 2332 ++++++++++
 .../test_security_inline_macsec_vectors.h     | 3895 +++++++++++++++++
 devtools/libabigail.abignore                  |    4 +
 lib/security/rte_security.c                   |   16 +-
 lib/security/rte_security.h                   |   24 +-
 lib/security/rte_security_driver.h            |   12 +-
 8 files changed, 6270 insertions(+), 51 deletions(-)
 create mode 100644 app/test/test_security_inline_macsec.c
 create mode 100644 app/test/test_security_inline_macsec_vectors.h
Signature · 1 line
2.25.1
#57 lore raw

PATCH v3 1/13 security: add direction in SA/SC configuration

MACsec SC/SA ids are created based on direction of the flow. Hence, added the missing field for configuration and cleanup of the SCs and SAs.

---
 devtools/libabigail.abignore       |  4 ++++
 lib/security/rte_security.c        | 16 ++++++++++------
 lib/security/rte_security.h        | 14 ++++++++++----
 lib/security/rte_security_driver.h | 12 ++++++++++--
 4 files changed, 34 insertions(+), 12 deletions(-)
devtools/libabigail.abignore +4 -0
index c0361bfc7b..03bfbce259 100644
@@ -41,3 +41,7 @@
 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
 ; Temporary exceptions till next major ABI version ;
 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+
+; Ignore changes to rte_security_ops which are internal to PMD.
+[suppress_type]
+        name = rte_security_ops
lib/security/rte_security.c +10 -6
index e102c55e55..c4d64bb8e9 100644
@@ -164,13 +164,14 @@ rte_security_macsec_sa_create(struct rte_security_ctx *instance,
 }
 
 int
-rte_security_macsec_sc_destroy(struct rte_security_ctx *instance, uint16_t sc_id)
+rte_security_macsec_sc_destroy(struct rte_security_ctx *instance, uint16_t sc_id,
+			       enum rte_security_macsec_direction dir)
 {
 	int ret;
 
 	RTE_PTR_CHAIN3_OR_ERR_RET(instance, ops, macsec_sc_destroy, -EINVAL, -ENOTSUP);
 
-	ret = instance->ops->macsec_sc_destroy(instance->device, sc_id);
+	ret = instance->ops->macsec_sc_destroy(instance->device, sc_id, dir);
 	if (ret != 0)
 		return ret;
 
@@ -181,13 +182,14 @@ rte_security_macsec_sc_destroy(struct rte_security_ctx *instance, uint16_t sc_id
 }
 
 int
-rte_security_macsec_sa_destroy(struct rte_security_ctx *instance, uint16_t sa_id)
+rte_security_macsec_sa_destroy(struct rte_security_ctx *instance, uint16_t sa_id,
+			       enum rte_security_macsec_direction dir)
 {
 	int ret;
 
 	RTE_PTR_CHAIN3_OR_ERR_RET(instance, ops, macsec_sa_destroy, -EINVAL, -ENOTSUP);
 
-	ret = instance->ops->macsec_sa_destroy(instance->device, sa_id);
+	ret = instance->ops->macsec_sa_destroy(instance->device, sa_id, dir);
 	if (ret != 0)
 		return ret;
 
@@ -199,22 +201,24 @@ rte_security_macsec_sa_destroy(struct rte_security_ctx *instance, uint16_t sa_id
 
 int
 rte_security_macsec_sc_stats_get(struct rte_security_ctx *instance, uint16_t sc_id,
+				 enum rte_security_macsec_direction dir,
 				 struct rte_security_macsec_sc_stats *stats)
 {
 	RTE_PTR_CHAIN3_OR_ERR_RET(instance, ops, macsec_sc_stats_get, -EINVAL, -ENOTSUP);
 	RTE_PTR_OR_ERR_RET(stats, -EINVAL);
 
-	return instance->ops->macsec_sc_stats_get(instance->device, sc_id, stats);
+	return instance->ops->macsec_sc_stats_get(instance->device, sc_id, dir, stats);
 }
 
 int
 rte_security_macsec_sa_stats_get(struct rte_security_ctx *instance, uint16_t sa_id,
+				 enum rte_security_macsec_direction dir,
 				 struct rte_security_macsec_sa_stats *stats)
 {
 	RTE_PTR_CHAIN3_OR_ERR_RET(instance, ops, macsec_sa_stats_get, -EINVAL, -ENOTSUP);
 	RTE_PTR_OR_ERR_RET(stats, -EINVAL);
 
-	return instance->ops->macsec_sa_stats_get(instance->device, sa_id, stats);
+	return instance->ops->macsec_sa_stats_get(instance->device, sa_id, dir, stats);
 }
 
 int
lib/security/rte_security.h +10 -4
index 4bacf9fcd9..c7a523b6d6 100644
@@ -761,6 +761,7 @@ rte_security_macsec_sc_create(struct rte_security_ctx *instance,
  *
  * @param   instance	security instance
  * @param   sc_id	SC ID to be destroyed
+ * @param   dir		direction of the SC
  * @return
  *  - 0 if successful.
  *  - -EINVAL if sc_id is invalid or instance is NULL.
@@ -768,7 +769,8 @@ rte_security_macsec_sc_create(struct rte_security_ctx *instance,
  */
 __rte_experimental
 int
-rte_security_macsec_sc_destroy(struct rte_security_ctx *instance, uint16_t sc_id);
+rte_security_macsec_sc_destroy(struct rte_security_ctx *instance, uint16_t sc_id,
+			       enum rte_security_macsec_direction dir);
 
 /**
  * @warning
@@ -798,6 +800,7 @@ rte_security_macsec_sa_create(struct rte_security_ctx *instance,
  *
  * @param   instance	security instance
  * @param   sa_id	SA ID to be destroyed
+ * @param   dir		direction of the SA
  * @return
  *  - 0 if successful.
  *  - -EINVAL if sa_id is invalid or instance is NULL.
@@ -805,7 +808,8 @@ rte_security_macsec_sa_create(struct rte_security_ctx *instance,
  */
 __rte_experimental
 int
-rte_security_macsec_sa_destroy(struct rte_security_ctx *instance, uint16_t sa_id);
+rte_security_macsec_sa_destroy(struct rte_security_ctx *instance, uint16_t sa_id,
+			       enum rte_security_macsec_direction dir);
 
 /** Device-specific metadata field type */
 typedef uint64_t rte_security_dynfield_t;
@@ -1077,6 +1081,7 @@ rte_security_session_stats_get(struct rte_security_ctx *instance,
  *
  * @param	instance	security instance
  * @param	sa_id		SA ID for which stats are needed
+ * @param	dir		direction of the SA
  * @param	stats		statistics
  * @return
  *  - On success, return 0.
@@ -1085,7 +1090,7 @@ rte_security_session_stats_get(struct rte_security_ctx *instance,
 __rte_experimental
 int
 rte_security_macsec_sa_stats_get(struct rte_security_ctx *instance,
-				 uint16_t sa_id,
+				 uint16_t sa_id, enum rte_security_macsec_direction dir,
 				 struct rte_security_macsec_sa_stats *stats);
 
 /**
@@ -1096,6 +1101,7 @@ rte_security_macsec_sa_stats_get(struct rte_security_ctx *instance,
  *
  * @param	instance	security instance
  * @param	sc_id		SC ID for which stats are needed
+ * @param	dir		direction of the SC
  * @param	stats		SC statistics
  * @return
  *  - On success, return 0.
@@ -1104,7 +1110,7 @@ rte_security_macsec_sa_stats_get(struct rte_security_ctx *instance,
 __rte_experimental
 int
 rte_security_macsec_sc_stats_get(struct rte_security_ctx *instance,
-				 uint16_t sc_id,
+				 uint16_t sc_id, enum rte_security_macsec_direction dir,
 				 struct rte_security_macsec_sc_stats *stats);
 
 /**
lib/security/rte_security_driver.h +10 -2
index 421e6f7780..677c7d1f91 100644
@@ -106,8 +106,10 @@ typedef int (*security_macsec_sc_create_t)(void *device, struct rte_security_mac
  *
  * @param	device		Crypto/eth device pointer
  * @param	sc_id		MACsec SC ID
+ * @param	dir		Direction of SC
  */
-typedef int (*security_macsec_sc_destroy_t)(void *device, uint16_t sc_id);
+typedef int (*security_macsec_sc_destroy_t)(void *device, uint16_t sc_id,
+		enum rte_security_macsec_direction dir);
 
 /**
  * Configure a MACsec security Association (SA) on a device.
@@ -128,8 +130,10 @@ typedef int (*security_macsec_sa_create_t)(void *device, struct rte_security_mac
  *
  * @param	device		Crypto/eth device pointer
  * @param	sa_id		MACsec SA ID
+ * @param	dir		Direction of SA
  */
-typedef int (*security_macsec_sa_destroy_t)(void *device, uint16_t sa_id);
+typedef int (*security_macsec_sa_destroy_t)(void *device, uint16_t sa_id,
+		enum rte_security_macsec_direction dir);
 
 /**
  * Get the size of a security session
@@ -162,6 +166,7 @@ typedef int (*security_session_stats_get_t)(void *device,
  *
  * @param	device		Crypto/eth device pointer
  * @param	sc_id		secure channel ID created by rte_security_macsec_sc_create()
+ * @param	dir		direction of SC
  * @param	stats		SC stats of the driver
  *
  * @return
@@ -169,6 +174,7 @@ typedef int (*security_session_stats_get_t)(void *device,
  *  - -EINVAL if sc_id or device is invalid.
  */
 typedef int (*security_macsec_sc_stats_get_t)(void *device, uint16_t sc_id,
+		enum rte_security_macsec_direction dir,
 		struct rte_security_macsec_sc_stats *stats);
 
 /**
@@ -176,6 +182,7 @@ typedef int (*security_macsec_sc_stats_get_t)(void *device, uint16_t sc_id,
  *
  * @param	device		Crypto/eth device pointer
  * @param	sa_id		secure channel ID created by rte_security_macsec_sc_create()
+ * @param	dir		direction of SA
  * @param	stats		SC stats of the driver
  *
  * @return
@@ -183,6 +190,7 @@ typedef int (*security_macsec_sc_stats_get_t)(void *device, uint16_t sc_id,
  *  - -EINVAL if sa_id or device is invalid.
  */
 typedef int (*security_macsec_sa_stats_get_t)(void *device, uint16_t sa_id,
+		enum rte_security_macsec_direction dir,
 		struct rte_security_macsec_sa_stats *stats);
 
 
Signature · 1 line
2.25.1
#58 lore raw

PATCH v3 2/13 security: add MACsec packet number threshold

In reply to Akhil Goyal

Added Packet number threshold parameter in MACsec SC configuration to identify the maximum allowed threshold for packet number field in the packet.
A field is_xpn is also added to identify if the SAs are configured for extended packet number or not so that packet number threshold can be configured accordingly.

---
 lib/security/rte_security.h | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)
lib/security/rte_security.h +8 -2
index c7a523b6d6..30bac4e25a 100644
@@ -399,6 +399,8 @@ struct rte_security_macsec_sa {
 struct rte_security_macsec_sc {
 	/** Direction of SC */
 	enum rte_security_macsec_direction dir;
+	/** Packet number threshold */
+	uint64_t pn_threshold;
 	union {
 		struct {
 			/** SAs for each association number */
@@ -407,8 +409,10 @@ struct rte_security_macsec_sc {
 			uint8_t sa_in_use[RTE_SECURITY_MACSEC_NUM_AN];
 			/** Channel is active */
 			uint8_t active : 1;
+			/** Extended packet number is enabled for SAs */
+			uint8_t is_xpn : 1;
 			/** Reserved bitfields for future */
-			uint8_t reserved : 7;
+			uint8_t reserved : 6;
 		} sc_rx;
 		struct {
 			uint16_t sa_id; /**< SA ID to be used for encryption */
@@ -416,8 +420,10 @@ struct rte_security_macsec_sc {
 			uint64_t sci; /**< SCI value to be used if send_sci is set */
 			uint8_t active : 1; /**< Channel is active */
 			uint8_t re_key_en : 1; /**< Enable Rekeying */
+			/** Extended packet number is enabled for SAs */
+			uint8_t is_xpn : 1;
 			/** Reserved bitfields for future */
-			uint8_t reserved : 6;
+			uint8_t reserved : 5;
 		} sc_tx;
 	};
 };
Signature · 1 line
2.25.1
#59 lore raw

PATCH v3 3/13 test/security: add inline MACsec cases

In reply to Akhil Goyal

Updated test app to verify Inline MACsec offload using rte_security APIs.
A couple of test cases are added to verify encap only and decap only of some known test vectors from MACsec specification.

---
 app/test/meson.build                          |    1 +
 app/test/test_security_inline_macsec.c        | 1108 +++++++++++++++++
 .../test_security_inline_macsec_vectors.h     | 1086 ++++++++++++++++
 3 files changed, 2195 insertions(+)
 create mode 100644 app/test/test_security_inline_macsec.c
 create mode 100644 app/test/test_security_inline_macsec_vectors.h
app/test/meson.build +1 -0
index b9b5432496..69c1d19f7b 100644
@@ -128,6 +128,7 @@ test_sources = files(
         'test_rwlock.c',
         'test_sched.c',
         'test_security.c',
+        'test_security_inline_macsec.c',
         'test_security_inline_proto.c',
         'test_seqlock.c',
         'test_service_cores.c',
app/test/test_security_inline_macsec.c new file +1108 -0

1,108 lines not on this page · raw message

app/test/test_security_inline_macsec_vectors.h new file +1086 -0

1,086 lines not on this page · raw message

Signature · 1 line
2.25.1
#60 lore raw

PATCH v3 4/13 test/security: add MACsec integrity cases

In reply to Akhil Goyal

Added test vectors and test cases to verify auth_only/verify_only and encap-decap/auth-verify to verify the complete TX-RX path using the loopback mode of ethdev.

---
 app/test/test_security_inline_macsec.c        | 153 +++
 .../test_security_inline_macsec_vectors.h     | 995 ++++++++++++++++++
 2 files changed, 1148 insertions(+)
app/test/test_security_inline_macsec.c +153 -0
index 9ef967597b..7445b667e4 100644
@@ -937,6 +937,143 @@ test_inline_macsec_decap_all(const void *data __rte_unused)
 	return all_err;
 }
 
+static int
+test_inline_macsec_auth_only_all(const void *data __rte_unused)
+{
+	const struct mcs_test_vector *cur_td;
+	struct mcs_test_opts opts = {0};
+	int err, all_err = 0;
+	int i, size;
+
+	opts.val_frames = RTE_SECURITY_MACSEC_VALIDATE_STRICT;
+	opts.protect_frames = true;
+	opts.sa_in_use = 1;
+	opts.nb_td = 1;
+	opts.sectag_insert_mode = 1;
+	opts.mtu = RTE_ETHER_MTU;
+
+	size = (sizeof(list_mcs_integrity_vectors) / sizeof((list_mcs_integrity_vectors)[0]));
+
+	for (i = 0; i < size; i++) {
+		cur_td = &list_mcs_integrity_vectors[i];
+		err = test_macsec(&cur_td, MCS_AUTH_ONLY, &opts);
+		if (err) {
+			printf("\nAuth Generate case %d failed", cur_td->test_idx);
+			err = -1;
+		} else {
+			printf("\nAuth Generate case %d Passed", cur_td->test_idx);
+			err = 0;
+		}
+		all_err += err;
+	}
+	printf("\n%s: Success: %d, Failure: %d\n", __func__, size + all_err, -all_err);
+
+	return all_err;
+}
+
+static int
+test_inline_macsec_verify_only_all(const void *data __rte_unused)
+{
+	const struct mcs_test_vector *cur_td;
+	struct mcs_test_opts opts = {0};
+	int err, all_err = 0;
+	int i, size;
+
+	opts.val_frames = RTE_SECURITY_MACSEC_VALIDATE_STRICT;
+	opts.sa_in_use = 1;
+	opts.nb_td = 1;
+	opts.sectag_insert_mode = 1;
+	opts.mtu = RTE_ETHER_MTU;
+
+	size = (sizeof(list_mcs_integrity_vectors) / sizeof((list_mcs_integrity_vectors)[0]));
+
+	for (i = 0; i < size; i++) {
+		cur_td = &list_mcs_integrity_vectors[i];
+		err = test_macsec(&cur_td, MCS_VERIFY_ONLY, &opts);
+		if (err) {
+			printf("\nAuth Verify case %d failed", cur_td->test_idx);
+			err = -1;
+		} else {
+			printf("\nAuth Verify case %d Passed", cur_td->test_idx);
+			err = 0;
+		}
+		all_err += err;
+	}
+	printf("\n%s: Success: %d, Failure: %d\n", __func__, size + all_err, -all_err);
+
+	return all_err;
+}
+
+static int
+test_inline_macsec_encap_decap_all(const void *data __rte_unused)
+{
+	const struct mcs_test_vector *cur_td;
+	struct mcs_test_opts opts = {0};
+	int err, all_err = 0;
+	int i, size;
+
+	opts.val_frames = RTE_SECURITY_MACSEC_VALIDATE_STRICT;
+	opts.encrypt = true;
+	opts.protect_frames = true;
+	opts.sa_in_use = 1;
+	opts.nb_td = 1;
+	opts.sectag_insert_mode = 1;
+	opts.mtu = RTE_ETHER_MTU;
+
+	size = (sizeof(list_mcs_cipher_vectors) / sizeof((list_mcs_cipher_vectors)[0]));
+
+	for (i = 0; i < size; i++) {
+		cur_td = &list_mcs_cipher_vectors[i];
+		err = test_macsec(&cur_td, MCS_ENCAP_DECAP, &opts);
+		if (err) {
+			printf("\nCipher Auth Encap-decap case %d failed", cur_td->test_idx);
+			err = -1;
+		} else {
+			printf("\nCipher Auth Encap-decap case %d Passed", cur_td->test_idx);
+			err = 0;
+		}
+		all_err += err;
+	}
+	printf("\n%s: Success: %d, Failure: %d\n", __func__, size + all_err, -all_err);
+
+	return all_err;
+}
+
+
+static int
+test_inline_macsec_auth_verify_all(const void *data __rte_unused)
+{
+	const struct mcs_test_vector *cur_td;
+	struct mcs_test_opts opts = {0};
+	int err, all_err = 0;
+	int i, size;
+
+	opts.val_frames = RTE_SECURITY_MACSEC_VALIDATE_STRICT;
+	opts.protect_frames = true;
+	opts.sa_in_use = 1;
+	opts.nb_td = 1;
+	opts.sectag_insert_mode = 1;
+	opts.mtu = RTE_ETHER_MTU;
+
+	size = (sizeof(list_mcs_integrity_vectors) / sizeof((list_mcs_integrity_vectors)[0]));
+
+	for (i = 0; i < size; i++) {
+		cur_td = &list_mcs_integrity_vectors[i];
+		err = test_macsec(&cur_td, MCS_AUTH_VERIFY, &opts);
+		if (err) {
+			printf("\nAuth Generate + Verify case %d failed", cur_td->test_idx);
+			err = -1;
+		} else {
+			printf("\nAuth Generate + Verify case %d Passed", cur_td->test_idx);
+			err = 0;
+		}
+		all_err += err;
+	}
+	printf("\n%s: Success: %d, Failure: %d\n", __func__, size + all_err, -all_err);
+
+	return all_err;
+}
+
 static int
 ut_setup_inline_macsec(void)
 {
@@ -1090,6 +1227,22 @@ static struct unit_test_suite inline_macsec_testsuite  = {
 			"MACsec decap(De-cipher+verify) known vector",
 			ut_setup_inline_macsec, ut_teardown_inline_macsec,
 			test_inline_macsec_decap_all),
+		TEST_CASE_NAMED_ST(
+			"MACsec auth only known vector",
+			ut_setup_inline_macsec, ut_teardown_inline_macsec,
+			test_inline_macsec_auth_only_all),
+		TEST_CASE_NAMED_ST(
+			"MACsec verify only known vector",
+			ut_setup_inline_macsec, ut_teardown_inline_macsec,
+			test_inline_macsec_verify_only_all),
+		TEST_CASE_NAMED_ST(
+			"MACsec encap + decap known vector",
+			ut_setup_inline_macsec, ut_teardown_inline_macsec,
+			test_inline_macsec_encap_decap_all),
+		TEST_CASE_NAMED_ST(
+			"MACsec auth + verify known vector",
+			ut_setup_inline_macsec, ut_teardown_inline_macsec,
+			test_inline_macsec_auth_verify_all),
 
 		TEST_CASES_END() /**< NULL terminate unit test array */
 	},
app/test/test_security_inline_macsec_vectors.h +995 -0

999 lines not on this page · raw message

Signature · 1 line
2.25.1
#61 lore raw

PATCH v3 5/13 test/security: verify multi flow MACsec

In reply to Akhil Goyal

Added test case and test vectors to verify multiple flows of MACsec.

---
 app/test/test_security_inline_macsec.c        |  49 ++++++++
 .../test_security_inline_macsec_vectors.h     | 110 +++++++++++++++++-
 2 files changed, 158 insertions(+), 1 deletion(-)
app/test/test_security_inline_macsec.c +49 -0
index 7445b667e4..621074a928 100644
@@ -1074,6 +1074,51 @@ test_inline_macsec_auth_verify_all(const void *data __rte_unused)
 	return all_err;
 }
 
+static int
+test_inline_macsec_multi_flow(const void *data __rte_unused)
+{
+	const struct mcs_test_vector *tv[MCS_MAX_FLOWS];
+	struct mcs_test_vector iter[MCS_MAX_FLOWS];
+	struct mcs_test_opts opts = {0};
+	int i, err;
+
+	opts.val_frames = RTE_SECURITY_MACSEC_VALIDATE_STRICT;
+	opts.encrypt = true;
+	opts.protect_frames = true;
+	opts.sa_in_use = 1;
+	opts.nb_td = MCS_MAX_FLOWS;
+	opts.sectag_insert_mode = 1;
+	opts.mtu = RTE_ETHER_MTU;
+
+	for (i = 0; i < MCS_MAX_FLOWS; i++) {
+		memcpy(&iter[i].sa_key.data, sa_key, MCS_MULTI_FLOW_TD_KEY_SZ);
+		memcpy(&iter[i].plain_pkt.data, eth_addrs[i], 2 * RTE_ETHER_ADDR_LEN);
+		memcpy(&iter[i].plain_pkt.data[2 * RTE_ETHER_ADDR_LEN], plain_user_data,
+		       MCS_MULTI_FLOW_TD_PLAIN_DATA_SZ);
+		memcpy(&iter[i].secure_pkt.data, eth_addrs[i], 2 * RTE_ETHER_ADDR_LEN);
+		memcpy(&iter[i].secure_pkt.data[2 * RTE_ETHER_ADDR_LEN], secure_user_data,
+		       MCS_MULTI_FLOW_TD_SECURE_DATA_SZ);
+		iter[i].sa_key.len = MCS_MULTI_FLOW_TD_KEY_SZ;
+		iter[i].plain_pkt.len = MCS_MULTI_FLOW_TD_PLAIN_DATA_SZ +
+					(2 * RTE_ETHER_ADDR_LEN);
+		iter[i].secure_pkt.len = MCS_MULTI_FLOW_TD_SECURE_DATA_SZ +
+					(2 * RTE_ETHER_ADDR_LEN);
+		iter[i].alg = RTE_SECURITY_MACSEC_ALG_GCM_128;
+		iter[i].ssci = 0x0;
+		iter[i].xpn = 0x0;
+		tv[i] = (const struct mcs_test_vector *)&iter[i];
+	}
+	err = test_macsec(tv, MCS_ENCAP_DECAP, &opts);
+	if (err) {
+		printf("\nCipher Auth Encryption multi flow failed");
+		err = -1;
+	} else {
+		printf("\nCipher Auth Encryption multi flow Passed");
+		err = 0;
+	}
+	return err;
+}
+
 static int
 ut_setup_inline_macsec(void)
 {
@@ -1219,6 +1264,10 @@ inline_macsec_testsuite_teardown(void)
 static struct unit_test_suite inline_macsec_testsuite  = {
 	.suite_name = "Inline MACsec Ethernet Device Unit Test Suite",
 	.unit_test_cases = {
+		TEST_CASE_NAMED_ST(
+			"MACsec Encap + decap Multi flow",
+			ut_setup_inline_macsec, ut_teardown_inline_macsec,
+			test_inline_macsec_multi_flow),
 		TEST_CASE_NAMED_ST(
 			"MACsec encap(Cipher+Auth) known vector",
 			ut_setup_inline_macsec, ut_teardown_inline_macsec,
app/test/test_security_inline_macsec_vectors.h +109 -1

120 lines not on this page · raw message

Signature · 1 line
2.25.1
#62 lore raw

PATCH v3 6/13 test/security: add MACsec VLAN cases

In reply to Akhil Goyal

Added cases to verify MACsec processing with VLAN
tags inserted. Vectors are added to verify 1/2/3
VLAN tags in clear or encrypted data.

---
 app/test/test_security_inline_macsec.c        |  67 ++++++
 .../test_security_inline_macsec_vectors.h     | 217 ++++++++++++++++++
 2 files changed, 284 insertions(+)
app/test/test_security_inline_macsec.c +67 -0
index 621074a928..854ead75a0 100644
@@ -1119,6 +1119,69 @@ test_inline_macsec_multi_flow(const void *data __rte_unused)
 	return err;
 }
 
+static int
+test_inline_macsec_with_vlan(const void *data __rte_unused)
+{
+	const struct mcs_test_vector *cur_td;
+	struct mcs_test_opts opts = {0};
+	int err, all_err = 0;
+	int i, size;
+
+	opts.val_frames = RTE_SECURITY_MACSEC_VALIDATE_STRICT;
+	opts.protect_frames = true;
+	opts.sa_in_use = 1;
+	opts.nb_td = 1;
+	opts.mtu = RTE_ETHER_MTU;
+
+	size = (sizeof(list_mcs_vlan_vectors) / sizeof((list_mcs_vlan_vectors)[0]));
+
+	for (i = 0; i < size; i++) {
+		cur_td = &list_mcs_vlan_vectors[i];
+		if (i == 0) {
+			opts.sectag_insert_mode = 1;
+		} else if (i == 1) {
+			opts.sectag_insert_mode = 0; /* offset from special E-type */
+			opts.nb_vlan = 1;
+		} else if (i == 2) {
+			opts.sectag_insert_mode = 0; /* offset from special E-type */
+			opts.nb_vlan = 2;
+		}
+		err = test_macsec(&cur_td, MCS_ENCAP, &opts);
+		if (err) {
+			printf("\n VLAN Encap case %d failed", cur_td->test_idx);
+			err = -1;
+		} else {
+			printf("\n VLAN Encap case %d passed", cur_td->test_idx);
+			err = 0;
+		}
+		all_err += err;
+	}
+	for (i = 0; i < size; i++) {
+		cur_td = &list_mcs_vlan_vectors[i];
+		if (i == 0) {
+			opts.sectag_insert_mode = 1;
+		} else if (i == 1) {
+			opts.sectag_insert_mode = 0; /* offset from special E-type */
+			opts.nb_vlan = 1;
+		} else if (i == 2) {
+			opts.sectag_insert_mode = 0; /* offset from special E-type */
+			opts.nb_vlan = 2;
+		}
+		err = test_macsec(&cur_td, MCS_DECAP, &opts);
+		if (err) {
+			printf("\n VLAN Decap case %d failed", cur_td->test_idx);
+			err = -1;
+		} else {
+			printf("\n VLAN Decap case %d passed", cur_td->test_idx);
+			err = 0;
+		}
+		all_err += err;
+	}
+
+	printf("\n%s: Success: %d, Failure: %d\n", __func__, (2 * size) + all_err, -all_err);
+	return all_err;
+}
+
 static int
 ut_setup_inline_macsec(void)
 {
@@ -1292,6 +1355,10 @@ static struct unit_test_suite inline_macsec_testsuite  = {
 			"MACsec auth + verify known vector",
 			ut_setup_inline_macsec, ut_teardown_inline_macsec,
 			test_inline_macsec_auth_verify_all),
+		TEST_CASE_NAMED_ST(
+			"MACsec Encap and decap with VLAN",
+			ut_setup_inline_macsec, ut_teardown_inline_macsec,
+			test_inline_macsec_with_vlan),
 
 		TEST_CASES_END() /**< NULL terminate unit test array */
 	},
app/test/test_security_inline_macsec_vectors.h +217 -0

222 lines not on this page · raw message

Signature · 1 line
2.25.1
#63 lore raw

PATCH v3 7/13 test/security: add MACsec negative cases

In reply to Akhil Goyal

Added MACsec negative test cases to verify
pkt drop, untagged rx, bad tag rx, sa not in use,
out packets untagged, pkts too long.

---
 app/test/test_security_inline_macsec.c        | 346 +++++++++++++
 .../test_security_inline_macsec_vectors.h     | 475 ++++++++++++++++++
 2 files changed, 821 insertions(+)
app/test/test_security_inline_macsec.c +346 -0
index 854ead75a0..2a06f31f37 100644
@@ -660,6 +660,103 @@ mcs_stats_dump(struct rte_security_ctx *ctx, enum mcs_op op,
 	}
 }
 
+static int
+mcs_stats_check(struct rte_security_ctx *ctx, enum mcs_op op,
+		const struct mcs_test_opts *opts,
+		const struct mcs_test_vector *td,
+		void *rx_sess, void *tx_sess,
+		uint8_t rx_sc_id, uint8_t tx_sc_id,
+		uint16_t rx_sa_id[], uint16_t tx_sa_id[])
+{
+	struct rte_security_stats sess_stats = {0};
+	struct rte_security_macsec_secy_stats *secy_stat;
+	struct rte_security_macsec_sc_stats sc_stat = {0};
+	struct rte_security_macsec_sa_stats sa_stat = {0};
+	int i;
+
+	if (op == MCS_DECAP || op == MCS_ENCAP_DECAP ||
+			op == MCS_VERIFY_ONLY || op == MCS_AUTH_VERIFY) {
+		rte_security_session_stats_get(ctx, rx_sess, &sess_stats);
+		secy_stat = &sess_stats.macsec;
+
+		if ((opts->check_untagged_rx && secy_stat->pkt_notag_cnt != 1) ||
+				(opts->check_untagged_rx && secy_stat->pkt_untaged_cnt != 1))
+			return TEST_FAILED;
+
+		if (opts->check_bad_tag_cnt && secy_stat->pkt_badtag_cnt != 1)
+			return TEST_FAILED;
+
+		if (opts->check_sa_not_in_use && secy_stat->pkt_nosaerror_cnt != 1)
+			return TEST_FAILED;
+
+		if (opts->check_decap_stats && secy_stat->octet_decrypted_cnt !=
+				(uint16_t)(td->plain_pkt.len - 2 * RTE_ETHER_ADDR_LEN))
+			return TEST_FAILED;
+
+		if (opts->check_verify_only_stats && secy_stat->octet_validated_cnt !=
+				(uint16_t)(td->plain_pkt.len - 2 * RTE_ETHER_ADDR_LEN))
+			return TEST_FAILED;
+
+		rte_security_macsec_sc_stats_get(ctx, rx_sc_id,
+				RTE_SECURITY_MACSEC_DIR_RX, &sc_stat);
+
+		if ((opts->check_decap_stats || opts->check_verify_only_stats) &&
+				sc_stat.pkt_ok_cnt != 1)
+			return TEST_FAILED;
+
+		if (opts->check_pkts_invalid_stats && sc_stat.pkt_notvalid_cnt != 1)
+			return TEST_FAILED;
+
+		if (opts->check_pkts_unchecked_stats && sc_stat.pkt_unchecked_cnt != 1)
+			return TEST_FAILED;
+
+		for (i = 0; i < RTE_SECURITY_MACSEC_NUM_AN; i++) {
+			memset(&sa_stat, 0, sizeof(struct rte_security_macsec_sa_stats));
+			rte_security_macsec_sa_stats_get(ctx, rx_sa_id[i],
+					RTE_SECURITY_MACSEC_DIR_RX, &sa_stat);
+
+		}
+	}
+
+	if (op == MCS_ENCAP || op == MCS_ENCAP_DECAP ||
+			op == MCS_AUTH_ONLY || op == MCS_AUTH_VERIFY) {
+		memset(&sess_stats, 0, sizeof(struct rte_security_stats));
+		rte_security_session_stats_get(ctx, tx_sess, &sess_stats);
+		secy_stat = &sess_stats.macsec;
+
+		if (opts->check_out_pkts_untagged && secy_stat->pkt_untagged_cnt != 1)
+			return TEST_FAILED;
+
+		if (opts->check_out_pkts_toolong && secy_stat->pkt_toolong_cnt != 1)
+			return TEST_FAILED;
+
+		if (opts->check_encap_stats && secy_stat->octet_encrypted_cnt !=
+				(uint16_t)(td->plain_pkt.len - 2 * RTE_ETHER_ADDR_LEN))
+			return TEST_FAILED;
+
+		if (opts->check_auth_only_stats && secy_stat->octet_protected_cnt !=
+				(uint16_t)(td->plain_pkt.len - 2 * RTE_ETHER_ADDR_LEN))
+			return TEST_FAILED;
+
+
+		memset(&sc_stat, 0, sizeof(struct rte_security_macsec_sc_stats));
+		rte_security_macsec_sc_stats_get(ctx, tx_sc_id, RTE_SECURITY_MACSEC_DIR_TX,
+						 &sc_stat);
+
+		if (opts->check_encap_stats && sc_stat.pkt_encrypt_cnt != 1)
+			return TEST_FAILED;
+
+		if (opts->check_auth_only_stats && sc_stat.pkt_protected_cnt != 1)
+			return TEST_FAILED;
+
+		memset(&sa_stat, 0, sizeof(struct rte_security_macsec_sa_stats));
+		rte_security_macsec_sa_stats_get(ctx, tx_sa_id[0],
+				RTE_SECURITY_MACSEC_DIR_TX, &sa_stat);
+	}
+
+	return 0;
+}
+
 static int
 test_macsec(const struct mcs_test_vector *td[], enum mcs_op op, const struct mcs_test_opts *opts)
 {
@@ -833,12 +930,23 @@ test_macsec(const struct mcs_test_vector *td[], enum mcs_op op, const struct mcs
 		rx_pkts_burst[i] = NULL;
 	}
 out:
+	if (opts->check_out_pkts_toolong == 1 ||
+			opts->check_sa_not_in_use == 1 ||
+			opts->check_bad_tag_cnt == 1)
+		ret = TEST_SUCCESS;
+
 	for (i = 0; i < opts->nb_td; i++) {
 		if (opts->dump_all_stats) {
 			mcs_stats_dump(ctx, op,
 					rx_sess[i], tx_sess[i],
 					rx_sc_id[i], tx_sc_id[i],
 					rx_sa_id[i], tx_sa_id[i]);
+		} else {
+			if (ret == TEST_SUCCESS)
+				ret = mcs_stats_check(ctx, op, opts, td[i],
+					rx_sess[i], tx_sess[i],
+					rx_sc_id[i], tx_sc_id[i],
+					rx_sa_id[i], tx_sa_id[i]);
 		}
 	}
 
@@ -1182,6 +1290,220 @@ test_inline_macsec_with_vlan(const void *data __rte_unused)
 	return all_err;
 }
 
+static int
+test_inline_macsec_pkt_drop(const void *data __rte_unused)
+{
+	const struct mcs_test_vector *cur_td;
+	struct mcs_test_opts opts = {0};
+	int err, all_err = 0;
+	int i, size;
+
+	opts.val_frames = RTE_SECURITY_MACSEC_VALIDATE_STRICT;
+	opts.encrypt = true;
+	opts.protect_frames = true;
+	opts.sa_in_use = 1;
+	opts.nb_td = 1;
+	opts.sectag_insert_mode = 1;
+	opts.mtu = RTE_ETHER_MTU;
+
+	size = (sizeof(list_mcs_err_cipher_vectors) / sizeof((list_mcs_err_cipher_vectors)[0]));
+
+	for (i = 0; i < size; i++) {
+		cur_td = &list_mcs_err_cipher_vectors[i];
+		err = test_macsec(&cur_td, MCS_DECAP, &opts);
+		if (err) {
+			printf("\nPacket drop case %d passed", cur_td->test_idx);
+			err = 0;
+		} else {
+			printf("\nPacket drop case %d failed", cur_td->test_idx);
+			err = -1;
+		}
+		all_err += err;
+	}
+	printf("\n%s: Success: %d, Failure: %d\n", __func__, size + all_err, -all_err);
+
+	return all_err;
+}
+
+static int
+test_inline_macsec_untagged_rx(const void *data __rte_unused)
+{
+	const struct mcs_test_vector *cur_td;
+	struct mcs_test_opts opts = {0};
+	int err, all_err = 0;
+	int i, size;
+
+	opts.val_frames = RTE_SECURITY_MACSEC_VALIDATE_STRICT;
+	opts.sa_in_use = 1;
+	opts.nb_td = 1;
+	opts.sectag_insert_mode = 1;
+	opts.mtu = RTE_ETHER_MTU;
+	opts.check_untagged_rx = 1;
+
+	size = (sizeof(list_mcs_untagged_cipher_vectors) /
+		sizeof((list_mcs_untagged_cipher_vectors)[0]));
+
+	for (i = 0; i < size; i++) {
+		cur_td = &list_mcs_untagged_cipher_vectors[i];
+		err = test_macsec(&cur_td, MCS_DECAP, &opts);
+		if (err)
+			err = 0;
+		else
+			err = -1;
+
+		all_err += err;
+	}
+
+	opts.val_frames = RTE_SECURITY_MACSEC_VALIDATE_NO_DISCARD;
+	for (i = 0; i < size; i++) {
+		cur_td = &list_mcs_untagged_cipher_vectors[i];
+		err = test_macsec(&cur_td, MCS_DECAP, &opts);
+		if (err)
+			err = 0;
+		else
+			err = -1;
+
+		all_err += err;
+	}
+	printf("\n%s: Success: %d, Failure: %d\n", __func__, size + all_err, -all_err);
+
+	return all_err;
+}
+
+static int
+test_inline_macsec_bad_tag_rx(const void *data __rte_unused)
+{
+	const struct mcs_test_vector *cur_td;
+	struct mcs_test_opts opts = {0};
+	int err, all_err = 0;
+	int i, size;
+
+	opts.val_frames = RTE_SECURITY_MACSEC_VALIDATE_STRICT;
+	opts.protect_frames = true;
+	opts.sa_in_use = 1;
+	opts.nb_td = 1;
+	opts.sectag_insert_mode = 1;
+	opts.mtu = RTE_ETHER_MTU;
+	opts.check_bad_tag_cnt = 1;
+
+	size = (sizeof(list_mcs_bad_tag_vectors) / sizeof((list_mcs_bad_tag_vectors)[0]));
+
+	for (i = 0; i < size; i++) {
+		cur_td = &list_mcs_bad_tag_vectors[i];
+		err = test_macsec(&cur_td, MCS_DECAP, &opts);
+		if (err)
+			err = -1;
+		else
+			err = 0;
+
+		all_err += err;
+	}
+
+	printf("\n%s: Success: %d, Failure: %d\n", __func__, size + all_err, -all_err);
+
+	return all_err;
+}
+
+static int
+test_inline_macsec_sa_not_in_use(const void *data __rte_unused)
+{
+	const struct mcs_test_vector *cur_td;
+	struct mcs_test_opts opts = {0};
+	int err, all_err = 0;
+	int i, size;
+
+	opts.val_frames = RTE_SECURITY_MACSEC_VALIDATE_STRICT;
+	opts.protect_frames = true;
+	opts.sa_in_use = 0;
+	opts.nb_td = 1;
+	opts.sectag_insert_mode = 1;
+	opts.mtu = RTE_ETHER_MTU;
+	opts.check_sa_not_in_use = 1;
+
+	size = (sizeof(list_mcs_cipher_vectors) / sizeof((list_mcs_cipher_vectors)[0]));
+
+	for (i = 0; i < size; i++) {
+		cur_td = &list_mcs_cipher_vectors[i];
+		err = test_macsec(&cur_td, MCS_DECAP, &opts);
+		if (err)
+			err = -1;
+		else
+			err = 0;
+
+		all_err += err;
+	}
+
+	printf("\n%s: Success: %d, Failure: %d\n", __func__, size + all_err, -all_err);
+
+	return all_err;
+}
+
+static int
+test_inline_macsec_out_pkts_untagged(const void *data __rte_unused)
+{
+	const struct mcs_test_vector *cur_td;
+	struct mcs_test_opts opts = {0};
+	int err, all_err = 0;
+	int i, size;
+
+	opts.val_frames = RTE_SECURITY_MACSEC_VALIDATE_STRICT;
+	opts.encrypt = false;
+	opts.protect_frames = false;
+	opts.sa_in_use = 1;
+	opts.nb_td = 1;
+	opts.sectag_insert_mode = 1;
+	opts.mtu = RTE_ETHER_MTU;
+	opts.check_out_pkts_untagged = 1;
+
+	size = (sizeof(list_mcs_cipher_vectors) / sizeof((list_mcs_cipher_vectors)[0]));
+	for (i = 0; i < size; i++) {
+		cur_td = &list_mcs_cipher_vectors[i];
+		err = test_macsec(&cur_td, MCS_ENCAP, &opts);
+		if (err)
+			err = -1;
+		else
+			err = 0;
+
+		all_err += err;
+	}
+
+	printf("\n%s: Success: %d, Failure: %d\n", __func__, size + all_err, -all_err);
+	return all_err;
+}
+
+static int
+test_inline_macsec_out_pkts_toolong(const void *data __rte_unused)
+{
+	const struct mcs_test_vector *cur_td;
+	struct mcs_test_opts opts = {0};
+	int err, all_err = 0;
+	int i, size;
+
+	opts.val_frames = RTE_SECURITY_MACSEC_VALIDATE_NO_DISCARD;
+	opts.encrypt = true;
+	opts.protect_frames = true;
+	opts.sa_in_use = 1;
+	opts.nb_td = 1;
+	opts.sectag_insert_mode = 1;
+	opts.mtu = 50;
+	opts.check_out_pkts_toolong = 1;
+
+	size = (sizeof(list_mcs_cipher_vectors) / sizeof((list_mcs_cipher_vectors)[0]));
+	for (i = 0; i < size; i++) {
+		cur_td = &list_mcs_cipher_vectors[i];
+		err = test_macsec(&cur_td, MCS_ENCAP, &opts);
+		if (err)
+			err = -1;
+		else
+			err = 0;
+
+		all_err += err;
+	}
+
+	printf("\n%s: Success: %d, Failure: %d\n", __func__, size + all_err, -all_err);
+	return all_err;
+}
+
 static int
 ut_setup_inline_macsec(void)
 {
@@ -1359,6 +1681,30 @@ static struct unit_test_suite inline_macsec_testsuite  = {
 			"MACsec Encap and decap with VLAN",
 			ut_setup_inline_macsec, ut_teardown_inline_macsec,
 			test_inline_macsec_with_vlan),
+		TEST_CASE_NAMED_ST(
+			"MACsec packet drop",
+			ut_setup_inline_macsec, ut_teardown_inline_macsec,
+			test_inline_macsec_pkt_drop),
+		TEST_CASE_NAMED_ST(
+			"MACsec untagged Rx",
+			ut_setup_inline_macsec, ut_teardown_inline_macsec,
+			test_inline_macsec_untagged_rx),
+		TEST_CASE_NAMED_ST(
+			"MACsec bad tag Rx",
+			ut_setup_inline_macsec, ut_teardown_inline_macsec,
+			test_inline_macsec_bad_tag_rx),
+		TEST_CASE_NAMED_ST(
+			"MACsec SA not in use",
+			ut_setup_inline_macsec, ut_teardown_inline_macsec,
+			test_inline_macsec_sa_not_in_use),
+		TEST_CASE_NAMED_ST(
+			"MACsec out pkts untagged",
+			ut_setup_inline_macsec, ut_teardown_inline_macsec,
+			test_inline_macsec_out_pkts_untagged),
+		TEST_CASE_NAMED_ST(
+			"MACsec out pkts too long",
+			ut_setup_inline_macsec, ut_teardown_inline_macsec,
+			test_inline_macsec_out_pkts_toolong),
 
 		TEST_CASES_END() /**< NULL terminate unit test array */
 	},
app/test/test_security_inline_macsec_vectors.h +475 -0

481 lines not on this page · raw message

Signature · 1 line
2.25.1
#64 lore raw

PATCH v3 8/13 test/security: verify MACsec stats

In reply to Akhil Goyal

Added cases to verify various stats of MACsec.

---
 app/test/test_security_inline_macsec.c | 222 +++++++++++++++++++++++++
 1 file changed, 222 insertions(+)
app/test/test_security_inline_macsec.c +222 -0
index 2a06f31f37..9cab3253f4 100644
@@ -1438,6 +1438,140 @@ test_inline_macsec_sa_not_in_use(const void *data __rte_unused)
 	return all_err;
 }
 
+static int
+test_inline_macsec_decap_stats(const void *data __rte_unused)
+{
+	const struct mcs_test_vector *cur_td;
+	struct mcs_test_opts opts = {0};
+	int err, all_err = 0;
+	int i, size;
+
+	opts.val_frames = RTE_SECURITY_MACSEC_VALIDATE_STRICT;
+	opts.protect_frames = true;
+	opts.sa_in_use = 1;
+	opts.nb_td = 1;
+	opts.sectag_insert_mode = 1;
+	opts.mtu = RTE_ETHER_MTU;
+	opts.check_decap_stats = 1;
+
+	size = (sizeof(list_mcs_cipher_vectors) / sizeof((list_mcs_cipher_vectors)[0]));
+
+	for (i = 0; i < size; i++) {
+		cur_td = &list_mcs_cipher_vectors[i];
+		err = test_macsec(&cur_td, MCS_DECAP, &opts);
+		if (err) {
+			printf("\nDecap stats case %d failed", cur_td->test_idx);
+			err = -1;
+		} else {
+			printf("\nDecap stats case %d passed", cur_td->test_idx);
+			err = 0;
+		}
+		all_err += err;
+	}
+	printf("\n%s: Success: %d, Failure: %d\n", __func__, size + all_err, -all_err);
+
+	return all_err;
+}
+
+static int
+test_inline_macsec_verify_only_stats(const void *data __rte_unused)
+{
+	const struct mcs_test_vector *cur_td;
+	struct mcs_test_opts opts = {0};
+	int err, all_err = 0;
+	int i, size;
+
+	opts.val_frames = RTE_SECURITY_MACSEC_VALIDATE_STRICT;
+	opts.protect_frames = true;
+	opts.sa_in_use = 1;
+	opts.nb_td = 1;
+	opts.sectag_insert_mode = 1;
+	opts.mtu = RTE_ETHER_MTU;
+	opts.check_verify_only_stats = 1;
+
+	size = (sizeof(list_mcs_integrity_vectors) / sizeof((list_mcs_integrity_vectors)[0]));
+
+	for (i = 0; i < size; i++) {
+		cur_td = &list_mcs_integrity_vectors[i];
+		err = test_macsec(&cur_td, MCS_VERIFY_ONLY, &opts);
+		if (err) {
+			printf("\nVerify only stats case %d failed", cur_td->test_idx);
+			err = -1;
+		} else {
+			printf("\nVerify only stats case %d Passed", cur_td->test_idx);
+			err = 0;
+		}
+		all_err += err;
+	}
+	printf("\n%s: Success: %d, Failure: %d\n", __func__, size + all_err, -all_err);
+
+	return all_err;
+}
+
+static int
+test_inline_macsec_pkts_invalid_stats(const void *data __rte_unused)
+{
+	const struct mcs_test_vector *cur_td;
+	struct mcs_test_opts opts = {0};
+	int err, all_err = 0;
+	int i, size;
+
+	opts.val_frames = RTE_SECURITY_MACSEC_VALIDATE_STRICT;
+	opts.protect_frames = true;
+	opts.sa_in_use = 1;
+	opts.nb_td = 1;
+	opts.sectag_insert_mode = 1;
+	opts.mtu = RTE_ETHER_MTU;
+
+	size = (sizeof(list_mcs_err_cipher_vectors) / sizeof((list_mcs_err_cipher_vectors)[0]));
+
+	for (i = 0; i < size; i++) {
+		cur_td = &list_mcs_err_cipher_vectors[i];
+		err = test_macsec(&cur_td, MCS_DECAP, &opts);
+		if (err)
+			err = 0;
+		else
+			err = -1;
+
+		all_err += err;
+	}
+	printf("\n%s: Success: %d, Failure: %d\n", __func__, size + all_err, -all_err);
+	return all_err;
+}
+
+static int
+test_inline_macsec_pkts_unchecked_stats(const void *data __rte_unused)
+{
+	const struct mcs_test_vector *cur_td;
+	struct mcs_test_opts opts = {0};
+	int err, all_err = 0;
+	int i, size;
+
+	opts.val_frames = RTE_SECURITY_MACSEC_VALIDATE_DISABLE;
+	opts.protect_frames = true;
+	opts.sa_in_use = 1;
+	opts.nb_td = 1;
+	opts.sectag_insert_mode = 1;
+	opts.mtu = RTE_ETHER_MTU;
+	opts.check_pkts_unchecked_stats = 1;
+
+	size = (sizeof(list_mcs_integrity_vectors) / sizeof((list_mcs_integrity_vectors)[0]));
+
+	for (i = 0; i < size; i++) {
+		cur_td = &list_mcs_integrity_vectors[i];
+		err = test_macsec(&cur_td, MCS_VERIFY_ONLY, &opts);
+		if (err)
+			err = -1;
+		else
+			err = 0;
+
+		all_err += err;
+	}
+
+	printf("\n%s: Success: %d, Failure: %d\n", __func__, size + all_err, -all_err);
+	return all_err;
+}
+
 static int
 test_inline_macsec_out_pkts_untagged(const void *data __rte_unused)
 {
@@ -1504,6 +1638,70 @@ test_inline_macsec_out_pkts_toolong(const void *data __rte_unused)
 	return all_err;
 }
 
+static int
+test_inline_macsec_encap_stats(const void *data __rte_unused)
+{
+	const struct mcs_test_vector *cur_td;
+	struct mcs_test_opts opts = {0};
+	int err, all_err = 0;
+	int i, size;
+
+	opts.val_frames = RTE_SECURITY_MACSEC_VALIDATE_STRICT;
+	opts.encrypt = true;
+	opts.protect_frames = true;
+	opts.sa_in_use = 1;
+	opts.nb_td = 1;
+	opts.sectag_insert_mode = 1;
+	opts.mtu = RTE_ETHER_MTU;
+	opts.check_encap_stats = 1;
+
+	size = (sizeof(list_mcs_cipher_vectors) / sizeof((list_mcs_cipher_vectors)[0]));
+	for (i = 0; i < size; i++) {
+		cur_td = &list_mcs_cipher_vectors[i];
+		err = test_macsec(&cur_td, MCS_ENCAP, &opts);
+		if (err)
+			err = -1;
+		else
+			err = 0;
+		all_err += err;
+	}
+
+	printf("\n%s: Success: %d, Failure: %d\n", __func__, size + all_err, -all_err);
+	return all_err;
+}
+
+static int
+test_inline_macsec_auth_only_stats(const void *data __rte_unused)
+{
+	const struct mcs_test_vector *cur_td;
+	struct mcs_test_opts opts = {0};
+	int err, all_err = 0;
+	int i, size;
+
+	opts.val_frames = RTE_SECURITY_MACSEC_VALIDATE_STRICT;
+	opts.protect_frames = true;
+	opts.sa_in_use = 1;
+	opts.nb_td = 1;
+	opts.sectag_insert_mode = 1;
+	opts.mtu = RTE_ETHER_MTU;
+	opts.check_auth_only_stats = 1;
+
+	size = (sizeof(list_mcs_integrity_vectors) / sizeof((list_mcs_integrity_vectors)[0]));
+
+	for (i = 0; i < size; i++) {
+		cur_td = &list_mcs_integrity_vectors[i];
+		err = test_macsec(&cur_td, MCS_AUTH_ONLY, &opts);
+		if (err)
+			err = -1;
+		else
+			err = 0;
+		all_err += err;
+	}
+
+	printf("\n%s: Success: %d, Failure: %d\n", __func__, size + all_err, -all_err);
+	return all_err;
+}
+
 static int
 ut_setup_inline_macsec(void)
 {
@@ -1697,6 +1895,22 @@ static struct unit_test_suite inline_macsec_testsuite  = {
 			"MACsec SA not in use",
 			ut_setup_inline_macsec, ut_teardown_inline_macsec,
 			test_inline_macsec_sa_not_in_use),
+		TEST_CASE_NAMED_ST(
+			"MACsec decap stats",
+			ut_setup_inline_macsec, ut_teardown_inline_macsec,
+			test_inline_macsec_decap_stats),
+		TEST_CASE_NAMED_ST(
+			"MACsec verify only stats",
+			ut_setup_inline_macsec, ut_teardown_inline_macsec,
+			test_inline_macsec_verify_only_stats),
+		TEST_CASE_NAMED_ST(
+			"MACsec pkts invalid stats",
+			ut_setup_inline_macsec, ut_teardown_inline_macsec,
+			test_inline_macsec_pkts_invalid_stats),
+		TEST_CASE_NAMED_ST(
+			"MACsec pkts unchecked stats",
+			ut_setup_inline_macsec, ut_teardown_inline_macsec,
+			test_inline_macsec_pkts_unchecked_stats),
 		TEST_CASE_NAMED_ST(
 			"MACsec out pkts untagged",
 			ut_setup_inline_macsec, ut_teardown_inline_macsec,
@@ -1705,6 +1919,14 @@ static struct unit_test_suite inline_macsec_testsuite  = {
 			"MACsec out pkts too long",
 			ut_setup_inline_macsec, ut_teardown_inline_macsec,
 			test_inline_macsec_out_pkts_toolong),
+		TEST_CASE_NAMED_ST(
+			"MACsec Encap stats",
+			ut_setup_inline_macsec, ut_teardown_inline_macsec,
+			test_inline_macsec_encap_stats),
+		TEST_CASE_NAMED_ST(
+			"MACsec auth only stats",
+			ut_setup_inline_macsec, ut_teardown_inline_macsec,
+			test_inline_macsec_auth_only_stats),
 
 		TEST_CASES_END() /**< NULL terminate unit test array */
 	},
Signature · 1 line
2.25.1
#65 lore raw

PATCH v3 9/13 test/security: verify MACsec interrupts

In reply to Akhil Goyal

From: Ankur Dwivedi <[email protected]>

This patch enables the test_inline_macsec_interrupts_all test case for MACSEC.

---
 app/test/test_security_inline_macsec.c        | 124 +++++++
 .../test_security_inline_macsec_vectors.h     | 306 +++++++++++++++++-
 2 files changed, 429 insertions(+), 1 deletion(-)
app/test/test_security_inline_macsec.c +124 -0
index 9cab3253f4..12e3234cfb 100644
@@ -757,6 +757,71 @@ mcs_stats_check(struct rte_security_ctx *ctx, enum mcs_op op,
 	return 0;
 }
 
+static int
+test_macsec_event_callback(uint16_t port_id, enum rte_eth_event_type type,
+			   void *param, void *ret_param)
+{
+	struct mcs_err_vector *vector = (struct mcs_err_vector *)param;
+	struct rte_eth_event_macsec_desc *event_desc = NULL;
+
+	RTE_SET_USED(port_id);
+
+	if (type != RTE_ETH_EVENT_MACSEC)
+		return -1;
+
+	event_desc = ret_param;
+	if (event_desc == NULL) {
+		printf("Event descriptor not set\n");
+		return -1;
+	}
+	vector->notify_event = true;
+
+	switch (event_desc->type) {
+	case RTE_ETH_EVENT_MACSEC_SECTAG_VAL_ERR:
+		vector->event = RTE_ETH_EVENT_MACSEC_SECTAG_VAL_ERR;
+		switch (event_desc->subtype) {
+		case RTE_ETH_SUBEVENT_MACSEC_RX_SECTAG_V_EQ1:
+			vector->event_subtype = RTE_ETH_SUBEVENT_MACSEC_RX_SECTAG_V_EQ1;
+			break;
+		case RTE_ETH_SUBEVENT_MACSEC_RX_SECTAG_E_EQ0_C_EQ1:
+			vector->event_subtype = RTE_ETH_SUBEVENT_MACSEC_RX_SECTAG_E_EQ0_C_EQ1;
+			break;
+		case RTE_ETH_SUBEVENT_MACSEC_RX_SECTAG_SL_GTE48:
+			vector->event_subtype = RTE_ETH_SUBEVENT_MACSEC_RX_SECTAG_SL_GTE48;
+			break;
+		case RTE_ETH_SUBEVENT_MACSEC_RX_SECTAG_ES_EQ1_SC_EQ1:
+			vector->event_subtype = RTE_ETH_SUBEVENT_MACSEC_RX_SECTAG_ES_EQ1_SC_EQ1;
+			break;
+		case RTE_ETH_SUBEVENT_MACSEC_RX_SECTAG_SC_EQ1_SCB_EQ1:
+			vector->event_subtype = RTE_ETH_SUBEVENT_MACSEC_RX_SECTAG_SC_EQ1_SCB_EQ1;
+			break;
+		default:
+			printf("\nUnknown Macsec event subtype: %d", event_desc->subtype);
+		}
+		break;
+	case RTE_ETH_EVENT_MACSEC_RX_SA_PN_HARD_EXP:
+		vector->event = RTE_ETH_EVENT_MACSEC_RX_SA_PN_HARD_EXP;
+		break;
+	case RTE_ETH_EVENT_MACSEC_RX_SA_PN_SOFT_EXP:
+		vector->event = RTE_ETH_EVENT_MACSEC_RX_SA_PN_SOFT_EXP;
+		break;
+	case RTE_ETH_EVENT_MACSEC_TX_SA_PN_HARD_EXP:
+		vector->event = RTE_ETH_EVENT_MACSEC_TX_SA_PN_HARD_EXP;
+		break;
+	case RTE_ETH_EVENT_MACSEC_TX_SA_PN_SOFT_EXP:
+		vector->event = RTE_ETH_EVENT_MACSEC_TX_SA_PN_SOFT_EXP;
+		break;
+	case RTE_ETH_EVENT_MACSEC_SA_NOT_VALID:
+		vector->event = RTE_ETH_EVENT_MACSEC_SA_NOT_VALID;
+		break;
+	default:
+		printf("Invalid MACsec event reported\n");
+		return -1;
+	}
+
+	return 0;
+}
+
 static int
 test_macsec(const struct mcs_test_vector *td[], enum mcs_op op, const struct mcs_test_opts *opts)
 {
@@ -914,6 +979,8 @@ test_macsec(const struct mcs_test_vector *td[], enum mcs_op op, const struct mcs
 		while (--nb_rx >= 0)
 			rte_pktmbuf_free(rx_pkts_burst[nb_rx]);
 		ret = TEST_FAILED;
+		if (opts->check_sectag_interrupts == 1)
+			ret = TEST_SUCCESS;
 		goto out;
 	}
 
@@ -1702,6 +1769,59 @@ test_inline_macsec_auth_only_stats(const void *data __rte_unused)
 	return all_err;
 }
 
+static int
+test_inline_macsec_interrupts_all(const void *data __rte_unused)
+{
+	struct mcs_err_vector err_vector = {0};
+	const struct mcs_test_vector *cur_td;
+	struct mcs_test_opts opts = {0};
+	int i, size;
+	int err, all_err = 0;
+	enum rte_eth_event_macsec_subtype subtype[] =  {
+		RTE_ETH_SUBEVENT_MACSEC_RX_SECTAG_V_EQ1,
+		RTE_ETH_SUBEVENT_MACSEC_RX_SECTAG_E_EQ0_C_EQ1,
+		RTE_ETH_SUBEVENT_MACSEC_RX_SECTAG_SL_GTE48,
+		RTE_ETH_SUBEVENT_MACSEC_RX_SECTAG_ES_EQ1_SC_EQ1,
+		RTE_ETH_SUBEVENT_MACSEC_RX_SECTAG_SC_EQ1_SCB_EQ1,
+	};
+
+	opts.val_frames = RTE_SECURITY_MACSEC_VALIDATE_STRICT;
+	opts.protect_frames = true;
+	opts.sa_in_use = 1;
+	opts.nb_td = 1;
+	opts.sectag_insert_mode = 1;
+	opts.mtu = RTE_ETHER_MTU;
+	opts.check_sectag_interrupts = 1;
+
+	err_vector.event = RTE_ETH_EVENT_MACSEC_UNKNOWN;
+	err_vector.event_subtype = RTE_ETH_SUBEVENT_MACSEC_UNKNOWN;
+	rte_eth_dev_callback_register(port_id, RTE_ETH_EVENT_MACSEC,
+			test_macsec_event_callback, &err_vector);
+
+	size = (sizeof(list_mcs_intr_test_vectors) / sizeof((list_mcs_intr_test_vectors)[0]));
+
+	for (i = 0; i < size; i++) {
+		cur_td = &list_mcs_intr_test_vectors[i];
+		err = test_macsec(&cur_td, MCS_DECAP, &opts);
+		if ((err_vector.event == RTE_ETH_EVENT_MACSEC_SECTAG_VAL_ERR) &&
+		    (err_vector.event_subtype == subtype[i])) {
+			printf("\nSectag val err interrupt test case %d passed",
+			       cur_td->test_idx);
+			err = 0;
+		} else {
+			printf("\nSectag val err interrupt test case %d failed",
+			       cur_td->test_idx);
+			err = -1;
+		}
+		all_err += err;
+	}
+	rte_eth_dev_callback_unregister(port_id, RTE_ETH_EVENT_MACSEC,
+			test_macsec_event_callback, &err_vector);
+
+	printf("\n%s: Success: %d, Failure: %d\n", __func__, size + all_err, -all_err);
+	return all_err;
+}
+
 static int
 ut_setup_inline_macsec(void)
 {
@@ -1927,6 +2047,10 @@ static struct unit_test_suite inline_macsec_testsuite  = {
 			"MACsec auth only stats",
 			ut_setup_inline_macsec, ut_teardown_inline_macsec,
 			test_inline_macsec_auth_only_stats),
+		TEST_CASE_NAMED_ST(
+			"MACsec interrupts all",
+			ut_setup_inline_macsec, ut_teardown_inline_macsec,
+			test_inline_macsec_interrupts_all),
 
 		TEST_CASES_END() /**< NULL terminate unit test array */
 	},
app/test/test_security_inline_macsec_vectors.h +305 -1

317 lines not on this page · raw message

Signature · 1 line
2.25.1
#66 lore raw

PATCH v3 10/13 test/security: verify MACsec Tx HW rekey

In reply to Akhil Goyal

This patch enables the Tx HW rekey test case for MACSEC.

---
 app/test/test_security_inline_macsec.c        | 137 +++++++++-
 .../test_security_inline_macsec_vectors.h     | 243 ++++++++++++++++++
 2 files changed, 378 insertions(+), 2 deletions(-)
app/test/test_security_inline_macsec.c +135 -2
index 12e3234cfb..2172f61199 100644
@@ -207,6 +207,8 @@ fill_macsec_sc_conf(const struct mcs_test_vector *td,
 	uint8_t i;
 
 	sc_conf->dir = dir;
+	sc_conf->pn_threshold = ((uint64_t)td->xpn << 32) |
+		rte_be_to_cpu_32(*(const uint32_t *)(&td->secure_pkt.data[tci_off + 2]));
 	if (dir == RTE_SECURITY_MACSEC_DIR_TX) {
 		sc_conf->sc_tx.sa_id = sa_id[0];
 		if (sa_id[1] != MCS_INVALID_SA) {
@@ -232,12 +234,16 @@ fill_macsec_sc_conf(const struct mcs_test_vector *td,
 			/* use some default SCI */
 			sc_conf->sc_tx.sci = 0xf1341e023a2b1c5d;
 		}
+		if (td->xpn > 0)
+			sc_conf->sc_tx.is_xpn = 1;
 	} else {
 		for (i = 0; i < RTE_SECURITY_MACSEC_NUM_AN; i++) {
 			sc_conf->sc_rx.sa_id[i] = sa_id[i];
 			sc_conf->sc_rx.sa_in_use[i] = opts->sa_in_use;
 		}
 		sc_conf->sc_rx.active = 1;
+		if (td->xpn > 0)
+			sc_conf->sc_rx.is_xpn = 1;
 	}
 }
 
@@ -834,6 +840,7 @@ test_macsec(const struct mcs_test_vector *td[], enum mcs_op op, const struct mcs
 	struct rte_security_session_conf sess_conf = {0};
 	struct rte_security_macsec_sa sa_conf = {0};
 	struct rte_security_macsec_sc sc_conf = {0};
+	struct mcs_err_vector err_vector = {0};
 	struct rte_security_ctx *ctx;
 	int nb_rx = 0, nb_sent;
 	int i, j = 0, ret, id, an = 0;
@@ -868,6 +875,34 @@ test_macsec(const struct mcs_test_vector *td[], enum mcs_op op, const struct mcs
 		}
 		j++;
 
+		if (opts->rekey_en) {
+
+			err_vector.td = td[i];
+			err_vector.rekey_td = opts->rekey_td;
+			err_vector.event = RTE_ETH_EVENT_MACSEC_UNKNOWN;
+			err_vector.event_subtype = RTE_ETH_SUBEVENT_MACSEC_UNKNOWN;
+			rte_eth_dev_callback_register(port_id, RTE_ETH_EVENT_MACSEC,
+					test_macsec_event_callback, &err_vector);
+			if (op == MCS_DECAP || op == MCS_VERIFY_ONLY)
+				tx_pkts_burst[j] = init_packet(mbufpool,
+						opts->rekey_td->secure_pkt.data,
+						opts->rekey_td->secure_pkt.len);
+			else {
+				tx_pkts_burst[j] = init_packet(mbufpool,
+						opts->rekey_td->plain_pkt.data,
+						opts->rekey_td->plain_pkt.len);
+
+				tx_pkts_burst[j]->ol_flags |= RTE_MBUF_F_TX_MACSEC;
+			}
+			if (tx_pkts_burst[j] == NULL) {
+				while (j--)
+					rte_pktmbuf_free(tx_pkts_burst[j]);
+				ret = TEST_FAILED;
+				goto out;
+			}
+			j++;
+		}
+
 		if (op == MCS_DECAP || op == MCS_ENCAP_DECAP ||
 				op == MCS_VERIFY_ONLY || op == MCS_AUTH_VERIFY) {
 			for (an = 0; an < RTE_SECURITY_MACSEC_NUM_AN; an++) {
@@ -922,6 +957,20 @@ test_macsec(const struct mcs_test_vector *td[], enum mcs_op op, const struct mcs
 			}
 			tx_sa_id[i][0] = (uint16_t)id;
 			tx_sa_id[i][1] = MCS_INVALID_SA;
+			if (opts->rekey_en) {
+				memset(&sa_conf, 0, sizeof(struct rte_security_macsec_sa));
+				fill_macsec_sa_conf(opts->rekey_td, &sa_conf,
+					RTE_SECURITY_MACSEC_DIR_TX,
+					opts->rekey_td->secure_pkt.data[tci_off] &
+						RTE_MACSEC_AN_MASK,
+					tci_off);
+				id = rte_security_macsec_sa_create(ctx, &sa_conf);
+				if (id < 0) {
+					printf("MACsec rekey SA create failed : %d.\n", id);
+					goto out;
+				}
+				tx_sa_id[i][1] = (uint16_t)id;
+			}
 			fill_macsec_sc_conf(td[i], &sc_conf, opts,
 					RTE_SECURITY_MACSEC_DIR_TX, tx_sa_id[i], tci_off);
 			id = rte_security_macsec_sc_create(ctx, &sc_conf);
@@ -984,9 +1033,44 @@ test_macsec(const struct mcs_test_vector *td[], enum mcs_op op, const struct mcs
 		goto out;
 	}
 
+	if (opts->rekey_en) {
+		switch (err_vector.event) {
+		case RTE_ETH_EVENT_MACSEC_TX_SA_PN_SOFT_EXP:
+			printf("Received RTE_ETH_EVENT_MACSEC_TX_SA_PN_SOFT_EXP event\n");
+			/* The first sa is active now, so the 0th sa can be
+			 * reconfigured. Using the same key as zeroeth sa, but
+			 * other key can also be configured.
+			 */
+			rte_security_macsec_sa_destroy(ctx, tx_sa_id[0][0],
+					RTE_SECURITY_MACSEC_DIR_TX);
+			fill_macsec_sa_conf(td[0], &sa_conf,
+					RTE_SECURITY_MACSEC_DIR_TX,
+					td[0]->secure_pkt.data[tci_off] &
+					RTE_MACSEC_AN_MASK, tci_off);
+			id = rte_security_macsec_sa_create(ctx, &sa_conf);
+			if (id < 0) {
+				printf("MACsec SA create failed : %d.\n", id);
+				return TEST_FAILED;
+			}
+			tx_sa_id[0][0] = (uint16_t)id;
+			break;
+		default:
+			printf("Received unsupported event\n");
+		}
+	}
+
 	for (i = 0; i < nb_rx; i++) {
-		ret = test_macsec_post_process(rx_pkts_burst[i], td[i], op,
-				opts->check_out_pkts_untagged);
+		if (opts->rekey_en && i == 1) {
+			/* The second received packet is matched with
+			 * rekey td
+			 */
+			ret = test_macsec_post_process(rx_pkts_burst[i],
+					opts->rekey_td, op,
+					opts->check_out_pkts_untagged);
+		} else {
+			ret = test_macsec_post_process(rx_pkts_burst[i], td[i],
+					op, opts->check_out_pkts_untagged);
+		}
 		if (ret != TEST_SUCCESS) {
 			for ( ; i < nb_rx; i++)
 				rte_pktmbuf_free(rx_pkts_burst[i]);
@@ -1019,6 +1103,10 @@ test_macsec(const struct mcs_test_vector *td[], enum mcs_op op, const struct mcs
 
 	destroy_default_flow(port_id);
 
+	if (opts->rekey_en)
+		rte_eth_dev_callback_unregister(port_id, RTE_ETH_EVENT_MACSEC,
+					test_macsec_event_callback, &err_vector);
+
 	/* Destroy session so that other cases can create the session again */
 	for (i = 0; i < opts->nb_td; i++) {
 		if (op == MCS_ENCAP || op == MCS_ENCAP_DECAP ||
@@ -1029,6 +1117,10 @@ test_macsec(const struct mcs_test_vector *td[], enum mcs_op op, const struct mcs
 						RTE_SECURITY_MACSEC_DIR_TX);
 			rte_security_macsec_sa_destroy(ctx, tx_sa_id[i][0],
 						RTE_SECURITY_MACSEC_DIR_TX);
+			if (opts->rekey_en) {
+				rte_security_macsec_sa_destroy(ctx, tx_sa_id[i][1],
+						RTE_SECURITY_MACSEC_DIR_TX);
+			}
 		}
 		if (op == MCS_DECAP || op == MCS_ENCAP_DECAP ||
 				op == MCS_VERIFY_ONLY || op == MCS_AUTH_VERIFY) {
@@ -1822,6 +1914,43 @@ test_inline_macsec_interrupts_all(const void *data __rte_unused)
 	return all_err;
 }
 
+static int
+test_inline_macsec_rekey_tx(const void *data __rte_unused)
+{
+	const struct mcs_test_vector *cur_td;
+	struct mcs_test_opts opts = {0};
+	int err, all_err = 0;
+	int i, size;
+
+	opts.val_frames = RTE_SECURITY_MACSEC_VALIDATE_STRICT;
+	opts.protect_frames = true;
+	opts.encrypt = true;
+	opts.sa_in_use = 1;
+	opts.nb_td = 1;
+	opts.sectag_insert_mode = 1;
+	opts.mtu = RTE_ETHER_MTU;
+	opts.rekey_en = 1;
+
+	size = (sizeof(list_mcs_rekey_vectors) / sizeof((list_mcs_rekey_vectors)[0]));
+
+	for (i = 0; i < size; i++) {
+		cur_td = &list_mcs_rekey_vectors[i];
+		opts.rekey_td = &list_mcs_rekey_vectors[++i];
+		err = test_macsec(&cur_td, MCS_ENCAP, &opts);
+		if (err) {
+			printf("Tx hw rekey test case %d failed\n", i);
+			err = -1;
+		} else {
+			printf("Tx hw rekey test case %d passed\n", i);
+			err = 0;
+		}
+		all_err += err;
+	}
+
+	printf("\n%s: Success: %d, Failure: %d\n", __func__, size + all_err, -all_err);
+	return all_err;
+}
+
 static int
 ut_setup_inline_macsec(void)
 {
@@ -2051,6 +2180,10 @@ static struct unit_test_suite inline_macsec_testsuite  = {
 			"MACsec interrupts all",
 			ut_setup_inline_macsec, ut_teardown_inline_macsec,
 			test_inline_macsec_interrupts_all),
+		TEST_CASE_NAMED_ST(
+			"MACsec re-key Tx",
+			ut_setup_inline_macsec, ut_teardown_inline_macsec,
+			test_inline_macsec_rekey_tx),
 
 		TEST_CASES_END() /**< NULL terminate unit test array */
 	},
app/test/test_security_inline_macsec_vectors.h +243 -0

253 lines not on this page · raw message

Signature · 1 line
2.25.1
#67 lore raw

PATCH v3 11/13 test/security: verify MACsec Rx rekey

In reply to Akhil Goyal

From: Ankur Dwivedi <[email protected]>

This patch enables the Rx rekey test case for MACSEC.

---
 app/test/test_security_inline_macsec.c | 50 +++++++++++++++++++++++++-
 1 file changed, 49 insertions(+), 1 deletion(-)
app/test/test_security_inline_macsec.c +49 -1
index 2172f61199..d832dfc170 100644
@@ -906,8 +906,14 @@ test_macsec(const struct mcs_test_vector *td[], enum mcs_op op, const struct mcs
 		if (op == MCS_DECAP || op == MCS_ENCAP_DECAP ||
 				op == MCS_VERIFY_ONLY || op == MCS_AUTH_VERIFY) {
 			for (an = 0; an < RTE_SECURITY_MACSEC_NUM_AN; an++) {
+				if (opts->rekey_en && an ==
+						(opts->rekey_td->secure_pkt.data[tci_off] &
+						RTE_MACSEC_AN_MASK))
+					fill_macsec_sa_conf(opts->rekey_td, &sa_conf,
+						RTE_SECURITY_MACSEC_DIR_RX, an, tci_off);
+				else
 				/* For simplicity, using same SA conf for all AN */
-				fill_macsec_sa_conf(td[i], &sa_conf,
+					fill_macsec_sa_conf(td[i], &sa_conf,
 						RTE_SECURITY_MACSEC_DIR_RX, an, tci_off);
 				id = rte_security_macsec_sa_create(ctx, &sa_conf);
 				if (id < 0) {
@@ -1054,6 +1060,9 @@ test_macsec(const struct mcs_test_vector *td[], enum mcs_op op, const struct mcs
 			}
 			tx_sa_id[0][0] = (uint16_t)id;
 			break;
+		case RTE_ETH_EVENT_MACSEC_RX_SA_PN_SOFT_EXP:
+			printf("Received RTE_ETH_EVENT_MACSEC_RX_SA_PN_SOFT_EXP event\n");
+			break;
 		default:
 			printf("Received unsupported event\n");
 		}
@@ -1951,6 +1960,41 @@ test_inline_macsec_rekey_tx(const void *data __rte_unused)
 	return all_err;
 }
 
+static int
+test_inline_macsec_rekey_rx(const void *data __rte_unused)
+{
+	const struct mcs_test_vector *cur_td;
+	struct mcs_test_opts opts = {0};
+	int err, all_err = 0;
+	int i, size;
+
+	opts.val_frames = RTE_SECURITY_MACSEC_VALIDATE_STRICT;
+	opts.protect_frames = true;
+	opts.sa_in_use = 1;
+	opts.nb_td = 1;
+	opts.sectag_insert_mode = 1;
+	opts.mtu = RTE_ETHER_MTU;
+	opts.rekey_en = 1;
+
+	size = (sizeof(list_mcs_rekey_vectors) / sizeof((list_mcs_rekey_vectors)[0]));
+	for (i = 0; i < size; i++) {
+		cur_td = &list_mcs_rekey_vectors[i];
+		opts.rekey_td = &list_mcs_rekey_vectors[++i];
+		err = test_macsec(&cur_td, MCS_DECAP, &opts);
+		if (err) {
+			printf("Rx rekey test case %d failed\n", i);
+			err = -1;
+		} else {
+			printf("Rx rekey test case %d passed\n", i);
+			err = 0;
+		}
+		all_err += err;
+	}
+
+	printf("\n%s: Success: %d, Failure: %d\n", __func__, size + all_err, -all_err);
+	return all_err;
+}
+
 static int
 ut_setup_inline_macsec(void)
 {
@@ -2184,6 +2228,10 @@ static struct unit_test_suite inline_macsec_testsuite  = {
 			"MACsec re-key Tx",
 			ut_setup_inline_macsec, ut_teardown_inline_macsec,
 			test_inline_macsec_rekey_tx),
+		TEST_CASE_NAMED_ST(
+			"MACsec re-key Rx",
+			ut_setup_inline_macsec, ut_teardown_inline_macsec,
+			test_inline_macsec_rekey_rx),
 
 		TEST_CASES_END() /**< NULL terminate unit test array */
 	},
Signature · 1 line
2.25.1
#68 lore raw

PATCH v3 12/13 test/security: verify MACsec anti replay

In reply to Akhil Goyal

From: Ankur Dwivedi <[email protected]>

This patch enables anti replay test case for MACsec.

---
 app/test/test_security_inline_macsec.c        |  82 +++
 .../test_security_inline_macsec_vectors.h     | 467 ++++++++++++++++++
 2 files changed, 549 insertions(+)
app/test/test_security_inline_macsec.c +82 -0
index d832dfc170..f7fb1b6fd6 100644
@@ -61,6 +61,7 @@ struct mcs_test_opts {
 	uint8_t replay_protect;
 	uint8_t rekey_en;
 	const struct mcs_test_vector *rekey_td;
+	const struct mcs_test_vector *ar_td[3];
 	bool dump_all_stats;
 	uint8_t check_untagged_rx;
 	uint8_t check_bad_tag_cnt;
@@ -716,6 +717,15 @@ mcs_stats_check(struct rte_security_ctx *ctx, enum mcs_op op,
 		if (opts->check_pkts_unchecked_stats && sc_stat.pkt_unchecked_cnt != 1)
 			return TEST_FAILED;
 
+		if (opts->replay_protect) {
+			if (opts->replay_win_sz == 0 &&
+					sc_stat.pkt_late_cnt != 2)
+				return TEST_FAILED;
+			else if (opts->replay_win_sz == 32 &&
+					sc_stat.pkt_late_cnt != 1)
+				return TEST_FAILED;
+		}
+
 		for (i = 0; i < RTE_SECURITY_MACSEC_NUM_AN; i++) {
 			memset(&sa_stat, 0, sizeof(struct rte_security_macsec_sa_stats));
 			rte_security_macsec_sa_stats_get(ctx, rx_sa_id[i],
@@ -845,6 +855,7 @@ test_macsec(const struct mcs_test_vector *td[], enum mcs_op op, const struct mcs
 	int nb_rx = 0, nb_sent;
 	int i, j = 0, ret, id, an = 0;
 	uint8_t tci_off;
+	int k;
 
 	memset(rx_pkts_burst, 0, sizeof(rx_pkts_burst[0]) * opts->nb_td);
 
@@ -875,6 +886,20 @@ test_macsec(const struct mcs_test_vector *td[], enum mcs_op op, const struct mcs
 		}
 		j++;
 
+		if (opts->replay_protect) {
+			for (k = 0; k < 3; k++, j++) {
+				tx_pkts_burst[j] = init_packet(mbufpool,
+					opts->ar_td[k]->secure_pkt.data,
+					opts->ar_td[k]->secure_pkt.len);
+				if (tx_pkts_burst[j] == NULL) {
+					while (j--)
+						rte_pktmbuf_free(tx_pkts_burst[j]);
+					ret = TEST_FAILED;
+					goto out;
+				}
+			}
+		}
+
 		if (opts->rekey_en) {
 
 			err_vector.td = td[i];
@@ -1068,6 +1093,15 @@ test_macsec(const struct mcs_test_vector *td[], enum mcs_op op, const struct mcs
 		}
 	}
 
+	if (opts->replay_protect) {
+		for (i = 0; i < nb_rx; i++) {
+			rte_pktmbuf_free(rx_pkts_burst[i]);
+			rx_pkts_burst[i] = NULL;
+		}
+		ret = TEST_SUCCESS;
+		goto out;
+	}
+
 	for (i = 0; i < nb_rx; i++) {
 		if (opts->rekey_en && i == 1) {
 			/* The second received packet is matched with
@@ -1995,6 +2029,50 @@ test_inline_macsec_rekey_rx(const void *data __rte_unused)
 	return all_err;
 }
 
+static int
+test_inline_macsec_anti_replay(const void *data __rte_unused)
+{
+	const struct mcs_test_vector *cur_td;
+	struct mcs_test_opts opts = {0};
+	uint16_t replay_win_sz[2] = {32, 0};
+	int err, all_err = 0;
+	int i, size;
+	int j;
+
+	opts.val_frames = RTE_SECURITY_MACSEC_VALIDATE_STRICT;
+	opts.sa_in_use = 1;
+	opts.nb_td = 1;
+	opts.sectag_insert_mode = 1;
+	opts.replay_protect = 1;
+
+	size = (sizeof(list_mcs_anti_replay_vectors) / sizeof((list_mcs_anti_replay_vectors)[0]));
+
+	for (j = 0; j < 2; j++) {
+		opts.replay_win_sz = replay_win_sz[j];
+
+		for (i = 0; i < size; i++) {
+			cur_td = &list_mcs_anti_replay_vectors[i];
+			opts.ar_td[0] = &list_mcs_anti_replay_vectors[++i];
+			opts.ar_td[1] = &list_mcs_anti_replay_vectors[++i];
+			opts.ar_td[2] = &list_mcs_anti_replay_vectors[++i];
+			err = test_macsec(&cur_td, MCS_DECAP, &opts);
+			if (err) {
+				printf("Replay window: %u, Anti replay test case %d failed\n",
+				       opts.replay_win_sz, i);
+				err = -1;
+			} else {
+				printf("Replay window: %u, Anti replay test case %d passed\n",
+				       opts.replay_win_sz, i);
+				err = 0;
+			}
+			all_err += err;
+		}
+	}
+
+	printf("\n%s: Success: %d, Failure: %d\n", __func__, size + all_err, -all_err);
+	return all_err;
+}
+
 static int
 ut_setup_inline_macsec(void)
 {
@@ -2232,6 +2310,10 @@ static struct unit_test_suite inline_macsec_testsuite  = {
 			"MACsec re-key Rx",
 			ut_setup_inline_macsec, ut_teardown_inline_macsec,
 			test_inline_macsec_rekey_rx),
+		TEST_CASE_NAMED_ST(
+			"MACsec anti-replay",
+			ut_setup_inline_macsec, ut_teardown_inline_macsec,
+			test_inline_macsec_anti_replay),
 
 		TEST_CASES_END() /**< NULL terminate unit test array */
 	},
app/test/test_security_inline_macsec_vectors.h +467 -0

471 lines not on this page · raw message

Signature · 1 line
2.25.1
#69 lore raw

PATCH v3 13/13 test/security: remove no MACsec support case

In reply to Akhil Goyal

Removed the test_capability_get_no_support_for_macsec case as MACsec is now supported and capability can have valid MACsec support.

---
 app/test/test_security.c | 37 -------------------------------------
 1 file changed, 37 deletions(-)
app/test/test_security.c +0 -37
index e4ddcefe40..4783cd0663 100644
@@ -1828,41 +1828,6 @@ test_capability_get_no_matching_protocol(void)
 	return TEST_SUCCESS;
 }
 
-/**
- * Test execution of rte_security_capability_get when macsec protocol
- * is searched and capabilities table contain proper entry.
- * However macsec records search is not supported in rte_security.
- */
-static int
-test_capability_get_no_support_for_macsec(void)
-{
-	struct security_unittest_params *ut_params = &unittest_params;
-	struct rte_security_capability_idx idx = {
-		.action = RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL,
-		.protocol = RTE_SECURITY_PROTOCOL_MACSEC,
-	};
-	struct rte_security_capability capabilities[] = {
-		{
-			.action = RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL,
-			.protocol = RTE_SECURITY_PROTOCOL_MACSEC,
-		},
-		{
-			.action = RTE_SECURITY_ACTION_TYPE_NONE,
-		},
-	};
-
-	mock_capabilities_get_exp.device = NULL;
-	mock_capabilities_get_exp.ret = capabilities;
-
-	const struct rte_security_capability *ret;
-	ret = rte_security_capability_get(&ut_params->ctx, &idx);
-	TEST_ASSERT_MOCK_FUNCTION_CALL_RET(rte_security_capability_get,
-			ret, NULL, "%p");
-	TEST_ASSERT_MOCK_CALLS(mock_capabilities_get_exp, 1);
-
-	return TEST_SUCCESS;
-}
-
 /**
  * Test execution of rte_security_capability_get when capabilities table
  * does not contain entry with matching ipsec proto field
@@ -2319,8 +2284,6 @@ static struct unit_test_suite security_testsuite  = {
 				test_capability_get_no_matching_action),
 		TEST_CASE_ST(ut_setup_with_session, ut_teardown,
 				test_capability_get_no_matching_protocol),
-		TEST_CASE_ST(ut_setup_with_session, ut_teardown,
-				test_capability_get_no_support_for_macsec),
 		TEST_CASE_ST(ut_setup_with_session, ut_teardown,
 				test_capability_get_ipsec_mismatch_proto),
 		TEST_CASE_ST(ut_setup_with_session, ut_teardown,
Signature · 1 line
2.25.1
#70 lore raw

RE: [PATCH v3 00/13] Add MACsec unit test cases

In reply to Akhil Goyal
Quoted 11 lines

Subject: [PATCH v3 00/13] Add MACsec unit test cases

Inline MACsec offload was supported in DPDK 22.11
using rte_security APIs.
This patchset adds few minor changes in the rte_security APIs to specify the direction of SA/SC and update the SC configuration to set packet number threshold.

The patchset also add functional test cases in dpdk-test app to verify MACsec functionality.

Quoted 7 lines

This patchset is pending from last release [1] due to lack of hardware to test. Now the test cases are verified on Marvell cnxk PMD and the pmd support is added as a separate patchset.

[1] https://patches.dpdk.org/project/dpdk/cover/20220928124516.93050-1-
[email protected]/

Patchset applied to dpdk-next-crypto

#71 lore raw

PATCH 5/5 test/security: add more MACsec cases

In reply to Akhil Goyal

Added more cases related to decap and auth + cipher.

---
 app/test/test_security_inline_macsec.c        | 305 +++++++++++++++++
 .../test_security_inline_macsec_vectors.h     | 321 ++++++++++++++++++
 2 files changed, 626 insertions(+)
app/test/test_security_inline_macsec.c +305 -0
index dec7cb20df..6d19a9377d 100644
@@ -655,6 +655,283 @@ test_inline_macsec_encap_all(const void *data __rte_unused)
 	return all_err;
 }
 
+static int
+test_inline_macsec_decap_all(const void *data __rte_unused)
+{
+	const struct mcs_test_vector *cur_td;
+	struct mcs_test_opts opts = {0};
+	int err, all_err = 0;
+	int i, size;
+
+	opts.val_frames = RTE_SECURITY_MACSEC_VALIDATE_STRICT;
+	opts.sa_in_use = 1;
+	opts.nb_td = 1;
+	opts.sectag_insert_mode = 1;
+	opts.mtu = RTE_ETHER_MTU;
+
+	size = (sizeof(list_mcs_cipher_vectors) / sizeof((list_mcs_cipher_vectors)[0]));
+
+	for (i = 0; i < size; i++) {
+		cur_td = &list_mcs_cipher_vectors[i];
+		err = test_macsec(&cur_td, MCS_DECAP, &opts);
+		if (err) {
+			printf("\nCipher Auth Decryption case %d failed", cur_td->test_idx);
+			err = -1;
+		} else {
+			printf("\nCipher Auth Decryption case %d Passed", cur_td->test_idx);
+			err = 0;
+		}
+		all_err += err;
+	}
+	printf("\n%s: Success: %d, Failure: %d\n", __func__, size + all_err, -all_err);
+
+	return all_err;
+}
+
+static int
+test_inline_macsec_auth_only_all(const void *data __rte_unused)
+{
+	const struct mcs_test_vector *cur_td;
+	struct mcs_test_opts opts = {0};
+	int err, all_err = 0;
+	int i, size;
+
+	opts.val_frames = RTE_SECURITY_MACSEC_VALIDATE_STRICT;
+	opts.protect_frames = true;
+	opts.sa_in_use = 1;
+	opts.nb_td = 1;
+	opts.sectag_insert_mode = 1;
+	opts.mtu = RTE_ETHER_MTU;
+
+	size = (sizeof(list_mcs_integrity_vectors) / sizeof((list_mcs_integrity_vectors)[0]));
+
+	for (i = 0; i < size; i++) {
+		cur_td = &list_mcs_integrity_vectors[i];
+		err = test_macsec(&cur_td, MCS_AUTH_ONLY, &opts);
+		if (err) {
+			printf("\nAuth Generate case %d failed", cur_td->test_idx);
+			err = -1;
+		} else {
+			printf("\nAuth Generate case %d Passed", cur_td->test_idx);
+			err = 0;
+		}
+		all_err += err;
+	}
+	printf("\n%s: Success: %d, Failure: %d\n", __func__, size + all_err, -all_err);
+
+	return all_err;
+}
+
+static int
+test_inline_macsec_verify_only_all(const void *data __rte_unused)
+{
+	const struct mcs_test_vector *cur_td;
+	struct mcs_test_opts opts = {0};
+	int err, all_err = 0;
+	int i, size;
+
+	opts.val_frames = RTE_SECURITY_MACSEC_VALIDATE_STRICT;
+	opts.sa_in_use = 1;
+	opts.nb_td = 1;
+	opts.sectag_insert_mode = 1;
+	opts.mtu = RTE_ETHER_MTU;
+
+	size = (sizeof(list_mcs_integrity_vectors) / sizeof((list_mcs_integrity_vectors)[0]));
+
+	for (i = 0; i < size; i++) {
+		cur_td = &list_mcs_integrity_vectors[i];
+		err = test_macsec(&cur_td, MCS_VERIFY_ONLY, &opts);
+		if (err) {
+			printf("\nAuth Verify case %d failed", cur_td->test_idx);
+			err = -1;
+		} else {
+			printf("\nAuth Verify case %d Passed", cur_td->test_idx);
+			err = 0;
+		}
+		all_err += err;
+	}
+	printf("\n%s: Success: %d, Failure: %d\n", __func__, size + all_err, -all_err);
+
+	return all_err;
+}
+
+static int
+test_inline_macsec_encap_decap_all(const void *data __rte_unused)
+{
+	const struct mcs_test_vector *cur_td;
+	struct mcs_test_opts opts = {0};
+	int err, all_err = 0;
+	int i, size;
+
+	opts.val_frames = RTE_SECURITY_MACSEC_VALIDATE_STRICT;
+	opts.protect_frames = true;
+	opts.sa_in_use = 1;
+	opts.nb_td = 1;
+	opts.sectag_insert_mode = 1;
+	opts.mtu = RTE_ETHER_MTU;
+
+	size = (sizeof(list_mcs_cipher_vectors) / sizeof((list_mcs_cipher_vectors)[0]));
+
+	for (i = 0; i < size; i++) {
+		cur_td = &list_mcs_cipher_vectors[i];
+		err = test_macsec(&cur_td, MCS_ENCAP_DECAP, &opts);
+		if (err) {
+			printf("\nCipher Auth Encap-decap case %d failed", cur_td->test_idx);
+			err = -1;
+		} else {
+			printf("\nCipher Auth Encap-decap case %d Passed", cur_td->test_idx);
+			err = 0;
+		}
+		all_err += err;
+	}
+	printf("\n%s: Success: %d, Failure: %d\n", __func__, size + all_err, -all_err);
+
+	return all_err;
+}
+
+
+static int
+test_inline_macsec_auth_verify_all(const void *data __rte_unused)
+{
+	const struct mcs_test_vector *cur_td;
+	struct mcs_test_opts opts = {0};
+	int err, all_err = 0;
+	int i, size;
+
+	opts.val_frames = RTE_SECURITY_MACSEC_VALIDATE_STRICT;
+	opts.protect_frames = true;
+	opts.sa_in_use = 1;
+	opts.nb_td = 1;
+	opts.sectag_insert_mode = 1;
+	opts.mtu = RTE_ETHER_MTU;
+
+	size = (sizeof(list_mcs_integrity_vectors) / sizeof((list_mcs_integrity_vectors)[0]));
+
+	for (i = 0; i < size; i++) {
+		cur_td = &list_mcs_integrity_vectors[i];
+		err = test_macsec(&cur_td, MCS_AUTH_VERIFY, &opts);
+		if (err) {
+			printf("\nAuth Generate + Verify case %d failed", cur_td->test_idx);
+			err = -1;
+		} else {
+			printf("\nAuth Generate + Verify case %d Passed", cur_td->test_idx);
+			err = 0;
+		}
+		all_err += err;
+	}
+	printf("\n%s: Success: %d, Failure: %d\n", __func__, size + all_err, -all_err);
+
+	return all_err;
+}
+
+static int
+test_inline_macsec_multi_flow(const void *data __rte_unused)
+{
+	const struct mcs_test_vector *tv[MCS_MAX_FLOWS];
+	struct mcs_test_vector iter[MCS_MAX_FLOWS];
+	struct mcs_test_opts opts = {0};
+	int i, err;
+
+	opts.val_frames = RTE_SECURITY_MACSEC_VALIDATE_STRICT;
+	opts.protect_frames = true;
+	opts.sa_in_use = 1;
+	opts.nb_td = MCS_MAX_FLOWS;
+	opts.sectag_insert_mode = 1;
+	opts.mtu = RTE_ETHER_MTU;
+
+	for (i = 0; i < MCS_MAX_FLOWS; i++) {
+		memcpy(&iter[i].sa_key.data, sa_key, MCS_MULTI_FLOW_TD_KEY_SZ);
+		memcpy(&iter[i].plain_pkt.data, eth_addrs[i], 2 * RTE_ETHER_ADDR_LEN);
+		memcpy(&iter[i].plain_pkt.data[2 * RTE_ETHER_ADDR_LEN], plain_user_data,
+		       MCS_MULTI_FLOW_TD_PLAIN_DATA_SZ);
+		memcpy(&iter[i].secure_pkt.data, eth_addrs[i], 2 * RTE_ETHER_ADDR_LEN);
+		memcpy(&iter[i].secure_pkt.data[2 * RTE_ETHER_ADDR_LEN], secure_user_data,
+		       MCS_MULTI_FLOW_TD_SECURE_DATA_SZ);
+		iter[i].sa_key.len = MCS_MULTI_FLOW_TD_KEY_SZ;
+		iter[i].hash_key.len = MCS_MULTI_FLOW_TD_KEY_SZ;
+		iter[i].plain_pkt.len = MCS_MULTI_FLOW_TD_PLAIN_DATA_SZ +
+					(2 * RTE_ETHER_ADDR_LEN);
+		iter[i].secure_pkt.len = MCS_MULTI_FLOW_TD_SECURE_DATA_SZ +
+					(2 * RTE_ETHER_ADDR_LEN);
+		iter[i].alg = RTE_SECURITY_MACSEC_ALG_GCM_128;
+		iter[i].ssci = 0x0;
+		iter[i].xpn = 0x0;
+		tv[i] = (const struct mcs_test_vector *)&iter[i];
+	}
+	err = test_macsec(tv, MCS_ENCAP_DECAP, &opts);
+	if (err) {
+		printf("\nCipher Auth Encryption multi flow failed");
+		err = -1;
+	} else {
+		printf("\nCipher Auth Encryption multi flow Passed");
+		err = 0;
+	}
+	return err;
+}
+
+static int
+test_inline_macsec_with_vlan(const void *data __rte_unused)
+{
+	const struct mcs_test_vector *cur_td;
+	struct mcs_test_opts opts = {0};
+	int err, all_err = 0;
+	int i, size;
+
+	opts.val_frames = RTE_SECURITY_MACSEC_VALIDATE_STRICT;
+	opts.protect_frames = true;
+	opts.sa_in_use = 1;
+	opts.nb_td = 1;
+	opts.mtu = RTE_ETHER_MTU;
+
+	size = (sizeof(list_mcs_vlan_vectors) / sizeof((list_mcs_vlan_vectors)[0]));
+
+	for (i = 0; i < size; i++) {
+		cur_td = &list_mcs_vlan_vectors[i];
+		if (i == 0) {
+			opts.sectag_insert_mode = 1;
+		} else if (i == 1) {
+			opts.sectag_insert_mode = 0; /* offset from special E-type */
+			opts.nb_vlan = 1;
+		} else if (i == 2) {
+			opts.sectag_insert_mode = 0; /* offset from special E-type */
+			opts.nb_vlan = 2;
+		}
+		err = test_macsec(&cur_td, MCS_ENCAP, &opts);
+		if (err) {
+			printf("\n VLAN Encap case %d failed", cur_td->test_idx);
+			err = -1;
+		} else {
+			printf("\n VLAN Encap case %d passed", cur_td->test_idx);
+			err = 0;
+		}
+		all_err += err;
+	}
+	for (i = 0; i < size; i++) {
+		cur_td = &list_mcs_vlan_vectors[i];
+		if (i == 0) {
+			opts.sectag_insert_mode = 1;
+		} else if (i == 1) {
+			opts.sectag_insert_mode = 0; /* offset from special E-type */
+			opts.nb_vlan = 1;
+		} else if (i == 2) {
+			opts.sectag_insert_mode = 0; /* offset from special E-type */
+			opts.nb_vlan = 2;
+		}
+		err = test_macsec(&cur_td, MCS_DECAP, &opts);
+		if (err) {
+			printf("\n VLAN Decap case %d failed", cur_td->test_idx);
+			err = -1;
+		} else {
+			printf("\n VLAN Decap case %d passed", cur_td->test_idx);
+			err = 0;
+		}
+		all_err += err;
+	}
+
+	printf("\n%s: Success: %d, Failure: %d\n", __func__, (2 * size) + all_err, -all_err);
+	return all_err;
+}
+
 static int
 ut_setup_inline_macsec(void)
 {
@@ -804,6 +1081,34 @@ static struct unit_test_suite inline_macsec_testsuite  = {
 			"MACsec encap(Cipher+Auth) known vector",
 			ut_setup_inline_macsec, ut_teardown_inline_macsec,
 			test_inline_macsec_encap_all),
+		TEST_CASE_NAMED_ST(
+			"MACsec decap(De-cipher+verify) known vector",
+			ut_setup_inline_macsec, ut_teardown_inline_macsec,
+			test_inline_macsec_decap_all),
+		TEST_CASE_NAMED_ST(
+			"MACsec auth only known vector",
+			ut_setup_inline_macsec, ut_teardown_inline_macsec,
+			test_inline_macsec_auth_only_all),
+		TEST_CASE_NAMED_ST(
+			"MACsec verify only known vector",
+			ut_setup_inline_macsec, ut_teardown_inline_macsec,
+			test_inline_macsec_verify_only_all),
+		TEST_CASE_NAMED_ST(
+			"MACsec encap + decap known vector",
+			ut_setup_inline_macsec, ut_teardown_inline_macsec,
+			test_inline_macsec_encap_decap_all),
+		TEST_CASE_NAMED_ST(
+			"MACsec auth + verify known vector",
+			ut_setup_inline_macsec, ut_teardown_inline_macsec,
+			test_inline_macsec_auth_verify_all),
+		TEST_CASE_NAMED_ST(
+			"MACsec Encap + decap Multi flow",
+			ut_setup_inline_macsec, ut_teardown_inline_macsec,
+			test_inline_macsec_multi_flow),
+		TEST_CASE_NAMED_ST(
+			"MACsec Encap and decap with VLAN",
+			ut_setup_inline_macsec, ut_teardown_inline_macsec,
+			test_inline_macsec_with_vlan),
 
 		TEST_CASES_END() /**< NULL terminate unit test array */
 	},
app/test/test_security_inline_macsec_vectors.h +321 -0

328 lines not on this page · raw message

Signature · 1 line
2.25.1
#72 lore raw

cover net/cnxk: add MACsec support

In reply to Akhil Goyal

Added MACsec support in Marvell cnxk PMD. The patchset is pending from last release [1] Sending as a new series as the functionality is now complete and tested on hardware.

Depends-on: https://patches.dpdk.org/project/dpdk/list/?series=28140

[1] https://patches.dpdk.org/project/dpdk/cover/[email protected]/

Akhil Goyal (15):
common/cnxk: add ROC MACsec initialization common/cnxk: add MACsec SA configuration common/cnxk: add MACsec SC configuration APIs common/cnxk: add MACsec secy and flow configuration common/cnxk: add MACsec PN and LMAC mode configuration common/cnxk: add MACsec stats
common/cnxk: add MACsec interrupt APIs common/cnxk: add MACsec port configuration common/cnxk: add MACsec control port configuration common/cnxk: add MACsec FIPS mbox common/cnxk: derive hash key for MACsec net/cnxk: add MACsec initialization
net/cnxk: create/destroy MACsec SC/SA net/cnxk: add MACsec session and flow configuration net/cnxk: add MACsec stats

 drivers/common/cnxk/meson.build       |   3 +
 drivers/common/cnxk/roc_aes.c         |  86 ++-
 drivers/common/cnxk/roc_aes.h         |   4 +-
 drivers/common/cnxk/roc_api.h         |   3 +
 drivers/common/cnxk/roc_dev.c         |  86 +++
 drivers/common/cnxk/roc_features.h    |   6 +
 drivers/common/cnxk/roc_idev.c        |  21 +
 drivers/common/cnxk/roc_idev.h        |   2 +
 drivers/common/cnxk/roc_idev_priv.h   |   1 +
 drivers/common/cnxk/roc_mbox.h        | 524 ++++++++++++++-
 drivers/common/cnxk/roc_mcs.c         | 895 ++++++++++++++++++++++++++
 drivers/common/cnxk/roc_mcs.h         | 619 ++++++++++++++++++
 drivers/common/cnxk/roc_mcs_priv.h    |  73 +++
 drivers/common/cnxk/roc_mcs_sec_cfg.c | 528 +++++++++++++++
 drivers/common/cnxk/roc_mcs_stats.c   | 193 ++++++
 drivers/common/cnxk/roc_priv.h        |   3 +
 drivers/common/cnxk/roc_utils.c       |   5 +
 drivers/common/cnxk/version.map       |  44 ++
 drivers/net/cnxk/cn10k_ethdev_sec.c   |  25 +-
 drivers/net/cnxk/cn10k_flow.c         |  22 +-
 drivers/net/cnxk/cnxk_ethdev.c        |  15 +
 drivers/net/cnxk/cnxk_ethdev.h        |  30 +
 drivers/net/cnxk/cnxk_ethdev_mcs.c    | 726 +++++++++++++++++++++
 drivers/net/cnxk/cnxk_ethdev_mcs.h    | 111 ++++
 drivers/net/cnxk/cnxk_ethdev_sec.c    |   2 +-
 drivers/net/cnxk/cnxk_flow.c          |   5 +
 drivers/net/cnxk/meson.build          |   1 +
 27 files changed, 3995 insertions(+), 38 deletions(-)
 create mode 100644 drivers/common/cnxk/roc_mcs.c
 create mode 100644 drivers/common/cnxk/roc_mcs.h
 create mode 100644 drivers/common/cnxk/roc_mcs_priv.h
 create mode 100644 drivers/common/cnxk/roc_mcs_sec_cfg.c
 create mode 100644 drivers/common/cnxk/roc_mcs_stats.c
 create mode 100644 drivers/net/cnxk/cnxk_ethdev_mcs.c
 create mode 100644 drivers/net/cnxk/cnxk_ethdev_mcs.h
Signature · 1 line
2.25.1
#73 lore raw

PATCH 1/15 common/cnxk: add ROC MACsec initialization

Added ROC init and fini APIs for supporting MACsec.

---
 drivers/common/cnxk/meson.build     |   1 +
 drivers/common/cnxk/roc_api.h       |   3 +
 drivers/common/cnxk/roc_features.h  |   6 +
 drivers/common/cnxk/roc_idev.c      |  21 +++
 drivers/common/cnxk/roc_idev.h      |   2 +
 drivers/common/cnxk/roc_idev_priv.h |   1 +
 drivers/common/cnxk/roc_mbox.h      |  65 +++++++-
 drivers/common/cnxk/roc_mcs.c       | 245 ++++++++++++++++++++++++++++
 drivers/common/cnxk/roc_mcs.h       |  39 +++++
 drivers/common/cnxk/roc_mcs_priv.h  |  65 ++++++++
 drivers/common/cnxk/roc_priv.h      |   3 +
 drivers/common/cnxk/roc_utils.c     |   5 +
 drivers/common/cnxk/version.map     |   6 +
 13 files changed, 461 insertions(+), 1 deletion(-)
 create mode 100644 drivers/common/cnxk/roc_mcs.c
 create mode 100644 drivers/common/cnxk/roc_mcs.h
 create mode 100644 drivers/common/cnxk/roc_mcs_priv.h
drivers/common/cnxk/meson.build +1 -0
index 631b594f32..e33c002676 100644
@@ -26,6 +26,7 @@ sources = files(
         'roc_irq.c',
         'roc_ie_ot.c',
         'roc_mbox.c',
+        'roc_mcs.c',
         'roc_ml.c',
         'roc_model.c',
         'roc_nix.c',
drivers/common/cnxk/roc_api.h +3 -0
index bbc94ab48e..f630853088 100644
@@ -114,4 +114,7 @@
 /* ML */
 #include "roc_ml.h"
 
+/* MACsec */
+#include "roc_mcs.h"
+
 #endif /* _ROC_API_H_ */
drivers/common/cnxk/roc_features.h +6 -0
index 252f306a86..dd39259c81 100644
@@ -40,4 +40,10 @@ roc_feature_nix_has_reass(void)
 	return roc_model_is_cn10ka();
 }
 
+static inline bool
+roc_feature_nix_has_macsec(void)
+{
+	return roc_model_is_cn10kb();
+}
+
 #endif
drivers/common/cnxk/roc_idev.c +21 -0
index 62a4fd8880..f9b94f3ca0 100644
@@ -38,6 +38,7 @@ idev_set_defaults(struct idev_cfg *idev)
 	idev->num_lmtlines = 0;
 	idev->bphy = NULL;
 	idev->cpt = NULL;
+	idev->mcs = NULL;
 	idev->nix_inl_dev = NULL;
 	plt_spinlock_init(&idev->nix_inl_dev_lock);
 	plt_spinlock_init(&idev->npa_dev_lock);
@@ -186,6 +187,26 @@ roc_idev_cpt_get(void)
 	return NULL;
 }
 
+struct roc_mcs *
+roc_idev_mcs_get(void)
+{
+	struct idev_cfg *idev = idev_get_cfg();
+
+	if (idev != NULL)
+		return idev->mcs;
+
+	return NULL;
+}
+
+void
+roc_idev_mcs_set(struct roc_mcs *mcs)
+{
+	struct idev_cfg *idev = idev_get_cfg();
+
+	if (idev != NULL)
+		__atomic_store_n(&idev->mcs, mcs, __ATOMIC_RELEASE);
+}
+
 uint64_t *
 roc_nix_inl_outb_ring_base_get(struct roc_nix *roc_nix)
 {
drivers/common/cnxk/roc_idev.h +2 -0
index 926aac0634..dbf1f46335 100644
@@ -18,4 +18,6 @@ void __roc_api roc_idev_cpt_set(struct roc_cpt *cpt);
 struct roc_nix *__roc_api roc_idev_npa_nix_get(void);
 uint64_t __roc_api roc_idev_nix_inl_meta_aura_get(void);
 
+struct roc_mcs *__roc_api roc_idev_mcs_get(void);
+void __roc_api roc_idev_mcs_set(struct roc_mcs *mcs);
 #endif /* _ROC_IDEV_H_ */
drivers/common/cnxk/roc_idev_priv.h +1 -0
index b97d2936a2..ce26caa062 100644
@@ -30,6 +30,7 @@ struct idev_cfg {
 	struct roc_bphy *bphy;
 	struct roc_cpt *cpt;
 	struct roc_sso *sso;
+	struct roc_mcs *mcs;
 	struct nix_inl_dev *nix_inl_dev;
 	struct idev_nix_inl_cfg inl_cfg;
 	plt_spinlock_t nix_inl_dev_lock;
drivers/common/cnxk/roc_mbox.h +64 -1

77 lines not on this page · raw message

drivers/common/cnxk/roc_mcs.c new file +245 -0

245 lines not on this page · raw message

drivers/common/cnxk/roc_mcs.h new file +39 -0
new file mode 100644
index 0000000000..504671a833
@@ -0,0 +1,39 @@
+/* SPDX-License-Identifier: BSD-3-Clause
+ * Copyright(C) 2022 Marvell.
+ */
+
+#ifndef _ROC_MCS_H_
+#define _ROC_MCS_H_
+
+#define MCS_AES_GCM_256_KEYLEN 32
+
+struct roc_mcs_hw_info {
+	uint8_t num_mcs_blks; /* Number of MCS blocks */
+	uint8_t tcam_entries; /* RX/TX Tcam entries per mcs block */
+	uint8_t secy_entries; /* RX/TX SECY entries per mcs block */
+	uint8_t sc_entries;   /* RX/TX SC CAM entries per mcs block */
+	uint16_t sa_entries;  /* PN table entries = SA entries */
+	uint64_t rsvd[16];
+};
+
+
+struct roc_mcs {
+	TAILQ_ENTRY(roc_mcs) next;
+	struct plt_pci_device *pci_dev;
+	struct mbox *mbox;
+	void *userdata;
+	uint8_t idx;
+	uint8_t refcount;
+
+#define ROC_MCS_MEM_SZ (1 * 1024)
+	uint8_t reserved[ROC_MCS_MEM_SZ] __plt_cache_aligned;
+} __plt_cache_aligned;
+
+/* Initialization */
+__roc_api struct roc_mcs *roc_mcs_dev_init(uint8_t mcs_idx);
+__roc_api void roc_mcs_dev_fini(struct roc_mcs *mcs);
+/* Get roc mcs dev structure */
+__roc_api struct roc_mcs *roc_mcs_dev_get(uint8_t mcs_idx);
+/* HW info get */
+__roc_api int roc_mcs_hw_info_get(struct roc_mcs_hw_info *hw_info);
+#endif /* _ROC_MCS_H_ */
drivers/common/cnxk/roc_mcs_priv.h new file +65 -0

65 lines not on this page · raw message

drivers/common/cnxk/roc_priv.h +3 -0
index 14fe2e452a..254a2d3310 100644
@@ -44,6 +44,9 @@
 /* DPI */
 #include "roc_dpi_priv.h"
 
+/* MCS */
+#include "roc_mcs_priv.h"
+
 /* REE */
 #include "roc_ree_priv.h"
 
drivers/common/cnxk/roc_utils.c +5 -0
index fe291fce96..9af2ae9b69 100644
@@ -16,6 +16,7 @@ roc_error_msg_get(int errorcode)
 	case NPA_ERR_PARAM:
 	case NPC_ERR_PARAM:
 	case SSO_ERR_PARAM:
+	case MCS_ERR_PARAM:
 	case UTIL_ERR_PARAM:
 		err_msg = "Invalid parameter";
 		break;
@@ -35,6 +36,7 @@ roc_error_msg_get(int errorcode)
 		err_msg = "Operation not supported";
 		break;
 	case NIX_ERR_HW_NOTSUP:
+	case MCS_ERR_HW_NOTSUP:
 		err_msg = "Hardware does not support";
 		break;
 	case NIX_ERR_QUEUE_INVALID_RANGE:
@@ -223,6 +225,9 @@ roc_error_msg_get(int errorcode)
 	case SSO_ERR_DEVICE_NOT_BOUNDED:
 		err_msg = "SSO pf/vf not found";
 		break;
+	case MCS_ERR_DEVICE_NOT_FOUND:
+		err_msg = "MCS device not found";
+		break;
 	case UTIL_ERR_FS:
 		err_msg = "file operation failed";
 		break;
drivers/common/cnxk/version.map +6 -0
index b298a21b84..7593c7c890 100644
@@ -94,6 +94,8 @@ INTERNAL {
 	roc_idev_cpt_get;
 	roc_idev_cpt_set;
 	roc_idev_lmt_base_addr_get;
+	roc_idev_mcs_get;
+	roc_idev_mcs_set;
 	roc_idev_npa_maxpools_get;
 	roc_idev_npa_maxpools_set;
 	roc_idev_npa_nix_get;
@@ -131,6 +133,10 @@ INTERNAL {
 	roc_se_auth_key_set;
 	roc_se_ciph_key_set;
 	roc_se_ctx_init;
+	roc_mcs_dev_init;
+	roc_mcs_dev_fini;
+	roc_mcs_dev_get;
+	roc_mcs_hw_info_get;
 	roc_nix_bpf_alloc;
 	roc_nix_bpf_config;
 	roc_nix_bpf_connect;
Signature · 1 line
2.25.1
#74 lore raw

Re: [PATCH 01/15] common/cnxk: add ROC MACsec initialization

drivers/common/cnxk/roc_mcs.c line 10

Quoted 11 lines · Akhil Goyal

Added ROC init and fini APIs for supporting MACsec.

---

drivers/common/cnxk/roc_mcs.c new file +4 -0
+
+TAILQ_HEAD(roc_mcs_head, roc_mcs);
+/* Local mcs tailq list */
+static struct roc_mcs_head roc_mcs_head = TAILQ_HEAD_INITIALIZER(roc_mcs_head);

Can we remove this global variable by moving? This is to avoid breaking multiprocess,

drivers/common/cnxk/roc_mcs.c line 179

Quoted 7 lines
drivers/common/cnxk/roc_mcs.c new file +7 -0
+struct roc_mcs *
+roc_mcs_dev_init(uint8_t mcs_idx)
+{
+       struct roc_mcs *mcs;
+       struct npa_lf *npa;
+
+       if (roc_model_is_cn10kb()) {

Use roc_feature_nix_has_macsec()

drivers/common/cnxk/roc_mcs.c line 192

Quoted 13 lines
drivers/common/cnxk/roc_mcs.c new file +13 -0
+               mcs = roc_idev_mcs_get();
+               if (mcs) {
+                       plt_info("Skipping device, mcs device already probed");
+                       mcs->refcount++;
+                       return mcs;
+               }
+       }
+
+       mcs = plt_zmalloc(sizeof(struct roc_mcs), PLT_CACHE_LINE_SIZE);
+       if (!mcs)
+               return NULL;
+
+       if (roc_model_is_cnf10kb() || roc_model_is_cn10kb()) {

Use roc_feature_nix_has_macsec()

drivers/common/cnxk/roc_mcs_priv.h line 18

Quoted 8 lines
drivers/common/cnxk/roc_mcs_priv.h new file +8 -0
+       MCS_ERR_PARAM = -900,
+       MCS_ERR_HW_NOTSUP = -901,
+       MCS_ERR_DEVICE_NOT_FOUND = -902,
+};
+
+#define MCS_SUPPORT_CHECK                                                                          \
+       do {                                                                                       \
+               if (!(roc_model_is_cnf10kb() || roc_model_is_cn10kb_a0()))                         \

Use roc_feature_nix_has_macsec()

#75 lore raw

PATCH 2/15 common/cnxk: add MACsec SA configuration

In reply to Akhil Goyal

Added ROC APIs to allocate/free MACsec resources
and APIs to write SA policy.

---
 drivers/common/cnxk/meson.build       |   1 +
 drivers/common/cnxk/roc_mbox.h        |  12 ++
 drivers/common/cnxk/roc_mcs.h         |  43 ++++++
 drivers/common/cnxk/roc_mcs_sec_cfg.c | 211 ++++++++++++++++++++++++++
 drivers/common/cnxk/version.map       |   4 +
 5 files changed, 271 insertions(+)
 create mode 100644 drivers/common/cnxk/roc_mcs_sec_cfg.c
drivers/common/cnxk/meson.build +1 -0
index e33c002676..589baf74fe 100644
@@ -27,6 +27,7 @@ sources = files(
         'roc_ie_ot.c',
         'roc_mbox.c',
         'roc_mcs.c',
+        'roc_mcs_sec_cfg.c',
         'roc_ml.c',
         'roc_model.c',
         'roc_nix.c',
drivers/common/cnxk/roc_mbox.h +12 -0
index 2ba35377da..66a6de2cd2 100644
@@ -280,6 +280,7 @@ struct mbox_msghdr {
 	M(MCS_ALLOC_RESOURCES, 0xa000, mcs_alloc_resources, mcs_alloc_rsrc_req,                    \
 	  mcs_alloc_rsrc_rsp)                                                                      \
 	M(MCS_FREE_RESOURCES, 0xa001, mcs_free_resources, mcs_free_rsrc_req, msg_rsp)              \
+	M(MCS_SA_PLCY_WRITE, 0xa005, mcs_sa_plcy_write, mcs_sa_plcy_write_req, msg_rsp)            \
 	M(MCS_GET_HW_INFO, 0xa00b, mcs_get_hw_info, msg_req, mcs_hw_info)                          \
 
 /* Messages initiated by AF (range 0xC00 - 0xDFF) */
@@ -705,6 +706,17 @@ struct mcs_free_rsrc_req {
 	uint64_t __io rsvd;
 };
 
+struct mcs_sa_plcy_write_req {
+	struct mbox_msghdr hdr;
+	uint64_t __io plcy[2][9]; /* Support 2 SA policy */
+	uint8_t __io sa_index[2];
+	uint8_t __io sa_cnt;
+	uint8_t __io mcs_id;
+	uint8_t __io dir;
+	uint64_t __io rsvd;
+};
+
+
 struct mcs_hw_info {
 	struct mbox_msghdr hdr;
 	uint8_t __io num_mcs_blks; /* Number of MCS blocks */
drivers/common/cnxk/roc_mcs.h +43 -0

53 lines not on this page · raw message

drivers/common/cnxk/roc_mcs_sec_cfg.c new file +211 -0

211 lines not on this page · raw message

drivers/common/cnxk/version.map +4 -0
index 7593c7c890..9266edd9a1 100644
@@ -133,10 +133,14 @@ INTERNAL {
 	roc_se_auth_key_set;
 	roc_se_ciph_key_set;
 	roc_se_ctx_init;
+	roc_mcs_alloc_rsrc;
 	roc_mcs_dev_init;
 	roc_mcs_dev_fini;
 	roc_mcs_dev_get;
+	roc_mcs_free_rsrc;
 	roc_mcs_hw_info_get;
+	roc_mcs_sa_policy_read;
+	roc_mcs_sa_policy_write;
 	roc_nix_bpf_alloc;
 	roc_nix_bpf_config;
 	roc_nix_bpf_connect;
Signature · 1 line
2.25.1
#76 lore raw

Re: [PATCH 02/15] common/cnxk: add MACsec SA configuration

Quoted 13 lines · Akhil Goyal

Added ROC APIs to allocate/free MACsec resources and APIs to write SA policy.

---

index 7593c7c890..9266edd9a1 100644

drivers/common/cnxk/version.map INTERNAL { · line 136

Quoted 4 lines
drivers/common/cnxk/version.map +1 -0
@@ -133,10 +133,14 @@ INTERNAL {
        roc_se_auth_key_set;
        roc_se_ciph_key_set;
        roc_se_ctx_init;
+       roc_mcs_alloc_rsrc;

Please change to roc_mcs_rsrc_alloc
i.e keeping action as last

drivers/common/cnxk/version.map INTERNAL { · line 140

Quoted 4 lines
drivers/common/cnxk/version.map +1 -0
        roc_mcs_dev_init;
        roc_mcs_dev_fini;
        roc_mcs_dev_get;
+       roc_mcs_free_rsrc;

Same as above.

Quoted 9 lines
drivers/common/cnxk/version.map +2 -1
        roc_mcs_hw_info_get;
+       roc_mcs_sa_policy_read;
+       roc_mcs_sa_policy_write;
        roc_nix_bpf_alloc;
        roc_nix_bpf_config;
        roc_nix_bpf_connect;
--

2.25.1

#77 lore raw

PATCH 3/15 common/cnxk: add MACsec SC configuration APIs

In reply to Akhil Goyal

Added ROC APIs to configure MACsec secure channel(SC) and its mapping with SAs for both Rx and Tx.

---
 drivers/common/cnxk/roc_mbox.h        |  37 ++++++
 drivers/common/cnxk/roc_mcs.h         |  41 ++++++
 drivers/common/cnxk/roc_mcs_sec_cfg.c | 171 ++++++++++++++++++++++++++
 drivers/common/cnxk/version.map       |   7 ++
 4 files changed, 256 insertions(+)
drivers/common/cnxk/roc_mbox.h +37 -0
index 66a6de2cd2..0673c31389 100644
@@ -280,7 +280,10 @@ struct mbox_msghdr {
 	M(MCS_ALLOC_RESOURCES, 0xa000, mcs_alloc_resources, mcs_alloc_rsrc_req,                    \
 	  mcs_alloc_rsrc_rsp)                                                                      \
 	M(MCS_FREE_RESOURCES, 0xa001, mcs_free_resources, mcs_free_rsrc_req, msg_rsp)              \
+	M(MCS_RX_SC_CAM_WRITE, 0xa004, mcs_rx_sc_cam_write, mcs_rx_sc_cam_write_req, msg_rsp)      \
 	M(MCS_SA_PLCY_WRITE, 0xa005, mcs_sa_plcy_write, mcs_sa_plcy_write_req, msg_rsp)            \
+	M(MCS_TX_SC_SA_MAP_WRITE, 0xa006, mcs_tx_sc_sa_map_write, mcs_tx_sc_sa_map, msg_rsp)       \
+	M(MCS_RX_SC_SA_MAP_WRITE, 0xa007, mcs_rx_sc_sa_map_write, mcs_rx_sc_sa_map, msg_rsp)       \
 	M(MCS_GET_HW_INFO, 0xa00b, mcs_get_hw_info, msg_req, mcs_hw_info)                          \
 
 /* Messages initiated by AF (range 0xC00 - 0xDFF) */
@@ -706,6 +709,16 @@ struct mcs_free_rsrc_req {
 	uint64_t __io rsvd;
 };
 
+/* RX SC_CAM mapping */
+struct mcs_rx_sc_cam_write_req {
+	struct mbox_msghdr hdr;
+	uint64_t __io sci;     /* SCI */
+	uint64_t __io secy_id; /* secy index mapped to SC */
+	uint8_t __io sc_id;    /* SC CAM entry index */
+	uint8_t __io mcs_id;
+	uint64_t __io rsvd;
+};
+
 struct mcs_sa_plcy_write_req {
 	struct mbox_msghdr hdr;
 	uint64_t __io plcy[2][9]; /* Support 2 SA policy */
@@ -716,6 +729,30 @@ struct mcs_sa_plcy_write_req {
 	uint64_t __io rsvd;
 };
 
+struct mcs_tx_sc_sa_map {
+	struct mbox_msghdr hdr;
+	uint8_t __io sa_index0;
+	uint8_t __io sa_index1;
+	uint8_t __io rekey_ena;
+	uint8_t __io sa_index0_vld;
+	uint8_t __io sa_index1_vld;
+	uint8_t __io tx_sa_active;
+	uint64_t __io sectag_sci;
+	uint8_t __io sc_id; /* used as index for SA_MEM_MAP */
+	uint8_t __io mcs_id;
+	uint64_t __io rsvd;
+};
+
+struct mcs_rx_sc_sa_map {
+	struct mbox_msghdr hdr;
+	uint8_t __io sa_index;
+	uint8_t __io sa_in_use;
+	uint8_t __io sc_id;
+	/* an range is 0-3, sc_id + an used as index SA_MEM_MAP */
+	uint8_t __io an;
+	uint8_t __io mcs_id;
+	uint64_t __io rsvd;
+};
 
 struct mcs_hw_info {
 	struct mbox_msghdr hdr;
drivers/common/cnxk/roc_mcs.h +41 -0

57 lines not on this page · raw message

drivers/common/cnxk/roc_mcs_sec_cfg.c +171 -0

174 lines not on this page · raw message

drivers/common/cnxk/version.map +7 -0
index 9266edd9a1..a1af736a07 100644
@@ -139,8 +139,15 @@ INTERNAL {
 	roc_mcs_dev_get;
 	roc_mcs_free_rsrc;
 	roc_mcs_hw_info_get;
+	roc_mcs_rx_sc_cam_enable;
+	roc_mcs_rx_sc_cam_read;
+	roc_mcs_rx_sc_cam_write;
+	roc_mcs_rx_sc_sa_map_read;
+	roc_mcs_rx_sc_sa_map_write;
 	roc_mcs_sa_policy_read;
 	roc_mcs_sa_policy_write;
+	roc_mcs_tx_sc_sa_map_read;
+	roc_mcs_tx_sc_sa_map_write;
 	roc_nix_bpf_alloc;
 	roc_nix_bpf_config;
 	roc_nix_bpf_connect;
Signature · 1 line
2.25.1
#78 lore raw

PATCH 4/15 common/cnxk: add MACsec secy and flow configuration

In reply to Akhil Goyal

Added ROC APIs to configure MACsec secy policy and flow entries.

---
 drivers/common/cnxk/roc_mbox.h        |  38 +++++++++
 drivers/common/cnxk/roc_mcs.h         |  37 +++++++++
 drivers/common/cnxk/roc_mcs_sec_cfg.c | 115 ++++++++++++++++++++++++++
 drivers/common/cnxk/version.map       |   5 ++
 4 files changed, 195 insertions(+)
drivers/common/cnxk/roc_mbox.h +38 -0
index 0673c31389..2f6ce958d8 100644
@@ -280,10 +280,14 @@ struct mbox_msghdr {
 	M(MCS_ALLOC_RESOURCES, 0xa000, mcs_alloc_resources, mcs_alloc_rsrc_req,                    \
 	  mcs_alloc_rsrc_rsp)                                                                      \
 	M(MCS_FREE_RESOURCES, 0xa001, mcs_free_resources, mcs_free_rsrc_req, msg_rsp)              \
+	M(MCS_FLOWID_ENTRY_WRITE, 0xa002, mcs_flowid_entry_write, mcs_flowid_entry_write_req,      \
+	  msg_rsp)                                                                                 \
+	M(MCS_SECY_PLCY_WRITE, 0xa003, mcs_secy_plcy_write, mcs_secy_plcy_write_req, msg_rsp)      \
 	M(MCS_RX_SC_CAM_WRITE, 0xa004, mcs_rx_sc_cam_write, mcs_rx_sc_cam_write_req, msg_rsp)      \
 	M(MCS_SA_PLCY_WRITE, 0xa005, mcs_sa_plcy_write, mcs_sa_plcy_write_req, msg_rsp)            \
 	M(MCS_TX_SC_SA_MAP_WRITE, 0xa006, mcs_tx_sc_sa_map_write, mcs_tx_sc_sa_map, msg_rsp)       \
 	M(MCS_RX_SC_SA_MAP_WRITE, 0xa007, mcs_rx_sc_sa_map_write, mcs_rx_sc_sa_map, msg_rsp)       \
+	M(MCS_FLOWID_ENA_ENTRY, 0xa008, mcs_flowid_ena_entry, mcs_flowid_ena_dis_entry, msg_rsp)   \
 	M(MCS_GET_HW_INFO, 0xa00b, mcs_get_hw_info, msg_req, mcs_hw_info)                          \
 
 /* Messages initiated by AF (range 0xC00 - 0xDFF) */
@@ -709,6 +713,31 @@ struct mcs_free_rsrc_req {
 	uint64_t __io rsvd;
 };
 
+struct mcs_flowid_entry_write_req {
+	struct mbox_msghdr hdr;
+	uint64_t __io data[4];
+	uint64_t __io mask[4];
+	uint64_t __io sci; /* CNF10K-B for tx_secy_mem_map */
+	uint8_t __io flow_id;
+	uint8_t __io secy_id; /* secyid for which flowid is mapped */
+	/* sc_id is Valid if dir = MCS_TX, SC_CAM id mapped to flowid */
+	uint8_t __io sc_id;
+	uint8_t __io ena; /* Enable tcam entry */
+	uint8_t __io ctr_pkt;
+	uint8_t __io mcs_id;
+	uint8_t __io dir;
+	uint64_t __io rsvd;
+};
+
+struct mcs_secy_plcy_write_req {
+	struct mbox_msghdr hdr;
+	uint64_t __io plcy;
+	uint8_t __io secy_id;
+	uint8_t __io mcs_id;
+	uint8_t __io dir;
+	uint64_t __io rsvd;
+};
+
 /* RX SC_CAM mapping */
 struct mcs_rx_sc_cam_write_req {
 	struct mbox_msghdr hdr;
@@ -754,6 +783,15 @@ struct mcs_rx_sc_sa_map {
 	uint64_t __io rsvd;
 };
 
+struct mcs_flowid_ena_dis_entry {
+	struct mbox_msghdr hdr;
+	uint8_t __io flow_id;
+	uint8_t __io ena;
+	uint8_t __io mcs_id;
+	uint8_t __io dir;
+	uint64_t __io rsvd;
+};
+
 struct mcs_hw_info {
 	struct mbox_msghdr hdr;
 	uint8_t __io num_mcs_blks; /* Number of MCS blocks */
drivers/common/cnxk/roc_mcs.h +37 -0
index 2787d6a940..7e0a98e91a 100644
@@ -32,6 +32,24 @@ struct roc_mcs_free_rsrc_req {
 	uint8_t all; /* Free all the cam resources */
 };
 
+struct roc_mcs_flowid_entry_write_req {
+	uint64_t data[4];
+	uint64_t mask[4];
+	uint64_t sci; /* 105N for tx_secy_mem_map */
+	uint8_t flow_id;
+	uint8_t secy_id; /* secyid for which flowid is mapped */
+	uint8_t sc_id;	 /* Valid if dir = MCS_TX, SC_CAM id mapped to flowid */
+	uint8_t ena;	 /* Enable tcam entry */
+	uint8_t ctr_pkt;
+	uint8_t dir;
+};
+
+struct roc_mcs_secy_plcy_write_req {
+	uint64_t plcy;
+	uint8_t secy_id;
+	uint8_t dir;
+};
+
 /* RX SC_CAM mapping */
 struct roc_mcs_rx_sc_cam_write_req {
 	uint64_t sci;	  /* SCI */
@@ -64,6 +82,12 @@ struct roc_mcs_rx_sc_sa_map {
 	uint8_t an; /* value range 0-3, sc_id + an used as index SA_MEM_MAP */
 };
 
+struct roc_mcs_flowid_ena_dis_entry {
+	uint8_t flow_id;
+	uint8_t ena;
+	uint8_t dir;
+};
+
 struct roc_mcs_hw_info {
 	uint8_t num_mcs_blks; /* Number of MCS blocks */
 	uint8_t tcam_entries; /* RX/TX Tcam entries per mcs block */
@@ -110,6 +134,11 @@ __roc_api int roc_mcs_rx_sc_cam_read(struct roc_mcs *mcs,
 				     struct roc_mcs_rx_sc_cam_write_req *rx_sc_cam);
 __roc_api int roc_mcs_rx_sc_cam_enable(struct roc_mcs *mcs,
 				       struct roc_mcs_rx_sc_cam_write_req *rx_sc_cam);
+/* SECY policy read and write */
+__roc_api int roc_mcs_secy_policy_write(struct roc_mcs *mcs,
+					struct roc_mcs_secy_plcy_write_req *secy_plcy);
+__roc_api int roc_mcs_secy_policy_read(struct roc_mcs *mcs,
+				       struct roc_mcs_rx_sc_cam_write_req *rx_sc_cam);
 /* RX SC-SA MAP read and write */
 __roc_api int roc_mcs_rx_sc_sa_map_write(struct roc_mcs *mcs,
 					 struct roc_mcs_rx_sc_sa_map *rx_sc_sa_map);
@@ -120,4 +149,12 @@ __roc_api int roc_mcs_tx_sc_sa_map_write(struct roc_mcs *mcs,
 					 struct roc_mcs_tx_sc_sa_map *tx_sc_sa_map);
 __roc_api int roc_mcs_tx_sc_sa_map_read(struct roc_mcs *mcs,
 					struct roc_mcs_tx_sc_sa_map *tx_sc_sa_map);
+/* Flow entry read, write and enable */
+__roc_api int roc_mcs_flowid_entry_write(struct roc_mcs *mcs,
+					 struct roc_mcs_flowid_entry_write_req *flowid_req);
+__roc_api int roc_mcs_flowid_entry_read(struct roc_mcs *mcs,
+					struct roc_mcs_flowid_entry_write_req *flowid_rsp);
+__roc_api int roc_mcs_flowid_entry_enable(struct roc_mcs *mcs,
+					  struct roc_mcs_flowid_ena_dis_entry *entry);
+
 #endif /* _ROC_MCS_H_ */
drivers/common/cnxk/roc_mcs_sec_cfg.c +115 -0

124 lines not on this page · raw message

drivers/common/cnxk/version.map +5 -0
index a1af736a07..cb821de9ac 100644
@@ -137,6 +137,9 @@ INTERNAL {
 	roc_mcs_dev_init;
 	roc_mcs_dev_fini;
 	roc_mcs_dev_get;
+	roc_mcs_flowid_entry_enable;
+	roc_mcs_flowid_entry_read;
+	roc_mcs_flowid_entry_write;
 	roc_mcs_free_rsrc;
 	roc_mcs_hw_info_get;
 	roc_mcs_rx_sc_cam_enable;
@@ -146,6 +149,8 @@ INTERNAL {
 	roc_mcs_rx_sc_sa_map_write;
 	roc_mcs_sa_policy_read;
 	roc_mcs_sa_policy_write;
+	roc_mcs_secy_policy_read;
+	roc_mcs_secy_policy_write;
 	roc_mcs_tx_sc_sa_map_read;
 	roc_mcs_tx_sc_sa_map_write;
 	roc_nix_bpf_alloc;
Signature · 1 line
2.25.1
#79 lore raw

PATCH 5/15 common/cnxk: add MACsec PN and LMAC mode configuration

In reply to Akhil Goyal

Added ROC APIs for setting packet number and LMAC
related configurations.

---
 drivers/common/cnxk/roc_mbox.h        | 56 +++++++++++++++++++++
 drivers/common/cnxk/roc_mcs.c         | 71 +++++++++++++++++++++++++++
 drivers/common/cnxk/roc_mcs.h         | 48 ++++++++++++++++++
 drivers/common/cnxk/roc_mcs_sec_cfg.c | 31 ++++++++++++
 drivers/common/cnxk/version.map       |  5 ++
 5 files changed, 211 insertions(+)
drivers/common/cnxk/roc_mbox.h +56 -0
index 2f6ce958d8..9f9783ec92 100644
@@ -288,7 +288,11 @@ struct mbox_msghdr {
 	M(MCS_TX_SC_SA_MAP_WRITE, 0xa006, mcs_tx_sc_sa_map_write, mcs_tx_sc_sa_map, msg_rsp)       \
 	M(MCS_RX_SC_SA_MAP_WRITE, 0xa007, mcs_rx_sc_sa_map_write, mcs_rx_sc_sa_map, msg_rsp)       \
 	M(MCS_FLOWID_ENA_ENTRY, 0xa008, mcs_flowid_ena_entry, mcs_flowid_ena_dis_entry, msg_rsp)   \
+	M(MCS_PN_TABLE_WRITE, 0xa009, mcs_pn_table_write, mcs_pn_table_write_req, msg_rsp)         \
+	M(MCS_SET_ACTIVE_LMAC, 0xa00a, mcs_set_active_lmac, mcs_set_active_lmac, msg_rsp)          \
 	M(MCS_GET_HW_INFO, 0xa00b, mcs_get_hw_info, msg_req, mcs_hw_info)                          \
+	M(MCS_SET_LMAC_MODE, 0xa013, mcs_set_lmac_mode, mcs_set_lmac_mode, msg_rsp)                \
+	M(MCS_SET_PN_THRESHOLD, 0xa014, mcs_set_pn_threshold, mcs_set_pn_threshold, msg_rsp)       \
 
 /* Messages initiated by AF (range 0xC00 - 0xDFF) */
 #define MBOX_UP_CGX_MESSAGES                                                   \
@@ -792,6 +796,34 @@ struct mcs_flowid_ena_dis_entry {
 	uint64_t __io rsvd;
 };
 
+struct mcs_pn_table_write_req {
+	struct mbox_msghdr hdr;
+	uint64_t __io next_pn;
+	uint8_t __io pn_id;
+	uint8_t __io mcs_id;
+	uint8_t __io dir;
+	uint64_t __io rsvd;
+};
+
+struct mcs_cam_entry_read_req {
+	struct mbox_msghdr hdr;
+	uint8_t __io rsrc_type; /* TCAM/SECY/SC/SA/PN */
+	uint8_t __io rsrc_id;
+	uint8_t __io mcs_id;
+	uint8_t __io dir;
+	uint64_t __io rsvd;
+};
+
+struct mcs_cam_entry_read_rsp {
+	struct mbox_msghdr hdr;
+	uint64_t __io reg_val[10];
+	uint8_t __io rsrc_type;
+	uint8_t __io rsrc_id;
+	uint8_t __io mcs_id;
+	uint8_t __io dir;
+	uint64_t __io rsvd;
+};
+
 struct mcs_hw_info {
 	struct mbox_msghdr hdr;
 	uint8_t __io num_mcs_blks; /* Number of MCS blocks */
@@ -802,6 +834,30 @@ struct mcs_hw_info {
 	uint64_t __io rsvd[16];
 };
 
+struct mcs_set_active_lmac {
+	struct mbox_msghdr hdr;
+	uint32_t __io lmac_bmap; /* bitmap of active lmac per mcs block */
+	uint8_t __io mcs_id;
+	uint16_t channel_base; /* MCS channel base */
+	uint64_t __io rsvd;
+};
+
+struct mcs_set_lmac_mode {
+	struct mbox_msghdr hdr;
+	uint8_t __io mode; /* '1' for internal bypass mode (passthrough), '0' for MCS processing */
+	uint8_t __io lmac_id;
+	uint8_t __io mcs_id;
+	uint64_t __io rsvd;
+};
+
+struct mcs_set_pn_threshold {
+	struct mbox_msghdr hdr;
+	uint64_t __io threshold;
+	uint8_t __io xpn; /* '1' for setting xpn threshold */
+	uint8_t __io mcs_id;
+	uint8_t __io dir;
+	uint64_t __io rsvd;
+};
 
 /* NPA mbox message formats */
 
drivers/common/cnxk/roc_mcs.c +71 -0

77 lines not on this page · raw message

drivers/common/cnxk/roc_mcs.h +48 -0

72 lines not on this page · raw message

drivers/common/cnxk/roc_mcs_sec_cfg.c +31 -0
index 50369c73d7..99afb63904 100644
@@ -210,6 +210,37 @@ roc_mcs_sa_policy_read(struct roc_mcs *mcs __plt_unused,
 	return -ENOTSUP;
 }
 
+int
+roc_mcs_pn_table_write(struct roc_mcs *mcs, struct roc_mcs_pn_table_write_req *pn_table)
+{
+	struct mcs_pn_table_write_req *pn;
+	struct msg_rsp *rsp;
+
+	MCS_SUPPORT_CHECK;
+
+	if (pn_table == NULL)
+		return -EINVAL;
+
+	pn = mbox_alloc_msg_mcs_pn_table_write(mcs->mbox);
+	if (pn == NULL)
+		return -ENOMEM;
+
+	pn->next_pn = pn_table->next_pn;
+	pn->pn_id = pn_table->pn_id;
+	pn->mcs_id = mcs->idx;
+	pn->dir = pn_table->dir;
+
+	return mbox_process_msg(mcs->mbox, (void *)&rsp);
+}
+
+int
+roc_mcs_pn_table_read(struct roc_mcs *mcs __plt_unused,
+		      struct roc_mcs_pn_table_write_req *sa __plt_unused)
+{
+	MCS_SUPPORT_CHECK;
+
+	return -ENOTSUP;
+}
 
 int
 roc_mcs_rx_sc_cam_write(struct roc_mcs *mcs, struct roc_mcs_rx_sc_cam_write_req *rx_sc_cam)
drivers/common/cnxk/version.map +5 -0
index cb821de9ac..9be7887967 100644
@@ -133,6 +133,7 @@ INTERNAL {
 	roc_se_auth_key_set;
 	roc_se_ciph_key_set;
 	roc_se_ctx_init;
+	roc_mcs_active_lmac_set;
 	roc_mcs_alloc_rsrc;
 	roc_mcs_dev_init;
 	roc_mcs_dev_fini;
@@ -142,6 +143,10 @@ INTERNAL {
 	roc_mcs_flowid_entry_write;
 	roc_mcs_free_rsrc;
 	roc_mcs_hw_info_get;
+	roc_mcs_lmac_mode_set;
+	roc_mcs_pn_table_write;
+	roc_mcs_pn_table_read;
+	roc_mcs_pn_threshold_set;
 	roc_mcs_rx_sc_cam_enable;
 	roc_mcs_rx_sc_cam_read;
 	roc_mcs_rx_sc_cam_write;
Signature · 1 line
2.25.1
#80 lore raw

Re: [PATCH 05/15] common/cnxk: add MACsec PN and LMAC mode configuration

drivers/common/cnxk/roc_mbox.h struct mcs_hw_info { · line 841

Quoted 12 lines · Akhil Goyal

Added ROC APIs for setting packet number and LMAC
related configurations.

drivers/common/cnxk/roc_mbox.h +5 -0
+struct mcs_set_active_lmac {
+       struct mbox_msghdr hdr;
+       uint32_t __io lmac_bmap; /* bitmap of active lmac per mcs block */
+       uint8_t __io mcs_id;
+       uint16_t channel_base; /* MCS channel base */

Gotcha . Found a missing __io

Quoted 3 lines
drivers/common/cnxk/roc_mbox.h +3 -0
+       uint64_t __io rsvd;
+};
+
#81 lore raw

PATCH 6/15 common/cnxk: add MACsec stats

In reply to Akhil Goyal

Added ROC APIs for MACsec stats for SC/SECY/FLOW/PORT

---
 drivers/common/cnxk/meson.build     |   1 +
 drivers/common/cnxk/roc_mbox.h      |  93 ++++++++++++++
 drivers/common/cnxk/roc_mcs.h       |  85 ++++++++++++
 drivers/common/cnxk/roc_mcs_stats.c | 193 ++++++++++++++++++++++++++++
 drivers/common/cnxk/version.map     |   5 +
 5 files changed, 377 insertions(+)
 create mode 100644 drivers/common/cnxk/roc_mcs_stats.c
drivers/common/cnxk/meson.build +1 -0
index 589baf74fe..79e10bac74 100644
@@ -28,6 +28,7 @@ sources = files(
         'roc_mbox.c',
         'roc_mcs.c',
         'roc_mcs_sec_cfg.c',
+        'roc_mcs_stats.c',
         'roc_ml.c',
         'roc_model.c',
         'roc_nix.c',
drivers/common/cnxk/roc_mbox.h +93 -0

105 lines not on this page · raw message

drivers/common/cnxk/roc_mcs.h +85 -0

95 lines not on this page · raw message

drivers/common/cnxk/roc_mcs_stats.c new file +193 -0

193 lines not on this page · raw message

drivers/common/cnxk/version.map +5 -0
index 9be7887967..4b832f2303 100644
@@ -141,12 +141,14 @@ INTERNAL {
 	roc_mcs_flowid_entry_enable;
 	roc_mcs_flowid_entry_read;
 	roc_mcs_flowid_entry_write;
+	roc_mcs_flowid_stats_get;
 	roc_mcs_free_rsrc;
 	roc_mcs_hw_info_get;
 	roc_mcs_lmac_mode_set;
 	roc_mcs_pn_table_write;
 	roc_mcs_pn_table_read;
 	roc_mcs_pn_threshold_set;
+	roc_mcs_port_stats_get;
 	roc_mcs_rx_sc_cam_enable;
 	roc_mcs_rx_sc_cam_read;
 	roc_mcs_rx_sc_cam_write;
@@ -154,8 +156,11 @@ INTERNAL {
 	roc_mcs_rx_sc_sa_map_write;
 	roc_mcs_sa_policy_read;
 	roc_mcs_sa_policy_write;
+	roc_mcs_sc_stats_get;
 	roc_mcs_secy_policy_read;
 	roc_mcs_secy_policy_write;
+	roc_mcs_secy_stats_get;
+	roc_mcs_stats_clear;
 	roc_mcs_tx_sc_sa_map_read;
 	roc_mcs_tx_sc_sa_map_write;
 	roc_nix_bpf_alloc;
Signature · 1 line
2.25.1
#82 lore raw

PATCH 7/15 common/cnxk: add MACsec interrupt APIs

In reply to Akhil Goyal

Added ROC APIs to support various MACsec interrupts.

---
 drivers/common/cnxk/roc_dev.c      |  86 +++++++++++++++++
 drivers/common/cnxk/roc_mbox.h     |  37 +++++++-
 drivers/common/cnxk/roc_mcs.c      | 117 +++++++++++++++++++++++
 drivers/common/cnxk/roc_mcs.h      | 144 +++++++++++++++++++++++++++++
 drivers/common/cnxk/roc_mcs_priv.h |   8 ++
 drivers/common/cnxk/version.map    |   3 +
 6 files changed, 394 insertions(+), 1 deletion(-)
drivers/common/cnxk/roc_dev.c +86 -0
index 2388237186..199d37d703 100644
@@ -500,6 +500,91 @@ pf_vf_mbox_send_up_msg(struct dev *dev, void *rec_msg)
 	}
 }
 
+static int
+mbox_up_handler_mcs_intr_notify(struct dev *dev, struct mcs_intr_info *info, struct msg_rsp *rsp)
+{
+	struct roc_mcs_event_desc desc = {0};
+	struct roc_mcs *mcs;
+
+	plt_base_dbg("pf:%d/vf:%d msg id 0x%x (%s) from: pf:%d/vf:%d", dev_get_pf(dev->pf_func),
+		     dev_get_vf(dev->pf_func), info->hdr.id, mbox_id2name(info->hdr.id),
+		     dev_get_pf(info->hdr.pcifunc), dev_get_vf(info->hdr.pcifunc));
+
+	mcs = roc_mcs_dev_get(info->mcs_id);
+	if (!mcs)
+		goto exit;
+
+	if (info->intr_mask) {
+		switch (info->intr_mask) {
+		case MCS_CPM_RX_SECTAG_V_EQ1_INT:
+			desc.type = ROC_MCS_EVENT_SECTAG_VAL_ERR;
+			desc.subtype = ROC_MCS_EVENT_RX_SECTAG_V_EQ1;
+			break;
+		case MCS_CPM_RX_SECTAG_E_EQ0_C_EQ1_INT:
+			desc.type = ROC_MCS_EVENT_SECTAG_VAL_ERR;
+			desc.subtype = ROC_MCS_EVENT_RX_SECTAG_E_EQ0_C_EQ1;
+			break;
+		case MCS_CPM_RX_SECTAG_SL_GTE48_INT:
+			desc.type = ROC_MCS_EVENT_SECTAG_VAL_ERR;
+			desc.subtype = ROC_MCS_EVENT_RX_SECTAG_SL_GTE48;
+			break;
+		case MCS_CPM_RX_SECTAG_ES_EQ1_SC_EQ1_INT:
+			desc.type = ROC_MCS_EVENT_SECTAG_VAL_ERR;
+			desc.subtype = ROC_MCS_EVENT_RX_SECTAG_ES_EQ1_SC_EQ1;
+			break;
+		case MCS_CPM_RX_SECTAG_SC_EQ1_SCB_EQ1_INT:
+			desc.type = ROC_MCS_EVENT_SECTAG_VAL_ERR;
+			desc.subtype = ROC_MCS_EVENT_RX_SECTAG_SC_EQ1_SCB_EQ1;
+			break;
+		case MCS_CPM_RX_PACKET_XPN_EQ0_INT:
+			desc.type = ROC_MCS_EVENT_RX_SA_PN_HARD_EXP;
+			desc.metadata.sa_idx = info->sa_id;
+			break;
+		case MCS_CPM_RX_PN_THRESH_REACHED_INT:
+			desc.type = ROC_MCS_EVENT_RX_SA_PN_SOFT_EXP;
+			desc.metadata.sa_idx = info->sa_id;
+			break;
+		case MCS_CPM_TX_PACKET_XPN_EQ0_INT:
+			desc.type = ROC_MCS_EVENT_TX_SA_PN_HARD_EXP;
+			desc.metadata.sa_idx = info->sa_id;
+			break;
+		case MCS_CPM_TX_PN_THRESH_REACHED_INT:
+			desc.type = ROC_MCS_EVENT_TX_SA_PN_SOFT_EXP;
+			desc.metadata.sa_idx = info->sa_id;
+			break;
+		case MCS_CPM_TX_SA_NOT_VALID_INT:
+			desc.type = ROC_MCS_EVENT_SA_NOT_VALID;
+			break;
+		case MCS_BBE_RX_DFIFO_OVERFLOW_INT:
+		case MCS_BBE_TX_DFIFO_OVERFLOW_INT:
+			desc.type = ROC_MCS_EVENT_FIFO_OVERFLOW;
+			desc.subtype = ROC_MCS_EVENT_DATA_FIFO_OVERFLOW;
+			desc.metadata.lmac_id = info->lmac_id;
+			break;
+		case MCS_BBE_RX_PLFIFO_OVERFLOW_INT:
+		case MCS_BBE_TX_PLFIFO_OVERFLOW_INT:
+			desc.type = ROC_MCS_EVENT_FIFO_OVERFLOW;
+			desc.subtype = ROC_MCS_EVENT_POLICY_FIFO_OVERFLOW;
+			desc.metadata.lmac_id = info->lmac_id;
+			break;
+		case MCS_PAB_RX_CHAN_OVERFLOW_INT:
+		case MCS_PAB_TX_CHAN_OVERFLOW_INT:
+			desc.type = ROC_MCS_EVENT_FIFO_OVERFLOW;
+			desc.subtype = ROC_MCS_EVENT_PKT_ASSM_FIFO_OVERFLOW;
+			desc.metadata.lmac_id = info->lmac_id;
+			break;
+		default:
+			goto exit;
+		}
+
+		mcs_event_cb_process(mcs, &desc);
+	}
+
+exit:
+	rsp->hdr.rc = 0;
+	return 0;
+}
+
 static int
 mbox_up_handler_cgx_link_event(struct dev *dev, struct cgx_link_info_msg *msg,
 			       struct msg_rsp *rsp)
@@ -588,6 +673,7 @@ mbox_process_msgs_up(struct dev *dev, struct mbox_msghdr *req)
 		return err;                                                    \
 	}
 		MBOX_UP_CGX_MESSAGES
+		MBOX_UP_MCS_MESSAGES
 #undef M
 	}
 
drivers/common/cnxk/roc_mbox.h +36 -1
index 1cbe66cc0c..6e2b32a43f 100644
@@ -296,6 +296,7 @@ struct mbox_msghdr {
 	M(MCS_GET_SC_STATS, 0xa00e, mcs_get_sc_stats, mcs_stats_req, mcs_sc_stats)                 \
 	M(MCS_GET_PORT_STATS, 0xa010, mcs_get_port_stats, mcs_stats_req, mcs_port_stats)           \
 	M(MCS_CLEAR_STATS, 0xa011, mcs_clear_stats, mcs_clear_stats, msg_rsp)                      \
+	M(MCS_INTR_CFG, 0xa012, mcs_intr_cfg, mcs_intr_cfg, msg_rsp)                               \
 	M(MCS_SET_LMAC_MODE, 0xa013, mcs_set_lmac_mode, mcs_set_lmac_mode, msg_rsp)                \
 	M(MCS_SET_PN_THRESHOLD, 0xa014, mcs_set_pn_threshold, mcs_set_pn_threshold, msg_rsp)       \
 
@@ -304,9 +305,11 @@ struct mbox_msghdr {
 	M(CGX_LINK_EVENT, 0xC00, cgx_link_event, cgx_link_info_msg, msg_rsp)   \
 	M(CGX_PTP_RX_INFO, 0xC01, cgx_ptp_rx_info, cgx_ptp_rx_info_msg, msg_rsp)
 
+#define MBOX_UP_MCS_MESSAGES M(MCS_INTR_NOTIFY, 0xE00, mcs_intr_notify, mcs_intr_info, msg_rsp)
+
 enum {
 #define M(_name, _id, _1, _2, _3) MBOX_MSG_##_name = _id,
-	MBOX_MESSAGES MBOX_UP_CGX_MESSAGES
+	MBOX_MESSAGES MBOX_UP_CGX_MESSAGES MBOX_UP_MCS_MESSAGES
 #undef M
 };
 
@@ -847,6 +850,38 @@ struct mcs_set_active_lmac {
 	uint64_t __io rsvd;
 };
 
+#define MCS_CPM_RX_SECTAG_V_EQ1_INT	     BIT_ULL(0)
+#define MCS_CPM_RX_SECTAG_E_EQ0_C_EQ1_INT    BIT_ULL(1)
+#define MCS_CPM_RX_SECTAG_SL_GTE48_INT	     BIT_ULL(2)
+#define MCS_CPM_RX_SECTAG_ES_EQ1_SC_EQ1_INT  BIT_ULL(3)
+#define MCS_CPM_RX_SECTAG_SC_EQ1_SCB_EQ1_INT BIT_ULL(4)
+#define MCS_CPM_RX_PACKET_XPN_EQ0_INT	     BIT_ULL(5)
+#define MCS_CPM_RX_PN_THRESH_REACHED_INT     BIT_ULL(6)
+#define MCS_CPM_TX_PACKET_XPN_EQ0_INT	     BIT_ULL(7)
+#define MCS_CPM_TX_PN_THRESH_REACHED_INT     BIT_ULL(8)
+#define MCS_CPM_TX_SA_NOT_VALID_INT	     BIT_ULL(9)
+#define MCS_BBE_RX_DFIFO_OVERFLOW_INT	     BIT_ULL(10)
+#define MCS_BBE_RX_PLFIFO_OVERFLOW_INT	     BIT_ULL(11)
+#define MCS_BBE_TX_DFIFO_OVERFLOW_INT	     BIT_ULL(12)
+#define MCS_BBE_TX_PLFIFO_OVERFLOW_INT	     BIT_ULL(13)
+#define MCS_PAB_RX_CHAN_OVERFLOW_INT	     BIT_ULL(14)
+#define MCS_PAB_TX_CHAN_OVERFLOW_INT	     BIT_ULL(15)
+
+struct mcs_intr_cfg {
+	struct mbox_msghdr hdr;
+	uint64_t __io intr_mask; /* Interrupt enable mask */
+	uint8_t __io mcs_id;
+};
+
+struct mcs_intr_info {
+	struct mbox_msghdr hdr;
+	uint64_t __io intr_mask;
+	int __io sa_id;
+	uint8_t __io mcs_id;
+	uint8_t __io lmac_id;
+	uint64_t __io rsvd;
+};
+
 struct mcs_set_lmac_mode {
 	struct mbox_msghdr hdr;
 	uint8_t __io mode; /* '1' for internal bypass mode (passthrough), '0' for MCS processing */
drivers/common/cnxk/roc_mcs.c +117 -0

141 lines not on this page · raw message

drivers/common/cnxk/roc_mcs.h +144 -0

160 lines not on this page · raw message

drivers/common/cnxk/roc_mcs_priv.h +8 -0
index 22915d206f..2c40f71d1d 100644
@@ -62,4 +62,12 @@ roc_mcs_to_mcs_priv(struct roc_mcs *roc_mcs)
 	return (struct mcs_priv *)&roc_mcs->reserved[0];
 }
 
+static inline void *
+roc_mcs_to_mcs_cb_list(struct roc_mcs *roc_mcs)
+{
+	return (void *)((uintptr_t)roc_mcs->reserved + sizeof(struct mcs_priv));
+}
+
+int mcs_event_cb_process(struct roc_mcs *mcs, struct roc_mcs_event_desc *desc);
+
 #endif /* _ROC_MCS_PRIV_H_ */
drivers/common/cnxk/version.map +3 -0
index 4b832f2303..97f107dd05 100644
@@ -138,12 +138,15 @@ INTERNAL {
 	roc_mcs_dev_init;
 	roc_mcs_dev_fini;
 	roc_mcs_dev_get;
+	roc_mcs_event_cb_register;
+	roc_mcs_event_cb_unregister;
 	roc_mcs_flowid_entry_enable;
 	roc_mcs_flowid_entry_read;
 	roc_mcs_flowid_entry_write;
 	roc_mcs_flowid_stats_get;
 	roc_mcs_free_rsrc;
 	roc_mcs_hw_info_get;
+	roc_mcs_intr_configure;
 	roc_mcs_lmac_mode_set;
 	roc_mcs_pn_table_write;
 	roc_mcs_pn_table_read;
Signature · 1 line
2.25.1
#83 lore raw

PATCH 8/15 common/cnxk: add MACsec port configuration

In reply to Akhil Goyal

Added ROC APIs for MACsec port configurations

---
 drivers/common/cnxk/roc_mbox.h  |  40 ++++
 drivers/common/cnxk/roc_mcs.c   | 345 ++++++++++++++++++++++++++++++++
 drivers/common/cnxk/roc_mcs.h   |  48 +++++
 drivers/common/cnxk/version.map |   4 +
 4 files changed, 437 insertions(+)
drivers/common/cnxk/roc_mbox.h +40 -0
index 6e2b32a43f..96515deafd 100644
@@ -299,6 +299,9 @@ struct mbox_msghdr {
 	M(MCS_INTR_CFG, 0xa012, mcs_intr_cfg, mcs_intr_cfg, msg_rsp)                               \
 	M(MCS_SET_LMAC_MODE, 0xa013, mcs_set_lmac_mode, mcs_set_lmac_mode, msg_rsp)                \
 	M(MCS_SET_PN_THRESHOLD, 0xa014, mcs_set_pn_threshold, mcs_set_pn_threshold, msg_rsp)       \
+	M(MCS_PORT_RESET, 0xa018, mcs_port_reset, mcs_port_reset_req, msg_rsp)                     \
+	M(MCS_PORT_CFG_SET, 0xa019, mcs_port_cfg_set, mcs_port_cfg_set_req, msg_rsp)               \
+	M(MCS_PORT_CFG_GET, 0xa020, mcs_port_cfg_get, mcs_port_cfg_get_req, mcs_port_cfg_get_rsp)  \
 
 /* Messages initiated by AF (range 0xC00 - 0xDFF) */
 #define MBOX_UP_CGX_MESSAGES                                                   \
@@ -899,6 +902,43 @@ struct mcs_set_pn_threshold {
 	uint64_t __io rsvd;
 };
 
+struct mcs_port_cfg_set_req {
+	struct mbox_msghdr hdr;
+	uint8_t __io cstm_tag_rel_mode_sel;
+	uint8_t __io custom_hdr_enb;
+	uint8_t __io fifo_skid;
+	uint8_t __io lmac_mode;
+	uint8_t __io lmac_id;
+	uint8_t __io mcs_id;
+	uint64_t __io rsvd;
+};
+
+struct mcs_port_cfg_get_req {
+	struct mbox_msghdr hdr;
+	uint8_t __io lmac_id;
+	uint8_t __io mcs_id;
+	uint64_t __io rsvd;
+};
+
+struct mcs_port_cfg_get_rsp {
+	struct mbox_msghdr hdr;
+	uint8_t __io cstm_tag_rel_mode_sel;
+	uint8_t __io custom_hdr_enb;
+	uint8_t __io fifo_skid;
+	uint8_t __io lmac_mode;
+	uint8_t __io lmac_id;
+	uint8_t __io mcs_id;
+	uint64_t __io rsvd;
+};
+
+struct mcs_port_reset_req {
+	struct mbox_msghdr hdr;
+	uint8_t __io reset;
+	uint8_t __io mcs_id;
+	uint8_t __io lmac_id;
+	uint64_t __io rsvd;
+};
+
 struct mcs_stats_req {
 	struct mbox_msghdr hdr;
 	uint8_t __io id;
drivers/common/cnxk/roc_mcs.c +345 -0

363 lines not on this page · raw message

drivers/common/cnxk/roc_mcs.h +48 -0

64 lines not on this page · raw message

drivers/common/cnxk/version.map +4 -0
index 97f107dd05..9ba804a04f 100644
@@ -151,6 +151,10 @@ INTERNAL {
 	roc_mcs_pn_table_write;
 	roc_mcs_pn_table_read;
 	roc_mcs_pn_threshold_set;
+	roc_mcs_port_cfg_get;
+	roc_mcs_port_cfg_set;
+	roc_mcs_port_recovery;
+	roc_mcs_port_reset;
 	roc_mcs_port_stats_get;
 	roc_mcs_rx_sc_cam_enable;
 	roc_mcs_rx_sc_cam_read;
Signature · 1 line
2.25.1
#84 lore raw

PATCH 9/15 common/cnxk: add MACsec control port configuration

In reply to Akhil Goyal

Added ROC APIs to configure MACsec control port.

---
 drivers/common/cnxk/roc_mbox.h  |  72 ++++++++++++++++++++
 drivers/common/cnxk/roc_mcs.c   | 117 ++++++++++++++++++++++++++++++++
 drivers/common/cnxk/roc_mcs.h   |  65 ++++++++++++++++++
 drivers/common/cnxk/version.map |   4 ++
 4 files changed, 258 insertions(+)
drivers/common/cnxk/roc_mbox.h +72 -0
index 96515deafd..ad97ceffb8 100644
@@ -299,9 +299,17 @@ struct mbox_msghdr {
 	M(MCS_INTR_CFG, 0xa012, mcs_intr_cfg, mcs_intr_cfg, msg_rsp)                               \
 	M(MCS_SET_LMAC_MODE, 0xa013, mcs_set_lmac_mode, mcs_set_lmac_mode, msg_rsp)                \
 	M(MCS_SET_PN_THRESHOLD, 0xa014, mcs_set_pn_threshold, mcs_set_pn_threshold, msg_rsp)       \
+	M(MCS_ALLOC_CTRL_PKT_RULE, 0xa015, mcs_alloc_ctrl_pkt_rule, mcs_alloc_ctrl_pkt_rule_req,   \
+	  mcs_alloc_ctrl_pkt_rule_rsp)                                                             \
+	M(MCS_FREE_CTRL_PKT_RULE, 0xa016, mcs_free_ctrl_pkt_rule, mcs_free_ctrl_pkt_rule_req,      \
+	  msg_rsp)                                                                                 \
+	M(MCS_CTRL_PKT_RULE_WRITE, 0xa017, mcs_ctrl_pkt_rule_write, mcs_ctrl_pkt_rule_write_req,   \
+	  msg_rsp)                                                                                 \
 	M(MCS_PORT_RESET, 0xa018, mcs_port_reset, mcs_port_reset_req, msg_rsp)                     \
 	M(MCS_PORT_CFG_SET, 0xa019, mcs_port_cfg_set, mcs_port_cfg_set_req, msg_rsp)               \
 	M(MCS_PORT_CFG_GET, 0xa020, mcs_port_cfg_get, mcs_port_cfg_get_req, mcs_port_cfg_get_rsp)  \
+	M(MCS_CUSTOM_TAG_CFG_GET, 0xa021, mcs_custom_tag_cfg_get, mcs_custom_tag_cfg_get_req,      \
+	  mcs_custom_tag_cfg_get_rsp)                                                              \
 
 /* Messages initiated by AF (range 0xC00 - 0xDFF) */
 #define MBOX_UP_CGX_MESSAGES                                                   \
@@ -902,6 +910,53 @@ struct mcs_set_pn_threshold {
 	uint64_t __io rsvd;
 };
 
+enum mcs_ctrl_pkt_rule_type {
+	MCS_CTRL_PKT_RULE_TYPE_ETH,
+	MCS_CTRL_PKT_RULE_TYPE_DA,
+	MCS_CTRL_PKT_RULE_TYPE_RANGE,
+	MCS_CTRL_PKT_RULE_TYPE_COMBO,
+	MCS_CTRL_PKT_RULE_TYPE_MAC,
+};
+
+struct mcs_alloc_ctrl_pkt_rule_req {
+	struct mbox_msghdr hdr;
+	uint8_t __io rule_type;
+	uint8_t __io mcs_id; /* MCS block ID */
+	uint8_t __io dir;    /* Macsec ingress or egress side */
+	uint64_t __io rsvd;
+};
+
+struct mcs_alloc_ctrl_pkt_rule_rsp {
+	struct mbox_msghdr hdr;
+	uint8_t __io rule_idx;
+	uint8_t __io rule_type;
+	uint8_t __io mcs_id;
+	uint8_t __io dir;
+	uint64_t __io rsvd;
+};
+
+struct mcs_free_ctrl_pkt_rule_req {
+	struct mbox_msghdr hdr;
+	uint8_t __io rule_idx;
+	uint8_t __io rule_type;
+	uint8_t __io mcs_id;
+	uint8_t __io dir;
+	uint8_t __io all; /* Free all the rule resources */
+	uint64_t __io rsvd;
+};
+
+struct mcs_ctrl_pkt_rule_write_req {
+	struct mbox_msghdr hdr;
+	uint64_t __io data0;
+	uint64_t __io data1;
+	uint64_t __io data2;
+	uint8_t __io rule_idx;
+	uint8_t __io rule_type;
+	uint8_t __io mcs_id;
+	uint8_t __io dir;
+	uint64_t __io rsvd;
+};
+
 struct mcs_port_cfg_set_req {
 	struct mbox_msghdr hdr;
 	uint8_t __io cstm_tag_rel_mode_sel;
@@ -931,6 +986,23 @@ struct mcs_port_cfg_get_rsp {
 	uint64_t __io rsvd;
 };
 
+struct mcs_custom_tag_cfg_get_req {
+	struct mbox_msghdr hdr;
+	uint8_t __io mcs_id;
+	uint8_t __io dir;
+	uint64_t __io rsvd;
+};
+
+struct mcs_custom_tag_cfg_get_rsp {
+	struct mbox_msghdr hdr;
+	uint16_t __io cstm_etype[8];
+	uint8_t __io cstm_indx[8];
+	uint8_t __io cstm_etype_en;
+	uint8_t __io mcs_id;
+	uint8_t __io dir;
+	uint64_t __io rsvd;
+};
+
 struct mcs_port_reset_req {
 	struct mbox_msghdr hdr;
 	uint8_t __io reset;
drivers/common/cnxk/roc_mcs.c +117 -0

129 lines not on this page · raw message

drivers/common/cnxk/roc_mcs.h +65 -0

89 lines not on this page · raw message

drivers/common/cnxk/version.map +4 -0
index 9ba804a04f..e501cdd4d9 100644
@@ -134,7 +134,10 @@ INTERNAL {
 	roc_se_ciph_key_set;
 	roc_se_ctx_init;
 	roc_mcs_active_lmac_set;
+	roc_mcs_alloc_ctrl_pkt_rule;
 	roc_mcs_alloc_rsrc;
+	roc_mcs_ctrl_pkt_rule_write;
+	roc_mcs_custom_tag_cfg_get;
 	roc_mcs_dev_init;
 	roc_mcs_dev_fini;
 	roc_mcs_dev_get;
@@ -144,6 +147,7 @@ INTERNAL {
 	roc_mcs_flowid_entry_read;
 	roc_mcs_flowid_entry_write;
 	roc_mcs_flowid_stats_get;
+	roc_mcs_free_ctrl_pkt_rule;
 	roc_mcs_free_rsrc;
 	roc_mcs_hw_info_get;
 	roc_mcs_intr_configure;
Signature · 1 line
2.25.1
#85 lore raw

Re: [PATCH 09/15] common/cnxk: add MACsec control port configuration

Quoted 15 lines · Akhil Goyal

Added ROC APIs to configure MACsec control port.

---

__roc_api int roc_mcs_flowid_stats_get(struct roc_mcs *mcs, struct roc_mcs_stats_req *mcs_req,

                                       struct roc_mcs_flowid_stats *stats);
drivers/common/cnxk/version.map +0 -0
index 9ba804a04f..e501cdd4d9 100644

drivers/common/cnxk/version.map INTERNAL { · line 137

Quoted 4 lines
drivers/common/cnxk/version.map +1 -0
@@ -134,7 +134,10 @@ INTERNAL {
        roc_se_ciph_key_set;
        roc_se_ctx_init;
        roc_mcs_active_lmac_set;
+       roc_mcs_alloc_ctrl_pkt_rule;

roc_mcs_ctrl_pkt_rule_alloc

drivers/common/cnxk/version.map INTERNAL { · line 150

Quoted 11 lines
drivers/common/cnxk/version.map +3 -0
        roc_mcs_alloc_rsrc;
+       roc_mcs_ctrl_pkt_rule_write;
+       roc_mcs_custom_tag_cfg_get;
        roc_mcs_dev_init;
        roc_mcs_dev_fini;
        roc_mcs_dev_get;
@@ -144,6 +147,7 @@ INTERNAL {
        roc_mcs_flowid_entry_read;
        roc_mcs_flowid_entry_write;
        roc_mcs_flowid_stats_get;
+       roc_mcs_free_ctrl_pkt_rule;

roc_mcs_ctrl_pkt_rule_free

Quoted 6 lines
drivers/common/cnxk/version.map +0 -1
        roc_mcs_free_rsrc;
        roc_mcs_hw_info_get;
        roc_mcs_intr_configure;
--

2.25.1

#86 lore raw

PATCH 10/15 common/cnxk: add MACsec FIPS mbox

In reply to Akhil Goyal

Added MACsec FIPS configuration mbox

---
 drivers/common/cnxk/roc_mbox.h | 74 ++++++++++++++++++++++++++++++++++
 drivers/common/cnxk/roc_mcs.h  | 69 +++++++++++++++++++++++++++++++
 2 files changed, 143 insertions(+)
drivers/common/cnxk/roc_mbox.h +74 -0
index ad97ceffb8..7057823112 100644
@@ -310,6 +310,15 @@ struct mbox_msghdr {
 	M(MCS_PORT_CFG_GET, 0xa020, mcs_port_cfg_get, mcs_port_cfg_get_req, mcs_port_cfg_get_rsp)  \
 	M(MCS_CUSTOM_TAG_CFG_GET, 0xa021, mcs_custom_tag_cfg_get, mcs_custom_tag_cfg_get_req,      \
 	  mcs_custom_tag_cfg_get_rsp)                                                              \
+	M(MCS_FIPS_RESET, 0xa040, mcs_fips_reset, mcs_fips_req, msg_rsp)                           \
+	M(MCS_FIPS_MODE_SET, 0xa041, mcs_fips_mode_set, mcs_fips_mode_req, msg_rsp)                \
+	M(MCS_FIPS_CTL_SET, 0xa042, mcs_fips_ctl_set, mcs_fips_ctl_req, msg_rsp)                   \
+	M(MCS_FIPS_IV_SET, 0xa043, mcs_fips_iv_set, mcs_fips_iv_req, msg_rsp)                      \
+	M(MCS_FIPS_CTR_SET, 0xa044, mcs_fips_ctr_set, mcs_fips_ctr_req, msg_rsp)                   \
+	M(MCS_FIPS_KEY_SET, 0xa045, mcs_fips_key_set, mcs_fips_key_req, msg_rsp)                   \
+	M(MCS_FIPS_BLOCK_SET, 0xa046, mcs_fips_block_set, mcs_fips_block_req, msg_rsp)             \
+	M(MCS_FIPS_START, 0xa047, mcs_fips_start, mcs_fips_req, msg_rsp)                           \
+	M(MCS_FIPS_RESULT_GET, 0xa048, mcs_fips_result_get, mcs_fips_req, mcs_fips_result_rsp)
 
 /* Messages initiated by AF (range 0xC00 - 0xDFF) */
 #define MBOX_UP_CGX_MESSAGES                                                   \
@@ -1099,6 +1108,71 @@ struct mcs_clear_stats {
 	uint8_t __io all; /* All resources stats mapped to PF are cleared */
 };
 
+struct mcs_fips_req {
+	struct mbox_msghdr hdr;
+	uint8_t __io mcs_id;
+	uint8_t __io dir;
+};
+
+struct mcs_fips_mode_req {
+	struct mbox_msghdr hdr;
+	uint64_t __io mode;
+	uint8_t __io mcs_id;
+	uint8_t __io dir;
+};
+
+struct mcs_fips_ctl_req {
+	struct mbox_msghdr hdr;
+	uint64_t __io ctl;
+	uint8_t __io mcs_id;
+	uint8_t __io dir;
+};
+
+struct mcs_fips_iv_req {
+	struct mbox_msghdr hdr;
+	uint32_t __io iv_bits95_64;
+	uint64_t __io iv_bits63_0;
+	uint8_t __io mcs_id;
+	uint8_t __io dir;
+};
+
+struct mcs_fips_ctr_req {
+	struct mbox_msghdr hdr;
+	uint32_t __io fips_ctr;
+	uint8_t __io mcs_id;
+	uint8_t __io dir;
+};
+
+struct mcs_fips_key_req {
+	struct mbox_msghdr hdr;
+	uint64_t __io sak_bits255_192;
+	uint64_t __io sak_bits191_128;
+	uint64_t __io sak_bits127_64;
+	uint64_t __io sak_bits63_0;
+	uint64_t __io hashkey_bits127_64;
+	uint64_t __io hashkey_bits63_0;
+	uint8_t __io sak_len;
+	uint8_t __io mcs_id;
+	uint8_t __io dir;
+};
+
+struct mcs_fips_block_req {
+	struct mbox_msghdr hdr;
+	uint64_t __io blk_bits127_64;
+	uint64_t __io blk_bits63_0;
+	uint8_t __io mcs_id;
+	uint8_t __io dir;
+};
+
+struct mcs_fips_result_rsp {
+	struct mbox_msghdr hdr;
+	uint64_t __io blk_bits127_64;
+	uint64_t __io blk_bits63_0;
+	uint64_t __io icv_bits127_64;
+	uint64_t __io icv_bits63_0;
+	uint8_t __io result_pass;
+};
+
 /* NPA mbox message formats */
 
 /* NPA mailbox error codes
drivers/common/cnxk/roc_mcs.h +69 -0

79 lines not on this page · raw message

Signature · 1 line
2.25.1
#87 lore raw

PATCH 11/15 common/cnxk: derive hash key for MACsec

In reply to Akhil Goyal

MACsec hardware configuration need hash key to be generated from the cipher key of AES-GCM-128/256.
Added an ROC API to derive the hash key and extend the case for AES-256 as well.

---
 drivers/common/cnxk/roc_aes.c   | 86 ++++++++++++++++++++++-----------
 drivers/common/cnxk/roc_aes.h   |  4 +-
 drivers/common/cnxk/version.map |  1 +
 3 files changed, 60 insertions(+), 31 deletions(-)
drivers/common/cnxk/roc_aes.c +57 -29
index f821c8b710..d84feb546a 100644
@@ -4,9 +4,10 @@
 
 #include "roc_api.h"
 
-#define KEY_WORD_LEN	 (ROC_CPT_AES_XCBC_KEY_LENGTH / sizeof(uint32_t))
-#define KEY_ROUNDS	 10			/* (Nr+1)*Nb */
-#define KEY_SCHEDULE_LEN ((KEY_ROUNDS + 1) * 4) /* (Nr+1)*Nb words */
+#define KEY128_ROUNDS		10		/* (Nr+1)*Nb */
+#define KEY256_ROUNDS		14		/* (Nr+1)*Nb */
+#define KEY_SCHEDULE_LEN(nr)	((nr + 1) * 4)	/* (Nr+1)*Nb words */
+#define AES_HASH_KEY_LEN	16
 
 /*
  * AES 128 implementation based on NIST FIPS 197 suitable for LittleEndian
@@ -93,22 +94,30 @@ GF8mul(uint8_t byte, uint32_t mp)
 }
 
 static void
-aes_key_expand(const uint8_t *key, uint32_t *ks)
+aes_key_expand(const uint8_t *key, uint32_t len, uint32_t *ks)
 {
-	unsigned int i = 4;
+	uint32_t len_words = len / sizeof(uint32_t);
+	unsigned int schedule_len;
+	unsigned int i = len_words;
 	uint32_t temp;
 
+	schedule_len = (len == ROC_CPT_AES128_KEY_LEN) ? KEY_SCHEDULE_LEN(KEY128_ROUNDS) :
+							 KEY_SCHEDULE_LEN(KEY256_ROUNDS);
 	/* Skip key in ks */
-	memcpy(ks, key, KEY_WORD_LEN * sizeof(uint32_t));
+	memcpy(ks, key, len);
 
-	while (i < KEY_SCHEDULE_LEN) {
+	while (i < schedule_len) {
 		temp = ks[i - 1];
-		if ((i & 0x3) == 0) {
+		if ((i & (len_words - 1)) == 0) {
 			temp = rot_word(temp);
 			temp = sub_word(temp);
-			temp ^= (uint32_t)GF8mul(1, 1 << ((i >> 2) - 1));
+			temp ^= (uint32_t)GF8mul(1, 1 << ((i / len_words) - 1));
 		}
-		ks[i] = ks[i - 4] ^ temp;
+		if (len == ROC_CPT_AES256_KEY_LEN) {
+			if ((i % len_words) == 4)
+				temp = sub_word(temp);
+		}
+		ks[i] = ks[i - len_words] ^ temp;
 		i++;
 	}
 }
@@ -145,64 +154,83 @@ mix_columns(uint8_t *sRc)
 }
 
 static void
-cipher(uint8_t *in, uint8_t *out, uint32_t *ks)
+cipher(uint8_t *in, uint8_t *out, uint32_t *ks, uint32_t key_rounds, uint8_t in_len)
 {
-	uint32_t state[KEY_WORD_LEN];
+	uint8_t data_word_len = in_len / sizeof(uint32_t);
+	uint32_t state[data_word_len];
 	unsigned int i, round;
 
 	memcpy(state, in, sizeof(state));
 
 	/* AddRoundKey(state, w[0, Nb-1]) // See Sec. 5.1.4 */
-	for (i = 0; i < KEY_WORD_LEN; i++)
+	for (i = 0; i < data_word_len; i++)
 		state[i] ^= ks[i];
 
-	for (round = 1; round < KEY_ROUNDS; round++) {
+	for (round = 1; round < key_rounds; round++) {
 		/* SubBytes(state) // See Sec. 5.1.1 */
-		for (i = 0; i < KEY_WORD_LEN; i++)
+		for (i = 0; i < data_word_len; i++)
 			state[i] = sub_word(state[i]);
 
 		/* ShiftRows(state) // See Sec. 5.1.2 */
-		for (i = 0; i < KEY_WORD_LEN; i++)
+		for (i = 0; i < data_word_len; i++)
 			shift_word((uint8_t *)state, i, i);
 
 		/* MixColumns(state) // See Sec. 5.1.3 */
-		for (i = 0; i < KEY_WORD_LEN; i++)
+		for (i = 0; i < data_word_len; i++)
 			mix_columns((uint8_t *)&state[i]);
 
 		/* AddRoundKey(state, w[round*Nb, (round+1)*Nb-1]) */
-		for (i = 0; i < KEY_WORD_LEN; i++)
-			state[i] ^= ks[round * 4 + i];
+		for (i = 0; i < data_word_len; i++)
+			state[i] ^= ks[round * data_word_len + i];
 	}
 
 	/* SubBytes(state) */
-	for (i = 0; i < KEY_WORD_LEN; i++)
+	for (i = 0; i < data_word_len; i++)
 		state[i] = sub_word(state[i]);
 
 	/* ShiftRows(state) */
-	for (i = 0; i < KEY_WORD_LEN; i++)
+	for (i = 0; i < data_word_len; i++)
 		shift_word((uint8_t *)state, i, i);
 
 	/* AddRoundKey(state, w[Nr*Nb, (Nr+1)*Nb-1]) */
-	for (i = 0; i < KEY_WORD_LEN; i++)
-		state[i] ^= ks[KEY_ROUNDS * 4 + i];
-	memcpy(out, state, KEY_WORD_LEN * sizeof(uint32_t));
+	for (i = 0; i < data_word_len; i++)
+		state[i] ^= ks[key_rounds * data_word_len + i];
+	memcpy(out, state, data_word_len * sizeof(uint32_t));
 }
 
 void
 roc_aes_xcbc_key_derive(const uint8_t *auth_key, uint8_t *derived_key)
 {
-	uint32_t aes_ks[KEY_SCHEDULE_LEN] = {0};
+	uint32_t aes_ks[KEY_SCHEDULE_LEN(KEY128_ROUNDS)] = {0};
 	uint8_t k1[16] = {[0 ... 15] = 0x01};
 	uint8_t k2[16] = {[0 ... 15] = 0x02};
 	uint8_t k3[16] = {[0 ... 15] = 0x03};
 
-	aes_key_expand(auth_key, aes_ks);
+	aes_key_expand(auth_key, ROC_CPT_AES_XCBC_KEY_LENGTH, aes_ks);
 
-	cipher(k1, derived_key, aes_ks);
+	cipher(k1, derived_key, aes_ks, KEY128_ROUNDS, sizeof(k1));
 	derived_key += sizeof(k1);
 
-	cipher(k2, derived_key, aes_ks);
+	cipher(k2, derived_key, aes_ks, KEY128_ROUNDS, sizeof(k2));
 	derived_key += sizeof(k2);
 
-	cipher(k3, derived_key, aes_ks);
+	cipher(k3, derived_key, aes_ks, KEY128_ROUNDS, sizeof(k3));
+}
+
+void
+roc_aes_hash_key_derive(const uint8_t *key, uint16_t len, uint8_t hash_key[])
+{
+	uint8_t data[AES_HASH_KEY_LEN] = {0x0};
+
+	if (len == ROC_CPT_AES128_KEY_LEN) {
+		uint32_t aes_ks[KEY_SCHEDULE_LEN(KEY128_ROUNDS)] = {0};
+
+		aes_key_expand(key, ROC_CPT_AES128_KEY_LEN, aes_ks);
+		cipher(data, hash_key, aes_ks, KEY128_ROUNDS, sizeof(data));
+	} else {
+		uint32_t aes_ks[KEY_SCHEDULE_LEN(KEY256_ROUNDS)] = {0};
+
+		aes_key_expand(key, ROC_CPT_AES256_KEY_LEN, aes_ks);
+		cipher(data, hash_key, aes_ks, KEY256_ROUNDS, sizeof(data));
+	}
 }
drivers/common/cnxk/roc_aes.h +2 -2
index 954039139f..3b4b921bcd 100644
@@ -8,7 +8,7 @@
 /*
  * Derive k1, k2, k3 from 128 bit AES key
  */
-void __roc_api roc_aes_xcbc_key_derive(const uint8_t *auth_key,
-				       uint8_t *derived_key);
+void __roc_api roc_aes_xcbc_key_derive(const uint8_t *auth_key, uint8_t *derived_key);
+void __roc_api roc_aes_hash_key_derive(const uint8_t *key, uint16_t len, uint8_t *hash_key);
 
 #endif /* _ROC_AES_H_ */
drivers/common/cnxk/version.map +1 -0
index e501cdd4d9..3e8f65f91a 100644
@@ -30,6 +30,7 @@ INTERNAL {
 	roc_ae_ec_grp_put;
 	roc_ae_fpm_get;
 	roc_ae_fpm_put;
+	roc_aes_hash_key_derive;
 	roc_aes_xcbc_key_derive;
 	roc_bphy_cgx_cpri_mode_change;
 	roc_bphy_cgx_cpri_mode_misc;
Signature · 1 line
2.25.1
#88 lore raw

PATCH 12/15 net/cnxk: add MACsec initialization

In reply to Akhil Goyal

Added initialization routines for MACsec for
cn10kb platform.

---
 drivers/net/cnxk/cn10k_ethdev_sec.c |   6 ++
 drivers/net/cnxk/cnxk_ethdev.c      |  13 +++
 drivers/net/cnxk/cnxk_ethdev.h      |  14 +++
 drivers/net/cnxk/cnxk_ethdev_mcs.c  | 151 ++++++++++++++++++++++++++++
 drivers/net/cnxk/cnxk_ethdev_mcs.h  |  61 +++++++++++
 drivers/net/cnxk/meson.build        |   1 +
 6 files changed, 246 insertions(+)
 create mode 100644 drivers/net/cnxk/cnxk_ethdev_mcs.c
 create mode 100644 drivers/net/cnxk/cnxk_ethdev_mcs.h
drivers/net/cnxk/cn10k_ethdev_sec.c +6 -0
index 3c32de0f94..655389b5ca 100644
@@ -1059,9 +1059,15 @@ cn10k_eth_sec_ops_override(void)
 	init_once = 1;
 
 	/* Update platform specific ops */
+	cnxk_eth_sec_ops.macsec_sa_create = NULL;
+	cnxk_eth_sec_ops.macsec_sc_create = NULL;
+	cnxk_eth_sec_ops.macsec_sa_destroy = NULL;
+	cnxk_eth_sec_ops.macsec_sc_destroy = NULL;
 	cnxk_eth_sec_ops.session_create = cn10k_eth_sec_session_create;
 	cnxk_eth_sec_ops.session_destroy = cn10k_eth_sec_session_destroy;
 	cnxk_eth_sec_ops.capabilities_get = cn10k_eth_sec_capabilities_get;
 	cnxk_eth_sec_ops.session_update = cn10k_eth_sec_session_update;
 	cnxk_eth_sec_ops.session_stats_get = cn10k_eth_sec_session_stats_get;
+	cnxk_eth_sec_ops.macsec_sc_stats_get = NULL;
+	cnxk_eth_sec_ops.macsec_sa_stats_get = NULL;
 }
drivers/net/cnxk/cnxk_ethdev.c +13 -0
index 42a52ed0ca..7a792937b7 100644
@@ -1945,6 +1945,16 @@ cnxk_eth_dev_init(struct rte_eth_dev *eth_dev)
 	if (rc)
 		goto free_mac_addrs;
 
+	if (roc_feature_nix_has_macsec()) {
+		rc = cnxk_mcs_dev_init(dev, 0);
+		if (rc) {
+			plt_err("Failed to init MCS");
+			goto free_mac_addrs;
+		}
+		dev->rx_offload_capa |= RTE_ETH_RX_OFFLOAD_MACSEC_STRIP;
+		dev->tx_offload_capa |= RTE_ETH_TX_OFFLOAD_MACSEC_INSERT;
+	}
+
 	plt_nix_dbg("Port=%d pf=%d vf=%d ver=%s hwcap=0x%" PRIx64
 		    " rxoffload_capa=0x%" PRIx64 " txoffload_capa=0x%" PRIx64,
 		    eth_dev->data->port_id, roc_nix_get_pf(nix),
@@ -2042,6 +2052,9 @@ cnxk_eth_dev_uninit(struct rte_eth_dev *eth_dev, bool reset)
 	}
 	eth_dev->data->nb_rx_queues = 0;
 
+	if (roc_feature_nix_has_macsec())
+		cnxk_mcs_dev_fini(dev);
+
 	/* Free security resources */
 	nix_security_release(dev);
 
drivers/net/cnxk/cnxk_ethdev.h +14 -0
index 97537de17a..6fde682344 100644
@@ -392,6 +392,9 @@ struct cnxk_eth_dev {
 	/* Reassembly dynfield/flag offsets */
 	int reass_dynfield_off;
 	int reass_dynflag_bit;
+
+	/* MCS device */
+	struct cnxk_mcs_dev *mcs_dev;
 };
 
 struct cnxk_eth_rxq_sp {
@@ -617,6 +620,17 @@ int cnxk_nix_cman_config_set(struct rte_eth_dev *dev, const struct rte_eth_cman_
 
 int cnxk_nix_cman_config_get(struct rte_eth_dev *dev, struct rte_eth_cman_config *config);
 
+int cnxk_mcs_dev_init(struct cnxk_eth_dev *dev, uint8_t mcs_idx);
+void cnxk_mcs_dev_fini(struct cnxk_eth_dev *dev);
+
+struct cnxk_macsec_sess *cnxk_eth_macsec_sess_get_by_sess(struct cnxk_eth_dev *dev,
+							  const struct rte_security_session *sess);
+int cnxk_mcs_flow_configure(struct rte_eth_dev *eth_dev, const struct rte_flow_attr *attr,
+			     const struct rte_flow_item pattern[],
+			     const struct rte_flow_action actions[], struct rte_flow_error *error,
+			     void **mcs_flow);
+int cnxk_mcs_flow_destroy(struct cnxk_eth_dev *eth_dev, void *mcs_flow);
+
 /* Other private functions */
 int nix_recalc_mtu(struct rte_eth_dev *eth_dev);
 int nix_mtr_validate(struct rte_eth_dev *dev, uint32_t id);
drivers/net/cnxk/cnxk_ethdev_mcs.c new file +151 -0

151 lines not on this page · raw message

drivers/net/cnxk/cnxk_ethdev_mcs.h new file +61 -0

61 lines not on this page · raw message

drivers/net/cnxk/meson.build +1 -0
index 62b8bb90fb..ae6a7d9aac 100644
@@ -22,6 +22,7 @@ sources = files(
         'cnxk_ethdev.c',
         'cnxk_ethdev_cman.c',
         'cnxk_ethdev_devargs.c',
+        'cnxk_ethdev_mcs.c',
         'cnxk_ethdev_mtr.c',
         'cnxk_ethdev_ops.c',
         'cnxk_ethdev_sec.c',
Signature · 1 line
2.25.1
#89 lore raw

PATCH 13/15 net/cnxk: create/destroy MACsec SC/SA

In reply to Akhil Goyal

Added support to create/destroy MACsec SA and SC.

---
 drivers/net/cnxk/cn10k_ethdev_sec.c |   9 +-
 drivers/net/cnxk/cnxk_ethdev_mcs.c  | 250 ++++++++++++++++++++++++++++
 drivers/net/cnxk/cnxk_ethdev_mcs.h  |  16 ++
 3 files changed, 271 insertions(+), 4 deletions(-)
drivers/net/cnxk/cn10k_ethdev_sec.c +5 -4
index 655389b5ca..e9bc05027f 100644
@@ -9,6 +9,7 @@
 #include <rte_pmd_cnxk.h>
 
 #include <cn10k_ethdev.h>
+#include <cnxk_ethdev_mcs.h>
 #include <cnxk_security.h>
 #include <roc_priv.h>
 
@@ -1059,10 +1060,10 @@ cn10k_eth_sec_ops_override(void)
 	init_once = 1;
 
 	/* Update platform specific ops */
-	cnxk_eth_sec_ops.macsec_sa_create = NULL;
-	cnxk_eth_sec_ops.macsec_sc_create = NULL;
-	cnxk_eth_sec_ops.macsec_sa_destroy = NULL;
-	cnxk_eth_sec_ops.macsec_sc_destroy = NULL;
+	cnxk_eth_sec_ops.macsec_sa_create = cnxk_eth_macsec_sa_create;
+	cnxk_eth_sec_ops.macsec_sc_create = cnxk_eth_macsec_sc_create;
+	cnxk_eth_sec_ops.macsec_sa_destroy = cnxk_eth_macsec_sa_destroy;
+	cnxk_eth_sec_ops.macsec_sc_destroy = cnxk_eth_macsec_sc_destroy;
 	cnxk_eth_sec_ops.session_create = cn10k_eth_sec_session_create;
 	cnxk_eth_sec_ops.session_destroy = cn10k_eth_sec_session_destroy;
 	cnxk_eth_sec_ops.capabilities_get = cn10k_eth_sec_capabilities_get;
drivers/net/cnxk/cnxk_ethdev_mcs.c +250 -0

256 lines not on this page · raw message

drivers/net/cnxk/cnxk_ethdev_mcs.h +16 -0
index 762c299fb8..68c6493169 100644
@@ -13,6 +13,14 @@ struct cnxk_mcs_dev {
 	uint8_t idx;
 };
 
+enum cnxk_mcs_rsrc_type {
+	CNXK_MCS_RSRC_TYPE_FLOWID,
+	CNXK_MCS_RSRC_TYPE_SECY,
+	CNXK_MCS_RSRC_TYPE_SC,
+	CNXK_MCS_RSRC_TYPE_SA,
+	CNXK_MCS_RSRC_TYPE_PORT,
+};
+
 struct cnxk_mcs_event_data {
 	/* Valid for below events
 	 * - ROC_MCS_EVENT_RX_SA_PN_SOFT_EXP
@@ -59,3 +67,11 @@ struct cnxk_mcs_event_desc {
 	enum roc_mcs_event_subtype subtype;
 	struct cnxk_mcs_event_data metadata;
 };
+
+int cnxk_eth_macsec_sa_create(void *device, struct rte_security_macsec_sa *conf);
+int cnxk_eth_macsec_sc_create(void *device, struct rte_security_macsec_sc *conf);
+
+int cnxk_eth_macsec_sa_destroy(void *device, uint16_t sa_id,
+			       enum rte_security_macsec_direction dir);
+int cnxk_eth_macsec_sc_destroy(void *device, uint16_t sc_id,
+			       enum rte_security_macsec_direction dir);
Signature · 1 line
2.25.1
#90 lore raw

PATCH 14/15 net/cnxk: add MACsec session and flow configuration

In reply to Akhil Goyal

Added support for MACsec session/flow create/destroy.

---
 drivers/net/cnxk/cn10k_ethdev_sec.c |  11 +-
 drivers/net/cnxk/cn10k_flow.c       |  22 ++-
 drivers/net/cnxk/cnxk_ethdev.c      |   2 +
 drivers/net/cnxk/cnxk_ethdev.h      |  16 ++
 drivers/net/cnxk/cnxk_ethdev_mcs.c  | 261 ++++++++++++++++++++++++++++
 drivers/net/cnxk/cnxk_ethdev_mcs.h  |  25 +++
 drivers/net/cnxk/cnxk_ethdev_sec.c  |   2 +-
 drivers/net/cnxk/cnxk_flow.c        |   5 +
 8 files changed, 340 insertions(+), 4 deletions(-)
drivers/net/cnxk/cn10k_ethdev_sec.c +9 -2
index e9bc05027f..0a8e7ae6fd 100644
@@ -612,7 +612,9 @@ cn10k_eth_sec_session_create(void *device,
 	if (conf->action_type != RTE_SECURITY_ACTION_TYPE_INLINE_PROTOCOL)
 		return -ENOTSUP;
 
-	if (conf->protocol != RTE_SECURITY_PROTOCOL_IPSEC)
+	if (conf->protocol == RTE_SECURITY_PROTOCOL_MACSEC)
+		return cnxk_eth_macsec_session_create(dev, conf, sess);
+	else if (conf->protocol != RTE_SECURITY_PROTOCOL_IPSEC)
 		return -ENOTSUP;
 
 	if (rte_security_dynfield_register() < 0)
@@ -856,13 +858,18 @@ cn10k_eth_sec_session_destroy(void *device, struct rte_security_session *sess)
 {
 	struct rte_eth_dev *eth_dev = (struct rte_eth_dev *)device;
 	struct cnxk_eth_dev *dev = cnxk_eth_pmd_priv(eth_dev);
+	struct cnxk_macsec_sess *macsec_sess;
 	struct cnxk_eth_sec_sess *eth_sec;
 	rte_spinlock_t *lock;
 	void *sa_dptr;
 
 	eth_sec = cnxk_eth_sec_sess_get_by_sess(dev, sess);
-	if (!eth_sec)
+	if (!eth_sec) {
+		macsec_sess = cnxk_eth_macsec_sess_get_by_sess(dev, sess);
+		if (macsec_sess)
+			return cnxk_eth_macsec_session_destroy(dev, sess);
 		return -ENOENT;
+	}
 
 	lock = eth_sec->inb ? &dev->inb.lock : &dev->outb.lock;
 	rte_spinlock_lock(lock);
drivers/net/cnxk/cn10k_flow.c +21 -1
index d7a3442c5f..9fa8e15d74 100644
@@ -1,10 +1,11 @@
 /* SPDX-License-Identifier: BSD-3-Clause
  * Copyright(C) 2020 Marvell.
  */
-#include <cnxk_flow.h>
 #include "cn10k_flow.h"
 #include "cn10k_ethdev.h"
 #include "cn10k_rx.h"
+#include "cnxk_ethdev_mcs.h"
+#include <cnxk_flow.h>
 
 static int
 cn10k_mtr_connect(struct rte_eth_dev *eth_dev, uint32_t mtr_id)
@@ -133,6 +134,7 @@ cn10k_flow_create(struct rte_eth_dev *eth_dev, const struct rte_flow_attr *attr,
 	const struct rte_flow_action *act_q = NULL;
 	struct roc_npc *npc = &dev->npc;
 	struct roc_npc_flow *flow;
+	void *mcs_flow = NULL;
 	int vtag_actions = 0;
 	uint32_t req_act = 0;
 	int mark_actions;
@@ -187,6 +189,17 @@ cn10k_flow_create(struct rte_eth_dev *eth_dev, const struct rte_flow_attr *attr,
 		}
 	}
 
+	if (actions[0].type == RTE_FLOW_ACTION_TYPE_SECURITY &&
+	    cnxk_eth_macsec_sess_get_by_sess(dev, actions[0].conf) != NULL) {
+		rc = cnxk_mcs_flow_configure(eth_dev, attr, pattern, actions, error, &mcs_flow);
+		if (rc) {
+			rte_flow_error_set(error, rc, RTE_FLOW_ERROR_TYPE_ACTION, NULL,
+					   "Failed to configure mcs flow");
+			return NULL;
+		}
+		return (struct rte_flow *)mcs_flow;
+	}
+
 	flow = cnxk_flow_create(eth_dev, attr, pattern, actions, error);
 	if (!flow) {
 		if (mtr)
@@ -253,6 +266,13 @@ cn10k_flow_destroy(struct rte_eth_dev *eth_dev, struct rte_flow *rte_flow,
 		}
 	}
 
+	rc = cnxk_mcs_flow_destroy(dev, (void *)flow);
+	if (rc < 0) {
+		rte_flow_error_set(error, rc, RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
+					   "Failed to free mcs flow");
+		return rc;
+	}
+
 	vtag_actions = roc_npc_vtag_actions_get(npc);
 	if (vtag_actions) {
 		if (flow->nix_intf == ROC_NPC_INTF_RX) {
drivers/net/cnxk/cnxk_ethdev.c +2 -0
index 7a792937b7..c137c2a7c4 100644
@@ -1953,6 +1953,8 @@ cnxk_eth_dev_init(struct rte_eth_dev *eth_dev)
 		}
 		dev->rx_offload_capa |= RTE_ETH_RX_OFFLOAD_MACSEC_STRIP;
 		dev->tx_offload_capa |= RTE_ETH_TX_OFFLOAD_MACSEC_INSERT;
+
+		TAILQ_INIT(&dev->mcs_list);
 	}
 
 	plt_nix_dbg("Port=%d pf=%d vf=%d ver=%s hwcap=0x%" PRIx64
drivers/net/cnxk/cnxk_ethdev.h +16 -0
index 6fde682344..327c737673 100644
@@ -289,6 +289,21 @@ struct cnxk_eth_dev_sec_outb {
 	rte_spinlock_t lock;
 };
 
+/* MACsec session private data */
+struct cnxk_macsec_sess {
+	/* List entry */
+	TAILQ_ENTRY(cnxk_macsec_sess) entry;
+
+	/* Back pointer to session */
+	struct rte_security_session *sess;
+	enum mcs_direction dir;
+	uint64_t sci;
+	uint8_t secy_id;
+	uint8_t sc_id;
+	uint8_t flow_id;
+};
+TAILQ_HEAD(cnxk_macsec_sess_list, cnxk_macsec_sess);
+
 struct cnxk_eth_dev {
 	/* ROC NIX */
 	struct roc_nix nix;
@@ -395,6 +410,7 @@ struct cnxk_eth_dev {
 
 	/* MCS device */
 	struct cnxk_mcs_dev *mcs_dev;
+	struct cnxk_macsec_sess_list mcs_list;
 };
 
 struct cnxk_eth_rxq_sp {
drivers/net/cnxk/cnxk_ethdev_mcs.c +261 -0

267 lines not on this page · raw message

drivers/net/cnxk/cnxk_ethdev_mcs.h +25 -0
index 68c6493169..2b1a6f2c90 100644
@@ -21,6 +21,27 @@ enum cnxk_mcs_rsrc_type {
 	CNXK_MCS_RSRC_TYPE_PORT,
 };
 
+struct cnxk_mcs_flow_opts {
+	uint32_t outer_tag_id;
+	/**< {VLAN_ID[11:0]}, or 20-bit MPLS label*/
+	uint8_t outer_priority;
+	/**< {PCP/Pbits, DE/CFI} or {1'b0, EXP} for MPLS.*/
+	uint32_t second_outer_tag_id;
+	/**< {VLAN_ID[11:0]}, or 20-bit MPLS label*/
+	uint8_t second_outer_priority;
+	/**< {PCP/Pbits, DE/CFI} or {1'b0, EXP} for MPLS. */
+	uint16_t bonus_data;
+	/**< 2 bytes of additional bonus data extracted from one of the custom tags*/
+	uint8_t tag_match_bitmap;
+	uint8_t packet_type;
+	uint8_t outer_vlan_type;
+	uint8_t inner_vlan_type;
+	uint8_t num_tags;
+	bool express;
+	uint8_t lmac_id;
+	uint8_t flowid_user;
+};
+
 struct cnxk_mcs_event_data {
 	/* Valid for below events
 	 * - ROC_MCS_EVENT_RX_SA_PN_SOFT_EXP
@@ -75,3 +96,7 @@ int cnxk_eth_macsec_sa_destroy(void *device, uint16_t sa_id,
 			       enum rte_security_macsec_direction dir);
 int cnxk_eth_macsec_sc_destroy(void *device, uint16_t sc_id,
 			       enum rte_security_macsec_direction dir);
+
+int cnxk_eth_macsec_session_create(struct cnxk_eth_dev *dev, struct rte_security_session_conf *conf,
+				   struct rte_security_session *sess);
+int cnxk_eth_macsec_session_destroy(struct cnxk_eth_dev *dev, struct rte_security_session *sess);
drivers/net/cnxk/cnxk_ethdev_sec.c +1 -1
index aa8a378a00..59924a36c9 100644
@@ -235,7 +235,7 @@ cnxk_eth_sec_sess_get_by_sess(struct cnxk_eth_dev *dev,
 static unsigned int
 cnxk_eth_sec_session_get_size(void *device __rte_unused)
 {
-	return sizeof(struct cnxk_eth_sec_sess);
+	return RTE_MAX(sizeof(struct cnxk_macsec_sess), sizeof(struct cnxk_eth_sec_sess));
 }
 
 struct rte_security_ops cnxk_eth_sec_ops = {
drivers/net/cnxk/cnxk_flow.c +5 -0
index f13d8e5582..05858d377a 100644
@@ -298,6 +298,11 @@ cnxk_flow_validate(struct rte_eth_dev *eth_dev,
 	uint32_t flowkey_cfg = 0;
 	int rc;
 
+	/* Skip flow validation for MACsec. */
+	if (actions[0].type == RTE_FLOW_ACTION_TYPE_SECURITY &&
+	    cnxk_eth_macsec_sess_get_by_sess(dev, actions[0].conf) != NULL)
+		return 0;
+
 	memset(&flow, 0, sizeof(flow));
 	flow.is_validate = true;
 
Signature · 1 line
2.25.1
#91 lore raw

PATCH 15/15 net/cnxk: add MACsec stats

In reply to Akhil Goyal

Added support for MACsec SC/flow/session stats.

---
 drivers/net/cnxk/cn10k_ethdev_sec.c | 11 +++--
 drivers/net/cnxk/cnxk_ethdev_mcs.c  | 64 +++++++++++++++++++++++++++++
 drivers/net/cnxk/cnxk_ethdev_mcs.h  |  9 ++++
 3 files changed, 81 insertions(+), 3 deletions(-)
drivers/net/cnxk/cn10k_ethdev_sec.c +8 -3
index 0a8e7ae6fd..cd0fd1744f 100644
@@ -1027,12 +1027,17 @@ cn10k_eth_sec_session_stats_get(void *device, struct rte_security_session *sess,
 {
 	struct rte_eth_dev *eth_dev = (struct rte_eth_dev *)device;
 	struct cnxk_eth_dev *dev = cnxk_eth_pmd_priv(eth_dev);
+	struct cnxk_macsec_sess *macsec_sess;
 	struct cnxk_eth_sec_sess *eth_sec;
 	int rc;
 
 	eth_sec = cnxk_eth_sec_sess_get_by_sess(dev, sess);
-	if (eth_sec == NULL)
+	if (eth_sec == NULL) {
+		macsec_sess = cnxk_eth_macsec_sess_get_by_sess(dev, sess);
+		if (macsec_sess)
+			return cnxk_eth_macsec_session_stats_get(dev, macsec_sess, stats);
 		return -EINVAL;
+	}
 
 	rc = roc_nix_inl_sa_sync(&dev->nix, eth_sec->sa, eth_sec->inb,
 			    ROC_NIX_INL_SA_OP_FLUSH);
@@ -1076,6 +1081,6 @@ cn10k_eth_sec_ops_override(void)
 	cnxk_eth_sec_ops.capabilities_get = cn10k_eth_sec_capabilities_get;
 	cnxk_eth_sec_ops.session_update = cn10k_eth_sec_session_update;
 	cnxk_eth_sec_ops.session_stats_get = cn10k_eth_sec_session_stats_get;
-	cnxk_eth_sec_ops.macsec_sc_stats_get = NULL;
-	cnxk_eth_sec_ops.macsec_sa_stats_get = NULL;
+	cnxk_eth_sec_ops.macsec_sc_stats_get = cnxk_eth_macsec_sc_stats_get;
+	cnxk_eth_sec_ops.macsec_sa_stats_get = cnxk_eth_macsec_sa_stats_get;
 }
drivers/net/cnxk/cnxk_ethdev_mcs.c +64 -0

70 lines not on this page · raw message

drivers/net/cnxk/cnxk_ethdev_mcs.h +9 -0
index 2b1a6f2c90..4a59dd3df9 100644
@@ -97,6 +97,15 @@ int cnxk_eth_macsec_sa_destroy(void *device, uint16_t sa_id,
 int cnxk_eth_macsec_sc_destroy(void *device, uint16_t sc_id,
 			       enum rte_security_macsec_direction dir);
 
+int cnxk_eth_macsec_sa_stats_get(void *device, uint16_t sa_id,
+				 enum rte_security_macsec_direction dir,
+				 struct rte_security_macsec_sa_stats *stats);
+int cnxk_eth_macsec_sc_stats_get(void *device, uint16_t sa_id,
+				 enum rte_security_macsec_direction dir,
+				 struct rte_security_macsec_sc_stats *stats);
+int cnxk_eth_macsec_session_stats_get(struct cnxk_eth_dev *dev, struct cnxk_macsec_sess *sess,
+				      struct rte_security_stats *stats);
+
 int cnxk_eth_macsec_session_create(struct cnxk_eth_dev *dev, struct rte_security_session_conf *conf,
 				   struct rte_security_session *sess);
 int cnxk_eth_macsec_session_destroy(struct cnxk_eth_dev *dev, struct rte_security_session *sess);
Signature · 1 line
2.25.1
#92 lore raw

Re: [PATCH 15/15] net/cnxk: add MACsec stats

Quoted 4 lines · Akhil Goyal

Added support for MACsec SC/flow/session stats.

# Please fix the the build issue
http://mails.dpdk.org/archives/test-report/2023-June/410104.html
# Please rebase to dpdk-next-mrvl as doc is updated in
https://patches.dpdk.org/project/dpdk/patch/[email protected]/

Quoted 136 lines
---
 drivers/net/cnxk/cn10k_ethdev_sec.c | 11 +++--
 drivers/net/cnxk/cnxk_ethdev_mcs.c  | 64 +++++++++++++++++++++++++++++
 drivers/net/cnxk/cnxk_ethdev_mcs.h  |  9 ++++
 3 files changed, 81 insertions(+), 3 deletions(-)
drivers/net/cnxk/cn10k_ethdev_sec.c +8 -3
index 0a8e7ae6fd..cd0fd1744f 100644
@@ -1027,12 +1027,17 @@ cn10k_eth_sec_session_stats_get(void *device, struct rte_security_session *sess,
 {
        struct rte_eth_dev *eth_dev = (struct rte_eth_dev *)device;
        struct cnxk_eth_dev *dev = cnxk_eth_pmd_priv(eth_dev);
+       struct cnxk_macsec_sess *macsec_sess;
        struct cnxk_eth_sec_sess *eth_sec;
        int rc;
 
        eth_sec = cnxk_eth_sec_sess_get_by_sess(dev, sess);
-       if (eth_sec == NULL)
+       if (eth_sec == NULL) {
+               macsec_sess = cnxk_eth_macsec_sess_get_by_sess(dev, sess);
+               if (macsec_sess)
+                       return cnxk_eth_macsec_session_stats_get(dev, macsec_sess, stats);
                return -EINVAL;
+       }
 
        rc = roc_nix_inl_sa_sync(&dev->nix, eth_sec->sa, eth_sec->inb,
                            ROC_NIX_INL_SA_OP_FLUSH);
@@ -1076,6 +1081,6 @@ cn10k_eth_sec_ops_override(void)
        cnxk_eth_sec_ops.capabilities_get = cn10k_eth_sec_capabilities_get;
        cnxk_eth_sec_ops.session_update = cn10k_eth_sec_session_update;
        cnxk_eth_sec_ops.session_stats_get = cn10k_eth_sec_session_stats_get;
-       cnxk_eth_sec_ops.macsec_sc_stats_get = NULL;
-       cnxk_eth_sec_ops.macsec_sa_stats_get = NULL;
+       cnxk_eth_sec_ops.macsec_sc_stats_get = cnxk_eth_macsec_sc_stats_get;
+       cnxk_eth_sec_ops.macsec_sa_stats_get = cnxk_eth_macsec_sa_stats_get;
 }
drivers/net/cnxk/cnxk_ethdev_mcs.c +64 -0
index c5ac5bafbb..e79b8279a7 100644
@@ -517,6 +517,70 @@ cnxk_mcs_flow_destroy(struct cnxk_eth_dev *dev, void *flow)
        return (ret == 0) ? 1 : ret;
 }
 
+int
+cnxk_eth_macsec_sa_stats_get(void *device, uint16_t sa_id, enum rte_security_macsec_direction dir,
+                            struct rte_security_macsec_sa_stats *stats)
+{
+       RTE_SET_USED(device);
+       RTE_SET_USED(sa_id);
+       RTE_SET_USED(dir);
+       RTE_SET_USED(stats);
+
+       return 0;
+}
+
+int
+cnxk_eth_macsec_sc_stats_get(void *device, uint16_t sc_id, enum rte_security_macsec_direction dir,
+                            struct rte_security_macsec_sc_stats *stats)
+{
+       struct rte_eth_dev *eth_dev = (struct rte_eth_dev *)device;
+       struct cnxk_eth_dev *dev = cnxk_eth_pmd_priv(eth_dev);
+       struct cnxk_mcs_dev *mcs_dev = dev->mcs_dev;
+       struct roc_mcs_stats_req req = {0};
+
+       if (!roc_feature_nix_has_macsec())
+               return -ENOTSUP;
+
+       req.id = sc_id;
+       req.dir = (dir == RTE_SECURITY_MACSEC_DIR_RX) ? MCS_RX : MCS_TX;
+
+       return roc_mcs_sc_stats_get(mcs_dev->mdev, &req, (struct roc_mcs_sc_stats *)stats);
+}
+
+int
+cnxk_eth_macsec_session_stats_get(struct cnxk_eth_dev *dev, struct cnxk_macsec_sess *sess,
+                                 struct rte_security_stats *stats)
+{
+       struct cnxk_mcs_dev *mcs_dev = dev->mcs_dev;
+       struct roc_mcs_flowid_stats flow_stats = {0};
+       struct roc_mcs_port_stats port_stats = {0};
+       struct roc_mcs_stats_req req = {0};
+
+       if (!roc_feature_nix_has_macsec())
+               return -ENOTSUP;
+
+       req.id = sess->flow_id;
+       req.dir = sess->dir;
+       roc_mcs_flowid_stats_get(mcs_dev->mdev, &req, &flow_stats);
+       plt_nix_dbg("\n******* FLOW_ID IDX[%u] STATS dir: %u********\n", sess->flow_id, sess->dir);
+       plt_nix_dbg("TX: tcam_hit_cnt: 0x%lx\n", flow_stats.tcam_hit_cnt);
+
+       req.id = mcs_dev->port_id;
+       req.dir = sess->dir;
+       roc_mcs_port_stats_get(mcs_dev->mdev, &req, &port_stats);
+       plt_nix_dbg("\n********** PORT[0] STATS ****************\n");
+       plt_nix_dbg("RX tcam_miss_cnt: 0x%lx\n", port_stats.tcam_miss_cnt);
+       plt_nix_dbg("RX parser_err_cnt: 0x%lx\n", port_stats.parser_err_cnt);
+       plt_nix_dbg("RX preempt_err_cnt: 0x%lx\n", port_stats.preempt_err_cnt);
+       plt_nix_dbg("RX sectag_insert_err_cnt: 0x%lx\n", port_stats.sectag_insert_err_cnt);
+
+       req.id = sess->secy_id;
+       req.dir = sess->dir;
+
+       return roc_mcs_secy_stats_get(mcs_dev->mdev, &req,
+                                     (struct roc_mcs_secy_stats *)(&stats->macsec));
+}
+
 static int
 cnxk_mcs_event_cb(void *userdata, struct roc_mcs_event_desc *desc, void *cb_arg)
 {
drivers/net/cnxk/cnxk_ethdev_mcs.h +9 -1
index 2b1a6f2c90..4a59dd3df9 100644
@@ -97,6 +97,15 @@ int cnxk_eth_macsec_sa_destroy(void *device, uint16_t sa_id,
 int cnxk_eth_macsec_sc_destroy(void *device, uint16_t sc_id,
                               enum rte_security_macsec_direction dir);
 
+int cnxk_eth_macsec_sa_stats_get(void *device, uint16_t sa_id,
+                                enum rte_security_macsec_direction dir,
+                                struct rte_security_macsec_sa_stats *stats);
+int cnxk_eth_macsec_sc_stats_get(void *device, uint16_t sa_id,
+                                enum rte_security_macsec_direction dir,
+                                struct rte_security_macsec_sc_stats *stats);
+int cnxk_eth_macsec_session_stats_get(struct cnxk_eth_dev *dev, struct cnxk_macsec_sess *sess,
+                                     struct rte_security_stats *stats);
+
 int cnxk_eth_macsec_session_create(struct cnxk_eth_dev *dev, struct rte_security_session_conf *conf,
                                   struct rte_security_session *sess);
 int cnxk_eth_macsec_session_destroy(struct cnxk_eth_dev *dev, struct rte_security_session *sess);
--

2.25.1

#93 lore raw

v2 cover net/cnxk: add MACsec support

In reply to Akhil Goyal

Added MACsec support in Marvell cnxk PMD. The patchset is pending from last release [1] Sending as a new series as the functionality is now complete and tested on hardware.

Depends-on: http://patches.dpdk.org/project/dpdk/list/?series=28391

[1] https://patches.dpdk.org/project/dpdk/cover/[email protected]/

Changes in v2:
- Addressed review comments from Jerin.

Akhil Goyal (15):
common/cnxk: add ROC MACsec initialization common/cnxk: add MACsec SA configuration common/cnxk: add MACsec SC configuration APIs common/cnxk: add MACsec secy and flow configuration common/cnxk: add MACsec PN and LMAC mode configuration common/cnxk: add MACsec stats
common/cnxk: add MACsec interrupt APIs common/cnxk: add MACsec port configuration common/cnxk: add MACsec control port configuration common/cnxk: add MACsec FIPS mbox common/cnxk: derive hash key for MACsec net/cnxk: add MACsec initialization
net/cnxk: create/destroy MACsec SC/SA net/cnxk: add MACsec session and flow configuration net/cnxk: add MACsec stats

 drivers/common/cnxk/meson.build       |   3 +
 drivers/common/cnxk/roc_aes.c         |  86 ++-
 drivers/common/cnxk/roc_aes.h         |   4 +-
 drivers/common/cnxk/roc_api.h         |   3 +
 drivers/common/cnxk/roc_dev.c         |  86 +++
 drivers/common/cnxk/roc_features.h    |  12 +
 drivers/common/cnxk/roc_idev.c        |  46 ++
 drivers/common/cnxk/roc_idev.h        |   3 +
 drivers/common/cnxk/roc_idev_priv.h   |   1 +
 drivers/common/cnxk/roc_mbox.h        | 524 +++++++++++++++-
 drivers/common/cnxk/roc_mcs.c         | 871 ++++++++++++++++++++++++++
 drivers/common/cnxk/roc_mcs.h         | 621 ++++++++++++++++++
 drivers/common/cnxk/roc_mcs_priv.h    |  73 +++
 drivers/common/cnxk/roc_mcs_sec_cfg.c | 528 ++++++++++++++++
 drivers/common/cnxk/roc_mcs_stats.c   | 193 ++++++
 drivers/common/cnxk/roc_priv.h        |   3 +
 drivers/common/cnxk/roc_utils.c       |   5 +
 drivers/common/cnxk/version.map       |  45 ++
 drivers/net/cnxk/cn10k_ethdev_sec.c   |  25 +-
 drivers/net/cnxk/cn10k_flow.c         |  23 +-
 drivers/net/cnxk/cnxk_ethdev.c        |  15 +
 drivers/net/cnxk/cnxk_ethdev.h        |  30 +
 drivers/net/cnxk/cnxk_ethdev_mcs.c    | 726 +++++++++++++++++++++
 drivers/net/cnxk/cnxk_ethdev_mcs.h    | 111 ++++
 drivers/net/cnxk/cnxk_ethdev_sec.c    |   2 +-
 drivers/net/cnxk/cnxk_flow.c          |   5 +
 drivers/net/cnxk/meson.build          |   1 +
 27 files changed, 4007 insertions(+), 38 deletions(-)
 create mode 100644 drivers/common/cnxk/roc_mcs.c
 create mode 100644 drivers/common/cnxk/roc_mcs.h
 create mode 100644 drivers/common/cnxk/roc_mcs_priv.h
 create mode 100644 drivers/common/cnxk/roc_mcs_sec_cfg.c
 create mode 100644 drivers/common/cnxk/roc_mcs_stats.c
 create mode 100644 drivers/net/cnxk/cnxk_ethdev_mcs.c
 create mode 100644 drivers/net/cnxk/cnxk_ethdev_mcs.h
Signature · 1 line
2.25.1
#94 lore raw

PATCH v2 1/15 common/cnxk: add ROC MACsec initialization

Added ROC init and fini APIs for supporting MACsec.

---
 drivers/common/cnxk/meson.build     |   1 +
 drivers/common/cnxk/roc_api.h       |   3 +
 drivers/common/cnxk/roc_features.h  |  12 ++
 drivers/common/cnxk/roc_idev.c      |  46 ++++++
 drivers/common/cnxk/roc_idev.h      |   3 +
 drivers/common/cnxk/roc_idev_priv.h |   1 +
 drivers/common/cnxk/roc_mbox.h      |  65 +++++++-
 drivers/common/cnxk/roc_mcs.c       | 220 ++++++++++++++++++++++++++++
 drivers/common/cnxk/roc_mcs.h       |  41 ++++++
 drivers/common/cnxk/roc_mcs_priv.h  |  65 ++++++++
 drivers/common/cnxk/roc_priv.h      |   3 +
 drivers/common/cnxk/roc_utils.c     |   5 +
 drivers/common/cnxk/version.map     |   7 +
 13 files changed, 471 insertions(+), 1 deletion(-)
 create mode 100644 drivers/common/cnxk/roc_mcs.c
 create mode 100644 drivers/common/cnxk/roc_mcs.h
 create mode 100644 drivers/common/cnxk/roc_mcs_priv.h
drivers/common/cnxk/meson.build +1 -0
index 631b594f32..e33c002676 100644
@@ -26,6 +26,7 @@ sources = files(
         'roc_irq.c',
         'roc_ie_ot.c',
         'roc_mbox.c',
+        'roc_mcs.c',
         'roc_ml.c',
         'roc_model.c',
         'roc_nix.c',
drivers/common/cnxk/roc_api.h +3 -0
index bbc94ab48e..f630853088 100644
@@ -114,4 +114,7 @@
 /* ML */
 #include "roc_ml.h"
 
+/* MACsec */
+#include "roc_mcs.h"
+
 #endif /* _ROC_API_H_ */
drivers/common/cnxk/roc_features.h +12 -0
index 36ef315f5a..815f800e7a 100644
@@ -59,4 +59,16 @@ roc_feature_nix_has_age_drop_stats(void)
 {
 	return (roc_model_is_cn10kb() || roc_model_is_cn10ka_b0());
 }
+
+static inline bool
+roc_feature_nix_has_macsec(void)
+{
+	return roc_model_is_cn10kb();
+}
+
+static inline bool
+roc_feature_bphy_has_macsec(void)
+{
+	return roc_model_is_cnf10kb();
+}
 #endif
drivers/common/cnxk/roc_idev.c +46 -0

58 lines not on this page · raw message

drivers/common/cnxk/roc_idev.h +3 -0
index 640ca97708..aea7f5279d 100644
@@ -19,4 +19,7 @@ struct roc_nix *__roc_api roc_idev_npa_nix_get(void);
 uint64_t __roc_api roc_idev_nix_inl_meta_aura_get(void);
 struct roc_nix_list *__roc_api roc_idev_nix_list_get(void);
 
+struct roc_mcs *__roc_api roc_idev_mcs_get(uint8_t mcs_idx);
+void __roc_api roc_idev_mcs_set(struct roc_mcs *mcs);
+void __roc_api roc_idev_mcs_free(struct roc_mcs *mcs);
 #endif /* _ROC_IDEV_H_ */
drivers/common/cnxk/roc_idev_priv.h +1 -0
index 4983578fc6..80f8465e1c 100644
@@ -31,6 +31,7 @@ struct idev_cfg {
 	struct roc_bphy *bphy;
 	struct roc_cpt *cpt;
 	struct roc_sso *sso;
+	struct roc_mcs_head mcs_list;
 	struct nix_inl_dev *nix_inl_dev;
 	struct idev_nix_inl_cfg inl_cfg;
 	struct roc_nix_list roc_nix_list;
drivers/common/cnxk/roc_mbox.h +64 -1

77 lines not on this page · raw message

drivers/common/cnxk/roc_mcs.c new file +220 -0

220 lines not on this page · raw message

drivers/common/cnxk/roc_mcs.h new file +41 -0

41 lines not on this page · raw message

drivers/common/cnxk/roc_mcs_priv.h new file +65 -0

65 lines not on this page · raw message

drivers/common/cnxk/roc_priv.h +3 -0
index 14fe2e452a..254a2d3310 100644
@@ -44,6 +44,9 @@
 /* DPI */
 #include "roc_dpi_priv.h"
 
+/* MCS */
+#include "roc_mcs_priv.h"
+
 /* REE */
 #include "roc_ree_priv.h"
 
drivers/common/cnxk/roc_utils.c +5 -0
index fe291fce96..9af2ae9b69 100644
@@ -16,6 +16,7 @@ roc_error_msg_get(int errorcode)
 	case NPA_ERR_PARAM:
 	case NPC_ERR_PARAM:
 	case SSO_ERR_PARAM:
+	case MCS_ERR_PARAM:
 	case UTIL_ERR_PARAM:
 		err_msg = "Invalid parameter";
 		break;
@@ -35,6 +36,7 @@ roc_error_msg_get(int errorcode)
 		err_msg = "Operation not supported";
 		break;
 	case NIX_ERR_HW_NOTSUP:
+	case MCS_ERR_HW_NOTSUP:
 		err_msg = "Hardware does not support";
 		break;
 	case NIX_ERR_QUEUE_INVALID_RANGE:
@@ -223,6 +225,9 @@ roc_error_msg_get(int errorcode)
 	case SSO_ERR_DEVICE_NOT_BOUNDED:
 		err_msg = "SSO pf/vf not found";
 		break;
+	case MCS_ERR_DEVICE_NOT_FOUND:
+		err_msg = "MCS device not found";
+		break;
 	case UTIL_ERR_FS:
 		err_msg = "file operation failed";
 		break;
drivers/common/cnxk/version.map +7 -0
index e1335e9068..900290b866 100644
@@ -94,6 +94,9 @@ INTERNAL {
 	roc_idev_cpt_get;
 	roc_idev_cpt_set;
 	roc_idev_lmt_base_addr_get;
+	roc_idev_mcs_free;
+	roc_idev_mcs_get;
+	roc_idev_mcs_set;
 	roc_idev_npa_maxpools_get;
 	roc_idev_npa_maxpools_set;
 	roc_idev_npa_nix_get;
@@ -132,6 +135,10 @@ INTERNAL {
 	roc_se_auth_key_set;
 	roc_se_ciph_key_set;
 	roc_se_ctx_init;
+	roc_mcs_dev_init;
+	roc_mcs_dev_fini;
+	roc_mcs_dev_get;
+	roc_mcs_hw_info_get;
 	roc_nix_bpf_alloc;
 	roc_nix_bpf_config;
 	roc_nix_bpf_connect;
Signature · 1 line
2.25.1
#95 lore raw

Re: [PATCH v2 01/15] common/cnxk: add ROC MACsec initialization

Quoted 6 lines · Akhil Goyal

Added ROC init and fini APIs for supporting MACsec.

Please update the release note in the last patch.

Quoted 651 lines
---
 drivers/common/cnxk/meson.build     |   1 +
 drivers/common/cnxk/roc_api.h       |   3 +
 drivers/common/cnxk/roc_features.h  |  12 ++
 drivers/common/cnxk/roc_idev.c      |  46 ++++++
 drivers/common/cnxk/roc_idev.h      |   3 +
 drivers/common/cnxk/roc_idev_priv.h |   1 +
 drivers/common/cnxk/roc_mbox.h      |  65 +++++++-
 drivers/common/cnxk/roc_mcs.c       | 220 ++++++++++++++++++++++++++++
 drivers/common/cnxk/roc_mcs.h       |  41 ++++++
 drivers/common/cnxk/roc_mcs_priv.h  |  65 ++++++++
 drivers/common/cnxk/roc_priv.h      |   3 +
 drivers/common/cnxk/roc_utils.c     |   5 +
 drivers/common/cnxk/version.map     |   7 +
 13 files changed, 471 insertions(+), 1 deletion(-)
 create mode 100644 drivers/common/cnxk/roc_mcs.c
 create mode 100644 drivers/common/cnxk/roc_mcs.h
 create mode 100644 drivers/common/cnxk/roc_mcs_priv.h
drivers/common/cnxk/meson.build +1 -0
index 631b594f32..e33c002676 100644
@@ -26,6 +26,7 @@ sources = files(
         'roc_irq.c',
         'roc_ie_ot.c',
         'roc_mbox.c',
+        'roc_mcs.c',
         'roc_ml.c',
         'roc_model.c',
         'roc_nix.c',
drivers/common/cnxk/roc_api.h +3 -0
index bbc94ab48e..f630853088 100644
@@ -114,4 +114,7 @@
 /* ML */
 #include "roc_ml.h"
 
+/* MACsec */
+#include "roc_mcs.h"
+
 #endif /* _ROC_API_H_ */
drivers/common/cnxk/roc_features.h +12 -0
index 36ef315f5a..815f800e7a 100644
@@ -59,4 +59,16 @@ roc_feature_nix_has_age_drop_stats(void)
 {
        return (roc_model_is_cn10kb() || roc_model_is_cn10ka_b0());
 }
+
+static inline bool
+roc_feature_nix_has_macsec(void)
+{
+       return roc_model_is_cn10kb();
+}
+
+static inline bool
+roc_feature_bphy_has_macsec(void)
+{
+       return roc_model_is_cnf10kb();
+}
 #endif
drivers/common/cnxk/roc_idev.c +46 -0
index f420f0158d..e6c6b34d78 100644
@@ -38,6 +38,7 @@ idev_set_defaults(struct idev_cfg *idev)
        idev->num_lmtlines = 0;
        idev->bphy = NULL;
        idev->cpt = NULL;
+       TAILQ_INIT(&idev->mcs_list);
        idev->nix_inl_dev = NULL;
        TAILQ_INIT(&idev->roc_nix_list);
        plt_spinlock_init(&idev->nix_inl_dev_lock);
@@ -187,6 +188,51 @@ roc_idev_cpt_get(void)
        return NULL;
 }
 
+struct roc_mcs *
+roc_idev_mcs_get(uint8_t mcs_idx)
+{
+       struct idev_cfg *idev = idev_get_cfg();
+       struct roc_mcs *mcs = NULL;
+
+       if (idev != NULL) {
+               TAILQ_FOREACH(mcs, &idev->mcs_list, next) {
+                       if (mcs->idx == mcs_idx)
+                               return mcs;
+               }
+       }
+
+       return NULL;
+}
+
+void
+roc_idev_mcs_set(struct roc_mcs *mcs)
+{
+       struct idev_cfg *idev = idev_get_cfg();
+       struct roc_mcs *mcs_iter = NULL;
+
+       if (idev != NULL) {
+               TAILQ_FOREACH(mcs_iter, &idev->mcs_list, next) {
+                       if (mcs_iter->idx == mcs->idx)
+                               return;
+               }
+               TAILQ_INSERT_TAIL(&idev->mcs_list, mcs, next);
+       }
+}
+
+void
+roc_idev_mcs_free(struct roc_mcs *mcs)
+{
+       struct idev_cfg *idev = idev_get_cfg();
+       struct roc_mcs *mcs_iter = NULL;
+
+       if (idev != NULL) {
+               TAILQ_FOREACH(mcs_iter, &idev->mcs_list, next) {
+                       if (mcs_iter->idx == mcs->idx)
+                               TAILQ_REMOVE(&idev->mcs_list, mcs, next);
+               }
+       }
+}
+
 uint64_t *
 roc_nix_inl_outb_ring_base_get(struct roc_nix *roc_nix)
 {
drivers/common/cnxk/roc_idev.h +3 -0
index 640ca97708..aea7f5279d 100644
@@ -19,4 +19,7 @@ struct roc_nix *__roc_api roc_idev_npa_nix_get(void);
 uint64_t __roc_api roc_idev_nix_inl_meta_aura_get(void);
 struct roc_nix_list *__roc_api roc_idev_nix_list_get(void);
 
+struct roc_mcs *__roc_api roc_idev_mcs_get(uint8_t mcs_idx);
+void __roc_api roc_idev_mcs_set(struct roc_mcs *mcs);
+void __roc_api roc_idev_mcs_free(struct roc_mcs *mcs);
 #endif /* _ROC_IDEV_H_ */
drivers/common/cnxk/roc_idev_priv.h +1 -0
index 4983578fc6..80f8465e1c 100644
@@ -31,6 +31,7 @@ struct idev_cfg {
        struct roc_bphy *bphy;
        struct roc_cpt *cpt;
        struct roc_sso *sso;
+       struct roc_mcs_head mcs_list;
        struct nix_inl_dev *nix_inl_dev;
        struct idev_nix_inl_cfg inl_cfg;
        struct roc_nix_list roc_nix_list;
drivers/common/cnxk/roc_mbox.h +64 -1
index 93c5451c0f..ef7a7d6513 100644
@@ -295,7 +295,12 @@ struct mbox_msghdr {
          nix_bpids)                                                           \
        M(NIX_FREE_BPIDS, 0x8029, nix_free_bpids, nix_bpids, msg_rsp)          \
        M(NIX_RX_CHAN_CFG, 0x802a, nix_rx_chan_cfg, nix_rx_chan_cfg,           \
-         nix_rx_chan_cfg)
+         nix_rx_chan_cfg)                                                     \
+       /* MCS mbox IDs (range 0xa000 - 0xbFFF) */                                                 \
+       M(MCS_ALLOC_RESOURCES, 0xa000, mcs_alloc_resources, mcs_alloc_rsrc_req,                    \
+         mcs_alloc_rsrc_rsp)                                                                      \
+       M(MCS_FREE_RESOURCES, 0xa001, mcs_free_resources, mcs_free_rsrc_req, msg_rsp)              \
+       M(MCS_GET_HW_INFO, 0xa00b, mcs_get_hw_info, msg_req, mcs_hw_info)                          \
 
 /* Messages initiated by AF (range 0xC00 - 0xDFF) */
 #define MBOX_UP_CGX_MESSAGES                                                   \
@@ -673,6 +678,64 @@ struct cgx_set_link_mode_rsp {
        int __io status;
 };
 
+/* MCS mbox structures */
+enum mcs_direction {
+       MCS_RX,
+       MCS_TX,
+};
+
+enum mcs_rsrc_type {
+       MCS_RSRC_TYPE_FLOWID,
+       MCS_RSRC_TYPE_SECY,
+       MCS_RSRC_TYPE_SC,
+       MCS_RSRC_TYPE_SA,
+};
+
+struct mcs_alloc_rsrc_req {
+       struct mbox_msghdr hdr;
+       uint8_t __io rsrc_type;
+       uint8_t __io rsrc_cnt; /* Resources count */
+       uint8_t __io mcs_id;   /* MCS block ID */
+       uint8_t __io dir;      /* Macsec ingress or egress side */
+       uint8_t __io all;      /* Allocate all resource type one each */
+       uint64_t __io rsvd;
+};
+
+struct mcs_alloc_rsrc_rsp {
+       struct mbox_msghdr hdr;
+       uint8_t __io flow_ids[128]; /* Index of reserved entries */
+       uint8_t __io secy_ids[128];
+       uint8_t __io sc_ids[128];
+       uint8_t __io sa_ids[256];
+       uint8_t __io rsrc_type;
+       uint8_t __io rsrc_cnt; /* No of entries reserved */
+       uint8_t __io mcs_id;
+       uint8_t __io dir;
+       uint8_t __io all;
+       uint8_t __io rsvd[256];
+};
+
+struct mcs_free_rsrc_req {
+       struct mbox_msghdr hdr;
+       uint8_t __io rsrc_id; /* Index of the entry to be freed */
+       uint8_t __io rsrc_type;
+       uint8_t __io mcs_id;
+       uint8_t __io dir;
+       uint8_t __io all; /* Free all the cam resources */
+       uint64_t __io rsvd;
+};
+
+struct mcs_hw_info {
+       struct mbox_msghdr hdr;
+       uint8_t __io num_mcs_blks; /* Number of MCS blocks */
+       uint8_t __io tcam_entries; /* RX/TX Tcam entries per mcs block */
+       uint8_t __io secy_entries; /* RX/TX SECY entries per mcs block */
+       uint8_t __io sc_entries;   /* RX/TX SC CAM entries per mcs block */
+       uint16_t __io sa_entries;  /* PN table entries = SA entries */
+       uint64_t __io rsvd[16];
+};
+
+
 /* NPA mbox message formats */
 
 /* NPA mailbox error codes
drivers/common/cnxk/roc_mcs.c new file +220 -0
new file mode 100644
index 0000000000..20433eae83
@@ -0,0 +1,220 @@
+/* SPDX-License-Identifier: BSD-3-Clause
+ * Copyright(C) 2022 Marvell.
+ */
+
+#include "roc_api.h"
+#include "roc_priv.h"
+
+int
+roc_mcs_hw_info_get(struct roc_mcs_hw_info *hw_info)
+{
+       struct mcs_hw_info *hw;
+       struct npa_lf *npa;
+       int rc;
+
+       MCS_SUPPORT_CHECK;
+
+       if (hw_info == NULL)
+               return -EINVAL;
+
+       /* Use mbox handler of first probed pci_func for
+        * initial mcs mbox communication.
+        */
+       npa = idev_npa_obj_get();
+       if (!npa)
+               return MCS_ERR_DEVICE_NOT_FOUND;
+
+       mbox_alloc_msg_mcs_get_hw_info(npa->mbox);
+       rc = mbox_process_msg(npa->mbox, (void *)&hw);
+       if (rc)
+               return rc;
+
+       hw_info->num_mcs_blks = hw->num_mcs_blks;
+       hw_info->tcam_entries = hw->tcam_entries;
+       hw_info->secy_entries = hw->secy_entries;
+       hw_info->sc_entries = hw->sc_entries;
+       hw_info->sa_entries = hw->sa_entries;
+
+       return rc;
+}
+
+static int
+mcs_alloc_bmap(uint16_t entries, void **mem, struct plt_bitmap **bmap)
+{
+       size_t bmap_sz;
+       int rc = 0;
+
+       bmap_sz = plt_bitmap_get_memory_footprint(entries);
+       *mem = plt_zmalloc(bmap_sz, PLT_CACHE_LINE_SIZE);
+       if (*mem == NULL)
+               rc = -ENOMEM;
+
+       *bmap = plt_bitmap_init(entries, *mem, bmap_sz);
+       if (!*bmap) {
+               plt_free(*mem);
+               *mem = NULL;
+               rc = -ENOMEM;
+       }
+
+       return rc;
+}
+
+static void
+rsrc_bmap_free(struct mcs_rsrc *rsrc)
+{
+       plt_bitmap_free(rsrc->tcam_bmap);
+       plt_free(rsrc->tcam_bmap_mem);
+       plt_bitmap_free(rsrc->secy_bmap);
+       plt_free(rsrc->secy_bmap_mem);
+       plt_bitmap_free(rsrc->sc_bmap);
+       plt_free(rsrc->sc_bmap_mem);
+       plt_bitmap_free(rsrc->sa_bmap);
+       plt_free(rsrc->sa_bmap_mem);
+}
+
+static int
+rsrc_bmap_alloc(struct mcs_priv *priv, struct mcs_rsrc *rsrc)
+{
+       int rc;
+
+       rc = mcs_alloc_bmap(priv->tcam_entries << 1, &rsrc->tcam_bmap_mem, &rsrc->tcam_bmap);
+       if (rc)
+               goto exit;
+
+       rc = mcs_alloc_bmap(priv->secy_entries << 1, &rsrc->secy_bmap_mem, &rsrc->secy_bmap);
+       if (rc)
+               goto exit;
+
+       rc = mcs_alloc_bmap(priv->sc_entries << 1, &rsrc->sc_bmap_mem, &rsrc->sc_bmap);
+       if (rc)
+               goto exit;
+
+       rc = mcs_alloc_bmap(priv->sa_entries << 1, &rsrc->sa_bmap_mem, &rsrc->sa_bmap);
+       if (rc)
+               goto exit;
+
+       return rc;
+exit:
+       rsrc_bmap_free(rsrc);
+
+       return rc;
+}
+
+static int
+mcs_alloc_rsrc_bmap(struct roc_mcs *mcs)
+{
+       struct mcs_priv *priv = roc_mcs_to_mcs_priv(mcs);
+       struct mcs_hw_info *hw;
+       int i, rc;
+
+       mbox_alloc_msg_mcs_get_hw_info(mcs->mbox);
+       rc = mbox_process_msg(mcs->mbox, (void *)&hw);
+       if (rc)
+               return rc;
+
+       priv->num_mcs_blks = hw->num_mcs_blks;
+       priv->tcam_entries = hw->tcam_entries;
+       priv->secy_entries = hw->secy_entries;
+       priv->sc_entries = hw->sc_entries;
+       priv->sa_entries = hw->sa_entries;
+
+       rc = rsrc_bmap_alloc(priv, &priv->dev_rsrc);
+       if (rc)
+               return rc;
+
+       priv->port_rsrc = plt_zmalloc(sizeof(struct mcs_rsrc) * 4, 0);
+       if (priv->port_rsrc == NULL) {
+               rsrc_bmap_free(&priv->dev_rsrc);
+               return -ENOMEM;
+       }
+
+       for (i = 0; i < MAX_PORTS_PER_MCS; i++) {
+               rc = rsrc_bmap_alloc(priv, &priv->port_rsrc[i]);
+               if (rc)
+                       goto exit;
+
+               priv->port_rsrc[i].sc_conf =
+                       plt_zmalloc(priv->sc_entries * sizeof(struct mcs_sc_conf), 0);
+               if (priv->port_rsrc[i].sc_conf == NULL) {
+                       rsrc_bmap_free(&priv->port_rsrc[i]);
+                       goto exit;
+               }
+       }
+
+       return rc;
+
+exit:
+       while (i--) {
+               rsrc_bmap_free(&priv->port_rsrc[i]);
+               plt_free(priv->port_rsrc[i].sc_conf);
+       }
+       plt_free(priv->port_rsrc);
+
+       return -ENOMEM;
+}
+
+struct roc_mcs *
+roc_mcs_dev_init(uint8_t mcs_idx)
+{
+       struct roc_mcs *mcs;
+       struct npa_lf *npa;
+
+       if (!(roc_feature_bphy_has_macsec() || roc_feature_nix_has_macsec()))
+               return NULL;
+
+       mcs = roc_idev_mcs_get(mcs_idx);
+       if (mcs) {
+               plt_info("Skipping device, mcs device already probed");
+               mcs->refcount++;
+               return mcs;
+       }
+
+       mcs = plt_zmalloc(sizeof(struct roc_mcs), PLT_CACHE_LINE_SIZE);
+       if (!mcs)
+               return NULL;
+
+       npa = idev_npa_obj_get();
+       if (!npa)
+               goto exit;
+
+       mcs->mbox = npa->mbox;
+       mcs->idx = mcs_idx;
+
+       /* Add any per mcsv initialization */
+       if (mcs_alloc_rsrc_bmap(mcs))
+               goto exit;
+
+       roc_idev_mcs_set(mcs);
+       mcs->refcount++;
+
+       return mcs;
+exit:
+       plt_free(mcs);
+       return NULL;
+}
+
+void
+roc_mcs_dev_fini(struct roc_mcs *mcs)
+{
+       struct mcs_priv *priv;
+       int i;
+
+       mcs->refcount--;
+       if (mcs->refcount > 0)
+               return;
+
+       priv = roc_mcs_to_mcs_priv(mcs);
+
+       rsrc_bmap_free(&priv->dev_rsrc);
+
+       for (i = 0; i < MAX_PORTS_PER_MCS; i++) {
+               rsrc_bmap_free(&priv->port_rsrc[i]);
+               plt_free(priv->port_rsrc[i].sc_conf);
+       }
+
+       plt_free(priv->port_rsrc);
+
+       roc_idev_mcs_free(mcs);
+
+       plt_free(mcs);
+}
drivers/common/cnxk/roc_mcs.h new file +41 -0
new file mode 100644
index 0000000000..2f06ce2659
@@ -0,0 +1,41 @@
+/* SPDX-License-Identifier: BSD-3-Clause
+ * Copyright(C) 2022 Marvell.
+ */
+
+#ifndef _ROC_MCS_H_
+#define _ROC_MCS_H_
+
+#define MCS_AES_GCM_256_KEYLEN 32
+
+struct roc_mcs_hw_info {
+       uint8_t num_mcs_blks; /* Number of MCS blocks */
+       uint8_t tcam_entries; /* RX/TX Tcam entries per mcs block */
+       uint8_t secy_entries; /* RX/TX SECY entries per mcs block */
+       uint8_t sc_entries;   /* RX/TX SC CAM entries per mcs block */
+       uint16_t sa_entries;  /* PN table entries = SA entries */
+       uint64_t rsvd[16];
+};
+
+
+struct roc_mcs {
+       TAILQ_ENTRY(roc_mcs) next;
+       struct plt_pci_device *pci_dev;
+       struct mbox *mbox;
+       void *userdata;
+       uint8_t idx;
+       uint8_t refcount;
+
+#define ROC_MCS_MEM_SZ (1 * 1024)
+       uint8_t reserved[ROC_MCS_MEM_SZ] __plt_cache_aligned;
+} __plt_cache_aligned;
+
+TAILQ_HEAD(roc_mcs_head, roc_mcs);
+
+/* Initialization */
+__roc_api struct roc_mcs *roc_mcs_dev_init(uint8_t mcs_idx);
+__roc_api void roc_mcs_dev_fini(struct roc_mcs *mcs);
+/* Get roc mcs dev structure */
+__roc_api struct roc_mcs *roc_mcs_dev_get(uint8_t mcs_idx);
+/* HW info get */
+__roc_api int roc_mcs_hw_info_get(struct roc_mcs_hw_info *hw_info);
+#endif /* _ROC_MCS_H_ */
drivers/common/cnxk/roc_mcs_priv.h new file +65 -0
new file mode 100644
index 0000000000..9e0bbe4392
@@ -0,0 +1,65 @@
+/* SPDX-License-Identifier: BSD-3-Clause
+ * Copyright(C) 2022 Marvell.
+ */
+
+#ifndef _ROC_MCS_PRIV_H_
+#define _ROC_MCS_PRIV_H_
+
+#define MAX_PORTS_PER_MCS 4
+
+enum mcs_error_status {
+       MCS_ERR_PARAM = -900,
+       MCS_ERR_HW_NOTSUP = -901,
+       MCS_ERR_DEVICE_NOT_FOUND = -902,
+};
+
+#define MCS_SUPPORT_CHECK                                                                          \
+       do {                                                                                       \
+               if (!(roc_feature_bphy_has_macsec() || roc_feature_nix_has_macsec()))              \
+                       return MCS_ERR_HW_NOTSUP;                                                  \
+       } while (0)
+
+struct mcs_sc_conf {
+       struct {
+               uint64_t sci;
+               uint16_t sa_idx0;
+               uint16_t sa_idx1;
+               uint8_t rekey_enb;
+       } tx;
+       struct {
+               uint16_t sa_idx;
+               uint8_t an;
+       } rx;
+};
+
+struct mcs_rsrc {
+       struct plt_bitmap *tcam_bmap;
+       void *tcam_bmap_mem;
+       struct plt_bitmap *secy_bmap;
+       void *secy_bmap_mem;
+       struct plt_bitmap *sc_bmap;
+       void *sc_bmap_mem;
+       struct plt_bitmap *sa_bmap;
+       void *sa_bmap_mem;
+       struct mcs_sc_conf *sc_conf;
+};
+
+struct mcs_priv {
+       struct mcs_rsrc *port_rsrc;
+       struct mcs_rsrc dev_rsrc;
+       uint64_t default_sci;
+       uint32_t lmac_bmap;
+       uint8_t num_mcs_blks;
+       uint8_t tcam_entries;
+       uint8_t secy_entries;
+       uint8_t sc_entries;
+       uint16_t sa_entries;
+};
+
+static inline struct mcs_priv *
+roc_mcs_to_mcs_priv(struct roc_mcs *roc_mcs)
+{
+       return (struct mcs_priv *)&roc_mcs->reserved[0];
+}
+
+#endif /* _ROC_MCS_PRIV_H_ */
drivers/common/cnxk/roc_priv.h +3 -0
index 14fe2e452a..254a2d3310 100644
@@ -44,6 +44,9 @@
 /* DPI */
 #include "roc_dpi_priv.h"
 
+/* MCS */
+#include "roc_mcs_priv.h"
+
 /* REE */
 #include "roc_ree_priv.h"
 
drivers/common/cnxk/roc_utils.c +5 -0
index fe291fce96..9af2ae9b69 100644
@@ -16,6 +16,7 @@ roc_error_msg_get(int errorcode)
        case NPA_ERR_PARAM:
        case NPC_ERR_PARAM:
        case SSO_ERR_PARAM:
+       case MCS_ERR_PARAM:
        case UTIL_ERR_PARAM:
                err_msg = "Invalid parameter";
                break;
@@ -35,6 +36,7 @@ roc_error_msg_get(int errorcode)
                err_msg = "Operation not supported";
                break;
        case NIX_ERR_HW_NOTSUP:
+       case MCS_ERR_HW_NOTSUP:
                err_msg = "Hardware does not support";
                break;
        case NIX_ERR_QUEUE_INVALID_RANGE:
@@ -223,6 +225,9 @@ roc_error_msg_get(int errorcode)
        case SSO_ERR_DEVICE_NOT_BOUNDED:
                err_msg = "SSO pf/vf not found";
                break;
+       case MCS_ERR_DEVICE_NOT_FOUND:
+               err_msg = "MCS device not found";
+               break;
        case UTIL_ERR_FS:
                err_msg = "file operation failed";
                break;
drivers/common/cnxk/version.map +7 -1
index e1335e9068..900290b866 100644
@@ -94,6 +94,9 @@ INTERNAL {
        roc_idev_cpt_get;
        roc_idev_cpt_set;
        roc_idev_lmt_base_addr_get;
+       roc_idev_mcs_free;
+       roc_idev_mcs_get;
+       roc_idev_mcs_set;
        roc_idev_npa_maxpools_get;
        roc_idev_npa_maxpools_set;
        roc_idev_npa_nix_get;
@@ -132,6 +135,10 @@ INTERNAL {
        roc_se_auth_key_set;
        roc_se_ciph_key_set;
        roc_se_ctx_init;
+       roc_mcs_dev_init;
+       roc_mcs_dev_fini;
+       roc_mcs_dev_get;
+       roc_mcs_hw_info_get;
        roc_nix_bpf_alloc;
        roc_nix_bpf_config;
        roc_nix_bpf_connect;
--

2.25.1

#96 lore raw

PATCH v2 2/15 common/cnxk: add MACsec SA configuration

In reply to Akhil Goyal

Added ROC APIs to allocate/free MACsec resources
and APIs to write SA policy.

---
 drivers/common/cnxk/meson.build       |   1 +
 drivers/common/cnxk/roc_mbox.h        |  12 ++
 drivers/common/cnxk/roc_mcs.h         |  43 ++++++
 drivers/common/cnxk/roc_mcs_sec_cfg.c | 211 ++++++++++++++++++++++++++
 drivers/common/cnxk/version.map       |   4 +
 5 files changed, 271 insertions(+)
 create mode 100644 drivers/common/cnxk/roc_mcs_sec_cfg.c
drivers/common/cnxk/meson.build +1 -0
index e33c002676..589baf74fe 100644
@@ -27,6 +27,7 @@ sources = files(
         'roc_ie_ot.c',
         'roc_mbox.c',
         'roc_mcs.c',
+        'roc_mcs_sec_cfg.c',
         'roc_ml.c',
         'roc_model.c',
         'roc_nix.c',
drivers/common/cnxk/roc_mbox.h +12 -0
index ef7a7d6513..ab1173e805 100644
@@ -300,6 +300,7 @@ struct mbox_msghdr {
 	M(MCS_ALLOC_RESOURCES, 0xa000, mcs_alloc_resources, mcs_alloc_rsrc_req,                    \
 	  mcs_alloc_rsrc_rsp)                                                                      \
 	M(MCS_FREE_RESOURCES, 0xa001, mcs_free_resources, mcs_free_rsrc_req, msg_rsp)              \
+	M(MCS_SA_PLCY_WRITE, 0xa005, mcs_sa_plcy_write, mcs_sa_plcy_write_req, msg_rsp)            \
 	M(MCS_GET_HW_INFO, 0xa00b, mcs_get_hw_info, msg_req, mcs_hw_info)                          \
 
 /* Messages initiated by AF (range 0xC00 - 0xDFF) */
@@ -725,6 +726,17 @@ struct mcs_free_rsrc_req {
 	uint64_t __io rsvd;
 };
 
+struct mcs_sa_plcy_write_req {
+	struct mbox_msghdr hdr;
+	uint64_t __io plcy[2][9]; /* Support 2 SA policy */
+	uint8_t __io sa_index[2];
+	uint8_t __io sa_cnt;
+	uint8_t __io mcs_id;
+	uint8_t __io dir;
+	uint64_t __io rsvd;
+};
+
+
 struct mcs_hw_info {
 	struct mbox_msghdr hdr;
 	uint8_t __io num_mcs_blks; /* Number of MCS blocks */
drivers/common/cnxk/roc_mcs.h +43 -0

53 lines not on this page · raw message

drivers/common/cnxk/roc_mcs_sec_cfg.c new file +211 -0

211 lines not on this page · raw message

drivers/common/cnxk/version.map +4 -0
index 900290b866..bd8a3095f9 100644
@@ -139,6 +139,10 @@ INTERNAL {
 	roc_mcs_dev_fini;
 	roc_mcs_dev_get;
 	roc_mcs_hw_info_get;
+	roc_mcs_rsrc_alloc;
+	roc_mcs_rsrc_free;
+	roc_mcs_sa_policy_read;
+	roc_mcs_sa_policy_write;
 	roc_nix_bpf_alloc;
 	roc_nix_bpf_config;
 	roc_nix_bpf_connect;
Signature · 1 line
2.25.1
#97 lore raw

PATCH v2 3/15 common/cnxk: add MACsec SC configuration APIs

In reply to Akhil Goyal

Added ROC APIs to configure MACsec secure channel(SC) and its mapping with SAs for both Rx and Tx.

---
 drivers/common/cnxk/roc_mbox.h        |  37 ++++++
 drivers/common/cnxk/roc_mcs.h         |  41 ++++++
 drivers/common/cnxk/roc_mcs_sec_cfg.c | 171 ++++++++++++++++++++++++++
 drivers/common/cnxk/version.map       |   7 ++
 4 files changed, 256 insertions(+)
drivers/common/cnxk/roc_mbox.h +37 -0
index ab1173e805..40b761ee99 100644
@@ -300,7 +300,10 @@ struct mbox_msghdr {
 	M(MCS_ALLOC_RESOURCES, 0xa000, mcs_alloc_resources, mcs_alloc_rsrc_req,                    \
 	  mcs_alloc_rsrc_rsp)                                                                      \
 	M(MCS_FREE_RESOURCES, 0xa001, mcs_free_resources, mcs_free_rsrc_req, msg_rsp)              \
+	M(MCS_RX_SC_CAM_WRITE, 0xa004, mcs_rx_sc_cam_write, mcs_rx_sc_cam_write_req, msg_rsp)      \
 	M(MCS_SA_PLCY_WRITE, 0xa005, mcs_sa_plcy_write, mcs_sa_plcy_write_req, msg_rsp)            \
+	M(MCS_TX_SC_SA_MAP_WRITE, 0xa006, mcs_tx_sc_sa_map_write, mcs_tx_sc_sa_map, msg_rsp)       \
+	M(MCS_RX_SC_SA_MAP_WRITE, 0xa007, mcs_rx_sc_sa_map_write, mcs_rx_sc_sa_map, msg_rsp)       \
 	M(MCS_GET_HW_INFO, 0xa00b, mcs_get_hw_info, msg_req, mcs_hw_info)                          \
 
 /* Messages initiated by AF (range 0xC00 - 0xDFF) */
@@ -726,6 +729,16 @@ struct mcs_free_rsrc_req {
 	uint64_t __io rsvd;
 };
 
+/* RX SC_CAM mapping */
+struct mcs_rx_sc_cam_write_req {
+	struct mbox_msghdr hdr;
+	uint64_t __io sci;     /* SCI */
+	uint64_t __io secy_id; /* secy index mapped to SC */
+	uint8_t __io sc_id;    /* SC CAM entry index */
+	uint8_t __io mcs_id;
+	uint64_t __io rsvd;
+};
+
 struct mcs_sa_plcy_write_req {
 	struct mbox_msghdr hdr;
 	uint64_t __io plcy[2][9]; /* Support 2 SA policy */
@@ -736,6 +749,30 @@ struct mcs_sa_plcy_write_req {
 	uint64_t __io rsvd;
 };
 
+struct mcs_tx_sc_sa_map {
+	struct mbox_msghdr hdr;
+	uint8_t __io sa_index0;
+	uint8_t __io sa_index1;
+	uint8_t __io rekey_ena;
+	uint8_t __io sa_index0_vld;
+	uint8_t __io sa_index1_vld;
+	uint8_t __io tx_sa_active;
+	uint64_t __io sectag_sci;
+	uint8_t __io sc_id; /* used as index for SA_MEM_MAP */
+	uint8_t __io mcs_id;
+	uint64_t __io rsvd;
+};
+
+struct mcs_rx_sc_sa_map {
+	struct mbox_msghdr hdr;
+	uint8_t __io sa_index;
+	uint8_t __io sa_in_use;
+	uint8_t __io sc_id;
+	/* an range is 0-3, sc_id + an used as index SA_MEM_MAP */
+	uint8_t __io an;
+	uint8_t __io mcs_id;
+	uint64_t __io rsvd;
+};
 
 struct mcs_hw_info {
 	struct mbox_msghdr hdr;
drivers/common/cnxk/roc_mcs.h +41 -0

57 lines not on this page · raw message

drivers/common/cnxk/roc_mcs_sec_cfg.c +171 -0

174 lines not on this page · raw message

drivers/common/cnxk/version.map +7 -0
index bd8a3095f9..dbfda62ad1 100644
@@ -141,8 +141,15 @@ INTERNAL {
 	roc_mcs_hw_info_get;
 	roc_mcs_rsrc_alloc;
 	roc_mcs_rsrc_free;
+	roc_mcs_rx_sc_cam_enable;
+	roc_mcs_rx_sc_cam_read;
+	roc_mcs_rx_sc_cam_write;
+	roc_mcs_rx_sc_sa_map_read;
+	roc_mcs_rx_sc_sa_map_write;
 	roc_mcs_sa_policy_read;
 	roc_mcs_sa_policy_write;
+	roc_mcs_tx_sc_sa_map_read;
+	roc_mcs_tx_sc_sa_map_write;
 	roc_nix_bpf_alloc;
 	roc_nix_bpf_config;
 	roc_nix_bpf_connect;
Signature · 1 line
2.25.1