master/debug.c
author Florian Pose <fp@igh-essen.com>
Mon, 26 Jan 2009 10:30:17 +0000
changeset 1323 10fbef0a3ac5
parent 1313 ed15eef57d5c
child 1326 ef907b0b5125
permissions -rw-r--r--
merge -r1599:1600 branches/stable-1.4: Removed bashisms from init script.
231
767548c75bf3 Added debug interface for network monitors.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     1
/******************************************************************************
767548c75bf3 Added debug interface for network monitors.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     2
 *
767548c75bf3 Added debug interface for network monitors.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     3
 *  $Id$
767548c75bf3 Added debug interface for network monitors.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     4
 *
767548c75bf3 Added debug interface for network monitors.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     5
 *  Copyright (C) 2006  Florian Pose, Ingenieurgemeinschaft IgH
767548c75bf3 Added debug interface for network monitors.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     6
 *
767548c75bf3 Added debug interface for network monitors.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     7
 *  This file is part of the IgH EtherCAT Master.
767548c75bf3 Added debug interface for network monitors.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     8
 *
767548c75bf3 Added debug interface for network monitors.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     9
 *  The IgH EtherCAT Master is free software; you can redistribute it
767548c75bf3 Added debug interface for network monitors.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    10
 *  and/or modify it under the terms of the GNU General Public License
246
0bf7c769de06 Changed license headers and added EtherCAT license notice.
Florian Pose <fp@igh-essen.com>
parents: 231
diff changeset
    11
 *  as published by the Free Software Foundation; either version 2 of the
0bf7c769de06 Changed license headers and added EtherCAT license notice.
Florian Pose <fp@igh-essen.com>
parents: 231
diff changeset
    12
 *  License, or (at your option) any later version.
231
767548c75bf3 Added debug interface for network monitors.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    13
 *
767548c75bf3 Added debug interface for network monitors.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    14
 *  The IgH EtherCAT Master is distributed in the hope that it will be
767548c75bf3 Added debug interface for network monitors.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    15
 *  useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
767548c75bf3 Added debug interface for network monitors.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    16
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
767548c75bf3 Added debug interface for network monitors.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    17
 *  GNU General Public License for more details.
767548c75bf3 Added debug interface for network monitors.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    18
 *
767548c75bf3 Added debug interface for network monitors.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    19
 *  You should have received a copy of the GNU General Public License
767548c75bf3 Added debug interface for network monitors.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    20
 *  along with the IgH EtherCAT Master; if not, write to the Free Software
767548c75bf3 Added debug interface for network monitors.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    21
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
767548c75bf3 Added debug interface for network monitors.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    22
 *
246
0bf7c769de06 Changed license headers and added EtherCAT license notice.
Florian Pose <fp@igh-essen.com>
parents: 231
diff changeset
    23
 *  The right to use EtherCAT Technology is granted and comes free of
0bf7c769de06 Changed license headers and added EtherCAT license notice.
Florian Pose <fp@igh-essen.com>
parents: 231
diff changeset
    24
 *  charge under condition of compatibility of product made by
0bf7c769de06 Changed license headers and added EtherCAT license notice.
Florian Pose <fp@igh-essen.com>
parents: 231
diff changeset
    25
 *  Licensee. People intending to distribute/sell products based on the
0bf7c769de06 Changed license headers and added EtherCAT license notice.
Florian Pose <fp@igh-essen.com>
parents: 231
diff changeset
    26
 *  code, have to sign an agreement to guarantee that products using
0bf7c769de06 Changed license headers and added EtherCAT license notice.
Florian Pose <fp@igh-essen.com>
parents: 231
diff changeset
    27
 *  software based on IgH EtherCAT master stay compatible with the actual
0bf7c769de06 Changed license headers and added EtherCAT license notice.
Florian Pose <fp@igh-essen.com>
parents: 231
diff changeset
    28
 *  EtherCAT specification (which are released themselves as an open
0bf7c769de06 Changed license headers and added EtherCAT license notice.
Florian Pose <fp@igh-essen.com>
parents: 231
diff changeset
    29
 *  standard) as the (only) precondition to have the right to use EtherCAT
0bf7c769de06 Changed license headers and added EtherCAT license notice.
Florian Pose <fp@igh-essen.com>
parents: 231
diff changeset
    30
 *  Technology, IP and trade marks.
0bf7c769de06 Changed license headers and added EtherCAT license notice.
Florian Pose <fp@igh-essen.com>
parents: 231
diff changeset
    31
 *
231
767548c75bf3 Added debug interface for network monitors.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    32
 *****************************************************************************/
