cregit-Linux how code gets into the kernel

Release 4.11 drivers/isdn/hardware/eicon/divasi.c

/* $Id: divasi.c,v 1.25.6.2 2005/01/31 12:22:20 armin Exp $
 *
 * Driver for Eicon DIVA Server ISDN cards.
 * User Mode IDI Interface
 *
 * Copyright 2000-2003 by Armin Schindler (mac@melware.de)
 * Copyright 2000-2003 Cytronics & Melware (info@melware.de)
 *
 * This software may be used and distributed according to the terms
 * of the GNU General Public License, incorporated herein by reference.
 */

#include <linux/module.h>
#include <linux/init.h>
#include <linux/kernel.h>
#include <linux/sched.h>
#include <linux/poll.h>
#include <linux/proc_fs.h>
#include <linux/skbuff.h>
#include <linux/seq_file.h>
#include <linux/uaccess.h>

#include "platform.h"
#include "di_defs.h"
#include "divasync.h"
#include "um_xdi.h"
#include "um_idi.h"


static char *main_revision = "$Revision: 1.25.6.2 $";


static int major;

MODULE_DESCRIPTION("User IDI Interface for Eicon ISDN cards");
MODULE_AUTHOR("Cytronics & Melware, Eicon Networks");
MODULE_SUPPORTED_DEVICE("DIVA card driver");
MODULE_LICENSE("GPL");


typedef struct _diva_um_idi_os_context {
	
wait_queue_head_t read_wait;
	
wait_queue_head_t close_wait;
	
struct timer_list diva_timer_id;
	
int aborted;
	
int adapter_nr;
} 
diva_um_idi_os_context_t;


static char *DRIVERNAME = "Eicon DIVA - User IDI (http://www.melware.net)";

static char *DRIVERLNAME = "diva_idi";

static char *DEVNAME = "DivasIDI";

char *DRIVERRELEASE_IDI = "2.0";

extern int idifunc_init(void);
extern void idifunc_finit(void);

/*
 *  helper functions
 */

static char *getrev(const char *revision) { char *rev; char *p; if ((p = strchr(revision, ':'))) { rev = p + 2; p = strchr(rev, '$'); *--p = 0; } else rev = "1.0"; return rev; }

Contributors

PersonTokensPropCommitsCommitProp
Armin Schindler64100.00%1100.00%
Total64100.00%1100.00%

/* * LOCALS */ static ssize_t um_idi_read(struct file *file, char __user *buf, size_t count, loff_t *offset); static ssize_t um_idi_write(struct file *file, const char __user *buf, size_t count, loff_t *offset); static unsigned int um_idi_poll(struct file *file, poll_table *wait); static int um_idi_open(struct inode *inode, struct file *file); static int um_idi_release(struct inode *inode, struct file *file); static int remove_entity(void *entity); static void diva_um_timer_function(unsigned long data); /* * proc entry */ extern struct proc_dir_entry *proc_net_eicon; static struct proc_dir_entry *um_idi_proc_entry = NULL;
static int um_idi_proc_show(struct seq_file *m, void *v) { char tmprev[32]; seq_printf(m, "%s\n", DRIVERNAME); seq_printf(m, "name : %s\n", DRIVERLNAME); seq_printf(m, "release : %s\n", DRIVERRELEASE_IDI); strcpy(tmprev, main_revision); seq_printf(m, "revision : %s\n", getrev(tmprev)); seq_printf(m, "build : %s\n", DIVA_BUILD); seq_printf(m, "major : %d\n", major); return 0; }

Contributors

PersonTokensPropCommitsCommitProp
Armin Schindler7079.55%266.67%
Alexey Dobriyan1820.45%133.33%
Total88100.00%3100.00%


static int um_idi_proc_open(struct inode *inode, struct file *file) { return single_open(file, um_idi_proc_show, NULL); }

Contributors

PersonTokensPropCommitsCommitProp
Alexey Dobriyan2388.46%150.00%
Armin Schindler311.54%150.00%
Total26100.00%2100.00%

static const struct file_operations um_idi_proc_fops = { .owner = THIS_MODULE, .open = um_idi_proc_open, .read = seq_read, .llseek = seq_lseek, .release = single_release, };
static int __init create_um_idi_proc(void) { um_idi_proc_entry = proc_create(DRIVERLNAME, S_IRUGO, proc_net_eicon, &um_idi_proc_fops); if (!um_idi_proc_entry) return (0); return (1); }

Contributors

PersonTokensPropCommitsCommitProp
Armin Schindler3386.84%250.00%
Alexey Dobriyan410.53%125.00%
H Hartley Sweeten12.63%125.00%
Total38100.00%4100.00%


