xref: /titanic_52/usr/src/uts/common/inet/sockmods/sockmod_rds.c (revision cd3e933325e68e23516a196a8fea7f49b1e497c3)
1 /*
2  * CDDL HEADER START
3  *
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.
7  *
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.
12  *
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]
18  *
19  * CDDL HEADER END
20  */
21 /*
22  * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
23  */
24 
25 #include <sys/types.h>
26 #include <sys/conf.h>
27 #include <sys/modctl.h>
28 #include <sys/sunldi.h>
29 #include <inet/common.h>
30 #include <sys/strsubr.h>
31 #include <sys/socketvar.h>
32 
33 extern sock_lower_handle_t rdsv3_create(int, int, int, sock_downcalls_t **,
34     uint_t *, int *, int, cred_t *);
35 
36 #define	INET_NAME	"sockrds"
37 #define	INET_DEVMINOR	0
38 #define	INET_MODMTFLAGS	D_MP
39 #define	INET_SOCKDESC	"RDSv3 socket module"
40 #define	INET_SOCK_PROTO_CREATE_FUNC	(*rdsv3_create)
41 
42 #include "../inetddi.c"
43 
44 ldi_ident_t	sockrds_li;
45 ldi_handle_t    rdsv3_transport_handle = NULL;
46 
47 #define	RDSV3_DEVICE_NAME	"/devices/ib/rdsv3@0:rdsv3"
48 
49 int
50 _init(void)
51 {
52 	int	ret;
53 
54 	ret = ldi_ident_from_mod(&modlinkage, &sockrds_li);
55 	if (ret != 0) {
56 		sockrds_li = NULL;
57 		goto done;
58 	}
59 
60 	ret = ldi_open_by_name(RDSV3_DEVICE_NAME, FREAD | FWRITE, kcred,
61 	    &rdsv3_transport_handle, sockrds_li);
62 	if (ret != 0) {
63 		ldi_ident_release(sockrds_li);
64 		sockrds_li = NULL;
65 		rdsv3_transport_handle = NULL;
66 		goto done;
67 	}
68 
69 	ret = mod_install(&modlinkage);
70 	if (ret != 0) {
71 		(void) ldi_close(rdsv3_transport_handle, FNDELAY, kcred);
72 		ldi_ident_release(sockrds_li);
73 		sockrds_li = NULL;
74 		rdsv3_transport_handle = NULL;
75 	}
76 
77 done:
78 	return (ret);
79 }
80 
81 int
82 _fini(void)
83 {
84 	int ret;
85 
86 	ret = mod_remove(&modlinkage);
87 	if (ret != 0) {
88 		return (ret);
89 	}
90 
91 	if (rdsv3_transport_handle != NULL) {
92 		(void) ldi_close(rdsv3_transport_handle, FNDELAY, kcred);
93 		rdsv3_transport_handle = NULL;
94 	}
95 
96 	if (sockrds_li != NULL)
97 		ldi_ident_release(sockrds_li);
98 
99 	return (0);
100 }
101 
102 int
103 _info(struct modinfo *modinfop)
104 {
105 	return (mod_info(&modlinkage, modinfop));
106 }
107