commonring.h 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. /* Copyright (c) 2014 Broadcom Corporation
  2. *
  3. * Permission to use, copy, modify, and/or distribute this software for any
  4. * purpose with or without fee is hereby granted, provided that the above
  5. * copyright notice and this permission notice appear in all copies.
  6. *
  7. * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
  8. * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
  9. * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
  10. * SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  11. * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
  12. * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
  13. * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  14. */
  15. #ifndef BRCMFMAC_COMMONRING_H
  16. #define BRCMFMAC_COMMONRING_H
  17. struct brcmf_commonring {
  18. u16 r_ptr;
  19. u16 w_ptr;
  20. u16 f_ptr;
  21. u16 depth;
  22. u16 item_len;
  23. void *buf_addr;
  24. int (*cr_ring_bell)(void *ctx);
  25. int (*cr_update_rptr)(void *ctx);
  26. int (*cr_update_wptr)(void *ctx);
  27. int (*cr_write_rptr)(void *ctx);
  28. int (*cr_write_wptr)(void *ctx);
  29. void *cr_ctx;
  30. spinlock_t lock;
  31. unsigned long flags;
  32. bool inited;
  33. bool was_full;
  34. atomic_t outstanding_tx;
  35. };
  36. void brcmf_commonring_register_cb(struct brcmf_commonring *commonring,
  37. int (*cr_ring_bell)(void *ctx),
  38. int (*cr_update_rptr)(void *ctx),
  39. int (*cr_update_wptr)(void *ctx),
  40. int (*cr_write_rptr)(void *ctx),
  41. int (*cr_write_wptr)(void *ctx), void *ctx);
  42. void brcmf_commonring_config(struct brcmf_commonring *commonring, u16 depth,
  43. u16 item_len, void *buf_addr);
  44. void brcmf_commonring_lock(struct brcmf_commonring *commonring);
  45. void brcmf_commonring_unlock(struct brcmf_commonring *commonring);
  46. bool brcmf_commonring_write_available(struct brcmf_commonring *commonring);
  47. void *brcmf_commonring_reserve_for_write(struct brcmf_commonring *commonring);
  48. void *
  49. brcmf_commonring_reserve_for_write_multiple(struct brcmf_commonring *commonring,
  50. u16 n_items, u16 *alloced);
  51. int brcmf_commonring_write_complete(struct brcmf_commonring *commonring);
  52. void brcmf_commonring_write_cancel(struct brcmf_commonring *commonring,
  53. u16 n_items);
  54. void *brcmf_commonring_get_read_ptr(struct brcmf_commonring *commonring,
  55. u16 *n_items);
  56. int brcmf_commonring_read_complete(struct brcmf_commonring *commonring,
  57. u16 n_items);
  58. #define brcmf_commonring_n_items(commonring) (commonring->depth)
  59. #define brcmf_commonring_len_item(commonring) (commonring->item_len)
  60. #endif /* BRCMFMAC_COMMONRING_H */