master/cdev.c
author Florian Pose <fp@igh-essen.com>
Wed, 06 May 2009 14:59:21 +0000
changeset 1450 117f5497efd9
parent 1448 d7ba0c408a07
child 1454 b9986feec1a5
permissions -rw-r--r--
TODO.
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"
922
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    45
#include "ioctl.h"
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    46
1397
6f9294a445c1 Introduced DEBUG_IOCTL.
Florian Pose <fp@igh-essen.com>
parents: 1388
diff changeset
    47
#define DEBUG_IOCTL 0
6f9294a445c1 Introduced DEBUG_IOCTL.
Florian Pose <fp@igh-essen.com>
parents: 1388
diff changeset
    48
922
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    49
/*****************************************************************************/
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    50
1268
d9599395e89b Maintained code docs.
Florian Pose <fp@igh-essen.com>
parents: 1264
diff changeset
    51
static int eccdev_open(struct inode *, struct file *);
d9599395e89b Maintained code docs.
Florian Pose <fp@igh-essen.com>
parents: 1264
diff changeset
    52
static int eccdev_release(struct inode *, struct file *);
d9599395e89b Maintained code docs.
Florian Pose <fp@igh-essen.com>
parents: 1264
diff changeset
    53
static long eccdev_ioctl(struct file *, unsigned int, unsigned long);
d9599395e89b Maintained code docs.
Florian Pose <fp@igh-essen.com>
parents: 1264
diff changeset
    54
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
    55
1272
288c982acd23 Use .fault handler instead of .nopage handler from 2.6.23.
Florian Pose <fp@igh-essen.com>
parents: 1268
diff changeset
    56
/** 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
    57
 * 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
    58
 */
288c982acd23 Use .fault handler instead of .nopage handler from 2.6.23.
Florian Pose <fp@igh-essen.com>
parents: 1268
diff changeset
    59
#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
    60
288c982acd23 Use .fault handler instead of .nopage handler from 2.6.23.
Florian Pose <fp@igh-essen.com>
parents: 1268
diff changeset
    61
#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
    62
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
    63
#else
1258
900f1124e8f8 Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents: 1255
diff changeset
    64
static struct page *eccdev_vma_nopage(
900f1124e8f8 Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents: 1255
diff changeset
    65
        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
    66
#endif
922
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    67
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    68
/*****************************************************************************/
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    69
1268
d9599395e89b Maintained code docs.
Florian Pose <fp@igh-essen.com>
parents: 1264
diff changeset
    70
/** File operation callbacks for the EtherCAT character device.
d9599395e89b Maintained code docs.
Florian Pose <fp@igh-essen.com>
parents: 1264
diff changeset
    71
 */
922
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    72
static struct file_operations eccdev_fops = {
935
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
    73
    .owner          = THIS_MODULE,
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
    74
    .open           = eccdev_open,
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
    75
    .release        = eccdev_release,
1258
900f1124e8f8 Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents: 1255
diff changeset
    76
    .unlocked_ioctl = eccdev_ioctl,
900f1124e8f8 Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents: 1255
diff changeset
    77
    .mmap           = eccdev_mmap
900f1124e8f8 Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents: 1255
diff changeset
    78
};
900f1124e8f8 Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents: 1255
diff changeset
    79
1268
d9599395e89b Maintained code docs.
Florian Pose <fp@igh-essen.com>
parents: 1264
diff changeset
    80
/** Callbacks for a virtual memory area retrieved with ecdevc_mmap().
d9599395e89b Maintained code docs.
Florian Pose <fp@igh-essen.com>
parents: 1264
diff changeset
    81
 */
1258
900f1124e8f8 Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents: 1255
diff changeset
    82
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
    83
#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
    84
    .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
    85
#else
1258
900f1124e8f8 Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents: 1255
diff changeset
    86
    .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
    87
#endif
922
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    88
};
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    89
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    90
/*****************************************************************************/
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    91
1242
632a6b91f8e4 First version of userspace library with requesting/releasing.
Florian Pose <fp@igh-essen.com>
parents: 1223
diff changeset
    92
/** 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
    93
 */
632a6b91f8e4 First version of userspace library with requesting/releasing.
Florian Pose <fp@igh-essen.com>
parents: 1223
diff changeset
    94
typedef struct {
1268
d9599395e89b Maintained code docs.
Florian Pose <fp@igh-essen.com>
parents: 1264
diff changeset
    95
    ec_cdev_t *cdev; /**< Character device. */
d9599395e89b Maintained code docs.
Florian Pose <fp@igh-essen.com>
parents: 1264
diff changeset
    96
    unsigned int requested; /**< Master wac requested via this file handle. */
d9599395e89b Maintained code docs.
Florian Pose <fp@igh-essen.com>
parents: 1264
diff changeset
    97
    uint8_t *process_data; /**< Total process data area. */
d9599395e89b Maintained code docs.
Florian Pose <fp@igh-essen.com>
parents: 1264
diff changeset
    98
    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
    99
} ec_cdev_priv_t;
632a6b91f8e4 First version of userspace library with requesting/releasing.
Florian Pose <fp@igh-essen.com>
parents: 1223
diff changeset
   100
632a6b91f8e4 First version of userspace library with requesting/releasing.
Florian Pose <fp@igh-essen.com>
parents: 1223
diff changeset
   101
/*****************************************************************************/
632a6b91f8e4 First version of userspace library with requesting/releasing.
Florian Pose <fp@igh-essen.com>
parents: 1223
diff changeset
   102
922
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   103
/** Constructor.
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   104
 * 
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   105
 * \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
   106
 */
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   107
int ec_cdev_init(
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   108
		ec_cdev_t *cdev, /**< EtherCAT master character device. */
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   109
		ec_master_t *master, /**< Parent master. */
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   110
		dev_t dev_num /**< Device number. */
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   111
		)
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   112
{
1313
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1312
diff changeset
   113
    int ret;
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1312
diff changeset
   114
922
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   115
    cdev->master = master;
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   116
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   117
    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
   118
    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
   119
1313
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1312
diff changeset
   120
    ret = cdev_add(&cdev->cdev,
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1312
diff changeset
   121
		 MKDEV(MAJOR(dev_num), master->index), 1);
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1312
diff changeset
   122
    if (ret) {
922
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   123
		EC_ERR("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
   124
    }
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1312
diff changeset
   125
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1312
diff changeset
   126
    return ret;
922
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   127
}
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   128
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   129
/*****************************************************************************/
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   130
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   131
/** Destructor.
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   132
 */
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   133
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
   134
{
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   135
    cdev_del(&cdev->cdev);
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
1079
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   138
/*****************************************************************************/
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   139
1108
7beba3e7e6b4 Added ec_cdev_strcpy() function.
Florian Pose <fp@igh-essen.com>
parents: 1092
diff changeset
   140
/** Copies a string to an ioctl structure.
7beba3e7e6b4 Added ec_cdev_strcpy() function.
Florian Pose <fp@igh-essen.com>
parents: 1092
diff changeset
   141
 */
7beba3e7e6b4 Added ec_cdev_strcpy() function.
Florian Pose <fp@igh-essen.com>
parents: 1092
diff changeset
   142
void ec_cdev_strcpy(
7beba3e7e6b4 Added ec_cdev_strcpy() function.
Florian Pose <fp@igh-essen.com>
parents: 1092
diff changeset
   143
        char *target, /**< Target. */
7beba3e7e6b4 Added ec_cdev_strcpy() function.
Florian Pose <fp@igh-essen.com>
parents: 1092
diff changeset
   144
        const char *source /**< Source. */
7beba3e7e6b4 Added ec_cdev_strcpy() function.
Florian Pose <fp@igh-essen.com>
parents: 1092
diff changeset
   145
        )
7beba3e7e6b4 Added ec_cdev_strcpy() function.
Florian Pose <fp@igh-essen.com>
parents: 1092
diff changeset
   146
{
7beba3e7e6b4 Added ec_cdev_strcpy() function.
Florian Pose <fp@igh-essen.com>
parents: 1092
diff changeset
   147
    if (source) {
7beba3e7e6b4 Added ec_cdev_strcpy() function.
Florian Pose <fp@igh-essen.com>
parents: 1092
diff changeset
   148
        strncpy(target, source, EC_IOCTL_STRING_SIZE);
7beba3e7e6b4 Added ec_cdev_strcpy() function.
Florian Pose <fp@igh-essen.com>
parents: 1092
diff changeset
   149
        target[EC_IOCTL_STRING_SIZE - 1] = 0;
7beba3e7e6b4 Added ec_cdev_strcpy() function.
Florian Pose <fp@igh-essen.com>
parents: 1092
diff changeset
   150
    } else {
7beba3e7e6b4 Added ec_cdev_strcpy() function.
Florian Pose <fp@igh-essen.com>
parents: 1092
diff changeset
   151
        target[0] = 0;
7beba3e7e6b4 Added ec_cdev_strcpy() function.
Florian Pose <fp@igh-essen.com>
parents: 1092
diff changeset
   152
    }
7beba3e7e6b4 Added ec_cdev_strcpy() function.
Florian Pose <fp@igh-essen.com>
parents: 1092
diff changeset
   153
}
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
1079
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   157
/** Get master information.
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   158
 */
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   159
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
   160
        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
   161
        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
   162
        )
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   163
{
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   164
    ec_ioctl_master_t data;
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   165
1189
acc6430bfb32 Use down_interruptible() wherever possible.
Florian Pose <fp@igh-essen.com>
parents: 1183
diff changeset
   166
    if (down_interruptible(&master->master_sem))
acc6430bfb32 Use down_interruptible() wherever possible.
Florian Pose <fp@igh-essen.com>
parents: 1183
diff changeset
   167
        return -EINTR;
1079
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   168
    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
   169
    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
   170
    data.domain_count = ec_master_domain_count(master);
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   171
    data.phase = (uint8_t) master->phase;
1447
846d75637c43 Added scan_busy flag to ioctl().
Florian Pose <fp@igh-essen.com>
parents: 1438
diff changeset
   172
    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
   173
    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
   174
1189
acc6430bfb32 Use down_interruptible() wherever possible.
Florian Pose <fp@igh-essen.com>
parents: 1183
diff changeset
   175
    if (down_interruptible(&master->device_sem))
acc6430bfb32 Use down_interruptible() wherever possible.
Florian Pose <fp@igh-essen.com>
parents: 1183
diff changeset
   176
        return -EINTR;
1415
9d1cdbf41247 Output reference clock and application time in 'ethercat Master'.
Florian Pose <fp@igh-essen.com>
parents: 1413
diff changeset
   177
1162
51a8b41d3dbc Display real ethernet address.
Florian Pose <fp@igh-essen.com>
parents: 1150
diff changeset
   178
    if (master->main_device.dev) {
51a8b41d3dbc Display real ethernet address.
Florian Pose <fp@igh-essen.com>
parents: 1150
diff changeset
   179
        memcpy(data.devices[0].address,
51a8b41d3dbc Display real ethernet address.
Florian Pose <fp@igh-essen.com>
parents: 1150
diff changeset
   180
                master->main_device.dev->dev_addr, ETH_ALEN);
51a8b41d3dbc Display real ethernet address.
Florian Pose <fp@igh-essen.com>
parents: 1150
diff changeset
   181
    } else {
51a8b41d3dbc Display real ethernet address.
Florian Pose <fp@igh-essen.com>
parents: 1150
diff changeset
   182
        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
   183
    }
1079
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   184
    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
   185
    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
   186
    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
   187
    data.devices[0].rx_count = master->main_device.rx_count;
1162
51a8b41d3dbc Display real ethernet address.
Florian Pose <fp@igh-essen.com>
parents: 1150
diff changeset
   188
51a8b41d3dbc Display real ethernet address.
Florian Pose <fp@igh-essen.com>
parents: 1150
diff changeset
   189
    if (master->backup_device.dev) {
51a8b41d3dbc Display real ethernet address.
Florian Pose <fp@igh-essen.com>
parents: 1150
diff changeset
   190
        memcpy(data.devices[1].address,
51a8b41d3dbc Display real ethernet address.
Florian Pose <fp@igh-essen.com>
parents: 1150
diff changeset
   191
                master->backup_device.dev->dev_addr, ETH_ALEN); 
51a8b41d3dbc Display real ethernet address.
Florian Pose <fp@igh-essen.com>
parents: 1150
diff changeset
   192
    } else {
51a8b41d3dbc Display real ethernet address.
Florian Pose <fp@igh-essen.com>
parents: 1150
diff changeset
   193
        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
   194
    }
1079
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   195
    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
   196
    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
   197
    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
   198
    data.devices[1].rx_count = master->backup_device.rx_count;
1415
9d1cdbf41247 Output reference clock and application time in 'ethercat Master'.
Florian Pose <fp@igh-essen.com>
parents: 1413
diff changeset
   199
1079
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   200
    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
   201
1415
9d1cdbf41247 Output reference clock and application time in 'ethercat Master'.
Florian Pose <fp@igh-essen.com>
parents: 1413
diff changeset
   202
    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
   203
    data.ref_clock =
f1df39224f49 Take ref clock address from dc_ref_clock pointer.
Florian Pose <fp@igh-essen.com>
parents: 1434
diff changeset
   204
        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
   205
1079
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   206
    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
   207
        return -EFAULT;
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   208
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   209
    return 0;
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   210
}
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   211
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   212
/*****************************************************************************/
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   213
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   214
/** Get slave information.
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   215
 */
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   216
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
   217
        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
   218
        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
   219
        )
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   220
{
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   221
    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
   222
    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
   223
    int i;
1079
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   224
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   225
    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
   226
        return -EFAULT;
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   227
    }
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   228
1189
acc6430bfb32 Use down_interruptible() wherever possible.
Florian Pose <fp@igh-essen.com>
parents: 1183
diff changeset
   229
    if (down_interruptible(&master->master_sem))
acc6430bfb32 Use down_interruptible() wherever possible.
Florian Pose <fp@igh-essen.com>
parents: 1183
diff changeset
   230
        return -EINTR;
1079
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   231
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   232
    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
   233
                    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
   234
        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
   235
        EC_ERR("Slave %u does not exist!\n", data.position);
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   236
        return -EINVAL;
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   237
    }
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   238
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   239
    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
   240
    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
   241
    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
   242
    data.serial_number = slave->sii.serial_number;
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   243
    data.alias = slave->sii.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
   244
    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
   245
    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
   246
    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
   247
    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
   248
    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
   249
    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
   250
    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
   251
    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
   252
    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
   253
    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
   254
    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
   255
    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
   256
    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
   257
    for (i = 0; i < EC_MAX_PORTS; i++) {
1425
c1322a8793c0 Transition delay calculation. TBC...
Florian Pose <fp@igh-essen.com>
parents: 1421
diff changeset
   258
        data.ports[i].desc = slave->ports[i].desc;
c1322a8793c0 Transition delay calculation. TBC...
Florian Pose <fp@igh-essen.com>
parents: 1421
diff changeset
   259
        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
   260
        data.ports[i].link.loop_closed = slave->ports[i].link.loop_closed;
c1322a8793c0 Transition delay calculation. TBC...
Florian Pose <fp@igh-essen.com>
parents: 1421
diff changeset
   261
        data.ports[i].link.signal_detected = slave->ports[i].link.signal_detected;
c1322a8793c0 Transition delay calculation. TBC...
Florian Pose <fp@igh-essen.com>
parents: 1421
diff changeset
   262
        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
   263
        if (slave->ports[i].next_slave) {
c1322a8793c0 Transition delay calculation. TBC...
Florian Pose <fp@igh-essen.com>
parents: 1421
diff changeset
   264
            data.ports[i].next_slave = slave->ports[i].next_slave->ring_position;
1421
043a518831b2 Bus topology calculation.
Florian Pose <fp@igh-essen.com>
parents: 1420
diff changeset
   265
        } else {
1425
c1322a8793c0 Transition delay calculation. TBC...
Florian Pose <fp@igh-essen.com>
parents: 1421
diff changeset
   266
            data.ports[i].next_slave = 0xffff;
1421
043a518831b2 Bus topology calculation.
Florian Pose <fp@igh-essen.com>
parents: 1420
diff changeset
   267
        }
1425
c1322a8793c0 Transition delay calculation. TBC...
Florian Pose <fp@igh-essen.com>
parents: 1421
diff changeset
   268
        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
   269
    }
cbceb0e2f2a0 Reading more base information (incl. whether DC supported).
Florian Pose <fp@igh-essen.com>
parents: 1363
diff changeset
   270
    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
   271
    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
   272
    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
   273
    data.has_dc_system_time = slave->has_dc_system_time;
1426
af45bba80d85 Transition->Transmission.
Florian Pose <fp@igh-essen.com>
parents: 1425
diff changeset
   274
    data.transmission_delay = slave->transmission_delay;
1148
1762296870bd Renamed state field to al_state.
Florian Pose <fp@igh-essen.com>
parents: 1147
diff changeset
   275
    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
   276
    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
   277
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   278
    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
   279
    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
   280
    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
   281
    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
   282
    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
   283
    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
   284
    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
   285
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   286
    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
   287
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   288
    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
   289
        return -EFAULT;
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   290
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   291
    return 0;
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   292
}
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   293
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   294
/*****************************************************************************/
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   295
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   296
/** 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
   297
 */
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   298
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
   299
        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
   300
        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
   301
        )
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   302
{
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   303
    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
   304
    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
   305
    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
   306
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   307
    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
   308
        return -EFAULT;
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   309
    }
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   310
1189
acc6430bfb32 Use down_interruptible() wherever possible.
Florian Pose <fp@igh-essen.com>
parents: 1183
diff changeset
   311
    if (down_interruptible(&master->master_sem))
acc6430bfb32 Use down_interruptible() wherever possible.
Florian Pose <fp@igh-essen.com>
parents: 1183
diff changeset
   312
        return -EINTR;
1079
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   313
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   314
    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
   315
                    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
   316
        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
   317
        EC_ERR("Slave %u does not exist!\n", data.slave_position);
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   318
        return -EINVAL;
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   319
    }
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   320
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   321
    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
   322
        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
   323
        EC_ERR("Sync manager %u does not exist in slave %u!\n",
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   324
                data.sync_index, data.slave_position);
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   325
        return -EINVAL;
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   326
    }
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   327
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   328
    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
   329
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   330
    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
   331
    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
   332
    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
   333
    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
   334
    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
   335
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   336
    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
   337
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   338
    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
   339
        return -EFAULT;
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
    return 0;
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   342
}
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
/*****************************************************************************/
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   345
1327
4d179b06dd3c merge -c1604 branches/stable-1.4: Fixed spelling of EtherCAT terms.
Florian Pose <fp@igh-essen.com>
parents: 1326
diff changeset
   346
/** 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
   347
 */
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   348
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
   349
        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
   350
        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
   351
        )
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   352
{
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   353
    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
   354
    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
   355
    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
   356
    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
   357
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   358
    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
   359
        return -EFAULT;
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   360
    }
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   361
1189
acc6430bfb32 Use down_interruptible() wherever possible.
Florian Pose <fp@igh-essen.com>
parents: 1183
diff changeset
   362
    if (down_interruptible(&master->master_sem))
acc6430bfb32 Use down_interruptible() wherever possible.
Florian Pose <fp@igh-essen.com>
parents: 1183
diff changeset
   363
        return -EINTR;
1079
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   364
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   365
    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
   366
                    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
   367
        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
   368
        EC_ERR("Slave %u does not exist!\n", 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
        return -EINVAL;
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   370
    }
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   371
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   372
    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
   373
        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
   374
        EC_ERR("Sync manager %u does not exist in slave %u!\n",
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   375
                data.sync_index, data.slave_position);
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   376
        return -EINVAL;
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   377
    }
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   378
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   379
    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
   380
    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
   381
                    &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
   382
        up(&master->master_sem);
1327
4d179b06dd3c merge -c1604 branches/stable-1.4: Fixed spelling of EtherCAT terms.
Florian Pose <fp@igh-essen.com>
parents: 1326
diff changeset
   383
        EC_ERR("Sync manager %u does not contain a PDO with "
1079
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   384
                "position %u in slave %u!\n", data.sync_index,
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   385
                data.pdo_pos, data.slave_position);
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   386
        return -EINVAL;
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   387
    }
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   388
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   389
    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
   390
    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
   391
    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
   392
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   393
    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
   394
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   395
    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
   396
        return -EFAULT;
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
    return 0;
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   399
}
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   400
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
1327
4d179b06dd3c merge -c1604 branches/stable-1.4: Fixed spelling of EtherCAT terms.
Florian Pose <fp@igh-essen.com>
parents: 1326
diff changeset
   403
/** 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
   404
 */
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   405
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
   406
        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
   407
        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
   408
        )
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   409
{
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   410
    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
   411
    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
   412
    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
   413
    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
   414
    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
   415
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   416
    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
   417
        return -EFAULT;
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
1189
acc6430bfb32 Use down_interruptible() wherever possible.
Florian Pose <fp@igh-essen.com>
parents: 1183
diff changeset
   420
    if (down_interruptible(&master->master_sem))
acc6430bfb32 Use down_interruptible() wherever possible.
Florian Pose <fp@igh-essen.com>
parents: 1183
diff changeset
   421
        return -EINTR;
1079
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   422
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   423
    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
   424
                    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
   425
        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
   426
        EC_ERR("Slave %u does not exist!\n", data.slave_position);
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   427
        return -EINVAL;
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   428
    }
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   429
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   430
    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
   431
        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
   432
        EC_ERR("Sync manager %u does not exist in slave %u!\n",
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   433
                data.sync_index, data.slave_position);
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   434
        return -EINVAL;
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   435
    }
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   436
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   437
    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
   438
    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
   439
                    &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
   440
        up(&master->master_sem);
1327
4d179b06dd3c merge -c1604 branches/stable-1.4: Fixed spelling of EtherCAT terms.
Florian Pose <fp@igh-essen.com>
parents: 1326
diff changeset
   441
        EC_ERR("Sync manager %u does not contain a PDO with "
1079
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   442
                "position %u in slave %u!\n", data.sync_index,
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   443
                data.pdo_pos, data.slave_position);
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   444
        return -EINVAL;
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   445
    }
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
    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
   448
                    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
   449
        up(&master->master_sem);
1327
4d179b06dd3c merge -c1604 branches/stable-1.4: Fixed spelling of EtherCAT terms.
Florian Pose <fp@igh-essen.com>
parents: 1326
diff changeset
   450
        EC_ERR("PDO 0x%04X does not contain an entry with "
1079
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   451
                "position %u in slave %u!\n", data.pdo_pos,
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   452
                data.entry_pos, data.slave_position);
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   453
        return -EINVAL;
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
    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
   457
    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
   458
    data.bit_length = entry->bit_length;
1108
7beba3e7e6b4 Added ec_cdev_strcpy() function.
Florian Pose <fp@igh-essen.com>
parents: 1092
diff changeset
   459
    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
   460
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   461
    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
   462
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   463
    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
   464
        return -EFAULT;
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   465
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   466
    return 0;
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   467
}
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   468
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
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   471
/** Get domain information.
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
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
   474
        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
   475
        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
   476
        )
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   477
{
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   478
    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
   479
    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
   480
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   481
    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
   482
        return -EFAULT;
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
1189
acc6430bfb32 Use down_interruptible() wherever possible.
Florian Pose <fp@igh-essen.com>
parents: 1183
diff changeset
   485
    if (down_interruptible(&master->master_sem))
acc6430bfb32 Use down_interruptible() wherever possible.
Florian Pose <fp@igh-essen.com>
parents: 1183
diff changeset
   486
        return -EINTR;
1079
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   487
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   488
    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
   489
        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
   490
        EC_ERR("Domain %u does not exist!\n", data.index);
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   491
        return -EINVAL;
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   492
    }
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   493
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   494
    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
   495
    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
   496
    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
   497
    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
   498
    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
   499
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   500
    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
   501
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   502
    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
   503
        return -EFAULT;
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   504
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   505
    return 0;
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   506
}
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
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   510
/** 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
   511
 */
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   512
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
   513
        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
   514
        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
   515
        )
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   516
{
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   517
    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
   518
    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
   519
    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
   520
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   521
    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
   522
        return -EFAULT;
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
1189
acc6430bfb32 Use down_interruptible() wherever possible.
Florian Pose <fp@igh-essen.com>
parents: 1183
diff changeset
   525
    if (down_interruptible(&master->master_sem))
acc6430bfb32 Use down_interruptible() wherever possible.
Florian Pose <fp@igh-essen.com>
parents: 1183
diff changeset
   526
        return -EINTR;
1079
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   527
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   528
    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
   529
        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
   530
        EC_ERR("Domain %u does not exist!\n", data.domain_index);
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   531
        return -EINVAL;
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   532
    }
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 (!(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
   535
        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
   536
        EC_ERR("Domain %u has less than %u fmmu configurations.\n",
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   537
                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
   538
        return -EINVAL;
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   539
    }
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
    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
   542
    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
   543
    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
   544
    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
   545
    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
   546
    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
   547
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   548
    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
   549
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   550
    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
   551
        return -EFAULT;
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
    return 0;
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
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   556
/*****************************************************************************/
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
/** Get domain data.
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
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
   561
        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
   562
        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
   563
        )
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
    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
   566
    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
   567
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   568
    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
   569
        return -EFAULT;
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   570
    }
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   571
1189
acc6430bfb32 Use down_interruptible() wherever possible.
Florian Pose <fp@igh-essen.com>
parents: 1183
diff changeset
   572
    if (down_interruptible(&master->master_sem))
acc6430bfb32 Use down_interruptible() wherever possible.
Florian Pose <fp@igh-essen.com>
parents: 1183
diff changeset
   573
        return -EINTR;
1079
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   574
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   575
    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
   576
        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
   577
        EC_ERR("Domain %u does not exist!\n", data.domain_index);
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   578
        return -EINVAL;
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   579
    }
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->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
   582
        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
   583
        EC_ERR("Data size mismatch %u/%u!\n",
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   584
                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
   585
        return -EFAULT;
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 (copy_to_user((void __user *) data.target, domain->data,
1223
6d539205114e Added missing up().
Florian Pose <fp@igh-essen.com>
parents: 1209
diff changeset
   589
                domain->data_size)) {
6d539205114e Added missing up().
Florian Pose <fp@igh-essen.com>
parents: 1209
diff changeset
   590
        up(&master->master_sem);
6d539205114e Added missing up().
Florian Pose <fp@igh-essen.com>
parents: 1209
diff changeset
   591
        return -EFAULT;
6d539205114e Added missing up().
Florian Pose <fp@igh-essen.com>
parents: 1209
diff changeset
   592
    }
1079
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   593
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   594
    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
   595
    return 0;
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   596
}
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   597
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   598
/*****************************************************************************/
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   599
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   600
/** 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
   601
 */
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   602
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
   603
        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
   604
        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
   605
        )
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   606
{
1313
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1312
diff changeset
   607
    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
   608
}
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
/** Set slave state.
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   613
 */
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   614
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
   615
        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
   616
        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
   617
        )
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
    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
   620
    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
   621
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   622
    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
   623
        return -EFAULT;
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   624
    }
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   625
1189
acc6430bfb32 Use down_interruptible() wherever possible.
Florian Pose <fp@igh-essen.com>
parents: 1183
diff changeset
   626
    if (down_interruptible(&master->master_sem))