static void remove_um_idi_proc(void) { if (um_idi_proc_entry) { remove_proc_entry(DRIVERLNAME, proc_net_eicon); um_idi_proc_entry = NULL; } }

Contributors

PersonTokensPropCommitsCommitProp
Armin Schindler25100.00%2100.00%
Total25100.00%2100.00%

static const struct file_operations divas_idi_fops = { .owner = THIS_MODULE, .llseek = no_llseek, .read = um_idi_read, .write = um_idi_write, .poll = um_idi_poll, .open = um_idi_open, .release = um_idi_release };
static void divas_idi_unregister_chrdev(void) { unregister_chrdev(major, DEVNAME); }

Contributors

PersonTokensPropCommitsCommitProp
Armin Schindler15100.00%2100.00%
Total15100.00%2100.00%


static int __init divas_idi_register_chrdev(void) { if ((major = register_chrdev(0, DEVNAME, &divas_idi_fops)) < 0) { printk(KERN_ERR "%s: failed to create /dev entry.\n", DRIVERLNAME); return (0); } return (1); }

Contributors

PersonTokensPropCommitsCommitProp
Armin Schindler4697.87%266.67%
H Hartley Sweeten12.13%133.33%
Total47100.00%3100.00%

/* ** Driver Load */
static int __init divasi_init(void) { char tmprev[50]; int ret = 0; printk(KERN_INFO "%s\n", DRIVERNAME); printk(KERN_INFO "%s: Rel:%s Rev:", DRIVERLNAME, DRIVERRELEASE_IDI); strcpy(tmprev, main_revision); printk("%s Build: %s\n", getrev(tmprev), DIVA_BUILD); if (!divas_idi_register_chrdev()) { ret = -EIO; goto out; } if (!create_um_idi_proc()) { divas_idi_unregister_chrdev(); printk(KERN_ERR "%s: failed to create proc entry.\n", DRIVERLNAME); ret = -EIO; goto out; } if (!(idifunc_init())) { remove_um_idi_proc(); divas_idi_unregister_chrdev(); printk(KERN_ERR "%s: failed to connect to DIDD.\n", DRIVERLNAME); ret = -EIO; goto out; } printk(KERN_INFO "%s: started with major %d\n", DRIVERLNAME, major); out: return (ret); }

Contributors

PersonTokensPropCommitsCommitProp
Armin Schindler14899.33%266.67%
H Hartley Sweeten10.67%133.33%
Total149100.00%3100.00%

/* ** Driver Unload */
static void __exit divasi_exit(void) { idifunc_finit(); remove_um_idi_proc(); divas_idi_unregister_chrdev(); printk(KERN_INFO "%s: module unloaded.\n", DRIVERLNAME); }

Contributors

PersonTokensPropCommitsCommitProp
Armin Schindler2596.15%150.00%
H Hartley Sweeten13.85%150.00%
Total26100.00%2100.00%

module_init(divasi_init); module_exit(divasi_exit); /* * FILE OPERATIONS */
static int divas_um_idi_copy_to_user(void *os_handle, void *dst, const void *src, int length) { memcpy(dst, src, length); return (length); }

Contributors

PersonTokensPropCommitsCommitProp
Armin Schindler36100.00%1100.00%
Total36100.00%1100.00%


static ssize_t um_idi_read(struct file *file, char __user *buf, size_t count, loff_t *offset) { diva_um_idi_os_context_t *p_os; int ret = -EINVAL; void *data; if (!file->private_data) { return (-ENODEV); } if (! (p_os = (diva_um_idi_os_context_t *) diva_um_id_get_os_context(file-> private_data))) { return (-ENODEV); } if (p_os->aborted) { return (-ENODEV); } if (!(data = diva_os_malloc(0, count))) { return (-ENOMEM); } ret = diva_um_idi_read(file->private_data, file, data, count, divas_um_idi_copy_to_user); switch (ret) { case 0: /* no message available */ ret = (-EAGAIN); break; case (-1): /* adapter was removed */ ret = (-ENODEV); break; case (-2): /* message_length > length of user buffer */ ret = (-EFAULT); break; } if (ret > 0) { if (copy_to_user(buf, data, ret)) { ret = (-EFAULT); } } diva_os_free(0, data); DBG_TRC(("read: ret %d", ret)); return (ret); }

Contributors

PersonTokensPropCommitsCommitProp
Armin Schindler22799.56%150.00%
Al Viro10.44%150.00%
Total228100.00%2100.00%


