]>
git.saurik.com Git - apple/xnu.git/blob - bsd/netat/adsp_reset.c
2 * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * The contents of this file constitute Original Code as defined in and
7 * are subject to the Apple Public Source License Version 1.1 (the
8 * "License"). You may not use this file except in compliance with the
9 * License. Please obtain a copy of the License at
10 * http://www.apple.com/publicsource and read it before using this file.
12 * This Original Code and all software distributed under the License are
13 * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
14 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
15 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
17 * License for the specific language governing rights and limitations
20 * @APPLE_LICENSE_HEADER_END@
25 * From v01.15 07/11/90 mbs
29 * 06/29/95 - Modified to handle flow control for writing (Tuyen Nguyen)
30 * Modified for MP, 1996 by Tuyen Nguyen
31 * Modified, April 9, 1997 by Tuyen Nguyen for MacOSX.
34 #include <sys/errno.h>
35 #include <sys/types.h>
36 #include <sys/param.h>
37 #include <machine/spl.h>
38 #include <sys/systm.h>
39 #include <sys/kernel.h>
41 #include <sys/filedesc.h>
42 #include <sys/fcntl.h>
44 #include <sys/socket.h>
47 #include <netat/sysglue.h>
48 #include <netat/appletalk.h>
49 #include <netat/at_pcb.h>
50 #include <netat/debug.h>
51 #include <netat/adsp.h>
52 #include <netat/adsp_internal.h>
57 * We just got a Forward Reset Packet.
59 * Called with interrupts OFF
63 * Pointer to ADSP header,
65 * Returns 1 if packet was ignored
67 int RXFReset(sp
, f
) /* (CCBPtr sp, ADSP_FRAMEPtr f) */
71 unsigned int pktFirstByteSeq
;
74 register struct adspcmd
*pb
;
77 ATDISABLE(s
, sp
->lock
);
78 pktFirstByteSeq
= netdw(UAL_VALUE(f
->pktFirstByteSeq
));
80 hi
= sp
->recvSeq
+ CalcRecvWdw(sp
);
83 * Must do this with interrupts OFF
85 if (BETWEEN(sp
->recvSeq
, pktFirstByteSeq
, hi
)) /* Is this acceptable? */
87 sp
->recvSeq
= pktFirstByteSeq
;
88 while (mp
= sp
->rbuf_mb
) { /* clear the receive queue */
89 sp
->rbuf_mb
= gbuf_next(mp
);
93 gbuf_freem(sp
->crbuf_mb
);
98 sp
->userFlags
|= eFwdReset
; /* Set forward reset received Flag */
100 mp
= gbuf_alloc(sizeof(struct adspcmd
), PRI_HI
);
101 pb
= (struct adspcmd
*)gbuf_rptr(mp
);
102 gbuf_winc(mp
,sizeof(struct adspcmd
));
106 pb
->csCode
= dspReset
;
109 sp
->userFlags
&= ~eFwdReset
;
112 if (LTE(pktFirstByteSeq
, hi
)) {
113 sp
->sendCtl
|= B_CTL_FRESETACK
; /* Ack it if it's OK, or a duplicate */
117 ATENABLE(s
, sp
->lock
);
125 * We just got a Forward Reset Acknowledgement packet
127 * Called with interrupts OFF
131 * Pointer to ADSP header,
133 * Returns 1 if packet was ignored
135 int RXFResetAck(sp
, f
) /* (CCBPtr sp, ADSP_FRAMEPtr f) */
139 unsigned int PktNextRecvSeq
;
142 if (sp
->frpb
== 0) /* Not expecting frwd reset Ack packet */
145 ATDISABLE(s
, sp
->lock
);
146 PktNextRecvSeq
= netdw(UAL_VALUE(f
->pktNextRecvSeq
));
148 if (BETWEEN(sp
->sendSeq
, PktNextRecvSeq
, sp
->sendWdwSeq
+1)) {
151 RemoveTimerElem(&adspGlobal
.fastTimers
, &sp
->ResetTimer
);
155 * Interrupts are OFF here while we muck with the linked list
157 pb
= sp
->frpb
; /* Unlink copy of user's parameter block */
158 sp
->frpb
= (struct adspcmd
*)pb
->qLink
;
161 completepb(sp
, pb
); /* complete(pb, 0); */
163 if (sp
->state
== sClosing
) /* this ack may allow us to close... */
166 if (sp
->frpb
) /* Another to send? */
169 sp
->sendCtl
|= B_CTL_FRESET
;
173 ATENABLE(s
, sp
->lock
);
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) */
198 register struct adspcmd
*rpb
;
201 pb
->ioResult
= errRefNum
;
205 if (sp
->state
!= sOpen
) {
206 pb
->ioResult
= errState
;
210 ATDISABLE(s
, sp
->lock
);
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
);
238 ATENABLE(s
, sp
->lock
);