master/cdev.c
author Florian Pose <fp@igh-essen.com>
Wed, 01 Oct 2008 11:53:22 +0000
changeset 1240 982eb5bee593
parent 1223 6d539205114e
child 1242 632a6b91f8e4
permissions -rw-r--r--
Removed watchdog debugging output.
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
 *
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     5
 *  Copyright (C) 2006  Florian Pose, Ingenieurgemeinschaft IgH
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
 *
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     9
 *  The IgH EtherCAT Master is free software; you can redistribute it
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    10
 *  and/or modify it under the terms of the GNU General Public License
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    11
 *  as published by the Free Software Foundation; either version 2 of the
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    12
 *  License, or (at your option) any later version.
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    13
 *
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    14
 *  The IgH EtherCAT Master is distributed in the hope that it will be
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    15
 *  useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    16
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    17
 *  GNU General Public License for more details.
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    18
 *
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    19
 *  You should have received a copy of the GNU General Public License
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    20
 *  along with the IgH EtherCAT Master; if not, write to the Free Software
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    21
 *  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
    22
 *
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    23
 *  The right to use EtherCAT Technology is granted and comes free of
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    24
 *  charge under condition of compatibility of product made by
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    25
 *  Licensee. People intending to distribute/sell products based on the
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    26
 *  code, have to sign an agreement to guarantee that products using
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    27
 *  software based on IgH EtherCAT master stay compatible with the actual
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    28
 *  EtherCAT specification (which are released themselves as an open
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    29
 *  standard) as the (only) precondition to have the right to use EtherCAT
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    30
 *  Technology, IP and trade marks.
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    31
 *
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    32
 *****************************************************************************/
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
   \file
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    36
   EtherCAT master character device.
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    37
*/
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    38
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    39
/*****************************************************************************/
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 <linux/module.h>
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    42
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    43
#include "cdev.h"
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    44
#include "master.h"
950
8b00e63fff90 'ethercat domain' shows domain contents and process data.
Florian Pose <fp@igh-essen.com>
parents: 949
diff changeset
    45
#include "slave_config.h"
922
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    46
#include "ioctl.h"
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    47
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    48
/*****************************************************************************/
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
/** \cond */
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    51
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    52
int eccdev_open(struct inode *, struct file *);
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    53
int eccdev_release(struct inode *, struct file *);
935
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
    54
long eccdev_ioctl(struct file *, unsigned int, unsigned long);
922
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    55
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    56
/*****************************************************************************/
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    57
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    58
static struct file_operations eccdev_fops = {
935
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
    59
    .owner          = THIS_MODULE,
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
    60
    .open           = eccdev_open,
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
    61
    .release        = eccdev_release,
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
    62
    .unlocked_ioctl = eccdev_ioctl
922
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    63
};
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    64
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    65
/** \endcond */
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    66
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
/** Constructor.
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    70
 * 
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    71
 * \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
    72
 */
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    73
int ec_cdev_init(
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    74
		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
    75
		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
    76
		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
    77
		)
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    78
{
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    79
    cdev->master = master;
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    80
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    81
    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
    82
    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
    83
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    84
    if (cdev_add(&cdev->cdev,
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    85
		 MKDEV(MAJOR(dev_num), master->index), 1)) {
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    86
		EC_ERR("Failed to add character device!\n");
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    87
		return -1;
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
    return 0;
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    91
}
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    92
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    93
/*****************************************************************************/
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    94
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    95
/** Destructor.
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    96
 */
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    97
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
    98
{
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    99
    cdev_del(&cdev->cdev);
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   100
}
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   101
1079
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   102
/*****************************************************************************/
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   103
1108
7beba3e7e6b4 Added ec_cdev_strcpy() function.
Florian Pose <fp@igh-essen.com>
parents: 1092
diff changeset
   104
/** Copies a string to an ioctl structure.
7beba3e7e6b4 Added ec_cdev_strcpy() function.
Florian Pose <fp@igh-essen.com>
parents: 1092
diff changeset
   105
 */
7beba3e7e6b4 Added ec_cdev_strcpy() function.
Florian Pose <fp@igh-essen.com>
parents: 1092
diff changeset
   106
void ec_cdev_strcpy(
7beba3e7e6b4 Added ec_cdev_strcpy() function.
Florian Pose <fp@igh-essen.com>
parents: 1092
diff changeset
   107
        char *target, /**< Target. */
7beba3e7e6b4 Added ec_cdev_strcpy() function.
Florian Pose <fp@igh-essen.com>
parents: 1092
diff changeset
   108
        const char *source /**< Source. */
7beba3e7e6b4 Added ec_cdev_strcpy() function.
Florian Pose <fp@igh-essen.com>
parents: 1092
diff changeset
   109
        )
7beba3e7e6b4 Added ec_cdev_strcpy() function.
Florian Pose <fp@igh-essen.com>
parents: 1092
diff changeset
   110
{
7beba3e7e6b4 Added ec_cdev_strcpy() function.
Florian Pose <fp@igh-essen.com>
parents: 1092
diff changeset
   111
    if (source) {
7beba3e7e6b4 Added ec_cdev_strcpy() function.
Florian Pose <fp@igh-essen.com>
parents: 1092
diff changeset
   112
        strncpy(target, source, EC_IOCTL_STRING_SIZE);
7beba3e7e6b4 Added ec_cdev_strcpy() function.
Florian Pose <fp@igh-essen.com>
parents: 1092
diff changeset
   113
        target[EC_IOCTL_STRING_SIZE - 1] = 0;
7beba3e7e6b4 Added ec_cdev_strcpy() function.
Florian Pose <fp@igh-essen.com>
parents: 1092
diff changeset
   114
    } else {
7beba3e7e6b4 Added ec_cdev_strcpy() function.
Florian Pose <fp@igh-essen.com>
parents: 1092
diff changeset
   115
        target[0] = 0;
7beba3e7e6b4 Added ec_cdev_strcpy() function.
Florian Pose <fp@igh-essen.com>
parents: 1092
diff changeset
   116
    }
7beba3e7e6b4 Added ec_cdev_strcpy() function.
Florian Pose <fp@igh-essen.com>
parents: 1092
diff changeset
   117
}
7beba3e7e6b4 Added ec_cdev_strcpy() function.
Florian Pose <fp@igh-essen.com>
parents: 1092
diff changeset
   118
7beba3e7e6b4 Added ec_cdev_strcpy() function.
Florian Pose <fp@igh-essen.com>
parents: 1092
diff changeset
   119
/*****************************************************************************/
7beba3e7e6b4 Added ec_cdev_strcpy() function.
Florian Pose <fp@igh-essen.com>
parents: 1092
diff changeset
   120
1079
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   121
/** Get master information.
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   122
 */
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   123
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
   124
        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
   125
        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
   126
        )
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   127
{
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   128
    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
   129
1189
acc6430bfb32 Use down_interruptible() wherever possible.
Florian Pose <fp@igh-essen.com>
parents: 1183
diff changeset
   130
    if (down_interruptible(&master->master_sem))
acc6430bfb32 Use down_interruptible() wherever possible.
Florian Pose <fp@igh-essen.com>
parents: 1183
diff changeset
   131
        return -EINTR;
1079
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   132
    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
   133
    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
   134
    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
   135
    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
   136
    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
   137
1189
acc6430bfb32 Use down_interruptible() wherever possible.
Florian Pose <fp@igh-essen.com>
parents: 1183
diff changeset
   138
    if (down_interruptible(&master->device_sem))
acc6430bfb32 Use down_interruptible() wherever possible.
Florian Pose <fp@igh-essen.com>
parents: 1183
diff changeset
   139
        return -EINTR;
1162
51a8b41d3dbc Display real ethernet address.
Florian Pose <fp@igh-essen.com>
parents: 1150
diff changeset
   140
    if (master->main_device.dev) {
51a8b41d3dbc Display real ethernet address.
Florian Pose <fp@igh-essen.com>
parents: 1150
diff changeset
   141
        memcpy(data.devices[0].address,
51a8b41d3dbc Display real ethernet address.
Florian Pose <fp@igh-essen.com>
parents: 1150
diff changeset
   142
                master->main_device.dev->dev_addr, ETH_ALEN);
51a8b41d3dbc Display real ethernet address.
Florian Pose <fp@igh-essen.com>
parents: 1150
diff changeset
   143
    } else {
51a8b41d3dbc Display real ethernet address.
Florian Pose <fp@igh-essen.com>
parents: 1150
diff changeset
   144
        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
   145
    }
1079
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   146
    data.devices[0].attached = master->main_device.dev ? 1 : 0;
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   147
    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
   148
    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
   149
51a8b41d3dbc Display real ethernet address.
Florian Pose <fp@igh-essen.com>
parents: 1150
diff changeset
   150
    if (master->backup_device.dev) {
51a8b41d3dbc Display real ethernet address.
Florian Pose <fp@igh-essen.com>
parents: 1150
diff changeset
   151
        memcpy(data.devices[1].address,
51a8b41d3dbc Display real ethernet address.
Florian Pose <fp@igh-essen.com>
parents: 1150
diff changeset
   152
                master->backup_device.dev->dev_addr, ETH_ALEN); 
51a8b41d3dbc Display real ethernet address.
Florian Pose <fp@igh-essen.com>
parents: 1150
diff changeset
   153
    } else {
51a8b41d3dbc Display real ethernet address.
Florian Pose <fp@igh-essen.com>
parents: 1150
diff changeset
   154
        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
   155
    }
1079
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   156
    data.devices[1].attached = master->backup_device.dev ? 1 : 0;
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   157
    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
   158
    data.devices[1].rx_count = master->backup_device.rx_count;
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   159
    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
   160
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   161
    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
   162
        return -EFAULT;
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
    return 0;
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   165
}
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   166
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   167
/*****************************************************************************/
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   168
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   169
/** Get slave information.
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   170
 */
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   171
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
   172
        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
   173
        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
   174
        )
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   175
{
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   176
    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
   177
    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
   178
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   179
    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
   180
        return -EFAULT;
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   181
    }
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   182
1189
acc6430bfb32 Use down_interruptible() wherever possible.
Florian Pose <fp@igh-essen.com>
parents: 1183
diff changeset
   183
    if (down_interruptible(&master->master_sem))
