199a2dd95SBruce Richardson /* SPDX-License-Identifier: BSD-3-Clause 299a2dd95SBruce Richardson * Copyright 2017 NXP. 399a2dd95SBruce Richardson * Copyright(c) 2017 Intel Corporation. 499a2dd95SBruce Richardson */ 599a2dd95SBruce Richardson 699a2dd95SBruce Richardson #ifndef _RTE_SECURITY_DRIVER_H_ 799a2dd95SBruce Richardson #define _RTE_SECURITY_DRIVER_H_ 899a2dd95SBruce Richardson 999a2dd95SBruce Richardson /** 1099a2dd95SBruce Richardson * @file rte_security_driver.h 1199a2dd95SBruce Richardson * 1299a2dd95SBruce Richardson * RTE Security Common Definitions 1399a2dd95SBruce Richardson */ 1499a2dd95SBruce Richardson 15*719834a6SMattias Rönnblom #include <rte_compat.h> 16*719834a6SMattias Rönnblom #include "rte_security.h" 17*719834a6SMattias Rönnblom 1899a2dd95SBruce Richardson #ifdef __cplusplus 1999a2dd95SBruce Richardson extern "C" { 2099a2dd95SBruce Richardson #endif 2199a2dd95SBruce Richardson 2299a2dd95SBruce Richardson /** 232973dbf9SAkhil Goyal * @internal 242973dbf9SAkhil Goyal * Security session to be used by library for internal usage 252973dbf9SAkhil Goyal */ 262973dbf9SAkhil Goyal struct rte_security_session { 272973dbf9SAkhil Goyal uint64_t opaque_data; 282973dbf9SAkhil Goyal /**< Opaque user defined data */ 292973dbf9SAkhil Goyal uint64_t fast_mdata; 302973dbf9SAkhil Goyal /**< Fast metadata to be used for inline path */ 312973dbf9SAkhil Goyal rte_iova_t driver_priv_data_iova; 322973dbf9SAkhil Goyal /**< session private data IOVA address */ 332973dbf9SAkhil Goyal 348cecb9adSTyler Retzlaff alignas(RTE_CACHE_LINE_MIN_SIZE) 3558064289SStephen Hemminger uint8_t driver_priv_data[]; 362973dbf9SAkhil Goyal /**< Private session material, variable size (depends on driver) */ 372973dbf9SAkhil Goyal }; 382973dbf9SAkhil Goyal 392973dbf9SAkhil Goyal /** 4079bdb787SAkhil Goyal * Security context for crypto/eth devices 4179bdb787SAkhil Goyal * 4279bdb787SAkhil Goyal * Security instance for each driver to register security operations. 4379bdb787SAkhil Goyal * The application can get the security context from the crypto/eth device id 4479bdb787SAkhil Goyal * using the APIs rte_cryptodev_get_sec_ctx()/rte_eth_dev_get_sec_ctx() 4579bdb787SAkhil Goyal * This structure is used to identify the device(crypto/eth) for which the 4679bdb787SAkhil Goyal * security operations need to be performed. 4779bdb787SAkhil Goyal */ 4879bdb787SAkhil Goyal struct rte_security_ctx { 4979bdb787SAkhil Goyal void *device; 5079bdb787SAkhil Goyal /**< Crypto/ethernet device attached */ 5179bdb787SAkhil Goyal const struct rte_security_ops *ops; 5279bdb787SAkhil Goyal /**< Pointer to security ops for the device */ 5379bdb787SAkhil Goyal uint32_t flags; 5479bdb787SAkhil Goyal /**< Flags for security context */ 5579bdb787SAkhil Goyal uint16_t sess_cnt; 5679bdb787SAkhil Goyal /**< Number of sessions attached to this context */ 5779bdb787SAkhil Goyal uint16_t macsec_sc_cnt; 5879bdb787SAkhil Goyal /**< Number of MACsec SC attached to this context */ 5979bdb787SAkhil Goyal uint16_t macsec_sa_cnt; 6079bdb787SAkhil Goyal /**< Number of MACsec SA attached to this context */ 6179bdb787SAkhil Goyal }; 6279bdb787SAkhil Goyal 6379bdb787SAkhil Goyal /** 643f3fc330SAkhil Goyal * Helper macro to get driver private data 653f3fc330SAkhil Goyal */ 663f3fc330SAkhil Goyal #define SECURITY_GET_SESS_PRIV(s) \ 673f3fc330SAkhil Goyal ((void *)(((struct rte_security_session *)s)->driver_priv_data)) 683f3fc330SAkhil Goyal #define SECURITY_GET_SESS_PRIV_IOVA(s) \ 693f3fc330SAkhil Goyal (((struct rte_security_session *)s)->driver_priv_data_iova) 703f3fc330SAkhil Goyal 713f3fc330SAkhil Goyal /** 7299a2dd95SBruce Richardson * Configure a security session on a device. 7399a2dd95SBruce Richardson * 7499a2dd95SBruce Richardson * @param device Crypto/eth device pointer 7599a2dd95SBruce Richardson * @param conf Security session configuration 7699a2dd95SBruce Richardson * @param sess Pointer to Security private session structure 7799a2dd95SBruce Richardson * 7899a2dd95SBruce Richardson * @return 7999a2dd95SBruce Richardson * - Returns 0 if private session structure have been created successfully. 8099a2dd95SBruce Richardson * - Returns -EINVAL if input parameters are invalid. 8199a2dd95SBruce Richardson * - Returns -ENOTSUP if crypto device does not support the crypto transform. 8299a2dd95SBruce Richardson */ 8399a2dd95SBruce Richardson typedef int (*security_session_create_t)(void *device, 8499a2dd95SBruce Richardson struct rte_security_session_conf *conf, 853f3fc330SAkhil Goyal struct rte_security_session *sess); 8699a2dd95SBruce Richardson 8799a2dd95SBruce Richardson /** 8899a2dd95SBruce Richardson * Free driver private session data. 8999a2dd95SBruce Richardson * 9099a2dd95SBruce Richardson * @param device Crypto/eth device pointer 9199a2dd95SBruce Richardson * @param sess Security session structure 9299a2dd95SBruce Richardson */ 9399a2dd95SBruce Richardson typedef int (*security_session_destroy_t)(void *device, 9499a2dd95SBruce Richardson struct rte_security_session *sess); 9599a2dd95SBruce Richardson 9699a2dd95SBruce Richardson /** 9799a2dd95SBruce Richardson * Update driver private session data. 9899a2dd95SBruce Richardson * 9999a2dd95SBruce Richardson * @param device Crypto/eth device pointer 10099a2dd95SBruce Richardson * @param sess Pointer to Security private session structure 10199a2dd95SBruce Richardson * @param conf Security session configuration 10299a2dd95SBruce Richardson * 10399a2dd95SBruce Richardson * @return 10499a2dd95SBruce Richardson * - Returns 0 if private session structure have been updated successfully. 10599a2dd95SBruce Richardson * - Returns -EINVAL if input parameters are invalid. 10699a2dd95SBruce Richardson * - Returns -ENOTSUP if crypto device does not support the crypto transform. 10799a2dd95SBruce Richardson */ 10899a2dd95SBruce Richardson typedef int (*security_session_update_t)(void *device, 10999a2dd95SBruce Richardson struct rte_security_session *sess, 11099a2dd95SBruce Richardson struct rte_security_session_conf *conf); 11199a2dd95SBruce Richardson 11299a2dd95SBruce Richardson /** 113bbbe6c59SAkhil Goyal * Configure a MACsec secure channel (SC) on a device. 114bbbe6c59SAkhil Goyal * 115bbbe6c59SAkhil Goyal * @param device Crypto/eth device pointer 116bbbe6c59SAkhil Goyal * @param conf MACsec SC configuration params 117bbbe6c59SAkhil Goyal * 118bbbe6c59SAkhil Goyal * @return 119bbbe6c59SAkhil Goyal * - positive sc_id if SC is created successfully. 120bbbe6c59SAkhil Goyal * - -EINVAL if input parameters are invalid. 121bbbe6c59SAkhil Goyal * - -ENOTSUP if device does not support MACsec. 122bbbe6c59SAkhil Goyal * - -ENOMEM if the SC cannot be created. 123bbbe6c59SAkhil Goyal */ 124bbbe6c59SAkhil Goyal typedef int (*security_macsec_sc_create_t)(void *device, struct rte_security_macsec_sc *conf); 125bbbe6c59SAkhil Goyal 126bbbe6c59SAkhil Goyal /** 127bbbe6c59SAkhil Goyal * Free MACsec secure channel (SC). 128bbbe6c59SAkhil Goyal * 129bbbe6c59SAkhil Goyal * @param device Crypto/eth device pointer 130bbbe6c59SAkhil Goyal * @param sc_id MACsec SC ID 131b241a5adSAkhil Goyal * @param dir Direction of SC 132bbbe6c59SAkhil Goyal */ 133b241a5adSAkhil Goyal typedef int (*security_macsec_sc_destroy_t)(void *device, uint16_t sc_id, 134b241a5adSAkhil Goyal enum rte_security_macsec_direction dir); 135bbbe6c59SAkhil Goyal 136bbbe6c59SAkhil Goyal /** 137bbbe6c59SAkhil Goyal * Configure a MACsec security Association (SA) on a device. 138bbbe6c59SAkhil Goyal * 139bbbe6c59SAkhil Goyal * @param device Crypto/eth device pointer 140bbbe6c59SAkhil Goyal * @param conf MACsec SA configuration params 141bbbe6c59SAkhil Goyal * 142bbbe6c59SAkhil Goyal * @return 143bbbe6c59SAkhil Goyal * - positive sa_id if SA is created successfully. 144bbbe6c59SAkhil Goyal * - -EINVAL if input parameters are invalid. 145bbbe6c59SAkhil Goyal * - -ENOTSUP if device does not support MACsec. 146bbbe6c59SAkhil Goyal * - -ENOMEM if the SA cannot be created. 147bbbe6c59SAkhil Goyal */ 148bbbe6c59SAkhil Goyal typedef int (*security_macsec_sa_create_t)(void *device, struct rte_security_macsec_sa *conf); 149bbbe6c59SAkhil Goyal 150bbbe6c59SAkhil Goyal /** 151bbbe6c59SAkhil Goyal * Free MACsec security association (SA). 152bbbe6c59SAkhil Goyal * 153bbbe6c59SAkhil Goyal * @param device Crypto/eth device pointer 154bbbe6c59SAkhil Goyal * @param sa_id MACsec SA ID 155b241a5adSAkhil Goyal * @param dir Direction of SA 156bbbe6c59SAkhil Goyal */ 157b241a5adSAkhil Goyal typedef int (*security_macsec_sa_destroy_t)(void *device, uint16_t sa_id, 158b241a5adSAkhil Goyal enum rte_security_macsec_direction dir); 159bbbe6c59SAkhil Goyal 160bbbe6c59SAkhil Goyal /** 16199a2dd95SBruce Richardson * Get the size of a security session 16299a2dd95SBruce Richardson * 16399a2dd95SBruce Richardson * @param device Crypto/eth device pointer 16499a2dd95SBruce Richardson * 16599a2dd95SBruce Richardson * @return 16699a2dd95SBruce Richardson * - On success returns the size of the session structure for device 16799a2dd95SBruce Richardson * - On failure returns 0 16899a2dd95SBruce Richardson */ 16999a2dd95SBruce Richardson typedef unsigned int (*security_session_get_size)(void *device); 17099a2dd95SBruce Richardson 17199a2dd95SBruce Richardson /** 17299a2dd95SBruce Richardson * Get stats from the PMD. 17399a2dd95SBruce Richardson * 17499a2dd95SBruce Richardson * @param device Crypto/eth device pointer 17599a2dd95SBruce Richardson * @param sess Pointer to Security private session structure 17699a2dd95SBruce Richardson * @param stats Security stats of the driver 17799a2dd95SBruce Richardson * 17899a2dd95SBruce Richardson * @return 17999a2dd95SBruce Richardson * - Returns 0 if private session structure have been updated successfully. 18099a2dd95SBruce Richardson * - Returns -EINVAL if session parameters are invalid. 18199a2dd95SBruce Richardson */ 18299a2dd95SBruce Richardson typedef int (*security_session_stats_get_t)(void *device, 18399a2dd95SBruce Richardson struct rte_security_session *sess, 18499a2dd95SBruce Richardson struct rte_security_stats *stats); 18599a2dd95SBruce Richardson 186bbbe6c59SAkhil Goyal /** 187bbbe6c59SAkhil Goyal * Get MACsec secure channel stats from the PMD. 188bbbe6c59SAkhil Goyal * 189bbbe6c59SAkhil Goyal * @param device Crypto/eth device pointer 190bbbe6c59SAkhil Goyal * @param sc_id secure channel ID created by rte_security_macsec_sc_create() 191b241a5adSAkhil Goyal * @param dir direction of SC 192bbbe6c59SAkhil Goyal * @param stats SC stats of the driver 193bbbe6c59SAkhil Goyal * 194bbbe6c59SAkhil Goyal * @return 195bbbe6c59SAkhil Goyal * - 0 if success. 196bbbe6c59SAkhil Goyal * - -EINVAL if sc_id or device is invalid. 197bbbe6c59SAkhil Goyal */ 198bbbe6c59SAkhil Goyal typedef int (*security_macsec_sc_stats_get_t)(void *device, uint16_t sc_id, 199b241a5adSAkhil Goyal enum rte_security_macsec_direction dir, 200bbbe6c59SAkhil Goyal struct rte_security_macsec_sc_stats *stats); 201bbbe6c59SAkhil Goyal 202bbbe6c59SAkhil Goyal /** 203bbbe6c59SAkhil Goyal * Get MACsec SA stats from the PMD. 204bbbe6c59SAkhil Goyal * 205bbbe6c59SAkhil Goyal * @param device Crypto/eth device pointer 206bbbe6c59SAkhil Goyal * @param sa_id secure channel ID created by rte_security_macsec_sc_create() 207b241a5adSAkhil Goyal * @param dir direction of SA 208bbbe6c59SAkhil Goyal * @param stats SC stats of the driver 209bbbe6c59SAkhil Goyal * 210bbbe6c59SAkhil Goyal * @return 211bbbe6c59SAkhil Goyal * - 0 if success. 212bbbe6c59SAkhil Goyal * - -EINVAL if sa_id or device is invalid. 213bbbe6c59SAkhil Goyal */ 214bbbe6c59SAkhil Goyal typedef int (*security_macsec_sa_stats_get_t)(void *device, uint16_t sa_id, 215b241a5adSAkhil Goyal enum rte_security_macsec_direction dir, 216bbbe6c59SAkhil Goyal struct rte_security_macsec_sa_stats *stats); 217bbbe6c59SAkhil Goyal 218bbbe6c59SAkhil Goyal 219bbbe6c59SAkhil Goyal 2203867ed02SAkhil Goyal __rte_internal 22199a2dd95SBruce Richardson int rte_security_dynfield_register(void); 22299a2dd95SBruce Richardson 22399a2dd95SBruce Richardson /** 2241d63855bSNithin Dabilpuram * @internal 2251d63855bSNithin Dabilpuram * Register mbuf dynamic field for security inline ingress Out-of-Place(OOP) 2261d63855bSNithin Dabilpuram * processing. 2271d63855bSNithin Dabilpuram */ 2281d63855bSNithin Dabilpuram __rte_internal 2291d63855bSNithin Dabilpuram int rte_security_oop_dynfield_register(void); 2301d63855bSNithin Dabilpuram 2311d63855bSNithin Dabilpuram /** 23299a2dd95SBruce Richardson * Update the mbuf with provided metadata. 23399a2dd95SBruce Richardson * 23499a2dd95SBruce Richardson * @param device Crypto/eth device pointer 23599a2dd95SBruce Richardson * @param sess Security session structure 23699a2dd95SBruce Richardson * @param mb Packet buffer 23799a2dd95SBruce Richardson * @param params Metadata 23899a2dd95SBruce Richardson * 23999a2dd95SBruce Richardson * @return 24099a2dd95SBruce Richardson * - Returns 0 if metadata updated successfully. 24199a2dd95SBruce Richardson * - Returns -ve value for errors. 24299a2dd95SBruce Richardson */ 24399a2dd95SBruce Richardson typedef int (*security_set_pkt_metadata_t)(void *device, 24499a2dd95SBruce Richardson struct rte_security_session *sess, struct rte_mbuf *mb, 24599a2dd95SBruce Richardson void *params); 24699a2dd95SBruce Richardson 24799a2dd95SBruce Richardson /** 24899a2dd95SBruce Richardson * Get security capabilities of the device. 24999a2dd95SBruce Richardson * 25099a2dd95SBruce Richardson * @param device crypto/eth device pointer 25199a2dd95SBruce Richardson * 25299a2dd95SBruce Richardson * @return 25399a2dd95SBruce Richardson * - Returns rte_security_capability pointer on success. 25499a2dd95SBruce Richardson * - Returns NULL on error. 25599a2dd95SBruce Richardson */ 25699a2dd95SBruce Richardson typedef const struct rte_security_capability *(*security_capabilities_get_t)( 25799a2dd95SBruce Richardson void *device); 25899a2dd95SBruce Richardson 259165bb658SAnoob Joseph /** 260165bb658SAnoob Joseph * Configure security device to inject packets to an ethdev port. 261165bb658SAnoob Joseph * 262165bb658SAnoob Joseph * @param device Crypto/eth device pointer 263165bb658SAnoob Joseph * @param port_id Port identifier of the ethernet device to which packets need to be 264165bb658SAnoob Joseph * injected. 265165bb658SAnoob Joseph * @param enable Flag to enable and disable connection between a security device and 266165bb658SAnoob Joseph * an ethdev port. 267165bb658SAnoob Joseph * @return 268165bb658SAnoob Joseph * - 0 if successful. 269165bb658SAnoob Joseph * - -EINVAL if context NULL or port_id is invalid. 270165bb658SAnoob Joseph * - -EBUSY if devices are not in stopped state. 271165bb658SAnoob Joseph * - -ENOTSUP if security device does not support injecting to the ethdev port. 272165bb658SAnoob Joseph */ 273165bb658SAnoob Joseph typedef int (*security_rx_inject_configure)(void *device, uint16_t port_id, bool enable); 274165bb658SAnoob Joseph 275165bb658SAnoob Joseph /** 276165bb658SAnoob Joseph * Perform security processing of packets and inject the processed packet to 277165bb658SAnoob Joseph * ethdev Rx. 278165bb658SAnoob Joseph * 279165bb658SAnoob Joseph * Rx inject would behave similarly to ethdev loopback but with the additional 280165bb658SAnoob Joseph * security processing. 281165bb658SAnoob Joseph * 282165bb658SAnoob Joseph * @param device Crypto/eth device pointer 283165bb658SAnoob Joseph * @param pkts The address of an array of *nb_pkts* pointers to 284165bb658SAnoob Joseph * *rte_mbuf* structures which contain the packets. 285165bb658SAnoob Joseph * @param sess The address of an array of *nb_pkts* pointers to 286165bb658SAnoob Joseph * *rte_security_session* structures corresponding 287165bb658SAnoob Joseph * to each packet. 288165bb658SAnoob Joseph * @param nb_pkts The maximum number of packets to process. 289165bb658SAnoob Joseph * 290165bb658SAnoob Joseph * @return 291165bb658SAnoob Joseph * The number of packets successfully injected to ethdev Rx. The return 292165bb658SAnoob Joseph * value can be less than the value of the *nb_pkts* parameter when the 293165bb658SAnoob Joseph * PMD internal queues have been filled up. 294165bb658SAnoob Joseph */ 295165bb658SAnoob Joseph typedef uint16_t (*security_inb_pkt_rx_inject)(void *device, 296165bb658SAnoob Joseph struct rte_mbuf **pkts, struct rte_security_session **sess, 297165bb658SAnoob Joseph uint16_t nb_pkts); 298165bb658SAnoob Joseph 29999a2dd95SBruce Richardson /** Security operations function pointer table */ 30099a2dd95SBruce Richardson struct rte_security_ops { 30199a2dd95SBruce Richardson security_session_create_t session_create; 30299a2dd95SBruce Richardson /**< Configure a security session. */ 30399a2dd95SBruce Richardson security_session_update_t session_update; 30499a2dd95SBruce Richardson /**< Update a security session. */ 30599a2dd95SBruce Richardson security_session_get_size session_get_size; 30699a2dd95SBruce Richardson /**< Return size of security session. */ 30799a2dd95SBruce Richardson security_session_stats_get_t session_stats_get; 30899a2dd95SBruce Richardson /**< Get security session statistics. */ 30999a2dd95SBruce Richardson security_session_destroy_t session_destroy; 31099a2dd95SBruce Richardson /**< Clear a security sessions private data. */ 31199a2dd95SBruce Richardson security_set_pkt_metadata_t set_pkt_metadata; 31299a2dd95SBruce Richardson /**< Update mbuf metadata. */ 31399a2dd95SBruce Richardson security_capabilities_get_t capabilities_get; 31499a2dd95SBruce Richardson /**< Get security capabilities. */ 315bbbe6c59SAkhil Goyal security_macsec_sc_create_t macsec_sc_create; 316bbbe6c59SAkhil Goyal /**< Configure a MACsec security channel (SC). */ 317bbbe6c59SAkhil Goyal security_macsec_sc_destroy_t macsec_sc_destroy; 318bbbe6c59SAkhil Goyal /**< Free a MACsec security channel (SC). */ 319bbbe6c59SAkhil Goyal security_macsec_sa_create_t macsec_sa_create; 320bbbe6c59SAkhil Goyal /**< Configure a MACsec security association (SA). */ 321bbbe6c59SAkhil Goyal security_macsec_sa_destroy_t macsec_sa_destroy; 322bbbe6c59SAkhil Goyal /**< Free a MACsec security association (SA). */ 323bbbe6c59SAkhil Goyal security_macsec_sc_stats_get_t macsec_sc_stats_get; 324bbbe6c59SAkhil Goyal /**< Get MACsec SC statistics. */ 325bbbe6c59SAkhil Goyal security_macsec_sa_stats_get_t macsec_sa_stats_get; 326bbbe6c59SAkhil Goyal /**< Get MACsec SA statistics. */ 327165bb658SAnoob Joseph security_rx_inject_configure rx_inject_configure; 328165bb658SAnoob Joseph /**< Rx inject configure. */ 329165bb658SAnoob Joseph security_inb_pkt_rx_inject inb_pkt_rx_inject; 330165bb658SAnoob Joseph /**< Perform security processing and do Rx inject. */ 33199a2dd95SBruce Richardson }; 33299a2dd95SBruce Richardson 33399a2dd95SBruce Richardson #ifdef __cplusplus 33499a2dd95SBruce Richardson } 33599a2dd95SBruce Richardson #endif 33699a2dd95SBruce Richardson 33799a2dd95SBruce Richardson #endif /* _RTE_SECURITY_DRIVER_H_ */ 338