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. skb_copy_from_linear_data(skb, msghead, 22);
  344. skb_copy_to_linear_data_offset(skb, _len2,
  345. msghead, 22);
  346. skb_pull(skb, _len2);
  347. CAPIMSG_SETLEN(skb->data, 22);
  348. retval = capilib_data_b3_req(&cinfo->ncci_head,
  349. CAPIMSG_APPID(skb->data),
  350. CAPIMSG_NCCI(skb->data),
  351. CAPIMSG_MSGID(skb->data));
  352. }
  353. break;
  354. case CAPI_LISTEN_REQ:
  355. if(hycapi_applications[appl_id-1].listen_req[ctrl->cnr-1])
  356. {
  357. kfree_skb(hycapi_applications[appl_id-1].listen_req[ctrl->cnr-1]);
  358. hycapi_applications[appl_id-1].listen_req[ctrl->cnr-1] = NULL;
  359. }
  360. if (!(hycapi_applications[appl_id-1].listen_req[ctrl->cnr-1] = skb_copy(skb, GFP_ATOMIC)))
  361. {
  362. printk(KERN_ERR "HYSDN: memory squeeze in private_listen\n");
  363. }
  364. break;
  365. default:
  366. break;
  367. }
  368. out:
  369. if (retval == CAPI_NOERROR)
  370. hycapi_sendmsg_internal(ctrl, skb);
  371. else
  372. dev_kfree_skb_any(skb);
  373. return retval;
  374. }
  375. /*********************************************************************
  376. hycapi_read_proc
  377. Informations provided in the /proc/capi-entries.
  378. *********************************************************************/
  379. static int hycapi_read_proc(char *page, char **start, off_t off,
  380. int count, int *eof, struct capi_ctr *ctrl)
  381. {
  382. hycapictrl_info *cinfo = (hycapictrl_info *)(ctrl->driverdata);
  383. hysdn_card *card = cinfo->card;
  384. int len = 0;
  385. char *s;
  386. #ifdef HYCAPI_PRINTFNAMES
  387. printk(KERN_NOTICE "hycapi_read_proc\n");
  388. #endif
  389. len += sprintf(page+len, "%-16s %s\n", "name", cinfo->cardname);
  390. len += sprintf(page+len, "%-16s 0x%x\n", "io", card->iobase);
  391. len += sprintf(page+len, "%-16s %d\n", "irq", card->irq);
  392. switch (card->brdtype) {
  393. case BD_PCCARD: s = "HYSDN Hycard"; break;
  394. case BD_ERGO: s = "HYSDN Ergo2"; break;
  395. case BD_METRO: s = "HYSDN Metro4"; break;
  396. case BD_CHAMP2: s = "HYSDN Champ2"; break;
  397. case BD_PLEXUS: s = "HYSDN Plexus30"; break;
  398. default: s = "???"; break;
  399. }
  400. len += sprintf(page+len, "%-16s %s\n", "type", s);
  401. if ((s = cinfo->version[VER_DRIVER]) != NULL)
  402. len += sprintf(page+len, "%-16s %s\n", "ver_driver", s);
  403. if ((s = cinfo->version[VER_CARDTYPE]) != NULL)
  404. len += sprintf(page+len, "%-16s %s\n", "ver_cardtype", s);
  405. if ((s = cinfo->version[VER_SERIAL]) != NULL)
  406. len += sprintf(page+len, "%-16s %s\n", "ver_serial", s);
  407. len += sprintf(page+len, "%-16s %s\n", "cardname", cinfo->cardname);
  408. if (off+count >= len)
  409. *eof = 1;
  410. if (len < off)
  411. return 0;
  412. *start = page + off;
  413. return ((count < len-off) ? count : len-off);
  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->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. }