master/ethernet.c
author Florian Pose <fp@igh-essen.com>
Mon, 26 Jan 2009 11:51:53 +0000
changeset 1331 7cd33a77f926
parent 1327 4d179b06dd3c
child 1337 0253c74d0940
permissions -rw-r--r--
merge -c1609 branches/stable-1.4: INSTALL, README.
145
11a82e4fd31b Mailbox-Interface ausgelagert, erster EOE-Ansatz.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     1
/******************************************************************************
11a82e4fd31b Mailbox-Interface ausgelagert, erster EOE-Ansatz.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     2
 *
11a82e4fd31b Mailbox-Interface ausgelagert, erster EOE-Ansatz.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     3
 *  $Id$
11a82e4fd31b Mailbox-Interface ausgelagert, erster EOE-Ansatz.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     4
 *
1326
ef907b0b5125 merge -c1603 branches/stable-1.4: Changed licence headers to avoid conflicts with the GPL; restricted licence to GPLv2 only.
Florian Pose <fp@igh-essen.com>
parents: 1313
diff changeset
     5
 *  Copyright (C) 2006-2008  Florian Pose, Ingenieurgemeinschaft IgH
197
b9a6e2c22745 GPLv2 License and enhanced Doxygen output.
Florian Pose <fp@igh-essen.com>
parents: 195
diff changeset
     6
 *
b9a6e2c22745 GPLv2 License and enhanced Doxygen output.
Florian Pose <fp@igh-essen.com>
parents: 195
diff changeset
     7
 *  This file is part of the IgH EtherCAT Master.
b9a6e2c22745 GPLv2 License and enhanced Doxygen output.
Florian Pose <fp@igh-essen.com>
parents: 195
diff changeset
     8
 *
1326
ef907b0b5125 merge -c1603 branches/stable-1.4: Changed licence headers to avoid conflicts with the GPL; restricted licence to GPLv2 only.
Florian Pose <fp@igh-essen.com>
parents: 1313
diff changeset
     9
 *  The IgH EtherCAT Master is free software; you can redistribute it and/or
ef907b0b5125 merge -c1603 branches/stable-1.4: Changed licence headers to avoid conflicts with the GPL; restricted licence to GPLv2 only.
Florian Pose <fp@igh-essen.com>
parents: 1313
diff changeset
    10
 *  modify it under the terms of the GNU General Public License version 2, as
ef907b0b5125 merge -c1603 branches/stable-1.4: Changed licence headers to avoid conflicts with the GPL; restricted licence to GPLv2 only.
Florian Pose <fp@igh-essen.com>
parents: 1313
diff changeset
    11
 *  published by the Free Software Foundation.
ef907b0b5125 merge -c1603 branches/stable-1.4: Changed licence headers to avoid conflicts with the GPL; restricted licence to GPLv2 only.
Florian Pose <fp@igh-essen.com>
parents: 1313
diff changeset
    12
 *
ef907b0b5125 merge -c1603 branches/stable-1.4: Changed licence headers to avoid conflicts with the GPL; restricted licence to GPLv2 only.
Florian Pose <fp@igh-essen.com>
parents: 1313
diff changeset
    13
 *  The IgH EtherCAT Master is distributed in the hope that it will be useful,
ef907b0b5125 merge -c1603 branches/stable-1.4: Changed licence headers to avoid conflicts with the GPL; restricted licence to GPLv2 only.
Florian Pose <fp@igh-essen.com>
parents: 1313
diff changeset
    14
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
ef907b0b5125 merge -c1603 branches/stable-1.4: Changed licence headers to avoid conflicts with the GPL; restricted licence to GPLv2 only.
Florian Pose <fp@igh-essen.com>
parents: 1313
diff changeset
    15
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General
ef907b0b5125 merge -c1603 branches/stable-1.4: Changed licence headers to avoid conflicts with the GPL; restricted licence to GPLv2 only.
Florian Pose <fp@igh-essen.com>
parents: 1313
diff changeset
    16
 *  Public License for more details.
ef907b0b5125 merge -c1603 branches/stable-1.4: Changed licence headers to avoid conflicts with the GPL; restricted licence to GPLv2 only.
Florian Pose <fp@igh-essen.com>
parents: 1313
diff changeset
    17
 *
ef907b0b5125 merge -c1603 branches/stable-1.4: Changed licence headers to avoid conflicts with the GPL; restricted licence to GPLv2 only.
Florian Pose <fp@igh-essen.com>
parents: 1313
diff changeset
    18
 *  You should have received a copy of the GNU General Public License along
ef907b0b5125 merge -c1603 branches/stable-1.4: Changed licence headers to avoid conflicts with the GPL; restricted licence to GPLv2 only.
Florian Pose <fp@igh-essen.com>
parents: 1313
diff changeset
    19
 *  with the IgH EtherCAT Master; if not, write to the Free Software
197
b9a6e2c22745 GPLv2 License and enhanced Doxygen output.
Florian Pose <fp@igh-essen.com>
parents: 195
diff changeset
    20
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
b9a6e2c22745 GPLv2 License and enhanced Doxygen output.
Florian Pose <fp@igh-essen.com>
parents: 195
diff changeset
    21
 *
1326
ef907b0b5125 merge -c1603 branches/stable-1.4: Changed licence headers to avoid conflicts with the GPL; restricted licence to GPLv2 only.
Florian Pose <fp@igh-essen.com>
parents: 1313
diff changeset
    22
 *  Using the EtherCAT technology and brand is permitted in compliance with
ef907b0b5125 merge -c1603 branches/stable-1.4: Changed licence headers to avoid conflicts with the GPL; restricted licence to GPLv2 only.
Florian Pose <fp@igh-essen.com>
parents: 1313
diff changeset
    23
 *  the industrial property and similar rights of Beckhoff Automation GmbH.
246
0bf7c769de06 Changed license headers and added EtherCAT license notice.
Florian Pose <fp@igh-essen.com>
parents: 235
diff changeset
    24
 *
145
11a82e4fd31b Mailbox-Interface ausgelagert, erster EOE-Ansatz.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    25
 *****************************************************************************/
11a82e4fd31b Mailbox-Interface ausgelagert, erster EOE-Ansatz.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    26
199
04ecf40fc2e9 Doxygen added interface modules and file documentation.
Florian Pose <fp@igh-essen.com>
parents: 197
diff changeset
    27
/**
04ecf40fc2e9 Doxygen added interface modules and file documentation.
Florian Pose <fp@igh-essen.com>
parents: 197
diff changeset
    28
   \file
1327
4d179b06dd3c merge -c1604 branches/stable-1.4: Fixed spelling of EtherCAT terms.
Florian Pose <fp@igh-essen.com>
parents: 1326
diff changeset
    29
   Ethernet over EtherCAT (EoE).
199
04ecf40fc2e9 Doxygen added interface modules and file documentation.
Florian Pose <fp@igh-essen.com>
parents: 197
diff changeset
    30
*/
04ecf40fc2e9 Doxygen added interface modules and file documentation.
Florian Pose <fp@igh-essen.com>
parents: 197
diff changeset
    31
04ecf40fc2e9 Doxygen added interface modules and file documentation.
Florian Pose <fp@igh-essen.com>
parents: 197
diff changeset
    32
/*****************************************************************************/
04ecf40fc2e9 Doxygen added interface modules and file documentation.
Florian Pose <fp@igh-essen.com>
parents: 197
diff changeset
    33
294
feea8d850c65 Applied include patch by M. Schwerin.
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
    34
#include <linux/netdevice.h>
210
1cc6bcb1e6ae EoE frame receiving; regarding open/stop commands.
Florian Pose <fp@igh-essen.com>
parents: 208
diff changeset
    35
#include <linux/etherdevice.h>
1cc6bcb1e6ae EoE frame receiving; regarding open/stop commands.
Florian Pose <fp@igh-essen.com>
parents: 208
diff changeset
    36
145
11a82e4fd31b Mailbox-Interface ausgelagert, erster EOE-Ansatz.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    37
#include "globals.h"
11a82e4fd31b Mailbox-Interface ausgelagert, erster EOE-Ansatz.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    38
#include "master.h"
11a82e4fd31b Mailbox-Interface ausgelagert, erster EOE-Ansatz.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    39
#include "slave.h"
11a82e4fd31b Mailbox-Interface ausgelagert, erster EOE-Ansatz.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    40
#include "mailbox.h"
11a82e4fd31b Mailbox-Interface ausgelagert, erster EOE-Ansatz.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    41
#include "ethernet.h"
11a82e4fd31b Mailbox-Interface ausgelagert, erster EOE-Ansatz.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    42
629
84a64efca00d Moved a few constants to the files they are needed in.
Florian Pose <fp@igh-essen.com>
parents: 610
diff changeset
    43
/*****************************************************************************/
84a64efca00d Moved a few constants to the files they are needed in.
Florian Pose <fp@igh-essen.com>
parents: 610
diff changeset
    44
84a64efca00d Moved a few constants to the files they are needed in.
Florian Pose <fp@igh-essen.com>
parents: 610
diff changeset
    45
/**
84a64efca00d Moved a few constants to the files they are needed in.
Florian Pose <fp@igh-essen.com>
parents: 610
diff changeset
    46
 * Defines the debug level of EoE processing.
84a64efca00d Moved a few constants to the files they are needed in.
Florian Pose <fp@igh-essen.com>
parents: 610
diff changeset
    47
 *
84a64efca00d Moved a few constants to the files they are needed in.
Florian Pose <fp@igh-essen.com>
parents: 610
diff changeset
    48
 * 0 = No debug messages.
84a64efca00d Moved a few constants to the files they are needed in.
Florian Pose <fp@igh-essen.com>
parents: 610
diff changeset
    49
 * 1 = Output actions.
84a64efca00d Moved a few constants to the files they are needed in.
Florian Pose <fp@igh-essen.com>
parents: 610
diff changeset
    50
 * 2 = Output actions and frame data.
84a64efca00d Moved a few constants to the files they are needed in.
Florian Pose <fp@igh-essen.com>
parents: 610
diff changeset
    51
 */
286
f3352378b4d4 Added missing documentation.
Florian Pose <fp@igh-essen.com>
parents: 279
diff changeset
    52
216
e7f3e485c5b8 EoE: Corrected faulty MAC address.
Florian Pose <fp@igh-essen.com>
parents: 215
diff changeset
    53
#define EOE_DEBUG_LEVEL 0
215
b021aa6eee38 EoE: TCP traffic possible; TX fragmenting to do.
Florian Pose <fp@igh-essen.com>
parents: 214
diff changeset
    54
629
84a64efca00d Moved a few constants to the files they are needed in.
Florian Pose <fp@igh-essen.com>
parents: 610
diff changeset
    55
/** size of the EoE tx queue */
84a64efca00d Moved a few constants to the files they are needed in.
Florian Pose <fp@igh-essen.com>
parents: 610
diff changeset
    56
#define EC_EOE_TX_QUEUE_SIZE 100
84a64efca00d Moved a few constants to the files they are needed in.
Florian Pose <fp@igh-essen.com>
parents: 610
diff changeset
    57
145
11a82e4fd31b Mailbox-Interface ausgelagert, erster EOE-Ansatz.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    58
/*****************************************************************************/
11a82e4fd31b Mailbox-Interface ausgelagert, erster EOE-Ansatz.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    59
214
8beb86af5ed0 EoE frame queuing, receiving of fragmented frames; no TCP possible yet.
Florian Pose <fp@igh-essen.com>
parents: 213
diff changeset
    60
void ec_eoe_flush(ec_eoe_t *);
218
80fb87518f3d EoE: State machine with function pointers, documentation.
Florian Pose <fp@igh-essen.com>
parents: 217
diff changeset
    61
80fb87518f3d EoE: State machine with function pointers, documentation.
Florian Pose <fp@igh-essen.com>
parents: 217
diff changeset
    62
// state functions
80fb87518f3d EoE: State machine with function pointers, documentation.
Florian Pose <fp@igh-essen.com>
parents: 217
diff changeset
    63
void ec_eoe_state_rx_start(ec_eoe_t *);
80fb87518f3d EoE: State machine with function pointers, documentation.
Florian Pose <fp@igh-essen.com>
parents: 217
diff changeset
    64
void ec_eoe_state_rx_check(ec_eoe_t *);
80fb87518f3d EoE: State machine with function pointers, documentation.
Florian Pose <fp@igh-essen.com>
parents: 217
diff changeset
    65
void ec_eoe_state_rx_fetch(ec_eoe_t *);
80fb87518f3d EoE: State machine with function pointers, documentation.
Florian Pose <fp@igh-essen.com>
parents: 217
diff changeset
    66
void ec_eoe_state_tx_start(ec_eoe_t *);
80fb87518f3d EoE: State machine with function pointers, documentation.
Florian Pose <fp@igh-essen.com>
parents: 217
diff changeset
    67
void ec_eoe_state_tx_sent(ec_eoe_t *);
80fb87518f3d EoE: State machine with function pointers, documentation.
Florian Pose <fp@igh-essen.com>
parents: 217
diff changeset
    68
80fb87518f3d EoE: State machine with function pointers, documentation.
Florian Pose <fp@igh-essen.com>
parents: 217
diff changeset
    69
// net_device functions
203
c1f305e339c6 EoE net_device implementation.
Florian Pose <fp@igh-essen.com>
parents: 199
diff changeset
    70
int ec_eoedev_open(struct net_device *);
c1f305e339c6 EoE net_device implementation.
Florian Pose <fp@igh-essen.com>
parents: 199
diff changeset
    71
int ec_eoedev_stop(struct net_device *);
c1f305e339c6 EoE net_device implementation.
Florian Pose <fp@igh-essen.com>
parents: 199
diff changeset
    72
int ec_eoedev_tx(struct sk_buff *, struct net_device *);
c1f305e339c6 EoE net_device implementation.
Florian Pose <fp@igh-essen.com>
parents: 199
diff changeset
    73
struct net_device_stats *ec_eoedev_stats(struct net_device *);
c1f305e339c6 EoE net_device implementation.
Florian Pose <fp@igh-essen.com>
parents: 199
diff changeset
    74
c1f305e339c6 EoE net_device implementation.
Florian Pose <fp@igh-essen.com>
parents: 199
diff changeset
    75
/*****************************************************************************/
c1f305e339c6 EoE net_device implementation.
Florian Pose <fp@igh-essen.com>
parents: 199
diff changeset
    76
c1f305e339c6 EoE net_device implementation.
Florian Pose <fp@igh-essen.com>
parents: 199
diff changeset
    77
/**
661
bc1de1362efb Dynamic creation of EoE handlers.
Florian Pose <fp@igh-essen.com>
parents: 629
diff changeset
    78
 * EoE constructor.
bc1de1362efb Dynamic creation of EoE handlers.
Florian Pose <fp@igh-essen.com>
parents: 629
diff changeset
    79
 * Initializes the EoE handler, creates a net_device and registers it.
bc1de1362efb Dynamic creation of EoE handlers.
Florian Pose <fp@igh-essen.com>
parents: 629
diff changeset
    80
 */
bc1de1362efb Dynamic creation of EoE handlers.
Florian Pose <fp@igh-essen.com>
parents: 629
diff changeset
    81
bc1de1362efb Dynamic creation of EoE handlers.
Florian Pose <fp@igh-essen.com>
parents: 629
diff changeset
    82
int ec_eoe_init(
bc1de1362efb Dynamic creation of EoE handlers.
Florian Pose <fp@igh-essen.com>
parents: 629
diff changeset
    83
        ec_eoe_t *eoe, /**< EoE handler */
bc1de1362efb Dynamic creation of EoE handlers.
Florian Pose <fp@igh-essen.com>
parents: 629
diff changeset
    84
        ec_slave_t *slave /**< EtherCAT slave */
bc1de1362efb Dynamic creation of EoE handlers.
Florian Pose <fp@igh-essen.com>
parents: 629
diff changeset
    85
        )
