debug.c 62 KB

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