767548c75bf3 Added debug interface for network monitors.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    33
767548c75bf3 Added debug interface for network monitors.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    34
/**
767548c75bf3 Added debug interface for network monitors.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    35
   \file
767548c75bf3 Added debug interface for network monitors.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    36
   Ethernet interface for debugging purposes.
767548c75bf3 Added debug interface for network monitors.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    37
*/
767548c75bf3 Added debug interface for network monitors.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    38
767548c75bf3 Added debug interface for network monitors.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    39
/*****************************************************************************/
767548c75bf3 Added debug interface for network monitors.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    40
294
feea8d850c65 Applied include patch by M. Schwerin.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
    41
#include <linux/netdevice.h>
231
767548c75bf3 Added debug interface for network monitors.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    42
#include <linux/etherdevice.h>
767548c75bf3 Added debug interface for network monitors.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    43
767548c75bf3 Added debug interface for network monitors.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    44
#include "globals.h"
767548c75bf3 Added debug interface for network monitors.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    45
#include "debug.h"
767548c75bf3 Added debug interface for network monitors.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    46
767548c75bf3 Added debug interface for network monitors.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    47
/*****************************************************************************/
767548c75bf3 Added debug interface for network monitors.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    48
767548c75bf3 Added debug interface for network monitors.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    49
// net_device functions
767548c75bf3 Added debug interface for network monitors.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    50
int ec_dbgdev_open(struct net_device *);
767548c75bf3 Added debug interface for network monitors.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    51
int ec_dbgdev_stop(struct net_device *);
471
0a6bd71bf4d3 Fixed debug interfaces.
Florian Pose <fp@igh-essen.com>
parents: 455
diff changeset
    52
int ec_dbgdev_tx(struct sk_buff *, struct net_device *);
231
767548c75bf3 Added debug interface for network monitors.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    53
struct net_device_stats *ec_dbgdev_stats(struct net_device *);
767548c75bf3 Added debug interface for network monitors.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    54
767548c75bf3 Added debug interface for network monitors.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    55
/*****************************************************************************/
767548c75bf3 Added debug interface for network monitors.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    56
1305
de3fcbb6773e Create debug interface with address of physical device on attachment.
Florian Pose <fp@igh-essen.com>
parents: 687
diff changeset
    57
/** Debug interface constructor.
de3fcbb6773e Create debug interface with address of physical device on attachment.
Florian Pose <fp@igh-essen.com>
parents: 687
diff changeset
    58
 *
de3fcbb6773e Create debug interface with address of physical device on attachment.
Florian Pose <fp@igh-essen.com>
parents: 687
diff changeset
    59
 * Initializes the debug object, creates a net_device and registeres it.
1313
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1305
diff changeset
    60
 *
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1305
diff changeset
    61
 * \retval  0 Success.
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1305
diff changeset
    62
 * \retval <0 Error code.
1305
de3fcbb6773e Create debug interface with address of physical device on attachment.
Florian Pose <fp@igh-essen.com>
parents: 687
diff changeset
    63
 */
687
6de97f276423 Changed names of debug interfaces.
Florian Pose <fp@igh-essen.com>
parents: 471
diff changeset
    64
int ec_debug_init(
6de97f276423 Changed names of debug interfaces.
Florian Pose <fp@igh-essen.com>
parents: 471
diff changeset
    65
        ec_debug_t *dbg, /**< debug object */
6de97f276423 Changed names of debug interfaces.
Florian Pose <fp@igh-essen.com>
parents: 471
diff changeset
    66
        const char *name /**< interface name */
6de97f276423 Changed names of debug interfaces.
Florian Pose <fp@igh-essen.com>
parents: 471
diff changeset
    67
        )