acc6430bfb32 Use down_interruptible() wherever possible.
Florian Pose <fp@igh-essen.com>
parents: 1183
diff changeset
   184
        return -EINTR;
1079
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   185
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   186
    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
   187
                    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
   188
        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
   189
        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
   190
        return -EINVAL;
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   191
    }
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   192
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   193
    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
   194
    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
   195
    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
   196
    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
   197
    data.alias = slave->sii.alias;
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   198
    data.rx_mailbox_offset = slave->sii.rx_mailbox_offset;
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   199
    data.rx_mailbox_size = slave->sii.rx_mailbox_size;
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   200
    data.tx_mailbox_offset = slave->sii.tx_mailbox_offset;
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   201
    data.tx_mailbox_size = slave->sii.tx_mailbox_size;
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   202
    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
   203
    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
   204
    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
   205
    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
   206
    data.current_on_ebus = slave->sii.current_on_ebus;
1148
1762296870bd Renamed state field to al_state.
Florian Pose <fp@igh-essen.com>
parents: 1147
diff changeset
   207
    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
   208
    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
   209
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   210
    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
   211
    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
   212
    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
   213
    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
   214
    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
   215
    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
   216
    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
   217
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   218
    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
   219
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   220
    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
   221
        return -EFAULT;
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
    return 0;
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   224
}
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   225
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
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   228
/** 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
   229
 */
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   230
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
   231
        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
   232
        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
   233
        )
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   234
{
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   235
    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
   236
    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
   237
    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
   238
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   239
    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
   240
        return -EFAULT;
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   241
    }
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   242
1189
acc6430bfb32 Use down_interruptible() wherever possible.
Florian Pose <fp@igh-essen.com>
parents: 1183
diff changeset
   243
    if (down_interruptible(&master->master_sem))
acc6430bfb32 Use down_interruptible() wherever possible.
Florian Pose <fp@igh-essen.com>
parents: 1183
diff changeset
   244
        return -EINTR;
1079
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   245
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   246
    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
   247
                    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
   248
        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
   249
        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
   250
        return -EINVAL;
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   251
    }
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   252
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   253
    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
   254
        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
   255
        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
   256
                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
   257
        return -EINVAL;
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   258
    }
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   259
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   260
    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
   261
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   262
    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
   263
    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
   264
    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
   265
    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
   266
    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
   267
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   268
    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
   269
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   270
    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
   271
        return -EFAULT;
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   272
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   273
    return 0;
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   274
}
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   275
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   276
/*****************************************************************************/
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   277
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   278
/** Get slave sync manager Pdo information.
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
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
   281
        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
   282
        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
   283
        )
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   284
{
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   285
    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
   286
    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
   287
    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
   288
    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
   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_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
   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
1189
acc6430bfb32 Use down_interruptible() wherever possible.
Florian Pose <fp@igh-essen.com>
parents: 1183
diff changeset
   294
    if (down_interruptible(&master->master_sem))
acc6430bfb32 Use down_interruptible() wherever possible.
Florian Pose <fp@igh-essen.com>
parents: 1183
diff changeset
   295
        return -EINTR;
1079
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
    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
   298
                    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
   299
        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
   300
        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
   301
        return -EINVAL;
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   302
    }
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   303
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   304
    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
   305
        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
   306
        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
   307
                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
   308
        return -EINVAL;
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   309
    }
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   310
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   311
    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
   312
    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
   313
                    &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
   314
        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
   315
        EC_ERR("Sync manager %u does not contain a Pdo with "
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   316
                "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
   317
                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
   318
        return -EINVAL;
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   319
    }
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   320
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   321
    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
   322
    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
   323
    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
   324
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   325
    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
   326
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   327
    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
   328
        return -EFAULT;
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
    return 0;
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
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   333
/*****************************************************************************/
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   334
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   335
/** Get slave sync manager Pdo entry information.
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   336
 */
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   337
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
   338
        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
   339
        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
   340
        )
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   341
{
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   342
    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
   343
    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
   344
    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
   345
    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
   346
    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
   347
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   348
    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
   349
        return -EFAULT;
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   350
    }
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   351
1189
acc6430bfb32 Use down_interruptible() wherever possible.
Florian Pose <fp@igh-essen.com>
parents: 1183
diff changeset
   352
    if (down_interruptible(&master->master_sem))
