drivers: use SPDX tag for Intel copyright files
[dpdk.git] / drivers / net / ixgbe / ixgbe_ipsec.h
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(c) 2010-2017 Intel Corporation
3  */
4
5 #ifndef IXGBE_IPSEC_H_
6 #define IXGBE_IPSEC_H_
7
8 #include <rte_security.h>
9
10 #define IPSRXIDX_RX_EN                                    0x00000001
11 #define IPSRXIDX_TABLE_IP                                 0x00000002
12 #define IPSRXIDX_TABLE_SPI                                0x00000004
13 #define IPSRXIDX_TABLE_KEY                                0x00000006
14 #define IPSRXIDX_WRITE                                    0x80000000
15 #define IPSRXIDX_READ                                     0x40000000
16 #define IPSRXMOD_VALID                                    0x00000001
17 #define IPSRXMOD_PROTO                                    0x00000004
18 #define IPSRXMOD_DECRYPT                                  0x00000008
19 #define IPSRXMOD_IPV6                                     0x00000010
20 #define IXGBE_ADVTXD_POPTS_IPSEC                          0x00000400
21 #define IXGBE_ADVTXD_TUCMD_IPSEC_TYPE_ESP                 0x00002000
22 #define IXGBE_ADVTXD_TUCMD_IPSEC_ENCRYPT_EN               0x00004000
23 #define IXGBE_RXDADV_IPSEC_STATUS_SECP                    0x00020000
24 #define IXGBE_RXDADV_IPSEC_ERROR_BIT_MASK                 0x18000000
25 #define IXGBE_RXDADV_IPSEC_ERROR_INVALID_PROTOCOL         0x08000000
26 #define IXGBE_RXDADV_IPSEC_ERROR_INVALID_LENGTH           0x10000000
27 #define IXGBE_RXDADV_IPSEC_ERROR_AUTHENTICATION_FAILED    0x18000000
28
29 #define IPSEC_MAX_RX_IP_COUNT           128
30 #define IPSEC_MAX_SA_COUNT              1024
31
32 #define ESP_ICV_SIZE 16
33 #define ESP_TRAILER_SIZE 2
34
35 enum ixgbe_operation {
36         IXGBE_OP_AUTHENTICATED_ENCRYPTION,
37         IXGBE_OP_AUTHENTICATED_DECRYPTION
38 };
39
40 enum ixgbe_gcm_key {
41         IXGBE_GCM_KEY_128,
42         IXGBE_GCM_KEY_256
43 };
44
45 /**
46  * Generic IP address structure
47  * TODO: Find better location for this rte_net.h possibly.
48  **/
49 struct ipaddr {
50         enum ipaddr_type {
51                 IPv4,
52                 IPv6
53         } type;
54         /**< IP Address Type - IPv4/IPv6 */
55
56         union {
57                 uint32_t ipv4;
58                 uint32_t ipv6[4];
59         };
60 };
61
62 /** inline crypto crypto private session structure */
63 struct ixgbe_crypto_session {
64         enum ixgbe_operation op;
65         uint8_t *key;
66         uint32_t salt;
67         uint32_t sa_index;
68         uint32_t spi;
69         struct ipaddr src_ip;
70         struct ipaddr dst_ip;
71         struct rte_eth_dev *dev;
72 } __rte_cache_aligned;
73
74 struct ixgbe_crypto_rx_ip_table {
75         struct ipaddr ip;
76         uint16_t ref_count;
77 };
78 struct ixgbe_crypto_rx_sa_table {
79         uint32_t spi;
80         uint32_t ip_index;
81         uint32_t key[4];
82         uint32_t salt;
83         uint8_t  mode;
84         uint8_t  used;
85 };
86
87 struct ixgbe_crypto_tx_sa_table {
88         uint32_t spi;
89         uint32_t key[4];
90         uint32_t salt;
91         uint8_t  used;
92 };
93
94 union ixgbe_crypto_tx_desc_md {
95         uint64_t data;
96         struct {
97                 /**< SA table index */
98                 uint32_t sa_idx;
99                 /**< ICV and ESP trailer length */
100                 uint8_t pad_len;
101                 /**< enable encryption */
102                 uint8_t enc;
103         };
104 };
105
106 struct ixgbe_ipsec {
107         struct ixgbe_crypto_rx_ip_table rx_ip_tbl[IPSEC_MAX_RX_IP_COUNT];
108         struct ixgbe_crypto_rx_sa_table rx_sa_tbl[IPSEC_MAX_SA_COUNT];
109         struct ixgbe_crypto_tx_sa_table tx_sa_tbl[IPSEC_MAX_SA_COUNT];
110 };
111
112
113 struct rte_security_ctx *
114 ixgbe_ipsec_ctx_create(struct rte_eth_dev *dev);
115 int ixgbe_crypto_enable_ipsec(struct rte_eth_dev *dev);
116 int ixgbe_crypto_add_ingress_sa_from_flow(const void *sess,
117                                           const void *ip_spec,
118                                           uint8_t is_ipv6);
119
120
121
122 #endif /*IXGBE_IPSEC_H_*/