debug.c 61 KB

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