master/ioctl.c
author Edouard Tisserant <edouard.tisserant@gmail.com>
Mon, 08 Oct 2018 23:16:34 +0200
branchstable-1.5
changeset 2726 ca80d6dac4c8
parent 2719 94c9657e0bee
permissions -rw-r--r--
devices/rtdmnet.c : abuse RTDM api to allow sendmsg and recvmsg to be called indirectly from userland cobalt process ioctl, while rtdm_socket is created from a kernel thread.
2433
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     1
/******************************************************************************
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     2
 *
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     3
 *  $Id$
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     4
 *
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     5
 *  Copyright (C) 2006-2012  Florian Pose, Ingenieurgemeinschaft IgH
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     6
 *
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     7
 *  This file is part of the IgH EtherCAT Master.
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     8
 *
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     9
 *  The IgH EtherCAT Master is free software; you can redistribute it and/or
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    10
 *  modify it under the terms of the GNU General Public License version 2, as
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    11
 *  published by the Free Software Foundation.
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    12
 *
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    13
 *  The IgH EtherCAT Master is distributed in the hope that it will be useful,
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    14
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    15
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    16
 *  Public License for more details.
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    17
 *
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    18
 *  You should have received a copy of the GNU General Public License along
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    19
 *  with the IgH EtherCAT Master; if not, write to the Free Software
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    20
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    21
 *
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    22
 *  ---
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    23
 *
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    24
 *  The license mentioned above concerns the source code only. Using the
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    25
 *  EtherCAT technology and brand is only permitted in compliance with the
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    26
 *  industrial property and similar rights of Beckhoff Automation GmbH.
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    27
 *
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    28
 *****************************************************************************/
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    29
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    30
/**
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    31
   \file
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    32
   EtherCAT master character device.
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    33
*/
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    34
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    35
/*****************************************************************************/
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    36
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    37
#include <linux/module.h>
2483
ec53d873dc5e Added vmalloc() include fix for ARM architecture, thanks to Andrea Scian.
Florian Pose <fp@igh-essen.com>
parents: 2481
diff changeset
    38
#include <linux/vmalloc.h>
2433
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    39
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    40
#include "master.h"
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    41
#include "slave_config.h"
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    42
#include "voe_handler.h"
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    43
#include "ethernet.h"
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    44
#include "ioctl.h"
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    45
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    46
/** Set to 1 to enable ioctl() latency tracing.
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    47
 *
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    48
 * Requires CPU timestamp counter!
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    49
 */
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    50
#define DEBUG_LATENCY 0
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    51
2522
ec403cf308eb Updated Doxygen documentation.
Florian Pose <fp@igh-essen.com>
parents: 2505
diff changeset
    52
/** Optional compiler attributes fo ioctl() functions.
ec403cf308eb Updated Doxygen documentation.
Florian Pose <fp@igh-essen.com>
parents: 2505
diff changeset
    53
 */
2481
c99ff159b60d Added function attribute definition.
Florian Pose <fp@igh-essen.com>
parents: 2477
diff changeset
    54
#if 0
c99ff159b60d Added function attribute definition.
Florian Pose <fp@igh-essen.com>
parents: 2477
diff changeset
    55
#define ATTRIBUTES __attribute__ ((__noinline__))
c99ff159b60d Added function attribute definition.
Florian Pose <fp@igh-essen.com>
parents: 2477
diff changeset
    56
#else
c99ff159b60d Added function attribute definition.
Florian Pose <fp@igh-essen.com>
parents: 2477
diff changeset
    57
#define ATTRIBUTES
c99ff159b60d Added function attribute definition.
Florian Pose <fp@igh-essen.com>
parents: 2477
diff changeset
    58
#endif
c99ff159b60d Added function attribute definition.
Florian Pose <fp@igh-essen.com>
parents: 2477
diff changeset
    59
2719
94c9657e0bee Xenomai 2 to 3 migration says "RTDM drivers implementing differentiated ioctl() support for both domains should serve all real-time only requests from ioctl_rt(), returning -ENOSYS for any unrecognized request, which will cause the adaptive switch to take place automatically to the ioctl_nrt() handler. The ioctl_nrt() should then implement all requests which may be valid from the regular Linux domain exclusively."
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2712
diff changeset
    60
#ifndef EC_IOCTL_RTDM
94c9657e0bee Xenomai 2 to 3 migration says "RTDM drivers implementing differentiated ioctl() support for both domains should serve all real-time only requests from ioctl_rt(), returning -ENOSYS for any unrecognized request, which will cause the adaptive switch to take place automatically to the ioctl_nrt() handler. The ioctl_nrt() should then implement all requests which may be valid from the regular Linux domain exclusively."
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2712
diff changeset
    61
#define ec_copy_to_user copy_to_user
94c9657e0bee Xenomai 2 to 3 migration says "RTDM drivers implementing differentiated ioctl() support for both domains should serve all real-time only requests from ioctl_rt(), returning -ENOSYS for any unrecognized request, which will cause the adaptive switch to take place automatically to the ioctl_nrt() handler. The ioctl_nrt() should then implement all requests which may be valid from the regular Linux domain exclusively."
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2712
diff changeset
    62
#define ec_copy_from_user copy_from_user
94c9657e0bee Xenomai 2 to 3 migration says "RTDM drivers implementing differentiated ioctl() support for both domains should serve all real-time only requests from ioctl_rt(), returning -ENOSYS for any unrecognized request, which will cause the adaptive switch to take place automatically to the ioctl_nrt() handler. The ioctl_nrt() should then implement all requests which may be valid from the regular Linux domain exclusively."
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2712
diff changeset
    63
#else
94c9657e0bee Xenomai 2 to 3 migration says "RTDM drivers implementing differentiated ioctl() support for both domains should serve all real-time only requests from ioctl_rt(), returning -ENOSYS for any unrecognized request, which will cause the adaptive switch to take place automatically to the ioctl_nrt() handler. The ioctl_nrt() should then implement all requests which may be valid from the regular Linux domain exclusively."
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2712
diff changeset
    64
/* RTDM provides rtdm_copy_{to,from}_user but they need fd argument 
94c9657e0bee Xenomai 2 to 3 migration says "RTDM drivers implementing differentiated ioctl() support for both domains should serve all real-time only requests from ioctl_rt(), returning -ENOSYS for any unrecognized request, which will cause the adaptive switch to take place automatically to the ioctl_nrt() handler. The ioctl_nrt() should then implement all requests which may be valid from the regular Linux domain exclusively."
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2712
diff changeset
    65
   for no good reason. This is is just a shortcut to real call */
94c9657e0bee Xenomai 2 to 3 migration says "RTDM drivers implementing differentiated ioctl() support for both domains should serve all real-time only requests from ioctl_rt(), returning -ENOSYS for any unrecognized request, which will cause the adaptive switch to take place automatically to the ioctl_nrt() handler. The ioctl_nrt() should then implement all requests which may be valid from the regular Linux domain exclusively."
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2712
diff changeset
    66
#define ec_copy_to_user __copy_to_user_inatomic
94c9657e0bee Xenomai 2 to 3 migration says "RTDM drivers implementing differentiated ioctl() support for both domains should serve all real-time only requests from ioctl_rt(), returning -ENOSYS for any unrecognized request, which will cause the adaptive switch to take place automatically to the ioctl_nrt() handler. The ioctl_nrt() should then implement all requests which may be valid from the regular Linux domain exclusively."
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2712
diff changeset
    67
#define ec_copy_from_user __copy_from_user_inatomic
94c9657e0bee Xenomai 2 to 3 migration says "RTDM drivers implementing differentiated ioctl() support for both domains should serve all real-time only requests from ioctl_rt(), returning -ENOSYS for any unrecognized request, which will cause the adaptive switch to take place automatically to the ioctl_nrt() handler. The ioctl_nrt() should then implement all requests which may be valid from the regular Linux domain exclusively."
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2712
diff changeset
    68
#endif
94c9657e0bee Xenomai 2 to 3 migration says "RTDM drivers implementing differentiated ioctl() support for both domains should serve all real-time only requests from ioctl_rt(), returning -ENOSYS for any unrecognized request, which will cause the adaptive switch to take place automatically to the ioctl_nrt() handler. The ioctl_nrt() should then implement all requests which may be valid from the regular Linux domain exclusively."
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2712
diff changeset
    69
94c9657e0bee Xenomai 2 to 3 migration says "RTDM drivers implementing differentiated ioctl() support for both domains should serve all real-time only requests from ioctl_rt(), returning -ENOSYS for any unrecognized request, which will cause the adaptive switch to take place automatically to the ioctl_nrt() handler. The ioctl_nrt() should then implement all requests which may be valid from the regular Linux domain exclusively."
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2712
diff changeset
    70
2433
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    71
/*****************************************************************************/
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    72
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    73
/** Copies a string to an ioctl structure.
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    74
 */
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    75
static void ec_ioctl_strcpy(
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    76
        char *target, /**< Target. */
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    77
        const char *source /**< Source. */
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    78
        )
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    79
{
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    80
    if (source) {
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    81
        strncpy(target, source, EC_IOCTL_STRING_SIZE);
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    82
        target[EC_IOCTL_STRING_SIZE - 1] = 0;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    83
    } else {
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    84
        target[0] = 0;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    85
    }
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    86
}
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    87
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    88
/*****************************************************************************/
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    89
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    90
/** Get module information.
2522
ec403cf308eb Updated Doxygen documentation.
Florian Pose <fp@igh-essen.com>
parents: 2505
diff changeset
    91
 *
ec403cf308eb Updated Doxygen documentation.
Florian Pose <fp@igh-essen.com>
parents: 2505
diff changeset
    92
 * \return Zero on success, otherwise a negative error code.
2433
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    93
 */
2481
c99ff159b60d Added function attribute definition.
Florian Pose <fp@igh-essen.com>
parents: 2477
diff changeset
    94
static ATTRIBUTES int ec_ioctl_module(
2433
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    95
        void *arg /**< Userspace address to store the results. */
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    96
        )
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    97
{
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    98
    ec_ioctl_module_t data;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    99
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   100
    data.ioctl_version_magic = EC_IOCTL_VERSION_MAGIC;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   101
    data.master_count = ec_master_count();
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   102
2719
94c9657e0bee Xenomai 2 to 3 migration says "RTDM drivers implementing differentiated ioctl() support for both domains should serve all real-time only requests from ioctl_rt(), returning -ENOSYS for any unrecognized request, which will cause the adaptive switch to take place automatically to the ioctl_nrt() handler. The ioctl_nrt() should then implement all requests which may be valid from the regular Linux domain exclusively."
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2712
diff changeset
   103
    if (ec_copy_to_user((void __user *) arg, &data, sizeof(data)))
2433
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   104
        return -EFAULT;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   105
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   106
    return 0;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   107
}
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   108
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   109
/*****************************************************************************/
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   110
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   111
/** Get master information.
2522
ec403cf308eb Updated Doxygen documentation.
Florian Pose <fp@igh-essen.com>
parents: 2505
diff changeset
   112
 *
ec403cf308eb Updated Doxygen documentation.
Florian Pose <fp@igh-essen.com>
parents: 2505
diff changeset
   113
 * \return Zero on success, otherwise a negative error code.
2433
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   114
 */
2481
c99ff159b60d Added function attribute definition.
Florian Pose <fp@igh-essen.com>
parents: 2477
diff changeset
   115
static ATTRIBUTES int ec_ioctl_master(
2433
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   116
        ec_master_t *master, /**< EtherCAT master. */
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   117
        void *arg /**< Userspace address to store the results. */
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   118
        )
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   119
{
2453
d461b1f07296 Added configure option for redundancy (--with-devices).
Florian Pose <fp@igh-essen.com>
parents: 2447
diff changeset
   120
    ec_ioctl_master_t io;
d461b1f07296 Added configure option for redundancy (--with-devices).
Florian Pose <fp@igh-essen.com>
parents: 2447
diff changeset
   121
    unsigned int dev_idx, j;
d461b1f07296 Added configure option for redundancy (--with-devices).
Florian Pose <fp@igh-essen.com>
parents: 2447
diff changeset
   122
d461b1f07296 Added configure option for redundancy (--with-devices).
Florian Pose <fp@igh-essen.com>
parents: 2447
diff changeset
   123
    if (down_interruptible(&master->master_sem)) {
2433
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   124
        return -EINTR;
2453
d461b1f07296 Added configure option for redundancy (--with-devices).
Florian Pose <fp@igh-essen.com>
parents: 2447
diff changeset
   125
    }
d461b1f07296 Added configure option for redundancy (--with-devices).
Florian Pose <fp@igh-essen.com>
parents: 2447
diff changeset
   126
d461b1f07296 Added configure option for redundancy (--with-devices).
Florian Pose <fp@igh-essen.com>
parents: 2447
diff changeset
   127
    io.slave_count = master->slave_count;
d461b1f07296 Added configure option for redundancy (--with-devices).
Florian Pose <fp@igh-essen.com>
parents: 2447
diff changeset
   128
    io.config_count = ec_master_config_count(master);
d461b1f07296 Added configure option for redundancy (--with-devices).
Florian Pose <fp@igh-essen.com>
parents: 2447
diff changeset
   129
    io.domain_count = ec_master_domain_count(master);
2433
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   130
#ifdef EC_EOE
2453
d461b1f07296 Added configure option for redundancy (--with-devices).
Florian Pose <fp@igh-essen.com>
parents: 2447
diff changeset
   131
    io.eoe_handler_count = ec_master_eoe_handler_count(master);
2433
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   132
#endif
2453
d461b1f07296 Added configure option for redundancy (--with-devices).
Florian Pose <fp@igh-essen.com>
parents: 2447
diff changeset
   133
    io.phase = (uint8_t) master->phase;
d461b1f07296 Added configure option for redundancy (--with-devices).
Florian Pose <fp@igh-essen.com>
parents: 2447
diff changeset
   134
    io.active = (uint8_t) master->active;
d461b1f07296 Added configure option for redundancy (--with-devices).
Florian Pose <fp@igh-essen.com>
parents: 2447
diff changeset
   135
    io.scan_busy = master->scan_busy;
2433
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   136
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   137
    up(&master->master_sem);
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   138
2453
d461b1f07296 Added configure option for redundancy (--with-devices).
Florian Pose <fp@igh-essen.com>
parents: 2447
diff changeset
   139
    if (down_interruptible(&master->device_sem)) {
2433
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   140
        return -EINTR;
2453
d461b1f07296 Added configure option for redundancy (--with-devices).
Florian Pose <fp@igh-essen.com>
parents: 2447
diff changeset
   141
    }
d461b1f07296 Added configure option for redundancy (--with-devices).
Florian Pose <fp@igh-essen.com>
parents: 2447
diff changeset
   142
d461b1f07296 Added configure option for redundancy (--with-devices).
Florian Pose <fp@igh-essen.com>
parents: 2447
diff changeset
   143
    for (dev_idx = EC_DEVICE_MAIN;
d461b1f07296 Added configure option for redundancy (--with-devices).
Florian Pose <fp@igh-essen.com>
parents: 2447
diff changeset
   144
            dev_idx < ec_master_num_devices(master); dev_idx++) {
d461b1f07296 Added configure option for redundancy (--with-devices).
Florian Pose <fp@igh-essen.com>
parents: 2447
diff changeset
   145
        ec_device_t *device = &master->devices[dev_idx];
2433
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   146
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   147
        if (device->dev) {
2453
d461b1f07296 Added configure option for redundancy (--with-devices).
Florian Pose <fp@igh-essen.com>
parents: 2447
diff changeset
   148
            memcpy(io.devices[dev_idx].address, device->dev->dev_addr,
d461b1f07296 Added configure option for redundancy (--with-devices).
Florian Pose <fp@igh-essen.com>
parents: 2447
diff changeset
   149
                    ETH_ALEN);
2433
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   150
        } else {
2453
d461b1f07296 Added configure option for redundancy (--with-devices).
Florian Pose <fp@igh-essen.com>
parents: 2447
diff changeset
   151
            memcpy(io.devices[dev_idx].address, master->macs[dev_idx],
d461b1f07296 Added configure option for redundancy (--with-devices).
Florian Pose <fp@igh-essen.com>
parents: 2447
diff changeset
   152
                    ETH_ALEN);
2433
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   153
        }
2453
d461b1f07296 Added configure option for redundancy (--with-devices).
Florian Pose <fp@igh-essen.com>
parents: 2447
diff changeset
   154
        io.devices[dev_idx].attached = device->dev ? 1 : 0;
d461b1f07296 Added configure option for redundancy (--with-devices).
Florian Pose <fp@igh-essen.com>
parents: 2447
diff changeset
   155
        io.devices[dev_idx].link_state = device->link_state ? 1 : 0;
d461b1f07296 Added configure option for redundancy (--with-devices).
Florian Pose <fp@igh-essen.com>
parents: 2447
diff changeset
   156
        io.devices[dev_idx].tx_count = device->tx_count;
d461b1f07296 Added configure option for redundancy (--with-devices).
Florian Pose <fp@igh-essen.com>
parents: 2447
diff changeset
   157
        io.devices[dev_idx].rx_count = device->rx_count;
d461b1f07296 Added configure option for redundancy (--with-devices).
Florian Pose <fp@igh-essen.com>
parents: 2447
diff changeset
   158
        io.devices[dev_idx].tx_bytes = device->tx_bytes;
d461b1f07296 Added configure option for redundancy (--with-devices).
Florian Pose <fp@igh-essen.com>
parents: 2447
diff changeset
   159
        io.devices[dev_idx].rx_bytes = device->rx_bytes;
d461b1f07296 Added configure option for redundancy (--with-devices).
Florian Pose <fp@igh-essen.com>
parents: 2447
diff changeset
   160
        io.devices[dev_idx].tx_errors = device->tx_errors;
2433
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   161
        for (j = 0; j < EC_RATE_COUNT; j++) {
2453
d461b1f07296 Added configure option for redundancy (--with-devices).
Florian Pose <fp@igh-essen.com>
parents: 2447
diff changeset
   162
            io.devices[dev_idx].tx_frame_rates[j] =
2433
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   163
                device->tx_frame_rates[j];
2453
d461b1f07296 Added configure option for redundancy (--with-devices).
Florian Pose <fp@igh-essen.com>
parents: 2447
diff changeset
   164
            io.devices[dev_idx].rx_frame_rates[j] =
2433
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   165
                device->rx_frame_rates[j];
2453
d461b1f07296 Added configure option for redundancy (--with-devices).
Florian Pose <fp@igh-essen.com>
parents: 2447
diff changeset
   166
            io.devices[dev_idx].tx_byte_rates[j] =
2433
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   167
                device->tx_byte_rates[j];
2453
d461b1f07296 Added configure option for redundancy (--with-devices).
Florian Pose <fp@igh-essen.com>
parents: 2447
diff changeset
   168
            io.devices[dev_idx].rx_byte_rates[j] =
2433
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   169
                device->rx_byte_rates[j];
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   170
        }
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   171
    }
2453
d461b1f07296 Added configure option for redundancy (--with-devices).
Florian Pose <fp@igh-essen.com>
parents: 2447
diff changeset
   172
    io.num_devices = ec_master_num_devices(master);
d461b1f07296 Added configure option for redundancy (--with-devices).
Florian Pose <fp@igh-essen.com>
parents: 2447
diff changeset
   173
d461b1f07296 Added configure option for redundancy (--with-devices).
Florian Pose <fp@igh-essen.com>
parents: 2447
diff changeset
   174
    io.tx_count = master->device_stats.tx_count;
d461b1f07296 Added configure option for redundancy (--with-devices).
Florian Pose <fp@igh-essen.com>
parents: 2447
diff changeset
   175
    io.rx_count = master->device_stats.rx_count;
d461b1f07296 Added configure option for redundancy (--with-devices).
Florian Pose <fp@igh-essen.com>
parents: 2447
diff changeset
   176
    io.tx_bytes = master->device_stats.tx_bytes;
d461b1f07296 Added configure option for redundancy (--with-devices).
Florian Pose <fp@igh-essen.com>
parents: 2447
diff changeset
   177
    io.rx_bytes = master->device_stats.rx_bytes;
d461b1f07296 Added configure option for redundancy (--with-devices).
Florian Pose <fp@igh-essen.com>
parents: 2447
diff changeset
   178
    for (j = 0; j < EC_RATE_COUNT; j++) {
d461b1f07296 Added configure option for redundancy (--with-devices).
Florian Pose <fp@igh-essen.com>
parents: 2447
diff changeset
   179
        io.tx_frame_rates[j] =
d461b1f07296 Added configure option for redundancy (--with-devices).
Florian Pose <fp@igh-essen.com>
parents: 2447
diff changeset
   180
            master->device_stats.tx_frame_rates[j];
d461b1f07296 Added configure option for redundancy (--with-devices).
Florian Pose <fp@igh-essen.com>
parents: 2447
diff changeset
   181
        io.rx_frame_rates[j] =
d461b1f07296 Added configure option for redundancy (--with-devices).
Florian Pose <fp@igh-essen.com>
parents: 2447
diff changeset
   182
            master->device_stats.rx_frame_rates[j];
d461b1f07296 Added configure option for redundancy (--with-devices).
Florian Pose <fp@igh-essen.com>
parents: 2447
diff changeset
   183
        io.tx_byte_rates[j] =
d461b1f07296 Added configure option for redundancy (--with-devices).
Florian Pose <fp@igh-essen.com>
parents: 2447
diff changeset
   184
            master->device_stats.tx_byte_rates[j];
d461b1f07296 Added configure option for redundancy (--with-devices).
Florian Pose <fp@igh-essen.com>
parents: 2447
diff changeset
   185
        io.rx_byte_rates[j] =
d461b1f07296 Added configure option for redundancy (--with-devices).
Florian Pose <fp@igh-essen.com>
parents: 2447
diff changeset
   186
            master->device_stats.rx_byte_rates[j];
d461b1f07296 Added configure option for redundancy (--with-devices).
Florian Pose <fp@igh-essen.com>
parents: 2447
diff changeset
   187
        io.loss_rates[j] =
d461b1f07296 Added configure option for redundancy (--with-devices).
Florian Pose <fp@igh-essen.com>
parents: 2447
diff changeset
   188
            master->device_stats.loss_rates[j];
2433
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   189
    }
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   190
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   191
    up(&master->device_sem);
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   192
2453
d461b1f07296 Added configure option for redundancy (--with-devices).
Florian Pose <fp@igh-essen.com>
parents: 2447
diff changeset
   193
    io.app_time = master->app_time;
d461b1f07296 Added configure option for redundancy (--with-devices).
Florian Pose <fp@igh-essen.com>
parents: 2447
diff changeset
   194
    io.ref_clock =
2433
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   195
        master->dc_ref_clock ? master->dc_ref_clock->ring_position : 0xffff;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   196
2719
94c9657e0bee Xenomai 2 to 3 migration says "RTDM drivers implementing differentiated ioctl() support for both domains should serve all real-time only requests from ioctl_rt(), returning -ENOSYS for any unrecognized request, which will cause the adaptive switch to take place automatically to the ioctl_nrt() handler. The ioctl_nrt() should then implement all requests which may be valid from the regular Linux domain exclusively."
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2712
diff changeset
   197
    if (ec_copy_to_user((void __user *) arg, &io, sizeof(io))) {
2453
d461b1f07296 Added configure option for redundancy (--with-devices).
Florian Pose <fp@igh-essen.com>
parents: 2447
diff changeset
   198
        return -EFAULT;
d461b1f07296 Added configure option for redundancy (--with-devices).
Florian Pose <fp@igh-essen.com>
parents: 2447
diff changeset
   199
    }
2433
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   200
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   201
    return 0;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   202
}
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   203
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   204
/*****************************************************************************/
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   205
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   206
/** Get slave information.
2522
ec403cf308eb Updated Doxygen documentation.
Florian Pose <fp@igh-essen.com>
parents: 2505
diff changeset
   207
 *
ec403cf308eb Updated Doxygen documentation.
Florian Pose <fp@igh-essen.com>
parents: 2505
diff changeset
   208
 * \return Zero on success, otherwise a negative error code.
2433
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   209
 */
2481
c99ff159b60d Added function attribute definition.
Florian Pose <fp@igh-essen.com>
parents: 2477
diff changeset
   210
static ATTRIBUTES int ec_ioctl_slave(
2433
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   211
        ec_master_t *master, /**< EtherCAT master. */
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   212
        void *arg /**< Userspace address to store the results. */
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   213
        )
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   214
{
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   215
    ec_ioctl_slave_t data;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   216
    const ec_slave_t *slave;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   217
    int i;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   218
2719
94c9657e0bee Xenomai 2 to 3 migration says "RTDM drivers implementing differentiated ioctl() support for both domains should serve all real-time only requests from ioctl_rt(), returning -ENOSYS for any unrecognized request, which will cause the adaptive switch to take place automatically to the ioctl_nrt() handler. The ioctl_nrt() should then implement all requests which may be valid from the regular Linux domain exclusively."
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2712
diff changeset
   219
    if (ec_copy_from_user(&data, (void __user *) arg, sizeof(data))) {
2433
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   220
        return -EFAULT;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   221
    }
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   222
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   223
    if (down_interruptible(&master->master_sem))
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   224
        return -EINTR;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   225
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   226
    if (!(slave = ec_master_find_slave_const(
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   227
                    master, 0, data.position))) {
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   228
        up(&master->master_sem);
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   229
        EC_MASTER_ERR(master, "Slave %u does not exist!\n", data.position);
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   230
        return -EINVAL;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   231
    }
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   232
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   233
    data.device_index = slave->device_index;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   234
    data.vendor_id = slave->sii.vendor_id;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   235
    data.product_code = slave->sii.product_code;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   236
    data.revision_number = slave->sii.revision_number;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   237
    data.serial_number = slave->sii.serial_number;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   238
    data.alias = slave->effective_alias;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   239
    data.boot_rx_mailbox_offset = slave->sii.boot_rx_mailbox_offset;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   240
    data.boot_rx_mailbox_size = slave->sii.boot_rx_mailbox_size;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   241
    data.boot_tx_mailbox_offset = slave->sii.boot_tx_mailbox_offset;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   242
    data.boot_tx_mailbox_size = slave->sii.boot_tx_mailbox_size;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   243
    data.std_rx_mailbox_offset = slave->sii.std_rx_mailbox_offset;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   244
    data.std_rx_mailbox_size = slave->sii.std_rx_mailbox_size;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   245
    data.std_tx_mailbox_offset = slave->sii.std_tx_mailbox_offset;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   246
    data.std_tx_mailbox_size = slave->sii.std_tx_mailbox_size;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   247
    data.mailbox_protocols = slave->sii.mailbox_protocols;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   248
    data.has_general_category = slave->sii.has_general;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   249
    data.coe_details = slave->sii.coe_details;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   250
    data.general_flags = slave->sii.general_flags;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   251
    data.current_on_ebus = slave->sii.current_on_ebus;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   252
    for (i = 0; i < EC_MAX_PORTS; i++) {
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   253
        data.ports[i].desc = slave->ports[i].desc;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   254
        data.ports[i].link.link_up = slave->ports[i].link.link_up;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   255
        data.ports[i].link.loop_closed = slave->ports[i].link.loop_closed;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   256
        data.ports[i].link.signal_detected =
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   257
            slave->ports[i].link.signal_detected;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   258
        data.ports[i].receive_time = slave->ports[i].receive_time;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   259
        if (slave->ports[i].next_slave) {
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   260
            data.ports[i].next_slave =
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   261
                slave->ports[i].next_slave->ring_position;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   262
        } else {
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   263
            data.ports[i].next_slave = 0xffff;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   264
        }
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   265
        data.ports[i].delay_to_next_dc = slave->ports[i].delay_to_next_dc;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   266
    }
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   267
    data.fmmu_bit = slave->base_fmmu_bit_operation;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   268
    data.dc_supported = slave->base_dc_supported;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   269
    data.dc_range = slave->base_dc_range;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   270
    data.has_dc_system_time = slave->has_dc_system_time;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   271
    data.transmission_delay = slave->transmission_delay;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   272
    data.al_state = slave->current_state;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   273
    data.error_flag = slave->error_flag;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   274
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   275
    data.sync_count = slave->sii.sync_count;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   276
    data.sdo_count = ec_slave_sdo_count(slave);
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   277
    data.sii_nwords = slave->sii_nwords;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   278
    ec_ioctl_strcpy(data.group, slave->sii.group);
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   279
    ec_ioctl_strcpy(data.image, slave->sii.image);
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   280
    ec_ioctl_strcpy(data.order, slave->sii.order);
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   281
    ec_ioctl_strcpy(data.name, slave->sii.name);
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   282
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   283
    up(&master->master_sem);
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   284
2719
94c9657e0bee Xenomai 2 to 3 migration says "RTDM drivers implementing differentiated ioctl() support for both domains should serve all real-time only requests from ioctl_rt(), returning -ENOSYS for any unrecognized request, which will cause the adaptive switch to take place automatically to the ioctl_nrt() handler. The ioctl_nrt() should then implement all requests which may be valid from the regular Linux domain exclusively."
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2712
diff changeset
   285
    if (ec_copy_to_user((void __user *) arg, &data, sizeof(data)))
2433
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   286
        return -EFAULT;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   287
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   288
    return 0;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   289
}
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   290
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   291
/*****************************************************************************/
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   292
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   293
/** Get slave sync manager information.
2522
ec403cf308eb Updated Doxygen documentation.
Florian Pose <fp@igh-essen.com>
parents: 2505
diff changeset
   294
 *
ec403cf308eb Updated Doxygen documentation.
Florian Pose <fp@igh-essen.com>
parents: 2505
diff changeset
   295
 * \return Zero on success, otherwise a negative error code.
2433
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   296
 */
2481
c99ff159b60d Added function attribute definition.
Florian Pose <fp@igh-essen.com>
parents: 2477
diff changeset
   297
static ATTRIBUTES int ec_ioctl_slave_sync(
2433
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   298
        ec_master_t *master, /**< EtherCAT master. */
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   299
        void *arg /**< Userspace address to store the results. */
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   300
        )
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   301
{
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   302
    ec_ioctl_slave_sync_t data;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   303
    const ec_slave_t *slave;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   304
    const ec_sync_t *sync;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   305
2719
94c9657e0bee Xenomai 2 to 3 migration says "RTDM drivers implementing differentiated ioctl() support for both domains should serve all real-time only requests from ioctl_rt(), returning -ENOSYS for any unrecognized request, which will cause the adaptive switch to take place automatically to the ioctl_nrt() handler. The ioctl_nrt() should then implement all requests which may be valid from the regular Linux domain exclusively."
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2712
diff changeset
   306
    if (ec_copy_from_user(&data, (void __user *) arg, sizeof(data))) {
2433
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   307
        return -EFAULT;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   308
    }
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   309
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   310
    if (down_interruptible(&master->master_sem))
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   311
        return -EINTR;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   312
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   313
    if (!(slave = ec_master_find_slave_const(
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   314
                    master, 0, data.slave_position))) {
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   315
        up(&master->master_sem);
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   316
        EC_MASTER_ERR(master, "Slave %u does not exist!\n",
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   317
                data.slave_position);
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   318
        return -EINVAL;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   319
    }
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   320
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   321
    if (data.sync_index >= slave->sii.sync_count) {
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   322
        up(&master->master_sem);
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   323
        EC_SLAVE_ERR(slave, "Sync manager %u does not exist!\n",
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   324
                data.sync_index);
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   325
        return -EINVAL;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   326
    }
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   327
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   328
    sync = &slave->sii.syncs[data.sync_index];
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   329
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   330
    data.physical_start_address = sync->physical_start_address;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   331
    data.default_size = sync->default_length;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   332
    data.control_register = sync->control_register;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   333
    data.enable = sync->enable;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   334
    data.pdo_count = ec_pdo_list_count(&sync->pdos);
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   335
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   336
    up(&master->master_sem);
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   337
2719
94c9657e0bee Xenomai 2 to 3 migration says "RTDM drivers implementing differentiated ioctl() support for both domains should serve all real-time only requests from ioctl_rt(), returning -ENOSYS for any unrecognized request, which will cause the adaptive switch to take place automatically to the ioctl_nrt() handler. The ioctl_nrt() should then implement all requests which may be valid from the regular Linux domain exclusively."
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2712
diff changeset
   338
    if (ec_copy_to_user((void __user *) arg, &data, sizeof(data)))
2433
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   339
        return -EFAULT;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   340
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   341
    return 0;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   342
}
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   343
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   344
/*****************************************************************************/
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   345
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   346
/** Get slave sync manager PDO information.
2522
ec403cf308eb Updated Doxygen documentation.
Florian Pose <fp@igh-essen.com>
parents: 2505
diff changeset
   347
 *
ec403cf308eb Updated Doxygen documentation.
Florian Pose <fp@igh-essen.com>
parents: 2505
diff changeset
   348
 * \return Zero on success, otherwise a negative error code.
2433
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   349
 */
2481
c99ff159b60d Added function attribute definition.
Florian Pose <fp@igh-essen.com>
parents: 2477
diff changeset
   350
static ATTRIBUTES int ec_ioctl_slave_sync_pdo(
2433
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   351
        ec_master_t *master, /**< EtherCAT master. */
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   352
        void *arg /**< Userspace address to store the results. */
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   353
        )
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   354
{
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   355
    ec_ioctl_slave_sync_pdo_t data;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   356
    const ec_slave_t *slave;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   357
    const ec_sync_t *sync;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   358
    const ec_pdo_t *pdo;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   359
2719
94c9657e0bee Xenomai 2 to 3 migration says "RTDM drivers implementing differentiated ioctl() support for both domains should serve all real-time only requests from ioctl_rt(), returning -ENOSYS for any unrecognized request, which will cause the adaptive switch to take place automatically to the ioctl_nrt() handler. The ioctl_nrt() should then implement all requests which may be valid from the regular Linux domain exclusively."
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2712
diff changeset
   360
    if (ec_copy_from_user(&data, (void __user *) arg, sizeof(data))) {
2433
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   361
        return -EFAULT;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   362
    }
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   363
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   364
    if (down_interruptible(&master->master_sem))
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   365
        return -EINTR;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   366
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   367
    if (!(slave = ec_master_find_slave_const(
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   368
                    master, 0, data.slave_position))) {
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   369
        up(&master->master_sem);
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   370
        EC_MASTER_ERR(master, "Slave %u does not exist!\n",
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   371
                data.slave_position);
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   372
        return -EINVAL;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   373
    }
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   374
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   375
    if (data.sync_index >= slave->sii.sync_count) {
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   376
        up(&master->master_sem);
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   377
        EC_SLAVE_ERR(slave, "Sync manager %u does not exist!\n",
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   378
                data.sync_index);
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   379
        return -EINVAL;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   380
    }
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   381
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   382
    sync = &slave->sii.syncs[data.sync_index];
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   383
    if (!(pdo = ec_pdo_list_find_pdo_by_pos_const(
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   384
                    &sync->pdos, data.pdo_pos))) {
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   385
        up(&master->master_sem);
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   386
        EC_SLAVE_ERR(slave, "Sync manager %u does not contain a PDO with "
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   387
                "position %u!\n", data.sync_index, data.pdo_pos);
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   388
        return -EINVAL;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   389
    }
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   390
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   391
    data.index = pdo->index;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   392
    data.entry_count = ec_pdo_entry_count(pdo);
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   393
    ec_ioctl_strcpy(data.name, pdo->name);
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   394
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   395
    up(&master->master_sem);
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   396
2719
94c9657e0bee Xenomai 2 to 3 migration says "RTDM drivers implementing differentiated ioctl() support for both domains should serve all real-time only requests from ioctl_rt(), returning -ENOSYS for any unrecognized request, which will cause the adaptive switch to take place automatically to the ioctl_nrt() handler. The ioctl_nrt() should then implement all requests which may be valid from the regular Linux domain exclusively."
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2712
diff changeset
   397
    if (ec_copy_to_user((void __user *) arg, &data, sizeof(data)))
2433
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   398
        return -EFAULT;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   399
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   400
    return 0;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   401
}
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   402
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   403
/*****************************************************************************/
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   404
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   405
/** Get slave sync manager PDO entry information.
2522
ec403cf308eb Updated Doxygen documentation.
Florian Pose <fp@igh-essen.com>
parents: 2505
diff changeset
   406
 *
ec403cf308eb Updated Doxygen documentation.
Florian Pose <fp@igh-essen.com>
parents: 2505
diff changeset
   407
 * \return Zero on success, otherwise a negative error code.
2433
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   408
 */
2481
c99ff159b60d Added function attribute definition.
Florian Pose <fp@igh-essen.com>
parents: 2477
diff changeset
   409
static ATTRIBUTES int ec_ioctl_slave_sync_pdo_entry(
2433
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   410
        ec_master_t *master, /**< EtherCAT master. */
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   411
        void *arg /**< Userspace address to store the results. */
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   412
        )
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   413
{
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   414
    ec_ioctl_slave_sync_pdo_entry_t data;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   415
    const ec_slave_t *slave;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   416
    const ec_sync_t *sync;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   417
    const ec_pdo_t *pdo;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   418
    const ec_pdo_entry_t *entry;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   419
2719
94c9657e0bee Xenomai 2 to 3 migration says "RTDM drivers implementing differentiated ioctl() support for both domains should serve all real-time only requests from ioctl_rt(), returning -ENOSYS for any unrecognized request, which will cause the adaptive switch to take place automatically to the ioctl_nrt() handler. The ioctl_nrt() should then implement all requests which may be valid from the regular Linux domain exclusively."
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2712
diff changeset
   420
    if (ec_copy_from_user(&data, (void __user *) arg, sizeof(data))) {
2433
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   421
        return -EFAULT;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   422
    }
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   423
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   424
    if (down_interruptible(&master->master_sem))
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   425
        return -EINTR;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   426
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   427
    if (!(slave = ec_master_find_slave_const(
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   428
                    master, 0, data.slave_position))) {
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   429
        up(&master->master_sem);
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   430
        EC_MASTER_ERR(master, "Slave %u does not exist!\n",
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   431
                data.slave_position);
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   432
        return -EINVAL;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   433
    }
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   434
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   435
    if (data.sync_index >= slave->sii.sync_count) {
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   436
        up(&master->master_sem);
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   437
        EC_SLAVE_ERR(slave, "Sync manager %u does not exist!\n",
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   438
                data.sync_index);
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   439
        return -EINVAL;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   440
    }
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   441
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   442
    sync = &slave->sii.syncs[data.sync_index];
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   443
    if (!(pdo = ec_pdo_list_find_pdo_by_pos_const(
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   444
                    &sync->pdos, data.pdo_pos))) {
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   445
        up(&master->master_sem);
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   446
        EC_SLAVE_ERR(slave, "Sync manager %u does not contain a PDO with "
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   447
                "position %u!\n", data.sync_index, data.pdo_pos);
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   448
        return -EINVAL;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   449
    }
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   450
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   451
    if (!(entry = ec_pdo_find_entry_by_pos_const(
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   452
                    pdo, data.entry_pos))) {
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   453
        up(&master->master_sem);
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   454
        EC_SLAVE_ERR(slave, "PDO 0x%04X does not contain an entry with "
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   455
                "position %u!\n", data.pdo_pos, data.entry_pos);
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   456
        return -EINVAL;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   457
    }
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   458
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   459
    data.index = entry->index;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   460
    data.subindex = entry->subindex;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   461
    data.bit_length = entry->bit_length;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   462
    ec_ioctl_strcpy(data.name, entry->name);
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   463
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   464
    up(&master->master_sem);
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   465
2719
94c9657e0bee Xenomai 2 to 3 migration says "RTDM drivers implementing differentiated ioctl() support for both domains should serve all real-time only requests from ioctl_rt(), returning -ENOSYS for any unrecognized request, which will cause the adaptive switch to take place automatically to the ioctl_nrt() handler. The ioctl_nrt() should then implement all requests which may be valid from the regular Linux domain exclusively."
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2712
diff changeset
   466
    if (ec_copy_to_user((void __user *) arg, &data, sizeof(data)))
2433
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   467
        return -EFAULT;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   468
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   469
    return 0;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   470
}
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   471
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   472
/*****************************************************************************/
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   473
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   474
/** Get domain information.
2522
ec403cf308eb Updated Doxygen documentation.
Florian Pose <fp@igh-essen.com>
parents: 2505
diff changeset
   475
 *
ec403cf308eb Updated Doxygen documentation.
Florian Pose <fp@igh-essen.com>
parents: 2505
diff changeset
   476
 * \return Zero on success, otherwise a negative error code.
2433
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   477
 */
2481
c99ff159b60d Added function attribute definition.
Florian Pose <fp@igh-essen.com>
parents: 2477
diff changeset
   478
static ATTRIBUTES int ec_ioctl_domain(
2433
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   479
        ec_master_t *master, /**< EtherCAT master. */
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   480
        void *arg /**< Userspace address to store the results. */
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   481
        )
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   482
{
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   483
    ec_ioctl_domain_t data;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   484
    const ec_domain_t *domain;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   485
    unsigned int dev_idx;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   486
2719
94c9657e0bee Xenomai 2 to 3 migration says "RTDM drivers implementing differentiated ioctl() support for both domains should serve all real-time only requests from ioctl_rt(), returning -ENOSYS for any unrecognized request, which will cause the adaptive switch to take place automatically to the ioctl_nrt() handler. The ioctl_nrt() should then implement all requests which may be valid from the regular Linux domain exclusively."
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2712
diff changeset
   487
    if (ec_copy_from_user(&data, (void __user *) arg, sizeof(data))) {
2433
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   488
        return -EFAULT;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   489
    }
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   490
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   491
    if (down_interruptible(&master->master_sem))
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   492
        return -EINTR;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   493
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   494
    if (!(domain = ec_master_find_domain_const(master, data.index))) {
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   495
        up(&master->master_sem);
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   496
        EC_MASTER_ERR(master, "Domain %u does not exist!\n", data.index);
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   497
        return -EINVAL;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   498
    }
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   499
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   500
    data.data_size = domain->data_size;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   501
    data.logical_base_address = domain->logical_base_address;
2453
d461b1f07296 Added configure option for redundancy (--with-devices).
Florian Pose <fp@igh-essen.com>
parents: 2447
diff changeset
   502
    for (dev_idx = EC_DEVICE_MAIN;
d461b1f07296 Added configure option for redundancy (--with-devices).
Florian Pose <fp@igh-essen.com>
parents: 2447
diff changeset
   503
            dev_idx < ec_master_num_devices(domain->master); dev_idx++) {
2433
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   504
        data.working_counter[dev_idx] = domain->working_counter[dev_idx];
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   505
    }
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   506
    data.expected_working_counter = domain->expected_working_counter;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   507
    data.fmmu_count = ec_domain_fmmu_count(domain);
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   508
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   509
    up(&master->master_sem);
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   510
2719
94c9657e0bee Xenomai 2 to 3 migration says "RTDM drivers implementing differentiated ioctl() support for both domains should serve all real-time only requests from ioctl_rt(), returning -ENOSYS for any unrecognized request, which will cause the adaptive switch to take place automatically to the ioctl_nrt() handler. The ioctl_nrt() should then implement all requests which may be valid from the regular Linux domain exclusively."
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2712
diff changeset
   511
    if (ec_copy_to_user((void __user *) arg, &data, sizeof(data)))
2433
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   512
        return -EFAULT;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   513
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   514
    return 0;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   515
}
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   516
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   517
/*****************************************************************************/
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   518
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   519
/** Get domain FMMU information.
2522
ec403cf308eb Updated Doxygen documentation.
Florian Pose <fp@igh-essen.com>
parents: 2505
diff changeset
   520
 *
ec403cf308eb Updated Doxygen documentation.
Florian Pose <fp@igh-essen.com>
parents: 2505
diff changeset
   521
 * \return Zero on success, otherwise a negative error code.
2433
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   522
 */
2481
c99ff159b60d Added function attribute definition.
Florian Pose <fp@igh-essen.com>
parents: 2477
diff changeset
   523
static ATTRIBUTES int ec_ioctl_domain_fmmu(
2433
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   524
        ec_master_t *master, /**< EtherCAT master. */
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   525
        void *arg /**< Userspace address to store the results. */
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   526
        )
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   527
{
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   528
    ec_ioctl_domain_fmmu_t data;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   529
    const ec_domain_t *domain;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   530
    const ec_fmmu_config_t *fmmu;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   531
2719
94c9657e0bee Xenomai 2 to 3 migration says "RTDM drivers implementing differentiated ioctl() support for both domains should serve all real-time only requests from ioctl_rt(), returning -ENOSYS for any unrecognized request, which will cause the adaptive switch to take place automatically to the ioctl_nrt() handler. The ioctl_nrt() should then implement all requests which may be valid from the regular Linux domain exclusively."
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2712
diff changeset
   532
    if (ec_copy_from_user(&data, (void __user *) arg, sizeof(data))) {
2433
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   533
        return -EFAULT;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   534
    }
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   535
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   536
    if (down_interruptible(&master->master_sem))
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   537
        return -EINTR;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   538
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   539
    if (!(domain = ec_master_find_domain_const(master, data.domain_index))) {
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   540
        up(&master->master_sem);
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   541
        EC_MASTER_ERR(master, "Domain %u does not exist!\n",
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   542
                data.domain_index);
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   543
        return -EINVAL;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   544
    }
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   545
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   546
    if (!(fmmu = ec_domain_find_fmmu(domain, data.fmmu_index))) {
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   547
        up(&master->master_sem);
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   548
        EC_MASTER_ERR(master, "Domain %u has less than %u"
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   549
                " fmmu configurations.\n",
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   550
                data.domain_index, data.fmmu_index + 1);
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   551
        return -EINVAL;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   552
    }
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   553
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   554
    data.slave_config_alias = fmmu->sc->alias;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   555
    data.slave_config_position = fmmu->sc->position;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   556
    data.sync_index = fmmu->sync_index;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   557
    data.dir = fmmu->dir;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   558
    data.logical_address = fmmu->logical_start_address;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   559
    data.data_size = fmmu->data_size;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   560
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   561
    up(&master->master_sem);
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   562
2719
94c9657e0bee Xenomai 2 to 3 migration says "RTDM drivers implementing differentiated ioctl() support for both domains should serve all real-time only requests from ioctl_rt(), returning -ENOSYS for any unrecognized request, which will cause the adaptive switch to take place automatically to the ioctl_nrt() handler. The ioctl_nrt() should then implement all requests which may be valid from the regular Linux domain exclusively."
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2712
diff changeset
   563
    if (ec_copy_to_user((void __user *) arg, &data, sizeof(data)))
2433
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   564
        return -EFAULT;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   565
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   566
    return 0;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   567
}
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   568
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   569
/*****************************************************************************/
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   570
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   571
/** Get domain data.
2522
ec403cf308eb Updated Doxygen documentation.
Florian Pose <fp@igh-essen.com>
parents: 2505
diff changeset
   572
 *
ec403cf308eb Updated Doxygen documentation.
Florian Pose <fp@igh-essen.com>
parents: 2505
diff changeset
   573
 * \return Zero on success, otherwise a negative error code.
2433
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   574
 */
2481
c99ff159b60d Added function attribute definition.
Florian Pose <fp@igh-essen.com>
parents: 2477
diff changeset
   575
static ATTRIBUTES int ec_ioctl_domain_data(
2433
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   576
        ec_master_t *master, /**< EtherCAT master. */
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   577
        void *arg /**< Userspace address to store the results. */
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   578
        )
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   579
{
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   580
    ec_ioctl_domain_data_t data;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   581
    const ec_domain_t *domain;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   582
2719
94c9657e0bee Xenomai 2 to 3 migration says "RTDM drivers implementing differentiated ioctl() support for both domains should serve all real-time only requests from ioctl_rt(), returning -ENOSYS for any unrecognized request, which will cause the adaptive switch to take place automatically to the ioctl_nrt() handler. The ioctl_nrt() should then implement all requests which may be valid from the regular Linux domain exclusively."
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2712
diff changeset
   583
    if (ec_copy_from_user(&data, (void __user *) arg, sizeof(data))) {
2433
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   584
        return -EFAULT;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   585
    }
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   586
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   587
    if (down_interruptible(&master->master_sem))
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   588
        return -EINTR;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   589
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   590
    if (!(domain = ec_master_find_domain_const(master, data.domain_index))) {
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   591
        up(&master->master_sem);
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   592
        EC_MASTER_ERR(master, "Domain %u does not exist!\n",
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   593
                data.domain_index);
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   594
        return -EINVAL;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   595
    }
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   596
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   597
    if (domain->data_size != data.data_size) {
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   598
        up(&master->master_sem);
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   599
        EC_MASTER_ERR(master, "Data size mismatch %u/%zu!\n",
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   600
                data.data_size, domain->data_size);
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   601
        return -EFAULT;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   602
    }
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   603
2719
94c9657e0bee Xenomai 2 to 3 migration says "RTDM drivers implementing differentiated ioctl() support for both domains should serve all real-time only requests from ioctl_rt(), returning -ENOSYS for any unrecognized request, which will cause the adaptive switch to take place automatically to the ioctl_nrt() handler. The ioctl_nrt() should then implement all requests which may be valid from the regular Linux domain exclusively."
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2712
diff changeset
   604
    if (ec_copy_to_user((void __user *) data.target, domain->data,
2433
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   605
                domain->data_size)) {
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   606
        up(&master->master_sem);
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   607
        return -EFAULT;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   608
    }
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   609
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   610
    up(&master->master_sem);
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   611
    return 0;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   612
}
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   613
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   614
/*****************************************************************************/
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   615
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   616
/** Set master debug level.
2522
ec403cf308eb Updated Doxygen documentation.
Florian Pose <fp@igh-essen.com>
parents: 2505
diff changeset
   617
 *
ec403cf308eb Updated Doxygen documentation.
Florian Pose <fp@igh-essen.com>
parents: 2505
diff changeset
   618
 * \return Zero on success, otherwise a negative error code.
2433
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   619
 */
2481
c99ff159b60d Added function attribute definition.
Florian Pose <fp@igh-essen.com>
parents: 2477
diff changeset
   620
static ATTRIBUTES int ec_ioctl_master_debug(
2433
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   621
        ec_master_t *master, /**< EtherCAT master. */
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   622
        void *arg /**< ioctl() argument. */
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   623
        )
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   624
{
2487
ccafdf1e261f Fixed some warnings on 64 bit systems.
Florian Pose <fp@igh-essen.com>
parents: 2486
diff changeset
   625
    return ec_master_debug_level(master, (unsigned long) arg);
2433
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   626
}
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   627
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   628
/*****************************************************************************/
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   629
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   630
/** Issue a bus scan.
2522
ec403cf308eb Updated Doxygen documentation.
Florian Pose <fp@igh-essen.com>
parents: 2505
diff changeset
   631
 *
ec403cf308eb Updated Doxygen documentation.
Florian Pose <fp@igh-essen.com>
parents: 2505
diff changeset
   632
 * \return Always zero (success).
2433
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   633
 */
2481
c99ff159b60d Added function attribute definition.
Florian Pose <fp@igh-essen.com>
parents: 2477
diff changeset
   634
static ATTRIBUTES int ec_ioctl_master_rescan(
2433
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   635
        ec_master_t *master, /**< EtherCAT master. */
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   636
        void *arg /**< ioctl() argument. */
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   637
        )
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   638
{
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   639
    master->fsm.rescan_required = 1;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   640
    return 0;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   641
}
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   642
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   643
/*****************************************************************************/
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   644
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   645
/** Set slave state.
2522
ec403cf308eb Updated Doxygen documentation.
Florian Pose <fp@igh-essen.com>
parents: 2505
diff changeset
   646
 *
ec403cf308eb Updated Doxygen documentation.
Florian Pose <fp@igh-essen.com>
parents: 2505
diff changeset
   647
 * \return Zero on success, otherwise a negative error code.
2433
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   648
 */
2481
c99ff159b60d Added function attribute definition.
Florian Pose <fp@igh-essen.com>
parents: 2477
diff changeset
   649
static ATTRIBUTES int ec_ioctl_slave_state(
2433
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   650
        ec_master_t *master, /**< EtherCAT master. */
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   651
        void *arg /**< ioctl() argument. */
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   652
        )
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   653
{
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   654
    ec_ioctl_slave_state_t data;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   655
    ec_slave_t *slave;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   656
2719
94c9657e0bee Xenomai 2 to 3 migration says "RTDM drivers implementing differentiated ioctl() support for both domains should serve all real-time only requests from ioctl_rt(), returning -ENOSYS for any unrecognized request, which will cause the adaptive switch to take place automatically to the ioctl_nrt() handler. The ioctl_nrt() should then implement all requests which may be valid from the regular Linux domain exclusively."
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2712
diff changeset
   657
    if (ec_copy_from_user(&data, (void __user *) arg, sizeof(data))) {
2433
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   658
        return -EFAULT;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   659
    }
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   660
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   661
    if (down_interruptible(&master->master_sem))
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   662
        return -EINTR;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   663
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   664
    if (!(slave = ec_master_find_slave(
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   665
                    master, 0, data.slave_position))) {
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   666
        up(&master->master_sem);
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   667
        EC_MASTER_ERR(master, "Slave %u does not exist!\n",
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   668
                data.slave_position);
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   669
        return -EINVAL;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   670
    }
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   671
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   672
    ec_slave_request_state(slave, data.al_state);
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   673
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   674
    up(&master->master_sem);
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   675
    return 0;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   676
}
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   677
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   678
/*****************************************************************************/
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   679
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   680
/** Get slave SDO information.
2522
ec403cf308eb Updated Doxygen documentation.
Florian Pose <fp@igh-essen.com>
parents: 2505
diff changeset
   681
 *
ec403cf308eb Updated Doxygen documentation.
Florian Pose <fp@igh-essen.com>
parents: 2505
diff changeset
   682
 * \return Zero on success, otherwise a negative error code.
2433
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   683
 */
2481
c99ff159b60d Added function attribute definition.
Florian Pose <fp@igh-essen.com>
parents: 2477
diff changeset
   684
static ATTRIBUTES int ec_ioctl_slave_sdo(
2433
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   685
        ec_master_t *master, /**< EtherCAT master. */
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   686
        void *arg /**< ioctl() argument. */
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   687
        )
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   688
{
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   689
    ec_ioctl_slave_sdo_t data;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   690
    const ec_slave_t *slave;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   691
    const ec_sdo_t *sdo;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   692
2719
94c9657e0bee Xenomai 2 to 3 migration says "RTDM drivers implementing differentiated ioctl() support for both domains should serve all real-time only requests from ioctl_rt(), returning -ENOSYS for any unrecognized request, which will cause the adaptive switch to take place automatically to the ioctl_nrt() handler. The ioctl_nrt() should then implement all requests which may be valid from the regular Linux domain exclusively."
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2712
diff changeset
   693
    if (ec_copy_from_user(&data, (void __user *) arg, sizeof(data))) {
2433
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   694
        return -EFAULT;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   695
    }
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   696
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   697
    if (down_interruptible(&master->master_sem))
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   698
        return -EINTR;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   699
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   700
    if (!(slave = ec_master_find_slave_const(
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   701
                    master, 0, data.slave_position))) {
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   702
        up(&master->master_sem);
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   703
        EC_MASTER_ERR(master, "Slave %u does not exist!\n",
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   704
                data.slave_position);
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   705
        return -EINVAL;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   706
    }
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   707
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   708
    if (!(sdo = ec_slave_get_sdo_by_pos_const(
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   709
                    slave, data.sdo_position))) {
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   710
        up(&master->master_sem);
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   711
        EC_SLAVE_ERR(slave, "SDO %u does not exist!\n", data.sdo_position);
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   712
        return -EINVAL;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   713
    }
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   714
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   715
    data.sdo_index = sdo->index;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   716
    data.max_subindex = sdo->max_subindex;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   717
    ec_ioctl_strcpy(data.name, sdo->name);
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   718
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   719
    up(&master->master_sem);
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   720
2719
94c9657e0bee Xenomai 2 to 3 migration says "RTDM drivers implementing differentiated ioctl() support for both domains should serve all real-time only requests from ioctl_rt(), returning -ENOSYS for any unrecognized request, which will cause the adaptive switch to take place automatically to the ioctl_nrt() handler. The ioctl_nrt() should then implement all requests which may be valid from the regular Linux domain exclusively."
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2712
diff changeset
   721
    if (ec_copy_to_user((void __user *) arg, &data, sizeof(data)))
2433
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   722
        return -EFAULT;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   723
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   724
    return 0;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   725
}
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   726
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   727
/*****************************************************************************/
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   728
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   729
/** Get slave SDO entry information.
2522
ec403cf308eb Updated Doxygen documentation.
Florian Pose <fp@igh-essen.com>
parents: 2505
diff changeset
   730
 *
ec403cf308eb Updated Doxygen documentation.
Florian Pose <fp@igh-essen.com>
parents: 2505
diff changeset
   731
 * \return Zero on success, otherwise a negative error code.
2433
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   732
 */
2481
c99ff159b60d Added function attribute definition.
Florian Pose <fp@igh-essen.com>
parents: 2477
diff changeset
   733
static ATTRIBUTES int ec_ioctl_slave_sdo_entry(
2433
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   734
        ec_master_t *master, /**< EtherCAT master. */
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   735
        void *arg /**< ioctl() argument. */
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   736
        )
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   737
{
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   738
    ec_ioctl_slave_sdo_entry_t data;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   739
    const ec_slave_t *slave;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   740
    const ec_sdo_t *sdo;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   741
    const ec_sdo_entry_t *entry;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   742
2719
94c9657e0bee Xenomai 2 to 3 migration says "RTDM drivers implementing differentiated ioctl() support for both domains should serve all real-time only requests from ioctl_rt(), returning -ENOSYS for any unrecognized request, which will cause the adaptive switch to take place automatically to the ioctl_nrt() handler. The ioctl_nrt() should then implement all requests which may be valid from the regular Linux domain exclusively."
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2712
diff changeset
   743
    if (ec_copy_from_user(&data, (void __user *) arg, sizeof(data))) {
2433
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   744
        return -EFAULT;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   745
    }
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   746
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   747
    if (down_interruptible(&master->master_sem))
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   748
        return -EINTR;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   749
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   750
    if (!(slave = ec_master_find_slave_const(
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   751
                    master, 0, data.slave_position))) {
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   752
        up(&master->master_sem);
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   753
        EC_MASTER_ERR(master, "Slave %u does not exist!\n",
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   754
                data.slave_position);
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   755
        return -EINVAL;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   756
    }
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   757
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   758
    if (data.sdo_spec <= 0) {
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   759
        if (!(sdo = ec_slave_get_sdo_by_pos_const(
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   760
                        slave, -data.sdo_spec))) {
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   761
            up(&master->master_sem);
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   762
            EC_SLAVE_ERR(slave, "SDO %u does not exist!\n", -data.sdo_spec);
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   763
            return -EINVAL;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   764
        }
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   765
    } else {
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   766
        if (!(sdo = ec_slave_get_sdo_const(
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   767
                        slave, data.sdo_spec))) {
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   768
            up(&master->master_sem);
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   769
            EC_SLAVE_ERR(slave, "SDO 0x%04X does not exist!\n",
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   770
                    data.sdo_spec);
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   771
            return -EINVAL;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   772
        }
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   773
    }
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   774
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   775
    if (!(entry = ec_sdo_get_entry_const(
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   776
                    sdo, data.sdo_entry_subindex))) {
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   777
        up(&master->master_sem);
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   778
        EC_SLAVE_ERR(slave, "SDO entry 0x%04X:%02X does not exist!\n",
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   779
                sdo->index, data.sdo_entry_subindex);
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   780
        return -EINVAL;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   781
    }
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   782
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   783
    data.data_type = entry->data_type;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   784
    data.bit_length = entry->bit_length;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   785
    data.read_access[EC_SDO_ENTRY_ACCESS_PREOP] =
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   786
        entry->read_access[EC_SDO_ENTRY_ACCESS_PREOP];
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   787
    data.read_access[EC_SDO_ENTRY_ACCESS_SAFEOP] =
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   788
        entry->read_access[EC_SDO_ENTRY_ACCESS_SAFEOP];
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   789
    data.read_access[EC_SDO_ENTRY_ACCESS_OP] =
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   790
        entry->read_access[EC_SDO_ENTRY_ACCESS_OP];
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   791
    data.write_access[EC_SDO_ENTRY_ACCESS_PREOP] =
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   792
        entry->write_access[EC_SDO_ENTRY_ACCESS_PREOP];
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   793
    data.write_access[EC_SDO_ENTRY_ACCESS_SAFEOP] =
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   794
        entry->write_access[EC_SDO_ENTRY_ACCESS_SAFEOP];
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   795
    data.write_access[EC_SDO_ENTRY_ACCESS_OP] =
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   796
        entry->write_access[EC_SDO_ENTRY_ACCESS_OP];
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   797
    ec_ioctl_strcpy(data.description, entry->description);
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   798
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   799
    up(&master->master_sem);
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   800
2719
94c9657e0bee Xenomai 2 to 3 migration says "RTDM drivers implementing differentiated ioctl() support for both domains should serve all real-time only requests from ioctl_rt(), returning -ENOSYS for any unrecognized request, which will cause the adaptive switch to take place automatically to the ioctl_nrt() handler. The ioctl_nrt() should then implement all requests which may be valid from the regular Linux domain exclusively."
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2712
diff changeset
   801
    if (ec_copy_to_user((void __user *) arg, &data, sizeof(data)))
2433
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   802
        return -EFAULT;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   803
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   804
    return 0;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   805
}
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   806
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   807
/*****************************************************************************/
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   808
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   809
/** Upload SDO.
2522
ec403cf308eb Updated Doxygen documentation.
Florian Pose <fp@igh-essen.com>
parents: 2505
diff changeset
   810
 *
ec403cf308eb Updated Doxygen documentation.
Florian Pose <fp@igh-essen.com>
parents: 2505
diff changeset
   811
 * \return Zero on success, otherwise a negative error code.
2433
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   812
 */
2481
c99ff159b60d Added function attribute definition.
Florian Pose <fp@igh-essen.com>
parents: 2477
diff changeset
   813
static ATTRIBUTES int ec_ioctl_slave_sdo_upload(
2433
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   814
        ec_master_t *master, /**< EtherCAT master. */
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   815
        void *arg /**< ioctl() argument. */
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   816
        )
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   817
{
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   818
    ec_ioctl_slave_sdo_upload_t data;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   819
    uint8_t *target;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   820
    int ret;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   821
2719
94c9657e0bee Xenomai 2 to 3 migration says "RTDM drivers implementing differentiated ioctl() support for both domains should serve all real-time only requests from ioctl_rt(), returning -ENOSYS for any unrecognized request, which will cause the adaptive switch to take place automatically to the ioctl_nrt() handler. The ioctl_nrt() should then implement all requests which may be valid from the regular Linux domain exclusively."
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2712
diff changeset
   822
    if (ec_copy_from_user(&data, (void __user *) arg, sizeof(data))) {
2433
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   823
        return -EFAULT;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   824
    }
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   825
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   826
    if (!(target = kmalloc(data.target_size, GFP_KERNEL))) {
2487
ccafdf1e261f Fixed some warnings on 64 bit systems.
Florian Pose <fp@igh-essen.com>
parents: 2486
diff changeset
   827
        EC_MASTER_ERR(master, "Failed to allocate %zu bytes"
2433
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   828
                " for SDO upload.\n", data.target_size);
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   829
        return -ENOMEM;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   830
    }
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   831
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   832
    ret = ecrt_master_sdo_upload(master, data.slave_position,
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   833
            data.sdo_index, data.sdo_entry_subindex, target,
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   834
            data.target_size, &data.data_size, &data.abort_code);
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   835
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   836
    if (!ret) {
2719
94c9657e0bee Xenomai 2 to 3 migration says "RTDM drivers implementing differentiated ioctl() support for both domains should serve all real-time only requests from ioctl_rt(), returning -ENOSYS for any unrecognized request, which will cause the adaptive switch to take place automatically to the ioctl_nrt() handler. The ioctl_nrt() should then implement all requests which may be valid from the regular Linux domain exclusively."
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2712
diff changeset
   837
        if (ec_copy_to_user((void __user *) data.target,
2433
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   838
                    target, data.data_size)) {
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   839
            kfree(target);
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   840
            return -EFAULT;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   841
        }
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   842
    }
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   843
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   844
    kfree(target);
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   845
2719
94c9657e0bee Xenomai 2 to 3 migration says "RTDM drivers implementing differentiated ioctl() support for both domains should serve all real-time only requests from ioctl_rt(), returning -ENOSYS for any unrecognized request, which will cause the adaptive switch to take place automatically to the ioctl_nrt() handler. The ioctl_nrt() should then implement all requests which may be valid from the regular Linux domain exclusively."
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2712
diff changeset
   846
    if (ec_copy_to_user((void __user *) arg, &data, sizeof(data))) {
2433
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   847
        return -EFAULT;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   848
    }
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   849
2474
fb2fe8fae501 Fixed some ioctl() return values.
Florian Pose <fp@igh-essen.com>
parents: 2467
diff changeset
   850
    return ret;
2433
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   851
}
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   852
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   853
/*****************************************************************************/
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   854
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   855
/** Download SDO.
2522
ec403cf308eb Updated Doxygen documentation.
Florian Pose <fp@igh-essen.com>
parents: 2505
diff changeset
   856
 *
ec403cf308eb Updated Doxygen documentation.
Florian Pose <fp@igh-essen.com>
parents: 2505
diff changeset
   857
 * \return Zero on success, otherwise a negative error code.
2433
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   858
 */
2481
c99ff159b60d Added function attribute definition.
Florian Pose <fp@igh-essen.com>
parents: 2477
diff changeset
   859
static ATTRIBUTES int ec_ioctl_slave_sdo_download(
2433
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   860
        ec_master_t *master, /**< EtherCAT master. */
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   861
        void *arg /**< ioctl() argument. */
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   862
        )
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   863
{
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   864
    ec_ioctl_slave_sdo_download_t data;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   865
    uint8_t *sdo_data;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   866
    int retval;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   867
2719
94c9657e0bee Xenomai 2 to 3 migration says "RTDM drivers implementing differentiated ioctl() support for both domains should serve all real-time only requests from ioctl_rt(), returning -ENOSYS for any unrecognized request, which will cause the adaptive switch to take place automatically to the ioctl_nrt() handler. The ioctl_nrt() should then implement all requests which may be valid from the regular Linux domain exclusively."
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2712
diff changeset
   868
    if (ec_copy_from_user(&data, (void __user *) arg, sizeof(data))) {
2433
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   869
        return -EFAULT;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   870
    }
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   871
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   872
    if (!(sdo_data = kmalloc(data.data_size, GFP_KERNEL))) {
2487
ccafdf1e261f Fixed some warnings on 64 bit systems.
Florian Pose <fp@igh-essen.com>
parents: 2486
diff changeset
   873
        EC_MASTER_ERR(master, "Failed to allocate %zu bytes"
2433
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   874
                " for SDO download.\n", data.data_size);
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   875
        return -ENOMEM;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   876
    }
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   877
2719
94c9657e0bee Xenomai 2 to 3 migration says "RTDM drivers implementing differentiated ioctl() support for both domains should serve all real-time only requests from ioctl_rt(), returning -ENOSYS for any unrecognized request, which will cause the adaptive switch to take place automatically to the ioctl_nrt() handler. The ioctl_nrt() should then implement all requests which may be valid from the regular Linux domain exclusively."
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2712
diff changeset
   878
    if (ec_copy_from_user(sdo_data, (void __user *) data.data, data.data_size)) {
2433
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   879
        kfree(sdo_data);
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   880
        return -EFAULT;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   881
    }
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   882
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   883
    if (data.complete_access) {
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   884
        retval = ecrt_master_sdo_download_complete(master, data.slave_position,
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   885
                data.sdo_index, sdo_data, data.data_size, &data.abort_code);
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   886
    } else {
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   887
        retval = ecrt_master_sdo_download(master, data.slave_position,
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   888
                data.sdo_index, data.sdo_entry_subindex, sdo_data,
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   889
                data.data_size, &data.abort_code);
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   890
    }
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   891
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   892
    kfree(sdo_data);
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   893
2719
94c9657e0bee Xenomai 2 to 3 migration says "RTDM drivers implementing differentiated ioctl() support for both domains should serve all real-time only requests from ioctl_rt(), returning -ENOSYS for any unrecognized request, which will cause the adaptive switch to take place automatically to the ioctl_nrt() handler. The ioctl_nrt() should then implement all requests which may be valid from the regular Linux domain exclusively."
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2712
diff changeset
   894
    if (ec_copy_to_user((void __user *) arg, &data, sizeof(data))) {
2433
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   895
        retval = -EFAULT;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   896
    }
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   897
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   898
    return retval;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   899
}
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   900
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   901
/*****************************************************************************/
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   902
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   903
/** Read a slave's SII.
2522
ec403cf308eb Updated Doxygen documentation.
Florian Pose <fp@igh-essen.com>
parents: 2505
diff changeset
   904
 *
ec403cf308eb Updated Doxygen documentation.
Florian Pose <fp@igh-essen.com>
parents: 2505
diff changeset
   905
 * \return Zero on success, otherwise a negative error code.
2433
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   906
 */
2481
c99ff159b60d Added function attribute definition.
Florian Pose <fp@igh-essen.com>
parents: 2477
diff changeset
   907
static ATTRIBUTES int ec_ioctl_slave_sii_read(
2433
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   908
        ec_master_t *master, /**< EtherCAT master. */
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   909
        void *arg /**< ioctl() argument. */
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   910
        )
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   911
{
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   912
    ec_ioctl_slave_sii_t data;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   913
    const ec_slave_t *slave;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   914
    int retval;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   915
2719
94c9657e0bee Xenomai 2 to 3 migration says "RTDM drivers implementing differentiated ioctl() support for both domains should serve all real-time only requests from ioctl_rt(), returning -ENOSYS for any unrecognized request, which will cause the adaptive switch to take place automatically to the ioctl_nrt() handler. The ioctl_nrt() should then implement all requests which may be valid from the regular Linux domain exclusively."
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2712
diff changeset
   916
    if (ec_copy_from_user(&data, (void __user *) arg, sizeof(data))) {
2433
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   917
        return -EFAULT;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   918
    }
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   919
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   920
    if (down_interruptible(&master->master_sem))
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   921
        return -EINTR;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   922
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   923
    if (!(slave = ec_master_find_slave_const(
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   924
                    master, 0, data.slave_position))) {
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   925
        up(&master->master_sem);
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   926
        EC_MASTER_ERR(master, "Slave %u does not exist!\n",
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   927
                data.slave_position);
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   928
        return -EINVAL;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   929
    }
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   930
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   931
    if (!data.nwords
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   932
            || data.offset + data.nwords > slave->sii_nwords) {
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   933
        up(&master->master_sem);
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   934
        EC_SLAVE_ERR(slave, "Invalid SII read offset/size %u/%u for slave SII"
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   935
                " size %zu!\n", data.offset, data.nwords, slave->sii_nwords);
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   936
        return -EINVAL;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   937
    }
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   938
2719
94c9657e0bee Xenomai 2 to 3 migration says "RTDM drivers implementing differentiated ioctl() support for both domains should serve all real-time only requests from ioctl_rt(), returning -ENOSYS for any unrecognized request, which will cause the adaptive switch to take place automatically to the ioctl_nrt() handler. The ioctl_nrt() should then implement all requests which may be valid from the regular Linux domain exclusively."
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2712
diff changeset
   939
    if (ec_copy_to_user((void __user *) data.words,
2433
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   940
                slave->sii_words + data.offset, data.nwords * 2))
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   941
        retval = -EFAULT;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   942
    else
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   943
        retval = 0;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   944
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   945
    up(&master->master_sem);
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   946
    return retval;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   947
}
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   948
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   949
/*****************************************************************************/
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   950
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   951
/** Write a slave's SII.
2522
ec403cf308eb Updated Doxygen documentation.
Florian Pose <fp@igh-essen.com>
parents: 2505
diff changeset
   952
 *
ec403cf308eb Updated Doxygen documentation.
Florian Pose <fp@igh-essen.com>
parents: 2505
diff changeset
   953
 * \return Zero on success, otherwise a negative error code.
2433
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   954
 */
2481
c99ff159b60d Added function attribute definition.
Florian Pose <fp@igh-essen.com>
parents: 2477
diff changeset
   955
static ATTRIBUTES int ec_ioctl_slave_sii_write(
2433
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   956
        ec_master_t *master, /**< EtherCAT master. */
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   957
        void *arg /**< ioctl() argument. */
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   958
        )
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   959
{
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   960
    ec_ioctl_slave_sii_t data;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   961
    ec_slave_t *slave;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   962
    unsigned int byte_size;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   963
    uint16_t *words;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   964
    ec_sii_write_request_t request;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   965
2719
94c9657e0bee Xenomai 2 to 3 migration says "RTDM drivers implementing differentiated ioctl() support for both domains should serve all real-time only requests from ioctl_rt(), returning -ENOSYS for any unrecognized request, which will cause the adaptive switch to take place automatically to the ioctl_nrt() handler. The ioctl_nrt() should then implement all requests which may be valid from the regular Linux domain exclusively."
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2712
diff changeset
   966
    if (ec_copy_from_user(&data, (void __user *) arg, sizeof(data))) {
2433
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   967
        return -EFAULT;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   968
    }
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   969
2467
74ede087bc85 Using common waitqueue for requests.
Florian Pose <fp@igh-essen.com>
parents: 2464
diff changeset
   970
    if (!data.nwords) {
2433
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   971
        return 0;
2467
74ede087bc85 Using common waitqueue for requests.
Florian Pose <fp@igh-essen.com>
parents: 2464
diff changeset
   972
    }
2433
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   973
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   974
    byte_size = sizeof(uint16_t) * data.nwords;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   975
    if (!(words = kmalloc(byte_size, GFP_KERNEL))) {
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   976
        EC_MASTER_ERR(master, "Failed to allocate %u bytes"
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   977
                " for SII contents.\n", byte_size);
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   978
        return -ENOMEM;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   979
    }
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   980
2719
94c9657e0bee Xenomai 2 to 3 migration says "RTDM drivers implementing differentiated ioctl() support for both domains should serve all real-time only requests from ioctl_rt(), returning -ENOSYS for any unrecognized request, which will cause the adaptive switch to take place automatically to the ioctl_nrt() handler. The ioctl_nrt() should then implement all requests which may be valid from the regular Linux domain exclusively."
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2712
diff changeset
   981
    if (ec_copy_from_user(words,
2433
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   982
                (void __user *) data.words, byte_size)) {
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   983
        kfree(words);
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   984
        return -EFAULT;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   985
    }
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   986
2467
74ede087bc85 Using common waitqueue for requests.
Florian Pose <fp@igh-essen.com>
parents: 2464
diff changeset
   987
    if (down_interruptible(&master->master_sem)) {
74ede087bc85 Using common waitqueue for requests.
Florian Pose <fp@igh-essen.com>
parents: 2464
diff changeset
   988
        kfree(words);
2433
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   989
        return -EINTR;
2467
74ede087bc85 Using common waitqueue for requests.
Florian Pose <fp@igh-essen.com>
parents: 2464
diff changeset
   990
    }
2433
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   991
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   992
    if (!(slave = ec_master_find_slave(
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   993
                    master, 0, data.slave_position))) {
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   994
        up(&master->master_sem);
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   995
        EC_MASTER_ERR(master, "Slave %u does not exist!\n",
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   996
                data.slave_position);
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   997
        kfree(words);
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   998
        return -EINVAL;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   999
    }
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1000
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1001
    // init SII write request
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1002
    INIT_LIST_HEAD(&request.list);
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1003
    request.slave = slave;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1004
    request.words = words;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1005
    request.offset = data.offset;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1006
    request.nwords = data.nwords;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1007
    request.state = EC_INT_REQUEST_QUEUED;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1008
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1009
    // schedule SII write request.
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1010
    list_add_tail(&request.list, &master->sii_requests);
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1011
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1012
    up(&master->master_sem);
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1013
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1014
    // wait for processing through FSM
2467
74ede087bc85 Using common waitqueue for requests.
Florian Pose <fp@igh-essen.com>
parents: 2464
diff changeset
  1015
    if (wait_event_interruptible(master->request_queue,
2433
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1016
                request.state != EC_INT_REQUEST_QUEUED)) {
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1017
        // interrupted by signal
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1018
        down(&master->master_sem);
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1019
        if (request.state == EC_INT_REQUEST_QUEUED) {
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1020
            // abort request
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1021
            list_del(&request.list);
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1022
            up(&master->master_sem);
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1023
            kfree(words);
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1024
            return -EINTR;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1025
        }
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1026
        up(&master->master_sem);
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1027
    }
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1028
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1029
    // wait until master FSM has finished processing
2467
74ede087bc85 Using common waitqueue for requests.
Florian Pose <fp@igh-essen.com>
parents: 2464
diff changeset
  1030
    wait_event(master->request_queue, request.state != EC_INT_REQUEST_BUSY);
2433
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1031
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1032
    kfree(words);
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1033
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1034
    return request.state == EC_INT_REQUEST_SUCCESS ? 0 : -EIO;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1035
}
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1036
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1037
/*****************************************************************************/
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1038
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1039
/** Read a slave's registers.
2522
ec403cf308eb Updated Doxygen documentation.
Florian Pose <fp@igh-essen.com>
parents: 2505
diff changeset
  1040
 *
ec403cf308eb Updated Doxygen documentation.
Florian Pose <fp@igh-essen.com>
parents: 2505
diff changeset
  1041
 * \return Zero on success, otherwise a negative error code.
2433
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1042
 */
2481
c99ff159b60d Added function attribute definition.
Florian Pose <fp@igh-essen.com>
parents: 2477
diff changeset
  1043
static ATTRIBUTES int ec_ioctl_slave_reg_read(
2433
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1044
        ec_master_t *master, /**< EtherCAT master. */
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1045
        void *arg /**< ioctl() argument. */
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1046
        )
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1047
{
2443
2c3ccdde3919 Added interface to read/write register contents; re-worked register requests.
Florian Pose <fp@igh-essen.com>
parents: 2438
diff changeset
  1048
    ec_ioctl_slave_reg_t io;
2433
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1049
    ec_slave_t *slave;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1050
    ec_reg_request_t request;
2443
2c3ccdde3919 Added interface to read/write register contents; re-worked register requests.
Florian Pose <fp@igh-essen.com>
parents: 2438
diff changeset
  1051
    int ret;
2c3ccdde3919 Added interface to read/write register contents; re-worked register requests.
Florian Pose <fp@igh-essen.com>
parents: 2438
diff changeset
  1052
2719
94c9657e0bee Xenomai 2 to 3 migration says "RTDM drivers implementing differentiated ioctl() support for both domains should serve all real-time only requests from ioctl_rt(), returning -ENOSYS for any unrecognized request, which will cause the adaptive switch to take place automatically to the ioctl_nrt() handler. The ioctl_nrt() should then implement all requests which may be valid from the regular Linux domain exclusively."
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2712
diff changeset
  1053
    if (ec_copy_from_user(&io, (void __user *) arg, sizeof(io))) {
2443
2c3ccdde3919 Added interface to read/write register contents; re-worked register requests.
Florian Pose <fp@igh-essen.com>
parents: 2438
diff changeset
  1054
        return -EFAULT;
2c3ccdde3919 Added interface to read/write register contents; re-worked register requests.
Florian Pose <fp@igh-essen.com>
parents: 2438
diff changeset
  1055
    }
2c3ccdde3919 Added interface to read/write register contents; re-worked register requests.
Florian Pose <fp@igh-essen.com>
parents: 2438
diff changeset
  1056
2c3ccdde3919 Added interface to read/write register contents; re-worked register requests.
Florian Pose <fp@igh-essen.com>
parents: 2438
diff changeset
  1057
    if (!io.size) {
2433
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1058
        return 0;
2443
2c3ccdde3919 Added interface to read/write register contents; re-worked register requests.
Florian Pose <fp@igh-essen.com>
parents: 2438
diff changeset
  1059
    }
2c3ccdde3919 Added interface to read/write register contents; re-worked register requests.
Florian Pose <fp@igh-essen.com>
parents: 2438
diff changeset
  1060
2c3ccdde3919 Added interface to read/write register contents; re-worked register requests.
Florian Pose <fp@igh-essen.com>
parents: 2438
diff changeset
  1061
    // init register request
2c3ccdde3919 Added interface to read/write register contents; re-worked register requests.
Florian Pose <fp@igh-essen.com>
parents: 2438
diff changeset
  1062
    ret = ec_reg_request_init(&request, io.size);
2c3ccdde3919 Added interface to read/write register contents; re-worked register requests.
Florian Pose <fp@igh-essen.com>
parents: 2438
diff changeset
  1063
    if (ret) {
2c3ccdde3919 Added interface to read/write register contents; re-worked register requests.
Florian Pose <fp@igh-essen.com>
parents: 2438
diff changeset
  1064
        return ret;
2c3ccdde3919 Added interface to read/write register contents; re-worked register requests.
Florian Pose <fp@igh-essen.com>
parents: 2438
diff changeset
  1065
    }
2c3ccdde3919 Added interface to read/write register contents; re-worked register requests.
Florian Pose <fp@igh-essen.com>
parents: 2438
diff changeset
  1066
2c3ccdde3919 Added interface to read/write register contents; re-worked register requests.
Florian Pose <fp@igh-essen.com>
parents: 2438
diff changeset
  1067
    ecrt_reg_request_read(&request, io.address, io.size);
2c3ccdde3919 Added interface to read/write register contents; re-worked register requests.
Florian Pose <fp@igh-essen.com>
parents: 2438
diff changeset
  1068
2c3ccdde3919 Added interface to read/write register contents; re-worked register requests.
Florian Pose <fp@igh-essen.com>
parents: 2438
diff changeset
  1069
    if (down_interruptible(&master->master_sem)) {
2c3ccdde3919 Added interface to read/write register contents; re-worked register requests.
Florian Pose <fp@igh-essen.com>
parents: 2438
diff changeset
  1070
        ec_reg_request_clear(&request);
2433
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1071
        return -EINTR;
2443
2c3ccdde3919 Added interface to read/write register contents; re-worked register requests.
Florian Pose <fp@igh-essen.com>
parents: 2438
diff changeset
  1072
    }
2433
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1073
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1074
    if (!(slave = ec_master_find_slave(
2443
2c3ccdde3919 Added interface to read/write register contents; re-worked register requests.
Florian Pose <fp@igh-essen.com>
parents: 2438
diff changeset
  1075
                    master, 0, io.slave_position))) {
2c3ccdde3919 Added interface to read/write register contents; re-worked register requests.
Florian Pose <fp@igh-essen.com>
parents: 2438
diff changeset
  1076
        up(&master->master_sem);
2c3ccdde3919 Added interface to read/write register contents; re-worked register requests.
Florian Pose <fp@igh-essen.com>
parents: 2438
diff changeset
  1077
        ec_reg_request_clear(&request);
2433
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1078
        EC_MASTER_ERR(master, "Slave %u does not exist!\n",
2443
2c3ccdde3919 Added interface to read/write register contents; re-worked register requests.
Florian Pose <fp@igh-essen.com>
parents: 2438
diff changeset
  1079
                io.slave_position);
2433
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1080
        return -EINVAL;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1081
    }
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1082
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1083
    // schedule request.
2443
2c3ccdde3919 Added interface to read/write register contents; re-worked register requests.
Florian Pose <fp@igh-essen.com>
parents: 2438
diff changeset
  1084
    list_add_tail(&request.list, &slave->reg_requests);
2433
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1085
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1086
    up(&master->master_sem);
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1087
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1088
    // wait for processing through FSM
2467
74ede087bc85 Using common waitqueue for requests.
Florian Pose <fp@igh-essen.com>
parents: 2464
diff changeset
  1089
    if (wait_event_interruptible(master->request_queue,
2433
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1090
                request.state != EC_INT_REQUEST_QUEUED)) {
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1091
        // interrupted by signal
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1092
        down(&master->master_sem);
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1093
        if (request.state == EC_INT_REQUEST_QUEUED) {
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1094
            // abort request
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1095
            list_del(&request.list);
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1096
            up(&master->master_sem);
2443
2c3ccdde3919 Added interface to read/write register contents; re-worked register requests.
Florian Pose <fp@igh-essen.com>
parents: 2438
diff changeset
  1097
            ec_reg_request_clear(&request);
2433
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1098
            return -EINTR;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1099
        }
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1100
        up(&master->master_sem);
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1101
    }
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1102
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1103
    // wait until master FSM has finished processing
2467
74ede087bc85 Using common waitqueue for requests.
Florian Pose <fp@igh-essen.com>
parents: 2464
diff changeset
  1104
    wait_event(master->request_queue, request.state != EC_INT_REQUEST_BUSY);
2433
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1105
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1106
    if (request.state == EC_INT_REQUEST_SUCCESS) {
2719
94c9657e0bee Xenomai 2 to 3 migration says "RTDM drivers implementing differentiated ioctl() support for both domains should serve all real-time only requests from ioctl_rt(), returning -ENOSYS for any unrecognized request, which will cause the adaptive switch to take place automatically to the ioctl_nrt() handler. The ioctl_nrt() should then implement all requests which may be valid from the regular Linux domain exclusively."
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2712
diff changeset
  1107
        if (ec_copy_to_user((void __user *) io.data, request.data, io.size)) {
2433
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1108
            return -EFAULT;
2443
2c3ccdde3919 Added interface to read/write register contents; re-worked register requests.
Florian Pose <fp@igh-essen.com>
parents: 2438
diff changeset
  1109
        }
2c3ccdde3919 Added interface to read/write register contents; re-worked register requests.
Florian Pose <fp@igh-essen.com>
parents: 2438
diff changeset
  1110
    }
2c3ccdde3919 Added interface to read/write register contents; re-worked register requests.
Florian Pose <fp@igh-essen.com>
parents: 2438
diff changeset
  1111
    ec_reg_request_clear(&request);
2433
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1112
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1113
    return request.state == EC_INT_REQUEST_SUCCESS ? 0 : -EIO;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1114
}
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1115
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1116
/*****************************************************************************/
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1117
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1118
/** Write a slave's registers.
2522
ec403cf308eb Updated Doxygen documentation.
Florian Pose <fp@igh-essen.com>
parents: 2505
diff changeset
  1119
 *
ec403cf308eb Updated Doxygen documentation.
Florian Pose <fp@igh-essen.com>
parents: 2505
diff changeset
  1120
 * \return Zero on success, otherwise a negative error code.
2433
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1121
 */
2481
c99ff159b60d Added function attribute definition.
Florian Pose <fp@igh-essen.com>
parents: 2477
diff changeset
  1122
static ATTRIBUTES int ec_ioctl_slave_reg_write(
2433
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1123
        ec_master_t *master, /**< EtherCAT master. */
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1124
        void *arg /**< ioctl() argument. */
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1125
        )
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1126
{
2443
2c3ccdde3919 Added interface to read/write register contents; re-worked register requests.
Florian Pose <fp@igh-essen.com>
parents: 2438
diff changeset
  1127
    ec_ioctl_slave_reg_t io;
2433
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1128
    ec_slave_t *slave;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1129
    ec_reg_request_t request;
2443
2c3ccdde3919 Added interface to read/write register contents; re-worked register requests.
Florian Pose <fp@igh-essen.com>
parents: 2438
diff changeset
  1130
    int ret;
2c3ccdde3919 Added interface to read/write register contents; re-worked register requests.
Florian Pose <fp@igh-essen.com>
parents: 2438
diff changeset
  1131
2719
94c9657e0bee Xenomai 2 to 3 migration says "RTDM drivers implementing differentiated ioctl() support for both domains should serve all real-time only requests from ioctl_rt(), returning -ENOSYS for any unrecognized request, which will cause the adaptive switch to take place automatically to the ioctl_nrt() handler. The ioctl_nrt() should then implement all requests which may be valid from the regular Linux domain exclusively."
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2712
diff changeset
  1132
    if (ec_copy_from_user(&io, (void __user *) arg, sizeof(io))) {
2443
2c3ccdde3919 Added interface to read/write register contents; re-worked register requests.
Florian Pose <fp@igh-essen.com>
parents: 2438
diff changeset
  1133
        return -EFAULT;
2c3ccdde3919 Added interface to read/write register contents; re-worked register requests.
Florian Pose <fp@igh-essen.com>
parents: 2438
diff changeset
  1134
    }
2c3ccdde3919 Added interface to read/write register contents; re-worked register requests.
Florian Pose <fp@igh-essen.com>
parents: 2438
diff changeset
  1135
2c3ccdde3919 Added interface to read/write register contents; re-worked register requests.
Florian Pose <fp@igh-essen.com>
parents: 2438
diff changeset
  1136
    if (!io.size) {
2433
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1137
        return 0;
2443
2c3ccdde3919 Added interface to read/write register contents; re-worked register requests.
Florian Pose <fp@igh-essen.com>
parents: 2438
diff changeset
  1138
    }
2c3ccdde3919 Added interface to read/write register contents; re-worked register requests.
Florian Pose <fp@igh-essen.com>
parents: 2438
diff changeset
  1139
2c3ccdde3919 Added interface to read/write register contents; re-worked register requests.
Florian Pose <fp@igh-essen.com>
parents: 2438
diff changeset
  1140
    // init register request
2c3ccdde3919 Added interface to read/write register contents; re-worked register requests.
Florian Pose <fp@igh-essen.com>
parents: 2438
diff changeset
  1141
    ret = ec_reg_request_init(&request, io.size);
2c3ccdde3919 Added interface to read/write register contents; re-worked register requests.
Florian Pose <fp@igh-essen.com>
parents: 2438
diff changeset
  1142
    if (ret) {
2c3ccdde3919 Added interface to read/write register contents; re-worked register requests.
Florian Pose <fp@igh-essen.com>
parents: 2438
diff changeset
  1143
        return ret;
2c3ccdde3919 Added interface to read/write register contents; re-worked register requests.
Florian Pose <fp@igh-essen.com>
parents: 2438
diff changeset
  1144
    }
2c3ccdde3919 Added interface to read/write register contents; re-worked register requests.
Florian Pose <fp@igh-essen.com>
parents: 2438
diff changeset
  1145
2719
94c9657e0bee Xenomai 2 to 3 migration says "RTDM drivers implementing differentiated ioctl() support for both domains should serve all real-time only requests from ioctl_rt(), returning -ENOSYS for any unrecognized request, which will cause the adaptive switch to take place automatically to the ioctl_nrt() handler. The ioctl_nrt() should then implement all requests which may be valid from the regular Linux domain exclusively."
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2712
diff changeset
  1146
    if (ec_copy_from_user(request.data, (void __user *) io.data, io.size)) {
2443
2c3ccdde3919 Added interface to read/write register contents; re-worked register requests.
Florian Pose <fp@igh-essen.com>
parents: 2438
diff changeset
  1147
        ec_reg_request_clear(&request);
2c3ccdde3919 Added interface to read/write register contents; re-worked register requests.
Florian Pose <fp@igh-essen.com>
parents: 2438
diff changeset
  1148
        return -EFAULT;
2c3ccdde3919 Added interface to read/write register contents; re-worked register requests.
Florian Pose <fp@igh-essen.com>
parents: 2438
diff changeset
  1149
    }
2c3ccdde3919 Added interface to read/write register contents; re-worked register requests.
Florian Pose <fp@igh-essen.com>
parents: 2438
diff changeset
  1150
2c3ccdde3919 Added interface to read/write register contents; re-worked register requests.
Florian Pose <fp@igh-essen.com>
parents: 2438
diff changeset
  1151
    ecrt_reg_request_write(&request, io.address, io.size);
2c3ccdde3919 Added interface to read/write register contents; re-worked register requests.
Florian Pose <fp@igh-essen.com>
parents: 2438
diff changeset
  1152
2c3ccdde3919 Added interface to read/write register contents; re-worked register requests.
Florian Pose <fp@igh-essen.com>
parents: 2438
diff changeset
  1153
    if (down_interruptible(&master->master_sem)) {
2c3ccdde3919 Added interface to read/write register contents; re-worked register requests.
Florian Pose <fp@igh-essen.com>
parents: 2438
diff changeset
  1154
        ec_reg_request_clear(&request);
2433
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1155
        return -EINTR;
2443
2c3ccdde3919 Added interface to read/write register contents; re-worked register requests.
Florian Pose <fp@igh-essen.com>
parents: 2438
diff changeset
  1156
    }
2433
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1157
2529
c7e1f2616a9d Implemented emergency register requests to analyze a broken bus.
Florian Pose <fp@igh-essen.com>
parents: 2522
diff changeset
  1158
    if (io.emergency) {
c7e1f2616a9d Implemented emergency register requests to analyze a broken bus.
Florian Pose <fp@igh-essen.com>
parents: 2522
diff changeset
  1159
        request.ring_position = io.slave_position;
c7e1f2616a9d Implemented emergency register requests to analyze a broken bus.
Florian Pose <fp@igh-essen.com>
parents: 2522
diff changeset
  1160
        // schedule request.
c7e1f2616a9d Implemented emergency register requests to analyze a broken bus.
Florian Pose <fp@igh-essen.com>
parents: 2522
diff changeset
  1161
        list_add_tail(&request.list, &master->emerg_reg_requests);
c7e1f2616a9d Implemented emergency register requests to analyze a broken bus.
Florian Pose <fp@igh-essen.com>
parents: 2522
diff changeset
  1162
    }
c7e1f2616a9d Implemented emergency register requests to analyze a broken bus.
Florian Pose <fp@igh-essen.com>
parents: 2522
diff changeset
  1163
    else {
c7e1f2616a9d Implemented emergency register requests to analyze a broken bus.
Florian Pose <fp@igh-essen.com>
parents: 2522
diff changeset
  1164
        if (!(slave = ec_master_find_slave(master, 0, io.slave_position))) {
c7e1f2616a9d Implemented emergency register requests to analyze a broken bus.
Florian Pose <fp@igh-essen.com>
parents: 2522
diff changeset
  1165
            up(&master->master_sem);
c7e1f2616a9d Implemented emergency register requests to analyze a broken bus.
Florian Pose <fp@igh-essen.com>
parents: 2522
diff changeset
  1166
            ec_reg_request_clear(&request);
c7e1f2616a9d Implemented emergency register requests to analyze a broken bus.
Florian Pose <fp@igh-essen.com>
parents: 2522
diff changeset
  1167
            EC_MASTER_ERR(master, "Slave %u does not exist!\n",
c7e1f2616a9d Implemented emergency register requests to analyze a broken bus.
Florian Pose <fp@igh-essen.com>
parents: 2522
diff changeset
  1168
                    io.slave_position);
c7e1f2616a9d Implemented emergency register requests to analyze a broken bus.
Florian Pose <fp@igh-essen.com>
parents: 2522
diff changeset
  1169
            return -EINVAL;
c7e1f2616a9d Implemented emergency register requests to analyze a broken bus.
Florian Pose <fp@igh-essen.com>
parents: 2522
diff changeset
  1170
        }
c7e1f2616a9d Implemented emergency register requests to analyze a broken bus.
Florian Pose <fp@igh-essen.com>
parents: 2522
diff changeset
  1171
c7e1f2616a9d Implemented emergency register requests to analyze a broken bus.
Florian Pose <fp@igh-essen.com>
parents: 2522
diff changeset
  1172
        // schedule request.
c7e1f2616a9d Implemented emergency register requests to analyze a broken bus.
Florian Pose <fp@igh-essen.com>
parents: 2522
diff changeset
  1173
        list_add_tail(&request.list, &slave->reg_requests);
c7e1f2616a9d Implemented emergency register requests to analyze a broken bus.
Florian Pose <fp@igh-essen.com>
parents: 2522
diff changeset
  1174
    }
2433
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1175
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1176
    up(&master->master_sem);
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1177
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1178
    // wait for processing through FSM
2467
74ede087bc85 Using common waitqueue for requests.
Florian Pose <fp@igh-essen.com>
parents: 2464
diff changeset
  1179
    if (wait_event_interruptible(master->request_queue,
2433
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1180
                request.state != EC_INT_REQUEST_QUEUED)) {
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1181
        // interrupted by signal
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1182
        down(&master->master_sem);
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1183
        if (request.state == EC_INT_REQUEST_QUEUED) {
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1184
            // abort request
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1185
            list_del(&request.list);
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1186
            up(&master->master_sem);
2443
2c3ccdde3919 Added interface to read/write register contents; re-worked register requests.
Florian Pose <fp@igh-essen.com>
parents: 2438
diff changeset
  1187
            ec_reg_request_clear(&request);
2433
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1188
            return -EINTR;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1189
        }
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1190
        up(&master->master_sem);
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1191
    }
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1192
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1193
    // wait until master FSM has finished processing
2467
74ede087bc85 Using common waitqueue for requests.
Florian Pose <fp@igh-essen.com>
parents: 2464
diff changeset
  1194
    wait_event(master->request_queue, request.state != EC_INT_REQUEST_BUSY);
2443
2c3ccdde3919 Added interface to read/write register contents; re-worked register requests.
Florian Pose <fp@igh-essen.com>
parents: 2438
diff changeset
  1195
2c3ccdde3919 Added interface to read/write register contents; re-worked register requests.
Florian Pose <fp@igh-essen.com>
parents: 2438
diff changeset
  1196
    ec_reg_request_clear(&request);
2433
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1197
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1198
    return request.state == EC_INT_REQUEST_SUCCESS ? 0 : -EIO;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1199
}
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1200
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1201
/*****************************************************************************/
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1202
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1203
/** Get slave configuration information.
2522
ec403cf308eb Updated Doxygen documentation.
Florian Pose <fp@igh-essen.com>
parents: 2505
diff changeset
  1204
 *
ec403cf308eb Updated Doxygen documentation.
Florian Pose <fp@igh-essen.com>
parents: 2505
diff changeset
  1205
 * \return Zero on success, otherwise a negative error code.
2433
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1206
 */
2481
c99ff159b60d Added function attribute definition.
Florian Pose <fp@igh-essen.com>
parents: 2477
diff changeset
  1207
static ATTRIBUTES int ec_ioctl_config(
2433
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1208
        ec_master_t *master, /**< EtherCAT master. */
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1209
        void *arg /**< ioctl() argument. */
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1210
        )
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1211
{
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1212
    ec_ioctl_config_t data;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1213
    const ec_slave_config_t *sc;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1214
    uint8_t i;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1215
2719
94c9657e0bee Xenomai 2 to 3 migration says "RTDM drivers implementing differentiated ioctl() support for both domains should serve all real-time only requests from ioctl_rt(), returning -ENOSYS for any unrecognized request, which will cause the adaptive switch to take place automatically to the ioctl_nrt() handler. The ioctl_nrt() should then implement all requests which may be valid from the regular Linux domain exclusively."
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2712
diff changeset
  1216
    if (ec_copy_from_user(&data, (void __user *) arg, sizeof(data))) {
2433
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1217
        return -EFAULT;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1218
    }
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1219
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1220
    if (down_interruptible(&master->master_sem))
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1221
        return -EINTR;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1222
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1223
    if (!(sc = ec_master_get_config_const(
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1224
                    master, data.config_index))) {
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1225
        up(&master->master_sem);
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1226
        EC_MASTER_ERR(master, "Slave config %u does not exist!\n",
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1227
                data.config_index);
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1228
        return -EINVAL;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1229
    }
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1230
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1231
    data.alias = sc->alias;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1232
    data.position = sc->position;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1233
    data.vendor_id = sc->vendor_id;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1234
    data.product_code = sc->product_code;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1235
    for (i = 0; i < EC_MAX_SYNC_MANAGERS; i++) {
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1236
        data.syncs[i].dir = sc->sync_configs[i].dir;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1237
        data.syncs[i].watchdog_mode = sc->sync_configs[i].watchdog_mode;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1238
        data.syncs[i].pdo_count =
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1239
            ec_pdo_list_count(&sc->sync_configs[i].pdos);
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1240
    }
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1241
    data.watchdog_divider = sc->watchdog_divider;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1242
    data.watchdog_intervals = sc->watchdog_intervals;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1243
    data.sdo_count = ec_slave_config_sdo_count(sc);
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1244
    data.idn_count = ec_slave_config_idn_count(sc);
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1245
    data.slave_position = sc->slave ? sc->slave->ring_position : -1;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1246
    data.dc_assign_activate = sc->dc_assign_activate;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1247
    for (i = 0; i < EC_SYNC_SIGNAL_COUNT; i++) {
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1248
        data.dc_sync[i] = sc->dc_sync[i];
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1249
    }
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1250
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1251
    up(&master->master_sem);
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1252
2719
94c9657e0bee Xenomai 2 to 3 migration says "RTDM drivers implementing differentiated ioctl() support for both domains should serve all real-time only requests from ioctl_rt(), returning -ENOSYS for any unrecognized request, which will cause the adaptive switch to take place automatically to the ioctl_nrt() handler. The ioctl_nrt() should then implement all requests which may be valid from the regular Linux domain exclusively."
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2712
diff changeset
  1253
    if (ec_copy_to_user((void __user *) arg, &data, sizeof(data)))
2433
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1254
        return -EFAULT;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1255
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1256
    return 0;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1257
}
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1258
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1259
/*****************************************************************************/
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1260
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1261
/** Get slave configuration PDO information.
2522
ec403cf308eb Updated Doxygen documentation.
Florian Pose <fp@igh-essen.com>
parents: 2505
diff changeset
  1262
 *
ec403cf308eb Updated Doxygen documentation.
Florian Pose <fp@igh-essen.com>
parents: 2505
diff changeset
  1263
 * \return Zero on success, otherwise a negative error code.
2433
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1264
 */
2481
c99ff159b60d Added function attribute definition.
Florian Pose <fp@igh-essen.com>
parents: 2477
diff changeset
  1265
static ATTRIBUTES int ec_ioctl_config_pdo(
2433
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1266
        ec_master_t *master, /**< EtherCAT master. */
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1267
        void *arg /**< ioctl() argument. */
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1268
        )
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1269
{
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1270
    ec_ioctl_config_pdo_t data;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1271
    const ec_slave_config_t *sc;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1272
    const ec_pdo_t *pdo;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1273
2719
94c9657e0bee Xenomai 2 to 3 migration says "RTDM drivers implementing differentiated ioctl() support for both domains should serve all real-time only requests from ioctl_rt(), returning -ENOSYS for any unrecognized request, which will cause the adaptive switch to take place automatically to the ioctl_nrt() handler. The ioctl_nrt() should then implement all requests which may be valid from the regular Linux domain exclusively."
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2712
diff changeset
  1274
    if (ec_copy_from_user(&data, (void __user *) arg, sizeof(data))) {
2433
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1275
        return -EFAULT;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1276
    }
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1277
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1278
    if (data.sync_index >= EC_MAX_SYNC_MANAGERS) {
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1279
        EC_MASTER_ERR(master, "Invalid sync manager index %u!\n",
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1280
                data.sync_index);
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1281
        return -EINVAL;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1282
    }
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1283
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1284
    if (down_interruptible(&master->master_sem))
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1285
        return -EINTR;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1286
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1287
    if (!(sc = ec_master_get_config_const(
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1288
                    master, data.config_index))) {
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1289
        up(&master->master_sem);
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1290
        EC_MASTER_ERR(master, "Slave config %u does not exist!\n",
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1291
                data.config_index);
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1292
        return -EINVAL;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1293
    }
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1294
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1295
    if (!(pdo = ec_pdo_list_find_pdo_by_pos_const(
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1296
                    &sc->sync_configs[data.sync_index].pdos,
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1297
                    data.pdo_pos))) {
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1298
        up(&master->master_sem);
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1299
        EC_MASTER_ERR(master, "Invalid PDO position!\n");
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1300
        return -EINVAL;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1301
    }
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1302
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1303
    data.index = pdo->index;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1304
    data.entry_count = ec_pdo_entry_count(pdo);
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1305
    ec_ioctl_strcpy(data.name, pdo->name);
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1306
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1307
    up(&master->master_sem);
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1308
2719
94c9657e0bee Xenomai 2 to 3 migration says "RTDM drivers implementing differentiated ioctl() support for both domains should serve all real-time only requests from ioctl_rt(), returning -ENOSYS for any unrecognized request, which will cause the adaptive switch to take place automatically to the ioctl_nrt() handler. The ioctl_nrt() should then implement all requests which may be valid from the regular Linux domain exclusively."
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2712
diff changeset
  1309
    if (ec_copy_to_user((void __user *) arg, &data, sizeof(data)))
2433
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1310
        return -EFAULT;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1311
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1312
    return 0;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1313
}
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1314
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1315
/*****************************************************************************/
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1316
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1317
/** Get slave configuration PDO entry information.
2522
ec403cf308eb Updated Doxygen documentation.
Florian Pose <fp@igh-essen.com>
parents: 2505
diff changeset
  1318
 *
ec403cf308eb Updated Doxygen documentation.
Florian Pose <fp@igh-essen.com>
parents: 2505
diff changeset
  1319
 * \return Zero on success, otherwise a negative error code.
2433
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1320
 */
2481
c99ff159b60d Added function attribute definition.
Florian Pose <fp@igh-essen.com>
parents: 2477
diff changeset
  1321
static ATTRIBUTES int ec_ioctl_config_pdo_entry(
2433
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1322
        ec_master_t *master, /**< EtherCAT master. */
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1323
        void *arg /**< ioctl() argument. */
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1324
        )
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1325
{
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1326
    ec_ioctl_config_pdo_entry_t data;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1327
    const ec_slave_config_t *sc;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1328
    const ec_pdo_t *pdo;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1329
    const ec_pdo_entry_t *entry;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1330
2719
94c9657e0bee Xenomai 2 to 3 migration says "RTDM drivers implementing differentiated ioctl() support for both domains should serve all real-time only requests from ioctl_rt(), returning -ENOSYS for any unrecognized request, which will cause the adaptive switch to take place automatically to the ioctl_nrt() handler. The ioctl_nrt() should then implement all requests which may be valid from the regular Linux domain exclusively."
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2712
diff changeset
  1331
    if (ec_copy_from_user(&data, (void __user *) arg, sizeof(data))) {
2433
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1332
        return -EFAULT;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1333
    }
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1334
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1335
    if (data.sync_index >= EC_MAX_SYNC_MANAGERS) {
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1336
        EC_MASTER_ERR(master, "Invalid sync manager index %u!\n",
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1337
                data.sync_index);
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1338
        return -EINVAL;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1339
    }
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1340
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1341
    if (down_interruptible(&master->master_sem))
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1342
        return -EINTR;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1343
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1344
    if (!(sc = ec_master_get_config_const(
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1345
                    master, data.config_index))) {
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1346
        up(&master->master_sem);
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1347
        EC_MASTER_ERR(master, "Slave config %u does not exist!\n",
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1348
                data.config_index);
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1349
        return -EINVAL;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1350
    }
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1351
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1352
    if (!(pdo = ec_pdo_list_find_pdo_by_pos_const(
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1353
                    &sc->sync_configs[data.sync_index].pdos,
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1354
                    data.pdo_pos))) {
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1355
        up(&master->master_sem);
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1356
        EC_MASTER_ERR(master, "Invalid PDO position!\n");
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1357
        return -EINVAL;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1358
    }
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1359
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1360
    if (!(entry = ec_pdo_find_entry_by_pos_const(
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1361
                    pdo, data.entry_pos))) {
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1362
        up(&master->master_sem);
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1363
        EC_MASTER_ERR(master, "Entry not found!\n");
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1364
        return -EINVAL;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1365
    }
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1366
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1367
    data.index = entry->index;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1368
    data.subindex = entry->subindex;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1369
    data.bit_length = entry->bit_length;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1370
    ec_ioctl_strcpy(data.name, entry->name);
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1371
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1372
    up(&master->master_sem);
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1373
2719
94c9657e0bee Xenomai 2 to 3 migration says "RTDM drivers implementing differentiated ioctl() support for both domains should serve all real-time only requests from ioctl_rt(), returning -ENOSYS for any unrecognized request, which will cause the adaptive switch to take place automatically to the ioctl_nrt() handler. The ioctl_nrt() should then implement all requests which may be valid from the regular Linux domain exclusively."
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2712
diff changeset
  1374
    if (ec_copy_to_user((void __user *) arg, &data, sizeof(data)))
2433
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1375
        return -EFAULT;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1376
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1377
    return 0;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1378
}
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1379
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1380
/*****************************************************************************/
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1381
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1382
/** Get slave configuration SDO information.
2522
ec403cf308eb Updated Doxygen documentation.
Florian Pose <fp@igh-essen.com>
parents: 2505
diff changeset
  1383
 *
ec403cf308eb Updated Doxygen documentation.
Florian Pose <fp@igh-essen.com>
parents: 2505
diff changeset
  1384
 * \return Zero on success, otherwise a negative error code.
2433
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1385
 */
2481
c99ff159b60d Added function attribute definition.
Florian Pose <fp@igh-essen.com>
parents: 2477
diff changeset
  1386
static ATTRIBUTES int ec_ioctl_config_sdo(
2433
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1387
        ec_master_t *master, /**< EtherCAT master. */
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1388
        void *arg /**< ioctl() argument. */
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1389
        )
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1390
{
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1391
    ec_ioctl_config_sdo_t *ioctl;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1392
    const ec_slave_config_t *sc;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1393
    const ec_sdo_request_t *req;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1394
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1395
    if (!(ioctl = kmalloc(sizeof(*ioctl), GFP_KERNEL))) {
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1396
        return -ENOMEM;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1397
    }
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1398
2719
94c9657e0bee Xenomai 2 to 3 migration says "RTDM drivers implementing differentiated ioctl() support for both domains should serve all real-time only requests from ioctl_rt(), returning -ENOSYS for any unrecognized request, which will cause the adaptive switch to take place automatically to the ioctl_nrt() handler. The ioctl_nrt() should then implement all requests which may be valid from the regular Linux domain exclusively."
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2712
diff changeset
  1399
    if (ec_copy_from_user(ioctl, (void __user *) arg, sizeof(*ioctl))) {
2433
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1400
        kfree(ioctl);
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1401
        return -EFAULT;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1402
    }
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1403
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1404
    if (down_interruptible(&master->master_sem)) {
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1405
        kfree(ioctl);
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1406
        return -EINTR;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1407
    }
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1408
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1409
    if (!(sc = ec_master_get_config_const(
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1410
                    master, ioctl->config_index))) {
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1411
        up(&master->master_sem);
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1412
        EC_MASTER_ERR(master, "Slave config %u does not exist!\n",
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1413
                ioctl->config_index);
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1414
        kfree(ioctl);
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1415
        return -EINVAL;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1416
    }
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1417
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1418
    if (!(req = ec_slave_config_get_sdo_by_pos_const(
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1419
                    sc, ioctl->sdo_pos))) {
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1420
        up(&master->master_sem);
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1421
        EC_MASTER_ERR(master, "Invalid SDO position!\n");
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1422
        kfree(ioctl);
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1423
        return -EINVAL;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1424
    }
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1425
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1426
    ioctl->index = req->index;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1427
    ioctl->subindex = req->subindex;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1428
    ioctl->size = req->data_size;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1429
    memcpy(ioctl->data, req->data,
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1430
            min((u32) ioctl->size, (u32) EC_MAX_SDO_DATA_SIZE));
2435
4151f6f4c3e1 Show complete access flag in config view.
Florian Pose <fp@igh-essen.com>
parents: 2434
diff changeset
  1431
    ioctl->complete_access = req->complete_access;
2433
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1432
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1433
    up(&master->master_sem);
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1434
2719
94c9657e0bee Xenomai 2 to 3 migration says "RTDM drivers implementing differentiated ioctl() support for both domains should serve all real-time only requests from ioctl_rt(), returning -ENOSYS for any unrecognized request, which will cause the adaptive switch to take place automatically to the ioctl_nrt() handler. The ioctl_nrt() should then implement all requests which may be valid from the regular Linux domain exclusively."
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2712
diff changeset
  1435
    if (ec_copy_to_user((void __user *) arg, ioctl, sizeof(*ioctl))) {
2433
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1436
        kfree(ioctl);
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1437
        return -EFAULT;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1438
    }
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1439
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1440
    kfree(ioctl);
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1441
    return 0;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1442
}
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1443
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1444
/*****************************************************************************/
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1445
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1446
/** Get slave configuration IDN information.
2522
ec403cf308eb Updated Doxygen documentation.
Florian Pose <fp@igh-essen.com>
parents: 2505
diff changeset
  1447
 *
ec403cf308eb Updated Doxygen documentation.
Florian Pose <fp@igh-essen.com>
parents: 2505
diff changeset
  1448
 * \return Zero on success, otherwise a negative error code.
2433
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1449
 */
2481
c99ff159b60d Added function attribute definition.
Florian Pose <fp@igh-essen.com>
parents: 2477
diff changeset
  1450
static ATTRIBUTES int ec_ioctl_config_idn(
2433
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1451
        ec_master_t *master, /**< EtherCAT master. */
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1452
        void *arg /**< ioctl() argument. */
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1453
        )
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1454
{
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1455
    ec_ioctl_config_idn_t *ioctl;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1456
    const ec_slave_config_t *sc;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1457
    const ec_soe_request_t *req;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1458
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1459
    if (!(ioctl = kmalloc(sizeof(*ioctl), GFP_KERNEL))) {
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1460
        return -ENOMEM;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1461
    }
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1462
2719
94c9657e0bee Xenomai 2 to 3 migration says "RTDM drivers implementing differentiated ioctl() support for both domains should serve all real-time only requests from ioctl_rt(), returning -ENOSYS for any unrecognized request, which will cause the adaptive switch to take place automatically to the ioctl_nrt() handler. The ioctl_nrt() should then implement all requests which may be valid from the regular Linux domain exclusively."
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2712
diff changeset
  1463
    if (ec_copy_from_user(ioctl, (void __user *) arg, sizeof(*ioctl))) {
2433
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1464
        kfree(ioctl);
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1465
        return -EFAULT;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1466
    }
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1467
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1468
    if (down_interruptible(&master->master_sem)) {
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1469
        kfree(ioctl);
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1470
        return -EINTR;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1471
    }
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1472
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1473
    if (!(sc = ec_master_get_config_const(
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1474
                    master, ioctl->config_index))) {
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1475
        up(&master->master_sem);
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1476
        EC_MASTER_ERR(master, "Slave config %u does not exist!\n",
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1477
                ioctl->config_index);
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1478
        kfree(ioctl);
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1479
        return -EINVAL;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1480
    }
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1481
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1482
    if (!(req = ec_slave_config_get_idn_by_pos_const(
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1483
                    sc, ioctl->idn_pos))) {
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1484
        up(&master->master_sem);
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1485
        EC_MASTER_ERR(master, "Invalid IDN position!\n");
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1486
        kfree(ioctl);
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1487
        return -EINVAL;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1488
    }
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1489
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1490
    ioctl->drive_no = req->drive_no;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1491
    ioctl->idn = req->idn;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1492
    ioctl->state = req->state;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1493
    ioctl->size = req->data_size;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1494
    memcpy(ioctl->data, req->data,
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1495
            min((u32) ioctl->size, (u32) EC_MAX_IDN_DATA_SIZE));
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1496
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1497
    up(&master->master_sem);
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1498
2719
94c9657e0bee Xenomai 2 to 3 migration says "RTDM drivers implementing differentiated ioctl() support for both domains should serve all real-time only requests from ioctl_rt(), returning -ENOSYS for any unrecognized request, which will cause the adaptive switch to take place automatically to the ioctl_nrt() handler. The ioctl_nrt() should then implement all requests which may be valid from the regular Linux domain exclusively."
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2712
diff changeset
  1499
    if (ec_copy_to_user((void __user *) arg, ioctl, sizeof(*ioctl))) {
2433
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1500
        kfree(ioctl);
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1501
        return -EFAULT;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1502
    }
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1503
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1504
    kfree(ioctl);
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1505
    return 0;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1506
}
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1507
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1508
/*****************************************************************************/
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1509
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1510
#ifdef EC_EOE
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1511
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1512
/** Get EoE handler information.
2522
ec403cf308eb Updated Doxygen documentation.
Florian Pose <fp@igh-essen.com>
parents: 2505
diff changeset
  1513
 *
ec403cf308eb Updated Doxygen documentation.
Florian Pose <fp@igh-essen.com>
parents: 2505
diff changeset
  1514
 * \return Zero on success, otherwise a negative error code.
2433
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1515
 */
2481
c99ff159b60d Added function attribute definition.
Florian Pose <fp@igh-essen.com>
parents: 2477
diff changeset
  1516
static ATTRIBUTES int ec_ioctl_eoe_handler(
2433
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1517
        ec_master_t *master, /**< EtherCAT master. */
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1518
        void *arg /**< ioctl() argument. */
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1519
        )
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1520
{
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1521
    ec_ioctl_eoe_handler_t data;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1522
    const ec_eoe_t *eoe;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1523
2719
94c9657e0bee Xenomai 2 to 3 migration says "RTDM drivers implementing differentiated ioctl() support for both domains should serve all real-time only requests from ioctl_rt(), returning -ENOSYS for any unrecognized request, which will cause the adaptive switch to take place automatically to the ioctl_nrt() handler. The ioctl_nrt() should then implement all requests which may be valid from the regular Linux domain exclusively."
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2712
diff changeset
  1524
    if (ec_copy_from_user(&data, (void __user *) arg, sizeof(data))) {
2433
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1525
        return -EFAULT;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1526
    }
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1527
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1528
    if (down_interruptible(&master->master_sem))
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1529
        return -EINTR;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1530
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1531
    if (!(eoe = ec_master_get_eoe_handler_const(master, data.eoe_index))) {
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1532
        up(&master->master_sem);
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1533
        EC_MASTER_ERR(master, "EoE handler %u does not exist!\n",
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1534
                data.eoe_index);
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1535
        return -EINVAL;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1536
    }
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1537
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1538
    if (eoe->slave) {
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1539
        data.slave_position = eoe->slave->ring_position;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1540
    } else {
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1541
        data.slave_position = 0xffff;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1542
    }
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1543
    snprintf(data.name, EC_DATAGRAM_NAME_SIZE, eoe->dev->name);
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1544
    data.open = eoe->opened;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1545
    data.rx_bytes = eoe->stats.tx_bytes;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1546
    data.rx_rate = eoe->tx_rate;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1547
    data.tx_bytes = eoe->stats.rx_bytes;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1548
    data.tx_rate = eoe->tx_rate;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1549
    data.tx_queued_frames = eoe->tx_queued_frames;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1550
    data.tx_queue_size = eoe->tx_queue_size;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1551
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1552
    up(&master->master_sem);
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1553
2719
94c9657e0bee Xenomai 2 to 3 migration says "RTDM drivers implementing differentiated ioctl() support for both domains should serve all real-time only requests from ioctl_rt(), returning -ENOSYS for any unrecognized request, which will cause the adaptive switch to take place automatically to the ioctl_nrt() handler. The ioctl_nrt() should then implement all requests which may be valid from the regular Linux domain exclusively."
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2712
diff changeset
  1554
    if (ec_copy_to_user((void __user *) arg, &data, sizeof(data)))
2433
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1555
        return -EFAULT;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1556
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1557
    return 0;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1558
}
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1559
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1560
#endif
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1561
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1562
/*****************************************************************************/
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1563
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1564
/** Request the master from userspace.
2522
ec403cf308eb Updated Doxygen documentation.
Florian Pose <fp@igh-essen.com>
parents: 2505
diff changeset
  1565
 *
ec403cf308eb Updated Doxygen documentation.
Florian Pose <fp@igh-essen.com>
parents: 2505
diff changeset
  1566
 * \return Zero on success, otherwise a negative error code.
2433
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1567
 */
2481
c99ff159b60d Added function attribute definition.
Florian Pose <fp@igh-essen.com>
parents: 2477
diff changeset
  1568
static ATTRIBUTES int ec_ioctl_request(
2433
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1569
        ec_master_t *master, /**< EtherCAT master. */
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1570
        void *arg, /**< ioctl() argument. */
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1571
        ec_ioctl_context_t *ctx /**< Private data structure of file handle. */
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1572
        )
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1573
{
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1574
    ec_master_t *m;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1575
    int ret = 0;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1576
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1577
    m = ecrt_request_master_err(master->index);
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1578
    if (IS_ERR(m)) {
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1579
        ret = PTR_ERR(m);
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1580
    } else {
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1581
        ctx->requested = 1;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1582
    }
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1583
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1584
    return ret;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1585
}
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1586
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1587
/*****************************************************************************/
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1588
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1589
/** Create a domain.
2522
ec403cf308eb Updated Doxygen documentation.
Florian Pose <fp@igh-essen.com>
parents: 2505
diff changeset
  1590
 *
ec403cf308eb Updated Doxygen documentation.
Florian Pose <fp@igh-essen.com>
parents: 2505
diff changeset
  1591
 * \return Domain index on success, otherwise a negative error code.
2433
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1592
 */
2481
c99ff159b60d Added function attribute definition.
Florian Pose <fp@igh-essen.com>
parents: 2477
diff changeset
  1593
static ATTRIBUTES int ec_ioctl_create_domain(
2433
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1594
        ec_master_t *master, /**< EtherCAT master. */
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1595
        void *arg, /**< ioctl() argument. */
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1596
        ec_ioctl_context_t *ctx /**< Private data structure of file handle. */
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1597
        )
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1598
{
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1599
    ec_domain_t *domain;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1600
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1601
    if (unlikely(!ctx->requested))
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1602
        return -EPERM;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1603
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1604
    domain = ecrt_master_create_domain_err(master);
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1605
    if (IS_ERR(domain))
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1606
        return PTR_ERR(domain);
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1607
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1608
    return domain->index;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1609
}
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1610
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1611
/*****************************************************************************/
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1612
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1613
/** Create a slave configuration.
2522
ec403cf308eb Updated Doxygen documentation.
Florian Pose <fp@igh-essen.com>
parents: 2505
diff changeset
  1614
 *
ec403cf308eb Updated Doxygen documentation.
Florian Pose <fp@igh-essen.com>
parents: 2505
diff changeset
  1615
 * \return Zero on success, otherwise a negative error code.
2433
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1616
 */
2481
c99ff159b60d Added function attribute definition.
Florian Pose <fp@igh-essen.com>
parents: 2477
diff changeset
  1617
static ATTRIBUTES int ec_ioctl_create_slave_config(
2433
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1618
        ec_master_t *master, /**< EtherCAT master. */
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1619
        void *arg, /**< ioctl() argument. */
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1620
        ec_ioctl_context_t *ctx /**< Private data structure of file handle. */
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1621
        )
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1622
{
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1623
    ec_ioctl_config_t data;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1624
    ec_slave_config_t *sc, *entry;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1625
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1626
    if (unlikely(!ctx->requested))
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1627
        return -EPERM;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1628
2719
94c9657e0bee Xenomai 2 to 3 migration says "RTDM drivers implementing differentiated ioctl() support for both domains should serve all real-time only requests from ioctl_rt(), returning -ENOSYS for any unrecognized request, which will cause the adaptive switch to take place automatically to the ioctl_nrt() handler. The ioctl_nrt() should then implement all requests which may be valid from the regular Linux domain exclusively."
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2712
diff changeset
  1629
    if (ec_copy_from_user(&data, (void __user *) arg, sizeof(data))) {
2433
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1630
        return -EFAULT;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1631
    }
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1632
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1633
    sc = ecrt_master_slave_config_err(master, data.alias, data.position,
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1634
            data.vendor_id, data.product_code);
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1635
    if (IS_ERR(sc))
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1636
        return PTR_ERR(sc);
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1637
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1638
    data.config_index = 0;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1639
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1640
    if (down_interruptible(&master->master_sem))
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1641
        return -EINTR;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1642
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1643
    list_for_each_entry(entry, &master->configs, list) {
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1644
        if (entry == sc)
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1645
            break;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1646
        data.config_index++;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1647
    }
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1648
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1649
    up(&master->master_sem);
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1650
2719
94c9657e0bee Xenomai 2 to 3 migration says "RTDM drivers implementing differentiated ioctl() support for both domains should serve all real-time only requests from ioctl_rt(), returning -ENOSYS for any unrecognized request, which will cause the adaptive switch to take place automatically to the ioctl_nrt() handler. The ioctl_nrt() should then implement all requests which may be valid from the regular Linux domain exclusively."
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2712
diff changeset
  1651
    if (ec_copy_to_user((void __user *) arg, &data, sizeof(data)))
2433
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1652
        return -EFAULT;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1653
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1654
    return 0;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1655
}
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1656
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1657
/*****************************************************************************/
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1658
2447
e93efb4af231 Added interface to select the reference clock and to sync to it.
Florian Pose <fp@igh-essen.com>
parents: 2443
diff changeset
  1659
/** Select the DC reference clock.
2522
ec403cf308eb Updated Doxygen documentation.
Florian Pose <fp@igh-essen.com>
parents: 2505
diff changeset
  1660
 *
ec403cf308eb Updated Doxygen documentation.
Florian Pose <fp@igh-essen.com>
parents: 2505
diff changeset
  1661
 * \return Zero on success, otherwise a negative error code.
2447
e93efb4af231 Added interface to select the reference clock and to sync to it.
Florian Pose <fp@igh-essen.com>
parents: 2443
diff changeset
  1662
 */
2481
c99ff159b60d Added function attribute definition.
Florian Pose <fp@igh-essen.com>
parents: 2477
diff changeset
  1663
static ATTRIBUTES int ec_ioctl_select_ref_clock(
2447
e93efb4af231 Added interface to select the reference clock and to sync to it.
Florian Pose <fp@igh-essen.com>
parents: 2443
diff changeset
  1664
        ec_master_t *master, /**< EtherCAT master. */
e93efb4af231 Added interface to select the reference clock and to sync to it.
Florian Pose <fp@igh-essen.com>
parents: 2443
diff changeset
  1665
        void *arg, /**< ioctl() argument. */
e93efb4af231 Added interface to select the reference clock and to sync to it.
Florian Pose <fp@igh-essen.com>
parents: 2443
diff changeset
  1666
        ec_ioctl_context_t *ctx /**< Private data structure of file handle. */
e93efb4af231 Added interface to select the reference clock and to sync to it.
Florian Pose <fp@igh-essen.com>
parents: 2443
diff changeset
  1667
        )
e93efb4af231 Added interface to select the reference clock and to sync to it.
Florian Pose <fp@igh-essen.com>
parents: 2443
diff changeset
  1668
{
2487
ccafdf1e261f Fixed some warnings on 64 bit systems.
Florian Pose <fp@igh-essen.com>
parents: 2486
diff changeset
  1669
    unsigned long config_index = (unsigned long) arg;
2447
e93efb4af231 Added interface to select the reference clock and to sync to it.
Florian Pose <fp@igh-essen.com>
parents: 2443
diff changeset
  1670
    ec_slave_config_t *sc = NULL;
e93efb4af231 Added interface to select the reference clock and to sync to it.
Florian Pose <fp@igh-essen.com>
parents: 2443
diff changeset
  1671
    int ret = 0;
e93efb4af231 Added interface to select the reference clock and to sync to it.
Florian Pose <fp@igh-essen.com>
parents: 2443
diff changeset
  1672
e93efb4af231 Added interface to select the reference clock and to sync to it.
Florian Pose <fp@igh-essen.com>
parents: 2443
diff changeset
  1673
    if (unlikely(!ctx->requested)) {
e93efb4af231 Added interface to select the reference clock and to sync to it.
Florian Pose <fp@igh-essen.com>
parents: 2443
diff changeset
  1674
        ret = -EPERM;
e93efb4af231 Added interface to select the reference clock and to sync to it.
Florian Pose <fp@igh-essen.com>
parents: 2443
diff changeset
  1675
        goto out_return;
e93efb4af231 Added interface to select the reference clock and to sync to it.
Florian Pose <fp@igh-essen.com>
parents: 2443
diff changeset
  1676
    }
e93efb4af231 Added interface to select the reference clock and to sync to it.
Florian Pose <fp@igh-essen.com>
parents: 2443
diff changeset
  1677
e93efb4af231 Added interface to select the reference clock and to sync to it.
Florian Pose <fp@igh-essen.com>
parents: 2443
diff changeset
  1678
    if (down_interruptible(&master->master_sem)) {
e93efb4af231 Added interface to select the reference clock and to sync to it.
Florian Pose <fp@igh-essen.com>
parents: 2443
diff changeset
  1679
        ret = -EINTR;
e93efb4af231 Added interface to select the reference clock and to sync to it.
Florian Pose <fp@igh-essen.com>
parents: 2443
diff changeset
  1680
        goto out_return;
e93efb4af231 Added interface to select the reference clock and to sync to it.
Florian Pose <fp@igh-essen.com>
parents: 2443
diff changeset
  1681
    }
e93efb4af231 Added interface to select the reference clock and to sync to it.
Florian Pose <fp@igh-essen.com>
parents: 2443
diff changeset
  1682
e93efb4af231 Added interface to select the reference clock and to sync to it.
Florian Pose <fp@igh-essen.com>
parents: 2443
diff changeset
  1683
    if (config_index != 0xFFFFFFFF) {
e93efb4af231 Added interface to select the reference clock and to sync to it.
Florian Pose <fp@igh-essen.com>
parents: 2443
diff changeset
  1684
        if (!(sc = ec_master_get_config(master, config_index))) {
e93efb4af231 Added interface to select the reference clock and to sync to it.
Florian Pose <fp@igh-essen.com>
parents: 2443
diff changeset
  1685
            ret = -ENOENT;
e93efb4af231 Added interface to select the reference clock and to sync to it.
Florian Pose <fp@igh-essen.com>
parents: 2443
diff changeset
  1686
            goto out_up;
e93efb4af231 Added interface to select the reference clock and to sync to it.
Florian Pose <fp@igh-essen.com>
parents: 2443
diff changeset
  1687
        }
e93efb4af231 Added interface to select the reference clock and to sync to it.
Florian Pose <fp@igh-essen.com>
parents: 2443
diff changeset
  1688
    }
e93efb4af231 Added interface to select the reference clock and to sync to it.
Florian Pose <fp@igh-essen.com>
parents: 2443
diff changeset
  1689
e93efb4af231 Added interface to select the reference clock and to sync to it.
Florian Pose <fp@igh-essen.com>
parents: 2443
diff changeset
  1690
    ecrt_master_select_reference_clock(master, sc);
e93efb4af231 Added interface to select the reference clock and to sync to it.
Florian Pose <fp@igh-essen.com>
parents: 2443
diff changeset
  1691
e93efb4af231 Added interface to select the reference clock and to sync to it.
Florian Pose <fp@igh-essen.com>
parents: 2443
diff changeset
  1692
out_up:
e93efb4af231 Added interface to select the reference clock and to sync to it.
Florian Pose <fp@igh-essen.com>
parents: 2443
diff changeset
  1693
    up(&master->master_sem);
e93efb4af231 Added interface to select the reference clock and to sync to it.
Florian Pose <fp@igh-essen.com>
parents: 2443
diff changeset
  1694
out_return:
e93efb4af231 Added interface to select the reference clock and to sync to it.
Florian Pose <fp@igh-essen.com>
parents: 2443
diff changeset
  1695
    return ret;
e93efb4af231 Added interface to select the reference clock and to sync to it.
Florian Pose <fp@igh-essen.com>
parents: 2443
diff changeset
  1696
}
e93efb4af231 Added interface to select the reference clock and to sync to it.
Florian Pose <fp@igh-essen.com>
parents: 2443
diff changeset
  1697
e93efb4af231 Added interface to select the reference clock and to sync to it.
Florian Pose <fp@igh-essen.com>
parents: 2443
diff changeset
  1698
/*****************************************************************************/
e93efb4af231 Added interface to select the reference clock and to sync to it.
Florian Pose <fp@igh-essen.com>
parents: 2443
diff changeset
  1699
2433
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1700
/** Activates the master.
2522
ec403cf308eb Updated Doxygen documentation.
Florian Pose <fp@igh-essen.com>
parents: 2505
diff changeset
  1701
 *
ec403cf308eb Updated Doxygen documentation.
Florian Pose <fp@igh-essen.com>
parents: 2505
diff changeset
  1702
 * \return Zero on success, otherwise a negative error code.
2433
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1703
 */
2481
c99ff159b60d Added function attribute definition.
Florian Pose <fp@igh-essen.com>
parents: 2477
diff changeset
  1704
static ATTRIBUTES int ec_ioctl_activate(
2433
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1705
        ec_master_t *master, /**< EtherCAT master. */
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1706
        void *arg, /**< ioctl() argument. */
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1707
        ec_ioctl_context_t *ctx /**< Private data structure of file handle. */
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1708
        )
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1709
{
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1710
    ec_ioctl_master_activate_t io;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1711
    ec_domain_t *domain;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1712
    off_t offset;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1713
    int ret;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1714
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1715
    if (unlikely(!ctx->requested))
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1716
        return -EPERM;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1717
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1718
    /* Get the sum of the domains' process data sizes. */
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1719
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1720
    ctx->process_data_size = 0;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1721
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1722
    if (down_interruptible(&master->master_sem))
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1723
        return -EINTR;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1724
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1725
    list_for_each_entry(domain, &master->domains, list) {
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1726
        ctx->process_data_size += ecrt_domain_size(domain);
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1727
    }
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1728
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1729
    up(&master->master_sem);
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1730
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1731
    if (ctx->process_data_size) {
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1732
        ctx->process_data = vmalloc(ctx->process_data_size);
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1733
        if (!ctx->process_data) {
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1734
            ctx->process_data_size = 0;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1735
            return -ENOMEM;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1736
        }
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1737
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1738
        /* Set the memory as external process data memory for the
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1739
         * domains.
2443
2c3ccdde3919 Added interface to read/write register contents; re-worked register requests.
Florian Pose <fp@igh-essen.com>
parents: 2438
diff changeset
  1740
         */
2433
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1741
        offset = 0;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1742
        list_for_each_entry(domain, &master->domains, list) {
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1743
            ecrt_domain_external_memory(domain,
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1744
                    ctx->process_data + offset);
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1745
            offset += ecrt_domain_size(domain);
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1746
        }
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1747
    }
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1748
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1749
    io.process_data_size = ctx->process_data_size;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1750
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1751
#ifndef EC_IOCTL_RTDM
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1752
    ecrt_master_callbacks(master, ec_master_internal_send_cb,
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1753
            ec_master_internal_receive_cb, master);
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1754
#endif
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1755
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1756
    ret = ecrt_master_activate(master);
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1757
    if (ret < 0)
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1758
        return ret;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1759
2719
94c9657e0bee Xenomai 2 to 3 migration says "RTDM drivers implementing differentiated ioctl() support for both domains should serve all real-time only requests from ioctl_rt(), returning -ENOSYS for any unrecognized request, which will cause the adaptive switch to take place automatically to the ioctl_nrt() handler. The ioctl_nrt() should then implement all requests which may be valid from the regular Linux domain exclusively."
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2712
diff changeset
  1760
    if (ec_copy_to_user((void __user *) arg, &io,
2433
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1761
                sizeof(ec_ioctl_master_activate_t)))
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1762
        return -EFAULT;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1763
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1764
    return 0;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1765
}
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1766
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1767
/*****************************************************************************/
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1768
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1769
/** Deactivates the master.
2522
ec403cf308eb Updated Doxygen documentation.
Florian Pose <fp@igh-essen.com>
parents: 2505
diff changeset
  1770
 *
ec403cf308eb Updated Doxygen documentation.
Florian Pose <fp@igh-essen.com>
parents: 2505
diff changeset
  1771
 * \return Zero on success, otherwise a negative error code.
2433
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1772
 */
2481
c99ff159b60d Added function attribute definition.
Florian Pose <fp@igh-essen.com>
parents: 2477
diff changeset
  1773
static ATTRIBUTES int ec_ioctl_deactivate(
2433
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1774
        ec_master_t *master, /**< EtherCAT master. */
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1775
        void *arg, /**< ioctl() argument. */
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1776
        ec_ioctl_context_t *ctx /**< Private data structure of file handle. */
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1777
        )
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1778
{
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1779
    if (unlikely(!ctx->requested))
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1780
        return -EPERM;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1781
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1782
    ecrt_master_deactivate(master);
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1783
    return 0;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1784
}
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1785
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1786
/*****************************************************************************/
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1787
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1788
/** Set max. number of databytes in a cycle
2522
ec403cf308eb Updated Doxygen documentation.
Florian Pose <fp@igh-essen.com>
parents: 2505
diff changeset
  1789
 *
ec403cf308eb Updated Doxygen documentation.
Florian Pose <fp@igh-essen.com>
parents: 2505
diff changeset
  1790
 * \return Zero on success, otherwise a negative error code.
2433
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1791
 */
2481
c99ff159b60d Added function attribute definition.
Florian Pose <fp@igh-essen.com>
parents: 2477
diff changeset
  1792
static ATTRIBUTES int ec_ioctl_set_send_interval(
2433
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1793
        ec_master_t *master, /**< EtherCAT master. */
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1794
        void *arg, /**< ioctl() argument. */
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1795
        ec_ioctl_context_t *ctx /**< Private data structure of file handle. */
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1796
        )
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1797
{
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1798
    size_t send_interval;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1799
2477
1d5ebfb7fec1 Fixed some ioctl() permissions.
Florian Pose <fp@igh-essen.com>
parents: 2474
diff changeset
  1800
    if (unlikely(!ctx->requested)) {
1d5ebfb7fec1 Fixed some ioctl() permissions.
Florian Pose <fp@igh-essen.com>
parents: 2474
diff changeset
  1801
        return -EPERM;
1d5ebfb7fec1 Fixed some ioctl() permissions.
Florian Pose <fp@igh-essen.com>
parents: 2474
diff changeset
  1802
    }
1d5ebfb7fec1 Fixed some ioctl() permissions.
Florian Pose <fp@igh-essen.com>
parents: 2474
diff changeset
  1803
2719
94c9657e0bee Xenomai 2 to 3 migration says "RTDM drivers implementing differentiated ioctl() support for both domains should serve all real-time only requests from ioctl_rt(), returning -ENOSYS for any unrecognized request, which will cause the adaptive switch to take place automatically to the ioctl_nrt() handler. The ioctl_nrt() should then implement all requests which may be valid from the regular Linux domain exclusively."
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2712
diff changeset
  1804
    if (ec_copy_from_user(&send_interval, (void __user *) arg,
2433
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1805
                sizeof(send_interval))) {
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1806
        return -EFAULT;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1807
    }
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1808
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1809
    if (down_interruptible(&master->master_sem))
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1810
        return -EINTR;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1811
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1812
    ec_master_set_send_interval(master, send_interval);
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1813
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1814
    up(&master->master_sem);
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1815
    return 0;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1816
}
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1817
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1818
/*****************************************************************************/
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1819
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1820
/** Send frames.
2522
ec403cf308eb Updated Doxygen documentation.
Florian Pose <fp@igh-essen.com>
parents: 2505
diff changeset
  1821
 *
ec403cf308eb Updated Doxygen documentation.
Florian Pose <fp@igh-essen.com>
parents: 2505
diff changeset
  1822
 * \return Zero on success, otherwise a negative error code.
2433
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1823
 */
2481
c99ff159b60d Added function attribute definition.
Florian Pose <fp@igh-essen.com>
parents: 2477
diff changeset
  1824
static ATTRIBUTES int ec_ioctl_send(
2433
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1825
        ec_master_t *master, /**< EtherCAT master. */
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1826
        void *arg, /**< ioctl() argument. */
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1827
        ec_ioctl_context_t *ctx /**< Private data structure of file handle. */
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1828
        )
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1829
{
2498
9cdd7669dc0b Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents: 2487
diff changeset
  1830
    if (unlikely(!ctx->requested)) {
9cdd7669dc0b Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents: 2487
diff changeset
  1831
        return -EPERM;
9cdd7669dc0b Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents: 2487
diff changeset
  1832
    }
9cdd7669dc0b Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents: 2487
diff changeset
  1833
2433
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1834
    ecrt_master_send(master);
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1835
    return 0;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1836
}
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1837
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1838
/*****************************************************************************/
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1839
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1840
/** Receive frames.
2522
ec403cf308eb Updated Doxygen documentation.
Florian Pose <fp@igh-essen.com>
parents: 2505
diff changeset
  1841
 *
ec403cf308eb Updated Doxygen documentation.
Florian Pose <fp@igh-essen.com>
parents: 2505
diff changeset
  1842
 * \return Zero on success, otherwise a negative error code.
2433
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1843
 */
2481
c99ff159b60d Added function attribute definition.
Florian Pose <fp@igh-essen.com>
parents: 2477
diff changeset
  1844
static ATTRIBUTES int ec_ioctl_receive(
2433
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1845
        ec_master_t *master, /**< EtherCAT master. */
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1846
        void *arg, /**< ioctl() argument. */
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1847
        ec_ioctl_context_t *ctx /**< Private data structure of file handle. */
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1848
        )
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1849
{
2498
9cdd7669dc0b Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents: 2487
diff changeset
  1850
    if (unlikely(!ctx->requested)) {
9cdd7669dc0b Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents: 2487
diff changeset
  1851
        return -EPERM;
9cdd7669dc0b Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents: 2487
diff changeset
  1852
    }
9cdd7669dc0b Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents: 2487
diff changeset
  1853
2433
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1854
    ecrt_master_receive(master);
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1855
    return 0;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1856
}
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1857
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1858
/*****************************************************************************/
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1859
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1860
/** Get the master state.
2522
ec403cf308eb Updated Doxygen documentation.
Florian Pose <fp@igh-essen.com>
parents: 2505
diff changeset
  1861
 *
ec403cf308eb Updated Doxygen documentation.
Florian Pose <fp@igh-essen.com>
parents: 2505
diff changeset
  1862
 * \return Zero on success, otherwise a negative error code.
2433
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1863
 */
2481
c99ff159b60d Added function attribute definition.
Florian Pose <fp@igh-essen.com>
parents: 2477
diff changeset
  1864
static ATTRIBUTES int ec_ioctl_master_state(
2433
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1865
        ec_master_t *master, /**< EtherCAT master. */
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1866
        void *arg, /**< ioctl() argument. */
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1867
        ec_ioctl_context_t *ctx /**< Private data structure of file handle. */
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1868
        )
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1869
{
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1870
    ec_master_state_t data;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1871
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1872
    ecrt_master_state(master, &data);
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1873
2719
94c9657e0bee Xenomai 2 to 3 migration says "RTDM drivers implementing differentiated ioctl() support for both domains should serve all real-time only requests from ioctl_rt(), returning -ENOSYS for any unrecognized request, which will cause the adaptive switch to take place automatically to the ioctl_nrt() handler. The ioctl_nrt() should then implement all requests which may be valid from the regular Linux domain exclusively."
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2712
diff changeset
  1874
    if (ec_copy_to_user((void __user *) arg, &data, sizeof(data)))
2433
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1875
        return -EFAULT;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1876
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1877
    return 0;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1878
}
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1879
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1880
/*****************************************************************************/
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1881
2522
ec403cf308eb Updated Doxygen documentation.
Florian Pose <fp@igh-essen.com>
parents: 2505
diff changeset
  1882
/** Get the link state.
ec403cf308eb Updated Doxygen documentation.
Florian Pose <fp@igh-essen.com>
parents: 2505
diff changeset
  1883
 *
ec403cf308eb Updated Doxygen documentation.
Florian Pose <fp@igh-essen.com>
parents: 2505
diff changeset
  1884
 * \return Zero on success, otherwise a negative error code.
2433
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1885
 */
2481
c99ff159b60d Added function attribute definition.
Florian Pose <fp@igh-essen.com>
parents: 2477
diff changeset
  1886
static ATTRIBUTES int ec_ioctl_master_link_state(
2433
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1887
        ec_master_t *master, /**< EtherCAT master. */
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1888
        void *arg, /**< ioctl() argument. */
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1889
        ec_ioctl_context_t *ctx /**< Private data structure of file handle. */
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1890
        )
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1891
{
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1892
    ec_ioctl_link_state_t ioctl;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1893
    ec_master_link_state_t state;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1894
    int ret;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1895
2719
94c9657e0bee Xenomai 2 to 3 migration says "RTDM drivers implementing differentiated ioctl() support for both domains should serve all real-time only requests from ioctl_rt(), returning -ENOSYS for any unrecognized request, which will cause the adaptive switch to take place automatically to the ioctl_nrt() handler. The ioctl_nrt() should then implement all requests which may be valid from the regular Linux domain exclusively."
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2712
diff changeset
  1896
    if (ec_copy_from_user(&ioctl, (void __user *) arg, sizeof(ioctl))) {
2433
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1897
        return -EFAULT;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1898
    }
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1899
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1900
    ret = ecrt_master_link_state(master, ioctl.dev_idx, &state);
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1901
    if (ret < 0) {
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1902
        return ret;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1903
    }
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1904
2719
94c9657e0bee Xenomai 2 to 3 migration says "RTDM drivers implementing differentiated ioctl() support for both domains should serve all real-time only requests from ioctl_rt(), returning -ENOSYS for any unrecognized request, which will cause the adaptive switch to take place automatically to the ioctl_nrt() handler. The ioctl_nrt() should then implement all requests which may be valid from the regular Linux domain exclusively."
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2712
diff changeset
  1905
    if (ec_copy_to_user((void __user *) ioctl.state, &state, sizeof(state))) {
2433
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1906
        return -EFAULT;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1907
    }
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1908
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1909
    return 0;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1910
}
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1911
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1912
/*****************************************************************************/
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1913
2522
ec403cf308eb Updated Doxygen documentation.
Florian Pose <fp@igh-essen.com>
parents: 2505
diff changeset
  1914
/** Set the master DC application time.
ec403cf308eb Updated Doxygen documentation.
Florian Pose <fp@igh-essen.com>
parents: 2505
diff changeset
  1915
 *
ec403cf308eb Updated Doxygen documentation.
Florian Pose <fp@igh-essen.com>
parents: 2505
diff changeset
  1916
 * \return Zero on success, otherwise a negative error code.
2433
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1917
 */
2481
c99ff159b60d Added function attribute definition.
Florian Pose <fp@igh-essen.com>
parents: 2477
diff changeset
  1918
static ATTRIBUTES int ec_ioctl_app_time(
2433
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1919
        ec_master_t *master, /**< EtherCAT master. */
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1920
        void *arg, /**< ioctl() argument. */
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1921
        ec_ioctl_context_t *ctx /**< Private data structure of file handle. */
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1922
        )
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1923
{
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1924
    ec_ioctl_app_time_t data;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1925
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1926
    if (unlikely(!ctx->requested))
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1927
        return -EPERM;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1928
2719
94c9657e0bee Xenomai 2 to 3 migration says "RTDM drivers implementing differentiated ioctl() support for both domains should serve all real-time only requests from ioctl_rt(), returning -ENOSYS for any unrecognized request, which will cause the adaptive switch to take place automatically to the ioctl_nrt() handler. The ioctl_nrt() should then implement all requests which may be valid from the regular Linux domain exclusively."
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2712
diff changeset
  1929
    if (ec_copy_from_user(&data, (void __user *) arg, sizeof(data))) {
2433
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1930
        return -EFAULT;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1931
    }
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1932
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1933
    ecrt_master_application_time(master, data.app_time);
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1934
    return 0;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1935
}
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1936
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1937
/*****************************************************************************/
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1938
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1939
/** Sync the reference clock.
2522
ec403cf308eb Updated Doxygen documentation.
Florian Pose <fp@igh-essen.com>
parents: 2505
diff changeset
  1940
 *
ec403cf308eb Updated Doxygen documentation.
Florian Pose <fp@igh-essen.com>
parents: 2505
diff changeset
  1941
 * \return Zero on success, otherwise a negative error code.
2433
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1942
 */
2481
c99ff159b60d Added function attribute definition.
Florian Pose <fp@igh-essen.com>
parents: 2477
diff changeset
  1943
static ATTRIBUTES int ec_ioctl_sync_ref(
2433
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1944
        ec_master_t *master, /**< EtherCAT master. */
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1945
        void *arg, /**< ioctl() argument. */
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1946
        ec_ioctl_context_t *ctx /**< Private data structure of file handle. */
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1947
        )
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1948
{
2498
9cdd7669dc0b Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents: 2487
diff changeset
  1949
    if (unlikely(!ctx->requested)) {
9cdd7669dc0b Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents: 2487
diff changeset
  1950
        return -EPERM;
9cdd7669dc0b Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents: 2487
diff changeset
  1951
    }
9cdd7669dc0b Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents: 2487
diff changeset
  1952
2433
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1953
    ecrt_master_sync_reference_clock(master);
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1954
    return 0;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1955
}
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1956
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1957
/*****************************************************************************/
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1958
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1959
/** Sync the slave clocks.
2522
ec403cf308eb Updated Doxygen documentation.
Florian Pose <fp@igh-essen.com>
parents: 2505
diff changeset
  1960
 *
ec403cf308eb Updated Doxygen documentation.
Florian Pose <fp@igh-essen.com>
parents: 2505
diff changeset
  1961
 * \return Zero on success, otherwise a negative error code.
2433
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1962
 */
2481
c99ff159b60d Added function attribute definition.
Florian Pose <fp@igh-essen.com>
parents: 2477
diff changeset
  1963
static ATTRIBUTES int ec_ioctl_sync_slaves(
2433
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1964
        ec_master_t *master, /**< EtherCAT master. */
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1965
        void *arg, /**< ioctl() argument. */
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1966
        ec_ioctl_context_t *ctx /**< Private data structure of file handle. */
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1967
        )
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1968
{
2498
9cdd7669dc0b Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents: 2487
diff changeset
  1969
    if (unlikely(!ctx->requested)) {
9cdd7669dc0b Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents: 2487
diff changeset
  1970
        return -EPERM;
9cdd7669dc0b Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents: 2487
diff changeset
  1971
    }
9cdd7669dc0b Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents: 2487
diff changeset
  1972
2433
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1973
    ecrt_master_sync_slave_clocks(master);
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1974
    return 0;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1975
}
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1976
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1977
/*****************************************************************************/
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1978
2447
e93efb4af231 Added interface to select the reference clock and to sync to it.
Florian Pose <fp@igh-essen.com>
parents: 2443
diff changeset
  1979
/** Get the system time of the reference clock.
2522
ec403cf308eb Updated Doxygen documentation.
Florian Pose <fp@igh-essen.com>
parents: 2505
diff changeset
  1980
 *
ec403cf308eb Updated Doxygen documentation.
Florian Pose <fp@igh-essen.com>
parents: 2505
diff changeset
  1981
 * \return Zero on success, otherwise a negative error code.
2447
e93efb4af231 Added interface to select the reference clock and to sync to it.
Florian Pose <fp@igh-essen.com>
parents: 2443
diff changeset
  1982
 */
2481
c99ff159b60d Added function attribute definition.
Florian Pose <fp@igh-essen.com>
parents: 2477
diff changeset
  1983
static ATTRIBUTES int ec_ioctl_ref_clock_time(
2447
e93efb4af231 Added interface to select the reference clock and to sync to it.
Florian Pose <fp@igh-essen.com>
parents: 2443
diff changeset
  1984
        ec_master_t *master, /**< EtherCAT master. */
e93efb4af231 Added interface to select the reference clock and to sync to it.
Florian Pose <fp@igh-essen.com>
parents: 2443
diff changeset
  1985
        void *arg, /**< ioctl() argument. */
e93efb4af231 Added interface to select the reference clock and to sync to it.
Florian Pose <fp@igh-essen.com>
parents: 2443
diff changeset
  1986
        ec_ioctl_context_t *ctx /**< Private data structure of file handle. */
e93efb4af231 Added interface to select the reference clock and to sync to it.
Florian Pose <fp@igh-essen.com>
parents: 2443
diff changeset
  1987
        )
e93efb4af231 Added interface to select the reference clock and to sync to it.
Florian Pose <fp@igh-essen.com>
parents: 2443
diff changeset
  1988
{
e93efb4af231 Added interface to select the reference clock and to sync to it.
Florian Pose <fp@igh-essen.com>
parents: 2443
diff changeset
  1989
    uint32_t time;
e93efb4af231 Added interface to select the reference clock and to sync to it.
Florian Pose <fp@igh-essen.com>
parents: 2443
diff changeset
  1990
    int ret;
e93efb4af231 Added interface to select the reference clock and to sync to it.
Florian Pose <fp@igh-essen.com>
parents: 2443
diff changeset
  1991
e93efb4af231 Added interface to select the reference clock and to sync to it.
Florian Pose <fp@igh-essen.com>
parents: 2443
diff changeset
  1992
    if (unlikely(!ctx->requested)) {
e93efb4af231 Added interface to select the reference clock and to sync to it.
Florian Pose <fp@igh-essen.com>
parents: 2443
diff changeset
  1993
        return -EPERM;
e93efb4af231 Added interface to select the reference clock and to sync to it.
Florian Pose <fp@igh-essen.com>
parents: 2443
diff changeset
  1994
    }
e93efb4af231 Added interface to select the reference clock and to sync to it.
Florian Pose <fp@igh-essen.com>
parents: 2443
diff changeset
  1995
e93efb4af231 Added interface to select the reference clock and to sync to it.
Florian Pose <fp@igh-essen.com>
parents: 2443
diff changeset
  1996
    ret = ecrt_master_reference_clock_time(master, &time);
e93efb4af231 Added interface to select the reference clock and to sync to it.
Florian Pose <fp@igh-essen.com>
parents: 2443
diff changeset
  1997
    if (ret) {
e93efb4af231 Added interface to select the reference clock and to sync to it.
Florian Pose <fp@igh-essen.com>
parents: 2443
diff changeset
  1998
        return ret;
e93efb4af231 Added interface to select the reference clock and to sync to it.
Florian Pose <fp@igh-essen.com>
parents: 2443
diff changeset
  1999
    }
e93efb4af231 Added interface to select the reference clock and to sync to it.
Florian Pose <fp@igh-essen.com>
parents: 2443
diff changeset
  2000
2719
94c9657e0bee Xenomai 2 to 3 migration says "RTDM drivers implementing differentiated ioctl() support for both domains should serve all real-time only requests from ioctl_rt(), returning -ENOSYS for any unrecognized request, which will cause the adaptive switch to take place automatically to the ioctl_nrt() handler. The ioctl_nrt() should then implement all requests which may be valid from the regular Linux domain exclusively."
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2712
diff changeset
  2001
    if (ec_copy_to_user((void __user *) arg, &time, sizeof(time))) {
2447
e93efb4af231 Added interface to select the reference clock and to sync to it.
Florian Pose <fp@igh-essen.com>
parents: 2443
diff changeset
  2002
        return -EFAULT;
e93efb4af231 Added interface to select the reference clock and to sync to it.
Florian Pose <fp@igh-essen.com>
parents: 2443
diff changeset
  2003
    }
e93efb4af231 Added interface to select the reference clock and to sync to it.
Florian Pose <fp@igh-essen.com>
parents: 2443
diff changeset
  2004
e93efb4af231 Added interface to select the reference clock and to sync to it.
Florian Pose <fp@igh-essen.com>
parents: 2443
diff changeset
  2005
    return 0;
e93efb4af231 Added interface to select the reference clock and to sync to it.
Florian Pose <fp@igh-essen.com>
parents: 2443
diff changeset
  2006
}
e93efb4af231 Added interface to select the reference clock and to sync to it.
Florian Pose <fp@igh-essen.com>
parents: 2443
diff changeset
  2007
e93efb4af231 Added interface to select the reference clock and to sync to it.
Florian Pose <fp@igh-essen.com>
parents: 2443
diff changeset
  2008
/*****************************************************************************/
e93efb4af231 Added interface to select the reference clock and to sync to it.
Florian Pose <fp@igh-essen.com>
parents: 2443
diff changeset
  2009
2433
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2010
/** Queue the sync monitoring datagram.
2522
ec403cf308eb Updated Doxygen documentation.
Florian Pose <fp@igh-essen.com>
parents: 2505
diff changeset
  2011
 *
ec403cf308eb Updated Doxygen documentation.
Florian Pose <fp@igh-essen.com>
parents: 2505
diff changeset
  2012
 * \return Zero on success, otherwise a negative error code.
2433
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2013
 */
2481
c99ff159b60d Added function attribute definition.
Florian Pose <fp@igh-essen.com>
parents: 2477
diff changeset
  2014
static ATTRIBUTES int ec_ioctl_sync_mon_queue(
2433
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2015
        ec_master_t *master, /**< EtherCAT master. */
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2016
        void *arg, /**< ioctl() argument. */
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2017
        ec_ioctl_context_t *ctx /**< Private data structure of file handle. */
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2018
        )
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2019
{
2498
9cdd7669dc0b Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents: 2487
diff changeset
  2020
    if (unlikely(!ctx->requested)) {
9cdd7669dc0b Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents: 2487
diff changeset
  2021
        return -EPERM;
9cdd7669dc0b Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents: 2487
diff changeset
  2022
    }
9cdd7669dc0b Avoided io_sem locking from userspace/rtdm library.
Florian Pose <fp@igh-essen.com>
parents: 2487
diff changeset
  2023
2433
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2024
    ecrt_master_sync_monitor_queue(master);
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2025
    return 0;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2026
}
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2027
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2028
/*****************************************************************************/
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2029
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2030
/** Processes the sync monitoring datagram.
2522
ec403cf308eb Updated Doxygen documentation.
Florian Pose <fp@igh-essen.com>
parents: 2505
diff changeset
  2031
 *
ec403cf308eb Updated Doxygen documentation.
Florian Pose <fp@igh-essen.com>
parents: 2505
diff changeset
  2032
 * \return Zero on success, otherwise a negative error code.
2433
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2033
 */
2481
c99ff159b60d Added function attribute definition.
Florian Pose <fp@igh-essen.com>
parents: 2477
diff changeset
  2034
static ATTRIBUTES int ec_ioctl_sync_mon_process(
2433
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2035
        ec_master_t *master, /**< EtherCAT master. */
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2036
        void *arg, /**< ioctl() argument. */
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2037
        ec_ioctl_context_t *ctx /**< Private data structure of file handle. */
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2038
        )
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2039
{
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2040
    uint32_t time_diff;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2041
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2042
    if (unlikely(!ctx->requested))
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2043
        return -EPERM;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2044
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2045
    time_diff = ecrt_master_sync_monitor_process(master);
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2046
2719
94c9657e0bee Xenomai 2 to 3 migration says "RTDM drivers implementing differentiated ioctl() support for both domains should serve all real-time only requests from ioctl_rt(), returning -ENOSYS for any unrecognized request, which will cause the adaptive switch to take place automatically to the ioctl_nrt() handler. The ioctl_nrt() should then implement all requests which may be valid from the regular Linux domain exclusively."
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2712
diff changeset
  2047
    if (ec_copy_to_user((void __user *) arg, &time_diff, sizeof(time_diff)))
2433
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2048
        return -EFAULT;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2049
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2050
    return 0;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2051
}
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2052
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2053
/*****************************************************************************/
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2054
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2055
/** Reset configuration.
2522
ec403cf308eb Updated Doxygen documentation.
Florian Pose <fp@igh-essen.com>
parents: 2505
diff changeset
  2056
 *
ec403cf308eb Updated Doxygen documentation.
Florian Pose <fp@igh-essen.com>
parents: 2505
diff changeset
  2057
 * \return Always zero (success).
2433
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2058
 */
2481
c99ff159b60d Added function attribute definition.
Florian Pose <fp@igh-essen.com>
parents: 2477
diff changeset
  2059
static ATTRIBUTES int ec_ioctl_reset(
2433
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2060
        ec_master_t *master, /**< EtherCAT master. */
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2061
        void *arg, /**< ioctl() argument. */
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2062
        ec_ioctl_context_t *ctx /**< Private data structure of file handle. */
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2063
        )
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2064
{
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2065
    down(&master->master_sem);
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2066
    ecrt_master_reset(master);
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2067
    up(&master->master_sem);
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2068
    return 0;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2069
}
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2070
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2071
/*****************************************************************************/
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2072
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2073
/** Configure a sync manager.
2522
ec403cf308eb Updated Doxygen documentation.
Florian Pose <fp@igh-essen.com>
parents: 2505
diff changeset
  2074
 *
ec403cf308eb Updated Doxygen documentation.
Florian Pose <fp@igh-essen.com>
parents: 2505
diff changeset
  2075
 * \return Zero on success, otherwise a negative error code.
2433
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2076
 */
2481
c99ff159b60d Added function attribute definition.
Florian Pose <fp@igh-essen.com>
parents: 2477
diff changeset
  2077
static ATTRIBUTES int ec_ioctl_sc_sync(
2433
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2078
        ec_master_t *master, /**< EtherCAT master. */
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2079
        void *arg, /**< ioctl() argument. */
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2080
        ec_ioctl_context_t *ctx /**< Private data structure of file handle. */
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2081
        )
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2082
{
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2083
    ec_ioctl_config_t data;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2084
    ec_slave_config_t *sc;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2085
    unsigned int i;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2086
    int ret = 0;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2087
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2088
    if (unlikely(!ctx->requested)) {
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2089
        ret = -EPERM;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2090
        goto out_return;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2091
    }
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2092
2719
94c9657e0bee Xenomai 2 to 3 migration says "RTDM drivers implementing differentiated ioctl() support for both domains should serve all real-time only requests from ioctl_rt(), returning -ENOSYS for any unrecognized request, which will cause the adaptive switch to take place automatically to the ioctl_nrt() handler. The ioctl_nrt() should then implement all requests which may be valid from the regular Linux domain exclusively."
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2712
diff changeset
  2093
    if (ec_copy_from_user(&data, (void __user *) arg, sizeof(data))) {
2433
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2094
        ret = -EFAULT;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2095
        goto out_return;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2096
    }
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2097
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2098
    if (down_interruptible(&master->master_sem)) {
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2099
        ret = -EINTR;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2100
        goto out_return;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2101
    }
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2102
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2103
    if (!(sc = ec_master_get_config(master, data.config_index))) {
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2104
        ret = -ENOENT;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2105
        goto out_up;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2106
    }
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2107
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2108
    for (i = 0; i < EC_MAX_SYNC_MANAGERS; i++) {
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2109
        if (data.syncs[i].config_this) {
2474
fb2fe8fae501 Fixed some ioctl() return values.
Florian Pose <fp@igh-essen.com>
parents: 2467
diff changeset
  2110
            ret = ecrt_slave_config_sync_manager(sc, i, data.syncs[i].dir,
fb2fe8fae501 Fixed some ioctl() return values.
Florian Pose <fp@igh-essen.com>
parents: 2467
diff changeset
  2111
                        data.syncs[i].watchdog_mode);
fb2fe8fae501 Fixed some ioctl() return values.
Florian Pose <fp@igh-essen.com>
parents: 2467
diff changeset
  2112
            if (ret) {
2433
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2113
                goto out_up;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2114
            }
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2115
        }
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2116
    }
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2117
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2118
out_up:
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2119
    up(&master->master_sem);
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2120
out_return:
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2121
    return ret;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2122
}
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2123
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2124
/*****************************************************************************/
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2125
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2126
/** Configure a slave's watchdogs.
2522
ec403cf308eb Updated Doxygen documentation.
Florian Pose <fp@igh-essen.com>
parents: 2505
diff changeset
  2127
 *
ec403cf308eb Updated Doxygen documentation.
Florian Pose <fp@igh-essen.com>
parents: 2505
diff changeset
  2128
 * \return Zero on success, otherwise a negative error code.
2433
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2129
 */
2481
c99ff159b60d Added function attribute definition.
Florian Pose <fp@igh-essen.com>
parents: 2477
diff changeset
  2130
static ATTRIBUTES int ec_ioctl_sc_watchdog(
2433
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2131
        ec_master_t *master, /**< EtherCAT master. */
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2132
        void *arg, /**< ioctl() argument. */
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2133
        ec_ioctl_context_t *ctx /**< Private data structure of file handle. */
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2134
        )
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2135
{
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2136
    ec_ioctl_config_t data;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2137
    ec_slave_config_t *sc;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2138
    int ret = 0;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2139
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2140
    if (unlikely(!ctx->requested)) {
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2141
        ret = -EPERM;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2142
        goto out_return;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2143
    }
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2144
2719
94c9657e0bee Xenomai 2 to 3 migration says "RTDM drivers implementing differentiated ioctl() support for both domains should serve all real-time only requests from ioctl_rt(), returning -ENOSYS for any unrecognized request, which will cause the adaptive switch to take place automatically to the ioctl_nrt() handler. The ioctl_nrt() should then implement all requests which may be valid from the regular Linux domain exclusively."
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2712
diff changeset
  2145
    if (ec_copy_from_user(&data, (void __user *) arg, sizeof(data))) {
2433
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2146
        ret = -EFAULT;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2147
        goto out_return;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2148
    }
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2149
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2150
    if (down_interruptible(&master->master_sem)) {
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2151
        ret = -EINTR;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2152
        goto out_return;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2153
    }
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2154
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2155
    if (!(sc = ec_master_get_config(master, data.config_index))) {
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2156
        ret = -ENOENT;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2157
        goto out_up;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2158
    }
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2159
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2160
    ecrt_slave_config_watchdog(sc,
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2161
            data.watchdog_divider, data.watchdog_intervals);
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2162
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2163
out_up:
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2164
    up(&master->master_sem);
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2165
out_return:
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2166
    return ret;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2167
}
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2168
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2169
/*****************************************************************************/
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2170
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2171
/** Add a PDO to the assignment.
2522
ec403cf308eb Updated Doxygen documentation.
Florian Pose <fp@igh-essen.com>
parents: 2505
diff changeset
  2172
 *
ec403cf308eb Updated Doxygen documentation.
Florian Pose <fp@igh-essen.com>
parents: 2505
diff changeset
  2173
 * \return Zero on success, otherwise a negative error code.
2433
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2174
 */
2481
c99ff159b60d Added function attribute definition.
Florian Pose <fp@igh-essen.com>
parents: 2477
diff changeset
  2175
static ATTRIBUTES int ec_ioctl_sc_add_pdo(
2433
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2176
        ec_master_t *master, /**< EtherCAT master. */
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2177
        void *arg, /**< ioctl() argument. */
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2178
        ec_ioctl_context_t *ctx /**< Private data structure of file handle. */
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2179
        )
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2180
{
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2181
    ec_ioctl_config_pdo_t data;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2182
    ec_slave_config_t *sc;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2183
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2184
    if (unlikely(!ctx->requested))
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2185
        return -EPERM;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2186
2719
94c9657e0bee Xenomai 2 to 3 migration says "RTDM drivers implementing differentiated ioctl() support for both domains should serve all real-time only requests from ioctl_rt(), returning -ENOSYS for any unrecognized request, which will cause the adaptive switch to take place automatically to the ioctl_nrt() handler. The ioctl_nrt() should then implement all requests which may be valid from the regular Linux domain exclusively."
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2712
diff changeset
  2187
    if (ec_copy_from_user(&data, (void __user *) arg, sizeof(data)))
2433
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2188
        return -EFAULT;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2189
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2190
    if (down_interruptible(&master->master_sem))
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2191
        return -EINTR;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2192
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2193
    if (!(sc = ec_master_get_config(master, data.config_index))) {
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2194
        up(&master->master_sem);
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2195
        return -ENOENT;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2196
    }
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2197
2522
ec403cf308eb Updated Doxygen documentation.
Florian Pose <fp@igh-essen.com>
parents: 2505
diff changeset
  2198
    up(&master->master_sem); /** \todo sc could be invalidated */
2433
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2199
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2200
    return ecrt_slave_config_pdo_assign_add(sc, data.sync_index, data.index);
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2201
}
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2202
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2203
/*****************************************************************************/
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2204
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2205
/** Clears the PDO assignment.
2522
ec403cf308eb Updated Doxygen documentation.
Florian Pose <fp@igh-essen.com>
parents: 2505
diff changeset
  2206
 *
ec403cf308eb Updated Doxygen documentation.
Florian Pose <fp@igh-essen.com>
parents: 2505
diff changeset
  2207
 * \return Zero on success, otherwise a negative error code.
2433
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2208
 */
2481
c99ff159b60d Added function attribute definition.
Florian Pose <fp@igh-essen.com>
parents: 2477
diff changeset
  2209
static ATTRIBUTES int ec_ioctl_sc_clear_pdos(
2433
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2210
        ec_master_t *master, /**< EtherCAT master. */
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2211
        void *arg, /**< ioctl() argument. */
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2212
        ec_ioctl_context_t *ctx /**< Private data structure of file handle. */
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2213
        )
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2214
{
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2215
    ec_ioctl_config_pdo_t data;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2216
    ec_slave_config_t *sc;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2217
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2218
    if (unlikely(!ctx->requested))
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2219
        return -EPERM;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2220
2719
94c9657e0bee Xenomai 2 to 3 migration says "RTDM drivers implementing differentiated ioctl() support for both domains should serve all real-time only requests from ioctl_rt(), returning -ENOSYS for any unrecognized request, which will cause the adaptive switch to take place automatically to the ioctl_nrt() handler. The ioctl_nrt() should then implement all requests which may be valid from the regular Linux domain exclusively."
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2712
diff changeset
  2221
    if (ec_copy_from_user(&data, (void __user *) arg, sizeof(data)))
2433
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2222
        return -EFAULT;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2223
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2224
    if (down_interruptible(&master->master_sem))
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2225
        return -EINTR;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2226
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2227
    if (!(sc = ec_master_get_config(master, data.config_index))) {
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2228
        up(&master->master_sem);
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2229
        return -ENOENT;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2230
    }
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2231
2522
ec403cf308eb Updated Doxygen documentation.
Florian Pose <fp@igh-essen.com>
parents: 2505
diff changeset
  2232
    up(&master->master_sem); /** \todo sc could be invalidated */
2433
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2233
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2234
    ecrt_slave_config_pdo_assign_clear(sc, data.sync_index);
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2235
    return 0;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2236
}
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2237
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2238
/*****************************************************************************/
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2239
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2240
/** Add an entry to a PDO's mapping.
2522
ec403cf308eb Updated Doxygen documentation.
Florian Pose <fp@igh-essen.com>
parents: 2505
diff changeset
  2241
 *
ec403cf308eb Updated Doxygen documentation.
Florian Pose <fp@igh-essen.com>
parents: 2505
diff changeset
  2242
 * \return Zero on success, otherwise a negative error code.
2433
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2243
 */
2481
c99ff159b60d Added function attribute definition.
Florian Pose <fp@igh-essen.com>
parents: 2477
diff changeset
  2244
static ATTRIBUTES int ec_ioctl_sc_add_entry(
2433
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2245
        ec_master_t *master, /**< EtherCAT master. */
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2246
        void *arg, /**< ioctl() argument. */
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2247
        ec_ioctl_context_t *ctx /**< Private data structure of file handle. */
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2248
        )
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2249
{
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2250
    ec_ioctl_add_pdo_entry_t data;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2251
    ec_slave_config_t *sc;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2252
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2253
    if (unlikely(!ctx->requested))
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2254
        return -EPERM;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2255
2719
94c9657e0bee Xenomai 2 to 3 migration says "RTDM drivers implementing differentiated ioctl() support for both domains should serve all real-time only requests from ioctl_rt(), returning -ENOSYS for any unrecognized request, which will cause the adaptive switch to take place automatically to the ioctl_nrt() handler. The ioctl_nrt() should then implement all requests which may be valid from the regular Linux domain exclusively."
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2712
diff changeset
  2256
    if (ec_copy_from_user(&data, (void __user *) arg, sizeof(data)))
2433
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2257
        return -EFAULT;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2258
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2259
    if (down_interruptible(&master->master_sem))
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2260
        return -EINTR;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2261
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2262
    if (!(sc = ec_master_get_config(master, data.config_index))) {
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2263
        up(&master->master_sem);
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2264
        return -ENOENT;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2265
    }
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2266
2522
ec403cf308eb Updated Doxygen documentation.
Florian Pose <fp@igh-essen.com>
parents: 2505
diff changeset
  2267
    up(&master->master_sem); /** \todo sc could be invalidated */
2433
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2268
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2269
    return ecrt_slave_config_pdo_mapping_add(sc, data.pdo_index,
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2270
            data.entry_index, data.entry_subindex, data.entry_bit_length);
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2271
}
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2272
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2273
/*****************************************************************************/
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2274
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2275
/** Clears the mapping of a PDO.
2522
ec403cf308eb Updated Doxygen documentation.
Florian Pose <fp@igh-essen.com>
parents: 2505
diff changeset
  2276
 *
ec403cf308eb Updated Doxygen documentation.
Florian Pose <fp@igh-essen.com>
parents: 2505
diff changeset
  2277
 * \return Zero on success, otherwise a negative error code.
2433
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2278
 */
2481
c99ff159b60d Added function attribute definition.
Florian Pose <fp@igh-essen.com>
parents: 2477
diff changeset
  2279
static ATTRIBUTES int ec_ioctl_sc_clear_entries(
2433
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2280
        ec_master_t *master, /**< EtherCAT master. */
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2281
        void *arg, /**< ioctl() argument. */
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2282
        ec_ioctl_context_t *ctx /**< Private data structure of file handle. */
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2283
        )
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2284
{
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2285
    ec_ioctl_config_pdo_t data;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2286
    ec_slave_config_t *sc;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2287
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2288
    if (unlikely(!ctx->requested))
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2289
        return -EPERM;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2290
2719
94c9657e0bee Xenomai 2 to 3 migration says "RTDM drivers implementing differentiated ioctl() support for both domains should serve all real-time only requests from ioctl_rt(), returning -ENOSYS for any unrecognized request, which will cause the adaptive switch to take place automatically to the ioctl_nrt() handler. The ioctl_nrt() should then implement all requests which may be valid from the regular Linux domain exclusively."
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2712
diff changeset
  2291
    if (ec_copy_from_user(&data, (void __user *) arg, sizeof(data)))
2433
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2292
        return -EFAULT;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2293
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2294
    if (down_interruptible(&master->master_sem))
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2295
        return -EINTR;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2296
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2297
    if (!(sc = ec_master_get_config(master, data.config_index))) {
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2298
        up(&master->master_sem);
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2299
        return -ENOENT;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2300
    }
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2301
2522
ec403cf308eb Updated Doxygen documentation.
Florian Pose <fp@igh-essen.com>
parents: 2505
diff changeset
  2302
    up(&master->master_sem); /** \todo sc could be invalidated */
2433
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2303
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2304
    ecrt_slave_config_pdo_mapping_clear(sc, data.index);
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2305
    return 0;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2306
}
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2307
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2308
/*****************************************************************************/
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2309
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2310
/** Registers a PDO entry.
2522
ec403cf308eb Updated Doxygen documentation.
Florian Pose <fp@igh-essen.com>
parents: 2505
diff changeset
  2311
 *
ec403cf308eb Updated Doxygen documentation.
Florian Pose <fp@igh-essen.com>
parents: 2505
diff changeset
  2312
 * \return Process data offset on success, otherwise a negative error code.
2433
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2313
 */
2481
c99ff159b60d Added function attribute definition.
Florian Pose <fp@igh-essen.com>
parents: 2477
diff changeset
  2314
static ATTRIBUTES int ec_ioctl_sc_reg_pdo_entry(
2433
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2315
        ec_master_t *master, /**< EtherCAT master. */
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2316
        void *arg, /**< ioctl() argument. */
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2317
        ec_ioctl_context_t *ctx /**< Private data structure of file handle. */
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2318
        )
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2319
{
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2320
    ec_ioctl_reg_pdo_entry_t data;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2321
    ec_slave_config_t *sc;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2322
    ec_domain_t *domain;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2323
    int ret;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2324
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2325
    if (unlikely(!ctx->requested))
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2326
        return -EPERM;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2327
2719
94c9657e0bee Xenomai 2 to 3 migration says "RTDM drivers implementing differentiated ioctl() support for both domains should serve all real-time only requests from ioctl_rt(), returning -ENOSYS for any unrecognized request, which will cause the adaptive switch to take place automatically to the ioctl_nrt() handler. The ioctl_nrt() should then implement all requests which may be valid from the regular Linux domain exclusively."
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2712
diff changeset
  2328
    if (ec_copy_from_user(&data, (void __user *) arg, sizeof(data)))
2433
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2329
        return -EFAULT;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2330
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2331
    if (down_interruptible(&master->master_sem))
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2332
        return -EINTR;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2333
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2334
    if (!(sc = ec_master_get_config(master, data.config_index))) {
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2335
        up(&master->master_sem);
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2336
        return -ENOENT;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2337
    }
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2338
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2339
    if (!(domain = ec_master_find_domain(master, data.domain_index))) {
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2340
        up(&master->master_sem);
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2341
        return -ENOENT;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2342
    }
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2343
2522
ec403cf308eb Updated Doxygen documentation.
Florian Pose <fp@igh-essen.com>
parents: 2505
diff changeset
  2344
    up(&master->master_sem); /** \todo sc or domain could be invalidated */
2433
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2345
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2346
    ret = ecrt_slave_config_reg_pdo_entry(sc, data.entry_index,
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2347
            data.entry_subindex, domain, &data.bit_position);
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2348
2719
94c9657e0bee Xenomai 2 to 3 migration says "RTDM drivers implementing differentiated ioctl() support for both domains should serve all real-time only requests from ioctl_rt(), returning -ENOSYS for any unrecognized request, which will cause the adaptive switch to take place automatically to the ioctl_nrt() handler. The ioctl_nrt() should then implement all requests which may be valid from the regular Linux domain exclusively."
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2712
diff changeset
  2349
    if (ec_copy_to_user((void __user *) arg, &data, sizeof(data)))
2433
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2350
        return -EFAULT;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2351
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2352
    return ret;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2353
}
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2354
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2355
/*****************************************************************************/
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2356
2505
5ef3197e5e1f Added ecrt_slave_config_reg_so_entry_pos() to register non-unique entries.
Florian Pose <fp@igh-essen.com>
parents: 2504
diff changeset
  2357
/** Registers a PDO entry by its position.
2522
ec403cf308eb Updated Doxygen documentation.
Florian Pose <fp@igh-essen.com>
parents: 2505
diff changeset
  2358
 *
ec403cf308eb Updated Doxygen documentation.
Florian Pose <fp@igh-essen.com>
parents: 2505
diff changeset
  2359
 * \return Process data offset on success, otherwise a negative error code.
2505
5ef3197e5e1f Added ecrt_slave_config_reg_so_entry_pos() to register non-unique entries.
Florian Pose <fp@igh-essen.com>
parents: 2504
diff changeset
  2360
 */
5ef3197e5e1f Added ecrt_slave_config_reg_so_entry_pos() to register non-unique entries.
Florian Pose <fp@igh-essen.com>
parents: 2504
diff changeset
  2361
static ATTRIBUTES int ec_ioctl_sc_reg_pdo_pos(
5ef3197e5e1f Added ecrt_slave_config_reg_so_entry_pos() to register non-unique entries.
Florian Pose <fp@igh-essen.com>
parents: 2504
diff changeset
  2362
        ec_master_t *master, /**< EtherCAT master. */
5ef3197e5e1f Added ecrt_slave_config_reg_so_entry_pos() to register non-unique entries.
Florian Pose <fp@igh-essen.com>
parents: 2504
diff changeset
  2363
        void *arg, /**< ioctl() argument. */
5ef3197e5e1f Added ecrt_slave_config_reg_so_entry_pos() to register non-unique entries.
Florian Pose <fp@igh-essen.com>
parents: 2504
diff changeset
  2364
        ec_ioctl_context_t *ctx /**< Private data structure of file handle. */
5ef3197e5e1f Added ecrt_slave_config_reg_so_entry_pos() to register non-unique entries.
Florian Pose <fp@igh-essen.com>
parents: 2504
diff changeset
  2365
        )
5ef3197e5e1f Added ecrt_slave_config_reg_so_entry_pos() to register non-unique entries.
Florian Pose <fp@igh-essen.com>
parents: 2504
diff changeset
  2366
{
5ef3197e5e1f Added ecrt_slave_config_reg_so_entry_pos() to register non-unique entries.
Florian Pose <fp@igh-essen.com>
parents: 2504
diff changeset
  2367
    ec_ioctl_reg_pdo_pos_t io;
5ef3197e5e1f Added ecrt_slave_config_reg_so_entry_pos() to register non-unique entries.
Florian Pose <fp@igh-essen.com>
parents: 2504
diff changeset
  2368
    ec_slave_config_t *sc;
5ef3197e5e1f Added ecrt_slave_config_reg_so_entry_pos() to register non-unique entries.
Florian Pose <fp@igh-essen.com>
parents: 2504
diff changeset
  2369
    ec_domain_t *domain;
5ef3197e5e1f Added ecrt_slave_config_reg_so_entry_pos() to register non-unique entries.
Florian Pose <fp@igh-essen.com>
parents: 2504
diff changeset
  2370
    int ret;
5ef3197e5e1f Added ecrt_slave_config_reg_so_entry_pos() to register non-unique entries.
Florian Pose <fp@igh-essen.com>
parents: 2504
diff changeset
  2371
5ef3197e5e1f Added ecrt_slave_config_reg_so_entry_pos() to register non-unique entries.
Florian Pose <fp@igh-essen.com>
parents: 2504
diff changeset
  2372
    if (unlikely(!ctx->requested)) {
5ef3197e5e1f Added ecrt_slave_config_reg_so_entry_pos() to register non-unique entries.
Florian Pose <fp@igh-essen.com>
parents: 2504
diff changeset
  2373
        return -EPERM;
5ef3197e5e1f Added ecrt_slave_config_reg_so_entry_pos() to register non-unique entries.
Florian Pose <fp@igh-essen.com>
parents: 2504
diff changeset
  2374
    }
5ef3197e5e1f Added ecrt_slave_config_reg_so_entry_pos() to register non-unique entries.
Florian Pose <fp@igh-essen.com>
parents: 2504
diff changeset
  2375
2719
94c9657e0bee Xenomai 2 to 3 migration says "RTDM drivers implementing differentiated ioctl() support for both domains should serve all real-time only requests from ioctl_rt(), returning -ENOSYS for any unrecognized request, which will cause the adaptive switch to take place automatically to the ioctl_nrt() handler. The ioctl_nrt() should then implement all requests which may be valid from the regular Linux domain exclusively."
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2712
diff changeset
  2376
    if (ec_copy_from_user(&io, (void __user *) arg, sizeof(io))) {
2505
5ef3197e5e1f Added ecrt_slave_config_reg_so_entry_pos() to register non-unique entries.
Florian Pose <fp@igh-essen.com>
parents: 2504
diff changeset
  2377
        return -EFAULT;
5ef3197e5e1f Added ecrt_slave_config_reg_so_entry_pos() to register non-unique entries.
Florian Pose <fp@igh-essen.com>
parents: 2504
diff changeset
  2378
    }
5ef3197e5e1f Added ecrt_slave_config_reg_so_entry_pos() to register non-unique entries.
Florian Pose <fp@igh-essen.com>
parents: 2504
diff changeset
  2379
5ef3197e5e1f Added ecrt_slave_config_reg_so_entry_pos() to register non-unique entries.
Florian Pose <fp@igh-essen.com>
parents: 2504
diff changeset
  2380
    if (down_interruptible(&master->master_sem)) {
5ef3197e5e1f Added ecrt_slave_config_reg_so_entry_pos() to register non-unique entries.
Florian Pose <fp@igh-essen.com>
parents: 2504
diff changeset
  2381
        return -EINTR;
5ef3197e5e1f Added ecrt_slave_config_reg_so_entry_pos() to register non-unique entries.
Florian Pose <fp@igh-essen.com>
parents: 2504
diff changeset
  2382
    }
5ef3197e5e1f Added ecrt_slave_config_reg_so_entry_pos() to register non-unique entries.
Florian Pose <fp@igh-essen.com>
parents: 2504
diff changeset
  2383
5ef3197e5e1f Added ecrt_slave_config_reg_so_entry_pos() to register non-unique entries.
Florian Pose <fp@igh-essen.com>
parents: 2504
diff changeset
  2384
    if (!(sc = ec_master_get_config(master, io.config_index))) {
5ef3197e5e1f Added ecrt_slave_config_reg_so_entry_pos() to register non-unique entries.
Florian Pose <fp@igh-essen.com>
parents: 2504
diff changeset
  2385
        up(&master->master_sem);
5ef3197e5e1f Added ecrt_slave_config_reg_so_entry_pos() to register non-unique entries.
Florian Pose <fp@igh-essen.com>
parents: 2504
diff changeset
  2386
        return -ENOENT;
5ef3197e5e1f Added ecrt_slave_config_reg_so_entry_pos() to register non-unique entries.
Florian Pose <fp@igh-essen.com>
parents: 2504
diff changeset
  2387
    }
5ef3197e5e1f Added ecrt_slave_config_reg_so_entry_pos() to register non-unique entries.
Florian Pose <fp@igh-essen.com>
parents: 2504
diff changeset
  2388
5ef3197e5e1f Added ecrt_slave_config_reg_so_entry_pos() to register non-unique entries.
Florian Pose <fp@igh-essen.com>
parents: 2504
diff changeset
  2389
    if (!(domain = ec_master_find_domain(master, io.domain_index))) {
5ef3197e5e1f Added ecrt_slave_config_reg_so_entry_pos() to register non-unique entries.
Florian Pose <fp@igh-essen.com>
parents: 2504
diff changeset
  2390
        up(&master->master_sem);
5ef3197e5e1f Added ecrt_slave_config_reg_so_entry_pos() to register non-unique entries.
Florian Pose <fp@igh-essen.com>
parents: 2504
diff changeset
  2391
        return -ENOENT;
5ef3197e5e1f Added ecrt_slave_config_reg_so_entry_pos() to register non-unique entries.
Florian Pose <fp@igh-essen.com>
parents: 2504
diff changeset
  2392
    }
5ef3197e5e1f Added ecrt_slave_config_reg_so_entry_pos() to register non-unique entries.
Florian Pose <fp@igh-essen.com>
parents: 2504
diff changeset
  2393
2522
ec403cf308eb Updated Doxygen documentation.
Florian Pose <fp@igh-essen.com>
parents: 2505
diff changeset
  2394
    up(&master->master_sem); /** \todo sc or domain could be invalidated */
2505
5ef3197e5e1f Added ecrt_slave_config_reg_so_entry_pos() to register non-unique entries.
Florian Pose <fp@igh-essen.com>
parents: 2504
diff changeset
  2395
5ef3197e5e1f Added ecrt_slave_config_reg_so_entry_pos() to register non-unique entries.
Florian Pose <fp@igh-essen.com>
parents: 2504
diff changeset
  2396
    ret = ecrt_slave_config_reg_pdo_entry_pos(sc, io.sync_index,
5ef3197e5e1f Added ecrt_slave_config_reg_so_entry_pos() to register non-unique entries.
Florian Pose <fp@igh-essen.com>
parents: 2504
diff changeset
  2397
            io.pdo_pos, io.entry_pos, domain, &io.bit_position);
5ef3197e5e1f Added ecrt_slave_config_reg_so_entry_pos() to register non-unique entries.
Florian Pose <fp@igh-essen.com>
parents: 2504
diff changeset
  2398
2719
94c9657e0bee Xenomai 2 to 3 migration says "RTDM drivers implementing differentiated ioctl() support for both domains should serve all real-time only requests from ioctl_rt(), returning -ENOSYS for any unrecognized request, which will cause the adaptive switch to take place automatically to the ioctl_nrt() handler. The ioctl_nrt() should then implement all requests which may be valid from the regular Linux domain exclusively."
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2712
diff changeset
  2399
    if (ec_copy_to_user((void __user *) arg, &io, sizeof(io)))
2505
5ef3197e5e1f Added ecrt_slave_config_reg_so_entry_pos() to register non-unique entries.
Florian Pose <fp@igh-essen.com>
parents: 2504
diff changeset
  2400
        return -EFAULT;
5ef3197e5e1f Added ecrt_slave_config_reg_so_entry_pos() to register non-unique entries.
Florian Pose <fp@igh-essen.com>
parents: 2504
diff changeset
  2401
5ef3197e5e1f Added ecrt_slave_config_reg_so_entry_pos() to register non-unique entries.
Florian Pose <fp@igh-essen.com>
parents: 2504
diff changeset
  2402
    return ret;
5ef3197e5e1f Added ecrt_slave_config_reg_so_entry_pos() to register non-unique entries.
Florian Pose <fp@igh-essen.com>
parents: 2504
diff changeset
  2403
}
5ef3197e5e1f Added ecrt_slave_config_reg_so_entry_pos() to register non-unique entries.
Florian Pose <fp@igh-essen.com>
parents: 2504
diff changeset
  2404
5ef3197e5e1f Added ecrt_slave_config_reg_so_entry_pos() to register non-unique entries.
Florian Pose <fp@igh-essen.com>
parents: 2504
diff changeset
  2405
/*****************************************************************************/
5ef3197e5e1f Added ecrt_slave_config_reg_so_entry_pos() to register non-unique entries.
Florian Pose <fp@igh-essen.com>
parents: 2504
diff changeset
  2406
2433
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2407
/** Sets the DC AssignActivate word and the sync signal times.
2522
ec403cf308eb Updated Doxygen documentation.
Florian Pose <fp@igh-essen.com>
parents: 2505
diff changeset
  2408
 *
ec403cf308eb Updated Doxygen documentation.
Florian Pose <fp@igh-essen.com>
parents: 2505
diff changeset
  2409
 * \return Zero on success, otherwise a negative error code.
2433
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2410
 */
2481
c99ff159b60d Added function attribute definition.
Florian Pose <fp@igh-essen.com>
parents: 2477
diff changeset
  2411
static ATTRIBUTES int ec_ioctl_sc_dc(
2433
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2412
        ec_master_t *master, /**< EtherCAT master. */
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2413
        void *arg, /**< ioctl() argument. */
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2414
        ec_ioctl_context_t *ctx /**< Private data structure of file handle. */
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2415
        )
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2416
{
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2417
    ec_ioctl_config_t data;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2418
    ec_slave_config_t *sc;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2419
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2420
    if (unlikely(!ctx->requested))
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2421
        return -EPERM;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2422
2719
94c9657e0bee Xenomai 2 to 3 migration says "RTDM drivers implementing differentiated ioctl() support for both domains should serve all real-time only requests from ioctl_rt(), returning -ENOSYS for any unrecognized request, which will cause the adaptive switch to take place automatically to the ioctl_nrt() handler. The ioctl_nrt() should then implement all requests which may be valid from the regular Linux domain exclusively."
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2712
diff changeset
  2423
    if (ec_copy_from_user(&data, (void __user *) arg, sizeof(data)))
2433
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2424
        return -EFAULT;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2425
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2426
    if (down_interruptible(&master->master_sem))
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2427
        return -EINTR;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2428
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2429
    if (!(sc = ec_master_get_config(master, data.config_index))) {
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2430
        up(&master->master_sem);
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2431
        return -ENOENT;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2432
    }
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2433
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2434
    ecrt_slave_config_dc(sc, data.dc_assign_activate,
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2435
            data.dc_sync[0].cycle_time,
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2436
            data.dc_sync[0].shift_time,
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2437
            data.dc_sync[1].cycle_time,
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2438
            data.dc_sync[1].shift_time);
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2439
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2440
    up(&master->master_sem);
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2441
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2442
    return 0;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2443
}
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2444
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2445
/*****************************************************************************/
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2446
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2447
/** Configures an SDO.
2522
ec403cf308eb Updated Doxygen documentation.
Florian Pose <fp@igh-essen.com>
parents: 2505
diff changeset
  2448
 *
ec403cf308eb Updated Doxygen documentation.
Florian Pose <fp@igh-essen.com>
parents: 2505
diff changeset
  2449
 * \return Zero on success, otherwise a negative error code.
2433
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2450
 */
2481
c99ff159b60d Added function attribute definition.
Florian Pose <fp@igh-essen.com>
parents: 2477
diff changeset
  2451
static ATTRIBUTES int ec_ioctl_sc_sdo(
2433
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2452
        ec_master_t *master, /**< EtherCAT master. */
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2453
        void *arg, /**< ioctl() argument. */
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2454
        ec_ioctl_context_t *ctx /**< Private data structure of file handle. */
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2455
        )
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2456
{
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2457
    ec_ioctl_sc_sdo_t data;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2458
    ec_slave_config_t *sc;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2459
    uint8_t *sdo_data = NULL;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2460
    int ret;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2461
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2462
    if (unlikely(!ctx->requested))
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2463
        return -EPERM;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2464
2719
94c9657e0bee Xenomai 2 to 3 migration says "RTDM drivers implementing differentiated ioctl() support for both domains should serve all real-time only requests from ioctl_rt(), returning -ENOSYS for any unrecognized request, which will cause the adaptive switch to take place automatically to the ioctl_nrt() handler. The ioctl_nrt() should then implement all requests which may be valid from the regular Linux domain exclusively."
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2712
diff changeset
  2465
    if (ec_copy_from_user(&data, (void __user *) arg, sizeof(data)))
2433
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2466
        return -EFAULT;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2467
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2468
    if (!data.size)
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2469
        return -EINVAL;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2470
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2471
    if (!(sdo_data = kmalloc(data.size, GFP_KERNEL))) {
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2472
        return -ENOMEM;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2473
    }
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2474
2719
94c9657e0bee Xenomai 2 to 3 migration says "RTDM drivers implementing differentiated ioctl() support for both domains should serve all real-time only requests from ioctl_rt(), returning -ENOSYS for any unrecognized request, which will cause the adaptive switch to take place automatically to the ioctl_nrt() handler. The ioctl_nrt() should then implement all requests which may be valid from the regular Linux domain exclusively."
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2712
diff changeset
  2475
    if (ec_copy_from_user(sdo_data, (void __user *) data.data, data.size)) {
2433
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2476
        kfree(sdo_data);
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2477
        return -EFAULT;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2478
    }
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2479
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2480
    if (down_interruptible(&master->master_sem)) {
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2481
        kfree(sdo_data);
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2482
        return -EINTR;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2483
    }
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2484
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2485
    if (!(sc = ec_master_get_config(master, data.config_index))) {
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2486
        up(&master->master_sem);
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2487
        kfree(sdo_data);
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2488
        return -ENOENT;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2489
    }
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2490
2522
ec403cf308eb Updated Doxygen documentation.
Florian Pose <fp@igh-essen.com>
parents: 2505
diff changeset
  2491
    up(&master->master_sem); /** \todo sc could be invalidated */
2433
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2492
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2493
    if (data.complete_access) {
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2494
        ret = ecrt_slave_config_complete_sdo(sc,
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2495
                data.index, sdo_data, data.size);
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2496
    } else {
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2497
        ret = ecrt_slave_config_sdo(sc, data.index, data.subindex, sdo_data,
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2498
                data.size);
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2499
    }
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2500
    kfree(sdo_data);
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2501
    return ret;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2502
}
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2503
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2504
/*****************************************************************************/
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2505
2438
9c3e629a220c Added API for querying CoE emergency requests.
Florian Pose <fp@igh-essen.com>
parents: 2435
diff changeset
  2506
/** Set the emergency ring buffer size.
2522
ec403cf308eb Updated Doxygen documentation.
Florian Pose <fp@igh-essen.com>
parents: 2505
diff changeset
  2507
 *
ec403cf308eb Updated Doxygen documentation.
Florian Pose <fp@igh-essen.com>
parents: 2505
diff changeset
  2508
 * \return Zero on success, otherwise a negative error code.
2438
9c3e629a220c Added API for querying CoE emergency requests.
Florian Pose <fp@igh-essen.com>
parents: 2435
diff changeset
  2509
 */
2481
c99ff159b60d Added function attribute definition.
Florian Pose <fp@igh-essen.com>
parents: 2477
diff changeset
  2510
static ATTRIBUTES int ec_ioctl_sc_emerg_size(
2438
9c3e629a220c Added API for querying CoE emergency requests.
Florian Pose <fp@igh-essen.com>
parents: 2435
diff changeset
  2511
        ec_master_t *master, /**< EtherCAT master. */
9c3e629a220c Added API for querying CoE emergency requests.
Florian Pose <fp@igh-essen.com>
parents: 2435
diff changeset
  2512
        void *arg, /**< ioctl() argument. */
9c3e629a220c Added API for querying CoE emergency requests.
Florian Pose <fp@igh-essen.com>
parents: 2435
diff changeset
  2513
        ec_ioctl_context_t *ctx /**< Private data structure of file handle. */
9c3e629a220c Added API for querying CoE emergency requests.
Florian Pose <fp@igh-essen.com>
parents: 2435
diff changeset
  2514
        )
9c3e629a220c Added API for querying CoE emergency requests.
Florian Pose <fp@igh-essen.com>
parents: 2435
diff changeset
  2515
{
9c3e629a220c Added API for querying CoE emergency requests.
Florian Pose <fp@igh-essen.com>
parents: 2435
diff changeset
  2516
    ec_ioctl_sc_emerg_t io;
9c3e629a220c Added API for querying CoE emergency requests.
Florian Pose <fp@igh-essen.com>
parents: 2435
diff changeset
  2517
    ec_slave_config_t *sc;
9c3e629a220c Added API for querying CoE emergency requests.
Florian Pose <fp@igh-essen.com>
parents: 2435
diff changeset
  2518
    int ret;
9c3e629a220c Added API for querying CoE emergency requests.
Florian Pose <fp@igh-essen.com>
parents: 2435
diff changeset
  2519
9c3e629a220c Added API for querying CoE emergency requests.
Florian Pose <fp@igh-essen.com>
parents: 2435
diff changeset
  2520
    if (unlikely(!ctx->requested))
9c3e629a220c Added API for querying CoE emergency requests.
Florian Pose <fp@igh-essen.com>
parents: 2435
diff changeset
  2521
        return -EPERM;
9c3e629a220c Added API for querying CoE emergency requests.
Florian Pose <fp@igh-essen.com>
parents: 2435
diff changeset
  2522
2719
94c9657e0bee Xenomai 2 to 3 migration says "RTDM drivers implementing differentiated ioctl() support for both domains should serve all real-time only requests from ioctl_rt(), returning -ENOSYS for any unrecognized request, which will cause the adaptive switch to take place automatically to the ioctl_nrt() handler. The ioctl_nrt() should then implement all requests which may be valid from the regular Linux domain exclusively."
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2712
diff changeset
  2523
    if (ec_copy_from_user(&io, (void __user *) arg, sizeof(io)))
2438
9c3e629a220c Added API for querying CoE emergency requests.
Florian Pose <fp@igh-essen.com>
parents: 2435
diff changeset
  2524
        return -EFAULT;
9c3e629a220c Added API for querying CoE emergency requests.
Florian Pose <fp@igh-essen.com>
parents: 2435
diff changeset
  2525
9c3e629a220c Added API for querying CoE emergency requests.
Florian Pose <fp@igh-essen.com>
parents: 2435
diff changeset
  2526
    if (down_interruptible(&master->master_sem)) {
9c3e629a220c Added API for querying CoE emergency requests.
Florian Pose <fp@igh-essen.com>
parents: 2435
diff changeset
  2527
        return -EINTR;
9c3e629a220c Added API for querying CoE emergency requests.
Florian Pose <fp@igh-essen.com>
parents: 2435
diff changeset
  2528
    }
9c3e629a220c Added API for querying CoE emergency requests.
Florian Pose <fp@igh-essen.com>
parents: 2435
diff changeset
  2529
9c3e629a220c Added API for querying CoE emergency requests.
Florian Pose <fp@igh-essen.com>
parents: 2435
diff changeset
  2530
    if (!(sc = ec_master_get_config(master, io.config_index))) {
9c3e629a220c Added API for querying CoE emergency requests.
Florian Pose <fp@igh-essen.com>
parents: 2435
diff changeset
  2531
        up(&master->master_sem);
9c3e629a220c Added API for querying CoE emergency requests.
Florian Pose <fp@igh-essen.com>
parents: 2435
diff changeset
  2532
        return -ENOENT;
9c3e629a220c Added API for querying CoE emergency requests.
Florian Pose <fp@igh-essen.com>
parents: 2435
diff changeset
  2533
    }
9c3e629a220c Added API for querying CoE emergency requests.
Florian Pose <fp@igh-essen.com>
parents: 2435
diff changeset
  2534
9c3e629a220c Added API for querying CoE emergency requests.
Florian Pose <fp@igh-essen.com>
parents: 2435
diff changeset
  2535
    ret = ecrt_slave_config_emerg_size(sc, io.size);
9c3e629a220c Added API for querying CoE emergency requests.
Florian Pose <fp@igh-essen.com>
parents: 2435
diff changeset
  2536
9c3e629a220c Added API for querying CoE emergency requests.
Florian Pose <fp@igh-essen.com>
parents: 2435
diff changeset
  2537
    up(&master->master_sem);
9c3e629a220c Added API for querying CoE emergency requests.
Florian Pose <fp@igh-essen.com>
parents: 2435
diff changeset
  2538
9c3e629a220c Added API for querying CoE emergency requests.
Florian Pose <fp@igh-essen.com>
parents: 2435
diff changeset
  2539
    return ret;
9c3e629a220c Added API for querying CoE emergency requests.
Florian Pose <fp@igh-essen.com>
parents: 2435
diff changeset
  2540
}
9c3e629a220c Added API for querying CoE emergency requests.
Florian Pose <fp@igh-essen.com>
parents: 2435
diff changeset
  2541
9c3e629a220c Added API for querying CoE emergency requests.
Florian Pose <fp@igh-essen.com>
parents: 2435
diff changeset
  2542
/*****************************************************************************/
9c3e629a220c Added API for querying CoE emergency requests.
Florian Pose <fp@igh-essen.com>
parents: 2435
diff changeset
  2543
9c3e629a220c Added API for querying CoE emergency requests.
Florian Pose <fp@igh-essen.com>
parents: 2435
diff changeset
  2544
/** Get an emergency message from the ring.
2522
ec403cf308eb Updated Doxygen documentation.
Florian Pose <fp@igh-essen.com>
parents: 2505
diff changeset
  2545
 *
ec403cf308eb Updated Doxygen documentation.
Florian Pose <fp@igh-essen.com>
parents: 2505
diff changeset
  2546
 * \return Zero on success, otherwise a negative error code.
2438
9c3e629a220c Added API for querying CoE emergency requests.
Florian Pose <fp@igh-essen.com>
parents: 2435
diff changeset
  2547
 */
2481
c99ff159b60d Added function attribute definition.
Florian Pose <fp@igh-essen.com>
parents: 2477
diff changeset
  2548
static ATTRIBUTES int ec_ioctl_sc_emerg_pop(
2438
9c3e629a220c Added API for querying CoE emergency requests.
Florian Pose <fp@igh-essen.com>
parents: 2435
diff changeset
  2549
        ec_master_t *master, /**< EtherCAT master. */
9c3e629a220c Added API for querying CoE emergency requests.
Florian Pose <fp@igh-essen.com>
parents: 2435
diff changeset
  2550
        void *arg, /**< ioctl() argument. */
9c3e629a220c Added API for querying CoE emergency requests.
Florian Pose <fp@igh-essen.com>
parents: 2435
diff changeset
  2551
        ec_ioctl_context_t *ctx /**< Private data structure of file handle. */
9c3e629a220c Added API for querying CoE emergency requests.
Florian Pose <fp@igh-essen.com>
parents: 2435
diff changeset
  2552
        )
9c3e629a220c Added API for querying CoE emergency requests.
Florian Pose <fp@igh-essen.com>
parents: 2435
diff changeset
  2553
{
9c3e629a220c Added API for querying CoE emergency requests.
Florian Pose <fp@igh-essen.com>
parents: 2435
diff changeset
  2554
    ec_ioctl_sc_emerg_t io;
9c3e629a220c Added API for querying CoE emergency requests.
Florian Pose <fp@igh-essen.com>
parents: 2435
diff changeset
  2555
    ec_slave_config_t *sc;
9c3e629a220c Added API for querying CoE emergency requests.
Florian Pose <fp@igh-essen.com>
parents: 2435
diff changeset
  2556
    u8 msg[EC_COE_EMERGENCY_MSG_SIZE];
9c3e629a220c Added API for querying CoE emergency requests.
Florian Pose <fp@igh-essen.com>
parents: 2435
diff changeset
  2557
    int ret;
9c3e629a220c Added API for querying CoE emergency requests.
Florian Pose <fp@igh-essen.com>
parents: 2435
diff changeset
  2558
2484
1cf54e2452c4 Removed unnecessary semaphore uses for emergency requests.
Florian Pose <fp@igh-essen.com>
parents: 2483
diff changeset
  2559
    if (unlikely(!ctx->requested)) {
1cf54e2452c4 Removed unnecessary semaphore uses for emergency requests.
Florian Pose <fp@igh-essen.com>
parents: 2483
diff changeset
  2560
        return -EPERM;
1cf54e2452c4 Removed unnecessary semaphore uses for emergency requests.
Florian Pose <fp@igh-essen.com>
parents: 2483
diff changeset
  2561
    }
1cf54e2452c4 Removed unnecessary semaphore uses for emergency requests.
Florian Pose <fp@igh-essen.com>
parents: 2483
diff changeset
  2562
2719
94c9657e0bee Xenomai 2 to 3 migration says "RTDM drivers implementing differentiated ioctl() support for both domains should serve all real-time only requests from ioctl_rt(), returning -ENOSYS for any unrecognized request, which will cause the adaptive switch to take place automatically to the ioctl_nrt() handler. The ioctl_nrt() should then implement all requests which may be valid from the regular Linux domain exclusively."
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2712
diff changeset
  2563
    if (ec_copy_from_user(&io, (void __user *) arg, sizeof(io))) {
2484
1cf54e2452c4 Removed unnecessary semaphore uses for emergency requests.
Florian Pose <fp@igh-essen.com>
parents: 2483
diff changeset
  2564
        return -EFAULT;
1cf54e2452c4 Removed unnecessary semaphore uses for emergency requests.
Florian Pose <fp@igh-essen.com>
parents: 2483
diff changeset
  2565
    }
1cf54e2452c4 Removed unnecessary semaphore uses for emergency requests.
Florian Pose <fp@igh-essen.com>
parents: 2483
diff changeset
  2566
1cf54e2452c4 Removed unnecessary semaphore uses for emergency requests.
Florian Pose <fp@igh-essen.com>
parents: 2483
diff changeset
  2567
    /* no locking of master_sem needed, because configuration will not be
1cf54e2452c4 Removed unnecessary semaphore uses for emergency requests.
Florian Pose <fp@igh-essen.com>
parents: 2483
diff changeset
  2568
     * deleted in the meantime. */
2438
9c3e629a220c Added API for querying CoE emergency requests.
Florian Pose <fp@igh-essen.com>
parents: 2435
diff changeset
  2569
9c3e629a220c Added API for querying CoE emergency requests.
Florian Pose <fp@igh-essen.com>
parents: 2435
diff changeset
  2570
    if (!(sc = ec_master_get_config(master, io.config_index))) {
9c3e629a220c Added API for querying CoE emergency requests.
Florian Pose <fp@igh-essen.com>
parents: 2435
diff changeset
  2571
        return -ENOENT;
9c3e629a220c Added API for querying CoE emergency requests.
Florian Pose <fp@igh-essen.com>
parents: 2435
diff changeset
  2572
    }
9c3e629a220c Added API for querying CoE emergency requests.
Florian Pose <fp@igh-essen.com>
parents: 2435
diff changeset
  2573
9c3e629a220c Added API for querying CoE emergency requests.
Florian Pose <fp@igh-essen.com>
parents: 2435
diff changeset
  2574
    ret = ecrt_slave_config_emerg_pop(sc, msg);
9c3e629a220c Added API for querying CoE emergency requests.
Florian Pose <fp@igh-essen.com>
parents: 2435
diff changeset
  2575
    if (ret < 0) {
9c3e629a220c Added API for querying CoE emergency requests.
Florian Pose <fp@igh-essen.com>
parents: 2435
diff changeset
  2576
        return ret;
9c3e629a220c Added API for querying CoE emergency requests.
Florian Pose <fp@igh-essen.com>
parents: 2435
diff changeset
  2577
    }
9c3e629a220c Added API for querying CoE emergency requests.
Florian Pose <fp@igh-essen.com>
parents: 2435
diff changeset
  2578
2719
94c9657e0bee Xenomai 2 to 3 migration says "RTDM drivers implementing differentiated ioctl() support for both domains should serve all real-time only requests from ioctl_rt(), returning -ENOSYS for any unrecognized request, which will cause the adaptive switch to take place automatically to the ioctl_nrt() handler. The ioctl_nrt() should then implement all requests which may be valid from the regular Linux domain exclusively."
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2712
diff changeset
  2579
    if (ec_copy_to_user((void __user *) io.target, msg, sizeof(msg))) {
2438
9c3e629a220c Added API for querying CoE emergency requests.
Florian Pose <fp@igh-essen.com>
parents: 2435
diff changeset
  2580
        return -EFAULT;
9c3e629a220c Added API for querying CoE emergency requests.
Florian Pose <fp@igh-essen.com>
parents: 2435
diff changeset
  2581
    }
9c3e629a220c Added API for querying CoE emergency requests.
Florian Pose <fp@igh-essen.com>
parents: 2435
diff changeset
  2582
9c3e629a220c Added API for querying CoE emergency requests.
Florian Pose <fp@igh-essen.com>
parents: 2435
diff changeset
  2583
    return ret;
9c3e629a220c Added API for querying CoE emergency requests.
Florian Pose <fp@igh-essen.com>
parents: 2435
diff changeset
  2584
}
9c3e629a220c Added API for querying CoE emergency requests.
Florian Pose <fp@igh-essen.com>
parents: 2435
diff changeset
  2585
9c3e629a220c Added API for querying CoE emergency requests.
Florian Pose <fp@igh-essen.com>
parents: 2435
diff changeset
  2586
/*****************************************************************************/
9c3e629a220c Added API for querying CoE emergency requests.
Florian Pose <fp@igh-essen.com>
parents: 2435
diff changeset
  2587
9c3e629a220c Added API for querying CoE emergency requests.
Florian Pose <fp@igh-essen.com>
parents: 2435
diff changeset
  2588
/** Clear the emergency ring.
2522
ec403cf308eb Updated Doxygen documentation.
Florian Pose <fp@igh-essen.com>
parents: 2505
diff changeset
  2589
 *
ec403cf308eb Updated Doxygen documentation.
Florian Pose <fp@igh-essen.com>
parents: 2505
diff changeset
  2590
 * \return Zero on success, otherwise a negative error code.
2438
9c3e629a220c Added API for querying CoE emergency requests.
Florian Pose <fp@igh-essen.com>
parents: 2435
diff changeset
  2591
 */
2481
c99ff159b60d Added function attribute definition.
Florian Pose <fp@igh-essen.com>
parents: 2477
diff changeset
  2592
static ATTRIBUTES int ec_ioctl_sc_emerg_clear(
2438
9c3e629a220c Added API for querying CoE emergency requests.
Florian Pose <fp@igh-essen.com>
parents: 2435
diff changeset
  2593
        ec_master_t *master, /**< EtherCAT master. */
9c3e629a220c Added API for querying CoE emergency requests.
Florian Pose <fp@igh-essen.com>
parents: 2435
diff changeset
  2594
        void *arg, /**< ioctl() argument. */
9c3e629a220c Added API for querying CoE emergency requests.
Florian Pose <fp@igh-essen.com>
parents: 2435
diff changeset
  2595
        ec_ioctl_context_t *ctx /**< Private data structure of file handle. */
9c3e629a220c Added API for querying CoE emergency requests.
Florian Pose <fp@igh-essen.com>
parents: 2435
diff changeset
  2596
        )
9c3e629a220c Added API for querying CoE emergency requests.
Florian Pose <fp@igh-essen.com>
parents: 2435
diff changeset
  2597
{
9c3e629a220c Added API for querying CoE emergency requests.
Florian Pose <fp@igh-essen.com>
parents: 2435
diff changeset
  2598
    ec_ioctl_sc_emerg_t io;
9c3e629a220c Added API for querying CoE emergency requests.
Florian Pose <fp@igh-essen.com>
parents: 2435
diff changeset
  2599
    ec_slave_config_t *sc;
9c3e629a220c Added API for querying CoE emergency requests.
Florian Pose <fp@igh-essen.com>
parents: 2435
diff changeset
  2600
2484
1cf54e2452c4 Removed unnecessary semaphore uses for emergency requests.
Florian Pose <fp@igh-essen.com>
parents: 2483
diff changeset
  2601
    if (unlikely(!ctx->requested)) {
1cf54e2452c4 Removed unnecessary semaphore uses for emergency requests.
Florian Pose <fp@igh-essen.com>
parents: 2483
diff changeset
  2602
        return -EPERM;
1cf54e2452c4 Removed unnecessary semaphore uses for emergency requests.
Florian Pose <fp@igh-essen.com>
parents: 2483
diff changeset
  2603
    }
1cf54e2452c4 Removed unnecessary semaphore uses for emergency requests.
Florian Pose <fp@igh-essen.com>
parents: 2483
diff changeset
  2604
2719
94c9657e0bee Xenomai 2 to 3 migration says "RTDM drivers implementing differentiated ioctl() support for both domains should serve all real-time only requests from ioctl_rt(), returning -ENOSYS for any unrecognized request, which will cause the adaptive switch to take place automatically to the ioctl_nrt() handler. The ioctl_nrt() should then implement all requests which may be valid from the regular Linux domain exclusively."
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2712
diff changeset
  2605
    if (ec_copy_from_user(&io, (void __user *) arg, sizeof(io))) {
2484
1cf54e2452c4 Removed unnecessary semaphore uses for emergency requests.
Florian Pose <fp@igh-essen.com>
parents: 2483
diff changeset
  2606
        return -EFAULT;
1cf54e2452c4 Removed unnecessary semaphore uses for emergency requests.
Florian Pose <fp@igh-essen.com>
parents: 2483
diff changeset
  2607
    }
1cf54e2452c4 Removed unnecessary semaphore uses for emergency requests.
Florian Pose <fp@igh-essen.com>
parents: 2483
diff changeset
  2608
1cf54e2452c4 Removed unnecessary semaphore uses for emergency requests.
Florian Pose <fp@igh-essen.com>
parents: 2483
diff changeset
  2609
    /* no locking of master_sem needed, because configuration will not be
1cf54e2452c4 Removed unnecessary semaphore uses for emergency requests.
Florian Pose <fp@igh-essen.com>
parents: 2483
diff changeset
  2610
     * deleted in the meantime. */
2438
9c3e629a220c Added API for querying CoE emergency requests.
Florian Pose <fp@igh-essen.com>
parents: 2435
diff changeset
  2611
9c3e629a220c Added API for querying CoE emergency requests.
Florian Pose <fp@igh-essen.com>
parents: 2435
diff changeset
  2612
    if (!(sc = ec_master_get_config(master, io.config_index))) {
2484
1cf54e2452c4 Removed unnecessary semaphore uses for emergency requests.
Florian Pose <fp@igh-essen.com>
parents: 2483
diff changeset
  2613
        return -ENOENT;
1cf54e2452c4 Removed unnecessary semaphore uses for emergency requests.
Florian Pose <fp@igh-essen.com>
parents: 2483
diff changeset
  2614
    }
1cf54e2452c4 Removed unnecessary semaphore uses for emergency requests.
Florian Pose <fp@igh-essen.com>
parents: 2483
diff changeset
  2615
1cf54e2452c4 Removed unnecessary semaphore uses for emergency requests.
Florian Pose <fp@igh-essen.com>
parents: 2483
diff changeset
  2616
    return ecrt_slave_config_emerg_clear(sc);
2438
9c3e629a220c Added API for querying CoE emergency requests.
Florian Pose <fp@igh-essen.com>
parents: 2435
diff changeset
  2617
}
9c3e629a220c Added API for querying CoE emergency requests.
Florian Pose <fp@igh-essen.com>
parents: 2435
diff changeset
  2618
9c3e629a220c Added API for querying CoE emergency requests.
Florian Pose <fp@igh-essen.com>
parents: 2435
diff changeset
  2619
/*****************************************************************************/
9c3e629a220c Added API for querying CoE emergency requests.
Florian Pose <fp@igh-essen.com>
parents: 2435
diff changeset
  2620
9c3e629a220c Added API for querying CoE emergency requests.
Florian Pose <fp@igh-essen.com>
parents: 2435
diff changeset
  2621
/** Get the number of emergency overruns.
2522
ec403cf308eb Updated Doxygen documentation.
Florian Pose <fp@igh-essen.com>
parents: 2505
diff changeset
  2622
 *
ec403cf308eb Updated Doxygen documentation.
Florian Pose <fp@igh-essen.com>
parents: 2505
diff changeset
  2623
 * \return Zero on success, otherwise a negative error code.
2438
9c3e629a220c Added API for querying CoE emergency requests.
Florian Pose <fp@igh-essen.com>
parents: 2435
diff changeset
  2624
 */
2481
c99ff159b60d Added function attribute definition.
Florian Pose <fp@igh-essen.com>
parents: 2477
diff changeset
  2625
static ATTRIBUTES int ec_ioctl_sc_emerg_overruns(
2438
9c3e629a220c Added API for querying CoE emergency requests.
Florian Pose <fp@igh-essen.com>
parents: 2435
diff changeset
  2626
        ec_master_t *master, /**< EtherCAT master. */
9c3e629a220c Added API for querying CoE emergency requests.
Florian Pose <fp@igh-essen.com>
parents: 2435
diff changeset
  2627
        void *arg, /**< ioctl() argument. */
9c3e629a220c Added API for querying CoE emergency requests.
Florian Pose <fp@igh-essen.com>
parents: 2435
diff changeset
  2628
        ec_ioctl_context_t *ctx /**< Private data structure of file handle. */
9c3e629a220c Added API for querying CoE emergency requests.
Florian Pose <fp@igh-essen.com>
parents: 2435
diff changeset
  2629
        )
9c3e629a220c Added API for querying CoE emergency requests.
Florian Pose <fp@igh-essen.com>
parents: 2435
diff changeset
  2630
{
9c3e629a220c Added API for querying CoE emergency requests.
Florian Pose <fp@igh-essen.com>
parents: 2435
diff changeset
  2631
    ec_ioctl_sc_emerg_t io;
9c3e629a220c Added API for querying CoE emergency requests.
Florian Pose <fp@igh-essen.com>
parents: 2435
diff changeset
  2632
    ec_slave_config_t *sc;
9c3e629a220c Added API for querying CoE emergency requests.
Florian Pose <fp@igh-essen.com>
parents: 2435
diff changeset
  2633
    int ret;
9c3e629a220c Added API for querying CoE emergency requests.
Florian Pose <fp@igh-essen.com>
parents: 2435
diff changeset
  2634
2484
1cf54e2452c4 Removed unnecessary semaphore uses for emergency requests.
Florian Pose <fp@igh-essen.com>
parents: 2483
diff changeset
  2635
    if (unlikely(!ctx->requested)) {
1cf54e2452c4 Removed unnecessary semaphore uses for emergency requests.
Florian Pose <fp@igh-essen.com>
parents: 2483
diff changeset
  2636
        return -EPERM;
1cf54e2452c4 Removed unnecessary semaphore uses for emergency requests.
Florian Pose <fp@igh-essen.com>
parents: 2483
diff changeset
  2637
    }
1cf54e2452c4 Removed unnecessary semaphore uses for emergency requests.
Florian Pose <fp@igh-essen.com>
parents: 2483
diff changeset
  2638
2719
94c9657e0bee Xenomai 2 to 3 migration says "RTDM drivers implementing differentiated ioctl() support for both domains should serve all real-time only requests from ioctl_rt(), returning -ENOSYS for any unrecognized request, which will cause the adaptive switch to take place automatically to the ioctl_nrt() handler. The ioctl_nrt() should then implement all requests which may be valid from the regular Linux domain exclusively."
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2712
diff changeset
  2639
    if (ec_copy_from_user(&io, (void __user *) arg, sizeof(io))) {
2484
1cf54e2452c4 Removed unnecessary semaphore uses for emergency requests.
Florian Pose <fp@igh-essen.com>
parents: 2483
diff changeset
  2640
        return -EFAULT;
1cf54e2452c4 Removed unnecessary semaphore uses for emergency requests.
Florian Pose <fp@igh-essen.com>
parents: 2483
diff changeset
  2641
    }
1cf54e2452c4 Removed unnecessary semaphore uses for emergency requests.
Florian Pose <fp@igh-essen.com>
parents: 2483
diff changeset
  2642
1cf54e2452c4 Removed unnecessary semaphore uses for emergency requests.
Florian Pose <fp@igh-essen.com>
parents: 2483
diff changeset
  2643
    /* no locking of master_sem needed, because configuration will not be
1cf54e2452c4 Removed unnecessary semaphore uses for emergency requests.
Florian Pose <fp@igh-essen.com>
parents: 2483
diff changeset
  2644
     * deleted in the meantime. */
2438
9c3e629a220c Added API for querying CoE emergency requests.
Florian Pose <fp@igh-essen.com>
parents: 2435
diff changeset
  2645
9c3e629a220c Added API for querying CoE emergency requests.
Florian Pose <fp@igh-essen.com>
parents: 2435
diff changeset
  2646
    if (!(sc = ec_master_get_config(master, io.config_index))) {
9c3e629a220c Added API for querying CoE emergency requests.
Florian Pose <fp@igh-essen.com>
parents: 2435
diff changeset
  2647
        return -ENOENT;
9c3e629a220c Added API for querying CoE emergency requests.
Florian Pose <fp@igh-essen.com>
parents: 2435
diff changeset
  2648
    }
9c3e629a220c Added API for querying CoE emergency requests.
Florian Pose <fp@igh-essen.com>
parents: 2435
diff changeset
  2649
9c3e629a220c Added API for querying CoE emergency requests.
Florian Pose <fp@igh-essen.com>
parents: 2435
diff changeset
  2650
    ret = ecrt_slave_config_emerg_overruns(sc);
9c3e629a220c Added API for querying CoE emergency requests.
Florian Pose <fp@igh-essen.com>
parents: 2435
diff changeset
  2651
    if (ret < 0) {
9c3e629a220c Added API for querying CoE emergency requests.
Florian Pose <fp@igh-essen.com>
parents: 2435
diff changeset
  2652
        return ret;
9c3e629a220c Added API for querying CoE emergency requests.
Florian Pose <fp@igh-essen.com>
parents: 2435
diff changeset
  2653
    }
9c3e629a220c Added API for querying CoE emergency requests.
Florian Pose <fp@igh-essen.com>
parents: 2435
diff changeset
  2654
9c3e629a220c Added API for querying CoE emergency requests.
Florian Pose <fp@igh-essen.com>
parents: 2435
diff changeset
  2655
    io.overruns = ret;
9c3e629a220c Added API for querying CoE emergency requests.
Florian Pose <fp@igh-essen.com>
parents: 2435
diff changeset
  2656
2719
94c9657e0bee Xenomai 2 to 3 migration says "RTDM drivers implementing differentiated ioctl() support for both domains should serve all real-time only requests from ioctl_rt(), returning -ENOSYS for any unrecognized request, which will cause the adaptive switch to take place automatically to the ioctl_nrt() handler. The ioctl_nrt() should then implement all requests which may be valid from the regular Linux domain exclusively."
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2712
diff changeset
  2657
    if (ec_copy_to_user((void __user *) arg, &io, sizeof(io))) {
2438
9c3e629a220c Added API for querying CoE emergency requests.
Florian Pose <fp@igh-essen.com>
parents: 2435
diff changeset
  2658
        return -EFAULT;
9c3e629a220c Added API for querying CoE emergency requests.
Florian Pose <fp@igh-essen.com>
parents: 2435
diff changeset
  2659
    }
9c3e629a220c Added API for querying CoE emergency requests.
Florian Pose <fp@igh-essen.com>
parents: 2435
diff changeset
  2660
9c3e629a220c Added API for querying CoE emergency requests.
Florian Pose <fp@igh-essen.com>
parents: 2435
diff changeset
  2661
    return 0;
9c3e629a220c Added API for querying CoE emergency requests.
Florian Pose <fp@igh-essen.com>
parents: 2435
diff changeset
  2662
}
9c3e629a220c Added API for querying CoE emergency requests.
Florian Pose <fp@igh-essen.com>
parents: 2435
diff changeset
  2663
9c3e629a220c Added API for querying CoE emergency requests.
Florian Pose <fp@igh-essen.com>
parents: 2435
diff changeset
  2664
/*****************************************************************************/
9c3e629a220c Added API for querying CoE emergency requests.
Florian Pose <fp@igh-essen.com>
parents: 2435
diff changeset
  2665
2433
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2666
/** Create an SDO request.
2522
ec403cf308eb Updated Doxygen documentation.
Florian Pose <fp@igh-essen.com>
parents: 2505
diff changeset
  2667
 *
ec403cf308eb Updated Doxygen documentation.
Florian Pose <fp@igh-essen.com>
parents: 2505
diff changeset
  2668
 * \return Zero on success, otherwise a negative error code.
2433
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2669
 */
2481
c99ff159b60d Added function attribute definition.
Florian Pose <fp@igh-essen.com>
parents: 2477
diff changeset
  2670
static ATTRIBUTES int ec_ioctl_sc_create_sdo_request(
2433
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2671
        ec_master_t *master, /**< EtherCAT master. */
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2672
        void *arg, /**< ioctl() argument. */
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2673
        ec_ioctl_context_t *ctx /**< Private data structure of file handle. */
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2674
        )
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2675
{
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2676
    ec_ioctl_sdo_request_t data;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2677
    ec_slave_config_t *sc;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2678
    ec_sdo_request_t *req;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2679
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2680
    if (unlikely(!ctx->requested))
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2681
        return -EPERM;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2682
2719
94c9657e0bee Xenomai 2 to 3 migration says "RTDM drivers implementing differentiated ioctl() support for both domains should serve all real-time only requests from ioctl_rt(), returning -ENOSYS for any unrecognized request, which will cause the adaptive switch to take place automatically to the ioctl_nrt() handler. The ioctl_nrt() should then implement all requests which may be valid from the regular Linux domain exclusively."
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2712
diff changeset
  2683
    if (ec_copy_from_user(&data, (void __user *) arg, sizeof(data))) {
2433
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2684
        return -EFAULT;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2685
    }
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2686
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2687
    data.request_index = 0;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2688
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2689
    if (down_interruptible(&master->master_sem))
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2690
        return -EINTR;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2691
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2692
    sc = ec_master_get_config(master, data.config_index);
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2693
    if (!sc) {
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2694
        up(&master->master_sem);
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2695
        return -ENOENT;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2696
    }
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2697
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2698
    list_for_each_entry(req, &sc->sdo_requests, list) {
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2699
        data.request_index++;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2700
    }
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2701
2522
ec403cf308eb Updated Doxygen documentation.
Florian Pose <fp@igh-essen.com>
parents: 2505
diff changeset
  2702
    up(&master->master_sem); /** \todo sc could be invalidated */
2433
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2703
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2704
    req = ecrt_slave_config_create_sdo_request_err(sc, data.sdo_index,
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2705
            data.sdo_subindex, data.size);
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2706
    if (IS_ERR(req))
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2707
        return PTR_ERR(req);
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2708
2719
94c9657e0bee Xenomai 2 to 3 migration says "RTDM drivers implementing differentiated ioctl() support for both domains should serve all real-time only requests from ioctl_rt(), returning -ENOSYS for any unrecognized request, which will cause the adaptive switch to take place automatically to the ioctl_nrt() handler. The ioctl_nrt() should then implement all requests which may be valid from the regular Linux domain exclusively."
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2712
diff changeset
  2709
    if (ec_copy_to_user((void __user *) arg, &data, sizeof(data)))
2433
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2710
        return -EFAULT;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2711
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2712
    return 0;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2713
}
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2714
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2715
/*****************************************************************************/
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2716
2443
2c3ccdde3919 Added interface to read/write register contents; re-worked register requests.
Florian Pose <fp@igh-essen.com>
parents: 2438
diff changeset
  2717
/** Create a register request.
2522
ec403cf308eb Updated Doxygen documentation.
Florian Pose <fp@igh-essen.com>
parents: 2505
diff changeset
  2718
 *
ec403cf308eb Updated Doxygen documentation.
Florian Pose <fp@igh-essen.com>
parents: 2505
diff changeset
  2719
 * \return Zero on success, otherwise a negative error code.
2443
2c3ccdde3919 Added interface to read/write register contents; re-worked register requests.
Florian Pose <fp@igh-essen.com>
parents: 2438
diff changeset
  2720
 */
2481
c99ff159b60d Added function attribute definition.
Florian Pose <fp@igh-essen.com>
parents: 2477
diff changeset
  2721
static ATTRIBUTES int ec_ioctl_sc_create_reg_request(
2443
2c3ccdde3919 Added interface to read/write register contents; re-worked register requests.
Florian Pose <fp@igh-essen.com>
parents: 2438
diff changeset
  2722
        ec_master_t *master, /**< EtherCAT master. */
2c3ccdde3919 Added interface to read/write register contents; re-worked register requests.
Florian Pose <fp@igh-essen.com>
parents: 2438
diff changeset
  2723
        void *arg, /**< ioctl() argument. */
2c3ccdde3919 Added interface to read/write register contents; re-worked register requests.
Florian Pose <fp@igh-essen.com>
parents: 2438
diff changeset
  2724
        ec_ioctl_context_t *ctx /**< Private data structure of file handle. */
2c3ccdde3919 Added interface to read/write register contents; re-worked register requests.
Florian Pose <fp@igh-essen.com>
parents: 2438
diff changeset
  2725
        )
2c3ccdde3919 Added interface to read/write register contents; re-worked register requests.
Florian Pose <fp@igh-essen.com>
parents: 2438
diff changeset
  2726
{
2c3ccdde3919 Added interface to read/write register contents; re-worked register requests.
Florian Pose <fp@igh-essen.com>
parents: 2438
diff changeset
  2727
    ec_ioctl_reg_request_t io;
2c3ccdde3919 Added interface to read/write register contents; re-worked register requests.
Florian Pose <fp@igh-essen.com>
parents: 2438
diff changeset
  2728
    ec_slave_config_t *sc;
2c3ccdde3919 Added interface to read/write register contents; re-worked register requests.
Florian Pose <fp@igh-essen.com>
parents: 2438
diff changeset
  2729
    ec_reg_request_t *reg;
2c3ccdde3919 Added interface to read/write register contents; re-worked register requests.
Florian Pose <fp@igh-essen.com>
parents: 2438
diff changeset
  2730
2c3ccdde3919 Added interface to read/write register contents; re-worked register requests.
Florian Pose <fp@igh-essen.com>
parents: 2438
diff changeset
  2731
    if (unlikely(!ctx->requested)) {
2c3ccdde3919 Added interface to read/write register contents; re-worked register requests.
Florian Pose <fp@igh-essen.com>
parents: 2438
diff changeset
  2732
        return -EPERM;
2c3ccdde3919 Added interface to read/write register contents; re-worked register requests.
Florian Pose <fp@igh-essen.com>
parents: 2438
diff changeset
  2733
    }
2c3ccdde3919 Added interface to read/write register contents; re-worked register requests.
Florian Pose <fp@igh-essen.com>
parents: 2438
diff changeset
  2734
2719
94c9657e0bee Xenomai 2 to 3 migration says "RTDM drivers implementing differentiated ioctl() support for both domains should serve all real-time only requests from ioctl_rt(), returning -ENOSYS for any unrecognized request, which will cause the adaptive switch to take place automatically to the ioctl_nrt() handler. The ioctl_nrt() should then implement all requests which may be valid from the regular Linux domain exclusively."
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2712
diff changeset
  2735
    if (ec_copy_from_user(&io, (void __user *) arg, sizeof(io))) {
2443
2c3ccdde3919 Added interface to read/write register contents; re-worked register requests.
Florian Pose <fp@igh-essen.com>
parents: 2438
diff changeset
  2736
        return -EFAULT;
2c3ccdde3919 Added interface to read/write register contents; re-worked register requests.
Florian Pose <fp@igh-essen.com>
parents: 2438
diff changeset
  2737
    }
2c3ccdde3919 Added interface to read/write register contents; re-worked register requests.
Florian Pose <fp@igh-essen.com>
parents: 2438
diff changeset
  2738
2c3ccdde3919 Added interface to read/write register contents; re-worked register requests.
Florian Pose <fp@igh-essen.com>
parents: 2438
diff changeset
  2739
    io.request_index = 0;
2c3ccdde3919 Added interface to read/write register contents; re-worked register requests.
Florian Pose <fp@igh-essen.com>
parents: 2438
diff changeset
  2740
2c3ccdde3919 Added interface to read/write register contents; re-worked register requests.
Florian Pose <fp@igh-essen.com>
parents: 2438
diff changeset
  2741
    if (down_interruptible(&master->master_sem)) {
2c3ccdde3919 Added interface to read/write register contents; re-worked register requests.
Florian Pose <fp@igh-essen.com>
parents: 2438
diff changeset
  2742
        return -EINTR;
2c3ccdde3919 Added interface to read/write register contents; re-worked register requests.
Florian Pose <fp@igh-essen.com>
parents: 2438
diff changeset
  2743
    }
2c3ccdde3919 Added interface to read/write register contents; re-worked register requests.
Florian Pose <fp@igh-essen.com>
parents: 2438
diff changeset
  2744
2c3ccdde3919 Added interface to read/write register contents; re-worked register requests.
Florian Pose <fp@igh-essen.com>
parents: 2438
diff changeset
  2745
    sc = ec_master_get_config(master, io.config_index);
2c3ccdde3919 Added interface to read/write register contents; re-worked register requests.
Florian Pose <fp@igh-essen.com>
parents: 2438
diff changeset
  2746
    if (!sc) {
2c3ccdde3919 Added interface to read/write register contents; re-worked register requests.
Florian Pose <fp@igh-essen.com>
parents: 2438
diff changeset
  2747
        up(&master->master_sem);
2c3ccdde3919 Added interface to read/write register contents; re-worked register requests.
Florian Pose <fp@igh-essen.com>
parents: 2438
diff changeset
  2748
        return -ENOENT;
2c3ccdde3919 Added interface to read/write register contents; re-worked register requests.
Florian Pose <fp@igh-essen.com>
parents: 2438
diff changeset
  2749
    }
2c3ccdde3919 Added interface to read/write register contents; re-worked register requests.
Florian Pose <fp@igh-essen.com>
parents: 2438
diff changeset
  2750
2c3ccdde3919 Added interface to read/write register contents; re-worked register requests.
Florian Pose <fp@igh-essen.com>
parents: 2438
diff changeset
  2751
    list_for_each_entry(reg, &sc->reg_requests, list) {
2c3ccdde3919 Added interface to read/write register contents; re-worked register requests.
Florian Pose <fp@igh-essen.com>
parents: 2438
diff changeset
  2752
        io.request_index++;
2c3ccdde3919 Added interface to read/write register contents; re-worked register requests.
Florian Pose <fp@igh-essen.com>
parents: 2438
diff changeset
  2753
    }
2c3ccdde3919 Added interface to read/write register contents; re-worked register requests.
Florian Pose <fp@igh-essen.com>
parents: 2438
diff changeset
  2754
2522
ec403cf308eb Updated Doxygen documentation.
Florian Pose <fp@igh-essen.com>
parents: 2505
diff changeset
  2755
    up(&master->master_sem); /** \todo sc could be invalidated */
2443
2c3ccdde3919 Added interface to read/write register contents; re-worked register requests.
Florian Pose <fp@igh-essen.com>
parents: 2438
diff changeset
  2756
2c3ccdde3919 Added interface to read/write register contents; re-worked register requests.
Florian Pose <fp@igh-essen.com>
parents: 2438
diff changeset
  2757
    reg = ecrt_slave_config_create_reg_request_err(sc, io.mem_size);
2c3ccdde3919 Added interface to read/write register contents; re-worked register requests.
Florian Pose <fp@igh-essen.com>
parents: 2438
diff changeset
  2758
    if (IS_ERR(reg)) {
2c3ccdde3919 Added interface to read/write register contents; re-worked register requests.
Florian Pose <fp@igh-essen.com>
parents: 2438
diff changeset
  2759
        return PTR_ERR(reg);
2c3ccdde3919 Added interface to read/write register contents; re-worked register requests.
Florian Pose <fp@igh-essen.com>
parents: 2438
diff changeset
  2760
    }
2c3ccdde3919 Added interface to read/write register contents; re-worked register requests.
Florian Pose <fp@igh-essen.com>
parents: 2438
diff changeset
  2761
2719
94c9657e0bee Xenomai 2 to 3 migration says "RTDM drivers implementing differentiated ioctl() support for both domains should serve all real-time only requests from ioctl_rt(), returning -ENOSYS for any unrecognized request, which will cause the adaptive switch to take place automatically to the ioctl_nrt() handler. The ioctl_nrt() should then implement all requests which may be valid from the regular Linux domain exclusively."
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2712
diff changeset
  2762
    if (ec_copy_to_user((void __user *) arg, &io, sizeof(io))) {
2443
2c3ccdde3919 Added interface to read/write register contents; re-worked register requests.
Florian Pose <fp@igh-essen.com>
parents: 2438
diff changeset
  2763
        return -EFAULT;
2c3ccdde3919 Added interface to read/write register contents; re-worked register requests.
Florian Pose <fp@igh-essen.com>
parents: 2438
diff changeset
  2764
    }
2c3ccdde3919 Added interface to read/write register contents; re-worked register requests.
Florian Pose <fp@igh-essen.com>
parents: 2438
diff changeset
  2765
2c3ccdde3919 Added interface to read/write register contents; re-worked register requests.
Florian Pose <fp@igh-essen.com>
parents: 2438
diff changeset
  2766
    return 0;
2c3ccdde3919 Added interface to read/write register contents; re-worked register requests.
Florian Pose <fp@igh-essen.com>
parents: 2438
diff changeset
  2767
}
2c3ccdde3919 Added interface to read/write register contents; re-worked register requests.
Florian Pose <fp@igh-essen.com>
parents: 2438
diff changeset
  2768
2c3ccdde3919 Added interface to read/write register contents; re-worked register requests.
Florian Pose <fp@igh-essen.com>
parents: 2438
diff changeset
  2769
/*****************************************************************************/
2c3ccdde3919 Added interface to read/write register contents; re-worked register requests.
Florian Pose <fp@igh-essen.com>
parents: 2438
diff changeset
  2770
2433
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2771
/** Create a VoE handler.
2522
ec403cf308eb Updated Doxygen documentation.
Florian Pose <fp@igh-essen.com>
parents: 2505
diff changeset
  2772
 *
ec403cf308eb Updated Doxygen documentation.
Florian Pose <fp@igh-essen.com>
parents: 2505
diff changeset
  2773
 * \return Zero on success, otherwise a negative error code.
2433
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2774
 */
2481
c99ff159b60d Added function attribute definition.
Florian Pose <fp@igh-essen.com>
parents: 2477
diff changeset
  2775
static ATTRIBUTES int ec_ioctl_sc_create_voe_handler(
2433
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2776
        ec_master_t *master, /**< EtherCAT master. */
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2777
        void *arg, /**< ioctl() argument. */
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2778
        ec_ioctl_context_t *ctx /**< Private data structure of file handle. */
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2779
        )
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2780
{
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2781
    ec_ioctl_voe_t data;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2782
    ec_slave_config_t *sc;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2783
    ec_voe_handler_t *voe;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2784
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2785
    if (unlikely(!ctx->requested))
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2786
        return -EPERM;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2787
2719
94c9657e0bee Xenomai 2 to 3 migration says "RTDM drivers implementing differentiated ioctl() support for both domains should serve all real-time only requests from ioctl_rt(), returning -ENOSYS for any unrecognized request, which will cause the adaptive switch to take place automatically to the ioctl_nrt() handler. The ioctl_nrt() should then implement all requests which may be valid from the regular Linux domain exclusively."
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2712
diff changeset
  2788
    if (ec_copy_from_user(&data, (void __user *) arg, sizeof(data))) {
2433
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2789
        return -EFAULT;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2790
    }
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2791
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2792
    data.voe_index = 0;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2793
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2794
    if (down_interruptible(&master->master_sem))
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2795
        return -EINTR;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2796
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2797
    sc = ec_master_get_config(master, data.config_index);
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2798
    if (!sc) {
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2799
        up(&master->master_sem);
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2800
        return -ENOENT;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2801
    }
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2802
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2803
    list_for_each_entry(voe, &sc->voe_handlers, list) {
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2804
        data.voe_index++;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2805
    }
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2806
2522
ec403cf308eb Updated Doxygen documentation.
Florian Pose <fp@igh-essen.com>
parents: 2505
diff changeset
  2807
    up(&master->master_sem); /** \todo sc could be invalidated */
2433
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2808
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2809
    voe = ecrt_slave_config_create_voe_handler_err(sc, data.size);
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2810
    if (IS_ERR(voe))
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2811
        return PTR_ERR(voe);
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2812
2719
94c9657e0bee Xenomai 2 to 3 migration says "RTDM drivers implementing differentiated ioctl() support for both domains should serve all real-time only requests from ioctl_rt(), returning -ENOSYS for any unrecognized request, which will cause the adaptive switch to take place automatically to the ioctl_nrt() handler. The ioctl_nrt() should then implement all requests which may be valid from the regular Linux domain exclusively."
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2712
diff changeset
  2813
    if (ec_copy_to_user((void __user *) arg, &data, sizeof(data)))
2433
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2814
        return -EFAULT;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2815
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2816
    return 0;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2817
}
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2818
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2819
/*****************************************************************************/
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2820
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2821
/** Get the slave configuration's state.
2522
ec403cf308eb Updated Doxygen documentation.
Florian Pose <fp@igh-essen.com>
parents: 2505
diff changeset
  2822
 *
ec403cf308eb Updated Doxygen documentation.
Florian Pose <fp@igh-essen.com>
parents: 2505
diff changeset
  2823
 * \return Zero on success, otherwise a negative error code.
2433
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2824
 */
2481
c99ff159b60d Added function attribute definition.
Florian Pose <fp@igh-essen.com>
parents: 2477
diff changeset
  2825
static ATTRIBUTES int ec_ioctl_sc_state(
2433
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2826
        ec_master_t *master, /**< EtherCAT master. */
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2827
        void *arg, /**< ioctl() argument. */
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2828
        ec_ioctl_context_t *ctx /**< Private data structure of file handle. */
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2829
        )
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2830
{
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2831
    ec_ioctl_sc_state_t data;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2832
    const ec_slave_config_t *sc;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2833
    ec_slave_config_state_t state;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2834
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2835
    if (unlikely(!ctx->requested))
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2836
        return -EPERM;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2837
2719
94c9657e0bee Xenomai 2 to 3 migration says "RTDM drivers implementing differentiated ioctl() support for both domains should serve all real-time only requests from ioctl_rt(), returning -ENOSYS for any unrecognized request, which will cause the adaptive switch to take place automatically to the ioctl_nrt() handler. The ioctl_nrt() should then implement all requests which may be valid from the regular Linux domain exclusively."
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2712
diff changeset
  2838
    if (ec_copy_from_user(&data, (void __user *) arg, sizeof(data))) {
2433
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2839
        return -EFAULT;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2840
    }
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2841
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2842
    /* no locking of master_sem needed, because sc will not be deleted in the
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2843
     * meantime. */
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2844
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2845
    if (!(sc = ec_master_get_config_const(master, data.config_index))) {
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2846
        return -ENOENT;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2847
    }
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2848
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2849
    ecrt_slave_config_state(sc, &state);
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2850
2719
94c9657e0bee Xenomai 2 to 3 migration says "RTDM drivers implementing differentiated ioctl() support for both domains should serve all real-time only requests from ioctl_rt(), returning -ENOSYS for any unrecognized request, which will cause the adaptive switch to take place automatically to the ioctl_nrt() handler. The ioctl_nrt() should then implement all requests which may be valid from the regular Linux domain exclusively."
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2712
diff changeset
  2851
    if (ec_copy_to_user((void __user *) data.state, &state, sizeof(state)))
2433
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2852
        return -EFAULT;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2853
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2854
    return 0;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2855
}
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2856
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2857
/*****************************************************************************/
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2858
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2859
/** Configures an IDN.
2522
ec403cf308eb Updated Doxygen documentation.
Florian Pose <fp@igh-essen.com>
parents: 2505
diff changeset
  2860
 *
ec403cf308eb Updated Doxygen documentation.
Florian Pose <fp@igh-essen.com>
parents: 2505
diff changeset
  2861
 * \return Zero on success, otherwise a negative error code.
2433
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2862
 */
2481
c99ff159b60d Added function attribute definition.
Florian Pose <fp@igh-essen.com>
parents: 2477
diff changeset
  2863
static ATTRIBUTES int ec_ioctl_sc_idn(
2433
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2864
        ec_master_t *master, /**< EtherCAT master. */
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2865
        void *arg, /**< ioctl() argument. */
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2866
        ec_ioctl_context_t *ctx /**< Private data structure of file handle. */
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2867
        )
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2868
{
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2869
    ec_ioctl_sc_idn_t ioctl;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2870
    ec_slave_config_t *sc;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2871
    uint8_t *data = NULL;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2872
    int ret;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2873
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2874
    if (unlikely(!ctx->requested))
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2875
        return -EPERM;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2876
2719
94c9657e0bee Xenomai 2 to 3 migration says "RTDM drivers implementing differentiated ioctl() support for both domains should serve all real-time only requests from ioctl_rt(), returning -ENOSYS for any unrecognized request, which will cause the adaptive switch to take place automatically to the ioctl_nrt() handler. The ioctl_nrt() should then implement all requests which may be valid from the regular Linux domain exclusively."
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2712
diff changeset
  2877
    if (ec_copy_from_user(&ioctl, (void __user *) arg, sizeof(ioctl)))
2433
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2878
        return -EFAULT;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2879
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2880
    if (!ioctl.size)
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2881
        return -EINVAL;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2882
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2883
    if (!(data = kmalloc(ioctl.size, GFP_KERNEL))) {
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2884
        return -ENOMEM;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2885
    }
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2886
2719
94c9657e0bee Xenomai 2 to 3 migration says "RTDM drivers implementing differentiated ioctl() support for both domains should serve all real-time only requests from ioctl_rt(), returning -ENOSYS for any unrecognized request, which will cause the adaptive switch to take place automatically to the ioctl_nrt() handler. The ioctl_nrt() should then implement all requests which may be valid from the regular Linux domain exclusively."
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2712
diff changeset
  2887
    if (ec_copy_from_user(data, (void __user *) ioctl.data, ioctl.size)) {
2433
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2888
        kfree(data);
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2889
        return -EFAULT;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2890
    }
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2891
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2892
    if (down_interruptible(&master->master_sem)) {
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2893
        kfree(data);
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2894
        return -EINTR;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2895
    }
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2896
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2897
    if (!(sc = ec_master_get_config(master, ioctl.config_index))) {
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2898
        up(&master->master_sem);
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2899
        kfree(data);
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2900
        return -ENOENT;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2901
    }
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2902
2522
ec403cf308eb Updated Doxygen documentation.
Florian Pose <fp@igh-essen.com>
parents: 2505
diff changeset
  2903
    up(&master->master_sem); /** \todo sc could be invalidated */
2433
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2904
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2905
    ret = ecrt_slave_config_idn(
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2906
            sc, ioctl.drive_no, ioctl.idn, ioctl.al_state, data, ioctl.size);
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2907
    kfree(data);
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2908
    return ret;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2909
}
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2910
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2911
/*****************************************************************************/
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2912
2504
5ef9d5b14879 Exported ecrt_domain_size() for userspace.
Florian Pose <fp@igh-essen.com>
parents: 2498
diff changeset
  2913
/** Gets the domain's data size.
2522
ec403cf308eb Updated Doxygen documentation.
Florian Pose <fp@igh-essen.com>
parents: 2505
diff changeset
  2914
 *
ec403cf308eb Updated Doxygen documentation.
Florian Pose <fp@igh-essen.com>
parents: 2505
diff changeset
  2915
 * \return Domain size, or a negative error code.
2504
5ef9d5b14879 Exported ecrt_domain_size() for userspace.
Florian Pose <fp@igh-essen.com>
parents: 2498
diff changeset
  2916
 */
5ef9d5b14879 Exported ecrt_domain_size() for userspace.
Florian Pose <fp@igh-essen.com>
parents: 2498
diff changeset
  2917
static ATTRIBUTES int ec_ioctl_domain_size(
5ef9d5b14879 Exported ecrt_domain_size() for userspace.
Florian Pose <fp@igh-essen.com>
parents: 2498
diff changeset
  2918
        ec_master_t *master, /**< EtherCAT master. */
5ef9d5b14879 Exported ecrt_domain_size() for userspace.
Florian Pose <fp@igh-essen.com>
parents: 2498
diff changeset
  2919
        void *arg, /**< ioctl() argument. */
5ef9d5b14879 Exported ecrt_domain_size() for userspace.
Florian Pose <fp@igh-essen.com>
parents: 2498
diff changeset
  2920
        ec_ioctl_context_t *ctx /**< Private data structure of file handle. */
5ef9d5b14879 Exported ecrt_domain_size() for userspace.
Florian Pose <fp@igh-essen.com>
parents: 2498
diff changeset
  2921
        )
5ef9d5b14879 Exported ecrt_domain_size() for userspace.
Florian Pose <fp@igh-essen.com>
parents: 2498
diff changeset
  2922
{
5ef9d5b14879 Exported ecrt_domain_size() for userspace.
Florian Pose <fp@igh-essen.com>
parents: 2498
diff changeset
  2923
    const ec_domain_t *domain;
5ef9d5b14879 Exported ecrt_domain_size() for userspace.
Florian Pose <fp@igh-essen.com>
parents: 2498
diff changeset
  2924
5ef9d5b14879 Exported ecrt_domain_size() for userspace.
Florian Pose <fp@igh-essen.com>
parents: 2498
diff changeset
  2925
    if (unlikely(!ctx->requested)) {
5ef9d5b14879 Exported ecrt_domain_size() for userspace.
Florian Pose <fp@igh-essen.com>
parents: 2498
diff changeset
  2926
        return -EPERM;
5ef9d5b14879 Exported ecrt_domain_size() for userspace.
Florian Pose <fp@igh-essen.com>
parents: 2498
diff changeset
  2927
    }
5ef9d5b14879 Exported ecrt_domain_size() for userspace.
Florian Pose <fp@igh-essen.com>
parents: 2498
diff changeset
  2928
5ef9d5b14879 Exported ecrt_domain_size() for userspace.
Florian Pose <fp@igh-essen.com>
parents: 2498
diff changeset
  2929
    if (down_interruptible(&master->master_sem)) {
5ef9d5b14879 Exported ecrt_domain_size() for userspace.
Florian Pose <fp@igh-essen.com>
parents: 2498
diff changeset
  2930
        return -EINTR;
5ef9d5b14879 Exported ecrt_domain_size() for userspace.
Florian Pose <fp@igh-essen.com>
parents: 2498
diff changeset
  2931
    }
5ef9d5b14879 Exported ecrt_domain_size() for userspace.
Florian Pose <fp@igh-essen.com>
parents: 2498
diff changeset
  2932
5ef9d5b14879 Exported ecrt_domain_size() for userspace.
Florian Pose <fp@igh-essen.com>
parents: 2498
diff changeset
  2933
    list_for_each_entry(domain, &master->domains, list) {
5ef9d5b14879 Exported ecrt_domain_size() for userspace.
Florian Pose <fp@igh-essen.com>
parents: 2498
diff changeset
  2934
        if (domain->index == (unsigned long) arg) {
5ef9d5b14879 Exported ecrt_domain_size() for userspace.
Florian Pose <fp@igh-essen.com>
parents: 2498
diff changeset
  2935
            size_t size = ecrt_domain_size(domain);
5ef9d5b14879 Exported ecrt_domain_size() for userspace.
Florian Pose <fp@igh-essen.com>
parents: 2498
diff changeset
  2936
            up(&master->master_sem);
5ef9d5b14879 Exported ecrt_domain_size() for userspace.
Florian Pose <fp@igh-essen.com>
parents: 2498
diff changeset
  2937
            return size;
5ef9d5b14879 Exported ecrt_domain_size() for userspace.
Florian Pose <fp@igh-essen.com>
parents: 2498
diff changeset
  2938
        }
5ef9d5b14879 Exported ecrt_domain_size() for userspace.
Florian Pose <fp@igh-essen.com>
parents: 2498
diff changeset
  2939
    }
5ef9d5b14879 Exported ecrt_domain_size() for userspace.
Florian Pose <fp@igh-essen.com>
parents: 2498
diff changeset
  2940
5ef9d5b14879 Exported ecrt_domain_size() for userspace.
Florian Pose <fp@igh-essen.com>
parents: 2498
diff changeset
  2941
    up(&master->master_sem);
5ef9d5b14879 Exported ecrt_domain_size() for userspace.
Florian Pose <fp@igh-essen.com>
parents: 2498
diff changeset
  2942
    return -ENOENT;
5ef9d5b14879 Exported ecrt_domain_size() for userspace.
Florian Pose <fp@igh-essen.com>
parents: 2498
diff changeset
  2943
}
5ef9d5b14879 Exported ecrt_domain_size() for userspace.
Florian Pose <fp@igh-essen.com>
parents: 2498
diff changeset
  2944
5ef9d5b14879 Exported ecrt_domain_size() for userspace.
Florian Pose <fp@igh-essen.com>
parents: 2498
diff changeset
  2945
/*****************************************************************************/
5ef9d5b14879 Exported ecrt_domain_size() for userspace.
Florian Pose <fp@igh-essen.com>
parents: 2498
diff changeset
  2946
2433
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2947
/** Gets the domain's offset in the total process data.
2522
ec403cf308eb Updated Doxygen documentation.
Florian Pose <fp@igh-essen.com>
parents: 2505
diff changeset
  2948
 *
ec403cf308eb Updated Doxygen documentation.
Florian Pose <fp@igh-essen.com>
parents: 2505
diff changeset
  2949
 * \return Domain offset, or a negative error code.
2433
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2950
 */
2481
c99ff159b60d Added function attribute definition.
Florian Pose <fp@igh-essen.com>
parents: 2477
diff changeset
  2951
static ATTRIBUTES int ec_ioctl_domain_offset(
2433
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2952
        ec_master_t *master, /**< EtherCAT master. */
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2953
        void *arg, /**< ioctl() argument. */
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2954
        ec_ioctl_context_t *ctx /**< Private data structure of file handle. */
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2955
        )
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2956
{
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2957
    int offset = 0;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2958
    const ec_domain_t *domain;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2959
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2960
    if (unlikely(!ctx->requested))
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2961
        return -EPERM;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2962
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2963
    if (down_interruptible(&master->master_sem)) {
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2964
        return -EINTR;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2965
    }
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2966
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2967
    list_for_each_entry(domain, &master->domains, list) {
2487
ccafdf1e261f Fixed some warnings on 64 bit systems.
Florian Pose <fp@igh-essen.com>
parents: 2486
diff changeset
  2968
        if (domain->index == (unsigned long) arg) {
2433
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2969
            up(&master->master_sem);
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2970
            return offset;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2971
        }
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2972
        offset += ecrt_domain_size(domain);
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2973
    }
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2974
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2975
    up(&master->master_sem);
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2976
    return -ENOENT;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2977
}
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2978
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2979
/*****************************************************************************/
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2980
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2981
/** Process the domain.
2522
ec403cf308eb Updated Doxygen documentation.
Florian Pose <fp@igh-essen.com>
parents: 2505
diff changeset
  2982
 *
ec403cf308eb Updated Doxygen documentation.
Florian Pose <fp@igh-essen.com>
parents: 2505
diff changeset
  2983
 * \return Zero on success, otherwise a negative error code.
2433
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2984
 */
2481
c99ff159b60d Added function attribute definition.
Florian Pose <fp@igh-essen.com>
parents: 2477
diff changeset
  2985
static ATTRIBUTES int ec_ioctl_domain_process(
2433
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2986
        ec_master_t *master, /**< EtherCAT master. */
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2987
        void *arg, /**< ioctl() argument. */
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2988
        ec_ioctl_context_t *ctx /**< Private data structure of file handle. */
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2989
        )
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2990
{
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2991
    ec_domain_t *domain;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2992
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2993
    if (unlikely(!ctx->requested))
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2994
        return -EPERM;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2995
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2996
    /* no locking of master_sem needed, because domain will not be deleted in
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2997
     * the meantime. */
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2998
2487
ccafdf1e261f Fixed some warnings on 64 bit systems.
Florian Pose <fp@igh-essen.com>
parents: 2486
diff changeset
  2999
    if (!(domain = ec_master_find_domain(master, (unsigned long) arg))) {
2433
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3000
        return -ENOENT;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3001
    }
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3002
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3003
    ecrt_domain_process(domain);
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3004
    return 0;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3005
}
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3006
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3007
/*****************************************************************************/
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3008
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3009
/** Queue the domain.
2522
ec403cf308eb Updated Doxygen documentation.
Florian Pose <fp@igh-essen.com>
parents: 2505
diff changeset
  3010
 *
ec403cf308eb Updated Doxygen documentation.
Florian Pose <fp@igh-essen.com>
parents: 2505
diff changeset
  3011
 * \return Zero on success, otherwise a negative error code.
2433
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3012
 */
2481
c99ff159b60d Added function attribute definition.
Florian Pose <fp@igh-essen.com>
parents: 2477
diff changeset
  3013
static ATTRIBUTES int ec_ioctl_domain_queue(
2433
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3014
        ec_master_t *master, /**< EtherCAT master. */
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3015
        void *arg, /**< ioctl() argument. */
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3016
        ec_ioctl_context_t *ctx /**< Private data structure of file handle. */
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3017
        )
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3018
{
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3019
    ec_domain_t *domain;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3020
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3021
    if (unlikely(!ctx->requested))
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3022
        return -EPERM;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3023
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3024
    /* no locking of master_sem needed, because domain will not be deleted in
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3025
     * the meantime. */
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3026
2487
ccafdf1e261f Fixed some warnings on 64 bit systems.
Florian Pose <fp@igh-essen.com>
parents: 2486
diff changeset
  3027
    if (!(domain = ec_master_find_domain(master, (unsigned long) arg))) {
2433
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3028
        return -ENOENT;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3029
    }
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3030
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3031
    ecrt_domain_queue(domain);
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3032
    return 0;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3033
}
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3034
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3035
/*****************************************************************************/
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3036
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3037
/** Get the domain state.
2522
ec403cf308eb Updated Doxygen documentation.
Florian Pose <fp@igh-essen.com>
parents: 2505
diff changeset
  3038
 *
ec403cf308eb Updated Doxygen documentation.
Florian Pose <fp@igh-essen.com>
parents: 2505
diff changeset
  3039
 * \return Zero on success, otherwise a negative error code.
2433
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3040
 */
2481
c99ff159b60d Added function attribute definition.
Florian Pose <fp@igh-essen.com>
parents: 2477
diff changeset
  3041
static ATTRIBUTES int ec_ioctl_domain_state(
2433
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3042
        ec_master_t *master, /**< EtherCAT master. */
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3043
        void *arg, /**< ioctl() argument. */
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3044
        ec_ioctl_context_t *ctx /**< Private data structure of file handle. */
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3045
        )
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3046
{
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3047
    ec_ioctl_domain_state_t data;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3048
    const ec_domain_t *domain;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3049
    ec_domain_state_t state;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3050
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3051
    if (unlikely(!ctx->requested))
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3052
        return -EPERM;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3053
2719
94c9657e0bee Xenomai 2 to 3 migration says "RTDM drivers implementing differentiated ioctl() support for both domains should serve all real-time only requests from ioctl_rt(), returning -ENOSYS for any unrecognized request, which will cause the adaptive switch to take place automatically to the ioctl_nrt() handler. The ioctl_nrt() should then implement all requests which may be valid from the regular Linux domain exclusively."
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2712
diff changeset
  3054
    if (ec_copy_from_user(&data, (void __user *) arg, sizeof(data))) {
2433
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3055
        return -EFAULT;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3056
    }
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3057
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3058
    /* no locking of master_sem needed, because domain will not be deleted in
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3059
     * the meantime. */
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3060
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3061
    if (!(domain = ec_master_find_domain_const(master, data.domain_index))) {
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3062
        return -ENOENT;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3063
    }
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3064
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3065
    ecrt_domain_state(domain, &state);
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3066
2719
94c9657e0bee Xenomai 2 to 3 migration says "RTDM drivers implementing differentiated ioctl() support for both domains should serve all real-time only requests from ioctl_rt(), returning -ENOSYS for any unrecognized request, which will cause the adaptive switch to take place automatically to the ioctl_nrt() handler. The ioctl_nrt() should then implement all requests which may be valid from the regular Linux domain exclusively."
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2712
diff changeset
  3067
    if (ec_copy_to_user((void __user *) data.state, &state, sizeof(state)))
2433
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3068
        return -EFAULT;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3069
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3070
    return 0;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3071
}
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3072
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3073
/*****************************************************************************/
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3074
2434
fa52128477f6 Added ecrt_sdo_request_index() method to change index and subindex.
Florian Pose <fp@igh-essen.com>
parents: 2433
diff changeset
  3075
/** Sets an SDO request's SDO index and subindex.
2522
ec403cf308eb Updated Doxygen documentation.
Florian Pose <fp@igh-essen.com>
parents: 2505
diff changeset
  3076
 *
ec403cf308eb Updated Doxygen documentation.
Florian Pose <fp@igh-essen.com>
parents: 2505
diff changeset
  3077
 * \return Zero on success, otherwise a negative error code.
2434
fa52128477f6 Added ecrt_sdo_request_index() method to change index and subindex.
Florian Pose <fp@igh-essen.com>
parents: 2433
diff changeset
  3078
 */
2481
c99ff159b60d Added function attribute definition.
Florian Pose <fp@igh-essen.com>
parents: 2477
diff changeset
  3079
static ATTRIBUTES int ec_ioctl_sdo_request_index(
2434
fa52128477f6 Added ecrt_sdo_request_index() method to change index and subindex.
Florian Pose <fp@igh-essen.com>
parents: 2433
diff changeset
  3080
        ec_master_t *master, /**< EtherCAT master. */
fa52128477f6 Added ecrt_sdo_request_index() method to change index and subindex.
Florian Pose <fp@igh-essen.com>
parents: 2433
diff changeset
  3081
        void *arg, /**< ioctl() argument. */
fa52128477f6 Added ecrt_sdo_request_index() method to change index and subindex.
Florian Pose <fp@igh-essen.com>
parents: 2433
diff changeset
  3082
        ec_ioctl_context_t *ctx /**< Private data structure of file handle. */
fa52128477f6 Added ecrt_sdo_request_index() method to change index and subindex.
Florian Pose <fp@igh-essen.com>
parents: 2433
diff changeset
  3083
        )
fa52128477f6 Added ecrt_sdo_request_index() method to change index and subindex.
Florian Pose <fp@igh-essen.com>
parents: 2433
diff changeset
  3084
{
fa52128477f6 Added ecrt_sdo_request_index() method to change index and subindex.
Florian Pose <fp@igh-essen.com>
parents: 2433
diff changeset
  3085
    ec_ioctl_sdo_request_t data;
fa52128477f6 Added ecrt_sdo_request_index() method to change index and subindex.
Florian Pose <fp@igh-essen.com>
parents: 2433
diff changeset
  3086
    ec_slave_config_t *sc;
fa52128477f6 Added ecrt_sdo_request_index() method to change index and subindex.
Florian Pose <fp@igh-essen.com>
parents: 2433
diff changeset
  3087
    ec_sdo_request_t *req;
fa52128477f6 Added ecrt_sdo_request_index() method to change index and subindex.
Florian Pose <fp@igh-essen.com>
parents: 2433
diff changeset
  3088
fa52128477f6 Added ecrt_sdo_request_index() method to change index and subindex.
Florian Pose <fp@igh-essen.com>
parents: 2433
diff changeset
  3089
    if (unlikely(!ctx->requested))
fa52128477f6 Added ecrt_sdo_request_index() method to change index and subindex.
Florian Pose <fp@igh-essen.com>
parents: 2433
diff changeset
  3090
        return -EPERM;
fa52128477f6 Added ecrt_sdo_request_index() method to change index and subindex.
Florian Pose <fp@igh-essen.com>
parents: 2433
diff changeset
  3091
2719
94c9657e0bee Xenomai 2 to 3 migration says "RTDM drivers implementing differentiated ioctl() support for both domains should serve all real-time only requests from ioctl_rt(), returning -ENOSYS for any unrecognized request, which will cause the adaptive switch to take place automatically to the ioctl_nrt() handler. The ioctl_nrt() should then implement all requests which may be valid from the regular Linux domain exclusively."
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2712
diff changeset
  3092
    if (ec_copy_from_user(&data, (void __user *) arg, sizeof(data)))
2434
fa52128477f6 Added ecrt_sdo_request_index() method to change index and subindex.
Florian Pose <fp@igh-essen.com>
parents: 2433
diff changeset
  3093
        return -EFAULT;
fa52128477f6 Added ecrt_sdo_request_index() method to change index and subindex.
Florian Pose <fp@igh-essen.com>
parents: 2433
diff changeset
  3094
fa52128477f6 Added ecrt_sdo_request_index() method to change index and subindex.
Florian Pose <fp@igh-essen.com>
parents: 2433
diff changeset
  3095
    /* no locking of master_sem needed, because neither sc nor req will not be
fa52128477f6 Added ecrt_sdo_request_index() method to change index and subindex.
Florian Pose <fp@igh-essen.com>
parents: 2433
diff changeset
  3096
     * deleted in the meantime. */
fa52128477f6 Added ecrt_sdo_request_index() method to change index and subindex.
Florian Pose <fp@igh-essen.com>
parents: 2433
diff changeset
  3097
fa52128477f6 Added ecrt_sdo_request_index() method to change index and subindex.
Florian Pose <fp@igh-essen.com>
parents: 2433
diff changeset
  3098
    if (!(sc = ec_master_get_config(master, data.config_index))) {
fa52128477f6 Added ecrt_sdo_request_index() method to change index and subindex.
Florian Pose <fp@igh-essen.com>
parents: 2433
diff changeset
  3099
        return -ENOENT;
fa52128477f6 Added ecrt_sdo_request_index() method to change index and subindex.
Florian Pose <fp@igh-essen.com>
parents: 2433
diff changeset
  3100
    }
fa52128477f6 Added ecrt_sdo_request_index() method to change index and subindex.
Florian Pose <fp@igh-essen.com>
parents: 2433
diff changeset
  3101
fa52128477f6 Added ecrt_sdo_request_index() method to change index and subindex.
Florian Pose <fp@igh-essen.com>
parents: 2433
diff changeset
  3102
    if (!(req = ec_slave_config_find_sdo_request(sc, data.request_index))) {
fa52128477f6 Added ecrt_sdo_request_index() method to change index and subindex.
Florian Pose <fp@igh-essen.com>
parents: 2433
diff changeset
  3103
        return -ENOENT;
fa52128477f6 Added ecrt_sdo_request_index() method to change index and subindex.
Florian Pose <fp@igh-essen.com>
parents: 2433
diff changeset
  3104
    }
fa52128477f6 Added ecrt_sdo_request_index() method to change index and subindex.
Florian Pose <fp@igh-essen.com>
parents: 2433
diff changeset
  3105
fa52128477f6 Added ecrt_sdo_request_index() method to change index and subindex.
Florian Pose <fp@igh-essen.com>
parents: 2433
diff changeset
  3106
    ecrt_sdo_request_index(req, data.sdo_index, data.sdo_subindex);
fa52128477f6 Added ecrt_sdo_request_index() method to change index and subindex.
Florian Pose <fp@igh-essen.com>
parents: 2433
diff changeset
  3107
    return 0;
fa52128477f6 Added ecrt_sdo_request_index() method to change index and subindex.
Florian Pose <fp@igh-essen.com>
parents: 2433
diff changeset
  3108
}
fa52128477f6 Added ecrt_sdo_request_index() method to change index and subindex.
Florian Pose <fp@igh-essen.com>
parents: 2433
diff changeset
  3109
fa52128477f6 Added ecrt_sdo_request_index() method to change index and subindex.
Florian Pose <fp@igh-essen.com>
parents: 2433
diff changeset
  3110
/*****************************************************************************/
fa52128477f6 Added ecrt_sdo_request_index() method to change index and subindex.
Florian Pose <fp@igh-essen.com>
parents: 2433
diff changeset
  3111
2433
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3112
/** Sets an SDO request's timeout.
2522
ec403cf308eb Updated Doxygen documentation.
Florian Pose <fp@igh-essen.com>
parents: 2505
diff changeset
  3113
 *
ec403cf308eb Updated Doxygen documentation.
Florian Pose <fp@igh-essen.com>
parents: 2505
diff changeset
  3114
 * \return Zero on success, otherwise a negative error code.
2433
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3115
 */
2481
c99ff159b60d Added function attribute definition.
Florian Pose <fp@igh-essen.com>
parents: 2477
diff changeset
  3116
static ATTRIBUTES int ec_ioctl_sdo_request_timeout(
2433
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3117
        ec_master_t *master, /**< EtherCAT master. */
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3118
        void *arg, /**< ioctl() argument. */
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3119
        ec_ioctl_context_t *ctx /**< Private data structure of file handle. */
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3120
        )
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3121
{
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3122
    ec_ioctl_sdo_request_t data;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3123
    ec_slave_config_t *sc;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3124
    ec_sdo_request_t *req;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3125
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3126
    if (unlikely(!ctx->requested))
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3127
        return -EPERM;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3128
2719
94c9657e0bee Xenomai 2 to 3 migration says "RTDM drivers implementing differentiated ioctl() support for both domains should serve all real-time only requests from ioctl_rt(), returning -ENOSYS for any unrecognized request, which will cause the adaptive switch to take place automatically to the ioctl_nrt() handler. The ioctl_nrt() should then implement all requests which may be valid from the regular Linux domain exclusively."
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2712
diff changeset
  3129
    if (ec_copy_from_user(&data, (void __user *) arg, sizeof(data)))
2433
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3130
        return -EFAULT;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3131
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3132
    /* no locking of master_sem needed, because neither sc nor req will not be
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3133
     * deleted in the meantime. */
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3134
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3135
    if (!(sc = ec_master_get_config(master, data.config_index))) {
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3136
        return -ENOENT;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3137
    }
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3138
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3139
    if (!(req = ec_slave_config_find_sdo_request(sc, data.request_index))) {
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3140
        return -ENOENT;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3141
    }
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3142
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3143
    ecrt_sdo_request_timeout(req, data.timeout);
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3144
    return 0;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3145
}
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3146
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3147
/*****************************************************************************/
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3148
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3149
/** Gets an SDO request's state.
2522
ec403cf308eb Updated Doxygen documentation.
Florian Pose <fp@igh-essen.com>
parents: 2505
diff changeset
  3150
 *
ec403cf308eb Updated Doxygen documentation.
Florian Pose <fp@igh-essen.com>
parents: 2505
diff changeset
  3151
 * \return Zero on success, otherwise a negative error code.
2433
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3152
 */
2481
c99ff159b60d Added function attribute definition.
Florian Pose <fp@igh-essen.com>
parents: 2477
diff changeset
  3153
static ATTRIBUTES int ec_ioctl_sdo_request_state(
2433
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3154
        ec_master_t *master, /**< EtherCAT master. */
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3155
        void *arg, /**< ioctl() argument. */
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3156
        ec_ioctl_context_t *ctx /**< Private data structure of file handle. */
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3157
        )
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3158
{
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3159
    ec_ioctl_sdo_request_t data;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3160
    ec_slave_config_t *sc;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3161
    ec_sdo_request_t *req;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3162
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3163
    if (unlikely(!ctx->requested))
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3164
        return -EPERM;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3165
2719
94c9657e0bee Xenomai 2 to 3 migration says "RTDM drivers implementing differentiated ioctl() support for both domains should serve all real-time only requests from ioctl_rt(), returning -ENOSYS for any unrecognized request, which will cause the adaptive switch to take place automatically to the ioctl_nrt() handler. The ioctl_nrt() should then implement all requests which may be valid from the regular Linux domain exclusively."
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2712
diff changeset
  3166
    if (ec_copy_from_user(&data, (void __user *) arg, sizeof(data)))
2433
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3167
        return -EFAULT;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3168
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3169
    /* no locking of master_sem needed, because neither sc nor req will not be
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3170
     * deleted in the meantime. */
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3171
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3172
    if (!(sc = ec_master_get_config(master, data.config_index))) {
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3173
        return -ENOENT;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3174
    }
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3175
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3176
    if (!(req = ec_slave_config_find_sdo_request(sc, data.request_index))) {
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3177
        return -ENOENT;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3178
    }
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3179
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3180
    data.state = ecrt_sdo_request_state(req);
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3181
    if (data.state == EC_REQUEST_SUCCESS && req->dir == EC_DIR_INPUT)
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3182
        data.size = ecrt_sdo_request_data_size(req);
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3183
    else
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3184
        data.size = 0;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3185
2719
94c9657e0bee Xenomai 2 to 3 migration says "RTDM drivers implementing differentiated ioctl() support for both domains should serve all real-time only requests from ioctl_rt(), returning -ENOSYS for any unrecognized request, which will cause the adaptive switch to take place automatically to the ioctl_nrt() handler. The ioctl_nrt() should then implement all requests which may be valid from the regular Linux domain exclusively."
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2712
diff changeset
  3186
    if (ec_copy_to_user((void __user *) arg, &data, sizeof(data)))
2433
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3187
        return -EFAULT;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3188
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3189
    return 0;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3190
}
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3191
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3192
/*****************************************************************************/
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3193
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3194
/** Starts an SDO read operation.
2522
ec403cf308eb Updated Doxygen documentation.
Florian Pose <fp@igh-essen.com>
parents: 2505
diff changeset
  3195
 *
ec403cf308eb Updated Doxygen documentation.
Florian Pose <fp@igh-essen.com>
parents: 2505
diff changeset
  3196
 * \return Zero on success, otherwise a negative error code.
2433
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3197
 */
2481
c99ff159b60d Added function attribute definition.
Florian Pose <fp@igh-essen.com>
parents: 2477
diff changeset
  3198
static ATTRIBUTES int ec_ioctl_sdo_request_read(
2433
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3199
        ec_master_t *master, /**< EtherCAT master. */
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3200
        void *arg, /**< ioctl() argument. */
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3201
        ec_ioctl_context_t *ctx /**< Private data structure of file handle. */
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3202
        )
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3203
{
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3204
    ec_ioctl_sdo_request_t data;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3205
    ec_slave_config_t *sc;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3206
    ec_sdo_request_t *req;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3207
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3208
    if (unlikely(!ctx->requested))
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3209
        return -EPERM;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3210
2719
94c9657e0bee Xenomai 2 to 3 migration says "RTDM drivers implementing differentiated ioctl() support for both domains should serve all real-time only requests from ioctl_rt(), returning -ENOSYS for any unrecognized request, which will cause the adaptive switch to take place automatically to the ioctl_nrt() handler. The ioctl_nrt() should then implement all requests which may be valid from the regular Linux domain exclusively."
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2712
diff changeset
  3211
    if (ec_copy_from_user(&data, (void __user *) arg, sizeof(data)))
2433
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3212
        return -EFAULT;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3213
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3214
    /* no locking of master_sem needed, because neither sc nor req will not be
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3215
     * deleted in the meantime. */
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3216
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3217
    if (!(sc = ec_master_get_config(master, data.config_index))) {
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3218
        return -ENOENT;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3219
    }
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3220
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3221
    if (!(req = ec_slave_config_find_sdo_request(sc, data.request_index))) {
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3222
        return -ENOENT;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3223
    }
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3224
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3225
    ecrt_sdo_request_read(req);
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3226
    return 0;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3227
}
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3228
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3229
/*****************************************************************************/
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3230
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3231
/** Starts an SDO write operation.
2522
ec403cf308eb Updated Doxygen documentation.
Florian Pose <fp@igh-essen.com>
parents: 2505
diff changeset
  3232
 *
ec403cf308eb Updated Doxygen documentation.
Florian Pose <fp@igh-essen.com>
parents: 2505
diff changeset
  3233
 * \return Zero on success, otherwise a negative error code.
2433
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3234
 */
2481
c99ff159b60d Added function attribute definition.
Florian Pose <fp@igh-essen.com>
parents: 2477
diff changeset
  3235
static ATTRIBUTES int ec_ioctl_sdo_request_write(
2433
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3236
        ec_master_t *master, /**< EtherCAT master. */
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3237
        void *arg, /**< ioctl() argument. */
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3238
        ec_ioctl_context_t *ctx /**< Private data structure of file handle. */
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3239
        )
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3240
{
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3241
    ec_ioctl_sdo_request_t data;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3242
    ec_slave_config_t *sc;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3243
    ec_sdo_request_t *req;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3244
    int ret;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3245
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3246
    if (unlikely(!ctx->requested))
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3247
        return -EPERM;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3248
2719
94c9657e0bee Xenomai 2 to 3 migration says "RTDM drivers implementing differentiated ioctl() support for both domains should serve all real-time only requests from ioctl_rt(), returning -ENOSYS for any unrecognized request, which will cause the adaptive switch to take place automatically to the ioctl_nrt() handler. The ioctl_nrt() should then implement all requests which may be valid from the regular Linux domain exclusively."
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2712
diff changeset
  3249
    if (ec_copy_from_user(&data, (void __user *) arg, sizeof(data)))
2433
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3250
        return -EFAULT;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3251
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3252
    if (!data.size) {
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3253
        EC_MASTER_ERR(master, "SDO download: Data size may not be zero!\n");
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3254
        return -EINVAL;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3255
    }
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3256
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3257
    /* no locking of master_sem needed, because neither sc nor req will not be
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3258
     * deleted in the meantime. */
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3259
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3260
    if (!(sc = ec_master_get_config(master, data.config_index))) {
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3261
        return -ENOENT;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3262
    }
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3263
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3264
    if (!(req = ec_slave_config_find_sdo_request(sc, data.request_index))) {
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3265
        return -ENOENT;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3266
    }
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3267
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3268
    ret = ec_sdo_request_alloc(req, data.size);
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3269
    if (ret)
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3270
        return ret;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3271
2719
94c9657e0bee Xenomai 2 to 3 migration says "RTDM drivers implementing differentiated ioctl() support for both domains should serve all real-time only requests from ioctl_rt(), returning -ENOSYS for any unrecognized request, which will cause the adaptive switch to take place automatically to the ioctl_nrt() handler. The ioctl_nrt() should then implement all requests which may be valid from the regular Linux domain exclusively."
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2712
diff changeset
  3272
    if (ec_copy_from_user(req->data, (void __user *) data.data, data.size))
2433
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3273
        return -EFAULT;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3274
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3275
    req->data_size = data.size;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3276
    ecrt_sdo_request_write(req);
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3277
    return 0;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3278
}
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3279
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3280
/*****************************************************************************/
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3281
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3282
/** Read SDO data.
2522
ec403cf308eb Updated Doxygen documentation.
Florian Pose <fp@igh-essen.com>
parents: 2505
diff changeset
  3283
 *
ec403cf308eb Updated Doxygen documentation.
Florian Pose <fp@igh-essen.com>
parents: 2505
diff changeset
  3284
 * \return Zero on success, otherwise a negative error code.
2433
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3285
 */
2481
c99ff159b60d Added function attribute definition.
Florian Pose <fp@igh-essen.com>
parents: 2477
diff changeset
  3286
static ATTRIBUTES int ec_ioctl_sdo_request_data(
2433
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3287
        ec_master_t *master, /**< EtherCAT master. */
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3288
        void *arg, /**< ioctl() argument. */
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3289
        ec_ioctl_context_t *ctx /**< Private data structure of file handle. */
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3290
        )
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3291
{
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3292
    ec_ioctl_sdo_request_t data;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3293
    ec_slave_config_t *sc;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3294
    ec_sdo_request_t *req;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3295
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3296
    if (unlikely(!ctx->requested))
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3297
        return -EPERM;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3298
2719
94c9657e0bee Xenomai 2 to 3 migration says "RTDM drivers implementing differentiated ioctl() support for both domains should serve all real-time only requests from ioctl_rt(), returning -ENOSYS for any unrecognized request, which will cause the adaptive switch to take place automatically to the ioctl_nrt() handler. The ioctl_nrt() should then implement all requests which may be valid from the regular Linux domain exclusively."
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2712
diff changeset
  3299
    if (ec_copy_from_user(&data, (void __user *) arg, sizeof(data)))
2433
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3300
        return -EFAULT;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3301
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3302
    /* no locking of master_sem needed, because neither sc nor req will not be
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3303
     * deleted in the meantime. */
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3304
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3305
    if (!(sc = ec_master_get_config(master, data.config_index))) {
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3306
        return -ENOENT;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3307
    }
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3308
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3309
    if (!(req = ec_slave_config_find_sdo_request(sc, data.request_index))) {
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3310
        return -ENOENT;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3311
    }
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3312
2719
94c9657e0bee Xenomai 2 to 3 migration says "RTDM drivers implementing differentiated ioctl() support for both domains should serve all real-time only requests from ioctl_rt(), returning -ENOSYS for any unrecognized request, which will cause the adaptive switch to take place automatically to the ioctl_nrt() handler. The ioctl_nrt() should then implement all requests which may be valid from the regular Linux domain exclusively."
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2712
diff changeset
  3313
    if (ec_copy_to_user((void __user *) data.data, ecrt_sdo_request_data(req),
2433
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3314
                ecrt_sdo_request_data_size(req)))
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3315
        return -EFAULT;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3316
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3317
    return 0;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3318
}
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3319
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3320
/*****************************************************************************/
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3321
2443
2c3ccdde3919 Added interface to read/write register contents; re-worked register requests.
Florian Pose <fp@igh-essen.com>
parents: 2438
diff changeset
  3322
/** Read register data.
2522
ec403cf308eb Updated Doxygen documentation.
Florian Pose <fp@igh-essen.com>
parents: 2505
diff changeset
  3323
 *
ec403cf308eb Updated Doxygen documentation.
Florian Pose <fp@igh-essen.com>
parents: 2505
diff changeset
  3324
 * \return Zero on success, otherwise a negative error code.
2443
2c3ccdde3919 Added interface to read/write register contents; re-worked register requests.
Florian Pose <fp@igh-essen.com>
parents: 2438
diff changeset
  3325
 */
2481
c99ff159b60d Added function attribute definition.
Florian Pose <fp@igh-essen.com>
parents: 2477
diff changeset
  3326
static ATTRIBUTES int ec_ioctl_reg_request_data(
2443
2c3ccdde3919 Added interface to read/write register contents; re-worked register requests.
Florian Pose <fp@igh-essen.com>
parents: 2438
diff changeset
  3327
        ec_master_t *master, /**< EtherCAT master. */
2c3ccdde3919 Added interface to read/write register contents; re-worked register requests.
Florian Pose <fp@igh-essen.com>
parents: 2438
diff changeset
  3328
        void *arg, /**< ioctl() argument. */
2c3ccdde3919 Added interface to read/write register contents; re-worked register requests.
Florian Pose <fp@igh-essen.com>
parents: 2438
diff changeset
  3329
        ec_ioctl_context_t *ctx /**< Private data structure of file handle. */
2c3ccdde3919 Added interface to read/write register contents; re-worked register requests.
Florian Pose <fp@igh-essen.com>
parents: 2438
diff changeset
  3330
        )
2c3ccdde3919 Added interface to read/write register contents; re-worked register requests.
Florian Pose <fp@igh-essen.com>
parents: 2438
diff changeset
  3331
{
2c3ccdde3919 Added interface to read/write register contents; re-worked register requests.
Florian Pose <fp@igh-essen.com>
parents: 2438
diff changeset
  3332
    ec_ioctl_reg_request_t io;
2c3ccdde3919 Added interface to read/write register contents; re-worked register requests.
Florian Pose <fp@igh-essen.com>
parents: 2438
diff changeset
  3333
    ec_slave_config_t *sc;
2c3ccdde3919 Added interface to read/write register contents; re-worked register requests.
Florian Pose <fp@igh-essen.com>
parents: 2438
diff changeset
  3334
    ec_reg_request_t *reg;
2c3ccdde3919 Added interface to read/write register contents; re-worked register requests.
Florian Pose <fp@igh-essen.com>
parents: 2438
diff changeset
  3335
2c3ccdde3919 Added interface to read/write register contents; re-worked register requests.
Florian Pose <fp@igh-essen.com>
parents: 2438
diff changeset
  3336
    if (unlikely(!ctx->requested)) {
2c3ccdde3919 Added interface to read/write register contents; re-worked register requests.
Florian Pose <fp@igh-essen.com>
parents: 2438
diff changeset
  3337
        return -EPERM;
2c3ccdde3919 Added interface to read/write register contents; re-worked register requests.
Florian Pose <fp@igh-essen.com>
parents: 2438
diff changeset
  3338
    }
2c3ccdde3919 Added interface to read/write register contents; re-worked register requests.
Florian Pose <fp@igh-essen.com>
parents: 2438
diff changeset
  3339
2719
94c9657e0bee Xenomai 2 to 3 migration says "RTDM drivers implementing differentiated ioctl() support for both domains should serve all real-time only requests from ioctl_rt(), returning -ENOSYS for any unrecognized request, which will cause the adaptive switch to take place automatically to the ioctl_nrt() handler. The ioctl_nrt() should then implement all requests which may be valid from the regular Linux domain exclusively."
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2712
diff changeset
  3340
    if (ec_copy_from_user(&io, (void __user *) arg, sizeof(io))) {
2443
2c3ccdde3919 Added interface to read/write register contents; re-worked register requests.
Florian Pose <fp@igh-essen.com>
parents: 2438
diff changeset
  3341
        return -EFAULT;
2c3ccdde3919 Added interface to read/write register contents; re-worked register requests.
Florian Pose <fp@igh-essen.com>
parents: 2438
diff changeset
  3342
    }
2c3ccdde3919 Added interface to read/write register contents; re-worked register requests.
Florian Pose <fp@igh-essen.com>
parents: 2438
diff changeset
  3343
2c3ccdde3919 Added interface to read/write register contents; re-worked register requests.
Florian Pose <fp@igh-essen.com>
parents: 2438
diff changeset
  3344
    if (io.mem_size <= 0) {
2c3ccdde3919 Added interface to read/write register contents; re-worked register requests.
Florian Pose <fp@igh-essen.com>
parents: 2438
diff changeset
  3345
        return 0;
2c3ccdde3919 Added interface to read/write register contents; re-worked register requests.
Florian Pose <fp@igh-essen.com>
parents: 2438
diff changeset
  3346
    }
2c3ccdde3919 Added interface to read/write register contents; re-worked register requests.
Florian Pose <fp@igh-essen.com>
parents: 2438
diff changeset
  3347
2c3ccdde3919 Added interface to read/write register contents; re-worked register requests.
Florian Pose <fp@igh-essen.com>
parents: 2438
diff changeset
  3348
    /* no locking of master_sem needed, because neither sc nor reg will not be
2c3ccdde3919 Added interface to read/write register contents; re-worked register requests.
Florian Pose <fp@igh-essen.com>
parents: 2438
diff changeset
  3349
     * deleted in the meantime. */
2c3ccdde3919 Added interface to read/write register contents; re-worked register requests.
Florian Pose <fp@igh-essen.com>
parents: 2438
diff changeset
  3350
2c3ccdde3919 Added interface to read/write register contents; re-worked register requests.
Florian Pose <fp@igh-essen.com>
parents: 2438
diff changeset
  3351
    if (!(sc = ec_master_get_config(master, io.config_index))) {
2c3ccdde3919 Added interface to read/write register contents; re-worked register requests.
Florian Pose <fp@igh-essen.com>
parents: 2438
diff changeset
  3352
        return -ENOENT;
2c3ccdde3919 Added interface to read/write register contents; re-worked register requests.
Florian Pose <fp@igh-essen.com>
parents: 2438
diff changeset
  3353
    }
2c3ccdde3919 Added interface to read/write register contents; re-worked register requests.
Florian Pose <fp@igh-essen.com>
parents: 2438
diff changeset
  3354
2c3ccdde3919 Added interface to read/write register contents; re-worked register requests.
Florian Pose <fp@igh-essen.com>
parents: 2438
diff changeset
  3355
    if (!(reg = ec_slave_config_find_reg_request(sc, io.request_index))) {
2c3ccdde3919 Added interface to read/write register contents; re-worked register requests.
Florian Pose <fp@igh-essen.com>
parents: 2438
diff changeset
  3356
        return -ENOENT;
2c3ccdde3919 Added interface to read/write register contents; re-worked register requests.
Florian Pose <fp@igh-essen.com>
parents: 2438
diff changeset
  3357
    }
2c3ccdde3919 Added interface to read/write register contents; re-worked register requests.
Florian Pose <fp@igh-essen.com>
parents: 2438
diff changeset
  3358
2719
94c9657e0bee Xenomai 2 to 3 migration says "RTDM drivers implementing differentiated ioctl() support for both domains should serve all real-time only requests from ioctl_rt(), returning -ENOSYS for any unrecognized request, which will cause the adaptive switch to take place automatically to the ioctl_nrt() handler. The ioctl_nrt() should then implement all requests which may be valid from the regular Linux domain exclusively."
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2712
diff changeset
  3359
    if (ec_copy_to_user((void __user *) io.data, ecrt_reg_request_data(reg),
2443
2c3ccdde3919 Added interface to read/write register contents; re-worked register requests.
Florian Pose <fp@igh-essen.com>
parents: 2438
diff changeset
  3360
                min(reg->mem_size, io.mem_size))) {
2c3ccdde3919 Added interface to read/write register contents; re-worked register requests.
Florian Pose <fp@igh-essen.com>
parents: 2438
diff changeset
  3361
        return -EFAULT;
2c3ccdde3919 Added interface to read/write register contents; re-worked register requests.
Florian Pose <fp@igh-essen.com>
parents: 2438
diff changeset
  3362
    }
2c3ccdde3919 Added interface to read/write register contents; re-worked register requests.
Florian Pose <fp@igh-essen.com>
parents: 2438
diff changeset
  3363
2c3ccdde3919 Added interface to read/write register contents; re-worked register requests.
Florian Pose <fp@igh-essen.com>
parents: 2438
diff changeset
  3364
    return 0;
2c3ccdde3919 Added interface to read/write register contents; re-worked register requests.
Florian Pose <fp@igh-essen.com>
parents: 2438
diff changeset
  3365
}
2c3ccdde3919 Added interface to read/write register contents; re-worked register requests.
Florian Pose <fp@igh-essen.com>
parents: 2438
diff changeset
  3366
2c3ccdde3919 Added interface to read/write register contents; re-worked register requests.
Florian Pose <fp@igh-essen.com>
parents: 2438
diff changeset
  3367
/*****************************************************************************/
2c3ccdde3919 Added interface to read/write register contents; re-worked register requests.
Florian Pose <fp@igh-essen.com>
parents: 2438
diff changeset
  3368
2c3ccdde3919 Added interface to read/write register contents; re-worked register requests.
Florian Pose <fp@igh-essen.com>
parents: 2438
diff changeset
  3369
/** Gets an register request's state.
2522
ec403cf308eb Updated Doxygen documentation.
Florian Pose <fp@igh-essen.com>
parents: 2505
diff changeset
  3370
 *
ec403cf308eb Updated Doxygen documentation.
Florian Pose <fp@igh-essen.com>
parents: 2505
diff changeset
  3371
 * \return Zero on success, otherwise a negative error code.
2443
2c3ccdde3919 Added interface to read/write register contents; re-worked register requests.
Florian Pose <fp@igh-essen.com>
parents: 2438
diff changeset
  3372
 */
2481
c99ff159b60d Added function attribute definition.
Florian Pose <fp@igh-essen.com>
parents: 2477
diff changeset
  3373
static ATTRIBUTES int ec_ioctl_reg_request_state(
2443
2c3ccdde3919 Added interface to read/write register contents; re-worked register requests.
Florian Pose <fp@igh-essen.com>
parents: 2438
diff changeset
  3374
        ec_master_t *master, /**< EtherCAT master. */
2c3ccdde3919 Added interface to read/write register contents; re-worked register requests.
Florian Pose <fp@igh-essen.com>
parents: 2438
diff changeset
  3375
        void *arg, /**< ioctl() argument. */
2c3ccdde3919 Added interface to read/write register contents; re-worked register requests.
Florian Pose <fp@igh-essen.com>
parents: 2438
diff changeset
  3376
        ec_ioctl_context_t *ctx /**< Private data structure of file handle. */
2c3ccdde3919 Added interface to read/write register contents; re-worked register requests.
Florian Pose <fp@igh-essen.com>
parents: 2438
diff changeset
  3377
        )
2c3ccdde3919 Added interface to read/write register contents; re-worked register requests.
Florian Pose <fp@igh-essen.com>
parents: 2438
diff changeset
  3378
{
2c3ccdde3919 Added interface to read/write register contents; re-worked register requests.
Florian Pose <fp@igh-essen.com>
parents: 2438
diff changeset
  3379
    ec_ioctl_reg_request_t io;
2c3ccdde3919 Added interface to read/write register contents; re-worked register requests.
Florian Pose <fp@igh-essen.com>
parents: 2438
diff changeset
  3380
    ec_slave_config_t *sc;
2c3ccdde3919 Added interface to read/write register contents; re-worked register requests.
Florian Pose <fp@igh-essen.com>
parents: 2438
diff changeset
  3381
    ec_reg_request_t *reg;
2c3ccdde3919 Added interface to read/write register contents; re-worked register requests.
Florian Pose <fp@igh-essen.com>
parents: 2438
diff changeset
  3382
2c3ccdde3919 Added interface to read/write register contents; re-worked register requests.
Florian Pose <fp@igh-essen.com>
parents: 2438
diff changeset
  3383
    if (unlikely(!ctx->requested)) {
2c3ccdde3919 Added interface to read/write register contents; re-worked register requests.
Florian Pose <fp@igh-essen.com>
parents: 2438
diff changeset
  3384
        return -EPERM;
2c3ccdde3919 Added interface to read/write register contents; re-worked register requests.
Florian Pose <fp@igh-essen.com>
parents: 2438
diff changeset
  3385
    }
2c3ccdde3919 Added interface to read/write register contents; re-worked register requests.
Florian Pose <fp@igh-essen.com>
parents: 2438
diff changeset
  3386
2719
94c9657e0bee Xenomai 2 to 3 migration says "RTDM drivers implementing differentiated ioctl() support for both domains should serve all real-time only requests from ioctl_rt(), returning -ENOSYS for any unrecognized request, which will cause the adaptive switch to take place automatically to the ioctl_nrt() handler. The ioctl_nrt() should then implement all requests which may be valid from the regular Linux domain exclusively."
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2712
diff changeset
  3387
    if (ec_copy_from_user(&io, (void __user *) arg, sizeof(io))) {
2443
2c3ccdde3919 Added interface to read/write register contents; re-worked register requests.
Florian Pose <fp@igh-essen.com>
parents: 2438
diff changeset
  3388
        return -EFAULT;
2c3ccdde3919 Added interface to read/write register contents; re-worked register requests.
Florian Pose <fp@igh-essen.com>
parents: 2438
diff changeset
  3389
    }
2c3ccdde3919 Added interface to read/write register contents; re-worked register requests.
Florian Pose <fp@igh-essen.com>
parents: 2438
diff changeset
  3390
2c3ccdde3919 Added interface to read/write register contents; re-worked register requests.
Florian Pose <fp@igh-essen.com>
parents: 2438
diff changeset
  3391
    /* no locking of master_sem needed, because neither sc nor reg will not be
2c3ccdde3919 Added interface to read/write register contents; re-worked register requests.
Florian Pose <fp@igh-essen.com>
parents: 2438
diff changeset
  3392
     * deleted in the meantime. */
2c3ccdde3919 Added interface to read/write register contents; re-worked register requests.
Florian Pose <fp@igh-essen.com>
parents: 2438
diff changeset
  3393
2c3ccdde3919 Added interface to read/write register contents; re-worked register requests.
Florian Pose <fp@igh-essen.com>
parents: 2438
diff changeset
  3394
    if (!(sc = ec_master_get_config(master, io.config_index))) {
2c3ccdde3919 Added interface to read/write register contents; re-worked register requests.
Florian Pose <fp@igh-essen.com>
parents: 2438
diff changeset
  3395
        return -ENOENT;
2c3ccdde3919 Added interface to read/write register contents; re-worked register requests.
Florian Pose <fp@igh-essen.com>
parents: 2438
diff changeset
  3396
    }
2c3ccdde3919 Added interface to read/write register contents; re-worked register requests.
Florian Pose <fp@igh-essen.com>
parents: 2438
diff changeset
  3397
2c3ccdde3919 Added interface to read/write register contents; re-worked register requests.
Florian Pose <fp@igh-essen.com>
parents: 2438
diff changeset
  3398
    if (!(reg = ec_slave_config_find_reg_request(sc, io.request_index))) {
2c3ccdde3919 Added interface to read/write register contents; re-worked register requests.
Florian Pose <fp@igh-essen.com>
parents: 2438
diff changeset
  3399
        return -ENOENT;
2c3ccdde3919 Added interface to read/write register contents; re-worked register requests.
Florian Pose <fp@igh-essen.com>
parents: 2438
diff changeset
  3400
    }
2c3ccdde3919 Added interface to read/write register contents; re-worked register requests.
Florian Pose <fp@igh-essen.com>
parents: 2438
diff changeset
  3401
2c3ccdde3919 Added interface to read/write register contents; re-worked register requests.
Florian Pose <fp@igh-essen.com>
parents: 2438
diff changeset
  3402
    io.state = ecrt_reg_request_state(reg);
2c3ccdde3919 Added interface to read/write register contents; re-worked register requests.
Florian Pose <fp@igh-essen.com>
parents: 2438
diff changeset
  3403
    io.new_data = io.state == EC_REQUEST_SUCCESS && reg->dir == EC_DIR_INPUT;
2c3ccdde3919 Added interface to read/write register contents; re-worked register requests.
Florian Pose <fp@igh-essen.com>
parents: 2438
diff changeset
  3404
2719
94c9657e0bee Xenomai 2 to 3 migration says "RTDM drivers implementing differentiated ioctl() support for both domains should serve all real-time only requests from ioctl_rt(), returning -ENOSYS for any unrecognized request, which will cause the adaptive switch to take place automatically to the ioctl_nrt() handler. The ioctl_nrt() should then implement all requests which may be valid from the regular Linux domain exclusively."
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2712
diff changeset
  3405
    if (ec_copy_to_user((void __user *) arg, &io, sizeof(io))) {
2443
2c3ccdde3919 Added interface to read/write register contents; re-worked register requests.
Florian Pose <fp@igh-essen.com>
parents: 2438
diff changeset
  3406
        return -EFAULT;
2c3ccdde3919 Added interface to read/write register contents; re-worked register requests.
Florian Pose <fp@igh-essen.com>
parents: 2438
diff changeset
  3407
    }
2c3ccdde3919 Added interface to read/write register contents; re-worked register requests.
Florian Pose <fp@igh-essen.com>
parents: 2438
diff changeset
  3408
2c3ccdde3919 Added interface to read/write register contents; re-worked register requests.
Florian Pose <fp@igh-essen.com>
parents: 2438
diff changeset
  3409
    return 0;
2c3ccdde3919 Added interface to read/write register contents; re-worked register requests.
Florian Pose <fp@igh-essen.com>
parents: 2438
diff changeset
  3410
}
2c3ccdde3919 Added interface to read/write register contents; re-worked register requests.
Florian Pose <fp@igh-essen.com>
parents: 2438
diff changeset
  3411
2c3ccdde3919 Added interface to read/write register contents; re-worked register requests.
Florian Pose <fp@igh-essen.com>
parents: 2438
diff changeset
  3412
/*****************************************************************************/
2c3ccdde3919 Added interface to read/write register contents; re-worked register requests.
Florian Pose <fp@igh-essen.com>
parents: 2438
diff changeset
  3413
2c3ccdde3919 Added interface to read/write register contents; re-worked register requests.
Florian Pose <fp@igh-essen.com>
parents: 2438
diff changeset
  3414
/** Starts an register write operation.
2522
ec403cf308eb Updated Doxygen documentation.
Florian Pose <fp@igh-essen.com>
parents: 2505
diff changeset
  3415
 *
ec403cf308eb Updated Doxygen documentation.
Florian Pose <fp@igh-essen.com>
parents: 2505
diff changeset
  3416
 * \return Zero on success, otherwise a negative error code.
2443
2c3ccdde3919 Added interface to read/write register contents; re-worked register requests.
Florian Pose <fp@igh-essen.com>
parents: 2438
diff changeset
  3417
 */
2481
c99ff159b60d Added function attribute definition.
Florian Pose <fp@igh-essen.com>
parents: 2477
diff changeset
  3418
static ATTRIBUTES int ec_ioctl_reg_request_write(
2443
2c3ccdde3919 Added interface to read/write register contents; re-worked register requests.
Florian Pose <fp@igh-essen.com>
parents: 2438
diff changeset
  3419
        ec_master_t *master, /**< EtherCAT master. */
2c3ccdde3919 Added interface to read/write register contents; re-worked register requests.
Florian Pose <fp@igh-essen.com>
parents: 2438
diff changeset
  3420
        void *arg, /**< ioctl() argument. */
2c3ccdde3919 Added interface to read/write register contents; re-worked register requests.
Florian Pose <fp@igh-essen.com>
parents: 2438
diff changeset
  3421
        ec_ioctl_context_t *ctx /**< Private data structure of file handle. */
2c3ccdde3919 Added interface to read/write register contents; re-worked register requests.
Florian Pose <fp@igh-essen.com>
parents: 2438
diff changeset
  3422
        )
2c3ccdde3919 Added interface to read/write register contents; re-worked register requests.
Florian Pose <fp@igh-essen.com>
parents: 2438
diff changeset
  3423
{
2c3ccdde3919 Added interface to read/write register contents; re-worked register requests.
Florian Pose <fp@igh-essen.com>
parents: 2438
diff changeset
  3424
    ec_ioctl_reg_request_t io;
2c3ccdde3919 Added interface to read/write register contents; re-worked register requests.
Florian Pose <fp@igh-essen.com>
parents: 2438
diff changeset
  3425
    ec_slave_config_t *sc;
2c3ccdde3919 Added interface to read/write register contents; re-worked register requests.
Florian Pose <fp@igh-essen.com>
parents: 2438
diff changeset
  3426
    ec_reg_request_t *reg;
2c3ccdde3919 Added interface to read/write register contents; re-worked register requests.
Florian Pose <fp@igh-essen.com>
parents: 2438
diff changeset
  3427
2c3ccdde3919 Added interface to read/write register contents; re-worked register requests.
Florian Pose <fp@igh-essen.com>
parents: 2438
diff changeset
  3428
    if (unlikely(!ctx->requested)) {
2c3ccdde3919 Added interface to read/write register contents; re-worked register requests.
Florian Pose <fp@igh-essen.com>
parents: 2438
diff changeset
  3429
        return -EPERM;
2c3ccdde3919 Added interface to read/write register contents; re-worked register requests.
Florian Pose <fp@igh-essen.com>
parents: 2438
diff changeset
  3430
    }
2c3ccdde3919 Added interface to read/write register contents; re-worked register requests.
Florian Pose <fp@igh-essen.com>
parents: 2438
diff changeset
  3431
2719
94c9657e0bee Xenomai 2 to 3 migration says "RTDM drivers implementing differentiated ioctl() support for both domains should serve all real-time only requests from ioctl_rt(), returning -ENOSYS for any unrecognized request, which will cause the adaptive switch to take place automatically to the ioctl_nrt() handler. The ioctl_nrt() should then implement all requests which may be valid from the regular Linux domain exclusively."
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2712
diff changeset
  3432
    if (ec_copy_from_user(&io, (void __user *) arg, sizeof(io))) {
2443
2c3ccdde3919 Added interface to read/write register contents; re-worked register requests.
Florian Pose <fp@igh-essen.com>
parents: 2438
diff changeset
  3433
        return -EFAULT;
2c3ccdde3919 Added interface to read/write register contents; re-worked register requests.
Florian Pose <fp@igh-essen.com>
parents: 2438
diff changeset
  3434
    }
2c3ccdde3919 Added interface to read/write register contents; re-worked register requests.
Florian Pose <fp@igh-essen.com>
parents: 2438
diff changeset
  3435
2c3ccdde3919 Added interface to read/write register contents; re-worked register requests.
Florian Pose <fp@igh-essen.com>
parents: 2438
diff changeset
  3436
    /* no locking of master_sem needed, because neither sc nor reg will not be
2c3ccdde3919 Added interface to read/write register contents; re-worked register requests.
Florian Pose <fp@igh-essen.com>
parents: 2438
diff changeset
  3437
     * deleted in the meantime. */
2c3ccdde3919 Added interface to read/write register contents; re-worked register requests.
Florian Pose <fp@igh-essen.com>
parents: 2438
diff changeset
  3438
2c3ccdde3919 Added interface to read/write register contents; re-worked register requests.
Florian Pose <fp@igh-essen.com>
parents: 2438
diff changeset
  3439
    if (!(sc = ec_master_get_config(master, io.config_index))) {
2c3ccdde3919 Added interface to read/write register contents; re-worked register requests.
Florian Pose <fp@igh-essen.com>
parents: 2438
diff changeset
  3440
        return -ENOENT;
2c3ccdde3919 Added interface to read/write register contents; re-worked register requests.
Florian Pose <fp@igh-essen.com>
parents: 2438
diff changeset
  3441
    }
2c3ccdde3919 Added interface to read/write register contents; re-worked register requests.
Florian Pose <fp@igh-essen.com>
parents: 2438
diff changeset
  3442
2c3ccdde3919 Added interface to read/write register contents; re-worked register requests.
Florian Pose <fp@igh-essen.com>
parents: 2438
diff changeset
  3443
    if (!(reg = ec_slave_config_find_reg_request(sc, io.request_index))) {
2c3ccdde3919 Added interface to read/write register contents; re-worked register requests.
Florian Pose <fp@igh-essen.com>
parents: 2438
diff changeset
  3444
        return -ENOENT;
2c3ccdde3919 Added interface to read/write register contents; re-worked register requests.
Florian Pose <fp@igh-essen.com>
parents: 2438
diff changeset
  3445
    }
2c3ccdde3919 Added interface to read/write register contents; re-worked register requests.
Florian Pose <fp@igh-essen.com>
parents: 2438
diff changeset
  3446
2c3ccdde3919 Added interface to read/write register contents; re-worked register requests.
Florian Pose <fp@igh-essen.com>
parents: 2438
diff changeset
  3447
    if (io.transfer_size > reg->mem_size) {
2c3ccdde3919 Added interface to read/write register contents; re-worked register requests.
Florian Pose <fp@igh-essen.com>
parents: 2438
diff changeset
  3448
        return -EOVERFLOW;
2c3ccdde3919 Added interface to read/write register contents; re-worked register requests.
Florian Pose <fp@igh-essen.com>
parents: 2438
diff changeset
  3449
    }
2c3ccdde3919 Added interface to read/write register contents; re-worked register requests.
Florian Pose <fp@igh-essen.com>
parents: 2438
diff changeset
  3450
2719
94c9657e0bee Xenomai 2 to 3 migration says "RTDM drivers implementing differentiated ioctl() support for both domains should serve all real-time only requests from ioctl_rt(), returning -ENOSYS for any unrecognized request, which will cause the adaptive switch to take place automatically to the ioctl_nrt() handler. The ioctl_nrt() should then implement all requests which may be valid from the regular Linux domain exclusively."
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2712
diff changeset
  3451
    if (ec_copy_from_user(reg->data, (void __user *) io.data,
2443
2c3ccdde3919 Added interface to read/write register contents; re-worked register requests.
Florian Pose <fp@igh-essen.com>
parents: 2438
diff changeset
  3452
                io.transfer_size)) {
2c3ccdde3919 Added interface to read/write register contents; re-worked register requests.
Florian Pose <fp@igh-essen.com>
parents: 2438
diff changeset
  3453
        return -EFAULT;
2c3ccdde3919 Added interface to read/write register contents; re-worked register requests.
Florian Pose <fp@igh-essen.com>
parents: 2438
diff changeset
  3454
    }
2c3ccdde3919 Added interface to read/write register contents; re-worked register requests.
Florian Pose <fp@igh-essen.com>
parents: 2438
diff changeset
  3455
2c3ccdde3919 Added interface to read/write register contents; re-worked register requests.
Florian Pose <fp@igh-essen.com>
parents: 2438
diff changeset
  3456
    ecrt_reg_request_write(reg, io.address, io.transfer_size);
2c3ccdde3919 Added interface to read/write register contents; re-worked register requests.
Florian Pose <fp@igh-essen.com>
parents: 2438
diff changeset
  3457
    return 0;
2c3ccdde3919 Added interface to read/write register contents; re-worked register requests.
Florian Pose <fp@igh-essen.com>
parents: 2438
diff changeset
  3458
}
2c3ccdde3919 Added interface to read/write register contents; re-worked register requests.
Florian Pose <fp@igh-essen.com>
parents: 2438
diff changeset
  3459
2c3ccdde3919 Added interface to read/write register contents; re-worked register requests.
Florian Pose <fp@igh-essen.com>
parents: 2438
diff changeset
  3460
/*****************************************************************************/
2c3ccdde3919 Added interface to read/write register contents; re-worked register requests.
Florian Pose <fp@igh-essen.com>
parents: 2438
diff changeset
  3461
2c3ccdde3919 Added interface to read/write register contents; re-worked register requests.
Florian Pose <fp@igh-essen.com>
parents: 2438
diff changeset
  3462
/** Starts an register read operation.
2522
ec403cf308eb Updated Doxygen documentation.
Florian Pose <fp@igh-essen.com>
parents: 2505
diff changeset
  3463
 *
ec403cf308eb Updated Doxygen documentation.
Florian Pose <fp@igh-essen.com>
parents: 2505
diff changeset
  3464
 * \return Zero on success, otherwise a negative error code.
2443
2c3ccdde3919 Added interface to read/write register contents; re-worked register requests.
Florian Pose <fp@igh-essen.com>
parents: 2438
diff changeset
  3465
 */
2481
c99ff159b60d Added function attribute definition.
Florian Pose <fp@igh-essen.com>
parents: 2477
diff changeset
  3466
static ATTRIBUTES int ec_ioctl_reg_request_read(
2443
2c3ccdde3919 Added interface to read/write register contents; re-worked register requests.
Florian Pose <fp@igh-essen.com>
parents: 2438
diff changeset
  3467
        ec_master_t *master, /**< EtherCAT master. */
2c3ccdde3919 Added interface to read/write register contents; re-worked register requests.
Florian Pose <fp@igh-essen.com>
parents: 2438
diff changeset
  3468
        void *arg, /**< ioctl() argument. */
2c3ccdde3919 Added interface to read/write register contents; re-worked register requests.
Florian Pose <fp@igh-essen.com>
parents: 2438
diff changeset
  3469
        ec_ioctl_context_t *ctx /**< Private data structure of file handle. */
2c3ccdde3919 Added interface to read/write register contents; re-worked register requests.
Florian Pose <fp@igh-essen.com>
parents: 2438
diff changeset
  3470
        )
2c3ccdde3919 Added interface to read/write register contents; re-worked register requests.
Florian Pose <fp@igh-essen.com>
parents: 2438
diff changeset
  3471
{
2c3ccdde3919 Added interface to read/write register contents; re-worked register requests.
Florian Pose <fp@igh-essen.com>
parents: 2438
diff changeset
  3472
    ec_ioctl_reg_request_t io;
2c3ccdde3919 Added interface to read/write register contents; re-worked register requests.
Florian Pose <fp@igh-essen.com>
parents: 2438
diff changeset
  3473
    ec_slave_config_t *sc;
2c3ccdde3919 Added interface to read/write register contents; re-worked register requests.
Florian Pose <fp@igh-essen.com>
parents: 2438
diff changeset
  3474
    ec_reg_request_t *reg;
2c3ccdde3919 Added interface to read/write register contents; re-worked register requests.
Florian Pose <fp@igh-essen.com>
parents: 2438
diff changeset
  3475
2c3ccdde3919 Added interface to read/write register contents; re-worked register requests.
Florian Pose <fp@igh-essen.com>
parents: 2438
diff changeset
  3476
    if (unlikely(!ctx->requested)) {
2c3ccdde3919 Added interface to read/write register contents; re-worked register requests.
Florian Pose <fp@igh-essen.com>
parents: 2438
diff changeset
  3477
        return -EPERM;
2c3ccdde3919 Added interface to read/write register contents; re-worked register requests.
Florian Pose <fp@igh-essen.com>
parents: 2438
diff changeset
  3478
    }
2c3ccdde3919 Added interface to read/write register contents; re-worked register requests.
Florian Pose <fp@igh-essen.com>
parents: 2438
diff changeset
  3479
2719
94c9657e0bee Xenomai 2 to 3 migration says "RTDM drivers implementing differentiated ioctl() support for both domains should serve all real-time only requests from ioctl_rt(), returning -ENOSYS for any unrecognized request, which will cause the adaptive switch to take place automatically to the ioctl_nrt() handler. The ioctl_nrt() should then implement all requests which may be valid from the regular Linux domain exclusively."
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2712
diff changeset
  3480
    if (ec_copy_from_user(&io, (void __user *) arg, sizeof(io))) {
2443
2c3ccdde3919 Added interface to read/write register contents; re-worked register requests.
Florian Pose <fp@igh-essen.com>
parents: 2438
diff changeset
  3481
        return -EFAULT;
2c3ccdde3919 Added interface to read/write register contents; re-worked register requests.
Florian Pose <fp@igh-essen.com>
parents: 2438
diff changeset
  3482
    }
2c3ccdde3919 Added interface to read/write register contents; re-worked register requests.
Florian Pose <fp@igh-essen.com>
parents: 2438
diff changeset
  3483
2c3ccdde3919 Added interface to read/write register contents; re-worked register requests.
Florian Pose <fp@igh-essen.com>
parents: 2438
diff changeset
  3484
    /* no locking of master_sem needed, because neither sc nor reg will not be
2c3ccdde3919 Added interface to read/write register contents; re-worked register requests.
Florian Pose <fp@igh-essen.com>
parents: 2438
diff changeset
  3485
     * deleted in the meantime. */
2c3ccdde3919 Added interface to read/write register contents; re-worked register requests.
Florian Pose <fp@igh-essen.com>
parents: 2438
diff changeset
  3486
2c3ccdde3919 Added interface to read/write register contents; re-worked register requests.
Florian Pose <fp@igh-essen.com>
parents: 2438
diff changeset
  3487
    if (!(sc = ec_master_get_config(master, io.config_index))) {
2c3ccdde3919 Added interface to read/write register contents; re-worked register requests.
Florian Pose <fp@igh-essen.com>
parents: 2438
diff changeset
  3488
        return -ENOENT;
2c3ccdde3919 Added interface to read/write register contents; re-worked register requests.
Florian Pose <fp@igh-essen.com>
parents: 2438
diff changeset
  3489
    }
2c3ccdde3919 Added interface to read/write register contents; re-worked register requests.
Florian Pose <fp@igh-essen.com>
parents: 2438
diff changeset
  3490
2c3ccdde3919 Added interface to read/write register contents; re-worked register requests.
Florian Pose <fp@igh-essen.com>
parents: 2438
diff changeset
  3491
    if (!(reg = ec_slave_config_find_reg_request(sc, io.request_index))) {
2c3ccdde3919 Added interface to read/write register contents; re-worked register requests.
Florian Pose <fp@igh-essen.com>
parents: 2438
diff changeset
  3492
        return -ENOENT;
2c3ccdde3919 Added interface to read/write register contents; re-worked register requests.
Florian Pose <fp@igh-essen.com>
parents: 2438
diff changeset
  3493
    }
2c3ccdde3919 Added interface to read/write register contents; re-worked register requests.
Florian Pose <fp@igh-essen.com>
parents: 2438
diff changeset
  3494
2c3ccdde3919 Added interface to read/write register contents; re-worked register requests.
Florian Pose <fp@igh-essen.com>
parents: 2438
diff changeset
  3495
    if (io.transfer_size > reg->mem_size) {
2c3ccdde3919 Added interface to read/write register contents; re-worked register requests.
Florian Pose <fp@igh-essen.com>
parents: 2438
diff changeset
  3496
        return -EOVERFLOW;
2c3ccdde3919 Added interface to read/write register contents; re-worked register requests.
Florian Pose <fp@igh-essen.com>
parents: 2438
diff changeset
  3497
    }
2c3ccdde3919 Added interface to read/write register contents; re-worked register requests.
Florian Pose <fp@igh-essen.com>
parents: 2438
diff changeset
  3498
2c3ccdde3919 Added interface to read/write register contents; re-worked register requests.
Florian Pose <fp@igh-essen.com>
parents: 2438
diff changeset
  3499
    ecrt_reg_request_read(reg, io.address, io.transfer_size);
2c3ccdde3919 Added interface to read/write register contents; re-worked register requests.
Florian Pose <fp@igh-essen.com>
parents: 2438
diff changeset
  3500
    return 0;
2c3ccdde3919 Added interface to read/write register contents; re-worked register requests.
Florian Pose <fp@igh-essen.com>
parents: 2438
diff changeset
  3501
}
2c3ccdde3919 Added interface to read/write register contents; re-worked register requests.
Florian Pose <fp@igh-essen.com>
parents: 2438
diff changeset
  3502
2c3ccdde3919 Added interface to read/write register contents; re-worked register requests.
Florian Pose <fp@igh-essen.com>
parents: 2438
diff changeset
  3503
/*****************************************************************************/
2c3ccdde3919 Added interface to read/write register contents; re-worked register requests.
Florian Pose <fp@igh-essen.com>
parents: 2438
diff changeset
  3504
2433
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3505
/** Sets the VoE send header.
2522
ec403cf308eb Updated Doxygen documentation.
Florian Pose <fp@igh-essen.com>
parents: 2505
diff changeset
  3506
 *
ec403cf308eb Updated Doxygen documentation.
Florian Pose <fp@igh-essen.com>
parents: 2505
diff changeset
  3507
 * \return Zero on success, otherwise a negative error code.
2433
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3508
 */
2481
c99ff159b60d Added function attribute definition.
Florian Pose <fp@igh-essen.com>
parents: 2477
diff changeset
  3509
static ATTRIBUTES int ec_ioctl_voe_send_header(
2433
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3510
        ec_master_t *master, /**< EtherCAT master. */
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3511
        void *arg, /**< ioctl() argument. */
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3512
        ec_ioctl_context_t *ctx /**< Private data structure of file handle. */
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3513
        )
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3514
{
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3515
    ec_ioctl_voe_t data;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3516
    ec_slave_config_t *sc;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3517
    ec_voe_handler_t *voe;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3518
    uint32_t vendor_id;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3519
    uint16_t vendor_type;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3520
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3521
    if (unlikely(!ctx->requested))
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3522
        return -EPERM;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3523
2719
94c9657e0bee Xenomai 2 to 3 migration says "RTDM drivers implementing differentiated ioctl() support for both domains should serve all real-time only requests from ioctl_rt(), returning -ENOSYS for any unrecognized request, which will cause the adaptive switch to take place automatically to the ioctl_nrt() handler. The ioctl_nrt() should then implement all requests which may be valid from the regular Linux domain exclusively."
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2712
diff changeset
  3524
    if (ec_copy_from_user(&data, (void __user *) arg, sizeof(data)))
2433
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3525
        return -EFAULT;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3526
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3527
    if (get_user(vendor_id, data.vendor_id))
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3528
        return -EFAULT;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3529
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3530
    if (get_user(vendor_type, data.vendor_type))
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3531
        return -EFAULT;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3532
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3533
    /* no locking of master_sem needed, because neither sc nor voe will not be
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3534
     * deleted in the meantime. */
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3535
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3536
    if (!(sc = ec_master_get_config(master, data.config_index))) {
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3537
        return -ENOENT;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3538
    }
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3539
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3540
    if (!(voe = ec_slave_config_find_voe_handler(sc, data.voe_index))) {
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3541
        return -ENOENT;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3542
    }
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3543
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3544
    ecrt_voe_handler_send_header(voe, vendor_id, vendor_type);
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3545
    return 0;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3546
}
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3547
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3548
/*****************************************************************************/
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3549
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3550
/** Gets the received VoE header.
2522
ec403cf308eb Updated Doxygen documentation.
Florian Pose <fp@igh-essen.com>
parents: 2505
diff changeset
  3551
 *
ec403cf308eb Updated Doxygen documentation.
Florian Pose <fp@igh-essen.com>
parents: 2505
diff changeset
  3552
 * \return Zero on success, otherwise a negative error code.
2433
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3553
 */
2481
c99ff159b60d Added function attribute definition.
Florian Pose <fp@igh-essen.com>
parents: 2477
diff changeset
  3554
static ATTRIBUTES int ec_ioctl_voe_rec_header(
2433
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3555
        ec_master_t *master, /**< EtherCAT master. */
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3556
        void *arg, /**< ioctl() argument. */
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3557
        ec_ioctl_context_t *ctx /**< Private data structure of file handle. */
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3558
        )
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3559
{
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3560
    ec_ioctl_voe_t data;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3561
    ec_slave_config_t *sc;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3562
    ec_voe_handler_t *voe;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3563
    uint32_t vendor_id;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3564
    uint16_t vendor_type;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3565
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3566
    if (unlikely(!ctx->requested))
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3567
        return -EPERM;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3568
2719
94c9657e0bee Xenomai 2 to 3 migration says "RTDM drivers implementing differentiated ioctl() support for both domains should serve all real-time only requests from ioctl_rt(), returning -ENOSYS for any unrecognized request, which will cause the adaptive switch to take place automatically to the ioctl_nrt() handler. The ioctl_nrt() should then implement all requests which may be valid from the regular Linux domain exclusively."
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2712
diff changeset
  3569
    if (ec_copy_from_user(&data, (void __user *) arg, sizeof(data)))
2433
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3570
        return -EFAULT;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3571
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3572
    /* no locking of master_sem needed, because neither sc nor voe will not be
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3573
     * deleted in the meantime. */
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3574
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3575
    if (!(sc = ec_master_get_config(master, data.config_index))) {
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3576
        return -ENOENT;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3577
    }
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3578
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3579
    if (!(voe = ec_slave_config_find_voe_handler(sc, data.voe_index))) {
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3580
        return -ENOENT;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3581
    }
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3582
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3583
    ecrt_voe_handler_received_header(voe, &vendor_id, &vendor_type);
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3584
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3585
    if (likely(data.vendor_id))
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3586
        if (put_user(vendor_id, data.vendor_id))
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3587
            return -EFAULT;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3588
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3589
    if (likely(data.vendor_type))
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3590
        if (put_user(vendor_type, data.vendor_type))
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3591
            return -EFAULT;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3592
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3593
    return 0;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3594
}
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3595
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3596
/*****************************************************************************/
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3597
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3598
/** Starts a VoE read operation.
2522
ec403cf308eb Updated Doxygen documentation.
Florian Pose <fp@igh-essen.com>
parents: 2505
diff changeset
  3599
 *
ec403cf308eb Updated Doxygen documentation.
Florian Pose <fp@igh-essen.com>
parents: 2505
diff changeset
  3600
 * \return Zero on success, otherwise a negative error code.
2433
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3601
 */
2481
c99ff159b60d Added function attribute definition.
Florian Pose <fp@igh-essen.com>
parents: 2477
diff changeset
  3602
static ATTRIBUTES int ec_ioctl_voe_read(
2433
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3603
        ec_master_t *master, /**< EtherCAT master. */
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3604
        void *arg, /**< ioctl() argument. */
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3605
        ec_ioctl_context_t *ctx /**< Private data structure of file handle. */
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3606
        )
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3607
{
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3608
    ec_ioctl_voe_t data;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3609
    ec_slave_config_t *sc;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3610
    ec_voe_handler_t *voe;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3611
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3612
    if (unlikely(!ctx->requested))
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3613
        return -EPERM;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3614
2719
94c9657e0bee Xenomai 2 to 3 migration says "RTDM drivers implementing differentiated ioctl() support for both domains should serve all real-time only requests from ioctl_rt(), returning -ENOSYS for any unrecognized request, which will cause the adaptive switch to take place automatically to the ioctl_nrt() handler. The ioctl_nrt() should then implement all requests which may be valid from the regular Linux domain exclusively."
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2712
diff changeset
  3615
    if (ec_copy_from_user(&data, (void __user *) arg, sizeof(data)))
2433
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3616
        return -EFAULT;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3617
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3618
    /* no locking of master_sem needed, because neither sc nor voe will not be
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3619
     * deleted in the meantime. */
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3620
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3621
    if (!(sc = ec_master_get_config(master, data.config_index))) {
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3622
        return -ENOENT;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3623
    }
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3624
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3625
    if (!(voe = ec_slave_config_find_voe_handler(sc, data.voe_index))) {
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3626
        return -ENOENT;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3627
    }
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3628
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3629
    ecrt_voe_handler_read(voe);
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3630
    return 0;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3631
}
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3632
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3633
/*****************************************************************************/
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3634
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3635
/** Starts a VoE read operation without sending a sync message first.
2522
ec403cf308eb Updated Doxygen documentation.
Florian Pose <fp@igh-essen.com>
parents: 2505
diff changeset
  3636
 *
ec403cf308eb Updated Doxygen documentation.
Florian Pose <fp@igh-essen.com>
parents: 2505
diff changeset
  3637
 * \return Zero on success, otherwise a negative error code.
2433
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3638
 */
2481
c99ff159b60d Added function attribute definition.
Florian Pose <fp@igh-essen.com>
parents: 2477
diff changeset
  3639
static ATTRIBUTES int ec_ioctl_voe_read_nosync(
2433
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3640
        ec_master_t *master, /**< EtherCAT master. */
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3641
        void *arg, /**< ioctl() argument. */
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3642
        ec_ioctl_context_t *ctx /**< Private data structure of file handle. */
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3643
        )
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3644
{
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3645
    ec_ioctl_voe_t data;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3646
    ec_slave_config_t *sc;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3647
    ec_voe_handler_t *voe;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3648
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3649
    if (unlikely(!ctx->requested))
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3650
        return -EPERM;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3651
2719
94c9657e0bee Xenomai 2 to 3 migration says "RTDM drivers implementing differentiated ioctl() support for both domains should serve all real-time only requests from ioctl_rt(), returning -ENOSYS for any unrecognized request, which will cause the adaptive switch to take place automatically to the ioctl_nrt() handler. The ioctl_nrt() should then implement all requests which may be valid from the regular Linux domain exclusively."
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2712
diff changeset
  3652
    if (ec_copy_from_user(&data, (void __user *) arg, sizeof(data)))
2433
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3653
        return -EFAULT;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3654
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3655
    /* no locking of master_sem needed, because neither sc nor voe will not be
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3656
     * deleted in the meantime. */
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3657
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3658
    if (!(sc = ec_master_get_config(master, data.config_index))) {
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3659
        return -ENOENT;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3660
    }
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3661
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3662
    if (!(voe = ec_slave_config_find_voe_handler(sc, data.voe_index))) {
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3663
        return -ENOENT;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3664
    }
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3665
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3666
    ecrt_voe_handler_read_nosync(voe);
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3667
    return 0;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3668
}
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3669
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3670
/*****************************************************************************/
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3671
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3672
/** Starts a VoE write operation.
2522
ec403cf308eb Updated Doxygen documentation.
Florian Pose <fp@igh-essen.com>
parents: 2505
diff changeset
  3673
 *
ec403cf308eb Updated Doxygen documentation.
Florian Pose <fp@igh-essen.com>
parents: 2505
diff changeset
  3674
 * \return Zero on success, otherwise a negative error code.
2433
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3675
 */
2481
c99ff159b60d Added function attribute definition.
Florian Pose <fp@igh-essen.com>
parents: 2477
diff changeset
  3676
static ATTRIBUTES int ec_ioctl_voe_write(
2433
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3677
        ec_master_t *master, /**< EtherCAT master. */
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3678
        void *arg, /**< ioctl() argument. */
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3679
        ec_ioctl_context_t *ctx /**< Private data structure of file handle. */
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3680
        )
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3681
{
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3682
    ec_ioctl_voe_t data;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3683
    ec_slave_config_t *sc;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3684
    ec_voe_handler_t *voe;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3685
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3686
    if (unlikely(!ctx->requested))
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3687
        return -EPERM;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3688
2719
94c9657e0bee Xenomai 2 to 3 migration says "RTDM drivers implementing differentiated ioctl() support for both domains should serve all real-time only requests from ioctl_rt(), returning -ENOSYS for any unrecognized request, which will cause the adaptive switch to take place automatically to the ioctl_nrt() handler. The ioctl_nrt() should then implement all requests which may be valid from the regular Linux domain exclusively."
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2712
diff changeset
  3689
    if (ec_copy_from_user(&data, (void __user *) arg, sizeof(data)))
2433
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3690
        return -EFAULT;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3691
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3692
    /* no locking of master_sem needed, because neither sc nor voe will not be
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3693
     * deleted in the meantime. */
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3694
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3695
    if (!(sc = ec_master_get_config(master, data.config_index))) {
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3696
        return -ENOENT;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3697
    }
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3698
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3699
    if (!(voe = ec_slave_config_find_voe_handler(sc, data.voe_index))) {
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3700
        return -ENOENT;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3701
    }
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3702
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3703
    if (data.size) {
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3704
        if (data.size > ec_voe_handler_mem_size(voe))
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3705
            return -EOVERFLOW;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3706
2719
94c9657e0bee Xenomai 2 to 3 migration says "RTDM drivers implementing differentiated ioctl() support for both domains should serve all real-time only requests from ioctl_rt(), returning -ENOSYS for any unrecognized request, which will cause the adaptive switch to take place automatically to the ioctl_nrt() handler. The ioctl_nrt() should then implement all requests which may be valid from the regular Linux domain exclusively."
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2712
diff changeset
  3707
        if (ec_copy_from_user(ecrt_voe_handler_data(voe),
2433
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3708
                    (void __user *) data.data, data.size))
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3709
            return -EFAULT;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3710
    }
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3711
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3712
    ecrt_voe_handler_write(voe, data.size);
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3713
    return 0;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3714
}
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3715
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3716
/*****************************************************************************/
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3717
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3718
/** Executes the VoE state machine.
2522
ec403cf308eb Updated Doxygen documentation.
Florian Pose <fp@igh-essen.com>
parents: 2505
diff changeset
  3719
 *
ec403cf308eb Updated Doxygen documentation.
Florian Pose <fp@igh-essen.com>
parents: 2505
diff changeset
  3720
 * \return Zero on success, otherwise a negative error code.
2433
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3721
 */
2481
c99ff159b60d Added function attribute definition.
Florian Pose <fp@igh-essen.com>
parents: 2477
diff changeset
  3722
static ATTRIBUTES int ec_ioctl_voe_exec(
2433
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3723
        ec_master_t *master, /**< EtherCAT master. */
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3724
        void *arg, /**< ioctl() argument. */
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3725
        ec_ioctl_context_t *ctx /**< Private data structure of file handle. */
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3726
        )
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3727
{
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3728
    ec_ioctl_voe_t data;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3729
    ec_slave_config_t *sc;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3730
    ec_voe_handler_t *voe;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3731
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3732
    if (unlikely(!ctx->requested))
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3733
        return -EPERM;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3734
2719
94c9657e0bee Xenomai 2 to 3 migration says "RTDM drivers implementing differentiated ioctl() support for both domains should serve all real-time only requests from ioctl_rt(), returning -ENOSYS for any unrecognized request, which will cause the adaptive switch to take place automatically to the ioctl_nrt() handler. The ioctl_nrt() should then implement all requests which may be valid from the regular Linux domain exclusively."
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2712
diff changeset
  3735
    if (ec_copy_from_user(&data, (void __user *) arg, sizeof(data)))
2433
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3736
        return -EFAULT;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3737
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3738
    /* no locking of master_sem needed, because neither sc nor voe will not be
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3739
     * deleted in the meantime. */
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3740
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3741
    if (!(sc = ec_master_get_config(master, data.config_index))) {
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3742
        return -ENOENT;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3743
    }
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3744
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3745
    if (!(voe = ec_slave_config_find_voe_handler(sc, data.voe_index))) {
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3746
        return -ENOENT;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3747
    }
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3748
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3749
    data.state = ecrt_voe_handler_execute(voe);
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3750
    if (data.state == EC_REQUEST_SUCCESS && voe->dir == EC_DIR_INPUT)
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3751
        data.size = ecrt_voe_handler_data_size(voe);
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3752
    else
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3753
        data.size = 0;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3754
2719
94c9657e0bee Xenomai 2 to 3 migration says "RTDM drivers implementing differentiated ioctl() support for both domains should serve all real-time only requests from ioctl_rt(), returning -ENOSYS for any unrecognized request, which will cause the adaptive switch to take place automatically to the ioctl_nrt() handler. The ioctl_nrt() should then implement all requests which may be valid from the regular Linux domain exclusively."
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2712
diff changeset
  3755
    if (ec_copy_to_user((void __user *) arg, &data, sizeof(data)))
2433
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3756
        return -EFAULT;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3757
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3758
    return 0;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3759
}
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3760
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3761
/*****************************************************************************/
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3762
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3763
/** Reads the received VoE data.
2522
ec403cf308eb Updated Doxygen documentation.
Florian Pose <fp@igh-essen.com>
parents: 2505
diff changeset
  3764
 *
ec403cf308eb Updated Doxygen documentation.
Florian Pose <fp@igh-essen.com>
parents: 2505
diff changeset
  3765
 * \return Zero on success, otherwise a negative error code.
2433
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3766
 */
2481
c99ff159b60d Added function attribute definition.
Florian Pose <fp@igh-essen.com>
parents: 2477
diff changeset
  3767
static ATTRIBUTES int ec_ioctl_voe_data(
2433
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3768
        ec_master_t *master, /**< EtherCAT master. */
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3769
        void *arg, /**< ioctl() argument. */
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3770
        ec_ioctl_context_t *ctx /**< Private data structure of file handle. */
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3771
        )
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3772
{
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3773
    ec_ioctl_voe_t data;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3774
    ec_slave_config_t *sc;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3775
    ec_voe_handler_t *voe;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3776
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3777
    if (unlikely(!ctx->requested))
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3778
        return -EPERM;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3779
2719
94c9657e0bee Xenomai 2 to 3 migration says "RTDM drivers implementing differentiated ioctl() support for both domains should serve all real-time only requests from ioctl_rt(), returning -ENOSYS for any unrecognized request, which will cause the adaptive switch to take place automatically to the ioctl_nrt() handler. The ioctl_nrt() should then implement all requests which may be valid from the regular Linux domain exclusively."
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2712
diff changeset
  3780
    if (ec_copy_from_user(&data, (void __user *) arg, sizeof(data)))
2433
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3781
        return -EFAULT;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3782
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3783
    /* no locking of master_sem needed, because neither sc nor voe will not be
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3784
     * deleted in the meantime. */
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3785
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3786
    if (!(sc = ec_master_get_config(master, data.config_index))) {
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3787
        return -ENOENT;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3788
    }
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3789
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3790
    if (!(voe = ec_slave_config_find_voe_handler(sc, data.voe_index))) {
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3791
        return -ENOENT;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3792
    }
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3793
2719
94c9657e0bee Xenomai 2 to 3 migration says "RTDM drivers implementing differentiated ioctl() support for both domains should serve all real-time only requests from ioctl_rt(), returning -ENOSYS for any unrecognized request, which will cause the adaptive switch to take place automatically to the ioctl_nrt() handler. The ioctl_nrt() should then implement all requests which may be valid from the regular Linux domain exclusively."
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2712
diff changeset
  3794
    if (ec_copy_to_user((void __user *) data.data, ecrt_voe_handler_data(voe),
2433
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3795
                ecrt_voe_handler_data_size(voe)))
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3796
        return -EFAULT;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3797
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3798
    return 0;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3799
}
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3800
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3801
/*****************************************************************************/
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3802
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3803
/** Read a file from a slave via FoE.
2522
ec403cf308eb Updated Doxygen documentation.
Florian Pose <fp@igh-essen.com>
parents: 2505
diff changeset
  3804
 *
ec403cf308eb Updated Doxygen documentation.
Florian Pose <fp@igh-essen.com>
parents: 2505
diff changeset
  3805
 * \return Zero on success, otherwise a negative error code.
2433
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3806
 */
2481
c99ff159b60d Added function attribute definition.
Florian Pose <fp@igh-essen.com>
parents: 2477
diff changeset
  3807
static ATTRIBUTES int ec_ioctl_slave_foe_read(
2433
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3808
        ec_master_t *master, /**< EtherCAT master. */
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3809
        void *arg /**< ioctl() argument. */
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3810
        )
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3811
{
2464
e6cc33cac6a2 Removed unnecessary ec_master_foe_request_t; fixed FoE access.
Florian Pose <fp@igh-essen.com>
parents: 2453
diff changeset
  3812
    ec_ioctl_slave_foe_t io;
e6cc33cac6a2 Removed unnecessary ec_master_foe_request_t; fixed FoE access.
Florian Pose <fp@igh-essen.com>
parents: 2453
diff changeset
  3813
    ec_foe_request_t request;
e6cc33cac6a2 Removed unnecessary ec_master_foe_request_t; fixed FoE access.
Florian Pose <fp@igh-essen.com>
parents: 2453
diff changeset
  3814
    ec_slave_t *slave;
e6cc33cac6a2 Removed unnecessary ec_master_foe_request_t; fixed FoE access.
Florian Pose <fp@igh-essen.com>
parents: 2453
diff changeset
  3815
    int ret;
e6cc33cac6a2 Removed unnecessary ec_master_foe_request_t; fixed FoE access.
Florian Pose <fp@igh-essen.com>
parents: 2453
diff changeset
  3816
2719
94c9657e0bee Xenomai 2 to 3 migration says "RTDM drivers implementing differentiated ioctl() support for both domains should serve all real-time only requests from ioctl_rt(), returning -ENOSYS for any unrecognized request, which will cause the adaptive switch to take place automatically to the ioctl_nrt() handler. The ioctl_nrt() should then implement all requests which may be valid from the regular Linux domain exclusively."
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2712
diff changeset
  3817
    if (ec_copy_from_user(&io, (void __user *) arg, sizeof(io))) {
2464
e6cc33cac6a2 Removed unnecessary ec_master_foe_request_t; fixed FoE access.
Florian Pose <fp@igh-essen.com>
parents: 2453
diff changeset
  3818
        return -EFAULT;
e6cc33cac6a2 Removed unnecessary ec_master_foe_request_t; fixed FoE access.
Florian Pose <fp@igh-essen.com>
parents: 2453
diff changeset
  3819
    }
e6cc33cac6a2 Removed unnecessary ec_master_foe_request_t; fixed FoE access.
Florian Pose <fp@igh-essen.com>
parents: 2453
diff changeset
  3820
e6cc33cac6a2 Removed unnecessary ec_master_foe_request_t; fixed FoE access.
Florian Pose <fp@igh-essen.com>
parents: 2453
diff changeset
  3821
    ec_foe_request_init(&request, io.file_name);
e6cc33cac6a2 Removed unnecessary ec_master_foe_request_t; fixed FoE access.
Florian Pose <fp@igh-essen.com>
parents: 2453
diff changeset
  3822
    ret = ec_foe_request_alloc(&request, 10000); // FIXME
e6cc33cac6a2 Removed unnecessary ec_master_foe_request_t; fixed FoE access.
Florian Pose <fp@igh-essen.com>
parents: 2453
diff changeset
  3823
    if (ret) {
e6cc33cac6a2 Removed unnecessary ec_master_foe_request_t; fixed FoE access.
Florian Pose <fp@igh-essen.com>
parents: 2453
diff changeset
  3824
        ec_foe_request_clear(&request);
e6cc33cac6a2 Removed unnecessary ec_master_foe_request_t; fixed FoE access.
Florian Pose <fp@igh-essen.com>
parents: 2453
diff changeset
  3825
        return ret;
e6cc33cac6a2 Removed unnecessary ec_master_foe_request_t; fixed FoE access.
Florian Pose <fp@igh-essen.com>
parents: 2453
diff changeset
  3826
    }
e6cc33cac6a2 Removed unnecessary ec_master_foe_request_t; fixed FoE access.
Florian Pose <fp@igh-essen.com>
parents: 2453
diff changeset
  3827
e6cc33cac6a2 Removed unnecessary ec_master_foe_request_t; fixed FoE access.
Florian Pose <fp@igh-essen.com>
parents: 2453
diff changeset
  3828
    ec_foe_request_read(&request);
2433
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3829
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3830
    if (down_interruptible(&master->master_sem)) {
2464
e6cc33cac6a2 Removed unnecessary ec_master_foe_request_t; fixed FoE access.
Florian Pose <fp@igh-essen.com>
parents: 2453
diff changeset
  3831
        ec_foe_request_clear(&request);
2433
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3832
        return -EINTR;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3833
    }
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3834
2464
e6cc33cac6a2 Removed unnecessary ec_master_foe_request_t; fixed FoE access.
Florian Pose <fp@igh-essen.com>
parents: 2453
diff changeset
  3835
    if (!(slave = ec_master_find_slave(master, 0, io.slave_position))) {
e6cc33cac6a2 Removed unnecessary ec_master_foe_request_t; fixed FoE access.
Florian Pose <fp@igh-essen.com>
parents: 2453
diff changeset
  3836
        up(&master->master_sem);
e6cc33cac6a2 Removed unnecessary ec_master_foe_request_t; fixed FoE access.
Florian Pose <fp@igh-essen.com>
parents: 2453
diff changeset
  3837
        ec_foe_request_clear(&request);
2433
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3838
        EC_MASTER_ERR(master, "Slave %u does not exist!\n",
2464
e6cc33cac6a2 Removed unnecessary ec_master_foe_request_t; fixed FoE access.
Florian Pose <fp@igh-essen.com>
parents: 2453
diff changeset
  3839
                io.slave_position);
2433
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3840
        return -EINVAL;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3841
    }
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3842
2467
74ede087bc85 Using common waitqueue for requests.
Florian Pose <fp@igh-essen.com>
parents: 2464
diff changeset
  3843
    EC_SLAVE_DBG(slave, 1, "Scheduling FoE read request.\n");
74ede087bc85 Using common waitqueue for requests.
Florian Pose <fp@igh-essen.com>
parents: 2464
diff changeset
  3844
2433
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3845
    // schedule request.
2464
e6cc33cac6a2 Removed unnecessary ec_master_foe_request_t; fixed FoE access.
Florian Pose <fp@igh-essen.com>
parents: 2453
diff changeset
  3846
    list_add_tail(&request.list, &slave->foe_requests);
2433
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3847
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3848
    up(&master->master_sem);
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3849
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3850
    // wait for processing through FSM
2467
74ede087bc85 Using common waitqueue for requests.
Florian Pose <fp@igh-essen.com>
parents: 2464
diff changeset
  3851
    if (wait_event_interruptible(master->request_queue,
2464
e6cc33cac6a2 Removed unnecessary ec_master_foe_request_t; fixed FoE access.
Florian Pose <fp@igh-essen.com>
parents: 2453
diff changeset
  3852
                request.state != EC_INT_REQUEST_QUEUED)) {
2433
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3853
        // interrupted by signal
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3854
        down(&master->master_sem);
2464
e6cc33cac6a2 Removed unnecessary ec_master_foe_request_t; fixed FoE access.
Florian Pose <fp@igh-essen.com>
parents: 2453
diff changeset
  3855
        if (request.state == EC_INT_REQUEST_QUEUED) {
2433
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3856
            list_del(&request.list);
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3857
            up(&master->master_sem);
2464
e6cc33cac6a2 Removed unnecessary ec_master_foe_request_t; fixed FoE access.
Florian Pose <fp@igh-essen.com>
parents: 2453
diff changeset
  3858
            ec_foe_request_clear(&request);
2433
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3859
            return -EINTR;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3860
        }
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3861
        // request already processing: interrupt not possible.
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3862
        up(&master->master_sem);
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3863
    }
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3864
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3865
    // wait until master FSM has finished processing
2467
74ede087bc85 Using common waitqueue for requests.
Florian Pose <fp@igh-essen.com>
parents: 2464
diff changeset
  3866
    wait_event(master->request_queue, request.state != EC_INT_REQUEST_BUSY);
2464
e6cc33cac6a2 Removed unnecessary ec_master_foe_request_t; fixed FoE access.
Florian Pose <fp@igh-essen.com>
parents: 2453
diff changeset
  3867
e6cc33cac6a2 Removed unnecessary ec_master_foe_request_t; fixed FoE access.
Florian Pose <fp@igh-essen.com>
parents: 2453
diff changeset
  3868
    io.result = request.result;
e6cc33cac6a2 Removed unnecessary ec_master_foe_request_t; fixed FoE access.
Florian Pose <fp@igh-essen.com>
parents: 2453
diff changeset
  3869
    io.error_code = request.error_code;
e6cc33cac6a2 Removed unnecessary ec_master_foe_request_t; fixed FoE access.
Florian Pose <fp@igh-essen.com>
parents: 2453
diff changeset
  3870
e6cc33cac6a2 Removed unnecessary ec_master_foe_request_t; fixed FoE access.
Florian Pose <fp@igh-essen.com>
parents: 2453
diff changeset
  3871
    if (request.state != EC_INT_REQUEST_SUCCESS) {
e6cc33cac6a2 Removed unnecessary ec_master_foe_request_t; fixed FoE access.
Florian Pose <fp@igh-essen.com>
parents: 2453
diff changeset
  3872
        io.data_size = 0;
e6cc33cac6a2 Removed unnecessary ec_master_foe_request_t; fixed FoE access.
Florian Pose <fp@igh-essen.com>
parents: 2453
diff changeset
  3873
        ret = -EIO;
2433
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3874
    } else {
2464
e6cc33cac6a2 Removed unnecessary ec_master_foe_request_t; fixed FoE access.
Florian Pose <fp@igh-essen.com>
parents: 2453
diff changeset
  3875
        if (request.data_size > io.buffer_size) {
2693
8051d05cb935 Improved buffer overflow messages.
Florian Pose <fp@igh.de>
parents: 2529
diff changeset
  3876
            EC_SLAVE_ERR(slave, "%s(): Buffer too small.\n", __func__);
2464
e6cc33cac6a2 Removed unnecessary ec_master_foe_request_t; fixed FoE access.
Florian Pose <fp@igh-essen.com>
parents: 2453
diff changeset
  3877
            ec_foe_request_clear(&request);
2433
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3878
            return -EOVERFLOW;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3879
        }
2464
e6cc33cac6a2 Removed unnecessary ec_master_foe_request_t; fixed FoE access.
Florian Pose <fp@igh-essen.com>
parents: 2453
diff changeset
  3880
        io.data_size = request.data_size;
2719
94c9657e0bee Xenomai 2 to 3 migration says "RTDM drivers implementing differentiated ioctl() support for both domains should serve all real-time only requests from ioctl_rt(), returning -ENOSYS for any unrecognized request, which will cause the adaptive switch to take place automatically to the ioctl_nrt() handler. The ioctl_nrt() should then implement all requests which may be valid from the regular Linux domain exclusively."
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2712
diff changeset
  3881
        if (ec_copy_to_user((void __user *) io.buffer,
2464
e6cc33cac6a2 Removed unnecessary ec_master_foe_request_t; fixed FoE access.
Florian Pose <fp@igh-essen.com>
parents: 2453
diff changeset
  3882
                    request.buffer, io.data_size)) {
e6cc33cac6a2 Removed unnecessary ec_master_foe_request_t; fixed FoE access.
Florian Pose <fp@igh-essen.com>
parents: 2453
diff changeset
  3883
            ec_foe_request_clear(&request);
2433
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3884
            return -EFAULT;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3885
        }
2464
e6cc33cac6a2 Removed unnecessary ec_master_foe_request_t; fixed FoE access.
Florian Pose <fp@igh-essen.com>
parents: 2453
diff changeset
  3886
        ret = 0;
e6cc33cac6a2 Removed unnecessary ec_master_foe_request_t; fixed FoE access.
Florian Pose <fp@igh-essen.com>
parents: 2453
diff changeset
  3887
    }
e6cc33cac6a2 Removed unnecessary ec_master_foe_request_t; fixed FoE access.
Florian Pose <fp@igh-essen.com>
parents: 2453
diff changeset
  3888
2719
94c9657e0bee Xenomai 2 to 3 migration says "RTDM drivers implementing differentiated ioctl() support for both domains should serve all real-time only requests from ioctl_rt(), returning -ENOSYS for any unrecognized request, which will cause the adaptive switch to take place automatically to the ioctl_nrt() handler. The ioctl_nrt() should then implement all requests which may be valid from the regular Linux domain exclusively."
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2712
diff changeset
  3889
    if (ec_copy_to_user((void __user *) arg, &io, sizeof(io))) {
2464
e6cc33cac6a2 Removed unnecessary ec_master_foe_request_t; fixed FoE access.
Florian Pose <fp@igh-essen.com>
parents: 2453
diff changeset
  3890
        ret = -EFAULT;
e6cc33cac6a2 Removed unnecessary ec_master_foe_request_t; fixed FoE access.
Florian Pose <fp@igh-essen.com>
parents: 2453
diff changeset
  3891
    }
e6cc33cac6a2 Removed unnecessary ec_master_foe_request_t; fixed FoE access.
Florian Pose <fp@igh-essen.com>
parents: 2453
diff changeset
  3892
e6cc33cac6a2 Removed unnecessary ec_master_foe_request_t; fixed FoE access.
Florian Pose <fp@igh-essen.com>
parents: 2453
diff changeset
  3893
    ec_foe_request_clear(&request);
e6cc33cac6a2 Removed unnecessary ec_master_foe_request_t; fixed FoE access.
Florian Pose <fp@igh-essen.com>
parents: 2453
diff changeset
  3894
    return ret;
2433
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3895
}
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3896
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3897
/*****************************************************************************/
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3898
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3899
/** Write a file to a slave via FoE
2522
ec403cf308eb Updated Doxygen documentation.
Florian Pose <fp@igh-essen.com>
parents: 2505
diff changeset
  3900
 *
ec403cf308eb Updated Doxygen documentation.
Florian Pose <fp@igh-essen.com>
parents: 2505
diff changeset
  3901
 * \return Zero on success, otherwise a negative error code.
2433
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3902
 */
2481
c99ff159b60d Added function attribute definition.
Florian Pose <fp@igh-essen.com>
parents: 2477
diff changeset
  3903
static ATTRIBUTES int ec_ioctl_slave_foe_write(
2433
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3904
        ec_master_t *master, /**< EtherCAT master. */
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3905
        void *arg /**< ioctl() argument. */
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3906
        )
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3907
{
2464
e6cc33cac6a2 Removed unnecessary ec_master_foe_request_t; fixed FoE access.
Florian Pose <fp@igh-essen.com>
parents: 2453
diff changeset
  3908
    ec_ioctl_slave_foe_t io;
e6cc33cac6a2 Removed unnecessary ec_master_foe_request_t; fixed FoE access.
Florian Pose <fp@igh-essen.com>
parents: 2453
diff changeset
  3909
    ec_foe_request_t request;
e6cc33cac6a2 Removed unnecessary ec_master_foe_request_t; fixed FoE access.
Florian Pose <fp@igh-essen.com>
parents: 2453
diff changeset
  3910
    ec_slave_t *slave;
e6cc33cac6a2 Removed unnecessary ec_master_foe_request_t; fixed FoE access.
Florian Pose <fp@igh-essen.com>
parents: 2453
diff changeset
  3911
    int ret;
e6cc33cac6a2 Removed unnecessary ec_master_foe_request_t; fixed FoE access.
Florian Pose <fp@igh-essen.com>
parents: 2453
diff changeset
  3912
2719
94c9657e0bee Xenomai 2 to 3 migration says "RTDM drivers implementing differentiated ioctl() support for both domains should serve all real-time only requests from ioctl_rt(), returning -ENOSYS for any unrecognized request, which will cause the adaptive switch to take place automatically to the ioctl_nrt() handler. The ioctl_nrt() should then implement all requests which may be valid from the regular Linux domain exclusively."
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2712
diff changeset
  3913
    if (ec_copy_from_user(&io, (void __user *) arg, sizeof(io))) {
2464
e6cc33cac6a2 Removed unnecessary ec_master_foe_request_t; fixed FoE access.
Florian Pose <fp@igh-essen.com>
parents: 2453
diff changeset
  3914
        return -EFAULT;
e6cc33cac6a2 Removed unnecessary ec_master_foe_request_t; fixed FoE access.
Florian Pose <fp@igh-essen.com>
parents: 2453
diff changeset
  3915
    }
e6cc33cac6a2 Removed unnecessary ec_master_foe_request_t; fixed FoE access.
Florian Pose <fp@igh-essen.com>
parents: 2453
diff changeset
  3916
e6cc33cac6a2 Removed unnecessary ec_master_foe_request_t; fixed FoE access.
Florian Pose <fp@igh-essen.com>
parents: 2453
diff changeset
  3917
    ec_foe_request_init(&request, io.file_name);
e6cc33cac6a2 Removed unnecessary ec_master_foe_request_t; fixed FoE access.
Florian Pose <fp@igh-essen.com>
parents: 2453
diff changeset
  3918
e6cc33cac6a2 Removed unnecessary ec_master_foe_request_t; fixed FoE access.
Florian Pose <fp@igh-essen.com>
parents: 2453
diff changeset
  3919
    ret = ec_foe_request_alloc(&request, io.buffer_size);
e6cc33cac6a2 Removed unnecessary ec_master_foe_request_t; fixed FoE access.
Florian Pose <fp@igh-essen.com>
parents: 2453
diff changeset
  3920
    if (ret) {
e6cc33cac6a2 Removed unnecessary ec_master_foe_request_t; fixed FoE access.
Florian Pose <fp@igh-essen.com>
parents: 2453
diff changeset
  3921
        ec_foe_request_clear(&request);
e6cc33cac6a2 Removed unnecessary ec_master_foe_request_t; fixed FoE access.
Florian Pose <fp@igh-essen.com>
parents: 2453
diff changeset
  3922
        return ret;
e6cc33cac6a2 Removed unnecessary ec_master_foe_request_t; fixed FoE access.
Florian Pose <fp@igh-essen.com>
parents: 2453
diff changeset
  3923
    }
e6cc33cac6a2 Removed unnecessary ec_master_foe_request_t; fixed FoE access.
Florian Pose <fp@igh-essen.com>
parents: 2453
diff changeset
  3924
2719
94c9657e0bee Xenomai 2 to 3 migration says "RTDM drivers implementing differentiated ioctl() support for both domains should serve all real-time only requests from ioctl_rt(), returning -ENOSYS for any unrecognized request, which will cause the adaptive switch to take place automatically to the ioctl_nrt() handler. The ioctl_nrt() should then implement all requests which may be valid from the regular Linux domain exclusively."
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2712
diff changeset
  3925
    if (ec_copy_from_user(request.buffer,
2464
e6cc33cac6a2 Removed unnecessary ec_master_foe_request_t; fixed FoE access.
Florian Pose <fp@igh-essen.com>
parents: 2453
diff changeset
  3926
                (void __user *) io.buffer, io.buffer_size)) {
e6cc33cac6a2 Removed unnecessary ec_master_foe_request_t; fixed FoE access.
Florian Pose <fp@igh-essen.com>
parents: 2453
diff changeset
  3927
        ec_foe_request_clear(&request);
e6cc33cac6a2 Removed unnecessary ec_master_foe_request_t; fixed FoE access.
Florian Pose <fp@igh-essen.com>
parents: 2453
diff changeset
  3928
        return -EFAULT;
e6cc33cac6a2 Removed unnecessary ec_master_foe_request_t; fixed FoE access.
Florian Pose <fp@igh-essen.com>
parents: 2453
diff changeset
  3929
    }
e6cc33cac6a2 Removed unnecessary ec_master_foe_request_t; fixed FoE access.
Florian Pose <fp@igh-essen.com>
parents: 2453
diff changeset
  3930
e6cc33cac6a2 Removed unnecessary ec_master_foe_request_t; fixed FoE access.
Florian Pose <fp@igh-essen.com>
parents: 2453
diff changeset
  3931
    request.data_size = io.buffer_size;
e6cc33cac6a2 Removed unnecessary ec_master_foe_request_t; fixed FoE access.
Florian Pose <fp@igh-essen.com>
parents: 2453
diff changeset
  3932
    ec_foe_request_write(&request);
2433
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3933
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3934
    if (down_interruptible(&master->master_sem)) {
2464
e6cc33cac6a2 Removed unnecessary ec_master_foe_request_t; fixed FoE access.
Florian Pose <fp@igh-essen.com>
parents: 2453
diff changeset
  3935
        ec_foe_request_clear(&request);
2433
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3936
        return -EINTR;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3937
    }
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3938
2464
e6cc33cac6a2 Removed unnecessary ec_master_foe_request_t; fixed FoE access.
Florian Pose <fp@igh-essen.com>
parents: 2453
diff changeset
  3939
    if (!(slave = ec_master_find_slave(master, 0, io.slave_position))) {
2433
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3940
        up(&master->master_sem);
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3941
        EC_MASTER_ERR(master, "Slave %u does not exist!\n",
2464
e6cc33cac6a2 Removed unnecessary ec_master_foe_request_t; fixed FoE access.
Florian Pose <fp@igh-essen.com>
parents: 2453
diff changeset
  3942
                io.slave_position);
e6cc33cac6a2 Removed unnecessary ec_master_foe_request_t; fixed FoE access.
Florian Pose <fp@igh-essen.com>
parents: 2453
diff changeset
  3943
        ec_foe_request_clear(&request);
2433
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3944
        return -EINVAL;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3945
    }
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3946
2464
e6cc33cac6a2 Removed unnecessary ec_master_foe_request_t; fixed FoE access.
Florian Pose <fp@igh-essen.com>
parents: 2453
diff changeset
  3947
    EC_SLAVE_DBG(slave, 1, "Scheduling FoE write request.\n");
2433
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3948
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3949
    // schedule FoE write request.
2464
e6cc33cac6a2 Removed unnecessary ec_master_foe_request_t; fixed FoE access.
Florian Pose <fp@igh-essen.com>
parents: 2453
diff changeset
  3950
    list_add_tail(&request.list, &slave->foe_requests);
2433
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3951
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3952
    up(&master->master_sem);
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3953
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3954
    // wait for processing through FSM
2467
74ede087bc85 Using common waitqueue for requests.
Florian Pose <fp@igh-essen.com>
parents: 2464
diff changeset
  3955
    if (wait_event_interruptible(master->request_queue,
2464
e6cc33cac6a2 Removed unnecessary ec_master_foe_request_t; fixed FoE access.
Florian Pose <fp@igh-essen.com>
parents: 2453
diff changeset
  3956
                request.state != EC_INT_REQUEST_QUEUED)) {
2433
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3957
        // interrupted by signal
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3958
        down(&master->master_sem);
2464
e6cc33cac6a2 Removed unnecessary ec_master_foe_request_t; fixed FoE access.
Florian Pose <fp@igh-essen.com>
parents: 2453
diff changeset
  3959
        if (request.state == EC_INT_REQUEST_QUEUED) {
2433
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3960
            // abort request
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3961
            list_del(&request.list);
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3962
            up(&master->master_sem);
2464
e6cc33cac6a2 Removed unnecessary ec_master_foe_request_t; fixed FoE access.
Florian Pose <fp@igh-essen.com>
parents: 2453
diff changeset
  3963
            ec_foe_request_clear(&request);
2433
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3964
            return -EINTR;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3965
        }
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3966
        up(&master->master_sem);
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3967
    }
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3968
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3969
    // wait until master FSM has finished processing
2467
74ede087bc85 Using common waitqueue for requests.
Florian Pose <fp@igh-essen.com>
parents: 2464
diff changeset
  3970
    wait_event(master->request_queue, request.state != EC_INT_REQUEST_BUSY);
2464
e6cc33cac6a2 Removed unnecessary ec_master_foe_request_t; fixed FoE access.
Florian Pose <fp@igh-essen.com>
parents: 2453
diff changeset
  3971
e6cc33cac6a2 Removed unnecessary ec_master_foe_request_t; fixed FoE access.
Florian Pose <fp@igh-essen.com>
parents: 2453
diff changeset
  3972
    io.result = request.result;
e6cc33cac6a2 Removed unnecessary ec_master_foe_request_t; fixed FoE access.
Florian Pose <fp@igh-essen.com>
parents: 2453
diff changeset
  3973
    io.error_code = request.error_code;
e6cc33cac6a2 Removed unnecessary ec_master_foe_request_t; fixed FoE access.
Florian Pose <fp@igh-essen.com>
parents: 2453
diff changeset
  3974
e6cc33cac6a2 Removed unnecessary ec_master_foe_request_t; fixed FoE access.
Florian Pose <fp@igh-essen.com>
parents: 2453
diff changeset
  3975
    ret = request.state == EC_INT_REQUEST_SUCCESS ? 0 : -EIO;
e6cc33cac6a2 Removed unnecessary ec_master_foe_request_t; fixed FoE access.
Florian Pose <fp@igh-essen.com>
parents: 2453
diff changeset
  3976
2719
94c9657e0bee Xenomai 2 to 3 migration says "RTDM drivers implementing differentiated ioctl() support for both domains should serve all real-time only requests from ioctl_rt(), returning -ENOSYS for any unrecognized request, which will cause the adaptive switch to take place automatically to the ioctl_nrt() handler. The ioctl_nrt() should then implement all requests which may be valid from the regular Linux domain exclusively."
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2712
diff changeset
  3977
    if (ec_copy_to_user((void __user *) arg, &io, sizeof(io))) {
2464
e6cc33cac6a2 Removed unnecessary ec_master_foe_request_t; fixed FoE access.
Florian Pose <fp@igh-essen.com>
parents: 2453
diff changeset
  3978
        ret = -EFAULT;
e6cc33cac6a2 Removed unnecessary ec_master_foe_request_t; fixed FoE access.
Florian Pose <fp@igh-essen.com>
parents: 2453
diff changeset
  3979
    }
e6cc33cac6a2 Removed unnecessary ec_master_foe_request_t; fixed FoE access.
Florian Pose <fp@igh-essen.com>
parents: 2453
diff changeset
  3980
e6cc33cac6a2 Removed unnecessary ec_master_foe_request_t; fixed FoE access.
Florian Pose <fp@igh-essen.com>
parents: 2453
diff changeset
  3981
    ec_foe_request_clear(&request);
e6cc33cac6a2 Removed unnecessary ec_master_foe_request_t; fixed FoE access.
Florian Pose <fp@igh-essen.com>
parents: 2453
diff changeset
  3982
    return ret;
2433
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3983
}
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3984
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3985
/*****************************************************************************/
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3986
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3987
/** Read an SoE IDN.
2522
ec403cf308eb Updated Doxygen documentation.
Florian Pose <fp@igh-essen.com>
parents: 2505
diff changeset
  3988
 *
ec403cf308eb Updated Doxygen documentation.
Florian Pose <fp@igh-essen.com>
parents: 2505
diff changeset
  3989
 * \return Zero on success, otherwise a negative error code.
2433
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3990
 */
2481
c99ff159b60d Added function attribute definition.
Florian Pose <fp@igh-essen.com>
parents: 2477
diff changeset
  3991
static ATTRIBUTES int ec_ioctl_slave_soe_read(
2433
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3992
        ec_master_t *master, /**< EtherCAT master. */
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3993
        void *arg /**< ioctl() argument. */
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3994
        )
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3995
{
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3996
    ec_ioctl_slave_soe_read_t ioctl;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3997
    u8 *data;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3998
    int retval;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3999
2719
94c9657e0bee Xenomai 2 to 3 migration says "RTDM drivers implementing differentiated ioctl() support for both domains should serve all real-time only requests from ioctl_rt(), returning -ENOSYS for any unrecognized request, which will cause the adaptive switch to take place automatically to the ioctl_nrt() handler. The ioctl_nrt() should then implement all requests which may be valid from the regular Linux domain exclusively."
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2712
diff changeset
  4000
    if (ec_copy_from_user(&ioctl, (void __user *) arg, sizeof(ioctl))) {
2433
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4001
        return -EFAULT;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4002
    }
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4003
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4004
    data = kmalloc(ioctl.mem_size, GFP_KERNEL);
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4005
    if (!data) {
2487
ccafdf1e261f Fixed some warnings on 64 bit systems.
Florian Pose <fp@igh-essen.com>
parents: 2486
diff changeset
  4006
        EC_MASTER_ERR(master, "Failed to allocate %zu bytes of IDN data.\n",
2433
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4007
                ioctl.mem_size);
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4008
        return -ENOMEM;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4009
    }
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4010
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4011
    retval = ecrt_master_read_idn(master, ioctl.slave_position,
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4012
            ioctl.drive_no, ioctl.idn, data, ioctl.mem_size, &ioctl.data_size,
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4013
            &ioctl.error_code);
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4014
    if (retval) {
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4015
        kfree(data);
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4016
        return retval;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4017
    }
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4018
2719
94c9657e0bee Xenomai 2 to 3 migration says "RTDM drivers implementing differentiated ioctl() support for both domains should serve all real-time only requests from ioctl_rt(), returning -ENOSYS for any unrecognized request, which will cause the adaptive switch to take place automatically to the ioctl_nrt() handler. The ioctl_nrt() should then implement all requests which may be valid from the regular Linux domain exclusively."
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2712
diff changeset
  4019
    if (ec_copy_to_user((void __user *) ioctl.data,
2433
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4020
                data, ioctl.data_size)) {
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4021
        kfree(data);
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4022
        return -EFAULT;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4023
    }
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4024
    kfree(data);
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4025
2719
94c9657e0bee Xenomai 2 to 3 migration says "RTDM drivers implementing differentiated ioctl() support for both domains should serve all real-time only requests from ioctl_rt(), returning -ENOSYS for any unrecognized request, which will cause the adaptive switch to take place automatically to the ioctl_nrt() handler. The ioctl_nrt() should then implement all requests which may be valid from the regular Linux domain exclusively."
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2712
diff changeset
  4026
    if (ec_copy_to_user((void __user *) arg, &ioctl, sizeof(ioctl))) {
2433
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4027
        retval = -EFAULT;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4028
    }
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4029
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4030
    EC_MASTER_DBG(master, 1, "Finished SoE read request.\n");
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4031
    return retval;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4032
}
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4033
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4034
/*****************************************************************************/
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4035
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4036
/** Write an IDN to a slave via SoE.
2522
ec403cf308eb Updated Doxygen documentation.
Florian Pose <fp@igh-essen.com>
parents: 2505
diff changeset
  4037
 *
ec403cf308eb Updated Doxygen documentation.
Florian Pose <fp@igh-essen.com>
parents: 2505
diff changeset
  4038
 * \return Zero on success, otherwise a negative error code.
2433
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4039
 */
2481
c99ff159b60d Added function attribute definition.
Florian Pose <fp@igh-essen.com>
parents: 2477
diff changeset
  4040
static ATTRIBUTES int ec_ioctl_slave_soe_write(
2433
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4041
        ec_master_t *master, /**< EtherCAT master. */
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4042
        void *arg /**< ioctl() argument. */
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4043
        )
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4044
{
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4045
    ec_ioctl_slave_soe_write_t ioctl;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4046
    u8 *data;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4047
    int retval;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4048
2719
94c9657e0bee Xenomai 2 to 3 migration says "RTDM drivers implementing differentiated ioctl() support for both domains should serve all real-time only requests from ioctl_rt(), returning -ENOSYS for any unrecognized request, which will cause the adaptive switch to take place automatically to the ioctl_nrt() handler. The ioctl_nrt() should then implement all requests which may be valid from the regular Linux domain exclusively."
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2712
diff changeset
  4049
    if (ec_copy_from_user(&ioctl, (void __user *) arg, sizeof(ioctl))) {
2433
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4050
        return -EFAULT;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4051
    }
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4052
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4053
    data = kmalloc(ioctl.data_size, GFP_KERNEL);
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4054
    if (!data) {
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4055
        EC_MASTER_ERR(master, "Failed to allocate %zu bytes of IDN data.\n",
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4056
                ioctl.data_size);
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4057
        return -ENOMEM;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4058
    }
2719
94c9657e0bee Xenomai 2 to 3 migration says "RTDM drivers implementing differentiated ioctl() support for both domains should serve all real-time only requests from ioctl_rt(), returning -ENOSYS for any unrecognized request, which will cause the adaptive switch to take place automatically to the ioctl_nrt() handler. The ioctl_nrt() should then implement all requests which may be valid from the regular Linux domain exclusively."
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2712
diff changeset
  4059
    if (ec_copy_from_user(data, (void __user *) ioctl.data, ioctl.data_size)) {
2433
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4060
        kfree(data);
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4061
        return -EFAULT;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4062
    }
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4063
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4064
    retval = ecrt_master_write_idn(master, ioctl.slave_position,
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4065
            ioctl.drive_no, ioctl.idn, data, ioctl.data_size,
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4066
            &ioctl.error_code);
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4067
    kfree(data);
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4068
    if (retval) {
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4069
        return retval;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4070
    }
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4071
2719
94c9657e0bee Xenomai 2 to 3 migration says "RTDM drivers implementing differentiated ioctl() support for both domains should serve all real-time only requests from ioctl_rt(), returning -ENOSYS for any unrecognized request, which will cause the adaptive switch to take place automatically to the ioctl_nrt() handler. The ioctl_nrt() should then implement all requests which may be valid from the regular Linux domain exclusively."
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2712
diff changeset
  4072
    if (ec_copy_to_user((void __user *) arg, &ioctl, sizeof(ioctl))) {
2433
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4073
        retval = -EFAULT;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4074
    }
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4075
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4076
    EC_MASTER_DBG(master, 1, "Finished SoE write request.\n");
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4077
    return retval;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4078
}
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4079
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4080
/*****************************************************************************/
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4081
2522
ec403cf308eb Updated Doxygen documentation.
Florian Pose <fp@igh-essen.com>
parents: 2505
diff changeset
  4082
/** ioctl() function to use.
ec403cf308eb Updated Doxygen documentation.
Florian Pose <fp@igh-essen.com>
parents: 2505
diff changeset
  4083
 */
2433
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4084
#ifdef EC_IOCTL_RTDM
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4085
#define EC_IOCTL ec_ioctl_rtdm
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4086
#else
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4087
#define EC_IOCTL ec_ioctl
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4088
#endif
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4089
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4090
/** Called when an ioctl() command is issued.
2522
ec403cf308eb Updated Doxygen documentation.
Florian Pose <fp@igh-essen.com>
parents: 2505
diff changeset
  4091
 *
ec403cf308eb Updated Doxygen documentation.
Florian Pose <fp@igh-essen.com>
parents: 2505
diff changeset
  4092
 * \return ioctl() return code.
ec403cf308eb Updated Doxygen documentation.
Florian Pose <fp@igh-essen.com>
parents: 2505
diff changeset
  4093
 */
ec403cf308eb Updated Doxygen documentation.
Florian Pose <fp@igh-essen.com>
parents: 2505
diff changeset
  4094
long EC_IOCTL(
ec403cf308eb Updated Doxygen documentation.
Florian Pose <fp@igh-essen.com>
parents: 2505
diff changeset
  4095
        ec_master_t *master, /**< EtherCAT master. */
ec403cf308eb Updated Doxygen documentation.
Florian Pose <fp@igh-essen.com>
parents: 2505
diff changeset
  4096
        ec_ioctl_context_t *ctx, /**< Device context. */
ec403cf308eb Updated Doxygen documentation.
Florian Pose <fp@igh-essen.com>
parents: 2505
diff changeset
  4097
        unsigned int cmd, /**< ioctl() command identifier. */
ec403cf308eb Updated Doxygen documentation.
Florian Pose <fp@igh-essen.com>
parents: 2505
diff changeset
  4098
        void *arg /**< ioctl() argument. */
ec403cf308eb Updated Doxygen documentation.
Florian Pose <fp@igh-essen.com>
parents: 2505
diff changeset
  4099
        )
2433
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4100
{
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4101
#if DEBUG_LATENCY
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4102
    cycles_t a = get_cycles(), b;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4103
    unsigned int t;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4104
#endif
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4105
    int ret;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4106
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4107
    switch (cmd) {
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4108
        case EC_IOCTL_MODULE:
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4109
            ret = ec_ioctl_module(arg);
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4110
            break;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4111
        case EC_IOCTL_MASTER:
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4112
            ret = ec_ioctl_master(master, arg);
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4113
            break;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4114
        case EC_IOCTL_SLAVE:
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4115
            ret = ec_ioctl_slave(master, arg);
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4116
            break;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4117
        case EC_IOCTL_SLAVE_SYNC:
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4118
            ret = ec_ioctl_slave_sync(master, arg);
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4119
            break;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4120
        case EC_IOCTL_SLAVE_SYNC_PDO:
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4121
            ret = ec_ioctl_slave_sync_pdo(master, arg);
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4122
            break;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4123
        case EC_IOCTL_SLAVE_SYNC_PDO_ENTRY:
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4124
            ret = ec_ioctl_slave_sync_pdo_entry(master, arg);
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4125
            break;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4126
        case EC_IOCTL_DOMAIN:
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4127
            ret = ec_ioctl_domain(master, arg);
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4128
            break;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4129
        case EC_IOCTL_DOMAIN_FMMU:
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4130
            ret = ec_ioctl_domain_fmmu(master, arg);
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4131
            break;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4132
        case EC_IOCTL_DOMAIN_DATA:
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4133
            ret = ec_ioctl_domain_data(master, arg);
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4134
            break;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4135
        case EC_IOCTL_MASTER_DEBUG:
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4136
            if (!ctx->writable) {
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4137
                ret = -EPERM;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4138
                break;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4139
            }
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4140
            ret = ec_ioctl_master_debug(master, arg);
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4141
            break;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4142
        case EC_IOCTL_MASTER_RESCAN:
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4143
            if (!ctx->writable) {
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4144
                ret = -EPERM;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4145
                break;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4146
            }
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4147
            ret = ec_ioctl_master_rescan(master, arg);
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4148
            break;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4149
        case EC_IOCTL_SLAVE_STATE:
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4150
            if (!ctx->writable) {
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4151
                ret = -EPERM;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4152
                break;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4153
            }
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4154
            ret = ec_ioctl_slave_state(master, arg);
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4155
            break;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4156
        case EC_IOCTL_SLAVE_SDO:
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4157
            ret = ec_ioctl_slave_sdo(master, arg);
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4158
            break;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4159
        case EC_IOCTL_SLAVE_SDO_ENTRY:
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4160
            ret = ec_ioctl_slave_sdo_entry(master, arg);
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4161
            break;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4162
        case EC_IOCTL_SLAVE_SDO_UPLOAD:
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4163
            ret = ec_ioctl_slave_sdo_upload(master, arg);
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4164
            break;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4165
        case EC_IOCTL_SLAVE_SDO_DOWNLOAD:
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4166
            if (!ctx->writable) {
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4167
                ret = -EPERM;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4168
                break;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4169
            }
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4170
            ret = ec_ioctl_slave_sdo_download(master, arg);
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4171
            break;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4172
        case EC_IOCTL_SLAVE_SII_READ:
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4173
            ret = ec_ioctl_slave_sii_read(master, arg);
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4174
            break;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4175
        case EC_IOCTL_SLAVE_SII_WRITE:
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4176
            if (!ctx->writable) {
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4177
                ret = -EPERM;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4178
                break;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4179
            }
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4180
            ret = ec_ioctl_slave_sii_write(master, arg);
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4181
            break;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4182
        case EC_IOCTL_SLAVE_REG_READ:
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4183
            ret = ec_ioctl_slave_reg_read(master, arg);
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4184
            break;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4185
        case EC_IOCTL_SLAVE_REG_WRITE:
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4186
            if (!ctx->writable) {
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4187
                ret = -EPERM;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4188
                break;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4189
            }
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4190
            ret = ec_ioctl_slave_reg_write(master, arg);
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4191
            break;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4192
        case EC_IOCTL_SLAVE_FOE_READ:
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4193
            ret = ec_ioctl_slave_foe_read(master, arg);
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4194
            break;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4195
        case EC_IOCTL_SLAVE_FOE_WRITE:
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4196
            if (!ctx->writable) {
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4197
                ret = -EPERM;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4198
                break;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4199
            }
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4200
            ret = ec_ioctl_slave_foe_write(master, arg);
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4201
            break;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4202
        case EC_IOCTL_SLAVE_SOE_READ:
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4203
            ret = ec_ioctl_slave_soe_read(master, arg);
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4204
            break;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4205
        case EC_IOCTL_SLAVE_SOE_WRITE:
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4206
            if (!ctx->writable) {
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4207
                ret = -EPERM;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4208
                break;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4209
            }
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4210
            ret = ec_ioctl_slave_soe_write(master, arg);
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4211
            break;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4212
        case EC_IOCTL_CONFIG:
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4213
            ret = ec_ioctl_config(master, arg);
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4214
            break;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4215
        case EC_IOCTL_CONFIG_PDO:
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4216
            ret = ec_ioctl_config_pdo(master, arg);
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4217
            break;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4218
        case EC_IOCTL_CONFIG_PDO_ENTRY:
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4219
            ret = ec_ioctl_config_pdo_entry(master, arg);
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4220
            break;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4221
        case EC_IOCTL_CONFIG_SDO:
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4222
            ret = ec_ioctl_config_sdo(master, arg);
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4223
            break;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4224
        case EC_IOCTL_CONFIG_IDN:
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4225
            ret = ec_ioctl_config_idn(master, arg);
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4226
            break;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4227
#ifdef EC_EOE
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4228
        case EC_IOCTL_EOE_HANDLER:
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4229
            ret = ec_ioctl_eoe_handler(master, arg);
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4230
            break;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4231
#endif
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4232
        case EC_IOCTL_REQUEST:
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4233
            if (!ctx->writable) {
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4234
                ret = -EPERM;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4235
                break;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4236
            }
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4237
            ret = ec_ioctl_request(master, arg, ctx);
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4238
            break;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4239
        case EC_IOCTL_CREATE_DOMAIN:
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4240
            if (!ctx->writable) {
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4241
                ret = -EPERM;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4242
                break;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4243
            }
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4244
            ret = ec_ioctl_create_domain(master, arg, ctx);
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4245
            break;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4246
        case EC_IOCTL_CREATE_SLAVE_CONFIG:
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4247
            if (!ctx->writable) {
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4248
                ret = -EPERM;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4249
                break;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4250
            }
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4251
            ret = ec_ioctl_create_slave_config(master, arg, ctx);
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4252
            break;
2447
e93efb4af231 Added interface to select the reference clock and to sync to it.
Florian Pose <fp@igh-essen.com>
parents: 2443
diff changeset
  4253
        case EC_IOCTL_SELECT_REF_CLOCK:
e93efb4af231 Added interface to select the reference clock and to sync to it.
Florian Pose <fp@igh-essen.com>
parents: 2443
diff changeset
  4254
            if (!ctx->writable) {
e93efb4af231 Added interface to select the reference clock and to sync to it.
Florian Pose <fp@igh-essen.com>
parents: 2443
diff changeset
  4255
                ret = -EPERM;
e93efb4af231 Added interface to select the reference clock and to sync to it.
Florian Pose <fp@igh-essen.com>
parents: 2443
diff changeset
  4256
                break;
e93efb4af231 Added interface to select the reference clock and to sync to it.
Florian Pose <fp@igh-essen.com>
parents: 2443
diff changeset
  4257
            }
e93efb4af231 Added interface to select the reference clock and to sync to it.
Florian Pose <fp@igh-essen.com>
parents: 2443
diff changeset
  4258
            ret = ec_ioctl_select_ref_clock(master, arg, ctx);
e93efb4af231 Added interface to select the reference clock and to sync to it.
Florian Pose <fp@igh-essen.com>
parents: 2443
diff changeset
  4259
            break;
2433
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4260
        case EC_IOCTL_ACTIVATE:
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4261
            if (!ctx->writable) {
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4262
                ret = -EPERM;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4263
                break;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4264
            }
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4265
            ret = ec_ioctl_activate(master, arg, ctx);
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4266
            break;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4267
        case EC_IOCTL_DEACTIVATE:
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4268
            if (!ctx->writable) {
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4269
                ret = -EPERM;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4270
                break;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4271
            }
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4272
            ret = ec_ioctl_deactivate(master, arg, ctx);
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4273
            break;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4274
        case EC_IOCTL_SEND:
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4275
            if (!ctx->writable) {
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4276
                ret = -EPERM;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4277
                break;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4278
            }
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4279
            ret = ec_ioctl_send(master, arg, ctx);
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4280
            break;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4281
        case EC_IOCTL_RECEIVE:
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4282
            if (!ctx->writable) {
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4283
                ret = -EPERM;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4284
                break;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4285
            }
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4286
            ret = ec_ioctl_receive(master, arg, ctx);
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4287
            break;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4288
        case EC_IOCTL_MASTER_STATE:
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4289
            ret = ec_ioctl_master_state(master, arg, ctx);
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4290
            break;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4291
        case EC_IOCTL_MASTER_LINK_STATE:
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4292
            ret = ec_ioctl_master_link_state(master, arg, ctx);
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4293
            break;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4294
        case EC_IOCTL_APP_TIME:
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4295
            if (!ctx->writable) {
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4296
                ret = -EPERM;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4297
                break;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4298
            }
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4299
            ret = ec_ioctl_app_time(master, arg, ctx);
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4300
            break;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4301
        case EC_IOCTL_SYNC_REF:
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4302
            if (!ctx->writable) {
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4303
                ret = -EPERM;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4304
                break;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4305
            }
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4306
            ret = ec_ioctl_sync_ref(master, arg, ctx);
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4307
            break;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4308
        case EC_IOCTL_SYNC_SLAVES:
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4309
            if (!ctx->writable) {
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4310
                ret = -EPERM;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4311
                break;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4312
            }
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4313
            ret = ec_ioctl_sync_slaves(master, arg, ctx);
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4314
            break;
2447
e93efb4af231 Added interface to select the reference clock and to sync to it.
Florian Pose <fp@igh-essen.com>
parents: 2443
diff changeset
  4315
        case EC_IOCTL_REF_CLOCK_TIME:
e93efb4af231 Added interface to select the reference clock and to sync to it.
Florian Pose <fp@igh-essen.com>
parents: 2443
diff changeset
  4316
            if (!ctx->writable) {
e93efb4af231 Added interface to select the reference clock and to sync to it.
Florian Pose <fp@igh-essen.com>
parents: 2443
diff changeset
  4317
                ret = -EPERM;
e93efb4af231 Added interface to select the reference clock and to sync to it.
Florian Pose <fp@igh-essen.com>
parents: 2443
diff changeset
  4318
                break;
e93efb4af231 Added interface to select the reference clock and to sync to it.
Florian Pose <fp@igh-essen.com>
parents: 2443
diff changeset
  4319
            }
e93efb4af231 Added interface to select the reference clock and to sync to it.
Florian Pose <fp@igh-essen.com>
parents: 2443
diff changeset
  4320
            ret = ec_ioctl_ref_clock_time(master, arg, ctx);
e93efb4af231 Added interface to select the reference clock and to sync to it.
Florian Pose <fp@igh-essen.com>
parents: 2443
diff changeset
  4321
            break;
2433
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4322
        case EC_IOCTL_SYNC_MON_QUEUE:
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4323
            if (!ctx->writable) {
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4324
                ret = -EPERM;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4325
                break;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4326
            }
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4327
            ret = ec_ioctl_sync_mon_queue(master, arg, ctx);
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4328
            break;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4329
        case EC_IOCTL_SYNC_MON_PROCESS:
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4330
            if (!ctx->writable) {
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4331
                ret = -EPERM;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4332
                break;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4333
            }
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4334
            ret = ec_ioctl_sync_mon_process(master, arg, ctx);
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4335
            break;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4336
        case EC_IOCTL_RESET:
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4337
            if (!ctx->writable) {
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4338
                ret = -EPERM;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4339
                break;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4340
            }
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4341
            ret = ec_ioctl_reset(master, arg, ctx);
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4342
            break;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4343
        case EC_IOCTL_SC_SYNC:
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4344
            if (!ctx->writable) {
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4345
                ret = -EPERM;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4346
                break;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4347
            }
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4348
            ret = ec_ioctl_sc_sync(master, arg, ctx);
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4349
            break;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4350
        case EC_IOCTL_SC_WATCHDOG:
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4351
            if (!ctx->writable) {
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4352
                ret = -EPERM;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4353
                break;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4354
            }
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4355
            ret = ec_ioctl_sc_watchdog(master, arg, ctx);
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4356
            break;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4357
        case EC_IOCTL_SC_ADD_PDO:
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4358
            if (!ctx->writable) {
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4359
                ret = -EPERM;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4360
                break;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4361
            }
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4362
            ret = ec_ioctl_sc_add_pdo(master, arg, ctx);
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4363
            break;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4364
        case EC_IOCTL_SC_CLEAR_PDOS:
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4365
            if (!ctx->writable) {
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4366
                ret = -EPERM;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4367
                break;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4368
            }
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4369
            ret = ec_ioctl_sc_clear_pdos(master, arg, ctx);
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4370
            break;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4371
        case EC_IOCTL_SC_ADD_ENTRY:
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4372
            if (!ctx->writable) {
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4373
                ret = -EPERM;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4374
                break;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4375
            }
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4376
            ret = ec_ioctl_sc_add_entry(master, arg, ctx);
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4377
            break;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4378
        case EC_IOCTL_SC_CLEAR_ENTRIES:
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4379
            if (!ctx->writable) {
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4380
                ret = -EPERM;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4381
                break;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4382
            }
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4383
            ret = ec_ioctl_sc_clear_entries(master, arg, ctx);
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4384
            break;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4385
        case EC_IOCTL_SC_REG_PDO_ENTRY:
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4386
            if (!ctx->writable) {
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4387
                ret = -EPERM;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4388
                break;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4389
            }
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4390
            ret = ec_ioctl_sc_reg_pdo_entry(master, arg, ctx);
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4391
            break;
2505
5ef3197e5e1f Added ecrt_slave_config_reg_so_entry_pos() to register non-unique entries.
Florian Pose <fp@igh-essen.com>
parents: 2504
diff changeset
  4392
        case EC_IOCTL_SC_REG_PDO_POS:
5ef3197e5e1f Added ecrt_slave_config_reg_so_entry_pos() to register non-unique entries.
Florian Pose <fp@igh-essen.com>
parents: 2504
diff changeset
  4393
            if (!ctx->writable) {
5ef3197e5e1f Added ecrt_slave_config_reg_so_entry_pos() to register non-unique entries.
Florian Pose <fp@igh-essen.com>
parents: 2504
diff changeset
  4394
                ret = -EPERM;
5ef3197e5e1f Added ecrt_slave_config_reg_so_entry_pos() to register non-unique entries.
Florian Pose <fp@igh-essen.com>
parents: 2504
diff changeset
  4395
                break;
5ef3197e5e1f Added ecrt_slave_config_reg_so_entry_pos() to register non-unique entries.
Florian Pose <fp@igh-essen.com>
parents: 2504
diff changeset
  4396
            }
5ef3197e5e1f Added ecrt_slave_config_reg_so_entry_pos() to register non-unique entries.
Florian Pose <fp@igh-essen.com>
parents: 2504
diff changeset
  4397
            ret = ec_ioctl_sc_reg_pdo_pos(master, arg, ctx);
5ef3197e5e1f Added ecrt_slave_config_reg_so_entry_pos() to register non-unique entries.
Florian Pose <fp@igh-essen.com>
parents: 2504
diff changeset
  4398
            break;
2433
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4399
        case EC_IOCTL_SC_DC:
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4400
            if (!ctx->writable) {
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4401
                ret = -EPERM;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4402
                break;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4403
            }
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4404
            ret = ec_ioctl_sc_dc(master, arg, ctx);
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4405
            break;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4406
        case EC_IOCTL_SC_SDO:
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4407
            if (!ctx->writable) {
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4408
                ret = -EPERM;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4409
                break;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4410
            }
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4411
            ret = ec_ioctl_sc_sdo(master, arg, ctx);
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4412
            break;
2438
9c3e629a220c Added API for querying CoE emergency requests.
Florian Pose <fp@igh-essen.com>
parents: 2435
diff changeset
  4413
        case EC_IOCTL_SC_EMERG_SIZE:
9c3e629a220c Added API for querying CoE emergency requests.
Florian Pose <fp@igh-essen.com>
parents: 2435
diff changeset
  4414
            if (!ctx->writable) {
9c3e629a220c Added API for querying CoE emergency requests.
Florian Pose <fp@igh-essen.com>
parents: 2435
diff changeset
  4415
                ret = -EPERM;
9c3e629a220c Added API for querying CoE emergency requests.
Florian Pose <fp@igh-essen.com>
parents: 2435
diff changeset
  4416
                break;
9c3e629a220c Added API for querying CoE emergency requests.
Florian Pose <fp@igh-essen.com>
parents: 2435
diff changeset
  4417
            }
9c3e629a220c Added API for querying CoE emergency requests.
Florian Pose <fp@igh-essen.com>
parents: 2435
diff changeset
  4418
            ret = ec_ioctl_sc_emerg_size(master, arg, ctx);
9c3e629a220c Added API for querying CoE emergency requests.
Florian Pose <fp@igh-essen.com>
parents: 2435
diff changeset
  4419
            break;
9c3e629a220c Added API for querying CoE emergency requests.
Florian Pose <fp@igh-essen.com>
parents: 2435
diff changeset
  4420
        case EC_IOCTL_SC_EMERG_POP:
9c3e629a220c Added API for querying CoE emergency requests.
Florian Pose <fp@igh-essen.com>
parents: 2435
diff changeset
  4421
            if (!ctx->writable) {
9c3e629a220c Added API for querying CoE emergency requests.
Florian Pose <fp@igh-essen.com>
parents: 2435
diff changeset
  4422
                ret = -EPERM;
9c3e629a220c Added API for querying CoE emergency requests.
Florian Pose <fp@igh-essen.com>
parents: 2435
diff changeset
  4423
                break;
9c3e629a220c Added API for querying CoE emergency requests.
Florian Pose <fp@igh-essen.com>
parents: 2435
diff changeset
  4424
            }
9c3e629a220c Added API for querying CoE emergency requests.
Florian Pose <fp@igh-essen.com>
parents: 2435
diff changeset
  4425
            ret = ec_ioctl_sc_emerg_pop(master, arg, ctx);
9c3e629a220c Added API for querying CoE emergency requests.
Florian Pose <fp@igh-essen.com>
parents: 2435
diff changeset
  4426
            break;
9c3e629a220c Added API for querying CoE emergency requests.
Florian Pose <fp@igh-essen.com>
parents: 2435
diff changeset
  4427
        case EC_IOCTL_SC_EMERG_CLEAR:
9c3e629a220c Added API for querying CoE emergency requests.
Florian Pose <fp@igh-essen.com>
parents: 2435
diff changeset
  4428
            if (!ctx->writable) {
9c3e629a220c Added API for querying CoE emergency requests.
Florian Pose <fp@igh-essen.com>
parents: 2435
diff changeset
  4429
                ret = -EPERM;
9c3e629a220c Added API for querying CoE emergency requests.
Florian Pose <fp@igh-essen.com>
parents: 2435
diff changeset
  4430
                break;
9c3e629a220c Added API for querying CoE emergency requests.
Florian Pose <fp@igh-essen.com>
parents: 2435
diff changeset
  4431
            }
9c3e629a220c Added API for querying CoE emergency requests.
Florian Pose <fp@igh-essen.com>
parents: 2435
diff changeset
  4432
            ret = ec_ioctl_sc_emerg_clear(master, arg, ctx);
9c3e629a220c Added API for querying CoE emergency requests.
Florian Pose <fp@igh-essen.com>
parents: 2435
diff changeset
  4433
            break;
9c3e629a220c Added API for querying CoE emergency requests.
Florian Pose <fp@igh-essen.com>
parents: 2435
diff changeset
  4434
        case EC_IOCTL_SC_EMERG_OVERRUNS:
9c3e629a220c Added API for querying CoE emergency requests.
Florian Pose <fp@igh-essen.com>
parents: 2435
diff changeset
  4435
            ret = ec_ioctl_sc_emerg_overruns(master, arg, ctx);
9c3e629a220c Added API for querying CoE emergency requests.
Florian Pose <fp@igh-essen.com>
parents: 2435
diff changeset
  4436
            break;
2433
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4437
        case EC_IOCTL_SC_SDO_REQUEST:
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4438
            if (!ctx->writable) {
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4439
                ret = -EPERM;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4440
                break;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4441
            }
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4442
            ret = ec_ioctl_sc_create_sdo_request(master, arg, ctx);
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4443
            break;
2443
2c3ccdde3919 Added interface to read/write register contents; re-worked register requests.
Florian Pose <fp@igh-essen.com>
parents: 2438
diff changeset
  4444
        case EC_IOCTL_SC_REG_REQUEST:
2c3ccdde3919 Added interface to read/write register contents; re-worked register requests.
Florian Pose <fp@igh-essen.com>
parents: 2438
diff changeset
  4445
            if (!ctx->writable) {
2c3ccdde3919 Added interface to read/write register contents; re-worked register requests.
Florian Pose <fp@igh-essen.com>
parents: 2438
diff changeset
  4446
                ret = -EPERM;
2c3ccdde3919 Added interface to read/write register contents; re-worked register requests.
Florian Pose <fp@igh-essen.com>
parents: 2438
diff changeset
  4447
                break;
2c3ccdde3919 Added interface to read/write register contents; re-worked register requests.
Florian Pose <fp@igh-essen.com>
parents: 2438
diff changeset
  4448
            }
2c3ccdde3919 Added interface to read/write register contents; re-worked register requests.
Florian Pose <fp@igh-essen.com>
parents: 2438
diff changeset
  4449
            ret = ec_ioctl_sc_create_reg_request(master, arg, ctx);
2c3ccdde3919 Added interface to read/write register contents; re-worked register requests.
Florian Pose <fp@igh-essen.com>
parents: 2438
diff changeset
  4450
            break;
2433
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4451
        case EC_IOCTL_SC_VOE:
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4452
            if (!ctx->writable) {
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4453
                ret = -EPERM;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4454
                break;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4455
            }
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4456
            ret = ec_ioctl_sc_create_voe_handler(master, arg, ctx);
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4457
            break;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4458
        case EC_IOCTL_SC_STATE:
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4459
            ret = ec_ioctl_sc_state(master, arg, ctx);
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4460
            break;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4461
        case EC_IOCTL_SC_IDN:
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4462
            if (!ctx->writable) {
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4463
                ret = -EPERM;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4464
                break;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4465
            }
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4466
            ret = ec_ioctl_sc_idn(master, arg, ctx);
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4467
            break;
2504
5ef9d5b14879 Exported ecrt_domain_size() for userspace.
Florian Pose <fp@igh-essen.com>
parents: 2498
diff changeset
  4468
        case EC_IOCTL_DOMAIN_SIZE:
5ef9d5b14879 Exported ecrt_domain_size() for userspace.
Florian Pose <fp@igh-essen.com>
parents: 2498
diff changeset
  4469
            ret = ec_ioctl_domain_size(master, arg, ctx);
5ef9d5b14879 Exported ecrt_domain_size() for userspace.
Florian Pose <fp@igh-essen.com>
parents: 2498
diff changeset
  4470
            break;
2433
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4471
        case EC_IOCTL_DOMAIN_OFFSET:
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4472
            ret = ec_ioctl_domain_offset(master, arg, ctx);
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4473
            break;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4474
        case EC_IOCTL_DOMAIN_PROCESS:
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4475
            if (!ctx->writable) {
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4476
                ret = -EPERM;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4477
                break;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4478
            }
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4479
            ret = ec_ioctl_domain_process(master, arg, ctx);
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4480
            break;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4481
        case EC_IOCTL_DOMAIN_QUEUE:
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4482
            if (!ctx->writable) {
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4483
                ret = -EPERM;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4484
                break;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4485
            }
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4486
            ret = ec_ioctl_domain_queue(master, arg, ctx);
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4487
            break;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4488
        case EC_IOCTL_DOMAIN_STATE:
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4489
            ret = ec_ioctl_domain_state(master, arg, ctx);
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4490
            break;
2434
fa52128477f6 Added ecrt_sdo_request_index() method to change index and subindex.
Florian Pose <fp@igh-essen.com>
parents: 2433
diff changeset
  4491
        case EC_IOCTL_SDO_REQUEST_INDEX:
fa52128477f6 Added ecrt_sdo_request_index() method to change index and subindex.
Florian Pose <fp@igh-essen.com>
parents: 2433
diff changeset
  4492
            if (!ctx->writable) {
fa52128477f6 Added ecrt_sdo_request_index() method to change index and subindex.
Florian Pose <fp@igh-essen.com>
parents: 2433
diff changeset
  4493
                ret = -EPERM;
fa52128477f6 Added ecrt_sdo_request_index() method to change index and subindex.
Florian Pose <fp@igh-essen.com>
parents: 2433
diff changeset
  4494
                break;
fa52128477f6 Added ecrt_sdo_request_index() method to change index and subindex.
Florian Pose <fp@igh-essen.com>
parents: 2433
diff changeset
  4495
            }
fa52128477f6 Added ecrt_sdo_request_index() method to change index and subindex.
Florian Pose <fp@igh-essen.com>
parents: 2433
diff changeset
  4496
            ret = ec_ioctl_sdo_request_index(master, arg, ctx);
fa52128477f6 Added ecrt_sdo_request_index() method to change index and subindex.
Florian Pose <fp@igh-essen.com>
parents: 2433
diff changeset
  4497
            break;
2433
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4498
        case EC_IOCTL_SDO_REQUEST_TIMEOUT:
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4499
            if (!ctx->writable) {
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4500
                ret = -EPERM;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4501
                break;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4502
            }
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4503
            ret = ec_ioctl_sdo_request_timeout(master, arg, ctx);
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4504
            break;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4505
        case EC_IOCTL_SDO_REQUEST_STATE:
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4506
            ret = ec_ioctl_sdo_request_state(master, arg, ctx);
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4507
            break;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4508
        case EC_IOCTL_SDO_REQUEST_READ:
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4509
            if (!ctx->writable) {
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4510
                ret = -EPERM;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4511
                break;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4512
            }
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4513
            ret = ec_ioctl_sdo_request_read(master, arg, ctx);
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4514
            break;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4515
        case EC_IOCTL_SDO_REQUEST_WRITE:
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4516
            if (!ctx->writable) {
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4517
                ret = -EPERM;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4518
                break;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4519
            }
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4520
            ret = ec_ioctl_sdo_request_write(master, arg, ctx);
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4521
            break;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4522
        case EC_IOCTL_SDO_REQUEST_DATA:
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4523
            ret = ec_ioctl_sdo_request_data(master, arg, ctx);
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4524
            break;
2443
2c3ccdde3919 Added interface to read/write register contents; re-worked register requests.
Florian Pose <fp@igh-essen.com>
parents: 2438
diff changeset
  4525
        case EC_IOCTL_REG_REQUEST_DATA:
2c3ccdde3919 Added interface to read/write register contents; re-worked register requests.
Florian Pose <fp@igh-essen.com>
parents: 2438
diff changeset
  4526
            ret = ec_ioctl_reg_request_data(master, arg, ctx);
2c3ccdde3919 Added interface to read/write register contents; re-worked register requests.
Florian Pose <fp@igh-essen.com>
parents: 2438
diff changeset
  4527
            break;
2c3ccdde3919 Added interface to read/write register contents; re-worked register requests.
Florian Pose <fp@igh-essen.com>
parents: 2438
diff changeset
  4528
        case EC_IOCTL_REG_REQUEST_STATE:
2c3ccdde3919 Added interface to read/write register contents; re-worked register requests.
Florian Pose <fp@igh-essen.com>
parents: 2438
diff changeset
  4529
            ret = ec_ioctl_reg_request_state(master, arg, ctx);
2c3ccdde3919 Added interface to read/write register contents; re-worked register requests.
Florian Pose <fp@igh-essen.com>
parents: 2438
diff changeset
  4530
            break;
2c3ccdde3919 Added interface to read/write register contents; re-worked register requests.
Florian Pose <fp@igh-essen.com>
parents: 2438
diff changeset
  4531
        case EC_IOCTL_REG_REQUEST_WRITE:
2c3ccdde3919 Added interface to read/write register contents; re-worked register requests.
Florian Pose <fp@igh-essen.com>
parents: 2438
diff changeset
  4532
            if (!ctx->writable) {
2c3ccdde3919 Added interface to read/write register contents; re-worked register requests.
Florian Pose <fp@igh-essen.com>
parents: 2438
diff changeset
  4533
                ret = -EPERM;
2c3ccdde3919 Added interface to read/write register contents; re-worked register requests.
Florian Pose <fp@igh-essen.com>
parents: 2438
diff changeset
  4534
                break;
2c3ccdde3919 Added interface to read/write register contents; re-worked register requests.
Florian Pose <fp@igh-essen.com>
parents: 2438
diff changeset
  4535
            }
2c3ccdde3919 Added interface to read/write register contents; re-worked register requests.
Florian Pose <fp@igh-essen.com>
parents: 2438
diff changeset
  4536
            ret = ec_ioctl_reg_request_write(master, arg, ctx);
2c3ccdde3919 Added interface to read/write register contents; re-worked register requests.
Florian Pose <fp@igh-essen.com>
parents: 2438
diff changeset
  4537
            break;
2c3ccdde3919 Added interface to read/write register contents; re-worked register requests.
Florian Pose <fp@igh-essen.com>
parents: 2438
diff changeset
  4538
        case EC_IOCTL_REG_REQUEST_READ:
2c3ccdde3919 Added interface to read/write register contents; re-worked register requests.
Florian Pose <fp@igh-essen.com>
parents: 2438
diff changeset
  4539
            if (!ctx->writable) {
2c3ccdde3919 Added interface to read/write register contents; re-worked register requests.
Florian Pose <fp@igh-essen.com>
parents: 2438
diff changeset
  4540
                ret = -EPERM;
2c3ccdde3919 Added interface to read/write register contents; re-worked register requests.
Florian Pose <fp@igh-essen.com>
parents: 2438
diff changeset
  4541
                break;
2c3ccdde3919 Added interface to read/write register contents; re-worked register requests.
Florian Pose <fp@igh-essen.com>
parents: 2438
diff changeset
  4542
            }
2c3ccdde3919 Added interface to read/write register contents; re-worked register requests.
Florian Pose <fp@igh-essen.com>
parents: 2438
diff changeset
  4543
            ret = ec_ioctl_reg_request_read(master, arg, ctx);
2c3ccdde3919 Added interface to read/write register contents; re-worked register requests.
Florian Pose <fp@igh-essen.com>
parents: 2438
diff changeset
  4544
            break;
2433
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4545
        case EC_IOCTL_VOE_SEND_HEADER:
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4546
            if (!ctx->writable) {
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4547
                ret = -EPERM;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4548
                break;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4549
            }
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4550
            ret = ec_ioctl_voe_send_header(master, arg, ctx);
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4551
            break;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4552
        case EC_IOCTL_VOE_REC_HEADER:
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4553
            ret = ec_ioctl_voe_rec_header(master, arg, ctx);
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4554
            break;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4555
        case EC_IOCTL_VOE_READ:
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4556
            if (!ctx->writable) {
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4557
                ret = -EPERM;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4558
                break;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4559
            }
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4560
            ret = ec_ioctl_voe_read(master, arg, ctx);
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4561
            break;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4562
        case EC_IOCTL_VOE_READ_NOSYNC:
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4563
            if (!ctx->writable) {
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4564
                ret = -EPERM;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4565
                break;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4566
            }
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4567
            ret = ec_ioctl_voe_read_nosync(master, arg, ctx);
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4568
            break;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4569
        case EC_IOCTL_VOE_WRITE:
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4570
            if (!ctx->writable) {
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4571
                ret = -EPERM;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4572
                break;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4573
            }
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4574
            ret = ec_ioctl_voe_write(master, arg, ctx);
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4575
            break;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4576
        case EC_IOCTL_VOE_EXEC:
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4577
            if (!ctx->writable) {
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4578
                ret = -EPERM;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4579
                break;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4580
            }
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4581
            ret = ec_ioctl_voe_exec(master, arg, ctx);
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4582
            break;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4583
        case EC_IOCTL_VOE_DATA:
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4584
            ret = ec_ioctl_voe_data(master, arg, ctx);
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4585
            break;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4586
        case EC_IOCTL_SET_SEND_INTERVAL:
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4587
            if (!ctx->writable) {
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4588
                ret = -EPERM;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4589
                break;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4590
            }
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4591
            ret = ec_ioctl_set_send_interval(master, arg, ctx);
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4592
            break;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4593
        default:
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4594
            ret = -ENOTTY;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4595
            break;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4596
    }
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4597
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4598
#if DEBUG_LATENCY
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4599
    b = get_cycles();
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4600
    t = (unsigned int) ((b - a) * 1000LL) / cpu_khz;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4601
    if (t > 50) {
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4602
        EC_MASTER_WARN(master, "ioctl(0x%02x) took %u us.\n",
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4603
                _IOC_NR(cmd), t);
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4604
    }
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4605
#endif
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4606
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4607
    return ret;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4608
}
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4609
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  4610
/*****************************************************************************/