smi.c 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234
  1. /*
  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.
  7. *
  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:
  13. *
  14. * Redistribution and use in source and binary forms, with or
  15. * without modification, are permitted provided that the following
  16. * conditions are met:
  17. *
  18. * - Redistributions of source code must retain the above
  19. * copyright notice, this list of conditions and the following
  20. * disclaimer.
  21. *
  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.
  26. *
  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
  34. * SOFTWARE.
  35. *
  36. * $Id: smi.c 1389 2004-12-27 22:56:47Z roland $
  37. */
  38. #include <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. int smi_handle_dr_smp_send(struct ib_smp *smp,
  45. u8 node_type,
  46. int port_num)
  47. {
  48. u8 hop_ptr, hop_cnt;
  49. hop_ptr = smp->hop_ptr;
  50. hop_cnt = smp->hop_cnt;
  51. /* See section 14.2.2.2, Vol 1 IB spec */
  52. if (!ib_get_smp_direction(smp)) {
  53. /* C14-9:1 */
  54. if (hop_cnt && hop_ptr == 0) {
  55. smp->hop_ptr++;
  56. return (smp->initial_path[smp->hop_ptr] ==
  57. port_num);
  58. }
  59. /* C14-9:2 */
  60. if (hop_ptr && hop_ptr < hop_cnt) {
  61. if (node_type != IB_NODE_SWITCH)
  62. return 0;
  63. /* smp->return_path set when received */
  64. smp->hop_ptr++;
  65. return (smp->initial_path[smp->hop_ptr] ==
  66. port_num);
  67. }
  68. /* C14-9:3 -- We're at the end of the DR segment of path */
  69. if (hop_ptr == hop_cnt) {
  70. /* smp->return_path set when received */
  71. smp->hop_ptr++;
  72. return (node_type == IB_NODE_SWITCH ||
  73. smp->dr_dlid == IB_LID_PERMISSIVE);
  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);
  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);
  84. }
  85. /* C14-13:2 */
  86. if (2 <= hop_ptr && hop_ptr <= hop_cnt) {
  87. if (node_type != IB_NODE_SWITCH)
  88. return 0;
  89. smp->hop_ptr--;
  90. return (smp->return_path[smp->hop_ptr] ==
  91. port_num);
  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 == IB_NODE_SWITCH ||
  98. smp->dr_slid == IB_LID_PERMISSIVE);
  99. }
  100. /* C14-13:4 -- hop_ptr = 0 -> should have gone to SM */
  101. if (hop_ptr == 0)
  102. return 1;
  103. /* C14-13:5 -- Check for unreasonable hop pointer */
  104. return 0;
  105. }
  106. }
  107. /*
  108. * Adjust information for a received SMP
  109. * Return 0 if the SMP should be dropped
  110. */
  111. int smi_handle_dr_smp_recv(struct ib_smp *smp,
  112. u8 node_type,
  113. int port_num,
  114. int phys_port_cnt)
  115. {
  116. u8 hop_ptr, hop_cnt;
  117. hop_ptr = smp->hop_ptr;
  118. hop_cnt = smp->hop_cnt;
  119. /* See section 14.2.2.2, Vol 1 IB spec */
  120. if (!ib_get_smp_direction(smp)) {
  121. /* C14-9:1 -- sender should have incremented hop_ptr */
  122. if (hop_cnt && hop_ptr == 0)
  123. return 0;
  124. /* C14-9:2 -- intermediate hop */
  125. if (hop_ptr && hop_ptr < hop_cnt) {
  126. if (node_type != IB_NODE_SWITCH)
  127. return 0;
  128. smp->return_path[hop_ptr] = port_num;
  129. /* smp->hop_ptr updated when sending */
  130. return (smp->initial_path[hop_ptr+1] <= phys_port_cnt);
  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 == IB_NODE_SWITCH ||
  138. smp->dr_dlid == IB_LID_PERMISSIVE);
  139. }
  140. /* C14-9:4 -- hop_ptr = hop_cnt + 1 -> give to SMA/SM */
  141. /* C14-9:5 -- fail unreasonable hop pointer */
  142. return (hop_ptr == hop_cnt + 1);
  143. } else {
  144. /* C14-13:1 */
  145. if (hop_cnt && hop_ptr == hop_cnt + 1) {
  146. smp->hop_ptr--;
  147. return (smp->return_path[smp->hop_ptr] ==
  148. port_num);
  149. }
  150. /* C14-13:2 */
  151. if (2 <= hop_ptr && hop_ptr <= hop_cnt) {
  152. if (node_type != IB_NODE_SWITCH)
  153. return 0;
  154. /* smp->hop_ptr updated when sending */
  155. return (smp->return_path[hop_ptr-1] <= phys_port_cnt);
  156. }
  157. /* C14-13:3 -- We're at the end of the DR segment of path */
  158. if (hop_ptr == 1) {
  159. if (smp->dr_slid == IB_LID_PERMISSIVE) {
  160. /* giving SMP to SM - update hop_ptr */
  161. smp->hop_ptr--;
  162. return 1;
  163. }
  164. /* smp->hop_ptr updated when sending */
  165. return (node_type == IB_NODE_SWITCH);
  166. }
  167. /* C14-13:4 -- hop_ptr = 0 -> give to SM */
  168. /* C14-13:5 -- Check for unreasonable hop pointer */
  169. return (hop_ptr == 0);
  170. }
  171. }
  172. /*
  173. * Return 1 if the received DR SMP should be forwarded to the send queue
  174. * Return 0 if the SMP should be completed up the stack
  175. */
  176. int smi_check_forward_dr_smp(struct ib_smp *smp)
  177. {
  178. u8 hop_ptr, hop_cnt;
  179. hop_ptr = smp->hop_ptr;
  180. hop_cnt = smp->hop_cnt;
  181. if (!ib_get_smp_direction(smp)) {
  182. /* C14-9:2 -- intermediate hop */
  183. if (hop_ptr && hop_ptr < hop_cnt)
  184. return 1;
  185. /* C14-9:3 -- at the end of the DR segment of path */
  186. if (hop_ptr == hop_cnt)
  187. return (smp->dr_dlid == IB_LID_PERMISSIVE);
  188. /* C14-9:4 -- hop_ptr = hop_cnt + 1 -> give to SMA/SM */
  189. if (hop_ptr == hop_cnt + 1)
  190. return 1;
  191. } else {
  192. /* C14-13:2 */
  193. if (2 <= hop_ptr && hop_ptr <= hop_cnt)
  194. return 1;
  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. }
  199. return 0;
  200. }