]> git.saurik.com Git - apple/xnu.git/blob - bsd/netat/adsp_Timer.c
xnu-792.13.8.tar.gz
[apple/xnu.git] / bsd / netat / adsp_Timer.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 * Copyright (c) 1990, 1996-1998 Apple Computer, Inc.
32 * All Rights Reserved.
33 */
34
35 /*
36 * Timer.c
37 *
38 * From v01.12 06/22/90 mbs
39 * Modified for MP, 1996 by Tuyen Nguyen
40 * Modified, April 9, 1997 by Tuyen Nguyen for MacOSX.
41 */
42
43 #include <sys/errno.h>
44 #include <sys/types.h>
45 #include <sys/param.h>
46 #include <machine/spl.h>
47 #include <sys/systm.h>
48 #include <sys/kernel.h>
49 #include <sys/proc.h>
50 #include <sys/filedesc.h>
51 #include <sys/fcntl.h>
52 #include <sys/mbuf.h>
53 #include <sys/socket.h>
54 #include <sys/time.h>
55
56 #include <netat/sysglue.h>
57 #include <netat/appletalk.h>
58 #include <netat/at_pcb.h>
59 #include <netat/debug.h>
60 #include <netat/adsp.h>
61 #include <netat/adsp_internal.h>
62
63 void TimerTick();
64
65 /*
66 * TrashSession
67 *
68 * Cleanly abort a session that might be open. Called if probe timer expires,
69 * or from AppleTalk event handler (close or network gone away)
70 *
71 * Only call if the session is active (I.e. not for closed or listeners)
72 *
73 * INPUTS:
74 * session pointer
75 * OUTPUTS:
76 * none
77 */
78 void TrashSession(sp) /* (CCBPtr sp) */
79 CCBPtr sp;
80 {
81
82 sp->userFlags |= eTearDown;
83 sp->removing = 1;
84 sp->state = sClosed;
85
86 DoClose(sp, errAborted, 1);
87 }
88
89
90 /*
91 * DoTimerElem
92 *
93 * INPUTS:
94 *
95 * OUTPUTS:
96 *
97 */
98 void DoTimerElem(t) /* (TimerElemPtr t) */
99 TimerElemPtr t;
100 {
101 CCBPtr sp;
102
103 sp = (CCBPtr)((Ptr)t - t->type); /* Recover stream pointer for this guy */
104
105 if (t->type == kFlushTimerType) { /* flush write data time just fired */
106 if (sp->sData) { /* If there's any data, flush it. */
107 sp->writeFlush = 1;
108 goto send;
109 }
110 } else if (t->type == kRetryTimerType) {
111 if (sp->waitingAck) {
112
113 sp->waitingAck = 0;
114 sp->sendSeq = sp->firstRtmtSeq;
115 sp->pktSendCnt = 0;
116 sp->resentData = 1; /* Had to resend data */
117 sp->noXmitFlow = 1; /* Don't incr. max packets. */
118
119 if ((sp->pktSendMax /= 2) == 0) /* Back off on max # packets
120 * sent */
121 sp->pktSendMax = 1;
122
123 if ((sp->roundTrip *= 2) > sp->probeInterval)
124 sp->roundTrip = sp->probeInterval;
125 sp->rtmtInterval = sp->roundTrip + ((short)2 *
126 (short)sp->deviation);
127 goto send;
128 }
129 } else if (t->type == kAttnTimerType) {
130 if (sp->sapb) { /* Unacknowledged attn pkt */
131 sp->sendAttnData = 1;
132 goto send;
133 }
134 } else if (t->type == kResetTimerType) {
135 if (sp->frpb) { /* Unacknowledged forward reset */
136 sp->sendCtl |= B_CTL_FRESET;
137 goto send;
138 }
139 } else if (t->type == kProbeTimerType) {
140 if (sp->state == sOpen || sp->state == sClosing) {
141 if (--sp->probeCntr == 0) { /* Connection died */
142 TrashSession(sp);
143 return;
144 } else {
145 InsertTimerElem(&adspGlobal.slowTimers, &sp->ProbeTimer,
146 sp->probeInterval);
147 sp->sendCtl |= B_CTL_PROBE;
148 goto send;
149 }
150 } else if (sp->state == sOpening) {
151 if ((sp->openState == O_STATE_OPENWAIT) ||
152 (sp->openState == O_STATE_ESTABLISHED))
153 {
154 if (--sp->openRetrys == 0) { /* Oops, didn't open */
155 sp->state = sClosed;
156 DoClose(sp, errOpening, 1);
157 return;
158 } /* open failed */
159 else /* Send packet again */
160 {
161 sp->sendCtl |= (sp->openState == O_STATE_OPENWAIT) ?
162 B_CTL_OREQ : B_CTL_OREQACK;
163 goto send;
164 }
165 } /* we're opening */
166 }
167 }
168
169 else {
170 dPrintf(D_M_ADSP, D_L_ERROR, ("DoTimerElem:Unknown timer type!\n"));
171 }
172
173 return;
174
175 send:
176 CheckSend(sp);
177 }
178
179 void TimerTick_funnel(void *arg)
180 {
181 atalk_lock();
182 TimerTick();
183 atalk_unlock();
184 }
185
186 static StopTimer;
187
188 /*
189 * TimerTick
190 *
191 * Called 6 times per second
192 * INPUTS:
193 *
194 * OUTPUTS:
195 *
196 */
197 void TimerTick() /* (void) */
198 {
199
200 if (StopTimer) {
201 return;
202 }
203 TimerQueueTick(&adspGlobal.slowTimers);
204 TimerQueueTick(&adspGlobal.fastTimers);
205 timeout(TimerTick_funnel, (caddr_t)0, HZ/6);
206 }
207
208 void TimerStop()
209 {
210 StopTimer = 1;
211 untimeout(TimerTick_funnel, (caddr_t) 0);
212 }