static int divas_um_idi_copy_from_user(void *os_handle, void *dst, const void *src, int length) { memcpy(dst, src, length); return (length); }

Contributors

PersonTokensPropCommitsCommitProp
Armin Schindler36100.00%1100.00%
Total36100.00%1100.00%


static int um_idi_open_adapter(struct file *file, int adapter_nr) { diva_um_idi_os_context_t *p_os; void *e = divas_um_idi_create_entity((dword) adapter_nr, (void *) file); if (!(file->private_data = e)) { return (0); } p_os = (diva_um_idi_os_context_t *) diva_um_id_get_os_context(e); init_waitqueue_head(&p_os->read_wait); init_waitqueue_head(&p_os->close_wait); init_timer(&p_os->diva_timer_id); p_os->diva_timer_id.function = (void *) diva_um_timer_function; p_os->diva_timer_id.data = (unsigned long) p_os; p_os->aborted = 0; p_os->adapter_nr = adapter_nr; return (1); }

Contributors

PersonTokensPropCommitsCommitProp
Armin Schindler130100.00%2100.00%
Total130100.00%2100.00%


static ssize_t um_idi_write(struct file *file, const char __user *buf, size_t count, loff_t *offset) { diva_um_idi_os_context_t *p_os; int ret = -EINVAL; void *data; int adapter_nr = 0; if (!file->private_data) { /* the first write() selects the adapter_nr */ if (count == sizeof(int)) { if (copy_from_user ((void *) &adapter_nr, buf, count)) return (-EFAULT); if (!(um_idi_open_adapter(file, adapter_nr))) return (-ENODEV); return (count); } else return (-ENODEV); } if (!(p_os = (diva_um_idi_os_context_t *) diva_um_id_get_os_context(file-> private_data))) { return (-ENODEV); } if (p_os->aborted) { return (-ENODEV); } if (!(data = diva_os_malloc(0, count))) { return (-ENOMEM); } if (copy_from_user(data, buf, count)) { ret = -EFAULT; } else { ret = diva_um_idi_write(file->private_data, file, data, count, divas_um_idi_copy_from_user); switch (ret) { case 0: /* no space available */ ret = (-EAGAIN); break; case (-1): /* adapter was removed */ ret = (-ENODEV); break; case (-2): /* length of user buffer > max message_length */ ret = (-EFAULT); break; } } diva_os_free(0, data); DBG_TRC(("write: ret %d", ret)); return (ret); }

Contributors

PersonTokensPropCommitsCommitProp
Armin Schindler28499.65%150.00%
Al Viro10.35%150.00%
Total285100.00%2100.00%


static unsigned int um_idi_poll(struct file *file, poll_table *wait) { diva_um_idi_os_context_t *p_os; if (!file->private_data) { return (POLLERR); } if ((!(p_os = (diva_um_idi_os_context_t *) diva_um_id_get_os_context(file->private_data))) || p_os->aborted) { return (POLLERR); } poll_wait(file, &p_os->read_wait, wait); if (p_os->aborted) { return (POLLERR); } switch (diva_user_mode_idi_ind_ready(file->private_data, file)) { case (-1): return (POLLERR); case 0: return (0); } return (POLLIN | POLLRDNORM); }

Contributors

PersonTokensPropCommitsCommitProp
Armin Schindler129100.00%1100.00%
Total129100.00%1100.00%


static int um_idi_open(struct inode *inode, struct file *file) { return (0); }

Contributors

PersonTokensPropCommitsCommitProp
Armin Schindler21100.00%1100.00%
Total21100.00%1100.00%


static int um_idi_release(struct inode *inode, struct file *file) { diva_um_idi_os_context_t *p_os; unsigned int adapter_nr; int ret = 0; if (!(file->private_data)) { ret = -ENODEV; goto out; } if (!(p_os = (diva_um_idi_os_context_t *) diva_um_id_get_os_context(file->private_data))) { ret = -ENODEV; goto out; } adapter_nr = p_os->adapter_nr; if ((ret = remove_entity(file->private_data))) { goto out; } if (divas_um_idi_delete_entity ((int) adapter_nr, file->private_data)) { ret = -ENODEV; goto out; } out: return (ret); }

Contributors

PersonTokensPropCommitsCommitProp
Armin Schindler131100.00%2100.00%
Total131100.00%2100.00%


int diva_os_get_context_size(void) { return (sizeof(diva_um_idi_os_context_t)); }

Contributors

PersonTokensPropCommitsCommitProp
Armin Schindler1493.33%150.00%
Kai Germaschewski16.67%150.00%
Total15100.00%2100.00%