203
c1f305e339c6 EoE net_device implementation.
Florian Pose <fp@igh-essen.com>
parents: 199
diff changeset
    86
{
213
8d723b9833a9 removed unnecessary private structure in eoe net_device.
Florian Pose <fp@igh-essen.com>
parents: 212
diff changeset
    87
    ec_eoe_t **priv;
1313
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1209
diff changeset
    88
    int i, ret = 0;
719
03d5b96632fb Store skipped information in datagrams; name datagrams for statistics
Florian Pose <fp@igh-essen.com>
parents: 712
diff changeset
    89
    char name[EC_DATAGRAM_NAME_SIZE];
661
bc1de1362efb Dynamic creation of EoE handlers.
Florian Pose <fp@igh-essen.com>
parents: 629
diff changeset
    90
bc1de1362efb Dynamic creation of EoE handlers.
Florian Pose <fp@igh-essen.com>
parents: 629
diff changeset
    91
    eoe->slave = slave;
bc1de1362efb Dynamic creation of EoE handlers.
Florian Pose <fp@igh-essen.com>
parents: 629
diff changeset
    92
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
    93
    ec_datagram_init(&eoe->datagram);
721
ebc2fd3e09e5 Improved EoE handling: Avoided skipping of datagrams and release lock
Florian Pose <fp@igh-essen.com>
parents: 719
diff changeset
    94
    eoe->queue_datagram = 0;
218
80fb87518f3d EoE: State machine with function pointers, documentation.
Florian Pose <fp@igh-essen.com>
parents: 217
diff changeset
    95
    eoe->state = ec_eoe_state_rx_start;
210
1cc6bcb1e6ae EoE frame receiving; regarding open/stop commands.
Florian Pose <fp@igh-essen.com>
parents: 208
diff changeset
    96
    eoe->opened = 0;
218
80fb87518f3d EoE: State machine with function pointers, documentation.
Florian Pose <fp@igh-essen.com>
parents: 217
diff changeset
    97
    eoe->rx_skb = NULL;
80fb87518f3d EoE: State machine with function pointers, documentation.
Florian Pose <fp@igh-essen.com>
parents: 217
diff changeset
    98
    eoe->rx_expected_fragment = 0;
212
82980deb8b00 moved stats into eoe struct; persistent rx-skb; tx queue.
Florian Pose <fp@igh-essen.com>
parents: 210
diff changeset
    99
    INIT_LIST_HEAD(&eoe->tx_queue);
218
80fb87518f3d EoE: State machine with function pointers, documentation.
Florian Pose <fp@igh-essen.com>
parents: 217
diff changeset
   100
    eoe->tx_frame = NULL;
214
8beb86af5ed0 EoE frame queuing, receiving of fragmented frames; no TCP possible yet.
Florian Pose <fp@igh-essen.com>
parents: 213
diff changeset
   101
    eoe->tx_queue_active = 0;
218
80fb87518f3d EoE: State machine with function pointers, documentation.
Florian Pose <fp@igh-essen.com>
parents: 217
diff changeset
   102
    eoe->tx_queued_frames = 0;
212
82980deb8b00 moved stats into eoe struct; persistent rx-skb; tx queue.
Florian Pose <fp@igh-essen.com>
parents: 210
diff changeset
   103
    eoe->tx_queue_lock = SPIN_LOCK_UNLOCKED;
214
8beb86af5ed0 EoE frame queuing, receiving of fragmented frames; no TCP possible yet.
Florian Pose <fp@igh-essen.com>
parents: 213
diff changeset
   104
    eoe->tx_frame_number = 0xFF;
8beb86af5ed0 EoE frame queuing, receiving of fragmented frames; no TCP possible yet.
Florian Pose <fp@igh-essen.com>
parents: 213
diff changeset
   105
    memset(&eoe->stats, 0, sizeof(struct net_device_stats));
203
c1f305e339c6 EoE net_device implementation.
Florian Pose <fp@igh-essen.com>
parents: 199
diff changeset
   106
336
360e5287c888 EoE rate statistics.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
   107
    eoe->rx_counter = 0;
360e5287c888 EoE rate statistics.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
   108
    eoe->tx_counter = 0;
360e5287c888 EoE rate statistics.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
   109
    eoe->rx_rate = 0;
360e5287c888 EoE rate statistics.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
   110
    eoe->tx_rate = 0;
344
5d8281f1aa2a Replaced longer cycle timestamps with jiffies.
Florian Pose <fp@igh-essen.com>
parents: 340
diff changeset
   111
    eoe->rate_jiffies = 0;
336
360e5287c888 EoE rate statistics.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
   112
712
14f899ac51f0 Create network interfaces for EoE devices with alias as eoeXaY.
Florian Pose <fp@igh-essen.com>
parents: 689
diff changeset
   113
    /* device name eoe<MASTER>[as]<SLAVE>, because networking scripts don't
14f899ac51f0 Create network interfaces for EoE devices with alias as eoeXaY.
Florian Pose <fp@igh-essen.com>
parents: 689
diff changeset
   114
     * like hyphens etc. in interface names. */
834
0791aac03180 Separated SII data from slave.
Florian Pose <fp@igh-essen.com>
parents: 770
diff changeset
   115
    if (slave->sii.alias) {
719
03d5b96632fb Store skipped information in datagrams; name datagrams for statistics
Florian Pose <fp@igh-essen.com>
parents: 712
diff changeset
   116
        snprintf(name, EC_DATAGRAM_NAME_SIZE,
834
0791aac03180 Separated SII data from slave.
Florian Pose <fp@igh-essen.com>
parents: 770
diff changeset
   117
                "eoe%ua%u", slave->master->index, slave->sii.alias);
712
14f899ac51f0 Create network interfaces for EoE devices with alias as eoeXaY.
Florian Pose <fp@igh-essen.com>
parents: 689
diff changeset
   118
    } else {
719
03d5b96632fb Store skipped information in datagrams; name datagrams for statistics
Florian Pose <fp@igh-essen.com>
parents: 712
diff changeset
   119
        snprintf(name, EC_DATAGRAM_NAME_SIZE,
03d5b96632fb Store skipped information in datagrams; name datagrams for statistics
Florian Pose <fp@igh-essen.com>
parents: 712
diff changeset
   120
                "eoe%us%u", slave->master->index, slave->ring_position);
03d5b96632fb Store skipped information in datagrams; name datagrams for statistics
Florian Pose <fp@igh-essen.com>
parents: 712
diff changeset
   121
    }
03d5b96632fb Store skipped information in datagrams; name datagrams for statistics
Florian Pose <fp@igh-essen.com>
parents: 712
diff changeset
   122
03d5b96632fb Store skipped information in datagrams; name datagrams for statistics
Florian Pose <fp@igh-essen.com>
parents: 712
diff changeset
   123
    snprintf(eoe->datagram.name, EC_DATAGRAM_NAME_SIZE, name);
661
bc1de1362efb Dynamic creation of EoE handlers.
Florian Pose <fp@igh-essen.com>
parents: 629
diff changeset
   124
bc1de1362efb Dynamic creation of EoE handlers.
Florian Pose <fp@igh-essen.com>
parents: 629
diff changeset
   125
    if (!(eoe->dev = alloc_netdev(sizeof(ec_eoe_t *), name, ether_setup))) {
712
14f899ac51f0 Create network interfaces for EoE devices with alias as eoeXaY.
Florian Pose <fp@igh-essen.com>
parents: 689
diff changeset
   126
        EC_ERR("Unable to allocate net_device %s for EoE handler!\n", name);
1313
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1209
diff changeset
   127
        ret = -ENODEV;
203
c1f305e339c6 EoE net_device implementation.
Florian Pose <fp@igh-essen.com>
parents: 199
diff changeset
   128
        goto out_return;
c1f305e339c6 EoE net_device implementation.
Florian Pose <fp@igh-essen.com>
parents: 199
diff changeset
   129
    }
c1f305e339c6 EoE net_device implementation.
Florian Pose <fp@igh-essen.com>
parents: 199
diff changeset
   130
218
80fb87518f3d EoE: State machine with function pointers, documentation.
Florian Pose <fp@igh-essen.com>
parents: 217
diff changeset
   131
    // initialize net_device
80fb87518f3d EoE: State machine with function pointers, documentation.
Florian Pose <fp@igh-essen.com>
parents: 217
diff changeset
   132
    eoe->dev->open = ec_eoedev_open;
80fb87518f3d EoE: State machine with function pointers, documentation.
Florian Pose <fp@igh-essen.com>
parents: 217
diff changeset
   133
    eoe->dev->stop = ec_eoedev_stop;
80fb87518f3d EoE: State machine with function pointers, documentation.
Florian Pose <fp@igh-essen.com>
parents: 217
diff changeset
   134
    eoe->dev->hard_start_xmit = ec_eoedev_tx;
80fb87518f3d EoE: State machine with function pointers, documentation.
Florian Pose <fp@igh-essen.com>
parents: 217
diff changeset
   135
    eoe->dev->get_stats = ec_eoedev_stats;
80fb87518f3d EoE: State machine with function pointers, documentation.
Florian Pose <fp@igh-essen.com>
parents: 217
diff changeset
   136
80fb87518f3d EoE: State machine with function pointers, documentation.
Florian Pose <fp@igh-essen.com>
parents: 217
diff changeset
   137
    for (i = 0; i < ETH_ALEN; i++)
80fb87518f3d EoE: State machine with function pointers, documentation.
Florian Pose <fp@igh-essen.com>
parents: 217
diff changeset
   138
        eoe->dev->dev_addr[i] = i | (i << 4);
80fb87518f3d EoE: State machine with function pointers, documentation.
Florian Pose <fp@igh-essen.com>
parents: 217
diff changeset
   139
80fb87518f3d EoE: State machine with function pointers, documentation.
Florian Pose <fp@igh-essen.com>
parents: 217
diff changeset
   140
    // initialize private data
203
c1f305e339c6 EoE net_device implementation.
Florian Pose <fp@igh-essen.com>
parents: 199
diff changeset
   141
    priv = netdev_priv(eoe->dev);
213
8d723b9833a9 removed unnecessary private structure in eoe net_device.
Florian Pose <fp@igh-essen.com>
parents: 212
diff changeset
   142
    *priv = eoe;
203
c1f305e339c6 EoE net_device implementation.
Florian Pose <fp@igh-essen.com>
parents: 199
diff changeset
   143
218
80fb87518f3d EoE: State machine with function pointers, documentation.
Florian Pose <fp@igh-essen.com>
parents: 217
diff changeset
   144
    // Usually setting the MTU appropriately makes the upper layers
80fb87518f3d EoE: State machine with function pointers, documentation.
Florian Pose <fp@igh-essen.com>
parents: 217
diff changeset
   145
    // do the frame fragmenting. In some cases this doesn't work
80fb87518f3d EoE: State machine with function pointers, documentation.
Florian Pose <fp@igh-essen.com>
parents: 217
diff changeset
   146
    // so the MTU is left on the Ethernet standard value and fragmenting
80fb87518f3d EoE: State machine with function pointers, documentation.
Florian Pose <fp@igh-essen.com>
parents: 217
diff changeset
   147
    // is done "manually".
80fb87518f3d EoE: State machine with function pointers, documentation.
Florian Pose <fp@igh-essen.com>
parents: 217
diff changeset
   148
#if 0
834
0791aac03180 Separated SII data from slave.
Florian Pose <fp@igh-essen.com>
parents: 770
diff changeset
   149
    eoe->dev->mtu = slave->sii.rx_mailbox_size - ETH_HLEN - 10;
218
80fb87518f3d EoE: State machine with function pointers, documentation.
Florian Pose <fp@igh-essen.com>
parents: 217
diff changeset
   150
#endif
214
8beb86af5ed0 EoE frame queuing, receiving of fragmented frames; no TCP possible yet.
Florian Pose <fp@igh-essen.com>
parents: 213
diff changeset
   151
203
c1f305e339c6 EoE net_device implementation.
Florian Pose <fp@igh-essen.com>
parents: 199
diff changeset
   152
    // connect the net_device to the kernel
1313
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1209
diff changeset
   153
    ret = register_netdev(eoe->dev);
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1209
diff changeset
   154
    if (ret) {
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1209
diff changeset
   155
        EC_ERR("Unable to register net_device: error %i\n", ret);
203
c1f305e339c6 EoE net_device implementation.
Florian Pose <fp@igh-essen.com>
parents: 199
diff changeset
   156
        goto out_free;
c1f305e339c6 EoE net_device implementation.
Florian Pose <fp@igh-essen.com>
parents: 199
diff changeset
   157
    }
c1f305e339c6 EoE net_device implementation.
Florian Pose <fp@igh-essen.com>
parents: 199
diff changeset
   158
218
80fb87518f3d EoE: State machine with function pointers, documentation.
Florian Pose <fp@igh-essen.com>
parents: 217
diff changeset
   159
    // make the last address octet unique
80fb87518f3d EoE: State machine with function pointers, documentation.
Florian Pose <fp@igh-essen.com>
parents: 217
diff changeset
   160
    eoe->dev->dev_addr[ETH_ALEN - 1] = (uint8_t) eoe->dev->ifindex;
203
c1f305e339c6 EoE net_device implementation.
Florian Pose <fp@igh-essen.com>
parents: 199
diff changeset
   161
    return 0;
c1f305e339c6 EoE net_device implementation.
Florian Pose <fp@igh-essen.com>
parents: 199
diff changeset
   162
c1f305e339c6 EoE net_device implementation.
Florian Pose <fp@igh-essen.com>
parents: 199
diff changeset
   163
 out_free:
c1f305e339c6 EoE net_device implementation.
Florian Pose <fp@igh-essen.com>
parents: 199
diff changeset
   164
    free_netdev(eoe->dev);
c1f305e339c6 EoE net_device implementation.
Florian Pose <fp@igh-essen.com>
parents: 199
diff changeset
   165
    eoe->dev = NULL;
c1f305e339c6 EoE net_device implementation.
Florian Pose <fp@igh-essen.com>
parents: 199
diff changeset
   166
 out_return:
1313
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1209
diff changeset
   167
    return ret;
145
11a82e4fd31b Mailbox-Interface ausgelagert, erster EOE-Ansatz.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   168
}
11a82e4fd31b Mailbox-Interface ausgelagert, erster EOE-Ansatz.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   169
11a82e4fd31b Mailbox-Interface ausgelagert, erster EOE-Ansatz.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   170
/*****************************************************************************/
11a82e4fd31b Mailbox-Interface ausgelagert, erster EOE-Ansatz.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   171
197
b9a6e2c22745 GPLv2 License and enhanced Doxygen output.
Florian Pose <fp@igh-essen.com>
parents: 195
diff changeset
   172
/**
199
04ecf40fc2e9 Doxygen added interface modules and file documentation.
Florian Pose <fp@igh-essen.com>
parents: 197
diff changeset
   173
   EoE destructor.
218
80fb87518f3d EoE: State machine with function pointers, documentation.
Florian Pose <fp@igh-essen.com>
parents: 217
diff changeset
   174
   Unregisteres the net_device and frees allocated memory.
80fb87518f3d EoE: State machine with function pointers, documentation.
Florian Pose <fp@igh-essen.com>
parents: 217
diff changeset
   175
*/
80fb87518f3d EoE: State machine with function pointers, documentation.
Florian Pose <fp@igh-essen.com>
parents: 217
diff changeset
   176
