112198SEiji.Ota@Sun.COM /*
212198SEiji.Ota@Sun.COM * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
312198SEiji.Ota@Sun.COM */
412198SEiji.Ota@Sun.COM
512198SEiji.Ota@Sun.COM /*
612763SGiri.Adari@Sun.COM * This file contains code imported from the OFED rds source file transport.c
712763SGiri.Adari@Sun.COM * Oracle elects to have and use the contents of transport.c under and governed
812763SGiri.Adari@Sun.COM * by the OpenIB.org BSD license (see below for full license text). However,
912763SGiri.Adari@Sun.COM * the following notice accompanied the original version of this file:
1012763SGiri.Adari@Sun.COM */
1112763SGiri.Adari@Sun.COM
1212763SGiri.Adari@Sun.COM /*
1312198SEiji.Ota@Sun.COM * Copyright (c) 2006 Oracle. All rights reserved.
1412198SEiji.Ota@Sun.COM *
1512198SEiji.Ota@Sun.COM * This software is available to you under a choice of one of two
1612198SEiji.Ota@Sun.COM * licenses. You may choose to be licensed under the terms of the GNU
1712198SEiji.Ota@Sun.COM * General Public License (GPL) Version 2, available from the file
1812198SEiji.Ota@Sun.COM * COPYING in the main directory of this source tree, or the
1912198SEiji.Ota@Sun.COM * OpenIB.org BSD license below:
2012198SEiji.Ota@Sun.COM *
2112198SEiji.Ota@Sun.COM * Redistribution and use in source and binary forms, with or
2212198SEiji.Ota@Sun.COM * without modification, are permitted provided that the following
2312198SEiji.Ota@Sun.COM * conditions are met:
2412198SEiji.Ota@Sun.COM *
2512198SEiji.Ota@Sun.COM * - Redistributions of source code must retain the above
2612198SEiji.Ota@Sun.COM * copyright notice, this list of conditions and the following
2712198SEiji.Ota@Sun.COM * disclaimer.
2812198SEiji.Ota@Sun.COM *
2912198SEiji.Ota@Sun.COM * - Redistributions in binary form must reproduce the above
3012198SEiji.Ota@Sun.COM * copyright notice, this list of conditions and the following
3112198SEiji.Ota@Sun.COM * disclaimer in the documentation and/or other materials
3212198SEiji.Ota@Sun.COM * provided with the distribution.
3312198SEiji.Ota@Sun.COM *
3412198SEiji.Ota@Sun.COM * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
3512198SEiji.Ota@Sun.COM * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
3612198SEiji.Ota@Sun.COM * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
3712198SEiji.Ota@Sun.COM * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
3812198SEiji.Ota@Sun.COM * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
3912198SEiji.Ota@Sun.COM * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
4012198SEiji.Ota@Sun.COM * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
4112198SEiji.Ota@Sun.COM * SOFTWARE.
4212198SEiji.Ota@Sun.COM *
4312198SEiji.Ota@Sun.COM */
4412198SEiji.Ota@Sun.COM #include <sys/ksynch.h>
4512198SEiji.Ota@Sun.COM #include <sys/list.h>
4612198SEiji.Ota@Sun.COM #include <sys/rds.h>
4712198SEiji.Ota@Sun.COM #include <sys/sysmacros.h>
4812198SEiji.Ota@Sun.COM
4912198SEiji.Ota@Sun.COM #include <sys/ib/clients/rdsv3/rdsv3.h>
5012198SEiji.Ota@Sun.COM #include <sys/ib/clients/rdsv3/loop.h>
5112198SEiji.Ota@Sun.COM #include <sys/ib/clients/rdsv3/rdsv3_impl.h>
5212198SEiji.Ota@Sun.COM #include <sys/ib/clients/rdsv3/rdsv3_debug.h>
5312198SEiji.Ota@Sun.COM
5412414SEiji.Ota@Sun.COM struct rdsv3_transport *transports[RDS_TRANS_COUNT];
5512198SEiji.Ota@Sun.COM krwlock_t trans_sem; /* this was a semaphore */
5612198SEiji.Ota@Sun.COM
5712198SEiji.Ota@Sun.COM int
rdsv3_trans_register(struct rdsv3_transport * trans)5812198SEiji.Ota@Sun.COM rdsv3_trans_register(struct rdsv3_transport *trans)
5912198SEiji.Ota@Sun.COM {
6012198SEiji.Ota@Sun.COM RDSV3_DPRINTF4("rdsv3_trans_register", "Enter(trans: %p)", trans);
6112198SEiji.Ota@Sun.COM
6212198SEiji.Ota@Sun.COM rw_enter(&trans_sem, RW_WRITER);
6312198SEiji.Ota@Sun.COM
6412414SEiji.Ota@Sun.COM if (transports[trans->t_type]) {
6512414SEiji.Ota@Sun.COM cmn_err(CE_WARN,
6612414SEiji.Ota@Sun.COM "RDSV3 Transport type %d already registered\n",
6712414SEiji.Ota@Sun.COM trans->t_type);
6812414SEiji.Ota@Sun.COM rw_exit(&trans_sem);
6912414SEiji.Ota@Sun.COM return (1);
7012414SEiji.Ota@Sun.COM } else {
7112414SEiji.Ota@Sun.COM transports[trans->t_type] = trans;
7212414SEiji.Ota@Sun.COM RDSV3_DPRINTF2("rdsv3_trans_register",
7312414SEiji.Ota@Sun.COM "Registered RDS/%s transport\n", trans->t_name);
7412414SEiji.Ota@Sun.COM }
7512198SEiji.Ota@Sun.COM
7612198SEiji.Ota@Sun.COM rw_exit(&trans_sem);
7712198SEiji.Ota@Sun.COM
7812198SEiji.Ota@Sun.COM RDSV3_DPRINTF4("rdsv3_trans_register", "Return(trans: %p)", trans);
7912198SEiji.Ota@Sun.COM
8012198SEiji.Ota@Sun.COM return (0);
8112198SEiji.Ota@Sun.COM }
8212198SEiji.Ota@Sun.COM
8312198SEiji.Ota@Sun.COM void
rdsv3_trans_unregister(struct rdsv3_transport * trans)8412198SEiji.Ota@Sun.COM rdsv3_trans_unregister(struct rdsv3_transport *trans)
8512198SEiji.Ota@Sun.COM {
8612198SEiji.Ota@Sun.COM RDSV3_DPRINTF4("rdsv3_trans_register", "Enter(trans: %p)", trans);
8712198SEiji.Ota@Sun.COM
8812198SEiji.Ota@Sun.COM rw_enter(&trans_sem, RW_WRITER);
8912198SEiji.Ota@Sun.COM
9012414SEiji.Ota@Sun.COM transports[trans->t_type] = NULL;
9112198SEiji.Ota@Sun.COM
9212198SEiji.Ota@Sun.COM rw_exit(&trans_sem);
9312198SEiji.Ota@Sun.COM
9412198SEiji.Ota@Sun.COM RDSV3_DPRINTF4("rdsv3_trans_register", "Return(trans: %p)", trans);
9512198SEiji.Ota@Sun.COM }
9612198SEiji.Ota@Sun.COM
9712198SEiji.Ota@Sun.COM struct rdsv3_transport *
rdsv3_trans_get_preferred(uint32_be_t addr)9812198SEiji.Ota@Sun.COM rdsv3_trans_get_preferred(uint32_be_t addr)
9912198SEiji.Ota@Sun.COM {
10012198SEiji.Ota@Sun.COM struct rdsv3_transport *ret = NULL;
10112414SEiji.Ota@Sun.COM int i;
10212198SEiji.Ota@Sun.COM
10312198SEiji.Ota@Sun.COM RDSV3_DPRINTF4("rdsv3_trans_get_preferred", "Enter(addr: %x)",
10412198SEiji.Ota@Sun.COM ntohl(addr));
10512198SEiji.Ota@Sun.COM
10612198SEiji.Ota@Sun.COM if (rdsv3_isloopback(addr))
10712198SEiji.Ota@Sun.COM return (&rdsv3_loop_transport);
10812198SEiji.Ota@Sun.COM
10912198SEiji.Ota@Sun.COM rw_enter(&trans_sem, RW_READER);
11012414SEiji.Ota@Sun.COM for (i = 0; i < RDS_TRANS_COUNT; i++) {
11112676SEiji.Ota@Sun.COM if (transports[i] &&
11212676SEiji.Ota@Sun.COM transports[i]->laddr_check(addr) == 0) {
11312414SEiji.Ota@Sun.COM ret = transports[i];
11412198SEiji.Ota@Sun.COM break;
11512198SEiji.Ota@Sun.COM }
11612198SEiji.Ota@Sun.COM }
11712198SEiji.Ota@Sun.COM rw_exit(&trans_sem);
11812198SEiji.Ota@Sun.COM
11912198SEiji.Ota@Sun.COM RDSV3_DPRINTF4("rdsv3_trans_get_preferred",
12012198SEiji.Ota@Sun.COM "Return(addr: %x, ret: %p)", ntohl(addr), ret);
12112198SEiji.Ota@Sun.COM
12212198SEiji.Ota@Sun.COM return (ret);
12312198SEiji.Ota@Sun.COM }
12412198SEiji.Ota@Sun.COM
12512198SEiji.Ota@Sun.COM /*
12612198SEiji.Ota@Sun.COM * This returns the number of stats entries in the snapshot and only
12712198SEiji.Ota@Sun.COM * copies them using the iter if there is enough space for them. The
12812198SEiji.Ota@Sun.COM * caller passes in the global stats so that we can size and copy while
12912198SEiji.Ota@Sun.COM * holding the lock.
13012198SEiji.Ota@Sun.COM */
13112198SEiji.Ota@Sun.COM /* ARGSUSED */
13212198SEiji.Ota@Sun.COM unsigned int
rdsv3_trans_stats_info_copy(struct rdsv3_info_iterator * iter,unsigned int avail)13312198SEiji.Ota@Sun.COM rdsv3_trans_stats_info_copy(struct rdsv3_info_iterator *iter,
13412198SEiji.Ota@Sun.COM unsigned int avail)
13512198SEiji.Ota@Sun.COM {
136*13118SEiji.Ota@Sun.COM struct rdsv3_transport *trans;
137*13118SEiji.Ota@Sun.COM unsigned int total = 0;
138*13118SEiji.Ota@Sun.COM unsigned int part;
139*13118SEiji.Ota@Sun.COM int i;
140*13118SEiji.Ota@Sun.COM
141*13118SEiji.Ota@Sun.COM rw_enter(&trans_sem, RW_READER);
142*13118SEiji.Ota@Sun.COM
143*13118SEiji.Ota@Sun.COM for (i = 0; i < RDS_TRANS_COUNT; i++) {
144*13118SEiji.Ota@Sun.COM trans = transports[i];
145*13118SEiji.Ota@Sun.COM if (!trans || !trans->stats_info_copy)
146*13118SEiji.Ota@Sun.COM continue;
147*13118SEiji.Ota@Sun.COM
148*13118SEiji.Ota@Sun.COM part = trans->stats_info_copy(iter, avail);
149*13118SEiji.Ota@Sun.COM avail -= min(avail, part);
150*13118SEiji.Ota@Sun.COM total += part;
151*13118SEiji.Ota@Sun.COM }
152*13118SEiji.Ota@Sun.COM
153*13118SEiji.Ota@Sun.COM rw_exit(&trans_sem);
154*13118SEiji.Ota@Sun.COM
155*13118SEiji.Ota@Sun.COM return (total);
15612198SEiji.Ota@Sun.COM }
157