Removed kobject from master and module. Sysfs is gone!
authorFlorian Pose <fp@igh-essen.com>
Thu, 12 Jun 2008 08:12:02 +0000
changeset 997 652180478e95
parent 996 1c7033e7c1b9
child 998 05a24788f3b2
Removed kobject from master and module. Sysfs is gone!
master/master.c
master/master.h
master/module.c
--- a/master/master.c	Thu Jun 12 07:47:26 2008 +0000
+++ b/master/master.c	Thu Jun 12 08:12:02 2008 +0000
@@ -67,23 +67,12 @@
 
 /*****************************************************************************/
 
-/** \cond */
-
-static struct kobj_type ktype_ec_master = {
-    .release = NULL,
-};
-
-/** \endcond */
-
-/*****************************************************************************/
-
 /**
    Master constructor.
    \return 0 in case of success, else < 0
 */
 
 int ec_master_init(ec_master_t *master, /**< EtherCAT master */
-        struct kobject *module_kobj, /**< kobject of the master module */
         unsigned int index, /**< master index */
         const uint8_t *main_mac, /**< MAC address of main device */
         const uint8_t *backup_mac, /**< MAC address of backup device */
@@ -160,13 +149,9 @@
     init_MUTEX(&master->sdo_sem);
     init_waitqueue_head(&master->sdo_queue);
 
-    // init character device
-    if (ec_cdev_init(&master->cdev, master, device_number))
-        goto out_return;
-
     // init devices
     if (ec_device_init(&master->main_device, master))
-        goto out_cdev;
+        goto out_return;
 
     if (ec_device_init(&master->backup_device, master))
         goto out_clear_main;
@@ -182,46 +167,27 @@
     // create state machine object
     ec_fsm_master_init(&master->fsm, master, &master->fsm_datagram);
 
-    // init kobject and add it to the hierarchy
-    memset(&master->kobj, 0x00, sizeof(struct kobject));
-    kobject_init(&master->kobj);
-    master->kobj.ktype = &ktype_ec_master;
-    master->kobj.parent = module_kobj;
-    
-    if (kobject_set_name(&master->kobj, "master%u", index)) {
-        EC_ERR("Failed to set master kobject name.\n");
-        kobject_put(&master->kobj);
+    // init character device
+    if (ec_cdev_init(&master->cdev, master, device_number))
         goto out_clear_fsm;
-    }
-    
-    if (kobject_add(&master->kobj)) {
-        EC_ERR("Failed to add master kobject.\n");
-        kobject_put(&master->kobj);
-        goto out_clear_fsm;
-    }
 
     return 0;
 
 out_clear_fsm:
     ec_fsm_master_clear(&master->fsm);
+    ec_datagram_clear(&master->fsm_datagram);
 out_clear_backup:
     ec_device_clear(&master->backup_device);
 out_clear_main:
     ec_device_clear(&master->main_device);
-out_cdev:
-    ec_cdev_clear(&master->cdev);
 out_return:
     return -1;
 }
 
 /*****************************************************************************/
 
-/**
-   Clear and free master.
-   This method is called by the kobject,
-   once there are no more references to it.
+/** Destructor.
 */
-
 void ec_master_clear(
         ec_master_t *master /**< EtherCAT master */
         )
@@ -237,10 +203,6 @@
     ec_datagram_clear(&master->fsm_datagram);
     ec_device_clear(&master->backup_device);
     ec_device_clear(&master->main_device);
-
-    // destroy self
-    kobject_del(&master->kobj);
-    kobject_put(&master->kobj);
 }
 
 /*****************************************************************************/
@@ -279,7 +241,7 @@
 
 /*****************************************************************************/
 
