shm_ipc.h 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. /*
  2. * Copyright (c) 2015-2016 Quantenna Communications, Inc.
  3. * All rights reserved.
  4. *
  5. * This program is free software; you can redistribute it and/or
  6. * modify it under the terms of the GNU General Public License
  7. * as published by the Free Software Foundation; either version 2
  8. * of the License, or (at your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. */
  16. #ifndef _QTN_FMAC_SHM_IPC_H_
  17. #define _QTN_FMAC_SHM_IPC_H_
  18. #include <linux/workqueue.h>
  19. #include <linux/completion.h>
  20. #include <linux/mutex.h>
  21. #include <linux/spinlock.h>
  22. #include "shm_ipc_defs.h"
  23. #define QTN_SHM_IPC_ACK_TIMEOUT (2 * HZ)
  24. struct qtnf_shm_ipc_int {
  25. void (*fn)(void *arg);
  26. void *arg;
  27. };
  28. struct qtnf_shm_ipc_rx_callback {
  29. void (*fn)(void *arg, const u8 *buf, size_t len);
  30. void *arg;
  31. };
  32. enum qtnf_shm_ipc_direction {
  33. QTNF_SHM_IPC_OUTBOUND = BIT(0),
  34. QTNF_SHM_IPC_INBOUND = BIT(1),
  35. };
  36. struct qtnf_shm_ipc {
  37. struct qtnf_shm_ipc_region __iomem *shm_region;
  38. enum qtnf_shm_ipc_direction direction;
  39. size_t tx_packet_count;
  40. size_t rx_packet_count;
  41. size_t tx_timeout_count;
  42. u8 waiting_for_ack;
  43. u8 rx_data[QTN_IPC_MAX_DATA_SZ] __aligned(sizeof(u32));
  44. struct qtnf_shm_ipc_int interrupt;
  45. struct qtnf_shm_ipc_rx_callback rx_callback;
  46. void (*irq_handler)(struct qtnf_shm_ipc *ipc);
  47. struct workqueue_struct *workqueue;
  48. struct work_struct irq_work;
  49. struct completion tx_completion;
  50. };
  51. int qtnf_shm_ipc_init(struct qtnf_shm_ipc *ipc,
  52. enum qtnf_shm_ipc_direction direction,
  53. struct qtnf_shm_ipc_region __iomem *shm_region,
  54. struct workqueue_struct *workqueue,
  55. const struct qtnf_shm_ipc_int *interrupt,
  56. const struct qtnf_shm_ipc_rx_callback *rx_callback);
  57. void qtnf_shm_ipc_free(struct qtnf_shm_ipc *ipc);
  58. int qtnf_shm_ipc_send(struct qtnf_shm_ipc *ipc, const u8 *buf, size_t size);
  59. static inline void qtnf_shm_ipc_irq_handler(struct qtnf_shm_ipc *ipc)
  60. {
  61. ipc->irq_handler(ipc);
  62. }
  63. #endif /* _QTN_FMAC_SHM_IPC_H_ */