author | Florian Pose <fp@igh-essen.com> |
Thu, 15 Dec 2011 14:05:44 +0100 | |
branch | stable-1.5 |
changeset 2202 | 14728d0c4a66 |
parent 2170 | e69a5010914f |
child 2631 | 827abf3c50de |
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 |
|
1558
55213fcc93a6
generic device receive buffer in heap.
Florian Pose <fp@igh-essen.com>
parents:
1557
diff
changeset
|
50 |
#define EC_GEN_RX_BUF_SIZE 1600 |
55213fcc93a6
generic device receive buffer in heap.
Florian Pose <fp@igh-essen.com>
parents:
1557
diff
changeset
|
51 |
|
1540
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
52 |
/*****************************************************************************/ |
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
53 |
|
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
54 |
int __init ec_gen_init_module(void); |
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
55 |
void __exit ec_gen_cleanup_module(void); |
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 |
/*****************************************************************************/ |
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 |
/** \cond */ |
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
60 |
|
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
61 |
MODULE_AUTHOR("Florian Pose <fp@igh-essen.com>"); |
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
62 |
MODULE_DESCRIPTION("EtherCAT master generic Ethernet device module"); |
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
63 |
MODULE_LICENSE("GPL"); |
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
64 |
MODULE_VERSION(EC_MASTER_VERSION); |
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 |
/** \endcond */ |
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 |
struct list_head generic_devices; |
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
69 |
|
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
70 |
typedef struct { |
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
71 |
struct list_head list; |
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
72 |
struct net_device *netdev; |
1612 | 73 |
struct net_device *used_netdev; |
74 |
struct socket *socket; |
|
1540
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
75 |
ec_device_t *ecdev; |
1558
55213fcc93a6
generic device receive buffer in heap.
Florian Pose <fp@igh-essen.com>
parents:
1557
diff
changeset
|
76 |
uint8_t *rx_buf; |
1540
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
77 |
} ec_gen_device_t; |
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
78 |
|
1557
daf92232d9c5
Fixed bug in generic driver failing to create debug interfaces, because the
Florian Pose <fp@igh-essen.com>
parents:
1555
diff
changeset
|
79 |
typedef struct { |
daf92232d9c5
Fixed bug in generic driver failing to create debug interfaces, because the
Florian Pose <fp@igh-essen.com>
parents:
1555
diff
changeset
|
80 |
struct list_head list; |
1612 | 81 |
struct net_device *netdev; |
82 |
char name[IFNAMSIZ]; |
|
1557
daf92232d9c5
Fixed bug in generic driver failing to create debug interfaces, because the
Florian Pose <fp@igh-essen.com>
parents:
1555
diff
changeset
|
83 |
int ifindex; |
daf92232d9c5
Fixed bug in generic driver failing to create debug interfaces, because the
Florian Pose <fp@igh-essen.com>
parents:
1555
diff
changeset
|
84 |
uint8_t dev_addr[ETH_ALEN]; |
daf92232d9c5
Fixed bug in generic driver failing to create debug interfaces, because the
Florian Pose <fp@igh-essen.com>
parents:
1555
diff
changeset
|
85 |
} ec_gen_interface_desc_t; |
daf92232d9c5
Fixed bug in generic driver failing to create debug interfaces, because the
Florian Pose <fp@igh-essen.com>
parents:
1555
diff
changeset
|
86 |
|
1540
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
87 |
int ec_gen_device_open(ec_gen_device_t *); |
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
88 |
int ec_gen_device_stop(ec_gen_device_t *); |
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
89 |
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
|
90 |
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
|
91 |
|
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
92 |
/*****************************************************************************/ |
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
93 |
|
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
94 |
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
|
95 |
{ |
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
96 |
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
|
97 |
return ec_gen_device_open(gendev); |
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
98 |
} |
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
99 |
|
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
100 |
/*****************************************************************************/ |
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 |
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
|
103 |
{ |
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
104 |
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
|
105 |
return ec_gen_device_stop(gendev); |
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 |
|
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
110 |
static int ec_gen_netdev_start_xmit( |
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
111 |
struct sk_buff *skb, |
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
112 |
struct net_device *dev |
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 |
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
|
116 |
return ec_gen_device_start_xmit(gendev, skb); |
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
117 |
} |
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
118 |
|
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
119 |
/*****************************************************************************/ |
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
120 |
|
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
121 |
void ec_gen_poll(struct net_device *dev) |
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
122 |
{ |
1542
91ae9c95dd2e
Implemented poll(); receiving on generic device also works.
Florian Pose <fp@igh-essen.com>
parents:
1541
diff
changeset
|
123 |
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
|
124 |
ec_gen_device_poll(gendev); |
1540
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
125 |
} |
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 |
/*****************************************************************************/ |
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
128 |
|
1555
7679e98b0bb1
Generic driver net_device_ops for kernels < 2.6.29.
Florian Pose <fp@igh-essen.com>
parents:
1542
diff
changeset
|
129 |
#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 29) |
1540
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
130 |
static const struct net_device_ops ec_gen_netdev_ops = { |
1555
7679e98b0bb1
Generic driver net_device_ops for kernels < 2.6.29.
Florian Pose <fp@igh-essen.com>
parents:
1542
diff
changeset
|
131 |
.ndo_open = ec_gen_netdev_open, |
7679e98b0bb1
Generic driver net_device_ops for kernels < 2.6.29.
Florian Pose <fp@igh-essen.com>
parents:
1542
diff
changeset
|
132 |
.ndo_stop = ec_gen_netdev_stop, |
7679e98b0bb1
Generic driver net_device_ops for kernels < 2.6.29.
Florian Pose <fp@igh-essen.com>
parents:
1542
diff
changeset
|
133 |
.ndo_start_xmit = ec_gen_netdev_start_xmit, |
1540
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
134 |
}; |
1555
7679e98b0bb1
Generic driver net_device_ops for kernels < 2.6.29.
Florian Pose <fp@igh-essen.com>
parents:
1542
diff
changeset
|
135 |
#endif |
1540
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
136 |
|
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 |
|
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
139 |
/** Init generic device. |
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
140 |
*/ |
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
141 |
int ec_gen_device_init( |
1557
daf92232d9c5
Fixed bug in generic driver failing to create debug interfaces, because the
Florian Pose <fp@igh-essen.com>
parents:
1555
diff
changeset
|
142 |
ec_gen_device_t *dev |
1540
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
143 |
) |
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
144 |
{ |
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
145 |
ec_gen_device_t **priv; |
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
146 |
char null = 0x00; |
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
147 |
|
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
148 |
dev->ecdev = NULL; |
1541
26ac1c611100
Sending via generic device works.
Florian Pose <fp@igh-essen.com>
parents:
1540
diff
changeset
|
149 |
dev->socket = NULL; |
1558
55213fcc93a6
generic device receive buffer in heap.
Florian Pose <fp@igh-essen.com>
parents:
1557
diff
changeset
|
150 |
dev->rx_buf = NULL; |
1540
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
151 |
|
1555
7679e98b0bb1
Generic driver net_device_ops for kernels < 2.6.29.
Florian Pose <fp@igh-essen.com>
parents:
1542
diff
changeset
|
152 |
dev->netdev = alloc_netdev(sizeof(ec_gen_device_t *), &null, ether_setup); |
7679e98b0bb1
Generic driver net_device_ops for kernels < 2.6.29.
Florian Pose <fp@igh-essen.com>
parents:
1542
diff
changeset
|
153 |
if (!dev->netdev) { |
7679e98b0bb1
Generic driver net_device_ops for kernels < 2.6.29.
Florian Pose <fp@igh-essen.com>
parents:
1542
diff
changeset
|
154 |
return -ENOMEM; |
7679e98b0bb1
Generic driver net_device_ops for kernels < 2.6.29.
Florian Pose <fp@igh-essen.com>
parents:
1542
diff
changeset
|
155 |
} |
7679e98b0bb1
Generic driver net_device_ops for kernels < 2.6.29.
Florian Pose <fp@igh-essen.com>
parents:
1542
diff
changeset
|
156 |
|
7679e98b0bb1
Generic driver net_device_ops for kernels < 2.6.29.
Florian Pose <fp@igh-essen.com>
parents:
1542
diff
changeset
|
157 |
#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 29) |
1540
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
158 |
dev->netdev->netdev_ops = &ec_gen_netdev_ops; |
1555
7679e98b0bb1
Generic driver net_device_ops for kernels < 2.6.29.
Florian Pose <fp@igh-essen.com>
parents:
1542
diff
changeset
|
159 |
#else |
7679e98b0bb1
Generic driver net_device_ops for kernels < 2.6.29.
Florian Pose <fp@igh-essen.com>
parents:
1542
diff
changeset
|
160 |
dev->netdev->open = ec_gen_netdev_open; |
7679e98b0bb1
Generic driver net_device_ops for kernels < 2.6.29.
Florian Pose <fp@igh-essen.com>
parents:
1542
diff
changeset
|
161 |
dev->netdev->stop = ec_gen_netdev_stop; |
7679e98b0bb1
Generic driver net_device_ops for kernels < 2.6.29.
Florian Pose <fp@igh-essen.com>
parents:
1542
diff
changeset
|
162 |
dev->netdev->hard_start_xmit = ec_gen_netdev_start_xmit; |
7679e98b0bb1
Generic driver net_device_ops for kernels < 2.6.29.
Florian Pose <fp@igh-essen.com>
parents:
1542
diff
changeset
|
163 |
#endif |
7679e98b0bb1
Generic driver net_device_ops for kernels < 2.6.29.
Florian Pose <fp@igh-essen.com>
parents:
1542
diff
changeset
|
164 |
|
1540
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
165 |
priv = netdev_priv(dev->netdev); |
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
166 |
*priv = dev; |
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 |
return 0; |
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
169 |
} |
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
170 |
|
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
171 |
/*****************************************************************************/ |
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
172 |
|
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
173 |
/** Clear generic device. |
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
174 |
*/ |
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
175 |
void ec_gen_device_clear( |
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
176 |
ec_gen_device_t *dev |
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
177 |
) |
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
178 |
{ |
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
179 |
if (dev->ecdev) { |
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
180 |
ecdev_close(dev->ecdev); |
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
181 |
ecdev_withdraw(dev->ecdev); |
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
182 |
} |
1541
26ac1c611100
Sending via generic device works.
Florian Pose <fp@igh-essen.com>
parents:
1540
diff
changeset
|
183 |
if (dev->socket) { |
26ac1c611100
Sending via generic device works.
Florian Pose <fp@igh-essen.com>
parents:
1540
diff
changeset
|
184 |
sock_release(dev->socket); |
26ac1c611100
Sending via generic device works.
Florian Pose <fp@igh-essen.com>
parents:
1540
diff
changeset
|
185 |
} |
1540
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
186 |
free_netdev(dev->netdev); |
1558
55213fcc93a6
generic device receive buffer in heap.
Florian Pose <fp@igh-essen.com>
parents:
1557
diff
changeset
|
187 |
|
55213fcc93a6
generic device receive buffer in heap.
Florian Pose <fp@igh-essen.com>
parents:
1557
diff
changeset
|
188 |
if (dev->rx_buf) { |
55213fcc93a6
generic device receive buffer in heap.
Florian Pose <fp@igh-essen.com>
parents:
1557
diff
changeset
|
189 |
kfree(dev->rx_buf); |
55213fcc93a6
generic device receive buffer in heap.
Florian Pose <fp@igh-essen.com>
parents:
1557
diff
changeset
|
190 |
} |
1540
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
191 |
} |
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
192 |
|
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
193 |
/*****************************************************************************/ |
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
194 |
|
1541
26ac1c611100
Sending via generic device works.
Florian Pose <fp@igh-essen.com>
parents:
1540
diff
changeset
|
195 |
/** Creates a network socket. |
26ac1c611100
Sending via generic device works.
Florian Pose <fp@igh-essen.com>
parents:
1540
diff
changeset
|
196 |
*/ |
26ac1c611100
Sending via generic device works.
Florian Pose <fp@igh-essen.com>
parents:
1540
diff
changeset
|
197 |
int ec_gen_device_create_socket( |
26ac1c611100
Sending via generic device works.
Florian Pose <fp@igh-essen.com>
parents:
1540
diff
changeset
|
198 |
ec_gen_device_t *dev, |
1557
daf92232d9c5
Fixed bug in generic driver failing to create debug interfaces, because the
Florian Pose <fp@igh-essen.com>
parents:
1555
diff
changeset
|
199 |
ec_gen_interface_desc_t *desc |
1541
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 |
{ |
26ac1c611100
Sending via generic device works.
Florian Pose <fp@igh-essen.com>
parents:
1540
diff
changeset
|
202 |
int ret; |
26ac1c611100
Sending via generic device works.
Florian Pose <fp@igh-essen.com>
parents:
1540
diff
changeset
|
203 |
struct sockaddr_ll sa; |
26ac1c611100
Sending via generic device works.
Florian Pose <fp@igh-essen.com>
parents:
1540
diff
changeset
|
204 |
|
1612 | 205 |
dev->rx_buf = kmalloc(EC_GEN_RX_BUF_SIZE, GFP_KERNEL); |
1558
55213fcc93a6
generic device receive buffer in heap.
Florian Pose <fp@igh-essen.com>
parents:
1557
diff
changeset
|
206 |
if (!dev->rx_buf) { |
55213fcc93a6
generic device receive buffer in heap.
Florian Pose <fp@igh-essen.com>
parents:
1557
diff
changeset
|
207 |
return -ENOMEM; |
55213fcc93a6
generic device receive buffer in heap.
Florian Pose <fp@igh-essen.com>
parents:
1557
diff
changeset
|
208 |
} |
55213fcc93a6
generic device receive buffer in heap.
Florian Pose <fp@igh-essen.com>
parents:
1557
diff
changeset
|
209 |
|
2170
e69a5010914f
Improved generic driver error messages.
Florian Pose <fp@igh-essen.com>
parents:
1833
diff
changeset
|
210 |
ret = sock_create_kern(PF_PACKET, SOCK_RAW, htons(ETH_P_ETHERCAT), |
e69a5010914f
Improved generic driver error messages.
Florian Pose <fp@igh-essen.com>
parents:
1833
diff
changeset
|
211 |
&dev->socket); |
1541
26ac1c611100
Sending via generic device works.
Florian Pose <fp@igh-essen.com>
parents:
1540
diff
changeset
|
212 |
if (ret) { |
2170
e69a5010914f
Improved generic driver error messages.
Florian Pose <fp@igh-essen.com>
parents:
1833
diff
changeset
|
213 |
printk(KERN_ERR PFX "Failed to create socket (ret = %i).\n", ret); |
1541
26ac1c611100
Sending via generic device works.
Florian Pose <fp@igh-essen.com>
parents:
1540
diff
changeset
|
214 |
return ret; |
26ac1c611100
Sending via generic device works.
Florian Pose <fp@igh-essen.com>
parents:
1540
diff
changeset
|
215 |
} |
26ac1c611100
Sending via generic device works.
Florian Pose <fp@igh-essen.com>
parents:
1540
diff
changeset
|
216 |
|
26ac1c611100
Sending via generic device works.
Florian Pose <fp@igh-essen.com>
parents:
1540
diff
changeset
|
217 |
printk(KERN_ERR PFX "Binding socket to interface %i (%s).\n", |
1557
daf92232d9c5
Fixed bug in generic driver failing to create debug interfaces, because the
Florian Pose <fp@igh-essen.com>
parents:
1555
diff
changeset
|
218 |
desc->ifindex, desc->name); |
1541
26ac1c611100
Sending via generic device works.
Florian Pose <fp@igh-essen.com>
parents:
1540
diff
changeset
|
219 |
|
26ac1c611100
Sending via generic device works.
Florian Pose <fp@igh-essen.com>
parents:
1540
diff
changeset
|
220 |
memset(&sa, 0x00, sizeof(sa)); |
26ac1c611100
Sending via generic device works.
Florian Pose <fp@igh-essen.com>
parents:
1540
diff
changeset
|
221 |
sa.sll_family = AF_PACKET; |
26ac1c611100
Sending via generic device works.
Florian Pose <fp@igh-essen.com>
parents:
1540
diff
changeset
|
222 |
sa.sll_protocol = htons(ETH_P_ETHERCAT); |
1557
daf92232d9c5
Fixed bug in generic driver failing to create debug interfaces, because the
Florian Pose <fp@igh-essen.com>
parents:
1555
diff
changeset
|
223 |
sa.sll_ifindex = desc->ifindex; |
1541
26ac1c611100
Sending via generic device works.
Florian Pose <fp@igh-essen.com>
parents:
1540
diff
changeset
|
224 |
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
|
225 |
if (ret) { |
2170
e69a5010914f
Improved generic driver error messages.
Florian Pose <fp@igh-essen.com>
parents:
1833
diff
changeset
|
226 |
printk(KERN_ERR PFX "Failed to bind() socket to interface" |
e69a5010914f
Improved generic driver error messages.
Florian Pose <fp@igh-essen.com>
parents:
1833
diff
changeset
|
227 |
" (ret = %i).\n", ret); |
1541
26ac1c611100
Sending via generic device works.
Florian Pose <fp@igh-essen.com>
parents:
1540
diff
changeset
|
228 |
sock_release(dev->socket); |
26ac1c611100
Sending via generic device works.
Florian Pose <fp@igh-essen.com>
parents:
1540
diff
changeset
|
229 |
dev->socket = NULL; |
26ac1c611100
Sending via generic device works.
Florian Pose <fp@igh-essen.com>
parents:
1540
diff
changeset
|
230 |
return ret; |
26ac1c611100
Sending via generic device works.
Florian Pose <fp@igh-essen.com>
parents:
1540
diff
changeset
|
231 |
} |
26ac1c611100
Sending via generic device works.
Florian Pose <fp@igh-essen.com>
parents:
1540
diff
changeset
|
232 |
|
26ac1c611100
Sending via generic device works.
Florian Pose <fp@igh-essen.com>
parents:
1540
diff
changeset
|
233 |
return 0; |
26ac1c611100
Sending via generic device works.
Florian Pose <fp@igh-essen.com>
parents:
1540
diff
changeset
|
234 |
} |
26ac1c611100
Sending via generic device works.
Florian Pose <fp@igh-essen.com>
parents:
1540
diff
changeset
|
235 |
|
26ac1c611100
Sending via generic device works.
Florian Pose <fp@igh-essen.com>
parents:
1540
diff
changeset
|
236 |
/*****************************************************************************/ |
26ac1c611100
Sending via generic device works.
Florian Pose <fp@igh-essen.com>
parents:
1540
diff
changeset
|
237 |
|
1540
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
238 |
/** Offer generic device to master. |
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
239 |
*/ |
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
240 |
int ec_gen_device_offer( |
1541
26ac1c611100
Sending via generic device works.
Florian Pose <fp@igh-essen.com>
parents:
1540
diff
changeset
|
241 |
ec_gen_device_t *dev, |
1557
daf92232d9c5
Fixed bug in generic driver failing to create debug interfaces, because the
Florian Pose <fp@igh-essen.com>
parents:
1555
diff
changeset
|
242 |
ec_gen_interface_desc_t *desc |
1540
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 |
int ret = 0; |
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
246 |
|
1612 | 247 |
dev->used_netdev = desc->netdev; |
248 |
memcpy(dev->netdev->dev_addr, desc->dev_addr, ETH_ALEN); |
|
1557
daf92232d9c5
Fixed bug in generic driver failing to create debug interfaces, because the
Florian Pose <fp@igh-essen.com>
parents:
1555
diff
changeset
|
249 |
|
1555
7679e98b0bb1
Generic driver net_device_ops for kernels < 2.6.29.
Florian Pose <fp@igh-essen.com>
parents:
1542
diff
changeset
|
250 |
dev->ecdev = ecdev_offer(dev->netdev, ec_gen_poll, THIS_MODULE); |
1540
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
251 |
if (dev->ecdev) { |
1557
daf92232d9c5
Fixed bug in generic driver failing to create debug interfaces, because the
Florian Pose <fp@igh-essen.com>
parents:
1555
diff
changeset
|
252 |
if (ec_gen_device_create_socket(dev, desc)) { |
1541
26ac1c611100
Sending via generic device works.
Florian Pose <fp@igh-essen.com>
parents:
1540
diff
changeset
|
253 |
ecdev_withdraw(dev->ecdev); |
26ac1c611100
Sending via generic device works.
Florian Pose <fp@igh-essen.com>
parents:
1540
diff
changeset
|
254 |
dev->ecdev = NULL; |
26ac1c611100
Sending via generic device works.
Florian Pose <fp@igh-essen.com>
parents:
1540
diff
changeset
|
255 |
} else if (ecdev_open(dev->ecdev)) { |
1540
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
256 |
ecdev_withdraw(dev->ecdev); |
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
257 |
dev->ecdev = NULL; |
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
258 |
} else { |
1612 | 259 |
ecdev_set_link(dev->ecdev, netif_carrier_ok(dev->used_netdev)); // FIXME |
1540
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
260 |
ret = 1; |
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
261 |
} |
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
262 |
} |
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
263 |
|
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
264 |
return ret; |
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
265 |
} |
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
266 |
|
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
267 |
/*****************************************************************************/ |
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
268 |
|
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
269 |
/** Open the device. |
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
270 |
*/ |
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
271 |
int ec_gen_device_open( |
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
272 |
ec_gen_device_t *dev |
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 |
{ |
1541
26ac1c611100
Sending via generic device works.
Florian Pose <fp@igh-essen.com>
parents:
1540
diff
changeset
|
275 |
return 0; |
1540
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
276 |
} |
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
277 |
|
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
278 |
/*****************************************************************************/ |
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
279 |
|
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
280 |
/** Stop the device. |
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
281 |
*/ |
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
282 |
int ec_gen_device_stop( |
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
283 |
ec_gen_device_t *dev |
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
284 |
) |
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
285 |
{ |
1541
26ac1c611100
Sending via generic device works.
Florian Pose <fp@igh-essen.com>
parents:
1540
diff
changeset
|
286 |
return 0; |
1540
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
287 |
} |
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
288 |
|
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
289 |
/*****************************************************************************/ |
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
290 |
|
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
291 |
int ec_gen_device_start_xmit( |
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
292 |
ec_gen_device_t *dev, |
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
293 |
struct sk_buff *skb |
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
294 |
) |
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
295 |
{ |
1541
26ac1c611100
Sending via generic device works.
Florian Pose <fp@igh-essen.com>
parents:
1540
diff
changeset
|
296 |
struct msghdr msg; |
26ac1c611100
Sending via generic device works.
Florian Pose <fp@igh-essen.com>
parents:
1540
diff
changeset
|
297 |
struct kvec iov; |
26ac1c611100
Sending via generic device works.
Florian Pose <fp@igh-essen.com>
parents:
1540
diff
changeset
|
298 |
size_t len = skb->len; |
26ac1c611100
Sending via generic device works.
Florian Pose <fp@igh-essen.com>
parents:
1540
diff
changeset
|
299 |
int ret; |
26ac1c611100
Sending via generic device works.
Florian Pose <fp@igh-essen.com>
parents:
1540
diff
changeset
|
300 |
|
1612 | 301 |
ecdev_set_link(dev->ecdev, netif_carrier_ok(dev->used_netdev)); |
1607
be4dd9c80f42
generic device driver checks link up/down
Martin Troxler <martin.troxler@komaxgroup.com>
parents:
1559
diff
changeset
|
302 |
|
1541
26ac1c611100
Sending via generic device works.
Florian Pose <fp@igh-essen.com>
parents:
1540
diff
changeset
|
303 |
iov.iov_base = skb->data; |
26ac1c611100
Sending via generic device works.
Florian Pose <fp@igh-essen.com>
parents:
1540
diff
changeset
|
304 |
iov.iov_len = len; |
26ac1c611100
Sending via generic device works.
Florian Pose <fp@igh-essen.com>
parents:
1540
diff
changeset
|
305 |
memset(&msg, 0, sizeof(msg)); |
26ac1c611100
Sending via generic device works.
Florian Pose <fp@igh-essen.com>
parents:
1540
diff
changeset
|
306 |
|
26ac1c611100
Sending via generic device works.
Florian Pose <fp@igh-essen.com>
parents:
1540
diff
changeset
|
307 |
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
|
308 |
|
26ac1c611100
Sending via generic device works.
Florian Pose <fp@igh-essen.com>
parents:
1540
diff
changeset
|
309 |
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
|
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 |
/*****************************************************************************/ |
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
313 |
|
1542
91ae9c95dd2e
Implemented poll(); receiving on generic device also works.
Florian Pose <fp@igh-essen.com>
parents:
1541
diff
changeset
|
314 |
/** Polls the device. |
91ae9c95dd2e
Implemented poll(); receiving on generic device also works.
Florian Pose <fp@igh-essen.com>
parents:
1541
diff
changeset
|
315 |
*/ |
91ae9c95dd2e
Implemented poll(); receiving on generic device also works.
Florian Pose <fp@igh-essen.com>
parents:
1541
diff
changeset
|
316 |
void ec_gen_device_poll( |
91ae9c95dd2e
Implemented poll(); receiving on generic device also works.
Florian Pose <fp@igh-essen.com>
parents:
1541
diff
changeset
|
317 |
ec_gen_device_t *dev |
91ae9c95dd2e
Implemented poll(); receiving on generic device also works.
Florian Pose <fp@igh-essen.com>
parents:
1541
diff
changeset
|
318 |
) |
91ae9c95dd2e
Implemented poll(); receiving on generic device also works.
Florian Pose <fp@igh-essen.com>
parents:
1541
diff
changeset
|
319 |
{ |
91ae9c95dd2e
Implemented poll(); receiving on generic device also works.
Florian Pose <fp@igh-essen.com>
parents:
1541
diff
changeset
|
320 |
struct msghdr msg; |
91ae9c95dd2e
Implemented poll(); receiving on generic device also works.
Florian Pose <fp@igh-essen.com>
parents:
1541
diff
changeset
|
321 |
struct kvec iov; |
91ae9c95dd2e
Implemented poll(); receiving on generic device also works.
Florian Pose <fp@igh-essen.com>
parents:
1541
diff
changeset
|
322 |
int ret, budget = 10; // FIXME |
91ae9c95dd2e
Implemented poll(); receiving on generic device also works.
Florian Pose <fp@igh-essen.com>
parents:
1541
diff
changeset
|
323 |
|
1612 | 324 |
ecdev_set_link(dev->ecdev, netif_carrier_ok(dev->used_netdev)); |
325 |
||
326 |
do { |
|
1559
1b3a89f6dc29
Fixed receiving multiple frames in generic device.
Florian Pose <fp@igh-essen.com>
parents:
1558
diff
changeset
|
327 |
iov.iov_base = dev->rx_buf; |
1b3a89f6dc29
Fixed receiving multiple frames in generic device.
Florian Pose <fp@igh-essen.com>
parents:
1558
diff
changeset
|
328 |
iov.iov_len = EC_GEN_RX_BUF_SIZE; |
1b3a89f6dc29
Fixed receiving multiple frames in generic device.
Florian Pose <fp@igh-essen.com>
parents:
1558
diff
changeset
|
329 |
memset(&msg, 0, sizeof(msg)); |
1b3a89f6dc29
Fixed receiving multiple frames in generic device.
Florian Pose <fp@igh-essen.com>
parents:
1558
diff
changeset
|
330 |
|
1542
91ae9c95dd2e
Implemented poll(); receiving on generic device also works.
Florian Pose <fp@igh-essen.com>
parents:
1541
diff
changeset
|
331 |
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
|
332 |
MSG_DONTWAIT); |
91ae9c95dd2e
Implemented poll(); receiving on generic device also works.
Florian Pose <fp@igh-essen.com>
parents:
1541
diff
changeset
|
333 |
if (ret > 0) { |
1558
55213fcc93a6
generic device receive buffer in heap.
Florian Pose <fp@igh-essen.com>
parents:
1557
diff
changeset
|
334 |
ecdev_receive(dev->ecdev, dev->rx_buf, ret); |
1542
91ae9c95dd2e
Implemented poll(); receiving on generic device also works.
Florian Pose <fp@igh-essen.com>
parents:
1541
diff
changeset
|
335 |
} else if (ret < 0) { |
91ae9c95dd2e
Implemented poll(); receiving on generic device also works.
Florian Pose <fp@igh-essen.com>
parents:
1541
diff
changeset
|
336 |
break; |
91ae9c95dd2e
Implemented poll(); receiving on generic device also works.
Florian Pose <fp@igh-essen.com>
parents:
1541
diff
changeset
|
337 |
} |
91ae9c95dd2e
Implemented poll(); receiving on generic device also works.
Florian Pose <fp@igh-essen.com>
parents:
1541
diff
changeset
|
338 |
budget--; |
91ae9c95dd2e
Implemented poll(); receiving on generic device also works.
Florian Pose <fp@igh-essen.com>
parents:
1541
diff
changeset
|
339 |
} while (budget); |
91ae9c95dd2e
Implemented poll(); receiving on generic device also works.
Florian Pose <fp@igh-essen.com>
parents:
1541
diff
changeset
|
340 |
} |
91ae9c95dd2e
Implemented poll(); receiving on generic device also works.
Florian Pose <fp@igh-essen.com>
parents:
1541
diff
changeset
|
341 |
|
91ae9c95dd2e
Implemented poll(); receiving on generic device also works.
Florian Pose <fp@igh-essen.com>
parents:
1541
diff
changeset
|
342 |
/*****************************************************************************/ |
91ae9c95dd2e
Implemented poll(); receiving on generic device also works.
Florian Pose <fp@igh-essen.com>
parents:
1541
diff
changeset
|
343 |
|
1540
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
344 |
/** Offer device. |
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
345 |
*/ |
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
346 |
int offer_device( |
1557
daf92232d9c5
Fixed bug in generic driver failing to create debug interfaces, because the
Florian Pose <fp@igh-essen.com>
parents:
1555
diff
changeset
|
347 |
ec_gen_interface_desc_t *desc |
1540
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 |
ec_gen_device_t *gendev; |
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
351 |
int ret = 0; |
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 |
gendev = kmalloc(sizeof(ec_gen_device_t), GFP_KERNEL); |
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
354 |
if (!gendev) { |
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
355 |
return -ENOMEM; |
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
356 |
} |
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
357 |
|
1557
daf92232d9c5
Fixed bug in generic driver failing to create debug interfaces, because the
Florian Pose <fp@igh-essen.com>
parents:
1555
diff
changeset
|
358 |
ret = ec_gen_device_init(gendev); |
1540
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
359 |
if (ret) { |
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
360 |
kfree(gendev); |
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
361 |
return ret; |
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 |
|
1557
daf92232d9c5
Fixed bug in generic driver failing to create debug interfaces, because the
Florian Pose <fp@igh-essen.com>
parents:
1555
diff
changeset
|
364 |
if (ec_gen_device_offer(gendev, desc)) { |
1540
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
365 |
list_add_tail(&gendev->list, &generic_devices); |
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
366 |
} else { |
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
367 |
ec_gen_device_clear(gendev); |
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
368 |
kfree(gendev); |
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
369 |
} |
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
370 |
|
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
371 |
return ret; |
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
372 |
} |
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
373 |
|
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
374 |
/*****************************************************************************/ |
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
375 |
|
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
376 |
/** Clear devices. |
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 |
void clear_devices(void) |
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
379 |
{ |
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
380 |
ec_gen_device_t *gendev, *next; |
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
381 |
|
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
382 |
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
|
383 |
list_del(&gendev->list); |
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
384 |
ec_gen_device_clear(gendev); |
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
385 |
kfree(gendev); |
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 |
|
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 |
|
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
391 |
/** Module initialization. |
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
392 |
* |
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
393 |
* Initializes \a master_count masters. |
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
394 |
* \return 0 on success, else < 0 |
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
395 |
*/ |
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
396 |
int __init ec_gen_init_module(void) |
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 |
int ret = 0; |
1557
daf92232d9c5
Fixed bug in generic driver failing to create debug interfaces, because the
Florian Pose <fp@igh-essen.com>
parents:
1555
diff
changeset
|
399 |
struct list_head descs; |
1540
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
400 |
struct net_device *netdev; |
1557
daf92232d9c5
Fixed bug in generic driver failing to create debug interfaces, because the
Florian Pose <fp@igh-essen.com>
parents:
1555
diff
changeset
|
401 |
ec_gen_interface_desc_t *desc, *next; |
1540
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
402 |
|
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
403 |
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
|
404 |
EC_MASTER_VERSION); |
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
405 |
|
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
406 |
INIT_LIST_HEAD(&generic_devices); |
1557
daf92232d9c5
Fixed bug in generic driver failing to create debug interfaces, because the
Florian Pose <fp@igh-essen.com>
parents:
1555
diff
changeset
|
407 |
INIT_LIST_HEAD(&descs); |
1540
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
408 |
|
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
409 |
read_lock(&dev_base_lock); |
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
410 |
for_each_netdev(&init_net, netdev) { |
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
411 |
if (netdev->type != ARPHRD_ETHER) |
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
412 |
continue; |
1833
5adbf2bc48d9
Fixed memory allocation while lock is held. Thanks to Esben Haabendal.
Florian Pose <fp@igh-essen.com>
parents:
1612
diff
changeset
|
413 |
desc = kmalloc(sizeof(ec_gen_interface_desc_t), GFP_ATOMIC); |
1557
daf92232d9c5
Fixed bug in generic driver failing to create debug interfaces, because the
Florian Pose <fp@igh-essen.com>
parents:
1555
diff
changeset
|
414 |
if (!desc) { |
daf92232d9c5
Fixed bug in generic driver failing to create debug interfaces, because the
Florian Pose <fp@igh-essen.com>
parents:
1555
diff
changeset
|
415 |
ret = -ENOMEM; |
1540
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
416 |
read_unlock(&dev_base_lock); |
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
417 |
goto out_err; |
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
418 |
} |
1557
daf92232d9c5
Fixed bug in generic driver failing to create debug interfaces, because the
Florian Pose <fp@igh-essen.com>
parents:
1555
diff
changeset
|
419 |
strncpy(desc->name, netdev->name, IFNAMSIZ); |
1612 | 420 |
desc->netdev = netdev; |
1557
daf92232d9c5
Fixed bug in generic driver failing to create debug interfaces, because the
Florian Pose <fp@igh-essen.com>
parents:
1555
diff
changeset
|
421 |
desc->ifindex = netdev->ifindex; |
daf92232d9c5
Fixed bug in generic driver failing to create debug interfaces, because the
Florian Pose <fp@igh-essen.com>
parents:
1555
diff
changeset
|
422 |
memcpy(desc->dev_addr, netdev->dev_addr, ETH_ALEN); |
daf92232d9c5
Fixed bug in generic driver failing to create debug interfaces, because the
Florian Pose <fp@igh-essen.com>
parents:
1555
diff
changeset
|
423 |
list_add_tail(&desc->list, &descs); |
1540
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
424 |
} |
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
425 |
read_unlock(&dev_base_lock); |
1557
daf92232d9c5
Fixed bug in generic driver failing to create debug interfaces, because the
Florian Pose <fp@igh-essen.com>
parents:
1555
diff
changeset
|
426 |
|
daf92232d9c5
Fixed bug in generic driver failing to create debug interfaces, because the
Florian Pose <fp@igh-essen.com>
parents:
1555
diff
changeset
|
427 |
list_for_each_entry_safe(desc, next, &descs, list) { |
daf92232d9c5
Fixed bug in generic driver failing to create debug interfaces, because the
Florian Pose <fp@igh-essen.com>
parents:
1555
diff
changeset
|
428 |
ret = offer_device(desc); |
daf92232d9c5
Fixed bug in generic driver failing to create debug interfaces, because the
Florian Pose <fp@igh-essen.com>
parents:
1555
diff
changeset
|
429 |
if (ret) { |
daf92232d9c5
Fixed bug in generic driver failing to create debug interfaces, because the
Florian Pose <fp@igh-essen.com>
parents:
1555
diff
changeset
|
430 |
goto out_err; |
daf92232d9c5
Fixed bug in generic driver failing to create debug interfaces, because the
Florian Pose <fp@igh-essen.com>
parents:
1555
diff
changeset
|
431 |
} |
daf92232d9c5
Fixed bug in generic driver failing to create debug interfaces, because the
Florian Pose <fp@igh-essen.com>
parents:
1555
diff
changeset
|
432 |
kfree(desc); |
daf92232d9c5
Fixed bug in generic driver failing to create debug interfaces, because the
Florian Pose <fp@igh-essen.com>
parents:
1555
diff
changeset
|
433 |
} |
1540
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
434 |
return ret; |
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
435 |
|
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
436 |
out_err: |
1557
daf92232d9c5
Fixed bug in generic driver failing to create debug interfaces, because the
Florian Pose <fp@igh-essen.com>
parents:
1555
diff
changeset
|
437 |
list_for_each_entry_safe(desc, next, &descs, list) { |
daf92232d9c5
Fixed bug in generic driver failing to create debug interfaces, because the
Florian Pose <fp@igh-essen.com>
parents:
1555
diff
changeset
|
438 |
list_del(&desc->list); |
daf92232d9c5
Fixed bug in generic driver failing to create debug interfaces, because the
Florian Pose <fp@igh-essen.com>
parents:
1555
diff
changeset
|
439 |
kfree(desc); |
daf92232d9c5
Fixed bug in generic driver failing to create debug interfaces, because the
Florian Pose <fp@igh-essen.com>
parents:
1555
diff
changeset
|
440 |
} |
1540
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
441 |
clear_devices(); |
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
442 |
return ret; |
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
443 |
} |
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
444 |
|
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
445 |
/*****************************************************************************/ |
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
446 |
|
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
447 |
/** Module cleanup. |
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
448 |
* |
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
449 |
* Clears all master instances. |
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
450 |
*/ |
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
451 |
void __exit ec_gen_cleanup_module(void) |
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
452 |
{ |
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
453 |
clear_devices(); |
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
454 |
printk(KERN_INFO PFX "Unloading.\n"); |
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
455 |
} |
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
456 |
|
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
457 |
/*****************************************************************************/ |
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
458 |
|
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
459 |
/** \cond */ |
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
460 |
|
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
461 |
module_init(ec_gen_init_module); |
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
462 |
module_exit(ec_gen_cleanup_module); |
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
463 |
|
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
464 |
/** \endcond */ |
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
465 |
|
49430a3fe73d
Basic generic Ethernet device module.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
466 |
/*****************************************************************************/ |