# HG changeset patch # User Florian Pose # Date 1213697992 0 # Node ID a0759d0dded457f83ff0fdb26c9ff860d668c0ce # Parent 6672b86e7b100d679ff748adf82b58ec3cc6c5c4 Improved ecdev_offer(). diff -r 6672b86e7b10 -r a0759d0dded4 NEWS --- a/NEWS Tue Jun 17 09:44:46 2008 +0000 +++ b/NEWS Tue Jun 17 10:19:52 2008 +0000 @@ -49,6 +49,8 @@ - Exported ecrt_slave_config_sdo(), the generic Sdo configuration function. - Removed the bus_state and bus_tainted flags from ec_master_state_t. +* Device interface changes: + - Moved device output parameter of ecdev_offer() to return value. * Replaces the Sysfs interface with a new 'ethercat' command-line tool. See 'ethercat --help'. * Removed include/ecdb.h. diff -r 6672b86e7b10 -r a0759d0dded4 devices/8139too-2.6.13-ethercat.c --- a/devices/8139too-2.6.13-ethercat.c Tue Jun 17 09:44:46 2008 +0000 +++ b/devices/8139too-2.6.13-ethercat.c Tue Jun 17 10:19:52 2008 +0000 @@ -1069,10 +1069,7 @@ /* dev is fully set up and ready to use now */ // offer device to EtherCAT master module - if (ecdev_offer(dev, ec_poll, THIS_MODULE, &tp->ecdev)) { - printk(KERN_ERR PFX "Failed to offer device.\n"); - goto err_out; - } + tp->ecdev = ecdev_offer(dev, ec_poll, THIS_MODULE); if (!tp->ecdev) { DPRINTK("about to register device named %s (%p)...\n", dev->name, dev); diff -r 6672b86e7b10 -r a0759d0dded4 devices/8139too-2.6.17-ethercat.c --- a/devices/8139too-2.6.17-ethercat.c Tue Jun 17 09:44:46 2008 +0000 +++ b/devices/8139too-2.6.17-ethercat.c Tue Jun 17 10:19:52 2008 +0000 @@ -1073,10 +1073,7 @@ /* dev is fully set up and ready to use now */ // offer device to EtherCAT master module - if (ecdev_offer(dev, ec_poll, THIS_MODULE, &tp->ecdev)) { - printk(KERN_ERR PFX "Failed to offer device.\n"); - goto err_out; - } + tp->ecdev = ecdev_offer(dev, ec_poll, THIS_MODULE); if (!tp->ecdev) { DPRINTK("about to register device named %s (%p)...\n", dev->name, dev); diff -r 6672b86e7b10 -r a0759d0dded4 devices/8139too-2.6.18-ethercat.c --- a/devices/8139too-2.6.18-ethercat.c Tue Jun 17 09:44:46 2008 +0000 +++ b/devices/8139too-2.6.18-ethercat.c Tue Jun 17 10:19:52 2008 +0000 @@ -1074,10 +1074,7 @@ /* dev is fully set up and ready to use now */ // offer device to EtherCAT master module - if (ecdev_offer(dev, ec_poll, THIS_MODULE, &tp->ecdev)) { - printk(KERN_ERR PFX "Failed to offer device.\n"); - goto err_out; - } + tp->ecdev = ecdev_offer(dev, ec_poll, THIS_MODULE); if (!tp->ecdev) { DPRINTK("about to register device named %s (%p)...\n", dev->name, dev); diff -r 6672b86e7b10 -r a0759d0dded4 devices/8139too-2.6.19-ethercat.c --- a/devices/8139too-2.6.19-ethercat.c Tue Jun 17 09:44:46 2008 +0000 +++ b/devices/8139too-2.6.19-ethercat.c Tue Jun 17 10:19:52 2008 +0000 @@ -1073,10 +1073,7 @@ /* dev is fully set up and ready to use now */ // offer device to EtherCAT master module - if (ecdev_offer(dev, ec_poll, THIS_MODULE, &tp->ecdev)) { - printk(KERN_ERR PFX "Failed to offer device.\n"); - goto err_out; - } + tp->ecdev = ecdev_offer(dev, ec_poll, THIS_MODULE); if (!tp->ecdev) { DPRINTK("about to register device named %s (%p)...\n", dev->name, dev); diff -r 6672b86e7b10 -r a0759d0dded4 devices/8139too-2.6.22-ethercat.c --- a/devices/8139too-2.6.22-ethercat.c Tue Jun 17 09:44:46 2008 +0000 +++ b/devices/8139too-2.6.22-ethercat.c Tue Jun 17 10:19:52 2008 +0000 @@ -1073,10 +1073,7 @@ /* dev is fully set up and ready to use now */ // offer device to EtherCAT master module - if (ecdev_offer(dev, ec_poll, THIS_MODULE, &tp->ecdev)) { - printk(KERN_ERR PFX "Failed to offer device.\n"); - goto err_out; - } + tp->ecdev = ecdev_offer(dev, ec_poll, THIS_MODULE); if (!tp->ecdev) { DPRINTK("about to register device named %s (%p)...\n", dev->name, dev); diff -r 6672b86e7b10 -r a0759d0dded4 devices/8139too-2.6.23-ethercat.c --- a/devices/8139too-2.6.23-ethercat.c Tue Jun 17 09:44:46 2008 +0000 +++ b/devices/8139too-2.6.23-ethercat.c Tue Jun 17 10:19:52 2008 +0000 @@ -1070,10 +1070,7 @@ /* dev is fully set up and ready to use now */ // offer device to EtherCAT master module - if (ecdev_offer(dev, ec_poll, THIS_MODULE, &tp->ecdev)) { - printk(KERN_ERR PFX "Failed to offer device.\n"); - goto err_out; - } + tp->ecdev = ecdev_offer(dev, ec_poll, THIS_MODULE); if (!tp->ecdev) { DPRINTK("about to register device named %s (%p)...\n", dev->name, dev); diff -r 6672b86e7b10 -r a0759d0dded4 devices/8139too-2.6.24-ethercat.c --- a/devices/8139too-2.6.24-ethercat.c Tue Jun 17 09:44:46 2008 +0000 +++ b/devices/8139too-2.6.24-ethercat.c Tue Jun 17 10:19:52 2008 +0000 @@ -1066,10 +1066,7 @@ /* dev is fully set up and ready to use now */ // offer device to EtherCAT master module - if (ecdev_offer(dev, ec_poll, THIS_MODULE, &tp->ecdev)) { - printk(KERN_ERR PFX "Failed to offer device.\n"); - goto err_out; - } + tp->ecdev = ecdev_offer(dev, ec_poll, THIS_MODULE); if (!tp->ecdev) { DPRINTK("about to register device named %s (%p)...\n", dev->name, dev); diff -r 6672b86e7b10 -r a0759d0dded4 devices/e1000/e1000_main-2.6.13-ethercat.c --- a/devices/e1000/e1000_main-2.6.13-ethercat.c Tue Jun 17 09:44:46 2008 +0000 +++ b/devices/e1000/e1000_main-2.6.13-ethercat.c Tue Jun 17 10:19:52 2008 +0000 @@ -713,11 +713,7 @@ } // offer device to EtherCAT master module - if (ecdev_offer(netdev, ec_poll, THIS_MODULE, &adapter->ecdev)) { - DPRINTK(PROBE, ERR, "Failed to offer device.\n"); - goto err_register; - } - + adapter->ecdev = ecdev_offer(netdev, ec_poll, THIS_MODULE); if (adapter->ecdev) { if (ecdev_open(adapter->ecdev)) { ecdev_withdraw(adapter->ecdev); diff -r 6672b86e7b10 -r a0759d0dded4 devices/e1000/e1000_main-2.6.18-ethercat.c --- a/devices/e1000/e1000_main-2.6.18-ethercat.c Tue Jun 17 09:44:46 2008 +0000 +++ b/devices/e1000/e1000_main-2.6.18-ethercat.c Tue Jun 17 10:19:52 2008 +0000 @@ -973,11 +973,7 @@ e1000_get_hw_control(adapter); // offer device to EtherCAT master module - if (ecdev_offer(netdev, ec_poll, THIS_MODULE, &adapter->ecdev)) { - DPRINTK(PROBE, ERR, "Failed to offer device.\n"); - goto err_register; - } - + adapter->ecdev = ecdev_offer(netdev, ec_poll, THIS_MODULE); if (adapter->ecdev) { if (ecdev_open(adapter->ecdev)) { ecdev_withdraw(adapter->ecdev); diff -r 6672b86e7b10 -r a0759d0dded4 devices/e1000/e1000_main-2.6.20-ethercat.c --- a/devices/e1000/e1000_main-2.6.20-ethercat.c Tue Jun 17 09:44:46 2008 +0000 +++ b/devices/e1000/e1000_main-2.6.20-ethercat.c Tue Jun 17 10:19:52 2008 +0000 @@ -1180,11 +1180,7 @@ e1000_get_hw_control(adapter); // offer device to EtherCAT master module - if (ecdev_offer(netdev, ec_poll, THIS_MODULE, &adapter->ecdev)) { - DPRINTK(PROBE, ERR, "Failed to offer device.\n"); - goto err_register; - } - + adapter->ecdev = ecdev_offer(netdev, ec_poll, THIS_MODULE); if (adapter->ecdev) { if (ecdev_open(adapter->ecdev)) { ecdev_withdraw(adapter->ecdev); diff -r 6672b86e7b10 -r a0759d0dded4 devices/e1000/e1000_main-2.6.22-ethercat.c --- a/devices/e1000/e1000_main-2.6.22-ethercat.c Tue Jun 17 09:44:46 2008 +0000 +++ b/devices/e1000/e1000_main-2.6.22-ethercat.c Tue Jun 17 10:19:52 2008 +0000 @@ -1163,11 +1163,7 @@ e1000_get_hw_control(adapter); // offer device to EtherCAT master module - if (ecdev_offer(netdev, ec_poll, THIS_MODULE, &adapter->ecdev)) { - DPRINTK(PROBE, ERR, "Failed to offer device.\n"); - goto err_register; - } - + adapter->ecdev = ecdev_offer(netdev, ec_poll, THIS_MODULE); if (adapter->ecdev) { if (ecdev_open(adapter->ecdev)) { ecdev_withdraw(adapter->ecdev); diff -r 6672b86e7b10 -r a0759d0dded4 devices/e1000/e1000_main-2.6.24-ethercat.c --- a/devices/e1000/e1000_main-2.6.24-ethercat.c Tue Jun 17 09:44:46 2008 +0000 +++ b/devices/e1000/e1000_main-2.6.24-ethercat.c Tue Jun 17 10:19:52 2008 +0000 @@ -1167,11 +1167,7 @@ e1000_get_hw_control(adapter); // offer device to EtherCAT master module - if (ecdev_offer(netdev, ec_poll, THIS_MODULE, &adapter->ecdev)) { - DPRINTK(PROBE, ERR, "Failed to offer device.\n"); - goto err_register; - } - + adapter->ecdev = ecdev_offer(netdev, ec_poll, THIS_MODULE); if (adapter->ecdev) { if (ecdev_open(adapter->ecdev)) { ecdev_withdraw(adapter->ecdev); diff -r 6672b86e7b10 -r a0759d0dded4 devices/ecdev.h --- a/devices/ecdev.h Tue Jun 17 09:44:46 2008 +0000 +++ b/devices/ecdev.h Tue Jun 17 10:19:52 2008 +0000 @@ -56,27 +56,27 @@ struct ec_device; typedef struct ec_device ec_device_t; /**< \see ec_device */ -/** - Device poll function type. -*/ - +/** Device poll function type. + */ typedef void (*ec_pollfunc_t)(struct net_device *); -/*****************************************************************************/ -// Offering/withdrawal functions +/****************************************************************************** + * Offering/withdrawal functions + *****************************************************************************/ -int ecdev_offer(struct net_device *net_dev, ec_pollfunc_t poll, - struct module *module, ec_device_t **); +ec_device_t *ecdev_offer(struct net_device *net_dev, ec_pollfunc_t poll, + struct module *module); void ecdev_withdraw(ec_device_t *device); -/*****************************************************************************/ -// Device methods +/****************************************************************************** + * Device methods + *****************************************************************************/ int ecdev_open(ec_device_t *device); void ecdev_close(ec_device_t *device); void ecdev_receive(ec_device_t *device, const void *data, size_t size); void ecdev_set_link(ec_device_t *device, uint8_t state); -uint8_t ecdev_get_link(ec_device_t *device); +uint8_t ecdev_get_link(const ec_device_t *device); /*****************************************************************************/ diff -r 6672b86e7b10 -r a0759d0dded4 devices/forcedeth-2.6.17-ethercat.c --- a/devices/forcedeth-2.6.17-ethercat.c Tue Jun 17 09:44:46 2008 +0000 +++ b/devices/forcedeth-2.6.17-ethercat.c Tue Jun 17 10:19:52 2008 +0000 @@ -3336,18 +3336,13 @@ np->autoneg = 1; // offer device to EtherCAT master module - if (ecdev_offer(dev, ec_poll, THIS_MODULE, &np->ecdev)) { - printk(KERN_ERR "forcedeth: Failed to offer device.\n"); - goto out_freering; - } - + np->ecdev = ecdev_offer(dev, ec_poll, THIS_MODULE); if (np->ecdev) { if (ecdev_open(np->ecdev)) { ecdev_withdraw(np->ecdev); goto out_freering; } - } - else { + } else { err = register_netdev(dev); if (err) { printk(KERN_INFO "forcedeth: unable to register netdev: %d\n", err); diff -r 6672b86e7b10 -r a0759d0dded4 devices/forcedeth-2.6.19-ethercat.c --- a/devices/forcedeth-2.6.19-ethercat.c Tue Jun 17 09:44:46 2008 +0000 +++ b/devices/forcedeth-2.6.19-ethercat.c Tue Jun 17 10:19:52 2008 +0000 @@ -4628,18 +4628,13 @@ np->autoneg = 1; // offer device to EtherCAT master module - if (ecdev_offer(dev, ec_poll, THIS_MODULE, &np->ecdev)) { - printk(KERN_ERR "forcedeth: Failed to offer device.\n"); - goto out_error; - } - + np->ecdev = ecdev_offer(dev, ec_poll, THIS_MODULE); if (np->ecdev) { if (ecdev_open(np->ecdev)) { ecdev_withdraw(np->ecdev); goto out_error; } - } - else { + } else { err = register_netdev(dev); if (err) { printk(KERN_INFO "forcedeth: unable to register netdev: %d\n", err); diff -r 6672b86e7b10 -r a0759d0dded4 devices/r8169-2.6.22-ethercat.c --- a/devices/r8169-2.6.22-ethercat.c Tue Jun 17 09:44:46 2008 +0000 +++ b/devices/r8169-2.6.22-ethercat.c Tue Jun 17 10:19:52 2008 +0000 @@ -1733,10 +1733,7 @@ spin_lock_init(&tp->lock); // offer device to EtherCAT master module - if (ecdev_offer(dev, ec_poll, THIS_MODULE, &tp->ecdev)) { - printk(KERN_ERR PFX "Failed to offer device.\n"); - goto err_out_unmap_5; - } + tp->ecdev = ecdev_offer(dev, ec_poll, THIS_MODULE); if (!tp->ecdev) { printk(KERN_INFO "about to register device named %s (%p)...\n", dev->name, dev); diff -r 6672b86e7b10 -r a0759d0dded4 master/device.c --- a/master/device.c Tue Jun 17 09:44:46 2008 +0000 +++ b/master/device.c Tue Jun 17 10:19:52 2008 +0000 @@ -60,12 +60,12 @@ /*****************************************************************************/ -/** - Device constructor. - \return 0 in case of success, else < 0 -*/ - -int ec_device_init(ec_device_t *device, /**< EtherCAT device */ +/** Constructor. + * + * \return 0 in case of success, else < 0 + */ +int ec_device_init( + ec_device_t *device, /**< EtherCAT device */ ec_master_t *master /**< master owning the device */ ) { @@ -129,11 +129,11 @@ /*****************************************************************************/ -/** - EtherCAT device destuctor. -*/ - -void ec_device_clear(ec_device_t *device /**< EtherCAT device */) +/** Destuctor. + */ +void ec_device_clear( + ec_device_t *device /**< EtherCAT device */ + ) { unsigned int i; @@ -147,11 +147,10 @@ /*****************************************************************************/ -/** - Associate with net_device. -*/ - -void ec_device_attach(ec_device_t *device, /**< EtherCAT device */ +/** Associate with net_device. + */ +void ec_device_attach( + ec_device_t *device, /**< EtherCAT device */ struct net_device *net_dev, /**< net_device structure */ ec_pollfunc_t poll, /**< pointer to device's poll function */ struct module *module /**< the device's module */ @@ -175,11 +174,11 @@ /*****************************************************************************/ -/** - Disconnect from net_device. -*/ - -void ec_device_detach(ec_device_t *device /**< EtherCAT device */) +/** Disconnect from net_device. + */ +void ec_device_detach( + ec_device_t *device /**< EtherCAT device */ + ) { unsigned int i; @@ -196,12 +195,13 @@ /*****************************************************************************/ -/** - Opens the EtherCAT device. - \return 0 in case of success, else < 0 -*/ - -int ec_device_open(ec_device_t *device /**< EtherCAT device */) +/** Opens the EtherCAT device. + * + * \return 0 in case of success, else < 0 + */ +int ec_device_open( + ec_device_t *device /**< EtherCAT device */ + ) { if (!device->dev) { EC_ERR("No net_device to open!\n"); @@ -224,12 +224,13 @@ /*****************************************************************************/ -/** - Stops the EtherCAT device. - \return 0 in case of success, else < 0 -*/ - -int ec_device_close(ec_device_t *device /**< EtherCAT device */) +/** Stops the EtherCAT device. + * + * \return 0 in case of success, else < 0 + */ +int ec_device_close( + ec_device_t *device /**< EtherCAT device */ + ) { if (!device->dev) { EC_ERR("No device to close!\n"); @@ -248,12 +249,13 @@ /*****************************************************************************/ -/** - Returns a pointer to the device's transmit memory. - \return pointer to the TX socket buffer -*/ - -uint8_t *ec_device_tx_data(ec_device_t *device /**< EtherCAT device */) +/** Returns a pointer to the device's transmit memory. + * + * \return pointer to the TX socket buffer + */ +uint8_t *ec_device_tx_data( + ec_device_t *device /**< EtherCAT device */ + ) { /* cycle through socket buffers, because otherwise there is a race * condition, if multiple frames are sent and the DMA is not scheduled in @@ -265,15 +267,15 @@ /*****************************************************************************/ -/** - Sends the content of the transmit socket buffer. - Cuts the socket buffer content to the (now known) size, and calls the - start_xmit() function of the assigned net_device. -*/ - -void ec_device_send(ec_device_t *device, /**< EtherCAT device */ - size_t size /**< number of bytes to send */ - ) +/** Sends the content of the transmit socket buffer. + * + * Cuts the socket buffer content to the (now known) size, and calls the + * start_xmit() function of the assigned net_device. + */ +void ec_device_send( + ec_device_t *device, /**< EtherCAT device */ + size_t size /**< number of bytes to send */ + ) { struct sk_buff *skb = device->tx_skb[device->tx_ring_index]; @@ -304,10 +306,8 @@ /*****************************************************************************/ #ifdef EC_DEBUG_RING -/** - * Appends frame data to the debug ring. - */ - +/** Appends frame data to the debug ring. + */ void ec_device_debug_ring_append( ec_device_t *device, /**< EtherCAT device */ ec_debug_frame_dir_t dir, /**< direction */ @@ -333,10 +333,8 @@ /*****************************************************************************/ -/** - * Outputs the debug ring. - */ - +/** Outputs the debug ring. + */ void ec_device_debug_ring_print( const ec_device_t *device /**< EtherCAT device */ ) @@ -376,14 +374,15 @@ /*****************************************************************************/ -/** - Calls the poll function of the assigned net_device. - The master itself works without using interrupts. Therefore the processing - of received data and status changes of the network device has to be - done by the master calling the ISR "manually". -*/ - -void ec_device_poll(ec_device_t *device /**< EtherCAT device */) +/** Calls the poll function of the assigned net_device. + * + * The master itself works without using interrupts. Therefore the processing + * of received data and status changes of the network device has to be + * done by the master calling the ISR "manually". + */ +void ec_device_poll( + ec_device_t *device /**< EtherCAT device */ + ) { device->cycles_poll = get_cycles(); device->jiffies_poll = jiffies; @@ -397,17 +396,80 @@ * Device interface *****************************************************************************/ -/** - Accepts a received frame. - Forwards the received data to the master. The master will analyze the frame - and dispatch the received commands to the sending instances. - \ingroup DeviceInterface -*/ - -void ecdev_receive(ec_device_t *device, /**< EtherCAT device */ - const void *data, /**< pointer to received data */ - size_t size /**< number of bytes received */ - ) +/** Withdraws an EtherCAT device from the master. + * + * The device is disconnected from the master and all device ressources + * are freed. + * + * \attention Before calling this function, the ecdev_stop() function has + * to be called, to be sure that the master does not use the device + * any more. + * \ingroup DeviceInterface + */ +void ecdev_withdraw(ec_device_t *device /**< EtherCAT device */) +{ + ec_master_t *master = device->master; + char str[20]; + + ec_mac_print(device->dev->dev_addr, str); + EC_INFO("Master %u releasing main device %s.\n", master->index, str); + + down(&master->device_sem); + ec_device_detach(device); + up(&master->device_sem); +} + +/*****************************************************************************/ + +/** Opens the network device and makes the master enter IDLE mode. + * + * \return 0 on success, else < 0 + * \ingroup DeviceInterface + */ +int ecdev_open(ec_device_t *device /**< EtherCAT device */) +{ + if (ec_device_open(device)) { + EC_ERR("Failed to open device!\n"); + return -1; + } + + if (ec_master_enter_idle_mode(device->master)) { + EC_ERR("Failed to enter idle mode!\n"); + return -1; + } + + return 0; +} + +/*****************************************************************************/ + +/** Makes the master leave IDLE mode and closes the network device. + * + * \return 0 on success, else < 0 + * \ingroup DeviceInterface + */ +void ecdev_close(ec_device_t *device /**< EtherCAT device */) +{ + ec_master_leave_idle_mode(device->master); + + if (ec_device_close(device)) + EC_WARN("Failed to close device!\n"); +} + +/*****************************************************************************/ + +/** Accepts a received frame. + * + * Forwards the received data to the master. The master will analyze the frame + * and dispatch the received commands to the sending instances. + * + * \ingroup DeviceInterface + */ +void ecdev_receive( + ec_device_t *device, /**< EtherCAT device */ + const void *data, /**< pointer to received data */ + size_t size /**< number of bytes received */ + ) { const void *ec_data = data + ETH_HLEN; size_t ec_size = size - ETH_HLEN; @@ -430,19 +492,20 @@ /*****************************************************************************/ -/** - Sets a new link state. - If the device notifies the master about the link being down, the master - will not try to send frames using this device. - \ingroup DeviceInterface -*/ - -void ecdev_set_link(ec_device_t *device, /**< EtherCAT device */ +/** Sets a new link state. + * + * If the device notifies the master about the link being down, the master + * will not try to send frames using this device. + * + * \ingroup DeviceInterface + */ +void ecdev_set_link( + ec_device_t *device, /**< EtherCAT device */ uint8_t state /**< new link state */ ) { if (unlikely(!device)) { - EC_WARN("ecdev_link_state: no device!\n"); + EC_WARN("ecdev_set_link(): No device!\n"); return; } @@ -454,15 +517,16 @@ /*****************************************************************************/ -/** - Reads the link state. - \ingroup DeviceInterface -*/ - -uint8_t ecdev_get_link(ec_device_t *device /**< EtherCAT device */) +/** Reads the link state. + * + * \ingroup DeviceInterface + */ +uint8_t ecdev_get_link( + const ec_device_t *device /**< EtherCAT device */ + ) { if (unlikely(!device)) { - EC_WARN("ecdev_link_state: no device!\n"); + EC_WARN("ecdev_get_link(): No device!\n"); return 0; } @@ -473,6 +537,9 @@ /** \cond */ +EXPORT_SYMBOL(ecdev_withdraw); +EXPORT_SYMBOL(ecdev_open); +EXPORT_SYMBOL(ecdev_close); EXPORT_SYMBOL(ecdev_receive); EXPORT_SYMBOL(ecdev_get_link); EXPORT_SYMBOL(ecdev_set_link); diff -r 6672b86e7b10 -r a0759d0dded4 master/module.c --- a/master/module.c Tue Jun 17 09:44:46 2008 +0000 +++ b/master/module.c Tue Jun 17 10:19:52 2008 +0000 @@ -393,16 +393,15 @@ * The master decides, if it wants to use the device for EtherCAT operation, * or not. It is important, that the offered net_device is not used by the * kernel IP stack. If the master, accepted the offer, the address of the - * newly created EtherCAT device is written to the ecdev pointer, else the - * pointer is written to zero. - * - * \return 0 on success, else < 0 + * newly created EtherCAT device is returned, else \a NULL is returned. + * + * \return Pointer to device, if accepted, or NULL if declined. * \ingroup DeviceInterface */ -int ecdev_offer(struct net_device *net_dev, /**< net_device to offer */ +ec_device_t *ecdev_offer( + struct net_device *net_dev, /**< net_device to offer */ ec_pollfunc_t poll, /**< device poll function */ - struct module *module, /**< pointer to the module */ - ec_device_t **ecdev /**< pointer to store a device on success */ + struct module *module /**< pointer to the module */ ) { ec_master_t *master; @@ -428,8 +427,7 @@ up(&master->device_sem); sprintf(net_dev->name, "ec%u", master->index); - *ecdev = &master->main_device; // offer accepted - return 0; // no error + return &master->main_device; // offer accepted } else { up(&master->device_sem); @@ -441,70 +439,7 @@ } } - *ecdev = NULL; // offer declined - return 0; // no error -} - -/*****************************************************************************/ - -/** Withdraws an EtherCAT device from the master. - * - * The device is disconnected from the master and all device ressources - * are freed. - * - * \attention Before calling this function, the ecdev_stop() function has - * to be called, to be sure that the master does not use the device - * any more. - * \ingroup DeviceInterface - */ -void ecdev_withdraw(ec_device_t *device /**< EtherCAT device */) -{ - ec_master_t *master = device->master; - char str[20]; - - ec_mac_print(device->dev->dev_addr, str); - EC_INFO("Master %u releasing main device %s.\n", master->index, str); - - down(&master->device_sem); - ec_device_detach(device); - up(&master->device_sem); -} - -/*****************************************************************************/ - -/** Opens the network device and makes the master enter IDLE mode. - * - * \return 0 on success, else < 0 - * \ingroup DeviceInterface - */ -int ecdev_open(ec_device_t *device /**< EtherCAT device */) -{ - if (ec_device_open(device)) { - EC_ERR("Failed to open device!\n"); - return -1; - } - - if (ec_master_enter_idle_mode(device->master)) { - EC_ERR("Failed to enter idle mode!\n"); - return -1; - } - - return 0; -} - -/*****************************************************************************/ - -/** Makes the master leave IDLE mode and closes the network device. - * - * \return 0 on success, else < 0 - * \ingroup DeviceInterface - */ -void ecdev_close(ec_device_t *device /**< EtherCAT device */) -{ - ec_master_leave_idle_mode(device->master); - - if (ec_device_close(device)) - EC_WARN("Failed to close device!\n"); + return NULL; // offer declined } /****************************************************************************** @@ -598,9 +533,6 @@ module_exit(ec_cleanup_module); EXPORT_SYMBOL(ecdev_offer); -EXPORT_SYMBOL(ecdev_withdraw); -EXPORT_SYMBOL(ecdev_open); -EXPORT_SYMBOL(ecdev_close); EXPORT_SYMBOL(ecrt_request_master); EXPORT_SYMBOL(ecrt_release_master);