]>
git.saurik.com Git - apple/xnu.git/blob - bsd/netat/adsp_reset.c
0915f6857a093c5f800429dadcc1fdee1accc7ee
2 * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
4 * @APPLE_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. Please obtain a copy of the License at
10 * http://www.opensource.apple.com/apsl/ and read it before using this
13 * The Original Code and all software distributed under the License are
14 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
15 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
16 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
18 * Please see the License for the specific language governing rights and
19 * limitations under the License.
21 * @APPLE_LICENSE_HEADER_END@
26 * From v01.15 07/11/90 mbs
30 * 06/29/95 - Modified to handle flow control for writing (Tuyen Nguyen)
31 * Modified for MP, 1996 by Tuyen Nguyen
32 * Modified, April 9, 1997 by Tuyen Nguyen for MacOSX.
35 #include <sys/errno.h>
36 #include <sys/types.h>
37 #include <sys/param.h>
38 #include <machine/spl.h>
39 #include <sys/systm.h>
40 #include <sys/kernel.h>
42 #include <sys/filedesc.h>
43 #include <sys/fcntl.h>
45 #include <sys/socket.h>
48 #include <netat/sysglue.h>
49 #include <netat/appletalk.h>
50 #include <netat/at_pcb.h>
51 #include <netat/debug.h>
52 #include <netat/adsp.h>
53 #include <netat/adsp_internal.h>
58 * We just got a Forward Reset Packet.
60 * Called with interrupts OFF
64 * Pointer to ADSP header,
66 * Returns 1 if packet was ignored
68 int RXFReset(sp
, f
) /* (CCBPtr sp, ADSP_FRAMEPtr f) */
72 unsigned int pktFirstByteSeq
;
75 register struct adspcmd
*pb
;
78 ATDISABLE(s
, sp
->lock
);
79 pktFirstByteSeq
= netdw(UAL_VALUE(f
->pktFirstByteSeq
));
81 hi
= sp
->recvSeq
+ CalcRecvWdw(sp
);
84 * Must do this with interrupts OFF
86 if (BETWEEN(sp
->recvSeq
, pktFirstByteSeq
, hi
)) /* Is this acceptable? */
88 sp
->recvSeq
= pktFirstByteSeq
;
89 while (mp
= sp
->rbuf_mb
) { /* clear the receive queue */
90 sp
->rbuf_mb
= gbuf_next(mp
);
94 gbuf_freem(sp
->crbuf_mb
);
99 sp
->userFlags
|= eFwdReset
; /* Set forward reset received Flag */
101 mp
= gbuf_alloc(sizeof(struct adspcmd
), PRI_HI
);
102 pb
= (struct adspcmd
*)gbuf_rptr(mp
);
103 gbuf_winc(mp
,sizeof(struct adspcmd
));
107 pb
->csCode
= dspReset
;
110 sp
->userFlags
&= ~eFwdReset
;
113 if (LTE(pktFirstByteSeq
, hi
)) {
114 sp
->sendCtl
|= B_CTL_FRESETACK
; /* Ack it if it's OK, or a duplicate */
118 ATENABLE(s
, sp
->lock
);
126 * We just got a Forward Reset Acknowledgement packet
128 * Called with interrupts OFF
132 * Pointer to ADSP header,
134 * Returns 1 if packet was ignored
136 int RXFResetAck(sp
, f
) /* (CCBPtr sp, ADSP_FRAMEPtr f) */
140 unsigned int PktNextRecvSeq
;
143 if (sp
->frpb
== 0) /* Not expecting frwd reset Ack packet */
146 ATDISABLE(s
, sp
->lock
);
147 PktNextRecvSeq
= netdw(UAL_VALUE(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
;
174 ATENABLE(s
, sp
->lock
);
183 * --> ccbRefNum refnum of connection end
189 * errRefNum bad connection refnum
190 * errState connection is not open
191 * errAborted request aborted by Remove or Close call
193 int adspReset(sp
, pb
) /* (DSPPBPtr pb) */
199 register struct adspcmd
*rpb
;
202 pb
->ioResult
= errRefNum
;
206 if (sp
->state
!= sOpen
) {
207 pb
->ioResult
= errState
;
211 ATDISABLE(s
, sp
->lock
);
213 while (mp
= sp
->sbuf_mb
) { /* clear the send queue */
214 sp
->sbuf_mb
= gbuf_next(mp
);
218 gbuf_freem(sp
->csbuf_mb
);
223 sp
->sendCtl
|= B_CTL_FRESET
;
225 sp
->firstRtmtSeq
= sp
->sendSeq
; /* Reset sequence #'s */
226 if (mp
= gbuf_copym(pb
->mp
)) { /* copy the parameter block */
227 adspioc_ack(0, pb
->ioc
, pb
->gref
); /* release user */
228 rpb
= (struct adspcmd
*)gbuf_rptr(mp
);
229 rpb
->ioc
= 0; /* unlink copy */
232 qAddToEnd(&sp
->frpb
, rpb
);
233 /* Hold on to pb (will be completed when */
234 /* forward reset ack is received). */
235 } else { /* assume it will work... but keep no
236 * bookkeeping for it. yetch! */
237 adspioc_ack(0, pb
->ioc
, pb
->gref
);
239 ATENABLE(s
, sp
->lock
);