master/ethernet.c
author Florian Pose <fp@igh-essen.com>
Wed, 25 Jul 2007 12:53:01 +0000
changeset 671 2223549df36c
parent 661 bc1de1362efb
child 683 43700671b37a
permissions -rw-r--r--
Serveral changes on e1000 driver (not tested!).
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
 *
197
b9a6e2c22745 GPLv2 License and enhanced Doxygen output.
Florian Pose <fp@igh-essen.com>
parents: 195
diff changeset
     5
 *  Copyright (C) 2006  Florian Pose, Ingenieurgemeinschaft IgH
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
 *
b9a6e2c22745 GPLv2 License and enhanced Doxygen output.
Florian Pose <fp@igh-essen.com>
parents: 195
diff changeset
     9
 *  The IgH EtherCAT Master is free software; you can redistribute it
b9a6e2c22745 GPLv2 License and enhanced Doxygen output.
Florian Pose <fp@igh-essen.com>
parents: 195
diff changeset
    10
 *  and/or modify it under the terms of the GNU General Public License
246
0bf7c769de06 Changed license headers and added EtherCAT license notice.
Florian Pose <fp@igh-essen.com>
parents: 235
diff changeset
    11
 *  as published by the Free Software Foundation; either version 2 of the
0bf7c769de06 Changed license headers and added EtherCAT license notice.
Florian Pose <fp@igh-essen.com>
parents: 235
diff changeset
    12
 *  License, or (at your option) any later version.
197
b9a6e2c22745 GPLv2 License and enhanced Doxygen output.
Florian Pose <fp@igh-essen.com>
parents: 195
diff changeset
    13
 *
b9a6e2c22745 GPLv2 License and enhanced Doxygen output.
Florian Pose <fp@igh-essen.com>
parents: 195
diff changeset
    14
 *  The IgH EtherCAT Master is distributed in the hope that it will be
b9a6e2c22745 GPLv2 License and enhanced Doxygen output.
Florian Pose <fp@igh-essen.com>
parents: 195
diff changeset
    15
 *  useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
b9a6e2c22745 GPLv2 License and enhanced Doxygen output.
Florian Pose <fp@igh-essen.com>
parents: 195
diff changeset
    16
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
b9a6e2c22745 GPLv2 License and enhanced Doxygen output.
Florian Pose <fp@igh-essen.com>
parents: 195
diff changeset
    17
 *  GNU General Public License for more details.
b9a6e2c22745 GPLv2 License and enhanced Doxygen output.
Florian Pose <fp@igh-essen.com>
parents: 195
diff changeset
    18
 *
b9a6e2c22745 GPLv2 License and enhanced Doxygen output.
Florian Pose <fp@igh-essen.com>
parents: 195
diff changeset
    19
 *  You should have received a copy of the GNU General Public License
b9a6e2c22745 GPLv2 License and enhanced Doxygen output.
Florian Pose <fp@igh-essen.com>
parents: 195
diff changeset
    20
 *  along with the IgH EtherCAT Master; if not, write to the Free Software
b9a6e2c22745 GPLv2 License and enhanced Doxygen output.
Florian Pose <fp@igh-essen.com>
parents: 195
diff changeset
    21
 *  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
    22
 *
246
0bf7c769de06 Changed license headers and added EtherCAT license notice.
Florian Pose <fp@igh-essen.com>
parents: 235
diff changeset
    23
 *  The right to use EtherCAT Technology is granted and comes free of
0bf7c769de06 Changed license headers and added EtherCAT license notice.
Florian Pose <fp@igh-essen.com>
parents: 235
diff changeset
    24
 *  charge under condition of compatibility of product made by
0bf7c769de06 Changed license headers and added EtherCAT license notice.
Florian Pose <fp@igh-essen.com>
parents: 235
diff changeset
    25
 *  Licensee. People intending to distribute/sell products based on the
0bf7c769de06 Changed license headers and added EtherCAT license notice.
Florian Pose <fp@igh-essen.com>
parents: 235
diff changeset
    26
 *  code, have to sign an agreement to guarantee that products using
0bf7c769de06 Changed license headers and added EtherCAT license notice.
Florian Pose <fp@igh-essen.com>
parents: 235
diff changeset
    27
 *  software based on IgH EtherCAT master stay compatible with the actual
0bf7c769de06 Changed license headers and added EtherCAT license notice.
Florian Pose <fp@igh-essen.com>
parents: 235
diff changeset
    28
 *  EtherCAT specification (which are released themselves as an open
0bf7c769de06 Changed license headers and added EtherCAT license notice.
Florian Pose <fp@igh-essen.com>
parents: 235
diff changeset
    29
 *  standard) as the (only) precondition to have the right to use EtherCAT
0bf7c769de06 Changed license headers and added EtherCAT license notice.
Florian Pose <fp@igh-essen.com>
parents: 235
diff changeset
    30
 *  Technology, IP and trade marks.
0bf7c769de06 Changed license headers and added EtherCAT license notice.
Florian Pose <fp@igh-essen.com>
parents: 235
diff changeset
    31
 *
145
11a82e4fd31b Mailbox-Interface ausgelagert, erster EOE-Ansatz.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    32
 *****************************************************************************/
11a82e4fd31b Mailbox-Interface ausgelagert, erster EOE-Ansatz.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    33
199
04ecf40fc2e9 Doxygen added interface modules and file documentation.
Florian Pose <fp@igh-essen.com>
parents: 197
diff changeset
    34
/**
04ecf40fc2e9 Doxygen added interface modules and file documentation.
Florian Pose <fp@igh-essen.com>
parents: 197
diff changeset
    35
   \file
04ecf40fc2e9 Doxygen added interface modules and file documentation.
Florian Pose <fp@igh-essen.com>
parents: 197
diff changeset
    36
   Ethernet-over-EtherCAT (EoE).
04ecf40fc2e9 Doxygen added interface modules and file documentation.
Florian Pose <fp@igh-essen.com>
parents: 197
diff changeset
    37
*/
04ecf40fc2e9 Doxygen added interface modules and file documentation.
Florian Pose <fp@igh-essen.com>
parents: 197
diff changeset
    38
04ecf40fc2e9 Doxygen added interface modules and file documentation.
Florian Pose <fp@igh-essen.com>
parents: 197
diff changeset
    39
/*****************************************************************************/
04ecf40fc2e9 Doxygen added interface modules and file documentation.
Florian Pose <fp@igh-essen.com>
parents: 197
diff changeset
    40
294
feea8d850c65 Applied include patch by M. Schwerin.
Florian Pose <fp@igh-essen.com>
parents: 293
diff changeset
    41
#include <linux/netdevice.h>
210
1cc6bcb1e6ae EoE frame receiving; regarding open/stop commands.
Florian Pose <fp@igh-essen.com>
parents: 208
diff changeset
    42
#include <linux/etherdevice.h>
1cc6bcb1e6ae EoE frame receiving; regarding open/stop commands.
Florian Pose <fp@igh-essen.com>
parents: 208
diff changeset
    43
145
11a82e4fd31b Mailbox-Interface ausgelagert, erster EOE-Ansatz.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    44
#include "../include/ecrt.h"
11a82e4fd31b Mailbox-Interface ausgelagert, erster EOE-Ansatz.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    45
#include "globals.h"
11a82e4fd31b Mailbox-Interface ausgelagert, erster EOE-Ansatz.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    46
#include "master.h"
11a82e4fd31b Mailbox-Interface ausgelagert, erster EOE-Ansatz.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    47
#include "slave.h"
11a82e4fd31b Mailbox-Interface ausgelagert, erster EOE-Ansatz.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    48
#include "mailbox.h"
11a82e4fd31b Mailbox-Interface ausgelagert, erster EOE-Ansatz.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    49
#include "ethernet.h"
11a82e4fd31b Mailbox-Interface ausgelagert, erster EOE-Ansatz.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    50
629
84a64efca00d Moved a few constants to the files they are needed in.
Florian Pose <fp@igh-essen.com>
parents: 610
diff changeset
    51
/*****************************************************************************/
84a64efca00d Moved a few constants to the files they are needed in.
Florian Pose <fp@igh-essen.com>
parents: 610
diff changeset
    52
84a64efca00d Moved a few constants to the files they are needed in.
Florian Pose <fp@igh-essen.com>
parents: 610
diff changeset
    53
/**
84a64efca00d Moved a few constants to the files they are needed in.
Florian Pose <fp@igh-essen.com>
parents: 610
diff changeset
    54
 * 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
    55
 *
84a64efca00d Moved a few constants to the files they are needed in.
Florian Pose <fp@igh-essen.com>
parents: 610
diff changeset
    56
 * 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
    57
 * 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
    58
 * 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
    59
 */
286
f3352378b4d4 Added missing documentation.
Florian Pose <fp@igh-essen.com>
parents: 279
diff changeset
    60
216
e7f3e485c5b8 EoE: Corrected faulty MAC address.
Florian Pose <fp@igh-essen.com>
parents: 215
diff changeset
    61
#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
    62
629
84a64efca00d Moved a few constants to the files they are needed in.
Florian Pose <fp@igh-essen.com>
parents: 610
diff changeset
    63
/** 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
    64
#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
    65
145
11a82e4fd31b Mailbox-Interface ausgelagert, erster EOE-Ansatz.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    66
/*****************************************************************************/
11a82e4fd31b Mailbox-Interface ausgelagert, erster EOE-Ansatz.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    67
214
8beb86af5ed0 EoE frame queuing, receiving of fragmented frames; no TCP possible yet.
Florian Pose <fp@igh-essen.com>
parents: 213
diff changeset
    68
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
    69
80fb87518f3d EoE: State machine with function pointers, documentation.
Florian Pose <fp@igh-essen.com>
parents: 217
diff changeset
    70
// state functions
80fb87518f3d EoE: State machine with function pointers, documentation.
Florian Pose <fp@igh-essen.com>
parents: 217
diff changeset
    71
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
    72
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
    73
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
    74
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
    75
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
    76
80fb87518f3d EoE: State machine with function pointers, documentation.
Florian Pose <fp@igh-essen.com>
parents: 217
diff changeset
    77
// net_device functions
203
c1f305e339c6 EoE net_device implementation.
Florian Pose <fp@igh-essen.com>
parents: 199
diff changeset
    78
int ec_eoedev_open(struct net_device *);
c1f305e339c6 EoE net_device implementation.
Florian Pose <fp@igh-essen.com>
parents: 199
diff changeset
    79
int ec_eoedev_stop(struct net_device *);
c1f305e339c6 EoE net_device implementation.
Florian Pose <fp@igh-essen.com>
parents: 199
diff changeset
    80
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
    81
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
    82
c1f305e339c6 EoE net_device implementation.
Florian Pose <fp@igh-essen.com>
parents: 199
diff changeset
    83
/*****************************************************************************/
c1f305e339c6 EoE net_device implementation.
Florian Pose <fp@igh-essen.com>
parents: 199
diff changeset
    84
c1f305e339c6 EoE net_device implementation.
Florian Pose <fp@igh-essen.com>
parents: 199
diff changeset
    85
