e2fe4b867958802f05edfc71304cbeed9363ae17
[linux-2.6-block.git] / drivers / net / ethernet / netronome / nfp / ccm.h
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  * @tag_allocator:      bitmap of control message tags in use
58  * @tag_alloc_next:     next tag bit to allocate
59  * @tag_alloc_last:     next tag bit to be freed
60  *
61  * @replies:            received cmsg replies waiting to be consumed
62  * @wq:                 work queue for waiting for cmsg replies
63  */
64 struct nfp_ccm {
65         struct nfp_app *app;
66
67         DECLARE_BITMAP(tag_allocator, U16_MAX + 1);
68         u16 tag_alloc_next;
69         u16 tag_alloc_last;
70
71         struct sk_buff_head replies;
72         struct wait_queue_head wq;
73 };
74
75 int nfp_ccm_init(struct nfp_ccm *ccm, struct nfp_app *app);
76 void nfp_ccm_clean(struct nfp_ccm *ccm);
77 void nfp_ccm_rx(struct nfp_ccm *ccm, struct sk_buff *skb);
78 struct sk_buff *
79 nfp_ccm_communicate(struct nfp_ccm *ccm, struct sk_buff *skb,
80                     enum nfp_ccm_type type, unsigned int reply_size);
81 #endif