]> git.saurik.com Git - apple/xnu.git/blob - bsd/netat/adsp_reset.c
296b73c26f470ecabcf0b336422773947932584f
[apple/xnu.git] / bsd / netat / adsp_reset.c
1 /*
2 * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
3 *
4 * @APPLE_LICENSE_OSREFERENCE_HEADER_START@
5 *
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
14 * agreement.
15 *
16 * Please obtain a copy of the License at
17 * http://www.opensource.apple.com/apsl/ and read it before using this
18 * file.
19 *
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.
27 *
28 * @APPLE_LICENSE_OSREFERENCE_HEADER_END@
29 */
30 /*
31 * Reset.c
32 *
33 * From v01.15 07/11/90 mbs
34 */
35 /*
36 * Change log:
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.
40 */
41
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>
48 #include <sys/proc.h>
49 #include <sys/filedesc.h>
50 #include <sys/fcntl.h>
51 #include <sys/mbuf.h>
52 #include <sys/socket.h>
53 #include <sys/time.h>
54
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>
61
62 /*
63 * RXFReset
64 *
65 * We just got a Forward Reset Packet.
66 *
67 * Called with interrupts OFF
68 *
69 * INPUTS:
70 * stream pointer
71 * Pointer to ADSP header,
72 * OUTPUTS:
73 * Returns 1 if packet was ignored
74 */
75 int RXFReset(sp, f) /* (CCBPtr sp, ADSP_FRAMEPtr f) */
76 CCBPtr sp;
77 ADSP_FRAMEPtr f;
78 {
79 unsigned int pktFirstByteSeq;
80 unsigned int hi;
81 register gbuf_t *mp;
82 register struct adspcmd *pb;
83
84 pktFirstByteSeq = UAL_VALUE_NTOH(f->pktFirstByteSeq);
85
86 hi = sp->recvSeq + CalcRecvWdw(sp);
87
88 /*
89 * Must do this with interrupts OFF
90 */
91 if (BETWEEN(sp->recvSeq, pktFirstByteSeq, hi)) /* Is this acceptable? */
92 {
93 sp->recvSeq = pktFirstByteSeq;
94 while (mp = sp->rbuf_mb) { /* clear the receive queue */
95 sp->rbuf_mb = gbuf_next(mp);
96 gbuf_freem(mp);
97 }
98 if (sp->crbuf_mb) {
99 gbuf_freem(sp->crbuf_mb);
100 sp->crbuf_mb = 0;
101 }
102 sp->rData = 0;
103 sp->rbufFull = 0;
104 sp->userFlags |= eFwdReset; /* Set forward reset received Flag */
105
106 mp = gbuf_alloc(sizeof(struct adspcmd), PRI_HI);
107 pb = (struct adspcmd *)gbuf_rptr(mp);
108 gbuf_winc(mp,sizeof(struct adspcmd));
109 pb->ioc = 0;
110 pb->mp = mp;
111
112 pb->csCode = dspReset;
113 pb->ioResult = 0;
114 completepb(sp, pb);
115 sp->userFlags &= ~eFwdReset;
116 }
117
118 if (LTE(pktFirstByteSeq, hi)) {
119 sp->sendCtl |= B_CTL_FRESETACK; /* Ack it if it's OK, or a duplicate */
120 sp->callSend = 1;
121 }
122
123 return 0;
124 }
125
126
127 /*
128 * RXFResetAck
129 *
130 * We just got a Forward Reset Acknowledgement packet
131 *
132 * Called with interrupts OFF
133 *
134 * INPUTS:
135 * stream pointer
136 * Pointer to ADSP header,
137 * OUTPUTS:
138 * Returns 1 if packet was ignored
139 */
140 int RXFResetAck(sp, f) /* (CCBPtr sp, ADSP_FRAMEPtr f) */
141 CCBPtr sp;
142 ADSP_FRAMEPtr f;
143 {
144 unsigned int PktNextRecvSeq;
145
146 if (sp->frpb == 0) /* Not expecting frwd reset Ack packet */
147 return 1;
148
149 PktNextRecvSeq = UAL_VALUE_NTOH(f->pktNextRecvSeq);
150
151 if (BETWEEN(sp->sendSeq, PktNextRecvSeq, sp->sendWdwSeq+1)) {
152 struct adspcmd *pb;
153
154 RemoveTimerElem(&adspGlobal.fastTimers, &sp->ResetTimer);
155 /* Remove timer */
156
157 /*
158 * Interrupts are OFF here while we muck with the linked list
159 */
160 pb = sp->frpb; /* Unlink copy of user's parameter block */
161 sp->frpb = (struct adspcmd *)pb->qLink;
162
163 pb->ioResult = 0;
164 completepb(sp, pb); /* complete(pb, 0); */
165
166 if (sp->state == sClosing) /* this ack may allow us to close... */
167 CheckOkToClose(sp);
168
169 if (sp->frpb) /* Another to send? */
170 {
171 sp->callSend = 1;
172 sp->sendCtl |= B_CTL_FRESET;
173 }
174 }
175
176 return 0;
177 }
178
179
180 /*
181 * dspReset
182 *
183 * INPUTS:
184 * --> ccbRefNum refnum of connection end
185 *
186 * OUTPUTS:
187 * none
188 *
189 * ERRORS:
190 * errRefNum bad connection refnum
191 * errState connection is not open
192 * errAborted request aborted by Remove or Close call
193 */
194 int adspReset(sp, pb) /* (DSPPBPtr pb) */
195 CCBPtr sp;
196 struct adspcmd *pb;
197 {
198 register gbuf_t *mp;
199 register struct adspcmd *rpb;
200
201 if (sp == 0) {
202 pb->ioResult = errRefNum;
203 return EINVAL;
204 }
205
206 if (sp->state != sOpen) {
207 pb->ioResult = errState;
208 return EINVAL;
209 }
210
211
212 while (mp = sp->sbuf_mb) { /* clear the send queue */
213 sp->sbuf_mb = gbuf_next(mp);
214 gbuf_freem(mp);
215 }
216 if (sp->csbuf_mb) {
217 gbuf_freem(sp->csbuf_mb);
218 sp->csbuf_mb = 0;
219 }
220 sp->sData = 0;
221 sp->writeFlush = 0;
222 sp->sendCtl |= B_CTL_FRESET;
223
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 */
229 rpb->mp = mp;
230
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);
237 }
238
239 CheckSend(sp);
240 return STR_IGNORE;
241
242 }