91 static int ec_ioctl_master( |
91 static int ec_ioctl_master( |
92 ec_master_t *master, /**< EtherCAT master. */ |
92 ec_master_t *master, /**< EtherCAT master. */ |
93 void *arg /**< Userspace address to store the results. */ |
93 void *arg /**< Userspace address to store the results. */ |
94 ) |
94 ) |
95 { |
95 { |
96 ec_ioctl_master_t data; |
96 ec_ioctl_master_t io; |
97 unsigned int i, j; |
97 unsigned int dev_idx, j; |
98 |
98 |
99 if (down_interruptible(&master->master_sem)) |
99 if (down_interruptible(&master->master_sem)) { |
100 return -EINTR; |
100 return -EINTR; |
101 |
101 } |
102 data.slave_count = master->slave_count; |
102 |
103 data.config_count = ec_master_config_count(master); |
103 io.slave_count = master->slave_count; |
104 data.domain_count = ec_master_domain_count(master); |
104 io.config_count = ec_master_config_count(master); |
|
105 io.domain_count = ec_master_domain_count(master); |
105 #ifdef EC_EOE |
106 #ifdef EC_EOE |
106 data.eoe_handler_count = ec_master_eoe_handler_count(master); |
107 io.eoe_handler_count = ec_master_eoe_handler_count(master); |
107 #endif |
108 #endif |
108 data.phase = (uint8_t) master->phase; |
109 io.phase = (uint8_t) master->phase; |
109 data.active = (uint8_t) master->active; |
110 io.active = (uint8_t) master->active; |
110 data.scan_busy = master->scan_busy; |
111 io.scan_busy = master->scan_busy; |
111 |
112 |
112 up(&master->master_sem); |
113 up(&master->master_sem); |
113 |
114 |
114 if (down_interruptible(&master->device_sem)) |
115 if (down_interruptible(&master->device_sem)) { |
115 return -EINTR; |
116 return -EINTR; |
116 |
117 } |
117 for (i = 0; i < EC_NUM_DEVICES; i++) { |
118 |
118 ec_device_t *device = &master->devices[i]; |
119 for (dev_idx = EC_DEVICE_MAIN; |
|
120 dev_idx < ec_master_num_devices(master); dev_idx++) { |
|
121 ec_device_t *device = &master->devices[dev_idx]; |
119 |
122 |
120 if (device->dev) { |
123 if (device->dev) { |
121 memcpy(data.devices[i].address, |
124 memcpy(io.devices[dev_idx].address, device->dev->dev_addr, |
122 device->dev->dev_addr, ETH_ALEN); |
125 ETH_ALEN); |
123 } else { |
126 } else { |
124 memcpy(data.devices[i].address, master->macs[i], ETH_ALEN); |
127 memcpy(io.devices[dev_idx].address, master->macs[dev_idx], |
|
128 ETH_ALEN); |
125 } |
129 } |
126 data.devices[i].attached = device->dev ? 1 : 0; |
130 io.devices[dev_idx].attached = device->dev ? 1 : 0; |
127 data.devices[i].link_state = device->link_state ? 1 : 0; |
131 io.devices[dev_idx].link_state = device->link_state ? 1 : 0; |
128 data.devices[i].tx_count = device->tx_count; |
132 io.devices[dev_idx].tx_count = device->tx_count; |
129 data.devices[i].rx_count = device->rx_count; |
133 io.devices[dev_idx].rx_count = device->rx_count; |
130 data.devices[i].tx_bytes = device->tx_bytes; |
134 io.devices[dev_idx].tx_bytes = device->tx_bytes; |
131 data.devices[i].rx_bytes = device->rx_bytes; |
135 io.devices[dev_idx].rx_bytes = device->rx_bytes; |
132 data.devices[i].tx_errors = device->tx_errors; |
136 io.devices[dev_idx].tx_errors = device->tx_errors; |
133 for (j = 0; j < EC_RATE_COUNT; j++) { |
137 for (j = 0; j < EC_RATE_COUNT; j++) { |
134 data.devices[i].tx_frame_rates[j] = |
138 io.devices[dev_idx].tx_frame_rates[j] = |
135 device->tx_frame_rates[j]; |
139 device->tx_frame_rates[j]; |
136 data.devices[i].rx_frame_rates[j] = |
140 io.devices[dev_idx].rx_frame_rates[j] = |
137 device->rx_frame_rates[j]; |
141 device->rx_frame_rates[j]; |
138 data.devices[i].tx_byte_rates[j] = |
142 io.devices[dev_idx].tx_byte_rates[j] = |
139 device->tx_byte_rates[j]; |
143 device->tx_byte_rates[j]; |
140 data.devices[i].rx_byte_rates[j] = |
144 io.devices[dev_idx].rx_byte_rates[j] = |
141 device->rx_byte_rates[j]; |
145 device->rx_byte_rates[j]; |
142 } |
146 } |
143 } |
147 } |
144 |
148 io.num_devices = ec_master_num_devices(master); |
145 data.tx_count = master->device_stats.tx_count; |
149 |
146 data.rx_count = master->device_stats.rx_count; |
150 io.tx_count = master->device_stats.tx_count; |
147 data.tx_bytes = master->device_stats.tx_bytes; |
151 io.rx_count = master->device_stats.rx_count; |
148 data.rx_bytes = master->device_stats.rx_bytes; |
152 io.tx_bytes = master->device_stats.tx_bytes; |
149 for (i = 0; i < EC_RATE_COUNT; i++) { |
153 io.rx_bytes = master->device_stats.rx_bytes; |
150 data.tx_frame_rates[i] = |
154 for (j = 0; j < EC_RATE_COUNT; j++) { |
151 master->device_stats.tx_frame_rates[i]; |
155 io.tx_frame_rates[j] = |
152 data.rx_frame_rates[i] = |
156 master->device_stats.tx_frame_rates[j]; |
153 master->device_stats.rx_frame_rates[i]; |
157 io.rx_frame_rates[j] = |
154 data.tx_byte_rates[i] = |
158 master->device_stats.rx_frame_rates[j]; |
155 master->device_stats.tx_byte_rates[i]; |
159 io.tx_byte_rates[j] = |
156 data.rx_byte_rates[i] = |
160 master->device_stats.tx_byte_rates[j]; |
157 master->device_stats.rx_byte_rates[i]; |
161 io.rx_byte_rates[j] = |
158 data.loss_rates[i] = |
162 master->device_stats.rx_byte_rates[j]; |
159 master->device_stats.loss_rates[i]; |
163 io.loss_rates[j] = |
|
164 master->device_stats.loss_rates[j]; |
160 } |
165 } |
161 |
166 |
162 up(&master->device_sem); |
167 up(&master->device_sem); |
163 |
168 |
164 data.app_time = master->app_time; |
169 io.app_time = master->app_time; |
165 data.ref_clock = |
170 io.ref_clock = |
166 master->dc_ref_clock ? master->dc_ref_clock->ring_position : 0xffff; |
171 master->dc_ref_clock ? master->dc_ref_clock->ring_position : 0xffff; |
167 |
172 |
168 if (copy_to_user((void __user *) arg, &data, sizeof(data))) |
173 if (copy_to_user((void __user *) arg, &io, sizeof(io))) { |
169 return -EFAULT; |
174 return -EFAULT; |
|
175 } |
170 |
176 |
171 return 0; |
177 return 0; |
172 } |
178 } |
173 |
179 |
174 /*****************************************************************************/ |
180 /*****************************************************************************/ |