2 * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
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.
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
14 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
15 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
17 * License for the specific language governing rights and limitations
20 * @APPLE_LICENSE_HEADER_END@
22 /* Modified for MP, 1996 by Tuyen Nguyen */
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.
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>
38 #include <sys/filedesc.h>
39 #include <sys/fcntl.h>
41 #include <sys/socket.h>
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>
50 /*### MacOSX MCLBYTE is 2048, not 4096 like AIX */
51 #define TRPS_PER_BLK 16
53 gbuf_t
*atp_resource_m
= 0;
54 extern caddr_t atp_free_cluster_list
;
55 extern void atp_delete_free_clusters();
57 struct atp_trans
*atp_trans_alloc(atp
)
58 struct atp_state
*atp
;
62 register struct atp_trans
*trp
, *trp_array
;
64 if (atp_trans_free_list
== 0) {
65 if ((m
= gbuf_alloc(TRPS_PER_BLK
*sizeof(struct atp_trans
),PRI_HI
)) == 0)
66 return (struct atp_trans
*)0;
67 bzero(gbuf_rptr(m
), TRPS_PER_BLK
*sizeof(struct atp_trans
));
68 trp_array
= (struct atp_trans
*)gbuf_rptr(m
);
69 for (i
=0; i
< TRPS_PER_BLK
-1; i
++)
70 trp_array
[i
].tr_list
.next
= (struct atp_trans
*)&trp_array
[i
+1];
71 gbuf_cont(m
) = atp_resource_m
;
73 trp_array
[i
].tr_list
.next
= atp_trans_free_list
;
74 atp_trans_free_list
= (struct atp_trans
*)&trp_array
[0];
77 trp
= atp_trans_free_list
;
78 atp_trans_free_list
= trp
->tr_list
.next
;
80 trp
->tr_state
= TRANS_TIMEOUT
;
81 trp
->tr_local_node
= 0;
82 ATEVENTINIT(trp
->tr_event
);
84 dPrintf(D_M_ATP_LOW
, D_L_TRACE
,
85 ("atp_trans_alloc(0x%x): alloc'd trp 0x%x\n",
86 (u_int
) atp
, (u_int
) trp
));
88 } /* atp_trans_alloc */
91 * tcb free routine - if modules are waiting schedule them
92 * always called at 'lock'
95 void atp_trans_free(trp
)
96 register struct atp_trans
*trp
;
100 trp
->tr_list
.next
= atp_trans_free_list
;
101 atp_trans_free_list
= trp
;
105 * This routine allocates a rcb, if none are available it makes sure the
106 * the write service routine will be called when one is
107 * always called at 'lock'
110 struct atp_rcb
*atp_rcb_alloc(atp
)
111 struct atp_state
*atp
;
113 register struct atp_rcb
*rcbp
;
115 if ((rcbp
= atp_rcb_free_list
) != NULL
) {
116 atp_rcb_free_list
= rcbp
->rc_list
.next
;
117 rcbp
->rc_queue
= atp
;
119 rcbp
->rc_local_node
= 0;
121 dPrintf(D_M_ATP_LOW
, D_L_TRACE
,
122 ("atp_rcb_alloc: allocated rcbp 0x%x\n", (u_int
) rcbp
));
127 * Here we free rcbs, if required reschedule other people waiting for them
128 * always called at 'lock'
131 void atp_rcb_free(rcbp
)
132 register struct atp_rcb
*rcbp
;
134 register struct atp_state
*atp
;
136 register int rc_state
;
138 dPrintf(D_M_ATP_LOW
, D_L_TRACE
,
139 ("atp_rcb_free: freeing rcbp 0x%x\n", (u_int
) rcbp
));
140 atp
= rcbp
->rc_queue
;
141 if ((rc_state
= rcbp
->rc_state
) == -1) {
142 dPrintf(D_M_ATP
, D_L_WARNING
,
143 ("atp_rcb_free(%d): tid=%d,loc=%d,rem=%d\n",
145 rcbp
->rc_socket
.socket
, atp
->atp_socket_no
));
152 if (rcbp
->rc_timestamp
) {
153 extern struct atp_rcb_qhead atp_need_rel
;
155 rcbp
->rc_timestamp
= 0;
156 ATP_Q_REMOVE(atp_need_rel
, rcbp
, rc_tlist
);
157 rcbp
->rc_tlist
.prev
= NULL
;
158 rcbp
->rc_tlist
.next
= NULL
;
162 gbuf_freem(rcbp
->rc_xmt
); /* *** bad free is the second mbuf in this chain *** */
164 for (i
=0; i
< rcbp
->rc_pktcnt
; i
++)
167 if (atp_free_cluster_list
)
168 atp_delete_free_clusters();
169 if (rc_state
!= RCB_UNQUEUED
) {
170 if (rc_state
== RCB_PENDING
) {
171 ATP_Q_REMOVE(atp
->atp_attached
, rcbp
, rc_list
);
173 ATP_Q_REMOVE(atp
->atp_rcb
, rcbp
, rc_list
);
176 if (rcbp
->rc_ioctl
) {
177 gbuf_freem(rcbp
->rc_ioctl
);
178 rcbp
->rc_ioctl
= NULL
;
180 rcbp
->rc_list
.next
= atp_rcb_free_list
;
181 atp_rcb_free_list
= rcbp
;