Linux kernel mirror (for testing)
git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel
os
linux
1/* SPDX-License-Identifier: GPL-2.0-only */
2
3#ifndef __NET_PSP_H
4#define __NET_PSP_H
5
6#include <linux/mutex.h>
7#include <linux/refcount.h>
8
9struct netlink_ext_ack;
10
11#define PSP_DEFAULT_UDP_PORT 1000
12
13struct psphdr {
14 u8 nexthdr;
15 u8 hdrlen;
16 u8 crypt_offset;
17 u8 verfl;
18 __be32 spi;
19 __be64 iv;
20 __be64 vc[]; /* optional */
21};
22
23#define PSP_ENCAP_HLEN (sizeof(struct udphdr) + sizeof(struct psphdr))
24
25#define PSP_SPI_KEY_ID GENMASK(30, 0)
26#define PSP_SPI_KEY_PHASE BIT(31)
27
28#define PSPHDR_CRYPT_OFFSET GENMASK(5, 0)
29
30#define PSPHDR_VERFL_SAMPLE BIT(7)
31#define PSPHDR_VERFL_DROP BIT(6)
32#define PSPHDR_VERFL_VERSION GENMASK(5, 2)
33#define PSPHDR_VERFL_VIRT BIT(1)
34#define PSPHDR_VERFL_ONE BIT(0)
35
36#define PSP_HDRLEN_NOOPT ((sizeof(struct psphdr) - 8) / 8)
37
38/**
39 * struct psp_dev_config - PSP device configuration
40 * @versions: PSP versions enabled on the device
41 */
42struct psp_dev_config {
43 u32 versions;
44};
45
46/**
47 * struct psp_dev - PSP device struct
48 * @main_netdev: original netdevice of this PSP device
49 * @ops: driver callbacks
50 * @caps: device capabilities
51 * @drv_priv: driver priv pointer
52 * @lock: instance lock, protects all fields
53 * @refcnt: reference count for the instance
54 * @id: instance id
55 * @generation: current generation of the device key
56 * @config: current device configuration
57 * @active_assocs: list of registered associations
58 * @prev_assocs: associations which use old (but still usable)
59 * device key
60 * @stale_assocs: associations which use a rotated out key
61 *
62 * @stats: statistics maintained by the core
63 * @stats.rotations: See stats attr key-rotations
64 * @stats.stales: See stats attr stale-events
65 *
66 * @rcu: RCU head for freeing the structure
67 */
68struct psp_dev {
69 struct net_device *main_netdev;
70
71 struct psp_dev_ops *ops;
72 struct psp_dev_caps *caps;
73 void *drv_priv;
74
75 struct mutex lock;
76 refcount_t refcnt;
77
78 u32 id;
79
80 u8 generation;
81
82 struct psp_dev_config config;
83
84 struct list_head active_assocs;
85 struct list_head prev_assocs;
86 struct list_head stale_assocs;
87
88 struct {
89 unsigned long rotations;
90 unsigned long stales;
91 } stats;
92
93 struct rcu_head rcu;
94};
95
96#define PSP_GEN_VALID_MASK 0x7f
97
98/**
99 * struct psp_dev_caps - PSP device capabilities
100 */
101struct psp_dev_caps {
102 /**
103 * @versions: mask of supported PSP versions
104 * Set this field to 0 to indicate PSP is not supported at all.
105 */
106 u32 versions;
107
108 /**
109 * @assoc_drv_spc: size of driver-specific state in Tx assoc
110 * Determines the size of struct psp_assoc::drv_data
111 */
112 u32 assoc_drv_spc;
113};
114
115#define PSP_MAX_KEY 32
116
117#define PSP_HDR_SIZE 16 /* We don't support optional fields, yet */
118#define PSP_TRL_SIZE 16 /* AES-GCM/GMAC trailer size */
119
120struct psp_skb_ext {
121 __be32 spi;
122 u16 dev_id;
123 u8 generation;
124 u8 version;
125};
126
127struct psp_key_parsed {
128 __be32 spi;
129 u8 key[PSP_MAX_KEY];
130};
131
132struct psp_assoc {
133 struct psp_dev *psd;
134
135 u16 dev_id;
136 u8 generation;
137 u8 version;
138 u8 peer_tx;
139
140 u32 upgrade_seq;
141
142 struct psp_key_parsed tx;
143 struct psp_key_parsed rx;
144
145 refcount_t refcnt;
146 struct rcu_head rcu;
147 struct work_struct work;
148 struct list_head assocs_list;
149
150 u8 drv_data[] __aligned(8);
151};
152
153struct psp_dev_stats {
154 union {
155 struct {
156 u64 rx_packets;
157 u64 rx_bytes;
158 u64 rx_auth_fail;
159 u64 rx_error;
160 u64 rx_bad;
161 u64 tx_packets;
162 u64 tx_bytes;
163 u64 tx_error;
164 };
165 DECLARE_FLEX_ARRAY(u64, required);
166 };
167};
168
169/**
170 * struct psp_dev_ops - netdev driver facing PSP callbacks
171 */
172struct psp_dev_ops {
173 /**
174 * @set_config: set configuration of a PSP device
175 * Driver can inspect @psd->config for the previous configuration.
176 * Core will update @psd->config with @config on success.
177 */
178 int (*set_config)(struct psp_dev *psd, struct psp_dev_config *conf,
179 struct netlink_ext_ack *extack);
180
181 /**
182 * @key_rotate: rotate the device key
183 */
184 int (*key_rotate)(struct psp_dev *psd, struct netlink_ext_ack *extack);
185
186 /**
187 * @rx_spi_alloc: allocate an Rx SPI+key pair
188 * Allocate an Rx SPI and resulting derived key.
189 * This key should remain valid until key rotation.
190 */
191 int (*rx_spi_alloc)(struct psp_dev *psd, u32 version,
192 struct psp_key_parsed *assoc,
193 struct netlink_ext_ack *extack);
194
195 /**
196 * @tx_key_add: add a Tx key to the device
197 * Install an association in the device. Core will allocate space
198 * for the driver to use at drv_data.
199 */
200 int (*tx_key_add)(struct psp_dev *psd, struct psp_assoc *pas,
201 struct netlink_ext_ack *extack);
202 /**
203 * @tx_key_del: remove a Tx key from the device
204 * Remove an association from the device.
205 */
206 void (*tx_key_del)(struct psp_dev *psd, struct psp_assoc *pas);
207
208 /**
209 * @get_stats: get statistics from the device
210 * Stats required by the spec must be maintained and filled in.
211 * Stats must be filled in member-by-member, never memset the struct.
212 */
213 void (*get_stats)(struct psp_dev *psd, struct psp_dev_stats *stats);
214};
215
216#endif /* __NET_PSP_H */