]>
git.saurik.com Git - apple/xnu.git/blob - bsd/netat/adsp_reset.c
2 * Copyright (c) 2006 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
;
85 ATDISABLE(s
, sp
->lock
);
86 pktFirstByteSeq
= netdw(UAL_VALUE(f
->pktFirstByteSeq
));
88 hi
= sp
->recvSeq
+ CalcRecvWdw(sp
);
91 * Must do this with interrupts OFF
93 if (BETWEEN(sp
->recvSeq
, pktFirstByteSeq
, hi
)) /* Is this acceptable? */
95 sp
->recvSeq
= pktFirstByteSeq
;
96 while (mp
= sp
->rbuf_mb
) { /* clear the receive queue */
97 sp
->rbuf_mb
= gbuf_next(mp
);
101 gbuf_freem(sp
->crbuf_mb
);
106 sp
->userFlags
|= eFwdReset
; /* Set forward reset received Flag */
108 mp
= gbuf_alloc(sizeof(struct adspcmd
), PRI_HI
);
109 pb
= (struct adspcmd
*)gbuf_rptr(mp
);
110 gbuf_winc(mp
,sizeof(struct adspcmd
));
114 pb
->csCode
= dspReset
;
117 sp
->userFlags
&= ~eFwdReset
;
120 if (LTE(pktFirstByteSeq
, hi
)) {
121 sp
->sendCtl
|= B_CTL_FRESETACK
; /* Ack it if it's OK, or a duplicate */
125 ATENABLE(s
, sp
->lock
);
133 * We just got a Forward Reset Acknowledgement packet
135 * Called with interrupts OFF
139 * Pointer to ADSP header,
141 * Returns 1 if packet was ignored
143 int RXFResetAck(sp
, f
) /* (CCBPtr sp, ADSP_FRAMEPtr f) */
147 unsigned int PktNextRecvSeq
;
150 if (sp
->frpb
== 0) /* Not expecting frwd reset Ack packet */
153 ATDISABLE(s
, sp
->lock
);
154 PktNextRecvSeq
= netdw(UAL_VALUE(f
->pktNextRecvSeq
));
156 if (BETWEEN(sp
->sendSeq
, PktNextRecvSeq
, sp
->sendWdwSeq
+1)) {
159 RemoveTimerElem(&adspGlobal
.fastTimers
, &sp
->ResetTimer
);
163 * Interrupts are OFF here while we muck with the linked list
165 pb
= sp
->frpb
; /* Unlink copy of user's parameter block */
166 sp
->frpb
= (struct adspcmd
*)pb
->qLink
;
169 completepb(sp
, pb
); /* complete(pb, 0); */
171 if (sp
->state
== sClosing
) /* this ack may allow us to close... */
174 if (sp
->frpb
) /* Another to send? */
177 sp
->sendCtl
|= B_CTL_FRESET
;
181 ATENABLE(s
, sp
->lock
);
190 * --> ccbRefNum refnum of connection end
196 * errRefNum bad connection refnum
197 * errState connection is not open
198 * errAborted request aborted by Remove or Close call
200 int adspReset(sp
, pb
) /* (DSPPBPtr pb) */
206 register struct adspcmd
*rpb
;
209 pb
->ioResult
= errRefNum
;
213 if (sp
->state
!= sOpen
) {
214 pb
->ioResult
= errState
;
218 ATDISABLE(s
, sp
->lock
);
220 while (mp
= sp
->sbuf_mb
) { /* clear the send queue */
221 sp
->sbuf_mb
= gbuf_next(mp
);
225 gbuf_freem(sp
->csbuf_mb
);
230 sp
->sendCtl
|= B_CTL_FRESET
;
232 sp
->firstRtmtSeq
= sp
->sendSeq
; /* Reset sequence #'s */
233 if (mp
= gbuf_copym(pb
->mp
)) { /* copy the parameter block */
234 adspioc_ack(0, pb
->ioc
, pb
->gref
); /* release user */
235 rpb
= (struct adspcmd
*)gbuf_rptr(mp
);
236 rpb
->ioc
= 0; /* unlink copy */
239 qAddToEnd(&sp
->frpb
, rpb
);
240 /* Hold on to pb (will be completed when */
241 /* forward reset ack is received). */
242 } else { /* assume it will work... but keep no
243 * bookkeeping for it. yetch! */
244 adspioc_ack(0, pb
->ioc
, pb
->gref
);
246 ATENABLE(s
, sp
->lock
);