debug.c 61 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128
  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. }