251
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   177
void ec_eoe_clear(ec_eoe_t *eoe /**< EoE handler */)
145
11a82e4fd31b Mailbox-Interface ausgelagert, erster EOE-Ansatz.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   178
{
552
029546740810 Minor: Removed warning when EoE interface is up upon master unloading.
Florian Pose <fp@igh-essen.com>
parents: 460
diff changeset
   179
    unregister_netdev(eoe->dev); // possibly calls close callback
325
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 322
diff changeset
   180
    free_netdev(eoe->dev);
214
8beb86af5ed0 EoE frame queuing, receiving of fragmented frames; no TCP possible yet.
Florian Pose <fp@igh-essen.com>
parents: 213
diff changeset
   181
8beb86af5ed0 EoE frame queuing, receiving of fragmented frames; no TCP possible yet.
Florian Pose <fp@igh-essen.com>
parents: 213
diff changeset
   182
    // empty transmit queue
8beb86af5ed0 EoE frame queuing, receiving of fragmented frames; no TCP possible yet.
Florian Pose <fp@igh-essen.com>
parents: 213
diff changeset
   183
    ec_eoe_flush(eoe);
218
80fb87518f3d EoE: State machine with function pointers, documentation.
Florian Pose <fp@igh-essen.com>
parents: 217
diff changeset
   184
80fb87518f3d EoE: State machine with function pointers, documentation.
Florian Pose <fp@igh-essen.com>
parents: 217
diff changeset
   185
    if (eoe->tx_frame) {
80fb87518f3d EoE: State machine with function pointers, documentation.
Florian Pose <fp@igh-essen.com>
parents: 217
diff changeset
   186
        dev_kfree_skb(eoe->tx_frame->skb);
80fb87518f3d EoE: State machine with function pointers, documentation.
Florian Pose <fp@igh-essen.com>
parents: 217
diff changeset
   187
        kfree(eoe->tx_frame);
80fb87518f3d EoE: State machine with function pointers, documentation.
Florian Pose <fp@igh-essen.com>
parents: 217
diff changeset
   188
    }
80fb87518f3d EoE: State machine with function pointers, documentation.
Florian Pose <fp@igh-essen.com>
parents: 217
diff changeset
   189
80fb87518f3d EoE: State machine with function pointers, documentation.
Florian Pose <fp@igh-essen.com>
parents: 217
diff changeset
   190
    if (eoe->rx_skb) dev_kfree_skb(eoe->rx_skb);
279
12f48c1cb143 Removed mbox_command out of slave.
Florian Pose <fp@igh-essen.com>
parents: 261
diff changeset
   191
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
   192
    ec_datagram_clear(&eoe->datagram);
214
8beb86af5ed0 EoE frame queuing, receiving of fragmented frames; no TCP possible yet.
Florian Pose <fp@igh-essen.com>
parents: 213
diff changeset
   193
}
8beb86af5ed0 EoE frame queuing, receiving of fragmented frames; no TCP possible yet.
Florian Pose <fp@igh-essen.com>
parents: 213
diff changeset
   194
8beb86af5ed0 EoE frame queuing, receiving of fragmented frames; no TCP possible yet.
Florian Pose <fp@igh-essen.com>
parents: 213
diff changeset
   195
/*****************************************************************************/
8beb86af5ed0 EoE frame queuing, receiving of fragmented frames; no TCP possible yet.
Florian Pose <fp@igh-essen.com>
parents: 213
diff changeset
   196
8beb86af5ed0 EoE frame queuing, receiving of fragmented frames; no TCP possible yet.
Florian Pose <fp@igh-essen.com>
parents: 213
diff changeset
   197
/**
8beb86af5ed0 EoE frame queuing, receiving of fragmented frames; no TCP possible yet.
Florian Pose <fp@igh-essen.com>
parents: 213
diff changeset
   198
   Empties the transmit queue.
8beb86af5ed0 EoE frame queuing, receiving of fragmented frames; no TCP possible yet.
Florian Pose <fp@igh-essen.com>
parents: 213
diff changeset
   199
*/
8beb86af5ed0 EoE frame queuing, receiving of fragmented frames; no TCP possible yet.
Florian Pose <fp@igh-essen.com>
parents: 213
diff changeset
   200
251
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   201
void ec_eoe_flush(ec_eoe_t *eoe /**< EoE handler */)
214
8beb86af5ed0 EoE frame queuing, receiving of fragmented frames; no TCP possible yet.
Florian Pose <fp@igh-essen.com>
parents: 213
diff changeset
   202
{
8beb86af5ed0 EoE frame queuing, receiving of fragmented frames; no TCP possible yet.
Florian Pose <fp@igh-essen.com>
parents: 213
diff changeset
   203
    ec_eoe_frame_t *frame, *next;
8beb86af5ed0 EoE frame queuing, receiving of fragmented frames; no TCP possible yet.
Florian Pose <fp@igh-essen.com>
parents: 213
diff changeset
   204
8beb86af5ed0 EoE frame queuing, receiving of fragmented frames; no TCP possible yet.
Florian Pose <fp@igh-essen.com>
parents: 213
diff changeset
   205
    spin_lock_bh(&eoe->tx_queue_lock);
8beb86af5ed0 EoE frame queuing, receiving of fragmented frames; no TCP possible yet.
Florian Pose <fp@igh-essen.com>
parents: 213
diff changeset
   206
8beb86af5ed0 EoE frame queuing, receiving of fragmented frames; no TCP possible yet.
Florian Pose <fp@igh-essen.com>
parents: 213
diff changeset
   207
    list_for_each_entry_safe(frame, next, &eoe->tx_queue, queue) {
8beb86af5ed0 EoE frame queuing, receiving of fragmented frames; no TCP possible yet.
Florian Pose <fp@igh-essen.com>
parents: 213
diff changeset
   208
        list_del(&frame->queue);
8beb86af5ed0 EoE frame queuing, receiving of fragmented frames; no TCP possible yet.
Florian Pose <fp@igh-essen.com>
parents: 213
diff changeset
   209
        dev_kfree_skb(frame->skb);
8beb86af5ed0 EoE frame queuing, receiving of fragmented frames; no TCP possible yet.
Florian Pose <fp@igh-essen.com>
parents: 213
diff changeset
   210
        kfree(frame);
8beb86af5ed0 EoE frame queuing, receiving of fragmented frames; no TCP possible yet.
Florian Pose <fp@igh-essen.com>
parents: 213
diff changeset
   211
    }
218
80fb87518f3d EoE: State machine with function pointers, documentation.
Florian Pose <fp@igh-essen.com>
parents: 217
diff changeset
   212
    eoe->tx_queued_frames = 0;
214
8beb86af5ed0 EoE frame queuing, receiving of fragmented frames; no TCP possible yet.
Florian Pose <fp@igh-essen.com>
parents: 213
diff changeset
   213
8beb86af5ed0 EoE frame queuing, receiving of fragmented frames; no TCP possible yet.
Florian Pose <fp@igh-essen.com>
parents: 213
diff changeset
   214
    spin_unlock_bh(&eoe->tx_queue_lock);
145
11a82e4fd31b Mailbox-Interface ausgelagert, erster EOE-Ansatz.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   215
}
11a82e4fd31b Mailbox-Interface ausgelagert, erster EOE-Ansatz.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   216
11a82e4fd31b Mailbox-Interface ausgelagert, erster EOE-Ansatz.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   217
/*****************************************************************************/
11a82e4fd31b Mailbox-Interface ausgelagert, erster EOE-Ansatz.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   218
197
b9a6e2c22745 GPLv2 License and enhanced Doxygen output.
Florian Pose <fp@igh-essen.com>
parents: 195
diff changeset
   219
/**
217
dcfd406e7786 EoE - TX fragmenting works. TCP traffic possible.
Florian Pose <fp@igh-essen.com>
parents: 216
diff changeset
   220
   Sends a frame or the next fragment.
dcfd406e7786 EoE - TX fragmenting works. TCP traffic possible.
Florian Pose <fp@igh-essen.com>
parents: 216
diff changeset
   221
*/
dcfd406e7786 EoE - TX fragmenting works. TCP traffic possible.
Florian Pose <fp@igh-essen.com>
parents: 216
diff changeset
   222
251
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   223
int ec_eoe_send(ec_eoe_t *eoe /**< EoE handler */)
218
80fb87518f3d EoE: State machine with function pointers, documentation.
Florian Pose <fp@igh-essen.com>
parents: 217
diff changeset
   224
{
217
dcfd406e7786 EoE - TX fragmenting works. TCP traffic possible.
Florian Pose <fp@igh-essen.com>
parents: 216
diff changeset
   225
    size_t remaining_size, current_size, complete_offset;
dcfd406e7786 EoE - TX fragmenting works. TCP traffic possible.
Florian Pose <fp@igh-essen.com>
parents: 216
diff changeset
   226
    unsigned int last_fragment;
dcfd406e7786 EoE - TX fragmenting works. TCP traffic possible.
Florian Pose <fp@igh-essen.com>
parents: 216
diff changeset
   227
    uint8_t *data;
dcfd406e7786 EoE - TX fragmenting works. TCP traffic possible.
Florian Pose <fp@igh-essen.com>
parents: 216
diff changeset
   228
#if EOE_DEBUG_LEVEL > 1
dcfd406e7786 EoE - TX fragmenting works. TCP traffic possible.
Florian Pose <fp@igh-essen.com>
parents: 216
diff changeset
   229
    unsigned int i;
dcfd406e7786 EoE - TX fragmenting works. TCP traffic possible.
Florian Pose <fp@igh-essen.com>
parents: 216
diff changeset
   230
#endif
dcfd406e7786 EoE - TX fragmenting works. TCP traffic possible.
Florian Pose <fp@igh-essen.com>
parents: 216
diff changeset
   231
218
80fb87518f3d EoE: State machine with function pointers, documentation.
Florian Pose <fp@igh-essen.com>
parents: 217
diff changeset
   232
    remaining_size = eoe->tx_frame->skb->len - eoe->tx_offset;
217
dcfd406e7786 EoE - TX fragmenting works. TCP traffic possible.
Florian Pose <fp@igh-essen.com>
parents: 216
diff changeset
   233
834
0791aac03180 Separated SII data from slave.
Florian Pose <fp@igh-essen.com>
parents: 770
diff changeset
   234
    if (remaining_size <= eoe->slave->sii.tx_mailbox_size - 10) {
217
dcfd406e7786 EoE - TX fragmenting works. TCP traffic possible.
Florian Pose <fp@igh-essen.com>
parents: 216
diff changeset
   235
        current_size = remaining_size;
dcfd406e7786 EoE - TX fragmenting works. TCP traffic possible.
Florian Pose <fp@igh-essen.com>
parents: 216
diff changeset
   236
        last_fragment = 1;
dcfd406e7786 EoE - TX fragmenting works. TCP traffic possible.
Florian Pose <fp@igh-essen.com>
parents: 216
diff changeset
   237
    }
dcfd406e7786 EoE - TX fragmenting works. TCP traffic possible.
Florian Pose <fp@igh-essen.com>
parents: 216
diff changeset
   238
    else {
834
0791aac03180 Separated SII data from slave.
Florian Pose <fp@igh-essen.com>
parents: 770
diff changeset
   239
        current_size = ((eoe->slave->sii.tx_mailbox_size - 10) / 32) * 32;
217
dcfd406e7786 EoE - TX fragmenting works. TCP traffic possible.
Florian Pose <fp@igh-essen.com>
parents: 216
diff changeset
   240
        last_fragment = 0;
dcfd406e7786 EoE - TX fragmenting works. TCP traffic possible.
Florian Pose <fp@igh-essen.com>
parents: 216
diff changeset
   241
    }
dcfd406e7786 EoE - TX fragmenting works. TCP traffic possible.
Florian Pose <fp@igh-essen.com>
parents: 216
diff changeset
   242
dcfd406e7786 EoE - TX fragmenting works. TCP traffic possible.
Florian Pose <fp@igh-essen.com>
parents: 216
diff changeset
   243
    if (eoe->tx_fragment_number) {
dcfd406e7786 EoE - TX fragmenting works. TCP traffic possible.
Florian Pose <fp@igh-essen.com>
parents: 216
diff changeset
   244
        complete_offset = eoe->tx_offset / 32;
dcfd406e7786 EoE - TX fragmenting works. TCP traffic possible.
Florian Pose <fp@igh-essen.com>
parents: 216
diff changeset
   245
    }
dcfd406e7786 EoE - TX fragmenting works. TCP traffic possible.
Florian Pose <fp@igh-essen.com>
parents: 216
diff changeset
   246
    else {
319
88f2e8c4face Minor changes.
Florian Pose <fp@igh-essen.com>
parents: 314
diff changeset
   247
        // complete size in 32 bit blocks, rounded up.
217
dcfd406e7786 EoE - TX fragmenting works. TCP traffic possible.
Florian Pose <fp@igh-essen.com>
parents: 216
diff changeset
   248
        complete_offset = remaining_size / 32 + 1;
dcfd406e7786 EoE - TX fragmenting works. TCP traffic possible.
Florian Pose <fp@igh-essen.com>
parents: 216
diff changeset
   249
    }
dcfd406e7786 EoE - TX fragmenting works. TCP traffic possible.
Florian Pose <fp@igh-essen.com>
parents: 216
diff changeset
   250
dcfd406e7786 EoE - TX fragmenting works. TCP traffic possible.
Florian Pose <fp@igh-essen.com>
parents: 216
diff changeset
   251
#if EOE_DEBUG_LEVEL > 0
986
a486591ba86b Replaced misleading %i by %u.
Florian Pose <fp@igh-essen.com>
parents: 906
diff changeset
   252
    EC_INFO("EoE %s TX sending fragment %u%s with %u octets (%u)."
a486591ba86b Replaced misleading %i by %u.
Florian Pose <fp@igh-essen.com>
parents: 906
diff changeset
   253
           " %u frames queued.\n", eoe->dev->name, eoe->tx_fragment_number,
770
efa5af306318 Improved EoE debugging.
Florian Pose <fp@igh-essen.com>
parents: 721
diff changeset
   254
           last_fragment ? "" : "+", current_size, complete_offset,
218
80fb87518f3d EoE: State machine with function pointers, documentation.
Florian Pose <fp@igh-essen.com>
parents: 217
diff changeset
   255
           eoe->tx_queued_frames);
217
dcfd406e7786 EoE - TX fragmenting works. TCP traffic possible.
Florian Pose <fp@igh-essen.com>
parents: 216
diff changeset
   256
#endif
dcfd406e7786 EoE - TX fragmenting works. TCP traffic possible.
Florian Pose <fp@igh-essen.com>
parents: 216
diff changeset
   257
dcfd406e7786 EoE - TX fragmenting works. TCP traffic possible.
Florian Pose <fp@igh-essen.com>
parents: 216
diff changeset
   258
#if EOE_DEBUG_LEVEL > 1
770
efa5af306318 Improved EoE debugging.
Florian Pose <fp@igh-essen.com>
parents: 721
diff changeset
   259
    EC_INFO("");
217
dcfd406e7786 EoE - TX fragmenting works. TCP traffic possible.
Florian Pose <fp@igh-essen.com>
parents: 216
diff changeset
   260
    for (i = 0; i < current_size; i++) {
340
5a5f5a14c847 Fixed EoE debugging.
Florian Pose <fp@igh-essen.com>
parents: 339
diff changeset
   261
        printk("%02X ", eoe->tx_frame->skb->data[eoe->tx_offset + i]);
217
dcfd406e7786 EoE - TX fragmenting works. TCP traffic possible.
Florian Pose <fp@igh-essen.com>
parents: 216
diff changeset
   262
        if ((i + 1) % 16 == 0) {
dcfd406e7786 EoE - TX fragmenting works. TCP traffic possible.
Florian Pose <fp@igh-essen.com>
parents: 216
diff changeset
   263
            printk("\n");
770
efa5af306318 Improved EoE debugging.
Florian Pose <fp@igh-essen.com>
parents: 721
diff changeset
   264
            EC_INFO("");
217
dcfd406e7786 EoE - TX fragmenting works. TCP traffic possible.
Florian Pose <fp@igh-essen.com>
parents: 216
diff changeset
   265
        }
dcfd406e7786 EoE - TX fragmenting works. TCP traffic possible.
Florian Pose <fp@igh-essen.com>
parents: 216
diff changeset
   266
    }
dcfd406e7786 EoE - TX fragmenting works. TCP traffic possible.
Florian Pose <fp@igh-essen.com>
parents: 216
diff changeset
   267
    printk("\n");
dcfd406e7786 EoE - TX fragmenting works. TCP traffic possible.
Florian Pose <fp@igh-essen.com>
parents: 216
diff changeset
   268
#endif
dcfd406e7786 EoE - TX fragmenting works. TCP traffic possible.
Florian Pose <fp@igh-essen.com>
parents: 216
diff changeset
   269
1313
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1209
diff changeset
   270
    data = ec_slave_mbox_prepare_send(eoe->slave, &eoe->datagram,
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1209
diff changeset
   271
            0x02, current_size + 4);
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1209
diff changeset
   272
    if (IS_ERR(data))
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1209
diff changeset
   273
        return PTR_ERR(data);
217
dcfd406e7786 EoE - TX fragmenting works. TCP traffic possible.
Florian Pose <fp@igh-essen.com>
parents: 216
diff changeset
   274
dcfd406e7786 EoE - TX fragmenting works. TCP traffic possible.
Florian Pose <fp@igh-essen.com>
parents: 216
diff changeset
   275
    EC_WRITE_U8 (data,     0x00); // eoe fragment req.
dcfd406e7786 EoE - TX fragmenting works. TCP traffic possible.
Florian Pose <fp@igh-essen.com>
parents: 216
diff changeset
   276
    EC_WRITE_U8 (data + 1, last_fragment);
dcfd406e7786 EoE - TX fragmenting works. TCP traffic possible.
Florian Pose <fp@igh-essen.com>
parents: 216
diff changeset
   277
    EC_WRITE_U16(data + 2, ((eoe->tx_fragment_number & 0x3F) |
dcfd406e7786 EoE - TX fragmenting works. TCP traffic possible.
Florian Pose <fp@igh-essen.com>
parents: 216
diff changeset
   278
                            (complete_offset & 0x3F) << 6 |
dcfd406e7786 EoE - TX fragmenting works. TCP traffic possible.
Florian Pose <fp@igh-essen.com>
parents: 216
diff changeset
   279
                            (eoe->tx_frame_number & 0x0F) << 12));
dcfd406e7786 EoE - TX fragmenting works. TCP traffic possible.
Florian Pose <fp@igh-essen.com>
parents: 216
diff changeset
   280
218
80fb87518f3d EoE: State machine with function pointers, documentation.
Florian Pose <fp@igh-essen.com>
parents: 217
diff changeset
   281
    memcpy(data + 4, eoe->tx_frame->skb->data + eoe->tx_offset, current_size);
721
ebc2fd3e09e5 Improved EoE handling: Avoided skipping of datagrams and release lock
Florian Pose <fp@igh-essen.com>
parents: 719
diff changeset
   282
    eoe->queue_datagram = 1;
217
dcfd406e7786 EoE - TX fragmenting works. TCP traffic possible.
Florian Pose <fp@igh-essen.com>
parents: 216
diff changeset
   283
dcfd406e7786 EoE - TX fragmenting works. TCP traffic possible.
Florian Pose <fp@igh-essen.com>
parents: 216
diff changeset
   284
    eoe->tx_offset += current_size;
dcfd406e7786 EoE - TX fragmenting works. TCP traffic possible.
Florian Pose <fp@igh-essen.com>
parents: 216
diff changeset
   285
    eoe->tx_fragment_number++;
dcfd406e7786 EoE - TX fragmenting works. TCP traffic possible.
Florian Pose <fp@igh-essen.com>
parents: 216
diff changeset
   286
    return 0;
dcfd406e7786 EoE - TX fragmenting works. TCP traffic possible.
Florian Pose <fp@igh-essen.com>
parents: 216
diff changeset
   287
}
dcfd406e7786 EoE - TX fragmenting works. TCP traffic possible.
Florian Pose <fp@igh-essen.com>
parents: 216
diff changeset
   288
