Loading...
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 | /* * Copyright (c) 2000 Apple Computer, Inc. All rights reserved. * * @APPLE_LICENSE_HEADER_START@ * * The contents of this file constitute Original Code as defined in and * are subject to the Apple Public Source License Version 1.1 (the * "License"). You may not use this file except in compliance with the * License. Please obtain a copy of the License at * http://www.apple.com/publicsource and read it before using this file. * * This Original Code and all software distributed under the License are * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the * License for the specific language governing rights and limitations * under the License. * * @APPLE_LICENSE_HEADER_END@ */ /* * Copyright (c) 1996-1998 Apple Computer, Inc. * All Rights Reserved. */ /* Modified for MP, 1996 by Tuyen Nguyen * Modified, March 17, 1997 by Tuyen Nguyen for MacOSX. */ #define ATP_DECLARE #include <sys/errno.h> #include <sys/types.h> #include <sys/param.h> #include <machine/spl.h> #include <sys/systm.h> #include <sys/kernel.h> #include <sys/proc.h> #include <sys/filedesc.h> #include <sys/fcntl.h> #include <sys/mbuf.h> #include <sys/ioctl.h> #include <sys/malloc.h> #include <sys/socket.h> #include <vm/vm_kern.h> /* for kernel_map */ #include <netat/sysglue.h> #include <netat/appletalk.h> #include <netat/ddp.h> #include <netat/at_pcb.h> #include <netat/atp.h> #include <netat/debug.h> /* * The init routine creates all the free lists * Version 1.4 of atp_open.c on 89/02/09 17:53:11 */ int atp_inited = 0; struct atp_rcb_qhead atp_need_rel; atlock_t atpall_lock; atlock_t atptmo_lock; atlock_t atpgen_lock; /**********/ int atp_pidM[256]; gref_t *atp_inputQ[256]; struct atp_state *atp_used_list; int atp_input(mp) gbuf_t *mp; { register gref_t *gref; switch (gbuf_type(mp)) { case MSG_DATA: gref = atp_inputQ[((at_ddp_t *)gbuf_rptr(mp))->dst_socket]; if ((gref == 0) || (gref == (gref_t *)1)) { dPrintf(D_M_ATP, D_L_WARNING, ("atp_input: no socket, skt=%d\n", ((at_ddp_t *)gbuf_rptr(mp))->dst_socket)); gbuf_freem(mp); return 0; } break; case MSG_IOCACK: case MSG_IOCNAK: gref = (gref_t *)((ioc_t *)gbuf_rptr(mp))->ioc_private; break; case MSG_IOCTL: default: dPrintf(D_M_ATP, D_L_WARNING, ("atp_input: unknown msg, type=%d\n", gbuf_type(mp))); gbuf_freem(mp); return 0; } atp_rput(gref, mp); return 0; } /**********/ void atp_init() { int i; if (!atp_inited) { atp_inited = 1; atp_used_list = 0; atp_trans_abort.head = NULL; atp_trans_abort.tail = NULL; atp_need_rel.head = NULL; atp_need_rel.tail = NULL; bzero(atp_inputQ, sizeof(atp_inputQ)); bzero(atp_pidM, sizeof(atp_pidM)); asp_init(); } } /* * The open routine allocates a state structure */ /*ARGSUSED*/ int atp_open(gref, flag) gref_t *gref; int flag; { register struct atp_state *atp; register int s, i; vm_offset_t temp; /* * Allocate and init state and reply control block lists * if this is the first open */ if (atp_rcb_data == NULL) { if (kmem_alloc(kernel_map, &temp, sizeof(struct atp_rcb) * NATP_RCB) != KERN_SUCCESS) return(ENOMEM); if (atp_rcb_data == NULL) { bzero((caddr_t)temp, sizeof(struct atp_rcb) * NATP_RCB); atp_rcb_data = (struct atp_rcb*)temp; for (i = 0; i < NATP_RCB; i++) { atp_rcb_data[i].rc_list.next = atp_rcb_free_list; atp_rcb_free_list = &atp_rcb_data[i]; } } else kmem_free(kernel_map, temp, sizeof(struct atp_rcb) * NATP_RCB); /* already allocated by another process */ } if (atp_state_data == NULL) { if (kmem_alloc(kernel_map, &temp, sizeof(struct atp_state) * NATP_STATE) != KERN_SUCCESS) return(ENOMEM); if (atp_state_data == NULL) { bzero((caddr_t)temp, sizeof(struct atp_state) * NATP_STATE); atp_state_data = (struct atp_state*) temp; for (i = 0; i < NATP_STATE; i++) { atp_state_data[i].atp_trans_waiting = atp_free_list; atp_free_list = &atp_state_data[i]; } } else kmem_free(kernel_map, temp, sizeof(struct atp_state) * NATP_STATE); } /* * If no atp structure available return failure */ ATDISABLE(s, atpall_lock); if ((atp = atp_free_list) == NULL) { ATENABLE(s, atpall_lock); return(EAGAIN); } /* * Update free list */ atp_free_list = atp->atp_trans_waiting; ATENABLE(s, atpall_lock); /* * Initialize the data structure */ atp->dflag = 0; atp->atp_trans_wait.head = NULL; atp->atp_trans_waiting = NULL; atp->atp_gref = gref; atp->atp_retry = 10; atp->atp_timeout = HZ/8; atp->atp_rcb_waiting = NULL; atp->atp_rcb.head = NULL; atp->atp_flags = T_MPSAFE; atp->atp_socket_no = -1; atp->atp_pid = gref->pid; atp->atp_msgq = 0; ATLOCKINIT(atp->atp_lock); ATLOCKINIT(atp->atp_delay_lock); ATEVENTINIT(atp->atp_event); ATEVENTINIT(atp->atp_delay_event); gref->info = (void *)atp; /* * Return success */ if (flag) { ATDISABLE(s, atpall_lock); if ((atp->atp_trans_waiting = atp_used_list) != 0) atp->atp_trans_waiting->atp_rcb_waiting = atp; atp_used_list = atp; ATENABLE(s, atpall_lock); } return(0); } /* * The close routine frees all the data structures */ /*ARGSUSED*/ int atp_close(gref, flag) gref_t *gref; int flag; { extern void atp_req_timeout(); register struct atp_state *atp; register struct atp_trans *trp; register struct atp_rcb *rcbp; register int s; int socket; pid_t pid; atp = (struct atp_state *)gref->info; if (atp->dflag) atp = (struct atp_state *)atp->atp_msgq; if (atp->atp_msgq) { gbuf_freem(atp->atp_msgq); atp->atp_msgq = 0; } ATDISABLE(s, atp->atp_lock); atp->atp_flags |= ATP_CLOSING; socket = atp->atp_socket_no; if (socket != -1) atp_inputQ[socket] = (gref_t *)1; /* * blow away all pending timers */ for (trp = atp->atp_trans_wait.head; trp; trp = trp->tr_list.next) atp_untimout(atp_req_timeout, trp); /* * Release pending transactions + rcbs */ while ((trp = atp->atp_trans_wait.head)) atp_free(trp); while ((rcbp = atp->atp_rcb.head)) atp_rcb_free(rcbp); while ((rcbp = atp->atp_attached.head)) atp_rcb_free(rcbp); ATENABLE(s, atp->atp_lock); if (flag && (socket == -1)) atp_dequeue_atp(atp); /* * free the state variable */ ATDISABLE(s, atpall_lock); atp->atp_socket_no = -1; atp->atp_trans_waiting = atp_free_list; atp_free_list = atp; ATENABLE(s, atpall_lock); if (socket != -1) { pid = (pid_t)atp_pidM[socket]; atp_pidM[socket] = 0; atp_inputQ[socket] = NULL; if (pid) ddp_notify_nbp(socket, pid, DDP_ATP); } return 0; } |