IgH EtherCAT Master  1.5.2
device.h
Go to the documentation of this file.
1 /******************************************************************************
2  *
3  * $Id$
4  *
5  * Copyright (C) 2006-2008 Florian Pose, Ingenieurgemeinschaft IgH
6  *
7  * This file is part of the IgH EtherCAT Master.
8  *
9  * The IgH EtherCAT Master is free software; you can redistribute it and/or
10  * modify it under the terms of the GNU General Public License version 2, as
11  * published by the Free Software Foundation.
12  *
13  * The IgH EtherCAT Master is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
16  * Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License along
19  * with the IgH EtherCAT Master; if not, write to the Free Software
20  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
21  *
22  * ---
23  *
24  * The license mentioned above concerns the source code only. Using the
25  * EtherCAT technology and brand is only permitted in compliance with the
26  * industrial property and similar rights of Beckhoff Automation GmbH.
27  *
28  *****************************************************************************/
29 
35 /*****************************************************************************/
36 
37 #ifndef __EC_DEVICE_H__
38 #define __EC_DEVICE_H__
39 
40 #include <linux/interrupt.h>
41 #include <linux/version.h>
42 
43 #include "../devices/ecdev.h"
44 #include "globals.h"
45 
52 #define EC_TX_RING_SIZE 0x10
53 
54 #ifdef EC_DEBUG_IF
55 #include "debug.h"
56 #endif
57 
58 #if LINUX_VERSION_CODE >= KERNEL_VERSION(5, 6, 0)
59 struct timeval {
60  __kernel_old_time_t tv_sec; /* seconds */
61  __kernel_suseconds_t tv_usec; /* microseconds */
62 };
63 #endif
64 
65 
66 #ifdef EC_DEBUG_RING
67 #define EC_DEBUG_RING_SIZE 10
68 
69 typedef enum {
70  TX, RX
71 } ec_debug_frame_dir_t;
72 
73 typedef struct {
74  ec_debug_frame_dir_t dir;
75  struct timeval t;
76  uint8_t data[EC_MAX_DATA_SIZE];
77  unsigned int data_size;
78 } ec_debug_frame_t;
79 
80 #endif
81 
82 /*****************************************************************************/
83 
90 struct ec_device
91 {
93  struct net_device *dev;
95  struct module *module;
96  uint8_t open;
97  uint8_t link_state;
98  struct sk_buff *tx_skb[EC_TX_RING_SIZE];
99  unsigned int tx_ring_index;
100 #ifdef EC_HAVE_CYCLES
101  cycles_t cycles_poll;
102 #endif
103 #if defined(EC_DEBUG_RING) || !defined(EC_RTDM)
104  struct timeval timeval_poll;
105 #endif
106  unsigned long jiffies_poll;
108  // Frame statistics
109  u64 tx_count;
111  u64 rx_count;
114  u64 tx_bytes;
116  u64 rx_bytes;
119  u64 tx_errors;
120  s32 tx_frame_rates[EC_RATE_COUNT];
123  s32 rx_frame_rates[EC_RATE_COUNT];
126  s32 tx_byte_rates[EC_RATE_COUNT];
128  s32 rx_byte_rates[EC_RATE_COUNT];
131 #ifdef EC_DEBUG_IF
132  ec_debug_t dbg;
133 #endif
134 #ifdef EC_DEBUG_RING
135  ec_debug_frame_t debug_frames[EC_DEBUG_RING_SIZE];
136  unsigned int debug_frame_index;
137  unsigned int debug_frame_count;
138 #endif
139 };
140 
141 /*****************************************************************************/
142 
147 typedef struct {
148  u32 magic_number; /* magic number */
149  u16 version_major; /* major version number */
150  u16 version_minor; /* minor version number */
151  s32 thiszone; /* GMT to local correction */
152  u32 sigfigs; /* accuracy of timestamps */
153  u32 snaplen; /* max length of captured packets, in octets */
154  u32 network; /* data link type */
155 } pcap_hdr_t;
156 
157 /*****************************************************************************/
158 
163 typedef struct {
164  u32 ts_sec; /* timestamp seconds */
165  u32 ts_usec; /* timestamp microseconds */
166  u32 incl_len; /* number of octets of packet saved in file */
167  u32 orig_len; /* actual length of packet */
168 } pcaprec_hdr_t;
169 
170 /*****************************************************************************/
171 
174 
175 void ec_device_attach(ec_device_t *, struct net_device *, ec_pollfunc_t,
176  struct module *);
178 
181 
183 uint8_t *ec_device_tx_data(ec_device_t *);
184 void ec_device_send(ec_device_t *, size_t);
187 
188 #ifdef EC_DEBUG_RING
189 void ec_device_debug_ring_append(ec_device_t *, ec_debug_frame_dir_t,
190  const void *, size_t);
191 void ec_device_debug_ring_print(const ec_device_t *);
192 #endif
193 
194 /*****************************************************************************/
195 
196 #endif
void ec_device_attach(ec_device_t *, struct net_device *, ec_pollfunc_t, struct module *)
Associate with net_device.
Definition: device.c:183
ec_pollfunc_t poll
pointer to the device&#39;s poll function
Definition: device.h:94
unsigned long jiffies_poll
jiffies of last poll
Definition: device.h:106
Network interface for debugging purposes.
u64 last_tx_count
Number of frames sent of last statistics cycle.
Definition: device.h:110
pcap packet header
Definition: device.h:163
#define EC_RATE_COUNT
Number of statistic rate intervals to maintain.
Definition: globals.h:71
uint8_t * ec_device_tx_data(ec_device_t *)
Returns a pointer to the device&#39;s transmit memory.
Definition: device.c:356
struct module * module
pointer to the device&#39;s owning module
Definition: device.h:95
Debugging network interface.
Definition: debug.h:46
uint8_t link_state
device link state
Definition: device.h:97
u64 rx_count
Number of frames received.
Definition: device.h:111
u64 last_tx_bytes
Number of bytes sent of last statistics cycle.
Definition: device.h:115
Global definitions and macros.
void ec_device_detach(ec_device_t *)
Disconnect from net_device.
Definition: device.c:214
#define EC_TX_RING_SIZE
Size of the transmit ring.
Definition: device.h:52
pcap global header
Definition: device.h:147
u64 last_rx_count
Number of frames received of last statistics cycle.
Definition: device.h:112
void(* ec_pollfunc_t)(struct net_device *)
Device poll function type.
Definition: ecdev.h:57
EtherCAT device.
Definition: device.h:90
unsigned int tx_ring_index
last ring entry used to transmit
Definition: device.h:99
void ec_device_poll(ec_device_t *)
Calls the poll function of the assigned net_device.
Definition: device.c:536
void ec_device_clear_stats(ec_device_t *)
Clears the frame statistics.
Definition: device.c:419
ec_master_t * master
EtherCAT master.
Definition: device.h:92
Definition: device.h:59
u64 rx_bytes
Number of bytes received.
Definition: device.h:116
u64 tx_count
Number of frames sent.
Definition: device.h:109
int ec_device_init(ec_device_t *, ec_master_t *)
Constructor.
Definition: device.c:64
uint8_t open
true, if the net_device has been opened
Definition: device.h:96
u64 tx_errors
Number of transmit errors.
Definition: device.h:119
u64 last_rx_bytes
Number of bytes received of last statistics cycle.
Definition: device.h:117
void ec_device_update_stats(ec_device_t *)
Update device statistics.
Definition: device.c:557
void ec_device_clear(ec_device_t *)
Destructor.
Definition: device.c:163
void ec_device_send(ec_device_t *, size_t)
Sends the content of the transmit socket buffer.
Definition: device.c:375
int ec_device_open(ec_device_t *)
Opens the EtherCAT device.
Definition: device.c:243
int ec_device_close(ec_device_t *)
Stops the EtherCAT device.
Definition: device.c:280
struct net_device * dev
pointer to the assigned net_device
Definition: device.h:93
EtherCAT master.
Definition: master.h:202
u64 tx_bytes
Number of bytes sent.
Definition: device.h:114
#define EC_MAX_DATA_SIZE
Resulting maximum data size of a single datagram in a frame.
Definition: globals.h:95