dcfd406e7786 EoE - TX fragmenting works. TCP traffic possible.
Florian Pose <fp@igh-essen.com>
parents: 216
diff changeset
   289
/*****************************************************************************/
dcfd406e7786 EoE - TX fragmenting works. TCP traffic possible.
Florian Pose <fp@igh-essen.com>
parents: 216
diff changeset
   290
dcfd406e7786 EoE - TX fragmenting works. TCP traffic possible.
Florian Pose <fp@igh-essen.com>
parents: 216
diff changeset
   291
/**
199
04ecf40fc2e9 Doxygen added interface modules and file documentation.
Florian Pose <fp@igh-essen.com>
parents: 197
diff changeset
   292
   Runs the EoE state machine.
197
b9a6e2c22745 GPLv2 License and enhanced Doxygen output.
Florian Pose <fp@igh-essen.com>
parents: 195
diff changeset
   293
*/
b9a6e2c22745 GPLv2 License and enhanced Doxygen output.
Florian Pose <fp@igh-essen.com>
parents: 195
diff changeset
   294
251
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   295
void ec_eoe_run(ec_eoe_t *eoe /**< EoE handler */)
218
80fb87518f3d EoE: State machine with function pointers, documentation.
Florian Pose <fp@igh-essen.com>
parents: 217
diff changeset
   296
{
210
1cc6bcb1e6ae EoE frame receiving; regarding open/stop commands.
Florian Pose <fp@igh-essen.com>
parents: 208
diff changeset
   297
    if (!eoe->opened) return;
145
11a82e4fd31b Mailbox-Interface ausgelagert, erster EOE-Ansatz.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   298
721
ebc2fd3e09e5 Improved EoE handling: Avoided skipping of datagrams and release lock
Florian Pose <fp@igh-essen.com>
parents: 719
diff changeset
   299
    // if the datagram was not sent, or is not yet received, skip this cycle
ebc2fd3e09e5 Improved EoE handling: Avoided skipping of datagrams and release lock
Florian Pose <fp@igh-essen.com>
parents: 719
diff changeset
   300
    if (eoe->queue_datagram || eoe->datagram.state == EC_DATAGRAM_SENT)
ebc2fd3e09e5 Improved EoE handling: Avoided skipping of datagrams and release lock
Florian Pose <fp@igh-essen.com>
parents: 719
diff changeset
   301
        return;
ebc2fd3e09e5 Improved EoE handling: Avoided skipping of datagrams and release lock
Florian Pose <fp@igh-essen.com>
parents: 719
diff changeset
   302
218
80fb87518f3d EoE: State machine with function pointers, documentation.
Florian Pose <fp@igh-essen.com>
parents: 217
diff changeset
   303
    // call state function
80fb87518f3d EoE: State machine with function pointers, documentation.
Florian Pose <fp@igh-essen.com>
parents: 217
diff changeset
   304
    eoe->state(eoe);
336
360e5287c888 EoE rate statistics.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
   305
360e5287c888 EoE rate statistics.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
   306
    // update statistics
344
5d8281f1aa2a Replaced longer cycle timestamps with jiffies.
Florian Pose <fp@igh-essen.com>
parents: 340
diff changeset
   307
    if (jiffies - eoe->rate_jiffies > HZ) {
336
360e5287c888 EoE rate statistics.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
   308
        eoe->rx_rate = eoe->rx_counter * 8;
360e5287c888 EoE rate statistics.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
   309
        eoe->tx_rate = eoe->tx_counter * 8;
360e5287c888 EoE rate statistics.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
   310
        eoe->rx_counter = 0;
360e5287c888 EoE rate statistics.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
   311
        eoe->tx_counter = 0;
344
5d8281f1aa2a Replaced longer cycle timestamps with jiffies.
Florian Pose <fp@igh-essen.com>
parents: 340
diff changeset
   312
        eoe->rate_jiffies = jiffies;
336
360e5287c888 EoE rate statistics.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
   313
    }
721
ebc2fd3e09e5 Improved EoE handling: Avoided skipping of datagrams and release lock
Florian Pose <fp@igh-essen.com>
parents: 719
diff changeset
   314
719
03d5b96632fb Store skipped information in datagrams; name datagrams for statistics
Florian Pose <fp@igh-essen.com>
parents: 712
diff changeset
   315
    ec_datagram_output_stats(&eoe->datagram);
145
11a82e4fd31b Mailbox-Interface ausgelagert, erster EOE-Ansatz.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   316
}
11a82e4fd31b Mailbox-Interface ausgelagert, erster EOE-Ansatz.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   317
11a82e4fd31b Mailbox-Interface ausgelagert, erster EOE-Ansatz.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   318
/*****************************************************************************/
11a82e4fd31b Mailbox-Interface ausgelagert, erster EOE-Ansatz.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   319
197
b9a6e2c22745 GPLv2 License and enhanced Doxygen output.
Florian Pose <fp@igh-essen.com>
parents: 195
diff changeset
   320
/**
721
ebc2fd3e09e5 Improved EoE handling: Avoided skipping of datagrams and release lock
Florian Pose <fp@igh-essen.com>
parents: 719
diff changeset
   321
 * Queues the datagram, if necessary.
ebc2fd3e09e5 Improved EoE handling: Avoided skipping of datagrams and release lock
Florian Pose <fp@igh-essen.com>
parents: 719
diff changeset
   322
 */
ebc2fd3e09e5 Improved EoE handling: Avoided skipping of datagrams and release lock
Florian Pose <fp@igh-essen.com>
parents: 719
diff changeset
   323
ebc2fd3e09e5 Improved EoE handling: Avoided skipping of datagrams and release lock
Florian Pose <fp@igh-essen.com>
parents: 719
diff changeset
   324
void ec_eoe_queue(ec_eoe_t *eoe /**< EoE handler */)
ebc2fd3e09e5 Improved EoE handling: Avoided skipping of datagrams and release lock
Florian Pose <fp@igh-essen.com>
parents: 719
diff changeset
   325
{
ebc2fd3e09e5 Improved EoE handling: Avoided skipping of datagrams and release lock
Florian Pose <fp@igh-essen.com>
parents: 719
diff changeset
   326
   if (eoe->queue_datagram) {
ebc2fd3e09e5 Improved EoE handling: Avoided skipping of datagrams and release lock
Florian Pose <fp@igh-essen.com>
parents: 719
diff changeset
   327
       ec_master_queue_datagram(eoe->slave->master, &eoe->datagram);
ebc2fd3e09e5 Improved EoE handling: Avoided skipping of datagrams and release lock
Florian Pose <fp@igh-essen.com>
parents: 719
diff changeset
   328
       eoe->queue_datagram = 0;
ebc2fd3e09e5 Improved EoE handling: Avoided skipping of datagrams and release lock
Florian Pose <fp@igh-essen.com>
parents: 719
diff changeset
   329
   }
ebc2fd3e09e5 Improved EoE handling: Avoided skipping of datagrams and release lock
Florian Pose <fp@igh-essen.com>
parents: 719
diff changeset
   330
}
ebc2fd3e09e5 Improved EoE handling: Avoided skipping of datagrams and release lock
Florian Pose <fp@igh-essen.com>
parents: 719
diff changeset
   331
ebc2fd3e09e5 Improved EoE handling: Avoided skipping of datagrams and release lock
Florian Pose <fp@igh-essen.com>
parents: 719
diff changeset
   332
/*****************************************************************************/
ebc2fd3e09e5 Improved EoE handling: Avoided skipping of datagrams and release lock
Florian Pose <fp@igh-essen.com>
parents: 719
diff changeset
   333
ebc2fd3e09e5 Improved EoE handling: Avoided skipping of datagrams and release lock
Florian Pose <fp@igh-essen.com>
parents: 719
diff changeset
   334
/**
235
f973808540a6 No master locking, if no EoE devices are "up".
Florian Pose <fp@igh-essen.com>
parents: 219
diff changeset
   335
   Returns the state of the device.
f973808540a6 No master locking, if no EoE devices are "up".
Florian Pose <fp@igh-essen.com>
parents: 219
diff changeset
   336
   \return 1 if the device is "up", 0 if it is "down"
f973808540a6 No master locking, if no EoE devices are "up".
Florian Pose <fp@igh-essen.com>
parents: 219
diff changeset
   337
*/
f973808540a6 No master locking, if no EoE devices are "up".
Florian Pose <fp@igh-essen.com>
parents: 219
diff changeset
   338
661
bc1de1362efb Dynamic creation of EoE handlers.
Florian Pose <fp@igh-essen.com>
parents: 629
diff changeset
   339
int ec_eoe_is_open(const ec_eoe_t *eoe /**< EoE handler */)
bc1de1362efb Dynamic creation of EoE handlers.
Florian Pose <fp@igh-essen.com>
parents: 629
diff changeset
   340
{
bc1de1362efb Dynamic creation of EoE handlers.
Florian Pose <fp@igh-essen.com>
parents: 629
diff changeset
   341
    return eoe->opened;
251
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   342
}
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   343
218
80fb87518f3d EoE: State machine with function pointers, documentation.
Florian Pose <fp@igh-essen.com>
parents: 217
diff changeset
   344
/******************************************************************************
80fb87518f3d EoE: State machine with function pointers, documentation.
Florian Pose <fp@igh-essen.com>
parents: 217
diff changeset
   345
 *  STATE PROCESSING FUNCTIONS
80fb87518f3d EoE: State machine with function pointers, documentation.
Florian Pose <fp@igh-essen.com>
parents: 217
diff changeset
   346
 *****************************************************************************/
80fb87518f3d EoE: State machine with function pointers, documentation.
Florian Pose <fp@igh-essen.com>
parents: 217
diff changeset
   347
80fb87518f3d EoE: State machine with function pointers, documentation.
Florian Pose <fp@igh-essen.com>
parents: 217
diff changeset
   348
/**
80fb87518f3d EoE: State machine with function pointers, documentation.
Florian Pose <fp@igh-essen.com>
parents: 217
diff changeset
   349
   State: RX_START.
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
   350
   Starts a new receiving sequence by queueing a datagram that checks the
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
   351
   slave's mailbox for a new EoE datagram.
218
80fb87518f3d EoE: State machine with function pointers, documentation.
Florian Pose <fp@igh-essen.com>
parents: 217
diff changeset
   352
*/
80fb87518f3d EoE: State machine with function pointers, documentation.
Florian Pose <fp@igh-essen.com>
parents: 217
diff changeset
   353
251
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   354
void ec_eoe_state_rx_start(ec_eoe_t *eoe /**< EoE handler */)
218
80fb87518f3d EoE: State machine with function pointers, documentation.
Florian Pose <fp@igh-essen.com>
parents: 217
diff changeset
   355
{
906
f95e3e33c0cf Removed slave online flag.
Florian Pose <fp@igh-essen.com>
parents: 834
diff changeset
   356
    if (eoe->slave->error_flag || !eoe->slave->master->main_device.link_state)
261
44a3a5833c49 Better state-dependent behaviour for EoE-capable slaves.
Florian Pose <fp@igh-essen.com>
parents: 251
diff changeset
   357
        return;
44a3a5833c49 Better state-dependent behaviour for EoE-capable slaves.
Florian Pose <fp@igh-essen.com>
parents: 251
diff changeset
   358
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
   359
    ec_slave_mbox_prepare_check(eoe->slave, &eoe->datagram);
721
ebc2fd3e09e5 Improved EoE handling: Avoided skipping of datagrams and release lock
Florian Pose <fp@igh-essen.com>
parents: 719
diff changeset
   360
    eoe->queue_datagram = 1;
218
80fb87518f3d EoE: State machine with function pointers, documentation.
Florian Pose <fp@igh-essen.com>
parents: 217
diff changeset
   361
    eoe->state = ec_eoe_state_rx_check;
80fb87518f3d EoE: State machine with function pointers, documentation.
Florian Pose <fp@igh-essen.com>
parents: 217
diff changeset
   362
}
80fb87518f3d EoE: State machine with function pointers, documentation.
Florian Pose <fp@igh-essen.com>
parents: 217
diff changeset
   363
80fb87518f3d EoE: State machine with function pointers, documentation.
Florian Pose <fp@igh-essen.com>
parents: 217
diff changeset
   364
/*****************************************************************************/
80fb87518f3d EoE: State machine with function pointers, documentation.
Florian Pose <fp@igh-essen.com>
parents: 217
diff changeset
   365
80fb87518f3d EoE: State machine with function pointers, documentation.
Florian Pose <fp@igh-essen.com>
parents: 217
diff changeset
   366
/**
80fb87518f3d EoE: State machine with function pointers, documentation.
Florian Pose <fp@igh-essen.com>
parents: 217
diff changeset
   367
   State: RX_CHECK.
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
   368
   Processes the checking datagram sent in RX_START and issues a receive
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
   369
   datagram, if new data is available.
218
80fb87518f3d EoE: State machine with function pointers, documentation.
Florian Pose <fp@igh-essen.com>
parents: 217
diff changeset
   370
*/
80fb87518f3d EoE: State machine with function pointers, documentation.
Florian Pose <fp@igh-essen.com>
parents: 217
diff changeset
   371
