master/cdev.c
author Christoph Mathys <ch1010832@ch10pc602>
Thu, 04 Nov 2010 09:32:58 +0100
branchstable-1.5
changeset 2198 190791fd47d2
parent 2180 912d70d6f0e5
child 2258 79269cfe25a7
permissions -rw-r--r--
Added e1000 port for 2.6.31
922
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     1
/******************************************************************************
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     2
 *
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     3
 *  $Id$
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     4
 *
1326
ef907b0b5125 merge -c1603 branches/stable-1.4: Changed licence headers to avoid conflicts with the GPL; restricted licence to GPLv2 only.
Florian Pose <fp@igh-essen.com>
parents: 1314
diff changeset
     5
 *  Copyright (C) 2006-2008  Florian Pose, Ingenieurgemeinschaft IgH
922
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     6
 *
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     7
 *  This file is part of the IgH EtherCAT Master.
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     8
 *
1326
ef907b0b5125 merge -c1603 branches/stable-1.4: Changed licence headers to avoid conflicts with the GPL; restricted licence to GPLv2 only.
Florian Pose <fp@igh-essen.com>
parents: 1314
diff changeset
     9
 *  The IgH EtherCAT Master is free software; you can redistribute it and/or
ef907b0b5125 merge -c1603 branches/stable-1.4: Changed licence headers to avoid conflicts with the GPL; restricted licence to GPLv2 only.
Florian Pose <fp@igh-essen.com>
parents: 1314
diff changeset
    10
 *  modify it under the terms of the GNU General Public License version 2, as
ef907b0b5125 merge -c1603 branches/stable-1.4: Changed licence headers to avoid conflicts with the GPL; restricted licence to GPLv2 only.
Florian Pose <fp@igh-essen.com>
parents: 1314
diff changeset
    11
 *  published by the Free Software Foundation.
922
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    12
 *
1326
ef907b0b5125 merge -c1603 branches/stable-1.4: Changed licence headers to avoid conflicts with the GPL; restricted licence to GPLv2 only.
Florian Pose <fp@igh-essen.com>
parents: 1314
diff changeset
    13
 *  The IgH EtherCAT Master is distributed in the hope that it will be useful,
ef907b0b5125 merge -c1603 branches/stable-1.4: Changed licence headers to avoid conflicts with the GPL; restricted licence to GPLv2 only.
Florian Pose <fp@igh-essen.com>
parents: 1314
diff changeset
    14
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
ef907b0b5125 merge -c1603 branches/stable-1.4: Changed licence headers to avoid conflicts with the GPL; restricted licence to GPLv2 only.
Florian Pose <fp@igh-essen.com>
parents: 1314
diff changeset
    15
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General
ef907b0b5125 merge -c1603 branches/stable-1.4: Changed licence headers to avoid conflicts with the GPL; restricted licence to GPLv2 only.
Florian Pose <fp@igh-essen.com>
parents: 1314
diff changeset
    16
 *  Public License for more details.
922
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    17
 *
1326
ef907b0b5125 merge -c1603 branches/stable-1.4: Changed licence headers to avoid conflicts with the GPL; restricted licence to GPLv2 only.
Florian Pose <fp@igh-essen.com>
parents: 1314
diff changeset
    18
 *  You should have received a copy of the GNU General Public License along
ef907b0b5125 merge -c1603 branches/stable-1.4: Changed licence headers to avoid conflicts with the GPL; restricted licence to GPLv2 only.
Florian Pose <fp@igh-essen.com>
parents: 1314
diff changeset
    19
 *  with the IgH EtherCAT Master; if not, write to the Free Software
922
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    20
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    21
 *
1363
11c0b2caa253 Improved and added license headers.
Florian Pose <fp@igh-essen.com>
parents: 1362
diff changeset
    22
 *  ---
11c0b2caa253 Improved and added license headers.
Florian Pose <fp@igh-essen.com>
parents: 1362
diff changeset
    23
 *
11c0b2caa253 Improved and added license headers.
Florian Pose <fp@igh-essen.com>
parents: 1362
diff changeset
    24
 *  The license mentioned above concerns the source code only. Using the
11c0b2caa253 Improved and added license headers.
Florian Pose <fp@igh-essen.com>
parents: 1362
diff changeset
    25
 *  EtherCAT technology and brand is only permitted in compliance with the
11c0b2caa253 Improved and added license headers.
Florian Pose <fp@igh-essen.com>
parents: 1362
diff changeset
    26
 *  industrial property and similar rights of Beckhoff Automation GmbH.
922
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    27
 *
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    28
 *****************************************************************************/
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    29
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    30
/**
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    31
   \file
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    32
   EtherCAT master character device.
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    33
*/
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    34
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    35
/*****************************************************************************/
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    36
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    37
#include <linux/module.h>
1258
900f1124e8f8 Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents: 1255
diff changeset
    38
#include <linux/vmalloc.h>
900f1124e8f8 Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents: 1255
diff changeset
    39
#include <linux/mm.h>
922
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    40
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    41
#include "cdev.h"
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    42
#include "master.h"
950
8b00e63fff90 'ethercat domain' shows domain contents and process data.
Florian Pose <fp@igh-essen.com>
parents: 949
diff changeset
    43
#include "slave_config.h"
1264
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
    44
#include "voe_handler.h"
1485
5ddc3a455059 ethercat eoe command.
Florian Pose <fp@igh-essen.com>
parents: 1465
diff changeset
    45
#include "ethernet.h"
922
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    46
#include "ioctl.h"
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    47
1465
3099d78343ea Added documentation.
Florian Pose <fp@igh-essen.com>
parents: 1455
diff changeset
    48
/** Set to 1 to enable ioctl() command debugging.
3099d78343ea Added documentation.
Florian Pose <fp@igh-essen.com>
parents: 1455
diff changeset
    49
 */
1397
6f9294a445c1 Introduced DEBUG_IOCTL.
Florian Pose <fp@igh-essen.com>
parents: 1388
diff changeset
    50
#define DEBUG_IOCTL 0
6f9294a445c1 Introduced DEBUG_IOCTL.
Florian Pose <fp@igh-essen.com>
parents: 1388
diff changeset
    51
2180
912d70d6f0e5 Removed some locks causing latency when using the library; added ioctl()
Florian Pose <fp@igh-essen.com>
parents: 2124
diff changeset
    52
/** Set to 1 to enable ioctl() latency warnings.
912d70d6f0e5 Removed some locks causing latency when using the library; added ioctl()
Florian Pose <fp@igh-essen.com>
parents: 2124
diff changeset
    53
 *
912d70d6f0e5 Removed some locks causing latency when using the library; added ioctl()
Florian Pose <fp@igh-essen.com>
parents: 2124
diff changeset
    54
 * Requires CPU timestamp counter!
912d70d6f0e5 Removed some locks causing latency when using the library; added ioctl()
Florian Pose <fp@igh-essen.com>
parents: 2124
diff changeset
    55
 */
912d70d6f0e5 Removed some locks causing latency when using the library; added ioctl()
Florian Pose <fp@igh-essen.com>
parents: 2124
diff changeset
    56
#define DEBUG_LATENCY 0
912d70d6f0e5 Removed some locks causing latency when using the library; added ioctl()
Florian Pose <fp@igh-essen.com>
parents: 2124
diff changeset
    57
922
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    58
/*****************************************************************************/
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    59
1268
d9599395e89b Maintained code docs.
Florian Pose <fp@igh-essen.com>
parents: 1264
diff changeset
    60
static int eccdev_open(struct inode *, struct file *);
d9599395e89b Maintained code docs.
Florian Pose <fp@igh-essen.com>
parents: 1264
diff changeset
    61
static int eccdev_release(struct inode *, struct file *);
d9599395e89b Maintained code docs.
Florian Pose <fp@igh-essen.com>
parents: 1264
diff changeset
    62
static long eccdev_ioctl(struct file *, unsigned int, unsigned long);
d9599395e89b Maintained code docs.
Florian Pose <fp@igh-essen.com>
parents: 1264
diff changeset
    63
static int eccdev_mmap(struct file *, struct vm_area_struct *);
1258
900f1124e8f8 Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents: 1255
diff changeset
    64
1272
288c982acd23 Use .fault handler instead of .nopage handler from 2.6.23.
Florian Pose <fp@igh-essen.com>
parents: 1268
diff changeset
    65
/** This is the kernel version from which the .fault member of the
288c982acd23 Use .fault handler instead of .nopage handler from 2.6.23.
Florian Pose <fp@igh-essen.com>
parents: 1268
diff changeset
    66
 * vm_operations_struct is usable.
288c982acd23 Use .fault handler instead of .nopage handler from 2.6.23.
Florian Pose <fp@igh-essen.com>
parents: 1268
diff changeset
    67
 */
288c982acd23 Use .fault handler instead of .nopage handler from 2.6.23.
Florian Pose <fp@igh-essen.com>
parents: 1268
diff changeset
    68
#define PAGE_FAULT_VERSION KERNEL_VERSION(2, 6, 23)
288c982acd23 Use .fault handler instead of .nopage handler from 2.6.23.
Florian Pose <fp@igh-essen.com>
parents: 1268
diff changeset
    69
288c982acd23 Use .fault handler instead of .nopage handler from 2.6.23.
Florian Pose <fp@igh-essen.com>
parents: 1268
diff changeset
    70
#if LINUX_VERSION_CODE >= PAGE_FAULT_VERSION
288c982acd23 Use .fault handler instead of .nopage handler from 2.6.23.
Florian Pose <fp@igh-essen.com>
parents: 1268
diff changeset
    71
static int eccdev_vma_fault(struct vm_area_struct *, struct vm_fault *);
288c982acd23 Use .fault handler instead of .nopage handler from 2.6.23.
Florian Pose <fp@igh-essen.com>
parents: 1268
diff changeset
    72
#else
1258
900f1124e8f8 Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents: 1255
diff changeset
    73
static struct page *eccdev_vma_nopage(
900f1124e8f8 Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents: 1255
diff changeset
    74
        struct vm_area_struct *, unsigned long, int *);
1272
288c982acd23 Use .fault handler instead of .nopage handler from 2.6.23.
Florian Pose <fp@igh-essen.com>
parents: 1268
diff changeset
    75
#endif
922
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    76
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    77
/*****************************************************************************/
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    78
1268
d9599395e89b Maintained code docs.
Florian Pose <fp@igh-essen.com>
parents: 1264
diff changeset
    79
/** File operation callbacks for the EtherCAT character device.
d9599395e89b Maintained code docs.
Florian Pose <fp@igh-essen.com>
parents: 1264
diff changeset
    80
 */
922
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    81
static struct file_operations eccdev_fops = {
935
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
    82
    .owner          = THIS_MODULE,
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
    83
    .open           = eccdev_open,
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
    84
    .release        = eccdev_release,
1258
900f1124e8f8 Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents: 1255
diff changeset
    85
    .unlocked_ioctl = eccdev_ioctl,
900f1124e8f8 Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents: 1255
diff changeset
    86
    .mmap           = eccdev_mmap
900f1124e8f8 Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents: 1255
diff changeset
    87
};
900f1124e8f8 Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents: 1255
diff changeset
    88
1268
d9599395e89b Maintained code docs.
Florian Pose <fp@igh-essen.com>
parents: 1264
diff changeset
    89
/** Callbacks for a virtual memory area retrieved with ecdevc_mmap().
d9599395e89b Maintained code docs.
Florian Pose <fp@igh-essen.com>
parents: 1264
diff changeset
    90
 */
1258
900f1124e8f8 Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents: 1255
diff changeset
    91
struct vm_operations_struct eccdev_vm_ops = {
1272
288c982acd23 Use .fault handler instead of .nopage handler from 2.6.23.
Florian Pose <fp@igh-essen.com>
parents: 1268
diff changeset
    92
#if LINUX_VERSION_CODE >= PAGE_FAULT_VERSION
288c982acd23 Use .fault handler instead of .nopage handler from 2.6.23.
Florian Pose <fp@igh-essen.com>
parents: 1268
diff changeset
    93
    .fault = eccdev_vma_fault
288c982acd23 Use .fault handler instead of .nopage handler from 2.6.23.
Florian Pose <fp@igh-essen.com>
parents: 1268
diff changeset
    94
#else
1258
900f1124e8f8 Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents: 1255
diff changeset
    95
    .nopage = eccdev_vma_nopage
1272
288c982acd23 Use .fault handler instead of .nopage handler from 2.6.23.
Florian Pose <fp@igh-essen.com>
parents: 1268
diff changeset
    96
#endif
922
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    97
};
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    98
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    99
/*****************************************************************************/
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   100
1242
632a6b91f8e4 First version of userspace library with requesting/releasing.
Florian Pose <fp@igh-essen.com>
parents: 1223
diff changeset
   101
/** Private data structure for file handles.
632a6b91f8e4 First version of userspace library with requesting/releasing.
Florian Pose <fp@igh-essen.com>
parents: 1223
diff changeset
   102
 */
632a6b91f8e4 First version of userspace library with requesting/releasing.
Florian Pose <fp@igh-essen.com>
parents: 1223
diff changeset
   103
typedef struct {
1268
d9599395e89b Maintained code docs.
Florian Pose <fp@igh-essen.com>
parents: 1264
diff changeset
   104
    ec_cdev_t *cdev; /**< Character device. */
d9599395e89b Maintained code docs.
Florian Pose <fp@igh-essen.com>
parents: 1264
diff changeset
   105
    unsigned int requested; /**< Master wac requested via this file handle. */
d9599395e89b Maintained code docs.
Florian Pose <fp@igh-essen.com>
parents: 1264
diff changeset
   106
    uint8_t *process_data; /**< Total process data area. */
d9599395e89b Maintained code docs.
Florian Pose <fp@igh-essen.com>
parents: 1264
diff changeset
   107
    size_t process_data_size; /**< Size of the \a process_data. */
1242
632a6b91f8e4 First version of userspace library with requesting/releasing.
Florian Pose <fp@igh-essen.com>
parents: 1223
diff changeset
   108
} ec_cdev_priv_t;
632a6b91f8e4 First version of userspace library with requesting/releasing.
Florian Pose <fp@igh-essen.com>
parents: 1223
diff changeset
   109
632a6b91f8e4 First version of userspace library with requesting/releasing.
Florian Pose <fp@igh-essen.com>
parents: 1223
diff changeset
   110
/*****************************************************************************/
632a6b91f8e4 First version of userspace library with requesting/releasing.
Florian Pose <fp@igh-essen.com>
parents: 1223
diff changeset
   111
922
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   112
/** Constructor.
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   113
 * 
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   114
 * \return 0 in case of success, else < 0
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   115
 */
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   116
int ec_cdev_init(
1507
68e89abadd19 Removed unwanted tabulators.
Florian Pose <fp@igh-essen.com>
parents: 1500
diff changeset
   117
        ec_cdev_t *cdev, /**< EtherCAT master character device. */
68e89abadd19 Removed unwanted tabulators.
Florian Pose <fp@igh-essen.com>
parents: 1500
diff changeset
   118
        ec_master_t *master, /**< Parent master. */
68e89abadd19 Removed unwanted tabulators.
Florian Pose <fp@igh-essen.com>
parents: 1500
diff changeset
   119
        dev_t dev_num /**< Device number. */
68e89abadd19 Removed unwanted tabulators.
Florian Pose <fp@igh-essen.com>
parents: 1500
diff changeset
   120
        )
922
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   121
{
1313
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1312
diff changeset
   122
    int ret;
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1312
diff changeset
   123
922
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   124
    cdev->master = master;
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   125
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   126
    cdev_init(&cdev->cdev, &eccdev_fops);
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   127
    cdev->cdev.owner = THIS_MODULE;
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   128
1313
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1312
diff changeset
   129
    ret = cdev_add(&cdev->cdev,
1507
68e89abadd19 Removed unwanted tabulators.
Florian Pose <fp@igh-essen.com>
parents: 1500
diff changeset
   130
            MKDEV(MAJOR(dev_num), master->index), 1);
1313
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1312
diff changeset
   131
    if (ret) {
1921
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1909
diff changeset
   132
        EC_MASTER_ERR(master, "Failed to add character device!\n");
1313
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1312
diff changeset
   133
    }
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1312
diff changeset
   134
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1312
diff changeset
   135
    return ret;
922
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   136
}
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   137
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   138
/*****************************************************************************/
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   139
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   140
/** Destructor.
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   141
 */
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   142
void ec_cdev_clear(ec_cdev_t *cdev /**< EtherCAT XML device */)
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   143
{
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   144
    cdev_del(&cdev->cdev);
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   145
}
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   146
1079
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   147
/*****************************************************************************/
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   148
1108
7beba3e7e6b4 Added ec_cdev_strcpy() function.
Florian Pose <fp@igh-essen.com>
parents: 1092
diff changeset
   149
/** Copies a string to an ioctl structure.
7beba3e7e6b4 Added ec_cdev_strcpy() function.
Florian Pose <fp@igh-essen.com>
parents: 1092
diff changeset
   150
 */
7beba3e7e6b4 Added ec_cdev_strcpy() function.
Florian Pose <fp@igh-essen.com>
parents: 1092
diff changeset
   151
void ec_cdev_strcpy(
7beba3e7e6b4 Added ec_cdev_strcpy() function.
Florian Pose <fp@igh-essen.com>
parents: 1092
diff changeset
   152
        char *target, /**< Target. */
7beba3e7e6b4 Added ec_cdev_strcpy() function.
Florian Pose <fp@igh-essen.com>
parents: 1092
diff changeset
   153
        const char *source /**< Source. */
7beba3e7e6b4 Added ec_cdev_strcpy() function.
Florian Pose <fp@igh-essen.com>
parents: 1092
diff changeset
   154
        )
7beba3e7e6b4 Added ec_cdev_strcpy() function.
Florian Pose <fp@igh-essen.com>
parents: 1092
diff changeset
   155
{
7beba3e7e6b4 Added ec_cdev_strcpy() function.
Florian Pose <fp@igh-essen.com>
parents: 1092
diff changeset
   156
    if (source) {
7beba3e7e6b4 Added ec_cdev_strcpy() function.
Florian Pose <fp@igh-essen.com>
parents: 1092
diff changeset
   157
        strncpy(target, source, EC_IOCTL_STRING_SIZE);
7beba3e7e6b4 Added ec_cdev_strcpy() function.
Florian Pose <fp@igh-essen.com>
parents: 1092
diff changeset
   158
        target[EC_IOCTL_STRING_SIZE - 1] = 0;
7beba3e7e6b4 Added ec_cdev_strcpy() function.
Florian Pose <fp@igh-essen.com>
parents: 1092
diff changeset
   159
    } else {
7beba3e7e6b4 Added ec_cdev_strcpy() function.
Florian Pose <fp@igh-essen.com>
parents: 1092
diff changeset
   160
        target[0] = 0;
7beba3e7e6b4 Added ec_cdev_strcpy() function.
Florian Pose <fp@igh-essen.com>
parents: 1092
diff changeset
   161
    }
7beba3e7e6b4 Added ec_cdev_strcpy() function.
Florian Pose <fp@igh-essen.com>
parents: 1092
diff changeset
   162
}
7beba3e7e6b4 Added ec_cdev_strcpy() function.
Florian Pose <fp@igh-essen.com>
parents: 1092
diff changeset
   163
7beba3e7e6b4 Added ec_cdev_strcpy() function.
Florian Pose <fp@igh-essen.com>
parents: 1092
diff changeset
   164
/*****************************************************************************/
7beba3e7e6b4 Added ec_cdev_strcpy() function.
Florian Pose <fp@igh-essen.com>
parents: 1092
diff changeset
   165
1826
ec6223c3b7ec Multi-master support for command-line tool. The --master option supports
Florian Pose <fp@igh-essen.com>
parents: 1804
diff changeset
   166
/** Get module information.
ec6223c3b7ec Multi-master support for command-line tool. The --master option supports
Florian Pose <fp@igh-essen.com>
parents: 1804
diff changeset
   167
 */
ec6223c3b7ec Multi-master support for command-line tool. The --master option supports
Florian Pose <fp@igh-essen.com>
parents: 1804
diff changeset
   168
int ec_cdev_ioctl_module(
ec6223c3b7ec Multi-master support for command-line tool. The --master option supports
Florian Pose <fp@igh-essen.com>
parents: 1804
diff changeset
   169
        unsigned long arg /**< Userspace address to store the results. */
ec6223c3b7ec Multi-master support for command-line tool. The --master option supports
Florian Pose <fp@igh-essen.com>
parents: 1804
diff changeset
   170
        )
ec6223c3b7ec Multi-master support for command-line tool. The --master option supports
Florian Pose <fp@igh-essen.com>
parents: 1804
diff changeset
   171
{
ec6223c3b7ec Multi-master support for command-line tool. The --master option supports
Florian Pose <fp@igh-essen.com>
parents: 1804
diff changeset
   172
    ec_ioctl_module_t data;
ec6223c3b7ec Multi-master support for command-line tool. The --master option supports
Florian Pose <fp@igh-essen.com>
parents: 1804
diff changeset
   173
ec6223c3b7ec Multi-master support for command-line tool. The --master option supports
Florian Pose <fp@igh-essen.com>
parents: 1804
diff changeset
   174
    data.ioctl_version_magic = EC_IOCTL_VERSION_MAGIC;
ec6223c3b7ec Multi-master support for command-line tool. The --master option supports
Florian Pose <fp@igh-essen.com>
parents: 1804
diff changeset
   175
    data.master_count = ec_master_count();
ec6223c3b7ec Multi-master support for command-line tool. The --master option supports
Florian Pose <fp@igh-essen.com>
parents: 1804
diff changeset
   176
ec6223c3b7ec Multi-master support for command-line tool. The --master option supports
Florian Pose <fp@igh-essen.com>
parents: 1804
diff changeset
   177
    if (copy_to_user((void __user *) arg, &data, sizeof(data)))
ec6223c3b7ec Multi-master support for command-line tool. The --master option supports
Florian Pose <fp@igh-essen.com>
parents: 1804
diff changeset
   178
        return -EFAULT;
ec6223c3b7ec Multi-master support for command-line tool. The --master option supports
Florian Pose <fp@igh-essen.com>
parents: 1804
diff changeset
   179
ec6223c3b7ec Multi-master support for command-line tool. The --master option supports
Florian Pose <fp@igh-essen.com>
parents: 1804
diff changeset
   180
    return 0;
ec6223c3b7ec Multi-master support for command-line tool. The --master option supports
Florian Pose <fp@igh-essen.com>
parents: 1804
diff changeset
   181
}
ec6223c3b7ec Multi-master support for command-line tool. The --master option supports
Florian Pose <fp@igh-essen.com>
parents: 1804
diff changeset
   182
ec6223c3b7ec Multi-master support for command-line tool. The --master option supports
Florian Pose <fp@igh-essen.com>
parents: 1804
diff changeset
   183
/*****************************************************************************/
ec6223c3b7ec Multi-master support for command-line tool. The --master option supports
Florian Pose <fp@igh-essen.com>
parents: 1804
diff changeset
   184
1079
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   185
/** Get master information.
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   186
 */
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   187
int ec_cdev_ioctl_master(
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   188
        ec_master_t *master, /**< EtherCAT master. */
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   189
        unsigned long arg /**< Userspace address to store the results. */
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   190
        )
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   191
{
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   192
    ec_ioctl_master_t data;
1851
a56bd34e20a1 Frame statistics in 'ethercat master' output.
Florian Pose <fp@igh-essen.com>
parents: 1839
diff changeset
   193
    unsigned int i;
1079
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   194
1189
acc6430bfb32 Use down_interruptible() wherever possible.
Florian Pose <fp@igh-essen.com>
parents: 1183
diff changeset
   195
    if (down_interruptible(&master->master_sem))
acc6430bfb32 Use down_interruptible() wherever possible.
Florian Pose <fp@igh-essen.com>
parents: 1183
diff changeset
   196
        return -EINTR;
1079
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   197
    data.slave_count = master->slave_count;
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   198
    data.config_count = ec_master_config_count(master);
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   199
    data.domain_count = ec_master_domain_count(master);
1516
e3b09f847512 Fixed compiler error on --disable-eoe.
Florian Pose <fp@igh-essen.com>
parents: 1513
diff changeset
   200
#ifdef EC_EOE
1485
5ddc3a455059 ethercat eoe command.
Florian Pose <fp@igh-essen.com>
parents: 1465
diff changeset
   201
    data.eoe_handler_count = ec_master_eoe_handler_count(master);
1516
e3b09f847512 Fixed compiler error on --disable-eoe.
Florian Pose <fp@igh-essen.com>
parents: 1513
diff changeset
   202
#endif
1079
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   203
    data.phase = (uint8_t) master->phase;
1530
96629de2202b Added ecrt_master_deactivate() to remove the bus configuration.
Florian Pose <fp@igh-essen.com>
parents: 1526
diff changeset
   204
    data.active = (uint8_t) master->active;
1447
846d75637c43 Added scan_busy flag to ioctl().
Florian Pose <fp@igh-essen.com>
parents: 1438
diff changeset
   205
    data.scan_busy = master->scan_busy;
1079
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   206
    up(&master->master_sem);
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   207
1189
acc6430bfb32 Use down_interruptible() wherever possible.
Florian Pose <fp@igh-essen.com>
parents: 1183
diff changeset
   208
    if (down_interruptible(&master->device_sem))
acc6430bfb32 Use down_interruptible() wherever possible.
Florian Pose <fp@igh-essen.com>
parents: 1183
diff changeset
   209
        return -EINTR;
1415
9d1cdbf41247 Output reference clock and application time in 'ethercat Master'.
Florian Pose <fp@igh-essen.com>
parents: 1413
diff changeset
   210
1162
51a8b41d3dbc Display real ethernet address.
Florian Pose <fp@igh-essen.com>
parents: 1150
diff changeset
   211
    if (master->main_device.dev) {
51a8b41d3dbc Display real ethernet address.
Florian Pose <fp@igh-essen.com>
parents: 1150
diff changeset
   212
        memcpy(data.devices[0].address,
51a8b41d3dbc Display real ethernet address.
Florian Pose <fp@igh-essen.com>
parents: 1150
diff changeset
   213
                master->main_device.dev->dev_addr, ETH_ALEN);
51a8b41d3dbc Display real ethernet address.
Florian Pose <fp@igh-essen.com>
parents: 1150
diff changeset
   214
    } else {
51a8b41d3dbc Display real ethernet address.
Florian Pose <fp@igh-essen.com>
parents: 1150
diff changeset
   215
        memcpy(data.devices[0].address, master->main_mac, ETH_ALEN); 
51a8b41d3dbc Display real ethernet address.
Florian Pose <fp@igh-essen.com>
parents: 1150
diff changeset
   216
    }
1079
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   217
    data.devices[0].attached = master->main_device.dev ? 1 : 0;
1401
96baef8a3162 Output link state in 'ethercat master'.
Florian Pose <fp@igh-essen.com>
parents: 1398
diff changeset
   218
    data.devices[0].link_state = master->main_device.link_state ? 1 : 0;
1079
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   219
    data.devices[0].tx_count = master->main_device.tx_count;
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   220
    data.devices[0].rx_count = master->main_device.rx_count;
1857
ed8b490b5bc3 Output tx errors and tx rate in byte/s.
Florian Pose <fp@igh-essen.com>
parents: 1851
diff changeset
   221
    data.devices[0].tx_bytes = master->main_device.tx_bytes;
ed8b490b5bc3 Output tx errors and tx rate in byte/s.
Florian Pose <fp@igh-essen.com>
parents: 1851
diff changeset
   222
    data.devices[0].tx_errors = master->main_device.tx_errors;
1851
a56bd34e20a1 Frame statistics in 'ethercat master' output.
Florian Pose <fp@igh-essen.com>
parents: 1839
diff changeset
   223
    for (i = 0; i < EC_RATE_COUNT; i++) {
1857
ed8b490b5bc3 Output tx errors and tx rate in byte/s.
Florian Pose <fp@igh-essen.com>
parents: 1851
diff changeset
   224
        data.devices[0].tx_frame_rates[i] =
ed8b490b5bc3 Output tx errors and tx rate in byte/s.
Florian Pose <fp@igh-essen.com>
parents: 1851
diff changeset
   225
            master->main_device.tx_frame_rates[i];
ed8b490b5bc3 Output tx errors and tx rate in byte/s.
Florian Pose <fp@igh-essen.com>
parents: 1851
diff changeset
   226
        data.devices[0].tx_byte_rates[i] =
ed8b490b5bc3 Output tx errors and tx rate in byte/s.
Florian Pose <fp@igh-essen.com>
parents: 1851
diff changeset
   227
            master->main_device.tx_byte_rates[i];
1851
a56bd34e20a1 Frame statistics in 'ethercat master' output.
Florian Pose <fp@igh-essen.com>
parents: 1839
diff changeset
   228
        data.devices[0].loss_rates[i] = master->main_device.loss_rates[i];
a56bd34e20a1 Frame statistics in 'ethercat master' output.
Florian Pose <fp@igh-essen.com>
parents: 1839
diff changeset
   229
    }
1162
51a8b41d3dbc Display real ethernet address.
Florian Pose <fp@igh-essen.com>
parents: 1150
diff changeset
   230
51a8b41d3dbc Display real ethernet address.
Florian Pose <fp@igh-essen.com>
parents: 1150
diff changeset
   231
    if (master->backup_device.dev) {
51a8b41d3dbc Display real ethernet address.
Florian Pose <fp@igh-essen.com>
parents: 1150
diff changeset
   232
        memcpy(data.devices[1].address,
51a8b41d3dbc Display real ethernet address.
Florian Pose <fp@igh-essen.com>
parents: 1150
diff changeset
   233
                master->backup_device.dev->dev_addr, ETH_ALEN); 
51a8b41d3dbc Display real ethernet address.
Florian Pose <fp@igh-essen.com>
parents: 1150
diff changeset
   234
    } else {
51a8b41d3dbc Display real ethernet address.
Florian Pose <fp@igh-essen.com>
parents: 1150
diff changeset
   235
        memcpy(data.devices[1].address, master->backup_mac, ETH_ALEN); 
51a8b41d3dbc Display real ethernet address.
Florian Pose <fp@igh-essen.com>
parents: 1150
diff changeset
   236
    }
1079
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   237
    data.devices[1].attached = master->backup_device.dev ? 1 : 0;
1401
96baef8a3162 Output link state in 'ethercat master'.
Florian Pose <fp@igh-essen.com>
parents: 1398
diff changeset
   238
    data.devices[1].link_state = master->backup_device.link_state ? 1 : 0;
1079
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   239
    data.devices[1].tx_count = master->backup_device.tx_count;
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   240
    data.devices[1].rx_count = master->backup_device.rx_count;
1857
ed8b490b5bc3 Output tx errors and tx rate in byte/s.
Florian Pose <fp@igh-essen.com>
parents: 1851
diff changeset
   241
    data.devices[1].tx_bytes = master->backup_device.tx_bytes;
ed8b490b5bc3 Output tx errors and tx rate in byte/s.
Florian Pose <fp@igh-essen.com>
parents: 1851
diff changeset
   242
    data.devices[1].tx_errors = master->backup_device.tx_errors;
1851
a56bd34e20a1 Frame statistics in 'ethercat master' output.
Florian Pose <fp@igh-essen.com>
parents: 1839
diff changeset
   243
    for (i = 0; i < EC_RATE_COUNT; i++) {
1857
ed8b490b5bc3 Output tx errors and tx rate in byte/s.
Florian Pose <fp@igh-essen.com>
parents: 1851
diff changeset
   244
        data.devices[1].tx_frame_rates[i] =
ed8b490b5bc3 Output tx errors and tx rate in byte/s.
Florian Pose <fp@igh-essen.com>
parents: 1851
diff changeset
   245
            master->backup_device.tx_frame_rates[i];
ed8b490b5bc3 Output tx errors and tx rate in byte/s.
Florian Pose <fp@igh-essen.com>
parents: 1851
diff changeset
   246
        data.devices[1].tx_byte_rates[i] =
ed8b490b5bc3 Output tx errors and tx rate in byte/s.
Florian Pose <fp@igh-essen.com>
parents: 1851
diff changeset
   247
            master->backup_device.tx_byte_rates[i];
1851
a56bd34e20a1 Frame statistics in 'ethercat master' output.
Florian Pose <fp@igh-essen.com>
parents: 1839
diff changeset
   248
        data.devices[1].loss_rates[i] = master->backup_device.loss_rates[i];
a56bd34e20a1 Frame statistics in 'ethercat master' output.
Florian Pose <fp@igh-essen.com>
parents: 1839
diff changeset
   249
    }
1415
9d1cdbf41247 Output reference clock and application time in 'ethercat Master'.
Florian Pose <fp@igh-essen.com>
parents: 1413
diff changeset
   250
1079
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   251
    up(&master->device_sem);
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   252
1415
9d1cdbf41247 Output reference clock and application time in 'ethercat Master'.
Florian Pose <fp@igh-essen.com>
parents: 1413
diff changeset
   253
    data.app_time = master->app_time;
1435
f1df39224f49 Take ref clock address from dc_ref_clock pointer.
Florian Pose <fp@igh-essen.com>
parents: 1434
diff changeset
   254
    data.ref_clock =
f1df39224f49 Take ref clock address from dc_ref_clock pointer.
Florian Pose <fp@igh-essen.com>
parents: 1434
diff changeset
   255
        master->dc_ref_clock ? master->dc_ref_clock->ring_position : 0xffff;
1415
9d1cdbf41247 Output reference clock and application time in 'ethercat Master'.
Florian Pose <fp@igh-essen.com>
parents: 1413
diff changeset
   256
1079
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   257
    if (copy_to_user((void __user *) arg, &data, sizeof(data)))
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   258
        return -EFAULT;
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   259
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   260
    return 0;
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   261
}
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   262
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   263
/*****************************************************************************/
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   264
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   265
/** Get slave information.
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   266
 */
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   267
int ec_cdev_ioctl_slave(
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   268
        ec_master_t *master, /**< EtherCAT master. */
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   269
        unsigned long arg /**< Userspace address to store the results. */
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   270
        )
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   271
{
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   272
    ec_ioctl_slave_t data;
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   273
    const ec_slave_t *slave;
1379
cbceb0e2f2a0 Reading more base information (incl. whether DC supported).
Florian Pose <fp@igh-essen.com>
parents: 1363
diff changeset
   274
    int i;
1079
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   275
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   276
    if (copy_from_user(&data, (void __user *) arg, sizeof(data))) {
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   277
        return -EFAULT;
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   278
    }
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   279
1189
acc6430bfb32 Use down_interruptible() wherever possible.
Florian Pose <fp@igh-essen.com>
parents: 1183
diff changeset
   280
    if (down_interruptible(&master->master_sem))
acc6430bfb32 Use down_interruptible() wherever possible.
Florian Pose <fp@igh-essen.com>
parents: 1183
diff changeset
   281
        return -EINTR;
1079
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   282
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   283
    if (!(slave = ec_master_find_slave_const(
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   284
                    master, 0, data.position))) {
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   285
        up(&master->master_sem);
1921
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1909
diff changeset
   286
        EC_MASTER_ERR(master, "Slave %u does not exist!\n", data.position);
1079
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   287
        return -EINVAL;
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   288
    }
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   289
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   290
    data.vendor_id = slave->sii.vendor_id;
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   291
    data.product_code = slave->sii.product_code;
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   292
    data.revision_number = slave->sii.revision_number;
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   293
    data.serial_number = slave->sii.serial_number;
1909
ea3eb4c74c1b Introduced effective_alias variable to separate reg12 alias from SII alias.
Florian Pose <fp@igh-essen.com>
parents: 1862
diff changeset
   294
    data.alias = slave->effective_alias;
1337
0253c74d0940 merge -c1619 branches/1.4-foe: Implemented going to bootstrap state BOOT.
Florian Pose <fp@igh-essen.com>
parents: 1336
diff changeset
   295
    data.boot_rx_mailbox_offset = slave->sii.boot_rx_mailbox_offset;
0253c74d0940 merge -c1619 branches/1.4-foe: Implemented going to bootstrap state BOOT.
Florian Pose <fp@igh-essen.com>
parents: 1336
diff changeset
   296
    data.boot_rx_mailbox_size = slave->sii.boot_rx_mailbox_size;
0253c74d0940 merge -c1619 branches/1.4-foe: Implemented going to bootstrap state BOOT.
Florian Pose <fp@igh-essen.com>
parents: 1336
diff changeset
   297
    data.boot_tx_mailbox_offset = slave->sii.boot_tx_mailbox_offset;
0253c74d0940 merge -c1619 branches/1.4-foe: Implemented going to bootstrap state BOOT.
Florian Pose <fp@igh-essen.com>
parents: 1336
diff changeset
   298
    data.boot_tx_mailbox_size = slave->sii.boot_tx_mailbox_size;
0253c74d0940 merge -c1619 branches/1.4-foe: Implemented going to bootstrap state BOOT.
Florian Pose <fp@igh-essen.com>
parents: 1336
diff changeset
   299
    data.std_rx_mailbox_offset = slave->sii.std_rx_mailbox_offset;
0253c74d0940 merge -c1619 branches/1.4-foe: Implemented going to bootstrap state BOOT.
Florian Pose <fp@igh-essen.com>
parents: 1336
diff changeset
   300
    data.std_rx_mailbox_size = slave->sii.std_rx_mailbox_size;
0253c74d0940 merge -c1619 branches/1.4-foe: Implemented going to bootstrap state BOOT.
Florian Pose <fp@igh-essen.com>
parents: 1336
diff changeset
   301
    data.std_tx_mailbox_offset = slave->sii.std_tx_mailbox_offset;
0253c74d0940 merge -c1619 branches/1.4-foe: Implemented going to bootstrap state BOOT.
Florian Pose <fp@igh-essen.com>
parents: 1336
diff changeset
   302
    data.std_tx_mailbox_size = slave->sii.std_tx_mailbox_size;
1079
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   303
    data.mailbox_protocols = slave->sii.mailbox_protocols;
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   304
    data.has_general_category = slave->sii.has_general;
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   305
    data.coe_details = slave->sii.coe_details;
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   306
    data.general_flags = slave->sii.general_flags;
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   307
    data.current_on_ebus = slave->sii.current_on_ebus;
1379
cbceb0e2f2a0 Reading more base information (incl. whether DC supported).
Florian Pose <fp@igh-essen.com>
parents: 1363
diff changeset
   308
    for (i = 0; i < EC_MAX_PORTS; i++) {
1425
c1322a8793c0 Transition delay calculation. TBC...
Florian Pose <fp@igh-essen.com>
parents: 1421
diff changeset
   309
        data.ports[i].desc = slave->ports[i].desc;
c1322a8793c0 Transition delay calculation. TBC...
Florian Pose <fp@igh-essen.com>
parents: 1421
diff changeset
   310
        data.ports[i].link.link_up = slave->ports[i].link.link_up;
c1322a8793c0 Transition delay calculation. TBC...
Florian Pose <fp@igh-essen.com>
parents: 1421
diff changeset
   311
        data.ports[i].link.loop_closed = slave->ports[i].link.loop_closed;
1831
1875b9fea0ba Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents: 1826
diff changeset
   312
        data.ports[i].link.signal_detected =
1875b9fea0ba Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents: 1826
diff changeset
   313
            slave->ports[i].link.signal_detected;
1425
c1322a8793c0 Transition delay calculation. TBC...
Florian Pose <fp@igh-essen.com>
parents: 1421
diff changeset
   314
        data.ports[i].receive_time = slave->ports[i].receive_time;
c1322a8793c0 Transition delay calculation. TBC...
Florian Pose <fp@igh-essen.com>
parents: 1421
diff changeset
   315
        if (slave->ports[i].next_slave) {
1831
1875b9fea0ba Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents: 1826
diff changeset
   316
            data.ports[i].next_slave =
1875b9fea0ba Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents: 1826
diff changeset
   317
                slave->ports[i].next_slave->ring_position;
1421
043a518831b2 Bus topology calculation.
Florian Pose <fp@igh-essen.com>
parents: 1420
diff changeset
   318
        } else {
1425
c1322a8793c0 Transition delay calculation. TBC...
Florian Pose <fp@igh-essen.com>
parents: 1421
diff changeset
   319
            data.ports[i].next_slave = 0xffff;
1421
043a518831b2 Bus topology calculation.
Florian Pose <fp@igh-essen.com>
parents: 1420
diff changeset
   320
        }
1425
c1322a8793c0 Transition delay calculation. TBC...
Florian Pose <fp@igh-essen.com>
parents: 1421
diff changeset
   321
        data.ports[i].delay_to_next_dc = slave->ports[i].delay_to_next_dc;
1379
cbceb0e2f2a0 Reading more base information (incl. whether DC supported).
Florian Pose <fp@igh-essen.com>
parents: 1363
diff changeset
   322
    }
cbceb0e2f2a0 Reading more base information (incl. whether DC supported).
Florian Pose <fp@igh-essen.com>
parents: 1363
diff changeset
   323
    data.fmmu_bit = slave->base_fmmu_bit_operation;
cbceb0e2f2a0 Reading more base information (incl. whether DC supported).
Florian Pose <fp@igh-essen.com>
parents: 1363
diff changeset
   324
    data.dc_supported = slave->base_dc_supported;
cbceb0e2f2a0 Reading more base information (incl. whether DC supported).
Florian Pose <fp@igh-essen.com>
parents: 1363
diff changeset
   325
    data.dc_range = slave->base_dc_range;
1419
8fc38c37d86e Determine type of DC implementation (full or delay meas. only); update scan FSM graph.
Florian Pose <fp@igh-essen.com>
parents: 1417
diff changeset
   326
    data.has_dc_system_time = slave->has_dc_system_time;
1426
af45bba80d85 Transition->Transmission.
Florian Pose <fp@igh-essen.com>
parents: 1425
diff changeset
   327
    data.transmission_delay = slave->transmission_delay;
1148
1762296870bd Renamed state field to al_state.
Florian Pose <fp@igh-essen.com>
parents: 1147
diff changeset
   328
    data.al_state = slave->current_state;
1079
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   329
    data.error_flag = slave->error_flag;
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   330
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   331
    data.sync_count = slave->sii.sync_count;
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   332
    data.sdo_count = ec_slave_sdo_count(slave);
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   333
    data.sii_nwords = slave->sii_nwords;
1109
11ac4051db6b Group/Image/Order strings in slave ioctl; order number as text content
Florian Pose <fp@igh-essen.com>
parents: 1108
diff changeset
   334
    ec_cdev_strcpy(data.group, slave->sii.group);
11ac4051db6b Group/Image/Order strings in slave ioctl; order number as text content
Florian Pose <fp@igh-essen.com>
parents: 1108
diff changeset
   335
    ec_cdev_strcpy(data.image, slave->sii.image);
11ac4051db6b Group/Image/Order strings in slave ioctl; order number as text content
Florian Pose <fp@igh-essen.com>
parents: 1108
diff changeset
   336
    ec_cdev_strcpy(data.order, slave->sii.order);
1108
7beba3e7e6b4 Added ec_cdev_strcpy() function.
Florian Pose <fp@igh-essen.com>
parents: 1092
diff changeset
   337
    ec_cdev_strcpy(data.name, slave->sii.name);
1079
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   338
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   339
    up(&master->master_sem);
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   340
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   341
    if (copy_to_user((void __user *) arg, &data, sizeof(data)))
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   342
        return -EFAULT;
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   343
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   344
    return 0;
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   345
}
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   346
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   347
/*****************************************************************************/
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   348
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   349
/** Get slave sync manager information.
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   350
 */
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   351
int ec_cdev_ioctl_slave_sync(
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   352
        ec_master_t *master, /**< EtherCAT master. */
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   353
        unsigned long arg /**< Userspace address to store the results. */
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   354
        )
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   355
{
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   356
    ec_ioctl_slave_sync_t data;
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   357
    const ec_slave_t *slave;
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   358
    const ec_sync_t *sync;
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   359
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   360
    if (copy_from_user(&data, (void __user *) arg, sizeof(data))) {
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   361
        return -EFAULT;
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   362
    }
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   363
1189
acc6430bfb32 Use down_interruptible() wherever possible.
Florian Pose <fp@igh-essen.com>
parents: 1183
diff changeset
   364
    if (down_interruptible(&master->master_sem))
acc6430bfb32 Use down_interruptible() wherever possible.
Florian Pose <fp@igh-essen.com>
parents: 1183
diff changeset
   365
        return -EINTR;
1079
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   366
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   367
    if (!(slave = ec_master_find_slave_const(
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   368
                    master, 0, data.slave_position))) {
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   369
        up(&master->master_sem);
1921
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1909
diff changeset
   370
        EC_MASTER_ERR(master, "Slave %u does not exist!\n",
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1909
diff changeset
   371
                data.slave_position);
1079
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   372
        return -EINVAL;
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   373
    }
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   374
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   375
    if (data.sync_index >= slave->sii.sync_count) {
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   376
        up(&master->master_sem);
1921
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1909
diff changeset
   377
        EC_SLAVE_ERR(slave, "Sync manager %u does not exist!\n",
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1909
diff changeset
   378
                data.sync_index);
1079
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   379
        return -EINVAL;
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   380
    }
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   381
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   382
    sync = &slave->sii.syncs[data.sync_index];
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   383
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   384
    data.physical_start_address = sync->physical_start_address;
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   385
    data.default_size = sync->default_length;
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   386
    data.control_register = sync->control_register;
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   387
    data.enable = sync->enable;
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   388
    data.pdo_count = ec_pdo_list_count(&sync->pdos);
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   389
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   390
    up(&master->master_sem);
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   391
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   392
    if (copy_to_user((void __user *) arg, &data, sizeof(data)))
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   393
        return -EFAULT;
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   394
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   395
    return 0;
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   396
}
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   397
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   398
/*****************************************************************************/
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   399
1327
4d179b06dd3c merge -c1604 branches/stable-1.4: Fixed spelling of EtherCAT terms.
Florian Pose <fp@igh-essen.com>
parents: 1326
diff changeset
   400
/** Get slave sync manager PDO information.
1079
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   401
 */
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   402
int ec_cdev_ioctl_slave_sync_pdo(
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   403
        ec_master_t *master, /**< EtherCAT master. */
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   404
        unsigned long arg /**< Userspace address to store the results. */
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   405
        )
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   406
{
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   407
    ec_ioctl_slave_sync_pdo_t data;
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   408
    const ec_slave_t *slave;
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   409
    const ec_sync_t *sync;
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   410
    const ec_pdo_t *pdo;
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   411
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   412
    if (copy_from_user(&data, (void __user *) arg, sizeof(data))) {
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   413
        return -EFAULT;
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   414
    }
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   415
1189
acc6430bfb32 Use down_interruptible() wherever possible.
Florian Pose <fp@igh-essen.com>
parents: 1183
diff changeset
   416
    if (down_interruptible(&master->master_sem))
acc6430bfb32 Use down_interruptible() wherever possible.
Florian Pose <fp@igh-essen.com>
parents: 1183
diff changeset
   417
        return -EINTR;
1079
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   418
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   419
    if (!(slave = ec_master_find_slave_const(
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   420
                    master, 0, data.slave_position))) {
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   421
        up(&master->master_sem);
1921
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1909
diff changeset
   422
        EC_MASTER_ERR(master, "Slave %u does not exist!\n",
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1909
diff changeset
   423
                data.slave_position);
1079
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   424
        return -EINVAL;
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   425
    }
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   426
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   427
    if (data.sync_index >= slave->sii.sync_count) {
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   428
        up(&master->master_sem);
1921
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1909
diff changeset
   429
        EC_SLAVE_ERR(slave, "Sync manager %u does not exist!\n",
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1909
diff changeset
   430
                data.sync_index);
1079
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   431
        return -EINVAL;
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   432
    }
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   433
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   434
    sync = &slave->sii.syncs[data.sync_index];
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   435
    if (!(pdo = ec_pdo_list_find_pdo_by_pos_const(
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   436
                    &sync->pdos, data.pdo_pos))) {
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   437
        up(&master->master_sem);
1921
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1909
diff changeset
   438
        EC_SLAVE_ERR(slave, "Sync manager %u does not contain a PDO with "
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1909
diff changeset
   439
                "position %u!\n", data.sync_index, data.pdo_pos);
1079
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   440
        return -EINVAL;
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   441
    }
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   442
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   443
    data.index = pdo->index;
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   444
    data.entry_count = ec_pdo_entry_count(pdo);
1108
7beba3e7e6b4 Added ec_cdev_strcpy() function.
Florian Pose <fp@igh-essen.com>
parents: 1092
diff changeset
   445
    ec_cdev_strcpy(data.name, pdo->name);
1079
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   446
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   447
    up(&master->master_sem);
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   448
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   449
    if (copy_to_user((void __user *) arg, &data, sizeof(data)))
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   450
        return -EFAULT;
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   451
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   452
    return 0;
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   453
}
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   454
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   455
/*****************************************************************************/
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   456
1327
4d179b06dd3c merge -c1604 branches/stable-1.4: Fixed spelling of EtherCAT terms.
Florian Pose <fp@igh-essen.com>
parents: 1326
diff changeset
   457
/** Get slave sync manager PDO entry information.
1079
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   458
 */
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   459
int ec_cdev_ioctl_slave_sync_pdo_entry(
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   460
        ec_master_t *master, /**< EtherCAT master. */
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   461
        unsigned long arg /**< Userspace address to store the results. */
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   462
        )
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   463
{
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   464
    ec_ioctl_slave_sync_pdo_entry_t data;
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   465
    const ec_slave_t *slave;
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   466
    const ec_sync_t *sync;
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   467
    const ec_pdo_t *pdo;
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   468
    const ec_pdo_entry_t *entry;
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   469
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   470
    if (copy_from_user(&data, (void __user *) arg, sizeof(data))) {
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   471
        return -EFAULT;
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   472
    }
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   473
1189
acc6430bfb32 Use down_interruptible() wherever possible.
Florian Pose <fp@igh-essen.com>
parents: 1183
diff changeset
   474
    if (down_interruptible(&master->master_sem))
acc6430bfb32 Use down_interruptible() wherever possible.
Florian Pose <fp@igh-essen.com>
parents: 1183
diff changeset
   475
        return -EINTR;
1079
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   476
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   477
    if (!(slave = ec_master_find_slave_const(
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   478
                    master, 0, data.slave_position))) {
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   479
        up(&master->master_sem);
1921
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1909
diff changeset
   480
        EC_MASTER_ERR(master, "Slave %u does not exist!\n",
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1909
diff changeset
   481
                data.slave_position);
1079
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   482
        return -EINVAL;
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   483
    }
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   484
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   485
    if (data.sync_index >= slave->sii.sync_count) {
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   486
        up(&master->master_sem);
1921
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1909
diff changeset
   487
        EC_SLAVE_ERR(slave, "Sync manager %u does not exist!\n",
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1909
diff changeset
   488
                data.sync_index);
1079
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   489
        return -EINVAL;
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   490
    }
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   491
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   492
    sync = &slave->sii.syncs[data.sync_index];
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   493
    if (!(pdo = ec_pdo_list_find_pdo_by_pos_const(
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   494
                    &sync->pdos, data.pdo_pos))) {
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   495
        up(&master->master_sem);
1921
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1909
diff changeset
   496
        EC_SLAVE_ERR(slave, "Sync manager %u does not contain a PDO with "
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1909
diff changeset
   497
                "position %u!\n", data.sync_index, data.pdo_pos);
1079
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   498
        return -EINVAL;
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   499
    }
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   500
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   501
    if (!(entry = ec_pdo_find_entry_by_pos_const(
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   502
                    pdo, data.entry_pos))) {
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   503
        up(&master->master_sem);
1921
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1909
diff changeset
   504
        EC_SLAVE_ERR(slave, "PDO 0x%04X does not contain an entry with "
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1909
diff changeset
   505
                "position %u!\n", data.pdo_pos, data.entry_pos);
1079
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   506
        return -EINVAL;
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   507
    }
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   508
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   509
    data.index = entry->index;
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   510
    data.subindex = entry->subindex;
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   511
    data.bit_length = entry->bit_length;
1108
7beba3e7e6b4 Added ec_cdev_strcpy() function.
Florian Pose <fp@igh-essen.com>
parents: 1092
diff changeset
   512
    ec_cdev_strcpy(data.name, entry->name);
1079
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   513
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   514
    up(&master->master_sem);
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   515
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   516
    if (copy_to_user((void __user *) arg, &data, sizeof(data)))
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   517
        return -EFAULT;
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   518
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   519
    return 0;
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   520
}
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   521
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   522
/*****************************************************************************/
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   523
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   524
/** Get domain information.
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   525
 */
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   526
int ec_cdev_ioctl_domain(
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   527
        ec_master_t *master, /**< EtherCAT master. */
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   528
        unsigned long arg /**< Userspace address to store the results. */
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   529
        )
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   530
{
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   531
    ec_ioctl_domain_t data;
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   532
    const ec_domain_t *domain;
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   533
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   534
    if (copy_from_user(&data, (void __user *) arg, sizeof(data))) {
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   535
        return -EFAULT;
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   536
    }
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   537
1189
acc6430bfb32 Use down_interruptible() wherever possible.
Florian Pose <fp@igh-essen.com>
parents: 1183
diff changeset
   538
    if (down_interruptible(&master->master_sem))
acc6430bfb32 Use down_interruptible() wherever possible.
Florian Pose <fp@igh-essen.com>
parents: 1183
diff changeset
   539
        return -EINTR;
1079
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   540
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   541
    if (!(domain = ec_master_find_domain_const(master, data.index))) {
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   542
        up(&master->master_sem);
1921
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1909
diff changeset
   543
        EC_MASTER_ERR(master, "Domain %u does not exist!\n", data.index);
1079
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   544
        return -EINVAL;
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   545
    }
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   546
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   547
    data.data_size = domain->data_size;
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   548
    data.logical_base_address = domain->logical_base_address;
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   549
    data.working_counter = domain->working_counter;
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   550
    data.expected_working_counter = domain->expected_working_counter;
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   551
    data.fmmu_count = ec_domain_fmmu_count(domain);
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   552
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   553
    up(&master->master_sem);
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   554
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   555
    if (copy_to_user((void __user *) arg, &data, sizeof(data)))
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   556
        return -EFAULT;
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   557
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   558
    return 0;
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   559
}
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   560
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   561
/*****************************************************************************/
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   562
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   563
/** Get domain FMMU information.
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   564
 */
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   565
int ec_cdev_ioctl_domain_fmmu(
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   566
        ec_master_t *master, /**< EtherCAT master. */
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   567
        unsigned long arg /**< Userspace address to store the results. */
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   568
        )
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   569
{
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   570
    ec_ioctl_domain_fmmu_t data;
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   571
    const ec_domain_t *domain;
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   572
    const ec_fmmu_config_t *fmmu;
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   573
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   574
    if (copy_from_user(&data, (void __user *) arg, sizeof(data))) {
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   575
        return -EFAULT;
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   576
    }
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   577
1189
acc6430bfb32 Use down_interruptible() wherever possible.
Florian Pose <fp@igh-essen.com>
parents: 1183
diff changeset
   578
    if (down_interruptible(&master->master_sem))
acc6430bfb32 Use down_interruptible() wherever possible.
Florian Pose <fp@igh-essen.com>
parents: 1183
diff changeset
   579
        return -EINTR;
1079
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   580
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   581
    if (!(domain = ec_master_find_domain_const(master, data.domain_index))) {
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   582
        up(&master->master_sem);
1921
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1909
diff changeset
   583
        EC_MASTER_ERR(master, "Domain %u does not exist!\n",
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1909
diff changeset
   584
                data.domain_index);
1079
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   585
        return -EINVAL;
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   586
    }
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   587
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   588
    if (!(fmmu = ec_domain_find_fmmu(domain, data.fmmu_index))) {
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   589
        up(&master->master_sem);
1921
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1909
diff changeset
   590
        EC_MASTER_ERR(master, "Domain %u has less than %u"
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1909
diff changeset
   591
                " fmmu configurations.\n",
1079
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   592
                data.domain_index, data.fmmu_index + 1);
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   593
        return -EINVAL;
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   594
    }
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   595
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   596
    data.slave_config_alias = fmmu->sc->alias;
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   597
    data.slave_config_position = fmmu->sc->position;
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   598
    data.sync_index = fmmu->sync_index;
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   599
    data.dir = fmmu->dir;
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   600
    data.logical_address = fmmu->logical_start_address;
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   601
    data.data_size = fmmu->data_size;
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   602
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   603
    up(&master->master_sem);
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   604
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   605
    if (copy_to_user((void __user *) arg, &data, sizeof(data)))
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   606
        return -EFAULT;
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   607
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   608
    return 0;
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   609
}
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   610
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   611
/*****************************************************************************/
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   612
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   613
/** Get domain data.
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   614
 */
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   615
int ec_cdev_ioctl_domain_data(
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   616
        ec_master_t *master, /**< EtherCAT master. */
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   617
        unsigned long arg /**< Userspace address to store the results. */
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   618
        )
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   619
{
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   620
    ec_ioctl_domain_data_t data;
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   621
    const ec_domain_t *domain;
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   622
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   623
    if (copy_from_user(&data, (void __user *) arg, sizeof(data))) {
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   624
        return -EFAULT;
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   625
    }
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   626
1189
acc6430bfb32 Use down_interruptible() wherever possible.
Florian Pose <fp@igh-essen.com>
parents: 1183
diff changeset
   627
    if (down_interruptible(&master->master_sem))
acc6430bfb32 Use down_interruptible() wherever possible.
Florian Pose <fp@igh-essen.com>
parents: 1183
diff changeset
   628
        return -EINTR;
1079
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   629
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   630
    if (!(domain = ec_master_find_domain_const(master, data.domain_index))) {
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   631
        up(&master->master_sem);
1921
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1909
diff changeset
   632
        EC_MASTER_ERR(master, "Domain %u does not exist!\n",
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1909
diff changeset
   633
                data.domain_index);
1079
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   634
        return -EINVAL;
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   635
    }
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   636
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   637
    if (domain->data_size != data.data_size) {
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   638
        up(&master->master_sem);
1921
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1909
diff changeset
   639
        EC_MASTER_ERR(master, "Data size mismatch %u/%zu!\n",
1079
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   640
                data.data_size, domain->data_size);
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   641
        return -EFAULT;
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   642
    }
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   643
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   644
    if (copy_to_user((void __user *) data.target, domain->data,
1223
6d539205114e Added missing up().
Florian Pose <fp@igh-essen.com>
parents: 1209
diff changeset
   645
                domain->data_size)) {
6d539205114e Added missing up().
Florian Pose <fp@igh-essen.com>
parents: 1209
diff changeset
   646
        up(&master->master_sem);
6d539205114e Added missing up().
Florian Pose <fp@igh-essen.com>
parents: 1209
diff changeset
   647
        return -EFAULT;
6d539205114e Added missing up().
Florian Pose <fp@igh-essen.com>
parents: 1209
diff changeset
   648
    }
1079
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   649
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   650
    up(&master->master_sem);
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   651
    return 0;
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   652
}
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   653
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   654
/*****************************************************************************/
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   655
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   656
/** Set master debug level.
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   657
 */
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   658
int ec_cdev_ioctl_master_debug(
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   659
        ec_master_t *master, /**< EtherCAT master. */
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   660
        unsigned long arg /**< ioctl() argument. */
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   661
        )
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   662
{
1313
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1312
diff changeset
   663
    return ec_master_debug_level(master, (unsigned int) arg);
1079
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   664
}
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   665
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   666
/*****************************************************************************/
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   667
1961
48f536aefc18 Rescan command.
Florian Pose <fp@igh-essen.com>
parents: 1945
diff changeset
   668
/** Issue a bus scan.
48f536aefc18 Rescan command.
Florian Pose <fp@igh-essen.com>
parents: 1945
diff changeset
   669
 */
48f536aefc18 Rescan command.
Florian Pose <fp@igh-essen.com>
parents: 1945
diff changeset
   670
int ec_cdev_ioctl_master_rescan(
48f536aefc18 Rescan command.
Florian Pose <fp@igh-essen.com>
parents: 1945
diff changeset
   671
        ec_master_t *master, /**< EtherCAT master. */
48f536aefc18 Rescan command.
Florian Pose <fp@igh-essen.com>
parents: 1945
diff changeset
   672
        unsigned long arg /**< ioctl() argument. */
48f536aefc18 Rescan command.
Florian Pose <fp@igh-essen.com>
parents: 1945
diff changeset
   673
        )
48f536aefc18 Rescan command.
Florian Pose <fp@igh-essen.com>
parents: 1945
diff changeset
   674
{
48f536aefc18 Rescan command.
Florian Pose <fp@igh-essen.com>
parents: 1945
diff changeset
   675
    master->fsm.rescan_required = 1;
48f536aefc18 Rescan command.
Florian Pose <fp@igh-essen.com>
parents: 1945
diff changeset
   676
    return 0;
48f536aefc18 Rescan command.
Florian Pose <fp@igh-essen.com>
parents: 1945
diff changeset
   677
}
48f536aefc18 Rescan command.
Florian Pose <fp@igh-essen.com>
parents: 1945
diff changeset
   678
48f536aefc18 Rescan command.
Florian Pose <fp@igh-essen.com>
parents: 1945
diff changeset
   679
/*****************************************************************************/
48f536aefc18 Rescan command.
Florian Pose <fp@igh-essen.com>
parents: 1945
diff changeset
   680
1079
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   681
/** Set slave state.
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   682
 */
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   683
int ec_cdev_ioctl_slave_state(
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   684
        ec_master_t *master, /**< EtherCAT master. */
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   685
        unsigned long arg /**< ioctl() argument. */
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   686
        )
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   687
{
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   688
    ec_ioctl_slave_state_t data;
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   689
    ec_slave_t *slave;
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   690
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   691
    if (copy_from_user(&data, (void __user *) arg, sizeof(data))) {
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   692
        return -EFAULT;
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   693
    }
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   694
1189
acc6430bfb32 Use down_interruptible() wherever possible.
Florian Pose <fp@igh-essen.com>
parents: 1183
diff changeset
   695
    if (down_interruptible(&master->master_sem))
acc6430bfb32 Use down_interruptible() wherever possible.
Florian Pose <fp@igh-essen.com>
parents: 1183
diff changeset
   696
        return -EINTR;
1079
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   697
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   698
    if (!(slave = ec_master_find_slave(
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   699
                    master, 0, data.slave_position))) {
1196
a27966f01b72 Fixed missing up().
Florian Pose <fp@igh-essen.com>
parents: 1189
diff changeset
   700
        up(&master->master_sem);
1921
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1909
diff changeset
   701
        EC_MASTER_ERR(master, "Slave %u does not exist!\n",
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1909
diff changeset
   702
                data.slave_position);
1079
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   703
        return -EINVAL;
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   704
    }
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   705
1150
c589b54ade01 Fixed requested_state.
Florian Pose <fp@igh-essen.com>
parents: 1148
diff changeset
   706
    ec_slave_request_state(slave, data.al_state);
1079
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   707
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   708
    up(&master->master_sem);
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   709
    return 0;
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   710
}
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   711
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   712
/*****************************************************************************/
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   713
1327
4d179b06dd3c merge -c1604 branches/stable-1.4: Fixed spelling of EtherCAT terms.
Florian Pose <fp@igh-essen.com>
parents: 1326
diff changeset
   714
/** Get slave SDO information.
1079
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   715
 */
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   716
int ec_cdev_ioctl_slave_sdo(
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   717
        ec_master_t *master, /**< EtherCAT master. */
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   718
        unsigned long arg /**< ioctl() argument. */
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   719
        )
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   720
{
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   721
    ec_ioctl_slave_sdo_t data;
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   722
    const ec_slave_t *slave;
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   723
    const ec_sdo_t *sdo;
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   724
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   725
    if (copy_from_user(&data, (void __user *) arg, sizeof(data))) {
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   726
        return -EFAULT;
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   727
    }
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   728
1189
acc6430bfb32 Use down_interruptible() wherever possible.
Florian Pose <fp@igh-essen.com>
parents: 1183
diff changeset
   729
    if (down_interruptible(&master->master_sem))
acc6430bfb32 Use down_interruptible() wherever possible.
Florian Pose <fp@igh-essen.com>
parents: 1183
diff changeset
   730
        return -EINTR;
1079
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   731
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   732
    if (!(slave = ec_master_find_slave_const(
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   733
                    master, 0, data.slave_position))) {
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   734
        up(&master->master_sem);
1921
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1909
diff changeset
   735
        EC_MASTER_ERR(master, "Slave %u does not exist!\n",
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1909
diff changeset
   736
                data.slave_position);
1079
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   737
        return -EINVAL;
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   738
    }
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   739
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   740
    if (!(sdo = ec_slave_get_sdo_by_pos_const(
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   741
                    slave, data.sdo_position))) {
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   742
        up(&master->master_sem);
1921
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1909
diff changeset
   743
        EC_SLAVE_ERR(slave, "SDO %u does not exist!\n", data.sdo_position);
1079
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   744
        return -EINVAL;
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   745
    }
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   746
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   747
    data.sdo_index = sdo->index;
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   748
    data.max_subindex = sdo->max_subindex;
1108
7beba3e7e6b4 Added ec_cdev_strcpy() function.
Florian Pose <fp@igh-essen.com>
parents: 1092
diff changeset
   749
    ec_cdev_strcpy(data.name, sdo->name);
1079
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   750
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   751
    up(&master->master_sem);
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   752
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   753
    if (copy_to_user((void __user *) arg, &data, sizeof(data)))
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   754
        return -EFAULT;
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   755
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   756
    return 0;
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   757
}
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   758
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   759
/*****************************************************************************/
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   760
1327
4d179b06dd3c merge -c1604 branches/stable-1.4: Fixed spelling of EtherCAT terms.
Florian Pose <fp@igh-essen.com>
parents: 1326
diff changeset
   761
/** Get slave SDO entry information.
1079
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   762
 */
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   763
int ec_cdev_ioctl_slave_sdo_entry(
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   764
        ec_master_t *master, /**< EtherCAT master. */
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   765
        unsigned long arg /**< ioctl() argument. */
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   766
        )
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   767
{
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   768
    ec_ioctl_slave_sdo_entry_t data;
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   769
    const ec_slave_t *slave;
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   770
    const ec_sdo_t *sdo;
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   771
    const ec_sdo_entry_t *entry;
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   772
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   773
    if (copy_from_user(&data, (void __user *) arg, sizeof(data))) {
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   774
        return -EFAULT;
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   775
    }
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   776
1189
acc6430bfb32 Use down_interruptible() wherever possible.
Florian Pose <fp@igh-essen.com>
parents: 1183
diff changeset
   777
    if (down_interruptible(&master->master_sem))
acc6430bfb32 Use down_interruptible() wherever possible.
Florian Pose <fp@igh-essen.com>
parents: 1183
diff changeset
   778
        return -EINTR;
1079
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   779
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   780
    if (!(slave = ec_master_find_slave_const(
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   781
                    master, 0, data.slave_position))) {
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   782
        up(&master->master_sem);
1921
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1909
diff changeset
   783
        EC_MASTER_ERR(master, "Slave %u does not exist!\n",
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1909
diff changeset
   784
                data.slave_position);
1079
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   785
        return -EINVAL;
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   786
    }
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   787
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   788
    if (data.sdo_spec <= 0) {
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   789
        if (!(sdo = ec_slave_get_sdo_by_pos_const(
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   790
                        slave, -data.sdo_spec))) {
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   791
            up(&master->master_sem);
1921
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1909
diff changeset
   792
            EC_SLAVE_ERR(slave, "SDO %u does not exist!\n", -data.sdo_spec);
1079
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   793
            return -EINVAL;
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   794
        }
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   795
    } else {
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   796
        if (!(sdo = ec_slave_get_sdo_const(
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   797
                        slave, data.sdo_spec))) {
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   798
            up(&master->master_sem);
1921
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1909
diff changeset
   799
            EC_SLAVE_ERR(slave, "SDO 0x%04X does not exist!\n",
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1909
diff changeset
   800
                    data.sdo_spec);
1079
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   801
            return -EINVAL;
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   802
        }
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   803
    }
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   804
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   805
    if (!(entry = ec_sdo_get_entry_const(
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   806
                    sdo, data.sdo_entry_subindex))) {
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   807
        up(&master->master_sem);
1921
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1909
diff changeset
   808
        EC_SLAVE_ERR(slave, "SDO entry 0x%04X:%02X does not exist!\n",
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1909
diff changeset
   809
                sdo->index, data.sdo_entry_subindex);
1079
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   810
        return -EINVAL;
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   811
    }
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   812
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   813
    data.data_type = entry->data_type;
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   814
    data.bit_length = entry->bit_length;
1382
cb2188d111f3 Read SDO entry access rights.
Florian Pose <fp@igh-essen.com>
parents: 1381
diff changeset
   815
    data.read_access[EC_SDO_ENTRY_ACCESS_PREOP] =
cb2188d111f3 Read SDO entry access rights.
Florian Pose <fp@igh-essen.com>
parents: 1381
diff changeset
   816
        entry->read_access[EC_SDO_ENTRY_ACCESS_PREOP];
cb2188d111f3 Read SDO entry access rights.
Florian Pose <fp@igh-essen.com>
parents: 1381
diff changeset
   817
    data.read_access[EC_SDO_ENTRY_ACCESS_SAFEOP] =
cb2188d111f3 Read SDO entry access rights.
Florian Pose <fp@igh-essen.com>
parents: 1381
diff changeset
   818
        entry->read_access[EC_SDO_ENTRY_ACCESS_SAFEOP];
cb2188d111f3 Read SDO entry access rights.
Florian Pose <fp@igh-essen.com>
parents: 1381
diff changeset
   819
    data.read_access[EC_SDO_ENTRY_ACCESS_OP] =
cb2188d111f3 Read SDO entry access rights.
Florian Pose <fp@igh-essen.com>
parents: 1381
diff changeset
   820
        entry->read_access[EC_SDO_ENTRY_ACCESS_OP];
cb2188d111f3 Read SDO entry access rights.
Florian Pose <fp@igh-essen.com>
parents: 1381
diff changeset
   821
    data.write_access[EC_SDO_ENTRY_ACCESS_PREOP] =
cb2188d111f3 Read SDO entry access rights.
Florian Pose <fp@igh-essen.com>
parents: 1381
diff changeset
   822
        entry->write_access[EC_SDO_ENTRY_ACCESS_PREOP];
cb2188d111f3 Read SDO entry access rights.
Florian Pose <fp@igh-essen.com>
parents: 1381
diff changeset
   823
    data.write_access[EC_SDO_ENTRY_ACCESS_SAFEOP] =
cb2188d111f3 Read SDO entry access rights.
Florian Pose <fp@igh-essen.com>
parents: 1381
diff changeset
   824
        entry->write_access[EC_SDO_ENTRY_ACCESS_SAFEOP];
cb2188d111f3 Read SDO entry access rights.
Florian Pose <fp@igh-essen.com>
parents: 1381
diff changeset
   825
    data.write_access[EC_SDO_ENTRY_ACCESS_OP] =
cb2188d111f3 Read SDO entry access rights.
Florian Pose <fp@igh-essen.com>
parents: 1381
diff changeset
   826
        entry->write_access[EC_SDO_ENTRY_ACCESS_OP];
1108
7beba3e7e6b4 Added ec_cdev_strcpy() function.
Florian Pose <fp@igh-essen.com>
parents: 1092
diff changeset
   827
    ec_cdev_strcpy(data.description, entry->description);
1079
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   828
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   829
    up(&master->master_sem);
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   830
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   831
    if (copy_to_user((void __user *) arg, &data, sizeof(data)))
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   832
        return -EFAULT;
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   833
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   834
    return 0;
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   835
}
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   836
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   837
/*****************************************************************************/
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   838
1327
4d179b06dd3c merge -c1604 branches/stable-1.4: Fixed spelling of EtherCAT terms.
Florian Pose <fp@igh-essen.com>
parents: 1326
diff changeset
   839
/** Upload SDO.
1079
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   840
 */
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   841
int ec_cdev_ioctl_slave_sdo_upload(
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   842
        ec_master_t *master, /**< EtherCAT master. */
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   843
        unsigned long arg /**< ioctl() argument. */
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   844
        )
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   845
{
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   846
    ec_ioctl_slave_sdo_upload_t data;
2109
755e6ce823f0 Implemented ecrt_master_sdo_upload() and ecrt_master_sdo_download() also for
Florian Pose <fp@igh-essen.com>
parents: 2061
diff changeset
   847
    uint8_t *target;
755e6ce823f0 Implemented ecrt_master_sdo_upload() and ecrt_master_sdo_download() also for
Florian Pose <fp@igh-essen.com>
parents: 2061
diff changeset
   848
    int ret;
1079
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   849
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   850
    if (copy_from_user(&data, (void __user *) arg, sizeof(data))) {
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   851
        return -EFAULT;
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   852
    }
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   853
2109
755e6ce823f0 Implemented ecrt_master_sdo_upload() and ecrt_master_sdo_download() also for
Florian Pose <fp@igh-essen.com>
parents: 2061
diff changeset
   854
    if (!(target = kmalloc(data.target_size, GFP_KERNEL))) {
755e6ce823f0 Implemented ecrt_master_sdo_upload() and ecrt_master_sdo_download() also for
Florian Pose <fp@igh-essen.com>
parents: 2061
diff changeset
   855
        EC_MASTER_ERR(master, "Failed to allocate %u bytes"
755e6ce823f0 Implemented ecrt_master_sdo_upload() and ecrt_master_sdo_download() also for
Florian Pose <fp@igh-essen.com>
parents: 2061
diff changeset
   856
                " for SDO upload.\n", data.target_size);
755e6ce823f0 Implemented ecrt_master_sdo_upload() and ecrt_master_sdo_download() also for
Florian Pose <fp@igh-essen.com>
parents: 2061
diff changeset
   857
        return -ENOMEM;
755e6ce823f0 Implemented ecrt_master_sdo_upload() and ecrt_master_sdo_download() also for
Florian Pose <fp@igh-essen.com>
parents: 2061
diff changeset
   858
    }
755e6ce823f0 Implemented ecrt_master_sdo_upload() and ecrt_master_sdo_download() also for
Florian Pose <fp@igh-essen.com>
parents: 2061
diff changeset
   859
755e6ce823f0 Implemented ecrt_master_sdo_upload() and ecrt_master_sdo_download() also for
Florian Pose <fp@igh-essen.com>
parents: 2061
diff changeset
   860
    ret = ecrt_master_sdo_upload(master, data.slave_position,
755e6ce823f0 Implemented ecrt_master_sdo_upload() and ecrt_master_sdo_download() also for
Florian Pose <fp@igh-essen.com>
parents: 2061
diff changeset
   861
            data.sdo_index, data.sdo_entry_subindex, target,
755e6ce823f0 Implemented ecrt_master_sdo_upload() and ecrt_master_sdo_download() also for
Florian Pose <fp@igh-essen.com>
parents: 2061
diff changeset
   862
            data.target_size, &data.data_size, &data.abort_code);
755e6ce823f0 Implemented ecrt_master_sdo_upload() and ecrt_master_sdo_download() also for
Florian Pose <fp@igh-essen.com>
parents: 2061
diff changeset
   863
755e6ce823f0 Implemented ecrt_master_sdo_upload() and ecrt_master_sdo_download() also for
Florian Pose <fp@igh-essen.com>
parents: 2061
diff changeset
   864
    if (!ret) {
1079
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   865
        if (copy_to_user((void __user *) data.target,
2109
755e6ce823f0 Implemented ecrt_master_sdo_upload() and ecrt_master_sdo_download() also for
Florian Pose <fp@igh-essen.com>
parents: 2061
diff changeset
   866
                    target, data.data_size)) {
755e6ce823f0 Implemented ecrt_master_sdo_upload() and ecrt_master_sdo_download() also for
Florian Pose <fp@igh-essen.com>
parents: 2061
diff changeset
   867
            kfree(target);
1079
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   868
            return -EFAULT;
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   869
        }
2109
755e6ce823f0 Implemented ecrt_master_sdo_upload() and ecrt_master_sdo_download() also for
Florian Pose <fp@igh-essen.com>
parents: 2061
diff changeset
   870
    }
755e6ce823f0 Implemented ecrt_master_sdo_upload() and ecrt_master_sdo_download() also for
Florian Pose <fp@igh-essen.com>
parents: 2061
diff changeset
   871
755e6ce823f0 Implemented ecrt_master_sdo_upload() and ecrt_master_sdo_download() also for
Florian Pose <fp@igh-essen.com>
parents: 2061
diff changeset
   872
    kfree(target);
755e6ce823f0 Implemented ecrt_master_sdo_upload() and ecrt_master_sdo_download() also for
Florian Pose <fp@igh-essen.com>
parents: 2061
diff changeset
   873
755e6ce823f0 Implemented ecrt_master_sdo_upload() and ecrt_master_sdo_download() also for
Florian Pose <fp@igh-essen.com>
parents: 2061
diff changeset
   874
    if (__copy_to_user((void __user *) arg, &data, sizeof(data))) {
755e6ce823f0 Implemented ecrt_master_sdo_upload() and ecrt_master_sdo_download() also for
Florian Pose <fp@igh-essen.com>
parents: 2061
diff changeset
   875
        return -EFAULT;
755e6ce823f0 Implemented ecrt_master_sdo_upload() and ecrt_master_sdo_download() also for
Florian Pose <fp@igh-essen.com>
parents: 2061
diff changeset
   876
    }
755e6ce823f0 Implemented ecrt_master_sdo_upload() and ecrt_master_sdo_download() also for
Florian Pose <fp@igh-essen.com>
parents: 2061
diff changeset
   877
755e6ce823f0 Implemented ecrt_master_sdo_upload() and ecrt_master_sdo_download() also for
Florian Pose <fp@igh-essen.com>
parents: 2061
diff changeset
   878
    return 0;
755e6ce823f0 Implemented ecrt_master_sdo_upload() and ecrt_master_sdo_download() also for
Florian Pose <fp@igh-essen.com>
parents: 2061
diff changeset
   879
}
755e6ce823f0 Implemented ecrt_master_sdo_upload() and ecrt_master_sdo_download() also for
Florian Pose <fp@igh-essen.com>
parents: 2061
diff changeset
   880
755e6ce823f0 Implemented ecrt_master_sdo_upload() and ecrt_master_sdo_download() also for
Florian Pose <fp@igh-essen.com>
parents: 2061
diff changeset
   881
/*****************************************************************************/
755e6ce823f0 Implemented ecrt_master_sdo_upload() and ecrt_master_sdo_download() also for
Florian Pose <fp@igh-essen.com>
parents: 2061
diff changeset
   882
755e6ce823f0 Implemented ecrt_master_sdo_upload() and ecrt_master_sdo_download() also for
Florian Pose <fp@igh-essen.com>
parents: 2061
diff changeset
   883
/** Download SDO.
755e6ce823f0 Implemented ecrt_master_sdo_upload() and ecrt_master_sdo_download() also for
Florian Pose <fp@igh-essen.com>
parents: 2061
diff changeset
   884
 */
755e6ce823f0 Implemented ecrt_master_sdo_upload() and ecrt_master_sdo_download() also for
Florian Pose <fp@igh-essen.com>
parents: 2061
diff changeset
   885
int ec_cdev_ioctl_slave_sdo_download(
755e6ce823f0 Implemented ecrt_master_sdo_upload() and ecrt_master_sdo_download() also for
Florian Pose <fp@igh-essen.com>
parents: 2061
diff changeset
   886
        ec_master_t *master, /**< EtherCAT master. */
755e6ce823f0 Implemented ecrt_master_sdo_upload() and ecrt_master_sdo_download() also for
Florian Pose <fp@igh-essen.com>
parents: 2061
diff changeset
   887
        unsigned long arg /**< ioctl() argument. */
755e6ce823f0 Implemented ecrt_master_sdo_upload() and ecrt_master_sdo_download() also for
Florian Pose <fp@igh-essen.com>
parents: 2061
diff changeset
   888
        )
755e6ce823f0 Implemented ecrt_master_sdo_upload() and ecrt_master_sdo_download() also for
Florian Pose <fp@igh-essen.com>
parents: 2061
diff changeset
   889
{
755e6ce823f0 Implemented ecrt_master_sdo_upload() and ecrt_master_sdo_download() also for
Florian Pose <fp@igh-essen.com>
parents: 2061
diff changeset
   890
    ec_ioctl_slave_sdo_download_t data;
755e6ce823f0 Implemented ecrt_master_sdo_upload() and ecrt_master_sdo_download() also for
Florian Pose <fp@igh-essen.com>
parents: 2061
diff changeset
   891
    uint8_t *sdo_data;
755e6ce823f0 Implemented ecrt_master_sdo_upload() and ecrt_master_sdo_download() also for
Florian Pose <fp@igh-essen.com>
parents: 2061
diff changeset
   892
    int retval;
755e6ce823f0 Implemented ecrt_master_sdo_upload() and ecrt_master_sdo_download() also for
Florian Pose <fp@igh-essen.com>
parents: 2061
diff changeset
   893
755e6ce823f0 Implemented ecrt_master_sdo_upload() and ecrt_master_sdo_download() also for
Florian Pose <fp@igh-essen.com>
parents: 2061
diff changeset
   894
    if (copy_from_user(&data, (void __user *) arg, sizeof(data))) {
755e6ce823f0 Implemented ecrt_master_sdo_upload() and ecrt_master_sdo_download() also for
Florian Pose <fp@igh-essen.com>
parents: 2061
diff changeset
   895
        return -EFAULT;
755e6ce823f0 Implemented ecrt_master_sdo_upload() and ecrt_master_sdo_download() also for
Florian Pose <fp@igh-essen.com>
parents: 2061
diff changeset
   896
    }
755e6ce823f0 Implemented ecrt_master_sdo_upload() and ecrt_master_sdo_download() also for
Florian Pose <fp@igh-essen.com>
parents: 2061
diff changeset
   897
755e6ce823f0 Implemented ecrt_master_sdo_upload() and ecrt_master_sdo_download() also for
Florian Pose <fp@igh-essen.com>
parents: 2061
diff changeset
   898
    if (!(sdo_data = kmalloc(data.data_size, GFP_KERNEL))) {
755e6ce823f0 Implemented ecrt_master_sdo_upload() and ecrt_master_sdo_download() also for
Florian Pose <fp@igh-essen.com>
parents: 2061
diff changeset
   899
        EC_MASTER_ERR(master, "Failed to allocate %u bytes"
755e6ce823f0 Implemented ecrt_master_sdo_upload() and ecrt_master_sdo_download() also for
Florian Pose <fp@igh-essen.com>
parents: 2061
diff changeset
   900
                " for SDO download.\n", data.data_size);
755e6ce823f0 Implemented ecrt_master_sdo_upload() and ecrt_master_sdo_download() also for
Florian Pose <fp@igh-essen.com>
parents: 2061
diff changeset
   901
        return -ENOMEM;
755e6ce823f0 Implemented ecrt_master_sdo_upload() and ecrt_master_sdo_download() also for
Florian Pose <fp@igh-essen.com>
parents: 2061
diff changeset
   902
    }
755e6ce823f0 Implemented ecrt_master_sdo_upload() and ecrt_master_sdo_download() also for
Florian Pose <fp@igh-essen.com>
parents: 2061
diff changeset
   903
755e6ce823f0 Implemented ecrt_master_sdo_upload() and ecrt_master_sdo_download() also for
Florian Pose <fp@igh-essen.com>
parents: 2061
diff changeset
   904
    if (copy_from_user(sdo_data, (void __user *) data.data, data.data_size)) {
755e6ce823f0 Implemented ecrt_master_sdo_upload() and ecrt_master_sdo_download() also for
Florian Pose <fp@igh-essen.com>
parents: 2061
diff changeset
   905
        kfree(sdo_data);
755e6ce823f0 Implemented ecrt_master_sdo_upload() and ecrt_master_sdo_download() also for
Florian Pose <fp@igh-essen.com>
parents: 2061
diff changeset
   906
        return -EFAULT;
755e6ce823f0 Implemented ecrt_master_sdo_upload() and ecrt_master_sdo_download() also for
Florian Pose <fp@igh-essen.com>
parents: 2061
diff changeset
   907
    }
755e6ce823f0 Implemented ecrt_master_sdo_upload() and ecrt_master_sdo_download() also for
Florian Pose <fp@igh-essen.com>
parents: 2061
diff changeset
   908
2124
c4afc5fede19 Added ecrt_master_sdo_download_complete() for ad-hoc downloading SDOs (also
Florian Pose <fp@igh-essen.com>
parents: 2109
diff changeset
   909
    if (data.complete_access) {
c4afc5fede19 Added ecrt_master_sdo_download_complete() for ad-hoc downloading SDOs (also
Florian Pose <fp@igh-essen.com>
parents: 2109
diff changeset
   910
        retval = ecrt_master_sdo_download_complete(master, data.slave_position,
c4afc5fede19 Added ecrt_master_sdo_download_complete() for ad-hoc downloading SDOs (also
Florian Pose <fp@igh-essen.com>
parents: 2109
diff changeset
   911
                data.sdo_index, sdo_data, data.data_size, &data.abort_code);
c4afc5fede19 Added ecrt_master_sdo_download_complete() for ad-hoc downloading SDOs (also
Florian Pose <fp@igh-essen.com>
parents: 2109
diff changeset
   912
    } else {
c4afc5fede19 Added ecrt_master_sdo_download_complete() for ad-hoc downloading SDOs (also
Florian Pose <fp@igh-essen.com>
parents: 2109
diff changeset
   913
        retval = ecrt_master_sdo_download(master, data.slave_position,
c4afc5fede19 Added ecrt_master_sdo_download_complete() for ad-hoc downloading SDOs (also
Florian Pose <fp@igh-essen.com>
parents: 2109
diff changeset
   914
                data.sdo_index, data.sdo_entry_subindex, sdo_data,
c4afc5fede19 Added ecrt_master_sdo_download_complete() for ad-hoc downloading SDOs (also
Florian Pose <fp@igh-essen.com>
parents: 2109
diff changeset
   915
                data.data_size, &data.abort_code);
c4afc5fede19 Added ecrt_master_sdo_download_complete() for ad-hoc downloading SDOs (also
Florian Pose <fp@igh-essen.com>
parents: 2109
diff changeset
   916
    }
2109
755e6ce823f0 Implemented ecrt_master_sdo_upload() and ecrt_master_sdo_download() also for
Florian Pose <fp@igh-essen.com>
parents: 2061
diff changeset
   917
755e6ce823f0 Implemented ecrt_master_sdo_upload() and ecrt_master_sdo_download() also for
Florian Pose <fp@igh-essen.com>
parents: 2061
diff changeset
   918
    kfree(sdo_data);
1079
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   919
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   920
    if (__copy_to_user((void __user *) arg, &data, sizeof(data))) {
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   921
        retval = -EFAULT;
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   922
    }
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   923
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   924
    return retval;
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   925
}
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   926
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   927
/*****************************************************************************/
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   928
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   929
/** Read a slave's SII.
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   930
 */
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   931
int ec_cdev_ioctl_slave_sii_read(
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   932
        ec_master_t *master, /**< EtherCAT master. */
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   933
        unsigned long arg /**< ioctl() argument. */
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   934
        )
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   935
{
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   936
    ec_ioctl_slave_sii_t data;
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   937
    const ec_slave_t *slave;
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   938
    int retval;
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   939
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   940
    if (copy_from_user(&data, (void __user *) arg, sizeof(data))) {
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   941
        return -EFAULT;
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   942
    }
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   943
1189
acc6430bfb32 Use down_interruptible() wherever possible.
Florian Pose <fp@igh-essen.com>
parents: 1183
diff changeset
   944
    if (down_interruptible(&master->master_sem))
acc6430bfb32 Use down_interruptible() wherever possible.
Florian Pose <fp@igh-essen.com>
parents: 1183
diff changeset
   945
        return -EINTR;
1079
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   946
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   947
    if (!(slave = ec_master_find_slave_const(
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   948
                    master, 0, data.slave_position))) {
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   949
        up(&master->master_sem);
1921
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1909
diff changeset
   950
        EC_MASTER_ERR(master, "Slave %u does not exist!\n",
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1909
diff changeset
   951
                data.slave_position);
1079
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   952
        return -EINVAL;
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   953
    }
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   954
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   955
    if (!data.nwords
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   956
            || data.offset + data.nwords > slave->sii_nwords) {
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   957
        up(&master->master_sem);
1921
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1909
diff changeset
   958
        EC_SLAVE_ERR(slave, "Invalid SII read offset/size %u/%u for slave SII"
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1909
diff changeset
   959
                " size %zu!\n", data.offset, data.nwords, slave->sii_nwords);
1079
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   960
        return -EINVAL;
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   961
    }
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   962
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   963
    if (copy_to_user((void __user *) data.words,
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   964
                slave->sii_words + data.offset, data.nwords * 2))
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   965
        retval = -EFAULT;
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   966
    else
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   967
        retval = 0;
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   968
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   969
    up(&master->master_sem);
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   970
    return retval;
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   971
}
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   972
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   973
/*****************************************************************************/
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   974
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   975
/** Write a slave's SII.
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   976
 */
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   977
int ec_cdev_ioctl_slave_sii_write(
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   978
        ec_master_t *master, /**< EtherCAT master. */
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   979
        unsigned long arg /**< ioctl() argument. */
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   980
        )
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   981
{
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   982
    ec_ioctl_slave_sii_t data;
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   983
    ec_slave_t *slave;
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   984
    unsigned int byte_size;
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   985
    uint16_t *words;
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   986
    ec_sii_write_request_t request;
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   987
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   988
    if (copy_from_user(&data, (void __user *) arg, sizeof(data))) {
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   989
        return -EFAULT;
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   990
    }
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   991
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   992
    if (!data.nwords)
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   993
        return 0;
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   994
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   995
    byte_size = sizeof(uint16_t) * data.nwords;
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   996
    if (!(words = kmalloc(byte_size, GFP_KERNEL))) {
1921
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1909
diff changeset
   997
        EC_MASTER_ERR(master, "Failed to allocate %u bytes"
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1909
diff changeset
   998
                " for SII contents.\n", byte_size);
1079
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   999
        return -ENOMEM;
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1000
    }
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1001
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1002
    if (copy_from_user(words,
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1003
                (void __user *) data.words, byte_size)) {
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1004
        kfree(words);
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1005
        return -EFAULT;
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1006
    }
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1007
1189
acc6430bfb32 Use down_interruptible() wherever possible.
Florian Pose <fp@igh-essen.com>
parents: 1183
diff changeset
  1008
    if (down_interruptible(&master->master_sem))
acc6430bfb32 Use down_interruptible() wherever possible.
Florian Pose <fp@igh-essen.com>
parents: 1183
diff changeset
  1009
        return -EINTR;
1079
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1010
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1011
    if (!(slave = ec_master_find_slave(
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1012
                    master, 0, data.slave_position))) {
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1013
        up(&master->master_sem);
1921
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1909
diff changeset
  1014
        EC_MASTER_ERR(master, "Slave %u does not exist!\n",
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1909
diff changeset
  1015
                data.slave_position);
1079
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1016
        kfree(words);
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1017
        return -EINVAL;
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1018
    }
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1019
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1020
    // init SII write request
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1021
    INIT_LIST_HEAD(&request.list);
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1022
    request.slave = slave;
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1023
    request.words = words;
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1024
    request.offset = data.offset;
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1025
    request.nwords = data.nwords;
1209
8be462afb7f4 Added VoE handler.
Florian Pose <fp@igh-essen.com>
parents: 1200
diff changeset
  1026
    request.state = EC_INT_REQUEST_QUEUED;
1079
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1027
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1028
    // schedule SII write request.
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1029
    list_add_tail(&request.list, &master->sii_requests);
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1030
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1031
    up(&master->master_sem);
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1032
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1033
    // wait for processing through FSM
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1034
    if (wait_event_interruptible(master->sii_queue,
1209
8be462afb7f4 Added VoE handler.
Florian Pose <fp@igh-essen.com>
parents: 1200
diff changeset
  1035
                request.state != EC_INT_REQUEST_QUEUED)) {
1079
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1036
        // interrupted by signal
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1037
        down(&master->master_sem);
1209
8be462afb7f4 Added VoE handler.
Florian Pose <fp@igh-essen.com>
parents: 1200
diff changeset
  1038
        if (request.state == EC_INT_REQUEST_QUEUED) {
1079
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1039
            // abort request
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1040
            list_del(&request.list);
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1041
            up(&master->master_sem);
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1042
            kfree(words);
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1043
            return -EINTR;
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1044
        }
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1045
        up(&master->master_sem);
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1046
    }
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1047
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1048
    // wait until master FSM has finished processing
1209
8be462afb7f4 Added VoE handler.
Florian Pose <fp@igh-essen.com>
parents: 1200
diff changeset
  1049
    wait_event(master->sii_queue, request.state != EC_INT_REQUEST_BUSY);
1079
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1050
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1051
    kfree(words);
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1052
1209
8be462afb7f4 Added VoE handler.
Florian Pose <fp@igh-essen.com>
parents: 1200
diff changeset
  1053
    return request.state == EC_INT_REQUEST_SUCCESS ? 0 : -EIO;
1079
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1054
}
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1055
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1056
/*****************************************************************************/
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1057
1388
3c886ec376f5 Renamed phy_ commands to reg_.
Florian Pose <fp@igh-essen.com>
parents: 1382
diff changeset
  1058
/** Read a slave's registers.
3c886ec376f5 Renamed phy_ commands to reg_.
Florian Pose <fp@igh-essen.com>
parents: 1382
diff changeset
  1059
 */
3c886ec376f5 Renamed phy_ commands to reg_.
Florian Pose <fp@igh-essen.com>
parents: 1382
diff changeset
  1060
int ec_cdev_ioctl_slave_reg_read(
1200
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1196
diff changeset
  1061
        ec_master_t *master, /**< EtherCAT master. */
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1196
diff changeset
  1062
        unsigned long arg /**< ioctl() argument. */
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1196
diff changeset
  1063
        )
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1196
diff changeset
  1064
{
1388
3c886ec376f5 Renamed phy_ commands to reg_.
Florian Pose <fp@igh-essen.com>
parents: 1382
diff changeset
  1065
    ec_ioctl_slave_reg_t data;
1200
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1196
diff changeset
  1066
    ec_slave_t *slave;
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1196
diff changeset
  1067
    uint8_t *contents;
1388
3c886ec376f5 Renamed phy_ commands to reg_.
Florian Pose <fp@igh-essen.com>
parents: 1382
diff changeset
  1068
    ec_reg_request_t request;
1200
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1196
diff changeset
  1069
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1196
diff changeset
  1070
    if (copy_from_user(&data, (void __user *) arg, sizeof(data))) {
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1196
diff changeset
  1071
        return -EFAULT;
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1196
diff changeset
  1072
    }
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1196
diff changeset
  1073
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1196
diff changeset
  1074
    if (!data.length)
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1196
diff changeset
  1075
        return 0;
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1196
diff changeset
  1076
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1196
diff changeset
  1077
    if (!(contents = kmalloc(data.length, GFP_KERNEL))) {
1921
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1909
diff changeset
  1078
        EC_MASTER_ERR(master, "Failed to allocate %u bytes"
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1909
diff changeset
  1079
                " for register data.\n", data.length);
1200
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1196
diff changeset
  1080
        return -ENOMEM;
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1196
diff changeset
  1081
    }
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1196
diff changeset
  1082
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1196
diff changeset
  1083
    if (down_interruptible(&master->master_sem))
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1196
diff changeset
  1084
        return -EINTR;
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1196
diff changeset
  1085
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1196
diff changeset
  1086
    if (!(slave = ec_master_find_slave(
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1196
diff changeset
  1087
                    master, 0, data.slave_position))) {
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1196
diff changeset
  1088
        up(&master->master_sem);
1921
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1909
diff changeset
  1089
        EC_MASTER_ERR(master, "Slave %u does not exist!\n",
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1909
diff changeset
  1090
                data.slave_position);
1200
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1196
diff changeset
  1091
        return -EINVAL;
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1196
diff changeset
  1092
    }
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1196
diff changeset
  1093
1388
3c886ec376f5 Renamed phy_ commands to reg_.
Florian Pose <fp@igh-essen.com>
parents: 1382
diff changeset
  1094
    // init register request
1200
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1196
diff changeset
  1095
    INIT_LIST_HEAD(&request.list);
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1196
diff changeset
  1096
    request.slave = slave;
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1196
diff changeset
  1097
    request.dir = EC_DIR_INPUT;
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1196
diff changeset
  1098
    request.data = contents;
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1196
diff changeset
  1099
    request.offset = data.offset;
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1196
diff changeset
  1100
    request.length = data.length;
1209
8be462afb7f4 Added VoE handler.
Florian Pose <fp@igh-essen.com>
parents: 1200
diff changeset
  1101
    request.state = EC_INT_REQUEST_QUEUED;
1200
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1196
diff changeset
  1102
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1196
diff changeset
  1103
    // schedule request.
1388
3c886ec376f5 Renamed phy_ commands to reg_.
Florian Pose <fp@igh-essen.com>
parents: 1382
diff changeset
  1104
    list_add_tail(&request.list, &master->reg_requests);
1200
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1196
diff changeset
  1105
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1196
diff changeset
  1106
    up(&master->master_sem);
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1196
diff changeset
  1107
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1196
diff changeset
  1108
    // wait for processing through FSM
1388
3c886ec376f5 Renamed phy_ commands to reg_.
Florian Pose <fp@igh-essen.com>
parents: 1382
diff changeset
  1109
    if (wait_event_interruptible(master->reg_queue,
1209
8be462afb7f4 Added VoE handler.
Florian Pose <fp@igh-essen.com>
parents: 1200
diff changeset
  1110
                request.state != EC_INT_REQUEST_QUEUED)) {
1200
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1196
diff changeset
  1111
        // interrupted by signal
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1196
diff changeset
  1112
        down(&master->master_sem);
1209
8be462afb7f4 Added VoE handler.
Florian Pose <fp@igh-essen.com>
parents: 1200
diff changeset
  1113
        if (request.state == EC_INT_REQUEST_QUEUED) {
1200
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1196
diff changeset
  1114
            // abort request
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1196
diff changeset
  1115
            list_del(&request.list);
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1196
diff changeset
  1116
            up(&master->master_sem);
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1196
diff changeset
  1117
            kfree(contents);
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1196
diff changeset
  1118
            return -EINTR;
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1196
diff changeset
  1119
        }
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1196
diff changeset
  1120
        up(&master->master_sem);
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1196
diff changeset
  1121
    }
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1196
diff changeset
  1122
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1196
diff changeset
  1123
    // wait until master FSM has finished processing
1388
3c886ec376f5 Renamed phy_ commands to reg_.
Florian Pose <fp@igh-essen.com>
parents: 1382
diff changeset
  1124
    wait_event(master->reg_queue, request.state != EC_INT_REQUEST_BUSY);
1209
8be462afb7f4 Added VoE handler.
Florian Pose <fp@igh-essen.com>
parents: 1200
diff changeset
  1125
8be462afb7f4 Added VoE handler.
Florian Pose <fp@igh-essen.com>
parents: 1200
diff changeset
  1126
    if (request.state == EC_INT_REQUEST_SUCCESS) {
1200
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1196
diff changeset
  1127
        if (copy_to_user((void __user *) data.data, contents, data.length))
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1196
diff changeset
  1128
            return -EFAULT;
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1196
diff changeset
  1129
    }
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1196
diff changeset
  1130
    kfree(contents);
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1196
diff changeset
  1131
1209
8be462afb7f4 Added VoE handler.
Florian Pose <fp@igh-essen.com>
parents: 1200
diff changeset
  1132
    return request.state == EC_INT_REQUEST_SUCCESS ? 0 : -EIO;
1200
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1196
diff changeset
  1133
}
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1196
diff changeset
  1134
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1196
diff changeset
  1135
/*****************************************************************************/
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1196
diff changeset
  1136
1388
3c886ec376f5 Renamed phy_ commands to reg_.
Florian Pose <fp@igh-essen.com>
parents: 1382
diff changeset
  1137
/** Write a slave's registers.
3c886ec376f5 Renamed phy_ commands to reg_.
Florian Pose <fp@igh-essen.com>
parents: 1382
diff changeset
  1138
 */
3c886ec376f5 Renamed phy_ commands to reg_.
Florian Pose <fp@igh-essen.com>
parents: 1382
diff changeset
  1139
int ec_cdev_ioctl_slave_reg_write(
1200
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1196
diff changeset
  1140
        ec_master_t *master, /**< EtherCAT master. */
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1196
diff changeset
  1141
        unsigned long arg /**< ioctl() argument. */
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1196
diff changeset
  1142
        )
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1196
diff changeset
  1143
{
1388
3c886ec376f5 Renamed phy_ commands to reg_.
Florian Pose <fp@igh-essen.com>
parents: 1382
diff changeset
  1144
    ec_ioctl_slave_reg_t data;
1200
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1196
diff changeset
  1145
    ec_slave_t *slave;
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1196
diff changeset
  1146
    uint8_t *contents;
1388
3c886ec376f5 Renamed phy_ commands to reg_.
Florian Pose <fp@igh-essen.com>
parents: 1382
diff changeset
  1147
    ec_reg_request_t request;
1200
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1196
diff changeset
  1148
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1196
diff changeset
  1149
    if (copy_from_user(&data, (void __user *) arg, sizeof(data))) {
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1196
diff changeset
  1150
        return -EFAULT;
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1196
diff changeset
  1151
    }
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1196
diff changeset
  1152
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1196
diff changeset
  1153
    if (!data.length)
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1196
diff changeset
  1154
        return 0;
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1196
diff changeset
  1155
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1196
diff changeset
  1156
    if (!(contents = kmalloc(data.length, GFP_KERNEL))) {
1921
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1909
diff changeset
  1157
        EC_MASTER_ERR(master, "Failed to allocate %u bytes"
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1909
diff changeset
  1158
                " for register data.\n", data.length);
1200
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1196
diff changeset
  1159
        return -ENOMEM;
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1196
diff changeset
  1160
    }
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1196
diff changeset
  1161
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1196
diff changeset
  1162
    if (copy_from_user(contents, (void __user *) data.data, data.length)) {
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1196
diff changeset
  1163
        kfree(contents);
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1196
diff changeset
  1164
        return -EFAULT;
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1196
diff changeset
  1165
    }
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1196
diff changeset
  1166
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1196
diff changeset
  1167
    if (down_interruptible(&master->master_sem))
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1196
diff changeset
  1168
        return -EINTR;
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1196
diff changeset
  1169
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1196
diff changeset
  1170
    if (!(slave = ec_master_find_slave(
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1196
diff changeset
  1171
                    master, 0, data.slave_position))) {
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1196
diff changeset
  1172
        up(&master->master_sem);
1921
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1909
diff changeset
  1173
        EC_MASTER_ERR(master, "Slave %u does not exist!\n",
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1909
diff changeset
  1174
                data.slave_position);
1200
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1196
diff changeset
  1175
        kfree(contents);
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1196
diff changeset
  1176
        return -EINVAL;
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1196
diff changeset
  1177
    }
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1196
diff changeset
  1178
1388
3c886ec376f5 Renamed phy_ commands to reg_.
Florian Pose <fp@igh-essen.com>
parents: 1382
diff changeset
  1179
    // init register request
1200
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1196
diff changeset
  1180
    INIT_LIST_HEAD(&request.list);
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1196
diff changeset
  1181
    request.slave = slave;
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1196
diff changeset
  1182
    request.dir = EC_DIR_OUTPUT;
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1196
diff changeset
  1183
    request.data = contents;
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1196
diff changeset
  1184
    request.offset = data.offset;
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1196
diff changeset
  1185
    request.length = data.length;
1209
8be462afb7f4 Added VoE handler.
Florian Pose <fp@igh-essen.com>
parents: 1200
diff changeset
  1186
    request.state = EC_INT_REQUEST_QUEUED;
1200
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1196
diff changeset
  1187
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1196
diff changeset
  1188
    // schedule request.
1388
3c886ec376f5 Renamed phy_ commands to reg_.
Florian Pose <fp@igh-essen.com>
parents: 1382
diff changeset
  1189
    list_add_tail(&request.list, &master->reg_requests);
1200
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1196
diff changeset
  1190
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1196
diff changeset
  1191
    up(&master->master_sem);
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1196
diff changeset
  1192
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1196
diff changeset
  1193
    // wait for processing through FSM
1388
3c886ec376f5 Renamed phy_ commands to reg_.
Florian Pose <fp@igh-essen.com>
parents: 1382
diff changeset
  1194
    if (wait_event_interruptible(master->reg_queue,
1209
8be462afb7f4 Added VoE handler.
Florian Pose <fp@igh-essen.com>
parents: 1200
diff changeset
  1195
                request.state != EC_INT_REQUEST_QUEUED)) {
1200
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1196
diff changeset
  1196
        // interrupted by signal
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1196
diff changeset
  1197
        down(&master->master_sem);
1209
8be462afb7f4 Added VoE handler.
Florian Pose <fp@igh-essen.com>
parents: 1200
diff changeset
  1198
        if (request.state == EC_INT_REQUEST_QUEUED) {
1200
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1196
diff changeset
  1199
            // abort request
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1196
diff changeset
  1200
            list_del(&request.list);
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1196
diff changeset
  1201
            up(&master->master_sem);
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1196
diff changeset
  1202
            kfree(contents);
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1196
diff changeset
  1203
            return -EINTR;
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1196
diff changeset
  1204
        }
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1196
diff changeset
  1205
        up(&master->master_sem);
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1196
diff changeset
  1206
    }
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1196
diff changeset
  1207
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1196
diff changeset
  1208
    // wait until master FSM has finished processing
1388
3c886ec376f5 Renamed phy_ commands to reg_.
Florian Pose <fp@igh-essen.com>
parents: 1382
diff changeset
  1209
    wait_event(master->reg_queue, request.state != EC_INT_REQUEST_BUSY);
1200
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1196
diff changeset
  1210
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1196
diff changeset
  1211
    kfree(contents);
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1196
diff changeset
  1212
1209
8be462afb7f4 Added VoE handler.
Florian Pose <fp@igh-essen.com>
parents: 1200
diff changeset
  1213
    return request.state == EC_INT_REQUEST_SUCCESS ? 0 : -EIO;
1200
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1196
diff changeset
  1214
}
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1196
diff changeset
  1215
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1196
diff changeset
  1216
/*****************************************************************************/
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1196
diff changeset
  1217
1079
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1218
/** Get slave configuration information.
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1219
 */
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1220
int ec_cdev_ioctl_config(
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1221
        ec_master_t *master, /**< EtherCAT master. */
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1222
        unsigned long arg /**< ioctl() argument. */
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1223
        )
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1224
{
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1225
    ec_ioctl_config_t data;
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1226
    const ec_slave_config_t *sc;
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1227
    uint8_t i;
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1228
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1229
    if (copy_from_user(&data, (void __user *) arg, sizeof(data))) {
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1230
        return -EFAULT;
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1231
    }
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1232
1189
acc6430bfb32 Use down_interruptible() wherever possible.
Florian Pose <fp@igh-essen.com>
parents: 1183
diff changeset
  1233
    if (down_interruptible(&master->master_sem))
acc6430bfb32 Use down_interruptible() wherever possible.
Florian Pose <fp@igh-essen.com>
parents: 1183
diff changeset
  1234
        return -EINTR;
1079
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1235
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1236
    if (!(sc = ec_master_get_config_const(
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1237
                    master, data.config_index))) {
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1238
        up(&master->master_sem);
1921
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1909
diff changeset
  1239
        EC_MASTER_ERR(master, "Slave config %u does not exist!\n",
1079
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1240
                data.config_index);
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1241
        return -EINVAL;
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1242
    }
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1243
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1244
    data.alias = sc->alias;
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1245
    data.position = sc->position;
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1246
    data.vendor_id = sc->vendor_id;
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1247
    data.product_code = sc->product_code;
1082
ff06c58e269c Renamed ecrt_slave_config_sync_managers() to ecrt_slave_config_pdos();
Florian Pose <fp@igh-essen.com>
parents: 1079
diff changeset
  1248
    for (i = 0; i < EC_MAX_SYNC_MANAGERS; i++) {
1079
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1249
        data.syncs[i].dir = sc->sync_configs[i].dir;
1518
ab5694a51826 Output watchdog configuration in ethercat config.
Florian Pose <fp@igh-essen.com>
parents: 1516
diff changeset
  1250
        data.syncs[i].watchdog_mode = sc->sync_configs[i].watchdog_mode;
1079
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1251
        data.syncs[i].pdo_count =
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1252
            ec_pdo_list_count(&sc->sync_configs[i].pdos);
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1253
    }
1518
ab5694a51826 Output watchdog configuration in ethercat config.
Florian Pose <fp@igh-essen.com>
parents: 1516
diff changeset
  1254
    data.watchdog_divider = sc->watchdog_divider;
ab5694a51826 Output watchdog configuration in ethercat config.
Florian Pose <fp@igh-essen.com>
parents: 1516
diff changeset
  1255
    data.watchdog_intervals = sc->watchdog_intervals;
1079
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1256
    data.sdo_count = ec_slave_config_sdo_count(sc);
1966
23c638a81fe7 Output IDN configuration as part of 'ethercat config -v'.
Florian Pose <fp@igh-essen.com>
parents: 1963
diff changeset
  1257
    data.idn_count = ec_slave_config_idn_count(sc);
1147
0eac1ee8512a Show attached slave position and state in 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 1109
diff changeset
  1258
    data.slave_position = sc->slave ? sc->slave->ring_position : -1;
1455
aa18fcfe0fd1 Output DC config in 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 1454
diff changeset
  1259
    data.dc_assign_activate = sc->dc_assign_activate;
aa18fcfe0fd1 Output DC config in 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 1454
diff changeset
  1260
    for (i = 0; i < EC_SYNC_SIGNAL_COUNT; i++) {
aa18fcfe0fd1 Output DC config in 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 1454
diff changeset
  1261
        data.dc_sync[i] = sc->dc_sync[i];
aa18fcfe0fd1 Output DC config in 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 1454
diff changeset
  1262
    }
1079
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1263
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1264
    up(&master->master_sem);
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1265
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1266
    if (copy_to_user((void __user *) arg, &data, sizeof(data)))
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1267
        return -EFAULT;
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1268
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1269
    return 0;
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1270
}
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1271
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1272
/*****************************************************************************/
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1273
1327
4d179b06dd3c merge -c1604 branches/stable-1.4: Fixed spelling of EtherCAT terms.
Florian Pose <fp@igh-essen.com>
parents: 1326
diff changeset
  1274
/** Get slave configuration PDO information.
1079
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1275
 */
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1276
int ec_cdev_ioctl_config_pdo(
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1277
        ec_master_t *master, /**< EtherCAT master. */
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1278
        unsigned long arg /**< ioctl() argument. */
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1279
        )
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1280
{
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1281
    ec_ioctl_config_pdo_t data;
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1282
    const ec_slave_config_t *sc;
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1283
    const ec_pdo_t *pdo;
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1284
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1285
    if (copy_from_user(&data, (void __user *) arg, sizeof(data))) {
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1286
        return -EFAULT;
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1287
    }
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1288
1082
ff06c58e269c Renamed ecrt_slave_config_sync_managers() to ecrt_slave_config_pdos();
Florian Pose <fp@igh-essen.com>
parents: 1079
diff changeset
  1289
    if (data.sync_index >= EC_MAX_SYNC_MANAGERS) {
1921
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1909
diff changeset
  1290
        EC_MASTER_ERR(master, "Invalid sync manager index %u!\n",
1079
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1291
                data.sync_index);
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1292
        return -EINVAL;
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1293
    }
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1294
1189
acc6430bfb32 Use down_interruptible() wherever possible.
Florian Pose <fp@igh-essen.com>
parents: 1183
diff changeset
  1295
    if (down_interruptible(&master->master_sem))
acc6430bfb32 Use down_interruptible() wherever possible.
Florian Pose <fp@igh-essen.com>
parents: 1183
diff changeset
  1296
        return -EINTR;
1079
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1297
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1298
    if (!(sc = ec_master_get_config_const(
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1299
                    master, data.config_index))) {
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1300
        up(&master->master_sem);
1921
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1909
diff changeset
  1301
        EC_MASTER_ERR(master, "Slave config %u does not exist!\n",
1079
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1302
                data.config_index);
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1303
        return -EINVAL;
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1304
    }
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1305
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1306
    if (!(pdo = ec_pdo_list_find_pdo_by_pos_const(
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1307
                    &sc->sync_configs[data.sync_index].pdos,
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1308
                    data.pdo_pos))) {
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1309
        up(&master->master_sem);
1921
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1909
diff changeset
  1310
        EC_MASTER_ERR(master, "Invalid PDO position!\n");
1079
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1311
        return -EINVAL;
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1312
    }
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1313
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1314
    data.index = pdo->index;
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1315
    data.entry_count = ec_pdo_entry_count(pdo);
1108
7beba3e7e6b4 Added ec_cdev_strcpy() function.
Florian Pose <fp@igh-essen.com>
parents: 1092
diff changeset
  1316
    ec_cdev_strcpy(data.name, pdo->name);
1079
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1317
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1318
    up(&master->master_sem);
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1319
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1320
    if (copy_to_user((void __user *) arg, &data, sizeof(data)))
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1321
        return -EFAULT;
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1322
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1323
    return 0;
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1324
}
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1325
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1326
/*****************************************************************************/
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1327
1327
4d179b06dd3c merge -c1604 branches/stable-1.4: Fixed spelling of EtherCAT terms.
Florian Pose <fp@igh-essen.com>
parents: 1326
diff changeset
  1328
/** Get slave configuration PDO entry information.
1079
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1329
 */
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1330
int ec_cdev_ioctl_config_pdo_entry(
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1331
        ec_master_t *master, /**< EtherCAT master. */
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1332
        unsigned long arg /**< ioctl() argument. */
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1333
        )
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1334
{
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1335
    ec_ioctl_config_pdo_entry_t data;
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1336
    const ec_slave_config_t *sc;
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1337
    const ec_pdo_t *pdo;
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1338
    const ec_pdo_entry_t *entry;
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1339
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1340
    if (copy_from_user(&data, (void __user *) arg, sizeof(data))) {
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1341
        return -EFAULT;
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1342
    }
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1343
1082
ff06c58e269c Renamed ecrt_slave_config_sync_managers() to ecrt_slave_config_pdos();
Florian Pose <fp@igh-essen.com>
parents: 1079
diff changeset
  1344
    if (data.sync_index >= EC_MAX_SYNC_MANAGERS) {
1921
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1909
diff changeset
  1345
        EC_MASTER_ERR(master, "Invalid sync manager index %u!\n",
1079
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1346
                data.sync_index);
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1347
        return -EINVAL;
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1348
    }
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1349
1189
acc6430bfb32 Use down_interruptible() wherever possible.
Florian Pose <fp@igh-essen.com>
parents: 1183
diff changeset
  1350
    if (down_interruptible(&master->master_sem))
acc6430bfb32 Use down_interruptible() wherever possible.
Florian Pose <fp@igh-essen.com>
parents: 1183
diff changeset
  1351
        return -EINTR;
1079
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1352
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1353
    if (!(sc = ec_master_get_config_const(
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1354
                    master, data.config_index))) {
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1355
        up(&master->master_sem);
1921
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1909
diff changeset
  1356
        EC_MASTER_ERR(master, "Slave config %u does not exist!\n",
1079
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1357
                data.config_index);
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1358
        return -EINVAL;
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1359
    }
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1360
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1361
    if (!(pdo = ec_pdo_list_find_pdo_by_pos_const(
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1362
                    &sc->sync_configs[data.sync_index].pdos,
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1363
                    data.pdo_pos))) {
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1364
        up(&master->master_sem);
1921
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1909
diff changeset
  1365
        EC_MASTER_ERR(master, "Invalid PDO position!\n");
1079
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1366
        return -EINVAL;
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1367
    }
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1368
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1369
    if (!(entry = ec_pdo_find_entry_by_pos_const(
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1370
                    pdo, data.entry_pos))) {
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1371
        up(&master->master_sem);
1921
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1909
diff changeset
  1372
        EC_MASTER_ERR(master, "Entry not found!\n");
1079
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1373
        return -EINVAL;
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1374
    }
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1375
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1376
    data.index = entry->index;
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1377
    data.subindex = entry->subindex;
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1378
    data.bit_length = entry->bit_length;
1108
7beba3e7e6b4 Added ec_cdev_strcpy() function.
Florian Pose <fp@igh-essen.com>
parents: 1092
diff changeset
  1379
    ec_cdev_strcpy(data.name, entry->name);
1079
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1380
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1381
    up(&master->master_sem);
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1382
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1383
    if (copy_to_user((void __user *) arg, &data, sizeof(data)))
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1384
        return -EFAULT;
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1385
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1386
    return 0;
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1387
}
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1388
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1389
/*****************************************************************************/
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1390
1327
4d179b06dd3c merge -c1604 branches/stable-1.4: Fixed spelling of EtherCAT terms.
Florian Pose <fp@igh-essen.com>
parents: 1326
diff changeset
  1391
/** Get slave configuration SDO information.
1079
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1392
 */
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1393
int ec_cdev_ioctl_config_sdo(
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1394
        ec_master_t *master, /**< EtherCAT master. */
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1395
        unsigned long arg /**< ioctl() argument. */
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1396
        )
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1397
{
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1398
    ec_ioctl_config_sdo_t data;
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1399
    const ec_slave_config_t *sc;
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1400
    const ec_sdo_request_t *req;
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1401
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1402
    if (copy_from_user(&data, (void __user *) arg, sizeof(data))) {
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1403
        return -EFAULT;
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1404
    }
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1405
1189
acc6430bfb32 Use down_interruptible() wherever possible.
Florian Pose <fp@igh-essen.com>
parents: 1183
diff changeset
  1406
    if (down_interruptible(&master->master_sem))
acc6430bfb32 Use down_interruptible() wherever possible.
Florian Pose <fp@igh-essen.com>
parents: 1183
diff changeset
  1407
        return -EINTR;
1079
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1408
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1409
    if (!(sc = ec_master_get_config_const(
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1410
                    master, data.config_index))) {
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1411
        up(&master->master_sem);
1921
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1909
diff changeset
  1412
        EC_MASTER_ERR(master, "Slave config %u does not exist!\n",
1079
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1413
                data.config_index);
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1414
        return -EINVAL;
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1415
    }
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1416
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1417
    if (!(req = ec_slave_config_get_sdo_by_pos_const(
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1418
                    sc, data.sdo_pos))) {
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1419
        up(&master->master_sem);
1921
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1909
diff changeset
  1420
        EC_MASTER_ERR(master, "Invalid SDO position!\n");
1079
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1421
        return -EINVAL;
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1422
    }
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1423
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1424
    data.index = req->index;
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1425
    data.subindex = req->subindex;
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1426
    data.size = req->data_size;
1526
66edd310830c Implemented CompleteAccess for SDO downloads.
Florian Pose <fp@igh-essen.com>
parents: 1518
diff changeset
  1427
    memcpy(&data.data, req->data,
66edd310830c Implemented CompleteAccess for SDO downloads.
Florian Pose <fp@igh-essen.com>
parents: 1518
diff changeset
  1428
            min((u32) data.size, (u32) EC_MAX_SDO_DATA_SIZE));
1079
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1429
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1430
    up(&master->master_sem);
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1431
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1432
    if (copy_to_user((void __user *) arg, &data, sizeof(data)))
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1433
        return -EFAULT;
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1434
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1435
    return 0;
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1436
}
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1437
1242
632a6b91f8e4 First version of userspace library with requesting/releasing.
Florian Pose <fp@igh-essen.com>
parents: 1223
diff changeset
  1438
/*****************************************************************************/
632a6b91f8e4 First version of userspace library with requesting/releasing.
Florian Pose <fp@igh-essen.com>
parents: 1223
diff changeset
  1439
1966
23c638a81fe7 Output IDN configuration as part of 'ethercat config -v'.
Florian Pose <fp@igh-essen.com>
parents: 1963
diff changeset
  1440
/** Get slave configuration IDN information.
23c638a81fe7 Output IDN configuration as part of 'ethercat config -v'.
Florian Pose <fp@igh-essen.com>
parents: 1963
diff changeset
  1441
 */
23c638a81fe7 Output IDN configuration as part of 'ethercat config -v'.
Florian Pose <fp@igh-essen.com>
parents: 1963
diff changeset
  1442
int ec_cdev_ioctl_config_idn(
23c638a81fe7 Output IDN configuration as part of 'ethercat config -v'.
Florian Pose <fp@igh-essen.com>
parents: 1963
diff changeset
  1443
        ec_master_t *master, /**< EtherCAT master. */
23c638a81fe7 Output IDN configuration as part of 'ethercat config -v'.
Florian Pose <fp@igh-essen.com>
parents: 1963
diff changeset
  1444
        unsigned long arg /**< ioctl() argument. */
23c638a81fe7 Output IDN configuration as part of 'ethercat config -v'.
Florian Pose <fp@igh-essen.com>
parents: 1963
diff changeset
  1445
        )
23c638a81fe7 Output IDN configuration as part of 'ethercat config -v'.
Florian Pose <fp@igh-essen.com>
parents: 1963
diff changeset
  1446
{
23c638a81fe7 Output IDN configuration as part of 'ethercat config -v'.
Florian Pose <fp@igh-essen.com>
parents: 1963
diff changeset
  1447
    ec_ioctl_config_idn_t data;
23c638a81fe7 Output IDN configuration as part of 'ethercat config -v'.
Florian Pose <fp@igh-essen.com>
parents: 1963
diff changeset
  1448
    const ec_slave_config_t *sc;
23c638a81fe7 Output IDN configuration as part of 'ethercat config -v'.
Florian Pose <fp@igh-essen.com>
parents: 1963
diff changeset
  1449
    const ec_soe_request_t *req;
23c638a81fe7 Output IDN configuration as part of 'ethercat config -v'.
Florian Pose <fp@igh-essen.com>
parents: 1963
diff changeset
  1450
23c638a81fe7 Output IDN configuration as part of 'ethercat config -v'.
Florian Pose <fp@igh-essen.com>
parents: 1963
diff changeset
  1451
    if (copy_from_user(&data, (void __user *) arg, sizeof(data))) {
23c638a81fe7 Output IDN configuration as part of 'ethercat config -v'.
Florian Pose <fp@igh-essen.com>
parents: 1963
diff changeset
  1452
        return -EFAULT;
23c638a81fe7 Output IDN configuration as part of 'ethercat config -v'.
Florian Pose <fp@igh-essen.com>
parents: 1963
diff changeset
  1453
    }
23c638a81fe7 Output IDN configuration as part of 'ethercat config -v'.
Florian Pose <fp@igh-essen.com>
parents: 1963
diff changeset
  1454
23c638a81fe7 Output IDN configuration as part of 'ethercat config -v'.
Florian Pose <fp@igh-essen.com>
parents: 1963
diff changeset
  1455
    if (down_interruptible(&master->master_sem))
23c638a81fe7 Output IDN configuration as part of 'ethercat config -v'.
Florian Pose <fp@igh-essen.com>
parents: 1963
diff changeset
  1456
        return -EINTR;
23c638a81fe7 Output IDN configuration as part of 'ethercat config -v'.
Florian Pose <fp@igh-essen.com>
parents: 1963
diff changeset
  1457
23c638a81fe7 Output IDN configuration as part of 'ethercat config -v'.
Florian Pose <fp@igh-essen.com>
parents: 1963
diff changeset
  1458
    if (!(sc = ec_master_get_config_const(
23c638a81fe7 Output IDN configuration as part of 'ethercat config -v'.
Florian Pose <fp@igh-essen.com>
parents: 1963
diff changeset
  1459
                    master, data.config_index))) {
23c638a81fe7 Output IDN configuration as part of 'ethercat config -v'.
Florian Pose <fp@igh-essen.com>
parents: 1963
diff changeset
  1460
        up(&master->master_sem);
23c638a81fe7 Output IDN configuration as part of 'ethercat config -v'.
Florian Pose <fp@igh-essen.com>
parents: 1963
diff changeset
  1461
        EC_MASTER_ERR(master, "Slave config %u does not exist!\n",
23c638a81fe7 Output IDN configuration as part of 'ethercat config -v'.
Florian Pose <fp@igh-essen.com>
parents: 1963
diff changeset
  1462
                data.config_index);
23c638a81fe7 Output IDN configuration as part of 'ethercat config -v'.
Florian Pose <fp@igh-essen.com>
parents: 1963
diff changeset
  1463
        return -EINVAL;
23c638a81fe7 Output IDN configuration as part of 'ethercat config -v'.
Florian Pose <fp@igh-essen.com>
parents: 1963
diff changeset
  1464
    }
23c638a81fe7 Output IDN configuration as part of 'ethercat config -v'.
Florian Pose <fp@igh-essen.com>
parents: 1963
diff changeset
  1465
23c638a81fe7 Output IDN configuration as part of 'ethercat config -v'.
Florian Pose <fp@igh-essen.com>
parents: 1963
diff changeset
  1466
    if (!(req = ec_slave_config_get_idn_by_pos_const(
23c638a81fe7 Output IDN configuration as part of 'ethercat config -v'.
Florian Pose <fp@igh-essen.com>
parents: 1963
diff changeset
  1467
                    sc, data.idn_pos))) {
23c638a81fe7 Output IDN configuration as part of 'ethercat config -v'.
Florian Pose <fp@igh-essen.com>
parents: 1963
diff changeset
  1468
        up(&master->master_sem);
23c638a81fe7 Output IDN configuration as part of 'ethercat config -v'.
Florian Pose <fp@igh-essen.com>
parents: 1963
diff changeset
  1469
        EC_MASTER_ERR(master, "Invalid IDN position!\n");
23c638a81fe7 Output IDN configuration as part of 'ethercat config -v'.
Florian Pose <fp@igh-essen.com>
parents: 1963
diff changeset
  1470
        return -EINVAL;
23c638a81fe7 Output IDN configuration as part of 'ethercat config -v'.
Florian Pose <fp@igh-essen.com>
parents: 1963
diff changeset
  1471
    }
23c638a81fe7 Output IDN configuration as part of 'ethercat config -v'.
Florian Pose <fp@igh-essen.com>
parents: 1963
diff changeset
  1472
23c638a81fe7 Output IDN configuration as part of 'ethercat config -v'.
Florian Pose <fp@igh-essen.com>
parents: 1963
diff changeset
  1473
    data.drive_no = req->drive_no;
23c638a81fe7 Output IDN configuration as part of 'ethercat config -v'.
Florian Pose <fp@igh-essen.com>
parents: 1963
diff changeset
  1474
    data.idn = req->idn;
23c638a81fe7 Output IDN configuration as part of 'ethercat config -v'.
Florian Pose <fp@igh-essen.com>
parents: 1963
diff changeset
  1475
    data.state = req->state;
23c638a81fe7 Output IDN configuration as part of 'ethercat config -v'.
Florian Pose <fp@igh-essen.com>
parents: 1963
diff changeset
  1476
    data.size = req->data_size;
23c638a81fe7 Output IDN configuration as part of 'ethercat config -v'.
Florian Pose <fp@igh-essen.com>
parents: 1963
diff changeset
  1477
    memcpy(&data.data, req->data,
23c638a81fe7 Output IDN configuration as part of 'ethercat config -v'.
Florian Pose <fp@igh-essen.com>
parents: 1963
diff changeset
  1478
            min((u32) data.size, (u32) EC_MAX_IDN_DATA_SIZE));
23c638a81fe7 Output IDN configuration as part of 'ethercat config -v'.
Florian Pose <fp@igh-essen.com>
parents: 1963
diff changeset
  1479
23c638a81fe7 Output IDN configuration as part of 'ethercat config -v'.
Florian Pose <fp@igh-essen.com>
parents: 1963
diff changeset
  1480
    up(&master->master_sem);
23c638a81fe7 Output IDN configuration as part of 'ethercat config -v'.
Florian Pose <fp@igh-essen.com>
parents: 1963
diff changeset
  1481
23c638a81fe7 Output IDN configuration as part of 'ethercat config -v'.
Florian Pose <fp@igh-essen.com>
parents: 1963
diff changeset
  1482
    if (copy_to_user((void __user *) arg, &data, sizeof(data)))
23c638a81fe7 Output IDN configuration as part of 'ethercat config -v'.
Florian Pose <fp@igh-essen.com>
parents: 1963
diff changeset
  1483
        return -EFAULT;
23c638a81fe7 Output IDN configuration as part of 'ethercat config -v'.
Florian Pose <fp@igh-essen.com>
parents: 1963
diff changeset
  1484
23c638a81fe7 Output IDN configuration as part of 'ethercat config -v'.
Florian Pose <fp@igh-essen.com>
parents: 1963
diff changeset
  1485
    return 0;
23c638a81fe7 Output IDN configuration as part of 'ethercat config -v'.
Florian Pose <fp@igh-essen.com>
parents: 1963
diff changeset
  1486
}
23c638a81fe7 Output IDN configuration as part of 'ethercat config -v'.
Florian Pose <fp@igh-essen.com>
parents: 1963
diff changeset
  1487
23c638a81fe7 Output IDN configuration as part of 'ethercat config -v'.
Florian Pose <fp@igh-essen.com>
parents: 1963
diff changeset
  1488
/*****************************************************************************/
23c638a81fe7 Output IDN configuration as part of 'ethercat config -v'.
Florian Pose <fp@igh-essen.com>
parents: 1963
diff changeset
  1489
1516
e3b09f847512 Fixed compiler error on --disable-eoe.
Florian Pose <fp@igh-essen.com>
parents: 1513
diff changeset
  1490
#ifdef EC_EOE
e3b09f847512 Fixed compiler error on --disable-eoe.
Florian Pose <fp@igh-essen.com>
parents: 1513
diff changeset
  1491
1485
5ddc3a455059 ethercat eoe command.
Florian Pose <fp@igh-essen.com>
parents: 1465
diff changeset
  1492
/** Get EoE handler information.
5ddc3a455059 ethercat eoe command.
Florian Pose <fp@igh-essen.com>
parents: 1465
diff changeset
  1493
 */
5ddc3a455059 ethercat eoe command.
Florian Pose <fp@igh-essen.com>
parents: 1465
diff changeset
  1494
int ec_cdev_ioctl_eoe_handler(
5ddc3a455059 ethercat eoe command.
Florian Pose <fp@igh-essen.com>
parents: 1465
diff changeset
  1495
        ec_master_t *master, /**< EtherCAT master. */
5ddc3a455059 ethercat eoe command.
Florian Pose <fp@igh-essen.com>
parents: 1465
diff changeset
  1496
        unsigned long arg /**< ioctl() argument. */
5ddc3a455059 ethercat eoe command.
Florian Pose <fp@igh-essen.com>
parents: 1465
diff changeset
  1497
        )
5ddc3a455059 ethercat eoe command.
Florian Pose <fp@igh-essen.com>
parents: 1465
diff changeset
  1498
{
5ddc3a455059 ethercat eoe command.
Florian Pose <fp@igh-essen.com>
parents: 1465
diff changeset
  1499
    ec_ioctl_eoe_handler_t data;
1507
68e89abadd19 Removed unwanted tabulators.
Florian Pose <fp@igh-essen.com>
parents: 1500
diff changeset
  1500
    const ec_eoe_t *eoe;
1485
5ddc3a455059 ethercat eoe command.
Florian Pose <fp@igh-essen.com>
parents: 1465
diff changeset
  1501
5ddc3a455059 ethercat eoe command.
Florian Pose <fp@igh-essen.com>
parents: 1465
diff changeset
  1502
    if (copy_from_user(&data, (void __user *) arg, sizeof(data))) {
5ddc3a455059 ethercat eoe command.
Florian Pose <fp@igh-essen.com>
parents: 1465
diff changeset
  1503
        return -EFAULT;
5ddc3a455059 ethercat eoe command.
Florian Pose <fp@igh-essen.com>
parents: 1465
diff changeset
  1504
    }
5ddc3a455059 ethercat eoe command.
Florian Pose <fp@igh-essen.com>
parents: 1465
diff changeset
  1505
5ddc3a455059 ethercat eoe command.
Florian Pose <fp@igh-essen.com>
parents: 1465
diff changeset
  1506
    if (down_interruptible(&master->master_sem))
5ddc3a455059 ethercat eoe command.
Florian Pose <fp@igh-essen.com>
parents: 1465
diff changeset
  1507
        return -EINTR;
5ddc3a455059 ethercat eoe command.
Florian Pose <fp@igh-essen.com>
parents: 1465
diff changeset
  1508
5ddc3a455059 ethercat eoe command.
Florian Pose <fp@igh-essen.com>
parents: 1465
diff changeset
  1509
    if (!(eoe = ec_master_get_eoe_handler_const(master, data.eoe_index))) {
5ddc3a455059 ethercat eoe command.
Florian Pose <fp@igh-essen.com>
parents: 1465
diff changeset
  1510
        up(&master->master_sem);
1921
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1909
diff changeset
  1511
        EC_MASTER_ERR(master, "EoE handler %u does not exist!\n",
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1909
diff changeset
  1512
                data.eoe_index);
1485
5ddc3a455059 ethercat eoe command.
Florian Pose <fp@igh-essen.com>
parents: 1465
diff changeset
  1513
        return -EINVAL;
5ddc3a455059 ethercat eoe command.
Florian Pose <fp@igh-essen.com>
parents: 1465
diff changeset
  1514
    }
5ddc3a455059 ethercat eoe command.
Florian Pose <fp@igh-essen.com>
parents: 1465
diff changeset
  1515
1507
68e89abadd19 Removed unwanted tabulators.
Florian Pose <fp@igh-essen.com>
parents: 1500
diff changeset
  1516
    if (eoe->slave) {
68e89abadd19 Removed unwanted tabulators.
Florian Pose <fp@igh-essen.com>
parents: 1500
diff changeset
  1517
        data.slave_position = eoe->slave->ring_position;
68e89abadd19 Removed unwanted tabulators.
Florian Pose <fp@igh-essen.com>
parents: 1500
diff changeset
  1518
    } else {
68e89abadd19 Removed unwanted tabulators.
Florian Pose <fp@igh-essen.com>
parents: 1500
diff changeset
  1519
        data.slave_position = 0xffff;
68e89abadd19 Removed unwanted tabulators.
Florian Pose <fp@igh-essen.com>
parents: 1500
diff changeset
  1520
    }
68e89abadd19 Removed unwanted tabulators.
Florian Pose <fp@igh-essen.com>
parents: 1500
diff changeset
  1521
    snprintf(data.name, EC_DATAGRAM_NAME_SIZE, eoe->dev->name);
1485
5ddc3a455059 ethercat eoe command.
Florian Pose <fp@igh-essen.com>
parents: 1465
diff changeset
  1522
    data.open = eoe->opened;
5ddc3a455059 ethercat eoe command.
Florian Pose <fp@igh-essen.com>
parents: 1465
diff changeset
  1523
    data.rx_bytes = eoe->stats.tx_bytes;
5ddc3a455059 ethercat eoe command.
Florian Pose <fp@igh-essen.com>
parents: 1465
diff changeset
  1524
    data.rx_rate = eoe->tx_rate;
5ddc3a455059 ethercat eoe command.
Florian Pose <fp@igh-essen.com>
parents: 1465
diff changeset
  1525
    data.tx_bytes = eoe->stats.rx_bytes;
5ddc3a455059 ethercat eoe command.
Florian Pose <fp@igh-essen.com>
parents: 1465
diff changeset
  1526
    data.tx_rate = eoe->tx_rate;
5ddc3a455059 ethercat eoe command.
Florian Pose <fp@igh-essen.com>
parents: 1465
diff changeset
  1527
    data.tx_queued_frames = eoe->tx_queued_frames;
5ddc3a455059 ethercat eoe command.
Florian Pose <fp@igh-essen.com>
parents: 1465
diff changeset
  1528
    data.tx_queue_size = eoe->tx_queue_size;
5ddc3a455059 ethercat eoe command.
Florian Pose <fp@igh-essen.com>
parents: 1465
diff changeset
  1529
5ddc3a455059 ethercat eoe command.
Florian Pose <fp@igh-essen.com>
parents: 1465
diff changeset
  1530
    up(&master->master_sem);
5ddc3a455059 ethercat eoe command.
Florian Pose <fp@igh-essen.com>
parents: 1465
diff changeset
  1531
5ddc3a455059 ethercat eoe command.
Florian Pose <fp@igh-essen.com>
parents: 1465
diff changeset
  1532
    if (copy_to_user((void __user *) arg, &data, sizeof(data)))
5ddc3a455059 ethercat eoe command.
Florian Pose <fp@igh-essen.com>
parents: 1465
diff changeset
  1533
        return -EFAULT;
5ddc3a455059 ethercat eoe command.
Florian Pose <fp@igh-essen.com>
parents: 1465
diff changeset
  1534
5ddc3a455059 ethercat eoe command.
Florian Pose <fp@igh-essen.com>
parents: 1465
diff changeset
  1535
    return 0;
5ddc3a455059 ethercat eoe command.
Florian Pose <fp@igh-essen.com>
parents: 1465
diff changeset
  1536
}
5ddc3a455059 ethercat eoe command.
Florian Pose <fp@igh-essen.com>
parents: 1465
diff changeset
  1537
1516
e3b09f847512 Fixed compiler error on --disable-eoe.
Florian Pose <fp@igh-essen.com>
parents: 1513
diff changeset
  1538
#endif
e3b09f847512 Fixed compiler error on --disable-eoe.
Florian Pose <fp@igh-essen.com>
parents: 1513
diff changeset
  1539
1485
5ddc3a455059 ethercat eoe command.
Florian Pose <fp@igh-essen.com>
parents: 1465
diff changeset
  1540
/*****************************************************************************/
5ddc3a455059 ethercat eoe command.
Florian Pose <fp@igh-essen.com>
parents: 1465
diff changeset
  1541
1242
632a6b91f8e4 First version of userspace library with requesting/releasing.
Florian Pose <fp@igh-essen.com>
parents: 1223
diff changeset
  1542
/** Request the master from userspace.
632a6b91f8e4 First version of userspace library with requesting/releasing.
Florian Pose <fp@igh-essen.com>
parents: 1223
diff changeset
  1543
 */
632a6b91f8e4 First version of userspace library with requesting/releasing.
Florian Pose <fp@igh-essen.com>
parents: 1223
diff changeset
  1544
int ec_cdev_ioctl_request(
632a6b91f8e4 First version of userspace library with requesting/releasing.
Florian Pose <fp@igh-essen.com>
parents: 1223
diff changeset
  1545
        ec_master_t *master, /**< EtherCAT master. */
632a6b91f8e4 First version of userspace library with requesting/releasing.
Florian Pose <fp@igh-essen.com>
parents: 1223
diff changeset
  1546
        unsigned long arg, /**< ioctl() argument. */
632a6b91f8e4 First version of userspace library with requesting/releasing.
Florian Pose <fp@igh-essen.com>
parents: 1223
diff changeset
  1547
        ec_cdev_priv_t *priv /**< Private data structure of file handle. */
632a6b91f8e4 First version of userspace library with requesting/releasing.
Florian Pose <fp@igh-essen.com>
parents: 1223
diff changeset
  1548
        )
632a6b91f8e4 First version of userspace library with requesting/releasing.
Florian Pose <fp@igh-essen.com>
parents: 1223
diff changeset
  1549
{
1507
68e89abadd19 Removed unwanted tabulators.
Florian Pose <fp@igh-essen.com>
parents: 1500
diff changeset
  1550
    ec_master_t *m;
1242
632a6b91f8e4 First version of userspace library with requesting/releasing.
Florian Pose <fp@igh-essen.com>
parents: 1223
diff changeset
  1551
    int ret = 0;
632a6b91f8e4 First version of userspace library with requesting/releasing.
Florian Pose <fp@igh-essen.com>
parents: 1223
diff changeset
  1552
1312
74853e018898 Created backend versions of all API functions returing a pointer; using
Florian Pose <fp@igh-essen.com>
parents: 1284
diff changeset
  1553
    m = ecrt_request_master_err(master->index);
1244
0b70040d3daa No kernel handles in userspace; Domain creation.
Florian Pose <fp@igh-essen.com>
parents: 1242
diff changeset
  1554
    if (IS_ERR(m)) {
0b70040d3daa No kernel handles in userspace; Domain creation.
Florian Pose <fp@igh-essen.com>
parents: 1242
diff changeset
  1555
        ret = PTR_ERR(m);
1242
632a6b91f8e4 First version of userspace library with requesting/releasing.
Florian Pose <fp@igh-essen.com>
parents: 1223
diff changeset
  1556
    } else {
632a6b91f8e4 First version of userspace library with requesting/releasing.
Florian Pose <fp@igh-essen.com>
parents: 1223
diff changeset
  1557
        priv->requested = 1;
632a6b91f8e4 First version of userspace library with requesting/releasing.
Florian Pose <fp@igh-essen.com>
parents: 1223
diff changeset
  1558
    }
632a6b91f8e4 First version of userspace library with requesting/releasing.
Florian Pose <fp@igh-essen.com>
parents: 1223
diff changeset
  1559
632a6b91f8e4 First version of userspace library with requesting/releasing.
Florian Pose <fp@igh-essen.com>
parents: 1223
diff changeset
  1560
    return ret;
632a6b91f8e4 First version of userspace library with requesting/releasing.
Florian Pose <fp@igh-essen.com>
parents: 1223
diff changeset
  1561
}
632a6b91f8e4 First version of userspace library with requesting/releasing.
Florian Pose <fp@igh-essen.com>
parents: 1223
diff changeset
  1562
1244
0b70040d3daa No kernel handles in userspace; Domain creation.
Florian Pose <fp@igh-essen.com>
parents: 1242
diff changeset
  1563
/*****************************************************************************/
0b70040d3daa No kernel handles in userspace; Domain creation.
Florian Pose <fp@igh-essen.com>
parents: 1242
diff changeset
  1564
0b70040d3daa No kernel handles in userspace; Domain creation.
Florian Pose <fp@igh-essen.com>
parents: 1242
diff changeset
  1565
/** Create a domain.
0b70040d3daa No kernel handles in userspace; Domain creation.
Florian Pose <fp@igh-essen.com>
parents: 1242
diff changeset
  1566
 */
0b70040d3daa No kernel handles in userspace; Domain creation.
Florian Pose <fp@igh-essen.com>
parents: 1242
diff changeset
  1567
int ec_cdev_ioctl_create_domain(
0b70040d3daa No kernel handles in userspace; Domain creation.
Florian Pose <fp@igh-essen.com>
parents: 1242
diff changeset
  1568
        ec_master_t *master, /**< EtherCAT master. */
0b70040d3daa No kernel handles in userspace; Domain creation.
Florian Pose <fp@igh-essen.com>
parents: 1242
diff changeset
  1569
        unsigned long arg, /**< ioctl() argument. */
0b70040d3daa No kernel handles in userspace; Domain creation.
Florian Pose <fp@igh-essen.com>
parents: 1242
diff changeset
  1570
        ec_cdev_priv_t *priv /**< Private data structure of file handle. */
0b70040d3daa No kernel handles in userspace; Domain creation.
Florian Pose <fp@igh-essen.com>
parents: 1242
diff changeset
  1571
        )
0b70040d3daa No kernel handles in userspace; Domain creation.
Florian Pose <fp@igh-essen.com>
parents: 1242
diff changeset
  1572
{
0b70040d3daa No kernel handles in userspace; Domain creation.
Florian Pose <fp@igh-essen.com>
parents: 1242
diff changeset
  1573
    ec_domain_t *domain;
0b70040d3daa No kernel handles in userspace; Domain creation.
Florian Pose <fp@igh-essen.com>
parents: 1242
diff changeset
  1574
1507
68e89abadd19 Removed unwanted tabulators.
Florian Pose <fp@igh-essen.com>
parents: 1500
diff changeset
  1575
    if (unlikely(!priv->requested))
68e89abadd19 Removed unwanted tabulators.
Florian Pose <fp@igh-essen.com>
parents: 1500
diff changeset
  1576
        return -EPERM;
1244
0b70040d3daa No kernel handles in userspace; Domain creation.
Florian Pose <fp@igh-essen.com>
parents: 1242
diff changeset
  1577
1312
74853e018898 Created backend versions of all API functions returing a pointer; using
Florian Pose <fp@igh-essen.com>
parents: 1284
diff changeset
  1578
    domain = ecrt_master_create_domain_err(master);
74853e018898 Created backend versions of all API functions returing a pointer; using
Florian Pose <fp@igh-essen.com>
parents: 1284
diff changeset
  1579
    if (IS_ERR(domain))
74853e018898 Created backend versions of all API functions returing a pointer; using
Florian Pose <fp@igh-essen.com>
parents: 1284
diff changeset
  1580
        return PTR_ERR(domain);
1244
0b70040d3daa No kernel handles in userspace; Domain creation.
Florian Pose <fp@igh-essen.com>
parents: 1242
diff changeset
  1581
0b70040d3daa No kernel handles in userspace; Domain creation.
Florian Pose <fp@igh-essen.com>
parents: 1242
diff changeset
  1582
    return domain->index;
0b70040d3daa No kernel handles in userspace; Domain creation.
Florian Pose <fp@igh-essen.com>
parents: 1242
diff changeset
  1583
}
0b70040d3daa No kernel handles in userspace; Domain creation.
Florian Pose <fp@igh-essen.com>
parents: 1242
diff changeset
  1584
1246
4042bda8c980 Creating slave configurations.
Florian Pose <fp@igh-essen.com>
parents: 1244
diff changeset
  1585
/*****************************************************************************/
4042bda8c980 Creating slave configurations.
Florian Pose <fp@igh-essen.com>
parents: 1244
diff changeset
  1586
4042bda8c980 Creating slave configurations.
Florian Pose <fp@igh-essen.com>
parents: 1244
diff changeset
  1587
/** Create a slave configuration.
4042bda8c980 Creating slave configurations.
Florian Pose <fp@igh-essen.com>
parents: 1244
diff changeset
  1588
 */
4042bda8c980 Creating slave configurations.
Florian Pose <fp@igh-essen.com>
parents: 1244
diff changeset
  1589
int ec_cdev_ioctl_create_slave_config(
4042bda8c980 Creating slave configurations.
Florian Pose <fp@igh-essen.com>
parents: 1244
diff changeset
  1590
        ec_master_t *master, /**< EtherCAT master. */
4042bda8c980 Creating slave configurations.
Florian Pose <fp@igh-essen.com>
parents: 1244
diff changeset
  1591
        unsigned long arg, /**< ioctl() argument. */
4042bda8c980 Creating slave configurations.
Florian Pose <fp@igh-essen.com>
parents: 1244
diff changeset
  1592
        ec_cdev_priv_t *priv /**< Private data structure of file handle. */
4042bda8c980 Creating slave configurations.
Florian Pose <fp@igh-essen.com>
parents: 1244
diff changeset
  1593
        )
4042bda8c980 Creating slave configurations.
Florian Pose <fp@igh-essen.com>
parents: 1244
diff changeset
  1594
{
4042bda8c980 Creating slave configurations.
Florian Pose <fp@igh-essen.com>
parents: 1244
diff changeset
  1595
    ec_ioctl_config_t data;
4042bda8c980 Creating slave configurations.
Florian Pose <fp@igh-essen.com>
parents: 1244
diff changeset
  1596
    ec_slave_config_t *sc, *entry;
4042bda8c980 Creating slave configurations.
Florian Pose <fp@igh-essen.com>
parents: 1244
diff changeset
  1597
1507
68e89abadd19 Removed unwanted tabulators.
Florian Pose <fp@igh-essen.com>
parents: 1500
diff changeset
  1598
    if (unlikely(!priv->requested))
68e89abadd19 Removed unwanted tabulators.
Florian Pose <fp@igh-essen.com>
parents: 1500
diff changeset
  1599
        return -EPERM;
1246
4042bda8c980 Creating slave configurations.
Florian Pose <fp@igh-essen.com>
parents: 1244
diff changeset
  1600
4042bda8c980 Creating slave configurations.
Florian Pose <fp@igh-essen.com>
parents: 1244
diff changeset
  1601
    if (copy_from_user(&data, (void __user *) arg, sizeof(data))) {
4042bda8c980 Creating slave configurations.
Florian Pose <fp@igh-essen.com>
parents: 1244
diff changeset
  1602
        return -EFAULT;
4042bda8c980 Creating slave configurations.
Florian Pose <fp@igh-essen.com>
parents: 1244
diff changeset
  1603
    }
4042bda8c980 Creating slave configurations.
Florian Pose <fp@igh-essen.com>
parents: 1244
diff changeset
  1604
1312
74853e018898 Created backend versions of all API functions returing a pointer; using
Florian Pose <fp@igh-essen.com>
parents: 1284
diff changeset
  1605
    sc = ecrt_master_slave_config_err(master, data.alias, data.position,
1246
4042bda8c980 Creating slave configurations.
Florian Pose <fp@igh-essen.com>
parents: 1244
diff changeset
  1606
            data.vendor_id, data.product_code);
1312
74853e018898 Created backend versions of all API functions returing a pointer; using
Florian Pose <fp@igh-essen.com>
parents: 1284
diff changeset
  1607
    if (IS_ERR(sc))
74853e018898 Created backend versions of all API functions returing a pointer; using
Florian Pose <fp@igh-essen.com>
parents: 1284
diff changeset
  1608
        return PTR_ERR(sc);
1246
4042bda8c980 Creating slave configurations.
Florian Pose <fp@igh-essen.com>
parents: 1244
diff changeset
  1609
4042bda8c980 Creating slave configurations.
Florian Pose <fp@igh-essen.com>
parents: 1244
diff changeset
  1610
    data.config_index = 0;
4042bda8c980 Creating slave configurations.
Florian Pose <fp@igh-essen.com>
parents: 1244
diff changeset
  1611
4042bda8c980 Creating slave configurations.
Florian Pose <fp@igh-essen.com>
parents: 1244
diff changeset
  1612
    if (down_interruptible(&master->master_sem))
4042bda8c980 Creating slave configurations.
Florian Pose <fp@igh-essen.com>
parents: 1244
diff changeset
  1613
        return -EINTR;
4042bda8c980 Creating slave configurations.
Florian Pose <fp@igh-essen.com>
parents: 1244
diff changeset
  1614
4042bda8c980 Creating slave configurations.
Florian Pose <fp@igh-essen.com>
parents: 1244
diff changeset
  1615
    list_for_each_entry(entry, &master->configs, list) {
4042bda8c980 Creating slave configurations.
Florian Pose <fp@igh-essen.com>
parents: 1244
diff changeset
  1616
        if (entry == sc)
4042bda8c980 Creating slave configurations.
Florian Pose <fp@igh-essen.com>
parents: 1244
diff changeset
  1617
            break;
4042bda8c980 Creating slave configurations.
Florian Pose <fp@igh-essen.com>
parents: 1244
diff changeset
  1618
        data.config_index++;
4042bda8c980 Creating slave configurations.
Florian Pose <fp@igh-essen.com>
parents: 1244
diff changeset
  1619
    }
4042bda8c980 Creating slave configurations.
Florian Pose <fp@igh-essen.com>
parents: 1244
diff changeset
  1620
4042bda8c980 Creating slave configurations.
Florian Pose <fp@igh-essen.com>
parents: 1244
diff changeset
  1621
    up(&master->master_sem);
4042bda8c980 Creating slave configurations.
Florian Pose <fp@igh-essen.com>
parents: 1244
diff changeset
  1622
4042bda8c980 Creating slave configurations.
Florian Pose <fp@igh-essen.com>
parents: 1244
diff changeset
  1623
    if (copy_to_user((void __user *) arg, &data, sizeof(data)))
4042bda8c980 Creating slave configurations.
Florian Pose <fp@igh-essen.com>
parents: 1244
diff changeset
  1624
        return -EFAULT;
4042bda8c980 Creating slave configurations.
Florian Pose <fp@igh-essen.com>
parents: 1244
diff changeset
  1625
4042bda8c980 Creating slave configurations.
Florian Pose <fp@igh-essen.com>
parents: 1244
diff changeset
  1626
    return 0;
4042bda8c980 Creating slave configurations.
Florian Pose <fp@igh-essen.com>
parents: 1244
diff changeset
  1627
}
4042bda8c980 Creating slave configurations.
Florian Pose <fp@igh-essen.com>
parents: 1244
diff changeset
  1628
1247
5f1f1a3e6636 Activate, Send and received; cyclic timer with setitimer().
Florian Pose <fp@igh-essen.com>
parents: 1246
diff changeset
  1629
/*****************************************************************************/
5f1f1a3e6636 Activate, Send and received; cyclic timer with setitimer().
Florian Pose <fp@igh-essen.com>
parents: 1246
diff changeset
  1630
5f1f1a3e6636 Activate, Send and received; cyclic timer with setitimer().
Florian Pose <fp@igh-essen.com>
parents: 1246
diff changeset
  1631
/** Activates the master.
5f1f1a3e6636 Activate, Send and received; cyclic timer with setitimer().
Florian Pose <fp@igh-essen.com>
parents: 1246
diff changeset
  1632
 */
5f1f1a3e6636 Activate, Send and received; cyclic timer with setitimer().
Florian Pose <fp@igh-essen.com>
parents: 1246
diff changeset
  1633
int ec_cdev_ioctl_activate(
5f1f1a3e6636 Activate, Send and received; cyclic timer with setitimer().
Florian Pose <fp@igh-essen.com>
parents: 1246
diff changeset
  1634
        ec_master_t *master, /**< EtherCAT master. */
5f1f1a3e6636 Activate, Send and received; cyclic timer with setitimer().
Florian Pose <fp@igh-essen.com>
parents: 1246
diff changeset
  1635
        unsigned long arg, /**< ioctl() argument. */
5f1f1a3e6636 Activate, Send and received; cyclic timer with setitimer().
Florian Pose <fp@igh-essen.com>
parents: 1246
diff changeset
  1636
        ec_cdev_priv_t *priv /**< Private data structure of file handle. */
5f1f1a3e6636 Activate, Send and received; cyclic timer with setitimer().
Florian Pose <fp@igh-essen.com>
parents: 1246
diff changeset
  1637
        )
5f1f1a3e6636 Activate, Send and received; cyclic timer with setitimer().
Florian Pose <fp@igh-essen.com>
parents: 1246
diff changeset
  1638
{
1258
900f1124e8f8 Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents: 1255
diff changeset
  1639
    ec_domain_t *domain;
900f1124e8f8 Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents: 1255
diff changeset
  1640
    off_t offset;
1313
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1312
diff changeset
  1641
    int ret;
1258
900f1124e8f8 Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents: 1255
diff changeset
  1642
    
1507
68e89abadd19 Removed unwanted tabulators.
Florian Pose <fp@igh-essen.com>
parents: 1500
diff changeset
  1643
    if (unlikely(!priv->requested))
68e89abadd19 Removed unwanted tabulators.
Florian Pose <fp@igh-essen.com>
parents: 1500
diff changeset
  1644
        return -EPERM;
1247
5f1f1a3e6636 Activate, Send and received; cyclic timer with setitimer().
Florian Pose <fp@igh-essen.com>
parents: 1246
diff changeset
  1645
1258
900f1124e8f8 Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents: 1255
diff changeset
  1646
    /* Get the sum of the domains' process data sizes. */
900f1124e8f8 Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents: 1255
diff changeset
  1647
    
900f1124e8f8 Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents: 1255
diff changeset
  1648
    priv->process_data_size = 0;
900f1124e8f8 Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents: 1255
diff changeset
  1649
900f1124e8f8 Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents: 1255
diff changeset
  1650
    if (down_interruptible(&master->master_sem))
900f1124e8f8 Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents: 1255
diff changeset
  1651
        return -EINTR;
900f1124e8f8 Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents: 1255
diff changeset
  1652
900f1124e8f8 Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents: 1255
diff changeset
  1653
    list_for_each_entry(domain, &master->domains, list) {
900f1124e8f8 Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents: 1255
diff changeset
  1654
        priv->process_data_size += ecrt_domain_size(domain);
900f1124e8f8 Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents: 1255
diff changeset
  1655
    }
900f1124e8f8 Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents: 1255
diff changeset
  1656
    
900f1124e8f8 Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents: 1255
diff changeset
  1657
    up(&master->master_sem);
900f1124e8f8 Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents: 1255
diff changeset
  1658
900f1124e8f8 Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents: 1255
diff changeset
  1659
    if (priv->process_data_size) {
900f1124e8f8 Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents: 1255
diff changeset
  1660
        priv->process_data = vmalloc(priv->process_data_size);
900f1124e8f8 Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents: 1255
diff changeset
  1661
        if (!priv->process_data) {
900f1124e8f8 Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents: 1255
diff changeset
  1662
            priv->process_data_size = 0;
900f1124e8f8 Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents: 1255
diff changeset
  1663
            return -ENOMEM;
900f1124e8f8 Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents: 1255
diff changeset
  1664
        }
900f1124e8f8 Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents: 1255
diff changeset
  1665
900f1124e8f8 Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents: 1255
diff changeset
  1666
        /* Set the memory as external process data memory for the domains. */
900f1124e8f8 Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents: 1255
diff changeset
  1667
900f1124e8f8 Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents: 1255
diff changeset
  1668
        offset = 0;
900f1124e8f8 Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents: 1255
diff changeset
  1669
        list_for_each_entry(domain, &master->domains, list) {
900f1124e8f8 Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents: 1255
diff changeset
  1670
            ecrt_domain_external_memory(domain, priv->process_data + offset);
900f1124e8f8 Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents: 1255
diff changeset
  1671
            offset += ecrt_domain_size(domain);
900f1124e8f8 Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents: 1255
diff changeset
  1672
        }
900f1124e8f8 Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents: 1255
diff changeset
  1673
    }
900f1124e8f8 Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents: 1255
diff changeset
  1674
1500
ed1a733efbc5 Improved the callback mechanism.
Florian Pose <fp@igh-essen.com>
parents: 1489
diff changeset
  1675
    ecrt_master_callbacks(master, ec_master_internal_send_cb,
1513
60ca68d853b8 Re-added callback data pointer, because it is necessary for some applications.
Florian Pose <fp@igh-essen.com>
parents: 1509
diff changeset
  1676
            ec_master_internal_receive_cb, master);
1500
ed1a733efbc5 Improved the callback mechanism.
Florian Pose <fp@igh-essen.com>
parents: 1489
diff changeset
  1677
1313
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1312
diff changeset
  1678
    ret = ecrt_master_activate(master);
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1312
diff changeset
  1679
    if (ret < 0)
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1312
diff changeset
  1680
        return ret;
1247
5f1f1a3e6636 Activate, Send and received; cyclic timer with setitimer().
Florian Pose <fp@igh-essen.com>
parents: 1246
diff changeset
  1681
1258
900f1124e8f8 Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents: 1255
diff changeset
  1682
    if (copy_to_user((void __user *) arg,
900f1124e8f8 Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents: 1255
diff changeset
  1683
                &priv->process_data_size, sizeof(size_t)))
900f1124e8f8 Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents: 1255
diff changeset
  1684
        return -EFAULT;
900f1124e8f8 Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents: 1255
diff changeset
  1685
1247
5f1f1a3e6636 Activate, Send and received; cyclic timer with setitimer().
Florian Pose <fp@igh-essen.com>
parents: 1246
diff changeset
  1686
    return 0;
5f1f1a3e6636 Activate, Send and received; cyclic timer with setitimer().
Florian Pose <fp@igh-essen.com>
parents: 1246
diff changeset
  1687
}
5f1f1a3e6636 Activate, Send and received; cyclic timer with setitimer().
Florian Pose <fp@igh-essen.com>
parents: 1246
diff changeset
  1688
5f1f1a3e6636 Activate, Send and received; cyclic timer with setitimer().
Florian Pose <fp@igh-essen.com>
parents: 1246
diff changeset
  1689
/*****************************************************************************/
5f1f1a3e6636 Activate, Send and received; cyclic timer with setitimer().
Florian Pose <fp@igh-essen.com>
parents: 1246
diff changeset
  1690
1531
6c5478400e28 Implemented ecrt_master_deactivate() in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1530
diff changeset
  1691
/** Deactivates the master.
6c5478400e28 Implemented ecrt_master_deactivate() in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1530
diff changeset
  1692
 */
6c5478400e28 Implemented ecrt_master_deactivate() in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1530
diff changeset
  1693
int ec_cdev_ioctl_deactivate(
6c5478400e28 Implemented ecrt_master_deactivate() in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1530
diff changeset
  1694
        ec_master_t *master, /**< EtherCAT master. */
6c5478400e28 Implemented ecrt_master_deactivate() in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1530
diff changeset
  1695
        unsigned long arg, /**< ioctl() argument. */
6c5478400e28 Implemented ecrt_master_deactivate() in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1530
diff changeset
  1696
        ec_cdev_priv_t *priv /**< Private data structure of file handle. */
6c5478400e28 Implemented ecrt_master_deactivate() in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1530
diff changeset
  1697
        )
6c5478400e28 Implemented ecrt_master_deactivate() in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1530
diff changeset
  1698
{
6c5478400e28 Implemented ecrt_master_deactivate() in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1530
diff changeset
  1699
    if (unlikely(!priv->requested))
6c5478400e28 Implemented ecrt_master_deactivate() in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1530
diff changeset
  1700
        return -EPERM;
6c5478400e28 Implemented ecrt_master_deactivate() in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1530
diff changeset
  1701
6c5478400e28 Implemented ecrt_master_deactivate() in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1530
diff changeset
  1702
    ecrt_master_deactivate(master);
6c5478400e28 Implemented ecrt_master_deactivate() in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1530
diff changeset
  1703
    return 0;
6c5478400e28 Implemented ecrt_master_deactivate() in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1530
diff changeset
  1704
}
6c5478400e28 Implemented ecrt_master_deactivate() in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1530
diff changeset
  1705
1585
1f640e321ee4 ecrt_master_set_max_cycle_size: limit SDO traffic
Martin Troxler <martin.troxler@komaxgroup.com>
parents: 1583
diff changeset
  1706
/*****************************************************************************/
1f640e321ee4 ecrt_master_set_max_cycle_size: limit SDO traffic
Martin Troxler <martin.troxler@komaxgroup.com>
parents: 1583
diff changeset
  1707
1f640e321ee4 ecrt_master_set_max_cycle_size: limit SDO traffic
Martin Troxler <martin.troxler@komaxgroup.com>
parents: 1583
diff changeset
  1708
/** Set max. number of databytes in a cycle
1f640e321ee4 ecrt_master_set_max_cycle_size: limit SDO traffic
Martin Troxler <martin.troxler@komaxgroup.com>
parents: 1583
diff changeset
  1709
 */
1600
e36c92cf58a9 use given send interval to limit SDO/FOE traffic
Martin Troxler <martin.troxler@komaxgroup.com>
parents: 1597
diff changeset
  1710
int ec_cdev_ioctl_set_send_interval(
e36c92cf58a9 use given send interval to limit SDO/FOE traffic
Martin Troxler <martin.troxler@komaxgroup.com>
parents: 1597
diff changeset
  1711
        ec_master_t *master, /**< EtherCAT master. */
e36c92cf58a9 use given send interval to limit SDO/FOE traffic
Martin Troxler <martin.troxler@komaxgroup.com>
parents: 1597
diff changeset
  1712
        unsigned long arg, /**< ioctl() argument. */
e36c92cf58a9 use given send interval to limit SDO/FOE traffic
Martin Troxler <martin.troxler@komaxgroup.com>
parents: 1597
diff changeset
  1713
        ec_cdev_priv_t *priv /**< Private data structure of file handle. */
e36c92cf58a9 use given send interval to limit SDO/FOE traffic
Martin Troxler <martin.troxler@komaxgroup.com>
parents: 1597
diff changeset
  1714
        )
e36c92cf58a9 use given send interval to limit SDO/FOE traffic
Martin Troxler <martin.troxler@komaxgroup.com>
parents: 1597
diff changeset
  1715
{
1804
742607c464c4 Removed tabulators.
Florian Pose <fp@igh-essen.com>
parents: 1606
diff changeset
  1716
    size_t send_interval;
742607c464c4 Removed tabulators.
Florian Pose <fp@igh-essen.com>
parents: 1606
diff changeset
  1717
742607c464c4 Removed tabulators.
Florian Pose <fp@igh-essen.com>
parents: 1606
diff changeset
  1718
    if (copy_from_user(&send_interval, (void __user *) arg,
742607c464c4 Removed tabulators.
Florian Pose <fp@igh-essen.com>
parents: 1606
diff changeset
  1719
                sizeof(send_interval))) {
742607c464c4 Removed tabulators.
Florian Pose <fp@igh-essen.com>
parents: 1606
diff changeset
  1720
        return -EFAULT;
742607c464c4 Removed tabulators.
Florian Pose <fp@igh-essen.com>
parents: 1606
diff changeset
  1721
    }
742607c464c4 Removed tabulators.
Florian Pose <fp@igh-essen.com>
parents: 1606
diff changeset
  1722
742607c464c4 Removed tabulators.
Florian Pose <fp@igh-essen.com>
parents: 1606
diff changeset
  1723
    if (down_interruptible(&master->master_sem))
742607c464c4 Removed tabulators.
Florian Pose <fp@igh-essen.com>
parents: 1606
diff changeset
  1724
        return -EINTR;
2180
912d70d6f0e5 Removed some locks causing latency when using the library; added ioctl()
Florian Pose <fp@igh-essen.com>
parents: 2124
diff changeset
  1725
912d70d6f0e5 Removed some locks causing latency when using the library; added ioctl()
Florian Pose <fp@igh-essen.com>
parents: 2124
diff changeset
  1726
    ec_master_set_send_interval(master, send_interval);
912d70d6f0e5 Removed some locks causing latency when using the library; added ioctl()
Florian Pose <fp@igh-essen.com>
parents: 2124
diff changeset
  1727
1585
1f640e321ee4 ecrt_master_set_max_cycle_size: limit SDO traffic
Martin Troxler <martin.troxler@komaxgroup.com>
parents: 1583
diff changeset
  1728
    up(&master->master_sem);
2180
912d70d6f0e5 Removed some locks causing latency when using the library; added ioctl()
Florian Pose <fp@igh-essen.com>
parents: 2124
diff changeset
  1729
    return 0;
912d70d6f0e5 Removed some locks causing latency when using the library; added ioctl()
Florian Pose <fp@igh-essen.com>
parents: 2124
diff changeset
  1730
}
1585
1f640e321ee4 ecrt_master_set_max_cycle_size: limit SDO traffic
Martin Troxler <martin.troxler@komaxgroup.com>
parents: 1583
diff changeset
  1731
1531
6c5478400e28 Implemented ecrt_master_deactivate() in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1530
diff changeset
  1732
/*****************************************************************************/
6c5478400e28 Implemented ecrt_master_deactivate() in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1530
diff changeset
  1733
1247
5f1f1a3e6636 Activate, Send and received; cyclic timer with setitimer().
Florian Pose <fp@igh-essen.com>
parents: 1246
diff changeset
  1734
/** Send frames.
5f1f1a3e6636 Activate, Send and received; cyclic timer with setitimer().
Florian Pose <fp@igh-essen.com>
parents: 1246
diff changeset
  1735
 */
5f1f1a3e6636 Activate, Send and received; cyclic timer with setitimer().
Florian Pose <fp@igh-essen.com>
parents: 1246
diff changeset
  1736
int ec_cdev_ioctl_send(
5f1f1a3e6636 Activate, Send and received; cyclic timer with setitimer().
Florian Pose <fp@igh-essen.com>
parents: 1246
diff changeset
  1737
        ec_master_t *master, /**< EtherCAT master. */
5f1f1a3e6636 Activate, Send and received; cyclic timer with setitimer().
Florian Pose <fp@igh-essen.com>
parents: 1246
diff changeset
  1738
        unsigned long arg, /**< ioctl() argument. */
5f1f1a3e6636 Activate, Send and received; cyclic timer with setitimer().
Florian Pose <fp@igh-essen.com>
parents: 1246
diff changeset
  1739
        ec_cdev_priv_t *priv /**< Private data structure of file handle. */
5f1f1a3e6636 Activate, Send and received; cyclic timer with setitimer().
Florian Pose <fp@igh-essen.com>
parents: 1246
diff changeset
  1740
        )
5f1f1a3e6636 Activate, Send and received; cyclic timer with setitimer().
Florian Pose <fp@igh-essen.com>
parents: 1246
diff changeset
  1741
{
1507
68e89abadd19 Removed unwanted tabulators.
Florian Pose <fp@igh-essen.com>
parents: 1500
diff changeset
  1742
    if (unlikely(!priv->requested))
68e89abadd19 Removed unwanted tabulators.
Florian Pose <fp@igh-essen.com>
parents: 1500
diff changeset
  1743
        return -EPERM;
1247
5f1f1a3e6636 Activate, Send and received; cyclic timer with setitimer().
Florian Pose <fp@igh-essen.com>
parents: 1246
diff changeset
  1744
1489
f77a1182b6f4 EoE processing with kthread.
Florian Pose <fp@igh-essen.com>
parents: 1485
diff changeset
  1745
    down(&master->io_sem);
1247
5f1f1a3e6636 Activate, Send and received; cyclic timer with setitimer().
Florian Pose <fp@igh-essen.com>
parents: 1246
diff changeset
  1746
    ecrt_master_send(master);
1489
f77a1182b6f4 EoE processing with kthread.
Florian Pose <fp@igh-essen.com>
parents: 1485
diff changeset
  1747
    up(&master->io_sem);
1247
5f1f1a3e6636 Activate, Send and received; cyclic timer with setitimer().
Florian Pose <fp@igh-essen.com>
parents: 1246
diff changeset
  1748
    return 0;
5f1f1a3e6636 Activate, Send and received; cyclic timer with setitimer().
Florian Pose <fp@igh-essen.com>
parents: 1246
diff changeset
  1749
}
5f1f1a3e6636 Activate, Send and received; cyclic timer with setitimer().
Florian Pose <fp@igh-essen.com>
parents: 1246
diff changeset
  1750
5f1f1a3e6636 Activate, Send and received; cyclic timer with setitimer().
Florian Pose <fp@igh-essen.com>
parents: 1246
diff changeset
  1751
/*****************************************************************************/
5f1f1a3e6636 Activate, Send and received; cyclic timer with setitimer().
Florian Pose <fp@igh-essen.com>
parents: 1246
diff changeset
  1752
5f1f1a3e6636 Activate, Send and received; cyclic timer with setitimer().
Florian Pose <fp@igh-essen.com>
parents: 1246
diff changeset
  1753
/** Receive frames.
5f1f1a3e6636 Activate, Send and received; cyclic timer with setitimer().
Florian Pose <fp@igh-essen.com>
parents: 1246
diff changeset
  1754
 */
5f1f1a3e6636 Activate, Send and received; cyclic timer with setitimer().
Florian Pose <fp@igh-essen.com>
parents: 1246
diff changeset
  1755
int ec_cdev_ioctl_receive(
5f1f1a3e6636 Activate, Send and received; cyclic timer with setitimer().
Florian Pose <fp@igh-essen.com>
parents: 1246
diff changeset
  1756
        ec_master_t *master, /**< EtherCAT master. */
5f1f1a3e6636 Activate, Send and received; cyclic timer with setitimer().
Florian Pose <fp@igh-essen.com>
parents: 1246
diff changeset
  1757
        unsigned long arg, /**< ioctl() argument. */
5f1f1a3e6636 Activate, Send and received; cyclic timer with setitimer().
Florian Pose <fp@igh-essen.com>
parents: 1246
diff changeset
  1758
        ec_cdev_priv_t *priv /**< Private data structure of file handle. */
5f1f1a3e6636 Activate, Send and received; cyclic timer with setitimer().
Florian Pose <fp@igh-essen.com>
parents: 1246
diff changeset
  1759
        )
5f1f1a3e6636 Activate, Send and received; cyclic timer with setitimer().
Florian Pose <fp@igh-essen.com>
parents: 1246
diff changeset
  1760
{
1507
68e89abadd19 Removed unwanted tabulators.
Florian Pose <fp@igh-essen.com>
parents: 1500
diff changeset
  1761
    if (unlikely(!priv->requested))
68e89abadd19 Removed unwanted tabulators.
Florian Pose <fp@igh-essen.com>
parents: 1500
diff changeset
  1762
        return -EPERM;
1247
5f1f1a3e6636 Activate, Send and received; cyclic timer with setitimer().
Florian Pose <fp@igh-essen.com>
parents: 1246
diff changeset
  1763
1489
f77a1182b6f4 EoE processing with kthread.
Florian Pose <fp@igh-essen.com>
parents: 1485
diff changeset
  1764
    down(&master->io_sem);
1247
5f1f1a3e6636 Activate, Send and received; cyclic timer with setitimer().
Florian Pose <fp@igh-essen.com>
parents: 1246
diff changeset
  1765
    ecrt_master_receive(master);
1489
f77a1182b6f4 EoE processing with kthread.
Florian Pose <fp@igh-essen.com>
parents: 1485
diff changeset
  1766
    up(&master->io_sem);
1247
5f1f1a3e6636 Activate, Send and received; cyclic timer with setitimer().
Florian Pose <fp@igh-essen.com>
parents: 1246
diff changeset
  1767
    return 0;
5f1f1a3e6636 Activate, Send and received; cyclic timer with setitimer().
Florian Pose <fp@igh-essen.com>
parents: 1246
diff changeset
  1768
}
5f1f1a3e6636 Activate, Send and received; cyclic timer with setitimer().
Florian Pose <fp@igh-essen.com>
parents: 1246
diff changeset
  1769
1255
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  1770
/*****************************************************************************/
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  1771
1259
5f9d1abbee71 Added state functions; writing of process data works.
Florian Pose <fp@igh-essen.com>
parents: 1258
diff changeset
  1772
/** Get the master state.
5f9d1abbee71 Added state functions; writing of process data works.
Florian Pose <fp@igh-essen.com>
parents: 1258
diff changeset
  1773
 */
5f9d1abbee71 Added state functions; writing of process data works.
Florian Pose <fp@igh-essen.com>
parents: 1258
diff changeset
  1774
int ec_cdev_ioctl_master_state(
5f9d1abbee71 Added state functions; writing of process data works.
Florian Pose <fp@igh-essen.com>
parents: 1258
diff changeset
  1775
        ec_master_t *master, /**< EtherCAT master. */
5f9d1abbee71 Added state functions; writing of process data works.
Florian Pose <fp@igh-essen.com>
parents: 1258
diff changeset
  1776
        unsigned long arg, /**< ioctl() argument. */
5f9d1abbee71 Added state functions; writing of process data works.
Florian Pose <fp@igh-essen.com>
parents: 1258
diff changeset
  1777
        ec_cdev_priv_t *priv /**< Private data structure of file handle. */
5f9d1abbee71 Added state functions; writing of process data works.
Florian Pose <fp@igh-essen.com>
parents: 1258
diff changeset
  1778
        )
5f9d1abbee71 Added state functions; writing of process data works.
Florian Pose <fp@igh-essen.com>
parents: 1258
diff changeset
  1779
{
5f9d1abbee71 Added state functions; writing of process data works.
Florian Pose <fp@igh-essen.com>
parents: 1258
diff changeset
  1780
    ec_master_state_t data;
5f9d1abbee71 Added state functions; writing of process data works.
Florian Pose <fp@igh-essen.com>
parents: 1258
diff changeset
  1781
    
1507
68e89abadd19 Removed unwanted tabulators.
Florian Pose <fp@igh-essen.com>
parents: 1500
diff changeset
  1782
    if (unlikely(!priv->requested))
68e89abadd19 Removed unwanted tabulators.
Florian Pose <fp@igh-essen.com>
parents: 1500
diff changeset
  1783
        return -EPERM;
1259
5f9d1abbee71 Added state functions; writing of process data works.
Florian Pose <fp@igh-essen.com>
parents: 1258
diff changeset
  1784
5f9d1abbee71 Added state functions; writing of process data works.
Florian Pose <fp@igh-essen.com>
parents: 1258
diff changeset
  1785
    ecrt_master_state(master, &data);
5f9d1abbee71 Added state functions; writing of process data works.
Florian Pose <fp@igh-essen.com>
parents: 1258
diff changeset
  1786
5f9d1abbee71 Added state functions; writing of process data works.
Florian Pose <fp@igh-essen.com>
parents: 1258
diff changeset
  1787
    if (copy_to_user((void __user *) arg, &data, sizeof(data)))
5f9d1abbee71 Added state functions; writing of process data works.
Florian Pose <fp@igh-essen.com>
parents: 1258
diff changeset
  1788
        return -EFAULT;
5f9d1abbee71 Added state functions; writing of process data works.
Florian Pose <fp@igh-essen.com>
parents: 1258
diff changeset
  1789
5f9d1abbee71 Added state functions; writing of process data works.
Florian Pose <fp@igh-essen.com>
parents: 1258
diff changeset
  1790
    return 0;
5f9d1abbee71 Added state functions; writing of process data works.
Florian Pose <fp@igh-essen.com>
parents: 1258
diff changeset
  1791
}
5f9d1abbee71 Added state functions; writing of process data works.
Florian Pose <fp@igh-essen.com>
parents: 1258
diff changeset
  1792
5f9d1abbee71 Added state functions; writing of process data works.
Florian Pose <fp@igh-essen.com>
parents: 1258
diff changeset
  1793
/*****************************************************************************/
5f9d1abbee71 Added state functions; writing of process data works.
Florian Pose <fp@igh-essen.com>
parents: 1258
diff changeset
  1794
1454
b9986feec1a5 Added EC_IOCTL_APP_TIME.
Florian Pose <fp@igh-essen.com>
parents: 1448
diff changeset
  1795
/** Get the master state.
b9986feec1a5 Added EC_IOCTL_APP_TIME.
Florian Pose <fp@igh-essen.com>
parents: 1448
diff changeset
  1796
 */
b9986feec1a5 Added EC_IOCTL_APP_TIME.
Florian Pose <fp@igh-essen.com>
parents: 1448
diff changeset
  1797
int ec_cdev_ioctl_app_time(
b9986feec1a5 Added EC_IOCTL_APP_TIME.
Florian Pose <fp@igh-essen.com>
parents: 1448
diff changeset
  1798
        ec_master_t *master, /**< EtherCAT master. */
b9986feec1a5 Added EC_IOCTL_APP_TIME.
Florian Pose <fp@igh-essen.com>
parents: 1448
diff changeset
  1799
        unsigned long arg, /**< ioctl() argument. */
b9986feec1a5 Added EC_IOCTL_APP_TIME.
Florian Pose <fp@igh-essen.com>
parents: 1448
diff changeset
  1800
        ec_cdev_priv_t *priv /**< Private data structure of file handle. */
b9986feec1a5 Added EC_IOCTL_APP_TIME.
Florian Pose <fp@igh-essen.com>
parents: 1448
diff changeset
  1801
        )
b9986feec1a5 Added EC_IOCTL_APP_TIME.
Florian Pose <fp@igh-essen.com>
parents: 1448
diff changeset
  1802
{
b9986feec1a5 Added EC_IOCTL_APP_TIME.
Florian Pose <fp@igh-essen.com>
parents: 1448
diff changeset
  1803
    ec_ioctl_app_time_t data;
b9986feec1a5 Added EC_IOCTL_APP_TIME.
Florian Pose <fp@igh-essen.com>
parents: 1448
diff changeset
  1804
    
1507
68e89abadd19 Removed unwanted tabulators.
Florian Pose <fp@igh-essen.com>
parents: 1500
diff changeset
  1805
    if (unlikely(!priv->requested))
68e89abadd19 Removed unwanted tabulators.
Florian Pose <fp@igh-essen.com>
parents: 1500
diff changeset
  1806
        return -EPERM;
1454
b9986feec1a5 Added EC_IOCTL_APP_TIME.
Florian Pose <fp@igh-essen.com>
parents: 1448
diff changeset
  1807
b9986feec1a5 Added EC_IOCTL_APP_TIME.
Florian Pose <fp@igh-essen.com>
parents: 1448
diff changeset
  1808
    if (copy_from_user(&data, (void __user *) arg, sizeof(data))) {
b9986feec1a5 Added EC_IOCTL_APP_TIME.
Florian Pose <fp@igh-essen.com>
parents: 1448
diff changeset
  1809
        return -EFAULT;
b9986feec1a5 Added EC_IOCTL_APP_TIME.
Florian Pose <fp@igh-essen.com>
parents: 1448
diff changeset
  1810
    }
b9986feec1a5 Added EC_IOCTL_APP_TIME.
Florian Pose <fp@igh-essen.com>
parents: 1448
diff changeset
  1811
b9986feec1a5 Added EC_IOCTL_APP_TIME.
Florian Pose <fp@igh-essen.com>
parents: 1448
diff changeset
  1812
    ecrt_master_application_time(master, data.app_time);
b9986feec1a5 Added EC_IOCTL_APP_TIME.
Florian Pose <fp@igh-essen.com>
parents: 1448
diff changeset
  1813
    return 0;
b9986feec1a5 Added EC_IOCTL_APP_TIME.
Florian Pose <fp@igh-essen.com>
parents: 1448
diff changeset
  1814
}
b9986feec1a5 Added EC_IOCTL_APP_TIME.
Florian Pose <fp@igh-essen.com>
parents: 1448
diff changeset
  1815
b9986feec1a5 Added EC_IOCTL_APP_TIME.
Florian Pose <fp@igh-essen.com>
parents: 1448
diff changeset
  1816
/*****************************************************************************/
b9986feec1a5 Added EC_IOCTL_APP_TIME.
Florian Pose <fp@igh-essen.com>
parents: 1448
diff changeset
  1817
1413
44c2b7c0ae1a Userspace library implementation of DC functions.
Florian Pose <fp@igh-essen.com>
parents: 1401
diff changeset
  1818
/** Sync the reference clock.
44c2b7c0ae1a Userspace library implementation of DC functions.
Florian Pose <fp@igh-essen.com>
parents: 1401
diff changeset
  1819
 */
44c2b7c0ae1a Userspace library implementation of DC functions.
Florian Pose <fp@igh-essen.com>
parents: 1401
diff changeset
  1820
int ec_cdev_ioctl_sync_ref(
44c2b7c0ae1a Userspace library implementation of DC functions.
Florian Pose <fp@igh-essen.com>
parents: 1401
diff changeset
  1821
        ec_master_t *master, /**< EtherCAT master. */
44c2b7c0ae1a Userspace library implementation of DC functions.
Florian Pose <fp@igh-essen.com>
parents: 1401
diff changeset
  1822
        unsigned long arg, /**< ioctl() argument. */
44c2b7c0ae1a Userspace library implementation of DC functions.
Florian Pose <fp@igh-essen.com>
parents: 1401
diff changeset
  1823
        ec_cdev_priv_t *priv /**< Private data structure of file handle. */
44c2b7c0ae1a Userspace library implementation of DC functions.
Florian Pose <fp@igh-essen.com>
parents: 1401
diff changeset
  1824
        )
44c2b7c0ae1a Userspace library implementation of DC functions.
Florian Pose <fp@igh-essen.com>
parents: 1401
diff changeset
  1825
{
1507
68e89abadd19 Removed unwanted tabulators.
Florian Pose <fp@igh-essen.com>
parents: 1500
diff changeset
  1826
    if (unlikely(!priv->requested))
68e89abadd19 Removed unwanted tabulators.
Florian Pose <fp@igh-essen.com>
parents: 1500
diff changeset
  1827
        return -EPERM;
1413
44c2b7c0ae1a Userspace library implementation of DC functions.
Florian Pose <fp@igh-essen.com>
parents: 1401
diff changeset
  1828
1489
f77a1182b6f4 EoE processing with kthread.
Florian Pose <fp@igh-essen.com>
parents: 1485
diff changeset
  1829
    down(&master->io_sem);
1434
4c6fe0ae37f1 Separated application time from synchronizing reference clock.
Florian Pose <fp@igh-essen.com>
parents: 1426
diff changeset
  1830
    ecrt_master_sync_reference_clock(master);
1489
f77a1182b6f4 EoE processing with kthread.
Florian Pose <fp@igh-essen.com>
parents: 1485
diff changeset
  1831
    up(&master->io_sem);
1413
44c2b7c0ae1a Userspace library implementation of DC functions.
Florian Pose <fp@igh-essen.com>
parents: 1401
diff changeset
  1832
    return 0;
44c2b7c0ae1a Userspace library implementation of DC functions.
Florian Pose <fp@igh-essen.com>
parents: 1401
diff changeset
  1833
}
44c2b7c0ae1a Userspace library implementation of DC functions.
Florian Pose <fp@igh-essen.com>
parents: 1401
diff changeset
  1834
44c2b7c0ae1a Userspace library implementation of DC functions.
Florian Pose <fp@igh-essen.com>
parents: 1401
diff changeset
  1835
/*****************************************************************************/
44c2b7c0ae1a Userspace library implementation of DC functions.
Florian Pose <fp@igh-essen.com>
parents: 1401
diff changeset
  1836
44c2b7c0ae1a Userspace library implementation of DC functions.
Florian Pose <fp@igh-essen.com>
parents: 1401
diff changeset
  1837
/** Sync the slave clocks.
44c2b7c0ae1a Userspace library implementation of DC functions.
Florian Pose <fp@igh-essen.com>
parents: 1401
diff changeset
  1838
 */
44c2b7c0ae1a Userspace library implementation of DC functions.
Florian Pose <fp@igh-essen.com>
parents: 1401
diff changeset
  1839
int ec_cdev_ioctl_sync_slaves(
44c2b7c0ae1a Userspace library implementation of DC functions.
Florian Pose <fp@igh-essen.com>
parents: 1401
diff changeset
  1840
        ec_master_t *master, /**< EtherCAT master. */
44c2b7c0ae1a Userspace library implementation of DC functions.
Florian Pose <fp@igh-essen.com>
parents: 1401
diff changeset
  1841
        unsigned long arg, /**< ioctl() argument. */
44c2b7c0ae1a Userspace library implementation of DC functions.
Florian Pose <fp@igh-essen.com>
parents: 1401
diff changeset
  1842
        ec_cdev_priv_t *priv /**< Private data structure of file handle. */
44c2b7c0ae1a Userspace library implementation of DC functions.
Florian Pose <fp@igh-essen.com>
parents: 1401
diff changeset
  1843
        )
44c2b7c0ae1a Userspace library implementation of DC functions.
Florian Pose <fp@igh-essen.com>
parents: 1401
diff changeset
  1844
{
1507
68e89abadd19 Removed unwanted tabulators.
Florian Pose <fp@igh-essen.com>
parents: 1500
diff changeset
  1845
    if (unlikely(!priv->requested))
68e89abadd19 Removed unwanted tabulators.
Florian Pose <fp@igh-essen.com>
parents: 1500
diff changeset
  1846
        return -EPERM;
1413
44c2b7c0ae1a Userspace library implementation of DC functions.
Florian Pose <fp@igh-essen.com>
parents: 1401
diff changeset
  1847
1489
f77a1182b6f4 EoE processing with kthread.
Florian Pose <fp@igh-essen.com>
parents: 1485
diff changeset
  1848
    down(&master->io_sem);
1413
44c2b7c0ae1a Userspace library implementation of DC functions.
Florian Pose <fp@igh-essen.com>
parents: 1401
diff changeset
  1849
    ecrt_master_sync_slave_clocks(master);
1489
f77a1182b6f4 EoE processing with kthread.
Florian Pose <fp@igh-essen.com>
parents: 1485
diff changeset
  1850
    up(&master->io_sem);
1413
44c2b7c0ae1a Userspace library implementation of DC functions.
Florian Pose <fp@igh-essen.com>
parents: 1401
diff changeset
  1851
    return 0;
44c2b7c0ae1a Userspace library implementation of DC functions.
Florian Pose <fp@igh-essen.com>
parents: 1401
diff changeset
  1852
}
44c2b7c0ae1a Userspace library implementation of DC functions.
Florian Pose <fp@igh-essen.com>
parents: 1401
diff changeset
  1853
44c2b7c0ae1a Userspace library implementation of DC functions.
Florian Pose <fp@igh-essen.com>
parents: 1401
diff changeset
  1854
/*****************************************************************************/
44c2b7c0ae1a Userspace library implementation of DC functions.
Florian Pose <fp@igh-essen.com>
parents: 1401
diff changeset
  1855
1535
0c484ee12d89 DC synchrony monitoring methods.
Florian Pose <fp@igh-essen.com>
parents: 1531
diff changeset
  1856
/** Queue the sync monitoring datagram.
0c484ee12d89 DC synchrony monitoring methods.
Florian Pose <fp@igh-essen.com>
parents: 1531
diff changeset
  1857
 */
0c484ee12d89 DC synchrony monitoring methods.
Florian Pose <fp@igh-essen.com>
parents: 1531
diff changeset
  1858
int ec_cdev_ioctl_sync_mon_queue(
0c484ee12d89 DC synchrony monitoring methods.
Florian Pose <fp@igh-essen.com>
parents: 1531
diff changeset
  1859
        ec_master_t *master, /**< EtherCAT master. */
0c484ee12d89 DC synchrony monitoring methods.
Florian Pose <fp@igh-essen.com>
parents: 1531
diff changeset
  1860
        unsigned long arg, /**< ioctl() argument. */
0c484ee12d89 DC synchrony monitoring methods.
Florian Pose <fp@igh-essen.com>
parents: 1531
diff changeset
  1861
        ec_cdev_priv_t *priv /**< Private data structure of file handle. */
0c484ee12d89 DC synchrony monitoring methods.
Florian Pose <fp@igh-essen.com>
parents: 1531
diff changeset
  1862
        )
0c484ee12d89 DC synchrony monitoring methods.
Florian Pose <fp@igh-essen.com>
parents: 1531
diff changeset
  1863
{
0c484ee12d89 DC synchrony monitoring methods.
Florian Pose <fp@igh-essen.com>
parents: 1531
diff changeset
  1864
    if (unlikely(!priv->requested))
0c484ee12d89 DC synchrony monitoring methods.
Florian Pose <fp@igh-essen.com>
parents: 1531
diff changeset
  1865
        return -EPERM;
0c484ee12d89 DC synchrony monitoring methods.
Florian Pose <fp@igh-essen.com>
parents: 1531
diff changeset
  1866
0c484ee12d89 DC synchrony monitoring methods.
Florian Pose <fp@igh-essen.com>
parents: 1531
diff changeset
  1867
    down(&master->io_sem);
0c484ee12d89 DC synchrony monitoring methods.
Florian Pose <fp@igh-essen.com>
parents: 1531
diff changeset
  1868
    ecrt_master_sync_monitor_queue(master);
0c484ee12d89 DC synchrony monitoring methods.
Florian Pose <fp@igh-essen.com>
parents: 1531
diff changeset
  1869
    up(&master->io_sem);
0c484ee12d89 DC synchrony monitoring methods.
Florian Pose <fp@igh-essen.com>
parents: 1531
diff changeset
  1870
    return 0;
0c484ee12d89 DC synchrony monitoring methods.
Florian Pose <fp@igh-essen.com>
parents: 1531
diff changeset
  1871
}
0c484ee12d89 DC synchrony monitoring methods.
Florian Pose <fp@igh-essen.com>
parents: 1531
diff changeset
  1872
0c484ee12d89 DC synchrony monitoring methods.
Florian Pose <fp@igh-essen.com>
parents: 1531
diff changeset
  1873
/*****************************************************************************/
0c484ee12d89 DC synchrony monitoring methods.
Florian Pose <fp@igh-essen.com>
parents: 1531
diff changeset
  1874
0c484ee12d89 DC synchrony monitoring methods.
Florian Pose <fp@igh-essen.com>
parents: 1531
diff changeset
  1875
/** Processes the sync monitoring datagram.
0c484ee12d89 DC synchrony monitoring methods.
Florian Pose <fp@igh-essen.com>
parents: 1531
diff changeset
  1876
 */
0c484ee12d89 DC synchrony monitoring methods.
Florian Pose <fp@igh-essen.com>
parents: 1531
diff changeset
  1877
int ec_cdev_ioctl_sync_mon_process(
0c484ee12d89 DC synchrony monitoring methods.
Florian Pose <fp@igh-essen.com>
parents: 1531
diff changeset
  1878
        ec_master_t *master, /**< EtherCAT master. */
0c484ee12d89 DC synchrony monitoring methods.
Florian Pose <fp@igh-essen.com>
parents: 1531
diff changeset
  1879
        unsigned long arg, /**< ioctl() argument. */
0c484ee12d89 DC synchrony monitoring methods.
Florian Pose <fp@igh-essen.com>
parents: 1531
diff changeset
  1880
        ec_cdev_priv_t *priv /**< Private data structure of file handle. */
0c484ee12d89 DC synchrony monitoring methods.
Florian Pose <fp@igh-essen.com>
parents: 1531
diff changeset
  1881
        )
0c484ee12d89 DC synchrony monitoring methods.
Florian Pose <fp@igh-essen.com>
parents: 1531
diff changeset
  1882
{
0c484ee12d89 DC synchrony monitoring methods.
Florian Pose <fp@igh-essen.com>
parents: 1531
diff changeset
  1883
    uint32_t time_diff;
0c484ee12d89 DC synchrony monitoring methods.
Florian Pose <fp@igh-essen.com>
parents: 1531
diff changeset
  1884
0c484ee12d89 DC synchrony monitoring methods.
Florian Pose <fp@igh-essen.com>
parents: 1531
diff changeset
  1885
    if (unlikely(!priv->requested))
0c484ee12d89 DC synchrony monitoring methods.
Florian Pose <fp@igh-essen.com>
parents: 1531
diff changeset
  1886
        return -EPERM;
0c484ee12d89 DC synchrony monitoring methods.
Florian Pose <fp@igh-essen.com>
parents: 1531
diff changeset
  1887
0c484ee12d89 DC synchrony monitoring methods.
Florian Pose <fp@igh-essen.com>
parents: 1531
diff changeset
  1888
    down(&master->io_sem);
0c484ee12d89 DC synchrony monitoring methods.
Florian Pose <fp@igh-essen.com>
parents: 1531
diff changeset
  1889
    time_diff = ecrt_master_sync_monitor_process(master);
0c484ee12d89 DC synchrony monitoring methods.
Florian Pose <fp@igh-essen.com>
parents: 1531
diff changeset
  1890
    up(&master->io_sem);
0c484ee12d89 DC synchrony monitoring methods.
Florian Pose <fp@igh-essen.com>
parents: 1531
diff changeset
  1891
0c484ee12d89 DC synchrony monitoring methods.
Florian Pose <fp@igh-essen.com>
parents: 1531
diff changeset
  1892
    if (copy_to_user((void __user *) arg, &time_diff, sizeof(time_diff)))
0c484ee12d89 DC synchrony monitoring methods.
Florian Pose <fp@igh-essen.com>
parents: 1531
diff changeset
  1893
        return -EFAULT;
0c484ee12d89 DC synchrony monitoring methods.
Florian Pose <fp@igh-essen.com>
parents: 1531
diff changeset
  1894
0c484ee12d89 DC synchrony monitoring methods.
Florian Pose <fp@igh-essen.com>
parents: 1531
diff changeset
  1895
    return 0;
0c484ee12d89 DC synchrony monitoring methods.
Florian Pose <fp@igh-essen.com>
parents: 1531
diff changeset
  1896
}
0c484ee12d89 DC synchrony monitoring methods.
Florian Pose <fp@igh-essen.com>
parents: 1531
diff changeset
  1897
0c484ee12d89 DC synchrony monitoring methods.
Florian Pose <fp@igh-essen.com>
parents: 1531
diff changeset
  1898
/*****************************************************************************/
0c484ee12d89 DC synchrony monitoring methods.
Florian Pose <fp@igh-essen.com>
parents: 1531
diff changeset
  1899
2009
b5391b329b5d Added ecrt_master_reset() method.
Florian Pose <fp@igh-essen.com>
parents: 1972
diff changeset
  1900
/** Reset configuration.
b5391b329b5d Added ecrt_master_reset() method.
Florian Pose <fp@igh-essen.com>
parents: 1972
diff changeset
  1901
 */
b5391b329b5d Added ecrt_master_reset() method.
Florian Pose <fp@igh-essen.com>
parents: 1972
diff changeset
  1902
int ec_cdev_ioctl_reset(
b5391b329b5d Added ecrt_master_reset() method.
Florian Pose <fp@igh-essen.com>
parents: 1972
diff changeset
  1903
        ec_master_t *master, /**< EtherCAT master. */
b5391b329b5d Added ecrt_master_reset() method.
Florian Pose <fp@igh-essen.com>
parents: 1972
diff changeset
  1904
        unsigned long arg, /**< ioctl() argument. */
b5391b329b5d Added ecrt_master_reset() method.
Florian Pose <fp@igh-essen.com>
parents: 1972
diff changeset
  1905
        ec_cdev_priv_t *priv /**< Private data structure of file handle. */
b5391b329b5d Added ecrt_master_reset() method.
Florian Pose <fp@igh-essen.com>
parents: 1972
diff changeset
  1906
        )
b5391b329b5d Added ecrt_master_reset() method.
Florian Pose <fp@igh-essen.com>
parents: 1972
diff changeset
  1907
{
b5391b329b5d Added ecrt_master_reset() method.
Florian Pose <fp@igh-essen.com>
parents: 1972
diff changeset
  1908
    if (unlikely(!priv->requested))
b5391b329b5d Added ecrt_master_reset() method.
Florian Pose <fp@igh-essen.com>
parents: 1972
diff changeset
  1909
        return -EPERM;
b5391b329b5d Added ecrt_master_reset() method.
Florian Pose <fp@igh-essen.com>
parents: 1972
diff changeset
  1910
b5391b329b5d Added ecrt_master_reset() method.
Florian Pose <fp@igh-essen.com>
parents: 1972
diff changeset
  1911
    down(&master->master_sem);
b5391b329b5d Added ecrt_master_reset() method.
Florian Pose <fp@igh-essen.com>
parents: 1972
diff changeset
  1912
    ecrt_master_reset(master);
b5391b329b5d Added ecrt_master_reset() method.
Florian Pose <fp@igh-essen.com>
parents: 1972
diff changeset
  1913
    up(&master->master_sem);
b5391b329b5d Added ecrt_master_reset() method.
Florian Pose <fp@igh-essen.com>
parents: 1972
diff changeset
  1914
    return 0;
b5391b329b5d Added ecrt_master_reset() method.
Florian Pose <fp@igh-essen.com>
parents: 1972
diff changeset
  1915
}
b5391b329b5d Added ecrt_master_reset() method.
Florian Pose <fp@igh-essen.com>
parents: 1972
diff changeset
  1916
b5391b329b5d Added ecrt_master_reset() method.
Florian Pose <fp@igh-essen.com>
parents: 1972
diff changeset
  1917
/*****************************************************************************/
b5391b329b5d Added ecrt_master_reset() method.
Florian Pose <fp@igh-essen.com>
parents: 1972
diff changeset
  1918
1509
a864688e7de5 Added watchdog configuration via application interface (thanks to J. Mohre).
Florian Pose <fp@igh-essen.com>
parents: 1507
diff changeset
  1919
/** Configure a sync manager.
1255
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  1920
 */
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  1921
int ec_cdev_ioctl_sc_sync(
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  1922
        ec_master_t *master, /**< EtherCAT master. */
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  1923
        unsigned long arg, /**< ioctl() argument. */
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  1924
        ec_cdev_priv_t *priv /**< Private data structure of file handle. */
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  1925
        )
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  1926
{
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  1927
    ec_ioctl_config_t data;
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  1928
    ec_slave_config_t *sc;
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  1929
    unsigned int i;
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  1930
    int ret = 0;
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  1931
1507
68e89abadd19 Removed unwanted tabulators.
Florian Pose <fp@igh-essen.com>
parents: 1500
diff changeset
  1932
    if (unlikely(!priv->requested)) {
1255
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  1933
        ret = -EPERM;
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  1934
        goto out_return;
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  1935
    }
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  1936
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  1937
    if (copy_from_user(&data, (void __user *) arg, sizeof(data))) {
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  1938
        ret = -EFAULT;
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  1939
        goto out_return;
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  1940
    }
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  1941
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  1942
    if (down_interruptible(&master->master_sem)) {
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  1943
        ret = -EINTR;
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  1944
        goto out_return;
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  1945
    }
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  1946
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  1947
    if (!(sc = ec_master_get_config(master, data.config_index))) {
1313
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1312
diff changeset
  1948
        ret = -ENOENT;
1255
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  1949
        goto out_up;
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  1950
    }
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  1951
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  1952
    for (i = 0; i < EC_MAX_SYNC_MANAGERS; i++) {
1509
a864688e7de5 Added watchdog configuration via application interface (thanks to J. Mohre).
Florian Pose <fp@igh-essen.com>
parents: 1507
diff changeset
  1953
        if (data.syncs[i].config_this) {
a864688e7de5 Added watchdog configuration via application interface (thanks to J. Mohre).
Florian Pose <fp@igh-essen.com>
parents: 1507
diff changeset
  1954
            if (ecrt_slave_config_sync_manager(sc, i, data.syncs[i].dir,
a864688e7de5 Added watchdog configuration via application interface (thanks to J. Mohre).
Florian Pose <fp@igh-essen.com>
parents: 1507
diff changeset
  1955
                        data.syncs[i].watchdog_mode)) {
1255
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  1956
                ret = -EINVAL;
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  1957
                goto out_up;
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  1958
            }
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  1959
        }
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  1960
    }
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  1961
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  1962
out_up:
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  1963
    up(&master->master_sem);
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  1964
out_return:
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  1965
    return ret;
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  1966
}
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  1967
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  1968
/*****************************************************************************/
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  1969
1509
a864688e7de5 Added watchdog configuration via application interface (thanks to J. Mohre).
Florian Pose <fp@igh-essen.com>
parents: 1507
diff changeset
  1970
/** Configure a slave's watchdogs.
a864688e7de5 Added watchdog configuration via application interface (thanks to J. Mohre).
Florian Pose <fp@igh-essen.com>
parents: 1507
diff changeset
  1971
 */
a864688e7de5 Added watchdog configuration via application interface (thanks to J. Mohre).
Florian Pose <fp@igh-essen.com>
parents: 1507
diff changeset
  1972
int ec_cdev_ioctl_sc_watchdog(
a864688e7de5 Added watchdog configuration via application interface (thanks to J. Mohre).
Florian Pose <fp@igh-essen.com>
parents: 1507
diff changeset
  1973
        ec_master_t *master, /**< EtherCAT master. */
a864688e7de5 Added watchdog configuration via application interface (thanks to J. Mohre).
Florian Pose <fp@igh-essen.com>
parents: 1507
diff changeset
  1974
        unsigned long arg, /**< ioctl() argument. */
a864688e7de5 Added watchdog configuration via application interface (thanks to J. Mohre).
Florian Pose <fp@igh-essen.com>
parents: 1507
diff changeset
  1975
        ec_cdev_priv_t *priv /**< Private data structure of file handle. */
a864688e7de5 Added watchdog configuration via application interface (thanks to J. Mohre).
Florian Pose <fp@igh-essen.com>
parents: 1507
diff changeset
  1976
        )
a864688e7de5 Added watchdog configuration via application interface (thanks to J. Mohre).
Florian Pose <fp@igh-essen.com>
parents: 1507
diff changeset
  1977
{
a864688e7de5 Added watchdog configuration via application interface (thanks to J. Mohre).
Florian Pose <fp@igh-essen.com>
parents: 1507
diff changeset
  1978
    ec_ioctl_config_t data;
a864688e7de5 Added watchdog configuration via application interface (thanks to J. Mohre).
Florian Pose <fp@igh-essen.com>
parents: 1507
diff changeset
  1979
    ec_slave_config_t *sc;
a864688e7de5 Added watchdog configuration via application interface (thanks to J. Mohre).
Florian Pose <fp@igh-essen.com>
parents: 1507
diff changeset
  1980
    int ret = 0;
a864688e7de5 Added watchdog configuration via application interface (thanks to J. Mohre).
Florian Pose <fp@igh-essen.com>
parents: 1507
diff changeset
  1981
a864688e7de5 Added watchdog configuration via application interface (thanks to J. Mohre).
Florian Pose <fp@igh-essen.com>
parents: 1507
diff changeset
  1982
    if (unlikely(!priv->requested)) {
a864688e7de5 Added watchdog configuration via application interface (thanks to J. Mohre).
Florian Pose <fp@igh-essen.com>
parents: 1507
diff changeset
  1983
        ret = -EPERM;
a864688e7de5 Added watchdog configuration via application interface (thanks to J. Mohre).
Florian Pose <fp@igh-essen.com>
parents: 1507
diff changeset
  1984
        goto out_return;
a864688e7de5 Added watchdog configuration via application interface (thanks to J. Mohre).
Florian Pose <fp@igh-essen.com>
parents: 1507
diff changeset
  1985
    }
a864688e7de5 Added watchdog configuration via application interface (thanks to J. Mohre).
Florian Pose <fp@igh-essen.com>
parents: 1507
diff changeset
  1986
a864688e7de5 Added watchdog configuration via application interface (thanks to J. Mohre).
Florian Pose <fp@igh-essen.com>
parents: 1507
diff changeset
  1987
    if (copy_from_user(&data, (void __user *) arg, sizeof(data))) {
a864688e7de5 Added watchdog configuration via application interface (thanks to J. Mohre).
Florian Pose <fp@igh-essen.com>
parents: 1507
diff changeset
  1988
        ret = -EFAULT;
a864688e7de5 Added watchdog configuration via application interface (thanks to J. Mohre).
Florian Pose <fp@igh-essen.com>
parents: 1507
diff changeset
  1989
        goto out_return;
a864688e7de5 Added watchdog configuration via application interface (thanks to J. Mohre).
Florian Pose <fp@igh-essen.com>
parents: 1507
diff changeset
  1990
    }
a864688e7de5 Added watchdog configuration via application interface (thanks to J. Mohre).
Florian Pose <fp@igh-essen.com>
parents: 1507
diff changeset
  1991
a864688e7de5 Added watchdog configuration via application interface (thanks to J. Mohre).
Florian Pose <fp@igh-essen.com>
parents: 1507
diff changeset
  1992
    if (down_interruptible(&master->master_sem)) {
a864688e7de5 Added watchdog configuration via application interface (thanks to J. Mohre).
Florian Pose <fp@igh-essen.com>
parents: 1507
diff changeset
  1993
        ret = -EINTR;
a864688e7de5 Added watchdog configuration via application interface (thanks to J. Mohre).
Florian Pose <fp@igh-essen.com>
parents: 1507
diff changeset
  1994
        goto out_return;
a864688e7de5 Added watchdog configuration via application interface (thanks to J. Mohre).
Florian Pose <fp@igh-essen.com>
parents: 1507
diff changeset
  1995
    }
a864688e7de5 Added watchdog configuration via application interface (thanks to J. Mohre).
Florian Pose <fp@igh-essen.com>
parents: 1507
diff changeset
  1996
a864688e7de5 Added watchdog configuration via application interface (thanks to J. Mohre).
Florian Pose <fp@igh-essen.com>
parents: 1507
diff changeset
  1997
    if (!(sc = ec_master_get_config(master, data.config_index))) {
a864688e7de5 Added watchdog configuration via application interface (thanks to J. Mohre).
Florian Pose <fp@igh-essen.com>
parents: 1507
diff changeset
  1998
        ret = -ENOENT;
a864688e7de5 Added watchdog configuration via application interface (thanks to J. Mohre).
Florian Pose <fp@igh-essen.com>
parents: 1507
diff changeset
  1999
        goto out_up;
a864688e7de5 Added watchdog configuration via application interface (thanks to J. Mohre).
Florian Pose <fp@igh-essen.com>
parents: 1507
diff changeset
  2000
    }
a864688e7de5 Added watchdog configuration via application interface (thanks to J. Mohre).
Florian Pose <fp@igh-essen.com>
parents: 1507
diff changeset
  2001
a864688e7de5 Added watchdog configuration via application interface (thanks to J. Mohre).
Florian Pose <fp@igh-essen.com>
parents: 1507
diff changeset
  2002
    ecrt_slave_config_watchdog(sc,
a864688e7de5 Added watchdog configuration via application interface (thanks to J. Mohre).
Florian Pose <fp@igh-essen.com>
parents: 1507
diff changeset
  2003
            data.watchdog_divider, data.watchdog_intervals);
a864688e7de5 Added watchdog configuration via application interface (thanks to J. Mohre).
Florian Pose <fp@igh-essen.com>
parents: 1507
diff changeset
  2004
a864688e7de5 Added watchdog configuration via application interface (thanks to J. Mohre).
Florian Pose <fp@igh-essen.com>
parents: 1507
diff changeset
  2005
out_up:
a864688e7de5 Added watchdog configuration via application interface (thanks to J. Mohre).
Florian Pose <fp@igh-essen.com>
parents: 1507
diff changeset
  2006
    up(&master->master_sem);
a864688e7de5 Added watchdog configuration via application interface (thanks to J. Mohre).
Florian Pose <fp@igh-essen.com>
parents: 1507
diff changeset
  2007
out_return:
a864688e7de5 Added watchdog configuration via application interface (thanks to J. Mohre).
Florian Pose <fp@igh-essen.com>
parents: 1507
diff changeset
  2008
    return ret;
a864688e7de5 Added watchdog configuration via application interface (thanks to J. Mohre).
Florian Pose <fp@igh-essen.com>
parents: 1507
diff changeset
  2009
}
a864688e7de5 Added watchdog configuration via application interface (thanks to J. Mohre).
Florian Pose <fp@igh-essen.com>
parents: 1507
diff changeset
  2010
a864688e7de5 Added watchdog configuration via application interface (thanks to J. Mohre).
Florian Pose <fp@igh-essen.com>
parents: 1507
diff changeset
  2011
/*****************************************************************************/
a864688e7de5 Added watchdog configuration via application interface (thanks to J. Mohre).
Florian Pose <fp@igh-essen.com>
parents: 1507
diff changeset
  2012
1327
4d179b06dd3c merge -c1604 branches/stable-1.4: Fixed spelling of EtherCAT terms.
Florian Pose <fp@igh-essen.com>
parents: 1326
diff changeset
  2013
/** Add a PDO to the assignment.
1255
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  2014
 */
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  2015
int ec_cdev_ioctl_sc_add_pdo(
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  2016
        ec_master_t *master, /**< EtherCAT master. */
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  2017
        unsigned long arg, /**< ioctl() argument. */
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  2018
        ec_cdev_priv_t *priv /**< Private data structure of file handle. */
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  2019
        )
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  2020
{
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  2021
    ec_ioctl_config_pdo_t data;
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  2022
    ec_slave_config_t *sc;
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  2023
1507
68e89abadd19 Removed unwanted tabulators.
Florian Pose <fp@igh-essen.com>
parents: 1500
diff changeset
  2024
    if (unlikely(!priv->requested))
1255
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  2025
        return -EPERM;
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  2026
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  2027
    if (copy_from_user(&data, (void __user *) arg, sizeof(data)))
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  2028
        return -EFAULT;
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  2029
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  2030
    if (down_interruptible(&master->master_sem))
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  2031
        return -EINTR;
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  2032
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  2033
    if (!(sc = ec_master_get_config(master, data.config_index))) {
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  2034
        up(&master->master_sem);
1313
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1312
diff changeset
  2035
        return -ENOENT;
1255
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  2036
    }
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  2037
2180
912d70d6f0e5 Removed some locks causing latency when using the library; added ioctl()
Florian Pose <fp@igh-essen.com>
parents: 2124
diff changeset
  2038
    up(&master->master_sem); /** \fixme sc could be invalidated */
1255
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  2039
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  2040
    return ecrt_slave_config_pdo_assign_add(sc, data.sync_index, data.index);
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  2041
}
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  2042
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  2043
/*****************************************************************************/
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  2044
1327
4d179b06dd3c merge -c1604 branches/stable-1.4: Fixed spelling of EtherCAT terms.
Florian Pose <fp@igh-essen.com>
parents: 1326
diff changeset
  2045
/** Clears the PDO assignment.
1255
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  2046
 */
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  2047
int ec_cdev_ioctl_sc_clear_pdos(
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  2048
        ec_master_t *master, /**< EtherCAT master. */
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  2049
        unsigned long arg, /**< ioctl() argument. */
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  2050
        ec_cdev_priv_t *priv /**< Private data structure of file handle. */
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  2051
        )
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  2052
{
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  2053
    ec_ioctl_config_pdo_t data;
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  2054
    ec_slave_config_t *sc;
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  2055
1507
68e89abadd19 Removed unwanted tabulators.
Florian Pose <fp@igh-essen.com>
parents: 1500
diff changeset
  2056
    if (unlikely(!priv->requested))
1255
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  2057
        return -EPERM;
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  2058
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  2059
    if (copy_from_user(&data, (void __user *) arg, sizeof(data)))
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  2060
        return -EFAULT;
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  2061
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  2062
    if (down_interruptible(&master->master_sem))
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  2063
        return -EINTR;
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  2064
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  2065
    if (!(sc = ec_master_get_config(master, data.config_index))) {
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  2066
        up(&master->master_sem);
1313
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1312
diff changeset
  2067
        return -ENOENT;
1255
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  2068
    }
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  2069
2180
912d70d6f0e5 Removed some locks causing latency when using the library; added ioctl()
Florian Pose <fp@igh-essen.com>
parents: 2124
diff changeset
  2070
    up(&master->master_sem); /** \fixme sc could be invalidated */
1255
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  2071
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  2072
    ecrt_slave_config_pdo_assign_clear(sc, data.sync_index);
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  2073
    return 0;
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  2074
}
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  2075
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  2076
/*****************************************************************************/
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  2077
1327
4d179b06dd3c merge -c1604 branches/stable-1.4: Fixed spelling of EtherCAT terms.
Florian Pose <fp@igh-essen.com>
parents: 1326
diff changeset
  2078
/** Add an entry to a PDO's mapping.
1255
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  2079
 */
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  2080
int ec_cdev_ioctl_sc_add_entry(
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  2081
        ec_master_t *master, /**< EtherCAT master. */
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  2082
        unsigned long arg, /**< ioctl() argument. */
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  2083
        ec_cdev_priv_t *priv /**< Private data structure of file handle. */
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  2084
        )
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  2085
{
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  2086
    ec_ioctl_add_pdo_entry_t data;
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  2087
    ec_slave_config_t *sc;
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  2088
1507
68e89abadd19 Removed unwanted tabulators.
Florian Pose <fp@igh-essen.com>
parents: 1500
diff changeset
  2089
    if (unlikely(!priv->requested))
1255
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  2090
        return -EPERM;
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  2091
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  2092
    if (copy_from_user(&data, (void __user *) arg, sizeof(data)))
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  2093
        return -EFAULT;
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  2094
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  2095
    if (down_interruptible(&master->master_sem))
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  2096
        return -EINTR;
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  2097
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  2098
    if (!(sc = ec_master_get_config(master, data.config_index))) {
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  2099
        up(&master->master_sem);
1313
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1312
diff changeset
  2100
        return -ENOENT;
1255
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  2101
    }
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  2102
2180
912d70d6f0e5 Removed some locks causing latency when using the library; added ioctl()
Florian Pose <fp@igh-essen.com>
parents: 2124
diff changeset
  2103
    up(&master->master_sem); /** \fixme sc could be invalidated */
1255
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  2104
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  2105
    return ecrt_slave_config_pdo_mapping_add(sc, data.pdo_index,
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  2106
            data.entry_index, data.entry_subindex, data.entry_bit_length);
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  2107
}
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  2108
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  2109
/*****************************************************************************/
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  2110
1327
4d179b06dd3c merge -c1604 branches/stable-1.4: Fixed spelling of EtherCAT terms.
Florian Pose <fp@igh-essen.com>
parents: 1326
diff changeset
  2111
/** Clears the mapping of a PDO.
1255
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  2112
 */
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  2113
int ec_cdev_ioctl_sc_clear_entries(
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  2114
        ec_master_t *master, /**< EtherCAT master. */
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  2115
        unsigned long arg, /**< ioctl() argument. */
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  2116
        ec_cdev_priv_t *priv /**< Private data structure of file handle. */
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  2117
        )
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  2118
{
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  2119
    ec_ioctl_config_pdo_t data;
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  2120
    ec_slave_config_t *sc;
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  2121
1507
68e89abadd19 Removed unwanted tabulators.
Florian Pose <fp@igh-essen.com>
parents: 1500
diff changeset
  2122
    if (unlikely(!priv->requested))
1255
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  2123
        return -EPERM;
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  2124
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  2125
    if (copy_from_user(&data, (void __user *) arg, sizeof(data)))
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  2126
        return -EFAULT;
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  2127
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  2128
    if (down_interruptible(&master->master_sem))
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  2129
        return -EINTR;
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  2130
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  2131
    if (!(sc = ec_master_get_config(master, data.config_index))) {
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  2132
        up(&master->master_sem);
1313
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1312
diff changeset
  2133
        return -ENOENT;
1255
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  2134
    }
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  2135
2180
912d70d6f0e5 Removed some locks causing latency when using the library; added ioctl()
Florian Pose <fp@igh-essen.com>
parents: 2124
diff changeset
  2136
    up(&master->master_sem); /** \fixme sc could be invalidated */
1255
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  2137
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  2138
    ecrt_slave_config_pdo_mapping_clear(sc, data.index);
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  2139
    return 0;
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  2140
}
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  2141
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  2142
/*****************************************************************************/
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  2143
1327
4d179b06dd3c merge -c1604 branches/stable-1.4: Fixed spelling of EtherCAT terms.
Florian Pose <fp@igh-essen.com>
parents: 1326
diff changeset
  2144
/** Registers a PDO entry.
1255
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  2145
 */
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  2146
int ec_cdev_ioctl_sc_reg_pdo_entry(
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  2147
        ec_master_t *master, /**< EtherCAT master. */
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  2148
        unsigned long arg, /**< ioctl() argument. */
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  2149
        ec_cdev_priv_t *priv /**< Private data structure of file handle. */
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  2150
        )
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  2151
{
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  2152
    ec_ioctl_reg_pdo_entry_t data;
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  2153
    ec_slave_config_t *sc;
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  2154
    ec_domain_t *domain;
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  2155
    int ret;
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  2156
1507
68e89abadd19 Removed unwanted tabulators.
Florian Pose <fp@igh-essen.com>
parents: 1500
diff changeset
  2157
    if (unlikely(!priv->requested))
1255
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  2158
        return -EPERM;
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  2159
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  2160
    if (copy_from_user(&data, (void __user *) arg, sizeof(data)))
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  2161
        return -EFAULT;
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  2162
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  2163
    if (down_interruptible(&master->master_sem))
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  2164
        return -EINTR;
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  2165
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  2166
    if (!(sc = ec_master_get_config(master, data.config_index))) {
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  2167
        up(&master->master_sem);
1313
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1312
diff changeset
  2168
        return -ENOENT;
1255
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  2169
    }
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  2170
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  2171
    if (!(domain = ec_master_find_domain(master, data.domain_index))) {
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  2172
        up(&master->master_sem);
1313
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1312
diff changeset
  2173
        return -ENOENT;
1255
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  2174
    }
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  2175
2180
912d70d6f0e5 Removed some locks causing latency when using the library; added ioctl()
Florian Pose <fp@igh-essen.com>
parents: 2124
diff changeset
  2176
    up(&master->master_sem); /** \fixme sc or domain could be invalidated */
1255
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  2177
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  2178
    ret = ecrt_slave_config_reg_pdo_entry(sc, data.entry_index,
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  2179
            data.entry_subindex, domain, &data.bit_position);
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  2180
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  2181
    if (copy_to_user((void __user *) arg, &data, sizeof(data)))
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  2182
        return -EFAULT;
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  2183
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  2184
    return ret;
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  2185
}
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  2186
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  2187
/*****************************************************************************/
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  2188
1448
d7ba0c408a07 Merged ecrt_slave_config_dc_assign_activate() and
Florian Pose <fp@igh-essen.com>
parents: 1447
diff changeset
  2189
/** Sets the DC AssignActivate word and the sync signal times.
d7ba0c408a07 Merged ecrt_slave_config_dc_assign_activate() and
Florian Pose <fp@igh-essen.com>
parents: 1447
diff changeset
  2190
 */
d7ba0c408a07 Merged ecrt_slave_config_dc_assign_activate() and
Florian Pose <fp@igh-essen.com>
parents: 1447
diff changeset
  2191
int ec_cdev_ioctl_sc_dc(
1413
44c2b7c0ae1a Userspace library implementation of DC functions.
Florian Pose <fp@igh-essen.com>
parents: 1401
diff changeset
  2192
        ec_master_t *master, /**< EtherCAT master. */
44c2b7c0ae1a Userspace library implementation of DC functions.
Florian Pose <fp@igh-essen.com>
parents: 1401
diff changeset
  2193
        unsigned long arg, /**< ioctl() argument. */
44c2b7c0ae1a Userspace library implementation of DC functions.
Florian Pose <fp@igh-essen.com>
parents: 1401
diff changeset
  2194
        ec_cdev_priv_t *priv /**< Private data structure of file handle. */
44c2b7c0ae1a Userspace library implementation of DC functions.
Florian Pose <fp@igh-essen.com>
parents: 1401
diff changeset
  2195
        )
44c2b7c0ae1a Userspace library implementation of DC functions.
Florian Pose <fp@igh-essen.com>
parents: 1401
diff changeset
  2196
{
1455
aa18fcfe0fd1 Output DC config in 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 1454
diff changeset
  2197
    ec_ioctl_config_t data;
1413
44c2b7c0ae1a Userspace library implementation of DC functions.
Florian Pose <fp@igh-essen.com>
parents: 1401
diff changeset
  2198
    ec_slave_config_t *sc;
44c2b7c0ae1a Userspace library implementation of DC functions.
Florian Pose <fp@igh-essen.com>
parents: 1401
diff changeset
  2199
1507
68e89abadd19 Removed unwanted tabulators.
Florian Pose <fp@igh-essen.com>
parents: 1500
diff changeset
  2200
    if (unlikely(!priv->requested))
1413
44c2b7c0ae1a Userspace library implementation of DC functions.
Florian Pose <fp@igh-essen.com>
parents: 1401
diff changeset
  2201
        return -EPERM;
44c2b7c0ae1a Userspace library implementation of DC functions.
Florian Pose <fp@igh-essen.com>
parents: 1401
diff changeset
  2202
44c2b7c0ae1a Userspace library implementation of DC functions.
Florian Pose <fp@igh-essen.com>
parents: 1401
diff changeset
  2203
    if (copy_from_user(&data, (void __user *) arg, sizeof(data)))
44c2b7c0ae1a Userspace library implementation of DC functions.
Florian Pose <fp@igh-essen.com>
parents: 1401
diff changeset
  2204
        return -EFAULT;
44c2b7c0ae1a Userspace library implementation of DC functions.
Florian Pose <fp@igh-essen.com>
parents: 1401
diff changeset
  2205
44c2b7c0ae1a Userspace library implementation of DC functions.
Florian Pose <fp@igh-essen.com>
parents: 1401
diff changeset
  2206
    if (down_interruptible(&master->master_sem))
44c2b7c0ae1a Userspace library implementation of DC functions.
Florian Pose <fp@igh-essen.com>
parents: 1401
diff changeset
  2207
        return -EINTR;
44c2b7c0ae1a Userspace library implementation of DC functions.
Florian Pose <fp@igh-essen.com>
parents: 1401
diff changeset
  2208
44c2b7c0ae1a Userspace library implementation of DC functions.
Florian Pose <fp@igh-essen.com>
parents: 1401
diff changeset
  2209
    if (!(sc = ec_master_get_config(master, data.config_index))) {
44c2b7c0ae1a Userspace library implementation of DC functions.
Florian Pose <fp@igh-essen.com>
parents: 1401
diff changeset
  2210
        up(&master->master_sem);
44c2b7c0ae1a Userspace library implementation of DC functions.
Florian Pose <fp@igh-essen.com>
parents: 1401
diff changeset
  2211
        return -ENOENT;
44c2b7c0ae1a Userspace library implementation of DC functions.
Florian Pose <fp@igh-essen.com>
parents: 1401
diff changeset
  2212
    }
44c2b7c0ae1a Userspace library implementation of DC functions.
Florian Pose <fp@igh-essen.com>
parents: 1401
diff changeset
  2213
1455
aa18fcfe0fd1 Output DC config in 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 1454
diff changeset
  2214
    ecrt_slave_config_dc(sc, data.dc_assign_activate,
aa18fcfe0fd1 Output DC config in 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 1454
diff changeset
  2215
            data.dc_sync[0].cycle_time,
aa18fcfe0fd1 Output DC config in 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 1454
diff changeset
  2216
            data.dc_sync[0].shift_time,
aa18fcfe0fd1 Output DC config in 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 1454
diff changeset
  2217
            data.dc_sync[1].cycle_time,
aa18fcfe0fd1 Output DC config in 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 1454
diff changeset
  2218
            data.dc_sync[1].shift_time);
1413
44c2b7c0ae1a Userspace library implementation of DC functions.
Florian Pose <fp@igh-essen.com>
parents: 1401
diff changeset
  2219
44c2b7c0ae1a Userspace library implementation of DC functions.
Florian Pose <fp@igh-essen.com>
parents: 1401
diff changeset
  2220
    up(&master->master_sem);
44c2b7c0ae1a Userspace library implementation of DC functions.
Florian Pose <fp@igh-essen.com>
parents: 1401
diff changeset
  2221
44c2b7c0ae1a Userspace library implementation of DC functions.
Florian Pose <fp@igh-essen.com>
parents: 1401
diff changeset
  2222
    return 0;
44c2b7c0ae1a Userspace library implementation of DC functions.
Florian Pose <fp@igh-essen.com>
parents: 1401
diff changeset
  2223
}
44c2b7c0ae1a Userspace library implementation of DC functions.
Florian Pose <fp@igh-essen.com>
parents: 1401
diff changeset
  2224
44c2b7c0ae1a Userspace library implementation of DC functions.
Florian Pose <fp@igh-essen.com>
parents: 1401
diff changeset
  2225
/*****************************************************************************/
44c2b7c0ae1a Userspace library implementation of DC functions.
Florian Pose <fp@igh-essen.com>
parents: 1401
diff changeset
  2226
1327
4d179b06dd3c merge -c1604 branches/stable-1.4: Fixed spelling of EtherCAT terms.
Florian Pose <fp@igh-essen.com>
parents: 1326
diff changeset
  2227
/** Configures an SDO.
1255
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  2228
 */
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  2229
int ec_cdev_ioctl_sc_sdo(
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  2230
        ec_master_t *master, /**< EtherCAT master. */
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  2231
        unsigned long arg, /**< ioctl() argument. */
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  2232
        ec_cdev_priv_t *priv /**< Private data structure of file handle. */
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  2233
        )
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  2234
{
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  2235
    ec_ioctl_sc_sdo_t data;
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  2236
    ec_slave_config_t *sc;
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  2237
    uint8_t *sdo_data = NULL;
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  2238
    int ret;
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  2239
1507
68e89abadd19 Removed unwanted tabulators.
Florian Pose <fp@igh-essen.com>
parents: 1500
diff changeset
  2240
    if (unlikely(!priv->requested))
1255
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  2241
        return -EPERM;
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  2242
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  2243
    if (copy_from_user(&data, (void __user *) arg, sizeof(data)))
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  2244
        return -EFAULT;
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  2245
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  2246
    if (!data.size)
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  2247
        return -EINVAL;
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  2248
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  2249
    if (!(sdo_data = kmalloc(data.size, GFP_KERNEL))) {
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  2250
        return -ENOMEM;
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  2251
    }
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  2252
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  2253
    if (copy_from_user(sdo_data, (void __user *) data.data, data.size)) {
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  2254
        kfree(sdo_data);
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  2255
        return -EFAULT;
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  2256
    }
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  2257
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  2258
    if (down_interruptible(&master->master_sem)) {
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  2259
        kfree(sdo_data);
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  2260
        return -EINTR;
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  2261
    }
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  2262
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  2263
    if (!(sc = ec_master_get_config(master, data.config_index))) {
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  2264
        up(&master->master_sem);
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  2265
        kfree(sdo_data);
1313
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1312
diff changeset
  2266
        return -ENOENT;
1255
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  2267
    }
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  2268
2180
912d70d6f0e5 Removed some locks causing latency when using the library; added ioctl()
Florian Pose <fp@igh-essen.com>
parents: 2124
diff changeset
  2269
    up(&master->master_sem); /** \fixme sc could be invalidated */
1255
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  2270
1526
66edd310830c Implemented CompleteAccess for SDO downloads.
Florian Pose <fp@igh-essen.com>
parents: 1518
diff changeset
  2271
    if (data.complete_access) {
1831
1875b9fea0ba Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents: 1826
diff changeset
  2272
        ret = ecrt_slave_config_complete_sdo(sc,
1875b9fea0ba Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents: 1826
diff changeset
  2273
                data.index, sdo_data, data.size);
1526
66edd310830c Implemented CompleteAccess for SDO downloads.
Florian Pose <fp@igh-essen.com>
parents: 1518
diff changeset
  2274
    } else {
66edd310830c Implemented CompleteAccess for SDO downloads.
Florian Pose <fp@igh-essen.com>
parents: 1518
diff changeset
  2275
        ret = ecrt_slave_config_sdo(sc, data.index, data.subindex, sdo_data,
66edd310830c Implemented CompleteAccess for SDO downloads.
Florian Pose <fp@igh-essen.com>
parents: 1518
diff changeset
  2276
                data.size);
66edd310830c Implemented CompleteAccess for SDO downloads.
Florian Pose <fp@igh-essen.com>
parents: 1518
diff changeset
  2277
    }
1255
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  2278
    kfree(sdo_data);
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  2279
    return ret;
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  2280
}
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  2281
1258
900f1124e8f8 Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents: 1255
diff changeset
  2282
/*****************************************************************************/
900f1124e8f8 Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents: 1255
diff changeset
  2283
1352
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1350
diff changeset
  2284
/** Create an SDO request.
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1350
diff changeset
  2285
 */
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1350
diff changeset
  2286
int ec_cdev_ioctl_sc_create_sdo_request(
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1350
diff changeset
  2287
        ec_master_t *master, /**< EtherCAT master. */
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1350
diff changeset
  2288
        unsigned long arg, /**< ioctl() argument. */
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1350
diff changeset
  2289
        ec_cdev_priv_t *priv /**< Private data structure of file handle. */
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1350
diff changeset
  2290
        )
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1350
diff changeset
  2291
{
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1350
diff changeset
  2292
    ec_ioctl_sdo_request_t data;
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1350
diff changeset
  2293
    ec_slave_config_t *sc;
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1350
diff changeset
  2294
    ec_sdo_request_t *req;
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1350
diff changeset
  2295
1507
68e89abadd19 Removed unwanted tabulators.
Florian Pose <fp@igh-essen.com>
parents: 1500
diff changeset
  2296
    if (unlikely(!priv->requested))
68e89abadd19 Removed unwanted tabulators.
Florian Pose <fp@igh-essen.com>
parents: 1500
diff changeset
  2297
        return -EPERM;
1352
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1350
diff changeset
  2298
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1350
diff changeset
  2299
    if (copy_from_user(&data, (void __user *) arg, sizeof(data))) {
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1350
diff changeset
  2300
        return -EFAULT;
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1350
diff changeset
  2301
    }
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1350
diff changeset
  2302
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1350
diff changeset
  2303
    data.request_index = 0;
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1350
diff changeset
  2304
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1350
diff changeset
  2305
    if (down_interruptible(&master->master_sem))
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1350
diff changeset
  2306
        return -EINTR;
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1350
diff changeset
  2307
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1350
diff changeset
  2308
    sc = ec_master_get_config(master, data.config_index);
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1350
diff changeset
  2309
    if (!sc) {
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1350
diff changeset
  2310
        up(&master->master_sem);
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1350
diff changeset
  2311
        return -ENOENT;
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1350
diff changeset
  2312
    }
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1350
diff changeset
  2313
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1350
diff changeset
  2314
    list_for_each_entry(req, &sc->sdo_requests, list) {
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1350
diff changeset
  2315
        data.request_index++;
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1350
diff changeset
  2316
    }
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1350
diff changeset
  2317
2180
912d70d6f0e5 Removed some locks causing latency when using the library; added ioctl()
Florian Pose <fp@igh-essen.com>
parents: 2124
diff changeset
  2318
    up(&master->master_sem); /** \fixme sc could be invalidated */
1352
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1350
diff changeset
  2319
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1350
diff changeset
  2320
    req = ecrt_slave_config_create_sdo_request_err(sc, data.sdo_index,
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1350
diff changeset
  2321
            data.sdo_subindex, data.size);
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1350
diff changeset
  2322
    if (IS_ERR(req))
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1350
diff changeset
  2323
        return PTR_ERR(req);
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1350
diff changeset
  2324
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1350
diff changeset
  2325
    if (copy_to_user((void __user *) arg, &data, sizeof(data)))
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1350
diff changeset
  2326
        return -EFAULT;
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1350
diff changeset
  2327
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1350
diff changeset
  2328
    return 0;
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1350
diff changeset
  2329
}
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1350
diff changeset
  2330
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1350
diff changeset
  2331
/*****************************************************************************/
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1350
diff changeset
  2332
1264
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  2333
/** Create a VoE handler.
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  2334
 */
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  2335
int ec_cdev_ioctl_sc_create_voe_handler(
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  2336
        ec_master_t *master, /**< EtherCAT master. */
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  2337
        unsigned long arg, /**< ioctl() argument. */
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  2338
        ec_cdev_priv_t *priv /**< Private data structure of file handle. */
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  2339
        )
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  2340
{
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  2341
    ec_ioctl_voe_t data;
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  2342
    ec_slave_config_t *sc;
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  2343
    ec_voe_handler_t *voe;
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  2344
1507
68e89abadd19 Removed unwanted tabulators.
Florian Pose <fp@igh-essen.com>
parents: 1500
diff changeset
  2345
    if (unlikely(!priv->requested))
68e89abadd19 Removed unwanted tabulators.
Florian Pose <fp@igh-essen.com>
parents: 1500
diff changeset
  2346
        return -EPERM;
1264
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  2347
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  2348
    if (copy_from_user(&data, (void __user *) arg, sizeof(data))) {
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  2349
        return -EFAULT;
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  2350
    }
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  2351
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  2352
    data.voe_index = 0;
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  2353
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  2354
    if (down_interruptible(&master->master_sem))
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  2355
        return -EINTR;
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  2356
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  2357
    sc = ec_master_get_config(master, data.config_index);
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  2358
    if (!sc) {
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  2359
        up(&master->master_sem);
1313
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1312
diff changeset
  2360
        return -ENOENT;
1264
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  2361
    }
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  2362
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  2363
    list_for_each_entry(voe, &sc->voe_handlers, list) {
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  2364
        data.voe_index++;
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  2365
    }
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  2366
2180
912d70d6f0e5 Removed some locks causing latency when using the library; added ioctl()
Florian Pose <fp@igh-essen.com>
parents: 2124
diff changeset
  2367
    up(&master->master_sem); /** \fixme sc could be invalidated */
1264
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  2368
1312
74853e018898 Created backend versions of all API functions returing a pointer; using
Florian Pose <fp@igh-essen.com>
parents: 1284
diff changeset
  2369
    voe = ecrt_slave_config_create_voe_handler_err(sc, data.size);
74853e018898 Created backend versions of all API functions returing a pointer; using
Florian Pose <fp@igh-essen.com>
parents: 1284
diff changeset
  2370
    if (IS_ERR(voe))
74853e018898 Created backend versions of all API functions returing a pointer; using
Florian Pose <fp@igh-essen.com>
parents: 1284
diff changeset
  2371
        return PTR_ERR(voe);
1264
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  2372
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  2373
    if (copy_to_user((void __user *) arg, &data, sizeof(data)))
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  2374
        return -EFAULT;
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  2375
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  2376
    return 0;
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  2377
}
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  2378
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  2379
/*****************************************************************************/
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  2380
1259
5f9d1abbee71 Added state functions; writing of process data works.
Florian Pose <fp@igh-essen.com>
parents: 1258
diff changeset
  2381
/** Get the slave configuration's state.
5f9d1abbee71 Added state functions; writing of process data works.
Florian Pose <fp@igh-essen.com>
parents: 1258
diff changeset
  2382
 */
5f9d1abbee71 Added state functions; writing of process data works.
Florian Pose <fp@igh-essen.com>
parents: 1258
diff changeset
  2383
int ec_cdev_ioctl_sc_state(
5f9d1abbee71 Added state functions; writing of process data works.
Florian Pose <fp@igh-essen.com>
parents: 1258
diff changeset
  2384
        ec_master_t *master, /**< EtherCAT master. */
5f9d1abbee71 Added state functions; writing of process data works.
Florian Pose <fp@igh-essen.com>
parents: 1258
diff changeset
  2385
        unsigned long arg, /**< ioctl() argument. */
5f9d1abbee71 Added state functions; writing of process data works.
Florian Pose <fp@igh-essen.com>
parents: 1258
diff changeset
  2386
        ec_cdev_priv_t *priv /**< Private data structure of file handle. */
5f9d1abbee71 Added state functions; writing of process data works.
Florian Pose <fp@igh-essen.com>
parents: 1258
diff changeset
  2387
        )
5f9d1abbee71 Added state functions; writing of process data works.
Florian Pose <fp@igh-essen.com>
parents: 1258
diff changeset
  2388
{
5f9d1abbee71 Added state functions; writing of process data works.
Florian Pose <fp@igh-essen.com>
parents: 1258
diff changeset
  2389
    ec_ioctl_sc_state_t data;
5f9d1abbee71 Added state functions; writing of process data works.
Florian Pose <fp@igh-essen.com>
parents: 1258
diff changeset
  2390
    const ec_slave_config_t *sc;
5f9d1abbee71 Added state functions; writing of process data works.
Florian Pose <fp@igh-essen.com>
parents: 1258
diff changeset
  2391
    ec_slave_config_state_t state;
5f9d1abbee71 Added state functions; writing of process data works.
Florian Pose <fp@igh-essen.com>
parents: 1258
diff changeset
  2392
    
1507
68e89abadd19 Removed unwanted tabulators.
Florian Pose <fp@igh-essen.com>
parents: 1500
diff changeset
  2393
    if (unlikely(!priv->requested))
68e89abadd19 Removed unwanted tabulators.
Florian Pose <fp@igh-essen.com>
parents: 1500
diff changeset
  2394
        return -EPERM;
1259
5f9d1abbee71 Added state functions; writing of process data works.
Florian Pose <fp@igh-essen.com>
parents: 1258
diff changeset
  2395
5f9d1abbee71 Added state functions; writing of process data works.
Florian Pose <fp@igh-essen.com>
parents: 1258
diff changeset
  2396
    if (copy_from_user(&data, (void __user *) arg, sizeof(data))) {
5f9d1abbee71 Added state functions; writing of process data works.
Florian Pose <fp@igh-essen.com>
parents: 1258
diff changeset
  2397
        return -EFAULT;
5f9d1abbee71 Added state functions; writing of process data works.
Florian Pose <fp@igh-essen.com>
parents: 1258
diff changeset
  2398
    }
5f9d1abbee71 Added state functions; writing of process data works.
Florian Pose <fp@igh-essen.com>
parents: 1258
diff changeset
  2399
2180
912d70d6f0e5 Removed some locks causing latency when using the library; added ioctl()
Florian Pose <fp@igh-essen.com>
parents: 2124
diff changeset
  2400
    /* no locking of master_sem needed, because sc will not be deleted in the
912d70d6f0e5 Removed some locks causing latency when using the library; added ioctl()
Florian Pose <fp@igh-essen.com>
parents: 2124
diff changeset
  2401
     * meantime. */
1259
5f9d1abbee71 Added state functions; writing of process data works.
Florian Pose <fp@igh-essen.com>
parents: 1258
diff changeset
  2402
5f9d1abbee71 Added state functions; writing of process data works.
Florian Pose <fp@igh-essen.com>
parents: 1258
diff changeset
  2403
    if (!(sc = ec_master_get_config_const(master, data.config_index))) {
1313
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1312
diff changeset
  2404
        return -ENOENT;
1259
5f9d1abbee71 Added state functions; writing of process data works.
Florian Pose <fp@igh-essen.com>
parents: 1258
diff changeset
  2405
    }
5f9d1abbee71 Added state functions; writing of process data works.
Florian Pose <fp@igh-essen.com>
parents: 1258
diff changeset
  2406
5f9d1abbee71 Added state functions; writing of process data works.
Florian Pose <fp@igh-essen.com>
parents: 1258
diff changeset
  2407
    ecrt_slave_config_state(sc, &state);
5f9d1abbee71 Added state functions; writing of process data works.
Florian Pose <fp@igh-essen.com>
parents: 1258
diff changeset
  2408
5f9d1abbee71 Added state functions; writing of process data works.
Florian Pose <fp@igh-essen.com>
parents: 1258
diff changeset
  2409
    if (copy_to_user((void __user *) data.state, &state, sizeof(state)))
5f9d1abbee71 Added state functions; writing of process data works.
Florian Pose <fp@igh-essen.com>
parents: 1258
diff changeset
  2410
        return -EFAULT;
5f9d1abbee71 Added state functions; writing of process data works.
Florian Pose <fp@igh-essen.com>
parents: 1258
diff changeset
  2411
5f9d1abbee71 Added state functions; writing of process data works.
Florian Pose <fp@igh-essen.com>
parents: 1258
diff changeset
  2412
    return 0;
5f9d1abbee71 Added state functions; writing of process data works.
Florian Pose <fp@igh-essen.com>
parents: 1258
diff changeset
  2413
}
5f9d1abbee71 Added state functions; writing of process data works.
Florian Pose <fp@igh-essen.com>
parents: 1258
diff changeset
  2414
5f9d1abbee71 Added state functions; writing of process data works.
Florian Pose <fp@igh-essen.com>
parents: 1258
diff changeset
  2415
/*****************************************************************************/
5f9d1abbee71 Added state functions; writing of process data works.
Florian Pose <fp@igh-essen.com>
parents: 1258
diff changeset
  2416
1862
05d224a66270 Implemented ecrt_slave_config_idn() for user-space library.
Florian Pose <fp@igh-essen.com>
parents: 1857
diff changeset
  2417
/** Configures an IDN.
05d224a66270 Implemented ecrt_slave_config_idn() for user-space library.
Florian Pose <fp@igh-essen.com>
parents: 1857
diff changeset
  2418
 */
05d224a66270 Implemented ecrt_slave_config_idn() for user-space library.
Florian Pose <fp@igh-essen.com>
parents: 1857
diff changeset
  2419
int ec_cdev_ioctl_sc_idn(
05d224a66270 Implemented ecrt_slave_config_idn() for user-space library.
Florian Pose <fp@igh-essen.com>
parents: 1857
diff changeset
  2420
        ec_master_t *master, /**< EtherCAT master. */
05d224a66270 Implemented ecrt_slave_config_idn() for user-space library.
Florian Pose <fp@igh-essen.com>
parents: 1857
diff changeset
  2421
        unsigned long arg, /**< ioctl() argument. */
05d224a66270 Implemented ecrt_slave_config_idn() for user-space library.
Florian Pose <fp@igh-essen.com>
parents: 1857
diff changeset
  2422
        ec_cdev_priv_t *priv /**< Private data structure of file handle. */
05d224a66270 Implemented ecrt_slave_config_idn() for user-space library.
Florian Pose <fp@igh-essen.com>
parents: 1857
diff changeset
  2423
        )
05d224a66270 Implemented ecrt_slave_config_idn() for user-space library.
Florian Pose <fp@igh-essen.com>
parents: 1857
diff changeset
  2424
{
05d224a66270 Implemented ecrt_slave_config_idn() for user-space library.
Florian Pose <fp@igh-essen.com>
parents: 1857
diff changeset
  2425
    ec_ioctl_sc_idn_t ioctl;
05d224a66270 Implemented ecrt_slave_config_idn() for user-space library.
Florian Pose <fp@igh-essen.com>
parents: 1857
diff changeset
  2426
    ec_slave_config_t *sc;
05d224a66270 Implemented ecrt_slave_config_idn() for user-space library.
Florian Pose <fp@igh-essen.com>
parents: 1857
diff changeset
  2427
    uint8_t *data = NULL;
05d224a66270 Implemented ecrt_slave_config_idn() for user-space library.
Florian Pose <fp@igh-essen.com>
parents: 1857
diff changeset
  2428
    int ret;
05d224a66270 Implemented ecrt_slave_config_idn() for user-space library.
Florian Pose <fp@igh-essen.com>
parents: 1857
diff changeset
  2429
05d224a66270 Implemented ecrt_slave_config_idn() for user-space library.
Florian Pose <fp@igh-essen.com>
parents: 1857
diff changeset
  2430
    if (unlikely(!priv->requested))
05d224a66270 Implemented ecrt_slave_config_idn() for user-space library.
Florian Pose <fp@igh-essen.com>
parents: 1857
diff changeset
  2431
        return -EPERM;
05d224a66270 Implemented ecrt_slave_config_idn() for user-space library.
Florian Pose <fp@igh-essen.com>
parents: 1857
diff changeset
  2432
05d224a66270 Implemented ecrt_slave_config_idn() for user-space library.
Florian Pose <fp@igh-essen.com>
parents: 1857
diff changeset
  2433
    if (copy_from_user(&ioctl, (void __user *) arg, sizeof(ioctl)))
05d224a66270 Implemented ecrt_slave_config_idn() for user-space library.
Florian Pose <fp@igh-essen.com>
parents: 1857
diff changeset
  2434
        return -EFAULT;
05d224a66270 Implemented ecrt_slave_config_idn() for user-space library.
Florian Pose <fp@igh-essen.com>
parents: 1857
diff changeset
  2435
05d224a66270 Implemented ecrt_slave_config_idn() for user-space library.
Florian Pose <fp@igh-essen.com>
parents: 1857
diff changeset
  2436
    if (!ioctl.size)
05d224a66270 Implemented ecrt_slave_config_idn() for user-space library.
Florian Pose <fp@igh-essen.com>
parents: 1857
diff changeset
  2437
        return -EINVAL;
05d224a66270 Implemented ecrt_slave_config_idn() for user-space library.
Florian Pose <fp@igh-essen.com>
parents: 1857
diff changeset
  2438
05d224a66270 Implemented ecrt_slave_config_idn() for user-space library.
Florian Pose <fp@igh-essen.com>
parents: 1857
diff changeset
  2439
    if (!(data = kmalloc(ioctl.size, GFP_KERNEL))) {
05d224a66270 Implemented ecrt_slave_config_idn() for user-space library.
Florian Pose <fp@igh-essen.com>
parents: 1857
diff changeset
  2440
        return -ENOMEM;
05d224a66270 Implemented ecrt_slave_config_idn() for user-space library.
Florian Pose <fp@igh-essen.com>
parents: 1857
diff changeset
  2441
    }
05d224a66270 Implemented ecrt_slave_config_idn() for user-space library.
Florian Pose <fp@igh-essen.com>
parents: 1857
diff changeset
  2442
05d224a66270 Implemented ecrt_slave_config_idn() for user-space library.
Florian Pose <fp@igh-essen.com>
parents: 1857
diff changeset
  2443
    if (copy_from_user(data, (void __user *) ioctl.data, ioctl.size)) {
05d224a66270 Implemented ecrt_slave_config_idn() for user-space library.
Florian Pose <fp@igh-essen.com>
parents: 1857
diff changeset
  2444
        kfree(data);
05d224a66270 Implemented ecrt_slave_config_idn() for user-space library.
Florian Pose <fp@igh-essen.com>
parents: 1857
diff changeset
  2445
        return -EFAULT;
05d224a66270 Implemented ecrt_slave_config_idn() for user-space library.
Florian Pose <fp@igh-essen.com>
parents: 1857
diff changeset
  2446
    }
05d224a66270 Implemented ecrt_slave_config_idn() for user-space library.
Florian Pose <fp@igh-essen.com>
parents: 1857
diff changeset
  2447
05d224a66270 Implemented ecrt_slave_config_idn() for user-space library.
Florian Pose <fp@igh-essen.com>
parents: 1857
diff changeset
  2448
    if (down_interruptible(&master->master_sem)) {
05d224a66270 Implemented ecrt_slave_config_idn() for user-space library.
Florian Pose <fp@igh-essen.com>
parents: 1857
diff changeset
  2449
        kfree(data);
05d224a66270 Implemented ecrt_slave_config_idn() for user-space library.
Florian Pose <fp@igh-essen.com>
parents: 1857
diff changeset
  2450
        return -EINTR;
05d224a66270 Implemented ecrt_slave_config_idn() for user-space library.
Florian Pose <fp@igh-essen.com>
parents: 1857
diff changeset
  2451
    }
05d224a66270 Implemented ecrt_slave_config_idn() for user-space library.
Florian Pose <fp@igh-essen.com>
parents: 1857
diff changeset
  2452
05d224a66270 Implemented ecrt_slave_config_idn() for user-space library.
Florian Pose <fp@igh-essen.com>
parents: 1857
diff changeset
  2453
    if (!(sc = ec_master_get_config(master, ioctl.config_index))) {
05d224a66270 Implemented ecrt_slave_config_idn() for user-space library.
Florian Pose <fp@igh-essen.com>
parents: 1857
diff changeset
  2454
        up(&master->master_sem);
05d224a66270 Implemented ecrt_slave_config_idn() for user-space library.
Florian Pose <fp@igh-essen.com>
parents: 1857
diff changeset
  2455
        kfree(data);
05d224a66270 Implemented ecrt_slave_config_idn() for user-space library.
Florian Pose <fp@igh-essen.com>
parents: 1857
diff changeset
  2456
        return -ENOENT;
05d224a66270 Implemented ecrt_slave_config_idn() for user-space library.
Florian Pose <fp@igh-essen.com>
parents: 1857
diff changeset
  2457
    }
05d224a66270 Implemented ecrt_slave_config_idn() for user-space library.
Florian Pose <fp@igh-essen.com>
parents: 1857
diff changeset
  2458
2180
912d70d6f0e5 Removed some locks causing latency when using the library; added ioctl()
Florian Pose <fp@igh-essen.com>
parents: 2124
diff changeset
  2459
    up(&master->master_sem); /** \fixme sc could be invalidated */
1862
05d224a66270 Implemented ecrt_slave_config_idn() for user-space library.
Florian Pose <fp@igh-essen.com>
parents: 1857
diff changeset
  2460
1945
f9204699e799 Incremented ioctl interface version; Minor changes.
Florian Pose <fp@igh-essen.com>
parents: 1944
diff changeset
  2461
    ret = ecrt_slave_config_idn(
1952
7d9fb723fc4b Added drive_no parameter to SoE layer.
Florian Pose <fp@igh-essen.com>
parents: 1948
diff changeset
  2462
            sc, ioctl.drive_no, ioctl.idn, ioctl.al_state, data, ioctl.size);
1862
05d224a66270 Implemented ecrt_slave_config_idn() for user-space library.
Florian Pose <fp@igh-essen.com>
parents: 1857
diff changeset
  2463
    kfree(data);
05d224a66270 Implemented ecrt_slave_config_idn() for user-space library.
Florian Pose <fp@igh-essen.com>
parents: 1857
diff changeset
  2464
    return ret;
05d224a66270 Implemented ecrt_slave_config_idn() for user-space library.
Florian Pose <fp@igh-essen.com>
parents: 1857
diff changeset
  2465
}
05d224a66270 Implemented ecrt_slave_config_idn() for user-space library.
Florian Pose <fp@igh-essen.com>
parents: 1857
diff changeset
  2466
05d224a66270 Implemented ecrt_slave_config_idn() for user-space library.
Florian Pose <fp@igh-essen.com>
parents: 1857
diff changeset
  2467
/*****************************************************************************/
05d224a66270 Implemented ecrt_slave_config_idn() for user-space library.
Florian Pose <fp@igh-essen.com>
parents: 1857
diff changeset
  2468
1258
900f1124e8f8 Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents: 1255
diff changeset
  2469
/** Gets the domain's offset in the total process data.
900f1124e8f8 Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents: 1255
diff changeset
  2470
 */
900f1124e8f8 Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents: 1255
diff changeset
  2471
int ec_cdev_ioctl_domain_offset(
900f1124e8f8 Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents: 1255
diff changeset
  2472
        ec_master_t *master, /**< EtherCAT master. */
900f1124e8f8 Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents: 1255
diff changeset
  2473
        unsigned long arg, /**< ioctl() argument. */
900f1124e8f8 Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents: 1255
diff changeset
  2474
        ec_cdev_priv_t *priv /**< Private data structure of file handle. */
900f1124e8f8 Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents: 1255
diff changeset
  2475
        )
900f1124e8f8 Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents: 1255
diff changeset
  2476
{
900f1124e8f8 Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents: 1255
diff changeset
  2477
    int offset = 0;
900f1124e8f8 Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents: 1255
diff changeset
  2478
    const ec_domain_t *domain;
900f1124e8f8 Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents: 1255
diff changeset
  2479
1507
68e89abadd19 Removed unwanted tabulators.
Florian Pose <fp@igh-essen.com>
parents: 1500
diff changeset
  2480
    if (unlikely(!priv->requested))
1258
900f1124e8f8 Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents: 1255
diff changeset
  2481
        return -EPERM;
900f1124e8f8 Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents: 1255
diff changeset
  2482
900f1124e8f8 Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents: 1255
diff changeset
  2483
    if (down_interruptible(&master->master_sem)) {
900f1124e8f8 Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents: 1255
diff changeset
  2484
        return -EINTR;
900f1124e8f8 Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents: 1255
diff changeset
  2485
    }
900f1124e8f8 Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents: 1255
diff changeset
  2486
900f1124e8f8 Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents: 1255
diff changeset
  2487
    list_for_each_entry(domain, &master->domains, list) {
900f1124e8f8 Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents: 1255
diff changeset
  2488
        if (domain->index == arg) {
900f1124e8f8 Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents: 1255
diff changeset
  2489
            up(&master->master_sem);
900f1124e8f8 Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents: 1255
diff changeset
  2490
            return offset;
900f1124e8f8 Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents: 1255
diff changeset
  2491
        }
900f1124e8f8 Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents: 1255
diff changeset
  2492
        offset += ecrt_domain_size(domain);
900f1124e8f8 Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents: 1255
diff changeset
  2493
    }
900f1124e8f8 Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents: 1255
diff changeset
  2494
900f1124e8f8 Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents: 1255
diff changeset
  2495
    up(&master->master_sem);
1313
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1312
diff changeset
  2496
    return -ENOENT;
1258
900f1124e8f8 Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents: 1255
diff changeset
  2497
}
900f1124e8f8 Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents: 1255
diff changeset
  2498
900f1124e8f8 Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents: 1255
diff changeset
  2499
/*****************************************************************************/
900f1124e8f8 Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents: 1255
diff changeset
  2500
900f1124e8f8 Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents: 1255
diff changeset
  2501
/** Process the domain.
900f1124e8f8 Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents: 1255
diff changeset
  2502
 */
900f1124e8f8 Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents: 1255
diff changeset
  2503
int ec_cdev_ioctl_domain_process(
900f1124e8f8 Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents: 1255
diff changeset
  2504
        ec_master_t *master, /**< EtherCAT master. */
900f1124e8f8 Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents: 1255
diff changeset
  2505
        unsigned long arg, /**< ioctl() argument. */
900f1124e8f8 Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents: 1255
diff changeset
  2506
        ec_cdev_priv_t *priv /**< Private data structure of file handle. */
900f1124e8f8 Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents: 1255
diff changeset
  2507
        )
900f1124e8f8 Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents: 1255
diff changeset
  2508
{
900f1124e8f8 Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents: 1255
diff changeset
  2509
    ec_domain_t *domain;
900f1124e8f8 Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents: 1255
diff changeset
  2510
1507
68e89abadd19 Removed unwanted tabulators.
Florian Pose <fp@igh-essen.com>
parents: 1500
diff changeset
  2511
    if (unlikely(!priv->requested))
1258
900f1124e8f8 Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents: 1255
diff changeset
  2512
        return -EPERM;
900f1124e8f8 Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents: 1255
diff changeset
  2513
2180
912d70d6f0e5 Removed some locks causing latency when using the library; added ioctl()
Florian Pose <fp@igh-essen.com>
parents: 2124
diff changeset
  2514
    /* no locking of master_sem needed, because domain will not be deleted in
912d70d6f0e5 Removed some locks causing latency when using the library; added ioctl()
Florian Pose <fp@igh-essen.com>
parents: 2124
diff changeset
  2515
     * the meantime. */
1258
900f1124e8f8 Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents: 1255
diff changeset
  2516
900f1124e8f8 Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents: 1255
diff changeset
  2517
    if (!(domain = ec_master_find_domain(master, arg))) {
1313
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1312
diff changeset
  2518
        return -ENOENT;
1258
900f1124e8f8 Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents: 1255
diff changeset
  2519
    }
900f1124e8f8 Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents: 1255
diff changeset
  2520
900f1124e8f8 Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents: 1255
diff changeset
  2521
    ecrt_domain_process(domain);
900f1124e8f8 Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents: 1255
diff changeset
  2522
    return 0;
900f1124e8f8 Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents: 1255
diff changeset
  2523
}
900f1124e8f8 Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents: 1255
diff changeset
  2524
900f1124e8f8 Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents: 1255
diff changeset
  2525
/*****************************************************************************/
900f1124e8f8 Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents: 1255
diff changeset
  2526
900f1124e8f8 Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents: 1255
diff changeset
  2527
/** Queue the domain.
900f1124e8f8 Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents: 1255
diff changeset
  2528
 */
900f1124e8f8 Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents: 1255
diff changeset
  2529
int ec_cdev_ioctl_domain_queue(
900f1124e8f8 Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents: 1255
diff changeset
  2530
        ec_master_t *master, /**< EtherCAT master. */
900f1124e8f8 Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents: 1255
diff changeset
  2531
        unsigned long arg, /**< ioctl() argument. */
900f1124e8f8 Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents: 1255
diff changeset
  2532
        ec_cdev_priv_t *priv /**< Private data structure of file handle. */
900f1124e8f8 Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents: 1255
diff changeset
  2533
        )
900f1124e8f8 Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents: 1255
diff changeset
  2534
{
900f1124e8f8 Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents: 1255
diff changeset
  2535
    ec_domain_t *domain;
900f1124e8f8 Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents: 1255
diff changeset
  2536
1507
68e89abadd19 Removed unwanted tabulators.
Florian Pose <fp@igh-essen.com>
parents: 1500
diff changeset
  2537
    if (unlikely(!priv->requested))
1258
900f1124e8f8 Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents: 1255
diff changeset
  2538
        return -EPERM;
900f1124e8f8 Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents: 1255
diff changeset
  2539
2180
912d70d6f0e5 Removed some locks causing latency when using the library; added ioctl()
Florian Pose <fp@igh-essen.com>
parents: 2124
diff changeset
  2540
    /* no locking of master_sem needed, because domain will not be deleted in
912d70d6f0e5 Removed some locks causing latency when using the library; added ioctl()
Florian Pose <fp@igh-essen.com>
parents: 2124
diff changeset
  2541
     * the meantime. */
1258
900f1124e8f8 Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents: 1255
diff changeset
  2542
900f1124e8f8 Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents: 1255
diff changeset
  2543
    if (!(domain = ec_master_find_domain(master, arg))) {
1313
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1312
diff changeset
  2544
        return -ENOENT;
1258
900f1124e8f8 Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents: 1255
diff changeset
  2545
    }
900f1124e8f8 Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents: 1255
diff changeset
  2546
900f1124e8f8 Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents: 1255
diff changeset
  2547
    ecrt_domain_queue(domain);
900f1124e8f8 Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents: 1255
diff changeset
  2548
    return 0;
900f1124e8f8 Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents: 1255
diff changeset
  2549
}
900f1124e8f8 Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents: 1255
diff changeset
  2550
1259
5f9d1abbee71 Added state functions; writing of process data works.
Florian Pose <fp@igh-essen.com>
parents: 1258
diff changeset
  2551
/*****************************************************************************/
5f9d1abbee71 Added state functions; writing of process data works.
Florian Pose <fp@igh-essen.com>
parents: 1258
diff changeset
  2552
5f9d1abbee71 Added state functions; writing of process data works.
Florian Pose <fp@igh-essen.com>
parents: 1258
diff changeset
  2553
/** Get the domain state.
5f9d1abbee71 Added state functions; writing of process data works.
Florian Pose <fp@igh-essen.com>
parents: 1258
diff changeset
  2554
 */
5f9d1abbee71 Added state functions; writing of process data works.
Florian Pose <fp@igh-essen.com>
parents: 1258
diff changeset
  2555
int ec_cdev_ioctl_domain_state(
5f9d1abbee71 Added state functions; writing of process data works.
Florian Pose <fp@igh-essen.com>
parents: 1258
diff changeset
  2556
        ec_master_t *master, /**< EtherCAT master. */
5f9d1abbee71 Added state functions; writing of process data works.
Florian Pose <fp@igh-essen.com>
parents: 1258
diff changeset
  2557
        unsigned long arg, /**< ioctl() argument. */
5f9d1abbee71 Added state functions; writing of process data works.
Florian Pose <fp@igh-essen.com>
parents: 1258
diff changeset
  2558
        ec_cdev_priv_t *priv /**< Private data structure of file handle. */
5f9d1abbee71 Added state functions; writing of process data works.
Florian Pose <fp@igh-essen.com>
parents: 1258
diff changeset
  2559
        )
5f9d1abbee71 Added state functions; writing of process data works.
Florian Pose <fp@igh-essen.com>
parents: 1258
diff changeset
  2560
{
5f9d1abbee71 Added state functions; writing of process data works.
Florian Pose <fp@igh-essen.com>
parents: 1258
diff changeset
  2561
    ec_ioctl_domain_state_t data;
5f9d1abbee71 Added state functions; writing of process data works.
Florian Pose <fp@igh-essen.com>
parents: 1258
diff changeset
  2562
    const ec_domain_t *domain;
5f9d1abbee71 Added state functions; writing of process data works.
Florian Pose <fp@igh-essen.com>
parents: 1258
diff changeset
  2563
    ec_domain_state_t state;
5f9d1abbee71 Added state functions; writing of process data works.
Florian Pose <fp@igh-essen.com>
parents: 1258
diff changeset
  2564
    
1507
68e89abadd19 Removed unwanted tabulators.
Florian Pose <fp@igh-essen.com>
parents: 1500
diff changeset
  2565
    if (unlikely(!priv->requested))
68e89abadd19 Removed unwanted tabulators.
Florian Pose <fp@igh-essen.com>
parents: 1500
diff changeset
  2566
        return -EPERM;
1259
5f9d1abbee71 Added state functions; writing of process data works.
Florian Pose <fp@igh-essen.com>
parents: 1258
diff changeset
  2567
5f9d1abbee71 Added state functions; writing of process data works.
Florian Pose <fp@igh-essen.com>
parents: 1258
diff changeset
  2568
    if (copy_from_user(&data, (void __user *) arg, sizeof(data))) {
5f9d1abbee71 Added state functions; writing of process data works.
Florian Pose <fp@igh-essen.com>
parents: 1258
diff changeset
  2569
        return -EFAULT;
5f9d1abbee71 Added state functions; writing of process data works.
Florian Pose <fp@igh-essen.com>
parents: 1258
diff changeset
  2570
    }
5f9d1abbee71 Added state functions; writing of process data works.
Florian Pose <fp@igh-essen.com>
parents: 1258
diff changeset
  2571
2180
912d70d6f0e5 Removed some locks causing latency when using the library; added ioctl()
Florian Pose <fp@igh-essen.com>
parents: 2124
diff changeset
  2572
    /* no locking of master_sem needed, because domain will not be deleted in
912d70d6f0e5 Removed some locks causing latency when using the library; added ioctl()
Florian Pose <fp@igh-essen.com>
parents: 2124
diff changeset
  2573
     * the meantime. */
1259
5f9d1abbee71 Added state functions; writing of process data works.
Florian Pose <fp@igh-essen.com>
parents: 1258
diff changeset
  2574
5f9d1abbee71 Added state functions; writing of process data works.
Florian Pose <fp@igh-essen.com>
parents: 1258
diff changeset
  2575
    if (!(domain = ec_master_find_domain_const(master, data.domain_index))) {
1313
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1312
diff changeset
  2576
        return -ENOENT;
1259
5f9d1abbee71 Added state functions; writing of process data works.
Florian Pose <fp@igh-essen.com>
parents: 1258
diff changeset
  2577
    }
5f9d1abbee71 Added state functions; writing of process data works.
Florian Pose <fp@igh-essen.com>
parents: 1258
diff changeset
  2578
5f9d1abbee71 Added state functions; writing of process data works.
Florian Pose <fp@igh-essen.com>
parents: 1258
diff changeset
  2579
    ecrt_domain_state(domain, &state);
5f9d1abbee71 Added state functions; writing of process data works.
Florian Pose <fp@igh-essen.com>
parents: 1258
diff changeset
  2580
5f9d1abbee71 Added state functions; writing of process data works.
Florian Pose <fp@igh-essen.com>
parents: 1258
diff changeset
  2581
    if (copy_to_user((void __user *) data.state, &state, sizeof(state)))
5f9d1abbee71 Added state functions; writing of process data works.
Florian Pose <fp@igh-essen.com>
parents: 1258
diff changeset
  2582
        return -EFAULT;
5f9d1abbee71 Added state functions; writing of process data works.
Florian Pose <fp@igh-essen.com>
parents: 1258
diff changeset
  2583
5f9d1abbee71 Added state functions; writing of process data works.
Florian Pose <fp@igh-essen.com>
parents: 1258
diff changeset
  2584
    return 0;
5f9d1abbee71 Added state functions; writing of process data works.
Florian Pose <fp@igh-essen.com>
parents: 1258
diff changeset
  2585
}
5f9d1abbee71 Added state functions; writing of process data works.
Florian Pose <fp@igh-essen.com>
parents: 1258
diff changeset
  2586
1264
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  2587
/*****************************************************************************/
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  2588
1352
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1350
diff changeset
  2589
/** Sets an SDO request's timeout.
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1350
diff changeset
  2590
 */
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1350
diff changeset
  2591
int ec_cdev_ioctl_sdo_request_timeout(
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1350
diff changeset
  2592
        ec_master_t *master, /**< EtherCAT master. */
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1350
diff changeset
  2593
        unsigned long arg, /**< ioctl() argument. */
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1350
diff changeset
  2594
        ec_cdev_priv_t *priv /**< Private data structure of file handle. */
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1350
diff changeset
  2595
        )
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1350
diff changeset
  2596
{
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1350
diff changeset
  2597
    ec_ioctl_sdo_request_t data;
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1350
diff changeset
  2598
    ec_slave_config_t *sc;
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1350
diff changeset
  2599
    ec_sdo_request_t *req;
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1350
diff changeset
  2600
1507
68e89abadd19 Removed unwanted tabulators.
Florian Pose <fp@igh-essen.com>
parents: 1500
diff changeset
  2601
    if (unlikely(!priv->requested))
1352
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1350
diff changeset
  2602
        return -EPERM;
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1350
diff changeset
  2603
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1350
diff changeset
  2604
    if (copy_from_user(&data, (void __user *) arg, sizeof(data)))
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1350
diff changeset
  2605
        return -EFAULT;
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1350
diff changeset
  2606
2180
912d70d6f0e5 Removed some locks causing latency when using the library; added ioctl()
Florian Pose <fp@igh-essen.com>
parents: 2124
diff changeset
  2607
    /* no locking of master_sem needed, because neither sc nor req will not be
912d70d6f0e5 Removed some locks causing latency when using the library; added ioctl()
Florian Pose <fp@igh-essen.com>
parents: 2124
diff changeset
  2608
     * deleted in the meantime. */
1352
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1350
diff changeset
  2609
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1350
diff changeset
  2610
    if (!(sc = ec_master_get_config(master, data.config_index))) {
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1350
diff changeset
  2611
        return -ENOENT;
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1350
diff changeset
  2612
    }
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1350
diff changeset
  2613
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1350
diff changeset
  2614
    if (!(req = ec_slave_config_find_sdo_request(sc, data.request_index))) {
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1350
diff changeset
  2615
        return -ENOENT;
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1350
diff changeset
  2616
    }
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1350
diff changeset
  2617
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1350
diff changeset
  2618
    ecrt_sdo_request_timeout(req, data.timeout);
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1350
diff changeset
  2619
    return 0;
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1350
diff changeset
  2620
}
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1350
diff changeset
  2621
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1350
diff changeset
  2622
/*****************************************************************************/
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1350
diff changeset
  2623
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1350
diff changeset
  2624
/** Gets an SDO request's state.
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1350
diff changeset
  2625
 */
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1350
diff changeset
  2626
int ec_cdev_ioctl_sdo_request_state(
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1350
diff changeset
  2627
        ec_master_t *master, /**< EtherCAT master. */
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1350
diff changeset
  2628
        unsigned long arg, /**< ioctl() argument. */
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1350
diff changeset
  2629
        ec_cdev_priv_t *priv /**< Private data structure of file handle. */
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1350
diff changeset
  2630
        )
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1350
diff changeset
  2631
{
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1350
diff changeset
  2632
    ec_ioctl_sdo_request_t data;
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1350
diff changeset
  2633
    ec_slave_config_t *sc;
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1350
diff changeset
  2634
    ec_sdo_request_t *req;
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1350
diff changeset
  2635
1507
68e89abadd19 Removed unwanted tabulators.
Florian Pose <fp@igh-essen.com>
parents: 1500
diff changeset
  2636
    if (unlikely(!priv->requested))
1352
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1350
diff changeset
  2637
        return -EPERM;
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1350
diff changeset
  2638
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1350
diff changeset
  2639
    if (copy_from_user(&data, (void __user *) arg, sizeof(data)))
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1350
diff changeset
  2640
        return -EFAULT;
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1350
diff changeset
  2641
2180
912d70d6f0e5 Removed some locks causing latency when using the library; added ioctl()
Florian Pose <fp@igh-essen.com>
parents: 2124
diff changeset
  2642
    /* no locking of master_sem needed, because neither sc nor req will not be
912d70d6f0e5 Removed some locks causing latency when using the library; added ioctl()
Florian Pose <fp@igh-essen.com>
parents: 2124
diff changeset
  2643
     * deleted in the meantime. */
1352
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1350
diff changeset
  2644
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1350
diff changeset
  2645
    if (!(sc = ec_master_get_config(master, data.config_index))) {
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1350
diff changeset
  2646
        return -ENOENT;
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1350
diff changeset
  2647
    }
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1350
diff changeset
  2648
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1350
diff changeset
  2649
    if (!(req = ec_slave_config_find_sdo_request(sc, data.request_index))) {
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1350
diff changeset
  2650
        return -ENOENT;
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1350
diff changeset
  2651
    }
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1350
diff changeset
  2652
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1350
diff changeset
  2653
    data.state = ecrt_sdo_request_state(req);
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1350
diff changeset
  2654
    if (data.state == EC_REQUEST_SUCCESS && req->dir == EC_DIR_INPUT)
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1350
diff changeset
  2655
        data.size = ecrt_sdo_request_data_size(req);
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1350
diff changeset
  2656
    else
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1350
diff changeset
  2657
        data.size = 0;
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1350
diff changeset
  2658
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1350
diff changeset
  2659
    if (copy_to_user((void __user *) arg, &data, sizeof(data)))
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1350
diff changeset
  2660
        return -EFAULT;
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1350
diff changeset
  2661
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1350
diff changeset
  2662
    return 0;
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1350
diff changeset
  2663
}
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1350
diff changeset
  2664
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1350
diff changeset
  2665
/*****************************************************************************/
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1350
diff changeset
  2666
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1350
diff changeset
  2667
/** Starts an SDO read operation.
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1350
diff changeset
  2668
 */
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1350
diff changeset
  2669
int ec_cdev_ioctl_sdo_request_read(
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1350
diff changeset
  2670
        ec_master_t *master, /**< EtherCAT master. */
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1350
diff changeset
  2671
        unsigned long arg, /**< ioctl() argument. */
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1350
diff changeset
  2672
        ec_cdev_priv_t *priv /**< Private data structure of file handle. */
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1350
diff changeset
  2673
        )
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1350
diff changeset
  2674
{
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1350
diff changeset
  2675
    ec_ioctl_sdo_request_t data;
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1350
diff changeset
  2676
    ec_slave_config_t *sc;
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1350
diff changeset
  2677
    ec_sdo_request_t *req;
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1350
diff changeset
  2678
1507
68e89abadd19 Removed unwanted tabulators.
Florian Pose <fp@igh-essen.com>
parents: 1500
diff changeset
  2679
    if (unlikely(!priv->requested))
1352
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1350
diff changeset
  2680
        return -EPERM;
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1350
diff changeset
  2681
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1350
diff changeset
  2682
    if (copy_from_user(&data, (void __user *) arg, sizeof(data)))
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1350
diff changeset
  2683
        return -EFAULT;
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1350
diff changeset
  2684
2180
912d70d6f0e5 Removed some locks causing latency when using the library; added ioctl()
Florian Pose <fp@igh-essen.com>
parents: 2124
diff changeset
  2685
    /* no locking of master_sem needed, because neither sc nor req will not be
912d70d6f0e5 Removed some locks causing latency when using the library; added ioctl()
Florian Pose <fp@igh-essen.com>
parents: 2124
diff changeset
  2686
     * deleted in the meantime. */
1352
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1350
diff changeset
  2687
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1350
diff changeset
  2688
    if (!(sc = ec_master_get_config(master, data.config_index))) {
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1350
diff changeset
  2689
        return -ENOENT;
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1350
diff changeset
  2690
    }
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1350
diff changeset
  2691
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1350
diff changeset
  2692
    if (!(req = ec_slave_config_find_sdo_request(sc, data.request_index))) {
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1350
diff changeset
  2693
        return -ENOENT;
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1350
diff changeset
  2694
    }
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1350
diff changeset
  2695
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1350
diff changeset
  2696
    ecrt_sdo_request_read(req);
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1350
diff changeset
  2697
    return 0;
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1350
diff changeset
  2698
}
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1350
diff changeset
  2699
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1350
diff changeset
  2700
/*****************************************************************************/
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1350
diff changeset
  2701
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1350
diff changeset
  2702
/** Starts an SDO write operation.
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1350
diff changeset
  2703
 */
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1350
diff changeset
  2704
int ec_cdev_ioctl_sdo_request_write(
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1350
diff changeset
  2705
        ec_master_t *master, /**< EtherCAT master. */
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1350
diff changeset
  2706
        unsigned long arg, /**< ioctl() argument. */
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1350
diff changeset
  2707
        ec_cdev_priv_t *priv /**< Private data structure of file handle. */
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1350
diff changeset
  2708
        )
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1350
diff changeset
  2709
{
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1350
diff changeset
  2710
    ec_ioctl_sdo_request_t data;
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1350
diff changeset
  2711
    ec_slave_config_t *sc;
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1350
diff changeset
  2712
    ec_sdo_request_t *req;
1361
9c16b62326fa Fixed SDO download via library.
Florian Pose <fp@igh-essen.com>
parents: 1352
diff changeset
  2713
    int ret;
1352
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1350
diff changeset
  2714
1507
68e89abadd19 Removed unwanted tabulators.
Florian Pose <fp@igh-essen.com>
parents: 1500
diff changeset
  2715
    if (unlikely(!priv->requested))
1352
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1350
diff changeset
  2716
        return -EPERM;
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1350
diff changeset
  2717
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1350
diff changeset
  2718
    if (copy_from_user(&data, (void __user *) arg, sizeof(data)))
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1350
diff changeset
  2719
        return -EFAULT;
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1350
diff changeset
  2720
1361
9c16b62326fa Fixed SDO download via library.
Florian Pose <fp@igh-essen.com>
parents: 1352
diff changeset
  2721
    if (!data.size) {
1921
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1909
diff changeset
  2722
        EC_MASTER_ERR(master, "SDO download: Data size may not be zero!\n");
1361
9c16b62326fa Fixed SDO download via library.
Florian Pose <fp@igh-essen.com>
parents: 1352
diff changeset
  2723
        return -EINVAL;
9c16b62326fa Fixed SDO download via library.
Florian Pose <fp@igh-essen.com>
parents: 1352
diff changeset
  2724
    }
9c16b62326fa Fixed SDO download via library.
Florian Pose <fp@igh-essen.com>
parents: 1352
diff changeset
  2725
2180
912d70d6f0e5 Removed some locks causing latency when using the library; added ioctl()
Florian Pose <fp@igh-essen.com>
parents: 2124
diff changeset
  2726
    /* no locking of master_sem needed, because neither sc nor req will not be
912d70d6f0e5 Removed some locks causing latency when using the library; added ioctl()
Florian Pose <fp@igh-essen.com>
parents: 2124
diff changeset
  2727
     * deleted in the meantime. */
1352
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1350
diff changeset
  2728
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1350
diff changeset
  2729
    if (!(sc = ec_master_get_config(master, data.config_index))) {
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1350
diff changeset
  2730
        return -ENOENT;
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1350
diff changeset
  2731
    }
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1350
diff changeset
  2732
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1350
diff changeset
  2733
    if (!(req = ec_slave_config_find_sdo_request(sc, data.request_index))) {
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1350
diff changeset
  2734
        return -ENOENT;
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1350
diff changeset
  2735
    }
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1350
diff changeset
  2736
1361
9c16b62326fa Fixed SDO download via library.
Florian Pose <fp@igh-essen.com>
parents: 1352
diff changeset
  2737
    ret = ec_sdo_request_alloc(req, data.size);
9c16b62326fa Fixed SDO download via library.
Florian Pose <fp@igh-essen.com>
parents: 1352
diff changeset
  2738
    if (ret)
9c16b62326fa Fixed SDO download via library.
Florian Pose <fp@igh-essen.com>
parents: 1352
diff changeset
  2739
        return ret;
9c16b62326fa Fixed SDO download via library.
Florian Pose <fp@igh-essen.com>
parents: 1352
diff changeset
  2740
9c16b62326fa Fixed SDO download via library.
Florian Pose <fp@igh-essen.com>
parents: 1352
diff changeset
  2741
    if (copy_from_user(req->data, (void __user *) data.data, data.size))
9c16b62326fa Fixed SDO download via library.
Florian Pose <fp@igh-essen.com>
parents: 1352
diff changeset
  2742
        return -EFAULT;
9c16b62326fa Fixed SDO download via library.
Florian Pose <fp@igh-essen.com>
parents: 1352
diff changeset
  2743
9c16b62326fa Fixed SDO download via library.
Florian Pose <fp@igh-essen.com>
parents: 1352
diff changeset
  2744
    req->data_size = data.size;
1352
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1350
diff changeset
  2745
    ecrt_sdo_request_write(req);
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1350
diff changeset
  2746
    return 0;
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1350
diff changeset
  2747
}
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1350
diff changeset
  2748
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1350
diff changeset
  2749
/*****************************************************************************/
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1350
diff changeset
  2750
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1350
diff changeset
  2751
/** Read SDO data.
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1350
diff changeset
  2752
 */
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1350
diff changeset
  2753
int ec_cdev_ioctl_sdo_request_data(
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1350
diff changeset
  2754
        ec_master_t *master, /**< EtherCAT master. */
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1350
diff changeset
  2755
        unsigned long arg, /**< ioctl() argument. */
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1350
diff changeset
  2756
        ec_cdev_priv_t *priv /**< Private data structure of file handle. */
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1350
diff changeset
  2757
        )
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1350
diff changeset
  2758
{
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1350
diff changeset
  2759
    ec_ioctl_sdo_request_t data;
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1350
diff changeset
  2760
    ec_slave_config_t *sc;
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1350
diff changeset
  2761
    ec_sdo_request_t *req;
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1350
diff changeset
  2762
1507
68e89abadd19 Removed unwanted tabulators.
Florian Pose <fp@igh-essen.com>
parents: 1500
diff changeset
  2763
    if (unlikely(!priv->requested))
1352
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1350
diff changeset
  2764
        return -EPERM;
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1350
diff changeset
  2765
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1350
diff changeset
  2766
    if (copy_from_user(&data, (void __user *) arg, sizeof(data)))
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1350
diff changeset
  2767
        return -EFAULT;
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1350
diff changeset
  2768
2180
912d70d6f0e5 Removed some locks causing latency when using the library; added ioctl()
Florian Pose <fp@igh-essen.com>
parents: 2124
diff changeset
  2769
    /* no locking of master_sem needed, because neither sc nor req will not be
912d70d6f0e5 Removed some locks causing latency when using the library; added ioctl()
Florian Pose <fp@igh-essen.com>
parents: 2124
diff changeset
  2770
     * deleted in the meantime. */
1352
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1350
diff changeset
  2771
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1350
diff changeset
  2772
    if (!(sc = ec_master_get_config(master, data.config_index))) {
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1350
diff changeset
  2773
        return -ENOENT;
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1350
diff changeset
  2774
    }
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1350
diff changeset
  2775
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1350
diff changeset
  2776
    if (!(req = ec_slave_config_find_sdo_request(sc, data.request_index))) {
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1350
diff changeset
  2777
        return -ENOENT;
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1350
diff changeset
  2778
    }
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1350
diff changeset
  2779
1362
2d6e0b01c80a Fixed SDO upload via library.
Florian Pose <fp@igh-essen.com>
parents: 1361
diff changeset
  2780
    if (copy_to_user((void __user *) data.data, ecrt_sdo_request_data(req),
2d6e0b01c80a Fixed SDO upload via library.
Florian Pose <fp@igh-essen.com>
parents: 1361
diff changeset
  2781
                ecrt_sdo_request_data_size(req)))
2d6e0b01c80a Fixed SDO upload via library.
Florian Pose <fp@igh-essen.com>
parents: 1361
diff changeset
  2782
        return -EFAULT;
2d6e0b01c80a Fixed SDO upload via library.
Florian Pose <fp@igh-essen.com>
parents: 1361
diff changeset
  2783
1352
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1350
diff changeset
  2784
    return 0;
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1350
diff changeset
  2785
}
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1350
diff changeset
  2786
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1350
diff changeset
  2787
/*****************************************************************************/
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1350
diff changeset
  2788
1264
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  2789
/** Sets the VoE send header.
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  2790
 */
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  2791
int ec_cdev_ioctl_voe_send_header(
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  2792
        ec_master_t *master, /**< EtherCAT master. */
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  2793
        unsigned long arg, /**< ioctl() argument. */
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  2794
        ec_cdev_priv_t *priv /**< Private data structure of file handle. */
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  2795
        )
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  2796
{
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  2797
    ec_ioctl_voe_t data;
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  2798
    ec_slave_config_t *sc;
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  2799
    ec_voe_handler_t *voe;
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  2800
    uint32_t vendor_id;
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  2801
    uint16_t vendor_type;
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  2802
1507
68e89abadd19 Removed unwanted tabulators.
Florian Pose <fp@igh-essen.com>
parents: 1500
diff changeset
  2803
    if (unlikely(!priv->requested))
1264
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  2804
        return -EPERM;
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  2805
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  2806
    if (copy_from_user(&data, (void __user *) arg, sizeof(data)))
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  2807
        return -EFAULT;
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  2808
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  2809
    if (get_user(vendor_id, data.vendor_id))
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  2810
        return -EFAULT;
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  2811
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  2812
    if (get_user(vendor_type, data.vendor_type))
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  2813
        return -EFAULT;
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  2814
2180
912d70d6f0e5 Removed some locks causing latency when using the library; added ioctl()
Florian Pose <fp@igh-essen.com>
parents: 2124
diff changeset
  2815
    /* no locking of master_sem needed, because neither sc nor voe will not be
912d70d6f0e5 Removed some locks causing latency when using the library; added ioctl()
Florian Pose <fp@igh-essen.com>
parents: 2124
diff changeset
  2816
     * deleted in the meantime. */
1264
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  2817
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  2818
    if (!(sc = ec_master_get_config(master, data.config_index))) {
1313
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1312
diff changeset
  2819
        return -ENOENT;
1264
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  2820
    }
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  2821
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  2822
    if (!(voe = ec_slave_config_find_voe_handler(sc, data.voe_index))) {
1313
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1312
diff changeset
  2823
        return -ENOENT;
1264
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  2824
    }
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  2825
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  2826
    ecrt_voe_handler_send_header(voe, vendor_id, vendor_type);
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  2827
    return 0;
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  2828
}
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  2829
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  2830
/*****************************************************************************/
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  2831
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  2832
/** Gets the received VoE header.
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  2833
 */
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  2834
int ec_cdev_ioctl_voe_rec_header(
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  2835
        ec_master_t *master, /**< EtherCAT master. */
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  2836
        unsigned long arg, /**< ioctl() argument. */
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  2837
        ec_cdev_priv_t *priv /**< Private data structure of file handle. */
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  2838
        )
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  2839
{
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  2840
    ec_ioctl_voe_t data;
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  2841
    ec_slave_config_t *sc;
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  2842
    ec_voe_handler_t *voe;
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  2843
    uint32_t vendor_id;
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  2844
    uint16_t vendor_type;
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  2845
1507
68e89abadd19 Removed unwanted tabulators.
Florian Pose <fp@igh-essen.com>
parents: 1500
diff changeset
  2846
    if (unlikely(!priv->requested))
1264
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  2847
        return -EPERM;
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  2848
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  2849
    if (copy_from_user(&data, (void __user *) arg, sizeof(data)))
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  2850
        return -EFAULT;
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  2851
2180
912d70d6f0e5 Removed some locks causing latency when using the library; added ioctl()
Florian Pose <fp@igh-essen.com>
parents: 2124
diff changeset
  2852
    /* no locking of master_sem needed, because neither sc nor voe will not be
912d70d6f0e5 Removed some locks causing latency when using the library; added ioctl()
Florian Pose <fp@igh-essen.com>
parents: 2124
diff changeset
  2853
     * deleted in the meantime. */
1264
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  2854
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  2855
    if (!(sc = ec_master_get_config(master, data.config_index))) {
1313
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1312
diff changeset
  2856
        return -ENOENT;
1264
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  2857
    }
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  2858
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  2859
    if (!(voe = ec_slave_config_find_voe_handler(sc, data.voe_index))) {
1313
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1312
diff changeset
  2860
        return -ENOENT;
1264
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  2861
    }
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  2862
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  2863
    ecrt_voe_handler_received_header(voe, &vendor_id, &vendor_type);
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  2864
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  2865
    if (likely(data.vendor_id))
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  2866
        if (put_user(vendor_id, data.vendor_id))
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  2867
            return -EFAULT;
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  2868
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  2869
    if (likely(data.vendor_type))
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  2870
        if (put_user(vendor_type, data.vendor_type))
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  2871
            return -EFAULT;
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  2872
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  2873
    return 0;
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  2874
}
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  2875
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  2876
/*****************************************************************************/
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  2877
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  2878
/** Starts a VoE read operation.
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  2879
 */
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  2880
int ec_cdev_ioctl_voe_read(
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  2881
        ec_master_t *master, /**< EtherCAT master. */
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  2882
        unsigned long arg, /**< ioctl() argument. */
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  2883
        ec_cdev_priv_t *priv /**< Private data structure of file handle. */
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  2884
        )
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  2885
{
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  2886
    ec_ioctl_voe_t data;
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  2887
    ec_slave_config_t *sc;
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  2888
    ec_voe_handler_t *voe;
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  2889
1507
68e89abadd19 Removed unwanted tabulators.
Florian Pose <fp@igh-essen.com>
parents: 1500
diff changeset
  2890
    if (unlikely(!priv->requested))
1264
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  2891
        return -EPERM;
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  2892
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  2893
    if (copy_from_user(&data, (void __user *) arg, sizeof(data)))
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  2894
        return -EFAULT;
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  2895
2180
912d70d6f0e5 Removed some locks causing latency when using the library; added ioctl()
Florian Pose <fp@igh-essen.com>
parents: 2124
diff changeset
  2896
    /* no locking of master_sem needed, because neither sc nor voe will not be
912d70d6f0e5 Removed some locks causing latency when using the library; added ioctl()
Florian Pose <fp@igh-essen.com>
parents: 2124
diff changeset
  2897
     * deleted in the meantime. */
1264
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  2898
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  2899
    if (!(sc = ec_master_get_config(master, data.config_index))) {
1313
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1312
diff changeset
  2900
        return -ENOENT;
1264
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  2901
    }
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  2902
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  2903
    if (!(voe = ec_slave_config_find_voe_handler(sc, data.voe_index))) {
1313
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1312
diff changeset
  2904
        return -ENOENT;
1264
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  2905
    }
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  2906
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  2907
    ecrt_voe_handler_read(voe);
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  2908
    return 0;
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  2909
}
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  2910
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  2911
/*****************************************************************************/
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  2912
1314
b3d06a8807b3 Included ecrt_voe_handler_read_nosync()-Patch by Mathias Weber.
Florian Pose <fp@igh-essen.com>
parents: 1313
diff changeset
  2913
/** Starts a VoE read operation without sending a sync message first.
b3d06a8807b3 Included ecrt_voe_handler_read_nosync()-Patch by Mathias Weber.
Florian Pose <fp@igh-essen.com>
parents: 1313
diff changeset
  2914
 */
b3d06a8807b3 Included ecrt_voe_handler_read_nosync()-Patch by Mathias Weber.
Florian Pose <fp@igh-essen.com>
parents: 1313
diff changeset
  2915
int ec_cdev_ioctl_voe_read_nosync(
b3d06a8807b3 Included ecrt_voe_handler_read_nosync()-Patch by Mathias Weber.
Florian Pose <fp@igh-essen.com>
parents: 1313
diff changeset
  2916
        ec_master_t *master, /**< EtherCAT master. */
b3d06a8807b3 Included ecrt_voe_handler_read_nosync()-Patch by Mathias Weber.
Florian Pose <fp@igh-essen.com>
parents: 1313
diff changeset
  2917
        unsigned long arg, /**< ioctl() argument. */
b3d06a8807b3 Included ecrt_voe_handler_read_nosync()-Patch by Mathias Weber.
Florian Pose <fp@igh-essen.com>
parents: 1313
diff changeset
  2918
        ec_cdev_priv_t *priv /**< Private data structure of file handle. */
b3d06a8807b3 Included ecrt_voe_handler_read_nosync()-Patch by Mathias Weber.
Florian Pose <fp@igh-essen.com>
parents: 1313
diff changeset
  2919
        )
b3d06a8807b3 Included ecrt_voe_handler_read_nosync()-Patch by Mathias Weber.
Florian Pose <fp@igh-essen.com>
parents: 1313
diff changeset
  2920
{
b3d06a8807b3 Included ecrt_voe_handler_read_nosync()-Patch by Mathias Weber.
Florian Pose <fp@igh-essen.com>
parents: 1313
diff changeset
  2921
    ec_ioctl_voe_t data;
b3d06a8807b3 Included ecrt_voe_handler_read_nosync()-Patch by Mathias Weber.
Florian Pose <fp@igh-essen.com>
parents: 1313
diff changeset
  2922
    ec_slave_config_t *sc;
b3d06a8807b3 Included ecrt_voe_handler_read_nosync()-Patch by Mathias Weber.
Florian Pose <fp@igh-essen.com>
parents: 1313
diff changeset
  2923
    ec_voe_handler_t *voe;
b3d06a8807b3 Included ecrt_voe_handler_read_nosync()-Patch by Mathias Weber.
Florian Pose <fp@igh-essen.com>
parents: 1313
diff changeset
  2924
1507
68e89abadd19 Removed unwanted tabulators.
Florian Pose <fp@igh-essen.com>
parents: 1500
diff changeset
  2925
    if (unlikely(!priv->requested))
1314
b3d06a8807b3 Included ecrt_voe_handler_read_nosync()-Patch by Mathias Weber.
Florian Pose <fp@igh-essen.com>
parents: 1313
diff changeset
  2926
        return -EPERM;
b3d06a8807b3 Included ecrt_voe_handler_read_nosync()-Patch by Mathias Weber.
Florian Pose <fp@igh-essen.com>
parents: 1313
diff changeset
  2927
b3d06a8807b3 Included ecrt_voe_handler_read_nosync()-Patch by Mathias Weber.
Florian Pose <fp@igh-essen.com>
parents: 1313
diff changeset
  2928
    if (copy_from_user(&data, (void __user *) arg, sizeof(data)))
b3d06a8807b3 Included ecrt_voe_handler_read_nosync()-Patch by Mathias Weber.
Florian Pose <fp@igh-essen.com>
parents: 1313
diff changeset
  2929
        return -EFAULT;
b3d06a8807b3 Included ecrt_voe_handler_read_nosync()-Patch by Mathias Weber.
Florian Pose <fp@igh-essen.com>
parents: 1313
diff changeset
  2930
2180
912d70d6f0e5 Removed some locks causing latency when using the library; added ioctl()
Florian Pose <fp@igh-essen.com>
parents: 2124
diff changeset
  2931
    /* no locking of master_sem needed, because neither sc nor voe will not be
912d70d6f0e5 Removed some locks causing latency when using the library; added ioctl()
Florian Pose <fp@igh-essen.com>
parents: 2124
diff changeset
  2932
     * deleted in the meantime. */
1314
b3d06a8807b3 Included ecrt_voe_handler_read_nosync()-Patch by Mathias Weber.
Florian Pose <fp@igh-essen.com>
parents: 1313
diff changeset
  2933
b3d06a8807b3 Included ecrt_voe_handler_read_nosync()-Patch by Mathias Weber.
Florian Pose <fp@igh-essen.com>
parents: 1313
diff changeset
  2934
    if (!(sc = ec_master_get_config(master, data.config_index))) {
b3d06a8807b3 Included ecrt_voe_handler_read_nosync()-Patch by Mathias Weber.
Florian Pose <fp@igh-essen.com>
parents: 1313
diff changeset
  2935
        return -ENOENT;
b3d06a8807b3 Included ecrt_voe_handler_read_nosync()-Patch by Mathias Weber.
Florian Pose <fp@igh-essen.com>
parents: 1313
diff changeset
  2936
    }
b3d06a8807b3 Included ecrt_voe_handler_read_nosync()-Patch by Mathias Weber.
Florian Pose <fp@igh-essen.com>
parents: 1313
diff changeset
  2937
b3d06a8807b3 Included ecrt_voe_handler_read_nosync()-Patch by Mathias Weber.
Florian Pose <fp@igh-essen.com>
parents: 1313
diff changeset
  2938
    if (!(voe = ec_slave_config_find_voe_handler(sc, data.voe_index))) {
b3d06a8807b3 Included ecrt_voe_handler_read_nosync()-Patch by Mathias Weber.
Florian Pose <fp@igh-essen.com>
parents: 1313
diff changeset
  2939
        return -ENOENT;
b3d06a8807b3 Included ecrt_voe_handler_read_nosync()-Patch by Mathias Weber.
Florian Pose <fp@igh-essen.com>
parents: 1313
diff changeset
  2940
    }
b3d06a8807b3 Included ecrt_voe_handler_read_nosync()-Patch by Mathias Weber.
Florian Pose <fp@igh-essen.com>
parents: 1313
diff changeset
  2941
b3d06a8807b3 Included ecrt_voe_handler_read_nosync()-Patch by Mathias Weber.
Florian Pose <fp@igh-essen.com>
parents: 1313
diff changeset
  2942
    ecrt_voe_handler_read_nosync(voe);
b3d06a8807b3 Included ecrt_voe_handler_read_nosync()-Patch by Mathias Weber.
Florian Pose <fp@igh-essen.com>
parents: 1313
diff changeset
  2943
    return 0;
b3d06a8807b3 Included ecrt_voe_handler_read_nosync()-Patch by Mathias Weber.
Florian Pose <fp@igh-essen.com>
parents: 1313
diff changeset
  2944
}
b3d06a8807b3 Included ecrt_voe_handler_read_nosync()-Patch by Mathias Weber.
Florian Pose <fp@igh-essen.com>
parents: 1313
diff changeset
  2945
b3d06a8807b3 Included ecrt_voe_handler_read_nosync()-Patch by Mathias Weber.
Florian Pose <fp@igh-essen.com>
parents: 1313
diff changeset
  2946
/*****************************************************************************/
b3d06a8807b3 Included ecrt_voe_handler_read_nosync()-Patch by Mathias Weber.
Florian Pose <fp@igh-essen.com>
parents: 1313
diff changeset
  2947
1264
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  2948
/** Starts a VoE write operation.
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  2949
 */
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  2950
int ec_cdev_ioctl_voe_write(
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  2951
        ec_master_t *master, /**< EtherCAT master. */
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  2952
        unsigned long arg, /**< ioctl() argument. */
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  2953
        ec_cdev_priv_t *priv /**< Private data structure of file handle. */
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  2954
        )
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  2955
{
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  2956
    ec_ioctl_voe_t data;
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  2957
    ec_slave_config_t *sc;
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  2958
    ec_voe_handler_t *voe;
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  2959
1507
68e89abadd19 Removed unwanted tabulators.
Florian Pose <fp@igh-essen.com>
parents: 1500
diff changeset
  2960
    if (unlikely(!priv->requested))
1264
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  2961
        return -EPERM;
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  2962
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  2963
    if (copy_from_user(&data, (void __user *) arg, sizeof(data)))
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  2964
        return -EFAULT;
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  2965
2180
912d70d6f0e5 Removed some locks causing latency when using the library; added ioctl()
Florian Pose <fp@igh-essen.com>
parents: 2124
diff changeset
  2966
    /* no locking of master_sem needed, because neither sc nor voe will not be
912d70d6f0e5 Removed some locks causing latency when using the library; added ioctl()
Florian Pose <fp@igh-essen.com>
parents: 2124
diff changeset
  2967
     * deleted in the meantime. */
1264
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  2968
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  2969
    if (!(sc = ec_master_get_config(master, data.config_index))) {
1313
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1312
diff changeset
  2970
        return -ENOENT;
1264
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  2971
    }
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  2972
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  2973
    if (!(voe = ec_slave_config_find_voe_handler(sc, data.voe_index))) {
1313
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1312
diff changeset
  2974
        return -ENOENT;
1264
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  2975
    }
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  2976
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  2977
    if (data.size) {
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  2978
        if (data.size > ec_voe_handler_mem_size(voe))
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  2979
            return -EOVERFLOW;
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  2980
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  2981
        if (copy_from_user(ecrt_voe_handler_data(voe),
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  2982
                    (void __user *) data.data, data.size))
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  2983
            return -EFAULT;
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  2984
    }
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  2985
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  2986
    ecrt_voe_handler_write(voe, data.size);
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  2987
    return 0;
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  2988
}
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  2989
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  2990
/*****************************************************************************/
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  2991
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  2992
/** Executes the VoE state machine.
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  2993
 */
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  2994
int ec_cdev_ioctl_voe_exec(
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  2995
        ec_master_t *master, /**< EtherCAT master. */
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  2996
        unsigned long arg, /**< ioctl() argument. */
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  2997
        ec_cdev_priv_t *priv /**< Private data structure of file handle. */
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  2998
        )
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  2999
{
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  3000
    ec_ioctl_voe_t data;
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  3001
    ec_slave_config_t *sc;
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  3002
    ec_voe_handler_t *voe;
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  3003
1507
68e89abadd19 Removed unwanted tabulators.
Florian Pose <fp@igh-essen.com>
parents: 1500
diff changeset
  3004
    if (unlikely(!priv->requested))
1264
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  3005
        return -EPERM;
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  3006
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  3007
    if (copy_from_user(&data, (void __user *) arg, sizeof(data)))
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  3008
        return -EFAULT;
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  3009
2180
912d70d6f0e5 Removed some locks causing latency when using the library; added ioctl()
Florian Pose <fp@igh-essen.com>
parents: 2124
diff changeset
  3010
    /* no locking of master_sem needed, because neither sc nor voe will not be
912d70d6f0e5 Removed some locks causing latency when using the library; added ioctl()
Florian Pose <fp@igh-essen.com>
parents: 2124
diff changeset
  3011
     * deleted in the meantime. */
1264
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  3012
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  3013
    if (!(sc = ec_master_get_config(master, data.config_index))) {
1313
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1312
diff changeset
  3014
        return -ENOENT;
1264
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  3015
    }
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  3016
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  3017
    if (!(voe = ec_slave_config_find_voe_handler(sc, data.voe_index))) {
1313
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1312
diff changeset
  3018
        return -ENOENT;
1264
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  3019
    }
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  3020
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  3021
    data.state = ecrt_voe_handler_execute(voe);
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  3022
    if (data.state == EC_REQUEST_SUCCESS && voe->dir == EC_DIR_INPUT)
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  3023
        data.size = ecrt_voe_handler_data_size(voe);
1350
cd278db5a872 Minor fix in VoE handler.
Florian Pose <fp@igh-essen.com>
parents: 1349
diff changeset
  3024
    else
cd278db5a872 Minor fix in VoE handler.
Florian Pose <fp@igh-essen.com>
parents: 1349
diff changeset
  3025
        data.size = 0;
1264
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  3026
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  3027
    if (copy_to_user((void __user *) arg, &data, sizeof(data)))
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  3028
        return -EFAULT;
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  3029
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  3030
    return 0;
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  3031
}
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  3032
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  3033
/*****************************************************************************/
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  3034
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  3035
/** Reads the received VoE data.
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  3036
 */
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  3037
int ec_cdev_ioctl_voe_data(
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  3038
        ec_master_t *master, /**< EtherCAT master. */
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  3039
        unsigned long arg, /**< ioctl() argument. */
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  3040
        ec_cdev_priv_t *priv /**< Private data structure of file handle. */
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  3041
        )
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  3042
{
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  3043
    ec_ioctl_voe_t data;
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  3044
    ec_slave_config_t *sc;
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  3045
    ec_voe_handler_t *voe;
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  3046
1507
68e89abadd19 Removed unwanted tabulators.
Florian Pose <fp@igh-essen.com>
parents: 1500
diff changeset
  3047
    if (unlikely(!priv->requested))
1264
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  3048
        return -EPERM;
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  3049
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  3050
    if (copy_from_user(&data, (void __user *) arg, sizeof(data)))
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  3051
        return -EFAULT;
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  3052
2180
912d70d6f0e5 Removed some locks causing latency when using the library; added ioctl()
Florian Pose <fp@igh-essen.com>
parents: 2124
diff changeset
  3053
    /* no locking of master_sem needed, because neither sc nor voe will not be
912d70d6f0e5 Removed some locks causing latency when using the library; added ioctl()
Florian Pose <fp@igh-essen.com>
parents: 2124
diff changeset
  3054
     * deleted in the meantime. */
1264
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  3055
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  3056
    if (!(sc = ec_master_get_config(master, data.config_index))) {
1313
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1312
diff changeset
  3057
        return -ENOENT;
1264
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  3058
    }
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  3059
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  3060
    if (!(voe = ec_slave_config_find_voe_handler(sc, data.voe_index))) {
1313
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1312
diff changeset
  3061
        return -ENOENT;
1264
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  3062
    }
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  3063
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  3064
    if (copy_to_user((void __user *) data.data, ecrt_voe_handler_data(voe),
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  3065
                ecrt_voe_handler_data_size(voe)))
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  3066
        return -EFAULT;
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  3067
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  3068
    return 0;
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  3069
}
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  3070
1335
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents: 1328
diff changeset
  3071
/*****************************************************************************/
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents: 1328
diff changeset
  3072
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents: 1328
diff changeset
  3073
/** Read a file from a slave via FoE.
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents: 1328
diff changeset
  3074
 */
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents: 1328
diff changeset
  3075
int ec_cdev_ioctl_slave_foe_read(
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents: 1328
diff changeset
  3076
        ec_master_t *master, /**< EtherCAT master. */
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents: 1328
diff changeset
  3077
        unsigned long arg /**< ioctl() argument. */
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents: 1328
diff changeset
  3078
        )
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents: 1328
diff changeset
  3079
{
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents: 1328
diff changeset
  3080
    ec_ioctl_slave_foe_t data;
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents: 1328
diff changeset
  3081
    ec_master_foe_request_t request;
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents: 1328
diff changeset
  3082
    int retval;
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents: 1328
diff changeset
  3083
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents: 1328
diff changeset
  3084
    if (copy_from_user(&data, (void __user *) arg, sizeof(data))) {
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents: 1328
diff changeset
  3085
        return -EFAULT;
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents: 1328
diff changeset
  3086
    }
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents: 1328
diff changeset
  3087
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents: 1328
diff changeset
  3088
    ec_foe_request_init(&request.req, data.file_name);
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents: 1328
diff changeset
  3089
    ec_foe_request_read(&request.req);
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents: 1328
diff changeset
  3090
    ec_foe_request_alloc(&request.req, 10000); // FIXME
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents: 1328
diff changeset
  3091
2180
912d70d6f0e5 Removed some locks causing latency when using the library; added ioctl()
Florian Pose <fp@igh-essen.com>
parents: 2124
diff changeset
  3092
    if (down_interruptible(&master->master_sem)) {
912d70d6f0e5 Removed some locks causing latency when using the library; added ioctl()
Florian Pose <fp@igh-essen.com>
parents: 2124
diff changeset
  3093
        ec_foe_request_clear(&request.req);
1335
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents: 1328
diff changeset
  3094
        return -EINTR;
2180
912d70d6f0e5 Removed some locks causing latency when using the library; added ioctl()
Florian Pose <fp@igh-essen.com>
parents: 2124
diff changeset
  3095
    }
1335
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents: 1328
diff changeset
  3096
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents: 1328
diff changeset
  3097
    if (!(request.slave = ec_master_find_slave(
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents: 1328
diff changeset
  3098
                    master, 0, data.slave_position))) {
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents: 1328
diff changeset
  3099
        up(&master->master_sem);
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents: 1328
diff changeset
  3100
        ec_foe_request_clear(&request.req);
1921
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1909
diff changeset
  3101
        EC_MASTER_ERR(master, "Slave %u does not exist!\n",
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1909
diff changeset
  3102
                data.slave_position);
1335
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents: 1328
diff changeset
  3103
        return -EINVAL;
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents: 1328
diff changeset
  3104
    }
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents: 1328
diff changeset
  3105
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents: 1328
diff changeset
  3106
    // schedule request.
1597
491dea6f4fd7 Moved FOE request queue and fsm into slaves
Martin Troxler <martin.troxler@komaxgroup.com>
parents: 1596
diff changeset
  3107
    list_add_tail(&request.list, &request.slave->foe_requests);
1335
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents: 1328
diff changeset
  3108
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents: 1328
diff changeset
  3109
    up(&master->master_sem);
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents: 1328
diff changeset
  3110
1921
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1909
diff changeset
  3111
    EC_SLAVE_DBG(request.slave, 1, "Scheduled FoE read request.\n");
1336
e27b37e80a99 merge -c1618 branches/1.4-foe: Improved FoE.
Florian Pose <fp@igh-essen.com>
parents: 1335
diff changeset
  3112
1335
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents: 1328
diff changeset
  3113
    // wait for processing through FSM
1597
491dea6f4fd7 Moved FOE request queue and fsm into slaves
Martin Troxler <martin.troxler@komaxgroup.com>
parents: 1596
diff changeset
  3114
    if (wait_event_interruptible(request.slave->foe_queue,
1335
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents: 1328
diff changeset
  3115
                request.req.state != EC_INT_REQUEST_QUEUED)) {
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents: 1328
diff changeset
  3116
        // interrupted by signal
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents: 1328
diff changeset
  3117
        down(&master->master_sem);
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents: 1328
diff changeset
  3118
        if (request.req.state == EC_INT_REQUEST_QUEUED) {
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents: 1328
diff changeset
  3119
            list_del(&request.list);
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents: 1328
diff changeset
  3120
            up(&master->master_sem);
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents: 1328
diff changeset
  3121
            ec_foe_request_clear(&request.req);
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents: 1328
diff changeset
  3122
            return -EINTR;
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents: 1328
diff changeset
  3123
        }
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents: 1328
diff changeset
  3124
        // request already processing: interrupt not possible.
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents: 1328
diff changeset
  3125
        up(&master->master_sem);
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents: 1328
diff changeset
  3126
    }
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents: 1328
diff changeset
  3127
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents: 1328
diff changeset
  3128
    // wait until master FSM has finished processing
1831
1875b9fea0ba Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents: 1826
diff changeset
  3129
    wait_event(request.slave->foe_queue,
1875b9fea0ba Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents: 1826
diff changeset
  3130
            request.req.state != EC_INT_REQUEST_BUSY);
1335
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents: 1328
diff changeset
  3131
1336
e27b37e80a99 merge -c1618 branches/1.4-foe: Improved FoE.
Florian Pose <fp@igh-essen.com>
parents: 1335
diff changeset
  3132
    data.result = request.req.result;
e27b37e80a99 merge -c1618 branches/1.4-foe: Improved FoE.
Florian Pose <fp@igh-essen.com>
parents: 1335
diff changeset
  3133
    data.error_code = request.req.error_code;
1335
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents: 1328
diff changeset
  3134
1921
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1909
diff changeset
  3135
    EC_SLAVE_DBG(request.slave, 1, "Read %zd bytes via FoE"
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1909
diff changeset
  3136
            " (result = 0x%x).\n", request.req.data_size, request.req.result);
1335
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents: 1328
diff changeset
  3137
1349
9baba3568df4 Fixed FoE request states.
Florian Pose <fp@igh-essen.com>
parents: 1337
diff changeset
  3138
    if (request.req.state != EC_INT_REQUEST_SUCCESS) {
1335
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents: 1328
diff changeset
  3139
        data.data_size = 0;
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents: 1328
diff changeset
  3140
        retval = -EIO;
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents: 1328
diff changeset
  3141
    } else {
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents: 1328
diff changeset
  3142
        if (request.req.data_size > data.buffer_size) {
1921
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1909
diff changeset
  3143
            EC_MASTER_ERR(master, "Buffer too small.\n");
1335
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents: 1328
diff changeset
  3144
            ec_foe_request_clear(&request.req);
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents: 1328
diff changeset
  3145
            return -EOVERFLOW;
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents: 1328
diff changeset
  3146
        }
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents: 1328
diff changeset
  3147
        data.data_size = request.req.data_size;
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents: 1328
diff changeset
  3148
        if (copy_to_user((void __user *) data.buffer,
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents: 1328
diff changeset
  3149
                    request.req.buffer, data.data_size)) {
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents: 1328
diff changeset
  3150
            ec_foe_request_clear(&request.req);
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents: 1328
diff changeset
  3151
            return -EFAULT;
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents: 1328
diff changeset
  3152
        }
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents: 1328
diff changeset
  3153
        retval = 0;
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents: 1328
diff changeset
  3154
    }
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents: 1328
diff changeset
  3155
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents: 1328
diff changeset
  3156
    if (__copy_to_user((void __user *) arg, &data, sizeof(data))) {
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents: 1328
diff changeset
  3157
        retval = -EFAULT;
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents: 1328
diff changeset
  3158
    }
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents: 1328
diff changeset
  3159
1921
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1909
diff changeset
  3160
    EC_SLAVE_DBG(request.slave, 1, "Finished FoE read request.\n");
1336
e27b37e80a99 merge -c1618 branches/1.4-foe: Improved FoE.
Florian Pose <fp@igh-essen.com>
parents: 1335
diff changeset
  3161
1335
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents: 1328
diff changeset
  3162
    ec_foe_request_clear(&request.req);
1336
e27b37e80a99 merge -c1618 branches/1.4-foe: Improved FoE.
Florian Pose <fp@igh-essen.com>
parents: 1335
diff changeset
  3163
1335
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents: 1328
diff changeset
  3164
    return retval;
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents: 1328
diff changeset
  3165
}
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents: 1328
diff changeset
  3166
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents: 1328
diff changeset
  3167
/*****************************************************************************/
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents: 1328
diff changeset
  3168
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents: 1328
diff changeset
  3169
/** Write a file to a slave via FoE
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents: 1328
diff changeset
  3170
 */
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents: 1328
diff changeset
  3171
int ec_cdev_ioctl_slave_foe_write(
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents: 1328
diff changeset
  3172
        ec_master_t *master, /**< EtherCAT master. */
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents: 1328
diff changeset
  3173
        unsigned long arg /**< ioctl() argument. */
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents: 1328
diff changeset
  3174
        )
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents: 1328
diff changeset
  3175
{
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents: 1328
diff changeset
  3176
    ec_ioctl_slave_foe_t data;
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents: 1328
diff changeset
  3177
    ec_master_foe_request_t request;
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents: 1328
diff changeset
  3178
    int retval;
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents: 1328
diff changeset
  3179
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents: 1328
diff changeset
  3180
    if (copy_from_user(&data, (void __user *) arg, sizeof(data))) {
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents: 1328
diff changeset
  3181
        return -EFAULT;
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents: 1328
diff changeset
  3182
    }
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents: 1328
diff changeset
  3183
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents: 1328
diff changeset
  3184
    INIT_LIST_HEAD(&request.list);
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents: 1328
diff changeset
  3185
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents: 1328
diff changeset
  3186
    ec_foe_request_init(&request.req, data.file_name);
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents: 1328
diff changeset
  3187
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents: 1328
diff changeset
  3188
    if (ec_foe_request_alloc(&request.req, data.buffer_size)) {
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents: 1328
diff changeset
  3189
        ec_foe_request_clear(&request.req);
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents: 1328
diff changeset
  3190
        return -ENOMEM;
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents: 1328
diff changeset
  3191
    }
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents: 1328
diff changeset
  3192
    if (copy_from_user(request.req.buffer,
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents: 1328
diff changeset
  3193
                (void __user *) data.buffer, data.buffer_size)) {
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents: 1328
diff changeset
  3194
        ec_foe_request_clear(&request.req);
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents: 1328
diff changeset
  3195
        return -EFAULT;
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents: 1328
diff changeset
  3196
    }
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents: 1328
diff changeset
  3197
    request.req.data_size = data.buffer_size;
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents: 1328
diff changeset
  3198
    ec_foe_request_write(&request.req);
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents: 1328
diff changeset
  3199
2180
912d70d6f0e5 Removed some locks causing latency when using the library; added ioctl()
Florian Pose <fp@igh-essen.com>
parents: 2124
diff changeset
  3200
    if (down_interruptible(&master->master_sem)) {
912d70d6f0e5 Removed some locks causing latency when using the library; added ioctl()
Florian Pose <fp@igh-essen.com>
parents: 2124
diff changeset
  3201
        ec_foe_request_clear(&request.req);
1335
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents: 1328
diff changeset
  3202
        return -EINTR;
2180
912d70d6f0e5 Removed some locks causing latency when using the library; added ioctl()
Florian Pose <fp@igh-essen.com>
parents: 2124
diff changeset
  3203
    }
1335
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents: 1328
diff changeset
  3204
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents: 1328
diff changeset
  3205
    if (!(request.slave = ec_master_find_slave(
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents: 1328
diff changeset
  3206
                    master, 0, data.slave_position))) {
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents: 1328
diff changeset
  3207
        up(&master->master_sem);
1921
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1909
diff changeset
  3208
        EC_MASTER_ERR(master, "Slave %u does not exist!\n",
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1909
diff changeset
  3209
                data.slave_position);
1335
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents: 1328
diff changeset
  3210
        ec_foe_request_clear(&request.req);
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents: 1328
diff changeset
  3211
        return -EINVAL;
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents: 1328
diff changeset
  3212
    }
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents: 1328
diff changeset
  3213
1921
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1909
diff changeset
  3214
    EC_SLAVE_DBG(request.slave, 1, "Scheduling FoE write request.\n");
1335
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents: 1328
diff changeset
  3215
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents: 1328
diff changeset
  3216
    // schedule FoE write request.
1597
491dea6f4fd7 Moved FOE request queue and fsm into slaves
Martin Troxler <martin.troxler@komaxgroup.com>
parents: 1596
diff changeset
  3217
    list_add_tail(&request.list, &request.slave->foe_requests);
1335
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents: 1328
diff changeset
  3218
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents: 1328
diff changeset
  3219
    up(&master->master_sem);
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents: 1328
diff changeset
  3220
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents: 1328
diff changeset
  3221
    // wait for processing through FSM
1597
491dea6f4fd7 Moved FOE request queue and fsm into slaves
Martin Troxler <martin.troxler@komaxgroup.com>
parents: 1596
diff changeset
  3222
    if (wait_event_interruptible(request.slave->foe_queue,
1335
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents: 1328
diff changeset
  3223
                request.req.state != EC_INT_REQUEST_QUEUED)) {
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents: 1328
diff changeset
  3224
        // interrupted by signal
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents: 1328
diff changeset
  3225
        down(&master->master_sem);
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents: 1328
diff changeset
  3226
        if (request.req.state == EC_INT_REQUEST_QUEUED) {
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents: 1328
diff changeset
  3227
            // abort request
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents: 1328
diff changeset
  3228
            list_del(&request.list);
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents: 1328
diff changeset
  3229
            up(&master->master_sem);
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents: 1328
diff changeset
  3230
            ec_foe_request_clear(&request.req);
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents: 1328
diff changeset
  3231
            return -EINTR;
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents: 1328
diff changeset
  3232
        }
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents: 1328
diff changeset
  3233
        up(&master->master_sem);
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents: 1328
diff changeset
  3234
    }
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents: 1328
diff changeset
  3235
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents: 1328
diff changeset
  3236
    // wait until master FSM has finished processing
1831
1875b9fea0ba Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents: 1826
diff changeset
  3237
    wait_event(request.slave->foe_queue,
1875b9fea0ba Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents: 1826
diff changeset
  3238
            request.req.state != EC_INT_REQUEST_BUSY);
1335
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents: 1328
diff changeset
  3239
1336
e27b37e80a99 merge -c1618 branches/1.4-foe: Improved FoE.
Florian Pose <fp@igh-essen.com>
parents: 1335
diff changeset
  3240
    data.result = request.req.result;
e27b37e80a99 merge -c1618 branches/1.4-foe: Improved FoE.
Florian Pose <fp@igh-essen.com>
parents: 1335
diff changeset
  3241
    data.error_code = request.req.error_code;
1335
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents: 1328
diff changeset
  3242
1349
9baba3568df4 Fixed FoE request states.
Florian Pose <fp@igh-essen.com>
parents: 1337
diff changeset
  3243
    retval = request.req.state == EC_INT_REQUEST_SUCCESS ? 0 : -EIO;
1335
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents: 1328
diff changeset
  3244
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents: 1328
diff changeset
  3245
    if (__copy_to_user((void __user *) arg, &data, sizeof(data))) {
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents: 1328
diff changeset
  3246
        retval = -EFAULT;
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents: 1328
diff changeset
  3247
    }
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents: 1328
diff changeset
  3248
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents: 1328
diff changeset
  3249
    ec_foe_request_clear(&request.req);
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents: 1328
diff changeset
  3250
1921
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1909
diff changeset
  3251
    EC_SLAVE_DBG(request.slave, 1, "Finished FoE write request.\n");
1831
1875b9fea0ba Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents: 1826
diff changeset
  3252
1875b9fea0ba Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents: 1826
diff changeset
  3253
    return retval;
1875b9fea0ba Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents: 1826
diff changeset
  3254
}
1875b9fea0ba Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents: 1826
diff changeset
  3255
1875b9fea0ba Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents: 1826
diff changeset
  3256
/*****************************************************************************/
1875b9fea0ba Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents: 1826
diff changeset
  3257
1875b9fea0ba Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents: 1826
diff changeset
  3258
/** Read an SoE IDN.
1875b9fea0ba Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents: 1826
diff changeset
  3259
 */
1875b9fea0ba Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents: 1826
diff changeset
  3260
int ec_cdev_ioctl_slave_soe_read(
1875b9fea0ba Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents: 1826
diff changeset
  3261
        ec_master_t *master, /**< EtherCAT master. */
1875b9fea0ba Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents: 1826
diff changeset
  3262
        unsigned long arg /**< ioctl() argument. */
1875b9fea0ba Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents: 1826
diff changeset
  3263
        )
1875b9fea0ba Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents: 1826
diff changeset
  3264
{
1837
32136215c1fa Implemented SoE write state machine and soe_write command.
Florian Pose <fp@igh-essen.com>
parents: 1831
diff changeset
  3265
    ec_ioctl_slave_soe_read_t ioctl;
1947
024a3c6aa3f7 Implemented ecrt_master_read_idn() and ecrt_master_write_idn() in kernel space.
Florian Pose <fp@igh-essen.com>
parents: 1945
diff changeset
  3266
    u8 *data;
1831
1875b9fea0ba Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents: 1826
diff changeset
  3267
    int retval;
1875b9fea0ba Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents: 1826
diff changeset
  3268
1837
32136215c1fa Implemented SoE write state machine and soe_write command.
Florian Pose <fp@igh-essen.com>
parents: 1831
diff changeset
  3269
    if (copy_from_user(&ioctl, (void __user *) arg, sizeof(ioctl))) {
1831
1875b9fea0ba Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents: 1826
diff changeset
  3270
        return -EFAULT;
1875b9fea0ba Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents: 1826
diff changeset
  3271
    }
1875b9fea0ba Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents: 1826
diff changeset
  3272
1947
024a3c6aa3f7 Implemented ecrt_master_read_idn() and ecrt_master_write_idn() in kernel space.
Florian Pose <fp@igh-essen.com>
parents: 1945
diff changeset
  3273
    data = kmalloc(ioctl.mem_size, GFP_KERNEL);
024a3c6aa3f7 Implemented ecrt_master_read_idn() and ecrt_master_write_idn() in kernel space.
Florian Pose <fp@igh-essen.com>
parents: 1945
diff changeset
  3274
    if (!data) {
024a3c6aa3f7 Implemented ecrt_master_read_idn() and ecrt_master_write_idn() in kernel space.
Florian Pose <fp@igh-essen.com>
parents: 1945
diff changeset
  3275
        EC_MASTER_ERR(master, "Failed to allocate %u bytes of IDN data.\n",
024a3c6aa3f7 Implemented ecrt_master_read_idn() and ecrt_master_write_idn() in kernel space.
Florian Pose <fp@igh-essen.com>
parents: 1945
diff changeset
  3276
                ioctl.mem_size);
024a3c6aa3f7 Implemented ecrt_master_read_idn() and ecrt_master_write_idn() in kernel space.
Florian Pose <fp@igh-essen.com>
parents: 1945
diff changeset
  3277
        return -ENOMEM;
024a3c6aa3f7 Implemented ecrt_master_read_idn() and ecrt_master_write_idn() in kernel space.
Florian Pose <fp@igh-essen.com>
parents: 1945
diff changeset
  3278
    }
024a3c6aa3f7 Implemented ecrt_master_read_idn() and ecrt_master_write_idn() in kernel space.
Florian Pose <fp@igh-essen.com>
parents: 1945
diff changeset
  3279
024a3c6aa3f7 Implemented ecrt_master_read_idn() and ecrt_master_write_idn() in kernel space.
Florian Pose <fp@igh-essen.com>
parents: 1945
diff changeset
  3280
    retval = ecrt_master_read_idn(master, ioctl.slave_position,
1952
7d9fb723fc4b Added drive_no parameter to SoE layer.
Florian Pose <fp@igh-essen.com>
parents: 1948
diff changeset
  3281
            ioctl.drive_no, ioctl.idn, data, ioctl.mem_size, &ioctl.data_size,
1947
024a3c6aa3f7 Implemented ecrt_master_read_idn() and ecrt_master_write_idn() in kernel space.
Florian Pose <fp@igh-essen.com>
parents: 1945
diff changeset
  3282
            &ioctl.error_code);
024a3c6aa3f7 Implemented ecrt_master_read_idn() and ecrt_master_write_idn() in kernel space.
Florian Pose <fp@igh-essen.com>
parents: 1945
diff changeset
  3283
    if (retval) {
024a3c6aa3f7 Implemented ecrt_master_read_idn() and ecrt_master_write_idn() in kernel space.
Florian Pose <fp@igh-essen.com>
parents: 1945
diff changeset
  3284
        kfree(data);
024a3c6aa3f7 Implemented ecrt_master_read_idn() and ecrt_master_write_idn() in kernel space.
Florian Pose <fp@igh-essen.com>
parents: 1945
diff changeset
  3285
        return retval;
024a3c6aa3f7 Implemented ecrt_master_read_idn() and ecrt_master_write_idn() in kernel space.
Florian Pose <fp@igh-essen.com>
parents: 1945
diff changeset
  3286
    }
024a3c6aa3f7 Implemented ecrt_master_read_idn() and ecrt_master_write_idn() in kernel space.
Florian Pose <fp@igh-essen.com>
parents: 1945
diff changeset
  3287
024a3c6aa3f7 Implemented ecrt_master_read_idn() and ecrt_master_write_idn() in kernel space.
Florian Pose <fp@igh-essen.com>
parents: 1945
diff changeset
  3288
    if (copy_to_user((void __user *) ioctl.data,
024a3c6aa3f7 Implemented ecrt_master_read_idn() and ecrt_master_write_idn() in kernel space.
Florian Pose <fp@igh-essen.com>
parents: 1945
diff changeset
  3289
                data, ioctl.data_size)) {
024a3c6aa3f7 Implemented ecrt_master_read_idn() and ecrt_master_write_idn() in kernel space.
Florian Pose <fp@igh-essen.com>
parents: 1945
diff changeset
  3290
        kfree(data);
024a3c6aa3f7 Implemented ecrt_master_read_idn() and ecrt_master_write_idn() in kernel space.
Florian Pose <fp@igh-essen.com>
parents: 1945
diff changeset
  3291
        return -EFAULT;
024a3c6aa3f7 Implemented ecrt_master_read_idn() and ecrt_master_write_idn() in kernel space.
Florian Pose <fp@igh-essen.com>
parents: 1945
diff changeset
  3292
    }
024a3c6aa3f7 Implemented ecrt_master_read_idn() and ecrt_master_write_idn() in kernel space.
Florian Pose <fp@igh-essen.com>
parents: 1945
diff changeset
  3293
    kfree(data);
1831
1875b9fea0ba Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents: 1826
diff changeset
  3294
1837
32136215c1fa Implemented SoE write state machine and soe_write command.
Florian Pose <fp@igh-essen.com>
parents: 1831
diff changeset
  3295
    if (__copy_to_user((void __user *) arg, &ioctl, sizeof(ioctl))) {
1831
1875b9fea0ba Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents: 1826
diff changeset
  3296
        retval = -EFAULT;
1875b9fea0ba Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents: 1826
diff changeset
  3297
    }
1875b9fea0ba Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents: 1826
diff changeset
  3298
1947
024a3c6aa3f7 Implemented ecrt_master_read_idn() and ecrt_master_write_idn() in kernel space.
Florian Pose <fp@igh-essen.com>
parents: 1945
diff changeset
  3299
    EC_MASTER_DBG(master, 1, "Finished SoE read request.\n");
1831
1875b9fea0ba Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents: 1826
diff changeset
  3300
    return retval;
1875b9fea0ba Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents: 1826
diff changeset
  3301
}
1875b9fea0ba Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents: 1826
diff changeset
  3302
1875b9fea0ba Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents: 1826
diff changeset
  3303
/*****************************************************************************/
1875b9fea0ba Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents: 1826
diff changeset
  3304
1875b9fea0ba Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents: 1826
diff changeset
  3305
/** Write an IDN to a slave via SoE.
1875b9fea0ba Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents: 1826
diff changeset
  3306
 */
1875b9fea0ba Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents: 1826
diff changeset
  3307
int ec_cdev_ioctl_slave_soe_write(
1875b9fea0ba Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents: 1826
diff changeset
  3308
        ec_master_t *master, /**< EtherCAT master. */
1875b9fea0ba Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents: 1826
diff changeset
  3309
        unsigned long arg /**< ioctl() argument. */
1875b9fea0ba Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents: 1826
diff changeset
  3310
        )
1875b9fea0ba Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents: 1826
diff changeset
  3311
{
1837
32136215c1fa Implemented SoE write state machine and soe_write command.
Florian Pose <fp@igh-essen.com>
parents: 1831
diff changeset
  3312
    ec_ioctl_slave_soe_write_t ioctl;
1947
024a3c6aa3f7 Implemented ecrt_master_read_idn() and ecrt_master_write_idn() in kernel space.
Florian Pose <fp@igh-essen.com>
parents: 1945
diff changeset
  3313
    u8 *data;
1831
1875b9fea0ba Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents: 1826
diff changeset
  3314
    int retval;
1875b9fea0ba Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents: 1826
diff changeset
  3315
1837
32136215c1fa Implemented SoE write state machine and soe_write command.
Florian Pose <fp@igh-essen.com>
parents: 1831
diff changeset
  3316
    if (copy_from_user(&ioctl, (void __user *) arg, sizeof(ioctl))) {
1831
1875b9fea0ba Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents: 1826
diff changeset
  3317
        return -EFAULT;
1875b9fea0ba Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents: 1826
diff changeset
  3318
    }
1875b9fea0ba Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents: 1826
diff changeset
  3319
1947
024a3c6aa3f7 Implemented ecrt_master_read_idn() and ecrt_master_write_idn() in kernel space.
Florian Pose <fp@igh-essen.com>
parents: 1945
diff changeset
  3320
    data = kmalloc(ioctl.data_size, GFP_KERNEL);
024a3c6aa3f7 Implemented ecrt_master_read_idn() and ecrt_master_write_idn() in kernel space.
Florian Pose <fp@igh-essen.com>
parents: 1945
diff changeset
  3321
    if (!data) {
1972
c1b564299829 Minor 64bit improvements.
Florian Pose <fp@igh-essen.com>
parents: 1966
diff changeset
  3322
        EC_MASTER_ERR(master, "Failed to allocate %zu bytes of IDN data.\n",
1947
024a3c6aa3f7 Implemented ecrt_master_read_idn() and ecrt_master_write_idn() in kernel space.
Florian Pose <fp@igh-essen.com>
parents: 1945
diff changeset
  3323
                ioctl.data_size);
1831
1875b9fea0ba Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents: 1826
diff changeset
  3324
        return -ENOMEM;
1875b9fea0ba Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents: 1826
diff changeset
  3325
    }
1947
024a3c6aa3f7 Implemented ecrt_master_read_idn() and ecrt_master_write_idn() in kernel space.
Florian Pose <fp@igh-essen.com>
parents: 1945
diff changeset
  3326
    if (copy_from_user(data, (void __user *) ioctl.data, ioctl.data_size)) {
024a3c6aa3f7 Implemented ecrt_master_read_idn() and ecrt_master_write_idn() in kernel space.
Florian Pose <fp@igh-essen.com>
parents: 1945
diff changeset
  3327
        kfree(data);
024a3c6aa3f7 Implemented ecrt_master_read_idn() and ecrt_master_write_idn() in kernel space.
Florian Pose <fp@igh-essen.com>
parents: 1945
diff changeset
  3328
        return -EFAULT;
024a3c6aa3f7 Implemented ecrt_master_read_idn() and ecrt_master_write_idn() in kernel space.
Florian Pose <fp@igh-essen.com>
parents: 1945
diff changeset
  3329
    }
024a3c6aa3f7 Implemented ecrt_master_read_idn() and ecrt_master_write_idn() in kernel space.
Florian Pose <fp@igh-essen.com>
parents: 1945
diff changeset
  3330
024a3c6aa3f7 Implemented ecrt_master_read_idn() and ecrt_master_write_idn() in kernel space.
Florian Pose <fp@igh-essen.com>
parents: 1945
diff changeset
  3331
    retval = ecrt_master_write_idn(master, ioctl.slave_position,
1952
7d9fb723fc4b Added drive_no parameter to SoE layer.
Florian Pose <fp@igh-essen.com>
parents: 1948
diff changeset
  3332
            ioctl.drive_no, ioctl.idn, data, ioctl.data_size,
7d9fb723fc4b Added drive_no parameter to SoE layer.
Florian Pose <fp@igh-essen.com>
parents: 1948
diff changeset
  3333
            &ioctl.error_code);
1947
024a3c6aa3f7 Implemented ecrt_master_read_idn() and ecrt_master_write_idn() in kernel space.
Florian Pose <fp@igh-essen.com>
parents: 1945
diff changeset
  3334
    kfree(data);
024a3c6aa3f7 Implemented ecrt_master_read_idn() and ecrt_master_write_idn() in kernel space.
Florian Pose <fp@igh-essen.com>
parents: 1945
diff changeset
  3335
    if (retval) {
024a3c6aa3f7 Implemented ecrt_master_read_idn() and ecrt_master_write_idn() in kernel space.
Florian Pose <fp@igh-essen.com>
parents: 1945
diff changeset
  3336
        return retval;
024a3c6aa3f7 Implemented ecrt_master_read_idn() and ecrt_master_write_idn() in kernel space.
Florian Pose <fp@igh-essen.com>
parents: 1945
diff changeset
  3337
    }
1831
1875b9fea0ba Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents: 1826
diff changeset
  3338
1837
32136215c1fa Implemented SoE write state machine and soe_write command.
Florian Pose <fp@igh-essen.com>
parents: 1831
diff changeset
  3339
    if (__copy_to_user((void __user *) arg, &ioctl, sizeof(ioctl))) {
1831
1875b9fea0ba Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents: 1826
diff changeset
  3340
        retval = -EFAULT;
1875b9fea0ba Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents: 1826
diff changeset
  3341
    }
1875b9fea0ba Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents: 1826
diff changeset
  3342
1947
024a3c6aa3f7 Implemented ecrt_master_read_idn() and ecrt_master_write_idn() in kernel space.
Florian Pose <fp@igh-essen.com>
parents: 1945
diff changeset
  3343
    EC_MASTER_DBG(master, 1, "Finished SoE write request.\n");
1335
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents: 1328
diff changeset
  3344
    return retval;
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents: 1328
diff changeset
  3345
}
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents: 1328
diff changeset
  3346
922
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3347
/******************************************************************************
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3348
 * File operations
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3349
 *****************************************************************************/
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3350
1092
69393cf60399 Improved source code doc.
Florian Pose <fp@igh-essen.com>
parents: 1082
diff changeset
  3351
/** Called when the cdev is opened.
69393cf60399 Improved source code doc.
Florian Pose <fp@igh-essen.com>
parents: 1082
diff changeset
  3352
 */
922
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3353
int eccdev_open(struct inode *inode, struct file *filp)
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3354
{
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3355
    ec_cdev_t *cdev = container_of(inode->i_cdev, ec_cdev_t, cdev);
1242
632a6b91f8e4 First version of userspace library with requesting/releasing.
Florian Pose <fp@igh-essen.com>
parents: 1223
diff changeset
  3356
    ec_cdev_priv_t *priv;
632a6b91f8e4 First version of userspace library with requesting/releasing.
Florian Pose <fp@igh-essen.com>
parents: 1223
diff changeset
  3357
632a6b91f8e4 First version of userspace library with requesting/releasing.
Florian Pose <fp@igh-essen.com>
parents: 1223
diff changeset
  3358
    priv = kmalloc(sizeof(ec_cdev_priv_t), GFP_KERNEL);
632a6b91f8e4 First version of userspace library with requesting/releasing.
Florian Pose <fp@igh-essen.com>
parents: 1223
diff changeset
  3359
    if (!priv) {
1922
Florian Pose <fp@igh-essen.com>
parents: 1921
diff changeset
  3360
        EC_MASTER_ERR(cdev->master,
Florian Pose <fp@igh-essen.com>
parents: 1921
diff changeset
  3361
                "Failed to allocate memory for private data structure.\n");
1242
632a6b91f8e4 First version of userspace library with requesting/releasing.
Florian Pose <fp@igh-essen.com>
parents: 1223
diff changeset
  3362
        return -ENOMEM;
632a6b91f8e4 First version of userspace library with requesting/releasing.
Florian Pose <fp@igh-essen.com>
parents: 1223
diff changeset
  3363
    }
632a6b91f8e4 First version of userspace library with requesting/releasing.
Florian Pose <fp@igh-essen.com>
parents: 1223
diff changeset
  3364
632a6b91f8e4 First version of userspace library with requesting/releasing.
Florian Pose <fp@igh-essen.com>
parents: 1223
diff changeset
  3365
    priv->cdev = cdev;
632a6b91f8e4 First version of userspace library with requesting/releasing.
Florian Pose <fp@igh-essen.com>
parents: 1223
diff changeset
  3366
    priv->requested = 0;
1258
900f1124e8f8 Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents: 1255
diff changeset
  3367
    priv->process_data = NULL;
900f1124e8f8 Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents: 1255
diff changeset
  3368
    priv->process_data_size = 0;
1242
632a6b91f8e4 First version of userspace library with requesting/releasing.
Florian Pose <fp@igh-essen.com>
parents: 1223
diff changeset
  3369
632a6b91f8e4 First version of userspace library with requesting/releasing.
Florian Pose <fp@igh-essen.com>
parents: 1223
diff changeset
  3370
    filp->private_data = priv;
1397
6f9294a445c1 Introduced DEBUG_IOCTL.
Florian Pose <fp@igh-essen.com>
parents: 1388
diff changeset
  3371
6f9294a445c1 Introduced DEBUG_IOCTL.
Florian Pose <fp@igh-essen.com>
parents: 1388
diff changeset
  3372
#if DEBUG_IOCTL
1931
831f2d34664c Fixed format specifiers.
Florian Pose <fp@igh-essen.com>
parents: 1922
diff changeset
  3373
    EC_MASTER_DBG(cdev->master, 0, "File opened.\n");
1397
6f9294a445c1 Introduced DEBUG_IOCTL.
Florian Pose <fp@igh-essen.com>
parents: 1388
diff changeset
  3374
#endif
922
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3375
    return 0;
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3376
}
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3377
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3378
/*****************************************************************************/
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3379
1092
69393cf60399 Improved source code doc.
Florian Pose <fp@igh-essen.com>
parents: 1082
diff changeset
  3380
/** Called when the cdev is closed.
69393cf60399 Improved source code doc.
Florian Pose <fp@igh-essen.com>
parents: 1082
diff changeset
  3381
 */
922
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3382
int eccdev_release(struct inode *inode, struct file *filp)
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3383
{
1242
632a6b91f8e4 First version of userspace library with requesting/releasing.
Florian Pose <fp@igh-essen.com>
parents: 1223
diff changeset
  3384
    ec_cdev_priv_t *priv = (ec_cdev_priv_t *) filp->private_data;
632a6b91f8e4 First version of userspace library with requesting/releasing.
Florian Pose <fp@igh-essen.com>
parents: 1223
diff changeset
  3385
    ec_master_t *master = priv->cdev->master;
632a6b91f8e4 First version of userspace library with requesting/releasing.
Florian Pose <fp@igh-essen.com>
parents: 1223
diff changeset
  3386
632a6b91f8e4 First version of userspace library with requesting/releasing.
Florian Pose <fp@igh-essen.com>
parents: 1223
diff changeset
  3387
    if (priv->requested)
632a6b91f8e4 First version of userspace library with requesting/releasing.
Florian Pose <fp@igh-essen.com>
parents: 1223
diff changeset
  3388
        ecrt_release_master(master);
935
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
  3389
1258
900f1124e8f8 Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents: 1255
diff changeset
  3390
    if (priv->process_data)
900f1124e8f8 Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents: 1255
diff changeset
  3391
        vfree(priv->process_data);
900f1124e8f8 Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents: 1255
diff changeset
  3392
1397
6f9294a445c1 Introduced DEBUG_IOCTL.
Florian Pose <fp@igh-essen.com>
parents: 1388
diff changeset
  3393
#if DEBUG_IOCTL
1931
831f2d34664c Fixed format specifiers.
Florian Pose <fp@igh-essen.com>
parents: 1922
diff changeset
  3394
    EC_MASTER_DBG(master, 0, "File closed.\n");
1397
6f9294a445c1 Introduced DEBUG_IOCTL.
Florian Pose <fp@igh-essen.com>
parents: 1388
diff changeset
  3395
#endif
6f9294a445c1 Introduced DEBUG_IOCTL.
Florian Pose <fp@igh-essen.com>
parents: 1388
diff changeset
  3396
1242
632a6b91f8e4 First version of userspace library with requesting/releasing.
Florian Pose <fp@igh-essen.com>
parents: 1223
diff changeset
  3397
    kfree(priv);
922
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3398
    return 0;
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3399
}
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3400
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3401
/*****************************************************************************/
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3402
1092
69393cf60399 Improved source code doc.
Florian Pose <fp@igh-essen.com>
parents: 1082
diff changeset
  3403
/** Called when an ioctl() command is issued.
69393cf60399 Improved source code doc.
Florian Pose <fp@igh-essen.com>
parents: 1082
diff changeset
  3404
 */
935
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
  3405
long eccdev_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
  3406
{
2180
912d70d6f0e5 Removed some locks causing latency when using the library; added ioctl()
Florian Pose <fp@igh-essen.com>
parents: 2124
diff changeset
  3407
#if DEBUG_LATENCY
912d70d6f0e5 Removed some locks causing latency when using the library; added ioctl()
Florian Pose <fp@igh-essen.com>
parents: 2124
diff changeset
  3408
    cycles_t a = get_cycles(), b;
912d70d6f0e5 Removed some locks causing latency when using the library; added ioctl()
Florian Pose <fp@igh-essen.com>
parents: 2124
diff changeset
  3409
    unsigned int t;
912d70d6f0e5 Removed some locks causing latency when using the library; added ioctl()
Florian Pose <fp@igh-essen.com>
parents: 2124
diff changeset
  3410
#endif
1242
632a6b91f8e4 First version of userspace library with requesting/releasing.
Florian Pose <fp@igh-essen.com>
parents: 1223
diff changeset
  3411
    ec_cdev_priv_t *priv = (ec_cdev_priv_t *) filp->private_data;
632a6b91f8e4 First version of userspace library with requesting/releasing.
Florian Pose <fp@igh-essen.com>
parents: 1223
diff changeset
  3412
    ec_master_t *master = priv->cdev->master;
2180
912d70d6f0e5 Removed some locks causing latency when using the library; added ioctl()
Florian Pose <fp@igh-essen.com>
parents: 2124
diff changeset
  3413
    int ret;
922
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3414
1397
6f9294a445c1 Introduced DEBUG_IOCTL.
Florian Pose <fp@igh-essen.com>
parents: 1388
diff changeset
  3415
#if DEBUG_IOCTL
1931
831f2d34664c Fixed format specifiers.
Florian Pose <fp@igh-essen.com>
parents: 1922
diff changeset
  3416
    EC_MASTER_DBG(master, 0, "ioctl(filp = 0x%p, cmd = 0x%08x (0x%02x),"
831f2d34664c Fixed format specifiers.
Florian Pose <fp@igh-essen.com>
parents: 1922
diff changeset
  3417
            " arg = 0x%lx)\n", filp, cmd, _IOC_NR(cmd), arg);
1397
6f9294a445c1 Introduced DEBUG_IOCTL.
Florian Pose <fp@igh-essen.com>
parents: 1388
diff changeset
  3418
#endif
935
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
  3419
922
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3420
    switch (cmd) {
1826
ec6223c3b7ec Multi-master support for command-line tool. The --master option supports
Florian Pose <fp@igh-essen.com>
parents: 1804
diff changeset
  3421
        case EC_IOCTL_MODULE:
2180
912d70d6f0e5 Removed some locks causing latency when using the library; added ioctl()
Florian Pose <fp@igh-essen.com>
parents: 2124
diff changeset
  3422
            ret = ec_cdev_ioctl_module(arg);
912d70d6f0e5 Removed some locks causing latency when using the library; added ioctl()
Florian Pose <fp@igh-essen.com>
parents: 2124
diff changeset
  3423
            break;
957
ed5ac2e83495 Replaced EC_IOCTL_SLAVE_COUNT with EC_IOCTL_MASTER; implemented
Florian Pose <fp@igh-essen.com>
parents: 956
diff changeset
  3424
        case EC_IOCTL_MASTER:
2180
912d70d6f0e5 Removed some locks causing latency when using the library; added ioctl()
Florian Pose <fp@igh-essen.com>
parents: 2124
diff changeset
  3425
            ret = ec_cdev_ioctl_master(master, arg);
912d70d6f0e5 Removed some locks causing latency when using the library; added ioctl()
Florian Pose <fp@igh-essen.com>
parents: 2124
diff changeset
  3426
            break;
935
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
  3427
        case EC_IOCTL_SLAVE:
2180
912d70d6f0e5 Removed some locks causing latency when using the library; added ioctl()
Florian Pose <fp@igh-essen.com>
parents: 2124
diff changeset
  3428
            ret = ec_cdev_ioctl_slave(master, arg);
912d70d6f0e5 Removed some locks causing latency when using the library; added ioctl()
Florian Pose <fp@igh-essen.com>
parents: 2124
diff changeset
  3429
            break;
1079
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  3430
        case EC_IOCTL_SLAVE_SYNC:
2180
912d70d6f0e5 Removed some locks causing latency when using the library; added ioctl()
Florian Pose <fp@igh-essen.com>
parents: 2124
diff changeset
  3431
            ret = ec_cdev_ioctl_slave_sync(master, arg);
912d70d6f0e5 Removed some locks causing latency when using the library; added ioctl()
Florian Pose <fp@igh-essen.com>
parents: 2124
diff changeset
  3432
            break;
1079
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  3433
        case EC_IOCTL_SLAVE_SYNC_PDO:
2180
912d70d6f0e5 Removed some locks causing latency when using the library; added ioctl()
Florian Pose <fp@igh-essen.com>
parents: 2124
diff changeset
  3434
            ret = ec_cdev_ioctl_slave_sync_pdo(master, arg);
912d70d6f0e5 Removed some locks causing latency when using the library; added ioctl()
Florian Pose <fp@igh-essen.com>
parents: 2124
diff changeset
  3435
            break;
1079
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  3436
        case EC_IOCTL_SLAVE_SYNC_PDO_ENTRY:
2180
912d70d6f0e5 Removed some locks causing latency when using the library; added ioctl()
Florian Pose <fp@igh-essen.com>
parents: 2124
diff changeset
  3437
            ret = ec_cdev_ioctl_slave_sync_pdo_entry(master, arg);
912d70d6f0e5 Removed some locks causing latency when using the library; added ioctl()
Florian Pose <fp@igh-essen.com>
parents: 2124
diff changeset
  3438
            break;
948
1cfab7161491 Implemented domain command.
Florian Pose <fp@igh-essen.com>
parents: 938
diff changeset
  3439
        case EC_IOCTL_DOMAIN:
2180
912d70d6f0e5 Removed some locks causing latency when using the library; added ioctl()
Florian Pose <fp@igh-essen.com>
parents: 2124
diff changeset
  3440
            ret = ec_cdev_ioctl_domain(master, arg);
912d70d6f0e5 Removed some locks causing latency when using the library; added ioctl()
Florian Pose <fp@igh-essen.com>
parents: 2124
diff changeset
  3441
            break;
950
8b00e63fff90 'ethercat domain' shows domain contents and process data.
Florian Pose <fp@igh-essen.com>
parents: 949
diff changeset
  3442
        case EC_IOCTL_DOMAIN_FMMU:
2180
912d70d6f0e5 Removed some locks causing latency when using the library; added ioctl()
Florian Pose <fp@igh-essen.com>
parents: 2124
diff changeset
  3443
            ret = ec_cdev_ioctl_domain_fmmu(master, arg);
912d70d6f0e5 Removed some locks causing latency when using the library; added ioctl()
Florian Pose <fp@igh-essen.com>
parents: 2124
diff changeset
  3444
            break;
1079
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  3445
        case EC_IOCTL_DOMAIN_DATA:
2180
912d70d6f0e5 Removed some locks causing latency when using the library; added ioctl()
Florian Pose <fp@igh-essen.com>
parents: 2124
diff changeset
  3446
            ret = ec_cdev_ioctl_domain_data(master, arg);
912d70d6f0e5 Removed some locks causing latency when using the library; added ioctl()
Florian Pose <fp@igh-essen.com>
parents: 2124
diff changeset
  3447
            break;
1079
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  3448
        case EC_IOCTL_MASTER_DEBUG:
2180
912d70d6f0e5 Removed some locks causing latency when using the library; added ioctl()
Florian Pose <fp@igh-essen.com>
parents: 2124
diff changeset
  3449
            if (!(filp->f_mode & FMODE_WRITE)) {
912d70d6f0e5 Removed some locks causing latency when using the library; added ioctl()
Florian Pose <fp@igh-essen.com>
parents: 2124
diff changeset
  3450
                ret = -EPERM;
912d70d6f0e5 Removed some locks causing latency when using the library; added ioctl()
Florian Pose <fp@igh-essen.com>
parents: 2124
diff changeset
  3451
                break;
912d70d6f0e5 Removed some locks causing latency when using the library; added ioctl()
Florian Pose <fp@igh-essen.com>
parents: 2124
diff changeset
  3452
            }
912d70d6f0e5 Removed some locks causing latency when using the library; added ioctl()
Florian Pose <fp@igh-essen.com>
parents: 2124
diff changeset
  3453
            ret = ec_cdev_ioctl_master_debug(master, arg);
912d70d6f0e5 Removed some locks causing latency when using the library; added ioctl()
Florian Pose <fp@igh-essen.com>
parents: 2124
diff changeset
  3454
            break;
1961
48f536aefc18 Rescan command.
Florian Pose <fp@igh-essen.com>
parents: 1945
diff changeset
  3455
        case EC_IOCTL_MASTER_RESCAN:
2180
912d70d6f0e5 Removed some locks causing latency when using the library; added ioctl()
Florian Pose <fp@igh-essen.com>
parents: 2124
diff changeset
  3456
            if (!(filp->f_mode & FMODE_WRITE)) {
912d70d6f0e5 Removed some locks causing latency when using the library; added ioctl()
Florian Pose <fp@igh-essen.com>
parents: 2124
diff changeset
  3457
                ret = -EPERM;
912d70d6f0e5 Removed some locks causing latency when using the library; added ioctl()
Florian Pose <fp@igh-essen.com>
parents: 2124
diff changeset
  3458
                break;
912d70d6f0e5 Removed some locks causing latency when using the library; added ioctl()
Florian Pose <fp@igh-essen.com>
parents: 2124
diff changeset
  3459
            }
912d70d6f0e5 Removed some locks causing latency when using the library; added ioctl()
Florian Pose <fp@igh-essen.com>
parents: 2124
diff changeset
  3460
            ret = ec_cdev_ioctl_master_rescan(master, arg);
912d70d6f0e5 Removed some locks causing latency when using the library; added ioctl()
Florian Pose <fp@igh-essen.com>
parents: 2124
diff changeset
  3461
            break;
960
36e460ffbb5e Request slave state(s) with 'ethercat state'; removed sysfs state file.
Florian Pose <fp@igh-essen.com>
parents: 957
diff changeset
  3462
        case EC_IOCTL_SLAVE_STATE:
2180
912d70d6f0e5 Removed some locks causing latency when using the library; added ioctl()
Florian Pose <fp@igh-essen.com>
parents: 2124
diff changeset
  3463
            if (!(filp->f_mode & FMODE_WRITE)) {
912d70d6f0e5 Removed some locks causing latency when using the library; added ioctl()
Florian Pose <fp@igh-essen.com>
parents: 2124
diff changeset
  3464
                ret = -EPERM;
912d70d6f0e5 Removed some locks causing latency when using the library; added ioctl()
Florian Pose <fp@igh-essen.com>
parents: 2124
diff changeset
  3465
                break;
912d70d6f0e5 Removed some locks causing latency when using the library; added ioctl()
Florian Pose <fp@igh-essen.com>
parents: 2124
diff changeset
  3466
            }
912d70d6f0e5 Removed some locks causing latency when using the library; added ioctl()
Florian Pose <fp@igh-essen.com>
parents: 2124
diff changeset
  3467
            ret = ec_cdev_ioctl_slave_state(master, arg);
912d70d6f0e5 Removed some locks causing latency when using the library; added ioctl()
Florian Pose <fp@igh-essen.com>
parents: 2124
diff changeset
  3468
            break;
1079
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  3469
        case EC_IOCTL_SLAVE_SDO:
2180
912d70d6f0e5 Removed some locks causing latency when using the library; added ioctl()
Florian Pose <fp@igh-essen.com>
parents: 2124
diff changeset
  3470
            ret = ec_cdev_ioctl_slave_sdo(master, arg);
912d70d6f0e5 Removed some locks causing latency when using the library; added ioctl()
Florian Pose <fp@igh-essen.com>
parents: 2124
diff changeset
  3471
            break;
1079
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  3472
        case EC_IOCTL_SLAVE_SDO_ENTRY:
2180
912d70d6f0e5 Removed some locks causing latency when using the library; added ioctl()
Florian Pose <fp@igh-essen.com>
parents: 2124
diff changeset
  3473
            ret = ec_cdev_ioctl_slave_sdo_entry(master, arg);
912d70d6f0e5 Removed some locks causing latency when using the library; added ioctl()
Florian Pose <fp@igh-essen.com>
parents: 2124
diff changeset
  3474
            break;
1079
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  3475
        case EC_IOCTL_SLAVE_SDO_UPLOAD:
2180
912d70d6f0e5 Removed some locks causing latency when using the library; added ioctl()
Florian Pose <fp@igh-essen.com>
parents: 2124
diff changeset
  3476
            ret = ec_cdev_ioctl_slave_sdo_upload(master, arg);
912d70d6f0e5 Removed some locks causing latency when using the library; added ioctl()
Florian Pose <fp@igh-essen.com>
parents: 2124
diff changeset
  3477
            break;
1079
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  3478
        case EC_IOCTL_SLAVE_SDO_DOWNLOAD:
2180
912d70d6f0e5 Removed some locks causing latency when using the library; added ioctl()
Florian Pose <fp@igh-essen.com>
parents: 2124
diff changeset
  3479
            if (!(filp->f_mode & FMODE_WRITE)) {
912d70d6f0e5 Removed some locks causing latency when using the library; added ioctl()
Florian Pose <fp@igh-essen.com>
parents: 2124
diff changeset
  3480
                ret = -EPERM;
912d70d6f0e5 Removed some locks causing latency when using the library; added ioctl()
Florian Pose <fp@igh-essen.com>
parents: 2124
diff changeset
  3481
                break;
912d70d6f0e5 Removed some locks causing latency when using the library; added ioctl()
Florian Pose <fp@igh-essen.com>
parents: 2124
diff changeset
  3482
            }
912d70d6f0e5 Removed some locks causing latency when using the library; added ioctl()
Florian Pose <fp@igh-essen.com>
parents: 2124
diff changeset
  3483
            ret = ec_cdev_ioctl_slave_sdo_download(master, arg);
912d70d6f0e5 Removed some locks causing latency when using the library; added ioctl()
Florian Pose <fp@igh-essen.com>
parents: 2124
diff changeset
  3484
            break;
1079
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  3485
        case EC_IOCTL_SLAVE_SII_READ:
2180
912d70d6f0e5 Removed some locks causing latency when using the library; added ioctl()
Florian Pose <fp@igh-essen.com>
parents: 2124
diff changeset
  3486
            ret = ec_cdev_ioctl_slave_sii_read(master, arg);
912d70d6f0e5 Removed some locks causing latency when using the library; added ioctl()
Florian Pose <fp@igh-essen.com>
parents: 2124
diff changeset
  3487
            break;
1079
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  3488
        case EC_IOCTL_SLAVE_SII_WRITE:
2180
912d70d6f0e5 Removed some locks causing latency when using the library; added ioctl()
Florian Pose <fp@igh-essen.com>
parents: 2124
diff changeset
  3489
            if (!(filp->f_mode & FMODE_WRITE)) {
912d70d6f0e5 Removed some locks causing latency when using the library; added ioctl()
Florian Pose <fp@igh-essen.com>
parents: 2124
diff changeset
  3490
                ret = -EPERM;
912d70d6f0e5 Removed some locks causing latency when using the library; added ioctl()
Florian Pose <fp@igh-essen.com>
parents: 2124
diff changeset
  3491
                break;
912d70d6f0e5 Removed some locks causing latency when using the library; added ioctl()
Florian Pose <fp@igh-essen.com>
parents: 2124
diff changeset
  3492
            }
912d70d6f0e5 Removed some locks causing latency when using the library; added ioctl()
Florian Pose <fp@igh-essen.com>
parents: 2124
diff changeset
  3493
            ret = ec_cdev_ioctl_slave_sii_write(master, arg);
912d70d6f0e5 Removed some locks causing latency when using the library; added ioctl()
Florian Pose <fp@igh-essen.com>
parents: 2124
diff changeset
  3494
            break;
1388
3c886ec376f5 Renamed phy_ commands to reg_.
Florian Pose <fp@igh-essen.com>
parents: 1382
diff changeset
  3495
        case EC_IOCTL_SLAVE_REG_READ:
2180
912d70d6f0e5 Removed some locks causing latency when using the library; added ioctl()
Florian Pose <fp@igh-essen.com>
parents: 2124
diff changeset
  3496
            ret = ec_cdev_ioctl_slave_reg_read(master, arg);
912d70d6f0e5 Removed some locks causing latency when using the library; added ioctl()
Florian Pose <fp@igh-essen.com>
parents: 2124
diff changeset
  3497
            break;
1388
3c886ec376f5 Renamed phy_ commands to reg_.
Florian Pose <fp@igh-essen.com>
parents: 1382
diff changeset
  3498
        case EC_IOCTL_SLAVE_REG_WRITE:
2180
912d70d6f0e5 Removed some locks causing latency when using the library; added ioctl()
Florian Pose <fp@igh-essen.com>
parents: 2124
diff changeset
  3499
            if (!(filp->f_mode & FMODE_WRITE)) {
912d70d6f0e5 Removed some locks causing latency when using the library; added ioctl()
Florian Pose <fp@igh-essen.com>
parents: 2124
diff changeset
  3500
                ret = -EPERM;
912d70d6f0e5 Removed some locks causing latency when using the library; added ioctl()
Florian Pose <fp@igh-essen.com>
parents: 2124
diff changeset
  3501
                break;
912d70d6f0e5 Removed some locks causing latency when using the library; added ioctl()
Florian Pose <fp@igh-essen.com>
parents: 2124
diff changeset
  3502
            }
912d70d6f0e5 Removed some locks causing latency when using the library; added ioctl()
Florian Pose <fp@igh-essen.com>
parents: 2124
diff changeset
  3503
            ret = ec_cdev_ioctl_slave_reg_write(master, arg);
912d70d6f0e5 Removed some locks causing latency when using the library; added ioctl()
Florian Pose <fp@igh-essen.com>
parents: 2124
diff changeset
  3504
            break;
1335
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents: 1328
diff changeset
  3505
        case EC_IOCTL_SLAVE_FOE_READ:
2180
912d70d6f0e5 Removed some locks causing latency when using the library; added ioctl()
Florian Pose <fp@igh-essen.com>
parents: 2124
diff changeset
  3506
            ret = ec_cdev_ioctl_slave_foe_read(master, arg);
912d70d6f0e5 Removed some locks causing latency when using the library; added ioctl()
Florian Pose <fp@igh-essen.com>
parents: 2124
diff changeset
  3507
            break;
1335
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents: 1328
diff changeset
  3508
        case EC_IOCTL_SLAVE_FOE_WRITE:
2180
912d70d6f0e5 Removed some locks causing latency when using the library; added ioctl()
Florian Pose <fp@igh-essen.com>
parents: 2124
diff changeset
  3509
            if (!(filp->f_mode & FMODE_WRITE)) {
912d70d6f0e5 Removed some locks causing latency when using the library; added ioctl()
Florian Pose <fp@igh-essen.com>
parents: 2124
diff changeset
  3510
                ret = -EPERM;
912d70d6f0e5 Removed some locks causing latency when using the library; added ioctl()
Florian Pose <fp@igh-essen.com>
parents: 2124
diff changeset
  3511
                break;
912d70d6f0e5 Removed some locks causing latency when using the library; added ioctl()
Florian Pose <fp@igh-essen.com>
parents: 2124
diff changeset
  3512
            }
912d70d6f0e5 Removed some locks causing latency when using the library; added ioctl()
Florian Pose <fp@igh-essen.com>
parents: 2124
diff changeset
  3513
            ret = ec_cdev_ioctl_slave_foe_write(master, arg);
912d70d6f0e5 Removed some locks causing latency when using the library; added ioctl()
Florian Pose <fp@igh-essen.com>
parents: 2124
diff changeset
  3514
            break;
1831
1875b9fea0ba Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents: 1826
diff changeset
  3515
        case EC_IOCTL_SLAVE_SOE_READ:
2180
912d70d6f0e5 Removed some locks causing latency when using the library; added ioctl()
Florian Pose <fp@igh-essen.com>
parents: 2124
diff changeset
  3516
            ret = ec_cdev_ioctl_slave_soe_read(master, arg);
912d70d6f0e5 Removed some locks causing latency when using the library; added ioctl()
Florian Pose <fp@igh-essen.com>
parents: 2124
diff changeset
  3517
            break;
1831
1875b9fea0ba Implemented reading Sercos-over-EtherCAT services. To be continued...
Florian Pose <fp@igh-essen.com>
parents: 1826
diff changeset
  3518
        case EC_IOCTL_SLAVE_SOE_WRITE:
2180
912d70d6f0e5 Removed some locks causing latency when using the library; added ioctl()
Florian Pose <fp@igh-essen.com>
parents: 2124
diff changeset
  3519
            if (!(filp->f_mode & FMODE_WRITE)) {
912d70d6f0e5 Removed some locks causing latency when using the library; added ioctl()
Florian Pose <fp@igh-essen.com>
parents: 2124
diff changeset
  3520
                ret = -EPERM;
912d70d6f0e5 Removed some locks causing latency when using the library; added ioctl()
Florian Pose <fp@igh-essen.com>
parents: 2124
diff changeset
  3521
                break;
912d70d6f0e5 Removed some locks causing latency when using the library; added ioctl()
Florian Pose <fp@igh-essen.com>
parents: 2124
diff changeset
  3522
            }
912d70d6f0e5 Removed some locks causing latency when using the library; added ioctl()
Florian Pose <fp@igh-essen.com>
parents: 2124
diff changeset
  3523
            ret = ec_cdev_ioctl_slave_soe_write(master, arg);
912d70d6f0e5 Removed some locks causing latency when using the library; added ioctl()
Florian Pose <fp@igh-essen.com>
parents: 2124
diff changeset
  3524
            break;
990
4f223f3df05a Bus configuration via 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 989
diff changeset
  3525
        case EC_IOCTL_CONFIG:
2180
912d70d6f0e5 Removed some locks causing latency when using the library; added ioctl()
Florian Pose <fp@igh-essen.com>
parents: 2124
diff changeset
  3526
            ret = ec_cdev_ioctl_config(master, arg);
912d70d6f0e5 Removed some locks causing latency when using the library; added ioctl()
Florian Pose <fp@igh-essen.com>
parents: 2124
diff changeset
  3527
            break;
990
4f223f3df05a Bus configuration via 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 989
diff changeset
  3528
        case EC_IOCTL_CONFIG_PDO:
2180
912d70d6f0e5 Removed some locks causing latency when using the library; added ioctl()
Florian Pose <fp@igh-essen.com>
parents: 2124
diff changeset
  3529
            ret = ec_cdev_ioctl_config_pdo(master, arg);
912d70d6f0e5 Removed some locks causing latency when using the library; added ioctl()
Florian Pose <fp@igh-essen.com>
parents: 2124
diff changeset
  3530
            break;
990
4f223f3df05a Bus configuration via 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 989
diff changeset
  3531
        case EC_IOCTL_CONFIG_PDO_ENTRY:
2180
912d70d6f0e5 Removed some locks causing latency when using the library; added ioctl()
Florian Pose <fp@igh-essen.com>
parents: 2124
diff changeset
  3532
            ret = ec_cdev_ioctl_config_pdo_entry(master, arg);
912d70d6f0e5 Removed some locks causing latency when using the library; added ioctl()
Florian Pose <fp@igh-essen.com>
parents: 2124
diff changeset
  3533
            break;
990
4f223f3df05a Bus configuration via 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 989
diff changeset
  3534
        case EC_IOCTL_CONFIG_SDO:
2180
912d70d6f0e5 Removed some locks causing latency when using the library; added ioctl()
Florian Pose <fp@igh-essen.com>
parents: 2124
diff changeset
  3535
            ret = ec_cdev_ioctl_config_sdo(master, arg);
912d70d6f0e5 Removed some locks causing latency when using the library; added ioctl()
Florian Pose <fp@igh-essen.com>
parents: 2124
diff changeset
  3536
            break;
1966
23c638a81fe7 Output IDN configuration as part of 'ethercat config -v'.
Florian Pose <fp@igh-essen.com>
parents: 1963
diff changeset
  3537
        case EC_IOCTL_CONFIG_IDN:
2180
912d70d6f0e5 Removed some locks causing latency when using the library; added ioctl()
Florian Pose <fp@igh-essen.com>
parents: 2124
diff changeset
  3538
            ret = ec_cdev_ioctl_config_idn(master, arg);
912d70d6f0e5 Removed some locks causing latency when using the library; added ioctl()
Florian Pose <fp@igh-essen.com>
parents: 2124
diff changeset
  3539
            break;
1516
e3b09f847512 Fixed compiler error on --disable-eoe.
Florian Pose <fp@igh-essen.com>
parents: 1513
diff changeset
  3540
#ifdef EC_EOE
1485
5ddc3a455059 ethercat eoe command.
Florian Pose <fp@igh-essen.com>
parents: 1465
diff changeset
  3541
        case EC_IOCTL_EOE_HANDLER:
2180
912d70d6f0e5 Removed some locks causing latency when using the library; added ioctl()
Florian Pose <fp@igh-essen.com>
parents: 2124
diff changeset
  3542
            ret = ec_cdev_ioctl_eoe_handler(master, arg);
912d70d6f0e5 Removed some locks causing latency when using the library; added ioctl()
Florian Pose <fp@igh-essen.com>
parents: 2124
diff changeset
  3543
            break;
1516
e3b09f847512 Fixed compiler error on --disable-eoe.
Florian Pose <fp@igh-essen.com>
parents: 1513
diff changeset
  3544
#endif
1242
632a6b91f8e4 First version of userspace library with requesting/releasing.
Florian Pose <fp@igh-essen.com>
parents: 1223
diff changeset
  3545
        case EC_IOCTL_REQUEST:
2180
912d70d6f0e5 Removed some locks causing latency when using the library; added ioctl()
Florian Pose <fp@igh-essen.com>
parents: 2124
diff changeset
  3546
            if (!(filp->f_mode & FMODE_WRITE)) {
912d70d6f0e5 Removed some locks causing latency when using the library; added ioctl()
Florian Pose <fp@igh-essen.com>
parents: 2124
diff changeset
  3547
                ret = -EPERM;
912d70d6f0e5 Removed some locks causing latency when using the library; added ioctl()
Florian Pose <fp@igh-essen.com>
parents: 2124
diff changeset
  3548
                break;
912d70d6f0e5 Removed some locks causing latency when using the library; added ioctl()
Florian Pose <fp@igh-essen.com>
parents: 2124
diff changeset
  3549
            }
912d70d6f0e5 Removed some locks causing latency when using the library; added ioctl()
Florian Pose <fp@igh-essen.com>
parents: 2124
diff changeset
  3550
            ret = ec_cdev_ioctl_request(master, arg, priv);
912d70d6f0e5 Removed some locks causing latency when using the library; added ioctl()
Florian Pose <fp@igh-essen.com>
parents: 2124
diff changeset
  3551
            break;
1244
0b70040d3daa No kernel handles in userspace; Domain creation.
Florian Pose <fp@igh-essen.com>
parents: 1242
diff changeset
  3552
        case EC_IOCTL_CREATE_DOMAIN:
2180
912d70d6f0e5 Removed some locks causing latency when using the library; added ioctl()
Florian Pose <fp@igh-essen.com>
parents: 2124
diff changeset
  3553
            if (!(filp->f_mode & FMODE_WRITE)) {
912d70d6f0e5 Removed some locks causing latency when using the library; added ioctl()
Florian Pose <fp@igh-essen.com>
parents: 2124
diff changeset
  3554
                ret = -EPERM;
912d70d6f0e5 Removed some locks causing latency when using the library; added ioctl()
Florian Pose <fp@igh-essen.com>
parents: 2124
diff changeset
  3555
                break;
912d70d6f0e5 Removed some locks causing latency when using the library; added ioctl()
Florian Pose <fp@igh-essen.com>
parents: 2124
diff changeset
  3556
            }
912d70d6f0e5 Removed some locks causing latency when using the library; added ioctl()
Florian Pose <fp@igh-essen.com>
parents: 2124
diff changeset
  3557
            ret = ec_cdev_ioctl_create_domain(master, arg, priv);
912d70d6f0e5 Removed some locks causing latency when using the library; added ioctl()
Florian Pose <fp@igh-essen.com>
parents: 2124
diff changeset
  3558
            break;
1246
4042bda8c980 Creating slave configurations.
Florian Pose <fp@igh-essen.com>
parents: 1244
diff changeset
  3559
        case EC_IOCTL_CREATE_SLAVE_CONFIG:
2180
912d70d6f0e5 Removed some locks causing latency when using the library; added ioctl()
Florian Pose <fp@igh-essen.com>
parents: 2124
diff changeset
  3560
            if (!(filp->f_mode & FMODE_WRITE)) {
912d70d6f0e5 Removed some locks causing latency when using the library; added ioctl()
Florian Pose <fp@igh-essen.com>
parents: 2124
diff changeset
  3561
                ret = -EPERM;
912d70d6f0e5 Removed some locks causing latency when using the library; added ioctl()
Florian Pose <fp@igh-essen.com>
parents: 2124
diff changeset
  3562
                break;
912d70d6f0e5 Removed some locks causing latency when using the library; added ioctl()
Florian Pose <fp@igh-essen.com>
parents: 2124
diff changeset
  3563
            }
912d70d6f0e5 Removed some locks causing latency when using the library; added ioctl()
Florian Pose <fp@igh-essen.com>
parents: 2124
diff changeset
  3564
            ret = ec_cdev_ioctl_create_slave_config(master, arg, priv);
912d70d6f0e5 Removed some locks causing latency when using the library; added ioctl()
Florian Pose <fp@igh-essen.com>
parents: 2124
diff changeset
  3565
            break;
1247
5f1f1a3e6636 Activate, Send and received; cyclic timer with setitimer().
Florian Pose <fp@igh-essen.com>
parents: 1246
diff changeset
  3566
        case EC_IOCTL_ACTIVATE:
2180
912d70d6f0e5 Removed some locks causing latency when using the library; added ioctl()
Florian Pose <fp@igh-essen.com>
parents: 2124
diff changeset
  3567
            if (!(filp->f_mode & FMODE_WRITE)) {
912d70d6f0e5 Removed some locks causing latency when using the library; added ioctl()
Florian Pose <fp@igh-essen.com>
parents: 2124
diff changeset
  3568
                ret = -EPERM;
912d70d6f0e5 Removed some locks causing latency when using the library; added ioctl()
Florian Pose <fp@igh-essen.com>
parents: 2124
diff changeset
  3569
                break;
912d70d6f0e5 Removed some locks causing latency when using the library; added ioctl()
Florian Pose <fp@igh-essen.com>
parents: 2124
diff changeset
  3570
            }
912d70d6f0e5 Removed some locks causing latency when using the library; added ioctl()
Florian Pose <fp@igh-essen.com>
parents: 2124
diff changeset
  3571
            ret = ec_cdev_ioctl_activate(master, arg, priv);
912d70d6f0e5 Removed some locks causing latency when using the library; added ioctl()
Florian Pose <fp@igh-essen.com>
parents: 2124
diff changeset
  3572
            break;
1531
6c5478400e28 Implemented ecrt_master_deactivate() in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1530
diff changeset
  3573
        case EC_IOCTL_DEACTIVATE:
2180
912d70d6f0e5 Removed some locks causing latency when using the library; added ioctl()
Florian Pose <fp@igh-essen.com>
parents: 2124
diff changeset
  3574
            if (!(filp->f_mode & FMODE_WRITE)) {
912d70d6f0e5 Removed some locks causing latency when using the library; added ioctl()
Florian Pose <fp@igh-essen.com>
parents: 2124
diff changeset
  3575
                ret = -EPERM;
912d70d6f0e5 Removed some locks causing latency when using the library; added ioctl()
Florian Pose <fp@igh-essen.com>
parents: 2124
diff changeset
  3576
                break;
912d70d6f0e5 Removed some locks causing latency when using the library; added ioctl()
Florian Pose <fp@igh-essen.com>
parents: 2124
diff changeset
  3577
            }
912d70d6f0e5 Removed some locks causing latency when using the library; added ioctl()
Florian Pose <fp@igh-essen.com>
parents: 2124
diff changeset
  3578
            ret = ec_cdev_ioctl_deactivate(master, arg, priv);
912d70d6f0e5 Removed some locks causing latency when using the library; added ioctl()
Florian Pose <fp@igh-essen.com>
parents: 2124
diff changeset
  3579
            break;
1247
5f1f1a3e6636 Activate, Send and received; cyclic timer with setitimer().
Florian Pose <fp@igh-essen.com>
parents: 1246
diff changeset
  3580
        case EC_IOCTL_SEND:
2180
912d70d6f0e5 Removed some locks causing latency when using the library; added ioctl()
Florian Pose <fp@igh-essen.com>
parents: 2124
diff changeset
  3581
            if (!(filp->f_mode & FMODE_WRITE)) {
912d70d6f0e5 Removed some locks causing latency when using the library; added ioctl()
Florian Pose <fp@igh-essen.com>
parents: 2124
diff changeset
  3582
                ret = -EPERM;
912d70d6f0e5 Removed some locks causing latency when using the library; added ioctl()
Florian Pose <fp@igh-essen.com>
parents: 2124
diff changeset
  3583
                break;
912d70d6f0e5 Removed some locks causing latency when using the library; added ioctl()
Florian Pose <fp@igh-essen.com>
parents: 2124
diff changeset
  3584
            }
912d70d6f0e5 Removed some locks causing latency when using the library; added ioctl()
Florian Pose <fp@igh-essen.com>
parents: 2124
diff changeset
  3585
            ret = ec_cdev_ioctl_send(master, arg, priv);
912d70d6f0e5 Removed some locks causing latency when using the library; added ioctl()
Florian Pose <fp@igh-essen.com>
parents: 2124
diff changeset
  3586
            break;
1247
5f1f1a3e6636 Activate, Send and received; cyclic timer with setitimer().
Florian Pose <fp@igh-essen.com>
parents: 1246
diff changeset
  3587
        case EC_IOCTL_RECEIVE:
2180
912d70d6f0e5 Removed some locks causing latency when using the library; added ioctl()
Florian Pose <fp@igh-essen.com>
parents: 2124
diff changeset
  3588
            if (!(filp->f_mode & FMODE_WRITE)) {
912d70d6f0e5 Removed some locks causing latency when using the library; added ioctl()
Florian Pose <fp@igh-essen.com>
parents: 2124
diff changeset
  3589
                ret = -EPERM;
912d70d6f0e5 Removed some locks causing latency when using the library; added ioctl()
Florian Pose <fp@igh-essen.com>
parents: 2124
diff changeset
  3590
                break;
912d70d6f0e5 Removed some locks causing latency when using the library; added ioctl()
Florian Pose <fp@igh-essen.com>
parents: 2124
diff changeset
  3591
            }
912d70d6f0e5 Removed some locks causing latency when using the library; added ioctl()
Florian Pose <fp@igh-essen.com>
parents: 2124
diff changeset
  3592
            ret = ec_cdev_ioctl_receive(master, arg, priv);
912d70d6f0e5 Removed some locks causing latency when using the library; added ioctl()
Florian Pose <fp@igh-essen.com>
parents: 2124
diff changeset
  3593
            break;
1259
5f9d1abbee71 Added state functions; writing of process data works.
Florian Pose <fp@igh-essen.com>
parents: 1258
diff changeset
  3594
        case EC_IOCTL_MASTER_STATE:
2180
912d70d6f0e5 Removed some locks causing latency when using the library; added ioctl()
Florian Pose <fp@igh-essen.com>
parents: 2124
diff changeset
  3595
            ret = ec_cdev_ioctl_master_state(master, arg, priv);
912d70d6f0e5 Removed some locks causing latency when using the library; added ioctl()
Florian Pose <fp@igh-essen.com>
parents: 2124
diff changeset
  3596
            break;
1454
b9986feec1a5 Added EC_IOCTL_APP_TIME.
Florian Pose <fp@igh-essen.com>
parents: 1448
diff changeset
  3597
        case EC_IOCTL_APP_TIME:
2180
912d70d6f0e5 Removed some locks causing latency when using the library; added ioctl()
Florian Pose <fp@igh-essen.com>
parents: 2124
diff changeset
  3598
            if (!(filp->f_mode & FMODE_WRITE)) {
912d70d6f0e5 Removed some locks causing latency when using the library; added ioctl()
Florian Pose <fp@igh-essen.com>
parents: 2124
diff changeset
  3599
                ret = -EPERM;
912d70d6f0e5 Removed some locks causing latency when using the library; added ioctl()
Florian Pose <fp@igh-essen.com>
parents: 2124
diff changeset
  3600
                break;
912d70d6f0e5 Removed some locks causing latency when using the library; added ioctl()
Florian Pose <fp@igh-essen.com>
parents: 2124
diff changeset
  3601
            }
912d70d6f0e5 Removed some locks causing latency when using the library; added ioctl()
Florian Pose <fp@igh-essen.com>
parents: 2124
diff changeset
  3602
            ret = ec_cdev_ioctl_app_time(master, arg, priv);
912d70d6f0e5 Removed some locks causing latency when using the library; added ioctl()
Florian Pose <fp@igh-essen.com>
parents: 2124
diff changeset
  3603
            break;
1413
44c2b7c0ae1a Userspace library implementation of DC functions.
Florian Pose <fp@igh-essen.com>
parents: 1401
diff changeset
  3604
        case EC_IOCTL_SYNC_REF:
2180
912d70d6f0e5 Removed some locks causing latency when using the library; added ioctl()
Florian Pose <fp@igh-essen.com>
parents: 2124
diff changeset
  3605
            if (!(filp->f_mode & FMODE_WRITE)) {
912d70d6f0e5 Removed some locks causing latency when using the library; added ioctl()
Florian Pose <fp@igh-essen.com>
parents: 2124
diff changeset
  3606
                ret = -EPERM;
912d70d6f0e5 Removed some locks causing latency when using the library; added ioctl()
Florian Pose <fp@igh-essen.com>
parents: 2124
diff changeset
  3607
                break;
912d70d6f0e5 Removed some locks causing latency when using the library; added ioctl()
Florian Pose <fp@igh-essen.com>
parents: 2124
diff changeset
  3608
            }
912d70d6f0e5 Removed some locks causing latency when using the library; added ioctl()
Florian Pose <fp@igh-essen.com>
parents: 2124
diff changeset
  3609
            ret = ec_cdev_ioctl_sync_ref(master, arg, priv);
912d70d6f0e5 Removed some locks causing latency when using the library; added ioctl()
Florian Pose <fp@igh-essen.com>
parents: 2124
diff changeset
  3610
            break;
1413
44c2b7c0ae1a Userspace library implementation of DC functions.
Florian Pose <fp@igh-essen.com>
parents: 1401
diff changeset
  3611
        case EC_IOCTL_SYNC_SLAVES:
2180
912d70d6f0e5 Removed some locks causing latency when using the library; added ioctl()
Florian Pose <fp@igh-essen.com>
parents: 2124
diff changeset
  3612
            if (!(filp->f_mode & FMODE_WRITE)) {
912d70d6f0e5 Removed some locks causing latency when using the library; added ioctl()
Florian Pose <fp@igh-essen.com>
parents: 2124
diff changeset
  3613
                ret = -EPERM;
912d70d6f0e5 Removed some locks causing latency when using the library; added ioctl()
Florian Pose <fp@igh-essen.com>
parents: 2124
diff changeset
  3614
                break;
912d70d6f0e5 Removed some locks causing latency when using the library; added ioctl()
Florian Pose <fp@igh-essen.com>
parents: 2124
diff changeset
  3615
            }
912d70d6f0e5 Removed some locks causing latency when using the library; added ioctl()
Florian Pose <fp@igh-essen.com>
parents: 2124
diff changeset
  3616
            ret = ec_cdev_ioctl_sync_slaves(master, arg, priv);
912d70d6f0e5 Removed some locks causing latency when using the library; added ioctl()
Florian Pose <fp@igh-essen.com>
parents: 2124
diff changeset
  3617
            break;
1535
0c484ee12d89 DC synchrony monitoring methods.
Florian Pose <fp@igh-essen.com>
parents: 1531
diff changeset
  3618
        case EC_IOCTL_SYNC_MON_QUEUE:
2180
912d70d6f0e5 Removed some locks causing latency when using the library; added ioctl()
Florian Pose <fp@igh-essen.com>
parents: 2124
diff changeset
  3619
            if (!(filp->f_mode & FMODE_WRITE)) {
912d70d6f0e5 Removed some locks causing latency when using the library; added ioctl()
Florian Pose <fp@igh-essen.com>
parents: 2124
diff changeset
  3620
                ret = -EPERM;
912d70d6f0e5 Removed some locks causing latency when using the library; added ioctl()
Florian Pose <fp@igh-essen.com>
parents: 2124
diff changeset
  3621
                break;
912d70d6f0e5 Removed some locks causing latency when using the library; added ioctl()
Florian Pose <fp@igh-essen.com>
parents: 2124
diff changeset
  3622
            }
912d70d6f0e5 Removed some locks causing latency when using the library; added ioctl()
Florian Pose <fp@igh-essen.com>
parents: 2124
diff changeset
  3623
            ret = ec_cdev_ioctl_sync_mon_queue(master, arg, priv);
912d70d6f0e5 Removed some locks causing latency when using the library; added ioctl()
Florian Pose <fp@igh-essen.com>
parents: 2124
diff changeset
  3624
            break;
1535
0c484ee12d89 DC synchrony monitoring methods.
Florian Pose <fp@igh-essen.com>
parents: 1531
diff changeset
  3625
        case EC_IOCTL_SYNC_MON_PROCESS:
2180
912d70d6f0e5 Removed some locks causing latency when using the library; added ioctl()
Florian Pose <fp@igh-essen.com>
parents: 2124
diff changeset
  3626
            if (!(filp->f_mode & FMODE_WRITE)) {
912d70d6f0e5 Removed some locks causing latency when using the library; added ioctl()
Florian Pose <fp@igh-essen.com>
parents: 2124
diff changeset
  3627
                ret = -EPERM;
912d70d6f0e5 Removed some locks causing latency when using the library; added ioctl()
Florian Pose <fp@igh-essen.com>
parents: 2124
diff changeset
  3628
                break;
912d70d6f0e5 Removed some locks causing latency when using the library; added ioctl()
Florian Pose <fp@igh-essen.com>
parents: 2124
diff changeset
  3629
            }
912d70d6f0e5 Removed some locks causing latency when using the library; added ioctl()
Florian Pose <fp@igh-essen.com>
parents: 2124
diff changeset
  3630
            ret = ec_cdev_ioctl_sync_mon_process(master, arg, priv);
912d70d6f0e5 Removed some locks causing latency when using the library; added ioctl()
Florian Pose <fp@igh-essen.com>
parents: 2124
diff changeset
  3631
            break;
2009
b5391b329b5d Added ecrt_master_reset() method.
Florian Pose <fp@igh-essen.com>
parents: 1972
diff changeset
  3632
        case EC_IOCTL_RESET:
2180
912d70d6f0e5 Removed some locks causing latency when using the library; added ioctl()
Florian Pose <fp@igh-essen.com>
parents: 2124
diff changeset
  3633
            if (!(filp->f_mode & FMODE_WRITE)) {
912d70d6f0e5 Removed some locks causing latency when using the library; added ioctl()
Florian Pose <fp@igh-essen.com>
parents: 2124
diff changeset
  3634
                ret = -EPERM;
912d70d6f0e5 Removed some locks causing latency when using the library; added ioctl()
Florian Pose <fp@igh-essen.com>
parents: 2124
diff changeset
  3635
                break;
912d70d6f0e5 Removed some locks causing latency when using the library; added ioctl()
Florian Pose <fp@igh-essen.com>
parents: 2124
diff changeset
  3636
            }
912d70d6f0e5 Removed some locks causing latency when using the library; added ioctl()
Florian Pose <fp@igh-essen.com>
parents: 2124
diff changeset
  3637
            ret = ec_cdev_ioctl_reset(master, arg, priv);
912d70d6f0e5 Removed some locks causing latency when using the library; added ioctl()
Florian Pose <fp@igh-essen.com>
parents: 2124
diff changeset
  3638
            break;
1255
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  3639
        case EC_IOCTL_SC_SYNC:
2180
912d70d6f0e5 Removed some locks causing latency when using the library; added ioctl()
Florian Pose <fp@igh-essen.com>
parents: 2124
diff changeset
  3640
            if (!(filp->f_mode & FMODE_WRITE)) {
912d70d6f0e5 Removed some locks causing latency when using the library; added ioctl()
Florian Pose <fp@igh-essen.com>
parents: 2124
diff changeset
  3641
                ret = -EPERM;
912d70d6f0e5 Removed some locks causing latency when using the library; added ioctl()
Florian Pose <fp@igh-essen.com>
parents: 2124
diff changeset
  3642
                break;
912d70d6f0e5 Removed some locks causing latency when using the library; added ioctl()
Florian Pose <fp@igh-essen.com>
parents: 2124
diff changeset
  3643
            }
912d70d6f0e5 Removed some locks causing latency when using the library; added ioctl()
Florian Pose <fp@igh-essen.com>
parents: 2124
diff changeset
  3644
            ret = ec_cdev_ioctl_sc_sync(master, arg, priv);
912d70d6f0e5 Removed some locks causing latency when using the library; added ioctl()
Florian Pose <fp@igh-essen.com>
parents: 2124
diff changeset
  3645
            break;
1509
a864688e7de5 Added watchdog configuration via application interface (thanks to J. Mohre).
Florian Pose <fp@igh-essen.com>
parents: 1507
diff changeset
  3646
        case EC_IOCTL_SC_WATCHDOG:
2180
912d70d6f0e5 Removed some locks causing latency when using the library; added ioctl()
Florian Pose <fp@igh-essen.com>
parents: 2124
diff changeset
  3647
            if (!(filp->f_mode & FMODE_WRITE)) {
912d70d6f0e5 Removed some locks causing latency when using the library; added ioctl()
Florian Pose <fp@igh-essen.com>
parents: 2124
diff changeset
  3648
                ret = -EPERM;
912d70d6f0e5 Removed some locks causing latency when using the library; added ioctl()
Florian Pose <fp@igh-essen.com>
parents: 2124
diff changeset
  3649
                break;
912d70d6f0e5 Removed some locks causing latency when using the library; added ioctl()
Florian Pose <fp@igh-essen.com>
parents: 2124
diff changeset
  3650
            }
912d70d6f0e5 Removed some locks causing latency when using the library; added ioctl()
Florian Pose <fp@igh-essen.com>
parents: 2124
diff changeset
  3651
            ret = ec_cdev_ioctl_sc_watchdog(master, arg, priv);
912d70d6f0e5 Removed some locks causing latency when using the library; added ioctl()
Florian Pose <fp@igh-essen.com>
parents: 2124
diff changeset
  3652
            break;
1255
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  3653
        case EC_IOCTL_SC_ADD_PDO:
2180
912d70d6f0e5 Removed some locks causing latency when using the library; added ioctl()
Florian Pose <fp@igh-essen.com>
parents: 2124
diff changeset
  3654
            if (!(filp->f_mode & FMODE_WRITE)) {
912d70d6f0e5 Removed some locks causing latency when using the library; added ioctl()
Florian Pose <fp@igh-essen.com>
parents: 2124
diff changeset
  3655
                ret = -EPERM;
912d70d6f0e5 Removed some locks causing latency when using the library; added ioctl()
Florian Pose <fp@igh-essen.com>
parents: 2124
diff changeset
  3656
                break;
912d70d6f0e5 Removed some locks causing latency when using the library; added ioctl()
Florian Pose <fp@igh-essen.com>
parents: 2124
diff changeset
  3657
            }
912d70d6f0e5 Removed some locks causing latency when using the library; added ioctl()
Florian Pose <fp@igh-essen.com>
parents: 2124
diff changeset
  3658
            ret = ec_cdev_ioctl_sc_add_pdo(master, arg, priv);
912d70d6f0e5 Removed some locks causing latency when using the library; added ioctl()
Florian Pose <fp@igh-essen.com>
parents: 2124
diff changeset
  3659
            break;
1255
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  3660
        case EC_IOCTL_SC_CLEAR_PDOS:
2180
912d70d6f0e5 Removed some locks causing latency when using the library; added ioctl()
Florian Pose <fp@igh-essen.com>
parents: 2124
diff changeset
  3661
            if (!(filp->f_mode & FMODE_WRITE)) {
912d70d6f0e5 Removed some locks causing latency when using the library; added ioctl()
Florian Pose <fp@igh-essen.com>
parents: 2124
diff changeset
  3662
                ret = -EPERM;
912d70d6f0e5 Removed some locks causing latency when using the library; added ioctl()
Florian Pose <fp@igh-essen.com>
parents: 2124
diff changeset
  3663
                break;
912d70d6f0e5 Removed some locks causing latency when using the library; added ioctl()
Florian Pose <fp@igh-essen.com>
parents: 2124
diff changeset
  3664
            }
912d70d6f0e5 Removed some locks causing latency when using the library; added ioctl()
Florian Pose <fp@igh-essen.com>
parents: 2124
diff changeset
  3665
            ret = ec_cdev_ioctl_sc_clear_pdos(master, arg, priv);
912d70d6f0e5 Removed some locks causing latency when using the library; added ioctl()
Florian Pose <fp@igh-essen.com>
parents: 2124
diff changeset
  3666
            break;
1255
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  3667
        case EC_IOCTL_SC_ADD_ENTRY:
2180
912d70d6f0e5 Removed some locks causing latency when using the library; added ioctl()
Florian Pose <fp@igh-essen.com>
parents: 2124
diff changeset
  3668
            if (!(filp->f_mode & FMODE_WRITE)) {
912d70d6f0e5 Removed some locks causing latency when using the library; added ioctl()
Florian Pose <fp@igh-essen.com>
parents: 2124
diff changeset
  3669
                ret = -EPERM;
912d70d6f0e5 Removed some locks causing latency when using the library; added ioctl()
Florian Pose <fp@igh-essen.com>
parents: 2124
diff changeset
  3670
                break;
912d70d6f0e5 Removed some locks causing latency when using the library; added ioctl()
Florian Pose <fp@igh-essen.com>
parents: 2124
diff changeset
  3671
            }
912d70d6f0e5 Removed some locks causing latency when using the library; added ioctl()
Florian Pose <fp@igh-essen.com>
parents: 2124
diff changeset
  3672
            ret = ec_cdev_ioctl_sc_add_entry(master, arg, priv);
912d70d6f0e5 Removed some locks causing latency when using the library; added ioctl()
Florian Pose <fp@igh-essen.com>
parents: 2124
diff changeset
  3673
            break;
1255
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  3674
        case EC_IOCTL_SC_CLEAR_ENTRIES:
2180
912d70d6f0e5 Removed some locks causing latency when using the library; added ioctl()
Florian Pose <fp@igh-essen.com>
parents: 2124
diff changeset
  3675
            if (!(filp->f_mode & FMODE_WRITE)) {
912d70d6f0e5 Removed some locks causing latency when using the library; added ioctl()
Florian Pose <fp@igh-essen.com>
parents: 2124
diff changeset
  3676
                ret = -EPERM;
912d70d6f0e5 Removed some locks causing latency when using the library; added ioctl()
Florian Pose <fp@igh-essen.com>
parents: 2124
diff changeset
  3677
                break;
912d70d6f0e5 Removed some locks causing latency when using the library; added ioctl()
Florian Pose <fp@igh-essen.com>
parents: 2124
diff changeset
  3678
            }
912d70d6f0e5 Removed some locks causing latency when using the library; added ioctl()
Florian Pose <fp@igh-essen.com>
parents: 2124
diff changeset
  3679
            ret = ec_cdev_ioctl_sc_clear_entries(master, arg, priv);
912d70d6f0e5 Removed some locks causing latency when using the library; added ioctl()
Florian Pose <fp@igh-essen.com>
parents: 2124
diff changeset
  3680
            break;
1255
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  3681
        case EC_IOCTL_SC_REG_PDO_ENTRY:
2180
912d70d6f0e5 Removed some locks causing latency when using the library; added ioctl()
Florian Pose <fp@igh-essen.com>
parents: 2124
diff changeset
  3682
            if (!(filp->f_mode & FMODE_WRITE)) {
912d70d6f0e5 Removed some locks causing latency when using the library; added ioctl()
Florian Pose <fp@igh-essen.com>
parents: 2124
diff changeset
  3683
                ret = -EPERM;
912d70d6f0e5 Removed some locks causing latency when using the library; added ioctl()
Florian Pose <fp@igh-essen.com>
parents: 2124
diff changeset
  3684
                break;
912d70d6f0e5 Removed some locks causing latency when using the library; added ioctl()
Florian Pose <fp@igh-essen.com>
parents: 2124
diff changeset
  3685
            }
912d70d6f0e5 Removed some locks causing latency when using the library; added ioctl()
Florian Pose <fp@igh-essen.com>
parents: 2124
diff changeset
  3686
            ret = ec_cdev_ioctl_sc_reg_pdo_entry(master, arg, priv);
912d70d6f0e5 Removed some locks causing latency when using the library; added ioctl()
Florian Pose <fp@igh-essen.com>
parents: 2124
diff changeset
  3687
            break;
1448
d7ba0c408a07 Merged ecrt_slave_config_dc_assign_activate() and
Florian Pose <fp@igh-essen.com>
parents: 1447
diff changeset
  3688
        case EC_IOCTL_SC_DC:
2180
912d70d6f0e5 Removed some locks causing latency when using the library; added ioctl()
Florian Pose <fp@igh-essen.com>
parents: 2124
diff changeset
  3689
            if (!(filp->f_mode & FMODE_WRITE)) {
912d70d6f0e5 Removed some locks causing latency when using the library; added ioctl()
Florian Pose <fp@igh-essen.com>
parents: 2124
diff changeset
  3690
                ret = -EPERM;
912d70d6f0e5 Removed some locks causing latency when using the library; added ioctl()
Florian Pose <fp@igh-essen.com>
parents: 2124
diff changeset
  3691
                break;
912d70d6f0e5 Removed some locks causing latency when using the library; added ioctl()
Florian Pose <fp@igh-essen.com>
parents: 2124
diff changeset
  3692
            }
912d70d6f0e5 Removed some locks causing latency when using the library; added ioctl()
Florian Pose <fp@igh-essen.com>
parents: 2124
diff changeset
  3693
            ret = ec_cdev_ioctl_sc_dc(master, arg, priv);
912d70d6f0e5 Removed some locks causing latency when using the library; added ioctl()
Florian Pose <fp@igh-essen.com>
parents: 2124
diff changeset
  3694
            break;
1255
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  3695
        case EC_IOCTL_SC_SDO:
2180
912d70d6f0e5 Removed some locks causing latency when using the library; added ioctl()
Florian Pose <fp@igh-essen.com>
parents: 2124
diff changeset
  3696
            if (!(filp->f_mode & FMODE_WRITE)) {
912d70d6f0e5 Removed some locks causing latency when using the library; added ioctl()
Florian Pose <fp@igh-essen.com>
parents: 2124
diff changeset
  3697
                ret = -EPERM;
912d70d6f0e5 Removed some locks causing latency when using the library; added ioctl()
Florian Pose <fp@igh-essen.com>
parents: 2124
diff changeset
  3698
                break;
912d70d6f0e5 Removed some locks causing latency when using the library; added ioctl()
Florian Pose <fp@igh-essen.com>
parents: 2124
diff changeset
  3699
            }
912d70d6f0e5 Removed some locks causing latency when using the library; added ioctl()
Florian Pose <fp@igh-essen.com>
parents: 2124
diff changeset
  3700
            ret = ec_cdev_ioctl_sc_sdo(master, arg, priv);
912d70d6f0e5 Removed some locks causing latency when using the library; added ioctl()
Florian Pose <fp@igh-essen.com>
parents: 2124
diff changeset
  3701
            break;
1352
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1350
diff changeset
  3702
        case EC_IOCTL_SC_SDO_REQUEST:
2180
912d70d6f0e5 Removed some locks causing latency when using the library; added ioctl()
Florian Pose <fp@igh-essen.com>
parents: 2124
diff changeset
  3703
            if (!(filp->f_mode & FMODE_WRITE)) {
912d70d6f0e5 Removed some locks causing latency when using the library; added ioctl()
Florian Pose <fp@igh-essen.com>
parents: 2124
diff changeset
  3704
                ret = -EPERM;
912d70d6f0e5 Removed some locks causing latency when using the library; added ioctl()
Florian Pose <fp@igh-essen.com>
parents: 2124
diff changeset
  3705
                break;
912d70d6f0e5 Removed some locks causing latency when using the library; added ioctl()
Florian Pose <fp@igh-essen.com>
parents: 2124
diff changeset
  3706
            }
912d70d6f0e5 Removed some locks causing latency when using the library; added ioctl()
Florian Pose <fp@igh-essen.com>
parents: 2124
diff changeset
  3707
            ret = ec_cdev_ioctl_sc_create_sdo_request(master, arg, priv);
912d70d6f0e5 Removed some locks causing latency when using the library; added ioctl()
Florian Pose <fp@igh-essen.com>
parents: 2124
diff changeset
  3708
            break;
1264
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  3709
        case EC_IOCTL_SC_VOE:
2180
912d70d6f0e5 Removed some locks causing latency when using the library; added ioctl()
Florian Pose <fp@igh-essen.com>
parents: 2124
diff changeset
  3710
            if (!(filp->f_mode & FMODE_WRITE)) {
912d70d6f0e5 Removed some locks causing latency when using the library; added ioctl()
Florian Pose <fp@igh-essen.com>
parents: 2124
diff changeset
  3711
                ret = -EPERM;
912d70d6f0e5 Removed some locks causing latency when using the library; added ioctl()
Florian Pose <fp@igh-essen.com>
parents: 2124
diff changeset
  3712
                break;
912d70d6f0e5 Removed some locks causing latency when using the library; added ioctl()
Florian Pose <fp@igh-essen.com>
parents: 2124
diff changeset
  3713
            }
912d70d6f0e5 Removed some locks causing latency when using the library; added ioctl()
Florian Pose <fp@igh-essen.com>
parents: 2124
diff changeset
  3714
            ret = ec_cdev_ioctl_sc_create_voe_handler(master, arg, priv);
912d70d6f0e5 Removed some locks causing latency when using the library; added ioctl()
Florian Pose <fp@igh-essen.com>
parents: 2124
diff changeset
  3715
            break;
1259
5f9d1abbee71 Added state functions; writing of process data works.
Florian Pose <fp@igh-essen.com>
parents: 1258
diff changeset
  3716
        case EC_IOCTL_SC_STATE:
2180
912d70d6f0e5 Removed some locks causing latency when using the library; added ioctl()
Florian Pose <fp@igh-essen.com>
parents: 2124
diff changeset
  3717
            ret = ec_cdev_ioctl_sc_state(master, arg, priv);
912d70d6f0e5 Removed some locks causing latency when using the library; added ioctl()
Florian Pose <fp@igh-essen.com>
parents: 2124
diff changeset
  3718
            break;
1862
05d224a66270 Implemented ecrt_slave_config_idn() for user-space library.
Florian Pose <fp@igh-essen.com>
parents: 1857
diff changeset
  3719
        case EC_IOCTL_SC_IDN:
2180
912d70d6f0e5 Removed some locks causing latency when using the library; added ioctl()
Florian Pose <fp@igh-essen.com>
parents: 2124
diff changeset
  3720
            if (!(filp->f_mode & FMODE_WRITE)) {
912d70d6f0e5 Removed some locks causing latency when using the library; added ioctl()
Florian Pose <fp@igh-essen.com>
parents: 2124
diff changeset
  3721
                ret = -EPERM;
912d70d6f0e5 Removed some locks causing latency when using the library; added ioctl()
Florian Pose <fp@igh-essen.com>
parents: 2124
diff changeset
  3722
                break;
912d70d6f0e5 Removed some locks causing latency when using the library; added ioctl()
Florian Pose <fp@igh-essen.com>
parents: 2124
diff changeset
  3723
            }
912d70d6f0e5 Removed some locks causing latency when using the library; added ioctl()
Florian Pose <fp@igh-essen.com>
parents: 2124
diff changeset
  3724
            ret = ec_cdev_ioctl_sc_idn(master, arg, priv);
912d70d6f0e5 Removed some locks causing latency when using the library; added ioctl()
Florian Pose <fp@igh-essen.com>
parents: 2124
diff changeset
  3725
            break;
1258
900f1124e8f8 Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents: 1255
diff changeset
  3726
        case EC_IOCTL_DOMAIN_OFFSET:
2180
912d70d6f0e5 Removed some locks causing latency when using the library; added ioctl()
Florian Pose <fp@igh-essen.com>
parents: 2124
diff changeset
  3727
            ret = ec_cdev_ioctl_domain_offset(master, arg, priv);
912d70d6f0e5 Removed some locks causing latency when using the library; added ioctl()
Florian Pose <fp@igh-essen.com>
parents: 2124
diff changeset
  3728
            break;
1258
900f1124e8f8 Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents: 1255
diff changeset
  3729
        case EC_IOCTL_DOMAIN_PROCESS:
2180
912d70d6f0e5 Removed some locks causing latency when using the library; added ioctl()
Florian Pose <fp@igh-essen.com>
parents: 2124
diff changeset
  3730
            if (!(filp->f_mode & FMODE_WRITE)) {
912d70d6f0e5 Removed some locks causing latency when using the library; added ioctl()
Florian Pose <fp@igh-essen.com>
parents: 2124
diff changeset
  3731
                ret = -EPERM;
912d70d6f0e5 Removed some locks causing latency when using the library; added ioctl()
Florian Pose <fp@igh-essen.com>
parents: 2124
diff changeset
  3732
                break;
912d70d6f0e5 Removed some locks causing latency when using the library; added ioctl()
Florian Pose <fp@igh-essen.com>
parents: 2124
diff changeset
  3733
            }
912d70d6f0e5 Removed some locks causing latency when using the library; added ioctl()
Florian Pose <fp@igh-essen.com>
parents: 2124
diff changeset
  3734
            ret = ec_cdev_ioctl_domain_process(master, arg, priv);
912d70d6f0e5 Removed some locks causing latency when using the library; added ioctl()
Florian Pose <fp@igh-essen.com>
parents: 2124
diff changeset
  3735
            break;
1258
900f1124e8f8 Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents: 1255
diff changeset
  3736
        case EC_IOCTL_DOMAIN_QUEUE:
2180
912d70d6f0e5 Removed some locks causing latency when using the library; added ioctl()
Florian Pose <fp@igh-essen.com>
parents: 2124
diff changeset
  3737
            if (!(filp->f_mode & FMODE_WRITE)) {
912d70d6f0e5 Removed some locks causing latency when using the library; added ioctl()
Florian Pose <fp@igh-essen.com>
parents: 2124
diff changeset
  3738
                ret = -EPERM;
912d70d6f0e5 Removed some locks causing latency when using the library; added ioctl()
Florian Pose <fp@igh-essen.com>
parents: 2124
diff changeset
  3739
                break;
912d70d6f0e5 Removed some locks causing latency when using the library; added ioctl()
Florian Pose <fp@igh-essen.com>
parents: 2124
diff changeset
  3740
            }
912d70d6f0e5 Removed some locks causing latency when using the library; added ioctl()
Florian Pose <fp@igh-essen.com>
parents: 2124
diff changeset
  3741
            ret = ec_cdev_ioctl_domain_queue(master, arg, priv);
912d70d6f0e5 Removed some locks causing latency when using the library; added ioctl()
Florian Pose <fp@igh-essen.com>
parents: 2124
diff changeset
  3742
            break;
1259
5f9d1abbee71 Added state functions; writing of process data works.
Florian Pose <fp@igh-essen.com>
parents: 1258
diff changeset
  3743
        case EC_IOCTL_DOMAIN_STATE:
2180
912d70d6f0e5 Removed some locks causing latency when using the library; added ioctl()
Florian Pose <fp@igh-essen.com>
parents: 2124
diff changeset
  3744
            ret = ec_cdev_ioctl_domain_state(master, arg, priv);
912d70d6f0e5 Removed some locks causing latency when using the library; added ioctl()
Florian Pose <fp@igh-essen.com>
parents: 2124
diff changeset
  3745
            break;
1352
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1350
diff changeset
  3746
        case EC_IOCTL_SDO_REQUEST_TIMEOUT:
2180
912d70d6f0e5 Removed some locks causing latency when using the library; added ioctl()
Florian Pose <fp@igh-essen.com>
parents: 2124
diff changeset
  3747
            if (!(filp->f_mode & FMODE_WRITE)) {
912d70d6f0e5 Removed some locks causing latency when using the library; added ioctl()
Florian Pose <fp@igh-essen.com>
parents: 2124
diff changeset
  3748
                ret = -EPERM;
912d70d6f0e5 Removed some locks causing latency when using the library; added ioctl()
Florian Pose <fp@igh-essen.com>
parents: 2124
diff changeset
  3749
                break;
912d70d6f0e5 Removed some locks causing latency when using the library; added ioctl()
Florian Pose <fp@igh-essen.com>
parents: 2124
diff changeset
  3750
            }
912d70d6f0e5 Removed some locks causing latency when using the library; added ioctl()
Florian Pose <fp@igh-essen.com>
parents: 2124
diff changeset
  3751
            ret = ec_cdev_ioctl_sdo_request_timeout(master, arg, priv);
912d70d6f0e5 Removed some locks causing latency when using the library; added ioctl()
Florian Pose <fp@igh-essen.com>
parents: 2124
diff changeset
  3752
            break;
1352
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1350
diff changeset
  3753
        case EC_IOCTL_SDO_REQUEST_STATE:
2180
912d70d6f0e5 Removed some locks causing latency when using the library; added ioctl()
Florian Pose <fp@igh-essen.com>
parents: 2124
diff changeset
  3754
            ret = ec_cdev_ioctl_sdo_request_state(master, arg, priv);
912d70d6f0e5 Removed some locks causing latency when using the library; added ioctl()
Florian Pose <fp@igh-essen.com>
parents: 2124
diff changeset
  3755
            break;
1352
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1350
diff changeset
  3756
        case EC_IOCTL_SDO_REQUEST_READ:
2180
912d70d6f0e5 Removed some locks causing latency when using the library; added ioctl()
Florian Pose <fp@igh-essen.com>
parents: 2124
diff changeset
  3757
            if (!(filp->f_mode & FMODE_WRITE)) {
912d70d6f0e5 Removed some locks causing latency when using the library; added ioctl()
Florian Pose <fp@igh-essen.com>
parents: 2124
diff changeset
  3758
                ret = -EPERM;
912d70d6f0e5 Removed some locks causing latency when using the library; added ioctl()
Florian Pose <fp@igh-essen.com>
parents: 2124
diff changeset
  3759
                break;
912d70d6f0e5 Removed some locks causing latency when using the library; added ioctl()
Florian Pose <fp@igh-essen.com>
parents: 2124
diff changeset
  3760
            }
912d70d6f0e5 Removed some locks causing latency when using the library; added ioctl()
Florian Pose <fp@igh-essen.com>
parents: 2124
diff changeset
  3761
            ret = ec_cdev_ioctl_sdo_request_read(master, arg, priv);
912d70d6f0e5 Removed some locks causing latency when using the library; added ioctl()
Florian Pose <fp@igh-essen.com>
parents: 2124
diff changeset
  3762
            break;
1352
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1350
diff changeset
  3763
        case EC_IOCTL_SDO_REQUEST_WRITE:
2180
912d70d6f0e5 Removed some locks causing latency when using the library; added ioctl()
Florian Pose <fp@igh-essen.com>
parents: 2124
diff changeset
  3764
            if (!(filp->f_mode & FMODE_WRITE)) {
912d70d6f0e5 Removed some locks causing latency when using the library; added ioctl()
Florian Pose <fp@igh-essen.com>
parents: 2124
diff changeset
  3765
                ret = -EPERM;
912d70d6f0e5 Removed some locks causing latency when using the library; added ioctl()
Florian Pose <fp@igh-essen.com>
parents: 2124
diff changeset
  3766
                break;
912d70d6f0e5 Removed some locks causing latency when using the library; added ioctl()
Florian Pose <fp@igh-essen.com>
parents: 2124
diff changeset
  3767
            }
912d70d6f0e5 Removed some locks causing latency when using the library; added ioctl()
Florian Pose <fp@igh-essen.com>
parents: 2124
diff changeset
  3768
            ret = ec_cdev_ioctl_sdo_request_write(master, arg, priv);
912d70d6f0e5 Removed some locks causing latency when using the library; added ioctl()
Florian Pose <fp@igh-essen.com>
parents: 2124
diff changeset
  3769
            break;
1352
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1350
diff changeset
  3770
        case EC_IOCTL_SDO_REQUEST_DATA:
2180
912d70d6f0e5 Removed some locks causing latency when using the library; added ioctl()
Florian Pose <fp@igh-essen.com>
parents: 2124
diff changeset
  3771
            ret = ec_cdev_ioctl_sdo_request_data(master, arg, priv);
912d70d6f0e5 Removed some locks causing latency when using the library; added ioctl()
Florian Pose <fp@igh-essen.com>
parents: 2124
diff changeset
  3772
            break;
1264
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  3773
        case EC_IOCTL_VOE_SEND_HEADER:
2180
912d70d6f0e5 Removed some locks causing latency when using the library; added ioctl()
Florian Pose <fp@igh-essen.com>
parents: 2124
diff changeset
  3774
            if (!(filp->f_mode & FMODE_WRITE)) {
912d70d6f0e5 Removed some locks causing latency when using the library; added ioctl()
Florian Pose <fp@igh-essen.com>
parents: 2124
diff changeset
  3775
                ret = -EPERM;
912d70d6f0e5 Removed some locks causing latency when using the library; added ioctl()
Florian Pose <fp@igh-essen.com>
parents: 2124
diff changeset
  3776
                break;
912d70d6f0e5 Removed some locks causing latency when using the library; added ioctl()
Florian Pose <fp@igh-essen.com>
parents: 2124
diff changeset
  3777
            }
912d70d6f0e5 Removed some locks causing latency when using the library; added ioctl()
Florian Pose <fp@igh-essen.com>
parents: 2124
diff changeset
  3778
            ret = ec_cdev_ioctl_voe_send_header(master, arg, priv);
912d70d6f0e5 Removed some locks causing latency when using the library; added ioctl()
Florian Pose <fp@igh-essen.com>
parents: 2124
diff changeset
  3779
            break;
1264
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  3780
        case EC_IOCTL_VOE_REC_HEADER:
2180
912d70d6f0e5 Removed some locks causing latency when using the library; added ioctl()
Florian Pose <fp@igh-essen.com>
parents: 2124
diff changeset
  3781
            ret = ec_cdev_ioctl_voe_rec_header(master, arg, priv);
912d70d6f0e5 Removed some locks causing latency when using the library; added ioctl()
Florian Pose <fp@igh-essen.com>
parents: 2124
diff changeset
  3782
            break;
1264
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  3783
        case EC_IOCTL_VOE_READ:
2180
912d70d6f0e5 Removed some locks causing latency when using the library; added ioctl()
Florian Pose <fp@igh-essen.com>
parents: 2124
diff changeset
  3784
            if (!(filp->f_mode & FMODE_WRITE)) {
912d70d6f0e5 Removed some locks causing latency when using the library; added ioctl()
Florian Pose <fp@igh-essen.com>
parents: 2124
diff changeset
  3785
                ret = -EPERM;
912d70d6f0e5 Removed some locks causing latency when using the library; added ioctl()
Florian Pose <fp@igh-essen.com>
parents: 2124
diff changeset
  3786
                break;
912d70d6f0e5 Removed some locks causing latency when using the library; added ioctl()
Florian Pose <fp@igh-essen.com>
parents: 2124
diff changeset
  3787
            }
912d70d6f0e5 Removed some locks causing latency when using the library; added ioctl()
Florian Pose <fp@igh-essen.com>
parents: 2124
diff changeset
  3788
            ret = ec_cdev_ioctl_voe_read(master, arg, priv);
912d70d6f0e5 Removed some locks causing latency when using the library; added ioctl()
Florian Pose <fp@igh-essen.com>
parents: 2124
diff changeset
  3789
            break;
1314
b3d06a8807b3 Included ecrt_voe_handler_read_nosync()-Patch by Mathias Weber.
Florian Pose <fp@igh-essen.com>
parents: 1313
diff changeset
  3790
        case EC_IOCTL_VOE_READ_NOSYNC:
2180
912d70d6f0e5 Removed some locks causing latency when using the library; added ioctl()
Florian Pose <fp@igh-essen.com>
parents: 2124
diff changeset
  3791
            if (!(filp->f_mode & FMODE_WRITE)) {
912d70d6f0e5 Removed some locks causing latency when using the library; added ioctl()
Florian Pose <fp@igh-essen.com>
parents: 2124
diff changeset
  3792
                ret = -EPERM;
912d70d6f0e5 Removed some locks causing latency when using the library; added ioctl()
Florian Pose <fp@igh-essen.com>
parents: 2124
diff changeset
  3793
                break;
912d70d6f0e5 Removed some locks causing latency when using the library; added ioctl()
Florian Pose <fp@igh-essen.com>
parents: 2124
diff changeset
  3794
            }
912d70d6f0e5 Removed some locks causing latency when using the library; added ioctl()
Florian Pose <fp@igh-essen.com>
parents: 2124
diff changeset
  3795
            ret = ec_cdev_ioctl_voe_read_nosync(master, arg, priv);
912d70d6f0e5 Removed some locks causing latency when using the library; added ioctl()
Florian Pose <fp@igh-essen.com>
parents: 2124
diff changeset
  3796
            break;
1264
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  3797
        case EC_IOCTL_VOE_WRITE:
2180
912d70d6f0e5 Removed some locks causing latency when using the library; added ioctl()
Florian Pose <fp@igh-essen.com>
parents: 2124
diff changeset
  3798
            if (!(filp->f_mode & FMODE_WRITE)) {
912d70d6f0e5 Removed some locks causing latency when using the library; added ioctl()
Florian Pose <fp@igh-essen.com>
parents: 2124
diff changeset
  3799
                ret = -EPERM;
912d70d6f0e5 Removed some locks causing latency when using the library; added ioctl()
Florian Pose <fp@igh-essen.com>
parents: 2124
diff changeset
  3800
                break;
912d70d6f0e5 Removed some locks causing latency when using the library; added ioctl()
Florian Pose <fp@igh-essen.com>
parents: 2124
diff changeset
  3801
            }
912d70d6f0e5 Removed some locks causing latency when using the library; added ioctl()
Florian Pose <fp@igh-essen.com>
parents: 2124
diff changeset
  3802
            ret = ec_cdev_ioctl_voe_write(master, arg, priv);
912d70d6f0e5 Removed some locks causing latency when using the library; added ioctl()
Florian Pose <fp@igh-essen.com>
parents: 2124
diff changeset
  3803
            break;
1264
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  3804
        case EC_IOCTL_VOE_EXEC:
2180
912d70d6f0e5 Removed some locks causing latency when using the library; added ioctl()
Florian Pose <fp@igh-essen.com>
parents: 2124
diff changeset
  3805
            if (!(filp->f_mode & FMODE_WRITE)) {
912d70d6f0e5 Removed some locks causing latency when using the library; added ioctl()
Florian Pose <fp@igh-essen.com>
parents: 2124
diff changeset
  3806
                ret = -EPERM;
912d70d6f0e5 Removed some locks causing latency when using the library; added ioctl()
Florian Pose <fp@igh-essen.com>
parents: 2124
diff changeset
  3807
                break;
912d70d6f0e5 Removed some locks causing latency when using the library; added ioctl()
Florian Pose <fp@igh-essen.com>
parents: 2124
diff changeset
  3808
            }
912d70d6f0e5 Removed some locks causing latency when using the library; added ioctl()
Florian Pose <fp@igh-essen.com>
parents: 2124
diff changeset
  3809
            ret = ec_cdev_ioctl_voe_exec(master, arg, priv);
912d70d6f0e5 Removed some locks causing latency when using the library; added ioctl()
Florian Pose <fp@igh-essen.com>
parents: 2124
diff changeset
  3810
            break;
1264
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  3811
        case EC_IOCTL_VOE_DATA:
2180
912d70d6f0e5 Removed some locks causing latency when using the library; added ioctl()
Florian Pose <fp@igh-essen.com>
parents: 2124
diff changeset
  3812
            ret = ec_cdev_ioctl_voe_data(master, arg, priv);
912d70d6f0e5 Removed some locks causing latency when using the library; added ioctl()
Florian Pose <fp@igh-essen.com>
parents: 2124
diff changeset
  3813
            break;
1804
742607c464c4 Removed tabulators.
Florian Pose <fp@igh-essen.com>
parents: 1606
diff changeset
  3814
        case EC_IOCTL_SET_SEND_INTERVAL:
2180
912d70d6f0e5 Removed some locks causing latency when using the library; added ioctl()
Florian Pose <fp@igh-essen.com>
parents: 2124
diff changeset
  3815
            if (!(filp->f_mode & FMODE_WRITE)) {
912d70d6f0e5 Removed some locks causing latency when using the library; added ioctl()
Florian Pose <fp@igh-essen.com>
parents: 2124
diff changeset
  3816
                ret = -EPERM;
912d70d6f0e5 Removed some locks causing latency when using the library; added ioctl()
Florian Pose <fp@igh-essen.com>
parents: 2124
diff changeset
  3817
                break;
912d70d6f0e5 Removed some locks causing latency when using the library; added ioctl()
Florian Pose <fp@igh-essen.com>
parents: 2124
diff changeset
  3818
            }
912d70d6f0e5 Removed some locks causing latency when using the library; added ioctl()
Florian Pose <fp@igh-essen.com>
parents: 2124
diff changeset
  3819
            ret = ec_cdev_ioctl_set_send_interval(master, arg, priv);
912d70d6f0e5 Removed some locks causing latency when using the library; added ioctl()
Florian Pose <fp@igh-essen.com>
parents: 2124
diff changeset
  3820
            break;
922
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3821
        default:
2180
912d70d6f0e5 Removed some locks causing latency when using the library; added ioctl()
Florian Pose <fp@igh-essen.com>
parents: 2124
diff changeset
  3822
            ret = -ENOTTY;
912d70d6f0e5 Removed some locks causing latency when using the library; added ioctl()
Florian Pose <fp@igh-essen.com>
parents: 2124
diff changeset
  3823
            break;
912d70d6f0e5 Removed some locks causing latency when using the library; added ioctl()
Florian Pose <fp@igh-essen.com>
parents: 2124
diff changeset
  3824
    }
912d70d6f0e5 Removed some locks causing latency when using the library; added ioctl()
Florian Pose <fp@igh-essen.com>
parents: 2124
diff changeset
  3825
912d70d6f0e5 Removed some locks causing latency when using the library; added ioctl()
Florian Pose <fp@igh-essen.com>
parents: 2124
diff changeset
  3826
#if DEBUG_LATENCY
912d70d6f0e5 Removed some locks causing latency when using the library; added ioctl()
Florian Pose <fp@igh-essen.com>
parents: 2124
diff changeset
  3827
    b = get_cycles();
912d70d6f0e5 Removed some locks causing latency when using the library; added ioctl()
Florian Pose <fp@igh-essen.com>
parents: 2124
diff changeset
  3828
    t = (unsigned int) ((b - a) * 1000LL) / cpu_khz;
912d70d6f0e5 Removed some locks causing latency when using the library; added ioctl()
Florian Pose <fp@igh-essen.com>
parents: 2124
diff changeset
  3829
    if (t > 50) {
912d70d6f0e5 Removed some locks causing latency when using the library; added ioctl()
Florian Pose <fp@igh-essen.com>
parents: 2124
diff changeset
  3830
        EC_MASTER_WARN(master, "ioctl(0x%02x) took %u us.\n",
912d70d6f0e5 Removed some locks causing latency when using the library; added ioctl()
Florian Pose <fp@igh-essen.com>
parents: 2124
diff changeset
  3831
                _IOC_NR(cmd), t);
912d70d6f0e5 Removed some locks causing latency when using the library; added ioctl()
Florian Pose <fp@igh-essen.com>
parents: 2124
diff changeset
  3832
    }
912d70d6f0e5 Removed some locks causing latency when using the library; added ioctl()
Florian Pose <fp@igh-essen.com>
parents: 2124
diff changeset
  3833
#endif
912d70d6f0e5 Removed some locks causing latency when using the library; added ioctl()
Florian Pose <fp@igh-essen.com>
parents: 2124
diff changeset
  3834
912d70d6f0e5 Removed some locks causing latency when using the library; added ioctl()
Florian Pose <fp@igh-essen.com>
parents: 2124
diff changeset
  3835
    return ret;
1079
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  3836
}
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  3837
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  3838
/*****************************************************************************/
1258
900f1124e8f8 Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents: 1255
diff changeset
  3839
1268
d9599395e89b Maintained code docs.
Florian Pose <fp@igh-essen.com>
parents: 1264
diff changeset
  3840
/** Memory-map callback for the EtherCAT character device.
d9599395e89b Maintained code docs.
Florian Pose <fp@igh-essen.com>
parents: 1264
diff changeset
  3841
 *
d9599395e89b Maintained code docs.
Florian Pose <fp@igh-essen.com>
parents: 1264
diff changeset
  3842
 * The actual mapping will be done in the eccdev_vma_nopage() callback of the
d9599395e89b Maintained code docs.
Florian Pose <fp@igh-essen.com>
parents: 1264
diff changeset
  3843
 * virtual memory area.
d9599395e89b Maintained code docs.
Florian Pose <fp@igh-essen.com>
parents: 1264
diff changeset
  3844
 */
1258
900f1124e8f8 Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents: 1255
diff changeset
  3845
int eccdev_mmap(
900f1124e8f8 Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents: 1255
diff changeset
  3846
        struct file *filp,
900f1124e8f8 Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents: 1255
diff changeset
  3847
        struct vm_area_struct *vma
900f1124e8f8 Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents: 1255
diff changeset
  3848
        )
900f1124e8f8 Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents: 1255
diff changeset
  3849
{
900f1124e8f8 Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents: 1255
diff changeset
  3850
    ec_cdev_priv_t *priv = (ec_cdev_priv_t *) filp->private_data;
900f1124e8f8 Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents: 1255
diff changeset
  3851
1921
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1909
diff changeset
  3852
    EC_MASTER_DBG(priv->cdev->master, 1, "mmap()\n");
1258
900f1124e8f8 Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents: 1255
diff changeset
  3853
900f1124e8f8 Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents: 1255
diff changeset
  3854
    vma->vm_ops = &eccdev_vm_ops;
900f1124e8f8 Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents: 1255
diff changeset
  3855
    vma->vm_flags |= VM_RESERVED; /* Pages will not be swapped out */
900f1124e8f8 Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents: 1255
diff changeset
  3856
    vma->vm_private_data = priv;
900f1124e8f8 Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents: 1255
diff changeset
  3857
900f1124e8f8 Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents: 1255
diff changeset
  3858
    return 0;
900f1124e8f8 Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents: 1255
diff changeset
  3859
}
900f1124e8f8 Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents: 1255
diff changeset
  3860
900f1124e8f8 Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents: 1255
diff changeset
  3861
/*****************************************************************************/
900f1124e8f8 Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents: 1255
diff changeset
  3862
1272
288c982acd23 Use .fault handler instead of .nopage handler from 2.6.23.
Florian Pose <fp@igh-essen.com>
parents: 1268
diff changeset
  3863
#if LINUX_VERSION_CODE >= PAGE_FAULT_VERSION
288c982acd23 Use .fault handler instead of .nopage handler from 2.6.23.
Florian Pose <fp@igh-essen.com>
parents: 1268
diff changeset
  3864
1268
d9599395e89b Maintained code docs.
Florian Pose <fp@igh-essen.com>
parents: 1264
diff changeset
  3865
/** Page fault callback for a virtual memory area.
d9599395e89b Maintained code docs.
Florian Pose <fp@igh-essen.com>
parents: 1264
diff changeset
  3866
 *
d9599395e89b Maintained code docs.
Florian Pose <fp@igh-essen.com>
parents: 1264
diff changeset
  3867
 * Called at the first access on a virtual-memory area retrieved with
d9599395e89b Maintained code docs.
Florian Pose <fp@igh-essen.com>
parents: 1264
diff changeset
  3868
 * ecdev_mmap().
d9599395e89b Maintained code docs.
Florian Pose <fp@igh-essen.com>
parents: 1264
diff changeset
  3869
 */
1272
288c982acd23 Use .fault handler instead of .nopage handler from 2.6.23.
Florian Pose <fp@igh-essen.com>
parents: 1268
diff changeset
  3870
static int eccdev_vma_fault(
288c982acd23 Use .fault handler instead of .nopage handler from 2.6.23.
Florian Pose <fp@igh-essen.com>
parents: 1268
diff changeset
  3871
        struct vm_area_struct *vma, /**< Virtual memory area. */
288c982acd23 Use .fault handler instead of .nopage handler from 2.6.23.
Florian Pose <fp@igh-essen.com>
parents: 1268
diff changeset
  3872
        struct vm_fault *vmf /**< Fault data. */
288c982acd23 Use .fault handler instead of .nopage handler from 2.6.23.
Florian Pose <fp@igh-essen.com>
parents: 1268
diff changeset
  3873
        )
288c982acd23 Use .fault handler instead of .nopage handler from 2.6.23.
Florian Pose <fp@igh-essen.com>
parents: 1268
diff changeset
  3874
{
1284
283aab089eb5 Fixed page fault handler.
Florian Pose <fp@igh-essen.com>
parents: 1272
diff changeset
  3875
    unsigned long offset = vmf->pgoff << PAGE_SHIFT;
283aab089eb5 Fixed page fault handler.
Florian Pose <fp@igh-essen.com>
parents: 1272
diff changeset
  3876
    ec_cdev_priv_t *priv = (ec_cdev_priv_t *) vma->vm_private_data;
1272
288c982acd23 Use .fault handler instead of .nopage handler from 2.6.23.
Florian Pose <fp@igh-essen.com>
parents: 1268
diff changeset
  3877
    struct page *page;
1284
283aab089eb5 Fixed page fault handler.
Florian Pose <fp@igh-essen.com>
parents: 1272
diff changeset
  3878
283aab089eb5 Fixed page fault handler.
Florian Pose <fp@igh-essen.com>
parents: 1272
diff changeset
  3879
    if (offset >= priv->process_data_size)
1272
288c982acd23 Use .fault handler instead of .nopage handler from 2.6.23.
Florian Pose <fp@igh-essen.com>
parents: 1268
diff changeset
  3880
        return VM_FAULT_SIGBUS;
288c982acd23 Use .fault handler instead of .nopage handler from 2.6.23.
Florian Pose <fp@igh-essen.com>
parents: 1268
diff changeset
  3881
1284
283aab089eb5 Fixed page fault handler.
Florian Pose <fp@igh-essen.com>
parents: 1272
diff changeset
  3882
    page = vmalloc_to_page(priv->process_data + offset);
283aab089eb5 Fixed page fault handler.
Florian Pose <fp@igh-essen.com>
parents: 1272
diff changeset
  3883
    if (!page)
283aab089eb5 Fixed page fault handler.
Florian Pose <fp@igh-essen.com>
parents: 1272
diff changeset
  3884
        return VM_FAULT_SIGBUS;
1272
288c982acd23 Use .fault handler instead of .nopage handler from 2.6.23.
Florian Pose <fp@igh-essen.com>
parents: 1268
diff changeset
  3885
288c982acd23 Use .fault handler instead of .nopage handler from 2.6.23.
Florian Pose <fp@igh-essen.com>
parents: 1268
diff changeset
  3886
    get_page(page);
288c982acd23 Use .fault handler instead of .nopage handler from 2.6.23.
Florian Pose <fp@igh-essen.com>
parents: 1268
diff changeset
  3887
    vmf->page = page;
1284
283aab089eb5 Fixed page fault handler.
Florian Pose <fp@igh-essen.com>
parents: 1272
diff changeset
  3888
1921
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1909
diff changeset
  3889
    EC_MASTER_DBG(priv->cdev->master, 1, "Vma fault, virtual_address = %p,"
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1909
diff changeset
  3890
            " offset = %lu, page = %p\n", vmf->virtual_address, offset, page);
1284
283aab089eb5 Fixed page fault handler.
Florian Pose <fp@igh-essen.com>
parents: 1272
diff changeset
  3891
1272
288c982acd23 Use .fault handler instead of .nopage handler from 2.6.23.
Florian Pose <fp@igh-essen.com>
parents: 1268
diff changeset
  3892
    return 0;
288c982acd23 Use .fault handler instead of .nopage handler from 2.6.23.
Florian Pose <fp@igh-essen.com>
parents: 1268
diff changeset
  3893
}
288c982acd23 Use .fault handler instead of .nopage handler from 2.6.23.
Florian Pose <fp@igh-essen.com>
parents: 1268
diff changeset
  3894
288c982acd23 Use .fault handler instead of .nopage handler from 2.6.23.
Florian Pose <fp@igh-essen.com>
parents: 1268
diff changeset
  3895
#else
288c982acd23 Use .fault handler instead of .nopage handler from 2.6.23.
Florian Pose <fp@igh-essen.com>
parents: 1268
diff changeset
  3896
288c982acd23 Use .fault handler instead of .nopage handler from 2.6.23.
Florian Pose <fp@igh-essen.com>
parents: 1268
diff changeset
  3897
/** Nopage callback for a virtual memory area.
288c982acd23 Use .fault handler instead of .nopage handler from 2.6.23.
Florian Pose <fp@igh-essen.com>
parents: 1268
diff changeset
  3898
 *
288c982acd23 Use .fault handler instead of .nopage handler from 2.6.23.
Florian Pose <fp@igh-essen.com>
parents: 1268
diff changeset
  3899
 * Called at the first access on a virtual-memory area retrieved with
288c982acd23 Use .fault handler instead of .nopage handler from 2.6.23.
Florian Pose <fp@igh-essen.com>
parents: 1268
diff changeset
  3900
 * ecdev_mmap().
288c982acd23 Use .fault handler instead of .nopage handler from 2.6.23.
Florian Pose <fp@igh-essen.com>
parents: 1268
diff changeset
  3901
 */
1258
900f1124e8f8 Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents: 1255
diff changeset
  3902
struct page *eccdev_vma_nopage(
1268
d9599395e89b Maintained code docs.
Florian Pose <fp@igh-essen.com>
parents: 1264
diff changeset
  3903
        struct vm_area_struct *vma, /**< Virtual memory area initialized by
d9599395e89b Maintained code docs.
Florian Pose <fp@igh-essen.com>
parents: 1264
diff changeset
  3904
                                      the kernel. */
d9599395e89b Maintained code docs.
Florian Pose <fp@igh-essen.com>
parents: 1264
diff changeset
  3905
        unsigned long address, /**< Requested virtual address. */
d9599395e89b Maintained code docs.
Florian Pose <fp@igh-essen.com>
parents: 1264
diff changeset
  3906
        int *type /**< Type output parameter. */
1258
900f1124e8f8 Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents: 1255
diff changeset
  3907
        )
900f1124e8f8 Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents: 1255
diff changeset
  3908
{
900f1124e8f8 Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents: 1255
diff changeset
  3909
    unsigned long offset;
900f1124e8f8 Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents: 1255
diff changeset
  3910
    struct page *page = NOPAGE_SIGBUS;
900f1124e8f8 Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents: 1255
diff changeset
  3911
    ec_cdev_priv_t *priv = (ec_cdev_priv_t *) vma->vm_private_data;
2061
7982704c8599 Fixed compiler error for kernel versions < 2.6.23.
Florian Pose <fp@igh-essen.com>
parents: 2009
diff changeset
  3912
    ec_master_t *master = priv->cdev->master;
1258
900f1124e8f8 Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents: 1255
diff changeset
  3913
900f1124e8f8 Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents: 1255
diff changeset
  3914
    offset = (address - vma->vm_start) + (vma->vm_pgoff << PAGE_SHIFT);
900f1124e8f8 Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents: 1255
diff changeset
  3915
900f1124e8f8 Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents: 1255
diff changeset
  3916
    if (offset >= priv->process_data_size)
900f1124e8f8 Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents: 1255
diff changeset
  3917
        return NOPAGE_SIGBUS;
900f1124e8f8 Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents: 1255
diff changeset
  3918
900f1124e8f8 Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents: 1255
diff changeset
  3919
    page = vmalloc_to_page(priv->process_data + offset);
900f1124e8f8 Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents: 1255
diff changeset
  3920
2061
7982704c8599 Fixed compiler error for kernel versions < 2.6.23.
Florian Pose <fp@igh-essen.com>
parents: 2009
diff changeset
  3921
    EC_MASTER_DBG(master, 1, "Nopage fault vma, address = %#lx,"
1921
d9cf40facbc4 Improved syslog macros.
Florian Pose <fp@igh-essen.com>
parents: 1909
diff changeset
  3922
            " offset = %#lx, page = %p\n", address, offset, page);
1258
900f1124e8f8 Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents: 1255
diff changeset
  3923
900f1124e8f8 Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents: 1255
diff changeset
  3924
    get_page(page);
900f1124e8f8 Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents: 1255
diff changeset
  3925
    if (type)
900f1124e8f8 Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents: 1255
diff changeset
  3926
        *type = VM_FAULT_MINOR;
900f1124e8f8 Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents: 1255
diff changeset
  3927
900f1124e8f8 Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents: 1255
diff changeset
  3928
    return page;
900f1124e8f8 Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents: 1255
diff changeset
  3929
}
900f1124e8f8 Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents: 1255
diff changeset
  3930
1272
288c982acd23 Use .fault handler instead of .nopage handler from 2.6.23.
Florian Pose <fp@igh-essen.com>
parents: 1268
diff changeset
  3931
#endif
288c982acd23 Use .fault handler instead of .nopage handler from 2.6.23.
Florian Pose <fp@igh-essen.com>
parents: 1268
diff changeset
  3932
288c982acd23 Use .fault handler instead of .nopage handler from 2.6.23.
Florian Pose <fp@igh-essen.com>
parents: 1268
diff changeset
  3933
/*****************************************************************************/