master/cdev.c
author Florian Pose <fp@igh-essen.com>
Thu, 12 Jun 2008 13:05:05 +0000
changeset 1006 90db4c3de57b
parent 1001 a8eab75aa8e3
child 1019 ed69d862ff44
permissions -rw-r--r--
Added a few debugging messages.
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 *);
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    54
ssize_t eccdev_read(struct file *, char __user *, size_t, loff_t *);
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    55
ssize_t eccdev_write(struct file *, const char __user *, size_t, loff_t *);
935
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
    56
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
    57
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    58
/*****************************************************************************/
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    59
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    60
static struct file_operations eccdev_fops = {
935
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
    61
    .owner          = THIS_MODULE,
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
    62
    .open           = eccdev_open,
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
    63
    .release        = eccdev_release,
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
    64
    .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
    65
};
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
/** \endcond */
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
/*****************************************************************************/
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
/** Constructor.
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
 * \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
    74
 */
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    75
int ec_cdev_init(
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    76
		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
    77
		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
    78
		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
    79
		)
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->master = master;
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    82
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    83
    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
    84
    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
    85
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    86
    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
    87
		 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
    88
		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
    89
		return -1;
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    90
    }
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    91
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    92
    return 0;
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
/*****************************************************************************/
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
/** Destructor.
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
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
   100
{
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   101
    cdev_del(&cdev->cdev);
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   102
}
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   103
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   104
/******************************************************************************
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   105
 * File operations
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   106
 *****************************************************************************/
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   107
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   108
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
   109
{
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   110
    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
   111
    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
   112
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   113
    filp->private_data = cdev;
935
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   114
    if (master->debug_level)
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   115
        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
   116
    return 0;
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   117
}
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   118
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   119
/*****************************************************************************/
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   120
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   121
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
   122
{
935
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   123
    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
   124
    ec_master_t *master = cdev->master;
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   125
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   126
    if (master->debug_level)
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   127
        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
   128
    return 0;
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   129
}
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   130
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   131
/*****************************************************************************/
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   132
935
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   133
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
   134
{
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   135
    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
   136
    ec_master_t *master = cdev->master;
935
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   137
    long retval = 0;
922
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   138
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   139
    if (master->debug_level)
981
5a2bd04c555c Output decoded ioctl command number.
Florian Pose <fp@igh-essen.com>
parents: 980
diff changeset
   140
        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
   141
                (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
   142
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   143
    // FIXME lock
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   144
    
922
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   145
    switch (cmd) {
957
ed5ac2e83495 Replaced EC_IOCTL_SLAVE_COUNT with EC_IOCTL_MASTER; implemented
Florian Pose <fp@igh-essen.com>
parents: 956
diff changeset
   146
        case EC_IOCTL_MASTER:
ed5ac2e83495 Replaced EC_IOCTL_SLAVE_COUNT with EC_IOCTL_MASTER; implemented
Florian Pose <fp@igh-essen.com>
parents: 956
diff changeset
   147
            {
ed5ac2e83495 Replaced EC_IOCTL_SLAVE_COUNT with EC_IOCTL_MASTER; implemented
Florian Pose <fp@igh-essen.com>
parents: 956
diff changeset
   148
                ec_ioctl_master_t data;
ed5ac2e83495 Replaced EC_IOCTL_SLAVE_COUNT with EC_IOCTL_MASTER; implemented
Florian Pose <fp@igh-essen.com>
parents: 956
diff changeset
   149
ed5ac2e83495 Replaced EC_IOCTL_SLAVE_COUNT with EC_IOCTL_MASTER; implemented
Florian Pose <fp@igh-essen.com>
parents: 956
diff changeset
   150
                data.slave_count = master->slave_count;
990
4f223f3df05a Bus configuration via 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 989
diff changeset
   151
                data.config_count = ec_master_config_count(master);
1001
a8eab75aa8e3 Removed EC_IOCTL_DOMAIN_COUNT.
Florian Pose <fp@igh-essen.com>
parents: 999
diff changeset
   152
                data.domain_count = ec_master_domain_count(master);
957
ed5ac2e83495 Replaced EC_IOCTL_SLAVE_COUNT with EC_IOCTL_MASTER; implemented
Florian Pose <fp@igh-essen.com>
parents: 956
diff changeset
   153
                data.mode = (uint8_t) master->mode;
ed5ac2e83495 Replaced EC_IOCTL_SLAVE_COUNT with EC_IOCTL_MASTER; implemented
Florian Pose <fp@igh-essen.com>
parents: 956
diff changeset
   154
                
ed5ac2e83495 Replaced EC_IOCTL_SLAVE_COUNT with EC_IOCTL_MASTER; implemented
Florian Pose <fp@igh-essen.com>
parents: 956
diff changeset
   155
                memcpy(data.devices[0].address, master->main_mac, ETH_ALEN); 
ed5ac2e83495 Replaced EC_IOCTL_SLAVE_COUNT with EC_IOCTL_MASTER; implemented
Florian Pose <fp@igh-essen.com>
parents: 956
diff changeset
   156
                data.devices[0].attached = master->main_device.dev ? 1 : 0;
ed5ac2e83495 Replaced EC_IOCTL_SLAVE_COUNT with EC_IOCTL_MASTER; implemented
Florian Pose <fp@igh-essen.com>
parents: 956
diff changeset
   157
                data.devices[0].tx_count = master->main_device.tx_count;
ed5ac2e83495 Replaced EC_IOCTL_SLAVE_COUNT with EC_IOCTL_MASTER; implemented
Florian Pose <fp@igh-essen.com>
parents: 956
diff changeset
   158
                data.devices[0].rx_count = master->main_device.rx_count;
ed5ac2e83495 Replaced EC_IOCTL_SLAVE_COUNT with EC_IOCTL_MASTER; implemented
Florian Pose <fp@igh-essen.com>
parents: 956
diff changeset
   159
                memcpy(data.devices[1].address, master->backup_mac, ETH_ALEN); 
ed5ac2e83495 Replaced EC_IOCTL_SLAVE_COUNT with EC_IOCTL_MASTER; implemented
Florian Pose <fp@igh-essen.com>
parents: 956
diff changeset
   160
                data.devices[1].attached = master->backup_device.dev ? 1 : 0;
ed5ac2e83495 Replaced EC_IOCTL_SLAVE_COUNT with EC_IOCTL_MASTER; implemented
Florian Pose <fp@igh-essen.com>
parents: 956
diff changeset
   161
                data.devices[1].tx_count = master->backup_device.tx_count;
ed5ac2e83495 Replaced EC_IOCTL_SLAVE_COUNT with EC_IOCTL_MASTER; implemented
Florian Pose <fp@igh-essen.com>
parents: 956
diff changeset
   162
                data.devices[1].rx_count = master->backup_device.rx_count;
ed5ac2e83495 Replaced EC_IOCTL_SLAVE_COUNT with EC_IOCTL_MASTER; implemented
Florian Pose <fp@igh-essen.com>
parents: 956
diff changeset
   163
999
14307580deb6 Removed unnecessary code.
Florian Pose <fp@igh-essen.com>
parents: 990
diff changeset
   164
                if (copy_to_user((void __user *) arg, &data, sizeof(data)))
14307580deb6 Removed unnecessary code.
Florian Pose <fp@igh-essen.com>
parents: 990
diff changeset
   165
                    retval = -EFAULT;
14307580deb6 Removed unnecessary code.
Florian Pose <fp@igh-essen.com>
parents: 990
diff changeset
   166
                break;
14307580deb6 Removed unnecessary code.
Florian Pose <fp@igh-essen.com>
parents: 990
diff changeset
   167
            }
935
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   168
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   169
        case EC_IOCTL_SLAVE:
922
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   170
            {
935
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   171
                ec_ioctl_slave_t data;
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   172
                const ec_slave_t *slave;
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   173
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   174
                if (copy_from_user(&data, (void __user *) arg, sizeof(data))) {
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   175
                    retval = -EFAULT;
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   176
                    break;
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   177
                }
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   178
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   179
                if (!(slave = ec_master_find_slave(
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   180
                                master, 0, data.position))) {
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   181
                    EC_ERR("Slave %u does not exist!\n", data.position);
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   182
                    retval = -EINVAL;
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   183
                    break;
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   184
                }
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   185
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   186
                data.vendor_id = slave->sii.vendor_id;
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   187
                data.product_code = slave->sii.product_code;
938
5b936e8e39fa Added 'xml' command to generate a slave description file from a real
Florian Pose <fp@igh-essen.com>
parents: 935
diff changeset
   188
                data.revision_number = slave->sii.revision_number;
5b936e8e39fa Added 'xml' command to generate a slave description file from a real
Florian Pose <fp@igh-essen.com>
parents: 935
diff changeset
   189
                data.serial_number = slave->sii.serial_number;
935
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   190
                data.alias = slave->sii.alias;
989
816663ca9370 Slave information via 'ethercat slave'.
Florian Pose <fp@igh-essen.com>
parents: 987
diff changeset
   191
                data.rx_mailbox_offset = slave->sii.rx_mailbox_offset;
816663ca9370 Slave information via 'ethercat slave'.
Florian Pose <fp@igh-essen.com>
parents: 987
diff changeset
   192
                data.rx_mailbox_size = slave->sii.rx_mailbox_size;
816663ca9370 Slave information via 'ethercat slave'.
Florian Pose <fp@igh-essen.com>
parents: 987
diff changeset
   193
                data.tx_mailbox_offset = slave->sii.tx_mailbox_offset;
816663ca9370 Slave information via 'ethercat slave'.
Florian Pose <fp@igh-essen.com>
parents: 987
diff changeset
   194
                data.tx_mailbox_size = slave->sii.tx_mailbox_size;
816663ca9370 Slave information via 'ethercat slave'.
Florian Pose <fp@igh-essen.com>
parents: 987
diff changeset
   195
                data.mailbox_protocols = slave->sii.mailbox_protocols;
816663ca9370 Slave information via 'ethercat slave'.
Florian Pose <fp@igh-essen.com>
parents: 987
diff changeset
   196
                data.has_general_category = slave->sii.has_general;
816663ca9370 Slave information via 'ethercat slave'.
Florian Pose <fp@igh-essen.com>
parents: 987
diff changeset
   197
                data.coe_details = slave->sii.coe_details;
816663ca9370 Slave information via 'ethercat slave'.
Florian Pose <fp@igh-essen.com>
parents: 987
diff changeset
   198
                data.general_flags = slave->sii.general_flags;
816663ca9370 Slave information via 'ethercat slave'.
Florian Pose <fp@igh-essen.com>
parents: 987
diff changeset
   199
                data.current_on_ebus = slave->sii.current_on_ebus;
935
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   200
                data.state = slave->current_state;
987
3c9090138140 Display error flag in 'ethercat ls'; cleaned up usage of error flag;
Florian Pose <fp@igh-essen.com>
parents: 981
diff changeset
   201
                data.error_flag = slave->error_flag;
935
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   202
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   203
                data.sync_count = slave->sii.sync_count;
965
1aee4aa1def3 Implemented Sdo dictionary info via 'ethercat sdos'.
Florian Pose <fp@igh-essen.com>
parents: 960
diff changeset
   204
                data.sdo_count = ec_slave_sdo_count(slave);
978
2962baf7e6d1 Implemented SII read.
Florian Pose <fp@igh-essen.com>
parents: 974
diff changeset
   205
                data.sii_nwords = slave->sii_nwords;
935
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   206
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   207
                if (slave->sii.name) {
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   208
                    strncpy(data.name, slave->sii.name,
990
4f223f3df05a Bus configuration via 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 989
diff changeset
   209
                            EC_IOCTL_STRING_SIZE);
4f223f3df05a Bus configuration via 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 989
diff changeset
   210
                    data.name[EC_IOCTL_STRING_SIZE - 1] = 0;
935
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   211
                } else {
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   212
                    data.name[0] = 0;
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   213
                }
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   214
999
14307580deb6 Removed unnecessary code.
Florian Pose <fp@igh-essen.com>
parents: 990
diff changeset
   215
                if (copy_to_user((void __user *) arg, &data, sizeof(data)))
14307580deb6 Removed unnecessary code.
Florian Pose <fp@igh-essen.com>
parents: 990
diff changeset
   216
                    retval = -EFAULT;
935
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   217
                break;
922
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   218
            }
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   219
935
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   220
        case EC_IOCTL_SYNC:
922
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   221
            {
935
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   222
                ec_ioctl_sync_t data;
922
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   223
                const ec_slave_t *slave;
935
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   224
                const ec_sync_t *sync;
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   225
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   226
                if (copy_from_user(&data, (void __user *) arg, sizeof(data))) {
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   227
                    retval = -EFAULT;
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   228
                    break;
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   229
                }
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   230
                
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   231
                if (!(slave = ec_master_find_slave(
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   232
                                master, 0, data.slave_position))) {
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   233
                    EC_ERR("Slave %u does not exist!\n", data.slave_position);
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   234
                    retval = -EINVAL;
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   235
                    break;
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   236
                }
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   237
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   238
                if (data.sync_index >= slave->sii.sync_count) {
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   239
                    EC_ERR("Sync manager %u does not exist in slave %u!\n",
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   240
                            data.sync_index, data.slave_position);
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   241
                    retval = -EINVAL;
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   242
                    break;
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   243
                }
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   244
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   245
                sync = &slave->sii.syncs[data.sync_index];
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   246
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   247
                data.physical_start_address = sync->physical_start_address;
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   248
                data.default_size = sync->length;
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   249
                data.control_register = sync->control_register;
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   250
                data.enable = sync->enable;
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   251
                data.assign_source = sync->assign_source;
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   252
                data.pdo_count = ec_pdo_list_count(&sync->pdos);
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   253
999
14307580deb6 Removed unnecessary code.
Florian Pose <fp@igh-essen.com>
parents: 990
diff changeset
   254
                if (copy_to_user((void __user *) arg, &data, sizeof(data)))
14307580deb6 Removed unnecessary code.
Florian Pose <fp@igh-essen.com>
parents: 990
diff changeset
   255
                    retval = -EFAULT;
935
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   256
                break;
922
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   257
            }
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   258
935
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   259
        case EC_IOCTL_PDO:
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   260
            {
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   261
                ec_ioctl_pdo_t data;
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   262
                const ec_slave_t *slave;
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   263
                const ec_sync_t *sync;
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   264
                const ec_pdo_t *pdo;
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   265
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   266
                if (copy_from_user(&data, (void __user *) arg, sizeof(data))) {
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   267
                    retval = -EFAULT;
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   268
                    break;
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   269
                }
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   270
                
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   271
                if (!(slave = ec_master_find_slave(
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   272
                                master, 0, data.slave_position))) {
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   273
                    EC_ERR("Slave %u does not exist!\n", data.slave_position);
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   274
                    retval = -EINVAL;
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   275
                    break;
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   276
                }
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   277
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   278
                if (data.sync_index >= slave->sii.sync_count) {
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   279
                    EC_ERR("Sync manager %u does not exist in slave %u!\n",
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   280
                            data.sync_index, data.slave_position);
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   281
                    retval = -EINVAL;
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   282
                    break;
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   283
                }
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   284
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   285
                sync = &slave->sii.syncs[data.sync_index];
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   286
                if (!(pdo = ec_pdo_list_find_pdo_by_pos_const(
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   287
                                &sync->pdos, data.pdo_pos))) {
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   288
                    EC_ERR("Sync manager %u does not contain a Pdo with "
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   289
                            "position %u in slave %u!\n", data.sync_index,
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   290
                            data.pdo_pos, data.slave_position);
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   291
                    retval = -EINVAL;
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   292
                    break;
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   293
                }
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   294
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   295
                data.dir = pdo->dir;
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   296
                data.index = pdo->index;
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   297
                data.entry_count = ec_pdo_entry_count(pdo);
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   298
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   299
                if (pdo->name) {
990
4f223f3df05a Bus configuration via 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 989
diff changeset
   300
                    strncpy(data.name, pdo->name, EC_IOCTL_STRING_SIZE);
4f223f3df05a Bus configuration via 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 989
diff changeset
   301
                    data.name[EC_IOCTL_STRING_SIZE - 1] = 0;
935
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   302
                } else {
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   303
                    data.name[0] = 0;
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   304
                }
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   305
999
14307580deb6 Removed unnecessary code.
Florian Pose <fp@igh-essen.com>
parents: 990
diff changeset
   306
                if (copy_to_user((void __user *) arg, &data, sizeof(data)))
14307580deb6 Removed unnecessary code.
Florian Pose <fp@igh-essen.com>
parents: 990
diff changeset
   307
                    retval = -EFAULT;
935
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   308
                break;
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   309
            }
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   310
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   311
        case EC_IOCTL_PDO_ENTRY:
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   312
            {
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   313
                ec_ioctl_pdo_entry_t data;
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   314
                const ec_slave_t *slave;
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   315
                const ec_sync_t *sync;
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   316
                const ec_pdo_t *pdo;
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   317
                const ec_pdo_entry_t *entry;
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   318
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   319
                if (copy_from_user(&data, (void __user *) arg, sizeof(data))) {
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   320
                    retval = -EFAULT;
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   321
                    break;
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   322
                }
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   323
                
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   324
                if (!(slave = ec_master_find_slave(
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   325
                                master, 0, data.slave_position))) {
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   326
                    EC_ERR("Slave %u does not exist!\n", data.slave_position);
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   327
                    retval = -EINVAL;
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   328
                    break;
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   329
                }
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   330
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   331
                if (data.sync_index >= slave->sii.sync_count) {
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   332
                    EC_ERR("Sync manager %u does not exist in slave %u!\n",
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   333
                            data.sync_index, data.slave_position);
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   334
                    retval = -EINVAL;
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   335
                    break;
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   336
                }
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   337
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   338
                sync = &slave->sii.syncs[data.sync_index];
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   339
                if (!(pdo = ec_pdo_list_find_pdo_by_pos_const(
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   340
                                &sync->pdos, data.pdo_pos))) {
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   341
                    EC_ERR("Sync manager %u does not contain a Pdo with "
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   342
                            "position %u in slave %u!\n", data.sync_index,
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   343
                            data.pdo_pos, data.slave_position);
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   344
                    retval = -EINVAL;
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   345
                    break;
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   346
                }
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   347
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   348
                if (!(entry = ec_pdo_find_entry_by_pos_const(
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   349
                                pdo, data.entry_pos))) {
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   350
                    EC_ERR("Pdo 0x%04X does not contain an entry with "
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   351
                            "position %u in slave %u!\n", data.pdo_pos,
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   352
                            data.entry_pos, data.slave_position);
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   353
                    retval = -EINVAL;
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   354
                    break;
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   355
                }
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   356
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   357
                data.index = entry->index;
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   358
                data.subindex = entry->subindex;
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   359
                data.bit_length = entry->bit_length;
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   360
                if (entry->name) {
990
4f223f3df05a Bus configuration via 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 989
diff changeset
   361
                    strncpy(data.name, entry->name, EC_IOCTL_STRING_SIZE);
4f223f3df05a Bus configuration via 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 989
diff changeset
   362
                    data.name[EC_IOCTL_STRING_SIZE - 1] = 0;
935
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   363
                } else {
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   364
                    data.name[0] = 0;
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   365
                }
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   366
999
14307580deb6 Removed unnecessary code.
Florian Pose <fp@igh-essen.com>
parents: 990
diff changeset
   367
                if (copy_to_user((void __user *) arg, &data, sizeof(data)))
14307580deb6 Removed unnecessary code.
Florian Pose <fp@igh-essen.com>
parents: 990
diff changeset
   368
                    retval = -EFAULT;
935
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   369
                break;
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   370
            }
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   371
948
1cfab7161491 Implemented domain command.
Florian Pose <fp@igh-essen.com>
parents: 938
diff changeset
   372
        case EC_IOCTL_DOMAIN:
1cfab7161491 Implemented domain command.
Florian Pose <fp@igh-essen.com>
parents: 938
diff changeset
   373
            {
1cfab7161491 Implemented domain command.
Florian Pose <fp@igh-essen.com>
parents: 938
diff changeset
   374
                ec_ioctl_domain_t data;
1cfab7161491 Implemented domain command.
Florian Pose <fp@igh-essen.com>
parents: 938
diff changeset
   375
                const ec_domain_t *domain;
1cfab7161491 Implemented domain command.
Florian Pose <fp@igh-essen.com>
parents: 938
diff changeset
   376
1cfab7161491 Implemented domain command.
Florian Pose <fp@igh-essen.com>
parents: 938
diff changeset
   377
                if (copy_from_user(&data, (void __user *) arg, sizeof(data))) {
1cfab7161491 Implemented domain command.
Florian Pose <fp@igh-essen.com>
parents: 938
diff changeset
   378
                    retval = -EFAULT;
1cfab7161491 Implemented domain command.
Florian Pose <fp@igh-essen.com>
parents: 938
diff changeset
   379
                    break;
1cfab7161491 Implemented domain command.
Florian Pose <fp@igh-essen.com>
parents: 938
diff changeset
   380
                }
1cfab7161491 Implemented domain command.
Florian Pose <fp@igh-essen.com>
parents: 938
diff changeset
   381
                
1cfab7161491 Implemented domain command.
Florian Pose <fp@igh-essen.com>
parents: 938
diff changeset
   382
                if (!(domain = ec_master_find_domain(master, data.index))) {
1cfab7161491 Implemented domain command.
Florian Pose <fp@igh-essen.com>
parents: 938
diff changeset
   383
                    EC_ERR("Domain %u does not exist!\n", data.index);
1cfab7161491 Implemented domain command.
Florian Pose <fp@igh-essen.com>
parents: 938
diff changeset
   384
                    retval = -EINVAL;
1cfab7161491 Implemented domain command.
Florian Pose <fp@igh-essen.com>
parents: 938
diff changeset
   385
                    break;
1cfab7161491 Implemented domain command.
Florian Pose <fp@igh-essen.com>
parents: 938
diff changeset
   386
                }
1cfab7161491 Implemented domain command.
Florian Pose <fp@igh-essen.com>
parents: 938
diff changeset
   387
1cfab7161491 Implemented domain command.
Florian Pose <fp@igh-essen.com>
parents: 938
diff changeset
   388
                data.data_size = domain->data_size;
1cfab7161491 Implemented domain command.
Florian Pose <fp@igh-essen.com>
parents: 938
diff changeset
   389
                data.logical_base_address = domain->logical_base_address;
1cfab7161491 Implemented domain command.
Florian Pose <fp@igh-essen.com>
parents: 938
diff changeset
   390
                data.working_counter = domain->working_counter;
1cfab7161491 Implemented domain command.
Florian Pose <fp@igh-essen.com>
parents: 938
diff changeset
   391
                data.expected_working_counter = domain->expected_working_counter;
950
8b00e63fff90 'ethercat domain' shows domain contents and process data.
Florian Pose <fp@igh-essen.com>
parents: 949
diff changeset
   392
                data.fmmu_count = ec_domain_fmmu_count(domain);
8b00e63fff90 'ethercat domain' shows domain contents and process data.
Florian Pose <fp@igh-essen.com>
parents: 949
diff changeset
   393
999
14307580deb6 Removed unnecessary code.
Florian Pose <fp@igh-essen.com>
parents: 990
diff changeset
   394
                if (copy_to_user((void __user *) arg, &data, sizeof(data)))
14307580deb6 Removed unnecessary code.
Florian Pose <fp@igh-essen.com>
parents: 990
diff changeset
   395
                    retval = -EFAULT;
950
8b00e63fff90 'ethercat domain' shows domain contents and process data.
Florian Pose <fp@igh-essen.com>
parents: 949
diff changeset
   396
                break;
8b00e63fff90 'ethercat domain' shows domain contents and process data.
Florian Pose <fp@igh-essen.com>
parents: 949
diff changeset
   397
            }
8b00e63fff90 'ethercat domain' shows domain contents and process data.
Florian Pose <fp@igh-essen.com>
parents: 949
diff changeset
   398
8b00e63fff90 'ethercat domain' shows domain contents and process data.
Florian Pose <fp@igh-essen.com>
parents: 949
diff changeset
   399
        case EC_IOCTL_DOMAIN_FMMU:
8b00e63fff90 'ethercat domain' shows domain contents and process data.
Florian Pose <fp@igh-essen.com>
parents: 949
diff changeset
   400
            {
8b00e63fff90 'ethercat domain' shows domain contents and process data.
Florian Pose <fp@igh-essen.com>
parents: 949
diff changeset
   401
                ec_ioctl_domain_fmmu_t data;
8b00e63fff90 'ethercat domain' shows domain contents and process data.
Florian Pose <fp@igh-essen.com>
parents: 949
diff changeset
   402
                const ec_domain_t *domain;
8b00e63fff90 'ethercat domain' shows domain contents and process data.
Florian Pose <fp@igh-essen.com>
parents: 949
diff changeset
   403
                const ec_fmmu_config_t *fmmu;
8b00e63fff90 'ethercat domain' shows domain contents and process data.
Florian Pose <fp@igh-essen.com>
parents: 949
diff changeset
   404
8b00e63fff90 'ethercat domain' shows domain contents and process data.
Florian Pose <fp@igh-essen.com>
parents: 949
diff changeset
   405
                if (copy_from_user(&data, (void __user *) arg, sizeof(data))) {
8b00e63fff90 'ethercat domain' shows domain contents and process data.
Florian Pose <fp@igh-essen.com>
parents: 949
diff changeset
   406
                    retval = -EFAULT;
8b00e63fff90 'ethercat domain' shows domain contents and process data.
Florian Pose <fp@igh-essen.com>
parents: 949
diff changeset
   407
                    break;
8b00e63fff90 'ethercat domain' shows domain contents and process data.
Florian Pose <fp@igh-essen.com>
parents: 949
diff changeset
   408
                }
8b00e63fff90 'ethercat domain' shows domain contents and process data.
Florian Pose <fp@igh-essen.com>
parents: 949
diff changeset
   409
                
8b00e63fff90 'ethercat domain' shows domain contents and process data.
Florian Pose <fp@igh-essen.com>
parents: 949
diff changeset
   410
                if (!(domain = ec_master_find_domain(master, data.domain_index))) {
8b00e63fff90 'ethercat domain' shows domain contents and process data.
Florian Pose <fp@igh-essen.com>
parents: 949
diff changeset
   411
                    EC_ERR("Domain %u does not exist!\n", data.domain_index);
8b00e63fff90 'ethercat domain' shows domain contents and process data.
Florian Pose <fp@igh-essen.com>
parents: 949
diff changeset
   412
                    retval = -EINVAL;
8b00e63fff90 'ethercat domain' shows domain contents and process data.
Florian Pose <fp@igh-essen.com>
parents: 949
diff changeset
   413
                    break;
8b00e63fff90 'ethercat domain' shows domain contents and process data.
Florian Pose <fp@igh-essen.com>
parents: 949
diff changeset
   414
                }
8b00e63fff90 'ethercat domain' shows domain contents and process data.
Florian Pose <fp@igh-essen.com>
parents: 949
diff changeset
   415
8b00e63fff90 'ethercat domain' shows domain contents and process data.
Florian Pose <fp@igh-essen.com>
parents: 949
diff changeset
   416
                if (!(fmmu = ec_domain_find_fmmu(domain, data.fmmu_index))) {
8b00e63fff90 'ethercat domain' shows domain contents and process data.
Florian Pose <fp@igh-essen.com>
parents: 949
diff changeset
   417
                    EC_ERR("Domain %u has less than %u fmmu configurations.\n",
8b00e63fff90 'ethercat domain' shows domain contents and process data.
Florian Pose <fp@igh-essen.com>
parents: 949
diff changeset
   418
                            data.domain_index, data.fmmu_index + 1);
8b00e63fff90 'ethercat domain' shows domain contents and process data.
Florian Pose <fp@igh-essen.com>
parents: 949
diff changeset
   419
                    retval = -EINVAL;
8b00e63fff90 'ethercat domain' shows domain contents and process data.
Florian Pose <fp@igh-essen.com>
parents: 949
diff changeset
   420
                    break;
8b00e63fff90 'ethercat domain' shows domain contents and process data.
Florian Pose <fp@igh-essen.com>
parents: 949
diff changeset
   421
                }
8b00e63fff90 'ethercat domain' shows domain contents and process data.
Florian Pose <fp@igh-essen.com>
parents: 949
diff changeset
   422
8b00e63fff90 'ethercat domain' shows domain contents and process data.
Florian Pose <fp@igh-essen.com>
parents: 949
diff changeset
   423
                data.slave_config_alias = fmmu->sc->alias;
8b00e63fff90 'ethercat domain' shows domain contents and process data.
Florian Pose <fp@igh-essen.com>
parents: 949
diff changeset
   424
                data.slave_config_position = fmmu->sc->position;
8b00e63fff90 'ethercat domain' shows domain contents and process data.
Florian Pose <fp@igh-essen.com>
parents: 949
diff changeset
   425
                data.fmmu_dir = fmmu->dir;
8b00e63fff90 'ethercat domain' shows domain contents and process data.
Florian Pose <fp@igh-essen.com>
parents: 949
diff changeset
   426
                data.logical_address = fmmu->logical_start_address;
8b00e63fff90 'ethercat domain' shows domain contents and process data.
Florian Pose <fp@igh-essen.com>
parents: 949
diff changeset
   427
                data.data_size = fmmu->data_size;
948
1cfab7161491 Implemented domain command.
Florian Pose <fp@igh-essen.com>
parents: 938
diff changeset
   428
999
14307580deb6 Removed unnecessary code.
Florian Pose <fp@igh-essen.com>
parents: 990
diff changeset
   429
                if (copy_to_user((void __user *) arg, &data, sizeof(data)))
14307580deb6 Removed unnecessary code.
Florian Pose <fp@igh-essen.com>
parents: 990
diff changeset
   430
                    retval = -EFAULT;
948
1cfab7161491 Implemented domain command.
Florian Pose <fp@igh-essen.com>
parents: 938
diff changeset
   431
                break;
1cfab7161491 Implemented domain command.
Florian Pose <fp@igh-essen.com>
parents: 938
diff changeset
   432
            }
1cfab7161491 Implemented domain command.
Florian Pose <fp@igh-essen.com>
parents: 938
diff changeset
   433
949
e424c0074c67 Implemented 'data' command.
Florian Pose <fp@igh-essen.com>
parents: 948
diff changeset
   434
        case EC_IOCTL_DATA:
e424c0074c67 Implemented 'data' command.
Florian Pose <fp@igh-essen.com>
parents: 948
diff changeset
   435
            {
e424c0074c67 Implemented 'data' command.
Florian Pose <fp@igh-essen.com>
parents: 948
diff changeset
   436
                ec_ioctl_data_t data;
e424c0074c67 Implemented 'data' command.
Florian Pose <fp@igh-essen.com>
parents: 948
diff changeset
   437
                const ec_domain_t *domain;
e424c0074c67 Implemented 'data' command.
Florian Pose <fp@igh-essen.com>
parents: 948
diff changeset
   438
e424c0074c67 Implemented 'data' command.
Florian Pose <fp@igh-essen.com>
parents: 948
diff changeset
   439
                if (copy_from_user(&data, (void __user *) arg, sizeof(data))) {
e424c0074c67 Implemented 'data' command.
Florian Pose <fp@igh-essen.com>
parents: 948
diff changeset
   440
                    retval = -EFAULT;
e424c0074c67 Implemented 'data' command.
Florian Pose <fp@igh-essen.com>
parents: 948
diff changeset
   441
                    break;
e424c0074c67 Implemented 'data' command.
Florian Pose <fp@igh-essen.com>
parents: 948
diff changeset
   442
                }
e424c0074c67 Implemented 'data' command.
Florian Pose <fp@igh-essen.com>
parents: 948
diff changeset
   443
                
e424c0074c67 Implemented 'data' command.
Florian Pose <fp@igh-essen.com>
parents: 948
diff changeset
   444
                if (!(domain = ec_master_find_domain(master, data.domain_index))) {
e424c0074c67 Implemented 'data' command.
Florian Pose <fp@igh-essen.com>
parents: 948
diff changeset
   445
                    EC_ERR("Domain %u does not exist!\n", data.domain_index);
e424c0074c67 Implemented 'data' command.
Florian Pose <fp@igh-essen.com>
parents: 948
diff changeset
   446
                    retval = -EINVAL;
e424c0074c67 Implemented 'data' command.
Florian Pose <fp@igh-essen.com>
parents: 948
diff changeset
   447
                    break;
e424c0074c67 Implemented 'data' command.
Florian Pose <fp@igh-essen.com>
parents: 948
diff changeset
   448
                }
e424c0074c67 Implemented 'data' command.
Florian Pose <fp@igh-essen.com>
parents: 948
diff changeset
   449
e424c0074c67 Implemented 'data' command.
Florian Pose <fp@igh-essen.com>
parents: 948
diff changeset
   450
                if (domain->data_size != data.data_size) {
e424c0074c67 Implemented 'data' command.
Florian Pose <fp@igh-essen.com>
parents: 948
diff changeset
   451
                    EC_ERR("Data size mismatch %u/%u!\n",
e424c0074c67 Implemented 'data' command.
Florian Pose <fp@igh-essen.com>
parents: 948
diff changeset
   452
                            data.data_size, domain->data_size);
e424c0074c67 Implemented 'data' command.
Florian Pose <fp@igh-essen.com>
parents: 948
diff changeset
   453
                    retval = -EFAULT;
e424c0074c67 Implemented 'data' command.
Florian Pose <fp@igh-essen.com>
parents: 948
diff changeset
   454
                    break;
e424c0074c67 Implemented 'data' command.
Florian Pose <fp@igh-essen.com>
parents: 948
diff changeset
   455
                }
e424c0074c67 Implemented 'data' command.
Florian Pose <fp@igh-essen.com>
parents: 948
diff changeset
   456
e424c0074c67 Implemented 'data' command.
Florian Pose <fp@igh-essen.com>
parents: 948
diff changeset
   457
                if (copy_to_user((void __user *) data.target, domain->data,
999
14307580deb6 Removed unnecessary code.
Florian Pose <fp@igh-essen.com>
parents: 990
diff changeset
   458
                            domain->data_size))
14307580deb6 Removed unnecessary code.
Florian Pose <fp@igh-essen.com>
parents: 990
diff changeset
   459
                    retval = -EFAULT;
949
e424c0074c67 Implemented 'data' command.
Florian Pose <fp@igh-essen.com>
parents: 948
diff changeset
   460
                break;
e424c0074c67 Implemented 'data' command.
Florian Pose <fp@igh-essen.com>
parents: 948
diff changeset
   461
            }
e424c0074c67 Implemented 'data' command.
Florian Pose <fp@igh-essen.com>
parents: 948
diff changeset
   462
957
ed5ac2e83495 Replaced EC_IOCTL_SLAVE_COUNT with EC_IOCTL_MASTER; implemented
Florian Pose <fp@igh-essen.com>
parents: 956
diff changeset
   463
        case EC_IOCTL_SET_DEBUG:
972
ad59641a68c8 ioctl() permissions.
Florian Pose <fp@igh-essen.com>
parents: 968
diff changeset
   464
            if (!(filp->f_mode & FMODE_WRITE))
ad59641a68c8 ioctl() permissions.
Florian Pose <fp@igh-essen.com>
parents: 968
diff changeset
   465
                return -EPERM;
999
14307580deb6 Removed unnecessary code.
Florian Pose <fp@igh-essen.com>
parents: 990
diff changeset
   466
            if (ec_master_debug_level(master, (unsigned int) arg))
956
d9b9bc794d10 Implemented 'ethercat debug' command.
Florian Pose <fp@igh-essen.com>
parents: 950
diff changeset
   467
                retval = -EINVAL;
d9b9bc794d10 Implemented 'ethercat debug' command.
Florian Pose <fp@igh-essen.com>
parents: 950
diff changeset
   468
            break;
d9b9bc794d10 Implemented 'ethercat debug' command.
Florian Pose <fp@igh-essen.com>
parents: 950
diff changeset
   469
960
36e460ffbb5e Request slave state(s) with 'ethercat state'; removed sysfs state file.
Florian Pose <fp@igh-essen.com>
parents: 957
diff changeset
   470
        case EC_IOCTL_SLAVE_STATE:
36e460ffbb5e Request slave state(s) with 'ethercat state'; removed sysfs state file.
Florian Pose <fp@igh-essen.com>
parents: 957
diff changeset
   471
            {
36e460ffbb5e Request slave state(s) with 'ethercat state'; removed sysfs state file.
Florian Pose <fp@igh-essen.com>
parents: 957
diff changeset
   472
                ec_ioctl_slave_state_t data;
36e460ffbb5e Request slave state(s) with 'ethercat state'; removed sysfs state file.
Florian Pose <fp@igh-essen.com>
parents: 957
diff changeset
   473
                ec_slave_t *slave;
36e460ffbb5e Request slave state(s) with 'ethercat state'; removed sysfs state file.
Florian Pose <fp@igh-essen.com>
parents: 957
diff changeset
   474
972
ad59641a68c8 ioctl() permissions.
Florian Pose <fp@igh-essen.com>
parents: 968
diff changeset
   475
                if (!(filp->f_mode & FMODE_WRITE))
ad59641a68c8 ioctl() permissions.
Florian Pose <fp@igh-essen.com>
parents: 968
diff changeset
   476
                    return -EPERM;
ad59641a68c8 ioctl() permissions.
Florian Pose <fp@igh-essen.com>
parents: 968
diff changeset
   477
960
36e460ffbb5e Request slave state(s) with 'ethercat state'; removed sysfs state file.
Florian Pose <fp@igh-essen.com>
parents: 957
diff changeset
   478
                if (copy_from_user(&data, (void __user *) arg, sizeof(data))) {
36e460ffbb5e Request slave state(s) with 'ethercat state'; removed sysfs state file.
Florian Pose <fp@igh-essen.com>
parents: 957
diff changeset
   479
                    retval = -EFAULT;
36e460ffbb5e Request slave state(s) with 'ethercat state'; removed sysfs state file.
Florian Pose <fp@igh-essen.com>
parents: 957
diff changeset
   480
                    break;
36e460ffbb5e Request slave state(s) with 'ethercat state'; removed sysfs state file.
Florian Pose <fp@igh-essen.com>
parents: 957
diff changeset
   481
                }
36e460ffbb5e Request slave state(s) with 'ethercat state'; removed sysfs state file.
Florian Pose <fp@igh-essen.com>
parents: 957
diff changeset
   482
                
36e460ffbb5e Request slave state(s) with 'ethercat state'; removed sysfs state file.
Florian Pose <fp@igh-essen.com>
parents: 957
diff changeset
   483
                if (!(slave = ec_master_find_slave(
36e460ffbb5e Request slave state(s) with 'ethercat state'; removed sysfs state file.
Florian Pose <fp@igh-essen.com>
parents: 957
diff changeset
   484
                                master, 0, data.slave_position))) {
36e460ffbb5e Request slave state(s) with 'ethercat state'; removed sysfs state file.
Florian Pose <fp@igh-essen.com>
parents: 957
diff changeset
   485
                    EC_ERR("Slave %u does not exist!\n", data.slave_position);
36e460ffbb5e Request slave state(s) with 'ethercat state'; removed sysfs state file.
Florian Pose <fp@igh-essen.com>
parents: 957
diff changeset
   486
                    retval = -EINVAL;
36e460ffbb5e Request slave state(s) with 'ethercat state'; removed sysfs state file.
Florian Pose <fp@igh-essen.com>
parents: 957
diff changeset
   487
                    break;
36e460ffbb5e Request slave state(s) with 'ethercat state'; removed sysfs state file.
Florian Pose <fp@igh-essen.com>
parents: 957
diff changeset
   488
                }
36e460ffbb5e Request slave state(s) with 'ethercat state'; removed sysfs state file.
Florian Pose <fp@igh-essen.com>
parents: 957
diff changeset
   489
36e460ffbb5e Request slave state(s) with 'ethercat state'; removed sysfs state file.
Florian Pose <fp@igh-essen.com>
parents: 957
diff changeset
   490
                ec_slave_request_state(slave, data.requested_state);
36e460ffbb5e Request slave state(s) with 'ethercat state'; removed sysfs state file.
Florian Pose <fp@igh-essen.com>
parents: 957
diff changeset
   491
                break;
36e460ffbb5e Request slave state(s) with 'ethercat state'; removed sysfs state file.
Florian Pose <fp@igh-essen.com>
parents: 957
diff changeset
   492
            }
36e460ffbb5e Request slave state(s) with 'ethercat state'; removed sysfs state file.
Florian Pose <fp@igh-essen.com>
parents: 957
diff changeset
   493
965
1aee4aa1def3 Implemented Sdo dictionary info via 'ethercat sdos'.
Florian Pose <fp@igh-essen.com>
parents: 960
diff changeset
   494
        case EC_IOCTL_SDO:
1aee4aa1def3 Implemented Sdo dictionary info via 'ethercat sdos'.
Florian Pose <fp@igh-essen.com>
parents: 960
diff changeset
   495
            {
1aee4aa1def3 Implemented Sdo dictionary info via 'ethercat sdos'.
Florian Pose <fp@igh-essen.com>
parents: 960
diff changeset
   496
                ec_ioctl_sdo_t data;
1aee4aa1def3 Implemented Sdo dictionary info via 'ethercat sdos'.
Florian Pose <fp@igh-essen.com>
parents: 960
diff changeset
   497
                const ec_slave_t *slave;
1aee4aa1def3 Implemented Sdo dictionary info via 'ethercat sdos'.
Florian Pose <fp@igh-essen.com>
parents: 960
diff changeset
   498
                const ec_sdo_t *sdo;
1aee4aa1def3 Implemented Sdo dictionary info via 'ethercat sdos'.
Florian Pose <fp@igh-essen.com>
parents: 960
diff changeset
   499
1aee4aa1def3 Implemented Sdo dictionary info via 'ethercat sdos'.
Florian Pose <fp@igh-essen.com>
parents: 960
diff changeset
   500
                if (copy_from_user(&data, (void __user *) arg, sizeof(data))) {
1aee4aa1def3 Implemented Sdo dictionary info via 'ethercat sdos'.
Florian Pose <fp@igh-essen.com>
parents: 960
diff changeset
   501
                    retval = -EFAULT;
1aee4aa1def3 Implemented Sdo dictionary info via 'ethercat sdos'.
Florian Pose <fp@igh-essen.com>
parents: 960
diff changeset
   502
                    break;
1aee4aa1def3 Implemented Sdo dictionary info via 'ethercat sdos'.
Florian Pose <fp@igh-essen.com>
parents: 960
diff changeset
   503
                }
1aee4aa1def3 Implemented Sdo dictionary info via 'ethercat sdos'.
Florian Pose <fp@igh-essen.com>
parents: 960
diff changeset
   504
                
1aee4aa1def3 Implemented Sdo dictionary info via 'ethercat sdos'.
Florian Pose <fp@igh-essen.com>
parents: 960
diff changeset
   505
                if (!(slave = ec_master_find_slave(
1aee4aa1def3 Implemented Sdo dictionary info via 'ethercat sdos'.
Florian Pose <fp@igh-essen.com>
parents: 960
diff changeset
   506
                                master, 0, data.slave_position))) {
1aee4aa1def3 Implemented Sdo dictionary info via 'ethercat sdos'.
Florian Pose <fp@igh-essen.com>
parents: 960
diff changeset
   507
                    EC_ERR("Slave %u does not exist!\n", data.slave_position);
1aee4aa1def3 Implemented Sdo dictionary info via 'ethercat sdos'.
Florian Pose <fp@igh-essen.com>
parents: 960
diff changeset
   508
                    retval = -EINVAL;
1aee4aa1def3 Implemented Sdo dictionary info via 'ethercat sdos'.
Florian Pose <fp@igh-essen.com>
parents: 960
diff changeset
   509
                    break;
1aee4aa1def3 Implemented Sdo dictionary info via 'ethercat sdos'.
Florian Pose <fp@igh-essen.com>
parents: 960
diff changeset
   510
                }
1aee4aa1def3 Implemented Sdo dictionary info via 'ethercat sdos'.
Florian Pose <fp@igh-essen.com>
parents: 960
diff changeset
   511
1aee4aa1def3 Implemented Sdo dictionary info via 'ethercat sdos'.
Florian Pose <fp@igh-essen.com>
parents: 960
diff changeset
   512
                if (!(sdo = ec_slave_get_sdo_by_pos_const(
1aee4aa1def3 Implemented Sdo dictionary info via 'ethercat sdos'.
Florian Pose <fp@igh-essen.com>
parents: 960
diff changeset
   513
                                slave, data.sdo_position))) {
1aee4aa1def3 Implemented Sdo dictionary info via 'ethercat sdos'.
Florian Pose <fp@igh-essen.com>
parents: 960
diff changeset
   514
                    EC_ERR("Sdo %u does not exist in slave %u!\n",
1aee4aa1def3 Implemented Sdo dictionary info via 'ethercat sdos'.
Florian Pose <fp@igh-essen.com>
parents: 960
diff changeset
   515
                            data.sdo_position, data.slave_position);
1aee4aa1def3 Implemented Sdo dictionary info via 'ethercat sdos'.
Florian Pose <fp@igh-essen.com>
parents: 960
diff changeset
   516
                    retval = -EINVAL;
1aee4aa1def3 Implemented Sdo dictionary info via 'ethercat sdos'.
Florian Pose <fp@igh-essen.com>
parents: 960
diff changeset
   517
                    break;
1aee4aa1def3 Implemented Sdo dictionary info via 'ethercat sdos'.
Florian Pose <fp@igh-essen.com>
parents: 960
diff changeset
   518
                }
1aee4aa1def3 Implemented Sdo dictionary info via 'ethercat sdos'.
Florian Pose <fp@igh-essen.com>
parents: 960
diff changeset
   519
1aee4aa1def3 Implemented Sdo dictionary info via 'ethercat sdos'.
Florian Pose <fp@igh-essen.com>
parents: 960
diff changeset
   520
                data.sdo_index = sdo->index;
1aee4aa1def3 Implemented Sdo dictionary info via 'ethercat sdos'.
Florian Pose <fp@igh-essen.com>
parents: 960
diff changeset
   521
                data.max_subindex = sdo->max_subindex;
1aee4aa1def3 Implemented Sdo dictionary info via 'ethercat sdos'.
Florian Pose <fp@igh-essen.com>
parents: 960
diff changeset
   522
1aee4aa1def3 Implemented Sdo dictionary info via 'ethercat sdos'.
Florian Pose <fp@igh-essen.com>
parents: 960
diff changeset
   523
                if (sdo->name) {
990
4f223f3df05a Bus configuration via 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 989
diff changeset
   524
                    strncpy(data.name, sdo->name, EC_IOCTL_STRING_SIZE);
4f223f3df05a Bus configuration via 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 989
diff changeset
   525
                    data.name[EC_IOCTL_STRING_SIZE - 1] = 0;
965
1aee4aa1def3 Implemented Sdo dictionary info via 'ethercat sdos'.
Florian Pose <fp@igh-essen.com>
parents: 960
diff changeset
   526
                } else {
1aee4aa1def3 Implemented Sdo dictionary info via 'ethercat sdos'.
Florian Pose <fp@igh-essen.com>
parents: 960
diff changeset
   527
                    data.name[0] = 0;
1aee4aa1def3 Implemented Sdo dictionary info via 'ethercat sdos'.
Florian Pose <fp@igh-essen.com>
parents: 960
diff changeset
   528
                }
1aee4aa1def3 Implemented Sdo dictionary info via 'ethercat sdos'.
Florian Pose <fp@igh-essen.com>
parents: 960
diff changeset
   529
999
14307580deb6 Removed unnecessary code.
Florian Pose <fp@igh-essen.com>
parents: 990
diff changeset
   530
                if (copy_to_user((void __user *) arg, &data, sizeof(data)))
14307580deb6 Removed unnecessary code.
Florian Pose <fp@igh-essen.com>
parents: 990
diff changeset
   531
                    retval = -EFAULT;
965
1aee4aa1def3 Implemented Sdo dictionary info via 'ethercat sdos'.
Florian Pose <fp@igh-essen.com>
parents: 960
diff changeset
   532
                break;
1aee4aa1def3 Implemented Sdo dictionary info via 'ethercat sdos'.
Florian Pose <fp@igh-essen.com>
parents: 960
diff changeset
   533
            }
1aee4aa1def3 Implemented Sdo dictionary info via 'ethercat sdos'.
Florian Pose <fp@igh-essen.com>
parents: 960
diff changeset
   534
1aee4aa1def3 Implemented Sdo dictionary info via 'ethercat sdos'.
Florian Pose <fp@igh-essen.com>
parents: 960
diff changeset
   535
        case EC_IOCTL_SDO_ENTRY:
1aee4aa1def3 Implemented Sdo dictionary info via 'ethercat sdos'.
Florian Pose <fp@igh-essen.com>
parents: 960
diff changeset
   536
            {
1aee4aa1def3 Implemented Sdo dictionary info via 'ethercat sdos'.
Florian Pose <fp@igh-essen.com>
parents: 960
diff changeset
   537
                ec_ioctl_sdo_entry_t data;
1aee4aa1def3 Implemented Sdo dictionary info via 'ethercat sdos'.
Florian Pose <fp@igh-essen.com>
parents: 960
diff changeset
   538
                const ec_slave_t *slave;
1aee4aa1def3 Implemented Sdo dictionary info via 'ethercat sdos'.
Florian Pose <fp@igh-essen.com>
parents: 960
diff changeset
   539
                const ec_sdo_t *sdo;
1aee4aa1def3 Implemented Sdo dictionary info via 'ethercat sdos'.
Florian Pose <fp@igh-essen.com>
parents: 960
diff changeset
   540
                const ec_sdo_entry_t *entry;
1aee4aa1def3 Implemented Sdo dictionary info via 'ethercat sdos'.
Florian Pose <fp@igh-essen.com>
parents: 960
diff changeset
   541
1aee4aa1def3 Implemented Sdo dictionary info via 'ethercat sdos'.
Florian Pose <fp@igh-essen.com>
parents: 960
diff changeset
   542
                if (copy_from_user(&data, (void __user *) arg, sizeof(data))) {
1aee4aa1def3 Implemented Sdo dictionary info via 'ethercat sdos'.
Florian Pose <fp@igh-essen.com>
parents: 960
diff changeset
   543
                    retval = -EFAULT;
1aee4aa1def3 Implemented Sdo dictionary info via 'ethercat sdos'.
Florian Pose <fp@igh-essen.com>
parents: 960
diff changeset
   544
                    break;
1aee4aa1def3 Implemented Sdo dictionary info via 'ethercat sdos'.
Florian Pose <fp@igh-essen.com>
parents: 960
diff changeset
   545
                }
1aee4aa1def3 Implemented Sdo dictionary info via 'ethercat sdos'.
Florian Pose <fp@igh-essen.com>
parents: 960
diff changeset
   546
                
1aee4aa1def3 Implemented Sdo dictionary info via 'ethercat sdos'.
Florian Pose <fp@igh-essen.com>
parents: 960
diff changeset
   547
                if (!(slave = ec_master_find_slave(
1aee4aa1def3 Implemented Sdo dictionary info via 'ethercat sdos'.
Florian Pose <fp@igh-essen.com>
parents: 960
diff changeset
   548
                                master, 0, data.slave_position))) {
1aee4aa1def3 Implemented Sdo dictionary info via 'ethercat sdos'.
Florian Pose <fp@igh-essen.com>
parents: 960
diff changeset
   549
                    EC_ERR("Slave %u does not exist!\n", data.slave_position);
1aee4aa1def3 Implemented Sdo dictionary info via 'ethercat sdos'.
Florian Pose <fp@igh-essen.com>
parents: 960
diff changeset
   550
                    retval = -EINVAL;
1aee4aa1def3 Implemented Sdo dictionary info via 'ethercat sdos'.
Florian Pose <fp@igh-essen.com>
parents: 960
diff changeset
   551
                    break;
1aee4aa1def3 Implemented Sdo dictionary info via 'ethercat sdos'.
Florian Pose <fp@igh-essen.com>
parents: 960
diff changeset
   552
                }
1aee4aa1def3 Implemented Sdo dictionary info via 'ethercat sdos'.
Florian Pose <fp@igh-essen.com>
parents: 960
diff changeset
   553
968
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 965
diff changeset
   554
                if (data.sdo_spec <= 0) {
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 965
diff changeset
   555
                    if (!(sdo = ec_slave_get_sdo_by_pos_const(
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 965
diff changeset
   556
                                    slave, -data.sdo_spec))) {
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 965
diff changeset
   557
                        EC_ERR("Sdo %u does not exist in slave %u!\n",
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 965
diff changeset
   558
                                -data.sdo_spec, data.slave_position);
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 965
diff changeset
   559
                        retval = -EINVAL;
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 965
diff changeset
   560
                        break;
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 965
diff changeset
   561
                    }
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 965
diff changeset
   562
                } else {
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 965
diff changeset
   563
                    if (!(sdo = ec_slave_get_sdo_const(
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 965
diff changeset
   564
                                    slave, data.sdo_spec))) {
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 965
diff changeset
   565
                        EC_ERR("Sdo 0x%04X does not exist in slave %u!\n",
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 965
diff changeset
   566
                                data.sdo_spec, data.slave_position);
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 965
diff changeset
   567
                        retval = -EINVAL;
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 965
diff changeset
   568
                        break;
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 965
diff changeset
   569
                    }
965
1aee4aa1def3 Implemented Sdo dictionary info via 'ethercat sdos'.
Florian Pose <fp@igh-essen.com>
parents: 960
diff changeset
   570
                }
1aee4aa1def3 Implemented Sdo dictionary info via 'ethercat sdos'.
Florian Pose <fp@igh-essen.com>
parents: 960
diff changeset
   571
1aee4aa1def3 Implemented Sdo dictionary info via 'ethercat sdos'.
Florian Pose <fp@igh-essen.com>
parents: 960
diff changeset
   572
                if (!(entry = ec_sdo_get_entry_const(
1aee4aa1def3 Implemented Sdo dictionary info via 'ethercat sdos'.
Florian Pose <fp@igh-essen.com>
parents: 960
diff changeset
   573
                                sdo, data.sdo_entry_subindex))) {
968
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 965
diff changeset
   574
                    EC_ERR("Sdo entry 0x%04X:%02X does not exist "
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 965
diff changeset
   575
                            "in slave %u!\n", sdo->index,
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 965
diff changeset
   576
                            data.sdo_entry_subindex, data.slave_position);
965
1aee4aa1def3 Implemented Sdo dictionary info via 'ethercat sdos'.
Florian Pose <fp@igh-essen.com>
parents: 960
diff changeset
   577
                    retval = -EINVAL;
1aee4aa1def3 Implemented Sdo dictionary info via 'ethercat sdos'.
Florian Pose <fp@igh-essen.com>
parents: 960
diff changeset
   578
                    break;
1aee4aa1def3 Implemented Sdo dictionary info via 'ethercat sdos'.
Florian Pose <fp@igh-essen.com>
parents: 960
diff changeset
   579
                }
1aee4aa1def3 Implemented Sdo dictionary info via 'ethercat sdos'.
Florian Pose <fp@igh-essen.com>
parents: 960
diff changeset
   580
1aee4aa1def3 Implemented Sdo dictionary info via 'ethercat sdos'.
Florian Pose <fp@igh-essen.com>
parents: 960
diff changeset
   581
                data.data_type = entry->data_type;
1aee4aa1def3 Implemented Sdo dictionary info via 'ethercat sdos'.
Florian Pose <fp@igh-essen.com>
parents: 960
diff changeset
   582
                data.bit_length = entry->bit_length;
1aee4aa1def3 Implemented Sdo dictionary info via 'ethercat sdos'.
Florian Pose <fp@igh-essen.com>
parents: 960
diff changeset
   583
1aee4aa1def3 Implemented Sdo dictionary info via 'ethercat sdos'.
Florian Pose <fp@igh-essen.com>
parents: 960
diff changeset
   584
                if (entry->description) {
1aee4aa1def3 Implemented Sdo dictionary info via 'ethercat sdos'.
Florian Pose <fp@igh-essen.com>
parents: 960
diff changeset
   585
                    strncpy(data.description, entry->description,
990
4f223f3df05a Bus configuration via 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 989
diff changeset
   586
                            EC_IOCTL_STRING_SIZE);
4f223f3df05a Bus configuration via 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 989
diff changeset
   587
                    data.description[EC_IOCTL_STRING_SIZE - 1]
965
1aee4aa1def3 Implemented Sdo dictionary info via 'ethercat sdos'.
Florian Pose <fp@igh-essen.com>
parents: 960
diff changeset
   588
                        = 0;
1aee4aa1def3 Implemented Sdo dictionary info via 'ethercat sdos'.
Florian Pose <fp@igh-essen.com>
parents: 960
diff changeset
   589
                } else {
1aee4aa1def3 Implemented Sdo dictionary info via 'ethercat sdos'.
Florian Pose <fp@igh-essen.com>
parents: 960
diff changeset
   590
                    data.description[0] = 0;
1aee4aa1def3 Implemented Sdo dictionary info via 'ethercat sdos'.
Florian Pose <fp@igh-essen.com>
parents: 960
diff changeset
   591
                }
1aee4aa1def3 Implemented Sdo dictionary info via 'ethercat sdos'.
Florian Pose <fp@igh-essen.com>
parents: 960
diff changeset
   592
999
14307580deb6 Removed unnecessary code.
Florian Pose <fp@igh-essen.com>
parents: 990
diff changeset
   593
                if (copy_to_user((void __user *) arg, &data, sizeof(data)))
14307580deb6 Removed unnecessary code.
Florian Pose <fp@igh-essen.com>
parents: 990
diff changeset
   594
                    retval = -EFAULT;
965
1aee4aa1def3 Implemented Sdo dictionary info via 'ethercat sdos'.
Florian Pose <fp@igh-essen.com>
parents: 960
diff changeset
   595
                break;
1aee4aa1def3 Implemented Sdo dictionary info via 'ethercat sdos'.
Florian Pose <fp@igh-essen.com>
parents: 960
diff changeset
   596
            }
1aee4aa1def3 Implemented Sdo dictionary info via 'ethercat sdos'.
Florian Pose <fp@igh-essen.com>
parents: 960
diff changeset
   597
968
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 965
diff changeset
   598
        case EC_IOCTL_SDO_UPLOAD:
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 965
diff changeset
   599
            {
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 965
diff changeset
   600
                ec_ioctl_sdo_upload_t data;
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 965
diff changeset
   601
                ec_master_sdo_request_t request;
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 965
diff changeset
   602
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 965
diff changeset
   603
                if (copy_from_user(&data, (void __user *) arg, sizeof(data))) {
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 965
diff changeset
   604
                    retval = -EFAULT;
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 965
diff changeset
   605
                    break;
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 965
diff changeset
   606
                }
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 965
diff changeset
   607
                
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 965
diff changeset
   608
                if (!(request.slave = ec_master_find_slave(
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 965
diff changeset
   609
                                master, 0, data.slave_position))) {
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 965
diff changeset
   610
                    EC_ERR("Slave %u does not exist!\n", data.slave_position);
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 965
diff changeset
   611
                    retval = -EINVAL;
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 965
diff changeset
   612
                    break;
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 965
diff changeset
   613
                }
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 965
diff changeset
   614
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 965
diff changeset
   615
                ec_sdo_request_init(&request.req);
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 965
diff changeset
   616
                ec_sdo_request_address(&request.req,
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 965
diff changeset
   617
                        data.sdo_index, data.sdo_entry_subindex);
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 965
diff changeset
   618
                ecrt_sdo_request_read(&request.req);
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 965
diff changeset
   619
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 965
diff changeset
   620
                // schedule request.
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 965
diff changeset
   621
                down(&master->sdo_sem);
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 965
diff changeset
   622
                list_add_tail(&request.list, &master->slave_sdo_requests);
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 965
diff changeset
   623
                up(&master->sdo_sem);
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 965
diff changeset
   624
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 965
diff changeset
   625
                // wait for processing through FSM
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 965
diff changeset
   626
                if (wait_event_interruptible(master->sdo_queue,
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 965
diff changeset
   627
                            request.req.state != EC_REQUEST_QUEUED)) {
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 965
diff changeset
   628
                    // interrupted by signal
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 965
diff changeset
   629
                    down(&master->sdo_sem);
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 965
diff changeset
   630
                    if (request.req.state == EC_REQUEST_QUEUED) {
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 965
diff changeset
   631
                        list_del(&request.req.list);
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 965
diff changeset
   632
                        up(&master->sdo_sem);
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 965
diff changeset
   633
                        retval = -EINTR;
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 965
diff changeset
   634
                        break;
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 965
diff changeset
   635
                    }
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 965
diff changeset
   636
                    // request already processing: interrupt not possible.
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 965
diff changeset
   637
                    up(&master->sdo_sem);
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 965
diff changeset
   638
                }
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 965
diff changeset
   639
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 965
diff changeset
   640
                // wait until master FSM has finished processing
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 965
diff changeset
   641
                wait_event(master->sdo_queue, request.req.state != EC_REQUEST_BUSY);
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 965
diff changeset
   642
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 965
diff changeset
   643
                if (request.req.state != EC_REQUEST_SUCCESS) {
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 965
diff changeset
   644
                    retval = -EIO;
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 965
diff changeset
   645
                    break;
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 965
diff changeset
   646
                }
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 965
diff changeset
   647
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 965
diff changeset
   648
                if (request.req.data_size > data.target_size) {
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 965
diff changeset
   649
                    EC_ERR("Buffer too small.\n");
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 965
diff changeset
   650
                    retval = -EOVERFLOW;
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 965
diff changeset
   651
                    break;
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 965
diff changeset
   652
                }
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 965
diff changeset
   653
                data.data_size = request.req.data_size;
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 965
diff changeset
   654
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 965
diff changeset
   655
                if (copy_to_user((void __user *) data.target,
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 965
diff changeset
   656
                            request.req.data, data.data_size)) {
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 965
diff changeset
   657
                    retval = -EFAULT;
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 965
diff changeset
   658
                    break;
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 965
diff changeset
   659
                }
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 965
diff changeset
   660
                if (__copy_to_user((void __user *) arg, &data, sizeof(data))) {
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 965
diff changeset
   661
                    retval = -EFAULT;
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 965
diff changeset
   662
                    break;
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 965
diff changeset
   663
                }
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 965
diff changeset
   664
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 965
diff changeset
   665
                ec_sdo_request_clear(&request.req);
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 965
diff changeset
   666
                break;
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 965
diff changeset
   667
            }
b0e894257743 Implemented sdo_upload command.
Florian Pose <fp@igh-essen.com>
parents: 965
diff changeset
   668
974
5868944a6456 Implemented Sdo download via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 972
diff changeset
   669
        case EC_IOCTL_SDO_DOWNLOAD:
5868944a6456 Implemented Sdo download via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 972
diff changeset
   670
            {
5868944a6456 Implemented Sdo download via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 972
diff changeset
   671
                ec_ioctl_sdo_download_t data;
5868944a6456 Implemented Sdo download via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 972
diff changeset
   672
                ec_master_sdo_request_t request;
5868944a6456 Implemented Sdo download via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 972
diff changeset
   673
5868944a6456 Implemented Sdo download via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 972
diff changeset
   674
                if (!(filp->f_mode & FMODE_WRITE))
5868944a6456 Implemented Sdo download via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 972
diff changeset
   675
                    return -EPERM;
5868944a6456 Implemented Sdo download via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 972
diff changeset
   676
5868944a6456 Implemented Sdo download via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 972
diff changeset
   677
                if (copy_from_user(&data, (void __user *) arg, sizeof(data))) {
5868944a6456 Implemented Sdo download via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 972
diff changeset
   678
                    retval = -EFAULT;
5868944a6456 Implemented Sdo download via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 972
diff changeset
   679
                    break;
5868944a6456 Implemented Sdo download via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 972
diff changeset
   680
                }
5868944a6456 Implemented Sdo download via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 972
diff changeset
   681
                
5868944a6456 Implemented Sdo download via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 972
diff changeset
   682
                if (!(request.slave = ec_master_find_slave(
5868944a6456 Implemented Sdo download via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 972
diff changeset
   683
                                master, 0, data.slave_position))) {
5868944a6456 Implemented Sdo download via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 972
diff changeset
   684
                    EC_ERR("Slave %u does not exist!\n", data.slave_position);
5868944a6456 Implemented Sdo download via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 972
diff changeset
   685
                    retval = -EINVAL;
5868944a6456 Implemented Sdo download via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 972
diff changeset
   686
                    break;
5868944a6456 Implemented Sdo download via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 972
diff changeset
   687
                }
5868944a6456 Implemented Sdo download via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 972
diff changeset
   688
5868944a6456 Implemented Sdo download via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 972
diff changeset
   689
                // copy data to download
5868944a6456 Implemented Sdo download via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 972
diff changeset
   690
                if (!data.data_size) {
5868944a6456 Implemented Sdo download via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 972
diff changeset
   691
                    EC_ERR("Zero data size!\n");
5868944a6456 Implemented Sdo download via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 972
diff changeset
   692
                    retval = -EINVAL;
5868944a6456 Implemented Sdo download via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 972
diff changeset
   693
                    break;
5868944a6456 Implemented Sdo download via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 972
diff changeset
   694
                }
5868944a6456 Implemented Sdo download via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 972
diff changeset
   695
5868944a6456 Implemented Sdo download via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 972
diff changeset
   696
                ec_sdo_request_init(&request.req);
5868944a6456 Implemented Sdo download via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 972
diff changeset
   697
                ec_sdo_request_address(&request.req,
5868944a6456 Implemented Sdo download via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 972
diff changeset
   698
                        data.sdo_index, data.sdo_entry_subindex);
5868944a6456 Implemented Sdo download via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 972
diff changeset
   699
                if (ec_sdo_request_alloc(&request.req, data.data_size)) {
5868944a6456 Implemented Sdo download via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 972
diff changeset
   700
                    ec_sdo_request_clear(&request.req);
5868944a6456 Implemented Sdo download via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 972
diff changeset
   701
                    retval = -ENOMEM;
5868944a6456 Implemented Sdo download via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 972
diff changeset
   702
                    break;
5868944a6456 Implemented Sdo download via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 972
diff changeset
   703
                }
5868944a6456 Implemented Sdo download via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 972
diff changeset
   704
                if (copy_from_user(request.req.data,
5868944a6456 Implemented Sdo download via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 972
diff changeset
   705
                            (void __user *) data.data, data.data_size)) {
5868944a6456 Implemented Sdo download via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 972
diff changeset
   706
                    ec_sdo_request_clear(&request.req);
5868944a6456 Implemented Sdo download via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 972
diff changeset
   707
                    retval = -EFAULT;
5868944a6456 Implemented Sdo download via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 972
diff changeset
   708
                    break;
5868944a6456 Implemented Sdo download via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 972
diff changeset
   709
                }
5868944a6456 Implemented Sdo download via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 972
diff changeset
   710
                request.req.data_size = data.data_size;
5868944a6456 Implemented Sdo download via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 972
diff changeset
   711
                ecrt_sdo_request_write(&request.req);
5868944a6456 Implemented Sdo download via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 972
diff changeset
   712
5868944a6456 Implemented Sdo download via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 972
diff changeset
   713
                // schedule request.
5868944a6456 Implemented Sdo download via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 972
diff changeset
   714
                down(&master->sdo_sem);
5868944a6456 Implemented Sdo download via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 972
diff changeset
   715
                list_add_tail(&request.list, &master->slave_sdo_requests);
5868944a6456 Implemented Sdo download via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 972
diff changeset
   716
                up(&master->sdo_sem);
5868944a6456 Implemented Sdo download via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 972
diff changeset
   717
5868944a6456 Implemented Sdo download via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 972
diff changeset
   718
                // wait for processing through FSM
5868944a6456 Implemented Sdo download via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 972
diff changeset
   719
                if (wait_event_interruptible(master->sdo_queue,
5868944a6456 Implemented Sdo download via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 972
diff changeset
   720
                            request.req.state != EC_REQUEST_QUEUED)) {
5868944a6456 Implemented Sdo download via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 972
diff changeset
   721
                    // interrupted by signal
5868944a6456 Implemented Sdo download via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 972
diff changeset
   722
                    down(&master->sdo_sem);
5868944a6456 Implemented Sdo download via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 972
diff changeset
   723
                    if (request.req.state == EC_REQUEST_QUEUED) {
5868944a6456 Implemented Sdo download via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 972
diff changeset
   724
                        list_del(&request.req.list);
5868944a6456 Implemented Sdo download via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 972
diff changeset
   725
                        up(&master->sdo_sem);
5868944a6456 Implemented Sdo download via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 972
diff changeset
   726
                        retval = -EINTR;
5868944a6456 Implemented Sdo download via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 972
diff changeset
   727
                        break;
5868944a6456 Implemented Sdo download via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 972
diff changeset
   728
                    }
5868944a6456 Implemented Sdo download via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 972
diff changeset
   729
                    // request already processing: interrupt not possible.
5868944a6456 Implemented Sdo download via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 972
diff changeset
   730
                    up(&master->sdo_sem);
5868944a6456 Implemented Sdo download via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 972
diff changeset
   731
                }
5868944a6456 Implemented Sdo download via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 972
diff changeset
   732
5868944a6456 Implemented Sdo download via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 972
diff changeset
   733
                // wait until master FSM has finished processing
5868944a6456 Implemented Sdo download via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 972
diff changeset
   734
                wait_event(master->sdo_queue, request.req.state != EC_REQUEST_BUSY);
5868944a6456 Implemented Sdo download via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 972
diff changeset
   735
5868944a6456 Implemented Sdo download via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 972
diff changeset
   736
                if (request.req.state != EC_REQUEST_SUCCESS) {
5868944a6456 Implemented Sdo download via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 972
diff changeset
   737
                    retval = -EIO;
5868944a6456 Implemented Sdo download via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 972
diff changeset
   738
                    break;
5868944a6456 Implemented Sdo download via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 972
diff changeset
   739
                }
5868944a6456 Implemented Sdo download via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 972
diff changeset
   740
5868944a6456 Implemented Sdo download via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 972
diff changeset
   741
                ec_sdo_request_clear(&request.req);
5868944a6456 Implemented Sdo download via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 972
diff changeset
   742
                break;
5868944a6456 Implemented Sdo download via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 972
diff changeset
   743
            }
5868944a6456 Implemented Sdo download via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 972
diff changeset
   744
978
2962baf7e6d1 Implemented SII read.
Florian Pose <fp@igh-essen.com>
parents: 974
diff changeset
   745
        case EC_IOCTL_SII_READ:
2962baf7e6d1 Implemented SII read.
Florian Pose <fp@igh-essen.com>
parents: 974
diff changeset
   746
            {
980
c07dd38243ba Implemented SII writing (including alias writing) via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 978
diff changeset
   747
                ec_ioctl_sii_t data;
978
2962baf7e6d1 Implemented SII read.
Florian Pose <fp@igh-essen.com>
parents: 974
diff changeset
   748
                const ec_slave_t *slave;
2962baf7e6d1 Implemented SII read.
Florian Pose <fp@igh-essen.com>
parents: 974
diff changeset
   749
2962baf7e6d1 Implemented SII read.
Florian Pose <fp@igh-essen.com>
parents: 974
diff changeset
   750
                if (copy_from_user(&data, (void __user *) arg, sizeof(data))) {
2962baf7e6d1 Implemented SII read.
Florian Pose <fp@igh-essen.com>
parents: 974
diff changeset
   751
                    retval = -EFAULT;
2962baf7e6d1 Implemented SII read.
Florian Pose <fp@igh-essen.com>
parents: 974
diff changeset
   752
                    break;
2962baf7e6d1 Implemented SII read.
Florian Pose <fp@igh-essen.com>
parents: 974
diff changeset
   753
                }
2962baf7e6d1 Implemented SII read.
Florian Pose <fp@igh-essen.com>
parents: 974
diff changeset
   754
                
2962baf7e6d1 Implemented SII read.
Florian Pose <fp@igh-essen.com>
parents: 974
diff changeset
   755
                if (!(slave = ec_master_find_slave(
2962baf7e6d1 Implemented SII read.
Florian Pose <fp@igh-essen.com>
parents: 974
diff changeset
   756
                                master, 0, data.slave_position))) {
2962baf7e6d1 Implemented SII read.
Florian Pose <fp@igh-essen.com>
parents: 974
diff changeset
   757
                    EC_ERR("Slave %u does not exist!\n", data.slave_position);
2962baf7e6d1 Implemented SII read.
Florian Pose <fp@igh-essen.com>
parents: 974
diff changeset
   758
                    retval = -EINVAL;
2962baf7e6d1 Implemented SII read.
Florian Pose <fp@igh-essen.com>
parents: 974
diff changeset
   759
                    break;
2962baf7e6d1 Implemented SII read.
Florian Pose <fp@igh-essen.com>
parents: 974
diff changeset
   760
                }
2962baf7e6d1 Implemented SII read.
Florian Pose <fp@igh-essen.com>
parents: 974
diff changeset
   761
2962baf7e6d1 Implemented SII read.
Florian Pose <fp@igh-essen.com>
parents: 974
diff changeset
   762
                if (!data.nwords
2962baf7e6d1 Implemented SII read.
Florian Pose <fp@igh-essen.com>
parents: 974
diff changeset
   763
                        || data.offset + data.nwords > slave->sii_nwords) {
2962baf7e6d1 Implemented SII read.
Florian Pose <fp@igh-essen.com>
parents: 974
diff changeset
   764
                    EC_ERR("Invalid SII read offset/size %u/%u for slave "
2962baf7e6d1 Implemented SII read.
Florian Pose <fp@igh-essen.com>
parents: 974
diff changeset
   765
                            "SII size %u!\n", data.offset,
2962baf7e6d1 Implemented SII read.
Florian Pose <fp@igh-essen.com>
parents: 974
diff changeset
   766
                            data.nwords, slave->sii_nwords);
2962baf7e6d1 Implemented SII read.
Florian Pose <fp@igh-essen.com>
parents: 974
diff changeset
   767
                    retval = -EINVAL;
2962baf7e6d1 Implemented SII read.
Florian Pose <fp@igh-essen.com>
parents: 974
diff changeset
   768
                    break;
2962baf7e6d1 Implemented SII read.
Florian Pose <fp@igh-essen.com>
parents: 974
diff changeset
   769
                }
2962baf7e6d1 Implemented SII read.
Florian Pose <fp@igh-essen.com>
parents: 974
diff changeset
   770
2962baf7e6d1 Implemented SII read.
Florian Pose <fp@igh-essen.com>
parents: 974
diff changeset
   771
                if (copy_to_user((void __user *) data.words,
999
14307580deb6 Removed unnecessary code.
Florian Pose <fp@igh-essen.com>
parents: 990
diff changeset
   772
                            slave->sii_words + data.offset, data.nwords * 2))
14307580deb6 Removed unnecessary code.
Florian Pose <fp@igh-essen.com>
parents: 990
diff changeset
   773
                    retval = -EFAULT;
978
2962baf7e6d1 Implemented SII read.
Florian Pose <fp@igh-essen.com>
parents: 974
diff changeset
   774
                break;
2962baf7e6d1 Implemented SII read.
Florian Pose <fp@igh-essen.com>
parents: 974
diff changeset
   775
            }
2962baf7e6d1 Implemented SII read.
Florian Pose <fp@igh-essen.com>
parents: 974
diff changeset
   776
980
c07dd38243ba Implemented SII writing (including alias writing) via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 978
diff changeset
   777
        case EC_IOCTL_SII_WRITE:
c07dd38243ba Implemented SII writing (including alias writing) via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 978
diff changeset
   778
            {
c07dd38243ba Implemented SII writing (including alias writing) via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 978
diff changeset
   779
                ec_ioctl_sii_t data;
c07dd38243ba Implemented SII writing (including alias writing) via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 978
diff changeset
   780
                ec_slave_t *slave;
c07dd38243ba Implemented SII writing (including alias writing) via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 978
diff changeset
   781
                unsigned int byte_size;
c07dd38243ba Implemented SII writing (including alias writing) via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 978
diff changeset
   782
                uint16_t *words;
c07dd38243ba Implemented SII writing (including alias writing) via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 978
diff changeset
   783
c07dd38243ba Implemented SII writing (including alias writing) via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 978
diff changeset
   784
                if (copy_from_user(&data, (void __user *) arg, sizeof(data))) {
c07dd38243ba Implemented SII writing (including alias writing) via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 978
diff changeset
   785
                    retval = -EFAULT;
c07dd38243ba Implemented SII writing (including alias writing) via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 978
diff changeset
   786
                    break;
c07dd38243ba Implemented SII writing (including alias writing) via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 978
diff changeset
   787
                }
c07dd38243ba Implemented SII writing (including alias writing) via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 978
diff changeset
   788
                
c07dd38243ba Implemented SII writing (including alias writing) via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 978
diff changeset
   789
                if (!(slave = ec_master_find_slave(
c07dd38243ba Implemented SII writing (including alias writing) via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 978
diff changeset
   790
                                master, 0, data.slave_position))) {
c07dd38243ba Implemented SII writing (including alias writing) via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 978
diff changeset
   791
                    EC_ERR("Slave %u does not exist!\n", data.slave_position);
c07dd38243ba Implemented SII writing (including alias writing) via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 978
diff changeset
   792
                    retval = -EINVAL;
c07dd38243ba Implemented SII writing (including alias writing) via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 978
diff changeset
   793
                    break;
c07dd38243ba Implemented SII writing (including alias writing) via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 978
diff changeset
   794
                }
c07dd38243ba Implemented SII writing (including alias writing) via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 978
diff changeset
   795
c07dd38243ba Implemented SII writing (including alias writing) via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 978
diff changeset
   796
                if (!data.nwords)
c07dd38243ba Implemented SII writing (including alias writing) via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 978
diff changeset
   797
                    break;
c07dd38243ba Implemented SII writing (including alias writing) via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 978
diff changeset
   798
c07dd38243ba Implemented SII writing (including alias writing) via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 978
diff changeset
   799
                byte_size = sizeof(uint16_t) * data.nwords;
c07dd38243ba Implemented SII writing (including alias writing) via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 978
diff changeset
   800
                if (!(words = kmalloc(byte_size, GFP_KERNEL))) {
c07dd38243ba Implemented SII writing (including alias writing) via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 978
diff changeset
   801
                    EC_ERR("Failed to allocate %u bytes for SII contents.\n",
c07dd38243ba Implemented SII writing (including alias writing) via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 978
diff changeset
   802
                            byte_size);
c07dd38243ba Implemented SII writing (including alias writing) via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 978
diff changeset
   803
                    retval = -ENOMEM;
c07dd38243ba Implemented SII writing (including alias writing) via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 978
diff changeset
   804
                    break;
c07dd38243ba Implemented SII writing (including alias writing) via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 978
diff changeset
   805
                }
c07dd38243ba Implemented SII writing (including alias writing) via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 978
diff changeset
   806
c07dd38243ba Implemented SII writing (including alias writing) via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 978
diff changeset
   807
                if (copy_from_user(words,
c07dd38243ba Implemented SII writing (including alias writing) via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 978
diff changeset
   808
                            (void __user *) data.words, byte_size)) {
c07dd38243ba Implemented SII writing (including alias writing) via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 978
diff changeset
   809
                    retval = -EFAULT;
c07dd38243ba Implemented SII writing (including alias writing) via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 978
diff changeset
   810
                    kfree(words);
c07dd38243ba Implemented SII writing (including alias writing) via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 978
diff changeset
   811
                    break;
c07dd38243ba Implemented SII writing (including alias writing) via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 978
diff changeset
   812
                }
c07dd38243ba Implemented SII writing (including alias writing) via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 978
diff changeset
   813
c07dd38243ba Implemented SII writing (including alias writing) via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 978
diff changeset
   814
                if (ec_slave_write_sii(slave,
999
14307580deb6 Removed unnecessary code.
Florian Pose <fp@igh-essen.com>
parents: 990
diff changeset
   815
                            data.offset, data.nwords, words))
980
c07dd38243ba Implemented SII writing (including alias writing) via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 978
diff changeset
   816
                    retval = -EIO;
c07dd38243ba Implemented SII writing (including alias writing) via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 978
diff changeset
   817
c07dd38243ba Implemented SII writing (including alias writing) via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 978
diff changeset
   818
                kfree(words);
c07dd38243ba Implemented SII writing (including alias writing) via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 978
diff changeset
   819
                break;
c07dd38243ba Implemented SII writing (including alias writing) via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 978
diff changeset
   820
            }
c07dd38243ba Implemented SII writing (including alias writing) via ethercat command.
Florian Pose <fp@igh-essen.com>
parents: 978
diff changeset
   821
990
4f223f3df05a Bus configuration via 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 989
diff changeset
   822
        case EC_IOCTL_CONFIG:
4f223f3df05a Bus configuration via 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 989
diff changeset
   823
            {
4f223f3df05a Bus configuration via 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 989
diff changeset
   824
                ec_ioctl_config_t data;
4f223f3df05a Bus configuration via 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 989
diff changeset
   825
                const ec_slave_config_t *sc;
4f223f3df05a Bus configuration via 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 989
diff changeset
   826
4f223f3df05a Bus configuration via 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 989
diff changeset
   827
                if (copy_from_user(&data, (void __user *) arg, sizeof(data))) {
4f223f3df05a Bus configuration via 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 989
diff changeset
   828
                    retval = -EFAULT;
4f223f3df05a Bus configuration via 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 989
diff changeset
   829
                    break;
4f223f3df05a Bus configuration via 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 989
diff changeset
   830
                }
4f223f3df05a Bus configuration via 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 989
diff changeset
   831
                
4f223f3df05a Bus configuration via 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 989
diff changeset
   832
                if (!(sc = ec_master_get_config_const(
4f223f3df05a Bus configuration via 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 989
diff changeset
   833
                                master, data.config_index))) {
4f223f3df05a Bus configuration via 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 989
diff changeset
   834
                    EC_ERR("Slave config %u does not exist!\n",
4f223f3df05a Bus configuration via 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 989
diff changeset
   835
                            data.config_index);
4f223f3df05a Bus configuration via 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 989
diff changeset
   836
                    retval = -EINVAL;
4f223f3df05a Bus configuration via 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 989
diff changeset
   837
                    break;
4f223f3df05a Bus configuration via 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 989
diff changeset
   838
                }
4f223f3df05a Bus configuration via 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 989
diff changeset
   839
4f223f3df05a Bus configuration via 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 989
diff changeset
   840
                data.alias = sc->alias;
4f223f3df05a Bus configuration via 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 989
diff changeset
   841
                data.position = sc->position;
4f223f3df05a Bus configuration via 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 989
diff changeset
   842
                data.vendor_id = sc->vendor_id;
4f223f3df05a Bus configuration via 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 989
diff changeset
   843
                data.product_code = sc->product_code;
4f223f3df05a Bus configuration via 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 989
diff changeset
   844
                data.pdo_count[EC_DIR_OUTPUT] =
4f223f3df05a Bus configuration via 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 989
diff changeset
   845
                    ec_pdo_list_count(&sc->pdos[EC_DIR_OUTPUT]);
4f223f3df05a Bus configuration via 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 989
diff changeset
   846
                data.pdo_count[EC_DIR_INPUT] =
4f223f3df05a Bus configuration via 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 989
diff changeset
   847
                    ec_pdo_list_count(&sc->pdos[EC_DIR_INPUT]);
4f223f3df05a Bus configuration via 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 989
diff changeset
   848
                data.sdo_count = ec_slave_config_sdo_count(sc);
4f223f3df05a Bus configuration via 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 989
diff changeset
   849
                data.attached = sc->slave != NULL;
4f223f3df05a Bus configuration via 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 989
diff changeset
   850
999
14307580deb6 Removed unnecessary code.
Florian Pose <fp@igh-essen.com>
parents: 990
diff changeset
   851
                if (copy_to_user((void __user *) arg, &data, sizeof(data)))
14307580deb6 Removed unnecessary code.
Florian Pose <fp@igh-essen.com>
parents: 990
diff changeset
   852
                    retval = -EFAULT;
990
4f223f3df05a Bus configuration via 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 989
diff changeset
   853
                break;
4f223f3df05a Bus configuration via 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 989
diff changeset
   854
            }
4f223f3df05a Bus configuration via 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 989
diff changeset
   855
4f223f3df05a Bus configuration via 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 989
diff changeset
   856
        case EC_IOCTL_CONFIG_PDO:
4f223f3df05a Bus configuration via 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 989
diff changeset
   857
            {
4f223f3df05a Bus configuration via 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 989
diff changeset
   858
                ec_ioctl_config_pdo_t data;
4f223f3df05a Bus configuration via 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 989
diff changeset
   859
                const ec_slave_config_t *sc;
4f223f3df05a Bus configuration via 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 989
diff changeset
   860
                const ec_pdo_t *pdo;
4f223f3df05a Bus configuration via 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 989
diff changeset
   861
4f223f3df05a Bus configuration via 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 989
diff changeset
   862
                if (copy_from_user(&data, (void __user *) arg, sizeof(data))) {
4f223f3df05a Bus configuration via 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 989
diff changeset
   863
                    retval = -EFAULT;
4f223f3df05a Bus configuration via 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 989
diff changeset
   864
                    break;
4f223f3df05a Bus configuration via 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 989
diff changeset
   865
                }
4f223f3df05a Bus configuration via 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 989
diff changeset
   866
                
4f223f3df05a Bus configuration via 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 989
diff changeset
   867
                if (!(sc = ec_master_get_config_const(
4f223f3df05a Bus configuration via 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 989
diff changeset
   868
                                master, data.config_index))) {
4f223f3df05a Bus configuration via 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 989
diff changeset
   869
                    EC_ERR("Slave config %u does not exist!\n",
4f223f3df05a Bus configuration via 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 989
diff changeset
   870
                            data.config_index);
4f223f3df05a Bus configuration via 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 989
diff changeset
   871
                    retval = -EINVAL;
4f223f3df05a Bus configuration via 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 989
diff changeset
   872
                    break;
4f223f3df05a Bus configuration via 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 989
diff changeset
   873
                }
4f223f3df05a Bus configuration via 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 989
diff changeset
   874
4f223f3df05a Bus configuration via 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 989
diff changeset
   875
                if (data.direction > EC_DIR_INPUT) {
4f223f3df05a Bus configuration via 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 989
diff changeset
   876
                    EC_ERR("Invalid direction %u!\n", data.direction);
4f223f3df05a Bus configuration via 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 989
diff changeset
   877
                    retval = -EINVAL;
4f223f3df05a Bus configuration via 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 989
diff changeset
   878
                    break;
4f223f3df05a Bus configuration via 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 989
diff changeset
   879
                }
4f223f3df05a Bus configuration via 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 989
diff changeset
   880
                
4f223f3df05a Bus configuration via 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 989
diff changeset
   881
                if (!(pdo = ec_pdo_list_find_pdo_by_pos_const(
4f223f3df05a Bus configuration via 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 989
diff changeset
   882
                                &sc->pdos[data.direction], data.pdo_pos))) {
4f223f3df05a Bus configuration via 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 989
diff changeset
   883
                    EC_ERR("Invalid Pdo position!\n");
4f223f3df05a Bus configuration via 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 989
diff changeset
   884
                    retval = -EINVAL;
4f223f3df05a Bus configuration via 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 989
diff changeset
   885
                    break;
4f223f3df05a Bus configuration via 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 989
diff changeset
   886
                }
4f223f3df05a Bus configuration via 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 989
diff changeset
   887
4f223f3df05a Bus configuration via 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 989
diff changeset
   888
                data.index = pdo->index;
4f223f3df05a Bus configuration via 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 989
diff changeset
   889
                data.entry_count = ec_pdo_entry_count(pdo);
4f223f3df05a Bus configuration via 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 989
diff changeset
   890
4f223f3df05a Bus configuration via 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 989
diff changeset
   891
                if (pdo->name) {
4f223f3df05a Bus configuration via 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 989
diff changeset
   892
                    strncpy(data.name, pdo->name, EC_IOCTL_STRING_SIZE);
4f223f3df05a Bus configuration via 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 989
diff changeset
   893
                    data.name[EC_IOCTL_STRING_SIZE - 1] = 0;
4f223f3df05a Bus configuration via 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 989
diff changeset
   894
                } else {
4f223f3df05a Bus configuration via 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 989
diff changeset
   895
                    data.name[0] = 0;
4f223f3df05a Bus configuration via 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 989
diff changeset
   896
                }
4f223f3df05a Bus configuration via 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 989
diff changeset
   897
999
14307580deb6 Removed unnecessary code.
Florian Pose <fp@igh-essen.com>
parents: 990
diff changeset
   898
                if (copy_to_user((void __user *) arg, &data, sizeof(data)))
14307580deb6 Removed unnecessary code.
Florian Pose <fp@igh-essen.com>
parents: 990
diff changeset
   899
                    retval = -EFAULT;
990
4f223f3df05a Bus configuration via 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 989
diff changeset
   900
                break;
4f223f3df05a Bus configuration via 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 989
diff changeset
   901
            }
4f223f3df05a Bus configuration via 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 989
diff changeset
   902
4f223f3df05a Bus configuration via 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 989
diff changeset
   903
        case EC_IOCTL_CONFIG_PDO_ENTRY:
4f223f3df05a Bus configuration via 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 989
diff changeset
   904
            {
4f223f3df05a Bus configuration via 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 989
diff changeset
   905
                ec_ioctl_config_pdo_entry_t data;
4f223f3df05a Bus configuration via 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 989
diff changeset
   906
                const ec_slave_config_t *sc;
4f223f3df05a Bus configuration via 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 989
diff changeset
   907
                const ec_pdo_t *pdo;
4f223f3df05a Bus configuration via 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 989
diff changeset
   908
                const ec_pdo_entry_t *entry;
4f223f3df05a Bus configuration via 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 989
diff changeset
   909
4f223f3df05a Bus configuration via 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 989
diff changeset
   910
                if (copy_from_user(&data, (void __user *) arg, sizeof(data))) {
4f223f3df05a Bus configuration via 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 989
diff changeset
   911
                    retval = -EFAULT;
4f223f3df05a Bus configuration via 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 989
diff changeset
   912
                    break;
4f223f3df05a Bus configuration via 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 989
diff changeset
   913
                }
4f223f3df05a Bus configuration via 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 989
diff changeset
   914
                
4f223f3df05a Bus configuration via 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 989
diff changeset
   915
                if (!(sc = ec_master_get_config_const(
4f223f3df05a Bus configuration via 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 989
diff changeset
   916
                                master, data.config_index))) {
4f223f3df05a Bus configuration via 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 989
diff changeset
   917
                    EC_ERR("Slave config %u does not exist!\n",
4f223f3df05a Bus configuration via 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 989
diff changeset
   918
                            data.config_index);
4f223f3df05a Bus configuration via 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 989
diff changeset
   919
                    retval = -EINVAL;
4f223f3df05a Bus configuration via 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 989
diff changeset
   920
                    break;
4f223f3df05a Bus configuration via 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 989
diff changeset
   921
                }
4f223f3df05a Bus configuration via 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 989
diff changeset
   922
4f223f3df05a Bus configuration via 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 989
diff changeset
   923
                if (data.direction > EC_DIR_INPUT) {
4f223f3df05a Bus configuration via 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 989
diff changeset
   924
                    EC_ERR("Invalid direction %u!\n", data.direction);
4f223f3df05a Bus configuration via 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 989
diff changeset
   925
                    retval = -EINVAL;
4f223f3df05a Bus configuration via 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 989
diff changeset
   926
                    break;
4f223f3df05a Bus configuration via 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 989
diff changeset
   927
                }
4f223f3df05a Bus configuration via 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 989
diff changeset
   928
                
4f223f3df05a Bus configuration via 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 989
diff changeset
   929
                if (!(pdo = ec_pdo_list_find_pdo_by_pos_const(
4f223f3df05a Bus configuration via 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 989
diff changeset
   930
                                &sc->pdos[data.direction], data.pdo_pos))) {
4f223f3df05a Bus configuration via 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 989
diff changeset
   931
                    EC_ERR("Invalid Pdo position!\n");
4f223f3df05a Bus configuration via 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 989
diff changeset
   932
                    retval = -EINVAL;
4f223f3df05a Bus configuration via 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 989
diff changeset
   933
                    break;
4f223f3df05a Bus configuration via 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 989
diff changeset
   934
                }
4f223f3df05a Bus configuration via 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 989
diff changeset
   935
4f223f3df05a Bus configuration via 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 989
diff changeset
   936
                if (!(entry = ec_pdo_find_entry_by_pos_const(
4f223f3df05a Bus configuration via 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 989
diff changeset
   937
                                pdo, data.entry_pos))) {
4f223f3df05a Bus configuration via 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 989
diff changeset
   938
                    EC_ERR("Entry not found!\n");
4f223f3df05a Bus configuration via 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 989
diff changeset
   939
                    retval = -EINVAL;
4f223f3df05a Bus configuration via 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 989
diff changeset
   940
                    break;
4f223f3df05a Bus configuration via 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 989
diff changeset
   941
                }
4f223f3df05a Bus configuration via 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 989
diff changeset
   942
4f223f3df05a Bus configuration via 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 989
diff changeset
   943
                data.index = entry->index;
4f223f3df05a Bus configuration via 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 989
diff changeset
   944
                data.subindex = entry->subindex;
4f223f3df05a Bus configuration via 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 989
diff changeset
   945
                data.bit_length = entry->bit_length;
4f223f3df05a Bus configuration via 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 989
diff changeset
   946
                if (entry->name) {
4f223f3df05a Bus configuration via 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 989
diff changeset
   947
                    strncpy(data.name, entry->name, EC_IOCTL_STRING_SIZE);
4f223f3df05a Bus configuration via 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 989
diff changeset
   948
                    data.name[EC_IOCTL_STRING_SIZE - 1] = 0;
4f223f3df05a Bus configuration via 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 989
diff changeset
   949
                } else {
4f223f3df05a Bus configuration via 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 989
diff changeset
   950
                    data.name[0] = 0;
4f223f3df05a Bus configuration via 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 989
diff changeset
   951
                }
4f223f3df05a Bus configuration via 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 989
diff changeset
   952
999
14307580deb6 Removed unnecessary code.
Florian Pose <fp@igh-essen.com>
parents: 990
diff changeset
   953
                if (copy_to_user((void __user *) arg, &data, sizeof(data)))
14307580deb6 Removed unnecessary code.
Florian Pose <fp@igh-essen.com>
parents: 990
diff changeset
   954
                    retval = -EFAULT;
990
4f223f3df05a Bus configuration via 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 989
diff changeset
   955
                break;
4f223f3df05a Bus configuration via 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 989
diff changeset
   956
            }
4f223f3df05a Bus configuration via 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 989
diff changeset
   957
4f223f3df05a Bus configuration via 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 989
diff changeset
   958
        case EC_IOCTL_CONFIG_SDO:
4f223f3df05a Bus configuration via 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 989
diff changeset
   959
            {
4f223f3df05a Bus configuration via 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 989
diff changeset
   960
                ec_ioctl_config_sdo_t data;
4f223f3df05a Bus configuration via 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 989
diff changeset
   961
                const ec_slave_config_t *sc;
4f223f3df05a Bus configuration via 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 989
diff changeset
   962
                const ec_sdo_request_t *req;
4f223f3df05a Bus configuration via 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 989
diff changeset
   963
4f223f3df05a Bus configuration via 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 989
diff changeset
   964
                if (copy_from_user(&data, (void __user *) arg, sizeof(data))) {
4f223f3df05a Bus configuration via 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 989
diff changeset
   965
                    retval = -EFAULT;
4f223f3df05a Bus configuration via 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 989
diff changeset
   966
                    break;
4f223f3df05a Bus configuration via 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 989
diff changeset
   967
                }
4f223f3df05a Bus configuration via 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 989
diff changeset
   968
                
4f223f3df05a Bus configuration via 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 989
diff changeset
   969
                if (!(sc = ec_master_get_config_const(
4f223f3df05a Bus configuration via 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 989
diff changeset
   970
                                master, data.config_index))) {
4f223f3df05a Bus configuration via 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 989
diff changeset
   971
                    EC_ERR("Slave config %u does not exist!\n",
4f223f3df05a Bus configuration via 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 989
diff changeset
   972
                            data.config_index);
4f223f3df05a Bus configuration via 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 989
diff changeset
   973
                    retval = -EINVAL;
4f223f3df05a Bus configuration via 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 989
diff changeset
   974
                    break;
4f223f3df05a Bus configuration via 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 989
diff changeset
   975
                }
4f223f3df05a Bus configuration via 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 989
diff changeset
   976
4f223f3df05a Bus configuration via 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 989
diff changeset
   977
                if (!(req = ec_slave_config_get_sdo_by_pos_const(
4f223f3df05a Bus configuration via 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 989
diff changeset
   978
                                sc, data.sdo_pos))) {
4f223f3df05a Bus configuration via 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 989
diff changeset
   979
                    EC_ERR("Invalid Sdo position!\n");
4f223f3df05a Bus configuration via 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 989
diff changeset
   980
                    retval = -EINVAL;
4f223f3df05a Bus configuration via 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 989
diff changeset
   981
                    break;
4f223f3df05a Bus configuration via 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 989
diff changeset
   982
                }
4f223f3df05a Bus configuration via 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 989
diff changeset
   983
4f223f3df05a Bus configuration via 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 989
diff changeset
   984
                data.index = req->index;
4f223f3df05a Bus configuration via 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 989
diff changeset
   985
                data.subindex = req->subindex;
4f223f3df05a Bus configuration via 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 989
diff changeset
   986
                data.size = req->data_size;
4f223f3df05a Bus configuration via 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 989
diff changeset
   987
                memcpy(&data.data, req->data, min((u32) data.size, (u32) 4));
4f223f3df05a Bus configuration via 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 989
diff changeset
   988
999
14307580deb6 Removed unnecessary code.
Florian Pose <fp@igh-essen.com>
parents: 990
diff changeset
   989
                if (copy_to_user((void __user *) arg, &data, sizeof(data)))
14307580deb6 Removed unnecessary code.
Florian Pose <fp@igh-essen.com>
parents: 990
diff changeset
   990
                    retval = -EFAULT;
990
4f223f3df05a Bus configuration via 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 989
diff changeset
   991
                break;
4f223f3df05a Bus configuration via 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 989
diff changeset
   992
            }
4f223f3df05a Bus configuration via 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents: 989
diff changeset
   993
922
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   994
        default:
972
ad59641a68c8 ioctl() permissions.
Florian Pose <fp@igh-essen.com>
parents: 968
diff changeset
   995
            retval = -ENOTTY;
922
fede1d8f5b71 Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   996
    }
935
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   997
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   998
    return retval;
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
   999
}
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
  1000
b954e9d91ea5 Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents: 922
diff changeset
  1001
/*****************************************************************************/