Release 4.11 drivers/isdn/gigaset/interface.c
/*
* interface to user space for the gigaset driver
*
* Copyright (c) 2004 by Hansjoerg Lipp <hjlipp@web.de>
*
* =====================================================================
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of
* the License, or (at your option) any later version.
* =====================================================================
*/
#include "gigaset.h"
#include <linux/gigaset_dev.h>
#include <linux/tty_flip.h>
#include <linux/module.h>
/*** our ioctls ***/
static int if_lock(struct cardstate *cs, int *arg)
{
int cmd = *arg;
gig_dbg(DEBUG_IF, "%u: if_lock (%d)", cs->minor_index, cmd);
if (cmd > 1)
return -EINVAL;
if (cmd < 0) {
*arg = cs->mstate == MS_LOCKED;
return 0;
}
if (!cmd && cs->mstate == MS_LOCKED && cs->connected) {
cs->ops->set_modem_ctrl(cs, 0, TIOCM_DTR | TIOCM_RTS);
cs->ops->baud_rate(cs, B115200);
cs->ops->set_line_ctrl(cs, CS8);
cs->control_state = TIOCM_DTR | TIOCM_RTS;
}
cs->waiting = 1;
if (!gigaset_add_event(cs, &cs->at_state, EV_IF_LOCK,
NULL, cmd, NULL)) {
cs->waiting = 0;
return -ENOMEM;
}
gigaset_schedule_event(cs);
wait_event(cs->waitqueue, !cs->waiting);
if (cs->cmd_result >= 0) {
*arg = cs->cmd_result;
return 0;
}
return cs->cmd_result;
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Hansjoerg Lipp | 206 | 99.52% | 1 | 50.00% |
Tilman Schmidt | 1 | 0.48% | 1 | 50.00% |
Total | 207 | 100.00% | 2 | 100.00% |
static int if_version(struct cardstate *cs, unsigned arg[4])
{
static const unsigned version[4] = GIG_VERSION;
static const unsigned compat[4] = GIG_COMPAT;
unsigned cmd = arg[0];
gig_dbg(DEBUG_IF, "%u: if_version (%d)", cs->minor_index, cmd);
switch (cmd) {
case GIGVER_DRIVER:
memcpy(arg, version, sizeof version);
return 0;
case GIGVER_COMPAT:
memcpy(arg, compat, sizeof compat);
return 0;
case GIGVER_FWBASE:
cs->waiting = 1;
if (!gigaset_add_event(cs, &cs->at_state, EV_IF_VER,
NULL, 0, arg)) {
cs->waiting = 0;
return -ENOMEM;
}
gigaset_schedule_event(cs);
wait_event(cs->waitqueue, !cs->waiting);
if (cs->cmd_result >= 0)
return 0;
return cs->cmd_result;
default:
return -EINVAL;
}
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Hansjoerg Lipp | 175 | 99.43% | 1 | 50.00% |
Tilman Schmidt | 1 | 0.57% | 1 | 50.00% |
Total | 176 | 100.00% | 2 | 100.00% |
static int if_config(struct cardstate *cs, int *arg)
{
gig_dbg(DEBUG_IF, "%u: if_config (%d)", cs->minor_index, *arg);
if (*arg != 1)
return -EINVAL;
if (cs->mstate != MS_LOCKED)
return -EBUSY;
if (!cs->connected) {
pr_err("%s: not connected\n", __func__);
return -ENODEV;
}
*arg = 0;
return gigaset_enterconfigmode(cs);
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Hansjoerg Lipp | 62 | 74.70% | 1 | 25.00% |
Tilman Schmidt | 21 | 25.30% | 3 | 75.00% |
Total | 83 | 100.00% | 4 | 100.00% |
/*** the terminal driver ***/
static int if_open(struct tty_struct *tty, struct file *filp)
{
struct cardstate *cs;
gig_dbg(DEBUG_IF, "%d+%d: %s()",
tty->driver->minor_start, tty->index, __func__);
cs = gigaset_get_cs_by_tty(tty);
if (!cs || !try_module_get(cs->driver->owner))
return -ENODEV;
if (mutex_lock_interruptible(&cs->mutex)) {
module_put(cs->driver->owner);
return -ERESTARTSYS;
}
tty->driver_data = cs;
++cs->port.count;
if (cs->port.count == 1) {
tty_port_tty_set(&cs->port, tty);
cs->port.low_latency = 1;
}
mutex_unlock(&cs->mutex);
return 0;
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Hansjoerg Lipp | 107 | 73.79% | 1 | 14.29% |
Tilman Schmidt | 16 | 11.03% | 3 | 42.86% |
Jiri Slaby | 11 | 7.59% | 2 | 28.57% |
Pavel Shved | 11 | 7.59% | 1 | 14.29% |
Total | 145 | 100.00% | 7 | 100.00% |
static void if_close(struct tty_struct *tty, struct file *filp)
{
struct cardstate *cs = tty->driver_data;
if (!cs) { /* happens if we didn't find cs in open */
gig_dbg(DEBUG_IF, "%s: no cardstate", __func__);
return;
}
gig_dbg(DEBUG_IF, "%u: %s()", cs->minor_index, __func__);
mutex_lock(&cs->mutex);
if (!cs->connected)
gig_dbg(DEBUG_IF, "not connected"); /* nothing to do */
else if (!cs->port.count)
dev_warn(cs->dev, "%s: device not opened\n", __func__);
else if (!--cs->port.count)
tty_port_tty_set(&cs->port, NULL);
mutex_unlock(&cs->mutex);
module_put(cs->driver->owner);
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Hansjoerg Lipp | 81 | 58.70% | 1 | 11.11% |
Tilman Schmidt | 43 | 31.16% | 6 | 66.67% |
Jiri Slaby | 14 | 10.14% | 2 | 22.22% |
Total | 138 | 100.00% | 9 | 100.00% |
static int if_ioctl(struct tty_struct *tty,
unsigned int cmd, unsigned long arg)
{
struct cardstate *cs = tty->driver_data;
int retval = -ENODEV;
int int_arg;
unsigned char buf[6];
unsigned version[4];
gig_dbg(DEBUG_IF, "%u: %s(0x%x)", cs->minor_index, __func__, cmd);
if (mutex_lock_interruptible(&cs->mutex))
return -ERESTARTSYS;
if (!cs->connected) {
gig_dbg(DEBUG_IF, "not connected");
retval = -ENODEV;
} else {
retval = 0;
switch (cmd) {
case GIGASET_REDIR:
retval = get_user(int_arg, (int __user *) arg);
if (retval >= 0)
retval = if_lock(cs, &int_arg);
if (retval >= 0)
retval = put_user(int_arg, (int __user *) arg);
break;
case GIGASET_CONFIG:
retval = get_user(int_arg, (int __user *) arg);
if (retval >= 0)
retval = if_config(cs, &int_arg);
if (retval >= 0)
retval = put_user(int_arg, (int __user *) arg);
break;
case GIGASET_BRKCHARS:
retval = copy_from_user(&buf,
(const unsigned char __user *) arg, 6)
? -EFAULT : 0;
if (retval >= 0) {
gigaset_dbg_buffer(DEBUG_IF, "GIGASET_BRKCHARS",
6, (const unsigned char *) arg);
retval = cs->ops->brkchars(cs, buf);
}
break;
case GIGASET_VERSION:
retval = copy_from_user(version,
(unsigned __user *) arg, sizeof version)
? -EFAULT : 0;
if (retval >= 0)
retval = if_version(cs, version);
if (retval >= 0)
retval = copy_to_user((unsigned __user *) arg,
version, sizeof version)
? -EFAULT : 0;
break;
default:
gig_dbg(DEBUG_IF, "%s: arg not supported - 0x%04x",
__func__, cmd);
retval = -ENOIOCTLCMD;
}
}
mutex_unlock(&cs->mutex);
return retval;
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Hansjoerg Lipp | 336 | 87.50% | 1 | 14.29% |
Tilman Schmidt | 44 | 11.46% | 5 | 71.43% |
Jiri Slaby | 4 | 1.04% | 1 | 14.29% |
Total | 384 | 100.00% | 7 | 100.00% |
static int if_tiocmget(struct tty_struct *tty)
{
struct cardstate *cs = tty->driver_data;
int retval;
gig_dbg(DEBUG_IF, "%u: %s()", cs->minor_index, __func__);
if (mutex_lock_interruptible(&cs->mutex))
return -ERESTARTSYS;
retval = cs->control_state & (TIOCM_RTS | TIOCM_DTR);
mutex_unlock(&cs->mutex);
return retval;
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Hansjoerg Lipp | 63 | 86.30% | 1 | 25.00% |
Tilman Schmidt | 6 | 8.22% | 2 | 50.00% |
Jiri Slaby | 4 | 5.48% | 1 | 25.00% |
Total | 73 | 100.00% | 4 | 100.00% |
static int if_tiocmset(struct tty_struct *tty,
unsigned int set, unsigned int clear)
{
struct cardstate *cs = tty->driver_data;
int retval;
unsigned mc;
gig_dbg(DEBUG_IF, "%u: %s(0x%x, 0x%x)",
cs->minor_index, __func__, set, clear);
if (mutex_lock_interruptible(&cs->mutex))
return -ERESTARTSYS;
if (!cs->connected) {
gig_dbg(DEBUG_IF, "not connected");
retval = -ENODEV;
} else {
mc = (cs->control_state | set) & ~clear & (TIOCM_RTS | TIOCM_DTR);
retval = cs->ops->set_modem_ctrl(cs, cs->control_state, mc);
cs->control_state = mc;
}
mutex_unlock(&cs->mutex);
return retval;
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Hansjoerg Lipp | 129 | 90.85% | 1 | 20.00% |
Tilman Schmidt | 9 | 6.34% | 3 | 60.00% |
Jiri Slaby | 4 | 2.82% | 1 | 20.00% |
Total | 142 | 100.00% | 5 | 100.00% |
static int if_write(struct tty_struct *tty, const unsigned char *buf, int count)
{
struct cardstate *cs = tty->driver_data;
struct cmdbuf_t *cb;
int retval;
gig_dbg(DEBUG_IF, "%u: %s()", cs->minor_index, __func__);
if (mutex_lock_interruptible(&cs->mutex))
return -ERESTARTSYS;
if (!cs->connected) {
gig_dbg(DEBUG_IF, "not connected");
retval = -ENODEV;
goto done;
}
if (cs->mstate != MS_LOCKED) {
dev_warn(cs->dev, "can't write to unlocked device\n");
retval = -EBUSY;
goto done;
}
if (count <= 0) {
/* nothing to do */
retval = 0;
goto done;
}
cb = kmalloc(sizeof(struct cmdbuf_t) + count, GFP_KERNEL);
if (!cb) {
dev_err(cs->dev, "%s: out of memory\n", __func__);
retval = -ENOMEM;
goto done;
}
memcpy(cb->buf, buf, count);
cb->len = count;
cb->offset = 0;
cb->next = NULL;
cb->wake_tasklet = &cs->if_wake_tasklet;
retval = cs->ops->write_cmd(cs, cb);
done:
mutex_unlock(&cs->mutex);
return retval;
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Tilman Schmidt | 135 | 57.20% | 5 | 71.43% |
Hansjoerg Lipp | 97 | 41.10% | 1 | 14.29% |
Jiri Slaby | 4 | 1.69% | 1 | 14.29% |
Total | 236 | 100.00% | 7 | 100.00% |
static int if_write_room(struct tty_struct *tty)
{
struct cardstate *cs = tty->driver_data;
int retval;
gig_dbg(DEBUG_IF, "%u: %s()", cs->minor_index, __func__);
if (mutex_lock_interruptible(&cs->mutex))
return -ERESTARTSYS;
if (!cs->connected) {
gig_dbg(DEBUG_IF, "not connected");
retval = -ENODEV;
} else if (cs->mstate != MS_LOCKED) {
dev_warn(cs->dev, "can't write to unlocked device\n");
retval = -EBUSY;
} else
retval = cs->ops->write_room(cs);
mutex_unlock(&cs->mutex);
return retval;
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Hansjoerg Lipp | 84 | 70.59% | 1 | 16.67% |
Tilman Schmidt | 31 | 26.05% | 4 | 66.67% |
Jiri Slaby | 4 | 3.36% | 1 | 16.67% |
Total | 119 | 100.00% | 6 | 100.00% |
static int if_chars_in_buffer(struct tty_struct *tty)
{
struct cardstate *cs = tty->driver_data;
int retval = 0;
gig_dbg(DEBUG_IF, "%u: %s()", cs->minor_index, __func__);
mutex_lock(&cs->mutex);
if (!cs->connected)
gig_dbg(DEBUG_IF, "not connected");
else if (cs->mstate != MS_LOCKED)
dev_warn(cs->dev, "can't write to unlocked device\n");
else
retval = cs->ops->chars_in_buffer(cs);
mutex_unlock(&cs->mutex);
return retval;
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Hansjoerg Lipp | 71 | 70.30% | 1 | 14.29% |
Tilman Schmidt | 26 | 25.74% | 5 | 71.43% |
Jiri Slaby | 4 | 3.96% | 1 | 14.29% |
Total | 101 | 100.00% | 7 | 100.00% |
static void if_throttle(struct tty_struct *tty)
{
struct cardstate *cs = tty->driver_data;
gig_dbg(DEBUG_IF, "%u: %s()", cs->minor_index, __func__);
mutex_lock(&cs->mutex);
if (!cs->connected)
gig_dbg(DEBUG_IF, "not connected"); /* nothing to do */
else
gig_dbg(DEBUG_IF, "%s: not implemented\n", __func__);
mutex_unlock(&cs->mutex);
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Hansjoerg Lipp | 47 | 63.51% | 1 | 14.29% |
Tilman Schmidt | 25 | 33.78% | 5 | 71.43% |
Jiri Slaby | 2 | 2.70% | 1 | 14.29% |
Total | 74 | 100.00% | 7 | 100.00% |
static void if_unthrottle(struct tty_struct *tty)
{
struct cardstate *cs = tty->driver_data;
gig_dbg(DEBUG_IF, "%u: %s()", cs->minor_index, __func__);
mutex_lock(&cs->mutex);
if (!cs->connected)
gig_dbg(DEBUG_IF, "not connected"); /* nothing to do */
else
gig_dbg(DEBUG_IF, "%s: not implemented\n", __func__);
mutex_unlock(&cs->mutex);
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Hansjoerg Lipp | 47 | 63.51% | 1 | 14.29% |
Tilman Schmidt | 25 | 33.78% | 5 | 71.43% |
Jiri Slaby | 2 | 2.70% | 1 | 14.29% |
Total | 74 | 100.00% | 7 | 100.00% |
static void if_set_termios(struct tty_struct *tty, struct ktermios *old)
{
struct cardstate *cs = tty->driver_data;
unsigned int iflag;
unsigned int cflag;
unsigned int old_cflag;
unsigned int control_state, new_state;
gig_dbg(DEBUG_IF, "%u: %s()", cs->minor_index, __func__);
mutex_lock(&cs->mutex);
if (!cs->connected) {
gig_dbg(DEBUG_IF, "not connected");
goto out;
}
iflag = tty->termios.c_iflag;
cflag = tty->termios.c_cflag;
old_cflag = old ? old->c_cflag : cflag;
gig_dbg(DEBUG_IF, "%u: iflag %x cflag %x old %x",
cs->minor_index, iflag, cflag, old_cflag);
/* get a local copy of the current port settings */
control_state = cs->control_state;
/*
* Update baud rate.
* Do not attempt to cache old rates and skip settings,
* disconnects screw such tricks up completely.
* Premature optimization is the root of all evil.
*/
/* reassert DTR and (maybe) RTS on transition from B0 */
if ((old_cflag & CBAUD) == B0) {
new_state = control_state | TIOCM_DTR;
/* don't set RTS if using hardware flow control */
if (!(old_cflag & CRTSCTS))
new_state |= TIOCM_RTS;
gig_dbg(DEBUG_IF, "%u: from B0 - set DTR%s",
cs->minor_index,
(new_state & TIOCM_RTS) ? " only" : "/RTS");
cs->ops->set_modem_ctrl(cs, control_state, new_state);
control_state = new_state;
}
cs->ops->baud_rate(cs, cflag & CBAUD);
if ((cflag & CBAUD) == B0) {
/* Drop RTS and DTR */
gig_dbg(DEBUG_IF, "%u: to B0 - drop DTR/RTS", cs->minor_index);
new_state = control_state & ~(TIOCM_DTR | TIOCM_RTS);
cs->ops->set_modem_ctrl(cs, control_state, new_state);
control_state = new_state;
}
/*
* Update line control register (LCR)
*/
cs->ops->set_line_ctrl(cs, cflag);
/* save off the modified port settings */
cs->control_state = control_state;
out:
mutex_unlock(&cs->mutex);
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Hansjoerg Lipp | 279 | 93.31% | 1 | 14.29% |
Tilman Schmidt | 13 | 4.35% | 3 | 42.86% |
Jiri Slaby | 4 | 1.34% | 1 | 14.29% |
Alan Cox | 3 | 1.00% | 2 | 28.57% |
Total | 299 | 100.00% | 7 | 100.00% |
static const struct tty_operations if_ops = {
.open = if_open,
.close = if_close,
.ioctl = if_ioctl,
.write = if_write,
.write_room = if_write_room,
.chars_in_buffer = if_chars_in_buffer,
.set_termios = if_set_termios,
.throttle = if_throttle,
.unthrottle = if_unthrottle,
.tiocmget = if_tiocmget,
.tiocmset = if_tiocmset,
};
/* wakeup tasklet for the write operation */
static void if_wake(unsigned long data)
{
struct cardstate *cs = (struct cardstate *)data;
tty_port_tty_wakeup(&cs->port);
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Hansjoerg Lipp | 24 | 80.00% | 1 | 25.00% |
Jiri Slaby | 6 | 20.00% | 3 | 75.00% |
Total | 30 | 100.00% | 4 | 100.00% |
/*** interface to common ***/
void gigaset_if_init(struct cardstate *cs)
{
struct gigaset_driver *drv;
drv = cs->driver;
if (!drv->have_tty)
return;
tasklet_init(&cs->if_wake_tasklet, if_wake, (unsigned long) cs);
mutex_lock(&cs->mutex);
cs->tty_dev = tty_port_register_device(&cs->port, drv->tty,
cs->minor_index, NULL);
if (!IS_ERR(cs->tty_dev))
dev_set_drvdata(cs->tty_dev, cs);
else {
pr_warning("could not register device to the tty subsystem\n");
cs->tty_dev = NULL;
}
mutex_unlock(&cs->mutex);
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Hansjoerg Lipp | 87 | 75.00% | 2 | 28.57% |
Tilman Schmidt | 18 | 15.52% | 3 | 42.86% |
Jiri Slaby | 6 | 5.17% | 1 | 14.29% |
Greg Kroah-Hartman | 5 | 4.31% | 1 | 14.29% |
Total | 116 | 100.00% | 7 | 100.00% |
void gigaset_if_free(struct cardstate *cs)
{
struct gigaset_driver *drv;
drv = cs->driver;
if (!drv->have_tty)
return;
tasklet_disable(&cs->if_wake_tasklet);
tasklet_kill(&cs->if_wake_tasklet);
cs->tty_dev = NULL;
tty_unregister_device(drv->tty, cs->minor_index);
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Hansjoerg Lipp | 61 | 98.39% | 2 | 66.67% |
Greg Kroah-Hartman | 1 | 1.61% | 1 | 33.33% |
Total | 62 | 100.00% | 3 | 100.00% |
/**
* gigaset_if_receive() - pass a received block of data to the tty device
* @cs: device descriptor structure.
* @buffer: received data.
* @len: number of bytes received.
*
* Called by asyncdata/isocdata if a block of data received from the
* device must be sent to userspace through the ttyG* device.
*/
void gigaset_if_receive(struct cardstate *cs,
unsigned char *buffer, size_t len)
{
tty_insert_flip_string(&cs->port, buffer, len);
tty_flip_buffer_push(&cs->port);
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Hansjoerg Lipp | 33 | 86.84% | 1 | 33.33% |
Jiri Slaby | 5 | 13.16% | 2 | 66.67% |
Total | 38 | 100.00% | 3 | 100.00% |
EXPORT_SYMBOL_GPL(gigaset_if_receive);
/* gigaset_if_initdriver
* Initialize tty interface.
* parameters:
* drv Driver
* procname Name of the driver (e.g. for /proc/tty/drivers)
* devname Name of the device files (prefix without minor number)
*/
void gigaset_if_initdriver(struct gigaset_driver *drv, const char *procname,
const char *devname)
{
int ret;
struct tty_driver *tty;
drv->have_tty = 0;
drv->tty = tty = alloc_tty_driver(drv->minors);
if (tty == NULL)
goto enomem;
tty->type = TTY_DRIVER_TYPE_SERIAL;
tty->subtype = SERIAL_TYPE_NORMAL;
tty->flags = TTY_DRIVER_REAL_RAW | TTY_DRIVER_DYNAMIC_DEV;
tty->driver_name = procname;
tty->name = devname;
tty->minor_start = drv->minor;
tty->init_termios = tty_std_termios;
tty->init_termios.c_cflag = B9600 | CS8 | CREAD | HUPCL | CLOCAL;
tty_set_operations(tty, &if_ops);
ret = tty_register_driver(tty);
if (ret < 0) {
pr_err("error %d registering tty driver\n", ret);
goto error;
}
gig_dbg(DEBUG_IF, "tty driver initialized");
drv->have_tty = 1;
return;
enomem:
pr_err("out of memory\n");
error:
if (drv->tty)
put_tty_driver(drv->tty);
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Hansjoerg Lipp | 170 | 90.91% | 1 | 14.29% |
Tilman Schmidt | 11 | 5.88% | 3 | 42.86% |
Joe Perches | 2 | 1.07% | 1 | 14.29% |
Jiri Slaby | 2 | 1.07% | 1 | 14.29% |
Greg Kroah-Hartman | 2 | 1.07% | 1 | 14.29% |
Total | 187 | 100.00% | 7 | 100.00% |
void gigaset_if_freedriver(struct gigaset_driver *drv)
{
if (!drv->have_tty)
return;
drv->have_tty = 0;
tty_unregister_driver(drv->tty);
put_tty_driver(drv->tty);
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Hansjoerg Lipp | 38 | 100.00% | 1 | 100.00% |
Total | 38 | 100.00% | 1 | 100.00% |
Overall Contributors
Person | Tokens | Prop | Commits | CommitProp |
Hansjoerg Lipp | 2215 | 78.85% | 2 | 5.56% |
Tilman Schmidt | 490 | 17.44% | 18 | 50.00% |
Jiri Slaby | 76 | 2.71% | 8 | 22.22% |
Pavel Shved | 11 | 0.39% | 1 | 2.78% |
Greg Kroah-Hartman | 9 | 0.32% | 3 | 8.33% |
Paul Gortmaker | 3 | 0.11% | 1 | 2.78% |
Alan Cox | 3 | 0.11% | 2 | 5.56% |
Joe Perches | 2 | 0.07% | 1 | 2.78% |
Total | 2809 | 100.00% | 36 | 100.00% |
Information contained on this website is for historical information purposes only and does not indicate or represent copyright ownership.