251
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   372
void ec_eoe_state_rx_check(ec_eoe_t *eoe /**< EoE handler */)
218
80fb87518f3d EoE: State machine with function pointers, documentation.
Florian Pose <fp@igh-essen.com>
parents: 217
diff changeset
   373
{
325
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 322
diff changeset
   374
    if (eoe->datagram.state != EC_DATAGRAM_RECEIVED) {
218
80fb87518f3d EoE: State machine with function pointers, documentation.
Florian Pose <fp@igh-essen.com>
parents: 217
diff changeset
   375
        eoe->stats.rx_errors++;
80fb87518f3d EoE: State machine with function pointers, documentation.
Florian Pose <fp@igh-essen.com>
parents: 217
diff changeset
   376
        eoe->state = ec_eoe_state_tx_start;
80fb87518f3d EoE: State machine with function pointers, documentation.
Florian Pose <fp@igh-essen.com>
parents: 217
diff changeset
   377
        return;
80fb87518f3d EoE: State machine with function pointers, documentation.
Florian Pose <fp@igh-essen.com>
parents: 217
diff changeset
   378
    }
80fb87518f3d EoE: State machine with function pointers, documentation.
Florian Pose <fp@igh-essen.com>
parents: 217
diff changeset
   379
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
   380
    if (!ec_slave_mbox_check(&eoe->datagram)) {
218
80fb87518f3d EoE: State machine with function pointers, documentation.
Florian Pose <fp@igh-essen.com>
parents: 217
diff changeset
   381
        eoe->state = ec_eoe_state_tx_start;
80fb87518f3d EoE: State machine with function pointers, documentation.
Florian Pose <fp@igh-essen.com>
parents: 217
diff changeset
   382
        return;
80fb87518f3d EoE: State machine with function pointers, documentation.
Florian Pose <fp@igh-essen.com>
parents: 217
diff changeset
   383
    }
80fb87518f3d EoE: State machine with function pointers, documentation.
Florian Pose <fp@igh-essen.com>
parents: 217
diff changeset
   384
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
   385
    ec_slave_mbox_prepare_fetch(eoe->slave, &eoe->datagram);
721
ebc2fd3e09e5 Improved EoE handling: Avoided skipping of datagrams and release lock
Florian Pose <fp@igh-essen.com>
parents: 719
diff changeset
   386
    eoe->queue_datagram = 1;
218
80fb87518f3d EoE: State machine with function pointers, documentation.
Florian Pose <fp@igh-essen.com>
parents: 217
diff changeset
   387
    eoe->state = ec_eoe_state_rx_fetch;
80fb87518f3d EoE: State machine with function pointers, documentation.
Florian Pose <fp@igh-essen.com>
parents: 217
diff changeset
   388
}
80fb87518f3d EoE: State machine with function pointers, documentation.
Florian Pose <fp@igh-essen.com>
parents: 217
diff changeset
   389
80fb87518f3d EoE: State machine with function pointers, documentation.
Florian Pose <fp@igh-essen.com>
parents: 217
diff changeset
   390
/*****************************************************************************/
80fb87518f3d EoE: State machine with function pointers, documentation.
Florian Pose <fp@igh-essen.com>
parents: 217
diff changeset
   391
80fb87518f3d EoE: State machine with function pointers, documentation.
Florian Pose <fp@igh-essen.com>
parents: 217
diff changeset
   392
/**
80fb87518f3d EoE: State machine with function pointers, documentation.
Florian Pose <fp@igh-essen.com>
parents: 217
diff changeset
   393
   State: RX_FETCH.
80fb87518f3d EoE: State machine with function pointers, documentation.
Florian Pose <fp@igh-essen.com>
parents: 217
diff changeset
   394
   Checks if the requested data of RX_CHECK was received and processes the
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
   395
   EoE datagram.
218
80fb87518f3d EoE: State machine with function pointers, documentation.
Florian Pose <fp@igh-essen.com>
parents: 217
diff changeset
   396
*/
80fb87518f3d EoE: State machine with function pointers, documentation.
Florian Pose <fp@igh-essen.com>
parents: 217
diff changeset
   397
251
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   398
void ec_eoe_state_rx_fetch(ec_eoe_t *eoe /**< EoE handler */)
218
80fb87518f3d EoE: State machine with function pointers, documentation.
Florian Pose <fp@igh-essen.com>
parents: 217
diff changeset
   399
{
80fb87518f3d EoE: State machine with function pointers, documentation.
Florian Pose <fp@igh-essen.com>
parents: 217
diff changeset
   400
    size_t rec_size, data_size;
391
7d67195702dd Removed additional loop in coe_down FSM; renamed mbox_type to mbox_prot.
Florian Pose <fp@igh-essen.com>
parents: 390
diff changeset
   401
    uint8_t *data, frame_type, last_fragment, time_appended, mbox_prot;
218
80fb87518f3d EoE: State machine with function pointers, documentation.
Florian Pose <fp@igh-essen.com>
parents: 217
diff changeset
   402
    uint8_t frame_number, fragment_offset, fragment_number;
80fb87518f3d EoE: State machine with function pointers, documentation.
Florian Pose <fp@igh-essen.com>
parents: 217
diff changeset
   403
    off_t offset;
340
5a5f5a14c847 Fixed EoE debugging.
Florian Pose <fp@igh-essen.com>
parents: 339
diff changeset
   404
#if EOE_DEBUG_LEVEL > 1
5a5f5a14c847 Fixed EoE debugging.
Florian Pose <fp@igh-essen.com>
parents: 339
diff changeset
   405
    unsigned int i;
5a5f5a14c847 Fixed EoE debugging.
Florian Pose <fp@igh-essen.com>
parents: 339
diff changeset
   406
#endif
218
80fb87518f3d EoE: State machine with function pointers, documentation.
Florian Pose <fp@igh-essen.com>
parents: 217
diff changeset
   407
325
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 322
diff changeset
   408
    if (eoe->datagram.state != EC_DATAGRAM_RECEIVED) {
218
80fb87518f3d EoE: State machine with function pointers, documentation.
Florian Pose <fp@igh-essen.com>
parents: 217
diff changeset
   409
        eoe->stats.rx_errors++;
80fb87518f3d EoE: State machine with function pointers, documentation.
Florian Pose <fp@igh-essen.com>
parents: 217
diff changeset
   410
        eoe->state = ec_eoe_state_tx_start;
80fb87518f3d EoE: State machine with function pointers, documentation.
Florian Pose <fp@igh-essen.com>
parents: 217
diff changeset
   411
        return;
80fb87518f3d EoE: State machine with function pointers, documentation.
Florian Pose <fp@igh-essen.com>
parents: 217
diff changeset
   412
    }
80fb87518f3d EoE: State machine with function pointers, documentation.
Florian Pose <fp@igh-essen.com>
parents: 217
diff changeset
   413
1313
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1209
diff changeset
   414
    data = ec_slave_mbox_fetch(eoe->slave, &eoe->datagram,
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1209
diff changeset
   415
            &mbox_prot, &rec_size);
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1209
diff changeset
   416
    if (IS_ERR(data)) {
390
685c267d80d8 Fixed mailbox bug, added mailbox error codes.
Florian Pose <fp@igh-essen.com>
parents: 344
diff changeset
   417
        eoe->stats.rx_errors++;
685c267d80d8 Fixed mailbox bug, added mailbox error codes.
Florian Pose <fp@igh-essen.com>
parents: 344
diff changeset
   418
        eoe->state = ec_eoe_state_tx_start;
685c267d80d8 Fixed mailbox bug, added mailbox error codes.
Florian Pose <fp@igh-essen.com>
parents: 344
diff changeset
   419
        return;
685c267d80d8 Fixed mailbox bug, added mailbox error codes.
Florian Pose <fp@igh-essen.com>
parents: 344
diff changeset
   420
    }
685c267d80d8 Fixed mailbox bug, added mailbox error codes.
Florian Pose <fp@igh-essen.com>
parents: 344
diff changeset
   421
689
880b556a6efc Removed checking for NULL slave pointer in EoE handler; added comments.
Florian Pose <fp@igh-essen.com>
parents: 683
diff changeset
   422
    if (mbox_prot != 0x02) { // EoE FIXME mailbox handler necessary
218
80fb87518f3d EoE: State machine with function pointers, documentation.
Florian Pose <fp@igh-essen.com>
parents: 217
diff changeset
   423
        eoe->stats.rx_errors++;
80fb87518f3d EoE: State machine with function pointers, documentation.
Florian Pose <fp@igh-essen.com>
parents: 217
diff changeset
   424
        eoe->state = ec_eoe_state_tx_start;
80fb87518f3d EoE: State machine with function pointers, documentation.
Florian Pose <fp@igh-essen.com>
parents: 217
diff changeset
   425
        return;
80fb87518f3d EoE: State machine with function pointers, documentation.
Florian Pose <fp@igh-essen.com>
parents: 217
diff changeset
   426
    }
80fb87518f3d EoE: State machine with function pointers, documentation.
Florian Pose <fp@igh-essen.com>
parents: 217
diff changeset
   427
80fb87518f3d EoE: State machine with function pointers, documentation.
Florian Pose <fp@igh-essen.com>
parents: 217
diff changeset
   428
    frame_type = EC_READ_U16(data) & 0x000F;
80fb87518f3d EoE: State machine with function pointers, documentation.
Florian Pose <fp@igh-essen.com>
parents: 217
diff changeset
   429
322
fceb7b6e0a06 Improved EoE state machine.
Florian Pose <fp@igh-essen.com>
parents: 319
diff changeset
   430
    if (frame_type != 0x00) {
218
80fb87518f3d EoE: State machine with function pointers, documentation.
Florian Pose <fp@igh-essen.com>
parents: 217
diff changeset
   431
#if EOE_DEBUG_LEVEL > 0
770
efa5af306318 Improved EoE debugging.
Florian Pose <fp@igh-essen.com>
parents: 721
diff changeset
   432
        EC_INFO("EoE %s: Other frame received.\n", eoe->dev->name);
218
80fb87518f3d EoE: State machine with function pointers, documentation.
Florian Pose <fp@igh-essen.com>
parents: 217
diff changeset
   433
#endif
80fb87518f3d EoE: State machine with function pointers, documentation.
Florian Pose <fp@igh-essen.com>
parents: 217
diff changeset
   434
        eoe->stats.rx_dropped++;
80fb87518f3d EoE: State machine with function pointers, documentation.
Florian Pose <fp@igh-essen.com>
parents: 217
diff changeset
   435
        eoe->state = ec_eoe_state_tx_start;
322
fceb7b6e0a06 Improved EoE state machine.
Florian Pose <fp@igh-essen.com>
parents: 319
diff changeset
   436
        return;
fceb7b6e0a06 Improved EoE state machine.
Florian Pose <fp@igh-essen.com>
parents: 319
diff changeset
   437
    }
fceb7b6e0a06 Improved EoE state machine.
Florian Pose <fp@igh-essen.com>
parents: 319
diff changeset
   438
fceb7b6e0a06 Improved EoE state machine.
Florian Pose <fp@igh-essen.com>
parents: 319
diff changeset
   439
    // EoE Fragment Request received
fceb7b6e0a06 Improved EoE state machine.
Florian Pose <fp@igh-essen.com>
parents: 319
diff changeset
   440
fceb7b6e0a06 Improved EoE state machine.
Florian Pose <fp@igh-essen.com>
parents: 319
diff changeset
   441
    last_fragment = (EC_READ_U16(data) >> 8) & 0x0001;
fceb7b6e0a06 Improved EoE state machine.
Florian Pose <fp@igh-essen.com>
parents: 319
diff changeset
   442
    time_appended = (EC_READ_U16(data) >> 9) & 0x0001;
fceb7b6e0a06 Improved EoE state machine.
Florian Pose <fp@igh-essen.com>
parents: 319
diff changeset
   443
    fragment_number = EC_READ_U16(data + 2) & 0x003F;
fceb7b6e0a06 Improved EoE state machine.
Florian Pose <fp@igh-essen.com>
parents: 319
diff changeset
   444
    fragment_offset = (EC_READ_U16(data + 2) >> 6) & 0x003F;
fceb7b6e0a06 Improved EoE state machine.
Florian Pose <fp@igh-essen.com>
parents: 319
diff changeset
   445
    frame_number = (EC_READ_U16(data + 2) >> 12) & 0x000F;
fceb7b6e0a06 Improved EoE state machine.
Florian Pose <fp@igh-essen.com>
parents: 319
diff changeset
   446
fceb7b6e0a06 Improved EoE state machine.
Florian Pose <fp@igh-essen.com>
parents: 319
diff changeset
   447
#if EOE_DEBUG_LEVEL > 0
986
a486591ba86b Replaced misleading %i by %u.
Florian Pose <fp@igh-essen.com>
parents: 906
diff changeset
   448
    EC_INFO("EoE %s RX fragment %u%s, offset %u, frame %u%s,"
a486591ba86b Replaced misleading %i by %u.
Florian Pose <fp@igh-essen.com>
parents: 906
diff changeset
   449
           " %u octets\n", eoe->dev->name, fragment_number,
770
efa5af306318 Improved EoE debugging.
Florian Pose <fp@igh-essen.com>
parents: 721
diff changeset
   450
           last_fragment ? "" : "+", fragment_offset, frame_number, 
322
fceb7b6e0a06 Improved EoE state machine.
Florian Pose <fp@igh-essen.com>
parents: 319
diff changeset
   451
           time_appended ? ", + timestamp" : "",
fceb7b6e0a06 Improved EoE state machine.
Florian Pose <fp@igh-essen.com>
parents: 319
diff changeset
   452
           time_appended ? rec_size - 8 : rec_size - 4);
fceb7b6e0a06 Improved EoE state machine.
Florian Pose <fp@igh-essen.com>
parents: 319
diff changeset
   453
#endif
fceb7b6e0a06 Improved EoE state machine.
Florian Pose <fp@igh-essen.com>
parents: 319
diff changeset
   454
fceb7b6e0a06 Improved EoE state machine.
Florian Pose <fp@igh-essen.com>
parents: 319
diff changeset
   455
#if EOE_DEBUG_LEVEL > 1
770
efa5af306318 Improved EoE debugging.
Florian Pose <fp@igh-essen.com>
parents: 721
diff changeset
   456
    EC_INFO("");
322
fceb7b6e0a06 Improved EoE state machine.
Florian Pose <fp@igh-essen.com>
parents: 319
diff changeset
   457
    for (i = 0; i < rec_size - 4; i++) {
fceb7b6e0a06 Improved EoE state machine.
Florian Pose <fp@igh-essen.com>
parents: 319
diff changeset
   458
        printk("%02X ", data[i + 4]);
fceb7b6e0a06 Improved EoE state machine.
Florian Pose <fp@igh-essen.com>
parents: 319
diff changeset
   459
        if ((i + 1) % 16 == 0) {
fceb7b6e0a06 Improved EoE state machine.
Florian Pose <fp@igh-essen.com>
parents: 319
diff changeset
   460
            printk("\n");
770
efa5af306318 Improved EoE debugging.
Florian Pose <fp@igh-essen.com>
parents: 721
diff changeset
   461
            EC_INFO("");
322
fceb7b6e0a06 Improved EoE state machine.
Florian Pose <fp@igh-essen.com>
parents: 319
diff changeset
   462
        }
fceb7b6e0a06 Improved EoE state machine.
Florian Pose <fp@igh-essen.com>
parents: 319
diff changeset
   463
    }
fceb7b6e0a06 Improved EoE state machine.
Florian Pose <fp@igh-essen.com>
parents: 319
diff changeset
   464
    printk("\n");
fceb7b6e0a06 Improved EoE state machine.
Florian Pose <fp@igh-essen.com>
parents: 319
diff changeset
   465
#endif
fceb7b6e0a06 Improved EoE state machine.
Florian Pose <fp@igh-essen.com>
parents: 319
diff changeset
   466
fceb7b6e0a06 Improved EoE state machine.
Florian Pose <fp@igh-essen.com>
parents: 319
diff changeset
   467
    data_size = time_appended ? rec_size - 8 : rec_size - 4;
fceb7b6e0a06 Improved EoE state machine.
Florian Pose <fp@igh-essen.com>
parents: 319
diff changeset
   468
fceb7b6e0a06 Improved EoE state machine.
Florian Pose <fp@igh-essen.com>
parents: 319
diff changeset
   469
    if (!fragment_number) {
fceb7b6e0a06 Improved EoE state machine.
Florian Pose <fp@igh-essen.com>
parents: 319
diff changeset
   470
        if (eoe->rx_skb) {
fceb7b6e0a06 Improved EoE state machine.
Florian Pose <fp@igh-essen.com>
parents: 319
diff changeset
   471
            EC_WARN("EoE RX freeing old socket buffer...\n");
fceb7b6e0a06 Improved EoE state machine.
Florian Pose <fp@igh-essen.com>
parents: 319
diff changeset
   472
            dev_kfree_skb(eoe->rx_skb);
fceb7b6e0a06 Improved EoE state machine.
Florian Pose <fp@igh-essen.com>
parents: 319
diff changeset
   473
        }
fceb7b6e0a06 Improved EoE state machine.
Florian Pose <fp@igh-essen.com>
parents: 319
diff changeset
   474
fceb7b6e0a06 Improved EoE state machine.
Florian Pose <fp@igh-essen.com>
parents: 319
diff changeset
   475
        // new socket buffer
fceb7b6e0a06 Improved EoE state machine.
Florian Pose <fp@igh-essen.com>
parents: 319
diff changeset
   476
        if (!(eoe->rx_skb = dev_alloc_skb(fragment_offset * 32))) {
fceb7b6e0a06 Improved EoE state machine.
Florian Pose <fp@igh-essen.com>
parents: 319
diff changeset
   477
            if (printk_ratelimit())
fceb7b6e0a06 Improved EoE state machine.
Florian Pose <fp@igh-essen.com>
parents: 319
diff changeset
   478
                EC_WARN("EoE RX low on mem. frame dropped.\n");
fceb7b6e0a06 Improved EoE state machine.
Florian Pose <fp@igh-essen.com>
parents: 319
diff changeset
   479
            eoe->stats.rx_dropped++;
fceb7b6e0a06 Improved EoE state machine.
Florian Pose <fp@igh-essen.com>
parents: 319
diff changeset
   480
            eoe->state = ec_eoe_state_tx_start;
fceb7b6e0a06 Improved EoE state machine.
Florian Pose <fp@igh-essen.com>
parents: 319
diff changeset
   481
            return;
fceb7b6e0a06 Improved EoE state machine.
Florian Pose <fp@igh-essen.com>
parents: 319
diff changeset
   482
        }
fceb7b6e0a06 Improved EoE state machine.
Florian Pose <fp@igh-essen.com>
parents: 319
diff changeset
   483
fceb7b6e0a06 Improved EoE state machine.
Florian Pose <fp@igh-essen.com>
parents: 319
diff changeset
   484
        eoe->rx_skb_offset = 0;
fceb7b6e0a06 Improved EoE state machine.
Florian Pose <fp@igh-essen.com>
parents: 319
diff changeset
   485
        eoe->rx_skb_size = fragment_offset * 32;
fceb7b6e0a06 Improved EoE state machine.
Florian Pose <fp@igh-essen.com>
parents: 319
diff changeset
   486
        eoe->rx_expected_fragment = 0;
fceb7b6e0a06 Improved EoE state machine.
Florian Pose <fp@igh-essen.com>
parents: 319
diff changeset
   487
    }
fceb7b6e0a06 Improved EoE state machine.
Florian Pose <fp@igh-essen.com>
parents: 319
diff changeset
   488
    else {
fceb7b6e0a06 Improved EoE state machine.
Florian Pose <fp@igh-essen.com>
parents: 319
diff changeset
   489
        if (!eoe->rx_skb) {
fceb7b6e0a06 Improved EoE state machine.
Florian Pose <fp@igh-essen.com>
parents: 319
diff changeset
   490
            eoe->stats.rx_dropped++;
fceb7b6e0a06 Improved EoE state machine.
Florian Pose <fp@igh-essen.com>
parents: 319
diff changeset
   491
            eoe->state = ec_eoe_state_tx_start;
fceb7b6e0a06 Improved EoE state machine.
Florian Pose <fp@igh-essen.com>
parents: 319
diff changeset
   492
            return;
fceb7b6e0a06 Improved EoE state machine.
Florian Pose <fp@igh-essen.com>
parents: 319
diff changeset
   493
        }
fceb7b6e0a06 Improved EoE state machine.
Florian Pose <fp@igh-essen.com>
parents: 319
diff changeset
   494
fceb7b6e0a06 Improved EoE state machine.
Florian Pose <fp@igh-essen.com>
parents: 319
diff changeset
   495
        offset = fragment_offset * 32;
fceb7b6e0a06 Improved EoE state machine.
Florian Pose <fp@igh-essen.com>
parents: 319
diff changeset
   496
        if (offset != eoe->rx_skb_offset ||
fceb7b6e0a06 Improved EoE state machine.
Florian Pose <fp@igh-essen.com>
parents: 319
diff changeset
   497
            offset + data_size > eoe->rx_skb_size ||
fceb7b6e0a06 Improved EoE state machine.
Florian Pose <fp@igh-essen.com>
parents: 319
diff changeset
   498
            fragment_number != eoe->rx_expected_fragment) {
fceb7b6e0a06 Improved EoE state machine.
Florian Pose <fp@igh-essen.com>
parents: 319
diff changeset
   499
            dev_kfree_skb(eoe->rx_skb);
fceb7b6e0a06 Improved EoE state machine.
Florian Pose <fp@igh-essen.com>
parents: 319
diff changeset
   500
            eoe->rx_skb = NULL;
fceb7b6e0a06 Improved EoE state machine.
Florian Pose <fp@igh-essen.com>
parents: 319
diff changeset
   501
            eoe->stats.rx_errors++;
fceb7b6e0a06 Improved EoE state machine.
Florian Pose <fp@igh-essen.com>
parents: 319
diff changeset
   502
            eoe->state = ec_eoe_state_tx_start;
fceb7b6e0a06 Improved EoE state machine.
Florian Pose <fp@igh-essen.com>
parents: 319
diff changeset
   503
            return;
fceb7b6e0a06 Improved EoE state machine.
Florian Pose <fp@igh-essen.com>
parents: 319
diff changeset
   504
        }
fceb7b6e0a06 Improved EoE state machine.
Florian Pose <fp@igh-essen.com>
parents: 319
diff changeset
   505
    }
fceb7b6e0a06 Improved EoE state machine.
Florian Pose <fp@igh-essen.com>
parents: 319
diff changeset
   506
fceb7b6e0a06 Improved EoE state machine.
Florian Pose <fp@igh-essen.com>
parents: 319
diff changeset
   507
    // copy fragment into socket buffer
fceb7b6e0a06 Improved EoE state machine.
Florian Pose <fp@igh-essen.com>
parents: 319
diff changeset
   508
    memcpy(skb_put(eoe->rx_skb, data_size), data + 4, data_size);
fceb7b6e0a06 Improved EoE state machine.
Florian Pose <fp@igh-essen.com>
parents: 319
diff changeset
   509
    eoe->rx_skb_offset += data_size;
fceb7b6e0a06 Improved EoE state machine.
Florian Pose <fp@igh-essen.com>
parents: 319
diff changeset
   510
fceb7b6e0a06 Improved EoE state machine.
Florian Pose <fp@igh-essen.com>
parents: 319
diff changeset
   511
    if (last_fragment) {
fceb7b6e0a06 Improved EoE state machine.
Florian Pose <fp@igh-essen.com>
parents: 319
diff changeset
   512
        // update statistics
fceb7b6e0a06 Improved EoE state machine.
Florian Pose <fp@igh-essen.com>
parents: 319
diff changeset
   513
        eoe->stats.rx_packets++;
fceb7b6e0a06 Improved EoE state machine.
Florian Pose <fp@igh-essen.com>
parents: 319
diff changeset
   514
        eoe->stats.rx_bytes += eoe->rx_skb->len;
336
360e5287c888 EoE rate statistics.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
   515
        eoe->rx_counter += eoe->rx_skb->len;
322
fceb7b6e0a06 Improved EoE state machine.
Florian Pose <fp@igh-essen.com>
parents: 319
diff changeset
   516
fceb7b6e0a06 Improved EoE state machine.
Florian Pose <fp@igh-essen.com>
parents: 319
diff changeset
   517
#if EOE_DEBUG_LEVEL > 0
770
efa5af306318 Improved EoE debugging.
Florian Pose <fp@igh-essen.com>
parents: 721
diff changeset
   518
        EC_INFO("EoE %s RX frame completed with %u octets.\n",
efa5af306318 Improved EoE debugging.
Florian Pose <fp@igh-essen.com>
parents: 721
diff changeset
   519
               eoe->dev->name, eoe->rx_skb->len);
322
fceb7b6e0a06 Improved EoE state machine.
Florian Pose <fp@igh-essen.com>
parents: 319
diff changeset
   520
#endif
fceb7b6e0a06 Improved EoE state machine.
Florian Pose <fp@igh-essen.com>
parents: 319
diff changeset
   521
fceb7b6e0a06 Improved EoE state machine.
Florian Pose <fp@igh-essen.com>
parents: 319
diff changeset
   522
        // pass socket buffer to network stack
fceb7b6e0a06 Improved EoE state machine.
Florian Pose <fp@igh-essen.com>
parents: 319
diff changeset
   523
        eoe->rx_skb->dev = eoe->dev;
fceb7b6e0a06 Improved EoE state machine.
Florian Pose <fp@igh-essen.com>
parents: 319
diff changeset
   524
        eoe->rx_skb->protocol = eth_type_trans(eoe->rx_skb, eoe->dev);
fceb7b6e0a06 Improved EoE state machine.
Florian Pose <fp@igh-essen.com>
parents: 319
diff changeset
   525
        eoe->rx_skb->ip_summed = CHECKSUM_UNNECESSARY;
fceb7b6e0a06 Improved EoE state machine.
Florian Pose <fp@igh-essen.com>
parents: 319
diff changeset
   526
        if (netif_rx(eoe->rx_skb)) {
fceb7b6e0a06 Improved EoE state machine.
Florian Pose <fp@igh-essen.com>
parents: 319
diff changeset
   527
            EC_WARN("EoE RX netif_rx failed.\n");
fceb7b6e0a06 Improved EoE state machine.
Florian Pose <fp@igh-essen.com>
parents: 319
diff changeset
   528
        }
fceb7b6e0a06 Improved EoE state machine.
Florian Pose <fp@igh-essen.com>
parents: 319
diff changeset
   529
        eoe->rx_skb = NULL;
fceb7b6e0a06 Improved EoE state machine.
Florian Pose <fp@igh-essen.com>
parents: 319
diff changeset
   530
fceb7b6e0a06 Improved EoE state machine.
Florian Pose <fp@igh-essen.com>
parents: 319
diff changeset
   531
        eoe->state = ec_eoe_state_tx_start;
fceb7b6e0a06 Improved EoE state machine.
Florian Pose <fp@igh-essen.com>
parents: 319
diff changeset
   532
    }
fceb7b6e0a06 Improved EoE state machine.
Florian Pose <fp@igh-essen.com>
parents: 319
diff changeset
   533
    else {
fceb7b6e0a06 Improved EoE state machine.
Florian Pose <fp@igh-essen.com>
parents: 319
diff changeset
   534
        eoe->rx_expected_fragment++;
fceb7b6e0a06 Improved EoE state machine.
Florian Pose <fp@igh-essen.com>
parents: 319
diff changeset
   535
#if EOE_DEBUG_LEVEL > 0
986
a486591ba86b Replaced misleading %i by %u.
Florian Pose <fp@igh-essen.com>
parents: 906
diff changeset
   536
        EC_INFO("EoE %s RX expecting fragment %u\n",
770
efa5af306318 Improved EoE debugging.
Florian Pose <fp@igh-essen.com>
parents: 721
diff changeset
   537
               eoe->dev->name, eoe->rx_expected_fragment);
322
fceb7b6e0a06 Improved EoE state machine.
Florian Pose <fp@igh-essen.com>
parents: 319
diff changeset
   538
#endif
fceb7b6e0a06 Improved EoE state machine.
Florian Pose <fp@igh-essen.com>
parents: 319
diff changeset
   539
        eoe->state = ec_eoe_state_rx_start;
218
80fb87518f3d EoE: State machine with function pointers, documentation.
Florian Pose <fp@igh-essen.com>
parents: 217
diff changeset
   540
    }
80fb87518f3d EoE: State machine with function pointers, documentation.
Florian Pose <fp@igh-essen.com>
parents: 217
diff changeset
   541
}
80fb87518f3d EoE: State machine with function pointers, documentation.
Florian Pose <fp@igh-essen.com>
parents: 217
diff changeset
   542
