summaryrefstree
path: root/kernel/drivers/misc/modem_v1/include/sipc5.h
blob: fb42e33eb610fa9469391c45dff50c795a158f2a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
/*
 * Copyright (C) 2010 Samsung Electronics.
 *
 * This software is licensed under the terms of the GNU General Public
 * License version 2, as published by the Free Software Foundation, and
 * may be copied, distributed, and modified under those terms.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 */

#ifndef __SIPC5_H__
#define __SIPC5_H__

#include <linux/types.h>
#include "../modem_v1.h"

/* SIPC5 link-layer header */
struct __packed sipc5_link_header {
	u8 cfg;
	u8 ch;
	u16 len;
	union {
		struct multi_frame_control ctrl;
		u16 ext_len;
	};
};

#define SIPC5_START_MASK	(0b11111000)
#define SIPC5_CONFIG_MASK	(0b00000111)
#define SIPC5_EXT_FIELD_MASK	(0b00000011)

#define SIPC5_PADDING_EXIST	(0b00000100)
#define SIPC5_EXT_FIELD_EXIST	(0b00000010)
#define SIPC5_CTL_FIELD_EXIST	(0b00000001)

#define SIPC5_MULTI_FRAME_CFG	(0b00000011)
#define SIPC5_EXT_LENGTH_CFG	(0b00000010)

#define SIPC5_CONFIG_OFFSET	0
#define SIPC5_CONFIG_SIZE	1

#define SIPC5_CH_ID_OFFSET	1
#define SIPC5_CH_ID_SIZE	1

#define SIPC5_LEN_OFFSET	2
#define SIPC5_LEN_SIZE		2

#define SIPC5_CTRL_OFFSET	4
#define SIPC5_CTRL_SIZE		1

#define SIPC5_EXT_LEN_OFFSET	4
#define SIPC5_EXT_LEN_SIZE	2

#define SIPC5_MIN_HEADER_SIZE		4
#define SIPC5_HEADER_SIZE_WITH_CTL_FLD	5
#define SIPC5_HEADER_SIZE_WITH_EXT_LEN	6
#define SIPC5_MAX_HEADER_SIZE		SIPC5_HEADER_SIZE_WITH_EXT_LEN

static inline bool sipc5_start_valid(u8 *frm)
{
	return (*frm & SIPC5_START_MASK) == SIPC5_START_MASK;
}

static inline bool sipc5_padding_exist(u8 *frm)
{
	return (*frm & SIPC5_PADDING_EXIST) ? true : false;
}

static inline bool sipc5_multi_frame(u8 *frm)
{
	return (*frm & SIPC5_EXT_FIELD_MASK) == SIPC5_MULTI_FRAME_CFG;
}

static inline bool sipc5_ext_len(u8 *frm)
{
	return (*frm & SIPC5_EXT_FIELD_MASK) == SIPC5_EXT_LENGTH_CFG;
}

static inline u8 sipc5_get_ch(u8 *frm)
{
	return frm[SIPC5_CH_ID_OFFSET];
}

static inline u8 sipc5_get_ctrl(u8 *frm)
{
	return frm[SIPC5_CTRL_OFFSET];
}

static inline unsigned int sipc5_calc_padding_size(unsigned int len)
{
	unsigned int residue = len & (BITS_PER_LONG / 8 - 1);

	return residue ? (BITS_PER_LONG / 8 - residue) : 0;
}

/**
@brief		get the length of the header of an SIPC5 link frame
@param frm	the pointer to an SIPC5 link frame
@return		the size of the header of an SIPC5 link frame
*/
static inline unsigned int sipc5_get_hdr_len(u8 *frm)
{
	if (unlikely(frm[0] & SIPC5_EXT_FIELD_EXIST)) {
		if (sipc5_multi_frame(frm))
			return SIPC5_HEADER_SIZE_WITH_CTL_FLD;
		else
			return SIPC5_HEADER_SIZE_WITH_EXT_LEN;
	} else {
		return SIPC5_MIN_HEADER_SIZE;
	}
}