acc6430bfb32 Use down_interruptible() wherever possible.
Florian Pose <fp@igh-essen.com>
parents: 1183
diff changeset
   353
        return -EINTR;
1079
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
    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
   356
                    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
   357
        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
   358
        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
   359
        return -EINVAL;
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   360
    }
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   361
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   362
    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
   363
        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
   364
        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
   365
                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
   366
        return -EINVAL;
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   367
    }
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   368
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   369
    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
   370
    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
   371
                    &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
   372
        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
   373
        EC_ERR("Sync manager %u does not contain a Pdo with "
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   374
                "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
   375
                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
   376
        return -EINVAL;
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   377
    }
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   378
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   379
    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
   380
                    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
   381
        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
   382
        EC_ERR("Pdo 0x%04X does not contain an entry with "
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   383
                "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
   384
                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
   385
        return -EINVAL;
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   386
    }
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   387
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   388
    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
   389
    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
   390
    data.bit_length = entry->bit_length;
1108
7beba3e7e6b4 Added ec_cdev_strcpy() function.
Florian Pose <fp@igh-essen.com>
parents: 1092
diff changeset
   391
    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
   392
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   393
    up(&master->master_sem);
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   394
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   395
    if (copy_to_user((void __user *) arg, &data, sizeof(data)))
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   396
        return -EFAULT;
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   397
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   398
    return 0;
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   399
}
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   400
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   401
/*****************************************************************************/
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   402
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   403
/** Get domain information.
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   404
 */
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   405
int ec_cdev_ioctl_domain(
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   406
        ec_master_t *master, /**< EtherCAT master. */
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   407
        unsigned long arg /**< Userspace address to store the results. */
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   408
        )
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   409
{
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   410
    ec_ioctl_domain_t data;
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   411
    const ec_domain_t *domain;
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   412
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   413
    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
   414
        return -EFAULT;
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   415
    }
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   416
1189
acc6430bfb32 Use down_interruptible() wherever possible.
Florian Pose <fp@igh-essen.com>
parents: 1183
diff changeset
   417
    if (down_interruptible(&master->master_sem))
acc6430bfb32 Use down_interruptible() wherever possible.
Florian Pose <fp@igh-essen.com>
parents: 1183
diff changeset
   418
        return -EINTR;
1079
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   419
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   420
    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
   421
        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
   422
        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
   423
        return -EINVAL;
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
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   426
    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
   427
    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
   428
    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
   429
    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
   430
    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
   431
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   432
    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
   433
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   434
    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
   435
        return -EFAULT;
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   436
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   437
    return 0;
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
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   440
/*****************************************************************************/
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   441
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   442
/** 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
   443
 */
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   444
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
   445
        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
   446
        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
   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
    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
   450
    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
   451
    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
   452
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   453
    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
   454
        return -EFAULT;
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   455
    }
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   456
1189
acc6430bfb32 Use down_interruptible() wherever possible.
Florian Pose <fp@igh-essen.com>
parents: 1183
diff changeset
   457
    if (down_interruptible(&master->master_sem))
acc6430bfb32 Use down_interruptible() wherever possible.
Florian Pose <fp@igh-essen.com>
parents: 1183
diff changeset
   458
        return -EINTR;
1079
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   459
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   460
    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
   461
        up(&master->master_sem);
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   462
        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
   463
        return -EINVAL;
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
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   466
    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
   467
        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
   468
        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
   469
                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
   470
        return -EINVAL;
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
    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
   474
    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
   475
    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
   476
    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
   477
    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
   478
    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
   479
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   480
    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
   481
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   482
    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
   483
        return -EFAULT;
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   484
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   485
    return 0;
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   486
}
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   487
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   488
/*****************************************************************************/
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
/** Get domain data.
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   491
 */
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   492
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
   493
        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
   494
        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
   495
        )
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   496
{
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   497
    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
   498
    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
   499
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   500
    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
   501
        return -EFAULT;
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   502
    }
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   503
1189
acc6430bfb32 Use down_interruptible() wherever possible.
Florian Pose <fp@igh-essen.com>
parents: 1183
diff changeset
   504
    if (down_interruptible(&master->master_sem))
acc6430bfb32 Use down_interruptible() wherever possible.
Florian Pose <fp@igh-essen.com>
parents: 1183
diff changeset
   505
        return -EINTR;
1079
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
    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
   508
        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
   509
        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
   510
        return -EINVAL;
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
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   513
    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
   514
        up(&master->master_sem);
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   515
        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
   516
                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
   517
        return -EFAULT;
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   518
    }
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   519
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   520
    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
   521
                domain->data_size)) {
6d539205114e Added missing up().
Florian Pose <fp@igh-essen.com>
parents: 1209
diff changeset
   522
        up(&master->master_sem);
6d539205114e Added missing up().
Florian Pose <fp@igh-essen.com>
parents: 1209
diff changeset
   523
        return -EFAULT;
6d539205114e Added missing up().
Florian Pose <fp@igh-essen.com>
parents: 1209
diff changeset
   524
    }