/**
661
bc1de1362efb Dynamic creation of EoE handlers.
Florian Pose <fp@igh-essen.com>
parents: 629
diff changeset
    86
 * EoE constructor.
bc1de1362efb Dynamic creation of EoE handlers.
Florian Pose <fp@igh-essen.com>
parents: 629
diff changeset
    87
 * 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
    88
 */
bc1de1362efb Dynamic creation of EoE handlers.
Florian Pose <fp@igh-essen.com>
parents: 629
diff changeset
    89
bc1de1362efb Dynamic creation of EoE handlers.
Florian Pose <fp@igh-essen.com>
parents: 629
diff changeset
    90
int ec_eoe_init(
bc1de1362efb Dynamic creation of EoE handlers.
Florian Pose <fp@igh-essen.com>
parents: 629
diff changeset
    91
        ec_eoe_t *eoe, /**< EoE handler */
bc1de1362efb Dynamic creation of EoE handlers.
Florian Pose <fp@igh-essen.com>
parents: 629
diff changeset
    92
        ec_slave_t *slave /**< EtherCAT slave */
bc1de1362efb Dynamic creation of EoE handlers.
Florian Pose <fp@igh-essen.com>
parents: 629
diff changeset
    93
        )
203
c1f305e339c6 EoE net_device implementation.
Florian Pose <fp@igh-essen.com>
parents: 199
diff changeset
    94
{
213
8d723b9833a9 removed unnecessary private structure in eoe net_device.
Florian Pose <fp@igh-essen.com>
parents: 212
diff changeset
    95
    ec_eoe_t **priv;
218
80fb87518f3d EoE: State machine with function pointers, documentation.
Florian Pose <fp@igh-essen.com>
parents: 217
diff changeset
    96
    int result, i;
661
bc1de1362efb Dynamic creation of EoE handlers.
Florian Pose <fp@igh-essen.com>
parents: 629
diff changeset
    97
    char name[20];
bc1de1362efb Dynamic creation of EoE handlers.
Florian Pose <fp@igh-essen.com>
parents: 629
diff changeset
    98
bc1de1362efb Dynamic creation of EoE handlers.
Florian Pose <fp@igh-essen.com>
parents: 629
diff changeset
    99
    eoe->slave = slave;
bc1de1362efb Dynamic creation of EoE handlers.
Florian Pose <fp@igh-essen.com>
parents: 629
diff changeset
   100
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
   101
    ec_datagram_init(&eoe->datagram);
218
80fb87518f3d EoE: State machine with function pointers, documentation.
Florian Pose <fp@igh-essen.com>
parents: 217
diff changeset
   102
    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
   103
    eoe->opened = 0;
218
80fb87518f3d EoE: State machine with function pointers, documentation.
Florian Pose <fp@igh-essen.com>
parents: 217
diff changeset
   104
    eoe->rx_skb = NULL;
80fb87518f3d EoE: State machine with function pointers, documentation.
Florian Pose <fp@igh-essen.com>
parents: 217
diff changeset
   105
    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
   106
    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
   107
    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
   108
    eoe->tx_queue_active = 0;
218
80fb87518f3d EoE: State machine with function pointers, documentation.
Florian Pose <fp@igh-essen.com>
parents: 217
diff changeset
   109
    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
   110
    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
   111
    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
   112
    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
   113
336
360e5287c888 EoE rate statistics.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
   114
    eoe->rx_counter = 0;
360e5287c888 EoE rate statistics.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
   115
    eoe->tx_counter = 0;
360e5287c888 EoE rate statistics.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
   116
    eoe->rx_rate = 0;
360e5287c888 EoE rate statistics.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
   117
    eoe->tx_rate = 0;
344
5d8281f1aa2a Replaced longer cycle timestamps with jiffies.
Florian Pose <fp@igh-essen.com>
parents: 340
diff changeset
   118
    eoe->rate_jiffies = 0;
336
360e5287c888 EoE rate statistics.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
   119
661
bc1de1362efb Dynamic creation of EoE handlers.
Florian Pose <fp@igh-essen.com>
parents: 629
diff changeset
   120
    sprintf(name, "eoe%u-%u", slave->master->index, slave->ring_position);
bc1de1362efb Dynamic creation of EoE handlers.
Florian Pose <fp@igh-essen.com>
parents: 629
diff changeset
   121
bc1de1362efb Dynamic creation of EoE handlers.
Florian Pose <fp@igh-essen.com>
parents: 629
diff changeset
   122
    if (!(eoe->dev = alloc_netdev(sizeof(ec_eoe_t *), name, ether_setup))) {
251
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   123
        EC_ERR("Unable to allocate net_device for EoE handler!\n");
203
c1f305e339c6 EoE net_device implementation.
Florian Pose <fp@igh-essen.com>
parents: 199
diff changeset
   124
        goto out_return;
c1f305e339c6 EoE net_device implementation.
Florian Pose <fp@igh-essen.com>
parents: 199
diff changeset
   125
    }
c1f305e339c6 EoE net_device implementation.
Florian Pose <fp@igh-essen.com>
parents: 199
diff changeset
   126
218
80fb87518f3d EoE: State machine with function pointers, documentation.
Florian Pose <fp@igh-essen.com>
parents: 217
diff changeset
   127
    // initialize net_device
80fb87518f3d EoE: State machine with function pointers, documentation.
Florian Pose <fp@igh-essen.com>
parents: 217
diff changeset
   128
    eoe->dev->open = ec_eoedev_open;
80fb87518f3d EoE: State machine with function pointers, documentation.
Florian Pose <fp@igh-essen.com>
parents: 217
diff changeset
   129
    eoe->dev->stop = ec_eoedev_stop;
80fb87518f3d EoE: State machine with function pointers, documentation.
Florian Pose <fp@igh-essen.com>
parents: 217
diff changeset
   130
    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
   131
    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
   132
80fb87518f3d EoE: State machine with function pointers, documentation.
Florian Pose <fp@igh-essen.com>
parents: 217
diff changeset
   133
    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
   134
        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
   135
80fb87518f3d EoE: State machine with function pointers, documentation.
Florian Pose <fp@igh-essen.com>
parents: 217
diff changeset
   136
    // initialize private data
203
c1f305e339c6 EoE net_device implementation.
Florian Pose <fp@igh-essen.com>
parents: 199
diff changeset
   137
    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
   138
    *priv = eoe;
203
c1f305e339c6 EoE net_device implementation.
Florian Pose <fp@igh-essen.com>
parents: 199
diff changeset
   139
218
80fb87518f3d EoE: State machine with function pointers, documentation.
Florian Pose <fp@igh-essen.com>
parents: 217
diff changeset
   140
    // 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
   141
    // 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
   142
    // 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
   143
    // is done "manually".
80fb87518f3d EoE: State machine with function pointers, documentation.
Florian Pose <fp@igh-essen.com>
parents: 217
diff changeset
   144
#if 0
215
b021aa6eee38 EoE: TCP traffic possible; TX fragmenting to do.
Florian Pose <fp@igh-essen.com>
parents: 214
diff changeset
   145
    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
   146
#endif
214
8beb86af5ed0 EoE frame queuing, receiving of fragmented frames; no TCP possible yet.
Florian Pose <fp@igh-essen.com>
parents: 213
diff changeset
   147
203
c1f305e339c6 EoE net_device implementation.
Florian Pose <fp@igh-essen.com>
parents: 199
diff changeset
   148
    // connect the net_device to the kernel
c1f305e339c6 EoE net_device implementation.
Florian Pose <fp@igh-essen.com>
parents: 199
diff changeset
   149
    if ((result = register_netdev(eoe->dev))) {
c1f305e339c6 EoE net_device implementation.
Florian Pose <fp@igh-essen.com>
parents: 199
diff changeset
   150
        EC_ERR("Unable to register net_device: error %i\n", result);
c1f305e339c6 EoE net_device implementation.
Florian Pose <fp@igh-essen.com>
parents: 199
diff changeset
   151
        goto out_free;
c1f305e339c6 EoE net_device implementation.
Florian Pose <fp@igh-essen.com>
parents: 199
diff changeset
   152
    }
c1f305e339c6 EoE net_device implementation.
Florian Pose <fp@igh-essen.com>
parents: 199
diff changeset
   153
218
80fb87518f3d EoE: State machine with function pointers, documentation.
Florian Pose <fp@igh-essen.com>
parents: 217
diff changeset
   154
    // make the last address octet unique
80fb87518f3d EoE: State machine with function pointers, documentation.
Florian Pose <fp@igh-essen.com>
parents: 217
diff changeset
   155
    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
   156
    return 0;
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
 out_free:
c1f305e339c6 EoE net_device implementation.
Florian Pose <fp@igh-essen.com>
parents: 199
diff changeset
   159
    free_netdev(eoe->dev);
c1f305e339c6 EoE net_device implementation.
Florian Pose <fp@igh-essen.com>
parents: 199
diff changeset
   160
    eoe->dev = NULL;
c1f305e339c6 EoE net_device implementation.
Florian Pose <fp@igh-essen.com>
parents: 199
diff changeset
   161
 out_return:
c1f305e339c6 EoE net_device implementation.
Florian Pose <fp@igh-essen.com>
parents: 199
diff changeset
   162
    return -1;
145
11a82e4fd31b Mailbox-Interface ausgelagert, erster EOE-Ansatz.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   163
}
11a82e4fd31b Mailbox-Interface ausgelagert, erster EOE-Ansatz.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   164
11a82e4fd31b Mailbox-Interface ausgelagert, erster EOE-Ansatz.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   165
/*****************************************************************************/
11a82e4fd31b Mailbox-Interface ausgelagert, erster EOE-Ansatz.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   166
197
b9a6e2c22745 GPLv2 License and enhanced Doxygen output.
Florian Pose <fp@igh-essen.com>
parents: 195
diff changeset
   167
/**
199
04ecf40fc2e9 Doxygen added interface modules and file documentation.
Florian Pose <fp@igh-essen.com>
parents: 197
diff changeset
   168
   EoE destructor.
218
80fb87518f3d EoE: State machine with function pointers, documentation.
Florian Pose <fp@igh-essen.com>
parents: 217
diff changeset
   169
   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
   170
*/
80fb87518f3d EoE: State machine with function pointers, documentation.
Florian Pose <fp@igh-essen.com>
parents: 217
diff changeset
   171
251
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   172
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
   173
{
552
029546740810 Minor: Removed warning when EoE interface is up upon master unloading.
Florian Pose <fp@igh-essen.com>
parents: 460
diff changeset
   174
    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
   175
    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
   176
8beb86af5ed0 EoE frame queuing, receiving of fragmented frames; no TCP possible yet.
Florian Pose <fp@igh-essen.com>
parents: 213
diff changeset
   177
    // 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
   178
    ec_eoe_flush(eoe);
218
80fb87518f3d EoE: State machine with function pointers, documentation.
Florian Pose <fp@igh-essen.com>
parents: 217
diff changeset
   179
80fb87518f3d EoE: State machine with function pointers, documentation.
Florian Pose <fp@igh-essen.com>
parents: 217
diff changeset
   180
    if (eoe->tx_frame) {
80fb87518f3d EoE: State machine with function pointers, documentation.
Florian Pose <fp@igh-essen.com>
parents: 217
diff changeset
   181
        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
   182
        kfree(eoe->tx_frame);
80fb87518f3d EoE: State machine with function pointers, documentation.
Florian Pose <fp@igh-essen.com>
parents: 217
diff changeset
   183
    }
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->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
   186
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
   187
    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
   188
}
8beb86af5ed0 EoE frame queuing, receiving of fragmented frames; no TCP possible yet.
Florian Pose <fp@igh-essen.com>
parents: 213
diff changeset
   189
