]> git.saurik.com Git - apple/xnu.git/blame - bsd/netat/adsp_internal.h
xnu-344.21.74.tar.gz
[apple/xnu.git] / bsd / netat / adsp_internal.h
CommitLineData
1c79356b
A
1/*
2 * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
d7e50217 6 * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
1c79356b 7 *
d7e50217
A
8 * This file contains Original Code and/or Modifications of Original Code
9 * as defined in and that are subject to the Apple Public Source License
10 * Version 2.0 (the 'License'). You may not use this file except in
11 * compliance with the License. Please obtain a copy of the License at
12 * http://www.opensource.apple.com/apsl/ and read it before using this
13 * file.
14 *
15 * The Original Code and all software distributed under the License are
16 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
1c79356b
A
17 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
18 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
d7e50217
A
19 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
20 * Please see the License for the specific language governing rights and
21 * limitations under the License.
1c79356b
A
22 *
23 * @APPLE_LICENSE_HEADER_END@
24 */
25#ifndef _NETAT_ADSP_INTERNAL_H_
26#define _NETAT_ADSP_INTERNAL_H_
9bccf70c
A
27#include <sys/appleapiopts.h>
28
29#include <sys/types.h>
1c79356b
A
30
31#ifdef KERNEL
9bccf70c 32#ifdef __APPLE_API_PRIVATE
1c79356b
A
33
34/* from h/adsp_portab.h */
35
36/* TypeDefs for the basic data bytes. */
37
38typedef unsigned char byte, *bytePtr;
39
40#ifdef NOT_USED
41typedef char int8;
42typedef short int16;
43typedef int int32;
44#endif
45
46typedef unsigned char boolean;
47
48typedef unsigned short word;
49
50typedef unsigned int dword;
51
52#define BYTE_AT(x) (*((byte PTR)(x)))
53#define WORD_AT(x) (*((word PTR)(x)))
54#define DWORD_AT(x) (*((dword PTR)(x)))
55
56#define high(x) ((byte)((x) >> 8))
57#define low(x) ((byte)(x))
58#define hlword(h, l) (((byte)(l)) | (((byte)(h)) << 8))
59
1c79356b
A
60
61/*
62 * On a Mac, there is no need to byte-swap data on the network, so
63 * these macros do nothing
64 */
65
66#define netw(x) x
67#define netdw(x) x
68
69typedef struct
70{
71 at_net network; /* network number */
72 byte nodeid; /* node number */
73 byte socket; /* socket number */
74} AddrBlk, *AddrBlkPtr;
75
76typedef union
77{
78 at_inet_t a;
79} AddrUnion, *AddrUnionPtr;
80
81/* End Portab.h */
82
83/* from h/adsp_internal.h */
84
85#undef T_IDLE
86
87/*
88* Default Behavior for ADSP
89*/
90#define ocIntervalDefault 6
91#define ocMaximumDefault 10
92#define probeIntervalDefault 180
93
94/*
95* MACROS for comparing 32-bit sequence numbers
96*/
97#define GT(x,y) (((long)(x-y)) > (long) 0)
98#define LT(x,y) (((long)(x-y)) < (long) 0)
99#define GTE(x,y) (((long)(x-y)) >= (long) 0)
100#define LTE(x,y) (((long)(x-y)) <= (long) 0)
101#define BETWEEN(x,y,z) (LTE(x,y) && LTE(y,z))
102
103/*
104 * Use the kernel tick counter for SysTicks.
105 */
106
107#define SysTicks() lbolt
108
109/*
110 * Timer element used for handling timings
111 */
112typedef struct timerelem {
113 struct timerelem *link;
114 short timer;
115 char type;
116 unsigned onQ:1; /* Bit-fields are faster than booleans */
117} TimerElem;
118
119typedef TimerElem *TimerElemPtr;
120
121/*
122 * For AppleTalk Phase 2 event queue
123 */
124typedef struct {
125 Ptr qLink;
126 unsigned short qType;
127 ProcPtr callAddr;
128} LAPEventElem;
129
130typedef LAPEventElem *LAPEventElemPtr;
131
132/*
133 * The Event types we're passed when an AppleTalk transition occurs
134 */
135#define AOpenTransition 0
136#define ACloseTransition 2
137#define ANetworkTransition 5
138
139/*
140 * The element we're passed when a NetworkTransaction event occurs
141 */
142typedef struct TNetworkTransition {
143 Ptr private; /* pointer used internally by NetShare */
144 ProcPtr netValidProc; /* pointer to the network valid procedure */
145} TNetworkTransition, *TPNetworkTransition;
146
147typedef long (*NetworkTransitionProcPtr)();
148 /* (TPNetworkTransition nettrans,
149 unsigned long thenet); */
150/*
151 * This is the connection control block
152 */
153typedef struct ccb {
154 /*---These fields may not change order or size-----------*/
155
156 struct ccb *ccbLink; /* link to next ccb */
157 unsigned short state; /* state of the connection end */
158 unsigned char userFlags; /* flags for unsolicited connection events */
159 unsigned char localSocket; /* socket number of this connection end */
160 AddrUnion remoteAddress; /* internet address of remote end */
161 unsigned short attnCode; /* attention code received */
162 unsigned short attnSize; /* size of received attention data */
163 unsigned char *attnPtr; /* ptr to received attention data */
164 unsigned short recvQPending; /* # bytes in receive queue %%% */
165 /*------------------------------------------------------ */
166
167 struct adspcmd *opb; /* Outstanding open/close/remove/listens */
168 struct adspcmd *spb; /* Outstanding Sends */
169 struct adspcmd *sapb; /* Outstanding Send Attentions */
170 struct adspcmd *frpb; /* Outstanding Forward Resets */
171 struct adspcmd *rpb; /* Outstanding Read Requests */
172
173 struct ccb *otccbLink; /* link to next ccb */
174 int pid; /* Process ID for CCB owner */
175
176 unsigned short remCID; /* Remote Connection ID */
177 unsigned short locCID; /* Local Connection ID */
178 int sendSeq; /* Seq number of next char to send to remote */
179 int firstRtmtSeq; /* oldest seq # in local send queue */
180 int sendWdwSeq; /* Seq # of last char remote has bfr for */
181 int recvSeq; /* Seq of # of next char expected from rmte */
182 int recvWdw; /* # of bytes local end has buffer space for */
183 int attnSendSeq; /* Seq # of next attn pkt to send to remote */
184 int attnRecvSeq; /* Seq # of next packet local end expects */
185 int maxSendSeq; /* Highest seq # we ever sent on connection */
186
187 /* These must be in the first 255 bytes of the CCB */
188 TimerElem ProbeTimer; /* Timer element for probes (and open) */
189 TimerElem FlushTimer; /* Timer element for flushing data */
190 TimerElem RetryTimer; /* Timer element for retransmissions */
191 TimerElem AttnTimer; /* Timer element for attention packets */
192 TimerElem ResetTimer; /* Timer element for forward resets */
193
194 short openInterval; /* Interval between open connection packets */
195 short probeInterval; /* Interval between probes */
196 short sendInterval; /* Interval before automatic flush */
197 short rtmtInterval; /* Rexmit interval (dynamically determined) */
198
199 short sendCtl; /* Send control message bits */
200 short sendBlocking; /* Flush unsent data if > than sendBlocking */
201 short openRetrys; /* # of retrys for Connect & Accept */
202 short rbuflen; /* Total size of receive buffer */
203 short sbuflen; /* Total size of receive buffer */
204 char pad;
205 char lockFlag;
206 char badSeqMax; /* retransmit advice send threshold */
207 char badSeqCnt; /* # of of out-of-order packets received */
208 char useCheckSum; /* true to use DDP checksums */
209 char openState; /* Used for opening a connection (see below) */
210
211 gbuf_t *rbuf_mb; /* message block for the recv buffer */
212 gbuf_t *crbuf_mb;
213 gbuf_t *sbuf_mb; /* message block for the send buffer */
214 gbuf_t *csbuf_mb;
215 gbuf_t *attn_mb; /* message block for the attention buffer */
216 gbuf_t *deferred_mb; /* message block deferred for later processing */
217
218#ifdef NOT_USED
219 char ioDone; /* flag for when the adsp header is busy */
220#endif
221 char probeCntr; /* # of probes we can miss (counts down) */
222 char pktSendMax; /* Max # of packets to send without an ack */
223 char pktSendCnt; /* # of packets sent so far */
224
225 int sendStamp; /* Time of last ackRequest */
226 int timerSeq; /* Seq # of char corresponding to above time stamp */
227 short roundTrip; /* Average Round-Trip time (in 6ths of a second) */
228 short deviation; /* deviation from roundTrip time */
229
230 unsigned sData:1; /* There's data in the send queue */
231 unsigned waitingAck:1; /* We're waiting for an ack packet */
232 unsigned rData:1; /* There's data in the receive queue */
233 unsigned resentData:1; /* True when we resend data due to timeout */
234 unsigned sendDataAck:1; /* True if he requested an ack */
235 unsigned sendAttnAck:1; /* Must send attn acknowlege */
236 unsigned sendAttnData:1; /* Must send attn data */
237 unsigned callSend:1; /* Must call CheckSend() */
238 unsigned rbufFull:1; /* We've closed our receive window. */
239 unsigned noXmitFlow:1; /* True stops incrementing # of xmit
240 * packets to send in a row after receiving
241 * an ack packet. */
242 unsigned secureCCB:1; /* True if this is a secure connection */
243 unsigned removing:1; /* There is a dspRemove pending */
244 unsigned writeFlush:1; /* Flush send queue even if # bytes to
245 * send is less than send blocking. */
246 unsigned delay:1; /* do not complete commands until user
247 * *** NO LONGER USED IN KERNEL *** */
248 ADSP_FRAME f; /* Used to send every packet */
249 ADSP_OPEN_DATA of; /* Holds the data for the open exchange */
250 gref_t *gref; /* The queue associated with the CCB */
251 gbuf_t *sp_mp;
252 atlock_t lock;
253 atlock_t lockClose;
254 atlock_t lockRemove;
255} CCB, *CCBPtr;
256
257
258/*
259 * Change order and die !!! --- See the receive open packet code
260 */
261#define O_STATE_NOTHING 0 /* Not opening */
262#define O_STATE_LISTEN 1 /* Listening for open request */
263#define O_STATE_OPENWAIT 2 /* Sent Req, waiting for Ack to open
264 * request */
265#define O_STATE_ESTABLISHED 3 /* Got Req, send Req+Ack,waiting Ack */
266#define O_STATE_OPEN 4 /* Connection is open */
267
268/*
269* These bits are used in the sendCtl field to indicate what needs to be sent
270*/
271#define B_CTL_PROBE 0x0001
272#define B_CTL_OREQ 0x0002
273#define B_CTL_OACK 0x0004
274#define B_CTL_OREQACK 0x0008
275#define B_CTL_ODENY 0x0010
276#define B_CTL_CLOSE 0x0020
277#define B_CTL_FRESET 0x0040
278#define B_CTL_FRESETACK 0x0080
279#define B_CTL_RETRANSMIT 0x0100
280
281
282#define kProbeTimerType offsetof(CCB, ProbeTimer)
283#define kFlushTimerType offsetof(CCB, FlushTimer)
284#define kRetryTimerType offsetof(CCB, RetryTimer)
285#define kAttnTimerType offsetof(CCB, AttnTimer)
286#define kResetTimerType offsetof(CCB, ResetTimer)
287
288/*
289 * Used to manage the send receive queue
290 */
291typedef struct {
292 short len; /* # of bytes in this fragment */
293 char flags; /* See #define's below */
294 char data[1];
295} HDR, *HDRPtr;
296
297#define HDR_LEN 3 /* Yes, I know it really is 4 bytes long... */
298
299#define F_GAP 0x03
300#define F_EOM 0x04
301#define F_WRAP 0x08
302#define F_VALID 0x10
303#define F_ENCRYPTED 0x20 /* %%% Needed ??? */
304#define F_LAST 0x40 /* This is last block in buffer */
305
306
307/* %%% Are these two used anymore? */
308#define sbufPtr(y) (&sp->sbuf[((y) < sp->sbuflen) ? (y) : ((y) - sp->sbuflen)])
309#define rbufPtr(y) (&sp->rbuf[((y) < sp->rbuflen) ? (y) : ((y) - sp->rbuflen)])
310
311/* End Internal.h */
312
313/* fron h/adsp_supp.h */
314
315void CallUserRoutine(); /* (CCB FPTR sp); */
316
317
318/*
319 * Add queue element to end of queue. Pass Address of ptr to
320 * 1st element of queue
321 */
322int qAddToEnd(); /* (void FPTR FPTR qhead, void FPTR qelem); */
323
324/*
325 * Hunt down a linked list of queue elements looking for an element with
326 * 'data' at 'offset' bytes into the queue element.
327 */
328void *qfind_b(); /* (void *qhead, word offset, word data); */
329void *qfind_w(); /* (void *qhead, word offset, word data); */
330void *qfind_p(); /* (void *qhead, word offset, void *ptr); */
331void *qfind_o(); /* (void *qhead, word offset, void *ptr); */
332void *qfind_m(); /* (void *qhead, void *match,
333 ProcPtr compare_fnx); */
334
335
336/*
337 * Routines to handle sorted timer queues
338 */
339void InsertTimerElem(); /* (TimerElemPtr *qhead, TimerElemPtr t,
340 word val); */
341void RemoveTimerElem(); /* (TimerElemPtr *qhead, TimerElemPtr t); */
342void TimerQueueTick(); /* (TimerElemPtr *qhead);*/
343
344/* from h/adsp_global.h */
345
346typedef struct {
347 void *ccbList; /* Ptr to list of connection control blocks */
348
349 TimerElemPtr slowTimers; /* The probe timer list */
350 TimerElemPtr fastTimers; /* The fast timer list */
351
352 unsigned short lastCID; /* Last connection ID assigned */
353 char inTimer; /* We're inside timer routine */
354} GLOBAL;
355
356extern GLOBAL adspGlobal;
357
358/* Address of ptr to list of ccb's */
359#define AT_ADSP_STREAMS ((CCB **)&(adspGlobal.ccbList))
360
9bccf70c 361#endif /* __APPLE_API_PRIVATE */
1c79356b
A
362#endif /* KERNEL */
363
364#endif /* _NETAT_ADSP_INTERNAL_H_ */