15 #include <linux/module.h>
16 #include <linux/kernel.h>
17 #include <linux/slab.h>
36 static int sirdev_tx_complete_fsm(
struct sir_dev *
dev)
49 if (dev->
drv->chars_in_buffer)
50 bytes_left = dev->
drv->chars_in_buffer(dev);
58 if (dev->
speed > 115200)
59 delay = (bytes_left*8*10000) / (dev->
speed/100);
60 else if (dev->
speed > 0)
61 delay = (bytes_left*10*10000) / (dev->
speed/100);
71 delay = (delay+999) / 1000;
76 if (dev->
drv->wait_until_sent)
77 dev->
drv->wait_until_sent(dev);
85 IRDA_ERROR(
"%s - undefined state\n", __func__);
112 IRDA_DEBUG(2,
"%s(), <%ld>\n", __func__, jiffies);
115 IRDA_DEBUG(3,
"%s - state=0x%04x / substate=0x%04x\n",
118 next_state = fsm->
state;
185 ret = sirdev_tx_complete_fsm(dev);
191 if ((delay=ret) != 0)
215 if ((delay=ret) == 0) {
217 if (dev->
drv->set_speed)
218 dev->
drv->set_speed(dev, dev->
speed);
235 if ((delay=ret) == 0)
241 if (dev->
drv->set_speed)
242 dev->
drv->set_speed(dev, dev->
speed);
249 netif_wake_queue(dev->
netdev);
254 IRDA_ERROR(
"%s - undefined state\n", __func__);
262 netif_stop_queue(dev->
netdev);
264 netif_wake_queue(dev->
netdev);
289 IRDA_DEBUG(2,
"%s - state=0x%04x / param=%u\n", __func__,
290 initial_state, param);
294 IRDA_DEBUG(1,
"%s(), state machine busy!\n", __func__);
302 IRDA_ERROR(
"%s(), instance staled!\n", __func__);
307 netif_stop_queue(dev->
netdev);
310 fsm->
state = initial_state;
335 static int sirdev_is_receiving(
struct sir_dev *dev)
347 IRDA_DEBUG(3,
"%s : requesting dongle %d.\n", __func__, type);
349 err = sirdev_schedule_dongle_open(dev, type);
353 err = dev->
fsm.result;
371 spin_unlock_irqrestore(&dev->
tx_lock, flags);
382 IRDA_DEBUG(3,
"%s(), raw-tx started\n", __func__);
389 spin_unlock_irqrestore(&dev->
tx_lock, flags);
420 if (dev->
drv->set_dtr_rts)
421 ret = dev->
drv->set_dtr_rts(dev, dtr, rts);
442 IRDA_DEBUG(3,
"%s() - dev->tx_buff.len = %d\n",
460 dev->
netdev->stats.tx_errors++;
461 dev->
netdev->stats.tx_dropped++;
477 IRDA_DEBUG(3,
"%s(), raw-tx done\n", __func__);
494 IRDA_DEBUG(5,
"%s(), finished with frame!\n", __func__);
498 dev->
netdev->stats.tx_packets++;
504 IRDA_DEBUG(5,
"%s(), Changing speed!\n", __func__);
505 err = sirdev_schedule_speed(dev, dev->
new_speed);
510 IRDA_ERROR(
"%s - schedule speed change failed: %d\n",
512 netif_wake_queue(dev->
netdev);
522 netif_wake_queue(dev->
netdev);
526 spin_unlock_irqrestore(&dev->
tx_lock, flags);
537 if (!dev || !dev->
netdev) {
544 __func__, cp, count);
553 dev->
netdev->stats.rx_dropped++;
554 IRDA_DEBUG(0,
"%s; rx-drop: %zd\n", __func__, count);
590 struct sir_dev *dev = netdev_priv(ndev);
598 netif_stop_queue(ndev);
602 speed = irda_get_next_speed(skb);
603 if ((speed != dev->
speed) && (speed != -1)) {
605 err = sirdev_schedule_speed(dev, speed);
619 netif_start_queue(ndev);
636 if(spin_is_locked(&dev->
tx_lock)) {
637 IRDA_DEBUG(3,
"%s(), write not completed\n", __func__);
652 if (
unlikely(sirdev_is_receiving(dev)))
653 dev->
netdev->stats.collisions++;
667 dev->
netdev->stats.tx_errors++;
668 dev->
netdev->stats.tx_dropped++;
669 netif_wake_queue(ndev);
671 spin_unlock_irqrestore(&dev->
tx_lock, flags);
681 struct sir_dev *dev = netdev_priv(ndev);
686 IRDA_DEBUG(3,
"%s(), %s, (cmd=0x%X)\n", __func__, ndev->
name, cmd);
693 ret = sirdev_schedule_speed(dev, irq->ifr_baudrate);
703 ret = sirdev_schedule_dongle_open(dev, irq->ifr_dongle);
717 irq->ifr_receiving = sirdev_is_receiving(dev);
724 ret = sirdev_schedule_dtr_rts(dev, irq->ifr_dtr, irq->ifr_rts);
735 ret = sirdev_schedule_mode(dev, irq->ifr_mode);
750 #define SIRBUF_ALLOCSIZE 4269
752 static int sirdev_alloc_buffers(
struct sir_dev *dev)
783 static void sirdev_free_buffers(
struct sir_dev *dev)
791 static int sirdev_open(
struct net_device *ndev)
793 struct sir_dev *dev = netdev_priv(ndev);
800 if (!try_module_get(drv->
owner))
805 if (sirdev_alloc_buffers(dev))
808 if (!dev->
drv->start_dev || dev->
drv->start_dev(dev))
814 netif_start_queue(ndev);
819 netif_wake_queue(ndev);
827 if (dev->
drv->stop_dev)
828 dev->
drv->stop_dev(dev);
830 sirdev_free_buffers(dev);
832 module_put(drv->
owner);
836 static int sirdev_close(
struct net_device *ndev)
838 struct sir_dev *dev = netdev_priv(ndev);
843 netif_stop_queue(ndev);
861 sirdev_free_buffers(dev);
862 module_put(drv->
owner);
871 .ndo_start_xmit = sirdev_hard_xmit,
872 .ndo_open = sirdev_open,
873 .ndo_stop = sirdev_close,
874 .ndo_do_ioctl = sirdev_ioctl,
897 IRDA_ERROR(
"%s - Can't allocate memory for IrDA control block!\n", __func__);
900 dev = netdev_priv(ndev);
913 sema_init(&dev->
fsm.sem, 1);
922 IRDA_ERROR(
"%s(), register_netdev() failed!\n", __func__);
947 err = sirdev_schedule_dongle_close(dev);
951 sirdev_close(dev->
netdev);
968 static int __init sir_wq_init(
void)
976 static void __exit sir_wq_exit(
void)