8beb86af5ed0 EoE frame queuing, receiving of fragmented frames; no TCP possible yet.
Florian Pose <fp@igh-essen.com>
parents: 213
diff changeset
   190
/*****************************************************************************/
8beb86af5ed0 EoE frame queuing, receiving of fragmented frames; no TCP possible yet.
Florian Pose <fp@igh-essen.com>
parents: 213
diff changeset
   191
8beb86af5ed0 EoE frame queuing, receiving of fragmented frames; no TCP possible yet.
Florian Pose <fp@igh-essen.com>
parents: 213
diff changeset
   192
/**
8beb86af5ed0 EoE frame queuing, receiving of fragmented frames; no TCP possible yet.
Florian Pose <fp@igh-essen.com>
parents: 213
diff changeset
   193
   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
   194
*/
8beb86af5ed0 EoE frame queuing, receiving of fragmented frames; no TCP possible yet.
Florian Pose <fp@igh-essen.com>
parents: 213
diff changeset
   195
251
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   196
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
   197
{
8beb86af5ed0 EoE frame queuing, receiving of fragmented frames; no TCP possible yet.
Florian Pose <fp@igh-essen.com>
parents: 213
diff changeset
   198
    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
   199
8beb86af5ed0 EoE frame queuing, receiving of fragmented frames; no TCP possible yet.
Florian Pose <fp@igh-essen.com>
parents: 213
diff changeset
   200
    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
   201
8beb86af5ed0 EoE frame queuing, receiving of fragmented frames; no TCP possible yet.
Florian Pose <fp@igh-essen.com>
parents: 213
diff changeset
   202
    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
   203
        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
   204
        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
   205
        kfree(frame);
8beb86af5ed0 EoE frame queuing, receiving of fragmented frames; no TCP possible yet.
Florian Pose <fp@igh-essen.com>
parents: 213
diff changeset
   206
    }
218
80fb87518f3d EoE: State machine with function pointers, documentation.
Florian Pose <fp@igh-essen.com>
parents: 217
diff changeset
   207
    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
   208
8beb86af5ed0 EoE frame queuing, receiving of fragmented frames; no TCP possible yet.
Florian Pose <fp@igh-essen.com>
parents: 213
diff changeset
   209
    spin_unlock_bh(&eoe->tx_queue_lock);
145
11a82e4fd31b Mailbox-Interface ausgelagert, erster EOE-Ansatz.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   210
}
11a82e4fd31b Mailbox-Interface ausgelagert, erster EOE-Ansatz.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   211
11a82e4fd31b Mailbox-Interface ausgelagert, erster EOE-Ansatz.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   212
/*****************************************************************************/
11a82e4fd31b Mailbox-Interface ausgelagert, erster EOE-Ansatz.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   213
197
b9a6e2c22745 GPLv2 License and enhanced Doxygen output.
Florian Pose <fp@igh-essen.com>
parents: 195
diff changeset
   214
/**
217
dcfd406e7786 EoE - TX fragmenting works. TCP traffic possible.
Florian Pose <fp@igh-essen.com>
parents: 216
diff changeset
   215
   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
   216
*/
dcfd406e7786 EoE - TX fragmenting works. TCP traffic possible.
Florian Pose <fp@igh-essen.com>
parents: 216
diff changeset
   217
251
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   218
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
   219
{
217
dcfd406e7786 EoE - TX fragmenting works. TCP traffic possible.
Florian Pose <fp@igh-essen.com>
parents: 216
diff changeset
   220
    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
   221
    unsigned int last_fragment;
dcfd406e7786 EoE - TX fragmenting works. TCP traffic possible.
Florian Pose <fp@igh-essen.com>
parents: 216
diff changeset
   222
    uint8_t *data;
dcfd406e7786 EoE - TX fragmenting works. TCP traffic possible.
Florian Pose <fp@igh-essen.com>
parents: 216
diff changeset
   223
#if EOE_DEBUG_LEVEL > 1
dcfd406e7786 EoE - TX fragmenting works. TCP traffic possible.
Florian Pose <fp@igh-essen.com>
parents: 216
diff changeset
   224
    unsigned int i;
dcfd406e7786 EoE - TX fragmenting works. TCP traffic possible.
Florian Pose <fp@igh-essen.com>
parents: 216
diff changeset
   225
#endif
dcfd406e7786 EoE - TX fragmenting works. TCP traffic possible.
Florian Pose <fp@igh-essen.com>
parents: 216
diff changeset
   226
218
80fb87518f3d EoE: State machine with function pointers, documentation.
Florian Pose <fp@igh-essen.com>
parents: 217
diff changeset
   227
    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
   228
dcfd406e7786 EoE - TX fragmenting works. TCP traffic possible.
Florian Pose <fp@igh-essen.com>
parents: 216
diff changeset
   229
    if (remaining_size <= eoe->slave->sii_tx_mailbox_size - 10) {
dcfd406e7786 EoE - TX fragmenting works. TCP traffic possible.
Florian Pose <fp@igh-essen.com>
parents: 216
diff changeset
   230
        current_size = remaining_size;
dcfd406e7786 EoE - TX fragmenting works. TCP traffic possible.
Florian Pose <fp@igh-essen.com>
parents: 216
diff changeset
   231
        last_fragment = 1;
dcfd406e7786 EoE - TX fragmenting works. TCP traffic possible.
Florian Pose <fp@igh-essen.com>
parents: 216
diff changeset
   232
    }
dcfd406e7786 EoE - TX fragmenting works. TCP traffic possible.
Florian Pose <fp@igh-essen.com>
parents: 216
diff changeset
   233
    else {
dcfd406e7786 EoE - TX fragmenting works. TCP traffic possible.
Florian Pose <fp@igh-essen.com>
parents: 216
diff changeset
   234
        current_size = ((eoe->slave->sii_tx_mailbox_size - 10) / 32) * 32;
dcfd406e7786 EoE - TX fragmenting works. TCP traffic possible.
Florian Pose <fp@igh-essen.com>
parents: 216
diff changeset
   235
        last_fragment = 0;
dcfd406e7786 EoE - TX fragmenting works. TCP traffic possible.
Florian Pose <fp@igh-essen.com>
parents: 216
diff changeset
   236
    }
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
    if (eoe->tx_fragment_number) {
dcfd406e7786 EoE - TX fragmenting works. TCP traffic possible.
Florian Pose <fp@igh-essen.com>
parents: 216
diff changeset
   239
        complete_offset = eoe->tx_offset / 32;
dcfd406e7786 EoE - TX fragmenting works. TCP traffic possible.
Florian Pose <fp@igh-essen.com>
parents: 216
diff changeset
   240
    }
dcfd406e7786 EoE - TX fragmenting works. TCP traffic possible.
Florian Pose <fp@igh-essen.com>
parents: 216
diff changeset
   241
    else {
319
88f2e8c4face Minor changes.
Florian Pose <fp@igh-essen.com>
parents: 314
diff changeset
   242
        // 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
   243
        complete_offset = remaining_size / 32 + 1;
dcfd406e7786 EoE - TX fragmenting works. TCP traffic possible.
Florian Pose <fp@igh-essen.com>
parents: 216
diff changeset
   244
    }
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
#if EOE_DEBUG_LEVEL > 0
dcfd406e7786 EoE - TX fragmenting works. TCP traffic possible.
Florian Pose <fp@igh-essen.com>
parents: 216
diff changeset
   247
    EC_DBG("EoE TX sending %sfragment %i with %i octets (%i)."
dcfd406e7786 EoE - TX fragmenting works. TCP traffic possible.
Florian Pose <fp@igh-essen.com>
parents: 216
diff changeset
   248
           " %i frames queued.\n", last_fragment ? "last " : "",
dcfd406e7786 EoE - TX fragmenting works. TCP traffic possible.
Florian Pose <fp@igh-essen.com>
parents: 216
diff changeset
   249
           eoe->tx_fragment_number, current_size, complete_offset,
218
80fb87518f3d EoE: State machine with function pointers, documentation.
Florian Pose <fp@igh-essen.com>
parents: 217
diff changeset
   250
           eoe->tx_queued_frames);
217
dcfd406e7786 EoE - TX fragmenting works. TCP traffic possible.
Florian Pose <fp@igh-essen.com>
parents: 216
diff changeset
   251
#endif
dcfd406e7786 EoE - TX fragmenting works. TCP traffic possible.
Florian Pose <fp@igh-essen.com>
parents: 216
diff changeset
   252
dcfd406e7786 EoE - TX fragmenting works. TCP traffic possible.
Florian Pose <fp@igh-essen.com>
parents: 216
diff changeset
   253
#if EOE_DEBUG_LEVEL > 1
dcfd406e7786 EoE - TX fragmenting works. TCP traffic possible.
Florian Pose <fp@igh-essen.com>
parents: 216
diff changeset
   254
    EC_DBG("");
dcfd406e7786 EoE - TX fragmenting works. TCP traffic possible.
Florian Pose <fp@igh-essen.com>
parents: 216
diff changeset
   255
    for (i = 0; i < current_size; i++) {
340
5a5f5a14c847 Fixed EoE debugging.
Florian Pose <fp@igh-essen.com>
parents: 339
diff changeset
   256
        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
   257
        if ((i + 1) % 16 == 0) {
dcfd406e7786 EoE - TX fragmenting works. TCP traffic possible.
Florian Pose <fp@igh-essen.com>
parents: 216
diff changeset
   258
            printk("\n");
dcfd406e7786 EoE - TX fragmenting works. TCP traffic possible.
Florian Pose <fp@igh-essen.com>
parents: 216
diff changeset
   259
            EC_DBG("");
dcfd406e7786 EoE - TX fragmenting works. TCP traffic possible.
Florian Pose <fp@igh-essen.com>
parents: 216
diff changeset
   260
        }
dcfd406e7786 EoE - TX fragmenting works. TCP traffic possible.
Florian Pose <fp@igh-essen.com>
parents: 216
diff changeset
   261
    }
dcfd406e7786 EoE - TX fragmenting works. TCP traffic possible.
Florian Pose <fp@igh-essen.com>
parents: 216
diff changeset
   262
    printk("\n");
dcfd406e7786 EoE - TX fragmenting works. TCP traffic possible.
Florian Pose <fp@igh-essen.com>
parents: 216
diff changeset
   263
#endif
dcfd406e7786 EoE - TX fragmenting works. TCP traffic possible.
Florian Pose <fp@igh-essen.com>
parents: 216
diff changeset
   264
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
   265
    if (!(data = ec_slave_mbox_prepare_send(eoe->slave, &eoe->datagram,
279
12f48c1cb143 Removed mbox_command out of slave.
Florian Pose <fp@igh-essen.com>
parents: 261
diff changeset
   266
                                            0x02, current_size + 4)))
217
dcfd406e7786 EoE - TX fragmenting works. TCP traffic possible.
Florian Pose <fp@igh-essen.com>
parents: 216
diff changeset
   267
        return -1;
dcfd406e7786 EoE - TX fragmenting works. TCP traffic possible.
Florian Pose <fp@igh-essen.com>
parents: 216
diff changeset
   268
dcfd406e7786 EoE - TX fragmenting works. TCP traffic possible.
Florian Pose <fp@igh-essen.com>
parents: 216
diff changeset
   269
    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
   270
    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
   271
    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
   272
                            (complete_offset & 0x3F) << 6 |
dcfd406e7786 EoE - TX fragmenting works. TCP traffic possible.
Florian Pose <fp@igh-essen.com>
parents: 216
diff changeset
   273
                            (eoe->tx_frame_number & 0x0F) << 12));
