hycapi.c 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786
  1. /* $Id: hycapi.c,v 1.8.6.4 2001/09/23 22:24:54 kai Exp $
  2. *
  3. * Linux driver for HYSDN cards, CAPI2.0-Interface.
  4. *
  5. * Author Ulrich Albrecht <u.albrecht@hypercope.de> for Hypercope GmbH
  6. * Copyright 2000 by Hypercope GmbH
  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. */
  12. #include <linux/module.h>
  13. #include <linux/proc_fs.h>
  14. #include <linux/seq_file.h>
  15. #include <linux/signal.h>
  16. #include <linux/kernel.h>
  17. #include <linux/skbuff.h>
  18. #include <linux/netdevice.h>
  19. #include <linux/slab.h>
  20. #define VER_DRIVER 0
  21. #define VER_CARDTYPE 1
  22. #define VER_HWID 2
  23. #define VER_SERIAL 3
  24. #define VER_OPTION 4
  25. #define VER_PROTO 5
  26. #define VER_PROFILE 6
  27. #define VER_CAPI 7
  28. #include "hysdn_defs.h"
  29. #include <linux/kernelcapi.h>
  30. static char hycapi_revision[] = "$Revision: 1.8.6.4 $";
  31. unsigned int hycapi_enable = 0xffffffff;
  32. module_param(hycapi_enable, uint, 0);
  33. typedef struct _hycapi_appl {
  34. unsigned int ctrl_mask;
  35. capi_register_params rp;
  36. struct sk_buff *listen_req[CAPI_MAXCONTR];
  37. } hycapi_appl;
  38. static hycapi_appl hycapi_applications[CAPI_MAXAPPL];
  39. static u16 hycapi_send_message(struct capi_ctr *ctrl, struct sk_buff *skb);
  40. static inline int _hycapi_appCheck(int app_id, int ctrl_no)
  41. {
  42. if ((ctrl_no <= 0) || (ctrl_no > CAPI_MAXCONTR) || (app_id <= 0) ||
  43. (app_id > CAPI_MAXAPPL))
  44. {
  45. printk(KERN_ERR "HYCAPI: Invalid request app_id %d for controller %d", app_id, ctrl_no);
  46. return -1;
  47. }
  48. return ((hycapi_applications[app_id - 1].ctrl_mask & (1 << (ctrl_no-1))) != 0);
  49. }
  50. /******************************
  51. Kernel-Capi callback reset_ctr
  52. ******************************/
  53. static void
  54. hycapi_reset_ctr(struct capi_ctr *ctrl)
  55. {
  56. hycapictrl_info *cinfo = ctrl->driverdata;
  57. #ifdef HYCAPI_PRINTFNAMES
  58. printk(KERN_NOTICE "HYCAPI hycapi_reset_ctr\n");
  59. #endif
  60. capilib_release(&cinfo->ncci_head);
  61. capi_ctr_down(ctrl);
  62. }
  63. /******************************
  64. Kernel-Capi callback remove_ctr
  65. ******************************/
  66. static void
  67. hycapi_remove_ctr(struct capi_ctr *ctrl)
  68. {
  69. int i;
  70. hycapictrl_info *cinfo = NULL;
  71. hysdn_card *card = NULL;
  72. #ifdef HYCAPI_PRINTFNAMES
  73. printk(KERN_NOTICE "HYCAPI hycapi_remove_ctr\n");
  74. #endif
  75. cinfo = (hycapictrl_info *)(ctrl->driverdata);
  76. if (!cinfo) {
  77. printk(KERN_ERR "No hycapictrl_info set!");
  78. return;
  79. }
  80. card = cinfo->card;
  81. capi_ctr_suspend_output(ctrl);
  82. for (i = 0; i < CAPI_MAXAPPL; i++) {
  83. if (hycapi_applications[i].listen_req[ctrl->cnr - 1]) {
  84. kfree_skb(hycapi_applications[i].listen_req[ctrl->cnr - 1]);
  85. hycapi_applications[i].listen_req[ctrl->cnr - 1] = NULL;
  86. }
  87. }
  88. detach_capi_ctr(ctrl);
  89. ctrl->driverdata = NULL;
  90. kfree(card->hyctrlinfo);
  91. card->hyctrlinfo = NULL;
  92. }
  93. /***********************************************************
  94. Queue a CAPI-message to the controller.
  95. ***********************************************************/
  96. static void
  97. hycapi_sendmsg_internal(struct capi_ctr *ctrl, struct sk_buff *skb)
  98. {
  99. hycapictrl_info *cinfo = (hycapictrl_info *)(ctrl->driverdata);
  100. hysdn_card *card = cinfo->card;
  101. spin_lock_irq(&cinfo->lock);
  102. #ifdef HYCAPI_PRINTFNAMES
  103. printk(KERN_NOTICE "hycapi_send_message\n");
  104. #endif
  105. cinfo->skbs[cinfo->in_idx++] = skb; /* add to buffer list */
  106. if (cinfo->in_idx >= HYSDN_MAX_CAPI_SKB)
  107. cinfo->in_idx = 0; /* wrap around */
  108. cinfo->sk_count++; /* adjust counter */
  109. if (cinfo->sk_count >= HYSDN_MAX_CAPI_SKB) {
  110. /* inform upper layers we're full */
  111. printk(KERN_ERR "HYSDN Card%d: CAPI-buffer overrun!\n",
  112. card->myid);
  113. capi_ctr_suspend_output(ctrl);
  114. }
  115. cinfo->tx_skb = skb;
  116. spin_unlock_irq(&cinfo->lock);
  117. schedule_work(&card->irq_queue);
  118. }
  119. /***********************************************************
  120. hycapi_register_internal
  121. Send down the CAPI_REGISTER-Command to the controller.
  122. This functions will also be used if the adapter has been rebooted to
  123. re-register any applications in the private list.
  124. ************************************************************/
  125. static void
  126. hycapi_register_internal(struct capi_ctr *ctrl, __u16 appl,
  127. capi_register_params *rp)
  128. {
  129. char ExtFeatureDefaults[] = "49 /0/0/0/0,*/1,*/2,*/3,*/4,*/5,*/6,*/7,*/8,*/9,*";
  130. hycapictrl_info *cinfo = (hycapictrl_info *)(ctrl->driverdata);
  131. hysdn_card *card = cinfo->card;
  132. struct sk_buff *skb;
  133. __u16 len;
  134. __u8 _command = 0xa0, _subcommand = 0x80;
  135. __u16 MessageNumber = 0x0000;
  136. __u16 MessageBufferSize = 0;
  137. int slen = strlen(ExtFeatureDefaults);
  138. #ifdef HYCAPI_PRINTFNAMES
  139. printk(KERN_NOTICE "hycapi_register_appl\n");
  140. #endif
  141. MessageBufferSize = rp->level3cnt * rp->datablkcnt * rp->datablklen;
  142. len = CAPI_MSG_BASELEN + 8 + slen + 1;
  143. if (!(skb = alloc_skb(len, GFP_ATOMIC))) {
  144. printk(KERN_ERR "HYSDN card%d: memory squeeze in hycapi_register_appl\n",
  145. card->myid);
  146. return;
  147. }
  148. skb_put_data(skb, &len, sizeof(__u16));
  149. skb_put_data(skb, &appl, sizeof(__u16));
  150. skb_put_data(skb, &_command, sizeof(__u8));
  151. skb_put_data(skb, &_subcommand, sizeof(__u8));
  152. skb_put_data(skb, &MessageNumber, sizeof(__u16));
  153. skb_put_data(skb, &MessageBufferSize, sizeof(__u16));
  154. skb_put_data(skb, &(rp->level3cnt), sizeof(__u16));
  155. skb_put_data(skb, &(rp->datablkcnt), sizeof(__u16));
  156. skb_put_data(skb, &(rp->datablklen), sizeof(__u16));
  157. skb_put_data(skb, ExtFeatureDefaults, slen);
  158. hycapi_applications[appl - 1].ctrl_mask |= (1 << (ctrl->cnr - 1));
  159. hycapi_send_message(ctrl, skb);
  160. }
  161. /************************************************************
  162. hycapi_restart_internal
  163. After an adapter has been rebootet, re-register all applications and
  164. send a LISTEN_REQ (if there has been such a thing )
  165. *************************************************************/
  166. static void hycapi_restart_internal(struct capi_ctr *ctrl)
  167. {
  168. int i;
  169. struct sk_buff *skb;
  170. #ifdef HYCAPI_PRINTFNAMES
  171. printk(KERN_WARNING "HYSDN: hycapi_restart_internal");
  172. #endif
  173. for (i = 0; i < CAPI_MAXAPPL; i++) {
  174. if (_hycapi_appCheck(i + 1, ctrl->cnr) == 1) {
  175. hycapi_register_internal(ctrl, i + 1,
  176. &hycapi_applications[i].rp);
  177. if (hycapi_applications[i].listen_req[ctrl->cnr - 1]) {
  178. skb = skb_copy(hycapi_applications[i].listen_req[ctrl->cnr - 1], GFP_ATOMIC);
  179. hycapi_sendmsg_internal(ctrl, skb);
  180. }
  181. }
  182. }
  183. }
  184. /*************************************************************
  185. Register an application.
  186. Error-checking is done for CAPI-compliance.
  187. The application is recorded in the internal list.
  188. *************************************************************/
  189. static void
  190. hycapi_register_appl(struct capi_ctr *ctrl, __u16 appl,
  191. capi_register_params *rp)
  192. {
  193. int MaxLogicalConnections = 0, MaxBDataBlocks = 0, MaxBDataLen = 0;
  194. hycapictrl_info *cinfo = (hycapictrl_info *)(ctrl->driverdata);
  195. hysdn_card *card = cinfo->card;
  196. int chk = _hycapi_appCheck(appl, ctrl->cnr);
  197. if (chk < 0) {
  198. return;
  199. }
  200. if (chk == 1) {
  201. printk(KERN_INFO "HYSDN: apl %d already registered\n", appl);
  202. return;
  203. }
  204. MaxBDataBlocks = rp->datablkcnt > CAPI_MAXDATAWINDOW ? CAPI_MAXDATAWINDOW : rp->datablkcnt;
  205. rp->datablkcnt = MaxBDataBlocks;
  206. MaxBDataLen = rp->datablklen < 1024 ? 1024 : rp->datablklen;
  207. rp->datablklen = MaxBDataLen;
  208. MaxLogicalConnections = rp->level3cnt;
  209. if (MaxLogicalConnections < 0) {
  210. MaxLogicalConnections = card->bchans * -MaxLogicalConnections;
  211. }
  212. if (MaxLogicalConnections == 0) {
  213. MaxLogicalConnections = card->bchans;
  214. }
  215. rp->level3cnt = MaxLogicalConnections;
  216. memcpy(&hycapi_applications[appl - 1].rp,
  217. rp, sizeof(capi_register_params));
  218. }
  219. /*********************************************************************
  220. hycapi_release_internal
  221. Send down a CAPI_RELEASE to the controller.
  222. *********************************************************************/
  223. static void hycapi_release_internal(struct capi_ctr *ctrl, __u16 appl)
  224. {
  225. hycapictrl_info *cinfo = (hycapictrl_info *)(ctrl->driverdata);
  226. hysdn_card *card = cinfo->card;
  227. struct sk_buff *skb;
  228. __u16 len;
  229. __u8 _command = 0xa1, _subcommand = 0x80;
  230. __u16 MessageNumber = 0x0000;
  231. capilib_release_appl(&cinfo->ncci_head, appl);
  232. #ifdef HYCAPI_PRINTFNAMES
  233. printk(KERN_NOTICE "hycapi_release_appl\n");
  234. #endif
  235. len = CAPI_MSG_BASELEN;
  236. if (!(skb = alloc_skb(len, GFP_ATOMIC))) {
  237. printk(KERN_ERR "HYSDN card%d: memory squeeze in hycapi_register_appl\n",
  238. card->myid);
  239. return;
  240. }
  241. skb_put_data(skb, &len, sizeof(__u16));
  242. skb_put_data(skb, &appl, sizeof(__u16));
  243. skb_put_data(skb, &_command, sizeof(__u8));
  244. skb_put_data(skb, &_subcommand, sizeof(__u8));
  245. skb_put_data(skb, &MessageNumber, sizeof(__u16));
  246. hycapi_send_message(ctrl, skb);
  247. hycapi_applications[appl - 1].ctrl_mask &= ~(1 << (ctrl->cnr - 1));
  248. }
  249. /******************************************************************
  250. hycapi_release_appl
  251. Release the application from the internal list an remove it's
  252. registration at controller-level
  253. ******************************************************************/
  254. static void
  255. hycapi_release_appl(struct capi_ctr *ctrl, __u16 appl)
  256. {
  257. int chk;
  258. chk = _hycapi_appCheck(appl, ctrl->cnr);
  259. if (chk < 0) {
  260. printk(KERN_ERR "HYCAPI: Releasing invalid appl %d on controller %d\n", appl, ctrl->cnr);
  261. return;
  262. }
  263. if (hycapi_applications[appl - 1].listen_req[ctrl->cnr - 1]) {
  264. kfree_skb(hycapi_applications[appl - 1].listen_req[ctrl->cnr - 1]);
  265. hycapi_applications[appl - 1].listen_req[ctrl->cnr - 1] = NULL;
  266. }
  267. if (chk == 1)
  268. {
  269. hycapi_release_internal(ctrl, appl);
  270. }
  271. }
  272. /**************************************************************
  273. Kill a single controller.
  274. **************************************************************/
  275. int hycapi_capi_release(hysdn_card *card)
  276. {
  277. hycapictrl_info *cinfo = card->hyctrlinfo;
  278. struct capi_ctr *ctrl;
  279. #ifdef HYCAPI_PRINTFNAMES
  280. printk(KERN_NOTICE "hycapi_capi_release\n");
  281. #endif
  282. if (cinfo) {
  283. ctrl = &cinfo->capi_ctrl;
  284. hycapi_remove_ctr(ctrl);
  285. }
  286. return 0;
  287. }
  288. /**************************************************************
  289. hycapi_capi_stop
  290. Stop CAPI-Output on a card. (e.g. during reboot)
  291. ***************************************************************/
  292. int hycapi_capi_stop(hysdn_card *card)
  293. {
  294. hycapictrl_info *cinfo = card->hyctrlinfo;
  295. struct capi_ctr *ctrl;
  296. #ifdef HYCAPI_PRINTFNAMES
  297. printk(KERN_NOTICE "hycapi_capi_stop\n");
  298. #endif
  299. if (cinfo) {
  300. ctrl = &cinfo->capi_ctrl;
  301. /* ctrl->suspend_output(ctrl); */
  302. capi_ctr_down(ctrl);
  303. }
  304. return 0;
  305. }
  306. /***************************************************************
  307. hycapi_send_message
  308. Send a message to the controller.
  309. Messages are parsed for their Command/Subcommand-type, and appropriate
  310. action's are performed.
  311. Note that we have to muck around with a 64Bit-DATA_REQ as there are
  312. firmware-releases that do not check the MsgLen-Indication!
  313. ***************************************************************/
  314. static u16 hycapi_send_message(struct capi_ctr *ctrl, struct sk_buff *skb)
  315. {
  316. __u16 appl_id;
  317. int _len, _len2;
  318. __u8 msghead[64];
  319. hycapictrl_info *cinfo = ctrl->driverdata;
  320. u16 retval = CAPI_NOERROR;
  321. appl_id = CAPIMSG_APPID(skb->data);
  322. switch (_hycapi_appCheck(appl_id, ctrl->cnr))
  323. {
  324. case 0:
  325. /* printk(KERN_INFO "Need to register\n"); */
  326. hycapi_register_internal(ctrl,
  327. appl_id,
  328. &(hycapi_applications[appl_id - 1].rp));
  329. break;
  330. case 1:
  331. break;
  332. default:
  333. printk(KERN_ERR "HYCAPI: Controller mixup!\n");
  334. retval = CAPI_ILLAPPNR;
  335. goto out;
  336. }
  337. switch (CAPIMSG_CMD(skb->data)) {
  338. case CAPI_DISCONNECT_B3_RESP:
  339. capilib_free_ncci(&cinfo->ncci_head, appl_id,
  340. CAPIMSG_NCCI(skb->data));
  341. break;
  342. case CAPI_DATA_B3_REQ:
  343. _len = CAPIMSG_LEN(skb->data);
  344. if (_len > 22) {
  345. _len2 = _len - 22;
  346. skb_copy_from_linear_data(skb, msghead, 22);
  347. skb_copy_to_linear_data_offset(skb, _len2,
  348. msghead, 22);
  349. skb_pull(skb, _len2);
  350. CAPIMSG_SETLEN(skb->data, 22);
  351. retval = capilib_data_b3_req(&cinfo->ncci_head,
  352. CAPIMSG_APPID(skb->data),
  353. CAPIMSG_NCCI(skb->data),
  354. CAPIMSG_MSGID(skb->data));
  355. }
  356. break;
  357. case CAPI_LISTEN_REQ:
  358. if (hycapi_applications[appl_id - 1].listen_req[ctrl->cnr - 1])
  359. {
  360. kfree_skb(hycapi_applications[appl_id - 1].listen_req[ctrl->cnr - 1]);
  361. hycapi_applications[appl_id - 1].listen_req[ctrl->cnr - 1] = NULL;
  362. }
  363. if (!(hycapi_applications[appl_id -1].listen_req[ctrl->cnr - 1] = skb_copy(skb, GFP_ATOMIC)))
  364. {
  365. printk(KERN_ERR "HYSDN: memory squeeze in private_listen\n");
  366. }
  367. break;
  368. default:
  369. break;
  370. }
  371. out:
  372. if (retval == CAPI_NOERROR)
  373. hycapi_sendmsg_internal(ctrl, skb);
  374. else
  375. dev_kfree_skb_any(skb);
  376. return retval;
  377. }
  378. static int hycapi_proc_show(struct seq_file *m, void *v)
  379. {
  380. struct capi_ctr *ctrl = m->private;
  381. hycapictrl_info *cinfo = (hycapictrl_info *)(ctrl->driverdata);
  382. hysdn_card *card = cinfo->card;
  383. char *s;
  384. seq_printf(m, "%-16s %s\n", "name", cinfo->cardname);
  385. seq_printf(m, "%-16s 0x%x\n", "io", card->iobase);
  386. seq_printf(m, "%-16s %d\n", "irq", card->irq);
  387. switch (card->brdtype) {
  388. case BD_PCCARD: s = "HYSDN Hycard"; break;
  389. case BD_ERGO: s = "HYSDN Ergo2"; break;
  390. case BD_METRO: s = "HYSDN Metro4"; break;
  391. case BD_CHAMP2: s = "HYSDN Champ2"; break;
  392. case BD_PLEXUS: s = "HYSDN Plexus30"; break;
  393. default: s = "???"; break;
  394. }
  395. seq_printf(m, "%-16s %s\n", "type", s);
  396. if ((s = cinfo->version[VER_DRIVER]) != NULL)
  397. seq_printf(m, "%-16s %s\n", "ver_driver", s);
  398. if ((s = cinfo->version[VER_CARDTYPE]) != NULL)
  399. seq_printf(m, "%-16s %s\n", "ver_cardtype", s);
  400. if ((s = cinfo->version[VER_SERIAL]) != NULL)
  401. seq_printf(m, "%-16s %s\n", "ver_serial", s);
  402. seq_printf(m, "%-16s %s\n", "cardname", cinfo->cardname);
  403. return 0;
  404. }
  405. /**************************************************************
  406. hycapi_load_firmware
  407. This does NOT load any firmware, but the callback somehow is needed
  408. on capi-interface registration.
  409. **************************************************************/
  410. static int hycapi_load_firmware(struct capi_ctr *ctrl, capiloaddata *data)
  411. {
  412. #ifdef HYCAPI_PRINTFNAMES
  413. printk(KERN_NOTICE "hycapi_load_firmware\n");
  414. #endif
  415. return 0;
  416. }
  417. static char *hycapi_procinfo(struct capi_ctr *ctrl)
  418. {
  419. hycapictrl_info *cinfo = (hycapictrl_info *)(ctrl->driverdata);
  420. #ifdef HYCAPI_PRINTFNAMES
  421. printk(KERN_NOTICE "%s\n", __func__);
  422. #endif
  423. if (!cinfo)
  424. return "";
  425. sprintf(cinfo->infobuf, "%s %s 0x%x %d %s",
  426. cinfo->cardname[0] ? cinfo->cardname : "-",
  427. cinfo->version[VER_DRIVER] ? cinfo->version[VER_DRIVER] : "-",
  428. cinfo->card ? cinfo->card->iobase : 0x0,
  429. cinfo->card ? cinfo->card->irq : 0,
  430. hycapi_revision
  431. );
  432. return cinfo->infobuf;
  433. }
  434. /******************************************************************
  435. hycapi_rx_capipkt
  436. Receive a capi-message.
  437. All B3_DATA_IND are converted to 64K-extension compatible format.
  438. New nccis are created if necessary.
  439. *******************************************************************/
  440. void
  441. hycapi_rx_capipkt(hysdn_card *card, unsigned char *buf, unsigned short len)
  442. {
  443. struct sk_buff *skb;
  444. hycapictrl_info *cinfo = card->hyctrlinfo;
  445. struct capi_ctr *ctrl;
  446. __u16 ApplId;
  447. __u16 MsgLen, info;
  448. __u16 len2, CapiCmd;
  449. __u32 CP64[2] = {0, 0};
  450. #ifdef HYCAPI_PRINTFNAMES
  451. printk(KERN_NOTICE "hycapi_rx_capipkt\n");
  452. #endif
  453. if (!cinfo) {
  454. return;
  455. }
  456. ctrl = &cinfo->capi_ctrl;
  457. if (len < CAPI_MSG_BASELEN) {
  458. printk(KERN_ERR "HYSDN Card%d: invalid CAPI-message, length %d!\n",
  459. card->myid, len);
  460. return;
  461. }
  462. MsgLen = CAPIMSG_LEN(buf);
  463. ApplId = CAPIMSG_APPID(buf);
  464. CapiCmd = CAPIMSG_CMD(buf);
  465. if ((CapiCmd == CAPI_DATA_B3_IND) && (MsgLen < 30)) {
  466. len2 = len + (30 - MsgLen);
  467. if (!(skb = alloc_skb(len2, GFP_ATOMIC))) {
  468. printk(KERN_ERR "HYSDN Card%d: incoming packet dropped\n",
  469. card->myid);
  470. return;
  471. }
  472. skb_put_data(skb, buf, MsgLen);
  473. skb_put_data(skb, CP64, 2 * sizeof(__u32));
  474. skb_put_data(skb, buf + MsgLen, len - MsgLen);
  475. CAPIMSG_SETLEN(skb->data, 30);
  476. } else {
  477. if (!(skb = alloc_skb(len, GFP_ATOMIC))) {
  478. printk(KERN_ERR "HYSDN Card%d: incoming packet dropped\n",
  479. card->myid);
  480. return;
  481. }
  482. skb_put_data(skb, buf, len);
  483. }
  484. switch (CAPIMSG_CMD(skb->data))
  485. {
  486. case CAPI_CONNECT_B3_CONF:
  487. /* Check info-field for error-indication: */
  488. info = CAPIMSG_U16(skb->data, 12);
  489. switch (info)
  490. {
  491. case 0:
  492. capilib_new_ncci(&cinfo->ncci_head, ApplId, CAPIMSG_NCCI(skb->data),
  493. hycapi_applications[ApplId - 1].rp.datablkcnt);
  494. break;
  495. case 0x0001:
  496. printk(KERN_ERR "HYSDN Card%d: NCPI not supported by current "
  497. "protocol. NCPI ignored.\n", card->myid);
  498. break;
  499. case 0x2001:
  500. printk(KERN_ERR "HYSDN Card%d: Message not supported in"
  501. " current state\n", card->myid);
  502. break;
  503. case 0x2002:
  504. printk(KERN_ERR "HYSDN Card%d: invalid PLCI\n", card->myid);
  505. break;
  506. case 0x2004:
  507. printk(KERN_ERR "HYSDN Card%d: out of NCCI\n", card->myid);
  508. break;
  509. case 0x3008:
  510. printk(KERN_ERR "HYSDN Card%d: NCPI not supported\n",
  511. card->myid);
  512. break;
  513. default:
  514. printk(KERN_ERR "HYSDN Card%d: Info in CONNECT_B3_CONF: %d\n",
  515. card->myid, info);
  516. break;
  517. }
  518. break;
  519. case CAPI_CONNECT_B3_IND:
  520. capilib_new_ncci(&cinfo->ncci_head, ApplId,
  521. CAPIMSG_NCCI(skb->data),
  522. hycapi_applications[ApplId - 1].rp.datablkcnt);
  523. break;
  524. case CAPI_DATA_B3_CONF:
  525. capilib_data_b3_conf(&cinfo->ncci_head, ApplId,
  526. CAPIMSG_NCCI(skb->data),
  527. CAPIMSG_MSGID(skb->data));
  528. break;
  529. default:
  530. break;
  531. }
  532. capi_ctr_handle_message(ctrl, ApplId, skb);
  533. }
  534. /******************************************************************
  535. hycapi_tx_capiack
  536. Internally acknowledge a msg sent. This will remove the msg from the
  537. internal queue.
  538. *******************************************************************/
  539. void hycapi_tx_capiack(hysdn_card *card)
  540. {
  541. hycapictrl_info *cinfo = card->hyctrlinfo;
  542. #ifdef HYCAPI_PRINTFNAMES
  543. printk(KERN_NOTICE "hycapi_tx_capiack\n");
  544. #endif
  545. if (!cinfo) {
  546. return;
  547. }
  548. spin_lock_irq(&cinfo->lock);
  549. kfree_skb(cinfo->skbs[cinfo->out_idx]); /* free skb */
  550. cinfo->skbs[cinfo->out_idx++] = NULL;
  551. if (cinfo->out_idx >= HYSDN_MAX_CAPI_SKB)
  552. cinfo->out_idx = 0; /* wrap around */
  553. if (cinfo->sk_count-- == HYSDN_MAX_CAPI_SKB) /* dec usage count */
  554. capi_ctr_resume_output(&cinfo->capi_ctrl);
  555. spin_unlock_irq(&cinfo->lock);
  556. }
  557. /***************************************************************
  558. hycapi_tx_capiget(hysdn_card *card)
  559. This is called when polling for messages to SEND.
  560. ****************************************************************/
  561. struct sk_buff *
  562. hycapi_tx_capiget(hysdn_card *card)
  563. {
  564. hycapictrl_info *cinfo = card->hyctrlinfo;
  565. if (!cinfo) {
  566. return (struct sk_buff *)NULL;
  567. }
  568. if (!cinfo->sk_count)
  569. return (struct sk_buff *)NULL; /* nothing available */
  570. return (cinfo->skbs[cinfo->out_idx]); /* next packet to send */
  571. }
  572. /**********************************************************
  573. int hycapi_init()
  574. attach the capi-driver to the kernel-capi.
  575. ***********************************************************/
  576. int hycapi_init(void)
  577. {
  578. int i;
  579. for (i = 0; i < CAPI_MAXAPPL; i++) {
  580. memset(&(hycapi_applications[i]), 0, sizeof(hycapi_appl));
  581. }
  582. return (0);
  583. }
  584. /**************************************************************
  585. hycapi_cleanup(void)
  586. detach the capi-driver to the kernel-capi. Actually this should
  587. free some more ressources. Do that later.
  588. **************************************************************/
  589. void
  590. hycapi_cleanup(void)
  591. {
  592. }
  593. /********************************************************************
  594. hycapi_capi_create(hysdn_card *card)
  595. Attach the card with its capi-ctrl.
  596. *********************************************************************/
  597. static void hycapi_fill_profile(hysdn_card *card)
  598. {
  599. hycapictrl_info *cinfo = NULL;
  600. struct capi_ctr *ctrl = NULL;
  601. cinfo = card->hyctrlinfo;
  602. if (!cinfo) return;
  603. ctrl = &cinfo->capi_ctrl;
  604. strcpy(ctrl->manu, "Hypercope");
  605. ctrl->version.majorversion = 2;
  606. ctrl->version.minorversion = 0;
  607. ctrl->version.majormanuversion = 3;
  608. ctrl->version.minormanuversion = 2;
  609. ctrl->profile.ncontroller = card->myid;
  610. ctrl->profile.nbchannel = card->bchans;
  611. ctrl->profile.goptions = GLOBAL_OPTION_INTERNAL_CONTROLLER |
  612. GLOBAL_OPTION_B_CHANNEL_OPERATION;
  613. ctrl->profile.support1 = B1_PROT_64KBIT_HDLC |
  614. (card->faxchans ? B1_PROT_T30 : 0) |
  615. B1_PROT_64KBIT_TRANSPARENT;
  616. ctrl->profile.support2 = B2_PROT_ISO7776 |
  617. (card->faxchans ? B2_PROT_T30 : 0) |
  618. B2_PROT_TRANSPARENT;
  619. ctrl->profile.support3 = B3_PROT_TRANSPARENT |
  620. B3_PROT_T90NL |
  621. (card->faxchans ? B3_PROT_T30 : 0) |
  622. (card->faxchans ? B3_PROT_T30EXT : 0) |
  623. B3_PROT_ISO8208;
  624. }
  625. int
  626. hycapi_capi_create(hysdn_card *card)
  627. {
  628. hycapictrl_info *cinfo = NULL;
  629. struct capi_ctr *ctrl = NULL;
  630. int retval;
  631. #ifdef HYCAPI_PRINTFNAMES
  632. printk(KERN_NOTICE "hycapi_capi_create\n");
  633. #endif
  634. if ((hycapi_enable & (1 << card->myid)) == 0) {
  635. return 1;
  636. }
  637. if (!card->hyctrlinfo) {
  638. cinfo = kzalloc(sizeof(hycapictrl_info), GFP_ATOMIC);
  639. if (!cinfo) {
  640. printk(KERN_WARNING "HYSDN: no memory for capi-ctrl.\n");
  641. return -ENOMEM;
  642. }
  643. card->hyctrlinfo = cinfo;
  644. cinfo->card = card;
  645. spin_lock_init(&cinfo->lock);
  646. INIT_LIST_HEAD(&cinfo->ncci_head);
  647. switch (card->brdtype) {
  648. case BD_PCCARD: strcpy(cinfo->cardname, "HYSDN Hycard"); break;
  649. case BD_ERGO: strcpy(cinfo->cardname, "HYSDN Ergo2"); break;
  650. case BD_METRO: strcpy(cinfo->cardname, "HYSDN Metro4"); break;
  651. case BD_CHAMP2: strcpy(cinfo->cardname, "HYSDN Champ2"); break;
  652. case BD_PLEXUS: strcpy(cinfo->cardname, "HYSDN Plexus30"); break;
  653. default: strcpy(cinfo->cardname, "HYSDN ???"); break;
  654. }
  655. ctrl = &cinfo->capi_ctrl;
  656. ctrl->driver_name = "hycapi";
  657. ctrl->driverdata = cinfo;
  658. ctrl->register_appl = hycapi_register_appl;
  659. ctrl->release_appl = hycapi_release_appl;
  660. ctrl->send_message = hycapi_send_message;
  661. ctrl->load_firmware = hycapi_load_firmware;
  662. ctrl->reset_ctr = hycapi_reset_ctr;
  663. ctrl->procinfo = hycapi_procinfo;
  664. ctrl->proc_show = hycapi_proc_show;
  665. strcpy(ctrl->name, cinfo->cardname);
  666. ctrl->owner = THIS_MODULE;
  667. retval = attach_capi_ctr(ctrl);
  668. if (retval) {
  669. printk(KERN_ERR "hycapi: attach controller failed.\n");
  670. return -EBUSY;
  671. }
  672. /* fill in the blanks: */
  673. hycapi_fill_profile(card);
  674. capi_ctr_ready(ctrl);
  675. } else {
  676. /* resume output on stopped ctrl */
  677. ctrl = &card->hyctrlinfo->capi_ctrl;
  678. hycapi_fill_profile(card);
  679. capi_ctr_ready(ctrl);
  680. hycapi_restart_internal(ctrl);
  681. /* ctrl->resume_output(ctrl); */
  682. }
  683. return 0;
  684. }