xref: /openbmc/linux/drivers/net/ethernet/microchip/vcap/vcap_api_private.h (revision 9a87ffc99ec8eb8d35eed7c4f816d75f5cc9662e)
1d4134d41SSteen Hegelund /* SPDX-License-Identifier: GPL-2.0+ */
2d4134d41SSteen Hegelund /* Copyright (C) 2022 Microchip Technology Inc. and its subsidiaries.
3d4134d41SSteen Hegelund  * Microchip VCAP API
4d4134d41SSteen Hegelund  */
5d4134d41SSteen Hegelund 
6d4134d41SSteen Hegelund #ifndef __VCAP_API_PRIVATE__
7d4134d41SSteen Hegelund #define __VCAP_API_PRIVATE__
8d4134d41SSteen Hegelund 
9d4134d41SSteen Hegelund #include <linux/types.h>
10d4134d41SSteen Hegelund 
11d4134d41SSteen Hegelund #include "vcap_api.h"
12d4134d41SSteen Hegelund #include "vcap_api_client.h"
13d4134d41SSteen Hegelund 
14d4134d41SSteen Hegelund #define to_intrule(rule) container_of((rule), struct vcap_rule_internal, data)
15d4134d41SSteen Hegelund 
16814e7693SSteen Hegelund enum vcap_rule_state {
17814e7693SSteen Hegelund 	VCAP_RS_PERMANENT, /* the rule is always stored in HW */
18814e7693SSteen Hegelund 	VCAP_RS_ENABLED, /* enabled in HW but can be disabled */
19814e7693SSteen Hegelund 	VCAP_RS_DISABLED, /* disabled (stored in SW) and can be enabled */
20814e7693SSteen Hegelund };
21814e7693SSteen Hegelund 
22d4134d41SSteen Hegelund /* Private VCAP API rule data */
23d4134d41SSteen Hegelund struct vcap_rule_internal {
24d4134d41SSteen Hegelund 	struct vcap_rule data; /* provided by the client */
25d4134d41SSteen Hegelund 	struct list_head list; /* the vcap admin list of rules */
26d4134d41SSteen Hegelund 	struct vcap_admin *admin; /* vcap hw instance */
27d4134d41SSteen Hegelund 	struct net_device *ndev;  /* the interface that the rule applies to */
28d4134d41SSteen Hegelund 	struct vcap_control *vctrl; /* the client control */
29d4134d41SSteen Hegelund 	u32 sort_key;  /* defines the position in the VCAP */
30d4134d41SSteen Hegelund 	int keyset_sw;  /* subwords in a keyset */
31d4134d41SSteen Hegelund 	int actionset_sw;  /* subwords in an actionset */
32d4134d41SSteen Hegelund 	int keyset_sw_regs;  /* registers in a subword in an keyset */
33d4134d41SSteen Hegelund 	int actionset_sw_regs;  /* registers in a subword in an actionset */
34d4134d41SSteen Hegelund 	int size; /* the size of the rule: max(entry, action) */
35d4134d41SSteen Hegelund 	u32 addr; /* address in the VCAP at insertion */
36d4134d41SSteen Hegelund 	u32 counter_id; /* counter id (if a dedicated counter is available) */
37d4134d41SSteen Hegelund 	struct vcap_counter counter; /* last read counter value */
38814e7693SSteen Hegelund 	enum vcap_rule_state state;  /* rule storage state */
39d4134d41SSteen Hegelund };
40d4134d41SSteen Hegelund 
41d4134d41SSteen Hegelund /* Bit iterator for the VCAP cache streams */
42d4134d41SSteen Hegelund struct vcap_stream_iter {
43d4134d41SSteen Hegelund 	u32 offset; /* bit offset from the stream start */
44d4134d41SSteen Hegelund 	u32 sw_width; /* subword width in bits */
45d4134d41SSteen Hegelund 	u32 regs_per_sw; /* registers per subword */
46d4134d41SSteen Hegelund 	u32 reg_idx; /* current register index */
47d4134d41SSteen Hegelund 	u32 reg_bitpos; /* bit offset in current register */
48d4134d41SSteen Hegelund 	const struct vcap_typegroup *tg; /* current typegroup */
49d4134d41SSteen Hegelund };
50d4134d41SSteen Hegelund 
51d4134d41SSteen Hegelund /* Check that the control has a valid set of callbacks */
52d4134d41SSteen Hegelund int vcap_api_check(struct vcap_control *ctrl);
533a792156SSteen Hegelund /* Erase the VCAP cache area used or encoding and decoding */
543a792156SSteen Hegelund void vcap_erase_cache(struct vcap_rule_internal *ri);
55d4134d41SSteen Hegelund 
56d4134d41SSteen Hegelund /* Iterator functionality */
57d4134d41SSteen Hegelund 
58d4134d41SSteen Hegelund void vcap_iter_init(struct vcap_stream_iter *itr, int sw_width,
59d4134d41SSteen Hegelund 		    const struct vcap_typegroup *tg, u32 offset);
60d4134d41SSteen Hegelund void vcap_iter_next(struct vcap_stream_iter *itr);
61d4134d41SSteen Hegelund void vcap_iter_set(struct vcap_stream_iter *itr, int sw_width,
62d4134d41SSteen Hegelund 		   const struct vcap_typegroup *tg, u32 offset);
63d4134d41SSteen Hegelund void vcap_iter_update(struct vcap_stream_iter *itr);
64d4134d41SSteen Hegelund 
65d4134d41SSteen Hegelund /* Keyset and keyfield functionality */
66d4134d41SSteen Hegelund 
67d4134d41SSteen Hegelund /* Return the number of keyfields in the keyset */
68d4134d41SSteen Hegelund int vcap_keyfield_count(struct vcap_control *vctrl,
69d4134d41SSteen Hegelund 			enum vcap_type vt, enum vcap_keyfield_set keyset);
70d4134d41SSteen Hegelund /* Return the typegroup table for the matching keyset (using subword size) */
71d4134d41SSteen Hegelund const struct vcap_typegroup *
72d4134d41SSteen Hegelund vcap_keyfield_typegroup(struct vcap_control *vctrl,
73d4134d41SSteen Hegelund 			enum vcap_type vt, enum vcap_keyfield_set keyset);
74d4134d41SSteen Hegelund /* Return the list of keyfields for the keyset */
75d4134d41SSteen Hegelund const struct vcap_field *vcap_keyfields(struct vcap_control *vctrl,
76d4134d41SSteen Hegelund 					enum vcap_type vt,
77d4134d41SSteen Hegelund 					enum vcap_keyfield_set keyset);
783a792156SSteen Hegelund 
793a792156SSteen Hegelund /* Actionset and actionfield functionality */
803a792156SSteen Hegelund 
8172d84dd6SSteen Hegelund /* Return the actionset information for the actionset */
8272d84dd6SSteen Hegelund const struct vcap_set *
8372d84dd6SSteen Hegelund vcap_actionfieldset(struct vcap_control *vctrl,
8472d84dd6SSteen Hegelund 		    enum vcap_type vt, enum vcap_actionfield_set actionset);
8572d84dd6SSteen Hegelund /* Return the number of actionfields in the actionset */
8672d84dd6SSteen Hegelund int vcap_actionfield_count(struct vcap_control *vctrl,
8772d84dd6SSteen Hegelund 			   enum vcap_type vt,
8872d84dd6SSteen Hegelund 			   enum vcap_actionfield_set actionset);
8972d84dd6SSteen Hegelund /* Return the typegroup table for the matching actionset (using subword size) */
9072d84dd6SSteen Hegelund const struct vcap_typegroup *
9172d84dd6SSteen Hegelund vcap_actionfield_typegroup(struct vcap_control *vctrl, enum vcap_type vt,
9272d84dd6SSteen Hegelund 			   enum vcap_actionfield_set actionset);
9372d84dd6SSteen Hegelund /* Return the list of actionfields for the actionset */
9472d84dd6SSteen Hegelund const struct vcap_field *
9572d84dd6SSteen Hegelund vcap_actionfields(struct vcap_control *vctrl,
9672d84dd6SSteen Hegelund 		  enum vcap_type vt, enum vcap_actionfield_set actionset);
973a792156SSteen Hegelund /* Map actionset id to a string with the actionset name */
983a792156SSteen Hegelund const char *vcap_actionset_name(struct vcap_control *vctrl,
993a792156SSteen Hegelund 				enum vcap_actionfield_set actionset);
1003a792156SSteen Hegelund /* Map key field id to a string with the key name */
1013a792156SSteen Hegelund const char *vcap_actionfield_name(struct vcap_control *vctrl,
1023a792156SSteen Hegelund 				  enum vcap_action_field action);
1033a792156SSteen Hegelund 
104610c32b2SHoratiu Vultur /* Read key data from a VCAP address and discover if there are any rule keysets
105610c32b2SHoratiu Vultur  * here
106610c32b2SHoratiu Vultur  */
107610c32b2SHoratiu Vultur int vcap_addr_keysets(struct vcap_control *vctrl, struct net_device *ndev,
108610c32b2SHoratiu Vultur 		      struct vcap_admin *admin, int addr,
109610c32b2SHoratiu Vultur 		      struct vcap_keyset_list *kslist);
110610c32b2SHoratiu Vultur 
111610c32b2SHoratiu Vultur /* Verify that the typegroup information, subword count, keyset and type id
112610c32b2SHoratiu Vultur  * are in sync and correct, return the list of matchin keysets
113610c32b2SHoratiu Vultur  */
114610c32b2SHoratiu Vultur int vcap_find_keystream_keysets(struct vcap_control *vctrl, enum vcap_type vt,
115610c32b2SHoratiu Vultur 				u32 *keystream, u32 *mskstream, bool mask,
116610c32b2SHoratiu Vultur 				int sw_max, struct vcap_keyset_list *kslist);
117610c32b2SHoratiu Vultur 
11818a15c76SSteen Hegelund /* Get the keysets that matches the rule key type/mask */
11918a15c76SSteen Hegelund int vcap_rule_get_keysets(struct vcap_rule_internal *ri,
12018a15c76SSteen Hegelund 			  struct vcap_keyset_list *matches);
121*9579e2c2SSteen Hegelund /* Decode a rule from the VCAP cache and return a copy */
122*9579e2c2SSteen Hegelund struct vcap_rule *vcap_decode_rule(struct vcap_rule_internal *elem);
123*9579e2c2SSteen Hegelund 
124d4134d41SSteen Hegelund #endif /* __VCAP_API_PRIVATE__ */
125