2 * Copyright (c) 2004 Mellanox Technologies Ltd. All rights reserved.
3 * Copyright (c) 2004 Infinicon Corporation. All rights reserved.
4 * Copyright (c) 2004 Intel Corporation. All rights reserved.
5 * Copyright (c) 2004 Topspin Corporation. All rights reserved.
6 * Copyright (c) 2004 Voltaire Corporation. All rights reserved.
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:
14 * Redistribution and use in source and binary forms, with or
15 * without modification, are permitted provided that the following
18 * - Redistributions of source code must retain the above
19 * copyright notice, this list of conditions and the following
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.
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
36 * $Id: smi.c 1389 2004-12-27 22:56:47Z roland $
43 * Fixup a directed route SMP for sending
44 * Return 0 if the SMP should be discarded
46 int smi_handle_dr_smp_send(struct ib_smp
*smp
,
52 hop_ptr
= smp
->hop_ptr
;
53 hop_cnt
= smp
->hop_cnt
;
55 /* See section 14.2.2.2, Vol 1 IB spec */
56 if (!ib_get_smp_direction(smp
)) {
58 if (hop_cnt
&& hop_ptr
== 0) {
60 return (smp
->initial_path
[smp
->hop_ptr
] ==
65 if (hop_ptr
&& hop_ptr
< hop_cnt
) {
66 if (node_type
!= IB_NODE_SWITCH
)
69 /* smp->return_path set when received */
71 return (smp
->initial_path
[smp
->hop_ptr
] ==
75 /* C14-9:3 -- We're at the end of the DR segment of path */
76 if (hop_ptr
== hop_cnt
) {
77 /* smp->return_path set when received */
79 return (node_type
== IB_NODE_SWITCH
||
80 smp
->dr_dlid
== IB_LID_PERMISSIVE
);
83 /* C14-9:4 -- hop_ptr = hop_cnt + 1 -> give to SMA/SM */
84 /* C14-9:5 -- Fail unreasonable hop pointer */
85 return (hop_ptr
== hop_cnt
+ 1);
89 if (hop_cnt
&& hop_ptr
== hop_cnt
+ 1) {
91 return (smp
->return_path
[smp
->hop_ptr
] ==
96 if (2 <= hop_ptr
&& hop_ptr
<= hop_cnt
) {
97 if (node_type
!= IB_NODE_SWITCH
)
101 return (smp
->return_path
[smp
->hop_ptr
] ==
105 /* C14-13:3 -- at the end of the DR segment of path */
108 /* C14-13:3 -- SMPs destined for SM shouldn't be here */
109 return (node_type
== IB_NODE_SWITCH
||
110 smp
->dr_slid
== IB_LID_PERMISSIVE
);
113 /* C14-13:4 -- hop_ptr = 0 -> should have gone to SM */
117 /* C14-13:5 -- Check for unreasonable hop pointer */
123 * Adjust information for a received SMP
124 * Return 0 if the SMP should be dropped
126 int smi_handle_dr_smp_recv(struct ib_smp
*smp
,
133 hop_ptr
= smp
->hop_ptr
;
134 hop_cnt
= smp
->hop_cnt
;
136 /* See section 14.2.2.2, Vol 1 IB spec */
137 if (!ib_get_smp_direction(smp
)) {
138 /* C14-9:1 -- sender should have incremented hop_ptr */
139 if (hop_cnt
&& hop_ptr
== 0)
142 /* C14-9:2 -- intermediate hop */
143 if (hop_ptr
&& hop_ptr
< hop_cnt
) {
144 if (node_type
!= IB_NODE_SWITCH
)
147 smp
->return_path
[hop_ptr
] = port_num
;
148 /* smp->hop_ptr updated when sending */
149 return (smp
->initial_path
[hop_ptr
+1] <= phys_port_cnt
);
152 /* C14-9:3 -- We're at the end of the DR segment of path */
153 if (hop_ptr
== hop_cnt
) {
155 smp
->return_path
[hop_ptr
] = port_num
;
156 /* smp->hop_ptr updated when sending */
158 return (node_type
== IB_NODE_SWITCH
||
159 smp
->dr_dlid
== IB_LID_PERMISSIVE
);
162 /* C14-9:4 -- hop_ptr = hop_cnt + 1 -> give to SMA/SM */
163 /* C14-9:5 -- fail unreasonable hop pointer */
164 return (hop_ptr
== hop_cnt
+ 1);
169 if (hop_cnt
&& hop_ptr
== hop_cnt
+ 1) {
171 return (smp
->return_path
[smp
->hop_ptr
] ==
176 if (2 <= hop_ptr
&& hop_ptr
<= hop_cnt
) {
177 if (node_type
!= IB_NODE_SWITCH
)
180 /* smp->hop_ptr updated when sending */
181 return (smp
->return_path
[hop_ptr
-1] <= phys_port_cnt
);
184 /* C14-13:3 -- We're at the end of the DR segment of path */
186 if (smp
->dr_slid
== IB_LID_PERMISSIVE
) {
187 /* giving SMP to SM - update hop_ptr */
191 /* smp->hop_ptr updated when sending */
192 return (node_type
== IB_NODE_SWITCH
);
195 /* C14-13:4 -- hop_ptr = 0 -> give to SM */
196 /* C14-13:5 -- Check for unreasonable hop pointer */
197 return (hop_ptr
== 0);
202 * Return 1 if the received DR SMP should be forwarded to the send queue
203 * Return 0 if the SMP should be completed up the stack
205 int smi_check_forward_dr_smp(struct ib_smp
*smp
)
209 hop_ptr
= smp
->hop_ptr
;
210 hop_cnt
= smp
->hop_cnt
;
212 if (!ib_get_smp_direction(smp
)) {
213 /* C14-9:2 -- intermediate hop */
214 if (hop_ptr
&& hop_ptr
< hop_cnt
)
217 /* C14-9:3 -- at the end of the DR segment of path */
218 if (hop_ptr
== hop_cnt
)
219 return (smp
->dr_dlid
== IB_LID_PERMISSIVE
);
221 /* C14-9:4 -- hop_ptr = hop_cnt + 1 -> give to SMA/SM */
222 if (hop_ptr
== hop_cnt
+ 1)
226 if (2 <= hop_ptr
&& hop_ptr
<= hop_cnt
)
229 /* C14-13:3 -- at the end of the DR segment of path */
231 return (smp
->dr_slid
!= IB_LID_PERMISSIVE
);