acc6430bfb32 Use down_interruptible() wherever possible.
Florian Pose <fp@igh-essen.com>
parents: 1183
diff changeset
   627
        return -EINTR;
1079
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   628
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   629
    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
   630
                    master, 0, data.slave_position))) {
1196
a27966f01b72 Fixed missing up().
Florian Pose <fp@igh-essen.com>
parents: 1189
diff changeset
   631
        up(&master->master_sem);
1079
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   632
        EC_ERR("Slave %u does not exist!\n", data.slave_position);
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   633
        return -EINVAL;
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   634
    }
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   635
1150
c589b54ade01 Fixed requested_state.
Florian Pose <fp@igh-essen.com>
parents: 1148
diff changeset
   636
    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
   637
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);
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   639
    return 0;
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   640
}
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   641
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
1327
4d179b06dd3c merge -c1604 branches/stable-1.4: Fixed spelling of EtherCAT terms.
Florian Pose <fp@igh-essen.com>
parents: 1326
diff changeset
   644
/** 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
   645
 */
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   646
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
   647
        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
   648
        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
   649
        )
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   650
{
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   651
    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
   652
    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
   653
    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
   654
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   655
    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
   656
        return -EFAULT;
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
1189
acc6430bfb32 Use down_interruptible() wherever possible.
Florian Pose <fp@igh-essen.com>
parents: 1183
diff changeset
   659
    if (down_interruptible(&master->master_sem))
acc6430bfb32 Use down_interruptible() wherever possible.
Florian Pose <fp@igh-essen.com>
parents: 1183
diff changeset
   660
        return -EINTR;
1079
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
    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
   663
                    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
   664
        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
   665
        EC_ERR("Slave %u does not exist!\n", data.slave_position);
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   666
        return -EINVAL;
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   667
    }
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   668
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   669
    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
   670
                    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
   671
        up(&master->master_sem);
1327
4d179b06dd3c merge -c1604 branches/stable-1.4: Fixed spelling of EtherCAT terms.
Florian Pose <fp@igh-essen.com>
parents: 1326
diff changeset
   672
        EC_ERR("SDO %u does not exist in slave %u!\n",
1079
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   673
                data.sdo_position, data.slave_position);
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   674
        return -EINVAL;
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   675
    }
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   676
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   677
    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
   678
    data.max_subindex = sdo->max_subindex;
1108
7beba3e7e6b4 Added ec_cdev_strcpy() function.
Florian Pose <fp@igh-essen.com>
parents: 1092
diff changeset
   679
    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
   680
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   681
    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
   682
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   683
    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
   684
        return -EFAULT;
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   685
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   686
    return 0;
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
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   689
/*****************************************************************************/
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   690
1327
4d179b06dd3c merge -c1604 branches/stable-1.4: Fixed spelling of EtherCAT terms.
Florian Pose <fp@igh-essen.com>
parents: 1326
diff changeset
   691
/** 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
   692
 */
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   693
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
   694
        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
   695
        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
   696
        )
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
    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
   699
    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
   700
    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
   701
    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
   702
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   703
    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
   704
        return -EFAULT;
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   705
    }
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   706
1189
acc6430bfb32 Use down_interruptible() wherever possible.
Florian Pose <fp@igh-essen.com>
parents: 1183
diff changeset
   707
    if (down_interruptible(&master->master_sem))
acc6430bfb32 Use down_interruptible() wherever possible.
Florian Pose <fp@igh-essen.com>
parents: 1183
diff changeset
   708
        return -EINTR;
1079
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   709
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   710
    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
   711
                    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
   712
        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
   713
        EC_ERR("Slave %u does not exist!\n", data.slave_position);
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   714
        return -EINVAL;
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
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   717
    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
   718
        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
   719
                        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
   720
            up(&master->master_sem);
1327
4d179b06dd3c merge -c1604 branches/stable-1.4: Fixed spelling of EtherCAT terms.
Florian Pose <fp@igh-essen.com>
parents: 1326
diff changeset
   721
            EC_ERR("SDO %u does not exist in slave %u!\n",
1079
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   722
                    -data.sdo_spec, data.slave_position);
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   723
            return -EINVAL;
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
    } else {
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   726
        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
   727
                        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
   728
            up(&master->master_sem);
1327
4d179b06dd3c merge -c1604 branches/stable-1.4: Fixed spelling of EtherCAT terms.
Florian Pose <fp@igh-essen.com>
parents: 1326
diff changeset
   729
            EC_ERR("SDO 0x%04X does not exist in slave %u!\n",
1079
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   730
                    data.sdo_spec, data.slave_position);
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   731
            return -EINVAL;
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   732
        }
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   733
    }
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   734
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   735
    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
   736
                    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
   737
        up(&master->master_sem);
1327
4d179b06dd3c merge -c1604 branches/stable-1.4: Fixed spelling of EtherCAT terms.
Florian Pose <fp@igh-essen.com>
parents: 1326
diff changeset
   738
        EC_ERR("SDO entry 0x%04X:%02X does not exist "
1079
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   739
                "in slave %u!\n", sdo->index,
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   740
                data.sdo_entry_subindex, data.slave_position);
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   741
        return -EINVAL;
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   742
    }
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   743
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   744
    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
   745
    data.bit_length = entry->bit_length;
1382
cb2188d111f3 Read SDO entry access rights.
Florian Pose <fp@igh-essen.com>
parents: 1381
diff changeset
   746
    data.read_access[EC_SDO_ENTRY_ACCESS_PREOP] =
cb2188d111f3 Read SDO entry access rights.
Florian Pose <fp@igh-essen.com>
parents: 1381
diff changeset
   747
        entry->read_access[EC_SDO_ENTRY_ACCESS_PREOP];
cb2188d111f3 Read SDO entry access rights.
Florian Pose <fp@igh-essen.com>
parents: 1381
diff changeset
   748
    data.read_access[EC_SDO_ENTRY_ACCESS_SAFEOP] =
cb2188d111f3 Read SDO entry access rights.
Florian Pose <fp@igh-essen.com>
parents: 1381
diff changeset
   749
        entry->read_access[EC_SDO_ENTRY_ACCESS_SAFEOP];
cb2188d111f3 Read SDO entry access rights.
Florian Pose <fp@igh-essen.com>
parents: 1381
diff changeset
   750
    data.read_access[EC_SDO_ENTRY_ACCESS_OP] =
cb2188d111f3 Read SDO entry access rights.
Florian Pose <fp@igh-essen.com>
parents: 1381
diff changeset
   751
        entry->read_access[EC_SDO_ENTRY_ACCESS_OP];
cb2188d111f3 Read SDO entry access rights.
Florian Pose <fp@igh-essen.com>
parents: 1381
diff changeset
   752
    data.write_access[EC_SDO_ENTRY_ACCESS_PREOP] =
cb2188d111f3 Read SDO entry access rights.
Florian Pose <fp@igh-essen.com>
parents: 1381
diff changeset
   753
        entry->write_access[EC_SDO_ENTRY_ACCESS_PREOP];
cb2188d111f3 Read SDO entry access rights.
Florian Pose <fp@igh-essen.com>
parents: 1381
diff changeset
   754
    data.write_access[EC_SDO_ENTRY_ACCESS_SAFEOP] =
cb2188d111f3 Read SDO entry access rights.
Florian Pose <fp@igh-essen.com>
parents: 1381
diff changeset
   755
        entry->write_access[EC_SDO_ENTRY_ACCESS_SAFEOP];
cb2188d111f3 Read SDO entry access rights.
Florian Pose <fp@igh-essen.com>
parents: 1381
diff changeset
   756
    data.write_access[EC_SDO_ENTRY_ACCESS_OP] =
cb2188d111f3 Read SDO entry access rights.
Florian Pose <fp@igh-essen.com>
parents: 1381
diff changeset
   757
        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
   758
    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
   759
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   760
    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
   761
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   762
    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
   763
        return -EFAULT;
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   764
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   765
    return 0;
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
/*****************************************************************************/
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   769
1327
4d179b06dd3c merge -c1604 branches/stable-1.4: Fixed spelling of EtherCAT terms.
Florian Pose <fp@igh-essen.com>
parents: 1326
diff changeset
   770
/** Upload SDO.
1079
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   771
 */
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   772
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
   773
        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
   774
        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
   775
        )
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   776
{
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   777
    ec_ioctl_slave_sdo_upload_t data;
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   778
    ec_master_sdo_request_t request;
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   779
    int retval;
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   780
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   781
    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
   782
        return -EFAULT;
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   783
    }
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   784
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   785
    ec_sdo_request_init(&request.req);
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   786
    ec_sdo_request_address(&request.req,
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   787
            data.sdo_index, 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
   788
    ecrt_sdo_request_read(&request.req);
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   789
1189
acc6430bfb32 Use down_interruptible() wherever possible.
Florian Pose <fp@igh-essen.com>
parents: 1183
diff changeset
   790
    if (down_interruptible(&master->master_sem))
acc6430bfb32 Use down_interruptible() wherever possible.
Florian Pose <fp@igh-essen.com>
parents: 1183
diff changeset
   791
        return -EINTR;
1079
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   792
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   793
    if (!(request.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
   794
                    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
   795
        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
   796
        ec_sdo_request_clear(&request.req);
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   797
        EC_ERR("Slave %u does not exist!\n", data.slave_position);
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   798
        return -EINVAL;
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   799
    }
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   800
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   801
    // schedule request.
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   802
    list_add_tail(&request.list, &master->slave_sdo_requests);
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
    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
   805
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   806
    // 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
   807
    if (wait_event_interruptible(master->sdo_queue,
1209
8be462afb7f4 Added VoE handler.
Florian Pose <fp@igh-essen.com>
parents: 1200
diff changeset
   808
                request.req.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
   809
        // interrupted by signal
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   810
        down(&master->master_sem);
1209
8be462afb7f4 Added VoE handler.
Florian Pose <fp@igh-essen.com>
parents: 1200
diff changeset
   811
        if (request.req.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
   812
            list_del(&request.req.list);
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   813
            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
   814
            ec_sdo_request_clear(&request.req);
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   815
            return -EINTR;
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   816
        }
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   817
        // request already processing: interrupt not possible.
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   818
        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
   819
    }
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   820
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   821
    // wait until master FSM has finished processing
1209
8be462afb7f4 Added VoE handler.
Florian Pose <fp@igh-essen.com>
parents: 1200
diff changeset
   822
    wait_event(master->sdo_queue, request.req.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
   823
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   824
    data.abort_code = request.req.abort_code;
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   825
1209
8be462afb7f4 Added VoE handler.
Florian Pose <fp@igh-essen.com>
parents: 1200
diff changeset
   826
    if (request.req.state != EC_INT_REQUEST_SUCCESS) {
1079
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   827
        data.data_size = 0;
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   828
        retval = -EIO;
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   829
    } else {
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   830
        if (request.req.data_size > data.target_size) {
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   831
            EC_ERR("Buffer too small.\n");
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   832
            ec_sdo_request_clear(&request.req);
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   833
            return -EOVERFLOW;
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   834
        }
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   835
        data.data_size = request.req.data_size;
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
        if (copy_to_user((void __user *) data.target,
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   838
                    request.req.data, data.data_size)) {
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   839
            ec_sdo_request_clear(&request.req);
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   840
            return -EFAULT;
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   841
        }
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   842
        retval = 0;
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   843
    }
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
    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
   846
        retval = -EFAULT;
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   847
    }
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   848
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   849
    ec_sdo_request_clear(&request.req);
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   850
    return retval;
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   851
}
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
/*****************************************************************************/
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   854
1327
4d179b06dd3c merge -c1604 branches/stable-1.4: Fixed spelling of EtherCAT terms.
Florian Pose <fp@igh-essen.com>
parents: 1326
diff changeset
   855
/** Download SDO.
1079
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   856
 */
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   857
int ec_cdev_ioctl_slave_sdo_download(
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   858
        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
   859
        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
   860
        )
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   861
{
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   862
    ec_ioctl_slave_sdo_download_t data;
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   863
    ec_master_sdo_request_t request;
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   864
    int retval;
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   865
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   866
    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
   867
        return -EFAULT;
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   868
    }
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   869
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   870
    // copy data to download
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   871
    if (!data.data_size) {
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   872
        EC_ERR("Zero data size!\n");
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   873
        return -EINVAL;
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   874
    }
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   875
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   876
    ec_sdo_request_init(&request.req);
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   877
    ec_sdo_request_address(&request.req,
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   878
            data.sdo_index, 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
   879
    if (ec_sdo_request_alloc(&request.req, data.data_size)) {
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   880
        ec_sdo_request_clear(&request.req);
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   881
        return -ENOMEM;
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   882
    }
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   883
    if (copy_from_user(request.req.data,
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   884
                (void __user *) data.data, data.data_size)) {
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   885
        ec_sdo_request_clear(&request.req);
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   886
        return -EFAULT;
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   887
    }
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   888
    request.req.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
   889
    ecrt_sdo_request_write(&request.req);
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   890
1189
acc6430bfb32 Use down_interruptible() wherever possible.
Florian Pose <fp@igh-essen.com>
parents: 1183
diff changeset
   891
    if (down_interruptible(&master->master_sem))
acc6430bfb32 Use down_interruptible() wherever possible.
Florian Pose <fp@igh-essen.com>
parents: 1183
diff changeset
   892
        return -EINTR;
1079
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   893
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   894
    if (!(request.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
   895
                    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
   896
        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
   897
        EC_ERR("Slave %u does not exist!\n", data.slave_position);
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   898
        ec_sdo_request_clear(&request.req);
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   899
        return -EINVAL;
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   900
    }
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   901
    
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   902
    // schedule request.
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   903
    list_add_tail(&request.list, &master->slave_sdo_requests);
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   904
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   905
    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
   906
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   907
    // 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
   908
    if (wait_event_interruptible(master->sdo_queue,
1209
8be462afb7f4 Added VoE handler.
Florian Pose <fp@igh-essen.com>
parents: 1200
diff changeset
   909
                request.req.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
   910
        // interrupted by signal
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   911
        down(&master->master_sem);
1209
8be462afb7f4 Added VoE handler.
Florian Pose <fp@igh-essen.com>
parents: 1200
diff changeset
   912
        if (request.req.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
   913
            list_del(&request.req.list);
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   914
            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
   915
            ec_sdo_request_clear(&request.req);
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   916
            return -EINTR;
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   917
        }
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   918
        // request already processing: interrupt not possible.
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   919
        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
   920
    }
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   921
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   922
    // wait until master FSM has finished processing
1209
8be462afb7f4 Added VoE handler.
Florian Pose <fp@igh-essen.com>
parents: 1200
diff changeset
   923
    wait_event(master->sdo_queue, request.req.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
   924
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   925
    data.abort_code = request.req.abort_code;
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   926
1209
8be462afb7f4 Added VoE handler.
Florian Pose <fp@igh-essen.com>
parents: 1200
diff changeset
   927
    retval = request.req.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
   928
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   929
    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
   930
        retval = -EFAULT;
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   931
    }
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   932
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   933
    ec_sdo_request_clear(&request.req);
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   934
    return retval;
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
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   937
/*****************************************************************************/
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   938
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   939
/** 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
   940
 */
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   941
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
   942
        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
   943
        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
   944
        )
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   945
{
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   946
    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
   947
    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
   948
    int retval;
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   949
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   950
    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
   951
        return -EFAULT;
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   952
    }
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   953
1189
acc6430bfb32 Use down_interruptible() wherever possible.
Florian Pose <fp@igh-essen.com>
parents: 1183
diff changeset
   954
    if (down_interruptible(&master->master_sem))
acc6430bfb32 Use down_interruptible() wherever possible.
Florian Pose <fp@igh-essen.com>
parents: 1183
diff changeset
   955
        return -EINTR;
1079
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   956
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   957
    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
   958
                    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
   959
        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
   960
        EC_ERR("Slave %u does not exist!\n", data.slave_position);
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   961
        return -EINVAL;
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
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   964
    if (!data.nwords
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   965
            || 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
   966
        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
   967
        EC_ERR("Invalid SII read offset/size %u/%u for slave "
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   968
                "SII size %u!\n", data.offset,
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   969
                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
   970
        return -EINVAL;
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
    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
   974
                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
   975
        retval = -EFAULT;
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   976
    else
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   977
        retval = 0;
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   978
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   979
    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
   980
    return retval;
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
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   983
/*****************************************************************************/
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   984
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   985
/** 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
   986
 */
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   987
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
   988
        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
   989
        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
   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
    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
   993
    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
   994
    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
   995
    uint16_t *words;
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   996
    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
   997
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   998
    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
   999
        return -EFAULT;
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 (!data.nwords)
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1003
        return 0;
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1004
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1005
    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
  1006
    if (!(words = kmalloc(byte_size, GFP_KERNEL))) {
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1007
        EC_ERR("Failed to allocate %u bytes for SII contents.\n",
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1008
                byte_size);
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1009
        return -ENOMEM;
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
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1012
    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
  1013
                (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
  1014
        kfree(words);
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1015
        return -EFAULT;
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1016
    }
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1017
1189
acc6430bfb32 Use down_interruptible() wherever possible.
Florian Pose <fp@igh-essen.com>
parents: 1183
diff changeset
  1018
    if (down_interruptible(&master->master_sem))
acc6430bfb32 Use down_interruptible() wherever possible.
Florian Pose <fp@igh-essen.com>
parents: 1183
diff changeset
  1019
        return -EINTR;
1079
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1020
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1021
    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
  1022
                    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
  1023
        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
  1024
        EC_ERR("Slave %u does not exist!\n", data.slave_position);
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1025
        kfree(words);
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1026
        return -EINVAL;
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
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1029
    // 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
  1030
    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
  1031
    request.slave = slave;
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1032
    request.words = words;
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1033
    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
  1034
    request.nwords = data.nwords;
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
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1037
    // 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
  1038
    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
  1039
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1040
    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
  1041
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1042
    // 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
  1043
    if (wait_event_interruptible(master->sii_queue,
1209
8be462afb7f4 Added VoE handler.
Florian Pose <fp@igh-essen.com>
parents: 1200
diff changeset
  1044
                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
  1045
        // interrupted by signal
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1046
        down(&master->master_sem);
1209
8be462afb7f4 Added VoE handler.
Florian Pose <fp@igh-essen.com>
parents: 1200
diff changeset
  1047
        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
  1048
            // abort request
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1049
            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
  1050
            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
  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
            return -EINTR;
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1053
        }
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1054
        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
  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
    // wait until master FSM has finished processing
1209
8be462afb7f4 Added VoE handler.
Florian Pose <fp@igh-essen.com>
parents: 1200
diff changeset
  1058
    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
  1059
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1060
    kfree(words);
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1061
1209
8be462afb7f4 Added VoE handler.
Florian Pose <fp@igh-essen.com>
parents: 1200
diff changeset
  1062
    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
  1063
}
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1064
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1065
/*****************************************************************************/
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1066
1388
3c886ec376f5 Renamed phy_ commands to reg_.
Florian Pose <fp@igh-essen.com>
parents: 1382
diff changeset
  1067
/** Read a slave's registers.
3c886ec376f5 Renamed phy_ commands to reg_.
Florian Pose <fp@igh-essen.com>
parents: 1382
diff changeset
  1068
 */
3c886ec376f5 Renamed phy_ commands to reg_.
Florian Pose <fp@igh-essen.com>
parents: 1382
diff changeset
  1069
int ec_cdev_ioctl_slave_reg_read(
1200
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1196
diff changeset
  1070
        ec_master_t *master, /**< EtherCAT master. */
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1196
diff changeset
  1071
        unsigned long arg /**< ioctl() argument. */
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
{
1388
3c886ec376f5 Renamed phy_ commands to reg_.
Florian Pose <fp@igh-essen.com>
parents: 1382
diff changeset
  1074
    ec_ioctl_slave_reg_t data;
1200
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1196
diff changeset
  1075
    ec_slave_t *slave;
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1196
diff changeset
  1076
    uint8_t *contents;
1388
3c886ec376f5 Renamed phy_ commands to reg_.
Florian Pose <fp@igh-essen.com>
parents: 1382
diff changeset
  1077
    ec_reg_request_t request;
1200
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1196
diff changeset
  1078
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1196
diff changeset
  1079
    if (copy_from_user(&data, (void __user *) arg, sizeof(data))) {
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1196
diff changeset
  1080
        return -EFAULT;
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 (!data.length)
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1196
diff changeset
  1084
        return 0;
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 (!(contents = kmalloc(data.length, GFP_KERNEL))) {
1388
3c886ec376f5 Renamed phy_ commands to reg_.
Florian Pose <fp@igh-essen.com>
parents: 1382
diff changeset
  1087
        EC_ERR("Failed to allocate %u bytes for register data.\n", data.length);
1200
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1196
diff changeset
  1088
        return -ENOMEM;
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1196
diff changeset
  1089
    }
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1196
diff changeset
  1090
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1196
diff changeset
  1091
    if (down_interruptible(&master->master_sem))
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1196
diff changeset
  1092
        return -EINTR;
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1196
diff changeset
  1093
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1196
diff changeset
  1094
    if (!(slave = ec_master_find_slave(
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1196
diff changeset
  1095
                    master, 0, data.slave_position))) {
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1196
diff changeset
  1096
        up(&master->master_sem);
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1196
diff changeset
  1097
        EC_ERR("Slave %u does not exist!\n", data.slave_position);
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1196
diff changeset
  1098
        return -EINVAL;
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1196
diff changeset
  1099
    }
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1196
diff changeset
  1100
1388
3c886ec376f5 Renamed phy_ commands to reg_.
Florian Pose <fp@igh-essen.com>
parents: 1382
diff changeset
  1101
    // init register request
1200
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1196
diff changeset
  1102
    INIT_LIST_HEAD(&request.list);
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1196
diff changeset
  1103
    request.slave = slave;
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1196
diff changeset
  1104
    request.dir = EC_DIR_INPUT;
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1196
diff changeset
  1105
    request.data = contents;
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1196
diff changeset
  1106
    request.offset = data.offset;
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1196
diff changeset
  1107
    request.length = data.length;
1209
8be462afb7f4 Added VoE handler.
Florian Pose <fp@igh-essen.com>
parents: 1200
diff changeset
  1108
    request.state = EC_INT_REQUEST_QUEUED;
1200
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1196
diff changeset
  1109
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1196
diff changeset
  1110
    // schedule request.
1388
3c886ec376f5 Renamed phy_ commands to reg_.
Florian Pose <fp@igh-essen.com>
parents: 1382
diff changeset
  1111
    list_add_tail(&request.list, &master->reg_requests);
1200
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1196
diff changeset
  1112
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1196
diff changeset
  1113
    up(&master->master_sem);
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1196
diff changeset
  1114
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1196
diff changeset
  1115
    // wait for processing through FSM
1388
3c886ec376f5 Renamed phy_ commands to reg_.
Florian Pose <fp@igh-essen.com>
parents: 1382
diff changeset
  1116
    if (wait_event_interruptible(master->reg_queue,
1209
8be462afb7f4 Added VoE handler.
Florian Pose <fp@igh-essen.com>
parents: 1200
diff changeset
  1117
                request.state != EC_INT_REQUEST_QUEUED)) {
1200
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1196
diff changeset
  1118
        // interrupted by signal
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1196
diff changeset
  1119
        down(&master->master_sem);
1209
8be462afb7f4 Added VoE handler.
Florian Pose <fp@igh-essen.com>
parents: 1200
diff changeset
  1120
        if (request.state == EC_INT_REQUEST_QUEUED) {
1200
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1196
diff changeset
  1121
            // abort request
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1196
diff changeset
  1122
            list_del(&request.list);
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1196
diff changeset
  1123
            up(&master->master_sem);
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1196
diff changeset
  1124
            kfree(contents);
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1196
diff changeset
  1125
            return -EINTR;
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1196
diff changeset
  1126
        }
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1196
diff changeset
  1127
        up(&master->master_sem);
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1196
diff changeset
  1128
    }
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
    // wait until master FSM has finished processing
1388
3c886ec376f5 Renamed phy_ commands to reg_.
Florian Pose <fp@igh-essen.com>
parents: 1382
diff changeset
  1131
    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
  1132
8be462afb7f4 Added VoE handler.
Florian Pose <fp@igh-essen.com>
parents: 1200
diff changeset
  1133
    if (request.state == EC_INT_REQUEST_SUCCESS) {
1200
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1196
diff changeset
  1134
        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
  1135
            return -EFAULT;
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1196
diff changeset
  1136
    }
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1196
diff changeset
  1137
    kfree(contents);
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1196
diff changeset
  1138
1209
8be462afb7f4 Added VoE handler.
Florian Pose <fp@igh-essen.com>
parents: 1200
diff changeset
  1139
    return request.state == EC_INT_REQUEST_SUCCESS ? 0 : -EIO;
1200
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1196
diff changeset
  1140
}
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1196
diff changeset
  1141
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
/** Write a slave's registers.
3c886ec376f5 Renamed phy_ commands to reg_.
Florian Pose <fp@igh-essen.com>
parents: 1382
diff changeset
  1145
 */
3c886ec376f5 Renamed phy_ commands to reg_.
Florian Pose <fp@igh-essen.com>
parents: 1382
diff changeset
  1146
int ec_cdev_ioctl_slave_reg_write(
1200
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1196
diff changeset
  1147
        ec_master_t *master, /**< EtherCAT master. */
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1196
diff changeset
  1148
        unsigned long arg /**< ioctl() argument. */
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1196
diff changeset
  1149
        )
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1196
diff changeset
  1150
{
1388
3c886ec376f5 Renamed phy_ commands to reg_.
Florian Pose <fp@igh-essen.com>
parents: 1382
diff changeset
  1151
    ec_ioctl_slave_reg_t data;
1200
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1196
diff changeset
  1152
    ec_slave_t *slave;
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1196
diff changeset
  1153
    uint8_t *contents;
1388
3c886ec376f5 Renamed phy_ commands to reg_.
Florian Pose <fp@igh-essen.com>
parents: 1382
diff changeset
  1154
    ec_reg_request_t request;
1200
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 (copy_from_user(&data, (void __user *) arg, sizeof(data))) {
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1196
diff changeset
  1157
        return -EFAULT;
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1196
diff changeset
  1158
    }
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1196
diff changeset
  1159
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1196
diff changeset
  1160
    if (!data.length)
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1196
diff changeset
  1161
        return 0;
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1196
diff changeset
  1162
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1196
diff changeset
  1163
    if (!(contents = kmalloc(data.length, GFP_KERNEL))) {
1388
3c886ec376f5 Renamed phy_ commands to reg_.
Florian Pose <fp@igh-essen.com>
parents: 1382
diff changeset
  1164
        EC_ERR("Failed to allocate %u bytes for register data.\n", data.length);
1200
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1196
diff changeset
  1165
        return -ENOMEM;
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
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1196
diff changeset
  1168
    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
  1169
        kfree(contents);
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1196
diff changeset
  1170
        return -EFAULT;
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1196
diff changeset
  1171
    }
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1196
diff changeset
  1172
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1196
diff changeset
  1173
    if (down_interruptible(&master->master_sem))
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1196
diff changeset
  1174
        return -EINTR;
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1196
diff changeset
  1175
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1196
diff changeset
  1176
    if (!(slave = ec_master_find_slave(
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1196
diff changeset
  1177
                    master, 0, data.slave_position))) {
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1196
diff changeset
  1178
        up(&master->master_sem);
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1196
diff changeset
  1179
        EC_ERR("Slave %u does not exist!\n", data.slave_position);
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1196
diff changeset
  1180
        kfree(contents);
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1196
diff changeset
  1181
        return -EINVAL;
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1196
diff changeset
  1182
    }
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1196
diff changeset
  1183
1388
3c886ec376f5 Renamed phy_ commands to reg_.
Florian Pose <fp@igh-essen.com>
parents: 1382
diff changeset
  1184
    // init register request
1200
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1196
diff changeset
  1185
    INIT_LIST_HEAD(&request.list);
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1196
diff changeset
  1186
    request.slave = slave;
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1196
diff changeset
  1187
    request.dir = EC_DIR_OUTPUT;
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1196
diff changeset
  1188
    request.data = contents;
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1196
diff changeset
  1189
    request.offset = data.offset;
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1196
diff changeset
  1190
    request.length = data.length;
1209
8be462afb7f4 Added VoE handler.
Florian Pose <fp@igh-essen.com>
parents: 1200
diff changeset
  1191
    request.state = EC_INT_REQUEST_QUEUED;
1200
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
    // schedule request.
1388
3c886ec376f5 Renamed phy_ commands to reg_.
Florian Pose <fp@igh-essen.com>
parents: 1382
diff changeset
  1194
    list_add_tail(&request.list, &master->reg_requests);
1200
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1196
diff changeset
  1195
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1196
diff changeset
  1196
    up(&master->master_sem);
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1196
diff changeset
  1197
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1196
diff changeset
  1198
    // wait for processing through FSM
1388
3c886ec376f5 Renamed phy_ commands to reg_.
Florian Pose <fp@igh-essen.com>
parents: 1382
diff changeset
  1199
    if (wait_event_interruptible(master->reg_queue,
1209
8be462afb7f4 Added VoE handler.
Florian Pose <fp@igh-essen.com>
parents: 1200
diff changeset
  1200
                request.state != EC_INT_REQUEST_QUEUED)) {
1200
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1196
diff changeset
  1201
        // interrupted by signal
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1196
diff changeset
  1202
        down(&master->master_sem);
1209
8be462afb7f4 Added VoE handler.
Florian Pose <fp@igh-essen.com>
parents: 1200
diff changeset
  1203
        if (request.state == EC_INT_REQUEST_QUEUED) {
1200
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1196
diff changeset
  1204
            // abort request
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1196
diff changeset
  1205
            list_del(&request.list);
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1196
diff changeset
  1206
            up(&master->master_sem);
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1196
diff changeset
  1207
            kfree(contents);
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1196
diff changeset
  1208
            return -EINTR;
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1196
diff changeset
  1209
        }
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1196
diff changeset
  1210
        up(&master->master_sem);
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1196
diff changeset
  1211
    }
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1196
diff changeset
  1212
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1196
diff changeset
  1213
    // wait until master FSM has finished processing
1388
3c886ec376f5 Renamed phy_ commands to reg_.
Florian Pose <fp@igh-essen.com>
parents: 1382
diff changeset
  1214
    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
  1215
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1196
diff changeset
  1216
    kfree(contents);
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1196
diff changeset
  1217
1209
8be462afb7f4 Added VoE handler.
Florian Pose <fp@igh-essen.com>
parents: 1200
diff changeset
  1218
    return request.state == EC_INT_REQUEST_SUCCESS ? 0 : -EIO;
1200
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1196
diff changeset
  1219
}
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1196
diff changeset
  1220
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1196
diff changeset
  1221
/*****************************************************************************/
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1196
diff changeset
  1222
1079
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1223
/** 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
  1224
 */
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1225
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
  1226
        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
  1227
        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
  1228
        )
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1229
{
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1230
    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
  1231
    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
  1232
    uint8_t i;
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1233
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1234
    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
  1235
        return -EFAULT;
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1236
    }
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1237
1189
acc6430bfb32 Use down_interruptible() wherever possible.
Florian Pose <fp@igh-essen.com>
parents: 1183
diff changeset
  1238
    if (down_interruptible(&master->master_sem))
acc6430bfb32 Use down_interruptible() wherever possible.
Florian Pose <fp@igh-essen.com>
parents: 1183
diff changeset
  1239
        return -EINTR;
1079
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1240
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1241
    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
  1242
                    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
  1243
        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
  1244
        EC_ERR("Slave config %u does not exist!\n",
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1245
                data.config_index);
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1246
        return -EINVAL;
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1247
    }
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1248
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1249
    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
  1250
    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
  1251
    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
  1252
    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
  1253
    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
  1254
        data.syncs[i].dir = sc->sync_configs[i].dir;
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1255
        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
  1256
            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
  1257
    }
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1258
    data.sdo_count = ec_slave_config_sdo_count(sc);
1147
0eac1ee8512a Show attached slave position and state in 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 1109
diff changeset
  1259
    data.slave_position = sc->slave ? sc->slave->ring_position : -1;
1079
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1260
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1261
    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
  1262
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1263
    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
  1264
        return -EFAULT;
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
    return 0;
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1267
}
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
/*****************************************************************************/
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1270
1327
4d179b06dd3c merge -c1604 branches/stable-1.4: Fixed spelling of EtherCAT terms.
Florian Pose <fp@igh-essen.com>
parents: 1326
diff changeset
  1271
/** 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
  1272
 */
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1273
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
  1274
        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
  1275
        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
  1276
        )
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1277
{
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1278
    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
  1279
    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
  1280
    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
  1281
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1282
    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
  1283
        return -EFAULT;
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
1082
ff06c58e269c Renamed ecrt_slave_config_sync_managers() to ecrt_slave_config_pdos();
Florian Pose <fp@igh-essen.com>
parents: 1079
diff changeset
  1286
    if (data.sync_index >= EC_MAX_SYNC_MANAGERS) {
1079
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1287
        EC_ERR("Invalid sync manager index %u!\n",
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1288
                data.sync_index);
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1289
        return -EINVAL;
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1290
    }
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1291
1189
acc6430bfb32 Use down_interruptible() wherever possible.
Florian Pose <fp@igh-essen.com>
parents: 1183
diff changeset
  1292
    if (down_interruptible(&master->master_sem))
acc6430bfb32 Use down_interruptible() wherever possible.
Florian Pose <fp@igh-essen.com>
parents: 1183
diff changeset
  1293
        return -EINTR;
1079
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1294
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1295
    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
  1296
                    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
  1297
        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
  1298
        EC_ERR("Slave config %u does not exist!\n",
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1299
                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
        return -EINVAL;
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1301
    }
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1302
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1303
    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
  1304
                    &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
  1305
                    data.pdo_pos))) {
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1306
        up(&master->master_sem);
1327
4d179b06dd3c merge -c1604 branches/stable-1.4: Fixed spelling of EtherCAT terms.
Florian Pose <fp@igh-essen.com>
parents: 1326
diff changeset
  1307
        EC_ERR("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
  1308
        return -EINVAL;
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1309
    }
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1310
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1311
    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
  1312
    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
  1313
    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
  1314
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1315
    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
  1316
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1317
    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
  1318
        return -EFAULT;
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
    return 0;
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1321
}
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
/*****************************************************************************/
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1324
1327
4d179b06dd3c merge -c1604 branches/stable-1.4: Fixed spelling of EtherCAT terms.
Florian Pose <fp@igh-essen.com>
parents: 1326
diff changeset
  1325
/** 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
  1326
 */
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1327
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
  1328
        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
  1329
        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
  1330
        )
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1331
{
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1332
    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
  1333
    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
  1334
    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
  1335
    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
  1336
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1337
    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
  1338
        return -EFAULT;
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
1082
ff06c58e269c Renamed ecrt_slave_config_sync_managers() to ecrt_slave_config_pdos();
Florian Pose <fp@igh-essen.com>
parents: 1079
diff changeset
  1341
    if (data.sync_index >= EC_MAX_SYNC_MANAGERS) {
1079
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1342
        EC_ERR("Invalid sync manager index %u!\n",
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1343
                data.sync_index);
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1344
        return -EINVAL;
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1345
    }
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1346
1189
acc6430bfb32 Use down_interruptible() wherever possible.
Florian Pose <fp@igh-essen.com>
parents: 1183
diff changeset
  1347
    if (down_interruptible(&master->master_sem))
acc6430bfb32 Use down_interruptible() wherever possible.
Florian Pose <fp@igh-essen.com>
parents: 1183
diff changeset
  1348
        return -EINTR;
1079
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1349
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1350
    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
  1351
                    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
  1352
        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
  1353
        EC_ERR("Slave config %u does not exist!\n",
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1354
                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
        return -EINVAL;
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1356
    }
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1357
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1358
    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
  1359
                    &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
  1360
                    data.pdo_pos))) {
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1361
        up(&master->master_sem);
1327
4d179b06dd3c merge -c1604 branches/stable-1.4: Fixed spelling of EtherCAT terms.
Florian Pose <fp@igh-essen.com>
parents: 1326
diff changeset
  1362
        EC_ERR("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
  1363
        return -EINVAL;
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1364
    }
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1365
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1366
    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
  1367
                    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
  1368
        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
  1369
        EC_ERR("Entry not found!\n");
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1370
        return -EINVAL;
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1371
    }
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1372
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1373
    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
  1374
    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
  1375
    data.bit_length = entry->bit_length;
