Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
Roland Dreier | 2a1d9b7 | 2005-08-10 23:03:10 -0700 | [diff] [blame] | 2 | * Copyright (c) 2004, 2005 Mellanox Technologies Ltd. All rights reserved. |
| 3 | * Copyright (c) 2004, 2005 Infinicon Corporation. All rights reserved. |
| 4 | * Copyright (c) 2004, 2005 Intel Corporation. All rights reserved. |
| 5 | * Copyright (c) 2004, 2005 Topspin Corporation. All rights reserved. |
Hal Rosenstock | de493d4 | 2007-04-02 11:24:07 -0400 | [diff] [blame] | 6 | * Copyright (c) 2004-2007 Voltaire Corporation. All rights reserved. |
Roland Dreier | 2a1d9b7 | 2005-08-10 23:03:10 -0700 | [diff] [blame] | 7 | * Copyright (c) 2005 Sun Microsystems, Inc. All rights reserved. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8 | * |
| 9 | * This software is available to you under a choice of one of two |
| 10 | * licenses. You may choose to be licensed under the terms of the GNU |
| 11 | * General Public License (GPL) Version 2, available from the file |
| 12 | * COPYING in the main directory of this source tree, or the |
| 13 | * OpenIB.org BSD license below: |
| 14 | * |
| 15 | * Redistribution and use in source and binary forms, with or |
| 16 | * without modification, are permitted provided that the following |
| 17 | * conditions are met: |
| 18 | * |
| 19 | * - Redistributions of source code must retain the above |
| 20 | * copyright notice, this list of conditions and the following |
| 21 | * disclaimer. |
| 22 | * |
| 23 | * - Redistributions in binary form must reproduce the above |
| 24 | * copyright notice, this list of conditions and the following |
| 25 | * disclaimer in the documentation and/or other materials |
| 26 | * provided with the distribution. |
| 27 | * |
| 28 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, |
| 29 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
| 30 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
| 31 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS |
| 32 | * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN |
| 33 | * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN |
| 34 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
| 35 | * SOFTWARE. |
| 36 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 37 | */ |
| 38 | |
Roland Dreier | a4d61e8 | 2005-08-25 13:40:04 -0700 | [diff] [blame] | 39 | #include <rdma/ib_smi.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 40 | #include "smi.h" |
| 41 | |
| 42 | /* |
| 43 | * Fixup a directed route SMP for sending |
| 44 | * Return 0 if the SMP should be discarded |
| 45 | */ |
Hal Rosenstock | de493d4 | 2007-04-02 11:24:07 -0400 | [diff] [blame] | 46 | enum smi_action smi_handle_dr_smp_send(struct ib_smp *smp, |
| 47 | u8 node_type, int port_num) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 48 | { |
| 49 | u8 hop_ptr, hop_cnt; |
| 50 | |
| 51 | hop_ptr = smp->hop_ptr; |
| 52 | hop_cnt = smp->hop_cnt; |
| 53 | |
| 54 | /* See section 14.2.2.2, Vol 1 IB spec */ |
Roland Dreier | 60f2b65 | 2009-09-05 20:24:10 -0700 | [diff] [blame] | 55 | /* C14-6 -- valid hop_cnt values are from 0 to 63 */ |
| 56 | if (hop_cnt >= IB_SMP_MAX_PATH_HOPS) |
| 57 | return IB_SMI_DISCARD; |
| 58 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 59 | if (!ib_get_smp_direction(smp)) { |
| 60 | /* C14-9:1 */ |
| 61 | if (hop_cnt && hop_ptr == 0) { |
| 62 | smp->hop_ptr++; |
| 63 | return (smp->initial_path[smp->hop_ptr] == |
Hal Rosenstock | de493d4 | 2007-04-02 11:24:07 -0400 | [diff] [blame] | 64 | port_num ? IB_SMI_HANDLE : IB_SMI_DISCARD); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 65 | } |
| 66 | |
| 67 | /* C14-9:2 */ |
| 68 | if (hop_ptr && hop_ptr < hop_cnt) { |
Tom Tucker | 07ebafb | 2006-08-03 16:02:42 -0500 | [diff] [blame] | 69 | if (node_type != RDMA_NODE_IB_SWITCH) |
Hal Rosenstock | de493d4 | 2007-04-02 11:24:07 -0400 | [diff] [blame] | 70 | return IB_SMI_DISCARD; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 71 | |
| 72 | /* smp->return_path set when received */ |
| 73 | smp->hop_ptr++; |
| 74 | return (smp->initial_path[smp->hop_ptr] == |
Hal Rosenstock | de493d4 | 2007-04-02 11:24:07 -0400 | [diff] [blame] | 75 | port_num ? IB_SMI_HANDLE : IB_SMI_DISCARD); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 76 | } |
| 77 | |
| 78 | /* C14-9:3 -- We're at the end of the DR segment of path */ |
| 79 | if (hop_ptr == hop_cnt) { |
| 80 | /* smp->return_path set when received */ |
| 81 | smp->hop_ptr++; |
Tom Tucker | 07ebafb | 2006-08-03 16:02:42 -0500 | [diff] [blame] | 82 | return (node_type == RDMA_NODE_IB_SWITCH || |
Hal Rosenstock | de493d4 | 2007-04-02 11:24:07 -0400 | [diff] [blame] | 83 | smp->dr_dlid == IB_LID_PERMISSIVE ? |
| 84 | IB_SMI_HANDLE : IB_SMI_DISCARD); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 85 | } |
| 86 | |
| 87 | /* C14-9:4 -- hop_ptr = hop_cnt + 1 -> give to SMA/SM */ |
| 88 | /* C14-9:5 -- Fail unreasonable hop pointer */ |
Hal Rosenstock | de493d4 | 2007-04-02 11:24:07 -0400 | [diff] [blame] | 89 | return (hop_ptr == hop_cnt + 1 ? IB_SMI_HANDLE : IB_SMI_DISCARD); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 90 | |
| 91 | } else { |
| 92 | /* C14-13:1 */ |
| 93 | if (hop_cnt && hop_ptr == hop_cnt + 1) { |
| 94 | smp->hop_ptr--; |
| 95 | return (smp->return_path[smp->hop_ptr] == |
Hal Rosenstock | de493d4 | 2007-04-02 11:24:07 -0400 | [diff] [blame] | 96 | port_num ? IB_SMI_HANDLE : IB_SMI_DISCARD); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 97 | } |
| 98 | |
| 99 | /* C14-13:2 */ |
| 100 | if (2 <= hop_ptr && hop_ptr <= hop_cnt) { |
Tom Tucker | 07ebafb | 2006-08-03 16:02:42 -0500 | [diff] [blame] | 101 | if (node_type != RDMA_NODE_IB_SWITCH) |
Hal Rosenstock | de493d4 | 2007-04-02 11:24:07 -0400 | [diff] [blame] | 102 | return IB_SMI_DISCARD; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 103 | |
| 104 | smp->hop_ptr--; |
| 105 | return (smp->return_path[smp->hop_ptr] == |
Hal Rosenstock | de493d4 | 2007-04-02 11:24:07 -0400 | [diff] [blame] | 106 | port_num ? IB_SMI_HANDLE : IB_SMI_DISCARD); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 107 | } |
| 108 | |
| 109 | /* C14-13:3 -- at the end of the DR segment of path */ |
| 110 | if (hop_ptr == 1) { |
| 111 | smp->hop_ptr--; |
| 112 | /* C14-13:3 -- SMPs destined for SM shouldn't be here */ |
Tom Tucker | 07ebafb | 2006-08-03 16:02:42 -0500 | [diff] [blame] | 113 | return (node_type == RDMA_NODE_IB_SWITCH || |
Hal Rosenstock | de493d4 | 2007-04-02 11:24:07 -0400 | [diff] [blame] | 114 | smp->dr_slid == IB_LID_PERMISSIVE ? |
| 115 | IB_SMI_HANDLE : IB_SMI_DISCARD); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 116 | } |
| 117 | |
| 118 | /* C14-13:4 -- hop_ptr = 0 -> should have gone to SM */ |
| 119 | if (hop_ptr == 0) |
Hal Rosenstock | de493d4 | 2007-04-02 11:24:07 -0400 | [diff] [blame] | 120 | return IB_SMI_HANDLE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 121 | |
| 122 | /* C14-13:5 -- Check for unreasonable hop pointer */ |
Hal Rosenstock | de493d4 | 2007-04-02 11:24:07 -0400 | [diff] [blame] | 123 | return IB_SMI_DISCARD; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 124 | } |
| 125 | } |
| 126 | |
| 127 | /* |
| 128 | * Adjust information for a received SMP |
| 129 | * Return 0 if the SMP should be dropped |
| 130 | */ |
Hal Rosenstock | de493d4 | 2007-04-02 11:24:07 -0400 | [diff] [blame] | 131 | enum smi_action smi_handle_dr_smp_recv(struct ib_smp *smp, u8 node_type, |
| 132 | int port_num, int phys_port_cnt) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 133 | { |
| 134 | u8 hop_ptr, hop_cnt; |
| 135 | |
| 136 | hop_ptr = smp->hop_ptr; |
| 137 | hop_cnt = smp->hop_cnt; |
| 138 | |
| 139 | /* See section 14.2.2.2, Vol 1 IB spec */ |
Roland Dreier | 60f2b65 | 2009-09-05 20:24:10 -0700 | [diff] [blame] | 140 | /* C14-6 -- valid hop_cnt values are from 0 to 63 */ |
| 141 | if (hop_cnt >= IB_SMP_MAX_PATH_HOPS) |
| 142 | return IB_SMI_DISCARD; |
| 143 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 144 | if (!ib_get_smp_direction(smp)) { |
| 145 | /* C14-9:1 -- sender should have incremented hop_ptr */ |
| 146 | if (hop_cnt && hop_ptr == 0) |
Hal Rosenstock | de493d4 | 2007-04-02 11:24:07 -0400 | [diff] [blame] | 147 | return IB_SMI_DISCARD; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 148 | |
| 149 | /* C14-9:2 -- intermediate hop */ |
| 150 | if (hop_ptr && hop_ptr < hop_cnt) { |
Tom Tucker | 07ebafb | 2006-08-03 16:02:42 -0500 | [diff] [blame] | 151 | if (node_type != RDMA_NODE_IB_SWITCH) |
Hal Rosenstock | de493d4 | 2007-04-02 11:24:07 -0400 | [diff] [blame] | 152 | return IB_SMI_DISCARD; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 153 | |
| 154 | smp->return_path[hop_ptr] = port_num; |
| 155 | /* smp->hop_ptr updated when sending */ |
Hal Rosenstock | de493d4 | 2007-04-02 11:24:07 -0400 | [diff] [blame] | 156 | return (smp->initial_path[hop_ptr+1] <= phys_port_cnt ? |
| 157 | IB_SMI_HANDLE : IB_SMI_DISCARD); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 158 | } |
| 159 | |
| 160 | /* C14-9:3 -- We're at the end of the DR segment of path */ |
| 161 | if (hop_ptr == hop_cnt) { |
| 162 | if (hop_cnt) |
| 163 | smp->return_path[hop_ptr] = port_num; |
| 164 | /* smp->hop_ptr updated when sending */ |
| 165 | |
Tom Tucker | 07ebafb | 2006-08-03 16:02:42 -0500 | [diff] [blame] | 166 | return (node_type == RDMA_NODE_IB_SWITCH || |
Hal Rosenstock | de493d4 | 2007-04-02 11:24:07 -0400 | [diff] [blame] | 167 | smp->dr_dlid == IB_LID_PERMISSIVE ? |
| 168 | IB_SMI_HANDLE : IB_SMI_DISCARD); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 169 | } |
| 170 | |
| 171 | /* C14-9:4 -- hop_ptr = hop_cnt + 1 -> give to SMA/SM */ |
| 172 | /* C14-9:5 -- fail unreasonable hop pointer */ |
Hal Rosenstock | de493d4 | 2007-04-02 11:24:07 -0400 | [diff] [blame] | 173 | return (hop_ptr == hop_cnt + 1 ? IB_SMI_HANDLE : IB_SMI_DISCARD); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 174 | |
| 175 | } else { |
| 176 | |
| 177 | /* C14-13:1 */ |
| 178 | if (hop_cnt && hop_ptr == hop_cnt + 1) { |
| 179 | smp->hop_ptr--; |
| 180 | return (smp->return_path[smp->hop_ptr] == |
Hal Rosenstock | de493d4 | 2007-04-02 11:24:07 -0400 | [diff] [blame] | 181 | port_num ? IB_SMI_HANDLE : IB_SMI_DISCARD); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 182 | } |
| 183 | |
| 184 | /* C14-13:2 */ |
| 185 | if (2 <= hop_ptr && hop_ptr <= hop_cnt) { |
Tom Tucker | 07ebafb | 2006-08-03 16:02:42 -0500 | [diff] [blame] | 186 | if (node_type != RDMA_NODE_IB_SWITCH) |
Hal Rosenstock | de493d4 | 2007-04-02 11:24:07 -0400 | [diff] [blame] | 187 | return IB_SMI_DISCARD; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 188 | |
| 189 | /* smp->hop_ptr updated when sending */ |
Hal Rosenstock | de493d4 | 2007-04-02 11:24:07 -0400 | [diff] [blame] | 190 | return (smp->return_path[hop_ptr-1] <= phys_port_cnt ? |
| 191 | IB_SMI_HANDLE : IB_SMI_DISCARD); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 192 | } |
| 193 | |
| 194 | /* C14-13:3 -- We're at the end of the DR segment of path */ |
| 195 | if (hop_ptr == 1) { |
| 196 | if (smp->dr_slid == IB_LID_PERMISSIVE) { |
| 197 | /* giving SMP to SM - update hop_ptr */ |
| 198 | smp->hop_ptr--; |
Hal Rosenstock | de493d4 | 2007-04-02 11:24:07 -0400 | [diff] [blame] | 199 | return IB_SMI_HANDLE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 200 | } |
| 201 | /* smp->hop_ptr updated when sending */ |
Hal Rosenstock | de493d4 | 2007-04-02 11:24:07 -0400 | [diff] [blame] | 202 | return (node_type == RDMA_NODE_IB_SWITCH ? |
Hal Rosenstock | 1bae4db | 2007-05-14 17:21:52 -0400 | [diff] [blame] | 203 | IB_SMI_HANDLE : IB_SMI_DISCARD); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 204 | } |
| 205 | |
| 206 | /* C14-13:4 -- hop_ptr = 0 -> give to SM */ |
| 207 | /* C14-13:5 -- Check for unreasonable hop pointer */ |
Hal Rosenstock | de493d4 | 2007-04-02 11:24:07 -0400 | [diff] [blame] | 208 | return (hop_ptr == 0 ? IB_SMI_HANDLE : IB_SMI_DISCARD); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 209 | } |
| 210 | } |
| 211 | |
Hal Rosenstock | de493d4 | 2007-04-02 11:24:07 -0400 | [diff] [blame] | 212 | enum smi_forward_action smi_check_forward_dr_smp(struct ib_smp *smp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 213 | { |
| 214 | u8 hop_ptr, hop_cnt; |
| 215 | |
| 216 | hop_ptr = smp->hop_ptr; |
| 217 | hop_cnt = smp->hop_cnt; |
| 218 | |
| 219 | if (!ib_get_smp_direction(smp)) { |
| 220 | /* C14-9:2 -- intermediate hop */ |
| 221 | if (hop_ptr && hop_ptr < hop_cnt) |
Hal Rosenstock | 1bae4db | 2007-05-14 17:21:52 -0400 | [diff] [blame] | 222 | return IB_SMI_FORWARD; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 223 | |
| 224 | /* C14-9:3 -- at the end of the DR segment of path */ |
| 225 | if (hop_ptr == hop_cnt) |
Hal Rosenstock | de493d4 | 2007-04-02 11:24:07 -0400 | [diff] [blame] | 226 | return (smp->dr_dlid == IB_LID_PERMISSIVE ? |
| 227 | IB_SMI_SEND : IB_SMI_LOCAL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 228 | |
| 229 | /* C14-9:4 -- hop_ptr = hop_cnt + 1 -> give to SMA/SM */ |
| 230 | if (hop_ptr == hop_cnt + 1) |
Hal Rosenstock | de493d4 | 2007-04-02 11:24:07 -0400 | [diff] [blame] | 231 | return IB_SMI_SEND; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 232 | } else { |
Hal Rosenstock | de493d4 | 2007-04-02 11:24:07 -0400 | [diff] [blame] | 233 | /* C14-13:2 -- intermediate hop */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 234 | if (2 <= hop_ptr && hop_ptr <= hop_cnt) |
Hal Rosenstock | 1bae4db | 2007-05-14 17:21:52 -0400 | [diff] [blame] | 235 | return IB_SMI_FORWARD; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 236 | |
| 237 | /* C14-13:3 -- at the end of the DR segment of path */ |
| 238 | if (hop_ptr == 1) |
Hal Rosenstock | de493d4 | 2007-04-02 11:24:07 -0400 | [diff] [blame] | 239 | return (smp->dr_slid != IB_LID_PERMISSIVE ? |
| 240 | IB_SMI_SEND : IB_SMI_LOCAL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 241 | } |
Hal Rosenstock | de493d4 | 2007-04-02 11:24:07 -0400 | [diff] [blame] | 242 | return IB_SMI_LOCAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 243 | } |
Hal Rosenstock | 1bae4db | 2007-05-14 17:21:52 -0400 | [diff] [blame] | 244 | |
| 245 | /* |
| 246 | * Return the forwarding port number from initial_path for outgoing SMP and |
| 247 | * from return_path for returning SMP |
| 248 | */ |
| 249 | int smi_get_fwd_port(struct ib_smp *smp) |
| 250 | { |
| 251 | return (!ib_get_smp_direction(smp) ? smp->initial_path[smp->hop_ptr+1] : |
| 252 | smp->return_path[smp->hop_ptr-1]); |
| 253 | } |