1079
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
    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
   527
    return 0;
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   528
}
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   529
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   530
/*****************************************************************************/
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   531
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   532
/** 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
   533
 */
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   534
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
   535
        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
   536
        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
   537
        )
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   538
{
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   539
    if (ec_master_debug_level(master, (unsigned int) arg))
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
    return 0;
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   543
}
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   544
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   545
/*****************************************************************************/
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   546
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   547
/** Set slave state.
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   548
 */
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   549
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
   550
        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
   551
        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
   552
        )
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   553
{
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   554
    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
   555
    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
   556
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   557
    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
   558
        return -EFAULT;
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
1189
acc6430bfb32 Use down_interruptible() wherever possible.
Florian Pose <fp@igh-essen.com>
parents: 1183
diff changeset
   561
    if (down_interruptible(&master->master_sem))
acc6430bfb32 Use down_interruptible() wherever possible.
Florian Pose <fp@igh-essen.com>
parents: 1183
diff changeset
   562
        return -EINTR;
1079
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   563
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   564
    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
   565
                    master, 0, data.slave_position))) {
1196
a27966f01b72 Fixed missing up().
Florian Pose <fp@igh-essen.com>
parents: 1189
diff changeset
   566
        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
   567
        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
   568
        return -EINVAL;
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
1150
c589b54ade01 Fixed requested_state.
Florian Pose <fp@igh-essen.com>
parents: 1148
diff changeset
   571
    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
   572
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   573
    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
   574
    return 0;
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   575
}
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
/*****************************************************************************/
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   578
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   579
/** Get slave Sdo information.
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   580
 */
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   581
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
   582
        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
   583
        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
   584
        )
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   585
{
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   586
    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
   587
    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
   588
    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
   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_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
   591
        return -EFAULT;
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   592
    }
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   593
1189
acc6430bfb32 Use down_interruptible() wherever possible.
Florian Pose <fp@igh-essen.com>
parents: 1183
diff changeset
   594
    if (down_interruptible(&master->master_sem))
acc6430bfb32 Use down_interruptible() wherever possible.
Florian Pose <fp@igh-essen.com>
parents: 1183
diff changeset
   595
        return -EINTR;
1079
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   596
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   597
    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
   598
                    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
   599
        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
   600
        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
   601
        return -EINVAL;
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   602
    }
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   603
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   604
    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
   605
                    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
   606
        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
   607
        EC_ERR("Sdo %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
   608
                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
   609
        return -EINVAL;
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
    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
   613
    data.max_subindex = sdo->max_subindex;
1108
7beba3e7e6b4 Added ec_cdev_strcpy() function.
Florian Pose <fp@igh-essen.com>
parents: 1092
diff changeset
   614
    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
   615
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   616
    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
   617
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   618
    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
   619
        return -EFAULT;
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
    return 0;
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   622
}
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   623
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   624
/*****************************************************************************/
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   625
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   626
/** Get slave Sdo entry information.
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   627
 */
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   628
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
   629
        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
   630
        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
   631
        )
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   632
{
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   633
    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
   634
    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
   635
    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
   636
    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
   637
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   638
    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
   639
        return -EFAULT;
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   640
    }
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   641
1189
acc6430bfb32 Use down_interruptible() wherever possible.
Florian Pose <fp@igh-essen.com>
parents: 1183
diff changeset
   642
    if (down_interruptible(&master->master_sem))
acc6430bfb32 Use down_interruptible() wherever possible.
Florian Pose <fp@igh-essen.com>
parents: 1183
diff changeset
   643
        return -EINTR;
1079
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
    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
   646
                    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
   647
        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
   648
        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
   649
        return -EINVAL;
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   650
    }
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   651
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   652
    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
   653
        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
   654
                        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
   655
            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
   656
            EC_ERR("Sdo %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
   657
                    -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
   658
            return -EINVAL;
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
    } else {
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   661
        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
   662
                        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
   663
            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
   664
            EC_ERR("Sdo 0x%04X 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
   665
                    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
   666
            return -EINVAL;
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   667
        }
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   668
    }
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   669
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   670
    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
   671
                    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
   672
        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
   673
        EC_ERR("Sdo entry 0x%04X:%02X does not exist "
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   674
                "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
   675
                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
   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.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
   680
    data.bit_length = entry->bit_length;
1108
7beba3e7e6b4 Added ec_cdev_strcpy() function.
Florian Pose <fp@igh-essen.com>
parents: 1092
diff changeset
   681
    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
   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
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   693
/** Upload Sdo.
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_upload(
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_upload_t data;
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   701
    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
   702
    int retval;
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   703
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   704
    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
   705
        return -EFAULT;
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   706
    }
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
    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
   709
    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
   710
            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
   711
    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
   712
1189
acc6430bfb32 Use down_interruptible() wherever possible.
Florian Pose <fp@igh-essen.com>
parents: 1183
diff changeset
   713
    if (down_interruptible(&master->master_sem))
acc6430bfb32 Use down_interruptible() wherever possible.
Florian Pose <fp@igh-essen.com>
parents: 1183
diff changeset
   714
        return -EINTR;
1079
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   715
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   716
    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
   717
                    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
   718
        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
   719
        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
   720
        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
   721
        return -EINVAL;
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   722
    }
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   723
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   724
    // schedule request.
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   725
    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
   726
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   727
    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
   728
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   729
    // 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
   730
    if (wait_event_interruptible(master->sdo_queue,
1209
8be462afb7f4 Added VoE handler.
Florian Pose <fp@igh-essen.com>
parents: 1200
diff changeset
   731
                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
   732
        // interrupted by signal
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   733
        down(&master->master_sem);
1209
8be462afb7f4 Added VoE handler.
Florian Pose <fp@igh-essen.com>
parents: 1200
diff changeset
   734
        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
   735
            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
   736
            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
   737
            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
   738
            return -EINTR;
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   739
        }
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   740
        // 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
   741
        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
   742
    }
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   743
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   744
    // wait until master FSM has finished processing
1209
8be462afb7f4 Added VoE handler.
Florian Pose <fp@igh-essen.com>
parents: 1200
diff changeset
   745
    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
   746
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   747
    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
   748
1209
8be462afb7f4 Added VoE handler.
Florian Pose <fp@igh-essen.com>
parents: 1200
diff changeset
   749
    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
   750
        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
   751
        retval = -EIO;
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   752
    } else {
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   753
        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
   754
            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
   755
            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
   756
            return -EOVERFLOW;
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   757
        }
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   758
        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
   759
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   760
        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
   761
                    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
   762
            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
   763
            return -EFAULT;
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   764
        }
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   765
        retval = 0;
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   766
    }
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   767
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   768
    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
   769
        retval = -EFAULT;
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
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   772
    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
   773
    return retval;
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   774
}
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   775
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   776
/*****************************************************************************/
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   777
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   778
/** Download Sdo.
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   779
 */
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   780
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
   781
        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
   782
        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
   783
        )
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   784
{
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   785
    ec_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
   786
    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
   787
    int retval;
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   788
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   789
    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
   790
        return -EFAULT;
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   791
    }
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   792
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   793
    // 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
   794
    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
   795
        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
   796
        return -EINVAL;
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   797
    }
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   798
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   799
    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
   800
    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
   801
            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
   802
    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
   803
        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
   804
        return -ENOMEM;
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
    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
   807
                (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
   808
        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
   809
        return -EFAULT;
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   810
    }
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   811
    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
   812
    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
   813