1108
7beba3e7e6b4 Added ec_cdev_strcpy() function.
Florian Pose <fp@igh-essen.com>
parents: 1092
diff changeset
  1376
    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
  1377
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1378
    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
  1379
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1380
    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
  1381
        return -EFAULT;
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
    return 0;
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1384
}
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
/*****************************************************************************/
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1387
1327
4d179b06dd3c merge -c1604 branches/stable-1.4: Fixed spelling of EtherCAT terms.
Florian Pose <fp@igh-essen.com>
parents: 1326
diff changeset
  1388
/** 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
  1389
 */
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1390
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
  1391
        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
  1392
        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
  1393
        )
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1394
{
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1395
    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
  1396
    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
  1397
    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
  1398
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1399
    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
  1400
        return -EFAULT;
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
1189
acc6430bfb32 Use down_interruptible() wherever possible.
Florian Pose <fp@igh-essen.com>
parents: 1183
diff changeset
  1403
    if (down_interruptible(&master->master_sem))
acc6430bfb32 Use down_interruptible() wherever possible.
Florian Pose <fp@igh-essen.com>
parents: 1183
diff changeset
  1404
        return -EINTR;
1079
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1405
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1406
    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
  1407
                    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
  1408
        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
  1409
        EC_ERR("Slave config %u does not exist!\n",
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1410
                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
        return -EINVAL;
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1412
    }
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1413
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1414
    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
  1415
                    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
  1416
        up(&master->master_sem);
1327
4d179b06dd3c merge -c1604 branches/stable-1.4: Fixed spelling of EtherCAT terms.
Florian Pose <fp@igh-essen.com>
parents: 1326
diff changeset
  1417
        EC_ERR("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
  1418
        return -EINVAL;
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1419
    }
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1420
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1421
    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
  1422
    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
  1423
    data.size = req->data_size;
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1424
    memcpy(&data.data, req->data, min((u32) data.size, (u32) 4));
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1425
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1426
    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
  1427
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1428
    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
  1429
        return -EFAULT;
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1430
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1431
    return 0;
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1432
}
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1433
1242
632a6b91f8e4 First version of userspace library with requesting/releasing.
Florian Pose <fp@igh-essen.com>
parents: 1223
diff changeset
  1434
/*****************************************************************************/
632a6b91f8e4 First version of userspace library with requesting/releasing.
Florian Pose <fp@igh-essen.com>
parents: 1223
diff changeset
  1435
632a6b91f8e4 First version of userspace library with requesting/releasing.
Florian Pose <fp@igh-essen.com>
parents: 1223
diff changeset
  1436
/** Request the master from userspace.
632a6b91f8e4 First version of userspace library with requesting/releasing.
Florian Pose <fp@igh-essen.com>
parents: 1223
diff changeset
  1437
 */
632a6b91f8e4 First version of userspace library with requesting/releasing.
Florian Pose <fp@igh-essen.com>
parents: 1223
diff changeset
  1438
int ec_cdev_ioctl_request(
632a6b91f8e4 First version of userspace library with requesting/releasing.
Florian Pose <fp@igh-essen.com>
parents: 1223
diff changeset
  1439
        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
  1440
        unsigned long arg, /**< ioctl() argument. */
632a6b91f8e4 First version of userspace library with requesting/releasing.
Florian Pose <fp@igh-essen.com>
parents: 1223
diff changeset
  1441
        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
  1442
        )
632a6b91f8e4 First version of userspace library with requesting/releasing.
Florian Pose <fp@igh-essen.com>
parents: 1223
diff changeset
  1443
{
1244
0b70040d3daa No kernel handles in userspace; Domain creation.
Florian Pose <fp@igh-essen.com>
parents: 1242
diff changeset
  1444
	ec_master_t *m;
1242
632a6b91f8e4 First version of userspace library with requesting/releasing.
Florian Pose <fp@igh-essen.com>
parents: 1223
diff changeset
  1445
    int ret = 0;
632a6b91f8e4 First version of userspace library with requesting/releasing.
Florian Pose <fp@igh-essen.com>
parents: 1223
diff changeset
  1446
1312
74853e018898 Created backend versions of all API functions returing a pointer; using
Florian Pose <fp@igh-essen.com>
parents: 1284
diff changeset
  1447
    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
  1448
    if (IS_ERR(m)) {
0b70040d3daa No kernel handles in userspace; Domain creation.
Florian Pose <fp@igh-essen.com>
parents: 1242
diff changeset
  1449
        ret = PTR_ERR(m);
1242
632a6b91f8e4 First version of userspace library with requesting/releasing.
Florian Pose <fp@igh-essen.com>
parents: 1223
diff changeset
  1450
    } else {
632a6b91f8e4 First version of userspace library with requesting/releasing.
Florian Pose <fp@igh-essen.com>
parents: 1223
diff changeset
  1451
        priv->requested = 1;
632a6b91f8e4 First version of userspace library with requesting/releasing.
Florian Pose <fp@igh-essen.com>
parents: 1223
diff changeset
  1452
    }
632a6b91f8e4 First version of userspace library with requesting/releasing.
Florian Pose <fp@igh-essen.com>
parents: 1223
diff changeset
  1453
632a6b91f8e4 First version of userspace library with requesting/releasing.
Florian Pose <fp@igh-essen.com>
parents: 1223
diff changeset
  1454
    return ret;
632a6b91f8e4 First version of userspace library with requesting/releasing.
Florian Pose <fp@igh-essen.com>
parents: 1223
diff changeset
  1455
}
632a6b91f8e4 First version of userspace library with requesting/releasing.
Florian Pose <fp@igh-essen.com>
parents: 1223
diff changeset
  1456
1244
0b70040d3daa No kernel handles in userspace; Domain creation.
Florian Pose <fp@igh-essen.com>
parents: 1242
diff changeset
  1457
/*****************************************************************************/
0b70040d3daa No kernel handles in userspace; Domain creation.
Florian Pose <fp@igh-essen.com>
parents: 1242
diff changeset
  1458
0b70040d3daa No kernel handles in userspace; Domain creation.
Florian Pose <fp@igh-essen.com>
parents: 1242
diff changeset
  1459
/** Create a domain.
0b70040d3daa No kernel handles in userspace; Domain creation.
Florian Pose <fp@igh-essen.com>
parents: 1242
diff changeset
  1460
 */
0b70040d3daa No kernel handles in userspace; Domain creation.
Florian Pose <fp@igh-essen.com>
parents: 1242
diff changeset
  1461
int ec_cdev_ioctl_create_domain(
0b70040d3daa No kernel handles in userspace; Domain creation.
Florian Pose <fp@igh-essen.com>
parents: 1242
diff changeset
  1462
        ec_master_t *master, /**< EtherCAT master. */
0b70040d3daa No kernel handles in userspace; Domain creation.
Florian Pose <fp@igh-essen.com>
parents: 1242
diff changeset
  1463
        unsigned long arg, /**< ioctl() argument. */
0b70040d3daa No kernel handles in userspace; Domain creation.
Florian Pose <fp@igh-essen.com>
parents: 1242
diff changeset
  1464
        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
  1465
        )
0b70040d3daa No kernel handles in userspace; Domain creation.
Florian Pose <fp@igh-essen.com>
parents: 1242
diff changeset
  1466
{
0b70040d3daa No kernel handles in userspace; Domain creation.
Florian Pose <fp@igh-essen.com>
parents: 1242
diff changeset
  1467
    ec_domain_t *domain;
0b70040d3daa No kernel handles in userspace; Domain creation.
Florian Pose <fp@igh-essen.com>
parents: 1242
diff changeset
  1468
0b70040d3daa No kernel handles in userspace; Domain creation.
Florian Pose <fp@igh-essen.com>
parents: 1242
diff changeset
  1469
	if (unlikely(!priv->requested))
0b70040d3daa No kernel handles in userspace; Domain creation.
Florian Pose <fp@igh-essen.com>
parents: 1242
diff changeset
  1470
		return -EPERM;
0b70040d3daa No kernel handles in userspace; Domain creation.
Florian Pose <fp@igh-essen.com>
parents: 1242
diff changeset
  1471
1312
74853e018898 Created backend versions of all API functions returing a pointer; using
Florian Pose <fp@igh-essen.com>
parents: 1284
diff changeset
  1472
    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
  1473
    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
  1474
        return PTR_ERR(domain);
1244
0b70040d3daa No kernel handles in userspace; Domain creation.
Florian Pose <fp@igh-essen.com>
parents: 1242
diff changeset
  1475
0b70040d3daa No kernel handles in userspace; Domain creation.
Florian Pose <fp@igh-essen.com>
parents: 1242
diff changeset
  1476
    return domain->index;
0b70040d3daa No kernel handles in userspace; Domain creation.
Florian Pose <fp@igh-essen.com>
parents: 1242
diff changeset
  1477
}
0b70040d3daa No kernel handles in userspace; Domain creation.
Florian Pose <fp@igh-essen.com>
parents: 1242
diff changeset
  1478
1246
4042bda8c980 Creating slave configurations.
Florian Pose <fp@igh-essen.com>
parents: 1244
diff changeset
  1479
/*****************************************************************************/
4042bda8c980 Creating slave configurations.
Florian Pose <fp@igh-essen.com>
parents: 1244
diff changeset
  1480
4042bda8c980 Creating slave configurations.
Florian Pose <fp@igh-essen.com>
parents: 1244
diff changeset
  1481
/** Create a slave configuration.
4042bda8c980 Creating slave configurations.
Florian Pose <fp@igh-essen.com>
parents: 1244
diff changeset
  1482
 */
4042bda8c980 Creating slave configurations.
Florian Pose <fp@igh-essen.com>
parents: 1244
diff changeset
  1483
int ec_cdev_ioctl_create_slave_config(
4042bda8c980 Creating slave configurations.
Florian Pose <fp@igh-essen.com>
parents: 1244
diff changeset
  1484
        ec_master_t *master, /**< EtherCAT master. */
4042bda8c980 Creating slave configurations.
Florian Pose <fp@igh-essen.com>
parents: 1244
diff changeset
  1485
        unsigned long arg, /**< ioctl() argument. */
4042bda8c980 Creating slave configurations.
Florian Pose <fp@igh-essen.com>
parents: 1244
diff changeset
  1486
        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
  1487
        )
4042bda8c980 Creating slave configurations.
Florian Pose <fp@igh-essen.com>
parents: 1244
diff changeset
  1488
{
4042bda8c980 Creating slave configurations.
Florian Pose <fp@igh-essen.com>
parents: 1244
diff changeset
  1489
    ec_ioctl_config_t data;
4042bda8c980 Creating slave configurations.
Florian Pose <fp@igh-essen.com>
parents: 1244
diff changeset
  1490
    ec_slave_config_t *sc, *entry;
4042bda8c980 Creating slave configurations.
Florian Pose <fp@igh-essen.com>
parents: 1244
diff changeset
  1491
4042bda8c980 Creating slave configurations.
Florian Pose <fp@igh-essen.com>
parents: 1244
diff changeset
  1492
	if (unlikely(!priv->requested))
4042bda8c980 Creating slave configurations.
Florian Pose <fp@igh-essen.com>
parents: 1244
diff changeset
  1493
		return -EPERM;
4042bda8c980 Creating slave configurations.
Florian Pose <fp@igh-essen.com>
parents: 1244
diff changeset
  1494
4042bda8c980 Creating slave configurations.
Florian Pose <fp@igh-essen.com>
parents: 1244
diff changeset
  1495
    if (copy_from_user(&data, (void __user *) arg, sizeof(data))) {
4042bda8c980 Creating slave configurations.
Florian Pose <fp@igh-essen.com>
parents: 1244
diff changeset
  1496
        return -EFAULT;
4042bda8c980 Creating slave configurations.
Florian Pose <fp@igh-essen.com>
parents: 1244
diff changeset
  1497
    }
4042bda8c980 Creating slave configurations.
Florian Pose <fp@igh-essen.com>
parents: 1244
diff changeset
  1498
1312
74853e018898 Created backend versions of all API functions returing a pointer; using
Florian Pose <fp@igh-essen.com>
parents: 1284
diff changeset
  1499
    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
  1500
            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
  1501
    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
  1502
        return PTR_ERR(sc);
1246
4042bda8c980 Creating slave configurations.
Florian Pose <fp@igh-essen.com>
parents: 1244
diff changeset
  1503
4042bda8c980 Creating slave configurations.
Florian Pose <fp@igh-essen.com>
parents: 1244
diff changeset
  1504
    data.config_index = 0;
4042bda8c980 Creating slave configurations.
Florian Pose <fp@igh-essen.com>
parents: 1244
diff changeset
  1505
4042bda8c980 Creating slave configurations.
Florian Pose <fp@igh-essen.com>
parents: 1244
diff changeset
  1506
    if (down_interruptible(&master->master_sem))
4042bda8c980 Creating slave configurations.
Florian Pose <fp@igh-essen.com>
parents: 1244
diff changeset
  1507
        return -EINTR;
4042bda8c980 Creating slave configurations.
Florian Pose <fp@igh-essen.com>
parents: 1244
diff changeset
  1508
4042bda8c980 Creating slave configurations.
Florian Pose <fp@igh-essen.com>
parents: 1244
diff changeset
  1509
    list_for_each_entry(entry, &master->configs, list) {
4042bda8c980 Creating slave configurations.
Florian Pose <fp@igh-essen.com>
parents: 1244
diff changeset
  1510
        if (entry == sc)
4042bda8c980 Creating slave configurations.
Florian Pose <fp@igh-essen.com>
parents: 1244
diff changeset
  1511
            break;
4042bda8c980 Creating slave configurations.
Florian Pose <fp@igh-essen.com>
parents: 1244
diff changeset
  1512
        data.config_index++;
4042bda8c980 Creating slave configurations.
Florian Pose <fp@igh-essen.com>
parents: 1244
diff changeset
  1513
    }
4042bda8c980 Creating slave configurations.
Florian Pose <fp@igh-essen.com>
parents: 1244
diff changeset
  1514
4042bda8c980 Creating slave configurations.
Florian Pose <fp@igh-essen.com>
parents: 1244
diff changeset
  1515
    up(&master->master_sem);
4042bda8c980 Creating slave configurations.
Florian Pose <fp@igh-essen.com>
parents: 1244
diff changeset
  1516
4042bda8c980 Creating slave configurations.
Florian Pose <fp@igh-essen.com>
parents: 1244
diff changeset
  1517
    if (copy_to_user((void __user *) arg, &data, sizeof(data)))
4042bda8c980 Creating slave configurations.
Florian Pose <fp@igh-essen.com>
parents: 1244
diff changeset
  1518
        return -EFAULT;
4042bda8c980 Creating slave configurations.
Florian Pose <fp@igh-essen.com>
parents: 1244
diff changeset
  1519
4042bda8c980 Creating slave configurations.
Florian Pose <fp@igh-essen.com>
parents: 1244
diff changeset
  1520
    return 0;
4042bda8c980 Creating slave configurations.
Florian Pose <fp@igh-essen.com>
parents: 1244
diff changeset
  1521
}
4042bda8c980 Creating slave configurations.
Florian Pose <fp@igh-essen.com>
parents: 1244
diff changeset
  1522
1247
5f1f1a3e6636 Activate, Send and received; cyclic timer with setitimer().
Florian Pose <fp@igh-essen.com>
parents: 1246
diff changeset
  1523
/*****************************************************************************/
5f1f1a3e6636 Activate, Send and received; cyclic timer with setitimer().
Florian Pose <fp@igh-essen.com>
parents: 1246
diff changeset
  1524
5f1f1a3e6636 Activate, Send and received; cyclic timer with setitimer().
Florian Pose <fp@igh-essen.com>
parents: 1246
diff changeset
  1525
/** Activates the master.
5f1f1a3e6636 Activate, Send and received; cyclic timer with setitimer().
Florian Pose <fp@igh-essen.com>
parents: 1246
diff changeset
  1526
 */
5f1f1a3e6636 Activate, Send and received; cyclic timer with setitimer().
Florian Pose <fp@igh-essen.com>
parents: 1246
diff changeset
  1527
int ec_cdev_ioctl_activate(
5f1f1a3e6636 Activate, Send and received; cyclic timer with setitimer().
Florian Pose <fp@igh-essen.com>
parents: 1246
diff changeset
  1528
        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
  1529
        unsigned long arg, /**< ioctl() argument. */
5f1f1a3e6636 Activate, Send and received; cyclic timer with setitimer().
Florian Pose <fp@igh-essen.com>
parents: 1246
diff changeset
  1530
        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
  1531
        )
