]> git.saurik.com Git - apple/xnu.git/blob - bsd/netat/adsp_reset.c
xnu-792.12.6.tar.gz
[apple/xnu.git] / bsd / netat / adsp_reset.c
1 /*
2 * Copyright (c) 2006 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 int s;
84
85 ATDISABLE(s, sp->lock);
86 pktFirstByteSeq = netdw(UAL_VALUE(f->pktFirstByteSeq));
87
88 hi = sp->recvSeq + CalcRecvWdw(sp);
89
90 /*
91 * Must do this with interrupts OFF
92 */
93 if (BETWEEN(sp->recvSeq, pktFirstByteSeq, hi)) /* Is this acceptable? */
94 {
95 sp->recvSeq = pktFirstByteSeq;
96 while (mp = sp->rbuf_mb) { /* clear the receive queue */
97 sp->rbuf_mb = gbuf_next(mp);
98 gbuf_freem(mp);
99 }
100 if (sp->crbuf_mb) {
101 gbuf_freem(sp->crbuf_mb);
102 sp->crbuf_mb = 0;
103 }
104 sp->rData = 0;
105 sp->rbufFull = 0;
106 sp->userFlags |= eFwdReset; /* Set forward reset received Flag */
107
108 mp = gbuf_alloc(sizeof(struct adspcmd), PRI_HI);
109 pb = (struct adspcmd *)gbuf_rptr(mp);
110 gbuf_winc(mp,sizeof(struct adspcmd));
111 pb->ioc = 0;
112 pb->mp = mp;
113
114 pb->csCode = dspReset;
115 pb->ioResult = 0;
116 completepb(sp, pb);
117 sp->userFlags &= ~eFwdReset;
118 }
119
120 if (LTE(pktFirstByteSeq, hi)) {
121 sp->sendCtl |= B_CTL_FRESETACK; /* Ack it if it's OK, or a duplicate */
122 sp->callSend = 1;
123 }
124
125 ATENABLE(s, sp->lock);
126 return 0;
127 }
128
129
130 /*
131 * RXFResetAck
132 *
133 * We just got a Forward Reset Acknowledgement packet
134 *
135 * Called with interrupts OFF
136 *
137 * INPUTS:
138 * stream pointer
139 * Pointer to ADSP header,
140 * OUTPUTS:
141 * Returns 1 if packet was ignored
142 */
143 int RXFResetAck(sp, f) /* (CCBPtr sp, ADSP_FRAMEPtr f) */
144 CCBPtr sp;
145 ADSP_FRAMEPtr f;
146 {
147 unsigned int PktNextRecvSeq;
148 int s;
149
150 if (sp->frpb == 0) /* Not expecting frwd reset Ack packet */
151 return 1;
152
153 ATDISABLE(s, sp->lock);
154 PktNextRecvSeq = netdw(UAL_VALUE(f->pktNextRecvSeq));
155
156 if (BETWEEN(sp->sendSeq, PktNextRecvSeq, sp->sendWdwSeq+1)) {
157 struct adspcmd *pb;
158
159 RemoveTimerElem(&adspGlobal.fastTimers, &sp->ResetTimer);
160 /* Remove timer */
161
162 /*
163 * Interrupts are OFF here while we muck with the linked list
164 */
165 pb = sp->frpb; /* Unlink copy of user's parameter block */
166 sp->frpb = (struct adspcmd *)pb->qLink;
167
168 pb->ioResult = 0;
169 completepb(sp, pb); /* complete(pb, 0); */
170
171 if (sp->state == sClosing) /* this ack may allow us to close... */
172 CheckOkToClose(sp);
173
174 if (sp->frpb) /* Another to send? */
175 {
176 sp->callSend = 1;
177 sp->sendCtl |= B_CTL_FRESET;
178 }
179 }
180
181 ATENABLE(s, sp->lock);
182 return 0;
183 }
184
185
186 /*
187 * dspReset
188 *
189 * INPUTS:
190 * --> ccbRefNum refnum of connection end
191 *
192 * OUTPUTS:
193 * none
194 *
195 * ERRORS:
196 * errRefNum bad connection refnum
197 * errState connection is not open
198 * errAborted request aborted by Remove or Close call
199 */
200 int adspReset(sp, pb) /* (DSPPBPtr pb) */
201 CCBPtr sp;
202 struct adspcmd *pb;
203 {
204 int s;
205 register gbuf_t *mp;
206 register struct adspcmd *rpb;
207
208 if (sp == 0) {
209 pb->ioResult = errRefNum;
210 return EINVAL;
211 }
212
213 if (sp->state != sOpen) {
214 pb->ioResult = errState;
215 return EINVAL;
216 }
217
218 ATDISABLE(s, sp->lock);
219
220 while (mp = sp->sbuf_mb) { /* clear the send queue */
221 sp->sbuf_mb = gbuf_next(mp);
222 gbuf_freem(mp);
223 }
224 if (sp->csbuf_mb) {
225 gbuf_freem(sp->csbuf_mb);
226 sp->csbuf_mb = 0;
227 }
228 sp->sData = 0;
229 sp->writeFlush = 0;
230 sp->sendCtl |= B_CTL_FRESET;
231
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 */
237 rpb->mp = mp;
238
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);
245 }
246 ATENABLE(s, sp->lock);
247
248 CheckSend(sp);
249 return STR_IGNORE;
250
251 }