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
|
/*
* Copyright (C) 2011 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/module.h>
#include "modem_prj.h"
#include "modem_utils.h"
#include "link_device_memory.h"
static inline int check_udl_space(struct mem_link_device *mld,
struct mem_ipc_device *dev,
unsigned int qsize, unsigned int in,
unsigned int out, unsigned int count)
{
struct link_device *ld = &mld->link_dev;
unsigned int space;
if (!circ_valid(qsize, in, out)) {
mif_err("%s: ERR! Invalid %s_TXQ{qsize:%d in:%d out:%d}\n",
ld->name, dev->name, qsize, in, out);
return -EIO;
}
space = circ_get_space(qsize, in, out);
if (unlikely(space < count)) {
mif_err("%s: NOSPC in %s_TXQ{qsize:%d in:%d "
"out:%d space:%d count:%d}\n", ld->name,
dev->name, qsize, in, out, space, count);
return -ENOSPC;
}
return 0;
}
/**
@brief copy UDL data in an skb to a circular TXQ
Enqueues a frame in @b @@skb to the @b @@dev TXQ if there is enough space in the
TXQ, then releases @b @@skb.
@param mld the pointer to a mem_link_device instance
@param dev the pointer to a mem_ipc_device instance
@param skb the pointer to an sk_buff instance
@retval "> 0" the size of the frame written in the TXQ
@retval "< 0" an error code (-EBUSY, -ENOSPC, or -EIO)
*/
static inline int udl_write(struct mem_link_device *mld,
struct mem_ipc_device *dev, struct sk_buff *skb)
{
unsigned int count = skb->len;
char *src = skb->data;
char *dst = get_txq_buff(dev);
unsigned int qsize = get_txq_buff_size(dev);
unsigned int in = get_txq_head(dev);
unsigned int out = get_txq_tail(dev);
int space;
space = check_udl_space(mld, dev, qsize, in, out, count);
if (unlikely(space < 0))
return space;
barrier();
circ_write(dst, src, qsize, in, count);
barrier();
set_txq_head(dev, circ_new_ptr(qsize, in, count));
/* Commit the item before incrementing the head */
smp_mb();
return count;
}
/**
@brief transmit a BOOT/DUMP data packet
@param mld the pointer to a mem_link_device instance
@param ch the channel ID
@param skb the pointer to an skb that will be transmitted
@retval "> 0" the size of the data in @b @@skb
*/
int xmit_udl(struct mem_link_device *mld, struct io_device *iod,
enum sipc_ch_id ch, struct sk_buff *skb)
{
int ret;
struct mem_ipc_device *dev = mld->dev[IPC_RAW];
int count = skb->len;
int tried = 0;
while (1) {
ret = udl_write(mld, dev, skb);
if (ret == count)
break;
if (ret != -ENOSPC)
goto exit;
tried++;
if (tried >= 20)
goto exit;
if (in_interrupt())
mdelay(50);
else
msleep(50);
}
dev_kfree_skb_any(skb);
exit:
return ret;
}
/**
@brief function for the @b xmit_boot method in a link_device instance
Copies a CP bootloader binary in a user space to the BOOT region for CP
@param ld the pointer to a link_device instance
@param iod the pointer to an io_device instance
@param arg the pointer to a modem_firmware instance
@retval "= 0" if NO error
@retval "< 0" an error code
*/
int mem_xmit_boot(struct link_device *ld, struct io_device *iod,
unsigned long arg)
{
struct mem_link_device *mld = to_mem_link_device(ld);
void __iomem *dst;
void __user *src;
int err;
struct modem_firmware mf;
/**
* Get the information about the boot image
*/
memset(&mf, 0, sizeof(struct modem_firmware));
err = copy_from_user(&mf, (const void __user *)arg, sizeof(mf));
if (err) {
mif_err("%s: ERR! INFO copy_from_user fail\n", ld->name);
return -EFAULT;
}
/**
* Check the size of the boot image
*/
if (mf.size > mld->boot_size) {
mif_err("%s: ERR! Invalid BOOT size %d\n", ld->name, mf.size);
return -EINVAL;
}
mif_err("%s: BOOT size = %d bytes\n", ld->name, mf.size);
/**
* Copy the boot image to the BOOT region
*/
memset(mld->boot_base, 0, mld->boot_size);
dst = (void __iomem *)mld->boot_base;
src = (void __user *)mf.binary;
err = copy_from_user(dst, src, mf.size);
if (err) {
mif_err("%s: ERR! BOOT copy_from_user fail\n", ld->name);
return err;
}
return 0;
}
/**
@brief function for the @b dload_start method in a link_device instance
Set all flags and environments for CP binary download
@param ld the pointer to a link_device instance
@param iod the pointer to an io_device instance
*/
int mem_start_download(struct link_device *ld, struct io_device *iod)
{
struct mem_link_device *mld = to_mem_link_device(ld);
reset_ipc_map(mld);
if (mld->attrs & LINK_ATTR(LINK_ATTR_MEM_BOOT))
sbd_deactivate(&mld->sbd_link_dev);
if (mld->attrs & LINK_ATTR(LINK_ATTR_BOOT_ALIGNED))
ld->aligned = true;
else
ld->aligned = false;
if (mld->dpram_magic) {
unsigned int magic;
set_magic(mld, MEM_BOOT_MAGIC);
magic = get_magic(mld);
if (magic != MEM_BOOT_MAGIC) {
mif_err("%s: ERR! magic 0x%08X != BOOT_MAGIC 0x%08X\n",
ld->name, magic, MEM_BOOT_MAGIC);
return -EFAULT;
}
mif_err("%s: magic == 0x%08X\n", ld->name, magic);
}
return 0;
}
/**
@brief function for the @b firm_update method in a link_device instance
Updates download information for each CP binary image by copying download
information for a CP binary image from a user space to a local buffer in a
mem_link_device instance.
@param ld the pointer to a link_device instance
@param iod the pointer to an io_device instance
@param arg the pointer to a std_dload_info instance
*/
int mem_update_firm_info(struct link_device *ld, struct io_device *iod,
unsigned long arg)
{
struct mem_link_device *mld = to_mem_link_device(ld);
int ret;
ret = copy_from_user(&mld->img_info, (void __user *)arg,
sizeof(struct std_dload_info));
if (ret) {
mif_err("ERR! copy_from_user fail!\n");
return -EFAULT;
}
return 0;
}
/**
@brief function for the @b dump_start method in a link_device instance
@param ld the pointer to a link_device instance
@param iod the pointer to an io_device instance
*/
int mem_start_upload(struct link_device *ld, struct io_device *iod)
{
struct mem_link_device *mld = to_mem_link_device(ld);
if (mld->attrs & LINK_ATTR(LINK_ATTR_MEM_DUMP))
sbd_deactivate(&mld->sbd_link_dev);
reset_ipc_map(mld);
if (mld->attrs & LINK_ATTR(LINK_ATTR_DUMP_ALIGNED))
ld->aligned = true;
else
ld->aligned = false;
if (mld->dpram_magic) {
unsigned int magic;
set_magic(mld, MEM_DUMP_MAGIC);
magic = get_magic(mld);
if (magic != MEM_DUMP_MAGIC) {
mif_err("%s: ERR! magic 0x%08X != DUMP_MAGIC 0x%08X\n",
ld->name, magic, MEM_DUMP_MAGIC);
return -EFAULT;
}
mif_err("%s: magic == 0x%08X\n", ld->name, magic);
}
return 0;
}
|