5f1f1a3e6636 Activate, Send and received; cyclic timer with setitimer().
Florian Pose <fp@igh-essen.com>
parents: 1246
diff changeset
  1532
{
1258
900f1124e8f8 Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents: 1255
diff changeset
  1533
    ec_domain_t *domain;
900f1124e8f8 Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents: 1255
diff changeset
  1534
    off_t offset;
1313
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1312
diff changeset
  1535
    int ret;
1258
900f1124e8f8 Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents: 1255
diff changeset
  1536
    
1247
5f1f1a3e6636 Activate, Send and received; cyclic timer with setitimer().
Florian Pose <fp@igh-essen.com>
parents: 1246
diff changeset
  1537
	if (unlikely(!priv->requested))
5f1f1a3e6636 Activate, Send and received; cyclic timer with setitimer().
Florian Pose <fp@igh-essen.com>
parents: 1246
diff changeset
  1538
		return -EPERM;
5f1f1a3e6636 Activate, Send and received; cyclic timer with setitimer().
Florian Pose <fp@igh-essen.com>
parents: 1246
diff changeset
  1539
1258
900f1124e8f8 Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents: 1255
diff changeset
  1540
    /* Get the sum of the domains' process data sizes. */
900f1124e8f8 Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents: 1255
diff changeset
  1541
    
900f1124e8f8 Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents: 1255
diff changeset
  1542
    priv->process_data_size = 0;
900f1124e8f8 Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents: 1255
diff changeset
  1543
900f1124e8f8 Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents: 1255
diff changeset
  1544
    if (down_interruptible(&master->master_sem))
900f1124e8f8 Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents: 1255
diff changeset
  1545
        return -EINTR;
900f1124e8f8 Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents: 1255
diff changeset
  1546
900f1124e8f8 Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents: 1255
diff changeset
  1547
    list_for_each_entry(domain, &master->domains, list) {
900f1124e8f8 Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents: 1255
diff changeset
  1548
        priv->process_data_size += ecrt_domain_size(domain);
900f1124e8f8 Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents: 1255
diff changeset
  1549
    }
900f1124e8f8 Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents: 1255
diff changeset
  1550
    
900f1124e8f8 Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents: 1255
diff changeset
  1551
    up(&master->master_sem);
900f1124e8f8 Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents: 1255
diff changeset
  1552
900f1124e8f8 Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents: 1255
diff changeset
  1553
    if (priv->process_data_size) {
900f1124e8f8 Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents: 1255
diff changeset
  1554
        priv->process_data = vmalloc(priv->process_data_size);
900f1124e8f8 Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents: 1255
diff changeset
  1555
        if (!priv->process_data) {
900f1124e8f8 Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents: 1255
diff changeset
  1556
            priv->process_data_size = 0;
900f1124e8f8 Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents: 1255
diff changeset
  1557
            return -ENOMEM;
900f1124e8f8 Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents: 1255
diff changeset
  1558
        }
900f1124e8f8 Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents: 1255
diff changeset
  1559
900f1124e8f8 Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents: 1255
diff changeset
  1560
        /* 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
  1561
900f1124e8f8 Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents: 1255
diff changeset
  1562
        offset = 0;
900f1124e8f8 Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents: 1255
diff changeset
  1563
        list_for_each_entry(domain, &master->domains, list) {
900f1124e8f8 Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents: 1255
diff changeset
  1564
            ecrt_domain_external_memory(domain, priv->process_data + offset);
900f1124e8f8 Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents: 1255
diff changeset
  1565
            offset += ecrt_domain_size(domain);
900f1124e8f8 Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents: 1255
diff changeset
  1566
        }
900f1124e8f8 Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents: 1255
diff changeset
  1567
    }
900f1124e8f8 Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents: 1255
diff changeset
  1568
1313
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1312
diff changeset
  1569
    ret = ecrt_master_activate(master);
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1312
diff changeset
  1570
    if (ret < 0)
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1312
diff changeset
  1571
        return ret;
1247
5f1f1a3e6636 Activate, Send and received; cyclic timer with setitimer().
Florian Pose <fp@igh-essen.com>
parents: 1246
diff changeset
  1572
1258
900f1124e8f8 Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents: 1255
diff changeset
  1573
    if (copy_to_user((void __user *) arg,
900f1124e8f8 Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents: 1255
diff changeset
  1574
                &priv->process_data_size, sizeof(size_t)))
900f1124e8f8 Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents: 1255
diff changeset
  1575
        return -EFAULT;
900f1124e8f8 Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents: 1255
diff changeset
  1576
1247
5f1f1a3e6636 Activate, Send and received; cyclic timer with setitimer().
Florian Pose <fp@igh-essen.com>
parents: 1246
diff changeset
  1577
    return 0;
5f1f1a3e6636 Activate, Send and received; cyclic timer with setitimer().
Florian Pose <fp@igh-essen.com>
parents: 1246
diff changeset
  1578
}
5f1f1a3e6636 Activate, Send and received; cyclic timer with setitimer().
Florian Pose <fp@igh-essen.com>
parents: 1246
diff changeset
  1579
5f1f1a3e6636 Activate, Send and received; cyclic timer with setitimer().
Florian Pose <fp@igh-essen.com>
parents: 1246
diff changeset
  1580
/*****************************************************************************/
5f1f1a3e6636 Activate, Send and received; cyclic timer with setitimer().
Florian Pose <fp@igh-essen.com>
parents: 1246
diff changeset
  1581
5f1f1a3e6636 Activate, Send and received; cyclic timer with setitimer().
Florian Pose <fp@igh-essen.com>
parents: 1246
diff changeset
  1582
/** Send frames.
5f1f1a3e6636 Activate, Send and received; cyclic timer with setitimer().
Florian Pose <fp@igh-essen.com>
parents: 1246
diff changeset
  1583
 */
5f1f1a3e6636 Activate, Send and received; cyclic timer with setitimer().
Florian Pose <fp@igh-essen.com>
parents: 1246
diff changeset
  1584
int ec_cdev_ioctl_send(
5f1f1a3e6636 Activate, Send and received; cyclic timer with setitimer().
Florian Pose <fp@igh-essen.com>
parents: 1246
diff changeset
  1585
        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
  1586
        unsigned long arg, /**< ioctl() argument. */
5f1f1a3e6636 Activate, Send and received; cyclic timer with setitimer().
Florian Pose <fp@igh-essen.com>
parents: 1246
diff changeset
  1587
        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
  1588
        )
5f1f1a3e6636 Activate, Send and received; cyclic timer with setitimer().
Florian Pose <fp@igh-essen.com>
parents: 1246
diff changeset
  1589
{
5f1f1a3e6636 Activate, Send and received; cyclic timer with setitimer().
Florian Pose <fp@igh-essen.com>
parents: 1246
diff changeset
  1590
	if (unlikely(!priv->requested))
5f1f1a3e6636 Activate, Send and received; cyclic timer with setitimer().
Florian Pose <fp@igh-essen.com>
parents: 1246
diff changeset
  1591
		return -EPERM;
5f1f1a3e6636 Activate, Send and received; cyclic timer with setitimer().
Florian Pose <fp@igh-essen.com>
parents: 1246
diff changeset
  1592
5f1f1a3e6636 Activate, Send and received; cyclic timer with setitimer().
Florian Pose <fp@igh-essen.com>
parents: 1246
diff changeset
  1593
    spin_lock_bh(&master->internal_lock);
5f1f1a3e6636 Activate, Send and received; cyclic timer with setitimer().
Florian Pose <fp@igh-essen.com>
parents: 1246
diff changeset
  1594
    ecrt_master_send(master);
5f1f1a3e6636 Activate, Send and received; cyclic timer with setitimer().
Florian Pose <fp@igh-essen.com>
parents: 1246
diff changeset
  1595
    spin_unlock_bh(&master->internal_lock);
5f1f1a3e6636 Activate, Send and received; cyclic timer with setitimer().
Florian Pose <fp@igh-essen.com>
parents: 1246
diff changeset
  1596
    return 0;
5f1f1a3e6636 Activate, Send and received; cyclic timer with setitimer().
Florian Pose <fp@igh-essen.com>
parents: 1246
diff changeset
  1597
}
5f1f1a3e6636 Activate, Send and received; cyclic timer with setitimer().
Florian Pose <fp@igh-essen.com>
parents: 1246
diff changeset
  1598
5f1f1a3e6636 Activate, Send and received; cyclic timer with setitimer().
Florian Pose <fp@igh-essen.com>
parents: 1246
diff changeset
  1599
/*****************************************************************************/
5f1f1a3e6636 Activate, Send and received; cyclic timer with setitimer().
Florian Pose <fp@igh-essen.com>
parents: 1246
diff changeset
  1600
5f1f1a3e6636 Activate, Send and received; cyclic timer with setitimer().
Florian Pose <fp@igh-essen.com>
parents: 1246
diff changeset
  1601
/** Receive frames.
5f1f1a3e6636 Activate, Send and received; cyclic timer with setitimer().
Florian Pose <fp@igh-essen.com>
parents: 1246
diff changeset
  1602
 */
5f1f1a3e6636 Activate, Send and received; cyclic timer with setitimer().
Florian Pose <fp@igh-essen.com>
parents: 1246
diff changeset
  1603
int ec_cdev_ioctl_receive(
5f1f1a3e6636 Activate, Send and received; cyclic timer with setitimer().
Florian Pose <fp@igh-essen.com>
parents: 1246
diff changeset
  1604
        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
  1605
        unsigned long arg, /**< ioctl() argument. */
5f1f1a3e6636 Activate, Send and received; cyclic timer with setitimer().
Florian Pose <fp@igh-essen.com>
parents: 1246
diff changeset
  1606
        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
  1607
        )
5f1f1a3e6636 Activate, Send and received; cyclic timer with setitimer().
Florian Pose <fp@igh-essen.com>
parents: 1246
diff changeset
  1608
{
5f1f1a3e6636 Activate, Send and received; cyclic timer with setitimer().
Florian Pose <fp@igh-essen.com>
parents: 1246
diff changeset
  1609
	if (unlikely(!priv->requested))
5f1f1a3e6636 Activate, Send and received; cyclic timer with setitimer().
Florian Pose <fp@igh-essen.com>
parents: 1246
diff changeset
  1610
		return -EPERM;
5f1f1a3e6636 Activate, Send and received; cyclic timer with setitimer().
Florian Pose <fp@igh-essen.com>
parents: 1246
diff changeset
  1611
5f1f1a3e6636 Activate, Send and received; cyclic timer with setitimer().
Florian Pose <fp@igh-essen.com>
parents: 1246
diff changeset
  1612
    spin_lock_bh(&master->internal_lock);
5f1f1a3e6636 Activate, Send and received; cyclic timer with setitimer().
Florian Pose <fp@igh-essen.com>
parents: 1246
diff changeset
  1613
    ecrt_master_receive(master);
5f1f1a3e6636 Activate, Send and received; cyclic timer with setitimer().
Florian Pose <fp@igh-essen.com>
parents: 1246
diff changeset
  1614
    spin_unlock_bh(&master->internal_lock);
5f1f1a3e6636 Activate, Send and received; cyclic timer with setitimer().
Florian Pose <fp@igh-essen.com>
parents: 1246
diff changeset
  1615
    return 0;
5f1f1a3e6636 Activate, Send and received; cyclic timer with setitimer().
Florian Pose <fp@igh-essen.com>
parents: 1246
diff changeset
  1616
}
5f1f1a3e6636 Activate, Send and received; cyclic timer with setitimer().
Florian Pose <fp@igh-essen.com>
parents: 1246
diff changeset
  1617
1255
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  1618
/*****************************************************************************/
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  1619
1259
5f9d1abbee71 Added state functions; writing of process data works.
Florian Pose <fp@igh-essen.com>
parents: 1258
diff changeset
  1620
/** Get the master state.
5f9d1abbee71 Added state functions; writing of process data works.
Florian Pose <fp@igh-essen.com>
parents: 1258
diff changeset
  1621
 */
5f9d1abbee71 Added state functions; writing of process data works.
Florian Pose <fp@igh-essen.com>
parents: 1258
diff changeset
  1622
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
  1623
        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
  1624
        unsigned long arg, /**< ioctl() argument. */
5f9d1abbee71 Added state functions; writing of process data works.
Florian Pose <fp@igh-essen.com>
parents: 1258
diff changeset
  1625
        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
  1626
        )
5f9d1abbee71 Added state functions; writing of process data works.
Florian Pose <fp@igh-essen.com>
parents: 1258
diff changeset
  1627
{
5f9d1abbee71 Added state functions; writing of process data works.
Florian Pose <fp@igh-essen.com>
parents: 1258
diff changeset
  1628
    ec_master_state_t data;
5f9d1abbee71 Added state functions; writing of process data works.
Florian Pose <fp@igh-essen.com>
parents: 1258
diff changeset
  1629
    
5f9d1abbee71 Added state functions; writing of process data works.
Florian Pose <fp@igh-essen.com>
parents: 1258
diff changeset
  1630
	if (unlikely(!priv->requested))
5f9d1abbee71 Added state functions; writing of process data works.
Florian Pose <fp@igh-essen.com>
parents: 1258
diff changeset
  1631
		return -EPERM;
5f9d1abbee71 Added state functions; writing of process data works.
Florian Pose <fp@igh-essen.com>
parents: 1258
diff changeset
  1632
5f9d1abbee71 Added state functions; writing of process data works.
Florian Pose <fp@igh-essen.com>
parents: 1258
diff changeset
  1633
    ecrt_master_state(master, &data);
5f9d1abbee71 Added state functions; writing of process data works.
Florian Pose <fp@igh-essen.com>
parents: 1258
diff changeset
  1634
5f9d1abbee71 Added state functions; writing of process data works.
Florian Pose <fp@igh-essen.com>
parents: 1258
diff changeset
  1635
    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
  1636
        return -EFAULT;
5f9d1abbee71 Added state functions; writing of process data works.
Florian Pose <fp@igh-essen.com>
parents: 1258
diff changeset
  1637
5f9d1abbee71 Added state functions; writing of process data works.
Florian Pose <fp@igh-essen.com>
parents: 1258
diff changeset
  1638
    return 0;
5f9d1abbee71 Added state functions; writing of process data works.
Florian Pose <fp@igh-essen.com>
parents: 1258
diff changeset
  1639
}
5f9d1abbee71 Added state functions; writing of process data works.
Florian Pose <fp@igh-essen.com>
parents: 1258
diff changeset
  1640
5f9d1abbee71 Added state functions; writing of process data works.
Florian Pose <fp@igh-essen.com>
parents: 1258
diff changeset
  1641
/*****************************************************************************/
5f9d1abbee71 Added state functions; writing of process data works.
Florian Pose <fp@igh-essen.com>
parents: 1258
diff changeset
  1642
1413
44c2b7c0ae1a Userspace library implementation of DC functions.
Florian Pose <fp@igh-essen.com>
parents: 1401
diff changeset
  1643
/** Sync the reference clock.
44c2b7c0ae1a Userspace library implementation of DC functions.
Florian Pose <fp@igh-essen.com>
parents: 1401
diff changeset
  1644
 */
44c2b7c0ae1a Userspace library implementation of DC functions.
Florian Pose <fp@igh-essen.com>
parents: 1401
diff changeset
  1645
int ec_cdev_ioctl_sync_ref(
44c2b7c0ae1a Userspace library implementation of DC functions.
Florian Pose <fp@igh-essen.com>
parents: 1401
diff changeset
  1646
        ec_master_t *master, /**< EtherCAT master. */
44c2b7c0ae1a Userspace library implementation of DC functions.
Florian Pose <fp@igh-essen.com>
parents: 1401
diff changeset
  1647
        unsigned long arg, /**< ioctl() argument. */
44c2b7c0ae1a Userspace library implementation of DC functions.
Florian Pose <fp@igh-essen.com>
parents: 1401
diff changeset
  1648
        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
  1649
        )
44c2b7c0ae1a Userspace library implementation of DC functions.
Florian Pose <fp@igh-essen.com>
parents: 1401
diff changeset
  1650
{
44c2b7c0ae1a Userspace library implementation of DC functions.
Florian Pose <fp@igh-essen.com>
parents: 1401
diff changeset
  1651
	if (unlikely(!priv->requested))
44c2b7c0ae1a Userspace library implementation of DC functions.
Florian Pose <fp@igh-essen.com>
parents: 1401
diff changeset
  1652
		return -EPERM;
44c2b7c0ae1a Userspace library implementation of DC functions.
Florian Pose <fp@igh-essen.com>
parents: 1401
diff changeset
  1653
44c2b7c0ae1a Userspace library implementation of DC functions.
Florian Pose <fp@igh-essen.com>
parents: 1401
diff changeset
  1654
    spin_lock_bh(&master->internal_lock);
1434
4c6fe0ae37f1 Separated application time from synchronizing reference clock.
Florian Pose <fp@igh-essen.com>
parents: 1426
diff changeset
  1655
    ecrt_master_sync_reference_clock(master);
1413
44c2b7c0ae1a Userspace library implementation of DC functions.
Florian Pose <fp@igh-essen.com>
parents: 1401
diff changeset
  1656
    spin_unlock_bh(&master->internal_lock);
44c2b7c0ae1a Userspace library implementation of DC functions.
Florian Pose <fp@igh-essen.com>
parents: 1401
diff changeset
  1657
    return 0;
44c2b7c0ae1a Userspace library implementation of DC functions.
Florian Pose <fp@igh-essen.com>
parents: 1401
diff changeset
  1658
}
44c2b7c0ae1a Userspace library implementation of DC functions.
Florian Pose <fp@igh-essen.com>
parents: 1401
diff changeset
  1659
44c2b7c0ae1a Userspace library implementation of DC functions.
Florian Pose <fp@igh-essen.com>
parents: 1401
diff changeset
  1660
/*****************************************************************************/
44c2b7c0ae1a Userspace library implementation of DC functions.
Florian Pose <fp@igh-essen.com>
parents: 1401
diff changeset
  1661
44c2b7c0ae1a Userspace library implementation of DC functions.
Florian Pose <fp@igh-essen.com>
parents: 1401
diff changeset
  1662
/** Sync the slave clocks.
44c2b7c0ae1a Userspace library implementation of DC functions.
Florian Pose <fp@igh-essen.com>
parents: 1401
diff changeset
  1663
 */
44c2b7c0ae1a Userspace library implementation of DC functions.
Florian Pose <fp@igh-essen.com>
parents: 1401
diff changeset
  1664
int ec_cdev_ioctl_sync_slaves(
44c2b7c0ae1a Userspace library implementation of DC functions.
Florian Pose <fp@igh-essen.com>
parents: 1401
diff changeset
  1665
        ec_master_t *master, /**< EtherCAT master. */
44c2b7c0ae1a Userspace library implementation of DC functions.
Florian Pose <fp@igh-essen.com>
parents: 1401
diff changeset
  1666
        unsigned long arg, /**< ioctl() argument. */
44c2b7c0ae1a Userspace library implementation of DC functions.
Florian Pose <fp@igh-essen.com>
parents: 1401
diff changeset
  1667
        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
  1668
        )
44c2b7c0ae1a Userspace library implementation of DC functions.
Florian Pose <fp@igh-essen.com>
parents: 1401
diff changeset
  1669
{
44c2b7c0ae1a Userspace library implementation of DC functions.
Florian Pose <fp@igh-essen.com>
parents: 1401
diff changeset
  1670
	if (unlikely(!priv->requested))
44c2b7c0ae1a Userspace library implementation of DC functions.
Florian Pose <fp@igh-essen.com>
parents: 1401
diff changeset
  1671
		return -EPERM;
44c2b7c0ae1a Userspace library implementation of DC functions.
Florian Pose <fp@igh-essen.com>
parents: 1401
diff changeset
  1672
44c2b7c0ae1a Userspace library implementation of DC functions.
Florian Pose <fp@igh-essen.com>
parents: 1401
diff changeset
  1673
    spin_lock_bh(&master->internal_lock);
44c2b7c0ae1a Userspace library implementation of DC functions.
Florian Pose <fp@igh-essen.com>
parents: 1401
diff changeset
  1674
    ecrt_master_sync_slave_clocks(master);
44c2b7c0ae1a Userspace library implementation of DC functions.
Florian Pose <fp@igh-essen.com>
parents: 1401
diff changeset
  1675
    spin_unlock_bh(&master->internal_lock);
44c2b7c0ae1a Userspace library implementation of DC functions.
Florian Pose <fp@igh-essen.com>
parents: 1401
diff changeset
  1676
    return 0;
44c2b7c0ae1a Userspace library implementation of DC functions.
Florian Pose <fp@igh-essen.com>
parents: 1401
diff changeset
  1677
}
44c2b7c0ae1a Userspace library implementation of DC functions.
Florian Pose <fp@igh-essen.com>
parents: 1401
diff changeset
  1678
44c2b7c0ae1a Userspace library implementation of DC functions.
Florian Pose <fp@igh-essen.com>
parents: 1401
diff changeset
  1679
/*****************************************************************************/
44c2b7c0ae1a Userspace library implementation of DC functions.
Florian Pose <fp@igh-essen.com>
parents: 1401
diff changeset
  1680
1255
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  1681
/** Set the direction of a sync manager.
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  1682
 */
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  1683
int ec_cdev_ioctl_sc_sync(
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  1684
        ec_master_t *master, /**< EtherCAT master. */
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  1685
        unsigned long arg, /**< ioctl() argument. */
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  1686
        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
  1687
        )
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  1688
{
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  1689
    ec_ioctl_config_t data;
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  1690
    ec_slave_config_t *sc;
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  1691
    unsigned int i;
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  1692
    int ret = 0;
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  1693
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  1694
	if (unlikely(!priv->requested)) {
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  1695
        ret = -EPERM;
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  1696
        goto out_return;
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  1697
    }
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  1698
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  1699
    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
  1700
        ret = -EFAULT;
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  1701
        goto out_return;
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  1702
    }
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  1703
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  1704
    if (down_interruptible(&master->master_sem)) {
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  1705
        ret = -EINTR;
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  1706
        goto out_return;
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  1707
    }
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  1708
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  1709
    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
  1710
        ret = -ENOENT;
1255
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  1711
        goto out_up;
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  1712
    }
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  1713
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  1714
    for (i = 0; i < EC_MAX_SYNC_MANAGERS; i++) {
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  1715
        ec_direction_t dir = data.syncs[i].dir;
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  1716
        if (dir == EC_DIR_INPUT || dir == EC_DIR_OUTPUT) {
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  1717
            if (ecrt_slave_config_sync_manager(sc, i, dir)) {
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  1718
                ret = -EINVAL;
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  1719
                goto out_up;
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  1720
            }
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  1721
        }
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  1722
    }
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  1723
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  1724
out_up:
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  1725
    up(&master->master_sem);
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  1726
out_return:
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  1727
    return ret;
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  1728
}
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  1729
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  1730
/*****************************************************************************/
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  1731
1327
4d179b06dd3c merge -c1604 branches/stable-1.4: Fixed spelling of EtherCAT terms.
Florian Pose <fp@igh-essen.com>
parents: 1326
diff changeset
  1732
/** Add a PDO to the assignment.
1255
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  1733
 */
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  1734
int ec_cdev_ioctl_sc_add_pdo(
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  1735
        ec_master_t *master, /**< EtherCAT master. */
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  1736
        unsigned long arg, /**< ioctl() argument. */
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  1737
        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
  1738
        )
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  1739
{
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  1740
    ec_ioctl_config_pdo_t data;
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  1741
    ec_slave_config_t *sc;
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  1742
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  1743
	if (unlikely(!priv->requested))
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  1744
        return -EPERM;
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  1745
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  1746
    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
  1747
        return -EFAULT;
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  1748
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  1749
    if (down_interruptible(&master->master_sem))
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  1750
        return -EINTR;
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  1751
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  1752
    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
  1753
        up(&master->master_sem);
1313
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1312
diff changeset
  1754
        return -ENOENT;
1255
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  1755
    }
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  1756
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  1757
    up(&master->master_sem); // FIXME
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  1758
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  1759
    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
  1760
}
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  1761
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  1762
/*****************************************************************************/
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  1763
1327
4d179b06dd3c merge -c1604 branches/stable-1.4: Fixed spelling of EtherCAT terms.
Florian Pose <fp@igh-essen.com>
parents: 1326
diff changeset
  1764
/** Clears the PDO assignment.
1255
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  1765
 */
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  1766
int ec_cdev_ioctl_sc_clear_pdos(
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  1767
        ec_master_t *master, /**< EtherCAT master. */
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  1768
        unsigned long arg, /**< ioctl() argument. */
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  1769
        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
  1770
        )
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  1771
{
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  1772
    ec_ioctl_config_pdo_t data;
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  1773
    ec_slave_config_t *sc;
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  1774
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  1775
	if (unlikely(!priv->requested))
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  1776
        return -EPERM;
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  1777
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  1778
    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
  1779
        return -EFAULT;
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  1780
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  1781
    if (down_interruptible(&master->master_sem))
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  1782
        return -EINTR;
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  1783
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  1784
    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
  1785
        up(&master->master_sem);
1313
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1312
diff changeset
  1786
        return -ENOENT;
1255
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  1787
    }
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  1788
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  1789
    up(&master->master_sem); // FIXME
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  1790
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  1791
    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
  1792
    return 0;
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  1793
}
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  1794
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  1795
/*****************************************************************************/
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  1796
1327
4d179b06dd3c merge -c1604 branches/stable-1.4: Fixed spelling of EtherCAT terms.
Florian Pose <fp@igh-essen.com>
parents: 1326
diff changeset
  1797
/** 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
  1798
 */
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  1799
int ec_cdev_ioctl_sc_add_entry(
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  1800
        ec_master_t *master, /**< EtherCAT master. */
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  1801
        unsigned long arg, /**< ioctl() argument. */
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  1802
        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
  1803
        )
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  1804
{
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  1805
    ec_ioctl_add_pdo_entry_t data;
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  1806
    ec_slave_config_t *sc;
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  1807
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  1808
	if (unlikely(!priv->requested))
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  1809
        return -EPERM;
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  1810
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  1811
    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
  1812
        return -EFAULT;
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  1813
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  1814
    if (down_interruptible(&master->master_sem))
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  1815
        return -EINTR;
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  1816
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  1817
    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
  1818
        up(&master->master_sem);
1313
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1312
diff changeset
  1819
        return -ENOENT;
1255
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  1820
    }
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  1821
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  1822
    up(&master->master_sem); // FIXME
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  1823
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  1824
    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
  1825
            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
  1826
}
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  1827
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  1828
/*****************************************************************************/
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  1829
1327
4d179b06dd3c merge -c1604 branches/stable-1.4: Fixed spelling of EtherCAT terms.
Florian Pose <fp@igh-essen.com>
parents: 1326
diff changeset
  1830
/** Clears the mapping of a PDO.
1255
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  1831
 */
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  1832
int ec_cdev_ioctl_sc_clear_entries(
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  1833
        ec_master_t *master, /**< EtherCAT master. */
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  1834
        unsigned long arg, /**< ioctl() argument. */
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  1835
        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
  1836
        )
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  1837
{
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  1838
    ec_ioctl_config_pdo_t data;
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  1839
    ec_slave_config_t *sc;
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  1840
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  1841
	if (unlikely(!priv->requested))
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  1842
        return -EPERM;
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  1843
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  1844
    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
  1845
        return -EFAULT;
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  1846
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  1847
    if (down_interruptible(&master->master_sem))
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  1848
        return -EINTR;
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  1849
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  1850
    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
  1851
        up(&master->master_sem);
1313
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1312
diff changeset
  1852
        return -ENOENT;
1255
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  1853
    }
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  1854
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  1855
    up(&master->master_sem); // FIXME
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  1856
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  1857
    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
  1858
    return 0;
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  1859
}
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  1860
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  1861
/*****************************************************************************/
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  1862
1327
4d179b06dd3c merge -c1604 branches/stable-1.4: Fixed spelling of EtherCAT terms.
Florian Pose <fp@igh-essen.com>
parents: 1326
diff changeset
  1863
