2005-04-17 00:20:36 +02:00
|
|
|
/*
|
|
|
|
* USB ConnectTech WhiteHEAT driver
|
|
|
|
*
|
|
|
|
* Copyright (C) 2002
|
|
|
|
* Connect Tech Inc.
|
|
|
|
*
|
|
|
|
* Copyright (C) 1999 - 2001
|
|
|
|
* Greg Kroah-Hartman (greg@kroah.com)
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*
|
2008-07-22 12:09:16 +02:00
|
|
|
* See Documentation/usb/usb-serial.txt for more information on using this
|
|
|
|
* driver
|
2005-04-17 00:20:36 +02:00
|
|
|
*
|
|
|
|
* (10/09/2002) Stuart MacDonald (stuartm@connecttech.com)
|
|
|
|
* Upgrade to full working driver
|
|
|
|
*
|
|
|
|
* (05/30/2001) gkh
|
2008-07-22 12:09:16 +02:00
|
|
|
* switched from using spinlock to a semaphore, which fixes lots of
|
|
|
|
* problems.
|
2005-04-17 00:20:36 +02:00
|
|
|
*
|
|
|
|
* (04/08/2001) gb
|
|
|
|
* Identify version on module load.
|
2008-07-22 12:09:16 +02:00
|
|
|
*
|
2005-04-17 00:20:36 +02:00
|
|
|
* 2001_Mar_19 gkh
|
2008-07-22 12:09:16 +02:00
|
|
|
* Fixed MOD_INC and MOD_DEC logic, the ability to open a port more
|
2005-04-17 00:20:36 +02:00
|
|
|
* than once, and the got the proper usb_device_id table entries so
|
|
|
|
* the driver works again.
|
|
|
|
*
|
|
|
|
* (11/01/2000) Adam J. Richter
|
|
|
|
* usb_device_id table support
|
2008-07-22 12:09:16 +02:00
|
|
|
*
|
2005-04-17 00:20:36 +02:00
|
|
|
* (10/05/2000) gkh
|
|
|
|
* Fixed bug with urb->dev not being set properly, now that the usb
|
|
|
|
* core needs it.
|
2008-07-22 12:09:16 +02:00
|
|
|
*
|
2005-04-17 00:20:36 +02:00
|
|
|
* (10/03/2000) smd
|
|
|
|
* firmware is improved to guard against crap sent to device
|
|
|
|
* firmware now replies CMD_FAILURE on bad things
|
|
|
|
* read_callback fix you provided for private info struct
|
|
|
|
* command_finished now indicates success or fail
|
|
|
|
* setup_port struct now packed to avoid gcc padding
|
|
|
|
* firmware uses 1 based port numbering, driver now handles that
|
|
|
|
*
|
|
|
|
* (09/11/2000) gkh
|
|
|
|
* Removed DEBUG #ifdefs with call to usb_serial_debug_data
|
|
|
|
*
|
|
|
|
* (07/19/2000) gkh
|
|
|
|
* Added module_init and module_exit functions to handle the fact that this
|
|
|
|
* driver is a loadable module now.
|
|
|
|
* Fixed bug with port->minor that was found by Al Borchers
|
|
|
|
*
|
|
|
|
* (07/04/2000) gkh
|
2008-07-22 12:09:16 +02:00
|
|
|
* Added support for port settings. Baud rate can now be changed. Line
|
|
|
|
* signals are not transferred to and from the tty layer yet, but things
|
|
|
|
* seem to be working well now.
|
2005-04-17 00:20:36 +02:00
|
|
|
*
|
|
|
|
* (05/04/2000) gkh
|
|
|
|
* First cut at open and close commands. Data can flow through the ports at
|
|
|
|
* default speeds now.
|
|
|
|
*
|
|
|
|
* (03/26/2000) gkh
|
|
|
|
* Split driver up into device specific pieces.
|
2008-07-22 12:09:16 +02:00
|
|
|
*
|
2005-04-17 00:20:36 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
#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>
|
2007-05-24 13:52:51 +02:00
|
|
|
#include <linux/mutex.h>
|
2008-07-22 12:09:16 +02:00
|
|
|
#include <linux/uaccess.h>
|
2005-04-17 00:20:36 +02:00
|
|
|
#include <asm/termbits.h>
|
|
|
|
#include <linux/usb.h>
|
|
|
|
#include <linux/serial_reg.h>
|
|
|
|
#include <linux/serial.h>
|
2006-07-12 06:22:58 +02:00
|
|
|
#include <linux/usb/serial.h>
|
2008-05-31 00:35:29 +02:00
|
|
|
#include <linux/firmware.h>
|
|
|
|
#include <linux/ihex.h>
|
2005-04-17 00:20:36 +02:00
|
|
|
#include "whiteheat.h" /* WhiteHEAT specific commands */
|
|
|
|
|
|
|
|
static int debug;
|
|
|
|
|
|
|
|
#ifndef CMSPAR
|
|
|
|
#define CMSPAR 0
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Version Information
|
|
|
|
*/
|
|
|
|
#define DRIVER_VERSION "v2.0"
|
|
|
|
#define DRIVER_AUTHOR "Greg Kroah-Hartman <greg@kroah.com>, Stuart MacDonald <stuartm@connecttech.com>"
|
|
|
|
#define DRIVER_DESC "USB ConnectTech WhiteHEAT driver"
|
|
|
|
|
|
|
|
#define CONNECT_TECH_VENDOR_ID 0x0710
|
|
|
|
#define CONNECT_TECH_FAKE_WHITE_HEAT_ID 0x0001
|
|
|
|
#define CONNECT_TECH_WHITE_HEAT_ID 0x8001
|
|
|
|
|
|
|
|
/*
|
|
|
|
ID tables for whiteheat are unusual, because we want to different
|
|
|
|
things for different versions of the device. Eventually, this
|
|
|
|
will be doable from a single table. But, for now, we define two
|
|
|
|
separate ID tables, and then a third table that combines them
|
|
|
|
just for the purpose of exporting the autoloading information.
|
|
|
|
*/
|
|
|
|
static struct usb_device_id id_table_std [] = {
|
|
|
|
{ USB_DEVICE(CONNECT_TECH_VENDOR_ID, CONNECT_TECH_WHITE_HEAT_ID) },
|
|
|
|
{ } /* Terminating entry */
|
|
|
|
};
|
|
|
|
|
|
|
|
static struct usb_device_id id_table_prerenumeration [] = {
|
|
|
|
{ USB_DEVICE(CONNECT_TECH_VENDOR_ID, CONNECT_TECH_FAKE_WHITE_HEAT_ID) },
|
|
|
|
{ } /* Terminating entry */
|
|
|
|
};
|
|
|
|
|
|
|
|
static struct usb_device_id id_table_combined [] = {
|
|
|
|
{ USB_DEVICE(CONNECT_TECH_VENDOR_ID, CONNECT_TECH_WHITE_HEAT_ID) },
|
|
|
|
{ USB_DEVICE(CONNECT_TECH_VENDOR_ID, CONNECT_TECH_FAKE_WHITE_HEAT_ID) },
|
|
|
|
{ } /* Terminating entry */
|
|
|
|
};
|
|
|
|
|
2008-07-22 12:09:16 +02:00
|
|
|
MODULE_DEVICE_TABLE(usb, id_table_combined);
|
2005-04-17 00:20:36 +02:00
|
|
|
|
|
|
|
static struct usb_driver whiteheat_driver = {
|
|
|
|
.name = "whiteheat",
|
|
|
|
.probe = usb_serial_probe,
|
|
|
|
.disconnect = usb_serial_disconnect,
|
|
|
|
.id_table = id_table_combined,
|
2005-11-16 22:41:28 +01:00
|
|
|
.no_dynamic_id = 1,
|
2005-04-17 00:20:36 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
/* function prototypes for the Connect Tech WhiteHEAT prerenumeration device */
|
2008-07-22 12:09:16 +02:00
|
|
|
static int whiteheat_firmware_download(struct usb_serial *serial,
|
|
|
|
const struct usb_device_id *id);
|
|
|
|
static int whiteheat_firmware_attach(struct usb_serial *serial);
|
2005-04-17 00:20:36 +02:00
|
|
|
|
|
|
|
/* function prototypes for the Connect Tech WhiteHEAT serial converter */
|
2008-07-22 12:09:16 +02:00
|
|
|
static int whiteheat_attach(struct usb_serial *serial);
|
|
|
|
static void whiteheat_shutdown(struct usb_serial *serial);
|
|
|
|
static int whiteheat_open(struct tty_struct *tty,
|
|
|
|
struct usb_serial_port *port, struct file *filp);
|
|
|
|
static void whiteheat_close(struct tty_struct *tty,
|
|
|
|
struct usb_serial_port *port, struct file *filp);
|
|
|
|
static int whiteheat_write(struct tty_struct *tty,
|
|
|
|
struct usb_serial_port *port,
|
|
|
|
const unsigned char *buf, int count);
|
|
|
|
static int whiteheat_write_room(struct tty_struct *tty);
|
|
|
|
static int whiteheat_ioctl(struct tty_struct *tty, struct file *file,
|
|
|
|
unsigned int cmd, unsigned long arg);
|
|
|
|
static void whiteheat_set_termios(struct tty_struct *tty,
|
|
|
|
struct usb_serial_port *port, struct ktermios *old);
|
|
|
|
static int whiteheat_tiocmget(struct tty_struct *tty, struct file *file);
|
|
|
|
static int whiteheat_tiocmset(struct tty_struct *tty, struct file *file,
|
|
|
|
unsigned int set, unsigned int clear);
|
|
|
|
static void whiteheat_break_ctl(struct tty_struct *tty, int break_state);
|
|
|
|
static int whiteheat_chars_in_buffer(struct tty_struct *tty);
|
|
|
|
static void whiteheat_throttle(struct tty_struct *tty);
|
|
|
|
static void whiteheat_unthrottle(struct tty_struct *tty);
|
|
|
|
static void whiteheat_read_callback(struct urb *urb);
|
|
|
|
static void whiteheat_write_callback(struct urb *urb);
|
2005-04-17 00:20:36 +02:00
|
|
|
|
2005-06-21 06:15:16 +02:00
|
|
|
static struct usb_serial_driver whiteheat_fake_device = {
|
2005-06-21 06:15:16 +02:00
|
|
|
.driver = {
|
|
|
|
.owner = THIS_MODULE,
|
2005-06-21 06:15:16 +02:00
|
|
|
.name = "whiteheatnofirm",
|
2005-06-21 06:15:16 +02:00
|
|
|
},
|
2005-06-21 06:15:16 +02:00
|
|
|
.description = "Connect Tech - WhiteHEAT - (prerenumeration)",
|
2006-12-17 21:50:24 +01:00
|
|
|
.usb_driver = &whiteheat_driver,
|
2005-04-17 00:20:36 +02:00
|
|
|
.id_table = id_table_prerenumeration,
|
|
|
|
.num_ports = 1,
|
|
|
|
.probe = whiteheat_firmware_download,
|
|
|
|
.attach = whiteheat_firmware_attach,
|
|
|
|
};
|
|
|
|
|
2005-06-21 06:15:16 +02:00
|
|
|
static struct usb_serial_driver whiteheat_device = {
|
2005-06-21 06:15:16 +02:00
|
|
|
.driver = {
|
|
|
|
.owner = THIS_MODULE,
|
2005-06-21 06:15:16 +02:00
|
|
|
.name = "whiteheat",
|
2005-06-21 06:15:16 +02:00
|
|
|
},
|
2005-06-21 06:15:16 +02:00
|
|
|
.description = "Connect Tech - WhiteHEAT",
|
2006-12-17 21:50:24 +01:00
|
|
|
.usb_driver = &whiteheat_driver,
|
2005-04-17 00:20:36 +02:00
|
|
|
.id_table = id_table_std,
|
|
|
|
.num_ports = 4,
|
|
|
|
.attach = whiteheat_attach,
|
|
|
|
.shutdown = whiteheat_shutdown,
|
|
|
|
.open = whiteheat_open,
|
|
|
|
.close = whiteheat_close,
|
|
|
|
.write = whiteheat_write,
|
|
|
|
.write_room = whiteheat_write_room,
|
|
|
|
.ioctl = whiteheat_ioctl,
|
|
|
|
.set_termios = whiteheat_set_termios,
|
|
|
|
.break_ctl = whiteheat_break_ctl,
|
|
|
|
.tiocmget = whiteheat_tiocmget,
|
|
|
|
.tiocmset = whiteheat_tiocmset,
|
|
|
|
.chars_in_buffer = whiteheat_chars_in_buffer,
|
|
|
|
.throttle = whiteheat_throttle,
|
|
|
|
.unthrottle = whiteheat_unthrottle,
|
|
|
|
.read_bulk_callback = whiteheat_read_callback,
|
|
|
|
.write_bulk_callback = whiteheat_write_callback,
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
struct whiteheat_command_private {
|
2007-05-24 13:52:51 +02:00
|
|
|
struct mutex mutex;
|
2005-04-17 00:20:36 +02:00
|
|
|
__u8 port_running;
|
|
|
|
__u8 command_finished;
|
2008-07-22 12:09:16 +02:00
|
|
|
wait_queue_head_t wait_command; /* for handling sleeping whilst
|
|
|
|
waiting for a command to
|
|
|
|
finish */
|
2005-04-17 00:20:36 +02:00
|
|
|
__u8 result_buffer[64];
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
#define THROTTLED 0x01
|
|
|
|
#define ACTUALLY_THROTTLED 0x02
|
|
|
|
|
|
|
|
static int urb_pool_size = 8;
|
|
|
|
|
|
|
|
struct whiteheat_urb_wrap {
|
|
|
|
struct list_head list;
|
|
|
|
struct urb *urb;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct whiteheat_private {
|
|
|
|
spinlock_t lock;
|
|
|
|
__u8 flags;
|
2008-04-08 18:16:06 +02:00
|
|
|
__u8 mcr; /* FIXME: no locking on mcr */
|
2005-04-17 00:20:36 +02:00
|
|
|
struct list_head rx_urbs_free;
|
|
|
|
struct list_head rx_urbs_submitted;
|
|
|
|
struct list_head rx_urb_q;
|
|
|
|
struct work_struct rx_work;
|
2006-11-22 15:57:56 +01:00
|
|
|
struct usb_serial_port *port;
|
2005-04-17 00:20:36 +02:00
|
|
|
struct list_head tx_urbs_free;
|
|
|
|
struct list_head tx_urbs_submitted;
|
2007-05-24 13:52:51 +02:00
|
|
|
struct mutex deathwarrant;
|
2005-04-17 00:20:36 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/* local function prototypes */
|
|
|
|
static int start_command_port(struct usb_serial *serial);
|
|
|
|
static void stop_command_port(struct usb_serial *serial);
|
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 15:55:46 +02:00
|
|
|
static void command_port_write_callback(struct urb *urb);
|
|
|
|
static void command_port_read_callback(struct urb *urb);
|
2005-04-17 00:20:36 +02:00
|
|
|
|
|
|
|
static int start_port_read(struct usb_serial_port *port);
|
2008-07-22 12:09:16 +02:00
|
|
|
static struct whiteheat_urb_wrap *urb_to_wrap(struct urb *urb,
|
|
|
|
struct list_head *head);
|
2005-04-17 00:20:36 +02:00
|
|
|
static struct list_head *list_first(struct list_head *head);
|
2006-11-22 15:57:56 +01:00
|
|
|
static void rx_data_softint(struct work_struct *work);
|
2005-04-17 00:20:36 +02:00
|
|
|
|
2008-07-22 12:09:16 +02:00
|
|
|
static int firm_send_command(struct usb_serial_port *port, __u8 command,
|
|
|
|
__u8 *data, __u8 datasize);
|
2005-04-17 00:20:36 +02:00
|
|
|
static int firm_open(struct usb_serial_port *port);
|
|
|
|
static int firm_close(struct usb_serial_port *port);
|
2008-07-22 12:09:07 +02:00
|
|
|
static int firm_setup_port(struct tty_struct *tty);
|
2005-04-17 00:20:36 +02:00
|
|
|
static int firm_set_rts(struct usb_serial_port *port, __u8 onoff);
|
|
|
|
static int firm_set_dtr(struct usb_serial_port *port, __u8 onoff);
|
|
|
|
static int firm_set_break(struct usb_serial_port *port, __u8 onoff);
|
|
|
|
static int firm_purge(struct usb_serial_port *port, __u8 rxtx);
|
|
|
|
static int firm_get_dtr_rts(struct usb_serial_port *port);
|
|
|
|
static int firm_report_tx_done(struct usb_serial_port *port);
|
|
|
|
|
|
|
|
|
|
|
|
#define COMMAND_PORT 4
|
|
|
|
#define COMMAND_TIMEOUT (2*HZ) /* 2 second timeout for a command */
|
|
|
|
#define COMMAND_TIMEOUT_MS 2000
|
|
|
|
#define CLOSING_DELAY (30 * HZ)
|
|
|
|
|
|
|
|
|
|
|
|
/*****************************************************************************
|
|
|
|
* Connect Tech's White Heat prerenumeration driver functions
|
|
|
|
*****************************************************************************/
|
|
|
|
|
|
|
|
/* steps to download the firmware to the WhiteHEAT device:
|
|
|
|
- hold the reset (by writing to the reset bit of the CPUCS register)
|
|
|
|
- download the VEND_AX.HEX file to the chip using VENDOR_REQUEST-ANCHOR_LOAD
|
|
|
|
- release the reset (by writing to the CPUCS register)
|
|
|
|
- download the WH.HEX file for all addresses greater than 0x1b3f using
|
|
|
|
VENDOR_REQUEST-ANCHOR_EXTERNAL_RAM_LOAD
|
|
|
|
- hold the reset
|
|
|
|
- download the WH.HEX file for all addresses less than 0x1b40 using
|
|
|
|
VENDOR_REQUEST_ANCHOR_LOAD
|
|
|
|
- release the reset
|
|
|
|
- device renumerated itself and comes up as new device id with all
|
|
|
|
firmware download completed.
|
|
|
|
*/
|
2008-07-22 12:09:16 +02:00
|
|
|
static int whiteheat_firmware_download(struct usb_serial *serial,
|
|
|
|
const struct usb_device_id *id)
|
2005-04-17 00:20:36 +02:00
|
|
|
{
|
2008-05-31 00:35:29 +02:00
|
|
|
int response, ret = -ENOENT;
|
|
|
|
const struct firmware *loader_fw = NULL, *firmware_fw = NULL;
|
|
|
|
const struct ihex_binrec *record;
|
|
|
|
|
2008-03-04 01:08:34 +01:00
|
|
|
dbg("%s", __func__);
|
2008-05-31 00:35:29 +02:00
|
|
|
|
|
|
|
if (request_ihex_firmware(&firmware_fw, "whiteheat.fw",
|
|
|
|
&serial->dev->dev)) {
|
2008-08-21 01:56:34 +02:00
|
|
|
dev_err(&serial->dev->dev,
|
|
|
|
"%s - request \"whiteheat.fw\" failed\n", __func__);
|
2008-05-31 00:35:29 +02:00
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
if (request_ihex_firmware(&loader_fw, "whiteheat_loader.fw",
|
|
|
|
&serial->dev->dev)) {
|
2008-08-21 01:56:34 +02:00
|
|
|
dev_err(&serial->dev->dev,
|
|
|
|
"%s - request \"whiteheat_loader.fw\" failed\n",
|
|
|
|
__func__);
|
2008-05-31 00:35:29 +02:00
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
ret = 0;
|
2005-04-17 00:20:36 +02:00
|
|
|
response = ezusb_set_reset (serial, 1);
|
|
|
|
|
2008-05-31 00:35:29 +02:00
|
|
|
record = (const struct ihex_binrec *)loader_fw->data;
|
|
|
|
while (record) {
|
|
|
|
response = ezusb_writememory (serial, be32_to_cpu(record->addr),
|
|
|
|
(unsigned char *)record->data,
|
|
|
|
be16_to_cpu(record->len), 0xa0);
|
2005-04-17 00:20:36 +02:00
|
|
|
if (response < 0) {
|
2008-08-21 01:56:34 +02:00
|
|
|
dev_err(&serial->dev->dev, "%s - ezusb_writememory "
|
|
|
|
"failed for loader (%d %04X %p %d)\n",
|
|
|
|
__func__, response, be32_to_cpu(record->addr),
|
|
|
|
record->data, be16_to_cpu(record->len));
|
2005-04-17 00:20:36 +02:00
|
|
|
break;
|
|
|
|
}
|
2008-05-31 00:35:29 +02:00
|
|
|
record = ihex_next_binrec(record);
|
2005-04-17 00:20:36 +02:00
|
|
|
}
|
|
|
|
|
2008-07-22 12:09:16 +02:00
|
|
|
response = ezusb_set_reset(serial, 0);
|
2005-04-17 00:20:36 +02:00
|
|
|
|
2008-05-31 00:35:29 +02:00
|
|
|
record = (const struct ihex_binrec *)firmware_fw->data;
|
|
|
|
while (record && be32_to_cpu(record->addr) < 0x1b40)
|
|
|
|
record = ihex_next_binrec(record);
|
|
|
|
while (record) {
|
|
|
|
response = ezusb_writememory (serial, be32_to_cpu(record->addr),
|
|
|
|
(unsigned char *)record->data,
|
|
|
|
be16_to_cpu(record->len), 0xa3);
|
2005-04-17 00:20:36 +02:00
|
|
|
if (response < 0) {
|
2008-08-21 01:56:34 +02:00
|
|
|
dev_err(&serial->dev->dev, "%s - ezusb_writememory "
|
|
|
|
"failed for first firmware step "
|
|
|
|
"(%d %04X %p %d)\n", __func__, response,
|
|
|
|
be32_to_cpu(record->addr), record->data,
|
|
|
|
be16_to_cpu(record->len));
|
2005-04-17 00:20:36 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
++record;
|
|
|
|
}
|
2008-07-22 12:09:16 +02:00
|
|
|
|
|
|
|
response = ezusb_set_reset(serial, 1);
|
2005-04-17 00:20:36 +02:00
|
|
|
|
2008-05-31 00:35:29 +02:00
|
|
|
record = (const struct ihex_binrec *)firmware_fw->data;
|
|
|
|
while (record && be32_to_cpu(record->addr) < 0x1b40) {
|
|
|
|
response = ezusb_writememory (serial, be32_to_cpu(record->addr),
|
|
|
|
(unsigned char *)record->data,
|
|
|
|
be16_to_cpu(record->len), 0xa0);
|
2005-04-17 00:20:36 +02:00
|
|
|
if (response < 0) {
|
2008-08-21 01:56:34 +02:00
|
|
|
dev_err(&serial->dev->dev, "%s - ezusb_writememory "
|
|
|
|
"failed for second firmware step "
|
|
|
|
"(%d %04X %p %d)\n", __func__, response,
|
|
|
|
be32_to_cpu(record->addr), record->data,
|
|
|
|
be16_to_cpu(record->len));
|
2005-04-17 00:20:36 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
++record;
|
|
|
|
}
|
2008-05-31 00:35:29 +02:00
|
|
|
ret = 0;
|
2005-04-17 00:20:36 +02:00
|
|
|
response = ezusb_set_reset (serial, 0);
|
2008-05-31 00:35:29 +02:00
|
|
|
out:
|
|
|
|
release_firmware(loader_fw);
|
|
|
|
release_firmware(firmware_fw);
|
|
|
|
return ret;
|
2005-04-17 00:20:36 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-07-22 12:09:16 +02:00
|
|
|
static int whiteheat_firmware_attach(struct usb_serial *serial)
|
2005-04-17 00:20:36 +02:00
|
|
|
{
|
|
|
|
/* We want this device to fail to have a driver assigned to it */
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*****************************************************************************
|
|
|
|
* Connect Tech's White Heat serial driver functions
|
|
|
|
*****************************************************************************/
|
2008-07-22 12:09:16 +02:00
|
|
|
static int whiteheat_attach(struct usb_serial *serial)
|
2005-04-17 00:20:36 +02:00
|
|
|
{
|
|
|
|
struct usb_serial_port *command_port;
|
|
|
|
struct whiteheat_command_private *command_info;
|
|
|
|
struct usb_serial_port *port;
|
|
|
|
struct whiteheat_private *info;
|
|
|
|
struct whiteheat_hw_info *hw_info;
|
|
|
|
int pipe;
|
|
|
|
int ret;
|
|
|
|
int alen;
|
|
|
|
__u8 *command;
|
|
|
|
__u8 *result;
|
|
|
|
int i;
|
|
|
|
int j;
|
|
|
|
struct urb *urb;
|
|
|
|
int buf_size;
|
|
|
|
struct whiteheat_urb_wrap *wrap;
|
|
|
|
struct list_head *tmp;
|
|
|
|
|
|
|
|
command_port = serial->port[COMMAND_PORT];
|
|
|
|
|
2008-07-22 12:09:16 +02:00
|
|
|
pipe = usb_sndbulkpipe(serial->dev,
|
|
|
|
command_port->bulk_out_endpointAddress);
|
2005-04-17 00:20:36 +02:00
|
|
|
command = kmalloc(2, GFP_KERNEL);
|
|
|
|
if (!command)
|
|
|
|
goto no_command_buffer;
|
|
|
|
command[0] = WHITEHEAT_GET_HW_INFO;
|
|
|
|
command[1] = 0;
|
2008-07-22 12:09:16 +02:00
|
|
|
|
2005-04-17 00:20:36 +02:00
|
|
|
result = kmalloc(sizeof(*hw_info) + 1, GFP_KERNEL);
|
|
|
|
if (!result)
|
|
|
|
goto no_result_buffer;
|
|
|
|
/*
|
|
|
|
* When the module is reloaded the firmware is still there and
|
|
|
|
* the endpoints are still in the usb core unchanged. This is the
|
2008-07-22 12:09:16 +02:00
|
|
|
* unlinking bug in disguise. Same for the call below.
|
|
|
|
*/
|
2005-04-17 00:20:36 +02:00
|
|
|
usb_clear_halt(serial->dev, pipe);
|
2008-07-22 12:09:16 +02:00
|
|
|
ret = usb_bulk_msg(serial->dev, pipe, command, 2,
|
|
|
|
&alen, COMMAND_TIMEOUT_MS);
|
2005-04-17 00:20:36 +02:00
|
|
|
if (ret) {
|
2008-08-21 01:56:34 +02:00
|
|
|
dev_err(&serial->dev->dev, "%s: Couldn't send command [%d]\n",
|
|
|
|
serial->type->description, ret);
|
2005-04-17 00:20:36 +02:00
|
|
|
goto no_firmware;
|
2006-05-31 19:28:40 +02:00
|
|
|
} else if (alen != 2) {
|
2008-08-21 01:56:34 +02:00
|
|
|
dev_err(&serial->dev->dev, "%s: Send command incomplete [%d]\n",
|
|
|
|
serial->type->description, alen);
|
2005-04-17 00:20:36 +02:00
|
|
|
goto no_firmware;
|
|
|
|
}
|
|
|
|
|
2008-07-22 12:09:16 +02:00
|
|
|
pipe = usb_rcvbulkpipe(serial->dev,
|
|
|
|
command_port->bulk_in_endpointAddress);
|
2005-04-17 00:20:36 +02:00
|
|
|
/* See the comment on the usb_clear_halt() above */
|
|
|
|
usb_clear_halt(serial->dev, pipe);
|
2008-07-22 12:09:16 +02:00
|
|
|
ret = usb_bulk_msg(serial->dev, pipe, result,
|
|
|
|
sizeof(*hw_info) + 1, &alen, COMMAND_TIMEOUT_MS);
|
2005-04-17 00:20:36 +02:00
|
|
|
if (ret) {
|
2008-08-21 01:56:34 +02:00
|
|
|
dev_err(&serial->dev->dev, "%s: Couldn't get results [%d]\n",
|
|
|
|
serial->type->description, ret);
|
2005-04-17 00:20:36 +02:00
|
|
|
goto no_firmware;
|
2006-05-31 19:28:40 +02:00
|
|
|
} else if (alen != sizeof(*hw_info) + 1) {
|
2008-08-21 01:56:34 +02:00
|
|
|
dev_err(&serial->dev->dev, "%s: Get results incomplete [%d]\n",
|
|
|
|
serial->type->description, alen);
|
2005-04-17 00:20:36 +02:00
|
|
|
goto no_firmware;
|
|
|
|
} else if (result[0] != command[0]) {
|
2008-08-21 01:56:34 +02:00
|
|
|
dev_err(&serial->dev->dev, "%s: Command failed [%d]\n",
|
|
|
|
serial->type->description, result[0]);
|
2005-04-17 00:20:36 +02:00
|
|
|
goto no_firmware;
|
|
|
|
}
|
|
|
|
|
|
|
|
hw_info = (struct whiteheat_hw_info *)&result[1];
|
|
|
|
|
2008-08-18 22:21:04 +02:00
|
|
|
dev_info(&serial->dev->dev, "%s: Driver %s: Firmware v%d.%02d\n",
|
|
|
|
serial->type->description, DRIVER_VERSION,
|
|
|
|
hw_info->sw_major_rev, hw_info->sw_minor_rev);
|
2005-04-17 00:20:36 +02:00
|
|
|
|
|
|
|
for (i = 0; i < serial->num_ports; i++) {
|
|
|
|
port = serial->port[i];
|
|
|
|
|
2006-12-13 09:35:56 +01:00
|
|
|
info = kmalloc(sizeof(struct whiteheat_private), GFP_KERNEL);
|
2005-04-17 00:20:36 +02:00
|
|
|
if (info == NULL) {
|
2008-08-21 01:56:34 +02:00
|
|
|
dev_err(&port->dev,
|
|
|
|
"%s: Out of memory for port structures\n",
|
|
|
|
serial->type->description);
|
2005-04-17 00:20:36 +02:00
|
|
|
goto no_private;
|
|
|
|
}
|
|
|
|
|
|
|
|
spin_lock_init(&info->lock);
|
2007-05-24 13:52:51 +02:00
|
|
|
mutex_init(&info->deathwarrant);
|
2005-04-17 00:20:36 +02:00
|
|
|
info->flags = 0;
|
|
|
|
info->mcr = 0;
|
2006-11-22 15:57:56 +01:00
|
|
|
INIT_WORK(&info->rx_work, rx_data_softint);
|
|
|
|
info->port = port;
|
2005-04-17 00:20:36 +02:00
|
|
|
|
|
|
|
INIT_LIST_HEAD(&info->rx_urbs_free);
|
|
|
|
INIT_LIST_HEAD(&info->rx_urbs_submitted);
|
|
|
|
INIT_LIST_HEAD(&info->rx_urb_q);
|
|
|
|
INIT_LIST_HEAD(&info->tx_urbs_free);
|
|
|
|
INIT_LIST_HEAD(&info->tx_urbs_submitted);
|
|
|
|
|
|
|
|
for (j = 0; j < urb_pool_size; j++) {
|
|
|
|
urb = usb_alloc_urb(0, GFP_KERNEL);
|
|
|
|
if (!urb) {
|
2008-08-21 01:56:34 +02:00
|
|
|
dev_err(&port->dev, "No free urbs available\n");
|
2005-04-17 00:20:36 +02:00
|
|
|
goto no_rx_urb;
|
|
|
|
}
|
|
|
|
buf_size = port->read_urb->transfer_buffer_length;
|
|
|
|
urb->transfer_buffer = kmalloc(buf_size, GFP_KERNEL);
|
|
|
|
if (!urb->transfer_buffer) {
|
2008-08-21 01:56:34 +02:00
|
|
|
dev_err(&port->dev,
|
|
|
|
"Couldn't allocate urb buffer\n");
|
2005-04-17 00:20:36 +02:00
|
|
|
goto no_rx_buf;
|
|
|
|
}
|
|
|
|
wrap = kmalloc(sizeof(*wrap), GFP_KERNEL);
|
|
|
|
if (!wrap) {
|
2008-08-21 01:56:34 +02:00
|
|
|
dev_err(&port->dev,
|
|
|
|
"Couldn't allocate urb wrapper\n");
|
2005-04-17 00:20:36 +02:00
|
|
|
goto no_rx_wrap;
|
|
|
|
}
|
|
|
|
usb_fill_bulk_urb(urb, serial->dev,
|
|
|
|
usb_rcvbulkpipe(serial->dev,
|
|
|
|
port->bulk_in_endpointAddress),
|
|
|
|
urb->transfer_buffer, buf_size,
|
|
|
|
whiteheat_read_callback, port);
|
|
|
|
wrap->urb = urb;
|
|
|
|
list_add(&wrap->list, &info->rx_urbs_free);
|
|
|
|
|
|
|
|
urb = usb_alloc_urb(0, GFP_KERNEL);
|
|
|
|
if (!urb) {
|
2008-08-21 01:56:34 +02:00
|
|
|
dev_err(&port->dev, "No free urbs available\n");
|
2005-04-17 00:20:36 +02:00
|
|
|
goto no_tx_urb;
|
|
|
|
}
|
|
|
|
buf_size = port->write_urb->transfer_buffer_length;
|
|
|
|
urb->transfer_buffer = kmalloc(buf_size, GFP_KERNEL);
|
|
|
|
if (!urb->transfer_buffer) {
|
2008-08-21 01:56:34 +02:00
|
|
|
dev_err(&port->dev,
|
|
|
|
"Couldn't allocate urb buffer\n");
|
2005-04-17 00:20:36 +02:00
|
|
|
goto no_tx_buf;
|
|
|
|
}
|
|
|
|
wrap = kmalloc(sizeof(*wrap), GFP_KERNEL);
|
|
|
|
if (!wrap) {
|
2008-08-21 01:56:34 +02:00
|
|
|
dev_err(&port->dev,
|
|
|
|
"Couldn't allocate urb wrapper\n");
|
2005-04-17 00:20:36 +02:00
|
|
|
goto no_tx_wrap;
|
|
|
|
}
|
|
|
|
usb_fill_bulk_urb(urb, serial->dev,
|
|
|
|
usb_sndbulkpipe(serial->dev,
|
|
|
|
port->bulk_out_endpointAddress),
|
|
|
|
urb->transfer_buffer, buf_size,
|
|
|
|
whiteheat_write_callback, port);
|
|
|
|
wrap->urb = urb;
|
|
|
|
list_add(&wrap->list, &info->tx_urbs_free);
|
|
|
|
}
|
|
|
|
|
|
|
|
usb_set_serial_port_data(port, info);
|
|
|
|
}
|
|
|
|
|
2008-07-22 12:09:16 +02:00
|
|
|
command_info = kmalloc(sizeof(struct whiteheat_command_private),
|
|
|
|
GFP_KERNEL);
|
2005-04-17 00:20:36 +02:00
|
|
|
if (command_info == NULL) {
|
2008-08-21 01:56:34 +02:00
|
|
|
dev_err(&serial->dev->dev,
|
|
|
|
"%s: Out of memory for port structures\n",
|
|
|
|
serial->type->description);
|
2005-04-17 00:20:36 +02:00
|
|
|
goto no_command_private;
|
|
|
|
}
|
|
|
|
|
2007-05-24 13:52:51 +02:00
|
|
|
mutex_init(&command_info->mutex);
|
2005-04-17 00:20:36 +02:00
|
|
|
command_info->port_running = 0;
|
|
|
|
init_waitqueue_head(&command_info->wait_command);
|
|
|
|
usb_set_serial_port_data(command_port, command_info);
|
|
|
|
command_port->write_urb->complete = command_port_write_callback;
|
|
|
|
command_port->read_urb->complete = command_port_read_callback;
|
|
|
|
kfree(result);
|
|
|
|
kfree(command);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
no_firmware:
|
|
|
|
/* Firmware likely not running */
|
2008-08-21 01:56:34 +02:00
|
|
|
dev_err(&serial->dev->dev,
|
|
|
|
"%s: Unable to retrieve firmware version, try replugging\n",
|
|
|
|
serial->type->description);
|
|
|
|
dev_err(&serial->dev->dev,
|
|
|
|
"%s: If the firmware is not running (status led not blinking)\n",
|
|
|
|
serial->type->description);
|
|
|
|
dev_err(&serial->dev->dev,
|
|
|
|
"%s: please contact support@connecttech.com\n",
|
|
|
|
serial->type->description);
|
2006-04-23 19:59:23 +02:00
|
|
|
kfree(result);
|
2005-04-17 00:20:36 +02:00
|
|
|
return -ENODEV;
|
|
|
|
|
|
|
|
no_command_private:
|
|
|
|
for (i = serial->num_ports - 1; i >= 0; i--) {
|
|
|
|
port = serial->port[i];
|
|
|
|
info = usb_get_serial_port_data(port);
|
|
|
|
for (j = urb_pool_size - 1; j >= 0; j--) {
|
|
|
|
tmp = list_first(&info->tx_urbs_free);
|
|
|
|
list_del(tmp);
|
|
|
|
wrap = list_entry(tmp, struct whiteheat_urb_wrap, list);
|
|
|
|
urb = wrap->urb;
|
|
|
|
kfree(wrap);
|
|
|
|
no_tx_wrap:
|
|
|
|
kfree(urb->transfer_buffer);
|
|
|
|
no_tx_buf:
|
|
|
|
usb_free_urb(urb);
|
|
|
|
no_tx_urb:
|
|
|
|
tmp = list_first(&info->rx_urbs_free);
|
|
|
|
list_del(tmp);
|
|
|
|
wrap = list_entry(tmp, struct whiteheat_urb_wrap, list);
|
|
|
|
urb = wrap->urb;
|
|
|
|
kfree(wrap);
|
|
|
|
no_rx_wrap:
|
|
|
|
kfree(urb->transfer_buffer);
|
|
|
|
no_rx_buf:
|
|
|
|
usb_free_urb(urb);
|
|
|
|
no_rx_urb:
|
|
|
|
;
|
|
|
|
}
|
|
|
|
kfree(info);
|
|
|
|
no_private:
|
|
|
|
;
|
|
|
|
}
|
|
|
|
kfree(result);
|
|
|
|
no_result_buffer:
|
|
|
|
kfree(command);
|
|
|
|
no_command_buffer:
|
|
|
|
return -ENOMEM;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-07-22 12:09:16 +02:00
|
|
|
static void whiteheat_shutdown(struct usb_serial *serial)
|
2005-04-17 00:20:36 +02:00
|
|
|
{
|
|
|
|
struct usb_serial_port *command_port;
|
|
|
|
struct usb_serial_port *port;
|
|
|
|
struct whiteheat_private *info;
|
|
|
|
struct whiteheat_urb_wrap *wrap;
|
|
|
|
struct urb *urb;
|
|
|
|
struct list_head *tmp;
|
|
|
|
struct list_head *tmp2;
|
|
|
|
int i;
|
|
|
|
|
2008-03-04 01:08:34 +01:00
|
|
|
dbg("%s", __func__);
|
2005-04-17 00:20:36 +02:00
|
|
|
|
|
|
|
/* free up our private data for our command port */
|
|
|
|
command_port = serial->port[COMMAND_PORT];
|
2008-07-22 12:09:16 +02:00
|
|
|
kfree(usb_get_serial_port_data(command_port));
|
2005-04-17 00:20:36 +02:00
|
|
|
|
|
|
|
for (i = 0; i < serial->num_ports; i++) {
|
|
|
|
port = serial->port[i];
|
|
|
|
info = usb_get_serial_port_data(port);
|
|
|
|
list_for_each_safe(tmp, tmp2, &info->rx_urbs_free) {
|
|
|
|
list_del(tmp);
|
|
|
|
wrap = list_entry(tmp, struct whiteheat_urb_wrap, list);
|
|
|
|
urb = wrap->urb;
|
|
|
|
kfree(wrap);
|
|
|
|
kfree(urb->transfer_buffer);
|
|
|
|
usb_free_urb(urb);
|
|
|
|
}
|
|
|
|
list_for_each_safe(tmp, tmp2, &info->tx_urbs_free) {
|
|
|
|
list_del(tmp);
|
|
|
|
wrap = list_entry(tmp, struct whiteheat_urb_wrap, list);
|
|
|
|
urb = wrap->urb;
|
|
|
|
kfree(wrap);
|
|
|
|
kfree(urb->transfer_buffer);
|
|
|
|
usb_free_urb(urb);
|
|
|
|
}
|
|
|
|
kfree(info);
|
|
|
|
}
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2008-07-22 12:09:16 +02:00
|
|
|
static int whiteheat_open(struct tty_struct *tty,
|
2008-07-22 12:09:07 +02:00
|
|
|
struct usb_serial_port *port, struct file *filp)
|
2005-04-17 00:20:36 +02:00
|
|
|
{
|
|
|
|
int retval = 0;
|
|
|
|
|
2008-03-04 01:08:34 +01:00
|
|
|
dbg("%s - port %d", __func__, port->number);
|
2005-04-17 00:20:36 +02:00
|
|
|
|
|
|
|
retval = start_command_port(port->serial);
|
|
|
|
if (retval)
|
|
|
|
goto exit;
|
|
|
|
|
2008-07-22 12:09:07 +02:00
|
|
|
if (tty)
|
|
|
|
tty->low_latency = 1;
|
2005-04-17 00:20:36 +02:00
|
|
|
|
|
|
|
/* send an open port command */
|
|
|
|
retval = firm_open(port);
|
|
|
|
if (retval) {
|
|
|
|
stop_command_port(port->serial);
|
|
|
|
goto exit;
|
|
|
|
}
|
|
|
|
|
|
|
|
retval = firm_purge(port, WHITEHEAT_PURGE_RX | WHITEHEAT_PURGE_TX);
|
|
|
|
if (retval) {
|
|
|
|
firm_close(port);
|
|
|
|
stop_command_port(port->serial);
|
|
|
|
goto exit;
|
|
|
|
}
|
|
|
|
|
2008-07-22 12:09:29 +02:00
|
|
|
if (tty)
|
|
|
|
firm_setup_port(tty);
|
2005-04-17 00:20:36 +02:00
|
|
|
|
|
|
|
/* Work around HCD bugs */
|
|
|
|
usb_clear_halt(port->serial->dev, port->read_urb->pipe);
|
|
|
|
usb_clear_halt(port->serial->dev, port->write_urb->pipe);
|
|
|
|
|
|
|
|
/* Start reading from the device */
|
|
|
|
retval = start_port_read(port);
|
|
|
|
if (retval) {
|
2008-08-21 01:56:34 +02:00
|
|
|
dev_err(&port->dev,
|
|
|
|
"%s - failed submitting read urb, error %d\n",
|
|
|
|
__func__, retval);
|
2005-04-17 00:20:36 +02:00
|
|
|
firm_close(port);
|
|
|
|
stop_command_port(port->serial);
|
|
|
|
goto exit;
|
|
|
|
}
|
|
|
|
|
|
|
|
exit:
|
2008-03-04 01:08:34 +01:00
|
|
|
dbg("%s - exit, retval = %d", __func__, retval);
|
2005-04-17 00:20:36 +02:00
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-07-22 12:09:07 +02:00
|
|
|
static void whiteheat_close(struct tty_struct *tty,
|
2008-07-22 12:09:16 +02:00
|
|
|
struct usb_serial_port *port, struct file *filp)
|
2005-04-17 00:20:36 +02:00
|
|
|
{
|
|
|
|
struct whiteheat_private *info = usb_get_serial_port_data(port);
|
|
|
|
struct whiteheat_urb_wrap *wrap;
|
|
|
|
struct urb *urb;
|
|
|
|
struct list_head *tmp;
|
|
|
|
struct list_head *tmp2;
|
|
|
|
|
2008-03-04 01:08:34 +01:00
|
|
|
dbg("%s - port %d", __func__, port->number);
|
2008-01-21 17:44:10 +01:00
|
|
|
|
|
|
|
mutex_lock(&port->serial->disc_mutex);
|
2005-04-17 00:20:36 +02:00
|
|
|
/* filp is NULL when called from usb_serial_disconnect */
|
2008-01-21 17:44:10 +01:00
|
|
|
if ((filp && (tty_hung_up_p(filp))) || port->serial->disconnected) {
|
|
|
|
mutex_unlock(&port->serial->disc_mutex);
|
2005-04-17 00:20:36 +02:00
|
|
|
return;
|
|
|
|
}
|
2008-01-21 17:44:10 +01:00
|
|
|
mutex_unlock(&port->serial->disc_mutex);
|
2005-04-17 00:20:36 +02:00
|
|
|
|
2008-07-22 12:09:07 +02:00
|
|
|
tty->closing = 1;
|
2005-04-17 00:20:36 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Not currently in use; tty_wait_until_sent() calls
|
|
|
|
* serial_chars_in_buffer() which deadlocks on the second semaphore
|
|
|
|
* acquisition. This should be fixed at some point. Greg's been
|
|
|
|
* notified.
|
|
|
|
if ((filp->f_flags & (O_NDELAY | O_NONBLOCK)) == 0) {
|
2008-07-22 12:09:07 +02:00
|
|
|
tty_wait_until_sent(tty, CLOSING_DELAY);
|
2005-04-17 00:20:36 +02:00
|
|
|
}
|
|
|
|
*/
|
|
|
|
|
2008-07-22 12:09:07 +02:00
|
|
|
tty_driver_flush_buffer(tty);
|
|
|
|
tty_ldisc_flush(tty);
|
2005-04-17 00:20:36 +02:00
|
|
|
|
|
|
|
firm_report_tx_done(port);
|
|
|
|
|
|
|
|
firm_close(port);
|
|
|
|
|
|
|
|
/* shutdown our bulk reads and writes */
|
2007-05-24 13:52:51 +02:00
|
|
|
mutex_lock(&info->deathwarrant);
|
|
|
|
spin_lock_irq(&info->lock);
|
2005-04-17 00:20:36 +02:00
|
|
|
list_for_each_safe(tmp, tmp2, &info->rx_urbs_submitted) {
|
|
|
|
wrap = list_entry(tmp, struct whiteheat_urb_wrap, list);
|
|
|
|
urb = wrap->urb;
|
2007-05-24 13:52:51 +02:00
|
|
|
list_del(tmp);
|
|
|
|
spin_unlock_irq(&info->lock);
|
2005-04-17 00:20:36 +02:00
|
|
|
usb_kill_urb(urb);
|
2007-05-24 13:52:51 +02:00
|
|
|
spin_lock_irq(&info->lock);
|
|
|
|
list_add(tmp, &info->rx_urbs_free);
|
2005-04-17 00:20:36 +02:00
|
|
|
}
|
2006-06-26 09:24:41 +02:00
|
|
|
list_for_each_safe(tmp, tmp2, &info->rx_urb_q)
|
|
|
|
list_move(tmp, &info->rx_urbs_free);
|
2005-04-17 00:20:36 +02:00
|
|
|
list_for_each_safe(tmp, tmp2, &info->tx_urbs_submitted) {
|
|
|
|
wrap = list_entry(tmp, struct whiteheat_urb_wrap, list);
|
|
|
|
urb = wrap->urb;
|
2007-05-24 13:52:51 +02:00
|
|
|
list_del(tmp);
|
|
|
|
spin_unlock_irq(&info->lock);
|
2005-04-17 00:20:36 +02:00
|
|
|
usb_kill_urb(urb);
|
2007-05-24 13:52:51 +02:00
|
|
|
spin_lock_irq(&info->lock);
|
|
|
|
list_add(tmp, &info->tx_urbs_free);
|
2005-04-17 00:20:36 +02:00
|
|
|
}
|
2007-05-24 13:52:51 +02:00
|
|
|
spin_unlock_irq(&info->lock);
|
|
|
|
mutex_unlock(&info->deathwarrant);
|
2005-04-17 00:20:36 +02:00
|
|
|
|
|
|
|
stop_command_port(port->serial);
|
|
|
|
|
2008-07-22 12:09:07 +02:00
|
|
|
tty->closing = 0;
|
2005-04-17 00:20:36 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-07-22 12:09:07 +02:00
|
|
|
static int whiteheat_write(struct tty_struct *tty,
|
|
|
|
struct usb_serial_port *port, const unsigned char *buf, int count)
|
2005-04-17 00:20:36 +02:00
|
|
|
{
|
|
|
|
struct usb_serial *serial = port->serial;
|
|
|
|
struct whiteheat_private *info = usb_get_serial_port_data(port);
|
|
|
|
struct whiteheat_urb_wrap *wrap;
|
|
|
|
struct urb *urb;
|
|
|
|
int result;
|
|
|
|
int bytes;
|
|
|
|
int sent = 0;
|
|
|
|
unsigned long flags;
|
|
|
|
struct list_head *tmp;
|
|
|
|
|
2008-03-04 01:08:34 +01:00
|
|
|
dbg("%s - port %d", __func__, port->number);
|
2005-04-17 00:20:36 +02:00
|
|
|
|
|
|
|
if (count == 0) {
|
2008-03-04 01:08:34 +01:00
|
|
|
dbg("%s - write request of 0 bytes", __func__);
|
2005-04-17 00:20:36 +02:00
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
while (count) {
|
|
|
|
spin_lock_irqsave(&info->lock, flags);
|
|
|
|
if (list_empty(&info->tx_urbs_free)) {
|
|
|
|
spin_unlock_irqrestore(&info->lock, flags);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
tmp = list_first(&info->tx_urbs_free);
|
|
|
|
list_del(tmp);
|
|
|
|
spin_unlock_irqrestore(&info->lock, flags);
|
|
|
|
|
|
|
|
wrap = list_entry(tmp, struct whiteheat_urb_wrap, list);
|
|
|
|
urb = wrap->urb;
|
2008-07-22 12:09:16 +02:00
|
|
|
bytes = (count > port->bulk_out_size) ?
|
|
|
|
port->bulk_out_size : count;
|
|
|
|
memcpy(urb->transfer_buffer, buf + sent, bytes);
|
2005-04-17 00:20:36 +02:00
|
|
|
|
2008-07-22 12:09:16 +02:00
|
|
|
usb_serial_debug_data(debug, &port->dev,
|
|
|
|
__func__, bytes, urb->transfer_buffer);
|
2005-04-17 00:20:36 +02:00
|
|
|
|
|
|
|
urb->dev = serial->dev;
|
|
|
|
urb->transfer_buffer_length = bytes;
|
|
|
|
result = usb_submit_urb(urb, GFP_ATOMIC);
|
|
|
|
if (result) {
|
2008-08-21 01:56:34 +02:00
|
|
|
dev_err(&port->dev,
|
|
|
|
"%s - failed submitting write urb, error %d\n",
|
|
|
|
__func__, result);
|
2005-04-17 00:20:36 +02:00
|
|
|
sent = result;
|
|
|
|
spin_lock_irqsave(&info->lock, flags);
|
|
|
|
list_add(tmp, &info->tx_urbs_free);
|
|
|
|
spin_unlock_irqrestore(&info->lock, flags);
|
|
|
|
break;
|
|
|
|
} else {
|
|
|
|
sent += bytes;
|
|
|
|
count -= bytes;
|
|
|
|
spin_lock_irqsave(&info->lock, flags);
|
|
|
|
list_add(tmp, &info->tx_urbs_submitted);
|
|
|
|
spin_unlock_irqrestore(&info->lock, flags);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return sent;
|
|
|
|
}
|
|
|
|
|
2008-07-22 12:09:07 +02:00
|
|
|
static int whiteheat_write_room(struct tty_struct *tty)
|
2005-04-17 00:20:36 +02:00
|
|
|
{
|
2008-07-22 12:09:07 +02:00
|
|
|
struct usb_serial_port *port = tty->driver_data;
|
2005-04-17 00:20:36 +02:00
|
|
|
struct whiteheat_private *info = usb_get_serial_port_data(port);
|
|
|
|
struct list_head *tmp;
|
|
|
|
int room = 0;
|
|
|
|
unsigned long flags;
|
|
|
|
|
2008-03-04 01:08:34 +01:00
|
|
|
dbg("%s - port %d", __func__, port->number);
|
2008-07-22 12:09:16 +02:00
|
|
|
|
2005-04-17 00:20:36 +02:00
|
|
|
spin_lock_irqsave(&info->lock, flags);
|
|
|
|
list_for_each(tmp, &info->tx_urbs_free)
|
|
|
|
room++;
|
|
|
|
spin_unlock_irqrestore(&info->lock, flags);
|
|
|
|
room *= port->bulk_out_size;
|
|
|
|
|
2008-03-04 01:08:34 +01:00
|
|
|
dbg("%s - returns %d", __func__, room);
|
2005-04-17 00:20:36 +02:00
|
|
|
return (room);
|
|
|
|
}
|
|
|
|
|
2008-07-22 12:09:16 +02:00
|
|
|
static int whiteheat_tiocmget(struct tty_struct *tty, struct file *file)
|
2005-04-17 00:20:36 +02:00
|
|
|
{
|
2008-07-22 12:09:07 +02:00
|
|
|
struct usb_serial_port *port = tty->driver_data;
|
2005-04-17 00:20:36 +02:00
|
|
|
struct whiteheat_private *info = usb_get_serial_port_data(port);
|
|
|
|
unsigned int modem_signals = 0;
|
|
|
|
|
2008-03-04 01:08:34 +01:00
|
|
|
dbg("%s - port %d", __func__, port->number);
|
2005-04-17 00:20:36 +02:00
|
|
|
|
|
|
|
firm_get_dtr_rts(port);
|
|
|
|
if (info->mcr & UART_MCR_DTR)
|
|
|
|
modem_signals |= TIOCM_DTR;
|
|
|
|
if (info->mcr & UART_MCR_RTS)
|
|
|
|
modem_signals |= TIOCM_RTS;
|
|
|
|
|
|
|
|
return modem_signals;
|
|
|
|
}
|
|
|
|
|
2008-07-22 12:09:16 +02:00
|
|
|
static int whiteheat_tiocmset(struct tty_struct *tty, struct file *file,
|
2005-04-17 00:20:36 +02:00
|
|
|
unsigned int set, unsigned int clear)
|
|
|
|
{
|
2008-07-22 12:09:07 +02:00
|
|
|
struct usb_serial_port *port = tty->driver_data;
|
2005-04-17 00:20:36 +02:00
|
|
|
struct whiteheat_private *info = usb_get_serial_port_data(port);
|
|
|
|
|
2008-03-04 01:08:34 +01:00
|
|
|
dbg("%s - port %d", __func__, port->number);
|
2005-04-17 00:20:36 +02:00
|
|
|
|
|
|
|
if (set & TIOCM_RTS)
|
|
|
|
info->mcr |= UART_MCR_RTS;
|
|
|
|
if (set & TIOCM_DTR)
|
|
|
|
info->mcr |= UART_MCR_DTR;
|
|
|
|
|
|
|
|
if (clear & TIOCM_RTS)
|
|
|
|
info->mcr &= ~UART_MCR_RTS;
|
|
|
|
if (clear & TIOCM_DTR)
|
|
|
|
info->mcr &= ~UART_MCR_DTR;
|
|
|
|
|
|
|
|
firm_set_dtr(port, info->mcr & UART_MCR_DTR);
|
|
|
|
firm_set_rts(port, info->mcr & UART_MCR_RTS);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-07-22 12:09:16 +02:00
|
|
|
static int whiteheat_ioctl(struct tty_struct *tty, struct file *file,
|
|
|
|
unsigned int cmd, unsigned long arg)
|
2005-04-17 00:20:36 +02:00
|
|
|
{
|
2008-07-22 12:09:07 +02:00
|
|
|
struct usb_serial_port *port = tty->driver_data;
|
2005-04-17 00:20:36 +02:00
|
|
|
struct serial_struct serstruct;
|
|
|
|
void __user *user_arg = (void __user *)arg;
|
|
|
|
|
2008-03-04 01:08:34 +01:00
|
|
|
dbg("%s - port %d, cmd 0x%.4x", __func__, port->number, cmd);
|
2005-04-17 00:20:36 +02:00
|
|
|
|
|
|
|
switch (cmd) {
|
2008-07-22 12:09:16 +02:00
|
|
|
case TIOCGSERIAL:
|
|
|
|
memset(&serstruct, 0, sizeof(serstruct));
|
|
|
|
serstruct.type = PORT_16654;
|
|
|
|
serstruct.line = port->serial->minor;
|
|
|
|
serstruct.port = port->number;
|
|
|
|
serstruct.flags = ASYNC_SKIP_TEST | ASYNC_AUTO_IRQ;
|
|
|
|
serstruct.xmit_fifo_size = port->bulk_out_size;
|
|
|
|
serstruct.custom_divisor = 0;
|
|
|
|
serstruct.baud_base = 460800;
|
|
|
|
serstruct.close_delay = CLOSING_DELAY;
|
|
|
|
serstruct.closing_wait = CLOSING_DELAY;
|
|
|
|
|
|
|
|
if (copy_to_user(user_arg, &serstruct, sizeof(serstruct)))
|
|
|
|
return -EFAULT;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
2005-04-17 00:20:36 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return -ENOIOCTLCMD;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-07-22 12:09:16 +02:00
|
|
|
static void whiteheat_set_termios(struct tty_struct *tty,
|
|
|
|
struct usb_serial_port *port, struct ktermios *old_termios)
|
2005-04-17 00:20:36 +02:00
|
|
|
{
|
2008-07-22 12:09:07 +02:00
|
|
|
firm_setup_port(tty);
|
2005-04-17 00:20:36 +02:00
|
|
|
}
|
|
|
|
|
2008-07-22 12:09:16 +02:00
|
|
|
static void whiteheat_break_ctl(struct tty_struct *tty, int break_state)
|
|
|
|
{
|
2008-07-22 12:09:07 +02:00
|
|
|
struct usb_serial_port *port = tty->driver_data;
|
2005-04-17 00:20:36 +02:00
|
|
|
firm_set_break(port, break_state);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-07-22 12:09:07 +02:00
|
|
|
static int whiteheat_chars_in_buffer(struct tty_struct *tty)
|
2005-04-17 00:20:36 +02:00
|
|
|
{
|
2008-07-22 12:09:07 +02:00
|
|
|
struct usb_serial_port *port = tty->driver_data;
|
2005-04-17 00:20:36 +02:00
|
|
|
struct whiteheat_private *info = usb_get_serial_port_data(port);
|
|
|
|
struct list_head *tmp;
|
|
|
|
struct whiteheat_urb_wrap *wrap;
|
|
|
|
int chars = 0;
|
|
|
|
unsigned long flags;
|
|
|
|
|
2008-03-04 01:08:34 +01:00
|
|
|
dbg("%s - port %d", __func__, port->number);
|
2005-04-17 00:20:36 +02:00
|
|
|
|
|
|
|
spin_lock_irqsave(&info->lock, flags);
|
|
|
|
list_for_each(tmp, &info->tx_urbs_submitted) {
|
|
|
|
wrap = list_entry(tmp, struct whiteheat_urb_wrap, list);
|
|
|
|
chars += wrap->urb->transfer_buffer_length;
|
|
|
|
}
|
|
|
|
spin_unlock_irqrestore(&info->lock, flags);
|
|
|
|
|
2008-07-22 12:09:16 +02:00
|
|
|
dbg("%s - returns %d", __func__, chars);
|
2007-05-24 13:52:51 +02:00
|
|
|
return chars;
|
2005-04-17 00:20:36 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-07-22 12:09:16 +02:00
|
|
|
static void whiteheat_throttle(struct tty_struct *tty)
|
2005-04-17 00:20:36 +02:00
|
|
|
{
|
2008-07-22 12:09:07 +02:00
|
|
|
struct usb_serial_port *port = tty->driver_data;
|
2005-04-17 00:20:36 +02:00
|
|
|
struct whiteheat_private *info = usb_get_serial_port_data(port);
|
|
|
|
unsigned long flags;
|
|
|
|
|
2008-03-04 01:08:34 +01:00
|
|
|
dbg("%s - port %d", __func__, port->number);
|
2005-04-17 00:20:36 +02:00
|
|
|
|
|
|
|
spin_lock_irqsave(&info->lock, flags);
|
|
|
|
info->flags |= THROTTLED;
|
|
|
|
spin_unlock_irqrestore(&info->lock, flags);
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-07-22 12:09:16 +02:00
|
|
|
static void whiteheat_unthrottle(struct tty_struct *tty)
|
2005-04-17 00:20:36 +02:00
|
|
|
{
|
2008-07-22 12:09:07 +02:00
|
|
|
struct usb_serial_port *port = tty->driver_data;
|
2005-04-17 00:20:36 +02:00
|
|
|
struct whiteheat_private *info = usb_get_serial_port_data(port);
|
|
|
|
int actually_throttled;
|
|
|
|
unsigned long flags;
|
|
|
|
|
2008-03-04 01:08:34 +01:00
|
|
|
dbg("%s - port %d", __func__, port->number);
|
2005-04-17 00:20:36 +02:00
|
|
|
|
|
|
|
spin_lock_irqsave(&info->lock, flags);
|
|
|
|
actually_throttled = info->flags & ACTUALLY_THROTTLED;
|
|
|
|
info->flags &= ~(THROTTLED | ACTUALLY_THROTTLED);
|
|
|
|
spin_unlock_irqrestore(&info->lock, flags);
|
|
|
|
|
|
|
|
if (actually_throttled)
|
2006-11-22 15:57:56 +01:00
|
|
|
rx_data_softint(&info->rx_work);
|
2005-04-17 00:20:36 +02:00
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*****************************************************************************
|
|
|
|
* Connect Tech's White Heat callback routines
|
|
|
|
*****************************************************************************/
|
2007-05-24 13:52:51 +02:00
|
|
|
static void command_port_write_callback(struct urb *urb)
|
2005-04-17 00:20:36 +02:00
|
|
|
{
|
2007-06-16 00:44:13 +02:00
|
|
|
int status = urb->status;
|
|
|
|
|
2008-03-04 01:08:34 +01:00
|
|
|
dbg("%s", __func__);
|
2005-04-17 00:20:36 +02:00
|
|
|
|
2007-06-16 00:44:13 +02:00
|
|
|
if (status) {
|
|
|
|
dbg("nonzero urb status: %d", status);
|
2005-04-17 00:20:36 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-05-24 13:52:51 +02:00
|
|
|
static void command_port_read_callback(struct urb *urb)
|
2005-04-17 00:20:36 +02:00
|
|
|
{
|
2008-02-24 11:41:47 +01:00
|
|
|
struct usb_serial_port *command_port = urb->context;
|
2005-04-17 00:20:36 +02:00
|
|
|
struct whiteheat_command_private *command_info;
|
2007-06-16 00:44:13 +02:00
|
|
|
int status = urb->status;
|
2005-04-17 00:20:36 +02:00
|
|
|
unsigned char *data = urb->transfer_buffer;
|
|
|
|
int result;
|
|
|
|
|
2008-03-04 01:08:34 +01:00
|
|
|
dbg("%s", __func__);
|
2005-04-17 00:20:36 +02:00
|
|
|
|
2007-05-24 13:52:51 +02:00
|
|
|
command_info = usb_get_serial_port_data(command_port);
|
|
|
|
if (!command_info) {
|
2008-07-22 12:09:16 +02:00
|
|
|
dbg("%s - command_info is NULL, exiting.", __func__);
|
2007-05-24 13:52:51 +02:00
|
|
|
return;
|
|
|
|
}
|
2007-06-16 00:44:13 +02:00
|
|
|
if (status) {
|
2008-03-04 01:08:34 +01:00
|
|
|
dbg("%s - nonzero urb status: %d", __func__, status);
|
2007-06-16 00:44:13 +02:00
|
|
|
if (status != -ENOENT)
|
2007-05-24 13:52:51 +02:00
|
|
|
command_info->command_finished = WHITEHEAT_CMD_FAILURE;
|
|
|
|
wake_up(&command_info->wait_command);
|
2005-04-17 00:20:36 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2008-07-22 12:09:16 +02:00
|
|
|
usb_serial_debug_data(debug, &command_port->dev,
|
|
|
|
__func__, urb->actual_length, data);
|
2005-04-17 00:20:36 +02:00
|
|
|
|
|
|
|
if (data[0] == WHITEHEAT_CMD_COMPLETE) {
|
|
|
|
command_info->command_finished = WHITEHEAT_CMD_COMPLETE;
|
2007-05-24 13:52:51 +02:00
|
|
|
wake_up(&command_info->wait_command);
|
2005-04-17 00:20:36 +02:00
|
|
|
} else if (data[0] == WHITEHEAT_CMD_FAILURE) {
|
|
|
|
command_info->command_finished = WHITEHEAT_CMD_FAILURE;
|
2007-05-24 13:52:51 +02:00
|
|
|
wake_up(&command_info->wait_command);
|
2005-04-17 00:20:36 +02:00
|
|
|
} else if (data[0] == WHITEHEAT_EVENT) {
|
2008-07-22 12:09:16 +02:00
|
|
|
/* These are unsolicited reports from the firmware, hence no
|
|
|
|
waiting command to wakeup */
|
2008-03-04 01:08:34 +01:00
|
|
|
dbg("%s - event received", __func__);
|
2005-04-17 00:20:36 +02:00
|
|
|
} else if (data[0] == WHITEHEAT_GET_DTR_RTS) {
|
2008-07-22 12:09:16 +02:00
|
|
|
memcpy(command_info->result_buffer, &data[1],
|
|
|
|
urb->actual_length - 1);
|
2005-04-17 00:20:36 +02:00
|
|
|
command_info->command_finished = WHITEHEAT_CMD_COMPLETE;
|
2007-05-24 13:52:51 +02:00
|
|
|
wake_up(&command_info->wait_command);
|
2008-07-22 12:09:16 +02:00
|
|
|
} else
|
2008-03-04 01:08:34 +01:00
|
|
|
dbg("%s - bad reply from firmware", __func__);
|
2008-07-22 12:09:16 +02:00
|
|
|
|
2005-04-17 00:20:36 +02:00
|
|
|
/* Continue trying to always read */
|
|
|
|
command_port->read_urb->dev = command_port->serial->dev;
|
|
|
|
result = usb_submit_urb(command_port->read_urb, GFP_ATOMIC);
|
|
|
|
if (result)
|
2008-07-22 12:09:16 +02:00
|
|
|
dbg("%s - failed resubmitting read urb, error %d",
|
|
|
|
__func__, result);
|
2005-04-17 00:20:36 +02: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 15:55:46 +02:00
|
|
|
static void whiteheat_read_callback(struct urb *urb)
|
2005-04-17 00:20:36 +02:00
|
|
|
{
|
2008-02-24 11:41:47 +01:00
|
|
|
struct usb_serial_port *port = urb->context;
|
2005-04-17 00:20:36 +02:00
|
|
|
struct whiteheat_urb_wrap *wrap;
|
|
|
|
unsigned char *data = urb->transfer_buffer;
|
|
|
|
struct whiteheat_private *info = usb_get_serial_port_data(port);
|
2007-06-16 00:44:13 +02:00
|
|
|
int status = urb->status;
|
2005-04-17 00:20:36 +02:00
|
|
|
|
2008-03-04 01:08:34 +01:00
|
|
|
dbg("%s - port %d", __func__, port->number);
|
2005-04-17 00:20:36 +02:00
|
|
|
|
|
|
|
spin_lock(&info->lock);
|
|
|
|
wrap = urb_to_wrap(urb, &info->rx_urbs_submitted);
|
|
|
|
if (!wrap) {
|
|
|
|
spin_unlock(&info->lock);
|
2008-08-21 01:56:34 +02:00
|
|
|
dev_err(&port->dev, "%s - Not my urb!\n", __func__);
|
2005-04-17 00:20:36 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
list_del(&wrap->list);
|
|
|
|
spin_unlock(&info->lock);
|
|
|
|
|
2007-06-16 00:44:13 +02:00
|
|
|
if (status) {
|
|
|
|
dbg("%s - nonzero read bulk status received: %d",
|
2008-03-04 01:08:34 +01:00
|
|
|
__func__, status);
|
2005-04-17 00:20:36 +02:00
|
|
|
spin_lock(&info->lock);
|
|
|
|
list_add(&wrap->list, &info->rx_urbs_free);
|
|
|
|
spin_unlock(&info->lock);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2008-07-22 12:09:16 +02:00
|
|
|
usb_serial_debug_data(debug, &port->dev,
|
|
|
|
__func__, urb->actual_length, data);
|
2005-04-17 00:20:36 +02:00
|
|
|
|
|
|
|
spin_lock(&info->lock);
|
|
|
|
list_add_tail(&wrap->list, &info->rx_urb_q);
|
|
|
|
if (info->flags & THROTTLED) {
|
|
|
|
info->flags |= ACTUALLY_THROTTLED;
|
|
|
|
spin_unlock(&info->lock);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
spin_unlock(&info->lock);
|
|
|
|
|
|
|
|
schedule_work(&info->rx_work);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
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 15:55:46 +02:00
|
|
|
static void whiteheat_write_callback(struct urb *urb)
|
2005-04-17 00:20:36 +02:00
|
|
|
{
|
2008-02-24 11:41:47 +01:00
|
|
|
struct usb_serial_port *port = urb->context;
|
2005-04-17 00:20:36 +02:00
|
|
|
struct whiteheat_private *info = usb_get_serial_port_data(port);
|
|
|
|
struct whiteheat_urb_wrap *wrap;
|
2007-06-16 00:44:13 +02:00
|
|
|
int status = urb->status;
|
2005-04-17 00:20:36 +02:00
|
|
|
|
2008-03-04 01:08:34 +01:00
|
|
|
dbg("%s - port %d", __func__, port->number);
|
2005-04-17 00:20:36 +02:00
|
|
|
|
|
|
|
spin_lock(&info->lock);
|
|
|
|
wrap = urb_to_wrap(urb, &info->tx_urbs_submitted);
|
|
|
|
if (!wrap) {
|
|
|
|
spin_unlock(&info->lock);
|
2008-08-21 01:56:34 +02:00
|
|
|
dev_err(&port->dev, "%s - Not my urb!\n", __func__);
|
2005-04-17 00:20:36 +02:00
|
|
|
return;
|
|
|
|
}
|
2006-06-26 09:24:41 +02:00
|
|
|
list_move(&wrap->list, &info->tx_urbs_free);
|
2005-04-17 00:20:36 +02:00
|
|
|
spin_unlock(&info->lock);
|
|
|
|
|
2007-06-16 00:44:13 +02:00
|
|
|
if (status) {
|
|
|
|
dbg("%s - nonzero write bulk status received: %d",
|
2008-03-04 01:08:34 +01:00
|
|
|
__func__, status);
|
2005-04-17 00:20:36 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2006-05-23 06:58:49 +02:00
|
|
|
usb_serial_port_softint(port);
|
2005-04-17 00:20:36 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*****************************************************************************
|
|
|
|
* Connect Tech's White Heat firmware interface
|
|
|
|
*****************************************************************************/
|
2008-07-22 12:09:16 +02:00
|
|
|
static int firm_send_command(struct usb_serial_port *port, __u8 command,
|
|
|
|
__u8 *data, __u8 datasize)
|
2005-04-17 00:20:36 +02:00
|
|
|
{
|
|
|
|
struct usb_serial_port *command_port;
|
|
|
|
struct whiteheat_command_private *command_info;
|
|
|
|
struct whiteheat_private *info;
|
|
|
|
__u8 *transfer_buffer;
|
|
|
|
int retval = 0;
|
2007-05-24 13:52:51 +02:00
|
|
|
int t;
|
2005-04-17 00:20:36 +02:00
|
|
|
|
2008-03-04 01:08:34 +01:00
|
|
|
dbg("%s - command %d", __func__, command);
|
2005-04-17 00:20:36 +02:00
|
|
|
|
|
|
|
command_port = port->serial->port[COMMAND_PORT];
|
|
|
|
command_info = usb_get_serial_port_data(command_port);
|
2007-05-24 13:52:51 +02:00
|
|
|
mutex_lock(&command_info->mutex);
|
2007-03-27 08:00:28 +02:00
|
|
|
command_info->command_finished = false;
|
2008-07-22 12:09:16 +02:00
|
|
|
|
2005-04-17 00:20:36 +02:00
|
|
|
transfer_buffer = (__u8 *)command_port->write_urb->transfer_buffer;
|
|
|
|
transfer_buffer[0] = command;
|
2008-07-22 12:09:16 +02:00
|
|
|
memcpy(&transfer_buffer[1], data, datasize);
|
2005-04-17 00:20:36 +02:00
|
|
|
command_port->write_urb->transfer_buffer_length = datasize + 1;
|
|
|
|
command_port->write_urb->dev = port->serial->dev;
|
2008-07-22 12:09:16 +02:00
|
|
|
retval = usb_submit_urb(command_port->write_urb, GFP_NOIO);
|
2005-04-17 00:20:36 +02:00
|
|
|
if (retval) {
|
2008-03-04 01:08:34 +01:00
|
|
|
dbg("%s - submit urb failed", __func__);
|
2005-04-17 00:20:36 +02:00
|
|
|
goto exit;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* wait for the command to complete */
|
2007-05-24 13:52:51 +02:00
|
|
|
t = wait_event_timeout(command_info->wait_command,
|
2007-03-27 08:00:28 +02:00
|
|
|
(bool)command_info->command_finished, COMMAND_TIMEOUT);
|
2007-05-24 13:52:51 +02:00
|
|
|
if (!t)
|
|
|
|
usb_kill_urb(command_port->write_urb);
|
2005-04-17 00:20:36 +02:00
|
|
|
|
2007-03-27 08:00:28 +02:00
|
|
|
if (command_info->command_finished == false) {
|
2008-03-04 01:08:34 +01:00
|
|
|
dbg("%s - command timed out.", __func__);
|
2005-04-17 00:20:36 +02:00
|
|
|
retval = -ETIMEDOUT;
|
|
|
|
goto exit;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (command_info->command_finished == WHITEHEAT_CMD_FAILURE) {
|
2008-03-04 01:08:34 +01:00
|
|
|
dbg("%s - command failed.", __func__);
|
2005-04-17 00:20:36 +02:00
|
|
|
retval = -EIO;
|
|
|
|
goto exit;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (command_info->command_finished == WHITEHEAT_CMD_COMPLETE) {
|
2008-03-04 01:08:34 +01:00
|
|
|
dbg("%s - command completed.", __func__);
|
2005-04-17 00:20:36 +02:00
|
|
|
switch (command) {
|
2008-07-22 12:09:16 +02:00
|
|
|
case WHITEHEAT_GET_DTR_RTS:
|
|
|
|
info = usb_get_serial_port_data(port);
|
|
|
|
memcpy(&info->mcr, command_info->result_buffer,
|
|
|
|
sizeof(struct whiteheat_dr_info));
|
2005-04-17 00:20:36 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
exit:
|
2007-05-24 13:52:51 +02:00
|
|
|
mutex_unlock(&command_info->mutex);
|
2005-04-17 00:20:36 +02:00
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-07-22 12:09:16 +02:00
|
|
|
static int firm_open(struct usb_serial_port *port)
|
|
|
|
{
|
2005-04-17 00:20:36 +02:00
|
|
|
struct whiteheat_simple open_command;
|
|
|
|
|
|
|
|
open_command.port = port->number - port->serial->minor + 1;
|
2008-07-22 12:09:16 +02:00
|
|
|
return firm_send_command(port, WHITEHEAT_OPEN,
|
|
|
|
(__u8 *)&open_command, sizeof(open_command));
|
2005-04-17 00:20:36 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-07-22 12:09:16 +02:00
|
|
|
static int firm_close(struct usb_serial_port *port)
|
|
|
|
{
|
2005-04-17 00:20:36 +02:00
|
|
|
struct whiteheat_simple close_command;
|
|
|
|
|
|
|
|
close_command.port = port->number - port->serial->minor + 1;
|
2008-07-22 12:09:16 +02:00
|
|
|
return firm_send_command(port, WHITEHEAT_CLOSE,
|
|
|
|
(__u8 *)&close_command, sizeof(close_command));
|
2005-04-17 00:20:36 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-07-22 12:09:16 +02:00
|
|
|
static int firm_setup_port(struct tty_struct *tty)
|
|
|
|
{
|
2008-07-22 12:09:07 +02:00
|
|
|
struct usb_serial_port *port = tty->driver_data;
|
2005-04-17 00:20:36 +02:00
|
|
|
struct whiteheat_port_settings port_settings;
|
2008-07-22 12:09:07 +02:00
|
|
|
unsigned int cflag = tty->termios->c_cflag;
|
2005-04-17 00:20:36 +02:00
|
|
|
|
|
|
|
port_settings.port = port->number + 1;
|
|
|
|
|
|
|
|
/* get the byte size */
|
|
|
|
switch (cflag & CSIZE) {
|
2008-07-22 12:09:16 +02:00
|
|
|
case CS5: port_settings.bits = 5; break;
|
|
|
|
case CS6: port_settings.bits = 6; break;
|
|
|
|
case CS7: port_settings.bits = 7; break;
|
|
|
|
default:
|
|
|
|
case CS8: port_settings.bits = 8; break;
|
2005-04-17 00:20:36 +02:00
|
|
|
}
|
2008-03-04 01:08:34 +01:00
|
|
|
dbg("%s - data bits = %d", __func__, port_settings.bits);
|
2008-07-22 12:09:16 +02:00
|
|
|
|
2005-04-17 00:20:36 +02:00
|
|
|
/* determine the parity */
|
|
|
|
if (cflag & PARENB)
|
|
|
|
if (cflag & CMSPAR)
|
|
|
|
if (cflag & PARODD)
|
|
|
|
port_settings.parity = WHITEHEAT_PAR_MARK;
|
|
|
|
else
|
|
|
|
port_settings.parity = WHITEHEAT_PAR_SPACE;
|
|
|
|
else
|
|
|
|
if (cflag & PARODD)
|
|
|
|
port_settings.parity = WHITEHEAT_PAR_ODD;
|
|
|
|
else
|
|
|
|
port_settings.parity = WHITEHEAT_PAR_EVEN;
|
|
|
|
else
|
|
|
|
port_settings.parity = WHITEHEAT_PAR_NONE;
|
2008-03-04 01:08:34 +01:00
|
|
|
dbg("%s - parity = %c", __func__, port_settings.parity);
|
2005-04-17 00:20:36 +02:00
|
|
|
|
|
|
|
/* figure out the stop bits requested */
|
|
|
|
if (cflag & CSTOPB)
|
|
|
|
port_settings.stop = 2;
|
|
|
|
else
|
|
|
|
port_settings.stop = 1;
|
2008-03-04 01:08:34 +01:00
|
|
|
dbg("%s - stop bits = %d", __func__, port_settings.stop);
|
2005-04-17 00:20:36 +02:00
|
|
|
|
|
|
|
/* figure out the flow control settings */
|
|
|
|
if (cflag & CRTSCTS)
|
2008-07-22 12:09:16 +02:00
|
|
|
port_settings.hflow = (WHITEHEAT_HFLOW_CTS |
|
|
|
|
WHITEHEAT_HFLOW_RTS);
|
2005-04-17 00:20:36 +02:00
|
|
|
else
|
|
|
|
port_settings.hflow = WHITEHEAT_HFLOW_NONE;
|
2008-03-04 01:08:34 +01:00
|
|
|
dbg("%s - hardware flow control = %s %s %s %s", __func__,
|
2005-04-17 00:20:36 +02:00
|
|
|
(port_settings.hflow & WHITEHEAT_HFLOW_CTS) ? "CTS" : "",
|
|
|
|
(port_settings.hflow & WHITEHEAT_HFLOW_RTS) ? "RTS" : "",
|
|
|
|
(port_settings.hflow & WHITEHEAT_HFLOW_DSR) ? "DSR" : "",
|
|
|
|
(port_settings.hflow & WHITEHEAT_HFLOW_DTR) ? "DTR" : "");
|
2008-07-22 12:09:16 +02:00
|
|
|
|
2005-04-17 00:20:36 +02:00
|
|
|
/* determine software flow control */
|
2008-07-22 12:09:07 +02:00
|
|
|
if (I_IXOFF(tty))
|
2005-04-17 00:20:36 +02:00
|
|
|
port_settings.sflow = WHITEHEAT_SFLOW_RXTX;
|
|
|
|
else
|
|
|
|
port_settings.sflow = WHITEHEAT_SFLOW_NONE;
|
2008-03-04 01:08:34 +01:00
|
|
|
dbg("%s - software flow control = %c", __func__, port_settings.sflow);
|
2008-07-22 12:09:16 +02:00
|
|
|
|
2008-07-22 12:09:07 +02:00
|
|
|
port_settings.xon = START_CHAR(tty);
|
|
|
|
port_settings.xoff = STOP_CHAR(tty);
|
2008-07-22 12:09:16 +02:00
|
|
|
dbg("%s - XON = %2x, XOFF = %2x",
|
|
|
|
__func__, port_settings.xon, port_settings.xoff);
|
2005-04-17 00:20:36 +02:00
|
|
|
|
|
|
|
/* get the baud rate wanted */
|
2008-07-22 12:09:07 +02:00
|
|
|
port_settings.baud = tty_get_baud_rate(tty);
|
2008-03-04 01:08:34 +01:00
|
|
|
dbg("%s - baud rate = %d", __func__, port_settings.baud);
|
2005-04-17 00:20:36 +02:00
|
|
|
|
2007-10-18 10:24:23 +02:00
|
|
|
/* fixme: should set validated settings */
|
2008-07-22 12:09:07 +02:00
|
|
|
tty_encode_baud_rate(tty, port_settings.baud, port_settings.baud);
|
2005-04-17 00:20:36 +02:00
|
|
|
/* handle any settings that aren't specified in the tty structure */
|
|
|
|
port_settings.lloop = 0;
|
2008-07-22 12:09:16 +02:00
|
|
|
|
2005-04-17 00:20:36 +02:00
|
|
|
/* now send the message to the device */
|
2008-07-22 12:09:16 +02:00
|
|
|
return firm_send_command(port, WHITEHEAT_SETUP_PORT,
|
|
|
|
(__u8 *)&port_settings, sizeof(port_settings));
|
2005-04-17 00:20:36 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-07-22 12:09:16 +02:00
|
|
|
static int firm_set_rts(struct usb_serial_port *port, __u8 onoff)
|
|
|
|
{
|
2005-04-17 00:20:36 +02:00
|
|
|
struct whiteheat_set_rdb rts_command;
|
|
|
|
|
|
|
|
rts_command.port = port->number - port->serial->minor + 1;
|
|
|
|
rts_command.state = onoff;
|
2008-07-22 12:09:16 +02:00
|
|
|
return firm_send_command(port, WHITEHEAT_SET_RTS,
|
|
|
|
(__u8 *)&rts_command, sizeof(rts_command));
|
2005-04-17 00:20:36 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-07-22 12:09:16 +02:00
|
|
|
static int firm_set_dtr(struct usb_serial_port *port, __u8 onoff)
|
|
|
|
{
|
2005-04-17 00:20:36 +02:00
|
|
|
struct whiteheat_set_rdb dtr_command;
|
|
|
|
|
|
|
|
dtr_command.port = port->number - port->serial->minor + 1;
|
|
|
|
dtr_command.state = onoff;
|
2008-07-22 12:09:29 +02:00
|
|
|
return firm_send_command(port, WHITEHEAT_SET_DTR,
|
2008-07-22 12:09:16 +02:00
|
|
|
(__u8 *)&dtr_command, sizeof(dtr_command));
|
2005-04-17 00:20:36 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-07-22 12:09:16 +02:00
|
|
|
static int firm_set_break(struct usb_serial_port *port, __u8 onoff)
|
|
|
|
{
|
2005-04-17 00:20:36 +02:00
|
|
|
struct whiteheat_set_rdb break_command;
|
|
|
|
|
|
|
|
break_command.port = port->number - port->serial->minor + 1;
|
|
|
|
break_command.state = onoff;
|
2008-07-22 12:09:29 +02:00
|
|
|
return firm_send_command(port, WHITEHEAT_SET_BREAK,
|
2008-07-22 12:09:16 +02:00
|
|
|
(__u8 *)&break_command, sizeof(break_command));
|
2005-04-17 00:20:36 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-07-22 12:09:16 +02:00
|
|
|
static int firm_purge(struct usb_serial_port *port, __u8 rxtx)
|
|
|
|
{
|
2005-04-17 00:20:36 +02:00
|
|
|
struct whiteheat_purge purge_command;
|
|
|
|
|
|
|
|
purge_command.port = port->number - port->serial->minor + 1;
|
|
|
|
purge_command.what = rxtx;
|
2008-07-22 12:09:16 +02:00
|
|
|
return firm_send_command(port, WHITEHEAT_PURGE,
|
|
|
|
(__u8 *)&purge_command, sizeof(purge_command));
|
2005-04-17 00:20:36 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-07-22 12:09:16 +02:00
|
|
|
static int firm_get_dtr_rts(struct usb_serial_port *port)
|
|
|
|
{
|
2005-04-17 00:20:36 +02:00
|
|
|
struct whiteheat_simple get_dr_command;
|
|
|
|
|
|
|
|
get_dr_command.port = port->number - port->serial->minor + 1;
|
2008-07-22 12:09:16 +02:00
|
|
|
return firm_send_command(port, WHITEHEAT_GET_DTR_RTS,
|
|
|
|
(__u8 *)&get_dr_command, sizeof(get_dr_command));
|
2005-04-17 00:20:36 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-07-22 12:09:16 +02:00
|
|
|
static int firm_report_tx_done(struct usb_serial_port *port)
|
|
|
|
{
|
2005-04-17 00:20:36 +02:00
|
|
|
struct whiteheat_simple close_command;
|
|
|
|
|
|
|
|
close_command.port = port->number - port->serial->minor + 1;
|
2008-07-22 12:09:16 +02:00
|
|
|
return firm_send_command(port, WHITEHEAT_REPORT_TX_DONE,
|
|
|
|
(__u8 *)&close_command, sizeof(close_command));
|
2005-04-17 00:20:36 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*****************************************************************************
|
|
|
|
* Connect Tech's White Heat utility functions
|
|
|
|
*****************************************************************************/
|
|
|
|
static int start_command_port(struct usb_serial *serial)
|
|
|
|
{
|
|
|
|
struct usb_serial_port *command_port;
|
|
|
|
struct whiteheat_command_private *command_info;
|
|
|
|
int retval = 0;
|
2008-07-22 12:09:16 +02:00
|
|
|
|
2005-04-17 00:20:36 +02:00
|
|
|
command_port = serial->port[COMMAND_PORT];
|
|
|
|
command_info = usb_get_serial_port_data(command_port);
|
2007-05-24 13:52:51 +02:00
|
|
|
mutex_lock(&command_info->mutex);
|
2005-04-17 00:20:36 +02:00
|
|
|
if (!command_info->port_running) {
|
|
|
|
/* Work around HCD bugs */
|
|
|
|
usb_clear_halt(serial->dev, command_port->read_urb->pipe);
|
|
|
|
|
|
|
|
command_port->read_urb->dev = serial->dev;
|
|
|
|
retval = usb_submit_urb(command_port->read_urb, GFP_KERNEL);
|
|
|
|
if (retval) {
|
2008-08-21 01:56:34 +02:00
|
|
|
dev_err(&serial->dev->dev,
|
|
|
|
"%s - failed submitting read urb, error %d\n",
|
|
|
|
__func__, retval);
|
2005-04-17 00:20:36 +02:00
|
|
|
goto exit;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
command_info->port_running++;
|
|
|
|
|
|
|
|
exit:
|
2007-05-24 13:52:51 +02:00
|
|
|
mutex_unlock(&command_info->mutex);
|
2005-04-17 00:20:36 +02:00
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void stop_command_port(struct usb_serial *serial)
|
|
|
|
{
|
|
|
|
struct usb_serial_port *command_port;
|
|
|
|
struct whiteheat_command_private *command_info;
|
|
|
|
|
|
|
|
command_port = serial->port[COMMAND_PORT];
|
|
|
|
command_info = usb_get_serial_port_data(command_port);
|
2007-05-24 13:52:51 +02:00
|
|
|
mutex_lock(&command_info->mutex);
|
2005-04-17 00:20:36 +02:00
|
|
|
command_info->port_running--;
|
|
|
|
if (!command_info->port_running)
|
|
|
|
usb_kill_urb(command_port->read_urb);
|
2007-05-24 13:52:51 +02:00
|
|
|
mutex_unlock(&command_info->mutex);
|
2005-04-17 00:20:36 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static int start_port_read(struct usb_serial_port *port)
|
|
|
|
{
|
|
|
|
struct whiteheat_private *info = usb_get_serial_port_data(port);
|
|
|
|
struct whiteheat_urb_wrap *wrap;
|
|
|
|
struct urb *urb;
|
|
|
|
int retval = 0;
|
|
|
|
unsigned long flags;
|
|
|
|
struct list_head *tmp;
|
|
|
|
struct list_head *tmp2;
|
|
|
|
|
|
|
|
spin_lock_irqsave(&info->lock, flags);
|
|
|
|
|
|
|
|
list_for_each_safe(tmp, tmp2, &info->rx_urbs_free) {
|
|
|
|
list_del(tmp);
|
|
|
|
wrap = list_entry(tmp, struct whiteheat_urb_wrap, list);
|
|
|
|
urb = wrap->urb;
|
|
|
|
urb->dev = port->serial->dev;
|
2007-05-24 13:52:51 +02:00
|
|
|
spin_unlock_irqrestore(&info->lock, flags);
|
2005-04-17 00:20:36 +02:00
|
|
|
retval = usb_submit_urb(urb, GFP_KERNEL);
|
|
|
|
if (retval) {
|
2007-05-24 13:52:51 +02:00
|
|
|
spin_lock_irqsave(&info->lock, flags);
|
2005-04-17 00:20:36 +02:00
|
|
|
list_add(tmp, &info->rx_urbs_free);
|
|
|
|
list_for_each_safe(tmp, tmp2, &info->rx_urbs_submitted) {
|
|
|
|
wrap = list_entry(tmp, struct whiteheat_urb_wrap, list);
|
|
|
|
urb = wrap->urb;
|
2007-05-24 13:52:51 +02:00
|
|
|
list_del(tmp);
|
|
|
|
spin_unlock_irqrestore(&info->lock, flags);
|
2005-04-17 00:20:36 +02:00
|
|
|
usb_kill_urb(urb);
|
2007-05-24 13:52:51 +02:00
|
|
|
spin_lock_irqsave(&info->lock, flags);
|
|
|
|
list_add(tmp, &info->rx_urbs_free);
|
2005-04-17 00:20:36 +02:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2007-05-24 13:52:51 +02:00
|
|
|
spin_lock_irqsave(&info->lock, flags);
|
2005-04-17 00:20:36 +02:00
|
|
|
list_add(tmp, &info->rx_urbs_submitted);
|
|
|
|
}
|
|
|
|
|
|
|
|
spin_unlock_irqrestore(&info->lock, flags);
|
|
|
|
|
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-07-22 12:09:16 +02:00
|
|
|
static struct whiteheat_urb_wrap *urb_to_wrap(struct urb *urb,
|
|
|
|
struct list_head *head)
|
2005-04-17 00:20:36 +02:00
|
|
|
{
|
|
|
|
struct whiteheat_urb_wrap *wrap;
|
|
|
|
struct list_head *tmp;
|
|
|
|
|
|
|
|
list_for_each(tmp, head) {
|
|
|
|
wrap = list_entry(tmp, struct whiteheat_urb_wrap, list);
|
|
|
|
if (wrap->urb == urb)
|
|
|
|
return wrap;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static struct list_head *list_first(struct list_head *head)
|
|
|
|
{
|
|
|
|
return head->next;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-11-22 15:57:56 +01:00
|
|
|
static void rx_data_softint(struct work_struct *work)
|
2005-04-17 00:20:36 +02:00
|
|
|
{
|
2006-11-22 15:57:56 +01:00
|
|
|
struct whiteheat_private *info =
|
|
|
|
container_of(work, struct whiteheat_private, rx_work);
|
|
|
|
struct usb_serial_port *port = info->port;
|
2008-10-13 11:39:46 +02:00
|
|
|
struct tty_struct *tty = tty_port_tty_get(&port->port);
|
2005-04-17 00:20:36 +02:00
|
|
|
struct whiteheat_urb_wrap *wrap;
|
|
|
|
struct urb *urb;
|
|
|
|
unsigned long flags;
|
|
|
|
struct list_head *tmp;
|
|
|
|
struct list_head *tmp2;
|
|
|
|
int result;
|
|
|
|
int sent = 0;
|
|
|
|
|
|
|
|
spin_lock_irqsave(&info->lock, flags);
|
|
|
|
if (info->flags & THROTTLED) {
|
|
|
|
spin_unlock_irqrestore(&info->lock, flags);
|
2008-10-13 11:39:46 +02:00
|
|
|
goto out;
|
2005-04-17 00:20:36 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
list_for_each_safe(tmp, tmp2, &info->rx_urb_q) {
|
|
|
|
list_del(tmp);
|
|
|
|
spin_unlock_irqrestore(&info->lock, flags);
|
|
|
|
|
|
|
|
wrap = list_entry(tmp, struct whiteheat_urb_wrap, list);
|
|
|
|
urb = wrap->urb;
|
|
|
|
|
|
|
|
if (tty && urb->actual_length) {
|
2008-07-22 12:09:16 +02:00
|
|
|
int len = tty_buffer_request_room(tty,
|
|
|
|
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 05:54:13 +01:00
|
|
|
/* This stuff can go away now I suspect */
|
|
|
|
if (unlikely(len < urb->actual_length)) {
|
2005-04-17 00:20:36 +02:00
|
|
|
spin_lock_irqsave(&info->lock, flags);
|
|
|
|
list_add(tmp, &info->rx_urb_q);
|
|
|
|
spin_unlock_irqrestore(&info->lock, flags);
|
|
|
|
tty_flip_buffer_push(tty);
|
|
|
|
schedule_work(&info->rx_work);
|
2008-10-13 11:39:46 +02:00
|
|
|
goto out;
|
2005-04-17 00:20:36 +02:00
|
|
|
}
|
[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 05:54:13 +01:00
|
|
|
tty_insert_flip_string(tty, urb->transfer_buffer, len);
|
|
|
|
sent += len;
|
2005-04-17 00:20:36 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
urb->dev = port->serial->dev;
|
|
|
|
result = usb_submit_urb(urb, GFP_ATOMIC);
|
|
|
|
if (result) {
|
2008-08-21 01:56:34 +02:00
|
|
|
dev_err(&port->dev,
|
|
|
|
"%s - failed resubmitting read urb, error %d\n",
|
2008-07-22 12:09:16 +02:00
|
|
|
__func__, result);
|
2005-04-17 00:20:36 +02:00
|
|
|
spin_lock_irqsave(&info->lock, flags);
|
|
|
|
list_add(tmp, &info->rx_urbs_free);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
spin_lock_irqsave(&info->lock, flags);
|
|
|
|
list_add(tmp, &info->rx_urbs_submitted);
|
|
|
|
}
|
|
|
|
spin_unlock_irqrestore(&info->lock, flags);
|
|
|
|
|
|
|
|
if (sent)
|
|
|
|
tty_flip_buffer_push(tty);
|
2008-10-13 11:39:46 +02:00
|
|
|
out:
|
|
|
|
tty_kref_put(tty);
|
2005-04-17 00:20:36 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*****************************************************************************
|
|
|
|
* Connect Tech's White Heat module functions
|
|
|
|
*****************************************************************************/
|
2008-07-22 12:09:16 +02:00
|
|
|
static int __init whiteheat_init(void)
|
2005-04-17 00:20:36 +02:00
|
|
|
{
|
|
|
|
int retval;
|
|
|
|
retval = usb_serial_register(&whiteheat_fake_device);
|
|
|
|
if (retval)
|
|
|
|
goto failed_fake_register;
|
|
|
|
retval = usb_serial_register(&whiteheat_device);
|
|
|
|
if (retval)
|
|
|
|
goto failed_device_register;
|
|
|
|
retval = usb_register(&whiteheat_driver);
|
|
|
|
if (retval)
|
|
|
|
goto failed_usb_register;
|
2008-08-18 22:21:04 +02:00
|
|
|
printk(KERN_INFO KBUILD_MODNAME ": " DRIVER_VERSION ":"
|
|
|
|
DRIVER_DESC "\n");
|
2005-04-17 00:20:36 +02:00
|
|
|
return 0;
|
|
|
|
failed_usb_register:
|
|
|
|
usb_serial_deregister(&whiteheat_device);
|
|
|
|
failed_device_register:
|
|
|
|
usb_serial_deregister(&whiteheat_fake_device);
|
|
|
|
failed_fake_register:
|
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-07-22 12:09:16 +02:00
|
|
|
static void __exit whiteheat_exit(void)
|
2005-04-17 00:20:36 +02:00
|
|
|
{
|
2008-07-22 12:09:16 +02:00
|
|
|
usb_deregister(&whiteheat_driver);
|
|
|
|
usb_serial_deregister(&whiteheat_fake_device);
|
|
|
|
usb_serial_deregister(&whiteheat_device);
|
2005-04-17 00:20:36 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
module_init(whiteheat_init);
|
|
|
|
module_exit(whiteheat_exit);
|
|
|
|
|
2008-07-22 12:09:16 +02:00
|
|
|
MODULE_AUTHOR(DRIVER_AUTHOR);
|
|
|
|
MODULE_DESCRIPTION(DRIVER_DESC);
|
2005-04-17 00:20:36 +02:00
|
|
|
MODULE_LICENSE("GPL");
|
|
|
|
|
2008-05-31 00:35:29 +02:00
|
|
|
MODULE_FIRMWARE("whiteheat.fw");
|
|
|
|
MODULE_FIRMWARE("whiteheat_loader.fw");
|
|
|
|
|
2005-04-17 00:20:36 +02:00
|
|
|
module_param(urb_pool_size, int, 0);
|
|
|
|
MODULE_PARM_DESC(urb_pool_size, "Number of urbs to use for buffering");
|
|
|
|
|
|
|
|
module_param(debug, bool, S_IRUGO | S_IWUSR);
|
|
|
|
MODULE_PARM_DESC(debug, "Debug enabled or not");
|