1 /* SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) */ 2 /* Copyright (C) 2016-2019 Netronome Systems, Inc. */ 3 4 #ifndef NFP_CCM_H 5 #define NFP_CCM_H 1 6 7 #include <linux/bitmap.h> 8 #include <linux/skbuff.h> 9 #include <linux/wait.h> 10 11 struct nfp_app; 12 13 /* Firmware ABI */ 14 15 enum nfp_ccm_type { 16 NFP_CCM_TYPE_BPF_MAP_ALLOC = 1, 17 NFP_CCM_TYPE_BPF_MAP_FREE = 2, 18 NFP_CCM_TYPE_BPF_MAP_LOOKUP = 3, 19 NFP_CCM_TYPE_BPF_MAP_UPDATE = 4, 20 NFP_CCM_TYPE_BPF_MAP_DELETE = 5, 21 NFP_CCM_TYPE_BPF_MAP_GETNEXT = 6, 22 NFP_CCM_TYPE_BPF_MAP_GETFIRST = 7, 23 NFP_CCM_TYPE_BPF_BPF_EVENT = 8, 24 __NFP_CCM_TYPE_MAX, 25 }; 26 27 #define NFP_CCM_ABI_VERSION 1 28 29 struct nfp_ccm_hdr { 30 u8 type; 31 u8 ver; 32 __be16 tag; 33 }; 34 35 static inline u8 nfp_ccm_get_type(struct sk_buff *skb) 36 { 37 struct nfp_ccm_hdr *hdr; 38 39 hdr = (struct nfp_ccm_hdr *)skb->data; 40 41 return hdr->type; 42 } 43 44 static inline unsigned int nfp_ccm_get_tag(struct sk_buff *skb) 45 { 46 struct nfp_ccm_hdr *hdr; 47 48 hdr = (struct nfp_ccm_hdr *)skb->data; 49 50 return be16_to_cpu(hdr->tag); 51 } 52 53 /* Implementation */ 54 55 /** 56 * struct nfp_ccm - common control message handling 57 * @app: APP handle 58 * 59 * @tag_allocator: bitmap of control message tags in use 60 * @tag_alloc_next: next tag bit to allocate 61 * @tag_alloc_last: next tag bit to be freed 62 * 63 * @replies: received cmsg replies waiting to be consumed 64 * @wq: work queue for waiting for cmsg replies 65 */ 66 struct nfp_ccm { 67 struct nfp_app *app; 68 69 DECLARE_BITMAP(tag_allocator, U16_MAX + 1); 70 u16 tag_alloc_next; 71 u16 tag_alloc_last; 72 73 struct sk_buff_head replies; 74 struct wait_queue_head wq; 75 }; 76 77 int nfp_ccm_init(struct nfp_ccm *ccm, struct nfp_app *app); 78 void nfp_ccm_clean(struct nfp_ccm *ccm); 79 void nfp_ccm_rx(struct nfp_ccm *ccm, struct sk_buff *skb); 80 struct sk_buff * 81 nfp_ccm_communicate(struct nfp_ccm *ccm, struct sk_buff *skb, 82 enum nfp_ccm_type type, unsigned int reply_size); 83 #endif 84