iPXE
ib_sma.c File Reference

Infiniband Subnet Management Agent. More...

#include <stdint.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include <stdio.h>
#include <unistd.h>
#include <byteswap.h>
#include <ipxe/settings.h>
#include <ipxe/infiniband.h>
#include <ipxe/iobuf.h>
#include <ipxe/ib_mi.h>
#include <ipxe/ib_sma.h>

Go to the source code of this file.

Functions

 FILE_LICENCE (GPL2_OR_LATER_OR_UBDL)
static void ib_sma_node_info (struct ib_device *ibdev, struct ib_mad_interface *mi, union ib_mad *mad, struct ib_address_vector *av)
 Node information.
static void ib_sma_node_desc (struct ib_device *ibdev, struct ib_mad_interface *mi, union ib_mad *mad, struct ib_address_vector *av)
 Node description.
static void ib_sma_guid_info (struct ib_device *ibdev, struct ib_mad_interface *mi, union ib_mad *mad, struct ib_address_vector *av)
 GUID information.
static int ib_sma_set_port_info (struct ib_device *ibdev, struct ib_mad_interface *mi, union ib_mad *mad)
 Set port information.
static void ib_sma_port_info (struct ib_device *ibdev, struct ib_mad_interface *mi, union ib_mad *mad, struct ib_address_vector *av)
 Port information.
static int ib_sma_set_pkey_table (struct ib_device *ibdev, struct ib_mad_interface *mi, union ib_mad *mad)
 Set partition key table.
static void ib_sma_pkey_table (struct ib_device *ibdev, struct ib_mad_interface *mi, union ib_mad *mad, struct ib_address_vector *av)
 Partition key table.
int ib_create_sma (struct ib_device *ibdev, struct ib_mad_interface *mi)
 Create subnet management agent and interface.
void ib_destroy_sma (struct ib_device *ibdev __unused, struct ib_mad_interface *mi __unused)
 Destroy subnet management agent and interface.

Variables

struct ib_mad_agent ib_sma_agent[] __ib_mad_agent
 Subnet management agent.

Detailed Description

Infiniband Subnet Management Agent.

Definition in file ib_sma.c.

Function Documentation

◆ FILE_LICENCE()

FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL )

◆ ib_sma_node_info()

void ib_sma_node_info ( struct ib_device * ibdev,
struct ib_mad_interface * mi,
union ib_mad * mad,
struct ib_address_vector * av )
static

Node information.

Parameters
ibdevInfiniband device
miManagement interface
madReceived MAD
avSource address vector

Definition at line 54 of file ib_sma.c.

57 {
58 struct ib_node_info *node_info = &mad->smp.smp_data.node_info;
59 int rc;
60
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 = ibdev->ports;
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;
75
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 ) );
81 return;
82 }
83}
struct arbelprm_rc_send_wqe rc
Definition arbel.h:3
union ib_mad mad
Definition arbel.h:1
#define DBGC(...)
Definition compiler.h:505
#define IB_MGMT_BASE_VERSION
Definition ib_mad.h:553
#define IB_MGMT_METHOD_GET_RESP
Definition ib_mad.h:572
#define IB_SMP_CLASS_VERSION
Subnet management class version.
Definition ib_mad.h:35
struct ib_node_info node_info
Definition ib_mad.h:1
#define IB_NODE_TYPE_HCA
Definition ib_mad.h:89
int ib_mi_send(struct ib_device *ibdev, struct ib_mad_interface *mi, union ib_mad *mad, struct ib_address_vector *av)
Transmit MAD.
Definition ib_mi.c:187
#define htons(value)
Definition byteswap.h:136
void * memcpy(void *dest, const void *src, size_t len) __nonnull
void * memset(void *dest, int character, size_t len) __nonnull
char * strerror(int errno)
Retrieve string representation of error number.
Definition strerror.c:79
unsigned int ports
Total ports on device.
Definition infiniband.h:421
union ib_guid node_guid
Node GUID.
Definition infiniband.h:440
union ib_gid gid
Port GID (comprising GID prefix and port GUID)
Definition infiniband.h:442
unsigned int port
Port number.
Definition infiniband.h:419
A Node Information attribute.
Definition ib_mad.h:74
struct ib_gid::@251011351113275240012301235177256303262052134237 s
union ib_guid guid
Definition ib_packet.h:41

