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_CLIENT__ 7 #define __VCAP_API_CLIENT__ 8 9 #include <linux/types.h> 10 #include <linux/list.h> 11 #include <linux/netdevice.h> 12 #include <net/flow_offload.h> 13 14 #include "vcap_api.h" 15 16 /* Client supplied VCAP rule key control part */ 17 struct vcap_client_keyfield_ctrl { 18 struct list_head list; /* For insertion into a rule */ 19 enum vcap_key_field key; 20 enum vcap_field_type type; 21 }; 22 23 struct vcap_u1_key { 24 u8 value; 25 u8 mask; 26 }; 27 28 struct vcap_u32_key { 29 u32 value; 30 u32 mask; 31 }; 32 33 struct vcap_u48_key { 34 u8 value[6]; 35 u8 mask[6]; 36 }; 37 38 struct vcap_u56_key { 39 u8 value[7]; 40 u8 mask[7]; 41 }; 42 43 struct vcap_u64_key { 44 u8 value[8]; 45 u8 mask[8]; 46 }; 47 48 struct vcap_u72_key { 49 u8 value[9]; 50 u8 mask[9]; 51 }; 52 53 struct vcap_u112_key { 54 u8 value[14]; 55 u8 mask[14]; 56 }; 57 58 struct vcap_u128_key { 59 u8 value[16]; 60 u8 mask[16]; 61 }; 62 63 /* Client supplied VCAP rule field data */ 64 struct vcap_client_keyfield_data { 65 union { 66 struct vcap_u1_key u1; 67 struct vcap_u32_key u32; 68 struct vcap_u48_key u48; 69 struct vcap_u56_key u56; 70 struct vcap_u64_key u64; 71 struct vcap_u72_key u72; 72 struct vcap_u112_key u112; 73 struct vcap_u128_key u128; 74 }; 75 }; 76 77 /* Client supplied VCAP rule key (value, mask) */ 78 struct vcap_client_keyfield { 79 struct vcap_client_keyfield_ctrl ctrl; 80 struct vcap_client_keyfield_data data; 81 }; 82 83 /* Client supplied VCAP rule action control part */ 84 struct vcap_client_actionfield_ctrl { 85 struct list_head list; /* For insertion into a rule */ 86 enum vcap_action_field action; 87 enum vcap_field_type type; 88 }; 89 90 struct vcap_u1_action { 91 u8 value; 92 }; 93 94 struct vcap_u32_action { 95 u32 value; 96 }; 97 98 struct vcap_u48_action { 99 u8 value[6]; 100 }; 101 102 struct vcap_u56_action { 103 u8 value[7]; 104 }; 105 106 struct vcap_u64_action { 107 u8 value[8]; 108 }; 109 110 struct vcap_u72_action { 111 u8 value[9]; 112 }; 113 114 struct vcap_u112_action { 115 u8 value[14]; 116 }; 117 118 struct vcap_u128_action { 119 u8 value[16]; 120 }; 121 122 struct vcap_client_actionfield_data { 123 union { 124 struct vcap_u1_action u1; 125 struct vcap_u32_action u32; 126 struct vcap_u48_action u48; 127 struct vcap_u56_action u56; 128 struct vcap_u64_action u64; 129 struct vcap_u72_action u72; 130 struct vcap_u112_action u112; 131 struct vcap_u128_action u128; 132 }; 133 }; 134 135 struct vcap_client_actionfield { 136 struct vcap_client_actionfield_ctrl ctrl; 137 struct vcap_client_actionfield_data data; 138 }; 139 140 enum vcap_bit { 141 VCAP_BIT_ANY, 142 VCAP_BIT_0, 143 VCAP_BIT_1 144 }; 145 146 /* Enable/Disable the VCAP instance lookups. Chain id 0 means disable */ 147 int vcap_enable_lookups(struct vcap_control *vctrl, struct net_device *ndev, 148 int chain_id, unsigned long cookie, bool enable); 149 150 /* VCAP rule operations */ 151 /* Allocate a rule and fill in the basic information */ 152 struct vcap_rule *vcap_alloc_rule(struct vcap_control *vctrl, 153 struct net_device *ndev, 154 int vcap_chain_id, 155 enum vcap_user user, 156 u16 priority, 157 u32 id); 158 /* Free mem of a rule owned by client */ 159 void vcap_free_rule(struct vcap_rule *rule); 160 /* Validate a rule before adding it to the VCAP */ 161 int vcap_val_rule(struct vcap_rule *rule, u16 l3_proto); 162 /* Add rule to a VCAP instance */ 163 int vcap_add_rule(struct vcap_rule *rule); 164 /* Delete rule in a VCAP instance */ 165 int vcap_del_rule(struct vcap_control *vctrl, struct net_device *ndev, u32 id); 166 167 /* Update the keyset for the rule */ 168 int vcap_set_rule_set_keyset(struct vcap_rule *rule, 169 enum vcap_keyfield_set keyset); 170 /* Update the actionset for the rule */ 171 int vcap_set_rule_set_actionset(struct vcap_rule *rule, 172 enum vcap_actionfield_set actionset); 173 174 /* VCAP rule field operations */ 175 int vcap_rule_add_key_bit(struct vcap_rule *rule, enum vcap_key_field key, 176 enum vcap_bit val); 177 int vcap_rule_add_key_u32(struct vcap_rule *rule, enum vcap_key_field key, 178 u32 value, u32 mask); 179 int vcap_rule_add_key_u48(struct vcap_rule *rule, enum vcap_key_field key, 180 struct vcap_u48_key *fieldval); 181 int vcap_rule_add_key_u72(struct vcap_rule *rule, enum vcap_key_field key, 182 struct vcap_u72_key *fieldval); 183 int vcap_rule_add_key_u128(struct vcap_rule *rule, enum vcap_key_field key, 184 struct vcap_u128_key *fieldval); 185 int vcap_rule_add_action_bit(struct vcap_rule *rule, 186 enum vcap_action_field action, enum vcap_bit val); 187 int vcap_rule_add_action_u32(struct vcap_rule *rule, 188 enum vcap_action_field action, u32 value); 189 190 /* VCAP lookup operations */ 191 /* Convert a chain id to a VCAP lookup index */ 192 int vcap_chain_id_to_lookup(struct vcap_admin *admin, int cur_cid); 193 /* Lookup a vcap instance using chain id */ 194 struct vcap_admin *vcap_find_admin(struct vcap_control *vctrl, int cid); 195 /* Find information on a key field in a rule */ 196 const struct vcap_field *vcap_lookup_keyfield(struct vcap_rule *rule, 197 enum vcap_key_field key); 198 /* Find a rule id with a provided cookie */ 199 int vcap_lookup_rule_by_cookie(struct vcap_control *vctrl, u64 cookie); 200 /* Is the next chain id in the following lookup, possible in another VCAP */ 201 bool vcap_is_next_lookup(struct vcap_control *vctrl, int cur_cid, int next_cid); 202 203 /* Copy to host byte order */ 204 void vcap_netbytes_copy(u8 *dst, u8 *src, int count); 205 206 /* Convert validation error code into tc extact error message */ 207 void vcap_set_tc_exterr(struct flow_cls_offload *fco, struct vcap_rule *vrule); 208 209 /* Cleanup a VCAP instance */ 210 int vcap_del_rules(struct vcap_control *vctrl, struct vcap_admin *admin); 211 212 /* Add a keyset to a keyset list */ 213 bool vcap_keyset_list_add(struct vcap_keyset_list *keysetlist, 214 enum vcap_keyfield_set keyset); 215 216 /* map keyset id to a string with the keyset name */ 217 const char *vcap_keyset_name(struct vcap_control *vctrl, 218 enum vcap_keyfield_set keyset); 219 /* map key field id to a string with the key name */ 220 const char *vcap_keyfield_name(struct vcap_control *vctrl, 221 enum vcap_key_field key); 222 223 #endif /* __VCAP_API_CLIENT__ */ 224