/* $Id: b1dma.c,v 1.1.2.3 2004/02/10 01:07:12 keil Exp $
*
* Common module for AVM B1 cards that support dma with AMCC
*
* Copyright 2000 by Carsten Paeth <calle@calle.de>
*
* This software may be used and distributed according to the terms
* of the GNU General Public License, incorporated herein by reference.
*
*/
#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/proc_fs.h>
#include <linux/seq_file.h>
#include <linux/skbuff.h>
#include <linux/delay.h>
#include <linux/mm.h>
#include <linux/interrupt.h>
#include <linux/ioport.h>
#include <linux/capi.h>
#include <linux/kernelcapi.h>
#include <linux/gfp.h>
#include <asm/io.h>
#include <linux/init.h>
#include <asm/uaccess.h>
#include <linux/netdevice.h>
#include <linux/isdn/capilli.h>
#include "avmcard.h"
#include <linux/isdn/capicmd.h>
#include <linux/isdn/capiutil.h>
static char *revision = "$Revision: 1.1.2.3 $";
#undef AVM_B1DMA_DEBUG
/* ------------------------------------------------------------- */
MODULE_DESCRIPTION("CAPI4Linux: DMA support for active AVM cards");
MODULE_AUTHOR("Carsten Paeth");
MODULE_LICENSE("GPL");
static int suppress_pollack = 0;
module_param(suppress_pollack, bool, 0);
/* ------------------------------------------------------------- */
static void b1dma_dispatch_tx(avmcard *card);
/* ------------------------------------------------------------- */
/* S5933 */
#define AMCC_RXPTR 0x24
#define AMCC_RXLEN 0x28
#define AMCC_TXPTR 0x2c
#define AMCC_TXLEN 0x30
#define AMCC_INTCSR 0x38
# define EN_READ_TC_INT 0x00008000L
# define EN_WRITE_TC_INT 0x00004000L
# define EN_TX_TC_INT EN_READ_TC_INT
# define EN_RX_TC_INT EN_WRITE_TC_INT
# define AVM_FLAG 0x30000000L
# define ANY_S5933_INT 0x00800000L
# define READ_TC_INT 0x00080000L
# define WRITE_TC_INT 0x00040000L
# define TX_TC_INT READ_TC_INT
# define RX_TC_INT WRITE_TC_INT
# define MASTER_ABORT_INT 0x00100000L
# define TARGET_ABORT_INT 0x00200000L
# define BUS_MASTER_INT 0x00200000L
# define ALL_INT 0x000C0000L
#define AMCC_MCSR 0x3c
# define A2P_HI_PRIORITY 0x00000100L
# define EN_A2P_TRANSFERS 0x00000400L
# define P2A_HI_PRIORITY 0x00001000L
# define EN_P2A_TRANSFERS 0x00004000L
# define RESET_A2P_FLAGS 0x04000000L
# define RESET_P2A_FLAGS 0x02000000L
/* ------------------------------------------------------------- */
static inline void b1dma_writel(avmcard *card, u32 value, int off)
{
writel(value, card->mbase + off);
}
static inline u32 b1dma_readl(avmcard *card, int off)
{
return readl(card->mbase + off);
}
/* ------------------------------------------------------------- */
static inline int b1dma_tx_empty(unsigned int port)
{
return inb(port + 0x03) & 0x1;
}
static inline int b1dma_rx_full(unsigned int port)
{
return inb(port + 0x02) & 0x1;
}
static int b1dma_tolink(avmcard *card, void *buf, unsigned int len)
{
unsigned long stop = jiffies + 1 * HZ; /* maximum wait time 1 sec */
unsigned char *s = (unsigned char *)buf;
while (len--) {
while ( !b1dma_tx_empty(card->port)
&& time_before(jiffies, stop));
if (!b1dma_tx_empty(card->port))
return -1;
t1outp(card->port, 0x01, *s++);
}
return 0;
}
static int b1dma_fromlink(avmcard *card, void *buf, unsigned int len)
{
unsigned long stop = jiffies + 1 * HZ; /* maximum wait time 1 sec */
unsigned char *s = (unsigned char *)buf;
while (len--) {
while ( !b1dma_rx_full(card->port)
&& time_before(jiffies, stop));
if (!b1dma_rx_full(card->port))
return -1;
*s++ = t1inp(card->port, 0x00);
}
return 0;
}
static int WriteReg(avmcard *card, u32 reg, u8 val)
{
u8 cmd = 0x00;
if ( b1dma_tolink(card, &cmd, 1) == 0
&& b1dma_tolink(card, ®, 4) == 0) {
u32 tmp = val;
return b1dma_tolink(card, &tmp, 4);
}
return -1;
}
static u8 ReadReg(avmcard *card, u32 reg)
{
u8 cmd = 0x01;
if ( b1dma_tolink(card, &cmd, 1) == 0
&& b1dma_tolink(card, ®, 4) == 0) {
u32 tmp;
if (b1dma_fromlink(card, &tmp, 4) == 0)
return (u8)tmp;
}
return 0xff;
}
/* ------------------------------------------------------------- */
static inline void _put_byte(void **pp, u8 val)
{
u8 *s