References DBGC, ib_device::gid, ib_gid::guid, htons, IB_MGMT_BASE_VERSION, IB_MGMT_METHOD_GET_RESP, ib_mi_send(), IB_NODE_TYPE_HCA, IB_SMP_CLASS_VERSION, mad, memcpy(), memset(), ib_device::node_guid, node_info, ib_device::port, ib_device::ports, rc, ib_gid::s, and strerror().

◆ ib_sma_node_desc()

void ib_sma_node_desc ( struct ib_device * ibdev,
struct ib_mad_interface * mi,
union ib_mad * mad,
struct ib_address_vector * av )
static

Node description.

Parameters
ibdevInfiniband device
miManagement interface
madReceived MAD
avSource address vector

Definition at line 93 of file ib_sma.c.

96 {
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 ) ];
100 int hostname_len;
101 int rc;
102
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 );
113
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 ) );
119 return;
120 }
121}
#define NULL
NULL pointer (VOID *)
Definition Base.h:322
uint64_t guid
GUID.
Definition edd.h:1
struct ib_node_desc node_desc
Definition ib_mad.h:0
int fetch_string_setting(struct settings *settings, const struct setting *setting, char *data, size_t len)
Fetch value of string setting.
Definition settings.c:842
char name[40]
Name.
Definition device.h:79
struct device * dev
Underlying device.
Definition infiniband.h:411
A Node Description attribute.
Definition ib_mad.h:66
An Infiniband Globally Unique Identifier.
Definition ib_packet.h:19
int snprintf(char *buf, size_t size, const char *fmt,...)
Write a formatted string to a buffer.
Definition vsprintf.c:383

References DBGC, ib_device::dev, fetch_string_setting(), guid, IB_MGMT_METHOD_GET_RESP, ib_mi_send(), mad, memset(), device::name, node_desc, ib_device::node_guid, NULL, rc, snprintf(), and strerror().

◆ ib_sma_guid_info()

void ib_sma_guid_info ( struct ib_device * ibdev,
struct ib_mad_interface * mi,
union ib_mad * mad,
struct ib_address_vector * av )
static

GUID information.

Parameters
ibdevInfiniband device
miManagement interface
madReceived MAD
avSource address vector

Definition at line 131 of file ib_sma.c.

134 {
135 struct ib_guid_info *guid_info = &mad->smp.smp_data.guid_info;
136 int rc;
137
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] ) );
142
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 ) );
148 return;
149 }
150}
struct ib_guid_info guid_info
Definition ib_mad.h:2
A GUID Information attribute.
Definition ib_mad.h:97

References DBGC, ib_device::gid, ib_gid::guid, guid_info, IB_MGMT_METHOD_GET_RESP, ib_mi_send(), mad, memcpy(), memset(), rc, ib_gid::s, and strerror().

◆ ib_sma_set_port_info()

int ib_sma_set_port_info ( struct ib_device * ibdev,
struct ib_mad_interface * mi,
union ib_mad * mad )
static

Set port information.

Parameters
ibdevInfiniband device
miManagement interface
madReceived MAD
Return values
rcReturn status code

Definition at line 160 of file ib_sma.c.

162 {
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;
166 int rc;
167
168 /* Set parameters */
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 ) )
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 %d SMLID %d link width %d speed %d\n",
180 mi, ibdev->lid, ibdev->sm_lid, ibdev->link_width_enabled,
181 ibdev->link_speed_enabled );
182
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 ) );
187 return rc;
188 }
189
190 return 0;
191}
struct ib_port_info port_info
Definition ib_mad.h:3
uint8_t link_width_enabled
Definition ib_mad.h:8
#define ntohs(value)
Definition byteswap.h:137
int ib_set_port_info(struct ib_device *ibdev, union ib_mad *mad)
Set port information.
Definition infiniband.c:822
uint8_t sm_sl
Subnet manager SL.
Definition infiniband.h:448
uint8_t link_width_enabled
Link width enabled.
Definition infiniband.h:430
uint16_t sm_lid
Subnet manager LID.
Definition infiniband.h:446
uint8_t link_speed_enabled
Link speed enabled.
Definition infiniband.h:436
uint16_t lid
Port LID.
Definition infiniband.h:444
A Port Information attribute.
Definition ib_mad.h:105
union ib_guid prefix
Definition ib_packet.h:40

