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