module.c 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814
  1. /* $Id: module.c,v 1.14.6.4 2001/09/23 22:24:32 kai Exp $
  2. *
  3. * ISDN lowlevel-module for the IBM ISDN-S0 Active 2000.
  4. *
  5. * Author Fritz Elfert
  6. * Copyright by Fritz Elfert <fritz@isdn4linux.de>
  7. *
  8. * This software may be used and distributed according to the terms
  9. * of the GNU General Public License, incorporated herein by reference.
  10. *
  11. * Thanks to Friedemann Baitinger and IBM Germany
  12. *
  13. */
  14. #include "act2000.h"
  15. #include "act2000_isa.h"
  16. #include "capi.h"
  17. #include <linux/module.h>
  18. #include <linux/slab.h>
  19. #include <linux/init.h>
  20. static unsigned short act2000_isa_ports[] =
  21. {
  22. 0x0200, 0x0240, 0x0280, 0x02c0, 0x0300, 0x0340, 0x0380,
  23. 0xcfe0, 0xcfa0, 0xcf60, 0xcf20, 0xcee0, 0xcea0, 0xce60,
  24. };
  25. static act2000_card *cards = (act2000_card *) NULL;
  26. /* Parameters to be set by insmod */
  27. static int act_bus = 0;
  28. static int act_port = -1; /* -1 = Autoprobe */
  29. static int act_irq = -1;
  30. static char *act_id = "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0";
  31. MODULE_DESCRIPTION( "ISDN4Linux: Driver for IBM Active 2000 ISDN card");
  32. MODULE_AUTHOR( "Fritz Elfert");
  33. MODULE_LICENSE( "GPL");
  34. MODULE_PARM_DESC(act_bus, "BusType of first card, 1=ISA, 2=MCA, 3=PCMCIA, currently only ISA");
  35. MODULE_PARM_DESC(membase, "Base port address of first card");
  36. MODULE_PARM_DESC(act_irq, "IRQ of first card");
  37. MODULE_PARM_DESC(act_id, "ID-String of first card");
  38. module_param(act_bus, int, 0);
  39. module_param(act_port, int, 0);
  40. module_param(act_irq, int, 0);
  41. module_param(act_id, charp, 0);
  42. static int act2000_addcard(int, int, int, char *);
  43. static act2000_chan *
  44. find_channel(act2000_card *card, int channel)
  45. {
  46. if ((channel >= 0) && (channel < ACT2000_BCH))
  47. return &(card->bch[channel]);
  48. printk(KERN_WARNING "act2000: Invalid channel %d\n", channel);
  49. return NULL;
  50. }
  51. /*
  52. * Free MSN list
  53. */
  54. static void
  55. act2000_clear_msn(act2000_card *card)
  56. {
  57. struct msn_entry *p = card->msn_list;
  58. struct msn_entry *q;
  59. unsigned long flags;
  60. spin_lock_irqsave(&card->lock, flags);
  61. card->msn_list = NULL;
  62. spin_unlock_irqrestore(&card->lock, flags);
  63. while (p) {
  64. q = p->next;
  65. kfree(p);
  66. p = q;
  67. }
  68. }
  69. /*
  70. * Find an MSN entry in the list.
  71. * If ia5 != 0, return IA5-encoded EAZ, else
  72. * return a bitmask with corresponding bit set.
  73. */
  74. static __u16
  75. act2000_find_msn(act2000_card *card, char *msn, int ia5)
  76. {
  77. struct msn_entry *p = card->msn_list;
  78. __u8 eaz = '0';
  79. while (p) {
  80. if (!strcmp(p->msn, msn)) {
  81. eaz = p->eaz;
  82. break;
  83. }
  84. p = p->next;
  85. }
  86. if (!ia5)
  87. return (1 << (eaz - '0'));
  88. else
  89. return eaz;
  90. }
  91. /*
  92. * Find an EAZ entry in the list.
  93. * return a string with corresponding msn.
  94. */
  95. char *
  96. act2000_find_eaz(act2000_card *card, char eaz)
  97. {
  98. struct msn_entry *p = card->msn_list;
  99. while (p) {
  100. if (p->eaz == eaz)
  101. return(p->msn);
  102. p = p->next;
  103. }
  104. return("\0");
  105. }
  106. /*
  107. * Add or delete an MSN to the MSN list
  108. *
  109. * First character of msneaz is EAZ, rest is MSN.
  110. * If length of eazmsn is 1, delete that entry.
  111. */
  112. static int
  113. act2000_set_msn(act2000_card *card, char *eazmsn)
  114. {
  115. struct msn_entry *p = card->msn_list;
  116. struct msn_entry *q = NULL;
  117. unsigned long flags;
  118. int i;
  119. if (!strlen(eazmsn))
  120. return 0;
  121. if (strlen(eazmsn) > 16)
  122. return -EINVAL;
  123. for (i = 0; i < strlen(eazmsn); i++)
  124. if (!isdigit(eazmsn[i]))
  125. return -EINVAL;
  126. if (strlen(eazmsn) == 1) {
  127. /* Delete a single MSN */
  128. while (p) {
  129. if (p->eaz == eazmsn[0]) {
  130. spin_lock_irqsave(&card->lock, flags);
  131. if (q)
  132. q->next = p->next;
  133. else
  134. card->msn_list = p->next;
  135. spin_unlock_irqrestore(&card->lock, flags);
  136. kfree(p);
  137. printk(KERN_DEBUG
  138. "Mapping for EAZ %c deleted\n",
  139. eazmsn[0]);
  140. return 0;
  141. }
  142. q = p;
  143. p = p->next;
  144. }
  145. return 0;
  146. }
  147. /* Add a single MSN */
  148. while (p) {
  149. /* Found in list, replace MSN */
  150. if (p->eaz == eazmsn[0]) {
  151. spin_lock_irqsave(&card->lock, flags);
  152. strcpy(p->msn, &eazmsn[1]);
  153. spin_unlock_irqrestore(&card->lock, flags);
  154. printk(KERN_DEBUG
  155. "Mapping for EAZ %c changed to %s\n",
  156. eazmsn[0],
  157. &eazmsn[1]);
  158. return 0;
  159. }
  160. p = p->next;
  161. }
  162. /* Not found in list, add new entry */
  163. p = kmalloc(sizeof(msn_entry), GFP_KERNEL);
  164. if (!p)
  165. return -ENOMEM;
  166. p->eaz = eazmsn[0];
  167. strcpy(p->msn, &eazmsn[1]);
  168. p->next = card->msn_list;
  169. spin_lock_irqsave(&card->lock, flags);
  170. card->msn_list = p;
  171. spin_unlock_irqrestore(&card->lock, flags);
  172. printk(KERN_DEBUG
  173. "Mapping %c -> %s added\n",
  174. eazmsn[0],
  175. &eazmsn[1]);
  176. return 0;
  177. }
  178. static void
  179. act2000_transmit(struct work_struct *work)
  180. {
  181. struct act2000_card *card =
  182. container_of(work, struct act2000_card, snd_tq);
  183. switch (card->bus) {
  184. case ACT2000_BUS_ISA:
  185. act2000_isa_send(card);
  186. break;
  187. case ACT2000_BUS_PCMCIA:
  188. case ACT2000_BUS_MCA:
  189. default:
  190. printk(KERN_WARNING
  191. "act2000_transmit: Illegal bustype %d\n", card->bus);
  192. }
  193. }
  194. static void
  195. act2000_receive(struct work_struct *work)
  196. {
  197. struct act2000_card *card =
  198. container_of(work, struct act2000_card, poll_tq);
  199. switch (card->bus) {
  200. case ACT2000_BUS_ISA:
  201. act2000_isa_receive(card);
  202. break;
  203. case ACT2000_BUS_PCMCIA:
  204. case ACT2000_BUS_MCA:
  205. default:
  206. printk(KERN_WARNING
  207. "act2000_receive: Illegal bustype %d\n", card->bus);
  208. }
  209. }
  210. static void
  211. act2000_poll(unsigned long data)
  212. {
  213. act2000_card * card = (act2000_card *)data;
  214. unsigned long flags;
  215. act2000_receive(&card->poll_tq);
  216. spin_lock_irqsave(&card->lock, flags);
  217. mod_timer(&card->ptimer, jiffies+3);
  218. spin_unlock_irqrestore(&card->lock, flags);
  219. }
  220. static int
  221. act2000_command(act2000_card * card, isdn_ctrl * c)
  222. {
  223. ulong a;
  224. act2000_chan *chan;
  225. act2000_cdef cdef;
  226. isdn_ctrl cmd;
  227. char tmp[17];
  228. int ret;
  229. unsigned long flags;
  230. void __user *arg;
  231. switch (c->command) {
  232. case ISDN_CMD_IOCTL:
  233. memcpy(&a, c->parm.num, sizeof(ulong));
  234. arg = (void __user *)a;
  235. switch (c->arg) {
  236. case ACT2000_IOCTL_LOADBOOT:
  237. switch (card->bus) {
  238. case ACT2000_BUS_ISA:
  239. ret = act2000_isa_download(card,
  240. arg);
  241. if (!ret) {
  242. card->flags |= ACT2000_FLAGS_LOADED;
  243. if (!(card->flags & ACT2000_FLAGS_IVALID)) {
  244. card->ptimer.expires = jiffies + 3;
  245. card->ptimer.function = act2000_poll;
  246. card->ptimer.data = (unsigned long)card;
  247. add_timer(&card->ptimer);
  248. }
  249. actcapi_manufacturer_req_errh(card);
  250. }
  251. break;
  252. default:
  253. printk(KERN_WARNING
  254. "act2000: Illegal BUS type %d\n",
  255. card->bus);
  256. ret = -EIO;
  257. }
  258. return ret;
  259. case ACT2000_IOCTL_SETPROTO:
  260. card->ptype = a?ISDN_PTYPE_EURO:ISDN_PTYPE_1TR6;
  261. if (!(card->flags & ACT2000_FLAGS_RUNNING))
  262. return 0;
  263. actcapi_manufacturer_req_net(card);
  264. return 0;
  265. case ACT2000_IOCTL_SETMSN:
  266. if (copy_from_user(tmp, arg,
  267. sizeof(tmp)))
  268. return -EFAULT;
  269. if ((ret = act2000_set_msn(card, tmp)))
  270. return ret;
  271. if (card->flags & ACT2000_FLAGS_RUNNING)
  272. return(actcapi_manufacturer_req_msn(card));
  273. return 0;
  274. case ACT2000_IOCTL_ADDCARD:
  275. if (copy_from_user(&cdef, arg,
  276. sizeof(cdef)))
  277. return -EFAULT;
  278. if (act2000_addcard(cdef.bus, cdef.port, cdef.irq, cdef.id))
  279. return -EIO;
  280. return 0;
  281. case ACT2000_IOCTL_TEST:
  282. if (!(card->flags & ACT2000_FLAGS_RUNNING))
  283. return -ENODEV;
  284. return 0;
  285. default:
  286. return -EINVAL;
  287. }
  288. break;
  289. case ISDN_CMD_DIAL:
  290. if (!(card->flags & ACT2000_FLAGS_RUNNING))
  291. return -ENODEV;
  292. if (!(chan = find_channel(card, c->arg & 0x0f)))
  293. break;
  294. spin_lock_irqsave(&card->lock, flags);
  295. if (chan->fsm_state != ACT2000_STATE_NULL) {
  296. spin_unlock_irqrestore(&card->lock, flags);
  297. printk(KERN_WARNING "Dial on channel with state %d\n",
  298. chan->fsm_state);
  299. return -EBUSY;
  300. }
  301. if (card->ptype == ISDN_PTYPE_EURO)
  302. tmp[0] = act2000_find_msn(card, c->parm.setup.eazmsn, 1);
  303. else
  304. tmp[0] = c->parm.setup.eazmsn[0];
  305. chan->fsm_state = ACT2000_STATE_OCALL;
  306. chan->callref = 0xffff;
  307. spin_unlock_irqrestore(&card->lock, flags);
  308. ret = actcapi_connect_req(card, chan, c->parm.setup.phone,
  309. tmp[0], c->parm.setup.si1,
  310. c->parm.setup.si2);
  311. if (ret) {
  312. cmd.driver = card->myid;
  313. cmd.command = ISDN_STAT_DHUP;
  314. cmd.arg &= 0x0f;
  315. card->interface.statcallb(&cmd);
  316. }
  317. return ret;
  318. case ISDN_CMD_ACCEPTD:
  319. if (!(card->flags & ACT2000_FLAGS_RUNNING))
  320. return -ENODEV;
  321. if (!(chan = find_channel(card, c->arg & 0x0f)))
  322. break;
  323. if (chan->fsm_state == ACT2000_STATE_ICALL)
  324. actcapi_select_b2_protocol_req(card, chan);
  325. return 0;
  326. case ISDN_CMD_ACCEPTB:
  327. if (!(card->flags & ACT2000_FLAGS_RUNNING))
  328. return -ENODEV;
  329. return 0;
  330. case ISDN_CMD_HANGUP:
  331. if (!(card->flags & ACT2000_FLAGS_RUNNING))
  332. return -ENODEV;
  333. if (!(chan = find_channel(card, c->arg & 0x0f)))
  334. break;
  335. switch (chan->fsm_state) {
  336. case ACT2000_STATE_ICALL:
  337. case ACT2000_STATE_BSETUP:
  338. actcapi_connect_resp(card, chan, 0x15);
  339. break;
  340. case ACT2000_STATE_ACTIVE:
  341. actcapi_disconnect_b3_req(card, chan);
  342. break;
  343. }
  344. return 0;
  345. case ISDN_CMD_SETEAZ:
  346. if (!(card->flags & ACT2000_FLAGS_RUNNING))
  347. return -ENODEV;
  348. if (!(chan = find_channel(card, c->arg & 0x0f)))
  349. break;
  350. if (strlen(c->parm.num)) {
  351. if (card->ptype == ISDN_PTYPE_EURO) {
  352. chan->eazmask = act2000_find_msn(card, c->parm.num, 0);
  353. }
  354. if (card->ptype == ISDN_PTYPE_1TR6) {
  355. int i;
  356. chan->eazmask = 0;
  357. for (i = 0; i < strlen(c->parm.num); i++)
  358. if (isdigit(c->parm.num[i]))
  359. chan->eazmask |= (1 << (c->parm.num[i] - '0'));
  360. }
  361. } else
  362. chan->eazmask = 0x3ff;
  363. actcapi_listen_req(card);
  364. return 0;
  365. case ISDN_CMD_CLREAZ:
  366. if (!(card->flags & ACT2000_FLAGS_RUNNING))
  367. return -ENODEV;
  368. if (!(chan = find_channel(card, c->arg & 0x0f)))
  369. break;
  370. chan->eazmask = 0;
  371. actcapi_listen_req(card);
  372. return 0;
  373. case ISDN_CMD_SETL2:
  374. if (!(card->flags & ACT2000_FLAGS_RUNNING))
  375. return -ENODEV;
  376. if (!(chan = find_channel(card, c->arg & 0x0f)))
  377. break;
  378. chan->l2prot = (c->arg >> 8);
  379. return 0;
  380. case ISDN_CMD_SETL3:
  381. if (!(card->flags & ACT2000_FLAGS_RUNNING))
  382. return -ENODEV;
  383. if ((c->arg >> 8) != ISDN_PROTO_L3_TRANS) {
  384. printk(KERN_WARNING "L3 protocol unknown\n");
  385. return -1;
  386. }
  387. if (!(chan = find_channel(card, c->arg & 0x0f)))
  388. break;
  389. chan->l3prot = (c->arg >> 8);
  390. return 0;
  391. }
  392. return -EINVAL;
  393. }
  394. static int
  395. act2000_sendbuf(act2000_card *card, int channel, int ack, struct sk_buff *skb)
  396. {
  397. struct sk_buff *xmit_skb;
  398. int len;
  399. act2000_chan *chan;
  400. actcapi_msg *msg;
  401. if (!(chan = find_channel(card, channel)))
  402. return -1;
  403. if (chan->fsm_state != ACT2000_STATE_ACTIVE)
  404. return -1;
  405. len = skb->len;
  406. if ((chan->queued + len) >= ACT2000_MAX_QUEUED)
  407. return 0;
  408. if (!len)
  409. return 0;
  410. if (skb_headroom(skb) < 19) {
  411. printk(KERN_WARNING "act2000_sendbuf: Headroom only %d\n",
  412. skb_headroom(skb));
  413. xmit_skb = alloc_skb(len + 19, GFP_ATOMIC);
  414. if (!xmit_skb) {
  415. printk(KERN_WARNING "act2000_sendbuf: Out of memory\n");
  416. return 0;
  417. }
  418. skb_reserve(xmit_skb, 19);
  419. skb_copy_from_linear_data(skb, skb_put(xmit_skb, len), len);
  420. } else {
  421. xmit_skb = skb_clone(skb, GFP_ATOMIC);
  422. if (!xmit_skb) {
  423. printk(KERN_WARNING "act2000_sendbuf: Out of memory\n");
  424. return 0;
  425. }
  426. }
  427. dev_kfree_skb(skb);
  428. msg = (actcapi_msg *)skb_push(xmit_skb, 19);
  429. msg->hdr.len = 19 + len;
  430. msg->hdr.applicationID = 1;
  431. msg->hdr.cmd.cmd = 0x86;
  432. msg->hdr.cmd.subcmd = 0x00;
  433. msg->hdr.msgnum = actcapi_nextsmsg(card);
  434. msg->msg.data_b3_req.datalen = len;
  435. msg->msg.data_b3_req.blocknr = (msg->hdr.msgnum & 0xff);
  436. msg->msg.data_b3_req.fakencci = MAKE_NCCI(chan->plci, 0, chan->ncci);
  437. msg->msg.data_b3_req.flags = ack; /* Will be set to 0 on actual sending */
  438. actcapi_debug_msg(xmit_skb, 1);
  439. chan->queued += len;
  440. skb_queue_tail(&card->sndq, xmit_skb);
  441. act2000_schedule_tx(card);
  442. return len;
  443. }
  444. /* Read the Status-replies from the Interface */
  445. static int
  446. act2000_readstatus(u_char __user * buf, int len, act2000_card * card)
  447. {
  448. int count;
  449. u_char __user *p;
  450. for (p = buf, count = 0; count < len; p++, count++) {
  451. if (card->status_buf_read == card->status_buf_write)
  452. return count;
  453. put_user(*card->status_buf_read++, p);
  454. if (card->status_buf_read > card->status_buf_end)
  455. card->status_buf_read = card->status_buf;
  456. }
  457. return count;
  458. }
  459. /*
  460. * Find card with given driverId
  461. */
  462. static inline act2000_card *
  463. act2000_findcard(int driverid)
  464. {
  465. act2000_card *p = cards;
  466. while (p) {
  467. if (p->myid == driverid)
  468. return p;
  469. p = p->next;
  470. }
  471. return (act2000_card *) 0;
  472. }
  473. /*
  474. * Wrapper functions for interface to linklevel
  475. */
  476. static int
  477. if_command(isdn_ctrl * c)
  478. {
  479. act2000_card *card = act2000_findcard(c->driver);
  480. if (card)
  481. return (act2000_command(card, c));
  482. printk(KERN_ERR
  483. "act2000: if_command %d called with invalid driverId %d!\n",
  484. c->command, c->driver);
  485. return -ENODEV;
  486. }
  487. static int
  488. if_writecmd(const u_char __user *buf, int len, int id, int channel)
  489. {
  490. act2000_card *card = act2000_findcard(id);
  491. if (card) {
  492. if (!(card->flags & ACT2000_FLAGS_RUNNING))
  493. return -ENODEV;
  494. return (len);
  495. }
  496. printk(KERN_ERR
  497. "act2000: if_writecmd called with invalid driverId!\n");
  498. return -ENODEV;
  499. }
  500. static int
  501. if_readstatus(u_char __user * buf, int len, int id, int channel)
  502. {
  503. act2000_card *card = act2000_findcard(id);
  504. if (card) {
  505. if (!(card->flags & ACT2000_FLAGS_RUNNING))
  506. return -ENODEV;
  507. return (act2000_readstatus(buf, len, card));
  508. }
  509. printk(KERN_ERR
  510. "act2000: if_readstatus called with invalid driverId!\n");
  511. return -ENODEV;
  512. }
  513. static int
  514. if_sendbuf(int id, int channel, int ack, struct sk_buff *skb)
  515. {
  516. act2000_card *card = act2000_findcard(id);
  517. if (card) {
  518. if (!(card->flags & ACT2000_FLAGS_RUNNING))
  519. return -ENODEV;
  520. return (act2000_sendbuf(card, channel, ack, skb));
  521. }
  522. printk(KERN_ERR
  523. "act2000: if_sendbuf called with invalid driverId!\n");
  524. return -ENODEV;
  525. }
  526. /*
  527. * Allocate a new card-struct, initialize it
  528. * link it into cards-list.
  529. */
  530. static void
  531. act2000_alloccard(int bus, int port, int irq, char *id)
  532. {
  533. int i;
  534. act2000_card *card;
  535. if (!(card = kzalloc(sizeof(act2000_card), GFP_KERNEL))) {
  536. printk(KERN_WARNING
  537. "act2000: (%s) Could not allocate card-struct.\n", id);
  538. return;
  539. }
  540. spin_lock_init(&card->lock);
  541. spin_lock_init(&card->mnlock);
  542. skb_queue_head_init(&card->sndq);
  543. skb_queue_head_init(&card->rcvq);
  544. skb_queue_head_init(&card->ackq);
  545. INIT_WORK(&card->snd_tq, act2000_transmit);
  546. INIT_WORK(&card->rcv_tq, actcapi_dispatch);
  547. INIT_WORK(&card->poll_tq, act2000_receive);
  548. init_timer(&card->ptimer);
  549. card->interface.owner = THIS_MODULE;
  550. card->interface.channels = ACT2000_BCH;
  551. card->interface.maxbufsize = 4000;
  552. card->interface.command = if_command;
  553. card->interface.writebuf_skb = if_sendbuf;
  554. card->interface.writecmd = if_writecmd;
  555. card->interface.readstat = if_readstatus;
  556. card->interface.features =
  557. ISDN_FEATURE_L2_X75I |
  558. ISDN_FEATURE_L2_HDLC |
  559. ISDN_FEATURE_L3_TRANS |
  560. ISDN_FEATURE_P_UNKNOWN;
  561. card->interface.hl_hdrlen = 20;
  562. card->ptype = ISDN_PTYPE_EURO;
  563. strlcpy(card->interface.id, id, sizeof(card->interface.id));
  564. for (i=0; i<ACT2000_BCH; i++) {
  565. card->bch[i].plci = 0x8000;
  566. card->bch[i].ncci = 0x8000;
  567. card->bch[i].l2prot = ISDN_PROTO_L2_X75I;
  568. card->bch[i].l3prot = ISDN_PROTO_L3_TRANS;
  569. }
  570. card->myid = -1;
  571. card->bus = bus;
  572. card->port = port;
  573. card->irq = irq;
  574. card->next = cards;
  575. cards = card;
  576. }
  577. /*
  578. * register card at linklevel
  579. */
  580. static int
  581. act2000_registercard(act2000_card * card)
  582. {
  583. switch (card->bus) {
  584. case ACT2000_BUS_ISA:
  585. break;
  586. case ACT2000_BUS_MCA:
  587. case ACT2000_BUS_PCMCIA:
  588. default:
  589. printk(KERN_WARNING
  590. "act2000: Illegal BUS type %d\n",
  591. card->bus);
  592. return -1;
  593. }
  594. if (!register_isdn(&card->interface)) {
  595. printk(KERN_WARNING
  596. "act2000: Unable to register %s\n",
  597. card->interface.id);
  598. return -1;
  599. }
  600. card->myid = card->interface.channels;
  601. sprintf(card->regname, "act2000-isdn (%s)", card->interface.id);
  602. return 0;
  603. }
  604. static void
  605. unregister_card(act2000_card * card)
  606. {
  607. isdn_ctrl cmd;
  608. cmd.command = ISDN_STAT_UNLOAD;
  609. cmd.driver = card->myid;
  610. card->interface.statcallb(&cmd);
  611. switch (card->bus) {
  612. case ACT2000_BUS_ISA:
  613. act2000_isa_release(card);
  614. break;
  615. case ACT2000_BUS_MCA:
  616. case ACT2000_BUS_PCMCIA:
  617. default:
  618. printk(KERN_WARNING
  619. "act2000: Invalid BUS type %d\n",
  620. card->bus);
  621. break;
  622. }
  623. }
  624. static int
  625. act2000_addcard(int bus, int port, int irq, char *id)
  626. {
  627. act2000_card *p;
  628. act2000_card *q = NULL;
  629. int initialized;
  630. int added = 0;
  631. int failed = 0;
  632. int i;
  633. if (!bus)
  634. bus = ACT2000_BUS_ISA;
  635. if (port != -1) {
  636. /* Port defined, do fixed setup */
  637. act2000_alloccard(bus, port, irq, id);
  638. } else {
  639. /* No port defined, perform autoprobing.
  640. * This may result in more than one card detected.
  641. */
  642. switch (bus) {
  643. case ACT2000_BUS_ISA:
  644. for (i = 0; i < ARRAY_SIZE(act2000_isa_ports); i++)
  645. if (act2000_isa_detect(act2000_isa_ports[i])) {
  646. printk(KERN_INFO "act2000: Detected "
  647. "ISA card at port 0x%x\n",
  648. act2000_isa_ports[i]);
  649. act2000_alloccard(bus,
  650. act2000_isa_ports[i], irq, id);
  651. }
  652. break;
  653. case ACT2000_BUS_MCA:
  654. case ACT2000_BUS_PCMCIA:
  655. default:
  656. printk(KERN_WARNING
  657. "act2000: addcard: Invalid BUS type %d\n", bus);
  658. }
  659. }
  660. if (!cards)
  661. return 1;
  662. p = cards;
  663. while (p) {
  664. initialized = 0;
  665. if (!p->interface.statcallb) {
  666. /* Not yet registered.
  667. * Try to register and activate it.
  668. */
  669. added++;
  670. switch (p->bus) {
  671. case ACT2000_BUS_ISA:
  672. if (act2000_isa_detect(p->port)) {
  673. if (act2000_registercard(p))
  674. break;
  675. if (act2000_isa_config_port(p, p->port)) {
  676. printk(KERN_WARNING
  677. "act2000: Could not request port 0x%04x\n",
  678. p->port);
  679. unregister_card(p);
  680. p->interface.statcallb = NULL;
  681. break;
  682. }
  683. if (act2000_isa_config_irq(p, p->irq)) {
  684. printk(KERN_INFO
  685. "act2000: No IRQ available, fallback to polling\n");
  686. /* Fall back to polled operation */
  687. p->irq = 0;
  688. }
  689. printk(KERN_INFO
  690. "act2000: ISA"
  691. "-type card at port "
  692. "0x%04x ",
  693. p->port);
  694. if (p->irq)
  695. printk("irq %d\n", p->irq);
  696. else
  697. printk("polled\n");
  698. initialized = 1;
  699. }
  700. break;
  701. case ACT2000_BUS_MCA:
  702. case ACT2000_BUS_PCMCIA:
  703. default:
  704. printk(KERN_WARNING
  705. "act2000: addcard: Invalid BUS type %d\n",
  706. p->bus);
  707. }
  708. } else
  709. /* Card already initialized */
  710. initialized = 1;
  711. if (initialized) {
  712. /* Init OK, next card ... */
  713. q = p;
  714. p = p->next;
  715. } else {
  716. /* Init failed, remove card from list, free memory */
  717. printk(KERN_WARNING
  718. "act2000: Initialization of %s failed\n",
  719. p->interface.id);
  720. if (q) {
  721. q->next = p->next;
  722. kfree(p);
  723. p = q->next;
  724. } else {
  725. cards = p->next;
  726. kfree(p);
  727. p = cards;
  728. }
  729. failed++;
  730. }
  731. }
  732. return (added - failed);
  733. }
  734. #define DRIVERNAME "IBM Active 2000 ISDN driver"
  735. static int __init act2000_init(void)
  736. {
  737. printk(KERN_INFO "%s\n", DRIVERNAME);
  738. if (!cards)
  739. act2000_addcard(act_bus, act_port, act_irq, act_id);
  740. if (!cards)
  741. printk(KERN_INFO "act2000: No cards defined yet\n");
  742. return 0;
  743. }
  744. static void __exit act2000_exit(void)
  745. {
  746. act2000_card *card = cards;
  747. act2000_card *last;
  748. while (card) {
  749. unregister_card(card);
  750. del_timer(&card->ptimer);
  751. card = card->next;
  752. }
  753. card = cards;
  754. while (card) {
  755. last = card;
  756. card = card->next;
  757. act2000_clear_msn(last);
  758. kfree(last);
  759. }
  760. printk(KERN_INFO "%s unloaded\n", DRIVERNAME);
  761. }
  762. module_init(act2000_init);
  763. module_exit(act2000_exit);