Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) */
0002 /* Copyright (C) 2016-2019 Netronome Systems, Inc. */
0003 
0004 #ifndef NFP_CCM_H
0005 #define NFP_CCM_H 1
0006 
0007 #include <linux/bitmap.h>
0008 #include <linux/skbuff.h>
0009 #include <linux/wait.h>
0010 
0011 struct nfp_app;
0012 struct nfp_net;
0013 
0014 /* Firmware ABI */
0015 
0016 enum nfp_ccm_type {
0017     NFP_CCM_TYPE_BPF_MAP_ALLOC  = 1,
0018     NFP_CCM_TYPE_BPF_MAP_FREE   = 2,
0019     NFP_CCM_TYPE_BPF_MAP_LOOKUP = 3,
0020     NFP_CCM_TYPE_BPF_MAP_UPDATE = 4,
0021     NFP_CCM_TYPE_BPF_MAP_DELETE = 5,
0022     NFP_CCM_TYPE_BPF_MAP_GETNEXT    = 6,
0023     NFP_CCM_TYPE_BPF_MAP_GETFIRST   = 7,
0024     NFP_CCM_TYPE_BPF_BPF_EVENT  = 8,
0025     NFP_CCM_TYPE_CRYPTO_RESET   = 9,
0026     NFP_CCM_TYPE_CRYPTO_ADD     = 10,
0027     NFP_CCM_TYPE_CRYPTO_DEL     = 11,
0028     NFP_CCM_TYPE_CRYPTO_UPDATE  = 12,
0029     NFP_CCM_TYPE_CRYPTO_RESYNC  = 13,
0030     __NFP_CCM_TYPE_MAX,
0031 };
0032 
0033 #define NFP_CCM_ABI_VERSION     1
0034 
0035 #define NFP_CCM_TYPE_REPLY_BIT      7
0036 #define __NFP_CCM_REPLY(req)        (BIT(NFP_CCM_TYPE_REPLY_BIT) | (req))
0037 
0038 struct nfp_ccm_hdr {
0039     union {
0040         struct {
0041             u8 type;
0042             u8 ver;
0043             __be16 tag;
0044         };
0045         __be32 raw;
0046     };
0047 };
0048 
0049 static inline u8 nfp_ccm_get_type(struct sk_buff *skb)
0050 {
0051     struct nfp_ccm_hdr *hdr;
0052 
0053     hdr = (struct nfp_ccm_hdr *)skb->data;
0054 
0055     return hdr->type;
0056 }
0057 
0058 static inline __be16 __nfp_ccm_get_tag(struct sk_buff *skb)
0059 {
0060     struct nfp_ccm_hdr *hdr;
0061 
0062     hdr = (struct nfp_ccm_hdr *)skb->data;
0063 
0064     return hdr->tag;
0065 }
0066 
0067 static inline unsigned int nfp_ccm_get_tag(struct sk_buff *skb)
0068 {
0069     return be16_to_cpu(__nfp_ccm_get_tag(skb));
0070 }
0071 
0072 #define NFP_NET_MBOX_TLV_TYPE       GENMASK(31, 16)
0073 #define NFP_NET_MBOX_TLV_LEN        GENMASK(15, 0)
0074 
0075 enum nfp_ccm_mbox_tlv_type {
0076     NFP_NET_MBOX_TLV_TYPE_UNKNOWN   = 0,
0077     NFP_NET_MBOX_TLV_TYPE_END   = 1,
0078     NFP_NET_MBOX_TLV_TYPE_MSG   = 2,
0079     NFP_NET_MBOX_TLV_TYPE_MSG_NOSUP = 3,
0080     NFP_NET_MBOX_TLV_TYPE_RESV  = 4,
0081 };
0082 
0083 /* Implementation */
0084 
0085 /**
0086  * struct nfp_ccm - common control message handling
0087  * @app:        APP handle
0088  *
0089  * @tag_allocator:  bitmap of control message tags in use
0090  * @tag_alloc_next: next tag bit to allocate
0091  * @tag_alloc_last: next tag bit to be freed
0092  *
0093  * @replies:        received cmsg replies waiting to be consumed
0094  * @wq:         work queue for waiting for cmsg replies
0095  */
0096 struct nfp_ccm {
0097     struct nfp_app *app;
0098 
0099     DECLARE_BITMAP(tag_allocator, U16_MAX + 1);
0100     u16 tag_alloc_next;
0101     u16 tag_alloc_last;
0102 
0103     struct sk_buff_head replies;
0104     wait_queue_head_t wq;
0105 };
0106 
0107 int nfp_ccm_init(struct nfp_ccm *ccm, struct nfp_app *app);
0108 void nfp_ccm_clean(struct nfp_ccm *ccm);
0109 void nfp_ccm_rx(struct nfp_ccm *ccm, struct sk_buff *skb);
0110 struct sk_buff *
0111 nfp_ccm_communicate(struct nfp_ccm *ccm, struct sk_buff *skb,
0112             enum nfp_ccm_type type, unsigned int reply_size);
0113 
0114 int nfp_ccm_mbox_alloc(struct nfp_net *nn);
0115 void nfp_ccm_mbox_free(struct nfp_net *nn);
0116 int nfp_ccm_mbox_init(struct nfp_net *nn);
0117 void nfp_ccm_mbox_clean(struct nfp_net *nn);
0118 bool nfp_ccm_mbox_fits(struct nfp_net *nn, unsigned int size);
0119 struct sk_buff *
0120 nfp_ccm_mbox_msg_alloc(struct nfp_net *nn, unsigned int req_size,
0121                unsigned int reply_size, gfp_t flags);
0122 int __nfp_ccm_mbox_communicate(struct nfp_net *nn, struct sk_buff *skb,
0123                    enum nfp_ccm_type type,
0124                    unsigned int reply_size,
0125                    unsigned int max_reply_size, bool critical);
0126 int nfp_ccm_mbox_communicate(struct nfp_net *nn, struct sk_buff *skb,
0127                  enum nfp_ccm_type type,
0128                  unsigned int reply_size,
0129                  unsigned int max_reply_size);
0130 int nfp_ccm_mbox_post(struct nfp_net *nn, struct sk_buff *skb,
0131               enum nfp_ccm_type type, unsigned int max_reply_size);
0132 #endif