/**
@brief		get the real length of an SIPC5 link frame WITHOUT padding
@param frm	the pointer to an SIPC5 link frame
@return		the real length of an SIPC5 link frame WITHOUT padding
*/
static inline unsigned int sipc5_get_frame_len(u8 *frm)
{
	u16 *sz16 = (u16 *)(frm + SIPC5_LEN_OFFSET);
	u32 *sz32 = (u32 *)(frm + SIPC5_LEN_OFFSET);

	if (unlikely(frm[0] & SIPC5_EXT_FIELD_EXIST)) {
		if (sipc5_multi_frame(frm))
			return *sz16;
		else
			return *sz32;
	} else {
		return *sz16;
	}
}

/**
@brief		get the total length of an SIPC5 link frame with padding
@param frm	the pointer to an SIPC5 link frame
@return		the total length of an SIPC5 link frame with padding
*/
static inline unsigned int sipc5_get_total_len(u8 *frm)
{
	unsigned int len;
	unsigned int pad;

	len = sipc5_get_frame_len(frm);
	pad = sipc5_padding_exist(frm) ? sipc5_calc_padding_size(len) : 0;
	return len + pad;
}

/**
@param ch	the channel ID
@return		true if the channel ID is for FMT channel
*/
static inline bool sipc5_fmt_ch(u8 ch)
{
	return (ch >= SIPC5_CH_ID_FMT_0 && ch <= SIPC5_CH_ID_FMT_9) ?
		true : false;
}

/**
@param ch	the channel ID
@return		true if the channel ID is for RFS channel
*/
static inline bool sipc5_rfs_ch(u8 ch)
{
	return (ch >= SIPC5_CH_ID_RFS_0 && ch <= SIPC5_CH_ID_RFS_9) ?
		true : false;
}

/**
@param ch	the channel ID
@return		true if the channel ID is for BOOT channel
*/
static inline bool sipc5_boot_ch(u8 ch)
{
	return (ch >= SIPC5_CH_ID_BOOT_0 && ch <= SIPC5_CH_ID_BOOT_9) ?
		true : false;
}

/**
@param ch	the channel ID
@return		true if the channel ID is for DUMP channel
*/
static inline bool sipc5_dump_ch(u8 ch)
{
	return (ch >= SIPC5_CH_ID_DUMP_0 && ch <= SIPC5_CH_ID_DUMP_9) ?
		true : false;
}

/**
@param ch	the channel ID
@return		true if the channel ID is for BOOT/DUMP channel
*/
static inline bool sipc5_udl_ch(u8 ch)
{
	return (ch >= SIPC5_CH_ID_BOOT_0 && ch <= SIPC5_CH_ID_DUMP_9) ?
		true : false;
}

/**
@param ch	the channel ID
@return		true if the channel ID is for IPC channel
*/
static inline bool sipc5_ipc_ch(u8 ch)
{
	return (ch > 0 && (ch < SIPC5_CH_ID_BOOT_0 || ch > SIPC5_CH_ID_DUMP_9))
		? true : false;
}

struct sipc5_frame_data {
	/* Frame length calculated from the length fields */
	unsigned int len;

	/* The length of link layer header */
	unsigned int hdr_len;

	/* The length of received header */
	unsigned int hdr_rcvd;

	/* The length of link layer payload */
	unsigned int pay_len;

	/* The length of received data */
	unsigned int pay_rcvd;

	/* The length of link layer padding */
	unsigned int pad_len;

	/* The length of received padding */
	unsigned int pad_rcvd;

	/* Header buffer */
	u8 hdr[SIPC5_MAX_HEADER_SIZE];
};

#if 1
#endif

#define STD_UDL_STEP_MASK	0x0000000F
#define STD_UDL_SEND		0x1
#define STD_UDL_CRC		0xC

struct std_dload_info {
	u32 size;
	u32 mtu;
	u32 num_frames;
} __packed;


/**
@brief		get BOOT/DUMP command

@param frm	the pointer to an SIPC5 link frame

@return		the standard BOOT/DUMP command in an SIPC5 BOOT/DUMP frame
*/
static inline u32 std_udl_get_cmd(u8 *frm)
{
	u8 *cmd = frm + sipc5_get_hdr_len(frm);
	return *((u32 *)cmd);
}

/**
@brief		check whether or not a command came with a payload

@param cmd	the standard BOOT/DUMP command

@retval "true"	if the STD_UDL command has a payload
@retval "false"	otherwise
*/
static inline bool std_udl_with_payload(u32 cmd)
{
	u32 mask = cmd & STD_UDL_STEP_MASK;
	return (mask && mask < STD_UDL_CRC) ? true : false;
}

#endif