/** Registers a PDO entry.
1255
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  1864
 */
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  1865
int ec_cdev_ioctl_sc_reg_pdo_entry(
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  1866
        ec_master_t *master, /**< EtherCAT master. */
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  1867
        unsigned long arg, /**< ioctl() argument. */
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  1868
        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
  1869
        )
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  1870
{
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  1871
    ec_ioctl_reg_pdo_entry_t data;
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  1872
    ec_slave_config_t *sc;
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  1873
    ec_domain_t *domain;
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  1874
    int ret;
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  1875
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  1876
	if (unlikely(!priv->requested))
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  1877
        return -EPERM;
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  1878
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  1879
    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
  1880
        return -EFAULT;
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  1881
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  1882
    if (down_interruptible(&master->master_sem))
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  1883
        return -EINTR;
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  1884
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  1885
    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
  1886
        up(&master->master_sem);
1313
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1312
diff changeset
  1887
        return -ENOENT;
1255
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  1888
    }
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  1889
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  1890
    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
  1891
        up(&master->master_sem);
1313
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1312
diff changeset
  1892
        return -ENOENT;
1255
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  1893
    }
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  1894
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  1895
    up(&master->master_sem); // FIXME
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  1896
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  1897
    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
  1898
            data.entry_subindex, domain, &data.bit_position);
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  1899
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  1900
    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
  1901
        return -EFAULT;
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  1902
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  1903
    return ret;
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  1904
}
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  1905
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  1906
/*****************************************************************************/
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  1907
1448
d7ba0c408a07 Merged ecrt_slave_config_dc_assign_activate() and
Florian Pose <fp@igh-essen.com>
parents: 1447
diff changeset
  1908
/** 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
  1909
 */
d7ba0c408a07 Merged ecrt_slave_config_dc_assign_activate() and
Florian Pose <fp@igh-essen.com>
parents: 1447
diff changeset
  1910
int ec_cdev_ioctl_sc_dc(
1413
44c2b7c0ae1a Userspace library implementation of DC functions.
Florian Pose <fp@igh-essen.com>
parents: 1401
diff changeset
  1911
        ec_master_t *master, /**< EtherCAT master. */
44c2b7c0ae1a Userspace library implementation of DC functions.
Florian Pose <fp@igh-essen.com>
parents: 1401
diff changeset
  1912
        unsigned long arg, /**< ioctl() argument. */
44c2b7c0ae1a Userspace library implementation of DC functions.
Florian Pose <fp@igh-essen.com>
parents: 1401
diff changeset
  1913
        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
  1914
        )
44c2b7c0ae1a Userspace library implementation of DC functions.
Florian Pose <fp@igh-essen.com>
parents: 1401
diff changeset
  1915
{
44c2b7c0ae1a Userspace library implementation of DC functions.
Florian Pose <fp@igh-essen.com>
parents: 1401
diff changeset
  1916
    ec_ioctl_sc_dc_t data;
44c2b7c0ae1a Userspace library implementation of DC functions.
Florian Pose <fp@igh-essen.com>
parents: 1401
diff changeset
  1917
    ec_slave_config_t *sc;
44c2b7c0ae1a Userspace library implementation of DC functions.
Florian Pose <fp@igh-essen.com>
parents: 1401
diff changeset
  1918
44c2b7c0ae1a Userspace library implementation of DC functions.
Florian Pose <fp@igh-essen.com>
parents: 1401
diff changeset
  1919
	if (unlikely(!priv->requested))
44c2b7c0ae1a Userspace library implementation of DC functions.
Florian Pose <fp@igh-essen.com>
parents: 1401
diff changeset
  1920
        return -EPERM;
44c2b7c0ae1a Userspace library implementation of DC functions.
Florian Pose <fp@igh-essen.com>
parents: 1401
diff changeset
  1921
44c2b7c0ae1a Userspace library implementation of DC functions.
Florian Pose <fp@igh-essen.com>
parents: 1401
diff changeset
  1922
    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
  1923
        return -EFAULT;
44c2b7c0ae1a Userspace library implementation of DC functions.
Florian Pose <fp@igh-essen.com>
parents: 1401
diff changeset
  1924
44c2b7c0ae1a Userspace library implementation of DC functions.
Florian Pose <fp@igh-essen.com>
parents: 1401
diff changeset
  1925
    if (down_interruptible(&master->master_sem))
44c2b7c0ae1a Userspace library implementation of DC functions.
Florian Pose <fp@igh-essen.com>
parents: 1401
diff changeset
  1926
        return -EINTR;
44c2b7c0ae1a Userspace library implementation of DC functions.
Florian Pose <fp@igh-essen.com>
parents: 1401
diff changeset
  1927
44c2b7c0ae1a Userspace library implementation of DC functions.
Florian Pose <fp@igh-essen.com>
parents: 1401
diff changeset
  1928
    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
  1929
        up(&master->master_sem);
44c2b7c0ae1a Userspace library implementation of DC functions.
Florian Pose <fp@igh-essen.com>
parents: 1401
diff changeset
  1930
        return -ENOENT;
44c2b7c0ae1a Userspace library implementation of DC functions.
Florian Pose <fp@igh-essen.com>
parents: 1401
diff changeset
  1931
    }
44c2b7c0ae1a Userspace library implementation of DC functions.
Florian Pose <fp@igh-essen.com>
parents: 1401
diff changeset
  1932
1448
d7ba0c408a07 Merged ecrt_slave_config_dc_assign_activate() and
Florian Pose <fp@igh-essen.com>
parents: 1447
diff changeset
  1933
    ecrt_slave_config_dc(sc, data.assign_activate,
1438
1d30b96bb04f Replaced ecrt_slave_config_dc_cycle_times() and ecrt_slave_config_dc_shift_times() by ecrt_slave_config_dc_sync_signals().
Florian Pose <fp@igh-essen.com>
parents: 1435
diff changeset
  1934
            data.sync[0].cycle_time,
1d30b96bb04f Replaced ecrt_slave_config_dc_cycle_times() and ecrt_slave_config_dc_shift_times() by ecrt_slave_config_dc_sync_signals().
Florian Pose <fp@igh-essen.com>
parents: 1435
diff changeset
  1935
            data.sync[0].shift_time,
1d30b96bb04f Replaced ecrt_slave_config_dc_cycle_times() and ecrt_slave_config_dc_shift_times() by ecrt_slave_config_dc_sync_signals().
Florian Pose <fp@igh-essen.com>
parents: 1435
diff changeset
  1936
            data.sync[1].cycle_time,
1d30b96bb04f Replaced ecrt_slave_config_dc_cycle_times() and ecrt_slave_config_dc_shift_times() by ecrt_slave_config_dc_sync_signals().
Florian Pose <fp@igh-essen.com>
parents: 1435
diff changeset
  1937
            data.sync[1].shift_time);
1413
44c2b7c0ae1a Userspace library implementation of DC functions.
Florian Pose <fp@igh-essen.com>
parents: 1401
diff changeset
  1938
44c2b7c0ae1a Userspace library implementation of DC functions.
Florian Pose <fp@igh-essen.com>
parents: 1401
diff changeset
  1939
    up(&master->master_sem);
44c2b7c0ae1a Userspace library implementation of DC functions.
Florian Pose <fp@igh-essen.com>
parents: 1401
diff changeset
  1940
44c2b7c0ae1a Userspace library implementation of DC functions.
Florian Pose <fp@igh-essen.com>
parents: 1401
diff changeset
  1941
    return 0;
44c2b7c0ae1a Userspace library implementation of DC functions.
Florian Pose <fp@igh-essen.com>
parents: 1401
diff changeset
  1942
}
44c2b7c0ae1a Userspace library implementation of DC functions.
Florian Pose <fp@igh-essen.com>
parents: 1401
diff changeset
  1943
44c2b7c0ae1a Userspace library implementation of DC functions.
Florian Pose <fp@igh-essen.com>
parents: 1401
diff changeset
  1944
/*****************************************************************************/
44c2b7c0ae1a Userspace library implementation of DC functions.
Florian Pose <fp@igh-essen.com>
parents: 1401
diff changeset
  1945
1327
4d179b06dd3c merge -c1604 branches/stable-1.4: Fixed spelling of EtherCAT terms.
Florian Pose <fp@igh-essen.com>
parents: 1326
diff changeset
  1946
/** Configures an SDO.
1255
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  1947
 */
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  1948
int ec_cdev_ioctl_sc_sdo(
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  1949
        ec_master_t *master, /**< EtherCAT master. */
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  1950
        unsigned long arg, /**< ioctl() argument. */
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  1951
        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
  1952
        )
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  1953
{
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  1954
    ec_ioctl_sc_sdo_t data;
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  1955
    ec_slave_config_t *sc;
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  1956
    uint8_t *sdo_data = NULL;
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  1957
    int ret;
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
	if (unlikely(!priv->requested))
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  1960
        return -EPERM;
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
    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
  1963
        return -EFAULT;
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  1964
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  1965
    if (!data.size)
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  1966
        return -EINVAL;
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
    if (!(sdo_data = kmalloc(data.size, GFP_KERNEL))) {
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  1969
        return -ENOMEM;
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  1970
    }
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  1971
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  1972
    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
  1973
        kfree(sdo_data);
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  1974
        return -EFAULT;
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  1975
    }
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  1976
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  1977
    if (down_interruptible(&master->master_sem)) {
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  1978
        kfree(sdo_data);
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  1979
        return -EINTR;
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  1980
    }
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  1981
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  1982
    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
  1983
        up(&master->master_sem);
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  1984
        kfree(sdo_data);
1313
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1312
diff changeset
  1985
        return -ENOENT;
1255
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  1986
    }
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  1987
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  1988
    up(&master->master_sem); // FIXME
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  1989
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  1990
    ret = ecrt_slave_config_sdo(sc, data.index, data.subindex, sdo_data,
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  1991
            data.size);
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  1992
    kfree(sdo_data);
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  1993
    return ret;
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  1994
}
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  1995
1258
900f1124e8f8 Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents: 1255
diff changeset
  1996
/*****************************************************************************/
900f1124e8f8 Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents: 1255
diff changeset
  1997
1352
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1350
diff changeset
  1998
/** Create an SDO request.
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1350
diff changeset
  1999
 */
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1350
diff changeset
  2000
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
  2001
        ec_master_t *master, /**< EtherCAT master. */
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1350
diff changeset
  2002
        unsigned long arg, /**< ioctl() argument. */
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1350
diff changeset
  2003
        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
  2004
        )
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1350
diff changeset
  2005
{
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1350
diff changeset
  2006
    ec_ioctl_sdo_request_t data;
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1350
diff changeset
  2007
    ec_slave_config_t *sc;
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1350
diff changeset
  2008
    ec_sdo_request_t *req;
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1350
diff changeset
  2009
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1350
diff changeset
  2010
	if (unlikely(!priv->requested))
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1350
diff changeset
  2011
		return -EPERM;
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1350
diff changeset
  2012
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1350
diff changeset
  2013
    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
  2014
        return -EFAULT;
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1350
diff changeset
  2015
    }
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1350
diff changeset
  2016
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1350
diff changeset
  2017
    data.request_index = 0;
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1350
diff changeset
  2018
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1350
diff changeset
  2019
    if (down_interruptible(&master->master_sem))
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1350
diff changeset
  2020
        return -EINTR;
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1350
diff changeset
  2021
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1350
diff changeset
  2022
    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
  2023
    if (!sc) {
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1350
diff changeset
  2024
        up(&master->master_sem);
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1350
diff changeset
  2025
        return -ENOENT;
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1350
diff changeset
  2026
    }
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1350
diff changeset
  2027
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1350
diff changeset
  2028
    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
  2029
        data.request_index++;
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1350
diff changeset
  2030
    }
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1350
diff changeset
  2031
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1350
diff changeset
  2032
    up(&master->master_sem);
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1350
diff changeset
  2033
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1350
diff changeset
  2034
    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
  2035
            data.sdo_subindex, data.size);
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1350
diff changeset
  2036
    if (IS_ERR(req))
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1350
diff changeset
  2037
        return PTR_ERR(req);
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1350
diff changeset
  2038
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1350
diff changeset
  2039
    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
  2040
        return -EFAULT;
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1350
diff changeset
  2041
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1350
diff changeset
  2042
    return 0;
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1350
diff changeset
  2043
}
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1350
diff changeset
  2044
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1350
diff changeset
  2045
/*****************************************************************************/
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1350
diff changeset
  2046
1264
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  2047
/** Create a VoE handler.
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  2048
 */
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  2049
int ec_cdev_ioctl_sc_create_voe_handler(
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  2050
        ec_master_t *master, /**< EtherCAT master. */
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  2051
        unsigned long arg, /**< ioctl() argument. */
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  2052
        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
  2053
        )
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  2054
{
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  2055
    ec_ioctl_voe_t data;
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  2056
    ec_slave_config_t *sc;
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  2057
    ec_voe_handler_t *voe;
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  2058
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  2059
	if (unlikely(!priv->requested))
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  2060
		return -EPERM;
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  2061
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  2062
    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
  2063
        return -EFAULT;
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  2064
    }
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  2065
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  2066
    data.voe_index = 0;
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  2067
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  2068
    if (down_interruptible(&master->master_sem))
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  2069
        return -EINTR;
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  2070
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  2071
    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
  2072
    if (!sc) {
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  2073
        up(&master->master_sem);
1313
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1312
diff changeset
  2074
        return -ENOENT;
1264
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  2075
    }
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  2076
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  2077
    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
  2078
        data.voe_index++;
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  2079
    }
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  2080
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  2081
    up(&master->master_sem);
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  2082
1312
74853e018898 Created backend versions of all API functions returing a pointer; using
Florian Pose <fp@igh-essen.com>
parents: 1284
diff changeset
  2083
    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
  2084
    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
  2085
        return PTR_ERR(voe);
1264
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  2086
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  2087
    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
  2088
        return -EFAULT;
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  2089
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  2090
    return 0;
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  2091
}
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  2092
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  2093
/*****************************************************************************/
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  2094
1259
5f9d1abbee71 Added state functions; writing of process data works.
Florian Pose <fp@igh-essen.com>
parents: 1258
diff changeset
  2095
/** 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
  2096
 */
5f9d1abbee71 Added state functions; writing of process data works.
Florian Pose <fp@igh-essen.com>
parents: 1258
diff changeset
  2097
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
  2098
        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
  2099
        unsigned long arg, /**< ioctl() argument. */
5f9d1abbee71 Added state functions; writing of process data works.
Florian Pose <fp@igh-essen.com>
parents: 1258
diff changeset
  2100
        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
  2101
        )
5f9d1abbee71 Added state functions; writing of process data works.
Florian Pose <fp@igh-essen.com>
parents: 1258
diff changeset
  2102
{
5f9d1abbee71 Added state functions; writing of process data works.
Florian Pose <fp@igh-essen.com>
parents: 1258
diff changeset
  2103
    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
  2104
    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
  2105
    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
  2106
    
5f9d1abbee71 Added state functions; writing of process data works.
Florian Pose <fp@igh-essen.com>
parents: 1258
diff changeset
  2107
	if (unlikely(!priv->requested))
5f9d1abbee71 Added state functions; writing of process data works.
Florian Pose <fp@igh-essen.com>
parents: 1258
diff changeset
  2108
		return -EPERM;
5f9d1abbee71 Added state functions; writing of process data works.
Florian Pose <fp@igh-essen.com>
parents: 1258
diff changeset
  2109
5f9d1abbee71 Added state functions; writing of process data works.
Florian Pose <fp@igh-essen.com>
parents: 1258
diff changeset
  2110
    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
  2111
        return -EFAULT;
5f9d1abbee71 Added state functions; writing of process data works.
Florian Pose <fp@igh-essen.com>
parents: 1258
diff changeset
  2112
    }
5f9d1abbee71 Added state functions; writing of process data works.
Florian Pose <fp@igh-essen.com>
parents: 1258
diff changeset
  2113
5f9d1abbee71 Added state functions; writing of process data works.
Florian Pose <fp@igh-essen.com>
parents: 1258
diff changeset
  2114
    if (down_interruptible(&master->master_sem))
5f9d1abbee71 Added state functions; writing of process data works.
Florian Pose <fp@igh-essen.com>
parents: 1258
diff changeset
  2115
        return -EINTR;
5f9d1abbee71 Added state functions; writing of process data works.
Florian Pose <fp@igh-essen.com>
parents: 1258
diff changeset
  2116
5f9d1abbee71 Added state functions; writing of process data works.
Florian Pose <fp@igh-essen.com>
parents: 1258
diff changeset
  2117
    if (!(sc = ec_master_get_config_const(master, data.config_index))) {
5f9d1abbee71 Added state functions; writing of process data works.
Florian Pose <fp@igh-essen.com>
parents: 1258
diff changeset
  2118
        up(&master->master_sem);
1313
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1312
diff changeset
  2119
        return -ENOENT;
1259
5f9d1abbee71 Added state functions; writing of process data works.
Florian Pose <fp@igh-essen.com>
parents: 1258
diff changeset
  2120
    }
5f9d1abbee71 Added state functions; writing of process data works.
Florian Pose <fp@igh-essen.com>
parents: 1258
diff changeset
  2121
5f9d1abbee71 Added state functions; writing of process data works.
Florian Pose <fp@igh-essen.com>
parents: 1258
diff changeset
  2122
    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
  2123
5f9d1abbee71 Added state functions; writing of process data works.
Florian Pose <fp@igh-essen.com>
parents: 1258
diff changeset
  2124
    up(&master->master_sem);
5f9d1abbee71 Added state functions; writing of process data works.
Florian Pose <fp@igh-essen.com>
parents: 1258
diff changeset
  2125
5f9d1abbee71 Added state functions; writing of process data works.
Florian Pose <fp@igh-essen.com>
parents: 1258
diff changeset
  2126
    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
  2127
        return -EFAULT;
5f9d1abbee71 Added state functions; writing of process data works.
Florian Pose <fp@igh-essen.com>
parents: 1258
diff changeset
  2128
5f9d1abbee71 Added state functions; writing of process data works.
Florian Pose <fp@igh-essen.com>
parents: 1258
diff changeset
  2129
    return 0;
5f9d1abbee71 Added state functions; writing of process data works.
Florian Pose <fp@igh-essen.com>
parents: 1258
diff changeset
  2130
}
5f9d1abbee71 Added state functions; writing of process data works.
Florian Pose <fp@igh-essen.com>
parents: 1258
diff changeset
  2131
5f9d1abbee71 Added state functions; writing of process data works.
Florian Pose <fp@igh-essen.com>
parents: 1258
diff changeset
  2132
/*****************************************************************************/
5f9d1abbee71 Added state functions; writing of process data works.
Florian Pose <fp@igh-essen.com>
parents: 1258
diff changeset
  2133
1258
900f1124e8f8 Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents: 1255
diff changeset
  2134
/** 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
  2135
 */
900f1124e8f8 Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents: 1255
diff changeset
  2136
int ec_cdev_ioctl_domain_offset(
900f1124e8f8 Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents: 1255
diff changeset
  2137
        ec_master_t *master, /**< EtherCAT master. */
900f1124e8f8 Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents: 1255
diff changeset
  2138
        unsigned long arg, /**< ioctl() argument. */
900f1124e8f8 Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents: 1255
diff changeset
  2139
        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
  2140
        )
900f1124e8f8 Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents: 1255
diff changeset
  2141
{
900f1124e8f8 Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents: 1255
diff changeset
  2142
    int offset = 0;
900f1124e8f8 Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents: 1255
diff changeset
  2143
    const ec_domain_t *domain;
900f1124e8f8 Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents: 1255
diff changeset
  2144
900f1124e8f8 Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents: 1255
diff changeset
  2145
	if (unlikely(!priv->requested))
900f1124e8f8 Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents: 1255
diff changeset
  2146
        return -EPERM;
900f1124e8f8 Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents: 1255
diff changeset
  2147
900f1124e8f8 Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents: 1255
diff changeset
  2148
    if (down_interruptible(&master->master_sem)) {
900f1124e8f8 Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents: 1255
diff changeset
  2149
        return -EINTR;
900f1124e8f8 Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents: 1255
diff changeset
  2150
    }
900f1124e8f8 Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents: 1255
diff changeset
  2151
900f1124e8f8 Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents: 1255
diff changeset
  2152
    list_for_each_entry(domain, &master->domains, list) {
900f1124e8f8 Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents: 1255
diff changeset
  2153
        if (domain->index == arg) {
900f1124e8f8 Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents: 1255
diff changeset
  2154
            up(&master->master_sem);
900f1124e8f8 Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents: 1255
diff changeset
  2155
            return offset;
900f1124e8f8 Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents: 1255
diff changeset
  2156
        }
900f1124e8f8 Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents: 1255
diff changeset
  2157
        offset += ecrt_domain_size(domain);
900f1124e8f8 Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents: 1255
diff changeset
  2158
    }
900f1124e8f8 Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents: 1255
diff changeset
  2159
900f1124e8f8 Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents: 1255
diff changeset
  2160
    up(&master->master_sem);
1313
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1312
diff changeset
  2161
    return -ENOENT;
1258
900f1124e8f8 Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents: 1255
diff changeset
  2162
}
900f1124e8f8 Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents: 1255
diff changeset
  2163
900f1124e8f8 Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents: 1255
diff changeset
  2164
/*****************************************************************************/
900f1124e8f8 Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents: 1255
diff changeset
  2165
900f1124e8f8 Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents: 1255
diff changeset
  2166
/** Process the domain.
900f1124e8f8 Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents: 1255
diff changeset
  2167
 */
900f1124e8f8 Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents: 1255
diff changeset
  2168
int ec_cdev_ioctl_domain_process(
900f1124e8f8 Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents: 1255
diff changeset
  2169
        ec_master_t *master, /**< EtherCAT master. */
900f1124e8f8 Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents: 1255
diff changeset
  2170
        unsigned long arg, /**< ioctl() argument. */
900f1124e8f8 Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents: 1255
diff changeset
  2171
        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
  2172
        )
900f1124e8f8 Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents: 1255
diff changeset
  2173
{
900f1124e8f8 Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents: 1255
diff changeset
  2174
    ec_domain_t *domain;
900f1124e8f8 Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents: 1255
diff changeset
  2175
900f1124e8f8 Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents: 1255
diff changeset
  2176
	if (unlikely(!priv->requested))
900f1124e8f8 Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents: 1255
diff changeset
  2177
        return -EPERM;
900f1124e8f8 Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents: 1255
diff changeset
  2178
900f1124e8f8 Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents: 1255
diff changeset
  2179
    if (down_interruptible(&master->master_sem))
900f1124e8f8 Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents: 1255
diff changeset
  2180
        return -EINTR;
900f1124e8f8 Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents: 1255
diff changeset
  2181
900f1124e8f8 Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents: 1255
diff changeset
  2182
    if (!(domain = ec_master_find_domain(master, arg))) {
900f1124e8f8 Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents: 1255
diff changeset
  2183
        up(&master->master_sem);
1313
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1312
diff changeset
  2184
        return -ENOENT;
1258
900f1124e8f8 Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents: 1255
diff changeset
  2185
    }
900f1124e8f8 Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents: 1255
diff changeset
  2186
900f1124e8f8 Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents: 1255
diff changeset
  2187
    ecrt_domain_process(domain);
900f1124e8f8 Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents: 1255
diff changeset
  2188
    up(&master->master_sem);
900f1124e8f8 Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents: 1255
diff changeset
  2189
    return 0;
900f1124e8f8 Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents: 1255
diff changeset
  2190
}
900f1124e8f8 Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents: 1255
diff changeset
  2191
900f1124e8f8 Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents: 1255
diff changeset
  2192
/*****************************************************************************/
900f1124e8f8 Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents: 1255
diff changeset
  2193
900f1124e8f8 Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents: 1255
diff changeset
  2194
/** Queue the domain.
900f1124e8f8 Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents: 1255
diff changeset
  2195
 */
900f1124e8f8 Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents: 1255
diff changeset
  2196
int ec_cdev_ioctl_domain_queue(
900f1124e8f8 Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents: 1255
diff changeset
  2197
        ec_master_t *master, /**< EtherCAT master. */
900f1124e8f8 Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents: 1255
diff changeset
  2198
        unsigned long arg, /**< ioctl() argument. */
900f1124e8f8 Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents: 1255
diff changeset
  2199
        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
  2200
        )
900f1124e8f8 Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents: 1255
diff changeset
  2201
{
900f1124e8f8 Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents: 1255
diff changeset
  2202
    ec_domain_t *domain;
900f1124e8f8 Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents: 1255
diff changeset
  2203
900f1124e8f8 Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents: 1255
diff changeset
  2204
	if (unlikely(!priv->requested))
900f1124e8f8 Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents: 1255
diff changeset
  2205
        return -EPERM;
900f1124e8f8 Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents: 1255
diff changeset
  2206
900f1124e8f8 Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents: 1255
diff changeset
  2207
    if (down_interruptible(&master->master_sem))
900f1124e8f8 Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents: 1255
diff changeset
  2208
        return -EINTR;
900f1124e8f8 Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents: 1255
diff changeset
  2209
900f1124e8f8 Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents: 1255
diff changeset
  2210
    if (!(domain = ec_master_find_domain(master, arg))) {
900f1124e8f8 Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents: 1255
diff changeset
  2211
        up(&master->master_sem);
1313
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1312
diff changeset
  2212
        return -ENOENT;
1258
900f1124e8f8 Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents: 1255
diff changeset
  2213
    }
900f1124e8f8 Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents: 1255
diff changeset
  2214
900f1124e8f8 Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents: 1255
diff changeset
  2215
    ecrt_domain_queue(domain);
900f1124e8f8 Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents: 1255
diff changeset
  2216
    up(&master->master_sem);
900f1124e8f8 Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents: 1255
diff changeset
  2217
    return 0;
900f1124e8f8 Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents: 1255
diff changeset
  2218
}
900f1124e8f8 Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents: 1255
diff changeset
  2219
1259
5f9d1abbee71 Added state functions; writing of process data works.
Florian Pose <fp@igh-essen.com>
parents: 1258
diff changeset
  2220
/*****************************************************************************/
5f9d1abbee71 Added state functions; writing of process data works.
Florian Pose <fp@igh-essen.com>
parents: 1258
diff changeset
  2221
5f9d1abbee71 Added state functions; writing of process data works.
Florian Pose <fp@igh-essen.com>
parents: 1258
diff changeset
  2222
/** Get the domain state.
5f9d1abbee71 Added state functions; writing of process data works.
Florian Pose <fp@igh-essen.com>
parents: 1258
diff changeset
  2223
 */
5f9d1abbee71 Added state functions; writing of process data works.
Florian Pose <fp@igh-essen.com>
parents: 1258
diff changeset
  2224
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
  2225
        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
  2226
        unsigned long arg, /**< ioctl() argument. */
5f9d1abbee71 Added state functions; writing of process data works.
Florian Pose <fp@igh-essen.com>
parents: 1258
diff changeset
  2227
        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
  2228
        )