1189
acc6430bfb32 Use down_interruptible() wherever possible.
Florian Pose <fp@igh-essen.com>
parents: 1183
diff changeset
   814
    if (down_interruptible(&master->master_sem))
acc6430bfb32 Use down_interruptible() wherever possible.
Florian Pose <fp@igh-essen.com>
parents: 1183
diff changeset
   815
        return -EINTR;
1079
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   816
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   817
    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
   818
                    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
   819
        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
   820
        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
   821
        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
   822
        return -EINVAL;
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   823
    }
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   824
    
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   825
    // schedule request.
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   826
    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
   827
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   828
    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
   829
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   830
    // 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
   831
    if (wait_event_interruptible(master->sdo_queue,
1209
8be462afb7f4 Added VoE handler.
Florian Pose <fp@igh-essen.com>
parents: 1200
diff changeset
   832
                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
   833
        // interrupted by signal
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   834
        down(&master->master_sem);
1209
8be462afb7f4 Added VoE handler.
Florian Pose <fp@igh-essen.com>
parents: 1200
diff changeset
   835
        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
   836
            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
   837
            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
   838
            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
   839
            return -EINTR;
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   840
        }
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   841
        // 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
   842
        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
   843
    }
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   844
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   845
    // wait until master FSM has finished processing
1209
8be462afb7f4 Added VoE handler.
Florian Pose <fp@igh-essen.com>
parents: 1200
diff changeset
   846
    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
   847
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   848
    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
   849
1209
8be462afb7f4 Added VoE handler.
Florian Pose <fp@igh-essen.com>
parents: 1200
diff changeset
   850
    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
   851
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   852
    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
   853
        retval = -EFAULT;
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
    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
   857
    return retval;
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
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   860
/*****************************************************************************/
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   861
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   862
/** 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
   863
 */
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   864
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
   865
        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
   866
        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
   867
        )
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   868
{
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   869
    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
   870
    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
   871
    int retval;
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   872
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   873
    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
   874
        return -EFAULT;
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   875
    }
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   876
1189
acc6430bfb32 Use down_interruptible() wherever possible.
Florian Pose <fp@igh-essen.com>
parents: 1183
diff changeset
   877
    if (down_interruptible(&master->master_sem))
acc6430bfb32 Use down_interruptible() wherever possible.
Florian Pose <fp@igh-essen.com>
parents: 1183
diff changeset
   878
        return -EINTR;
1079
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   879
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   880
    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
   881
                    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
   882
        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
   883
        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
   884
        return -EINVAL;
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   885
    }
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   886
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   887
    if (!data.nwords
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   888
            || 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
   889
        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
   890
        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
   891
                "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
   892
                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
   893
        return -EINVAL;
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   894
    }
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 (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
   897
                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
   898
        retval = -EFAULT;
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   899
    else
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   900
        retval = 0;
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   901
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   902
    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
   903
    return retval;
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   904
}
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   905
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
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   908
/** 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
   909
 */
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   910
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
   911
        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
   912
        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
   913
        )
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   914
{
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   915
    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
   916
    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
   917
    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
   918
    uint16_t *words;
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   919
    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
   920
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   921
    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
   922
        return -EFAULT;
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
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   925
    if (!data.nwords)
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   926
        return 0;
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   927
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   928
    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
   929
    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
   930
        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
   931
                byte_size);
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   932
        return -ENOMEM;
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
    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
   936
                (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
   937
        kfree(words);
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   938
        return -EFAULT;
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
1189
acc6430bfb32 Use down_interruptible() wherever possible.
Florian Pose <fp@igh-essen.com>
parents: 1183
diff changeset
   941
    if (down_interruptible(&master->master_sem))
acc6430bfb32 Use down_interruptible() wherever possible.
Florian Pose <fp@igh-essen.com>
parents: 1183
diff changeset
   942
        return -EINTR;
1079
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   943
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   944
    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
   945
                    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
   946
        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
   947
        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
   948
        kfree(words);
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   949
        return -EINVAL;
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   950
    }
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
    // 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
   953
    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
   954
    request.slave = slave;
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   955
    request.words = words;
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   956
    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
   957
    request.nwords = data.nwords;
1209
8be462afb7f4 Added VoE handler.
Florian Pose <fp@igh-essen.com>
parents: 1200
diff changeset
   958
    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
   959
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   960
    // 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
   961
    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
   962
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   963
    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
   964
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   965
    // 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
   966
    if (wait_event_interruptible(master->sii_queue,
1209
8be462afb7f4 Added VoE handler.
Florian Pose <fp@igh-essen.com>
parents: 1200
diff changeset
   967
                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
   968
        // interrupted by signal
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   969
        down(&master->master_sem);
1209
8be462afb7f4 Added VoE handler.
Florian Pose <fp@igh-essen.com>
parents: 1200
diff changeset
   970
        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
   971
            // abort request
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   972
            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
   973
            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
   974
            kfree(words);
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   975
            return -EINTR;
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   976
        }
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   977
        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
   978
    }
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   979
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   980
    // wait until master FSM has finished processing
1209
8be462afb7f4 Added VoE handler.
Florian Pose <fp@igh-essen.com>
parents: 1200
diff changeset
   981
    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
   982
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   983
    kfree(words);
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   984
1209
8be462afb7f4 Added VoE handler.
Florian Pose <fp@igh-essen.com>
parents: 1200
diff changeset
   985
    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
   986
}
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   987
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   988
/*****************************************************************************/
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
   989
1200
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1196
diff changeset
   990
/** Read a slave's physical memory.
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1196
diff changeset
   991
 */
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1196
diff changeset
   992
