133 lines · c
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_H5#define NFP_CCM_H 16 7#include <linux/bitmap.h>8#include <linux/skbuff.h>9#include <linux/wait.h>10 11struct nfp_app;12struct nfp_net;13 14/* Firmware ABI */15 16enum nfp_ccm_type {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,30 __NFP_CCM_TYPE_MAX,31};32 33#define NFP_CCM_ABI_VERSION 134 35#define NFP_CCM_TYPE_REPLY_BIT 736#define __NFP_CCM_REPLY(req) (BIT(NFP_CCM_TYPE_REPLY_BIT) | (req))37 38struct nfp_ccm_hdr {39 union {40 struct {41 u8 type;42 u8 ver;43 __be16 tag;44 };45 __be32 raw;46 };47};48 49static inline u8 nfp_ccm_get_type(struct sk_buff *skb)50{51 struct nfp_ccm_hdr *hdr;52 53 hdr = (struct nfp_ccm_hdr *)skb->data;54 55 return hdr->type;56}57 58static inline __be16 __nfp_ccm_get_tag(struct sk_buff *skb)59{60 struct nfp_ccm_hdr *hdr;61 62 hdr = (struct nfp_ccm_hdr *)skb->data;63 64 return hdr->tag;65}66 67static inline unsigned int nfp_ccm_get_tag(struct sk_buff *skb)68{69 return be16_to_cpu(__nfp_ccm_get_tag(skb));70}71 72#define NFP_NET_MBOX_TLV_TYPE GENMASK(31, 16)73#define NFP_NET_MBOX_TLV_LEN GENMASK(15, 0)74 75enum 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,81};82 83/* Implementation */84 85/**86 * struct nfp_ccm - common control message handling87 * @app: APP handle88 *89 * @tag_allocator: bitmap of control message tags in use90 * @tag_alloc_next: next tag bit to allocate91 * @tag_alloc_last: next tag bit to be freed92 *93 * @replies: received cmsg replies waiting to be consumed94 * @wq: work queue for waiting for cmsg replies95 */96struct nfp_ccm {97 struct nfp_app *app;98 99 DECLARE_BITMAP(tag_allocator, U16_MAX + 1);100 u16 tag_alloc_next;101 u16 tag_alloc_last;102 103 struct sk_buff_head replies;104 wait_queue_head_t wq;105};106 107int nfp_ccm_init(struct nfp_ccm *ccm, struct nfp_app *app);108void nfp_ccm_clean(struct nfp_ccm *ccm);109void nfp_ccm_rx(struct nfp_ccm *ccm, struct sk_buff *skb);110struct sk_buff *111nfp_ccm_communicate(struct nfp_ccm *ccm, struct sk_buff *skb,112 enum nfp_ccm_type type, unsigned int reply_size);113 114int nfp_ccm_mbox_alloc(struct nfp_net *nn);115void nfp_ccm_mbox_free(struct nfp_net *nn);116int nfp_ccm_mbox_init(struct nfp_net *nn);117void nfp_ccm_mbox_clean(struct nfp_net *nn);118bool nfp_ccm_mbox_fits(struct nfp_net *nn, unsigned int size);119struct sk_buff *120nfp_ccm_mbox_msg_alloc(struct nfp_net *nn, unsigned int req_size,121 unsigned int reply_size, gfp_t flags);122int __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);126int 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);130int nfp_ccm_mbox_post(struct nfp_net *nn, struct sk_buff *skb,131 enum nfp_ccm_type type, unsigned int max_reply_size);132#endif133