dcfd406e7786 EoE - TX fragmenting works. TCP traffic possible.
Florian Pose <fp@igh-essen.com>
parents: 216
diff changeset
   274
218
80fb87518f3d EoE: State machine with function pointers, documentation.
Florian Pose <fp@igh-essen.com>
parents: 217
diff changeset
   275
    memcpy(data + 4, eoe->tx_frame->skb->data + eoe->tx_offset, current_size);
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
   276
    ec_master_queue_datagram(eoe->slave->master, &eoe->datagram);
217
dcfd406e7786 EoE - TX fragmenting works. TCP traffic possible.
Florian Pose <fp@igh-essen.com>
parents: 216
diff changeset
   277
dcfd406e7786 EoE - TX fragmenting works. TCP traffic possible.
Florian Pose <fp@igh-essen.com>
parents: 216
diff changeset
   278
    eoe->tx_offset += current_size;
dcfd406e7786 EoE - TX fragmenting works. TCP traffic possible.
Florian Pose <fp@igh-essen.com>
parents: 216
diff changeset
   279
    eoe->tx_fragment_number++;
dcfd406e7786 EoE - TX fragmenting works. TCP traffic possible.
Florian Pose <fp@igh-essen.com>
parents: 216
diff changeset
   280
    return 0;
dcfd406e7786 EoE - TX fragmenting works. TCP traffic possible.
Florian Pose <fp@igh-essen.com>
parents: 216
diff changeset
   281
}
dcfd406e7786 EoE - TX fragmenting works. TCP traffic possible.
Florian Pose <fp@igh-essen.com>
parents: 216
diff changeset
   282
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
dcfd406e7786 EoE - TX fragmenting works. TCP traffic possible.
Florian Pose <fp@igh-essen.com>
parents: 216
diff changeset
   285
/**
199
04ecf40fc2e9 Doxygen added interface modules and file documentation.
Florian Pose <fp@igh-essen.com>
parents: 197
diff changeset
   286
   Runs the EoE state machine.
197
b9a6e2c22745 GPLv2 License and enhanced Doxygen output.
Florian Pose <fp@igh-essen.com>
parents: 195
diff changeset
   287
*/
b9a6e2c22745 GPLv2 License and enhanced Doxygen output.
Florian Pose <fp@igh-essen.com>
parents: 195
diff changeset
   288
251
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   289
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
   290
{
210
1cc6bcb1e6ae EoE frame receiving; regarding open/stop commands.
Florian Pose <fp@igh-essen.com>
parents: 208
diff changeset
   291
    if (!eoe->opened) return;
145
11a82e4fd31b Mailbox-Interface ausgelagert, erster EOE-Ansatz.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   292
218
80fb87518f3d EoE: State machine with function pointers, documentation.
Florian Pose <fp@igh-essen.com>
parents: 217
diff changeset
   293
    // call state function
80fb87518f3d EoE: State machine with function pointers, documentation.
Florian Pose <fp@igh-essen.com>
parents: 217
diff changeset
   294
    eoe->state(eoe);
336
360e5287c888 EoE rate statistics.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
   295
360e5287c888 EoE rate statistics.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
   296
    // update statistics
344
5d8281f1aa2a Replaced longer cycle timestamps with jiffies.
Florian Pose <fp@igh-essen.com>
parents: 340
diff changeset
   297
    if (jiffies - eoe->rate_jiffies > HZ) {
336
360e5287c888 EoE rate statistics.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
   298
        eoe->rx_rate = eoe->rx_counter * 8;
360e5287c888 EoE rate statistics.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
   299
        eoe->tx_rate = eoe->tx_counter * 8;
360e5287c888 EoE rate statistics.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
   300
        eoe->rx_counter = 0;
360e5287c888 EoE rate statistics.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
   301
        eoe->tx_counter = 0;
344
5d8281f1aa2a Replaced longer cycle timestamps with jiffies.
Florian Pose <fp@igh-essen.com>
parents: 340
diff changeset
   302
        eoe->rate_jiffies = jiffies;
336
360e5287c888 EoE rate statistics.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
   303
    }
145
11a82e4fd31b Mailbox-Interface ausgelagert, erster EOE-Ansatz.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   304
}
11a82e4fd31b Mailbox-Interface ausgelagert, erster EOE-Ansatz.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   305
11a82e4fd31b Mailbox-Interface ausgelagert, erster EOE-Ansatz.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   306
/*****************************************************************************/
11a82e4fd31b Mailbox-Interface ausgelagert, erster EOE-Ansatz.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   307
197
b9a6e2c22745 GPLv2 License and enhanced Doxygen output.
Florian Pose <fp@igh-essen.com>
parents: 195
diff changeset
   308
/**
235
f973808540a6 No master locking, if no EoE devices are "up".
Florian Pose <fp@igh-essen.com>
parents: 219
diff changeset
   309
   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
   310
   \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
   311
*/
f973808540a6 No master locking, if no EoE devices are "up".
Florian Pose <fp@igh-essen.com>
parents: 219
diff changeset
   312
661
bc1de1362efb Dynamic creation of EoE handlers.
Florian Pose <fp@igh-essen.com>
parents: 629
diff changeset
   313
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
   314
{
bc1de1362efb Dynamic creation of EoE handlers.
Florian Pose <fp@igh-essen.com>
parents: 629
diff changeset
   315
    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
   316
}
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   317
218
80fb87518f3d EoE: State machine with function pointers, documentation.
Florian Pose <fp@igh-essen.com>
parents: 217
diff changeset
   318
/******************************************************************************
80fb87518f3d EoE: State machine with function pointers, documentation.
Florian Pose <fp@igh-essen.com>
parents: 217
diff changeset
   319
 *  STATE PROCESSING FUNCTIONS
80fb87518f3d EoE: State machine with function pointers, documentation.
Florian Pose <fp@igh-essen.com>
parents: 217
diff changeset
   320
 *****************************************************************************/
80fb87518f3d EoE: State machine with function pointers, documentation.
Florian Pose <fp@igh-essen.com>
parents: 217
diff changeset
   321
80fb87518f3d EoE: State machine with function pointers, documentation.
Florian Pose <fp@igh-essen.com>
parents: 217
diff changeset
   322
/**
80fb87518f3d EoE: State machine with function pointers, documentation.
Florian Pose <fp@igh-essen.com>
parents: 217
diff changeset
   323
   State: RX_START.
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
   324
   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
   325
   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
   326
*/
80fb87518f3d EoE: State machine with function pointers, documentation.
Florian Pose <fp@igh-essen.com>
parents: 217
diff changeset
   327
251
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   328
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
   329
{
610
29489a43ecee Introduced ec_slave_online_state_t, ec_slave_set_online_state(), renamed
Florian Pose <fp@igh-essen.com>
parents: 579
diff changeset
   330
    if (eoe->slave->online_state == EC_SLAVE_OFFLINE ||
29489a43ecee Introduced ec_slave_online_state_t, ec_slave_set_online_state(), renamed
Florian Pose <fp@igh-essen.com>
parents: 579
diff changeset
   331
            !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
   332
        return;
44a3a5833c49 Better state-dependent behaviour for EoE-capable slaves.
Florian Pose <fp@igh-essen.com>
parents: 251
diff changeset
   333
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
   334
    ec_slave_mbox_prepare_check(eoe->slave, &eoe->datagram);
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
   335
    ec_master_queue_datagram(eoe->slave->master, &eoe->datagram);
218
80fb87518f3d EoE: State machine with function pointers, documentation.
Florian Pose <fp@igh-essen.com>
parents: 217
diff changeset
   336
    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
   337
}
80fb87518f3d EoE: State machine with function pointers, documentation.
Florian Pose <fp@igh-essen.com>
parents: 217
diff changeset
   338
80fb87518f3d EoE: State machine with function pointers, documentation.
Florian Pose <fp@igh-essen.com>
parents: 217
diff changeset
   339
/*****************************************************************************/
80fb87518f3d EoE: State machine with function pointers, documentation.
Florian Pose <fp@igh-essen.com>
parents: 217
diff changeset
   340
80fb87518f3d EoE: State machine with function pointers, documentation.
Florian Pose <fp@igh-essen.com>
parents: 217
diff changeset
   341
/**
80fb87518f3d EoE: State machine with function pointers, documentation.
Florian Pose <fp@igh-essen.com>
parents: 217
diff changeset
   342
   State: RX_CHECK.
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
   343
   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
   344
   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
   345
*/
80fb87518f3d EoE: State machine with function pointers, documentation.
Florian Pose <fp@igh-essen.com>
parents: 217
diff changeset
   346
251
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   347
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
   348
{
325
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 322
diff changeset
   349
    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
   350
        eoe->stats.rx_errors++;
80fb87518f3d EoE: State machine with function pointers, documentation.
Florian Pose <fp@igh-essen.com>
parents: 217
diff changeset
   351
        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
   352
        return;
80fb87518f3d EoE: State machine with function pointers, documentation.
Florian Pose <fp@igh-essen.com>
parents: 217
diff changeset
   353
    }
80fb87518f3d EoE: State machine with function pointers, documentation.
Florian Pose <fp@igh-essen.com>
parents: 217
diff changeset
   354
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
   355
    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
   356
        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
   357
        return;
80fb87518f3d EoE: State machine with function pointers, documentation.
Florian Pose <fp@igh-essen.com>
parents: 217
diff changeset
   358
    }
80fb87518f3d EoE: State machine with function pointers, documentation.
Florian Pose <fp@igh-essen.com>
parents: 217
diff changeset
   359
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
   360
    ec_slave_mbox_prepare_fetch(eoe->slave, &eoe->datagram);
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
   361
    ec_master_queue_datagram(eoe->slave->master, &eoe->datagram);
218
80fb87518f3d EoE: State machine with function pointers, documentation.
Florian Pose <fp@igh-essen.com>
parents: 217
diff changeset
   362
    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
   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
/**
80fb87518f3d EoE: State machine with function pointers, documentation.
Florian Pose <fp@igh-essen.com>
parents: 217
diff changeset
   368
   State: RX_FETCH.
80fb87518f3d EoE: State machine with function pointers, documentation.
Florian Pose <fp@igh-essen.com>
parents: 217
diff changeset
   369
   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
   370
   EoE datagram.
218
80fb87518f3d EoE: State machine with function pointers, documentation.
Florian Pose <fp@igh-essen.com>
parents: 217
diff changeset
   371
*/
80fb87518f3d EoE: State machine with function pointers, documentation.
Florian Pose <fp@igh-essen.com>
parents: 217
diff changeset
   372