231
767548c75bf3 Added debug interface for network monitors.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    68
{
1305
de3fcbb6773e Create debug interface with address of physical device on attachment.
Florian Pose <fp@igh-essen.com>
parents: 687
diff changeset
    69
    dbg->registered = 0;
231
767548c75bf3 Added debug interface for network monitors.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    70
    dbg->opened = 0;
1305
de3fcbb6773e Create debug interface with address of physical device on attachment.
Florian Pose <fp@igh-essen.com>
parents: 687
diff changeset
    71
231
767548c75bf3 Added debug interface for network monitors.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    72
    memset(&dbg->stats, 0, sizeof(struct net_device_stats));
767548c75bf3 Added debug interface for network monitors.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    73
767548c75bf3 Added debug interface for network monitors.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    74
    if (!(dbg->dev =
687
6de97f276423 Changed names of debug interfaces.
Florian Pose <fp@igh-essen.com>
parents: 471
diff changeset
    75
          alloc_netdev(sizeof(ec_debug_t *), name, ether_setup))) {
231
767548c75bf3 Added debug interface for network monitors.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    76
        EC_ERR("Unable to allocate net_device for debug object!\n");
1313
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1305
diff changeset
    77
        return -ENODEV;
231
767548c75bf3 Added debug interface for network monitors.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    78
    }
767548c75bf3 Added debug interface for network monitors.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    79
767548c75bf3 Added debug interface for network monitors.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    80
    // initialize net_device
767548c75bf3 Added debug interface for network monitors.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    81
    dbg->dev->open = ec_dbgdev_open;
767548c75bf3 Added debug interface for network monitors.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    82
    dbg->dev->stop = ec_dbgdev_stop;
471
0a6bd71bf4d3 Fixed debug interfaces.
Florian Pose <fp@igh-essen.com>
parents: 455
diff changeset
    83
    dbg->dev->hard_start_xmit = ec_dbgdev_tx;
231
767548c75bf3 Added debug interface for network monitors.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    84
    dbg->dev->get_stats = ec_dbgdev_stats;
767548c75bf3 Added debug interface for network monitors.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    85
767548c75bf3 Added debug interface for network monitors.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    86
    // initialize private data
767548c75bf3 Added debug interface for network monitors.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    87
    *((ec_debug_t **) netdev_priv(dbg->dev)) = dbg;
767548c75bf3 Added debug interface for network monitors.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    88
1305
de3fcbb6773e Create debug interface with address of physical device on attachment.
Florian Pose <fp@igh-essen.com>
parents: 687
diff changeset
    89
    return 0;
de3fcbb6773e Create debug interface with address of physical device on attachment.
Florian Pose <fp@igh-essen.com>
parents: 687
diff changeset
    90
}
de3fcbb6773e Create debug interface with address of physical device on attachment.
Florian Pose <fp@igh-essen.com>
parents: 687
diff changeset
    91
de3fcbb6773e Create debug interface with address of physical device on attachment.
Florian Pose <fp@igh-essen.com>
parents: 687
diff changeset
    92
/*****************************************************************************/
de3fcbb6773e Create debug interface with address of physical device on attachment.
Florian Pose <fp@igh-essen.com>
parents: 687
diff changeset
    93
de3fcbb6773e Create debug interface with address of physical device on attachment.
Florian Pose <fp@igh-essen.com>
parents: 687
diff changeset
    94
/** Debug interface destructor.
de3fcbb6773e Create debug interface with address of physical device on attachment.
Florian Pose <fp@igh-essen.com>
parents: 687
diff changeset
    95
 *
de3fcbb6773e Create debug interface with address of physical device on attachment.
Florian Pose <fp@igh-essen.com>
parents: 687
diff changeset
    96
 * Unregisters the net_device and frees allocated memory.
de3fcbb6773e Create debug interface with address of physical device on attachment.
Florian Pose <fp@igh-essen.com>
parents: 687
diff changeset
    97
 */
