]>
git.saurik.com Git - apple/xnu.git/blob - bsd/netat/adsp_reset.c
296b73c26f470ecabcf0b336422773947932584f
2 * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_OSREFERENCE_HEADER_START@
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
16 * Please obtain a copy of the License at
17 * http://www.opensource.apple.com/apsl/ and read it before using this
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.
28 * @APPLE_LICENSE_OSREFERENCE_HEADER_END@
33 * From v01.15 07/11/90 mbs
37 * 06/29/95 - Modified to handle flow control for writing (Tuyen Nguyen)
38 * Modified for MP, 1996 by Tuyen Nguyen
39 * Modified, April 9, 1997 by Tuyen Nguyen for MacOSX.
42 #include <sys/errno.h>
43 #include <sys/types.h>
44 #include <sys/param.h>
45 #include <machine/spl.h>
46 #include <sys/systm.h>
47 #include <sys/kernel.h>
49 #include <sys/filedesc.h>
50 #include <sys/fcntl.h>
52 #include <sys/socket.h>
55 #include <netat/sysglue.h>
56 #include <netat/appletalk.h>
57 #include <netat/at_pcb.h>
58 #include <netat/debug.h>
59 #include <netat/adsp.h>
60 #include <netat/adsp_internal.h>
65 * We just got a Forward Reset Packet.
67 * Called with interrupts OFF
71 * Pointer to ADSP header,
73 * Returns 1 if packet was ignored
75 int RXFReset(sp
, f
) /* (CCBPtr sp, ADSP_FRAMEPtr f) */
79 unsigned int pktFirstByteSeq
;
82 register struct adspcmd
*pb
;
84 pktFirstByteSeq
= UAL_VALUE_NTOH(f
->pktFirstByteSeq
);
86 hi
= sp
->recvSeq
+ CalcRecvWdw(sp
);
89 * Must do this with interrupts OFF
91 if (BETWEEN(sp
->recvSeq
, pktFirstByteSeq
, hi
)) /* Is this acceptable? */
93 sp
->recvSeq
= pktFirstByteSeq
;
94 while (mp
= sp
->rbuf_mb
) { /* clear the receive queue */
95 sp
->rbuf_mb
= gbuf_next(mp
);
99 gbuf_freem(sp
->crbuf_mb
);
104 sp
->userFlags
|= eFwdReset
; /* Set forward reset received Flag */
106 mp
= gbuf_alloc(sizeof(struct adspcmd
), PRI_HI
);
107 pb
= (struct adspcmd
*)gbuf_rptr(mp
);
108 gbuf_winc(mp
,sizeof(struct adspcmd
));
112 pb
->csCode
= dspReset
;
115 sp
->userFlags
&= ~eFwdReset
;
118 if (LTE(pktFirstByteSeq
, hi
)) {
119 sp
->sendCtl
|= B_CTL_FRESETACK
; /* Ack it if it's OK, or a duplicate */
130 * We just got a Forward Reset Acknowledgement packet
132 * Called with interrupts OFF
136 * Pointer to ADSP header,
138 * Returns 1 if packet was ignored
140 int RXFResetAck(sp
, f
) /* (CCBPtr sp, ADSP_FRAMEPtr f) */
144 unsigned int PktNextRecvSeq
;
146 if (sp
->frpb
== 0) /* Not expecting frwd reset Ack packet */
149 PktNextRecvSeq
= UAL_VALUE_NTOH(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
;
184 * --> ccbRefNum refnum of connection end
190 * errRefNum bad connection refnum
191 * errState connection is not open
192 * errAborted request aborted by Remove or Close call
194 int adspReset(sp
, pb
) /* (DSPPBPtr pb) */
199 register struct adspcmd
*rpb
;
202 pb
->ioResult
= errRefNum
;
206 if (sp
->state
!= sOpen
) {
207 pb
->ioResult
= errState
;
212 while (mp
= sp
->sbuf_mb
) { /* clear the send queue */
213 sp
->sbuf_mb
= gbuf_next(mp
);
217 gbuf_freem(sp
->csbuf_mb
);
222 sp
->sendCtl
|= B_CTL_FRESET
;
224 sp
->firstRtmtSeq
= sp
->sendSeq
; /* Reset sequence #'s */
225 if (mp
= gbuf_copym(pb
->mp
)) { /* copy the parameter block */
226 adspioc_ack(0, pb
->ioc
, pb
->gref
); /* release user */
227 rpb
= (struct adspcmd
*)gbuf_rptr(mp
);
228 rpb
->ioc
= 0; /* unlink copy */
231 qAddToEnd(&sp
->frpb
, rpb
);
232 /* Hold on to pb (will be completed when */
233 /* forward reset ack is received). */
234 } else { /* assume it will work... but keep no
235 * bookkeeping for it. yetch! */
236 adspioc_ack(0, pb
->ioc
, pb
->gref
);