smi.c 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245
  1. /*
  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.
  6. * Copyright (c) 2004-2007 Voltaire Corporation. All rights reserved.
  7. * Copyright (c) 2005 Sun Microsystems, Inc. All rights reserved.
  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. *
  37. */
  38. #include <rdma/ib_smi.h>
  39. #include "smi.h"
  40. /*
  41. * Fixup a directed route SMP for sending
  42. * Return 0 if the SMP should be discarded
  43. */
  44. enum smi_action smi_handle_dr_smp_send(struct ib_smp *smp,
  45. u8 node_type, int port_num)
  46. {
  47. u8 hop_ptr, hop_cnt;
  48. hop_ptr = smp->hop_ptr;
  49. hop_cnt = smp->hop_cnt;
  50. /* See section 14.2.2.2, Vol 1 IB spec */
  51. if (!ib_get_smp_direction(smp)) {
  52. /* C14-9:1 */
  53. if (hop_cnt && hop_ptr == 0) {
  54. smp->hop_ptr++;
  55. return (smp->initial_path[smp->hop_ptr] ==
  56. port_num ? IB_SMI_HANDLE : IB_SMI_DISCARD);
  57. }
  58. /* C14-9:2 */
  59. if (hop_ptr && hop_ptr < hop_cnt) {
  60. if (node_type != RDMA_NODE_IB_SWITCH)
  61. return IB_SMI_DISCARD;
  62. /* smp->return_path set when received */
  63. smp->hop_ptr++;
  64. return (smp->initial_path[smp->hop_ptr] ==
  65. port_num ? IB_SMI_HANDLE : IB_SMI_DISCARD);
  66. }
  67. /* C14-9:3 -- We're at the end of the DR segment of path */
  68. if (hop_ptr == hop_cnt) {
  69. /* smp->return_path set when received */
  70. smp->hop_ptr++;
  71. return (node_type == RDMA_NODE_IB_SWITCH ||
  72. smp->dr_dlid == IB_LID_PERMISSIVE ?
  73. IB_SMI_HANDLE : IB_SMI_DISCARD);
  74. }
  75. /* C14-9:4 -- hop_ptr = hop_cnt + 1 -> give to SMA/SM */
  76. /* C14-9:5 -- Fail unreasonable hop pointer */
  77. return (hop_ptr == hop_cnt + 1 ? IB_SMI_HANDLE : IB_SMI_DISCARD);
  78. } else {
  79. /* C14-13:1 */
  80. if (hop_cnt && hop_ptr == hop_cnt + 1) {
  81. smp->hop_ptr--;
  82. return (smp->return_path[smp->hop_ptr] ==
  83. port_num ? IB_SMI_HANDLE : IB_SMI_DISCARD);
  84. }
  85. /* C14-13:2 */
  86. if (2 <= hop_ptr && hop_ptr <= hop_cnt) {
  87. if (node_type != RDMA_NODE_IB_SWITCH)
  88. return IB_SMI_DISCARD;
  89. smp->hop_ptr--;
  90. return (smp->return_path[smp->hop_ptr] ==
  91. port_num ? IB_SMI_HANDLE : IB_SMI_DISCARD);
  92. }
  93. /* C14-13:3 -- at the end of the DR segment of path */
  94. if (hop_ptr == 1) {
  95. smp->hop_ptr--;
  96. /* C14-13:3 -- SMPs destined for SM shouldn't be here */
  97. return (node_type == RDMA_NODE_IB_SWITCH ||
  98. smp->dr_slid == IB_LID_PERMISSIVE ?
  99. IB_SMI_HANDLE : IB_SMI_DISCARD);
  100. }
  101. /* C14-13:4 -- hop_ptr = 0 -> should have gone to SM */
  102. if (hop_ptr == 0)
  103. return IB_SMI_HANDLE;
  104. /* C14-13:5 -- Check for unreasonable hop pointer */
  105. return IB_SMI_DISCARD;
  106. }
  107. }
  108. /*
  109. * Adjust information for a received SMP
  110. * Return 0 if the SMP should be dropped
  111. */
  112. enum smi_action smi_handle_dr_smp_recv(struct ib_smp *smp, u8 node_type,
  113. int port_num, int phys_port_cnt)
  114. {
  115. u8 hop_ptr, hop_cnt;
  116. hop_ptr = smp->hop_ptr;
  117. hop_cnt = smp->hop_cnt;
  118. /* See section 14.2.2.2, Vol 1 IB spec */
  119. if (!ib_get_smp_direction(smp)) {
  120. /* C14-9:1 -- sender should have incremented hop_ptr */
  121. if (hop_cnt && hop_ptr == 0)
  122. return IB_SMI_DISCARD;
  123. /* C14-9:2 -- intermediate hop */
  124. if (hop_ptr && hop_ptr < hop_cnt) {
  125. if (node_type != RDMA_NODE_IB_SWITCH)
  126. return IB_SMI_DISCARD;
  127. smp->return_path[hop_ptr] = port_num;
  128. /* smp->hop_ptr updated when sending */
  129. return (smp->initial_path[hop_ptr+1] <= phys_port_cnt ?
  130. IB_SMI_HANDLE : IB_SMI_DISCARD);
  131. }
  132. /* C14-9:3 -- We're at the end of the DR segment of path */
  133. if (hop_ptr == hop_cnt) {
  134. if (hop_cnt)
  135. smp->return_path[hop_ptr] = port_num;
  136. /* smp->hop_ptr updated when sending */
  137. return (node_type == RDMA_NODE_IB_SWITCH ||
  138. smp->dr_dlid == IB_LID_PERMISSIVE ?
  139. IB_SMI_HANDLE : IB_SMI_DISCARD);
  140. }
  141. /* C14-9:4 -- hop_ptr = hop_cnt + 1 -> give to SMA/SM */
  142. /* C14-9:5 -- fail unreasonable hop pointer */
  143. return (hop_ptr == hop_cnt + 1 ? IB_SMI_HANDLE : IB_SMI_DISCARD);
  144. } else {
  145. /* C14-13:1 */
  146. if (hop_cnt && hop_ptr == hop_cnt + 1) {
  147. smp->hop_ptr--;
  148. return (smp->return_path[smp->hop_ptr] ==
  149. port_num ? IB_SMI_HANDLE : IB_SMI_DISCARD);
  150. }
  151. /* C14-13:2 */
  152. if (2 <= hop_ptr && hop_ptr <= hop_cnt) {
  153. if (node_type != RDMA_NODE_IB_SWITCH)
  154. return IB_SMI_DISCARD;
  155. /* smp->hop_ptr updated when sending */
  156. return (smp->return_path[hop_ptr-1] <= phys_port_cnt ?
  157. IB_SMI_HANDLE : IB_SMI_DISCARD);
  158. }
  159. /* C14-13:3 -- We're at the end of the DR segment of path */
  160. if (hop_ptr == 1) {
  161. if (smp->dr_slid == IB_LID_PERMISSIVE) {
  162. /* giving SMP to SM - update hop_ptr */
  163. smp->hop_ptr--;
  164. return IB_SMI_HANDLE;
  165. }
  166. /* smp->hop_ptr updated when sending */
  167. return (node_type == RDMA_NODE_IB_SWITCH ?
  168. IB_SMI_HANDLE : IB_SMI_DISCARD);
  169. }
  170. /* C14-13:4 -- hop_ptr = 0 -> give to SM */
  171. /* C14-13:5 -- Check for unreasonable hop pointer */
  172. return (hop_ptr == 0 ? IB_SMI_HANDLE : IB_SMI_DISCARD);
  173. }
  174. }
  175. enum smi_forward_action smi_check_forward_dr_smp(struct ib_smp *smp)
  176. {
  177. u8 hop_ptr, hop_cnt;
  178. hop_ptr = smp->hop_ptr;
  179. hop_cnt = smp->hop_cnt;
  180. if (!ib_get_smp_direction(smp)) {
  181. /* C14-9:2 -- intermediate hop */
  182. if (hop_ptr && hop_ptr < hop_cnt)
  183. return IB_SMI_FORWARD;
  184. /* C14-9:3 -- at the end of the DR segment of path */
  185. if (hop_ptr == hop_cnt)
  186. return (smp->dr_dlid == IB_LID_PERMISSIVE ?
  187. IB_SMI_SEND : IB_SMI_LOCAL);
  188. /* C14-9:4 -- hop_ptr = hop_cnt + 1 -> give to SMA/SM */
  189. if (hop_ptr == hop_cnt + 1)
  190. return IB_SMI_SEND;
  191. } else {
  192. /* C14-13:2 -- intermediate hop */
  193. if (2 <= hop_ptr && hop_ptr <= hop_cnt)
  194. return IB_SMI_FORWARD;
  195. /* C14-13:3 -- at the end of the DR segment of path */
  196. if (hop_ptr == 1)
  197. return (smp->dr_slid != IB_LID_PERMISSIVE ?
  198. IB_SMI_SEND : IB_SMI_LOCAL);
  199. }
  200. return IB_SMI_LOCAL;
  201. }
  202. /*
  203. * Return the forwarding port number from initial_path for outgoing SMP and
  204. * from return_path for returning SMP
  205. */
  206. int smi_get_fwd_port(struct ib_smp *smp)
  207. {
  208. return (!ib_get_smp_direction(smp) ? smp->initial_path[smp->hop_ptr+1] :
  209. smp->return_path[smp->hop_ptr-1]);
  210. }