xdp_sock.h 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. /* AF_XDP internal functions
  3. * Copyright(c) 2018 Intel Corporation.
  4. */
  5. #ifndef _LINUX_XDP_SOCK_H
  6. #define _LINUX_XDP_SOCK_H
  7. #include <linux/workqueue.h>
  8. #include <linux/if_xdp.h>
  9. #include <linux/mutex.h>
  10. #include <linux/spinlock.h>
  11. #include <linux/mm.h>
  12. #include <net/sock.h>
  13. struct net_device;
  14. struct xsk_queue;
  15. struct xdp_umem_props {
  16. u64 chunk_mask;
  17. u64 size;
  18. };
  19. struct xdp_umem_page {
  20. void *addr;
  21. dma_addr_t dma;
  22. };
  23. struct xdp_umem {
  24. struct xsk_queue *fq;
  25. struct xsk_queue *cq;
  26. struct xdp_umem_page *pages;
  27. struct xdp_umem_props props;
  28. u32 headroom;
  29. u32 chunk_size_nohr;
  30. struct user_struct *user;
  31. struct pid *pid;
  32. unsigned long address;
  33. refcount_t users;
  34. struct work_struct work;
  35. struct page **pgs;
  36. u32 npgs;
  37. struct net_device *dev;
  38. u16 queue_id;
  39. bool zc;
  40. spinlock_t xsk_list_lock;
  41. struct list_head xsk_list;
  42. };
  43. struct xdp_sock {
  44. /* struct sock must be the first member of struct xdp_sock */
  45. struct sock sk;
  46. struct xsk_queue *rx;
  47. struct net_device *dev;
  48. struct xdp_umem *umem;
  49. struct list_head flush_node;
  50. u16 queue_id;
  51. struct xsk_queue *tx ____cacheline_aligned_in_smp;
  52. struct list_head list;
  53. bool zc;
  54. /* Protects multiple processes in the control path */
  55. struct mutex mutex;
  56. u64 rx_dropped;
  57. };
  58. struct xdp_buff;
  59. #ifdef CONFIG_XDP_SOCKETS
  60. int xsk_generic_rcv(struct xdp_sock *xs, struct xdp_buff *xdp);
  61. int xsk_rcv(struct xdp_sock *xs, struct xdp_buff *xdp);
  62. void xsk_flush(struct xdp_sock *xs);
  63. bool xsk_is_setup_for_bpf_map(struct xdp_sock *xs);
  64. /* Used from netdev driver */
  65. u64 *xsk_umem_peek_addr(struct xdp_umem *umem, u64 *addr);
  66. void xsk_umem_discard_addr(struct xdp_umem *umem);
  67. void xsk_umem_complete_tx(struct xdp_umem *umem, u32 nb_entries);
  68. bool xsk_umem_consume_tx(struct xdp_umem *umem, dma_addr_t *dma, u32 *len);
  69. void xsk_umem_consume_tx_done(struct xdp_umem *umem);
  70. #else
  71. static inline int xsk_generic_rcv(struct xdp_sock *xs, struct xdp_buff *xdp)
  72. {
  73. return -ENOTSUPP;
  74. }
  75. static inline int xsk_rcv(struct xdp_sock *xs, struct xdp_buff *xdp)
  76. {
  77. return -ENOTSUPP;
  78. }
  79. static inline void xsk_flush(struct xdp_sock *xs)
  80. {
  81. }
  82. static inline bool xsk_is_setup_for_bpf_map(struct xdp_sock *xs)
  83. {
  84. return false;
  85. }
  86. #endif /* CONFIG_XDP_SOCKETS */
  87. #endif /* _LINUX_XDP_SOCK_H */