b1.c 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817
  1. /* $Id: b1.c,v 1.1.2.2 2004/01/16 21:09:27 keil Exp $
  2. *
  3. * Common module for AVM B1 cards.
  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/pci.h>
  14. #include <linux/proc_fs.h>
  15. #include <linux/seq_file.h>
  16. #include <linux/skbuff.h>
  17. #include <linux/delay.h>
  18. #include <linux/mm.h>
  19. #include <linux/interrupt.h>
  20. #include <linux/ioport.h>
  21. #include <linux/capi.h>
  22. #include <linux/kernelcapi.h>
  23. #include <linux/slab.h>
  24. #include <asm/io.h>
  25. #include <linux/init.h>
  26. #include <asm/uaccess.h>
  27. #include <linux/netdevice.h>
  28. #include <linux/isdn/capilli.h>
  29. #include "avmcard.h"
  30. #include <linux/isdn/capicmd.h>
  31. #include <linux/isdn/capiutil.h>
  32. static char *revision = "$Revision: 1.1.2.2 $";
  33. /* ------------------------------------------------------------- */
  34. MODULE_DESCRIPTION("CAPI4Linux: Common support for active AVM cards");
  35. MODULE_AUTHOR("Carsten Paeth");
  36. MODULE_LICENSE("GPL");
  37. /* ------------------------------------------------------------- */
  38. int b1_irq_table[16] =
  39. {0,
  40. 0,
  41. 0,
  42. 192, /* irq 3 */
  43. 32, /* irq 4 */
  44. 160, /* irq 5 */
  45. 96, /* irq 6 */
  46. 224, /* irq 7 */
  47. 0,
  48. 64, /* irq 9 */
  49. 80, /* irq 10 */
  50. 208, /* irq 11 */
  51. 48, /* irq 12 */
  52. 0,
  53. 0,
  54. 112, /* irq 15 */
  55. };
  56. /* ------------------------------------------------------------- */
  57. avmcard *b1_alloc_card(int nr_controllers)
  58. {
  59. avmcard *card;
  60. avmctrl_info *cinfo;
  61. int i;
  62. card = kzalloc(sizeof(*card), GFP_KERNEL);
  63. if (!card)
  64. return NULL;
  65. cinfo = kzalloc(sizeof(*cinfo) * nr_controllers, GFP_KERNEL);
  66. if (!cinfo) {
  67. kfree(card);
  68. return NULL;
  69. }
  70. card->ctrlinfo = cinfo;
  71. for (i = 0; i < nr_controllers; i++) {
  72. INIT_LIST_HEAD(&cinfo[i].ncci_head);
  73. cinfo[i].card = card;
  74. }
  75. spin_lock_init(&card->lock);
  76. card->nr_controllers = nr_controllers;
  77. return card;
  78. }
  79. /* ------------------------------------------------------------- */
  80. void b1_free_card(avmcard *card)
  81. {
  82. kfree(card->ctrlinfo);
  83. kfree(card);
  84. }
  85. /* ------------------------------------------------------------- */
  86. int b1_detect(unsigned int base, enum avmcardtype cardtype)
  87. {
  88. int onoff, i;
  89. /*
  90. * Statusregister 0000 00xx
  91. */
  92. if ((inb(base + B1_INSTAT) & 0xfc)
  93. || (inb(base + B1_OUTSTAT) & 0xfc))
  94. return 1;
  95. /*
  96. * Statusregister 0000 001x
  97. */
  98. b1outp(base, B1_INSTAT, 0x2); /* enable irq */
  99. /* b1outp(base, B1_OUTSTAT, 0x2); */
  100. if ((inb(base + B1_INSTAT) & 0xfe) != 0x2
  101. /* || (inb(base + B1_OUTSTAT) & 0xfe) != 0x2 */)
  102. return 2;
  103. /*
  104. * Statusregister 0000 000x
  105. */
  106. b1outp(base, B1_INSTAT, 0x0); /* disable irq */
  107. b1outp(base, B1_OUTSTAT, 0x0);
  108. if ((inb(base + B1_INSTAT) & 0xfe)
  109. || (inb(base + B1_OUTSTAT) & 0xfe))
  110. return 3;
  111. for (onoff = !0, i = 0; i < 10; i++) {
  112. b1_set_test_bit(base, cardtype, onoff);
  113. if (b1_get_test_bit(base, cardtype) != onoff)
  114. return 4;
  115. onoff = !onoff;
  116. }
  117. if (cardtype == avm_m1)
  118. return 0;
  119. if ((b1_rd_reg(base, B1_STAT1(cardtype)) & 0x0f) != 0x01)
  120. return 5;
  121. return 0;
  122. }
  123. void b1_getrevision(avmcard *card)
  124. {
  125. card->class = inb(card->port + B1_ANALYSE);
  126. card->revision = inb(card->port + B1_REVISION);
  127. }
  128. #define FWBUF_SIZE 256
  129. int b1_load_t4file(avmcard *card, capiloaddatapart *t4file)
  130. {
  131. unsigned char buf[FWBUF_SIZE];
  132. unsigned char *dp;
  133. int i, left;
  134. unsigned int base = card->port;
  135. dp = t4file->data;
  136. left = t4file->len;
  137. while (left > FWBUF_SIZE) {
  138. if (t4file->user) {
  139. if (copy_from_user(buf, dp, FWBUF_SIZE))
  140. return -EFAULT;
  141. } else {
  142. memcpy(buf, dp, FWBUF_SIZE);
  143. }
  144. for (i = 0; i < FWBUF_SIZE; i++)
  145. if (b1_save_put_byte(base, buf[i]) < 0) {
  146. printk(KERN_ERR "%s: corrupted firmware file ?\n",
  147. card->name);
  148. return -EIO;
  149. }
  150. left -= FWBUF_SIZE;
  151. dp += FWBUF_SIZE;
  152. }
  153. if (left) {
  154. if (t4file->user) {
  155. if (copy_from_user(buf, dp, left))
  156. return -EFAULT;
  157. } else {
  158. memcpy(buf, dp, left);
  159. }
  160. for (i = 0; i < left; i++)
  161. if (b1_save_put_byte(base, buf[i]) < 0) {
  162. printk(KERN_ERR "%s: corrupted firmware file ?\n",
  163. card->name);
  164. return -EIO;
  165. }
  166. }
  167. return 0;
  168. }
  169. int b1_load_config(avmcard *card, capiloaddatapart *config)
  170. {
  171. unsigned char buf[FWBUF_SIZE];
  172. unsigned char *dp;
  173. unsigned int base = card->port;
  174. int i, j, left;
  175. dp = config->data;
  176. left = config->len;
  177. if (left) {
  178. b1_put_byte(base, SEND_CONFIG);
  179. b1_put_word(base, 1);
  180. b1_put_byte(base, SEND_CONFIG);
  181. b1_put_word(base, left);
  182. }
  183. while (left > FWBUF_SIZE) {
  184. if (config->user) {
  185. if (copy_from_user(buf, dp, FWBUF_SIZE))
  186. return -EFAULT;
  187. } else {
  188. memcpy(buf, dp, FWBUF_SIZE);
  189. }
  190. for (i = 0; i < FWBUF_SIZE; ) {
  191. b1_put_byte(base, SEND_CONFIG);
  192. for (j = 0; j < 4; j++) {
  193. b1_put_byte(base, buf[i++]);
  194. }
  195. }
  196. left -= FWBUF_SIZE;
  197. dp += FWBUF_SIZE;
  198. }
  199. if (left) {
  200. if (config->user) {
  201. if (copy_from_user(buf, dp, left))
  202. return -EFAULT;
  203. } else {
  204. memcpy(buf, dp, left);
  205. }
  206. for (i = 0; i < left; ) {
  207. b1_put_byte(base, SEND_CONFIG);
  208. for (j = 0; j < 4; j++) {
  209. if (i < left)
  210. b1_put_byte(base, buf[i++]);
  211. else
  212. b1_put_byte(base, 0);
  213. }
  214. }
  215. }
  216. return 0;
  217. }
  218. int b1_loaded(avmcard *card)
  219. {
  220. unsigned int base = card->port;
  221. unsigned long stop;
  222. unsigned char ans;
  223. unsigned long tout = 2;
  224. for (stop = jiffies + tout * HZ; time_before(jiffies, stop);) {
  225. if (b1_tx_empty(base))
  226. break;
  227. }
  228. if (!b1_tx_empty(base)) {
  229. printk(KERN_ERR "%s: b1_loaded: tx err, corrupted t4 file ?\n",
  230. card->name);
  231. return 0;
  232. }
  233. b1_put_byte(base, SEND_POLL);
  234. for (stop = jiffies + tout * HZ; time_before(jiffies, stop);) {
  235. if (b1_rx_full(base)) {
  236. if ((ans = b1_get_byte(base)) == RECEIVE_POLL) {
  237. return 1;
  238. }
  239. printk(KERN_ERR "%s: b1_loaded: got 0x%x, firmware not running\n",
  240. card->name, ans);
  241. return 0;
  242. }
  243. }
  244. printk(KERN_ERR "%s: b1_loaded: firmware not running\n", card->name);
  245. return 0;
  246. }
  247. /* ------------------------------------------------------------- */
  248. int b1_load_firmware(struct capi_ctr *ctrl, capiloaddata *data)
  249. {
  250. avmctrl_info *cinfo = (avmctrl_info *)(ctrl->driverdata);
  251. avmcard *card = cinfo->card;
  252. unsigned int port = card->port;
  253. unsigned long flags;
  254. int retval;
  255. b1_reset(port);
  256. if ((retval = b1_load_t4file(card, &data->firmware))) {
  257. b1_reset(port);
  258. printk(KERN_ERR "%s: failed to load t4file!!\n",
  259. card->name);
  260. return retval;
  261. }
  262. b1_disable_irq(port);
  263. if (data->configuration.len > 0 && data->configuration.data) {
  264. if ((retval = b1_load_config(card, &data->configuration))) {
  265. b1_reset(port);
  266. printk(KERN_ERR "%s: failed to load config!!\n",
  267. card->name);
  268. return retval;
  269. }
  270. }
  271. if (!b1_loaded(card)) {
  272. printk(KERN_ERR "%s: failed to load t4file.\n", card->name);
  273. return -EIO;
  274. }
  275. spin_lock_irqsave(&card->lock, flags);
  276. b1_setinterrupt(port, card->irq, card->cardtype);
  277. b1_put_byte(port, SEND_INIT);
  278. b1_put_word(port, CAPI_MAXAPPL);
  279. b1_put_word(port, AVM_NCCI_PER_CHANNEL * 2);
  280. b1_put_word(port, ctrl->cnr - 1);
  281. spin_unlock_irqrestore(&card->lock, flags);
  282. return 0;
  283. }
  284. void b1_reset_ctr(struct capi_ctr *ctrl)
  285. {
  286. avmctrl_info *cinfo = (avmctrl_info *)(ctrl->driverdata);
  287. avmcard *card = cinfo->card;
  288. unsigned int port = card->port;
  289. unsigned long flags;
  290. b1_reset(port);
  291. b1_reset(port);
  292. memset(cinfo->version, 0, sizeof(cinfo->version));
  293. spin_lock_irqsave(&card->lock, flags);
  294. capilib_release(&cinfo->ncci_head);
  295. spin_unlock_irqrestore(&card->lock, flags);
  296. capi_ctr_down(ctrl);
  297. }
  298. void b1_register_appl(struct capi_ctr *ctrl,
  299. u16 appl,
  300. capi_register_params *rp)
  301. {
  302. avmctrl_info *cinfo = (avmctrl_info *)(ctrl->driverdata);
  303. avmcard *card = cinfo->card;
  304. unsigned int port = card->port;
  305. unsigned long flags;
  306. int nconn, want = rp->level3cnt;
  307. if (want > 0) nconn = want;
  308. else nconn = ctrl->profile.nbchannel * -want;
  309. if (nconn == 0) nconn = ctrl->profile.nbchannel;
  310. spin_lock_irqsave(&card->lock, flags);
  311. b1_put_byte(port, SEND_REGISTER);
  312. b1_put_word(port, appl);
  313. b1_put_word(port, 1024 * (nconn + 1));
  314. b1_put_word(port, nconn);
  315. b1_put_word(port, rp->datablkcnt);
  316. b1_put_word(port, rp->datablklen);
  317. spin_unlock_irqrestore(&card->lock, flags);
  318. }
  319. void b1_release_appl(struct capi_ctr *ctrl, u16 appl)
  320. {
  321. avmctrl_info *cinfo = (avmctrl_info *)(ctrl->driverdata);
  322. avmcard *card = cinfo->card;
  323. unsigned int port = card->port;
  324. unsigned long flags;
  325. spin_lock_irqsave(&card->lock, flags);
  326. capilib_release_appl(&cinfo->ncci_head, appl);
  327. b1_put_byte(port, SEND_RELEASE);
  328. b1_put_word(port, appl);
  329. spin_unlock_irqrestore(&card->lock, flags);
  330. }
  331. u16 b1_send_message(struct capi_ctr *ctrl, struct sk_buff *skb)
  332. {
  333. avmctrl_info *cinfo = (avmctrl_info *)(ctrl->driverdata);
  334. avmcard *card = cinfo->card;
  335. unsigned int port = card->port;
  336. unsigned long flags;
  337. u16 len = CAPIMSG_LEN(skb->data);
  338. u8 cmd = CAPIMSG_COMMAND(skb->data);
  339. u8 subcmd = CAPIMSG_SUBCOMMAND(skb->data);
  340. u16 dlen, retval;
  341. spin_lock_irqsave(&card->lock, flags);
  342. if (CAPICMD(cmd, subcmd) == CAPI_DATA_B3_REQ) {
  343. retval = capilib_data_b3_req(&cinfo->ncci_head,
  344. CAPIMSG_APPID(skb->data),
  345. CAPIMSG_NCCI(skb->data),
  346. CAPIMSG_MSGID(skb->data));
  347. if (retval != CAPI_NOERROR) {
  348. spin_unlock_irqrestore(&card->lock, flags);
  349. return retval;
  350. }
  351. dlen = CAPIMSG_DATALEN(skb->data);
  352. b1_put_byte(port, SEND_DATA_B3_REQ);
  353. b1_put_slice(port, skb->data, len);
  354. b1_put_slice(port, skb->data + len, dlen);
  355. } else {
  356. b1_put_byte(port, SEND_MESSAGE);
  357. b1_put_slice(port, skb->data, len);
  358. }
  359. spin_unlock_irqrestore(&card->lock, flags);
  360. dev_kfree_skb_any(skb);
  361. return CAPI_NOERROR;
  362. }
  363. /* ------------------------------------------------------------- */
  364. void b1_parse_version(avmctrl_info *cinfo)
  365. {
  366. struct capi_ctr *ctrl = &cinfo->capi_ctrl;
  367. avmcard *card = cinfo->card;
  368. capi_profile *profp;
  369. u8 *dversion;
  370. u8 flag;
  371. int i, j;
  372. for (j = 0; j < AVM_MAXVERSION; j++)
  373. cinfo->version[j] = "";
  374. for (i = 0, j = 0;
  375. j < AVM_MAXVERSION && i < cinfo->versionlen;
  376. j++, i += cinfo->versionbuf[i] + 1)
  377. cinfo->version[j] = &cinfo->versionbuf[i + 1];
  378. strlcpy(ctrl->serial, cinfo->version[VER_SERIAL], sizeof(ctrl->serial));
  379. memcpy(&ctrl->profile, cinfo->version[VER_PROFILE], sizeof(capi_profile));
  380. strlcpy(ctrl->manu, "AVM GmbH", sizeof(ctrl->manu));
  381. dversion = cinfo->version[VER_DRIVER];
  382. ctrl->version.majorversion = 2;
  383. ctrl->version.minorversion = 0;
  384. ctrl->version.majormanuversion = (((dversion[0] - '0') & 0xf) << 4);
  385. ctrl->version.majormanuversion |= ((dversion[2] - '0') & 0xf);
  386. ctrl->version.minormanuversion = (dversion[3] - '0') << 4;
  387. ctrl->version.minormanuversion |=
  388. (dversion[5] - '0') * 10 + ((dversion[6] - '0') & 0xf);
  389. profp = &ctrl->profile;
  390. flag = ((u8 *)(profp->manu))[1];
  391. switch (flag) {
  392. case 0: if (cinfo->version[VER_CARDTYPE])
  393. strcpy(cinfo->cardname, cinfo->version[VER_CARDTYPE]);
  394. else strcpy(cinfo->cardname, "B1");
  395. break;
  396. case 3: strcpy(cinfo->cardname, "PCMCIA B"); break;
  397. case 4: strcpy(cinfo->cardname, "PCMCIA M1"); break;
  398. case 5: strcpy(cinfo->cardname, "PCMCIA M2"); break;
  399. case 6: strcpy(cinfo->cardname, "B1 V3.0"); break;
  400. case 7: strcpy(cinfo->cardname, "B1 PCI"); break;
  401. default: sprintf(cinfo->cardname, "AVM?%u", (unsigned int)flag); break;
  402. }
  403. printk(KERN_NOTICE "%s: card %d \"%s\" ready.\n",
  404. card->name, ctrl->cnr, cinfo->cardname);
  405. flag = ((u8 *)(profp->manu))[3];
  406. if (flag)
  407. printk(KERN_NOTICE "%s: card %d Protocol:%s%s%s%s%s%s%s\n",
  408. card->name,
  409. ctrl->cnr,
  410. (flag & 0x01) ? " DSS1" : "",
  411. (flag & 0x02) ? " CT1" : "",
  412. (flag & 0x04) ? " VN3" : "",
  413. (flag & 0x08) ? " NI1" : "",
  414. (flag & 0x10) ? " AUSTEL" : "",
  415. (flag & 0x20) ? " ESS" : "",
  416. (flag & 0x40) ? " 1TR6" : ""
  417. );
  418. flag = ((u8 *)(profp->manu))[5];
  419. if (flag)
  420. printk(KERN_NOTICE "%s: card %d Linetype:%s%s%s%s\n",
  421. card->name,
  422. ctrl->cnr,
  423. (flag & 0x01) ? " point to point" : "",
  424. (flag & 0x02) ? " point to multipoint" : "",
  425. (flag & 0x08) ? " leased line without D-channel" : "",
  426. (flag & 0x04) ? " leased line with D-channel" : ""
  427. );
  428. }
  429. /* ------------------------------------------------------------- */
  430. irqreturn_t b1_interrupt(int interrupt, void *devptr)
  431. {
  432. avmcard *card = devptr;
  433. avmctrl_info *cinfo = &card->ctrlinfo[0];
  434. struct capi_ctr *ctrl = &cinfo->capi_ctrl;
  435. unsigned char b1cmd;
  436. struct sk_buff *skb;
  437. unsigned ApplId;
  438. unsigned MsgLen;
  439. unsigned DataB3Len;
  440. unsigned NCCI;
  441. unsigned WindowSize;
  442. unsigned long flags;
  443. spin_lock_irqsave(&card->lock, flags);
  444. if (!b1_rx_full(card->port)) {
  445. spin_unlock_irqrestore(&card->lock, flags);
  446. return IRQ_NONE;
  447. }
  448. b1cmd = b1_get_byte(card->port);
  449. switch (b1cmd) {
  450. case RECEIVE_DATA_B3_IND:
  451. ApplId = (unsigned) b1_get_word(card->port);
  452. MsgLen = b1_get_slice(card->port, card->msgbuf);
  453. DataB3Len = b1_get_slice(card->port, card->databuf);
  454. spin_unlock_irqrestore(&card->lock, flags);
  455. if (MsgLen < 30) { /* not CAPI 64Bit */
  456. memset(card->msgbuf + MsgLen, 0, 30-MsgLen);
  457. MsgLen = 30;
  458. CAPIMSG_SETLEN(card->msgbuf, 30);
  459. }
  460. if (!(skb = alloc_skb(DataB3Len + MsgLen, GFP_ATOMIC))) {
  461. printk(KERN_ERR "%s: incoming packet dropped\n",
  462. card->name);
  463. } else {
  464. memcpy(skb_put(skb, MsgLen), card->msgbuf, MsgLen);
  465. memcpy(skb_put(skb, DataB3Len), card->databuf, DataB3Len);
  466. capi_ctr_handle_message(ctrl, ApplId, skb);
  467. }
  468. break;
  469. case RECEIVE_MESSAGE:
  470. ApplId = (unsigned) b1_get_word(card->port);
  471. MsgLen = b1_get_slice(card->port, card->msgbuf);
  472. if (!(skb = alloc_skb(MsgLen, GFP_ATOMIC))) {
  473. printk(KERN_ERR "%s: incoming packet dropped\n",
  474. card->name);
  475. spin_unlock_irqrestore(&card->lock, flags);
  476. } else {
  477. memcpy(skb_put(skb, MsgLen), card->msgbuf, MsgLen);
  478. if (CAPIMSG_CMD(skb->data) == CAPI_DATA_B3_CONF)
  479. capilib_data_b3_conf(&cinfo->ncci_head, ApplId,
  480. CAPIMSG_NCCI(skb->data),
  481. CAPIMSG_MSGID(skb->data));
  482. spin_unlock_irqrestore(&card->lock, flags);
  483. capi_ctr_handle_message(ctrl, ApplId, skb);
  484. }
  485. break;
  486. case RECEIVE_NEW_NCCI:
  487. ApplId = b1_get_word(card->port);
  488. NCCI = b1_get_word(card->port);
  489. WindowSize = b1_get_word(card->port);
  490. capilib_new_ncci(&cinfo->ncci_head, ApplId, NCCI, WindowSize);
  491. spin_unlock_irqrestore(&card->lock, flags);
  492. break;
  493. case RECEIVE_FREE_NCCI:
  494. ApplId = b1_get_word(card->port);
  495. NCCI = b1_get_word(card->port);
  496. if (NCCI != 0xffffffff)
  497. capilib_free_ncci(&cinfo->ncci_head, ApplId, NCCI);
  498. spin_unlock_irqrestore(&card->lock, flags);
  499. break;
  500. case RECEIVE_START:
  501. /* b1_put_byte(card->port, SEND_POLLACK); */
  502. spin_unlock_irqrestore(&card->lock, flags);
  503. capi_ctr_resume_output(ctrl);
  504. break;
  505. case RECEIVE_STOP:
  506. spin_unlock_irqrestore(&card->lock, flags);
  507. capi_ctr_suspend_output(ctrl);
  508. break;
  509. case RECEIVE_INIT:
  510. cinfo->versionlen = b1_get_slice(card->port, cinfo->versionbuf);
  511. spin_unlock_irqrestore(&card->lock, flags);
  512. b1_parse_version(cinfo);
  513. printk(KERN_INFO "%s: %s-card (%s) now active\n",
  514. card->name,
  515. cinfo->version[VER_CARDTYPE],
  516. cinfo->version[VER_DRIVER]);
  517. capi_ctr_ready(ctrl);
  518. break;
  519. case RECEIVE_TASK_READY:
  520. ApplId = (unsigned) b1_get_word(card->port);
  521. MsgLen = b1_get_slice(card->port, card->msgbuf);
  522. spin_unlock_irqrestore(&card->lock, flags);
  523. card->msgbuf[MsgLen] = 0;
  524. while (MsgLen > 0
  525. && (card->msgbuf[MsgLen - 1] == '\n'
  526. || card->msgbuf[MsgLen - 1] == '\r')) {
  527. card->msgbuf[MsgLen - 1] = 0;
  528. MsgLen--;
  529. }
  530. printk(KERN_INFO "%s: task %d \"%s\" ready.\n",
  531. card->name, ApplId, card->msgbuf);
  532. break;
  533. case RECEIVE_DEBUGMSG:
  534. MsgLen = b1_get_slice(card->port, card->msgbuf);
  535. spin_unlock_irqrestore(&card->lock, flags);
  536. card->msgbuf[MsgLen] = 0;
  537. while (MsgLen > 0
  538. && (card->msgbuf[MsgLen - 1] == '\n'
  539. || card->msgbuf[MsgLen - 1] == '\r')) {
  540. card->msgbuf[MsgLen - 1] = 0;
  541. MsgLen--;
  542. }
  543. printk(KERN_INFO "%s: DEBUG: %s\n", card->name, card->msgbuf);
  544. break;
  545. case 0xff:
  546. spin_unlock_irqrestore(&card->lock, flags);
  547. printk(KERN_ERR "%s: card removed ?\n", card->name);
  548. return IRQ_NONE;
  549. default:
  550. spin_unlock_irqrestore(&card->lock, flags);
  551. printk(KERN_ERR "%s: b1_interrupt: 0x%x ???\n",
  552. card->name, b1cmd);
  553. return IRQ_HANDLED;
  554. }
  555. return IRQ_HANDLED;
  556. }
  557. /* ------------------------------------------------------------- */
  558. static int b1ctl_proc_show(struct seq_file *m, void *v)
  559. {
  560. struct capi_ctr *ctrl = m->private;
  561. avmctrl_info *cinfo = (avmctrl_info *)(ctrl->driverdata);
  562. avmcard *card = cinfo->card;
  563. u8 flag;
  564. char *s;
  565. seq_printf(m, "%-16s %s\n", "name", card->name);
  566. seq_printf(m, "%-16s 0x%x\n", "io", card->port);
  567. seq_printf(m, "%-16s %d\n", "irq", card->irq);
  568. switch (card->cardtype) {
  569. case avm_b1isa: s = "B1 ISA"; break;
  570. case avm_b1pci: s = "B1 PCI"; break;
  571. case avm_b1pcmcia: s = "B1 PCMCIA"; break;
  572. case avm_m1: s = "M1"; break;
  573. case avm_m2: s = "M2"; break;
  574. case avm_t1isa: s = "T1 ISA (HEMA)"; break;
  575. case avm_t1pci: s = "T1 PCI"; break;
  576. case avm_c4: s = "C4"; break;
  577. case avm_c2: s = "C2"; break;
  578. default: s = "???"; break;
  579. }
  580. seq_printf(m, "%-16s %s\n", "type", s);
  581. if (card->cardtype == avm_t1isa)
  582. seq_printf(m, "%-16s %d\n", "cardnr", card->cardnr);
  583. if ((s = cinfo->version[VER_DRIVER]) != NULL)
  584. seq_printf(m, "%-16s %s\n", "ver_driver", s);
  585. if ((s = cinfo->version[VER_CARDTYPE]) != NULL)
  586. seq_printf(m, "%-16s %s\n", "ver_cardtype", s);
  587. if ((s = cinfo->version[VER_SERIAL]) != NULL)
  588. seq_printf(m, "%-16s %s\n", "ver_serial", s);
  589. if (card->cardtype != avm_m1) {
  590. flag = ((u8 *)(ctrl->profile.manu))[3];
  591. if (flag)
  592. seq_printf(m, "%-16s%s%s%s%s%s%s%s\n",
  593. "protocol",
  594. (flag & 0x01) ? " DSS1" : "",
  595. (flag & 0x02) ? " CT1" : "",
  596. (flag & 0x04) ? " VN3" : "",
  597. (flag & 0x08) ? " NI1" : "",
  598. (flag & 0x10) ? " AUSTEL" : "",
  599. (flag & 0x20) ? " ESS" : "",
  600. (flag & 0x40) ? " 1TR6" : ""
  601. );
  602. }
  603. if (card->cardtype != avm_m1) {
  604. flag = ((u8 *)(ctrl->profile.manu))[5];
  605. if (flag)
  606. seq_printf(m, "%-16s%s%s%s%s\n",
  607. "linetype",
  608. (flag & 0x01) ? " point to point" : "",
  609. (flag & 0x02) ? " point to multipoint" : "",
  610. (flag & 0x08) ? " leased line without D-channel" : "",
  611. (flag & 0x04) ? " leased line with D-channel" : ""
  612. );
  613. }
  614. seq_printf(m, "%-16s %s\n", "cardname", cinfo->cardname);
  615. return 0;
  616. }
  617. static int b1ctl_proc_open(struct inode *inode, struct file *file)
  618. {
  619. return single_open(file, b1ctl_proc_show, PDE_DATA(inode));
  620. }
  621. const struct file_operations b1ctl_proc_fops = {
  622. .owner = THIS_MODULE,
  623. .open = b1ctl_proc_open,
  624. .read = seq_read,
  625. .llseek = seq_lseek,
  626. .release = single_release,
  627. };
  628. EXPORT_SYMBOL(b1ctl_proc_fops);
  629. /* ------------------------------------------------------------- */
  630. #ifdef CONFIG_PCI
  631. avmcard_dmainfo *
  632. avmcard_dma_alloc(char *name, struct pci_dev *pdev, long rsize, long ssize)
  633. {
  634. avmcard_dmainfo *p;
  635. void *buf;
  636. p = kzalloc(sizeof(avmcard_dmainfo), GFP_KERNEL);
  637. if (!p) {
  638. printk(KERN_WARNING "%s: no memory.\n", name);
  639. goto err;
  640. }
  641. p->recvbuf.size = rsize;
  642. buf = pci_alloc_consistent(pdev, rsize, &p->recvbuf.dmaaddr);
  643. if (!buf) {
  644. printk(KERN_WARNING "%s: allocation of receive dma buffer failed.\n", name);
  645. goto err_kfree;
  646. }
  647. p->recvbuf.dmabuf = buf;
  648. p->sendbuf.size = ssize;
  649. buf = pci_alloc_consistent(pdev, ssize, &p->sendbuf.dmaaddr);
  650. if (!buf) {
  651. printk(KERN_WARNING "%s: allocation of send dma buffer failed.\n", name);
  652. goto err_free_consistent;
  653. }
  654. p->sendbuf.dmabuf = buf;
  655. skb_queue_head_init(&p->send_queue);
  656. return p;
  657. err_free_consistent:
  658. pci_free_consistent(p->pcidev, p->recvbuf.size,
  659. p->recvbuf.dmabuf, p->recvbuf.dmaaddr);
  660. err_kfree:
  661. kfree(p);
  662. err:
  663. return NULL;
  664. }
  665. void avmcard_dma_free(avmcard_dmainfo *p)
  666. {
  667. pci_free_consistent(p->pcidev, p->recvbuf.size,
  668. p->recvbuf.dmabuf, p->recvbuf.dmaaddr);
  669. pci_free_consistent(p->pcidev, p->sendbuf.size,
  670. p->sendbuf.dmabuf, p->sendbuf.dmaaddr);
  671. skb_queue_purge(&p->send_queue);
  672. kfree(p);
  673. }
  674. EXPORT_SYMBOL(avmcard_dma_alloc);
  675. EXPORT_SYMBOL(avmcard_dma_free);
  676. #endif
  677. EXPORT_SYMBOL(b1_irq_table);
  678. EXPORT_SYMBOL(b1_alloc_card);
  679. EXPORT_SYMBOL(b1_free_card);
  680. EXPORT_SYMBOL(b1_detect);
  681. EXPORT_SYMBOL(b1_getrevision);
  682. EXPORT_SYMBOL(b1_load_t4file);
  683. EXPORT_SYMBOL(b1_load_config);
  684. EXPORT_SYMBOL(b1_loaded);
  685. EXPORT_SYMBOL(b1_load_firmware);
  686. EXPORT_SYMBOL(b1_reset_ctr);
  687. EXPORT_SYMBOL(b1_register_appl);
  688. EXPORT_SYMBOL(b1_release_appl);
  689. EXPORT_SYMBOL(b1_send_message);
  690. EXPORT_SYMBOL(b1_parse_version);
  691. EXPORT_SYMBOL(b1_interrupt);
  692. static int __init b1_init(void)
  693. {
  694. char *p;
  695. char rev[32];
  696. if ((p = strchr(revision, ':')) != NULL && p[1]) {
  697. strlcpy(rev, p + 2, 32);
  698. if ((p = strchr(rev, '$')) != NULL && p > rev)
  699. *(p - 1) = 0;
  700. } else
  701. strcpy(rev, "1.0");
  702. printk(KERN_INFO "b1: revision %s\n", rev);
  703. return 0;
  704. }
  705. static void __exit b1_exit(void)
  706. {
  707. }
  708. module_init(b1_init);
  709. module_exit(b1_exit);