xref: /linux/drivers/net/wwan/iosm/iosm_ipc_protocol.h (revision 46466ae3a105d9620e1355e33125a413b8c6ce18)
1 /* SPDX-License-Identifier: GPL-2.0-only
2  *
3  * Copyright (C) 2020-21 Intel Corporation.
4  */
5 
6 #ifndef IOSM_IPC_PROTOCOL_H
7 #define IOSM_IPC_PROTOCOL_H
8 
9 #include "iosm_ipc_imem.h"
10 #include "iosm_ipc_pm.h"
11 #include "iosm_ipc_protocol_ops.h"
12 
13 /* Trigger the doorbell interrupt on CP. */
14 #define IPC_DOORBELL_IRQ_HPDA 0
15 #define IPC_DOORBELL_IRQ_IPC 1
16 #define IPC_DOORBELL_IRQ_SLEEP 2
17 
18 /* IRQ vector number. */
19 #define IPC_DEVICE_IRQ_VECTOR 0
20 #define IPC_MSG_IRQ_VECTOR 0
21 #define IPC_UL_PIPE_IRQ_VECTOR 0
22 #define IPC_DL_PIPE_IRQ_VECTOR 0
23 
24 #define IPC_MEM_MSG_ENTRIES 128
25 
26 /* Default time out for sending IPC messages like open pipe, close pipe etc.
27  * during run mode.
28  *
29  * If the message interface lock to CP times out, the link to CP is broken.
30  * mode : run mode (IPC_MEM_EXEC_STAGE_RUN)
31  * unit : milliseconds
32  */
33 #define IPC_MSG_COMPLETE_RUN_DEFAULT_TIMEOUT 500 /* 0.5 seconds */
34 
35 /* Default time out for sending IPC messages like open pipe, close pipe etc.
36  * during boot mode.
37  *
38  * If the message interface lock to CP times out, the link to CP is broken.
39  * mode : boot mode
40  * (IPC_MEM_EXEC_STAGE_BOOT | IPC_MEM_EXEC_STAGE_PSI | IPC_MEM_EXEC_STAGE_EBL)
41  * unit : milliseconds
42  */
43 #define IPC_MSG_COMPLETE_BOOT_DEFAULT_TIMEOUT 500 /* 0.5 seconds */
44 
45 /**
46  * struct ipc_protocol_context_info - Structure of the context info
47  * @device_info_addr:		64 bit address to device info
48  * @head_array:			64 bit address to head pointer arr for the pipes
49  * @tail_array:			64 bit address to tail pointer arr for the pipes
50  * @msg_head:			64 bit address to message head pointer
51  * @msg_tail:			64 bit address to message tail pointer
52  * @msg_ring_addr:		64 bit pointer to the message ring buffer
53  * @msg_ring_entries:		This field provides the number of entries which
54  *				the MR can hold
55  * @msg_irq_vector:		This field provides the IRQ which shall be
56  *				generated by the EP device when generating
57  *				completion for Messages.
58  * @device_info_irq_vector:	This field provides the IRQ which shall be
59  *				generated by the EP dev after updating Dev. Info
60  */
61 struct ipc_protocol_context_info {
62 	phys_addr_t device_info_addr;
63 	phys_addr_t head_array;
64 	phys_addr_t tail_array;
65 	phys_addr_t msg_head;
66 	phys_addr_t msg_tail;
67 	phys_addr_t msg_ring_addr;
68 	__le16 msg_ring_entries;
69 	u8 msg_irq_vector;
70 	u8 device_info_irq_vector;
71 };
72 
73 /**
74  * struct ipc_protocol_device_info - Structure for the device information
75  * @execution_stage:		CP execution stage
76  * @ipc_status:			IPC states
77  * @device_sleep_notification:	Requested device pm states
78  */
79 struct ipc_protocol_device_info {
80 	__le32 execution_stage;
81 	__le32 ipc_status;
82 	__le32 device_sleep_notification;
83 };
84 
85 /**
86  * struct ipc_protocol_ap_shm - Protocol Shared Memory Structure
87  * @ci:			Context information struct
88  * @device_info:	Device information struct
89  * @msg_head:		Point to msg head
90  * @head_array:		Array of head pointer
91  * @msg_tail:		Point to msg tail
92  * @tail_array:		Array of tail pointer
93  * @msg_ring:		Circular buffers for the read/tail and write/head
94  *			indeces.
95  */
96 struct ipc_protocol_ap_shm {
97 	struct ipc_protocol_context_info ci;
98 	struct ipc_protocol_device_info device_info;
99 	__le32 msg_head;
100 	__le32 head_array[IPC_MEM_MAX_PIPES];
101 	__le32 msg_tail;
102 	__le32 tail_array[IPC_MEM_MAX_PIPES];
103 	union ipc_mem_msg_entry msg_ring[IPC_MEM_MSG_ENTRIES];
104 };
105 
106 /**
107  * struct iosm_protocol - Structure for IPC protocol.
108  * @p_ap_shm:		Pointer to Protocol Shared Memory Structure
109  * @pm:			Instance to struct iosm_pm
110  * @pcie:		Pointer to struct iosm_pcie
111  * @imem:		Pointer to struct iosm_imem
112  * @rsp_ring:		Array of OS completion objects to be triggered once CP
113  *			acknowledges a request in the message ring
114  * @dev:		Pointer to device structure
115  * @phy_ap_shm:		Physical/Mapped representation of the shared memory info
116  * @old_msg_tail:	Old msg tail ptr, until AP has handled ACK's from CP
117  */
118 struct iosm_protocol {
119 	struct ipc_protocol_ap_shm *p_ap_shm;
120 	struct iosm_pm pm;
121 	struct iosm_pcie *pcie;
122 	struct iosm_imem *imem;
123 	struct ipc_rsp *rsp_ring[IPC_MEM_MSG_ENTRIES];
124 	struct device *dev;
125 	phys_addr_t phy_ap_shm;
126 	u32 old_msg_tail;
127 };
128 
129 /**
130  * struct ipc_call_msg_send_args - Structure for message argument for
131  *				   tasklet function.
132  * @prep_args:		Arguments for message preparation function
133  * @response:		Can be NULL if result can be ignored
134  * @msg_type:		Message Type
135  */
136 struct ipc_call_msg_send_args {
137 	union ipc_msg_prep_args *prep_args;
138 	struct ipc_rsp *response;
139 	enum ipc_msg_prep_type msg_type;
140 };
141 
142 /**
143  * ipc_protocol_tq_msg_send - prepare the msg and send to CP
144  * @ipc_protocol:	Pointer to ipc_protocol instance
145  * @msg_type:		Message type
146  * @prep_args:		Message arguments
147  * @response:		Pointer to a response object which has a
148  *			completion object and return code.
149  *
150  * Returns: 0 on success and failure value on error
151  */
152 int ipc_protocol_tq_msg_send(struct iosm_protocol *ipc_protocol,
153 			     enum ipc_msg_prep_type msg_type,
154 			     union ipc_msg_prep_args *prep_args,
155 			     struct ipc_rsp *response);
156 
157 /**
158  * ipc_protocol_msg_send - Send ipc control message to CP and wait for response
159  * @ipc_protocol:	Pointer to ipc_protocol instance
160  * @prep:		Message type
161  * @prep_args:		Message arguments
162  *
163  * Returns: 0 on success and failure value on error
164  */
165 int ipc_protocol_msg_send(struct iosm_protocol *ipc_protocol,
166 			  enum ipc_msg_prep_type prep,
167 			  union ipc_msg_prep_args *prep_args);
168 
169 /**
170  * ipc_protocol_suspend - Signal to CP that host wants to go to sleep (suspend).
171  * @ipc_protocol:	Pointer to ipc_protocol instance
172  *
173  * Returns: true if host can suspend, false if suspend must be aborted.
174  */
175 bool ipc_protocol_suspend(struct iosm_protocol *ipc_protocol);
176 
177 /**
178  * ipc_protocol_s2idle_sleep - Call PM function to set PM variables in s2idle
179  *			       sleep/active case
180  * @ipc_protocol:	Pointer to ipc_protocol instance
181  * @sleep:		True for sleep/False for active
182  */
183 void ipc_protocol_s2idle_sleep(struct iosm_protocol *ipc_protocol, bool sleep);
184 
185 /**
186  * ipc_protocol_resume - Signal to CP that host wants to resume operation.
187  * @ipc_protocol:	Pointer to ipc_protocol instance
188  *
189  * Returns: true if host can resume, false if there is a problem.
190  */
191 bool ipc_protocol_resume(struct iosm_protocol *ipc_protocol);
192 
193 /**
194  * ipc_protocol_pm_dev_sleep_handle - Handles the Device Sleep state change
195  *				      notification.
196  * @ipc_protocol:	Pointer to ipc_protocol instance.
197  *
198  * Returns: true if sleep notification handled, false otherwise.
199  */
200 bool ipc_protocol_pm_dev_sleep_handle(struct iosm_protocol *ipc_protocol);
201 
202 /**
203  * ipc_protocol_doorbell_trigger - Wrapper for PM function which wake up the
204  *				   device if it is in low power mode
205  *				   and trigger a head pointer update interrupt.
206  * @ipc_protocol:	Pointer to ipc_protocol instance.
207  * @identifier:		Specifies what component triggered hpda
208  *			update irq
209  */
210 void ipc_protocol_doorbell_trigger(struct iosm_protocol *ipc_protocol,
211 				   u32 identifier);
212 
213 /**
214  * ipc_protocol_sleep_notification_string - Returns last Sleep Notification as
215  *					    string.
216  * @ipc_protocol:	Instance pointer of Protocol module.
217  *
218  * Returns: Pointer to string.
219  */
220 const char *
221 ipc_protocol_sleep_notification_string(struct iosm_protocol *ipc_protocol);
222 
223 /**
224  * ipc_protocol_init - Allocates IPC protocol instance
225  * @ipc_imem:		Pointer to iosm_imem structure
226  *
227  * Returns: Address of IPC  protocol instance on success & NULL on failure.
228  */
229 struct iosm_protocol *ipc_protocol_init(struct iosm_imem *ipc_imem);
230 
231 /**
232  * ipc_protocol_deinit - Deallocates IPC protocol instance
233  * @ipc_protocol:	pointer to the IPC protocol instance
234  */
235 void ipc_protocol_deinit(struct iosm_protocol *ipc_protocol);
236 
237 #endif
238