29#ifndef __EC_MASTER_H__
30#define __EC_MASTER_H__
32#include <linux/version.h>
33#include <linux/irq_work.h>
34#include <linux/list.h>
35#include <linux/timer.h>
36#include <linux/wait.h>
37#include <linux/kthread.h>
38#include <linux/rtmutex.h>
39#include <linux/workqueue.h>
62#define EC_MASTER_INFO(master, fmt, args...) \
63 printk(KERN_INFO "EtherCAT %u: " fmt, master->index, ##args)
74#define EC_MASTER_ERR(master, fmt, args...) \
75 printk(KERN_ERR "EtherCAT ERROR %u: " fmt, master->index, ##args)
86#define EC_MASTER_WARN(master, fmt, args...) \
87 printk(KERN_WARNING "EtherCAT WARNING %u: " fmt, master->index, ##args)
100#define EC_MASTER_DBG(master, level, fmt, args...) \
102 if (master->debug_level >= level) { \
103 printk(KERN_DEBUG "EtherCAT DEBUG %u: " fmt, \
104 master->index, ##args); \
113#define EC_EXT_RING_SIZE 32
117#define EC_MAX_MASTERS 32
177#if EC_MAX_NUM_DEVICES < 1
178#error Invalid number of devices
201 const uint8_t *
macs[EC_MAX_NUM_DEVICES];
202#if EC_MAX_NUM_DEVICES > 1
203 unsigned int num_devices;
315 const uint8_t *, dev_t,
struct class *,
unsigned int,
unsigned int);
320#if EC_MAX_NUM_DEVICES > 1
321#define ec_master_num_devices(MASTER) ((MASTER)->num_devices)
323#define ec_master_num_devices(MASTER) 1
340 const uint8_t *,
size_t);
374 uint16_t, uint32_t, uint32_t);
EtherCAT master character device.
EtherCAT device structure.
EtherCAT domain structure.
struct ec_device ec_device_t
Ethernet over EtherCAT (EoE)
EtherCAT master state machine.
struct ec_fsm_master ec_fsm_master_t
#define EC_RATE_COUNT
Number of statistic rate intervals to maintain.
struct ec_slave ec_slave_t
struct ec_master ec_master_t
struct ec_domain ec_domain_t
struct ec_slave_config ec_slave_config_t
const unsigned int rate_intervals[]
List of intervals for statistics [s].
void ec_master_set_send_interval(ec_master_t *, unsigned int)
Sets the expected interval between calls to ecrt_master_send and calculates the maximum amount of dat...
int ec_master_enter_operation_phase(ec_master_t *)
Transition function from IDLE to OPERATION phase.
ec_domain_t * ecrt_master_create_domain_err(ec_master_t *)
Same as ecrt_master_create_domain(), but with ERR_PTR() return value.
void ec_master_leave_operation_phase(ec_master_t *)
Transition function from OPERATION to IDLE phase.
unsigned int ec_master_domain_count(const ec_master_t *)
Get the number of domains.
void ec_master_init_static(void)
Static variables initializer.
const ec_domain_t * ec_master_find_domain_const(const ec_master_t *, unsigned int)
Get a domain via its position in the list.
void ec_master_leave_idle_phase(ec_master_t *)
Transition function from IDLE to ORPHANED phase.
ec_domain_t * ec_master_find_domain(ec_master_t *, unsigned int)
Get a domain via its position in the list.
unsigned int ec_master_config_count(const ec_master_t *)
Get the number of slave configurations provided by the application.
ec_slave_t * ec_master_find_slave(ec_master_t *, uint16_t, uint16_t)
Finds a slave in the bus, given the alias and position.
int ec_master_debug_level(ec_master_t *, unsigned int)
Set the debug level.
void ec_master_clear_eoe_handlers(ec_master_t *)
Clear and free all EoE handlers.
uint16_t ec_master_eoe_handler_count(const ec_master_t *)
Get the number of EoE handlers.
int ec_master_enter_idle_phase(ec_master_t *)
Transition function from ORPHANED to IDLE phase.
void ec_master_clear(ec_master_t *)
Destructor.
void ec_master_queue_datagram(ec_master_t *, ec_datagram_t *)
Places a datagram in the datagram queue.
const ec_slave_config_t * ec_master_get_config_const(const ec_master_t *, unsigned int)
Get a slave configuration via its position in the list.
#define EC_EXT_RING_SIZE
Size of the external datagram ring.
ec_slave_config_t * ecrt_master_slave_config_err(ec_master_t *, uint16_t, uint16_t, uint32_t, uint32_t)
Same as ecrt_master_slave_config(), but with ERR_PTR() return value.
void ec_master_clear_slaves(ec_master_t *)
Clear all slaves.
const ec_slave_t * ec_master_find_slave_const(const ec_master_t *, uint16_t, uint16_t)
Finds a slave in the bus, given the alias and position.
void ec_master_output_stats(ec_master_t *)
Output master statistics.
void ec_master_request_op(ec_master_t *)
Request OP state for configured slaves.
const ec_eoe_t * ec_master_get_eoe_handler_const(const ec_master_t *, uint16_t)
Get an EoE handler via its position in the list.
void ec_master_queue_datagram_ext(ec_master_t *, ec_datagram_t *)
Places a datagram in the non-application datagram queue.
void ec_master_attach_slave_configs(ec_master_t *)
Attaches the slave configurations to the slaves.
ec_slave_config_t * ec_master_get_config(const ec_master_t *, unsigned int)
Get a slave configuration via its position in the list.
void ec_master_calc_dc(ec_master_t *)
Distributed-clocks calculations.
void ec_master_eoe_stop(ec_master_t *)
Stops the Ethernet over EtherCAT processing.
void ec_master_internal_receive_cb(void *)
Internal receiving callback.
void ec_master_internal_send_cb(void *)
Internal sending callback.
void ec_master_eoe_start(ec_master_t *)
Starts Ethernet over EtherCAT processing on demand.
ec_master_phase_t
EtherCAT master phase.
@ EC_ORPHANED
Orphaned phase.
@ EC_OPERATION
Operation phase.
void ec_master_receive_datagrams(ec_master_t *, ec_device_t *, const uint8_t *, size_t)
Processes a received frame.
int ec_master_init(ec_master_t *, unsigned int, const uint8_t *, const uint8_t *, dev_t, struct class *, unsigned int, unsigned int)
Master constructor.
struct ec_rtdm_dev ec_rtdm_dev_t
EtherCAT RTDM device.
EtherCAT master character device.
s32 rx_byte_rates[EC_RATE_COUNT]
Receive rates in byte/s for different statistics cycle periods.
s32 loss_rates[EC_RATE_COUNT]
Frame loss rates for different statistics cycle periods.
u64 tx_count
Number of frames sent.
s32 rx_frame_rates[EC_RATE_COUNT]
Receive rates in frames/s for different statistics cycle periods.
u64 rx_bytes
Number of bytes received.
u64 last_loss
Tx/Rx difference of last statistics cycle.
u64 last_tx_bytes
Number of bytes sent of last statistics cycle.
u64 last_tx_count
Number of frames sent of last statistics cycle.
s32 tx_byte_rates[EC_RATE_COUNT]
Transmit rates in byte/s for different statistics cycle periods.
u64 tx_bytes
Number of bytes sent.
u64 rx_count
Number of frames received.
s32 tx_frame_rates[EC_RATE_COUNT]
Transmit rates in frames/s for different statistics cycle periods.
u64 last_rx_bytes
Number of bytes received of last statistics cycle.
u64 last_rx_count
Number of frames received of last statistics cycle.
unsigned long jiffies
Jiffies of last statistic cycle.
struct list_head datagram_queue
Datagram queue.
struct task_struct * eoe_thread
EoE thread.
struct work_struct sc_reset_work
Task to reset slave configuration.
unsigned int injection_seq_fsm
Datagram injection sequence number for the FSM side.
struct task_struct * thread
Master thread.
struct list_head eoe_handlers
Ethernet over EtherCAT handlers.
ec_datagram_t fsm_datagram
Datagram used for state machines.
struct list_head emerg_reg_requests
Emergency register access requests.
struct semaphore master_sem
Master semaphore.
struct list_head ext_datagram_queue
Queue for non-application datagrams.
ec_datagram_t sync_datagram
Datagram used for DC drift compensation.
size_t max_queue_size
Maximum size of datagram queue.
wait_queue_head_t request_queue
Wait queue for external requests from user space.
struct list_head fsm_exec_list
Slave FSM execution list.
struct list_head sii_requests
SII write requests.
ec_fsm_master_t fsm
Master state machine.
u64 app_time
Time of the last ecrt_master_sync() call.
wait_queue_head_t scan_queue
Queue for processes that wait for slave scanning.
unsigned int scan_busy
Current scan state.
unsigned int send_interval
Interval between two calls to ecrt_master_send().
unsigned int slave_count
Number of slaves on the bus.
void * app_cb_data
Application callback data.
void(* app_receive_cb)(void *)
Application's receive datagrams callback.
void(* receive_cb)(void *)
Current receive datagrams callback.
uint8_t datagram_index
Current datagram index.
unsigned int ext_ring_idx_fsm
Index in external datagram ring for FSM side.
ec_device_stats_t device_stats
Device statistics.
void(* send_cb)(void *)
Current send datagrams callback.
unsigned int config_busy
State of slave configuration.
ec_slave_t * dc_ref_clock
DC reference clock slave.
ec_datagram_t ref_sync_datagram
Datagram used for synchronizing the reference clock to the master clock.
struct list_head domains
List of domains.
struct semaphore config_sem
Semaphore protecting the config_busy variable and the allow_config flag.
unsigned int fsm_exec_count
Number of entries in execution list.
struct irq_work sc_reset_work_kicker
NMI-Safe kicker to trigger reset task above.
void(* app_send_cb)(void *)
Application's send datagrams callback.
u64 dc_ref_time
Common reference timestamp for DC start times.
ec_slave_t * fsm_slave
Slave that is queried next for FSM exec.
unsigned int injection_seq_rt
Datagram injection sequence number for the realtime side.
wait_queue_head_t config_queue
Queue for processes that wait for slave configuration.
struct semaphore scan_sem
Semaphore protecting the scan_busy variable and the allow_scan flag.
unsigned int run_on_cpu
bind kernel threads to this cpu
ec_datagram_t sync_mon_datagram
Datagram used for DC synchronisation monitoring.
struct rt_mutex io_mutex
Mutex used in IDLE and OP phase.
ec_slave_t * slaves
Array of slaves on the bus.
unsigned int active
Master has been activated.
unsigned int ext_ring_idx_rt
Index in external datagram ring for RT side.
unsigned int debug_level
Master debug level.
ec_stats_t stats
Cyclic statistics.
ec_slave_config_t * dc_ref_config
Application-selected DC reference clock slave config.
struct device * class_device
Master class device.
struct semaphore device_sem
Device semaphore.
ec_cdev_t cdev
Master character device.
unsigned int reserved
True, if the master is in use.
unsigned int allow_scan
True, if slave scanning is allowed.
unsigned int config_changed
The configuration changed.
struct list_head configs
List of slave configurations.
const uint8_t * macs[EC_MAX_NUM_DEVICES]
Device MAC addresses.
unsigned int scan_index
Index of slave currently scanned.
ec_datagram_t ext_datagram_ring[EC_EXT_RING_SIZE]
External datagram ring.
ec_master_phase_t phase
Master phase.
ec_device_t devices[EC_MAX_NUM_DEVICES]
EtherCAT devices.
void * cb_data
Current callback data.
struct semaphore ext_queue_sem
Semaphore protecting the ext_datagram_queue.
unsigned int corrupted
corrupted frames
unsigned long output_jiffies
time of last output
unsigned int timeouts
datagram timeouts
unsigned int unmatched
unmatched datagrams (received, but not queued any longer)