You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

ib_sma.c 9.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319
  1. /*
  2. * Copyright (C) 2008 Michael Brown <mbrown@fensystems.co.uk>.
  3. *
  4. * This program is free software; you can redistribute it and/or
  5. * modify it under the terms of the GNU General Public License as
  6. * published by the Free Software Foundation; either version 2 of the
  7. * License, or any later version.
  8. *
  9. * This program is distributed in the hope that it will be useful, but
  10. * WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12. * General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this program; if not, write to the Free Software
  16. * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  17. */
  18. FILE_LICENCE ( GPL2_OR_LATER );
  19. #include <stdint.h>
  20. #include <stdlib.h>
  21. #include <string.h>
  22. #include <errno.h>
  23. #include <stdio.h>
  24. #include <unistd.h>
  25. #include <byteswap.h>
  26. #include <gpxe/infiniband.h>
  27. #include <gpxe/ib_gma.h>
  28. #include <gpxe/ib_sma.h>
  29. /**
  30. * @file
  31. *
  32. * Infiniband Subnet Management Agent
  33. *
  34. */
  35. /**
  36. * Get node information
  37. *
  38. * @v gma General management agent
  39. * @v mad MAD
  40. * @ret rc Return status code
  41. */
  42. static int ib_sma_get_node_info ( struct ib_gma *gma,
  43. union ib_mad *mad ) {
  44. struct ib_device *ibdev = gma->ibdev;
  45. struct ib_node_info *node_info = &mad->smp.smp_data.node_info;
  46. memset ( node_info, 0, sizeof ( *node_info ) );
  47. node_info->base_version = IB_MGMT_BASE_VERSION;
  48. node_info->class_version = IB_SMP_CLASS_VERSION;
  49. node_info->node_type = IB_NODE_TYPE_HCA;
  50. node_info->num_ports = ib_get_hca_info ( ibdev, &node_info->sys_guid );
  51. memcpy ( &node_info->node_guid, &node_info->sys_guid,
  52. sizeof ( node_info->node_guid ) );
  53. memcpy ( &node_info->port_guid, &ibdev->gid.u.half[1],
  54. sizeof ( node_info->port_guid ) );
  55. node_info->partition_cap = htons ( 1 );
  56. node_info->local_port_num = ibdev->port;
  57. return 0;
  58. }
  59. /**
  60. * Get node description
  61. *
  62. * @v gma General management agent
  63. * @v mad MAD
  64. * @ret rc Return status code
  65. */
  66. static int ib_sma_get_node_desc ( struct ib_gma *gma,
  67. union ib_mad *mad ) {
  68. struct ib_device *ibdev = gma->ibdev;
  69. struct ib_node_desc *node_desc = &mad->smp.smp_data.node_desc;
  70. struct ib_gid_half *guid = &ibdev->gid.u.half[1];
  71. memset ( node_desc, 0, sizeof ( *node_desc ) );
  72. snprintf ( node_desc->node_string, sizeof ( node_desc->node_string ),
  73. "gPXE %02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x (%s)",
  74. guid->bytes[0], guid->bytes[1], guid->bytes[2],
  75. guid->bytes[3], guid->bytes[4], guid->bytes[5],
  76. guid->bytes[6], guid->bytes[7], ibdev->dev->name );
  77. return 0;
  78. }
  79. /**
  80. * Get GUID information
  81. *
  82. * @v gma General management agent
  83. * @v mad MAD
  84. * @ret rc Return status code
  85. */
  86. static int ib_sma_get_guid_info ( struct ib_gma *gma,
  87. union ib_mad *mad ) {
  88. struct ib_device *ibdev = gma->ibdev;
  89. struct ib_guid_info *guid_info = &mad->smp.smp_data.guid_info;
  90. memset ( guid_info, 0, sizeof ( *guid_info ) );
  91. memcpy ( guid_info->guid[0], &ibdev->gid.u.half[1],
  92. sizeof ( guid_info->guid[0] ) );
  93. return 0;
  94. }
  95. /**
  96. * Get port information
  97. *
  98. * @v gma General management agent
  99. * @v mad MAD
  100. * @ret rc Return status code
  101. */
  102. static int ib_sma_get_port_info ( struct ib_gma *gma,
  103. union ib_mad *mad ) {
  104. struct ib_device *ibdev = gma->ibdev;
  105. struct ib_port_info *port_info = &mad->smp.smp_data.port_info;
  106. memset ( port_info, 0, sizeof ( *port_info ) );
  107. memcpy ( port_info->gid_prefix, &ibdev->gid.u.half[0],
  108. sizeof ( port_info->gid_prefix ) );
  109. port_info->lid = ntohs ( ibdev->lid );
  110. port_info->mastersm_lid = ntohs ( ibdev->sm_lid );
  111. port_info->local_port_num = ibdev->port;
  112. port_info->link_width_enabled = ibdev->link_width;
  113. port_info->link_width_supported = ibdev->link_width;
  114. port_info->link_width_active = ibdev->link_width;
  115. port_info->link_speed_supported__port_state =
  116. ( ( ibdev->link_speed << 4 ) | ibdev->port_state );
  117. port_info->port_phys_state__link_down_def_state =
  118. ( ( IB_PORT_PHYS_STATE_POLLING << 4 ) |
  119. IB_PORT_PHYS_STATE_POLLING );
  120. port_info->link_speed_active__link_speed_enabled =
  121. ( ( ibdev->link_speed << 4 ) | ibdev->link_speed );
  122. port_info->neighbour_mtu__mastersm_sl =
  123. ( ( IB_MTU_2048 << 4 ) | ibdev->sm_sl );
  124. port_info->vl_cap__init_type = ( IB_VL_0 << 4 );
  125. port_info->init_type_reply__mtu_cap = IB_MTU_2048;
  126. port_info->operational_vls__enforcement = ( IB_VL_0 << 4 );
  127. port_info->guid_cap = 1;
  128. return 0;
  129. }
  130. /**
  131. * Set port information
  132. *
  133. * @v gma General management agent
  134. * @v mad MAD
  135. * @ret rc Return status code
  136. */
  137. static int ib_sma_set_port_info ( struct ib_gma *gma,
  138. union ib_mad *mad ) {
  139. struct ib_device *ibdev = gma->ibdev;
  140. const struct ib_port_info *port_info = &mad->smp.smp_data.port_info;
  141. int rc;
  142. memcpy ( &ibdev->gid.u.half[0], port_info->gid_prefix,
  143. sizeof ( ibdev->gid.u.half[0] ) );
  144. ibdev->lid = ntohs ( port_info->lid );
  145. ibdev->sm_lid = ntohs ( port_info->mastersm_lid );
  146. ibdev->sm_sl = ( port_info->neighbour_mtu__mastersm_sl & 0xf );
  147. if ( ( rc = ib_set_port_info ( ibdev, port_info ) ) != 0 ) {
  148. DBGC ( ibdev, "IBDEV %p could not set port information: %s\n",
  149. ibdev, strerror ( rc ) );
  150. mad->hdr.status =
  151. htons ( IB_MGMT_STATUS_UNSUPPORTED_METHOD_ATTR );
  152. }
  153. return ib_sma_get_port_info ( gma, mad );
  154. }
  155. /**
  156. * Get partition key table
  157. *
  158. * @v gma General management agent
  159. * @v mad MAD
  160. * @ret rc Return status code
  161. */
  162. static int ib_sma_get_pkey_table ( struct ib_gma *gma,
  163. union ib_mad *mad ) {
  164. struct ib_device *ibdev = gma->ibdev;
  165. struct ib_pkey_table *pkey_table = &mad->smp.smp_data.pkey_table;
  166. memset ( pkey_table, 0, sizeof ( *pkey_table ) );
  167. pkey_table->pkey[0] = htons ( ibdev->pkey );
  168. return 0;
  169. }
  170. /**
  171. * Set partition key table
  172. *
  173. * @v gma General management agent
  174. * @v mad MAD
  175. * @ret rc Return status code
  176. */
  177. static int ib_sma_set_pkey_table ( struct ib_gma *gma,
  178. union ib_mad *mad ) {
  179. struct ib_device *ibdev = gma->ibdev;
  180. struct ib_pkey_table *pkey_table = &mad->smp.smp_data.pkey_table;
  181. ibdev->pkey = ntohs ( pkey_table->pkey[0] );
  182. return ib_sma_get_pkey_table ( gma, mad );
  183. }
  184. /** List of attribute handlers */
  185. struct ib_gma_handler ib_sma_handlers[] __ib_gma_handler = {
  186. {
  187. .mgmt_class = IB_MGMT_CLASS_SUBN_LID_ROUTED,
  188. .mgmt_class_ignore = IB_SMP_CLASS_IGNORE,
  189. .class_version = IB_SMP_CLASS_VERSION,
  190. .method = IB_MGMT_METHOD_GET,
  191. .resp_method = IB_MGMT_METHOD_GET_RESP,
  192. .attr_id = htons ( IB_SMP_ATTR_NODE_INFO ),
  193. .handle = ib_sma_get_node_info,
  194. },
  195. {
  196. .mgmt_class = IB_MGMT_CLASS_SUBN_LID_ROUTED,
  197. .mgmt_class_ignore = IB_SMP_CLASS_IGNORE,
  198. .class_version = IB_SMP_CLASS_VERSION,
  199. .method = IB_MGMT_METHOD_GET,
  200. .resp_method = IB_MGMT_METHOD_GET_RESP,
  201. .attr_id = htons ( IB_SMP_ATTR_NODE_DESC ),
  202. .handle = ib_sma_get_node_desc,
  203. },
  204. {
  205. .mgmt_class = IB_MGMT_CLASS_SUBN_LID_ROUTED,
  206. .mgmt_class_ignore = IB_SMP_CLASS_IGNORE,
  207. .class_version = IB_SMP_CLASS_VERSION,
  208. .method = IB_MGMT_METHOD_GET,
  209. .resp_method = IB_MGMT_METHOD_GET_RESP,
  210. .attr_id = htons ( IB_SMP_ATTR_GUID_INFO ),
  211. .handle = ib_sma_get_guid_info,
  212. },
  213. {
  214. .mgmt_class = IB_MGMT_CLASS_SUBN_LID_ROUTED,
  215. .mgmt_class_ignore = IB_SMP_CLASS_IGNORE,
  216. .class_version = IB_SMP_CLASS_VERSION,
  217. .method = IB_MGMT_METHOD_GET,
  218. .resp_method = IB_MGMT_METHOD_GET_RESP,
  219. .attr_id = htons ( IB_SMP_ATTR_PORT_INFO ),
  220. .handle = ib_sma_get_port_info,
  221. },
  222. {
  223. .mgmt_class = IB_MGMT_CLASS_SUBN_LID_ROUTED,
  224. .mgmt_class_ignore = IB_SMP_CLASS_IGNORE,
  225. .class_version = IB_SMP_CLASS_VERSION,
  226. .method = IB_MGMT_METHOD_SET,
  227. .resp_method = IB_MGMT_METHOD_GET_RESP,
  228. .attr_id = htons ( IB_SMP_ATTR_PORT_INFO ),
  229. .handle = ib_sma_set_port_info,
  230. },
  231. {
  232. .mgmt_class = IB_MGMT_CLASS_SUBN_LID_ROUTED,
  233. .mgmt_class_ignore = IB_SMP_CLASS_IGNORE,
  234. .class_version = IB_SMP_CLASS_VERSION,
  235. .method = IB_MGMT_METHOD_GET,
  236. .resp_method = IB_MGMT_METHOD_GET_RESP,
  237. .attr_id = htons ( IB_SMP_ATTR_PKEY_TABLE ),
  238. .handle = ib_sma_get_pkey_table,
  239. },
  240. {
  241. .mgmt_class = IB_MGMT_CLASS_SUBN_LID_ROUTED,
  242. .mgmt_class_ignore = IB_SMP_CLASS_IGNORE,
  243. .class_version = IB_SMP_CLASS_VERSION,
  244. .method = IB_MGMT_METHOD_SET,
  245. .resp_method = IB_MGMT_METHOD_GET_RESP,
  246. .attr_id = htons ( IB_SMP_ATTR_PKEY_TABLE ),
  247. .handle = ib_sma_set_pkey_table,
  248. },
  249. };
  250. /**
  251. * Create SMA
  252. *
  253. * @v sma Subnet management agent
  254. * @v ibdev Infiniband device
  255. * @v op Subnet management operations
  256. * @ret rc Return status code
  257. */
  258. int ib_create_sma ( struct ib_sma *sma, struct ib_device *ibdev ) {
  259. int rc;
  260. /* Initialise GMA */
  261. if ( ( rc = ib_create_gma ( &sma->gma, ibdev, 0 ) ) != 0 ) {
  262. DBGC ( sma, "SMA %p could not create GMA: %s\n",
  263. sma, strerror ( rc ) );
  264. goto err_create_gma;
  265. }
  266. /* If we don't get QP0, we can't function */
  267. if ( sma->gma.qp->qpn != IB_QPN_SMA ) {
  268. DBGC ( sma, "SMA %p on QPN %lx, needs to be on QPN 0\n",
  269. sma, sma->gma.qp->qpn );
  270. rc = -ENOTSUP;
  271. goto err_not_qp0;
  272. }
  273. return 0;
  274. err_not_qp0:
  275. ib_destroy_gma ( &sma->gma );
  276. err_create_gma:
  277. return rc;
  278. }
  279. /**
  280. * Destroy SMA
  281. *
  282. * @v sma Subnet management agent
  283. */
  284. void ib_destroy_sma ( struct ib_sma *sma ) {
  285. ib_destroy_gma ( &sma->gma );
  286. }