Create debug interface with address of physical device on attachment.
--- a/NEWS Wed Nov 05 10:16:11 2008 +0000
+++ b/NEWS Wed Nov 05 15:05:40 2008 +0000
@@ -13,6 +13,8 @@
Introduced new method ec_datagram_zero() for that.
* Added phy_read and phy_write commands to ethercat tool.
* Added driver for Intel PRO/100 NICs.
+* Debug interfaces are created with the Ethernet addresses of the attached
+ physical device.
Changes since 1.4.0-rc3:
--- a/master/debug.c Wed Nov 05 10:16:11 2008 +0000
+++ b/master/debug.c Wed Nov 05 15:05:40 2008 +0000
@@ -54,19 +54,18 @@
/*****************************************************************************/
-/**
- Debug constructor.
- Initializes the debug object, creates a net_device and registeres it.
-*/
-
+/** Debug interface constructor.
+ *
+ * Initializes the debug object, creates a net_device and registeres it.
+ */
int ec_debug_init(
ec_debug_t *dbg, /**< debug object */
const char *name /**< interface name */
)
{
- int result;
-
+ dbg->registered = 0;
dbg->opened = 0;
+
memset(&dbg->stats, 0, sizeof(struct net_device_stats));
if (!(dbg->dev =
@@ -84,50 +83,79 @@
// initialize private data
*((ec_debug_t **) netdev_priv(dbg->dev)) = dbg;
+ return 0;
+
+ out_return:
+ return -1;
+}
+
+/*****************************************************************************/
+
+/** Debug interface destructor.
+ *
+ * Unregisters the net_device and frees allocated memory.
+ */
+void ec_debug_clear(
+ ec_debug_t *dbg /**< debug object */
+ )
+{
+ ec_debug_unregister(dbg);
+ free_netdev(dbg->dev);
+}
+
+/*****************************************************************************/
+
+/** Register debug interface.
+ */
+void ec_debug_register(
+ ec_debug_t *dbg, /**< debug object */
+ const struct net_device *net_dev /**< 'Real' Ethernet device. */
+ )
+{
+ int result;
+
+ ec_debug_unregister(dbg);
+
+ // use the Ethernet address of the physical device for the debug device
+ memcpy(dbg->dev->dev_addr, net_dev->dev_addr, ETH_ALEN);
+
// connect the net_device to the kernel
if ((result = register_netdev(dbg->dev))) {
- EC_ERR("Unable to register net_device: error %i\n", result);
- goto out_free;
- }
-
- return 0;
-
- out_free:
- free_netdev(dbg->dev);
- dbg->dev = NULL;
- out_return:
- return -1;
-}
-
-/*****************************************************************************/
-
-/**
- Debug destructor.
- Unregisteres the net_device and frees allocated memory.
-*/
-
-void ec_debug_clear(ec_debug_t *dbg /**< debug object */)
-{
- if (dbg->dev) {
+ EC_WARN("Unable to register net_device: error %i\n", result);
+ } else {
+ dbg->registered = 1;
+ }
+}
+
+/*****************************************************************************/
+
+/** Unregister debug interface.
+ */
+void ec_debug_unregister(
+ ec_debug_t *dbg /**< debug object */
+ )
+{
+ if (dbg->registered) {
+ dbg->opened = 0;
+ dbg->registered = 0;
unregister_netdev(dbg->dev);
- free_netdev(dbg->dev);
- }
-}
-
-/*****************************************************************************/
-
-/**
- Sends frame data to the interface.
-*/
-
-void ec_debug_send(ec_debug_t *dbg, /**< debug object */
- const uint8_t *data, /**< frame data */
- size_t size /**< size of the frame data */
- )
+ }
+}
+
+/*****************************************************************************/
+
+/** Sends frame data to the interface.
+ */
+void ec_debug_send(
+ ec_debug_t *dbg, /**< debug object */
+ const uint8_t *data, /**< frame data */
+ size_t size /**< size of the frame data */
+ )
{
struct sk_buff *skb;
- if (!dbg->opened) return;
+ if (!dbg->opened)
+ return;
// allocate socket buffer
if (!(skb = dev_alloc_skb(size))) {
@@ -153,11 +181,11 @@
* NET_DEVICE functions
*****************************************************************************/
-/**
- Opens the virtual network device.
-*/
-
-int ec_dbgdev_open(struct net_device *dev /**< debug net_device */)
+/** Opens the virtual network device.
+ */
+int ec_dbgdev_open(
+ struct net_device *dev /**< debug net_device */
+ )
{
ec_debug_t *dbg = *((ec_debug_t **) netdev_priv(dev));
dbg->opened = 1;
@@ -167,11 +195,11 @@
/*****************************************************************************/
-/**
- Stops the virtual network device.
-*/
-
-int ec_dbgdev_stop(struct net_device *dev /**< debug net_device */)
+/** Stops the virtual network device.
+ */
+int ec_dbgdev_stop(
+ struct net_device *dev /**< debug net_device */
+ )
{
ec_debug_t *dbg = *((ec_debug_t **) netdev_priv(dev));
dbg->opened = 0;
@@ -181,13 +209,12 @@
/*****************************************************************************/
-/**
- Transmits data via the virtual network device.
-*/
-
-int ec_dbgdev_tx(struct sk_buff *skb, /**< transmit socket buffer */
- struct net_device *dev /**< EoE net_device */
- )
+/** Transmits data via the virtual network device.
+ */
+int ec_dbgdev_tx(
+ struct sk_buff *skb, /**< transmit socket buffer */
+ struct net_device *dev /**< EoE net_device */
+ )
{
ec_debug_t *dbg = *((ec_debug_t **) netdev_priv(dev));
@@ -198,12 +225,11 @@
/*****************************************************************************/
-/**
- Gets statistics about the virtual network device.
-*/
-
-struct net_device_stats *ec_dbgdev_stats(struct net_device *dev
- /**< debug net_device */)
+/** Gets statistics about the virtual network device.
+ */
+struct net_device_stats *ec_dbgdev_stats(
+ struct net_device *dev /**< debug net_device */
+ )
{
ec_debug_t *dbg = *((ec_debug_t **) netdev_priv(dev));
return &dbg->stats;
--- a/master/debug.h Wed Nov 05 10:16:11 2008 +0000
+++ b/master/debug.h Wed Nov 05 15:05:40 2008 +0000
@@ -50,6 +50,7 @@
{
struct net_device *dev; /**< net_device for virtual ethernet device */
struct net_device_stats stats; /**< device statistics */
+ uint8_t registered; /**< net_device is opened */
uint8_t opened; /**< net_device is opened */
}
ec_debug_t;
@@ -58,6 +59,8 @@
int ec_debug_init(ec_debug_t *, const char *);
void ec_debug_clear(ec_debug_t *);
+void ec_debug_register(ec_debug_t *, const struct net_device *);
+void ec_debug_unregister(ec_debug_t *);
void ec_debug_send(ec_debug_t *, const uint8_t *, size_t);
/*****************************************************************************/
--- a/master/device.c Wed Nov 05 10:16:11 2008 +0000
+++ b/master/device.c Wed Nov 05 15:05:40 2008 +0000
@@ -170,6 +170,10 @@
eth = (struct ethhdr *) (device->tx_skb[i]->data);
memcpy(eth->h_source, net_dev->dev_addr, ETH_ALEN);
}
+
+#ifdef EC_DEBUG_IF
+ ec_debug_register(&device->dbg, net_dev);
+#endif
}
/*****************************************************************************/
@@ -182,6 +186,10 @@
{
unsigned int i;
+#ifdef EC_DEBUG_IF
+ ec_debug_unregister(&device->dbg);
+#endif
+
device->dev = NULL;
device->poll = NULL;
device->module = NULL;