hycapi.c 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800
  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. memcpy(skb_put(skb, sizeof(__u16)), &len, sizeof(__u16));
  149. memcpy(skb_put(skb, sizeof(__u16)), &appl, sizeof(__u16));
  150. memcpy(skb_put(skb, sizeof(__u8)), &_command, sizeof(_command));
  151. memcpy(skb_put(skb, sizeof(__u8)), &_subcommand, sizeof(_subcommand));
  152. memcpy(skb_put(skb, sizeof(__u16)), &MessageNumber, sizeof(__u16));
  153. memcpy(skb_put(skb, sizeof(__u16)), &MessageBufferSize, sizeof(__u16));
  154. memcpy(skb_put(skb, sizeof(__u16)), &(rp->level3cnt), sizeof(__u16));
  155. memcpy(skb_put(skb, sizeof(__u16)), &(rp->datablkcnt), sizeof(__u16));
  156. memcpy(skb_put(skb, sizeof(__u16)), &(rp->datablklen), sizeof(__u16));
  157. memcpy(skb_put(skb, slen), 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. memcpy(skb_put(skb, sizeof(__u16)), &len, sizeof(__u16));
  242. memcpy(skb_put(skb, sizeof(__u16)), &appl, sizeof(__u16));
  243. memcpy(skb_put(skb, sizeof(__u8)), &_command, sizeof(_command));
  244. memcpy(skb_put(skb, sizeof(__u8)), &_subcommand, sizeof(_subcommand));
  245. memcpy(skb_put(skb, sizeof(__u16)), &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. static int hycapi_proc_open(struct inode *inode, struct file *file)
  406. {
  407. return single_open(file, hycapi_proc_show, PDE_DATA(inode));
  408. }
  409. static const struct file_operations hycapi_proc_fops = {
  410. .owner = THIS_MODULE,
  411. .open = hycapi_proc_open,
  412. .read = seq_read,
  413. .llseek = seq_lseek,
  414. .release = single_release,
  415. };
  416. /**************************************************************
  417. hycapi_load_firmware
  418. This does NOT load any firmware, but the callback somehow is needed
  419. on capi-interface registration.
  420. **************************************************************/
  421. static int hycapi_load_firmware(struct capi_ctr *ctrl, capiloaddata *data)
  422. {
  423. #ifdef HYCAPI_PRINTFNAMES
  424. printk(KERN_NOTICE "hycapi_load_firmware\n");
  425. #endif
  426. return 0;
  427. }
  428. static char *hycapi_procinfo(struct capi_ctr *ctrl)
  429. {
  430. hycapictrl_info *cinfo = (hycapictrl_info *)(ctrl->driverdata);
  431. #ifdef HYCAPI_PRINTFNAMES
  432. printk(KERN_NOTICE "%s\n", __func__);
  433. #endif
  434. if (!cinfo)
  435. return "";
  436. sprintf(cinfo->infobuf, "%s %s 0x%x %d %s",
  437. cinfo->cardname[0] ? cinfo->cardname : "-",
  438. cinfo->version[VER_DRIVER] ? cinfo->version[VER_DRIVER] : "-",
  439. cinfo->card ? cinfo->card->iobase : 0x0,
  440. cinfo->card ? cinfo->card->irq : 0,
  441. hycapi_revision
  442. );
  443. return cinfo->infobuf;
  444. }
  445. /******************************************************************
  446. hycapi_rx_capipkt
  447. Receive a capi-message.
  448. All B3_DATA_IND are converted to 64K-extension compatible format.
  449. New nccis are created if necessary.
  450. *******************************************************************/
  451. void
  452. hycapi_rx_capipkt(hysdn_card *card, unsigned char *buf, unsigned short len)
  453. {
  454. struct sk_buff *skb;
  455. hycapictrl_info *cinfo = card->hyctrlinfo;
  456. struct capi_ctr *ctrl;
  457. __u16 ApplId;
  458. __u16 MsgLen, info;
  459. __u16 len2, CapiCmd;
  460. __u32 CP64[2] = {0, 0};
  461. #ifdef HYCAPI_PRINTFNAMES
  462. printk(KERN_NOTICE "hycapi_rx_capipkt\n");
  463. #endif
  464. if (!cinfo) {
  465. return;
  466. }
  467. ctrl = &cinfo->capi_ctrl;
  468. if (len < CAPI_MSG_BASELEN) {
  469. printk(KERN_ERR "HYSDN Card%d: invalid CAPI-message, length %d!\n",
  470. card->myid, len);
  471. return;
  472. }
  473. MsgLen = CAPIMSG_LEN(buf);
  474. ApplId = CAPIMSG_APPID(buf);
  475. CapiCmd = CAPIMSG_CMD(buf);
  476. if ((CapiCmd == CAPI_DATA_B3_IND) && (MsgLen < 30)) {
  477. len2 = len + (30 - MsgLen);
  478. if (!(skb = alloc_skb(len2, GFP_ATOMIC))) {
  479. printk(KERN_ERR "HYSDN Card%d: incoming packet dropped\n",
  480. card->myid);
  481. return;
  482. }
  483. memcpy(skb_put(skb, MsgLen), buf, MsgLen);
  484. memcpy(skb_put(skb, 2 * sizeof(__u32)), CP64, 2 * sizeof(__u32));
  485. memcpy(skb_put(skb, len - MsgLen), buf + MsgLen,
  486. len - MsgLen);
  487. CAPIMSG_SETLEN(skb->data, 30);
  488. } else {
  489. if (!(skb = alloc_skb(len, GFP_ATOMIC))) {
  490. printk(KERN_ERR "HYSDN Card%d: incoming packet dropped\n",
  491. card->myid);
  492. return;
  493. }
  494. memcpy(skb_put(skb, len), buf, len);
  495. }
  496. switch (CAPIMSG_CMD(skb->data))
  497. {
  498. case CAPI_CONNECT_B3_CONF:
  499. /* Check info-field for error-indication: */
  500. info = CAPIMSG_U16(skb->data, 12);
  501. switch (info)
  502. {
  503. case 0:
  504. capilib_new_ncci(&cinfo->ncci_head, ApplId, CAPIMSG_NCCI(skb->data),
  505. hycapi_applications[ApplId - 1].rp.datablkcnt);
  506. break;
  507. case 0x0001:
  508. printk(KERN_ERR "HYSDN Card%d: NCPI not supported by current "
  509. "protocol. NCPI ignored.\n", card->myid);
  510. break;
  511. case 0x2001:
  512. printk(KERN_ERR "HYSDN Card%d: Message not supported in"
  513. " current state\n", card->myid);
  514. break;
  515. case 0x2002:
  516. printk(KERN_ERR "HYSDN Card%d: invalid PLCI\n", card->myid);
  517. break;
  518. case 0x2004:
  519. printk(KERN_ERR "HYSDN Card%d: out of NCCI\n", card->myid);
  520. break;
  521. case 0x3008:
  522. printk(KERN_ERR "HYSDN Card%d: NCPI not supported\n",
  523. card->myid);
  524. break;
  525. default:
  526. printk(KERN_ERR "HYSDN Card%d: Info in CONNECT_B3_CONF: %d\n",
  527. card->myid, info);
  528. break;
  529. }
  530. break;
  531. case CAPI_CONNECT_B3_IND:
  532. capilib_new_ncci(&cinfo->ncci_head, ApplId,
  533. CAPIMSG_NCCI(skb->data),
  534. hycapi_applications[ApplId - 1].rp.datablkcnt);
  535. break;
  536. case CAPI_DATA_B3_CONF:
  537. capilib_data_b3_conf(&cinfo->ncci_head, ApplId,
  538. CAPIMSG_NCCI(skb->data),
  539. CAPIMSG_MSGID(skb->data));
  540. break;
  541. default:
  542. break;
  543. }
  544. capi_ctr_handle_message(ctrl, ApplId, skb);
  545. }
  546. /******************************************************************
  547. hycapi_tx_capiack
  548. Internally acknowledge a msg sent. This will remove the msg from the
  549. internal queue.
  550. *******************************************************************/
  551. void hycapi_tx_capiack(hysdn_card *card)
  552. {
  553. hycapictrl_info *cinfo = card->hyctrlinfo;
  554. #ifdef HYCAPI_PRINTFNAMES
  555. printk(KERN_NOTICE "hycapi_tx_capiack\n");
  556. #endif
  557. if (!cinfo) {
  558. return;
  559. }
  560. spin_lock_irq(&cinfo->lock);
  561. kfree_skb(cinfo->skbs[cinfo->out_idx]); /* free skb */
  562. cinfo->skbs[cinfo->out_idx++] = NULL;
  563. if (cinfo->out_idx >= HYSDN_MAX_CAPI_SKB)
  564. cinfo->out_idx = 0; /* wrap around */
  565. if (cinfo->sk_count-- == HYSDN_MAX_CAPI_SKB) /* dec usage count */
  566. capi_ctr_resume_output(&cinfo->capi_ctrl);
  567. spin_unlock_irq(&cinfo->lock);
  568. }
  569. /***************************************************************
  570. hycapi_tx_capiget(hysdn_card *card)
  571. This is called when polling for messages to SEND.
  572. ****************************************************************/
  573. struct sk_buff *
  574. hycapi_tx_capiget(hysdn_card *card)
  575. {
  576. hycapictrl_info *cinfo = card->hyctrlinfo;
  577. if (!cinfo) {
  578. return (struct sk_buff *)NULL;
  579. }
  580. if (!cinfo->sk_count)
  581. return (struct sk_buff *)NULL; /* nothing available */
  582. return (cinfo->skbs[cinfo->out_idx]); /* next packet to send */
  583. }
  584. /**********************************************************
  585. int hycapi_init()
  586. attach the capi-driver to the kernel-capi.
  587. ***********************************************************/
  588. int hycapi_init(void)
  589. {
  590. int i;
  591. for (i = 0; i < CAPI_MAXAPPL; i++) {
  592. memset(&(hycapi_applications[i]), 0, sizeof(hycapi_appl));
  593. }
  594. return (0);
  595. }
  596. /**************************************************************
  597. hycapi_cleanup(void)
  598. detach the capi-driver to the kernel-capi. Actually this should
  599. free some more ressources. Do that later.
  600. **************************************************************/
  601. void
  602. hycapi_cleanup(void)
  603. {
  604. }
  605. /********************************************************************
  606. hycapi_capi_create(hysdn_card *card)
  607. Attach the card with its capi-ctrl.
  608. *********************************************************************/
  609. static void hycapi_fill_profile(hysdn_card *card)
  610. {
  611. hycapictrl_info *cinfo = NULL;
  612. struct capi_ctr *ctrl = NULL;
  613. cinfo = card->hyctrlinfo;
  614. if (!cinfo) return;
  615. ctrl = &cinfo->capi_ctrl;
  616. strcpy(ctrl->manu, "Hypercope");
  617. ctrl->version.majorversion = 2;
  618. ctrl->version.minorversion = 0;
  619. ctrl->version.majormanuversion = 3;
  620. ctrl->version.minormanuversion = 2;
  621. ctrl->profile.ncontroller = card->myid;
  622. ctrl->profile.nbchannel = card->bchans;
  623. ctrl->profile.goptions = GLOBAL_OPTION_INTERNAL_CONTROLLER |
  624. GLOBAL_OPTION_B_CHANNEL_OPERATION;
  625. ctrl->profile.support1 = B1_PROT_64KBIT_HDLC |
  626. (card->faxchans ? B1_PROT_T30 : 0) |
  627. B1_PROT_64KBIT_TRANSPARENT;
  628. ctrl->profile.support2 = B2_PROT_ISO7776 |
  629. (card->faxchans ? B2_PROT_T30 : 0) |
  630. B2_PROT_TRANSPARENT;
  631. ctrl->profile.support3 = B3_PROT_TRANSPARENT |
  632. B3_PROT_T90NL |
  633. (card->faxchans ? B3_PROT_T30 : 0) |
  634. (card->faxchans ? B3_PROT_T30EXT : 0) |
  635. B3_PROT_ISO8208;
  636. }
  637. int
  638. hycapi_capi_create(hysdn_card *card)
  639. {
  640. hycapictrl_info *cinfo = NULL;
  641. struct capi_ctr *ctrl = NULL;
  642. int retval;
  643. #ifdef HYCAPI_PRINTFNAMES
  644. printk(KERN_NOTICE "hycapi_capi_create\n");
  645. #endif
  646. if ((hycapi_enable & (1 << card->myid)) == 0) {
  647. return 1;
  648. }
  649. if (!card->hyctrlinfo) {
  650. cinfo = kzalloc(sizeof(hycapictrl_info), GFP_ATOMIC);
  651. if (!cinfo) {
  652. printk(KERN_WARNING "HYSDN: no memory for capi-ctrl.\n");
  653. return -ENOMEM;
  654. }
  655. card->hyctrlinfo = cinfo;
  656. cinfo->card = card;
  657. spin_lock_init(&cinfo->lock);
  658. INIT_LIST_HEAD(&cinfo->ncci_head);
  659. switch (card->brdtype) {
  660. case BD_PCCARD: strcpy(cinfo->cardname, "HYSDN Hycard"); break;
  661. case BD_ERGO: strcpy(cinfo->cardname, "HYSDN Ergo2"); break;
  662. case BD_METRO: strcpy(cinfo->cardname, "HYSDN Metro4"); break;
  663. case BD_CHAMP2: strcpy(cinfo->cardname, "HYSDN Champ2"); break;
  664. case BD_PLEXUS: strcpy(cinfo->cardname, "HYSDN Plexus30"); break;
  665. default: strcpy(cinfo->cardname, "HYSDN ???"); break;
  666. }
  667. ctrl = &cinfo->capi_ctrl;
  668. ctrl->driver_name = "hycapi";
  669. ctrl->driverdata = cinfo;
  670. ctrl->register_appl = hycapi_register_appl;
  671. ctrl->release_appl = hycapi_release_appl;
  672. ctrl->send_message = hycapi_send_message;
  673. ctrl->load_firmware = hycapi_load_firmware;
  674. ctrl->reset_ctr = hycapi_reset_ctr;
  675. ctrl->procinfo = hycapi_procinfo;
  676. ctrl->proc_fops = &hycapi_proc_fops;
  677. strcpy(ctrl->name, cinfo->cardname);
  678. ctrl->owner = THIS_MODULE;
  679. retval = attach_capi_ctr(ctrl);
  680. if (retval) {
  681. printk(KERN_ERR "hycapi: attach controller failed.\n");
  682. return -EBUSY;
  683. }
  684. /* fill in the blanks: */
  685. hycapi_fill_profile(card);
  686. capi_ctr_ready(ctrl);
  687. } else {
  688. /* resume output on stopped ctrl */
  689. ctrl = &card->hyctrlinfo->capi_ctrl;
  690. hycapi_fill_profile(card);
  691. capi_ctr_ready(ctrl);
  692. hycapi_restart_internal(ctrl);
  693. /* ctrl->resume_output(ctrl); */
  694. }
  695. return 0;
  696. }