251
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   373
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
   374
{
80fb87518f3d EoE: State machine with function pointers, documentation.
Florian Pose <fp@igh-essen.com>
parents: 217
diff changeset
   375
    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
   376
    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
   377
    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
   378
    off_t offset;
340
5a5f5a14c847 Fixed EoE debugging.
Florian Pose <fp@igh-essen.com>
parents: 339
diff changeset
   379
#if EOE_DEBUG_LEVEL > 1
5a5f5a14c847 Fixed EoE debugging.
Florian Pose <fp@igh-essen.com>
parents: 339
diff changeset
   380
    unsigned int i;
5a5f5a14c847 Fixed EoE debugging.
Florian Pose <fp@igh-essen.com>
parents: 339
diff changeset
   381
#endif
218
80fb87518f3d EoE: State machine with function pointers, documentation.
Florian Pose <fp@igh-essen.com>
parents: 217
diff changeset
   382
325
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 322
diff changeset
   383
    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
   384
        eoe->stats.rx_errors++;
80fb87518f3d EoE: State machine with function pointers, documentation.
Florian Pose <fp@igh-essen.com>
parents: 217
diff changeset
   385
        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
   386
        return;
80fb87518f3d EoE: State machine with function pointers, documentation.
Florian Pose <fp@igh-essen.com>
parents: 217
diff changeset
   387
    }
80fb87518f3d EoE: State machine with function pointers, documentation.
Florian Pose <fp@igh-essen.com>
parents: 217
diff changeset
   388
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
   389
    if (!(data = ec_slave_mbox_fetch(eoe->slave, &eoe->datagram,
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
   390
                                     &mbox_prot, &rec_size))) {
390
685c267d80d8 Fixed mailbox bug, added mailbox error codes.
Florian Pose <fp@igh-essen.com>
parents: 344
diff changeset
   391
        eoe->stats.rx_errors++;
685c267d80d8 Fixed mailbox bug, added mailbox error codes.
Florian Pose <fp@igh-essen.com>
parents: 344
diff changeset
   392
        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
   393
        return;
685c267d80d8 Fixed mailbox bug, added mailbox error codes.
Florian Pose <fp@igh-essen.com>
parents: 344
diff changeset
   394
    }
685c267d80d8 Fixed mailbox bug, added mailbox error codes.
Florian Pose <fp@igh-essen.com>
parents: 344
diff changeset
   395
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
   396
    if (mbox_prot != 0x02) { // EoE
218
80fb87518f3d EoE: State machine with function pointers, documentation.
Florian Pose <fp@igh-essen.com>
parents: 217
diff changeset
   397
        eoe->stats.rx_errors++;
80fb87518f3d EoE: State machine with function pointers, documentation.
Florian Pose <fp@igh-essen.com>
parents: 217
diff changeset
   398
        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
   399
        return;
80fb87518f3d EoE: State machine with function pointers, documentation.
Florian Pose <fp@igh-essen.com>
parents: 217
diff changeset
   400
    }
80fb87518f3d EoE: State machine with function pointers, documentation.
Florian Pose <fp@igh-essen.com>
parents: 217
diff changeset
   401
80fb87518f3d EoE: State machine with function pointers, documentation.
Florian Pose <fp@igh-essen.com>
parents: 217
diff changeset
   402
    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
   403
322
fceb7b6e0a06 Improved EoE state machine.
Florian Pose <fp@igh-essen.com>
parents: 319
diff changeset
   404
    if (frame_type != 0x00) {
218
80fb87518f3d EoE: State machine with function pointers, documentation.
Florian Pose <fp@igh-essen.com>
parents: 217
diff changeset
   405
#if EOE_DEBUG_LEVEL > 0
80fb87518f3d EoE: State machine with function pointers, documentation.
Florian Pose <fp@igh-essen.com>
parents: 217
diff changeset
   406
        EC_DBG("other frame received.\n");
80fb87518f3d EoE: State machine with function pointers, documentation.
Florian Pose <fp@igh-essen.com>
parents: 217
diff changeset
   407
#endif
80fb87518f3d EoE: State machine with function pointers, documentation.
Florian Pose <fp@igh-essen.com>
parents: 217
diff changeset
   408
        eoe->stats.rx_dropped++;
80fb87518f3d EoE: State machine with function pointers, documentation.
Florian Pose <fp@igh-essen.com>
parents: 217
diff changeset
   409
        eoe->state = ec_eoe_state_tx_start;
322
fceb7b6e0a06 Improved EoE state machine.
Florian Pose <fp@igh-essen.com>
parents: 319
diff changeset
   410
        return;
fceb7b6e0a06 Improved EoE state machine.
Florian Pose <fp@igh-essen.com>
parents: 319
diff changeset
   411
    }
fceb7b6e0a06 Improved EoE state machine.
Florian Pose <fp@igh-essen.com>
parents: 319
diff changeset
   412
fceb7b6e0a06 Improved EoE state machine.
Florian Pose <fp@igh-essen.com>
parents: 319
diff changeset
   413
    // EoE Fragment Request received
fceb7b6e0a06 Improved EoE state machine.
Florian Pose <fp@igh-essen.com>
parents: 319
diff changeset
   414
fceb7b6e0a06 Improved EoE state machine.
Florian Pose <fp@igh-essen.com>
parents: 319
diff changeset
   415
    last_fragment = (EC_READ_U16(data) >> 8) & 0x0001;
fceb7b6e0a06 Improved EoE state machine.
Florian Pose <fp@igh-essen.com>
parents: 319
diff changeset
   416
    time_appended = (EC_READ_U16(data) >> 9) & 0x0001;
fceb7b6e0a06 Improved EoE state machine.
Florian Pose <fp@igh-essen.com>
parents: 319
diff changeset
   417
    fragment_number = EC_READ_U16(data + 2) & 0x003F;
fceb7b6e0a06 Improved EoE state machine.
Florian Pose <fp@igh-essen.com>
parents: 319
diff changeset
   418
    fragment_offset = (EC_READ_U16(data + 2) >> 6) & 0x003F;
fceb7b6e0a06 Improved EoE state machine.
Florian Pose <fp@igh-essen.com>
parents: 319
diff changeset
   419
    frame_number = (EC_READ_U16(data + 2) >> 12) & 0x000F;
fceb7b6e0a06 Improved EoE state machine.
Florian Pose <fp@igh-essen.com>
parents: 319
diff changeset
   420
fceb7b6e0a06 Improved EoE state machine.
Florian Pose <fp@igh-essen.com>
parents: 319
diff changeset
   421
#if EOE_DEBUG_LEVEL > 0
fceb7b6e0a06 Improved EoE state machine.
Florian Pose <fp@igh-essen.com>
parents: 319
diff changeset
   422
    EC_DBG("EoE RX fragment %i, offset %i, frame %i%s%s,"
fceb7b6e0a06 Improved EoE state machine.
Florian Pose <fp@igh-essen.com>
parents: 319
diff changeset
   423
           " %i octets\n", fragment_number, fragment_offset,
fceb7b6e0a06 Improved EoE state machine.
Florian Pose <fp@igh-essen.com>
parents: 319
diff changeset
   424
           frame_number,
fceb7b6e0a06 Improved EoE state machine.
Florian Pose <fp@igh-essen.com>
parents: 319
diff changeset
   425
           last_fragment ? ", last fragment" : "",
fceb7b6e0a06 Improved EoE state machine.
Florian Pose <fp@igh-essen.com>
parents: 319
diff changeset
   426
           time_appended ? ", + timestamp" : "",
fceb7b6e0a06 Improved EoE state machine.
Florian Pose <fp@igh-essen.com>
parents: 319
diff changeset
   427
           time_appended ? rec_size - 8 : rec_size - 4);
fceb7b6e0a06 Improved EoE state machine.
Florian Pose <fp@igh-essen.com>
parents: 319
diff changeset
   428
#endif
fceb7b6e0a06 Improved EoE state machine.
Florian Pose <fp@igh-essen.com>
parents: 319
diff changeset
   429
fceb7b6e0a06 Improved EoE state machine.
Florian Pose <fp@igh-essen.com>
parents: 319
diff changeset
   430
#if EOE_DEBUG_LEVEL > 1
fceb7b6e0a06 Improved EoE state machine.
Florian Pose <fp@igh-essen.com>
parents: 319
diff changeset
   431
    EC_DBG("");