5f9d1abbee71 Added state functions; writing of process data works.
Florian Pose <fp@igh-essen.com>
parents: 1258
diff changeset
  2229
{
5f9d1abbee71 Added state functions; writing of process data works.
Florian Pose <fp@igh-essen.com>
parents: 1258
diff changeset
  2230
    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
  2231
    const ec_domain_t *domain;
5f9d1abbee71 Added state functions; writing of process data works.
Florian Pose <fp@igh-essen.com>
parents: 1258
diff changeset
  2232
    ec_domain_state_t state;
5f9d1abbee71 Added state functions; writing of process data works.
Florian Pose <fp@igh-essen.com>
parents: 1258
diff changeset
  2233
    
5f9d1abbee71 Added state functions; writing of process data works.
Florian Pose <fp@igh-essen.com>
parents: 1258
diff changeset
  2234
	if (unlikely(!priv->requested))
5f9d1abbee71 Added state functions; writing of process data works.
Florian Pose <fp@igh-essen.com>
parents: 1258
diff changeset
  2235
		return -EPERM;
5f9d1abbee71 Added state functions; writing of process data works.
Florian Pose <fp@igh-essen.com>
parents: 1258
diff changeset
  2236
5f9d1abbee71 Added state functions; writing of process data works.
Florian Pose <fp@igh-essen.com>
parents: 1258
diff changeset
  2237
    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
  2238
        return -EFAULT;
5f9d1abbee71 Added state functions; writing of process data works.
Florian Pose <fp@igh-essen.com>
parents: 1258
diff changeset
  2239
    }
5f9d1abbee71 Added state functions; writing of process data works.
Florian Pose <fp@igh-essen.com>
parents: 1258
diff changeset
  2240
5f9d1abbee71 Added state functions; writing of process data works.
Florian Pose <fp@igh-essen.com>
parents: 1258
diff changeset
  2241
    if (down_interruptible(&master->master_sem))
5f9d1abbee71 Added state functions; writing of process data works.
Florian Pose <fp@igh-essen.com>
parents: 1258
diff changeset
  2242
        return -EINTR;
5f9d1abbee71 Added state functions; writing of process data works.
Florian Pose <fp@igh-essen.com>
parents: 1258
diff changeset
  2243
5f9d1abbee71 Added state functions; writing of process data works.
Florian Pose <fp@igh-essen.com>
parents: 1258
diff changeset
  2244
    if (!(domain = ec_master_find_domain_const(master, data.domain_index))) {
5f9d1abbee71 Added state functions; writing of process data works.
Florian Pose <fp@igh-essen.com>
parents: 1258
diff changeset
  2245
        up(&master->master_sem);
1313
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1312
diff changeset
  2246
        return -ENOENT;
1259
5f9d1abbee71 Added state functions; writing of process data works.
Florian Pose <fp@igh-essen.com>
parents: 1258
diff changeset
  2247
    }
5f9d1abbee71 Added state functions; writing of process data works.
Florian Pose <fp@igh-essen.com>
parents: 1258
diff changeset
  2248
5f9d1abbee71 Added state functions; writing of process data works.
Florian Pose <fp@igh-essen.com>
parents: 1258
diff changeset
  2249
    ecrt_domain_state(domain, &state);
5f9d1abbee71 Added state functions; writing of process data works.
Florian Pose <fp@igh-essen.com>
parents: 1258
diff changeset
  2250
5f9d1abbee71 Added state functions; writing of process data works.
Florian Pose <fp@igh-essen.com>
parents: 1258
diff changeset
  2251
    up(&master->master_sem);
5f9d1abbee71 Added state functions; writing of process data works.
Florian Pose <fp@igh-essen.com>
parents: 1258
diff changeset
  2252
5f9d1abbee71 Added state functions; writing of process data works.
Florian Pose <fp@igh-essen.com>
parents: 1258
diff changeset
  2253
    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
  2254
        return -EFAULT;
5f9d1abbee71 Added state functions; writing of process data works.
Florian Pose <fp@igh-essen.com>
parents: 1258
diff changeset
  2255
5f9d1abbee71 Added state functions; writing of process data works.
Florian Pose <fp@igh-essen.com>
parents: 1258
diff changeset
  2256
    return 0;
5f9d1abbee71 Added state functions; writing of process data works.
Florian Pose <fp@igh-essen.com>
parents: 1258
diff changeset
  2257
}
5f9d1abbee71 Added state functions; writing of process data works.
Florian Pose <fp@igh-essen.com>
parents: 1258
diff changeset
  2258
1264
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  2259
/*****************************************************************************/
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  2260
1352
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1350
diff changeset
  2261
/** Sets an SDO request's timeout.
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1350
diff changeset
  2262
 */
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1350
diff changeset
  2263
int ec_cdev_ioctl_sdo_request_timeout(
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1350
diff changeset
  2264
        ec_master_t *master, /**< EtherCAT master. */
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1350
diff changeset
  2265
        unsigned long arg, /**< ioctl() argument. */
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1350
diff changeset
  2266
        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
  2267
        )
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1350
diff changeset
  2268
{
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1350
diff changeset
  2269
    ec_ioctl_sdo_request_t data;
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1350
diff changeset
  2270
    ec_slave_config_t *sc;
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1350
diff changeset
  2271
    ec_sdo_request_t *req;
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1350
diff changeset
  2272
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1350
diff changeset
  2273
	if (unlikely(!priv->requested))
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1350
diff changeset
  2274
        return -EPERM;
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1350
diff changeset
  2275
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1350
diff changeset
  2276
    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
  2277
        return -EFAULT;
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1350
diff changeset
  2278
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1350
diff changeset
  2279
    if (down_interruptible(&master->master_sem))
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1350
diff changeset
  2280
        return -EINTR;
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1350
diff changeset
  2281
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1350
diff changeset
  2282
    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
  2283
        up(&master->master_sem);
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1350
diff changeset
  2284
        return -ENOENT;
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
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1350
diff changeset
  2287
    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
  2288
        up(&master->master_sem);
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1350
diff changeset
  2289
        return -ENOENT;
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
    up(&master->master_sem);
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1350
diff changeset
  2293
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1350
diff changeset
  2294
    ecrt_sdo_request_timeout(req, data.timeout);
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1350
diff changeset
  2295
    return 0;
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1350
diff changeset
  2296
}
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1350
diff changeset
  2297
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
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1350
diff changeset
  2300
/** Gets an SDO request's state.
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
int ec_cdev_ioctl_sdo_request_state(
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1350
diff changeset
  2303
        ec_master_t *master, /**< EtherCAT master. */
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1350
diff changeset
  2304
        unsigned long arg, /**< ioctl() argument. */
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1350
diff changeset
  2305
        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
  2306
        )
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
    ec_ioctl_sdo_request_t data;
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1350
diff changeset
  2309
    ec_slave_config_t *sc;
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1350
diff changeset
  2310
    ec_sdo_request_t *req;
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1350
diff changeset
  2311
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1350
diff changeset
  2312
	if (unlikely(!priv->requested))
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1350
diff changeset
  2313
        return -EPERM;
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1350
diff changeset
  2314
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1350
diff changeset
  2315
    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
  2316
        return -EFAULT;
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1350
diff changeset
  2317
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1350
diff changeset
  2318
    if (down_interruptible(&master->master_sem))
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1350
diff changeset
  2319
        return -EINTR;
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1350
diff changeset
  2320
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1350
diff changeset
  2321
    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
  2322
        up(&master->master_sem);
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1350
diff changeset
  2323
        return -ENOENT;
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
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1350
diff changeset
  2326
    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
  2327
        up(&master->master_sem);
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1350
diff changeset
  2328
        return -ENOENT;
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
    data.state = ecrt_sdo_request_state(req);
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1350
diff changeset
  2332
    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
  2333
        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
  2334
    else
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1350
diff changeset
  2335
        data.size = 0;
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1350
diff changeset
  2336
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1350
diff changeset
  2337
    up(&master->master_sem);
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1350
diff changeset
  2338
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1350
diff changeset
  2339
    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
  2340
        return -EFAULT;
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1350
diff changeset
  2341
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1350
diff changeset
  2342
    return 0;
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1350
diff changeset
  2343
}
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1350
diff changeset
  2344
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1350
diff changeset
  2345
/*****************************************************************************/
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1350
diff changeset
  2346
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1350
diff changeset
  2347
/** Starts an SDO read operation.
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1350
diff changeset
  2348
 */
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1350
diff changeset
  2349
int ec_cdev_ioctl_sdo_request_read(
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1350
diff changeset
  2350
        ec_master_t *master, /**< EtherCAT master. */
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1350
diff changeset
  2351
        unsigned long arg, /**< ioctl() argument. */
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1350
diff changeset
  2352
        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
  2353
        )
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1350
diff changeset
  2354
{
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1350
diff changeset
  2355
    ec_ioctl_sdo_request_t data;
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1350
diff changeset
  2356
    ec_slave_config_t *sc;
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1350
diff changeset
  2357
    ec_sdo_request_t *req;
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1350
diff changeset
  2358
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1350
diff changeset
  2359
	if (unlikely(!priv->requested))
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1350
diff changeset
  2360
        return -EPERM;
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1350
diff changeset
  2361
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1350
diff changeset
  2362
    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
  2363
        return -EFAULT;
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1350
diff changeset
  2364
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1350
diff changeset
  2365
    if (down_interruptible(&master->master_sem))
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1350
diff changeset
  2366
        return -EINTR;
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1350
diff changeset
  2367
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1350
diff changeset
  2368
    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
  2369
        up(&master->master_sem);
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1350
diff changeset
  2370
        return -ENOENT;
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1350
diff changeset
  2371
    }
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1350
diff changeset
  2372
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1350
diff changeset
  2373
    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
  2374
        up(&master->master_sem);
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1350
diff changeset
  2375
        return -ENOENT;
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1350
diff changeset
  2376
    }
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1350
diff changeset
  2377
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1350
diff changeset
  2378
    up(&master->master_sem);
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1350
diff changeset
  2379
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1350
diff changeset
  2380
    ecrt_sdo_request_read(req);
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1350
diff changeset
  2381
    return 0;
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1350
diff changeset
  2382
}
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1350
diff changeset
  2383
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1350
diff changeset
  2384
/*****************************************************************************/
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1350
diff changeset
  2385
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1350
diff changeset
  2386
/** Starts an SDO write operation.
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1350
diff changeset
  2387
 */
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1350
diff changeset
  2388
int ec_cdev_ioctl_sdo_request_write(
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1350
diff changeset
  2389
        ec_master_t *master, /**< EtherCAT master. */
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1350
diff changeset
  2390
        unsigned long arg, /**< ioctl() argument. */
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1350
diff changeset
  2391
        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
  2392
        )
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1350
diff changeset
  2393
{
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1350
diff changeset
  2394
    ec_ioctl_sdo_request_t data;
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1350
diff changeset
  2395
    ec_slave_config_t *sc;
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1350
diff changeset
  2396
    ec_sdo_request_t *req;
1361
9c16b62326fa Fixed SDO download via library.
Florian Pose <fp@igh-essen.com>
parents: 1352
diff changeset
  2397
    int ret;
1352
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1350
diff changeset
  2398
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1350
diff changeset
  2399
	if (unlikely(!priv->requested))
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1350
diff changeset
  2400
        return -EPERM;
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1350
diff changeset
  2401
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1350
diff changeset
  2402
    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
  2403
        return -EFAULT;
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1350
diff changeset
  2404
1361
9c16b62326fa Fixed SDO download via library.
Florian Pose <fp@igh-essen.com>
parents: 1352
diff changeset
  2405
    if (!data.size) {
9c16b62326fa Fixed SDO download via library.
Florian Pose <fp@igh-essen.com>
parents: 1352
diff changeset
  2406
        EC_ERR("Sdo download: Data size may not be zero!\n");
9c16b62326fa Fixed SDO download via library.
Florian Pose <fp@igh-essen.com>
parents: 1352
diff changeset
  2407
        return -EINVAL;
9c16b62326fa Fixed SDO download via library.
Florian Pose <fp@igh-essen.com>
parents: 1352
diff changeset
  2408
    }
9c16b62326fa Fixed SDO download via library.
Florian Pose <fp@igh-essen.com>
parents: 1352
diff changeset
  2409
1352
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1350
diff changeset
  2410
    if (down_interruptible(&master->master_sem))
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1350
diff changeset
  2411
        return -EINTR;
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1350
diff changeset
  2412
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1350
diff changeset
  2413
    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
  2414
        up(&master->master_sem);
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1350
diff changeset
  2415
        return -ENOENT;
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1350
diff changeset
  2416
    }
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1350
diff changeset
  2417
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1350
diff changeset
  2418
    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
  2419
        up(&master->master_sem);
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1350
diff changeset
  2420
        return -ENOENT;
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1350
diff changeset
  2421
    }
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1350
diff changeset
  2422
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1350
diff changeset
  2423
    up(&master->master_sem);
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1350
diff changeset
  2424
1361
9c16b62326fa Fixed SDO download via library.
Florian Pose <fp@igh-essen.com>
parents: 1352
diff changeset
  2425
    ret = ec_sdo_request_alloc(req, data.size);
9c16b62326fa Fixed SDO download via library.
Florian Pose <fp@igh-essen.com>
parents: 1352
diff changeset
  2426
    if (ret)
9c16b62326fa Fixed SDO download via library.
Florian Pose <fp@igh-essen.com>
parents: 1352
diff changeset
  2427
        return ret;
9c16b62326fa Fixed SDO download via library.
Florian Pose <fp@igh-essen.com>
parents: 1352
diff changeset
  2428
9c16b62326fa Fixed SDO download via library.
Florian Pose <fp@igh-essen.com>
parents: 1352
diff changeset
  2429
    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
  2430
        return -EFAULT;
9c16b62326fa Fixed SDO download via library.
Florian Pose <fp@igh-essen.com>
parents: 1352
diff changeset
  2431
9c16b62326fa Fixed SDO download via library.
Florian Pose <fp@igh-essen.com>
parents: 1352
diff changeset
  2432
    req->data_size = data.size;
1352
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1350
diff changeset
  2433
    ecrt_sdo_request_write(req);
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1350
diff changeset
  2434
    return 0;
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1350
diff changeset
  2435
}
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1350
diff changeset
  2436
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1350
diff changeset
  2437
/*****************************************************************************/
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1350
diff changeset
  2438
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1350
diff changeset
  2439
/** Read SDO data.
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1350
diff changeset
  2440
 */
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1350
diff changeset
  2441
int ec_cdev_ioctl_sdo_request_data(
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1350
diff changeset
  2442
        ec_master_t *master, /**< EtherCAT master. */
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1350
diff changeset
  2443
        unsigned long arg, /**< ioctl() argument. */
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1350
diff changeset
  2444
        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
  2445
        )
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1350
diff changeset
  2446
{
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1350
diff changeset
  2447
    ec_ioctl_sdo_request_t data;
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1350
diff changeset
  2448
    ec_slave_config_t *sc;
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1350
diff changeset
  2449
    ec_sdo_request_t *req;
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1350
diff changeset
  2450
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1350
diff changeset
  2451
	if (unlikely(!priv->requested))
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1350
diff changeset
  2452
        return -EPERM;
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1350
diff changeset
  2453
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1350
diff changeset
  2454
    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
  2455
        return -EFAULT;
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1350
diff changeset
  2456
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1350
diff changeset
  2457
    if (down_interruptible(&master->master_sem))
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1350
diff changeset
  2458
        return -EINTR;
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1350
diff changeset
  2459
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1350
diff changeset
  2460
    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
  2461
        up(&master->master_sem);
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1350
diff changeset
  2462
        return -ENOENT;
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1350
diff changeset
  2463
    }
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1350
diff changeset
  2464
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1350
diff changeset
  2465
    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
  2466
        up(&master->master_sem);
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1350
diff changeset
  2467
        return -ENOENT;
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1350
diff changeset
  2468
    }
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1350
diff changeset
  2469
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1350
diff changeset
  2470
    up(&master->master_sem);
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1350
diff changeset
  2471
1362
2d6e0b01c80a Fixed SDO upload via library.
Florian Pose <fp@igh-essen.com>
parents: 1361
diff changeset
  2472
    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
  2473
                ecrt_sdo_request_data_size(req)))
2d6e0b01c80a Fixed SDO upload via library.
Florian Pose <fp@igh-essen.com>
parents: 1361
diff changeset
  2474
        return -EFAULT;
2d6e0b01c80a Fixed SDO upload via library.
Florian Pose <fp@igh-essen.com>
parents: 1361
diff changeset
  2475
1352
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1350
diff changeset
  2476
    return 0;
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1350
diff changeset
  2477
}
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1350
diff changeset
  2478
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1350
diff changeset
  2479
/*****************************************************************************/
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1350
diff changeset
  2480
1264
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  2481
/** Sets the VoE send header.
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  2482
 */
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  2483
int ec_cdev_ioctl_voe_send_header(
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  2484
        ec_master_t *master, /**< EtherCAT master. */
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  2485
        unsigned long arg, /**< ioctl() argument. */
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  2486
        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
  2487
        )
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  2488
{
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  2489
    ec_ioctl_voe_t data;
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  2490
    ec_slave_config_t *sc;
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  2491
    ec_voe_handler_t *voe;
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  2492
    uint32_t vendor_id;
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  2493
    uint16_t vendor_type;
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  2494
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  2495
	if (unlikely(!priv->requested))
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  2496
        return -EPERM;
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  2497
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  2498
    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
  2499
        return -EFAULT;
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  2500
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  2501
    if (get_user(vendor_id, data.vendor_id))
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  2502
        return -EFAULT;
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  2503
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  2504
    if (get_user(vendor_type, data.vendor_type))
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  2505
        return -EFAULT;
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  2506
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  2507
    if (down_interruptible(&master->master_sem))
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  2508
        return -EINTR;
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  2509
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  2510
    if (!(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
  2511
        up(&master->master_sem);
1313
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1312
diff changeset
  2512
        return -ENOENT;
1264
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  2513
    }
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  2514
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  2515
    if (!(voe = ec_slave_config_find_voe_handler(sc, data.voe_index))) {
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  2516
        up(&master->master_sem);
1313
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1312
diff changeset
  2517
        return -ENOENT;
1264
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  2518
    }
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  2519
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  2520
    up(&master->master_sem);
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  2521
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  2522
    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
  2523
    return 0;
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  2524
}
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  2525
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  2526
/*****************************************************************************/
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  2527
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  2528
/** Gets the received VoE header.
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  2529
 */
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  2530
int ec_cdev_ioctl_voe_rec_header(
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  2531
        ec_master_t *master, /**< EtherCAT master. */
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  2532
        unsigned long arg, /**< ioctl() argument. */
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  2533
        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
  2534
        )
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  2535
{
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  2536
    ec_ioctl_voe_t data;
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  2537
    ec_slave_config_t *sc;
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  2538
    ec_voe_handler_t *voe;
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  2539
    uint32_t vendor_id;
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  2540
    uint16_t vendor_type;
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  2541
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  2542
	if (unlikely(!priv->requested))
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  2543
        return -EPERM;
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  2544
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  2545
    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
  2546
        return -EFAULT;
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  2547
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  2548
    if (down_interruptible(&master->master_sem))
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  2549
        return -EINTR;
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  2550
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  2551
    if (!(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
  2552
        up(&master->master_sem);
1313
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1312
diff changeset
  2553
        return -ENOENT;
1264
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  2554
    }
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  2555
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  2556
    if (!(voe = ec_slave_config_find_voe_handler(sc, data.voe_index))) {
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  2557
        up(&master->master_sem);
1313
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1312
diff changeset
  2558
        return -ENOENT;
1264
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  2559
    }
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  2560
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  2561
    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
  2562
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  2563
    up(&master->master_sem);
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  2564
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  2565
    if (likely(data.vendor_id))
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  2566
        if (put_user(vendor_id, data.vendor_id))
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  2567
            return -EFAULT;
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  2568
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  2569
    if (likely(data.vendor_type))
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  2570
        if (put_user(vendor_type, data.vendor_type))
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  2571
            return -EFAULT;
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  2572
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  2573
    return 0;
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  2574
}
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  2575
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  2576
/*****************************************************************************/
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  2577
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  2578
/** Starts a VoE read operation.
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  2579
 */
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  2580
int ec_cdev_ioctl_voe_read(
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  2581
        ec_master_t *master, /**< EtherCAT master. */
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  2582
        unsigned long arg, /**< ioctl() argument. */
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  2583
        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
  2584
        )
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  2585
{
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  2586
    ec_ioctl_voe_t data;
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  2587
    ec_slave_config_t *sc;
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  2588
    ec_voe_handler_t *voe;
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  2589
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  2590
	if (unlikely(!priv->requested))
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  2591
        return -EPERM;
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  2592
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  2593
    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
  2594
        return -EFAULT;
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  2595
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  2596
    if (down_interruptible(&master->master_sem))
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  2597
        return -EINTR;
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  2598
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  2599
    if (!(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
  2600
        up(&master->master_sem);
1313
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1312
diff changeset
  2601
        return -ENOENT;
1264
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  2602
    }
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  2603
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  2604
    if (!(voe = ec_slave_config_find_voe_handler(sc, data.voe_index))) {
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  2605
        up(&master->master_sem);
1313
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1312
diff changeset
  2606
        return -ENOENT;
1264
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  2607
    }
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  2608
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  2609
    up(&master->master_sem);
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  2610
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  2611
    ecrt_voe_handler_read(voe);
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  2612
    return 0;
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  2613
}
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  2614
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  2615
/*****************************************************************************/
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  2616
1314
b3d06a8807b3 Included ecrt_voe_handler_read_nosync()-Patch by Mathias Weber.
Florian Pose <fp@igh-essen.com>
parents: 1313
diff changeset
  2617
/** 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
  2618
 */
b3d06a8807b3 Included ecrt_voe_handler_read_nosync()-Patch by Mathias Weber.
Florian Pose <fp@igh-essen.com>
parents: 1313
diff changeset
  2619
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
  2620
        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
  2621
        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
  2622
        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
  2623
        )
b3d06a8807b3 Included ecrt_voe_handler_read_nosync()-Patch by Mathias Weber.
Florian Pose <fp@igh-essen.com>
parents: 1313
diff changeset
  2624
{
b3d06a8807b3 Included ecrt_voe_handler_read_nosync()-Patch by Mathias Weber.
Florian Pose <fp@igh-essen.com>
parents: 1313
diff changeset
  2625
    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
  2626
    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
  2627
    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
  2628
b3d06a8807b3 Included ecrt_voe_handler_read_nosync()-Patch by Mathias Weber.
Florian Pose <fp@igh-essen.com>
parents: 1313
diff changeset
  2629
	if (unlikely(!priv->requested))
b3d06a8807b3 Included ecrt_voe_handler_read_nosync()-Patch by Mathias Weber.
Florian Pose <fp@igh-essen.com>
parents: 1313
diff changeset
  2630
        return -EPERM;
b3d06a8807b3 Included ecrt_voe_handler_read_nosync()-Patch by Mathias Weber.
Florian Pose <fp@igh-essen.com>
parents: 1313
diff changeset
  2631
b3d06a8807b3 Included ecrt_voe_handler_read_nosync()-Patch by Mathias Weber.
Florian Pose <fp@igh-essen.com>
parents: 1313
diff changeset
  2632
    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
  2633
        return -EFAULT;
b3d06a8807b3 Included ecrt_voe_handler_read_nosync()-Patch by Mathias Weber.
Florian Pose <fp@igh-essen.com>
parents: 1313
diff changeset
  2634
b3d06a8807b3 Included ecrt_voe_handler_read_nosync()-Patch by Mathias Weber.
Florian Pose <fp@igh-essen.com>
parents: 1313
diff changeset
  2635
    if (down_interruptible(&master->master_sem))
b3d06a8807b3 Included ecrt_voe_handler_read_nosync()-Patch by Mathias Weber.
Florian Pose <fp@igh-essen.com>
parents: 1313
diff changeset
  2636
        return -EINTR;
b3d06a8807b3 Included ecrt_voe_handler_read_nosync()-Patch by Mathias Weber.
Florian Pose <fp@igh-essen.com>
parents: 1313
diff changeset
  2637
b3d06a8807b3 Included ecrt_voe_handler_read_nosync()-Patch by Mathias Weber.
Florian Pose <fp@igh-essen.com>
parents: 1313
diff changeset
  2638
    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
  2639
        up(&master->master_sem);
b3d06a8807b3 Included ecrt_voe_handler_read_nosync()-Patch by Mathias Weber.
Florian Pose <fp@igh-essen.com>
parents: 1313
diff changeset
  2640
        return -ENOENT;
b3d06a8807b3 Included ecrt_voe_handler_read_nosync()-Patch by Mathias Weber.
Florian Pose <fp@igh-essen.com>
parents: 1313
diff changeset
  2641
    }
b3d06a8807b3 Included ecrt_voe_handler_read_nosync()-Patch by Mathias Weber.
Florian Pose <fp@igh-essen.com>
parents: 1313
diff changeset
  2642
b3d06a8807b3 Included ecrt_voe_handler_read_nosync()-Patch by Mathias Weber.
Florian Pose <fp@igh-essen.com>
parents: 1313
diff changeset
  2643
    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
  2644
        up(&master->master_sem);
b3d06a8807b3 Included ecrt_voe_handler_read_nosync()-Patch by Mathias Weber.
Florian Pose <fp@igh-essen.com>
parents: 1313
diff changeset
  2645
        return -ENOENT;
b3d06a8807b3 Included ecrt_voe_handler_read_nosync()-Patch by Mathias Weber.
Florian Pose <fp@igh-essen.com>
parents: 1313
diff changeset
  2646
    }
b3d06a8807b3 Included ecrt_voe_handler_read_nosync()-Patch by Mathias Weber.
Florian Pose <fp@igh-essen.com>
parents: 1313
diff changeset
  2647
b3d06a8807b3 Included ecrt_voe_handler_read_nosync()-Patch by Mathias Weber.
Florian Pose <fp@igh-essen.com>
parents: 1313
diff changeset
  2648
    up(&master->master_sem);
b3d06a8807b3 Included ecrt_voe_handler_read_nosync()-Patch by Mathias Weber.
Florian Pose <fp@igh-essen.com>
parents: 1313
diff changeset
  2649
b3d06a8807b3 Included ecrt_voe_handler_read_nosync()-Patch by Mathias Weber.
Florian Pose <fp@igh-essen.com>
parents: 1313
diff changeset
  2650
    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
  2651
    return 0;
b3d06a8807b3 Included ecrt_voe_handler_read_nosync()-Patch by Mathias Weber.
Florian Pose <fp@igh-essen.com>
parents: 1313
diff changeset
  2652
}
b3d06a8807b3 Included ecrt_voe_handler_read_nosync()-Patch by Mathias Weber.
Florian Pose <fp@igh-essen.com>
parents: 1313
diff changeset
  2653
b3d06a8807b3 Included ecrt_voe_handler_read_nosync()-Patch by Mathias Weber.
Florian Pose <fp@igh-essen.com>
parents: 1313
diff changeset
  2654
/*****************************************************************************/
b3d06a8807b3 Included ecrt_voe_handler_read_nosync()-Patch by Mathias Weber.
Florian Pose <fp@igh-essen.com>
parents: 1313
diff changeset
  2655
