50 /*****************************************************************************/ |
50 /*****************************************************************************/ |
51 |
51 |
52 int __init ec_init_module(void); |
52 int __init ec_init_module(void); |
53 void __exit ec_cleanup_module(void); |
53 void __exit ec_cleanup_module(void); |
54 |
54 |
55 ssize_t ec_show_attribute(struct kobject *, struct attribute *, char *); |
|
56 |
|
57 /*****************************************************************************/ |
|
58 |
|
59 /** \cond */ |
|
60 |
|
61 EC_SYSFS_READ_ATTR(info); |
|
62 |
|
63 static struct attribute *ec_def_attrs[] = { |
|
64 &attr_info, |
|
65 NULL, |
|
66 }; |
|
67 |
|
68 static struct sysfs_ops ec_sysfs_ops = { |
|
69 .show = &ec_show_attribute, |
|
70 .store = NULL |
|
71 }; |
|
72 |
|
73 static struct kobj_type ktype_ec_module = { |
|
74 .release = NULL, // this is ok, because the module can not be unloaded |
|
75 // if the reference count is greater zero. |
|
76 .sysfs_ops = &ec_sysfs_ops, |
|
77 .default_attrs = ec_def_attrs |
|
78 }; |
|
79 |
|
80 /** \endcond */ |
|
81 |
|
82 /*****************************************************************************/ |
55 /*****************************************************************************/ |
83 |
56 |
84 struct kobject ec_kobj; /**< kobject for master module */ |
57 struct kobject ec_kobj; /**< kobject for master module */ |
85 |
58 |
86 static char *main; /**< main devices parameter */ |
59 static char *main; /**< main devices parameter */ |
126 |
99 |
127 EC_INFO("Master driver %s\n", EC_MASTER_VERSION); |
100 EC_INFO("Master driver %s\n", EC_MASTER_VERSION); |
128 |
101 |
129 // init kobject and add it to the hierarchy |
102 // init kobject and add it to the hierarchy |
130 memset(&ec_kobj, 0x00, sizeof(struct kobject)); |
103 memset(&ec_kobj, 0x00, sizeof(struct kobject)); |
131 kobject_init(&ec_kobj); |
104 kobject_init(&ec_kobj); // no ktype |
132 ec_kobj.ktype = &ktype_ec_module; |
|
133 |
105 |
134 if (kobject_set_name(&ec_kobj, "ethercat")) { |
106 if (kobject_set_name(&ec_kobj, "ethercat")) { |
135 EC_ERR("Failed to set module kobject name.\n"); |
107 EC_ERR("Failed to set module kobject name.\n"); |
136 goto out_put; |
108 goto out_put; |
137 } |
109 } |
232 } |
204 } |
233 |
205 |
234 /*****************************************************************************/ |
206 /*****************************************************************************/ |
235 |
207 |
236 /** |
208 /** |
237 Formats module information for SysFS read access. |
|
238 \return number of bytes written |
|
239 */ |
|
240 |
|
241 ssize_t ec_info(char *buffer /**< memory to store data */) |
|
242 { |
|
243 off_t off = 0; |
|
244 |
|
245 off += sprintf(buffer + off, "\nVersion: %s", ec_master_version_str); |
|
246 off += sprintf(buffer + off, "\n"); |
|
247 |
|
248 return off; |
|
249 } |
|
250 |
|
251 /*****************************************************************************/ |
|
252 |
|
253 /** |
|
254 Formats attribute data for SysFS read access. |
|
255 \return number of bytes to read |
|
256 */ |
|
257 |
|
258 ssize_t ec_show_attribute(struct kobject *kobj, /**< kobject */ |
|
259 struct attribute *attr, /**< attribute */ |
|
260 char *buffer /**< memory to store data */ |
|
261 ) |
|
262 { |
|
263 if (attr == &attr_info) |
|
264 return ec_info(buffer); |
|
265 |
|
266 return 0; |
|
267 } |
|
268 |
|
269 |
|
270 /*****************************************************************************/ |
|
271 |
|
272 /** |
|
273 Gets a handle to a certain master. |
209 Gets a handle to a certain master. |
274 \returns pointer to master |
210 \returns pointer to master |
275 */ |
211 */ |
276 |
212 |
277 ec_master_t *ec_find_master(unsigned int master_index /**< master index */) |
213 ec_master_t *ec_find_master(unsigned int master_index /**< master index */) |
401 ec_pollfunc_t poll, /**< device poll function */ |
337 ec_pollfunc_t poll, /**< device poll function */ |
402 struct module *module /**< pointer to the module */ |
338 struct module *module /**< pointer to the module */ |
403 ) |
339 ) |
404 { |
340 { |
405 ec_master_t *master; |
341 ec_master_t *master; |
406 unsigned int i; |
342 char str[50]; // FIXME |
407 |
343 |
408 list_for_each_entry(master, &masters, list) { |
344 list_for_each_entry(master, &masters, list) { |
409 if (down_interruptible(&master->device_sem)) { |
345 if (down_interruptible(&master->device_sem)) { |
410 EC_ERR("Interrupted while waiting for device semaphore!\n"); |
346 EC_ERR("Interrupted while waiting for device semaphore!\n"); |
411 goto out_return; |
347 goto out_return; |
412 } |
348 } |
413 |
349 |
414 if (ec_device_id_check(master->main_device_id, net_dev, |
350 if (ec_device_id_check(master->main_device_id, net_dev, |
415 driver_name, device_index)) { |
351 driver_name, device_index)) { |
416 |
352 |
417 EC_INFO("Accepting device %s:%u (", driver_name, device_index); |
353 ec_device_id_print(master->main_device_id, str); |
418 for (i = 0; i < ETH_ALEN; i++) { |
354 EC_INFO("Accepting device %s for master %u.\n", |
419 printk("%02X", net_dev->dev_addr[i]); |
355 str, master->index); |
420 if (i < ETH_ALEN - 1) printk(":"); |
|
421 } |
|
422 printk(") for master %u.\n", master->index); |
|
423 |
356 |
424 if (master->device) { |
357 if (master->device) { |
425 EC_ERR("Master already has a device.\n"); |
358 EC_ERR("Master %u already has a device.\n", master->index); |
426 goto out_up; |
359 goto out_up; |
427 } |
360 } |
428 |
361 |
429 if (!(master->device = (ec_device_t *) |
362 if (!(master->device = (ec_device_t *) |
430 kmalloc(sizeof(ec_device_t), GFP_KERNEL))) { |
363 kmalloc(sizeof(ec_device_t), GFP_KERNEL))) { |
471 */ |
404 */ |
472 |
405 |
473 void ecdev_withdraw(ec_device_t *device /**< EtherCAT device */) |
406 void ecdev_withdraw(ec_device_t *device /**< EtherCAT device */) |
474 { |
407 { |
475 ec_master_t *master = device->master; |
408 ec_master_t *master = device->master; |
476 unsigned int i; |
409 char str[50]; // FIXME |
477 |
410 |
|
411 ec_device_id_print(master->main_device_id, str); |
|
412 |
|
413 EC_INFO("Master %u releasing main device %s.\n", master->index, str); |
|
414 |
478 down(&master->device_sem); |
415 down(&master->device_sem); |
479 |
|
480 EC_INFO("Master %u releasing device ", master->index); |
|
481 for (i = 0; i < ETH_ALEN; i++) { |
|
482 printk("%02X", device->dev->dev_addr[i]); |
|
483 if (i < ETH_ALEN - 1) printk(":"); |
|
484 } |
|
485 printk(".\n"); |
|
486 |
|
487 ec_device_clear(master->device); |
|
488 kfree(master->device); |
|
489 master->device = NULL; |
416 master->device = NULL; |
490 |
|
491 up(&master->device_sem); |
417 up(&master->device_sem); |
|
418 |
|
419 ec_device_clear(device); |
|
420 kfree(device); |
492 } |
421 } |
493 |
422 |
494 /*****************************************************************************/ |
423 /*****************************************************************************/ |
495 |
424 |
496 /** |
425 /** |