xref: /linux/drivers/net/ipa/ipa.h (revision 8defab8bdfb1d0dc4e4e3c687cfde33b596896f7)
1 /* SPDX-License-Identifier: GPL-2.0 */
2 
3 /* Copyright (c) 2012-2018, The Linux Foundation. All rights reserved.
4  * Copyright (C) 2018-2022 Linaro Ltd.
5  */
6 #ifndef _IPA_H_
7 #define _IPA_H_
8 
9 #include <linux/types.h>
10 #include <linux/device.h>
11 #include <linux/notifier.h>
12 #include <linux/pm_wakeup.h>
13 
14 #include "ipa_version.h"
15 #include "gsi.h"
16 #include "ipa_mem.h"
17 #include "ipa_qmi.h"
18 #include "ipa_endpoint.h"
19 #include "ipa_interrupt.h"
20 
21 struct clk;
22 struct icc_path;
23 struct net_device;
24 struct platform_device;
25 
26 struct ipa_power;
27 struct ipa_smp2p;
28 struct ipa_interrupt;
29 
30 /**
31  * struct ipa - IPA information
32  * @gsi:		Embedded GSI structure
33  * @version:		IPA hardware version
34  * @pdev:		Platform device
35  * @completion:		Used to signal pipeline clear transfer complete
36  * @nb:			Notifier block used for remoteproc SSR
37  * @notifier:		Remoteproc SSR notifier
38  * @smp2p:		SMP2P information
39  * @power:		IPA power information
40  * @table_addr:		DMA address of filter/route table content
41  * @table_virt:		Virtual address of filter/route table content
42  * @route_count:	Total number of entries in a routing table
43  * @modem_route_count:	Number of modem entries in a routing table
44  * @interrupt:		IPA Interrupt information
45  * @uc_powered:		true if power is active by proxy for microcontroller
46  * @uc_loaded:		true after microcontroller has reported it's ready
47  * @reg_addr:		DMA address used for IPA register access
48  * @reg_virt:		Virtual address used for IPA register access
49  * @regs:		IPA register definitions
50  * @mem_addr:		DMA address of IPA-local memory space
51  * @mem_virt:		Virtual address of IPA-local memory space
52  * @mem_offset:		Offset from @mem_virt used for access to IPA memory
53  * @mem_size:		Total size (bytes) of memory at @mem_virt
54  * @mem_count:		Number of entries in the mem array
55  * @mem:		Array of IPA-local memory region descriptors
56  * @imem_iova:		I/O virtual address of IPA region in IMEM
57  * @imem_size:		Size of IMEM region
58  * @smem_iova:		I/O virtual address of IPA region in SMEM
59  * @smem_size:		Size of SMEM region
60  * @zero_addr:		DMA address of preallocated zero-filled memory
61  * @zero_virt:		Virtual address of preallocated zero-filled memory
62  * @zero_size:		Size (bytes) of preallocated zero-filled memory
63  * @available:		Bit mask indicating endpoints hardware supports
64  * @filter_map:		Bit mask indicating endpoints that support filtering
65  * @initialized:	Bit mask indicating endpoints initialized
66  * @set_up:		Bit mask indicating endpoints set up
67  * @enabled:		Bit mask indicating endpoints enabled
68  * @modem_tx_count:	Number of defined modem TX endoints
69  * @endpoint:		Array of endpoint information
70  * @channel_map:	Mapping of GSI channel to IPA endpoint
71  * @name_map:		Mapping of IPA endpoint name to IPA endpoint
72  * @setup_complete:	Flag indicating whether setup stage has completed
73  * @modem_state:	State of modem (stopped, running)
74  * @modem_netdev:	Network device structure used for modem
75  * @qmi:		QMI information
76  */
77 struct ipa {
78 	struct gsi gsi;
79 	enum ipa_version version;
80 	struct platform_device *pdev;
81 	struct completion completion;
82 	struct notifier_block nb;
83 	void *notifier;
84 	struct ipa_smp2p *smp2p;
85 	struct ipa_power *power;
86 
87 	dma_addr_t table_addr;
88 	__le64 *table_virt;
89 	u32 route_count;
90 	u32 modem_route_count;
91 
92 	struct ipa_interrupt *interrupt;
93 	bool uc_powered;
94 	bool uc_loaded;
95 
96 	dma_addr_t reg_addr;
97 	void __iomem *reg_virt;
98 	const struct ipa_regs *regs;
99 
100 	dma_addr_t mem_addr;
101 	void *mem_virt;
102 	u32 mem_offset;
103 	u32 mem_size;
104 	u32 mem_count;
105 	const struct ipa_mem *mem;
106 
107 	unsigned long imem_iova;
108 	size_t imem_size;
109 
110 	unsigned long smem_iova;
111 	size_t smem_size;
112 
113 	dma_addr_t zero_addr;
114 	void *zero_virt;
115 	size_t zero_size;
116 
117 	/* Bit masks indicating endpoint state */
118 	u32 available;		/* supported by hardware */
119 	u32 filter_map;
120 	u32 initialized;
121 	u32 set_up;
122 	u32 enabled;
123 
124 	u32 modem_tx_count;
125 	struct ipa_endpoint endpoint[IPA_ENDPOINT_MAX];
126 	struct ipa_endpoint *channel_map[GSI_CHANNEL_COUNT_MAX];
127 	struct ipa_endpoint *name_map[IPA_ENDPOINT_COUNT];
128 
129 	bool setup_complete;
130 
131 	atomic_t modem_state;		/* enum ipa_modem_state */
132 	struct net_device *modem_netdev;
133 	struct ipa_qmi qmi;
134 };
135 
136 /**
137  * ipa_setup() - Perform IPA setup
138  * @ipa:		IPA pointer
139  *
140  * IPA initialization is broken into stages:  init; config; and setup.
141  * (These have inverses exit, deconfig, and teardown.)
142  *
143  * Activities performed at the init stage can be done without requiring
144  * any access to IPA hardware.  Activities performed at the config stage
145  * require IPA power, because they involve access to IPA registers.
146  * The setup stage is performed only after the GSI hardware is ready
147  * (more on this below).  The setup stage allows the AP to perform
148  * more complex initialization by issuing "immediate commands" using
149  * a special interface to the IPA.
150  *
151  * This function, @ipa_setup(), starts the setup stage.
152  *
153  * In order for the GSI hardware to be functional it needs firmware to be
154  * loaded (in addition to some other low-level initialization).  This early
155  * GSI initialization can be done either by Trust Zone on the AP or by the
156  * modem.
157  *
158  * If it's done by Trust Zone, the AP loads the GSI firmware and supplies
159  * it to Trust Zone to verify and install.  When this completes, if
160  * verification was successful, the GSI layer is ready and ipa_setup()
161  * implements the setup phase of initialization.
162  *
163  * If the modem performs early GSI initialization, the AP needs to know
164  * when this has occurred.  An SMP2P interrupt is used for this purpose,
165  * and receipt of that interrupt triggers the call to ipa_setup().
166  */
167 int ipa_setup(struct ipa *ipa);
168 
169 #endif /* _IPA_H_ */
170