31 #include <linux/module.h> 32 #include <linux/kernel.h> 33 #include <linux/string.h> 34 #include <linux/slab.h> 35 #include <linux/delay.h> 36 #include <linux/device.h> 37 #include <linux/version.h> 38 #include <linux/hrtimer.h> 39 #include <linux/kthread.h> 50 #if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 11, 0) 51 #include <uapi/linux/sched/types.h> 52 #include <linux/sched/types.h> 57 #if LINUX_VERSION_CODE >= KERNEL_VERSION(3, 17, 0) || \ 58 (defined(CONFIG_PREEMPT_RT_FULL) && \ 59 LINUX_VERSION_CODE >= KERNEL_VERSION(3, 2, 0)) 60 # define ec_rt_lock_interruptible(lock) \ 61 rt_mutex_lock_interruptible(lock) 63 # define ec_rt_lock_interruptible(lock) \ 64 rt_mutex_lock_interruptible(lock, 0) 73 #define DEBUG_INJECT 0 77 #define FORCE_OUTPUT_CORRUPTED 0 80 #define EC_SDO_INJECTION_TIMEOUT 10000 83 #define EC_SII_CACHING_MASK \ 84 (EC_SII_VENDOR | EC_SII_PRODUCT | \ 85 EC_SII_REVISION | EC_SII_SERIAL | EC_SII_ALIAS) 91 static cycles_t timeout_cycles;
95 static cycles_t ext_injection_timeout_cycles;
138 void ec_master_nanosleep(
const unsigned long);
140 const ec_sii_page_t *, uint32_t, uint32_t, uint32_t, uint32_t,
142 static void sc_reset_task_kicker(
struct irq_work *work);
143 static void sc_reset_task(
struct work_struct *work);
151 #ifdef EC_HAVE_CYCLES 152 timeout_cycles = (cycles_t)
EC_IO_TIMEOUT * (cpu_khz / 1000);
153 ext_injection_timeout_cycles =
172 const uint8_t *main_mac,
173 const uint8_t *backup_mac,
182 unsigned int dev_idx, i;
184 master->
index = index;
189 for (dev_idx =
EC_DEVICE_MAIN; dev_idx < EC_MAX_NUM_DEVICES; dev_idx++) {
190 master->
macs[dev_idx] = NULL;
195 #if EC_MAX_NUM_DEVICES > 1 220 INIT_LIST_HEAD(&master->
configs);
221 INIT_LIST_HEAD(&master->
domains);
262 EC_MASTER_INFO(master,
"Initialising master with SII caching set to %u.",
294 goto out_clear_devices;
305 goto out_clear_devices;
317 " datagram %u.\n", i);
318 goto out_clear_ext_datagrams;
330 " synchronisation datagram.\n");
331 goto out_clear_ext_datagrams;
341 " synchronisation datagram.\n");
342 goto out_clear_ref_sync;
353 " monitoring datagram.\n");
366 goto out_clear_sync_mon;
370 "EtherCAT%u", master->
index);
381 goto out_unregister_class_device;
388 out_unregister_class_device:
399 out_clear_ext_datagrams:
406 for (; dev_idx > 0; dev_idx--) {
420 unsigned int dev_idx, i;
469 list_for_each_entry_safe(eoe, next, &master->
eoe_handlers, list) {
470 list_del(&eoe->
list);
485 list_for_each_entry_safe(page, next, &master->
sii_cache, list) {
486 list_del(&page->
list);
503 list_for_each_entry_safe(sc, next, &master->
configs, list) {
527 list_del_init(&request->
list);
530 request->
state = EC_INT_REQUEST_FAILURE;
538 for (slave = master->
slaves;
560 list_for_each_entry_safe(domain, next, &master->
domains, list) {
561 list_del(&domain->
list);
590 if (ec_rt_lock_interruptible(&master->
io_mutex))
605 if (ec_rt_lock_interruptible(&master->
io_mutex))
620 int (*thread_func)(
void *),
625 master->
thread = kthread_create(thread_func, master, name);
626 if (IS_ERR(master->
thread)) {
627 int err = (int) PTR_ERR(master->
thread);
628 EC_MASTER_ERR(master,
"Failed to start master thread (error %i)!\n",
639 (void) wake_up_process(master->
thread);
652 unsigned long sleep_jiffies;
661 kthread_stop(master->
thread);
670 sleep_jiffies = max(HZ / 100, 1);
671 schedule_timeout(sleep_jiffies);
755 " interrupted by signal.\n");
760 " configuration returned.\n");
773 ret = wait_event_interruptible(master->
scan_queue,
777 " interrupted by signal.\n");
782 " slave scan returned.\n");
786 for (slave = master->
slaves;
835 size_t queue_size = 0, new_queue_size = 0;
837 unsigned int datagram_count = 0;
852 EC_MASTER_DBG(master, 1,
"Injecting datagrams, queue_size=%zu\n",
866 new_queue_size = queue_size + datagram->
data_size;
867 if (new_queue_size <= master->max_queue_size) {
870 " size=%zu, queue_size=%zu\n", datagram->
name,
874 #ifdef EC_HAVE_CYCLES 875 datagram->cycles_sent = 0;
879 queue_size = new_queue_size;
884 " size=%zu, max_queue_size=%zu\n",
889 #ifdef EC_HAVE_CYCLES 890 cycles_t cycles_now = get_cycles();
892 if (cycles_now - datagram->cycles_sent
893 > ext_injection_timeout_cycles)
899 #if defined EC_RT_SYSLOG || DEBUG_INJECT 900 unsigned int time_us;
905 #if defined EC_RT_SYSLOG || DEBUG_INJECT 906 #ifdef EC_HAVE_CYCLES 907 time_us = (
unsigned int)
908 ((cycles_now - datagram->cycles_sent) * 1000LL)
911 time_us = (
unsigned int)
915 " external datagram %s size=%zu," 916 " max_queue_size=%zu\n", time_us, datagram->
name,
923 " external datagram %s size=%u, queue_size=%u\n",
935 EC_MASTER_DBG(master, 1,
"Injected %u datagrams.\n", datagram_count);
946 unsigned int send_interval
993 list_for_each_entry(queued_datagram, &master->
datagram_queue, queue) {
994 if (queued_datagram == datagram) {
998 "Datagram %p already queued (skipping).\n", datagram);
1036 size_t datagram_size;
1037 uint8_t *frame_data, *cur_data = NULL;
1039 #ifdef EC_HAVE_CYCLES 1040 cycles_t cycles_start, cycles_sent, cycles_end;
1042 unsigned long jiffies_sent;
1043 unsigned int frame_count, more_datagrams_waiting;
1044 struct list_head sent_datagrams;
1046 #ifdef EC_HAVE_CYCLES 1047 cycles_start = get_cycles();
1050 INIT_LIST_HEAD(&sent_datagrams);
1053 __func__, device_index);
1057 follows_word = NULL;
1058 more_datagrams_waiting = 0;
1077 if (cur_data - frame_data + datagram_size > ETH_DATA_LEN) {
1078 more_datagrams_waiting = 1;
1082 list_add_tail(&datagram->
sent, &sent_datagrams);
1100 follows_word = cur_data + 6;
1112 if (list_empty(&sent_datagrams)) {
1122 while (cur_data - frame_data < ETH_ZLEN - ETH_HLEN)
1125 EC_MASTER_DBG(master, 2,
"frame size: %zu\n", cur_data - frame_data);
1129 cur_data - frame_data);
1130 #ifdef EC_HAVE_CYCLES 1131 cycles_sent = get_cycles();
1133 jiffies_sent = jiffies;
1136 list_for_each_entry_safe(datagram, next, &sent_datagrams, sent) {
1137 #ifdef EC_HAVE_CYCLES 1138 datagram->cycles_sent = cycles_sent;
1141 list_del_init(&datagram->
sent);
1147 while (more_datagrams_waiting);
1149 #ifdef EC_HAVE_CYCLES 1151 cycles_end = get_cycles();
1153 " sent %u frames in %uus.\n", __func__, frame_count,
1154 (
unsigned int) (cycles_end - cycles_start) * 1000 / cpu_khz);
1169 const uint8_t *data,
1173 if (!mbox_data->
data) {
1181 memcpy(mbox_data->
data, data, size);
1195 const uint8_t *data,
1197 uint16_t slave_addr,
1198 uint16_t offset_addr
1215 for (slave = master->
slaves;
1216 slave < master->slaves + master->
slave_count; slave++) {
1224 " slave address: %u\n", slave_addr);
1242 switch (mbox_prot) {
1244 case EC_MBOX_TYPE_EOE:
1248 case EC_MBOX_TYPE_COE:
1251 case EC_MBOX_TYPE_FOE:
1254 case EC_MBOX_TYPE_SOE:
1257 case EC_MBOX_TYPE_VOE:
1262 " from slave: %u Protocol: %u\n", slave_addr, mbox_prot);
1266 if (smp_load_acquire(&mbox_data->
payload_size) && printk_ratelimit()) {
1267 EC_SLAVE_WARN(slave,
"Overwriting unfetched mailbox message of" 1268 " protocol 0x%02X.\n", mbox_prot);
1272 if (ret == -ENOENT) {
1273 if (printk_ratelimit()) {
1275 " 0x%02X, which is not supported by the slave.\n",
1279 }
else if (ret == -EOVERFLOW) {
1280 if (printk_ratelimit()) {
1282 " 0x%02X, which exceeds the buffer size" 1283 " (%zu > %zu bytes).\n",
1303 const uint8_t *frame_data,
1307 size_t frame_size, data_size;
1308 uint8_t datagram_type, datagram_index;
1309 uint16_t datagram_slave_addr, datagram_offset_addr;
1310 unsigned int cmd_follows, matched;
1311 const uint8_t *cur_data;
1317 " on %s (size %zu < %u byte):\n",
1328 cur_data = frame_data;
1334 if (unlikely(frame_size > size)) {
1337 " on %s (invalid frame size %zu for " 1338 "received size %zu):\n", device->
dev->name,
1350 while (cmd_follows) {
1360 if (unlikely(cur_data - frame_data
1364 " on %s (invalid data size %zu):\n",
1365 device->
dev->name, data_size);
1378 if (datagram->
index == datagram_index
1380 && datagram->
type == datagram_type
1399 #ifdef EC_DEBUG_RING 1416 datagram_slave_addr, datagram_offset_addr)) {
1417 memcpy(datagram->
data, cur_data, data_size);
1420 cur_data += data_size;
1427 #ifdef EC_HAVE_CYCLES 1428 datagram->cycles_received =
1435 list_del_init(&datagram->
queue);
1516 s32 tx_frame_rate, rx_frame_rate, tx_byte_rate, rx_byte_rate, loss_rate;
1518 unsigned int i, dev_idx;
1521 if (likely(jiffies - s->
jiffies < HZ)) {
1530 loss_rate = (loss - s->
last_loss) * 1000;
1561 #ifdef EC_USE_HRTIMER 1566 static enum hrtimer_restart ec_master_nanosleep_wakeup(
struct hrtimer *timer)
1568 struct hrtimer_sleeper *t =
1569 container_of(timer,
struct hrtimer_sleeper, timer);
1570 struct task_struct *task = t->task;
1574 wake_up_process(task);
1576 return HRTIMER_NORESTART;
1581 void ec_master_nanosleep(
const unsigned long nsecs)
1583 struct hrtimer_sleeper t;
1584 enum hrtimer_mode mode = HRTIMER_MODE_REL;
1586 #if LINUX_VERSION_CODE >= KERNEL_VERSION(6, 15, 0) 1587 hrtimer_setup(&t.timer, ec_master_nanosleep_wakeup,
1588 CLOCK_MONOTONIC, mode);
1590 hrtimer_init(&t.timer, CLOCK_MONOTONIC, mode);
1591 t.timer.function = ec_master_nanosleep_wakeup;
1594 hrtimer_set_expires(&t.timer, ktime_set(0, nsecs));
1597 set_current_state(TASK_INTERRUPTIBLE);
1598 hrtimer_start(&t.timer, hrtimer_get_expires(&t.timer), mode);
1600 if (likely(t.task)) {
1604 hrtimer_cancel(&t.timer);
1605 mode = HRTIMER_MODE_ABS;
1606 }
while (t.task && !signal_pending(current));
1609 #endif // EC_USE_HRTIMER 1621 unsigned int count = 0;
1623 list_for_each_entry_safe(fsm, next, &master->
fsm_exec_list, list) {
1627 list_del_init(&fsm->
list);
1644 " slave FSM execution. This is a bug!\n");
1665 list_del_init(&fsm->
list);
1675 && count < master->slave_count) {
1689 " consumed datagram %s, now %u FSMs in list.\n",
1712 #ifdef EC_USE_HRTIMER 1719 EC_MASTER_DBG(master, 1,
"Idle thread running with send interval = %u us," 1723 while (!kthread_should_stop()) {
1727 if (ec_rt_lock_interruptible(&master->
io_mutex))
1730 rt_mutex_unlock(&master->
io_mutex);
1733 if (down_interruptible(&master->
master_sem)) {
1744 if (ec_rt_lock_interruptible(&master->
io_mutex))
1750 #ifdef EC_USE_HRTIMER 1754 rt_mutex_unlock(&master->
io_mutex);
1757 #ifdef EC_USE_HRTIMER 1760 set_current_state(TASK_INTERRUPTIBLE);
1761 schedule_timeout(1);
1764 #ifdef EC_USE_HRTIMER 1772 EC_MASTER_DBG(master, 1,
"Master IDLE thread exiting...\n");
1784 unsigned int seq_rt;
1787 " with fsm interval = %u us, max data size=%zu\n",
1790 while (!kthread_should_stop()) {
1801 if (down_interruptible(&master->
master_sem)) {
1818 #ifdef EC_USE_HRTIMER 1823 set_current_state(TASK_INTERRUPTIBLE);
1824 schedule_timeout(1);
1841 static inline void set_normal_priority(
struct task_struct *p,
int nice)
1843 #if LINUX_VERSION_CODE >= KERNEL_VERSION(5, 9, 0) 1844 sched_set_normal(p, nice);
1846 struct sched_param param = { .sched_priority = 0 };
1847 sched_setscheduler(p, SCHED_NORMAL, ¶m);
1848 set_user_nice(p, nice);
1868 " because of missing callbacks!\n");
1877 EC_MASTER_ERR(master,
"Failed to start EoE thread (error %i)!\n",
1909 unsigned int none_open, sth_to_send, all_idle;
1913 while (!kthread_should_stop()) {
1917 list_for_each_entry(eoe, &master->
eoe_handlers, list) {
1933 list_for_each_entry(eoe, &master->
eoe_handlers, list) {
1944 list_for_each_entry(eoe, &master->
eoe_handlers, list) {
1953 set_current_state(TASK_INTERRUPTIBLE);
1954 schedule_timeout(1);
1976 list_for_each_entry(sc, &master->
configs, list) {
1986 #define EC_FIND_SLAVE \ 1989 for (; slave < master->slaves + master->slave_count; \ 1991 if (slave->effective_alias == alias) \ 1994 if (slave == master->slaves + master->slave_count) \ 1998 slave += position; \ 1999 if (slave < master->slaves + master->slave_count) { \ 2052 list_for_each_entry(sc, &master->
configs, list) {
2056 #ifdef EC_IDENT_WILDCARDS 2087 unsigned int count = 0;
2089 list_for_each_entry(sc, &master->
configs, list) {
2101 #define EC_FIND_CONFIG \ 2103 list_for_each_entry(sc, &master->configs, list) { \ 2150 unsigned int count = 0;
2152 list_for_each_entry(domain, &master->
domains, list) {
2164 #define EC_FIND_DOMAIN \ 2166 list_for_each_entry(domain, &master->domains, list) { \ 2216 unsigned int count = 0;
2218 list_for_each_entry(eoe, &master->
eoe_handlers, list) {
2240 list_for_each_entry(eoe, &master->
eoe_handlers, list) {
2308 for (slave = master->
slaves;
2321 EC_MASTER_INFO(master,
"Using slave %u as DC reference clock.\n",
2327 unsigned int upstream_dc = 0;
2329 for (slave = master->
slaves; slave < ref; slave++) {
2334 " but is in front of the reference clock and" 2335 " will not receive cyclic time" 2336 " distribution!\n");
2343 " the reference clock will not receive cyclic time" 2344 " distribution.\n", upstream_dc);
2369 unsigned int *slave_position
2373 unsigned int port_index;
2383 while (port_index != 0) {
2385 *slave_position = *slave_position + 1;
2386 if (*slave_position < master->slave_count) {
2388 master->
slaves + *slave_position;
2390 slave, slave_position);
2399 port_index = next_table[port_index];
2413 unsigned int slave_position = 0;
2419 EC_MASTER_ERR(master,
"Failed to calculate bus topology.\n");
2432 for (slave = master->
slaves;
2484 slave = master->
slaves + i;
2506 uint32_t product_code,
2536 (!alias || cached_page->
alias != alias)) {
2552 uint32_t product_code,
2559 list_for_each_entry(cached_page, &master->
sii_cache, list) {
2561 vendor_id, product_code, revision, serial, alias)) {
2599 list_for_each_entry(cached_page, &master->
sii_cache, list) {
2610 "Caching SII page for 0x%08X / 0x%08X / 0x%08X / 0x%08X / %u\n",
2616 EC_MASTER_ERR(master,
"Error allocating SII page memory!\n");
2648 EC_MASTER_DBG(master, 1,
"%s(master = 0x%p)\n", __func__, master);
2653 return ERR_PTR(-ENOMEM);
2658 if (list_empty(&master->
domains)) {
2662 index = last_domain->
index + 1;
2682 return IS_ERR(d) ? NULL : d;
2689 uint32_t domain_offset;
2693 int eoe_was_running;
2696 EC_MASTER_DBG(master, 1,
"%s(master = 0x%p)\n", __func__, master);
2699 EC_MASTER_WARN(master,
"%s: Master already active!\n", __func__);
2707 list_for_each_entry(domain, &master->
domains, list) {
2711 EC_MASTER_ERR(master,
"Failed to finish domain 0x%p!\n", domain);
2723 eoe_was_running = master->
eoe_thread != NULL;
2737 if (eoe_was_running) {
2766 int eoe_was_running;
2769 EC_MASTER_DBG(master, 1,
"%s(master = 0x%p)\n", __func__, master);
2778 eoe_was_running = master->
eoe_thread != NULL;
2788 for (slave = master->
slaves;
2802 list_for_each_entry(eoe, &master->
eoe_handlers, list) {
2812 if (eoe_was_running) {
2835 unsigned int seq_fsm;
2851 list_for_each_entry_safe(datagram, n,
2854 list_del_init(&datagram->
queue);
2881 unsigned int dev_idx;
2892 list_for_each_entry_safe(datagram, next, &master->
datagram_queue, queue) {
2895 #ifdef EC_HAVE_CYCLES 2897 datagram->cycles_sent > timeout_cycles) {
2902 list_del_init(&datagram->
queue);
2910 unsigned int time_us;
2911 #ifdef EC_HAVE_CYCLES 2912 time_us = (
unsigned int)
2914 datagram->cycles_sent) * 1000 / cpu_khz;
2916 time_us = (
unsigned int)
2921 " index %02X waited %u us.\n",
2922 datagram, datagram->
index, time_us);
2954 uint16_t alias, uint16_t position, uint32_t vendor_id,
2955 uint32_t product_code)
2958 unsigned int found = 0;
2960 EC_MASTER_DBG(master, 1,
"ecrt_master_slave_config(master = 0x%p," 2961 " alias = %u, position = %u, vendor_id = 0x%08x," 2962 " product_code = 0x%08x)\n",
2963 master, alias, position, vendor_id, product_code);
2965 list_for_each_entry(sc, &master->
configs, list) {
2975 " configured as 0x%08X/0x%08X before. Now configuring" 2977 vendor_id, product_code);
2978 return ERR_PTR(-ENOENT);
2981 EC_MASTER_DBG(master, 1,
"Creating slave configuration for %u:%u," 2982 " 0x%08X/0x%08X.\n",
2983 alias, position, vendor_id, product_code);
2988 " for slave configuration.\n");
2989 return ERR_PTR(-ENOMEM);
2993 alias, position, vendor_id, product_code);
3011 uint16_t alias, uint16_t position, uint32_t vendor_id,
3012 uint32_t product_code)
3015 position, vendor_id, product_code);
3016 return IS_ERR(sc) ? NULL : sc;
3025 __func__, master, sc);
3027 if (down_interruptible(&master->
master_sem)) {
3048 " master_info = 0x%p)\n", __func__, master, master_info);
3062 EC_MASTER_DBG(master, 1,
"%s(master = 0x%p, progress = 0x%p)\n",
3063 __func__, master, progress);
3079 if (down_interruptible(&master->
master_sem)) {
3085 if (slave == NULL) {
3123 slave_info->
name[0] = 0;
3135 void (*send_cb)(
void *),
void (*receive_cb)(
void *),
void *cb_data)
3138 " send_cb = 0x%p, receive_cb = 0x%p, cb_data = 0x%p)\n",
3139 __func__, master, send_cb, receive_cb, cb_data);
3283 uint16_t index, uint8_t subindex,
const uint8_t *data,
3284 size_t data_size, uint32_t *abort_code)
3291 " slave_position = %u, index = 0x%04X, subindex = 0x%02X," 3292 " data = 0x%p, data_size = %zu, abort_code = 0x%p)\n",
3293 __func__, master, slave_position, index, subindex,
3294 data, data_size, abort_code);
3304 memcpy(request.
data, data, data_size);
3308 if (down_interruptible(&master->
master_sem)) {
3315 EC_MASTER_ERR(master,
"Slave %u does not exist!\n", slave_position);
3320 EC_SLAVE_DBG(slave, 1,
"Scheduling SDO download request.\n");
3329 request.
state != EC_INT_REQUEST_QUEUED)) {
3332 if (request.
state == EC_INT_REQUEST_QUEUED) {
3333 list_del(&request.
list);
3347 if (request.
state == EC_INT_REQUEST_SUCCESS) {
3349 }
else if (request.
errno) {
3350 ret = -request.
errno;
3362 uint16_t slave_position, uint16_t index,
const uint8_t *data,
3363 size_t data_size, uint32_t *abort_code)
3370 " slave_position = %u, index = 0x%04X," 3371 " data = 0x%p, data_size = %zu, abort_code = 0x%p)\n",
3372 __func__, master, slave_position, index, data, data_size,
3384 memcpy(request.
data, data, data_size);
3388 if (down_interruptible(&master->
master_sem)) {
3395 EC_MASTER_ERR(master,
"Slave %u does not exist!\n", slave_position);
3400 EC_SLAVE_DBG(slave, 1,
"Scheduling SDO download request" 3401 " (complete access).\n");
3410 request.
state != EC_INT_REQUEST_QUEUED)) {
3413 if (request.
state == EC_INT_REQUEST_QUEUED) {
3414 list_del(&request.
list);
3428 if (request.
state == EC_INT_REQUEST_SUCCESS) {
3430 }
else if (request.
errno) {
3431 ret = -request.
errno;
3443 uint16_t index, uint8_t subindex, uint8_t *target,
3444 size_t target_size,
size_t *result_size, uint32_t *abort_code)
3451 " slave_position = %u, index = 0x%04X, subindex = 0x%02X," 3452 " target = 0x%p, target_size = %zu, result_size = 0x%p," 3453 " abort_code = 0x%p)\n",
3454 __func__, master, slave_position, index, subindex,
3455 target, target_size, result_size, abort_code);
3461 if (down_interruptible(&master->
master_sem)) {
3469 EC_MASTER_ERR(master,
"Slave %u does not exist!\n", slave_position);
3473 EC_SLAVE_DBG(slave, 1,
"Scheduling SDO upload request.\n");
3482 request.
state != EC_INT_REQUEST_QUEUED)) {
3485 if (request.
state == EC_INT_REQUEST_QUEUED) {
3486 list_del(&request.
list);
3500 if (request.
state != EC_INT_REQUEST_SUCCESS) {
3502 if (request.
errno) {
3503 ret = -request.
errno;
3509 EC_SLAVE_ERR(slave,
"%s(): Buffer too small.\n", __func__);
3526 uint8_t drive_no, uint16_t idn,
const uint8_t *data,
size_t data_size,
3527 uint16_t *error_code)
3548 memcpy(request.
data, data, data_size);
3552 if (down_interruptible(&master->
master_sem)) {
3565 EC_SLAVE_DBG(slave, 1,
"Scheduling SoE write request.\n");
3574 request.
state != EC_INT_REQUEST_QUEUED)) {
3577 if (request.
state == EC_INT_REQUEST_QUEUED) {
3579 list_del(&request.
list);
3593 ret = request.
state == EC_INT_REQUEST_SUCCESS ? 0 : -EIO;
3602 uint8_t drive_no, uint16_t idn, uint8_t *target,
size_t target_size,
3603 size_t *result_size, uint16_t *error_code)
3619 if (down_interruptible(&master->
master_sem)) {
3627 EC_MASTER_ERR(master,
"Slave %u does not exist!\n", slave_position);
3631 EC_SLAVE_DBG(slave, 1,
"Scheduling SoE read request.\n");
3640 request.
state != EC_INT_REQUEST_QUEUED)) {
3643 if (request.
state == EC_INT_REQUEST_QUEUED) {
3644 list_del(&request.
list);
3660 if (request.
state != EC_INT_REQUEST_SUCCESS) {
3667 EC_SLAVE_ERR(slave,
"%s(): Buffer too small.\n", __func__);
3689 list_for_each_entry(sc, &master->
configs, list) {
3709 EC_MASTER_DBG(master, 1,
"Setting SII caching fields to %u.\n",
3723 static void sc_reset_task_kicker(
struct irq_work *work)
3732 static void sc_reset_task(
struct work_struct *work)
uint8_t * data
Mailbox response data.
void ec_eoe_queue(ec_eoe_t *eoe)
Queues the datagram, if necessary.
unsigned int injection_seq_fsm
Datagram injection sequence number for the FSM side.
uint32_t serial_number
Serial-Number stored on the slave.
#define EC_IO_TIMEOUT
Datagram timeout in microseconds.
ec_slave_port_desc_t desc
Physical port type.
uint16_t error_code
SoE error code.
unsigned int reserved
True, if the master is in use.
struct list_head ext_datagram_queue
Queue for non-application datagrams.
int ec_mac_is_zero(const uint8_t *)
uint16_t ring_position
Ring position.
uint32_t revision_number
Revision number.
unsigned long jiffies_sent
Jiffies, when the datagram was sent.
void ec_master_clear_config(ec_master_t *)
Clear the configuration applied by the application.
ec_datagram_t * ec_master_get_external_datagram(ec_master_t *)
Searches for a free datagram in the external datagram ring.
#define EC_ADDR_LEN
Size of the EtherCAT address field.
uint16_t ec_slave_sdo_count(const ec_slave_t *slave)
Get the number of SDOs in the dictionary.
int ecrt_master_deactivate(ec_master_t *master)
Deactivates the master.
void ec_soe_request_set_idn(ec_soe_request_t *req, uint16_t idn)
Set IDN.
int ec_sii_page_copy(ec_sii_page_t *page, const ec_sii_page_t *from)
Copy contents from other page.
int ec_rtdm_dev_init(ec_rtdm_dev_t *rtdm_dev, ec_master_t *master)
Initialize an RTDM device.
#define EC_DATAGRAM_NAME_SIZE
Size of the datagram description string.
ec_sii_t sii
Extracted SII data.
struct sk_buff * tx_skb[EC_TX_RING_SIZE]
transmit skb ring
size_t data_size
Size of the data in data.
struct semaphore config_sem
Semaphore protecting the config_busy variable and the allow_config flag.
void ec_slave_config_init(ec_slave_config_t *sc, ec_master_t *master, uint16_t alias, uint16_t position, uint32_t vendor_id, uint32_t product_code)
Slave configuration constructor.
ec_sii_page_origin_t origin
Page origin.
uint8_t sync_count
Number of sync managers.
void ec_master_calc_dc(ec_master_t *master)
Distributed-clocks calculations.
int ecrt_master_sii_caching(ec_master_t *master, ec_sii_caching_fields_t fields)
Set the SII caching method.
int ecrt_sdo_request_write(ec_sdo_request_t *req)
Schedule an SDO write operation.
uint16_t configured_tx_mailbox_size
Configured send mailbox size.
int ecrt_master_link_state(const ec_master_t *master, unsigned int dev_idx, ec_master_link_state_t *state)
Reads the current state of a redundant link.
unsigned int fsm_exec_count
Number of entries in execution list.
unsigned int num_devices
Number of devices.
u64 last_loss
Tx/Rx difference of last statistics cycle.
u64 tx_count
Number of frames sent.
const unsigned int rate_intervals[]
List of intervals for statistics [s].
uint8_t error_flag
Error flag for that slave.
void ec_master_clear(ec_master_t *master)
Destructor.
struct list_head sii_requests
SII write requests.
#define EC_SLAVE_DBG(slave, level, fmt, args...)
Convenience macro for printing slave-specific debug messages to syslog.
int ecrt_master_send(ec_master_t *master)
Sends all datagrams in the queue.
size_t data_size
Size of the process data.
unsigned long jiffies_poll
jiffies of last poll
ec_slave_t * slave
pointer to the corresponding slave
void ec_master_queue_datagram_ext(ec_master_t *master, ec_datagram_t *datagram)
Places a datagram in the non-application datagram queue.
OP (mailbox communication and input/output update)
s32 tx_byte_rates[EC_RATE_COUNT]
Transmit rates in byte/s for different statistics cycle periods.
int ecrt_master_scan_progress(ec_master_t *master, ec_master_scan_progress_t *progress)
Obtains network scan progress information.
uint16_t configured_tx_mailbox_offset
Configured send mailbox offset.
ec_internal_request_state_t state
State of the request.
ec_slave_config_t * ec_master_get_config(const ec_master_t *master, unsigned int pos)
Get a slave configuration via its position in the list.
int ec_eoe_holds_mbox_lock(const ec_eoe_t *eoe)
Returns, if the handler holds the mailbox read lock of its slave.
unsigned int slaves_responding[EC_MAX_NUM_DEVICES]
Number of responding slaves for every device.
ec_slave_port_t ports[EC_MAX_PORTS]
Ports.
void ec_fsm_master_reset(ec_fsm_master_t *fsm)
Reset state machine.
void ec_master_request_op(ec_master_t *master)
Request OP state for configured slaves.
static int ec_master_eoe_thread(void *)
Does the Ethernet over EtherCAT processing.
int ec_fsm_slave_is_ready(const ec_fsm_slave_t *fsm)
Returns, if the FSM is currently not busy and ready to execute.
unsigned int slave_count
Number of slaves in the network.
ec_slave_state_t current_state
Current application state.
void ec_master_leave_operation_phase(ec_master_t *master)
Transition function from OPERATION to IDLE phase.
int ecrt_master_sdo_download_complete(ec_master_t *master, uint16_t slave_position, uint16_t index, const uint8_t *data, size_t data_size, uint32_t *abort_code)
Executes an SDO download request to write data to a slave via complete access.
ec_domain_t * ecrt_master_create_domain(ec_master_t *master)
Creates a new process data domain.
#define ec_master_num_devices(MASTER)
Number of Ethernet devices.
#define EC_RATE_COUNT
Number of statistic rate intervals to maintain.
ec_datagram_t sync_mon_datagram
Datagram used for DC synchronisation monitoring.
EtherCAT slave structure.
ec_internal_request_state_t state
SDO request state.
uint32_t vendor_id
Vendor-ID stored on the slave.
void ec_device_clear(ec_device_t *device)
Destructor.
struct list_head list
List item.
ec_mbox_data_t mbox_foe_data
Received mailbox data for FoE.
int ec_master_cached_sii_page_matches(const ec_master_t *, const ec_sii_page_t *, uint32_t, uint32_t, uint32_t, uint32_t, uint16_t)
Check if a cached SII page is matching the caching criteria.
struct list_head eoe_handlers
Ethernet over EtherCAT handlers.
uint32_t product_code
Slave product code.
ec_slave_port_link_t link
Port link state.
static unsigned int sii_caching
SII Caching mode.
unsigned int slaves_responding
Sum of responding slaves on the given link.
int ec_master_thread_start(ec_master_t *, int(*)(void *), const char *)
Starts the master thread.
dev_t device_number
Device number for master cdevs.
ec_slave_port_link_t link
Port link status.
unsigned int allow_scan
True, if slave scanning is allowed.
int ecrt_master_sync_reference_clock(ec_master_t *master)
Queues the DC reference clock drift compensation datagram for sending.
size_t max_queue_size
Maximum size of datagram queue.
void ec_master_internal_receive_cb(void *cb_data)
Internal receiving callback.
uint16_t position
Index after alias.
#define EC_SLAVE_WARN(slave, fmt, args...)
Convenience macro for printing slave-specific warnings to syslog.
static int ec_master_operation_thread(void *)
Master kernel thread function for OPERATION phase.
EtherCAT mailbox response data.
int ecrt_sdo_request_read(ec_sdo_request_t *req)
Schedule an SDO read operation.
const ec_slave_t * ec_master_find_slave_const(const ec_master_t *master, uint16_t alias, uint16_t position)
Finds a slave in the bus, given the alias and position.
#define EC_FRAME_HEADER_SIZE
Size of an EtherCAT frame header.
#define EC_SII_CACHING_MASK
SII caching mask (combination of valid flags).
void ecrt_master_callbacks(ec_master_t *master, void(*send_cb)(void *), void(*receive_cb)(void *), void *cb_data)
Sets the locking callbacks.
Not used by its state machine in this cycle and not to be queued.
struct list_head list
List item.
uint32_t serial_number
Serial number.
struct list_head fsm_exec_list
Slave FSM execution list.
Master scan progress information.
const ec_domain_t * ec_master_find_domain_const(const ec_master_t *master, unsigned int index)
Get a domain via its position in the list.
const ec_eoe_t * ec_master_get_eoe_handler_const(const ec_master_t *master, uint16_t index)
Get an EoE handler via its position in the list.
#define EC_WRITE_U8(DATA, VAL)
Write an 8-bit unsigned value to EtherCAT data.
unsigned int scan_index
Index of slave currently scanned.
uint32_t abort_code
SDO request abort code.
u64 dc_ref_time
Common reference timestamp for DC start times.
ec_slave_state_t slave_states[EC_MAX_NUM_DEVICES]
AL states of responding slaves for every device.
struct list_head emerg_reg_requests
Emergency register access requests.
char name[EC_DATAGRAM_NAME_SIZE]
Description of the datagram.
uint16_t alias
Slave alias.
void ec_master_send_datagrams(ec_master_t *, ec_device_index_t)
Sends the datagrams in the queue for a certain device.
void ec_device_update_stats(ec_device_t *device)
Update device statistics.
struct list_head domains
List of domains.
void ec_slave_calc_transmission_delays_rec(ec_slave_t *slave, ec_slave_t *came_from, uint32_t *delay)
Recursively calculates transmission delays.
ec_mbox_data_t mbox_eoe_data
Received mailbox data for EoE.
Finite state machine of an EtherCAT slave.
ec_datagram_t * datagram
Previous state datagram.
unsigned int link_up
true, if the given Ethernet link is up.
uint32_t delay_to_next_dc
Delay [ns] to next DC slave.
ec_fsm_slave_t fsm
Slave state machine.
#define EC_FIND_CONFIG
Common implementation for ec_master_get_config() and ec_master_get_config_const().
uint16_t working_counter
Working counter.
uint8_t * data
Pointer to SDO data.
unsigned long jiffies
Jiffies of last statistic cycle.
ec_slave_config_t * ec_master_find_config_for_slave(ec_master_t *master, const ec_slave_t *slave)
Finds the slave configuration that will be attached to the given slave.
int16_t current_on_ebus
Power consumption in mA.
ec_slave_t * ec_master_find_slave(ec_master_t *master, uint16_t alias, uint16_t position)
Finds a slave in the bus, given the alias and position.
uint8_t link_state
device link state
static unsigned int debug_level
Debug level parameter.
u64 last_rx_count
Number of frames received of last statistics cycle.
uint8_t signal_detected
Detected signal on RX port.
const uint8_t * macs[EC_MAX_NUM_DEVICES]
Device MAC addresses.
Sent (still in the queue).
uint16_t alias
Configured station alias.
unsigned int slaves_responding
Sum of responding slaves on all Ethernet devices.
size_t data_size
Size of SDO data.
Configured Address Physical Read.
wait_queue_head_t request_queue
Wait queue for external requests from user space.
void ec_master_clear_device_stats(ec_master_t *)
Clears the common device statistics.
unsigned int run_on_cpu
Bind kernel threads to this cpu.
uint16_t station_address
Configured station address.
int ec_soe_request_write(ec_soe_request_t *req)
Request a write operation.
unsigned int sync_count
Number of sync managers.
struct list_head list
List head.
void ec_slave_clear(ec_slave_t *slave)
Slave destructor.
ec_domain_t * ecrt_master_create_domain_err(ec_master_t *master)
Same as ecrt_master_create_domain(), but with ERR_PTR() return value.
unsigned int link_up
true, if the network link is up.
void ec_datagram_output_stats(ec_datagram_t *datagram)
Outputs datagram statistics at most every second.
int ecrt_master_write_idn(ec_master_t *master, uint16_t slave_position, uint8_t drive_no, uint16_t idn, const uint8_t *data, size_t data_size, uint16_t *error_code)
Executes an SoE write request.
int ec_master_enter_idle_phase(ec_master_t *master)
Transition function from ORPHANED to IDLE phase.
ec_datagram_type_t type
Datagram type (APRD, BWR, etc.).
const ec_slave_config_t * ec_master_get_config_const(const ec_master_t *master, unsigned int pos)
Get a slave configuration via its position in the list.
Global definitions and macros.
uint32_t revision_number
Revision-Number stored on the slave.
EtherCAT master structure.
void * cb_data
Current callback data.
void ec_device_send(ec_device_t *device, size_t size)
Sends the content of the transmit socket buffer.
int ecrt_master_reference_clock_time(const ec_master_t *master, uint32_t *time)
Get the lower 32 bit of the reference clock system time.
void ec_fsm_master_init(ec_fsm_master_t *fsm, ec_master_t *master, ec_datagram_t *datagram)
Constructor.
Initial state of a new datagram.
#define EC_MASTER_DBG(master, level, fmt, args...)
Convenience macro for printing master-specific debug messages to syslog.
ec_slave_t * fsm_slave
Slave that is queried next for FSM exec.
unsigned int send_interval
Interval between two calls to ecrt_master_send().
ec_slave_t * slave
EtherCAT slave.
Definitions of Kernel SMP macros.
struct semaphore master_sem
Master semaphore.
uint8_t loop_closed
Loop closed.
ec_sii_page_t * ec_master_find_cached_sii_page(const ec_master_t *master, uint32_t vendor_id, uint32_t product_code, uint32_t revision, uint32_t serial, uint16_t alias)
Find a matching cached SII page.
uint8_t datagram_index
Current datagram index.
void ec_master_attach_slave_configs(ec_master_t *master)
Attaches the slave configurations to the slaves.
struct list_head datagram_queue
Datagram queue.
int ecrt_master_sync_reference_clock_to(ec_master_t *master, uint64_t sync_time)
Queues the DC reference clock drift compensation datagram for sending.
ec_slave_t * slave
slave the FSM runs on
char name[EC_MAX_STRING_LENGTH]
Name of the slave.
void ec_sdo_request_clear(ec_sdo_request_t *req)
SDO request destructor.
struct irq_work sc_reset_work_kicker
NMI-Safe kicker to trigger reset task above.
struct task_struct * eoe_thread
EoE thread.
struct list_head sdo_requests
SDO access requests.
int ecrt_sdo_request_index(ec_sdo_request_t *req, uint16_t index, uint8_t subindex)
Set the SDO index and subindex.
unsigned int unmatched
unmatched datagrams (received, but not queued any longer)
unsigned int ext_ring_idx_fsm
Index in external datagram ring for FSM side.
void ec_datagram_zero(ec_datagram_t *datagram)
Fills the datagram payload memory with zeros.
int ec_master_debug_level(ec_master_t *master, unsigned int level)
Set the debug level.
s32 tx_frame_rates[EC_RATE_COUNT]
Transmit rates in frames/s for different statistics cycle periods.
uint64_t app_time
Application time.
s32 rx_byte_rates[EC_RATE_COUNT]
Receive rates in byte/s for different statistics cycle periods.
Ethernet over EtherCAT (EoE)
struct list_head soe_requests
SoE requests.
#define EC_DATAGRAM_HEADER_SIZE
Size of an EtherCAT datagram header.
ec_datagram_state_t state
State.
ec_device_stats_t device_stats
Device statistics.
ec_datagram_t fsm_datagram
Datagram used for state machines.
ec_slave_config_t * config
Current configuration.
ec_master_phase_t phase
Master phase.
#define EC_WRITE_U32(DATA, VAL)
Write a 32-bit unsigned value to EtherCAT data.
Slave information interface memory page.
ec_slave_t * slaves
Array of slaves on the bus.
int ec_master_cache_sii_page(ec_master_t *master, const ec_sii_page_t *page)
Add an SII page to the cache.
uint32_t revision_number
Revision number.
void ec_domain_clear(ec_domain_t *domain)
Domain destructor.
void ec_soe_request_set_drive_no(ec_soe_request_t *req, uint8_t drive_no)
Set drive number.
void ec_slave_calc_port_delays(ec_slave_t *slave)
Calculates the port transmission delays.
int ec_domain_finish(ec_domain_t *domain, uint32_t base_address)
Finishes a domain.
static unsigned long ext_injection_timeout_jiffies
Timeout for external datagram injection [jiffies].
struct semaphore device_sem
Device semaphore.
int ec_eoe_is_idle(const ec_eoe_t *eoe)
Returns the idle state.
ec_domain_t * ec_master_find_domain(ec_master_t *master, unsigned int index)
Get a domain via its position in the list.
int ecrt_master_application_time(ec_master_t *master, uint64_t app_time)
Sets the application time.
unsigned int tx_ring_index
last ring entry used to transmit
size_t data_size
Size of the mailbox response data buffer.
unsigned int timeouts
datagram timeouts
ec_sdo_request_t * sdo_request
SDO request to process.
unsigned int debug_level
Master debug level.
int ec_datagram_frmw(ec_datagram_t *datagram, uint16_t configured_address, uint16_t mem_address, size_t data_size)
Initializes an EtherCAT FRMW datagram.
#define EC_SLAVE_ERR(slave, fmt, args...)
Convenience macro for printing slave-specific errors to syslog.
unsigned int ec_master_domain_count(const ec_master_t *master)
Get the number of domains.
struct list_head ext_queue
External datagram queue item, protected by ext_queue_sem.
s32 loss_rates[EC_RATE_COUNT]
Frame loss rates for different statistics cycle periods.
unsigned int corrupted
corrupted frames
struct list_head list
List item.
u64 last_tx_count
Number of frames sent of last statistics cycle.
uint32_t transmission_delay
DC system time transmission delay (offset from reference clock).
void ec_master_exec_slave_fsms(ec_master_t *)
Execute slave FSMs.
void ec_soe_request_clear(ec_soe_request_t *req)
SoE request destructor.
unsigned int ext_ring_idx_rt
Index in external datagram ring for RT side.
struct rt_mutex io_mutex
Mutex used in IDLE and OP phase.
unsigned int slave_count
Number of slaves on the bus.
unsigned int scan_busy
Current scan state.
ec_device_index_t
Master devices.
void(* receive_cb)(void *)
Current receive datagrams callback.
uint16_t dc_assign_activate
Vendor-specific AssignActivate word.
s32 rx_frame_rates[EC_RATE_COUNT]
Receive rates in frames/s for different statistics cycle periods.
int ecrt_master_read_idn(ec_master_t *master, uint16_t slave_position, uint8_t drive_no, uint16_t idn, uint8_t *target, size_t target_size, size_t *result_size, uint16_t *error_code)
Executes an SoE read request.
#define EC_WRITE_U16(DATA, VAL)
Write a 16-bit unsigned value to EtherCAT data.
unsigned int index
Index (just a number).
static int ec_master_mbox_store(ec_mbox_data_t *mbox_data, const uint8_t *data, size_t size)
Stores a received mailbox response in a protocol-specific buffer.
void ec_master_leave_idle_phase(ec_master_t *master)
Transition function from IDLE to ORPHANED phase.
unsigned int skip_count
Number of requeues when not yet received.
ec_slave_config_t * ecrt_master_slave_config(ec_master_t *master, uint16_t alias, uint16_t position, uint32_t vendor_id, uint32_t product_code)
Obtains a slave configuration.
#define EC_READ_U32(DATA)
Read a 32-bit unsigned value from EtherCAT data.
int ec_device_init(ec_device_t *device, ec_master_t *master)
Constructor.
ec_slave_port_desc_t desc
Port descriptors.
#define EC_MASTER_WARN(master, fmt, args...)
Convenience macro for printing master-specific warnings to syslog.
int ec_fsm_slave_exec(ec_fsm_slave_t *fsm, ec_datagram_t *datagram)
Executes the current state of the state machine.
unsigned int active
Master has been activated.
struct list_head sent
Master list item for sent datagrams.
int ec_datagram_brd(ec_datagram_t *datagram, uint16_t mem_address, size_t data_size)
Initializes an EtherCAT BRD datagram.
int ec_datagram_fpwr(ec_datagram_t *datagram, uint16_t configured_address, uint16_t mem_address, size_t data_size)
Initializes an EtherCAT FPWR datagram.
int ec_master_enter_operation_phase(ec_master_t *master)
Transition function from IDLE to OPERATION phase.
uint8_t has_dc_system_time
The slave supports the DC system time register.
wait_queue_head_t scan_queue
Queue for processes that wait for slave scanning.
uint32_t vendor_id
Vendor ID.
ec_datagram_t sync_datagram
Datagram used for DC drift compensation.
int ecrt_master_send_ext(ec_master_t *master)
Sends non-application datagrams.
#define EC_MASTER_ERR(master, fmt, args...)
Convenience macro for printing master-specific errors to syslog.
int ecrt_master_select_reference_clock(ec_master_t *master, ec_slave_config_t *sc)
Selects the reference clock for distributed clocks.
struct device * class_device
Master class device.
EtherCAT datagram structure.
void ec_master_queue_datagram(ec_master_t *master, ec_datagram_t *datagram)
Places a datagram in the datagram queue.
int ec_slave_config_attach(ec_slave_config_t *sc)
Attaches the configuration to the addressed slave object.
int ecrt_master_sync_monitor_queue(ec_master_t *master)
Queues the DC synchrony monitoring datagram for sending.
static int ec_master_idle_thread(void *)
Master kernel thread function for IDLE phase.
struct list_head configs
List of slave configurations.
ec_slave_t * slave
Slave pointer.
ec_slave_config_t * dc_ref_config
Application-selected DC reference clock slave config.
ec_device_index_t device_index
Device via which the datagram shall be / was sent.
int ec_soe_request_alloc(ec_soe_request_t *req, size_t size)
Pre-allocates the data memory.
int ecrt_master(ec_master_t *master, ec_master_info_t *master_info)
Obtains master information.
int ec_fsm_master_idle(const ec_fsm_master_t *fsm)
void ec_master_clear_slaves(ec_master_t *master)
Clear all slaves.
struct list_head list
list item
uint8_t * ec_device_tx_data(ec_device_t *device)
Returns a pointer to the device's transmit memory.
u64 last_rx_bytes
Number of bytes received of last statistics cycle.
unsigned long output_jiffies
time of last output
ec_stats_t stats
Cyclic statistics.
void ec_print_data(const uint8_t *, size_t)
Outputs frame contents for debugging purposes.
uint8_t valid_mbox_data
Received mailbox data is valid.
void ec_master_update_device_stats(ec_master_t *)
Updates the common device statistics.
struct semaphore scan_sem
Semaphore protecting the scan_busy variable and the allow_scan flag.
int ecrt_master_get_slave(ec_master_t *master, uint16_t slave_position, ec_slave_info_t *slave_info)
Obtains slave information.
int ec_datagram_prealloc(ec_datagram_t *datagram, size_t size)
Allocates internal payload memory.
static unsigned int run_on_cpu
Bind created kernel threads to a cpu.
uint16_t effective_alias
Effective alias address.
void ec_sii_page_clear(ec_sii_page_t *page)
Slave destructor.
void ec_master_calc_transmission_delays(ec_master_t *)
Calculates the bus transmission delays.
void ec_master_clear_eoe_handlers(ec_master_t *master)
Clear and free all EoE handlers.
uint8_t al_state
Current state of the slave.
unsigned int sii_caching
SII caching mode.
size_t data_size
Size of SDO data.
uint8_t scan_busy
true, while the master is scanning the network.
#define EC_READ_U16(DATA)
Read a 16-bit unsigned value from EtherCAT data.
void ec_master_eoe_start(ec_master_t *master)
Starts Ethernet over EtherCAT processing on demand.
u64 tx_bytes
Number of bytes sent.
void(* app_send_cb)(void *)
Application's send datagrams callback.
void * app_cb_data
Application callback data.
uint16_t ec_master_eoe_handler_count(const ec_master_t *master)
Get the number of EoE handlers.
int16_t current_on_ebus
Used current in mA.
void ec_master_clear_slave_configs(ec_master_t *)
Clear all slave configurations.
int ec_soe_request_read(ec_soe_request_t *req)
Request a read operation.
void ec_master_clear_domains(ec_master_t *)
Clear all domains.
void ec_master_find_dc_ref_clock(ec_master_t *)
Finds the DC reference clock.
struct list_head list
Used for execution list.
void ec_master_thread_stop(ec_master_t *)
Stops the master thread.
void ec_sdo_request_init(ec_sdo_request_t *req)
SDO request constructor.
#define EC_MAX_PORTS
Maximum number of slave ports.
struct list_head sii_cache
List of cached SII pages.
#define EC_SDO_INJECTION_TIMEOUT
SDO injection timeout in microseconds.
int ecrt_master_sdo_download(ec_master_t *master, uint16_t slave_position, uint16_t index, uint8_t subindex, const uint8_t *data, size_t data_size, uint32_t *abort_code)
Executes an SDO download request to write data to a slave.
struct ec_slave_info_t::@7 ports[EC_MAX_PORTS]
Port information.
ec_datagram_t ext_datagram_ring[EC_EXT_RING_SIZE]
External datagram ring.
uint16_t sdo_count
Number of SDOs.
struct list_head list
List item.
#define EC_MAX_STRING_LENGTH
Maximum string length.
uint32_t product_code
Vendor-specific product code.
void ec_datagram_init(ec_datagram_t *datagram)
Constructor.
static unsigned long timeout_jiffies
Frame timeout in jiffies.
void ec_rtdm_dev_clear(ec_rtdm_dev_t *rtdm_dev)
Clear an RTDM device.
void ec_cdev_clear(ec_cdev_t *cdev)
Destructor.
ec_slave_t * next_slave
Connected slaves.
unsigned int link_up
true, if at least one Ethernet link is up.
uint32_t vendor_id
Slave vendor ID.
uint32_t receive_time
Port receive times for delay measurement.
wait_queue_head_t config_queue
Queue for processes that wait for slave configuration.
#define EC_EXT_RING_SIZE
Size of the external datagram ring.
void ec_master_internal_send_cb(void *cb_data)
Internal sending callback.
int ec_master_calc_topology_rec(ec_master_t *, ec_slave_t *, unsigned int *)
Calculates the bus topology; recursion function.
unsigned int scan_index
Index of the slave that is currently scanned.
uint16_t next_slave
Ring position of next DC slave on that port.
void ec_master_calc_topology(ec_master_t *)
Calculates the bus topology.
u64 app_time
Time of the last ecrt_master_sync() call.
void ec_slave_request_state(ec_slave_t *slave, ec_slave_state_t state)
Request a slave state and resets the error flag.
ec_mbox_data_t mbox_voe_data
Received mailbox data for VoE.
ec_datagram_t ref_sync_datagram
Datagram used for synchronizing the reference clock to the master clock.
void ec_master_output_stats(ec_master_t *master)
Output master statistics.
void ec_sii_page_init(ec_sii_page_t *page)
SII page constructor.
uint8_t base_dc_supported
Distributed clocks are supported.
#define EC_FIND_DOMAIN
Common implementation for ec_master_find_domain() and ec_master_find_domain_const().
u64 rx_count
Number of frames received.
static int ec_master_mbox_dispatch(ec_master_t *master, const uint8_t *data, size_t size, uint16_t slave_addr, uint16_t offset_addr)
Common mailbox dispatcher for mailboxes read via the station address.
unsigned int al_states
Application-layer states of all slaves.
int ecrt_master_activate(ec_master_t *master)
Finishes the configuration phase and prepares for cyclic operation.
struct work_struct sc_reset_work
Task to reset slave configuration.
uint8_t * data
Datagram payload.
#define EC_FIND_SLAVE
Common implementation for ec_master_find_slave() and ec_master_find_slave_const().
struct semaphore ext_queue_sem
Semaphore protecting the ext_datagram_queue.
#define EC_BYTE_TRANSMISSION_TIME_NS
Time to send a byte in nanoseconds.
uint16_t alias
The slaves alias if not equal to 0.
void ec_eoe_run(ec_eoe_t *eoe)
Runs the EoE state machine.
#define EC_READ_U8(DATA)
Read an 8-bit unsigned value from EtherCAT data.
EtherCAT slave configuration.
struct list_head queue
Master datagram queue item, protected by user-supplied mutex.
uint32_t product_code
Product-Code stored on the slave.
int ecrt_master_receive(ec_master_t *master)
Fetches received frames from the hardware and processes the datagrams.
EtherCAT device structure.
void(* app_receive_cb)(void *)
Application's receive datagrams callback.
unsigned int slave_count
Number of slaves detected.
struct net_device * dev
pointer to the assigned net_device
int ec_fsm_master_exec(ec_fsm_master_t *fsm)
Executes the current state of the state machine.
uint32_t ecrt_master_sync_monitor_process(const ec_master_t *master)
Processes the DC synchrony monitoring datagram.
void ec_soe_request_init(ec_soe_request_t *req)
SoE request constructor.
EtherCAT slave configuration structure.
ec_slave_config_t * ecrt_master_slave_config_err(ec_master_t *master, uint16_t alias, uint16_t position, uint32_t vendor_id, uint32_t product_code)
Same as ecrt_master_slave_config(), but with ERR_PTR() return value.
void ec_device_poll(ec_device_t *device)
Calls the poll function of the assigned net_device.
void ec_eoe_clear(ec_eoe_t *eoe)
EoE destructor.
unsigned int ec_master_config_count(const ec_master_t *master)
Get the number of slave configurations provided by the application.
Error while sending/receiving (dequeued).
Auto Increment Physical Write.
uint8_t address[EC_ADDR_LEN]
Recipient address.
u64 last_tx_bytes
Number of bytes sent of last statistics cycle.
int ec_sdo_request_alloc(ec_sdo_request_t *req, size_t size)
Pre-allocates the data memory.
uint32_t product_code
Vendor-specific product code.
void ec_domain_init(ec_domain_t *domain, ec_master_t *master, unsigned int index)
Domain constructor.
PREOP state (mailbox communication, no IO)
void ec_slave_config_clear(ec_slave_config_t *sc)
Slave configuration destructor.
int ec_master_init(ec_master_t *master, unsigned int index, const uint8_t *main_mac, const uint8_t *backup_mac, dev_t device_number, struct class *class, unsigned int debug_level, unsigned int run_on_cpu, unsigned int sii_caching)
Master constructor.
uint32_t serial_number
Serial number.
Ethernet over EtherCAT (EoE) handler.
ec_fsm_master_t fsm
Master state machine.
ec_cdev_t cdev
Master character device.
u64 rx_bytes
Number of bytes received.
#define EC_DATAGRAM_FOOTER_SIZE
Size of an EtherCAT datagram footer.
unsigned int al_states
Application-layer states of the slaves on the given link.
#define EC_MASTER_INFO(master, fmt, args...)
Convenience macro for printing master-specific information to syslog.
unsigned int error_flag
Stop processing after an error.
uint16_t position
Offset of the slave in the ring.
struct list_head list
List item (for cache).
uint32_t receive_time
Receive time on DC transmission delay measurement.
unsigned int config_changed
The configuration changed.
unsigned int injection_seq_rt
Datagram injection sequence number for the realtime side.
void ec_master_receive_datagrams(ec_master_t *master, ec_device_t *device, const uint8_t *frame_data, size_t size)
Processes a received frame.
Configured Address Physical Write.
#define FORCE_OUTPUT_CORRUPTED
Always output corrupted frames.
void ec_master_clear_sii_cache(ec_master_t *)
Clear SII page cache.
uint8_t index
Index (set by master).
uint8_t link_up
Link detected.
ec_sii_caching_fields_t
Fields for SII caching.
ec_device_t devices[EC_MAX_NUM_DEVICES]
EtherCAT devices.
void ec_slave_config_load_default_sync_config(ec_slave_config_t *sc)
Loads the default PDO assignment from the slave object.
ec_internal_request_state_t state
Request state.
unsigned int config_busy
State of slave configuration.
void ec_master_inject_external_datagrams(ec_master_t *)
Injects external datagrams that fit into the datagram queue.
int ecrt_master_sync_slave_clocks(ec_master_t *master)
Queues the DC clock drift compensation datagram for sending.
void ec_fsm_master_clear(ec_fsm_master_t *fsm)
Destructor.
int ecrt_master_state(const ec_master_t *master, ec_master_state_t *state)
Reads the current master state.
int ec_eoe_is_open(const ec_eoe_t *eoe)
Returns the state of the device.
void ec_device_clear_stats(ec_device_t *device)
Clears the frame statistics.
Sercos-over-EtherCAT request.
void ec_master_set_send_interval(ec_master_t *master, unsigned int send_interval)
Sets the expected interval between calls to ecrt_master_send and calculates the maximum amount of dat...
unsigned long jiffies_received
Jiffies, when the datagram was received.
int ecrt_master_reset(ec_master_t *master)
Retry configuring slaves.
uint8_t * data
Pointer to SDO data.
ec_mbox_data_t mbox_coe_data
Received mailbox data for CoE.
ec_mbox_data_t mbox_soe_data
Received mailbox data for SoE.
size_t payload_size
Size of the mailbox response payload data.
void ec_master_eoe_stop(ec_master_t *master)
Stops the Ethernet over EtherCAT processing.
void(* send_cb)(void *)
Current send datagrams callback.
int ecrt_master_sdo_upload(ec_master_t *master, uint16_t slave_position, uint16_t index, uint8_t subindex, uint8_t *target, size_t target_size, size_t *result_size, uint32_t *abort_code)
Executes an SDO upload request to read data from a slave.
uint32_t vendor_id
Vendor ID.
uint8_t complete_access
SDO shall be transferred completely.
uint32_t delay_to_next_dc
Delay to next slave with DC support behind this port [ns].
struct task_struct * thread
Master thread.
unsigned int queue_datagram
the datagram is ready for queuing
ec_slave_t * dc_ref_clock
DC reference clock slave.
int ec_cdev_init(ec_cdev_t *cdev, ec_master_t *master, dev_t dev_num)
Constructor.
unsigned int force_config
Force (re-)configuration.
#define EC_MAX_DATA_SIZE
Resulting maximum data size of a single datagram in a frame.
void ec_master_init_static(void)
Static variables initializer.
void ec_datagram_clear(ec_datagram_t *datagram)
Destructor.