11da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds
21da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds/*
31da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds *
4475be4d85a274d0961593db41cf85689db1d583cJoe Perches Copyright (c) Eicon Networks, 2002.
51da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds *
6475be4d85a274d0961593db41cf85689db1d583cJoe Perches This source file is supplied for the use with
7475be4d85a274d0961593db41cf85689db1d583cJoe Perches Eicon Networks range of DIVA Server Adapters.
81da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds *
9475be4d85a274d0961593db41cf85689db1d583cJoe Perches Eicon File Revision :    2.1
101da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds *
11475be4d85a274d0961593db41cf85689db1d583cJoe Perches This program is free software; you can redistribute it and/or modify
12475be4d85a274d0961593db41cf85689db1d583cJoe Perches it under the terms of the GNU General Public License as published by
13475be4d85a274d0961593db41cf85689db1d583cJoe Perches the Free Software Foundation; either version 2, or (at your option)
14475be4d85a274d0961593db41cf85689db1d583cJoe Perches any later version.
151da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds *
16475be4d85a274d0961593db41cf85689db1d583cJoe Perches This program is distributed in the hope that it will be useful,
17475be4d85a274d0961593db41cf85689db1d583cJoe Perches but WITHOUT ANY WARRANTY OF ANY KIND WHATSOEVER INCLUDING ANY
18475be4d85a274d0961593db41cf85689db1d583cJoe Perches implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
19475be4d85a274d0961593db41cf85689db1d583cJoe Perches See the GNU General Public License for more details.
201da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds *
21475be4d85a274d0961593db41cf85689db1d583cJoe Perches You should have received a copy of the GNU General Public License
22475be4d85a274d0961593db41cf85689db1d583cJoe Perches along with this program; if not, write to the Free Software
23475be4d85a274d0961593db41cf85689db1d583cJoe Perches Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
241da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds *
251da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds */
261da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#include "platform.h"
271da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#include "pc.h"
281da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#include "pr_pc.h"
291da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#include "di_defs.h"
301da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#include "di.h"
311da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#if !defined USE_EXTENDED_DEBUGS
32475be4d85a274d0961593db41cf85689db1d583cJoe Perches#include "dimaint.h"
331da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#else
34475be4d85a274d0961593db41cf85689db1d583cJoe Perches#define dprintf
351da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#endif
361da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#include "io.h"
371da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#include "dfifo.h"
381da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define PR_RAM  ((struct pr_ram *)0)
391da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define RAM ((struct dual *)0)
401da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds/*------------------------------------------------------------------*/
411da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds/* local function prototypes                                        */
421da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds/*------------------------------------------------------------------*/
43475be4d85a274d0961593db41cf85689db1d583cJoe Perchesvoid pr_out(ADAPTER *a);
44475be4d85a274d0961593db41cf85689db1d583cJoe Perchesbyte pr_dpc(ADAPTER *a);
45475be4d85a274d0961593db41cf85689db1d583cJoe Perchesstatic byte pr_ready(ADAPTER *a);
461da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsstatic byte isdn_rc(ADAPTER *, byte, byte, byte, word, dword, dword);
471da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsstatic byte isdn_ind(ADAPTER *, byte, byte, byte, PBUFFER *, byte, word);
481da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds/* -----------------------------------------------------------------
49475be4d85a274d0961593db41cf85689db1d583cJoe Perches   Functions used for the extended XDI Debug
50475be4d85a274d0961593db41cf85689db1d583cJoe Perches   macros
51475be4d85a274d0961593db41cf85689db1d583cJoe Perches   global convergence counter (used by all adapters)
52475be4d85a274d0961593db41cf85689db1d583cJoe Perches   Look by the implementation part of the functions
53475be4d85a274d0961593db41cf85689db1d583cJoe Perches   about the parameters.
54475be4d85a274d0961593db41cf85689db1d583cJoe Perches   If you change the dubugging parameters, then you should update
55475be4d85a274d0961593db41cf85689db1d583cJoe Perches   the aididbg.doc in the IDI doc's.
561da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds   ----------------------------------------------------------------- */
571da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#if defined(XDI_USE_XLOG)
581da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define XDI_A_NR(_x_) ((byte)(((ISDN_ADAPTER *)(_x_->io))->ANum))
59475be4d85a274d0961593db41cf85689db1d583cJoe Perchesstatic void xdi_xlog(byte *msg, word code, int length);
601da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldsstatic byte xdi_xlog_sec = 0;
611da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#else
621da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define XDI_A_NR(_x_) ((byte)0)
631da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#endif
64475be4d85a274d0961593db41cf85689db1d583cJoe Perchesstatic void xdi_xlog_rc_event(byte Adapter,
65475be4d85a274d0961593db41cf85689db1d583cJoe Perches			      byte Id, byte Ch, byte Rc, byte cb, byte type);
66475be4d85a274d0961593db41cf85689db1d583cJoe Perchesstatic void xdi_xlog_request(byte Adapter, byte Id,
67475be4d85a274d0961593db41cf85689db1d583cJoe Perches			     byte Ch, byte Req, byte type);
68475be4d85a274d0961593db41cf85689db1d583cJoe Perchesstatic void xdi_xlog_ind(byte Adapter,
69475be4d85a274d0961593db41cf85689db1d583cJoe Perches			 byte Id,
70475be4d85a274d0961593db41cf85689db1d583cJoe Perches			 byte Ch,
71475be4d85a274d0961593db41cf85689db1d583cJoe Perches			 byte Ind,
72475be4d85a274d0961593db41cf85689db1d583cJoe Perches			 byte rnr_valid,
73475be4d85a274d0961593db41cf85689db1d583cJoe Perches			 byte rnr,
74475be4d85a274d0961593db41cf85689db1d583cJoe Perches			 byte type);
751da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds/*------------------------------------------------------------------*/
761da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds/* output function                                                  */
771da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds/*------------------------------------------------------------------*/
78475be4d85a274d0961593db41cf85689db1d583cJoe Perchesvoid pr_out(ADAPTER *a)
791da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds{
80475be4d85a274d0961593db41cf85689db1d583cJoe Perches	byte e_no;
81475be4d85a274d0961593db41cf85689db1d583cJoe Perches	ENTITY *this = NULL;
82475be4d85a274d0961593db41cf85689db1d583cJoe Perches	BUFFERS *X;
83475be4d85a274d0961593db41cf85689db1d583cJoe Perches	word length;
84475be4d85a274d0961593db41cf85689db1d583cJoe Perches	word i;
85475be4d85a274d0961593db41cf85689db1d583cJoe Perches	word clength;
86475be4d85a274d0961593db41cf85689db1d583cJoe Perches	REQ *ReqOut;
87475be4d85a274d0961593db41cf85689db1d583cJoe Perches	byte more;
88475be4d85a274d0961593db41cf85689db1d583cJoe Perches	byte ReadyCount;
89475be4d85a274d0961593db41cf85689db1d583cJoe Perches	byte ReqCount;
90475be4d85a274d0961593db41cf85689db1d583cJoe Perches	byte Id;
91475be4d85a274d0961593db41cf85689db1d583cJoe Perches	dtrc(dprintf("pr_out"));
92475be4d85a274d0961593db41cf85689db1d583cJoe Perches	/* while a request is pending ...                           */
93475be4d85a274d0961593db41cf85689db1d583cJoe Perches	e_no = look_req(a);
94475be4d85a274d0961593db41cf85689db1d583cJoe Perches	if (!e_no)
95475be4d85a274d0961593db41cf85689db1d583cJoe Perches	{
96475be4d85a274d0961593db41cf85689db1d583cJoe Perches		dtrc(dprintf("no_req"));
97475be4d85a274d0961593db41cf85689db1d583cJoe Perches		return;
98475be4d85a274d0961593db41cf85689db1d583cJoe Perches	}
99475be4d85a274d0961593db41cf85689db1d583cJoe Perches	ReadyCount = pr_ready(a);
100475be4d85a274d0961593db41cf85689db1d583cJoe Perches	if (!ReadyCount)
101475be4d85a274d0961593db41cf85689db1d583cJoe Perches	{
102475be4d85a274d0961593db41cf85689db1d583cJoe Perches		dtrc(dprintf("not_ready"));
103475be4d85a274d0961593db41cf85689db1d583cJoe Perches		return;
104475be4d85a274d0961593db41cf85689db1d583cJoe Perches	}
105475be4d85a274d0961593db41cf85689db1d583cJoe Perches	ReqCount = 0;
106475be4d85a274d0961593db41cf85689db1d583cJoe Perches	while (e_no && ReadyCount) {
107475be4d85a274d0961593db41cf85689db1d583cJoe Perches		next_req(a);
108475be4d85a274d0961593db41cf85689db1d583cJoe Perches		this = entity_ptr(a, e_no);
1091da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#ifdef USE_EXTENDED_DEBUGS
110475be4d85a274d0961593db41cf85689db1d583cJoe Perches		if (!this)
111475be4d85a274d0961593db41cf85689db1d583cJoe Perches		{
112475be4d85a274d0961593db41cf85689db1d583cJoe Perches			DBG_FTL(("XDI: [%02x] !A%d ==> NULL entity ptr - try to ignore",
113475be4d85a274d0961593db41cf85689db1d583cJoe Perches				 xdi_xlog_sec++, (int)((ISDN_ADAPTER *)a->io)->ANum))
114475be4d85a274d0961593db41cf85689db1d583cJoe Perches				e_no = look_req(a);
115475be4d85a274d0961593db41cf85689db1d583cJoe Perches			ReadyCount--;
116475be4d85a274d0961593db41cf85689db1d583cJoe Perches			continue;
117475be4d85a274d0961593db41cf85689db1d583cJoe Perches		}
118475be4d85a274d0961593db41cf85689db1d583cJoe Perches		{
119475be4d85a274d0961593db41cf85689db1d583cJoe Perches			DBG_TRC((">A%d Id=0x%x Req=0x%x", ((ISDN_ADAPTER *)a->io)->ANum, this->Id, this->Req))
120475be4d85a274d0961593db41cf85689db1d583cJoe Perches				}
1211da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#else
122475be4d85a274d0961593db41cf85689db1d583cJoe Perches		dbug(dprintf("out:Req=%x,Id=%x,Ch=%x", this->Req, this->Id, this->ReqCh));
1231da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#endif
124475be4d85a274d0961593db41cf85689db1d583cJoe Perches		/* get address of next available request buffer             */
125475be4d85a274d0961593db41cf85689db1d583cJoe Perches		ReqOut = (REQ *)&PR_RAM->B[a->ram_inw(a, &PR_RAM->NextReq)];
1261da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#if defined(DIVA_ISTREAM)
127475be4d85a274d0961593db41cf85689db1d583cJoe Perches		if (!(a->tx_stream[this->Id]   &&
128475be4d85a274d0961593db41cf85689db1d583cJoe Perches		      this->Req == N_DATA)) {
1291da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#endif
130475be4d85a274d0961593db41cf85689db1d583cJoe Perches			/* now copy the data from the current data buffer into the  */
131475be4d85a274d0961593db41cf85689db1d583cJoe Perches			/* adapters request buffer                                  */
132475be4d85a274d0961593db41cf85689db1d583cJoe Perches			length = 0;
133475be4d85a274d0961593db41cf85689db1d583cJoe Perches			i = this->XCurrent;
134475be4d85a274d0961593db41cf85689db1d583cJoe Perches			X = PTR_X(a, this);
135475be4d85a274d0961593db41cf85689db1d583cJoe Perches			while (i < this->XNum && length < 270) {
136475be4d85a274d0961593db41cf85689db1d583cJoe Perches				clength = min((word)(270 - length), (word)(X[i].PLength-this->XOffset));
137475be4d85a274d0961593db41cf85689db1d583cJoe Perches				a->ram_out_buffer(a,
138475be4d85a274d0961593db41cf85689db1d583cJoe Perches						  &ReqOut->XBuffer.P[length],
139475be4d85a274d0961593db41cf85689db1d583cJoe Perches						  PTR_P(a, this, &X[i].P[this->XOffset]),
140475be4d85a274d0961593db41cf85689db1d583cJoe Perches						  clength);
141475be4d85a274d0961593db41cf85689db1d583cJoe Perches				length += clength;
142475be4d85a274d0961593db41cf85689db1d583cJoe Perches				this->XOffset += clength;
143475be4d85a274d0961593db41cf85689db1d583cJoe Perches				if (this->XOffset == X[i].PLength) {
144475be4d85a274d0961593db41cf85689db1d583cJoe Perches					this->XCurrent = (byte)++i;
145475be4d85a274d0961593db41cf85689db1d583cJoe Perches					this->XOffset = 0;
146475be4d85a274d0961593db41cf85689db1d583cJoe Perches				}
147475be4d85a274d0961593db41cf85689db1d583cJoe Perches			}
1481da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#if defined(DIVA_ISTREAM)
149475be4d85a274d0961593db41cf85689db1d583cJoe Perches		} else { /* Use CMA extension in order to transfer data to the card */
150475be4d85a274d0961593db41cf85689db1d583cJoe Perches			i = this->XCurrent;
151475be4d85a274d0961593db41cf85689db1d583cJoe Perches			X = PTR_X(a, this);
152475be4d85a274d0961593db41cf85689db1d583cJoe Perches			while (i < this->XNum) {
153475be4d85a274d0961593db41cf85689db1d583cJoe Perches				diva_istream_write(a,
154475be4d85a274d0961593db41cf85689db1d583cJoe Perches						   this->Id,
155475be4d85a274d0961593db41cf85689db1d583cJoe Perches						   PTR_P(a, this, &X[i].P[0]),
156475be4d85a274d0961593db41cf85689db1d583cJoe Perches						   X[i].PLength,
157475be4d85a274d0961593db41cf85689db1d583cJoe Perches						   ((i + 1) == this->XNum),
158475be4d85a274d0961593db41cf85689db1d583cJoe Perches						   0, 0);
159475be4d85a274d0961593db41cf85689db1d583cJoe Perches				this->XCurrent = (byte)++i;
160475be4d85a274d0961593db41cf85689db1d583cJoe Perches			}
161475be4d85a274d0961593db41cf85689db1d583cJoe Perches			length = 0;
162475be4d85a274d0961593db41cf85689db1d583cJoe Perches		}
1631da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#endif
164475be4d85a274d0961593db41cf85689db1d583cJoe Perches		a->ram_outw(a, &ReqOut->XBuffer.length, length);
165475be4d85a274d0961593db41cf85689db1d583cJoe Perches		a->ram_out(a, &ReqOut->ReqId, this->Id);
166475be4d85a274d0961593db41cf85689db1d583cJoe Perches		a->ram_out(a, &ReqOut->ReqCh, this->ReqCh);
167475be4d85a274d0961593db41cf85689db1d583cJoe Perches		/* if it's a specific request (no ASSIGN) ...                */
168475be4d85a274d0961593db41cf85689db1d583cJoe Perches		if (this->Id & 0x1f) {
169475be4d85a274d0961593db41cf85689db1d583cJoe Perches			/* if buffers are left in the list of data buffers do       */
170475be4d85a274d0961593db41cf85689db1d583cJoe Perches			/* do chaining (LL_MDATA, N_MDATA)                          */
171475be4d85a274d0961593db41cf85689db1d583cJoe Perches			this->More++;
172475be4d85a274d0961593db41cf85689db1d583cJoe Perches			if (i < this->XNum && this->MInd) {
173475be4d85a274d0961593db41cf85689db1d583cJoe Perches				xdi_xlog_request(XDI_A_NR(a), this->Id, this->ReqCh, this->MInd,
174475be4d85a274d0961593db41cf85689db1d583cJoe Perches						 a->IdTypeTable[this->No]);
175475be4d85a274d0961593db41cf85689db1d583cJoe Perches				a->ram_out(a, &ReqOut->Req, this->MInd);
176475be4d85a274d0961593db41cf85689db1d583cJoe Perches				more = true;
177475be4d85a274d0961593db41cf85689db1d583cJoe Perches			}
178475be4d85a274d0961593db41cf85689db1d583cJoe Perches			else {
179475be4d85a274d0961593db41cf85689db1d583cJoe Perches				xdi_xlog_request(XDI_A_NR(a), this->Id, this->ReqCh, this->Req,
180475be4d85a274d0961593db41cf85689db1d583cJoe Perches						 a->IdTypeTable[this->No]);
181475be4d85a274d0961593db41cf85689db1d583cJoe Perches				this->More |= XMOREF;
182475be4d85a274d0961593db41cf85689db1d583cJoe Perches				a->ram_out(a, &ReqOut->Req, this->Req);
183475be4d85a274d0961593db41cf85689db1d583cJoe Perches				more = false;
184475be4d85a274d0961593db41cf85689db1d583cJoe Perches				if (a->FlowControlIdTable[this->ReqCh] == this->Id)
185475be4d85a274d0961593db41cf85689db1d583cJoe Perches					a->FlowControlSkipTable[this->ReqCh] = true;
186475be4d85a274d0961593db41cf85689db1d583cJoe Perches				/*
187475be4d85a274d0961593db41cf85689db1d583cJoe Perches				  Note that remove request was sent to the card
188475be4d85a274d0961593db41cf85689db1d583cJoe Perches				*/
189475be4d85a274d0961593db41cf85689db1d583cJoe Perches				if (this->Req == REMOVE) {
190475be4d85a274d0961593db41cf85689db1d583cJoe Perches					a->misc_flags_table[e_no] |= DIVA_MISC_FLAGS_REMOVE_PENDING;
191475be4d85a274d0961593db41cf85689db1d583cJoe Perches				}
192475be4d85a274d0961593db41cf85689db1d583cJoe Perches			}
193475be4d85a274d0961593db41cf85689db1d583cJoe Perches			/* if we did chaining, this entity is put back into the     */
194475be4d85a274d0961593db41cf85689db1d583cJoe Perches			/* request queue                                            */
195475be4d85a274d0961593db41cf85689db1d583cJoe Perches			if (more) {
196475be4d85a274d0961593db41cf85689db1d583cJoe Perches				req_queue(a, this->No);
197475be4d85a274d0961593db41cf85689db1d583cJoe Perches			}
198475be4d85a274d0961593db41cf85689db1d583cJoe Perches		}
199475be4d85a274d0961593db41cf85689db1d583cJoe Perches		/* else it's a ASSIGN                                       */
200475be4d85a274d0961593db41cf85689db1d583cJoe Perches		else {
201475be4d85a274d0961593db41cf85689db1d583cJoe Perches			/* save the request code used for buffer chaining           */
202475be4d85a274d0961593db41cf85689db1d583cJoe Perches			this->MInd = 0;
203475be4d85a274d0961593db41cf85689db1d583cJoe Perches			if (this->Id == BLLC_ID) this->MInd = LL_MDATA;
204475be4d85a274d0961593db41cf85689db1d583cJoe Perches			if (this->Id == NL_ID ||
205475be4d85a274d0961593db41cf85689db1d583cJoe Perches			    this->Id == TASK_ID ||
206475be4d85a274d0961593db41cf85689db1d583cJoe Perches			    this->Id == MAN_ID
207475be4d85a274d0961593db41cf85689db1d583cJoe Perches				) this->MInd = N_MDATA;
208475be4d85a274d0961593db41cf85689db1d583cJoe Perches			/* send the ASSIGN                                          */
209475be4d85a274d0961593db41cf85689db1d583cJoe Perches			a->IdTypeTable[this->No] = this->Id;
210475be4d85a274d0961593db41cf85689db1d583cJoe Perches			xdi_xlog_request(XDI_A_NR(a), this->Id, this->ReqCh, this->Req, this->Id);
211475be4d85a274d0961593db41cf85689db1d583cJoe Perches			this->More |= XMOREF;
212475be4d85a274d0961593db41cf85689db1d583cJoe Perches			a->ram_out(a, &ReqOut->Req, this->Req);
213475be4d85a274d0961593db41cf85689db1d583cJoe Perches			/* save the reference of the ASSIGN                         */
214475be4d85a274d0961593db41cf85689db1d583cJoe Perches			assign_queue(a, this->No, a->ram_inw(a, &ReqOut->Reference));
215475be4d85a274d0961593db41cf85689db1d583cJoe Perches		}
216475be4d85a274d0961593db41cf85689db1d583cJoe Perches		a->ram_outw(a, &PR_RAM->NextReq, a->ram_inw(a, &ReqOut->next));
217475be4d85a274d0961593db41cf85689db1d583cJoe Perches		ReadyCount--;
218475be4d85a274d0961593db41cf85689db1d583cJoe Perches		ReqCount++;
219475be4d85a274d0961593db41cf85689db1d583cJoe Perches		e_no = look_req(a);
220475be4d85a274d0961593db41cf85689db1d583cJoe Perches	}
221475be4d85a274d0961593db41cf85689db1d583cJoe Perches	/* send the filled request buffers to the ISDN adapter      */
222475be4d85a274d0961593db41cf85689db1d583cJoe Perches	a->ram_out(a, &PR_RAM->ReqInput,
223475be4d85a274d0961593db41cf85689db1d583cJoe Perches		   (byte)(a->ram_in(a, &PR_RAM->ReqInput) + ReqCount));
224475be4d85a274d0961593db41cf85689db1d583cJoe Perches	/* if it is a 'unreturncoded' UREMOVE request, remove the  */
225475be4d85a274d0961593db41cf85689db1d583cJoe Perches	/* Id from our table after sending the request             */
226475be4d85a274d0961593db41cf85689db1d583cJoe Perches	if (this && (this->Req == UREMOVE) && this->Id) {
227475be4d85a274d0961593db41cf85689db1d583cJoe Perches		Id = this->Id;
228475be4d85a274d0961593db41cf85689db1d583cJoe Perches		e_no = a->IdTable[Id];
229475be4d85a274d0961593db41cf85689db1d583cJoe Perches		free_entity(a, e_no);
230475be4d85a274d0961593db41cf85689db1d583cJoe Perches		for (i = 0; i < 256; i++)
231475be4d85a274d0961593db41cf85689db1d583cJoe Perches		{
232475be4d85a274d0961593db41cf85689db1d583cJoe Perches			if (a->FlowControlIdTable[i] == Id)
233475be4d85a274d0961593db41cf85689db1d583cJoe Perches				a->FlowControlIdTable[i] = 0;
234475be4d85a274d0961593db41cf85689db1d583cJoe Perches		}
235475be4d85a274d0961593db41cf85689db1d583cJoe Perches		a->IdTable[Id] = 0;
236475be4d85a274d0961593db41cf85689db1d583cJoe Perches		this->Id = 0;
237475be4d85a274d0961593db41cf85689db1d583cJoe Perches	}
2381da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds}
239475be4d85a274d0961593db41cf85689db1d583cJoe Perchesstatic byte pr_ready(ADAPTER *a)
2401da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds{
241475be4d85a274d0961593db41cf85689db1d583cJoe Perches	byte ReadyCount;
242475be4d85a274d0961593db41cf85689db1d583cJoe Perches	ReadyCount = (byte)(a->ram_in(a, &PR_RAM->ReqOutput) -
243475be4d85a274d0961593db41cf85689db1d583cJoe Perches			    a->ram_in(a, &PR_RAM->ReqInput));
244475be4d85a274d0961593db41cf85689db1d583cJoe Perches	if (!ReadyCount) {
245475be4d85a274d0961593db41cf85689db1d583cJoe Perches		if (!a->ReadyInt) {
246475be4d85a274d0961593db41cf85689db1d583cJoe Perches			a->ram_inc(a, &PR_RAM->ReadyInt);
247475be4d85a274d0961593db41cf85689db1d583cJoe Perches			a->ReadyInt++;
248475be4d85a274d0961593db41cf85689db1d583cJoe Perches		}
249475be4d85a274d0961593db41cf85689db1d583cJoe Perches	}
250475be4d85a274d0961593db41cf85689db1d583cJoe Perches	return ReadyCount;
2511da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds}
2521da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds/*------------------------------------------------------------------*/
2531da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds/* isdn interrupt handler                                           */
2541da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds/*------------------------------------------------------------------*/
255475be4d85a274d0961593db41cf85689db1d583cJoe Perchesbyte pr_dpc(ADAPTER *a)
2561da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds{
257475be4d85a274d0961593db41cf85689db1d583cJoe Perches	byte Count;
258475be4d85a274d0961593db41cf85689db1d583cJoe Perches	RC *RcIn;
259475be4d85a274d0961593db41cf85689db1d583cJoe Perches	IND *IndIn;
260475be4d85a274d0961593db41cf85689db1d583cJoe Perches	byte c;
261475be4d85a274d0961593db41cf85689db1d583cJoe Perches	byte RNRId;
262475be4d85a274d0961593db41cf85689db1d583cJoe Perches	byte Rc;
263475be4d85a274d0961593db41cf85689db1d583cJoe Perches	byte Ind;
264475be4d85a274d0961593db41cf85689db1d583cJoe Perches	/* if return codes are available ...                        */
265475be4d85a274d0961593db41cf85689db1d583cJoe Perches	if ((Count = a->ram_in(a, &PR_RAM->RcOutput)) != 0) {
266475be4d85a274d0961593db41cf85689db1d583cJoe Perches		dtrc(dprintf("#Rc=%x", Count));
267475be4d85a274d0961593db41cf85689db1d583cJoe Perches		/* get the buffer address of the first return code          */
268475be4d85a274d0961593db41cf85689db1d583cJoe Perches		RcIn = (RC *)&PR_RAM->B[a->ram_inw(a, &PR_RAM->NextRc)];
269475be4d85a274d0961593db41cf85689db1d583cJoe Perches		/* for all return codes do ...                              */
270475be4d85a274d0961593db41cf85689db1d583cJoe Perches		while (Count--) {
271475be4d85a274d0961593db41cf85689db1d583cJoe Perches			if ((Rc = a->ram_in(a, &RcIn->Rc)) != 0) {
272475be4d85a274d0961593db41cf85689db1d583cJoe Perches				dword tmp[2];
273475be4d85a274d0961593db41cf85689db1d583cJoe Perches				/*
274475be4d85a274d0961593db41cf85689db1d583cJoe Perches				  Get extended information, associated with return code
275475be4d85a274d0961593db41cf85689db1d583cJoe Perches				*/
276475be4d85a274d0961593db41cf85689db1d583cJoe Perches				a->ram_in_buffer(a,
277475be4d85a274d0961593db41cf85689db1d583cJoe Perches						 &RcIn->Reserved2[0],
278475be4d85a274d0961593db41cf85689db1d583cJoe Perches						 (byte *)&tmp[0],
279475be4d85a274d0961593db41cf85689db1d583cJoe Perches						 8);
280475be4d85a274d0961593db41cf85689db1d583cJoe Perches				/* call return code handler, if it is not our return code   */
281475be4d85a274d0961593db41cf85689db1d583cJoe Perches				/* the handler returns 2                                    */
282475be4d85a274d0961593db41cf85689db1d583cJoe Perches				/* for all return codes we process, we clear the Rc field   */
283475be4d85a274d0961593db41cf85689db1d583cJoe Perches				isdn_rc(a,
284475be4d85a274d0961593db41cf85689db1d583cJoe Perches					Rc,
285475be4d85a274d0961593db41cf85689db1d583cJoe Perches					a->ram_in(a, &RcIn->RcId),
286475be4d85a274d0961593db41cf85689db1d583cJoe Perches					a->ram_in(a, &RcIn->RcCh),
287475be4d85a274d0961593db41cf85689db1d583cJoe Perches					a->ram_inw(a, &RcIn->Reference),
288475be4d85a274d0961593db41cf85689db1d583cJoe Perches					tmp[0],  /* type of extended information */
289475be4d85a274d0961593db41cf85689db1d583cJoe Perches					tmp[1]); /* extended information        */
290475be4d85a274d0961593db41cf85689db1d583cJoe Perches				a->ram_out(a, &RcIn->Rc, 0);
291475be4d85a274d0961593db41cf85689db1d583cJoe Perches			}
292475be4d85a274d0961593db41cf85689db1d583cJoe Perches			/* get buffer address of next return code                   */
293475be4d85a274d0961593db41cf85689db1d583cJoe Perches			RcIn = (RC *)&PR_RAM->B[a->ram_inw(a, &RcIn->next)];
294475be4d85a274d0961593db41cf85689db1d583cJoe Perches		}
295475be4d85a274d0961593db41cf85689db1d583cJoe Perches		/* clear all return codes (no chaining!)                    */
296475be4d85a274d0961593db41cf85689db1d583cJoe Perches		a->ram_out(a, &PR_RAM->RcOutput, 0);
297475be4d85a274d0961593db41cf85689db1d583cJoe Perches		/* call output function                                     */
298475be4d85a274d0961593db41cf85689db1d583cJoe Perches		pr_out(a);
299475be4d85a274d0961593db41cf85689db1d583cJoe Perches	}
300475be4d85a274d0961593db41cf85689db1d583cJoe Perches	/* clear RNR flag                                           */
301475be4d85a274d0961593db41cf85689db1d583cJoe Perches	RNRId = 0;
302475be4d85a274d0961593db41cf85689db1d583cJoe Perches	/* if indications are available ...                         */
303475be4d85a274d0961593db41cf85689db1d583cJoe Perches	if ((Count = a->ram_in(a, &PR_RAM->IndOutput)) != 0) {
304475be4d85a274d0961593db41cf85689db1d583cJoe Perches		dtrc(dprintf("#Ind=%x", Count));
305475be4d85a274d0961593db41cf85689db1d583cJoe Perches		/* get the buffer address of the first indication           */
306475be4d85a274d0961593db41cf85689db1d583cJoe Perches		IndIn = (IND *)&PR_RAM->B[a->ram_inw(a, &PR_RAM->NextInd)];
307475be4d85a274d0961593db41cf85689db1d583cJoe Perches		/* for all indications do ...                               */
308475be4d85a274d0961593db41cf85689db1d583cJoe Perches		while (Count--) {
309475be4d85a274d0961593db41cf85689db1d583cJoe Perches			/* if the application marks an indication as RNR, all       */
310475be4d85a274d0961593db41cf85689db1d583cJoe Perches			/* indications from the same Id delivered in this interrupt */
311475be4d85a274d0961593db41cf85689db1d583cJoe Perches			/* are marked RNR                                           */
312475be4d85a274d0961593db41cf85689db1d583cJoe Perches			if (RNRId && RNRId == a->ram_in(a, &IndIn->IndId)) {
313475be4d85a274d0961593db41cf85689db1d583cJoe Perches				a->ram_out(a, &IndIn->Ind, 0);
314475be4d85a274d0961593db41cf85689db1d583cJoe Perches				a->ram_out(a, &IndIn->RNR, true);
315475be4d85a274d0961593db41cf85689db1d583cJoe Perches			}
316475be4d85a274d0961593db41cf85689db1d583cJoe Perches			else {
317475be4d85a274d0961593db41cf85689db1d583cJoe Perches				Ind = a->ram_in(a, &IndIn->Ind);
318475be4d85a274d0961593db41cf85689db1d583cJoe Perches				if (Ind) {
319475be4d85a274d0961593db41cf85689db1d583cJoe Perches					RNRId = 0;
320475be4d85a274d0961593db41cf85689db1d583cJoe Perches					/* call indication handler, a return value of 2 means chain */
321475be4d85a274d0961593db41cf85689db1d583cJoe Perches					/* a return value of 1 means RNR                            */
322475be4d85a274d0961593db41cf85689db1d583cJoe Perches					/* for all indications we process, we clear the Ind field   */
323475be4d85a274d0961593db41cf85689db1d583cJoe Perches					c = isdn_ind(a,
324475be4d85a274d0961593db41cf85689db1d583cJoe Perches						     Ind,
325475be4d85a274d0961593db41cf85689db1d583cJoe Perches						     a->ram_in(a, &IndIn->IndId),
326475be4d85a274d0961593db41cf85689db1d583cJoe Perches						     a->ram_in(a, &IndIn->IndCh),
327475be4d85a274d0961593db41cf85689db1d583cJoe Perches						     &IndIn->RBuffer,
328475be4d85a274d0961593db41cf85689db1d583cJoe Perches						     a->ram_in(a, &IndIn->MInd),
329475be4d85a274d0961593db41cf85689db1d583cJoe Perches						     a->ram_inw(a, &IndIn->MLength));
330475be4d85a274d0961593db41cf85689db1d583cJoe Perches					if (c == 1) {
331475be4d85a274d0961593db41cf85689db1d583cJoe Perches						dtrc(dprintf("RNR"));
332475be4d85a274d0961593db41cf85689db1d583cJoe Perches						a->ram_out(a, &IndIn->Ind, 0);
333475be4d85a274d0961593db41cf85689db1d583cJoe Perches						RNRId = a->ram_in(a, &IndIn->IndId);
334475be4d85a274d0961593db41cf85689db1d583cJoe Perches						a->ram_out(a, &IndIn->RNR, true);
335475be4d85a274d0961593db41cf85689db1d583cJoe Perches					}
336475be4d85a274d0961593db41cf85689db1d583cJoe Perches				}
337475be4d85a274d0961593db41cf85689db1d583cJoe Perches			}
338475be4d85a274d0961593db41cf85689db1d583cJoe Perches			/* get buffer address of next indication                    */
339475be4d85a274d0961593db41cf85689db1d583cJoe Perches			IndIn = (IND *)&PR_RAM->B[a->ram_inw(a, &IndIn->next)];
340475be4d85a274d0961593db41cf85689db1d583cJoe Perches		}
341475be4d85a274d0961593db41cf85689db1d583cJoe Perches		a->ram_out(a, &PR_RAM->IndOutput, 0);
342475be4d85a274d0961593db41cf85689db1d583cJoe Perches	}
343475be4d85a274d0961593db41cf85689db1d583cJoe Perches	return false;
3441da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds}
345475be4d85a274d0961593db41cf85689db1d583cJoe Perchesbyte scom_test_int(ADAPTER *a)
3461da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds{
347475be4d85a274d0961593db41cf85689db1d583cJoe Perches	return a->ram_in(a, (void *)0x3fe);
3481da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds}
349475be4d85a274d0961593db41cf85689db1d583cJoe Perchesvoid scom_clear_int(ADAPTER *a)
3501da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds{
351475be4d85a274d0961593db41cf85689db1d583cJoe Perches	a->ram_out(a, (void *)0x3fe, 0);
3521da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds}
3531da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds/*------------------------------------------------------------------*/
3541da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds/* return code handler                                              */
3551da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds/*------------------------------------------------------------------*/
3564ee59d54c3f91f1f3ad7f2856b27981414430f9eHannes Ederstatic byte isdn_rc(ADAPTER *a,
3574ee59d54c3f91f1f3ad7f2856b27981414430f9eHannes Eder		    byte Rc,
3584ee59d54c3f91f1f3ad7f2856b27981414430f9eHannes Eder		    byte Id,
3594ee59d54c3f91f1f3ad7f2856b27981414430f9eHannes Eder		    byte Ch,
3604ee59d54c3f91f1f3ad7f2856b27981414430f9eHannes Eder		    word Ref,
3614ee59d54c3f91f1f3ad7f2856b27981414430f9eHannes Eder		    dword extended_info_type,
3624ee59d54c3f91f1f3ad7f2856b27981414430f9eHannes Eder		    dword extended_info)
3631da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds{
364475be4d85a274d0961593db41cf85689db1d583cJoe Perches	ENTITY *this;
365475be4d85a274d0961593db41cf85689db1d583cJoe Perches	byte e_no;
366475be4d85a274d0961593db41cf85689db1d583cJoe Perches	word i;
367475be4d85a274d0961593db41cf85689db1d583cJoe Perches	int cancel_rc;
3681da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#ifdef USE_EXTENDED_DEBUGS
369475be4d85a274d0961593db41cf85689db1d583cJoe Perches	{
370475be4d85a274d0961593db41cf85689db1d583cJoe Perches		DBG_TRC(("<A%d Id=0x%x Rc=0x%x", ((ISDN_ADAPTER *)a->io)->ANum, Id, Rc))
371475be4d85a274d0961593db41cf85689db1d583cJoe Perches			}
3721da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#else
373475be4d85a274d0961593db41cf85689db1d583cJoe Perches	dbug(dprintf("isdn_rc(Rc=%x,Id=%x,Ch=%x)", Rc, Id, Ch));
3741da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#endif
375475be4d85a274d0961593db41cf85689db1d583cJoe Perches	/* check for ready interrupt                                */
376475be4d85a274d0961593db41cf85689db1d583cJoe Perches	if (Rc == READY_INT) {
377475be4d85a274d0961593db41cf85689db1d583cJoe Perches		xdi_xlog_rc_event(XDI_A_NR(a), Id, Ch, Rc, 0, 0);
378475be4d85a274d0961593db41cf85689db1d583cJoe Perches		if (a->ReadyInt) {
379475be4d85a274d0961593db41cf85689db1d583cJoe Perches			a->ReadyInt--;
380475be4d85a274d0961593db41cf85689db1d583cJoe Perches			return 0;
381475be4d85a274d0961593db41cf85689db1d583cJoe Perches		}
382475be4d85a274d0961593db41cf85689db1d583cJoe Perches		return 2;
383475be4d85a274d0961593db41cf85689db1d583cJoe Perches	}
384475be4d85a274d0961593db41cf85689db1d583cJoe Perches	/* if we know this Id ...                                   */
385475be4d85a274d0961593db41cf85689db1d583cJoe Perches	e_no = a->IdTable[Id];
386475be4d85a274d0961593db41cf85689db1d583cJoe Perches	if (e_no) {
387475be4d85a274d0961593db41cf85689db1d583cJoe Perches		this = entity_ptr(a, e_no);
388475be4d85a274d0961593db41cf85689db1d583cJoe Perches		xdi_xlog_rc_event(XDI_A_NR(a), Id, Ch, Rc, 0, a->IdTypeTable[this->No]);
389475be4d85a274d0961593db41cf85689db1d583cJoe Perches		this->RcCh = Ch;
390475be4d85a274d0961593db41cf85689db1d583cJoe Perches		/* if it is a return code to a REMOVE request, remove the   */
391475be4d85a274d0961593db41cf85689db1d583cJoe Perches		/* Id from our table                                        */
392475be4d85a274d0961593db41cf85689db1d583cJoe Perches		if ((a->misc_flags_table[e_no] & DIVA_MISC_FLAGS_REMOVE_PENDING) &&
393475be4d85a274d0961593db41cf85689db1d583cJoe Perches		    (Rc == OK)) {
394475be4d85a274d0961593db41cf85689db1d583cJoe Perches			if (a->IdTypeTable[e_no] == NL_ID) {
395475be4d85a274d0961593db41cf85689db1d583cJoe Perches				if (a->RcExtensionSupported &&
396475be4d85a274d0961593db41cf85689db1d583cJoe Perches				    (extended_info_type != DIVA_RC_TYPE_REMOVE_COMPLETE)) {
397475be4d85a274d0961593db41cf85689db1d583cJoe Perches					dtrc(dprintf("XDI: N-REMOVE, A(%02x) Id:%02x, ignore RC=OK",
398475be4d85a274d0961593db41cf85689db1d583cJoe Perches						     XDI_A_NR(a), Id));
399475be4d85a274d0961593db41cf85689db1d583cJoe Perches					return (0);
400475be4d85a274d0961593db41cf85689db1d583cJoe Perches				}
401475be4d85a274d0961593db41cf85689db1d583cJoe Perches				if (extended_info_type == DIVA_RC_TYPE_REMOVE_COMPLETE)
402475be4d85a274d0961593db41cf85689db1d583cJoe Perches					a->RcExtensionSupported = true;
403475be4d85a274d0961593db41cf85689db1d583cJoe Perches			}
404475be4d85a274d0961593db41cf85689db1d583cJoe Perches			a->misc_flags_table[e_no] &= ~DIVA_MISC_FLAGS_REMOVE_PENDING;
405475be4d85a274d0961593db41cf85689db1d583cJoe Perches			a->misc_flags_table[e_no] &= ~DIVA_MISC_FLAGS_NO_RC_CANCELLING;
406475be4d85a274d0961593db41cf85689db1d583cJoe Perches			free_entity(a, e_no);
407475be4d85a274d0961593db41cf85689db1d583cJoe Perches			for (i = 0; i < 256; i++)
408475be4d85a274d0961593db41cf85689db1d583cJoe Perches			{
409475be4d85a274d0961593db41cf85689db1d583cJoe Perches				if (a->FlowControlIdTable[i] == Id)
410475be4d85a274d0961593db41cf85689db1d583cJoe Perches					a->FlowControlIdTable[i] = 0;
411475be4d85a274d0961593db41cf85689db1d583cJoe Perches			}
412475be4d85a274d0961593db41cf85689db1d583cJoe Perches			a->IdTable[Id] = 0;
413475be4d85a274d0961593db41cf85689db1d583cJoe Perches			this->Id = 0;
414475be4d85a274d0961593db41cf85689db1d583cJoe Perches			/* ---------------------------------------------------------------
415475be4d85a274d0961593db41cf85689db1d583cJoe Perches			   If we send N_DISC or N_DISK_ACK after we have received OK_FC
416475be4d85a274d0961593db41cf85689db1d583cJoe Perches			   then the card will respond with OK_FC and later with RC==OK.
417475be4d85a274d0961593db41cf85689db1d583cJoe Perches			   If we send N_REMOVE in this state we will receive only RC==OK
418475be4d85a274d0961593db41cf85689db1d583cJoe Perches			   This will create the state in that the XDI is waiting for the
419475be4d85a274d0961593db41cf85689db1d583cJoe Perches			   additional RC and does not delivery the RC to the client. This
420475be4d85a274d0961593db41cf85689db1d583cJoe Perches			   code corrects the counter of outstanding RC's in this case.
421475be4d85a274d0961593db41cf85689db1d583cJoe Perches			   --------------------------------------------------------------- */
422475be4d85a274d0961593db41cf85689db1d583cJoe Perches			if ((this->More & XMOREC) > 1) {
423475be4d85a274d0961593db41cf85689db1d583cJoe Perches				this->More &= ~XMOREC;
424475be4d85a274d0961593db41cf85689db1d583cJoe Perches				this->More |= 1;
425475be4d85a274d0961593db41cf85689db1d583cJoe Perches				dtrc(dprintf("XDI: correct MORE on REMOVE A(%02x) Id:%02x",
426475be4d85a274d0961593db41cf85689db1d583cJoe Perches					     XDI_A_NR(a), Id));
427475be4d85a274d0961593db41cf85689db1d583cJoe Perches			}
428475be4d85a274d0961593db41cf85689db1d583cJoe Perches		}
429475be4d85a274d0961593db41cf85689db1d583cJoe Perches		if (Rc == OK_FC) {
430475be4d85a274d0961593db41cf85689db1d583cJoe Perches			a->FlowControlIdTable[Ch] = Id;
431475be4d85a274d0961593db41cf85689db1d583cJoe Perches			a->FlowControlSkipTable[Ch] = false;
432475be4d85a274d0961593db41cf85689db1d583cJoe Perches			this->Rc = Rc;
433475be4d85a274d0961593db41cf85689db1d583cJoe Perches			this->More &= ~(XBUSY | XMOREC);
434475be4d85a274d0961593db41cf85689db1d583cJoe Perches			this->complete = 0xff;
435475be4d85a274d0961593db41cf85689db1d583cJoe Perches			xdi_xlog_rc_event(XDI_A_NR(a), Id, Ch, Rc, 1, a->IdTypeTable[this->No]);
436475be4d85a274d0961593db41cf85689db1d583cJoe Perches			CALLBACK(a, this);
437475be4d85a274d0961593db41cf85689db1d583cJoe Perches			return 0;
438475be4d85a274d0961593db41cf85689db1d583cJoe Perches		}
439475be4d85a274d0961593db41cf85689db1d583cJoe Perches		/*
440475be4d85a274d0961593db41cf85689db1d583cJoe Perches		  New protocol code sends return codes that comes from release
441475be4d85a274d0961593db41cf85689db1d583cJoe Perches		  of flow control condition marked with DIVA_RC_TYPE_OK_FC extended
442475be4d85a274d0961593db41cf85689db1d583cJoe Perches		  information element type.
443475be4d85a274d0961593db41cf85689db1d583cJoe Perches		  If like return code arrives then application is able to process
444475be4d85a274d0961593db41cf85689db1d583cJoe Perches		  all return codes self and XDI should not cances return codes.
445475be4d85a274d0961593db41cf85689db1d583cJoe Perches		  This return code does not decrement XMOREC partial return code
446475be4d85a274d0961593db41cf85689db1d583cJoe Perches		  counter due to fact that it was no request for this return code,
447475be4d85a274d0961593db41cf85689db1d583cJoe Perches		  also XMOREC was not incremented.
448475be4d85a274d0961593db41cf85689db1d583cJoe Perches		*/
449475be4d85a274d0961593db41cf85689db1d583cJoe Perches		if (extended_info_type == DIVA_RC_TYPE_OK_FC) {
450475be4d85a274d0961593db41cf85689db1d583cJoe Perches			a->misc_flags_table[e_no] |= DIVA_MISC_FLAGS_NO_RC_CANCELLING;
451475be4d85a274d0961593db41cf85689db1d583cJoe Perches			this->Rc = Rc;
452475be4d85a274d0961593db41cf85689db1d583cJoe Perches			this->complete = 0xff;
453475be4d85a274d0961593db41cf85689db1d583cJoe Perches			xdi_xlog_rc_event(XDI_A_NR(a), Id, Ch, Rc, 1, a->IdTypeTable[this->No]);
454475be4d85a274d0961593db41cf85689db1d583cJoe Perches			DBG_TRC(("XDI OK_FC A(%02x) Id:%02x Ch:%02x Rc:%02x",
455475be4d85a274d0961593db41cf85689db1d583cJoe Perches				 XDI_A_NR(a), Id, Ch, Rc))
456475be4d85a274d0961593db41cf85689db1d583cJoe Perches				CALLBACK(a, this);
457475be4d85a274d0961593db41cf85689db1d583cJoe Perches			return 0;
458475be4d85a274d0961593db41cf85689db1d583cJoe Perches		}
459475be4d85a274d0961593db41cf85689db1d583cJoe Perches		cancel_rc = !(a->misc_flags_table[e_no] & DIVA_MISC_FLAGS_NO_RC_CANCELLING);
460475be4d85a274d0961593db41cf85689db1d583cJoe Perches		if (cancel_rc && (a->FlowControlIdTable[Ch] == Id))
461475be4d85a274d0961593db41cf85689db1d583cJoe Perches		{
462475be4d85a274d0961593db41cf85689db1d583cJoe Perches			a->FlowControlIdTable[Ch] = 0;
463475be4d85a274d0961593db41cf85689db1d583cJoe Perches			if ((Rc != OK) || !a->FlowControlSkipTable[Ch])
464475be4d85a274d0961593db41cf85689db1d583cJoe Perches			{
465475be4d85a274d0961593db41cf85689db1d583cJoe Perches				this->Rc = Rc;
466475be4d85a274d0961593db41cf85689db1d583cJoe Perches				if (Ch == this->ReqCh)
467475be4d85a274d0961593db41cf85689db1d583cJoe Perches				{
468475be4d85a274d0961593db41cf85689db1d583cJoe Perches					this->More &= ~(XBUSY | XMOREC);
469475be4d85a274d0961593db41cf85689db1d583cJoe Perches					this->complete = 0xff;
470475be4d85a274d0961593db41cf85689db1d583cJoe Perches				}
471475be4d85a274d0961593db41cf85689db1d583cJoe Perches				xdi_xlog_rc_event(XDI_A_NR(a), Id, Ch, Rc, 1, a->IdTypeTable[this->No]);
472475be4d85a274d0961593db41cf85689db1d583cJoe Perches				CALLBACK(a, this);
473475be4d85a274d0961593db41cf85689db1d583cJoe Perches			}
474475be4d85a274d0961593db41cf85689db1d583cJoe Perches			return 0;
475475be4d85a274d0961593db41cf85689db1d583cJoe Perches		}
476475be4d85a274d0961593db41cf85689db1d583cJoe Perches		if (this->More & XMOREC)
477475be4d85a274d0961593db41cf85689db1d583cJoe Perches			this->More--;
478475be4d85a274d0961593db41cf85689db1d583cJoe Perches		/* call the application callback function                   */
479475be4d85a274d0961593db41cf85689db1d583cJoe Perches		if (((!cancel_rc) || (this->More & XMOREF)) && !(this->More & XMOREC)) {
480475be4d85a274d0961593db41cf85689db1d583cJoe Perches			this->Rc = Rc;
481475be4d85a274d0961593db41cf85689db1d583cJoe Perches			this->More &= ~XBUSY;
482475be4d85a274d0961593db41cf85689db1d583cJoe Perches			this->complete = 0xff;
483475be4d85a274d0961593db41cf85689db1d583cJoe Perches			xdi_xlog_rc_event(XDI_A_NR(a), Id, Ch, Rc, 1, a->IdTypeTable[this->No]);
484475be4d85a274d0961593db41cf85689db1d583cJoe Perches			CALLBACK(a, this);
485475be4d85a274d0961593db41cf85689db1d583cJoe Perches		}
486475be4d85a274d0961593db41cf85689db1d583cJoe Perches		return 0;
487475be4d85a274d0961593db41cf85689db1d583cJoe Perches	}
488475be4d85a274d0961593db41cf85689db1d583cJoe Perches	/* if it's an ASSIGN return code check if it's a return     */
489475be4d85a274d0961593db41cf85689db1d583cJoe Perches	/* code to an ASSIGN request from us                        */
490475be4d85a274d0961593db41cf85689db1d583cJoe Perches	if ((Rc & 0xf0) == ASSIGN_RC) {
491475be4d85a274d0961593db41cf85689db1d583cJoe Perches		e_no = get_assign(a, Ref);
492475be4d85a274d0961593db41cf85689db1d583cJoe Perches		if (e_no) {
493475be4d85a274d0961593db41cf85689db1d583cJoe Perches			this = entity_ptr(a, e_no);
494475be4d85a274d0961593db41cf85689db1d583cJoe Perches			this->Id = Id;
495475be4d85a274d0961593db41cf85689db1d583cJoe Perches			xdi_xlog_rc_event(XDI_A_NR(a), Id, Ch, Rc, 2, a->IdTypeTable[this->No]);
496475be4d85a274d0961593db41cf85689db1d583cJoe Perches			/* call the application callback function                   */
497475be4d85a274d0961593db41cf85689db1d583cJoe Perches			this->Rc = Rc;
498475be4d85a274d0961593db41cf85689db1d583cJoe Perches			this->More &= ~XBUSY;
499475be4d85a274d0961593db41cf85689db1d583cJoe Perches			this->complete = 0xff;
5001da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#if defined(DIVA_ISTREAM) /* { */
501475be4d85a274d0961593db41cf85689db1d583cJoe Perches			if ((Rc == ASSIGN_OK) && a->ram_offset &&
502475be4d85a274d0961593db41cf85689db1d583cJoe Perches			    (a->IdTypeTable[this->No] == NL_ID) &&
503475be4d85a274d0961593db41cf85689db1d583cJoe Perches			    ((extended_info_type == DIVA_RC_TYPE_RX_DMA) ||
504475be4d85a274d0961593db41cf85689db1d583cJoe Perches			     (extended_info_type == DIVA_RC_TYPE_CMA_PTR)) &&
505475be4d85a274d0961593db41cf85689db1d583cJoe Perches			    extended_info) {
506475be4d85a274d0961593db41cf85689db1d583cJoe Perches				dword offset = (*(a->ram_offset)) (a);
507475be4d85a274d0961593db41cf85689db1d583cJoe Perches				dword tmp[2];
508475be4d85a274d0961593db41cf85689db1d583cJoe Perches				extended_info -= offset;
5091da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#ifdef PLATFORM_GT_32BIT
510475be4d85a274d0961593db41cf85689db1d583cJoe Perches				a->ram_in_dw(a, (void *)ULongToPtr(extended_info), (dword *)&tmp[0], 2);
5111da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#else
512475be4d85a274d0961593db41cf85689db1d583cJoe Perches				a->ram_in_dw(a, (void *)extended_info, (dword *)&tmp[0], 2);
5131da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#endif
514475be4d85a274d0961593db41cf85689db1d583cJoe Perches				a->tx_stream[Id]  = tmp[0];
515475be4d85a274d0961593db41cf85689db1d583cJoe Perches				a->rx_stream[Id]  = tmp[1];
516475be4d85a274d0961593db41cf85689db1d583cJoe Perches				if (extended_info_type == DIVA_RC_TYPE_RX_DMA) {
517475be4d85a274d0961593db41cf85689db1d583cJoe Perches					DBG_TRC(("Id=0x%x RxDMA=%08x:%08x",
518475be4d85a274d0961593db41cf85689db1d583cJoe Perches						 Id, a->tx_stream[Id], a->rx_stream[Id]))
519475be4d85a274d0961593db41cf85689db1d583cJoe Perches						a->misc_flags_table[this->No] |= DIVA_MISC_FLAGS_RX_DMA;
520475be4d85a274d0961593db41cf85689db1d583cJoe Perches				} else {
521475be4d85a274d0961593db41cf85689db1d583cJoe Perches					DBG_TRC(("Id=0x%x CMA=%08x:%08x",
522475be4d85a274d0961593db41cf85689db1d583cJoe Perches						 Id, a->tx_stream[Id], a->rx_stream[Id]))
523475be4d85a274d0961593db41cf85689db1d583cJoe Perches						a->misc_flags_table[this->No] &= ~DIVA_MISC_FLAGS_RX_DMA;
524475be4d85a274d0961593db41cf85689db1d583cJoe Perches					a->rx_pos[Id]     = 0;
525475be4d85a274d0961593db41cf85689db1d583cJoe Perches					a->rx_stream[Id] -= offset;
526475be4d85a274d0961593db41cf85689db1d583cJoe Perches				}
527475be4d85a274d0961593db41cf85689db1d583cJoe Perches				a->tx_pos[Id]     = 0;
528475be4d85a274d0961593db41cf85689db1d583cJoe Perches				a->tx_stream[Id] -= offset;
529475be4d85a274d0961593db41cf85689db1d583cJoe Perches			} else {
530475be4d85a274d0961593db41cf85689db1d583cJoe Perches				a->tx_stream[Id] = 0;
531475be4d85a274d0961593db41cf85689db1d583cJoe Perches				a->rx_stream[Id] = 0;
532475be4d85a274d0961593db41cf85689db1d583cJoe Perches				a->misc_flags_table[this->No] &= ~DIVA_MISC_FLAGS_RX_DMA;
533475be4d85a274d0961593db41cf85689db1d583cJoe Perches			}
5341da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#endif /* } */
535475be4d85a274d0961593db41cf85689db1d583cJoe Perches			CALLBACK(a, this);
536475be4d85a274d0961593db41cf85689db1d583cJoe Perches			if (Rc == ASSIGN_OK) {
537475be4d85a274d0961593db41cf85689db1d583cJoe Perches				a->IdTable[Id] = e_no;
538475be4d85a274d0961593db41cf85689db1d583cJoe Perches			}
539475be4d85a274d0961593db41cf85689db1d583cJoe Perches			else
540475be4d85a274d0961593db41cf85689db1d583cJoe Perches			{
541475be4d85a274d0961593db41cf85689db1d583cJoe Perches				free_entity(a, e_no);
542475be4d85a274d0961593db41cf85689db1d583cJoe Perches				for (i = 0; i < 256; i++)
543475be4d85a274d0961593db41cf85689db1d583cJoe Perches				{
544475be4d85a274d0961593db41cf85689db1d583cJoe Perches					if (a->FlowControlIdTable[i] == Id)
545475be4d85a274d0961593db41cf85689db1d583cJoe Perches						a->FlowControlIdTable[i] = 0;
546475be4d85a274d0961593db41cf85689db1d583cJoe Perches				}
547475be4d85a274d0961593db41cf85689db1d583cJoe Perches				a->IdTable[Id] = 0;
548475be4d85a274d0961593db41cf85689db1d583cJoe Perches				this->Id = 0;
549475be4d85a274d0961593db41cf85689db1d583cJoe Perches			}
550475be4d85a274d0961593db41cf85689db1d583cJoe Perches			return 1;
551475be4d85a274d0961593db41cf85689db1d583cJoe Perches		}
552475be4d85a274d0961593db41cf85689db1d583cJoe Perches	}
553475be4d85a274d0961593db41cf85689db1d583cJoe Perches	return 2;
5541da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds}
5551da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds/*------------------------------------------------------------------*/
5561da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds/* indication handler                                               */
5571da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds/*------------------------------------------------------------------*/
5584ee59d54c3f91f1f3ad7f2856b27981414430f9eHannes Ederstatic byte isdn_ind(ADAPTER *a,
5594ee59d54c3f91f1f3ad7f2856b27981414430f9eHannes Eder		     byte Ind,
5604ee59d54c3f91f1f3ad7f2856b27981414430f9eHannes Eder		     byte Id,
5614ee59d54c3f91f1f3ad7f2856b27981414430f9eHannes Eder		     byte Ch,
5624ee59d54c3f91f1f3ad7f2856b27981414430f9eHannes Eder		     PBUFFER *RBuffer,
5634ee59d54c3f91f1f3ad7f2856b27981414430f9eHannes Eder		     byte MInd,
5644ee59d54c3f91f1f3ad7f2856b27981414430f9eHannes Eder		     word MLength)
5651da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds{
566475be4d85a274d0961593db41cf85689db1d583cJoe Perches	ENTITY *this;
567475be4d85a274d0961593db41cf85689db1d583cJoe Perches	word clength;
568475be4d85a274d0961593db41cf85689db1d583cJoe Perches	word offset;
569475be4d85a274d0961593db41cf85689db1d583cJoe Perches	BUFFERS *R;
570475be4d85a274d0961593db41cf85689db1d583cJoe Perches	byte *cma = NULL;
5711da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#ifdef USE_EXTENDED_DEBUGS
572475be4d85a274d0961593db41cf85689db1d583cJoe Perches	{
573475be4d85a274d0961593db41cf85689db1d583cJoe Perches		DBG_TRC(("<A%d Id=0x%x Ind=0x%x", ((ISDN_ADAPTER *)a->io)->ANum, Id, Ind))
574475be4d85a274d0961593db41cf85689db1d583cJoe Perches			}
5751da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#else
576475be4d85a274d0961593db41cf85689db1d583cJoe Perches	dbug(dprintf("isdn_ind(Ind=%x,Id=%x,Ch=%x)", Ind, Id, Ch));
5771da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#endif
578475be4d85a274d0961593db41cf85689db1d583cJoe Perches	if (a->IdTable[Id]) {
579475be4d85a274d0961593db41cf85689db1d583cJoe Perches		this = entity_ptr(a, a->IdTable[Id]);
580475be4d85a274d0961593db41cf85689db1d583cJoe Perches		this->IndCh = Ch;
581475be4d85a274d0961593db41cf85689db1d583cJoe Perches		xdi_xlog_ind(XDI_A_NR(a), Id, Ch, Ind,
582475be4d85a274d0961593db41cf85689db1d583cJoe Perches			     0/* rnr_valid */, 0 /* rnr */, a->IdTypeTable[this->No]);
583475be4d85a274d0961593db41cf85689db1d583cJoe Perches		/* if the Receive More flag is not yet set, this is the     */
584475be4d85a274d0961593db41cf85689db1d583cJoe Perches		/* first buffer of the packet                               */
585475be4d85a274d0961593db41cf85689db1d583cJoe Perches		if (this->RCurrent == 0xff) {
586475be4d85a274d0961593db41cf85689db1d583cJoe Perches			/* check for receive buffer chaining                        */
587475be4d85a274d0961593db41cf85689db1d583cJoe Perches			if (Ind == this->MInd) {
588475be4d85a274d0961593db41cf85689db1d583cJoe Perches				this->complete = 0;
589475be4d85a274d0961593db41cf85689db1d583cJoe Perches				this->Ind = MInd;
590475be4d85a274d0961593db41cf85689db1d583cJoe Perches			}
591475be4d85a274d0961593db41cf85689db1d583cJoe Perches			else {
592475be4d85a274d0961593db41cf85689db1d583cJoe Perches				this->complete = 1;
593475be4d85a274d0961593db41cf85689db1d583cJoe Perches				this->Ind = Ind;
594475be4d85a274d0961593db41cf85689db1d583cJoe Perches			}
595475be4d85a274d0961593db41cf85689db1d583cJoe Perches			/* call the application callback function for the receive   */
596475be4d85a274d0961593db41cf85689db1d583cJoe Perches			/* look ahead                                               */
597475be4d85a274d0961593db41cf85689db1d583cJoe Perches			this->RLength = MLength;
5981da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#if defined(DIVA_ISTREAM)
599475be4d85a274d0961593db41cf85689db1d583cJoe Perches			if ((a->rx_stream[this->Id] ||
600475be4d85a274d0961593db41cf85689db1d583cJoe Perches			     (a->misc_flags_table[this->No] & DIVA_MISC_FLAGS_RX_DMA)) &&
601475be4d85a274d0961593db41cf85689db1d583cJoe Perches			    ((Ind == N_DATA) ||
602475be4d85a274d0961593db41cf85689db1d583cJoe Perches			     (a->protocol_capabilities & PROTCAP_CMA_ALLPR))) {
603475be4d85a274d0961593db41cf85689db1d583cJoe Perches				PISDN_ADAPTER IoAdapter = (PISDN_ADAPTER)a->io;
604475be4d85a274d0961593db41cf85689db1d583cJoe Perches				if (a->misc_flags_table[this->No] & DIVA_MISC_FLAGS_RX_DMA) {
6051da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#if defined(DIVA_IDI_RX_DMA)
606475be4d85a274d0961593db41cf85689db1d583cJoe Perches					dword d;
607475be4d85a274d0961593db41cf85689db1d583cJoe Perches					diva_get_dma_map_entry(\
608475be4d85a274d0961593db41cf85689db1d583cJoe Perches						(struct _diva_dma_map_entry *)IoAdapter->dma_map,
609475be4d85a274d0961593db41cf85689db1d583cJoe Perches						(int)a->rx_stream[this->Id], (void **)&cma, &d);
6101da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#else
611475be4d85a274d0961593db41cf85689db1d583cJoe Perches					cma = &a->stream_buffer[0];
612475be4d85a274d0961593db41cf85689db1d583cJoe Perches					cma[0] = cma[1] = cma[2] = cma[3] = 0;
6131da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#endif
614475be4d85a274d0961593db41cf85689db1d583cJoe Perches					this->RLength = MLength = (word)*(dword *)cma;
615475be4d85a274d0961593db41cf85689db1d583cJoe Perches					cma += 4;
616475be4d85a274d0961593db41cf85689db1d583cJoe Perches				} else {
617475be4d85a274d0961593db41cf85689db1d583cJoe Perches					int final = 0;
618475be4d85a274d0961593db41cf85689db1d583cJoe Perches					cma = &a->stream_buffer[0];
619475be4d85a274d0961593db41cf85689db1d583cJoe Perches					this->RLength = MLength = (word)diva_istream_read(a,
620475be4d85a274d0961593db41cf85689db1d583cJoe Perches											  Id,
621475be4d85a274d0961593db41cf85689db1d583cJoe Perches											  cma,
622475be4d85a274d0961593db41cf85689db1d583cJoe Perches											  sizeof(a->stream_buffer),
623475be4d85a274d0961593db41cf85689db1d583cJoe Perches											  &final, NULL, NULL);
624475be4d85a274d0961593db41cf85689db1d583cJoe Perches				}
625475be4d85a274d0961593db41cf85689db1d583cJoe Perches				IoAdapter->RBuffer.length = min(MLength, (word)270);
626475be4d85a274d0961593db41cf85689db1d583cJoe Perches				if (IoAdapter->RBuffer.length != MLength) {
627475be4d85a274d0961593db41cf85689db1d583cJoe Perches					this->complete = 0;
628475be4d85a274d0961593db41cf85689db1d583cJoe Perches				} else {
629475be4d85a274d0961593db41cf85689db1d583cJoe Perches					this->complete = 1;
630475be4d85a274d0961593db41cf85689db1d583cJoe Perches				}
631475be4d85a274d0961593db41cf85689db1d583cJoe Perches				memcpy(IoAdapter->RBuffer.P, cma, IoAdapter->RBuffer.length);
632475be4d85a274d0961593db41cf85689db1d583cJoe Perches				this->RBuffer = (DBUFFER *)&IoAdapter->RBuffer;
633475be4d85a274d0961593db41cf85689db1d583cJoe Perches			}
6341da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#endif
635475be4d85a274d0961593db41cf85689db1d583cJoe Perches			if (!cma) {
636475be4d85a274d0961593db41cf85689db1d583cJoe Perches				a->ram_look_ahead(a, RBuffer, this);
637475be4d85a274d0961593db41cf85689db1d583cJoe Perches			}
638475be4d85a274d0961593db41cf85689db1d583cJoe Perches			this->RNum = 0;
639475be4d85a274d0961593db41cf85689db1d583cJoe Perches			CALLBACK(a, this);
640475be4d85a274d0961593db41cf85689db1d583cJoe Perches			/* map entity ptr, selector could be re-mapped by call to   */
641475be4d85a274d0961593db41cf85689db1d583cJoe Perches			/* IDI from within callback                                 */
642475be4d85a274d0961593db41cf85689db1d583cJoe Perches			this = entity_ptr(a, a->IdTable[Id]);
643475be4d85a274d0961593db41cf85689db1d583cJoe Perches			xdi_xlog_ind(XDI_A_NR(a), Id, Ch, Ind,
644475be4d85a274d0961593db41cf85689db1d583cJoe Perches				     1/* rnr_valid */, this->RNR/* rnr */, a->IdTypeTable[this->No]);
645475be4d85a274d0961593db41cf85689db1d583cJoe Perches			/* check for RNR                                            */
646475be4d85a274d0961593db41cf85689db1d583cJoe Perches			if (this->RNR == 1) {
647475be4d85a274d0961593db41cf85689db1d583cJoe Perches				this->RNR = 0;
648475be4d85a274d0961593db41cf85689db1d583cJoe Perches				return 1;
649475be4d85a274d0961593db41cf85689db1d583cJoe Perches			}
650475be4d85a274d0961593db41cf85689db1d583cJoe Perches			/* if no buffers are provided by the application, the       */
651475be4d85a274d0961593db41cf85689db1d583cJoe Perches			/* application want to copy the data itself including       */
652475be4d85a274d0961593db41cf85689db1d583cJoe Perches			/* N_MDATA/LL_MDATA chaining                                */
653475be4d85a274d0961593db41cf85689db1d583cJoe Perches			if (!this->RNR && !this->RNum) {
654475be4d85a274d0961593db41cf85689db1d583cJoe Perches				xdi_xlog_ind(XDI_A_NR(a), Id, Ch, Ind,
655475be4d85a274d0961593db41cf85689db1d583cJoe Perches					     2/* rnr_valid */, 0/* rnr */, a->IdTypeTable[this->No]);
656475be4d85a274d0961593db41cf85689db1d583cJoe Perches				return 0;
657475be4d85a274d0961593db41cf85689db1d583cJoe Perches			}
658475be4d85a274d0961593db41cf85689db1d583cJoe Perches			/* if there is no RNR, set the More flag                    */
659475be4d85a274d0961593db41cf85689db1d583cJoe Perches			this->RCurrent = 0;
660475be4d85a274d0961593db41cf85689db1d583cJoe Perches			this->ROffset = 0;
661475be4d85a274d0961593db41cf85689db1d583cJoe Perches		}
662475be4d85a274d0961593db41cf85689db1d583cJoe Perches		if (this->RNR == 2) {
663475be4d85a274d0961593db41cf85689db1d583cJoe Perches			if (Ind != this->MInd) {
664475be4d85a274d0961593db41cf85689db1d583cJoe Perches				this->RCurrent = 0xff;
665475be4d85a274d0961593db41cf85689db1d583cJoe Perches				this->RNR = 0;
666475be4d85a274d0961593db41cf85689db1d583cJoe Perches			}
667475be4d85a274d0961593db41cf85689db1d583cJoe Perches			return 0;
668475be4d85a274d0961593db41cf85689db1d583cJoe Perches		}
669475be4d85a274d0961593db41cf85689db1d583cJoe Perches		/* if we have received buffers from the application, copy   */
670475be4d85a274d0961593db41cf85689db1d583cJoe Perches		/* the data into these buffers                              */
671475be4d85a274d0961593db41cf85689db1d583cJoe Perches		offset = 0;
672475be4d85a274d0961593db41cf85689db1d583cJoe Perches		R = PTR_R(a, this);
673475be4d85a274d0961593db41cf85689db1d583cJoe Perches		do {
674475be4d85a274d0961593db41cf85689db1d583cJoe Perches			if (this->ROffset == R[this->RCurrent].PLength) {
675475be4d85a274d0961593db41cf85689db1d583cJoe Perches				this->ROffset = 0;
676475be4d85a274d0961593db41cf85689db1d583cJoe Perches				this->RCurrent++;
677475be4d85a274d0961593db41cf85689db1d583cJoe Perches			}
678475be4d85a274d0961593db41cf85689db1d583cJoe Perches			if (cma) {
679475be4d85a274d0961593db41cf85689db1d583cJoe Perches				clength = min(MLength, (word)(R[this->RCurrent].PLength-this->ROffset));
680475be4d85a274d0961593db41cf85689db1d583cJoe Perches			} else {
681475be4d85a274d0961593db41cf85689db1d583cJoe Perches				clength = min(a->ram_inw(a, &RBuffer->length)-offset,
682475be4d85a274d0961593db41cf85689db1d583cJoe Perches					      R[this->RCurrent].PLength-this->ROffset);
683475be4d85a274d0961593db41cf85689db1d583cJoe Perches			}
684475be4d85a274d0961593db41cf85689db1d583cJoe Perches			if (R[this->RCurrent].P) {
685475be4d85a274d0961593db41cf85689db1d583cJoe Perches				if (cma) {
686475be4d85a274d0961593db41cf85689db1d583cJoe Perches					memcpy(PTR_P(a, this, &R[this->RCurrent].P[this->ROffset]),
687475be4d85a274d0961593db41cf85689db1d583cJoe Perches					       &cma[offset],
688475be4d85a274d0961593db41cf85689db1d583cJoe Perches					       clength);
689475be4d85a274d0961593db41cf85689db1d583cJoe Perches				} else {
690475be4d85a274d0961593db41cf85689db1d583cJoe Perches					a->ram_in_buffer(a,
691475be4d85a274d0961593db41cf85689db1d583cJoe Perches							 &RBuffer->P[offset],
692475be4d85a274d0961593db41cf85689db1d583cJoe Perches							 PTR_P(a, this, &R[this->RCurrent].P[this->ROffset]),
693475be4d85a274d0961593db41cf85689db1d583cJoe Perches							 clength);
694475be4d85a274d0961593db41cf85689db1d583cJoe Perches				}
695475be4d85a274d0961593db41cf85689db1d583cJoe Perches			}
696475be4d85a274d0961593db41cf85689db1d583cJoe Perches			offset += clength;
697475be4d85a274d0961593db41cf85689db1d583cJoe Perches			this->ROffset += clength;
698475be4d85a274d0961593db41cf85689db1d583cJoe Perches			if (cma) {
699475be4d85a274d0961593db41cf85689db1d583cJoe Perches				if (offset >= MLength) {
700475be4d85a274d0961593db41cf85689db1d583cJoe Perches					break;
701475be4d85a274d0961593db41cf85689db1d583cJoe Perches				}
702475be4d85a274d0961593db41cf85689db1d583cJoe Perches				continue;
703475be4d85a274d0961593db41cf85689db1d583cJoe Perches			}
704475be4d85a274d0961593db41cf85689db1d583cJoe Perches		} while (offset < (a->ram_inw(a, &RBuffer->length)));
705475be4d85a274d0961593db41cf85689db1d583cJoe Perches		/* if it's the last buffer of the packet, call the          */
706475be4d85a274d0961593db41cf85689db1d583cJoe Perches		/* application callback function for the receive complete   */
707475be4d85a274d0961593db41cf85689db1d583cJoe Perches		/* call                                                     */
708475be4d85a274d0961593db41cf85689db1d583cJoe Perches		if (Ind != this->MInd) {
709475be4d85a274d0961593db41cf85689db1d583cJoe Perches			R[this->RCurrent].PLength = this->ROffset;
710475be4d85a274d0961593db41cf85689db1d583cJoe Perches			if (this->ROffset) this->RCurrent++;
711475be4d85a274d0961593db41cf85689db1d583cJoe Perches			this->RNum = this->RCurrent;
712475be4d85a274d0961593db41cf85689db1d583cJoe Perches			this->RCurrent = 0xff;
713475be4d85a274d0961593db41cf85689db1d583cJoe Perches			this->Ind = Ind;
714475be4d85a274d0961593db41cf85689db1d583cJoe Perches			this->complete = 2;
715475be4d85a274d0961593db41cf85689db1d583cJoe Perches			xdi_xlog_ind(XDI_A_NR(a), Id, Ch, Ind,
716475be4d85a274d0961593db41cf85689db1d583cJoe Perches				     3/* rnr_valid */, 0/* rnr */, a->IdTypeTable[this->No]);
717475be4d85a274d0961593db41cf85689db1d583cJoe Perches			CALLBACK(a, this);
718475be4d85a274d0961593db41cf85689db1d583cJoe Perches		}
719475be4d85a274d0961593db41cf85689db1d583cJoe Perches		return 0;
720475be4d85a274d0961593db41cf85689db1d583cJoe Perches	}
721475be4d85a274d0961593db41cf85689db1d583cJoe Perches	return 2;
7221da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds}
7231da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#if defined(XDI_USE_XLOG)
7241da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds/* -----------------------------------------------------------
7251da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds   This function works in the same way as xlog on the
7261da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds   active board
7271da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds   ----------------------------------------------------------- */
728475be4d85a274d0961593db41cf85689db1d583cJoe Perchesstatic void xdi_xlog(byte *msg, word code, int length) {
729475be4d85a274d0961593db41cf85689db1d583cJoe Perches	xdi_dbg_xlog("\x00\x02", msg, code, length);
7301da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds}
7311da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#endif
7321da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds/* -----------------------------------------------------------
733475be4d85a274d0961593db41cf85689db1d583cJoe Perches   This function writes the information about the Return Code
734475be4d85a274d0961593db41cf85689db1d583cJoe Perches   processing in the trace buffer. Trace ID is 221.
735475be4d85a274d0961593db41cf85689db1d583cJoe Perches   INPUT:
736475be4d85a274d0961593db41cf85689db1d583cJoe Perches   Adapter - system unicue adapter number (0 ... 255)
737475be4d85a274d0961593db41cf85689db1d583cJoe Perches   Id      - Id of the entity that had sent this return code
738475be4d85a274d0961593db41cf85689db1d583cJoe Perches   Ch      - Channel of the entity that had sent this return code
739475be4d85a274d0961593db41cf85689db1d583cJoe Perches   Rc      - return code value
740475be4d85a274d0961593db41cf85689db1d583cJoe Perches   cb:       (0...2)
741475be4d85a274d0961593db41cf85689db1d583cJoe Perches   switch (cb) {
742475be4d85a274d0961593db41cf85689db1d583cJoe Perches   case 0: printf ("DELIVERY"); break;
743475be4d85a274d0961593db41cf85689db1d583cJoe Perches   case 1: printf ("CALLBACK"); break;
744475be4d85a274d0961593db41cf85689db1d583cJoe Perches   case 2: printf ("ASSIGN"); break;
745475be4d85a274d0961593db41cf85689db1d583cJoe Perches   }
746475be4d85a274d0961593db41cf85689db1d583cJoe Perches   DELIVERY - have entered isdn_rc with this RC
747475be4d85a274d0961593db41cf85689db1d583cJoe Perches   CALLBACK - about to make callback to the application
748475be4d85a274d0961593db41cf85689db1d583cJoe Perches   for this RC
749475be4d85a274d0961593db41cf85689db1d583cJoe Perches   ASSIGN   - about to make callback for RC that is result
750475be4d85a274d0961593db41cf85689db1d583cJoe Perches   of ASSIGN request. It is no DELIVERY message
751475be4d85a274d0961593db41cf85689db1d583cJoe Perches   before of this message
752475be4d85a274d0961593db41cf85689db1d583cJoe Perches   type   - the Id that was sent by the ASSIGN of this entity.
753475be4d85a274d0961593db41cf85689db1d583cJoe Perches   This should be global Id like NL_ID, DSIG_ID, MAN_ID.
754475be4d85a274d0961593db41cf85689db1d583cJoe Perches   An unknown Id will cause "?-" in the front of the request.
755475be4d85a274d0961593db41cf85689db1d583cJoe Perches   In this case the log.c is to be extended.
7561da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds   ----------------------------------------------------------- */
757475be4d85a274d0961593db41cf85689db1d583cJoe Perchesstatic void xdi_xlog_rc_event(byte Adapter,
758475be4d85a274d0961593db41cf85689db1d583cJoe Perches			      byte Id, byte Ch, byte Rc, byte cb, byte type) {
7591da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#if defined(XDI_USE_XLOG)
760475be4d85a274d0961593db41cf85689db1d583cJoe Perches	word LogInfo[4];
761475be4d85a274d0961593db41cf85689db1d583cJoe Perches	PUT_WORD(&LogInfo[0], ((word)Adapter | (word)(xdi_xlog_sec++ << 8)));
762475be4d85a274d0961593db41cf85689db1d583cJoe Perches	PUT_WORD(&LogInfo[1], ((word)Id | (word)(Ch << 8)));
763475be4d85a274d0961593db41cf85689db1d583cJoe Perches	PUT_WORD(&LogInfo[2], ((word)Rc | (word)(type << 8)));
764475be4d85a274d0961593db41cf85689db1d583cJoe Perches	PUT_WORD(&LogInfo[3], cb);
765475be4d85a274d0961593db41cf85689db1d583cJoe Perches	xdi_xlog((byte *)&LogInfo[0], 221, sizeof(LogInfo));
7661da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#endif
7671da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds}
7681da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds/* ------------------------------------------------------------------------
769475be4d85a274d0961593db41cf85689db1d583cJoe Perches   This function writes the information about the request processing
770475be4d85a274d0961593db41cf85689db1d583cJoe Perches   in the trace buffer. Trace ID is 220.
771475be4d85a274d0961593db41cf85689db1d583cJoe Perches   INPUT:
772475be4d85a274d0961593db41cf85689db1d583cJoe Perches   Adapter - system unicue adapter number (0 ... 255)
773475be4d85a274d0961593db41cf85689db1d583cJoe Perches   Id      - Id of the entity that had sent this request
774475be4d85a274d0961593db41cf85689db1d583cJoe Perches   Ch      - Channel of the entity that had sent this request
775475be4d85a274d0961593db41cf85689db1d583cJoe Perches   Req     - Code of the request
776475be4d85a274d0961593db41cf85689db1d583cJoe Perches   type    - the Id that was sent by the ASSIGN of this entity.
777475be4d85a274d0961593db41cf85689db1d583cJoe Perches   This should be global Id like NL_ID, DSIG_ID, MAN_ID.
778475be4d85a274d0961593db41cf85689db1d583cJoe Perches   An unknown Id will cause "?-" in the front of the request.
779475be4d85a274d0961593db41cf85689db1d583cJoe Perches   In this case the log.c is to be extended.
7801da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds   ------------------------------------------------------------------------ */
781475be4d85a274d0961593db41cf85689db1d583cJoe Perchesstatic void xdi_xlog_request(byte Adapter, byte Id,
782475be4d85a274d0961593db41cf85689db1d583cJoe Perches			     byte Ch, byte Req, byte type) {
7831da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#if defined(XDI_USE_XLOG)
784475be4d85a274d0961593db41cf85689db1d583cJoe Perches	word LogInfo[3];
785475be4d85a274d0961593db41cf85689db1d583cJoe Perches	PUT_WORD(&LogInfo[0], ((word)Adapter | (word)(xdi_xlog_sec++ << 8)));
786475be4d85a274d0961593db41cf85689db1d583cJoe Perches	PUT_WORD(&LogInfo[1], ((word)Id | (word)(Ch << 8)));
787475be4d85a274d0961593db41cf85689db1d583cJoe Perches	PUT_WORD(&LogInfo[2], ((word)Req | (word)(type << 8)));
788475be4d85a274d0961593db41cf85689db1d583cJoe Perches	xdi_xlog((byte *)&LogInfo[0], 220, sizeof(LogInfo));
7891da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#endif
7901da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds}
7911da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds/* ------------------------------------------------------------------------
792475be4d85a274d0961593db41cf85689db1d583cJoe Perches   This function writes the information about the indication processing
793475be4d85a274d0961593db41cf85689db1d583cJoe Perches   in the trace buffer. Trace ID is 222.
794475be4d85a274d0961593db41cf85689db1d583cJoe Perches   INPUT:
795475be4d85a274d0961593db41cf85689db1d583cJoe Perches   Adapter - system unicue adapter number (0 ... 255)
796475be4d85a274d0961593db41cf85689db1d583cJoe Perches   Id      - Id of the entity that had sent this indication
797475be4d85a274d0961593db41cf85689db1d583cJoe Perches   Ch      - Channel of the entity that had sent this indication
798475be4d85a274d0961593db41cf85689db1d583cJoe Perches   Ind     - Code of the indication
799475be4d85a274d0961593db41cf85689db1d583cJoe Perches   rnr_valid: (0 .. 3) supported
800475be4d85a274d0961593db41cf85689db1d583cJoe Perches   switch (rnr_valid) {
801475be4d85a274d0961593db41cf85689db1d583cJoe Perches   case 0: printf ("DELIVERY"); break;
802475be4d85a274d0961593db41cf85689db1d583cJoe Perches   case 1: printf ("RNR=%d", rnr);
803475be4d85a274d0961593db41cf85689db1d583cJoe Perches   case 2: printf ("RNum=0");
804475be4d85a274d0961593db41cf85689db1d583cJoe Perches   case 3: printf ("COMPLETE");
805475be4d85a274d0961593db41cf85689db1d583cJoe Perches   }
806475be4d85a274d0961593db41cf85689db1d583cJoe Perches   DELIVERY - indication entered isdn_rc function
807475be4d85a274d0961593db41cf85689db1d583cJoe Perches   RNR=...  - application had returned RNR=... after the
808475be4d85a274d0961593db41cf85689db1d583cJoe Perches   look ahead callback
809475be4d85a274d0961593db41cf85689db1d583cJoe Perches   RNum=0   - application had not returned any buffer to copy
810475be4d85a274d0961593db41cf85689db1d583cJoe Perches   this indication and will copy it self
811475be4d85a274d0961593db41cf85689db1d583cJoe Perches   COMPLETE - XDI had copied the data to the buffers provided
812475be4d85a274d0961593db41cf85689db1d583cJoe Perches   bu the application and is about to issue the
813475be4d85a274d0961593db41cf85689db1d583cJoe Perches   final callback
814475be4d85a274d0961593db41cf85689db1d583cJoe Perches   rnr:  Look case 1 of the rnr_valid
815475be4d85a274d0961593db41cf85689db1d583cJoe Perches   type: the Id that was sent by the ASSIGN of this entity. This should
816475be4d85a274d0961593db41cf85689db1d583cJoe Perches   be global Id like NL_ID, DSIG_ID, MAN_ID. An unknown Id will
817475be4d85a274d0961593db41cf85689db1d583cJoe Perches   cause "?-" in the front of the request. In this case the
818475be4d85a274d0961593db41cf85689db1d583cJoe Perches   log.c is to be extended.
8191da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds   ------------------------------------------------------------------------ */
820475be4d85a274d0961593db41cf85689db1d583cJoe Perchesstatic void xdi_xlog_ind(byte Adapter,
821475be4d85a274d0961593db41cf85689db1d583cJoe Perches			 byte Id,
822475be4d85a274d0961593db41cf85689db1d583cJoe Perches			 byte Ch,
823475be4d85a274d0961593db41cf85689db1d583cJoe Perches			 byte Ind,
824475be4d85a274d0961593db41cf85689db1d583cJoe Perches			 byte rnr_valid,
825475be4d85a274d0961593db41cf85689db1d583cJoe Perches			 byte rnr,
826475be4d85a274d0961593db41cf85689db1d583cJoe Perches			 byte type) {
8271da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#if defined(XDI_USE_XLOG)
828475be4d85a274d0961593db41cf85689db1d583cJoe Perches	word LogInfo[4];
829475be4d85a274d0961593db41cf85689db1d583cJoe Perches	PUT_WORD(&LogInfo[0], ((word)Adapter | (word)(xdi_xlog_sec++ << 8)));
830475be4d85a274d0961593db41cf85689db1d583cJoe Perches	PUT_WORD(&LogInfo[1], ((word)Id | (word)(Ch << 8)));
831475be4d85a274d0961593db41cf85689db1d583cJoe Perches	PUT_WORD(&LogInfo[2], ((word)Ind | (word)(type << 8)));
832475be4d85a274d0961593db41cf85689db1d583cJoe Perches	PUT_WORD(&LogInfo[3], ((word)rnr | (word)(rnr_valid << 8)));
833475be4d85a274d0961593db41cf85689db1d583cJoe Perches	xdi_xlog((byte *)&LogInfo[0], 222, sizeof(LogInfo));
8341da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#endif
8351da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds}
836