1 /* SPDX-License-Identifier: GPL-2.0-only
3 * Copyright (c) 2021, MediaTek Inc.
4 * Copyright (c) 2021-2022, Intel Corporation.
7 * Amir Hanania <amir.hanania@intel.com>
8 * Haijun Liu <haijun.liu@mediatek.com>
9 * Moises Veleta <moises.veleta@intel.com>
12 * Eliot Lee <eliot.lee@intel.com>
13 * Ricardo Martinez <ricardo.martinez@linux.intel.com>
14 * Sreehari Kancharla <sreehari.kancharla@intel.com>
17 #ifndef __T7XX_MONITOR_H__
18 #define __T7XX_MONITOR_H__
20 #include <linux/bits.h>
21 #include <linux/sched.h>
22 #include <linux/spinlock.h>
23 #include <linux/types.h>
24 #include <linux/wait.h>
26 #include "t7xx_modem_ops.h"
38 enum t7xx_fsm_event_state {
43 FSM_EVENT_MD_EX_REC_OK,
45 FSM_EVENT_MD_HS2_EXIT,
46 FSM_EVENT_AP_HS2_EXIT,
50 enum t7xx_fsm_cmd_state {
63 enum t7xx_md_irq_type {
71 MD_STATE_WAITING_FOR_HS1,
72 MD_STATE_WAITING_FOR_HS2,
75 MD_STATE_WAITING_TO_STOP,
79 #define FSM_CMD_FLAG_WAIT_FOR_COMPLETION BIT(0)
80 #define FSM_CMD_FLAG_FLIGHT_MODE BIT(1)
81 #define FSM_CMD_FLAG_IN_INTERRUPT BIT(2)
82 #define FSM_CMD_EX_REASON GENMASK(23, 16)
85 struct t7xx_modem *md;
86 enum md_state md_state;
87 unsigned int curr_state;
88 struct list_head command_queue;
89 struct list_head event_queue;
90 wait_queue_head_t command_wq;
91 wait_queue_head_t event_wq;
92 wait_queue_head_t async_hk_wq;
93 spinlock_t event_lock; /* Protects event queue */
94 spinlock_t command_lock; /* Protects command queue */
95 struct task_struct *fsm_thread;
97 spinlock_t notifier_lock; /* Protects notifier list */
98 struct list_head notifier_list;
101 struct t7xx_fsm_event {
102 struct list_head entry;
103 enum t7xx_fsm_event_state event_id;
105 unsigned char data[] __counted_by(length);
108 struct t7xx_fsm_command {
109 struct list_head entry;
110 enum t7xx_fsm_cmd_state cmd_id;
112 struct completion *done;
116 struct t7xx_fsm_notifier {
117 struct list_head entry;
118 int (*notifier_fn)(enum md_state state, void *data);
122 int t7xx_fsm_append_cmd(struct t7xx_fsm_ctl *ctl, enum t7xx_fsm_cmd_state cmd_id,
124 int t7xx_fsm_append_event(struct t7xx_fsm_ctl *ctl, enum t7xx_fsm_event_state event_id,
125 unsigned char *data, unsigned int length);
126 void t7xx_fsm_clr_event(struct t7xx_fsm_ctl *ctl, enum t7xx_fsm_event_state event_id);
127 void t7xx_fsm_broadcast_state(struct t7xx_fsm_ctl *ctl, enum md_state state);
128 void t7xx_fsm_reset(struct t7xx_modem *md);
129 int t7xx_fsm_init(struct t7xx_modem *md);
130 void t7xx_fsm_uninit(struct t7xx_modem *md);
131 int t7xx_fsm_recv_md_intr(struct t7xx_fsm_ctl *ctl, enum t7xx_md_irq_type type);
132 enum md_state t7xx_fsm_get_md_state(struct t7xx_fsm_ctl *ctl);
133 unsigned int t7xx_fsm_get_ctl_state(struct t7xx_fsm_ctl *ctl);
134 void t7xx_fsm_notifier_register(struct t7xx_modem *md, struct t7xx_fsm_notifier *notifier);
135 void t7xx_fsm_notifier_unregister(struct t7xx_modem *md, struct t7xx_fsm_notifier *notifier);
137 #endif /* __T7XX_MONITOR_H__ */