162306a36Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 */
262306a36Sopenharmony_ci/*
362306a36Sopenharmony_ci * Copyright (c) 2022, Linaro Ltd.
462306a36Sopenharmony_ci *
562306a36Sopenharmony_ci */
662306a36Sopenharmony_ci
762306a36Sopenharmony_ci#ifndef _MHI_COMMON_H
862306a36Sopenharmony_ci#define _MHI_COMMON_H
962306a36Sopenharmony_ci
1062306a36Sopenharmony_ci#include <linux/bitfield.h>
1162306a36Sopenharmony_ci#include <linux/mhi.h>
1262306a36Sopenharmony_ci
1362306a36Sopenharmony_ci/* MHI registers */
1462306a36Sopenharmony_ci#define MHIREGLEN			0x00
1562306a36Sopenharmony_ci#define MHIVER				0x08
1662306a36Sopenharmony_ci#define MHICFG				0x10
1762306a36Sopenharmony_ci#define CHDBOFF				0x18
1862306a36Sopenharmony_ci#define ERDBOFF				0x20
1962306a36Sopenharmony_ci#define BHIOFF				0x28
2062306a36Sopenharmony_ci#define BHIEOFF				0x2c
2162306a36Sopenharmony_ci#define DEBUGOFF			0x30
2262306a36Sopenharmony_ci#define MHICTRL				0x38
2362306a36Sopenharmony_ci#define MHISTATUS			0x48
2462306a36Sopenharmony_ci#define CCABAP_LOWER			0x58
2562306a36Sopenharmony_ci#define CCABAP_HIGHER			0x5c
2662306a36Sopenharmony_ci#define ECABAP_LOWER			0x60
2762306a36Sopenharmony_ci#define ECABAP_HIGHER			0x64
2862306a36Sopenharmony_ci#define CRCBAP_LOWER			0x68
2962306a36Sopenharmony_ci#define CRCBAP_HIGHER			0x6c
3062306a36Sopenharmony_ci#define CRDB_LOWER			0x70
3162306a36Sopenharmony_ci#define CRDB_HIGHER			0x74
3262306a36Sopenharmony_ci#define MHICTRLBASE_LOWER		0x80
3362306a36Sopenharmony_ci#define MHICTRLBASE_HIGHER		0x84
3462306a36Sopenharmony_ci#define MHICTRLLIMIT_LOWER		0x88
3562306a36Sopenharmony_ci#define MHICTRLLIMIT_HIGHER		0x8c
3662306a36Sopenharmony_ci#define MHIDATABASE_LOWER		0x98
3762306a36Sopenharmony_ci#define MHIDATABASE_HIGHER		0x9c
3862306a36Sopenharmony_ci#define MHIDATALIMIT_LOWER		0xa0
3962306a36Sopenharmony_ci#define MHIDATALIMIT_HIGHER		0xa4
4062306a36Sopenharmony_ci
4162306a36Sopenharmony_ci/* MHI BHI registers */
4262306a36Sopenharmony_ci#define BHI_BHIVERSION_MINOR		0x00
4362306a36Sopenharmony_ci#define BHI_BHIVERSION_MAJOR		0x04
4462306a36Sopenharmony_ci#define BHI_IMGADDR_LOW			0x08
4562306a36Sopenharmony_ci#define BHI_IMGADDR_HIGH		0x0c
4662306a36Sopenharmony_ci#define BHI_IMGSIZE			0x10
4762306a36Sopenharmony_ci#define BHI_RSVD1			0x14
4862306a36Sopenharmony_ci#define BHI_IMGTXDB			0x18
4962306a36Sopenharmony_ci#define BHI_RSVD2			0x1c
5062306a36Sopenharmony_ci#define BHI_INTVEC			0x20
5162306a36Sopenharmony_ci#define BHI_RSVD3			0x24
5262306a36Sopenharmony_ci#define BHI_EXECENV			0x28
5362306a36Sopenharmony_ci#define BHI_STATUS			0x2c
5462306a36Sopenharmony_ci#define BHI_ERRCODE			0x30
5562306a36Sopenharmony_ci#define BHI_ERRDBG1			0x34
5662306a36Sopenharmony_ci#define BHI_ERRDBG2			0x38
5762306a36Sopenharmony_ci#define BHI_ERRDBG3			0x3c
5862306a36Sopenharmony_ci#define BHI_SERIALNU			0x40
5962306a36Sopenharmony_ci#define BHI_SBLANTIROLLVER		0x44
6062306a36Sopenharmony_ci#define BHI_NUMSEG			0x48
6162306a36Sopenharmony_ci#define BHI_MSMHWID(n)			(0x4c + (0x4 * (n)))
6262306a36Sopenharmony_ci#define BHI_OEMPKHASH(n)		(0x64 + (0x4 * (n)))
6362306a36Sopenharmony_ci#define BHI_RSVD5			0xc4
6462306a36Sopenharmony_ci
6562306a36Sopenharmony_ci/* BHI register bits */
6662306a36Sopenharmony_ci#define BHI_TXDB_SEQNUM_BMSK		GENMASK(29, 0)
6762306a36Sopenharmony_ci#define BHI_TXDB_SEQNUM_SHFT		0
6862306a36Sopenharmony_ci#define BHI_STATUS_MASK			GENMASK(31, 30)
6962306a36Sopenharmony_ci#define BHI_STATUS_ERROR		0x03
7062306a36Sopenharmony_ci#define BHI_STATUS_SUCCESS		0x02
7162306a36Sopenharmony_ci#define BHI_STATUS_RESET		0x00
7262306a36Sopenharmony_ci
7362306a36Sopenharmony_ci/* MHI BHIE registers */
7462306a36Sopenharmony_ci#define BHIE_MSMSOCID_OFFS		0x00
7562306a36Sopenharmony_ci#define BHIE_TXVECADDR_LOW_OFFS		0x2c
7662306a36Sopenharmony_ci#define BHIE_TXVECADDR_HIGH_OFFS	0x30
7762306a36Sopenharmony_ci#define BHIE_TXVECSIZE_OFFS		0x34
7862306a36Sopenharmony_ci#define BHIE_TXVECDB_OFFS		0x3c
7962306a36Sopenharmony_ci#define BHIE_TXVECSTATUS_OFFS		0x44
8062306a36Sopenharmony_ci#define BHIE_RXVECADDR_LOW_OFFS		0x60
8162306a36Sopenharmony_ci#define BHIE_RXVECADDR_HIGH_OFFS	0x64
8262306a36Sopenharmony_ci#define BHIE_RXVECSIZE_OFFS		0x68
8362306a36Sopenharmony_ci#define BHIE_RXVECDB_OFFS		0x70
8462306a36Sopenharmony_ci#define BHIE_RXVECSTATUS_OFFS		0x78
8562306a36Sopenharmony_ci
8662306a36Sopenharmony_ci/* BHIE register bits */
8762306a36Sopenharmony_ci#define BHIE_TXVECDB_SEQNUM_BMSK	GENMASK(29, 0)
8862306a36Sopenharmony_ci#define BHIE_TXVECDB_SEQNUM_SHFT	0
8962306a36Sopenharmony_ci#define BHIE_TXVECSTATUS_SEQNUM_BMSK	GENMASK(29, 0)
9062306a36Sopenharmony_ci#define BHIE_TXVECSTATUS_SEQNUM_SHFT	0
9162306a36Sopenharmony_ci#define BHIE_TXVECSTATUS_STATUS_BMSK	GENMASK(31, 30)
9262306a36Sopenharmony_ci#define BHIE_TXVECSTATUS_STATUS_SHFT	30
9362306a36Sopenharmony_ci#define BHIE_TXVECSTATUS_STATUS_RESET	0x00
9462306a36Sopenharmony_ci#define BHIE_TXVECSTATUS_STATUS_XFER_COMPL	0x02
9562306a36Sopenharmony_ci#define BHIE_TXVECSTATUS_STATUS_ERROR	0x03
9662306a36Sopenharmony_ci#define BHIE_RXVECDB_SEQNUM_BMSK	GENMASK(29, 0)
9762306a36Sopenharmony_ci#define BHIE_RXVECDB_SEQNUM_SHFT	0
9862306a36Sopenharmony_ci#define BHIE_RXVECSTATUS_SEQNUM_BMSK	GENMASK(29, 0)
9962306a36Sopenharmony_ci#define BHIE_RXVECSTATUS_SEQNUM_SHFT	0
10062306a36Sopenharmony_ci#define BHIE_RXVECSTATUS_STATUS_BMSK	GENMASK(31, 30)
10162306a36Sopenharmony_ci#define BHIE_RXVECSTATUS_STATUS_SHFT	30
10262306a36Sopenharmony_ci#define BHIE_RXVECSTATUS_STATUS_RESET	0x00
10362306a36Sopenharmony_ci#define BHIE_RXVECSTATUS_STATUS_XFER_COMPL	0x02
10462306a36Sopenharmony_ci#define BHIE_RXVECSTATUS_STATUS_ERROR	0x03
10562306a36Sopenharmony_ci
10662306a36Sopenharmony_ci/* MHI register bits */
10762306a36Sopenharmony_ci#define MHICFG_NHWER_MASK		GENMASK(31, 24)
10862306a36Sopenharmony_ci#define MHICFG_NER_MASK			GENMASK(23, 16)
10962306a36Sopenharmony_ci#define MHICFG_NHWCH_MASK		GENMASK(15, 8)
11062306a36Sopenharmony_ci#define MHICFG_NCH_MASK			GENMASK(7, 0)
11162306a36Sopenharmony_ci#define MHICTRL_MHISTATE_MASK		GENMASK(15, 8)
11262306a36Sopenharmony_ci#define MHICTRL_RESET_MASK		BIT(1)
11362306a36Sopenharmony_ci#define MHISTATUS_MHISTATE_MASK		GENMASK(15, 8)
11462306a36Sopenharmony_ci#define MHISTATUS_SYSERR_MASK		BIT(2)
11562306a36Sopenharmony_ci#define MHISTATUS_READY_MASK		BIT(0)
11662306a36Sopenharmony_ci
11762306a36Sopenharmony_ci/* Command Ring Element macros */
11862306a36Sopenharmony_ci/* No operation command */
11962306a36Sopenharmony_ci#define MHI_TRE_CMD_NOOP_PTR		0
12062306a36Sopenharmony_ci#define MHI_TRE_CMD_NOOP_DWORD0		0
12162306a36Sopenharmony_ci#define MHI_TRE_CMD_NOOP_DWORD1		cpu_to_le32(FIELD_PREP(GENMASK(23, 16), MHI_CMD_NOP))
12262306a36Sopenharmony_ci
12362306a36Sopenharmony_ci/* Channel reset command */
12462306a36Sopenharmony_ci#define MHI_TRE_CMD_RESET_PTR		0
12562306a36Sopenharmony_ci#define MHI_TRE_CMD_RESET_DWORD0	0
12662306a36Sopenharmony_ci#define MHI_TRE_CMD_RESET_DWORD1(chid)	cpu_to_le32(FIELD_PREP(GENMASK(31, 24), chid) | \
12762306a36Sopenharmony_ci						    FIELD_PREP(GENMASK(23, 16),         \
12862306a36Sopenharmony_ci							       MHI_CMD_RESET_CHAN))
12962306a36Sopenharmony_ci
13062306a36Sopenharmony_ci/* Channel stop command */
13162306a36Sopenharmony_ci#define MHI_TRE_CMD_STOP_PTR		0
13262306a36Sopenharmony_ci#define MHI_TRE_CMD_STOP_DWORD0		0
13362306a36Sopenharmony_ci#define MHI_TRE_CMD_STOP_DWORD1(chid)	cpu_to_le32(FIELD_PREP(GENMASK(31, 24), chid) | \
13462306a36Sopenharmony_ci						    FIELD_PREP(GENMASK(23, 16),         \
13562306a36Sopenharmony_ci							       MHI_CMD_STOP_CHAN))
13662306a36Sopenharmony_ci
13762306a36Sopenharmony_ci/* Channel start command */
13862306a36Sopenharmony_ci#define MHI_TRE_CMD_START_PTR		0
13962306a36Sopenharmony_ci#define MHI_TRE_CMD_START_DWORD0	0
14062306a36Sopenharmony_ci#define MHI_TRE_CMD_START_DWORD1(chid)	cpu_to_le32(FIELD_PREP(GENMASK(31, 24), chid) | \
14162306a36Sopenharmony_ci						    FIELD_PREP(GENMASK(23, 16),         \
14262306a36Sopenharmony_ci							       MHI_CMD_START_CHAN))
14362306a36Sopenharmony_ci
14462306a36Sopenharmony_ci#define MHI_TRE_GET_DWORD(tre, word)	le32_to_cpu((tre)->dword[(word)])
14562306a36Sopenharmony_ci#define MHI_TRE_GET_CMD_CHID(tre)	FIELD_GET(GENMASK(31, 24), MHI_TRE_GET_DWORD(tre, 1))
14662306a36Sopenharmony_ci#define MHI_TRE_GET_CMD_TYPE(tre)	FIELD_GET(GENMASK(23, 16), MHI_TRE_GET_DWORD(tre, 1))
14762306a36Sopenharmony_ci
14862306a36Sopenharmony_ci/* Event descriptor macros */
14962306a36Sopenharmony_ci#define MHI_TRE_EV_PTR(ptr)		cpu_to_le64(ptr)
15062306a36Sopenharmony_ci#define MHI_TRE_EV_DWORD0(code, len)	cpu_to_le32(FIELD_PREP(GENMASK(31, 24), code) | \
15162306a36Sopenharmony_ci						    FIELD_PREP(GENMASK(15, 0), len))
15262306a36Sopenharmony_ci#define MHI_TRE_EV_DWORD1(chid, type)	cpu_to_le32(FIELD_PREP(GENMASK(31, 24), chid) | \
15362306a36Sopenharmony_ci						    FIELD_PREP(GENMASK(23, 16), type))
15462306a36Sopenharmony_ci#define MHI_TRE_GET_EV_PTR(tre)		le64_to_cpu((tre)->ptr)
15562306a36Sopenharmony_ci#define MHI_TRE_GET_EV_CODE(tre)	FIELD_GET(GENMASK(31, 24), (MHI_TRE_GET_DWORD(tre, 0)))
15662306a36Sopenharmony_ci#define MHI_TRE_GET_EV_LEN(tre)		FIELD_GET(GENMASK(15, 0), (MHI_TRE_GET_DWORD(tre, 0)))
15762306a36Sopenharmony_ci#define MHI_TRE_GET_EV_CHID(tre)	FIELD_GET(GENMASK(31, 24), (MHI_TRE_GET_DWORD(tre, 1)))
15862306a36Sopenharmony_ci#define MHI_TRE_GET_EV_TYPE(tre)	FIELD_GET(GENMASK(23, 16), (MHI_TRE_GET_DWORD(tre, 1)))
15962306a36Sopenharmony_ci#define MHI_TRE_GET_EV_STATE(tre)	FIELD_GET(GENMASK(31, 24), (MHI_TRE_GET_DWORD(tre, 0)))
16062306a36Sopenharmony_ci#define MHI_TRE_GET_EV_EXECENV(tre)	FIELD_GET(GENMASK(31, 24), (MHI_TRE_GET_DWORD(tre, 0)))
16162306a36Sopenharmony_ci#define MHI_TRE_GET_EV_SEQ(tre)		MHI_TRE_GET_DWORD(tre, 0)
16262306a36Sopenharmony_ci#define MHI_TRE_GET_EV_TIME(tre)	MHI_TRE_GET_EV_PTR(tre)
16362306a36Sopenharmony_ci#define MHI_TRE_GET_EV_COOKIE(tre)	lower_32_bits(MHI_TRE_GET_EV_PTR(tre))
16462306a36Sopenharmony_ci#define MHI_TRE_GET_EV_VEID(tre)	FIELD_GET(GENMASK(23, 16), (MHI_TRE_GET_DWORD(tre, 0)))
16562306a36Sopenharmony_ci#define MHI_TRE_GET_EV_LINKSPEED(tre)	FIELD_GET(GENMASK(31, 24), (MHI_TRE_GET_DWORD(tre, 1)))
16662306a36Sopenharmony_ci#define MHI_TRE_GET_EV_LINKWIDTH(tre)	FIELD_GET(GENMASK(7, 0), (MHI_TRE_GET_DWORD(tre, 0)))
16762306a36Sopenharmony_ci
16862306a36Sopenharmony_ci/* State change event */
16962306a36Sopenharmony_ci#define MHI_SC_EV_PTR			0
17062306a36Sopenharmony_ci#define MHI_SC_EV_DWORD0(state)		cpu_to_le32(FIELD_PREP(GENMASK(31, 24), state))
17162306a36Sopenharmony_ci#define MHI_SC_EV_DWORD1(type)		cpu_to_le32(FIELD_PREP(GENMASK(23, 16), type))
17262306a36Sopenharmony_ci
17362306a36Sopenharmony_ci/* EE event */
17462306a36Sopenharmony_ci#define MHI_EE_EV_PTR			0
17562306a36Sopenharmony_ci#define MHI_EE_EV_DWORD0(ee)		cpu_to_le32(FIELD_PREP(GENMASK(31, 24), ee))
17662306a36Sopenharmony_ci#define MHI_EE_EV_DWORD1(type)		cpu_to_le32(FIELD_PREP(GENMASK(23, 16), type))
17762306a36Sopenharmony_ci
17862306a36Sopenharmony_ci
17962306a36Sopenharmony_ci/* Command Completion event */
18062306a36Sopenharmony_ci#define MHI_CC_EV_PTR(ptr)		cpu_to_le64(ptr)
18162306a36Sopenharmony_ci#define MHI_CC_EV_DWORD0(code)		cpu_to_le32(FIELD_PREP(GENMASK(31, 24), code))
18262306a36Sopenharmony_ci#define MHI_CC_EV_DWORD1(type)		cpu_to_le32(FIELD_PREP(GENMASK(23, 16), type))
18362306a36Sopenharmony_ci
18462306a36Sopenharmony_ci/* Transfer descriptor macros */
18562306a36Sopenharmony_ci#define MHI_TRE_DATA_PTR(ptr)		cpu_to_le64(ptr)
18662306a36Sopenharmony_ci#define MHI_TRE_DATA_DWORD0(len)	cpu_to_le32(FIELD_PREP(GENMASK(15, 0), len))
18762306a36Sopenharmony_ci#define MHI_TRE_TYPE_TRANSFER		2
18862306a36Sopenharmony_ci#define MHI_TRE_DATA_DWORD1(bei, ieot, ieob, chain) cpu_to_le32(FIELD_PREP(GENMASK(23, 16), \
18962306a36Sopenharmony_ci								MHI_TRE_TYPE_TRANSFER) |    \
19062306a36Sopenharmony_ci								FIELD_PREP(BIT(10), bei) |  \
19162306a36Sopenharmony_ci								FIELD_PREP(BIT(9), ieot) |  \
19262306a36Sopenharmony_ci								FIELD_PREP(BIT(8), ieob) |  \
19362306a36Sopenharmony_ci								FIELD_PREP(BIT(0), chain))
19462306a36Sopenharmony_ci#define MHI_TRE_DATA_GET_PTR(tre)	le64_to_cpu((tre)->ptr)
19562306a36Sopenharmony_ci#define MHI_TRE_DATA_GET_LEN(tre)	FIELD_GET(GENMASK(15, 0), MHI_TRE_GET_DWORD(tre, 0))
19662306a36Sopenharmony_ci#define MHI_TRE_DATA_GET_CHAIN(tre)	(!!(FIELD_GET(BIT(0), MHI_TRE_GET_DWORD(tre, 1))))
19762306a36Sopenharmony_ci#define MHI_TRE_DATA_GET_IEOB(tre)	(!!(FIELD_GET(BIT(8), MHI_TRE_GET_DWORD(tre, 1))))
19862306a36Sopenharmony_ci#define MHI_TRE_DATA_GET_IEOT(tre)	(!!(FIELD_GET(BIT(9), MHI_TRE_GET_DWORD(tre, 1))))
19962306a36Sopenharmony_ci#define MHI_TRE_DATA_GET_BEI(tre)	(!!(FIELD_GET(BIT(10), MHI_TRE_GET_DWORD(tre, 1))))
20062306a36Sopenharmony_ci
20162306a36Sopenharmony_ci/* RSC transfer descriptor macros */
20262306a36Sopenharmony_ci#define MHI_RSCTRE_DATA_PTR(ptr, len)	cpu_to_le64(FIELD_PREP(GENMASK(64, 48), len) | ptr)
20362306a36Sopenharmony_ci#define MHI_RSCTRE_DATA_DWORD0(cookie)	cpu_to_le32(cookie)
20462306a36Sopenharmony_ci#define MHI_RSCTRE_DATA_DWORD1		cpu_to_le32(FIELD_PREP(GENMASK(23, 16), \
20562306a36Sopenharmony_ci							       MHI_PKT_TYPE_COALESCING))
20662306a36Sopenharmony_ci
20762306a36Sopenharmony_cienum mhi_pkt_type {
20862306a36Sopenharmony_ci	MHI_PKT_TYPE_INVALID = 0x0,
20962306a36Sopenharmony_ci	MHI_PKT_TYPE_NOOP_CMD = 0x1,
21062306a36Sopenharmony_ci	MHI_PKT_TYPE_TRANSFER = 0x2,
21162306a36Sopenharmony_ci	MHI_PKT_TYPE_COALESCING = 0x8,
21262306a36Sopenharmony_ci	MHI_PKT_TYPE_RESET_CHAN_CMD = 0x10,
21362306a36Sopenharmony_ci	MHI_PKT_TYPE_STOP_CHAN_CMD = 0x11,
21462306a36Sopenharmony_ci	MHI_PKT_TYPE_START_CHAN_CMD = 0x12,
21562306a36Sopenharmony_ci	MHI_PKT_TYPE_STATE_CHANGE_EVENT = 0x20,
21662306a36Sopenharmony_ci	MHI_PKT_TYPE_CMD_COMPLETION_EVENT = 0x21,
21762306a36Sopenharmony_ci	MHI_PKT_TYPE_TX_EVENT = 0x22,
21862306a36Sopenharmony_ci	MHI_PKT_TYPE_RSC_TX_EVENT = 0x28,
21962306a36Sopenharmony_ci	MHI_PKT_TYPE_EE_EVENT = 0x40,
22062306a36Sopenharmony_ci	MHI_PKT_TYPE_TSYNC_EVENT = 0x48,
22162306a36Sopenharmony_ci	MHI_PKT_TYPE_BW_REQ_EVENT = 0x50,
22262306a36Sopenharmony_ci	MHI_PKT_TYPE_STALE_EVENT, /* internal event */
22362306a36Sopenharmony_ci};
22462306a36Sopenharmony_ci
22562306a36Sopenharmony_ci/* MHI transfer completion events */
22662306a36Sopenharmony_cienum mhi_ev_ccs {
22762306a36Sopenharmony_ci	MHI_EV_CC_INVALID = 0x0,
22862306a36Sopenharmony_ci	MHI_EV_CC_SUCCESS = 0x1,
22962306a36Sopenharmony_ci	MHI_EV_CC_EOT = 0x2, /* End of transfer event */
23062306a36Sopenharmony_ci	MHI_EV_CC_OVERFLOW = 0x3,
23162306a36Sopenharmony_ci	MHI_EV_CC_EOB = 0x4, /* End of block event */
23262306a36Sopenharmony_ci	MHI_EV_CC_OOB = 0x5, /* Out of block event */
23362306a36Sopenharmony_ci	MHI_EV_CC_DB_MODE = 0x6,
23462306a36Sopenharmony_ci	MHI_EV_CC_UNDEFINED_ERR = 0x10,
23562306a36Sopenharmony_ci	MHI_EV_CC_BAD_TRE = 0x11,
23662306a36Sopenharmony_ci};
23762306a36Sopenharmony_ci
23862306a36Sopenharmony_ci/* Channel state */
23962306a36Sopenharmony_cienum mhi_ch_state {
24062306a36Sopenharmony_ci	MHI_CH_STATE_DISABLED,
24162306a36Sopenharmony_ci	MHI_CH_STATE_ENABLED,
24262306a36Sopenharmony_ci	MHI_CH_STATE_RUNNING,
24362306a36Sopenharmony_ci	MHI_CH_STATE_SUSPENDED,
24462306a36Sopenharmony_ci	MHI_CH_STATE_STOP,
24562306a36Sopenharmony_ci	MHI_CH_STATE_ERROR,
24662306a36Sopenharmony_ci};
24762306a36Sopenharmony_ci
24862306a36Sopenharmony_cienum mhi_cmd_type {
24962306a36Sopenharmony_ci	MHI_CMD_NOP = 1,
25062306a36Sopenharmony_ci	MHI_CMD_RESET_CHAN = 16,
25162306a36Sopenharmony_ci	MHI_CMD_STOP_CHAN = 17,
25262306a36Sopenharmony_ci	MHI_CMD_START_CHAN = 18,
25362306a36Sopenharmony_ci};
25462306a36Sopenharmony_ci
25562306a36Sopenharmony_ci#define EV_CTX_RESERVED_MASK		GENMASK(7, 0)
25662306a36Sopenharmony_ci#define EV_CTX_INTMODC_MASK		GENMASK(15, 8)
25762306a36Sopenharmony_ci#define EV_CTX_INTMODT_MASK		GENMASK(31, 16)
25862306a36Sopenharmony_cistruct mhi_event_ctxt {
25962306a36Sopenharmony_ci	__le32 intmod;
26062306a36Sopenharmony_ci	__le32 ertype;
26162306a36Sopenharmony_ci	__le32 msivec;
26262306a36Sopenharmony_ci
26362306a36Sopenharmony_ci	__le64 rbase __packed __aligned(4);
26462306a36Sopenharmony_ci	__le64 rlen __packed __aligned(4);
26562306a36Sopenharmony_ci	__le64 rp __packed __aligned(4);
26662306a36Sopenharmony_ci	__le64 wp __packed __aligned(4);
26762306a36Sopenharmony_ci};
26862306a36Sopenharmony_ci
26962306a36Sopenharmony_ci#define CHAN_CTX_CHSTATE_MASK		GENMASK(7, 0)
27062306a36Sopenharmony_ci#define CHAN_CTX_BRSTMODE_MASK		GENMASK(9, 8)
27162306a36Sopenharmony_ci#define CHAN_CTX_POLLCFG_MASK		GENMASK(15, 10)
27262306a36Sopenharmony_ci#define CHAN_CTX_RESERVED_MASK		GENMASK(31, 16)
27362306a36Sopenharmony_cistruct mhi_chan_ctxt {
27462306a36Sopenharmony_ci	__le32 chcfg;
27562306a36Sopenharmony_ci	__le32 chtype;
27662306a36Sopenharmony_ci	__le32 erindex;
27762306a36Sopenharmony_ci
27862306a36Sopenharmony_ci	__le64 rbase __packed __aligned(4);
27962306a36Sopenharmony_ci	__le64 rlen __packed __aligned(4);
28062306a36Sopenharmony_ci	__le64 rp __packed __aligned(4);
28162306a36Sopenharmony_ci	__le64 wp __packed __aligned(4);
28262306a36Sopenharmony_ci};
28362306a36Sopenharmony_ci
28462306a36Sopenharmony_cistruct mhi_cmd_ctxt {
28562306a36Sopenharmony_ci	__le32 reserved0;
28662306a36Sopenharmony_ci	__le32 reserved1;
28762306a36Sopenharmony_ci	__le32 reserved2;
28862306a36Sopenharmony_ci
28962306a36Sopenharmony_ci	__le64 rbase __packed __aligned(4);
29062306a36Sopenharmony_ci	__le64 rlen __packed __aligned(4);
29162306a36Sopenharmony_ci	__le64 rp __packed __aligned(4);
29262306a36Sopenharmony_ci	__le64 wp __packed __aligned(4);
29362306a36Sopenharmony_ci};
29462306a36Sopenharmony_ci
29562306a36Sopenharmony_cistruct mhi_ring_element {
29662306a36Sopenharmony_ci	__le64 ptr;
29762306a36Sopenharmony_ci	__le32 dword[2];
29862306a36Sopenharmony_ci};
29962306a36Sopenharmony_ci
30062306a36Sopenharmony_cistatic inline const char *mhi_state_str(enum mhi_state state)
30162306a36Sopenharmony_ci{
30262306a36Sopenharmony_ci	switch (state) {
30362306a36Sopenharmony_ci	case MHI_STATE_RESET:
30462306a36Sopenharmony_ci		return "RESET";
30562306a36Sopenharmony_ci	case MHI_STATE_READY:
30662306a36Sopenharmony_ci		return "READY";
30762306a36Sopenharmony_ci	case MHI_STATE_M0:
30862306a36Sopenharmony_ci		return "M0";
30962306a36Sopenharmony_ci	case MHI_STATE_M1:
31062306a36Sopenharmony_ci		return "M1";
31162306a36Sopenharmony_ci	case MHI_STATE_M2:
31262306a36Sopenharmony_ci		return "M2";
31362306a36Sopenharmony_ci	case MHI_STATE_M3:
31462306a36Sopenharmony_ci		return "M3";
31562306a36Sopenharmony_ci	case MHI_STATE_M3_FAST:
31662306a36Sopenharmony_ci		return "M3 FAST";
31762306a36Sopenharmony_ci	case MHI_STATE_BHI:
31862306a36Sopenharmony_ci		return "BHI";
31962306a36Sopenharmony_ci	case MHI_STATE_SYS_ERR:
32062306a36Sopenharmony_ci		return "SYS ERROR";
32162306a36Sopenharmony_ci	default:
32262306a36Sopenharmony_ci		return "Unknown state";
32362306a36Sopenharmony_ci	}
32462306a36Sopenharmony_ci};
32562306a36Sopenharmony_ci
32662306a36Sopenharmony_ci#endif /* _MHI_COMMON_H */
327