void diva_os_wakeup_read(void *os_context) { diva_um_idi_os_context_t *p_os = (diva_um_idi_os_context_t *) os_context; wake_up_interruptible(&p_os->read_wait); }

Contributors

PersonTokensPropCommitsCommitProp
Armin Schindler2696.30%150.00%
Kai Germaschewski13.70%150.00%
Total27100.00%2100.00%


void diva_os_wakeup_close(void *os_context) { diva_um_idi_os_context_t *p_os = (diva_um_idi_os_context_t *) os_context; wake_up_interruptible(&p_os->close_wait); }

Contributors

PersonTokensPropCommitsCommitProp
Armin Schindler2696.30%150.00%
Kai Germaschewski13.70%150.00%
Total27100.00%2100.00%


static void diva_um_timer_function(unsigned long data) { diva_um_idi_os_context_t *p_os = (diva_um_idi_os_context_t *) data; p_os->aborted = 1; wake_up_interruptible(&p_os->read_wait); wake_up_interruptible(&p_os->close_wait); DBG_ERR(("entity removal watchdog")) }

Contributors

PersonTokensPropCommitsCommitProp
Armin Schindler48100.00%1100.00%
Total48100.00%1100.00%

/* ** If application exits without entity removal this function will remove ** entity and block until removal is complete */
static int remove_entity(void *entity) { struct task_struct *curtask = current; diva_um_idi_os_context_t *p_os; diva_um_idi_stop_wdog(entity); if (!entity) { DBG_FTL(("Zero entity on remove")) return (0); } if (!(p_os = (diva_um_idi_os_context_t *) diva_um_id_get_os_context(entity))) { DBG_FTL(("Zero entity os context on remove")) return (0); } if (!divas_um_idi_entity_assigned(entity) || p_os->aborted) { /* Entity is not assigned, also can be removed */ return (0); } DBG_TRC(("E(%08x) check remove", entity)) /* If adapter not answers on remove request inside of 10 Sec, then adapter is dead */ diva_um_idi_start_wdog(entity); { DECLARE_WAITQUEUE(wait, curtask); add_wait_queue(&p_os->close_wait, &wait); for (;;) { set_current_state(TASK_INTERRUPTIBLE); if (!divas_um_idi_entity_start_remove(entity) || p_os->aborted) { break; } schedule(); } set_current_state(TASK_RUNNING); remove_wait_queue(&p_os->close_wait, &wait); } DBG_TRC(("E(%08x) start remove", entity)) { DECLARE_WAITQUEUE(wait, curtask); add_wait_queue(&p_os->close_wait, &wait); for (;;) { set_current_state(TASK_INTERRUPTIBLE); if (!divas_um_idi_entity_assigned(entity) || p_os->aborted) { break; } schedule(); } set_current_state(TASK_RUNNING); remove_wait_queue(&p_os->close_wait, &wait); } DBG_TRC(("E(%08x) remove complete, aborted:%d", entity, p_os->aborted)) diva_um_idi_stop_wdog(entity); p_os->aborted = 0; return (0); }

Contributors

PersonTokensPropCommitsCommitProp
Armin Schindler26298.87%133.33%
Joe Perches20.75%133.33%
Kai Germaschewski10.38%133.33%
Total265100.00%3100.00%

/* * timer watchdog */
void diva_um_idi_start_wdog(void *entity) { diva_um_idi_os_context_t *p_os; if (entity && ((p_os = (diva_um_idi_os_context_t *) diva_um_id_get_os_context(entity)))) { mod_timer(&p_os->diva_timer_id, jiffies + 10 * HZ); } }

Contributors

PersonTokensPropCommitsCommitProp
Armin Schindler48100.00%1100.00%
Total48100.00%1100.00%


void diva_um_idi_stop_wdog(void *entity) { diva_um_idi_os_context_t *p_os; if (entity && ((p_os = (diva_um_idi_os_context_t *) diva_um_id_get_os_context(entity)))) { del_timer(&p_os->diva_timer_id); } }

Contributors

PersonTokensPropCommitsCommitProp
Armin Schindler42100.00%1100.00%
Total42100.00%1100.00%


Overall Contributors

PersonTokensPropCommitsCommitProp
Armin Schindler218695.04%327.27%
Alexey Dobriyan813.52%19.09%
Kai Germaschewski200.87%218.18%
Al Viro40.17%19.09%
H Hartley Sweeten40.17%19.09%
Joe Perches30.13%19.09%
Linus Torvalds10.04%19.09%
Arjan van de Ven10.04%19.09%
Total2300100.00%11100.00%
Information contained on this website is for historical information purposes only and does not indicate or represent copyright ownership.
Created with cregit.