author | Florian Pose <fp@igh-essen.com> |
Fri, 04 Jul 2008 12:04:56 +0000 | |
changeset 1090 | ee122eadda7f |
parent 1082 | ff06c58e269c |
child 1092 | 69393cf60399 |
permissions | -rw-r--r-- |
922
fede1d8f5b71
Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
1 |
/****************************************************************************** |
fede1d8f5b71
Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
2 |
* |
fede1d8f5b71
Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
3 |
* $Id$ |
fede1d8f5b71
Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
4 |
* |
fede1d8f5b71
Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
5 |
* Copyright (C) 2006 Florian Pose, Ingenieurgemeinschaft IgH |
fede1d8f5b71
Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
6 |
* |
fede1d8f5b71
Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
7 |
* This file is part of the IgH EtherCAT Master. |
fede1d8f5b71
Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
8 |
* |
fede1d8f5b71
Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
9 |
* The IgH EtherCAT Master is free software; you can redistribute it |
fede1d8f5b71
Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
10 |
* and/or modify it under the terms of the GNU General Public License |
fede1d8f5b71
Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
11 |
* as published by the Free Software Foundation; either version 2 of the |
fede1d8f5b71
Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
12 |
* License, or (at your option) any later version. |
fede1d8f5b71
Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
13 |
* |
fede1d8f5b71
Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
14 |
* The IgH EtherCAT Master is distributed in the hope that it will be |
fede1d8f5b71
Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
15 |
* useful, but WITHOUT ANY WARRANTY; without even the implied warranty of |
fede1d8f5b71
Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
16 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
fede1d8f5b71
Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
17 |
* GNU General Public License for more details. |
fede1d8f5b71
Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
18 |
* |
fede1d8f5b71
Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
19 |
* You should have received a copy of the GNU General Public License |
fede1d8f5b71
Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
20 |
* along with the IgH EtherCAT Master; if not, write to the Free Software |
fede1d8f5b71
Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
21 |
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
fede1d8f5b71
Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
22 |
* |
fede1d8f5b71
Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
23 |
* The right to use EtherCAT Technology is granted and comes free of |
fede1d8f5b71
Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
24 |
* charge under condition of compatibility of product made by |
fede1d8f5b71
Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
25 |
* Licensee. People intending to distribute/sell products based on the |
fede1d8f5b71
Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
26 |
* code, have to sign an agreement to guarantee that products using |
fede1d8f5b71
Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
27 |
* software based on IgH EtherCAT master stay compatible with the actual |
fede1d8f5b71
Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
28 |
* EtherCAT specification (which are released themselves as an open |
fede1d8f5b71
Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
29 |
* standard) as the (only) precondition to have the right to use EtherCAT |
fede1d8f5b71
Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
30 |
* Technology, IP and trade marks. |
fede1d8f5b71
Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
31 |
* |
fede1d8f5b71
Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
32 |
*****************************************************************************/ |
fede1d8f5b71
Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
33 |
|
fede1d8f5b71
Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
34 |
/** |
fede1d8f5b71
Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
35 |
\file |
fede1d8f5b71
Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
36 |
EtherCAT master character device. |
fede1d8f5b71
Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
37 |
*/ |
fede1d8f5b71
Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
38 |
|
fede1d8f5b71
Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
39 |
/*****************************************************************************/ |
fede1d8f5b71
Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
40 |
|
fede1d8f5b71
Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
41 |
#include <linux/module.h> |
fede1d8f5b71
Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
42 |
|
fede1d8f5b71
Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
43 |
#include "cdev.h" |
fede1d8f5b71
Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
44 |
#include "master.h" |
950
8b00e63fff90
'ethercat domain' shows domain contents and process data.
Florian Pose <fp@igh-essen.com>
parents:
949
diff
changeset
|
45 |
#include "slave_config.h" |
922
fede1d8f5b71
Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
46 |
#include "ioctl.h" |
fede1d8f5b71
Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
47 |
|
fede1d8f5b71
Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
48 |
/*****************************************************************************/ |
fede1d8f5b71
Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
49 |
|
fede1d8f5b71
Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
50 |
/** \cond */ |
fede1d8f5b71
Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
51 |
|
fede1d8f5b71
Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
52 |
int eccdev_open(struct inode *, struct file *); |
fede1d8f5b71
Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
53 |
int eccdev_release(struct inode *, struct file *); |
935
b954e9d91ea5
Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents:
922
diff
changeset
|
54 |
long eccdev_ioctl(struct file *, unsigned int, unsigned long); |
922
fede1d8f5b71
Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
55 |
|
fede1d8f5b71
Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
56 |
/*****************************************************************************/ |
fede1d8f5b71
Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
57 |
|
fede1d8f5b71
Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
58 |
static struct file_operations eccdev_fops = { |
935
b954e9d91ea5
Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents:
922
diff
changeset
|
59 |
.owner = THIS_MODULE, |
b954e9d91ea5
Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents:
922
diff
changeset
|
60 |
.open = eccdev_open, |
b954e9d91ea5
Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents:
922
diff
changeset
|
61 |
.release = eccdev_release, |
b954e9d91ea5
Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents:
922
diff
changeset
|
62 |
.unlocked_ioctl = eccdev_ioctl |
922
fede1d8f5b71
Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
63 |
}; |
fede1d8f5b71
Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
64 |
|
fede1d8f5b71
Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
65 |
/** \endcond */ |
fede1d8f5b71
Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
66 |
|
fede1d8f5b71
Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
67 |
/*****************************************************************************/ |
fede1d8f5b71
Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
68 |
|
fede1d8f5b71
Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
69 |
/** Constructor. |
fede1d8f5b71
Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
70 |
* |
fede1d8f5b71
Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
71 |
* \return 0 in case of success, else < 0 |
fede1d8f5b71
Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
72 |
*/ |
fede1d8f5b71
Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
73 |
int ec_cdev_init( |
fede1d8f5b71
Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
74 |
ec_cdev_t *cdev, /**< EtherCAT master character device. */ |
fede1d8f5b71
Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
75 |
ec_master_t *master, /**< Parent master. */ |
fede1d8f5b71
Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
76 |
dev_t dev_num /**< Device number. */ |
fede1d8f5b71
Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
77 |
) |
fede1d8f5b71
Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
78 |
{ |
fede1d8f5b71
Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
79 |
cdev->master = master; |
fede1d8f5b71
Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
80 |
|
fede1d8f5b71
Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
81 |
cdev_init(&cdev->cdev, &eccdev_fops); |
fede1d8f5b71
Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
82 |
cdev->cdev.owner = THIS_MODULE; |
fede1d8f5b71
Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
83 |
|
fede1d8f5b71
Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
84 |
if (cdev_add(&cdev->cdev, |
fede1d8f5b71
Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
85 |
MKDEV(MAJOR(dev_num), master->index), 1)) { |
fede1d8f5b71
Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
86 |
EC_ERR("Failed to add character device!\n"); |
fede1d8f5b71
Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
87 |
return -1; |
fede1d8f5b71
Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
88 |
} |
fede1d8f5b71
Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
89 |
|
fede1d8f5b71
Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
90 |
return 0; |
fede1d8f5b71
Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
91 |
} |
fede1d8f5b71
Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
92 |
|
fede1d8f5b71
Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
93 |
/*****************************************************************************/ |
fede1d8f5b71
Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
94 |
|
fede1d8f5b71
Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
95 |
/** Destructor. |
fede1d8f5b71
Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
96 |
*/ |
fede1d8f5b71
Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
97 |
void ec_cdev_clear(ec_cdev_t *cdev /**< EtherCAT XML device */) |
fede1d8f5b71
Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
98 |
{ |
fede1d8f5b71
Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
99 |
cdev_del(&cdev->cdev); |
fede1d8f5b71
Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
100 |
} |
fede1d8f5b71
Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
101 |
|
1079
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
102 |
/*****************************************************************************/ |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
103 |
|
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
104 |
/** Get master information. |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
105 |
*/ |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
106 |
int ec_cdev_ioctl_master( |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
107 |
ec_master_t *master, /**< EtherCAT master. */ |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
108 |
unsigned long arg /**< Userspace address to store the results. */ |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
109 |
) |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
110 |
{ |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
111 |
ec_ioctl_master_t data; |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
112 |
|
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
113 |
down(&master->master_sem); |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
114 |
data.slave_count = master->slave_count; |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
115 |
data.config_count = ec_master_config_count(master); |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
116 |
data.domain_count = ec_master_domain_count(master); |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
117 |
data.phase = (uint8_t) master->phase; |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
118 |
up(&master->master_sem); |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
119 |
|
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
120 |
down(&master->device_sem); |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
121 |
memcpy(data.devices[0].address, master->main_mac, ETH_ALEN); |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
122 |
data.devices[0].attached = master->main_device.dev ? 1 : 0; |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
123 |
data.devices[0].tx_count = master->main_device.tx_count; |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
124 |
data.devices[0].rx_count = master->main_device.rx_count; |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
125 |
memcpy(data.devices[1].address, master->backup_mac, ETH_ALEN); |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
126 |
data.devices[1].attached = master->backup_device.dev ? 1 : 0; |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
127 |
data.devices[1].tx_count = master->backup_device.tx_count; |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
128 |
data.devices[1].rx_count = master->backup_device.rx_count; |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
129 |
up(&master->device_sem); |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
130 |
|
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
131 |
if (copy_to_user((void __user *) arg, &data, sizeof(data))) |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
132 |
return -EFAULT; |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
133 |
|
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
134 |
return 0; |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
135 |
} |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
136 |
|
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
137 |
/*****************************************************************************/ |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
138 |
|
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
139 |
/** Get slave information. |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
140 |
*/ |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
141 |
int ec_cdev_ioctl_slave( |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
142 |
ec_master_t *master, /**< EtherCAT master. */ |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
143 |
unsigned long arg /**< Userspace address to store the results. */ |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
144 |
) |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
145 |
{ |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
146 |
ec_ioctl_slave_t data; |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
147 |
const ec_slave_t *slave; |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
148 |
|
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
149 |
if (copy_from_user(&data, (void __user *) arg, sizeof(data))) { |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
150 |
return -EFAULT; |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
151 |
} |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
152 |
|
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
153 |
down(&master->master_sem); |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
154 |
|
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
155 |
if (!(slave = ec_master_find_slave_const( |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
156 |
master, 0, data.position))) { |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
157 |
up(&master->master_sem); |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
158 |
EC_ERR("Slave %u does not exist!\n", data.position); |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
159 |
return -EINVAL; |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
160 |
} |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
161 |
|
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
162 |
data.vendor_id = slave->sii.vendor_id; |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
163 |
data.product_code = slave->sii.product_code; |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
164 |
data.revision_number = slave->sii.revision_number; |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
165 |
data.serial_number = slave->sii.serial_number; |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
166 |
data.alias = slave->sii.alias; |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
167 |
data.rx_mailbox_offset = slave->sii.rx_mailbox_offset; |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
168 |
data.rx_mailbox_size = slave->sii.rx_mailbox_size; |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
169 |
data.tx_mailbox_offset = slave->sii.tx_mailbox_offset; |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
170 |
data.tx_mailbox_size = slave->sii.tx_mailbox_size; |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
171 |
data.mailbox_protocols = slave->sii.mailbox_protocols; |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
172 |
data.has_general_category = slave->sii.has_general; |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
173 |
data.coe_details = slave->sii.coe_details; |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
174 |
data.general_flags = slave->sii.general_flags; |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
175 |
data.current_on_ebus = slave->sii.current_on_ebus; |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
176 |
data.state = slave->current_state; |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
177 |
data.error_flag = slave->error_flag; |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
178 |
|
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
179 |
data.sync_count = slave->sii.sync_count; |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
180 |
data.sdo_count = ec_slave_sdo_count(slave); |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
181 |
data.sii_nwords = slave->sii_nwords; |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
182 |
|
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
183 |
if (slave->sii.name) { |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
184 |
strncpy(data.name, slave->sii.name, |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
185 |
EC_IOCTL_STRING_SIZE); |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
186 |
data.name[EC_IOCTL_STRING_SIZE - 1] = 0; |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
187 |
} else { |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
188 |
data.name[0] = 0; |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
189 |
} |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
190 |
|
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
191 |
up(&master->master_sem); |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
192 |
|
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
193 |
if (copy_to_user((void __user *) arg, &data, sizeof(data))) |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
194 |
return -EFAULT; |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
195 |
|
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
196 |
return 0; |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
197 |
} |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
198 |
|
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
199 |
/*****************************************************************************/ |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
200 |
|
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
201 |
/** Get slave sync manager information. |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
202 |
*/ |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
203 |
int ec_cdev_ioctl_slave_sync( |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
204 |
ec_master_t *master, /**< EtherCAT master. */ |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
205 |
unsigned long arg /**< Userspace address to store the results. */ |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
206 |
) |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
207 |
{ |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
208 |
ec_ioctl_slave_sync_t data; |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
209 |
const ec_slave_t *slave; |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
210 |
const ec_sync_t *sync; |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
211 |
|
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
212 |
if (copy_from_user(&data, (void __user *) arg, sizeof(data))) { |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
213 |
return -EFAULT; |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
214 |
} |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
215 |
|
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
216 |
down(&master->master_sem); |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
217 |
|
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
218 |
if (!(slave = ec_master_find_slave_const( |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
219 |
master, 0, data.slave_position))) { |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
220 |
up(&master->master_sem); |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
221 |
EC_ERR("Slave %u does not exist!\n", data.slave_position); |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
222 |
return -EINVAL; |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
223 |
} |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
224 |
|
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
225 |
if (data.sync_index >= slave->sii.sync_count) { |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
226 |
up(&master->master_sem); |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
227 |
EC_ERR("Sync manager %u does not exist in slave %u!\n", |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
228 |
data.sync_index, data.slave_position); |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
229 |
return -EINVAL; |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
230 |
} |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
231 |
|
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
232 |
sync = &slave->sii.syncs[data.sync_index]; |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
233 |
|
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
234 |
data.physical_start_address = sync->physical_start_address; |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
235 |
data.default_size = sync->default_length; |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
236 |
data.control_register = sync->control_register; |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
237 |
data.enable = sync->enable; |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
238 |
data.assign_source = sync->assign_source; |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
239 |
data.pdo_count = ec_pdo_list_count(&sync->pdos); |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
240 |
|
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
241 |
up(&master->master_sem); |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
242 |
|
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
243 |
if (copy_to_user((void __user *) arg, &data, sizeof(data))) |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
244 |
return -EFAULT; |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
245 |
|
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
246 |
return 0; |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
247 |
} |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
248 |
|
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
249 |
/*****************************************************************************/ |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
250 |
|
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
251 |
/** Get slave sync manager Pdo information. |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
252 |
*/ |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
253 |
int ec_cdev_ioctl_slave_sync_pdo( |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
254 |
ec_master_t *master, /**< EtherCAT master. */ |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
255 |
unsigned long arg /**< Userspace address to store the results. */ |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
256 |
) |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
257 |
{ |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
258 |
ec_ioctl_slave_sync_pdo_t data; |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
259 |
const ec_slave_t *slave; |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
260 |
const ec_sync_t *sync; |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
261 |
const ec_pdo_t *pdo; |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
262 |
|
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
263 |
if (copy_from_user(&data, (void __user *) arg, sizeof(data))) { |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
264 |
return -EFAULT; |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
265 |
} |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
266 |
|
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
267 |
down(&master->master_sem); |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
268 |
|
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
269 |
if (!(slave = ec_master_find_slave_const( |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
270 |
master, 0, data.slave_position))) { |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
271 |
up(&master->master_sem); |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
272 |
EC_ERR("Slave %u does not exist!\n", data.slave_position); |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
273 |
return -EINVAL; |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
274 |
} |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
275 |
|
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
276 |
if (data.sync_index >= slave->sii.sync_count) { |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
277 |
up(&master->master_sem); |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
278 |
EC_ERR("Sync manager %u does not exist in slave %u!\n", |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
279 |
data.sync_index, data.slave_position); |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
280 |
return -EINVAL; |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
281 |
} |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
282 |
|
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
283 |
sync = &slave->sii.syncs[data.sync_index]; |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
284 |
if (!(pdo = ec_pdo_list_find_pdo_by_pos_const( |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
285 |
&sync->pdos, data.pdo_pos))) { |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
286 |
up(&master->master_sem); |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
287 |
EC_ERR("Sync manager %u does not contain a Pdo with " |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
288 |
"position %u in slave %u!\n", data.sync_index, |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
289 |
data.pdo_pos, data.slave_position); |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
290 |
return -EINVAL; |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
291 |
} |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
292 |
|
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
293 |
data.index = pdo->index; |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
294 |
data.entry_count = ec_pdo_entry_count(pdo); |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
295 |
|
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
296 |
if (pdo->name) { |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
297 |
strncpy(data.name, pdo->name, EC_IOCTL_STRING_SIZE); |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
298 |
data.name[EC_IOCTL_STRING_SIZE - 1] = 0; |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
299 |
} else { |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
300 |
data.name[0] = 0; |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
301 |
} |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
302 |
|
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
303 |
up(&master->master_sem); |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
304 |
|
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
305 |
if (copy_to_user((void __user *) arg, &data, sizeof(data))) |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
306 |
return -EFAULT; |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
307 |
|
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
308 |
return 0; |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
309 |
} |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
310 |
|
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
311 |
/*****************************************************************************/ |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
312 |
|
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
313 |
/** Get slave sync manager Pdo entry information. |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
314 |
*/ |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
315 |
int ec_cdev_ioctl_slave_sync_pdo_entry( |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
316 |
ec_master_t *master, /**< EtherCAT master. */ |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
317 |
unsigned long arg /**< Userspace address to store the results. */ |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
318 |
) |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
319 |
{ |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
320 |
ec_ioctl_slave_sync_pdo_entry_t data; |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
321 |
const ec_slave_t *slave; |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
322 |
const ec_sync_t *sync; |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
323 |
const ec_pdo_t *pdo; |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
324 |
const ec_pdo_entry_t *entry; |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
325 |
|
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
326 |
if (copy_from_user(&data, (void __user *) arg, sizeof(data))) { |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
327 |
return -EFAULT; |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
328 |
} |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
329 |
|
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
330 |
down(&master->master_sem); |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
331 |
|
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
332 |
if (!(slave = ec_master_find_slave_const( |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
333 |
master, 0, data.slave_position))) { |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
334 |
up(&master->master_sem); |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
335 |
EC_ERR("Slave %u does not exist!\n", data.slave_position); |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
336 |
return -EINVAL; |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
337 |
} |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
338 |
|
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
339 |
if (data.sync_index >= slave->sii.sync_count) { |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
340 |
up(&master->master_sem); |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
341 |
EC_ERR("Sync manager %u does not exist in slave %u!\n", |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
342 |
data.sync_index, data.slave_position); |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
343 |
return -EINVAL; |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
344 |
} |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
345 |
|
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
346 |
sync = &slave->sii.syncs[data.sync_index]; |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
347 |
if (!(pdo = ec_pdo_list_find_pdo_by_pos_const( |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
348 |
&sync->pdos, data.pdo_pos))) { |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
349 |
up(&master->master_sem); |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
350 |
EC_ERR("Sync manager %u does not contain a Pdo with " |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
351 |
"position %u in slave %u!\n", data.sync_index, |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
352 |
data.pdo_pos, data.slave_position); |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
353 |
return -EINVAL; |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
354 |
} |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
355 |
|
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
356 |
if (!(entry = ec_pdo_find_entry_by_pos_const( |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
357 |
pdo, data.entry_pos))) { |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
358 |
up(&master->master_sem); |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
359 |
EC_ERR("Pdo 0x%04X does not contain an entry with " |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
360 |
"position %u in slave %u!\n", data.pdo_pos, |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
361 |
data.entry_pos, data.slave_position); |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
362 |
return -EINVAL; |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
363 |
} |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
364 |
|
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
365 |
data.index = entry->index; |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
366 |
data.subindex = entry->subindex; |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
367 |
data.bit_length = entry->bit_length; |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
368 |
if (entry->name) { |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
369 |
strncpy(data.name, entry->name, EC_IOCTL_STRING_SIZE); |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
370 |
data.name[EC_IOCTL_STRING_SIZE - 1] = 0; |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
371 |
} else { |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
372 |
data.name[0] = 0; |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
373 |
} |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
374 |
|
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
375 |
up(&master->master_sem); |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
376 |
|
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
377 |
if (copy_to_user((void __user *) arg, &data, sizeof(data))) |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
378 |
return -EFAULT; |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
379 |
|
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
380 |
return 0; |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
381 |
} |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
382 |
|
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
383 |
/*****************************************************************************/ |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
384 |
|
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
385 |
/** Get domain information. |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
386 |
*/ |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
387 |
int ec_cdev_ioctl_domain( |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
388 |
ec_master_t *master, /**< EtherCAT master. */ |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
389 |
unsigned long arg /**< Userspace address to store the results. */ |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
390 |
) |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
391 |
{ |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
392 |
ec_ioctl_domain_t data; |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
393 |
const ec_domain_t *domain; |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
394 |
|
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
395 |
if (copy_from_user(&data, (void __user *) arg, sizeof(data))) { |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
396 |
return -EFAULT; |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
397 |
} |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
398 |
|
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
399 |
down(&master->master_sem); |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
400 |
|
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
401 |
if (!(domain = ec_master_find_domain_const(master, data.index))) { |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
402 |
up(&master->master_sem); |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
403 |
EC_ERR("Domain %u does not exist!\n", data.index); |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
404 |
return -EINVAL; |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
405 |
} |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
406 |
|
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
407 |
data.data_size = domain->data_size; |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
408 |
data.logical_base_address = domain->logical_base_address; |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
409 |
data.working_counter = domain->working_counter; |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
410 |
data.expected_working_counter = domain->expected_working_counter; |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
411 |
data.fmmu_count = ec_domain_fmmu_count(domain); |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
412 |
|
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
413 |
up(&master->master_sem); |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
414 |
|
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
415 |
if (copy_to_user((void __user *) arg, &data, sizeof(data))) |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
416 |
return -EFAULT; |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
417 |
|
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
418 |
return 0; |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
419 |
} |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
420 |
|
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
421 |
/*****************************************************************************/ |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
422 |
|
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
423 |
/** Get domain FMMU information. |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
424 |
*/ |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
425 |
int ec_cdev_ioctl_domain_fmmu( |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
426 |
ec_master_t *master, /**< EtherCAT master. */ |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
427 |
unsigned long arg /**< Userspace address to store the results. */ |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
428 |
) |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
429 |
{ |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
430 |
ec_ioctl_domain_fmmu_t data; |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
431 |
const ec_domain_t *domain; |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
432 |
const ec_fmmu_config_t *fmmu; |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
433 |
|
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
434 |
if (copy_from_user(&data, (void __user *) arg, sizeof(data))) { |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
435 |
return -EFAULT; |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
436 |
} |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
437 |
|
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
438 |
down(&master->master_sem); |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
439 |
|
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
440 |
if (!(domain = ec_master_find_domain_const(master, data.domain_index))) { |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
441 |
up(&master->master_sem); |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
442 |
EC_ERR("Domain %u does not exist!\n", data.domain_index); |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
443 |
return -EINVAL; |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
444 |
} |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
445 |
|
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
446 |
if (!(fmmu = ec_domain_find_fmmu(domain, data.fmmu_index))) { |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
447 |
up(&master->master_sem); |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
448 |
EC_ERR("Domain %u has less than %u fmmu configurations.\n", |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
449 |
data.domain_index, data.fmmu_index + 1); |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
450 |
return -EINVAL; |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
451 |
} |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
452 |
|
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
453 |
data.slave_config_alias = fmmu->sc->alias; |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
454 |
data.slave_config_position = fmmu->sc->position; |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
455 |
data.sync_index = fmmu->sync_index; |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
456 |
data.dir = fmmu->dir; |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
457 |
data.logical_address = fmmu->logical_start_address; |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
458 |
data.data_size = fmmu->data_size; |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
459 |
|
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
460 |
up(&master->master_sem); |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
461 |
|
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
462 |
if (copy_to_user((void __user *) arg, &data, sizeof(data))) |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
463 |
return -EFAULT; |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
464 |
|
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
465 |
return 0; |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
466 |
} |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
467 |
|
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
468 |
/*****************************************************************************/ |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
469 |
|
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
470 |
/** Get domain data. |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
471 |
*/ |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
472 |
int ec_cdev_ioctl_domain_data( |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
473 |
ec_master_t *master, /**< EtherCAT master. */ |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
474 |
unsigned long arg /**< Userspace address to store the results. */ |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
475 |
) |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
476 |
{ |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
477 |
ec_ioctl_domain_data_t data; |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
478 |
const ec_domain_t *domain; |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
479 |
|
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
480 |
if (copy_from_user(&data, (void __user *) arg, sizeof(data))) { |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
481 |
return -EFAULT; |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
482 |
} |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
483 |
|
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
484 |
down(&master->master_sem); |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
485 |
|
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
486 |
if (!(domain = ec_master_find_domain_const(master, data.domain_index))) { |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
487 |
up(&master->master_sem); |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
488 |
EC_ERR("Domain %u does not exist!\n", data.domain_index); |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
489 |
return -EINVAL; |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
490 |
} |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
491 |
|
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
492 |
if (domain->data_size != data.data_size) { |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
493 |
up(&master->master_sem); |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
494 |
EC_ERR("Data size mismatch %u/%u!\n", |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
495 |
data.data_size, domain->data_size); |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
496 |
return -EFAULT; |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
497 |
} |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
498 |
|
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
499 |
if (copy_to_user((void __user *) data.target, domain->data, |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
500 |
domain->data_size)) |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
501 |
return -EFAULT; |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
502 |
|
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
503 |
up(&master->master_sem); |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
504 |
return 0; |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
505 |
} |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
506 |
|
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
507 |
/*****************************************************************************/ |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
508 |
|
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
509 |
/** Set master debug level. |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
510 |
*/ |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
511 |
int ec_cdev_ioctl_master_debug( |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
512 |
ec_master_t *master, /**< EtherCAT master. */ |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
513 |
unsigned long arg /**< ioctl() argument. */ |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
514 |
) |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
515 |
{ |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
516 |
if (ec_master_debug_level(master, (unsigned int) arg)) |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
517 |
return -EINVAL; |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
518 |
|
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
519 |
return 0; |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
520 |
} |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
521 |
|
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
522 |
/*****************************************************************************/ |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
523 |
|
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
524 |
/** Set slave state. |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
525 |
*/ |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
526 |
int ec_cdev_ioctl_slave_state( |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
527 |
ec_master_t *master, /**< EtherCAT master. */ |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
528 |
unsigned long arg /**< ioctl() argument. */ |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
529 |
) |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
530 |
{ |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
531 |
ec_ioctl_slave_state_t data; |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
532 |
ec_slave_t *slave; |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
533 |
|
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
534 |
if (copy_from_user(&data, (void __user *) arg, sizeof(data))) { |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
535 |
return -EFAULT; |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
536 |
} |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
537 |
|
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
538 |
down(&master->master_sem); |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
539 |
|
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
540 |
if (!(slave = ec_master_find_slave( |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
541 |
master, 0, data.slave_position))) { |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
542 |
EC_ERR("Slave %u does not exist!\n", data.slave_position); |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
543 |
return -EINVAL; |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
544 |
} |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
545 |
|
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
546 |
ec_slave_request_state(slave, data.requested_state); |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
547 |
|
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
548 |
up(&master->master_sem); |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
549 |
return 0; |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
550 |
} |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
551 |
|
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
552 |
/*****************************************************************************/ |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
553 |
|
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
554 |
/** Get slave Sdo information. |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
555 |
*/ |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
556 |
int ec_cdev_ioctl_slave_sdo( |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
557 |
ec_master_t *master, /**< EtherCAT master. */ |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
558 |
unsigned long arg /**< ioctl() argument. */ |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
559 |
) |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
560 |
{ |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
561 |
ec_ioctl_slave_sdo_t data; |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
562 |
const ec_slave_t *slave; |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
563 |
const ec_sdo_t *sdo; |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
564 |
|
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
565 |
if (copy_from_user(&data, (void __user *) arg, sizeof(data))) { |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
566 |
return -EFAULT; |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
567 |
} |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
568 |
|
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
569 |
down(&master->master_sem); |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
570 |
|
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
571 |
if (!(slave = ec_master_find_slave_const( |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
572 |
master, 0, data.slave_position))) { |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
573 |
up(&master->master_sem); |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
574 |
EC_ERR("Slave %u does not exist!\n", data.slave_position); |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
575 |
return -EINVAL; |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
576 |
} |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
577 |
|
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
578 |
if (!(sdo = ec_slave_get_sdo_by_pos_const( |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
579 |
slave, data.sdo_position))) { |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
580 |
up(&master->master_sem); |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
581 |
EC_ERR("Sdo %u does not exist in slave %u!\n", |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
582 |
data.sdo_position, data.slave_position); |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
583 |
return -EINVAL; |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
584 |
} |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
585 |
|
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
586 |
data.sdo_index = sdo->index; |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
587 |
data.max_subindex = sdo->max_subindex; |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
588 |
|
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
589 |
if (sdo->name) { |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
590 |
strncpy(data.name, sdo->name, EC_IOCTL_STRING_SIZE); |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
591 |
data.name[EC_IOCTL_STRING_SIZE - 1] = 0; |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
592 |
} else { |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
593 |
data.name[0] = 0; |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
594 |
} |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
595 |
|
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
596 |
up(&master->master_sem); |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
597 |
|
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
598 |
if (copy_to_user((void __user *) arg, &data, sizeof(data))) |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
599 |
return -EFAULT; |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
600 |
|
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
601 |
return 0; |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
602 |
} |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
603 |
|
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
604 |
/*****************************************************************************/ |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
605 |
|
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
606 |
/** Get slave Sdo entry information. |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
607 |
*/ |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
608 |
int ec_cdev_ioctl_slave_sdo_entry( |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
609 |
ec_master_t *master, /**< EtherCAT master. */ |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
610 |
unsigned long arg /**< ioctl() argument. */ |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
611 |
) |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
612 |
{ |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
613 |
ec_ioctl_slave_sdo_entry_t data; |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
614 |
const ec_slave_t *slave; |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
615 |
const ec_sdo_t *sdo; |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
616 |
const ec_sdo_entry_t *entry; |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
617 |
|
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
618 |
if (copy_from_user(&data, (void __user *) arg, sizeof(data))) { |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
619 |
return -EFAULT; |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
620 |
} |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
621 |
|
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
622 |
down(&master->master_sem); |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
623 |
|
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
624 |
if (!(slave = ec_master_find_slave_const( |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
625 |
master, 0, data.slave_position))) { |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
626 |
up(&master->master_sem); |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
627 |
EC_ERR("Slave %u does not exist!\n", data.slave_position); |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
628 |
return -EINVAL; |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
629 |
} |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
630 |
|
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
631 |
if (data.sdo_spec <= 0) { |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
632 |
if (!(sdo = ec_slave_get_sdo_by_pos_const( |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
633 |
slave, -data.sdo_spec))) { |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
634 |
up(&master->master_sem); |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
635 |
EC_ERR("Sdo %u does not exist in slave %u!\n", |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
636 |
-data.sdo_spec, data.slave_position); |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
637 |
return -EINVAL; |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
638 |
} |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
639 |
} else { |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
640 |
if (!(sdo = ec_slave_get_sdo_const( |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
641 |
slave, data.sdo_spec))) { |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
642 |
up(&master->master_sem); |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
643 |
EC_ERR("Sdo 0x%04X does not exist in slave %u!\n", |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
644 |
data.sdo_spec, data.slave_position); |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
645 |
return -EINVAL; |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
646 |
} |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
647 |
} |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
648 |
|
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
649 |
if (!(entry = ec_sdo_get_entry_const( |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
650 |
sdo, data.sdo_entry_subindex))) { |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
651 |
up(&master->master_sem); |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
652 |
EC_ERR("Sdo entry 0x%04X:%02X does not exist " |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
653 |
"in slave %u!\n", sdo->index, |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
654 |
data.sdo_entry_subindex, data.slave_position); |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
655 |
return -EINVAL; |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
656 |
} |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
657 |
|
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
658 |
data.data_type = entry->data_type; |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
659 |
data.bit_length = entry->bit_length; |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
660 |
|
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
661 |
if (entry->description) { |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
662 |
strncpy(data.description, entry->description, |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
663 |
EC_IOCTL_STRING_SIZE); |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
664 |
data.description[EC_IOCTL_STRING_SIZE - 1] |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
665 |
= 0; |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
666 |
} else { |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
667 |
data.description[0] = 0; |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
668 |
} |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
669 |
|
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
670 |
up(&master->master_sem); |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
671 |
|
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
672 |
if (copy_to_user((void __user *) arg, &data, sizeof(data))) |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
673 |
return -EFAULT; |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
674 |
|
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
675 |
return 0; |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
676 |
} |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
677 |
|
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
678 |
/*****************************************************************************/ |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
679 |
|
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
680 |
/** Upload Sdo. |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
681 |
*/ |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
682 |
int ec_cdev_ioctl_slave_sdo_upload( |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
683 |
ec_master_t *master, /**< EtherCAT master. */ |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
684 |
unsigned long arg /**< ioctl() argument. */ |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
685 |
) |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
686 |
{ |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
687 |
ec_ioctl_slave_sdo_upload_t data; |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
688 |
ec_master_sdo_request_t request; |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
689 |
int retval; |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
690 |
|
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
691 |
if (copy_from_user(&data, (void __user *) arg, sizeof(data))) { |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
692 |
return -EFAULT; |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
693 |
} |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
694 |
|
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
695 |
ec_sdo_request_init(&request.req); |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
696 |
ec_sdo_request_address(&request.req, |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
697 |
data.sdo_index, data.sdo_entry_subindex); |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
698 |
ecrt_sdo_request_read(&request.req); |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
699 |
|
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
700 |
down(&master->master_sem); |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
701 |
|
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
702 |
if (!(request.slave = ec_master_find_slave( |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
703 |
master, 0, data.slave_position))) { |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
704 |
up(&master->master_sem); |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
705 |
ec_sdo_request_clear(&request.req); |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
706 |
EC_ERR("Slave %u does not exist!\n", data.slave_position); |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
707 |
return -EINVAL; |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
708 |
} |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
709 |
|
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
710 |
// schedule request. |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
711 |
list_add_tail(&request.list, &master->slave_sdo_requests); |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
712 |
|
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
713 |
up(&master->master_sem); |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
714 |
|
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
715 |
// wait for processing through FSM |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
716 |
if (wait_event_interruptible(master->sdo_queue, |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
717 |
request.req.state != EC_REQUEST_QUEUED)) { |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
718 |
// interrupted by signal |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
719 |
down(&master->master_sem); |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
720 |
if (request.req.state == EC_REQUEST_QUEUED) { |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
721 |
list_del(&request.req.list); |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
722 |
up(&master->master_sem); |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
723 |
ec_sdo_request_clear(&request.req); |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
724 |
return -EINTR; |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
725 |
} |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
726 |
// request already processing: interrupt not possible. |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
727 |
up(&master->master_sem); |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
728 |
} |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
729 |
|
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
730 |
// wait until master FSM has finished processing |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
731 |
wait_event(master->sdo_queue, request.req.state != EC_REQUEST_BUSY); |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
732 |
|
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
733 |
data.abort_code = request.req.abort_code; |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
734 |
|
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
735 |
if (request.req.state != EC_REQUEST_SUCCESS) { |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
736 |
data.data_size = 0; |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
737 |
retval = -EIO; |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
738 |
} else { |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
739 |
if (request.req.data_size > data.target_size) { |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
740 |
EC_ERR("Buffer too small.\n"); |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
741 |
ec_sdo_request_clear(&request.req); |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
742 |
return -EOVERFLOW; |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
743 |
} |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
744 |
data.data_size = request.req.data_size; |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
745 |
|
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
746 |
if (copy_to_user((void __user *) data.target, |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
747 |
request.req.data, data.data_size)) { |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
748 |
ec_sdo_request_clear(&request.req); |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
749 |
return -EFAULT; |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
750 |
} |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
751 |
retval = 0; |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
752 |
} |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
753 |
|
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
754 |
if (__copy_to_user((void __user *) arg, &data, sizeof(data))) { |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
755 |
retval = -EFAULT; |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
756 |
} |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
757 |
|
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
758 |
ec_sdo_request_clear(&request.req); |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
759 |
return retval; |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
760 |
} |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
761 |
|
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
762 |
/*****************************************************************************/ |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
763 |
|
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
764 |
/** Download Sdo. |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
765 |
*/ |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
766 |
int ec_cdev_ioctl_slave_sdo_download( |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
767 |
ec_master_t *master, /**< EtherCAT master. */ |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
768 |
unsigned long arg /**< ioctl() argument. */ |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
769 |
) |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
770 |
{ |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
771 |
ec_ioctl_slave_sdo_download_t data; |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
772 |
ec_master_sdo_request_t request; |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
773 |
int retval; |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
774 |
|
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
775 |
if (copy_from_user(&data, (void __user *) arg, sizeof(data))) { |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
776 |
return -EFAULT; |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
777 |
} |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
778 |
|
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
779 |
// copy data to download |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
780 |
if (!data.data_size) { |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
781 |
EC_ERR("Zero data size!\n"); |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
782 |
return -EINVAL; |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
783 |
} |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
784 |
|
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
785 |
ec_sdo_request_init(&request.req); |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
786 |
ec_sdo_request_address(&request.req, |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
787 |
data.sdo_index, data.sdo_entry_subindex); |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
788 |
if (ec_sdo_request_alloc(&request.req, data.data_size)) { |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
789 |
ec_sdo_request_clear(&request.req); |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
790 |
return -ENOMEM; |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
791 |
} |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
792 |
if (copy_from_user(request.req.data, |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
793 |
(void __user *) data.data, data.data_size)) { |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
794 |
ec_sdo_request_clear(&request.req); |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
795 |
return -EFAULT; |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
796 |
} |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
797 |
request.req.data_size = data.data_size; |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
798 |
ecrt_sdo_request_write(&request.req); |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
799 |
|
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
800 |
|
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
801 |
down(&master->master_sem); |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
802 |
|
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
803 |
if (!(request.slave = ec_master_find_slave( |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
804 |
master, 0, data.slave_position))) { |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
805 |
up(&master->master_sem); |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
806 |
EC_ERR("Slave %u does not exist!\n", data.slave_position); |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
807 |
ec_sdo_request_clear(&request.req); |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
808 |
return -EINVAL; |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
809 |
} |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
810 |
|
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
811 |
// schedule request. |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
812 |
list_add_tail(&request.list, &master->slave_sdo_requests); |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
813 |
|
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
814 |
up(&master->master_sem); |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
815 |
|
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
816 |
// wait for processing through FSM |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
817 |
if (wait_event_interruptible(master->sdo_queue, |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
818 |
request.req.state != EC_REQUEST_QUEUED)) { |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
819 |
// interrupted by signal |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
820 |
down(&master->master_sem); |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
821 |
if (request.req.state == EC_REQUEST_QUEUED) { |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
822 |
list_del(&request.req.list); |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
823 |
up(&master->master_sem); |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
824 |
ec_sdo_request_clear(&request.req); |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
825 |
return -EINTR; |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
826 |
} |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
827 |
// request already processing: interrupt not possible. |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
828 |
up(&master->master_sem); |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
829 |
} |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
830 |
|
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
831 |
// wait until master FSM has finished processing |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
832 |
wait_event(master->sdo_queue, request.req.state != EC_REQUEST_BUSY); |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
833 |
|
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
834 |
data.abort_code = request.req.abort_code; |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
835 |
|
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
836 |
retval = request.req.state == EC_REQUEST_SUCCESS ? 0 : -EIO; |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
837 |
|
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
838 |
if (__copy_to_user((void __user *) arg, &data, sizeof(data))) { |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
839 |
retval = -EFAULT; |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
840 |
} |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
841 |
|
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
842 |
ec_sdo_request_clear(&request.req); |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
843 |
return retval; |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
844 |
} |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
845 |
|
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
846 |
/*****************************************************************************/ |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
847 |
|
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
848 |
/** Read a slave's SII. |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
849 |
*/ |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
850 |
int ec_cdev_ioctl_slave_sii_read( |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
851 |
ec_master_t *master, /**< EtherCAT master. */ |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
852 |
unsigned long arg /**< ioctl() argument. */ |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
853 |
) |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
854 |
{ |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
855 |
ec_ioctl_slave_sii_t data; |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
856 |
const ec_slave_t *slave; |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
857 |
int retval; |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
858 |
|
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
859 |
if (copy_from_user(&data, (void __user *) arg, sizeof(data))) { |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
860 |
return -EFAULT; |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
861 |
} |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
862 |
|
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
863 |
down(&master->master_sem); |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
864 |
|
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
865 |
if (!(slave = ec_master_find_slave_const( |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
866 |
master, 0, data.slave_position))) { |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
867 |
up(&master->master_sem); |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
868 |
EC_ERR("Slave %u does not exist!\n", data.slave_position); |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
869 |
return -EINVAL; |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
870 |
} |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
871 |
|
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
872 |
if (!data.nwords |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
873 |
|| data.offset + data.nwords > slave->sii_nwords) { |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
874 |
up(&master->master_sem); |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
875 |
EC_ERR("Invalid SII read offset/size %u/%u for slave " |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
876 |
"SII size %u!\n", data.offset, |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
877 |
data.nwords, slave->sii_nwords); |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
878 |
return -EINVAL; |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
879 |
} |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
880 |
|
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
881 |
if (copy_to_user((void __user *) data.words, |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
882 |
slave->sii_words + data.offset, data.nwords * 2)) |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
883 |
retval = -EFAULT; |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
884 |
else |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
885 |
retval = 0; |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
886 |
|
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
887 |
up(&master->master_sem); |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
888 |
return retval; |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
889 |
} |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
890 |
|
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
891 |
/*****************************************************************************/ |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
892 |
|
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
893 |
/** Write a slave's SII. |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
894 |
*/ |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
895 |
int ec_cdev_ioctl_slave_sii_write( |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
896 |
ec_master_t *master, /**< EtherCAT master. */ |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
897 |
unsigned long arg /**< ioctl() argument. */ |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
898 |
) |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
899 |
{ |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
900 |
ec_ioctl_slave_sii_t data; |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
901 |
ec_slave_t *slave; |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
902 |
unsigned int byte_size; |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
903 |
uint16_t *words; |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
904 |
ec_sii_write_request_t request; |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
905 |
|
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
906 |
if (copy_from_user(&data, (void __user *) arg, sizeof(data))) { |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
907 |
return -EFAULT; |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
908 |
} |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
909 |
|
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
910 |
if (!data.nwords) |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
911 |
return 0; |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
912 |
|
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
913 |
byte_size = sizeof(uint16_t) * data.nwords; |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
914 |
if (!(words = kmalloc(byte_size, GFP_KERNEL))) { |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
915 |
EC_ERR("Failed to allocate %u bytes for SII contents.\n", |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
916 |
byte_size); |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
917 |
return -ENOMEM; |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
918 |
} |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
919 |
|
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
920 |
if (copy_from_user(words, |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
921 |
(void __user *) data.words, byte_size)) { |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
922 |
kfree(words); |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
923 |
return -EFAULT; |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
924 |
} |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
925 |
|
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
926 |
down(&master->master_sem); |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
927 |
|
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
928 |
if (!(slave = ec_master_find_slave( |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
929 |
master, 0, data.slave_position))) { |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
930 |
up(&master->master_sem); |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
931 |
EC_ERR("Slave %u does not exist!\n", data.slave_position); |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
932 |
kfree(words); |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
933 |
return -EINVAL; |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
934 |
} |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
935 |
|
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
936 |
// init SII write request |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
937 |
INIT_LIST_HEAD(&request.list); |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
938 |
request.slave = slave; |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
939 |
request.words = words; |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
940 |
request.offset = data.offset; |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
941 |
request.nwords = data.nwords; |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
942 |
request.state = EC_REQUEST_QUEUED; |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
943 |
|
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
944 |
// schedule SII write request. |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
945 |
list_add_tail(&request.list, &master->sii_requests); |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
946 |
|
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
947 |
up(&master->master_sem); |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
948 |
|
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
949 |
// wait for processing through FSM |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
950 |
if (wait_event_interruptible(master->sii_queue, |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
951 |
request.state != EC_REQUEST_QUEUED)) { |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
952 |
// interrupted by signal |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
953 |
down(&master->master_sem); |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
954 |
if (request.state == EC_REQUEST_QUEUED) { |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
955 |
// abort request |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
956 |
list_del(&request.list); |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
957 |
up(&master->master_sem); |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
958 |
kfree(words); |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
959 |
return -EINTR; |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
960 |
} |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
961 |
up(&master->master_sem); |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
962 |
} |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
963 |
|
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
964 |
// wait until master FSM has finished processing |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
965 |
wait_event(master->sii_queue, request.state != EC_REQUEST_BUSY); |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
966 |
|
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
967 |
kfree(words); |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
968 |
|
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
969 |
return request.state == EC_REQUEST_SUCCESS ? 0 : -EIO; |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
970 |
} |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
971 |
|
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
972 |
/*****************************************************************************/ |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
973 |
|
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
974 |
/** Get slave configuration information. |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
975 |
*/ |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
976 |
int ec_cdev_ioctl_config( |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
977 |
ec_master_t *master, /**< EtherCAT master. */ |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
978 |
unsigned long arg /**< ioctl() argument. */ |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
979 |
) |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
980 |
{ |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
981 |
ec_ioctl_config_t data; |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
982 |
const ec_slave_config_t *sc; |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
983 |
uint8_t i; |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
984 |
|
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
985 |
if (copy_from_user(&data, (void __user *) arg, sizeof(data))) { |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
986 |
return -EFAULT; |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
987 |
} |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
988 |
|
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
989 |
down(&master->master_sem); |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
990 |
|
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
991 |
if (!(sc = ec_master_get_config_const( |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
992 |
master, data.config_index))) { |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
993 |
up(&master->master_sem); |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
994 |
EC_ERR("Slave config %u does not exist!\n", |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
995 |
data.config_index); |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
996 |
return -EINVAL; |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
997 |
} |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
998 |
|
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
999 |
data.alias = sc->alias; |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
1000 |
data.position = sc->position; |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
1001 |
data.vendor_id = sc->vendor_id; |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
1002 |
data.product_code = sc->product_code; |
1082
ff06c58e269c
Renamed ecrt_slave_config_sync_managers() to ecrt_slave_config_pdos();
Florian Pose <fp@igh-essen.com>
parents:
1079
diff
changeset
|
1003 |
for (i = 0; i < EC_MAX_SYNC_MANAGERS; i++) { |
1079
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
1004 |
data.syncs[i].dir = sc->sync_configs[i].dir; |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
1005 |
data.syncs[i].pdo_count = |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
1006 |
ec_pdo_list_count(&sc->sync_configs[i].pdos); |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
1007 |
} |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
1008 |
data.sdo_count = ec_slave_config_sdo_count(sc); |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
1009 |
data.attached = sc->slave != NULL; |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
1010 |
data.operational = sc->slave && |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
1011 |
sc->slave->current_state == EC_SLAVE_STATE_OP; |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
1012 |
|
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
1013 |
up(&master->master_sem); |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
1014 |
|
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
1015 |
if (copy_to_user((void __user *) arg, &data, sizeof(data))) |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
1016 |
return -EFAULT; |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
1017 |
|
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
1018 |
return 0; |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
1019 |
} |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
1020 |
|
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
1021 |
/*****************************************************************************/ |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
1022 |
|
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
1023 |
/** Get slave configuration Pdo information. |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
1024 |
*/ |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
1025 |
int ec_cdev_ioctl_config_pdo( |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
1026 |
ec_master_t *master, /**< EtherCAT master. */ |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
1027 |
unsigned long arg /**< ioctl() argument. */ |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
1028 |
) |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
1029 |
{ |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
1030 |
ec_ioctl_config_pdo_t data; |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
1031 |
const ec_slave_config_t *sc; |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
1032 |
const ec_pdo_t *pdo; |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
1033 |
|
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
1034 |
if (copy_from_user(&data, (void __user *) arg, sizeof(data))) { |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
1035 |
return -EFAULT; |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
1036 |
} |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
1037 |
|
1082
ff06c58e269c
Renamed ecrt_slave_config_sync_managers() to ecrt_slave_config_pdos();
Florian Pose <fp@igh-essen.com>
parents:
1079
diff
changeset
|
1038 |
if (data.sync_index >= EC_MAX_SYNC_MANAGERS) { |
1079
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
1039 |
EC_ERR("Invalid sync manager index %u!\n", |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
1040 |
data.sync_index); |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
1041 |
return -EINVAL; |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
1042 |
} |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
1043 |
|
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
1044 |
down(&master->master_sem); |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
1045 |
|
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
1046 |
if (!(sc = ec_master_get_config_const( |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
1047 |
master, data.config_index))) { |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
1048 |
up(&master->master_sem); |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
1049 |
EC_ERR("Slave config %u does not exist!\n", |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
1050 |
data.config_index); |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
1051 |
return -EINVAL; |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
1052 |
} |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
1053 |
|
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
1054 |
if (!(pdo = ec_pdo_list_find_pdo_by_pos_const( |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
1055 |
&sc->sync_configs[data.sync_index].pdos, |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
1056 |
data.pdo_pos))) { |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
1057 |
up(&master->master_sem); |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
1058 |
EC_ERR("Invalid Pdo position!\n"); |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
1059 |
return -EINVAL; |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
1060 |
} |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
1061 |
|
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
1062 |
data.index = pdo->index; |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
1063 |
data.entry_count = ec_pdo_entry_count(pdo); |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
1064 |
|
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
1065 |
if (pdo->name) { |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
1066 |
strncpy(data.name, pdo->name, EC_IOCTL_STRING_SIZE); |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
1067 |
data.name[EC_IOCTL_STRING_SIZE - 1] = 0; |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
1068 |
} else { |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
1069 |
data.name[0] = 0; |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
1070 |
} |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
1071 |
|
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
1072 |
up(&master->master_sem); |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
1073 |
|
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
1074 |
if (copy_to_user((void __user *) arg, &data, sizeof(data))) |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
1075 |
return -EFAULT; |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
1076 |
|
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
1077 |
return 0; |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
1078 |
} |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
1079 |
|
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
1080 |
/*****************************************************************************/ |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
1081 |
|
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
1082 |
/** Get slave configuration Pdo entry information. |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
1083 |
*/ |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
1084 |
int ec_cdev_ioctl_config_pdo_entry( |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
1085 |
ec_master_t *master, /**< EtherCAT master. */ |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
1086 |
unsigned long arg /**< ioctl() argument. */ |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
1087 |
) |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
1088 |
{ |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
1089 |
ec_ioctl_config_pdo_entry_t data; |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
1090 |
const ec_slave_config_t *sc; |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
1091 |
const ec_pdo_t *pdo; |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
1092 |
const ec_pdo_entry_t *entry; |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
1093 |
|
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
1094 |
if (copy_from_user(&data, (void __user *) arg, sizeof(data))) { |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
1095 |
return -EFAULT; |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
1096 |
} |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
1097 |
|
1082
ff06c58e269c
Renamed ecrt_slave_config_sync_managers() to ecrt_slave_config_pdos();
Florian Pose <fp@igh-essen.com>
parents:
1079
diff
changeset
|
1098 |
if (data.sync_index >= EC_MAX_SYNC_MANAGERS) { |
1079
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
1099 |
EC_ERR("Invalid sync manager index %u!\n", |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
1100 |
data.sync_index); |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
1101 |
return -EINVAL; |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
1102 |
} |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
1103 |
|
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
1104 |
down(&master->master_sem); |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
1105 |
|
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
1106 |
if (!(sc = ec_master_get_config_const( |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
1107 |
master, data.config_index))) { |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
1108 |
up(&master->master_sem); |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
1109 |
EC_ERR("Slave config %u does not exist!\n", |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
1110 |
data.config_index); |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
1111 |
return -EINVAL; |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
1112 |
} |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
1113 |
|
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
1114 |
if (!(pdo = ec_pdo_list_find_pdo_by_pos_const( |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
1115 |
&sc->sync_configs[data.sync_index].pdos, |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
1116 |
data.pdo_pos))) { |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
1117 |
up(&master->master_sem); |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
1118 |
EC_ERR("Invalid Pdo position!\n"); |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
1119 |
return -EINVAL; |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
1120 |
} |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
1121 |
|
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
1122 |
if (!(entry = ec_pdo_find_entry_by_pos_const( |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
1123 |
pdo, data.entry_pos))) { |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
1124 |
up(&master->master_sem); |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
1125 |
EC_ERR("Entry not found!\n"); |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
1126 |
return -EINVAL; |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
1127 |
} |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
1128 |
|
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
1129 |
data.index = entry->index; |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
1130 |
data.subindex = entry->subindex; |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
1131 |
data.bit_length = entry->bit_length; |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
1132 |
if (entry->name) { |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
1133 |
strncpy(data.name, entry->name, EC_IOCTL_STRING_SIZE); |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
1134 |
data.name[EC_IOCTL_STRING_SIZE - 1] = 0; |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
1135 |
} else { |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
1136 |
data.name[0] = 0; |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
1137 |
} |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
1138 |
|
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
1139 |
up(&master->master_sem); |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
1140 |
|
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
1141 |
if (copy_to_user((void __user *) arg, &data, sizeof(data))) |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
1142 |
return -EFAULT; |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
1143 |
|
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
1144 |
return 0; |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
1145 |
} |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
1146 |
|
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
1147 |
/*****************************************************************************/ |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
1148 |
|
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
1149 |
/** Get slave configuration Sdo information. |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
1150 |
*/ |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
1151 |
int ec_cdev_ioctl_config_sdo( |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
1152 |
ec_master_t *master, /**< EtherCAT master. */ |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
1153 |
unsigned long arg /**< ioctl() argument. */ |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
1154 |
) |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
1155 |
{ |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
1156 |
ec_ioctl_config_sdo_t data; |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
1157 |
const ec_slave_config_t *sc; |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
1158 |
const ec_sdo_request_t *req; |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
1159 |
|
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
1160 |
if (copy_from_user(&data, (void __user *) arg, sizeof(data))) { |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
1161 |
return -EFAULT; |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
1162 |
} |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
1163 |
|
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
1164 |
down(&master->master_sem); |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
1165 |
|
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
1166 |
if (!(sc = ec_master_get_config_const( |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
1167 |
master, data.config_index))) { |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
1168 |
up(&master->master_sem); |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
1169 |
EC_ERR("Slave config %u does not exist!\n", |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
1170 |
data.config_index); |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
1171 |
return -EINVAL; |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
1172 |
} |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
1173 |
|
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
1174 |
if (!(req = ec_slave_config_get_sdo_by_pos_const( |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
1175 |
sc, data.sdo_pos))) { |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
1176 |
up(&master->master_sem); |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
1177 |
EC_ERR("Invalid Sdo position!\n"); |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
1178 |
return -EINVAL; |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
1179 |
} |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
1180 |
|
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
1181 |
data.index = req->index; |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
1182 |
data.subindex = req->subindex; |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
1183 |
data.size = req->data_size; |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
1184 |
memcpy(&data.data, req->data, min((u32) data.size, (u32) 4)); |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
1185 |
|
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
1186 |
up(&master->master_sem); |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
1187 |
|
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
1188 |
if (copy_to_user((void __user *) arg, &data, sizeof(data))) |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
1189 |
return -EFAULT; |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
1190 |
|
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
1191 |
return 0; |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
1192 |
} |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
1193 |
|
922
fede1d8f5b71
Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
1194 |
/****************************************************************************** |
fede1d8f5b71
Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
1195 |
* File operations |
fede1d8f5b71
Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
1196 |
*****************************************************************************/ |
fede1d8f5b71
Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
1197 |
|
fede1d8f5b71
Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
1198 |
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
|
1199 |
{ |
fede1d8f5b71
Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
1200 |
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
|
1201 |
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
|
1202 |
|
fede1d8f5b71
Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
1203 |
filp->private_data = cdev; |
935
b954e9d91ea5
Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents:
922
diff
changeset
|
1204 |
if (master->debug_level) |
b954e9d91ea5
Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents:
922
diff
changeset
|
1205 |
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
|
1206 |
return 0; |
fede1d8f5b71
Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
1207 |
} |
fede1d8f5b71
Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
1208 |
|
fede1d8f5b71
Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
1209 |
/*****************************************************************************/ |
fede1d8f5b71
Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
1210 |
|
fede1d8f5b71
Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
1211 |
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
|
1212 |
{ |
935
b954e9d91ea5
Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents:
922
diff
changeset
|
1213 |
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
|
1214 |
ec_master_t *master = cdev->master; |
b954e9d91ea5
Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents:
922
diff
changeset
|
1215 |
|
b954e9d91ea5
Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents:
922
diff
changeset
|
1216 |
if (master->debug_level) |
b954e9d91ea5
Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents:
922
diff
changeset
|
1217 |
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
|
1218 |
return 0; |
fede1d8f5b71
Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
1219 |
} |
fede1d8f5b71
Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
1220 |
|
fede1d8f5b71
Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
1221 |
/*****************************************************************************/ |
fede1d8f5b71
Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
1222 |
|
935
b954e9d91ea5
Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents:
922
diff
changeset
|
1223 |
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
|
1224 |
{ |
b954e9d91ea5
Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents:
922
diff
changeset
|
1225 |
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
|
1226 |
ec_master_t *master = cdev->master; |
fede1d8f5b71
Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
1227 |
|
fede1d8f5b71
Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
1228 |
if (master->debug_level) |
981
5a2bd04c555c
Output decoded ioctl command number.
Florian Pose <fp@igh-essen.com>
parents:
980
diff
changeset
|
1229 |
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
|
1230 |
(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
|
1231 |
|
922
fede1d8f5b71
Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
1232 |
switch (cmd) { |
957
ed5ac2e83495
Replaced EC_IOCTL_SLAVE_COUNT with EC_IOCTL_MASTER; implemented
Florian Pose <fp@igh-essen.com>
parents:
956
diff
changeset
|
1233 |
case EC_IOCTL_MASTER: |
1079
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
1234 |
return ec_cdev_ioctl_master(master, arg); |
935
b954e9d91ea5
Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents:
922
diff
changeset
|
1235 |
case EC_IOCTL_SLAVE: |
1079
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
1236 |
return ec_cdev_ioctl_slave(master, arg); |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
1237 |
case EC_IOCTL_SLAVE_SYNC: |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
1238 |
return ec_cdev_ioctl_slave_sync(master, arg); |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
1239 |
case EC_IOCTL_SLAVE_SYNC_PDO: |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
1240 |
return ec_cdev_ioctl_slave_sync_pdo(master, arg); |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
1241 |
case EC_IOCTL_SLAVE_SYNC_PDO_ENTRY: |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
1242 |
return ec_cdev_ioctl_slave_sync_pdo_entry(master, arg); |
948
1cfab7161491
Implemented domain command.
Florian Pose <fp@igh-essen.com>
parents:
938
diff
changeset
|
1243 |
case EC_IOCTL_DOMAIN: |
1079
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
1244 |
return ec_cdev_ioctl_domain(master, arg); |
950
8b00e63fff90
'ethercat domain' shows domain contents and process data.
Florian Pose <fp@igh-essen.com>
parents:
949
diff
changeset
|
1245 |
case EC_IOCTL_DOMAIN_FMMU: |
1079
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
1246 |
return ec_cdev_ioctl_domain_fmmu(master, arg); |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
1247 |
case EC_IOCTL_DOMAIN_DATA: |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
1248 |
return ec_cdev_ioctl_domain_data(master, arg); |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
1249 |
case EC_IOCTL_MASTER_DEBUG: |
972 | 1250 |
if (!(filp->f_mode & FMODE_WRITE)) |
1251 |
return -EPERM; |
|
1079
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
1252 |
return ec_cdev_ioctl_master_debug(master, arg); |
960
36e460ffbb5e
Request slave state(s) with 'ethercat state'; removed sysfs state file.
Florian Pose <fp@igh-essen.com>
parents:
957
diff
changeset
|
1253 |
case EC_IOCTL_SLAVE_STATE: |
1079
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
1254 |
if (!(filp->f_mode & FMODE_WRITE)) |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
1255 |
return -EPERM; |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
1256 |
return ec_cdev_ioctl_slave_state(master, arg); |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
1257 |
case EC_IOCTL_SLAVE_SDO: |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
1258 |
return ec_cdev_ioctl_slave_sdo(master, arg); |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
1259 |
case EC_IOCTL_SLAVE_SDO_ENTRY: |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
1260 |
return ec_cdev_ioctl_slave_sdo_entry(master, arg); |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
1261 |
case EC_IOCTL_SLAVE_SDO_UPLOAD: |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
1262 |
return ec_cdev_ioctl_slave_sdo_upload(master, arg); |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
1263 |
case EC_IOCTL_SLAVE_SDO_DOWNLOAD: |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
1264 |
if (!(filp->f_mode & FMODE_WRITE)) |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
1265 |
return -EPERM; |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
1266 |
return ec_cdev_ioctl_slave_sdo_download(master, arg); |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
1267 |
case EC_IOCTL_SLAVE_SII_READ: |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
1268 |
return ec_cdev_ioctl_slave_sii_read(master, arg); |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
1269 |
case EC_IOCTL_SLAVE_SII_WRITE: |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
1270 |
if (!(filp->f_mode & FMODE_WRITE)) |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
1271 |
return -EPERM; |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
1272 |
return ec_cdev_ioctl_slave_sii_write(master, arg); |
990
4f223f3df05a
Bus configuration via 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents:
989
diff
changeset
|
1273 |
case EC_IOCTL_CONFIG: |
1079
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
1274 |
return ec_cdev_ioctl_config(master, arg); |
990
4f223f3df05a
Bus configuration via 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents:
989
diff
changeset
|
1275 |
case EC_IOCTL_CONFIG_PDO: |
1079
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
1276 |
return ec_cdev_ioctl_config_pdo(master, arg); |
990
4f223f3df05a
Bus configuration via 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents:
989
diff
changeset
|
1277 |
case EC_IOCTL_CONFIG_PDO_ENTRY: |
1079
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
1278 |
return ec_cdev_ioctl_config_pdo_entry(master, arg); |
990
4f223f3df05a
Bus configuration via 'ethercat config'.
Florian Pose <fp@igh-essen.com>
parents:
989
diff
changeset
|
1279 |
case EC_IOCTL_CONFIG_SDO: |
1079
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
1280 |
return ec_cdev_ioctl_config_sdo(master, arg); |
922
fede1d8f5b71
Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
1281 |
default: |
1079
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
1282 |
return -ENOTTY; |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
1283 |
} |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
1284 |
} |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
1285 |
|
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
1286 |
/*****************************************************************************/ |