xref: /dpdk/drivers/net/cnxk/cnxk_ethdev_mcs.h (revision bc8147e67434b4aaa46f0913ba9a071b04f721c4)
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(C) 2023 Marvell.
3  */
4 
5 #ifndef CNXK_ETHDEV_MCS_H
6 #define CNXK_ETHDEV_MCS_H
7 
8 #include <cnxk_ethdev.h>
9 
10 #define CNXK_MACSEC_HASH_KEY 16
11 
12 struct cnxk_mcs_dev {
13 	uint64_t default_sci;
14 	void *mdev;
15 	uint8_t port_id;
16 	uint8_t idx;
17 };
18 
19 enum cnxk_mcs_rsrc_type {
20 	CNXK_MCS_RSRC_TYPE_FLOWID,
21 	CNXK_MCS_RSRC_TYPE_SECY,
22 	CNXK_MCS_RSRC_TYPE_SC,
23 	CNXK_MCS_RSRC_TYPE_SA,
24 	CNXK_MCS_RSRC_TYPE_PORT,
25 };
26 
27 struct cnxk_mcs_flow_opts {
28 	uint32_t outer_tag_id;
29 	/**< {VLAN_ID[11:0]}, or 20-bit MPLS label*/
30 	uint8_t outer_priority;
31 	/**< {PCP/Pbits, DE/CFI} or {1'b0, EXP} for MPLS.*/
32 	uint32_t second_outer_tag_id;
33 	/**< {VLAN_ID[11:0]}, or 20-bit MPLS label*/
34 	uint8_t second_outer_priority;
35 	/**< {PCP/Pbits, DE/CFI} or {1'b0, EXP} for MPLS. */
36 	uint16_t bonus_data;
37 	/**< 2 bytes of additional bonus data extracted from one of the custom tags*/
38 	uint8_t tag_match_bitmap;
39 	uint8_t packet_type;
40 	uint8_t outer_vlan_type;
41 	uint8_t inner_vlan_type;
42 	uint8_t num_tags;
43 	bool express;
44 	uint8_t lmac_id;
45 	uint8_t flowid_user;
46 };
47 
48 struct cnxk_mcs_event_data {
49 	/* Valid for below events
50 	 * - ROC_MCS_EVENT_RX_SA_PN_SOFT_EXP
51 	 * - ROC_MCS_EVENT_TX_SA_PN_SOFT_EXP
52 	 */
53 	struct {
54 		uint8_t secy_idx;
55 		uint8_t sc_idx;
56 		uint8_t sa_idx;
57 	};
58 	/* Valid for below event
59 	 * - ROC_MCS_EVENT_FIFO_OVERFLOW
60 	 *
61 	 * Upon fatal error notification on a MCS port, driver resets below attributes of active
62 	 * flow entities(sc & sa) and then resets the port.
63 	 * - Reset NEXT_PN of active SAs to 1.
64 	 * - Reset TX active SA for each SC, TX_SA_ACTIVE = 0, SA_INDEX0_VLD = 1.
65 	 * - Clear SA_IN_USE for active ANs in RX_SA_MAP_MEM.
66 	 * - Clear all stats mapping to this port.
67 	 * - Reactivate SA_IN_USE for active ANs in RX_SA_MAP_MEM.
68 	 *
69 	 *  UMD driver notifies the following flow entity(sc & sa) details in application callback,
70 	 *  application is expected to exchange the Tx/Rx NEXT_PN, TX_SA_ACTIVE, active RX SC AN
71 	 *  details with peer device so that peer device can resets it's MACsec flow states and than
72 	 *  resume packet transfers.
73 	 */
74 	struct {
75 		uint16_t *tx_sa_array; /* Tx SAs whose PN memories were reset (NEXT_PN=1) */
76 		uint16_t *rx_sa_array; /* Rx SAs whose PN memories were reset (NEXT_PN=1) */
77 		uint16_t *tx_sc_array; /* Tx SCs whose active SAs were reset (TX_SA_ACTIVE=0) */
78 		uint16_t *rx_sc_array; /* Rx SCs whose state was reset */
79 		uint8_t *sc_an_array;  /* AN of Rx SCs(in rx_sc_array) which were reactivated */
80 		uint8_t num_tx_sa;     /* num entries in tx_sa_array */
81 		uint8_t num_rx_sa;     /* num entries in rx_sa_array */
82 		uint8_t num_tx_sc;     /* num entries in tx_sc_array */
83 		uint8_t num_rx_sc;     /* num entries in rx_sc_array */
84 		uint8_t lmac_id;       /* lmac_id/port which was recovered from fatal error */
85 	};
86 };
87 
88 struct cnxk_mcs_event_desc {
89 	struct rte_eth_dev *eth_dev;
90 	enum roc_mcs_event_type type;
91 	enum roc_mcs_event_subtype subtype;
92 	struct cnxk_mcs_event_data metadata;
93 };
94 
95 int cnxk_eth_macsec_sa_create(void *device, struct rte_security_macsec_sa *conf);
96 int cnxk_eth_macsec_sc_create(void *device, struct rte_security_macsec_sc *conf);
97 
98 int cnxk_eth_macsec_sa_destroy(void *device, uint16_t sa_id,
99 			       enum rte_security_macsec_direction dir);
100 int cnxk_eth_macsec_sc_destroy(void *device, uint16_t sc_id,
101 			       enum rte_security_macsec_direction dir);
102 
103 int cnxk_eth_macsec_sa_stats_get(void *device, uint16_t sa_id,
104 				 enum rte_security_macsec_direction dir,
105 				 struct rte_security_macsec_sa_stats *stats);
106 int cnxk_eth_macsec_sc_stats_get(void *device, uint16_t sa_id,
107 				 enum rte_security_macsec_direction dir,
108 				 struct rte_security_macsec_sc_stats *stats);
109 int cnxk_eth_macsec_session_stats_get(struct cnxk_eth_dev *dev, struct cnxk_macsec_sess *sess,
110 				      struct rte_security_stats *stats);
111 
112 int cnxk_eth_macsec_session_create(struct cnxk_eth_dev *dev, struct rte_security_session_conf *conf,
113 				   struct rte_security_session *sess);
114 int cnxk_eth_macsec_session_destroy(struct cnxk_eth_dev *dev, struct rte_security_session *sess);
115 
116 #endif /* CNXK_ETHDEV_MCS_H */
117