| 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 |
/* ADB finish timer value */ |
| 17 |
#define IOSM_AGGR_MUX_ADB_FINISH_TIMEOUT_NSEC (500 * 1000) |
| 18 |
|
| 19 |
/* Enables the flow control (Flow is not allowed) */ |
| 20 |
#define IOSM_AGGR_MUX_CMD_FLOW_CTL_ENABLE 5 |
| 21 |
|
| 22 |
/* Disables the flow control (Flow is allowed) */ |
| 23 |
#define IOSM_AGGR_MUX_CMD_FLOW_CTL_DISABLE 6 |
| 24 |
|
| 25 |
/* ACK the flow control command. Shall have the same Transaction ID as the |
| 26 |
* matching FLOW_CTL command |
| 27 |
*/ |
| 28 |
#define IOSM_AGGR_MUX_CMD_FLOW_CTL_ACK 7 |
| 29 |
|
| 30 |
/* Aggregation Protocol Command for report packet indicating link quality |
| 31 |
*/ |
| 32 |
#define IOSM_AGGR_MUX_CMD_LINK_STATUS_REPORT 8 |
| 33 |
|
| 34 |
/* Response to a report packet */ |
| 35 |
#define IOSM_AGGR_MUX_CMD_LINK_STATUS_REPORT_RESP 9 |
| 36 |
|
| 37 |
/* ACBH: Signature of the Aggregated Command Block Header. */ |
| 38 |
#define IOSM_AGGR_MUX_SIG_ACBH 0x48424341 |
| 39 |
|
| 40 |
/* ADTH: Signature of the Aggregated Datagram Table Header. */ |
| 41 |
#define IOSM_AGGR_MUX_SIG_ADTH 0x48544441 |
| 42 |
|
| 43 |
/* ADBH: Signature of the Aggregated Data Block Header. */ |
| 44 |
#define IOSM_AGGR_MUX_SIG_ADBH 0x48424441 |
| 45 |
|
| 46 |
/* ADGH: Signature of the Datagram Header. */ |
| 47 |
#define IOSM_AGGR_MUX_SIG_ADGH 0x48474441 |
| 48 |
|
| 49 |
/* Size of the buffer for the IP MUX commands. */ |
| 50 |
#define MUX_MAX_UL_ACB_BUF_SIZE 256 |
| 51 |
|
| 52 |
/* Maximum number of packets in a go per session */ |
| 53 |
#define MUX_MAX_UL_DG_ENTRIES 100 |
| 54 |
|
| 55 |
/* ADGH: Signature of the Datagram Header. */ |
| 56 |
#define MUX_SIG_ADGH 0x48474441 |
| 57 |
|
| 58 |
/* CMDH: Signature of the Command Header. */ |
| 59 |
#define MUX_SIG_CMDH 0x48444D43 |
| 60 |
|
| 61 |
/* QLTH: Signature of the Queue Level Table */ |
| 62 |
#define MUX_SIG_QLTH 0x48544C51 |
| 63 |
|
| 64 |
/* FCTH: Signature of the Flow Credit Table */ |
| 65 |
#define MUX_SIG_FCTH 0x48544346 |
| 66 |
|
| 67 |
/* MUX UL session threshold factor */ |
| 68 |
#define IPC_MEM_MUX_UL_SESS_FCOFF_THRESHOLD_FACTOR (4) |
| 69 |
|
| 70 |
/* Size of the buffer for the IP MUX Lite data buffer. */ |
| 71 |
#define IPC_MEM_MAX_DL_MUX_LITE_BUF_SIZE (2 * 1024) |
| 72 |
|
| 73 |
/* MUX UL session threshold in number of packets */ |
| 74 |
#define IPC_MEM_MUX_UL_SESS_FCON_THRESHOLD (64) |
| 75 |
|
| 76 |
/* Default time out for sending IPC session commands like |
| 77 |
* open session, close session etc |
| 78 |
* unit : milliseconds |
| 79 |
*/ |
| 80 |
#define IPC_MUX_CMD_RUN_DEFAULT_TIMEOUT 1000 /* 1 second */ |
| 81 |
|
| 82 |
/* MUX UL flow control lower threshold in bytes */ |
| 83 |
#define IPC_MEM_MUX_UL_FLOWCTRL_LOW_B 10240 /* 10KB */ |
| 84 |
|
| 85 |
/* MUX UL flow control higher threshold in bytes (5ms worth of data)*/ |
| 86 |
#define IPC_MEM_MUX_UL_FLOWCTRL_HIGH_B (110 * 1024) |
| 87 |
|
| 88 |
/** |
| 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 |
| 96 |
* details. |
| 97 |
* @transaction_id: The Transaction ID shall be unique to the command |
| 98 |
* @param: Optional parameters used with the command. |
| 99 |
*/ |
| 100 |
struct mux_cmdh { |
| 101 |
__le32 signature; |
| 102 |
__le16 cmd_len; |
| 103 |
u8 if_id; |
| 104 |
u8 reserved; |
| 105 |
__le32 next_cmd_index; |
| 106 |
__le32 command_type; |
| 107 |
__le32 transaction_id; |
| 108 |
union mux_cmd_param param; |
| 109 |
}; |
| 110 |
|
| 111 |
/** |
| 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. |
| 118 |
*/ |
| 119 |
struct mux_acbh { |
| 120 |
__le32 signature; |
| 121 |
__le16 reserved; |
| 122 |
__le16 sequence_nr; |
| 123 |
__le32 block_length; |
| 124 |
__le32 first_cmd_index; |
| 125 |
}; |
| 126 |
|
| 127 |
/** |
| 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 |
| 134 |
* the buffer. |
| 135 |
*/ |
| 136 |
struct mux_adbh { |
| 137 |
__le32 signature; |
| 138 |
__le16 reserved; |
| 139 |
__le16 sequence_nr; |
| 140 |
__le32 block_length; |
| 141 |
__le32 first_table_index; |
| 142 |
}; |
| 143 |
|
| 144 |
/** |
| 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 |
| 149 |
* belong to. |
| 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 |
| 153 |
* the buffer. |
| 154 |
* @reserved2: Reserved bytes. Set to zero |
| 155 |
* @dg: datagramm table with variable length |
| 156 |
*/ |
| 157 |
struct mux_adth { |
| 158 |
__le32 signature; |
| 159 |
__le16 table_length; |
| 160 |
u8 if_id; |
| 161 |
u8 opt_ipv4v6; |
| 162 |
__le32 next_table_index; |
| 163 |
__le32 reserved2; |
| 164 |
struct mux_adth_dg dg[]; |
| 165 |
}; |
| 166 |
|
| 167 |
/** |
| 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 |
| 181 |
*/ |
| 182 |
struct mux_adgh { |
| 183 |
__le32 signature; |
| 184 |
__le16 length; |
| 185 |
u8 if_id; |
| 186 |
u8 opt_ipv4v6; |
| 187 |
u8 service_class; |
| 188 |
u8 next_count; |
| 189 |
u8 reserved1[6]; |
| 190 |
}; |
| 191 |
|
| 192 |
/** |
| 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. |
| 205 |
*/ |
| 206 |
struct mux_lite_cmdh { |
| 207 |
__le32 signature; |
| 208 |
__le16 cmd_len; |
| 209 |
u8 if_id; |
| 210 |
u8 reserved; |
| 211 |
__le32 command_type; |
| 212 |
__le32 transaction_id; |
| 213 |
union mux_cmd_param param; |
| 214 |
}; |
| 215 |
|
| 216 |
/** |
| 217 |
* struct mux_lite_vfl - value field in generic table |
| 218 |
* @nr_of_bytes: Number of bytes available to transmit in the queue. |
| 219 |
*/ |
| 220 |
struct mux_lite_vfl { |
| 221 |
__le32 nr_of_bytes; |
| 222 |
}; |
| 223 |
|
| 224 |
/** |
| 225 |
* struct ipc_mem_lite_gen_tbl - Generic table format for Queue Level |
| 226 |
* and Flow Credit |
| 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 |
| 233 |
*/ |
| 234 |
struct ipc_mem_lite_gen_tbl { |
| 235 |
__le32 signature; |
| 236 |
__le16 length; |
| 237 |
u8 if_id; |
| 238 |
u8 vfl_length; |
| 239 |
u32 reserved[2]; |
| 240 |
struct mux_lite_vfl vfl; |
| 241 |
}; |
| 242 |
|
| 243 |
/** |
| 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 |
| 247 |
*/ |
| 248 |
union mux_type_cmdh { |
| 249 |
struct mux_lite_cmdh *ack_lite; |
| 250 |
struct mux_cmdh *ack_aggr; |
| 251 |
}; |
| 252 |
|
| 253 |
/** |
| 254 |
* struct mux_type_header - Structure of mux header type |
| 255 |
* @adgh: Aggregated Datagram Header pointer |
| 256 |
* @adbh: Aggregated Data Block Header pointer |
| 257 |
*/ |
| 258 |
union mux_type_header { |
| 259 |
struct mux_adgh *adgh; |
| 260 |
struct mux_adbh *adbh; |
| 261 |
}; |
| 262 |
|
| 263 |
void ipc_mux_dl_decode(struct iosm_mux *ipc_mux, struct sk_buff *skb); |
| 264 |
|
| 265 |
/** |
| 266 |
* ipc_mux_dl_acb_send_cmds - Respond to the Command blocks. |
| 267 |
* @ipc_mux: Pointer to MUX data-struct |
| 268 |
* @cmd_type: Command |
| 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 |
| 275 |
* |
| 276 |
* Returns: 0 in success and failure value on error |
| 277 |
*/ |
| 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); |
| 281 |
|
| 282 |
/** |
| 283 |
* ipc_mux_netif_tx_flowctrl - Enable/Disable TX flow control on MUX sessions. |
| 284 |
* @session: Pointer to mux_session struct |
| 285 |
* @idx: Session ID |
| 286 |
* @on: true for Enable and false for disable flow control |
| 287 |
*/ |
| 288 |
void ipc_mux_netif_tx_flowctrl(struct mux_session *session, int idx, bool on); |
| 289 |
|
| 290 |
/** |
| 291 |
* ipc_mux_ul_trigger_encode - Route the UL packet through the IP MUX layer |
| 292 |
* for encoding. |
| 293 |
* @ipc_mux: Pointer to MUX data-struct |
| 294 |
* @if_id: Session ID. |
| 295 |
* @skb: Pointer to ipc_skb. |
| 296 |
* |
| 297 |
* Returns: 0 if successfully encoded |
| 298 |
* failure value on error |
| 299 |
* -EBUSY if packet has to be retransmitted. |
| 300 |
*/ |
| 301 |
int ipc_mux_ul_trigger_encode(struct iosm_mux *ipc_mux, int if_id, |
| 302 |
struct sk_buff *skb); |
| 303 |
/** |
| 304 |
* ipc_mux_ul_data_encode - UL encode function for calling from Tasklet context. |
| 305 |
* @ipc_mux: Pointer to MUX data-struct |
| 306 |
* |
| 307 |
* Returns: TRUE if any packet of any session is encoded FALSE otherwise. |
| 308 |
*/ |
| 309 |
bool ipc_mux_ul_data_encode(struct iosm_mux *ipc_mux); |
| 310 |
|
| 311 |
/** |
| 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. |
| 316 |
*/ |
| 317 |
void ipc_mux_ul_encoded_process(struct iosm_mux *ipc_mux, struct sk_buff *skb); |
| 318 |
|
| 319 |
void ipc_mux_ul_adb_finish(struct iosm_mux *ipc_mux); |
| 320 |
|
| 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); |
| 324 |
|
| 325 |
#endif |