• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* SPDX-License-Identifier: GPL-2.0-only
2  *
3  * Copyright (C) 2020-21 Intel Corporation.
4  */
5 
6 #ifndef IOSM_IPC_MUX_H
7 #define IOSM_IPC_MUX_H
8 
9 #include "iosm_ipc_protocol.h"
10 
11 /* Size of the buffer for the IP MUX data buffer. */
12 #define IPC_MEM_MAX_DL_MUX_BUF_SIZE (16 * 1024)
13 #define IPC_MEM_MAX_UL_ADB_BUF_SIZE IPC_MEM_MAX_DL_MUX_BUF_SIZE
14 
15 /* Size of the buffer for the IP MUX Lite data buffer. */
16 #define IPC_MEM_MAX_DL_MUX_LITE_BUF_SIZE (2 * 1024)
17 
18 /* TD counts for IP MUX Lite */
19 #define IPC_MEM_MAX_TDS_MUX_LITE_UL 800
20 #define IPC_MEM_MAX_TDS_MUX_LITE_DL 1200
21 
22 /* open session request (AP->CP) */
23 #define MUX_CMD_OPEN_SESSION 1
24 
25 /* response to open session request (CP->AP) */
26 #define MUX_CMD_OPEN_SESSION_RESP 2
27 
28 /* close session request (AP->CP) */
29 #define MUX_CMD_CLOSE_SESSION 3
30 
31 /* response to close session request (CP->AP) */
32 #define MUX_CMD_CLOSE_SESSION_RESP 4
33 
34 /* Flow control command with mask of the flow per queue/flow. */
35 #define MUX_LITE_CMD_FLOW_CTL 5
36 
37 /* ACK the flow control command. Shall have the same Transaction ID as the
38  * matching FLOW_CTL command.
39  */
40 #define MUX_LITE_CMD_FLOW_CTL_ACK 6
41 
42 /* Command for report packet indicating link quality metrics. */
43 #define MUX_LITE_CMD_LINK_STATUS_REPORT 7
44 
45 /* Response to a report packet */
46 #define MUX_LITE_CMD_LINK_STATUS_REPORT_RESP 8
47 
48 /* Used to reset a command/response state. */
49 #define MUX_CMD_INVALID 255
50 
51 /* command response : command processed successfully */
52 #define MUX_CMD_RESP_SUCCESS 0
53 
54 /* MUX for route link devices */
55 #define IPC_MEM_WWAN_MUX BIT(0)
56 
57 /* Initiated actions to change the state of the MUX object. */
58 enum mux_event {
59 	MUX_E_INACTIVE, /* No initiated actions. */
60 	MUX_E_MUX_SESSION_OPEN, /* Create the MUX channel and a session. */
61 	MUX_E_MUX_SESSION_CLOSE, /* Release a session. */
62 	MUX_E_MUX_CHANNEL_CLOSE, /* Release the MUX channel. */
63 	MUX_E_NO_ORDERS, /* No MUX order. */
64 	MUX_E_NOT_APPLICABLE, /* Defect IP MUX. */
65 };
66 
67 /* MUX session open command. */
68 struct mux_session_open {
69 	enum mux_event event;
70 	__le32 if_id;
71 };
72 
73 /* MUX session close command. */
74 struct mux_session_close {
75 	enum mux_event event;
76 	__le32 if_id;
77 };
78 
79 /* MUX channel close command. */
80 struct mux_channel_close {
81 	enum mux_event event;
82 };
83 
84 /* Default message type to find out the right message type. */
85 struct mux_common {
86 	enum mux_event event;
87 };
88 
89 /* List of ops in MUX mode. */
90 union mux_msg {
91 	struct mux_session_open session_open;
92 	struct mux_session_close session_close;
93 	struct mux_channel_close channel_close;
94 	struct mux_common common;
95 };
96 
97 /* Parameter definition of the open session command. */
98 struct mux_cmd_open_session {
99 	u8 flow_ctrl; /* 0: Flow control disabled (flow allowed). */
100 	/* 1: Flow control enabled (flow not allowed)*/
101 	u8 ipv4v6_hints; /* 0: IPv4/IPv6 hints not supported.*/
102 	/* 1: IPv4/IPv6 hints supported*/
103 	__le16 reserved2; /* Reserved. Set to zero. */
104 	__le32 dl_head_pad_len; /* Maximum length supported */
105 	/* for DL head padding on a datagram. */
106 };
107 
108 /* Parameter definition of the open session response. */
109 struct mux_cmd_open_session_resp {
110 	__le32 response; /* Response code */
111 	u8 flow_ctrl; /* 0: Flow control disabled (flow allowed). */
112 	/* 1: Flow control enabled (flow not allowed) */
113 	u8 ipv4v6_hints; /* 0: IPv4/IPv6 hints not supported */
114 	/* 1: IPv4/IPv6 hints supported */
115 	__le16 reserved2; /* Reserved. Set to zero. */
116 	__le32 ul_head_pad_len; /* Actual length supported for */
117 	/* UL head padding on adatagram.*/
118 };
119 
120 /* Parameter definition of the close session response code */
121 struct mux_cmd_close_session_resp {
122 	__le32 response;
123 };
124 
125 /* Parameter definition of the flow control command. */
126 struct mux_cmd_flow_ctl {
127 	__le32 mask; /* indicating the desired flow control */
128 	/* state for various flows/queues */
129 };
130 
131 /* Parameter definition of the link status report code*/
132 struct mux_cmd_link_status_report {
133 	u8 payload;
134 };
135 
136 /* Parameter definition of the link status report response code. */
137 struct mux_cmd_link_status_report_resp {
138 	__le32 response;
139 };
140 
141 /**
142  * union mux_cmd_param - Union-definition of the command parameters.
143  * @open_session:	Inband command for open session
144  * @open_session_resp:	Inband command for open session response
145  * @close_session_resp:	Inband command for close session response
146  * @flow_ctl:		In-band flow control on the opened interfaces
147  * @link_status:	In-band Link Status Report
148  * @link_status_resp:	In-band command for link status report response
149  */
150 union mux_cmd_param {
151 	struct mux_cmd_open_session open_session;
152 	struct mux_cmd_open_session_resp open_session_resp;
153 	struct mux_cmd_close_session_resp close_session_resp;
154 	struct mux_cmd_flow_ctl flow_ctl;
155 	struct mux_cmd_link_status_report link_status;
156 	struct mux_cmd_link_status_report_resp link_status_resp;
157 };
158 
159 /* States of the MUX object.. */
160 enum mux_state {
161 	MUX_S_INACTIVE, /* IP MUX is unused. */
162 	MUX_S_ACTIVE, /* IP MUX channel is available. */
163 	MUX_S_ERROR, /* Defect IP MUX. */
164 };
165 
166 /* Supported MUX protocols. */
167 enum ipc_mux_protocol {
168 	MUX_UNKNOWN,
169 	MUX_LITE,
170 };
171 
172 /* Supported UL data transfer methods. */
173 enum ipc_mux_ul_flow {
174 	MUX_UL_UNKNOWN,
175 	MUX_UL, /* Normal UL data transfer */
176 	MUX_UL_ON_CREDITS, /* UL data transfer will be based on credits */
177 };
178 
179 /* List of the MUX session. */
180 struct mux_session {
181 	struct iosm_wwan *wwan; /*Network i/f used for communication*/
182 	int if_id; /* i/f id for session open message.*/
183 	u32 flags;
184 	u32 ul_head_pad_len; /* Nr of bytes for UL head padding. */
185 	u32 dl_head_pad_len; /* Nr of bytes for DL head padding. */
186 	struct sk_buff_head ul_list; /* skb entries for an ADT. */
187 	u32 flow_ctl_mask; /* UL flow control */
188 	u32 flow_ctl_en_cnt; /* Flow control Enable cmd count */
189 	u32 flow_ctl_dis_cnt; /* Flow Control Disable cmd count */
190 	int ul_flow_credits; /* UL flow credits */
191 	u8 net_tx_stop:1,
192 	   flush:1; /* flush net interface ? */
193 };
194 
195 /* State of a single UL data block. */
196 struct mux_adb {
197 	struct sk_buff *dest_skb; /* Current UL skb for the data block. */
198 	u8 *buf; /* ADB memory. */
199 	struct mux_adgh *adgh; /* ADGH pointer */
200 	struct sk_buff *qlth_skb; /* QLTH pointer */
201 	u32 *next_table_index; /* Pointer to next table index. */
202 	struct sk_buff_head free_list; /* List of alloc. ADB for the UL sess.*/
203 	int size; /* Size of the ADB memory. */
204 	u32 if_cnt; /* Statistic counter */
205 	u32 dg_cnt_total;
206 	u32 payload_size;
207 };
208 
209 /* Temporary ACB state. */
210 struct mux_acb {
211 	struct sk_buff *skb; /* Used UL skb. */
212 	int if_id; /* Session id. */
213 	u32 wanted_response;
214 	u32 got_response;
215 	u32 cmd;
216 	union mux_cmd_param got_param; /* Received command/response parameter */
217 };
218 
219 /**
220  * struct iosm_mux - Structure of the data multiplexing over an IP channel.
221  * @dev:		Pointer to device structure
222  * @session:		Array of the MUX sessions.
223  * @channel:		Reference to the IP MUX channel
224  * @pcie:		Pointer to iosm_pcie struct
225  * @imem:		Pointer to iosm_imem
226  * @wwan:		Poinetr to iosm_wwan
227  * @ipc_protocol:	Pointer to iosm_protocol
228  * @channel_id:		Channel ID for MUX
229  * @protocol:		Type of the MUX protocol
230  * @ul_flow:		UL Flow type
231  * @nr_sessions:	Number of sessions
232  * @instance_id:	Instance ID
233  * @state:		States of the MUX object
234  * @event:		Initiated actions to change the state of the MUX object
235  * @tx_transaction_id:	Transaction id for the ACB command.
236  * @rr_next_session:	Next session number for round robin.
237  * @ul_adb:		State of the UL ADB/ADGH.
238  * @size_needed:	Variable to store the size needed during ADB preparation
239  * @ul_data_pend_bytes:	Pending UL data to be processed in bytes
240  * @acb:		Temporary ACB state
241  * @wwan_q_offset:	This will hold the offset of the given instance
242  *			Useful while passing or receiving packets from
243  *			wwan/imem layer.
244  * @initialized:	MUX object is initialized
245  * @ev_mux_net_transmit_pending:
246  *			0 means inform the IPC tasklet to pass the
247  *			accumulated uplink ADB to CP.
248  * @adb_prep_ongoing:	Flag for ADB preparation status
249  */
250 struct iosm_mux {
251 	struct device *dev;
252 	struct mux_session session[IPC_MEM_MUX_IP_SESSION_ENTRIES];
253 	struct ipc_mem_channel *channel;
254 	struct iosm_pcie *pcie;
255 	struct iosm_imem *imem;
256 	struct iosm_wwan *wwan;
257 	struct iosm_protocol *ipc_protocol;
258 	int channel_id;
259 	enum ipc_mux_protocol protocol;
260 	enum ipc_mux_ul_flow ul_flow;
261 	int nr_sessions;
262 	int instance_id;
263 	enum mux_state state;
264 	enum mux_event event;
265 	u32 tx_transaction_id;
266 	int rr_next_session;
267 	struct mux_adb ul_adb;
268 	int size_needed;
269 	long long ul_data_pend_bytes;
270 	struct mux_acb acb;
271 	int wwan_q_offset;
272 	u8 initialized:1,
273 	   ev_mux_net_transmit_pending:1,
274 	   adb_prep_ongoing:1;
275 };
276 
277 /* MUX configuration structure */
278 struct ipc_mux_config {
279 	enum ipc_mux_protocol protocol;
280 	enum ipc_mux_ul_flow ul_flow;
281 	int nr_sessions;
282 	int instance_id;
283 };
284 
285 /**
286  * ipc_mux_init - Allocates and Init MUX instance
287  * @mux_cfg:	Pointer to MUX configuration structure
288  * @ipc_imem:	Pointer to imem data-struct
289  *
290  * Returns: Initialized mux pointer on success else NULL
291  */
292 struct iosm_mux *ipc_mux_init(struct ipc_mux_config *mux_cfg,
293 			      struct iosm_imem *ipc_imem);
294 
295 /**
296  * ipc_mux_deinit - Deallocates MUX instance
297  * @ipc_mux:	Pointer to the MUX instance.
298  */
299 void ipc_mux_deinit(struct iosm_mux *ipc_mux);
300 
301 /**
302  * ipc_mux_check_n_restart_tx - Checks for pending UL date bytes and then
303  *				it restarts the net interface tx queue if
304  *				device has set flow control as off.
305  * @ipc_mux:	Pointer to MUX data-struct
306  */
307 void ipc_mux_check_n_restart_tx(struct iosm_mux *ipc_mux);
308 
309 /**
310  * ipc_mux_get_active_protocol - Returns the active MUX protocol type.
311  * @ipc_mux:	Pointer to MUX data-struct
312  *
313  * Returns: enum of type ipc_mux_protocol
314  */
315 enum ipc_mux_protocol ipc_mux_get_active_protocol(struct iosm_mux *ipc_mux);
316 
317 /**
318  * ipc_mux_open_session - Opens a MUX session for IP traffic.
319  * @ipc_mux:	Pointer to MUX data-struct
320  * @session_nr:	Interface ID or session number
321  *
322  * Returns: channel id on success, failure value on error
323  */
324 int ipc_mux_open_session(struct iosm_mux *ipc_mux, int session_nr);
325 
326 /**
327  * ipc_mux_close_session - Closes a MUX session.
328  * @ipc_mux:	Pointer to MUX data-struct
329  * @session_nr:	Interface ID or session number
330  *
331  * Returns: channel id on success, failure value on error
332  */
333 int ipc_mux_close_session(struct iosm_mux *ipc_mux, int session_nr);
334 
335 /**
336  * ipc_mux_get_max_sessions - Retuns the maximum sessions supported on the
337  *			      provided MUX instance..
338  * @ipc_mux:	Pointer to MUX data-struct
339  *
340  * Returns: Number of sessions supported on Success and failure value on error
341  */
342 int ipc_mux_get_max_sessions(struct iosm_mux *ipc_mux);
343 #endif
344