1*fe267a55SPedro F. Giffuni /*-
2*fe267a55SPedro F. Giffuni * SPDX-License-Identifier: BSD-2-Clause OR GPL-2.0
3*fe267a55SPedro F. Giffuni *
4aa0a1e58SJeff Roberson * Copyright (c) 2004 Mellanox Technologies Ltd. All rights reserved.
5aa0a1e58SJeff Roberson * Copyright (c) 2004 Infinicon Corporation. All rights reserved.
6aa0a1e58SJeff Roberson * Copyright (c) 2004 Intel Corporation. All rights reserved.
7aa0a1e58SJeff Roberson * Copyright (c) 2004 Topspin Corporation. All rights reserved.
8aa0a1e58SJeff Roberson * Copyright (c) 2004-2007 Voltaire Corporation. All rights reserved.
9aa0a1e58SJeff Roberson *
10aa0a1e58SJeff Roberson * This software is available to you under a choice of one of two
11aa0a1e58SJeff Roberson * licenses. You may choose to be licensed under the terms of the GNU
12aa0a1e58SJeff Roberson * General Public License (GPL) Version 2, available from the file
13aa0a1e58SJeff Roberson * COPYING in the main directory of this source tree, or the
14aa0a1e58SJeff Roberson * OpenIB.org BSD license below:
15aa0a1e58SJeff Roberson *
16aa0a1e58SJeff Roberson * Redistribution and use in source and binary forms, with or
17aa0a1e58SJeff Roberson * without modification, are permitted provided that the following
18aa0a1e58SJeff Roberson * conditions are met:
19aa0a1e58SJeff Roberson *
20aa0a1e58SJeff Roberson * - Redistributions of source code must retain the above
21aa0a1e58SJeff Roberson * copyright notice, this list of conditions and the following
22aa0a1e58SJeff Roberson * disclaimer.
23aa0a1e58SJeff Roberson *
24aa0a1e58SJeff Roberson * - Redistributions in binary form must reproduce the above
25aa0a1e58SJeff Roberson * copyright notice, this list of conditions and the following
26aa0a1e58SJeff Roberson * disclaimer in the documentation and/or other materials
27aa0a1e58SJeff Roberson * provided with the distribution.
28aa0a1e58SJeff Roberson *
29aa0a1e58SJeff Roberson * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
30aa0a1e58SJeff Roberson * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
31aa0a1e58SJeff Roberson * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
32aa0a1e58SJeff Roberson * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
33aa0a1e58SJeff Roberson * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
34aa0a1e58SJeff Roberson * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
35aa0a1e58SJeff Roberson * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
36aa0a1e58SJeff Roberson * SOFTWARE.
37aa0a1e58SJeff Roberson */
38aa0a1e58SJeff Roberson
39aa0a1e58SJeff Roberson #ifndef __SMI_H_
40aa0a1e58SJeff Roberson #define __SMI_H_
41aa0a1e58SJeff Roberson
42aa0a1e58SJeff Roberson #include <rdma/ib_smi.h>
43aa0a1e58SJeff Roberson
44aa0a1e58SJeff Roberson enum smi_action {
45aa0a1e58SJeff Roberson IB_SMI_DISCARD,
46aa0a1e58SJeff Roberson IB_SMI_HANDLE
47aa0a1e58SJeff Roberson };
48aa0a1e58SJeff Roberson
49aa0a1e58SJeff Roberson enum smi_forward_action {
50aa0a1e58SJeff Roberson IB_SMI_LOCAL, /* SMP should be completed up the stack */
51aa0a1e58SJeff Roberson IB_SMI_SEND, /* received DR SMP should be forwarded to the send queue */
52aa0a1e58SJeff Roberson IB_SMI_FORWARD /* SMP should be forwarded (for switches only) */
53aa0a1e58SJeff Roberson };
54aa0a1e58SJeff Roberson
55478d3005SHans Petter Selasky enum smi_action smi_handle_dr_smp_recv(struct ib_smp *smp, bool is_switch,
56aa0a1e58SJeff Roberson int port_num, int phys_port_cnt);
57aa0a1e58SJeff Roberson int smi_get_fwd_port(struct ib_smp *smp);
58aa0a1e58SJeff Roberson extern enum smi_forward_action smi_check_forward_dr_smp(struct ib_smp *smp);
59aa0a1e58SJeff Roberson extern enum smi_action smi_handle_dr_smp_send(struct ib_smp *smp,
60478d3005SHans Petter Selasky bool is_switch, int port_num);
61aa0a1e58SJeff Roberson
62aa0a1e58SJeff Roberson /*
63aa0a1e58SJeff Roberson * Return IB_SMI_HANDLE if the SMP should be handled by the local SMA/SM
64aa0a1e58SJeff Roberson * via process_mad
65aa0a1e58SJeff Roberson */
smi_check_local_smp(struct ib_smp * smp,struct ib_device * device)66aa0a1e58SJeff Roberson static inline enum smi_action smi_check_local_smp(struct ib_smp *smp,
67aa0a1e58SJeff Roberson struct ib_device *device)
68aa0a1e58SJeff Roberson {
69aa0a1e58SJeff Roberson /* C14-9:3 -- We're at the end of the DR segment of path */
70aa0a1e58SJeff Roberson /* C14-9:4 -- Hop Pointer = Hop Count + 1 -> give to SMA/SM */
71aa0a1e58SJeff Roberson return ((device->process_mad &&
72aa0a1e58SJeff Roberson !ib_get_smp_direction(smp) &&
73aa0a1e58SJeff Roberson (smp->hop_ptr == smp->hop_cnt + 1)) ?
74aa0a1e58SJeff Roberson IB_SMI_HANDLE : IB_SMI_DISCARD);
75aa0a1e58SJeff Roberson }
76aa0a1e58SJeff Roberson
77aa0a1e58SJeff Roberson /*
78aa0a1e58SJeff Roberson * Return IB_SMI_HANDLE if the SMP should be handled by the local SMA/SM
79aa0a1e58SJeff Roberson * via process_mad
80aa0a1e58SJeff Roberson */
smi_check_local_returning_smp(struct ib_smp * smp,struct ib_device * device)81aa0a1e58SJeff Roberson static inline enum smi_action smi_check_local_returning_smp(struct ib_smp *smp,
82aa0a1e58SJeff Roberson struct ib_device *device)
83aa0a1e58SJeff Roberson {
84aa0a1e58SJeff Roberson /* C14-13:3 -- We're at the end of the DR segment of path */
85aa0a1e58SJeff Roberson /* C14-13:4 -- Hop Pointer == 0 -> give to SM */
86aa0a1e58SJeff Roberson return ((device->process_mad &&
87aa0a1e58SJeff Roberson ib_get_smp_direction(smp) &&
88aa0a1e58SJeff Roberson !smp->hop_ptr) ? IB_SMI_HANDLE : IB_SMI_DISCARD);
89aa0a1e58SJeff Roberson }
90aa0a1e58SJeff Roberson
91aa0a1e58SJeff Roberson #endif /* __SMI_H_ */
92