xref: /linux/drivers/net/ethernet/microchip/vcap/vcap_api_private.h (revision fafb66e5903c2bcfc7b7e259042a8282f18a6faa)
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 enum vcap_rule_state {
17 	VCAP_RS_PERMANENT, /* the rule is always stored in HW */
18 	VCAP_RS_ENABLED, /* enabled in HW but can be disabled */
19 	VCAP_RS_DISABLED, /* disabled (stored in SW) and can be enabled */
20 };
21 
22 /* Private VCAP API rule data */
23 struct vcap_rule_internal {
24 	struct vcap_rule data; /* provided by the client */
25 	struct list_head list; /* the vcap admin list of rules */
26 	struct vcap_admin *admin; /* vcap hw instance */
27 	struct net_device *ndev;  /* the interface that the rule applies to */
28 	struct vcap_control *vctrl; /* the client control */
29 	u32 sort_key;  /* defines the position in the VCAP */
30 	int keyset_sw;  /* subwords in a keyset */
31 	int actionset_sw;  /* subwords in an actionset */
32 	int keyset_sw_regs;  /* registers in a subword in an keyset */
33 	int actionset_sw_regs;  /* registers in a subword in an actionset */
34 	int size; /* the size of the rule: max(entry, action) */
35 	u32 addr; /* address in the VCAP at insertion */
36 	u32 counter_id; /* counter id (if a dedicated counter is available) */
37 	struct vcap_counter counter; /* last read counter value */
38 	enum vcap_rule_state state;  /* rule storage state */
39 };
40 
41 /* Bit iterator for the VCAP cache streams */
42 struct vcap_stream_iter {
43 	u32 offset; /* bit offset from the stream start */
44 	u32 sw_width; /* subword width in bits */
45 	u32 regs_per_sw; /* registers per subword */
46 	u32 reg_idx; /* current register index */
47 	u32 reg_bitpos; /* bit offset in current register */
48 	const struct vcap_typegroup *tg; /* current typegroup */
49 };
50 
51 /* Check that the control has a valid set of callbacks */
52 int vcap_api_check(struct vcap_control *ctrl);
53 /* Serialize access to the vcap instances of a control */
54 void vcap_lock(struct vcap_admin *admin);
55 void vcap_unlock(struct vcap_admin *admin);
56 /* Erase the VCAP cache area used or encoding and decoding */
57 void vcap_erase_cache(struct vcap_rule_internal *ri);
58 
59 /* Iterator functionality */
60 
61 void vcap_iter_init(struct vcap_stream_iter *itr, int sw_width,
62 		    const struct vcap_typegroup *tg, u32 offset);
63 void vcap_iter_next(struct vcap_stream_iter *itr);
64 void vcap_iter_set(struct vcap_stream_iter *itr, int sw_width,
65 		   const struct vcap_typegroup *tg, u32 offset);
66 void vcap_iter_update(struct vcap_stream_iter *itr);
67 
68 /* Keyset and keyfield functionality */
69 
70 /* Return the number of keyfields in the keyset */
71 int vcap_keyfield_count(struct vcap_control *vctrl,
72 			enum vcap_type vt, enum vcap_keyfield_set keyset);
73 /* Return the typegroup table for the matching keyset (using subword size) */
74 const struct vcap_typegroup *
75 vcap_keyfield_typegroup(struct vcap_control *vctrl,
76 			enum vcap_type vt, enum vcap_keyfield_set keyset);
77 /* Return the list of keyfields for the keyset */
78 const struct vcap_field *vcap_keyfields(struct vcap_control *vctrl,
79 					enum vcap_type vt,
80 					enum vcap_keyfield_set keyset);
81 
82 /* Actionset and actionfield functionality */
83 
84 /* Return the actionset information for the actionset */
85 const struct vcap_set *
86 vcap_actionfieldset(struct vcap_control *vctrl,
87 		    enum vcap_type vt, enum vcap_actionfield_set actionset);
88 /* Return the number of actionfields in the actionset */
89 int vcap_actionfield_count(struct vcap_control *vctrl,
90 			   enum vcap_type vt,
91 			   enum vcap_actionfield_set actionset);
92 /* Return the typegroup table for the matching actionset (using subword size) */
93 const struct vcap_typegroup *
94 vcap_actionfield_typegroup(struct vcap_control *vctrl, enum vcap_type vt,
95 			   enum vcap_actionfield_set actionset);
96 /* Return the list of actionfields for the actionset */
97 const struct vcap_field *
98 vcap_actionfields(struct vcap_control *vctrl,
99 		  enum vcap_type vt, enum vcap_actionfield_set actionset);
100 /* Map actionset id to a string with the actionset name */
101 const char *vcap_actionset_name(struct vcap_control *vctrl,
102 				enum vcap_actionfield_set actionset);
103 /* Map key field id to a string with the key name */
104 const char *vcap_actionfield_name(struct vcap_control *vctrl,
105 				  enum vcap_action_field action);
106 
107 /* Read key data from a VCAP address and discover if there are any rule keysets
108  * here
109  */
110 int vcap_addr_keysets(struct vcap_control *vctrl, struct net_device *ndev,
111 		      struct vcap_admin *admin, int addr,
112 		      struct vcap_keyset_list *kslist);
113 
114 /* Verify that the typegroup information, subword count, keyset and type id
115  * are in sync and correct, return the list of matching keysets
116  */
117 int vcap_find_keystream_keysets(struct vcap_control *vctrl, enum vcap_type vt,
118 				u32 *keystream, u32 *mskstream, bool mask,
119 				int sw_max, struct vcap_keyset_list *kslist);
120 
121 /* Get the keysets that matches the rule key type/mask */
122 int vcap_rule_get_keysets(struct vcap_rule_internal *ri,
123 			  struct vcap_keyset_list *matches);
124 /* Decode a rule from the VCAP cache and return a copy */
125 struct vcap_rule *vcap_decode_rule(struct vcap_rule_internal *elem);
126 
127 #endif /* __VCAP_API_PRIVATE__ */
128