1 /* SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) */
2 /* Copyright (C) 2016-2019 Netronome Systems, Inc. */
7 #include <linux/bitmap.h>
8 #include <linux/skbuff.h>
9 #include <linux/wait.h>
17 NFP_CCM_TYPE_BPF_MAP_ALLOC
= 1,
18 NFP_CCM_TYPE_BPF_MAP_FREE
= 2,
19 NFP_CCM_TYPE_BPF_MAP_LOOKUP
= 3,
20 NFP_CCM_TYPE_BPF_MAP_UPDATE
= 4,
21 NFP_CCM_TYPE_BPF_MAP_DELETE
= 5,
22 NFP_CCM_TYPE_BPF_MAP_GETNEXT
= 6,
23 NFP_CCM_TYPE_BPF_MAP_GETFIRST
= 7,
24 NFP_CCM_TYPE_BPF_BPF_EVENT
= 8,
25 NFP_CCM_TYPE_CRYPTO_RESET
= 9,
26 NFP_CCM_TYPE_CRYPTO_ADD
= 10,
27 NFP_CCM_TYPE_CRYPTO_DEL
= 11,
28 NFP_CCM_TYPE_CRYPTO_UPDATE
= 12,
29 NFP_CCM_TYPE_CRYPTO_RESYNC
= 13,
33 #define NFP_CCM_ABI_VERSION 1
35 #define NFP_CCM_TYPE_REPLY_BIT 7
36 #define __NFP_CCM_REPLY(req) (BIT(NFP_CCM_TYPE_REPLY_BIT) | (req))
49 static inline u8
nfp_ccm_get_type(struct sk_buff
*skb
)
51 struct nfp_ccm_hdr
*hdr
;
53 hdr
= (struct nfp_ccm_hdr
*)skb
->data
;
58 static inline __be16
__nfp_ccm_get_tag(struct sk_buff
*skb
)
60 struct nfp_ccm_hdr
*hdr
;
62 hdr
= (struct nfp_ccm_hdr
*)skb
->data
;
67 static inline unsigned int nfp_ccm_get_tag(struct sk_buff
*skb
)
69 return be16_to_cpu(__nfp_ccm_get_tag(skb
));
72 #define NFP_NET_MBOX_TLV_TYPE GENMASK(31, 16)
73 #define NFP_NET_MBOX_TLV_LEN GENMASK(15, 0)
75 enum nfp_ccm_mbox_tlv_type
{
76 NFP_NET_MBOX_TLV_TYPE_UNKNOWN
= 0,
77 NFP_NET_MBOX_TLV_TYPE_END
= 1,
78 NFP_NET_MBOX_TLV_TYPE_MSG
= 2,
79 NFP_NET_MBOX_TLV_TYPE_MSG_NOSUP
= 3,
80 NFP_NET_MBOX_TLV_TYPE_RESV
= 4,
86 * struct nfp_ccm - common control message handling
89 * @tag_allocator: bitmap of control message tags in use
90 * @tag_alloc_next: next tag bit to allocate
91 * @tag_alloc_last: next tag bit to be freed
93 * @replies: received cmsg replies waiting to be consumed
94 * @wq: work queue for waiting for cmsg replies
99 DECLARE_BITMAP(tag_allocator
, U16_MAX
+ 1);
103 struct sk_buff_head replies
;
104 wait_queue_head_t wq
;
107 int nfp_ccm_init(struct nfp_ccm
*ccm
, struct nfp_app
*app
);
108 void nfp_ccm_clean(struct nfp_ccm
*ccm
);
109 void nfp_ccm_rx(struct nfp_ccm
*ccm
, struct sk_buff
*skb
);
111 nfp_ccm_communicate(struct nfp_ccm
*ccm
, struct sk_buff
*skb
,
112 enum nfp_ccm_type type
, unsigned int reply_size
);
114 int nfp_ccm_mbox_alloc(struct nfp_net
*nn
);
115 void nfp_ccm_mbox_free(struct nfp_net
*nn
);
116 int nfp_ccm_mbox_init(struct nfp_net
*nn
);
117 void nfp_ccm_mbox_clean(struct nfp_net
*nn
);
118 bool nfp_ccm_mbox_fits(struct nfp_net
*nn
, unsigned int size
);
120 nfp_ccm_mbox_msg_alloc(struct nfp_net
*nn
, unsigned int req_size
,
121 unsigned int reply_size
, gfp_t flags
);
122 int __nfp_ccm_mbox_communicate(struct nfp_net
*nn
, struct sk_buff
*skb
,
123 enum nfp_ccm_type type
,
124 unsigned int reply_size
,
125 unsigned int max_reply_size
, bool critical
);
126 int nfp_ccm_mbox_communicate(struct nfp_net
*nn
, struct sk_buff
*skb
,
127 enum nfp_ccm_type type
,
128 unsigned int reply_size
,
129 unsigned int max_reply_size
);
130 int nfp_ccm_mbox_post(struct nfp_net
*nn
, struct sk_buff
*skb
,
131 enum nfp_ccm_type type
, unsigned int max_reply_size
);