80fb87518f3d EoE: State machine with function pointers, documentation.
Florian Pose <fp@igh-essen.com>
parents: 217
diff changeset
   543
/*****************************************************************************/
80fb87518f3d EoE: State machine with function pointers, documentation.
Florian Pose <fp@igh-essen.com>
parents: 217
diff changeset
   544
80fb87518f3d EoE: State machine with function pointers, documentation.
Florian Pose <fp@igh-essen.com>
parents: 217
diff changeset
   545
/**
80fb87518f3d EoE: State machine with function pointers, documentation.
Florian Pose <fp@igh-essen.com>
parents: 217
diff changeset
   546
   State: TX START.
80fb87518f3d EoE: State machine with function pointers, documentation.
Florian Pose <fp@igh-essen.com>
parents: 217
diff changeset
   547
   Starts a new transmit sequence. If no data is available, a new receive
80fb87518f3d EoE: State machine with function pointers, documentation.
Florian Pose <fp@igh-essen.com>
parents: 217
diff changeset
   548
   sequence is started instead.
80fb87518f3d EoE: State machine with function pointers, documentation.
Florian Pose <fp@igh-essen.com>
parents: 217
diff changeset
   549
*/
80fb87518f3d EoE: State machine with function pointers, documentation.
Florian Pose <fp@igh-essen.com>
parents: 217
diff changeset
   550
