xdp_umem.h 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. /* SPDX-License-Identifier: GPL-2.0
  2. * XDP user-space packet buffer
  3. * Copyright(c) 2018 Intel Corporation.
  4. *
  5. * This program is free software; you can redistribute it and/or modify it
  6. * under the terms and conditions of the GNU General Public License,
  7. * version 2, as published by the Free Software Foundation.
  8. *
  9. * This program is distributed in the hope it will be useful, but WITHOUT
  10. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  12. * more details.
  13. */
  14. #ifndef XDP_UMEM_H_
  15. #define XDP_UMEM_H_
  16. #include <linux/mm.h>
  17. #include <linux/if_xdp.h>
  18. #include <linux/workqueue.h>
  19. #include "xsk_queue.h"
  20. #include "xdp_umem_props.h"
  21. struct xdp_umem {
  22. struct xsk_queue *fq;
  23. struct page **pgs;
  24. struct xdp_umem_props props;
  25. u32 npgs;
  26. u32 frame_headroom;
  27. u32 nfpp_mask;
  28. u32 nfpplog2;
  29. u32 frame_size_log2;
  30. struct user_struct *user;
  31. struct pid *pid;
  32. unsigned long address;
  33. size_t size;
  34. atomic_t users;
  35. struct work_struct work;
  36. };
  37. static inline char *xdp_umem_get_data(struct xdp_umem *umem, u32 idx)
  38. {
  39. u64 pg, off;
  40. char *data;
  41. pg = idx >> umem->nfpplog2;
  42. off = (idx & umem->nfpp_mask) << umem->frame_size_log2;
  43. data = page_address(umem->pgs[pg]);
  44. return data + off;
  45. }
  46. static inline char *xdp_umem_get_data_with_headroom(struct xdp_umem *umem,
  47. u32 idx)
  48. {
  49. return xdp_umem_get_data(umem, idx) + umem->frame_headroom;
  50. }
  51. bool xdp_umem_validate_queues(struct xdp_umem *umem);
  52. int xdp_umem_reg(struct xdp_umem *umem, struct xdp_umem_reg *mr);
  53. void xdp_get_umem(struct xdp_umem *umem);
  54. void xdp_put_umem(struct xdp_umem *umem);
  55. int xdp_umem_create(struct xdp_umem **umem);
  56. #endif /* XDP_UMEM_H_ */