1 /* SPDX-License-Identifier: GPL-2.0-only
3 * Copyright (C) 2020-21 Intel Corporation.
6 #ifndef IOSM_IPC_MUX_CODEC_H
7 #define IOSM_IPC_MUX_CODEC_H
9 #include "iosm_ipc_mux.h"
11 /* Queue level size and reporting
12 * >1 is enable, 0 is disable
14 #define MUX_QUEUE_LEVEL 1
16 /* ADB finish timer value */
17 #define IOSM_AGGR_MUX_ADB_FINISH_TIMEOUT_NSEC (500 * 1000)
19 /* Enables the flow control (Flow is not allowed) */
20 #define IOSM_AGGR_MUX_CMD_FLOW_CTL_ENABLE 5
22 /* Disables the flow control (Flow is allowed) */
23 #define IOSM_AGGR_MUX_CMD_FLOW_CTL_DISABLE 6
25 /* ACK the flow control command. Shall have the same Transaction ID as the
26 * matching FLOW_CTL command
28 #define IOSM_AGGR_MUX_CMD_FLOW_CTL_ACK 7
30 /* Aggregation Protocol Command for report packet indicating link quality
32 #define IOSM_AGGR_MUX_CMD_LINK_STATUS_REPORT 8
34 /* Response to a report packet */
35 #define IOSM_AGGR_MUX_CMD_LINK_STATUS_REPORT_RESP 9
37 /* ACBH: Signature of the Aggregated Command Block Header. */
38 #define IOSM_AGGR_MUX_SIG_ACBH 0x48424341
40 /* ADTH: Signature of the Aggregated Datagram Table Header. */
41 #define IOSM_AGGR_MUX_SIG_ADTH 0x48544441
43 /* ADBH: Signature of the Aggregated Data Block Header. */
44 #define IOSM_AGGR_MUX_SIG_ADBH 0x48424441
46 /* ADGH: Signature of the Datagram Header. */
47 #define IOSM_AGGR_MUX_SIG_ADGH 0x48474441
49 /* Size of the buffer for the IP MUX commands. */
50 #define MUX_MAX_UL_ACB_BUF_SIZE 256
52 /* Maximum number of packets in a go per session */
53 #define MUX_MAX_UL_DG_ENTRIES 100
55 /* ADGH: Signature of the Datagram Header. */
56 #define MUX_SIG_ADGH 0x48474441
58 /* CMDH: Signature of the Command Header. */
59 #define MUX_SIG_CMDH 0x48444D43
61 /* QLTH: Signature of the Queue Level Table */
62 #define MUX_SIG_QLTH 0x48544C51
64 /* FCTH: Signature of the Flow Credit Table */
65 #define MUX_SIG_FCTH 0x48544346
67 /* MUX UL session threshold factor */
68 #define IPC_MEM_MUX_UL_SESS_FCOFF_THRESHOLD_FACTOR (4)
70 /* Size of the buffer for the IP MUX Lite data buffer. */
71 #define IPC_MEM_MAX_DL_MUX_LITE_BUF_SIZE (2 * 1024)
73 /* MUX UL session threshold in number of packets */
74 #define IPC_MEM_MUX_UL_SESS_FCON_THRESHOLD (64)
76 /* Default time out for sending IPC session commands like
77 * open session, close session etc
80 #define IPC_MUX_CMD_RUN_DEFAULT_TIMEOUT 1000 /* 1 second */
82 /* MUX UL flow control lower threshold in bytes */
83 #define IPC_MEM_MUX_UL_FLOWCTRL_LOW_B 10240 /* 10KB */
85 /* MUX UL flow control higher threshold in bytes (5ms worth of data)*/
86 #define IPC_MEM_MUX_UL_FLOWCTRL_HIGH_B (110 * 1024)
89 * struct mux_cmdh - Structure of Command Header.
90 * @signature: Signature of the Command Header.
91 * @cmd_len: Length (in bytes) of the Aggregated Command Block.
92 * @if_id: ID of the interface the commands in the table belong to.
93 * @reserved: Reserved. Set to zero.
94 * @next_cmd_index: Index (in bytes) to the next command in the buffer.
95 * @command_type: Command Enum. See table Session Management chapter for
97 * @transaction_id: The Transaction ID shall be unique to the command
98 * @param: Optional parameters used with the command.
105 __le32 next_cmd_index;
107 __le32 transaction_id;
108 union mux_cmd_param param;
112 * struct mux_acbh - Structure of the Aggregated Command Block Header.
113 * @signature: Signature of the Aggregated Command Block Header.
114 * @reserved: Reserved bytes. Set to zero.
115 * @sequence_nr: Block sequence number.
116 * @block_length: Length (in bytes) of the Aggregated Command Block.
117 * @first_cmd_index: Index (in bytes) to the first command in the buffer.
124 __le32 first_cmd_index;
128 * struct mux_adbh - Structure of the Aggregated Data Block Header.
129 * @signature: Signature of the Aggregated Data Block Header.
130 * @reserved: Reserved bytes. Set to zero.
131 * @sequence_nr: Block sequence number.
132 * @block_length: Length (in bytes) of the Aggregated Data Block.
133 * @first_table_index: Index (in bytes) to the first Datagram Table in
141 __le32 first_table_index;
145 * struct mux_adth - Structure of the Aggregated Datagram Table Header.
146 * @signature: Signature of the Aggregated Datagram Table Header.
147 * @table_length: Length (in bytes) of the datagram table.
148 * @if_id: ID of the interface the datagrams in the table
150 * @opt_ipv4v6: Indicates IPv4(=0)/IPv6(=1) hint.
151 * @reserved: Reserved bits. Set to zero.
152 * @next_table_index: Index (in bytes) to the next Datagram Table in
154 * @reserved2: Reserved bytes. Set to zero
155 * @dg: datagramm table with variable length
162 __le32 next_table_index;
164 struct mux_adth_dg dg;
168 * struct mux_adgh - Aggregated Datagram Header.
169 * @signature: Signature of the Aggregated Datagram Header(0x48474441)
170 * @length: Length (in bytes) of the datagram header. This length
171 * shall include the header size. Min value: 0x10
172 * @if_id: ID of the interface the datagrams belong to
173 * @opt_ipv4v6: Indicates IPv4(=0)/IPv6(=1), It is optional if not
174 * used set it to zero.
175 * @reserved: Reserved bits. Set to zero.
176 * @service_class: Service class identifier for the datagram.
177 * @next_count: Count of the datagrams that shall be following this
178 * datagrams for this interface. A count of zero means
179 * the next datagram may not belong to this interface.
180 * @reserved1: Reserved bytes, Set to zero
193 * struct mux_lite_cmdh - MUX Lite Command Header
194 * @signature: Signature of the Command Header(0x48444D43)
195 * @cmd_len: Length (in bytes) of the command. This length shall
196 * include the header size. Minimum value: 0x10
197 * @if_id: ID of the interface the commands in the table belong to.
198 * @reserved: Reserved Set to zero.
199 * @command_type: Command Enum.
200 * @transaction_id: 4 byte value shall be generated and sent along with a
201 * command Responses and ACKs shall have the same
202 * Transaction ID as their commands. It shall be unique to
203 * the command transaction on the given interface.
204 * @param: Optional parameters used with the command.
206 struct mux_lite_cmdh {
212 __le32 transaction_id;
213 union mux_cmd_param param;
217 * struct mux_lite_vfl - value field in generic table
218 * @nr_of_bytes: Number of bytes available to transmit in the queue.
220 struct mux_lite_vfl {
225 * struct ipc_mem_lite_gen_tbl - Generic table format for Queue Level
227 * @signature: Signature of the table
228 * @length: Length of the table
229 * @if_id: ID of the interface the table belongs to
230 * @vfl_length: Value field length
231 * @reserved: Reserved
232 * @vfl: Value field of variable length
234 struct ipc_mem_lite_gen_tbl {
240 struct mux_lite_vfl vfl;
244 * struct mux_type_cmdh - Structure of command header for mux lite and aggr
245 * @ack_lite: MUX Lite Command Header pointer
246 * @ack_aggr: Command Header pointer
248 union mux_type_cmdh {
249 struct mux_lite_cmdh *ack_lite;
250 struct mux_cmdh *ack_aggr;
254 * struct mux_type_header - Structure of mux header type
255 * @adgh: Aggregated Datagram Header pointer
256 * @adbh: Aggregated Data Block Header pointer
258 union mux_type_header {
259 struct mux_adgh *adgh;
260 struct mux_adbh *adbh;
263 void ipc_mux_dl_decode(struct iosm_mux *ipc_mux, struct sk_buff *skb);
266 * ipc_mux_dl_acb_send_cmds - Respond to the Command blocks.
267 * @ipc_mux: Pointer to MUX data-struct
269 * @if_id: Session interface id.
270 * @transaction_id: Command transaction id.
271 * @param: Pointer to command params.
272 * @res_size: Response size
273 * @blocking: True for blocking send
274 * @respond: If true return transaction ID
276 * Returns: 0 in success and failure value on error
278 int ipc_mux_dl_acb_send_cmds(struct iosm_mux *ipc_mux, u32 cmd_type, u8 if_id,
279 u32 transaction_id, union mux_cmd_param *param,
280 size_t res_size, bool blocking, bool respond);
283 * ipc_mux_netif_tx_flowctrl - Enable/Disable TX flow control on MUX sessions.
284 * @session: Pointer to mux_session struct
286 * @on: true for Enable and false for disable flow control
288 void ipc_mux_netif_tx_flowctrl(struct mux_session *session, int idx, bool on);
291 * ipc_mux_ul_trigger_encode - Route the UL packet through the IP MUX layer
293 * @ipc_mux: Pointer to MUX data-struct
294 * @if_id: Session ID.
295 * @skb: Pointer to ipc_skb.
297 * Returns: 0 if successfully encoded
298 * failure value on error
299 * -EBUSY if packet has to be retransmitted.
301 int ipc_mux_ul_trigger_encode(struct iosm_mux *ipc_mux, int if_id,
302 struct sk_buff *skb);
304 * ipc_mux_ul_data_encode - UL encode function for calling from Tasklet context.
305 * @ipc_mux: Pointer to MUX data-struct
307 * Returns: TRUE if any packet of any session is encoded FALSE otherwise.
309 bool ipc_mux_ul_data_encode(struct iosm_mux *ipc_mux);
312 * ipc_mux_ul_encoded_process - Handles the Modem processed UL data by adding
313 * the SKB to the UL free list.
314 * @ipc_mux: Pointer to MUX data-struct
315 * @skb: Pointer to ipc_skb.
317 void ipc_mux_ul_encoded_process(struct iosm_mux *ipc_mux, struct sk_buff *skb);
319 void ipc_mux_ul_adb_finish(struct iosm_mux *ipc_mux);
321 void ipc_mux_ul_adb_update_ql(struct iosm_mux *ipc_mux, struct mux_adb *p_adb,
322 int session_id, int qlth_n_ql_size,
323 struct sk_buff_head *ul_list);