1 /* SPDX-License-Identifier: GPL-2.0-only
3 * Copyright (C) 2020-21 Intel Corporation.
9 #include "iosm_ipc_protocol.h"
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
15 /* Size of the buffer for the IP MUX Lite data buffer. */
16 #define IPC_MEM_MAX_DL_MUX_LITE_BUF_SIZE (2 * 1024)
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
22 /* open session request (AP->CP) */
23 #define MUX_CMD_OPEN_SESSION 1
25 /* response to open session request (CP->AP) */
26 #define MUX_CMD_OPEN_SESSION_RESP 2
28 /* close session request (AP->CP) */
29 #define MUX_CMD_CLOSE_SESSION 3
31 /* response to close session request (CP->AP) */
32 #define MUX_CMD_CLOSE_SESSION_RESP 4
34 /* Flow control command with mask of the flow per queue/flow. */
35 #define MUX_LITE_CMD_FLOW_CTL 5
37 /* ACK the flow control command. Shall have the same Transaction ID as the
38 * matching FLOW_CTL command.
40 #define MUX_LITE_CMD_FLOW_CTL_ACK 6
42 /* Command for report packet indicating link quality metrics. */
43 #define MUX_LITE_CMD_LINK_STATUS_REPORT 7
45 /* Response to a report packet */
46 #define MUX_LITE_CMD_LINK_STATUS_REPORT_RESP 8
48 /* Used to reset a command/response state. */
49 #define MUX_CMD_INVALID 255
51 /* command response : command processed successfully */
52 #define MUX_CMD_RESP_SUCCESS 0
54 /* MUX for route link devices */
55 #define IPC_MEM_WWAN_MUX BIT(0)
57 /* Initiated actions to change the state of the MUX object. */
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. */
67 /* MUX session open command. */
68 struct mux_session_open {
73 /* MUX session close command. */
74 struct mux_session_close {
79 /* MUX channel close command. */
80 struct mux_channel_close {
84 /* Default message type to find out the right message type. */
89 /* List of ops in MUX mode. */
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;
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. */
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.*/
120 /* Parameter definition of the close session response code */
121 struct mux_cmd_close_session_resp {
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 */
131 /* Parameter definition of the link status report code*/
132 struct mux_cmd_link_status_report {
136 /* Parameter definition of the link status report response code. */
137 struct mux_cmd_link_status_report_resp {
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
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;
159 /* States of the MUX object.. */
161 MUX_S_INACTIVE, /* IP MUX is unused. */
162 MUX_S_ACTIVE, /* IP MUX channel is available. */
163 MUX_S_ERROR, /* Defect IP MUX. */
166 /* Supported MUX protocols. */
167 enum ipc_mux_protocol {
172 /* Supported UL data transfer methods. */
173 enum ipc_mux_ul_flow {
175 MUX_UL, /* Normal UL data transfer */
176 MUX_UL_ON_CREDITS, /* UL data transfer will be based on credits */
179 /* List of the MUX session. */
181 struct iosm_wwan *wwan; /*Network i/f used for communication*/
182 int if_id; /* i/f id for session open message.*/
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 */
192 flush:1; /* flush net interface ? */
195 /* State of a single UL data block. */
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 */
209 /* Temporary ACB state. */
211 struct sk_buff *skb; /* Used UL skb. */
212 int if_id; /* Session id. */
216 union mux_cmd_param got_param; /* Received command/response parameter */
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
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
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;
259 enum ipc_mux_protocol protocol;
260 enum ipc_mux_ul_flow ul_flow;
263 enum mux_state state;
264 enum mux_event event;
265 u32 tx_transaction_id;
267 struct mux_adb ul_adb;
269 long long ul_data_pend_bytes;
273 ev_mux_net_transmit_pending:1,
277 /* MUX configuration structure */
278 struct ipc_mux_config {
279 enum ipc_mux_protocol protocol;
280 enum ipc_mux_ul_flow ul_flow;
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
290 * Returns: Initialized mux pointer on success else NULL
292 struct iosm_mux *ipc_mux_init(struct ipc_mux_config *mux_cfg,
293 struct iosm_imem *ipc_imem);
296 * ipc_mux_deinit - Deallocates MUX instance
297 * @ipc_mux: Pointer to the MUX instance.
299 void ipc_mux_deinit(struct iosm_mux *ipc_mux);
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
307 void ipc_mux_check_n_restart_tx(struct iosm_mux *ipc_mux);
310 * ipc_mux_get_active_protocol - Returns the active MUX protocol type.
311 * @ipc_mux: Pointer to MUX data-struct
313 * Returns: enum of type ipc_mux_protocol
315 enum ipc_mux_protocol ipc_mux_get_active_protocol(struct iosm_mux *ipc_mux);
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
322 * Returns: channel id on success, failure value on error
324 int ipc_mux_open_session(struct iosm_mux *ipc_mux, int session_nr);
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
331 * Returns: channel id on success, failure value on error
333 int ipc_mux_close_session(struct iosm_mux *ipc_mux, int session_nr);
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
340 * Returns: Number of sessions supported on Success and failure value on error
342 int ipc_mux_get_max_sessions(struct iosm_mux *ipc_mux);