]> git.saurik.com Git - apple/xnu.git/blame - bsd/netat/adsp_reset.c
xnu-792.25.20.tar.gz
[apple/xnu.git] / bsd / netat / adsp_reset.c
CommitLineData
1c79356b 1/*
5d5c5d0d
A
2 * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
3 *
6601e61a 4 * @APPLE_LICENSE_HEADER_START@
1c79356b 5 *
6601e61a
A
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.
8f6c56a5 11 *
6601e61a
A
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
8f6c56a5
A
14 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
15 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
6601e61a
A
16 * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
17 * License for the specific language governing rights and limitations
18 * under the License.
8f6c56a5 19 *
6601e61a 20 * @APPLE_LICENSE_HEADER_END@
1c79356b
A
21 */
22/*
23 * Reset.c
24 *
25 * From v01.15 07/11/90 mbs
26 */
27/*
28 * Change log:
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.
32 */
33
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>
40#include <sys/proc.h>
41#include <sys/filedesc.h>
42#include <sys/fcntl.h>
43#include <sys/mbuf.h>
44#include <sys/socket.h>
45#include <sys/time.h>
46
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>
53
54/*
55 * RXFReset
56 *
57 * We just got a Forward Reset Packet.
58 *
59 * Called with interrupts OFF
60 *
61 * INPUTS:
62 * stream pointer
63 * Pointer to ADSP header,
64 * OUTPUTS:
65 * Returns 1 if packet was ignored
66 */
67int RXFReset(sp, f) /* (CCBPtr sp, ADSP_FRAMEPtr f) */
68 CCBPtr sp;
69 ADSP_FRAMEPtr f;
70{
71 unsigned int pktFirstByteSeq;
72 unsigned int hi;
73 register gbuf_t *mp;
74 register struct adspcmd *pb;
1c79356b 75
0c530ab8 76 pktFirstByteSeq = UAL_VALUE_NTOH(f->pktFirstByteSeq);
1c79356b
A
77
78 hi = sp->recvSeq + CalcRecvWdw(sp);
79
80 /*
81 * Must do this with interrupts OFF
82 */
83 if (BETWEEN(sp->recvSeq, pktFirstByteSeq, hi)) /* Is this acceptable? */
84 {
85 sp->recvSeq = pktFirstByteSeq;
86 while (mp = sp->rbuf_mb) { /* clear the receive queue */
87 sp->rbuf_mb = gbuf_next(mp);
88 gbuf_freem(mp);
89 }
90 if (sp->crbuf_mb) {
91 gbuf_freem(sp->crbuf_mb);
92 sp->crbuf_mb = 0;
93 }
94 sp->rData = 0;
95 sp->rbufFull = 0;
96 sp->userFlags |= eFwdReset; /* Set forward reset received Flag */
97
98 mp = gbuf_alloc(sizeof(struct adspcmd), PRI_HI);
99 pb = (struct adspcmd *)gbuf_rptr(mp);
100 gbuf_winc(mp,sizeof(struct adspcmd));
101 pb->ioc = 0;
102 pb->mp = mp;
103
104 pb->csCode = dspReset;
105 pb->ioResult = 0;
106 completepb(sp, pb);
107 sp->userFlags &= ~eFwdReset;
108 }
109
110 if (LTE(pktFirstByteSeq, hi)) {
111 sp->sendCtl |= B_CTL_FRESETACK; /* Ack it if it's OK, or a duplicate */
112 sp->callSend = 1;
113 }
114
1c79356b
A
115 return 0;
116}
117
118
119/*
120 * RXFResetAck
121 *
122 * We just got a Forward Reset Acknowledgement packet
123 *
124 * Called with interrupts OFF
125 *
126 * INPUTS:
127 * stream pointer
128 * Pointer to ADSP header,
129 * OUTPUTS:
130 * Returns 1 if packet was ignored
131 */
132int RXFResetAck(sp, f) /* (CCBPtr sp, ADSP_FRAMEPtr f) */
133 CCBPtr sp;
134 ADSP_FRAMEPtr f;
135{
136 unsigned int PktNextRecvSeq;
1c79356b
A
137
138 if (sp->frpb == 0) /* Not expecting frwd reset Ack packet */
139 return 1;
140
0c530ab8 141 PktNextRecvSeq = UAL_VALUE_NTOH(f->pktNextRecvSeq);
1c79356b
A
142
143 if (BETWEEN(sp->sendSeq, PktNextRecvSeq, sp->sendWdwSeq+1)) {
144 struct adspcmd *pb;
145
146 RemoveTimerElem(&adspGlobal.fastTimers, &sp->ResetTimer);
147 /* Remove timer */
148
149 /*
150 * Interrupts are OFF here while we muck with the linked list
151 */
152 pb = sp->frpb; /* Unlink copy of user's parameter block */
153 sp->frpb = (struct adspcmd *)pb->qLink;
154
155 pb->ioResult = 0;
156 completepb(sp, pb); /* complete(pb, 0); */
157
158 if (sp->state == sClosing) /* this ack may allow us to close... */
159 CheckOkToClose(sp);
160
161 if (sp->frpb) /* Another to send? */
162 {
163 sp->callSend = 1;
164 sp->sendCtl |= B_CTL_FRESET;
165 }
166 }
167
1c79356b
A
168 return 0;
169}
170
171
172/*
173 * dspReset
174 *
175 * INPUTS:
176 * --> ccbRefNum refnum of connection end
177 *
178 * OUTPUTS:
179 * none
180 *
181 * ERRORS:
182 * errRefNum bad connection refnum
183 * errState connection is not open
184 * errAborted request aborted by Remove or Close call
185 */
186int adspReset(sp, pb) /* (DSPPBPtr pb) */
187 CCBPtr sp;
188 struct adspcmd *pb;
189{
1c79356b
A
190 register gbuf_t *mp;
191 register struct adspcmd *rpb;
192
193 if (sp == 0) {
194 pb->ioResult = errRefNum;
195 return EINVAL;
196 }
197
198 if (sp->state != sOpen) {
199 pb->ioResult = errState;
200 return EINVAL;
201 }
202
1c79356b
A
203
204 while (mp = sp->sbuf_mb) { /* clear the send queue */
205 sp->sbuf_mb = gbuf_next(mp);
206 gbuf_freem(mp);
207 }
208 if (sp->csbuf_mb) {
209 gbuf_freem(sp->csbuf_mb);
210 sp->csbuf_mb = 0;
211 }
212 sp->sData = 0;
213 sp->writeFlush = 0;
214 sp->sendCtl |= B_CTL_FRESET;
215
216 sp->firstRtmtSeq = sp->sendSeq; /* Reset sequence #'s */
217 if (mp = gbuf_copym(pb->mp)) { /* copy the parameter block */
218 adspioc_ack(0, pb->ioc, pb->gref); /* release user */
219 rpb = (struct adspcmd *)gbuf_rptr(mp);
220 rpb->ioc = 0; /* unlink copy */
221 rpb->mp = mp;
222
223 qAddToEnd(&sp->frpb, rpb);
224 /* Hold on to pb (will be completed when */
225 /* forward reset ack is received). */
226 } else { /* assume it will work... but keep no
227 * bookkeeping for it. yetch! */
228 adspioc_ack(0, pb->ioc, pb->gref);
229 }
1c79356b
A
230
231 CheckSend(sp);
232 return STR_IGNORE;
233
234}