xref: /freebsd/sys/ofed/include/rdma/ib_cache.h (revision d15f2551b25f79ddcbe289faa95e655100b952da)
1 /*-
2  * SPDX-License-Identifier: BSD-2-Clause OR GPL-2.0
3  *
4  * Copyright (c) 2004 Topspin Communications.  All rights reserved.
5  * Copyright (c) 2005 Intel Corporation. All rights reserved.
6  * Copyright (c) 2005 Sun Microsystems, Inc. All rights reserved.
7  *
8  * This software is available to you under a choice of one of two
9  * licenses.  You may choose to be licensed under the terms of the GNU
10  * General Public License (GPL) Version 2, available from the file
11  * COPYING in the main directory of this source tree, or the
12  * OpenIB.org BSD license below:
13  *
14  *     Redistribution and use in source and binary forms, with or
15  *     without modification, are permitted provided that the following
16  *     conditions are met:
17  *
18  *      - Redistributions of source code must retain the above
19  *        copyright notice, this list of conditions and the following
20  *        disclaimer.
21  *
22  *      - Redistributions in binary form must reproduce the above
23  *        copyright notice, this list of conditions and the following
24  *        disclaimer in the documentation and/or other materials
25  *        provided with the distribution.
26  *
27  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
28  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
29  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
30  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
31  * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
32  * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
33  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
34  * SOFTWARE.
35  */
36 
37 #ifndef _IB_CACHE_H
38 #define _IB_CACHE_H
39 
40 #include <rdma/ib_verbs.h>
41 
42 int rdma_query_gid(struct ib_device *device, u8 port_num, int index,
43 		   union ib_gid *gid);
44 const struct ib_gid_attr *rdma_find_gid(struct ib_device *device,
45 					const union ib_gid *gid,
46 					enum ib_gid_type gid_type,
47 					if_t ndev);
48 const struct ib_gid_attr *rdma_find_gid_by_port(struct ib_device *ib_dev,
49 						const union ib_gid *gid,
50 						enum ib_gid_type gid_type,
51 						u8 port,
52 						if_t ndev);
53 const struct ib_gid_attr *rdma_find_gid_by_filter(
54 	struct ib_device *device, const union ib_gid *gid, u8 port_num,
55 	bool (*filter)(const union ib_gid *gid, const struct ib_gid_attr *,
56 		       void *),
57 	void *context);
58 
59 int rdma_read_gid_l2_fields(const struct ib_gid_attr *attr,
60 			    u16 *vlan_id, u8 *smac);
61 if_t rdma_read_gid_attr_ndev_rcu(const struct ib_gid_attr *attr);
62 
63 /**
64  * ib_get_cached_pkey - Returns a cached PKey table entry
65  * @device: The device to query.
66  * @port_num: The port number of the device to query.
67  * @index: The index into the cached PKey table to query.
68  * @pkey: The PKey value found at the specified index.
69  *
70  * ib_get_cached_pkey() fetches the specified PKey table entry stored in
71  * the local software cache.
72  */
73 int ib_get_cached_pkey(struct ib_device    *device_handle,
74 		       u8                   port_num,
75 		       int                  index,
76 		       u16                 *pkey);
77 
78 /**
79  * ib_find_cached_pkey - Returns the PKey table index where a specified
80  *   PKey value occurs.
81  * @device: The device to query.
82  * @port_num: The port number of the device to search for the PKey.
83  * @pkey: The PKey value to search for.
84  * @index: The index into the cached PKey table where the PKey was found.
85  *
86  * ib_find_cached_pkey() searches the specified PKey table in
87  * the local software cache.
88  */
89 int ib_find_cached_pkey(struct ib_device    *device,
90 			u8                   port_num,
91 			u16                  pkey,
92 			u16                 *index);
93 
94 /**
95  * ib_find_exact_cached_pkey - Returns the PKey table index where a specified
96  *   PKey value occurs. Comparison uses the FULL 16 bits (incl membership bit)
97  * @device: The device to query.
98  * @port_num: The port number of the device to search for the PKey.
99  * @pkey: The PKey value to search for.
100  * @index: The index into the cached PKey table where the PKey was found.
101  *
102  * ib_find_exact_cached_pkey() searches the specified PKey table in
103  * the local software cache.
104  */
105 int ib_find_exact_cached_pkey(struct ib_device    *device,
106 			      u8                   port_num,
107 			      u16                  pkey,
108 			      u16                 *index);
109 
110 /**
111  * ib_get_cached_lmc - Returns a cached lmc table entry
112  * @device: The device to query.
113  * @port_num: The port number of the device to query.
114  * @lmc: The lmc value for the specified port for that device.
115  *
116  * ib_get_cached_lmc() fetches the specified lmc table entry stored in
117  * the local software cache.
118  */
119 int ib_get_cached_lmc(struct ib_device *device,
120 		      u8                port_num,
121 		      u8                *lmc);
122 
123 /**
124  * ib_get_cached_port_state - Returns a cached port state table entry
125  * @device: The device to query.
126  * @port_num: The port number of the device to query.
127  * @port_state: port_state for the specified port for that device.
128  *
129  * ib_get_cached_port_state() fetches the specified port_state table entry stored in
130  * the local software cache.
131  */
132 int ib_get_cached_port_state(struct ib_device *device,
133 			      u8                port_num,
134 			      enum ib_port_state *port_active);
135 
136 bool rdma_is_zero_gid(const union ib_gid *gid);
137 const struct ib_gid_attr *rdma_get_gid_attr(struct ib_device *device,
138 					    u8 port_num, int index);
139 void rdma_put_gid_attr(const struct ib_gid_attr *attr);
140 void rdma_hold_gid_attr(const struct ib_gid_attr *attr);
141 #endif /* _IB_CACHE_H */
142