zcrx.h 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. // SPDX-License-Identifier: GPL-2.0
  2. #ifndef IOU_ZC_RX_H
  3. #define IOU_ZC_RX_H
  4. #include <linux/io_uring_types.h>
  5. #include <linux/dma-buf.h>
  6. #include <linux/socket.h>
  7. #include <net/page_pool/types.h>
  8. #include <net/net_trackers.h>
  9. struct io_zcrx_mem {
  10. unsigned long size;
  11. bool is_dmabuf;
  12. struct page **pages;
  13. unsigned long nr_folios;
  14. struct sg_table page_sg_table;
  15. unsigned long account_pages;
  16. struct sg_table *sgt;
  17. struct dma_buf_attachment *attach;
  18. struct dma_buf *dmabuf;
  19. };
  20. struct io_zcrx_area {
  21. struct net_iov_area nia;
  22. struct io_zcrx_ifq *ifq;
  23. atomic_t *user_refs;
  24. bool is_mapped;
  25. u16 area_id;
  26. /* freelist */
  27. spinlock_t freelist_lock ____cacheline_aligned_in_smp;
  28. u32 free_count;
  29. u32 *freelist;
  30. struct io_zcrx_mem mem;
  31. };
  32. struct io_zcrx_ifq {
  33. struct io_zcrx_area *area;
  34. unsigned niov_shift;
  35. struct user_struct *user;
  36. struct mm_struct *mm_account;
  37. spinlock_t rq_lock ____cacheline_aligned_in_smp;
  38. struct io_uring *rq_ring;
  39. struct io_uring_zcrx_rqe *rqes;
  40. u32 cached_rq_head;
  41. u32 rq_entries;
  42. u32 if_rxq;
  43. struct device *dev;
  44. struct net_device *netdev;
  45. netdevice_tracker netdev_tracker;
  46. refcount_t refs;
  47. /* counts userspace facing users like io_uring */
  48. refcount_t user_refs;
  49. /*
  50. * Page pool and net configuration lock, can be taken deeper in the
  51. * net stack.
  52. */
  53. struct mutex pp_lock;
  54. struct io_mapped_region region;
  55. };
  56. #if defined(CONFIG_IO_URING_ZCRX)
  57. int io_zcrx_ctrl(struct io_ring_ctx *ctx, void __user *arg, unsigned nr_arg);
  58. int io_register_zcrx_ifq(struct io_ring_ctx *ctx,
  59. struct io_uring_zcrx_ifq_reg __user *arg);
  60. void io_unregister_zcrx_ifqs(struct io_ring_ctx *ctx);
  61. int io_zcrx_recv(struct io_kiocb *req, struct io_zcrx_ifq *ifq,
  62. struct socket *sock, unsigned int flags,
  63. unsigned issue_flags, unsigned int *len);
  64. struct io_mapped_region *io_zcrx_get_region(struct io_ring_ctx *ctx,
  65. unsigned int id);
  66. #else
  67. static inline int io_register_zcrx_ifq(struct io_ring_ctx *ctx,
  68. struct io_uring_zcrx_ifq_reg __user *arg)
  69. {
  70. return -EOPNOTSUPP;
  71. }
  72. static inline void io_unregister_zcrx_ifqs(struct io_ring_ctx *ctx)
  73. {
  74. }
  75. static inline int io_zcrx_recv(struct io_kiocb *req, struct io_zcrx_ifq *ifq,
  76. struct socket *sock, unsigned int flags,
  77. unsigned issue_flags, unsigned int *len)
  78. {
  79. return -EOPNOTSUPP;
  80. }
  81. static inline struct io_mapped_region *io_zcrx_get_region(struct io_ring_ctx *ctx,
  82. unsigned int id)
  83. {
  84. return NULL;
  85. }
  86. static inline int io_zcrx_ctrl(struct io_ring_ctx *ctx,
  87. void __user *arg, unsigned nr_arg)
  88. {
  89. return -EOPNOTSUPP;
  90. }
  91. #endif
  92. int io_recvzc(struct io_kiocb *req, unsigned int issue_flags);
  93. int io_recvzc_prep(struct io_kiocb *req, const struct io_uring_sqe *sqe);
  94. #endif