xref: /illumos-gate/usr/src/uts/common/io/ib/clients/rdsv3/transport.c (revision cadbfdc3bdb156e92d7a88978bc98ea87f6e037f)
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 /*
26  * Copyright (c) 2006 Oracle.  All rights reserved.
27  *
28  * This software is available to you under a choice of one of two
29  * licenses.  You may choose to be licensed under the terms of the GNU
30  * General Public License (GPL) Version 2, available from the file
31  * COPYING in the main directory of this source tree, or the
32  * OpenIB.org BSD license below:
33  *
34  *     Redistribution and use in source and binary forms, with or
35  *     without modification, are permitted provided that the following
36  *     conditions are met:
37  *
38  *      - Redistributions of source code must retain the above
39  *        copyright notice, this list of conditions and the following
40  *        disclaimer.
41  *
42  *      - Redistributions in binary form must reproduce the above
43  *        copyright notice, this list of conditions and the following
44  *        disclaimer in the documentation and/or other materials
45  *        provided with the distribution.
46  *
47  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
48  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
49  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
50  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
51  * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
52  * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
53  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
54  * SOFTWARE.
55  *
56  */
57 #include <sys/ksynch.h>
58 #include <sys/list.h>
59 #include <sys/rds.h>
60 #include <sys/sysmacros.h>
61 
62 #include <sys/ib/clients/rdsv3/rdsv3.h>
63 #include <sys/ib/clients/rdsv3/loop.h>
64 #include <sys/ib/clients/rdsv3/rdsv3_impl.h>
65 #include <sys/ib/clients/rdsv3/rdsv3_debug.h>
66 
67 struct rdsv3_transport *transports[RDS_TRANS_COUNT];
68 krwlock_t		trans_sem; /* this was a semaphore */
69 
70 int
71 rdsv3_trans_register(struct rdsv3_transport *trans)
72 {
73 	RDSV3_DPRINTF4("rdsv3_trans_register", "Enter(trans: %p)", trans);
74 
75 	rw_enter(&trans_sem, RW_WRITER);
76 
77 	if (transports[trans->t_type]) {
78 		cmn_err(CE_WARN,
79 		    "RDSV3 Transport type %d already registered\n",
80 		    trans->t_type);
81 		rw_exit(&trans_sem);
82 		return (1);
83 	} else {
84 		transports[trans->t_type] = trans;
85 		RDSV3_DPRINTF2("rdsv3_trans_register",
86 		    "Registered RDS/%s transport\n", trans->t_name);
87 	}
88 
89 	rw_exit(&trans_sem);
90 
91 	RDSV3_DPRINTF4("rdsv3_trans_register", "Return(trans: %p)", trans);
92 
93 	return (0);
94 }
95 
96 void
97 rdsv3_trans_unregister(struct rdsv3_transport *trans)
98 {
99 	RDSV3_DPRINTF4("rdsv3_trans_register", "Enter(trans: %p)", trans);
100 
101 	rw_enter(&trans_sem, RW_WRITER);
102 
103 	transports[trans->t_type] = NULL;
104 
105 	rw_exit(&trans_sem);
106 
107 	RDSV3_DPRINTF4("rdsv3_trans_register", "Return(trans: %p)", trans);
108 }
109 
110 struct rdsv3_transport *
111 rdsv3_trans_get_preferred(uint32_be_t addr)
112 {
113 	struct rdsv3_transport *ret = NULL;
114 	int i;
115 
116 	RDSV3_DPRINTF4("rdsv3_trans_get_preferred", "Enter(addr: %x)",
117 	    ntohl(addr));
118 
119 	if (rdsv3_isloopback(addr))
120 		return (&rdsv3_loop_transport);
121 
122 	rw_enter(&trans_sem, RW_READER);
123 	for (i = 0; i < RDS_TRANS_COUNT; i++) {
124 		if (transports[i] && (transports[i]->laddr_check(addr) == 0)) {
125 			ret = transports[i];
126 			break;
127 		}
128 	}
129 	rw_exit(&trans_sem);
130 
131 	RDSV3_DPRINTF4("rdsv3_trans_get_preferred",
132 	    "Return(addr: %x, ret: %p)", ntohl(addr), ret);
133 
134 	return (ret);
135 }
136 
137 /*
138  * This returns the number of stats entries in the snapshot and only
139  * copies them using the iter if there is enough space for them.  The
140  * caller passes in the global stats so that we can size and copy while
141  * holding the lock.
142  */
143 /* ARGSUSED */
144 unsigned int
145 rdsv3_trans_stats_info_copy(struct rdsv3_info_iterator *iter,
146     unsigned int avail)
147 {
148 	/*
149 	 * XXX - Add this when we port info (info.c)
150 	 */
151 	return (0);
152 }
153