divasfunc.c 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238
  1. /* $Id: divasfunc.c,v 1.23.4.2 2004/08/28 20:03:53 armin Exp $
  2. *
  3. * Low level driver for Eicon DIVA Server ISDN cards.
  4. *
  5. * Copyright 2000-2003 by Armin Schindler (mac@melware.de)
  6. * Copyright 2000-2003 Cytronics & Melware (info@melware.de)
  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. #include "platform.h"
  12. #include "di_defs.h"
  13. #include "pc.h"
  14. #include "di.h"
  15. #include "io.h"
  16. #include "divasync.h"
  17. #include "diva.h"
  18. #include "xdi_vers.h"
  19. #define DBG_MINIMUM (DL_LOG + DL_FTL + DL_ERR)
  20. #define DBG_DEFAULT (DBG_MINIMUM + DL_XLOG + DL_REG)
  21. static int debugmask;
  22. extern void DIVA_DIDD_Read(void *, int);
  23. extern PISDN_ADAPTER IoAdapters[MAX_ADAPTER];
  24. extern char *DRIVERRELEASE_DIVAS;
  25. static dword notify_handle;
  26. static DESCRIPTOR DAdapter;
  27. static DESCRIPTOR MAdapter;
  28. /* --------------------------------------------------------------------------
  29. MAINT driver connector section
  30. -------------------------------------------------------------------------- */
  31. static void no_printf(unsigned char *x, ...)
  32. {
  33. /* dummy debug function */
  34. }
  35. #include "debuglib.c"
  36. /*
  37. * get the adapters serial number
  38. */
  39. void diva_get_vserial_number(PISDN_ADAPTER IoAdapter, char *buf)
  40. {
  41. int contr = 0;
  42. if ((contr = ((IoAdapter->serialNo & 0xff000000) >> 24))) {
  43. sprintf(buf, "%d-%d",
  44. IoAdapter->serialNo & 0x00ffffff, contr + 1);
  45. } else {
  46. sprintf(buf, "%d", IoAdapter->serialNo);
  47. }
  48. }
  49. /*
  50. * register a new adapter
  51. */
  52. void diva_xdi_didd_register_adapter(int card)
  53. {
  54. DESCRIPTOR d;
  55. IDI_SYNC_REQ req;
  56. if (card && ((card - 1) < MAX_ADAPTER) &&
  57. IoAdapters[card - 1] && Requests[card - 1]) {
  58. d.type = IoAdapters[card - 1]->Properties.DescType;
  59. d.request = Requests[card - 1];
  60. d.channels = IoAdapters[card - 1]->Properties.Channels;
  61. d.features = IoAdapters[card - 1]->Properties.Features;
  62. DBG_TRC(("DIDD register A(%d) channels=%d", card,
  63. d.channels))
  64. /* workaround for different Name in structure */
  65. strlcpy(IoAdapters[card - 1]->Name,
  66. IoAdapters[card - 1]->Properties.Name,
  67. sizeof(IoAdapters[card - 1]->Name));
  68. req.didd_remove_adapter.e.Req = 0;
  69. req.didd_add_adapter.e.Rc = IDI_SYNC_REQ_DIDD_ADD_ADAPTER;
  70. req.didd_add_adapter.info.descriptor = (void *) &d;
  71. DAdapter.request((ENTITY *)&req);
  72. if (req.didd_add_adapter.e.Rc != 0xff) {
  73. DBG_ERR(("DIDD register A(%d) failed !", card))
  74. }
  75. IoAdapters[card - 1]->os_trap_nfy_Fnc = NULL;
  76. }
  77. }
  78. /*
  79. * remove an adapter
  80. */
  81. void diva_xdi_didd_remove_adapter(int card)
  82. {
  83. IDI_SYNC_REQ req;
  84. ADAPTER *a = &IoAdapters[card - 1]->a;
  85. IoAdapters[card - 1]->os_trap_nfy_Fnc = NULL;
  86. DBG_TRC(("DIDD de-register A(%d)", card))
  87. req.didd_remove_adapter.e.Req = 0;
  88. req.didd_remove_adapter.e.Rc = IDI_SYNC_REQ_DIDD_REMOVE_ADAPTER;
  89. req.didd_remove_adapter.info.p_request =
  90. (IDI_CALL) Requests[card - 1];
  91. DAdapter.request((ENTITY *)&req);
  92. memset(&(a->IdTable), 0x00, 256);
  93. }
  94. /*
  95. * start debug
  96. */
  97. static void start_dbg(void)
  98. {
  99. DbgRegister("DIVAS", DRIVERRELEASE_DIVAS, (debugmask) ? debugmask : DBG_DEFAULT);
  100. DBG_LOG(("DIVA ISDNXDI BUILD (%s[%s])",
  101. DIVA_BUILD, diva_xdi_common_code_build))
  102. }
  103. /*
  104. * stop debug
  105. */
  106. static void stop_dbg(void)
  107. {
  108. DbgDeregister();
  109. memset(&MAdapter, 0, sizeof(MAdapter));
  110. dprintf = no_printf;
  111. }
  112. /*
  113. * didd callback function
  114. */
  115. static void *didd_callback(void *context, DESCRIPTOR *adapter,
  116. int removal)
  117. {
  118. if (adapter->type == IDI_DADAPTER) {
  119. DBG_ERR(("Notification about IDI_DADAPTER change ! Oops."));
  120. return (NULL);
  121. }
  122. if (adapter->type == IDI_DIMAINT) {
  123. if (removal) {
  124. stop_dbg();
  125. } else {
  126. memcpy(&MAdapter, adapter, sizeof(MAdapter));
  127. dprintf = (DIVA_DI_PRINTF) MAdapter.request;
  128. start_dbg();
  129. }
  130. }
  131. return (NULL);
  132. }
  133. /*
  134. * connect to didd
  135. */
  136. static int __init connect_didd(void)
  137. {
  138. int x = 0;
  139. int dadapter = 0;
  140. IDI_SYNC_REQ req;
  141. DESCRIPTOR DIDD_Table[MAX_DESCRIPTORS];
  142. DIVA_DIDD_Read(DIDD_Table, sizeof(DIDD_Table));
  143. for (x = 0; x < MAX_DESCRIPTORS; x++) {
  144. if (DIDD_Table[x].type == IDI_DADAPTER) { /* DADAPTER found */
  145. dadapter = 1;
  146. memcpy(&DAdapter, &DIDD_Table[x], sizeof(DAdapter));
  147. req.didd_notify.e.Req = 0;
  148. req.didd_notify.e.Rc =
  149. IDI_SYNC_REQ_DIDD_REGISTER_ADAPTER_NOTIFY;
  150. req.didd_notify.info.callback = (void *)didd_callback;
  151. req.didd_notify.info.context = NULL;
  152. DAdapter.request((ENTITY *)&req);
  153. if (req.didd_notify.e.Rc != 0xff) {
  154. stop_dbg();
  155. return (0);
  156. }
  157. notify_handle = req.didd_notify.info.handle;
  158. } else if (DIDD_Table[x].type == IDI_DIMAINT) { /* MAINT found */
  159. memcpy(&MAdapter, &DIDD_Table[x], sizeof(DAdapter));
  160. dprintf = (DIVA_DI_PRINTF) MAdapter.request;
  161. start_dbg();
  162. }
  163. }
  164. if (!dadapter) {
  165. stop_dbg();
  166. }
  167. return (dadapter);
  168. }
  169. /*
  170. * disconnect from didd
  171. */
  172. static void disconnect_didd(void)
  173. {
  174. IDI_SYNC_REQ req;
  175. stop_dbg();
  176. req.didd_notify.e.Req = 0;
  177. req.didd_notify.e.Rc = IDI_SYNC_REQ_DIDD_REMOVE_ADAPTER_NOTIFY;
  178. req.didd_notify.info.handle = notify_handle;
  179. DAdapter.request((ENTITY *)&req);
  180. }
  181. /*
  182. * init
  183. */
  184. int __init divasfunc_init(int dbgmask)
  185. {
  186. char *version;
  187. debugmask = dbgmask;
  188. if (!connect_didd()) {
  189. DBG_ERR(("divasfunc: failed to connect to DIDD."))
  190. return (0);
  191. }
  192. version = diva_xdi_common_code_build;
  193. divasa_xdi_driver_entry();
  194. return (1);
  195. }
  196. /*
  197. * exit
  198. */
  199. void divasfunc_exit(void)
  200. {
  201. divasa_xdi_driver_unload();
  202. disconnect_didd();
  203. }