smi.c 6.4 KB

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