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