Path: blob/master/drivers/isdn/hardware/eicon/divamnt.c
15115 views
/* $Id: divamnt.c,v 1.32.6.10 2005/02/11 19:40:25 armin Exp $1*2* Driver for Eicon DIVA Server ISDN cards.3* Maint module4*5* Copyright 2000-2003 by Armin Schindler ([email protected])6* Copyright 2000-2003 Cytronics & Melware ([email protected])7*8* This software may be used and distributed according to the terms9* of the GNU General Public License, incorporated herein by reference.10*/1112#include <linux/module.h>13#include <linux/init.h>14#include <linux/kernel.h>15#include <linux/poll.h>16#include <linux/mutex.h>17#include <asm/uaccess.h>1819#include "platform.h"20#include "di_defs.h"21#include "divasync.h"22#include "debug_if.h"2324static DEFINE_MUTEX(maint_mutex);25static char *main_revision = "$Revision: 1.32.6.10 $";2627static int major;2829MODULE_DESCRIPTION("Maint driver for Eicon DIVA Server cards");30MODULE_AUTHOR("Cytronics & Melware, Eicon Networks");31MODULE_SUPPORTED_DEVICE("DIVA card driver");32MODULE_LICENSE("GPL");3334static int buffer_length = 128;35module_param(buffer_length, int, 0);36static unsigned long diva_dbg_mem = 0;37module_param(diva_dbg_mem, ulong, 0);3839static char *DRIVERNAME =40"Eicon DIVA - MAINT module (http://www.melware.net)";41static char *DRIVERLNAME = "diva_mnt";42static char *DEVNAME = "DivasMAINT";43char *DRIVERRELEASE_MNT = "2.0";4445static wait_queue_head_t msgwaitq;46static unsigned long opened;47static struct timeval start_time;4849extern int mntfunc_init(int *, void **, unsigned long);50extern void mntfunc_finit(void);51extern int maint_read_write(void __user *buf, int count);5253/*54* helper functions55*/56static char *getrev(const char *revision)57{58char *rev;59char *p;6061if ((p = strchr(revision, ':'))) {62rev = p + 2;63p = strchr(rev, '$');64*--p = 0;65} else66rev = "1.0";6768return rev;69}7071/*72* kernel/user space copy functions73*/74int diva_os_copy_to_user(void *os_handle, void __user *dst, const void *src,75int length)76{77return (copy_to_user(dst, src, length));78}79int diva_os_copy_from_user(void *os_handle, void *dst, const void __user *src,80int length)81{82return (copy_from_user(dst, src, length));83}8485/*86* get time87*/88void diva_os_get_time(dword * sec, dword * usec)89{90struct timeval tv;9192do_gettimeofday(&tv);9394if (tv.tv_sec > start_time.tv_sec) {95if (start_time.tv_usec > tv.tv_usec) {96tv.tv_sec--;97tv.tv_usec += 1000000;98}99*sec = (dword) (tv.tv_sec - start_time.tv_sec);100*usec = (dword) (tv.tv_usec - start_time.tv_usec);101} else if (tv.tv_sec == start_time.tv_sec) {102*sec = 0;103if (start_time.tv_usec < tv.tv_usec) {104*usec = (dword) (tv.tv_usec - start_time.tv_usec);105} else {106*usec = 0;107}108} else {109*sec = (dword) tv.tv_sec;110*usec = (dword) tv.tv_usec;111}112}113114/*115* device node operations116*/117static unsigned int maint_poll(struct file *file, poll_table * wait)118{119unsigned int mask = 0;120121poll_wait(file, &msgwaitq, wait);122mask = POLLOUT | POLLWRNORM;123if (file->private_data || diva_dbg_q_length()) {124mask |= POLLIN | POLLRDNORM;125}126return (mask);127}128129static int maint_open(struct inode *ino, struct file *filep)130{131int ret;132133mutex_lock(&maint_mutex);134/* only one open is allowed, so we test135it atomically */136if (test_and_set_bit(0, &opened))137ret = -EBUSY;138else {139filep->private_data = NULL;140ret = nonseekable_open(ino, filep);141}142mutex_unlock(&maint_mutex);143return ret;144}145146static int maint_close(struct inode *ino, struct file *filep)147{148if (filep->private_data) {149diva_os_free(0, filep->private_data);150filep->private_data = NULL;151}152153/* clear 'used' flag */154clear_bit(0, &opened);155156return (0);157}158159static ssize_t divas_maint_write(struct file *file, const char __user *buf,160size_t count, loff_t * ppos)161{162return (maint_read_write((char __user *) buf, (int) count));163}164165static ssize_t divas_maint_read(struct file *file, char __user *buf,166size_t count, loff_t * ppos)167{168return (maint_read_write(buf, (int) count));169}170171static const struct file_operations divas_maint_fops = {172.owner = THIS_MODULE,173.llseek = no_llseek,174.read = divas_maint_read,175.write = divas_maint_write,176.poll = maint_poll,177.open = maint_open,178.release = maint_close179};180181static void divas_maint_unregister_chrdev(void)182{183unregister_chrdev(major, DEVNAME);184}185186static int DIVA_INIT_FUNCTION divas_maint_register_chrdev(void)187{188if ((major = register_chrdev(0, DEVNAME, &divas_maint_fops)) < 0)189{190printk(KERN_ERR "%s: failed to create /dev entry.\n",191DRIVERLNAME);192return (0);193}194195return (1);196}197198/*199* wake up reader200*/201void diva_maint_wakeup_read(void)202{203wake_up_interruptible(&msgwaitq);204}205206/*207* Driver Load208*/209static int DIVA_INIT_FUNCTION maint_init(void)210{211char tmprev[50];212int ret = 0;213void *buffer = NULL;214215do_gettimeofday(&start_time);216init_waitqueue_head(&msgwaitq);217218printk(KERN_INFO "%s\n", DRIVERNAME);219printk(KERN_INFO "%s: Rel:%s Rev:", DRIVERLNAME, DRIVERRELEASE_MNT);220strcpy(tmprev, main_revision);221printk("%s Build: %s \n", getrev(tmprev), DIVA_BUILD);222223if (!divas_maint_register_chrdev()) {224ret = -EIO;225goto out;226}227228if (!(mntfunc_init(&buffer_length, &buffer, diva_dbg_mem))) {229printk(KERN_ERR "%s: failed to connect to DIDD.\n",230DRIVERLNAME);231divas_maint_unregister_chrdev();232ret = -EIO;233goto out;234}235236printk(KERN_INFO "%s: trace buffer = %p - %d kBytes, %s (Major: %d)\n",237DRIVERLNAME, buffer, (buffer_length / 1024),238(diva_dbg_mem == 0) ? "internal" : "external", major);239240out:241return (ret);242}243244/*245** Driver Unload246*/247static void DIVA_EXIT_FUNCTION maint_exit(void)248{249divas_maint_unregister_chrdev();250mntfunc_finit();251252printk(KERN_INFO "%s: module unloaded.\n", DRIVERLNAME);253}254255module_init(maint_init);256module_exit(maint_exit);257258259260