References DBGC, ib_device::gid, ib_set_port_info(), ib_device::lid, ib_device::link_speed_enabled, ib_device::link_width_enabled, link_width_enabled, mad, memcpy(), ntohs, port_info, ib_gid::prefix, rc, ib_gid::s, ib_device::sm_lid, ib_device::sm_sl, and strerror().

Referenced by ib_sma_port_info().

◆ ib_sma_port_info()

void ib_sma_port_info ( struct ib_device * ibdev,
struct ib_mad_interface * mi,
union ib_mad * mad,
struct ib_address_vector * av )
static

Port information.

Parameters
ibdevInfiniband device
miManagement interface
madReceived MAD
avSource address vector

Definition at line 201 of file ib_sma.c.

204 {
205 struct ib_port_info *port_info = &mad->smp.smp_data.port_info;
206 int rc;
207
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 ) {
211 mad->hdr.status =
213 /* Fall through to generate GetResponse */
214 }
215 }
216
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 ) |
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;
241
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 ) );
247 return;
248 }
249}
#define IB_MGMT_STATUS_UNSUPPORTED_METHOD_ATTR
Definition ib_mad.h:584
#define IB_MTU_2048
Definition ib_mad.h:163
#define IB_PORT_PHYS_STATE_POLLING
Definition ib_mad.h:158
#define IB_VL_0
Definition ib_mad.h:166
#define IB_MGMT_METHOD_SET
Definition ib_mad.h:571
static int ib_sma_set_port_info(struct ib_device *ibdev, struct ib_mad_interface *mi, union ib_mad *mad)
Set port information.
Definition ib_sma.c:160
uint8_t link_speed_active
Link speed active.
Definition infiniband.h:438
uint8_t link_speed_supported
Link speed supported.
Definition infiniband.h:434
uint8_t link_width_active
Link width active.
Definition infiniband.h:432
uint8_t link_width_supported
Link width supported.
Definition infiniband.h:428
uint8_t port_state
Port state.
Definition infiniband.h:426

References DBGC, ib_device::gid, htons, IB_MGMT_METHOD_GET_RESP, IB_MGMT_METHOD_SET, IB_MGMT_STATUS_UNSUPPORTED_METHOD_ATTR, ib_mi_send(), IB_MTU_2048, IB_PORT_PHYS_STATE_POLLING, ib_sma_set_port_info(), IB_VL_0, ib_device::lid, ib_device::link_speed_active, ib_device::link_speed_enabled, ib_device::link_speed_supported, ib_device::link_width_active, ib_device::link_width_enabled, ib_device::link_width_supported, mad, memcpy(), memset(), ntohs, ib_device::port, port_info, ib_device::port_state, ib_gid::prefix, rc, ib_gid::s, ib_device::sm_lid, ib_device::sm_sl, and strerror().

◆ ib_sma_set_pkey_table()

int ib_sma_set_pkey_table ( struct ib_device * ibdev,
struct ib_mad_interface * mi,
union ib_mad * mad )
static

Set partition key table.

Parameters
ibdevInfiniband device
miManagement interface
madReceived MAD
Return values
rcReturn status code

Definition at line 259 of file ib_sma.c.

261 {
262 struct ib_pkey_table *pkey_table = &mad->smp.smp_data.pkey_table;
263 int rc;
264
265 /* Set parameters */
266 ibdev->pkey = ntohs ( pkey_table->pkey[0] );
267 DBGC ( mi, "SMA %p set pkey %04x\n", mi, ibdev->pkey );
268
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 ) );
273 return rc;
274 }
275
276 return 0;
277}
struct ib_pkey_table pkey_table
Definition ib_mad.h:4
int ib_set_pkey_table(struct ib_device *ibdev, union ib_mad *mad)
Set partition key table.
Definition infiniband.c:847
uint16_t pkey
Partition key.
Definition infiniband.h:450
A Partition Key Table attribute.
Definition ib_mad.h:176

References DBGC, ib_set_pkey_table(), mad, ntohs, ib_device::pkey, pkey_table, rc, and strerror().