-/** Destroy all slaves.
+/** Clear all slaves.
  */
 void ec_master_clear_slaves(ec_master_t *master)
 {
@@ -296,10 +258,8 @@
 
 /*****************************************************************************/
 
-/**
-   Destroy all domains.
-*/
-
+/** Clear all domains.
+ */
 void ec_master_clear_domains(ec_master_t *master)
 {
     ec_domain_t *domain, *next;
@@ -313,10 +273,8 @@
 
 /*****************************************************************************/
 
-/**
-   Internal locking callback.
-*/
-
+/** Internal locking callback.
+ */
 int ec_master_request_cb(void *master /**< callback data */)
 {
     spin_lock(&((ec_master_t *) master)->internal_lock);
@@ -325,10 +283,8 @@
 
 /*****************************************************************************/
 
-/**
-   Internal unlocking callback.
-*/
-
+/** Internal unlocking callback.
+ */
 void ec_master_release_cb(void *master /**< callback data */)
 {
     spin_unlock(&((ec_master_t *) master)->internal_lock);
@@ -336,10 +292,8 @@
 
 /*****************************************************************************/
 
-/**
- * Starts the master thread.
- */
-
+/** Starts the master thread.
+ */
 int ec_master_thread_start(
         ec_master_t *master, /**< EtherCAT master */
         int (*thread_func)(ec_master_t *) /**< thread function to start */
@@ -357,10 +311,8 @@
 
 /*****************************************************************************/
 
-/**
- * Stops the master thread.
- */
-
+/** Stops the master thread.
+ */
 void ec_master_thread_stop(ec_master_t *master /**< EtherCAT master */)
 {
     if (!master->thread_id) {
@@ -382,10 +334,8 @@
 
 /*****************************************************************************/
 
-/**
- * Transition function from ORPHANED to IDLE mode.
- */
-
+/** Transition function from ORPHANED to IDLE mode.
+ */
 int ec_master_enter_idle_mode(ec_master_t *master /**< EtherCAT master */)
 {
     master->request_cb = ec_master_request_cb;
@@ -403,10 +353,8 @@
 
 /*****************************************************************************/
 
-/**
- * Transition function from IDLE to ORPHANED mode.
- */
-
+/** Transition function from IDLE to ORPHANED mode.
+ */
 void ec_master_leave_idle_mode(ec_master_t *master /**< EtherCAT master */)
 {
     master->mode = EC_MASTER_MODE_ORPHANED;
@@ -420,10 +368,8 @@
 
 /*****************************************************************************/
 
-/**
- * Transition function from IDLE to OPERATION mode.
- */
-
+/** Transition function from IDLE to OPERATION mode.
+ */
 int ec_master_enter_operation_mode(ec_master_t *master /**< EtherCAT master */)
 {
     ec_slave_t *slave;
@@ -495,10 +441,8 @@
 
 /*****************************************************************************/
 
-/**
- * Transition function from OPERATION to IDLE mode.
- */
-
+/** Transition function from OPERATION to IDLE mode.
+ */
 void ec_master_leave_operation_mode(ec_master_t *master
                                     /**< EtherCAT master */)
 {
@@ -545,10 +489,8 @@
 
 /*****************************************************************************/
 
-/**
-   Places a datagram in the datagram queue.
-*/
-
+/** Places a datagram in the datagram queue.
+ */
 void ec_master_queue_datagram(ec_master_t *master, /**< EtherCAT master */
                               ec_datagram_t *datagram /**< datagram */
                               )
@@ -572,11 +514,10 @@
 
 /*****************************************************************************/
 
-/**
-   Sends the datagrams in the queue.
-   \return 0 in case of success, else < 0
-*/
-
+/** Sends the datagrams in the queue.
+ *
+ * \return 0 in case of success, else < 0
+ */
 void ec_master_send_datagrams(ec_master_t *master /**< EtherCAT master */)
 {
     ec_datagram_t *datagram, *next;
@@ -686,12 +627,12 @@
 
 /*****************************************************************************/
 
-/**
-   Processes a received frame.
-   This function is called by the network driver for every received frame.
-   \return 0 in case of success, else < 0
-*/
-
+/** Processes a received frame.
+ *
+ * This function is called by the network driver for every received frame.
+ * 
+ * \return 0 in case of success, else < 0
+ */
 void ec_master_receive_datagrams(ec_master_t *master, /**< EtherCAT master */
                                  const uint8_t *frame_data, /**< frame data */
                                  size_t size /**< size of the received data */
@@ -786,12 +727,11 @@
 
 /*****************************************************************************/
 
-/**
-   Output statistics in cyclic mode.
-   This function outputs statistical data on demand, but not more often than
-   necessary. The output happens at most once a second.
-*/
-
+/** Output statistics in cyclic mode.
+ *
+ * This function outputs statistical data on demand, but not more often than
+ * necessary. The output happens at most once a second.
+ */
 void ec_master_output_stats(ec_master_t *master /**< EtherCAT master */)
 {
     if (unlikely(jiffies - master->stats.output_jiffies >= HZ)) {
@@ -817,10 +757,8 @@
 
 /*****************************************************************************/
 
-/**
- * Master kernel thread function for IDLE mode.
- */
-
+/** Master kernel thread function for IDLE mode.
+ */
 static int ec_master_idle_thread(ec_master_t *master)
 {
     cycles_t cycles_start, cycles_end;
@@ -875,10 +813,8 @@
 
 /*****************************************************************************/
 
-/**
- * Master kernel thread function for IDLE mode.
- */
-
+/** Master kernel thread function for IDLE mode.
+ */
 static int ec_master_operation_thread(ec_master_t *master)
 {
     cycles_t cycles_start, cycles_end;
@@ -929,10 +865,8 @@
 /*****************************************************************************/
 
 #ifdef EC_EOE
-/**
-   Starts Ethernet-over-EtherCAT processing on demand.
-*/
-
+/** Starts Ethernet-over-EtherCAT processing on demand.
+ */
 void ec_master_eoe_start(ec_master_t *master /**< EtherCAT master */)
 {
     if (master->eoe_running) {
@@ -958,10 +892,8 @@
 
 /*****************************************************************************/
 
-/**
-   Stops the Ethernet-over-EtherCAT processing.
-*/
-
+/** Stops the Ethernet-over-EtherCAT processing.
+ */
 void ec_master_eoe_stop(ec_master_t *master /**< EtherCAT master */)
 {
     if (!master->eoe_running) return;
@@ -974,10 +906,8 @@
 
 /*****************************************************************************/
 
-/**
-   Does the Ethernet-over-EtherCAT processing.
-*/
-
+/** Does the Ethernet-over-EtherCAT processing.
+ */
 void ec_master_eoe_run(unsigned long data /**< master pointer */)
 {
     ec_master_t *master = (ec_master_t *) data;
--- a/master/master.h	Thu Jun 12 07:47:26 2008 +0000
+++ b/master/master.h	Thu Jun 12 08:12:02 2008 +0000
@@ -42,7 +42,6 @@
 #define __EC_MASTER_H__
 
 #include <linux/list.h>
-#include <linux/sysfs.h>
 #include <linux/timer.h>
 #include <linux/wait.h>
 #include <asm/semaphore.h>
@@ -81,7 +80,6 @@
  * Manages slaves, domains and IO.
  */
 struct ec_master {
-    struct kobject kobj; /**< kobject */
     unsigned int index; /**< master index */
     unsigned int reserved; /**< non-zero, if the master is reserved for RT */
 
@@ -168,8 +166,8 @@
 /*****************************************************************************/
 
 // master creation/deletion
-int ec_master_init(ec_master_t *, struct kobject *, unsigned int,
-        const uint8_t *, const uint8_t *, dev_t);
+int ec_master_init(ec_master_t *, unsigned int, const uint8_t *,
+        const uint8_t *, dev_t);
 void ec_master_clear(ec_master_t *);
 
 // mode transitions
--- a/master/module.c	Thu Jun 12 07:47:26 2008 +0000
+++ b/master/module.c	Thu Jun 12 08:12:02 2008 +0000
@@ -38,9 +38,6 @@
 /*****************************************************************************/
 
 #include <linux/module.h>
-#include <linux/kernel.h>
-#include <linux/init.h>
-#include <linux/fs.h>
 
 #include "globals.h"
 #include "master.h"
@@ -59,8 +56,6 @@
 
 /*****************************************************************************/
 
-struct kobject kobj; /**< kobject for master module. */
-
 static char *main_devices[MAX_MASTERS]; /**< Main devices parameter. */
 static char *backup_devices[MAX_MASTERS]; /**< Backup devices parameter. */
 
@@ -106,26 +101,12 @@
 
     init_MUTEX(&master_sem);
 
-    // init kobject and add it to the hierarchy
-    memset(&kobj, 0x00, sizeof(struct kobject));
-    kobject_init(&kobj); // no ktype
-    
-    if (kobject_set_name(&kobj, "ethercat")) {
-        EC_ERR("Failed to set module kobject name.\n");
-        ret = -ENOMEM;
-        goto out_put;
-    }
-    
-    if (kobject_add(&kobj)) {
-        EC_ERR("Failed to add module kobject.\n");
-        ret = -EEXIST;
-        goto out_put;
-    }
-    
-    if (alloc_chrdev_region(&device_number, 0, master_count, "EtherCAT")) {
-        EC_ERR("Failed to obtain device number(s)!\n");
-        ret = -EBUSY;
-        goto out_del;
+    if (master_count) {
+        if (alloc_chrdev_region(&device_number, 0, master_count, "EtherCAT")) {
+            EC_ERR("Failed to obtain device number(s)!\n");
+            ret = -EBUSY;
+            goto out_return;
+        }
     }
 
     // zero MAC addresses
@@ -154,9 +135,9 @@
     }
     
     for (i = 0; i < master_count; i++) {
-        if (ec_master_init(&masters[i], &kobj, i, macs[i][0], macs[i][1],
-                device_number)) {
-            ret = -EIO;
+        if (ec_master_init(&masters[i], i, macs[i][0], macs[i][1],
+                    device_number)) {
+            ret = -ENOMEM;
             goto out_free_masters;
         }
     }
@@ -166,14 +147,12 @@
     return ret;
 
 out_free_masters:
-    for (i--; i >= 0; i--) ec_master_clear(&masters[i]);
+    for (i--; i >= 0; i--)
+        ec_master_clear(&masters[i]);
     kfree(masters);
 out_cdev:
     unregister_chrdev_region(device_number, master_count);
-out_del:
-    kobject_del(&kobj);
-out_put:
-    kobject_put(&kobj);
+out_return:
     return ret;
 }
 
@@ -190,14 +169,11 @@
     for (i = 0; i < master_count; i++) {
         ec_master_clear(&masters[i]);
     }
-    if (master_count)
+    if (master_count) {
         kfree(masters);
-
-    unregister_chrdev_region(device_number, master_count);
-    
-    kobject_del(&kobj);
-    kobject_put(&kobj);
-
+        unregister_chrdev_region(device_number, master_count);
+    }
+    
     EC_INFO("Master module cleaned up.\n");
 }
 
@@ -594,7 +570,7 @@
 {
     EC_INFO("Releasing master %u...\n", master->index);
 
-    if (master->mode != EC_MASTER_MODE_OPERATION) {
+    if (!master->reserved) {
         EC_WARN("Master %u was was not requested!\n", master->index);
         return;
     }
@@ -625,6 +601,7 @@
 EXPORT_SYMBOL(ecdev_withdraw);
 EXPORT_SYMBOL(ecdev_open);
 EXPORT_SYMBOL(ecdev_close);
+
 EXPORT_SYMBOL(ecrt_request_master);
 EXPORT_SYMBOL(ecrt_release_master);
 EXPORT_SYMBOL(ecrt_version_magic);