xref: /linux/drivers/net/wwan/t7xx/t7xx_modem_ops.h (revision 9410645520e9b820069761f3450ef6661418e279)
113e920d9SHaijun Liu /* SPDX-License-Identifier: GPL-2.0-only
213e920d9SHaijun Liu  *
313e920d9SHaijun Liu  * Copyright (c) 2021, MediaTek Inc.
413e920d9SHaijun Liu  * Copyright (c) 2021-2022, Intel Corporation.
513e920d9SHaijun Liu  *
613e920d9SHaijun Liu  * Authors:
713e920d9SHaijun Liu  *  Haijun Liu <haijun.liu@mediatek.com>
813e920d9SHaijun Liu  *  Eliot Lee <eliot.lee@intel.com>
913e920d9SHaijun Liu  *  Moises Veleta <moises.veleta@intel.com>
1013e920d9SHaijun Liu  *  Ricardo Martinez <ricardo.martinez@linux.intel.com>
1113e920d9SHaijun Liu  *
1213e920d9SHaijun Liu  * Contributors:
1313e920d9SHaijun Liu  *  Amir Hanania <amir.hanania@intel.com>
1413e920d9SHaijun Liu  *  Chiranjeevi Rapolu <chiranjeevi.rapolu@intel.com>
1513e920d9SHaijun Liu  *  Sreehari Kancharla <sreehari.kancharla@intel.com>
1613e920d9SHaijun Liu  */
1713e920d9SHaijun Liu 
1813e920d9SHaijun Liu #ifndef __T7XX_MODEM_OPS_H__
1913e920d9SHaijun Liu #define __T7XX_MODEM_OPS_H__
2013e920d9SHaijun Liu 
2113e920d9SHaijun Liu #include <linux/spinlock.h>
2213e920d9SHaijun Liu #include <linux/types.h>
2313e920d9SHaijun Liu #include <linux/workqueue.h>
2413e920d9SHaijun Liu 
2513e920d9SHaijun Liu #include "t7xx_hif_cldma.h"
2613e920d9SHaijun Liu #include "t7xx_pci.h"
2713e920d9SHaijun Liu 
2813e920d9SHaijun Liu #define FEATURE_COUNT		64
2913e920d9SHaijun Liu 
3013e920d9SHaijun Liu /**
3113e920d9SHaijun Liu  * enum hif_ex_stage -	HIF exception handshake stages with the HW.
3213e920d9SHaijun Liu  * @HIF_EX_INIT:        Disable and clear TXQ.
3313e920d9SHaijun Liu  * @HIF_EX_INIT_DONE:   Polling for initialization to be done.
3413e920d9SHaijun Liu  * @HIF_EX_CLEARQ_DONE: Disable RX, flush TX/RX workqueues and clear RX.
3513e920d9SHaijun Liu  * @HIF_EX_ALLQ_RESET:  HW is back in safe mode for re-initialization and restart.
3613e920d9SHaijun Liu  */
3713e920d9SHaijun Liu enum hif_ex_stage {
3813e920d9SHaijun Liu 	HIF_EX_INIT,
3913e920d9SHaijun Liu 	HIF_EX_INIT_DONE,
4013e920d9SHaijun Liu 	HIF_EX_CLEARQ_DONE,
4113e920d9SHaijun Liu 	HIF_EX_ALLQ_RESET,
4213e920d9SHaijun Liu };
4313e920d9SHaijun Liu 
4413e920d9SHaijun Liu struct mtk_runtime_feature {
4513e920d9SHaijun Liu 	u8				feature_id;
4613e920d9SHaijun Liu 	u8				support_info;
4713e920d9SHaijun Liu 	u8				reserved[2];
4813e920d9SHaijun Liu 	__le32				data_len;
4913e920d9SHaijun Liu 	__le32				data[];
5013e920d9SHaijun Liu };
5113e920d9SHaijun Liu 
5213e920d9SHaijun Liu enum md_event_id {
5313e920d9SHaijun Liu 	FSM_PRE_START,
5413e920d9SHaijun Liu 	FSM_START,
5513e920d9SHaijun Liu 	FSM_READY,
5613e920d9SHaijun Liu };
5713e920d9SHaijun Liu 
5813e920d9SHaijun Liu struct t7xx_sys_info {
5913e920d9SHaijun Liu 	bool				ready;
60da45d256SHaijun Liu 	bool				handshake_ongoing;
61da45d256SHaijun Liu 	u8				feature_set[FEATURE_COUNT];
62da45d256SHaijun Liu 	struct t7xx_port		*ctl_port;
6313e920d9SHaijun Liu };
6413e920d9SHaijun Liu 
6513e920d9SHaijun Liu struct t7xx_modem {
6613e920d9SHaijun Liu 	struct cldma_ctrl		*md_ctrl[CLDMA_NUM];
6713e920d9SHaijun Liu 	struct t7xx_pci_dev		*t7xx_dev;
6813e920d9SHaijun Liu 	struct t7xx_sys_info		core_md;
69ba2274dcSJose Ignacio Tornos Martinez 	struct t7xx_sys_info		core_ap;
7013e920d9SHaijun Liu 	bool				md_init_finish;
7113e920d9SHaijun Liu 	bool				rgu_irq_asserted;
7213e920d9SHaijun Liu 	struct workqueue_struct		*handshake_wq;
7313e920d9SHaijun Liu 	struct work_struct		handshake_work;
74ba2274dcSJose Ignacio Tornos Martinez 	struct work_struct		ap_handshake_work;
7513e920d9SHaijun Liu 	struct t7xx_fsm_ctl		*fsm_ctl;
7613e920d9SHaijun Liu 	struct port_proxy		*port_prox;
7713e920d9SHaijun Liu 	unsigned int			exp_id;
7813e920d9SHaijun Liu 	spinlock_t			exp_lock; /* Protects exception events */
7913e920d9SHaijun Liu };
8013e920d9SHaijun Liu 
81*d785ed94SJinjian Song enum reset_type {
82*d785ed94SJinjian Song 	FLDR,
83*d785ed94SJinjian Song 	PLDR,
84*d785ed94SJinjian Song 	FASTBOOT,
85*d785ed94SJinjian Song };
86*d785ed94SJinjian Song 
8713e920d9SHaijun Liu void t7xx_md_exception_handshake(struct t7xx_modem *md);
8813e920d9SHaijun Liu void t7xx_md_event_notify(struct t7xx_modem *md, enum md_event_id evt_id);
8913e920d9SHaijun Liu int t7xx_md_reset(struct t7xx_pci_dev *t7xx_dev);
9013e920d9SHaijun Liu int t7xx_md_init(struct t7xx_pci_dev *t7xx_dev);
9113e920d9SHaijun Liu void t7xx_md_exit(struct t7xx_pci_dev *t7xx_dev);
9213e920d9SHaijun Liu void t7xx_clear_rgu_irq(struct t7xx_pci_dev *t7xx_dev);
93*d785ed94SJinjian Song int t7xx_reset_device(struct t7xx_pci_dev *t7xx_dev, enum reset_type type);
9413e920d9SHaijun Liu int t7xx_pci_mhccif_isr(struct t7xx_pci_dev *t7xx_dev);
9513e920d9SHaijun Liu 
9613e920d9SHaijun Liu #endif	/* __T7XX_MODEM_OPS_H__ */
97