master/module.c
branchstable-1.0
changeset 1624 9dc190591c0f
parent 1623 05622513f627
equal deleted inserted replaced
1623:05622513f627 1624:9dc190591c0f
    65                      " at " __DATE__ " " __TIME__
    65                      " at " __DATE__ " " __TIME__
    66 
    66 
    67 /*****************************************************************************/
    67 /*****************************************************************************/
    68 
    68 
    69 static int ec_master_count = 1; /**< parameter value, number of masters */
    69 static int ec_master_count = 1; /**< parameter value, number of masters */
    70 static int ec_eoe_devices = 0; /**< parameter value, number of EoE interf. */
    70 static int ec_eoeif_count = 0; /**< parameter value, number of EoE interf. */
    71 static struct list_head ec_masters; /**< list of masters */
    71 static struct list_head ec_masters; /**< list of masters */
    72 
    72 
    73 /*****************************************************************************/
    73 /*****************************************************************************/
    74 
    74 
    75 /** \cond */
    75 /** \cond */
    76 
    76 
    77 module_param(ec_master_count, int, S_IRUGO);
    77 module_param(ec_master_count, int, S_IRUGO);
    78 module_param(ec_eoe_devices, int, S_IRUGO);
    78 module_param(ec_eoeif_count, int, S_IRUGO);
    79 
    79 
    80 MODULE_AUTHOR("Florian Pose <fp@igh-essen.com>");
    80 MODULE_AUTHOR("Florian Pose <fp@igh-essen.com>");
    81 MODULE_DESCRIPTION("EtherCAT master driver module");
    81 MODULE_DESCRIPTION("EtherCAT master driver module");
    82 MODULE_LICENSE("GPL");
    82 MODULE_LICENSE("GPL");
    83 MODULE_VERSION(COMPILE_INFO);
    83 MODULE_VERSION(COMPILE_INFO);
    84 MODULE_PARM_DESC(ec_master_count, "number of EtherCAT masters to initialize");
    84 MODULE_PARM_DESC(ec_master_count, "number of EtherCAT masters to initialize");
    85 MODULE_PARM_DESC(ec_eoe_devices, "number of EoE devices per master");
    85 MODULE_PARM_DESC(ec_eoeif_count, "number of EoE interfaces per master");
    86 
    86 
    87 /** \endcond */
    87 /** \endcond */
    88 
    88 
    89 /*****************************************************************************/
    89 /*****************************************************************************/
    90 
    90 
   115               (ec_master_t *) kmalloc(sizeof(ec_master_t), GFP_KERNEL))) {
   115               (ec_master_t *) kmalloc(sizeof(ec_master_t), GFP_KERNEL))) {
   116             EC_ERR("Failed to allocate memory for EtherCAT master %i.\n", i);
   116             EC_ERR("Failed to allocate memory for EtherCAT master %i.\n", i);
   117             goto out_free;
   117             goto out_free;
   118         }
   118         }
   119 
   119 
   120         if (ec_master_init(master, i, ec_eoe_devices))
   120         if (ec_master_init(master, i, ec_eoeif_count))
   121             goto out_free;
   121             goto out_free;
   122 
   122 
   123         if (kobject_add(&master->kobj)) {
   123         if (kobject_add(&master->kobj)) {
   124             EC_ERR("Failed to add kobj.\n");
   124             EC_ERR("Failed to add kobj.\n");
   125             kobject_put(&master->kobj); // free master
   125             kobject_put(&master->kobj); // free master
   348 
   348 
   349 /**
   349 /**
   350    Starts the master associated with the device.
   350    Starts the master associated with the device.
   351    This function has to be called by the network device driver to tell the
   351    This function has to be called by the network device driver to tell the
   352    master that the device is ready to send and receive data. The master
   352    master that the device is ready to send and receive data. The master
   353    will enter the free-run mode then.
   353    will enter the idle mode then.
   354    \ingroup DeviceInterface
   354    \ingroup DeviceInterface
   355 */
   355 */
   356 
   356 
   357 int ecdev_start(unsigned int master_index /**< master index */)
   357 int ecdev_start(unsigned int master_index /**< master index */)
   358 {
   358 {
   362     if (ec_device_open(master->device)) {
   362     if (ec_device_open(master->device)) {
   363         EC_ERR("Failed to open device!\n");
   363         EC_ERR("Failed to open device!\n");
   364         return -1;
   364         return -1;
   365     }
   365     }
   366 
   366 
   367     ec_master_freerun_start(master);
   367     ec_master_idle_start(master);
   368     return 0;
   368     return 0;
   369 }
   369 }
   370 
   370 
   371 /*****************************************************************************/
   371 /*****************************************************************************/
   372 
   372 
   380 void ecdev_stop(unsigned int master_index /**< master index */)
   380 void ecdev_stop(unsigned int master_index /**< master index */)
   381 {
   381 {
   382     ec_master_t *master;
   382     ec_master_t *master;
   383     if (!(master = ec_find_master(master_index))) return;
   383     if (!(master = ec_find_master(master_index))) return;
   384 
   384 
   385     ec_master_freerun_stop(master);
   385     ec_master_idle_stop(master);
   386 
   386 
   387     if (ec_device_close(master->device))
   387     if (ec_device_close(master->device))
   388         EC_WARN("Failed to close device!\n");
   388         EC_WARN("Failed to close device!\n");
   389 }
   389 }
   390 
   390 
   422     if (!try_module_get(master->device->module)) {
   422     if (!try_module_get(master->device->module)) {
   423         EC_ERR("Failed to reserve device module!\n");
   423         EC_ERR("Failed to reserve device module!\n");
   424         goto out_release;
   424         goto out_release;
   425     }
   425     }
   426 
   426 
   427     ec_master_freerun_stop(master);
   427     ec_master_idle_stop(master);
   428     ec_master_reset(master);
   428     ec_master_reset(master);
   429     master->mode = EC_MASTER_MODE_RUNNING;
   429     master->mode = EC_MASTER_MODE_RUNNING;
   430 
   430 
   431     if (!master->device->link_state) EC_WARN("Link is DOWN.\n");
   431     if (!master->device->link_state) EC_WARN("Link is DOWN.\n");
   432 
   432 
   439     return master;
   439     return master;
   440 
   440 
   441  out_module_put:
   441  out_module_put:
   442     module_put(master->device->module);
   442     module_put(master->device->module);
   443     ec_master_reset(master);
   443     ec_master_reset(master);
   444     ec_master_freerun_start(master);
   444     ec_master_idle_start(master);
   445  out_release:
   445  out_release:
   446     master->reserved = 0;
   446     master->reserved = 0;
   447  out_return:
   447  out_return:
   448     EC_ERR("Failed requesting master %i.\n", master_index);
   448     EC_ERR("Failed requesting master %i.\n", master_index);
   449     return NULL;
   449     return NULL;
   464         EC_ERR("Master %i was never requested!\n", master->index);
   464         EC_ERR("Master %i was never requested!\n", master->index);
   465         return;
   465         return;
   466     }
   466     }
   467 
   467 
   468     ec_master_reset(master);
   468     ec_master_reset(master);
   469 
   469     ec_master_idle_start(master);
   470     master->mode = EC_MASTER_MODE_IDLE;
       
   471     ec_master_freerun_start(master);
       
   472 
   470 
   473     module_put(master->device->module);
   471     module_put(master->device->module);
   474     master->reserved = 0;
   472     master->reserved = 0;
   475 
   473 
   476     EC_INFO("Released master %i.\n", master->index);
   474     EC_INFO("Released master %i.\n", master->index);