capifunc.c 31 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219
  1. /* $Id: capifunc.c,v 1.61.4.7 2005/02/11 19:40:25 armin Exp $
  2. *
  3. * ISDN interface module for Eicon active cards DIVA.
  4. * CAPI Interface common functions
  5. *
  6. * Copyright 2000-2003 by Armin Schindler (mac@melware.de)
  7. * Copyright 2000-2003 Cytronics & Melware (info@melware.de)
  8. *
  9. * This software may be used and distributed according to the terms
  10. * of the GNU General Public License, incorporated herein by reference.
  11. *
  12. */
  13. #include "platform.h"
  14. #include "os_capi.h"
  15. #include "di_defs.h"
  16. #include "capi20.h"
  17. #include "divacapi.h"
  18. #include "divasync.h"
  19. #include "capifunc.h"
  20. #define DBG_MINIMUM (DL_LOG + DL_FTL + DL_ERR)
  21. #define DBG_DEFAULT (DBG_MINIMUM + DL_XLOG + DL_REG)
  22. DIVA_CAPI_ADAPTER *adapter = (DIVA_CAPI_ADAPTER *) NULL;
  23. APPL *application = (APPL *) NULL;
  24. byte max_appl = MAX_APPL;
  25. byte max_adapter = 0;
  26. static CAPI_MSG *mapped_msg = (CAPI_MSG *) NULL;
  27. byte UnMapController(byte);
  28. char DRIVERRELEASE_CAPI[32];
  29. extern void AutomaticLaw(DIVA_CAPI_ADAPTER *);
  30. extern void callback(ENTITY *);
  31. extern word api_remove_start(void);
  32. extern word CapiRelease(word);
  33. extern word CapiRegister(word);
  34. extern word api_put(APPL *, CAPI_MSG *);
  35. static diva_os_spin_lock_t api_lock;
  36. static LIST_HEAD(cards);
  37. static dword notify_handle;
  38. static void DIRequest(ENTITY *e);
  39. static DESCRIPTOR MAdapter;
  40. static DESCRIPTOR DAdapter;
  41. static byte ControllerMap[MAX_DESCRIPTORS + 1];
  42. static void diva_register_appl(struct capi_ctr *, __u16,
  43. capi_register_params *);
  44. static void diva_release_appl(struct capi_ctr *, __u16);
  45. static char *diva_procinfo(struct capi_ctr *);
  46. static u16 diva_send_message(struct capi_ctr *,
  47. diva_os_message_buffer_s *);
  48. extern void diva_os_set_controller_struct(struct capi_ctr *);
  49. extern void DIVA_DIDD_Read(DESCRIPTOR *, int);
  50. /*
  51. * debug
  52. */
  53. static void no_printf(unsigned char *, ...);
  54. #include "debuglib.c"
  55. static void xlog(char *x, ...)
  56. {
  57. #ifndef DIVA_NO_DEBUGLIB
  58. va_list ap;
  59. if (myDriverDebugHandle.dbgMask & DL_XLOG) {
  60. va_start(ap, x);
  61. if (myDriverDebugHandle.dbg_irq) {
  62. myDriverDebugHandle.dbg_irq(myDriverDebugHandle.id,
  63. DLI_XLOG, x, ap);
  64. } else if (myDriverDebugHandle.dbg_old) {
  65. myDriverDebugHandle.dbg_old(myDriverDebugHandle.id,
  66. x, ap);
  67. }
  68. va_end(ap);
  69. }
  70. #endif
  71. }
  72. /*
  73. * info for proc
  74. */
  75. static char *diva_procinfo(struct capi_ctr *ctrl)
  76. {
  77. return (ctrl->serial);
  78. }
  79. /*
  80. * stop debugging
  81. */
  82. static void stop_dbg(void)
  83. {
  84. DbgDeregister();
  85. memset(&MAdapter, 0, sizeof(MAdapter));
  86. dprintf = no_printf;
  87. }
  88. /*
  89. * dummy debug function
  90. */
  91. static void no_printf(unsigned char *x, ...)
  92. {
  93. }
  94. /*
  95. * Controller mapping
  96. */
  97. byte MapController(byte Controller)
  98. {
  99. byte i;
  100. byte MappedController = 0;
  101. byte ctrl = Controller & 0x7f; /* mask external controller bit off */
  102. for (i = 1; i < max_adapter + 1; i++) {
  103. if (ctrl == ControllerMap[i]) {
  104. MappedController = (byte) i;
  105. break;
  106. }
  107. }
  108. if (i > max_adapter) {
  109. ControllerMap[0] = ctrl;
  110. MappedController = 0;
  111. }
  112. return (MappedController | (Controller & 0x80)); /* put back external controller bit */
  113. }
  114. /*
  115. * Controller unmapping
  116. */
  117. byte UnMapController(byte MappedController)
  118. {
  119. byte Controller;
  120. byte ctrl = MappedController & 0x7f; /* mask external controller bit off */
  121. if (ctrl <= max_adapter) {
  122. Controller = ControllerMap[ctrl];
  123. } else {
  124. Controller = 0;
  125. }
  126. return (Controller | (MappedController & 0x80)); /* put back external controller bit */
  127. }
  128. /*
  129. * find a new free id
  130. */
  131. static int find_free_id(void)
  132. {
  133. int num = 0;
  134. DIVA_CAPI_ADAPTER *a;
  135. while (num < MAX_DESCRIPTORS) {
  136. a = &adapter[num];
  137. if (!a->Id)
  138. break;
  139. num++;
  140. }
  141. return (num + 1);
  142. }
  143. /*
  144. * find a card structure by controller number
  145. */
  146. static diva_card *find_card_by_ctrl(word controller)
  147. {
  148. struct list_head *tmp;
  149. diva_card *card;
  150. list_for_each(tmp, &cards) {
  151. card = list_entry(tmp, diva_card, list);
  152. if (ControllerMap[card->Id] == controller) {
  153. if (card->remove_in_progress)
  154. card = NULL;
  155. return (card);
  156. }
  157. }
  158. return (diva_card *) 0;
  159. }
  160. /*
  161. * Buffer RX/TX
  162. */
  163. void *TransmitBufferSet(APPL *appl, dword ref)
  164. {
  165. appl->xbuffer_used[ref] = true;
  166. DBG_PRV1(("%d:xbuf_used(%d)", appl->Id, ref + 1))
  167. return (void *)(long)ref;
  168. }
  169. void *TransmitBufferGet(APPL *appl, void *p)
  170. {
  171. if (appl->xbuffer_internal[(dword)(long)p])
  172. return appl->xbuffer_internal[(dword)(long)p];
  173. return appl->xbuffer_ptr[(dword)(long)p];
  174. }
  175. void TransmitBufferFree(APPL *appl, void *p)
  176. {
  177. appl->xbuffer_used[(dword)(long)p] = false;
  178. DBG_PRV1(("%d:xbuf_free(%d)", appl->Id, ((dword)(long)p) + 1))
  179. }
  180. void *ReceiveBufferGet(APPL *appl, int Num)
  181. {
  182. return &appl->ReceiveBuffer[Num * appl->MaxDataLength];
  183. }
  184. /*
  185. * api_remove_start/complete for cleanup
  186. */
  187. void api_remove_complete(void)
  188. {
  189. DBG_PRV1(("api_remove_complete"))
  190. }
  191. /*
  192. * main function called by message.c
  193. */
  194. void sendf(APPL *appl, word command, dword Id, word Number, byte *format, ...)
  195. {
  196. word i, j;
  197. word length = 12, dlength = 0;
  198. byte *write;
  199. CAPI_MSG msg;
  200. byte *string = NULL;
  201. va_list ap;
  202. diva_os_message_buffer_s *dmb;
  203. diva_card *card = NULL;
  204. dword tmp;
  205. if (!appl)
  206. return;
  207. DBG_PRV1(("sendf(a=%d,cmd=%x,format=%s)",
  208. appl->Id, command, (byte *) format))
  209. PUT_WORD(&msg.header.appl_id, appl->Id);
  210. PUT_WORD(&msg.header.command, command);
  211. if ((byte) (command >> 8) == 0x82)
  212. Number = appl->Number++;
  213. PUT_WORD(&msg.header.number, Number);
  214. PUT_DWORD(&msg.header.controller, Id);
  215. write = (byte *)&msg;
  216. write += 12;
  217. va_start(ap, format);
  218. for (i = 0; format[i]; i++) {
  219. switch (format[i]) {
  220. case 'b':
  221. tmp = va_arg(ap, dword);
  222. *(byte *) write = (byte) (tmp & 0xff);
  223. write += 1;
  224. length += 1;
  225. break;
  226. case 'w':
  227. tmp = va_arg(ap, dword);
  228. PUT_WORD(write, (tmp & 0xffff));
  229. write += 2;
  230. length += 2;
  231. break;
  232. case 'd':
  233. tmp = va_arg(ap, dword);
  234. PUT_DWORD(write, tmp);
  235. write += 4;
  236. length += 4;
  237. break;
  238. case 's':
  239. case 'S':
  240. string = va_arg(ap, byte *);
  241. length += string[0] + 1;
  242. for (j = 0; j <= string[0]; j++)
  243. *write++ = string[j];
  244. break;
  245. }
  246. }
  247. va_end(ap);
  248. PUT_WORD(&msg.header.length, length);
  249. msg.header.controller = UnMapController(msg.header.controller);
  250. if (command == _DATA_B3_I)
  251. dlength = GET_WORD(
  252. ((byte *)&msg.info.data_b3_ind.Data_Length));
  253. if (!(dmb = diva_os_alloc_message_buffer(length + dlength,
  254. (void **) &write))) {
  255. DBG_ERR(("sendf: alloc_message_buffer failed, incoming msg dropped."))
  256. return;
  257. }
  258. /* copy msg header to sk_buff */
  259. memcpy(write, (byte *)&msg, length);
  260. /* if DATA_B3_IND, copy data too */
  261. if (command == _DATA_B3_I) {
  262. dword data = GET_DWORD(&msg.info.data_b3_ind.Data);
  263. memcpy(write + length, (void *)(long)data, dlength);
  264. }
  265. #ifndef DIVA_NO_DEBUGLIB
  266. if (myDriverDebugHandle.dbgMask & DL_XLOG) {
  267. switch (command) {
  268. default:
  269. xlog("\x00\x02", &msg, 0x81, length);
  270. break;
  271. case _DATA_B3_R | CONFIRM:
  272. if (myDriverDebugHandle.dbgMask & DL_BLK)
  273. xlog("\x00\x02", &msg, 0x81, length);
  274. break;
  275. case _DATA_B3_I:
  276. if (myDriverDebugHandle.dbgMask & DL_BLK) {
  277. xlog("\x00\x02", &msg, 0x81, length);
  278. for (i = 0; i < dlength; i += 256) {
  279. DBG_BLK((((char *)(long)GET_DWORD(&msg.info.data_b3_ind.Data)) + i,
  280. ((dlength - i) < 256) ? (dlength - i) : 256))
  281. if (!(myDriverDebugHandle.dbgMask & DL_PRV0))
  282. break; /* not more if not explicitly requested */
  283. }
  284. }
  285. break;
  286. }
  287. }
  288. #endif
  289. /* find the card structure for this controller */
  290. if (!(card = find_card_by_ctrl(write[8] & 0x7f))) {
  291. DBG_ERR(("sendf - controller %d not found, incoming msg dropped",
  292. write[8] & 0x7f))
  293. diva_os_free_message_buffer(dmb);
  294. return;
  295. }
  296. /* send capi msg to capi layer */
  297. capi_ctr_handle_message(&card->capi_ctrl, appl->Id, dmb);
  298. }
  299. /*
  300. * cleanup adapter
  301. */
  302. static void clean_adapter(int id, struct list_head *free_mem_q)
  303. {
  304. DIVA_CAPI_ADAPTER *a;
  305. int i, k;
  306. a = &adapter[id];
  307. k = li_total_channels - a->li_channels;
  308. if (k == 0) {
  309. if (li_config_table) {
  310. list_add((struct list_head *)li_config_table, free_mem_q);
  311. li_config_table = NULL;
  312. }
  313. } else {
  314. if (a->li_base < k) {
  315. memmove(&li_config_table[a->li_base],
  316. &li_config_table[a->li_base + a->li_channels],
  317. (k - a->li_base) * sizeof(LI_CONFIG));
  318. for (i = 0; i < k; i++) {
  319. memmove(&li_config_table[i].flag_table[a->li_base],
  320. &li_config_table[i].flag_table[a->li_base + a->li_channels],
  321. k - a->li_base);
  322. memmove(&li_config_table[i].
  323. coef_table[a->li_base],
  324. &li_config_table[i].coef_table[a->li_base + a->li_channels],
  325. k - a->li_base);
  326. }
  327. }
  328. }
  329. li_total_channels = k;
  330. for (i = id; i < max_adapter; i++) {
  331. if (adapter[i].request)
  332. adapter[i].li_base -= a->li_channels;
  333. }
  334. if (a->plci)
  335. list_add((struct list_head *)a->plci, free_mem_q);
  336. memset(a, 0x00, sizeof(DIVA_CAPI_ADAPTER));
  337. while ((max_adapter != 0) && !adapter[max_adapter - 1].request)
  338. max_adapter--;
  339. }
  340. /*
  341. * remove a card, but ensures consistent state of LI tables
  342. * in the time adapter is removed
  343. */
  344. static void divacapi_remove_card(DESCRIPTOR *d)
  345. {
  346. diva_card *card = NULL;
  347. diva_os_spin_lock_magic_t old_irql;
  348. LIST_HEAD(free_mem_q);
  349. struct list_head *link;
  350. struct list_head *tmp;
  351. /*
  352. * Set "remove in progress flag".
  353. * Ensures that there is no call from sendf to CAPI in
  354. * the time CAPI controller is about to be removed.
  355. */
  356. diva_os_enter_spin_lock(&api_lock, &old_irql, "remove card");
  357. list_for_each(tmp, &cards) {
  358. card = list_entry(tmp, diva_card, list);
  359. if (card->d.request == d->request) {
  360. card->remove_in_progress = 1;
  361. list_del(tmp);
  362. break;
  363. }
  364. }
  365. diva_os_leave_spin_lock(&api_lock, &old_irql, "remove card");
  366. if (card) {
  367. /*
  368. * Detach CAPI. Sendf cannot call to CAPI any more.
  369. * After detach no call to send_message() is done too.
  370. */
  371. detach_capi_ctr(&card->capi_ctrl);
  372. /*
  373. * Now get API lock (to ensure stable state of LI tables)
  374. * and update the adapter map/LI table.
  375. */
  376. diva_os_enter_spin_lock(&api_lock, &old_irql, "remove card");
  377. clean_adapter(card->Id - 1, &free_mem_q);
  378. DBG_TRC(("DelAdapterMap (%d) -> (%d)",
  379. ControllerMap[card->Id], card->Id))
  380. ControllerMap[card->Id] = 0;
  381. DBG_TRC(("adapter remove, max_adapter=%d",
  382. max_adapter));
  383. diva_os_leave_spin_lock(&api_lock, &old_irql, "remove card");
  384. /* After releasing the lock, we can free the memory */
  385. diva_os_free(0, card);
  386. }
  387. /* free queued memory areas */
  388. list_for_each_safe(link, tmp, &free_mem_q) {
  389. list_del(link);
  390. diva_os_free(0, link);
  391. }
  392. }
  393. /*
  394. * remove cards
  395. */
  396. static void divacapi_remove_cards(void)
  397. {
  398. DESCRIPTOR d;
  399. struct list_head *tmp;
  400. diva_card *card;
  401. diva_os_spin_lock_magic_t old_irql;
  402. rescan:
  403. diva_os_enter_spin_lock(&api_lock, &old_irql, "remove cards");
  404. list_for_each(tmp, &cards) {
  405. card = list_entry(tmp, diva_card, list);
  406. diva_os_leave_spin_lock(&api_lock, &old_irql, "remove cards");
  407. d.request = card->d.request;
  408. divacapi_remove_card(&d);
  409. goto rescan;
  410. }
  411. diva_os_leave_spin_lock(&api_lock, &old_irql, "remove cards");
  412. }
  413. /*
  414. * sync_callback
  415. */
  416. static void sync_callback(ENTITY *e)
  417. {
  418. diva_os_spin_lock_magic_t old_irql;
  419. DBG_TRC(("cb:Id=%x,Rc=%x,Ind=%x", e->Id, e->Rc, e->Ind))
  420. diva_os_enter_spin_lock(&api_lock, &old_irql, "sync_callback");
  421. callback(e);
  422. diva_os_leave_spin_lock(&api_lock, &old_irql, "sync_callback");
  423. }
  424. /*
  425. * add a new card
  426. */
  427. static int diva_add_card(DESCRIPTOR *d)
  428. {
  429. int k = 0, i = 0;
  430. diva_os_spin_lock_magic_t old_irql;
  431. diva_card *card = NULL;
  432. struct capi_ctr *ctrl = NULL;
  433. DIVA_CAPI_ADAPTER *a = NULL;
  434. IDI_SYNC_REQ sync_req;
  435. char serial[16];
  436. void *mem_to_free;
  437. LI_CONFIG *new_li_config_table;
  438. int j;
  439. if (!(card = (diva_card *) diva_os_malloc(0, sizeof(diva_card)))) {
  440. DBG_ERR(("diva_add_card: failed to allocate card struct."))
  441. return (0);
  442. }
  443. memset((char *) card, 0x00, sizeof(diva_card));
  444. memcpy(&card->d, d, sizeof(DESCRIPTOR));
  445. sync_req.GetName.Req = 0;
  446. sync_req.GetName.Rc = IDI_SYNC_REQ_GET_NAME;
  447. card->d.request((ENTITY *)&sync_req);
  448. strlcpy(card->name, sync_req.GetName.name, sizeof(card->name));
  449. ctrl = &card->capi_ctrl;
  450. strcpy(ctrl->name, card->name);
  451. ctrl->register_appl = diva_register_appl;
  452. ctrl->release_appl = diva_release_appl;
  453. ctrl->send_message = diva_send_message;
  454. ctrl->procinfo = diva_procinfo;
  455. ctrl->driverdata = card;
  456. diva_os_set_controller_struct(ctrl);
  457. if (attach_capi_ctr(ctrl)) {
  458. DBG_ERR(("diva_add_card: failed to attach controller."))
  459. diva_os_free(0, card);
  460. return (0);
  461. }
  462. diva_os_enter_spin_lock(&api_lock, &old_irql, "find id");
  463. card->Id = find_free_id();
  464. diva_os_leave_spin_lock(&api_lock, &old_irql, "find id");
  465. strlcpy(ctrl->manu, M_COMPANY, sizeof(ctrl->manu));
  466. ctrl->version.majorversion = 2;
  467. ctrl->version.minorversion = 0;
  468. ctrl->version.majormanuversion = DRRELMAJOR;
  469. ctrl->version.minormanuversion = DRRELMINOR;
  470. sync_req.GetSerial.Req = 0;
  471. sync_req.GetSerial.Rc = IDI_SYNC_REQ_GET_SERIAL;
  472. sync_req.GetSerial.serial = 0;
  473. card->d.request((ENTITY *)&sync_req);
  474. if ((i = ((sync_req.GetSerial.serial & 0xff000000) >> 24))) {
  475. sprintf(serial, "%ld-%d",
  476. sync_req.GetSerial.serial & 0x00ffffff, i + 1);
  477. } else {
  478. sprintf(serial, "%ld", sync_req.GetSerial.serial);
  479. }
  480. serial[CAPI_SERIAL_LEN - 1] = 0;
  481. strlcpy(ctrl->serial, serial, sizeof(ctrl->serial));
  482. a = &adapter[card->Id - 1];
  483. card->adapter = a;
  484. a->os_card = card;
  485. ControllerMap[card->Id] = (byte) (ctrl->cnr);
  486. DBG_TRC(("AddAdapterMap (%d) -> (%d)", ctrl->cnr, card->Id))
  487. sync_req.xdi_capi_prms.Req = 0;
  488. sync_req.xdi_capi_prms.Rc = IDI_SYNC_REQ_XDI_GET_CAPI_PARAMS;
  489. sync_req.xdi_capi_prms.info.structure_length =
  490. sizeof(diva_xdi_get_capi_parameters_t);
  491. card->d.request((ENTITY *)&sync_req);
  492. a->flag_dynamic_l1_down =
  493. sync_req.xdi_capi_prms.info.flag_dynamic_l1_down;
  494. a->group_optimization_enabled =
  495. sync_req.xdi_capi_prms.info.group_optimization_enabled;
  496. a->request = DIRequest; /* card->d.request; */
  497. a->max_plci = card->d.channels + 30;
  498. a->max_listen = (card->d.channels > 2) ? 8 : 2;
  499. if (!
  500. (a->plci =
  501. (PLCI *) diva_os_malloc(0, sizeof(PLCI) * a->max_plci))) {
  502. DBG_ERR(("diva_add_card: failed alloc plci struct."))
  503. memset(a, 0, sizeof(DIVA_CAPI_ADAPTER));
  504. return (0);
  505. }
  506. memset(a->plci, 0, sizeof(PLCI) * a->max_plci);
  507. for (k = 0; k < a->max_plci; k++) {
  508. a->Id = (byte) card->Id;
  509. a->plci[k].Sig.callback = sync_callback;
  510. a->plci[k].Sig.XNum = 1;
  511. a->plci[k].Sig.X = a->plci[k].XData;
  512. a->plci[k].Sig.user[0] = (word) (card->Id - 1);
  513. a->plci[k].Sig.user[1] = (word) k;
  514. a->plci[k].NL.callback = sync_callback;
  515. a->plci[k].NL.XNum = 1;
  516. a->plci[k].NL.X = a->plci[k].XData;
  517. a->plci[k].NL.user[0] = (word) ((card->Id - 1) | 0x8000);
  518. a->plci[k].NL.user[1] = (word) k;
  519. a->plci[k].adapter = a;
  520. }
  521. a->profile.Number = card->Id;
  522. a->profile.Channels = card->d.channels;
  523. if (card->d.features & DI_FAX3) {
  524. a->profile.Global_Options = 0x71;
  525. if (card->d.features & DI_CODEC)
  526. a->profile.Global_Options |= 0x6;
  527. #if IMPLEMENT_DTMF
  528. a->profile.Global_Options |= 0x8;
  529. #endif /* IMPLEMENT_DTMF */
  530. a->profile.Global_Options |= 0x80; /* Line Interconnect */
  531. #if IMPLEMENT_ECHO_CANCELLER
  532. a->profile.Global_Options |= 0x100;
  533. #endif /* IMPLEMENT_ECHO_CANCELLER */
  534. a->profile.B1_Protocols = 0xdf;
  535. a->profile.B2_Protocols = 0x1fdb;
  536. a->profile.B3_Protocols = 0xb7;
  537. a->manufacturer_features = MANUFACTURER_FEATURE_HARDDTMF;
  538. } else {
  539. a->profile.Global_Options = 0x71;
  540. if (card->d.features & DI_CODEC)
  541. a->profile.Global_Options |= 0x2;
  542. a->profile.B1_Protocols = 0x43;
  543. a->profile.B2_Protocols = 0x1f0f;
  544. a->profile.B3_Protocols = 0x07;
  545. a->manufacturer_features = 0;
  546. }
  547. a->li_pri = (a->profile.Channels > 2);
  548. a->li_channels = a->li_pri ? MIXER_CHANNELS_PRI : MIXER_CHANNELS_BRI;
  549. a->li_base = 0;
  550. for (i = 0; &adapter[i] != a; i++) {
  551. if (adapter[i].request)
  552. a->li_base = adapter[i].li_base + adapter[i].li_channels;
  553. }
  554. k = li_total_channels + a->li_channels;
  555. new_li_config_table =
  556. (LI_CONFIG *) diva_os_malloc(0, ((k * sizeof(LI_CONFIG) + 3) & ~3) + (2 * k) * ((k + 3) & ~3));
  557. if (new_li_config_table == NULL) {
  558. DBG_ERR(("diva_add_card: failed alloc li_config table."))
  559. memset(a, 0, sizeof(DIVA_CAPI_ADAPTER));
  560. return (0);
  561. }
  562. /* Prevent access to line interconnect table in process update */
  563. diva_os_enter_spin_lock(&api_lock, &old_irql, "add card");
  564. j = 0;
  565. for (i = 0; i < k; i++) {
  566. if ((i >= a->li_base) && (i < a->li_base + a->li_channels))
  567. memset(&new_li_config_table[i], 0, sizeof(LI_CONFIG));
  568. else
  569. memcpy(&new_li_config_table[i], &li_config_table[j], sizeof(LI_CONFIG));
  570. new_li_config_table[i].flag_table =
  571. ((byte *) new_li_config_table) + (((k * sizeof(LI_CONFIG) + 3) & ~3) + (2 * i) * ((k + 3) & ~3));
  572. new_li_config_table[i].coef_table =
  573. ((byte *) new_li_config_table) + (((k * sizeof(LI_CONFIG) + 3) & ~3) + (2 * i + 1) * ((k + 3) & ~3));
  574. if ((i >= a->li_base) && (i < a->li_base + a->li_channels)) {
  575. new_li_config_table[i].adapter = a;
  576. memset(&new_li_config_table[i].flag_table[0], 0, k);
  577. memset(&new_li_config_table[i].coef_table[0], 0, k);
  578. } else {
  579. if (a->li_base != 0) {
  580. memcpy(&new_li_config_table[i].flag_table[0],
  581. &li_config_table[j].flag_table[0],
  582. a->li_base);
  583. memcpy(&new_li_config_table[i].coef_table[0],
  584. &li_config_table[j].coef_table[0],
  585. a->li_base);
  586. }
  587. memset(&new_li_config_table[i].flag_table[a->li_base], 0, a->li_channels);
  588. memset(&new_li_config_table[i].coef_table[a->li_base], 0, a->li_channels);
  589. if (a->li_base + a->li_channels < k) {
  590. memcpy(&new_li_config_table[i].flag_table[a->li_base +
  591. a->li_channels],
  592. &li_config_table[j].flag_table[a->li_base],
  593. k - (a->li_base + a->li_channels));
  594. memcpy(&new_li_config_table[i].coef_table[a->li_base +
  595. a->li_channels],
  596. &li_config_table[j].coef_table[a->li_base],
  597. k - (a->li_base + a->li_channels));
  598. }
  599. j++;
  600. }
  601. }
  602. li_total_channels = k;
  603. mem_to_free = li_config_table;
  604. li_config_table = new_li_config_table;
  605. for (i = card->Id; i < max_adapter; i++) {
  606. if (adapter[i].request)
  607. adapter[i].li_base += a->li_channels;
  608. }
  609. if (a == &adapter[max_adapter])
  610. max_adapter++;
  611. list_add(&(card->list), &cards);
  612. AutomaticLaw(a);
  613. diva_os_leave_spin_lock(&api_lock, &old_irql, "add card");
  614. if (mem_to_free) {
  615. diva_os_free(0, mem_to_free);
  616. }
  617. i = 0;
  618. while (i++ < 30) {
  619. if (a->automatic_law > 3)
  620. break;
  621. diva_os_sleep(10);
  622. }
  623. /* profile information */
  624. PUT_WORD(&ctrl->profile.nbchannel, card->d.channels);
  625. ctrl->profile.goptions = a->profile.Global_Options;
  626. ctrl->profile.support1 = a->profile.B1_Protocols;
  627. ctrl->profile.support2 = a->profile.B2_Protocols;
  628. ctrl->profile.support3 = a->profile.B3_Protocols;
  629. /* manufacturer profile information */
  630. ctrl->profile.manu[0] = a->man_profile.private_options;
  631. ctrl->profile.manu[1] = a->man_profile.rtp_primary_payloads;
  632. ctrl->profile.manu[2] = a->man_profile.rtp_additional_payloads;
  633. ctrl->profile.manu[3] = 0;
  634. ctrl->profile.manu[4] = 0;
  635. capi_ctr_ready(ctrl);
  636. DBG_TRC(("adapter added, max_adapter=%d", max_adapter));
  637. return (1);
  638. }
  639. /*
  640. * register appl
  641. */
  642. static void diva_register_appl(struct capi_ctr *ctrl, __u16 appl,
  643. capi_register_params *rp)
  644. {
  645. APPL *this;
  646. word bnum, xnum;
  647. int i = 0;
  648. unsigned char *p;
  649. void *DataNCCI, *DataFlags, *ReceiveBuffer, *xbuffer_used;
  650. void **xbuffer_ptr, **xbuffer_internal;
  651. diva_os_spin_lock_magic_t old_irql;
  652. unsigned int mem_len;
  653. int nconn = rp->level3cnt;
  654. if (diva_os_in_irq()) {
  655. DBG_ERR(("CAPI_REGISTER - in irq context !"))
  656. return;
  657. }
  658. DBG_TRC(("application register Id=%d", appl))
  659. if (appl > MAX_APPL) {
  660. DBG_ERR(("CAPI_REGISTER - appl.Id exceeds MAX_APPL"))
  661. return;
  662. }
  663. if (nconn <= 0)
  664. nconn = ctrl->profile.nbchannel * -nconn;
  665. if (nconn == 0)
  666. nconn = ctrl->profile.nbchannel;
  667. DBG_LOG(("CAPI_REGISTER - Id = %d", appl))
  668. DBG_LOG((" MaxLogicalConnections = %d(%d)", nconn, rp->level3cnt))
  669. DBG_LOG((" MaxBDataBuffers = %d", rp->datablkcnt))
  670. DBG_LOG((" MaxBDataLength = %d", rp->datablklen))
  671. if (nconn < 1 ||
  672. nconn > 255 ||
  673. rp->datablklen < 80 ||
  674. rp->datablklen > 2150 || rp->datablkcnt > 255) {
  675. DBG_ERR(("CAPI_REGISTER - invalid parameters"))
  676. return;
  677. }
  678. if (application[appl - 1].Id == appl) {
  679. DBG_LOG(("CAPI_REGISTER - appl already registered"))
  680. return; /* appl already registered */
  681. }
  682. /* alloc memory */
  683. bnum = nconn * rp->datablkcnt;
  684. xnum = nconn * MAX_DATA_B3;
  685. mem_len = bnum * sizeof(word); /* DataNCCI */
  686. mem_len += bnum * sizeof(word); /* DataFlags */
  687. mem_len += bnum * rp->datablklen; /* ReceiveBuffer */
  688. mem_len += xnum; /* xbuffer_used */
  689. mem_len += xnum * sizeof(void *); /* xbuffer_ptr */
  690. mem_len += xnum * sizeof(void *); /* xbuffer_internal */
  691. mem_len += xnum * rp->datablklen; /* xbuffer_ptr[xnum] */
  692. DBG_LOG((" Allocated Memory = %d", mem_len))
  693. if (!(p = diva_os_malloc(0, mem_len))) {
  694. DBG_ERR(("CAPI_REGISTER - memory allocation failed"))
  695. return;
  696. }
  697. memset(p, 0, mem_len);
  698. DataNCCI = (void *)p;
  699. p += bnum * sizeof(word);
  700. DataFlags = (void *)p;
  701. p += bnum * sizeof(word);
  702. ReceiveBuffer = (void *)p;
  703. p += bnum * rp->datablklen;
  704. xbuffer_used = (void *)p;
  705. p += xnum;
  706. xbuffer_ptr = (void **)p;
  707. p += xnum * sizeof(void *);
  708. xbuffer_internal = (void **)p;
  709. p += xnum * sizeof(void *);
  710. for (i = 0; i < xnum; i++) {
  711. xbuffer_ptr[i] = (void *)p;
  712. p += rp->datablklen;
  713. }
  714. /* initialize application data */
  715. diva_os_enter_spin_lock(&api_lock, &old_irql, "register_appl");
  716. this = &application[appl - 1];
  717. memset(this, 0, sizeof(APPL));
  718. this->Id = appl;
  719. for (i = 0; i < max_adapter; i++) {
  720. adapter[i].CIP_Mask[appl - 1] = 0;
  721. }
  722. this->queue_size = 1000;
  723. this->MaxNCCI = (byte) nconn;
  724. this->MaxNCCIData = (byte) rp->datablkcnt;
  725. this->MaxBuffer = bnum;
  726. this->MaxDataLength = rp->datablklen;
  727. this->DataNCCI = DataNCCI;
  728. this->DataFlags = DataFlags;
  729. this->ReceiveBuffer = ReceiveBuffer;
  730. this->xbuffer_used = xbuffer_used;
  731. this->xbuffer_ptr = xbuffer_ptr;
  732. this->xbuffer_internal = xbuffer_internal;
  733. for (i = 0; i < xnum; i++) {
  734. this->xbuffer_ptr[i] = xbuffer_ptr[i];
  735. }
  736. CapiRegister(this->Id);
  737. diva_os_leave_spin_lock(&api_lock, &old_irql, "register_appl");
  738. }
  739. /*
  740. * release appl
  741. */
  742. static void diva_release_appl(struct capi_ctr *ctrl, __u16 appl)
  743. {
  744. diva_os_spin_lock_magic_t old_irql;
  745. APPL *this = &application[appl - 1];
  746. void *mem_to_free = NULL;
  747. DBG_TRC(("application %d(%d) cleanup", this->Id, appl))
  748. if (diva_os_in_irq()) {
  749. DBG_ERR(("CAPI_RELEASE - in irq context !"))
  750. return;
  751. }
  752. diva_os_enter_spin_lock(&api_lock, &old_irql, "release_appl");
  753. if (this->Id) {
  754. CapiRelease(this->Id);
  755. mem_to_free = this->DataNCCI;
  756. this->DataNCCI = NULL;
  757. this->Id = 0;
  758. }
  759. diva_os_leave_spin_lock(&api_lock, &old_irql, "release_appl");
  760. if (mem_to_free)
  761. diva_os_free(0, mem_to_free);
  762. }
  763. /*
  764. * send message
  765. */
  766. static u16 diva_send_message(struct capi_ctr *ctrl,
  767. diva_os_message_buffer_s *dmb)
  768. {
  769. int i = 0;
  770. word ret = 0;
  771. diva_os_spin_lock_magic_t old_irql;
  772. CAPI_MSG *msg = (CAPI_MSG *) DIVA_MESSAGE_BUFFER_DATA(dmb);
  773. APPL *this = &application[GET_WORD(&msg->header.appl_id) - 1];
  774. diva_card *card = ctrl->driverdata;
  775. __u32 length = DIVA_MESSAGE_BUFFER_LEN(dmb);
  776. word clength = GET_WORD(&msg->header.length);
  777. word command = GET_WORD(&msg->header.command);
  778. u16 retval = CAPI_NOERROR;
  779. if (diva_os_in_irq()) {
  780. DBG_ERR(("CAPI_SEND_MSG - in irq context !"))
  781. return CAPI_REGOSRESOURCEERR;
  782. }
  783. DBG_PRV1(("Write - appl = %d, cmd = 0x%x", this->Id, command))
  784. if (card->remove_in_progress) {
  785. DBG_ERR(("CAPI_SEND_MSG - remove in progress!"))
  786. return CAPI_REGOSRESOURCEERR;
  787. }
  788. diva_os_enter_spin_lock(&api_lock, &old_irql, "send message");
  789. if (!this->Id) {
  790. diva_os_leave_spin_lock(&api_lock, &old_irql, "send message");
  791. return CAPI_ILLAPPNR;
  792. }
  793. /* patch controller number */
  794. msg->header.controller = ControllerMap[card->Id]
  795. | (msg->header.controller & 0x80); /* preserve external controller bit */
  796. switch (command) {
  797. default:
  798. xlog("\x00\x02", msg, 0x80, clength);
  799. break;
  800. case _DATA_B3_I | RESPONSE:
  801. #ifndef DIVA_NO_DEBUGLIB
  802. if (myDriverDebugHandle.dbgMask & DL_BLK)
  803. xlog("\x00\x02", msg, 0x80, clength);
  804. #endif
  805. break;
  806. case _DATA_B3_R:
  807. #ifndef DIVA_NO_DEBUGLIB
  808. if (myDriverDebugHandle.dbgMask & DL_BLK)
  809. xlog("\x00\x02", msg, 0x80, clength);
  810. #endif
  811. if (clength == 24)
  812. clength = 22; /* workaround for PPcom bug */
  813. /* header is always 22 */
  814. if (GET_WORD(&msg->info.data_b3_req.Data_Length) >
  815. this->MaxDataLength
  816. || GET_WORD(&msg->info.data_b3_req.Data_Length) >
  817. (length - clength)) {
  818. DBG_ERR(("Write - invalid message size"))
  819. retval = CAPI_ILLCMDORSUBCMDORMSGTOSMALL;
  820. goto write_end;
  821. }
  822. for (i = 0; i < (MAX_DATA_B3 * this->MaxNCCI)
  823. && this->xbuffer_used[i]; i++);
  824. if (i == (MAX_DATA_B3 * this->MaxNCCI)) {
  825. DBG_ERR(("Write - too many data pending"))
  826. retval = CAPI_SENDQUEUEFULL;
  827. goto write_end;
  828. }
  829. msg->info.data_b3_req.Data = i;
  830. this->xbuffer_internal[i] = NULL;
  831. memcpy(this->xbuffer_ptr[i], &((__u8 *) msg)[clength],
  832. GET_WORD(&msg->info.data_b3_req.Data_Length));
  833. #ifndef DIVA_NO_DEBUGLIB
  834. if ((myDriverDebugHandle.dbgMask & DL_BLK)
  835. && (myDriverDebugHandle.dbgMask & DL_XLOG)) {
  836. int j;
  837. for (j = 0; j <
  838. GET_WORD(&msg->info.data_b3_req.Data_Length);
  839. j += 256) {
  840. DBG_BLK((((char *) this->xbuffer_ptr[i]) + j,
  841. ((GET_WORD(&msg->info.data_b3_req.Data_Length) - j) <
  842. 256) ? (GET_WORD(&msg->info.data_b3_req.Data_Length) - j) : 256))
  843. if (!(myDriverDebugHandle.dbgMask & DL_PRV0))
  844. break; /* not more if not explicitly requested */
  845. }
  846. }
  847. #endif
  848. break;
  849. }
  850. memcpy(mapped_msg, msg, (__u32) clength);
  851. mapped_msg->header.controller = MapController(mapped_msg->header.controller);
  852. mapped_msg->header.length = clength;
  853. mapped_msg->header.command = command;
  854. mapped_msg->header.number = GET_WORD(&msg->header.number);
  855. ret = api_put(this, mapped_msg);
  856. switch (ret) {
  857. case 0:
  858. break;
  859. case _BAD_MSG:
  860. DBG_ERR(("Write - bad message"))
  861. retval = CAPI_ILLCMDORSUBCMDORMSGTOSMALL;
  862. break;
  863. case _QUEUE_FULL:
  864. DBG_ERR(("Write - queue full"))
  865. retval = CAPI_SENDQUEUEFULL;
  866. break;
  867. default:
  868. DBG_ERR(("Write - api_put returned unknown error"))
  869. retval = CAPI_UNKNOWNNOTPAR;
  870. break;
  871. }
  872. write_end:
  873. diva_os_leave_spin_lock(&api_lock, &old_irql, "send message");
  874. if (retval == CAPI_NOERROR)
  875. diva_os_free_message_buffer(dmb);
  876. return retval;
  877. }
  878. /*
  879. * cards request function
  880. */
  881. static void DIRequest(ENTITY *e)
  882. {
  883. DIVA_CAPI_ADAPTER *a = &(adapter[(byte) e->user[0]]);
  884. diva_card *os_card = (diva_card *) a->os_card;
  885. if (e->Req && (a->FlowControlIdTable[e->ReqCh] == e->Id)) {
  886. a->FlowControlSkipTable[e->ReqCh] = 1;
  887. }
  888. (*(os_card->d.request)) (e);
  889. }
  890. /*
  891. * callback function from didd
  892. */
  893. static void didd_callback(void *context, DESCRIPTOR *adapter, int removal)
  894. {
  895. if (adapter->type == IDI_DADAPTER) {
  896. DBG_ERR(("Notification about IDI_DADAPTER change ! Oops."));
  897. return;
  898. } else if (adapter->type == IDI_DIMAINT) {
  899. if (removal) {
  900. stop_dbg();
  901. } else {
  902. memcpy(&MAdapter, adapter, sizeof(MAdapter));
  903. dprintf = (DIVA_DI_PRINTF) MAdapter.request;
  904. DbgRegister("CAPI20", DRIVERRELEASE_CAPI, DBG_DEFAULT);
  905. }
  906. } else if ((adapter->type > 0) && (adapter->type < 16)) { /* IDI Adapter */
  907. if (removal) {
  908. divacapi_remove_card(adapter);
  909. } else {
  910. diva_add_card(adapter);
  911. }
  912. }
  913. return;
  914. }
  915. /*
  916. * connect to didd
  917. */
  918. static int divacapi_connect_didd(void)
  919. {
  920. int x = 0;
  921. int dadapter = 0;
  922. IDI_SYNC_REQ req;
  923. DESCRIPTOR DIDD_Table[MAX_DESCRIPTORS];
  924. DIVA_DIDD_Read(DIDD_Table, sizeof(DIDD_Table));
  925. for (x = 0; x < MAX_DESCRIPTORS; x++) {
  926. if (DIDD_Table[x].type == IDI_DIMAINT) { /* MAINT found */
  927. memcpy(&MAdapter, &DIDD_Table[x], sizeof(DAdapter));
  928. dprintf = (DIVA_DI_PRINTF) MAdapter.request;
  929. DbgRegister("CAPI20", DRIVERRELEASE_CAPI, DBG_DEFAULT);
  930. break;
  931. }
  932. }
  933. for (x = 0; x < MAX_DESCRIPTORS; x++) {
  934. if (DIDD_Table[x].type == IDI_DADAPTER) { /* DADAPTER found */
  935. dadapter = 1;
  936. memcpy(&DAdapter, &DIDD_Table[x], sizeof(DAdapter));
  937. req.didd_notify.e.Req = 0;
  938. req.didd_notify.e.Rc =
  939. IDI_SYNC_REQ_DIDD_REGISTER_ADAPTER_NOTIFY;
  940. req.didd_notify.info.callback = (void *)didd_callback;
  941. req.didd_notify.info.context = NULL;
  942. DAdapter.request((ENTITY *)&req);
  943. if (req.didd_notify.e.Rc != 0xff) {
  944. stop_dbg();
  945. return (0);
  946. }
  947. notify_handle = req.didd_notify.info.handle;
  948. }
  949. else if ((DIDD_Table[x].type > 0) && (DIDD_Table[x].type < 16)) { /* IDI Adapter found */
  950. diva_add_card(&DIDD_Table[x]);
  951. }
  952. }
  953. if (!dadapter) {
  954. stop_dbg();
  955. }
  956. return (dadapter);
  957. }
  958. /*
  959. * diconnect from didd
  960. */
  961. static void divacapi_disconnect_didd(void)
  962. {
  963. IDI_SYNC_REQ req;
  964. stop_dbg();
  965. req.didd_notify.e.Req = 0;
  966. req.didd_notify.e.Rc = IDI_SYNC_REQ_DIDD_REMOVE_ADAPTER_NOTIFY;
  967. req.didd_notify.info.handle = notify_handle;
  968. DAdapter.request((ENTITY *)&req);
  969. }
  970. /*
  971. * we do not provide date/time here,
  972. * the application should do this.
  973. */
  974. int fax_head_line_time(char *buffer)
  975. {
  976. return (0);
  977. }
  978. /*
  979. * init (alloc) main structures
  980. */
  981. static int __init init_main_structs(void)
  982. {
  983. if (!(mapped_msg = (CAPI_MSG *) diva_os_malloc(0, MAX_MSG_SIZE))) {
  984. DBG_ERR(("init: failed alloc mapped_msg."))
  985. return 0;
  986. }
  987. if (!(adapter = diva_os_malloc(0, sizeof(DIVA_CAPI_ADAPTER) * MAX_DESCRIPTORS))) {
  988. DBG_ERR(("init: failed alloc adapter struct."))
  989. diva_os_free(0, mapped_msg);
  990. return 0;
  991. }
  992. memset(adapter, 0, sizeof(DIVA_CAPI_ADAPTER) * MAX_DESCRIPTORS);
  993. if (!(application = diva_os_malloc(0, sizeof(APPL) * MAX_APPL))) {
  994. DBG_ERR(("init: failed alloc application struct."))
  995. diva_os_free(0, mapped_msg);
  996. diva_os_free(0, adapter);
  997. return 0;
  998. }
  999. memset(application, 0, sizeof(APPL) * MAX_APPL);
  1000. return (1);
  1001. }
  1002. /*
  1003. * remove (free) main structures
  1004. */
  1005. static void remove_main_structs(void)
  1006. {
  1007. if (application)
  1008. diva_os_free(0, application);
  1009. if (adapter)
  1010. diva_os_free(0, adapter);
  1011. if (mapped_msg)
  1012. diva_os_free(0, mapped_msg);
  1013. }
  1014. /*
  1015. * api_remove_start
  1016. */
  1017. static void do_api_remove_start(void)
  1018. {
  1019. diva_os_spin_lock_magic_t old_irql;
  1020. int ret = 1, count = 100;
  1021. do {
  1022. diva_os_enter_spin_lock(&api_lock, &old_irql, "api remove start");
  1023. ret = api_remove_start();
  1024. diva_os_leave_spin_lock(&api_lock, &old_irql, "api remove start");
  1025. diva_os_sleep(10);
  1026. } while (ret && count--);
  1027. if (ret)
  1028. DBG_ERR(("could not remove signaling ID's"))
  1029. }
  1030. /*
  1031. * init
  1032. */
  1033. int __init init_capifunc(void)
  1034. {
  1035. diva_os_initialize_spin_lock(&api_lock, "capifunc");
  1036. memset(ControllerMap, 0, MAX_DESCRIPTORS + 1);
  1037. max_adapter = 0;
  1038. if (!init_main_structs()) {
  1039. DBG_ERR(("init: failed to init main structs."))
  1040. diva_os_destroy_spin_lock(&api_lock, "capifunc");
  1041. return (0);
  1042. }
  1043. if (!divacapi_connect_didd()) {
  1044. DBG_ERR(("init: failed to connect to DIDD."))
  1045. do_api_remove_start();
  1046. divacapi_remove_cards();
  1047. remove_main_structs();
  1048. diva_os_destroy_spin_lock(&api_lock, "capifunc");
  1049. return (0);
  1050. }
  1051. return (1);
  1052. }
  1053. /*
  1054. * finit
  1055. */
  1056. void __exit finit_capifunc(void)
  1057. {
  1058. do_api_remove_start();
  1059. divacapi_disconnect_didd();
  1060. divacapi_remove_cards();
  1061. remove_main_structs();
  1062. diva_os_destroy_spin_lock(&api_lock, "capifunc");
  1063. }