]>
git.saurik.com Git - apple/xnu.git/blob - bsd/netat/adsp_reset.c
f52f42ab5ff5d81303b60917e1998a65f38d2460
2 * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
4 * @APPLE_OSREFERENCE_LICENSE_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 License
10 * may not be used to create, or enable the creation or redistribution of,
11 * unlawful or unlicensed copies of an Apple operating system, or to
12 * circumvent, violate, or enable the circumvention or violation of, any
13 * terms of an Apple operating system software license agreement.
15 * Please obtain a copy of the License at
16 * http://www.opensource.apple.com/apsl/ and read it before using this file.
18 * The Original Code and all software distributed under the License are
19 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
20 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
21 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
22 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
23 * Please see the License for the specific language governing rights and
24 * limitations under the License.
26 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
31 * From v01.15 07/11/90 mbs
35 * 06/29/95 - Modified to handle flow control for writing (Tuyen Nguyen)
36 * Modified for MP, 1996 by Tuyen Nguyen
37 * Modified, April 9, 1997 by Tuyen Nguyen for MacOSX.
40 #include <sys/errno.h>
41 #include <sys/types.h>
42 #include <sys/param.h>
43 #include <machine/spl.h>
44 #include <sys/systm.h>
45 #include <sys/kernel.h>
47 #include <sys/filedesc.h>
48 #include <sys/fcntl.h>
50 #include <sys/socket.h>
53 #include <netat/sysglue.h>
54 #include <netat/appletalk.h>
55 #include <netat/at_pcb.h>
56 #include <netat/debug.h>
57 #include <netat/adsp.h>
58 #include <netat/adsp_internal.h>
63 * We just got a Forward Reset Packet.
65 * Called with interrupts OFF
69 * Pointer to ADSP header,
71 * Returns 1 if packet was ignored
73 int RXFReset(sp
, f
) /* (CCBPtr sp, ADSP_FRAMEPtr f) */
77 unsigned int pktFirstByteSeq
;
80 register struct adspcmd
*pb
;
82 pktFirstByteSeq
= UAL_VALUE_NTOH(f
->pktFirstByteSeq
);
84 hi
= sp
->recvSeq
+ CalcRecvWdw(sp
);
87 * Must do this with interrupts OFF
89 if (BETWEEN(sp
->recvSeq
, pktFirstByteSeq
, hi
)) /* Is this acceptable? */
91 sp
->recvSeq
= pktFirstByteSeq
;
92 while ((mp
= sp
->rbuf_mb
)) { /* clear the receive queue */
93 sp
->rbuf_mb
= gbuf_next(mp
);
97 gbuf_freem(sp
->crbuf_mb
);
102 sp
->userFlags
|= eFwdReset
; /* Set forward reset received Flag */
104 mp
= gbuf_alloc(sizeof(struct adspcmd
), PRI_HI
);
105 pb
= (struct adspcmd
*)gbuf_rptr(mp
);
106 gbuf_winc(mp
,sizeof(struct adspcmd
));
110 pb
->csCode
= dspReset
;
113 sp
->userFlags
&= ~eFwdReset
;
116 if (LTE(pktFirstByteSeq
, hi
)) {
117 sp
->sendCtl
|= B_CTL_FRESETACK
; /* Ack it if it's OK, or a duplicate */
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
;
144 if (sp
->frpb
== 0) /* Not expecting frwd reset Ack packet */
147 PktNextRecvSeq
= UAL_VALUE_NTOH(f
->pktNextRecvSeq
);
149 if (BETWEEN(sp
->sendSeq
, PktNextRecvSeq
, sp
->sendWdwSeq
+1)) {
152 RemoveTimerElem(&adspGlobal
.fastTimers
, &sp
->ResetTimer
);
156 * Interrupts are OFF here while we muck with the linked list
158 pb
= sp
->frpb
; /* Unlink copy of user's parameter block */
159 sp
->frpb
= (struct adspcmd
*)pb
->qLink
;
162 completepb(sp
, pb
); /* complete(pb, 0); */
164 if (sp
->state
== sClosing
) /* this ack may allow us to close... */
167 if (sp
->frpb
) /* Another to send? */
170 sp
->sendCtl
|= B_CTL_FRESET
;
182 * --> ccbRefNum refnum of connection end
188 * errRefNum bad connection refnum
189 * errState connection is not open
190 * errAborted request aborted by Remove or Close call
192 int adspReset(sp
, pb
) /* (DSPPBPtr pb) */
197 register struct adspcmd
*rpb
;
200 pb
->ioResult
= errRefNum
;
204 if (sp
->state
!= sOpen
) {
205 pb
->ioResult
= errState
;
210 while ((mp
= sp
->sbuf_mb
)) { /* clear the send queue */
211 sp
->sbuf_mb
= gbuf_next(mp
);
215 gbuf_freem(sp
->csbuf_mb
);
220 sp
->sendCtl
|= B_CTL_FRESET
;
222 sp
->firstRtmtSeq
= sp
->sendSeq
; /* Reset sequence #'s */
223 if ((mp
= gbuf_copym(pb
->mp
))) { /* copy the parameter block */
224 adspioc_ack(0, (gbuf_t
*)pb
->ioc
, pb
->gref
); /* release user */
225 rpb
= (struct adspcmd
*)gbuf_rptr(mp
);
226 rpb
->ioc
= 0; /* unlink copy */
229 qAddToEnd((struct qlink
**)&sp
->frpb
, (struct qlink
*)rpb
);
230 /* Hold on to pb (will be completed when */
231 /* forward reset ack is received). */
232 } else { /* assume it will work... but keep no
233 * bookkeeping for it. yetch! */
234 adspioc_ack(0, (gbuf_t
*)pb
->ioc
, pb
->gref
);