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

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