2 * Copyright (C) 2009 Michael Brown <mbrown@fensystems.co.uk>.
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.
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.
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
20 FILE_LICENCE ( GPL2_OR_LATER );
29 #include <ipxe/settings.h>
30 #include <ipxe/infiniband.h>
31 #include <ipxe/iobuf.h>
32 #include <ipxe/ib_mi.h>
33 #include <ipxe/ib_sma.h>
38 * Infiniband Subnet Management Agent
45 * @v ibdev Infiniband device
46 * @v mi Management interface
48 * @v av Source address vector
50 static void ib_sma_node_info ( struct ib_device *ibdev,
51 struct ib_mad_interface *mi,
53 struct ib_address_vector *av ) {
54 struct ib_node_info *node_info = &mad->smp.smp_data.node_info;
57 /* Fill in information */
58 memset ( node_info, 0, sizeof ( *node_info ) );
59 node_info->base_version = IB_MGMT_BASE_VERSION;
60 node_info->class_version = IB_SMP_CLASS_VERSION;
61 node_info->node_type = IB_NODE_TYPE_HCA;
62 node_info->num_ports = ib_count_ports ( ibdev );
63 memcpy ( &node_info->sys_guid, &ibdev->node_guid,
64 sizeof ( node_info->sys_guid ) );
65 memcpy ( &node_info->node_guid, &ibdev->node_guid,
66 sizeof ( node_info->node_guid ) );
67 memcpy ( &node_info->port_guid, &ibdev->gid.s.guid,
68 sizeof ( node_info->port_guid ) );
69 node_info->partition_cap = htons ( 1 );
70 node_info->local_port_num = ibdev->port;
72 /* Send GetResponse */
73 mad->hdr.method = IB_MGMT_METHOD_GET_RESP;
74 if ( ( rc = ib_mi_send ( ibdev, mi, mad, av ) ) != 0 ) {
75 DBGC ( mi, "SMA %p could not send NodeInfo GetResponse: %s\n",
76 mi, strerror ( rc ) );
84 * @v ibdev Infiniband device
85 * @v mi Management interface
87 * @v av Source address vector
89 static void ib_sma_node_desc ( struct ib_device *ibdev,
90 struct ib_mad_interface *mi,
92 struct ib_address_vector *av ) {
93 struct ib_node_desc *node_desc = &mad->smp.smp_data.node_desc;
94 union ib_guid *guid = &ibdev->node_guid;
95 char hostname[ sizeof ( node_desc->node_string ) ];
99 /* Fill in information */
100 memset ( node_desc, 0, sizeof ( *node_desc ) );
101 hostname_len = fetch_string_setting ( NULL, &hostname_setting,
102 hostname, sizeof ( hostname ) );
103 snprintf ( node_desc->node_string, sizeof ( node_desc->node_string ),
104 "iPXE %s%s%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x (%s)",
105 hostname, ( ( hostname_len >= 0 ) ? " " : "" ),
106 guid->bytes[0], guid->bytes[1], guid->bytes[2],
107 guid->bytes[3], guid->bytes[4], guid->bytes[5],
108 guid->bytes[6], guid->bytes[7], ibdev->dev->name );
110 /* Send GetResponse */
111 mad->hdr.method = IB_MGMT_METHOD_GET_RESP;
112 if ( ( rc = ib_mi_send ( ibdev, mi, mad, av ) ) != 0 ) {
113 DBGC ( mi, "SMA %p could not send NodeDesc GetResponse: %s\n",
114 mi, strerror ( rc ) );
122 * @v ibdev Infiniband device
123 * @v mi Management interface
124 * @v mad Received MAD
125 * @v av Source address vector
127 static void ib_sma_guid_info ( struct ib_device *ibdev,
128 struct ib_mad_interface *mi,
130 struct ib_address_vector *av ) {
131 struct ib_guid_info *guid_info = &mad->smp.smp_data.guid_info;
134 /* Fill in information */
135 memset ( guid_info, 0, sizeof ( *guid_info ) );
136 memcpy ( guid_info->guid[0], &ibdev->gid.s.guid,
137 sizeof ( guid_info->guid[0] ) );
139 /* Send GetResponse */
140 mad->hdr.method = IB_MGMT_METHOD_GET_RESP;
141 if ( ( rc = ib_mi_send ( ibdev, mi, mad, av ) ) != 0 ) {
142 DBGC ( mi, "SMA %p could not send GuidInfo GetResponse: %s\n",
143 mi, strerror ( rc ) );
149 * Set port information
151 * @v ibdev Infiniband device
152 * @v mi Management interface
153 * @v mad Received MAD
154 * @ret rc Return status code
156 static int ib_sma_set_port_info ( struct ib_device *ibdev,
157 struct ib_mad_interface *mi,
158 union ib_mad *mad ) {
159 const struct ib_port_info *port_info = &mad->smp.smp_data.port_info;
160 unsigned int link_width_enabled;
161 unsigned int link_speed_enabled;
165 memcpy ( &ibdev->gid.s.prefix, port_info->gid_prefix,
166 sizeof ( ibdev->gid.s.prefix ) );
167 ibdev->lid = ntohs ( port_info->lid );
168 ibdev->sm_lid = ntohs ( port_info->mastersm_lid );
169 if ( ( link_width_enabled = port_info->link_width_enabled ) )
170 ibdev->link_width_enabled = link_width_enabled;
171 if ( ( link_speed_enabled =
172 ( port_info->link_speed_active__link_speed_enabled & 0xf ) ) )
173 ibdev->link_speed_enabled = link_speed_enabled;
174 ibdev->sm_sl = ( port_info->neighbour_mtu__mastersm_sl & 0xf );
175 DBGC ( mi, "SMA %p set LID %04x SMLID %04x link width %02x speed "
176 "%02x\n", mi, ibdev->lid, ibdev->sm_lid,
177 ibdev->link_width_enabled, ibdev->link_speed_enabled );
179 /* Update parameters on device */
180 if ( ( rc = ib_set_port_info ( ibdev, mad ) ) != 0 ) {
181 DBGC ( mi, "SMA %p could not set port information: %s\n",
182 mi, strerror ( rc ) );
192 * @v ibdev Infiniband device
193 * @v mi Management interface
194 * @v mad Received MAD
195 * @v av Source address vector
197 static void ib_sma_port_info ( struct ib_device *ibdev,
198 struct ib_mad_interface *mi,
200 struct ib_address_vector *av ) {
201 struct ib_port_info *port_info = &mad->smp.smp_data.port_info;
204 /* Set parameters if applicable */
205 if ( mad->hdr.method == IB_MGMT_METHOD_SET ) {
206 if ( ( rc = ib_sma_set_port_info ( ibdev, mi, mad ) ) != 0 ) {
208 htons ( IB_MGMT_STATUS_UNSUPPORTED_METHOD_ATTR );
209 /* Fall through to generate GetResponse */
213 /* Fill in information */
214 memset ( port_info, 0, sizeof ( *port_info ) );
215 memcpy ( port_info->gid_prefix, &ibdev->gid.s.prefix,
216 sizeof ( port_info->gid_prefix ) );
217 port_info->lid = ntohs ( ibdev->lid );
218 port_info->mastersm_lid = ntohs ( ibdev->sm_lid );
219 port_info->local_port_num = ibdev->port;
220 port_info->link_width_enabled = ibdev->link_width_enabled;
221 port_info->link_width_supported = ibdev->link_width_supported;
222 port_info->link_width_active = ibdev->link_width_active;
223 port_info->link_speed_supported__port_state =
224 ( ( ibdev->link_speed_supported << 4 ) | ibdev->port_state );
225 port_info->port_phys_state__link_down_def_state =
226 ( ( IB_PORT_PHYS_STATE_POLLING << 4 ) |
227 IB_PORT_PHYS_STATE_POLLING );
228 port_info->link_speed_active__link_speed_enabled =
229 ( ( ibdev->link_speed_active << 4 ) |
230 ibdev->link_speed_enabled );
231 port_info->neighbour_mtu__mastersm_sl =
232 ( ( IB_MTU_2048 << 4 ) | ibdev->sm_sl );
233 port_info->vl_cap__init_type = ( IB_VL_0 << 4 );
234 port_info->init_type_reply__mtu_cap = IB_MTU_2048;
235 port_info->operational_vls__enforcement = ( IB_VL_0 << 4 );
236 port_info->guid_cap = 1;
238 /* Send GetResponse */
239 mad->hdr.method = IB_MGMT_METHOD_GET_RESP;
240 if ( ( rc = ib_mi_send ( ibdev, mi, mad, av ) ) != 0 ) {
241 DBGC ( mi, "SMA %p could not send PortInfo GetResponse: %s\n",
242 mi, strerror ( rc ) );
248 * Set partition key table
250 * @v ibdev Infiniband device
251 * @v mi Management interface
252 * @v mad Received MAD
253 * @ret rc Return status code
255 static int ib_sma_set_pkey_table ( struct ib_device *ibdev,
256 struct ib_mad_interface *mi,
257 union ib_mad *mad ) {
258 struct ib_pkey_table *pkey_table = &mad->smp.smp_data.pkey_table;
262 ibdev->pkey = ntohs ( pkey_table->pkey[0] );
263 DBGC ( mi, "SMA %p set pkey %04x\n", mi, ibdev->pkey );
265 /* Update parameters on device */
266 if ( ( rc = ib_set_pkey_table ( ibdev, mad ) ) != 0 ) {
267 DBGC ( mi, "SMA %p could not set pkey table: %s\n",
268 mi, strerror ( rc ) );
276 * Partition key table
278 * @v ibdev Infiniband device
279 * @v mi Management interface
280 * @v mad Received MAD
281 * @v av Source address vector
283 static void ib_sma_pkey_table ( struct ib_device *ibdev,
284 struct ib_mad_interface *mi,
286 struct ib_address_vector *av ) {
287 struct ib_pkey_table *pkey_table = &mad->smp.smp_data.pkey_table;
290 /* Set parameters, if applicable */
291 if ( mad->hdr.method == IB_MGMT_METHOD_SET ) {
292 if ( ( rc = ib_sma_set_pkey_table ( ibdev, mi, mad ) ) != 0 ) {
294 htons ( IB_MGMT_STATUS_UNSUPPORTED_METHOD_ATTR );
295 /* Fall through to generate GetResponse */
299 /* Fill in information */
300 mad->hdr.method = IB_MGMT_METHOD_GET_RESP;
301 memset ( pkey_table, 0, sizeof ( *pkey_table ) );
302 pkey_table->pkey[0] = htons ( ibdev->pkey );
304 /* Send GetResponse */
305 mad->hdr.method = IB_MGMT_METHOD_GET_RESP;
306 if ( ( rc = ib_mi_send ( ibdev, mi, mad, av ) ) != 0 ) {
307 DBGC ( mi, "SMA %p could not send PKeyTable GetResponse: %s\n",
308 mi, strerror ( rc ) );
313 /** Subnet management agent */
314 struct ib_mad_agent ib_sma_agent[] __ib_mad_agent = {
316 .mgmt_class = IB_MGMT_CLASS_SUBN_LID_ROUTED,
317 .class_version = IB_SMP_CLASS_VERSION,
318 .attr_id = htons ( IB_SMP_ATTR_NODE_INFO ),
319 .handle = ib_sma_node_info,
322 .mgmt_class = IB_MGMT_CLASS_SUBN_LID_ROUTED,
323 .class_version = IB_SMP_CLASS_VERSION,
324 .attr_id = htons ( IB_SMP_ATTR_NODE_DESC ),
325 .handle = ib_sma_node_desc,
328 .mgmt_class = IB_MGMT_CLASS_SUBN_LID_ROUTED,
329 .class_version = IB_SMP_CLASS_VERSION,
330 .attr_id = htons ( IB_SMP_ATTR_GUID_INFO ),
331 .handle = ib_sma_guid_info,
334 .mgmt_class = IB_MGMT_CLASS_SUBN_LID_ROUTED,
335 .class_version = IB_SMP_CLASS_VERSION,
336 .attr_id = htons ( IB_SMP_ATTR_PORT_INFO ),
337 .handle = ib_sma_port_info,
340 .mgmt_class = IB_MGMT_CLASS_SUBN_LID_ROUTED,
341 .class_version = IB_SMP_CLASS_VERSION,
342 .attr_id = htons ( IB_SMP_ATTR_PKEY_TABLE ),
343 .handle = ib_sma_pkey_table,
348 * Create subnet management agent and interface
350 * @v ibdev Infiniband device
351 * @v mi Management interface
352 * @ret rc Return status code
354 int ib_create_sma ( struct ib_device *ibdev, struct ib_mad_interface *mi ) {
357 DBGC ( ibdev, "IBDEV %p SMA using SMI %p\n", ibdev, mi );
363 * Destroy subnet management agent and interface
365 * @v ibdev Infiniband device
366 * @v mi Management interface
368 void ib_destroy_sma ( struct ib_device *ibdev __unused,
369 struct ib_mad_interface *mi __unused ) {