diff options
author | Hal Rosenstock <halr@voltaire.com> | 2007-04-02 11:24:07 -0400 |
---|---|---|
committer | Roland Dreier <rolandd@cisco.com> | 2007-04-24 19:31:12 -0400 |
commit | de493d47d8b4738827d8914a4dc94058c58f4249 (patch) | |
tree | 3da66e364fe8c1c51ad0a4cbbced337cce6a33d4 /drivers/infiniband/core/smi.c | |
parent | aeba84a9251968a51fc6faae846518aac4e77565 (diff) |
IB/mad: Change SMI to use enums rather than magic return codes
Clarify code by changing return values from SMI functions to named
enum values instead of magic 0/1 values.
Signed-off-by: Hal Rosenstock <halr@voltaire.com>
Signed-off-by: Roland Dreier <rolandd@cisco.com>
Diffstat (limited to 'drivers/infiniband/core/smi.c')
-rw-r--r-- | drivers/infiniband/core/smi.c | 86 |
1 files changed, 43 insertions, 43 deletions
diff --git a/drivers/infiniband/core/smi.c b/drivers/infiniband/core/smi.c index 54b81e17ad5..2bca753eb62 100644 --- a/drivers/infiniband/core/smi.c +++ b/drivers/infiniband/core/smi.c | |||
@@ -3,7 +3,7 @@ | |||
3 | * Copyright (c) 2004, 2005 Infinicon Corporation. All rights reserved. | 3 | * Copyright (c) 2004, 2005 Infinicon Corporation. All rights reserved. |
4 | * Copyright (c) 2004, 2005 Intel Corporation. All rights reserved. | 4 | * Copyright (c) 2004, 2005 Intel Corporation. All rights reserved. |
5 | * Copyright (c) 2004, 2005 Topspin Corporation. All rights reserved. | 5 | * Copyright (c) 2004, 2005 Topspin Corporation. All rights reserved. |
6 | * Copyright (c) 2004, 2005 Voltaire Corporation. All rights reserved. | 6 | * Copyright (c) 2004-2007 Voltaire Corporation. All rights reserved. |
7 | * Copyright (c) 2005 Sun Microsystems, Inc. All rights reserved. | 7 | * Copyright (c) 2005 Sun Microsystems, Inc. All rights reserved. |
8 | * | 8 | * |
9 | * This software is available to you under a choice of one of two | 9 | * This software is available to you under a choice of one of two |
@@ -34,7 +34,6 @@ | |||
34 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | 34 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
35 | * SOFTWARE. | 35 | * SOFTWARE. |
36 | * | 36 | * |
37 | * $Id: smi.c 1389 2004-12-27 22:56:47Z roland $ | ||
38 | */ | 37 | */ |
39 | 38 | ||
40 | #include <rdma/ib_smi.h> | 39 | #include <rdma/ib_smi.h> |
@@ -44,9 +43,8 @@ | |||
44 | * Fixup a directed route SMP for sending | 43 | * Fixup a directed route SMP for sending |
45 | * Return 0 if the SMP should be discarded | 44 | * Return 0 if the SMP should be discarded |
46 | */ | 45 | */ |
47 | int smi_handle_dr_smp_send(struct ib_smp *smp, | 46 | enum smi_action smi_handle_dr_smp_send(struct ib_smp *smp, |
48 | u8 node_type, | 47 | u8 node_type, int port_num) |
49 | int port_num) | ||
50 | { | 48 | { |
51 | u8 hop_ptr, hop_cnt; | 49 | u8 hop_ptr, hop_cnt; |
52 | 50 | ||
@@ -59,18 +57,18 @@ int smi_handle_dr_smp_send(struct ib_smp *smp, | |||
59 | if (hop_cnt && hop_ptr == 0) { | 57 | if (hop_cnt && hop_ptr == 0) { |
60 | smp->hop_ptr++; | 58 | smp->hop_ptr++; |
61 | return (smp->initial_path[smp->hop_ptr] == | 59 | return (smp->initial_path[smp->hop_ptr] == |
62 | port_num); | 60 | port_num ? IB_SMI_HANDLE : IB_SMI_DISCARD); |
63 | } | 61 | } |
64 | 62 | ||
65 | /* C14-9:2 */ | 63 | /* C14-9:2 */ |
66 | if (hop_ptr && hop_ptr < hop_cnt) { | 64 | if (hop_ptr && hop_ptr < hop_cnt) { |
67 | if (node_type != RDMA_NODE_IB_SWITCH) | 65 | if (node_type != RDMA_NODE_IB_SWITCH) |
68 | return 0; | 66 | return IB_SMI_DISCARD; |
69 | 67 | ||
70 | /* smp->return_path set when received */ | 68 | /* smp->return_path set when received */ |
71 | smp->hop_ptr++; | 69 | smp->hop_ptr++; |
72 | return (smp->initial_path[smp->hop_ptr] == | 70 | return (smp->initial_path[smp->hop_ptr] == |
73 | port_num); | 71 | port_num ? IB_SMI_HANDLE : IB_SMI_DISCARD); |
74 | } | 72 | } |
75 | 73 | ||
76 | /* C14-9:3 -- We're at the end of the DR segment of path */ | 74 | /* C14-9:3 -- We're at the end of the DR segment of path */ |
@@ -78,29 +76,30 @@ int smi_handle_dr_smp_send(struct ib_smp *smp, | |||
78 | /* smp->return_path set when received */ | 76 | /* smp->return_path set when received */ |
79 | smp->hop_ptr++; | 77 | smp->hop_ptr++; |
80 | return (node_type == RDMA_NODE_IB_SWITCH || | 78 | return (node_type == RDMA_NODE_IB_SWITCH || |
81 | smp->dr_dlid == IB_LID_PERMISSIVE); | 79 | smp->dr_dlid == IB_LID_PERMISSIVE ? |
80 | IB_SMI_HANDLE : IB_SMI_DISCARD); | ||
82 | } | 81 | } |
83 | 82 | ||
84 | /* C14-9:4 -- hop_ptr = hop_cnt + 1 -> give to SMA/SM */ | 83 | /* C14-9:4 -- hop_ptr = hop_cnt + 1 -> give to SMA/SM */ |
85 | /* C14-9:5 -- Fail unreasonable hop pointer */ | 84 | /* C14-9:5 -- Fail unreasonable hop pointer */ |
86 | return (hop_ptr == hop_cnt + 1); | 85 | return (hop_ptr == hop_cnt + 1 ? IB_SMI_HANDLE : IB_SMI_DISCARD); |
87 | 86 | ||
88 | } else { | 87 | } else { |
89 | /* C14-13:1 */ | 88 | /* C14-13:1 */ |
90 | if (hop_cnt && hop_ptr == hop_cnt + 1) { | 89 | if (hop_cnt && hop_ptr == hop_cnt + 1) { |
91 | smp->hop_ptr--; | 90 | smp->hop_ptr--; |
92 | return (smp->return_path[smp->hop_ptr] == | 91 | return (smp->return_path[smp->hop_ptr] == |
93 | port_num); | 92 | port_num ? IB_SMI_HANDLE : IB_SMI_DISCARD); |
94 | } | 93 | } |
95 | 94 | ||
96 | /* C14-13:2 */ | 95 | /* C14-13:2 */ |
97 | if (2 <= hop_ptr && hop_ptr <= hop_cnt) { | 96 | if (2 <= hop_ptr && hop_ptr <= hop_cnt) { |
98 | if (node_type != RDMA_NODE_IB_SWITCH) | 97 | if (node_type != RDMA_NODE_IB_SWITCH) |
99 | return 0; | 98 | return IB_SMI_DISCARD; |
100 | 99 | ||
101 | smp->hop_ptr--; | 100 | smp->hop_ptr--; |
102 | return (smp->return_path[smp->hop_ptr] == | 101 | return (smp->return_path[smp->hop_ptr] == |
103 | port_num); | 102 | port_num ? IB_SMI_HANDLE : IB_SMI_DISCARD); |
104 | } | 103 | } |
105 | 104 | ||
106 | /* C14-13:3 -- at the end of the DR segment of path */ | 105 | /* C14-13:3 -- at the end of the DR segment of path */ |
@@ -108,15 +107,16 @@ int smi_handle_dr_smp_send(struct ib_smp *smp, | |||
108 | smp->hop_ptr--; | 107 | smp->hop_ptr--; |
109 | /* C14-13:3 -- SMPs destined for SM shouldn't be here */ | 108 | /* C14-13:3 -- SMPs destined for SM shouldn't be here */ |
110 | return (node_type == RDMA_NODE_IB_SWITCH || | 109 | return (node_type == RDMA_NODE_IB_SWITCH || |
111 | smp->dr_slid == IB_LID_PERMISSIVE); | 110 | smp->dr_slid == IB_LID_PERMISSIVE ? |
111 | IB_SMI_HANDLE : IB_SMI_DISCARD); | ||
112 | } | 112 | } |
113 | 113 | ||
114 | /* C14-13:4 -- hop_ptr = 0 -> should have gone to SM */ | 114 | /* C14-13:4 -- hop_ptr = 0 -> should have gone to SM */ |
115 | if (hop_ptr == 0) | 115 | if (hop_ptr == 0) |
116 | return 1; | 116 | return IB_SMI_HANDLE; |
117 | 117 | ||
118 | /* C14-13:5 -- Check for unreasonable hop pointer */ | 118 | /* C14-13:5 -- Check for unreasonable hop pointer */ |
119 | return 0; | 119 | return IB_SMI_DISCARD; |
120 | } | 120 | } |
121 | } | 121 | } |
122 | 122 | ||
@@ -124,10 +124,8 @@ int smi_handle_dr_smp_send(struct ib_smp *smp, | |||
124 | * Adjust information for a received SMP | 124 | * Adjust information for a received SMP |
125 | * Return 0 if the SMP should be dropped | 125 | * Return 0 if the SMP should be dropped |
126 | */ | 126 | */ |
127 | int smi_handle_dr_smp_recv(struct ib_smp *smp, | 127 | enum smi_action smi_handle_dr_smp_recv(struct ib_smp *smp, u8 node_type, |
128 | u8 node_type, | 128 | int port_num, int phys_port_cnt) |
129 | int port_num, | ||
130 | int phys_port_cnt) | ||
131 | { | 129 | { |
132 | u8 hop_ptr, hop_cnt; | 130 | u8 hop_ptr, hop_cnt; |
133 | 131 | ||
@@ -138,16 +136,17 @@ int smi_handle_dr_smp_recv(struct ib_smp *smp, | |||
138 | if (!ib_get_smp_direction(smp)) { | 136 | if (!ib_get_smp_direction(smp)) { |
139 | /* C14-9:1 -- sender should have incremented hop_ptr */ | 137 | /* C14-9:1 -- sender should have incremented hop_ptr */ |
140 | if (hop_cnt && hop_ptr == 0) | 138 | if (hop_cnt && hop_ptr == 0) |
141 | return 0; | 139 | return IB_SMI_DISCARD; |
142 | 140 | ||
143 | /* C14-9:2 -- intermediate hop */ | 141 | /* C14-9:2 -- intermediate hop */ |
144 | if (hop_ptr && hop_ptr < hop_cnt) { | 142 | if (hop_ptr && hop_ptr < hop_cnt) { |
145 | if (node_type != RDMA_NODE_IB_SWITCH) | 143 | if (node_type != RDMA_NODE_IB_SWITCH) |
146 | return 0; | 144 | return IB_SMI_DISCARD; |
147 | 145 | ||
148 | smp->return_path[hop_ptr] = port_num; | 146 | smp->return_path[hop_ptr] = port_num; |
149 | /* smp->hop_ptr updated when sending */ | 147 | /* smp->hop_ptr updated when sending */ |
150 | return (smp->initial_path[hop_ptr+1] <= phys_port_cnt); | 148 | return (smp->initial_path[hop_ptr+1] <= phys_port_cnt ? |
149 | IB_SMI_HANDLE : IB_SMI_DISCARD); | ||
151 | } | 150 | } |
152 | 151 | ||
153 | /* C14-9:3 -- We're at the end of the DR segment of path */ | 152 | /* C14-9:3 -- We're at the end of the DR segment of path */ |
@@ -157,12 +156,13 @@ int smi_handle_dr_smp_recv(struct ib_smp *smp, | |||
157 | /* smp->hop_ptr updated when sending */ | 156 | /* smp->hop_ptr updated when sending */ |
158 | 157 | ||
159 | return (node_type == RDMA_NODE_IB_SWITCH || | 158 | return (node_type == RDMA_NODE_IB_SWITCH || |
160 | smp->dr_dlid == IB_LID_PERMISSIVE); | 159 | smp->dr_dlid == IB_LID_PERMISSIVE ? |
160 | IB_SMI_HANDLE : IB_SMI_DISCARD); | ||
161 | } | 161 | } |
162 | 162 | ||
163 | /* C14-9:4 -- hop_ptr = hop_cnt + 1 -> give to SMA/SM */ | 163 | /* C14-9:4 -- hop_ptr = hop_cnt + 1 -> give to SMA/SM */ |
164 | /* C14-9:5 -- fail unreasonable hop pointer */ | 164 | /* C14-9:5 -- fail unreasonable hop pointer */ |
165 | return (hop_ptr == hop_cnt + 1); | 165 | return (hop_ptr == hop_cnt + 1 ? IB_SMI_HANDLE : IB_SMI_DISCARD); |
166 | 166 | ||
167 | } else { | 167 | } else { |
168 | 168 | ||
@@ -170,16 +170,17 @@ int smi_handle_dr_smp_recv(struct ib_smp *smp, | |||
170 | if (hop_cnt && hop_ptr == hop_cnt + 1) { | 170 | if (hop_cnt && hop_ptr == hop_cnt + 1) { |
171 | smp->hop_ptr--; | 171 | smp->hop_ptr--; |
172 | return (smp->return_path[smp->hop_ptr] == | 172 | return (smp->return_path[smp->hop_ptr] == |
173 | port_num); | 173 | port_num ? IB_SMI_HANDLE : IB_SMI_DISCARD); |
174 | } | 174 | } |
175 | 175 | ||
176 | /* C14-13:2 */ | 176 | /* C14-13:2 */ |
177 | if (2 <= hop_ptr && hop_ptr <= hop_cnt) { | 177 | if (2 <= hop_ptr && hop_ptr <= hop_cnt) { |
178 | if (node_type != RDMA_NODE_IB_SWITCH) | 178 | if (node_type != RDMA_NODE_IB_SWITCH) |
179 | return 0; | 179 | return IB_SMI_DISCARD; |
180 | 180 | ||
181 | /* smp->hop_ptr updated when sending */ | 181 | /* smp->hop_ptr updated when sending */ |
182 | return (smp->return_path[hop_ptr-1] <= phys_port_cnt); | 182 | return (smp->return_path[hop_ptr-1] <= phys_port_cnt ? |
183 | IB_SMI_HANDLE : IB_SMI_DISCARD); | ||
183 | } | 184 | } |
184 | 185 | ||
185 | /* C14-13:3 -- We're at the end of the DR segment of path */ | 186 | /* C14-13:3 -- We're at the end of the DR segment of path */ |
@@ -187,23 +188,20 @@ int smi_handle_dr_smp_recv(struct ib_smp *smp, | |||
187 | if (smp->dr_slid == IB_LID_PERMISSIVE) { | 188 | if (smp->dr_slid == IB_LID_PERMISSIVE) { |
188 | /* giving SMP to SM - update hop_ptr */ | 189 | /* giving SMP to SM - update hop_ptr */ |
189 | smp->hop_ptr--; | 190 | smp->hop_ptr--; |
190 | return 1; | 191 | return IB_SMI_HANDLE; |
191 | } | 192 | } |
192 | /* smp->hop_ptr updated when sending */ | 193 | /* smp->hop_ptr updated when sending */ |
193 | return (node_type == RDMA_NODE_IB_SWITCH); | 194 | return (node_type == RDMA_NODE_IB_SWITCH ? |
195 | IB_SMI_HANDLE: IB_SMI_DISCARD); | ||
194 | } | 196 | } |
195 | 197 | ||
196 | /* C14-13:4 -- hop_ptr = 0 -> give to SM */ | 198 | /* C14-13:4 -- hop_ptr = 0 -> give to SM */ |
197 | /* C14-13:5 -- Check for unreasonable hop pointer */ | 199 | /* C14-13:5 -- Check for unreasonable hop pointer */ |
198 | return (hop_ptr == 0); | 200 | return (hop_ptr == 0 ? IB_SMI_HANDLE : IB_SMI_DISCARD); |
199 | } | 201 | } |
200 | } | 202 | } |
201 | 203 | ||
202 | /* | 204 | enum smi_forward_action smi_check_forward_dr_smp(struct ib_smp *smp) |
203 | * Return 1 if the received DR SMP should be forwarded to the send queue | ||
204 | * Return 0 if the SMP should be completed up the stack | ||
205 | */ | ||
206 | int smi_check_forward_dr_smp(struct ib_smp *smp) | ||
207 | { | 205 | { |
208 | u8 hop_ptr, hop_cnt; | 206 | u8 hop_ptr, hop_cnt; |
209 | 207 | ||
@@ -213,23 +211,25 @@ int smi_check_forward_dr_smp(struct ib_smp *smp) | |||
213 | if (!ib_get_smp_direction(smp)) { | 211 | if (!ib_get_smp_direction(smp)) { |
214 | /* C14-9:2 -- intermediate hop */ | 212 | /* C14-9:2 -- intermediate hop */ |
215 | if (hop_ptr && hop_ptr < hop_cnt) | 213 | if (hop_ptr && hop_ptr < hop_cnt) |
216 | return 1; | 214 | return IB_SMI_SEND; |
217 | 215 | ||
218 | /* C14-9:3 -- at the end of the DR segment of path */ | 216 | /* C14-9:3 -- at the end of the DR segment of path */ |
219 | if (hop_ptr == hop_cnt) | 217 | if (hop_ptr == hop_cnt) |
220 | return (smp->dr_dlid == IB_LID_PERMISSIVE); | 218 | return (smp->dr_dlid == IB_LID_PERMISSIVE ? |
219 | IB_SMI_SEND : IB_SMI_LOCAL); | ||
221 | 220 | ||
222 | /* C14-9:4 -- hop_ptr = hop_cnt + 1 -> give to SMA/SM */ | 221 | /* C14-9:4 -- hop_ptr = hop_cnt + 1 -> give to SMA/SM */ |
223 | if (hop_ptr == hop_cnt + 1) | 222 | if (hop_ptr == hop_cnt + 1) |
224 | return 1; | 223 | return IB_SMI_SEND; |
225 | } else { | 224 | } else { |
226 | /* C14-13:2 */ | 225 | /* C14-13:2 -- intermediate hop */ |
227 | if (2 <= hop_ptr && hop_ptr <= hop_cnt) | 226 | if (2 <= hop_ptr && hop_ptr <= hop_cnt) |
228 | return 1; | 227 | return IB_SMI_SEND; |
229 | 228 | ||
230 | /* C14-13:3 -- at the end of the DR segment of path */ | 229 | /* C14-13:3 -- at the end of the DR segment of path */ |
231 | if (hop_ptr == 1) | 230 | if (hop_ptr == 1) |
232 | return (smp->dr_slid != IB_LID_PERMISSIVE); | 231 | return (smp->dr_slid != IB_LID_PERMISSIVE ? |
232 | IB_SMI_SEND : IB_SMI_LOCAL); | ||
233 | } | 233 | } |
234 | return 0; | 234 | return IB_SMI_LOCAL; |
235 | } | 235 | } |