11da177e4SLinus Torvalds /*
21da177e4SLinus Torvalds * Copyright (c) 2004 Mellanox Technologies Ltd. All rights reserved.
31da177e4SLinus Torvalds * Copyright (c) 2004 Infinicon Corporation. All rights reserved.
41da177e4SLinus Torvalds * Copyright (c) 2004 Intel Corporation. All rights reserved.
51da177e4SLinus Torvalds * Copyright (c) 2004 Topspin Corporation. All rights reserved.
6de493d47SHal Rosenstock * Copyright (c) 2004-2007 Voltaire Corporation. All rights reserved.
71da177e4SLinus Torvalds *
81da177e4SLinus Torvalds * This software is available to you under a choice of one of two
91da177e4SLinus Torvalds * licenses. You may choose to be licensed under the terms of the GNU
101da177e4SLinus Torvalds * General Public License (GPL) Version 2, available from the file
111da177e4SLinus Torvalds * COPYING in the main directory of this source tree, or the
121da177e4SLinus Torvalds * OpenIB.org BSD license below:
131da177e4SLinus Torvalds *
141da177e4SLinus Torvalds * Redistribution and use in source and binary forms, with or
151da177e4SLinus Torvalds * without modification, are permitted provided that the following
161da177e4SLinus Torvalds * conditions are met:
171da177e4SLinus Torvalds *
181da177e4SLinus Torvalds * - Redistributions of source code must retain the above
191da177e4SLinus Torvalds * copyright notice, this list of conditions and the following
201da177e4SLinus Torvalds * disclaimer.
211da177e4SLinus Torvalds *
221da177e4SLinus Torvalds * - Redistributions in binary form must reproduce the above
231da177e4SLinus Torvalds * copyright notice, this list of conditions and the following
241da177e4SLinus Torvalds * disclaimer in the documentation and/or other materials
251da177e4SLinus Torvalds * provided with the distribution.
261da177e4SLinus Torvalds *
271da177e4SLinus Torvalds * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
281da177e4SLinus Torvalds * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
291da177e4SLinus Torvalds * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
301da177e4SLinus Torvalds * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
311da177e4SLinus Torvalds * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
321da177e4SLinus Torvalds * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
331da177e4SLinus Torvalds * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
341da177e4SLinus Torvalds * SOFTWARE.
351da177e4SLinus Torvalds *
361da177e4SLinus Torvalds */
371da177e4SLinus Torvalds
381da177e4SLinus Torvalds #ifndef __SMI_H_
391da177e4SLinus Torvalds #define __SMI_H_
401da177e4SLinus Torvalds
4134816ad9SSean Hefty #include <rdma/ib_smi.h>
4234816ad9SSean Hefty
43de493d47SHal Rosenstock enum smi_action {
44de493d47SHal Rosenstock IB_SMI_DISCARD,
45de493d47SHal Rosenstock IB_SMI_HANDLE
46de493d47SHal Rosenstock };
47de493d47SHal Rosenstock
48de493d47SHal Rosenstock enum smi_forward_action {
49de493d47SHal Rosenstock IB_SMI_LOCAL, /* SMP should be completed up the stack */
50de493d47SHal Rosenstock IB_SMI_SEND, /* received DR SMP should be forwarded to the send queue */
511bae4dbfSHal Rosenstock IB_SMI_FORWARD /* SMP should be forwarded (for switches only) */
52de493d47SHal Rosenstock };
53de493d47SHal Rosenstock
544139032bSHal Rosenstock enum smi_action smi_handle_dr_smp_recv(struct ib_smp *smp, bool is_switch,
55*1fb7f897SMark Bloch u32 port_num, int phys_port_cnt);
561bae4dbfSHal Rosenstock int smi_get_fwd_port(struct ib_smp *smp);
57de493d47SHal Rosenstock extern enum smi_forward_action smi_check_forward_dr_smp(struct ib_smp *smp);
58de493d47SHal Rosenstock extern enum smi_action smi_handle_dr_smp_send(struct ib_smp *smp,
59*1fb7f897SMark Bloch bool is_switch, u32 port_num);
601da177e4SLinus Torvalds
611da177e4SLinus Torvalds /*
62727792daSSteve Welch * Return IB_SMI_HANDLE if the SMP should be handled by the local SMA/SM
63727792daSSteve Welch * via process_mad
641da177e4SLinus Torvalds */
smi_check_local_smp(struct ib_smp * smp,struct ib_device * device)65de493d47SHal Rosenstock static inline enum smi_action smi_check_local_smp(struct ib_smp *smp,
665e9f71a1SRalph Campbell struct ib_device *device)
671da177e4SLinus Torvalds {
681da177e4SLinus Torvalds /* C14-9:3 -- We're at the end of the DR segment of path */
691da177e4SLinus Torvalds /* C14-9:4 -- Hop Pointer = Hop Count + 1 -> give to SMA/SM */
703023a1e9SKamal Heib return ((device->ops.process_mad &&
711da177e4SLinus Torvalds !ib_get_smp_direction(smp) &&
72de493d47SHal Rosenstock (smp->hop_ptr == smp->hop_cnt + 1)) ?
73de493d47SHal Rosenstock IB_SMI_HANDLE : IB_SMI_DISCARD);
741da177e4SLinus Torvalds }
75727792daSSteve Welch
76727792daSSteve Welch /*
77727792daSSteve Welch * Return IB_SMI_HANDLE if the SMP should be handled by the local SMA/SM
78727792daSSteve Welch * via process_mad
79727792daSSteve Welch */
smi_check_local_returning_smp(struct ib_smp * smp,struct ib_device * device)80727792daSSteve Welch static inline enum smi_action smi_check_local_returning_smp(struct ib_smp *smp,
81727792daSSteve Welch struct ib_device *device)
82727792daSSteve Welch {
83727792daSSteve Welch /* C14-13:3 -- We're at the end of the DR segment of path */
84727792daSSteve Welch /* C14-13:4 -- Hop Pointer == 0 -> give to SM */
853023a1e9SKamal Heib return ((device->ops.process_mad &&
86727792daSSteve Welch ib_get_smp_direction(smp) &&
87727792daSSteve Welch !smp->hop_ptr) ? IB_SMI_HANDLE : IB_SMI_DISCARD);
88727792daSSteve Welch }
89727792daSSteve Welch
901da177e4SLinus Torvalds #endif /* __SMI_H_ */
91