]>
git.saurik.com Git - apple/xnu.git/blob - bsd/netat/adsp_reset.c
b8e8e4293d45fdef64a63ef94a9a472d897b5fb1
2 * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
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
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
17 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
18 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
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.
23 * @APPLE_LICENSE_HEADER_END@
28 * From v01.15 07/11/90 mbs
32 * 06/29/95 - Modified to handle flow control for writing (Tuyen Nguyen)
33 * Modified for MP, 1996 by Tuyen Nguyen
34 * Modified, April 9, 1997 by Tuyen Nguyen for MacOSX.
37 #include <sys/errno.h>
38 #include <sys/types.h>
39 #include <sys/param.h>
40 #include <machine/spl.h>
41 #include <sys/systm.h>
42 #include <sys/kernel.h>
44 #include <sys/filedesc.h>
45 #include <sys/fcntl.h>
47 #include <sys/socket.h>
50 #include <netat/sysglue.h>
51 #include <netat/appletalk.h>
52 #include <netat/at_pcb.h>
53 #include <netat/debug.h>
54 #include <netat/adsp.h>
55 #include <netat/adsp_internal.h>
60 * We just got a Forward Reset Packet.
62 * Called with interrupts OFF
66 * Pointer to ADSP header,
68 * Returns 1 if packet was ignored
70 int RXFReset(sp
, f
) /* (CCBPtr sp, ADSP_FRAMEPtr f) */
74 unsigned int pktFirstByteSeq
;
77 register struct adspcmd
*pb
;
80 ATDISABLE(s
, sp
->lock
);
81 pktFirstByteSeq
= netdw(UAL_VALUE(f
->pktFirstByteSeq
));
83 hi
= sp
->recvSeq
+ CalcRecvWdw(sp
);
86 * Must do this with interrupts OFF
88 if (BETWEEN(sp
->recvSeq
, pktFirstByteSeq
, hi
)) /* Is this acceptable? */
90 sp
->recvSeq
= pktFirstByteSeq
;
91 while (mp
= sp
->rbuf_mb
) { /* clear the receive queue */
92 sp
->rbuf_mb
= gbuf_next(mp
);
96 gbuf_freem(sp
->crbuf_mb
);
101 sp
->userFlags
|= eFwdReset
; /* Set forward reset received Flag */
103 mp
= gbuf_alloc(sizeof(struct adspcmd
), PRI_HI
);
104 pb
= (struct adspcmd
*)gbuf_rptr(mp
);
105 gbuf_winc(mp
,sizeof(struct adspcmd
));
109 pb
->csCode
= dspReset
;
112 sp
->userFlags
&= ~eFwdReset
;
115 if (LTE(pktFirstByteSeq
, hi
)) {
116 sp
->sendCtl
|= B_CTL_FRESETACK
; /* Ack it if it's OK, or a duplicate */
120 ATENABLE(s
, sp
->lock
);
128 * We just got a Forward Reset Acknowledgement packet
130 * Called with interrupts OFF
134 * Pointer to ADSP header,
136 * Returns 1 if packet was ignored
138 int RXFResetAck(sp
, f
) /* (CCBPtr sp, ADSP_FRAMEPtr f) */
142 unsigned int PktNextRecvSeq
;
145 if (sp
->frpb
== 0) /* Not expecting frwd reset Ack packet */
148 ATDISABLE(s
, sp
->lock
);
149 PktNextRecvSeq
= netdw(UAL_VALUE(f
->pktNextRecvSeq
));
151 if (BETWEEN(sp
->sendSeq
, PktNextRecvSeq
, sp
->sendWdwSeq
+1)) {
154 RemoveTimerElem(&adspGlobal
.fastTimers
, &sp
->ResetTimer
);
158 * Interrupts are OFF here while we muck with the linked list
160 pb
= sp
->frpb
; /* Unlink copy of user's parameter block */
161 sp
->frpb
= (struct adspcmd
*)pb
->qLink
;
164 completepb(sp
, pb
); /* complete(pb, 0); */
166 if (sp
->state
== sClosing
) /* this ack may allow us to close... */
169 if (sp
->frpb
) /* Another to send? */
172 sp
->sendCtl
|= B_CTL_FRESET
;
176 ATENABLE(s
, sp
->lock
);
185 * --> ccbRefNum refnum of connection end
191 * errRefNum bad connection refnum
192 * errState connection is not open
193 * errAborted request aborted by Remove or Close call
195 int adspReset(sp
, pb
) /* (DSPPBPtr pb) */
201 register struct adspcmd
*rpb
;
204 pb
->ioResult
= errRefNum
;
208 if (sp
->state
!= sOpen
) {
209 pb
->ioResult
= errState
;
213 ATDISABLE(s
, sp
->lock
);
215 while (mp
= sp
->sbuf_mb
) { /* clear the send queue */
216 sp
->sbuf_mb
= gbuf_next(mp
);
220 gbuf_freem(sp
->csbuf_mb
);
225 sp
->sendCtl
|= B_CTL_FRESET
;
227 sp
->firstRtmtSeq
= sp
->sendSeq
; /* Reset sequence #'s */
228 if (mp
= gbuf_copym(pb
->mp
)) { /* copy the parameter block */
229 adspioc_ack(0, pb
->ioc
, pb
->gref
); /* release user */
230 rpb
= (struct adspcmd
*)gbuf_rptr(mp
);
231 rpb
->ioc
= 0; /* unlink copy */
234 qAddToEnd(&sp
->frpb
, rpb
);
235 /* Hold on to pb (will be completed when */
236 /* forward reset ack is received). */
237 } else { /* assume it will work... but keep no
238 * bookkeeping for it. yetch! */
239 adspioc_ack(0, pb
->ioc
, pb
->gref
);
241 ATENABLE(s
, sp
->lock
);