c4.c 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332
  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 int 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(inode)->data);
  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 __devinit c4_probe(struct pci_dev *dev,
  1046. const struct pci_device_id *ent)
  1047. {
  1048. int nr = ent->driver_data;
  1049. int retval = 0;
  1050. struct capicardparams param;
  1051. if (pci_enable_device(dev) < 0) {
  1052. printk(KERN_ERR "c4: failed to enable AVM-C%d\n", nr);
  1053. return -ENODEV;
  1054. }
  1055. pci_set_master(dev);
  1056. param.port = pci_resource_start(dev, 1);
  1057. param.irq = dev->irq;
  1058. param.membase = pci_resource_start(dev, 0);
  1059. printk(KERN_INFO "c4: PCI BIOS reports AVM-C%d at i/o %#x, irq %d, mem %#x\n",
  1060. nr, param.port, param.irq, param.membase);
  1061. retval = c4_add_card(&param, dev, nr);
  1062. if (retval != 0) {
  1063. printk(KERN_ERR "c4: no AVM-C%d at i/o %#x, irq %d detected, mem %#x\n",
  1064. nr, param.port, param.irq, param.membase);
  1065. pci_disable_device(dev);
  1066. return -ENODEV;
  1067. }
  1068. return 0;
  1069. }
  1070. static struct pci_driver c4_pci_driver = {
  1071. .name = "c4",
  1072. .id_table = c4_pci_tbl,
  1073. .probe = c4_probe,
  1074. .remove = c4_remove,
  1075. };
  1076. static struct capi_driver capi_driver_c2 = {
  1077. .name = "c2",
  1078. .revision = "1.0",
  1079. };
  1080. static struct capi_driver capi_driver_c4 = {
  1081. .name = "c4",
  1082. .revision = "1.0",
  1083. };
  1084. static int __init c4_init(void)
  1085. {
  1086. char *p;
  1087. char rev[32];
  1088. int err;
  1089. if ((p = strchr(revision, ':')) != NULL && p[1]) {
  1090. strlcpy(rev, p + 2, 32);
  1091. if ((p = strchr(rev, '$')) != NULL && p > rev)
  1092. *(p-1) = 0;
  1093. } else
  1094. strcpy(rev, "1.0");
  1095. err = pci_register_driver(&c4_pci_driver);
  1096. if (!err) {
  1097. strlcpy(capi_driver_c2.revision, rev, 32);
  1098. register_capi_driver(&capi_driver_c2);
  1099. strlcpy(capi_driver_c4.revision, rev, 32);
  1100. register_capi_driver(&capi_driver_c4);
  1101. printk(KERN_INFO "c4: revision %s\n", rev);
  1102. }
  1103. return err;
  1104. }
  1105. static void __exit c4_exit(void)
  1106. {
  1107. unregister_capi_driver(&capi_driver_c2);
  1108. unregister_capi_driver(&capi_driver_c4);
  1109. pci_unregister_driver(&c4_pci_driver);
  1110. }
  1111. module_init(c4_init);
  1112. module_exit(c4_exit);