de3fcbb6773e Create debug interface with address of physical device on attachment.
Florian Pose <fp@igh-essen.com>
parents: 687
diff changeset
    98
void ec_debug_clear(
de3fcbb6773e Create debug interface with address of physical device on attachment.
Florian Pose <fp@igh-essen.com>
parents: 687
diff changeset
    99
        ec_debug_t *dbg /**< debug object */
de3fcbb6773e Create debug interface with address of physical device on attachment.
Florian Pose <fp@igh-essen.com>
parents: 687
diff changeset
   100
        )
de3fcbb6773e Create debug interface with address of physical device on attachment.
Florian Pose <fp@igh-essen.com>
parents: 687
diff changeset
   101
{
de3fcbb6773e Create debug interface with address of physical device on attachment.
Florian Pose <fp@igh-essen.com>
parents: 687
diff changeset
   102
    ec_debug_unregister(dbg);
de3fcbb6773e Create debug interface with address of physical device on attachment.
Florian Pose <fp@igh-essen.com>
parents: 687
diff changeset
   103
    free_netdev(dbg->dev);
de3fcbb6773e Create debug interface with address of physical device on attachment.
Florian Pose <fp@igh-essen.com>
parents: 687
diff changeset
   104
}
de3fcbb6773e Create debug interface with address of physical device on attachment.
Florian Pose <fp@igh-essen.com>
parents: 687
diff changeset
   105
de3fcbb6773e Create debug interface with address of physical device on attachment.
Florian Pose <fp@igh-essen.com>
parents: 687
diff changeset
   106
/*****************************************************************************/
de3fcbb6773e Create debug interface with address of physical device on attachment.
Florian Pose <fp@igh-essen.com>
parents: 687
diff changeset
   107
de3fcbb6773e Create debug interface with address of physical device on attachment.
Florian Pose <fp@igh-essen.com>
parents: 687
diff changeset
   108
/** Register debug interface.
de3fcbb6773e Create debug interface with address of physical device on attachment.
Florian Pose <fp@igh-essen.com>
parents: 687
diff changeset
   109
 */
de3fcbb6773e Create debug interface with address of physical device on attachment.
Florian Pose <fp@igh-essen.com>
parents: 687
diff changeset
   110
void ec_debug_register(
de3fcbb6773e Create debug interface with address of physical device on attachment.
Florian Pose <fp@igh-essen.com>
parents: 687
diff changeset
   111
        ec_debug_t *dbg, /**< debug object */
de3fcbb6773e Create debug interface with address of physical device on attachment.
Florian Pose <fp@igh-essen.com>
parents: 687
diff changeset
   112
        const struct net_device *net_dev /**< 'Real' Ethernet device. */
de3fcbb6773e Create debug interface with address of physical device on attachment.
Florian Pose <fp@igh-essen.com>
parents: 687
diff changeset
   113
        )
