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/rds.h>
58 
59 #include <sys/ib/clients/rdsv3/rdsv3.h>
60 #include <sys/ib/clients/rdsv3/ib.h>
61 #include <sys/ib/clients/rdsv3/rdsv3_debug.h>
62 
63 RDSV3_DEFINE_PER_CPU(struct rdsv3_ib_statistics, rdsv3_ib_stats);
64 
65 static char *rdsv3_ib_stat_names[] = {
66 	"ib_connect_raced",
67 	"ib_listen_closed_stale",
68 	"ib_tx_cq_call",
69 	"ib_tx_cq_event",
70 	"ib_tx_ring_full",
71 	"ib_tx_throttle",
72 	"ib_tx_sg_mapping_failure",
73 	"ib_tx_stalled",
74 	"ib_tx_credit_updates",
75 	"ib_rx_cq_call",
76 	"ib_rx_cq_event",
77 	"ib_rx_ring_empty",
78 	"ib_rx_refill_from_cq",
79 	"ib_rx_refill_from_thread",
80 	"ib_rx_alloc_limit",
81 	"ib_rx_credit_updates",
82 	"ib_ack_sent",
83 	"ib_ack_send_failure",
84 	"ib_ack_send_delayed",
85 	"ib_ack_send_piggybacked",
86 	"ib_ack_received",
87 	"ib_rdma_mr_alloc",
88 	"ib_rdma_mr_free",
89 	"ib_rdma_mr_used",
90 	"ib_rdma_mr_pool_flush",
91 	"ib_rdma_mr_pool_wait",
92 	"ib_rdma_mr_pool_depleted",
93 };
94 
95 unsigned int
96 rdsv3_ib_stats_info_copy(struct rdsv3_info_iterator *iter,
97     unsigned int avail)
98 {
99 	struct rdsv3_ib_statistics stats = {0, };
100 	uint64_t *src;
101 	uint64_t *sum;
102 	size_t i;
103 	int cpu;
104 
105 	RDSV3_DPRINTF4("rdsv3_ib_stats_info_copy", "iter: %p, avail: %d",
106 	    iter, avail);
107 
108 	if (avail < ARRAY_SIZE(rdsv3_ib_stat_names))
109 		goto out;
110 
111 	for (cpu = 0; cpu < NR_CPUS; cpu++) {
112 		src = (uint64_t *)&(rdsv3_per_cpu(rdsv3_ib_stats, cpu));
113 		sum = (uint64_t *)&stats;
114 		for (i = 0; i < sizeof (stats) / sizeof (uint64_t); i++)
115 			*(sum++) += *(src++);
116 	}
117 
118 	rdsv3_stats_info_copy(iter, (uint64_t *)&stats, rdsv3_ib_stat_names,
119 	    ARRAY_SIZE(rdsv3_ib_stat_names));
120 
121 	RDSV3_DPRINTF4("rdsv3_ib_stats_info_copy",
122 	    "Return: iter: %p, avail: %d", iter, avail);
123 out:
124 	return (ARRAY_SIZE(rdsv3_ib_stat_names));
125 }
126