| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | /* $Id: c4.c,v 1.1.2.2 2004/01/16 21:09:27 keil Exp $
 | 
					
						
							| 
									
										
										
										
											2012-02-19 19:52:38 -08:00
										 |  |  |  * | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  |  * Module for AVM C4 & C2 card. | 
					
						
							| 
									
										
										
										
											2012-02-19 19:52:38 -08:00
										 |  |  |  * | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  |  * Copyright 1999 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>
 | 
					
						
							| 
									
										
										
										
											2010-01-14 03:10:54 -08:00
										 |  |  | #include <linux/proc_fs.h>
 | 
					
						
							|  |  |  | #include <linux/seq_file.h>
 | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | #include <linux/skbuff.h>
 | 
					
						
							|  |  |  | #include <linux/delay.h>
 | 
					
						
							|  |  |  | #include <linux/mm.h>
 | 
					
						
							|  |  |  | #include <linux/interrupt.h>
 | 
					
						
							|  |  |  | #include <linux/ioport.h>
 | 
					
						
							|  |  |  | #include <linux/pci.h>
 | 
					
						
							|  |  |  | #include <linux/capi.h>
 | 
					
						
							|  |  |  | #include <linux/kernelcapi.h>
 | 
					
						
							|  |  |  | #include <linux/init.h>
 | 
					
						
							| 
									
										
											  
											
												include cleanup: Update gfp.h and slab.h includes to prepare for breaking implicit slab.h inclusion from percpu.h
percpu.h is included by sched.h and module.h and thus ends up being
included when building most .c files.  percpu.h includes slab.h which
in turn includes gfp.h making everything defined by the two files
universally available and complicating inclusion dependencies.
percpu.h -> slab.h dependency is about to be removed.  Prepare for
this change by updating users of gfp and slab facilities include those
headers directly instead of assuming availability.  As this conversion
needs to touch large number of source files, the following script is
used as the basis of conversion.
  http://userweb.kernel.org/~tj/misc/slabh-sweep.py
The script does the followings.
* Scan files for gfp and slab usages and update includes such that
  only the necessary includes are there.  ie. if only gfp is used,
  gfp.h, if slab is used, slab.h.
* When the script inserts a new include, it looks at the include
  blocks and try to put the new include such that its order conforms
  to its surrounding.  It's put in the include block which contains
  core kernel includes, in the same order that the rest are ordered -
  alphabetical, Christmas tree, rev-Xmas-tree or at the end if there
  doesn't seem to be any matching order.
* If the script can't find a place to put a new include (mostly
  because the file doesn't have fitting include block), it prints out
  an error message indicating which .h file needs to be added to the
  file.
The conversion was done in the following steps.
1. The initial automatic conversion of all .c files updated slightly
   over 4000 files, deleting around 700 includes and adding ~480 gfp.h
   and ~3000 slab.h inclusions.  The script emitted errors for ~400
   files.
2. Each error was manually checked.  Some didn't need the inclusion,
   some needed manual addition while adding it to implementation .h or
   embedding .c file was more appropriate for others.  This step added
   inclusions to around 150 files.
3. The script was run again and the output was compared to the edits
   from #2 to make sure no file was left behind.
4. Several build tests were done and a couple of problems were fixed.
   e.g. lib/decompress_*.c used malloc/free() wrappers around slab
   APIs requiring slab.h to be added manually.
5. The script was run on all .h files but without automatically
   editing them as sprinkling gfp.h and slab.h inclusions around .h
   files could easily lead to inclusion dependency hell.  Most gfp.h
   inclusion directives were ignored as stuff from gfp.h was usually
   wildly available and often used in preprocessor macros.  Each
   slab.h inclusion directive was examined and added manually as
   necessary.
6. percpu.h was updated not to include slab.h.
7. Build test were done on the following configurations and failures
   were fixed.  CONFIG_GCOV_KERNEL was turned off for all tests (as my
   distributed build env didn't work with gcov compiles) and a few
   more options had to be turned off depending on archs to make things
   build (like ipr on powerpc/64 which failed due to missing writeq).
   * x86 and x86_64 UP and SMP allmodconfig and a custom test config.
   * powerpc and powerpc64 SMP allmodconfig
   * sparc and sparc64 SMP allmodconfig
   * ia64 SMP allmodconfig
   * s390 SMP allmodconfig
   * alpha SMP allmodconfig
   * um on x86_64 SMP allmodconfig
8. percpu.h modifications were reverted so that it could be applied as
   a separate patch and serve as bisection point.
Given the fact that I had only a couple of failures from tests on step
6, I'm fairly confident about the coverage of this conversion patch.
If there is a breakage, it's likely to be something in one of the arch
headers which should be easily discoverable easily on most builds of
the specific arch.
Signed-off-by: Tejun Heo <tj@kernel.org>
Guess-its-ok-by: Christoph Lameter <cl@linux-foundation.org>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Lee Schermerhorn <Lee.Schermerhorn@hp.com>
											
										 
											2010-03-24 17:04:11 +09:00
										 |  |  | #include <linux/gfp.h>
 | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | #include <asm/io.h>
 | 
					
						
							|  |  |  | #include <asm/uaccess.h>
 | 
					
						
							|  |  |  | #include <linux/netdevice.h>
 | 
					
						
							|  |  |  | #include <linux/isdn/capicmd.h>
 | 
					
						
							|  |  |  | #include <linux/isdn/capiutil.h>
 | 
					
						
							|  |  |  | #include <linux/isdn/capilli.h>
 | 
					
						
							|  |  |  | #include "avmcard.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2007-02-12 00:53:20 -08:00
										 |  |  | #undef AVM_C4_DEBUG
 | 
					
						
							|  |  |  | #undef AVM_C4_POLLDEBUG
 | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  | /* ------------------------------------------------------------- */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static char *revision = "$Revision: 1.1.2.2 $"; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* ------------------------------------------------------------- */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-01-13 09:32:20 +10:30
										 |  |  | static bool suppress_pollack; | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  | static struct pci_device_id c4_pci_tbl[] = { | 
					
						
							|  |  |  | 	{ PCI_VENDOR_ID_DEC, PCI_DEVICE_ID_DEC_21285, PCI_VENDOR_ID_AVM, PCI_DEVICE_ID_AVM_C4, 0, 0, (unsigned long)4 }, | 
					
						
							|  |  |  | 	{ PCI_VENDOR_ID_DEC, PCI_DEVICE_ID_DEC_21285, PCI_VENDOR_ID_AVM, PCI_DEVICE_ID_AVM_C2, 0, 0, (unsigned long)2 }, | 
					
						
							|  |  |  | 	{ }			/* Terminating entry */ | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | MODULE_DEVICE_TABLE(pci, c4_pci_tbl); | 
					
						
							|  |  |  | MODULE_DESCRIPTION("CAPI4Linux: Driver for AVM C2/C4 cards"); | 
					
						
							|  |  |  | MODULE_AUTHOR("Carsten Paeth"); | 
					
						
							|  |  |  | MODULE_LICENSE("GPL"); | 
					
						
							| 
									
										
										
										
											2006-03-25 03:07:05 -08:00
										 |  |  | module_param(suppress_pollack, bool, 0); | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  | /* ------------------------------------------------------------- */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static void c4_dispatch_tx(avmcard *card); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* ------------------------------------------------------------- */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #define DC21285_DRAM_A0MR	0x40000000
 | 
					
						
							|  |  |  | #define DC21285_DRAM_A1MR	0x40004000
 | 
					
						
							|  |  |  | #define DC21285_DRAM_A2MR	0x40008000
 | 
					
						
							|  |  |  | #define DC21285_DRAM_A3MR	0x4000C000
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #define	CAS_OFFSET	0x88
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #define DC21285_ARMCSR_BASE	0x42000000
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #define	PCI_OUT_INT_STATUS	0x30
 | 
					
						
							|  |  |  | #define	PCI_OUT_INT_MASK	0x34
 | 
					
						
							|  |  |  | #define	MAILBOX_0		0x50
 | 
					
						
							|  |  |  | #define	MAILBOX_1		0x54
 | 
					
						
							|  |  |  | #define	MAILBOX_2		0x58
 | 
					
						
							|  |  |  | #define	MAILBOX_3		0x5C
 | 
					
						
							|  |  |  | #define	DOORBELL		0x60
 | 
					
						
							|  |  |  | #define	DOORBELL_SETUP		0x64
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #define CHAN_1_CONTROL		0x90
 | 
					
						
							|  |  |  | #define CHAN_2_CONTROL		0xB0
 | 
					
						
							|  |  |  | #define DRAM_TIMING		0x10C
 | 
					
						
							|  |  |  | #define DRAM_ADDR_SIZE_0	0x110
 | 
					
						
							|  |  |  | #define DRAM_ADDR_SIZE_1	0x114
 | 
					
						
							|  |  |  | #define DRAM_ADDR_SIZE_2	0x118
 | 
					
						
							|  |  |  | #define DRAM_ADDR_SIZE_3	0x11C
 | 
					
						
							|  |  |  | #define	SA_CONTROL		0x13C
 | 
					
						
							|  |  |  | #define	XBUS_CYCLE		0x148
 | 
					
						
							|  |  |  | #define	XBUS_STROBE		0x14C
 | 
					
						
							|  |  |  | #define	DBELL_PCI_MASK		0x150
 | 
					
						
							|  |  |  | #define DBELL_SA_MASK		0x154
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #define SDRAM_SIZE		0x1000000
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* ------------------------------------------------------------- */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #define	MBOX_PEEK_POKE		MAILBOX_0
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #define DBELL_ADDR		0x01
 | 
					
						
							|  |  |  | #define DBELL_DATA		0x02
 | 
					
						
							|  |  |  | #define DBELL_RNWR		0x40
 | 
					
						
							|  |  |  | #define DBELL_INIT		0x80
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* ------------------------------------------------------------- */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #define	MBOX_UP_ADDR		MAILBOX_0
 | 
					
						
							|  |  |  | #define	MBOX_UP_LEN		MAILBOX_1
 | 
					
						
							|  |  |  | #define	MBOX_DOWN_ADDR		MAILBOX_2
 | 
					
						
							|  |  |  | #define	MBOX_DOWN_LEN		MAILBOX_3
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #define	DBELL_UP_HOST		0x00000100
 | 
					
						
							|  |  |  | #define	DBELL_UP_ARM		0x00000200
 | 
					
						
							|  |  |  | #define	DBELL_DOWN_HOST		0x00000400
 | 
					
						
							|  |  |  | #define	DBELL_DOWN_ARM		0x00000800
 | 
					
						
							|  |  |  | #define	DBELL_RESET_HOST	0x40000000
 | 
					
						
							|  |  |  | #define	DBELL_RESET_ARM		0x80000000
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* ------------------------------------------------------------- */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #define	DRAM_TIMING_DEF		0x001A01A5
 | 
					
						
							|  |  |  | #define DRAM_AD_SZ_DEF0		0x00000045
 | 
					
						
							|  |  |  | #define DRAM_AD_SZ_NULL		0x00000000
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #define SA_CTL_ALLRIGHT		0x64AA0271
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #define	INIT_XBUS_CYCLE		0x100016DB
 | 
					
						
							|  |  |  | #define	INIT_XBUS_STROBE	0xF1F1F1F1
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* ------------------------------------------------------------- */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-02-19 19:52:38 -08:00
										 |  |  | #define	RESET_TIMEOUT		(15 * HZ)	/* 15 sec */
 | 
					
						
							|  |  |  | #define	PEEK_POKE_TIMEOUT	(HZ / 10)	/* 0.1 sec */
 | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  | /* ------------------------------------------------------------- */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #define c4outmeml(addr, value)	writel(value, addr)
 | 
					
						
							|  |  |  | #define c4inmeml(addr)	readl(addr)
 | 
					
						
							|  |  |  | #define c4outmemw(addr, value)	writew(value, addr)
 | 
					
						
							|  |  |  | #define c4inmemw(addr)	readw(addr)
 | 
					
						
							|  |  |  | #define c4outmemb(addr, value)	writeb(value, addr)
 | 
					
						
							|  |  |  | #define c4inmemb(addr)	readb(addr)
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* ------------------------------------------------------------- */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static inline int wait_for_doorbell(avmcard *card, unsigned long t) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	unsigned long stop; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	stop = jiffies + t; | 
					
						
							| 
									
										
										
										
											2012-02-19 19:52:38 -08:00
										 |  |  | 	while (c4inmeml(card->mbase + DOORBELL) != 0xffffffff) { | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 		if (!time_before(jiffies, stop)) | 
					
						
							|  |  |  | 			return -1; | 
					
						
							|  |  |  | 		mb(); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	return 0; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static int c4_poke(avmcard *card,  unsigned long off, unsigned long value) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-02-19 19:52:38 -08:00
										 |  |  | 	if (wait_for_doorbell(card, HZ / 10) < 0) | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 		return -1; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-02-19 19:52:38 -08:00
										 |  |  | 	c4outmeml(card->mbase + MBOX_PEEK_POKE, off); | 
					
						
							|  |  |  | 	c4outmeml(card->mbase + DOORBELL, DBELL_ADDR); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (wait_for_doorbell(card, HZ / 10) < 0) | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 		return -1; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-02-19 19:52:38 -08:00
										 |  |  | 	c4outmeml(card->mbase + MBOX_PEEK_POKE, value); | 
					
						
							|  |  |  | 	c4outmeml(card->mbase + DOORBELL, DBELL_DATA | DBELL_ADDR); | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	return 0; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static int c4_peek(avmcard *card,  unsigned long off, unsigned long *valuep) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2012-02-19 19:52:38 -08:00
										 |  |  | 	if (wait_for_doorbell(card, HZ / 10) < 0) | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 		return -1; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-02-19 19:52:38 -08:00
										 |  |  | 	c4outmeml(card->mbase + MBOX_PEEK_POKE, off); | 
					
						
							|  |  |  | 	c4outmeml(card->mbase + DOORBELL, DBELL_RNWR | DBELL_ADDR); | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-02-19 19:52:38 -08:00
										 |  |  | 	if (wait_for_doorbell(card, HZ / 10) < 0) | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 		return -1; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-02-19 19:52:38 -08:00
										 |  |  | 	*valuep = c4inmeml(card->mbase + MBOX_PEEK_POKE); | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	return 0; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* ------------------------------------------------------------- */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-02-19 19:52:38 -08:00
										 |  |  | static int c4_load_t4file(avmcard *card, capiloaddatapart *t4file) | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | { | 
					
						
							|  |  |  | 	u32 val; | 
					
						
							|  |  |  | 	unsigned char *dp; | 
					
						
							|  |  |  | 	u_int left; | 
					
						
							|  |  |  | 	u32 loadoff = 0; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	dp = t4file->data; | 
					
						
							|  |  |  | 	left = t4file->len; | 
					
						
							|  |  |  | 	while (left >= sizeof(u32)) { | 
					
						
							| 
									
										
										
										
											2012-02-19 19:52:38 -08:00
										 |  |  | 		if (t4file->user) { | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 			if (copy_from_user(&val, dp, sizeof(val))) | 
					
						
							|  |  |  | 				return -EFAULT; | 
					
						
							|  |  |  | 		} else { | 
					
						
							|  |  |  | 			memcpy(&val, dp, sizeof(val)); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		if (c4_poke(card, loadoff, val)) { | 
					
						
							|  |  |  | 			printk(KERN_ERR "%s: corrupted firmware file ?\n", | 
					
						
							| 
									
										
										
										
											2012-02-19 19:52:38 -08:00
										 |  |  | 			       card->name); | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 			return -EIO; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		left -= sizeof(u32); | 
					
						
							|  |  |  | 		dp += sizeof(u32); | 
					
						
							|  |  |  | 		loadoff += sizeof(u32); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	if (left) { | 
					
						
							|  |  |  | 		val = 0; | 
					
						
							|  |  |  | 		if (t4file->user) { | 
					
						
							|  |  |  | 			if (copy_from_user(&val, dp, left)) | 
					
						
							|  |  |  | 				return -EFAULT; | 
					
						
							|  |  |  | 		} else { | 
					
						
							|  |  |  | 			memcpy(&val, dp, left); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		if (c4_poke(card, loadoff, val)) { | 
					
						
							|  |  |  | 			printk(KERN_ERR "%s: corrupted firmware file ?\n", | 
					
						
							| 
									
										
										
										
											2012-02-19 19:52:38 -08:00
										 |  |  | 			       card->name); | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 			return -EIO; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	return 0; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* ------------------------------------------------------------- */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static inline void _put_byte(void **pp, u8 val) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	u8 *s = *pp; | 
					
						
							|  |  |  | 	*s++ = val; | 
					
						
							|  |  |  | 	*pp = s; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static inline void _put_word(void **pp, u32 val) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	u8 *s = *pp; | 
					
						
							|  |  |  | 	*s++ = val & 0xff; | 
					
						
							|  |  |  | 	*s++ = (val >> 8) & 0xff; | 
					
						
							|  |  |  | 	*s++ = (val >> 16) & 0xff; | 
					
						
							|  |  |  | 	*s++ = (val >> 24) & 0xff; | 
					
						
							|  |  |  | 	*pp = s; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static inline void _put_slice(void **pp, unsigned char *dp, unsigned int len) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	unsigned i = len; | 
					
						
							|  |  |  | 	_put_word(pp, i); | 
					
						
							|  |  |  | 	while (i-- > 0) | 
					
						
							|  |  |  | 		_put_byte(pp, *dp++); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static inline u8 _get_byte(void **pp) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	u8 *s = *pp; | 
					
						
							|  |  |  | 	u8 val; | 
					
						
							|  |  |  | 	val = *s++; | 
					
						
							|  |  |  | 	*pp = s; | 
					
						
							|  |  |  | 	return val; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static inline u32 _get_word(void **pp) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	u8 *s = *pp; | 
					
						
							|  |  |  | 	u32 val; | 
					
						
							|  |  |  | 	val = *s++; | 
					
						
							|  |  |  | 	val |= (*s++ << 8); | 
					
						
							|  |  |  | 	val |= (*s++ << 16); | 
					
						
							|  |  |  | 	val |= (*s++ << 24); | 
					
						
							|  |  |  | 	*pp = s; | 
					
						
							|  |  |  | 	return val; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static inline u32 _get_slice(void **pp, unsigned char *dp) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	unsigned int len, i; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	len = i = _get_word(pp); | 
					
						
							|  |  |  | 	while (i-- > 0) *dp++ = _get_byte(pp); | 
					
						
							|  |  |  | 	return len; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* ------------------------------------------------------------- */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static void c4_reset(avmcard *card) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	unsigned long stop; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-02-19 19:52:38 -08:00
										 |  |  | 	c4outmeml(card->mbase + DOORBELL, DBELL_RESET_ARM); | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-02-19 19:52:38 -08:00
										 |  |  | 	stop = jiffies + HZ * 10; | 
					
						
							|  |  |  | 	while (c4inmeml(card->mbase + DOORBELL) != 0xffffffff) { | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 		if (!time_before(jiffies, stop)) | 
					
						
							|  |  |  | 			return; | 
					
						
							| 
									
										
										
										
											2012-02-19 19:52:38 -08:00
										 |  |  | 		c4outmeml(card->mbase + DOORBELL, DBELL_ADDR); | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 		mb(); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	c4_poke(card, DC21285_ARMCSR_BASE + CHAN_1_CONTROL, 0); | 
					
						
							|  |  |  | 	c4_poke(card, DC21285_ARMCSR_BASE + CHAN_2_CONTROL, 0); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* ------------------------------------------------------------- */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static int c4_detect(avmcard *card) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	unsigned long stop, dummy; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-02-19 19:52:38 -08:00
										 |  |  | 	c4outmeml(card->mbase + PCI_OUT_INT_MASK, 0x0c); | 
					
						
							|  |  |  | 	if (c4inmeml(card->mbase + PCI_OUT_INT_MASK) != 0x0c) | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 		return	1; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-02-19 19:52:38 -08:00
										 |  |  | 	c4outmeml(card->mbase + DOORBELL, DBELL_RESET_ARM); | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-02-19 19:52:38 -08:00
										 |  |  | 	stop = jiffies + HZ * 10; | 
					
						
							|  |  |  | 	while (c4inmeml(card->mbase + DOORBELL) != 0xffffffff) { | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 		if (!time_before(jiffies, stop)) | 
					
						
							|  |  |  | 			return 2; | 
					
						
							| 
									
										
										
										
											2012-02-19 19:52:38 -08:00
										 |  |  | 		c4outmeml(card->mbase + DOORBELL, DBELL_ADDR); | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 		mb(); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	c4_poke(card, DC21285_ARMCSR_BASE + CHAN_1_CONTROL, 0); | 
					
						
							|  |  |  | 	c4_poke(card, DC21285_ARMCSR_BASE + CHAN_2_CONTROL, 0); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-02-19 19:52:38 -08:00
										 |  |  | 	c4outmeml(card->mbase + MAILBOX_0, 0x55aa55aa); | 
					
						
							|  |  |  | 	if (c4inmeml(card->mbase + MAILBOX_0) != 0x55aa55aa) return 3; | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-02-19 19:52:38 -08:00
										 |  |  | 	c4outmeml(card->mbase + MAILBOX_0, 0xaa55aa55); | 
					
						
							|  |  |  | 	if (c4inmeml(card->mbase + MAILBOX_0) != 0xaa55aa55) return 4; | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-02-19 19:52:38 -08:00
										 |  |  | 	if (c4_poke(card, DC21285_ARMCSR_BASE + DBELL_SA_MASK, 0)) return 5; | 
					
						
							|  |  |  | 	if (c4_poke(card, DC21285_ARMCSR_BASE + DBELL_PCI_MASK, 0)) return 6; | 
					
						
							|  |  |  | 	if (c4_poke(card, DC21285_ARMCSR_BASE + SA_CONTROL, SA_CTL_ALLRIGHT)) | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 		return 7; | 
					
						
							| 
									
										
										
										
											2012-02-19 19:52:38 -08:00
										 |  |  | 	if (c4_poke(card, DC21285_ARMCSR_BASE + XBUS_CYCLE, INIT_XBUS_CYCLE)) | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 		return 8; | 
					
						
							| 
									
										
										
										
											2012-02-19 19:52:38 -08:00
										 |  |  | 	if (c4_poke(card, DC21285_ARMCSR_BASE + XBUS_STROBE, INIT_XBUS_STROBE)) | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 		return 8; | 
					
						
							| 
									
										
										
										
											2012-02-19 19:52:38 -08:00
										 |  |  | 	if (c4_poke(card, DC21285_ARMCSR_BASE + DRAM_TIMING, 0)) return 9; | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-02-19 19:52:38 -08:00
										 |  |  | 	mdelay(1); | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	if (c4_peek(card, DC21285_DRAM_A0MR, &dummy)) return 10; | 
					
						
							|  |  |  | 	if (c4_peek(card, DC21285_DRAM_A1MR, &dummy)) return 11; | 
					
						
							|  |  |  | 	if (c4_peek(card, DC21285_DRAM_A2MR, &dummy)) return 12; | 
					
						
							|  |  |  | 	if (c4_peek(card, DC21285_DRAM_A3MR, &dummy)) return 13; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-02-19 19:52:38 -08:00
										 |  |  | 	if (c4_poke(card, DC21285_DRAM_A0MR + CAS_OFFSET, 0)) return 14; | 
					
						
							|  |  |  | 	if (c4_poke(card, DC21285_DRAM_A1MR + CAS_OFFSET, 0)) return 15; | 
					
						
							|  |  |  | 	if (c4_poke(card, DC21285_DRAM_A2MR + CAS_OFFSET, 0)) return 16; | 
					
						
							|  |  |  | 	if (c4_poke(card, DC21285_DRAM_A3MR + CAS_OFFSET, 0)) return 17; | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-02-19 19:52:38 -08:00
										 |  |  | 	mdelay(1); | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-02-19 19:52:38 -08:00
										 |  |  | 	if (c4_poke(card, DC21285_ARMCSR_BASE + DRAM_TIMING, DRAM_TIMING_DEF)) | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 		return 18; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-02-19 19:52:38 -08:00
										 |  |  | 	if (c4_poke(card, DC21285_ARMCSR_BASE + DRAM_ADDR_SIZE_0, DRAM_AD_SZ_DEF0)) | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 		return 19; | 
					
						
							| 
									
										
										
										
											2012-02-19 19:52:38 -08:00
										 |  |  | 	if (c4_poke(card, DC21285_ARMCSR_BASE + DRAM_ADDR_SIZE_1, DRAM_AD_SZ_NULL)) | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 		return 20; | 
					
						
							| 
									
										
										
										
											2012-02-19 19:52:38 -08:00
										 |  |  | 	if (c4_poke(card, DC21285_ARMCSR_BASE + DRAM_ADDR_SIZE_2, DRAM_AD_SZ_NULL)) | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 		return 21; | 
					
						
							| 
									
										
										
										
											2012-02-19 19:52:38 -08:00
										 |  |  | 	if (c4_poke(card, DC21285_ARMCSR_BASE + DRAM_ADDR_SIZE_3, DRAM_AD_SZ_NULL)) | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 		return 22; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* Transputer test */ | 
					
						
							| 
									
										
										
										
											2012-02-19 19:52:38 -08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	if (c4_poke(card, 0x000000, 0x11111111) | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 	    || c4_poke(card, 0x400000, 0x22222222) | 
					
						
							| 
									
										
										
										
											2012-02-19 19:52:38 -08:00
										 |  |  | 	       || c4_poke(card, 0x800000, 0x33333333) | 
					
						
							|  |  |  | 	       || c4_poke(card, 0xC00000, 0x44444444)) | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 		return 23; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-02-19 19:52:38 -08:00
										 |  |  | 	if (c4_peek(card, 0x000000, &dummy) || dummy != 0x11111111 | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 	    || c4_peek(card, 0x400000, &dummy) || dummy != 0x22222222 | 
					
						
							| 
									
										
										
										
											2012-02-19 19:52:38 -08:00
										 |  |  | 	       || c4_peek(card, 0x800000, &dummy) || dummy != 0x33333333 | 
					
						
							|  |  |  | 	       || c4_peek(card, 0xC00000, &dummy) || dummy != 0x44444444) | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 		return 24; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-02-19 19:52:38 -08:00
										 |  |  | 	if (c4_poke(card, 0x000000, 0x55555555) | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 	    || c4_poke(card, 0x400000, 0x66666666) | 
					
						
							| 
									
										
										
										
											2012-02-19 19:52:38 -08:00
										 |  |  | 	       || c4_poke(card, 0x800000, 0x77777777) | 
					
						
							|  |  |  | 	       || c4_poke(card, 0xC00000, 0x88888888)) | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 		return 25; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-02-19 19:52:38 -08:00
										 |  |  | 	if (c4_peek(card, 0x000000, &dummy) || dummy != 0x55555555 | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 	    || c4_peek(card, 0x400000, &dummy) || dummy != 0x66666666 | 
					
						
							| 
									
										
										
										
											2012-02-19 19:52:38 -08:00
										 |  |  | 	       || c4_peek(card, 0x800000, &dummy) || dummy != 0x77777777 | 
					
						
							|  |  |  | 	       || c4_peek(card, 0xC00000, &dummy) || dummy != 0x88888888) | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 		return 26; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return 0; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* ------------------------------------------------------------- */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static void c4_dispatch_tx(avmcard *card) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	avmcard_dmainfo *dma = card->dma; | 
					
						
							|  |  |  | 	struct sk_buff *skb; | 
					
						
							|  |  |  | 	u8 cmd, subcmd; | 
					
						
							|  |  |  | 	u16 len; | 
					
						
							|  |  |  | 	u32 txlen; | 
					
						
							|  |  |  | 	void *p; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (card->csr & DBELL_DOWN_ARM) { /* tx busy */ | 
					
						
							|  |  |  | 		return; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	skb = skb_dequeue(&dma->send_queue); | 
					
						
							|  |  |  | 	if (!skb) { | 
					
						
							| 
									
										
										
										
											2007-02-12 00:53:20 -08:00
										 |  |  | #ifdef AVM_C4_DEBUG
 | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 		printk(KERN_DEBUG "%s: tx underrun\n", card->name); | 
					
						
							|  |  |  | #endif
 | 
					
						
							|  |  |  | 		return; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	len = CAPIMSG_LEN(skb->data); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (len) { | 
					
						
							|  |  |  | 		cmd = CAPIMSG_COMMAND(skb->data); | 
					
						
							|  |  |  | 		subcmd = CAPIMSG_SUBCOMMAND(skb->data); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		p = dma->sendbuf.dmabuf; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		if (CAPICMD(cmd, subcmd) == CAPI_DATA_B3_REQ) { | 
					
						
							|  |  |  | 			u16 dlen = CAPIMSG_DATALEN(skb->data); | 
					
						
							|  |  |  | 			_put_byte(&p, SEND_DATA_B3_REQ); | 
					
						
							|  |  |  | 			_put_slice(&p, skb->data, len); | 
					
						
							|  |  |  | 			_put_slice(&p, skb->data + len, dlen); | 
					
						
							|  |  |  | 		} else { | 
					
						
							|  |  |  | 			_put_byte(&p, SEND_MESSAGE); | 
					
						
							|  |  |  | 			_put_slice(&p, skb->data, len); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		txlen = (u8 *)p - (u8 *)dma->sendbuf.dmabuf; | 
					
						
							| 
									
										
										
										
											2007-02-12 00:53:20 -08:00
										 |  |  | #ifdef AVM_C4_DEBUG
 | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 		printk(KERN_DEBUG "%s: tx put msg len=%d\n", card->name, txlen); | 
					
						
							|  |  |  | #endif
 | 
					
						
							|  |  |  | 	} else { | 
					
						
							| 
									
										
										
										
											2012-02-19 19:52:38 -08:00
										 |  |  | 		txlen = skb->len - 2; | 
					
						
							| 
									
										
										
										
											2007-02-12 00:53:20 -08:00
										 |  |  | #ifdef AVM_C4_POLLDEBUG
 | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 		if (skb->data[2] == SEND_POLLACK) | 
					
						
							|  |  |  | 			printk(KERN_INFO "%s: ack to c4\n", card->name); | 
					
						
							|  |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2007-02-12 00:53:20 -08:00
										 |  |  | #ifdef AVM_C4_DEBUG
 | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 		printk(KERN_DEBUG "%s: tx put 0x%x len=%d\n", | 
					
						
							| 
									
										
										
										
											2012-02-19 19:52:38 -08:00
										 |  |  | 		       card->name, skb->data[2], txlen); | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2007-03-27 18:55:52 -03:00
										 |  |  | 		skb_copy_from_linear_data_offset(skb, 2, dma->sendbuf.dmabuf, | 
					
						
							|  |  |  | 						 skb->len - 2); | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 	} | 
					
						
							|  |  |  | 	txlen = (txlen + 3) & ~3; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-02-19 19:52:38 -08:00
										 |  |  | 	c4outmeml(card->mbase + MBOX_DOWN_ADDR, dma->sendbuf.dmaaddr); | 
					
						
							|  |  |  | 	c4outmeml(card->mbase + MBOX_DOWN_LEN, txlen); | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	card->csr |= DBELL_DOWN_ARM; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-02-19 19:52:38 -08:00
										 |  |  | 	c4outmeml(card->mbase + DOORBELL, DBELL_DOWN_ARM); | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	dev_kfree_skb_any(skb); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* ------------------------------------------------------------- */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static void queue_pollack(avmcard *card) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	struct sk_buff *skb; | 
					
						
							|  |  |  | 	void *p; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	skb = alloc_skb(3, GFP_ATOMIC); | 
					
						
							|  |  |  | 	if (!skb) { | 
					
						
							|  |  |  | 		printk(KERN_CRIT "%s: no memory, lost poll ack\n", | 
					
						
							| 
									
										
										
										
											2012-02-19 19:52:38 -08:00
										 |  |  | 		       card->name); | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 		return; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	p = skb->data; | 
					
						
							|  |  |  | 	_put_byte(&p, 0); | 
					
						
							|  |  |  | 	_put_byte(&p, 0); | 
					
						
							|  |  |  | 	_put_byte(&p, SEND_POLLACK); | 
					
						
							|  |  |  | 	skb_put(skb, (u8 *)p - (u8 *)skb->data); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	skb_queue_tail(&card->dma->send_queue, skb); | 
					
						
							|  |  |  | 	c4_dispatch_tx(card); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* ------------------------------------------------------------- */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static void c4_handle_rx(avmcard *card) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	avmcard_dmainfo *dma = card->dma; | 
					
						
							|  |  |  | 	struct capi_ctr *ctrl; | 
					
						
							|  |  |  | 	avmctrl_info *cinfo; | 
					
						
							|  |  |  | 	struct sk_buff *skb; | 
					
						
							|  |  |  | 	void *p = dma->recvbuf.dmabuf; | 
					
						
							|  |  |  | 	u32 ApplId, MsgLen, DataB3Len, NCCI, WindowSize; | 
					
						
							|  |  |  | 	u8 b1cmd =  _get_byte(&p); | 
					
						
							|  |  |  | 	u32 cidx; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2007-02-12 00:53:20 -08:00
										 |  |  | #ifdef AVM_C4_DEBUG
 | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 	printk(KERN_DEBUG "%s: rx 0x%x len=%lu\n", card->name, | 
					
						
							| 
									
										
										
										
											2012-02-19 19:52:38 -08:00
										 |  |  | 	       b1cmd, (unsigned long)dma->recvlen); | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2012-02-19 19:52:38 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 	switch (b1cmd) { | 
					
						
							|  |  |  | 	case RECEIVE_DATA_B3_IND: | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		ApplId = (unsigned) _get_word(&p); | 
					
						
							|  |  |  | 		MsgLen = _get_slice(&p, card->msgbuf); | 
					
						
							|  |  |  | 		DataB3Len = _get_slice(&p, card->databuf); | 
					
						
							|  |  |  | 		cidx = CAPIMSG_CONTROLLER(card->msgbuf)-card->cardnr; | 
					
						
							|  |  |  | 		if (cidx >= card->nlogcontr) cidx = 0; | 
					
						
							|  |  |  | 		ctrl = &card->ctrlinfo[cidx].capi_ctrl; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		if (MsgLen < 30) { /* not CAPI 64Bit */ | 
					
						
							| 
									
										
										
										
											2012-02-19 19:52:38 -08:00
										 |  |  | 			memset(card->msgbuf + MsgLen, 0, 30 - MsgLen); | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 			MsgLen = 30; | 
					
						
							|  |  |  | 			CAPIMSG_SETLEN(card->msgbuf, 30); | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2012-02-19 19:52:38 -08:00
										 |  |  | 		if (!(skb = alloc_skb(DataB3Len + MsgLen, GFP_ATOMIC))) { | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 			printk(KERN_ERR "%s: incoming packet dropped\n", | 
					
						
							| 
									
										
										
										
											2012-02-19 19:52:38 -08:00
										 |  |  | 			       card->name); | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 		} else { | 
					
						
							|  |  |  | 			memcpy(skb_put(skb, MsgLen), card->msgbuf, MsgLen); | 
					
						
							|  |  |  | 			memcpy(skb_put(skb, DataB3Len), card->databuf, DataB3Len); | 
					
						
							|  |  |  | 			capi_ctr_handle_message(ctrl, ApplId, skb); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		break; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	case RECEIVE_MESSAGE: | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		ApplId = (unsigned) _get_word(&p); | 
					
						
							|  |  |  | 		MsgLen = _get_slice(&p, card->msgbuf); | 
					
						
							|  |  |  | 		cidx = CAPIMSG_CONTROLLER(card->msgbuf)-card->cardnr; | 
					
						
							|  |  |  | 		if (cidx >= card->nlogcontr) cidx = 0; | 
					
						
							|  |  |  | 		cinfo = &card->ctrlinfo[cidx]; | 
					
						
							|  |  |  | 		ctrl = &card->ctrlinfo[cidx].capi_ctrl; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		if (!(skb = alloc_skb(MsgLen, GFP_ATOMIC))) { | 
					
						
							|  |  |  | 			printk(KERN_ERR "%s: incoming packet dropped\n", | 
					
						
							| 
									
										
										
										
											2012-02-19 19:52:38 -08:00
										 |  |  | 			       card->name); | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 		} else { | 
					
						
							|  |  |  | 			memcpy(skb_put(skb, MsgLen), card->msgbuf, MsgLen); | 
					
						
							|  |  |  | 			if (CAPIMSG_CMD(skb->data) == CAPI_DATA_B3_CONF) | 
					
						
							|  |  |  | 				capilib_data_b3_conf(&cinfo->ncci_head, ApplId, | 
					
						
							|  |  |  | 						     CAPIMSG_NCCI(skb->data), | 
					
						
							|  |  |  | 						     CAPIMSG_MSGID(skb->data)); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			capi_ctr_handle_message(ctrl, ApplId, skb); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		break; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	case RECEIVE_NEW_NCCI: | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		ApplId = _get_word(&p); | 
					
						
							|  |  |  | 		NCCI = _get_word(&p); | 
					
						
							|  |  |  | 		WindowSize = _get_word(&p); | 
					
						
							| 
									
										
										
										
											2012-02-19 19:52:38 -08:00
										 |  |  | 		cidx = (NCCI & 0x7f) - card->cardnr; | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 		if (cidx >= card->nlogcontr) cidx = 0; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		capilib_new_ncci(&card->ctrlinfo[cidx].ncci_head, ApplId, NCCI, WindowSize); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		break; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	case RECEIVE_FREE_NCCI: | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		ApplId = _get_word(&p); | 
					
						
							|  |  |  | 		NCCI = _get_word(&p); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		if (NCCI != 0xffffffff) { | 
					
						
							| 
									
										
										
										
											2012-02-19 19:52:38 -08:00
										 |  |  | 			cidx = (NCCI & 0x7f) - card->cardnr; | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 			if (cidx >= card->nlogcontr) cidx = 0; | 
					
						
							|  |  |  | 			capilib_free_ncci(&card->ctrlinfo[cidx].ncci_head, ApplId, NCCI); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		break; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	case RECEIVE_START: | 
					
						
							| 
									
										
										
										
											2007-02-12 00:53:20 -08:00
										 |  |  | #ifdef AVM_C4_POLLDEBUG
 | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 		printk(KERN_INFO "%s: poll from c4\n", card->name); | 
					
						
							|  |  |  | #endif
 | 
					
						
							|  |  |  | 		if (!suppress_pollack) | 
					
						
							|  |  |  | 			queue_pollack(card); | 
					
						
							| 
									
										
										
										
											2012-02-19 19:52:38 -08:00
										 |  |  | 		for (cidx = 0; cidx < card->nr_controllers; cidx++) { | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 			ctrl = &card->ctrlinfo[cidx].capi_ctrl; | 
					
						
							|  |  |  | 			capi_ctr_resume_output(ctrl); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		break; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	case RECEIVE_STOP: | 
					
						
							| 
									
										
										
										
											2012-02-19 19:52:38 -08:00
										 |  |  | 		for (cidx = 0; cidx < card->nr_controllers; cidx++) { | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 			ctrl = &card->ctrlinfo[cidx].capi_ctrl; | 
					
						
							|  |  |  | 			capi_ctr_suspend_output(ctrl); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		break; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	case RECEIVE_INIT: | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-02-19 19:52:38 -08:00
										 |  |  | 		cidx = card->nlogcontr; | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 		if (cidx >= card->nr_controllers) { | 
					
						
							|  |  |  | 			printk(KERN_ERR "%s: card with %d controllers ??\n", | 
					
						
							| 
									
										
										
										
											2012-02-19 19:52:38 -08:00
										 |  |  | 			       card->name, cidx + 1); | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 			break; | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2012-02-19 19:52:38 -08:00
										 |  |  | 		card->nlogcontr++; | 
					
						
							|  |  |  | 		cinfo = &card->ctrlinfo[cidx]; | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 		ctrl = &cinfo->capi_ctrl; | 
					
						
							|  |  |  | 		cinfo->versionlen = _get_slice(&p, cinfo->versionbuf); | 
					
						
							|  |  |  | 		b1_parse_version(cinfo); | 
					
						
							|  |  |  | 		printk(KERN_INFO "%s: %s-card (%s) now active\n", | 
					
						
							|  |  |  | 		       card->name, | 
					
						
							|  |  |  | 		       cinfo->version[VER_CARDTYPE], | 
					
						
							|  |  |  | 		       cinfo->version[VER_DRIVER]); | 
					
						
							|  |  |  | 		capi_ctr_ready(&cinfo->capi_ctrl); | 
					
						
							|  |  |  | 		break; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	case RECEIVE_TASK_READY: | 
					
						
							|  |  |  | 		ApplId = (unsigned) _get_word(&p); | 
					
						
							|  |  |  | 		MsgLen = _get_slice(&p, card->msgbuf); | 
					
						
							|  |  |  | 		card->msgbuf[MsgLen] = 0; | 
					
						
							| 
									
										
										
										
											2012-02-19 19:52:38 -08:00
										 |  |  | 		while (MsgLen > 0 | 
					
						
							|  |  |  | 		       && (card->msgbuf[MsgLen - 1] == '\n' | 
					
						
							|  |  |  | 			   || card->msgbuf[MsgLen - 1] == '\r')) { | 
					
						
							|  |  |  | 			card->msgbuf[MsgLen - 1] = 0; | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 			MsgLen--; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		printk(KERN_INFO "%s: task %d \"%s\" ready.\n", | 
					
						
							| 
									
										
										
										
											2012-02-19 19:52:38 -08:00
										 |  |  | 		       card->name, ApplId, card->msgbuf); | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 		break; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	case RECEIVE_DEBUGMSG: | 
					
						
							|  |  |  | 		MsgLen = _get_slice(&p, card->msgbuf); | 
					
						
							|  |  |  | 		card->msgbuf[MsgLen] = 0; | 
					
						
							| 
									
										
										
										
											2012-02-19 19:52:38 -08:00
										 |  |  | 		while (MsgLen > 0 | 
					
						
							|  |  |  | 		       && (card->msgbuf[MsgLen - 1] == '\n' | 
					
						
							|  |  |  | 			   || card->msgbuf[MsgLen - 1] == '\r')) { | 
					
						
							|  |  |  | 			card->msgbuf[MsgLen - 1] = 0; | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 			MsgLen--; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		printk(KERN_INFO "%s: DEBUG: %s\n", card->name, card->msgbuf); | 
					
						
							|  |  |  | 		break; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	default: | 
					
						
							|  |  |  | 		printk(KERN_ERR "%s: c4_interrupt: 0x%x ???\n", | 
					
						
							| 
									
										
										
										
											2012-02-19 19:52:38 -08:00
										 |  |  | 		       card->name, b1cmd); | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 		return; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* ------------------------------------------------------------- */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static irqreturn_t c4_handle_interrupt(avmcard *card) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	unsigned long flags; | 
					
						
							|  |  |  | 	u32 status; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	spin_lock_irqsave(&card->lock, flags); | 
					
						
							| 
									
										
										
										
											2012-02-19 19:52:38 -08:00
										 |  |  | 	status = c4inmeml(card->mbase + DOORBELL); | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	if (status & DBELL_RESET_HOST) { | 
					
						
							|  |  |  | 		u_int i; | 
					
						
							| 
									
										
										
										
											2012-02-19 19:52:38 -08:00
										 |  |  | 		c4outmeml(card->mbase + PCI_OUT_INT_MASK, 0x0c); | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 		spin_unlock_irqrestore(&card->lock, flags); | 
					
						
							|  |  |  | 		if (card->nlogcontr == 0) | 
					
						
							|  |  |  | 			return IRQ_HANDLED; | 
					
						
							|  |  |  | 		printk(KERN_ERR "%s: unexpected reset\n", card->name); | 
					
						
							| 
									
										
										
										
											2012-02-19 19:52:38 -08:00
										 |  |  | 		for (i = 0; i < card->nr_controllers; i++) { | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 			avmctrl_info *cinfo = &card->ctrlinfo[i]; | 
					
						
							|  |  |  | 			memset(cinfo->version, 0, sizeof(cinfo->version)); | 
					
						
							| 
									
										
										
										
											2007-10-18 23:39:18 -07:00
										 |  |  | 			spin_lock_irqsave(&card->lock, flags); | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 			capilib_release(&cinfo->ncci_head); | 
					
						
							| 
									
										
										
										
											2007-10-18 23:39:18 -07:00
										 |  |  | 			spin_unlock_irqrestore(&card->lock, flags); | 
					
						
							| 
									
										
										
										
											2009-06-07 09:09:23 +00:00
										 |  |  | 			capi_ctr_down(&cinfo->capi_ctrl); | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 		} | 
					
						
							|  |  |  | 		card->nlogcontr = 0; | 
					
						
							|  |  |  | 		return IRQ_HANDLED; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	status &= (DBELL_UP_HOST | DBELL_DOWN_HOST); | 
					
						
							|  |  |  | 	if (!status) { | 
					
						
							|  |  |  | 		spin_unlock_irqrestore(&card->lock, flags); | 
					
						
							|  |  |  | 		return IRQ_HANDLED; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2012-02-19 19:52:38 -08:00
										 |  |  | 	c4outmeml(card->mbase + DOORBELL, status); | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	if ((status & DBELL_UP_HOST) != 0) { | 
					
						
							| 
									
										
										
										
											2012-02-19 19:52:38 -08:00
										 |  |  | 		card->dma->recvlen = c4inmeml(card->mbase + MBOX_UP_LEN); | 
					
						
							|  |  |  | 		c4outmeml(card->mbase + MBOX_UP_LEN, 0); | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 		c4_handle_rx(card); | 
					
						
							|  |  |  | 		card->dma->recvlen = 0; | 
					
						
							| 
									
										
										
										
											2012-02-19 19:52:38 -08:00
										 |  |  | 		c4outmeml(card->mbase + MBOX_UP_LEN, card->dma->recvbuf.size); | 
					
						
							|  |  |  | 		c4outmeml(card->mbase + DOORBELL, DBELL_UP_ARM); | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if ((status & DBELL_DOWN_HOST) != 0) { | 
					
						
							|  |  |  | 		card->csr &= ~DBELL_DOWN_ARM; | 
					
						
							| 
									
										
										
										
											2012-02-19 19:52:38 -08:00
										 |  |  | 		c4_dispatch_tx(card); | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 	} else if (card->csr & DBELL_DOWN_HOST) { | 
					
						
							| 
									
										
										
										
											2012-02-19 19:52:38 -08:00
										 |  |  | 		if (c4inmeml(card->mbase + MBOX_DOWN_LEN) == 0) { | 
					
						
							|  |  |  | 			card->csr &= ~DBELL_DOWN_ARM; | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 			c4_dispatch_tx(card); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	spin_unlock_irqrestore(&card->lock, flags); | 
					
						
							|  |  |  | 	return IRQ_HANDLED; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
											  
											
												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 14:55:46 +01:00
										 |  |  | static irqreturn_t c4_interrupt(int interrupt, void *devptr) | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | { | 
					
						
							|  |  |  | 	avmcard *card = devptr; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return c4_handle_interrupt(card); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* ------------------------------------------------------------- */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static void c4_send_init(avmcard *card) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	struct sk_buff *skb; | 
					
						
							|  |  |  | 	void *p; | 
					
						
							| 
									
										
										
										
											2007-10-18 03:04:32 -07:00
										 |  |  | 	unsigned long flags; | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	skb = alloc_skb(15, GFP_ATOMIC); | 
					
						
							|  |  |  | 	if (!skb) { | 
					
						
							|  |  |  | 		printk(KERN_CRIT "%s: no memory, lost register appl.\n", | 
					
						
							| 
									
										
										
										
											2012-02-19 19:52:38 -08:00
										 |  |  | 		       card->name); | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 		return; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	p = skb->data; | 
					
						
							|  |  |  | 	_put_byte(&p, 0); | 
					
						
							|  |  |  | 	_put_byte(&p, 0); | 
					
						
							|  |  |  | 	_put_byte(&p, SEND_INIT); | 
					
						
							|  |  |  | 	_put_word(&p, CAPI_MAXAPPL); | 
					
						
							| 
									
										
										
										
											2012-02-19 19:52:38 -08:00
										 |  |  | 	_put_word(&p, AVM_NCCI_PER_CHANNEL * 30); | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 	_put_word(&p, card->cardnr - 1); | 
					
						
							|  |  |  | 	skb_put(skb, (u8 *)p - (u8 *)skb->data); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	skb_queue_tail(&card->dma->send_queue, skb); | 
					
						
							| 
									
										
										
										
											2007-10-18 03:04:32 -07:00
										 |  |  | 	spin_lock_irqsave(&card->lock, flags); | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 	c4_dispatch_tx(card); | 
					
						
							| 
									
										
										
										
											2007-10-18 03:04:32 -07:00
										 |  |  | 	spin_unlock_irqrestore(&card->lock, flags); | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static int queue_sendconfigword(avmcard *card, u32 val) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	struct sk_buff *skb; | 
					
						
							| 
									
										
										
										
											2007-10-18 03:04:32 -07:00
										 |  |  | 	unsigned long flags; | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 	void *p; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-02-19 19:52:38 -08:00
										 |  |  | 	skb = alloc_skb(3 + 4, GFP_ATOMIC); | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 	if (!skb) { | 
					
						
							|  |  |  | 		printk(KERN_CRIT "%s: no memory, send config\n", | 
					
						
							| 
									
										
										
										
											2012-02-19 19:52:38 -08:00
										 |  |  | 		       card->name); | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 		return -ENOMEM; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	p = skb->data; | 
					
						
							|  |  |  | 	_put_byte(&p, 0); | 
					
						
							|  |  |  | 	_put_byte(&p, 0); | 
					
						
							|  |  |  | 	_put_byte(&p, SEND_CONFIG); | 
					
						
							|  |  |  | 	_put_word(&p, val); | 
					
						
							|  |  |  | 	skb_put(skb, (u8 *)p - (u8 *)skb->data); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	skb_queue_tail(&card->dma->send_queue, skb); | 
					
						
							| 
									
										
										
										
											2007-10-18 03:04:32 -07:00
										 |  |  | 	spin_lock_irqsave(&card->lock, flags); | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 	c4_dispatch_tx(card); | 
					
						
							| 
									
										
										
										
											2007-10-18 03:04:32 -07:00
										 |  |  | 	spin_unlock_irqrestore(&card->lock, flags); | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 	return 0; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static int queue_sendconfig(avmcard *card, char cval[4]) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	struct sk_buff *skb; | 
					
						
							|  |  |  | 	unsigned long flags; | 
					
						
							|  |  |  | 	void *p; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-02-19 19:52:38 -08:00
										 |  |  | 	skb = alloc_skb(3 + 4, GFP_ATOMIC); | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 	if (!skb) { | 
					
						
							|  |  |  | 		printk(KERN_CRIT "%s: no memory, send config\n", | 
					
						
							| 
									
										
										
										
											2012-02-19 19:52:38 -08:00
										 |  |  | 		       card->name); | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 		return -ENOMEM; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	p = skb->data; | 
					
						
							|  |  |  | 	_put_byte(&p, 0); | 
					
						
							|  |  |  | 	_put_byte(&p, 0); | 
					
						
							|  |  |  | 	_put_byte(&p, SEND_CONFIG); | 
					
						
							|  |  |  | 	_put_byte(&p, cval[0]); | 
					
						
							|  |  |  | 	_put_byte(&p, cval[1]); | 
					
						
							|  |  |  | 	_put_byte(&p, cval[2]); | 
					
						
							|  |  |  | 	_put_byte(&p, cval[3]); | 
					
						
							|  |  |  | 	skb_put(skb, (u8 *)p - (u8 *)skb->data); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	skb_queue_tail(&card->dma->send_queue, skb); | 
					
						
							| 
									
										
										
										
											2012-02-19 19:52:38 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 	spin_lock_irqsave(&card->lock, flags); | 
					
						
							|  |  |  | 	c4_dispatch_tx(card); | 
					
						
							|  |  |  | 	spin_unlock_irqrestore(&card->lock, flags); | 
					
						
							|  |  |  | 	return 0; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-02-19 19:52:38 -08:00
										 |  |  | static int c4_send_config(avmcard *card, capiloaddatapart *config) | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | { | 
					
						
							|  |  |  | 	u8 val[4]; | 
					
						
							|  |  |  | 	unsigned char *dp; | 
					
						
							|  |  |  | 	u_int left; | 
					
						
							|  |  |  | 	int retval; | 
					
						
							| 
									
										
										
										
											2012-02-19 19:52:38 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 	if ((retval = queue_sendconfigword(card, 1)) != 0) | 
					
						
							|  |  |  | 		return retval; | 
					
						
							|  |  |  | 	if ((retval = queue_sendconfigword(card, config->len)) != 0) | 
					
						
							|  |  |  | 		return retval; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	dp = config->data; | 
					
						
							|  |  |  | 	left = config->len; | 
					
						
							|  |  |  | 	while (left >= sizeof(u32)) { | 
					
						
							| 
									
										
										
										
											2012-02-19 19:52:38 -08:00
										 |  |  | 		if (config->user) { | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 			if (copy_from_user(val, dp, sizeof(val))) | 
					
						
							|  |  |  | 				return -EFAULT; | 
					
						
							|  |  |  | 		} else { | 
					
						
							|  |  |  | 			memcpy(val, dp, sizeof(val)); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		if ((retval = queue_sendconfig(card, val)) != 0) | 
					
						
							|  |  |  | 			return retval; | 
					
						
							|  |  |  | 		left -= sizeof(val); | 
					
						
							|  |  |  | 		dp += sizeof(val); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	if (left) { | 
					
						
							|  |  |  | 		memset(val, 0, sizeof(val)); | 
					
						
							|  |  |  | 		if (config->user) { | 
					
						
							|  |  |  | 			if (copy_from_user(&val, dp, left)) | 
					
						
							|  |  |  | 				return -EFAULT; | 
					
						
							|  |  |  | 		} else { | 
					
						
							|  |  |  | 			memcpy(&val, dp, left); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		if ((retval = queue_sendconfig(card, val)) != 0) | 
					
						
							|  |  |  | 			return retval; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return 0; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static int c4_load_firmware(struct capi_ctr *ctrl, capiloaddata *data) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	avmctrl_info *cinfo = (avmctrl_info *)(ctrl->driverdata); | 
					
						
							|  |  |  | 	avmcard *card = cinfo->card; | 
					
						
							|  |  |  | 	int retval; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if ((retval = c4_load_t4file(card, &data->firmware))) { | 
					
						
							|  |  |  | 		printk(KERN_ERR "%s: failed to load t4file!!\n", | 
					
						
							| 
									
										
										
										
											2012-02-19 19:52:38 -08:00
										 |  |  | 		       card->name); | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 		c4_reset(card); | 
					
						
							|  |  |  | 		return retval; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	card->csr = 0; | 
					
						
							| 
									
										
										
										
											2012-02-19 19:52:38 -08:00
										 |  |  | 	c4outmeml(card->mbase + MBOX_UP_LEN, 0); | 
					
						
							|  |  |  | 	c4outmeml(card->mbase + MBOX_DOWN_LEN, 0); | 
					
						
							|  |  |  | 	c4outmeml(card->mbase + DOORBELL, DBELL_INIT); | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 	mdelay(1); | 
					
						
							| 
									
										
										
										
											2012-02-19 19:52:38 -08:00
										 |  |  | 	c4outmeml(card->mbase + DOORBELL, | 
					
						
							|  |  |  | 		  DBELL_UP_HOST | DBELL_DOWN_HOST | DBELL_RESET_HOST); | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-02-19 19:52:38 -08:00
										 |  |  | 	c4outmeml(card->mbase + PCI_OUT_INT_MASK, 0x08); | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	card->dma->recvlen = 0; | 
					
						
							| 
									
										
										
										
											2012-02-19 19:52:38 -08:00
										 |  |  | 	c4outmeml(card->mbase + MBOX_UP_ADDR, card->dma->recvbuf.dmaaddr); | 
					
						
							|  |  |  | 	c4outmeml(card->mbase + MBOX_UP_LEN, card->dma->recvbuf.size); | 
					
						
							|  |  |  | 	c4outmeml(card->mbase + DOORBELL, DBELL_UP_ARM); | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	if (data->configuration.len > 0 && data->configuration.data) { | 
					
						
							|  |  |  | 		retval = c4_send_config(card, &data->configuration); | 
					
						
							|  |  |  | 		if (retval) { | 
					
						
							|  |  |  | 			printk(KERN_ERR "%s: failed to set config!!\n", | 
					
						
							| 
									
										
										
										
											2012-02-19 19:52:38 -08:00
										 |  |  | 			       card->name); | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 			c4_reset(card); | 
					
						
							|  |  |  | 			return retval; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-02-19 19:52:38 -08:00
										 |  |  | 	c4_send_init(card); | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	return 0; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-06-25 14:58:37 -07:00
										 |  |  | static void c4_reset_ctr(struct capi_ctr *ctrl) | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | { | 
					
						
							|  |  |  | 	avmcard *card = ((avmctrl_info *)(ctrl->driverdata))->card; | 
					
						
							|  |  |  | 	avmctrl_info *cinfo; | 
					
						
							|  |  |  | 	u_int i; | 
					
						
							|  |  |  | 	unsigned long flags; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	spin_lock_irqsave(&card->lock, flags); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-02-19 19:52:38 -08:00
										 |  |  | 	c4_reset(card); | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	spin_unlock_irqrestore(&card->lock, flags); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-02-19 19:52:38 -08:00
										 |  |  | 	for (i = 0; i < card->nr_controllers; i++) { | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 		cinfo = &card->ctrlinfo[i]; | 
					
						
							|  |  |  | 		memset(cinfo->version, 0, sizeof(cinfo->version)); | 
					
						
							| 
									
										
										
										
											2009-06-07 09:09:23 +00:00
										 |  |  | 		capi_ctr_down(&cinfo->capi_ctrl); | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 	} | 
					
						
							|  |  |  | 	card->nlogcontr = 0; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static void c4_remove(struct pci_dev *pdev) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	avmcard *card = pci_get_drvdata(pdev); | 
					
						
							|  |  |  | 	avmctrl_info *cinfo; | 
					
						
							|  |  |  | 	u_int i; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (!card) | 
					
						
							|  |  |  | 		return; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-02-19 19:52:38 -08:00
										 |  |  | 	c4_reset(card); | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-02-19 19:52:38 -08:00
										 |  |  | 	for (i = 0; i < card->nr_controllers; i++) { | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 		cinfo = &card->ctrlinfo[i]; | 
					
						
							|  |  |  | 		detach_capi_ctr(&cinfo->capi_ctrl); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	free_irq(card->irq, card); | 
					
						
							|  |  |  | 	iounmap(card->mbase); | 
					
						
							|  |  |  | 	release_region(card->port, AVMB1_PORTLEN); | 
					
						
							| 
									
										
										
										
											2012-02-19 19:52:38 -08:00
										 |  |  | 	avmcard_dma_free(card->dma); | 
					
						
							|  |  |  | 	pci_set_drvdata(pdev, NULL); | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 	b1_free_card(card); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* ------------------------------------------------------------- */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-06-25 14:58:37 -07:00
										 |  |  | static void c4_register_appl(struct capi_ctr *ctrl, | 
					
						
							| 
									
										
										
										
											2012-02-19 19:52:38 -08:00
										 |  |  | 			     u16 appl, | 
					
						
							|  |  |  | 			     capi_register_params *rp) | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | { | 
					
						
							|  |  |  | 	avmctrl_info *cinfo = (avmctrl_info *)(ctrl->driverdata); | 
					
						
							|  |  |  | 	avmcard *card = cinfo->card; | 
					
						
							|  |  |  | 	struct sk_buff *skb; | 
					
						
							|  |  |  | 	int want = rp->level3cnt; | 
					
						
							|  |  |  | 	unsigned long flags; | 
					
						
							|  |  |  | 	int nconn; | 
					
						
							|  |  |  | 	void *p; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (ctrl->cnr == card->cardnr) { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		if (want > 0) nconn = want; | 
					
						
							|  |  |  | 		else nconn = ctrl->profile.nbchannel * 4 * -want; | 
					
						
							|  |  |  | 		if (nconn == 0) nconn = ctrl->profile.nbchannel * 4; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		skb = alloc_skb(23, GFP_ATOMIC); | 
					
						
							|  |  |  | 		if (!skb) { | 
					
						
							|  |  |  | 			printk(KERN_CRIT "%s: no memory, lost register appl.\n", | 
					
						
							| 
									
										
										
										
											2012-02-19 19:52:38 -08:00
										 |  |  | 			       card->name); | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 			return; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		p = skb->data; | 
					
						
							|  |  |  | 		_put_byte(&p, 0); | 
					
						
							|  |  |  | 		_put_byte(&p, 0); | 
					
						
							|  |  |  | 		_put_byte(&p, SEND_REGISTER); | 
					
						
							|  |  |  | 		_put_word(&p, appl); | 
					
						
							| 
									
										
										
										
											2012-02-19 19:52:38 -08:00
										 |  |  | 		_put_word(&p, 1024 * (nconn + 1)); | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 		_put_word(&p, nconn); | 
					
						
							|  |  |  | 		_put_word(&p, rp->datablkcnt); | 
					
						
							|  |  |  | 		_put_word(&p, rp->datablklen); | 
					
						
							|  |  |  | 		skb_put(skb, (u8 *)p - (u8 *)skb->data); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		skb_queue_tail(&card->dma->send_queue, skb); | 
					
						
							| 
									
										
										
										
											2012-02-19 19:52:38 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 		spin_lock_irqsave(&card->lock, flags); | 
					
						
							|  |  |  | 		c4_dispatch_tx(card); | 
					
						
							|  |  |  | 		spin_unlock_irqrestore(&card->lock, flags); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* ------------------------------------------------------------- */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-06-25 14:58:37 -07:00
										 |  |  | static void c4_release_appl(struct capi_ctr *ctrl, u16 appl) | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | { | 
					
						
							|  |  |  | 	avmctrl_info *cinfo = (avmctrl_info *)(ctrl->driverdata); | 
					
						
							|  |  |  | 	avmcard *card = cinfo->card; | 
					
						
							|  |  |  | 	unsigned long flags; | 
					
						
							|  |  |  | 	struct sk_buff *skb; | 
					
						
							|  |  |  | 	void *p; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2007-10-18 03:04:32 -07:00
										 |  |  | 	spin_lock_irqsave(&card->lock, flags); | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 	capilib_release_appl(&cinfo->ncci_head, appl); | 
					
						
							| 
									
										
										
										
											2007-10-18 03:04:32 -07:00
										 |  |  | 	spin_unlock_irqrestore(&card->lock, flags); | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	if (ctrl->cnr == card->cardnr) { | 
					
						
							|  |  |  | 		skb = alloc_skb(7, GFP_ATOMIC); | 
					
						
							|  |  |  | 		if (!skb) { | 
					
						
							|  |  |  | 			printk(KERN_CRIT "%s: no memory, lost release appl.\n", | 
					
						
							| 
									
										
										
										
											2012-02-19 19:52:38 -08:00
										 |  |  | 			       card->name); | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 			return; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		p = skb->data; | 
					
						
							|  |  |  | 		_put_byte(&p, 0); | 
					
						
							|  |  |  | 		_put_byte(&p, 0); | 
					
						
							|  |  |  | 		_put_byte(&p, SEND_RELEASE); | 
					
						
							|  |  |  | 		_put_word(&p, appl); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		skb_put(skb, (u8 *)p - (u8 *)skb->data); | 
					
						
							|  |  |  | 		skb_queue_tail(&card->dma->send_queue, skb); | 
					
						
							|  |  |  | 		spin_lock_irqsave(&card->lock, flags); | 
					
						
							|  |  |  | 		c4_dispatch_tx(card); | 
					
						
							|  |  |  | 		spin_unlock_irqrestore(&card->lock, flags); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* ------------------------------------------------------------- */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static u16 c4_send_message(struct capi_ctr *ctrl, struct sk_buff *skb) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	avmctrl_info *cinfo = (avmctrl_info *)(ctrl->driverdata); | 
					
						
							|  |  |  | 	avmcard *card = cinfo->card; | 
					
						
							|  |  |  | 	u16 retval = CAPI_NOERROR; | 
					
						
							|  |  |  | 	unsigned long flags; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2007-10-18 03:04:32 -07:00
										 |  |  | 	spin_lock_irqsave(&card->lock, flags); | 
					
						
							|  |  |  | 	if (CAPIMSG_CMD(skb->data) == CAPI_DATA_B3_REQ) { | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 		retval = capilib_data_b3_req(&cinfo->ncci_head, | 
					
						
							|  |  |  | 					     CAPIMSG_APPID(skb->data), | 
					
						
							|  |  |  | 					     CAPIMSG_NCCI(skb->data), | 
					
						
							|  |  |  | 					     CAPIMSG_MSGID(skb->data)); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	if (retval == CAPI_NOERROR) { | 
					
						
							|  |  |  | 		skb_queue_tail(&card->dma->send_queue, skb); | 
					
						
							|  |  |  | 		c4_dispatch_tx(card); | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2007-10-18 03:04:32 -07:00
										 |  |  | 	spin_unlock_irqrestore(&card->lock, flags); | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 	return retval; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* ------------------------------------------------------------- */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static char *c4_procinfo(struct capi_ctr *ctrl) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	avmctrl_info *cinfo = (avmctrl_info *)(ctrl->driverdata); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (!cinfo) | 
					
						
							|  |  |  | 		return ""; | 
					
						
							|  |  |  | 	sprintf(cinfo->infobuf, "%s %s 0x%x %d 0x%lx", | 
					
						
							|  |  |  | 		cinfo->cardname[0] ? cinfo->cardname : "-", | 
					
						
							|  |  |  | 		cinfo->version[VER_DRIVER] ? cinfo->version[VER_DRIVER] : "-", | 
					
						
							|  |  |  | 		cinfo->card ? cinfo->card->port : 0x0, | 
					
						
							|  |  |  | 		cinfo->card ? cinfo->card->irq : 0, | 
					
						
							|  |  |  | 		cinfo->card ? cinfo->card->membase : 0 | 
					
						
							|  |  |  | 		); | 
					
						
							|  |  |  | 	return cinfo->infobuf; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-01-14 03:10:54 -08:00
										 |  |  | static int c4_proc_show(struct seq_file *m, void *v) | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2010-01-14 03:10:54 -08:00
										 |  |  | 	struct capi_ctr *ctrl = m->private; | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 	avmctrl_info *cinfo = (avmctrl_info *)(ctrl->driverdata); | 
					
						
							|  |  |  | 	avmcard *card = cinfo->card; | 
					
						
							|  |  |  | 	u8 flag; | 
					
						
							|  |  |  | 	char *s; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-01-14 03:10:54 -08:00
										 |  |  | 	seq_printf(m, "%-16s %s\n", "name", card->name); | 
					
						
							|  |  |  | 	seq_printf(m, "%-16s 0x%x\n", "io", card->port); | 
					
						
							|  |  |  | 	seq_printf(m, "%-16s %d\n", "irq", card->irq); | 
					
						
							|  |  |  | 	seq_printf(m, "%-16s 0x%lx\n", "membase", card->membase); | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 	switch (card->cardtype) { | 
					
						
							|  |  |  | 	case avm_b1isa: s = "B1 ISA"; break; | 
					
						
							|  |  |  | 	case avm_b1pci: s = "B1 PCI"; break; | 
					
						
							|  |  |  | 	case avm_b1pcmcia: s = "B1 PCMCIA"; break; | 
					
						
							|  |  |  | 	case avm_m1: s = "M1"; break; | 
					
						
							|  |  |  | 	case avm_m2: s = "M2"; break; | 
					
						
							|  |  |  | 	case avm_t1isa: s = "T1 ISA (HEMA)"; break; | 
					
						
							|  |  |  | 	case avm_t1pci: s = "T1 PCI"; break; | 
					
						
							|  |  |  | 	case avm_c4: s = "C4"; break; | 
					
						
							|  |  |  | 	case avm_c2: s = "C2"; break; | 
					
						
							|  |  |  | 	default: s = "???"; break; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2010-01-14 03:10:54 -08:00
										 |  |  | 	seq_printf(m, "%-16s %s\n", "type", s); | 
					
						
							| 
									
										
										
										
											2008-04-28 02:14:38 -07:00
										 |  |  | 	if ((s = cinfo->version[VER_DRIVER]) != NULL) | 
					
						
							| 
									
										
										
										
											2010-01-14 03:10:54 -08:00
										 |  |  | 		seq_printf(m, "%-16s %s\n", "ver_driver", s); | 
					
						
							| 
									
										
										
										
											2008-04-28 02:14:38 -07:00
										 |  |  | 	if ((s = cinfo->version[VER_CARDTYPE]) != NULL) | 
					
						
							| 
									
										
										
										
											2010-01-14 03:10:54 -08:00
										 |  |  | 		seq_printf(m, "%-16s %s\n", "ver_cardtype", s); | 
					
						
							| 
									
										
										
										
											2008-04-28 02:14:38 -07:00
										 |  |  | 	if ((s = cinfo->version[VER_SERIAL]) != NULL) | 
					
						
							| 
									
										
										
										
											2010-01-14 03:10:54 -08:00
										 |  |  | 		seq_printf(m, "%-16s %s\n", "ver_serial", s); | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	if (card->cardtype != avm_m1) { | 
					
						
							| 
									
										
										
										
											2012-02-19 19:52:38 -08:00
										 |  |  | 		flag = ((u8 *)(ctrl->profile.manu))[3]; | 
					
						
							|  |  |  | 		if (flag) | 
					
						
							| 
									
										
										
										
											2010-01-14 03:10:54 -08:00
										 |  |  | 			seq_printf(m, "%-16s%s%s%s%s%s%s%s\n", | 
					
						
							| 
									
										
										
										
											2012-02-19 19:52:38 -08:00
										 |  |  | 				   "protocol", | 
					
						
							|  |  |  | 				   (flag & 0x01) ? " DSS1" : "", | 
					
						
							|  |  |  | 				   (flag & 0x02) ? " CT1" : "", | 
					
						
							|  |  |  | 				   (flag & 0x04) ? " VN3" : "", | 
					
						
							|  |  |  | 				   (flag & 0x08) ? " NI1" : "", | 
					
						
							|  |  |  | 				   (flag & 0x10) ? " AUSTEL" : "", | 
					
						
							|  |  |  | 				   (flag & 0x20) ? " ESS" : "", | 
					
						
							|  |  |  | 				   (flag & 0x40) ? " 1TR6" : "" | 
					
						
							|  |  |  | 				); | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 	} | 
					
						
							|  |  |  | 	if (card->cardtype != avm_m1) { | 
					
						
							| 
									
										
										
										
											2012-02-19 19:52:38 -08:00
										 |  |  | 		flag = ((u8 *)(ctrl->profile.manu))[5]; | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 		if (flag) | 
					
						
							| 
									
										
										
										
											2010-01-14 03:10:54 -08:00
										 |  |  | 			seq_printf(m, "%-16s%s%s%s%s\n", | 
					
						
							| 
									
										
										
										
											2012-02-19 19:52:38 -08:00
										 |  |  | 				   "linetype", | 
					
						
							|  |  |  | 				   (flag & 0x01) ? " point to point" : "", | 
					
						
							|  |  |  | 				   (flag & 0x02) ? " point to multipoint" : "", | 
					
						
							|  |  |  | 				   (flag & 0x08) ? " leased line without D-channel" : "", | 
					
						
							|  |  |  | 				   (flag & 0x04) ? " leased line with D-channel" : "" | 
					
						
							|  |  |  | 				); | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2010-01-14 03:10:54 -08:00
										 |  |  | 	seq_printf(m, "%-16s %s\n", "cardname", cinfo->cardname); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return 0; | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-01-14 03:10:54 -08:00
										 |  |  | static int c4_proc_open(struct inode *inode, struct file *file) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2013-03-31 18:16:14 -04:00
										 |  |  | 	return single_open(file, c4_proc_show, PDE_DATA(inode)); | 
					
						
							| 
									
										
										
										
											2010-01-14 03:10:54 -08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static const struct file_operations c4_proc_fops = { | 
					
						
							|  |  |  | 	.owner		= THIS_MODULE, | 
					
						
							|  |  |  | 	.open		= c4_proc_open, | 
					
						
							|  |  |  | 	.read		= seq_read, | 
					
						
							|  |  |  | 	.llseek		= seq_lseek, | 
					
						
							|  |  |  | 	.release	= single_release, | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | /* ------------------------------------------------------------- */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static int c4_add_card(struct capicardparams *p, struct pci_dev *dev, | 
					
						
							|  |  |  | 		       int nr_controllers) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	avmcard *card; | 
					
						
							|  |  |  | 	avmctrl_info *cinfo; | 
					
						
							|  |  |  | 	int retval; | 
					
						
							|  |  |  | 	int i; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	card = b1_alloc_card(nr_controllers); | 
					
						
							|  |  |  | 	if (!card) { | 
					
						
							|  |  |  | 		printk(KERN_WARNING "c4: no memory.\n"); | 
					
						
							|  |  |  | 		retval = -ENOMEM; | 
					
						
							|  |  |  | 		goto err; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2012-02-19 19:52:38 -08:00
										 |  |  | 	card->dma = avmcard_dma_alloc("c4", dev, 2048 + 128, 2048 + 128); | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 	if (!card->dma) { | 
					
						
							|  |  |  | 		printk(KERN_WARNING "c4: no memory.\n"); | 
					
						
							|  |  |  | 		retval = -ENOMEM; | 
					
						
							|  |  |  | 		goto err_free; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	sprintf(card->name, "c%d-%x", nr_controllers, p->port); | 
					
						
							|  |  |  | 	card->port = p->port; | 
					
						
							|  |  |  | 	card->irq = p->irq; | 
					
						
							|  |  |  | 	card->membase = p->membase; | 
					
						
							|  |  |  | 	card->cardtype = (nr_controllers == 4) ? avm_c4 : avm_c2; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (!request_region(card->port, AVMB1_PORTLEN, card->name)) { | 
					
						
							|  |  |  | 		printk(KERN_WARNING "c4: ports 0x%03x-0x%03x in use.\n", | 
					
						
							|  |  |  | 		       card->port, card->port + AVMB1_PORTLEN); | 
					
						
							|  |  |  | 		retval = -EBUSY; | 
					
						
							|  |  |  | 		goto err_free_dma; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	card->mbase = ioremap(card->membase, 128); | 
					
						
							| 
									
										
										
										
											2008-04-28 02:14:38 -07:00
										 |  |  | 	if (card->mbase == NULL) { | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 		printk(KERN_NOTICE "c4: can't remap memory at 0x%lx\n", | 
					
						
							|  |  |  | 		       card->membase); | 
					
						
							|  |  |  | 		retval = -EIO; | 
					
						
							|  |  |  | 		goto err_release_region; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	retval = c4_detect(card); | 
					
						
							|  |  |  | 	if (retval != 0) { | 
					
						
							|  |  |  | 		printk(KERN_NOTICE "c4: NO card at 0x%x error(%d)\n", | 
					
						
							|  |  |  | 		       card->port, retval); | 
					
						
							|  |  |  | 		retval = -EIO; | 
					
						
							|  |  |  | 		goto err_unmap; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	c4_reset(card); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-07-01 19:29:36 -07:00
										 |  |  | 	retval = request_irq(card->irq, c4_interrupt, IRQF_SHARED, card->name, card); | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 	if (retval) { | 
					
						
							| 
									
										
										
										
											2012-02-19 19:52:38 -08:00
										 |  |  | 		printk(KERN_ERR "c4: unable to get IRQ %d.\n", card->irq); | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 		retval = -EBUSY; | 
					
						
							|  |  |  | 		goto err_unmap; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-02-19 19:52:38 -08:00
										 |  |  | 	for (i = 0; i < nr_controllers; i++) { | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 		cinfo = &card->ctrlinfo[i]; | 
					
						
							|  |  |  | 		cinfo->capi_ctrl.owner = THIS_MODULE; | 
					
						
							|  |  |  | 		cinfo->capi_ctrl.driver_name   = "c4"; | 
					
						
							|  |  |  | 		cinfo->capi_ctrl.driverdata    = cinfo; | 
					
						
							|  |  |  | 		cinfo->capi_ctrl.register_appl = c4_register_appl; | 
					
						
							|  |  |  | 		cinfo->capi_ctrl.release_appl  = c4_release_appl; | 
					
						
							|  |  |  | 		cinfo->capi_ctrl.send_message  = c4_send_message; | 
					
						
							|  |  |  | 		cinfo->capi_ctrl.load_firmware = c4_load_firmware; | 
					
						
							|  |  |  | 		cinfo->capi_ctrl.reset_ctr     = c4_reset_ctr; | 
					
						
							|  |  |  | 		cinfo->capi_ctrl.procinfo      = c4_procinfo; | 
					
						
							| 
									
										
										
										
											2010-01-14 03:10:54 -08:00
										 |  |  | 		cinfo->capi_ctrl.proc_fops = &c4_proc_fops; | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 		strcpy(cinfo->capi_ctrl.name, card->name); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		retval = attach_capi_ctr(&cinfo->capi_ctrl); | 
					
						
							|  |  |  | 		if (retval) { | 
					
						
							|  |  |  | 			printk(KERN_ERR "c4: attach controller failed (%d).\n", i); | 
					
						
							|  |  |  | 			for (i--; i >= 0; i--) { | 
					
						
							|  |  |  | 				cinfo = &card->ctrlinfo[i]; | 
					
						
							|  |  |  | 				detach_capi_ctr(&cinfo->capi_ctrl); | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 			goto err_free_irq; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		if (i == 0) | 
					
						
							|  |  |  | 			card->cardnr = cinfo->capi_ctrl.cnr; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	printk(KERN_INFO "c4: AVM C%d at i/o %#x, irq %d, mem %#lx\n", | 
					
						
							|  |  |  | 	       nr_controllers, card->port, card->irq, | 
					
						
							|  |  |  | 	       card->membase); | 
					
						
							|  |  |  | 	pci_set_drvdata(dev, card); | 
					
						
							|  |  |  | 	return 0; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-02-19 19:52:38 -08:00
										 |  |  | err_free_irq: | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 	free_irq(card->irq, card); | 
					
						
							| 
									
										
										
										
											2012-02-19 19:52:38 -08:00
										 |  |  | err_unmap: | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 	iounmap(card->mbase); | 
					
						
							| 
									
										
										
										
											2012-02-19 19:52:38 -08:00
										 |  |  | err_release_region: | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 	release_region(card->port, AVMB1_PORTLEN); | 
					
						
							| 
									
										
										
										
											2012-02-19 19:52:38 -08:00
										 |  |  | err_free_dma: | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 	avmcard_dma_free(card->dma); | 
					
						
							| 
									
										
										
										
											2012-02-19 19:52:38 -08:00
										 |  |  | err_free: | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 	b1_free_card(card); | 
					
						
							| 
									
										
										
										
											2012-02-19 19:52:38 -08:00
										 |  |  | err: | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 	return retval; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* ------------------------------------------------------------- */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-12-21 13:13:05 -08:00
										 |  |  | static int c4_probe(struct pci_dev *dev, const struct pci_device_id *ent) | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | { | 
					
						
							|  |  |  | 	int nr = ent->driver_data; | 
					
						
							|  |  |  | 	int retval = 0; | 
					
						
							|  |  |  | 	struct capicardparams param; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (pci_enable_device(dev) < 0) { | 
					
						
							|  |  |  | 		printk(KERN_ERR "c4: failed to enable AVM-C%d\n", nr); | 
					
						
							|  |  |  | 		return -ENODEV; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	pci_set_master(dev); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	param.port = pci_resource_start(dev, 1); | 
					
						
							|  |  |  | 	param.irq = dev->irq; | 
					
						
							|  |  |  | 	param.membase = pci_resource_start(dev, 0); | 
					
						
							| 
									
										
										
										
											2012-02-19 19:52:38 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 	printk(KERN_INFO "c4: PCI BIOS reports AVM-C%d at i/o %#x, irq %d, mem %#x\n", | 
					
						
							|  |  |  | 	       nr, param.port, param.irq, param.membase); | 
					
						
							| 
									
										
										
										
											2012-02-19 19:52:38 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 	retval = c4_add_card(¶m, dev, nr); | 
					
						
							|  |  |  | 	if (retval != 0) { | 
					
						
							|  |  |  | 		printk(KERN_ERR "c4: no AVM-C%d at i/o %#x, irq %d detected, mem %#x\n", | 
					
						
							|  |  |  | 		       nr, param.port, param.irq, param.membase); | 
					
						
							| 
									
										
										
										
											2010-08-09 09:50:37 +00:00
										 |  |  | 		pci_disable_device(dev); | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 		return -ENODEV; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	return 0; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static struct pci_driver c4_pci_driver = { | 
					
						
							| 
									
										
										
										
											2012-02-19 19:52:38 -08:00
										 |  |  | 	.name           = "c4", | 
					
						
							|  |  |  | 	.id_table       = c4_pci_tbl, | 
					
						
							|  |  |  | 	.probe          = c4_probe, | 
					
						
							|  |  |  | 	.remove         = c4_remove, | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static struct capi_driver capi_driver_c2 = { | 
					
						
							|  |  |  | 	.name		= "c2", | 
					
						
							|  |  |  | 	.revision	= "1.0", | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static struct capi_driver capi_driver_c4 = { | 
					
						
							|  |  |  | 	.name		= "c4", | 
					
						
							|  |  |  | 	.revision	= "1.0", | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static int __init c4_init(void) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	char *p; | 
					
						
							|  |  |  | 	char rev[32]; | 
					
						
							|  |  |  | 	int err; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-04-28 02:14:38 -07:00
										 |  |  | 	if ((p = strchr(revision, ':')) != NULL && p[1]) { | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 		strlcpy(rev, p + 2, 32); | 
					
						
							| 
									
										
										
										
											2008-04-28 02:14:38 -07:00
										 |  |  | 		if ((p = strchr(rev, '$')) != NULL && p > rev) | 
					
						
							| 
									
										
										
										
											2012-02-19 19:52:38 -08:00
										 |  |  | 			*(p - 1) = 0; | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 	} else | 
					
						
							|  |  |  | 		strcpy(rev, "1.0"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	err = pci_register_driver(&c4_pci_driver); | 
					
						
							|  |  |  | 	if (!err) { | 
					
						
							|  |  |  | 		strlcpy(capi_driver_c2.revision, rev, 32); | 
					
						
							|  |  |  | 		register_capi_driver(&capi_driver_c2); | 
					
						
							|  |  |  | 		strlcpy(capi_driver_c4.revision, rev, 32); | 
					
						
							|  |  |  | 		register_capi_driver(&capi_driver_c4); | 
					
						
							|  |  |  | 		printk(KERN_INFO "c4: revision %s\n", rev); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	return err; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static void __exit c4_exit(void) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	unregister_capi_driver(&capi_driver_c2); | 
					
						
							|  |  |  | 	unregister_capi_driver(&capi_driver_c4); | 
					
						
							|  |  |  | 	pci_unregister_driver(&c4_pci_driver); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | module_init(c4_init); | 
					
						
							|  |  |  | module_exit(c4_exit); |