int ec_cdev_ioctl_slave_phy_read(
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1196
diff changeset
   993
        ec_master_t *master, /**< EtherCAT master. */
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1196
diff changeset
   994
        unsigned long arg /**< ioctl() argument. */
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1196
diff changeset
   995
        )
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1196
diff changeset
   996
{
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1196
diff changeset
   997
    ec_ioctl_slave_phy_t data;
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1196
diff changeset
   998
    ec_slave_t *slave;
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1196
diff changeset
   999
    uint8_t *contents;
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1196
diff changeset
  1000
    ec_phy_request_t request;
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1196
diff changeset
  1001
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1196
diff changeset
  1002
    if (copy_from_user(&data, (void __user *) arg, sizeof(data))) {
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1196
diff changeset
  1003
        return -EFAULT;
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1196
diff changeset
  1004
    }
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1196
diff changeset
  1005
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1196
diff changeset
  1006
    if (!data.length)
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1196
diff changeset
  1007
        return 0;
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1196
diff changeset
  1008
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1196
diff changeset
  1009
    if (!(contents = kmalloc(data.length, GFP_KERNEL))) {
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1196
diff changeset
  1010
        EC_ERR("Failed to allocate %u bytes for phy data.\n", data.length);
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1196
diff changeset
  1011
        return -ENOMEM;
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1196
diff changeset
  1012
    }
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1196
diff changeset
  1013
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1196
diff changeset
  1014
    if (down_interruptible(&master->master_sem))
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1196
diff changeset
  1015
        return -EINTR;
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1196
diff changeset
  1016
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1196
diff changeset
  1017
    if (!(slave = ec_master_find_slave(
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1196
diff changeset
  1018
                    master, 0, data.slave_position))) {
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1196
diff changeset
  1019
        up(&master->master_sem);
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1196
diff changeset
  1020
        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
  1021
        return -EINVAL;
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1196
diff changeset
  1022
    }
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1196
diff changeset
  1023
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1196
diff changeset
  1024
    // init phy request
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1196
diff changeset
  1025
    INIT_LIST_HEAD(&request.list);
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1196
diff changeset
  1026
    request.slave = slave;
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1196
diff changeset
  1027
    request.dir = EC_DIR_INPUT;
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1196
diff changeset
  1028
    request.data = contents;
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1196
diff changeset
  1029
    request.offset = data.offset;
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1196
diff changeset
  1030
    request.length = data.length;
1209
8be462afb7f4 Added VoE handler.
Florian Pose <fp@igh-essen.com>
parents: 1200
diff changeset
  1031
    request.state = EC_INT_REQUEST_QUEUED;
1200
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1196
diff changeset
  1032
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1196
diff changeset
  1033
    // schedule request.
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1196
diff changeset
  1034
    list_add_tail(&request.list, &master->phy_requests);
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1196
diff changeset
  1035
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1196
diff changeset
  1036
    up(&master->master_sem);
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1196
diff changeset
  1037
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1196
diff changeset
  1038
    // wait for processing through FSM
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1196
diff changeset
  1039
    if (wait_event_interruptible(master->phy_queue,
1209
8be462afb7f4 Added VoE handler.
Florian Pose <fp@igh-essen.com>
parents: 1200
diff changeset
  1040
                request.state != EC_INT_REQUEST_QUEUED)) {
1200
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1196
diff changeset
  1041
        // interrupted by signal
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1196
diff changeset
  1042
        down(&master->master_sem);
1209
8be462afb7f4 Added VoE handler.
Florian Pose <fp@igh-essen.com>
parents: 1200
diff changeset
  1043
        if (request.state == EC_INT_REQUEST_QUEUED) {
1200
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1196
diff changeset
  1044
            // abort request
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1196
diff changeset
  1045
            list_del(&request.list);
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1196
diff changeset
  1046
            up(&master->master_sem);
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1196
diff changeset
  1047
            kfree(contents);
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1196
diff changeset
  1048
            return -EINTR;
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1196
diff changeset
  1049
        }
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1196
diff changeset
  1050
        up(&master->master_sem);
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1196
diff changeset
  1051
    }
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1196
diff changeset
  1052
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1196
diff changeset
  1053
    // wait until master FSM has finished processing
1209
8be462afb7f4 Added VoE handler.
Florian Pose <fp@igh-essen.com>
parents: 1200
diff changeset
  1054
    wait_event(master->phy_queue, request.state != EC_INT_REQUEST_BUSY);
8be462afb7f4 Added VoE handler.
Florian Pose <fp@igh-essen.com>
parents: 1200
diff changeset
  1055
8be462afb7f4 Added VoE handler.
Florian Pose <fp@igh-essen.com>
parents: 1200
diff changeset
  1056
    if (request.state == EC_INT_REQUEST_SUCCESS) {
1200
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1196
diff changeset
  1057
        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
  1058
            return -EFAULT;
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1196
diff changeset
  1059
    }
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1196
diff changeset
  1060
    kfree(contents);
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1196
diff changeset
  1061
1209
8be462afb7f4 Added VoE handler.
Florian Pose <fp@igh-essen.com>
parents: 1200
diff changeset
  1062
    return request.state == EC_INT_REQUEST_SUCCESS ? 0 : -EIO;
1200
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1196
diff changeset
  1063
}
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1196
diff changeset
  1064
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1196
diff changeset
  1065
/*****************************************************************************/
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1196
diff changeset
  1066
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1196
diff changeset
  1067
/** Write a slave's physical memory.
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1196
diff changeset
  1068
 */
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1196
diff changeset
  1069
