2005-04-17 06:20:36 +08:00
|
|
|
/*
|
|
|
|
* REINER SCT cyberJack pinpad/e-com USB Chipcard Reader Driver
|
|
|
|
*
|
|
|
|
* Copyright (C) 2001 REINER SCT
|
|
|
|
* Author: Matthias Bruestle
|
|
|
|
*
|
|
|
|
* Contact: support@reiner-sct.com (see MAINTAINERS)
|
|
|
|
*
|
|
|
|
* This program is largely derived from work by the linux-usb group
|
|
|
|
* and associated source files. Please see the usb/serial files for
|
|
|
|
* individual credits and copyrights.
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
* Thanks to Greg Kroah-Hartman (greg@kroah.com) for his help and
|
|
|
|
* patience.
|
|
|
|
*
|
|
|
|
* In case of problems, please write to the contact e-mail address
|
|
|
|
* mentioned above.
|
|
|
|
*
|
|
|
|
* Please note that later models of the cyberjack reader family are
|
|
|
|
* supported by a libusb-based userspace device driver.
|
|
|
|
*
|
|
|
|
* Homepage: http://www.reiner-sct.de/support/treiber_cyberjack.php#linux
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
#include <linux/kernel.h>
|
|
|
|
#include <linux/errno.h>
|
|
|
|
#include <linux/init.h>
|
|
|
|
#include <linux/slab.h>
|
|
|
|
#include <linux/tty.h>
|
|
|
|
#include <linux/tty_driver.h>
|
|
|
|
#include <linux/tty_flip.h>
|
|
|
|
#include <linux/module.h>
|
|
|
|
#include <linux/spinlock.h>
|
|
|
|
#include <asm/uaccess.h>
|
|
|
|
#include <linux/usb.h>
|
2006-07-12 12:22:58 +08:00
|
|
|
#include <linux/usb/serial.h>
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
#define CYBERJACK_LOCAL_BUF_SIZE 32
|
|
|
|
|
|
|
|
static int debug;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Version Information
|
|
|
|
*/
|
|
|
|
#define DRIVER_VERSION "v1.01"
|
|
|
|
#define DRIVER_AUTHOR "Matthias Bruestle"
|
|
|
|
#define DRIVER_DESC "REINER SCT cyberJack pinpad/e-com USB Chipcard Reader Driver"
|
|
|
|
|
|
|
|
|
|
|
|
#define CYBERJACK_VENDOR_ID 0x0C4B
|
|
|
|
#define CYBERJACK_PRODUCT_ID 0x0100
|
|
|
|
|
|
|
|
/* Function prototypes */
|
|
|
|
static int cyberjack_startup (struct usb_serial *serial);
|
|
|
|
static void cyberjack_shutdown (struct usb_serial *serial);
|
|
|
|
static int cyberjack_open (struct usb_serial_port *port, struct file *filp);
|
|
|
|
static void cyberjack_close (struct usb_serial_port *port, struct file *filp);
|
|
|
|
static int cyberjack_write (struct usb_serial_port *port, const unsigned char *buf, int count);
|
|
|
|
static int cyberjack_write_room( struct usb_serial_port *port );
|
IRQ: Maintain regs pointer globally rather than passing to IRQ handlers
Maintain a per-CPU global "struct pt_regs *" variable which can be used instead
of passing regs around manually through all ~1800 interrupt handlers in the
Linux kernel.
The regs pointer is used in few places, but it potentially costs both stack
space and code to pass it around. On the FRV arch, removing the regs parameter
from all the genirq function results in a 20% speed up of the IRQ exit path
(ie: from leaving timer_interrupt() to leaving do_IRQ()).
Where appropriate, an arch may override the generic storage facility and do
something different with the variable. On FRV, for instance, the address is
maintained in GR28 at all times inside the kernel as part of general exception
handling.
Having looked over the code, it appears that the parameter may be handed down
through up to twenty or so layers of functions. Consider a USB character
device attached to a USB hub, attached to a USB controller that posts its
interrupts through a cascaded auxiliary interrupt controller. A character
device driver may want to pass regs to the sysrq handler through the input
layer which adds another few layers of parameter passing.
I've build this code with allyesconfig for x86_64 and i386. I've runtested the
main part of the code on FRV and i386, though I can't test most of the drivers.
I've also done partial conversion for powerpc and MIPS - these at least compile
with minimal configurations.
This will affect all archs. Mostly the changes should be relatively easy.
Take do_IRQ(), store the regs pointer at the beginning, saving the old one:
struct pt_regs *old_regs = set_irq_regs(regs);
And put the old one back at the end:
set_irq_regs(old_regs);
Don't pass regs through to generic_handle_irq() or __do_IRQ().
In timer_interrupt(), this sort of change will be necessary:
- update_process_times(user_mode(regs));
- profile_tick(CPU_PROFILING, regs);
+ update_process_times(user_mode(get_irq_regs()));
+ profile_tick(CPU_PROFILING);
I'd like to move update_process_times()'s use of get_irq_regs() into itself,
except that i386, alone of the archs, uses something other than user_mode().
Some notes on the interrupt handling in the drivers:
(*) input_dev() is now gone entirely. The regs pointer is no longer stored in
the input_dev struct.
(*) finish_unlinks() in drivers/usb/host/ohci-q.c needs checking. It does
something different depending on whether it's been supplied with a regs
pointer or not.
(*) Various IRQ handler function pointers have been moved to type
irq_handler_t.
Signed-Off-By: David Howells <dhowells@redhat.com>
(cherry picked from 1b16e7ac850969f38b375e511e3fa2f474a33867 commit)
2006-10-05 21:55:46 +08:00
|
|
|
static void cyberjack_read_int_callback (struct urb *urb);
|
|
|
|
static void cyberjack_read_bulk_callback (struct urb *urb);
|
|
|
|
static void cyberjack_write_bulk_callback (struct urb *urb);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
static struct usb_device_id id_table [] = {
|
|
|
|
{ USB_DEVICE(CYBERJACK_VENDOR_ID, CYBERJACK_PRODUCT_ID) },
|
|
|
|
{ } /* Terminating entry */
|
|
|
|
};
|
|
|
|
|
|
|
|
MODULE_DEVICE_TABLE (usb, id_table);
|
|
|
|
|
|
|
|
static struct usb_driver cyberjack_driver = {
|
|
|
|
.name = "cyberjack",
|
|
|
|
.probe = usb_serial_probe,
|
|
|
|
.disconnect = usb_serial_disconnect,
|
|
|
|
.id_table = id_table,
|
2005-11-17 05:41:28 +08:00
|
|
|
.no_dynamic_id = 1,
|
2005-04-17 06:20:36 +08:00
|
|
|
};
|
|
|
|
|
2005-06-21 12:15:16 +08:00
|
|
|
static struct usb_serial_driver cyberjack_device = {
|
2005-06-21 12:15:16 +08:00
|
|
|
.driver = {
|
|
|
|
.owner = THIS_MODULE,
|
2005-06-21 12:15:16 +08:00
|
|
|
.name = "cyberjack",
|
2005-06-21 12:15:16 +08:00
|
|
|
},
|
2005-06-21 12:15:16 +08:00
|
|
|
.description = "Reiner SCT Cyberjack USB card reader",
|
2006-12-18 04:50:24 +08:00
|
|
|
.usb_driver = &cyberjack_driver,
|
2005-04-17 06:20:36 +08:00
|
|
|
.id_table = id_table,
|
|
|
|
.num_ports = 1,
|
|
|
|
.attach = cyberjack_startup,
|
|
|
|
.shutdown = cyberjack_shutdown,
|
|
|
|
.open = cyberjack_open,
|
|
|
|
.close = cyberjack_close,
|
|
|
|
.write = cyberjack_write,
|
2006-12-18 04:50:24 +08:00
|
|
|
.write_room = cyberjack_write_room,
|
2005-04-17 06:20:36 +08:00
|
|
|
.read_int_callback = cyberjack_read_int_callback,
|
|
|
|
.read_bulk_callback = cyberjack_read_bulk_callback,
|
|
|
|
.write_bulk_callback = cyberjack_write_bulk_callback,
|
|
|
|
};
|
|
|
|
|
|
|
|
struct cyberjack_private {
|
|
|
|
spinlock_t lock; /* Lock for SMP */
|
|
|
|
short rdtodo; /* Bytes still to read */
|
|
|
|
unsigned char wrbuf[5*64]; /* Buffer for collecting data to write */
|
|
|
|
short wrfilled; /* Overall data size we already got */
|
|
|
|
short wrsent; /* Data already sent */
|
|
|
|
};
|
|
|
|
|
|
|
|
/* do some startup allocations not currently performed by usb_serial_probe() */
|
|
|
|
static int cyberjack_startup (struct usb_serial *serial)
|
|
|
|
{
|
|
|
|
struct cyberjack_private *priv;
|
|
|
|
int i;
|
|
|
|
|
2008-03-04 08:08:34 +08:00
|
|
|
dbg("%s", __func__);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
/* allocate the private data structure */
|
|
|
|
priv = kmalloc(sizeof(struct cyberjack_private), GFP_KERNEL);
|
|
|
|
if (!priv)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
/* set initial values */
|
|
|
|
spin_lock_init(&priv->lock);
|
|
|
|
priv->rdtodo = 0;
|
|
|
|
priv->wrfilled = 0;
|
|
|
|
priv->wrsent = 0;
|
|
|
|
usb_set_serial_port_data(serial->port[0], priv);
|
|
|
|
|
|
|
|
init_waitqueue_head(&serial->port[0]->write_wait);
|
|
|
|
|
|
|
|
for (i = 0; i < serial->num_ports; ++i) {
|
|
|
|
int result;
|
|
|
|
serial->port[i]->interrupt_in_urb->dev = serial->dev;
|
|
|
|
result = usb_submit_urb(serial->port[i]->interrupt_in_urb,
|
|
|
|
GFP_KERNEL);
|
|
|
|
if (result)
|
|
|
|
err(" usb_submit_urb(read int) failed");
|
2008-03-04 08:08:34 +08:00
|
|
|
dbg("%s - usb_submit_urb(int urb)", __func__);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return( 0 );
|
|
|
|
}
|
|
|
|
|
|
|
|
static void cyberjack_shutdown (struct usb_serial *serial)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
2008-03-04 08:08:34 +08:00
|
|
|
dbg("%s", __func__);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2008-04-09 00:16:06 +08:00
|
|
|
for (i = 0; i < serial->num_ports; ++i) {
|
2005-04-17 06:20:36 +08:00
|
|
|
usb_kill_urb(serial->port[i]->interrupt_in_urb);
|
|
|
|
/* My special items, the standard routines free my urbs */
|
|
|
|
kfree(usb_get_serial_port_data(serial->port[i]));
|
|
|
|
usb_set_serial_port_data(serial->port[i], NULL);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static int cyberjack_open (struct usb_serial_port *port, struct file *filp)
|
|
|
|
{
|
|
|
|
struct cyberjack_private *priv;
|
|
|
|
unsigned long flags;
|
|
|
|
int result = 0;
|
|
|
|
|
2008-03-04 08:08:34 +08:00
|
|
|
dbg("%s - port %d", __func__, port->number);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2008-03-04 08:08:34 +08:00
|
|
|
dbg("%s - usb_clear_halt", __func__ );
|
2005-04-17 06:20:36 +08:00
|
|
|
usb_clear_halt(port->serial->dev, port->write_urb->pipe);
|
|
|
|
|
|
|
|
/* force low_latency on so that our tty_push actually forces
|
|
|
|
* the data through, otherwise it is scheduled, and with high
|
|
|
|
* data rates (like with OHCI) data can get lost.
|
|
|
|
*/
|
|
|
|
port->tty->low_latency = 1;
|
|
|
|
|
|
|
|
priv = usb_get_serial_port_data(port);
|
|
|
|
spin_lock_irqsave(&priv->lock, flags);
|
|
|
|
priv->rdtodo = 0;
|
|
|
|
priv->wrfilled = 0;
|
|
|
|
priv->wrsent = 0;
|
|
|
|
spin_unlock_irqrestore(&priv->lock, flags);
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void cyberjack_close (struct usb_serial_port *port, struct file *filp)
|
|
|
|
{
|
2008-03-04 08:08:34 +08:00
|
|
|
dbg("%s - port %d", __func__, port->number);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
if (port->serial->dev) {
|
|
|
|
/* shutdown any bulk reads that might be going on */
|
|
|
|
usb_kill_urb(port->write_urb);
|
|
|
|
usb_kill_urb(port->read_urb);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static int cyberjack_write (struct usb_serial_port *port, const unsigned char *buf, int count)
|
|
|
|
{
|
|
|
|
struct usb_serial *serial = port->serial;
|
|
|
|
struct cyberjack_private *priv = usb_get_serial_port_data(port);
|
|
|
|
unsigned long flags;
|
|
|
|
int result;
|
|
|
|
int wrexpected;
|
|
|
|
|
2008-03-04 08:08:34 +08:00
|
|
|
dbg("%s - port %d", __func__, port->number);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
if (count == 0) {
|
2008-03-04 08:08:34 +08:00
|
|
|
dbg("%s - write request of 0 bytes", __func__);
|
2008-04-09 00:16:06 +08:00
|
|
|
return 0;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
2006-09-25 18:51:41 +08:00
|
|
|
spin_lock_bh(&port->lock);
|
2005-04-24 03:49:16 +08:00
|
|
|
if (port->write_urb_busy) {
|
2006-09-25 18:51:41 +08:00
|
|
|
spin_unlock_bh(&port->lock);
|
2008-03-04 08:08:34 +08:00
|
|
|
dbg("%s - already writing", __func__);
|
2005-04-24 03:49:16 +08:00
|
|
|
return 0;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
2005-04-24 03:49:16 +08:00
|
|
|
port->write_urb_busy = 1;
|
2006-09-25 18:51:41 +08:00
|
|
|
spin_unlock_bh(&port->lock);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
spin_lock_irqsave(&priv->lock, flags);
|
|
|
|
|
2008-04-09 00:16:06 +08:00
|
|
|
if( (count+priv->wrfilled) > sizeof(priv->wrbuf) ) {
|
2005-04-17 06:20:36 +08:00
|
|
|
/* To much data for buffer. Reset buffer. */
|
2008-04-09 00:16:06 +08:00
|
|
|
priv->wrfilled = 0;
|
2005-04-24 03:49:16 +08:00
|
|
|
port->write_urb_busy = 0;
|
2008-04-09 00:16:06 +08:00
|
|
|
spin_unlock_irqrestore(&priv->lock, flags);
|
|
|
|
return 0;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Copy data */
|
|
|
|
memcpy (priv->wrbuf+priv->wrfilled, buf, count);
|
|
|
|
|
2008-03-04 08:08:34 +08:00
|
|
|
usb_serial_debug_data(debug, &port->dev, __func__, count,
|
2005-04-17 06:20:36 +08:00
|
|
|
priv->wrbuf+priv->wrfilled);
|
|
|
|
priv->wrfilled += count;
|
|
|
|
|
|
|
|
if( priv->wrfilled >= 3 ) {
|
|
|
|
wrexpected = ((int)priv->wrbuf[2]<<8)+priv->wrbuf[1]+3;
|
2008-03-04 08:08:34 +08:00
|
|
|
dbg("%s - expected data: %d", __func__, wrexpected);
|
2005-04-17 06:20:36 +08:00
|
|
|
} else {
|
|
|
|
wrexpected = sizeof(priv->wrbuf);
|
|
|
|
}
|
|
|
|
|
|
|
|
if( priv->wrfilled >= wrexpected ) {
|
|
|
|
/* We have enough data to begin transmission */
|
|
|
|
int length;
|
|
|
|
|
2008-03-04 08:08:34 +08:00
|
|
|
dbg("%s - transmitting data (frame 1)", __func__);
|
2005-04-17 06:20:36 +08:00
|
|
|
length = (wrexpected > port->bulk_out_size) ? port->bulk_out_size : wrexpected;
|
|
|
|
|
|
|
|
memcpy (port->write_urb->transfer_buffer, priv->wrbuf, length );
|
|
|
|
priv->wrsent=length;
|
|
|
|
|
|
|
|
/* set up our urb */
|
|
|
|
usb_fill_bulk_urb(port->write_urb, serial->dev,
|
|
|
|
usb_sndbulkpipe(serial->dev, port->bulk_out_endpointAddress),
|
|
|
|
port->write_urb->transfer_buffer, length,
|
|
|
|
((serial->type->write_bulk_callback) ?
|
|
|
|
serial->type->write_bulk_callback :
|
|
|
|
cyberjack_write_bulk_callback),
|
|
|
|
port);
|
|
|
|
|
|
|
|
/* send the data out the bulk port */
|
|
|
|
result = usb_submit_urb(port->write_urb, GFP_ATOMIC);
|
|
|
|
if (result) {
|
2008-03-04 08:08:34 +08:00
|
|
|
err("%s - failed submitting write urb, error %d", __func__, result);
|
2005-04-17 06:20:36 +08:00
|
|
|
/* Throw away data. No better idea what to do with it. */
|
2008-04-09 00:16:06 +08:00
|
|
|
priv->wrfilled = 0;
|
|
|
|
priv->wrsent = 0;
|
2005-04-17 06:20:36 +08:00
|
|
|
spin_unlock_irqrestore(&priv->lock, flags);
|
2005-04-24 03:49:16 +08:00
|
|
|
port->write_urb_busy = 0;
|
2005-04-17 06:20:36 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2008-03-04 08:08:34 +08:00
|
|
|
dbg("%s - priv->wrsent=%d", __func__,priv->wrsent);
|
|
|
|
dbg("%s - priv->wrfilled=%d", __func__,priv->wrfilled);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
if( priv->wrsent>=priv->wrfilled ) {
|
2008-03-04 08:08:34 +08:00
|
|
|
dbg("%s - buffer cleaned", __func__);
|
2005-04-17 06:20:36 +08:00
|
|
|
memset( priv->wrbuf, 0, sizeof(priv->wrbuf) );
|
2008-04-09 00:16:06 +08:00
|
|
|
priv->wrfilled = 0;
|
|
|
|
priv->wrsent = 0;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
spin_unlock_irqrestore(&priv->lock, flags);
|
|
|
|
|
|
|
|
return (count);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int cyberjack_write_room( struct usb_serial_port *port )
|
|
|
|
{
|
2008-04-09 00:16:06 +08:00
|
|
|
/* FIXME: .... */
|
2005-04-17 06:20:36 +08:00
|
|
|
return CYBERJACK_LOCAL_BUF_SIZE;
|
|
|
|
}
|
|
|
|
|
IRQ: Maintain regs pointer globally rather than passing to IRQ handlers
Maintain a per-CPU global "struct pt_regs *" variable which can be used instead
of passing regs around manually through all ~1800 interrupt handlers in the
Linux kernel.
The regs pointer is used in few places, but it potentially costs both stack
space and code to pass it around. On the FRV arch, removing the regs parameter
from all the genirq function results in a 20% speed up of the IRQ exit path
(ie: from leaving timer_interrupt() to leaving do_IRQ()).
Where appropriate, an arch may override the generic storage facility and do
something different with the variable. On FRV, for instance, the address is
maintained in GR28 at all times inside the kernel as part of general exception
handling.
Having looked over the code, it appears that the parameter may be handed down
through up to twenty or so layers of functions. Consider a USB character
device attached to a USB hub, attached to a USB controller that posts its
interrupts through a cascaded auxiliary interrupt controller. A character
device driver may want to pass regs to the sysrq handler through the input
layer which adds another few layers of parameter passing.
I've build this code with allyesconfig for x86_64 and i386. I've runtested the
main part of the code on FRV and i386, though I can't test most of the drivers.
I've also done partial conversion for powerpc and MIPS - these at least compile
with minimal configurations.
This will affect all archs. Mostly the changes should be relatively easy.
Take do_IRQ(), store the regs pointer at the beginning, saving the old one:
struct pt_regs *old_regs = set_irq_regs(regs);
And put the old one back at the end:
set_irq_regs(old_regs);
Don't pass regs through to generic_handle_irq() or __do_IRQ().
In timer_interrupt(), this sort of change will be necessary:
- update_process_times(user_mode(regs));
- profile_tick(CPU_PROFILING, regs);
+ update_process_times(user_mode(get_irq_regs()));
+ profile_tick(CPU_PROFILING);
I'd like to move update_process_times()'s use of get_irq_regs() into itself,
except that i386, alone of the archs, uses something other than user_mode().
Some notes on the interrupt handling in the drivers:
(*) input_dev() is now gone entirely. The regs pointer is no longer stored in
the input_dev struct.
(*) finish_unlinks() in drivers/usb/host/ohci-q.c needs checking. It does
something different depending on whether it's been supplied with a regs
pointer or not.
(*) Various IRQ handler function pointers have been moved to type
irq_handler_t.
Signed-Off-By: David Howells <dhowells@redhat.com>
(cherry picked from 1b16e7ac850969f38b375e511e3fa2f474a33867 commit)
2006-10-05 21:55:46 +08:00
|
|
|
static void cyberjack_read_int_callback( struct urb *urb )
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
struct usb_serial_port *port = (struct usb_serial_port *)urb->context;
|
|
|
|
struct cyberjack_private *priv = usb_get_serial_port_data(port);
|
|
|
|
unsigned char *data = urb->transfer_buffer;
|
2007-06-16 06:44:13 +08:00
|
|
|
int status = urb->status;
|
2005-04-17 06:20:36 +08:00
|
|
|
int result;
|
|
|
|
|
2008-03-04 08:08:34 +08:00
|
|
|
dbg("%s - port %d", __func__, port->number);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
/* the urb might have been killed. */
|
2007-06-16 06:44:13 +08:00
|
|
|
if (status)
|
2005-04-17 06:20:36 +08:00
|
|
|
return;
|
|
|
|
|
2008-03-04 08:08:34 +08:00
|
|
|
usb_serial_debug_data(debug, &port->dev, __func__, urb->actual_length, data);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
/* React only to interrupts signaling a bulk_in transfer */
|
2008-04-09 00:16:06 +08:00
|
|
|
if( (urb->actual_length == 4) && (data[0] == 0x01) ) {
|
2005-04-17 06:20:36 +08:00
|
|
|
short old_rdtodo;
|
|
|
|
|
|
|
|
/* This is a announcement of coming bulk_ins. */
|
|
|
|
unsigned short size = ((unsigned short)data[3]<<8)+data[2]+3;
|
|
|
|
|
|
|
|
spin_lock(&priv->lock);
|
|
|
|
|
|
|
|
old_rdtodo = priv->rdtodo;
|
|
|
|
|
|
|
|
if( (old_rdtodo+size)<(old_rdtodo) ) {
|
|
|
|
dbg( "To many bulk_in urbs to do." );
|
|
|
|
spin_unlock(&priv->lock);
|
|
|
|
goto resubmit;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* "+=" is probably more fault tollerant than "=" */
|
|
|
|
priv->rdtodo += size;
|
|
|
|
|
2008-03-04 08:08:34 +08:00
|
|
|
dbg("%s - rdtodo: %d", __func__, priv->rdtodo);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
spin_unlock(&priv->lock);
|
|
|
|
|
|
|
|
if( !old_rdtodo ) {
|
|
|
|
port->read_urb->dev = port->serial->dev;
|
|
|
|
result = usb_submit_urb(port->read_urb, GFP_ATOMIC);
|
|
|
|
if( result )
|
2008-03-04 08:08:34 +08:00
|
|
|
err("%s - failed resubmitting read urb, error %d", __func__, result);
|
|
|
|
dbg("%s - usb_submit_urb(read urb)", __func__);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
resubmit:
|
|
|
|
port->interrupt_in_urb->dev = port->serial->dev;
|
|
|
|
result = usb_submit_urb(port->interrupt_in_urb, GFP_ATOMIC);
|
|
|
|
if (result)
|
|
|
|
err(" usb_submit_urb(read int) failed");
|
2008-03-04 08:08:34 +08:00
|
|
|
dbg("%s - usb_submit_urb(int urb)", __func__);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
IRQ: Maintain regs pointer globally rather than passing to IRQ handlers
Maintain a per-CPU global "struct pt_regs *" variable which can be used instead
of passing regs around manually through all ~1800 interrupt handlers in the
Linux kernel.
The regs pointer is used in few places, but it potentially costs both stack
space and code to pass it around. On the FRV arch, removing the regs parameter
from all the genirq function results in a 20% speed up of the IRQ exit path
(ie: from leaving timer_interrupt() to leaving do_IRQ()).
Where appropriate, an arch may override the generic storage facility and do
something different with the variable. On FRV, for instance, the address is
maintained in GR28 at all times inside the kernel as part of general exception
handling.
Having looked over the code, it appears that the parameter may be handed down
through up to twenty or so layers of functions. Consider a USB character
device attached to a USB hub, attached to a USB controller that posts its
interrupts through a cascaded auxiliary interrupt controller. A character
device driver may want to pass regs to the sysrq handler through the input
layer which adds another few layers of parameter passing.
I've build this code with allyesconfig for x86_64 and i386. I've runtested the
main part of the code on FRV and i386, though I can't test most of the drivers.
I've also done partial conversion for powerpc and MIPS - these at least compile
with minimal configurations.
This will affect all archs. Mostly the changes should be relatively easy.
Take do_IRQ(), store the regs pointer at the beginning, saving the old one:
struct pt_regs *old_regs = set_irq_regs(regs);
And put the old one back at the end:
set_irq_regs(old_regs);
Don't pass regs through to generic_handle_irq() or __do_IRQ().
In timer_interrupt(), this sort of change will be necessary:
- update_process_times(user_mode(regs));
- profile_tick(CPU_PROFILING, regs);
+ update_process_times(user_mode(get_irq_regs()));
+ profile_tick(CPU_PROFILING);
I'd like to move update_process_times()'s use of get_irq_regs() into itself,
except that i386, alone of the archs, uses something other than user_mode().
Some notes on the interrupt handling in the drivers:
(*) input_dev() is now gone entirely. The regs pointer is no longer stored in
the input_dev struct.
(*) finish_unlinks() in drivers/usb/host/ohci-q.c needs checking. It does
something different depending on whether it's been supplied with a regs
pointer or not.
(*) Various IRQ handler function pointers have been moved to type
irq_handler_t.
Signed-Off-By: David Howells <dhowells@redhat.com>
(cherry picked from 1b16e7ac850969f38b375e511e3fa2f474a33867 commit)
2006-10-05 21:55:46 +08:00
|
|
|
static void cyberjack_read_bulk_callback (struct urb *urb)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
struct usb_serial_port *port = (struct usb_serial_port *)urb->context;
|
|
|
|
struct cyberjack_private *priv = usb_get_serial_port_data(port);
|
|
|
|
struct tty_struct *tty;
|
|
|
|
unsigned char *data = urb->transfer_buffer;
|
|
|
|
short todo;
|
|
|
|
int result;
|
2007-06-16 06:44:13 +08:00
|
|
|
int status = urb->status;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2008-03-04 08:08:34 +08:00
|
|
|
dbg("%s - port %d", __func__, port->number);
|
2007-06-16 06:44:13 +08:00
|
|
|
|
2008-03-04 08:08:34 +08:00
|
|
|
usb_serial_debug_data(debug, &port->dev, __func__, urb->actual_length, data);
|
2007-06-16 06:44:13 +08:00
|
|
|
if (status) {
|
|
|
|
dbg("%s - nonzero read bulk status received: %d",
|
2008-03-04 08:08:34 +08:00
|
|
|
__func__, status);
|
2005-04-17 06:20:36 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
tty = port->tty;
|
|
|
|
if (!tty) {
|
2008-03-04 08:08:34 +08:00
|
|
|
dbg("%s - ignoring since device not open\n", __func__);
|
2005-04-17 06:20:36 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (urb->actual_length) {
|
[PATCH] TTY layer buffering revamp
The API and code have been through various bits of initial review by
serial driver people but they definitely need to live somewhere for a
while so the unconverted drivers can get knocked into shape, existing
drivers that have been updated can be better tuned and bugs whacked out.
This replaces the tty flip buffers with kmalloc objects in rings. In the
normal situation for an IRQ driven serial port at typical speeds the
behaviour is pretty much the same, two buffers end up allocated and the
kernel cycles between them as before.
When there are delays or at high speed we now behave far better as the
buffer pool can grow a bit rather than lose characters. This also means
that we can operate at higher speeds reliably.
For drivers that receive characters in blocks (DMA based, USB and
especially virtualisation) the layer allows a lot of driver specific
code that works around the tty layer with private secondary queues to be
removed. The IBM folks need this sort of layer, the smart serial port
people do, the virtualisers do (because a virtualised tty typically
operates at infinite speed rather than emulating 9600 baud).
Finally many drivers had invalid and unsafe attempts to avoid buffer
overflows by directly invoking tty methods extracted out of the innards
of work queue structs. These are no longer needed and all go away. That
fixes various random hangs with serial ports on overflow.
The other change in here is to optimise the receive_room path that is
used by some callers. It turns out that only one ldisc uses receive room
except asa constant and it updates it far far less than the value is
read. We thus make it a variable not a function call.
I expect the code to contain bugs due to the size alone but I'll be
watching and squashing them and feeding out new patches as it goes.
Because the buffers now dynamically expand you should only run out of
buffering when the kernel runs out of memory for real. That means a lot of
the horrible hacks high performance drivers used to do just aren't needed any
more.
Description:
tty_insert_flip_char is an old API and continues to work as before, as does
tty_flip_buffer_push() [this is why many drivers dont need modification]. It
does now also return the number of chars inserted
There are also
tty_buffer_request_room(tty, len)
which asks for a buffer block of the length requested and returns the space
found. This improves efficiency with hardware that knows how much to
transfer.
and tty_insert_flip_string_flags(tty, str, flags, len)
to insert a string of characters and flags
For a smart interface the usual code is
len = tty_request_buffer_room(tty, amount_hardware_says);
tty_insert_flip_string(tty, buffer_from_card, len);
More description!
At the moment tty buffers are attached directly to the tty. This is causing a
lot of the problems related to tty layer locking, also problems at high speed
and also with bursty data (such as occurs in virtualised environments)
I'm working on ripping out the flip buffers and replacing them with a pool of
dynamically allocated buffers. This allows both for old style "byte I/O"
devices and also helps virtualisation and smart devices where large blocks of
data suddenely materialise and need storing.
So far so good. Lots of drivers reference tty->flip.*. Several of them also
call directly and unsafely into function pointers it provides. This will all
break. Most drivers can use tty_insert_flip_char which can be kept as an API
but others need more.
At the moment I've added the following interfaces, if people think more will
be needed now is a good time to say
int tty_buffer_request_room(tty, size)
Try and ensure at least size bytes are available, returns actual room (may be
zero). At the moment it just uses the flipbuf space but that will change.
Repeated calls without characters being added are not cumulative. (ie if you
call it with 1, 1, 1, and then 4 you'll have four characters of space. The
other functions will also try and grow buffers in future but this will be a
more efficient way when you know block sizes.
int tty_insert_flip_char(tty, ch, flag)
As before insert a character if there is room. Now returns 1 for success, 0
for failure.
int tty_insert_flip_string(tty, str, len)
Insert a block of non error characters. Returns the number inserted.
int tty_prepare_flip_string(tty, strptr, len)
Adjust the buffer to allow len characters to be added. Returns a buffer
pointer in strptr and the length available. This allows for hardware that
needs to use functions like insl or mencpy_fromio.
Signed-off-by: Alan Cox <alan@redhat.com>
Cc: Paul Fulghum <paulkf@microgate.com>
Signed-off-by: Hirokazu Takata <takata@linux-m32r.org>
Signed-off-by: Serge Hallyn <serue@us.ibm.com>
Signed-off-by: Jeff Dike <jdike@addtoit.com>
Signed-off-by: John Hawkes <hawkes@sgi.com>
Signed-off-by: Martin Schwidefsky <schwidefsky@de.ibm.com>
Signed-off-by: Adrian Bunk <bunk@stusta.de>
Signed-off-by: Andrew Morton <akpm@osdl.org>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
2006-01-10 12:54:13 +08:00
|
|
|
tty_buffer_request_room(tty, urb->actual_length);
|
|
|
|
tty_insert_flip_string(tty, data, urb->actual_length);
|
2005-04-17 06:20:36 +08:00
|
|
|
tty_flip_buffer_push(tty);
|
|
|
|
}
|
|
|
|
|
|
|
|
spin_lock(&priv->lock);
|
|
|
|
|
|
|
|
/* Reduce urbs to do by one. */
|
|
|
|
priv->rdtodo-=urb->actual_length;
|
|
|
|
/* Just to be sure */
|
|
|
|
if ( priv->rdtodo<0 ) priv->rdtodo = 0;
|
|
|
|
todo = priv->rdtodo;
|
|
|
|
|
|
|
|
spin_unlock(&priv->lock);
|
|
|
|
|
2008-03-04 08:08:34 +08:00
|
|
|
dbg("%s - rdtodo: %d", __func__, todo);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
/* Continue to read if we have still urbs to do. */
|
|
|
|
if( todo /* || (urb->actual_length==port->bulk_in_endpointAddress)*/ ) {
|
|
|
|
port->read_urb->dev = port->serial->dev;
|
|
|
|
result = usb_submit_urb(port->read_urb, GFP_ATOMIC);
|
|
|
|
if (result)
|
2008-03-04 08:08:34 +08:00
|
|
|
err("%s - failed resubmitting read urb, error %d", __func__, result);
|
|
|
|
dbg("%s - usb_submit_urb(read urb)", __func__);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
IRQ: Maintain regs pointer globally rather than passing to IRQ handlers
Maintain a per-CPU global "struct pt_regs *" variable which can be used instead
of passing regs around manually through all ~1800 interrupt handlers in the
Linux kernel.
The regs pointer is used in few places, but it potentially costs both stack
space and code to pass it around. On the FRV arch, removing the regs parameter
from all the genirq function results in a 20% speed up of the IRQ exit path
(ie: from leaving timer_interrupt() to leaving do_IRQ()).
Where appropriate, an arch may override the generic storage facility and do
something different with the variable. On FRV, for instance, the address is
maintained in GR28 at all times inside the kernel as part of general exception
handling.
Having looked over the code, it appears that the parameter may be handed down
through up to twenty or so layers of functions. Consider a USB character
device attached to a USB hub, attached to a USB controller that posts its
interrupts through a cascaded auxiliary interrupt controller. A character
device driver may want to pass regs to the sysrq handler through the input
layer which adds another few layers of parameter passing.
I've build this code with allyesconfig for x86_64 and i386. I've runtested the
main part of the code on FRV and i386, though I can't test most of the drivers.
I've also done partial conversion for powerpc and MIPS - these at least compile
with minimal configurations.
This will affect all archs. Mostly the changes should be relatively easy.
Take do_IRQ(), store the regs pointer at the beginning, saving the old one:
struct pt_regs *old_regs = set_irq_regs(regs);
And put the old one back at the end:
set_irq_regs(old_regs);
Don't pass regs through to generic_handle_irq() or __do_IRQ().
In timer_interrupt(), this sort of change will be necessary:
- update_process_times(user_mode(regs));
- profile_tick(CPU_PROFILING, regs);
+ update_process_times(user_mode(get_irq_regs()));
+ profile_tick(CPU_PROFILING);
I'd like to move update_process_times()'s use of get_irq_regs() into itself,
except that i386, alone of the archs, uses something other than user_mode().
Some notes on the interrupt handling in the drivers:
(*) input_dev() is now gone entirely. The regs pointer is no longer stored in
the input_dev struct.
(*) finish_unlinks() in drivers/usb/host/ohci-q.c needs checking. It does
something different depending on whether it's been supplied with a regs
pointer or not.
(*) Various IRQ handler function pointers have been moved to type
irq_handler_t.
Signed-Off-By: David Howells <dhowells@redhat.com>
(cherry picked from 1b16e7ac850969f38b375e511e3fa2f474a33867 commit)
2006-10-05 21:55:46 +08:00
|
|
|
static void cyberjack_write_bulk_callback (struct urb *urb)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
struct usb_serial_port *port = (struct usb_serial_port *)urb->context;
|
|
|
|
struct cyberjack_private *priv = usb_get_serial_port_data(port);
|
2007-06-16 06:44:13 +08:00
|
|
|
int status = urb->status;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2008-03-04 08:08:34 +08:00
|
|
|
dbg("%s - port %d", __func__, port->number);
|
2005-04-24 03:49:16 +08:00
|
|
|
|
|
|
|
port->write_urb_busy = 0;
|
2007-06-16 06:44:13 +08:00
|
|
|
if (status) {
|
|
|
|
dbg("%s - nonzero write bulk status received: %d",
|
2008-03-04 08:08:34 +08:00
|
|
|
__func__, status);
|
2005-04-17 06:20:36 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
spin_lock(&priv->lock);
|
|
|
|
|
|
|
|
/* only do something if we have more data to send */
|
|
|
|
if( priv->wrfilled ) {
|
|
|
|
int length, blksize, result;
|
|
|
|
|
2008-03-04 08:08:34 +08:00
|
|
|
dbg("%s - transmitting data (frame n)", __func__);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
length = ((priv->wrfilled - priv->wrsent) > port->bulk_out_size) ?
|
|
|
|
port->bulk_out_size : (priv->wrfilled - priv->wrsent);
|
|
|
|
|
|
|
|
memcpy (port->write_urb->transfer_buffer, priv->wrbuf + priv->wrsent,
|
|
|
|
length );
|
|
|
|
priv->wrsent+=length;
|
|
|
|
|
|
|
|
/* set up our urb */
|
|
|
|
usb_fill_bulk_urb(port->write_urb, port->serial->dev,
|
|
|
|
usb_sndbulkpipe(port->serial->dev, port->bulk_out_endpointAddress),
|
|
|
|
port->write_urb->transfer_buffer, length,
|
|
|
|
((port->serial->type->write_bulk_callback) ?
|
|
|
|
port->serial->type->write_bulk_callback :
|
|
|
|
cyberjack_write_bulk_callback),
|
|
|
|
port);
|
|
|
|
|
|
|
|
/* send the data out the bulk port */
|
|
|
|
result = usb_submit_urb(port->write_urb, GFP_ATOMIC);
|
|
|
|
if (result) {
|
2008-03-04 08:08:34 +08:00
|
|
|
err("%s - failed submitting write urb, error %d", __func__, result);
|
2005-04-17 06:20:36 +08:00
|
|
|
/* Throw away data. No better idea what to do with it. */
|
2008-04-09 00:16:06 +08:00
|
|
|
priv->wrfilled = 0;
|
|
|
|
priv->wrsent = 0;
|
2005-04-17 06:20:36 +08:00
|
|
|
goto exit;
|
|
|
|
}
|
|
|
|
|
2008-03-04 08:08:34 +08:00
|
|
|
dbg("%s - priv->wrsent=%d", __func__,priv->wrsent);
|
|
|
|
dbg("%s - priv->wrfilled=%d", __func__,priv->wrfilled);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
blksize = ((int)priv->wrbuf[2]<<8)+priv->wrbuf[1]+3;
|
|
|
|
|
|
|
|
if( (priv->wrsent>=priv->wrfilled) || (priv->wrsent>=blksize) ) {
|
2008-03-04 08:08:34 +08:00
|
|
|
dbg("%s - buffer cleaned", __func__);
|
2005-04-17 06:20:36 +08:00
|
|
|
memset( priv->wrbuf, 0, sizeof(priv->wrbuf) );
|
2008-04-09 00:16:06 +08:00
|
|
|
priv->wrfilled = 0;
|
|
|
|
priv->wrsent = 0;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
exit:
|
|
|
|
spin_unlock(&priv->lock);
|
2006-05-23 12:58:49 +08:00
|
|
|
usb_serial_port_softint(port);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static int __init cyberjack_init (void)
|
|
|
|
{
|
|
|
|
int retval;
|
|
|
|
retval = usb_serial_register(&cyberjack_device);
|
|
|
|
if (retval)
|
|
|
|
goto failed_usb_serial_register;
|
|
|
|
retval = usb_register(&cyberjack_driver);
|
|
|
|
if (retval)
|
|
|
|
goto failed_usb_register;
|
|
|
|
|
|
|
|
info(DRIVER_VERSION " " DRIVER_AUTHOR);
|
|
|
|
info(DRIVER_DESC);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
failed_usb_register:
|
|
|
|
usb_serial_deregister(&cyberjack_device);
|
|
|
|
failed_usb_serial_register:
|
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void __exit cyberjack_exit (void)
|
|
|
|
{
|
|
|
|
usb_deregister (&cyberjack_driver);
|
|
|
|
usb_serial_deregister (&cyberjack_device);
|
|
|
|
}
|
|
|
|
|
|
|
|
module_init(cyberjack_init);
|
|
|
|
module_exit(cyberjack_exit);
|
|
|
|
|
|
|
|
MODULE_AUTHOR( DRIVER_AUTHOR );
|
|
|
|
MODULE_DESCRIPTION( DRIVER_DESC );
|
|
|
|
MODULE_VERSION( DRIVER_VERSION );
|
|
|
|
MODULE_LICENSE("GPL");
|
|
|
|
|
|
|
|
module_param(debug, bool, S_IRUGO | S_IWUSR);
|
|
|
|
MODULE_PARM_DESC(debug, "Debug enabled or not");
|