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
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
|
/******************************************************************************
Copyright (c) 2007
Infineon Technologies AG
Am Campeon 1-12; 81726 Munich, Germany
THE DELIVERY OF THIS SOFTWARE AS WELL AS THE HEREBY GRANTED NON-EXCLUSIVE,
WORLDWIDE LICENSE TO USE, COPY, MODIFY, DISTRIBUTE AND SUBLICENSE THIS
SOFTWARE IS FREE OF CHARGE.
THE LICENSED SOFTWARE IS PROVIDED "AS IS" AND INFINEON EXPRESSLY DISCLAIMS
ALL REPRESENTATIONS AND WARRANTIES, WHETHER EXPRESS OR IMPLIED, INCLUDING
WITHOUT LIMITATION, WARRANTIES OR REPRESENTATIONS OF WORKMANSHIP,
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, DURABILITY, THAT THE
OPERATING OF THE LICENSED SOFTWARE WILL BE ERROR FREE OR FREE OF ANY THIRD
PARTY CLAIMS, INCLUDING WITHOUT LIMITATION CLAIMS OF THIRD PARTY INTELLECTUAL
PROPERTY INFRINGEMENT.
EXCEPT FOR ANY LIABILITY DUE TO WILFUL ACTS OR GROSS NEGLIGENCE AND EXCEPT
FOR ANY PERSONAL INJURY INFINEON SHALL IN NO EVENT BE LIABLE FOR ANY CLAIM
OR DAMAGES OF ANY KIND, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
DEALINGS IN THE SOFTWARE.
****************************************************************************
Module : svip_virtual_eth.c
Description : This file contains network driver implementation for a
Virtual Ethernet interface. The Virtual Ethernet interface
is part of Infineon's VINETIC-SVIP Linux BSP.
*******************************************************************************/
#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/netdevice.h>
#include <linux/platform_device.h>
#include <linux/etherdevice.h>
#include <linux/init.h>
#define SVIP_VETH_VER_STR "3.0"
#define SVIP_VETH_INFO_STR \
"@(#)SVIP virtual ethernet interface, version " SVIP_VETH_VER_STR
/******************************************************************************
* Local define/macro definitions
******************************************************************************/
struct svip_ve_priv
{
struct net_device_stats stats;
};
/******************************************************************************
* Global function declarations
******************************************************************************/
int svip_ve_rx(struct sk_buff *skb);
/******************************************************************************
* Local variable declarations
******************************************************************************/
static struct net_device *svip_ve_dev;
static int watchdog_timeout = 10*HZ;
static int (*svip_ve_mps_xmit)(struct sk_buff *skb) = NULL;
/******************************************************************************
* Global function declarations
******************************************************************************/
/**
* Called by MPS driver to register a transmit routine called for each outgoing
* VoFW0 message.
*
* \param mps_xmit pointer to transmit routine
*
* \return none
*
* \ingroup Internal
*/
void register_mps_xmit_routine(int (*mps_xmit)(struct sk_buff *skb))
{
svip_ve_mps_xmit = mps_xmit;
}
EXPORT_SYMBOL(register_mps_xmit_routine);
/**
* Returns a pointer to the routine used to deliver an incoming packet/message
* from the MPS mailbox to the networking layer. This routine is called by MPS
* driver during initialisation time.
*
* \param skb pointer to incoming socket buffer
*
* \return svip_ve_rx pointer to incoming messages delivering routine
*
* \ingroup Internal
*/
int (*register_mps_recv_routine(void)) (struct sk_buff *skb)
{
return svip_ve_rx;
}
/**
* Used to deliver outgoing packets to VoFW0 module through the MPS driver.
* Upon loading/initialisation the MPS driver is registering a transmitting
* routine, which is called here to deliver the packet to the VoFW0 module.
*
* \param skb pointer to skb containing outgoing data
* \param dev pointer to this networking device's data
*
* \return 0 on success
* \return non-zero on error
*
* \ingroup Internal
*/
static int svip_ve_xmit(struct sk_buff *skb, struct net_device *dev)
{
int err;
struct svip_ve_priv *priv = netdev_priv(dev);
struct net_device_stats *stats = &priv->stats;
stats->tx_packets++;
stats->tx_bytes += skb->len;
if (svip_ve_mps_xmit)
{
err = svip_ve_mps_xmit(skb);
if (err)
stats->tx_errors++;
dev->trans_start = jiffies;
return err;
}
else
printk(KERN_ERR "%s: MPS driver not registered, outgoing packet not delivered\n", dev->name);
dev_kfree_skb(skb);
return -1;
}
/**
* Called by MPS driver upon receipt of a new message from VoFW0 module in
* the data inbox. The packet is pushed up the IP module for further processing.
*
* \param skb pointer to skb containing the incoming message
*
* \return 0 on success
* \return non-zero on error
*
* \ingroup Internal
*/
int svip_ve_rx(struct sk_buff *skb)
{
int err;
struct svip_ve_priv *priv = netdev_priv(svip_ve_dev);
struct net_device_stats *stats = &priv->stats;
skb->dev = svip_ve_dev;
skb->protocol = eth_type_trans(skb, svip_ve_dev);
stats->rx_packets++;
stats->rx_bytes += skb->len;
err = netif_rx(skb);
switch (err)
{
case NET_RX_SUCCESS:
return 0;
break;
case NET_RX_DROP:
default:
stats->rx_dropped++;
break;
}
return 1;
}
EXPORT_SYMBOL(svip_ve_rx);
/**
* Returns a pointer to the device's networking statistics data
*
* \param dev pointer to this networking device's data
*
* \return stats pointer to this network device's statistics data
*
* \ingroup Internal
*/
static struct net_device_stats *svip_ve_get_stats(struct net_device *dev)
{
struct svip_ve_priv *priv = netdev_priv(dev);
return &priv->stats;
}
static void svip_ve_tx_timeout(struct net_device *dev)
{
struct svip_ve_priv *priv = netdev_priv(dev);
priv->stats.tx_errors++;
netif_wake_queue(dev);
}
/**
* Device open routine. Called e.g. upon setting of an IP address using,
* 'ifconfig veth0 YYY.YYY.YYY.YYY netmask ZZZ.ZZZ.ZZZ.ZZZ' or
* 'ifconfig veth0 up'
*
* \param dev pointer to this network device's data
*
* \return 0 on success
* \return non-zero on error
*
* \ingroup Internal
*/
int svip_ve_open(struct net_device *dev)
{
netif_start_queue(dev);
return 0;
}
/**
* Device close routine. Called e.g. upon calling
* 'ifconfig veth0 down'
*
* \param dev pointer to this network device's data
*
* \return 0 on success
* \return non-zero on error
*
* \ingroup Internal
*/
int svip_ve_release(struct net_device *dev)
{
netif_stop_queue(dev);
return 0;
}
static int svip_ve_dev_init(struct net_device *dev);
static const struct net_device_ops svip_virtual_eth_netdev_ops = {
.ndo_init = svip_ve_dev_init,
.ndo_open = svip_ve_open,
.ndo_stop = svip_ve_release,
.ndo_start_xmit = svip_ve_xmit,
.ndo_get_stats = svip_ve_get_stats,
.ndo_tx_timeout = svip_ve_tx_timeout,
};
/**
* Device initialisation routine which registers device interface routines.
* It is called upon execution of 'register_netdev' routine.
*
* \param dev pointer to this network device's data
*
* \return 0 on success
* \return non-zero on error
*
* \ingroup Internal
*/
static int svip_ve_dev_init(struct net_device *dev)
{
ether_setup(dev); /* assign some of the fields */
dev->watchdog_timeo = watchdog_timeout;
memset(netdev_priv(dev), 0, sizeof(struct svip_ve_priv));
dev->flags |= IFF_NOARP|IFF_PROMISC;
dev->flags &= ~IFF_MULTICAST;
/* dedicated MAC address to veth0, 00:03:19:00:15:80 */
dev->dev_addr[0] = 0x00;
dev->dev_addr[1] = 0x03;
dev->dev_addr[2] = 0x19;
dev->dev_addr[3] = 0x00;
dev->dev_addr[4] = 0x15;
dev->dev_addr[5] = 0x80;
return 0;
}
static int svip_ve_probe(struct platform_device *dev)
{
int result = 0;
svip_ve_dev = alloc_etherdev(sizeof(struct svip_ve_priv));
svip_ve_dev->netdev_ops = &svip_virtual_eth_netdev_ops;
strcpy(svip_ve_dev->name, "veth%d");
result = register_netdev(svip_ve_dev);
if (result)
{
printk(KERN_INFO "error %i registering device \"%s\"\n", result, svip_ve_dev->name);
goto out;
}
printk (KERN_INFO "%s, (c) 2009, Lantiq Deutschland GmbH\n", &SVIP_VETH_INFO_STR[4]);
out:
return result;
}
static int svip_ve_remove(struct platform_device *dev)
{
unregister_netdev(svip_ve_dev);
free_netdev(svip_ve_dev);
printk(KERN_INFO "%s removed\n", svip_ve_dev->name);
return 0;
}
static struct platform_driver svip_ve_driver = {
.probe = svip_ve_probe,
.remove = svip_ve_remove,
.driver = {
.name = "ifxmips_svip_ve",
.owner = THIS_MODULE,
},
};
/**
* Module/driver entry routine
*/
static int __init svip_ve_init_module(void)
{
int ret;
ret = platform_driver_register(&svip_ve_driver);
if (ret)
printk(KERN_INFO "SVIP: error(%d) registering virtual Ethernet driver!\n", ret);
return ret;
}
/**
* Module exit routine (never called for statically linked driver)
*/
static void __exit svip_ve_cleanup_module(void)
{
platform_driver_unregister(&svip_ve_driver);
}
module_init(svip_ve_init_module);
module_exit(svip_ve_cleanup_module);
MODULE_LICENSE("GPL");
MODULE_DESCRIPTION("virtual ethernet driver for LANTIQ SVIP system");
EXPORT_SYMBOL(register_mps_recv_routine);
|