251
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   551
void ec_eoe_state_tx_start(ec_eoe_t *eoe /**< EoE handler */)
218
80fb87518f3d EoE: State machine with function pointers, documentation.
Florian Pose <fp@igh-essen.com>
parents: 217
diff changeset
   552
{
80fb87518f3d EoE: State machine with function pointers, documentation.
Florian Pose <fp@igh-essen.com>
parents: 217
diff changeset
   553
#if EOE_DEBUG_LEVEL > 0
340
5a5f5a14c847 Fixed EoE debugging.
Florian Pose <fp@igh-essen.com>
parents: 339
diff changeset
   554
    unsigned int wakeup = 0;
218
80fb87518f3d EoE: State machine with function pointers, documentation.
Florian Pose <fp@igh-essen.com>
parents: 217
diff changeset
   555
#endif
80fb87518f3d EoE: State machine with function pointers, documentation.
Florian Pose <fp@igh-essen.com>
parents: 217
diff changeset
   556
906
f95e3e33c0cf Removed slave online flag.
Florian Pose <fp@igh-essen.com>
parents: 834
diff changeset
   557
    if (eoe->slave->error_flag || !eoe->slave->master->main_device.link_state)
261
44a3a5833c49 Better state-dependent behaviour for EoE-capable slaves.
Florian Pose <fp@igh-essen.com>
parents: 251
diff changeset
   558
        return;
44a3a5833c49 Better state-dependent behaviour for EoE-capable slaves.
Florian Pose <fp@igh-essen.com>
parents: 251
diff changeset
   559
218
80fb87518f3d EoE: State machine with function pointers, documentation.
Florian Pose <fp@igh-essen.com>
parents: 217
diff changeset
   560
    spin_lock_bh(&eoe->tx_queue_lock);
80fb87518f3d EoE: State machine with function pointers, documentation.
Florian Pose <fp@igh-essen.com>
parents: 217
diff changeset
   561
80fb87518f3d EoE: State machine with function pointers, documentation.
Florian Pose <fp@igh-essen.com>
parents: 217
diff changeset
   562
    if (!eoe->tx_queued_frames || list_empty(&eoe->tx_queue)) {
80fb87518f3d EoE: State machine with function pointers, documentation.
Florian Pose <fp@igh-essen.com>
parents: 217
diff changeset
   563
        spin_unlock_bh(&eoe->tx_queue_lock);
80fb87518f3d EoE: State machine with function pointers, documentation.
Florian Pose <fp@igh-essen.com>
parents: 217
diff changeset
   564
        // no data available.
80fb87518f3d EoE: State machine with function pointers, documentation.
Florian Pose <fp@igh-essen.com>
parents: 217
diff changeset
   565
        // start a new receive immediately.
80fb87518f3d EoE: State machine with function pointers, documentation.
Florian Pose <fp@igh-essen.com>
parents: 217
diff changeset
   566
        ec_eoe_state_rx_start(eoe);
80fb87518f3d EoE: State machine with function pointers, documentation.
Florian Pose <fp@igh-essen.com>
parents: 217
diff changeset
   567
        return;
80fb87518f3d EoE: State machine with function pointers, documentation.
Florian Pose <fp@igh-essen.com>
parents: 217
diff changeset
   568
    }
80fb87518f3d EoE: State machine with function pointers, documentation.
Florian Pose <fp@igh-essen.com>
parents: 217
diff changeset
   569
80fb87518f3d EoE: State machine with function pointers, documentation.
Florian Pose <fp@igh-essen.com>
parents: 217
diff changeset
   570
    // take the first frame out of the queue
80fb87518f3d EoE: State machine with function pointers, documentation.
Florian Pose <fp@igh-essen.com>
parents: 217
diff changeset
   571
    eoe->tx_frame = list_entry(eoe->tx_queue.next, ec_eoe_frame_t, queue);
80fb87518f3d EoE: State machine with function pointers, documentation.
Florian Pose <fp@igh-essen.com>
parents: 217
diff changeset
   572
    list_del(&eoe->tx_frame->queue);
80fb87518f3d EoE: State machine with function pointers, documentation.
Florian Pose <fp@igh-essen.com>
parents: 217
diff changeset
   573
    if (!eoe->tx_queue_active &&
80fb87518f3d EoE: State machine with function pointers, documentation.
Florian Pose <fp@igh-essen.com>
parents: 217
diff changeset
   574
        eoe->tx_queued_frames == EC_EOE_TX_QUEUE_SIZE / 2) {
80fb87518f3d EoE: State machine with function pointers, documentation.
Florian Pose <fp@igh-essen.com>
parents: 217
diff changeset
   575
        netif_wake_queue(eoe->dev);
80fb87518f3d EoE: State machine with function pointers, documentation.
Florian Pose <fp@igh-essen.com>
parents: 217
diff changeset
   576
        eoe->tx_queue_active = 1;
80fb87518f3d EoE: State machine with function pointers, documentation.
Florian Pose <fp@igh-essen.com>
parents: 217
diff changeset
   577
#if EOE_DEBUG_LEVEL > 0
80fb87518f3d EoE: State machine with function pointers, documentation.
Florian Pose <fp@igh-essen.com>
parents: 217
diff changeset
   578
        wakeup = 1;
80fb87518f3d EoE: State machine with function pointers, documentation.
Florian Pose <fp@igh-essen.com>
parents: 217
diff changeset
   579
#endif
80fb87518f3d EoE: State machine with function pointers, documentation.
Florian Pose <fp@igh-essen.com>
parents: 217
diff changeset
   580
    }
80fb87518f3d EoE: State machine with function pointers, documentation.
Florian Pose <fp@igh-essen.com>
parents: 217
diff changeset
   581
80fb87518f3d EoE: State machine with function pointers, documentation.
Florian Pose <fp@igh-essen.com>
parents: 217
diff changeset
   582
    eoe->tx_queued_frames--;
80fb87518f3d EoE: State machine with function pointers, documentation.
Florian Pose <fp@igh-essen.com>
parents: 217
diff changeset
   583
    spin_unlock_bh(&eoe->tx_queue_lock);
80fb87518f3d EoE: State machine with function pointers, documentation.
Florian Pose <fp@igh-essen.com>
parents: 217
diff changeset
   584
80fb87518f3d EoE: State machine with function pointers, documentation.
Florian Pose <fp@igh-essen.com>
parents: 217
diff changeset
   585
    eoe->tx_frame_number++;
80fb87518f3d EoE: State machine with function pointers, documentation.
Florian Pose <fp@igh-essen.com>
parents: 217
diff changeset
   586
    eoe->tx_frame_number %= 16;
80fb87518f3d EoE: State machine with function pointers, documentation.
Florian Pose <fp@igh-essen.com>
parents: 217
diff changeset
   587
    eoe->tx_fragment_number = 0;
80fb87518f3d EoE: State machine with function pointers, documentation.
Florian Pose <fp@igh-essen.com>
parents: 217
diff changeset
   588
    eoe->tx_offset = 0;
80fb87518f3d EoE: State machine with function pointers, documentation.
Florian Pose <fp@igh-essen.com>
parents: 217
diff changeset
   589
80fb87518f3d EoE: State machine with function pointers, documentation.
Florian Pose <fp@igh-essen.com>
parents: 217
diff changeset
   590
    if (ec_eoe_send(eoe)) {
80fb87518f3d EoE: State machine with function pointers, documentation.
Florian Pose <fp@igh-essen.com>
parents: 217
diff changeset
   591
        dev_kfree_skb(eoe->tx_frame->skb);
80fb87518f3d EoE: State machine with function pointers, documentation.
Florian Pose <fp@igh-essen.com>
parents: 217
diff changeset
   592
        kfree(eoe->tx_frame);
80fb87518f3d EoE: State machine with function pointers, documentation.
Florian Pose <fp@igh-essen.com>
parents: 217
diff changeset
   593
        eoe->tx_frame = NULL;
80fb87518f3d EoE: State machine with function pointers, documentation.
Florian Pose <fp@igh-essen.com>
parents: 217
diff changeset
   594
        eoe->stats.tx_errors++;
80fb87518f3d EoE: State machine with function pointers, documentation.
Florian Pose <fp@igh-essen.com>
parents: 217
diff changeset
   595
        eoe->state = ec_eoe_state_rx_start;
80fb87518f3d EoE: State machine with function pointers, documentation.
Florian Pose <fp@igh-essen.com>
parents: 217
diff changeset
   596
        return;
80fb87518f3d EoE: State machine with function pointers, documentation.
Florian Pose <fp@igh-essen.com>
parents: 217
diff changeset
   597
    }
80fb87518f3d EoE: State machine with function pointers, documentation.
Florian Pose <fp@igh-essen.com>
parents: 217
diff changeset
   598
80fb87518f3d EoE: State machine with function pointers, documentation.
Florian Pose <fp@igh-essen.com>
parents: 217
diff changeset
   599
#if EOE_DEBUG_LEVEL > 0
770
efa5af306318 Improved EoE debugging.
Florian Pose <fp@igh-essen.com>
parents: 721
diff changeset
   600
    if (wakeup) EC_INFO("EoE %s waking up TX queue...\n", eoe->dev->name);
218
80fb87518f3d EoE: State machine with function pointers, documentation.
Florian Pose <fp@igh-essen.com>
parents: 217
diff changeset
   601
#endif
80fb87518f3d EoE: State machine with function pointers, documentation.
Florian Pose <fp@igh-essen.com>
parents: 217
diff changeset
   602
80fb87518f3d EoE: State machine with function pointers, documentation.
Florian Pose <fp@igh-essen.com>
parents: 217
diff changeset
   603
    eoe->state = ec_eoe_state_tx_sent;
80fb87518f3d EoE: State machine with function pointers, documentation.
Florian Pose <fp@igh-essen.com>
parents: 217
diff changeset
   604
}
80fb87518f3d EoE: State machine with function pointers, documentation.
Florian Pose <fp@igh-essen.com>
parents: 217
diff changeset
   605
80fb87518f3d EoE: State machine with function pointers, documentation.
Florian Pose <fp@igh-essen.com>
parents: 217
diff changeset
   606
/*****************************************************************************/
80fb87518f3d EoE: State machine with function pointers, documentation.
Florian Pose <fp@igh-essen.com>
parents: 217
diff changeset
   607
80fb87518f3d EoE: State machine with function pointers, documentation.
Florian Pose <fp@igh-essen.com>
parents: 217
diff changeset
   608
/**
80fb87518f3d EoE: State machine with function pointers, documentation.
Florian Pose <fp@igh-essen.com>
parents: 217
diff changeset
   609
   State: TX SENT.
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
   610
   Checks is the previous transmit datagram succeded and sends the next
218
80fb87518f3d EoE: State machine with function pointers, documentation.
Florian Pose <fp@igh-essen.com>
parents: 217
diff changeset
   611
   fragment, if necessary.
80fb87518f3d EoE: State machine with function pointers, documentation.
Florian Pose <fp@igh-essen.com>
parents: 217
diff changeset
   612
*/
80fb87518f3d EoE: State machine with function pointers, documentation.
Florian Pose <fp@igh-essen.com>
parents: 217
diff changeset
   613
251
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   614
void ec_eoe_state_tx_sent(ec_eoe_t *eoe /**< EoE handler */)
218
80fb87518f3d EoE: State machine with function pointers, documentation.
Florian Pose <fp@igh-essen.com>
parents: 217
diff changeset
   615
{
325
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 322
diff changeset
   616
    if (eoe->datagram.state != EC_DATAGRAM_RECEIVED) {
218
80fb87518f3d EoE: State machine with function pointers, documentation.
Florian Pose <fp@igh-essen.com>
parents: 217
diff changeset
   617
        eoe->stats.tx_errors++;
80fb87518f3d EoE: State machine with function pointers, documentation.
Florian Pose <fp@igh-essen.com>
parents: 217
diff changeset
   618
        eoe->state = ec_eoe_state_rx_start;
80fb87518f3d EoE: State machine with function pointers, documentation.
Florian Pose <fp@igh-essen.com>
parents: 217
diff changeset
   619
        return;
80fb87518f3d EoE: State machine with function pointers, documentation.
Florian Pose <fp@igh-essen.com>
parents: 217
diff changeset
   620
    }
80fb87518f3d EoE: State machine with function pointers, documentation.
Florian Pose <fp@igh-essen.com>
parents: 217
diff changeset
   621
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
   622
    if (eoe->datagram.working_counter != 1) {
218
80fb87518f3d EoE: State machine with function pointers, documentation.
Florian Pose <fp@igh-essen.com>
parents: 217
diff changeset
   623
        eoe->stats.tx_errors++;
80fb87518f3d EoE: State machine with function pointers, documentation.
Florian Pose <fp@igh-essen.com>
parents: 217
diff changeset
   624
        eoe->state = ec_eoe_state_rx_start;
80fb87518f3d EoE: State machine with function pointers, documentation.
Florian Pose <fp@igh-essen.com>
parents: 217
diff changeset
   625
        return;
80fb87518f3d EoE: State machine with function pointers, documentation.
Florian Pose <fp@igh-essen.com>
parents: 217
diff changeset
   626
    }
80fb87518f3d EoE: State machine with function pointers, documentation.
Florian Pose <fp@igh-essen.com>
parents: 217
diff changeset
   627
80fb87518f3d EoE: State machine with function pointers, documentation.
Florian Pose <fp@igh-essen.com>
parents: 217
diff changeset
   628
    // frame completely sent
80fb87518f3d EoE: State machine with function pointers, documentation.
Florian Pose <fp@igh-essen.com>
parents: 217
diff changeset
   629
    if (eoe->tx_offset >= eoe->tx_frame->skb->len) {
80fb87518f3d EoE: State machine with function pointers, documentation.
Florian Pose <fp@igh-essen.com>
parents: 217
diff changeset
   630
        eoe->stats.tx_packets++;
80fb87518f3d EoE: State machine with function pointers, documentation.
Florian Pose <fp@igh-essen.com>
parents: 217
diff changeset
   631
        eoe->stats.tx_bytes += eoe->tx_frame->skb->len;
336
360e5287c888 EoE rate statistics.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
   632
        eoe->tx_counter += eoe->tx_frame->skb->len;
218
80fb87518f3d EoE: State machine with function pointers, documentation.
Florian Pose <fp@igh-essen.com>
parents: 217
diff changeset
   633
        dev_kfree_skb(eoe->tx_frame->skb);
80fb87518f3d EoE: State machine with function pointers, documentation.
Florian Pose <fp@igh-essen.com>
parents: 217
diff changeset
   634
        kfree(eoe->tx_frame);
80fb87518f3d EoE: State machine with function pointers, documentation.
Florian Pose <fp@igh-essen.com>
parents: 217
diff changeset
   635
        eoe->tx_frame = NULL;
80fb87518f3d EoE: State machine with function pointers, documentation.
Florian Pose <fp@igh-essen.com>
parents: 217
diff changeset
   636
        eoe->state = ec_eoe_state_rx_start;
80fb87518f3d EoE: State machine with function pointers, documentation.
Florian Pose <fp@igh-essen.com>
parents: 217
diff changeset
   637
    }
80fb87518f3d EoE: State machine with function pointers, documentation.
Florian Pose <fp@igh-essen.com>
parents: 217
diff changeset
   638
    else { // send next fragment
80fb87518f3d EoE: State machine with function pointers, documentation.
Florian Pose <fp@igh-essen.com>
parents: 217
diff changeset
   639
        if (ec_eoe_send(eoe)) {
80fb87518f3d EoE: State machine with function pointers, documentation.
Florian Pose <fp@igh-essen.com>
parents: 217
diff changeset
   640
            dev_kfree_skb(eoe->tx_frame->skb);
80fb87518f3d EoE: State machine with function pointers, documentation.
Florian Pose <fp@igh-essen.com>
parents: 217
diff changeset
   641
            kfree(eoe->tx_frame);
80fb87518f3d EoE: State machine with function pointers, documentation.
Florian Pose <fp@igh-essen.com>
parents: 217
diff changeset
   642
            eoe->tx_frame = NULL;
80fb87518f3d EoE: State machine with function pointers, documentation.
Florian Pose <fp@igh-essen.com>
parents: 217
diff changeset
   643
            eoe->stats.tx_errors++;
80fb87518f3d EoE: State machine with function pointers, documentation.
Florian Pose <fp@igh-essen.com>
parents: 217
diff changeset
   644
            eoe->state = ec_eoe_state_rx_start;
80fb87518f3d EoE: State machine with function pointers, documentation.
Florian Pose <fp@igh-essen.com>
parents: 217
diff changeset
   645
        }
80fb87518f3d EoE: State machine with function pointers, documentation.
Florian Pose <fp@igh-essen.com>
parents: 217
diff changeset
   646
    }
80fb87518f3d EoE: State machine with function pointers, documentation.
Florian Pose <fp@igh-essen.com>
parents: 217
diff changeset
   647
}
80fb87518f3d EoE: State machine with function pointers, documentation.
Florian Pose <fp@igh-essen.com>
parents: 217
diff changeset
   648
80fb87518f3d EoE: State machine with function pointers, documentation.
Florian Pose <fp@igh-essen.com>
parents: 217
diff changeset
   649
/******************************************************************************
80fb87518f3d EoE: State machine with function pointers, documentation.
Florian Pose <fp@igh-essen.com>
parents: 217
diff changeset
   650
 *  NET_DEVICE functions
80fb87518f3d EoE: State machine with function pointers, documentation.
Florian Pose <fp@igh-essen.com>
parents: 217
diff changeset
   651
 *****************************************************************************/
203
c1f305e339c6 EoE net_device implementation.
Florian Pose <fp@igh-essen.com>
parents: 199
diff changeset
   652
c1f305e339c6 EoE net_device implementation.
Florian Pose <fp@igh-essen.com>
parents: 199
diff changeset
   653
/**
c1f305e339c6 EoE net_device implementation.
Florian Pose <fp@igh-essen.com>
parents: 199
diff changeset
   654
   Opens the virtual network device.
c1f305e339c6 EoE net_device implementation.
Florian Pose <fp@igh-essen.com>
parents: 199
diff changeset
   655
*/
c1f305e339c6 EoE net_device implementation.
Florian Pose <fp@igh-essen.com>
parents: 199
diff changeset
   656
c1f305e339c6 EoE net_device implementation.
Florian Pose <fp@igh-essen.com>
parents: 199
diff changeset
   657
