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