ccm.h 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. /* SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) */
  2. /* Copyright (C) 2016-2019 Netronome Systems, Inc. */
  3. #ifndef NFP_CCM_H
  4. #define NFP_CCM_H 1
  5. #include <linux/bitmap.h>
  6. #include <linux/skbuff.h>
  7. #include <linux/wait.h>
  8. struct nfp_app;
  9. struct nfp_net;
  10. /* Firmware ABI */
  11. enum nfp_ccm_type {
  12. NFP_CCM_TYPE_BPF_MAP_ALLOC = 1,
  13. NFP_CCM_TYPE_BPF_MAP_FREE = 2,
  14. NFP_CCM_TYPE_BPF_MAP_LOOKUP = 3,
  15. NFP_CCM_TYPE_BPF_MAP_UPDATE = 4,
  16. NFP_CCM_TYPE_BPF_MAP_DELETE = 5,
  17. NFP_CCM_TYPE_BPF_MAP_GETNEXT = 6,
  18. NFP_CCM_TYPE_BPF_MAP_GETFIRST = 7,
  19. NFP_CCM_TYPE_BPF_BPF_EVENT = 8,
  20. NFP_CCM_TYPE_CRYPTO_RESET = 9,
  21. NFP_CCM_TYPE_CRYPTO_ADD = 10,
  22. NFP_CCM_TYPE_CRYPTO_DEL = 11,
  23. NFP_CCM_TYPE_CRYPTO_UPDATE = 12,
  24. NFP_CCM_TYPE_CRYPTO_RESYNC = 13,
  25. __NFP_CCM_TYPE_MAX,
  26. };
  27. #define NFP_CCM_ABI_VERSION 1
  28. #define NFP_CCM_TYPE_REPLY_BIT 7
  29. #define __NFP_CCM_REPLY(req) (BIT(NFP_CCM_TYPE_REPLY_BIT) | (req))
  30. struct nfp_ccm_hdr {
  31. union {
  32. struct {
  33. u8 type;
  34. u8 ver;
  35. __be16 tag;
  36. };
  37. __be32 raw;
  38. };
  39. };
  40. static inline u8 nfp_ccm_get_type(struct sk_buff *skb)
  41. {
  42. struct nfp_ccm_hdr *hdr;
  43. hdr = (struct nfp_ccm_hdr *)skb->data;
  44. return hdr->type;
  45. }
  46. static inline __be16 __nfp_ccm_get_tag(struct sk_buff *skb)
  47. {
  48. struct nfp_ccm_hdr *hdr;
  49. hdr = (struct nfp_ccm_hdr *)skb->data;
  50. return hdr->tag;
  51. }
  52. static inline unsigned int nfp_ccm_get_tag(struct sk_buff *skb)
  53. {
  54. return be16_to_cpu(__nfp_ccm_get_tag(skb));
  55. }
  56. #define NFP_NET_MBOX_TLV_TYPE GENMASK(31, 16)
  57. #define NFP_NET_MBOX_TLV_LEN GENMASK(15, 0)
  58. enum nfp_ccm_mbox_tlv_type {
  59. NFP_NET_MBOX_TLV_TYPE_UNKNOWN = 0,
  60. NFP_NET_MBOX_TLV_TYPE_END = 1,
  61. NFP_NET_MBOX_TLV_TYPE_MSG = 2,
  62. NFP_NET_MBOX_TLV_TYPE_MSG_NOSUP = 3,
  63. NFP_NET_MBOX_TLV_TYPE_RESV = 4,
  64. };
  65. /* Implementation */
  66. /**
  67. * struct nfp_ccm - common control message handling
  68. * @app: APP handle
  69. *
  70. * @tag_allocator: bitmap of control message tags in use
  71. * @tag_alloc_next: next tag bit to allocate
  72. * @tag_alloc_last: next tag bit to be freed
  73. *
  74. * @replies: received cmsg replies waiting to be consumed
  75. * @wq: work queue for waiting for cmsg replies
  76. */
  77. struct nfp_ccm {
  78. struct nfp_app *app;
  79. DECLARE_BITMAP(tag_allocator, U16_MAX + 1);
  80. u16 tag_alloc_next;
  81. u16 tag_alloc_last;
  82. struct sk_buff_head replies;
  83. wait_queue_head_t wq;
  84. };
  85. int nfp_ccm_init(struct nfp_ccm *ccm, struct nfp_app *app);
  86. void nfp_ccm_clean(struct nfp_ccm *ccm);
  87. void nfp_ccm_rx(struct nfp_ccm *ccm, struct sk_buff *skb);
  88. struct sk_buff *
  89. nfp_ccm_communicate(struct nfp_ccm *ccm, struct sk_buff *skb,
  90. enum nfp_ccm_type type, unsigned int reply_size);
  91. int nfp_ccm_mbox_alloc(struct nfp_net *nn);
  92. void nfp_ccm_mbox_free(struct nfp_net *nn);
  93. int nfp_ccm_mbox_init(struct nfp_net *nn);
  94. void nfp_ccm_mbox_clean(struct nfp_net *nn);
  95. bool nfp_ccm_mbox_fits(struct nfp_net *nn, unsigned int size);
  96. struct sk_buff *
  97. nfp_ccm_mbox_msg_alloc(struct nfp_net *nn, unsigned int req_size,
  98. unsigned int reply_size, gfp_t flags);
  99. int __nfp_ccm_mbox_communicate(struct nfp_net *nn, struct sk_buff *skb,
  100. enum nfp_ccm_type type,
  101. unsigned int reply_size,
  102. unsigned int max_reply_size, bool critical);
  103. int nfp_ccm_mbox_communicate(struct nfp_net *nn, struct sk_buff *skb,
  104. enum nfp_ccm_type type,
  105. unsigned int reply_size,
  106. unsigned int max_reply_size);
  107. int nfp_ccm_mbox_post(struct nfp_net *nn, struct sk_buff *skb,
  108. enum nfp_ccm_type type, unsigned int max_reply_size);
  109. #endif