您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

ib_sma.c 11KB

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