GNU Linux-libre 6.8.7-gnu
[releases.git] / drivers / net / wireless / quantenna / qtnfmac / shm_ipc.h
1 /* SPDX-License-Identifier: GPL-2.0+ */
2 /* Copyright (c) 2015-2016 Quantenna Communications. All rights reserved. */
3
4 #ifndef _QTN_FMAC_SHM_IPC_H_
5 #define _QTN_FMAC_SHM_IPC_H_
6
7 #include <linux/workqueue.h>
8 #include <linux/completion.h>
9 #include <linux/mutex.h>
10 #include <linux/spinlock.h>
11
12 #include "shm_ipc_defs.h"
13
14 #define QTN_SHM_IPC_ACK_TIMEOUT         (2 * HZ)
15
16 struct qtnf_shm_ipc_int {
17         void (*fn)(void *arg);
18         void *arg;
19 };
20
21 struct qtnf_shm_ipc_rx_callback {
22         void (*fn)(void *arg, const u8 __iomem *buf, size_t len);
23         void *arg;
24 };
25
26 enum qtnf_shm_ipc_direction {
27         QTNF_SHM_IPC_OUTBOUND           = BIT(0),
28         QTNF_SHM_IPC_INBOUND            = BIT(1),
29 };
30
31 struct qtnf_shm_ipc {
32         struct qtnf_shm_ipc_region __iomem *shm_region;
33         enum qtnf_shm_ipc_direction direction;
34         size_t tx_packet_count;
35         size_t rx_packet_count;
36
37         size_t tx_timeout_count;
38
39         u8 waiting_for_ack;
40
41         struct qtnf_shm_ipc_int interrupt;
42         struct qtnf_shm_ipc_rx_callback rx_callback;
43
44         void (*irq_handler)(struct qtnf_shm_ipc *ipc);
45
46         struct workqueue_struct *workqueue;
47         struct work_struct irq_work;
48         struct completion tx_completion;
49 };
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
60 static inline void qtnf_shm_ipc_irq_handler(struct qtnf_shm_ipc *ipc)
61 {
62         ipc->irq_handler(ipc);
63 }
64
65 #endif /* _QTN_FMAC_SHM_IPC_H_ */