de3fcbb6773e Create debug interface with address of physical device on attachment.
Florian Pose <fp@igh-essen.com>
parents: 687
diff changeset
   114
{
de3fcbb6773e Create debug interface with address of physical device on attachment.
Florian Pose <fp@igh-essen.com>
parents: 687
diff changeset
   115
    int result;
de3fcbb6773e Create debug interface with address of physical device on attachment.
Florian Pose <fp@igh-essen.com>
parents: 687
diff changeset
   116
de3fcbb6773e Create debug interface with address of physical device on attachment.
Florian Pose <fp@igh-essen.com>
parents: 687
diff changeset
   117
    ec_debug_unregister(dbg);
de3fcbb6773e Create debug interface with address of physical device on attachment.
Florian Pose <fp@igh-essen.com>
parents: 687
diff changeset
   118
de3fcbb6773e Create debug interface with address of physical device on attachment.
Florian Pose <fp@igh-essen.com>
parents: 687
diff changeset
   119
    // use the Ethernet address of the physical device for the debug device
de3fcbb6773e Create debug interface with address of physical device on attachment.
Florian Pose <fp@igh-essen.com>
parents: 687
diff changeset
   120
    memcpy(dbg->dev->dev_addr, net_dev->dev_addr, ETH_ALEN);
de3fcbb6773e Create debug interface with address of physical device on attachment.
Florian Pose <fp@igh-essen.com>
parents: 687
diff changeset
   121
231
767548c75bf3 Added debug interface for network monitors.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   122
    // connect the net_device to the kernel
767548c75bf3 Added debug interface for network monitors.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   123
    if ((result = register_netdev(dbg->dev))) {
1305
de3fcbb6773e Create debug interface with address of physical device on attachment.
Florian Pose <fp@igh-essen.com>
parents: 687
diff changeset
   124
        EC_WARN("Unable to register net_device: error %i\n", result);
de3fcbb6773e Create debug interface with address of physical device on attachment.
Florian Pose <fp@igh-essen.com>
parents: 687
diff changeset
   125
    } else {
de3fcbb6773e Create debug interface with address of physical device on attachment.
Florian Pose <fp@igh-essen.com>
parents: 687
diff changeset
   126
        dbg->registered = 1;
de3fcbb6773e Create debug interface with address of physical device on attachment.
Florian Pose <fp@igh-essen.com>
parents: 687
diff changeset
   127
    }
de3fcbb6773e Create debug interface with address of physical device on attachment.
Florian Pose <fp@igh-essen.com>
parents: 687
diff changeset
   128
}
de3fcbb6773e Create debug interface with address of physical device on attachment.
Florian Pose <fp@igh-essen.com>
parents: 687
diff changeset
   129
de3fcbb6773e Create debug interface with address of physical device on attachment.
Florian Pose <fp@igh-essen.com>
parents: 687
diff changeset
   130
/*****************************************************************************/
de3fcbb6773e Create debug interface with address of physical device on attachment.
Florian Pose <fp@igh-essen.com>
parents: 687
diff changeset
   131
de3fcbb6773e Create debug interface with address of physical device on attachment.
Florian Pose <fp@igh-essen.com>
parents: 687
diff changeset
   132
/** Unregister debug interface.
de3fcbb6773e Create debug interface with address of physical device on attachment.
Florian Pose <fp@igh-essen.com>
parents: 687
diff changeset
   133
 */
de3fcbb6773e Create debug interface with address of physical device on attachment.
Florian Pose <fp@igh-essen.com>
parents: 687
diff changeset
   134
void ec_debug_unregister(
de3fcbb6773e Create debug interface with address of physical device on attachment.
Florian Pose <fp@igh-essen.com>
parents: 687
diff changeset
   135
        ec_debug_t *dbg /**< debug object */
de3fcbb6773e Create debug interface with address of physical device on attachment.
Florian Pose <fp@igh-essen.com>
parents: 687
diff changeset
   136
        )
de3fcbb6773e Create debug interface with address of physical device on attachment.
Florian Pose <fp@igh-essen.com>
parents: 687
diff changeset
   137
{
de3fcbb6773e Create debug interface with address of physical device on attachment.
Florian Pose <fp@igh-essen.com>
parents: 687
diff changeset
   138
    if (dbg->registered) {
de3fcbb6773e Create debug interface with address of physical device on attachment.
Florian Pose <fp@igh-essen.com>
parents: 687
diff changeset
   139
        dbg->opened = 0;
de3fcbb6773e Create debug interface with address of physical device on attachment.
Florian Pose <fp@igh-essen.com>
parents: 687
diff changeset
   140
        dbg->registered = 0;
231
767548c75bf3 Added debug interface for network monitors.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   141
        unregister_netdev(dbg->dev);
1305
de3fcbb6773e Create debug interface with address of physical device on attachment.
Florian Pose <fp@igh-essen.com>
parents: 687
diff changeset
   142
    }
de3fcbb6773e Create debug interface with address of physical device on attachment.
Florian Pose <fp@igh-essen.com>
parents: 687
diff changeset
   143
}
de3fcbb6773e Create debug interface with address of physical device on attachment.
Florian Pose <fp@igh-essen.com>
parents: 687
diff changeset
   144
