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