Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0-only
0002  *
0003  * Copyright (c) 2021, MediaTek Inc.
0004  * Copyright (c) 2021-2022, Intel Corporation.
0005  *
0006  * Authors:
0007  *  Amir Hanania <amir.hanania@intel.com>
0008  *  Haijun Liu <haijun.liu@mediatek.com>
0009  *  Moises Veleta <moises.veleta@intel.com>
0010  *
0011  * Contributors:
0012  *  Eliot Lee <eliot.lee@intel.com>
0013  *  Ricardo Martinez <ricardo.martinez@linux.intel.com>
0014  *  Sreehari Kancharla <sreehari.kancharla@intel.com>
0015  */
0016 
0017 #ifndef __T7XX_MONITOR_H__
0018 #define __T7XX_MONITOR_H__
0019 
0020 #include <linux/bits.h>
0021 #include <linux/sched.h>
0022 #include <linux/spinlock.h>
0023 #include <linux/types.h>
0024 #include <linux/wait.h>
0025 
0026 #include "t7xx_modem_ops.h"
0027 
0028 enum t7xx_fsm_state {
0029     FSM_STATE_INIT,
0030     FSM_STATE_PRE_START,
0031     FSM_STATE_STARTING,
0032     FSM_STATE_READY,
0033     FSM_STATE_EXCEPTION,
0034     FSM_STATE_STOPPING,
0035     FSM_STATE_STOPPED,
0036 };
0037 
0038 enum t7xx_fsm_event_state {
0039     FSM_EVENT_INVALID,
0040     FSM_EVENT_MD_HS2,
0041     FSM_EVENT_MD_EX,
0042     FSM_EVENT_MD_EX_REC_OK,
0043     FSM_EVENT_MD_EX_PASS,
0044     FSM_EVENT_MD_HS2_EXIT,
0045     FSM_EVENT_MAX
0046 };
0047 
0048 enum t7xx_fsm_cmd_state {
0049     FSM_CMD_INVALID,
0050     FSM_CMD_START,
0051     FSM_CMD_EXCEPTION,
0052     FSM_CMD_PRE_STOP,
0053     FSM_CMD_STOP,
0054 };
0055 
0056 enum t7xx_ex_reason {
0057     EXCEPTION_HS_TIMEOUT,
0058     EXCEPTION_EVENT,
0059 };
0060 
0061 enum t7xx_md_irq_type {
0062     MD_IRQ_WDT,
0063     MD_IRQ_CCIF_EX,
0064     MD_IRQ_PORT_ENUM,
0065 };
0066 
0067 enum md_state {
0068     MD_STATE_INVALID,
0069     MD_STATE_WAITING_FOR_HS1,
0070     MD_STATE_WAITING_FOR_HS2,
0071     MD_STATE_READY,
0072     MD_STATE_EXCEPTION,
0073     MD_STATE_WAITING_TO_STOP,
0074     MD_STATE_STOPPED,
0075 };
0076 
0077 #define FSM_CMD_FLAG_WAIT_FOR_COMPLETION    BIT(0)
0078 #define FSM_CMD_FLAG_FLIGHT_MODE        BIT(1)
0079 #define FSM_CMD_FLAG_IN_INTERRUPT       BIT(2)
0080 #define FSM_CMD_EX_REASON           GENMASK(23, 16)
0081 
0082 struct t7xx_fsm_ctl {
0083     struct t7xx_modem   *md;
0084     enum md_state       md_state;
0085     unsigned int        curr_state;
0086     struct list_head    command_queue;
0087     struct list_head    event_queue;
0088     wait_queue_head_t   command_wq;
0089     wait_queue_head_t   event_wq;
0090     wait_queue_head_t   async_hk_wq;
0091     spinlock_t      event_lock;     /* Protects event queue */
0092     spinlock_t      command_lock;       /* Protects command queue */
0093     struct task_struct  *fsm_thread;
0094     bool            exp_flg;
0095     spinlock_t      notifier_lock;      /* Protects notifier list */
0096     struct list_head    notifier_list;
0097 };
0098 
0099 struct t7xx_fsm_event {
0100     struct list_head    entry;
0101     enum t7xx_fsm_event_state event_id;
0102     unsigned int        length;
0103     unsigned char       data[];
0104 };
0105 
0106 struct t7xx_fsm_command {
0107     struct list_head    entry;
0108     enum t7xx_fsm_cmd_state cmd_id;
0109     unsigned int        flag;
0110     struct completion   *done;
0111     int         *ret;
0112 };
0113 
0114 struct t7xx_fsm_notifier {
0115     struct list_head    entry;
0116     int (*notifier_fn)(enum md_state state, void *data);
0117     void            *data;
0118 };
0119 
0120 int t7xx_fsm_append_cmd(struct t7xx_fsm_ctl *ctl, enum t7xx_fsm_cmd_state cmd_id,
0121             unsigned int flag);
0122 int t7xx_fsm_append_event(struct t7xx_fsm_ctl *ctl, enum t7xx_fsm_event_state event_id,
0123               unsigned char *data, unsigned int length);
0124 void t7xx_fsm_clr_event(struct t7xx_fsm_ctl *ctl, enum t7xx_fsm_event_state event_id);
0125 void t7xx_fsm_broadcast_state(struct t7xx_fsm_ctl *ctl, enum md_state state);
0126 void t7xx_fsm_reset(struct t7xx_modem *md);
0127 int t7xx_fsm_init(struct t7xx_modem *md);
0128 void t7xx_fsm_uninit(struct t7xx_modem *md);
0129 int t7xx_fsm_recv_md_intr(struct t7xx_fsm_ctl *ctl, enum t7xx_md_irq_type type);
0130 enum md_state t7xx_fsm_get_md_state(struct t7xx_fsm_ctl *ctl);
0131 unsigned int t7xx_fsm_get_ctl_state(struct t7xx_fsm_ctl *ctl);
0132 void t7xx_fsm_notifier_register(struct t7xx_modem *md, struct t7xx_fsm_notifier *notifier);
0133 void t7xx_fsm_notifier_unregister(struct t7xx_modem *md, struct t7xx_fsm_notifier *notifier);
0134 
0135 #endif /* __T7XX_MONITOR_H__ */