]>
Commit | Line | Data |
---|---|---|
1 | /* | |
2 | * Copyright (c) 2000 Apple Computer, Inc. All rights reserved. | |
3 | * | |
4 | * @APPLE_LICENSE_HEADER_START@ | |
5 | * | |
6 | * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved. | |
7 | * | |
8 | * This file contains Original Code and/or Modifications of Original Code | |
9 | * as defined in and that are subject to the Apple Public Source License | |
10 | * Version 2.0 (the 'License'). You may not use this file except in | |
11 | * compliance with the License. Please obtain a copy of the License at | |
12 | * http://www.opensource.apple.com/apsl/ and read it before using this | |
13 | * file. | |
14 | * | |
15 | * The Original Code and all software distributed under the License are | |
16 | * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER | |
17 | * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, | |
18 | * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, | |
19 | * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. | |
20 | * Please see the License for the specific language governing rights and | |
21 | * limitations under the License. | |
22 | * | |
23 | * @APPLE_LICENSE_HEADER_END@ | |
24 | */ | |
25 | /* | |
26 | * Reset.c | |
27 | * | |
28 | * From v01.15 07/11/90 mbs | |
29 | */ | |
30 | /* | |
31 | * Change log: | |
32 | * 06/29/95 - Modified to handle flow control for writing (Tuyen Nguyen) | |
33 | * Modified for MP, 1996 by Tuyen Nguyen | |
34 | * Modified, April 9, 1997 by Tuyen Nguyen for MacOSX. | |
35 | */ | |
36 | ||
37 | #include <sys/errno.h> | |
38 | #include <sys/types.h> | |
39 | #include <sys/param.h> | |
40 | #include <machine/spl.h> | |
41 | #include <sys/systm.h> | |
42 | #include <sys/kernel.h> | |
43 | #include <sys/proc.h> | |
44 | #include <sys/filedesc.h> | |
45 | #include <sys/fcntl.h> | |
46 | #include <sys/mbuf.h> | |
47 | #include <sys/socket.h> | |
48 | #include <sys/time.h> | |
49 | ||
50 | #include <netat/sysglue.h> | |
51 | #include <netat/appletalk.h> | |
52 | #include <netat/at_pcb.h> | |
53 | #include <netat/debug.h> | |
54 | #include <netat/adsp.h> | |
55 | #include <netat/adsp_internal.h> | |
56 | ||
57 | /* | |
58 | * RXFReset | |
59 | * | |
60 | * We just got a Forward Reset Packet. | |
61 | * | |
62 | * Called with interrupts OFF | |
63 | * | |
64 | * INPUTS: | |
65 | * stream pointer | |
66 | * Pointer to ADSP header, | |
67 | * OUTPUTS: | |
68 | * Returns 1 if packet was ignored | |
69 | */ | |
70 | int RXFReset(sp, f) /* (CCBPtr sp, ADSP_FRAMEPtr f) */ | |
71 | CCBPtr sp; | |
72 | ADSP_FRAMEPtr f; | |
73 | { | |
74 | unsigned int pktFirstByteSeq; | |
75 | unsigned int hi; | |
76 | register gbuf_t *mp; | |
77 | register struct adspcmd *pb; | |
78 | int s; | |
79 | ||
80 | ATDISABLE(s, sp->lock); | |
81 | pktFirstByteSeq = netdw(UAL_VALUE(f->pktFirstByteSeq)); | |
82 | ||
83 | hi = sp->recvSeq + CalcRecvWdw(sp); | |
84 | ||
85 | /* | |
86 | * Must do this with interrupts OFF | |
87 | */ | |
88 | if (BETWEEN(sp->recvSeq, pktFirstByteSeq, hi)) /* Is this acceptable? */ | |
89 | { | |
90 | sp->recvSeq = pktFirstByteSeq; | |
91 | while (mp = sp->rbuf_mb) { /* clear the receive queue */ | |
92 | sp->rbuf_mb = gbuf_next(mp); | |
93 | gbuf_freem(mp); | |
94 | } | |
95 | if (sp->crbuf_mb) { | |
96 | gbuf_freem(sp->crbuf_mb); | |
97 | sp->crbuf_mb = 0; | |
98 | } | |
99 | sp->rData = 0; | |
100 | sp->rbufFull = 0; | |
101 | sp->userFlags |= eFwdReset; /* Set forward reset received Flag */ | |
102 | ||
103 | mp = gbuf_alloc(sizeof(struct adspcmd), PRI_HI); | |
104 | pb = (struct adspcmd *)gbuf_rptr(mp); | |
105 | gbuf_winc(mp,sizeof(struct adspcmd)); | |
106 | pb->ioc = 0; | |
107 | pb->mp = mp; | |
108 | ||
109 | pb->csCode = dspReset; | |
110 | pb->ioResult = 0; | |
111 | completepb(sp, pb); | |
112 | sp->userFlags &= ~eFwdReset; | |
113 | } | |
114 | ||
115 | if (LTE(pktFirstByteSeq, hi)) { | |
116 | sp->sendCtl |= B_CTL_FRESETACK; /* Ack it if it's OK, or a duplicate */ | |
117 | sp->callSend = 1; | |
118 | } | |
119 | ||
120 | ATENABLE(s, sp->lock); | |
121 | return 0; | |
122 | } | |
123 | ||
124 | ||
125 | /* | |
126 | * RXFResetAck | |
127 | * | |
128 | * We just got a Forward Reset Acknowledgement packet | |
129 | * | |
130 | * Called with interrupts OFF | |
131 | * | |
132 | * INPUTS: | |
133 | * stream pointer | |
134 | * Pointer to ADSP header, | |
135 | * OUTPUTS: | |
136 | * Returns 1 if packet was ignored | |
137 | */ | |
138 | int RXFResetAck(sp, f) /* (CCBPtr sp, ADSP_FRAMEPtr f) */ | |
139 | CCBPtr sp; | |
140 | ADSP_FRAMEPtr f; | |
141 | { | |
142 | unsigned int PktNextRecvSeq; | |
143 | int s; | |
144 | ||
145 | if (sp->frpb == 0) /* Not expecting frwd reset Ack packet */ | |
146 | return 1; | |
147 | ||
148 | ATDISABLE(s, sp->lock); | |
149 | PktNextRecvSeq = netdw(UAL_VALUE(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 | ATENABLE(s, sp->lock); | |
177 | return 0; | |
178 | } | |
179 | ||
180 | ||
181 | /* | |
182 | * dspReset | |
183 | * | |
184 | * INPUTS: | |
185 | * --> ccbRefNum refnum of connection end | |
186 | * | |
187 | * OUTPUTS: | |
188 | * none | |
189 | * | |
190 | * ERRORS: | |
191 | * errRefNum bad connection refnum | |
192 | * errState connection is not open | |
193 | * errAborted request aborted by Remove or Close call | |
194 | */ | |
195 | int adspReset(sp, pb) /* (DSPPBPtr pb) */ | |
196 | CCBPtr sp; | |
197 | struct adspcmd *pb; | |
198 | { | |
199 | int s; | |
200 | register gbuf_t *mp; | |
201 | register struct adspcmd *rpb; | |
202 | ||
203 | if (sp == 0) { | |
204 | pb->ioResult = errRefNum; | |
205 | return EINVAL; | |
206 | } | |
207 | ||
208 | if (sp->state != sOpen) { | |
209 | pb->ioResult = errState; | |
210 | return EINVAL; | |
211 | } | |
212 | ||
213 | ATDISABLE(s, sp->lock); | |
214 | ||
215 | while (mp = sp->sbuf_mb) { /* clear the send queue */ | |
216 | sp->sbuf_mb = gbuf_next(mp); | |
217 | gbuf_freem(mp); | |
218 | } | |
219 | if (sp->csbuf_mb) { | |
220 | gbuf_freem(sp->csbuf_mb); | |
221 | sp->csbuf_mb = 0; | |
222 | } | |
223 | sp->sData = 0; | |
224 | sp->writeFlush = 0; | |
225 | sp->sendCtl |= B_CTL_FRESET; | |
226 | ||
227 | sp->firstRtmtSeq = sp->sendSeq; /* Reset sequence #'s */ | |
228 | if (mp = gbuf_copym(pb->mp)) { /* copy the parameter block */ | |
229 | adspioc_ack(0, pb->ioc, pb->gref); /* release user */ | |
230 | rpb = (struct adspcmd *)gbuf_rptr(mp); | |
231 | rpb->ioc = 0; /* unlink copy */ | |
232 | rpb->mp = mp; | |
233 | ||
234 | qAddToEnd(&sp->frpb, rpb); | |
235 | /* Hold on to pb (will be completed when */ | |
236 | /* forward reset ack is received). */ | |
237 | } else { /* assume it will work... but keep no | |
238 | * bookkeeping for it. yetch! */ | |
239 | adspioc_ack(0, pb->ioc, pb->gref); | |
240 | } | |
241 | ATENABLE(s, sp->lock); | |
242 | ||
243 | CheckSend(sp); | |
244 | return STR_IGNORE; | |
245 | ||
246 | } |