di.c 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835
  1. /*
  2. *
  3. Copyright (c) Eicon Networks, 2002.
  4. *
  5. This source file is supplied for the use with
  6. Eicon Networks range of DIVA Server Adapters.
  7. *
  8. Eicon File Revision : 2.1
  9. *
  10. This program is free software; you can redistribute it and/or modify
  11. it under the terms of the GNU General Public License as published by
  12. the Free Software Foundation; either version 2, or (at your option)
  13. any later version.
  14. *
  15. This program is distributed in the hope that it will be useful,
  16. but WITHOUT ANY WARRANTY OF ANY KIND WHATSOEVER INCLUDING ANY
  17. implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  18. See the GNU General Public License for more details.
  19. *
  20. You should have received a copy of the GNU General Public License
  21. along with this program; if not, write to the Free Software
  22. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  23. *
  24. */
  25. #include "platform.h"
  26. #include "pc.h"
  27. #include "pr_pc.h"
  28. #include "di_defs.h"
  29. #include "di.h"
  30. #if !defined USE_EXTENDED_DEBUGS
  31. #include "dimaint.h"
  32. #else
  33. #define dprintf
  34. #endif
  35. #include "io.h"
  36. #include "dfifo.h"
  37. #define PR_RAM ((struct pr_ram *)0)
  38. #define RAM ((struct dual *)0)
  39. /*------------------------------------------------------------------*/
  40. /* local function prototypes */
  41. /*------------------------------------------------------------------*/
  42. void pr_out(ADAPTER *a);
  43. byte pr_dpc(ADAPTER *a);
  44. static byte pr_ready(ADAPTER *a);
  45. static byte isdn_rc(ADAPTER *, byte, byte, byte, word, dword, dword);
  46. static byte isdn_ind(ADAPTER *, byte, byte, byte, PBUFFER *, byte, word);
  47. /* -----------------------------------------------------------------
  48. Functions used for the extended XDI Debug
  49. macros
  50. global convergence counter (used by all adapters)
  51. Look by the implementation part of the functions
  52. about the parameters.
  53. If you change the dubugging parameters, then you should update
  54. the aididbg.doc in the IDI doc's.
  55. ----------------------------------------------------------------- */
  56. #if defined(XDI_USE_XLOG)
  57. #define XDI_A_NR(_x_) ((byte)(((ISDN_ADAPTER *)(_x_->io))->ANum))
  58. static void xdi_xlog(byte *msg, word code, int length);
  59. static byte xdi_xlog_sec = 0;
  60. #else
  61. #define XDI_A_NR(_x_) ((byte)0)
  62. #endif
  63. static void xdi_xlog_rc_event(byte Adapter,
  64. byte Id, byte Ch, byte Rc, byte cb, byte type);
  65. static void xdi_xlog_request(byte Adapter, byte Id,
  66. byte Ch, byte Req, byte type);
  67. static void xdi_xlog_ind(byte Adapter,
  68. byte Id,
  69. byte Ch,
  70. byte Ind,
  71. byte rnr_valid,
  72. byte rnr,
  73. byte type);
  74. /*------------------------------------------------------------------*/
  75. /* output function */
  76. /*------------------------------------------------------------------*/
  77. void pr_out(ADAPTER *a)
  78. {
  79. byte e_no;
  80. ENTITY *this = NULL;
  81. BUFFERS *X;
  82. word length;
  83. word i;
  84. word clength;
  85. REQ *ReqOut;
  86. byte more;
  87. byte ReadyCount;
  88. byte ReqCount;
  89. byte Id;
  90. dtrc(dprintf("pr_out"));
  91. /* while a request is pending ... */
  92. e_no = look_req(a);
  93. if (!e_no)
  94. {
  95. dtrc(dprintf("no_req"));
  96. return;
  97. }
  98. ReadyCount = pr_ready(a);
  99. if (!ReadyCount)
  100. {
  101. dtrc(dprintf("not_ready"));
  102. return;
  103. }
  104. ReqCount = 0;
  105. while (e_no && ReadyCount) {
  106. next_req(a);
  107. this = entity_ptr(a, e_no);
  108. #ifdef USE_EXTENDED_DEBUGS
  109. if (!this)
  110. {
  111. DBG_FTL(("XDI: [%02x] !A%d ==> NULL entity ptr - try to ignore",
  112. xdi_xlog_sec++, (int)((ISDN_ADAPTER *)a->io)->ANum))
  113. e_no = look_req(a);
  114. ReadyCount--;
  115. continue;
  116. }
  117. {
  118. DBG_TRC((">A%d Id=0x%x Req=0x%x", ((ISDN_ADAPTER *)a->io)->ANum, this->Id, this->Req))
  119. }
  120. #else
  121. dbug(dprintf("out:Req=%x,Id=%x,Ch=%x", this->Req, this->Id, this->ReqCh));
  122. #endif
  123. /* get address of next available request buffer */
  124. ReqOut = (REQ *)&PR_RAM->B[a->ram_inw(a, &PR_RAM->NextReq)];
  125. #if defined(DIVA_ISTREAM)
  126. if (!(a->tx_stream[this->Id] &&
  127. this->Req == N_DATA)) {
  128. #endif
  129. /* now copy the data from the current data buffer into the */
  130. /* adapters request buffer */
  131. length = 0;
  132. i = this->XCurrent;
  133. X = PTR_X(a, this);
  134. while (i < this->XNum && length < 270) {
  135. clength = min((word)(270 - length), (word)(X[i].PLength-this->XOffset));
  136. a->ram_out_buffer(a,
  137. &ReqOut->XBuffer.P[length],
  138. PTR_P(a, this, &X[i].P[this->XOffset]),
  139. clength);
  140. length += clength;
  141. this->XOffset += clength;
  142. if (this->XOffset == X[i].PLength) {
  143. this->XCurrent = (byte)++i;
  144. this->XOffset = 0;
  145. }
  146. }
  147. #if defined(DIVA_ISTREAM)
  148. } else { /* Use CMA extension in order to transfer data to the card */
  149. i = this->XCurrent;
  150. X = PTR_X(a, this);
  151. while (i < this->XNum) {
  152. diva_istream_write(a,
  153. this->Id,
  154. PTR_P(a, this, &X[i].P[0]),
  155. X[i].PLength,
  156. ((i + 1) == this->XNum),
  157. 0, 0);
  158. this->XCurrent = (byte)++i;
  159. }
  160. length = 0;
  161. }
  162. #endif
  163. a->ram_outw(a, &ReqOut->XBuffer.length, length);
  164. a->ram_out(a, &ReqOut->ReqId, this->Id);
  165. a->ram_out(a, &ReqOut->ReqCh, this->ReqCh);
  166. /* if it's a specific request (no ASSIGN) ... */
  167. if (this->Id & 0x1f) {
  168. /* if buffers are left in the list of data buffers do */
  169. /* do chaining (LL_MDATA, N_MDATA) */
  170. this->More++;
  171. if (i < this->XNum && this->MInd) {
  172. xdi_xlog_request(XDI_A_NR(a), this->Id, this->ReqCh, this->MInd,
  173. a->IdTypeTable[this->No]);
  174. a->ram_out(a, &ReqOut->Req, this->MInd);
  175. more = true;
  176. }
  177. else {
  178. xdi_xlog_request(XDI_A_NR(a), this->Id, this->ReqCh, this->Req,
  179. a->IdTypeTable[this->No]);
  180. this->More |= XMOREF;
  181. a->ram_out(a, &ReqOut->Req, this->Req);
  182. more = false;
  183. if (a->FlowControlIdTable[this->ReqCh] == this->Id)
  184. a->FlowControlSkipTable[this->ReqCh] = true;
  185. /*
  186. Note that remove request was sent to the card
  187. */
  188. if (this->Req == REMOVE) {
  189. a->misc_flags_table[e_no] |= DIVA_MISC_FLAGS_REMOVE_PENDING;
  190. }
  191. }
  192. /* if we did chaining, this entity is put back into the */
  193. /* request queue */
  194. if (more) {
  195. req_queue(a, this->No);
  196. }
  197. }
  198. /* else it's a ASSIGN */
  199. else {
  200. /* save the request code used for buffer chaining */
  201. this->MInd = 0;
  202. if (this->Id == BLLC_ID) this->MInd = LL_MDATA;
  203. if (this->Id == NL_ID ||
  204. this->Id == TASK_ID ||
  205. this->Id == MAN_ID
  206. ) this->MInd = N_MDATA;
  207. /* send the ASSIGN */
  208. a->IdTypeTable[this->No] = this->Id;
  209. xdi_xlog_request(XDI_A_NR(a), this->Id, this->ReqCh, this->Req, this->Id);
  210. this->More |= XMOREF;
  211. a->ram_out(a, &ReqOut->Req, this->Req);
  212. /* save the reference of the ASSIGN */
  213. assign_queue(a, this->No, a->ram_inw(a, &ReqOut->Reference));
  214. }
  215. a->ram_outw(a, &PR_RAM->NextReq, a->ram_inw(a, &ReqOut->next));
  216. ReadyCount--;
  217. ReqCount++;
  218. e_no = look_req(a);
  219. }
  220. /* send the filled request buffers to the ISDN adapter */
  221. a->ram_out(a, &PR_RAM->ReqInput,
  222. (byte)(a->ram_in(a, &PR_RAM->ReqInput) + ReqCount));
  223. /* if it is a 'unreturncoded' UREMOVE request, remove the */
  224. /* Id from our table after sending the request */
  225. if (this && (this->Req == UREMOVE) && this->Id) {
  226. Id = this->Id;
  227. e_no = a->IdTable[Id];
  228. free_entity(a, e_no);
  229. for (i = 0; i < 256; i++)
  230. {
  231. if (a->FlowControlIdTable[i] == Id)
  232. a->FlowControlIdTable[i] = 0;
  233. }
  234. a->IdTable[Id] = 0;
  235. this->Id = 0;
  236. }
  237. }
  238. static byte pr_ready(ADAPTER *a)
  239. {
  240. byte ReadyCount;
  241. ReadyCount = (byte)(a->ram_in(a, &PR_RAM->ReqOutput) -
  242. a->ram_in(a, &PR_RAM->ReqInput));
  243. if (!ReadyCount) {
  244. if (!a->ReadyInt) {
  245. a->ram_inc(a, &PR_RAM->ReadyInt);
  246. a->ReadyInt++;
  247. }
  248. }
  249. return ReadyCount;
  250. }
  251. /*------------------------------------------------------------------*/
  252. /* isdn interrupt handler */
  253. /*------------------------------------------------------------------*/
  254. byte pr_dpc(ADAPTER *a)
  255. {
  256. byte Count;
  257. RC *RcIn;
  258. IND *IndIn;
  259. byte c;
  260. byte RNRId;
  261. byte Rc;
  262. byte Ind;
  263. /* if return codes are available ... */
  264. if ((Count = a->ram_in(a, &PR_RAM->RcOutput)) != 0) {
  265. dtrc(dprintf("#Rc=%x", Count));
  266. /* get the buffer address of the first return code */
  267. RcIn = (RC *)&PR_RAM->B[a->ram_inw(a, &PR_RAM->NextRc)];
  268. /* for all return codes do ... */
  269. while (Count--) {
  270. if ((Rc = a->ram_in(a, &RcIn->Rc)) != 0) {
  271. dword tmp[2];
  272. /*
  273. Get extended information, associated with return code
  274. */
  275. a->ram_in_buffer(a,
  276. &RcIn->Reserved2[0],
  277. (byte *)&tmp[0],
  278. 8);
  279. /* call return code handler, if it is not our return code */
  280. /* the handler returns 2 */
  281. /* for all return codes we process, we clear the Rc field */
  282. isdn_rc(a,
  283. Rc,
  284. a->ram_in(a, &RcIn->RcId),
  285. a->ram_in(a, &RcIn->RcCh),
  286. a->ram_inw(a, &RcIn->Reference),
  287. tmp[0], /* type of extended information */
  288. tmp[1]); /* extended information */
  289. a->ram_out(a, &RcIn->Rc, 0);
  290. }
  291. /* get buffer address of next return code */
  292. RcIn = (RC *)&PR_RAM->B[a->ram_inw(a, &RcIn->next)];
  293. }
  294. /* clear all return codes (no chaining!) */
  295. a->ram_out(a, &PR_RAM->RcOutput, 0);
  296. /* call output function */
  297. pr_out(a);
  298. }
  299. /* clear RNR flag */
  300. RNRId = 0;
  301. /* if indications are available ... */
  302. if ((Count = a->ram_in(a, &PR_RAM->IndOutput)) != 0) {
  303. dtrc(dprintf("#Ind=%x", Count));
  304. /* get the buffer address of the first indication */
  305. IndIn = (IND *)&PR_RAM->B[a->ram_inw(a, &PR_RAM->NextInd)];
  306. /* for all indications do ... */
  307. while (Count--) {
  308. /* if the application marks an indication as RNR, all */
  309. /* indications from the same Id delivered in this interrupt */
  310. /* are marked RNR */
  311. if (RNRId && RNRId == a->ram_in(a, &IndIn->IndId)) {
  312. a->ram_out(a, &IndIn->Ind, 0);
  313. a->ram_out(a, &IndIn->RNR, true);
  314. }
  315. else {
  316. Ind = a->ram_in(a, &IndIn->Ind);
  317. if (Ind) {
  318. RNRId = 0;
  319. /* call indication handler, a return value of 2 means chain */
  320. /* a return value of 1 means RNR */
  321. /* for all indications we process, we clear the Ind field */
  322. c = isdn_ind(a,
  323. Ind,
  324. a->ram_in(a, &IndIn->IndId),
  325. a->ram_in(a, &IndIn->IndCh),
  326. &IndIn->RBuffer,
  327. a->ram_in(a, &IndIn->MInd),
  328. a->ram_inw(a, &IndIn->MLength));
  329. if (c == 1) {
  330. dtrc(dprintf("RNR"));
  331. a->ram_out(a, &IndIn->Ind, 0);
  332. RNRId = a->ram_in(a, &IndIn->IndId);
  333. a->ram_out(a, &IndIn->RNR, true);
  334. }
  335. }
  336. }
  337. /* get buffer address of next indication */
  338. IndIn = (IND *)&PR_RAM->B[a->ram_inw(a, &IndIn->next)];
  339. }
  340. a->ram_out(a, &PR_RAM->IndOutput, 0);
  341. }
  342. return false;
  343. }
  344. byte scom_test_int(ADAPTER *a)
  345. {
  346. return a->ram_in(a, (void *)0x3fe);
  347. }
  348. void scom_clear_int(ADAPTER *a)
  349. {
  350. a->ram_out(a, (void *)0x3fe, 0);
  351. }
  352. /*------------------------------------------------------------------*/
  353. /* return code handler */
  354. /*------------------------------------------------------------------*/
  355. static byte isdn_rc(ADAPTER *a,
  356. byte Rc,
  357. byte Id,
  358. byte Ch,
  359. word Ref,
  360. dword extended_info_type,
  361. dword extended_info)
  362. {
  363. ENTITY *this;
  364. byte e_no;
  365. word i;
  366. int cancel_rc;
  367. #ifdef USE_EXTENDED_DEBUGS
  368. {
  369. DBG_TRC(("<A%d Id=0x%x Rc=0x%x", ((ISDN_ADAPTER *)a->io)->ANum, Id, Rc))
  370. }
  371. #else
  372. dbug(dprintf("isdn_rc(Rc=%x,Id=%x,Ch=%x)", Rc, Id, Ch));
  373. #endif
  374. /* check for ready interrupt */
  375. if (Rc == READY_INT) {
  376. xdi_xlog_rc_event(XDI_A_NR(a), Id, Ch, Rc, 0, 0);
  377. if (a->ReadyInt) {
  378. a->ReadyInt--;
  379. return 0;
  380. }
  381. return 2;
  382. }
  383. /* if we know this Id ... */
  384. e_no = a->IdTable[Id];
  385. if (e_no) {
  386. this = entity_ptr(a, e_no);
  387. xdi_xlog_rc_event(XDI_A_NR(a), Id, Ch, Rc, 0, a->IdTypeTable[this->No]);
  388. this->RcCh = Ch;
  389. /* if it is a return code to a REMOVE request, remove the */
  390. /* Id from our table */
  391. if ((a->misc_flags_table[e_no] & DIVA_MISC_FLAGS_REMOVE_PENDING) &&
  392. (Rc == OK)) {
  393. if (a->IdTypeTable[e_no] == NL_ID) {
  394. if (a->RcExtensionSupported &&
  395. (extended_info_type != DIVA_RC_TYPE_REMOVE_COMPLETE)) {
  396. dtrc(dprintf("XDI: N-REMOVE, A(%02x) Id:%02x, ignore RC=OK",
  397. XDI_A_NR(a), Id));
  398. return (0);
  399. }
  400. if (extended_info_type == DIVA_RC_TYPE_REMOVE_COMPLETE)
  401. a->RcExtensionSupported = true;
  402. }
  403. a->misc_flags_table[e_no] &= ~DIVA_MISC_FLAGS_REMOVE_PENDING;
  404. a->misc_flags_table[e_no] &= ~DIVA_MISC_FLAGS_NO_RC_CANCELLING;
  405. free_entity(a, e_no);
  406. for (i = 0; i < 256; i++)
  407. {
  408. if (a->FlowControlIdTable[i] == Id)
  409. a->FlowControlIdTable[i] = 0;
  410. }
  411. a->IdTable[Id] = 0;
  412. this->Id = 0;
  413. /* ---------------------------------------------------------------
  414. If we send N_DISC or N_DISK_ACK after we have received OK_FC
  415. then the card will respond with OK_FC and later with RC==OK.
  416. If we send N_REMOVE in this state we will receive only RC==OK
  417. This will create the state in that the XDI is waiting for the
  418. additional RC and does not delivery the RC to the client. This
  419. code corrects the counter of outstanding RC's in this case.
  420. --------------------------------------------------------------- */
  421. if ((this->More & XMOREC) > 1) {
  422. this->More &= ~XMOREC;
  423. this->More |= 1;
  424. dtrc(dprintf("XDI: correct MORE on REMOVE A(%02x) Id:%02x",
  425. XDI_A_NR(a), Id));
  426. }
  427. }
  428. if (Rc == OK_FC) {
  429. a->FlowControlIdTable[Ch] = Id;
  430. a->FlowControlSkipTable[Ch] = false;
  431. this->Rc = Rc;
  432. this->More &= ~(XBUSY | XMOREC);
  433. this->complete = 0xff;
  434. xdi_xlog_rc_event(XDI_A_NR(a), Id, Ch, Rc, 1, a->IdTypeTable[this->No]);
  435. CALLBACK(a, this);
  436. return 0;
  437. }
  438. /*
  439. New protocol code sends return codes that comes from release
  440. of flow control condition marked with DIVA_RC_TYPE_OK_FC extended
  441. information element type.
  442. If like return code arrives then application is able to process
  443. all return codes self and XDI should not cances return codes.
  444. This return code does not decrement XMOREC partial return code
  445. counter due to fact that it was no request for this return code,
  446. also XMOREC was not incremented.
  447. */
  448. if (extended_info_type == DIVA_RC_TYPE_OK_FC) {
  449. a->misc_flags_table[e_no] |= DIVA_MISC_FLAGS_NO_RC_CANCELLING;
  450. this->Rc = Rc;
  451. this->complete = 0xff;
  452. xdi_xlog_rc_event(XDI_A_NR(a), Id, Ch, Rc, 1, a->IdTypeTable[this->No]);
  453. DBG_TRC(("XDI OK_FC A(%02x) Id:%02x Ch:%02x Rc:%02x",
  454. XDI_A_NR(a), Id, Ch, Rc))
  455. CALLBACK(a, this);
  456. return 0;
  457. }
  458. cancel_rc = !(a->misc_flags_table[e_no] & DIVA_MISC_FLAGS_NO_RC_CANCELLING);
  459. if (cancel_rc && (a->FlowControlIdTable[Ch] == Id))
  460. {
  461. a->FlowControlIdTable[Ch] = 0;
  462. if ((Rc != OK) || !a->FlowControlSkipTable[Ch])
  463. {
  464. this->Rc = Rc;
  465. if (Ch == this->ReqCh)
  466. {
  467. this->More &= ~(XBUSY | XMOREC);
  468. this->complete = 0xff;
  469. }
  470. xdi_xlog_rc_event(XDI_A_NR(a), Id, Ch, Rc, 1, a->IdTypeTable[this->No]);
  471. CALLBACK(a, this);
  472. }
  473. return 0;
  474. }
  475. if (this->More & XMOREC)
  476. this->More--;
  477. /* call the application callback function */
  478. if (((!cancel_rc) || (this->More & XMOREF)) && !(this->More & XMOREC)) {
  479. this->Rc = Rc;
  480. this->More &= ~XBUSY;
  481. this->complete = 0xff;
  482. xdi_xlog_rc_event(XDI_A_NR(a), Id, Ch, Rc, 1, a->IdTypeTable[this->No]);
  483. CALLBACK(a, this);
  484. }
  485. return 0;
  486. }
  487. /* if it's an ASSIGN return code check if it's a return */
  488. /* code to an ASSIGN request from us */
  489. if ((Rc & 0xf0) == ASSIGN_RC) {
  490. e_no = get_assign(a, Ref);
  491. if (e_no) {
  492. this = entity_ptr(a, e_no);
  493. this->Id = Id;
  494. xdi_xlog_rc_event(XDI_A_NR(a), Id, Ch, Rc, 2, a->IdTypeTable[this->No]);
  495. /* call the application callback function */
  496. this->Rc = Rc;
  497. this->More &= ~XBUSY;
  498. this->complete = 0xff;
  499. #if defined(DIVA_ISTREAM) /* { */
  500. if ((Rc == ASSIGN_OK) && a->ram_offset &&
  501. (a->IdTypeTable[this->No] == NL_ID) &&
  502. ((extended_info_type == DIVA_RC_TYPE_RX_DMA) ||
  503. (extended_info_type == DIVA_RC_TYPE_CMA_PTR)) &&
  504. extended_info) {
  505. dword offset = (*(a->ram_offset)) (a);
  506. dword tmp[2];
  507. extended_info -= offset;
  508. #ifdef PLATFORM_GT_32BIT
  509. a->ram_in_dw(a, (void *)ULongToPtr(extended_info), (dword *)&tmp[0], 2);
  510. #else
  511. a->ram_in_dw(a, (void *)extended_info, (dword *)&tmp[0], 2);
  512. #endif
  513. a->tx_stream[Id] = tmp[0];
  514. a->rx_stream[Id] = tmp[1];
  515. if (extended_info_type == DIVA_RC_TYPE_RX_DMA) {
  516. DBG_TRC(("Id=0x%x RxDMA=%08x:%08x",
  517. Id, a->tx_stream[Id], a->rx_stream[Id]))
  518. a->misc_flags_table[this->No] |= DIVA_MISC_FLAGS_RX_DMA;
  519. } else {
  520. DBG_TRC(("Id=0x%x CMA=%08x:%08x",
  521. Id, a->tx_stream[Id], a->rx_stream[Id]))
  522. a->misc_flags_table[this->No] &= ~DIVA_MISC_FLAGS_RX_DMA;
  523. a->rx_pos[Id] = 0;
  524. a->rx_stream[Id] -= offset;
  525. }
  526. a->tx_pos[Id] = 0;
  527. a->tx_stream[Id] -= offset;
  528. } else {
  529. a->tx_stream[Id] = 0;
  530. a->rx_stream[Id] = 0;
  531. a->misc_flags_table[this->No] &= ~DIVA_MISC_FLAGS_RX_DMA;
  532. }
  533. #endif /* } */
  534. CALLBACK(a, this);
  535. if (Rc == ASSIGN_OK) {
  536. a->IdTable[Id] = e_no;
  537. }
  538. else
  539. {
  540. free_entity(a, e_no);
  541. for (i = 0; i < 256; i++)
  542. {
  543. if (a->FlowControlIdTable[i] == Id)
  544. a->FlowControlIdTable[i] = 0;
  545. }
  546. a->IdTable[Id] = 0;
  547. this->Id = 0;
  548. }
  549. return 1;
  550. }
  551. }
  552. return 2;
  553. }
  554. /*------------------------------------------------------------------*/
  555. /* indication handler */
  556. /*------------------------------------------------------------------*/
  557. static byte isdn_ind(ADAPTER *a,
  558. byte Ind,
  559. byte Id,
  560. byte Ch,
  561. PBUFFER *RBuffer,
  562. byte MInd,
  563. word MLength)
  564. {
  565. ENTITY *this;
  566. word clength;
  567. word offset;
  568. BUFFERS *R;
  569. byte *cma = NULL;
  570. #ifdef USE_EXTENDED_DEBUGS
  571. {
  572. DBG_TRC(("<A%d Id=0x%x Ind=0x%x", ((ISDN_ADAPTER *)a->io)->ANum, Id, Ind))
  573. }
  574. #else
  575. dbug(dprintf("isdn_ind(Ind=%x,Id=%x,Ch=%x)", Ind, Id, Ch));
  576. #endif
  577. if (a->IdTable[Id]) {
  578. this = entity_ptr(a, a->IdTable[Id]);
  579. this->IndCh = Ch;
  580. xdi_xlog_ind(XDI_A_NR(a), Id, Ch, Ind,
  581. 0/* rnr_valid */, 0 /* rnr */, a->IdTypeTable[this->No]);
  582. /* if the Receive More flag is not yet set, this is the */
  583. /* first buffer of the packet */
  584. if (this->RCurrent == 0xff) {
  585. /* check for receive buffer chaining */
  586. if (Ind == this->MInd) {
  587. this->complete = 0;
  588. this->Ind = MInd;
  589. }
  590. else {
  591. this->complete = 1;
  592. this->Ind = Ind;
  593. }
  594. /* call the application callback function for the receive */
  595. /* look ahead */
  596. this->RLength = MLength;
  597. #if defined(DIVA_ISTREAM)
  598. if ((a->rx_stream[this->Id] ||
  599. (a->misc_flags_table[this->No] & DIVA_MISC_FLAGS_RX_DMA)) &&
  600. ((Ind == N_DATA) ||
  601. (a->protocol_capabilities & PROTCAP_CMA_ALLPR))) {
  602. PISDN_ADAPTER IoAdapter = (PISDN_ADAPTER)a->io;
  603. if (a->misc_flags_table[this->No] & DIVA_MISC_FLAGS_RX_DMA) {
  604. #if defined(DIVA_IDI_RX_DMA)
  605. dword d;
  606. diva_get_dma_map_entry(\
  607. (struct _diva_dma_map_entry *)IoAdapter->dma_map,
  608. (int)a->rx_stream[this->Id], (void **)&cma, &d);
  609. #else
  610. cma = &a->stream_buffer[0];
  611. cma[0] = cma[1] = cma[2] = cma[3] = 0;
  612. #endif
  613. this->RLength = MLength = (word)*(dword *)cma;
  614. cma += 4;
  615. } else {
  616. int final = 0;
  617. cma = &a->stream_buffer[0];
  618. this->RLength = MLength = (word)diva_istream_read(a,
  619. Id,
  620. cma,
  621. sizeof(a->stream_buffer),
  622. &final, NULL, NULL);
  623. }
  624. IoAdapter->RBuffer.length = min(MLength, (word)270);
  625. if (IoAdapter->RBuffer.length != MLength) {
  626. this->complete = 0;
  627. } else {
  628. this->complete = 1;
  629. }
  630. memcpy(IoAdapter->RBuffer.P, cma, IoAdapter->RBuffer.length);
  631. this->RBuffer = (DBUFFER *)&IoAdapter->RBuffer;
  632. }
  633. #endif
  634. if (!cma) {
  635. a->ram_look_ahead(a, RBuffer, this);
  636. }
  637. this->RNum = 0;
  638. CALLBACK(a, this);
  639. /* map entity ptr, selector could be re-mapped by call to */
  640. /* IDI from within callback */
  641. this = entity_ptr(a, a->IdTable[Id]);
  642. xdi_xlog_ind(XDI_A_NR(a), Id, Ch, Ind,
  643. 1/* rnr_valid */, this->RNR/* rnr */, a->IdTypeTable[this->No]);
  644. /* check for RNR */
  645. if (this->RNR == 1) {
  646. this->RNR = 0;
  647. return 1;
  648. }
  649. /* if no buffers are provided by the application, the */
  650. /* application want to copy the data itself including */
  651. /* N_MDATA/LL_MDATA chaining */
  652. if (!this->RNR && !this->RNum) {
  653. xdi_xlog_ind(XDI_A_NR(a), Id, Ch, Ind,
  654. 2/* rnr_valid */, 0/* rnr */, a->IdTypeTable[this->No]);
  655. return 0;
  656. }
  657. /* if there is no RNR, set the More flag */
  658. this->RCurrent = 0;
  659. this->ROffset = 0;
  660. }
  661. if (this->RNR == 2) {
  662. if (Ind != this->MInd) {
  663. this->RCurrent = 0xff;
  664. this->RNR = 0;
  665. }
  666. return 0;
  667. }
  668. /* if we have received buffers from the application, copy */
  669. /* the data into these buffers */
  670. offset = 0;
  671. R = PTR_R(a, this);
  672. do {
  673. if (this->ROffset == R[this->RCurrent].PLength) {
  674. this->ROffset = 0;
  675. this->RCurrent++;
  676. }
  677. if (cma) {
  678. clength = min(MLength, (word)(R[this->RCurrent].PLength-this->ROffset));
  679. } else {
  680. clength = min(a->ram_inw(a, &RBuffer->length)-offset,
  681. R[this->RCurrent].PLength-this->ROffset);
  682. }
  683. if (R[this->RCurrent].P) {
  684. if (cma) {
  685. memcpy(PTR_P(a, this, &R[this->RCurrent].P[this->ROffset]),
  686. &cma[offset],
  687. clength);
  688. } else {
  689. a->ram_in_buffer(a,
  690. &RBuffer->P[offset],
  691. PTR_P(a, this, &R[this->RCurrent].P[this->ROffset]),
  692. clength);
  693. }
  694. }
  695. offset += clength;
  696. this->ROffset += clength;
  697. if (cma) {
  698. if (offset >= MLength) {
  699. break;
  700. }
  701. continue;
  702. }
  703. } while (offset < (a->ram_inw(a, &RBuffer->length)));
  704. /* if it's the last buffer of the packet, call the */
  705. /* application callback function for the receive complete */
  706. /* call */
  707. if (Ind != this->MInd) {
  708. R[this->RCurrent].PLength = this->ROffset;
  709. if (this->ROffset) this->RCurrent++;
  710. this->RNum = this->RCurrent;
  711. this->RCurrent = 0xff;
  712. this->Ind = Ind;
  713. this->complete = 2;
  714. xdi_xlog_ind(XDI_A_NR(a), Id, Ch, Ind,
  715. 3/* rnr_valid */, 0/* rnr */, a->IdTypeTable[this->No]);
  716. CALLBACK(a, this);
  717. }
  718. return 0;
  719. }
  720. return 2;
  721. }
  722. #if defined(XDI_USE_XLOG)
  723. /* -----------------------------------------------------------
  724. This function works in the same way as xlog on the
  725. active board
  726. ----------------------------------------------------------- */
  727. static void xdi_xlog(byte *msg, word code, int length) {
  728. xdi_dbg_xlog("\x00\x02", msg, code, length);
  729. }
  730. #endif
  731. /* -----------------------------------------------------------
  732. This function writes the information about the Return Code
  733. processing in the trace buffer. Trace ID is 221.
  734. INPUT:
  735. Adapter - system unicue adapter number (0 ... 255)
  736. Id - Id of the entity that had sent this return code
  737. Ch - Channel of the entity that had sent this return code
  738. Rc - return code value
  739. cb: (0...2)
  740. switch (cb) {
  741. case 0: printf ("DELIVERY"); break;
  742. case 1: printf ("CALLBACK"); break;
  743. case 2: printf ("ASSIGN"); break;
  744. }
  745. DELIVERY - have entered isdn_rc with this RC
  746. CALLBACK - about to make callback to the application
  747. for this RC
  748. ASSIGN - about to make callback for RC that is result
  749. of ASSIGN request. It is no DELIVERY message
  750. before of this message
  751. type - the Id that was sent by the ASSIGN of this entity.
  752. This should be global Id like NL_ID, DSIG_ID, MAN_ID.
  753. An unknown Id will cause "?-" in the front of the request.
  754. In this case the log.c is to be extended.
  755. ----------------------------------------------------------- */
  756. static void xdi_xlog_rc_event(byte Adapter,
  757. byte Id, byte Ch, byte Rc, byte cb, byte type) {
  758. #if defined(XDI_USE_XLOG)
  759. word LogInfo[4];
  760. PUT_WORD(&LogInfo[0], ((word)Adapter | (word)(xdi_xlog_sec++ << 8)));
  761. PUT_WORD(&LogInfo[1], ((word)Id | (word)(Ch << 8)));
  762. PUT_WORD(&LogInfo[2], ((word)Rc | (word)(type << 8)));
  763. PUT_WORD(&LogInfo[3], cb);
  764. xdi_xlog((byte *)&LogInfo[0], 221, sizeof(LogInfo));
  765. #endif
  766. }
  767. /* ------------------------------------------------------------------------
  768. This function writes the information about the request processing
  769. in the trace buffer. Trace ID is 220.
  770. INPUT:
  771. Adapter - system unicue adapter number (0 ... 255)
  772. Id - Id of the entity that had sent this request
  773. Ch - Channel of the entity that had sent this request
  774. Req - Code of the request
  775. type - the Id that was sent by the ASSIGN of this entity.
  776. This should be global Id like NL_ID, DSIG_ID, MAN_ID.
  777. An unknown Id will cause "?-" in the front of the request.
  778. In this case the log.c is to be extended.
  779. ------------------------------------------------------------------------ */
  780. static void xdi_xlog_request(byte Adapter, byte Id,
  781. byte Ch, byte Req, byte type) {
  782. #if defined(XDI_USE_XLOG)
  783. word LogInfo[3];
  784. PUT_WORD(&LogInfo[0], ((word)Adapter | (word)(xdi_xlog_sec++ << 8)));
  785. PUT_WORD(&LogInfo[1], ((word)Id | (word)(Ch << 8)));
  786. PUT_WORD(&LogInfo[2], ((word)Req | (word)(type << 8)));
  787. xdi_xlog((byte *)&LogInfo[0], 220, sizeof(LogInfo));
  788. #endif
  789. }
  790. /* ------------------------------------------------------------------------
  791. This function writes the information about the indication processing
  792. in the trace buffer. Trace ID is 222.
  793. INPUT:
  794. Adapter - system unicue adapter number (0 ... 255)
  795. Id - Id of the entity that had sent this indication
  796. Ch - Channel of the entity that had sent this indication
  797. Ind - Code of the indication
  798. rnr_valid: (0 .. 3) supported
  799. switch (rnr_valid) {
  800. case 0: printf ("DELIVERY"); break;
  801. case 1: printf ("RNR=%d", rnr);
  802. case 2: printf ("RNum=0");
  803. case 3: printf ("COMPLETE");
  804. }
  805. DELIVERY - indication entered isdn_rc function
  806. RNR=... - application had returned RNR=... after the
  807. look ahead callback
  808. RNum=0 - application had not returned any buffer to copy
  809. this indication and will copy it self
  810. COMPLETE - XDI had copied the data to the buffers provided
  811. bu the application and is about to issue the
  812. final callback
  813. rnr: Look case 1 of the rnr_valid
  814. type: the Id that was sent by the ASSIGN of this entity. This should
  815. be global Id like NL_ID, DSIG_ID, MAN_ID. An unknown Id will
  816. cause "?-" in the front of the request. In this case the
  817. log.c is to be extended.
  818. ------------------------------------------------------------------------ */
  819. static void xdi_xlog_ind(byte Adapter,
  820. byte Id,
  821. byte Ch,
  822. byte Ind,
  823. byte rnr_valid,
  824. byte rnr,
  825. byte type) {
  826. #if defined(XDI_USE_XLOG)
  827. word LogInfo[4];
  828. PUT_WORD(&LogInfo[0], ((word)Adapter | (word)(xdi_xlog_sec++ << 8)));
  829. PUT_WORD(&LogInfo[1], ((word)Id | (word)(Ch << 8)));
  830. PUT_WORD(&LogInfo[2], ((word)Ind | (word)(type << 8)));
  831. PUT_WORD(&LogInfo[3], ((word)rnr | (word)(rnr_valid << 8)));
  832. xdi_xlog((byte *)&LogInfo[0], 222, sizeof(LogInfo));
  833. #endif
  834. }