debug.c 67 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133
  1. #include "platform.h"
  2. #include "pc.h"
  3. #include "di_defs.h"
  4. #include "debug_if.h"
  5. #include "divasync.h"
  6. #include "kst_ifc.h"
  7. #include "maintidi.h"
  8. #include "man_defs.h"
  9. /*
  10. LOCALS
  11. */
  12. #define DBG_MAGIC (0x47114711L)
  13. static void DI_register (void *arg);
  14. static void DI_deregister (pDbgHandle hDbg);
  15. static void DI_format (int do_lock, word id, int type, char *format, va_list argument_list);
  16. static void DI_format_locked (word id, int type, char *format, va_list argument_list);
  17. static void DI_format_old (word id, char *format, va_list ap) { }
  18. static void DiProcessEventLog (unsigned short id, unsigned long msgID, va_list ap) { }
  19. static void single_p (byte * P, word * PLength, byte Id);
  20. static void diva_maint_xdi_cb (ENTITY* e);
  21. static word SuperTraceCreateReadReq (byte* P, const char* path);
  22. static int diva_mnt_cmp_nmbr (const char* nmbr);
  23. static void diva_free_dma_descriptor (IDI_CALL request, int nr);
  24. static int diva_get_dma_descriptor (IDI_CALL request, dword *dma_magic);
  25. void diva_mnt_internal_dprintf (dword drv_id, dword type, char* p, ...);
  26. static dword MaxDumpSize = 256 ;
  27. static dword MaxXlogSize = 2 + 128 ;
  28. static char TraceFilter[DIVA_MAX_SELECTIVE_FILTER_LENGTH+1];
  29. static int TraceFilterIdent = -1;
  30. static int TraceFilterChannel = -1;
  31. typedef struct _diva_maint_client {
  32. dword sec;
  33. dword usec;
  34. pDbgHandle hDbg;
  35. char drvName[128];
  36. dword dbgMask;
  37. dword last_dbgMask;
  38. IDI_CALL request;
  39. _DbgHandle_ Dbg;
  40. int logical;
  41. int channels;
  42. diva_strace_library_interface_t* pIdiLib;
  43. BUFFERS XData;
  44. char xbuffer[2048+512];
  45. byte* pmem;
  46. int request_pending;
  47. int dma_handle;
  48. } diva_maint_client_t;
  49. static diva_maint_client_t clients[MAX_DESCRIPTORS];
  50. static void diva_change_management_debug_mask (diva_maint_client_t* pC, dword old_mask);
  51. static void diva_maint_error (void* user_context,
  52. diva_strace_library_interface_t* hLib,
  53. int Adapter,
  54. int error,
  55. const char* file,
  56. int line);
  57. static void diva_maint_state_change_notify (void* user_context,
  58. diva_strace_library_interface_t* hLib,
  59. int Adapter,
  60. diva_trace_line_state_t* channel,
  61. int notify_subject);
  62. static void diva_maint_trace_notify (void* user_context,
  63. diva_strace_library_interface_t* hLib,
  64. int Adapter,
  65. void* xlog_buffer,
  66. int length);
  67. typedef struct MSG_QUEUE {
  68. dword Size; /* total size of queue (constant) */
  69. byte *Base; /* lowest address (constant) */
  70. byte *High; /* Base + Size (constant) */
  71. byte *Head; /* first message in queue (if any) */
  72. byte *Tail; /* first free position */
  73. byte *Wrap; /* current wraparound position */
  74. dword Count; /* current no of bytes in queue */
  75. } MSG_QUEUE;
  76. typedef struct MSG_HEAD {
  77. volatile dword Size; /* size of data following MSG_HEAD */
  78. #define MSG_INCOMPLETE 0x8000 /* ored to Size until queueCompleteMsg */
  79. } MSG_HEAD;
  80. #define queueCompleteMsg(p) do{ ((MSG_HEAD *)p - 1)->Size &= ~MSG_INCOMPLETE; }while(0)
  81. #define queueCount(q) ((q)->Count)
  82. #define MSG_NEED(size) \
  83. ( (sizeof(MSG_HEAD) + size + sizeof(dword) - 1) & ~(sizeof(dword) - 1) )
  84. static void queueInit (MSG_QUEUE *Q, byte *Buffer, dword sizeBuffer) {
  85. Q->Size = sizeBuffer;
  86. Q->Base = Q->Head = Q->Tail = Buffer;
  87. Q->High = Buffer + sizeBuffer;
  88. Q->Wrap = NULL;
  89. Q->Count= 0;
  90. }
  91. static byte *queueAllocMsg (MSG_QUEUE *Q, word size) {
  92. /* Allocate 'size' bytes at tail of queue which will be filled later
  93. * directly with callers own message header info and/or message.
  94. * An 'alloced' message is marked incomplete by oring the 'Size' field
  95. * with MSG_INCOMPLETE.
  96. * This must be reset via queueCompleteMsg() after the message is filled.
  97. * As long as a message is marked incomplete queuePeekMsg() will return
  98. * a 'queue empty' condition when it reaches such a message. */
  99. MSG_HEAD *Msg;
  100. word need = MSG_NEED(size);
  101. if (Q->Tail == Q->Head) {
  102. if (Q->Wrap || need > Q->Size) {
  103. return NULL; /* full */
  104. }
  105. goto alloc; /* empty */
  106. }
  107. if (Q->Tail > Q->Head) {
  108. if (Q->Tail + need <= Q->High) goto alloc; /* append */
  109. if (Q->Base + need > Q->Head) {
  110. return NULL; /* too much */
  111. }
  112. /* wraparound the queue (but not the message) */
  113. Q->Wrap = Q->Tail;
  114. Q->Tail = Q->Base;
  115. goto alloc;
  116. }
  117. if (Q->Tail + need > Q->Head) {
  118. return NULL; /* too much */
  119. }
  120. alloc:
  121. Msg = (MSG_HEAD *)Q->Tail;
  122. Msg->Size = size | MSG_INCOMPLETE;
  123. Q->Tail += need;
  124. Q->Count += size;
  125. return ((byte*)(Msg + 1));
  126. }
  127. static void queueFreeMsg (MSG_QUEUE *Q) {
  128. /* Free the message at head of queue */
  129. word size = ((MSG_HEAD *)Q->Head)->Size & ~MSG_INCOMPLETE;
  130. Q->Head += MSG_NEED(size);
  131. Q->Count -= size;
  132. if (Q->Wrap) {
  133. if (Q->Head >= Q->Wrap) {
  134. Q->Head = Q->Base;
  135. Q->Wrap = NULL;
  136. }
  137. } else if (Q->Head >= Q->Tail) {
  138. Q->Head = Q->Tail = Q->Base;
  139. }
  140. }
  141. static byte *queuePeekMsg (MSG_QUEUE *Q, word *size) {
  142. /* Show the first valid message in queue BUT DON'T free the message.
  143. * After looking on the message contents it can be freed queueFreeMsg()
  144. * or simply remain in message queue. */
  145. MSG_HEAD *Msg = (MSG_HEAD *)Q->Head;
  146. if (((byte *)Msg == Q->Tail && !Q->Wrap) ||
  147. (Msg->Size & MSG_INCOMPLETE)) {
  148. return NULL;
  149. } else {
  150. *size = Msg->Size;
  151. return ((byte *)(Msg + 1));
  152. }
  153. }
  154. /*
  155. Message queue header
  156. */
  157. static MSG_QUEUE* dbg_queue;
  158. static byte* dbg_base;
  159. static int external_dbg_queue;
  160. static diva_os_spin_lock_t dbg_q_lock;
  161. static diva_os_spin_lock_t dbg_adapter_lock;
  162. static int dbg_q_busy;
  163. static volatile dword dbg_sequence;
  164. static dword start_sec;
  165. static dword start_usec;
  166. /*
  167. INTERFACE:
  168. Initialize run time queue structures.
  169. base: base of the message queue
  170. length: length of the message queue
  171. do_init: perfor queue reset
  172. return: zero on success, -1 on error
  173. */
  174. int diva_maint_init (byte* base, unsigned long length, int do_init) {
  175. if (dbg_queue || (!base) || (length < (4096*4))) {
  176. return (-1);
  177. }
  178. TraceFilter[0] = 0;
  179. TraceFilterIdent = -1;
  180. TraceFilterChannel = -1;
  181. dbg_base = base;
  182. diva_os_get_time (&start_sec, &start_usec);
  183. *(dword*)base = (dword)DBG_MAGIC; /* Store Magic */
  184. base += sizeof(dword);
  185. length -= sizeof(dword);
  186. *(dword*)base = 2048; /* Extension Field Length */
  187. base += sizeof(dword);
  188. length -= sizeof(dword);
  189. strcpy (base, "KERNEL MODE BUFFER\n");
  190. base += 2048;
  191. length -= 2048;
  192. *(dword*)base = 0; /* Terminate extension */
  193. base += sizeof(dword);
  194. length -= sizeof(dword);
  195. *(void**)base = (void*)(base+sizeof(void*)); /* Store Base */
  196. base += sizeof(void*);
  197. length -= sizeof(void*);
  198. dbg_queue = (MSG_QUEUE*)base;
  199. queueInit (dbg_queue, base + sizeof(MSG_QUEUE), length - sizeof(MSG_QUEUE) - 512);
  200. external_dbg_queue = 0;
  201. if (!do_init) {
  202. external_dbg_queue = 1; /* memory was located on the external device */
  203. }
  204. if (diva_os_initialize_spin_lock (&dbg_q_lock, "dbg_init")) {
  205. dbg_queue = NULL;
  206. dbg_base = NULL;
  207. external_dbg_queue = 0;
  208. return (-1);
  209. }
  210. if (diva_os_initialize_spin_lock (&dbg_adapter_lock, "dbg_init")) {
  211. diva_os_destroy_spin_lock(&dbg_q_lock, "dbg_init");
  212. dbg_queue = NULL;
  213. dbg_base = NULL;
  214. external_dbg_queue = 0;
  215. return (-1);
  216. }
  217. return (0);
  218. }
  219. /*
  220. INTERFACE:
  221. Finit at unload time
  222. return address of internal queue or zero if queue
  223. was external
  224. */
  225. void* diva_maint_finit (void) {
  226. void* ret = (void*)dbg_base;
  227. int i;
  228. dbg_queue = NULL;
  229. dbg_base = NULL;
  230. if (ret) {
  231. diva_os_destroy_spin_lock(&dbg_q_lock, "dbg_finit");
  232. diva_os_destroy_spin_lock(&dbg_adapter_lock, "dbg_finit");
  233. }
  234. if (external_dbg_queue) {
  235. ret = NULL;
  236. }
  237. external_dbg_queue = 0;
  238. for (i = 1; i < ARRAY_SIZE(clients); i++) {
  239. if (clients[i].pmem) {
  240. diva_os_free (0, clients[i].pmem);
  241. }
  242. }
  243. return (ret);
  244. }
  245. /*
  246. INTERFACE:
  247. Return amount of messages in debug queue
  248. */
  249. dword diva_dbg_q_length (void) {
  250. return (dbg_queue ? queueCount(dbg_queue) : 0);
  251. }
  252. /*
  253. INTERFACE:
  254. Lock message queue and return the pointer to the first
  255. entry.
  256. */
  257. diva_dbg_entry_head_t* diva_maint_get_message (word* size,
  258. diva_os_spin_lock_magic_t* old_irql) {
  259. diva_dbg_entry_head_t* pmsg = NULL;
  260. diva_os_enter_spin_lock (&dbg_q_lock, old_irql, "read");
  261. if (dbg_q_busy) {
  262. diva_os_leave_spin_lock (&dbg_q_lock, old_irql, "read_busy");
  263. return NULL;
  264. }
  265. dbg_q_busy = 1;
  266. if (!(pmsg = (diva_dbg_entry_head_t*)queuePeekMsg (dbg_queue, size))) {
  267. dbg_q_busy = 0;
  268. diva_os_leave_spin_lock (&dbg_q_lock, old_irql, "read_empty");
  269. }
  270. return (pmsg);
  271. }
  272. /*
  273. INTERFACE:
  274. acknowledge last message and unlock queue
  275. */
  276. void diva_maint_ack_message (int do_release,
  277. diva_os_spin_lock_magic_t* old_irql) {
  278. if (!dbg_q_busy) {
  279. return;
  280. }
  281. if (do_release) {
  282. queueFreeMsg (dbg_queue);
  283. }
  284. dbg_q_busy = 0;
  285. diva_os_leave_spin_lock (&dbg_q_lock, old_irql, "read_ack");
  286. }
  287. /*
  288. INTERFACE:
  289. PRT COMP function used to register
  290. with MAINT adapter or log in compatibility
  291. mode in case older driver version is connected too
  292. */
  293. void diva_maint_prtComp (char *format, ...) {
  294. void *hDbg;
  295. va_list ap;
  296. if (!format)
  297. return;
  298. va_start(ap, format);
  299. /*
  300. register to new log driver functions
  301. */
  302. if ((format[0] == 0) && ((unsigned char)format[1] == 255)) {
  303. hDbg = va_arg(ap, void *); /* ptr to DbgHandle */
  304. DI_register (hDbg);
  305. }
  306. va_end (ap);
  307. }
  308. static void DI_register (void *arg) {
  309. diva_os_spin_lock_magic_t old_irql;
  310. dword sec, usec;
  311. pDbgHandle hDbg ;
  312. int id, free_id = -1, best_id = 0;
  313. diva_os_get_time (&sec, &usec);
  314. hDbg = (pDbgHandle)arg ;
  315. /*
  316. Check for bad args, specially for the old obsolete debug handle
  317. */
  318. if ((hDbg == NULL) ||
  319. ((hDbg->id == 0) && (((_OldDbgHandle_ *)hDbg)->id == -1)) ||
  320. (hDbg->Registered != 0)) {
  321. return ;
  322. }
  323. diva_os_enter_spin_lock (&dbg_q_lock, &old_irql, "register");
  324. for (id = 1; id < ARRAY_SIZE(clients); id++) {
  325. if (clients[id].hDbg == hDbg) {
  326. /*
  327. driver already registered
  328. */
  329. diva_os_leave_spin_lock (&dbg_q_lock, &old_irql, "register");
  330. return;
  331. }
  332. if (clients[id].hDbg) { /* slot is busy */
  333. continue;
  334. }
  335. free_id = id;
  336. if (!strcmp (clients[id].drvName, hDbg->drvName)) {
  337. /*
  338. This driver was already registered with this name
  339. and slot is still free - reuse it
  340. */
  341. best_id = 1;
  342. break;
  343. }
  344. if (!clients[id].hDbg) { /* slot is busy */
  345. break;
  346. }
  347. }
  348. if (free_id != -1) {
  349. diva_dbg_entry_head_t* pmsg = NULL;
  350. int len;
  351. char tmp[256];
  352. word size;
  353. /*
  354. Register new driver with id == free_id
  355. */
  356. clients[free_id].hDbg = hDbg;
  357. clients[free_id].sec = sec;
  358. clients[free_id].usec = usec;
  359. strcpy (clients[free_id].drvName, hDbg->drvName);
  360. clients[free_id].dbgMask = hDbg->dbgMask;
  361. if (best_id) {
  362. hDbg->dbgMask |= clients[free_id].last_dbgMask;
  363. } else {
  364. clients[free_id].last_dbgMask = 0;
  365. }
  366. hDbg->Registered = DBG_HANDLE_REG_NEW ;
  367. hDbg->id = (byte)free_id;
  368. hDbg->dbg_end = DI_deregister;
  369. hDbg->dbg_prt = DI_format_locked;
  370. hDbg->dbg_ev = DiProcessEventLog;
  371. hDbg->dbg_irq = DI_format_locked;
  372. if (hDbg->Version > 0) {
  373. hDbg->dbg_old = DI_format_old;
  374. }
  375. hDbg->next = (pDbgHandle)DBG_MAGIC;
  376. /*
  377. Log driver register, MAINT driver ID is '0'
  378. */
  379. len = sprintf (tmp, "DIMAINT - drv # %d = '%s' registered",
  380. free_id, hDbg->drvName);
  381. while (!(pmsg = (diva_dbg_entry_head_t*)queueAllocMsg (dbg_queue,
  382. (word)(len+1+sizeof(*pmsg))))) {
  383. if ((pmsg = (diva_dbg_entry_head_t*)queuePeekMsg (dbg_queue, &size))) {
  384. queueFreeMsg (dbg_queue);
  385. } else {
  386. break;
  387. }
  388. }
  389. if (pmsg) {
  390. pmsg->sequence = dbg_sequence++;
  391. pmsg->time_sec = sec;
  392. pmsg->time_usec = usec;
  393. pmsg->facility = MSG_TYPE_STRING;
  394. pmsg->dli = DLI_REG;
  395. pmsg->drv_id = 0; /* id 0 - DIMAINT */
  396. pmsg->di_cpu = 0;
  397. pmsg->data_length = len+1;
  398. memcpy (&pmsg[1], tmp, len+1);
  399. queueCompleteMsg (pmsg);
  400. diva_maint_wakeup_read();
  401. }
  402. }
  403. diva_os_leave_spin_lock (&dbg_q_lock, &old_irql, "register");
  404. }
  405. static void DI_deregister (pDbgHandle hDbg) {
  406. diva_os_spin_lock_magic_t old_irql, old_irql1;
  407. dword sec, usec;
  408. int i;
  409. word size;
  410. byte* pmem = NULL;
  411. diva_os_get_time (&sec, &usec);
  412. diva_os_enter_spin_lock (&dbg_adapter_lock, &old_irql1, "read");
  413. diva_os_enter_spin_lock (&dbg_q_lock, &old_irql, "read");
  414. for (i = 1; i < ARRAY_SIZE(clients); i++) {
  415. if (clients[i].hDbg == hDbg) {
  416. diva_dbg_entry_head_t* pmsg;
  417. char tmp[256];
  418. int len;
  419. clients[i].hDbg = NULL;
  420. hDbg->id = -1;
  421. hDbg->dbgMask = 0;
  422. hDbg->dbg_end = NULL;
  423. hDbg->dbg_prt = NULL;
  424. hDbg->dbg_irq = NULL;
  425. if (hDbg->Version > 0)
  426. hDbg->dbg_old = NULL;
  427. hDbg->Registered = 0;
  428. hDbg->next = NULL;
  429. if (clients[i].pIdiLib) {
  430. (*(clients[i].pIdiLib->DivaSTraceLibraryFinit))(clients[i].pIdiLib->hLib);
  431. clients[i].pIdiLib = NULL;
  432. pmem = clients[i].pmem;
  433. clients[i].pmem = NULL;
  434. }
  435. /*
  436. Log driver register, MAINT driver ID is '0'
  437. */
  438. len = sprintf (tmp, "DIMAINT - drv # %d = '%s' de-registered",
  439. i, hDbg->drvName);
  440. while (!(pmsg = (diva_dbg_entry_head_t*)queueAllocMsg (dbg_queue,
  441. (word)(len+1+sizeof(*pmsg))))) {
  442. if ((pmsg = (diva_dbg_entry_head_t*)queuePeekMsg (dbg_queue, &size))) {
  443. queueFreeMsg (dbg_queue);
  444. } else {
  445. break;
  446. }
  447. }
  448. if (pmsg) {
  449. pmsg->sequence = dbg_sequence++;
  450. pmsg->time_sec = sec;
  451. pmsg->time_usec = usec;
  452. pmsg->facility = MSG_TYPE_STRING;
  453. pmsg->dli = DLI_REG;
  454. pmsg->drv_id = 0; /* id 0 - DIMAINT */
  455. pmsg->di_cpu = 0;
  456. pmsg->data_length = len+1;
  457. memcpy (&pmsg[1], tmp, len+1);
  458. queueCompleteMsg (pmsg);
  459. diva_maint_wakeup_read();
  460. }
  461. break;
  462. }
  463. }
  464. diva_os_leave_spin_lock (&dbg_q_lock, &old_irql, "read_ack");
  465. diva_os_leave_spin_lock (&dbg_adapter_lock, &old_irql1, "read_ack");
  466. if (pmem) {
  467. diva_os_free (0, pmem);
  468. }
  469. }
  470. static void DI_format_locked (unsigned short id,
  471. int type,
  472. char *format,
  473. va_list argument_list) {
  474. DI_format (1, id, type, format, argument_list);
  475. }
  476. static void DI_format (int do_lock,
  477. unsigned short id,
  478. int type,
  479. char *format,
  480. va_list ap) {
  481. diva_os_spin_lock_magic_t old_irql;
  482. dword sec, usec;
  483. diva_dbg_entry_head_t* pmsg = NULL;
  484. dword length;
  485. word size;
  486. static char fmtBuf[MSG_FRAME_MAX_SIZE+sizeof(*pmsg)+1];
  487. char *data;
  488. unsigned short code;
  489. if (diva_os_in_irq()) {
  490. dbg_sequence++;
  491. return;
  492. }
  493. if ((!format) ||
  494. ((TraceFilter[0] != 0) && ((TraceFilterIdent < 0) || (TraceFilterChannel < 0)))) {
  495. return;
  496. }
  497. diva_os_get_time (&sec, &usec);
  498. if (do_lock) {
  499. diva_os_enter_spin_lock (&dbg_q_lock, &old_irql, "format");
  500. }
  501. switch (type) {
  502. case DLI_MXLOG :
  503. case DLI_BLK :
  504. case DLI_SEND:
  505. case DLI_RECV:
  506. if (!(length = va_arg(ap, unsigned long))) {
  507. break;
  508. }
  509. if (length > MaxDumpSize) {
  510. length = MaxDumpSize;
  511. }
  512. while (!(pmsg = (diva_dbg_entry_head_t*)queueAllocMsg (dbg_queue,
  513. (word)length+sizeof(*pmsg)))) {
  514. if ((pmsg = (diva_dbg_entry_head_t*)queuePeekMsg (dbg_queue, &size))) {
  515. queueFreeMsg (dbg_queue);
  516. } else {
  517. break;
  518. }
  519. }
  520. if (pmsg) {
  521. memcpy (&pmsg[1], format, length);
  522. pmsg->sequence = dbg_sequence++;
  523. pmsg->time_sec = sec;
  524. pmsg->time_usec = usec;
  525. pmsg->facility = MSG_TYPE_BINARY ;
  526. pmsg->dli = type; /* DLI_XXX */
  527. pmsg->drv_id = id; /* driver MAINT id */
  528. pmsg->di_cpu = 0;
  529. pmsg->data_length = length;
  530. queueCompleteMsg (pmsg);
  531. }
  532. break;
  533. case DLI_XLOG: {
  534. byte* p;
  535. data = va_arg(ap, char*);
  536. code = (unsigned short)va_arg(ap, unsigned int);
  537. length = (unsigned long) va_arg(ap, unsigned int);
  538. if (length > MaxXlogSize)
  539. length = MaxXlogSize;
  540. while (!(pmsg = (diva_dbg_entry_head_t*)queueAllocMsg (dbg_queue,
  541. (word)length+sizeof(*pmsg)+2))) {
  542. if ((pmsg = (diva_dbg_entry_head_t*)queuePeekMsg (dbg_queue, &size))) {
  543. queueFreeMsg (dbg_queue);
  544. } else {
  545. break;
  546. }
  547. }
  548. if (pmsg) {
  549. p = (byte*)&pmsg[1];
  550. p[0] = (char)(code) ;
  551. p[1] = (char)(code >> 8) ;
  552. if (data && length) {
  553. memcpy (&p[2], &data[0], length) ;
  554. }
  555. length += 2 ;
  556. pmsg->sequence = dbg_sequence++;
  557. pmsg->time_sec = sec;
  558. pmsg->time_usec = usec;
  559. pmsg->facility = MSG_TYPE_BINARY ;
  560. pmsg->dli = type; /* DLI_XXX */
  561. pmsg->drv_id = id; /* driver MAINT id */
  562. pmsg->di_cpu = 0;
  563. pmsg->data_length = length;
  564. queueCompleteMsg (pmsg);
  565. }
  566. } break;
  567. case DLI_LOG :
  568. case DLI_FTL :
  569. case DLI_ERR :
  570. case DLI_TRC :
  571. case DLI_REG :
  572. case DLI_MEM :
  573. case DLI_SPL :
  574. case DLI_IRP :
  575. case DLI_TIM :
  576. case DLI_TAPI:
  577. case DLI_NDIS:
  578. case DLI_CONN:
  579. case DLI_STAT:
  580. case DLI_PRV0:
  581. case DLI_PRV1:
  582. case DLI_PRV2:
  583. case DLI_PRV3:
  584. if ((length = (unsigned long)vsprintf (&fmtBuf[0], format, ap)) > 0) {
  585. length += (sizeof(*pmsg)+1);
  586. while (!(pmsg = (diva_dbg_entry_head_t*)queueAllocMsg (dbg_queue,
  587. (word)length))) {
  588. if ((pmsg = (diva_dbg_entry_head_t*)queuePeekMsg (dbg_queue, &size))) {
  589. queueFreeMsg (dbg_queue);
  590. } else {
  591. break;
  592. }
  593. }
  594. pmsg->sequence = dbg_sequence++;
  595. pmsg->time_sec = sec;
  596. pmsg->time_usec = usec;
  597. pmsg->facility = MSG_TYPE_STRING;
  598. pmsg->dli = type; /* DLI_XXX */
  599. pmsg->drv_id = id; /* driver MAINT id */
  600. pmsg->di_cpu = 0;
  601. pmsg->data_length = length - sizeof(*pmsg);
  602. memcpy (&pmsg[1], fmtBuf, pmsg->data_length);
  603. queueCompleteMsg (pmsg);
  604. }
  605. break;
  606. } /* switch type */
  607. if (queueCount(dbg_queue)) {
  608. diva_maint_wakeup_read();
  609. }
  610. if (do_lock) {
  611. diva_os_leave_spin_lock (&dbg_q_lock, &old_irql, "format");
  612. }
  613. }
  614. /*
  615. Write driver ID and driver revision to callers buffer
  616. */
  617. int diva_get_driver_info (dword id, byte* data, int data_length) {
  618. diva_os_spin_lock_magic_t old_irql;
  619. byte* p = data;
  620. int to_copy;
  621. if (!data || !id || (data_length < 17) ||
  622. (id >= ARRAY_SIZE(clients))) {
  623. return (-1);
  624. }
  625. diva_os_enter_spin_lock (&dbg_q_lock, &old_irql, "driver info");
  626. if (clients[id].hDbg) {
  627. *p++ = 1;
  628. *p++ = (byte)clients[id].sec; /* save seconds */
  629. *p++ = (byte)(clients[id].sec >> 8);
  630. *p++ = (byte)(clients[id].sec >> 16);
  631. *p++ = (byte)(clients[id].sec >> 24);
  632. *p++ = (byte)(clients[id].usec/1000); /* save mseconds */
  633. *p++ = (byte)((clients[id].usec/1000) >> 8);
  634. *p++ = (byte)((clients[id].usec/1000) >> 16);
  635. *p++ = (byte)((clients[id].usec/1000) >> 24);
  636. data_length -= 9;
  637. if ((to_copy = min(strlen(clients[id].drvName), (size_t)(data_length-1)))) {
  638. memcpy (p, clients[id].drvName, to_copy);
  639. p += to_copy;
  640. data_length -= to_copy;
  641. if ((data_length >= 4) && clients[id].hDbg->drvTag[0]) {
  642. *p++ = '(';
  643. data_length -= 1;
  644. if ((to_copy = min(strlen(clients[id].hDbg->drvTag), (size_t)(data_length-2)))) {
  645. memcpy (p, clients[id].hDbg->drvTag, to_copy);
  646. p += to_copy;
  647. data_length -= to_copy;
  648. if (data_length >= 2) {
  649. *p++ = ')';
  650. data_length--;
  651. }
  652. }
  653. }
  654. }
  655. }
  656. *p++ = 0;
  657. diva_os_leave_spin_lock (&dbg_q_lock, &old_irql, "driver info");
  658. return (p - data);
  659. }
  660. int diva_get_driver_dbg_mask (dword id, byte* data) {
  661. diva_os_spin_lock_magic_t old_irql;
  662. int ret = -1;
  663. if (!data || !id || (id >= ARRAY_SIZE(clients))) {
  664. return (-1);
  665. }
  666. diva_os_enter_spin_lock (&dbg_q_lock, &old_irql, "driver info");
  667. if (clients[id].hDbg) {
  668. ret = 4;
  669. *data++= (byte)(clients[id].hDbg->dbgMask);
  670. *data++= (byte)(clients[id].hDbg->dbgMask >> 8);
  671. *data++= (byte)(clients[id].hDbg->dbgMask >> 16);
  672. *data++= (byte)(clients[id].hDbg->dbgMask >> 24);
  673. }
  674. diva_os_leave_spin_lock (&dbg_q_lock, &old_irql, "driver info");
  675. return (ret);
  676. }
  677. int diva_set_driver_dbg_mask (dword id, dword mask) {
  678. diva_os_spin_lock_magic_t old_irql, old_irql1;
  679. int ret = -1;
  680. if (!id || (id >= ARRAY_SIZE(clients))) {
  681. return (-1);
  682. }
  683. diva_os_enter_spin_lock (&dbg_adapter_lock, &old_irql1, "dbg mask");
  684. diva_os_enter_spin_lock (&dbg_q_lock, &old_irql, "dbg mask");
  685. if (clients[id].hDbg) {
  686. dword old_mask = clients[id].hDbg->dbgMask;
  687. mask &= 0x7fffffff;
  688. clients[id].hDbg->dbgMask = mask;
  689. clients[id].last_dbgMask = (clients[id].hDbg->dbgMask | clients[id].dbgMask);
  690. ret = 4;
  691. diva_change_management_debug_mask (&clients[id], old_mask);
  692. }
  693. diva_os_leave_spin_lock (&dbg_q_lock, &old_irql, "dbg mask");
  694. if (clients[id].request_pending) {
  695. clients[id].request_pending = 0;
  696. (*(clients[id].request))((ENTITY*)(*(clients[id].pIdiLib->DivaSTraceGetHandle))(clients[id].pIdiLib->hLib));
  697. }
  698. diva_os_leave_spin_lock (&dbg_adapter_lock, &old_irql1, "dbg mask");
  699. return (ret);
  700. }
  701. static int diva_get_idi_adapter_info (IDI_CALL request, dword* serial, dword* logical) {
  702. IDI_SYNC_REQ sync_req;
  703. sync_req.xdi_logical_adapter_number.Req = 0;
  704. sync_req.xdi_logical_adapter_number.Rc = IDI_SYNC_REQ_XDI_GET_LOGICAL_ADAPTER_NUMBER;
  705. (*request)((ENTITY *)&sync_req);
  706. *logical = sync_req.xdi_logical_adapter_number.info.logical_adapter_number;
  707. sync_req.GetSerial.Req = 0;
  708. sync_req.GetSerial.Rc = IDI_SYNC_REQ_GET_SERIAL;
  709. sync_req.GetSerial.serial = 0;
  710. (*request)((ENTITY *)&sync_req);
  711. *serial = sync_req.GetSerial.serial;
  712. return (0);
  713. }
  714. /*
  715. Register XDI adapter as MAINT compatible driver
  716. */
  717. void diva_mnt_add_xdi_adapter (const DESCRIPTOR* d) {
  718. diva_os_spin_lock_magic_t old_irql, old_irql1;
  719. dword sec, usec, logical, serial, org_mask;
  720. int id, free_id = -1;
  721. char tmp[128];
  722. diva_dbg_entry_head_t* pmsg = NULL;
  723. int len;
  724. word size;
  725. byte* pmem;
  726. diva_os_get_time (&sec, &usec);
  727. diva_get_idi_adapter_info (d->request, &serial, &logical);
  728. if (serial & 0xff000000) {
  729. sprintf (tmp, "ADAPTER:%d SN:%u-%d",
  730. (int)logical,
  731. serial & 0x00ffffff,
  732. (byte)(((serial & 0xff000000) >> 24) + 1));
  733. } else {
  734. sprintf (tmp, "ADAPTER:%d SN:%u", (int)logical, serial);
  735. }
  736. if (!(pmem = diva_os_malloc (0, DivaSTraceGetMemotyRequirement (d->channels)))) {
  737. return;
  738. }
  739. memset (pmem, 0x00, DivaSTraceGetMemotyRequirement (d->channels));
  740. diva_os_enter_spin_lock (&dbg_adapter_lock, &old_irql1, "register");
  741. diva_os_enter_spin_lock (&dbg_q_lock, &old_irql, "register");
  742. for (id = 1; id < ARRAY_SIZE(clients); id++) {
  743. if (clients[id].hDbg && (clients[id].request == d->request)) {
  744. diva_os_leave_spin_lock (&dbg_q_lock, &old_irql, "register");
  745. diva_os_leave_spin_lock (&dbg_adapter_lock, &old_irql1, "register");
  746. diva_os_free(0, pmem);
  747. return;
  748. }
  749. if (clients[id].hDbg) { /* slot is busy */
  750. continue;
  751. }
  752. if (free_id < 0) {
  753. free_id = id;
  754. }
  755. if (!strcmp (clients[id].drvName, tmp)) {
  756. /*
  757. This driver was already registered with this name
  758. and slot is still free - reuse it
  759. */
  760. free_id = id;
  761. break;
  762. }
  763. }
  764. if (free_id < 0) {
  765. diva_os_leave_spin_lock (&dbg_q_lock, &old_irql, "register");
  766. diva_os_leave_spin_lock (&dbg_adapter_lock, &old_irql1, "register");
  767. diva_os_free (0, pmem);
  768. return;
  769. }
  770. id = free_id;
  771. clients[id].request = d->request;
  772. clients[id].request_pending = 0;
  773. clients[id].hDbg = &clients[id].Dbg;
  774. clients[id].sec = sec;
  775. clients[id].usec = usec;
  776. strcpy (clients[id].drvName, tmp);
  777. strcpy (clients[id].Dbg.drvName, tmp);
  778. clients[id].Dbg.drvTag[0] = 0;
  779. clients[id].logical = (int)logical;
  780. clients[id].channels = (int)d->channels;
  781. clients[id].dma_handle = -1;
  782. clients[id].Dbg.dbgMask = 0;
  783. clients[id].dbgMask = clients[id].Dbg.dbgMask;
  784. if (id) {
  785. clients[id].Dbg.dbgMask |= clients[free_id].last_dbgMask;
  786. } else {
  787. clients[id].last_dbgMask = 0;
  788. }
  789. clients[id].Dbg.Registered = DBG_HANDLE_REG_NEW;
  790. clients[id].Dbg.id = (byte)id;
  791. clients[id].Dbg.dbg_end = DI_deregister;
  792. clients[id].Dbg.dbg_prt = DI_format_locked;
  793. clients[id].Dbg.dbg_ev = DiProcessEventLog;
  794. clients[id].Dbg.dbg_irq = DI_format_locked;
  795. clients[id].Dbg.next = (pDbgHandle)DBG_MAGIC;
  796. {
  797. diva_trace_library_user_interface_t diva_maint_user_ifc = { &clients[id],
  798. diva_maint_state_change_notify,
  799. diva_maint_trace_notify,
  800. diva_maint_error };
  801. /*
  802. Attach to adapter management interface
  803. */
  804. if ((clients[id].pIdiLib =
  805. DivaSTraceLibraryCreateInstance ((int)logical, &diva_maint_user_ifc, pmem))) {
  806. if (((*(clients[id].pIdiLib->DivaSTraceLibraryStart))(clients[id].pIdiLib->hLib))) {
  807. diva_mnt_internal_dprintf (0, DLI_ERR, "Adapter(%d) Start failed", (int)logical);
  808. (*(clients[id].pIdiLib->DivaSTraceLibraryFinit))(clients[id].pIdiLib->hLib);
  809. clients[id].pIdiLib = NULL;
  810. }
  811. } else {
  812. diva_mnt_internal_dprintf (0, DLI_ERR, "A(%d) management init failed", (int)logical);
  813. }
  814. }
  815. if (!clients[id].pIdiLib) {
  816. clients[id].request = NULL;
  817. clients[id].request_pending = 0;
  818. clients[id].hDbg = NULL;
  819. diva_os_leave_spin_lock (&dbg_q_lock, &old_irql, "register");
  820. diva_os_leave_spin_lock (&dbg_adapter_lock, &old_irql1, "register");
  821. diva_os_free (0, pmem);
  822. return;
  823. }
  824. /*
  825. Log driver register, MAINT driver ID is '0'
  826. */
  827. len = sprintf (tmp, "DIMAINT - drv # %d = '%s' registered",
  828. id, clients[id].Dbg.drvName);
  829. while (!(pmsg = (diva_dbg_entry_head_t*)queueAllocMsg (dbg_queue,
  830. (word)(len+1+sizeof(*pmsg))))) {
  831. if ((pmsg = (diva_dbg_entry_head_t*)queuePeekMsg (dbg_queue, &size))) {
  832. queueFreeMsg (dbg_queue);
  833. } else {
  834. break;
  835. }
  836. }
  837. if (pmsg) {
  838. pmsg->sequence = dbg_sequence++;
  839. pmsg->time_sec = sec;
  840. pmsg->time_usec = usec;
  841. pmsg->facility = MSG_TYPE_STRING;
  842. pmsg->dli = DLI_REG;
  843. pmsg->drv_id = 0; /* id 0 - DIMAINT */
  844. pmsg->di_cpu = 0;
  845. pmsg->data_length = len+1;
  846. memcpy (&pmsg[1], tmp, len+1);
  847. queueCompleteMsg (pmsg);
  848. diva_maint_wakeup_read();
  849. }
  850. org_mask = clients[id].Dbg.dbgMask;
  851. clients[id].Dbg.dbgMask = 0;
  852. diva_os_leave_spin_lock (&dbg_q_lock, &old_irql, "register");
  853. if (clients[id].request_pending) {
  854. clients[id].request_pending = 0;
  855. (*(clients[id].request))((ENTITY*)(*(clients[id].pIdiLib->DivaSTraceGetHandle))(clients[id].pIdiLib->hLib));
  856. }
  857. diva_os_leave_spin_lock (&dbg_adapter_lock, &old_irql1, "register");
  858. diva_set_driver_dbg_mask (id, org_mask);
  859. }
  860. /*
  861. De-Register XDI adapter
  862. */
  863. void diva_mnt_remove_xdi_adapter (const DESCRIPTOR* d) {
  864. diva_os_spin_lock_magic_t old_irql, old_irql1;
  865. dword sec, usec;
  866. int i;
  867. word size;
  868. byte* pmem = NULL;
  869. diva_os_get_time (&sec, &usec);
  870. diva_os_enter_spin_lock (&dbg_adapter_lock, &old_irql1, "read");
  871. diva_os_enter_spin_lock (&dbg_q_lock, &old_irql, "read");
  872. for (i = 1; i < ARRAY_SIZE(clients); i++) {
  873. if (clients[i].hDbg && (clients[i].request == d->request)) {
  874. diva_dbg_entry_head_t* pmsg;
  875. char tmp[256];
  876. int len;
  877. if (clients[i].pIdiLib) {
  878. (*(clients[i].pIdiLib->DivaSTraceLibraryFinit))(clients[i].pIdiLib->hLib);
  879. clients[i].pIdiLib = NULL;
  880. pmem = clients[i].pmem;
  881. clients[i].pmem = NULL;
  882. }
  883. clients[i].hDbg = NULL;
  884. clients[i].request_pending = 0;
  885. if (clients[i].dma_handle >= 0) {
  886. /*
  887. Free DMA handle
  888. */
  889. diva_free_dma_descriptor (clients[i].request, clients[i].dma_handle);
  890. clients[i].dma_handle = -1;
  891. }
  892. clients[i].request = NULL;
  893. /*
  894. Log driver register, MAINT driver ID is '0'
  895. */
  896. len = sprintf (tmp, "DIMAINT - drv # %d = '%s' de-registered",
  897. i, clients[i].Dbg.drvName);
  898. memset (&clients[i].Dbg, 0x00, sizeof(clients[i].Dbg));
  899. while (!(pmsg = (diva_dbg_entry_head_t*)queueAllocMsg (dbg_queue,
  900. (word)(len+1+sizeof(*pmsg))))) {
  901. if ((pmsg = (diva_dbg_entry_head_t*)queuePeekMsg (dbg_queue, &size))) {
  902. queueFreeMsg (dbg_queue);
  903. } else {
  904. break;
  905. }
  906. }
  907. if (pmsg) {
  908. pmsg->sequence = dbg_sequence++;
  909. pmsg->time_sec = sec;
  910. pmsg->time_usec = usec;
  911. pmsg->facility = MSG_TYPE_STRING;
  912. pmsg->dli = DLI_REG;
  913. pmsg->drv_id = 0; /* id 0 - DIMAINT */
  914. pmsg->di_cpu = 0;
  915. pmsg->data_length = len+1;
  916. memcpy (&pmsg[1], tmp, len+1);
  917. queueCompleteMsg (pmsg);
  918. diva_maint_wakeup_read();
  919. }
  920. break;
  921. }
  922. }
  923. diva_os_leave_spin_lock (&dbg_q_lock, &old_irql, "read_ack");
  924. diva_os_leave_spin_lock (&dbg_adapter_lock, &old_irql1, "read_ack");
  925. if (pmem) {
  926. diva_os_free (0, pmem);
  927. }
  928. }
  929. /* ----------------------------------------------------------------
  930. Low level interface for management interface client
  931. ---------------------------------------------------------------- */
  932. /*
  933. Return handle to client structure
  934. */
  935. void* SuperTraceOpenAdapter (int AdapterNumber) {
  936. int i;
  937. for (i = 1; i < ARRAY_SIZE(clients); i++) {
  938. if (clients[i].hDbg && clients[i].request && (clients[i].logical == AdapterNumber)) {
  939. return (&clients[i]);
  940. }
  941. }
  942. return NULL;
  943. }
  944. int SuperTraceCloseAdapter (void* AdapterHandle) {
  945. return (0);
  946. }
  947. int SuperTraceReadRequest (void* AdapterHandle, const char* name, byte* data) {
  948. diva_maint_client_t* pC = (diva_maint_client_t*)AdapterHandle;
  949. if (pC && pC->pIdiLib && pC->request) {
  950. ENTITY* e = (ENTITY*)(*(pC->pIdiLib->DivaSTraceGetHandle))(pC->pIdiLib->hLib);
  951. byte* xdata = (byte*)&pC->xbuffer[0];
  952. char tmp = 0;
  953. word length;
  954. if (!strcmp(name, "\\")) { /* Read ROOT */
  955. name = &tmp;
  956. }
  957. length = SuperTraceCreateReadReq (xdata, name);
  958. single_p (xdata, &length, 0); /* End Of Message */
  959. e->Req = MAN_READ;
  960. e->ReqCh = 0;
  961. e->X->PLength = length;
  962. e->X->P = (byte*)xdata;
  963. pC->request_pending = 1;
  964. return (0);
  965. }
  966. return (-1);
  967. }
  968. int SuperTraceGetNumberOfChannels (void* AdapterHandle) {
  969. if (AdapterHandle) {
  970. diva_maint_client_t* pC = (diva_maint_client_t*)AdapterHandle;
  971. return (pC->channels);
  972. }
  973. return (0);
  974. }
  975. int SuperTraceASSIGN (void* AdapterHandle, byte* data) {
  976. diva_maint_client_t* pC = (diva_maint_client_t*)AdapterHandle;
  977. if (pC && pC->pIdiLib && pC->request) {
  978. ENTITY* e = (ENTITY*)(*(pC->pIdiLib->DivaSTraceGetHandle))(pC->pIdiLib->hLib);
  979. IDI_SYNC_REQ* preq;
  980. char buffer[((sizeof(preq->xdi_extended_features)+4) > sizeof(ENTITY)) ? (sizeof(preq->xdi_extended_features)+4) : sizeof(ENTITY)];
  981. char features[4];
  982. word assign_data_length = 1;
  983. features[0] = 0;
  984. pC->xbuffer[0] = 0;
  985. preq = (IDI_SYNC_REQ*)&buffer[0];
  986. preq->xdi_extended_features.Req = 0;
  987. preq->xdi_extended_features.Rc = IDI_SYNC_REQ_XDI_GET_EXTENDED_FEATURES;
  988. preq->xdi_extended_features.info.buffer_length_in_bytes = sizeof(features);
  989. preq->xdi_extended_features.info.features = &features[0];
  990. (*(pC->request))((ENTITY*)preq);
  991. if ((features[0] & DIVA_XDI_EXTENDED_FEATURES_VALID) &&
  992. (features[0] & DIVA_XDI_EXTENDED_FEATURE_MANAGEMENT_DMA)) {
  993. dword uninitialized_var(rx_dma_magic);
  994. if ((pC->dma_handle = diva_get_dma_descriptor (pC->request, &rx_dma_magic)) >= 0) {
  995. pC->xbuffer[0] = LLI;
  996. pC->xbuffer[1] = 8;
  997. pC->xbuffer[2] = 0x40;
  998. pC->xbuffer[3] = (byte)pC->dma_handle;
  999. pC->xbuffer[4] = (byte)rx_dma_magic;
  1000. pC->xbuffer[5] = (byte)(rx_dma_magic >> 8);
  1001. pC->xbuffer[6] = (byte)(rx_dma_magic >> 16);
  1002. pC->xbuffer[7] = (byte)(rx_dma_magic >> 24);
  1003. pC->xbuffer[8] = (byte)(DIVA_MAX_MANAGEMENT_TRANSFER_SIZE & 0xFF);
  1004. pC->xbuffer[9] = (byte)(DIVA_MAX_MANAGEMENT_TRANSFER_SIZE >> 8);
  1005. pC->xbuffer[10] = 0;
  1006. assign_data_length = 11;
  1007. }
  1008. } else {
  1009. pC->dma_handle = -1;
  1010. }
  1011. e->Id = MAN_ID;
  1012. e->callback = diva_maint_xdi_cb;
  1013. e->XNum = 1;
  1014. e->X = &pC->XData;
  1015. e->Req = ASSIGN;
  1016. e->ReqCh = 0;
  1017. e->X->PLength = assign_data_length;
  1018. e->X->P = (byte*)&pC->xbuffer[0];
  1019. pC->request_pending = 1;
  1020. return (0);
  1021. }
  1022. return (-1);
  1023. }
  1024. int SuperTraceREMOVE (void* AdapterHandle) {
  1025. diva_maint_client_t* pC = (diva_maint_client_t*)AdapterHandle;
  1026. if (pC && pC->pIdiLib && pC->request) {
  1027. ENTITY* e = (ENTITY*)(*(pC->pIdiLib->DivaSTraceGetHandle))(pC->pIdiLib->hLib);
  1028. e->XNum = 1;
  1029. e->X = &pC->XData;
  1030. e->Req = REMOVE;
  1031. e->ReqCh = 0;
  1032. e->X->PLength = 1;
  1033. e->X->P = (byte*)&pC->xbuffer[0];
  1034. pC->xbuffer[0] = 0;
  1035. pC->request_pending = 1;
  1036. return (0);
  1037. }
  1038. return (-1);
  1039. }
  1040. int SuperTraceTraceOnRequest(void* hAdapter, const char* name, byte* data) {
  1041. diva_maint_client_t* pC = (diva_maint_client_t*)hAdapter;
  1042. if (pC && pC->pIdiLib && pC->request) {
  1043. ENTITY* e = (ENTITY*)(*(pC->pIdiLib->DivaSTraceGetHandle))(pC->pIdiLib->hLib);
  1044. byte* xdata = (byte*)&pC->xbuffer[0];
  1045. char tmp = 0;
  1046. word length;
  1047. if (!strcmp(name, "\\")) { /* Read ROOT */
  1048. name = &tmp;
  1049. }
  1050. length = SuperTraceCreateReadReq (xdata, name);
  1051. single_p (xdata, &length, 0); /* End Of Message */
  1052. e->Req = MAN_EVENT_ON;
  1053. e->ReqCh = 0;
  1054. e->X->PLength = length;
  1055. e->X->P = (byte*)xdata;
  1056. pC->request_pending = 1;
  1057. return (0);
  1058. }
  1059. return (-1);
  1060. }
  1061. int SuperTraceWriteVar (void* AdapterHandle,
  1062. byte* data,
  1063. const char* name,
  1064. void* var,
  1065. byte type,
  1066. byte var_length) {
  1067. diva_maint_client_t* pC = (diva_maint_client_t*)AdapterHandle;
  1068. if (pC && pC->pIdiLib && pC->request) {
  1069. ENTITY* e = (ENTITY*)(*(pC->pIdiLib->DivaSTraceGetHandle))(pC->pIdiLib->hLib);
  1070. diva_man_var_header_t* pVar = (diva_man_var_header_t*)&pC->xbuffer[0];
  1071. word length = SuperTraceCreateReadReq ((byte*)pVar, name);
  1072. memcpy (&pC->xbuffer[length], var, var_length);
  1073. length += var_length;
  1074. pVar->length += var_length;
  1075. pVar->value_length = var_length;
  1076. pVar->type = type;
  1077. single_p ((byte*)pVar, &length, 0); /* End Of Message */
  1078. e->Req = MAN_WRITE;
  1079. e->ReqCh = 0;
  1080. e->X->PLength = length;
  1081. e->X->P = (byte*)pVar;
  1082. pC->request_pending = 1;
  1083. return (0);
  1084. }
  1085. return (-1);
  1086. }
  1087. int SuperTraceExecuteRequest (void* AdapterHandle,
  1088. const char* name,
  1089. byte* data) {
  1090. diva_maint_client_t* pC = (diva_maint_client_t*)AdapterHandle;
  1091. if (pC && pC->pIdiLib && pC->request) {
  1092. ENTITY* e = (ENTITY*)(*(pC->pIdiLib->DivaSTraceGetHandle))(pC->pIdiLib->hLib);
  1093. byte* xdata = (byte*)&pC->xbuffer[0];
  1094. word length;
  1095. length = SuperTraceCreateReadReq (xdata, name);
  1096. single_p (xdata, &length, 0); /* End Of Message */
  1097. e->Req = MAN_EXECUTE;
  1098. e->ReqCh = 0;
  1099. e->X->PLength = length;
  1100. e->X->P = (byte*)xdata;
  1101. pC->request_pending = 1;
  1102. return (0);
  1103. }
  1104. return (-1);
  1105. }
  1106. static word SuperTraceCreateReadReq (byte* P, const char* path) {
  1107. byte var_length;
  1108. byte* plen;
  1109. var_length = (byte)strlen (path);
  1110. *P++ = ESC;
  1111. plen = P++;
  1112. *P++ = 0x80; /* MAN_IE */
  1113. *P++ = 0x00; /* Type */
  1114. *P++ = 0x00; /* Attribute */
  1115. *P++ = 0x00; /* Status */
  1116. *P++ = 0x00; /* Variable Length */
  1117. *P++ = var_length;
  1118. memcpy (P, path, var_length);
  1119. P += var_length;
  1120. *plen = var_length + 0x06;
  1121. return ((word)(var_length + 0x08));
  1122. }
  1123. static void single_p (byte * P, word * PLength, byte Id) {
  1124. P[(*PLength)++] = Id;
  1125. }
  1126. static void diva_maint_xdi_cb (ENTITY* e) {
  1127. diva_strace_context_t* pLib = DIVAS_CONTAINING_RECORD(e,diva_strace_context_t,e);
  1128. diva_maint_client_t* pC;
  1129. diva_os_spin_lock_magic_t old_irql, old_irql1;
  1130. diva_os_enter_spin_lock (&dbg_adapter_lock, &old_irql1, "xdi_cb");
  1131. diva_os_enter_spin_lock (&dbg_q_lock, &old_irql, "xdi_cb");
  1132. pC = (diva_maint_client_t*)pLib->hAdapter;
  1133. if ((e->complete == 255) || (pC->dma_handle < 0)) {
  1134. if ((*(pLib->instance.DivaSTraceMessageInput))(&pLib->instance)) {
  1135. diva_mnt_internal_dprintf (0, DLI_ERR, "Trace internal library error");
  1136. }
  1137. } else {
  1138. /*
  1139. Process combined management interface indication
  1140. */
  1141. if ((*(pLib->instance.DivaSTraceMessageInput))(&pLib->instance)) {
  1142. diva_mnt_internal_dprintf (0, DLI_ERR, "Trace internal library error (DMA mode)");
  1143. }
  1144. }
  1145. diva_os_leave_spin_lock (&dbg_q_lock, &old_irql, "xdi_cb");
  1146. if (pC->request_pending) {
  1147. pC->request_pending = 0;
  1148. (*(pC->request))(e);
  1149. }
  1150. diva_os_leave_spin_lock (&dbg_adapter_lock, &old_irql1, "xdi_cb");
  1151. }
  1152. static void diva_maint_error (void* user_context,
  1153. diva_strace_library_interface_t* hLib,
  1154. int Adapter,
  1155. int error,
  1156. const char* file,
  1157. int line) {
  1158. diva_mnt_internal_dprintf (0, DLI_ERR,
  1159. "Trace library error(%d) A(%d) %s %d", error, Adapter, file, line);
  1160. }
  1161. static void print_ie (diva_trace_ie_t* ie, char* buffer, int length) {
  1162. int i;
  1163. buffer[0] = 0;
  1164. if (length > 32) {
  1165. for (i = 0; ((i < ie->length) && (length > 3)); i++) {
  1166. sprintf (buffer, "%02x", ie->data[i]);
  1167. buffer += 2;
  1168. length -= 2;
  1169. if (i < (ie->length-1)) {
  1170. strcpy (buffer, " ");
  1171. buffer++;
  1172. length--;
  1173. }
  1174. }
  1175. }
  1176. }
  1177. static void diva_maint_state_change_notify (void* user_context,
  1178. diva_strace_library_interface_t* hLib,
  1179. int Adapter,
  1180. diva_trace_line_state_t* channel,
  1181. int notify_subject) {
  1182. diva_maint_client_t* pC = (diva_maint_client_t*)user_context;
  1183. diva_trace_fax_state_t* fax = &channel->fax;
  1184. diva_trace_modem_state_t* modem = &channel->modem;
  1185. char tmp[256];
  1186. if (!pC->hDbg) {
  1187. return;
  1188. }
  1189. switch (notify_subject) {
  1190. case DIVA_SUPER_TRACE_NOTIFY_LINE_CHANGE: {
  1191. int view = (TraceFilter[0] == 0);
  1192. /*
  1193. Process selective Trace
  1194. */
  1195. if (channel->Line[0] == 'I' && channel->Line[1] == 'd' &&
  1196. channel->Line[2] == 'l' && channel->Line[3] == 'e') {
  1197. if ((TraceFilterIdent == pC->hDbg->id) && (TraceFilterChannel == (int)channel->ChannelNumber)) {
  1198. (*(hLib->DivaSTraceSetBChannel))(hLib, (int)channel->ChannelNumber, 0);
  1199. (*(hLib->DivaSTraceSetAudioTap))(hLib, (int)channel->ChannelNumber, 0);
  1200. diva_mnt_internal_dprintf (pC->hDbg->id, DLI_LOG, "Selective Trace OFF for Ch=%d",
  1201. (int)channel->ChannelNumber);
  1202. TraceFilterIdent = -1;
  1203. TraceFilterChannel = -1;
  1204. view = 1;
  1205. }
  1206. } else if (TraceFilter[0] && (TraceFilterIdent < 0) && !(diva_mnt_cmp_nmbr (&channel->RemoteAddress[0]) &&
  1207. diva_mnt_cmp_nmbr (&channel->LocalAddress[0]))) {
  1208. if ((pC->hDbg->dbgMask & DIVA_MGT_DBG_IFC_BCHANNEL) != 0) { /* Activate B-channel trace */
  1209. (*(hLib->DivaSTraceSetBChannel))(hLib, (int)channel->ChannelNumber, 1);
  1210. }
  1211. if ((pC->hDbg->dbgMask & DIVA_MGT_DBG_IFC_AUDIO) != 0) { /* Activate AudioTap Trace */
  1212. (*(hLib->DivaSTraceSetAudioTap))(hLib, (int)channel->ChannelNumber, 1);
  1213. }
  1214. TraceFilterIdent = pC->hDbg->id;
  1215. TraceFilterChannel = (int)channel->ChannelNumber;
  1216. if (TraceFilterIdent >= 0) {
  1217. diva_mnt_internal_dprintf (pC->hDbg->id, DLI_LOG, "Selective Trace ON for Ch=%d",
  1218. (int)channel->ChannelNumber);
  1219. view = 1;
  1220. }
  1221. }
  1222. if (view && (pC->hDbg->dbgMask & DIVA_MGT_DBG_LINE_EVENTS)) {
  1223. diva_mnt_internal_dprintf (pC->hDbg->id, DLI_STAT, "L Ch = %d",
  1224. (int)channel->ChannelNumber);
  1225. diva_mnt_internal_dprintf (pC->hDbg->id, DLI_STAT, "L Status = <%s>", &channel->Line[0]);
  1226. diva_mnt_internal_dprintf (pC->hDbg->id, DLI_STAT, "L Layer1 = <%s>", &channel->Framing[0]);
  1227. diva_mnt_internal_dprintf (pC->hDbg->id, DLI_STAT, "L Layer2 = <%s>", &channel->Layer2[0]);
  1228. diva_mnt_internal_dprintf (pC->hDbg->id, DLI_STAT, "L Layer3 = <%s>", &channel->Layer3[0]);
  1229. diva_mnt_internal_dprintf (pC->hDbg->id, DLI_STAT, "L RAddr = <%s>",
  1230. &channel->RemoteAddress[0]);
  1231. diva_mnt_internal_dprintf (pC->hDbg->id, DLI_STAT, "L RSAddr = <%s>",
  1232. &channel->RemoteSubAddress[0]);
  1233. diva_mnt_internal_dprintf (pC->hDbg->id, DLI_STAT, "L LAddr = <%s>",
  1234. &channel->LocalAddress[0]);
  1235. diva_mnt_internal_dprintf (pC->hDbg->id, DLI_STAT, "L LSAddr = <%s>",
  1236. &channel->LocalSubAddress[0]);
  1237. print_ie(&channel->call_BC, tmp, sizeof(tmp));
  1238. diva_mnt_internal_dprintf (pC->hDbg->id, DLI_STAT, "L BC = <%s>", tmp);
  1239. print_ie(&channel->call_HLC, tmp, sizeof(tmp));
  1240. diva_mnt_internal_dprintf (pC->hDbg->id, DLI_STAT, "L HLC = <%s>", tmp);
  1241. print_ie(&channel->call_LLC, tmp, sizeof(tmp));
  1242. diva_mnt_internal_dprintf (pC->hDbg->id, DLI_STAT, "L LLC = <%s>", tmp);
  1243. diva_mnt_internal_dprintf (pC->hDbg->id, DLI_STAT, "L CR = 0x%x", channel->CallReference);
  1244. diva_mnt_internal_dprintf (pC->hDbg->id, DLI_STAT, "L Disc = 0x%x",
  1245. channel->LastDisconnecCause);
  1246. diva_mnt_internal_dprintf (pC->hDbg->id, DLI_STAT, "L Owner = <%s>", &channel->UserID[0]);
  1247. }
  1248. } break;
  1249. case DIVA_SUPER_TRACE_NOTIFY_MODEM_CHANGE:
  1250. if (pC->hDbg->dbgMask & DIVA_MGT_DBG_MDM_PROGRESS) {
  1251. {
  1252. int ch = TraceFilterChannel;
  1253. int id = TraceFilterIdent;
  1254. if ((id >= 0) && (ch >= 0) && (id < ARRAY_SIZE(clients)) &&
  1255. (clients[id].Dbg.id == (byte)id) && (clients[id].pIdiLib == hLib)) {
  1256. if (ch != (int)modem->ChannelNumber) {
  1257. break;
  1258. }
  1259. } else if (TraceFilter[0] != 0) {
  1260. break;
  1261. }
  1262. }
  1263. diva_mnt_internal_dprintf(pC->hDbg->id, DLI_STAT, "MDM Ch = %lu",
  1264. (int)modem->ChannelNumber);
  1265. diva_mnt_internal_dprintf(pC->hDbg->id, DLI_STAT, "MDM Event = %lu", modem->Event);
  1266. diva_mnt_internal_dprintf(pC->hDbg->id, DLI_STAT, "MDM Norm = %lu", modem->Norm);
  1267. diva_mnt_internal_dprintf(pC->hDbg->id, DLI_STAT, "MDM Opts. = 0x%08x", modem->Options);
  1268. diva_mnt_internal_dprintf(pC->hDbg->id, DLI_STAT, "MDM Tx = %lu Bps", modem->TxSpeed);
  1269. diva_mnt_internal_dprintf(pC->hDbg->id, DLI_STAT, "MDM Rx = %lu Bps", modem->RxSpeed);
  1270. diva_mnt_internal_dprintf(pC->hDbg->id, DLI_STAT, "MDM RT = %lu mSec",
  1271. modem->RoundtripMsec);
  1272. diva_mnt_internal_dprintf(pC->hDbg->id, DLI_STAT, "MDM Sr = %lu", modem->SymbolRate);
  1273. diva_mnt_internal_dprintf(pC->hDbg->id, DLI_STAT, "MDM Rxl = %d dBm", modem->RxLeveldBm);
  1274. diva_mnt_internal_dprintf(pC->hDbg->id, DLI_STAT, "MDM El = %d dBm", modem->EchoLeveldBm);
  1275. diva_mnt_internal_dprintf(pC->hDbg->id, DLI_STAT, "MDM SNR = %lu dB", modem->SNRdb);
  1276. diva_mnt_internal_dprintf(pC->hDbg->id, DLI_STAT, "MDM MAE = %lu", modem->MAE);
  1277. diva_mnt_internal_dprintf(pC->hDbg->id, DLI_STAT, "MDM LRet = %lu",
  1278. modem->LocalRetrains);
  1279. diva_mnt_internal_dprintf(pC->hDbg->id, DLI_STAT, "MDM RRet = %lu",
  1280. modem->RemoteRetrains);
  1281. diva_mnt_internal_dprintf(pC->hDbg->id, DLI_STAT, "MDM LRes = %lu", modem->LocalResyncs);
  1282. diva_mnt_internal_dprintf(pC->hDbg->id, DLI_STAT, "MDM RRes = %lu",
  1283. modem->RemoteResyncs);
  1284. if (modem->Event == 3) {
  1285. diva_mnt_internal_dprintf(pC->hDbg->id,DLI_STAT,"MDM Disc = %lu", modem->DiscReason);
  1286. }
  1287. }
  1288. if ((modem->Event == 3) && (pC->hDbg->dbgMask & DIVA_MGT_DBG_MDM_STATISTICS)) {
  1289. (*(pC->pIdiLib->DivaSTraceGetModemStatistics))(pC->pIdiLib);
  1290. }
  1291. break;
  1292. case DIVA_SUPER_TRACE_NOTIFY_FAX_CHANGE:
  1293. if (pC->hDbg->dbgMask & DIVA_MGT_DBG_FAX_PROGRESS) {
  1294. {
  1295. int ch = TraceFilterChannel;
  1296. int id = TraceFilterIdent;
  1297. if ((id >= 0) && (ch >= 0) && (id < ARRAY_SIZE(clients)) &&
  1298. (clients[id].Dbg.id == (byte)id) && (clients[id].pIdiLib == hLib)) {
  1299. if (ch != (int)fax->ChannelNumber) {
  1300. break;
  1301. }
  1302. } else if (TraceFilter[0] != 0) {
  1303. break;
  1304. }
  1305. }
  1306. diva_mnt_internal_dprintf(pC->hDbg->id, DLI_STAT, "FAX Ch = %lu",(int)fax->ChannelNumber);
  1307. diva_mnt_internal_dprintf(pC->hDbg->id, DLI_STAT, "FAX Event = %lu", fax->Event);
  1308. diva_mnt_internal_dprintf(pC->hDbg->id, DLI_STAT, "FAX Pages = %lu", fax->Page_Counter);
  1309. diva_mnt_internal_dprintf(pC->hDbg->id, DLI_STAT, "FAX Feat. = 0x%08x", fax->Features);
  1310. diva_mnt_internal_dprintf(pC->hDbg->id, DLI_STAT, "FAX ID = <%s>", &fax->Station_ID[0]);
  1311. diva_mnt_internal_dprintf(pC->hDbg->id, DLI_STAT, "FAX Saddr = <%s>", &fax->Subaddress[0]);
  1312. diva_mnt_internal_dprintf(pC->hDbg->id, DLI_STAT, "FAX Pwd = <%s>", &fax->Password[0]);
  1313. diva_mnt_internal_dprintf(pC->hDbg->id, DLI_STAT, "FAX Speed = %lu", fax->Speed);
  1314. diva_mnt_internal_dprintf(pC->hDbg->id, DLI_STAT, "FAX Res. = 0x%08x", fax->Resolution);
  1315. diva_mnt_internal_dprintf(pC->hDbg->id, DLI_STAT, "FAX Width = %lu", fax->Paper_Width);
  1316. diva_mnt_internal_dprintf(pC->hDbg->id, DLI_STAT, "FAX Length= %lu", fax->Paper_Length);
  1317. diva_mnt_internal_dprintf(pC->hDbg->id, DLI_STAT, "FAX SLT = %lu", fax->Scanline_Time);
  1318. if (fax->Event == 3) {
  1319. diva_mnt_internal_dprintf(pC->hDbg->id, DLI_STAT, "FAX Disc = %lu", fax->Disc_Reason);
  1320. }
  1321. }
  1322. if ((fax->Event == 3) && (pC->hDbg->dbgMask & DIVA_MGT_DBG_FAX_STATISTICS)) {
  1323. (*(pC->pIdiLib->DivaSTraceGetFaxStatistics))(pC->pIdiLib);
  1324. }
  1325. break;
  1326. case DIVA_SUPER_TRACE_INTERFACE_CHANGE:
  1327. if (pC->hDbg->dbgMask & DIVA_MGT_DBG_IFC_EVENTS) {
  1328. diva_mnt_internal_dprintf (pC->hDbg->id, DLI_STAT,
  1329. "Layer 1 -> [%s]", channel->pInterface->Layer1);
  1330. diva_mnt_internal_dprintf (pC->hDbg->id, DLI_STAT,
  1331. "Layer 2 -> [%s]", channel->pInterface->Layer2);
  1332. }
  1333. break;
  1334. case DIVA_SUPER_TRACE_NOTIFY_STAT_CHANGE:
  1335. if (pC->hDbg->dbgMask & DIVA_MGT_DBG_IFC_STATISTICS) {
  1336. /*
  1337. Incoming Statistics
  1338. */
  1339. if (channel->pInterfaceStat->inc.Calls) {
  1340. diva_mnt_internal_dprintf (pC->hDbg->id, DLI_LOG,
  1341. "Inc Calls =%lu", channel->pInterfaceStat->inc.Calls);
  1342. }
  1343. if (channel->pInterfaceStat->inc.Connected) {
  1344. diva_mnt_internal_dprintf (pC->hDbg->id, DLI_LOG,
  1345. "Inc Connected =%lu", channel->pInterfaceStat->inc.Connected);
  1346. }
  1347. if (channel->pInterfaceStat->inc.User_Busy) {
  1348. diva_mnt_internal_dprintf (pC->hDbg->id, DLI_LOG,
  1349. "Inc Busy =%lu", channel->pInterfaceStat->inc.User_Busy);
  1350. }
  1351. if (channel->pInterfaceStat->inc.Call_Rejected) {
  1352. diva_mnt_internal_dprintf (pC->hDbg->id, DLI_LOG,
  1353. "Inc Rejected =%lu", channel->pInterfaceStat->inc.Call_Rejected);
  1354. }
  1355. if (channel->pInterfaceStat->inc.Wrong_Number) {
  1356. diva_mnt_internal_dprintf (pC->hDbg->id, DLI_LOG,
  1357. "Inc Wrong Nr =%lu", channel->pInterfaceStat->inc.Wrong_Number);
  1358. }
  1359. if (channel->pInterfaceStat->inc.Incompatible_Dst) {
  1360. diva_mnt_internal_dprintf (pC->hDbg->id, DLI_LOG,
  1361. "Inc Incomp. Dest =%lu", channel->pInterfaceStat->inc.Incompatible_Dst);
  1362. }
  1363. if (channel->pInterfaceStat->inc.Out_of_Order) {
  1364. diva_mnt_internal_dprintf (pC->hDbg->id, DLI_LOG,
  1365. "Inc Out of Order =%lu", channel->pInterfaceStat->inc.Out_of_Order);
  1366. }
  1367. if (channel->pInterfaceStat->inc.Ignored) {
  1368. diva_mnt_internal_dprintf (pC->hDbg->id, DLI_LOG,
  1369. "Inc Ignored =%lu", channel->pInterfaceStat->inc.Ignored);
  1370. }
  1371. /*
  1372. Outgoing Statistics
  1373. */
  1374. if (channel->pInterfaceStat->outg.Calls) {
  1375. diva_mnt_internal_dprintf (pC->hDbg->id, DLI_LOG,
  1376. "Outg Calls =%lu", channel->pInterfaceStat->outg.Calls);
  1377. }
  1378. if (channel->pInterfaceStat->outg.Connected) {
  1379. diva_mnt_internal_dprintf (pC->hDbg->id, DLI_LOG,
  1380. "Outg Connected =%lu", channel->pInterfaceStat->outg.Connected);
  1381. }
  1382. if (channel->pInterfaceStat->outg.User_Busy) {
  1383. diva_mnt_internal_dprintf (pC->hDbg->id, DLI_LOG,
  1384. "Outg Busy =%lu", channel->pInterfaceStat->outg.User_Busy);
  1385. }
  1386. if (channel->pInterfaceStat->outg.No_Answer) {
  1387. diva_mnt_internal_dprintf (pC->hDbg->id, DLI_LOG,
  1388. "Outg No Answer =%lu", channel->pInterfaceStat->outg.No_Answer);
  1389. }
  1390. if (channel->pInterfaceStat->outg.Wrong_Number) {
  1391. diva_mnt_internal_dprintf (pC->hDbg->id, DLI_LOG,
  1392. "Outg Wrong Nr =%lu", channel->pInterfaceStat->outg.Wrong_Number);
  1393. }
  1394. if (channel->pInterfaceStat->outg.Call_Rejected) {
  1395. diva_mnt_internal_dprintf (pC->hDbg->id, DLI_LOG,
  1396. "Outg Rejected =%lu", channel->pInterfaceStat->outg.Call_Rejected);
  1397. }
  1398. if (channel->pInterfaceStat->outg.Other_Failures) {
  1399. diva_mnt_internal_dprintf (pC->hDbg->id, DLI_LOG,
  1400. "Outg Other Failures =%lu", channel->pInterfaceStat->outg.Other_Failures);
  1401. }
  1402. }
  1403. break;
  1404. case DIVA_SUPER_TRACE_NOTIFY_MDM_STAT_CHANGE:
  1405. if (channel->pInterfaceStat->mdm.Disc_Normal) {
  1406. diva_mnt_internal_dprintf (pC->hDbg->id, DLI_LOG,
  1407. "MDM Disc Normal = %lu", channel->pInterfaceStat->mdm.Disc_Normal);
  1408. }
  1409. if (channel->pInterfaceStat->mdm.Disc_Unspecified) {
  1410. diva_mnt_internal_dprintf (pC->hDbg->id, DLI_LOG,
  1411. "MDM Disc Unsp. = %lu", channel->pInterfaceStat->mdm.Disc_Unspecified);
  1412. }
  1413. if (channel->pInterfaceStat->mdm.Disc_Busy_Tone) {
  1414. diva_mnt_internal_dprintf (pC->hDbg->id, DLI_LOG,
  1415. "MDM Disc Busy Tone = %lu", channel->pInterfaceStat->mdm.Disc_Busy_Tone);
  1416. }
  1417. if (channel->pInterfaceStat->mdm.Disc_Congestion) {
  1418. diva_mnt_internal_dprintf (pC->hDbg->id, DLI_LOG,
  1419. "MDM Disc Congestion = %lu", channel->pInterfaceStat->mdm.Disc_Congestion);
  1420. }
  1421. if (channel->pInterfaceStat->mdm.Disc_Carr_Wait) {
  1422. diva_mnt_internal_dprintf (pC->hDbg->id, DLI_LOG,
  1423. "MDM Disc Carrier Wait = %lu", channel->pInterfaceStat->mdm.Disc_Carr_Wait);
  1424. }
  1425. if (channel->pInterfaceStat->mdm.Disc_Trn_Timeout) {
  1426. diva_mnt_internal_dprintf (pC->hDbg->id, DLI_LOG,
  1427. "MDM Disc Trn. T.o. = %lu", channel->pInterfaceStat->mdm.Disc_Trn_Timeout);
  1428. }
  1429. if (channel->pInterfaceStat->mdm.Disc_Incompat) {
  1430. diva_mnt_internal_dprintf (pC->hDbg->id, DLI_LOG,
  1431. "MDM Disc Incompatible = %lu", channel->pInterfaceStat->mdm.Disc_Incompat);
  1432. }
  1433. if (channel->pInterfaceStat->mdm.Disc_Frame_Rej) {
  1434. diva_mnt_internal_dprintf (pC->hDbg->id, DLI_LOG,
  1435. "MDM Disc Frame Reject = %lu", channel->pInterfaceStat->mdm.Disc_Frame_Rej);
  1436. }
  1437. if (channel->pInterfaceStat->mdm.Disc_V42bis) {
  1438. diva_mnt_internal_dprintf (pC->hDbg->id, DLI_LOG,
  1439. "MDM Disc V.42bis = %lu", channel->pInterfaceStat->mdm.Disc_V42bis);
  1440. }
  1441. break;
  1442. case DIVA_SUPER_TRACE_NOTIFY_FAX_STAT_CHANGE:
  1443. if (channel->pInterfaceStat->fax.Disc_Normal) {
  1444. diva_mnt_internal_dprintf (pC->hDbg->id, DLI_LOG,
  1445. "FAX Disc Normal = %lu", channel->pInterfaceStat->fax.Disc_Normal);
  1446. }
  1447. if (channel->pInterfaceStat->fax.Disc_Not_Ident) {
  1448. diva_mnt_internal_dprintf (pC->hDbg->id, DLI_LOG,
  1449. "FAX Disc Not Ident. = %lu", channel->pInterfaceStat->fax.Disc_Not_Ident);
  1450. }
  1451. if (channel->pInterfaceStat->fax.Disc_No_Response) {
  1452. diva_mnt_internal_dprintf (pC->hDbg->id, DLI_LOG,
  1453. "FAX Disc No Response = %lu", channel->pInterfaceStat->fax.Disc_No_Response);
  1454. }
  1455. if (channel->pInterfaceStat->fax.Disc_Retries) {
  1456. diva_mnt_internal_dprintf (pC->hDbg->id, DLI_LOG,
  1457. "FAX Disc Max Retries = %lu", channel->pInterfaceStat->fax.Disc_Retries);
  1458. }
  1459. if (channel->pInterfaceStat->fax.Disc_Unexp_Msg) {
  1460. diva_mnt_internal_dprintf (pC->hDbg->id, DLI_LOG,
  1461. "FAX Unexp. Msg. = %lu", channel->pInterfaceStat->fax.Disc_Unexp_Msg);
  1462. }
  1463. if (channel->pInterfaceStat->fax.Disc_No_Polling) {
  1464. diva_mnt_internal_dprintf (pC->hDbg->id, DLI_LOG,
  1465. "FAX Disc No Polling = %lu", channel->pInterfaceStat->fax.Disc_No_Polling);
  1466. }
  1467. if (channel->pInterfaceStat->fax.Disc_Training) {
  1468. diva_mnt_internal_dprintf (pC->hDbg->id, DLI_LOG,
  1469. "FAX Disc Training = %lu", channel->pInterfaceStat->fax.Disc_Training);
  1470. }
  1471. if (channel->pInterfaceStat->fax.Disc_Unexpected) {
  1472. diva_mnt_internal_dprintf (pC->hDbg->id, DLI_LOG,
  1473. "FAX Disc Unexpected = %lu", channel->pInterfaceStat->fax.Disc_Unexpected);
  1474. }
  1475. if (channel->pInterfaceStat->fax.Disc_Application) {
  1476. diva_mnt_internal_dprintf (pC->hDbg->id, DLI_LOG,
  1477. "FAX Disc Application = %lu", channel->pInterfaceStat->fax.Disc_Application);
  1478. }
  1479. if (channel->pInterfaceStat->fax.Disc_Incompat) {
  1480. diva_mnt_internal_dprintf (pC->hDbg->id, DLI_LOG,
  1481. "FAX Disc Incompatible = %lu", channel->pInterfaceStat->fax.Disc_Incompat);
  1482. }
  1483. if (channel->pInterfaceStat->fax.Disc_No_Command) {
  1484. diva_mnt_internal_dprintf (pC->hDbg->id, DLI_LOG,
  1485. "FAX Disc No Command = %lu", channel->pInterfaceStat->fax.Disc_No_Command);
  1486. }
  1487. if (channel->pInterfaceStat->fax.Disc_Long_Msg) {
  1488. diva_mnt_internal_dprintf (pC->hDbg->id, DLI_LOG,
  1489. "FAX Disc Long Msg. = %lu", channel->pInterfaceStat->fax.Disc_Long_Msg);
  1490. }
  1491. if (channel->pInterfaceStat->fax.Disc_Supervisor) {
  1492. diva_mnt_internal_dprintf (pC->hDbg->id, DLI_LOG,
  1493. "FAX Disc Supervisor = %lu", channel->pInterfaceStat->fax.Disc_Supervisor);
  1494. }
  1495. if (channel->pInterfaceStat->fax.Disc_SUB_SEP_PWD) {
  1496. diva_mnt_internal_dprintf (pC->hDbg->id, DLI_LOG,
  1497. "FAX Disc SUP SEP PWD = %lu", channel->pInterfaceStat->fax.Disc_SUB_SEP_PWD);
  1498. }
  1499. if (channel->pInterfaceStat->fax.Disc_Invalid_Msg) {
  1500. diva_mnt_internal_dprintf (pC->hDbg->id, DLI_LOG,
  1501. "FAX Disc Invalid Msg. = %lu", channel->pInterfaceStat->fax.Disc_Invalid_Msg);
  1502. }
  1503. if (channel->pInterfaceStat->fax.Disc_Page_Coding) {
  1504. diva_mnt_internal_dprintf (pC->hDbg->id, DLI_LOG,
  1505. "FAX Disc Page Coding = %lu", channel->pInterfaceStat->fax.Disc_Page_Coding);
  1506. }
  1507. if (channel->pInterfaceStat->fax.Disc_App_Timeout) {
  1508. diva_mnt_internal_dprintf (pC->hDbg->id, DLI_LOG,
  1509. "FAX Disc Appl. T.o. = %lu", channel->pInterfaceStat->fax.Disc_App_Timeout);
  1510. }
  1511. if (channel->pInterfaceStat->fax.Disc_Unspecified) {
  1512. diva_mnt_internal_dprintf (pC->hDbg->id, DLI_LOG,
  1513. "FAX Disc Unspec. = %lu", channel->pInterfaceStat->fax.Disc_Unspecified);
  1514. }
  1515. break;
  1516. }
  1517. }
  1518. /*
  1519. Receive trace information from the Management Interface and store it in the
  1520. internal trace buffer with MSG_TYPE_MLOG as is, without any filtering.
  1521. Event Filtering and formatting is done in Management Interface self.
  1522. */
  1523. static void diva_maint_trace_notify (void* user_context,
  1524. diva_strace_library_interface_t* hLib,
  1525. int Adapter,
  1526. void* xlog_buffer,
  1527. int length) {
  1528. diva_maint_client_t* pC = (diva_maint_client_t*)user_context;
  1529. diva_dbg_entry_head_t* pmsg;
  1530. word size;
  1531. dword sec, usec;
  1532. int ch = TraceFilterChannel;
  1533. int id = TraceFilterIdent;
  1534. /*
  1535. Selective trace
  1536. */
  1537. if ((id >= 0) && (ch >= 0) && (id < ARRAY_SIZE(clients)) &&
  1538. (clients[id].Dbg.id == (byte)id) && (clients[id].pIdiLib == hLib)) {
  1539. const char* p = NULL;
  1540. int ch_value = -1;
  1541. MI_XLOG_HDR *TrcData = (MI_XLOG_HDR *)xlog_buffer;
  1542. if (Adapter != clients[id].logical) {
  1543. return; /* Ignore all trace messages from other adapters */
  1544. }
  1545. if (TrcData->code == 24) {
  1546. p = (char*)&TrcData->code;
  1547. p += 2;
  1548. }
  1549. /*
  1550. All L1 messages start as [dsp,ch], so we can filter this information
  1551. and filter out all messages that use different channel
  1552. */
  1553. if (p && p[0] == '[') {
  1554. if (p[2] == ',') {
  1555. p += 3;
  1556. ch_value = *p - '0';
  1557. } else if (p[3] == ',') {
  1558. p += 4;
  1559. ch_value = *p - '0';
  1560. }
  1561. if (ch_value >= 0) {
  1562. if (p[2] == ']') {
  1563. ch_value = ch_value * 10 + p[1] - '0';
  1564. }
  1565. if (ch_value != ch) {
  1566. return; /* Ignore other channels */
  1567. }
  1568. }
  1569. }
  1570. } else if (TraceFilter[0] != 0) {
  1571. return; /* Ignore trace if trace filter is activated, but idle */
  1572. }
  1573. diva_os_get_time (&sec, &usec);
  1574. while (!(pmsg = (diva_dbg_entry_head_t*)queueAllocMsg (dbg_queue,
  1575. (word)length+sizeof(*pmsg)))) {
  1576. if ((pmsg = (diva_dbg_entry_head_t*)queuePeekMsg (dbg_queue, &size))) {
  1577. queueFreeMsg (dbg_queue);
  1578. } else {
  1579. break;
  1580. }
  1581. }
  1582. if (pmsg) {
  1583. memcpy (&pmsg[1], xlog_buffer, length);
  1584. pmsg->sequence = dbg_sequence++;
  1585. pmsg->time_sec = sec;
  1586. pmsg->time_usec = usec;
  1587. pmsg->facility = MSG_TYPE_MLOG;
  1588. pmsg->dli = pC->logical;
  1589. pmsg->drv_id = pC->hDbg->id;
  1590. pmsg->di_cpu = 0;
  1591. pmsg->data_length = length;
  1592. queueCompleteMsg (pmsg);
  1593. if (queueCount(dbg_queue)) {
  1594. diva_maint_wakeup_read();
  1595. }
  1596. }
  1597. }
  1598. /*
  1599. Convert MAINT trace mask to management interface trace mask/work/facility and
  1600. issue command to management interface
  1601. */
  1602. static void diva_change_management_debug_mask (diva_maint_client_t* pC, dword old_mask) {
  1603. if (pC->request && pC->hDbg && pC->pIdiLib) {
  1604. dword changed = pC->hDbg->dbgMask ^ old_mask;
  1605. if (changed & DIVA_MGT_DBG_TRACE) {
  1606. (*(pC->pIdiLib->DivaSTraceSetInfo))(pC->pIdiLib,
  1607. (pC->hDbg->dbgMask & DIVA_MGT_DBG_TRACE) != 0);
  1608. }
  1609. if (changed & DIVA_MGT_DBG_DCHAN) {
  1610. (*(pC->pIdiLib->DivaSTraceSetDChannel))(pC->pIdiLib,
  1611. (pC->hDbg->dbgMask & DIVA_MGT_DBG_DCHAN) != 0);
  1612. }
  1613. if (!TraceFilter[0]) {
  1614. if (changed & DIVA_MGT_DBG_IFC_BCHANNEL) {
  1615. int i, state = ((pC->hDbg->dbgMask & DIVA_MGT_DBG_IFC_BCHANNEL) != 0);
  1616. for (i = 0; i < pC->channels; i++) {
  1617. (*(pC->pIdiLib->DivaSTraceSetBChannel))(pC->pIdiLib, i+1, state);
  1618. }
  1619. }
  1620. if (changed & DIVA_MGT_DBG_IFC_AUDIO) {
  1621. int i, state = ((pC->hDbg->dbgMask & DIVA_MGT_DBG_IFC_AUDIO) != 0);
  1622. for (i = 0; i < pC->channels; i++) {
  1623. (*(pC->pIdiLib->DivaSTraceSetAudioTap))(pC->pIdiLib, i+1, state);
  1624. }
  1625. }
  1626. }
  1627. }
  1628. }
  1629. void diva_mnt_internal_dprintf (dword drv_id, dword type, char* fmt, ...) {
  1630. va_list ap;
  1631. va_start(ap, fmt);
  1632. DI_format (0, (word)drv_id, (int)type, fmt, ap);
  1633. va_end(ap);
  1634. }
  1635. /*
  1636. Shutdown all adapters before driver removal
  1637. */
  1638. int diva_mnt_shutdown_xdi_adapters (void) {
  1639. diva_os_spin_lock_magic_t old_irql, old_irql1;
  1640. int i, fret = 0;
  1641. byte * pmem;
  1642. for (i = 1; i < ARRAY_SIZE(clients); i++) {
  1643. pmem = NULL;
  1644. diva_os_enter_spin_lock (&dbg_adapter_lock, &old_irql1, "unload");
  1645. diva_os_enter_spin_lock (&dbg_q_lock, &old_irql, "unload");
  1646. if (clients[i].hDbg && clients[i].pIdiLib && clients[i].request) {
  1647. if ((*(clients[i].pIdiLib->DivaSTraceLibraryStop))(clients[i].pIdiLib) == 1) {
  1648. /*
  1649. Adapter removal complete
  1650. */
  1651. if (clients[i].pIdiLib) {
  1652. (*(clients[i].pIdiLib->DivaSTraceLibraryFinit))(clients[i].pIdiLib->hLib);
  1653. clients[i].pIdiLib = NULL;
  1654. pmem = clients[i].pmem;
  1655. clients[i].pmem = NULL;
  1656. }
  1657. clients[i].hDbg = NULL;
  1658. clients[i].request_pending = 0;
  1659. if (clients[i].dma_handle >= 0) {
  1660. /*
  1661. Free DMA handle
  1662. */
  1663. diva_free_dma_descriptor (clients[i].request, clients[i].dma_handle);
  1664. clients[i].dma_handle = -1;
  1665. }
  1666. clients[i].request = NULL;
  1667. } else {
  1668. fret = -1;
  1669. }
  1670. }
  1671. diva_os_leave_spin_lock (&dbg_q_lock, &old_irql, "unload");
  1672. if (clients[i].hDbg && clients[i].pIdiLib && clients[i].request && clients[i].request_pending) {
  1673. clients[i].request_pending = 0;
  1674. (*(clients[i].request))((ENTITY*)(*(clients[i].pIdiLib->DivaSTraceGetHandle))(clients[i].pIdiLib->hLib));
  1675. if (clients[i].dma_handle >= 0) {
  1676. diva_free_dma_descriptor (clients[i].request, clients[i].dma_handle);
  1677. clients[i].dma_handle = -1;
  1678. }
  1679. }
  1680. diva_os_leave_spin_lock (&dbg_adapter_lock, &old_irql1, "unload");
  1681. if (pmem) {
  1682. diva_os_free (0, pmem);
  1683. }
  1684. }
  1685. return (fret);
  1686. }
  1687. /*
  1688. Set/Read the trace filter used for selective tracing.
  1689. Affects B- and Audio Tap trace mask at run time
  1690. */
  1691. int diva_set_trace_filter (int filter_length, const char* filter) {
  1692. diva_os_spin_lock_magic_t old_irql, old_irql1;
  1693. int i, ch, on, client_b_on, client_atap_on;
  1694. diva_os_enter_spin_lock (&dbg_adapter_lock, &old_irql1, "dbg mask");
  1695. diva_os_enter_spin_lock (&dbg_q_lock, &old_irql, "write_filter");
  1696. if (filter_length <= DIVA_MAX_SELECTIVE_FILTER_LENGTH) {
  1697. memcpy (&TraceFilter[0], filter, filter_length);
  1698. if (TraceFilter[filter_length]) {
  1699. TraceFilter[filter_length] = 0;
  1700. }
  1701. if (TraceFilter[0] == '*') {
  1702. TraceFilter[0] = 0;
  1703. }
  1704. } else {
  1705. filter_length = -1;
  1706. }
  1707. TraceFilterIdent = -1;
  1708. TraceFilterChannel = -1;
  1709. on = (TraceFilter[0] == 0);
  1710. for (i = 1; i < ARRAY_SIZE(clients); i++) {
  1711. if (clients[i].hDbg && clients[i].pIdiLib && clients[i].request) {
  1712. client_b_on = on && ((clients[i].hDbg->dbgMask & DIVA_MGT_DBG_IFC_BCHANNEL) != 0);
  1713. client_atap_on = on && ((clients[i].hDbg->dbgMask & DIVA_MGT_DBG_IFC_AUDIO) != 0);
  1714. for (ch = 0; ch < clients[i].channels; ch++) {
  1715. (*(clients[i].pIdiLib->DivaSTraceSetBChannel))(clients[i].pIdiLib->hLib, ch+1, client_b_on);
  1716. (*(clients[i].pIdiLib->DivaSTraceSetAudioTap))(clients[i].pIdiLib->hLib, ch+1, client_atap_on);
  1717. }
  1718. }
  1719. }
  1720. for (i = 1; i < ARRAY_SIZE(clients); i++) {
  1721. if (clients[i].hDbg && clients[i].pIdiLib && clients[i].request && clients[i].request_pending) {
  1722. diva_os_leave_spin_lock (&dbg_q_lock, &old_irql, "write_filter");
  1723. clients[i].request_pending = 0;
  1724. (*(clients[i].request))((ENTITY*)(*(clients[i].pIdiLib->DivaSTraceGetHandle))(clients[i].pIdiLib->hLib));
  1725. diva_os_enter_spin_lock (&dbg_q_lock, &old_irql, "write_filter");
  1726. }
  1727. }
  1728. diva_os_leave_spin_lock (&dbg_q_lock, &old_irql, "write_filter");
  1729. diva_os_leave_spin_lock (&dbg_adapter_lock, &old_irql1, "dbg mask");
  1730. return (filter_length);
  1731. }
  1732. int diva_get_trace_filter (int max_length, char* filter) {
  1733. diva_os_spin_lock_magic_t old_irql;
  1734. int len;
  1735. diva_os_enter_spin_lock (&dbg_q_lock, &old_irql, "read_filter");
  1736. len = strlen (&TraceFilter[0]) + 1;
  1737. if (max_length >= len) {
  1738. memcpy (filter, &TraceFilter[0], len);
  1739. }
  1740. diva_os_leave_spin_lock (&dbg_q_lock, &old_irql, "read_filter");
  1741. return (len);
  1742. }
  1743. static int diva_dbg_cmp_key (const char* ref, const char* key) {
  1744. while (*key && (*ref++ == *key++));
  1745. return (!*key && !*ref);
  1746. }
  1747. /*
  1748. In case trace filter starts with "C" character then
  1749. all following characters are interpreted as command.
  1750. Followings commands are available:
  1751. - single, trace single call at time, independent from CPN/CiPN
  1752. */
  1753. static int diva_mnt_cmp_nmbr (const char* nmbr) {
  1754. const char* ref = &TraceFilter[0];
  1755. int ref_len = strlen(&TraceFilter[0]), nmbr_len = strlen(nmbr);
  1756. if (ref[0] == 'C') {
  1757. if (diva_dbg_cmp_key (&ref[1], "single")) {
  1758. return (0);
  1759. }
  1760. return (-1);
  1761. }
  1762. if (!ref_len || (ref_len > nmbr_len)) {
  1763. return (-1);
  1764. }
  1765. nmbr = nmbr + nmbr_len - 1;
  1766. ref = ref + ref_len - 1;
  1767. while (ref_len--) {
  1768. if (*nmbr-- != *ref--) {
  1769. return (-1);
  1770. }
  1771. }
  1772. return (0);
  1773. }
  1774. static int diva_get_dma_descriptor (IDI_CALL request, dword *dma_magic) {
  1775. ENTITY e;
  1776. IDI_SYNC_REQ* pReq = (IDI_SYNC_REQ*)&e;
  1777. if (!request) {
  1778. return (-1);
  1779. }
  1780. pReq->xdi_dma_descriptor_operation.Req = 0;
  1781. pReq->xdi_dma_descriptor_operation.Rc = IDI_SYNC_REQ_DMA_DESCRIPTOR_OPERATION;
  1782. pReq->xdi_dma_descriptor_operation.info.operation = IDI_SYNC_REQ_DMA_DESCRIPTOR_ALLOC;
  1783. pReq->xdi_dma_descriptor_operation.info.descriptor_number = -1;
  1784. pReq->xdi_dma_descriptor_operation.info.descriptor_address = NULL;
  1785. pReq->xdi_dma_descriptor_operation.info.descriptor_magic = 0;
  1786. (*request)((ENTITY*)pReq);
  1787. if (!pReq->xdi_dma_descriptor_operation.info.operation &&
  1788. (pReq->xdi_dma_descriptor_operation.info.descriptor_number >= 0) &&
  1789. pReq->xdi_dma_descriptor_operation.info.descriptor_magic) {
  1790. *dma_magic = pReq->xdi_dma_descriptor_operation.info.descriptor_magic;
  1791. return (pReq->xdi_dma_descriptor_operation.info.descriptor_number);
  1792. } else {
  1793. return (-1);
  1794. }
  1795. }
  1796. static void diva_free_dma_descriptor (IDI_CALL request, int nr) {
  1797. ENTITY e;
  1798. IDI_SYNC_REQ* pReq = (IDI_SYNC_REQ*)&e;
  1799. if (!request || (nr < 0)) {
  1800. return;
  1801. }
  1802. pReq->xdi_dma_descriptor_operation.Req = 0;
  1803. pReq->xdi_dma_descriptor_operation.Rc = IDI_SYNC_REQ_DMA_DESCRIPTOR_OPERATION;
  1804. pReq->xdi_dma_descriptor_operation.info.operation = IDI_SYNC_REQ_DMA_DESCRIPTOR_FREE;
  1805. pReq->xdi_dma_descriptor_operation.info.descriptor_number = nr;
  1806. pReq->xdi_dma_descriptor_operation.info.descriptor_address = NULL;
  1807. pReq->xdi_dma_descriptor_operation.info.descriptor_magic = 0;
  1808. (*request)((ENTITY*)pReq);
  1809. }