1264
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  2656
/** Starts a VoE write operation.
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  2657
 */
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  2658
int ec_cdev_ioctl_voe_write(
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  2659
        ec_master_t *master, /**< EtherCAT master. */
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  2660
        unsigned long arg, /**< ioctl() argument. */
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  2661
        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
  2662
        )
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  2663
{
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  2664
    ec_ioctl_voe_t data;
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  2665
    ec_slave_config_t *sc;
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  2666
    ec_voe_handler_t *voe;
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  2667
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  2668
	if (unlikely(!priv->requested))
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  2669
        return -EPERM;
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  2670
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  2671
    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
  2672
        return -EFAULT;
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  2673
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  2674
    if (down_interruptible(&master->master_sem))
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  2675
        return -EINTR;
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  2676
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  2677
    if (!(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
  2678
        up(&master->master_sem);
1313
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1312
diff changeset
  2679
        return -ENOENT;
1264
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  2680
    }
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  2681
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  2682
    if (!(voe = ec_slave_config_find_voe_handler(sc, data.voe_index))) {
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  2683
        up(&master->master_sem);
1313
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1312
diff changeset
  2684
        return -ENOENT;
1264
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  2685
    }
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  2686
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  2687
    up(&master->master_sem);
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  2688
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  2689
    if (data.size) {
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  2690
        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
  2691
            return -EOVERFLOW;
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  2692
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  2693
        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
  2694
                    (void __user *) data.data, data.size))
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  2695
            return -EFAULT;
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  2696
    }
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  2697
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  2698
    ecrt_voe_handler_write(voe, data.size);
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  2699
    return 0;
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  2700
}
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  2701
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  2702
/*****************************************************************************/
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  2703
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  2704
/** Executes the VoE state machine.
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  2705
 */
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  2706
int ec_cdev_ioctl_voe_exec(
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  2707
        ec_master_t *master, /**< EtherCAT master. */
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  2708
        unsigned long arg, /**< ioctl() argument. */
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  2709
        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
  2710
        )
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  2711
{
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  2712
    ec_ioctl_voe_t data;
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  2713
    ec_slave_config_t *sc;
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  2714
    ec_voe_handler_t *voe;
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  2715
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  2716
	if (unlikely(!priv->requested))
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  2717
        return -EPERM;
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  2718
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  2719
    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
  2720
        return -EFAULT;
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  2721
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  2722
    if (down_interruptible(&master->master_sem))
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  2723
        return -EINTR;
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  2724
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  2725
    if (!(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
  2726
        up(&master->master_sem);
1313
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1312
diff changeset
  2727
        return -ENOENT;
1264
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  2728
    }
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  2729
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  2730
    if (!(voe = ec_slave_config_find_voe_handler(sc, data.voe_index))) {
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  2731
        up(&master->master_sem);
1313
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1312
diff changeset
  2732
        return -ENOENT;
1264
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  2733
    }
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  2734
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  2735
    up(&master->master_sem);
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  2736
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  2737
    data.state = ecrt_voe_handler_execute(voe);
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  2738
    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
  2739
        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
  2740
    else
cd278db5a872 Minor fix in VoE handler.
Florian Pose <fp@igh-essen.com>
parents: 1349
diff changeset
  2741
        data.size = 0;
1264
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  2742
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  2743
    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
  2744
        return -EFAULT;
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  2745
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  2746
    return 0;
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  2747
}
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  2748
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  2749
/*****************************************************************************/
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  2750
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  2751
/** Reads the received VoE data.
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  2752
 */
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  2753
int ec_cdev_ioctl_voe_data(
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  2754
        ec_master_t *master, /**< EtherCAT master. */
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  2755
        unsigned long arg, /**< ioctl() argument. */
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  2756
        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
  2757
        )
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  2758
{
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  2759
    ec_ioctl_voe_t data;
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  2760
    ec_slave_config_t *sc;
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  2761
    ec_voe_handler_t *voe;
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  2762
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  2763
	if (unlikely(!priv->requested))
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  2764
        return -EPERM;
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  2765
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  2766
    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
  2767
        return -EFAULT;
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  2768
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  2769
    if (down_interruptible(&master->master_sem))
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  2770
        return -EINTR;
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  2771
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  2772
    if (!(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
  2773
        up(&master->master_sem);
1313
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1312
diff changeset
  2774
        return -ENOENT;
1264
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  2775
    }
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  2776
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  2777
    if (!(voe = ec_slave_config_find_voe_handler(sc, data.voe_index))) {
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  2778
        up(&master->master_sem);
1313
ed15eef57d5c Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents: 1312
diff changeset
  2779
        return -ENOENT;
1264
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  2780
    }
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  2781
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  2782
    up(&master->master_sem);
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  2783
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  2784
    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
  2785
                ecrt_voe_handler_data_size(voe)))
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  2786
        return -EFAULT;
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  2787
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  2788
    return 0;
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  2789
}
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  2790
1335
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents: 1328
diff changeset
  2791
/*****************************************************************************/
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents: 1328
diff changeset
  2792
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents: 1328
diff changeset
  2793
/** 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
  2794
 */
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents: 1328
diff changeset
  2795
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
  2796
        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
  2797
        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
  2798
        )
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents: 1328
diff changeset
  2799
{
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents: 1328
diff changeset
  2800
    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
  2801
    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
  2802
    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
  2803
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents: 1328
diff changeset
  2804
    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
  2805
        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
  2806
    }
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents: 1328
diff changeset
  2807
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents: 1328
diff changeset
  2808
    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
  2809
    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
  2810
    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
  2811
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents: 1328
diff changeset
  2812
    if (down_interruptible(&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
  2813
        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
  2814
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents: 1328
diff changeset
  2815
    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
  2816
                    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
  2817
        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
  2818
        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
  2819
        EC_ERR("Slave %u does not exist!\n", 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
  2820
        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
  2821
    }
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents: 1328
diff changeset
  2822
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents: 1328
diff changeset
  2823
    // schedule request.
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents: 1328
diff changeset
  2824
    list_add_tail(&request.list, &master->foe_requests);
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents: 1328
diff changeset
  2825
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents: 1328
diff changeset
  2826
    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
  2827
1336
e27b37e80a99 merge -c1618 branches/1.4-foe: Improved FoE.
Florian Pose <fp@igh-essen.com>
parents: 1335
diff changeset
  2828
    if (master->debug_level) {
e27b37e80a99 merge -c1618 branches/1.4-foe: Improved FoE.
Florian Pose <fp@igh-essen.com>
parents: 1335
diff changeset
  2829
        EC_DBG("Scheduled FoE read request on slave %u.\n",
e27b37e80a99 merge -c1618 branches/1.4-foe: Improved FoE.
Florian Pose <fp@igh-essen.com>
parents: 1335
diff changeset
  2830
                request.slave->ring_position);
e27b37e80a99 merge -c1618 branches/1.4-foe: Improved FoE.
Florian Pose <fp@igh-essen.com>
parents: 1335
diff changeset
  2831
    }
e27b37e80a99 merge -c1618 branches/1.4-foe: Improved FoE.
Florian Pose <fp@igh-essen.com>
parents: 1335
diff changeset
  2832
1335
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents: 1328
diff changeset
  2833
    // wait for processing through FSM
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents: 1328
diff changeset
  2834
    if (wait_event_interruptible(master->foe_queue,
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents: 1328
diff changeset
  2835
                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
  2836
        // 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
  2837
        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
  2838
        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
  2839
            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
  2840
            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
  2841
            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
  2842
            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
  2843
        }
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents: 1328
diff changeset
  2844
        // 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
  2845
        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
  2846
    }
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents: 1328
diff changeset
  2847
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents: 1328
diff changeset
  2848
    // wait until master FSM has finished processing
1349
9baba3568df4 Fixed FoE request states.
Florian Pose <fp@igh-essen.com>
parents: 1337
diff changeset
  2849
    wait_event(master->foe_queue, 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
  2850
1336
e27b37e80a99 merge -c1618 branches/1.4-foe: Improved FoE.
Florian Pose <fp@igh-essen.com>
parents: 1335
diff changeset
  2851
    data.result = request.req.result;
e27b37e80a99 merge -c1618 branches/1.4-foe: Improved FoE.
Florian Pose <fp@igh-essen.com>
parents: 1335
diff changeset
  2852
    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
  2853
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents: 1328
diff changeset
  2854
	if (master->debug_level) {
1336
e27b37e80a99 merge -c1618 branches/1.4-foe: Improved FoE.
Florian Pose <fp@igh-essen.com>
parents: 1335
diff changeset
  2855
		EC_DBG("Read %d bytes via FoE (result = 0x%x).\n",
e27b37e80a99 merge -c1618 branches/1.4-foe: Improved FoE.
Florian Pose <fp@igh-essen.com>
parents: 1335
diff changeset
  2856
				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
  2857
	}
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents: 1328
diff changeset
  2858
1349
9baba3568df4 Fixed FoE request states.
Florian Pose <fp@igh-essen.com>
parents: 1337
diff changeset
  2859
    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
  2860
        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
  2861
        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
  2862
    } else {
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents: 1328
diff changeset
  2863
        if (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
  2864
            EC_ERR("Buffer too small.\n");
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents: 1328
diff changeset
  2865
            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
  2866
            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
  2867
        }
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents: 1328
diff changeset
  2868
        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
  2869
        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
  2870
                    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
  2871
            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
  2872
            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
  2873
        }
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents: 1328
diff changeset
  2874
        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
  2875
    }
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents: 1328
diff changeset
  2876
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents: 1328
diff changeset
  2877
    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
  2878
        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
  2879
    }
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents: 1328
diff changeset
  2880
1336
e27b37e80a99 merge -c1618 branches/1.4-foe: Improved FoE.
Florian Pose <fp@igh-essen.com>
parents: 1335
diff changeset
  2881
    if (master->debug_level)
e27b37e80a99 merge -c1618 branches/1.4-foe: Improved FoE.
Florian Pose <fp@igh-essen.com>
parents: 1335
diff changeset
  2882
        EC_DBG("FoE read request finished on slave %u.\n",
e27b37e80a99 merge -c1618 branches/1.4-foe: Improved FoE.
Florian Pose <fp@igh-essen.com>
parents: 1335
diff changeset
  2883
                request.slave->ring_position);
e27b37e80a99 merge -c1618 branches/1.4-foe: Improved FoE.
Florian Pose <fp@igh-essen.com>
parents: 1335
diff changeset
  2884
1335
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents: 1328
diff changeset
  2885
    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
  2886
1335
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents: 1328
diff changeset
  2887
    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
  2888
}
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents: 1328
diff changeset
  2889
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents: 1328
diff changeset
  2890
/*****************************************************************************/
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents: 1328
diff changeset
  2891
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents: 1328
diff changeset
  2892
