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 11KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370
  1. /*
  2. * Copyright (C) 2009 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 <ipxe/settings.h>
  27. #include <ipxe/infiniband.h>
  28. #include <ipxe/iobuf.h>
  29. #include <ipxe/ib_mi.h>
  30. #include <ipxe/ib_sma.h>
  31. /**
  32. * @file
  33. *
  34. * Infiniband Subnet Management Agent
  35. *
  36. */
  37. /**
  38. * Node information
  39. *
  40. * @v ibdev Infiniband device
  41. * @v mi Management interface
  42. * @v mad Received MAD
  43. * @v av Source address vector
  44. */
  45. static void ib_sma_node_info ( struct ib_device *ibdev,
  46. struct ib_mad_interface *mi,
  47. union ib_mad *mad,
  48. struct ib_address_vector *av ) {
  49. struct ib_node_info *node_info = &mad->smp.smp_data.node_info;
  50. int rc;
  51. /* Fill in information */
  52. memset ( node_info, 0, sizeof ( *node_info ) );
  53. node_info->base_version = IB_MGMT_BASE_VERSION;
  54. node_info->class_version = IB_SMP_CLASS_VERSION;
  55. node_info->node_type = IB_NODE_TYPE_HCA;
  56. node_info->num_ports = ib_count_ports ( ibdev );
  57. memcpy ( &node_info->sys_guid, &ibdev->node_guid,
  58. sizeof ( node_info->sys_guid ) );
  59. memcpy ( &node_info->node_guid, &ibdev->node_guid,
  60. sizeof ( node_info->node_guid ) );
  61. memcpy ( &node_info->port_guid, &ibdev->gid.s.guid,
  62. sizeof ( node_info->port_guid ) );
  63. node_info->partition_cap = htons ( 1 );
  64. node_info->local_port_num = ibdev->port;
  65. /* Send GetResponse */
  66. mad->hdr.method = IB_MGMT_METHOD_GET_RESP;
  67. if ( ( rc = ib_mi_send ( ibdev, mi, mad, av ) ) != 0 ) {
  68. DBGC ( mi, "SMA %p could not send NodeInfo GetResponse: %s\n",
  69. mi, strerror ( rc ) );
  70. return;
  71. }
  72. }
  73. /**
  74. * Node description
  75. *
  76. * @v ibdev Infiniband device
  77. * @v mi Management interface
  78. * @v mad Received MAD
  79. * @v av Source address vector
  80. */
  81. static void ib_sma_node_desc ( struct ib_device *ibdev,
  82. struct ib_mad_interface *mi,
  83. union ib_mad *mad,
  84. struct ib_address_vector *av ) {
  85. struct ib_node_desc *node_desc = &mad->smp.smp_data.node_desc;
  86. union ib_guid *guid = &ibdev->node_guid;
  87. char hostname[ sizeof ( node_desc->node_string ) ];
  88. int hostname_len;
  89. int rc;
  90. /* Fill in information */
  91. memset ( node_desc, 0, sizeof ( *node_desc ) );
  92. hostname_len = fetch_string_setting ( NULL, &hostname_setting,
  93. hostname, sizeof ( hostname ) );
  94. snprintf ( node_desc->node_string, sizeof ( node_desc->node_string ),
  95. "iPXE %s%s%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x (%s)",
  96. hostname, ( ( hostname_len >= 0 ) ? " " : "" ),
  97. guid->bytes[0], guid->bytes[1], guid->bytes[2],
  98. guid->bytes[3], guid->bytes[4], guid->bytes[5],
  99. guid->bytes[6], guid->bytes[7], ibdev->dev->name );
  100. /* Send GetResponse */
  101. mad->hdr.method = IB_MGMT_METHOD_GET_RESP;
  102. if ( ( rc = ib_mi_send ( ibdev, mi, mad, av ) ) != 0 ) {
  103. DBGC ( mi, "SMA %p could not send NodeDesc GetResponse: %s\n",
  104. mi, strerror ( rc ) );
  105. return;
  106. }
  107. }
  108. /**
  109. * GUID information
  110. *
  111. * @v ibdev Infiniband device
  112. * @v mi Management interface
  113. * @v mad Received MAD
  114. * @v av Source address vector
  115. */
  116. static void ib_sma_guid_info ( struct ib_device *ibdev,
  117. struct ib_mad_interface *mi,
  118. union ib_mad *mad,
  119. struct ib_address_vector *av ) {
  120. struct ib_guid_info *guid_info = &mad->smp.smp_data.guid_info;
  121. int rc;
  122. /* Fill in information */
  123. memset ( guid_info, 0, sizeof ( *guid_info ) );
  124. memcpy ( guid_info->guid[0], &ibdev->gid.s.guid,
  125. sizeof ( guid_info->guid[0] ) );
  126. /* Send GetResponse */
  127. mad->hdr.method = IB_MGMT_METHOD_GET_RESP;
  128. if ( ( rc = ib_mi_send ( ibdev, mi, mad, av ) ) != 0 ) {
  129. DBGC ( mi, "SMA %p could not send GuidInfo GetResponse: %s\n",
  130. mi, strerror ( rc ) );
  131. return;
  132. }
  133. }
  134. /**
  135. * Set port information
  136. *
  137. * @v ibdev Infiniband device
  138. * @v mi Management interface
  139. * @v mad Received MAD
  140. * @ret rc Return status code
  141. */
  142. static int ib_sma_set_port_info ( struct ib_device *ibdev,
  143. struct ib_mad_interface *mi,
  144. union ib_mad *mad ) {
  145. const struct ib_port_info *port_info = &mad->smp.smp_data.port_info;
  146. unsigned int link_width_enabled;
  147. unsigned int link_speed_enabled;
  148. int rc;
  149. /* Set parameters */
  150. memcpy ( &ibdev->gid.s.prefix, port_info->gid_prefix,
  151. sizeof ( ibdev->gid.s.prefix ) );
  152. ibdev->lid = ntohs ( port_info->lid );
  153. ibdev->sm_lid = ntohs ( port_info->mastersm_lid );
  154. if ( ( link_width_enabled = port_info->link_width_enabled ) )
  155. ibdev->link_width_enabled = link_width_enabled;
  156. if ( ( link_speed_enabled =
  157. ( port_info->link_speed_active__link_speed_enabled & 0xf ) ) )
  158. ibdev->link_speed_enabled = link_speed_enabled;
  159. ibdev->sm_sl = ( port_info->neighbour_mtu__mastersm_sl & 0xf );
  160. DBGC ( mi, "SMA %p set LID %04x SMLID %04x link width %02x speed "
  161. "%02x\n", mi, ibdev->lid, ibdev->sm_lid,
  162. ibdev->link_width_enabled, ibdev->link_speed_enabled );
  163. /* Update parameters on device */
  164. if ( ( rc = ib_set_port_info ( ibdev, mad ) ) != 0 ) {
  165. DBGC ( mi, "SMA %p could not set port information: %s\n",
  166. mi, strerror ( rc ) );
  167. return rc;
  168. }
  169. return 0;
  170. }
  171. /**
  172. * Port information
  173. *
  174. * @v ibdev Infiniband device
  175. * @v mi Management interface
  176. * @v mad Received MAD
  177. * @v av Source address vector
  178. */
  179. static void ib_sma_port_info ( struct ib_device *ibdev,
  180. struct ib_mad_interface *mi,
  181. union ib_mad *mad,
  182. struct ib_address_vector *av ) {
  183. struct ib_port_info *port_info = &mad->smp.smp_data.port_info;
  184. int rc;
  185. /* Set parameters if applicable */
  186. if ( mad->hdr.method == IB_MGMT_METHOD_SET ) {
  187. if ( ( rc = ib_sma_set_port_info ( ibdev, mi, mad ) ) != 0 ) {
  188. mad->hdr.status =
  189. htons ( IB_MGMT_STATUS_UNSUPPORTED_METHOD_ATTR );
  190. /* Fall through to generate GetResponse */
  191. }
  192. }
  193. /* Fill in information */
  194. memset ( port_info, 0, sizeof ( *port_info ) );
  195. memcpy ( port_info->gid_prefix, &ibdev->gid.s.prefix,
  196. sizeof ( port_info->gid_prefix ) );
  197. port_info->lid = ntohs ( ibdev->lid );
  198. port_info->mastersm_lid = ntohs ( ibdev->sm_lid );
  199. port_info->local_port_num = ibdev->port;
  200. port_info->link_width_enabled = ibdev->link_width_enabled;
  201. port_info->link_width_supported = ibdev->link_width_supported;
  202. port_info->link_width_active = ibdev->link_width_active;
  203. port_info->link_speed_supported__port_state =
  204. ( ( ibdev->link_speed_supported << 4 ) | ibdev->port_state );
  205. port_info->port_phys_state__link_down_def_state =
  206. ( ( IB_PORT_PHYS_STATE_POLLING << 4 ) |
  207. IB_PORT_PHYS_STATE_POLLING );
  208. port_info->link_speed_active__link_speed_enabled =
  209. ( ( ibdev->link_speed_active << 4 ) |
  210. ibdev->link_speed_enabled );
  211. port_info->neighbour_mtu__mastersm_sl =
  212. ( ( IB_MTU_2048 << 4 ) | ibdev->sm_sl );
  213. port_info->vl_cap__init_type = ( IB_VL_0 << 4 );
  214. port_info->init_type_reply__mtu_cap = IB_MTU_2048;
  215. port_info->operational_vls__enforcement = ( IB_VL_0 << 4 );
  216. port_info->guid_cap = 1;
  217. /* Send GetResponse */
  218. mad->hdr.method = IB_MGMT_METHOD_GET_RESP;
  219. if ( ( rc = ib_mi_send ( ibdev, mi, mad, av ) ) != 0 ) {
  220. DBGC ( mi, "SMA %p could not send PortInfo GetResponse: %s\n",
  221. mi, strerror ( rc ) );
  222. return;
  223. }
  224. }
  225. /**
  226. * Set partition key table
  227. *
  228. * @v ibdev Infiniband device
  229. * @v mi Management interface
  230. * @v mad Received MAD
  231. * @ret rc Return status code
  232. */
  233. static int ib_sma_set_pkey_table ( struct ib_device *ibdev,
  234. struct ib_mad_interface *mi,
  235. union ib_mad *mad ) {
  236. struct ib_pkey_table *pkey_table = &mad->smp.smp_data.pkey_table;
  237. int rc;
  238. /* Set parameters */
  239. ibdev->pkey = ntohs ( pkey_table->pkey[0] );
  240. DBGC ( mi, "SMA %p set pkey %04x\n", mi, ibdev->pkey );
  241. /* Update parameters on device */
  242. if ( ( rc = ib_set_pkey_table ( ibdev, mad ) ) != 0 ) {
  243. DBGC ( mi, "SMA %p could not set pkey table: %s\n",
  244. mi, strerror ( rc ) );
  245. return rc;
  246. }
  247. return 0;
  248. }
  249. /**
  250. * Partition key table
  251. *
  252. * @v ibdev Infiniband device
  253. * @v mi Management interface
  254. * @v mad Received MAD
  255. * @v av Source address vector
  256. */
  257. static void ib_sma_pkey_table ( struct ib_device *ibdev,
  258. struct ib_mad_interface *mi,
  259. union ib_mad *mad,
  260. struct ib_address_vector *av ) {
  261. struct ib_pkey_table *pkey_table = &mad->smp.smp_data.pkey_table;
  262. int rc;
  263. /* Set parameters, if applicable */
  264. if ( mad->hdr.method == IB_MGMT_METHOD_SET ) {
  265. if ( ( rc = ib_sma_set_pkey_table ( ibdev, mi, mad ) ) != 0 ) {
  266. mad->hdr.status =
  267. htons ( IB_MGMT_STATUS_UNSUPPORTED_METHOD_ATTR );
  268. /* Fall through to generate GetResponse */
  269. }
  270. }
  271. /* Fill in information */
  272. mad->hdr.method = IB_MGMT_METHOD_GET_RESP;
  273. memset ( pkey_table, 0, sizeof ( *pkey_table ) );
  274. pkey_table->pkey[0] = htons ( ibdev->pkey );
  275. /* Send GetResponse */
  276. mad->hdr.method = IB_MGMT_METHOD_GET_RESP;
  277. if ( ( rc = ib_mi_send ( ibdev, mi, mad, av ) ) != 0 ) {
  278. DBGC ( mi, "SMA %p could not send PKeyTable GetResponse: %s\n",
  279. mi, strerror ( rc ) );
  280. return;
  281. }
  282. }
  283. /** Subnet management agent */
  284. struct ib_mad_agent ib_sma_agent[] __ib_mad_agent = {
  285. {
  286. .mgmt_class = IB_MGMT_CLASS_SUBN_LID_ROUTED,
  287. .class_version = IB_SMP_CLASS_VERSION,
  288. .attr_id = htons ( IB_SMP_ATTR_NODE_INFO ),
  289. .handle = ib_sma_node_info,
  290. },
  291. {
  292. .mgmt_class = IB_MGMT_CLASS_SUBN_LID_ROUTED,
  293. .class_version = IB_SMP_CLASS_VERSION,
  294. .attr_id = htons ( IB_SMP_ATTR_NODE_DESC ),
  295. .handle = ib_sma_node_desc,
  296. },
  297. {
  298. .mgmt_class = IB_MGMT_CLASS_SUBN_LID_ROUTED,
  299. .class_version = IB_SMP_CLASS_VERSION,
  300. .attr_id = htons ( IB_SMP_ATTR_GUID_INFO ),
  301. .handle = ib_sma_guid_info,
  302. },
  303. {
  304. .mgmt_class = IB_MGMT_CLASS_SUBN_LID_ROUTED,
  305. .class_version = IB_SMP_CLASS_VERSION,
  306. .attr_id = htons ( IB_SMP_ATTR_PORT_INFO ),
  307. .handle = ib_sma_port_info,
  308. },
  309. {
  310. .mgmt_class = IB_MGMT_CLASS_SUBN_LID_ROUTED,
  311. .class_version = IB_SMP_CLASS_VERSION,
  312. .attr_id = htons ( IB_SMP_ATTR_PKEY_TABLE ),
  313. .handle = ib_sma_pkey_table,
  314. },
  315. };
  316. /**
  317. * Create subnet management agent and interface
  318. *
  319. * @v ibdev Infiniband device
  320. * @v mi Management interface
  321. * @ret rc Return status code
  322. */
  323. int ib_create_sma ( struct ib_device *ibdev, struct ib_mad_interface *mi ) {
  324. /* Nothing to do */
  325. DBGC ( ibdev, "IBDEV %p SMA using SMI %p\n", ibdev, mi );
  326. return 0;
  327. }
  328. /**
  329. * Destroy subnet management agent and interface
  330. *
  331. * @v ibdev Infiniband device
  332. * @v mi Management interface
  333. */
  334. void ib_destroy_sma ( struct ib_device *ibdev __unused,
  335. struct ib_mad_interface *mi __unused ) {
  336. /* Nothing to do */
  337. }