int ec_cdev_ioctl_slave_phy_write(
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1196
diff changeset
  1070
        ec_master_t *master, /**< EtherCAT master. */
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1196
diff changeset
  1071
        unsigned long arg /**< ioctl() argument. */
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1196
diff changeset
  1072
        )
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1196
diff changeset
  1073
{
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1196
diff changeset
  1074
    ec_ioctl_slave_phy_t data;
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1196
diff changeset
  1075
    ec_slave_t *slave;
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1196
diff changeset
  1076
    uint8_t *contents;
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1196
diff changeset
  1077
    ec_phy_request_t request;
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1196
diff changeset
  1078
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1196
diff changeset
  1079
    if (copy_from_user(&data, (void __user *) arg, sizeof(data))) {
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1196
diff changeset
  1080
        return -EFAULT;
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1196
diff changeset
  1081
    }
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1196
diff changeset
  1082
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1196
diff changeset
  1083
    if (!data.length)
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1196
diff changeset
  1084
        return 0;
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1196
diff changeset
  1085
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1196
diff changeset
  1086
    if (!(contents = kmalloc(data.length, GFP_KERNEL))) {
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1196
diff changeset
  1087
        EC_ERR("Failed to allocate %u bytes for phy data.\n", data.length);
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1196
diff changeset
  1088
        return -ENOMEM;
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1196
diff changeset
  1089
    }
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1196
diff changeset
  1090
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1196
diff changeset
  1091
    if (copy_from_user(contents, (void __user *) data.data, data.length)) {
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1196
diff changeset
  1092
        kfree(contents);
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1196
diff changeset
  1093
        return -EFAULT;
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1196
diff changeset
  1094
    }
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 (down_interruptible(&master->master_sem))
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1196
diff changeset
  1097
        return -EINTR;
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1196
diff changeset
  1098
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1196
diff changeset
  1099
    if (!(slave = ec_master_find_slave(
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1196
diff changeset
  1100
                    master, 0, data.slave_position))) {
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1196
diff changeset
  1101
        up(&master->master_sem);
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1196
diff changeset
  1102
        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
  1103
        kfree(contents);
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1196
diff changeset
  1104
        return -EINVAL;
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1196
diff changeset
  1105
    }
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1196
diff changeset
  1106
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1196
diff changeset
  1107
    // init phy request
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1196
diff changeset
  1108
    INIT_LIST_HEAD(&request.list);
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1196
diff changeset
  1109
    request.slave = slave;
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1196
diff changeset
  1110
    request.dir = EC_DIR_OUTPUT;
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1196
diff changeset
  1111
    request.data = contents;
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1196
diff changeset
  1112
    request.offset = data.offset;
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1196
diff changeset
  1113
    request.length = data.length;
1209
8be462afb7f4 Added VoE handler.
Florian Pose <fp@igh-essen.com>
parents: 1200
diff changeset
  1114
    request.state = EC_INT_REQUEST_QUEUED;
1200
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1196
diff changeset
  1115
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1196
diff changeset
  1116
    // schedule request.
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1196
diff changeset
  1117
    list_add_tail(&request.list, &master->phy_requests);
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1196
diff changeset
  1118
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1196
diff changeset
  1119
    up(&master->master_sem);
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1196
diff changeset
  1120
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1196
diff changeset
  1121
    // wait for processing through FSM
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1196
diff changeset
  1122
    if (wait_event_interruptible(master->phy_queue,
1209
8be462afb7f4 Added VoE handler.
Florian Pose <fp@igh-essen.com>
parents: 1200
diff changeset
  1123
                request.state != EC_INT_REQUEST_QUEUED)) {
1200
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1196
diff changeset
  1124
        // interrupted by signal
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1196
diff changeset
  1125
        down(&master->master_sem);
1209
8be462afb7f4 Added VoE handler.
Florian Pose <fp@igh-essen.com>
parents: 1200
diff changeset
  1126
        if (request.state == EC_INT_REQUEST_QUEUED) {
1200
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1196
diff changeset
  1127
            // abort request
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1196
diff changeset
  1128
            list_del(&request.list);
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
            kfree(contents);
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1196
diff changeset
  1131
            return -EINTR;
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1196
diff changeset
  1132
        }
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1196
diff changeset
  1133
        up(&master->master_sem);
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1196
diff changeset
  1134
    }
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1196
diff changeset
  1135
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1196
diff changeset
  1136
    // wait until master FSM has finished processing
1209
8be462afb7f4 Added VoE handler.
Florian Pose <fp@igh-essen.com>
parents: 1200
diff changeset
  1137
    wait_event(master->phy_queue, request.state != EC_INT_REQUEST_BUSY);
1200
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
1079
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1146
/** 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
  1147
 */
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1148
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
  1149
        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
  1150
        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
  1151
        )
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1152
{
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1153
    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
  1154
    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
  1155
    uint8_t i;
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1156
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1157
    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
  1158
        return -EFAULT;
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1159
    }
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1160
1189
acc6430bfb32 Use down_interruptible() wherever possible.
Florian Pose <fp@igh-essen.com>
parents: 1183
diff changeset
  1161
    if (down_interruptible(&master->master_sem))
acc6430bfb32 Use down_interruptible() wherever possible.
Florian Pose <fp@igh-essen.com>
parents: 1183
diff changeset
  1162
        return -EINTR;
1079
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1163
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1164
    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
  1165
                    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
  1166
        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
  1167
        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
  1168
                data.config_index);
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1169
        return -EINVAL;
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1170
    }
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1171
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1172
    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
  1173
    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
  1174
    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
  1175
    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
  1176
    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
  1177
        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
  1178
        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
  1179
            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
  1180
    }
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1181
    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
  1182
    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
  1183
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1184
    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
  1185
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1186
    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
  1187
        return -EFAULT;
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1188
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1189
    return 0;
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1190
}
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1191
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1192
/*****************************************************************************/
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1193
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1194
/** Get slave configuration Pdo information.
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1195
 */
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1196
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
  1197
        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
  1198
        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
  1199
        )
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1200
{
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1201
    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
  1202
    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
  1203
    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
  1204
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1205
    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
  1206
        return -EFAULT;
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1207
    }
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1208
1082
ff06c58e269c Renamed ecrt_slave_config_sync_managers() to ecrt_slave_config_pdos();
Florian Pose <fp@igh-essen.com>
parents: 1079
diff changeset
  1209
    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
  1210
        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
  1211
                data.sync_index);
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1212
        return -EINVAL;
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1213
    }
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1214
1189
acc6430bfb32 Use down_interruptible() wherever possible.
Florian Pose <fp@igh-essen.com>
parents: 1183
diff changeset
  1215
    if (down_interruptible(&master->master_sem))
acc6430bfb32 Use down_interruptible() wherever possible.
Florian Pose <fp@igh-essen.com>
parents: 1183
diff changeset
  1216
        return -EINTR;
1079
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1217
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1218
    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
  1219
                    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
  1220
        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
  1221
        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
  1222
                data.config_index);
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1223
        return -EINVAL;
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1224
    }
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1225
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1226
    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
  1227
                    &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
  1228
                    data.pdo_pos))) {
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1229
        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
  1230
        EC_ERR("Invalid Pdo position!\n");
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1231
        return -EINVAL;
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1232
    }
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1233
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1234
    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
  1235
    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
  1236
    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
  1237
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1238
    up(&master->master_sem);
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1239
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1240
    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
  1241
        return -EFAULT;
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
    return 0;
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1244
}
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1245
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1246
/*****************************************************************************/
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1247
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1248
/** Get slave configuration Pdo entry information.
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
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
  1251
        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
  1252
        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
  1253
        )
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1254
{
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1255
    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
  1256
    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
  1257
    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
  1258
    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
  1259
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1260
    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
  1261
        return -EFAULT;
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
1082
ff06c58e269c Renamed ecrt_slave_config_sync_managers() to ecrt_slave_config_pdos();
Florian Pose <fp@igh-essen.com>
parents: 1079
diff changeset
  1264
    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
  1265
        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
  1266
                data.sync_index);
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1267
        return -EINVAL;
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1268
    }
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1269
1189
acc6430bfb32 Use down_interruptible() wherever possible.
Florian Pose <fp@igh-essen.com>
parents: 1183
diff changeset
  1270
    if (down_interruptible(&master->master_sem))
acc6430bfb32 Use down_interruptible() wherever possible.
Florian Pose <fp@igh-essen.com>
parents: 1183
diff changeset
  1271
        return -EINTR;
1079
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1272
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1273
    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
  1274
                    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
  1275
        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
  1276
        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
  1277
                data.config_index);
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1278
        return -EINVAL;
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1279
    }
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1280
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1281
    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
  1282
                    &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
  1283
                    data.pdo_pos))) {
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1284
        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
  1285
        EC_ERR("Invalid Pdo position!\n");
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1286
        return -EINVAL;
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1287
    }
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1288
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1289
    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
  1290
                    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
  1291
        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
  1292
        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
  1293
        return -EINVAL;
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1294
    }
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1295
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1296
    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
  1297
    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
  1298
    data.bit_length = entry->bit_length;
1108
7beba3e7e6b4 Added ec_cdev_strcpy() function.
Florian Pose <fp@igh-essen.com>
parents: 1092
diff changeset
  1299
    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
  1300
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1301
    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
  1302
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1303
    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
  1304
        return -EFAULT;
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1305
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1306
    return 0;
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1307
}
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1308
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1309
/*****************************************************************************/
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1310
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1311
/** Get slave configuration Sdo information.
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
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
  1314
        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
  1315
        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
  1316
        )
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1317
{
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1318
    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
  1319
    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
  1320
    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
  1321
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1322
    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
  1323
        return -EFAULT;
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
1189
acc6430bfb32 Use down_interruptible() wherever possible.
Florian Pose <fp@igh-essen.com>
parents: 1183
diff changeset
  1326
    if (down_interruptible(&master->master_sem))
acc6430bfb32 Use down_interruptible() wherever possible.
Florian Pose <fp@igh-essen.com>
parents: 1183
diff changeset
  1327
        return -EINTR;
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
    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
  1330
                    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
  1331
        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
  1332
        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
  1333
                data.config_index);
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1334
        return -EINVAL;
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1335
    }
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1336
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1337
    if (!(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
  1338
                    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
  1339
        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
  1340
        EC_ERR("Invalid Sdo position!\n");
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1341
        return -EINVAL;
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1342
    }
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1343
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1344
    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
  1345
    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
  1346
    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
  1347
    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
  1348
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1349
    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
  1350
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1351
    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
  1352
        return -EFAULT;
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1353
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1354
    return 0;
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1355
}
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1356
922
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1357
/******************************************************************************
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1358
 * File operations
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1359
 *****************************************************************************/
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1360
1092
69393cf60399 Improved source code doc.
Florian Pose <fp@igh-essen.com>
parents: 1082
diff changeset
  1361
