1*ff233cb5SSergey Matyukevich /* SPDX-License-Identifier: GPL-2.0+ */
2*ff233cb5SSergey Matyukevich /* Copyright (c) 2015-2016 Quantenna Communications. All rights reserved. */
398f44cb0SIgor Mitsyanko
498f44cb0SIgor Mitsyanko #ifndef _QTN_FMAC_SHM_IPC_H_
598f44cb0SIgor Mitsyanko #define _QTN_FMAC_SHM_IPC_H_
698f44cb0SIgor Mitsyanko
798f44cb0SIgor Mitsyanko #include <linux/workqueue.h>
898f44cb0SIgor Mitsyanko #include <linux/completion.h>
998f44cb0SIgor Mitsyanko #include <linux/mutex.h>
1098f44cb0SIgor Mitsyanko #include <linux/spinlock.h>
1198f44cb0SIgor Mitsyanko
1298f44cb0SIgor Mitsyanko #include "shm_ipc_defs.h"
1398f44cb0SIgor Mitsyanko
1498f44cb0SIgor Mitsyanko #define QTN_SHM_IPC_ACK_TIMEOUT (2 * HZ)
1598f44cb0SIgor Mitsyanko
1698f44cb0SIgor Mitsyanko struct qtnf_shm_ipc_int {
1798f44cb0SIgor Mitsyanko void (*fn)(void *arg);
1898f44cb0SIgor Mitsyanko void *arg;
1998f44cb0SIgor Mitsyanko };
2098f44cb0SIgor Mitsyanko
2198f44cb0SIgor Mitsyanko struct qtnf_shm_ipc_rx_callback {
228804ea9eSSergey Matyukevich void (*fn)(void *arg, const u8 __iomem *buf, size_t len);
2398f44cb0SIgor Mitsyanko void *arg;
2498f44cb0SIgor Mitsyanko };
2598f44cb0SIgor Mitsyanko
2698f44cb0SIgor Mitsyanko enum qtnf_shm_ipc_direction {
2798f44cb0SIgor Mitsyanko QTNF_SHM_IPC_OUTBOUND = BIT(0),
2898f44cb0SIgor Mitsyanko QTNF_SHM_IPC_INBOUND = BIT(1),
2998f44cb0SIgor Mitsyanko };
3098f44cb0SIgor Mitsyanko
3198f44cb0SIgor Mitsyanko struct qtnf_shm_ipc {
3298f44cb0SIgor Mitsyanko struct qtnf_shm_ipc_region __iomem *shm_region;
3398f44cb0SIgor Mitsyanko enum qtnf_shm_ipc_direction direction;
3498f44cb0SIgor Mitsyanko size_t tx_packet_count;
3598f44cb0SIgor Mitsyanko size_t rx_packet_count;
3698f44cb0SIgor Mitsyanko
3798f44cb0SIgor Mitsyanko size_t tx_timeout_count;
3898f44cb0SIgor Mitsyanko
3998f44cb0SIgor Mitsyanko u8 waiting_for_ack;
4098f44cb0SIgor Mitsyanko
4198f44cb0SIgor Mitsyanko struct qtnf_shm_ipc_int interrupt;
4298f44cb0SIgor Mitsyanko struct qtnf_shm_ipc_rx_callback rx_callback;
4398f44cb0SIgor Mitsyanko
4498f44cb0SIgor Mitsyanko void (*irq_handler)(struct qtnf_shm_ipc *ipc);
4598f44cb0SIgor Mitsyanko
4698f44cb0SIgor Mitsyanko struct workqueue_struct *workqueue;
4798f44cb0SIgor Mitsyanko struct work_struct irq_work;
4898f44cb0SIgor Mitsyanko struct completion tx_completion;
4998f44cb0SIgor Mitsyanko };
5098f44cb0SIgor Mitsyanko
5198f44cb0SIgor Mitsyanko int qtnf_shm_ipc_init(struct qtnf_shm_ipc *ipc,
5298f44cb0SIgor Mitsyanko enum qtnf_shm_ipc_direction direction,
5398f44cb0SIgor Mitsyanko struct qtnf_shm_ipc_region __iomem *shm_region,
5498f44cb0SIgor Mitsyanko struct workqueue_struct *workqueue,
5598f44cb0SIgor Mitsyanko const struct qtnf_shm_ipc_int *interrupt,
5698f44cb0SIgor Mitsyanko const struct qtnf_shm_ipc_rx_callback *rx_callback);
5798f44cb0SIgor Mitsyanko void qtnf_shm_ipc_free(struct qtnf_shm_ipc *ipc);
5898f44cb0SIgor Mitsyanko int qtnf_shm_ipc_send(struct qtnf_shm_ipc *ipc, const u8 *buf, size_t size);
5998f44cb0SIgor Mitsyanko
qtnf_shm_ipc_irq_handler(struct qtnf_shm_ipc * ipc)6098f44cb0SIgor Mitsyanko static inline void qtnf_shm_ipc_irq_handler(struct qtnf_shm_ipc *ipc)
6198f44cb0SIgor Mitsyanko {
6298f44cb0SIgor Mitsyanko ipc->irq_handler(ipc);
6398f44cb0SIgor Mitsyanko }
6498f44cb0SIgor Mitsyanko
6598f44cb0SIgor Mitsyanko #endif /* _QTN_FMAC_SHM_IPC_H_ */
66