1 /* SPDX-License-Identifier: GPL-2.0+ */
2 /* Copyright (C) 2022 Microchip Technology Inc. and its subsidiaries.
3  * Microchip VCAP API
4  */
5 
6 #ifndef __VCAP_API_PRIVATE__
7 #define __VCAP_API_PRIVATE__
8 
9 #include <linux/types.h>
10 
11 #include "vcap_api.h"
12 #include "vcap_api_client.h"
13 
14 #define to_intrule(rule) container_of((rule), struct vcap_rule_internal, data)
15 
16 /* Private VCAP API rule data */
17 struct vcap_rule_internal {
18 	struct vcap_rule data; /* provided by the client */
19 	struct list_head list; /* the vcap admin list of rules */
20 	struct vcap_admin *admin; /* vcap hw instance */
21 	struct net_device *ndev;  /* the interface that the rule applies to */
22 	struct vcap_control *vctrl; /* the client control */
23 	u32 sort_key;  /* defines the position in the VCAP */
24 	int keyset_sw;  /* subwords in a keyset */
25 	int actionset_sw;  /* subwords in an actionset */
26 	int keyset_sw_regs;  /* registers in a subword in an keyset */
27 	int actionset_sw_regs;  /* registers in a subword in an actionset */
28 	int size; /* the size of the rule: max(entry, action) */
29 	u32 addr; /* address in the VCAP at insertion */
30 	u32 counter_id; /* counter id (if a dedicated counter is available) */
31 	struct vcap_counter counter; /* last read counter value */
32 };
33 
34 /* Bit iterator for the VCAP cache streams */
35 struct vcap_stream_iter {
36 	u32 offset; /* bit offset from the stream start */
37 	u32 sw_width; /* subword width in bits */
38 	u32 regs_per_sw; /* registers per subword */
39 	u32 reg_idx; /* current register index */
40 	u32 reg_bitpos; /* bit offset in current register */
41 	const struct vcap_typegroup *tg; /* current typegroup */
42 };
43 
44 /* Check that the control has a valid set of callbacks */
45 int vcap_api_check(struct vcap_control *ctrl);
46 /* Make a shallow copy of the rule without the fields */
47 struct vcap_rule_internal *vcap_dup_rule(struct vcap_rule_internal *ri);
48 /* Erase the VCAP cache area used or encoding and decoding */
49 void vcap_erase_cache(struct vcap_rule_internal *ri);
50 
51 /* Iterator functionality */
52 
53 void vcap_iter_init(struct vcap_stream_iter *itr, int sw_width,
54 		    const struct vcap_typegroup *tg, u32 offset);
55 void vcap_iter_next(struct vcap_stream_iter *itr);
56 void vcap_iter_set(struct vcap_stream_iter *itr, int sw_width,
57 		   const struct vcap_typegroup *tg, u32 offset);
58 void vcap_iter_update(struct vcap_stream_iter *itr);
59 
60 /* Keyset and keyfield functionality */
61 
62 /* Return the number of keyfields in the keyset */
63 int vcap_keyfield_count(struct vcap_control *vctrl,
64 			enum vcap_type vt, enum vcap_keyfield_set keyset);
65 /* Return the typegroup table for the matching keyset (using subword size) */
66 const struct vcap_typegroup *
67 vcap_keyfield_typegroup(struct vcap_control *vctrl,
68 			enum vcap_type vt, enum vcap_keyfield_set keyset);
69 /* Return the list of keyfields for the keyset */
70 const struct vcap_field *vcap_keyfields(struct vcap_control *vctrl,
71 					enum vcap_type vt,
72 					enum vcap_keyfield_set keyset);
73 
74 /* Actionset and actionfield functionality */
75 
76 /* Return the actionset information for the actionset */
77 const struct vcap_set *
78 vcap_actionfieldset(struct vcap_control *vctrl,
79 		    enum vcap_type vt, enum vcap_actionfield_set actionset);
80 /* Return the number of actionfields in the actionset */
81 int vcap_actionfield_count(struct vcap_control *vctrl,
82 			   enum vcap_type vt,
83 			   enum vcap_actionfield_set actionset);
84 /* Return the typegroup table for the matching actionset (using subword size) */
85 const struct vcap_typegroup *
86 vcap_actionfield_typegroup(struct vcap_control *vctrl, enum vcap_type vt,
87 			   enum vcap_actionfield_set actionset);
88 /* Return the list of actionfields for the actionset */
89 const struct vcap_field *
90 vcap_actionfields(struct vcap_control *vctrl,
91 		  enum vcap_type vt, enum vcap_actionfield_set actionset);
92 /* Map actionset id to a string with the actionset name */
93 const char *vcap_actionset_name(struct vcap_control *vctrl,
94 				enum vcap_actionfield_set actionset);
95 /* Map key field id to a string with the key name */
96 const char *vcap_actionfield_name(struct vcap_control *vctrl,
97 				  enum vcap_action_field action);
98 
99 /* Read key data from a VCAP address and discover if there are any rule keysets
100  * here
101  */
102 int vcap_addr_keysets(struct vcap_control *vctrl, struct net_device *ndev,
103 		      struct vcap_admin *admin, int addr,
104 		      struct vcap_keyset_list *kslist);
105 
106 /* Verify that the typegroup information, subword count, keyset and type id
107  * are in sync and correct, return the list of matchin keysets
108  */
109 int vcap_find_keystream_keysets(struct vcap_control *vctrl, enum vcap_type vt,
110 				u32 *keystream, u32 *mskstream, bool mask,
111 				int sw_max, struct vcap_keyset_list *kslist);
112 
113 #endif /* __VCAP_API_PRIVATE__ */
114