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