4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
22 * Copyright 2007 Sun Microsystems, Inc. All rights reserved.
23 * Use is subject to license terms.
26 /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
27 /* All Rights Reserved */
30 * University Copyright- Copyright (c) 1982, 1986, 1988
31 * The Regents of the University of California
34 * University Acknowledgment- Portions of this document are derived from
35 * software developed by the University of California, Berkeley, and its
40 * Kernel TLI-like function to initialize a transport
41 * endpoint using the protocol specified.
44 * 0 on success and "tiptr" is set to a valid transport pointer,
45 * else a positive error code.
48 #include <sys/param.h>
49 #include <sys/types.h>
53 #include <sys/vnode.h>
54 #include <sys/errno.h>
55 #include <sys/stream.h>
56 #include <sys/ioctl.h>
57 #include <sys/stropts.h>
58 #include <sys/strsubr.h>
59 #include <sys/tihdr.h>
60 #include <sys/timod.h>
61 #include <sys/tiuser.h>
62 #include <sys/t_kuser.h>
64 #include <sys/cmn_err.h>
66 static t_scalar_t
_t_setsize(t_scalar_t
);
69 t_kopen(file_t
*fp
, dev_t rdev
, int flags
, TIUSER
**tiptr
, cred_t
*cr
)
72 struct T_info_ack inforeq
;
75 struct strioctl strioc
;
81 * Special case for install: miniroot needs to be able to access files
82 * via NFS as though it were always in the global zone.
84 if (nfs_global_client_only
!= 0)
87 KTLILOG(2, "t_kopen: fp %x, ", fp
);
88 KTLILOG(2, "rdev %x, ", rdev
);
89 KTLILOG(2, "flags %x\n", flags
);
96 KTLILOG(1, "t_kopen: null device\n", 0);
101 * allocate a file pointer, but
102 * no file descripter.
104 if ((error
= falloc(NULL
, flags
, &fp
, NULL
)) != 0) {
105 KTLILOG(1, "t_kopen: falloc: %d\n", error
);
109 /* Install proper cred in file */
110 if (cr
!= fp
->f_cred
) {
116 vp
= makespecvp(rdev
, VCHR
);
119 * this will call the streams open for us.
120 * Want to retry if error is EAGAIN, the streams open routine
121 * might fail due to temporarely out of memory.
124 if ((error
= fop_open(&vp
, flags
, cr
, NULL
))
128 } while (error
== EAGAIN
&& ++rtries
< 5);
131 KTLILOG(1, "t_kopen: fop_open: %d\n", error
);
137 * fp is completely initialized so drop the write lock.
138 * I actually don't need any locking on fp in here since
139 * there is no fd pointing at it. However, since I could
140 * call closef if there is an error and closef requires
141 * the fp read locked, I will acquire the read lock here
142 * and make sure I release it before I leave this routine.
145 mutex_exit(&fp
->f_tlock
);
152 if (vp
->v_stream
== NULL
) {
155 KTLILOG(1, "t_kopen: not a streams device\n", 0);
160 * allocate a new transport structure
162 ntiptr
= kmem_alloc(TIUSERSZ
, KM_SLEEP
);
164 ntiptr
->flags
= madefp
? MADE_FP
: 0;
166 KTLILOG(2, "t_kopen: vp %x, ", vp
);
167 KTLILOG(2, "stp %x\n", vp
->v_stream
);
170 * see if TIMOD is already pushed
172 error
= strioctl(vp
, I_FIND
, (intptr_t)"timod", 0, K_TO_K
, cr
, &retval
);
174 kmem_free(ntiptr
, TIUSERSZ
);
177 KTLILOG(1, "t_kopen: strioctl(I_FIND, timod): %d\n", error
);
183 error
= strioctl(vp
, I_PUSH
, (intptr_t)"timod", 0, K_TO_K
, cr
,
191 * This probably means the master file
195 "t_kopen: I_PUSH of timod failed, error %d\n",
202 kmem_free(ntiptr
, TIUSERSZ
);
205 KTLILOG(1, "t_kopen: I_PUSH (timod): %d",
212 inforeq
.PRIM_type
= T_INFO_REQ
;
213 strioc
.ic_cmd
= TI_GETINFO
;
214 strioc
.ic_timout
= 0;
215 strioc
.ic_dp
= (char *)&inforeq
;
216 strioc
.ic_len
= (int)sizeof (struct T_info_req
);
218 error
= strdoioctl(vp
->v_stream
, &strioc
, FNATIVE
, K_TO_K
, cr
, &retval
);
220 kmem_free(ntiptr
, TIUSERSZ
);
223 KTLILOG(1, "t_kopen: strdoioctl(T_INFO_REQ): %d\n", error
);
228 if ((retval
& 0xff) == TSYSERR
)
229 error
= (retval
>> 8) & 0xff;
231 error
= t_tlitosyserr(retval
& 0xff);
232 kmem_free(ntiptr
, TIUSERSZ
);
235 KTLILOG(1, "t_kopen: strdoioctl(T_INFO_REQ): retval: 0x%x\n",
240 if (strioc
.ic_len
!= sizeof (struct T_info_ack
)) {
241 kmem_free(ntiptr
, TIUSERSZ
);
245 "t_kopen: strioc.ic_len != sizeof (struct T_info_ack): %d\n",
250 ntiptr
->tp_info
.addr
= _t_setsize(inforeq
.ADDR_size
);
251 ntiptr
->tp_info
.options
= _t_setsize(inforeq
.OPT_size
);
252 ntiptr
->tp_info
.tsdu
= _t_setsize(inforeq
.TSDU_size
);
253 ntiptr
->tp_info
.etsdu
= _t_setsize(inforeq
.ETSDU_size
);
254 ntiptr
->tp_info
.connect
= _t_setsize(inforeq
.CDATA_size
);
255 ntiptr
->tp_info
.discon
= _t_setsize(inforeq
.DDATA_size
);
256 ntiptr
->tp_info
.servtype
= inforeq
.SERV_type
;
266 _t_setsize(t_scalar_t infosize
)