Referenced by ib_sma_pkey_table().

◆ ib_sma_pkey_table()

void ib_sma_pkey_table ( struct ib_device * ibdev,
struct ib_mad_interface * mi,
union ib_mad * mad,
struct ib_address_vector * av )
static

Partition key table.

Parameters
ibdevInfiniband device
miManagement interface
madReceived MAD
avSource address vector

Definition at line 287 of file ib_sma.c.

290 {
291 struct ib_pkey_table *pkey_table = &mad->smp.smp_data.pkey_table;
292 int rc;
293
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 ) {
297 mad->hdr.status =
299 /* Fall through to generate GetResponse */
300 }
301 }
302
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 );
307
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 ) );
313 return;
314 }
315}
static int ib_sma_set_pkey_table(struct ib_device *ibdev, struct ib_mad_interface *mi, union ib_mad *mad)
Set partition key table.
Definition ib_sma.c:259

References DBGC, htons, IB_MGMT_METHOD_GET_RESP, IB_MGMT_METHOD_SET, IB_MGMT_STATUS_UNSUPPORTED_METHOD_ATTR, ib_mi_send(), ib_sma_set_pkey_table(), mad, memset(), ib_device::pkey, pkey_table, rc, and strerror().

◆ ib_create_sma()

int ib_create_sma ( struct ib_device * ibdev,
struct ib_mad_interface * mi )

Create subnet management agent and interface.

Parameters
ibdevInfiniband device
miManagement interface
Return values
rcReturn status code

Definition at line 358 of file ib_sma.c.

358 {
359
360 /* Nothing to do */
361 DBGC ( ibdev, "IBDEV %s SMA using SMI %p\n", ibdev->name, mi );
362
363 return 0;
364}
char name[IBDEV_NAME_LEN]
Name of this Infiniband device.
Definition infiniband.h:409

References DBGC, and ib_device::name.

Referenced by ib_open().

◆ ib_destroy_sma()

void ib_destroy_sma ( struct ib_device *ibdev __unused,
struct ib_mad_interface *mi __unused )

Destroy subnet management agent and interface.

Parameters
ibdevInfiniband device
miManagement interface

Definition at line 372 of file ib_sma.c.

373 {
374 /* Nothing to do */
375}

References __unused.

Referenced by ib_close(), and ib_open().

Variable Documentation

◆ __ib_mad_agent

struct ib_mad_agent ib_sma_agent [] __ib_mad_agent

Subnet management agent.

Definition at line 318 of file ib_sma.c.

318 {
319 {
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,
324 },
325 {
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,
330 },
331 {
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,
336 },
337 {
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,
342 },
343 {
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,
348 },
349};
#define IB_SMP_ATTR_NODE_INFO
Definition ib_mad.h:46
#define IB_SMP_ATTR_NODE_DESC
Definition ib_mad.h:45
#define IB_MGMT_CLASS_SUBN_LID_ROUTED
Definition ib_mad.h:556
#define IB_SMP_ATTR_GUID_INFO
Definition ib_mad.h:48
#define IB_SMP_ATTR_PORT_INFO
Definition ib_mad.h:49
#define IB_SMP_ATTR_PKEY_TABLE
Definition ib_mad.h:50
static void ib_sma_guid_info(struct ib_device *ibdev, struct ib_mad_interface *mi, union ib_mad *mad, struct ib_address_vector *av)
GUID information.
Definition ib_sma.c:131
static void ib_sma_port_info(struct ib_device *ibdev, struct ib_mad_interface *mi, union ib_mad *mad, struct ib_address_vector *av)
Port information.
Definition ib_sma.c:201
static void ib_sma_node_desc(struct ib_device *ibdev, struct ib_mad_interface *mi, union ib_mad *mad, struct ib_address_vector *av)
Node description.
Definition ib_sma.c:93
static void ib_sma_pkey_table(struct ib_device *ibdev, struct ib_mad_interface *mi, union ib_mad *mad, struct ib_address_vector *av)
Partition key table.
Definition ib_sma.c:287
static void ib_sma_node_info(struct ib_device *ibdev, struct ib_mad_interface *mi, union ib_mad *mad, struct ib_address_vector *av)
Node information.
Definition ib_sma.c:54