c4.c 33 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330
  1. /* $Id: c4.c,v 1.1.2.2 2004/01/16 21:09:27 keil Exp $
  2. *
  3. * Module for AVM C4 & C2 card.
  4. *
  5. * Copyright 1999 by Carsten Paeth <calle@calle.de>
  6. *
  7. * This software may be used and distributed according to the terms
  8. * of the GNU General Public License, incorporated herein by reference.
  9. *
  10. */
  11. #include <linux/module.h>
  12. #include <linux/kernel.h>
  13. #include <linux/proc_fs.h>
  14. #include <linux/seq_file.h>
  15. #include <linux/skbuff.h>
  16. #include <linux/delay.h>
  17. #include <linux/mm.h>
  18. #include <linux/interrupt.h>
  19. #include <linux/ioport.h>
  20. #include <linux/pci.h>
  21. #include <linux/capi.h>
  22. #include <linux/kernelcapi.h>
  23. #include <linux/init.h>
  24. #include <linux/gfp.h>
  25. #include <asm/io.h>
  26. #include <asm/uaccess.h>
  27. #include <linux/netdevice.h>
  28. #include <linux/isdn/capicmd.h>
  29. #include <linux/isdn/capiutil.h>
  30. #include <linux/isdn/capilli.h>
  31. #include "avmcard.h"
  32. #undef AVM_C4_DEBUG
  33. #undef AVM_C4_POLLDEBUG
  34. /* ------------------------------------------------------------- */
  35. static char *revision = "$Revision: 1.1.2.2 $";
  36. /* ------------------------------------------------------------- */
  37. static bool suppress_pollack;
  38. static struct pci_device_id c4_pci_tbl[] = {
  39. { PCI_VENDOR_ID_DEC, PCI_DEVICE_ID_DEC_21285, PCI_VENDOR_ID_AVM, PCI_DEVICE_ID_AVM_C4, 0, 0, (unsigned long)4 },
  40. { PCI_VENDOR_ID_DEC, PCI_DEVICE_ID_DEC_21285, PCI_VENDOR_ID_AVM, PCI_DEVICE_ID_AVM_C2, 0, 0, (unsigned long)2 },
  41. { } /* Terminating entry */
  42. };
  43. MODULE_DEVICE_TABLE(pci, c4_pci_tbl);
  44. MODULE_DESCRIPTION("CAPI4Linux: Driver for AVM C2/C4 cards");
  45. MODULE_AUTHOR("Carsten Paeth");
  46. MODULE_LICENSE("GPL");
  47. module_param(suppress_pollack, bool, 0);
  48. /* ------------------------------------------------------------- */
  49. static void c4_dispatch_tx(avmcard *card);
  50. /* ------------------------------------------------------------- */
  51. #define DC21285_DRAM_A0MR 0x40000000
  52. #define DC21285_DRAM_A1MR 0x40004000
  53. #define DC21285_DRAM_A2MR 0x40008000
  54. #define DC21285_DRAM_A3MR 0x4000C000
  55. #define CAS_OFFSET 0x88
  56. #define DC21285_ARMCSR_BASE 0x42000000
  57. #define PCI_OUT_INT_STATUS 0x30
  58. #define PCI_OUT_INT_MASK 0x34
  59. #define MAILBOX_0 0x50
  60. #define MAILBOX_1 0x54
  61. #define MAILBOX_2 0x58
  62. #define MAILBOX_3 0x5C
  63. #define DOORBELL 0x60
  64. #define DOORBELL_SETUP 0x64
  65. #define CHAN_1_CONTROL 0x90
  66. #define CHAN_2_CONTROL 0xB0
  67. #define DRAM_TIMING 0x10C
  68. #define DRAM_ADDR_SIZE_0 0x110
  69. #define DRAM_ADDR_SIZE_1 0x114
  70. #define DRAM_ADDR_SIZE_2 0x118
  71. #define DRAM_ADDR_SIZE_3 0x11C
  72. #define SA_CONTROL 0x13C
  73. #define XBUS_CYCLE 0x148
  74. #define XBUS_STROBE 0x14C
  75. #define DBELL_PCI_MASK 0x150
  76. #define DBELL_SA_MASK 0x154
  77. #define SDRAM_SIZE 0x1000000
  78. /* ------------------------------------------------------------- */
  79. #define MBOX_PEEK_POKE MAILBOX_0
  80. #define DBELL_ADDR 0x01
  81. #define DBELL_DATA 0x02
  82. #define DBELL_RNWR 0x40
  83. #define DBELL_INIT 0x80
  84. /* ------------------------------------------------------------- */
  85. #define MBOX_UP_ADDR MAILBOX_0
  86. #define MBOX_UP_LEN MAILBOX_1
  87. #define MBOX_DOWN_ADDR MAILBOX_2
  88. #define MBOX_DOWN_LEN MAILBOX_3
  89. #define DBELL_UP_HOST 0x00000100
  90. #define DBELL_UP_ARM 0x00000200
  91. #define DBELL_DOWN_HOST 0x00000400
  92. #define DBELL_DOWN_ARM 0x00000800
  93. #define DBELL_RESET_HOST 0x40000000
  94. #define DBELL_RESET_ARM 0x80000000
  95. /* ------------------------------------------------------------- */
  96. #define DRAM_TIMING_DEF 0x001A01A5
  97. #define DRAM_AD_SZ_DEF0 0x00000045
  98. #define DRAM_AD_SZ_NULL 0x00000000
  99. #define SA_CTL_ALLRIGHT 0x64AA0271
  100. #define INIT_XBUS_CYCLE 0x100016DB
  101. #define INIT_XBUS_STROBE 0xF1F1F1F1
  102. /* ------------------------------------------------------------- */
  103. #define RESET_TIMEOUT (15 * HZ) /* 15 sec */
  104. #define PEEK_POKE_TIMEOUT (HZ / 10) /* 0.1 sec */
  105. /* ------------------------------------------------------------- */
  106. #define c4outmeml(addr, value) writel(value, addr)
  107. #define c4inmeml(addr) readl(addr)
  108. #define c4outmemw(addr, value) writew(value, addr)
  109. #define c4inmemw(addr) readw(addr)
  110. #define c4outmemb(addr, value) writeb(value, addr)
  111. #define c4inmemb(addr) readb(addr)
  112. /* ------------------------------------------------------------- */
  113. static inline int wait_for_doorbell(avmcard *card, unsigned long t)
  114. {
  115. unsigned long stop;
  116. stop = jiffies + t;
  117. while (c4inmeml(card->mbase + DOORBELL) != 0xffffffff) {
  118. if (!time_before(jiffies, stop))
  119. return -1;
  120. mb();
  121. }
  122. return 0;
  123. }
  124. static int c4_poke(avmcard *card, unsigned long off, unsigned long value)
  125. {
  126. if (wait_for_doorbell(card, HZ / 10) < 0)
  127. return -1;
  128. c4outmeml(card->mbase + MBOX_PEEK_POKE, off);
  129. c4outmeml(card->mbase + DOORBELL, DBELL_ADDR);
  130. if (wait_for_doorbell(card, HZ / 10) < 0)
  131. return -1;
  132. c4outmeml(card->mbase + MBOX_PEEK_POKE, value);
  133. c4outmeml(card->mbase + DOORBELL, DBELL_DATA | DBELL_ADDR);
  134. return 0;
  135. }
  136. static int c4_peek(avmcard *card, unsigned long off, unsigned long *valuep)
  137. {
  138. if (wait_for_doorbell(card, HZ / 10) < 0)
  139. return -1;
  140. c4outmeml(card->mbase + MBOX_PEEK_POKE, off);
  141. c4outmeml(card->mbase + DOORBELL, DBELL_RNWR | DBELL_ADDR);
  142. if (wait_for_doorbell(card, HZ / 10) < 0)
  143. return -1;
  144. *valuep = c4inmeml(card->mbase + MBOX_PEEK_POKE);
  145. return 0;
  146. }
  147. /* ------------------------------------------------------------- */
  148. static int c4_load_t4file(avmcard *card, capiloaddatapart *t4file)
  149. {
  150. u32 val;
  151. unsigned char *dp;
  152. u_int left;
  153. u32 loadoff = 0;
  154. dp = t4file->data;
  155. left = t4file->len;
  156. while (left >= sizeof(u32)) {
  157. if (t4file->user) {
  158. if (copy_from_user(&val, dp, sizeof(val)))
  159. return -EFAULT;
  160. } else {
  161. memcpy(&val, dp, sizeof(val));
  162. }
  163. if (c4_poke(card, loadoff, val)) {
  164. printk(KERN_ERR "%s: corrupted firmware file ?\n",
  165. card->name);
  166. return -EIO;
  167. }
  168. left -= sizeof(u32);
  169. dp += sizeof(u32);
  170. loadoff += sizeof(u32);
  171. }
  172. if (left) {
  173. val = 0;
  174. if (t4file->user) {
  175. if (copy_from_user(&val, dp, left))
  176. return -EFAULT;
  177. } else {
  178. memcpy(&val, dp, left);
  179. }
  180. if (c4_poke(card, loadoff, val)) {
  181. printk(KERN_ERR "%s: corrupted firmware file ?\n",
  182. card->name);
  183. return -EIO;
  184. }
  185. }
  186. return 0;
  187. }
  188. /* ------------------------------------------------------------- */
  189. static inline void _put_byte(void **pp, u8 val)
  190. {
  191. u8 *s = *pp;
  192. *s++ = val;
  193. *pp = s;
  194. }
  195. static inline void _put_word(void **pp, u32 val)
  196. {
  197. u8 *s = *pp;
  198. *s++ = val & 0xff;
  199. *s++ = (val >> 8) & 0xff;
  200. *s++ = (val >> 16) & 0xff;
  201. *s++ = (val >> 24) & 0xff;
  202. *pp = s;
  203. }
  204. static inline void _put_slice(void **pp, unsigned char *dp, unsigned int len)
  205. {
  206. unsigned i = len;
  207. _put_word(pp, i);
  208. while (i-- > 0)
  209. _put_byte(pp, *dp++);
  210. }
  211. static inline u8 _get_byte(void **pp)
  212. {
  213. u8 *s = *pp;
  214. u8 val;
  215. val = *s++;
  216. *pp = s;
  217. return val;
  218. }
  219. static inline u32 _get_word(void **pp)
  220. {
  221. u8 *s = *pp;
  222. u32 val;
  223. val = *s++;
  224. val |= (*s++ << 8);
  225. val |= (*s++ << 16);
  226. val |= (*s++ << 24);
  227. *pp = s;
  228. return val;
  229. }
  230. static inline u32 _get_slice(void **pp, unsigned char *dp)
  231. {
  232. unsigned int len, i;
  233. len = i = _get_word(pp);
  234. while (i-- > 0) *dp++ = _get_byte(pp);
  235. return len;
  236. }
  237. /* ------------------------------------------------------------- */
  238. static void c4_reset(avmcard *card)
  239. {
  240. unsigned long stop;
  241. c4outmeml(card->mbase + DOORBELL, DBELL_RESET_ARM);
  242. stop = jiffies + HZ * 10;
  243. while (c4inmeml(card->mbase + DOORBELL) != 0xffffffff) {
  244. if (!time_before(jiffies, stop))
  245. return;
  246. c4outmeml(card->mbase + DOORBELL, DBELL_ADDR);
  247. mb();
  248. }
  249. c4_poke(card, DC21285_ARMCSR_BASE + CHAN_1_CONTROL, 0);
  250. c4_poke(card, DC21285_ARMCSR_BASE + CHAN_2_CONTROL, 0);
  251. }
  252. /* ------------------------------------------------------------- */
  253. static int c4_detect(avmcard *card)
  254. {
  255. unsigned long stop, dummy;
  256. c4outmeml(card->mbase + PCI_OUT_INT_MASK, 0x0c);
  257. if (c4inmeml(card->mbase + PCI_OUT_INT_MASK) != 0x0c)
  258. return 1;
  259. c4outmeml(card->mbase + DOORBELL, DBELL_RESET_ARM);
  260. stop = jiffies + HZ * 10;
  261. while (c4inmeml(card->mbase + DOORBELL) != 0xffffffff) {
  262. if (!time_before(jiffies, stop))
  263. return 2;
  264. c4outmeml(card->mbase + DOORBELL, DBELL_ADDR);
  265. mb();
  266. }
  267. c4_poke(card, DC21285_ARMCSR_BASE + CHAN_1_CONTROL, 0);
  268. c4_poke(card, DC21285_ARMCSR_BASE + CHAN_2_CONTROL, 0);
  269. c4outmeml(card->mbase + MAILBOX_0, 0x55aa55aa);
  270. if (c4inmeml(card->mbase + MAILBOX_0) != 0x55aa55aa) return 3;
  271. c4outmeml(card->mbase + MAILBOX_0, 0xaa55aa55);
  272. if (c4inmeml(card->mbase + MAILBOX_0) != 0xaa55aa55) return 4;
  273. if (c4_poke(card, DC21285_ARMCSR_BASE + DBELL_SA_MASK, 0)) return 5;
  274. if (c4_poke(card, DC21285_ARMCSR_BASE + DBELL_PCI_MASK, 0)) return 6;
  275. if (c4_poke(card, DC21285_ARMCSR_BASE + SA_CONTROL, SA_CTL_ALLRIGHT))
  276. return 7;
  277. if (c4_poke(card, DC21285_ARMCSR_BASE + XBUS_CYCLE, INIT_XBUS_CYCLE))
  278. return 8;
  279. if (c4_poke(card, DC21285_ARMCSR_BASE + XBUS_STROBE, INIT_XBUS_STROBE))
  280. return 8;
  281. if (c4_poke(card, DC21285_ARMCSR_BASE + DRAM_TIMING, 0)) return 9;
  282. mdelay(1);
  283. if (c4_peek(card, DC21285_DRAM_A0MR, &dummy)) return 10;
  284. if (c4_peek(card, DC21285_DRAM_A1MR, &dummy)) return 11;
  285. if (c4_peek(card, DC21285_DRAM_A2MR, &dummy)) return 12;
  286. if (c4_peek(card, DC21285_DRAM_A3MR, &dummy)) return 13;
  287. if (c4_poke(card, DC21285_DRAM_A0MR + CAS_OFFSET, 0)) return 14;
  288. if (c4_poke(card, DC21285_DRAM_A1MR + CAS_OFFSET, 0)) return 15;
  289. if (c4_poke(card, DC21285_DRAM_A2MR + CAS_OFFSET, 0)) return 16;
  290. if (c4_poke(card, DC21285_DRAM_A3MR + CAS_OFFSET, 0)) return 17;
  291. mdelay(1);
  292. if (c4_poke(card, DC21285_ARMCSR_BASE + DRAM_TIMING, DRAM_TIMING_DEF))
  293. return 18;
  294. if (c4_poke(card, DC21285_ARMCSR_BASE + DRAM_ADDR_SIZE_0, DRAM_AD_SZ_DEF0))
  295. return 19;
  296. if (c4_poke(card, DC21285_ARMCSR_BASE + DRAM_ADDR_SIZE_1, DRAM_AD_SZ_NULL))
  297. return 20;
  298. if (c4_poke(card, DC21285_ARMCSR_BASE + DRAM_ADDR_SIZE_2, DRAM_AD_SZ_NULL))
  299. return 21;
  300. if (c4_poke(card, DC21285_ARMCSR_BASE + DRAM_ADDR_SIZE_3, DRAM_AD_SZ_NULL))
  301. return 22;
  302. /* Transputer test */
  303. if (c4_poke(card, 0x000000, 0x11111111)
  304. || c4_poke(card, 0x400000, 0x22222222)
  305. || c4_poke(card, 0x800000, 0x33333333)
  306. || c4_poke(card, 0xC00000, 0x44444444))
  307. return 23;
  308. if (c4_peek(card, 0x000000, &dummy) || dummy != 0x11111111
  309. || c4_peek(card, 0x400000, &dummy) || dummy != 0x22222222
  310. || c4_peek(card, 0x800000, &dummy) || dummy != 0x33333333
  311. || c4_peek(card, 0xC00000, &dummy) || dummy != 0x44444444)
  312. return 24;
  313. if (c4_poke(card, 0x000000, 0x55555555)
  314. || c4_poke(card, 0x400000, 0x66666666)
  315. || c4_poke(card, 0x800000, 0x77777777)
  316. || c4_poke(card, 0xC00000, 0x88888888))
  317. return 25;
  318. if (c4_peek(card, 0x000000, &dummy) || dummy != 0x55555555
  319. || c4_peek(card, 0x400000, &dummy) || dummy != 0x66666666
  320. || c4_peek(card, 0x800000, &dummy) || dummy != 0x77777777
  321. || c4_peek(card, 0xC00000, &dummy) || dummy != 0x88888888)
  322. return 26;
  323. return 0;
  324. }
  325. /* ------------------------------------------------------------- */
  326. static void c4_dispatch_tx(avmcard *card)
  327. {
  328. avmcard_dmainfo *dma = card->dma;
  329. struct sk_buff *skb;
  330. u8 cmd, subcmd;
  331. u16 len;
  332. u32 txlen;
  333. void *p;
  334. if (card->csr & DBELL_DOWN_ARM) { /* tx busy */
  335. return;
  336. }
  337. skb = skb_dequeue(&dma->send_queue);
  338. if (!skb) {
  339. #ifdef AVM_C4_DEBUG
  340. printk(KERN_DEBUG "%s: tx underrun\n", card->name);
  341. #endif
  342. return;
  343. }
  344. len = CAPIMSG_LEN(skb->data);
  345. if (len) {
  346. cmd = CAPIMSG_COMMAND(skb->data);
  347. subcmd = CAPIMSG_SUBCOMMAND(skb->data);
  348. p = dma->sendbuf.dmabuf;
  349. if (CAPICMD(cmd, subcmd) == CAPI_DATA_B3_REQ) {
  350. u16 dlen = CAPIMSG_DATALEN(skb->data);
  351. _put_byte(&p, SEND_DATA_B3_REQ);
  352. _put_slice(&p, skb->data, len);
  353. _put_slice(&p, skb->data + len, dlen);
  354. } else {
  355. _put_byte(&p, SEND_MESSAGE);
  356. _put_slice(&p, skb->data, len);
  357. }
  358. txlen = (u8 *)p - (u8 *)dma->sendbuf.dmabuf;
  359. #ifdef AVM_C4_DEBUG
  360. printk(KERN_DEBUG "%s: tx put msg len=%d\n", card->name, txlen);
  361. #endif
  362. } else {
  363. txlen = skb->len - 2;
  364. #ifdef AVM_C4_POLLDEBUG
  365. if (skb->data[2] == SEND_POLLACK)
  366. printk(KERN_INFO "%s: ack to c4\n", card->name);
  367. #endif
  368. #ifdef AVM_C4_DEBUG
  369. printk(KERN_DEBUG "%s: tx put 0x%x len=%d\n",
  370. card->name, skb->data[2], txlen);
  371. #endif
  372. skb_copy_from_linear_data_offset(skb, 2, dma->sendbuf.dmabuf,
  373. skb->len - 2);
  374. }
  375. txlen = (txlen + 3) & ~3;
  376. c4outmeml(card->mbase + MBOX_DOWN_ADDR, dma->sendbuf.dmaaddr);
  377. c4outmeml(card->mbase + MBOX_DOWN_LEN, txlen);
  378. card->csr |= DBELL_DOWN_ARM;
  379. c4outmeml(card->mbase + DOORBELL, DBELL_DOWN_ARM);
  380. dev_kfree_skb_any(skb);
  381. }
  382. /* ------------------------------------------------------------- */
  383. static void queue_pollack(avmcard *card)
  384. {
  385. struct sk_buff *skb;
  386. void *p;
  387. skb = alloc_skb(3, GFP_ATOMIC);
  388. if (!skb) {
  389. printk(KERN_CRIT "%s: no memory, lost poll ack\n",
  390. card->name);
  391. return;
  392. }
  393. p = skb->data;
  394. _put_byte(&p, 0);
  395. _put_byte(&p, 0);
  396. _put_byte(&p, SEND_POLLACK);
  397. skb_put(skb, (u8 *)p - (u8 *)skb->data);
  398. skb_queue_tail(&card->dma->send_queue, skb);
  399. c4_dispatch_tx(card);
  400. }
  401. /* ------------------------------------------------------------- */
  402. static void c4_handle_rx(avmcard *card)
  403. {
  404. avmcard_dmainfo *dma = card->dma;
  405. struct capi_ctr *ctrl;
  406. avmctrl_info *cinfo;
  407. struct sk_buff *skb;
  408. void *p = dma->recvbuf.dmabuf;
  409. u32 ApplId, MsgLen, DataB3Len, NCCI, WindowSize;
  410. u8 b1cmd = _get_byte(&p);
  411. u32 cidx;
  412. #ifdef AVM_C4_DEBUG
  413. printk(KERN_DEBUG "%s: rx 0x%x len=%lu\n", card->name,
  414. b1cmd, (unsigned long)dma->recvlen);
  415. #endif
  416. switch (b1cmd) {
  417. case RECEIVE_DATA_B3_IND:
  418. ApplId = (unsigned) _get_word(&p);
  419. MsgLen = _get_slice(&p, card->msgbuf);
  420. DataB3Len = _get_slice(&p, card->databuf);
  421. cidx = CAPIMSG_CONTROLLER(card->msgbuf)-card->cardnr;
  422. if (cidx >= card->nlogcontr) cidx = 0;
  423. ctrl = &card->ctrlinfo[cidx].capi_ctrl;
  424. if (MsgLen < 30) { /* not CAPI 64Bit */
  425. memset(card->msgbuf + MsgLen, 0, 30 - MsgLen);
  426. MsgLen = 30;
  427. CAPIMSG_SETLEN(card->msgbuf, 30);
  428. }
  429. if (!(skb = alloc_skb(DataB3Len + MsgLen, GFP_ATOMIC))) {
  430. printk(KERN_ERR "%s: incoming packet dropped\n",
  431. card->name);
  432. } else {
  433. memcpy(skb_put(skb, MsgLen), card->msgbuf, MsgLen);
  434. memcpy(skb_put(skb, DataB3Len), card->databuf, DataB3Len);
  435. capi_ctr_handle_message(ctrl, ApplId, skb);
  436. }
  437. break;
  438. case RECEIVE_MESSAGE:
  439. ApplId = (unsigned) _get_word(&p);
  440. MsgLen = _get_slice(&p, card->msgbuf);
  441. cidx = CAPIMSG_CONTROLLER(card->msgbuf)-card->cardnr;
  442. if (cidx >= card->nlogcontr) cidx = 0;
  443. cinfo = &card->ctrlinfo[cidx];
  444. ctrl = &card->ctrlinfo[cidx].capi_ctrl;
  445. if (!(skb = alloc_skb(MsgLen, GFP_ATOMIC))) {
  446. printk(KERN_ERR "%s: incoming packet dropped\n",
  447. card->name);
  448. } else {
  449. memcpy(skb_put(skb, MsgLen), card->msgbuf, MsgLen);
  450. if (CAPIMSG_CMD(skb->data) == CAPI_DATA_B3_CONF)
  451. capilib_data_b3_conf(&cinfo->ncci_head, ApplId,
  452. CAPIMSG_NCCI(skb->data),
  453. CAPIMSG_MSGID(skb->data));
  454. capi_ctr_handle_message(ctrl, ApplId, skb);
  455. }
  456. break;
  457. case RECEIVE_NEW_NCCI:
  458. ApplId = _get_word(&p);
  459. NCCI = _get_word(&p);
  460. WindowSize = _get_word(&p);
  461. cidx = (NCCI & 0x7f) - card->cardnr;
  462. if (cidx >= card->nlogcontr) cidx = 0;
  463. capilib_new_ncci(&card->ctrlinfo[cidx].ncci_head, ApplId, NCCI, WindowSize);
  464. break;
  465. case RECEIVE_FREE_NCCI:
  466. ApplId = _get_word(&p);
  467. NCCI = _get_word(&p);
  468. if (NCCI != 0xffffffff) {
  469. cidx = (NCCI & 0x7f) - card->cardnr;
  470. if (cidx >= card->nlogcontr) cidx = 0;
  471. capilib_free_ncci(&card->ctrlinfo[cidx].ncci_head, ApplId, NCCI);
  472. }
  473. break;
  474. case RECEIVE_START:
  475. #ifdef AVM_C4_POLLDEBUG
  476. printk(KERN_INFO "%s: poll from c4\n", card->name);
  477. #endif
  478. if (!suppress_pollack)
  479. queue_pollack(card);
  480. for (cidx = 0; cidx < card->nr_controllers; cidx++) {
  481. ctrl = &card->ctrlinfo[cidx].capi_ctrl;
  482. capi_ctr_resume_output(ctrl);
  483. }
  484. break;
  485. case RECEIVE_STOP:
  486. for (cidx = 0; cidx < card->nr_controllers; cidx++) {
  487. ctrl = &card->ctrlinfo[cidx].capi_ctrl;
  488. capi_ctr_suspend_output(ctrl);
  489. }
  490. break;
  491. case RECEIVE_INIT:
  492. cidx = card->nlogcontr;
  493. if (cidx >= card->nr_controllers) {
  494. printk(KERN_ERR "%s: card with %d controllers ??\n",
  495. card->name, cidx + 1);
  496. break;
  497. }
  498. card->nlogcontr++;
  499. cinfo = &card->ctrlinfo[cidx];
  500. ctrl = &cinfo->capi_ctrl;
  501. cinfo->versionlen = _get_slice(&p, cinfo->versionbuf);
  502. b1_parse_version(cinfo);
  503. printk(KERN_INFO "%s: %s-card (%s) now active\n",
  504. card->name,
  505. cinfo->version[VER_CARDTYPE],
  506. cinfo->version[VER_DRIVER]);
  507. capi_ctr_ready(&cinfo->capi_ctrl);
  508. break;
  509. case RECEIVE_TASK_READY:
  510. ApplId = (unsigned) _get_word(&p);
  511. MsgLen = _get_slice(&p, card->msgbuf);
  512. card->msgbuf[MsgLen] = 0;
  513. while (MsgLen > 0
  514. && (card->msgbuf[MsgLen - 1] == '\n'
  515. || card->msgbuf[MsgLen - 1] == '\r')) {
  516. card->msgbuf[MsgLen - 1] = 0;
  517. MsgLen--;
  518. }
  519. printk(KERN_INFO "%s: task %d \"%s\" ready.\n",
  520. card->name, ApplId, card->msgbuf);
  521. break;
  522. case RECEIVE_DEBUGMSG:
  523. MsgLen = _get_slice(&p, card->msgbuf);
  524. card->msgbuf[MsgLen] = 0;
  525. while (MsgLen > 0
  526. && (card->msgbuf[MsgLen - 1] == '\n'
  527. || card->msgbuf[MsgLen - 1] == '\r')) {
  528. card->msgbuf[MsgLen - 1] = 0;
  529. MsgLen--;
  530. }
  531. printk(KERN_INFO "%s: DEBUG: %s\n", card->name, card->msgbuf);
  532. break;
  533. default:
  534. printk(KERN_ERR "%s: c4_interrupt: 0x%x ???\n",
  535. card->name, b1cmd);
  536. return;
  537. }
  538. }
  539. /* ------------------------------------------------------------- */
  540. static irqreturn_t c4_handle_interrupt(avmcard *card)
  541. {
  542. unsigned long flags;
  543. u32 status;
  544. spin_lock_irqsave(&card->lock, flags);
  545. status = c4inmeml(card->mbase + DOORBELL);
  546. if (status & DBELL_RESET_HOST) {
  547. u_int i;
  548. c4outmeml(card->mbase + PCI_OUT_INT_MASK, 0x0c);
  549. spin_unlock_irqrestore(&card->lock, flags);
  550. if (card->nlogcontr == 0)
  551. return IRQ_HANDLED;
  552. printk(KERN_ERR "%s: unexpected reset\n", card->name);
  553. for (i = 0; i < card->nr_controllers; i++) {
  554. avmctrl_info *cinfo = &card->ctrlinfo[i];
  555. memset(cinfo->version, 0, sizeof(cinfo->version));
  556. spin_lock_irqsave(&card->lock, flags);
  557. capilib_release(&cinfo->ncci_head);
  558. spin_unlock_irqrestore(&card->lock, flags);
  559. capi_ctr_down(&cinfo->capi_ctrl);
  560. }
  561. card->nlogcontr = 0;
  562. return IRQ_HANDLED;
  563. }
  564. status &= (DBELL_UP_HOST | DBELL_DOWN_HOST);
  565. if (!status) {
  566. spin_unlock_irqrestore(&card->lock, flags);
  567. return IRQ_HANDLED;
  568. }
  569. c4outmeml(card->mbase + DOORBELL, status);
  570. if ((status & DBELL_UP_HOST) != 0) {
  571. card->dma->recvlen = c4inmeml(card->mbase + MBOX_UP_LEN);
  572. c4outmeml(card->mbase + MBOX_UP_LEN, 0);
  573. c4_handle_rx(card);
  574. card->dma->recvlen = 0;
  575. c4outmeml(card->mbase + MBOX_UP_LEN, card->dma->recvbuf.size);
  576. c4outmeml(card->mbase + DOORBELL, DBELL_UP_ARM);
  577. }
  578. if ((status & DBELL_DOWN_HOST) != 0) {
  579. card->csr &= ~DBELL_DOWN_ARM;
  580. c4_dispatch_tx(card);
  581. } else if (card->csr & DBELL_DOWN_HOST) {
  582. if (c4inmeml(card->mbase + MBOX_DOWN_LEN) == 0) {
  583. card->csr &= ~DBELL_DOWN_ARM;
  584. c4_dispatch_tx(card);
  585. }
  586. }
  587. spin_unlock_irqrestore(&card->lock, flags);
  588. return IRQ_HANDLED;
  589. }
  590. static irqreturn_t c4_interrupt(int interrupt, void *devptr)
  591. {
  592. avmcard *card = devptr;
  593. return c4_handle_interrupt(card);
  594. }
  595. /* ------------------------------------------------------------- */
  596. static void c4_send_init(avmcard *card)
  597. {
  598. struct sk_buff *skb;
  599. void *p;
  600. unsigned long flags;
  601. skb = alloc_skb(15, GFP_ATOMIC);
  602. if (!skb) {
  603. printk(KERN_CRIT "%s: no memory, lost register appl.\n",
  604. card->name);
  605. return;
  606. }
  607. p = skb->data;
  608. _put_byte(&p, 0);
  609. _put_byte(&p, 0);
  610. _put_byte(&p, SEND_INIT);
  611. _put_word(&p, CAPI_MAXAPPL);
  612. _put_word(&p, AVM_NCCI_PER_CHANNEL * 30);
  613. _put_word(&p, card->cardnr - 1);
  614. skb_put(skb, (u8 *)p - (u8 *)skb->data);
  615. skb_queue_tail(&card->dma->send_queue, skb);
  616. spin_lock_irqsave(&card->lock, flags);
  617. c4_dispatch_tx(card);
  618. spin_unlock_irqrestore(&card->lock, flags);
  619. }
  620. static int queue_sendconfigword(avmcard *card, u32 val)
  621. {
  622. struct sk_buff *skb;
  623. unsigned long flags;
  624. void *p;
  625. skb = alloc_skb(3 + 4, GFP_ATOMIC);
  626. if (!skb) {
  627. printk(KERN_CRIT "%s: no memory, send config\n",
  628. card->name);
  629. return -ENOMEM;
  630. }
  631. p = skb->data;
  632. _put_byte(&p, 0);
  633. _put_byte(&p, 0);
  634. _put_byte(&p, SEND_CONFIG);
  635. _put_word(&p, val);
  636. skb_put(skb, (u8 *)p - (u8 *)skb->data);
  637. skb_queue_tail(&card->dma->send_queue, skb);
  638. spin_lock_irqsave(&card->lock, flags);
  639. c4_dispatch_tx(card);
  640. spin_unlock_irqrestore(&card->lock, flags);
  641. return 0;
  642. }
  643. static int queue_sendconfig(avmcard *card, char cval[4])
  644. {
  645. struct sk_buff *skb;
  646. unsigned long flags;
  647. void *p;
  648. skb = alloc_skb(3 + 4, GFP_ATOMIC);
  649. if (!skb) {
  650. printk(KERN_CRIT "%s: no memory, send config\n",
  651. card->name);
  652. return -ENOMEM;
  653. }
  654. p = skb->data;
  655. _put_byte(&p, 0);
  656. _put_byte(&p, 0);
  657. _put_byte(&p, SEND_CONFIG);
  658. _put_byte(&p, cval[0]);
  659. _put_byte(&p, cval[1]);
  660. _put_byte(&p, cval[2]);
  661. _put_byte(&p, cval[3]);
  662. skb_put(skb, (u8 *)p - (u8 *)skb->data);
  663. skb_queue_tail(&card->dma->send_queue, skb);
  664. spin_lock_irqsave(&card->lock, flags);
  665. c4_dispatch_tx(card);
  666. spin_unlock_irqrestore(&card->lock, flags);
  667. return 0;
  668. }
  669. static int c4_send_config(avmcard *card, capiloaddatapart *config)
  670. {
  671. u8 val[4];
  672. unsigned char *dp;
  673. u_int left;
  674. int retval;
  675. if ((retval = queue_sendconfigword(card, 1)) != 0)
  676. return retval;
  677. if ((retval = queue_sendconfigword(card, config->len)) != 0)
  678. return retval;
  679. dp = config->data;
  680. left = config->len;
  681. while (left >= sizeof(u32)) {
  682. if (config->user) {
  683. if (copy_from_user(val, dp, sizeof(val)))
  684. return -EFAULT;
  685. } else {
  686. memcpy(val, dp, sizeof(val));
  687. }
  688. if ((retval = queue_sendconfig(card, val)) != 0)
  689. return retval;
  690. left -= sizeof(val);
  691. dp += sizeof(val);
  692. }
  693. if (left) {
  694. memset(val, 0, sizeof(val));
  695. if (config->user) {
  696. if (copy_from_user(&val, dp, left))
  697. return -EFAULT;
  698. } else {
  699. memcpy(&val, dp, left);
  700. }
  701. if ((retval = queue_sendconfig(card, val)) != 0)
  702. return retval;
  703. }
  704. return 0;
  705. }
  706. static int c4_load_firmware(struct capi_ctr *ctrl, capiloaddata *data)
  707. {
  708. avmctrl_info *cinfo = (avmctrl_info *)(ctrl->driverdata);
  709. avmcard *card = cinfo->card;
  710. int retval;
  711. if ((retval = c4_load_t4file(card, &data->firmware))) {
  712. printk(KERN_ERR "%s: failed to load t4file!!\n",
  713. card->name);
  714. c4_reset(card);
  715. return retval;
  716. }
  717. card->csr = 0;
  718. c4outmeml(card->mbase + MBOX_UP_LEN, 0);
  719. c4outmeml(card->mbase + MBOX_DOWN_LEN, 0);
  720. c4outmeml(card->mbase + DOORBELL, DBELL_INIT);
  721. mdelay(1);
  722. c4outmeml(card->mbase + DOORBELL,
  723. DBELL_UP_HOST | DBELL_DOWN_HOST | DBELL_RESET_HOST);
  724. c4outmeml(card->mbase + PCI_OUT_INT_MASK, 0x08);
  725. card->dma->recvlen = 0;
  726. c4outmeml(card->mbase + MBOX_UP_ADDR, card->dma->recvbuf.dmaaddr);
  727. c4outmeml(card->mbase + MBOX_UP_LEN, card->dma->recvbuf.size);
  728. c4outmeml(card->mbase + DOORBELL, DBELL_UP_ARM);
  729. if (data->configuration.len > 0 && data->configuration.data) {
  730. retval = c4_send_config(card, &data->configuration);
  731. if (retval) {
  732. printk(KERN_ERR "%s: failed to set config!!\n",
  733. card->name);
  734. c4_reset(card);
  735. return retval;
  736. }
  737. }
  738. c4_send_init(card);
  739. return 0;
  740. }
  741. static void c4_reset_ctr(struct capi_ctr *ctrl)
  742. {
  743. avmcard *card = ((avmctrl_info *)(ctrl->driverdata))->card;
  744. avmctrl_info *cinfo;
  745. u_int i;
  746. unsigned long flags;
  747. spin_lock_irqsave(&card->lock, flags);
  748. c4_reset(card);
  749. spin_unlock_irqrestore(&card->lock, flags);
  750. for (i = 0; i < card->nr_controllers; i++) {
  751. cinfo = &card->ctrlinfo[i];
  752. memset(cinfo->version, 0, sizeof(cinfo->version));
  753. capi_ctr_down(&cinfo->capi_ctrl);
  754. }
  755. card->nlogcontr = 0;
  756. }
  757. static void c4_remove(struct pci_dev *pdev)
  758. {
  759. avmcard *card = pci_get_drvdata(pdev);
  760. avmctrl_info *cinfo;
  761. u_int i;
  762. if (!card)
  763. return;
  764. c4_reset(card);
  765. for (i = 0; i < card->nr_controllers; i++) {
  766. cinfo = &card->ctrlinfo[i];
  767. detach_capi_ctr(&cinfo->capi_ctrl);
  768. }
  769. free_irq(card->irq, card);
  770. iounmap(card->mbase);
  771. release_region(card->port, AVMB1_PORTLEN);
  772. avmcard_dma_free(card->dma);
  773. pci_set_drvdata(pdev, NULL);
  774. b1_free_card(card);
  775. }
  776. /* ------------------------------------------------------------- */
  777. static void c4_register_appl(struct capi_ctr *ctrl,
  778. u16 appl,
  779. capi_register_params *rp)
  780. {
  781. avmctrl_info *cinfo = (avmctrl_info *)(ctrl->driverdata);
  782. avmcard *card = cinfo->card;
  783. struct sk_buff *skb;
  784. int want = rp->level3cnt;
  785. unsigned long flags;
  786. int nconn;
  787. void *p;
  788. if (ctrl->cnr == card->cardnr) {
  789. if (want > 0) nconn = want;
  790. else nconn = ctrl->profile.nbchannel * 4 * -want;
  791. if (nconn == 0) nconn = ctrl->profile.nbchannel * 4;
  792. skb = alloc_skb(23, GFP_ATOMIC);
  793. if (!skb) {
  794. printk(KERN_CRIT "%s: no memory, lost register appl.\n",
  795. card->name);
  796. return;
  797. }
  798. p = skb->data;
  799. _put_byte(&p, 0);
  800. _put_byte(&p, 0);
  801. _put_byte(&p, SEND_REGISTER);
  802. _put_word(&p, appl);
  803. _put_word(&p, 1024 * (nconn + 1));
  804. _put_word(&p, nconn);
  805. _put_word(&p, rp->datablkcnt);
  806. _put_word(&p, rp->datablklen);
  807. skb_put(skb, (u8 *)p - (u8 *)skb->data);
  808. skb_queue_tail(&card->dma->send_queue, skb);
  809. spin_lock_irqsave(&card->lock, flags);
  810. c4_dispatch_tx(card);
  811. spin_unlock_irqrestore(&card->lock, flags);
  812. }
  813. }
  814. /* ------------------------------------------------------------- */
  815. static void c4_release_appl(struct capi_ctr *ctrl, u16 appl)
  816. {
  817. avmctrl_info *cinfo = (avmctrl_info *)(ctrl->driverdata);
  818. avmcard *card = cinfo->card;
  819. unsigned long flags;
  820. struct sk_buff *skb;
  821. void *p;
  822. spin_lock_irqsave(&card->lock, flags);
  823. capilib_release_appl(&cinfo->ncci_head, appl);
  824. spin_unlock_irqrestore(&card->lock, flags);
  825. if (ctrl->cnr == card->cardnr) {
  826. skb = alloc_skb(7, GFP_ATOMIC);
  827. if (!skb) {
  828. printk(KERN_CRIT "%s: no memory, lost release appl.\n",
  829. card->name);
  830. return;
  831. }
  832. p = skb->data;
  833. _put_byte(&p, 0);
  834. _put_byte(&p, 0);
  835. _put_byte(&p, SEND_RELEASE);
  836. _put_word(&p, appl);
  837. skb_put(skb, (u8 *)p - (u8 *)skb->data);
  838. skb_queue_tail(&card->dma->send_queue, skb);
  839. spin_lock_irqsave(&card->lock, flags);
  840. c4_dispatch_tx(card);
  841. spin_unlock_irqrestore(&card->lock, flags);
  842. }
  843. }
  844. /* ------------------------------------------------------------- */
  845. static u16 c4_send_message(struct capi_ctr *ctrl, struct sk_buff *skb)
  846. {
  847. avmctrl_info *cinfo = (avmctrl_info *)(ctrl->driverdata);
  848. avmcard *card = cinfo->card;
  849. u16 retval = CAPI_NOERROR;
  850. unsigned long flags;
  851. spin_lock_irqsave(&card->lock, flags);
  852. if (CAPIMSG_CMD(skb->data) == CAPI_DATA_B3_REQ) {
  853. retval = capilib_data_b3_req(&cinfo->ncci_head,
  854. CAPIMSG_APPID(skb->data),
  855. CAPIMSG_NCCI(skb->data),
  856. CAPIMSG_MSGID(skb->data));
  857. }
  858. if (retval == CAPI_NOERROR) {
  859. skb_queue_tail(&card->dma->send_queue, skb);
  860. c4_dispatch_tx(card);
  861. }
  862. spin_unlock_irqrestore(&card->lock, flags);
  863. return retval;
  864. }
  865. /* ------------------------------------------------------------- */
  866. static char *c4_procinfo(struct capi_ctr *ctrl)
  867. {
  868. avmctrl_info *cinfo = (avmctrl_info *)(ctrl->driverdata);
  869. if (!cinfo)
  870. return "";
  871. sprintf(cinfo->infobuf, "%s %s 0x%x %d 0x%lx",
  872. cinfo->cardname[0] ? cinfo->cardname : "-",
  873. cinfo->version[VER_DRIVER] ? cinfo->version[VER_DRIVER] : "-",
  874. cinfo->card ? cinfo->card->port : 0x0,
  875. cinfo->card ? cinfo->card->irq : 0,
  876. cinfo->card ? cinfo->card->membase : 0
  877. );
  878. return cinfo->infobuf;
  879. }
  880. static int c4_proc_show(struct seq_file *m, void *v)
  881. {
  882. struct capi_ctr *ctrl = m->private;
  883. avmctrl_info *cinfo = (avmctrl_info *)(ctrl->driverdata);
  884. avmcard *card = cinfo->card;
  885. u8 flag;
  886. char *s;
  887. seq_printf(m, "%-16s %s\n", "name", card->name);
  888. seq_printf(m, "%-16s 0x%x\n", "io", card->port);
  889. seq_printf(m, "%-16s %d\n", "irq", card->irq);
  890. seq_printf(m, "%-16s 0x%lx\n", "membase", card->membase);
  891. switch (card->cardtype) {
  892. case avm_b1isa: s = "B1 ISA"; break;
  893. case avm_b1pci: s = "B1 PCI"; break;
  894. case avm_b1pcmcia: s = "B1 PCMCIA"; break;
  895. case avm_m1: s = "M1"; break;
  896. case avm_m2: s = "M2"; break;
  897. case avm_t1isa: s = "T1 ISA (HEMA)"; break;
  898. case avm_t1pci: s = "T1 PCI"; break;
  899. case avm_c4: s = "C4"; break;
  900. case avm_c2: s = "C2"; break;
  901. default: s = "???"; break;
  902. }
  903. seq_printf(m, "%-16s %s\n", "type", s);
  904. if ((s = cinfo->version[VER_DRIVER]) != NULL)
  905. seq_printf(m, "%-16s %s\n", "ver_driver", s);
  906. if ((s = cinfo->version[VER_CARDTYPE]) != NULL)
  907. seq_printf(m, "%-16s %s\n", "ver_cardtype", s);
  908. if ((s = cinfo->version[VER_SERIAL]) != NULL)
  909. seq_printf(m, "%-16s %s\n", "ver_serial", s);
  910. if (card->cardtype != avm_m1) {
  911. flag = ((u8 *)(ctrl->profile.manu))[3];
  912. if (flag)
  913. seq_printf(m, "%-16s%s%s%s%s%s%s%s\n",
  914. "protocol",
  915. (flag & 0x01) ? " DSS1" : "",
  916. (flag & 0x02) ? " CT1" : "",
  917. (flag & 0x04) ? " VN3" : "",
  918. (flag & 0x08) ? " NI1" : "",
  919. (flag & 0x10) ? " AUSTEL" : "",
  920. (flag & 0x20) ? " ESS" : "",
  921. (flag & 0x40) ? " 1TR6" : ""
  922. );
  923. }
  924. if (card->cardtype != avm_m1) {
  925. flag = ((u8 *)(ctrl->profile.manu))[5];
  926. if (flag)
  927. seq_printf(m, "%-16s%s%s%s%s\n",
  928. "linetype",
  929. (flag & 0x01) ? " point to point" : "",
  930. (flag & 0x02) ? " point to multipoint" : "",
  931. (flag & 0x08) ? " leased line without D-channel" : "",
  932. (flag & 0x04) ? " leased line with D-channel" : ""
  933. );
  934. }
  935. seq_printf(m, "%-16s %s\n", "cardname", cinfo->cardname);
  936. return 0;
  937. }
  938. static int c4_proc_open(struct inode *inode, struct file *file)
  939. {
  940. return single_open(file, c4_proc_show, PDE_DATA(inode));
  941. }
  942. static const struct file_operations c4_proc_fops = {
  943. .owner = THIS_MODULE,
  944. .open = c4_proc_open,
  945. .read = seq_read,
  946. .llseek = seq_lseek,
  947. .release = single_release,
  948. };
  949. /* ------------------------------------------------------------- */
  950. static int c4_add_card(struct capicardparams *p, struct pci_dev *dev,
  951. int nr_controllers)
  952. {
  953. avmcard *card;
  954. avmctrl_info *cinfo;
  955. int retval;
  956. int i;
  957. card = b1_alloc_card(nr_controllers);
  958. if (!card) {
  959. printk(KERN_WARNING "c4: no memory.\n");
  960. retval = -ENOMEM;
  961. goto err;
  962. }
  963. card->dma = avmcard_dma_alloc("c4", dev, 2048 + 128, 2048 + 128);
  964. if (!card->dma) {
  965. printk(KERN_WARNING "c4: no memory.\n");
  966. retval = -ENOMEM;
  967. goto err_free;
  968. }
  969. sprintf(card->name, "c%d-%x", nr_controllers, p->port);
  970. card->port = p->port;
  971. card->irq = p->irq;
  972. card->membase = p->membase;
  973. card->cardtype = (nr_controllers == 4) ? avm_c4 : avm_c2;
  974. if (!request_region(card->port, AVMB1_PORTLEN, card->name)) {
  975. printk(KERN_WARNING "c4: ports 0x%03x-0x%03x in use.\n",
  976. card->port, card->port + AVMB1_PORTLEN);
  977. retval = -EBUSY;
  978. goto err_free_dma;
  979. }
  980. card->mbase = ioremap(card->membase, 128);
  981. if (card->mbase == NULL) {
  982. printk(KERN_NOTICE "c4: can't remap memory at 0x%lx\n",
  983. card->membase);
  984. retval = -EIO;
  985. goto err_release_region;
  986. }
  987. retval = c4_detect(card);
  988. if (retval != 0) {
  989. printk(KERN_NOTICE "c4: NO card at 0x%x error(%d)\n",
  990. card->port, retval);
  991. retval = -EIO;
  992. goto err_unmap;
  993. }
  994. c4_reset(card);
  995. retval = request_irq(card->irq, c4_interrupt, IRQF_SHARED, card->name, card);
  996. if (retval) {
  997. printk(KERN_ERR "c4: unable to get IRQ %d.\n", card->irq);
  998. retval = -EBUSY;
  999. goto err_unmap;
  1000. }
  1001. for (i = 0; i < nr_controllers; i++) {
  1002. cinfo = &card->ctrlinfo[i];
  1003. cinfo->capi_ctrl.owner = THIS_MODULE;
  1004. cinfo->capi_ctrl.driver_name = "c4";
  1005. cinfo->capi_ctrl.driverdata = cinfo;
  1006. cinfo->capi_ctrl.register_appl = c4_register_appl;
  1007. cinfo->capi_ctrl.release_appl = c4_release_appl;
  1008. cinfo->capi_ctrl.send_message = c4_send_message;
  1009. cinfo->capi_ctrl.load_firmware = c4_load_firmware;
  1010. cinfo->capi_ctrl.reset_ctr = c4_reset_ctr;
  1011. cinfo->capi_ctrl.procinfo = c4_procinfo;
  1012. cinfo->capi_ctrl.proc_fops = &c4_proc_fops;
  1013. strcpy(cinfo->capi_ctrl.name, card->name);
  1014. retval = attach_capi_ctr(&cinfo->capi_ctrl);
  1015. if (retval) {
  1016. printk(KERN_ERR "c4: attach controller failed (%d).\n", i);
  1017. for (i--; i >= 0; i--) {
  1018. cinfo = &card->ctrlinfo[i];
  1019. detach_capi_ctr(&cinfo->capi_ctrl);
  1020. }
  1021. goto err_free_irq;
  1022. }
  1023. if (i == 0)
  1024. card->cardnr = cinfo->capi_ctrl.cnr;
  1025. }
  1026. printk(KERN_INFO "c4: AVM C%d at i/o %#x, irq %d, mem %#lx\n",
  1027. nr_controllers, card->port, card->irq,
  1028. card->membase);
  1029. pci_set_drvdata(dev, card);
  1030. return 0;
  1031. err_free_irq:
  1032. free_irq(card->irq, card);
  1033. err_unmap:
  1034. iounmap(card->mbase);
  1035. err_release_region:
  1036. release_region(card->port, AVMB1_PORTLEN);
  1037. err_free_dma:
  1038. avmcard_dma_free(card->dma);
  1039. err_free:
  1040. b1_free_card(card);
  1041. err:
  1042. return retval;
  1043. }
  1044. /* ------------------------------------------------------------- */
  1045. static int c4_probe(struct pci_dev *dev, const struct pci_device_id *ent)
  1046. {
  1047. int nr = ent->driver_data;
  1048. int retval = 0;
  1049. struct capicardparams param;
  1050. if (pci_enable_device(dev) < 0) {
  1051. printk(KERN_ERR "c4: failed to enable AVM-C%d\n", nr);
  1052. return -ENODEV;
  1053. }
  1054. pci_set_master(dev);
  1055. param.port = pci_resource_start(dev, 1);
  1056. param.irq = dev->irq;
  1057. param.membase = pci_resource_start(dev, 0);
  1058. printk(KERN_INFO "c4: PCI BIOS reports AVM-C%d at i/o %#x, irq %d, mem %#x\n",
  1059. nr, param.port, param.irq, param.membase);
  1060. retval = c4_add_card(&param, dev, nr);
  1061. if (retval != 0) {
  1062. printk(KERN_ERR "c4: no AVM-C%d at i/o %#x, irq %d detected, mem %#x\n",
  1063. nr, param.port, param.irq, param.membase);
  1064. pci_disable_device(dev);
  1065. return -ENODEV;
  1066. }
  1067. return 0;
  1068. }
  1069. static struct pci_driver c4_pci_driver = {
  1070. .name = "c4",
  1071. .id_table = c4_pci_tbl,
  1072. .probe = c4_probe,
  1073. .remove = c4_remove,
  1074. };
  1075. static struct capi_driver capi_driver_c2 = {
  1076. .name = "c2",
  1077. .revision = "1.0",
  1078. };
  1079. static struct capi_driver capi_driver_c4 = {
  1080. .name = "c4",
  1081. .revision = "1.0",
  1082. };
  1083. static int __init c4_init(void)
  1084. {
  1085. char *p;
  1086. char rev[32];
  1087. int err;
  1088. if ((p = strchr(revision, ':')) != NULL && p[1]) {
  1089. strlcpy(rev, p + 2, 32);
  1090. if ((p = strchr(rev, '$')) != NULL && p > rev)
  1091. *(p - 1) = 0;
  1092. } else
  1093. strcpy(rev, "1.0");
  1094. err = pci_register_driver(&c4_pci_driver);
  1095. if (!err) {
  1096. strlcpy(capi_driver_c2.revision, rev, 32);
  1097. register_capi_driver(&capi_driver_c2);
  1098. strlcpy(capi_driver_c4.revision, rev, 32);
  1099. register_capi_driver(&capi_driver_c4);
  1100. printk(KERN_INFO "c4: revision %s\n", rev);
  1101. }
  1102. return err;
  1103. }
  1104. static void __exit c4_exit(void)
  1105. {
  1106. unregister_capi_driver(&capi_driver_c2);
  1107. unregister_capi_driver(&capi_driver_c4);
  1108. pci_unregister_driver(&c4_pci_driver);
  1109. }
  1110. module_init(c4_init);
  1111. module_exit(c4_exit);