1 /* SPDX-License-Identifier: GPL-2.0-only
3 * Copyright (C) 2020-21 Intel Corporation.
9 #include "iosm_ipc_protocol.h"
11 #define IPC_MEM_MAX_UL_DG_ENTRIES 100
12 #define IPC_MEM_MAX_TDS_MUX_AGGR_UL 60
14 #define IPC_MEM_MAX_ADB_BUF_SIZE (16 * 1024)
15 #define IPC_MEM_MAX_UL_ADB_BUF_SIZE IPC_MEM_MAX_ADB_BUF_SIZE
16 #define IPC_MEM_MAX_DL_ADB_BUF_SIZE IPC_MEM_MAX_ADB_BUF_SIZE
18 /* Size of the buffer for the IP MUX Lite data buffer. */
19 #define IPC_MEM_MAX_DL_MUX_LITE_BUF_SIZE (2 * 1024)
21 /* TD counts for IP MUX Lite */
22 #define IPC_MEM_MAX_TDS_MUX_LITE_UL 800
23 #define IPC_MEM_MAX_TDS_MUX_LITE_DL 1200
25 /* open session request (AP->CP) */
26 #define MUX_CMD_OPEN_SESSION 1
28 /* response to open session request (CP->AP) */
29 #define MUX_CMD_OPEN_SESSION_RESP 2
31 /* close session request (AP->CP) */
32 #define MUX_CMD_CLOSE_SESSION 3
34 /* response to close session request (CP->AP) */
35 #define MUX_CMD_CLOSE_SESSION_RESP 4
37 /* Flow control command with mask of the flow per queue/flow. */
38 #define MUX_LITE_CMD_FLOW_CTL 5
40 /* ACK the flow control command. Shall have the same Transaction ID as the
41 * matching FLOW_CTL command.
43 #define MUX_LITE_CMD_FLOW_CTL_ACK 6
45 /* Command for report packet indicating link quality metrics. */
46 #define MUX_LITE_CMD_LINK_STATUS_REPORT 7
48 /* Response to a report packet */
49 #define MUX_LITE_CMD_LINK_STATUS_REPORT_RESP 8
51 /* Used to reset a command/response state. */
52 #define MUX_CMD_INVALID 255
54 /* command response : command processed successfully */
55 #define MUX_CMD_RESP_SUCCESS 0
57 /* MUX for route link devices */
58 #define IPC_MEM_WWAN_MUX BIT(0)
60 /* Initiated actions to change the state of the MUX object. */
62 MUX_E_INACTIVE, /* No initiated actions. */
63 MUX_E_MUX_SESSION_OPEN, /* Create the MUX channel and a session. */
64 MUX_E_MUX_SESSION_CLOSE, /* Release a session. */
65 MUX_E_MUX_CHANNEL_CLOSE, /* Release the MUX channel. */
66 MUX_E_NO_ORDERS, /* No MUX order. */
67 MUX_E_NOT_APPLICABLE, /* Defect IP MUX. */
70 /* MUX session open command. */
71 struct mux_session_open {
76 /* MUX session close command. */
77 struct mux_session_close {
82 /* MUX channel close command. */
83 struct mux_channel_close {
87 /* Default message type to find out the right message type. */
92 /* List of ops in MUX mode. */
94 struct mux_session_open session_open;
95 struct mux_session_close session_close;
96 struct mux_channel_close channel_close;
97 struct mux_common common;
100 /* Parameter definition of the open session command. */
101 struct mux_cmd_open_session {
102 u8 flow_ctrl; /* 0: Flow control disabled (flow allowed). */
103 /* 1: Flow control enabled (flow not allowed)*/
104 u8 ipv4v6_hints; /* 0: IPv4/IPv6 hints not supported.*/
105 /* 1: IPv4/IPv6 hints supported*/
106 __le16 reserved2; /* Reserved. Set to zero. */
107 __le32 dl_head_pad_len; /* Maximum length supported */
108 /* for DL head padding on a datagram. */
111 /* Parameter definition of the open session response. */
112 struct mux_cmd_open_session_resp {
113 __le32 response; /* Response code */
114 u8 flow_ctrl; /* 0: Flow control disabled (flow allowed). */
115 /* 1: Flow control enabled (flow not allowed) */
116 u8 ipv4v6_hints; /* 0: IPv4/IPv6 hints not supported */
117 /* 1: IPv4/IPv6 hints supported */
118 __le16 reserved2; /* Reserved. Set to zero. */
119 __le32 ul_head_pad_len; /* Actual length supported for */
120 /* UL head padding on adatagram.*/
123 /* Parameter definition of the close session response code */
124 struct mux_cmd_close_session_resp {
128 /* Parameter definition of the flow control command. */
129 struct mux_cmd_flow_ctl {
130 __le32 mask; /* indicating the desired flow control */
131 /* state for various flows/queues */
134 /* Parameter definition of the link status report code*/
135 struct mux_cmd_link_status_report {
139 /* Parameter definition of the link status report response code. */
140 struct mux_cmd_link_status_report_resp {
145 * union mux_cmd_param - Union-definition of the command parameters.
146 * @open_session: Inband command for open session
147 * @open_session_resp: Inband command for open session response
148 * @close_session_resp: Inband command for close session response
149 * @flow_ctl: In-band flow control on the opened interfaces
150 * @link_status: In-band Link Status Report
151 * @link_status_resp: In-band command for link status report response
153 union mux_cmd_param {
154 struct mux_cmd_open_session open_session;
155 struct mux_cmd_open_session_resp open_session_resp;
156 struct mux_cmd_close_session_resp close_session_resp;
157 struct mux_cmd_flow_ctl flow_ctl;
158 struct mux_cmd_link_status_report link_status;
159 struct mux_cmd_link_status_report_resp link_status_resp;
162 /* States of the MUX object.. */
164 MUX_S_INACTIVE, /* IP MUX is unused. */
165 MUX_S_ACTIVE, /* IP MUX channel is available. */
166 MUX_S_ERROR, /* Defect IP MUX. */
169 /* Supported MUX protocols. */
170 enum ipc_mux_protocol {
176 /* Supported UL data transfer methods. */
177 enum ipc_mux_ul_flow {
179 MUX_UL, /* Normal UL data transfer */
180 MUX_UL_ON_CREDITS, /* UL data transfer will be based on credits */
183 /* List of the MUX session. */
185 struct iosm_wwan *wwan; /*Network i/f used for communication*/
186 int if_id; /* i/f id for session open message.*/
188 u32 ul_head_pad_len; /* Nr of bytes for UL head padding. */
189 u32 dl_head_pad_len; /* Nr of bytes for DL head padding. */
190 struct sk_buff_head ul_list; /* skb entries for an ADT. */
191 u32 flow_ctl_mask; /* UL flow control */
192 u32 flow_ctl_en_cnt; /* Flow control Enable cmd count */
193 u32 flow_ctl_dis_cnt; /* Flow Control Disable cmd count */
194 int ul_flow_credits; /* UL flow credits */
196 flush:1; /* flush net interface ? */
200 * struct mux_adth_dg - Structure of the datagram in the Aggregated Datagram
202 * @datagram_index : Index (in bytes) to the k-th datagram in the table.
203 * Index shall count from the start of the block including
204 * the 16-byte header. This value shall be non-zero.
205 * @datagram_length: Length of the k-th datagram including the head padding.
206 * This value shall be non-zero.
207 * @service_class: Service class identifier for the datagram.
208 * @reserved: Reserved bytes. Set to zero
211 __le32 datagram_index;
212 __le16 datagram_length;
218 * struct mux_qlth_ql - Structure of the queue level in the Aggregated
219 * Datagram Queue Level Table Header.
220 * @nr_of_bytes: Number of bytes available to transmit in the queue.
227 * struct mux_qlth - Structure of Aggregated Datagram Queue Level Table
229 * @signature: Signature of the Queue Level Table Header
230 * Value: 0x48544C51 (ASCII characters: 'Q' 'L' 'T' 'H')
231 * @table_length: Length (in bytes) of the datagram table. This length
232 * shall include the queue level table header size.
234 * @if_id: ID of the interface the queue levels in the table
236 * @reserved: Reserved byte. Set to zero.
237 * @next_table_index: Index (in bytes) to the next table in the buffer. Index
238 * shall count from the start of the block including the
239 * 16-byte header. Value of zero indicates end of the list.
240 * @reserved2: Reserved bytes. Set to zero
241 * @ql: Queue level table with variable length
248 __le32 next_table_index;
250 struct mux_qlth_ql ql;
254 * struct mux_adb - Structure of State of a single UL data block.
255 * @dest_skb: Current UL skb for the data block.
257 * @adgh: ADGH pointer
258 * @qlth_skb: QLTH pointer
259 * @next_table_index: Pointer to next table index.
260 * @free_list: List of alloc. ADB for the UL sess.
261 * @size: Size of the ADB memory.
262 * @if_cnt: Statistic counter
263 * @dg_cnt_total: Datagram count total
264 * @payload_size: Payload Size
265 * @dg: Datagram table.
266 * @pp_qlt: Pointers to hold Queue Level Tables of session
267 * @adbh: ADBH pointer
268 * @qlt_updated: Queue level table updated
269 * @dg_count: Datagram count
272 struct sk_buff *dest_skb;
274 struct mux_adgh *adgh;
275 struct sk_buff *qlth_skb;
276 u32 *next_table_index;
277 struct sk_buff_head free_list;
283 dg[IPC_MEM_MUX_IP_SESSION_ENTRIES][IPC_MEM_MAX_UL_DG_ENTRIES];
284 struct mux_qlth *pp_qlt[IPC_MEM_MUX_IP_SESSION_ENTRIES];
285 struct mux_adbh *adbh;
286 u32 qlt_updated[IPC_MEM_MUX_IP_SESSION_ENTRIES];
287 u32 dg_count[IPC_MEM_MUX_IP_SESSION_ENTRIES];
291 * struct mux_acb - Structure of Temporary ACB state.
293 * @if_id: Session id.
294 * @buf_p: Command buffer.
295 * @wanted_response: Wanted Response
296 * @got_response: Got response
298 * @got_param: Received command/response parameter
301 struct sk_buff *skb; /* Used UL skb. */
302 int if_id; /* Session id. */
307 union mux_cmd_param got_param; /* Received command/response parameter */
311 * struct iosm_mux - Structure of the data multiplexing over an IP channel.
312 * @dev: Pointer to device structure
313 * @session: Array of the MUX sessions.
314 * @channel: Reference to the IP MUX channel
315 * @pcie: Pointer to iosm_pcie struct
316 * @imem: Pointer to iosm_imem
317 * @wwan: Poinetr to iosm_wwan
318 * @ipc_protocol: Pointer to iosm_protocol
319 * @channel_id: Channel ID for MUX
320 * @protocol: Type of the MUX protocol
321 * @ul_flow: UL Flow type
322 * @nr_sessions: Number of sessions
323 * @instance_id: Instance ID
324 * @state: States of the MUX object
325 * @event: Initiated actions to change the state of the MUX object
326 * @tx_transaction_id: Transaction id for the ACB command.
327 * @rr_next_session: Next session number for round robin.
328 * @ul_adb: State of the UL ADB/ADGH.
329 * @size_needed: Variable to store the size needed during ADB preparation
330 * @ul_data_pend_bytes: Pending UL data to be processed in bytes
331 * @acb: Temporary ACB state
332 * @wwan_q_offset: This will hold the offset of the given instance
333 * Useful while passing or receiving packets from
335 * @adb_finish_timer: Timer for forcefully finishing the ADB
336 * @acb_tx_sequence_nr: Sequence number for the ACB header.
337 * @params: user configurable parameters
338 * @adb_tx_sequence_nr: Sequence number for ADB header
339 * @acc_adb_size: Statistic data for logging
340 * @acc_payload_size: Statistic data for logging
341 * @initialized: MUX object is initialized
342 * @ev_mux_net_transmit_pending:
343 * 0 means inform the IPC tasklet to pass the
344 * accumulated uplink ADB to CP.
345 * @adb_prep_ongoing: Flag for ADB preparation status
349 struct mux_session session[IPC_MEM_MUX_IP_SESSION_ENTRIES];
350 struct ipc_mem_channel *channel;
351 struct iosm_pcie *pcie;
352 struct iosm_imem *imem;
353 struct iosm_wwan *wwan;
354 struct iosm_protocol *ipc_protocol;
356 enum ipc_mux_protocol protocol;
357 enum ipc_mux_ul_flow ul_flow;
360 enum mux_state state;
361 enum mux_event event;
362 u32 tx_transaction_id;
364 struct mux_adb ul_adb;
366 long long ul_data_pend_bytes;
369 struct hrtimer adb_finish_timer;
370 u16 acb_tx_sequence_nr;
371 struct ipc_params *params;
372 u16 adb_tx_sequence_nr;
373 unsigned long long acc_adb_size;
374 unsigned long long acc_payload_size;
376 ev_mux_net_transmit_pending:1,
380 /* MUX configuration structure */
381 struct ipc_mux_config {
382 enum ipc_mux_protocol protocol;
383 enum ipc_mux_ul_flow ul_flow;
388 * ipc_mux_init - Allocates and Init MUX instance
389 * @mux_cfg: Pointer to MUX configuration structure
390 * @ipc_imem: Pointer to imem data-struct
392 * Returns: Initialized mux pointer on success else NULL
394 struct iosm_mux *ipc_mux_init(struct ipc_mux_config *mux_cfg,
395 struct iosm_imem *ipc_imem);
398 * ipc_mux_deinit - Deallocates MUX instance
399 * @ipc_mux: Pointer to the MUX instance.
401 void ipc_mux_deinit(struct iosm_mux *ipc_mux);
404 * ipc_mux_check_n_restart_tx - Checks for pending UL date bytes and then
405 * it restarts the net interface tx queue if
406 * device has set flow control as off.
407 * @ipc_mux: Pointer to MUX data-struct
409 void ipc_mux_check_n_restart_tx(struct iosm_mux *ipc_mux);
412 * ipc_mux_get_active_protocol - Returns the active MUX protocol type.
413 * @ipc_mux: Pointer to MUX data-struct
415 * Returns: enum of type ipc_mux_protocol
417 enum ipc_mux_protocol ipc_mux_get_active_protocol(struct iosm_mux *ipc_mux);
420 * ipc_mux_open_session - Opens a MUX session for IP traffic.
421 * @ipc_mux: Pointer to MUX data-struct
422 * @session_nr: Interface ID or session number
424 * Returns: channel id on success, failure value on error
426 int ipc_mux_open_session(struct iosm_mux *ipc_mux, int session_nr);
429 * ipc_mux_close_session - Closes a MUX session.
430 * @ipc_mux: Pointer to MUX data-struct
431 * @session_nr: Interface ID or session number
433 * Returns: channel id on success, failure value on error
435 int ipc_mux_close_session(struct iosm_mux *ipc_mux, int session_nr);
438 * ipc_mux_get_max_sessions - Retuns the maximum sessions supported on the
439 * provided MUX instance..
440 * @ipc_mux: Pointer to MUX data-struct
442 * Returns: Number of sessions supported on Success and failure value on error
444 int ipc_mux_get_max_sessions(struct iosm_mux *ipc_mux);