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
19 * You can also choose to distribute this program under the terms of
20 * the Unmodified Binary Distribution Licence (as given in the file
21 * COPYING.UBDL), provided that you have satisfied its requirements.
24 FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
33 #include <ipxe/settings.h>
34 #include <ipxe/infiniband.h>
35 #include <ipxe/iobuf.h>
36 #include <ipxe/ib_mi.h>
37 #include <ipxe/ib_sma.h>
42 * Infiniband Subnet Management Agent
49 * @v ibdev Infiniband device
50 * @v mi Management interface
52 * @v av Source address vector
54 static void ib_sma_node_info ( struct ib_device *ibdev,
55 struct ib_mad_interface *mi,
57 struct ib_address_vector *av ) {
58 struct ib_node_info *node_info = &mad->smp.smp_data.node_info;
61 /* Fill in information */
62 memset ( node_info, 0, sizeof ( *node_info ) );
63 node_info->base_version = IB_MGMT_BASE_VERSION;
64 node_info->class_version = IB_SMP_CLASS_VERSION;
65 node_info->node_type = IB_NODE_TYPE_HCA;
66 node_info->num_ports = ib_count_ports ( ibdev );
67 memcpy ( &node_info->sys_guid, &ibdev->node_guid,
68 sizeof ( node_info->sys_guid ) );
69 memcpy ( &node_info->node_guid, &ibdev->node_guid,
70 sizeof ( node_info->node_guid ) );
71 memcpy ( &node_info->port_guid, &ibdev->gid.s.guid,
72 sizeof ( node_info->port_guid ) );
73 node_info->partition_cap = htons ( 1 );
74 node_info->local_port_num = ibdev->port;
76 /* Send GetResponse */
77 mad->hdr.method = IB_MGMT_METHOD_GET_RESP;
78 if ( ( rc = ib_mi_send ( ibdev, mi, mad, av ) ) != 0 ) {
79 DBGC ( mi, "SMA %p could not send NodeInfo GetResponse: %s\n",
80 mi, strerror ( rc ) );
88 * @v ibdev Infiniband device
89 * @v mi Management interface
91 * @v av Source address vector
93 static void ib_sma_node_desc ( struct ib_device *ibdev,
94 struct ib_mad_interface *mi,
96 struct ib_address_vector *av ) {
97 struct ib_node_desc *node_desc = &mad->smp.smp_data.node_desc;
98 union ib_guid *guid = &ibdev->node_guid;
99 char hostname[ sizeof ( node_desc->node_string ) ];
103 /* Fill in information */
104 memset ( node_desc, 0, sizeof ( *node_desc ) );
105 hostname_len = fetch_string_setting ( NULL, &hostname_setting,
106 hostname, sizeof ( hostname ) );
107 snprintf ( node_desc->node_string, sizeof ( node_desc->node_string ),
108 "iPXE %s%s%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x (%s)",
109 hostname, ( ( hostname_len >= 0 ) ? " " : "" ),
110 guid->bytes[0], guid->bytes[1], guid->bytes[2],
111 guid->bytes[3], guid->bytes[4], guid->bytes[5],
112 guid->bytes[6], guid->bytes[7], ibdev->dev->name );
114 /* Send GetResponse */
115 mad->hdr.method = IB_MGMT_METHOD_GET_RESP;
116 if ( ( rc = ib_mi_send ( ibdev, mi, mad, av ) ) != 0 ) {
117 DBGC ( mi, "SMA %p could not send NodeDesc GetResponse: %s\n",
118 mi, strerror ( rc ) );
126 * @v ibdev Infiniband device
127 * @v mi Management interface
128 * @v mad Received MAD
129 * @v av Source address vector
131 static void ib_sma_guid_info ( struct ib_device *ibdev,
132 struct ib_mad_interface *mi,
134 struct ib_address_vector *av ) {
135 struct ib_guid_info *guid_info = &mad->smp.smp_data.guid_info;
138 /* Fill in information */
139 memset ( guid_info, 0, sizeof ( *guid_info ) );
140 memcpy ( guid_info->guid[0], &ibdev->gid.s.guid,
141 sizeof ( guid_info->guid[0] ) );
143 /* Send GetResponse */
144 mad->hdr.method = IB_MGMT_METHOD_GET_RESP;
145 if ( ( rc = ib_mi_send ( ibdev, mi, mad, av ) ) != 0 ) {
146 DBGC ( mi, "SMA %p could not send GuidInfo GetResponse: %s\n",
147 mi, strerror ( rc ) );
153 * Set port information
155 * @v ibdev Infiniband device
156 * @v mi Management interface
157 * @v mad Received MAD
158 * @ret rc Return status code
160 static int ib_sma_set_port_info ( struct ib_device *ibdev,
161 struct ib_mad_interface *mi,
162 union ib_mad *mad ) {
163 const struct ib_port_info *port_info = &mad->smp.smp_data.port_info;
164 unsigned int link_width_enabled;
165 unsigned int link_speed_enabled;
169 memcpy ( &ibdev->gid.s.prefix, port_info->gid_prefix,
170 sizeof ( ibdev->gid.s.prefix ) );
171 ibdev->lid = ntohs ( port_info->lid );
172 ibdev->sm_lid = ntohs ( port_info->mastersm_lid );
173 if ( ( link_width_enabled = port_info->link_width_enabled ) )
174 ibdev->link_width_enabled = link_width_enabled;
175 if ( ( link_speed_enabled =
176 ( port_info->link_speed_active__link_speed_enabled & 0xf ) ) )
177 ibdev->link_speed_enabled = link_speed_enabled;
178 ibdev->sm_sl = ( port_info->neighbour_mtu__mastersm_sl & 0xf );
179 DBGC ( mi, "SMA %p set LID %04x SMLID %04x link width %02x speed "
180 "%02x\n", mi, ibdev->lid, ibdev->sm_lid,
181 ibdev->link_width_enabled, ibdev->link_speed_enabled );
183 /* Update parameters on device */
184 if ( ( rc = ib_set_port_info ( ibdev, mad ) ) != 0 ) {
185 DBGC ( mi, "SMA %p could not set port information: %s\n",
186 mi, strerror ( rc ) );
196 * @v ibdev Infiniband device
197 * @v mi Management interface
198 * @v mad Received MAD
199 * @v av Source address vector
201 static void ib_sma_port_info ( struct ib_device *ibdev,
202 struct ib_mad_interface *mi,
204 struct ib_address_vector *av ) {
205 struct ib_port_info *port_info = &mad->smp.smp_data.port_info;
208 /* Set parameters if applicable */
209 if ( mad->hdr.method == IB_MGMT_METHOD_SET ) {
210 if ( ( rc = ib_sma_set_port_info ( ibdev, mi, mad ) ) != 0 ) {
212 htons ( IB_MGMT_STATUS_UNSUPPORTED_METHOD_ATTR );
213 /* Fall through to generate GetResponse */
217 /* Fill in information */
218 memset ( port_info, 0, sizeof ( *port_info ) );
219 memcpy ( port_info->gid_prefix, &ibdev->gid.s.prefix,
220 sizeof ( port_info->gid_prefix ) );
221 port_info->lid = ntohs ( ibdev->lid );
222 port_info->mastersm_lid = ntohs ( ibdev->sm_lid );
223 port_info->local_port_num = ibdev->port;
224 port_info->link_width_enabled = ibdev->link_width_enabled;
225 port_info->link_width_supported = ibdev->link_width_supported;
226 port_info->link_width_active = ibdev->link_width_active;
227 port_info->link_speed_supported__port_state =
228 ( ( ibdev->link_speed_supported << 4 ) | ibdev->port_state );
229 port_info->port_phys_state__link_down_def_state =
230 ( ( IB_PORT_PHYS_STATE_POLLING << 4 ) |
231 IB_PORT_PHYS_STATE_POLLING );
232 port_info->link_speed_active__link_speed_enabled =
233 ( ( ibdev->link_speed_active << 4 ) |
234 ibdev->link_speed_enabled );
235 port_info->neighbour_mtu__mastersm_sl =
236 ( ( IB_MTU_2048 << 4 ) | ibdev->sm_sl );
237 port_info->vl_cap__init_type = ( IB_VL_0 << 4 );
238 port_info->init_type_reply__mtu_cap = IB_MTU_2048;
239 port_info->operational_vls__enforcement = ( IB_VL_0 << 4 );
240 port_info->guid_cap = 1;
242 /* Send GetResponse */
243 mad->hdr.method = IB_MGMT_METHOD_GET_RESP;
244 if ( ( rc = ib_mi_send ( ibdev, mi, mad, av ) ) != 0 ) {
245 DBGC ( mi, "SMA %p could not send PortInfo GetResponse: %s\n",
246 mi, strerror ( rc ) );
252 * Set partition key table
254 * @v ibdev Infiniband device
255 * @v mi Management interface
256 * @v mad Received MAD
257 * @ret rc Return status code
259 static int ib_sma_set_pkey_table ( struct ib_device *ibdev,
260 struct ib_mad_interface *mi,
261 union ib_mad *mad ) {
262 struct ib_pkey_table *pkey_table = &mad->smp.smp_data.pkey_table;
266 ibdev->pkey = ntohs ( pkey_table->pkey[0] );
267 DBGC ( mi, "SMA %p set pkey %04x\n", mi, ibdev->pkey );
269 /* Update parameters on device */
270 if ( ( rc = ib_set_pkey_table ( ibdev, mad ) ) != 0 ) {
271 DBGC ( mi, "SMA %p could not set pkey table: %s\n",
272 mi, strerror ( rc ) );
280 * Partition key table
282 * @v ibdev Infiniband device
283 * @v mi Management interface
284 * @v mad Received MAD
285 * @v av Source address vector
287 static void ib_sma_pkey_table ( struct ib_device *ibdev,
288 struct ib_mad_interface *mi,
290 struct ib_address_vector *av ) {
291 struct ib_pkey_table *pkey_table = &mad->smp.smp_data.pkey_table;
294 /* Set parameters, if applicable */
295 if ( mad->hdr.method == IB_MGMT_METHOD_SET ) {
296 if ( ( rc = ib_sma_set_pkey_table ( ibdev, mi, mad ) ) != 0 ) {
298 htons ( IB_MGMT_STATUS_UNSUPPORTED_METHOD_ATTR );
299 /* Fall through to generate GetResponse */
303 /* Fill in information */
304 mad->hdr.method = IB_MGMT_METHOD_GET_RESP;
305 memset ( pkey_table, 0, sizeof ( *pkey_table ) );
306 pkey_table->pkey[0] = htons ( ibdev->pkey );
308 /* Send GetResponse */
309 mad->hdr.method = IB_MGMT_METHOD_GET_RESP;
310 if ( ( rc = ib_mi_send ( ibdev, mi, mad, av ) ) != 0 ) {
311 DBGC ( mi, "SMA %p could not send PKeyTable GetResponse: %s\n",
312 mi, strerror ( rc ) );
317 /** Subnet management agent */
318 struct ib_mad_agent ib_sma_agent[] __ib_mad_agent = {
320 .mgmt_class = IB_MGMT_CLASS_SUBN_LID_ROUTED,
321 .class_version = IB_SMP_CLASS_VERSION,
322 .attr_id = htons ( IB_SMP_ATTR_NODE_INFO ),
323 .handle = ib_sma_node_info,
326 .mgmt_class = IB_MGMT_CLASS_SUBN_LID_ROUTED,
327 .class_version = IB_SMP_CLASS_VERSION,
328 .attr_id = htons ( IB_SMP_ATTR_NODE_DESC ),
329 .handle = ib_sma_node_desc,
332 .mgmt_class = IB_MGMT_CLASS_SUBN_LID_ROUTED,
333 .class_version = IB_SMP_CLASS_VERSION,
334 .attr_id = htons ( IB_SMP_ATTR_GUID_INFO ),
335 .handle = ib_sma_guid_info,
338 .mgmt_class = IB_MGMT_CLASS_SUBN_LID_ROUTED,
339 .class_version = IB_SMP_CLASS_VERSION,
340 .attr_id = htons ( IB_SMP_ATTR_PORT_INFO ),
341 .handle = ib_sma_port_info,
344 .mgmt_class = IB_MGMT_CLASS_SUBN_LID_ROUTED,
345 .class_version = IB_SMP_CLASS_VERSION,
346 .attr_id = htons ( IB_SMP_ATTR_PKEY_TABLE ),
347 .handle = ib_sma_pkey_table,
352 * Create subnet management agent and interface
354 * @v ibdev Infiniband device
355 * @v mi Management interface
356 * @ret rc Return status code
358 int ib_create_sma ( struct ib_device *ibdev, struct ib_mad_interface *mi ) {
361 DBGC ( ibdev, "IBDEV %p SMA using SMI %p\n", ibdev, mi );
367 * Destroy subnet management agent and interface
369 * @v ibdev Infiniband device
370 * @v mi Management interface
372 void ib_destroy_sma ( struct ib_device *ibdev __unused,
373 struct ib_mad_interface *mi __unused ) {