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
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
|
/*
* Copyright (C) 2012 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.
*
*/
#include <linux/netdevice.h>
#include <linux/platform_data/modem_v2.h>
#include <linux/platform_device.h>
#include <linux/skbuff.h>
#include <linux/ip.h>
#include <linux/tcp.h>
#include <linux/udp.h>
#include <linux/rtc.h>
#include <linux/time.h>
#include <net/ip.h>
#include "modem_prj.h"
#include "modem_utils.h"
int mif_dump_log(struct modem_shared *msd, struct io_device *iod)
{
struct sk_buff *skb;
unsigned long read_len = 0;
unsigned long int flags;
spin_lock_irqsave(&msd->lock, flags);
while (read_len < MAX_MIF_BUFF_SIZE) {
skb = alloc_skb(MAX_IPC_SKB_SIZE, GFP_ATOMIC);
if (!skb) {
pr_err("[MIF] <%s> alloc skb failed\n", __func__);
spin_unlock_irqrestore(&msd->lock, flags);
return -ENOMEM;
}
memcpy(skb_put(skb, MAX_IPC_SKB_SIZE),
msd->storage.addr + read_len, MAX_IPC_SKB_SIZE);
skb_queue_tail(&iod->sk_rx_q, skb);
read_len += MAX_IPC_SKB_SIZE;
wake_up(&iod->wq);
}
spin_unlock_irqrestore(&msd->lock, flags);
return 0;
}
static unsigned long long get_kernel_time(void)
{
int this_cpu;
unsigned long flags;
unsigned long long time;
preempt_disable();
raw_local_irq_save(flags);
this_cpu = smp_processor_id();
time = cpu_clock(this_cpu);
preempt_enable();
raw_local_irq_restore(flags);
return time;
}
void mif_ipc_log(enum mif_log_id id,
struct modem_shared *msd, const char *data, size_t len)
{
struct mif_ipc_block *block;
unsigned long int flags;
spin_lock_irqsave(&msd->lock, flags);
block = (struct mif_ipc_block *)
(msd->storage.addr + (MAX_LOG_SIZE * msd->storage.cnt));
msd->storage.cnt = ((msd->storage.cnt + 1) < MAX_LOG_CNT) ?
msd->storage.cnt + 1 : 0;
spin_unlock_irqrestore(&msd->lock, flags);
block->id = id;
block->time = get_kernel_time();
block->len = (len > MAX_IPC_LOG_SIZE) ? MAX_IPC_LOG_SIZE : len;
memcpy(block->buff, data, block->len);
}
void _mif_irq_log(enum mif_log_id id, struct modem_shared *msd,
struct mif_irq_map map, const char *data, size_t len)
{
struct mif_irq_block *block;
unsigned long int flags;
spin_lock_irqsave(&msd->lock, flags);
block = (struct mif_irq_block *)
(msd->storage.addr + (MAX_LOG_SIZE * msd->storage.cnt));
msd->storage.cnt = ((msd->storage.cnt + 1) < MAX_LOG_CNT) ?
msd->storage.cnt + 1 : 0;
spin_unlock_irqrestore(&msd->lock, flags);
block->id = id;
block->time = get_kernel_time();
memcpy(&(block->map), &map, sizeof(struct mif_irq_map));
if (data)
memcpy(block->buff, data,
(len > MAX_IRQ_LOG_SIZE) ? MAX_IRQ_LOG_SIZE : len);
}
void _mif_com_log(enum mif_log_id id,
struct modem_shared *msd, const char *format, ...)
{
struct mif_common_block *block;
unsigned long int flags;
va_list args;
int ret;
spin_lock_irqsave(&msd->lock, flags);
block = (struct mif_common_block *)
(msd->storage.addr + (MAX_LOG_SIZE * msd->storage.cnt));
msd->storage.cnt = ((msd->storage.cnt + 1) < MAX_LOG_CNT) ?
msd->storage.cnt + 1 : 0;
spin_unlock_irqrestore(&msd->lock, flags);
block->id = id;
block->time = get_kernel_time();
va_start(args, format);
ret = vsnprintf(block->buff, MAX_COM_LOG_SIZE, format, args);
va_end(args);
}
void _mif_time_log(enum mif_log_id id, struct modem_shared *msd,
struct timespec epoch, const char *data, size_t len)
{
struct mif_time_block *block;
unsigned long int flags;
spin_lock_irqsave(&msd->lock, flags);
block = (struct mif_time_block *)
(msd->storage.addr + (MAX_LOG_SIZE * msd->storage.cnt));
msd->storage.cnt = ((msd->storage.cnt + 1) < MAX_LOG_CNT) ?
msd->storage.cnt + 1 : 0;
spin_unlock_irqrestore(&msd->lock, flags);
block->id = id;
block->time = get_kernel_time();
memcpy(&block->epoch, &epoch, sizeof(struct timespec));
if (data)
memcpy(block->buff, data,
(len > MAX_IRQ_LOG_SIZE) ? MAX_IRQ_LOG_SIZE : len);
}
/* dump2hex
* dump data to hex as fast as possible.
* the length of @buf must be greater than "@len * 3"
* it need 3 bytes per one data byte to print.
*/
static inline int dump2hex(char *buf, const char *data, size_t len)
{
static const char *hex = "0123456789abcdef";
char *dest = buf;
int i;
for (i = 0; i < len; i++) {
*dest++ = hex[(data[i] >> 4) & 0xf];
*dest++ = hex[data[i] & 0xf];
*dest++ = ' ';
}
if (likely(len > 0))
dest--; /* last space will be overwrited with null */
*dest = '\0';
return dest - buf;
}
/* print buffer as hex string */
int pr_buffer(const char *tag, const char *data, size_t data_len,
size_t max_len)
{
size_t len = min(data_len, max_len);
unsigned char hexstr[len ? len * 3 : 1]; /* 1 <= sizeof <= max_len*3 */
dump2hex(hexstr, data, len);
/* don't change this printk to mif_debug for print this as level7 */
return printk(KERN_INFO "%s(%u): %s%s\n", tag, data_len, hexstr,
len == data_len ? "" : " ...");
}
struct io_device *get_iod_with_channel(struct modem_shared *msd,
unsigned channel)
{
struct rb_node *n = msd->iodevs_tree_chan.rb_node;
struct io_device *iodev;
while (n) {
iodev = rb_entry(n, struct io_device, node_chan);
if (channel < iodev->id)
n = n->rb_left;
else if (channel > iodev->id)
n = n->rb_right;
else
return iodev;
}
return NULL;
}
struct io_device *get_iod_with_format(struct modem_shared *msd,
enum dev_format format)
{
struct rb_node *n = msd->iodevs_tree_fmt.rb_node;
struct io_device *iodev;
while (n) {
iodev = rb_entry(n, struct io_device, node_fmt);
if (format < iodev->format)
n = n->rb_left;
else if (format > iodev->format)
n = n->rb_right;
else
return iodev;
}
return NULL;
}
struct io_device *insert_iod_with_channel(struct modem_shared *msd,
unsigned channel, struct io_device *iod)
{
struct rb_node **p = &msd->iodevs_tree_chan.rb_node;
struct rb_node *parent = NULL;
struct io_device *iodev;
while (*p) {
parent = *p;
iodev = rb_entry(parent, struct io_device, node_chan);
if (channel < iodev->id)
p = &(*p)->rb_left;
else if (channel > iodev->id)
p = &(*p)->rb_right;
else
return iodev;
}
rb_link_node(&iod->node_chan, parent, p);
rb_insert_color(&iod->node_chan, &msd->iodevs_tree_chan);
return NULL;
}
struct io_device *insert_iod_with_format(struct modem_shared *msd,
enum dev_format format, struct io_device *iod)
{
struct rb_node **p = &msd->iodevs_tree_fmt.rb_node;
struct rb_node *parent = NULL;
struct io_device *iodev;
while (*p) {
parent = *p;
iodev = rb_entry(parent, struct io_device, node_fmt);
if (format < iodev->format)
p = &(*p)->rb_left;
else if (format > iodev->format)
p = &(*p)->rb_right;
else
return iodev;
}
rb_link_node(&iod->node_fmt, parent, p);
rb_insert_color(&iod->node_fmt, &msd->iodevs_tree_fmt);
return NULL;
}
void iodevs_for_each(struct modem_shared *msd, action_fn action, void *args)
{
struct io_device *iod;
struct rb_node *node = rb_first(&msd->iodevs_tree_chan);
for (; node; node = rb_next(node)) {
iod = rb_entry(node, struct io_device, node_chan);
action(iod, args);
}
}
void iodev_netif_wake(struct io_device *iod, void *args)
{
if (iod->io_typ == IODEV_NET && iod->ndev) {
netif_wake_queue(iod->ndev);
mif_info("%s\n", iod->name);
}
}
void iodev_netif_stop(struct io_device *iod, void *args)
{
if (iod->io_typ == IODEV_NET && iod->ndev) {
netif_stop_queue(iod->ndev);
mif_info("%s\n", iod->name);
}
}
|