IgH EtherCAT Master  1.7.0
device.h
Go to the documentation of this file.
1 /*****************************************************************************
2  *
3  * Copyright (C) 2006-2008 Florian Pose, Ingenieurgemeinschaft IgH
4  *
5  * This file is part of the IgH EtherCAT Master.
6  *
7  * The IgH EtherCAT Master is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License version 2, as
9  * published by the Free Software Foundation.
10  *
11  * The IgH EtherCAT Master is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
14  * Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License along
17  * with the IgH EtherCAT Master; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19  *
20  ****************************************************************************/
21 
27 /****************************************************************************/
28 
29 #ifndef __EC_DEVICE_H__
30 #define __EC_DEVICE_H__
31 
32 #include <linux/interrupt.h>
33 
34 #include "../devices/ecdev.h"
35 #include "globals.h"
36 
43 #define EC_TX_RING_SIZE 2
44 
45 #ifdef EC_DEBUG_IF
46 #include "debug.h"
47 #endif
48 
49 #ifdef EC_DEBUG_RING
50 #include <linux/version.h>
51 #define EC_DEBUG_RING_SIZE 10
52 
53 typedef enum {
54  TX, RX
55 } ec_debug_frame_dir_t;
56 
57 typedef struct {
58  ec_debug_frame_dir_t dir;
59 #if LINUX_VERSION_CODE >= KERNEL_VERSION(5, 6, 0)
60  struct timespec64 t;
61 #else
62  struct timeval t;
63 #endif
64  uint8_t data[EC_MAX_DATA_SIZE];
65  unsigned int data_size;
66 } ec_debug_frame_t;
67 
68 #endif
69 
70 /****************************************************************************/
71 
78 struct ec_device
79 {
81  struct net_device *dev;
83  struct module *module;
84  uint8_t open;
85  uint8_t link_state;
86  struct sk_buff *tx_skb[EC_TX_RING_SIZE];
87  unsigned int tx_ring_index;
88 #ifdef EC_HAVE_CYCLES
89  cycles_t cycles_poll;
90 #endif
91 #ifdef EC_DEBUG_RING
92 #if LINUX_VERSION_CODE >= KERNEL_VERSION(5, 6, 0)
93  struct timespec64 timeval_poll;
94 #else
95  struct timeval timeval_poll;
96 #endif
97 #endif
98  unsigned long jiffies_poll;
100  // Frame statistics
101  u64 tx_count;
103  u64 rx_count;
106  u64 tx_bytes;
108  u64 rx_bytes;
111  u64 tx_errors;
123 #ifdef EC_DEBUG_IF
124  ec_debug_t dbg;
125 #endif
126 #ifdef EC_DEBUG_RING
127  ec_debug_frame_t debug_frames[EC_DEBUG_RING_SIZE];
128  unsigned int debug_frame_index;
129  unsigned int debug_frame_count;
130 #endif
131 };
132 
133 /****************************************************************************/
134 
137 
138 void ec_device_attach(ec_device_t *, struct net_device *, ec_pollfunc_t,
139  struct module *);
141 
144 
146 uint8_t *ec_device_tx_data(ec_device_t *);
147 void ec_device_send(ec_device_t *, size_t);
150 
151 #ifdef EC_DEBUG_RING
152 void ec_device_debug_ring_append(ec_device_t *, ec_debug_frame_dir_t,
153  const void *, size_t);
154 void ec_device_debug_ring_print(const ec_device_t *);
155 #endif
156 
157 /****************************************************************************/
158 
159 #endif
struct sk_buff * tx_skb[EC_TX_RING_SIZE]
transmit skb ring
Definition: device.h:86
void ec_device_attach(ec_device_t *, struct net_device *, ec_pollfunc_t, struct module *)
Associate with net_device.
Definition: device.c:194
ec_pollfunc_t poll
pointer to the device&#39;s poll function
Definition: device.h:82
unsigned long jiffies_poll
jiffies of last poll
Definition: device.h:98
Network interface for debugging purposes.
u64 last_tx_count
Number of frames sent of last statistics cycle.
Definition: device.h:102
#define EC_RATE_COUNT
Number of statistic rate intervals to maintain.
Definition: globals.h:60
uint8_t * ec_device_tx_data(ec_device_t *)
Returns a pointer to the device&#39;s transmit memory.
Definition: device.c:316
struct module * module
pointer to the device&#39;s owning module
Definition: device.h:83
s32 tx_frame_rates[EC_RATE_COUNT]
Transmit rates in frames/s for different statistics cycle periods.
Definition: device.h:112
Debugging network interface.
Definition: debug.h:38
uint8_t link_state
device link state
Definition: device.h:85
u64 rx_count
Number of frames received.
Definition: device.h:103
u64 last_tx_bytes
Number of bytes sent of last statistics cycle.
Definition: device.h:107
Global definitions and macros.
s32 rx_frame_rates[EC_RATE_COUNT]
Receive rates in frames/s for different statistics cycle periods.
Definition: device.h:115
void ec_device_detach(ec_device_t *)
Disconnect from net_device.
Definition: device.c:225
#define EC_TX_RING_SIZE
Size of the transmit ring.
Definition: device.h:43
u64 last_rx_count
Number of frames received of last statistics cycle.
Definition: device.h:104
void(* ec_pollfunc_t)(struct net_device *)
Device poll function type.
Definition: ecdev.h:49
s32 rx_byte_rates[EC_RATE_COUNT]
Receive rates in byte/s for different statistics cycle periods.
Definition: device.h:120
EtherCAT device.
Definition: device.h:78
unsigned int tx_ring_index
last ring entry used to transmit
Definition: device.h:87
void ec_device_poll(ec_device_t *)
Calls the poll function of the assigned net_device.
Definition: device.c:498
s32 tx_byte_rates[EC_RATE_COUNT]
Transmit rates in byte/s for different statistics cycle periods.
Definition: device.h:118
void ec_device_clear_stats(ec_device_t *)
Clears the frame statistics.
Definition: device.c:374
ec_master_t * master
EtherCAT master.
Definition: device.h:80
u64 rx_bytes
Number of bytes received.
Definition: device.h:108
u64 tx_count
Number of frames sent.
Definition: device.h:101
int ec_device_init(ec_device_t *, ec_master_t *)
Constructor.
Definition: device.c:62
uint8_t open
true, if the net_device has been opened
Definition: device.h:84
u64 tx_errors
Number of transmit errors.
Definition: device.h:111
u64 last_rx_bytes
Number of bytes received of last statistics cycle.
Definition: device.h:109
void ec_device_update_stats(ec_device_t *)
Update device statistics.
Definition: device.c:520
void ec_device_clear(ec_device_t *)
Destructor.
Definition: device.c:171
void ec_device_send(ec_device_t *, size_t)
Sends the content of the transmit socket buffer.
Definition: device.c:335
int ec_device_open(ec_device_t *)
Opens the EtherCAT device.
Definition: device.c:254
int ec_device_close(ec_device_t *)
Stops the EtherCAT device.
Definition: device.c:287
struct net_device * dev
pointer to the assigned net_device
Definition: device.h:81
EtherCAT master.
Definition: master.h:187
u64 tx_bytes
Number of bytes sent.
Definition: device.h:106
#define EC_MAX_DATA_SIZE
Resulting maximum data size of a single datagram in a frame.
Definition: globals.h:79