/** Called when the cdev is opened.
69393cf60399 Improved source code doc.
Florian Pose <fp@igh-essen.com>
parents: 1082
diff changeset
  1362
 */
922
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1363
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
  1364
{
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1365
    ec_cdev_t *cdev = container_of(inode->i_cdev, ec_cdev_t, cdev);
935
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
  1366
    ec_master_t *master = cdev->master;
922
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1367
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1368
    filp->private_data = cdev;
935
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
  1369
    if (master->debug_level)
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
  1370
        EC_DBG("File opened.\n");
922
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1371
    return 0;
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1372
}
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1373
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1374
/*****************************************************************************/
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1375
1092
69393cf60399 Improved source code doc.
Florian Pose <fp@igh-essen.com>
parents: 1082
diff changeset
  1376
/** Called when the cdev is closed.
69393cf60399 Improved source code doc.
Florian Pose <fp@igh-essen.com>
parents: 1082
diff changeset
  1377
 */
922
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1378
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
  1379
{
935
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
  1380
    ec_cdev_t *cdev = (ec_cdev_t *) filp->private_data;
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
  1381
    ec_master_t *master = cdev->master;
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
  1382
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
  1383
    if (master->debug_level)
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
  1384
        EC_DBG("File closed.\n");
922
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1385
    return 0;
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1386
}
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1387
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1388
/*****************************************************************************/
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1389
1092
69393cf60399 Improved source code doc.
Florian Pose <fp@igh-essen.com>
parents: 1082
diff changeset
  1390
/** Called when an ioctl() command is issued.
69393cf60399 Improved source code doc.
Florian Pose <fp@igh-essen.com>
parents: 1082
diff changeset
  1391
 */
935
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
  1392
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
  1393
{
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
  1394
    ec_cdev_t *cdev = (ec_cdev_t *) filp->private_data;
922
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1395
    ec_master_t *master = cdev->master;
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1396
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1397
    if (master->debug_level)
981
5a2bd04c555c Output decoded ioctl command number.
Florian Pose <fp@igh-essen.com>
parents: 980
diff changeset
  1398
        EC_DBG("ioctl(filp = %x, cmd = %u (%u), arg = %x)\n",
5a2bd04c555c Output decoded ioctl command number.
Florian Pose <fp@igh-essen.com>
parents: 980
diff changeset
  1399
                (u32) filp, (u32) cmd, (u32) _IOC_NR(cmd), (u32) arg);
935
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
  1400
922
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1401
    switch (cmd) {
957
ed5ac2e83495 Replaced EC_IOCTL_SLAVE_COUNT with EC_IOCTL_MASTER; implemented
Florian Pose <fp@igh-essen.com>
parents: 956
diff changeset
  1402
        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
  1403
            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
  1404
        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
  1405
            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
  1406
        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
  1407
            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
  1408
        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
  1409
            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
  1410
        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
  1411
            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
  1412
        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
  1413
            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
  1414
        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
  1415
            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
  1416
        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
  1417
            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
  1418
        case EC_IOCTL_MASTER_DEBUG:
972
ad59641a68c8 ioctl() permissions.
Florian Pose <fp@igh-essen.com>
parents: 968
diff changeset
  1419
            if (!(filp->f_mode & FMODE_WRITE))
ad59641a68c8 ioctl() permissions.
Florian Pose <fp@igh-essen.com>
parents: 968
diff changeset
  1420
                return -EPERM;
1079
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1421
            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
  1422
        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
  1423
            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
  1424
                return -EPERM;
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1425
            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
  1426
        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
  1427
            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
  1428
        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
  1429
            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
  1430
        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
  1431
            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
  1432
        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
  1433
            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
  1434
                return -EPERM;
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1435
            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
  1436
        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
  1437
            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
  1438
        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
  1439
            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
  1440
                return -EPERM;
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1441
            return ec_cdev_ioctl_slave_sii_write(master, arg);
1200
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1196
diff changeset
  1442
        case EC_IOCTL_SLAVE_PHY_READ:
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1196
diff changeset
  1443
            return ec_cdev_ioctl_slave_phy_read(master, arg);
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1196
diff changeset
  1444
        case EC_IOCTL_SLAVE_PHY_WRITE:
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1196
diff changeset
  1445
            if (!(filp->f_mode & FMODE_WRITE))
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1196
diff changeset
  1446
                return -EPERM;
ce1a65f06efc Added phy commands.
Florian Pose <fp@igh-essen.com>
parents: 1196
diff changeset
  1447
            return ec_cdev_ioctl_slave_phy_write(master, arg);
990
4f223f3df05a Bus configuration via 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 989
diff changeset
  1448
        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
  1449
            return ec_cdev_ioctl_config(master, arg);
990
4f223f3df05a Bus configuration via 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 989
diff changeset
  1450
        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
  1451
            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
  1452
        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
  1453
            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
  1454
        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
  1455
            return ec_cdev_ioctl_config_sdo(master, arg);
922
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
  1456
        default:
1079
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1457
            return -ENOTTY;
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1458
    }
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1459
}
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1460
ef1266652c4d Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents: 1075
diff changeset
  1461
/*****************************************************************************/