int ec_eoedev_open(struct net_device *dev /**< EoE net_device */)
c1f305e339c6 EoE net_device implementation.
Florian Pose <fp@igh-essen.com>
parents: 199
diff changeset
   658
{
213
8d723b9833a9 removed unnecessary private structure in eoe net_device.
Florian Pose <fp@igh-essen.com>
parents: 212
diff changeset
   659
    ec_eoe_t *eoe = *((ec_eoe_t **) netdev_priv(dev));
214
8beb86af5ed0 EoE frame queuing, receiving of fragmented frames; no TCP possible yet.
Florian Pose <fp@igh-essen.com>
parents: 213
diff changeset
   660
    ec_eoe_flush(eoe);
212
82980deb8b00 moved stats into eoe struct; persistent rx-skb; tx queue.
Florian Pose <fp@igh-essen.com>
parents: 210
diff changeset
   661
    eoe->opened = 1;
203
c1f305e339c6 EoE net_device implementation.
Florian Pose <fp@igh-essen.com>
parents: 199
diff changeset
   662
    netif_start_queue(dev);
214
8beb86af5ed0 EoE frame queuing, receiving of fragmented frames; no TCP possible yet.
Florian Pose <fp@igh-essen.com>
parents: 213
diff changeset
   663
    eoe->tx_queue_active = 1;
251
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   664
    EC_INFO("%s opened.\n", dev->name);
689
880b556a6efc Removed checking for NULL slave pointer in EoE handler; added comments.
Florian Pose <fp@igh-essen.com>
parents: 683
diff changeset
   665
    ec_slave_request_state(eoe->slave, EC_SLAVE_STATE_OP);
203
c1f305e339c6 EoE net_device implementation.
Florian Pose <fp@igh-essen.com>
parents: 199
diff changeset
   666
    return 0;
c1f305e339c6 EoE net_device implementation.
Florian Pose <fp@igh-essen.com>
parents: 199
diff changeset
   667
}
c1f305e339c6 EoE net_device implementation.
Florian Pose <fp@igh-essen.com>
parents: 199
diff changeset
   668
c1f305e339c6 EoE net_device implementation.
Florian Pose <fp@igh-essen.com>
parents: 199
diff changeset
   669
/*****************************************************************************/
c1f305e339c6 EoE net_device implementation.
Florian Pose <fp@igh-essen.com>
parents: 199
diff changeset
   670
c1f305e339c6 EoE net_device implementation.
Florian Pose <fp@igh-essen.com>
parents: 199
diff changeset
   671
/**
c1f305e339c6 EoE net_device implementation.
Florian Pose <fp@igh-essen.com>
parents: 199
diff changeset
   672
   Stops the virtual network device.
c1f305e339c6 EoE net_device implementation.
Florian Pose <fp@igh-essen.com>
parents: 199
diff changeset
   673
*/
c1f305e339c6 EoE net_device implementation.
Florian Pose <fp@igh-essen.com>
parents: 199
diff changeset
   674
c1f305e339c6 EoE net_device implementation.
Florian Pose <fp@igh-essen.com>
parents: 199
diff changeset
   675
int ec_eoedev_stop(struct net_device *dev /**< EoE net_device */)
c1f305e339c6 EoE net_device implementation.
Florian Pose <fp@igh-essen.com>
parents: 199
diff changeset
   676
{
213
8d723b9833a9 removed unnecessary private structure in eoe net_device.
Florian Pose <fp@igh-essen.com>
parents: 212
diff changeset
   677
    ec_eoe_t *eoe = *((ec_eoe_t **) netdev_priv(dev));
203
c1f305e339c6 EoE net_device implementation.
Florian Pose <fp@igh-essen.com>
parents: 199
diff changeset
   678
    netif_stop_queue(dev);
214
8beb86af5ed0 EoE frame queuing, receiving of fragmented frames; no TCP possible yet.
Florian Pose <fp@igh-essen.com>
parents: 213
diff changeset
   679
    eoe->tx_queue_active = 0;
212
82980deb8b00 moved stats into eoe struct; persistent rx-skb; tx queue.
Florian Pose <fp@igh-essen.com>
parents: 210
diff changeset
   680
    eoe->opened = 0;
214
8beb86af5ed0 EoE frame queuing, receiving of fragmented frames; no TCP possible yet.
Florian Pose <fp@igh-essen.com>
parents: 213
diff changeset
   681
    ec_eoe_flush(eoe);
251
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   682
    EC_INFO("%s stopped.\n", dev->name);
689
880b556a6efc Removed checking for NULL slave pointer in EoE handler; added comments.
Florian Pose <fp@igh-essen.com>
parents: 683
diff changeset
   683
    ec_slave_request_state(eoe->slave, EC_SLAVE_STATE_PREOP);
203
c1f305e339c6 EoE net_device implementation.
Florian Pose <fp@igh-essen.com>
parents: 199
diff changeset
   684
    return 0;
c1f305e339c6 EoE net_device implementation.
Florian Pose <fp@igh-essen.com>
parents: 199
diff changeset
   685
}
c1f305e339c6 EoE net_device implementation.
Florian Pose <fp@igh-essen.com>
parents: 199
diff changeset
   686
c1f305e339c6 EoE net_device implementation.
Florian Pose <fp@igh-essen.com>
parents: 199
diff changeset
   687
/*****************************************************************************/
c1f305e339c6 EoE net_device implementation.
Florian Pose <fp@igh-essen.com>
parents: 199
diff changeset
   688
c1f305e339c6 EoE net_device implementation.
Florian Pose <fp@igh-essen.com>
parents: 199
diff changeset
   689
/**
c1f305e339c6 EoE net_device implementation.
Florian Pose <fp@igh-essen.com>
parents: 199
diff changeset
   690
   Transmits data via the virtual network device.
c1f305e339c6 EoE net_device implementation.
Florian Pose <fp@igh-essen.com>
parents: 199
diff changeset
   691
*/
c1f305e339c6 EoE net_device implementation.
Florian Pose <fp@igh-essen.com>
parents: 199
diff changeset
   692
c1f305e339c6 EoE net_device implementation.
Florian Pose <fp@igh-essen.com>
parents: 199
diff changeset
   693
int ec_eoedev_tx(struct sk_buff *skb, /**< transmit socket buffer */
c1f305e339c6 EoE net_device implementation.
Florian Pose <fp@igh-essen.com>
parents: 199
diff changeset
   694
                 struct net_device *dev /**< EoE net_device */
212
82980deb8b00 moved stats into eoe struct; persistent rx-skb; tx queue.
Florian Pose <fp@igh-essen.com>
parents: 210
diff changeset
   695
                )
82980deb8b00 moved stats into eoe struct; persistent rx-skb; tx queue.
Florian Pose <fp@igh-essen.com>
parents: 210
diff changeset
   696
{
213
8d723b9833a9 removed unnecessary private structure in eoe net_device.
Florian Pose <fp@igh-essen.com>
parents: 212
diff changeset
   697
    ec_eoe_t *eoe = *((ec_eoe_t **) netdev_priv(dev));
214
8beb86af5ed0 EoE frame queuing, receiving of fragmented frames; no TCP possible yet.
Florian Pose <fp@igh-essen.com>
parents: 213
diff changeset
   698
    ec_eoe_frame_t *frame;
8beb86af5ed0 EoE frame queuing, receiving of fragmented frames; no TCP possible yet.
Florian Pose <fp@igh-essen.com>
parents: 213
diff changeset
   699
217
dcfd406e7786 EoE - TX fragmenting works. TCP traffic possible.
Florian Pose <fp@igh-essen.com>
parents: 216
diff changeset
   700
#if 0
834
0791aac03180 Separated SII data from slave.
Florian Pose <fp@igh-essen.com>
parents: 770
diff changeset
   701
    if (skb->len > eoe->slave->sii.tx_mailbox_size - 10) {
986
a486591ba86b Replaced misleading %i by %u.
Florian Pose <fp@igh-essen.com>
parents: 906
diff changeset
   702
        EC_WARN("EoE TX frame (%u octets) exceeds MTU. dropping.\n", skb->len);
214
8beb86af5ed0 EoE frame queuing, receiving of fragmented frames; no TCP possible yet.
Florian Pose <fp@igh-essen.com>
parents: 213
diff changeset
   703
        dev_kfree_skb(skb);
8beb86af5ed0 EoE frame queuing, receiving of fragmented frames; no TCP possible yet.
Florian Pose <fp@igh-essen.com>
parents: 213
diff changeset
   704
        eoe->stats.tx_dropped++;
8beb86af5ed0 EoE frame queuing, receiving of fragmented frames; no TCP possible yet.
Florian Pose <fp@igh-essen.com>
parents: 213
diff changeset
   705
        return 0;
8beb86af5ed0 EoE frame queuing, receiving of fragmented frames; no TCP possible yet.
Florian Pose <fp@igh-essen.com>
parents: 213
diff changeset
   706
    }
217
dcfd406e7786 EoE - TX fragmenting works. TCP traffic possible.
Florian Pose <fp@igh-essen.com>
parents: 216
diff changeset
   707
#endif
214
8beb86af5ed0 EoE frame queuing, receiving of fragmented frames; no TCP possible yet.
Florian Pose <fp@igh-essen.com>
parents: 213
diff changeset
   708
8beb86af5ed0 EoE frame queuing, receiving of fragmented frames; no TCP possible yet.
Florian Pose <fp@igh-essen.com>
parents: 213
diff changeset
   709
    if (!(frame =
8beb86af5ed0 EoE frame queuing, receiving of fragmented frames; no TCP possible yet.
Florian Pose <fp@igh-essen.com>
parents: 213
diff changeset
   710
          (ec_eoe_frame_t *) kmalloc(sizeof(ec_eoe_frame_t), GFP_ATOMIC))) {
8beb86af5ed0 EoE frame queuing, receiving of fragmented frames; no TCP possible yet.
Florian Pose <fp@igh-essen.com>
parents: 213
diff changeset
   711
        if (printk_ratelimit())
8beb86af5ed0 EoE frame queuing, receiving of fragmented frames; no TCP possible yet.
Florian Pose <fp@igh-essen.com>
parents: 213
diff changeset
   712
            EC_WARN("EoE TX: low on mem. frame dropped.\n");
8beb86af5ed0 EoE frame queuing, receiving of fragmented frames; no TCP possible yet.
Florian Pose <fp@igh-essen.com>
parents: 213
diff changeset
   713
        return 1;
8beb86af5ed0 EoE frame queuing, receiving of fragmented frames; no TCP possible yet.
Florian Pose <fp@igh-essen.com>
parents: 213
diff changeset
   714
    }
8beb86af5ed0 EoE frame queuing, receiving of fragmented frames; no TCP possible yet.
Florian Pose <fp@igh-essen.com>
parents: 213
diff changeset
   715
8beb86af5ed0 EoE frame queuing, receiving of fragmented frames; no TCP possible yet.
Florian Pose <fp@igh-essen.com>
parents: 213
diff changeset
   716
    frame->skb = skb;
212
82980deb8b00 moved stats into eoe struct; persistent rx-skb; tx queue.
Florian Pose <fp@igh-essen.com>
parents: 210
diff changeset
   717
82980deb8b00 moved stats into eoe struct; persistent rx-skb; tx queue.
Florian Pose <fp@igh-essen.com>
parents: 210
diff changeset
   718
    spin_lock_bh(&eoe->tx_queue_lock);
214
8beb86af5ed0 EoE frame queuing, receiving of fragmented frames; no TCP possible yet.
Florian Pose <fp@igh-essen.com>
parents: 213
diff changeset
   719
    list_add_tail(&frame->queue, &eoe->tx_queue);
218
80fb87518f3d EoE: State machine with function pointers, documentation.
Florian Pose <fp@igh-essen.com>
parents: 217
diff changeset
   720
    eoe->tx_queued_frames++;
80fb87518f3d EoE: State machine with function pointers, documentation.
Florian Pose <fp@igh-essen.com>
parents: 217
diff changeset
   721
    if (eoe->tx_queued_frames == EC_EOE_TX_QUEUE_SIZE) {
212
82980deb8b00 moved stats into eoe struct; persistent rx-skb; tx queue.
Florian Pose <fp@igh-essen.com>
parents: 210
diff changeset
   722
        netif_stop_queue(dev);
214
8beb86af5ed0 EoE frame queuing, receiving of fragmented frames; no TCP possible yet.
Florian Pose <fp@igh-essen.com>
parents: 213
diff changeset
   723
        eoe->tx_queue_active = 0;
8beb86af5ed0 EoE frame queuing, receiving of fragmented frames; no TCP possible yet.
Florian Pose <fp@igh-essen.com>
parents: 213
diff changeset
   724
    }
212
82980deb8b00 moved stats into eoe struct; persistent rx-skb; tx queue.
Florian Pose <fp@igh-essen.com>
parents: 210
diff changeset
   725
    spin_unlock_bh(&eoe->tx_queue_lock);
82980deb8b00 moved stats into eoe struct; persistent rx-skb; tx queue.
Florian Pose <fp@igh-essen.com>
parents: 210
diff changeset
   726
215
b021aa6eee38 EoE: TCP traffic possible; TX fragmenting to do.
Florian Pose <fp@igh-essen.com>
parents: 214
diff changeset
   727
#if EOE_DEBUG_LEVEL > 0
986
a486591ba86b Replaced misleading %i by %u.
Florian Pose <fp@igh-essen.com>
parents: 906
diff changeset
   728
    EC_INFO("EoE %s TX queued frame with %u octets (%u frames queued).\n",
770
efa5af306318 Improved EoE debugging.
Florian Pose <fp@igh-essen.com>
parents: 721
diff changeset
   729
           eoe->dev->name, skb->len, eoe->tx_queued_frames);
214
8beb86af5ed0 EoE frame queuing, receiving of fragmented frames; no TCP possible yet.
Florian Pose <fp@igh-essen.com>
parents: 213
diff changeset
   730
    if (!eoe->tx_queue_active)
8beb86af5ed0 EoE frame queuing, receiving of fragmented frames; no TCP possible yet.
Florian Pose <fp@igh-essen.com>
parents: 213
diff changeset
   731
        EC_WARN("EoE TX queue is now full.\n");
215
b021aa6eee38 EoE: TCP traffic possible; TX fragmenting to do.
Florian Pose <fp@igh-essen.com>
parents: 214
diff changeset
   732
#endif
214
8beb86af5ed0 EoE frame queuing, receiving of fragmented frames; no TCP possible yet.
Florian Pose <fp@igh-essen.com>
parents: 213
diff changeset
   733
203
c1f305e339c6 EoE net_device implementation.
Florian Pose <fp@igh-essen.com>
parents: 199
diff changeset
   734
    return 0;
c1f305e339c6 EoE net_device implementation.
Florian Pose <fp@igh-essen.com>
parents: 199
diff changeset
   735
}
c1f305e339c6 EoE net_device implementation.
Florian Pose <fp@igh-essen.com>
parents: 199
diff changeset
   736
c1f305e339c6 EoE net_device implementation.
Florian Pose <fp@igh-essen.com>
parents: 199
diff changeset
   737
/*****************************************************************************/
c1f305e339c6 EoE net_device implementation.
Florian Pose <fp@igh-essen.com>
parents: 199
diff changeset
   738
c1f305e339c6 EoE net_device implementation.
Florian Pose <fp@igh-essen.com>
parents: 199
diff changeset
   739
/**
c1f305e339c6 EoE net_device implementation.
Florian Pose <fp@igh-essen.com>
parents: 199
diff changeset
   740
   Gets statistics about the virtual network device.
c1f305e339c6 EoE net_device implementation.
Florian Pose <fp@igh-essen.com>
parents: 199
diff changeset
   741
*/
c1f305e339c6 EoE net_device implementation.
Florian Pose <fp@igh-essen.com>
parents: 199
diff changeset
   742
c1f305e339c6 EoE net_device implementation.
Florian Pose <fp@igh-essen.com>
parents: 199
diff changeset
   743
struct net_device_stats *ec_eoedev_stats(struct net_device *dev
c1f305e339c6 EoE net_device implementation.
Florian Pose <fp@igh-essen.com>
parents: 199
diff changeset
   744
                                         /**< EoE net_device */)
c1f305e339c6 EoE net_device implementation.
Florian Pose <fp@igh-essen.com>
parents: 199
diff changeset
   745
{
213
8d723b9833a9 removed unnecessary private structure in eoe net_device.
Florian Pose <fp@igh-essen.com>
parents: 212
diff changeset
   746
    ec_eoe_t *eoe = *((ec_eoe_t **) netdev_priv(dev));
212
82980deb8b00 moved stats into eoe struct; persistent rx-skb; tx queue.
Florian Pose <fp@igh-essen.com>
parents: 210
diff changeset
   747
    return &eoe->stats;
82980deb8b00 moved stats into eoe struct; persistent rx-skb; tx queue.
Florian Pose <fp@igh-essen.com>
parents: 210
diff changeset
   748
}
82980deb8b00 moved stats into eoe struct; persistent rx-skb; tx queue.
Florian Pose <fp@igh-essen.com>
parents: 210
diff changeset
   749
82980deb8b00 moved stats into eoe struct; persistent rx-skb; tx queue.
Florian Pose <fp@igh-essen.com>
parents: 210
diff changeset
   750
/*****************************************************************************/