hycapi.c 22 KB

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