de3fcbb6773e Create debug interface with address of physical device on attachment.
Florian Pose <fp@igh-essen.com>
parents: 687
diff changeset
   145
/*****************************************************************************/
de3fcbb6773e Create debug interface with address of physical device on attachment.
Florian Pose <fp@igh-essen.com>
parents: 687
diff changeset
   146
de3fcbb6773e Create debug interface with address of physical device on attachment.
Florian Pose <fp@igh-essen.com>
parents: 687
diff changeset
   147
/** Sends frame data to the interface.
de3fcbb6773e Create debug interface with address of physical device on attachment.
Florian Pose <fp@igh-essen.com>
parents: 687
diff changeset
   148
 */
de3fcbb6773e Create debug interface with address of physical device on attachment.
Florian Pose <fp@igh-essen.com>
parents: 687
diff changeset
   149
void ec_debug_send(
de3fcbb6773e Create debug interface with address of physical device on attachment.
Florian Pose <fp@igh-essen.com>
parents: 687
diff changeset
   150
        ec_debug_t *dbg, /**< debug object */
de3fcbb6773e Create debug interface with address of physical device on attachment.
Florian Pose <fp@igh-essen.com>
parents: 687
diff changeset
   151
        const uint8_t *data, /**< frame data */
de3fcbb6773e Create debug interface with address of physical device on attachment.
Florian Pose <fp@igh-essen.com>
parents: 687
diff changeset
   152
        size_t size /**< size of the frame data */
de3fcbb6773e Create debug interface with address of physical device on attachment.
Florian Pose <fp@igh-essen.com>
parents: 687
diff changeset
   153
        )
231
767548c75bf3 Added debug interface for network monitors.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   154
{
767548c75bf3 Added debug interface for network monitors.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   155
    struct sk_buff *skb;
767548c75bf3 Added debug interface for network monitors.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   156
1305
de3fcbb6773e Create debug interface with address of physical device on attachment.
Florian Pose <fp@igh-essen.com>
parents: 687
diff changeset
   157
    if (!dbg->opened)
de3fcbb6773e Create debug interface with address of physical device on attachment.
Florian Pose <fp@igh-essen.com>
parents: 687
diff changeset
   158
        return;
231
767548c75bf3 Added debug interface for network monitors.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   159
767548c75bf3 Added debug interface for network monitors.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   160
    // allocate socket buffer
767548c75bf3 Added debug interface for network monitors.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   161
    if (!(skb = dev_alloc_skb(size))) {
767548c75bf3 Added debug interface for network monitors.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   162
        dbg->stats.rx_dropped++;
767548c75bf3 Added debug interface for network monitors.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   163
        return;
767548c75bf3 Added debug interface for network monitors.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   164
    }
767548c75bf3 Added debug interface for network monitors.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   165
767548c75bf3 Added debug interface for network monitors.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   166
    // copy frame contents into socket buffer
767548c75bf3 Added debug interface for network monitors.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   167
    memcpy(skb_put(skb, size), data, size);
767548c75bf3 Added debug interface for network monitors.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   168
767548c75bf3 Added debug interface for network monitors.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   169
    // update device statistics
767548c75bf3 Added debug interface for network monitors.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   170
    dbg->stats.rx_packets++;
767548c75bf3 Added debug interface for network monitors.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   171
    dbg->stats.rx_bytes += size;
767548c75bf3 Added debug interface for network monitors.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   172
767548c75bf3 Added debug interface for network monitors.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   173
    // pass socket buffer to network stack
767548c75bf3 Added debug interface for network monitors.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   174
    skb->dev = dbg->dev;
767548c75bf3 Added debug interface for network monitors.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   175
    skb->protocol = eth_type_trans(skb, dbg->dev);
767548c75bf3 Added debug interface for network monitors.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   176
    skb->ip_summed = CHECKSUM_UNNECESSARY;
767548c75bf3 Added debug interface for network monitors.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   177
    netif_rx(skb);
767548c75bf3 Added debug interface for network monitors.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   178
}
767548c75bf3 Added debug interface for network monitors.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   179
767548c75bf3 Added debug interface for network monitors.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   180
/******************************************************************************
767548c75bf3 Added debug interface for network monitors.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   181
 *  NET_DEVICE functions
767548c75bf3 Added debug interface for network monitors.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   182
 *****************************************************************************/
