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 /* Erase the VCAP cache area used or encoding and decoding */ 54 void vcap_erase_cache(struct vcap_rule_internal *ri); 55 56 /* Iterator functionality */ 57 58 void vcap_iter_init(struct vcap_stream_iter *itr, int sw_width, 59 const struct vcap_typegroup *tg, u32 offset); 60 void vcap_iter_next(struct vcap_stream_iter *itr); 61 void vcap_iter_set(struct vcap_stream_iter *itr, int sw_width, 62 const struct vcap_typegroup *tg, u32 offset); 63 void vcap_iter_update(struct vcap_stream_iter *itr); 64 65 /* Keyset and keyfield functionality */ 66 67 /* Return the number of keyfields in the keyset */ 68 int vcap_keyfield_count(struct vcap_control *vctrl, 69 enum vcap_type vt, enum vcap_keyfield_set keyset); 70 /* Return the typegroup table for the matching keyset (using subword size) */ 71 const struct vcap_typegroup * 72 vcap_keyfield_typegroup(struct vcap_control *vctrl, 73 enum vcap_type vt, enum vcap_keyfield_set keyset); 74 /* Return the list of keyfields for the keyset */ 75 const struct vcap_field *vcap_keyfields(struct vcap_control *vctrl, 76 enum vcap_type vt, 77 enum vcap_keyfield_set keyset); 78 79 /* Actionset and actionfield functionality */ 80 81 /* Return the actionset information for the actionset */ 82 const struct vcap_set * 83 vcap_actionfieldset(struct vcap_control *vctrl, 84 enum vcap_type vt, enum vcap_actionfield_set actionset); 85 /* Return the number of actionfields in the actionset */ 86 int vcap_actionfield_count(struct vcap_control *vctrl, 87 enum vcap_type vt, 88 enum vcap_actionfield_set actionset); 89 /* Return the typegroup table for the matching actionset (using subword size) */ 90 const struct vcap_typegroup * 91 vcap_actionfield_typegroup(struct vcap_control *vctrl, enum vcap_type vt, 92 enum vcap_actionfield_set actionset); 93 /* Return the list of actionfields for the actionset */ 94 const struct vcap_field * 95 vcap_actionfields(struct vcap_control *vctrl, 96 enum vcap_type vt, enum vcap_actionfield_set actionset); 97 /* Map actionset id to a string with the actionset name */ 98 const char *vcap_actionset_name(struct vcap_control *vctrl, 99 enum vcap_actionfield_set actionset); 100 /* Map key field id to a string with the key name */ 101 const char *vcap_actionfield_name(struct vcap_control *vctrl, 102 enum vcap_action_field action); 103 104 /* Read key data from a VCAP address and discover if there are any rule keysets 105 * here 106 */ 107 int vcap_addr_keysets(struct vcap_control *vctrl, struct net_device *ndev, 108 struct vcap_admin *admin, int addr, 109 struct vcap_keyset_list *kslist); 110 111 /* Verify that the typegroup information, subword count, keyset and type id 112 * are in sync and correct, return the list of matching keysets 113 */ 114 int vcap_find_keystream_keysets(struct vcap_control *vctrl, enum vcap_type vt, 115 u32 *keystream, u32 *mskstream, bool mask, 116 int sw_max, struct vcap_keyset_list *kslist); 117 118 /* Get the keysets that matches the rule key type/mask */ 119 int vcap_rule_get_keysets(struct vcap_rule_internal *ri, 120 struct vcap_keyset_list *matches); 121 /* Decode a rule from the VCAP cache and return a copy */ 122 struct vcap_rule *vcap_decode_rule(struct vcap_rule_internal *elem); 123 124 #endif /* __VCAP_API_PRIVATE__ */ 125