author | Florian Pose <fp@igh-essen.com> |
Wed, 28 Oct 2009 14:59:34 +0100 | |
changeset 1552 | c9e2c3be294e |
parent 1542 | 91ae9c95dd2e |
child 1555 | 7679e98b0bb1 |
permissions | -rw-r--r-- |
1540
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
1 |
/****************************************************************************** |
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
2 |
* |
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
3 |
* $Id$ |
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
4 |
* |
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
5 |
* Copyright (C) 2006-2008 Florian Pose, Ingenieurgemeinschaft IgH |
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
6 |
* |
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
7 |
* This file is part of the IgH EtherCAT Master. |
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
8 |
* |
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
9 |
* The IgH EtherCAT Master is free software; you can redistribute it and/or |
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
10 |
* modify it under the terms of the GNU General Public License version 2, as |
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
11 |
* published by the Free Software Foundation. |
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
12 |
* |
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
13 |
* The IgH EtherCAT Master is distributed in the hope that it will be useful, |
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
14 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
15 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General |
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
16 |
* Public License for more details. |
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
17 |
* |
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
18 |
* You should have received a copy of the GNU General Public License along |
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
19 |
* with the IgH EtherCAT Master; if not, write to the Free Software |
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
20 |
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
21 |
* |
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
22 |
* --- |
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
23 |
* |
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
24 |
* The license mentioned above concerns the source code only. Using the |
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
25 |
* EtherCAT technology and brand is only permitted in compliance with the |
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
26 |
* industrial property and similar rights of Beckhoff Automation GmbH. |
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
27 |
* |
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
28 |
*****************************************************************************/ |
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
29 |
|
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
30 |
/** \file |
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
31 |
* EtherCAT generic Ethernet device module. |
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
32 |
*/ |
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
33 |
|
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
34 |
/*****************************************************************************/ |
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
35 |
|
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
36 |
#include <linux/module.h> |
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
37 |
#include <linux/device.h> |
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
38 |
#include <linux/err.h> |
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
39 |
#include <linux/version.h> |
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
40 |
#include <linux/if_arp.h> /* ARPHRD_ETHER */ |
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
41 |
#include <linux/etherdevice.h> |
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
42 |
|
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
43 |
#include "../globals.h" |
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
44 |
#include "ecdev.h" |
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
45 |
|
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
46 |
#define PFX "ec_generic: " |
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
47 |
|
1541
26ac1c611100
Sending via generic device works.
Florian Pose <fp@igh-essen.com>
parents:
1540
diff
changeset
|
48 |
#define ETH_P_ETHERCAT 0x88A4 |
26ac1c611100
Sending via generic device works.
Florian Pose <fp@igh-essen.com>
parents:
1540
diff
changeset
|
49 |
|
1540
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
50 |
/*****************************************************************************/ |
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
51 |
|
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
52 |
int __init ec_gen_init_module(void); |
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
53 |
void __exit ec_gen_cleanup_module(void); |
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
54 |
|
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
55 |
/*****************************************************************************/ |
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
56 |
|
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
57 |
/** \cond */ |
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
58 |
|
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
59 |
MODULE_AUTHOR("Florian Pose <fp@igh-essen.com>"); |
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
60 |
MODULE_DESCRIPTION("EtherCAT master generic Ethernet device module"); |
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
61 |
MODULE_LICENSE("GPL"); |
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
62 |
MODULE_VERSION(EC_MASTER_VERSION); |
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
63 |
|
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
64 |
/** \endcond */ |
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
65 |
|
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
66 |
struct list_head generic_devices; |
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
67 |
|
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
68 |
typedef struct { |
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
69 |
struct list_head list; |
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
70 |
struct net_device *netdev; |
1541
26ac1c611100
Sending via generic device works.
Florian Pose <fp@igh-essen.com>
parents:
1540
diff
changeset
|
71 |
struct socket *socket; |
1540
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
72 |
ec_device_t *ecdev; |
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
73 |
} ec_gen_device_t; |
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
74 |
|
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
75 |
int ec_gen_device_open(ec_gen_device_t *); |
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
76 |
int ec_gen_device_stop(ec_gen_device_t *); |
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
77 |
int ec_gen_device_start_xmit(ec_gen_device_t *, struct sk_buff *); |
1542
91ae9c95dd2e
Implemented poll(); receiving on generic device also works.
Florian Pose <fp@igh-essen.com>
parents:
1541
diff
changeset
|
78 |
void ec_gen_device_poll(ec_gen_device_t *); |
1540
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
79 |
|
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
80 |
/*****************************************************************************/ |
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
81 |
|
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
82 |
static int ec_gen_netdev_open(struct net_device *dev) |
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
83 |
{ |
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
84 |
ec_gen_device_t *gendev = *((ec_gen_device_t **) netdev_priv(dev)); |
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
85 |
return ec_gen_device_open(gendev); |
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
86 |
} |
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
87 |
|
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
88 |
/*****************************************************************************/ |
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
89 |
|
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
90 |
static int ec_gen_netdev_stop(struct net_device *dev) |
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
91 |
{ |
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
92 |
ec_gen_device_t *gendev = *((ec_gen_device_t **) netdev_priv(dev)); |
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
93 |
return ec_gen_device_stop(gendev); |
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
94 |
} |
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
95 |
|
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
96 |
/*****************************************************************************/ |
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
97 |
|
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
98 |
static int ec_gen_netdev_start_xmit( |
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
99 |
struct sk_buff *skb, |
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
100 |
struct net_device *dev |
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
101 |
) |
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
102 |
{ |
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
103 |
ec_gen_device_t *gendev = *((ec_gen_device_t **) netdev_priv(dev)); |
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
104 |
return ec_gen_device_start_xmit(gendev, skb); |
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
105 |
} |
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
106 |
|
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
107 |
/*****************************************************************************/ |
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
108 |
|
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
109 |
void ec_gen_poll(struct net_device *dev) |
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
110 |
{ |
1542
91ae9c95dd2e
Implemented poll(); receiving on generic device also works.
Florian Pose <fp@igh-essen.com>
parents:
1541
diff
changeset
|
111 |
ec_gen_device_t *gendev = *((ec_gen_device_t **) netdev_priv(dev)); |
91ae9c95dd2e
Implemented poll(); receiving on generic device also works.
Florian Pose <fp@igh-essen.com>
parents:
1541
diff
changeset
|
112 |
ec_gen_device_poll(gendev); |
1540
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
113 |
} |
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
114 |
|
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
115 |
/*****************************************************************************/ |
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
116 |
|
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
117 |
static const struct net_device_ops ec_gen_netdev_ops = { |
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
118 |
.ndo_open = ec_gen_netdev_open, |
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
119 |
.ndo_stop = ec_gen_netdev_stop, |
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
120 |
.ndo_start_xmit = ec_gen_netdev_start_xmit, |
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
121 |
}; |
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
122 |
|
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
123 |
/*****************************************************************************/ |
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
124 |
|
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
125 |
/** Init generic device. |
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
126 |
*/ |
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
127 |
int ec_gen_device_init( |
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
128 |
ec_gen_device_t *dev, |
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
129 |
struct net_device *real_netdev |
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
130 |
) |
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
131 |
{ |
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
132 |
ec_gen_device_t **priv; |
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
133 |
char null = 0x00; |
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
134 |
|
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
135 |
dev->ecdev = NULL; |
1541
26ac1c611100
Sending via generic device works.
Florian Pose <fp@igh-essen.com>
parents:
1540
diff
changeset
|
136 |
dev->socket = NULL; |
1540
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
137 |
|
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
138 |
dev->netdev = alloc_netdev(sizeof(ec_gen_device_t *), &null, ether_setup); |
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
139 |
if (!dev->netdev) { |
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
140 |
return -ENOMEM; |
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
141 |
} |
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
142 |
memcpy(dev->netdev->dev_addr, real_netdev->dev_addr, ETH_ALEN); |
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
143 |
dev->netdev->netdev_ops = &ec_gen_netdev_ops; |
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
144 |
priv = netdev_priv(dev->netdev); |
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
145 |
*priv = dev; |
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
146 |
|
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
147 |
return 0; |
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
148 |
} |
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
149 |
|
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
150 |
/*****************************************************************************/ |
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
151 |
|
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
152 |
/** Clear generic device. |
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
153 |
*/ |
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
154 |
void ec_gen_device_clear( |
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
155 |
ec_gen_device_t *dev |
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
156 |
) |
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
157 |
{ |
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
158 |
if (dev->ecdev) { |
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
159 |
ecdev_close(dev->ecdev); |
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
160 |
ecdev_withdraw(dev->ecdev); |
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
161 |
} |
1541
26ac1c611100
Sending via generic device works.
Florian Pose <fp@igh-essen.com>
parents:
1540
diff
changeset
|
162 |
if (dev->socket) { |
26ac1c611100
Sending via generic device works.
Florian Pose <fp@igh-essen.com>
parents:
1540
diff
changeset
|
163 |
sock_release(dev->socket); |
26ac1c611100
Sending via generic device works.
Florian Pose <fp@igh-essen.com>
parents:
1540
diff
changeset
|
164 |
} |
1540
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
165 |
free_netdev(dev->netdev); |
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
166 |
} |
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
167 |
|
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
168 |
/*****************************************************************************/ |
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
169 |
|
1541
26ac1c611100
Sending via generic device works.
Florian Pose <fp@igh-essen.com>
parents:
1540
diff
changeset
|
170 |
/** Creates a network socket. |
26ac1c611100
Sending via generic device works.
Florian Pose <fp@igh-essen.com>
parents:
1540
diff
changeset
|
171 |
*/ |
26ac1c611100
Sending via generic device works.
Florian Pose <fp@igh-essen.com>
parents:
1540
diff
changeset
|
172 |
int ec_gen_device_create_socket( |
26ac1c611100
Sending via generic device works.
Florian Pose <fp@igh-essen.com>
parents:
1540
diff
changeset
|
173 |
ec_gen_device_t *dev, |
26ac1c611100
Sending via generic device works.
Florian Pose <fp@igh-essen.com>
parents:
1540
diff
changeset
|
174 |
struct net_device *real_netdev |
26ac1c611100
Sending via generic device works.
Florian Pose <fp@igh-essen.com>
parents:
1540
diff
changeset
|
175 |
) |
26ac1c611100
Sending via generic device works.
Florian Pose <fp@igh-essen.com>
parents:
1540
diff
changeset
|
176 |
{ |
26ac1c611100
Sending via generic device works.
Florian Pose <fp@igh-essen.com>
parents:
1540
diff
changeset
|
177 |
int ret; |
26ac1c611100
Sending via generic device works.
Florian Pose <fp@igh-essen.com>
parents:
1540
diff
changeset
|
178 |
struct sockaddr_ll sa; |
26ac1c611100
Sending via generic device works.
Florian Pose <fp@igh-essen.com>
parents:
1540
diff
changeset
|
179 |
|
26ac1c611100
Sending via generic device works.
Florian Pose <fp@igh-essen.com>
parents:
1540
diff
changeset
|
180 |
ret = sock_create_kern(PF_PACKET, SOCK_RAW, htons(ETH_P_ETHERCAT), &dev->socket); |
26ac1c611100
Sending via generic device works.
Florian Pose <fp@igh-essen.com>
parents:
1540
diff
changeset
|
181 |
if (ret) { |
26ac1c611100
Sending via generic device works.
Florian Pose <fp@igh-essen.com>
parents:
1540
diff
changeset
|
182 |
printk(KERN_ERR PFX "Failed to create socket.\n"); |
26ac1c611100
Sending via generic device works.
Florian Pose <fp@igh-essen.com>
parents:
1540
diff
changeset
|
183 |
return ret; |
26ac1c611100
Sending via generic device works.
Florian Pose <fp@igh-essen.com>
parents:
1540
diff
changeset
|
184 |
} |
26ac1c611100
Sending via generic device works.
Florian Pose <fp@igh-essen.com>
parents:
1540
diff
changeset
|
185 |
|
26ac1c611100
Sending via generic device works.
Florian Pose <fp@igh-essen.com>
parents:
1540
diff
changeset
|
186 |
printk(KERN_ERR PFX "Binding socket to interface %i (%s).\n", |
26ac1c611100
Sending via generic device works.
Florian Pose <fp@igh-essen.com>
parents:
1540
diff
changeset
|
187 |
real_netdev->ifindex, real_netdev->name); |
26ac1c611100
Sending via generic device works.
Florian Pose <fp@igh-essen.com>
parents:
1540
diff
changeset
|
188 |
|
26ac1c611100
Sending via generic device works.
Florian Pose <fp@igh-essen.com>
parents:
1540
diff
changeset
|
189 |
memset(&sa, 0x00, sizeof(sa)); |
26ac1c611100
Sending via generic device works.
Florian Pose <fp@igh-essen.com>
parents:
1540
diff
changeset
|
190 |
sa.sll_family = AF_PACKET; |
26ac1c611100
Sending via generic device works.
Florian Pose <fp@igh-essen.com>
parents:
1540
diff
changeset
|
191 |
sa.sll_protocol = htons(ETH_P_ETHERCAT); |
26ac1c611100
Sending via generic device works.
Florian Pose <fp@igh-essen.com>
parents:
1540
diff
changeset
|
192 |
sa.sll_ifindex = real_netdev->ifindex; |
26ac1c611100
Sending via generic device works.
Florian Pose <fp@igh-essen.com>
parents:
1540
diff
changeset
|
193 |
ret = kernel_bind(dev->socket, (struct sockaddr *) &sa, sizeof(sa)); |
26ac1c611100
Sending via generic device works.
Florian Pose <fp@igh-essen.com>
parents:
1540
diff
changeset
|
194 |
if (ret) { |
26ac1c611100
Sending via generic device works.
Florian Pose <fp@igh-essen.com>
parents:
1540
diff
changeset
|
195 |
printk(KERN_ERR PFX "Failed to bind() socket to interface.\n"); |
26ac1c611100
Sending via generic device works.
Florian Pose <fp@igh-essen.com>
parents:
1540
diff
changeset
|
196 |
sock_release(dev->socket); |
26ac1c611100
Sending via generic device works.
Florian Pose <fp@igh-essen.com>
parents:
1540
diff
changeset
|
197 |
dev->socket = NULL; |
26ac1c611100
Sending via generic device works.
Florian Pose <fp@igh-essen.com>
parents:
1540
diff
changeset
|
198 |
return ret; |
26ac1c611100
Sending via generic device works.
Florian Pose <fp@igh-essen.com>
parents:
1540
diff
changeset
|
199 |
} |
26ac1c611100
Sending via generic device works.
Florian Pose <fp@igh-essen.com>
parents:
1540
diff
changeset
|
200 |
|
26ac1c611100
Sending via generic device works.
Florian Pose <fp@igh-essen.com>
parents:
1540
diff
changeset
|
201 |
return 0; |
26ac1c611100
Sending via generic device works.
Florian Pose <fp@igh-essen.com>
parents:
1540
diff
changeset
|
202 |
} |
26ac1c611100
Sending via generic device works.
Florian Pose <fp@igh-essen.com>
parents:
1540
diff
changeset
|
203 |
|
26ac1c611100
Sending via generic device works.
Florian Pose <fp@igh-essen.com>
parents:
1540
diff
changeset
|
204 |
/*****************************************************************************/ |
26ac1c611100
Sending via generic device works.
Florian Pose <fp@igh-essen.com>
parents:
1540
diff
changeset
|
205 |
|
1540
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
206 |
/** Offer generic device to master. |
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
207 |
*/ |
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
208 |
int ec_gen_device_offer( |
1541
26ac1c611100
Sending via generic device works.
Florian Pose <fp@igh-essen.com>
parents:
1540
diff
changeset
|
209 |
ec_gen_device_t *dev, |
26ac1c611100
Sending via generic device works.
Florian Pose <fp@igh-essen.com>
parents:
1540
diff
changeset
|
210 |
struct net_device *real_netdev |
1540
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
211 |
) |
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
212 |
{ |
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
213 |
int ret = 0; |
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
214 |
|
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
215 |
dev->ecdev = ecdev_offer(dev->netdev, ec_gen_poll, THIS_MODULE); |
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
216 |
if (dev->ecdev) { |
1541
26ac1c611100
Sending via generic device works.
Florian Pose <fp@igh-essen.com>
parents:
1540
diff
changeset
|
217 |
if (ec_gen_device_create_socket(dev, real_netdev)) { |
26ac1c611100
Sending via generic device works.
Florian Pose <fp@igh-essen.com>
parents:
1540
diff
changeset
|
218 |
ecdev_withdraw(dev->ecdev); |
26ac1c611100
Sending via generic device works.
Florian Pose <fp@igh-essen.com>
parents:
1540
diff
changeset
|
219 |
dev->ecdev = NULL; |
26ac1c611100
Sending via generic device works.
Florian Pose <fp@igh-essen.com>
parents:
1540
diff
changeset
|
220 |
} else if (ecdev_open(dev->ecdev)) { |
1540
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
221 |
ecdev_withdraw(dev->ecdev); |
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
222 |
dev->ecdev = NULL; |
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
223 |
} else { |
1541
26ac1c611100
Sending via generic device works.
Florian Pose <fp@igh-essen.com>
parents:
1540
diff
changeset
|
224 |
ecdev_set_link(dev->ecdev, 1); // FIXME |
1540
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
225 |
ret = 1; |
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
226 |
} |
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
227 |
} |
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
228 |
|
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
229 |
return ret; |
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
230 |
} |
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
231 |
|
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
232 |
/*****************************************************************************/ |
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
233 |
|
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
234 |
/** Open the device. |
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
235 |
*/ |
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
236 |
int ec_gen_device_open( |
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
237 |
ec_gen_device_t *dev |
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
238 |
) |
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
239 |
{ |
1541
26ac1c611100
Sending via generic device works.
Florian Pose <fp@igh-essen.com>
parents:
1540
diff
changeset
|
240 |
return 0; |
1540
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
241 |
} |
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
242 |
|
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
243 |
/*****************************************************************************/ |
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
244 |
|
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
245 |
/** Stop the device. |
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
246 |
*/ |
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
247 |
int ec_gen_device_stop( |
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
248 |
ec_gen_device_t *dev |
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
249 |
) |
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
250 |
{ |
1541
26ac1c611100
Sending via generic device works.
Florian Pose <fp@igh-essen.com>
parents:
1540
diff
changeset
|
251 |
return 0; |
1540
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
252 |
} |
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
253 |
|
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
254 |
/*****************************************************************************/ |
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
255 |
|
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
256 |
int ec_gen_device_start_xmit( |
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
257 |
ec_gen_device_t *dev, |
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
258 |
struct sk_buff *skb |
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
259 |
) |
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
260 |
{ |
1541
26ac1c611100
Sending via generic device works.
Florian Pose <fp@igh-essen.com>
parents:
1540
diff
changeset
|
261 |
struct msghdr msg; |
26ac1c611100
Sending via generic device works.
Florian Pose <fp@igh-essen.com>
parents:
1540
diff
changeset
|
262 |
struct kvec iov; |
26ac1c611100
Sending via generic device works.
Florian Pose <fp@igh-essen.com>
parents:
1540
diff
changeset
|
263 |
size_t len = skb->len; |
26ac1c611100
Sending via generic device works.
Florian Pose <fp@igh-essen.com>
parents:
1540
diff
changeset
|
264 |
int ret; |
26ac1c611100
Sending via generic device works.
Florian Pose <fp@igh-essen.com>
parents:
1540
diff
changeset
|
265 |
|
26ac1c611100
Sending via generic device works.
Florian Pose <fp@igh-essen.com>
parents:
1540
diff
changeset
|
266 |
iov.iov_base = skb->data; |
26ac1c611100
Sending via generic device works.
Florian Pose <fp@igh-essen.com>
parents:
1540
diff
changeset
|
267 |
iov.iov_len = len; |
26ac1c611100
Sending via generic device works.
Florian Pose <fp@igh-essen.com>
parents:
1540
diff
changeset
|
268 |
memset(&msg, 0, sizeof(msg)); |
26ac1c611100
Sending via generic device works.
Florian Pose <fp@igh-essen.com>
parents:
1540
diff
changeset
|
269 |
|
26ac1c611100
Sending via generic device works.
Florian Pose <fp@igh-essen.com>
parents:
1540
diff
changeset
|
270 |
ret = kernel_sendmsg(dev->socket, &msg, &iov, 1, len); |
26ac1c611100
Sending via generic device works.
Florian Pose <fp@igh-essen.com>
parents:
1540
diff
changeset
|
271 |
|
26ac1c611100
Sending via generic device works.
Florian Pose <fp@igh-essen.com>
parents:
1540
diff
changeset
|
272 |
return ret == len ? NETDEV_TX_OK : NETDEV_TX_BUSY; |
1540
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
273 |
} |
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
274 |
|
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
275 |
/*****************************************************************************/ |
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
276 |
|
1542
91ae9c95dd2e
Implemented poll(); receiving on generic device also works.
Florian Pose <fp@igh-essen.com>
parents:
1541
diff
changeset
|
277 |
/** Polls the device. |
91ae9c95dd2e
Implemented poll(); receiving on generic device also works.
Florian Pose <fp@igh-essen.com>
parents:
1541
diff
changeset
|
278 |
*/ |
91ae9c95dd2e
Implemented poll(); receiving on generic device also works.
Florian Pose <fp@igh-essen.com>
parents:
1541
diff
changeset
|
279 |
void ec_gen_device_poll( |
91ae9c95dd2e
Implemented poll(); receiving on generic device also works.
Florian Pose <fp@igh-essen.com>
parents:
1541
diff
changeset
|
280 |
ec_gen_device_t *dev |
91ae9c95dd2e
Implemented poll(); receiving on generic device also works.
Florian Pose <fp@igh-essen.com>
parents:
1541
diff
changeset
|
281 |
) |
91ae9c95dd2e
Implemented poll(); receiving on generic device also works.
Florian Pose <fp@igh-essen.com>
parents:
1541
diff
changeset
|
282 |
{ |
91ae9c95dd2e
Implemented poll(); receiving on generic device also works.
Florian Pose <fp@igh-essen.com>
parents:
1541
diff
changeset
|
283 |
struct msghdr msg; |
91ae9c95dd2e
Implemented poll(); receiving on generic device also works.
Florian Pose <fp@igh-essen.com>
parents:
1541
diff
changeset
|
284 |
struct kvec iov; |
91ae9c95dd2e
Implemented poll(); receiving on generic device also works.
Florian Pose <fp@igh-essen.com>
parents:
1541
diff
changeset
|
285 |
char buf[2000]; // FIXME |
91ae9c95dd2e
Implemented poll(); receiving on generic device also works.
Florian Pose <fp@igh-essen.com>
parents:
1541
diff
changeset
|
286 |
int ret, budget = 10; // FIXME |
91ae9c95dd2e
Implemented poll(); receiving on generic device also works.
Florian Pose <fp@igh-essen.com>
parents:
1541
diff
changeset
|
287 |
|
91ae9c95dd2e
Implemented poll(); receiving on generic device also works.
Florian Pose <fp@igh-essen.com>
parents:
1541
diff
changeset
|
288 |
iov.iov_base = buf; |
91ae9c95dd2e
Implemented poll(); receiving on generic device also works.
Florian Pose <fp@igh-essen.com>
parents:
1541
diff
changeset
|
289 |
iov.iov_len = 2000; |
91ae9c95dd2e
Implemented poll(); receiving on generic device also works.
Florian Pose <fp@igh-essen.com>
parents:
1541
diff
changeset
|
290 |
memset(&msg, 0, sizeof(msg)); |
91ae9c95dd2e
Implemented poll(); receiving on generic device also works.
Florian Pose <fp@igh-essen.com>
parents:
1541
diff
changeset
|
291 |
|
91ae9c95dd2e
Implemented poll(); receiving on generic device also works.
Florian Pose <fp@igh-essen.com>
parents:
1541
diff
changeset
|
292 |
do { |
91ae9c95dd2e
Implemented poll(); receiving on generic device also works.
Florian Pose <fp@igh-essen.com>
parents:
1541
diff
changeset
|
293 |
ret = kernel_recvmsg(dev->socket, &msg, &iov, 1, iov.iov_len, |
91ae9c95dd2e
Implemented poll(); receiving on generic device also works.
Florian Pose <fp@igh-essen.com>
parents:
1541
diff
changeset
|
294 |
MSG_DONTWAIT); |
91ae9c95dd2e
Implemented poll(); receiving on generic device also works.
Florian Pose <fp@igh-essen.com>
parents:
1541
diff
changeset
|
295 |
if (ret > 0) { |
91ae9c95dd2e
Implemented poll(); receiving on generic device also works.
Florian Pose <fp@igh-essen.com>
parents:
1541
diff
changeset
|
296 |
ecdev_receive(dev->ecdev, buf, ret); |
91ae9c95dd2e
Implemented poll(); receiving on generic device also works.
Florian Pose <fp@igh-essen.com>
parents:
1541
diff
changeset
|
297 |
} else if (ret < 0) { |
91ae9c95dd2e
Implemented poll(); receiving on generic device also works.
Florian Pose <fp@igh-essen.com>
parents:
1541
diff
changeset
|
298 |
break; |
91ae9c95dd2e
Implemented poll(); receiving on generic device also works.
Florian Pose <fp@igh-essen.com>
parents:
1541
diff
changeset
|
299 |
} |
91ae9c95dd2e
Implemented poll(); receiving on generic device also works.
Florian Pose <fp@igh-essen.com>
parents:
1541
diff
changeset
|
300 |
budget--; |
91ae9c95dd2e
Implemented poll(); receiving on generic device also works.
Florian Pose <fp@igh-essen.com>
parents:
1541
diff
changeset
|
301 |
} while (budget); |
91ae9c95dd2e
Implemented poll(); receiving on generic device also works.
Florian Pose <fp@igh-essen.com>
parents:
1541
diff
changeset
|
302 |
} |
91ae9c95dd2e
Implemented poll(); receiving on generic device also works.
Florian Pose <fp@igh-essen.com>
parents:
1541
diff
changeset
|
303 |
|
91ae9c95dd2e
Implemented poll(); receiving on generic device also works.
Florian Pose <fp@igh-essen.com>
parents:
1541
diff
changeset
|
304 |
/*****************************************************************************/ |
91ae9c95dd2e
Implemented poll(); receiving on generic device also works.
Florian Pose <fp@igh-essen.com>
parents:
1541
diff
changeset
|
305 |
|
1540
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
306 |
/** Offer device. |
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
307 |
*/ |
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
308 |
int offer_device( |
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
309 |
struct net_device *netdev |
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
310 |
) |
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
311 |
{ |
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
312 |
ec_gen_device_t *gendev; |
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
313 |
int ret = 0; |
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
314 |
|
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
315 |
gendev = kmalloc(sizeof(ec_gen_device_t), GFP_KERNEL); |
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
316 |
if (!gendev) { |
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
317 |
return -ENOMEM; |
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
318 |
} |
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
319 |
|
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
320 |
ret = ec_gen_device_init(gendev, netdev); |
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
321 |
if (ret) { |
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
322 |
kfree(gendev); |
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
323 |
return ret; |
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
324 |
} |
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
325 |
|
1541
26ac1c611100
Sending via generic device works.
Florian Pose <fp@igh-essen.com>
parents:
1540
diff
changeset
|
326 |
if (ec_gen_device_offer(gendev, netdev)) { |
1540
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
327 |
list_add_tail(&gendev->list, &generic_devices); |
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
328 |
} else { |
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
329 |
ec_gen_device_clear(gendev); |
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
330 |
kfree(gendev); |
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
331 |
} |
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
332 |
|
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
333 |
return ret; |
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
334 |
} |
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
335 |
|
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
336 |
/*****************************************************************************/ |
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
337 |
|
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
338 |
/** Clear devices. |
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
339 |
*/ |
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
340 |
void clear_devices(void) |
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
341 |
{ |
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
342 |
ec_gen_device_t *gendev, *next; |
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
343 |
|
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
344 |
list_for_each_entry_safe(gendev, next, &generic_devices, list) { |
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
345 |
list_del(&gendev->list); |
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
346 |
ec_gen_device_clear(gendev); |
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
347 |
kfree(gendev); |
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
348 |
} |
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
349 |
} |
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
350 |
|
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
351 |
/*****************************************************************************/ |
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
352 |
|
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
353 |
/** Module initialization. |
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
354 |
* |
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
355 |
* Initializes \a master_count masters. |
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
356 |
* \return 0 on success, else < 0 |
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
357 |
*/ |
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
358 |
int __init ec_gen_init_module(void) |
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
359 |
{ |
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
360 |
int ret = 0; |
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
361 |
struct net_device *netdev; |
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
362 |
|
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
363 |
printk(KERN_INFO PFX "EtherCAT master generic Ethernet device module %s\n", |
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
364 |
EC_MASTER_VERSION); |
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
365 |
|
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
366 |
INIT_LIST_HEAD(&generic_devices); |
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
367 |
|
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
368 |
read_lock(&dev_base_lock); |
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
369 |
for_each_netdev(&init_net, netdev) { |
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
370 |
if (netdev->type != ARPHRD_ETHER) |
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
371 |
continue; |
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
372 |
ret = offer_device(netdev); |
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
373 |
if (ret) { |
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
374 |
read_unlock(&dev_base_lock); |
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
375 |
goto out_err; |
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
376 |
} |
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
377 |
} |
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
378 |
read_unlock(&dev_base_lock); |
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
379 |
return ret; |
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
380 |
|
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
381 |
out_err: |
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
382 |
clear_devices(); |
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
383 |
return ret; |
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
384 |
} |
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
385 |
|
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
386 |
/*****************************************************************************/ |
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
387 |
|
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
388 |
/** Module cleanup. |
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
389 |
* |
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
390 |
* Clears all master instances. |
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
391 |
*/ |
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
392 |
void __exit ec_gen_cleanup_module(void) |
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
393 |
{ |
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
394 |
clear_devices(); |
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
395 |
printk(KERN_INFO PFX "Unloading.\n"); |
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
396 |
} |
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
397 |
|
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
398 |
/*****************************************************************************/ |
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
399 |
|
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
400 |
/** \cond */ |
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
401 |
|
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
402 |
module_init(ec_gen_init_module); |
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
403 |
module_exit(ec_gen_cleanup_module); |
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
404 |
|
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
405 |
/** \endcond */ |
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
406 |
|
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
407 |
/*****************************************************************************/ |