2005-04-17 06:20:36 +08:00
|
|
|
/*********************************************************************
|
2007-02-09 22:24:53 +08:00
|
|
|
*
|
2005-04-17 06:20:36 +08:00
|
|
|
* Filename: ircomm_tty.c
|
|
|
|
* Version: 1.0
|
|
|
|
* Description: IrCOMM serial TTY driver
|
|
|
|
* Status: Experimental.
|
|
|
|
* Author: Dag Brattli <dagb@cs.uit.no>
|
|
|
|
* Created at: Sun Jun 6 21:00:56 1999
|
|
|
|
* Modified at: Wed Feb 23 00:09:02 2000
|
|
|
|
* Modified by: Dag Brattli <dagb@cs.uit.no>
|
|
|
|
* Sources: serial.c and previous IrCOMM work by Takahide Higuchi
|
2007-02-09 22:24:53 +08:00
|
|
|
*
|
2005-04-17 06:20:36 +08:00
|
|
|
* Copyright (c) 1999-2000 Dag Brattli, All Rights Reserved.
|
|
|
|
* Copyright (c) 2000-2003 Jean Tourrilhes <jt@hpl.hp.com>
|
2007-02-09 22:24:53 +08:00
|
|
|
*
|
|
|
|
* 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
|
2005-04-17 06:20:36 +08:00
|
|
|
* the License, or (at your option) any later version.
|
2007-02-09 22:24:53 +08:00
|
|
|
*
|
2005-04-17 06:20:36 +08:00
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
2007-02-09 22:24:53 +08:00
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston,
|
2005-04-17 06:20:36 +08:00
|
|
|
* MA 02111-1307 USA
|
2007-02-09 22:24:53 +08:00
|
|
|
*
|
2005-04-17 06:20:36 +08:00
|
|
|
********************************************************************/
|
|
|
|
|
|
|
|
#include <linux/init.h>
|
|
|
|
#include <linux/module.h>
|
|
|
|
#include <linux/fs.h>
|
include cleanup: Update gfp.h and slab.h includes to prepare for breaking implicit slab.h inclusion from percpu.h
percpu.h is included by sched.h and module.h and thus ends up being
included when building most .c files. percpu.h includes slab.h which
in turn includes gfp.h making everything defined by the two files
universally available and complicating inclusion dependencies.
percpu.h -> slab.h dependency is about to be removed. Prepare for
this change by updating users of gfp and slab facilities include those
headers directly instead of assuming availability. As this conversion
needs to touch large number of source files, the following script is
used as the basis of conversion.
http://userweb.kernel.org/~tj/misc/slabh-sweep.py
The script does the followings.
* Scan files for gfp and slab usages and update includes such that
only the necessary includes are there. ie. if only gfp is used,
gfp.h, if slab is used, slab.h.
* When the script inserts a new include, it looks at the include
blocks and try to put the new include such that its order conforms
to its surrounding. It's put in the include block which contains
core kernel includes, in the same order that the rest are ordered -
alphabetical, Christmas tree, rev-Xmas-tree or at the end if there
doesn't seem to be any matching order.
* If the script can't find a place to put a new include (mostly
because the file doesn't have fitting include block), it prints out
an error message indicating which .h file needs to be added to the
file.
The conversion was done in the following steps.
1. The initial automatic conversion of all .c files updated slightly
over 4000 files, deleting around 700 includes and adding ~480 gfp.h
and ~3000 slab.h inclusions. The script emitted errors for ~400
files.
2. Each error was manually checked. Some didn't need the inclusion,
some needed manual addition while adding it to implementation .h or
embedding .c file was more appropriate for others. This step added
inclusions to around 150 files.
3. The script was run again and the output was compared to the edits
from #2 to make sure no file was left behind.
4. Several build tests were done and a couple of problems were fixed.
e.g. lib/decompress_*.c used malloc/free() wrappers around slab
APIs requiring slab.h to be added manually.
5. The script was run on all .h files but without automatically
editing them as sprinkling gfp.h and slab.h inclusions around .h
files could easily lead to inclusion dependency hell. Most gfp.h
inclusion directives were ignored as stuff from gfp.h was usually
wildly available and often used in preprocessor macros. Each
slab.h inclusion directive was examined and added manually as
necessary.
6. percpu.h was updated not to include slab.h.
7. Build test were done on the following configurations and failures
were fixed. CONFIG_GCOV_KERNEL was turned off for all tests (as my
distributed build env didn't work with gcov compiles) and a few
more options had to be turned off depending on archs to make things
build (like ipr on powerpc/64 which failed due to missing writeq).
* x86 and x86_64 UP and SMP allmodconfig and a custom test config.
* powerpc and powerpc64 SMP allmodconfig
* sparc and sparc64 SMP allmodconfig
* ia64 SMP allmodconfig
* s390 SMP allmodconfig
* alpha SMP allmodconfig
* um on x86_64 SMP allmodconfig
8. percpu.h modifications were reverted so that it could be applied as
a separate patch and serve as bisection point.
Given the fact that I had only a couple of failures from tests on step
6, I'm fairly confident about the coverage of this conversion patch.
If there is a breakage, it's likely to be something in one of the arch
headers which should be easily discoverable easily on most builds of
the specific arch.
Signed-off-by: Tejun Heo <tj@kernel.org>
Guess-its-ok-by: Christoph Lameter <cl@linux-foundation.org>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Lee Schermerhorn <Lee.Schermerhorn@hp.com>
2010-03-24 16:04:11 +08:00
|
|
|
#include <linux/slab.h>
|
2005-04-17 06:20:36 +08:00
|
|
|
#include <linux/sched.h>
|
2009-04-01 06:19:22 +08:00
|
|
|
#include <linux/seq_file.h>
|
2005-04-17 06:20:36 +08:00
|
|
|
#include <linux/termios.h>
|
|
|
|
#include <linux/tty.h>
|
2011-05-12 09:04:40 +08:00
|
|
|
#include <linux/tty_flip.h>
|
2005-04-17 06:20:36 +08:00
|
|
|
#include <linux/interrupt.h>
|
|
|
|
#include <linux/device.h> /* for MODULE_ALIAS_CHARDEV_MAJOR */
|
|
|
|
|
|
|
|
#include <asm/uaccess.h>
|
|
|
|
|
|
|
|
#include <net/irda/irda.h>
|
|
|
|
#include <net/irda/irmod.h>
|
|
|
|
|
|
|
|
#include <net/irda/ircomm_core.h>
|
|
|
|
#include <net/irda/ircomm_param.h>
|
|
|
|
#include <net/irda/ircomm_tty_attach.h>
|
|
|
|
#include <net/irda/ircomm_tty.h>
|
|
|
|
|
2012-08-08 03:48:02 +08:00
|
|
|
static int ircomm_tty_install(struct tty_driver *driver,
|
|
|
|
struct tty_struct *tty);
|
2005-04-17 06:20:36 +08:00
|
|
|
static int ircomm_tty_open(struct tty_struct *tty, struct file *filp);
|
|
|
|
static void ircomm_tty_close(struct tty_struct * tty, struct file *filp);
|
|
|
|
static int ircomm_tty_write(struct tty_struct * tty,
|
|
|
|
const unsigned char *buf, int count);
|
|
|
|
static int ircomm_tty_write_room(struct tty_struct *tty);
|
|
|
|
static void ircomm_tty_throttle(struct tty_struct *tty);
|
|
|
|
static void ircomm_tty_unthrottle(struct tty_struct *tty);
|
|
|
|
static int ircomm_tty_chars_in_buffer(struct tty_struct *tty);
|
|
|
|
static void ircomm_tty_flush_buffer(struct tty_struct *tty);
|
|
|
|
static void ircomm_tty_send_xchar(struct tty_struct *tty, char ch);
|
|
|
|
static void ircomm_tty_wait_until_sent(struct tty_struct *tty, int timeout);
|
|
|
|
static void ircomm_tty_hangup(struct tty_struct *tty);
|
2006-11-22 22:57:56 +08:00
|
|
|
static void ircomm_tty_do_softint(struct work_struct *work);
|
2005-04-17 06:20:36 +08:00
|
|
|
static void ircomm_tty_shutdown(struct ircomm_tty_cb *self);
|
|
|
|
static void ircomm_tty_stop(struct tty_struct *tty);
|
|
|
|
|
|
|
|
static int ircomm_tty_data_indication(void *instance, void *sap,
|
|
|
|
struct sk_buff *skb);
|
|
|
|
static int ircomm_tty_control_indication(void *instance, void *sap,
|
|
|
|
struct sk_buff *skb);
|
2007-02-09 22:24:53 +08:00
|
|
|
static void ircomm_tty_flow_indication(void *instance, void *sap,
|
2005-04-17 06:20:36 +08:00
|
|
|
LOCAL_FLOW cmd);
|
|
|
|
#ifdef CONFIG_PROC_FS
|
2009-04-01 06:19:22 +08:00
|
|
|
static const struct file_operations ircomm_tty_proc_fops;
|
2005-04-17 06:20:36 +08:00
|
|
|
#endif /* CONFIG_PROC_FS */
|
|
|
|
static struct tty_driver *driver;
|
|
|
|
|
2007-10-26 18:56:43 +08:00
|
|
|
static hashbin_t *ircomm_tty = NULL;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2006-10-02 17:17:18 +08:00
|
|
|
static const struct tty_operations ops = {
|
2012-08-08 03:48:02 +08:00
|
|
|
.install = ircomm_tty_install,
|
2005-04-17 06:20:36 +08:00
|
|
|
.open = ircomm_tty_open,
|
|
|
|
.close = ircomm_tty_close,
|
|
|
|
.write = ircomm_tty_write,
|
|
|
|
.write_room = ircomm_tty_write_room,
|
|
|
|
.chars_in_buffer = ircomm_tty_chars_in_buffer,
|
|
|
|
.flush_buffer = ircomm_tty_flush_buffer,
|
|
|
|
.ioctl = ircomm_tty_ioctl, /* ircomm_tty_ioctl.c */
|
|
|
|
.tiocmget = ircomm_tty_tiocmget, /* ircomm_tty_ioctl.c */
|
|
|
|
.tiocmset = ircomm_tty_tiocmset, /* ircomm_tty_ioctl.c */
|
|
|
|
.throttle = ircomm_tty_throttle,
|
|
|
|
.unthrottle = ircomm_tty_unthrottle,
|
|
|
|
.send_xchar = ircomm_tty_send_xchar,
|
|
|
|
.set_termios = ircomm_tty_set_termios,
|
|
|
|
.stop = ircomm_tty_stop,
|
|
|
|
.start = ircomm_tty_start,
|
|
|
|
.hangup = ircomm_tty_hangup,
|
|
|
|
.wait_until_sent = ircomm_tty_wait_until_sent,
|
|
|
|
#ifdef CONFIG_PROC_FS
|
2009-04-01 06:19:22 +08:00
|
|
|
.proc_fops = &ircomm_tty_proc_fops,
|
2005-04-17 06:20:36 +08:00
|
|
|
#endif /* CONFIG_PROC_FS */
|
|
|
|
};
|
|
|
|
|
2012-06-04 19:35:23 +08:00
|
|
|
static void ircomm_port_raise_dtr_rts(struct tty_port *port, int raise)
|
|
|
|
{
|
|
|
|
struct ircomm_tty_cb *self = container_of(port, struct ircomm_tty_cb,
|
|
|
|
port);
|
|
|
|
/*
|
|
|
|
* Here, we use to lock those two guys, but as ircomm_param_request()
|
|
|
|
* does it itself, I don't see the point (and I see the deadlock).
|
|
|
|
* Jean II
|
|
|
|
*/
|
|
|
|
if (raise)
|
|
|
|
self->settings.dte |= IRCOMM_RTS | IRCOMM_DTR;
|
|
|
|
else
|
|
|
|
self->settings.dte &= ~(IRCOMM_RTS | IRCOMM_DTR);
|
|
|
|
|
|
|
|
ircomm_param_request(self, IRCOMM_DTE, TRUE);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int ircomm_port_carrier_raised(struct tty_port *port)
|
|
|
|
{
|
|
|
|
struct ircomm_tty_cb *self = container_of(port, struct ircomm_tty_cb,
|
|
|
|
port);
|
|
|
|
return self->settings.dce & IRCOMM_CD;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const struct tty_port_operations ircomm_port_ops = {
|
|
|
|
.dtr_rts = ircomm_port_raise_dtr_rts,
|
|
|
|
.carrier_raised = ircomm_port_carrier_raised,
|
|
|
|
};
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
/*
|
|
|
|
* Function ircomm_tty_init()
|
|
|
|
*
|
|
|
|
* Init IrCOMM TTY layer/driver
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
static int __init ircomm_tty_init(void)
|
|
|
|
{
|
|
|
|
driver = alloc_tty_driver(IRCOMM_TTY_PORTS);
|
|
|
|
if (!driver)
|
|
|
|
return -ENOMEM;
|
2007-02-09 22:24:53 +08:00
|
|
|
ircomm_tty = hashbin_new(HB_LOCK);
|
2005-04-17 06:20:36 +08:00
|
|
|
if (ircomm_tty == NULL) {
|
2008-03-06 12:47:47 +08:00
|
|
|
IRDA_ERROR("%s(), can't allocate hashbin!\n", __func__);
|
2005-04-17 06:20:36 +08:00
|
|
|
put_tty_driver(driver);
|
|
|
|
return -ENOMEM;
|
|
|
|
}
|
|
|
|
|
|
|
|
driver->driver_name = "ircomm";
|
|
|
|
driver->name = "ircomm";
|
|
|
|
driver->major = IRCOMM_TTY_MAJOR;
|
|
|
|
driver->minor_start = IRCOMM_TTY_MINOR;
|
|
|
|
driver->type = TTY_DRIVER_TYPE_SERIAL;
|
|
|
|
driver->subtype = SERIAL_TYPE_NORMAL;
|
|
|
|
driver->init_termios = tty_std_termios;
|
|
|
|
driver->init_termios.c_cflag = B9600 | CS8 | CREAD | HUPCL | CLOCAL;
|
|
|
|
driver->flags = TTY_DRIVER_REAL_RAW;
|
|
|
|
tty_set_operations(driver, &ops);
|
|
|
|
if (tty_register_driver(driver)) {
|
|
|
|
IRDA_ERROR("%s(): Couldn't register serial driver\n",
|
2008-03-06 12:47:47 +08:00
|
|
|
__func__);
|
2005-04-17 06:20:36 +08:00
|
|
|
put_tty_driver(driver);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void __exit __ircomm_tty_cleanup(struct ircomm_tty_cb *self)
|
|
|
|
{
|
2008-03-06 12:47:47 +08:00
|
|
|
IRDA_DEBUG(0, "%s()\n", __func__ );
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
IRDA_ASSERT(self != NULL, return;);
|
|
|
|
IRDA_ASSERT(self->magic == IRCOMM_TTY_MAGIC, return;);
|
|
|
|
|
|
|
|
ircomm_tty_shutdown(self);
|
|
|
|
|
|
|
|
self->magic = 0;
|
2012-11-15 16:49:56 +08:00
|
|
|
tty_port_destroy(&self->port);
|
2005-04-17 06:20:36 +08:00
|
|
|
kfree(self);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Function ircomm_tty_cleanup ()
|
|
|
|
*
|
|
|
|
* Remove IrCOMM TTY layer/driver
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
static void __exit ircomm_tty_cleanup(void)
|
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
|
2008-03-06 12:47:47 +08:00
|
|
|
IRDA_DEBUG(4, "%s()\n", __func__ );
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
ret = tty_unregister_driver(driver);
|
2007-02-09 22:24:53 +08:00
|
|
|
if (ret) {
|
|
|
|
IRDA_ERROR("%s(), failed to unregister driver\n",
|
2008-03-06 12:47:47 +08:00
|
|
|
__func__);
|
2005-04-17 06:20:36 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
hashbin_delete(ircomm_tty, (FREE_FUNC) __ircomm_tty_cleanup);
|
|
|
|
put_tty_driver(driver);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Function ircomm_startup (self)
|
|
|
|
*
|
2007-02-09 22:24:53 +08:00
|
|
|
*
|
2005-04-17 06:20:36 +08:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
static int ircomm_tty_startup(struct ircomm_tty_cb *self)
|
|
|
|
{
|
|
|
|
notify_t notify;
|
|
|
|
int ret = -ENODEV;
|
|
|
|
|
2008-03-06 12:47:47 +08:00
|
|
|
IRDA_DEBUG(2, "%s()\n", __func__ );
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
IRDA_ASSERT(self != NULL, return -1;);
|
|
|
|
IRDA_ASSERT(self->magic == IRCOMM_TTY_MAGIC, return -1;);
|
|
|
|
|
|
|
|
/* Check if already open */
|
2012-06-04 19:35:19 +08:00
|
|
|
if (test_and_set_bit(ASYNCB_INITIALIZED, &self->port.flags)) {
|
2008-03-06 12:47:47 +08:00
|
|
|
IRDA_DEBUG(2, "%s(), already open so break out!\n", __func__ );
|
2005-04-17 06:20:36 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Register with IrCOMM */
|
|
|
|
irda_notify_init(¬ify);
|
|
|
|
/* These callbacks we must handle ourselves */
|
|
|
|
notify.data_indication = ircomm_tty_data_indication;
|
|
|
|
notify.udata_indication = ircomm_tty_control_indication;
|
2007-02-09 22:24:53 +08:00
|
|
|
notify.flow_indication = ircomm_tty_flow_indication;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
/* Use the ircomm_tty interface for these ones */
|
2007-02-09 22:24:53 +08:00
|
|
|
notify.disconnect_indication = ircomm_tty_disconnect_indication;
|
2005-04-17 06:20:36 +08:00
|
|
|
notify.connect_confirm = ircomm_tty_connect_confirm;
|
2007-02-09 22:24:53 +08:00
|
|
|
notify.connect_indication = ircomm_tty_connect_indication;
|
2005-04-17 06:20:36 +08:00
|
|
|
strlcpy(notify.name, "ircomm_tty", sizeof(notify.name));
|
|
|
|
notify.instance = self;
|
|
|
|
|
|
|
|
if (!self->ircomm) {
|
2007-02-09 22:24:53 +08:00
|
|
|
self->ircomm = ircomm_open(¬ify, self->service_type,
|
2005-04-17 06:20:36 +08:00
|
|
|
self->line);
|
|
|
|
}
|
|
|
|
if (!self->ircomm)
|
|
|
|
goto err;
|
|
|
|
|
|
|
|
self->slsap_sel = self->ircomm->slsap_sel;
|
|
|
|
|
|
|
|
/* Connect IrCOMM link with remote device */
|
|
|
|
ret = ircomm_tty_attach_cable(self);
|
|
|
|
if (ret < 0) {
|
2008-03-06 12:47:47 +08:00
|
|
|
IRDA_ERROR("%s(), error attaching cable!\n", __func__);
|
2005-04-17 06:20:36 +08:00
|
|
|
goto err;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
err:
|
2012-06-04 19:35:19 +08:00
|
|
|
clear_bit(ASYNCB_INITIALIZED, &self->port.flags);
|
2005-04-17 06:20:36 +08:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Function ircomm_block_til_ready (self, filp)
|
|
|
|
*
|
2007-02-09 22:24:53 +08:00
|
|
|
*
|
2005-04-17 06:20:36 +08:00
|
|
|
*
|
|
|
|
*/
|
2007-02-09 22:24:53 +08:00
|
|
|
static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
|
2012-06-04 19:35:21 +08:00
|
|
|
struct tty_struct *tty, struct file *filp)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2012-06-04 19:35:22 +08:00
|
|
|
struct tty_port *port = &self->port;
|
2005-04-17 06:20:36 +08:00
|
|
|
DECLARE_WAITQUEUE(wait, current);
|
|
|
|
int retval;
|
2013-03-05 14:09:04 +08:00
|
|
|
int do_clocal = 0;
|
2005-04-17 06:20:36 +08:00
|
|
|
unsigned long flags;
|
2007-02-09 22:24:53 +08:00
|
|
|
|
2008-03-06 12:47:47 +08:00
|
|
|
IRDA_DEBUG(2, "%s()\n", __func__ );
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* If non-blocking mode is set, or the port is not enabled,
|
|
|
|
* then make the check up front and then exit.
|
2007-02-09 22:24:53 +08:00
|
|
|
*/
|
2005-04-17 06:20:36 +08:00
|
|
|
if (filp->f_flags & O_NONBLOCK || tty->flags & (1 << TTY_IO_ERROR)){
|
|
|
|
/* nonblock mode is set or port is not enabled */
|
2012-06-04 19:35:22 +08:00
|
|
|
port->flags |= ASYNC_NORMAL_ACTIVE;
|
2008-03-06 12:47:47 +08:00
|
|
|
IRDA_DEBUG(1, "%s(), O_NONBLOCK requested!\n", __func__ );
|
2005-04-17 06:20:36 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2012-07-14 22:31:47 +08:00
|
|
|
if (tty->termios.c_cflag & CLOCAL) {
|
2008-03-06 12:47:47 +08:00
|
|
|
IRDA_DEBUG(1, "%s(), doing CLOCAL!\n", __func__ );
|
2005-04-17 06:20:36 +08:00
|
|
|
do_clocal = 1;
|
|
|
|
}
|
2007-02-09 22:24:53 +08:00
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
/* Wait for carrier detect and the line to become
|
|
|
|
* free (i.e., not in use by the callout). While we are in
|
2012-06-04 19:35:22 +08:00
|
|
|
* this loop, port->count is dropped by one, so that
|
2005-04-17 06:20:36 +08:00
|
|
|
* mgsl_close() knows when to free things. We restore it upon
|
|
|
|
* exit, either normal or abnormal.
|
|
|
|
*/
|
2007-02-09 22:24:53 +08:00
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
retval = 0;
|
2012-06-04 19:35:22 +08:00
|
|
|
add_wait_queue(&port->open_wait, &wait);
|
2007-02-09 22:24:53 +08:00
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
IRDA_DEBUG(2, "%s(%d):block_til_ready before block on %s open_count=%d\n",
|
2012-06-04 19:35:22 +08:00
|
|
|
__FILE__, __LINE__, tty->driver->name, port->count);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2012-06-04 19:35:22 +08:00
|
|
|
spin_lock_irqsave(&port->lock, flags);
|
2013-03-05 14:09:04 +08:00
|
|
|
if (!tty_hung_up_p(filp))
|
2012-06-04 19:35:22 +08:00
|
|
|
port->count--;
|
|
|
|
spin_unlock_irqrestore(&port->lock, flags);
|
|
|
|
port->blocked_open++;
|
2007-02-09 22:24:53 +08:00
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
while (1) {
|
2012-07-14 22:31:47 +08:00
|
|
|
if (tty->termios.c_cflag & CBAUD)
|
2012-06-04 19:35:23 +08:00
|
|
|
tty_port_raise_dtr_rts(port);
|
2007-02-09 22:24:53 +08:00
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
current->state = TASK_INTERRUPTIBLE;
|
2007-02-09 22:24:53 +08:00
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
if (tty_hung_up_p(filp) ||
|
2012-06-04 19:35:22 +08:00
|
|
|
!test_bit(ASYNCB_INITIALIZED, &port->flags)) {
|
|
|
|
retval = (port->flags & ASYNC_HUP_NOTIFY) ?
|
2005-04-17 06:20:36 +08:00
|
|
|
-EAGAIN : -ERESTARTSYS;
|
|
|
|
break;
|
|
|
|
}
|
2007-02-09 22:24:53 +08:00
|
|
|
|
|
|
|
/*
|
2005-04-17 06:20:36 +08:00
|
|
|
* Check if link is ready now. Even if CLOCAL is
|
|
|
|
* specified, we cannot return before the IrCOMM link is
|
2007-02-09 22:24:53 +08:00
|
|
|
* ready
|
2005-04-17 06:20:36 +08:00
|
|
|
*/
|
2012-06-04 19:35:22 +08:00
|
|
|
if (!test_bit(ASYNCB_CLOSING, &port->flags) &&
|
2012-06-04 19:35:23 +08:00
|
|
|
(do_clocal || tty_port_carrier_raised(port)) &&
|
2005-04-17 06:20:36 +08:00
|
|
|
self->state == IRCOMM_TTY_READY)
|
|
|
|
{
|
2007-02-09 22:24:53 +08:00
|
|
|
break;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
2007-02-09 22:24:53 +08:00
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
if (signal_pending(current)) {
|
|
|
|
retval = -ERESTARTSYS;
|
|
|
|
break;
|
|
|
|
}
|
2007-02-09 22:24:53 +08:00
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
IRDA_DEBUG(1, "%s(%d):block_til_ready blocking on %s open_count=%d\n",
|
2012-06-04 19:35:22 +08:00
|
|
|
__FILE__, __LINE__, tty->driver->name, port->count);
|
2007-02-09 22:24:53 +08:00
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
schedule();
|
|
|
|
}
|
2007-02-09 22:24:53 +08:00
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
__set_current_state(TASK_RUNNING);
|
2012-06-04 19:35:22 +08:00
|
|
|
remove_wait_queue(&port->open_wait, &wait);
|
2007-02-09 22:24:53 +08:00
|
|
|
|
2013-03-05 14:09:04 +08:00
|
|
|
spin_lock_irqsave(&port->lock, flags);
|
|
|
|
if (!tty_hung_up_p(filp))
|
2012-06-04 19:35:22 +08:00
|
|
|
port->count++;
|
2013-03-05 14:09:04 +08:00
|
|
|
spin_unlock_irqrestore(&port->lock, flags);
|
2012-06-04 19:35:22 +08:00
|
|
|
port->blocked_open--;
|
2007-02-09 22:24:53 +08:00
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
IRDA_DEBUG(1, "%s(%d):block_til_ready after blocking on %s open_count=%d\n",
|
2012-06-04 19:35:22 +08:00
|
|
|
__FILE__, __LINE__, tty->driver->name, port->count);
|
2007-02-09 22:24:53 +08:00
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
if (!retval)
|
2012-06-04 19:35:22 +08:00
|
|
|
port->flags |= ASYNC_NORMAL_ACTIVE;
|
2007-02-09 22:24:53 +08:00
|
|
|
|
|
|
|
return retval;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
2012-08-08 03:48:02 +08:00
|
|
|
|
|
|
|
static int ircomm_tty_install(struct tty_driver *driver, struct tty_struct *tty)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
struct ircomm_tty_cb *self;
|
2012-03-05 21:52:01 +08:00
|
|
|
unsigned int line = tty->index;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
/* Check if instance already exists */
|
|
|
|
self = hashbin_lock_find(ircomm_tty, line, NULL);
|
|
|
|
if (!self) {
|
|
|
|
/* No, so make new instance */
|
2006-07-22 05:51:30 +08:00
|
|
|
self = kzalloc(sizeof(struct ircomm_tty_cb), GFP_KERNEL);
|
2005-04-17 06:20:36 +08:00
|
|
|
if (self == NULL) {
|
2008-03-06 12:47:47 +08:00
|
|
|
IRDA_ERROR("%s(), kmalloc failed!\n", __func__);
|
2005-04-17 06:20:36 +08:00
|
|
|
return -ENOMEM;
|
|
|
|
}
|
2007-02-09 22:24:53 +08:00
|
|
|
|
2012-06-04 19:35:16 +08:00
|
|
|
tty_port_init(&self->port);
|
2012-06-04 19:35:23 +08:00
|
|
|
self->port.ops = &ircomm_port_ops;
|
2005-04-17 06:20:36 +08:00
|
|
|
self->magic = IRCOMM_TTY_MAGIC;
|
|
|
|
self->flow = FLOW_STOP;
|
|
|
|
|
|
|
|
self->line = line;
|
2006-11-22 22:57:56 +08:00
|
|
|
INIT_WORK(&self->tqueue, ircomm_tty_do_softint);
|
2005-04-17 06:20:36 +08:00
|
|
|
self->max_header_size = IRCOMM_TTY_HDR_UNINITIALISED;
|
|
|
|
self->max_data_size = IRCOMM_TTY_DATA_UNINITIALISED;
|
|
|
|
|
|
|
|
/* Init some important stuff */
|
|
|
|
init_timer(&self->watchdog_timer);
|
|
|
|
spin_lock_init(&self->spinlock);
|
|
|
|
|
2007-02-09 22:24:53 +08:00
|
|
|
/*
|
2005-04-17 06:20:36 +08:00
|
|
|
* Force TTY into raw mode by default which is usually what
|
|
|
|
* we want for IrCOMM and IrLPT. This way applications will
|
2007-02-09 22:24:53 +08:00
|
|
|
* not have to twiddle with printcap etc.
|
2009-01-02 21:50:20 +08:00
|
|
|
*
|
|
|
|
* Note this is completely usafe and doesn't work properly
|
2005-04-17 06:20:36 +08:00
|
|
|
*/
|
2012-07-14 22:31:47 +08:00
|
|
|
tty->termios.c_iflag = 0;
|
|
|
|
tty->termios.c_oflag = 0;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
/* Insert into hash */
|
|
|
|
hashbin_insert(ircomm_tty, (irda_queue_t *) self, line, NULL);
|
|
|
|
}
|
2012-08-08 03:48:02 +08:00
|
|
|
|
2012-10-05 08:01:21 +08:00
|
|
|
tty->driver_data = self;
|
|
|
|
|
2012-08-08 03:48:02 +08:00
|
|
|
return tty_port_install(&self->port, driver, tty);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Function ircomm_tty_open (tty, filp)
|
|
|
|
*
|
|
|
|
* This routine is called when a particular tty device is opened. This
|
|
|
|
* routine is mandatory; if this routine is not filled in, the attempted
|
|
|
|
* open will fail with ENODEV.
|
|
|
|
*/
|
|
|
|
static int ircomm_tty_open(struct tty_struct *tty, struct file *filp)
|
|
|
|
{
|
|
|
|
struct ircomm_tty_cb *self = tty->driver_data;
|
|
|
|
unsigned long flags;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
IRDA_DEBUG(2, "%s()\n", __func__ );
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
/* ++ is not atomic, so this should be protected - Jean II */
|
2012-06-04 19:35:20 +08:00
|
|
|
spin_lock_irqsave(&self->port.lock, flags);
|
2012-06-04 19:35:18 +08:00
|
|
|
self->port.count++;
|
2012-06-04 19:35:20 +08:00
|
|
|
spin_unlock_irqrestore(&self->port.lock, flags);
|
2012-06-04 19:35:21 +08:00
|
|
|
tty_port_tty_set(&self->port, tty);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2008-03-06 12:47:47 +08:00
|
|
|
IRDA_DEBUG(1, "%s(), %s%d, count = %d\n", __func__ , tty->driver->name,
|
2012-06-04 19:35:18 +08:00
|
|
|
self->line, self->port.count);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
/* Not really used by us, but lets do it anyway */
|
2013-01-03 22:53:05 +08:00
|
|
|
self->port.low_latency = (self->port.flags & ASYNC_LOW_LATENCY) ? 1 : 0;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* If the port is the middle of closing, bail out now
|
|
|
|
*/
|
|
|
|
if (tty_hung_up_p(filp) ||
|
2012-06-04 19:35:19 +08:00
|
|
|
test_bit(ASYNCB_CLOSING, &self->port.flags)) {
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
/* Hm, why are we blocking on ASYNC_CLOSING if we
|
|
|
|
* do return -EAGAIN/-ERESTARTSYS below anyway?
|
|
|
|
* IMHO it's either not needed in the first place
|
|
|
|
* or for some reason we need to make sure the async
|
|
|
|
* closing has been finished - if so, wouldn't we
|
|
|
|
* probably better sleep uninterruptible?
|
|
|
|
*/
|
|
|
|
|
2012-06-04 19:35:16 +08:00
|
|
|
if (wait_event_interruptible(self->port.close_wait,
|
2012-06-04 19:35:19 +08:00
|
|
|
!test_bit(ASYNCB_CLOSING, &self->port.flags))) {
|
2005-04-17 06:20:36 +08:00
|
|
|
IRDA_WARNING("%s - got signal while blocking on ASYNC_CLOSING!\n",
|
2008-03-06 12:47:47 +08:00
|
|
|
__func__);
|
2005-04-17 06:20:36 +08:00
|
|
|
return -ERESTARTSYS;
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef SERIAL_DO_RESTART
|
2012-06-04 19:35:19 +08:00
|
|
|
return (self->port.flags & ASYNC_HUP_NOTIFY) ?
|
2010-09-23 04:43:57 +08:00
|
|
|
-EAGAIN : -ERESTARTSYS;
|
2005-04-17 06:20:36 +08:00
|
|
|
#else
|
|
|
|
return -EAGAIN;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Check if this is a "normal" ircomm device, or an irlpt device */
|
2012-08-08 03:48:02 +08:00
|
|
|
if (self->line < 0x10) {
|
2005-04-17 06:20:36 +08:00
|
|
|
self->service_type = IRCOMM_3_WIRE | IRCOMM_9_WIRE;
|
|
|
|
self->settings.service_type = IRCOMM_9_WIRE; /* 9 wire as default */
|
|
|
|
/* Jan Kiszka -> add DSR/RI -> Conform to IrCOMM spec */
|
|
|
|
self->settings.dce = IRCOMM_CTS | IRCOMM_CD | IRCOMM_DSR | IRCOMM_RI; /* Default line settings */
|
2008-03-06 12:47:47 +08:00
|
|
|
IRDA_DEBUG(2, "%s(), IrCOMM device\n", __func__ );
|
2005-04-17 06:20:36 +08:00
|
|
|
} else {
|
2008-03-06 12:47:47 +08:00
|
|
|
IRDA_DEBUG(2, "%s(), IrLPT device\n", __func__ );
|
2005-04-17 06:20:36 +08:00
|
|
|
self->service_type = IRCOMM_3_WIRE_RAW;
|
|
|
|
self->settings.service_type = IRCOMM_3_WIRE_RAW; /* Default */
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = ircomm_tty_startup(self);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
|
2012-06-04 19:35:21 +08:00
|
|
|
ret = ircomm_tty_block_til_ready(self, tty, filp);
|
2005-04-17 06:20:36 +08:00
|
|
|
if (ret) {
|
2007-02-09 22:24:53 +08:00
|
|
|
IRDA_DEBUG(2,
|
2008-03-06 12:47:47 +08:00
|
|
|
"%s(), returning after block_til_ready with %d\n", __func__ ,
|
2005-04-17 06:20:36 +08:00
|
|
|
ret);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Function ircomm_tty_close (tty, filp)
|
|
|
|
*
|
|
|
|
* This routine is called when a particular tty device is closed.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
static void ircomm_tty_close(struct tty_struct *tty, struct file *filp)
|
|
|
|
{
|
|
|
|
struct ircomm_tty_cb *self = (struct ircomm_tty_cb *) tty->driver_data;
|
2012-06-04 19:35:22 +08:00
|
|
|
struct tty_port *port = &self->port;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2008-03-06 12:47:47 +08:00
|
|
|
IRDA_DEBUG(0, "%s()\n", __func__ );
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
IRDA_ASSERT(self != NULL, return;);
|
|
|
|
IRDA_ASSERT(self->magic == IRCOMM_TTY_MAGIC, return;);
|
|
|
|
|
2012-06-04 19:35:25 +08:00
|
|
|
if (tty_port_close_start(port, tty, filp) == 0)
|
2005-04-17 06:20:36 +08:00
|
|
|
return;
|
|
|
|
|
|
|
|
ircomm_tty_shutdown(self);
|
|
|
|
|
2008-04-30 15:54:13 +08:00
|
|
|
tty_driver_flush_buffer(tty);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2012-06-04 19:35:24 +08:00
|
|
|
tty_port_close_end(port, tty);
|
2012-06-04 19:35:22 +08:00
|
|
|
tty_port_tty_set(port, NULL);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Function ircomm_tty_flush_buffer (tty)
|
|
|
|
*
|
2007-02-09 22:24:53 +08:00
|
|
|
*
|
2005-04-17 06:20:36 +08:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
static void ircomm_tty_flush_buffer(struct tty_struct *tty)
|
|
|
|
{
|
|
|
|
struct ircomm_tty_cb *self = (struct ircomm_tty_cb *) tty->driver_data;
|
|
|
|
|
|
|
|
IRDA_ASSERT(self != NULL, return;);
|
|
|
|
IRDA_ASSERT(self->magic == IRCOMM_TTY_MAGIC, return;);
|
|
|
|
|
2007-02-09 22:24:53 +08:00
|
|
|
/*
|
|
|
|
* Let do_softint() do this to avoid race condition with
|
|
|
|
* do_softint() ;-)
|
2005-04-17 06:20:36 +08:00
|
|
|
*/
|
|
|
|
schedule_work(&self->tqueue);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2006-11-22 22:57:56 +08:00
|
|
|
* Function ircomm_tty_do_softint (work)
|
2005-04-17 06:20:36 +08:00
|
|
|
*
|
|
|
|
* We use this routine to give the write wakeup to the user at at a
|
2007-02-09 22:24:53 +08:00
|
|
|
* safe time (as fast as possible after write have completed). This
|
2005-04-17 06:20:36 +08:00
|
|
|
* can be compared to the Tx interrupt.
|
|
|
|
*/
|
2006-11-22 22:57:56 +08:00
|
|
|
static void ircomm_tty_do_softint(struct work_struct *work)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2006-11-22 22:57:56 +08:00
|
|
|
struct ircomm_tty_cb *self =
|
|
|
|
container_of(work, struct ircomm_tty_cb, tqueue);
|
2005-04-17 06:20:36 +08:00
|
|
|
struct tty_struct *tty;
|
|
|
|
unsigned long flags;
|
|
|
|
struct sk_buff *skb, *ctrl_skb;
|
|
|
|
|
2008-03-06 12:47:47 +08:00
|
|
|
IRDA_DEBUG(2, "%s()\n", __func__ );
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
if (!self || self->magic != IRCOMM_TTY_MAGIC)
|
|
|
|
return;
|
|
|
|
|
2012-06-04 19:35:21 +08:00
|
|
|
tty = tty_port_tty_get(&self->port);
|
2005-04-17 06:20:36 +08:00
|
|
|
if (!tty)
|
|
|
|
return;
|
|
|
|
|
|
|
|
/* Unlink control buffer */
|
|
|
|
spin_lock_irqsave(&self->spinlock, flags);
|
|
|
|
|
|
|
|
ctrl_skb = self->ctrl_skb;
|
|
|
|
self->ctrl_skb = NULL;
|
|
|
|
|
|
|
|
spin_unlock_irqrestore(&self->spinlock, flags);
|
|
|
|
|
|
|
|
/* Flush control buffer if any */
|
|
|
|
if(ctrl_skb) {
|
|
|
|
if(self->flow == FLOW_START)
|
|
|
|
ircomm_control_request(self->ircomm, ctrl_skb);
|
|
|
|
/* Drop reference count - see ircomm_ttp_data_request(). */
|
|
|
|
dev_kfree_skb(ctrl_skb);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (tty->hw_stopped)
|
2012-06-04 19:35:21 +08:00
|
|
|
goto put;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
/* Unlink transmit buffer */
|
|
|
|
spin_lock_irqsave(&self->spinlock, flags);
|
2007-02-09 22:24:53 +08:00
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
skb = self->tx_skb;
|
|
|
|
self->tx_skb = NULL;
|
|
|
|
|
|
|
|
spin_unlock_irqrestore(&self->spinlock, flags);
|
|
|
|
|
|
|
|
/* Flush transmit buffer if any */
|
|
|
|
if (skb) {
|
|
|
|
ircomm_tty_do_event(self, IRCOMM_TTY_DATA_REQUEST, skb, NULL);
|
|
|
|
/* Drop reference count - see ircomm_ttp_data_request(). */
|
|
|
|
dev_kfree_skb(skb);
|
|
|
|
}
|
2007-02-09 22:24:53 +08:00
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
/* Check if user (still) wants to be waken up */
|
2008-07-17 04:53:12 +08:00
|
|
|
tty_wakeup(tty);
|
2012-06-04 19:35:21 +08:00
|
|
|
put:
|
|
|
|
tty_kref_put(tty);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Function ircomm_tty_write (tty, buf, count)
|
|
|
|
*
|
|
|
|
* This routine is called by the kernel to write a series of characters
|
|
|
|
* to the tty device. The characters may come from user space or kernel
|
|
|
|
* space. This routine will return the number of characters actually
|
|
|
|
* accepted for writing. This routine is mandatory.
|
|
|
|
*/
|
|
|
|
static int ircomm_tty_write(struct tty_struct *tty,
|
|
|
|
const unsigned char *buf, int count)
|
|
|
|
{
|
|
|
|
struct ircomm_tty_cb *self = (struct ircomm_tty_cb *) tty->driver_data;
|
|
|
|
unsigned long flags;
|
|
|
|
struct sk_buff *skb;
|
|
|
|
int tailroom = 0;
|
|
|
|
int len = 0;
|
|
|
|
int size;
|
|
|
|
|
2008-03-06 12:47:47 +08:00
|
|
|
IRDA_DEBUG(2, "%s(), count=%d, hw_stopped=%d\n", __func__ , count,
|
2005-04-17 06:20:36 +08:00
|
|
|
tty->hw_stopped);
|
|
|
|
|
|
|
|
IRDA_ASSERT(self != NULL, return -1;);
|
|
|
|
IRDA_ASSERT(self->magic == IRCOMM_TTY_MAGIC, return -1;);
|
|
|
|
|
|
|
|
/* We may receive packets from the TTY even before we have finished
|
|
|
|
* our setup. Not cool.
|
|
|
|
* The problem is that we don't know the final header and data size
|
|
|
|
* to create the proper skb, so any skb we would create would have
|
|
|
|
* bogus header and data size, so need care.
|
|
|
|
* We use a bogus header size to safely detect this condition.
|
|
|
|
* Another problem is that hw_stopped was set to 0 way before it
|
|
|
|
* should be, so we would drop this skb. It should now be fixed.
|
|
|
|
* One option is to not accept data until we are properly setup.
|
|
|
|
* But, I suspect that when it happens, the ppp line discipline
|
|
|
|
* just "drops" the data, which might screw up connect scripts.
|
|
|
|
* The second option is to create a "safe skb", with large header
|
|
|
|
* and small size (see ircomm_tty_open() for values).
|
|
|
|
* We just need to make sure that when the real values get filled,
|
|
|
|
* we don't mess up the original "safe skb" (see tx_data_size).
|
|
|
|
* Jean II */
|
|
|
|
if (self->max_header_size == IRCOMM_TTY_HDR_UNINITIALISED) {
|
2008-03-06 12:47:47 +08:00
|
|
|
IRDA_DEBUG(1, "%s() : not initialised\n", __func__);
|
2005-04-17 06:20:36 +08:00
|
|
|
#ifdef IRCOMM_NO_TX_BEFORE_INIT
|
|
|
|
/* We didn't consume anything, TTY will retry */
|
|
|
|
return 0;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
if (count < 1)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
/* Protect our manipulation of self->tx_skb and related */
|
|
|
|
spin_lock_irqsave(&self->spinlock, flags);
|
|
|
|
|
|
|
|
/* Fetch current transmit buffer */
|
|
|
|
skb = self->tx_skb;
|
|
|
|
|
2007-02-09 22:24:53 +08:00
|
|
|
/*
|
2005-04-17 06:20:36 +08:00
|
|
|
* Send out all the data we get, possibly as multiple fragmented
|
|
|
|
* frames, but this will only happen if the data is larger than the
|
|
|
|
* max data size. The normal case however is just the opposite, and
|
|
|
|
* this function may be called multiple times, and will then actually
|
2007-02-09 22:24:53 +08:00
|
|
|
* defragment the data and send it out as one packet as soon as
|
2005-04-17 06:20:36 +08:00
|
|
|
* possible, but at a safer point in time
|
|
|
|
*/
|
|
|
|
while (count) {
|
|
|
|
size = count;
|
|
|
|
|
|
|
|
/* Adjust data size to the max data size */
|
|
|
|
if (size > self->max_data_size)
|
|
|
|
size = self->max_data_size;
|
2007-02-09 22:24:53 +08:00
|
|
|
|
|
|
|
/*
|
2005-04-17 06:20:36 +08:00
|
|
|
* Do we already have a buffer ready for transmit, or do
|
2007-02-09 22:24:53 +08:00
|
|
|
* we need to allocate a new frame
|
2005-04-17 06:20:36 +08:00
|
|
|
*/
|
2007-02-09 22:24:53 +08:00
|
|
|
if (skb) {
|
|
|
|
/*
|
|
|
|
* Any room for more data at the end of the current
|
2005-04-17 06:20:36 +08:00
|
|
|
* transmit buffer? Cannot use skb_tailroom, since
|
2007-02-09 22:24:53 +08:00
|
|
|
* dev_alloc_skb gives us a larger skb than we
|
2005-04-17 06:20:36 +08:00
|
|
|
* requested
|
|
|
|
* Note : use tx_data_size, because max_data_size
|
|
|
|
* may have changed and we don't want to overwrite
|
|
|
|
* the skb. - Jean II
|
|
|
|
*/
|
|
|
|
if ((tailroom = (self->tx_data_size - skb->len)) > 0) {
|
|
|
|
/* Adjust data to tailroom */
|
|
|
|
if (size > tailroom)
|
|
|
|
size = tailroom;
|
|
|
|
} else {
|
2007-02-09 22:24:53 +08:00
|
|
|
/*
|
|
|
|
* Current transmit frame is full, so break
|
2005-04-17 06:20:36 +08:00
|
|
|
* out, so we can send it as soon as possible
|
|
|
|
*/
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
/* Prepare a full sized frame */
|
2006-07-22 05:50:41 +08:00
|
|
|
skb = alloc_skb(self->max_data_size+
|
|
|
|
self->max_header_size,
|
|
|
|
GFP_ATOMIC);
|
2005-04-17 06:20:36 +08:00
|
|
|
if (!skb) {
|
|
|
|
spin_unlock_irqrestore(&self->spinlock, flags);
|
|
|
|
return -ENOBUFS;
|
|
|
|
}
|
|
|
|
skb_reserve(skb, self->max_header_size);
|
|
|
|
self->tx_skb = skb;
|
|
|
|
/* Remember skb size because max_data_size may
|
|
|
|
* change later on - Jean II */
|
|
|
|
self->tx_data_size = self->max_data_size;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Copy data */
|
|
|
|
memcpy(skb_put(skb,size), buf + len, size);
|
|
|
|
|
|
|
|
count -= size;
|
|
|
|
len += size;
|
|
|
|
}
|
|
|
|
|
|
|
|
spin_unlock_irqrestore(&self->spinlock, flags);
|
|
|
|
|
2007-02-09 22:24:53 +08:00
|
|
|
/*
|
2005-04-17 06:20:36 +08:00
|
|
|
* Schedule a new thread which will transmit the frame as soon
|
|
|
|
* as possible, but at a safe point in time. We do this so the
|
|
|
|
* "user" can give us data multiple times, as PPP does (because of
|
|
|
|
* its 256 byte tx buffer). We will then defragment and send out
|
2007-02-09 22:24:53 +08:00
|
|
|
* all this data as one single packet.
|
2005-04-17 06:20:36 +08:00
|
|
|
*/
|
|
|
|
schedule_work(&self->tqueue);
|
2007-02-09 22:24:53 +08:00
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
return len;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Function ircomm_tty_write_room (tty)
|
|
|
|
*
|
|
|
|
* This routine returns the numbers of characters the tty driver will
|
|
|
|
* accept for queuing to be written. This number is subject to change as
|
|
|
|
* output buffers get emptied, or if the output flow control is acted.
|
|
|
|
*/
|
|
|
|
static int ircomm_tty_write_room(struct tty_struct *tty)
|
|
|
|
{
|
|
|
|
struct ircomm_tty_cb *self = (struct ircomm_tty_cb *) tty->driver_data;
|
|
|
|
unsigned long flags;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
IRDA_ASSERT(self != NULL, return -1;);
|
|
|
|
IRDA_ASSERT(self->magic == IRCOMM_TTY_MAGIC, return -1;);
|
|
|
|
|
|
|
|
#ifdef IRCOMM_NO_TX_BEFORE_INIT
|
|
|
|
/* max_header_size tells us if the channel is initialised or not. */
|
|
|
|
if (self->max_header_size == IRCOMM_TTY_HDR_UNINITIALISED)
|
|
|
|
/* Don't bother us yet */
|
|
|
|
return 0;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* Check if we are allowed to transmit any data.
|
|
|
|
* hw_stopped is the regular flow control.
|
|
|
|
* Jean II */
|
|
|
|
if (tty->hw_stopped)
|
|
|
|
ret = 0;
|
|
|
|
else {
|
|
|
|
spin_lock_irqsave(&self->spinlock, flags);
|
|
|
|
if (self->tx_skb)
|
|
|
|
ret = self->tx_data_size - self->tx_skb->len;
|
|
|
|
else
|
|
|
|
ret = self->max_data_size;
|
|
|
|
spin_unlock_irqrestore(&self->spinlock, flags);
|
|
|
|
}
|
2008-03-06 12:47:47 +08:00
|
|
|
IRDA_DEBUG(2, "%s(), ret=%d\n", __func__ , ret);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Function ircomm_tty_wait_until_sent (tty, timeout)
|
|
|
|
*
|
|
|
|
* This routine waits until the device has written out all of the
|
|
|
|
* characters in its transmitter FIFO.
|
|
|
|
*/
|
|
|
|
static void ircomm_tty_wait_until_sent(struct tty_struct *tty, int timeout)
|
|
|
|
{
|
|
|
|
struct ircomm_tty_cb *self = (struct ircomm_tty_cb *) tty->driver_data;
|
|
|
|
unsigned long orig_jiffies, poll_time;
|
|
|
|
unsigned long flags;
|
2007-02-09 22:24:53 +08:00
|
|
|
|
2008-03-06 12:47:47 +08:00
|
|
|
IRDA_DEBUG(2, "%s()\n", __func__ );
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
IRDA_ASSERT(self != NULL, return;);
|
|
|
|
IRDA_ASSERT(self->magic == IRCOMM_TTY_MAGIC, return;);
|
|
|
|
|
|
|
|
orig_jiffies = jiffies;
|
|
|
|
|
|
|
|
/* Set poll time to 200 ms */
|
|
|
|
poll_time = IRDA_MIN(timeout, msecs_to_jiffies(200));
|
|
|
|
|
|
|
|
spin_lock_irqsave(&self->spinlock, flags);
|
|
|
|
while (self->tx_skb && self->tx_skb->len) {
|
|
|
|
spin_unlock_irqrestore(&self->spinlock, flags);
|
2005-09-13 05:15:34 +08:00
|
|
|
schedule_timeout_interruptible(poll_time);
|
2005-04-17 06:20:36 +08:00
|
|
|
spin_lock_irqsave(&self->spinlock, flags);
|
|
|
|
if (signal_pending(current))
|
|
|
|
break;
|
|
|
|
if (timeout && time_after(jiffies, orig_jiffies + timeout))
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
spin_unlock_irqrestore(&self->spinlock, flags);
|
|
|
|
current->state = TASK_RUNNING;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Function ircomm_tty_throttle (tty)
|
|
|
|
*
|
|
|
|
* This routine notifies the tty driver that input buffers for the line
|
|
|
|
* discipline are close to full, and it should somehow signal that no
|
2007-02-09 22:24:53 +08:00
|
|
|
* more characters should be sent to the tty.
|
2005-04-17 06:20:36 +08:00
|
|
|
*/
|
|
|
|
static void ircomm_tty_throttle(struct tty_struct *tty)
|
|
|
|
{
|
|
|
|
struct ircomm_tty_cb *self = (struct ircomm_tty_cb *) tty->driver_data;
|
|
|
|
|
2008-03-06 12:47:47 +08:00
|
|
|
IRDA_DEBUG(2, "%s()\n", __func__ );
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
IRDA_ASSERT(self != NULL, return;);
|
|
|
|
IRDA_ASSERT(self->magic == IRCOMM_TTY_MAGIC, return;);
|
|
|
|
|
|
|
|
/* Software flow control? */
|
|
|
|
if (I_IXOFF(tty))
|
|
|
|
ircomm_tty_send_xchar(tty, STOP_CHAR(tty));
|
2007-02-09 22:24:53 +08:00
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
/* Hardware flow control? */
|
2012-07-14 22:31:47 +08:00
|
|
|
if (tty->termios.c_cflag & CRTSCTS) {
|
2005-04-17 06:20:36 +08:00
|
|
|
self->settings.dte &= ~IRCOMM_RTS;
|
|
|
|
self->settings.dte |= IRCOMM_DELTA_RTS;
|
2007-02-09 22:24:53 +08:00
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
ircomm_param_request(self, IRCOMM_DTE, TRUE);
|
|
|
|
}
|
|
|
|
|
2007-02-09 22:24:53 +08:00
|
|
|
ircomm_flow_request(self->ircomm, FLOW_STOP);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Function ircomm_tty_unthrottle (tty)
|
|
|
|
*
|
|
|
|
* This routine notifies the tty drivers that it should signals that
|
|
|
|
* characters can now be sent to the tty without fear of overrunning the
|
|
|
|
* input buffers of the line disciplines.
|
|
|
|
*/
|
|
|
|
static void ircomm_tty_unthrottle(struct tty_struct *tty)
|
|
|
|
{
|
|
|
|
struct ircomm_tty_cb *self = (struct ircomm_tty_cb *) tty->driver_data;
|
|
|
|
|
2008-03-06 12:47:47 +08:00
|
|
|
IRDA_DEBUG(2, "%s()\n", __func__ );
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
IRDA_ASSERT(self != NULL, return;);
|
|
|
|
IRDA_ASSERT(self->magic == IRCOMM_TTY_MAGIC, return;);
|
|
|
|
|
|
|
|
/* Using software flow control? */
|
|
|
|
if (I_IXOFF(tty)) {
|
|
|
|
ircomm_tty_send_xchar(tty, START_CHAR(tty));
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Using hardware flow control? */
|
2012-07-14 22:31:47 +08:00
|
|
|
if (tty->termios.c_cflag & CRTSCTS) {
|
2005-04-17 06:20:36 +08:00
|
|
|
self->settings.dte |= (IRCOMM_RTS|IRCOMM_DELTA_RTS);
|
|
|
|
|
|
|
|
ircomm_param_request(self, IRCOMM_DTE, TRUE);
|
2008-03-06 12:47:47 +08:00
|
|
|
IRDA_DEBUG(1, "%s(), FLOW_START\n", __func__ );
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
2007-02-09 22:24:53 +08:00
|
|
|
ircomm_flow_request(self->ircomm, FLOW_START);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Function ircomm_tty_chars_in_buffer (tty)
|
|
|
|
*
|
|
|
|
* Indicates if there are any data in the buffer
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
static int ircomm_tty_chars_in_buffer(struct tty_struct *tty)
|
|
|
|
{
|
|
|
|
struct ircomm_tty_cb *self = (struct ircomm_tty_cb *) tty->driver_data;
|
|
|
|
unsigned long flags;
|
|
|
|
int len = 0;
|
|
|
|
|
|
|
|
IRDA_ASSERT(self != NULL, return -1;);
|
|
|
|
IRDA_ASSERT(self->magic == IRCOMM_TTY_MAGIC, return -1;);
|
|
|
|
|
|
|
|
spin_lock_irqsave(&self->spinlock, flags);
|
|
|
|
|
|
|
|
if (self->tx_skb)
|
|
|
|
len = self->tx_skb->len;
|
|
|
|
|
|
|
|
spin_unlock_irqrestore(&self->spinlock, flags);
|
|
|
|
|
|
|
|
return len;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void ircomm_tty_shutdown(struct ircomm_tty_cb *self)
|
|
|
|
{
|
|
|
|
unsigned long flags;
|
|
|
|
|
|
|
|
IRDA_ASSERT(self != NULL, return;);
|
|
|
|
IRDA_ASSERT(self->magic == IRCOMM_TTY_MAGIC, return;);
|
|
|
|
|
2008-03-06 12:47:47 +08:00
|
|
|
IRDA_DEBUG(0, "%s()\n", __func__ );
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2012-06-04 19:35:19 +08:00
|
|
|
if (!test_and_clear_bit(ASYNCB_INITIALIZED, &self->port.flags))
|
2005-04-17 06:20:36 +08:00
|
|
|
return;
|
|
|
|
|
|
|
|
ircomm_tty_detach_cable(self);
|
|
|
|
|
|
|
|
spin_lock_irqsave(&self->spinlock, flags);
|
|
|
|
|
|
|
|
del_timer(&self->watchdog_timer);
|
2007-02-09 22:24:53 +08:00
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
/* Free parameter buffer */
|
|
|
|
if (self->ctrl_skb) {
|
|
|
|
dev_kfree_skb(self->ctrl_skb);
|
|
|
|
self->ctrl_skb = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Free transmit buffer */
|
|
|
|
if (self->tx_skb) {
|
|
|
|
dev_kfree_skb(self->tx_skb);
|
|
|
|
self->tx_skb = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (self->ircomm) {
|
|
|
|
ircomm_close(self->ircomm);
|
|
|
|
self->ircomm = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
spin_unlock_irqrestore(&self->spinlock, flags);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Function ircomm_tty_hangup (tty)
|
|
|
|
*
|
|
|
|
* This routine notifies the tty driver that it should hangup the tty
|
|
|
|
* device.
|
2007-02-09 22:24:53 +08:00
|
|
|
*
|
2005-04-17 06:20:36 +08:00
|
|
|
*/
|
|
|
|
static void ircomm_tty_hangup(struct tty_struct *tty)
|
|
|
|
{
|
|
|
|
struct ircomm_tty_cb *self = (struct ircomm_tty_cb *) tty->driver_data;
|
2012-06-04 19:35:22 +08:00
|
|
|
struct tty_port *port = &self->port;
|
2005-04-17 06:20:36 +08:00
|
|
|
unsigned long flags;
|
|
|
|
|
2008-03-06 12:47:47 +08:00
|
|
|
IRDA_DEBUG(0, "%s()\n", __func__ );
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
IRDA_ASSERT(self != NULL, return;);
|
|
|
|
IRDA_ASSERT(self->magic == IRCOMM_TTY_MAGIC, return;);
|
|
|
|
|
|
|
|
/* ircomm_tty_flush_buffer(tty); */
|
|
|
|
ircomm_tty_shutdown(self);
|
|
|
|
|
2012-06-04 19:35:22 +08:00
|
|
|
spin_lock_irqsave(&port->lock, flags);
|
|
|
|
port->flags &= ~ASYNC_NORMAL_ACTIVE;
|
|
|
|
if (port->tty) {
|
|
|
|
set_bit(TTY_IO_ERROR, &port->tty->flags);
|
|
|
|
tty_kref_put(port->tty);
|
2012-06-04 19:35:21 +08:00
|
|
|
}
|
2012-06-04 19:35:22 +08:00
|
|
|
port->tty = NULL;
|
|
|
|
port->count = 0;
|
|
|
|
spin_unlock_irqrestore(&port->lock, flags);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2012-06-04 19:35:22 +08:00
|
|
|
wake_up_interruptible(&port->open_wait);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Function ircomm_tty_send_xchar (tty, ch)
|
|
|
|
*
|
|
|
|
* This routine is used to send a high-priority XON/XOFF character to
|
|
|
|
* the device.
|
|
|
|
*/
|
|
|
|
static void ircomm_tty_send_xchar(struct tty_struct *tty, char ch)
|
|
|
|
{
|
2008-03-06 12:47:47 +08:00
|
|
|
IRDA_DEBUG(0, "%s(), not impl\n", __func__ );
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Function ircomm_tty_start (tty)
|
|
|
|
*
|
|
|
|
* This routine notifies the tty driver that it resume sending
|
2007-02-09 22:24:53 +08:00
|
|
|
* characters to the tty device.
|
2005-04-17 06:20:36 +08:00
|
|
|
*/
|
|
|
|
void ircomm_tty_start(struct tty_struct *tty)
|
|
|
|
{
|
|
|
|
struct ircomm_tty_cb *self = (struct ircomm_tty_cb *) tty->driver_data;
|
|
|
|
|
|
|
|
ircomm_flow_request(self->ircomm, FLOW_START);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Function ircomm_tty_stop (tty)
|
|
|
|
*
|
|
|
|
* This routine notifies the tty driver that it should stop outputting
|
2007-02-09 22:24:53 +08:00
|
|
|
* characters to the tty device.
|
2005-04-17 06:20:36 +08:00
|
|
|
*/
|
2007-02-09 22:24:53 +08:00
|
|
|
static void ircomm_tty_stop(struct tty_struct *tty)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
struct ircomm_tty_cb *self = (struct ircomm_tty_cb *) tty->driver_data;
|
|
|
|
|
|
|
|
IRDA_ASSERT(self != NULL, return;);
|
|
|
|
IRDA_ASSERT(self->magic == IRCOMM_TTY_MAGIC, return;);
|
|
|
|
|
|
|
|
ircomm_flow_request(self->ircomm, FLOW_STOP);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Function ircomm_check_modem_status (self)
|
|
|
|
*
|
|
|
|
* Check for any changes in the DCE's line settings. This function should
|
|
|
|
* be called whenever the dce parameter settings changes, to update the
|
|
|
|
* flow control settings and other things
|
|
|
|
*/
|
|
|
|
void ircomm_tty_check_modem_status(struct ircomm_tty_cb *self)
|
|
|
|
{
|
|
|
|
struct tty_struct *tty;
|
|
|
|
int status;
|
|
|
|
|
2008-03-06 12:47:47 +08:00
|
|
|
IRDA_DEBUG(0, "%s()\n", __func__ );
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
IRDA_ASSERT(self != NULL, return;);
|
|
|
|
IRDA_ASSERT(self->magic == IRCOMM_TTY_MAGIC, return;);
|
|
|
|
|
2012-06-04 19:35:21 +08:00
|
|
|
tty = tty_port_tty_get(&self->port);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
status = self->settings.dce;
|
|
|
|
|
|
|
|
if (status & IRCOMM_DCE_DELTA_ANY) {
|
|
|
|
/*wake_up_interruptible(&self->delta_msr_wait);*/
|
|
|
|
}
|
2012-06-04 19:35:19 +08:00
|
|
|
if ((self->port.flags & ASYNC_CHECK_CD) && (status & IRCOMM_DELTA_CD)) {
|
2007-02-09 22:24:53 +08:00
|
|
|
IRDA_DEBUG(2,
|
2008-03-06 12:47:47 +08:00
|
|
|
"%s(), ircomm%d CD now %s...\n", __func__ , self->line,
|
2005-04-17 06:20:36 +08:00
|
|
|
(status & IRCOMM_CD) ? "on" : "off");
|
|
|
|
|
|
|
|
if (status & IRCOMM_CD) {
|
2012-06-04 19:35:16 +08:00
|
|
|
wake_up_interruptible(&self->port.open_wait);
|
2005-04-17 06:20:36 +08:00
|
|
|
} else {
|
2007-02-09 22:24:53 +08:00
|
|
|
IRDA_DEBUG(2,
|
2008-03-06 12:47:47 +08:00
|
|
|
"%s(), Doing serial hangup..\n", __func__ );
|
2005-04-17 06:20:36 +08:00
|
|
|
if (tty)
|
|
|
|
tty_hangup(tty);
|
|
|
|
|
|
|
|
/* Hangup will remote the tty, so better break out */
|
2012-06-04 19:35:21 +08:00
|
|
|
goto put;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
}
|
2012-08-23 10:13:36 +08:00
|
|
|
if (tty && tty_port_cts_enabled(&self->port)) {
|
2005-04-17 06:20:36 +08:00
|
|
|
if (tty->hw_stopped) {
|
|
|
|
if (status & IRCOMM_CTS) {
|
2007-02-09 22:24:53 +08:00
|
|
|
IRDA_DEBUG(2,
|
2008-03-06 12:47:47 +08:00
|
|
|
"%s(), CTS tx start...\n", __func__ );
|
2005-04-17 06:20:36 +08:00
|
|
|
tty->hw_stopped = 0;
|
2007-02-09 22:24:53 +08:00
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
/* Wake up processes blocked on open */
|
2012-06-04 19:35:16 +08:00
|
|
|
wake_up_interruptible(&self->port.open_wait);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
schedule_work(&self->tqueue);
|
2012-06-04 19:35:21 +08:00
|
|
|
goto put;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (!(status & IRCOMM_CTS)) {
|
2007-02-09 22:24:53 +08:00
|
|
|
IRDA_DEBUG(2,
|
2008-03-06 12:47:47 +08:00
|
|
|
"%s(), CTS tx stop...\n", __func__ );
|
2005-04-17 06:20:36 +08:00
|
|
|
tty->hw_stopped = 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2012-06-04 19:35:21 +08:00
|
|
|
put:
|
|
|
|
tty_kref_put(tty);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Function ircomm_tty_data_indication (instance, sap, skb)
|
|
|
|
*
|
|
|
|
* Handle incoming data, and deliver it to the line discipline
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
static int ircomm_tty_data_indication(void *instance, void *sap,
|
|
|
|
struct sk_buff *skb)
|
|
|
|
{
|
|
|
|
struct ircomm_tty_cb *self = (struct ircomm_tty_cb *) instance;
|
2012-06-04 19:35:21 +08:00
|
|
|
struct tty_struct *tty;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2008-03-06 12:47:47 +08:00
|
|
|
IRDA_DEBUG(2, "%s()\n", __func__ );
|
2007-02-09 22:24:53 +08:00
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
IRDA_ASSERT(self != NULL, return -1;);
|
|
|
|
IRDA_ASSERT(self->magic == IRCOMM_TTY_MAGIC, return -1;);
|
|
|
|
IRDA_ASSERT(skb != NULL, return -1;);
|
|
|
|
|
2012-06-04 19:35:21 +08:00
|
|
|
tty = tty_port_tty_get(&self->port);
|
|
|
|
if (!tty) {
|
2008-03-06 12:47:47 +08:00
|
|
|
IRDA_DEBUG(0, "%s(), no tty!\n", __func__ );
|
2005-04-17 06:20:36 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2007-02-09 22:24:53 +08:00
|
|
|
/*
|
2005-04-17 06:20:36 +08:00
|
|
|
* If we receive data when hardware is stopped then something is wrong.
|
|
|
|
* We try to poll the peers line settings to check if we are up todate.
|
2007-02-09 22:24:53 +08:00
|
|
|
* Devices like WinCE can do this, and since they don't send any
|
2005-04-17 06:20:36 +08:00
|
|
|
* params, we can just as well declare the hardware for running.
|
|
|
|
*/
|
2012-06-04 19:35:21 +08:00
|
|
|
if (tty->hw_stopped && (self->flow == FLOW_START)) {
|
2008-03-06 12:47:47 +08:00
|
|
|
IRDA_DEBUG(0, "%s(), polling for line settings!\n", __func__ );
|
2005-04-17 06:20:36 +08:00
|
|
|
ircomm_param_request(self, IRCOMM_POLL, TRUE);
|
|
|
|
|
|
|
|
/* We can just as well declare the hardware for running */
|
|
|
|
ircomm_tty_send_initial_parameters(self);
|
|
|
|
ircomm_tty_link_established(self);
|
|
|
|
}
|
2013-01-03 22:53:06 +08:00
|
|
|
tty_kref_put(tty);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2007-02-09 22:24:53 +08:00
|
|
|
/*
|
2011-05-12 09:04:40 +08:00
|
|
|
* Use flip buffer functions since the code may be called from interrupt
|
|
|
|
* context
|
2005-04-17 06:20:36 +08:00
|
|
|
*/
|
2013-01-03 22:53:04 +08:00
|
|
|
tty_insert_flip_string(&self->port, skb->data, skb->len);
|
2013-01-03 22:53:06 +08:00
|
|
|
tty_flip_buffer_push(&self->port);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
/* No need to kfree_skb - see ircomm_ttp_data_indication() */
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Function ircomm_tty_control_indication (instance, sap, skb)
|
|
|
|
*
|
|
|
|
* Parse all incoming parameters (easy!)
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
static int ircomm_tty_control_indication(void *instance, void *sap,
|
|
|
|
struct sk_buff *skb)
|
|
|
|
{
|
|
|
|
struct ircomm_tty_cb *self = (struct ircomm_tty_cb *) instance;
|
|
|
|
int clen;
|
|
|
|
|
2008-03-06 12:47:47 +08:00
|
|
|
IRDA_DEBUG(4, "%s()\n", __func__ );
|
2007-02-09 22:24:53 +08:00
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
IRDA_ASSERT(self != NULL, return -1;);
|
|
|
|
IRDA_ASSERT(self->magic == IRCOMM_TTY_MAGIC, return -1;);
|
|
|
|
IRDA_ASSERT(skb != NULL, return -1;);
|
|
|
|
|
|
|
|
clen = skb->data[0];
|
|
|
|
|
2007-02-09 22:24:53 +08:00
|
|
|
irda_param_extract_all(self, skb->data+1, IRDA_MIN(skb->len-1, clen),
|
2005-04-17 06:20:36 +08:00
|
|
|
&ircomm_param_info);
|
|
|
|
|
|
|
|
/* No need to kfree_skb - see ircomm_control_indication() */
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Function ircomm_tty_flow_indication (instance, sap, cmd)
|
|
|
|
*
|
|
|
|
* This function is called by IrTTP when it wants us to slow down the
|
|
|
|
* transmission of data. We just mark the hardware as stopped, and wait
|
|
|
|
* for IrTTP to notify us that things are OK again.
|
|
|
|
*/
|
2007-02-09 22:24:53 +08:00
|
|
|
static void ircomm_tty_flow_indication(void *instance, void *sap,
|
2005-04-17 06:20:36 +08:00
|
|
|
LOCAL_FLOW cmd)
|
|
|
|
{
|
|
|
|
struct ircomm_tty_cb *self = (struct ircomm_tty_cb *) instance;
|
|
|
|
struct tty_struct *tty;
|
|
|
|
|
|
|
|
IRDA_ASSERT(self != NULL, return;);
|
|
|
|
IRDA_ASSERT(self->magic == IRCOMM_TTY_MAGIC, return;);
|
|
|
|
|
2012-06-04 19:35:21 +08:00
|
|
|
tty = tty_port_tty_get(&self->port);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
switch (cmd) {
|
|
|
|
case FLOW_START:
|
2008-03-06 12:47:47 +08:00
|
|
|
IRDA_DEBUG(2, "%s(), hw start!\n", __func__ );
|
2012-06-04 19:35:21 +08:00
|
|
|
if (tty)
|
|
|
|
tty->hw_stopped = 0;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
/* ircomm_tty_do_softint will take care of the rest */
|
|
|
|
schedule_work(&self->tqueue);
|
|
|
|
break;
|
|
|
|
default: /* If we get here, something is very wrong, better stop */
|
|
|
|
case FLOW_STOP:
|
2008-03-06 12:47:47 +08:00
|
|
|
IRDA_DEBUG(2, "%s(), hw stopped!\n", __func__ );
|
2012-06-04 19:35:21 +08:00
|
|
|
if (tty)
|
|
|
|
tty->hw_stopped = 1;
|
2005-04-17 06:20:36 +08:00
|
|
|
break;
|
|
|
|
}
|
2012-06-04 19:35:21 +08:00
|
|
|
|
|
|
|
tty_kref_put(tty);
|
2005-04-17 06:20:36 +08:00
|
|
|
self->flow = cmd;
|
|
|
|
}
|
|
|
|
|
2007-12-05 18:18:48 +08:00
|
|
|
#ifdef CONFIG_PROC_FS
|
2009-04-01 06:19:22 +08:00
|
|
|
static void ircomm_tty_line_info(struct ircomm_tty_cb *self, struct seq_file *m)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2012-06-04 19:35:21 +08:00
|
|
|
struct tty_struct *tty;
|
2009-04-01 06:19:22 +08:00
|
|
|
char sep;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2009-04-01 06:19:22 +08:00
|
|
|
seq_printf(m, "State: %s\n", ircomm_tty_state[self->state]);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2009-04-01 06:19:22 +08:00
|
|
|
seq_puts(m, "Service type: ");
|
2005-04-17 06:20:36 +08:00
|
|
|
if (self->service_type & IRCOMM_9_WIRE)
|
2009-04-01 06:19:22 +08:00
|
|
|
seq_puts(m, "9_WIRE");
|
2005-04-17 06:20:36 +08:00
|
|
|
else if (self->service_type & IRCOMM_3_WIRE)
|
2009-04-01 06:19:22 +08:00
|
|
|
seq_puts(m, "3_WIRE");
|
2005-04-17 06:20:36 +08:00
|
|
|
else if (self->service_type & IRCOMM_3_WIRE_RAW)
|
2009-04-01 06:19:22 +08:00
|
|
|
seq_puts(m, "3_WIRE_RAW");
|
2005-04-17 06:20:36 +08:00
|
|
|
else
|
2009-04-01 06:19:22 +08:00
|
|
|
seq_puts(m, "No common service type!\n");
|
|
|
|
seq_putc(m, '\n');
|
|
|
|
|
|
|
|
seq_printf(m, "Port name: %s\n", self->settings.port_name);
|
|
|
|
|
|
|
|
seq_printf(m, "DTE status:");
|
|
|
|
sep = ' ';
|
|
|
|
if (self->settings.dte & IRCOMM_RTS) {
|
|
|
|
seq_printf(m, "%cRTS", sep);
|
|
|
|
sep = '|';
|
|
|
|
}
|
|
|
|
if (self->settings.dte & IRCOMM_DTR) {
|
|
|
|
seq_printf(m, "%cDTR", sep);
|
|
|
|
sep = '|';
|
|
|
|
}
|
|
|
|
seq_putc(m, '\n');
|
|
|
|
|
|
|
|
seq_puts(m, "DCE status:");
|
|
|
|
sep = ' ';
|
|
|
|
if (self->settings.dce & IRCOMM_CTS) {
|
|
|
|
seq_printf(m, "%cCTS", sep);
|
|
|
|
sep = '|';
|
|
|
|
}
|
|
|
|
if (self->settings.dce & IRCOMM_DSR) {
|
|
|
|
seq_printf(m, "%cDSR", sep);
|
|
|
|
sep = '|';
|
|
|
|
}
|
|
|
|
if (self->settings.dce & IRCOMM_CD) {
|
|
|
|
seq_printf(m, "%cCD", sep);
|
|
|
|
sep = '|';
|
|
|
|
}
|
|
|
|
if (self->settings.dce & IRCOMM_RI) {
|
|
|
|
seq_printf(m, "%cRI", sep);
|
|
|
|
sep = '|';
|
|
|
|
}
|
|
|
|
seq_putc(m, '\n');
|
|
|
|
|
|
|
|
seq_puts(m, "Configuration: ");
|
2005-04-17 06:20:36 +08:00
|
|
|
if (!self->settings.null_modem)
|
2009-04-01 06:19:22 +08:00
|
|
|
seq_puts(m, "DTE <-> DCE\n");
|
2005-04-17 06:20:36 +08:00
|
|
|
else
|
2009-04-01 06:19:22 +08:00
|
|
|
seq_puts(m, "DTE <-> DTE (null modem emulation)\n");
|
|
|
|
|
|
|
|
seq_printf(m, "Data rate: %d\n", self->settings.data_rate);
|
|
|
|
|
|
|
|
seq_puts(m, "Flow control:");
|
|
|
|
sep = ' ';
|
|
|
|
if (self->settings.flow_control & IRCOMM_XON_XOFF_IN) {
|
|
|
|
seq_printf(m, "%cXON_XOFF_IN", sep);
|
|
|
|
sep = '|';
|
|
|
|
}
|
|
|
|
if (self->settings.flow_control & IRCOMM_XON_XOFF_OUT) {
|
|
|
|
seq_printf(m, "%cXON_XOFF_OUT", sep);
|
|
|
|
sep = '|';
|
|
|
|
}
|
|
|
|
if (self->settings.flow_control & IRCOMM_RTS_CTS_IN) {
|
|
|
|
seq_printf(m, "%cRTS_CTS_IN", sep);
|
|
|
|
sep = '|';
|
|
|
|
}
|
|
|
|
if (self->settings.flow_control & IRCOMM_RTS_CTS_OUT) {
|
|
|
|
seq_printf(m, "%cRTS_CTS_OUT", sep);
|
|
|
|
sep = '|';
|
|
|
|
}
|
|
|
|
if (self->settings.flow_control & IRCOMM_DSR_DTR_IN) {
|
|
|
|
seq_printf(m, "%cDSR_DTR_IN", sep);
|
|
|
|
sep = '|';
|
|
|
|
}
|
|
|
|
if (self->settings.flow_control & IRCOMM_DSR_DTR_OUT) {
|
|
|
|
seq_printf(m, "%cDSR_DTR_OUT", sep);
|
|
|
|
sep = '|';
|
|
|
|
}
|
|
|
|
if (self->settings.flow_control & IRCOMM_ENQ_ACK_IN) {
|
|
|
|
seq_printf(m, "%cENQ_ACK_IN", sep);
|
|
|
|
sep = '|';
|
|
|
|
}
|
|
|
|
if (self->settings.flow_control & IRCOMM_ENQ_ACK_OUT) {
|
|
|
|
seq_printf(m, "%cENQ_ACK_OUT", sep);
|
|
|
|
sep = '|';
|
|
|
|
}
|
|
|
|
seq_putc(m, '\n');
|
|
|
|
|
|
|
|
seq_puts(m, "Flags:");
|
|
|
|
sep = ' ';
|
2012-08-23 10:13:36 +08:00
|
|
|
if (tty_port_cts_enabled(&self->port)) {
|
2009-04-01 06:19:22 +08:00
|
|
|
seq_printf(m, "%cASYNC_CTS_FLOW", sep);
|
|
|
|
sep = '|';
|
|
|
|
}
|
2012-06-04 19:35:19 +08:00
|
|
|
if (self->port.flags & ASYNC_CHECK_CD) {
|
2009-04-01 06:19:22 +08:00
|
|
|
seq_printf(m, "%cASYNC_CHECK_CD", sep);
|
|
|
|
sep = '|';
|
|
|
|
}
|
2012-06-04 19:35:19 +08:00
|
|
|
if (self->port.flags & ASYNC_INITIALIZED) {
|
2009-04-01 06:19:22 +08:00
|
|
|
seq_printf(m, "%cASYNC_INITIALIZED", sep);
|
|
|
|
sep = '|';
|
|
|
|
}
|
2012-06-04 19:35:19 +08:00
|
|
|
if (self->port.flags & ASYNC_LOW_LATENCY) {
|
2009-04-01 06:19:22 +08:00
|
|
|
seq_printf(m, "%cASYNC_LOW_LATENCY", sep);
|
|
|
|
sep = '|';
|
|
|
|
}
|
2012-06-04 19:35:19 +08:00
|
|
|
if (self->port.flags & ASYNC_CLOSING) {
|
2009-04-01 06:19:22 +08:00
|
|
|
seq_printf(m, "%cASYNC_CLOSING", sep);
|
|
|
|
sep = '|';
|
|
|
|
}
|
2012-06-04 19:35:19 +08:00
|
|
|
if (self->port.flags & ASYNC_NORMAL_ACTIVE) {
|
2009-04-01 06:19:22 +08:00
|
|
|
seq_printf(m, "%cASYNC_NORMAL_ACTIVE", sep);
|
|
|
|
sep = '|';
|
|
|
|
}
|
|
|
|
seq_putc(m, '\n');
|
|
|
|
|
|
|
|
seq_printf(m, "Role: %s\n", self->client ? "client" : "server");
|
2012-06-04 19:35:18 +08:00
|
|
|
seq_printf(m, "Open count: %d\n", self->port.count);
|
2009-04-01 06:19:22 +08:00
|
|
|
seq_printf(m, "Max data size: %d\n", self->max_data_size);
|
|
|
|
seq_printf(m, "Max header size: %d\n", self->max_header_size);
|
2007-02-09 22:24:53 +08:00
|
|
|
|
2012-06-04 19:35:21 +08:00
|
|
|
tty = tty_port_tty_get(&self->port);
|
|
|
|
if (tty) {
|
2009-04-01 06:19:22 +08:00
|
|
|
seq_printf(m, "Hardware: %s\n",
|
2012-06-04 19:35:21 +08:00
|
|
|
tty->hw_stopped ? "Stopped" : "Running");
|
|
|
|
tty_kref_put(tty);
|
|
|
|
}
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
2009-04-01 06:19:22 +08:00
|
|
|
static int ircomm_tty_proc_show(struct seq_file *m, void *v)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
struct ircomm_tty_cb *self;
|
|
|
|
unsigned long flags;
|
|
|
|
|
|
|
|
spin_lock_irqsave(&ircomm_tty->hb_spinlock, flags);
|
|
|
|
|
|
|
|
self = (struct ircomm_tty_cb *) hashbin_get_first(ircomm_tty);
|
2009-04-01 06:19:22 +08:00
|
|
|
while (self != NULL) {
|
2005-04-17 06:20:36 +08:00
|
|
|
if (self->magic != IRCOMM_TTY_MAGIC)
|
|
|
|
break;
|
|
|
|
|
2009-04-01 06:19:22 +08:00
|
|
|
ircomm_tty_line_info(self, m);
|
2005-04-17 06:20:36 +08:00
|
|
|
self = (struct ircomm_tty_cb *) hashbin_get_next(ircomm_tty);
|
2007-02-09 22:24:53 +08:00
|
|
|
}
|
2005-04-17 06:20:36 +08:00
|
|
|
spin_unlock_irqrestore(&ircomm_tty->hb_spinlock, flags);
|
2009-04-01 06:19:22 +08:00
|
|
|
return 0;
|
|
|
|
}
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2009-04-01 06:19:22 +08:00
|
|
|
static int ircomm_tty_proc_open(struct inode *inode, struct file *file)
|
|
|
|
{
|
|
|
|
return single_open(file, ircomm_tty_proc_show, NULL);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
2009-04-01 06:19:22 +08:00
|
|
|
|
|
|
|
static const struct file_operations ircomm_tty_proc_fops = {
|
|
|
|
.owner = THIS_MODULE,
|
|
|
|
.open = ircomm_tty_proc_open,
|
|
|
|
.read = seq_read,
|
|
|
|
.llseek = seq_lseek,
|
|
|
|
.release = single_release,
|
|
|
|
};
|
2005-04-17 06:20:36 +08:00
|
|
|
#endif /* CONFIG_PROC_FS */
|
|
|
|
|
|
|
|
MODULE_AUTHOR("Dag Brattli <dagb@cs.uit.no>");
|
|
|
|
MODULE_DESCRIPTION("IrCOMM serial TTY driver");
|
|
|
|
MODULE_LICENSE("GPL");
|
|
|
|
MODULE_ALIAS_CHARDEV_MAJOR(IRCOMM_TTY_MAJOR);
|
|
|
|
|
|
|
|
module_init(ircomm_tty_init);
|
|
|
|
module_exit(ircomm_tty_cleanup);
|