timerdev.c revision 6bff338bb60cb97f4ad06aa20f5c8e547eb1bc7a
11b2b03f8e514e4f68e293846ba511a948b80243cKarsten Keil/* 21b2b03f8e514e4f68e293846ba511a948b80243cKarsten Keil * 31b2b03f8e514e4f68e293846ba511a948b80243cKarsten Keil * general timer device for using in ISDN stacks 41b2b03f8e514e4f68e293846ba511a948b80243cKarsten Keil * 51b2b03f8e514e4f68e293846ba511a948b80243cKarsten Keil * Author Karsten Keil <kkeil@novell.com> 61b2b03f8e514e4f68e293846ba511a948b80243cKarsten Keil * 71b2b03f8e514e4f68e293846ba511a948b80243cKarsten Keil * Copyright 2008 by Karsten Keil <kkeil@novell.com> 81b2b03f8e514e4f68e293846ba511a948b80243cKarsten Keil * 91b2b03f8e514e4f68e293846ba511a948b80243cKarsten Keil * This program is free software; you can redistribute it and/or modify 101b2b03f8e514e4f68e293846ba511a948b80243cKarsten Keil * it under the terms of the GNU General Public License version 2 as 111b2b03f8e514e4f68e293846ba511a948b80243cKarsten Keil * published by the Free Software Foundation. 121b2b03f8e514e4f68e293846ba511a948b80243cKarsten Keil * 131b2b03f8e514e4f68e293846ba511a948b80243cKarsten Keil * This program is distributed in the hope that it will be useful, 141b2b03f8e514e4f68e293846ba511a948b80243cKarsten Keil * but WITHOUT ANY WARRANTY; without even the implied warranty of 151b2b03f8e514e4f68e293846ba511a948b80243cKarsten Keil * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 161b2b03f8e514e4f68e293846ba511a948b80243cKarsten Keil * GNU General Public License for more details. 171b2b03f8e514e4f68e293846ba511a948b80243cKarsten Keil * 181b2b03f8e514e4f68e293846ba511a948b80243cKarsten Keil */ 191b2b03f8e514e4f68e293846ba511a948b80243cKarsten Keil 201b2b03f8e514e4f68e293846ba511a948b80243cKarsten Keil#include <linux/poll.h> 211b2b03f8e514e4f68e293846ba511a948b80243cKarsten Keil#include <linux/vmalloc.h> 221b2b03f8e514e4f68e293846ba511a948b80243cKarsten Keil#include <linux/timer.h> 231b2b03f8e514e4f68e293846ba511a948b80243cKarsten Keil#include <linux/miscdevice.h> 241b2b03f8e514e4f68e293846ba511a948b80243cKarsten Keil#include <linux/module.h> 251b2b03f8e514e4f68e293846ba511a948b80243cKarsten Keil#include <linux/mISDNif.h> 261b2b03f8e514e4f68e293846ba511a948b80243cKarsten Keil 271b2b03f8e514e4f68e293846ba511a948b80243cKarsten Keilstatic int *debug; 281b2b03f8e514e4f68e293846ba511a948b80243cKarsten Keil 291b2b03f8e514e4f68e293846ba511a948b80243cKarsten Keil 301b2b03f8e514e4f68e293846ba511a948b80243cKarsten Keilstruct mISDNtimerdev { 311b2b03f8e514e4f68e293846ba511a948b80243cKarsten Keil int next_id; 321b2b03f8e514e4f68e293846ba511a948b80243cKarsten Keil struct list_head pending; 331b2b03f8e514e4f68e293846ba511a948b80243cKarsten Keil struct list_head expired; 341b2b03f8e514e4f68e293846ba511a948b80243cKarsten Keil wait_queue_head_t wait; 351b2b03f8e514e4f68e293846ba511a948b80243cKarsten Keil u_int work; 361b2b03f8e514e4f68e293846ba511a948b80243cKarsten Keil spinlock_t lock; /* protect lists */ 371b2b03f8e514e4f68e293846ba511a948b80243cKarsten Keil}; 381b2b03f8e514e4f68e293846ba511a948b80243cKarsten Keil 391b2b03f8e514e4f68e293846ba511a948b80243cKarsten Keilstruct mISDNtimer { 401b2b03f8e514e4f68e293846ba511a948b80243cKarsten Keil struct list_head list; 411b2b03f8e514e4f68e293846ba511a948b80243cKarsten Keil struct mISDNtimerdev *dev; 421b2b03f8e514e4f68e293846ba511a948b80243cKarsten Keil struct timer_list tl; 431b2b03f8e514e4f68e293846ba511a948b80243cKarsten Keil int id; 441b2b03f8e514e4f68e293846ba511a948b80243cKarsten Keil}; 451b2b03f8e514e4f68e293846ba511a948b80243cKarsten Keil 461b2b03f8e514e4f68e293846ba511a948b80243cKarsten Keilstatic int 471b2b03f8e514e4f68e293846ba511a948b80243cKarsten KeilmISDN_open(struct inode *ino, struct file *filep) 481b2b03f8e514e4f68e293846ba511a948b80243cKarsten Keil{ 491b2b03f8e514e4f68e293846ba511a948b80243cKarsten Keil struct mISDNtimerdev *dev; 501b2b03f8e514e4f68e293846ba511a948b80243cKarsten Keil 511b2b03f8e514e4f68e293846ba511a948b80243cKarsten Keil if (*debug & DEBUG_TIMER) 521b2b03f8e514e4f68e293846ba511a948b80243cKarsten Keil printk(KERN_DEBUG "%s(%p,%p)\n", __func__, ino, filep); 531b2b03f8e514e4f68e293846ba511a948b80243cKarsten Keil dev = kmalloc(sizeof(struct mISDNtimerdev) , GFP_KERNEL); 541b2b03f8e514e4f68e293846ba511a948b80243cKarsten Keil if (!dev) 551b2b03f8e514e4f68e293846ba511a948b80243cKarsten Keil return -ENOMEM; 561b2b03f8e514e4f68e293846ba511a948b80243cKarsten Keil dev->next_id = 1; 571b2b03f8e514e4f68e293846ba511a948b80243cKarsten Keil INIT_LIST_HEAD(&dev->pending); 581b2b03f8e514e4f68e293846ba511a948b80243cKarsten Keil INIT_LIST_HEAD(&dev->expired); 591b2b03f8e514e4f68e293846ba511a948b80243cKarsten Keil spin_lock_init(&dev->lock); 601b2b03f8e514e4f68e293846ba511a948b80243cKarsten Keil dev->work = 0; 611b2b03f8e514e4f68e293846ba511a948b80243cKarsten Keil init_waitqueue_head(&dev->wait); 621b2b03f8e514e4f68e293846ba511a948b80243cKarsten Keil filep->private_data = dev; 631b2b03f8e514e4f68e293846ba511a948b80243cKarsten Keil __module_get(THIS_MODULE); 646bff338bb60cb97f4ad06aa20f5c8e547eb1bc7aAndrew Morton return nonseekable_open(ino, filep); 651b2b03f8e514e4f68e293846ba511a948b80243cKarsten Keil} 661b2b03f8e514e4f68e293846ba511a948b80243cKarsten Keil 671b2b03f8e514e4f68e293846ba511a948b80243cKarsten Keilstatic int 681b2b03f8e514e4f68e293846ba511a948b80243cKarsten KeilmISDN_close(struct inode *ino, struct file *filep) 691b2b03f8e514e4f68e293846ba511a948b80243cKarsten Keil{ 701b2b03f8e514e4f68e293846ba511a948b80243cKarsten Keil struct mISDNtimerdev *dev = filep->private_data; 711b2b03f8e514e4f68e293846ba511a948b80243cKarsten Keil struct mISDNtimer *timer, *next; 721b2b03f8e514e4f68e293846ba511a948b80243cKarsten Keil 731b2b03f8e514e4f68e293846ba511a948b80243cKarsten Keil if (*debug & DEBUG_TIMER) 741b2b03f8e514e4f68e293846ba511a948b80243cKarsten Keil printk(KERN_DEBUG "%s(%p,%p)\n", __func__, ino, filep); 751b2b03f8e514e4f68e293846ba511a948b80243cKarsten Keil list_for_each_entry_safe(timer, next, &dev->pending, list) { 761b2b03f8e514e4f68e293846ba511a948b80243cKarsten Keil del_timer(&timer->tl); 771b2b03f8e514e4f68e293846ba511a948b80243cKarsten Keil kfree(timer); 781b2b03f8e514e4f68e293846ba511a948b80243cKarsten Keil } 791b2b03f8e514e4f68e293846ba511a948b80243cKarsten Keil list_for_each_entry_safe(timer, next, &dev->expired, list) { 801b2b03f8e514e4f68e293846ba511a948b80243cKarsten Keil kfree(timer); 811b2b03f8e514e4f68e293846ba511a948b80243cKarsten Keil } 821b2b03f8e514e4f68e293846ba511a948b80243cKarsten Keil kfree(dev); 831b2b03f8e514e4f68e293846ba511a948b80243cKarsten Keil module_put(THIS_MODULE); 841b2b03f8e514e4f68e293846ba511a948b80243cKarsten Keil return 0; 851b2b03f8e514e4f68e293846ba511a948b80243cKarsten Keil} 861b2b03f8e514e4f68e293846ba511a948b80243cKarsten Keil 871b2b03f8e514e4f68e293846ba511a948b80243cKarsten Keilstatic ssize_t 881b2b03f8e514e4f68e293846ba511a948b80243cKarsten KeilmISDN_read(struct file *filep, char *buf, size_t count, loff_t *off) 891b2b03f8e514e4f68e293846ba511a948b80243cKarsten Keil{ 901b2b03f8e514e4f68e293846ba511a948b80243cKarsten Keil struct mISDNtimerdev *dev = filep->private_data; 911b2b03f8e514e4f68e293846ba511a948b80243cKarsten Keil struct mISDNtimer *timer; 921b2b03f8e514e4f68e293846ba511a948b80243cKarsten Keil u_long flags; 931b2b03f8e514e4f68e293846ba511a948b80243cKarsten Keil int ret = 0; 941b2b03f8e514e4f68e293846ba511a948b80243cKarsten Keil 951b2b03f8e514e4f68e293846ba511a948b80243cKarsten Keil if (*debug & DEBUG_TIMER) 961b2b03f8e514e4f68e293846ba511a948b80243cKarsten Keil printk(KERN_DEBUG "%s(%p, %p, %d, %p)\n", __func__, 971b2b03f8e514e4f68e293846ba511a948b80243cKarsten Keil filep, buf, (int)count, off); 981b2b03f8e514e4f68e293846ba511a948b80243cKarsten Keil if (*off != filep->f_pos) 991b2b03f8e514e4f68e293846ba511a948b80243cKarsten Keil return -ESPIPE; 1001b2b03f8e514e4f68e293846ba511a948b80243cKarsten Keil 1011b2b03f8e514e4f68e293846ba511a948b80243cKarsten Keil if (list_empty(&dev->expired) && (dev->work == 0)) { 1021b2b03f8e514e4f68e293846ba511a948b80243cKarsten Keil if (filep->f_flags & O_NONBLOCK) 1031b2b03f8e514e4f68e293846ba511a948b80243cKarsten Keil return -EAGAIN; 1041b2b03f8e514e4f68e293846ba511a948b80243cKarsten Keil wait_event_interruptible(dev->wait, (dev->work || 1051b2b03f8e514e4f68e293846ba511a948b80243cKarsten Keil !list_empty(&dev->expired))); 1061b2b03f8e514e4f68e293846ba511a948b80243cKarsten Keil if (signal_pending(current)) 1071b2b03f8e514e4f68e293846ba511a948b80243cKarsten Keil return -ERESTARTSYS; 1081b2b03f8e514e4f68e293846ba511a948b80243cKarsten Keil } 1091b2b03f8e514e4f68e293846ba511a948b80243cKarsten Keil if (count < sizeof(int)) 1101b2b03f8e514e4f68e293846ba511a948b80243cKarsten Keil return -ENOSPC; 1111b2b03f8e514e4f68e293846ba511a948b80243cKarsten Keil if (dev->work) 1121b2b03f8e514e4f68e293846ba511a948b80243cKarsten Keil dev->work = 0; 1131b2b03f8e514e4f68e293846ba511a948b80243cKarsten Keil if (!list_empty(&dev->expired)) { 1141b2b03f8e514e4f68e293846ba511a948b80243cKarsten Keil spin_lock_irqsave(&dev->lock, flags); 1151b2b03f8e514e4f68e293846ba511a948b80243cKarsten Keil timer = (struct mISDNtimer *)dev->expired.next; 1161b2b03f8e514e4f68e293846ba511a948b80243cKarsten Keil list_del(&timer->list); 1171b2b03f8e514e4f68e293846ba511a948b80243cKarsten Keil spin_unlock_irqrestore(&dev->lock, flags); 1181b2b03f8e514e4f68e293846ba511a948b80243cKarsten Keil if (put_user(timer->id, (int *)buf)) 1191b2b03f8e514e4f68e293846ba511a948b80243cKarsten Keil ret = -EFAULT; 1201b2b03f8e514e4f68e293846ba511a948b80243cKarsten Keil else 1211b2b03f8e514e4f68e293846ba511a948b80243cKarsten Keil ret = sizeof(int); 1221b2b03f8e514e4f68e293846ba511a948b80243cKarsten Keil kfree(timer); 1231b2b03f8e514e4f68e293846ba511a948b80243cKarsten Keil } 1241b2b03f8e514e4f68e293846ba511a948b80243cKarsten Keil return ret; 1251b2b03f8e514e4f68e293846ba511a948b80243cKarsten Keil} 1261b2b03f8e514e4f68e293846ba511a948b80243cKarsten Keil 1271b2b03f8e514e4f68e293846ba511a948b80243cKarsten Keilstatic unsigned int 1281b2b03f8e514e4f68e293846ba511a948b80243cKarsten KeilmISDN_poll(struct file *filep, poll_table *wait) 1291b2b03f8e514e4f68e293846ba511a948b80243cKarsten Keil{ 1301b2b03f8e514e4f68e293846ba511a948b80243cKarsten Keil struct mISDNtimerdev *dev = filep->private_data; 1311b2b03f8e514e4f68e293846ba511a948b80243cKarsten Keil unsigned int mask = POLLERR; 1321b2b03f8e514e4f68e293846ba511a948b80243cKarsten Keil 1331b2b03f8e514e4f68e293846ba511a948b80243cKarsten Keil if (*debug & DEBUG_TIMER) 1341b2b03f8e514e4f68e293846ba511a948b80243cKarsten Keil printk(KERN_DEBUG "%s(%p, %p)\n", __func__, filep, wait); 1351b2b03f8e514e4f68e293846ba511a948b80243cKarsten Keil if (dev) { 1361b2b03f8e514e4f68e293846ba511a948b80243cKarsten Keil poll_wait(filep, &dev->wait, wait); 1371b2b03f8e514e4f68e293846ba511a948b80243cKarsten Keil mask = 0; 1381b2b03f8e514e4f68e293846ba511a948b80243cKarsten Keil if (dev->work || !list_empty(&dev->expired)) 1391b2b03f8e514e4f68e293846ba511a948b80243cKarsten Keil mask |= (POLLIN | POLLRDNORM); 1401b2b03f8e514e4f68e293846ba511a948b80243cKarsten Keil if (*debug & DEBUG_TIMER) 1411b2b03f8e514e4f68e293846ba511a948b80243cKarsten Keil printk(KERN_DEBUG "%s work(%d) empty(%d)\n", __func__, 1421b2b03f8e514e4f68e293846ba511a948b80243cKarsten Keil dev->work, list_empty(&dev->expired)); 1431b2b03f8e514e4f68e293846ba511a948b80243cKarsten Keil } 1441b2b03f8e514e4f68e293846ba511a948b80243cKarsten Keil return mask; 1451b2b03f8e514e4f68e293846ba511a948b80243cKarsten Keil} 1461b2b03f8e514e4f68e293846ba511a948b80243cKarsten Keil 1471b2b03f8e514e4f68e293846ba511a948b80243cKarsten Keilstatic void 148ce425a9f2c0182e9a9e49c7dc18699f2db4c3f48Andi Kleendev_expire_timer(unsigned long data) 1491b2b03f8e514e4f68e293846ba511a948b80243cKarsten Keil{ 150ce425a9f2c0182e9a9e49c7dc18699f2db4c3f48Andi Kleen struct mISDNtimer *timer = (void *)data; 1511b2b03f8e514e4f68e293846ba511a948b80243cKarsten Keil u_long flags; 1521b2b03f8e514e4f68e293846ba511a948b80243cKarsten Keil 1531b2b03f8e514e4f68e293846ba511a948b80243cKarsten Keil spin_lock_irqsave(&timer->dev->lock, flags); 1541b2b03f8e514e4f68e293846ba511a948b80243cKarsten Keil list_del(&timer->list); 1551b2b03f8e514e4f68e293846ba511a948b80243cKarsten Keil list_add_tail(&timer->list, &timer->dev->expired); 1561b2b03f8e514e4f68e293846ba511a948b80243cKarsten Keil spin_unlock_irqrestore(&timer->dev->lock, flags); 1571b2b03f8e514e4f68e293846ba511a948b80243cKarsten Keil wake_up_interruptible(&timer->dev->wait); 1581b2b03f8e514e4f68e293846ba511a948b80243cKarsten Keil} 1591b2b03f8e514e4f68e293846ba511a948b80243cKarsten Keil 1601b2b03f8e514e4f68e293846ba511a948b80243cKarsten Keilstatic int 1611b2b03f8e514e4f68e293846ba511a948b80243cKarsten Keilmisdn_add_timer(struct mISDNtimerdev *dev, int timeout) 1621b2b03f8e514e4f68e293846ba511a948b80243cKarsten Keil{ 1631b2b03f8e514e4f68e293846ba511a948b80243cKarsten Keil int id; 1641b2b03f8e514e4f68e293846ba511a948b80243cKarsten Keil u_long flags; 1651b2b03f8e514e4f68e293846ba511a948b80243cKarsten Keil struct mISDNtimer *timer; 1661b2b03f8e514e4f68e293846ba511a948b80243cKarsten Keil 1671b2b03f8e514e4f68e293846ba511a948b80243cKarsten Keil if (!timeout) { 1681b2b03f8e514e4f68e293846ba511a948b80243cKarsten Keil dev->work = 1; 1691b2b03f8e514e4f68e293846ba511a948b80243cKarsten Keil wake_up_interruptible(&dev->wait); 1701b2b03f8e514e4f68e293846ba511a948b80243cKarsten Keil id = 0; 1711b2b03f8e514e4f68e293846ba511a948b80243cKarsten Keil } else { 1721b2b03f8e514e4f68e293846ba511a948b80243cKarsten Keil timer = kzalloc(sizeof(struct mISDNtimer), GFP_KERNEL); 1731b2b03f8e514e4f68e293846ba511a948b80243cKarsten Keil if (!timer) 1741b2b03f8e514e4f68e293846ba511a948b80243cKarsten Keil return -ENOMEM; 1751b2b03f8e514e4f68e293846ba511a948b80243cKarsten Keil spin_lock_irqsave(&dev->lock, flags); 1761b2b03f8e514e4f68e293846ba511a948b80243cKarsten Keil timer->id = dev->next_id++; 1771b2b03f8e514e4f68e293846ba511a948b80243cKarsten Keil if (dev->next_id < 0) 1781b2b03f8e514e4f68e293846ba511a948b80243cKarsten Keil dev->next_id = 1; 1791b2b03f8e514e4f68e293846ba511a948b80243cKarsten Keil list_add_tail(&timer->list, &dev->pending); 1801b2b03f8e514e4f68e293846ba511a948b80243cKarsten Keil spin_unlock_irqrestore(&dev->lock, flags); 1811b2b03f8e514e4f68e293846ba511a948b80243cKarsten Keil timer->dev = dev; 1821b2b03f8e514e4f68e293846ba511a948b80243cKarsten Keil timer->tl.data = (long)timer; 183ce425a9f2c0182e9a9e49c7dc18699f2db4c3f48Andi Kleen timer->tl.function = dev_expire_timer; 1841b2b03f8e514e4f68e293846ba511a948b80243cKarsten Keil init_timer(&timer->tl); 1851b2b03f8e514e4f68e293846ba511a948b80243cKarsten Keil timer->tl.expires = jiffies + ((HZ * (u_long)timeout) / 1000); 1861b2b03f8e514e4f68e293846ba511a948b80243cKarsten Keil add_timer(&timer->tl); 1871b2b03f8e514e4f68e293846ba511a948b80243cKarsten Keil id = timer->id; 1881b2b03f8e514e4f68e293846ba511a948b80243cKarsten Keil } 1891b2b03f8e514e4f68e293846ba511a948b80243cKarsten Keil return id; 1901b2b03f8e514e4f68e293846ba511a948b80243cKarsten Keil} 1911b2b03f8e514e4f68e293846ba511a948b80243cKarsten Keil 1921b2b03f8e514e4f68e293846ba511a948b80243cKarsten Keilstatic int 1931b2b03f8e514e4f68e293846ba511a948b80243cKarsten Keilmisdn_del_timer(struct mISDNtimerdev *dev, int id) 1941b2b03f8e514e4f68e293846ba511a948b80243cKarsten Keil{ 1951b2b03f8e514e4f68e293846ba511a948b80243cKarsten Keil u_long flags; 1961b2b03f8e514e4f68e293846ba511a948b80243cKarsten Keil struct mISDNtimer *timer; 1971b2b03f8e514e4f68e293846ba511a948b80243cKarsten Keil int ret = 0; 1981b2b03f8e514e4f68e293846ba511a948b80243cKarsten Keil 1991b2b03f8e514e4f68e293846ba511a948b80243cKarsten Keil spin_lock_irqsave(&dev->lock, flags); 2001b2b03f8e514e4f68e293846ba511a948b80243cKarsten Keil list_for_each_entry(timer, &dev->pending, list) { 2011b2b03f8e514e4f68e293846ba511a948b80243cKarsten Keil if (timer->id == id) { 2021b2b03f8e514e4f68e293846ba511a948b80243cKarsten Keil list_del_init(&timer->list); 203ce425a9f2c0182e9a9e49c7dc18699f2db4c3f48Andi Kleen /* RED-PEN AK: race -- timer can be still running on 204ce425a9f2c0182e9a9e49c7dc18699f2db4c3f48Andi Kleen * other CPU. Needs reference count I think 205ce425a9f2c0182e9a9e49c7dc18699f2db4c3f48Andi Kleen */ 2061b2b03f8e514e4f68e293846ba511a948b80243cKarsten Keil del_timer(&timer->tl); 2071b2b03f8e514e4f68e293846ba511a948b80243cKarsten Keil ret = timer->id; 2081b2b03f8e514e4f68e293846ba511a948b80243cKarsten Keil kfree(timer); 2091b2b03f8e514e4f68e293846ba511a948b80243cKarsten Keil goto unlock; 2101b2b03f8e514e4f68e293846ba511a948b80243cKarsten Keil } 2111b2b03f8e514e4f68e293846ba511a948b80243cKarsten Keil } 2121b2b03f8e514e4f68e293846ba511a948b80243cKarsten Keilunlock: 2131b2b03f8e514e4f68e293846ba511a948b80243cKarsten Keil spin_unlock_irqrestore(&dev->lock, flags); 2141b2b03f8e514e4f68e293846ba511a948b80243cKarsten Keil return ret; 2151b2b03f8e514e4f68e293846ba511a948b80243cKarsten Keil} 2161b2b03f8e514e4f68e293846ba511a948b80243cKarsten Keil 2171b2b03f8e514e4f68e293846ba511a948b80243cKarsten Keilstatic int 2181b2b03f8e514e4f68e293846ba511a948b80243cKarsten KeilmISDN_ioctl(struct inode *inode, struct file *filep, unsigned int cmd, 2191b2b03f8e514e4f68e293846ba511a948b80243cKarsten Keil unsigned long arg) 2201b2b03f8e514e4f68e293846ba511a948b80243cKarsten Keil{ 2211b2b03f8e514e4f68e293846ba511a948b80243cKarsten Keil struct mISDNtimerdev *dev = filep->private_data; 2221b2b03f8e514e4f68e293846ba511a948b80243cKarsten Keil int id, tout, ret = 0; 2231b2b03f8e514e4f68e293846ba511a948b80243cKarsten Keil 2241b2b03f8e514e4f68e293846ba511a948b80243cKarsten Keil 2251b2b03f8e514e4f68e293846ba511a948b80243cKarsten Keil if (*debug & DEBUG_TIMER) 2261b2b03f8e514e4f68e293846ba511a948b80243cKarsten Keil printk(KERN_DEBUG "%s(%p, %x, %lx)\n", __func__, 2271b2b03f8e514e4f68e293846ba511a948b80243cKarsten Keil filep, cmd, arg); 2281b2b03f8e514e4f68e293846ba511a948b80243cKarsten Keil switch (cmd) { 2291b2b03f8e514e4f68e293846ba511a948b80243cKarsten Keil case IMADDTIMER: 2301b2b03f8e514e4f68e293846ba511a948b80243cKarsten Keil if (get_user(tout, (int __user *)arg)) { 2311b2b03f8e514e4f68e293846ba511a948b80243cKarsten Keil ret = -EFAULT; 2321b2b03f8e514e4f68e293846ba511a948b80243cKarsten Keil break; 2331b2b03f8e514e4f68e293846ba511a948b80243cKarsten Keil } 2341b2b03f8e514e4f68e293846ba511a948b80243cKarsten Keil id = misdn_add_timer(dev, tout); 2351b2b03f8e514e4f68e293846ba511a948b80243cKarsten Keil if (*debug & DEBUG_TIMER) 2361b2b03f8e514e4f68e293846ba511a948b80243cKarsten Keil printk(KERN_DEBUG "%s add %d id %d\n", __func__, 2371b2b03f8e514e4f68e293846ba511a948b80243cKarsten Keil tout, id); 2381b2b03f8e514e4f68e293846ba511a948b80243cKarsten Keil if (id < 0) { 2391b2b03f8e514e4f68e293846ba511a948b80243cKarsten Keil ret = id; 2401b2b03f8e514e4f68e293846ba511a948b80243cKarsten Keil break; 2411b2b03f8e514e4f68e293846ba511a948b80243cKarsten Keil } 2421b2b03f8e514e4f68e293846ba511a948b80243cKarsten Keil if (put_user(id, (int __user *)arg)) 2431b2b03f8e514e4f68e293846ba511a948b80243cKarsten Keil ret = -EFAULT; 2441b2b03f8e514e4f68e293846ba511a948b80243cKarsten Keil break; 2451b2b03f8e514e4f68e293846ba511a948b80243cKarsten Keil case IMDELTIMER: 2461b2b03f8e514e4f68e293846ba511a948b80243cKarsten Keil if (get_user(id, (int __user *)arg)) { 2471b2b03f8e514e4f68e293846ba511a948b80243cKarsten Keil ret = -EFAULT; 2481b2b03f8e514e4f68e293846ba511a948b80243cKarsten Keil break; 2491b2b03f8e514e4f68e293846ba511a948b80243cKarsten Keil } 2501b2b03f8e514e4f68e293846ba511a948b80243cKarsten Keil if (*debug & DEBUG_TIMER) 2511b2b03f8e514e4f68e293846ba511a948b80243cKarsten Keil printk(KERN_DEBUG "%s del id %d\n", __func__, id); 2521b2b03f8e514e4f68e293846ba511a948b80243cKarsten Keil id = misdn_del_timer(dev, id); 2531b2b03f8e514e4f68e293846ba511a948b80243cKarsten Keil if (put_user(id, (int __user *)arg)) 2541b2b03f8e514e4f68e293846ba511a948b80243cKarsten Keil ret = -EFAULT; 2551b2b03f8e514e4f68e293846ba511a948b80243cKarsten Keil break; 2561b2b03f8e514e4f68e293846ba511a948b80243cKarsten Keil default: 2571b2b03f8e514e4f68e293846ba511a948b80243cKarsten Keil ret = -EINVAL; 2581b2b03f8e514e4f68e293846ba511a948b80243cKarsten Keil } 2591b2b03f8e514e4f68e293846ba511a948b80243cKarsten Keil return ret; 2601b2b03f8e514e4f68e293846ba511a948b80243cKarsten Keil} 2611b2b03f8e514e4f68e293846ba511a948b80243cKarsten Keil 2621b2b03f8e514e4f68e293846ba511a948b80243cKarsten Keilstatic struct file_operations mISDN_fops = { 2631b2b03f8e514e4f68e293846ba511a948b80243cKarsten Keil .read = mISDN_read, 2641b2b03f8e514e4f68e293846ba511a948b80243cKarsten Keil .poll = mISDN_poll, 2651b2b03f8e514e4f68e293846ba511a948b80243cKarsten Keil .ioctl = mISDN_ioctl, 2661b2b03f8e514e4f68e293846ba511a948b80243cKarsten Keil .open = mISDN_open, 2671b2b03f8e514e4f68e293846ba511a948b80243cKarsten Keil .release = mISDN_close, 2681b2b03f8e514e4f68e293846ba511a948b80243cKarsten Keil}; 2691b2b03f8e514e4f68e293846ba511a948b80243cKarsten Keil 2701b2b03f8e514e4f68e293846ba511a948b80243cKarsten Keilstatic struct miscdevice mISDNtimer = { 2711b2b03f8e514e4f68e293846ba511a948b80243cKarsten Keil .minor = MISC_DYNAMIC_MINOR, 2721b2b03f8e514e4f68e293846ba511a948b80243cKarsten Keil .name = "mISDNtimer", 2731b2b03f8e514e4f68e293846ba511a948b80243cKarsten Keil .fops = &mISDN_fops, 2741b2b03f8e514e4f68e293846ba511a948b80243cKarsten Keil}; 2751b2b03f8e514e4f68e293846ba511a948b80243cKarsten Keil 2761b2b03f8e514e4f68e293846ba511a948b80243cKarsten Keilint 2771b2b03f8e514e4f68e293846ba511a948b80243cKarsten KeilmISDN_inittimer(int *deb) 2781b2b03f8e514e4f68e293846ba511a948b80243cKarsten Keil{ 2791b2b03f8e514e4f68e293846ba511a948b80243cKarsten Keil int err; 2801b2b03f8e514e4f68e293846ba511a948b80243cKarsten Keil 2811b2b03f8e514e4f68e293846ba511a948b80243cKarsten Keil debug = deb; 2821b2b03f8e514e4f68e293846ba511a948b80243cKarsten Keil err = misc_register(&mISDNtimer); 2831b2b03f8e514e4f68e293846ba511a948b80243cKarsten Keil if (err) 2841b2b03f8e514e4f68e293846ba511a948b80243cKarsten Keil printk(KERN_WARNING "mISDN: Could not register timer device\n"); 2851b2b03f8e514e4f68e293846ba511a948b80243cKarsten Keil return err; 2861b2b03f8e514e4f68e293846ba511a948b80243cKarsten Keil} 2871b2b03f8e514e4f68e293846ba511a948b80243cKarsten Keil 2881b2b03f8e514e4f68e293846ba511a948b80243cKarsten Keilvoid mISDN_timer_cleanup(void) 2891b2b03f8e514e4f68e293846ba511a948b80243cKarsten Keil{ 2901b2b03f8e514e4f68e293846ba511a948b80243cKarsten Keil misc_deregister(&mISDNtimer); 2911b2b03f8e514e4f68e293846ba511a948b80243cKarsten Keil} 292