/** 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
  2893
 */
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents: 1328
diff changeset
  2894
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
  2895
        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
  2896
        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
  2897
        )
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents: 1328
diff changeset
  2898
{
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents: 1328
diff changeset
  2899
    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
  2900
    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
  2901
    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
  2902
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents: 1328
diff changeset
  2903
    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
  2904
        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
  2905
    }
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents: 1328
diff changeset
  2906
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents: 1328
diff changeset
  2907
    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
  2908
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents: 1328
diff changeset
  2909
    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
  2910
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents: 1328
diff changeset
  2911
    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
  2912
        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
  2913
        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
  2914
    }
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents: 1328
diff changeset
  2915
    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
  2916
                (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
  2917
        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
  2918
        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
  2919
    }
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents: 1328
diff changeset
  2920
    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
  2921
    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
  2922
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents: 1328
diff changeset
  2923
    if (down_interruptible(&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
  2924
        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
  2925
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents: 1328
diff changeset
  2926
    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
  2927
                    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
  2928
        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
  2929
        EC_ERR("Slave %u does not exist!\n", 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
  2930
        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
  2931
        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
  2932
    }
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents: 1328
diff changeset
  2933
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents: 1328
diff changeset
  2934
	if (master->debug_level) {
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents: 1328
diff changeset
  2935
		EC_DBG("Scheduling FoE write request.\n");
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents: 1328
diff changeset
  2936
	}
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents: 1328
diff changeset
  2937
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents: 1328
diff changeset
  2938
    // schedule FoE write request.
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents: 1328
diff changeset
  2939
    list_add_tail(&request.list, &master->foe_requests);
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents: 1328
diff changeset
  2940
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents: 1328
diff changeset
  2941
    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
  2942
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents: 1328
diff changeset
  2943
    // wait for processing through FSM
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents: 1328
diff changeset
  2944
    if (wait_event_interruptible(master->foe_queue,
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents: 1328
diff changeset
  2945
                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
  2946
        // 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
  2947
        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
  2948
        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
  2949
            // 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
  2950
            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
  2951
            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
  2952
            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
  2953
            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
  2954
        }
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents: 1328
diff changeset
  2955
        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
  2956
    }
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents: 1328
diff changeset
  2957
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents: 1328
diff changeset
  2958
    // wait until master FSM has finished processing
1349
9baba3568df4 Fixed FoE request states.
Florian Pose <fp@igh-essen.com>
parents: 1337
diff changeset
  2959
    wait_event(master->foe_queue, 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
  2960
1336
e27b37e80a99 merge -c1618 branches/1.4-foe: Improved FoE.
Florian Pose <fp@igh-essen.com>
parents: 1335
diff changeset
  2961
    data.result = request.req.result;
e27b37e80a99 merge -c1618 branches/1.4-foe: Improved FoE.
Florian Pose <fp@igh-essen.com>
parents: 1335
diff changeset
  2962
    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
  2963
1349
9baba3568df4 Fixed FoE request states.
Florian Pose <fp@igh-essen.com>
parents: 1337
diff changeset
  2964
    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
  2965
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents: 1328
diff changeset
  2966
    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
  2967
        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
  2968
    }
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents: 1328
diff changeset
  2969
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents: 1328
diff changeset
  2970
    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
  2971
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents: 1328
diff changeset
  2972
	if (master->debug_level) {
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents: 1328
diff changeset
  2973
		printk ("Finished FoE writing.\n");
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents: 1328
diff changeset
  2974
	}
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents: 1328
diff changeset
  2975
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents: 1328
diff changeset
  2976
    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
  2977
}
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents: 1328
diff changeset
  2978
922
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2979
/******************************************************************************
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2980
 * File operations
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2981
 *****************************************************************************/
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2982
1092
69393cf60399 Improved source code doc.
Florian Pose <fp@igh-essen.com>
parents: 1082
diff changeset
  2983
/** Called when the cdev is opened.
69393cf60399 Improved source code doc.
Florian Pose <fp@igh-essen.com>
parents: 1082
diff changeset
  2984
 */
922
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2985
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
  2986
{
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  2987
    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
  2988
    ec_cdev_priv_t *priv;
632a6b91f8e4 First version of userspace library with requesting/releasing.
Florian Pose <fp@igh-essen.com>
parents: 1223
diff changeset
  2989
632a6b91f8e4 First version of userspace library with requesting/releasing.
Florian Pose <fp@igh-essen.com>
parents: 1223
diff changeset
  2990
    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
  2991
    if (!priv) {
632a6b91f8e4 First version of userspace library with requesting/releasing.
Florian Pose <fp@igh-essen.com>
parents: 1223
diff changeset
  2992
        EC_ERR("Failed to allocate memory for private data structure.\n");
632a6b91f8e4 First version of userspace library with requesting/releasing.
Florian Pose <fp@igh-essen.com>
parents: 1223
diff changeset
  2993
        return -ENOMEM;
632a6b91f8e4 First version of userspace library with requesting/releasing.
Florian Pose <fp@igh-essen.com>
parents: 1223
diff changeset
  2994
    }
632a6b91f8e4 First version of userspace library with requesting/releasing.
Florian Pose <fp@igh-essen.com>
parents: 1223
diff changeset
  2995
632a6b91f8e4 First version of userspace library with requesting/releasing.
Florian Pose <fp@igh-essen.com>
parents: 1223
diff changeset
  2996
    priv->cdev = cdev;
632a6b91f8e4 First version of userspace library with requesting/releasing.
Florian Pose <fp@igh-essen.com>
parents: 1223
diff changeset
  2997
    priv->requested = 0;
1258
900f1124e8f8 Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents: 1255
diff changeset
  2998
    priv->process_data = NULL;
900f1124e8f8 Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents: 1255
diff changeset
  2999
    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
  3000
632a6b91f8e4 First version of userspace library with requesting/releasing.
Florian Pose <fp@igh-essen.com>
parents: 1223
diff changeset
  3001
    filp->private_data = priv;
1397
6f9294a445c1 Introduced DEBUG_IOCTL.
Florian Pose <fp@igh-essen.com>
parents: 1388
diff changeset
  3002
6f9294a445c1 Introduced DEBUG_IOCTL.
Florian Pose <fp@igh-essen.com>
parents: 1388
diff changeset
  3003
#if DEBUG_IOCTL
6f9294a445c1 Introduced DEBUG_IOCTL.
Florian Pose <fp@igh-essen.com>
parents: 1388
diff changeset
  3004
    EC_DBG("File opened.\n");
6f9294a445c1 Introduced DEBUG_IOCTL.
Florian Pose <fp@igh-essen.com>
parents: 1388
diff changeset
  3005
#endif
922
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3006
    return 0;
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3007
}
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3008
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3009
/*****************************************************************************/
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3010
1092
69393cf60399 Improved source code doc.
Florian Pose <fp@igh-essen.com>
parents: 1082
diff changeset
  3011
/** Called when the cdev is closed.
69393cf60399 Improved source code doc.
Florian Pose <fp@igh-essen.com>
parents: 1082
diff changeset
  3012
 */
922
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3013
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
  3014
{
1242
632a6b91f8e4 First version of userspace library with requesting/releasing.
Florian Pose <fp@igh-essen.com>
parents: 1223
diff changeset
  3015
    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
  3016
    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
  3017
632a6b91f8e4 First version of userspace library with requesting/releasing.
Florian Pose <fp@igh-essen.com>
parents: 1223
diff changeset
  3018
    if (priv->requested)
632a6b91f8e4 First version of userspace library with requesting/releasing.
Florian Pose <fp@igh-essen.com>
parents: 1223
diff changeset
  3019
        ecrt_release_master(master);
935
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
  3020
1258
900f1124e8f8 Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents: 1255
diff changeset
  3021
    if (priv->process_data)
900f1124e8f8 Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents: 1255
diff changeset
  3022
        vfree(priv->process_data);
900f1124e8f8 Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents: 1255
diff changeset
  3023
1397
6f9294a445c1 Introduced DEBUG_IOCTL.
Florian Pose <fp@igh-essen.com>
parents: 1388
diff changeset
  3024
#if DEBUG_IOCTL
6f9294a445c1 Introduced DEBUG_IOCTL.
Florian Pose <fp@igh-essen.com>
parents: 1388
diff changeset
  3025
    EC_DBG("File closed.\n");
6f9294a445c1 Introduced DEBUG_IOCTL.
Florian Pose <fp@igh-essen.com>
parents: 1388
diff changeset
  3026
#endif
6f9294a445c1 Introduced DEBUG_IOCTL.
Florian Pose <fp@igh-essen.com>
parents: 1388
diff changeset
  3027
1242
632a6b91f8e4 First version of userspace library with requesting/releasing.
Florian Pose <fp@igh-essen.com>
parents: 1223
diff changeset
  3028
    kfree(priv);
922
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3029
    return 0;
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3030
}
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3031
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3032
/*****************************************************************************/
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3033
1092
69393cf60399 Improved source code doc.
Florian Pose <fp@igh-essen.com>
parents: 1082
diff changeset
  3034
/** Called when an ioctl() command is issued.
69393cf60399 Improved source code doc.
Florian Pose <fp@igh-essen.com>
parents: 1082
diff changeset
  3035
 */
935
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
  3036
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
  3037
{
1242
632a6b91f8e4 First version of userspace library with requesting/releasing.
Florian Pose <fp@igh-essen.com>
parents: 1223
diff changeset
  3038
    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
  3039
    ec_master_t *master = priv->cdev->master;
922
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3040
1397
6f9294a445c1 Introduced DEBUG_IOCTL.
Florian Pose <fp@igh-essen.com>
parents: 1388
diff changeset
  3041
#if DEBUG_IOCTL
6f9294a445c1 Introduced DEBUG_IOCTL.
Florian Pose <fp@igh-essen.com>
parents: 1388
diff changeset
  3042
    EC_DBG("ioctl(filp = 0x%x, cmd = 0x%08x (0x%02x), arg = 0x%x)\n",
6f9294a445c1 Introduced DEBUG_IOCTL.
Florian Pose <fp@igh-essen.com>
parents: 1388
diff changeset
  3043
            (u32) filp, (u32) cmd, (u32) _IOC_NR(cmd), (u32) arg);
6f9294a445c1 Introduced DEBUG_IOCTL.
Florian Pose <fp@igh-essen.com>
parents: 1388
diff changeset
  3044
#endif
935
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
  3045
922
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3046
    switch (cmd) {
957
ed5ac2e83495 Replaced EC_IOCTL_SLAVE_COUNT with EC_IOCTL_MASTER; implemented
Florian Pose <fp@igh-essen.com>
parents: 956
diff changeset
  3047
        case EC_IOCTL_MASTER:
1079
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  3048
            return ec_cdev_ioctl_master(master, arg);
935
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
  3049
        case EC_IOCTL_SLAVE:
1079
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  3050
            return ec_cdev_ioctl_slave(master, arg);
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  3051
        case EC_IOCTL_SLAVE_SYNC:
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  3052
            return ec_cdev_ioctl_slave_sync(master, arg);
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  3053
        case EC_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
  3054
            return ec_cdev_ioctl_slave_sync_pdo(master, arg);
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  3055
        case EC_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
  3056
            return ec_cdev_ioctl_slave_sync_pdo_entry(master, arg);
948
1cfab7161491 Implemented domain command.
Florian Pose <fp@igh-essen.com>
parents: 938
diff changeset
  3057
        case EC_IOCTL_DOMAIN:
1079
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  3058
            return ec_cdev_ioctl_domain(master, arg);
950
8b00e63fff90 'ethercat domain' shows domain contents and process data.
Florian Pose <fp@igh-essen.com>
parents: 949
diff changeset
  3059
        case EC_IOCTL_DOMAIN_FMMU:
1079
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  3060
            return ec_cdev_ioctl_domain_fmmu(master, arg);
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  3061
        case EC_IOCTL_DOMAIN_DATA:
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  3062
            return ec_cdev_ioctl_domain_data(master, arg);
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  3063
        case EC_IOCTL_MASTER_DEBUG:
972
ad59641a68c8 ioctl() permissions.
Florian Pose <fp@igh-essen.com>
parents: 968
diff changeset
  3064
            if (!(filp->f_mode & FMODE_WRITE))
ad59641a68c8 ioctl() permissions.
Florian Pose <fp@igh-essen.com>
parents: 968
diff changeset
  3065
                return -EPERM;
1079
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  3066
            return ec_cdev_ioctl_master_debug(master, arg);
960
36e460ffbb5e Request slave state(s) with 'ethercat state'; removed sysfs state file.
Florian Pose <fp@igh-essen.com>
parents: 957
diff changeset
  3067
        case EC_IOCTL_SLAVE_STATE:
1079
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  3068
            if (!(filp->f_mode & FMODE_WRITE))
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  3069
                return -EPERM;
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  3070
            return ec_cdev_ioctl_slave_state(master, arg);
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  3071
        case EC_IOCTL_SLAVE_SDO:
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  3072
            return ec_cdev_ioctl_slave_sdo(master, arg);
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  3073
        case EC_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
  3074
            return ec_cdev_ioctl_slave_sdo_entry(master, arg);
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  3075
        case EC_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
  3076
            return ec_cdev_ioctl_slave_sdo_upload(master, arg);
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  3077
        case EC_IOCTL_SLAVE_SDO_DOWNLOAD:
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  3078
            if (!(filp->f_mode & FMODE_WRITE))
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  3079
                return -EPERM;
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  3080
            return ec_cdev_ioctl_slave_sdo_download(master, arg);
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  3081
        case EC_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
  3082
            return ec_cdev_ioctl_slave_sii_read(master, arg);
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  3083
        case EC_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
  3084
            if (!(filp->f_mode & FMODE_WRITE))
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  3085
                return -EPERM;
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  3086
            return ec_cdev_ioctl_slave_sii_write(master, arg);
1388
3c886ec376f5 Renamed phy_ commands to reg_.
Florian Pose <fp@igh-essen.com>
parents: 1382
diff changeset
  3087
        case EC_IOCTL_SLAVE_REG_READ:
3c886ec376f5 Renamed phy_ commands to reg_.
Florian Pose <fp@igh-essen.com>
parents: 1382
diff changeset
  3088
            return ec_cdev_ioctl_slave_reg_read(master, arg);
3c886ec376f5 Renamed phy_ commands to reg_.
Florian Pose <fp@igh-essen.com>
parents: 1382
diff changeset
  3089
        case EC_IOCTL_SLAVE_REG_WRITE:
1200
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1196
diff changeset
  3090
            if (!(filp->f_mode & FMODE_WRITE))
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1196
diff changeset
  3091
                return -EPERM;
1388
3c886ec376f5 Renamed phy_ commands to reg_.
Florian Pose <fp@igh-essen.com>
parents: 1382
diff changeset
  3092
            return ec_cdev_ioctl_slave_reg_write(master, arg);
1335
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents: 1328
diff changeset
  3093
        case EC_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
  3094
            return ec_cdev_ioctl_slave_foe_read(master, arg);
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents: 1328
diff changeset
  3095
        case EC_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
  3096
            if (!(filp->f_mode & FMODE_WRITE))
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents: 1328
diff changeset
  3097
                return -EPERM;
09c6fce1ae45 merge -c1616 branches/1.4-foe: Included FoE patch from Olav Zarges.
Florian Pose <fp@igh-essen.com>
parents: 1328
diff changeset
  3098
            return ec_cdev_ioctl_slave_foe_write(master, arg);
990
4f223f3df05a Bus configuration via 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 989
diff changeset
  3099
        case EC_IOCTL_CONFIG:
1079
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  3100
            return ec_cdev_ioctl_config(master, arg);
990
4f223f3df05a Bus configuration via 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 989
diff changeset
  3101
        case EC_IOCTL_CONFIG_PDO:
1079
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  3102
            return ec_cdev_ioctl_config_pdo(master, arg);
990
4f223f3df05a Bus configuration via 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 989
diff changeset
  3103
        case EC_IOCTL_CONFIG_PDO_ENTRY:
1079
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  3104
            return ec_cdev_ioctl_config_pdo_entry(master, arg);
990
4f223f3df05a Bus configuration via 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 989
diff changeset
  3105
        case EC_IOCTL_CONFIG_SDO:
1079
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  3106
            return ec_cdev_ioctl_config_sdo(master, arg);
1242
632a6b91f8e4 First version of userspace library with requesting/releasing.
Florian Pose <fp@igh-essen.com>
parents: 1223
diff changeset
  3107
        case EC_IOCTL_REQUEST:
632a6b91f8e4 First version of userspace library with requesting/releasing.
Florian Pose <fp@igh-essen.com>
parents: 1223
diff changeset
  3108
            if (!(filp->f_mode & FMODE_WRITE))
632a6b91f8e4 First version of userspace library with requesting/releasing.
Florian Pose <fp@igh-essen.com>
parents: 1223
diff changeset
  3109
				return -EPERM;
632a6b91f8e4 First version of userspace library with requesting/releasing.
Florian Pose <fp@igh-essen.com>
parents: 1223
diff changeset
  3110
			return ec_cdev_ioctl_request(master, arg, priv);
1244
0b70040d3daa No kernel handles in userspace; Domain creation.
Florian Pose <fp@igh-essen.com>
parents: 1242
diff changeset
  3111
        case EC_IOCTL_CREATE_DOMAIN:
0b70040d3daa No kernel handles in userspace; Domain creation.
Florian Pose <fp@igh-essen.com>
parents: 1242
diff changeset
  3112
            if (!(filp->f_mode & FMODE_WRITE))
0b70040d3daa No kernel handles in userspace; Domain creation.
Florian Pose <fp@igh-essen.com>
parents: 1242
diff changeset
  3113
				return -EPERM;
0b70040d3daa No kernel handles in userspace; Domain creation.
Florian Pose <fp@igh-essen.com>
parents: 1242
diff changeset
  3114
			return ec_cdev_ioctl_create_domain(master, arg, priv);
1246
4042bda8c980 Creating slave configurations.
Florian Pose <fp@igh-essen.com>
parents: 1244
diff changeset
  3115
        case EC_IOCTL_CREATE_SLAVE_CONFIG:
4042bda8c980 Creating slave configurations.
Florian Pose <fp@igh-essen.com>
parents: 1244
diff changeset
  3116
            if (!(filp->f_mode & FMODE_WRITE))
4042bda8c980 Creating slave configurations.
Florian Pose <fp@igh-essen.com>
parents: 1244
diff changeset
  3117
				return -EPERM;
4042bda8c980 Creating slave configurations.
Florian Pose <fp@igh-essen.com>
parents: 1244
diff changeset
  3118
			return ec_cdev_ioctl_create_slave_config(master, arg, priv);
1247
5f1f1a3e6636 Activate, Send and received; cyclic timer with setitimer().
Florian Pose <fp@igh-essen.com>
parents: 1246
diff changeset
  3119
        case EC_IOCTL_ACTIVATE:
5f1f1a3e6636 Activate, Send and received; cyclic timer with setitimer().
Florian Pose <fp@igh-essen.com>
parents: 1246
diff changeset
  3120
            if (!(filp->f_mode & FMODE_WRITE))
5f1f1a3e6636 Activate, Send and received; cyclic timer with setitimer().
Florian Pose <fp@igh-essen.com>
parents: 1246
diff changeset
  3121
				return -EPERM;
5f1f1a3e6636 Activate, Send and received; cyclic timer with setitimer().
Florian Pose <fp@igh-essen.com>
parents: 1246
diff changeset
  3122
			return ec_cdev_ioctl_activate(master, arg, priv);
5f1f1a3e6636 Activate, Send and received; cyclic timer with setitimer().
Florian Pose <fp@igh-essen.com>
parents: 1246
diff changeset
  3123
        case EC_IOCTL_SEND:
5f1f1a3e6636 Activate, Send and received; cyclic timer with setitimer().
Florian Pose <fp@igh-essen.com>
parents: 1246
diff changeset
  3124
            if (!(filp->f_mode & FMODE_WRITE))
5f1f1a3e6636 Activate, Send and received; cyclic timer with setitimer().
Florian Pose <fp@igh-essen.com>
parents: 1246
diff changeset
  3125
				return -EPERM;
5f1f1a3e6636 Activate, Send and received; cyclic timer with setitimer().
Florian Pose <fp@igh-essen.com>
parents: 1246
diff changeset
  3126
			return ec_cdev_ioctl_send(master, arg, priv);
5f1f1a3e6636 Activate, Send and received; cyclic timer with setitimer().
Florian Pose <fp@igh-essen.com>
parents: 1246
diff changeset
  3127
        case EC_IOCTL_RECEIVE:
5f1f1a3e6636 Activate, Send and received; cyclic timer with setitimer().
Florian Pose <fp@igh-essen.com>
parents: 1246
diff changeset
  3128
            if (!(filp->f_mode & FMODE_WRITE))
5f1f1a3e6636 Activate, Send and received; cyclic timer with setitimer().
Florian Pose <fp@igh-essen.com>
parents: 1246
diff changeset
  3129
				return -EPERM;
5f1f1a3e6636 Activate, Send and received; cyclic timer with setitimer().
Florian Pose <fp@igh-essen.com>
parents: 1246
diff changeset
  3130
			return ec_cdev_ioctl_receive(master, arg, priv);
1259
5f9d1abbee71 Added state functions; writing of process data works.
Florian Pose <fp@igh-essen.com>
parents: 1258
diff changeset
  3131
        case EC_IOCTL_MASTER_STATE:
5f9d1abbee71 Added state functions; writing of process data works.
Florian Pose <fp@igh-essen.com>
parents: 1258
diff changeset
  3132
			return ec_cdev_ioctl_master_state(master, arg, priv);
1413
44c2b7c0ae1a Userspace library implementation of DC functions.
Florian Pose <fp@igh-essen.com>
parents: 1401
diff changeset
  3133
        case EC_IOCTL_SYNC_REF:
44c2b7c0ae1a Userspace library implementation of DC functions.
Florian Pose <fp@igh-essen.com>
parents: 1401
diff changeset
  3134
            if (!(filp->f_mode & FMODE_WRITE))
44c2b7c0ae1a Userspace library implementation of DC functions.
Florian Pose <fp@igh-essen.com>
parents: 1401
diff changeset
  3135
				return -EPERM;
44c2b7c0ae1a Userspace library implementation of DC functions.
Florian Pose <fp@igh-essen.com>
parents: 1401
diff changeset
  3136
			return ec_cdev_ioctl_sync_ref(master, arg, priv);
44c2b7c0ae1a Userspace library implementation of DC functions.
Florian Pose <fp@igh-essen.com>
parents: 1401
diff changeset
  3137
        case EC_IOCTL_SYNC_SLAVES:
44c2b7c0ae1a Userspace library implementation of DC functions.
Florian Pose <fp@igh-essen.com>
parents: 1401
diff changeset
  3138
            if (!(filp->f_mode & FMODE_WRITE))
44c2b7c0ae1a Userspace library implementation of DC functions.
Florian Pose <fp@igh-essen.com>
parents: 1401
diff changeset
  3139
				return -EPERM;
44c2b7c0ae1a Userspace library implementation of DC functions.
Florian Pose <fp@igh-essen.com>
parents: 1401
diff changeset
  3140
			return ec_cdev_ioctl_sync_slaves(master, arg, priv);
1255
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  3141
        case EC_IOCTL_SC_SYNC:
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  3142
            if (!(filp->f_mode & FMODE_WRITE))
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  3143
				return -EPERM;
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  3144
			return ec_cdev_ioctl_sc_sync(master, arg, priv);
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  3145
        case EC_IOCTL_SC_ADD_PDO:
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  3146
            if (!(filp->f_mode & FMODE_WRITE))
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  3147
				return -EPERM;
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  3148
			return ec_cdev_ioctl_sc_add_pdo(master, arg, priv);
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  3149
        case EC_IOCTL_SC_CLEAR_PDOS:
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  3150
            if (!(filp->f_mode & FMODE_WRITE))
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  3151
				return -EPERM;
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  3152
			return ec_cdev_ioctl_sc_clear_pdos(master, arg, priv);
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  3153
        case EC_IOCTL_SC_ADD_ENTRY:
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  3154
            if (!(filp->f_mode & FMODE_WRITE))
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  3155
				return -EPERM;
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  3156
			return ec_cdev_ioctl_sc_add_entry(master, arg, priv);
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  3157
        case EC_IOCTL_SC_CLEAR_ENTRIES:
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  3158
            if (!(filp->f_mode & FMODE_WRITE))
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  3159
				return -EPERM;
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  3160
			return ec_cdev_ioctl_sc_clear_entries(master, arg, priv);
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  3161
        case EC_IOCTL_SC_REG_PDO_ENTRY:
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  3162
            if (!(filp->f_mode & FMODE_WRITE))
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  3163
				return -EPERM;
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  3164
			return ec_cdev_ioctl_sc_reg_pdo_entry(master, arg, priv);
1448
d7ba0c408a07 Merged ecrt_slave_config_dc_assign_activate() and
Florian Pose <fp@igh-essen.com>
parents: 1447
diff changeset
  3165
        case EC_IOCTL_SC_DC:
1413
44c2b7c0ae1a Userspace library implementation of DC functions.
Florian Pose <fp@igh-essen.com>
parents: 1401
diff changeset
  3166
            if (!(filp->f_mode & FMODE_WRITE))
44c2b7c0ae1a Userspace library implementation of DC functions.
Florian Pose <fp@igh-essen.com>
parents: 1401
diff changeset
  3167
				return -EPERM;
1448
d7ba0c408a07 Merged ecrt_slave_config_dc_assign_activate() and
Florian Pose <fp@igh-essen.com>
parents: 1447
diff changeset
  3168
			return ec_cdev_ioctl_sc_dc(master, arg, priv);
1255
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  3169
        case EC_IOCTL_SC_SDO:
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  3170
            if (!(filp->f_mode & FMODE_WRITE))
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  3171
				return -EPERM;
38b7e05b20c1 Added some slave configuration methods.
Florian Pose <fp@igh-essen.com>
parents: 1247
diff changeset
  3172
			return ec_cdev_ioctl_sc_sdo(master, arg, priv);
1352
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1350
diff changeset
  3173
        case EC_IOCTL_SC_SDO_REQUEST:
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1350
diff changeset
  3174
            if (!(filp->f_mode & FMODE_WRITE))
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1350
diff changeset
  3175
				return -EPERM;
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1350
diff changeset
  3176
			return ec_cdev_ioctl_sc_create_sdo_request(master, arg, priv);
1264
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  3177
        case EC_IOCTL_SC_VOE:
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  3178
            if (!(filp->f_mode & FMODE_WRITE))
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  3179
				return -EPERM;
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  3180
			return ec_cdev_ioctl_sc_create_voe_handler(master, arg, priv);
1259
5f9d1abbee71 Added state functions; writing of process data works.
Florian Pose <fp@igh-essen.com>
parents: 1258
diff changeset
  3181
        case EC_IOCTL_SC_STATE:
5f9d1abbee71 Added state functions; writing of process data works.
Florian Pose <fp@igh-essen.com>
parents: 1258
diff changeset
  3182
			return ec_cdev_ioctl_sc_state(master, arg, priv);
1258
900f1124e8f8 Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents: 1255
diff changeset
  3183
        case EC_IOCTL_DOMAIN_OFFSET:
900f1124e8f8 Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents: 1255
diff changeset
  3184
			return ec_cdev_ioctl_domain_offset(master, arg, priv);
900f1124e8f8 Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents: 1255
diff changeset
  3185
        case EC_IOCTL_DOMAIN_PROCESS:
900f1124e8f8 Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents: 1255
diff changeset
  3186
            if (!(filp->f_mode & FMODE_WRITE))
900f1124e8f8 Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents: 1255
diff changeset
  3187
				return -EPERM;
900f1124e8f8 Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents: 1255
diff changeset
  3188
			return ec_cdev_ioctl_domain_process(master, arg, priv);
900f1124e8f8 Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents: 1255
diff changeset
  3189
        case EC_IOCTL_DOMAIN_QUEUE:
900f1124e8f8 Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents: 1255
diff changeset
  3190
            if (!(filp->f_mode & FMODE_WRITE))
900f1124e8f8 Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents: 1255
diff changeset
  3191
				return -EPERM;
900f1124e8f8 Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents: 1255
diff changeset
  3192
			return ec_cdev_ioctl_domain_queue(master, arg, priv);
1259
5f9d1abbee71 Added state functions; writing of process data works.
Florian Pose <fp@igh-essen.com>
parents: 1258
diff changeset
  3193
        case EC_IOCTL_DOMAIN_STATE:
5f9d1abbee71 Added state functions; writing of process data works.
Florian Pose <fp@igh-essen.com>
parents: 1258
diff changeset
  3194
			return ec_cdev_ioctl_domain_state(master, arg, priv);
1352
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1350
diff changeset
  3195
        case EC_IOCTL_SDO_REQUEST_TIMEOUT:
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1350
diff changeset
  3196
            if (!(filp->f_mode & FMODE_WRITE))
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1350
diff changeset
  3197
				return -EPERM;
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1350
diff changeset
  3198
			return ec_cdev_ioctl_sdo_request_timeout(master, arg, priv);
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1350
diff changeset
  3199
        case EC_IOCTL_SDO_REQUEST_STATE:
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1350
diff changeset
  3200
			return ec_cdev_ioctl_sdo_request_state(master, arg, priv);
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1350
diff changeset
  3201
        case EC_IOCTL_SDO_REQUEST_READ:
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1350
diff changeset
  3202
            if (!(filp->f_mode & FMODE_WRITE))
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1350
diff changeset
  3203
				return -EPERM;
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1350
diff changeset
  3204
			return ec_cdev_ioctl_sdo_request_read(master, arg, priv);
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1350
diff changeset
  3205
        case EC_IOCTL_SDO_REQUEST_WRITE:
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1350
diff changeset
  3206
            if (!(filp->f_mode & FMODE_WRITE))
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1350
diff changeset
  3207
				return -EPERM;
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1350
diff changeset
  3208
			return ec_cdev_ioctl_sdo_request_write(master, arg, priv);
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1350
diff changeset
  3209
        case EC_IOCTL_SDO_REQUEST_DATA:
275d2fdeab48 Implemented SDO requests in userspace library.
Florian Pose <fp@igh-essen.com>
parents: 1350
diff changeset
  3210
			return ec_cdev_ioctl_sdo_request_data(master, arg, priv);
1264
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  3211
        case EC_IOCTL_VOE_SEND_HEADER:
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  3212
            if (!(filp->f_mode & FMODE_WRITE))
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  3213
				return -EPERM;
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  3214
			return ec_cdev_ioctl_voe_send_header(master, arg, priv);
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  3215
        case EC_IOCTL_VOE_REC_HEADER:
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  3216
			return ec_cdev_ioctl_voe_rec_header(master, arg, priv);
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  3217
        case EC_IOCTL_VOE_READ:
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  3218
            if (!(filp->f_mode & FMODE_WRITE))
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  3219
				return -EPERM;
1381
f592fe7e799d Fixed VoE ioctl().
Florian Pose <fp@igh-essen.com>
parents: 1379
diff changeset
  3220
			return ec_cdev_ioctl_voe_read(master, arg, priv);
1314
b3d06a8807b3 Included ecrt_voe_handler_read_nosync()-Patch by Mathias Weber.
Florian Pose <fp@igh-essen.com>
parents: 1313
diff changeset
  3221
        case EC_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
  3222
            if (!(filp->f_mode & FMODE_WRITE))
b3d06a8807b3 Included ecrt_voe_handler_read_nosync()-Patch by Mathias Weber.
Florian Pose <fp@igh-essen.com>
parents: 1313
diff changeset
  3223
				return -EPERM;
b3d06a8807b3 Included ecrt_voe_handler_read_nosync()-Patch by Mathias Weber.
Florian Pose <fp@igh-essen.com>
parents: 1313
diff changeset
  3224
			return ec_cdev_ioctl_voe_read_nosync(master, arg, priv);
1264
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  3225
        case EC_IOCTL_VOE_WRITE:
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  3226
            if (!(filp->f_mode & FMODE_WRITE))
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  3227
				return -EPERM;
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  3228
			return ec_cdev_ioctl_voe_write(master, arg, priv);
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  3229
        case EC_IOCTL_VOE_EXEC:
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  3230
            if (!(filp->f_mode & FMODE_WRITE))
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  3231
				return -EPERM;
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  3232
			return ec_cdev_ioctl_voe_exec(master, arg, priv);
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  3233
        case EC_IOCTL_VOE_DATA:
e7882f246d7a Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents: 1259
diff changeset
  3234
			return ec_cdev_ioctl_voe_data(master, arg, priv);
922
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  3235
        default:
1079
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  3236
            return -ENOTTY;
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  3237
    }
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  3238
}
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  3239
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  3240
/*****************************************************************************/
1258
900f1124e8f8 Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents: 1255
diff changeset
  3241
1268
d9599395e89b Maintained code docs.
Florian Pose <fp@igh-essen.com>
parents: 1264
diff changeset
  3242
/** Memory-map callback for the EtherCAT character device.
d9599395e89b Maintained code docs.
Florian Pose <fp@igh-essen.com>
parents: 1264
diff changeset
  3243
 *
d9599395e89b Maintained code docs.
Florian Pose <fp@igh-essen.com>
parents: 1264
diff changeset
  3244
 * 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
  3245
 * virtual memory area.
d9599395e89b Maintained code docs.
Florian Pose <fp@igh-essen.com>
parents: 1264
diff changeset
  3246
 */
1258
900f1124e8f8 Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents: 1255
diff changeset
  3247
int eccdev_mmap(
900f1124e8f8 Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents: 1255
diff changeset
  3248
        struct file *filp,
900f1124e8f8 Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents: 1255
diff changeset
  3249
        struct vm_area_struct *vma
900f1124e8f8 Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents: 1255
diff changeset
  3250
        )
900f1124e8f8 Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents: 1255
diff changeset
  3251
{
900f1124e8f8 Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents: 1255
diff changeset
  3252
    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
  3253
900f1124e8f8 Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents: 1255
diff changeset
  3254
    if (priv->cdev->master->debug_level)
900f1124e8f8 Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents: 1255
diff changeset
  3255
        EC_DBG("mmap()\n");
900f1124e8f8 Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents: 1255
diff changeset
  3256
900f1124e8f8 Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents: 1255
diff changeset
  3257
    vma->vm_ops = &eccdev_vm_ops;
900f1124e8f8 Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents: 1255
diff changeset
  3258
    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
  3259
    vma->vm_private_data = priv;
900f1124e8f8 Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents: 1255
diff changeset
  3260
900f1124e8f8 Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents: 1255
diff changeset
  3261
    return 0;
900f1124e8f8 Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents: 1255
diff changeset
  3262
}
900f1124e8f8 Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents: 1255
diff changeset
  3263
900f1124e8f8 Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents: 1255
diff changeset
  3264
/*****************************************************************************/
900f1124e8f8 Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents: 1255
diff changeset
  3265
1272
288c982acd23 Use .fault handler instead of .nopage handler from 2.6.23.
Florian Pose <fp@igh-essen.com>
parents: 1268
diff changeset
  3266
#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
  3267
1268
d9599395e89b Maintained code docs.
Florian Pose <fp@igh-essen.com>
parents: 1264
diff changeset
  3268
/** Page fault callback for a virtual memory area.
d9599395e89b Maintained code docs.
Florian Pose <fp@igh-essen.com>
parents: 1264
diff changeset
  3269
 *
d9599395e89b Maintained code docs.
Florian Pose <fp@igh-essen.com>
parents: 1264
diff changeset
  3270
 * 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
  3271
 * ecdev_mmap().
d9599395e89b Maintained code docs.
Florian Pose <fp@igh-essen.com>
parents: 1264
diff changeset
  3272
 */
1272
288c982acd23 Use .fault handler instead of .nopage handler from 2.6.23.
Florian Pose <fp@igh-essen.com>
parents: 1268
diff changeset
  3273
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
  3274
        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
  3275
        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
  3276
        )
288c982acd23 Use .fault handler instead of .nopage handler from 2.6.23.
Florian Pose <fp@igh-essen.com>
parents: 1268
diff changeset
  3277
{
1284
283aab089eb5 Fixed page fault handler.
Florian Pose <fp@igh-essen.com>
parents: 1272
diff changeset
  3278
    unsigned long offset = vmf->pgoff << PAGE_SHIFT;
283aab089eb5 Fixed page fault handler.
Florian Pose <fp@igh-essen.com>
parents: 1272
diff changeset
  3279
    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
  3280
    struct page *page;
1284
283aab089eb5 Fixed page fault handler.
Florian Pose <fp@igh-essen.com>
parents: 1272
diff changeset
  3281
283aab089eb5 Fixed page fault handler.
Florian Pose <fp@igh-essen.com>
parents: 1272
diff changeset
  3282
    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
  3283
        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
  3284
1284
283aab089eb5 Fixed page fault handler.
Florian Pose <fp@igh-essen.com>
parents: 1272
diff changeset
  3285
    page = vmalloc_to_page(priv->process_data + offset);
283aab089eb5 Fixed page fault handler.
Florian Pose <fp@igh-essen.com>
parents: 1272
diff changeset
  3286
    if (!page)
283aab089eb5 Fixed page fault handler.
Florian Pose <fp@igh-essen.com>
parents: 1272
diff changeset
  3287
        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
  3288
288c982acd23 Use .fault handler instead of .nopage handler from 2.6.23.
Florian Pose <fp@igh-essen.com>
parents: 1268
diff changeset
  3289
    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
  3290
    vmf->page = page;
1284
283aab089eb5 Fixed page fault handler.
Florian Pose <fp@igh-essen.com>
parents: 1272
diff changeset
  3291
283aab089eb5 Fixed page fault handler.
Florian Pose <fp@igh-essen.com>
parents: 1272
diff changeset
  3292
    if (priv->cdev->master->debug_level)
283aab089eb5 Fixed page fault handler.
Florian Pose <fp@igh-essen.com>
parents: 1272
diff changeset
  3293
        EC_DBG("Vma fault, virtual_address = %p, offset = %lu, page = %p\n",
283aab089eb5 Fixed page fault handler.
Florian Pose <fp@igh-essen.com>
parents: 1272
diff changeset
  3294
                vmf->virtual_address, offset, page);
283aab089eb5 Fixed page fault handler.
Florian Pose <fp@igh-essen.com>
parents: 1272
diff changeset
  3295
1272
288c982acd23 Use .fault handler instead of .nopage handler from 2.6.23.
Florian Pose <fp@igh-essen.com>
parents: 1268
diff changeset
  3296
    return 0;
288c982acd23 Use .fault handler instead of .nopage handler from 2.6.23.
Florian Pose <fp@igh-essen.com>
parents: 1268
diff changeset
  3297
}
288c982acd23 Use .fault handler instead of .nopage handler from 2.6.23.
Florian Pose <fp@igh-essen.com>
parents: 1268
diff changeset
  3298
288c982acd23 Use .fault handler instead of .nopage handler from 2.6.23.
Florian Pose <fp@igh-essen.com>
parents: 1268
diff changeset
  3299
#else
288c982acd23 Use .fault handler instead of .nopage handler from 2.6.23.
Florian Pose <fp@igh-essen.com>
parents: 1268
diff changeset
  3300
288c982acd23 Use .fault handler instead of .nopage handler from 2.6.23.
Florian Pose <fp@igh-essen.com>
parents: 1268
diff changeset
  3301
/** 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
  3302
 *
288c982acd23 Use .fault handler instead of .nopage handler from 2.6.23.
Florian Pose <fp@igh-essen.com>
parents: 1268
diff changeset
  3303
 * 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
  3304
 * ecdev_mmap().
288c982acd23 Use .fault handler instead of .nopage handler from 2.6.23.
Florian Pose <fp@igh-essen.com>
parents: 1268
diff changeset
  3305
 */
1258
900f1124e8f8 Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents: 1255
diff changeset
  3306
struct page *eccdev_vma_nopage(
1268
d9599395e89b Maintained code docs.
Florian Pose <fp@igh-essen.com>
parents: 1264
diff changeset
  3307
        struct vm_area_struct *vma, /**< Virtual memory area initialized by
d9599395e89b Maintained code docs.
Florian Pose <fp@igh-essen.com>
parents: 1264
diff changeset
  3308
                                      the kernel. */
d9599395e89b Maintained code docs.
Florian Pose <fp@igh-essen.com>
parents: 1264
diff changeset
  3309
        unsigned long address, /**< Requested virtual address. */
d9599395e89b Maintained code docs.
Florian Pose <fp@igh-essen.com>
parents: 1264
diff changeset
  3310
        int *type /**< Type output parameter. */
1258
900f1124e8f8 Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents: 1255
diff changeset
  3311
        )
900f1124e8f8 Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents: 1255
diff changeset
  3312
{
900f1124e8f8 Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents: 1255
diff changeset
  3313
    unsigned long offset;
900f1124e8f8 Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents: 1255
diff changeset
  3314
    struct page *page = NOPAGE_SIGBUS;
900f1124e8f8 Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents: 1255
diff changeset
  3315
    ec_cdev_priv_t *priv = (ec_cdev_priv_t *) vma->vm_private_data;
900f1124e8f8 Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents: 1255
diff changeset
  3316
900f1124e8f8 Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents: 1255
diff changeset
  3317
    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
  3318
900f1124e8f8 Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents: 1255
diff changeset
  3319
    if (offset >= priv->process_data_size)
900f1124e8f8 Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents: 1255
diff changeset
  3320
        return NOPAGE_SIGBUS;
900f1124e8f8 Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents: 1255
diff changeset
  3321
900f1124e8f8 Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents: 1255
diff changeset
  3322
    page = vmalloc_to_page(priv->process_data + offset);
900f1124e8f8 Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents: 1255
diff changeset
  3323
900f1124e8f8 Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents: 1255
diff changeset
  3324
    if (priv->cdev->master->debug_level)
900f1124e8f8 Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents: 1255
diff changeset
  3325
        EC_DBG("Nopage fault vma, address = %#lx, offset = %#lx, page = %p\n",
900f1124e8f8 Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents: 1255
diff changeset
  3326
                address, offset, page);
900f1124e8f8 Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents: 1255
diff changeset
  3327
900f1124e8f8 Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents: 1255
diff changeset
  3328
    get_page(page);
900f1124e8f8 Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents: 1255
diff changeset
  3329
    if (type)
900f1124e8f8 Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents: 1255
diff changeset
  3330
        *type = VM_FAULT_MINOR;
900f1124e8f8 Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents: 1255
diff changeset
  3331
900f1124e8f8 Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents: 1255
diff changeset
  3332
    return page;
900f1124e8f8 Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents: 1255
diff changeset
  3333
}
900f1124e8f8 Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents: 1255
diff changeset
  3334
1272
288c982acd23 Use .fault handler instead of .nopage handler from 2.6.23.
Florian Pose <fp@igh-essen.com>
parents: 1268
diff changeset
  3335
#endif
288c982acd23 Use .fault handler instead of .nopage handler from 2.6.23.
Florian Pose <fp@igh-essen.com>
parents: 1268
diff changeset
  3336
288c982acd23 Use .fault handler instead of .nopage handler from 2.6.23.
Florian Pose <fp@igh-essen.com>
parents: 1268
diff changeset
  3337
/*****************************************************************************/