2005-04-17 06:20:36 +08:00
|
|
|
|
/* $Id: cosa.c,v 1.31 2000/03/08 17:47:16 kas Exp $ */
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Copyright (C) 1995-1997 Jan "Yenya" Kasprzak <kas@fi.muni.cz>
|
2008-07-02 05:40:29 +08:00
|
|
|
|
* Generic HDLC port Copyright (C) 2008 Krzysztof Halasa <khc@pm.waw.pl>
|
2005-04-17 06:20:36 +08:00
|
|
|
|
*
|
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
|
* (at your option) any later version.
|
|
|
|
|
*
|
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
|
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* The driver for the SRP and COSA synchronous serial cards.
|
|
|
|
|
*
|
|
|
|
|
* HARDWARE INFO
|
|
|
|
|
*
|
|
|
|
|
* Both cards are developed at the Institute of Computer Science,
|
|
|
|
|
* Masaryk University (http://www.ics.muni.cz/). The hardware is
|
|
|
|
|
* developed by Jiri Novotny <novotny@ics.muni.cz>. More information
|
|
|
|
|
* and the photo of both cards is available at
|
|
|
|
|
* http://www.pavoucek.cz/cosa.html. The card documentation, firmwares
|
|
|
|
|
* and other goods can be downloaded from ftp://ftp.ics.muni.cz/pub/cosa/.
|
|
|
|
|
* For Linux-specific utilities, see below in the "Software info" section.
|
|
|
|
|
* If you want to order the card, contact Jiri Novotny.
|
|
|
|
|
*
|
|
|
|
|
* The SRP (serial port?, the Czech word "srp" means "sickle") card
|
|
|
|
|
* is a 2-port intelligent (with its own 8-bit CPU) synchronous serial card
|
|
|
|
|
* with V.24 interfaces up to 80kb/s each.
|
|
|
|
|
*
|
|
|
|
|
* The COSA (communication serial adapter?, the Czech word "kosa" means
|
|
|
|
|
* "scythe") is a next-generation sync/async board with two interfaces
|
|
|
|
|
* - currently any of V.24, X.21, V.35 and V.36 can be selected.
|
|
|
|
|
* It has a 16-bit SAB80166 CPU and can do up to 10 Mb/s per channel.
|
|
|
|
|
* The 8-channels version is in development.
|
|
|
|
|
*
|
|
|
|
|
* Both types have downloadable firmware and communicate via ISA DMA.
|
|
|
|
|
* COSA can be also a bus-mastering device.
|
|
|
|
|
*
|
|
|
|
|
* SOFTWARE INFO
|
|
|
|
|
*
|
|
|
|
|
* The homepage of the Linux driver is at http://www.fi.muni.cz/~kas/cosa/.
|
|
|
|
|
* The CVS tree of Linux driver can be viewed there, as well as the
|
|
|
|
|
* firmware binaries and user-space utilities for downloading the firmware
|
|
|
|
|
* into the card and setting up the card.
|
|
|
|
|
*
|
|
|
|
|
* The Linux driver (unlike the present *BSD drivers :-) can work even
|
|
|
|
|
* for the COSA and SRP in one computer and allows each channel to work
|
2008-07-02 05:40:29 +08:00
|
|
|
|
* in one of the two modes (character or network device).
|
2005-04-17 06:20:36 +08:00
|
|
|
|
*
|
|
|
|
|
* AUTHOR
|
|
|
|
|
*
|
|
|
|
|
* The Linux driver was written by Jan "Yenya" Kasprzak <kas@fi.muni.cz>.
|
|
|
|
|
*
|
|
|
|
|
* You can mail me bugfixes and even success reports. I am especially
|
|
|
|
|
* interested in the SMP and/or muliti-channel success/failure reports
|
|
|
|
|
* (I wonder if I did the locking properly :-).
|
|
|
|
|
*
|
|
|
|
|
* THE AUTHOR USED THE FOLLOWING SOURCES WHEN PROGRAMMING THE DRIVER
|
|
|
|
|
*
|
|
|
|
|
* The COSA/SRP NetBSD driver by Zdenek Salvet and Ivos Cernohlavek
|
|
|
|
|
* The skeleton.c by Donald Becker
|
|
|
|
|
* The SDL Riscom/N2 driver by Mike Natale
|
|
|
|
|
* The Comtrol Hostess SV11 driver by Alan Cox
|
|
|
|
|
* The Sync PPP/Cisco HDLC layer (syncppp.c) ported to Linux by Alan Cox
|
|
|
|
|
*/
|
|
|
|
|
|
2011-06-27 03:01:29 +08:00
|
|
|
|
#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
|
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
|
#include <linux/module.h>
|
|
|
|
|
#include <linux/kernel.h>
|
2009-10-07 21:09:06 +08:00
|
|
|
|
#include <linux/sched.h>
|
2005-04-17 06:20:36 +08:00
|
|
|
|
#include <linux/slab.h>
|
|
|
|
|
#include <linux/poll.h>
|
|
|
|
|
#include <linux/fs.h>
|
|
|
|
|
#include <linux/interrupt.h>
|
|
|
|
|
#include <linux/delay.h>
|
2008-07-02 05:40:29 +08:00
|
|
|
|
#include <linux/hdlc.h>
|
2005-04-17 06:20:36 +08:00
|
|
|
|
#include <linux/errno.h>
|
|
|
|
|
#include <linux/ioport.h>
|
|
|
|
|
#include <linux/netdevice.h>
|
|
|
|
|
#include <linux/spinlock.h>
|
2008-03-06 10:53:01 +08:00
|
|
|
|
#include <linux/mutex.h>
|
2005-04-17 06:20:36 +08:00
|
|
|
|
#include <linux/device.h>
|
|
|
|
|
#include <asm/io.h>
|
|
|
|
|
#include <asm/dma.h>
|
|
|
|
|
#include <asm/byteorder.h>
|
|
|
|
|
|
2008-07-02 05:40:29 +08:00
|
|
|
|
#undef COSA_SLOW_IO /* for testing purposes only */
|
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
|
#include "cosa.h"
|
|
|
|
|
|
|
|
|
|
/* Maximum length of the identification string. */
|
|
|
|
|
#define COSA_MAX_ID_STRING 128
|
|
|
|
|
|
|
|
|
|
/* Maximum length of the channel name */
|
|
|
|
|
#define COSA_MAX_NAME (sizeof("cosaXXXcXXX")+1)
|
|
|
|
|
|
|
|
|
|
/* Per-channel data structure */
|
|
|
|
|
|
|
|
|
|
struct channel_data {
|
|
|
|
|
int usage; /* Usage count; >0 for chrdev, -1 for netdev */
|
|
|
|
|
int num; /* Number of the channel */
|
|
|
|
|
struct cosa_data *cosa; /* Pointer to the per-card structure */
|
|
|
|
|
int txsize; /* Size of transmitted data */
|
|
|
|
|
char *txbuf; /* Transmit buffer */
|
|
|
|
|
char name[COSA_MAX_NAME]; /* channel name */
|
|
|
|
|
|
|
|
|
|
/* The HW layer interface */
|
|
|
|
|
/* routine called from the RX interrupt */
|
|
|
|
|
char *(*setup_rx)(struct channel_data *channel, int size);
|
|
|
|
|
/* routine called when the RX is done (from the EOT interrupt) */
|
|
|
|
|
int (*rx_done)(struct channel_data *channel);
|
|
|
|
|
/* routine called when the TX is done (from the EOT interrupt) */
|
|
|
|
|
int (*tx_done)(struct channel_data *channel, int size);
|
|
|
|
|
|
|
|
|
|
/* Character device parts */
|
2008-03-06 10:53:01 +08:00
|
|
|
|
struct mutex rlock;
|
|
|
|
|
struct semaphore wsem;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
char *rxdata;
|
|
|
|
|
int rxsize;
|
|
|
|
|
wait_queue_head_t txwaitq, rxwaitq;
|
|
|
|
|
int tx_status, rx_status;
|
|
|
|
|
|
2008-07-02 05:40:29 +08:00
|
|
|
|
/* generic HDLC device parts */
|
|
|
|
|
struct net_device *netdev;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
struct sk_buff *rx_skb, *tx_skb;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/* cosa->firmware_status bits */
|
|
|
|
|
#define COSA_FW_RESET (1<<0) /* Is the ROM monitor active? */
|
|
|
|
|
#define COSA_FW_DOWNLOAD (1<<1) /* Is the microcode downloaded? */
|
|
|
|
|
#define COSA_FW_START (1<<2) /* Is the microcode running? */
|
|
|
|
|
|
|
|
|
|
struct cosa_data {
|
|
|
|
|
int num; /* Card number */
|
|
|
|
|
char name[COSA_MAX_NAME]; /* Card name - e.g "cosa0" */
|
|
|
|
|
unsigned int datareg, statusreg; /* I/O ports */
|
|
|
|
|
unsigned short irq, dma; /* IRQ and DMA number */
|
|
|
|
|
unsigned short startaddr; /* Firmware start address */
|
|
|
|
|
unsigned short busmaster; /* Use busmastering? */
|
|
|
|
|
int nchannels; /* # of channels on this card */
|
|
|
|
|
int driver_status; /* For communicating with firmware */
|
|
|
|
|
int firmware_status; /* Downloaded, reseted, etc. */
|
2007-10-15 02:35:20 +08:00
|
|
|
|
unsigned long rxbitmap, txbitmap;/* Bitmap of channels who are willing to send/receive data */
|
|
|
|
|
unsigned long rxtx; /* RX or TX in progress? */
|
2005-04-17 06:20:36 +08:00
|
|
|
|
int enabled;
|
|
|
|
|
int usage; /* usage count */
|
|
|
|
|
int txchan, txsize, rxsize;
|
|
|
|
|
struct channel_data *rxchan;
|
|
|
|
|
char *bouncebuf;
|
|
|
|
|
char *txbuf, *rxbuf;
|
|
|
|
|
struct channel_data *chan;
|
|
|
|
|
spinlock_t lock; /* For exclusive operations on this structure */
|
|
|
|
|
char id_string[COSA_MAX_ID_STRING]; /* ROM monitor ID string */
|
|
|
|
|
char *type; /* card type */
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Define this if you want all the possible ports to be autoprobed.
|
|
|
|
|
* It is here but it probably is not a good idea to use this.
|
|
|
|
|
*/
|
|
|
|
|
/* #define COSA_ISA_AUTOPROBE 1 */
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Character device major number. 117 was allocated for us.
|
|
|
|
|
* The value of 0 means to allocate a first free one.
|
|
|
|
|
*/
|
2010-07-11 19:18:57 +08:00
|
|
|
|
static DEFINE_MUTEX(cosa_chardev_mutex);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
static int cosa_major = 117;
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Encoding of the minor numbers:
|
|
|
|
|
* The lowest CARD_MINOR_BITS bits means the channel on the single card,
|
|
|
|
|
* the highest bits means the card number.
|
|
|
|
|
*/
|
|
|
|
|
#define CARD_MINOR_BITS 4 /* How many bits in minor number are reserved
|
|
|
|
|
* for the single card */
|
|
|
|
|
/*
|
|
|
|
|
* The following depends on CARD_MINOR_BITS. Unfortunately, the "MODULE_STRING"
|
|
|
|
|
* macro doesn't like anything other than the raw number as an argument :-(
|
|
|
|
|
*/
|
|
|
|
|
#define MAX_CARDS 16
|
|
|
|
|
/* #define MAX_CARDS (1 << (8-CARD_MINOR_BITS)) */
|
|
|
|
|
|
|
|
|
|
#define DRIVER_RX_READY 0x0001
|
|
|
|
|
#define DRIVER_TX_READY 0x0002
|
|
|
|
|
#define DRIVER_TXMAP_SHIFT 2
|
|
|
|
|
#define DRIVER_TXMAP_MASK 0x0c /* FIXME: 0xfc for 8-channel version */
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* for cosa->rxtx - indicates whether either transmit or receive is
|
|
|
|
|
* in progress. These values are mean number of the bit.
|
|
|
|
|
*/
|
|
|
|
|
#define TXBIT 0
|
|
|
|
|
#define RXBIT 1
|
|
|
|
|
#define IRQBIT 2
|
|
|
|
|
|
|
|
|
|
#define COSA_MTU 2000 /* FIXME: I don't know this exactly */
|
|
|
|
|
|
|
|
|
|
#undef DEBUG_DATA //1 /* Dump the data read or written to the channel */
|
|
|
|
|
#undef DEBUG_IRQS //1 /* Print the message when the IRQ is received */
|
|
|
|
|
#undef DEBUG_IO //1 /* Dump the I/O traffic */
|
|
|
|
|
|
|
|
|
|
#define TX_TIMEOUT (5*HZ)
|
|
|
|
|
|
|
|
|
|
/* Maybe the following should be allocated dynamically */
|
|
|
|
|
static struct cosa_data cosa_cards[MAX_CARDS];
|
|
|
|
|
static int nr_cards;
|
|
|
|
|
|
|
|
|
|
#ifdef COSA_ISA_AUTOPROBE
|
|
|
|
|
static int io[MAX_CARDS+1] = { 0x220, 0x228, 0x210, 0x218, 0, };
|
|
|
|
|
/* NOTE: DMA is not autoprobed!!! */
|
|
|
|
|
static int dma[MAX_CARDS+1] = { 1, 7, 1, 7, 1, 7, 1, 7, 0, };
|
|
|
|
|
#else
|
|
|
|
|
static int io[MAX_CARDS+1];
|
|
|
|
|
static int dma[MAX_CARDS+1];
|
|
|
|
|
#endif
|
|
|
|
|
/* IRQ can be safely autoprobed */
|
|
|
|
|
static int irq[MAX_CARDS+1] = { -1, -1, -1, -1, -1, -1, 0, };
|
|
|
|
|
|
|
|
|
|
/* for class stuff*/
|
2005-03-24 02:01:41 +08:00
|
|
|
|
static struct class *cosa_class;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
|
|
#ifdef MODULE
|
|
|
|
|
module_param_array(io, int, NULL, 0);
|
|
|
|
|
MODULE_PARM_DESC(io, "The I/O bases of the COSA or SRP cards");
|
|
|
|
|
module_param_array(irq, int, NULL, 0);
|
|
|
|
|
MODULE_PARM_DESC(irq, "The IRQ lines of the COSA or SRP cards");
|
|
|
|
|
module_param_array(dma, int, NULL, 0);
|
|
|
|
|
MODULE_PARM_DESC(dma, "The DMA channels of the COSA or SRP cards");
|
|
|
|
|
|
|
|
|
|
MODULE_AUTHOR("Jan \"Yenya\" Kasprzak, <kas@fi.muni.cz>");
|
|
|
|
|
MODULE_DESCRIPTION("Modular driver for the COSA or SRP synchronous card");
|
|
|
|
|
MODULE_LICENSE("GPL");
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
/* I use this mainly for testing purposes */
|
|
|
|
|
#ifdef COSA_SLOW_IO
|
|
|
|
|
#define cosa_outb outb_p
|
|
|
|
|
#define cosa_outw outw_p
|
|
|
|
|
#define cosa_inb inb_p
|
|
|
|
|
#define cosa_inw inw_p
|
|
|
|
|
#else
|
|
|
|
|
#define cosa_outb outb
|
|
|
|
|
#define cosa_outw outw
|
|
|
|
|
#define cosa_inb inb
|
|
|
|
|
#define cosa_inw inw
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
#define is_8bit(cosa) (!(cosa->datareg & 0x08))
|
|
|
|
|
|
|
|
|
|
#define cosa_getstatus(cosa) (cosa_inb(cosa->statusreg))
|
|
|
|
|
#define cosa_putstatus(cosa, stat) (cosa_outb(stat, cosa->statusreg))
|
|
|
|
|
#define cosa_getdata16(cosa) (cosa_inw(cosa->datareg))
|
|
|
|
|
#define cosa_getdata8(cosa) (cosa_inb(cosa->datareg))
|
|
|
|
|
#define cosa_putdata16(cosa, dt) (cosa_outw(dt, cosa->datareg))
|
|
|
|
|
#define cosa_putdata8(cosa, dt) (cosa_outb(dt, cosa->datareg))
|
|
|
|
|
|
|
|
|
|
/* Initialization stuff */
|
|
|
|
|
static int cosa_probe(int ioaddr, int irq, int dma);
|
|
|
|
|
|
|
|
|
|
/* HW interface */
|
|
|
|
|
static void cosa_enable_rx(struct channel_data *chan);
|
|
|
|
|
static void cosa_disable_rx(struct channel_data *chan);
|
|
|
|
|
static int cosa_start_tx(struct channel_data *channel, char *buf, int size);
|
|
|
|
|
static void cosa_kick(struct cosa_data *cosa);
|
|
|
|
|
static int cosa_dma_able(struct channel_data *chan, char *buf, int data);
|
|
|
|
|
|
2008-07-02 05:40:29 +08:00
|
|
|
|
/* Network device stuff */
|
|
|
|
|
static int cosa_net_attach(struct net_device *dev, unsigned short encoding,
|
|
|
|
|
unsigned short parity);
|
|
|
|
|
static int cosa_net_open(struct net_device *d);
|
|
|
|
|
static int cosa_net_close(struct net_device *d);
|
|
|
|
|
static void cosa_net_timeout(struct net_device *d);
|
2009-09-01 03:50:47 +08:00
|
|
|
|
static netdev_tx_t cosa_net_tx(struct sk_buff *skb, struct net_device *d);
|
2008-07-02 05:40:29 +08:00
|
|
|
|
static char *cosa_net_setup_rx(struct channel_data *channel, int size);
|
|
|
|
|
static int cosa_net_rx_done(struct channel_data *channel);
|
|
|
|
|
static int cosa_net_tx_done(struct channel_data *channel, int size);
|
|
|
|
|
static int cosa_net_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
|
|
/* Character device */
|
|
|
|
|
static char *chrdev_setup_rx(struct channel_data *channel, int size);
|
|
|
|
|
static int chrdev_rx_done(struct channel_data *channel);
|
|
|
|
|
static int chrdev_tx_done(struct channel_data *channel, int size);
|
|
|
|
|
static ssize_t cosa_read(struct file *file,
|
|
|
|
|
char __user *buf, size_t count, loff_t *ppos);
|
|
|
|
|
static ssize_t cosa_write(struct file *file,
|
|
|
|
|
const char __user *buf, size_t count, loff_t *ppos);
|
|
|
|
|
static unsigned int cosa_poll(struct file *file, poll_table *poll);
|
|
|
|
|
static int cosa_open(struct inode *inode, struct file *file);
|
|
|
|
|
static int cosa_release(struct inode *inode, struct file *file);
|
2009-10-14 13:22:24 +08:00
|
|
|
|
static long cosa_chardev_ioctl(struct file *file, unsigned int cmd,
|
|
|
|
|
unsigned long arg);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
#ifdef COSA_FASYNC_WORKING
|
|
|
|
|
static int cosa_fasync(struct inode *inode, struct file *file, int on);
|
|
|
|
|
#endif
|
|
|
|
|
|
2007-02-12 16:55:34 +08:00
|
|
|
|
static const struct file_operations cosa_fops = {
|
2005-04-17 06:20:36 +08:00
|
|
|
|
.owner = THIS_MODULE,
|
|
|
|
|
.llseek = no_llseek,
|
|
|
|
|
.read = cosa_read,
|
|
|
|
|
.write = cosa_write,
|
|
|
|
|
.poll = cosa_poll,
|
2009-10-14 13:22:24 +08:00
|
|
|
|
.unlocked_ioctl = cosa_chardev_ioctl,
|
2005-04-17 06:20:36 +08:00
|
|
|
|
.open = cosa_open,
|
|
|
|
|
.release = cosa_release,
|
|
|
|
|
#ifdef COSA_FASYNC_WORKING
|
|
|
|
|
.fasync = cosa_fasync,
|
|
|
|
|
#endif
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/* Ioctls */
|
|
|
|
|
static int cosa_start(struct cosa_data *cosa, int address);
|
|
|
|
|
static int cosa_reset(struct cosa_data *cosa);
|
|
|
|
|
static int cosa_download(struct cosa_data *cosa, void __user *a);
|
|
|
|
|
static int cosa_readmem(struct cosa_data *cosa, void __user *a);
|
|
|
|
|
|
|
|
|
|
/* COSA/SRP ROM monitor */
|
|
|
|
|
static int download(struct cosa_data *cosa, const char __user *data, int addr, int len);
|
|
|
|
|
static int startmicrocode(struct cosa_data *cosa, int address);
|
|
|
|
|
static int readmem(struct cosa_data *cosa, char __user *data, int addr, int len);
|
|
|
|
|
static int cosa_reset_and_read_id(struct cosa_data *cosa, char *id);
|
|
|
|
|
|
2011-03-31 09:57:33 +08:00
|
|
|
|
/* Auxiliary functions */
|
2005-04-17 06:20:36 +08:00
|
|
|
|
static int get_wait_data(struct cosa_data *cosa);
|
|
|
|
|
static int put_wait_data(struct cosa_data *cosa, int data);
|
|
|
|
|
static int puthexnumber(struct cosa_data *cosa, int number);
|
|
|
|
|
static void put_driver_status(struct cosa_data *cosa);
|
|
|
|
|
static void put_driver_status_nolock(struct cosa_data *cosa);
|
|
|
|
|
|
|
|
|
|
/* Interrupt handling */
|
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 irqreturn_t cosa_interrupt(int irq, void *cosa);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
|
|
/* I/O ops debugging */
|
|
|
|
|
#ifdef DEBUG_IO
|
|
|
|
|
static void debug_data_in(struct cosa_data *cosa, int data);
|
|
|
|
|
static void debug_data_out(struct cosa_data *cosa, int data);
|
|
|
|
|
static void debug_data_cmd(struct cosa_data *cosa, int data);
|
|
|
|
|
static void debug_status_in(struct cosa_data *cosa, int status);
|
|
|
|
|
static void debug_status_out(struct cosa_data *cosa, int status);
|
|
|
|
|
#endif
|
|
|
|
|
|
2008-07-02 05:40:29 +08:00
|
|
|
|
static inline struct channel_data* dev_to_chan(struct net_device *dev)
|
|
|
|
|
{
|
|
|
|
|
return (struct channel_data *)dev_to_hdlc(dev)->priv;
|
|
|
|
|
}
|
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
|
/* ---------- Initialization stuff ---------- */
|
|
|
|
|
|
|
|
|
|
static int __init cosa_init(void)
|
|
|
|
|
{
|
|
|
|
|
int i, err = 0;
|
|
|
|
|
|
|
|
|
|
if (cosa_major > 0) {
|
|
|
|
|
if (register_chrdev(cosa_major, "cosa", &cosa_fops)) {
|
2011-06-27 03:01:29 +08:00
|
|
|
|
pr_warn("unable to get major %d\n", cosa_major);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
err = -EIO;
|
|
|
|
|
goto out;
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
if (!(cosa_major=register_chrdev(0, "cosa", &cosa_fops))) {
|
2011-06-27 03:01:29 +08:00
|
|
|
|
pr_warn("unable to register chardev\n");
|
2005-04-17 06:20:36 +08:00
|
|
|
|
err = -EIO;
|
|
|
|
|
goto out;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
for (i=0; i<MAX_CARDS; i++)
|
|
|
|
|
cosa_cards[i].num = -1;
|
|
|
|
|
for (i=0; io[i] != 0 && i < MAX_CARDS; i++)
|
|
|
|
|
cosa_probe(io[i], irq[i], dma[i]);
|
|
|
|
|
if (!nr_cards) {
|
2011-06-27 03:01:29 +08:00
|
|
|
|
pr_warn("no devices found\n");
|
2005-04-17 06:20:36 +08:00
|
|
|
|
unregister_chrdev(cosa_major, "cosa");
|
|
|
|
|
err = -ENODEV;
|
|
|
|
|
goto out;
|
|
|
|
|
}
|
2005-03-24 02:01:41 +08:00
|
|
|
|
cosa_class = class_create(THIS_MODULE, "cosa");
|
2005-04-17 06:20:36 +08:00
|
|
|
|
if (IS_ERR(cosa_class)) {
|
|
|
|
|
err = PTR_ERR(cosa_class);
|
|
|
|
|
goto out_chrdev;
|
|
|
|
|
}
|
2008-05-22 03:52:33 +08:00
|
|
|
|
for (i = 0; i < nr_cards; i++)
|
2008-07-22 11:03:34 +08:00
|
|
|
|
device_create(cosa_class, NULL, MKDEV(cosa_major, i), NULL,
|
|
|
|
|
"cosa%d", i);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
err = 0;
|
|
|
|
|
goto out;
|
2008-07-02 05:40:29 +08:00
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
|
out_chrdev:
|
|
|
|
|
unregister_chrdev(cosa_major, "cosa");
|
|
|
|
|
out:
|
|
|
|
|
return err;
|
|
|
|
|
}
|
|
|
|
|
module_init(cosa_init);
|
|
|
|
|
|
|
|
|
|
static void __exit cosa_exit(void)
|
|
|
|
|
{
|
|
|
|
|
struct cosa_data *cosa;
|
|
|
|
|
int i;
|
|
|
|
|
|
2008-07-02 05:40:29 +08:00
|
|
|
|
for (i = 0; i < nr_cards; i++)
|
2007-09-25 08:03:03 +08:00
|
|
|
|
device_destroy(cosa_class, MKDEV(cosa_major, i));
|
2005-03-24 02:01:41 +08:00
|
|
|
|
class_destroy(cosa_class);
|
2008-07-02 05:40:29 +08:00
|
|
|
|
|
|
|
|
|
for (cosa = cosa_cards; nr_cards--; cosa++) {
|
2005-04-17 06:20:36 +08:00
|
|
|
|
/* Clean up the per-channel data */
|
2008-07-02 05:40:29 +08:00
|
|
|
|
for (i = 0; i < cosa->nchannels; i++) {
|
2005-04-17 06:20:36 +08:00
|
|
|
|
/* Chardev driver has no alloc'd per-channel data */
|
2008-07-02 05:40:29 +08:00
|
|
|
|
unregister_hdlc_device(cosa->chan[i].netdev);
|
|
|
|
|
free_netdev(cosa->chan[i].netdev);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
}
|
|
|
|
|
/* Clean up the per-card data */
|
|
|
|
|
kfree(cosa->chan);
|
|
|
|
|
kfree(cosa->bouncebuf);
|
|
|
|
|
free_irq(cosa->irq, cosa);
|
|
|
|
|
free_dma(cosa->dma);
|
2008-07-02 05:40:29 +08:00
|
|
|
|
release_region(cosa->datareg, is_8bit(cosa) ? 2 : 4);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
}
|
|
|
|
|
unregister_chrdev(cosa_major, "cosa");
|
|
|
|
|
}
|
|
|
|
|
module_exit(cosa_exit);
|
|
|
|
|
|
2009-01-09 05:52:11 +08:00
|
|
|
|
static const struct net_device_ops cosa_ops = {
|
|
|
|
|
.ndo_open = cosa_net_open,
|
|
|
|
|
.ndo_stop = cosa_net_close,
|
|
|
|
|
.ndo_change_mtu = hdlc_change_mtu,
|
|
|
|
|
.ndo_start_xmit = hdlc_start_xmit,
|
|
|
|
|
.ndo_do_ioctl = cosa_net_ioctl,
|
|
|
|
|
.ndo_tx_timeout = cosa_net_timeout,
|
|
|
|
|
};
|
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
|
static int cosa_probe(int base, int irq, int dma)
|
|
|
|
|
{
|
|
|
|
|
struct cosa_data *cosa = cosa_cards+nr_cards;
|
|
|
|
|
int i, err = 0;
|
|
|
|
|
|
|
|
|
|
memset(cosa, 0, sizeof(struct cosa_data));
|
|
|
|
|
|
|
|
|
|
/* Checking validity of parameters: */
|
|
|
|
|
/* IRQ should be 2-7 or 10-15; negative IRQ means autoprobe */
|
|
|
|
|
if ((irq >= 0 && irq < 2) || irq > 15 || (irq < 10 && irq > 7)) {
|
2011-06-27 03:01:29 +08:00
|
|
|
|
pr_info("invalid IRQ %d\n", irq);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
/* I/O address should be between 0x100 and 0x3ff and should be
|
|
|
|
|
* multiple of 8. */
|
|
|
|
|
if (base < 0x100 || base > 0x3ff || base & 0x7) {
|
2011-06-27 03:01:29 +08:00
|
|
|
|
pr_info("invalid I/O address 0x%x\n", base);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
/* DMA should be 0,1 or 3-7 */
|
|
|
|
|
if (dma < 0 || dma == 4 || dma > 7) {
|
2011-06-27 03:01:29 +08:00
|
|
|
|
pr_info("invalid DMA %d\n", dma);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
/* and finally, on 16-bit COSA DMA should be 4-7 and
|
|
|
|
|
* I/O base should not be multiple of 0x10 */
|
|
|
|
|
if (((base & 0x8) && dma < 4) || (!(base & 0x8) && dma > 3)) {
|
2011-06-27 03:01:29 +08:00
|
|
|
|
pr_info("8/16 bit base and DMA mismatch (base=0x%x, dma=%d)\n",
|
|
|
|
|
base, dma);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
cosa->dma = dma;
|
|
|
|
|
cosa->datareg = base;
|
|
|
|
|
cosa->statusreg = is_8bit(cosa)?base+1:base+2;
|
|
|
|
|
spin_lock_init(&cosa->lock);
|
|
|
|
|
|
|
|
|
|
if (!request_region(base, is_8bit(cosa)?2:4,"cosa"))
|
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
|
|
if (cosa_reset_and_read_id(cosa, cosa->id_string) < 0) {
|
2011-06-27 03:01:29 +08:00
|
|
|
|
printk(KERN_DEBUG "probe at 0x%x failed.\n", base);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
err = -1;
|
|
|
|
|
goto err_out;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Test the validity of identification string */
|
|
|
|
|
if (!strncmp(cosa->id_string, "SRP", 3))
|
|
|
|
|
cosa->type = "srp";
|
|
|
|
|
else if (!strncmp(cosa->id_string, "COSA", 4))
|
|
|
|
|
cosa->type = is_8bit(cosa)? "cosa8": "cosa16";
|
|
|
|
|
else {
|
|
|
|
|
/* Print a warning only if we are not autoprobing */
|
|
|
|
|
#ifndef COSA_ISA_AUTOPROBE
|
2011-06-27 03:01:29 +08:00
|
|
|
|
pr_info("valid signature not found at 0x%x\n", base);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
#endif
|
|
|
|
|
err = -1;
|
|
|
|
|
goto err_out;
|
|
|
|
|
}
|
|
|
|
|
/* Update the name of the region now we know the type of card */
|
|
|
|
|
release_region(base, is_8bit(cosa)?2:4);
|
|
|
|
|
if (!request_region(base, is_8bit(cosa)?2:4, cosa->type)) {
|
2011-06-27 03:01:29 +08:00
|
|
|
|
printk(KERN_DEBUG "changing name at 0x%x failed.\n", base);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Now do IRQ autoprobe */
|
|
|
|
|
if (irq < 0) {
|
|
|
|
|
unsigned long irqs;
|
2011-06-27 03:01:29 +08:00
|
|
|
|
/* pr_info("IRQ autoprobe\n"); */
|
2005-04-17 06:20:36 +08:00
|
|
|
|
irqs = probe_irq_on();
|
|
|
|
|
/*
|
|
|
|
|
* Enable interrupt on tx buffer empty (it sure is)
|
|
|
|
|
* really sure ?
|
|
|
|
|
* FIXME: When this code is not used as module, we should
|
|
|
|
|
* probably call udelay() instead of the interruptible sleep.
|
|
|
|
|
*/
|
|
|
|
|
set_current_state(TASK_INTERRUPTIBLE);
|
|
|
|
|
cosa_putstatus(cosa, SR_TX_INT_ENA);
|
|
|
|
|
schedule_timeout(30);
|
|
|
|
|
irq = probe_irq_off(irqs);
|
|
|
|
|
/* Disable all IRQs from the card */
|
|
|
|
|
cosa_putstatus(cosa, 0);
|
|
|
|
|
/* Empty the received data register */
|
|
|
|
|
cosa_getdata8(cosa);
|
|
|
|
|
|
|
|
|
|
if (irq < 0) {
|
2011-06-27 03:01:29 +08:00
|
|
|
|
pr_info("multiple interrupts obtained (%d, board at 0x%x)\n",
|
2005-04-17 06:20:36 +08:00
|
|
|
|
irq, cosa->datareg);
|
|
|
|
|
err = -1;
|
|
|
|
|
goto err_out;
|
|
|
|
|
}
|
|
|
|
|
if (irq == 0) {
|
2011-06-27 03:01:29 +08:00
|
|
|
|
pr_info("no interrupt obtained (board at 0x%x)\n",
|
2005-04-17 06:20:36 +08:00
|
|
|
|
cosa->datareg);
|
|
|
|
|
/* return -1; */
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
cosa->irq = irq;
|
|
|
|
|
cosa->num = nr_cards;
|
|
|
|
|
cosa->usage = 0;
|
|
|
|
|
cosa->nchannels = 2; /* FIXME: how to determine this? */
|
|
|
|
|
|
|
|
|
|
if (request_irq(cosa->irq, cosa_interrupt, 0, cosa->type, cosa)) {
|
|
|
|
|
err = -1;
|
|
|
|
|
goto err_out;
|
|
|
|
|
}
|
|
|
|
|
if (request_dma(cosa->dma, cosa->type)) {
|
|
|
|
|
err = -1;
|
|
|
|
|
goto err_out1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
cosa->bouncebuf = kmalloc(COSA_MTU, GFP_KERNEL|GFP_DMA);
|
|
|
|
|
if (!cosa->bouncebuf) {
|
|
|
|
|
err = -ENOMEM;
|
|
|
|
|
goto err_out2;
|
|
|
|
|
}
|
|
|
|
|
sprintf(cosa->name, "cosa%d", cosa->num);
|
|
|
|
|
|
|
|
|
|
/* Initialize the per-channel data */
|
some kmalloc/memset ->kzalloc (tree wide)
Transform some calls to kmalloc/memset to a single kzalloc (or kcalloc).
Here is a short excerpt of the semantic patch performing
this transformation:
@@
type T2;
expression x;
identifier f,fld;
expression E;
expression E1,E2;
expression e1,e2,e3,y;
statement S;
@@
x =
- kmalloc
+ kzalloc
(E1,E2)
... when != \(x->fld=E;\|y=f(...,x,...);\|f(...,x,...);\|x=E;\|while(...) S\|for(e1;e2;e3) S\)
- memset((T2)x,0,E1);
@@
expression E1,E2,E3;
@@
- kzalloc(E1 * E2,E3)
+ kcalloc(E1,E2,E3)
[akpm@linux-foundation.org: get kcalloc args the right way around]
Signed-off-by: Yoann Padioleau <padator@wanadoo.fr>
Cc: Richard Henderson <rth@twiddle.net>
Cc: Ivan Kokshaysky <ink@jurassic.park.msu.ru>
Acked-by: Russell King <rmk@arm.linux.org.uk>
Cc: Bryan Wu <bryan.wu@analog.com>
Acked-by: Jiri Slaby <jirislaby@gmail.com>
Cc: Dave Airlie <airlied@linux.ie>
Acked-by: Roland Dreier <rolandd@cisco.com>
Cc: Jiri Kosina <jkosina@suse.cz>
Acked-by: Dmitry Torokhov <dtor@mail.ru>
Cc: Benjamin Herrenschmidt <benh@kernel.crashing.org>
Acked-by: Mauro Carvalho Chehab <mchehab@infradead.org>
Acked-by: Pierre Ossman <drzeus-list@drzeus.cx>
Cc: Jeff Garzik <jeff@garzik.org>
Cc: "David S. Miller" <davem@davemloft.net>
Acked-by: Greg KH <greg@kroah.com>
Cc: James Bottomley <James.Bottomley@steeleye.com>
Cc: "Antonino A. Daplas" <adaplas@pol.net>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2007-07-19 16:49:03 +08:00
|
|
|
|
cosa->chan = kcalloc(cosa->nchannels, sizeof(struct channel_data), GFP_KERNEL);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
if (!cosa->chan) {
|
2008-07-02 05:40:29 +08:00
|
|
|
|
err = -ENOMEM;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
goto err_out3;
|
|
|
|
|
}
|
2008-07-02 05:40:29 +08:00
|
|
|
|
|
|
|
|
|
for (i = 0; i < cosa->nchannels; i++) {
|
|
|
|
|
struct channel_data *chan = &cosa->chan[i];
|
|
|
|
|
|
|
|
|
|
chan->cosa = cosa;
|
|
|
|
|
chan->num = i;
|
|
|
|
|
sprintf(chan->name, "cosa%dc%d", chan->cosa->num, i);
|
|
|
|
|
|
|
|
|
|
/* Initialize the chardev data structures */
|
|
|
|
|
mutex_init(&chan->rlock);
|
2010-09-07 22:32:25 +08:00
|
|
|
|
sema_init(&chan->wsem, 1);
|
2008-07-02 05:40:29 +08:00
|
|
|
|
|
|
|
|
|
/* Register the network interface */
|
|
|
|
|
if (!(chan->netdev = alloc_hdlcdev(chan))) {
|
2011-06-27 03:01:29 +08:00
|
|
|
|
pr_warn("%s: alloc_hdlcdev failed\n", chan->name);
|
2008-07-02 05:40:29 +08:00
|
|
|
|
goto err_hdlcdev;
|
|
|
|
|
}
|
|
|
|
|
dev_to_hdlc(chan->netdev)->attach = cosa_net_attach;
|
|
|
|
|
dev_to_hdlc(chan->netdev)->xmit = cosa_net_tx;
|
2009-01-09 05:52:11 +08:00
|
|
|
|
chan->netdev->netdev_ops = &cosa_ops;
|
2008-07-02 05:40:29 +08:00
|
|
|
|
chan->netdev->watchdog_timeo = TX_TIMEOUT;
|
|
|
|
|
chan->netdev->base_addr = chan->cosa->datareg;
|
|
|
|
|
chan->netdev->irq = chan->cosa->irq;
|
|
|
|
|
chan->netdev->dma = chan->cosa->dma;
|
|
|
|
|
if (register_hdlc_device(chan->netdev)) {
|
2011-06-27 03:01:29 +08:00
|
|
|
|
netdev_warn(chan->netdev,
|
|
|
|
|
"register_hdlc_device() failed\n");
|
2008-07-02 05:40:29 +08:00
|
|
|
|
free_netdev(chan->netdev);
|
|
|
|
|
goto err_hdlcdev;
|
|
|
|
|
}
|
2005-04-17 06:20:36 +08:00
|
|
|
|
}
|
|
|
|
|
|
2011-06-27 03:01:29 +08:00
|
|
|
|
pr_info("cosa%d: %s (%s at 0x%x irq %d dma %d), %d channels\n",
|
2005-04-17 06:20:36 +08:00
|
|
|
|
cosa->num, cosa->id_string, cosa->type,
|
|
|
|
|
cosa->datareg, cosa->irq, cosa->dma, cosa->nchannels);
|
|
|
|
|
|
|
|
|
|
return nr_cards++;
|
2008-07-02 05:40:29 +08:00
|
|
|
|
|
|
|
|
|
err_hdlcdev:
|
|
|
|
|
while (i-- > 0) {
|
|
|
|
|
unregister_hdlc_device(cosa->chan[i].netdev);
|
|
|
|
|
free_netdev(cosa->chan[i].netdev);
|
|
|
|
|
}
|
|
|
|
|
kfree(cosa->chan);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
err_out3:
|
|
|
|
|
kfree(cosa->bouncebuf);
|
|
|
|
|
err_out2:
|
|
|
|
|
free_dma(cosa->dma);
|
|
|
|
|
err_out1:
|
|
|
|
|
free_irq(cosa->irq, cosa);
|
2008-07-02 05:40:29 +08:00
|
|
|
|
err_out:
|
2005-04-17 06:20:36 +08:00
|
|
|
|
release_region(cosa->datareg,is_8bit(cosa)?2:4);
|
2011-06-27 03:01:29 +08:00
|
|
|
|
pr_notice("cosa%d: allocating resources failed\n", cosa->num);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
return err;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2008-07-02 05:40:29 +08:00
|
|
|
|
/*---------- network device ---------- */
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
2008-07-02 05:40:29 +08:00
|
|
|
|
static int cosa_net_attach(struct net_device *dev, unsigned short encoding,
|
|
|
|
|
unsigned short parity)
|
2005-04-17 06:20:36 +08:00
|
|
|
|
{
|
2008-07-02 05:40:29 +08:00
|
|
|
|
if (encoding == ENCODING_NRZ && parity == PARITY_CRC16_PR1_CCITT)
|
|
|
|
|
return 0;
|
|
|
|
|
return -EINVAL;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
}
|
|
|
|
|
|
2008-07-02 05:40:29 +08:00
|
|
|
|
static int cosa_net_open(struct net_device *dev)
|
2005-04-17 06:20:36 +08:00
|
|
|
|
{
|
2008-07-02 05:40:29 +08:00
|
|
|
|
struct channel_data *chan = dev_to_chan(dev);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
int err;
|
|
|
|
|
unsigned long flags;
|
|
|
|
|
|
|
|
|
|
if (!(chan->cosa->firmware_status & COSA_FW_START)) {
|
2011-06-27 03:01:29 +08:00
|
|
|
|
pr_notice("%s: start the firmware first (status %d)\n",
|
|
|
|
|
chan->cosa->name, chan->cosa->firmware_status);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
return -EPERM;
|
|
|
|
|
}
|
|
|
|
|
spin_lock_irqsave(&chan->cosa->lock, flags);
|
|
|
|
|
if (chan->usage != 0) {
|
2011-06-27 03:01:29 +08:00
|
|
|
|
pr_warn("%s: cosa_net_open called with usage count %d\n",
|
|
|
|
|
chan->name, chan->usage);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
spin_unlock_irqrestore(&chan->cosa->lock, flags);
|
|
|
|
|
return -EBUSY;
|
|
|
|
|
}
|
2008-07-02 05:40:29 +08:00
|
|
|
|
chan->setup_rx = cosa_net_setup_rx;
|
|
|
|
|
chan->tx_done = cosa_net_tx_done;
|
|
|
|
|
chan->rx_done = cosa_net_rx_done;
|
|
|
|
|
chan->usage = -1;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
chan->cosa->usage++;
|
|
|
|
|
spin_unlock_irqrestore(&chan->cosa->lock, flags);
|
|
|
|
|
|
2008-07-02 05:40:29 +08:00
|
|
|
|
err = hdlc_open(dev);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
if (err) {
|
|
|
|
|
spin_lock_irqsave(&chan->cosa->lock, flags);
|
2008-07-02 05:40:29 +08:00
|
|
|
|
chan->usage = 0;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
chan->cosa->usage--;
|
|
|
|
|
spin_unlock_irqrestore(&chan->cosa->lock, flags);
|
|
|
|
|
return err;
|
|
|
|
|
}
|
|
|
|
|
|
2008-07-02 05:40:29 +08:00
|
|
|
|
netif_start_queue(dev);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
cosa_enable_rx(chan);
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2009-09-01 03:50:47 +08:00
|
|
|
|
static netdev_tx_t cosa_net_tx(struct sk_buff *skb,
|
|
|
|
|
struct net_device *dev)
|
2005-04-17 06:20:36 +08:00
|
|
|
|
{
|
2008-07-02 05:40:29 +08:00
|
|
|
|
struct channel_data *chan = dev_to_chan(dev);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
|
|
netif_stop_queue(dev);
|
|
|
|
|
|
|
|
|
|
chan->tx_skb = skb;
|
|
|
|
|
cosa_start_tx(chan, skb->data, skb->len);
|
2009-09-01 03:50:47 +08:00
|
|
|
|
return NETDEV_TX_OK;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
}
|
|
|
|
|
|
2008-07-02 05:40:29 +08:00
|
|
|
|
static void cosa_net_timeout(struct net_device *dev)
|
2005-04-17 06:20:36 +08:00
|
|
|
|
{
|
2008-07-02 05:40:29 +08:00
|
|
|
|
struct channel_data *chan = dev_to_chan(dev);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
|
|
if (test_bit(RXBIT, &chan->cosa->rxtx)) {
|
2008-07-02 05:40:29 +08:00
|
|
|
|
chan->netdev->stats.rx_errors++;
|
|
|
|
|
chan->netdev->stats.rx_missed_errors++;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
} else {
|
2008-07-02 05:40:29 +08:00
|
|
|
|
chan->netdev->stats.tx_errors++;
|
|
|
|
|
chan->netdev->stats.tx_aborted_errors++;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
}
|
|
|
|
|
cosa_kick(chan->cosa);
|
|
|
|
|
if (chan->tx_skb) {
|
|
|
|
|
dev_kfree_skb(chan->tx_skb);
|
|
|
|
|
chan->tx_skb = NULL;
|
|
|
|
|
}
|
|
|
|
|
netif_wake_queue(dev);
|
|
|
|
|
}
|
|
|
|
|
|
2008-07-02 05:40:29 +08:00
|
|
|
|
static int cosa_net_close(struct net_device *dev)
|
2005-04-17 06:20:36 +08:00
|
|
|
|
{
|
2008-07-02 05:40:29 +08:00
|
|
|
|
struct channel_data *chan = dev_to_chan(dev);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
unsigned long flags;
|
|
|
|
|
|
2008-07-02 05:40:29 +08:00
|
|
|
|
netif_stop_queue(dev);
|
|
|
|
|
hdlc_close(dev);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
cosa_disable_rx(chan);
|
|
|
|
|
spin_lock_irqsave(&chan->cosa->lock, flags);
|
|
|
|
|
if (chan->rx_skb) {
|
|
|
|
|
kfree_skb(chan->rx_skb);
|
|
|
|
|
chan->rx_skb = NULL;
|
|
|
|
|
}
|
|
|
|
|
if (chan->tx_skb) {
|
|
|
|
|
kfree_skb(chan->tx_skb);
|
|
|
|
|
chan->tx_skb = NULL;
|
|
|
|
|
}
|
2008-07-02 05:40:29 +08:00
|
|
|
|
chan->usage = 0;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
chan->cosa->usage--;
|
|
|
|
|
spin_unlock_irqrestore(&chan->cosa->lock, flags);
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2008-07-02 05:40:29 +08:00
|
|
|
|
static char *cosa_net_setup_rx(struct channel_data *chan, int size)
|
2005-04-17 06:20:36 +08:00
|
|
|
|
{
|
|
|
|
|
/*
|
|
|
|
|
* We can safely fall back to non-dma-able memory, because we have
|
|
|
|
|
* the cosa->bouncebuf pre-allocated.
|
|
|
|
|
*/
|
2009-02-25 08:22:41 +08:00
|
|
|
|
kfree_skb(chan->rx_skb);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
chan->rx_skb = dev_alloc_skb(size);
|
|
|
|
|
if (chan->rx_skb == NULL) {
|
2011-06-27 03:01:29 +08:00
|
|
|
|
pr_notice("%s: Memory squeeze, dropping packet\n", chan->name);
|
2008-07-02 05:40:29 +08:00
|
|
|
|
chan->netdev->stats.rx_dropped++;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
return NULL;
|
|
|
|
|
}
|
2008-07-02 05:40:29 +08:00
|
|
|
|
chan->netdev->trans_start = jiffies;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
return skb_put(chan->rx_skb, size);
|
|
|
|
|
}
|
|
|
|
|
|
2008-07-02 05:40:29 +08:00
|
|
|
|
static int cosa_net_rx_done(struct channel_data *chan)
|
2005-04-17 06:20:36 +08:00
|
|
|
|
{
|
|
|
|
|
if (!chan->rx_skb) {
|
2011-06-27 03:01:29 +08:00
|
|
|
|
pr_warn("%s: rx_done with empty skb!\n", chan->name);
|
2008-07-02 05:40:29 +08:00
|
|
|
|
chan->netdev->stats.rx_errors++;
|
|
|
|
|
chan->netdev->stats.rx_frame_errors++;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
return 0;
|
|
|
|
|
}
|
2008-07-02 05:40:29 +08:00
|
|
|
|
chan->rx_skb->protocol = hdlc_type_trans(chan->rx_skb, chan->netdev);
|
|
|
|
|
chan->rx_skb->dev = chan->netdev;
|
2007-03-26 17:00:58 +08:00
|
|
|
|
skb_reset_mac_header(chan->rx_skb);
|
2008-07-02 05:40:29 +08:00
|
|
|
|
chan->netdev->stats.rx_packets++;
|
|
|
|
|
chan->netdev->stats.rx_bytes += chan->cosa->rxsize;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
netif_rx(chan->rx_skb);
|
|
|
|
|
chan->rx_skb = NULL;
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* ARGSUSED */
|
2008-07-02 05:40:29 +08:00
|
|
|
|
static int cosa_net_tx_done(struct channel_data *chan, int size)
|
2005-04-17 06:20:36 +08:00
|
|
|
|
{
|
|
|
|
|
if (!chan->tx_skb) {
|
2011-06-27 03:01:29 +08:00
|
|
|
|
pr_warn("%s: tx_done with empty skb!\n", chan->name);
|
2008-07-02 05:40:29 +08:00
|
|
|
|
chan->netdev->stats.tx_errors++;
|
|
|
|
|
chan->netdev->stats.tx_aborted_errors++;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
dev_kfree_skb_irq(chan->tx_skb);
|
|
|
|
|
chan->tx_skb = NULL;
|
2008-07-02 05:40:29 +08:00
|
|
|
|
chan->netdev->stats.tx_packets++;
|
|
|
|
|
chan->netdev->stats.tx_bytes += size;
|
|
|
|
|
netif_wake_queue(chan->netdev);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*---------- Character device ---------- */
|
|
|
|
|
|
|
|
|
|
static ssize_t cosa_read(struct file *file,
|
|
|
|
|
char __user *buf, size_t count, loff_t *ppos)
|
|
|
|
|
{
|
|
|
|
|
DECLARE_WAITQUEUE(wait, current);
|
|
|
|
|
unsigned long flags;
|
|
|
|
|
struct channel_data *chan = file->private_data;
|
|
|
|
|
struct cosa_data *cosa = chan->cosa;
|
|
|
|
|
char *kbuf;
|
|
|
|
|
|
|
|
|
|
if (!(cosa->firmware_status & COSA_FW_START)) {
|
2011-06-27 03:01:29 +08:00
|
|
|
|
pr_notice("%s: start the firmware first (status %d)\n",
|
|
|
|
|
cosa->name, cosa->firmware_status);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
return -EPERM;
|
|
|
|
|
}
|
2008-03-06 10:53:01 +08:00
|
|
|
|
if (mutex_lock_interruptible(&chan->rlock))
|
2005-04-17 06:20:36 +08:00
|
|
|
|
return -ERESTARTSYS;
|
|
|
|
|
|
|
|
|
|
if ((chan->rxdata = kmalloc(COSA_MTU, GFP_DMA|GFP_KERNEL)) == NULL) {
|
2011-06-27 03:01:29 +08:00
|
|
|
|
pr_info("%s: cosa_read() - OOM\n", cosa->name);
|
2008-03-06 10:53:01 +08:00
|
|
|
|
mutex_unlock(&chan->rlock);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
return -ENOMEM;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
chan->rx_status = 0;
|
|
|
|
|
cosa_enable_rx(chan);
|
|
|
|
|
spin_lock_irqsave(&cosa->lock, flags);
|
|
|
|
|
add_wait_queue(&chan->rxwaitq, &wait);
|
2009-12-09 22:35:40 +08:00
|
|
|
|
while (!chan->rx_status) {
|
2005-04-17 06:20:36 +08:00
|
|
|
|
current->state = TASK_INTERRUPTIBLE;
|
|
|
|
|
spin_unlock_irqrestore(&cosa->lock, flags);
|
|
|
|
|
schedule();
|
|
|
|
|
spin_lock_irqsave(&cosa->lock, flags);
|
|
|
|
|
if (signal_pending(current) && chan->rx_status == 0) {
|
|
|
|
|
chan->rx_status = 1;
|
|
|
|
|
remove_wait_queue(&chan->rxwaitq, &wait);
|
|
|
|
|
current->state = TASK_RUNNING;
|
|
|
|
|
spin_unlock_irqrestore(&cosa->lock, flags);
|
2008-03-06 10:53:01 +08:00
|
|
|
|
mutex_unlock(&chan->rlock);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
return -ERESTARTSYS;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
remove_wait_queue(&chan->rxwaitq, &wait);
|
|
|
|
|
current->state = TASK_RUNNING;
|
|
|
|
|
kbuf = chan->rxdata;
|
|
|
|
|
count = chan->rxsize;
|
|
|
|
|
spin_unlock_irqrestore(&cosa->lock, flags);
|
2008-03-06 10:53:01 +08:00
|
|
|
|
mutex_unlock(&chan->rlock);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
|
|
if (copy_to_user(buf, kbuf, count)) {
|
|
|
|
|
kfree(kbuf);
|
|
|
|
|
return -EFAULT;
|
|
|
|
|
}
|
|
|
|
|
kfree(kbuf);
|
|
|
|
|
return count;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static char *chrdev_setup_rx(struct channel_data *chan, int size)
|
|
|
|
|
{
|
|
|
|
|
/* Expect size <= COSA_MTU */
|
|
|
|
|
chan->rxsize = size;
|
|
|
|
|
return chan->rxdata;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static int chrdev_rx_done(struct channel_data *chan)
|
|
|
|
|
{
|
|
|
|
|
if (chan->rx_status) { /* Reader has died */
|
|
|
|
|
kfree(chan->rxdata);
|
|
|
|
|
up(&chan->wsem);
|
|
|
|
|
}
|
|
|
|
|
chan->rx_status = 1;
|
|
|
|
|
wake_up_interruptible(&chan->rxwaitq);
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static ssize_t cosa_write(struct file *file,
|
|
|
|
|
const char __user *buf, size_t count, loff_t *ppos)
|
|
|
|
|
{
|
|
|
|
|
DECLARE_WAITQUEUE(wait, current);
|
|
|
|
|
struct channel_data *chan = file->private_data;
|
|
|
|
|
struct cosa_data *cosa = chan->cosa;
|
|
|
|
|
unsigned long flags;
|
|
|
|
|
char *kbuf;
|
|
|
|
|
|
|
|
|
|
if (!(cosa->firmware_status & COSA_FW_START)) {
|
2011-06-27 03:01:29 +08:00
|
|
|
|
pr_notice("%s: start the firmware first (status %d)\n",
|
|
|
|
|
cosa->name, cosa->firmware_status);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
return -EPERM;
|
|
|
|
|
}
|
|
|
|
|
if (down_interruptible(&chan->wsem))
|
|
|
|
|
return -ERESTARTSYS;
|
|
|
|
|
|
|
|
|
|
if (count > COSA_MTU)
|
|
|
|
|
count = COSA_MTU;
|
|
|
|
|
|
|
|
|
|
/* Allocate the buffer */
|
|
|
|
|
if ((kbuf = kmalloc(count, GFP_KERNEL|GFP_DMA)) == NULL) {
|
2011-06-27 03:01:29 +08:00
|
|
|
|
pr_notice("%s: cosa_write() OOM - dropping packet\n",
|
|
|
|
|
cosa->name);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
up(&chan->wsem);
|
|
|
|
|
return -ENOMEM;
|
|
|
|
|
}
|
|
|
|
|
if (copy_from_user(kbuf, buf, count)) {
|
|
|
|
|
up(&chan->wsem);
|
|
|
|
|
kfree(kbuf);
|
|
|
|
|
return -EFAULT;
|
|
|
|
|
}
|
|
|
|
|
chan->tx_status=0;
|
|
|
|
|
cosa_start_tx(chan, kbuf, count);
|
|
|
|
|
|
|
|
|
|
spin_lock_irqsave(&cosa->lock, flags);
|
|
|
|
|
add_wait_queue(&chan->txwaitq, &wait);
|
2009-12-09 22:35:40 +08:00
|
|
|
|
while (!chan->tx_status) {
|
2005-04-17 06:20:36 +08:00
|
|
|
|
current->state = TASK_INTERRUPTIBLE;
|
|
|
|
|
spin_unlock_irqrestore(&cosa->lock, flags);
|
|
|
|
|
schedule();
|
|
|
|
|
spin_lock_irqsave(&cosa->lock, flags);
|
|
|
|
|
if (signal_pending(current) && chan->tx_status == 0) {
|
|
|
|
|
chan->tx_status = 1;
|
|
|
|
|
remove_wait_queue(&chan->txwaitq, &wait);
|
|
|
|
|
current->state = TASK_RUNNING;
|
|
|
|
|
chan->tx_status = 1;
|
|
|
|
|
spin_unlock_irqrestore(&cosa->lock, flags);
|
2009-11-29 14:02:55 +08:00
|
|
|
|
up(&chan->wsem);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
return -ERESTARTSYS;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
remove_wait_queue(&chan->txwaitq, &wait);
|
|
|
|
|
current->state = TASK_RUNNING;
|
|
|
|
|
up(&chan->wsem);
|
|
|
|
|
spin_unlock_irqrestore(&cosa->lock, flags);
|
|
|
|
|
kfree(kbuf);
|
|
|
|
|
return count;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static int chrdev_tx_done(struct channel_data *chan, int size)
|
|
|
|
|
{
|
|
|
|
|
if (chan->tx_status) { /* Writer was interrupted */
|
|
|
|
|
kfree(chan->txbuf);
|
|
|
|
|
up(&chan->wsem);
|
|
|
|
|
}
|
|
|
|
|
chan->tx_status = 1;
|
|
|
|
|
wake_up_interruptible(&chan->txwaitq);
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static unsigned int cosa_poll(struct file *file, poll_table *poll)
|
|
|
|
|
{
|
2011-06-27 03:01:29 +08:00
|
|
|
|
pr_info("cosa_poll is here\n");
|
2005-04-17 06:20:36 +08:00
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static int cosa_open(struct inode *inode, struct file *file)
|
|
|
|
|
{
|
|
|
|
|
struct cosa_data *cosa;
|
|
|
|
|
struct channel_data *chan;
|
|
|
|
|
unsigned long flags;
|
|
|
|
|
int n;
|
2008-05-15 23:21:33 +08:00
|
|
|
|
int ret = 0;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
2010-07-11 19:18:57 +08:00
|
|
|
|
mutex_lock(&cosa_chardev_mutex);
|
2006-12-08 18:36:57 +08:00
|
|
|
|
if ((n=iminor(file->f_path.dentry->d_inode)>>CARD_MINOR_BITS)
|
2008-05-15 23:21:33 +08:00
|
|
|
|
>= nr_cards) {
|
|
|
|
|
ret = -ENODEV;
|
|
|
|
|
goto out;
|
|
|
|
|
}
|
2005-04-17 06:20:36 +08:00
|
|
|
|
cosa = cosa_cards+n;
|
|
|
|
|
|
2006-12-08 18:36:57 +08:00
|
|
|
|
if ((n=iminor(file->f_path.dentry->d_inode)
|
2008-05-15 23:21:33 +08:00
|
|
|
|
& ((1<<CARD_MINOR_BITS)-1)) >= cosa->nchannels) {
|
|
|
|
|
ret = -ENODEV;
|
|
|
|
|
goto out;
|
|
|
|
|
}
|
2005-04-17 06:20:36 +08:00
|
|
|
|
chan = cosa->chan + n;
|
|
|
|
|
|
|
|
|
|
file->private_data = chan;
|
|
|
|
|
|
|
|
|
|
spin_lock_irqsave(&cosa->lock, flags);
|
|
|
|
|
|
|
|
|
|
if (chan->usage < 0) { /* in netdev mode */
|
|
|
|
|
spin_unlock_irqrestore(&cosa->lock, flags);
|
2008-05-15 23:21:33 +08:00
|
|
|
|
ret = -EBUSY;
|
|
|
|
|
goto out;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
}
|
|
|
|
|
cosa->usage++;
|
|
|
|
|
chan->usage++;
|
|
|
|
|
|
|
|
|
|
chan->tx_done = chrdev_tx_done;
|
|
|
|
|
chan->setup_rx = chrdev_setup_rx;
|
|
|
|
|
chan->rx_done = chrdev_rx_done;
|
|
|
|
|
spin_unlock_irqrestore(&cosa->lock, flags);
|
2008-05-15 23:21:33 +08:00
|
|
|
|
out:
|
2010-07-11 19:18:57 +08:00
|
|
|
|
mutex_unlock(&cosa_chardev_mutex);
|
2008-05-15 23:21:33 +08:00
|
|
|
|
return ret;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static int cosa_release(struct inode *inode, struct file *file)
|
|
|
|
|
{
|
|
|
|
|
struct channel_data *channel = file->private_data;
|
|
|
|
|
struct cosa_data *cosa;
|
|
|
|
|
unsigned long flags;
|
|
|
|
|
|
|
|
|
|
cosa = channel->cosa;
|
|
|
|
|
spin_lock_irqsave(&cosa->lock, flags);
|
|
|
|
|
cosa->usage--;
|
|
|
|
|
channel->usage--;
|
|
|
|
|
spin_unlock_irqrestore(&cosa->lock, flags);
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#ifdef COSA_FASYNC_WORKING
|
|
|
|
|
static struct fasync_struct *fasync[256] = { NULL, };
|
|
|
|
|
|
|
|
|
|
/* To be done ... */
|
|
|
|
|
static int cosa_fasync(struct inode *inode, struct file *file, int on)
|
|
|
|
|
{
|
|
|
|
|
int port = iminor(inode);
|
2009-02-02 05:52:56 +08:00
|
|
|
|
|
|
|
|
|
return fasync_helper(inode, file, on, &fasync[port]);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* ---------- Ioctls ---------- */
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Ioctl subroutines can safely be made inline, because they are called
|
|
|
|
|
* only from cosa_ioctl().
|
|
|
|
|
*/
|
|
|
|
|
static inline int cosa_reset(struct cosa_data *cosa)
|
|
|
|
|
{
|
|
|
|
|
char idstring[COSA_MAX_ID_STRING];
|
|
|
|
|
if (cosa->usage > 1)
|
2011-06-27 03:01:29 +08:00
|
|
|
|
pr_info("cosa%d: WARNING: reset requested with cosa->usage > 1 (%d). Odd things may happen.\n",
|
2005-04-17 06:20:36 +08:00
|
|
|
|
cosa->num, cosa->usage);
|
|
|
|
|
cosa->firmware_status &= ~(COSA_FW_RESET|COSA_FW_START);
|
|
|
|
|
if (cosa_reset_and_read_id(cosa, idstring) < 0) {
|
2011-06-27 03:01:29 +08:00
|
|
|
|
pr_notice("cosa%d: reset failed\n", cosa->num);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
return -EIO;
|
|
|
|
|
}
|
2011-06-27 03:01:29 +08:00
|
|
|
|
pr_info("cosa%d: resetting device: %s\n", cosa->num, idstring);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
cosa->firmware_status |= COSA_FW_RESET;
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* High-level function to download data into COSA memory. Calls download() */
|
|
|
|
|
static inline int cosa_download(struct cosa_data *cosa, void __user *arg)
|
|
|
|
|
{
|
|
|
|
|
struct cosa_download d;
|
|
|
|
|
int i;
|
|
|
|
|
|
|
|
|
|
if (cosa->usage > 1)
|
2011-06-27 03:01:29 +08:00
|
|
|
|
pr_info("%s: WARNING: download of microcode requested with cosa->usage > 1 (%d). Odd things may happen.\n",
|
2005-04-17 06:20:36 +08:00
|
|
|
|
cosa->name, cosa->usage);
|
|
|
|
|
if (!(cosa->firmware_status & COSA_FW_RESET)) {
|
2011-06-27 03:01:29 +08:00
|
|
|
|
pr_notice("%s: reset the card first (status %d)\n",
|
|
|
|
|
cosa->name, cosa->firmware_status);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
return -EPERM;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (copy_from_user(&d, arg, sizeof(d)))
|
|
|
|
|
return -EFAULT;
|
|
|
|
|
|
|
|
|
|
if (d.addr < 0 || d.addr > COSA_MAX_FIRMWARE_SIZE)
|
|
|
|
|
return -EINVAL;
|
|
|
|
|
if (d.len < 0 || d.len > COSA_MAX_FIRMWARE_SIZE)
|
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* If something fails, force the user to reset the card */
|
|
|
|
|
cosa->firmware_status &= ~(COSA_FW_RESET|COSA_FW_DOWNLOAD);
|
|
|
|
|
|
|
|
|
|
i = download(cosa, d.code, d.len, d.addr);
|
|
|
|
|
if (i < 0) {
|
2011-06-27 03:01:29 +08:00
|
|
|
|
pr_notice("cosa%d: microcode download failed: %d\n",
|
|
|
|
|
cosa->num, i);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
return -EIO;
|
|
|
|
|
}
|
2011-06-27 03:01:29 +08:00
|
|
|
|
pr_info("cosa%d: downloading microcode - 0x%04x bytes at 0x%04x\n",
|
2005-04-17 06:20:36 +08:00
|
|
|
|
cosa->num, d.len, d.addr);
|
|
|
|
|
cosa->firmware_status |= COSA_FW_RESET|COSA_FW_DOWNLOAD;
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* High-level function to read COSA memory. Calls readmem() */
|
|
|
|
|
static inline int cosa_readmem(struct cosa_data *cosa, void __user *arg)
|
|
|
|
|
{
|
|
|
|
|
struct cosa_download d;
|
|
|
|
|
int i;
|
|
|
|
|
|
|
|
|
|
if (cosa->usage > 1)
|
2011-06-27 03:01:29 +08:00
|
|
|
|
pr_info("cosa%d: WARNING: readmem requested with cosa->usage > 1 (%d). Odd things may happen.\n",
|
2005-04-17 06:20:36 +08:00
|
|
|
|
cosa->num, cosa->usage);
|
|
|
|
|
if (!(cosa->firmware_status & COSA_FW_RESET)) {
|
2011-06-27 03:01:29 +08:00
|
|
|
|
pr_notice("%s: reset the card first (status %d)\n",
|
|
|
|
|
cosa->name, cosa->firmware_status);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
return -EPERM;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (copy_from_user(&d, arg, sizeof(d)))
|
|
|
|
|
return -EFAULT;
|
|
|
|
|
|
|
|
|
|
/* If something fails, force the user to reset the card */
|
|
|
|
|
cosa->firmware_status &= ~COSA_FW_RESET;
|
|
|
|
|
|
|
|
|
|
i = readmem(cosa, d.code, d.len, d.addr);
|
|
|
|
|
if (i < 0) {
|
2011-06-27 03:01:29 +08:00
|
|
|
|
pr_notice("cosa%d: reading memory failed: %d\n", cosa->num, i);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
return -EIO;
|
|
|
|
|
}
|
2011-06-27 03:01:29 +08:00
|
|
|
|
pr_info("cosa%d: reading card memory - 0x%04x bytes at 0x%04x\n",
|
2005-04-17 06:20:36 +08:00
|
|
|
|
cosa->num, d.len, d.addr);
|
|
|
|
|
cosa->firmware_status |= COSA_FW_RESET;
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* High-level function to start microcode. Calls startmicrocode(). */
|
|
|
|
|
static inline int cosa_start(struct cosa_data *cosa, int address)
|
|
|
|
|
{
|
|
|
|
|
int i;
|
|
|
|
|
|
|
|
|
|
if (cosa->usage > 1)
|
2011-06-27 03:01:29 +08:00
|
|
|
|
pr_info("cosa%d: WARNING: start microcode requested with cosa->usage > 1 (%d). Odd things may happen.\n",
|
2005-04-17 06:20:36 +08:00
|
|
|
|
cosa->num, cosa->usage);
|
|
|
|
|
|
|
|
|
|
if ((cosa->firmware_status & (COSA_FW_RESET|COSA_FW_DOWNLOAD))
|
|
|
|
|
!= (COSA_FW_RESET|COSA_FW_DOWNLOAD)) {
|
2011-06-27 03:01:29 +08:00
|
|
|
|
pr_notice("%s: download the microcode and/or reset the card first (status %d)\n",
|
|
|
|
|
cosa->name, cosa->firmware_status);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
return -EPERM;
|
|
|
|
|
}
|
|
|
|
|
cosa->firmware_status &= ~COSA_FW_RESET;
|
|
|
|
|
if ((i=startmicrocode(cosa, address)) < 0) {
|
2011-06-27 03:01:29 +08:00
|
|
|
|
pr_notice("cosa%d: start microcode at 0x%04x failed: %d\n",
|
|
|
|
|
cosa->num, address, i);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
return -EIO;
|
|
|
|
|
}
|
2011-06-27 03:01:29 +08:00
|
|
|
|
pr_info("cosa%d: starting microcode at 0x%04x\n", cosa->num, address);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
cosa->startaddr = address;
|
|
|
|
|
cosa->firmware_status |= COSA_FW_START;
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Buffer of size at least COSA_MAX_ID_STRING is expected */
|
|
|
|
|
static inline int cosa_getidstr(struct cosa_data *cosa, char __user *string)
|
|
|
|
|
{
|
|
|
|
|
int l = strlen(cosa->id_string)+1;
|
|
|
|
|
if (copy_to_user(string, cosa->id_string, l))
|
|
|
|
|
return -EFAULT;
|
|
|
|
|
return l;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Buffer of size at least COSA_MAX_ID_STRING is expected */
|
|
|
|
|
static inline int cosa_gettype(struct cosa_data *cosa, char __user *string)
|
|
|
|
|
{
|
|
|
|
|
int l = strlen(cosa->type)+1;
|
|
|
|
|
if (copy_to_user(string, cosa->type, l))
|
|
|
|
|
return -EFAULT;
|
|
|
|
|
return l;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static int cosa_ioctl_common(struct cosa_data *cosa,
|
|
|
|
|
struct channel_data *channel, unsigned int cmd, unsigned long arg)
|
|
|
|
|
{
|
|
|
|
|
void __user *argp = (void __user *)arg;
|
2009-12-09 22:35:40 +08:00
|
|
|
|
switch (cmd) {
|
2005-04-17 06:20:36 +08:00
|
|
|
|
case COSAIORSET: /* Reset the device */
|
|
|
|
|
if (!capable(CAP_NET_ADMIN))
|
|
|
|
|
return -EACCES;
|
|
|
|
|
return cosa_reset(cosa);
|
|
|
|
|
case COSAIOSTRT: /* Start the firmware */
|
|
|
|
|
if (!capable(CAP_SYS_RAWIO))
|
|
|
|
|
return -EACCES;
|
|
|
|
|
return cosa_start(cosa, arg);
|
|
|
|
|
case COSAIODOWNLD: /* Download the firmware */
|
|
|
|
|
if (!capable(CAP_SYS_RAWIO))
|
|
|
|
|
return -EACCES;
|
|
|
|
|
|
|
|
|
|
return cosa_download(cosa, argp);
|
|
|
|
|
case COSAIORMEM:
|
|
|
|
|
if (!capable(CAP_SYS_RAWIO))
|
|
|
|
|
return -EACCES;
|
|
|
|
|
return cosa_readmem(cosa, argp);
|
|
|
|
|
case COSAIORTYPE:
|
|
|
|
|
return cosa_gettype(cosa, argp);
|
|
|
|
|
case COSAIORIDSTR:
|
|
|
|
|
return cosa_getidstr(cosa, argp);
|
|
|
|
|
case COSAIONRCARDS:
|
|
|
|
|
return nr_cards;
|
|
|
|
|
case COSAIONRCHANS:
|
|
|
|
|
return cosa->nchannels;
|
|
|
|
|
case COSAIOBMSET:
|
|
|
|
|
if (!capable(CAP_SYS_RAWIO))
|
|
|
|
|
return -EACCES;
|
|
|
|
|
if (is_8bit(cosa))
|
|
|
|
|
return -EINVAL;
|
|
|
|
|
if (arg != COSA_BM_OFF && arg != COSA_BM_ON)
|
|
|
|
|
return -EINVAL;
|
|
|
|
|
cosa->busmaster = arg;
|
|
|
|
|
return 0;
|
|
|
|
|
case COSAIOBMGET:
|
|
|
|
|
return cosa->busmaster;
|
|
|
|
|
}
|
|
|
|
|
return -ENOIOCTLCMD;
|
|
|
|
|
}
|
|
|
|
|
|
2008-07-02 05:40:29 +08:00
|
|
|
|
static int cosa_net_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
|
2005-04-17 06:20:36 +08:00
|
|
|
|
{
|
|
|
|
|
int rv;
|
2008-07-02 05:40:29 +08:00
|
|
|
|
struct channel_data *chan = dev_to_chan(dev);
|
|
|
|
|
rv = cosa_ioctl_common(chan->cosa, chan, cmd,
|
|
|
|
|
(unsigned long)ifr->ifr_data);
|
|
|
|
|
if (rv != -ENOIOCTLCMD)
|
|
|
|
|
return rv;
|
|
|
|
|
return hdlc_ioctl(dev, ifr, cmd);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
}
|
|
|
|
|
|
2009-10-14 13:22:24 +08:00
|
|
|
|
static long cosa_chardev_ioctl(struct file *file, unsigned int cmd,
|
|
|
|
|
unsigned long arg)
|
2005-04-17 06:20:36 +08:00
|
|
|
|
{
|
|
|
|
|
struct channel_data *channel = file->private_data;
|
2009-10-14 13:22:24 +08:00
|
|
|
|
struct cosa_data *cosa;
|
|
|
|
|
long ret;
|
|
|
|
|
|
2010-07-11 19:18:57 +08:00
|
|
|
|
mutex_lock(&cosa_chardev_mutex);
|
2009-10-14 13:22:24 +08:00
|
|
|
|
cosa = channel->cosa;
|
|
|
|
|
ret = cosa_ioctl_common(cosa, channel, cmd, arg);
|
2010-07-11 19:18:57 +08:00
|
|
|
|
mutex_unlock(&cosa_chardev_mutex);
|
2009-10-14 13:22:24 +08:00
|
|
|
|
return ret;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*---------- HW layer interface ---------- */
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* The higher layer can bind itself to the HW layer by setting the callbacks
|
|
|
|
|
* in the channel_data structure and by using these routines.
|
|
|
|
|
*/
|
|
|
|
|
static void cosa_enable_rx(struct channel_data *chan)
|
|
|
|
|
{
|
|
|
|
|
struct cosa_data *cosa = chan->cosa;
|
|
|
|
|
|
|
|
|
|
if (!test_and_set_bit(chan->num, &cosa->rxbitmap))
|
|
|
|
|
put_driver_status(cosa);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void cosa_disable_rx(struct channel_data *chan)
|
|
|
|
|
{
|
|
|
|
|
struct cosa_data *cosa = chan->cosa;
|
|
|
|
|
|
|
|
|
|
if (test_and_clear_bit(chan->num, &cosa->rxbitmap))
|
|
|
|
|
put_driver_status(cosa);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* FIXME: This routine probably should check for cosa_start_tx() called when
|
|
|
|
|
* the previous transmit is still unfinished. In this case the non-zero
|
|
|
|
|
* return value should indicate to the caller that the queuing(sp?) up
|
|
|
|
|
* the transmit has failed.
|
|
|
|
|
*/
|
|
|
|
|
static int cosa_start_tx(struct channel_data *chan, char *buf, int len)
|
|
|
|
|
{
|
|
|
|
|
struct cosa_data *cosa = chan->cosa;
|
|
|
|
|
unsigned long flags;
|
|
|
|
|
#ifdef DEBUG_DATA
|
|
|
|
|
int i;
|
|
|
|
|
|
2011-06-27 03:01:29 +08:00
|
|
|
|
pr_info("cosa%dc%d: starting tx(0x%x)",
|
|
|
|
|
chan->cosa->num, chan->num, len);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
for (i=0; i<len; i++)
|
2011-06-27 03:01:29 +08:00
|
|
|
|
pr_cont(" %02x", buf[i]&0xff);
|
|
|
|
|
pr_cont("\n");
|
2005-04-17 06:20:36 +08:00
|
|
|
|
#endif
|
|
|
|
|
spin_lock_irqsave(&cosa->lock, flags);
|
|
|
|
|
chan->txbuf = buf;
|
|
|
|
|
chan->txsize = len;
|
|
|
|
|
if (len > COSA_MTU)
|
|
|
|
|
chan->txsize = COSA_MTU;
|
|
|
|
|
spin_unlock_irqrestore(&cosa->lock, flags);
|
|
|
|
|
|
|
|
|
|
/* Tell the firmware we are ready */
|
|
|
|
|
set_bit(chan->num, &cosa->txbitmap);
|
|
|
|
|
put_driver_status(cosa);
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void put_driver_status(struct cosa_data *cosa)
|
|
|
|
|
{
|
|
|
|
|
unsigned long flags;
|
|
|
|
|
int status;
|
|
|
|
|
|
|
|
|
|
spin_lock_irqsave(&cosa->lock, flags);
|
|
|
|
|
|
|
|
|
|
status = (cosa->rxbitmap ? DRIVER_RX_READY : 0)
|
|
|
|
|
| (cosa->txbitmap ? DRIVER_TX_READY : 0)
|
|
|
|
|
| (cosa->txbitmap? ~(cosa->txbitmap<<DRIVER_TXMAP_SHIFT)
|
|
|
|
|
&DRIVER_TXMAP_MASK : 0);
|
|
|
|
|
if (!cosa->rxtx) {
|
|
|
|
|
if (cosa->rxbitmap|cosa->txbitmap) {
|
|
|
|
|
if (!cosa->enabled) {
|
|
|
|
|
cosa_putstatus(cosa, SR_RX_INT_ENA);
|
|
|
|
|
#ifdef DEBUG_IO
|
|
|
|
|
debug_status_out(cosa, SR_RX_INT_ENA);
|
|
|
|
|
#endif
|
|
|
|
|
cosa->enabled = 1;
|
|
|
|
|
}
|
|
|
|
|
} else if (cosa->enabled) {
|
|
|
|
|
cosa->enabled = 0;
|
|
|
|
|
cosa_putstatus(cosa, 0);
|
|
|
|
|
#ifdef DEBUG_IO
|
|
|
|
|
debug_status_out(cosa, 0);
|
|
|
|
|
#endif
|
|
|
|
|
}
|
|
|
|
|
cosa_putdata8(cosa, status);
|
|
|
|
|
#ifdef DEBUG_IO
|
|
|
|
|
debug_data_cmd(cosa, status);
|
|
|
|
|
#endif
|
|
|
|
|
}
|
|
|
|
|
spin_unlock_irqrestore(&cosa->lock, flags);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void put_driver_status_nolock(struct cosa_data *cosa)
|
|
|
|
|
{
|
|
|
|
|
int status;
|
|
|
|
|
|
|
|
|
|
status = (cosa->rxbitmap ? DRIVER_RX_READY : 0)
|
|
|
|
|
| (cosa->txbitmap ? DRIVER_TX_READY : 0)
|
|
|
|
|
| (cosa->txbitmap? ~(cosa->txbitmap<<DRIVER_TXMAP_SHIFT)
|
|
|
|
|
&DRIVER_TXMAP_MASK : 0);
|
|
|
|
|
|
|
|
|
|
if (cosa->rxbitmap|cosa->txbitmap) {
|
|
|
|
|
cosa_putstatus(cosa, SR_RX_INT_ENA);
|
|
|
|
|
#ifdef DEBUG_IO
|
|
|
|
|
debug_status_out(cosa, SR_RX_INT_ENA);
|
|
|
|
|
#endif
|
|
|
|
|
cosa->enabled = 1;
|
|
|
|
|
} else {
|
|
|
|
|
cosa_putstatus(cosa, 0);
|
|
|
|
|
#ifdef DEBUG_IO
|
|
|
|
|
debug_status_out(cosa, 0);
|
|
|
|
|
#endif
|
|
|
|
|
cosa->enabled = 0;
|
|
|
|
|
}
|
|
|
|
|
cosa_putdata8(cosa, status);
|
|
|
|
|
#ifdef DEBUG_IO
|
|
|
|
|
debug_data_cmd(cosa, status);
|
|
|
|
|
#endif
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* The "kickme" function: When the DMA times out, this is called to
|
|
|
|
|
* clean up the driver status.
|
|
|
|
|
* FIXME: Preliminary support, the interface is probably wrong.
|
|
|
|
|
*/
|
|
|
|
|
static void cosa_kick(struct cosa_data *cosa)
|
|
|
|
|
{
|
|
|
|
|
unsigned long flags, flags1;
|
|
|
|
|
char *s = "(probably) IRQ";
|
|
|
|
|
|
|
|
|
|
if (test_bit(RXBIT, &cosa->rxtx))
|
|
|
|
|
s = "RX DMA";
|
|
|
|
|
if (test_bit(TXBIT, &cosa->rxtx))
|
|
|
|
|
s = "TX DMA";
|
|
|
|
|
|
2011-06-27 03:01:29 +08:00
|
|
|
|
pr_info("%s: %s timeout - restarting\n", cosa->name, s);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
spin_lock_irqsave(&cosa->lock, flags);
|
|
|
|
|
cosa->rxtx = 0;
|
|
|
|
|
|
|
|
|
|
flags1 = claim_dma_lock();
|
|
|
|
|
disable_dma(cosa->dma);
|
|
|
|
|
clear_dma_ff(cosa->dma);
|
|
|
|
|
release_dma_lock(flags1);
|
|
|
|
|
|
|
|
|
|
/* FIXME: Anything else? */
|
|
|
|
|
udelay(100);
|
|
|
|
|
cosa_putstatus(cosa, 0);
|
|
|
|
|
udelay(100);
|
|
|
|
|
(void) cosa_getdata8(cosa);
|
|
|
|
|
udelay(100);
|
|
|
|
|
cosa_putdata8(cosa, 0);
|
|
|
|
|
udelay(100);
|
|
|
|
|
put_driver_status_nolock(cosa);
|
|
|
|
|
spin_unlock_irqrestore(&cosa->lock, flags);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Check if the whole buffer is DMA-able. It means it is below the 16M of
|
|
|
|
|
* physical memory and doesn't span the 64k boundary. For now it seems
|
|
|
|
|
* SKB's never do this, but we'll check this anyway.
|
|
|
|
|
*/
|
|
|
|
|
static int cosa_dma_able(struct channel_data *chan, char *buf, int len)
|
|
|
|
|
{
|
|
|
|
|
static int count;
|
|
|
|
|
unsigned long b = (unsigned long)buf;
|
|
|
|
|
if (b+len >= MAX_DMA_ADDRESS)
|
|
|
|
|
return 0;
|
|
|
|
|
if ((b^ (b+len)) & 0x10000) {
|
|
|
|
|
if (count++ < 5)
|
2011-06-27 03:01:29 +08:00
|
|
|
|
pr_info("%s: packet spanning a 64k boundary\n",
|
2005-04-17 06:20:36 +08:00
|
|
|
|
chan->name);
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* ---------- The SRP/COSA ROM monitor functions ---------- */
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Downloading SRP microcode: say "w" to SRP monitor, it answers by "w=",
|
|
|
|
|
* drivers need to say 4-digit hex number meaning start address of the microcode
|
|
|
|
|
* separated by a single space. Monitor replies by saying " =". Now driver
|
|
|
|
|
* has to write 4-digit hex number meaning the last byte address ended
|
|
|
|
|
* by a single space. Monitor has to reply with a space. Now the download
|
|
|
|
|
* begins. After the download monitor replies with "\r\n." (CR LF dot).
|
|
|
|
|
*/
|
|
|
|
|
static int download(struct cosa_data *cosa, const char __user *microcode, int length, int address)
|
|
|
|
|
{
|
|
|
|
|
int i;
|
|
|
|
|
|
|
|
|
|
if (put_wait_data(cosa, 'w') == -1) return -1;
|
|
|
|
|
if ((i=get_wait_data(cosa)) != 'w') { printk("dnld: 0x%04x\n",i); return -2;}
|
|
|
|
|
if (get_wait_data(cosa) != '=') return -3;
|
|
|
|
|
|
|
|
|
|
if (puthexnumber(cosa, address) < 0) return -4;
|
|
|
|
|
if (put_wait_data(cosa, ' ') == -1) return -10;
|
|
|
|
|
if (get_wait_data(cosa) != ' ') return -11;
|
|
|
|
|
if (get_wait_data(cosa) != '=') return -12;
|
|
|
|
|
|
|
|
|
|
if (puthexnumber(cosa, address+length-1) < 0) return -13;
|
|
|
|
|
if (put_wait_data(cosa, ' ') == -1) return -18;
|
|
|
|
|
if (get_wait_data(cosa) != ' ') return -19;
|
|
|
|
|
|
|
|
|
|
while (length--) {
|
|
|
|
|
char c;
|
|
|
|
|
#ifndef SRP_DOWNLOAD_AT_BOOT
|
|
|
|
|
if (get_user(c, microcode))
|
|
|
|
|
return -23; /* ??? */
|
|
|
|
|
#else
|
|
|
|
|
c = *microcode;
|
|
|
|
|
#endif
|
|
|
|
|
if (put_wait_data(cosa, c) == -1)
|
|
|
|
|
return -20;
|
|
|
|
|
microcode++;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (get_wait_data(cosa) != '\r') return -21;
|
|
|
|
|
if (get_wait_data(cosa) != '\n') return -22;
|
|
|
|
|
if (get_wait_data(cosa) != '.') return -23;
|
|
|
|
|
#if 0
|
|
|
|
|
printk(KERN_DEBUG "cosa%d: download completed.\n", cosa->num);
|
|
|
|
|
#endif
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Starting microcode is done via the "g" command of the SRP monitor.
|
|
|
|
|
* The chat should be the following: "g" "g=" "<addr><CR>"
|
|
|
|
|
* "<CR><CR><LF><CR><LF>".
|
|
|
|
|
*/
|
|
|
|
|
static int startmicrocode(struct cosa_data *cosa, int address)
|
|
|
|
|
{
|
|
|
|
|
if (put_wait_data(cosa, 'g') == -1) return -1;
|
|
|
|
|
if (get_wait_data(cosa) != 'g') return -2;
|
|
|
|
|
if (get_wait_data(cosa) != '=') return -3;
|
|
|
|
|
|
|
|
|
|
if (puthexnumber(cosa, address) < 0) return -4;
|
|
|
|
|
if (put_wait_data(cosa, '\r') == -1) return -5;
|
|
|
|
|
|
|
|
|
|
if (get_wait_data(cosa) != '\r') return -6;
|
|
|
|
|
if (get_wait_data(cosa) != '\r') return -7;
|
|
|
|
|
if (get_wait_data(cosa) != '\n') return -8;
|
|
|
|
|
if (get_wait_data(cosa) != '\r') return -9;
|
|
|
|
|
if (get_wait_data(cosa) != '\n') return -10;
|
|
|
|
|
#if 0
|
|
|
|
|
printk(KERN_DEBUG "cosa%d: microcode started\n", cosa->num);
|
|
|
|
|
#endif
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Reading memory is done via the "r" command of the SRP monitor.
|
|
|
|
|
* The chat is the following "r" "r=" "<addr> " " =" "<last_byte> " " "
|
|
|
|
|
* Then driver can read the data and the conversation is finished
|
|
|
|
|
* by SRP monitor sending "<CR><LF>." (dot at the end).
|
|
|
|
|
*
|
|
|
|
|
* This routine is not needed during the normal operation and serves
|
|
|
|
|
* for debugging purposes only.
|
|
|
|
|
*/
|
|
|
|
|
static int readmem(struct cosa_data *cosa, char __user *microcode, int length, int address)
|
|
|
|
|
{
|
|
|
|
|
if (put_wait_data(cosa, 'r') == -1) return -1;
|
|
|
|
|
if ((get_wait_data(cosa)) != 'r') return -2;
|
|
|
|
|
if ((get_wait_data(cosa)) != '=') return -3;
|
|
|
|
|
|
|
|
|
|
if (puthexnumber(cosa, address) < 0) return -4;
|
|
|
|
|
if (put_wait_data(cosa, ' ') == -1) return -5;
|
|
|
|
|
if (get_wait_data(cosa) != ' ') return -6;
|
|
|
|
|
if (get_wait_data(cosa) != '=') return -7;
|
|
|
|
|
|
|
|
|
|
if (puthexnumber(cosa, address+length-1) < 0) return -8;
|
|
|
|
|
if (put_wait_data(cosa, ' ') == -1) return -9;
|
|
|
|
|
if (get_wait_data(cosa) != ' ') return -10;
|
|
|
|
|
|
|
|
|
|
while (length--) {
|
|
|
|
|
char c;
|
|
|
|
|
int i;
|
|
|
|
|
if ((i=get_wait_data(cosa)) == -1) {
|
2011-06-27 03:01:29 +08:00
|
|
|
|
pr_info("0x%04x bytes remaining\n", length);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
return -11;
|
|
|
|
|
}
|
|
|
|
|
c=i;
|
|
|
|
|
#if 1
|
|
|
|
|
if (put_user(c, microcode))
|
|
|
|
|
return -23; /* ??? */
|
|
|
|
|
#else
|
|
|
|
|
*microcode = c;
|
|
|
|
|
#endif
|
|
|
|
|
microcode++;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (get_wait_data(cosa) != '\r') return -21;
|
|
|
|
|
if (get_wait_data(cosa) != '\n') return -22;
|
|
|
|
|
if (get_wait_data(cosa) != '.') return -23;
|
|
|
|
|
#if 0
|
|
|
|
|
printk(KERN_DEBUG "cosa%d: readmem completed.\n", cosa->num);
|
|
|
|
|
#endif
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* This function resets the device and reads the initial prompt
|
|
|
|
|
* of the device's ROM monitor.
|
|
|
|
|
*/
|
|
|
|
|
static int cosa_reset_and_read_id(struct cosa_data *cosa, char *idstring)
|
|
|
|
|
{
|
|
|
|
|
int i=0, id=0, prev=0, curr=0;
|
|
|
|
|
|
|
|
|
|
/* Reset the card ... */
|
|
|
|
|
cosa_putstatus(cosa, 0);
|
|
|
|
|
cosa_getdata8(cosa);
|
|
|
|
|
cosa_putstatus(cosa, SR_RST);
|
|
|
|
|
#ifdef MODULE
|
|
|
|
|
msleep(500);
|
|
|
|
|
#else
|
|
|
|
|
udelay(5*100000);
|
|
|
|
|
#endif
|
|
|
|
|
/* Disable all IRQs from the card */
|
|
|
|
|
cosa_putstatus(cosa, 0);
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Try to read the ID string. The card then prints out the
|
|
|
|
|
* identification string ended by the "\n\x2e".
|
|
|
|
|
*
|
|
|
|
|
* The following loop is indexed through i (instead of id)
|
|
|
|
|
* to avoid looping forever when for any reason
|
|
|
|
|
* the port returns '\r', '\n' or '\x2e' permanently.
|
|
|
|
|
*/
|
|
|
|
|
for (i=0; i<COSA_MAX_ID_STRING-1; i++, prev=curr) {
|
|
|
|
|
if ((curr = get_wait_data(cosa)) == -1) {
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
curr &= 0xff;
|
|
|
|
|
if (curr != '\r' && curr != '\n' && curr != 0x2e)
|
|
|
|
|
idstring[id++] = curr;
|
|
|
|
|
if (curr == 0x2e && prev == '\n')
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
/* Perhaps we should fail when i==COSA_MAX_ID_STRING-1 ? */
|
|
|
|
|
idstring[id] = '\0';
|
|
|
|
|
return id;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* ---------- Auxiliary routines for COSA/SRP monitor ---------- */
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* This routine gets the data byte from the card waiting for the SR_RX_RDY
|
|
|
|
|
* bit to be set in a loop. It should be used in the exceptional cases
|
|
|
|
|
* only (for example when resetting the card or downloading the firmware.
|
|
|
|
|
*/
|
|
|
|
|
static int get_wait_data(struct cosa_data *cosa)
|
|
|
|
|
{
|
|
|
|
|
int retries = 1000;
|
|
|
|
|
|
|
|
|
|
while (--retries) {
|
|
|
|
|
/* read data and return them */
|
|
|
|
|
if (cosa_getstatus(cosa) & SR_RX_RDY) {
|
|
|
|
|
short r;
|
|
|
|
|
r = cosa_getdata8(cosa);
|
|
|
|
|
#if 0
|
2011-06-27 03:01:29 +08:00
|
|
|
|
pr_info("get_wait_data returning after %d retries\n",
|
|
|
|
|
999-retries);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
#endif
|
|
|
|
|
return r;
|
|
|
|
|
}
|
|
|
|
|
/* sleep if not ready to read */
|
2005-09-11 17:09:55 +08:00
|
|
|
|
schedule_timeout_interruptible(1);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
}
|
2011-06-27 03:01:29 +08:00
|
|
|
|
pr_info("timeout in get_wait_data (status 0x%x)\n",
|
2005-04-17 06:20:36 +08:00
|
|
|
|
cosa_getstatus(cosa));
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* This routine puts the data byte to the card waiting for the SR_TX_RDY
|
|
|
|
|
* bit to be set in a loop. It should be used in the exceptional cases
|
|
|
|
|
* only (for example when resetting the card or downloading the firmware).
|
|
|
|
|
*/
|
|
|
|
|
static int put_wait_data(struct cosa_data *cosa, int data)
|
|
|
|
|
{
|
|
|
|
|
int retries = 1000;
|
|
|
|
|
while (--retries) {
|
|
|
|
|
/* read data and return them */
|
|
|
|
|
if (cosa_getstatus(cosa) & SR_TX_RDY) {
|
|
|
|
|
cosa_putdata8(cosa, data);
|
|
|
|
|
#if 0
|
2011-06-27 03:01:29 +08:00
|
|
|
|
pr_info("Putdata: %d retries\n", 999-retries);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
#endif
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
#if 0
|
|
|
|
|
/* sleep if not ready to read */
|
2005-09-11 17:09:55 +08:00
|
|
|
|
schedule_timeout_interruptible(1);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
#endif
|
|
|
|
|
}
|
2011-06-27 03:01:29 +08:00
|
|
|
|
pr_info("cosa%d: timeout in put_wait_data (status 0x%x)\n",
|
2005-04-17 06:20:36 +08:00
|
|
|
|
cosa->num, cosa_getstatus(cosa));
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* The following routine puts the hexadecimal number into the SRP monitor
|
|
|
|
|
* and verifies the proper echo of the sent bytes. Returns 0 on success,
|
|
|
|
|
* negative number on failure (-1,-3,-5,-7) means that put_wait_data() failed,
|
|
|
|
|
* (-2,-4,-6,-8) means that reading echo failed.
|
|
|
|
|
*/
|
|
|
|
|
static int puthexnumber(struct cosa_data *cosa, int number)
|
|
|
|
|
{
|
|
|
|
|
char temp[5];
|
|
|
|
|
int i;
|
|
|
|
|
|
|
|
|
|
/* Well, I should probably replace this by something faster. */
|
|
|
|
|
sprintf(temp, "%04X", number);
|
|
|
|
|
for (i=0; i<4; i++) {
|
|
|
|
|
if (put_wait_data(cosa, temp[i]) == -1) {
|
2011-06-27 03:01:29 +08:00
|
|
|
|
pr_notice("cosa%d: puthexnumber failed to write byte %d\n",
|
|
|
|
|
cosa->num, i);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
return -1-2*i;
|
|
|
|
|
}
|
|
|
|
|
if (get_wait_data(cosa) != temp[i]) {
|
2011-06-27 03:01:29 +08:00
|
|
|
|
pr_notice("cosa%d: puthexhumber failed to read echo of byte %d\n",
|
|
|
|
|
cosa->num, i);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
return -2-2*i;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* ---------- Interrupt routines ---------- */
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* There are three types of interrupt:
|
|
|
|
|
* At the beginning of transmit - this handled is in tx_interrupt(),
|
|
|
|
|
* at the beginning of receive - it is in rx_interrupt() and
|
|
|
|
|
* at the end of transmit/receive - it is the eot_interrupt() function.
|
|
|
|
|
* These functions are multiplexed by cosa_interrupt() according to the
|
|
|
|
|
* COSA status byte. I have moved the rx/tx/eot interrupt handling into
|
|
|
|
|
* separate functions to make it more readable. These functions are inline,
|
|
|
|
|
* so there should be no overhead of function call.
|
|
|
|
|
*
|
|
|
|
|
* In the COSA bus-master mode, we need to tell the card the address of a
|
|
|
|
|
* buffer. Unfortunately, COSA may be too slow for us, so we must busy-wait.
|
|
|
|
|
* It's time to use the bottom half :-(
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Transmit interrupt routine - called when COSA is willing to obtain
|
|
|
|
|
* data from the OS. The most tricky part of the routine is selection
|
|
|
|
|
* of channel we (OS) want to send packet for. For SRP we should probably
|
|
|
|
|
* use the round-robin approach. The newer COSA firmwares have a simple
|
|
|
|
|
* flow-control - in the status word has bits 2 and 3 set to 1 means that the
|
|
|
|
|
* channel 0 or 1 doesn't want to receive data.
|
|
|
|
|
*
|
|
|
|
|
* It seems there is a bug in COSA firmware (need to trace it further):
|
|
|
|
|
* When the driver status says that the kernel has no more data for transmit
|
|
|
|
|
* (e.g. at the end of TX DMA) and then the kernel changes its mind
|
|
|
|
|
* (e.g. new packet is queued to hard_start_xmit()), the card issues
|
|
|
|
|
* the TX interrupt but does not mark the channel as ready-to-transmit.
|
|
|
|
|
* The fix seems to be to push the packet to COSA despite its request.
|
|
|
|
|
* We first try to obey the card's opinion, and then fall back to forced TX.
|
|
|
|
|
*/
|
|
|
|
|
static inline void tx_interrupt(struct cosa_data *cosa, int status)
|
|
|
|
|
{
|
|
|
|
|
unsigned long flags, flags1;
|
|
|
|
|
#ifdef DEBUG_IRQS
|
2011-06-27 03:01:29 +08:00
|
|
|
|
pr_info("cosa%d: SR_DOWN_REQUEST status=0x%04x\n", cosa->num, status);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
#endif
|
|
|
|
|
spin_lock_irqsave(&cosa->lock, flags);
|
|
|
|
|
set_bit(TXBIT, &cosa->rxtx);
|
|
|
|
|
if (!test_bit(IRQBIT, &cosa->rxtx)) {
|
|
|
|
|
/* flow control, see the comment above */
|
|
|
|
|
int i=0;
|
|
|
|
|
if (!cosa->txbitmap) {
|
2011-06-27 03:01:29 +08:00
|
|
|
|
pr_warn("%s: No channel wants data in TX IRQ. Expect DMA timeout.\n",
|
2005-04-17 06:20:36 +08:00
|
|
|
|
cosa->name);
|
|
|
|
|
put_driver_status_nolock(cosa);
|
|
|
|
|
clear_bit(TXBIT, &cosa->rxtx);
|
|
|
|
|
spin_unlock_irqrestore(&cosa->lock, flags);
|
|
|
|
|
return;
|
|
|
|
|
}
|
2009-12-09 22:35:40 +08:00
|
|
|
|
while (1) {
|
2005-04-17 06:20:36 +08:00
|
|
|
|
cosa->txchan++;
|
|
|
|
|
i++;
|
|
|
|
|
if (cosa->txchan >= cosa->nchannels)
|
|
|
|
|
cosa->txchan = 0;
|
|
|
|
|
if (!(cosa->txbitmap & (1<<cosa->txchan)))
|
|
|
|
|
continue;
|
|
|
|
|
if (~status & (1 << (cosa->txchan+DRIVER_TXMAP_SHIFT)))
|
|
|
|
|
break;
|
|
|
|
|
/* in second pass, accept first ready-to-TX channel */
|
|
|
|
|
if (i > cosa->nchannels) {
|
|
|
|
|
/* Can be safely ignored */
|
|
|
|
|
#ifdef DEBUG_IRQS
|
|
|
|
|
printk(KERN_DEBUG "%s: Forcing TX "
|
|
|
|
|
"to not-ready channel %d\n",
|
|
|
|
|
cosa->name, cosa->txchan);
|
|
|
|
|
#endif
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
cosa->txsize = cosa->chan[cosa->txchan].txsize;
|
|
|
|
|
if (cosa_dma_able(cosa->chan+cosa->txchan,
|
|
|
|
|
cosa->chan[cosa->txchan].txbuf, cosa->txsize)) {
|
|
|
|
|
cosa->txbuf = cosa->chan[cosa->txchan].txbuf;
|
|
|
|
|
} else {
|
|
|
|
|
memcpy(cosa->bouncebuf, cosa->chan[cosa->txchan].txbuf,
|
|
|
|
|
cosa->txsize);
|
|
|
|
|
cosa->txbuf = cosa->bouncebuf;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (is_8bit(cosa)) {
|
|
|
|
|
if (!test_bit(IRQBIT, &cosa->rxtx)) {
|
|
|
|
|
cosa_putstatus(cosa, SR_TX_INT_ENA);
|
|
|
|
|
cosa_putdata8(cosa, ((cosa->txchan << 5) & 0xe0)|
|
|
|
|
|
((cosa->txsize >> 8) & 0x1f));
|
|
|
|
|
#ifdef DEBUG_IO
|
|
|
|
|
debug_status_out(cosa, SR_TX_INT_ENA);
|
|
|
|
|
debug_data_out(cosa, ((cosa->txchan << 5) & 0xe0)|
|
|
|
|
|
((cosa->txsize >> 8) & 0x1f));
|
|
|
|
|
debug_data_in(cosa, cosa_getdata8(cosa));
|
|
|
|
|
#else
|
|
|
|
|
cosa_getdata8(cosa);
|
|
|
|
|
#endif
|
|
|
|
|
set_bit(IRQBIT, &cosa->rxtx);
|
|
|
|
|
spin_unlock_irqrestore(&cosa->lock, flags);
|
|
|
|
|
return;
|
|
|
|
|
} else {
|
|
|
|
|
clear_bit(IRQBIT, &cosa->rxtx);
|
|
|
|
|
cosa_putstatus(cosa, 0);
|
|
|
|
|
cosa_putdata8(cosa, cosa->txsize&0xff);
|
|
|
|
|
#ifdef DEBUG_IO
|
|
|
|
|
debug_status_out(cosa, 0);
|
|
|
|
|
debug_data_out(cosa, cosa->txsize&0xff);
|
|
|
|
|
#endif
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
cosa_putstatus(cosa, SR_TX_INT_ENA);
|
|
|
|
|
cosa_putdata16(cosa, ((cosa->txchan<<13) & 0xe000)
|
|
|
|
|
| (cosa->txsize & 0x1fff));
|
|
|
|
|
#ifdef DEBUG_IO
|
|
|
|
|
debug_status_out(cosa, SR_TX_INT_ENA);
|
|
|
|
|
debug_data_out(cosa, ((cosa->txchan<<13) & 0xe000)
|
|
|
|
|
| (cosa->txsize & 0x1fff));
|
|
|
|
|
debug_data_in(cosa, cosa_getdata8(cosa));
|
|
|
|
|
debug_status_out(cosa, 0);
|
|
|
|
|
#else
|
|
|
|
|
cosa_getdata8(cosa);
|
|
|
|
|
#endif
|
|
|
|
|
cosa_putstatus(cosa, 0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (cosa->busmaster) {
|
|
|
|
|
unsigned long addr = virt_to_bus(cosa->txbuf);
|
|
|
|
|
int count=0;
|
2011-06-27 03:01:29 +08:00
|
|
|
|
pr_info("busmaster IRQ\n");
|
2005-04-17 06:20:36 +08:00
|
|
|
|
while (!(cosa_getstatus(cosa)&SR_TX_RDY)) {
|
|
|
|
|
count++;
|
|
|
|
|
udelay(10);
|
|
|
|
|
if (count > 1000) break;
|
|
|
|
|
}
|
2011-06-27 03:01:29 +08:00
|
|
|
|
pr_info("status %x\n", cosa_getstatus(cosa));
|
|
|
|
|
pr_info("ready after %d loops\n", count);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
cosa_putdata16(cosa, (addr >> 16)&0xffff);
|
|
|
|
|
|
|
|
|
|
count = 0;
|
|
|
|
|
while (!(cosa_getstatus(cosa)&SR_TX_RDY)) {
|
|
|
|
|
count++;
|
|
|
|
|
if (count > 1000) break;
|
|
|
|
|
udelay(10);
|
|
|
|
|
}
|
2011-06-27 03:01:29 +08:00
|
|
|
|
pr_info("ready after %d loops\n", count);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
cosa_putdata16(cosa, addr &0xffff);
|
|
|
|
|
flags1 = claim_dma_lock();
|
|
|
|
|
set_dma_mode(cosa->dma, DMA_MODE_CASCADE);
|
|
|
|
|
enable_dma(cosa->dma);
|
|
|
|
|
release_dma_lock(flags1);
|
|
|
|
|
} else {
|
|
|
|
|
/* start the DMA */
|
|
|
|
|
flags1 = claim_dma_lock();
|
|
|
|
|
disable_dma(cosa->dma);
|
|
|
|
|
clear_dma_ff(cosa->dma);
|
|
|
|
|
set_dma_mode(cosa->dma, DMA_MODE_WRITE);
|
|
|
|
|
set_dma_addr(cosa->dma, virt_to_bus(cosa->txbuf));
|
|
|
|
|
set_dma_count(cosa->dma, cosa->txsize);
|
|
|
|
|
enable_dma(cosa->dma);
|
|
|
|
|
release_dma_lock(flags1);
|
|
|
|
|
}
|
|
|
|
|
cosa_putstatus(cosa, SR_TX_DMA_ENA|SR_USR_INT_ENA);
|
|
|
|
|
#ifdef DEBUG_IO
|
|
|
|
|
debug_status_out(cosa, SR_TX_DMA_ENA|SR_USR_INT_ENA);
|
|
|
|
|
#endif
|
|
|
|
|
spin_unlock_irqrestore(&cosa->lock, flags);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static inline void rx_interrupt(struct cosa_data *cosa, int status)
|
|
|
|
|
{
|
|
|
|
|
unsigned long flags;
|
|
|
|
|
#ifdef DEBUG_IRQS
|
2011-06-27 03:01:29 +08:00
|
|
|
|
pr_info("cosa%d: SR_UP_REQUEST\n", cosa->num);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
spin_lock_irqsave(&cosa->lock, flags);
|
|
|
|
|
set_bit(RXBIT, &cosa->rxtx);
|
|
|
|
|
|
|
|
|
|
if (is_8bit(cosa)) {
|
|
|
|
|
if (!test_bit(IRQBIT, &cosa->rxtx)) {
|
|
|
|
|
set_bit(IRQBIT, &cosa->rxtx);
|
|
|
|
|
put_driver_status_nolock(cosa);
|
|
|
|
|
cosa->rxsize = cosa_getdata8(cosa) <<8;
|
|
|
|
|
#ifdef DEBUG_IO
|
|
|
|
|
debug_data_in(cosa, cosa->rxsize >> 8);
|
|
|
|
|
#endif
|
|
|
|
|
spin_unlock_irqrestore(&cosa->lock, flags);
|
|
|
|
|
return;
|
|
|
|
|
} else {
|
|
|
|
|
clear_bit(IRQBIT, &cosa->rxtx);
|
|
|
|
|
cosa->rxsize |= cosa_getdata8(cosa) & 0xff;
|
|
|
|
|
#ifdef DEBUG_IO
|
|
|
|
|
debug_data_in(cosa, cosa->rxsize & 0xff);
|
|
|
|
|
#endif
|
|
|
|
|
#if 0
|
2011-06-27 03:01:29 +08:00
|
|
|
|
pr_info("cosa%d: receive rxsize = (0x%04x)\n",
|
2005-04-17 06:20:36 +08:00
|
|
|
|
cosa->num, cosa->rxsize);
|
|
|
|
|
#endif
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
cosa->rxsize = cosa_getdata16(cosa);
|
|
|
|
|
#ifdef DEBUG_IO
|
|
|
|
|
debug_data_in(cosa, cosa->rxsize);
|
|
|
|
|
#endif
|
|
|
|
|
#if 0
|
2011-06-27 03:01:29 +08:00
|
|
|
|
pr_info("cosa%d: receive rxsize = (0x%04x)\n",
|
2005-04-17 06:20:36 +08:00
|
|
|
|
cosa->num, cosa->rxsize);
|
|
|
|
|
#endif
|
|
|
|
|
}
|
|
|
|
|
if (((cosa->rxsize & 0xe000) >> 13) >= cosa->nchannels) {
|
2011-06-27 03:01:29 +08:00
|
|
|
|
pr_warn("%s: rx for unknown channel (0x%04x)\n",
|
2005-04-17 06:20:36 +08:00
|
|
|
|
cosa->name, cosa->rxsize);
|
|
|
|
|
spin_unlock_irqrestore(&cosa->lock, flags);
|
|
|
|
|
goto reject;
|
|
|
|
|
}
|
|
|
|
|
cosa->rxchan = cosa->chan + ((cosa->rxsize & 0xe000) >> 13);
|
|
|
|
|
cosa->rxsize &= 0x1fff;
|
|
|
|
|
spin_unlock_irqrestore(&cosa->lock, flags);
|
|
|
|
|
|
|
|
|
|
cosa->rxbuf = NULL;
|
|
|
|
|
if (cosa->rxchan->setup_rx)
|
|
|
|
|
cosa->rxbuf = cosa->rxchan->setup_rx(cosa->rxchan, cosa->rxsize);
|
|
|
|
|
|
|
|
|
|
if (!cosa->rxbuf) {
|
|
|
|
|
reject: /* Reject the packet */
|
2011-06-27 03:01:29 +08:00
|
|
|
|
pr_info("cosa%d: rejecting packet on channel %d\n",
|
2005-04-17 06:20:36 +08:00
|
|
|
|
cosa->num, cosa->rxchan->num);
|
|
|
|
|
cosa->rxbuf = cosa->bouncebuf;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* start the DMA */
|
|
|
|
|
flags = claim_dma_lock();
|
|
|
|
|
disable_dma(cosa->dma);
|
|
|
|
|
clear_dma_ff(cosa->dma);
|
|
|
|
|
set_dma_mode(cosa->dma, DMA_MODE_READ);
|
|
|
|
|
if (cosa_dma_able(cosa->rxchan, cosa->rxbuf, cosa->rxsize & 0x1fff)) {
|
|
|
|
|
set_dma_addr(cosa->dma, virt_to_bus(cosa->rxbuf));
|
|
|
|
|
} else {
|
|
|
|
|
set_dma_addr(cosa->dma, virt_to_bus(cosa->bouncebuf));
|
|
|
|
|
}
|
|
|
|
|
set_dma_count(cosa->dma, (cosa->rxsize&0x1fff));
|
|
|
|
|
enable_dma(cosa->dma);
|
|
|
|
|
release_dma_lock(flags);
|
|
|
|
|
spin_lock_irqsave(&cosa->lock, flags);
|
|
|
|
|
cosa_putstatus(cosa, SR_RX_DMA_ENA|SR_USR_INT_ENA);
|
|
|
|
|
if (!is_8bit(cosa) && (status & SR_TX_RDY))
|
|
|
|
|
cosa_putdata8(cosa, DRIVER_RX_READY);
|
|
|
|
|
#ifdef DEBUG_IO
|
|
|
|
|
debug_status_out(cosa, SR_RX_DMA_ENA|SR_USR_INT_ENA);
|
|
|
|
|
if (!is_8bit(cosa) && (status & SR_TX_RDY))
|
|
|
|
|
debug_data_cmd(cosa, DRIVER_RX_READY);
|
|
|
|
|
#endif
|
|
|
|
|
spin_unlock_irqrestore(&cosa->lock, flags);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static inline void eot_interrupt(struct cosa_data *cosa, int status)
|
|
|
|
|
{
|
|
|
|
|
unsigned long flags, flags1;
|
|
|
|
|
spin_lock_irqsave(&cosa->lock, flags);
|
|
|
|
|
flags1 = claim_dma_lock();
|
|
|
|
|
disable_dma(cosa->dma);
|
|
|
|
|
clear_dma_ff(cosa->dma);
|
|
|
|
|
release_dma_lock(flags1);
|
|
|
|
|
if (test_bit(TXBIT, &cosa->rxtx)) {
|
|
|
|
|
struct channel_data *chan = cosa->chan+cosa->txchan;
|
|
|
|
|
if (chan->tx_done)
|
|
|
|
|
if (chan->tx_done(chan, cosa->txsize))
|
|
|
|
|
clear_bit(chan->num, &cosa->txbitmap);
|
|
|
|
|
} else if (test_bit(RXBIT, &cosa->rxtx)) {
|
|
|
|
|
#ifdef DEBUG_DATA
|
|
|
|
|
{
|
|
|
|
|
int i;
|
2011-06-27 03:01:29 +08:00
|
|
|
|
pr_info("cosa%dc%d: done rx(0x%x)",
|
|
|
|
|
cosa->num, cosa->rxchan->num, cosa->rxsize);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
for (i=0; i<cosa->rxsize; i++)
|
2011-06-27 03:01:29 +08:00
|
|
|
|
pr_cont(" %02x", cosa->rxbuf[i]&0xff);
|
|
|
|
|
pr_cont("\n");
|
2005-04-17 06:20:36 +08:00
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
/* Packet for unknown channel? */
|
|
|
|
|
if (cosa->rxbuf == cosa->bouncebuf)
|
|
|
|
|
goto out;
|
|
|
|
|
if (!cosa_dma_able(cosa->rxchan, cosa->rxbuf, cosa->rxsize))
|
|
|
|
|
memcpy(cosa->rxbuf, cosa->bouncebuf, cosa->rxsize);
|
|
|
|
|
if (cosa->rxchan->rx_done)
|
|
|
|
|
if (cosa->rxchan->rx_done(cosa->rxchan))
|
|
|
|
|
clear_bit(cosa->rxchan->num, &cosa->rxbitmap);
|
|
|
|
|
} else {
|
2011-06-27 03:01:29 +08:00
|
|
|
|
pr_notice("cosa%d: unexpected EOT interrupt\n", cosa->num);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
}
|
|
|
|
|
/*
|
|
|
|
|
* Clear the RXBIT, TXBIT and IRQBIT (the latest should be
|
|
|
|
|
* cleared anyway). We should do it as soon as possible
|
|
|
|
|
* so that we can tell the COSA we are done and to give it a time
|
|
|
|
|
* for recovery.
|
|
|
|
|
*/
|
|
|
|
|
out:
|
|
|
|
|
cosa->rxtx = 0;
|
|
|
|
|
put_driver_status_nolock(cosa);
|
|
|
|
|
spin_unlock_irqrestore(&cosa->lock, flags);
|
|
|
|
|
}
|
|
|
|
|
|
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 irqreturn_t cosa_interrupt(int irq, void *cosa_)
|
2005-04-17 06:20:36 +08:00
|
|
|
|
{
|
|
|
|
|
unsigned status;
|
|
|
|
|
int count = 0;
|
|
|
|
|
struct cosa_data *cosa = cosa_;
|
|
|
|
|
again:
|
|
|
|
|
status = cosa_getstatus(cosa);
|
|
|
|
|
#ifdef DEBUG_IRQS
|
2011-06-27 03:01:29 +08:00
|
|
|
|
pr_info("cosa%d: got IRQ, status 0x%02x\n", cosa->num, status & 0xff);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
#endif
|
|
|
|
|
#ifdef DEBUG_IO
|
|
|
|
|
debug_status_in(cosa, status);
|
|
|
|
|
#endif
|
|
|
|
|
switch (status & SR_CMD_FROM_SRP_MASK) {
|
|
|
|
|
case SR_DOWN_REQUEST:
|
|
|
|
|
tx_interrupt(cosa, status);
|
|
|
|
|
break;
|
|
|
|
|
case SR_UP_REQUEST:
|
|
|
|
|
rx_interrupt(cosa, status);
|
|
|
|
|
break;
|
|
|
|
|
case SR_END_OF_TRANSFER:
|
|
|
|
|
eot_interrupt(cosa, status);
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
/* We may be too fast for SRP. Try to wait a bit more. */
|
|
|
|
|
if (count++ < 100) {
|
|
|
|
|
udelay(100);
|
|
|
|
|
goto again;
|
|
|
|
|
}
|
2011-06-27 03:01:29 +08:00
|
|
|
|
pr_info("cosa%d: unknown status 0x%02x in IRQ after %d retries\n",
|
2005-04-17 06:20:36 +08:00
|
|
|
|
cosa->num, status & 0xff, count);
|
|
|
|
|
}
|
|
|
|
|
#ifdef DEBUG_IRQS
|
|
|
|
|
if (count)
|
2011-06-27 03:01:29 +08:00
|
|
|
|
pr_info("%s: %d-times got unknown status in IRQ\n",
|
2005-04-17 06:20:36 +08:00
|
|
|
|
cosa->name, count);
|
|
|
|
|
else
|
2011-06-27 03:01:29 +08:00
|
|
|
|
pr_info("%s: returning from IRQ\n", cosa->name);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
#endif
|
|
|
|
|
return IRQ_HANDLED;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* ---------- I/O debugging routines ---------- */
|
|
|
|
|
/*
|
|
|
|
|
* These routines can be used to monitor COSA/SRP I/O and to printk()
|
|
|
|
|
* the data being transferred on the data and status I/O port in a
|
|
|
|
|
* readable way.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#ifdef DEBUG_IO
|
|
|
|
|
static void debug_status_in(struct cosa_data *cosa, int status)
|
|
|
|
|
{
|
|
|
|
|
char *s;
|
2009-12-09 22:35:40 +08:00
|
|
|
|
switch (status & SR_CMD_FROM_SRP_MASK) {
|
2005-04-17 06:20:36 +08:00
|
|
|
|
case SR_UP_REQUEST:
|
|
|
|
|
s = "RX_REQ";
|
|
|
|
|
break;
|
|
|
|
|
case SR_DOWN_REQUEST:
|
|
|
|
|
s = "TX_REQ";
|
|
|
|
|
break;
|
|
|
|
|
case SR_END_OF_TRANSFER:
|
|
|
|
|
s = "ET_REQ";
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
s = "NO_REQ";
|
|
|
|
|
break;
|
|
|
|
|
}
|
2011-06-27 03:01:29 +08:00
|
|
|
|
pr_info("%s: IO: status -> 0x%02x (%s%s%s%s)\n",
|
2005-04-17 06:20:36 +08:00
|
|
|
|
cosa->name,
|
|
|
|
|
status,
|
2011-06-27 03:01:29 +08:00
|
|
|
|
status & SR_USR_RQ ? "USR_RQ|" : "",
|
|
|
|
|
status & SR_TX_RDY ? "TX_RDY|" : "",
|
|
|
|
|
status & SR_RX_RDY ? "RX_RDY|" : "",
|
2005-04-17 06:20:36 +08:00
|
|
|
|
s);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void debug_status_out(struct cosa_data *cosa, int status)
|
|
|
|
|
{
|
2011-06-27 03:01:29 +08:00
|
|
|
|
pr_info("%s: IO: status <- 0x%02x (%s%s%s%s%s%s)\n",
|
2005-04-17 06:20:36 +08:00
|
|
|
|
cosa->name,
|
|
|
|
|
status,
|
2011-06-27 03:01:29 +08:00
|
|
|
|
status & SR_RX_DMA_ENA ? "RXDMA|" : "!rxdma|",
|
|
|
|
|
status & SR_TX_DMA_ENA ? "TXDMA|" : "!txdma|",
|
|
|
|
|
status & SR_RST ? "RESET|" : "",
|
|
|
|
|
status & SR_USR_INT_ENA ? "USRINT|" : "!usrint|",
|
|
|
|
|
status & SR_TX_INT_ENA ? "TXINT|" : "!txint|",
|
|
|
|
|
status & SR_RX_INT_ENA ? "RXINT" : "!rxint");
|
2005-04-17 06:20:36 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void debug_data_in(struct cosa_data *cosa, int data)
|
|
|
|
|
{
|
2011-06-27 03:01:29 +08:00
|
|
|
|
pr_info("%s: IO: data -> 0x%04x\n", cosa->name, data);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void debug_data_out(struct cosa_data *cosa, int data)
|
|
|
|
|
{
|
2011-06-27 03:01:29 +08:00
|
|
|
|
pr_info("%s: IO: data <- 0x%04x\n", cosa->name, data);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void debug_data_cmd(struct cosa_data *cosa, int data)
|
|
|
|
|
{
|
2011-06-27 03:01:29 +08:00
|
|
|
|
pr_info("%s: IO: data <- 0x%04x (%s|%s)\n",
|
2005-04-17 06:20:36 +08:00
|
|
|
|
cosa->name, data,
|
|
|
|
|
data & SR_RDY_RCV ? "RX_RDY" : "!rx_rdy",
|
|
|
|
|
data & SR_RDY_SND ? "TX_RDY" : "!tx_rdy");
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
/* EOF -- this file has not been truncated */
|