767548c75bf3 Added debug interface for network monitors.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   183
1305
de3fcbb6773e Create debug interface with address of physical device on attachment.
Florian Pose <fp@igh-essen.com>
parents: 687
diff changeset
   184
/** Opens the virtual network device.
de3fcbb6773e Create debug interface with address of physical device on attachment.
Florian Pose <fp@igh-essen.com>
parents: 687
diff changeset
   185
 */
de3fcbb6773e Create debug interface with address of physical device on attachment.
Florian Pose <fp@igh-essen.com>
parents: 687
diff changeset
   186
int ec_dbgdev_open(
de3fcbb6773e Create debug interface with address of physical device on attachment.
Florian Pose <fp@igh-essen.com>
parents: 687
diff changeset
   187
        struct net_device *dev /**< debug net_device */
de3fcbb6773e Create debug interface with address of physical device on attachment.
Florian Pose <fp@igh-essen.com>
parents: 687
diff changeset
   188
        )
231
767548c75bf3 Added debug interface for network monitors.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   189
{
767548c75bf3 Added debug interface for network monitors.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   190
    ec_debug_t *dbg = *((ec_debug_t **) netdev_priv(dev));
767548c75bf3 Added debug interface for network monitors.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   191
    dbg->opened = 1;
455
204c435fddf9 Minor output changes in master/debug.c.
Florian Pose <fp@igh-essen.com>
parents: 294
diff changeset
   192
    EC_INFO("Debug interface %s opened.\n", dev->name);
231
767548c75bf3 Added debug interface for network monitors.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   193
    return 0;
767548c75bf3 Added debug interface for network monitors.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   194
}
767548c75bf3 Added debug interface for network monitors.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   195
767548c75bf3 Added debug interface for network monitors.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   196
/*****************************************************************************/
767548c75bf3 Added debug interface for network monitors.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   197
1305
de3fcbb6773e Create debug interface with address of physical device on attachment.
Florian Pose <fp@igh-essen.com>
parents: 687
diff changeset
   198
/** Stops the virtual network device.
de3fcbb6773e Create debug interface with address of physical device on attachment.
Florian Pose <fp@igh-essen.com>
parents: 687
diff changeset
   199
 */
de3fcbb6773e Create debug interface with address of physical device on attachment.
Florian Pose <fp@igh-essen.com>
parents: 687
diff changeset
   200
int ec_dbgdev_stop(
de3fcbb6773e Create debug interface with address of physical device on attachment.
Florian Pose <fp@igh-essen.com>
parents: 687
diff changeset
   201
        struct net_device *dev /**< debug net_device */
de3fcbb6773e Create debug interface with address of physical device on attachment.
Florian Pose <fp@igh-essen.com>
parents: 687
diff changeset
   202
        )
231
767548c75bf3 Added debug interface for network monitors.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   203
{
767548c75bf3 Added debug interface for network monitors.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   204
    ec_debug_t *dbg = *((ec_debug_t **) netdev_priv(dev));
767548c75bf3 Added debug interface for network monitors.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   205
    dbg->opened = 0;
455
204c435fddf9 Minor output changes in master/debug.c.
Florian Pose <fp@igh-essen.com>
parents: 294
diff changeset
   206
    EC_INFO("Debug interface %s stopped.\n", dev->name);
231
767548c75bf3 Added debug interface for network monitors.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   207
    return 0;
767548c75bf3 Added debug interface for network monitors.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   208
}
767548c75bf3 Added debug interface for network monitors.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   209
767548c75bf3 Added debug interface for network monitors.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   210
/*****************************************************************************/
767548c75bf3 Added debug interface for network monitors.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   211
1305
de3fcbb6773e Create debug interface with address of physical device on attachment.
Florian Pose <fp@igh-essen.com>
parents: 687
diff changeset
   212
