1 /* SPDX-License-Identifier: GPL-2.0-only
2  *
3  * Copyright (C) 2020-21 Intel Corporation.
4  */
5 
6 #ifndef IOSM_IPC_MUX_CODEC_H
7 #define IOSM_IPC_MUX_CODEC_H
8 
9 #include "iosm_ipc_mux.h"
10 
11 /* Queue level size and reporting
12  * >1 is enable, 0 is disable
13  */
14 #define MUX_QUEUE_LEVEL 1
15 
16 /* Size of the buffer for the IP MUX commands. */
17 #define MUX_MAX_UL_ACB_BUF_SIZE 256
18 
19 /* Maximum number of packets in a go per session */
20 #define MUX_MAX_UL_DG_ENTRIES 100
21 
22 /* ADGH: Signature of the Datagram Header. */
23 #define MUX_SIG_ADGH 0x48474441
24 
25 /* CMDH: Signature of the Command Header. */
26 #define MUX_SIG_CMDH 0x48444D43
27 
28 /* QLTH: Signature of the Queue Level Table */
29 #define MUX_SIG_QLTH 0x48544C51
30 
31 /* FCTH: Signature of the Flow Credit Table */
32 #define MUX_SIG_FCTH 0x48544346
33 
34 /* MUX UL session threshold factor */
35 #define IPC_MEM_MUX_UL_SESS_FCOFF_THRESHOLD_FACTOR (4)
36 
37 /* Size of the buffer for the IP MUX Lite data buffer. */
38 #define IPC_MEM_MAX_DL_MUX_LITE_BUF_SIZE (2 * 1024)
39 
40 /* MUX UL session threshold in number of packets */
41 #define IPC_MEM_MUX_UL_SESS_FCON_THRESHOLD (64)
42 
43 /* Default time out for sending IPC session commands like
44  * open session, close session etc
45  * unit : milliseconds
46  */
47 #define IPC_MUX_CMD_RUN_DEFAULT_TIMEOUT 1000 /* 1 second */
48 
49 /* MUX UL flow control lower threshold in bytes */
50 #define IPC_MEM_MUX_UL_FLOWCTRL_LOW_B 10240 /* 10KB */
51 
52 /* MUX UL flow control higher threshold in bytes (5ms worth of data)*/
53 #define IPC_MEM_MUX_UL_FLOWCTRL_HIGH_B (110 * 1024)
54 
55 /**
56  * struct mux_adgh - Aggregated Datagram Header.
57  * @signature:		Signature of the Aggregated Datagram Header(0x48474441)
58  * @length:		Length (in bytes) of the datagram header. This length
59  *			shall include the header size. Min value: 0x10
60  * @if_id:		ID of the interface the datagrams belong to
61  * @opt_ipv4v6:		Indicates IPv4(=0)/IPv6(=1), It is optional if not
62  *			used set it to zero.
63  * @reserved:		Reserved bits. Set to zero.
64  * @service_class:	Service class identifier for the datagram.
65  * @next_count:		Count of the datagrams that shall be following this
66  *			datagrams for this interface. A count of zero means
67  *			the next datagram may not belong to this interface.
68  * @reserved1:		Reserved bytes, Set to zero
69  */
70 struct mux_adgh {
71 	__le32 signature;
72 	__le16 length;
73 	u8 if_id;
74 	u8 opt_ipv4v6;
75 	u8 service_class;
76 	u8 next_count;
77 	u8 reserved1[6];
78 };
79 
80 /**
81  * struct mux_lite_cmdh - MUX Lite Command Header
82  * @signature:		Signature of the Command Header(0x48444D43)
83  * @cmd_len:		Length (in bytes) of the command. This length shall
84  *			include the header size. Minimum value: 0x10
85  * @if_id:		ID of the interface the commands in the table belong to.
86  * @reserved:		Reserved Set to zero.
87  * @command_type:	Command Enum.
88  * @transaction_id:	4 byte value shall be generated and sent along with a
89  *			command Responses and ACKs shall have the same
90  *			Transaction ID as their commands. It shall be unique to
91  *			the command transaction on the given interface.
92  * @param:		Optional parameters used with the command.
93  */
94 struct mux_lite_cmdh {
95 	__le32 signature;
96 	__le16 cmd_len;
97 	u8 if_id;
98 	u8 reserved;
99 	__le32 command_type;
100 	__le32 transaction_id;
101 	union mux_cmd_param param;
102 };
103 
104 /**
105  * struct mux_lite_vfl - value field in generic table
106  * @nr_of_bytes:	Number of bytes available to transmit in the queue.
107  */
108 struct mux_lite_vfl {
109 	__le32 nr_of_bytes;
110 };
111 
112 /**
113  * struct ipc_mem_lite_gen_tbl - Generic table format for Queue Level
114  *				 and Flow Credit
115  * @signature:	Signature of the table
116  * @length:	Length of the table
117  * @if_id:	ID of the interface the table belongs to
118  * @vfl_length:	Value field length
119  * @reserved:	Reserved
120  * @vfl:	Value field of variable length
121  */
122 struct ipc_mem_lite_gen_tbl {
123 	__le32 signature;
124 	__le16 length;
125 	u8 if_id;
126 	u8 vfl_length;
127 	u32 reserved[2];
128 	struct mux_lite_vfl vfl;
129 };
130 
131 /**
132  * ipc_mux_dl_decode -Route the DL packet through the IP MUX layer
133  *		      depending on Header.
134  * @ipc_mux:	Pointer to MUX data-struct
135  * @skb:	Pointer to ipc_skb.
136  */
137 void ipc_mux_dl_decode(struct iosm_mux *ipc_mux, struct sk_buff *skb);
138 
139 /**
140  * ipc_mux_dl_acb_send_cmds - Respond to the Command blocks.
141  * @ipc_mux:		Pointer to MUX data-struct
142  * @cmd_type:		Command
143  * @if_id:		Session interface id.
144  * @transaction_id:	Command transaction id.
145  * @param:		Pointer to command params.
146  * @res_size:		Response size
147  * @blocking:		True for blocking send
148  * @respond:		If true return transaction ID
149  *
150  * Returns: 0 in success and failure value on error
151  */
152 int ipc_mux_dl_acb_send_cmds(struct iosm_mux *ipc_mux, u32 cmd_type, u8 if_id,
153 			     u32 transaction_id, union mux_cmd_param *param,
154 			     size_t res_size, bool blocking, bool respond);
155 
156 /**
157  * ipc_mux_netif_tx_flowctrl - Enable/Disable TX flow control on MUX sessions.
158  * @session:	Pointer to mux_session struct
159  * @idx:	Session ID
160  * @on:		true for Enable and false for disable flow control
161  */
162 void ipc_mux_netif_tx_flowctrl(struct mux_session *session, int idx, bool on);
163 
164 /**
165  * ipc_mux_ul_trigger_encode - Route the UL packet through the IP MUX layer
166  *			       for encoding.
167  * @ipc_mux:	Pointer to MUX data-struct
168  * @if_id:	Session ID.
169  * @skb:	Pointer to ipc_skb.
170  *
171  * Returns: 0 if successfully encoded
172  *	    failure value on error
173  *	    -EBUSY if packet has to be retransmitted.
174  */
175 int ipc_mux_ul_trigger_encode(struct iosm_mux *ipc_mux, int if_id,
176 			      struct sk_buff *skb);
177 /**
178  * ipc_mux_ul_data_encode - UL encode function for calling from Tasklet context.
179  * @ipc_mux:	Pointer to MUX data-struct
180  *
181  * Returns: TRUE if any packet of any session is encoded FALSE otherwise.
182  */
183 bool ipc_mux_ul_data_encode(struct iosm_mux *ipc_mux);
184 
185 /**
186  * ipc_mux_ul_encoded_process - Handles the Modem processed UL data by adding
187  *				the SKB to the UL free list.
188  * @ipc_mux:	Pointer to MUX data-struct
189  * @skb:	Pointer to ipc_skb.
190  */
191 void ipc_mux_ul_encoded_process(struct iosm_mux *ipc_mux, struct sk_buff *skb);
192 
193 #endif
194