]>
Commit | Line | Data |
---|---|---|
1c79356b A |
1 | /* |
2 | * Copyright (c) 2000 Apple Computer, Inc. All rights reserved. | |
3 | * | |
4 | * @APPLE_LICENSE_HEADER_START@ | |
5 | * | |
de355530 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. | |
1c79356b | 11 | * |
de355530 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 | |
1c79356b A |
14 | * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, |
15 | * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, | |
de355530 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. | |
1c79356b A |
19 | * |
20 | * @APPLE_LICENSE_HEADER_END@ | |
21 | */ | |
22 | /* Modified for MP, 1996 by Tuyen Nguyen */ | |
23 | /* | |
24 | * tcb (transaction) allocation routine. If no transaction data structure | |
25 | * is available then put the module on a queue of modules waiting | |
26 | * for transaction structures. When a tcb is available it will be | |
27 | * removed from this list and its write queue will be scheduled. | |
28 | * Version 1.4 of atp_alloc.c on 89/02/09 17:53:01 | |
29 | * Modified, March 17, 1997 by Tuyen Nguyen for MacOSX. | |
30 | */ | |
31 | #include <sys/errno.h> | |
32 | #include <sys/types.h> | |
33 | #include <sys/param.h> | |
34 | #include <machine/spl.h> | |
35 | #include <sys/systm.h> | |
36 | #include <sys/kernel.h> | |
37 | #include <sys/proc.h> | |
38 | #include <sys/filedesc.h> | |
39 | #include <sys/fcntl.h> | |
40 | #include <sys/mbuf.h> | |
41 | #include <sys/socket.h> | |
42 | ||
43 | #include <netat/sysglue.h> | |
44 | #include <netat/appletalk.h> | |
45 | #include <netat/ddp.h> | |
46 | #include <netat/debug.h> | |
47 | #include <netat/at_pcb.h> | |
48 | #include <netat/atp.h> | |
49 | ||
50 | /*### MacOSX MCLBYTE is 2048, not 4096 like AIX */ | |
51 | #define TRPS_PER_BLK 16 | |
52 | ||
53 | gbuf_t *atp_resource_m = 0; | |
54 | extern atlock_t atpgen_lock; | |
0b4e3aa0 A |
55 | extern caddr_t atp_free_cluster_list; |
56 | extern void atp_delete_free_clusters(); | |
1c79356b A |
57 | |
58 | struct atp_trans *atp_trans_alloc(atp) | |
59 | struct atp_state *atp; | |
60 | { | |
61 | int s; | |
62 | int i; | |
63 | gbuf_t *m; | |
64 | register struct atp_trans *trp, *trp_array; | |
65 | ||
66 | ATDISABLE(s, atpgen_lock); | |
67 | if (atp_trans_free_list == 0) { | |
68 | ATENABLE(s, atpgen_lock); | |
69 | if ((m = gbuf_alloc(TRPS_PER_BLK*sizeof(struct atp_trans),PRI_HI)) == 0) | |
70 | return (struct atp_trans *)0; | |
71 | bzero(gbuf_rptr(m), TRPS_PER_BLK*sizeof(struct atp_trans)); | |
72 | trp_array = (struct atp_trans *)gbuf_rptr(m); | |
73 | for (i=0; i < TRPS_PER_BLK-1; i++) | |
74 | trp_array[i].tr_list.next = (struct atp_trans *)&trp_array[i+1]; | |
75 | ATDISABLE(s, atpgen_lock); | |
76 | gbuf_cont(m) = atp_resource_m; | |
77 | atp_resource_m = m; | |
78 | trp_array[i].tr_list.next = atp_trans_free_list; | |
79 | atp_trans_free_list = (struct atp_trans *)&trp_array[0]; | |
80 | } | |
81 | ||
82 | trp = atp_trans_free_list; | |
83 | atp_trans_free_list = trp->tr_list.next; | |
84 | ATENABLE(s, atpgen_lock); | |
85 | trp->tr_queue = atp; | |
86 | trp->tr_state = TRANS_TIMEOUT; | |
87 | trp->tr_local_node = 0; | |
88 | ATLOCKINIT(trp->tr_lock); | |
89 | ATEVENTINIT(trp->tr_event); | |
90 | ||
91 | dPrintf(D_M_ATP_LOW, D_L_TRACE, | |
92 | ("atp_trans_alloc(0x%x): alloc'd trp 0x%x\n", | |
93 | (u_int) atp, (u_int) trp)); | |
94 | return trp; | |
95 | } /* atp_trans_alloc */ | |
96 | ||
97 | /* | |
98 | * tcb free routine - if modules are waiting schedule them | |
99 | * always called at 'lock' | |
100 | */ | |
101 | ||
102 | void atp_trans_free(trp) | |
103 | register struct atp_trans *trp; | |
104 | { | |
105 | int s; | |
106 | ||
107 | ATDISABLE(s, atpgen_lock); | |
108 | trp->tr_queue = 0; | |
109 | trp->tr_list.next = atp_trans_free_list; | |
110 | atp_trans_free_list = trp; | |
111 | ATENABLE(s, atpgen_lock); | |
112 | } | |
113 | ||
114 | /* | |
115 | * This routine allocates a rcb, if none are available it makes sure the | |
116 | * the write service routine will be called when one is | |
117 | * always called at 'lock' | |
118 | */ | |
119 | ||
120 | struct atp_rcb *atp_rcb_alloc(atp) | |
121 | struct atp_state *atp; | |
122 | { | |
123 | register struct atp_rcb *rcbp; | |
124 | int s; | |
125 | ||
126 | ATDISABLE(s, atpgen_lock); | |
127 | if ((rcbp = atp_rcb_free_list) != NULL) { | |
128 | atp_rcb_free_list = rcbp->rc_list.next; | |
129 | rcbp->rc_queue = atp; | |
130 | rcbp->rc_pktcnt = 0; | |
131 | rcbp->rc_local_node = 0; | |
132 | } | |
133 | ATENABLE(s, atpgen_lock); | |
134 | dPrintf(D_M_ATP_LOW, D_L_TRACE, | |
135 | ("atp_rcb_alloc: allocated rcbp 0x%x\n", (u_int) rcbp)); | |
136 | return(rcbp); | |
137 | } | |
138 | ||
139 | /* | |
140 | * Here we free rcbs, if required reschedule other people waiting for them | |
141 | * always called at 'lock' | |
142 | */ | |
143 | ||
144 | void atp_rcb_free(rcbp) | |
145 | register struct atp_rcb *rcbp; | |
146 | { | |
147 | register struct atp_state *atp; | |
148 | register int i; | |
149 | register int rc_state; | |
150 | int s; | |
151 | ||
152 | dPrintf(D_M_ATP_LOW, D_L_TRACE, | |
153 | ("atp_rcb_free: freeing rcbp 0x%x\n", (u_int) rcbp)); | |
154 | ATDISABLE(s, atpgen_lock); | |
155 | atp = rcbp->rc_queue; | |
156 | if ((rc_state = rcbp->rc_state) == -1) { | |
157 | ATENABLE(s, atpgen_lock); | |
158 | dPrintf(D_M_ATP, D_L_WARNING, | |
159 | ("atp_rcb_free(%d): tid=%d,loc=%d,rem=%d\n", | |
160 | 0, rcbp->rc_tid, | |
161 | rcbp->rc_socket.socket, atp->atp_socket_no)); | |
162 | return; | |
163 | } | |
164 | rcbp->rc_state = -1; | |
165 | rcbp->rc_xo = 0; | |
166 | rcbp->rc_queue = 0; | |
167 | ||
168 | if (rcbp->rc_timestamp) { | |
169 | extern struct atp_rcb_qhead atp_need_rel; | |
170 | ||
171 | rcbp->rc_timestamp = 0; | |
172 | ATP_Q_REMOVE(atp_need_rel, rcbp, rc_tlist); | |
173 | rcbp->rc_tlist.prev = NULL; | |
174 | rcbp->rc_tlist.next = NULL; | |
175 | } | |
176 | ||
177 | if (rcbp->rc_xmt) { | |
178 | gbuf_freem(rcbp->rc_xmt); /* *** bad free is the second mbuf in this chain *** */ | |
179 | rcbp->rc_xmt = NULL; | |
180 | for (i=0; i < rcbp->rc_pktcnt; i++) | |
181 | rcbp->rc_snd[i] = 0; | |
182 | } | |
0b4e3aa0 A |
183 | if (atp_free_cluster_list) |
184 | atp_delete_free_clusters(); | |
1c79356b A |
185 | if (rc_state != RCB_UNQUEUED) { |
186 | if (rc_state == RCB_PENDING) { | |
187 | ATP_Q_REMOVE(atp->atp_attached, rcbp, rc_list); | |
188 | } else { | |
189 | ATP_Q_REMOVE(atp->atp_rcb, rcbp, rc_list); | |
190 | } | |
191 | } | |
192 | if (rcbp->rc_ioctl) { | |
193 | gbuf_freem(rcbp->rc_ioctl); | |
194 | rcbp->rc_ioctl = NULL; | |
195 | } | |
196 | rcbp->rc_list.next = atp_rcb_free_list; | |
197 | atp_rcb_free_list = rcbp; | |
198 | ATENABLE(s, atpgen_lock); | |
199 | } |