fceb7b6e0a06 Improved EoE state machine.
Florian Pose <fp@igh-essen.com>
parents: 319
diff changeset
   432
    for (i = 0; i < rec_size - 4; i++) {
fceb7b6e0a06 Improved EoE state machine.
Florian Pose <fp@igh-essen.com>
parents: 319
diff changeset
   433
        printk("%02X ", data[i + 4]);
fceb7b6e0a06 Improved EoE state machine.
Florian Pose <fp@igh-essen.com>
parents: 319
diff changeset
   434
        if ((i + 1) % 16 == 0) {
fceb7b6e0a06 Improved EoE state machine.
Florian Pose <fp@igh-essen.com>
parents: 319
diff changeset
   435
            printk("\n");
fceb7b6e0a06 Improved EoE state machine.
Florian Pose <fp@igh-essen.com>
parents: 319
diff changeset
   436
            EC_DBG("");
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
    printk("\n");
fceb7b6e0a06 Improved EoE state machine.
Florian Pose <fp@igh-essen.com>
parents: 319
diff changeset
   440
#endif
fceb7b6e0a06 Improved EoE state machine.
Florian Pose <fp@igh-essen.com>
parents: 319
diff changeset
   441
fceb7b6e0a06 Improved EoE state machine.
Florian Pose <fp@igh-essen.com>
parents: 319
diff changeset
   442
    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
   443
fceb7b6e0a06 Improved EoE state machine.
Florian Pose <fp@igh-essen.com>
parents: 319
diff changeset
   444
    if (!fragment_number) {
fceb7b6e0a06 Improved EoE state machine.
Florian Pose <fp@igh-essen.com>
parents: 319
diff changeset
   445
        if (eoe->rx_skb) {
fceb7b6e0a06 Improved EoE state machine.
Florian Pose <fp@igh-essen.com>
parents: 319
diff changeset
   446
            EC_WARN("EoE RX freeing old socket buffer...\n");
fceb7b6e0a06 Improved EoE state machine.
Florian Pose <fp@igh-essen.com>
parents: 319
diff changeset
   447
            dev_kfree_skb(eoe->rx_skb);
fceb7b6e0a06 Improved EoE state machine.
Florian Pose <fp@igh-essen.com>
parents: 319
diff changeset
   448
        }
fceb7b6e0a06 Improved EoE state machine.
Florian Pose <fp@igh-essen.com>
parents: 319
diff changeset
   449
fceb7b6e0a06 Improved EoE state machine.
Florian Pose <fp@igh-essen.com>
parents: 319
diff changeset
   450
        // new socket buffer
fceb7b6e0a06 Improved EoE state machine.
Florian Pose <fp@igh-essen.com>
parents: 319
diff changeset
   451
        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
   452
            if (printk_ratelimit())
fceb7b6e0a06 Improved EoE state machine.
Florian Pose <fp@igh-essen.com>
parents: 319
diff changeset
   453
                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
   454
            eoe->stats.rx_dropped++;
fceb7b6e0a06 Improved EoE state machine.
Florian Pose <fp@igh-essen.com>
parents: 319
diff changeset
   455
            eoe->state = ec_eoe_state_tx_start;
fceb7b6e0a06 Improved EoE state machine.
Florian Pose <fp@igh-essen.com>
parents: 319
diff changeset
   456
            return;
fceb7b6e0a06 Improved EoE state machine.
Florian Pose <fp@igh-essen.com>
parents: 319
diff changeset
   457
        }
fceb7b6e0a06 Improved EoE state machine.
Florian Pose <fp@igh-essen.com>
parents: 319
diff changeset
   458
fceb7b6e0a06 Improved EoE state machine.
Florian Pose <fp@igh-essen.com>
parents: 319
diff changeset
   459
        eoe->rx_skb_offset = 0;
fceb7b6e0a06 Improved EoE state machine.
Florian Pose <fp@igh-essen.com>
parents: 319
diff changeset
   460
        eoe->rx_skb_size = fragment_offset * 32;
fceb7b6e0a06 Improved EoE state machine.
Florian Pose <fp@igh-essen.com>
parents: 319
diff changeset
   461
        eoe->rx_expected_fragment = 0;
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
    else {
fceb7b6e0a06 Improved EoE state machine.
Florian Pose <fp@igh-essen.com>
parents: 319
diff changeset
   464
        if (!eoe->rx_skb) {
fceb7b6e0a06 Improved EoE state machine.
Florian Pose <fp@igh-essen.com>
parents: 319
diff changeset
   465
            eoe->stats.rx_dropped++;
fceb7b6e0a06 Improved EoE state machine.
Florian Pose <fp@igh-essen.com>
parents: 319
diff changeset
   466
            eoe->state = ec_eoe_state_tx_start;
fceb7b6e0a06 Improved EoE state machine.
Florian Pose <fp@igh-essen.com>
parents: 319
diff changeset
   467
            return;
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
fceb7b6e0a06 Improved EoE state machine.
Florian Pose <fp@igh-essen.com>
parents: 319
diff changeset
   470
        offset = fragment_offset * 32;
fceb7b6e0a06 Improved EoE state machine.
Florian Pose <fp@igh-essen.com>
parents: 319
diff changeset
   471
        if (offset != eoe->rx_skb_offset ||
fceb7b6e0a06 Improved EoE state machine.
Florian Pose <fp@igh-essen.com>
parents: 319
diff changeset
   472
            offset + data_size > eoe->rx_skb_size ||
fceb7b6e0a06 Improved EoE state machine.
Florian Pose <fp@igh-essen.com>
parents: 319
diff changeset
   473
            fragment_number != eoe->rx_expected_fragment) {
fceb7b6e0a06 Improved EoE state machine.
Florian Pose <fp@igh-essen.com>
parents: 319
diff changeset
   474
            dev_kfree_skb(eoe->rx_skb);
fceb7b6e0a06 Improved EoE state machine.
Florian Pose <fp@igh-essen.com>
parents: 319
diff changeset
   475
            eoe->rx_skb = NULL;
fceb7b6e0a06 Improved EoE state machine.
Florian Pose <fp@igh-essen.com>
parents: 319
diff changeset
   476
            eoe->stats.rx_errors++;
fceb7b6e0a06 Improved EoE state machine.
Florian Pose <fp@igh-essen.com>
parents: 319
diff changeset
   477
            eoe->state = ec_eoe_state_tx_start;
fceb7b6e0a06 Improved EoE state machine.
Florian Pose <fp@igh-essen.com>
parents: 319
diff changeset
   478
            return;
fceb7b6e0a06 Improved EoE state machine.
Florian Pose <fp@igh-essen.com>
parents: 319
diff changeset
   479
        }
fceb7b6e0a06 Improved EoE state machine.
Florian Pose <fp@igh-essen.com>
parents: 319
diff changeset
   480
    }
fceb7b6e0a06 Improved EoE state machine.
Florian Pose <fp@igh-essen.com>
parents: 319
diff changeset
   481
fceb7b6e0a06 Improved EoE state machine.
Florian Pose <fp@igh-essen.com>
parents: 319
diff changeset
   482
    // copy fragment into socket buffer
fceb7b6e0a06 Improved EoE state machine.
Florian Pose <fp@igh-essen.com>
parents: 319
diff changeset
   483
    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
   484
    eoe->rx_skb_offset += data_size;
fceb7b6e0a06 Improved EoE state machine.
Florian Pose <fp@igh-essen.com>
parents: 319
diff changeset
   485
fceb7b6e0a06 Improved EoE state machine.
Florian Pose <fp@igh-essen.com>
parents: 319
diff changeset
   486
    if (last_fragment) {
fceb7b6e0a06 Improved EoE state machine.
Florian Pose <fp@igh-essen.com>
parents: 319
diff changeset
   487
        // update statistics
fceb7b6e0a06 Improved EoE state machine.
Florian Pose <fp@igh-essen.com>
parents: 319
diff changeset
   488
        eoe->stats.rx_packets++;
fceb7b6e0a06 Improved EoE state machine.
Florian Pose <fp@igh-essen.com>
parents: 319
diff changeset
   489
        eoe->stats.rx_bytes += eoe->rx_skb->len;
336
360e5287c888 EoE rate statistics.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
   490
        eoe->rx_counter += eoe->rx_skb->len;
322
fceb7b6e0a06 Improved EoE state machine.
Florian Pose <fp@igh-essen.com>
parents: 319
diff changeset
   491
fceb7b6e0a06 Improved EoE state machine.
Florian Pose <fp@igh-essen.com>
parents: 319
diff changeset
   492
#if EOE_DEBUG_LEVEL > 0
fceb7b6e0a06 Improved EoE state machine.
Florian Pose <fp@igh-essen.com>
parents: 319
diff changeset
   493
        EC_DBG("EoE RX frame completed with %u octets.\n",
fceb7b6e0a06 Improved EoE state machine.
Florian Pose <fp@igh-essen.com>
parents: 319
diff changeset
   494
               eoe->rx_skb->len);
fceb7b6e0a06 Improved EoE state machine.
Florian Pose <fp@igh-essen.com>
parents: 319
diff changeset
   495
#endif
fceb7b6e0a06 Improved EoE state machine.
Florian Pose <fp@igh-essen.com>
parents: 319
diff changeset
   496
fceb7b6e0a06 Improved EoE state machine.
Florian Pose <fp@igh-essen.com>
parents: 319
diff changeset
   497
        // pass socket buffer to network stack
fceb7b6e0a06 Improved EoE state machine.
Florian Pose <fp@igh-essen.com>
parents: 319
diff changeset
   498
        eoe->rx_skb->dev = eoe->dev;
fceb7b6e0a06 Improved EoE state machine.
Florian Pose <fp@igh-essen.com>
parents: 319
diff changeset
   499
        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
   500
        eoe->rx_skb->ip_summed = CHECKSUM_UNNECESSARY;
fceb7b6e0a06 Improved EoE state machine.
Florian Pose <fp@igh-essen.com>
parents: 319
diff changeset
   501
        if (netif_rx(eoe->rx_skb)) {
fceb7b6e0a06 Improved EoE state machine.
Florian Pose <fp@igh-essen.com>
parents: 319
diff changeset
   502
            EC_WARN("EoE RX netif_rx failed.\n");
fceb7b6e0a06 Improved EoE state machine.
Florian Pose <fp@igh-essen.com>
parents: 319
diff changeset
   503
        }
fceb7b6e0a06 Improved EoE state machine.
Florian Pose <fp@igh-essen.com>
parents: 319
diff changeset
   504
        eoe->rx_skb = NULL;
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
        eoe->state = ec_eoe_state_tx_start;
fceb7b6e0a06 Improved EoE state machine.
Florian Pose <fp@igh-essen.com>
parents: 319
diff changeset
   507
    }
fceb7b6e0a06 Improved EoE state machine.
Florian Pose <fp@igh-essen.com>
parents: 319
diff changeset
   508
    else {
fceb7b6e0a06 Improved EoE state machine.
Florian Pose <fp@igh-essen.com>
parents: 319
diff changeset
   509
        eoe->rx_expected_fragment++;
fceb7b6e0a06 Improved EoE state machine.
Florian Pose <fp@igh-essen.com>
parents: 319
diff changeset
   510
#if EOE_DEBUG_LEVEL > 0
fceb7b6e0a06 Improved EoE state machine.
Florian Pose <fp@igh-essen.com>
parents: 319
diff changeset
   511
        EC_DBG("EoE RX expecting fragment %i\n",
fceb7b6e0a06 Improved EoE state machine.
Florian Pose <fp@igh-essen.com>
parents: 319
diff changeset
   512
               eoe->rx_expected_fragment);
fceb7b6e0a06 Improved EoE state machine.
Florian Pose <fp@igh-essen.com>
parents: 319
diff changeset
   513
#endif
fceb7b6e0a06 Improved EoE state machine.
Florian Pose <fp@igh-essen.com>
parents: 319
diff changeset
   514
        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
   515
    }
80fb87518f3d EoE: State machine with function pointers, documentation.
Florian Pose <fp@igh-essen.com>
parents: 217
diff changeset
   516
}
80fb87518f3d EoE: State machine with function pointers, documentation.
Florian Pose <fp@igh-essen.com>
parents: 217
diff changeset
   517
80fb87518f3d EoE: State machine with function pointers, documentation.
Florian Pose <fp@igh-essen.com>
parents: 217
diff changeset
   518
/*****************************************************************************/
80fb87518f3d EoE: State machine with function pointers, documentation.
Florian Pose <fp@igh-essen.com>
parents: 217
diff changeset
   519
80fb87518f3d EoE: State machine with function pointers, documentation.
Florian Pose <fp@igh-essen.com>
parents: 217
diff changeset
   520
/**
80fb87518f3d EoE: State machine with function pointers, documentation.
Florian Pose <fp@igh-essen.com>
parents: 217
diff changeset
   521
   State: TX START.
80fb87518f3d EoE: State machine with function pointers, documentation.
Florian Pose <fp@igh-essen.com>
parents: 217
diff changeset
   522
   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
   523
   sequence is started instead.
80fb87518f3d EoE: State machine with function pointers, documentation.
Florian Pose <fp@igh-essen.com>
parents: 217
diff changeset
   524
*/
80fb87518f3d EoE: State machine with function pointers, documentation.
Florian Pose <fp@igh-essen.com>
parents: 217
diff changeset
   525
251
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   526
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
   527
{
80fb87518f3d EoE: State machine with function pointers, documentation.
Florian Pose <fp@igh-essen.com>
parents: 217
diff changeset
   528
#if EOE_DEBUG_LEVEL > 0
340
5a5f5a14c847 Fixed EoE debugging.
Florian Pose <fp@igh-essen.com>
parents: 339
diff changeset
   529
    unsigned int wakeup = 0;
218
80fb87518f3d EoE: State machine with function pointers, documentation.
Florian Pose <fp@igh-essen.com>
parents: 217
diff changeset
   530
#endif
80fb87518f3d EoE: State machine with function pointers, documentation.
Florian Pose <fp@igh-essen.com>
parents: 217
diff changeset
   531
610
29489a43ecee Introduced ec_slave_online_state_t, ec_slave_set_online_state(), renamed
Florian Pose <fp@igh-essen.com>
parents: 579
diff changeset
   532
    if (eoe->slave->online_state == EC_SLAVE_OFFLINE ||
29489a43ecee Introduced ec_slave_online_state_t, ec_slave_set_online_state(), renamed
Florian Pose <fp@igh-essen.com>
parents: 579
diff changeset
   533
            !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
   534
        return;
44a3a5833c49 Better state-dependent behaviour for EoE-capable slaves.
Florian Pose <fp@igh-essen.com>
parents: 251
diff changeset
   535
218
80fb87518f3d EoE: State machine with function pointers, documentation.
Florian Pose <fp@igh-essen.com>
parents: 217
diff changeset
   536
    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
   537
80fb87518f3d EoE: State machine with function pointers, documentation.
Florian Pose <fp@igh-essen.com>
parents: 217
diff changeset
   538
    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
   539
        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
   540
        // no data available.
80fb87518f3d EoE: State machine with function pointers, documentation.
Florian Pose <fp@igh-essen.com>
parents: 217
diff changeset
   541
        // start a new receive immediately.
80fb87518f3d EoE: State machine with function pointers, documentation.
Florian Pose <fp@igh-essen.com>
parents: 217
diff changeset
   542
        ec_eoe_state_rx_start(eoe);
80fb87518f3d EoE: State machine with function pointers, documentation.
Florian Pose <fp@igh-essen.com>
parents: 217
diff changeset
   543
        return;
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
    // 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
   547
    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
   548
    list_del(&eoe->tx_frame->queue);
80fb87518f3d EoE: State machine with function pointers, documentation.
Florian Pose <fp@igh-essen.com>
parents: 217
diff changeset
   549
    if (!eoe->tx_queue_active &&
80fb87518f3d EoE: State machine with function pointers, documentation.
Florian Pose <fp@igh-essen.com>
parents: 217
diff changeset
   550
        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
   551
        netif_wake_queue(eoe->dev);
80fb87518f3d EoE: State machine with function pointers, documentation.
Florian Pose <fp@igh-essen.com>
parents: 217
diff changeset
   552
        eoe->tx_queue_active = 1;
80fb87518f3d EoE: State machine with function pointers, documentation.
Florian Pose <fp@igh-essen.com>
parents: 217
diff changeset
   553
#if EOE_DEBUG_LEVEL > 0
80fb87518f3d EoE: State machine with function pointers, documentation.
Florian Pose <fp@igh-essen.com>
parents: 217
diff changeset
   554
        wakeup = 1;
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
    }
80fb87518f3d EoE: State machine with function pointers, documentation.
Florian Pose <fp@igh-essen.com>
parents: 217
diff changeset
   557
80fb87518f3d EoE: State machine with function pointers, documentation.
Florian Pose <fp@igh-essen.com>
parents: 217
diff changeset
   558
    eoe->tx_queued_frames--;
80fb87518f3d EoE: State machine with function pointers, documentation.
Florian Pose <fp@igh-essen.com>
parents: 217
diff changeset
   559
    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
   560
80fb87518f3d EoE: State machine with function pointers, documentation.
Florian Pose <fp@igh-essen.com>
parents: 217
diff changeset
   561
    eoe->tx_frame_number++;
80fb87518f3d EoE: State machine with function pointers, documentation.
Florian Pose <fp@igh-essen.com>
parents: 217
diff changeset
   562
    eoe->tx_frame_number %= 16;
80fb87518f3d EoE: State machine with function pointers, documentation.
Florian Pose <fp@igh-essen.com>
parents: 217
diff changeset
   563
    eoe->tx_fragment_number = 0;
80fb87518f3d EoE: State machine with function pointers, documentation.
Florian Pose <fp@igh-essen.com>
parents: 217
diff changeset
   564
    eoe->tx_offset = 0;
80fb87518f3d EoE: State machine with function pointers, documentation.
Florian Pose <fp@igh-essen.com>
parents: 217
diff changeset
   565
80fb87518f3d EoE: State machine with function pointers, documentation.
Florian Pose <fp@igh-essen.com>
parents: 217
diff changeset
   566
    if (ec_eoe_send(eoe)) {
80fb87518f3d EoE: State machine with function pointers, documentation.
Florian Pose <fp@igh-essen.com>
parents: 217
diff changeset
   567
        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
   568
        kfree(eoe->tx_frame);
80fb87518f3d EoE: State machine with function pointers, documentation.
Florian Pose <fp@igh-essen.com>
parents: 217
diff changeset
   569
        eoe->tx_frame = NULL;
80fb87518f3d EoE: State machine with function pointers, documentation.
Florian Pose <fp@igh-essen.com>
parents: 217
diff changeset
   570
        eoe->stats.tx_errors++;
80fb87518f3d EoE: State machine with function pointers, documentation.
Florian Pose <fp@igh-essen.com>
parents: 217
diff changeset
   571
        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
   572
        return;
80fb87518f3d EoE: State machine with function pointers, documentation.
Florian Pose <fp@igh-essen.com>
parents: 217
diff changeset
   573
    }
80fb87518f3d EoE: State machine with function pointers, documentation.
Florian Pose <fp@igh-essen.com>
parents: 217
diff changeset
   574
80fb87518f3d EoE: State machine with function pointers, documentation.
Florian Pose <fp@igh-essen.com>
parents: 217
diff changeset
   575
#if EOE_DEBUG_LEVEL > 0
80fb87518f3d EoE: State machine with function pointers, documentation.
Florian Pose <fp@igh-essen.com>
parents: 217
diff changeset
   576
    if (wakeup) EC_DBG("waking up TX queue...\n");
80fb87518f3d EoE: State machine with function pointers, documentation.
Florian Pose <fp@igh-essen.com>
parents: 217
diff changeset
   577
#endif
80fb87518f3d EoE: State machine with function pointers, documentation.
Florian Pose <fp@igh-essen.com>
parents: 217
diff changeset
   578
80fb87518f3d EoE: State machine with function pointers, documentation.
Florian Pose <fp@igh-essen.com>
parents: 217
diff changeset
   579
    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
   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
/*****************************************************************************/
80fb87518f3d EoE: State machine with function pointers, documentation.
Florian Pose <fp@igh-essen.com>
parents: 217
diff changeset
   583
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
   State: TX SENT.
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
   586
   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
   587
   fragment, if necessary.
80fb87518f3d EoE: State machine with function pointers, documentation.
Florian Pose <fp@igh-essen.com>
parents: 217
diff changeset
   588
*/
80fb87518f3d EoE: State machine with function pointers, documentation.
Florian Pose <fp@igh-essen.com>
parents: 217
diff changeset
   589
251
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   590
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
   591
{
325
7833cf70c4f2 VERSION 1.1: New realtime interface, only state machines.
Florian Pose <fp@igh-essen.com>
parents: 322
diff changeset
   592
    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
   593
        eoe->stats.tx_errors++;
80fb87518f3d EoE: State machine with function pointers, documentation.
Florian Pose <fp@igh-essen.com>
parents: 217
diff changeset
   594
        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
   595
        return;
80fb87518f3d EoE: State machine with function pointers, documentation.
Florian Pose <fp@igh-essen.com>
parents: 217
diff changeset
   596
    }
80fb87518f3d EoE: State machine with function pointers, documentation.
Florian Pose <fp@igh-essen.com>
parents: 217
diff changeset
   597
293
14aeb79aa992 Renamed command structure to datagram.
Florian Pose <fp@igh-essen.com>
parents: 291
diff changeset
   598
    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
   599
        eoe->stats.tx_errors++;
80fb87518f3d EoE: State machine with function pointers, documentation.
Florian Pose <fp@igh-essen.com>
parents: 217
diff changeset
   600
        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
   601
        return;
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
80fb87518f3d EoE: State machine with function pointers, documentation.
Florian Pose <fp@igh-essen.com>
parents: 217
diff changeset
   604
    // frame completely sent
80fb87518f3d EoE: State machine with function pointers, documentation.
Florian Pose <fp@igh-essen.com>
parents: 217
diff changeset
   605
    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
   606
        eoe->stats.tx_packets++;
80fb87518f3d EoE: State machine with function pointers, documentation.
Florian Pose <fp@igh-essen.com>
parents: 217
diff changeset
   607
        eoe->stats.tx_bytes += eoe->tx_frame->skb->len;
336
360e5287c888 EoE rate statistics.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
   608
        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
   609
        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
   610
        kfree(eoe->tx_frame);
80fb87518f3d EoE: State machine with function pointers, documentation.
Florian Pose <fp@igh-essen.com>
parents: 217
diff changeset
   611
        eoe->tx_frame = NULL;
80fb87518f3d EoE: State machine with function pointers, documentation.
Florian Pose <fp@igh-essen.com>
parents: 217
diff changeset
   612
        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
   613
    }
80fb87518f3d EoE: State machine with function pointers, documentation.
Florian Pose <fp@igh-essen.com>
parents: 217
diff changeset
   614
    else { // send next fragment
80fb87518f3d EoE: State machine with function pointers, documentation.
Florian Pose <fp@igh-essen.com>
parents: 217
diff changeset
   615
        if (ec_eoe_send(eoe)) {
80fb87518f3d EoE: State machine with function pointers, documentation.
Florian Pose <fp@igh-essen.com>
parents: 217
diff changeset
   616
            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
   617
            kfree(eoe->tx_frame);
80fb87518f3d EoE: State machine with function pointers, documentation.
Florian Pose <fp@igh-essen.com>
parents: 217
diff changeset
   618
            eoe->tx_frame = NULL;
80fb87518f3d EoE: State machine with function pointers, documentation.
Florian Pose <fp@igh-essen.com>
parents: 217
diff changeset
   619
            eoe->stats.tx_errors++;
80fb87518f3d EoE: State machine with function pointers, documentation.
Florian Pose <fp@igh-essen.com>
parents: 217
diff changeset
   620
            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
   621
        }
80fb87518f3d EoE: State machine with function pointers, documentation.
Florian Pose <fp@igh-essen.com>
parents: 217
diff changeset
   622
    }
80fb87518f3d EoE: State machine with function pointers, documentation.
Florian Pose <fp@igh-essen.com>
parents: 217
diff changeset
   623
}
80fb87518f3d EoE: State machine with function pointers, documentation.
Florian Pose <fp@igh-essen.com>
parents: 217
diff changeset
   624
80fb87518f3d EoE: State machine with function pointers, documentation.
Florian Pose <fp@igh-essen.com>
parents: 217
diff changeset
   625
/******************************************************************************
80fb87518f3d EoE: State machine with function pointers, documentation.
Florian Pose <fp@igh-essen.com>
parents: 217
diff changeset
   626
 *  NET_DEVICE functions
80fb87518f3d EoE: State machine with function pointers, documentation.
Florian Pose <fp@igh-essen.com>
parents: 217
diff changeset
   627
 *****************************************************************************/
203
c1f305e339c6 EoE net_device implementation.
Florian Pose <fp@igh-essen.com>
parents: 199
diff changeset
   628
c1f305e339c6 EoE net_device implementation.
Florian Pose <fp@igh-essen.com>
parents: 199
diff changeset
   629
/**
c1f305e339c6 EoE net_device implementation.
Florian Pose <fp@igh-essen.com>
parents: 199
diff changeset
   630
   Opens the virtual network device.
c1f305e339c6 EoE net_device implementation.
Florian Pose <fp@igh-essen.com>
parents: 199
diff changeset
   631
*/
c1f305e339c6 EoE net_device implementation.
Florian Pose <fp@igh-essen.com>
parents: 199
diff changeset
   632
c1f305e339c6 EoE net_device implementation.
Florian Pose <fp@igh-essen.com>
parents: 199
diff changeset
   633
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
   634
{
213
8d723b9833a9 removed unnecessary private structure in eoe net_device.
Florian Pose <fp@igh-essen.com>
parents: 212
diff changeset
   635
    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
   636
    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
   637
    eoe->opened = 1;
203
c1f305e339c6 EoE net_device implementation.
Florian Pose <fp@igh-essen.com>
parents: 199
diff changeset
   638
    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
   639
    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
   640
    EC_INFO("%s opened.\n", dev->name);
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   641
    if (!eoe->slave)
460
719ba8ccc509 Minor output changes in ethernet.c
Florian Pose <fp@igh-essen.com>
parents: 446
diff changeset
   642
        EC_WARN("Device %s is not coupled to any EoE slave!\n", dev->name);
251
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   643
    else {
446
8fede404c01f Persistent slave lists.
Florian Pose <fp@igh-essen.com>
parents: 391
diff changeset
   644
        ec_slave_request_state(eoe->slave, EC_SLAVE_STATE_OP);
251
c1d0b63a9302 EoE in Free-Run mode; Finished slave configuration state machine.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
   645
    }
203
c1f305e339c6 EoE net_device implementation.
Florian Pose <fp@igh-essen.com>
parents: 199
diff changeset
   646
    return 0;
c1f305e339c6 EoE net_device implementation.
Florian Pose <fp@igh-essen.com>
parents: 199
diff changeset
   647
}
c1f305e339c6 EoE net_device implementation.
Florian Pose <fp@igh-essen.com>
parents: 199
diff changeset
   648
c1f305e339c6 EoE net_device implementation.
Florian Pose <fp@igh-essen.com>
parents: 199
diff changeset
   649
/*****************************************************************************/
c1f305e339c6 EoE net_device implementation.
Florian Pose <fp@igh-essen.com>
parents: 199
diff changeset
   650
c1f305e339c6 EoE net_device implementation.
Florian Pose <fp@igh-essen.com>
parents: 199
diff changeset
   651
/**
c1f305e339c6 EoE net_device implementation.
Florian Pose <fp@igh-essen.com>
parents: 199
diff changeset
   652
   Stops the virtual network device.
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
c1f305e339c6 EoE net_device implementation.
Florian Pose <fp@igh-essen.com>
parents: 199
diff changeset
   655
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
   656
{
213
8d723b9833a9 removed unnecessary private structure in eoe net_device.
Florian Pose <fp@igh-essen.com>
parents: 212
diff changeset
   657
    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
   658
    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
   659
    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
   660
    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
   661
    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
   662
    EC_INFO("%s stopped.\n", dev->name);
552
029546740810 Minor: Removed warning when EoE interface is up upon master unloading.
Florian Pose <fp@igh-essen.com>
parents: 460
diff changeset
   663
    if (eoe->slave)
446
8fede404c01f Persistent slave lists.
Florian Pose <fp@igh-essen.com>
parents: 391
diff changeset
   664
        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
   665
    return 0;
c1f305e339c6 EoE net_device implementation.
Florian Pose <fp@igh-essen.com>
parents: 199
diff changeset
   666
}
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
   Transmits data via the virtual network device.
c1f305e339c6 EoE net_device implementation.
Florian Pose <fp@igh-essen.com>
parents: 199
diff changeset
   672
*/
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
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
   675
                 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
   676
                )
82980deb8b00 moved stats into eoe struct; persistent rx-skb; tx queue.
Florian Pose <fp@igh-essen.com>
parents: 210
diff changeset
   677
{
213
8d723b9833a9 removed unnecessary private structure in eoe net_device.
Florian Pose <fp@igh-essen.com>
parents: 212
diff changeset
   678
    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
   679
    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
   680
217
dcfd406e7786 EoE - TX fragmenting works. TCP traffic possible.
Florian Pose <fp@igh-essen.com>
parents: 216
diff changeset
   681
#if 0
dcfd406e7786 EoE - TX fragmenting works. TCP traffic possible.
Florian Pose <fp@igh-essen.com>
parents: 216
diff changeset
   682
    if (skb->len > eoe->slave->sii_tx_mailbox_size - 10) {
214
8beb86af5ed0 EoE frame queuing, receiving of fragmented frames; no TCP possible yet.
Florian Pose <fp@igh-essen.com>
parents: 213
diff changeset
   683
        EC_WARN("EoE TX frame (%i octets) exceeds MTU. dropping.\n", skb->len);
8beb86af5ed0 EoE frame queuing, receiving of fragmented frames; no TCP possible yet.
Florian Pose <fp@igh-essen.com>
parents: 213
diff changeset
   684
        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
   685
        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
   686
        return 0;
8beb86af5ed0 EoE frame queuing, receiving of fragmented frames; no TCP possible yet.
Florian Pose <fp@igh-essen.com>
parents: 213
diff changeset
   687
    }
217
dcfd406e7786 EoE - TX fragmenting works. TCP traffic possible.
Florian Pose <fp@igh-essen.com>
parents: 216
diff changeset
   688
#endif
214
8beb86af5ed0 EoE frame queuing, receiving of fragmented frames; no TCP possible yet.
Florian Pose <fp@igh-essen.com>
parents: 213
diff changeset
   689
8beb86af5ed0 EoE frame queuing, receiving of fragmented frames; no TCP possible yet.
Florian Pose <fp@igh-essen.com>
parents: 213
diff changeset
   690
    if (!(frame =
8beb86af5ed0 EoE frame queuing, receiving of fragmented frames; no TCP possible yet.
Florian Pose <fp@igh-essen.com>
parents: 213
diff changeset
   691
          (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
   692
        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
   693
            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
   694
        return 1;
8beb86af5ed0 EoE frame queuing, receiving of fragmented frames; no TCP possible yet.
Florian Pose <fp@igh-essen.com>
parents: 213
diff changeset
   695
    }
8beb86af5ed0 EoE frame queuing, receiving of fragmented frames; no TCP possible yet.
Florian Pose <fp@igh-essen.com>
parents: 213
diff changeset
   696
8beb86af5ed0 EoE frame queuing, receiving of fragmented frames; no TCP possible yet.
Florian Pose <fp@igh-essen.com>
parents: 213
diff changeset
   697
    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
   698
82980deb8b00 moved stats into eoe struct; persistent rx-skb; tx queue.
Florian Pose <fp@igh-essen.com>
parents: 210
diff changeset
   699
    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
   700
    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
   701
    eoe->tx_queued_frames++;
80fb87518f3d EoE: State machine with function pointers, documentation.
Florian Pose <fp@igh-essen.com>
parents: 217
diff changeset
   702
    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
   703
        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
   704
        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
   705
    }
212
82980deb8b00 moved stats into eoe struct; persistent rx-skb; tx queue.
Florian Pose <fp@igh-essen.com>
parents: 210
diff changeset
   706
    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
   707
215
b021aa6eee38 EoE: TCP traffic possible; TX fragmenting to do.
Florian Pose <fp@igh-essen.com>
parents: 214
diff changeset
   708
#if EOE_DEBUG_LEVEL > 0
214
8beb86af5ed0 EoE frame queuing, receiving of fragmented frames; no TCP possible yet.
Florian Pose <fp@igh-essen.com>
parents: 213
diff changeset
   709
    EC_DBG("EoE TX queued frame with %i octets (%i frames queued).\n",
218
80fb87518f3d EoE: State machine with function pointers, documentation.
Florian Pose <fp@igh-essen.com>
parents: 217
diff changeset
   710
           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
   711
    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
   712
        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
   713
#endif
214
8beb86af5ed0 EoE frame queuing, receiving of fragmented frames; no TCP possible yet.
Florian Pose <fp@igh-essen.com>
parents: 213
diff changeset
   714
203
c1f305e339c6 EoE net_device implementation.
Florian Pose <fp@igh-essen.com>
parents: 199
diff changeset
   715
    return 0;
c1f305e339c6 EoE net_device implementation.
Florian Pose <fp@igh-essen.com>
parents: 199
diff changeset
   716
}
c1f305e339c6 EoE net_device implementation.
Florian Pose <fp@igh-essen.com>
parents: 199
diff changeset
   717
c1f305e339c6 EoE net_device implementation.
Florian Pose <fp@igh-essen.com>
parents: 199
diff changeset
   718
/*****************************************************************************/
c1f305e339c6 EoE net_device implementation.
Florian Pose <fp@igh-essen.com>
parents: 199
diff changeset
   719
c1f305e339c6 EoE net_device implementation.
Florian Pose <fp@igh-essen.com>
parents: 199
diff changeset
   720
/**
c1f305e339c6 EoE net_device implementation.
Florian Pose <fp@igh-essen.com>
parents: 199
diff changeset
   721
   Gets statistics about the virtual network device.
c1f305e339c6 EoE net_device implementation.
Florian Pose <fp@igh-essen.com>
parents: 199
diff changeset
   722
*/
c1f305e339c6 EoE net_device implementation.
Florian Pose <fp@igh-essen.com>
parents: 199
diff changeset
   723
c1f305e339c6 EoE net_device implementation.
Florian Pose <fp@igh-essen.com>
parents: 199
diff changeset
   724
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
   725
                                         /**< EoE net_device */)
c1f305e339c6 EoE net_device implementation.
Florian Pose <fp@igh-essen.com>
parents: 199
diff changeset
   726
{
213
8d723b9833a9 removed unnecessary private structure in eoe net_device.
Florian Pose <fp@igh-essen.com>
parents: 212
diff changeset
   727
    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
   728
    return &eoe->stats;
82980deb8b00 moved stats into eoe struct; persistent rx-skb; tx queue.
Florian Pose <fp@igh-essen.com>
parents: 210
diff changeset
   729
}
82980deb8b00 moved stats into eoe struct; persistent rx-skb; tx queue.
Florian Pose <fp@igh-essen.com>
parents: 210
diff changeset
   730
82980deb8b00 moved stats into eoe struct; persistent rx-skb; tx queue.
Florian Pose <fp@igh-essen.com>
parents: 210
diff changeset
   731
/*****************************************************************************/