/** Transmits data via the virtual network device.
de3fcbb6773e Create debug interface with address of physical device on attachment.
Florian Pose <fp@igh-essen.com>
parents: 687
diff changeset
   213
 */
de3fcbb6773e Create debug interface with address of physical device on attachment.
Florian Pose <fp@igh-essen.com>
parents: 687
diff changeset
   214
int ec_dbgdev_tx(
de3fcbb6773e Create debug interface with address of physical device on attachment.
Florian Pose <fp@igh-essen.com>
parents: 687
diff changeset
   215
        struct sk_buff *skb, /**< transmit socket buffer */
de3fcbb6773e Create debug interface with address of physical device on attachment.
Florian Pose <fp@igh-essen.com>
parents: 687
diff changeset
   216
        struct net_device *dev /**< EoE net_device */
de3fcbb6773e Create debug interface with address of physical device on attachment.
Florian Pose <fp@igh-essen.com>
parents: 687
diff changeset
   217
        )
471
0a6bd71bf4d3 Fixed debug interfaces.
Florian Pose <fp@igh-essen.com>
parents: 455
diff changeset
   218
{
0a6bd71bf4d3 Fixed debug interfaces.
Florian Pose <fp@igh-essen.com>
parents: 455
diff changeset
   219
    ec_debug_t *dbg = *((ec_debug_t **) netdev_priv(dev));
0a6bd71bf4d3 Fixed debug interfaces.
Florian Pose <fp@igh-essen.com>
parents: 455
diff changeset
   220
0a6bd71bf4d3 Fixed debug interfaces.
Florian Pose <fp@igh-essen.com>
parents: 455
diff changeset
   221
    dev_kfree_skb(skb);
0a6bd71bf4d3 Fixed debug interfaces.
Florian Pose <fp@igh-essen.com>
parents: 455
diff changeset
   222
    dbg->stats.tx_dropped++;
0a6bd71bf4d3 Fixed debug interfaces.
Florian Pose <fp@igh-essen.com>
parents: 455
diff changeset
   223
    return 0;
0a6bd71bf4d3 Fixed debug interfaces.
Florian Pose <fp@igh-essen.com>
parents: 455
diff changeset
   224
}
0a6bd71bf4d3 Fixed debug interfaces.
Florian Pose <fp@igh-essen.com>
parents: 455
diff changeset
   225
0a6bd71bf4d3 Fixed debug interfaces.
Florian Pose <fp@igh-essen.com>
parents: 455
diff changeset
   226
/*****************************************************************************/
0a6bd71bf4d3 Fixed debug interfaces.
Florian Pose <fp@igh-essen.com>
parents: 455
diff changeset
   227
1305
de3fcbb6773e Create debug interface with address of physical device on attachment.
Florian Pose <fp@igh-essen.com>
parents: 687
diff changeset
   228
/** Gets statistics about the virtual network device.
de3fcbb6773e Create debug interface with address of physical device on attachment.
Florian Pose <fp@igh-essen.com>
parents: 687
diff changeset
   229
 */
de3fcbb6773e Create debug interface with address of physical device on attachment.
Florian Pose <fp@igh-essen.com>
parents: 687
diff changeset
   230
struct net_device_stats *ec_dbgdev_stats(
de3fcbb6773e Create debug interface with address of physical device on attachment.
Florian Pose <fp@igh-essen.com>
parents: 687
diff changeset
   231
        struct net_device *dev /**< debug net_device */
de3fcbb6773e Create debug interface with address of physical device on attachment.
Florian Pose <fp@igh-essen.com>
parents: 687
diff changeset
   232
        )
231
767548c75bf3 Added debug interface for network monitors.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   233
{
767548c75bf3 Added debug interface for network monitors.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   234
    ec_debug_t *dbg = *((ec_debug_t **) netdev_priv(dev));
767548c75bf3 Added debug interface for network monitors.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   235
    return &dbg->stats;
767548c75bf3 Added debug interface for network monitors.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   236
}
767548c75bf3 Added debug interface for network monitors.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   237
767548c75bf3 Added debug interface for network monitors.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   238
/*****************************************************************************/