iPXE
ib_smc.c
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2008 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  * 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.
22  */
23 
24 FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
25 
26 #include <stdint.h>
27 #include <stdlib.h>
28 #include <string.h>
29 #include <errno.h>
30 #include <unistd.h>
31 #include <byteswap.h>
32 #include <ipxe/infiniband.h>
33 #include <ipxe/ib_smc.h>
34 
35 /**
36  * @file
37  *
38  * Infiniband Subnet Management Client
39  *
40  */
41 
42 /**
43  * Issue local MAD
44  *
45  * @v ibdev Infiniband device
46  * @v attr_id Attribute ID, in network byte order
47  * @v attr_mod Attribute modifier, in network byte order
48  * @v local_mad Method for issuing local MADs
49  * @v mad Management datagram to fill in
50  * @ret rc Return status code
51  */
52 static int ib_smc_mad ( struct ib_device *ibdev, uint16_t attr_id,
53  uint32_t attr_mod, ib_local_mad_t local_mad,
54  union ib_mad *mad ) {
55  int rc;
56 
57  /* Construct MAD */
58  memset ( mad, 0, sizeof ( *mad ) );
61  mad->hdr.class_version = 1;
65 
66  /* Issue MAD */
67  if ( ( rc = local_mad ( ibdev, mad ) ) != 0 )
68  return rc;
69 
70  return 0;
71 }
72 
73 /**
74  * Get node information
75  *
76  * @v ibdev Infiniband device
77  * @v local_mad Method for issuing local MADs
78  * @v mad Management datagram to fill in
79  * @ret rc Return status code
80  */
81 static int ib_smc_get_node_info ( struct ib_device *ibdev,
82  ib_local_mad_t local_mad,
83  union ib_mad *mad ) {
84  int rc;
85 
86  /* Issue MAD */
87  if ( ( rc = ib_smc_mad ( ibdev, htons ( IB_SMP_ATTR_NODE_INFO ), 0,
88  local_mad, mad ) ) != 0 ) {
89  DBGC ( ibdev, "IBDEV %s could not get node info: %s\n",
90  ibdev->name, strerror ( rc ) );
91  return rc;
92  }
93  return 0;
94 }
95 
96 /**
97  * Get port information
98  *
99  * @v ibdev Infiniband device
100  * @v local_mad Method for issuing local MADs
101  * @v mad Management datagram to fill in
102  * @ret rc Return status code
103  */
104 static int ib_smc_get_port_info ( struct ib_device *ibdev,
105  ib_local_mad_t local_mad,
106  union ib_mad *mad ) {
107  int rc;
108 
109  /* Issue MAD */
110  if ( ( rc = ib_smc_mad ( ibdev, htons ( IB_SMP_ATTR_PORT_INFO ),
111  htonl ( ibdev->port ), local_mad, mad )) !=0){
112  DBGC ( ibdev, "IBDEV %s could not get port info: %s\n",
113  ibdev->name, strerror ( rc ) );
114  return rc;
115  }
116  return 0;
117 }
118 
119 /**
120  * Get GUID information
121  *
122  * @v ibdev Infiniband device
123  * @v local_mad Method for issuing local MADs
124  * @v mad Management datagram to fill in
125  * @ret rc Return status code
126  */
127 static int ib_smc_get_guid_info ( struct ib_device *ibdev,
128  ib_local_mad_t local_mad,
129  union ib_mad *mad ) {
130  int rc;
131 
132  /* Issue MAD */
133  if ( ( rc = ib_smc_mad ( ibdev, htons ( IB_SMP_ATTR_GUID_INFO ), 0,
134  local_mad, mad ) ) != 0 ) {
135  DBGC ( ibdev, "IBDEV %s could not get GUID info: %s\n",
136  ibdev->name, strerror ( rc ) );
137  return rc;
138  }
139  return 0;
140 }
141 
142 /**
143  * Get partition key table
144  *
145  * @v ibdev Infiniband device
146  * @v local_mad Method for issuing local MADs
147  * @v mad Management datagram to fill in
148  * @ret rc Return status code
149  */
150 static int ib_smc_get_pkey_table ( struct ib_device *ibdev,
151  ib_local_mad_t local_mad,
152  union ib_mad *mad ) {
153  int rc;
154 
155  /* Issue MAD */
156  if ( ( rc = ib_smc_mad ( ibdev, htons ( IB_SMP_ATTR_PKEY_TABLE ), 0,
157  local_mad, mad ) ) != 0 ) {
158  DBGC ( ibdev, "IBDEV %s could not get pkey table: %s\n",
159  ibdev->name, strerror ( rc ) );
160  return rc;
161  }
162  return 0;
163 }
164 
165 /**
166  * Get Infiniband parameters using SMC
167  *
168  * @v ibdev Infiniband device
169  * @v local_mad Method for issuing local MADs
170  * @ret rc Return status code
171  */
172 static int ib_smc_get ( struct ib_device *ibdev, ib_local_mad_t local_mad ) {
173  union ib_mad mad;
178  int rc;
179 
180  /* Node info gives us the node GUID */
181  if ( ( rc = ib_smc_get_node_info ( ibdev, local_mad, &mad ) ) != 0 )
182  return rc;
183  memcpy ( &ibdev->node_guid, &node_info->node_guid,
184  sizeof ( ibdev->node_guid ) );
185 
186  /* Port info gives us the link state, the first half of the
187  * port GID and the SM LID.
188  */
189  if ( ( rc = ib_smc_get_port_info ( ibdev, local_mad, &mad ) ) != 0 )
190  return rc;
191  memcpy ( &ibdev->gid.s.prefix, port_info->gid_prefix,
192  sizeof ( ibdev->gid.s.prefix ) );
193  ibdev->lid = ntohs ( port_info->lid );
194  ibdev->sm_lid = ntohs ( port_info->mastersm_lid );
198  ibdev->link_speed_supported =
200  ibdev->port_state =
202  ibdev->link_speed_active =
204  ibdev->link_speed_enabled =
206  ibdev->sm_sl = ( port_info->neighbour_mtu__mastersm_sl & 0xf );
207 
208  /* GUID info gives us the second half of the port GID */
209  if ( ( rc = ib_smc_get_guid_info ( ibdev, local_mad, &mad ) ) != 0 )
210  return rc;
211  memcpy ( &ibdev->gid.s.guid, guid_info->guid[0],
212  sizeof ( ibdev->gid.s.guid ) );
213 
214  /* Get partition key */
215  if ( ( rc = ib_smc_get_pkey_table ( ibdev, local_mad, &mad ) ) != 0 )
216  return rc;
217  ibdev->pkey = ntohs ( pkey_table->pkey[0] );
218 
219  DBGC ( ibdev, "IBDEV %s port GID is " IB_GID_FMT "\n",
220  ibdev->name, IB_GID_ARGS ( &ibdev->gid ) );
221 
222  return 0;
223 }
224 
225 /**
226  * Initialise Infiniband parameters using SMC
227  *
228  * @v ibdev Infiniband device
229  * @v local_mad Method for issuing local MADs
230  * @ret rc Return status code
231  */
232 int ib_smc_init ( struct ib_device *ibdev, ib_local_mad_t local_mad ) {
233  int rc;
234 
235  /* Get MAD parameters */
236  if ( ( rc = ib_smc_get ( ibdev, local_mad ) ) != 0 )
237  return rc;
238 
239  return 0;
240 }
241 
242 /**
243  * Update Infiniband parameters using SMC
244  *
245  * @v ibdev Infiniband device
246  * @v local_mad Method for issuing local MADs
247  * @ret rc Return status code
248  */
249 int ib_smc_update ( struct ib_device *ibdev, ib_local_mad_t local_mad ) {
250  int rc;
251 
252  /* Get MAD parameters */
253  if ( ( rc = ib_smc_get ( ibdev, local_mad ) ) != 0 )
254  return rc;
255 
256  /* Notify Infiniband core of potential link state change */
257  ib_link_state_changed ( ibdev );
258 
259  return 0;
260 }
struct ib_node_info node_info
Definition: ib_mad.h:182
uint8_t method
Definition: ib_mad.h:542
#define IB_MGMT_METHOD_GET
Definition: ib_mad.h:569
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
Infiniband protocol.
unsigned short uint16_t
Definition: stdint.h:11
char name[IBDEV_NAME_LEN]
Name of this Infiniband device.
Definition: infiniband.h:408
union ib_guid guid
Definition: ib_packet.h:40
union ib_gid gid
Port GID (comprising GID prefix and port GUID)
Definition: infiniband.h:441
uint8_t link_width_enabled
Definition: ib_mad.h:113
#define IB_SMP_ATTR_NODE_INFO
Definition: ib_mad.h:45
Error codes.
uint8_t link_width_active
Definition: ib_mad.h:115
uint16_t lid
Port LID.
Definition: infiniband.h:443
uint16_t mastersm_lid
Definition: ib_mad.h:108
#define DBGC(...)
Definition: compiler.h:505
int(* ib_local_mad_t)(struct ib_device *ibdev, union ib_mad *mad)
Definition: ib_smc.h:14
union ib_smp_data smp_data
Definition: ib_mad.h:590
union ib_guid node_guid
Definition: ib_mad.h:79
uint16_t lid
Definition: ib_mad.h:107
#define ntohs(value)
Definition: byteswap.h:136
void ib_link_state_changed(struct ib_device *ibdev)
Notify of Infiniband link state change.
Definition: infiniband.c:637
uint8_t mgmt_class
Definition: ib_mad.h:540
uint8_t link_speed_enabled
Link speed enabled.
Definition: infiniband.h:435
static int ib_smc_get_pkey_table(struct ib_device *ibdev, ib_local_mad_t local_mad, union ib_mad *mad)
Get partition key table.
Definition: ib_smc.c:150
static int ib_smc_mad(struct ib_device *ibdev, uint16_t attr_id, uint32_t attr_mod, ib_local_mad_t local_mad, union ib_mad *mad)
Issue local MAD.
Definition: ib_smc.c:52
#define htonl(value)
Definition: byteswap.h:133
#define IB_MGMT_CLASS_SUBN_LID_ROUTED
Definition: ib_mad.h:555
uint8_t link_width_enabled
Link width enabled.
Definition: infiniband.h:429
uint8_t link_speed_active__link_speed_enabled
Definition: ib_mad.h:119
struct ib_port_info port_info
Definition: ib_mad.h:14
uint8_t link_width_supported
Link width supported.
Definition: infiniband.h:427
struct ib_port_info port_info
Definition: ib_mad.h:184
uint8_t guid[8][8]
Definition: ib_mad.h:97
An Infiniband device.
Definition: infiniband.h:398
void * memcpy(void *dest, const void *src, size_t len) __nonnull
uint8_t class_version
Definition: ib_mad.h:541
int ib_smc_init(struct ib_device *ibdev, ib_local_mad_t local_mad)
Initialise Infiniband parameters using SMC.
Definition: ib_smc.c:232
uint8_t link_speed_supported__port_state
Definition: ib_mad.h:116
A Node Information attribute.
Definition: ib_mad.h:73
uint16_t sm_lid
Subnet manager LID.
Definition: infiniband.h:445
struct ib_gid::@559 s
uint16_t pkey[32]
Definition: ib_mad.h:176
uint8_t sm_sl
Subnet manager SL.
Definition: infiniband.h:447
#define IB_GID_ARGS(gid)
Infiniband Global Identifier debug message arguments.
Definition: ib_packet.h:48
union ib_guid prefix
Definition: ib_packet.h:39
unsigned int port
Port number.
Definition: infiniband.h:418
char * strerror(int errno)
Retrieve string representation of error number.
Definition: strerror.c:78
struct ib_mad_smp smp
Definition: ib_mad.h:612
#define IB_SMP_ATTR_GUID_INFO
Definition: ib_mad.h:47
struct ib_node_info node_info
Definition: ib_mad.h:12
uint8_t neighbour_mtu__mastersm_sl
Definition: ib_mad.h:120
struct ib_pkey_table pkey_table
Definition: ib_mad.h:15
union ib_guid node_guid
Node GUID.
Definition: infiniband.h:439
#define IB_SMP_ATTR_PKEY_TABLE
Definition: ib_mad.h:49
int ib_smc_update(struct ib_device *ibdev, ib_local_mad_t local_mad)
Update Infiniband parameters using SMC.
Definition: ib_smc.c:249
static int ib_smc_get_port_info(struct ib_device *ibdev, ib_local_mad_t local_mad, union ib_mad *mad)
Get port information.
Definition: ib_smc.c:104
uint8_t link_width_active
Link width active.
Definition: infiniband.h:431
uint8_t gid_prefix[8]
Definition: ib_mad.h:106
unsigned int uint32_t
Definition: stdint.h:12
#define IB_SMP_ATTR_PORT_INFO
Definition: ib_mad.h:48
uint8_t base_version
Definition: ib_mad.h:539
uint8_t link_width_supported
Definition: ib_mad.h:114
struct ib_mad_hdr hdr
Definition: ib_mad.h:611
uint8_t link_speed_active
Link speed active.
Definition: infiniband.h:437
struct ib_guid_info guid_info
Definition: ib_mad.h:183
#define IB_GID_FMT
Infiniband Global Identifier debug message format.
Definition: ib_packet.h:45
uint8_t port_state
Port state.
Definition: infiniband.h:425
static int ib_smc_get_node_info(struct ib_device *ibdev, ib_local_mad_t local_mad, union ib_mad *mad)
Get node information.
Definition: ib_smc.c:81
uint16_t attr_id
Definition: ib_mad.h:546
A management datagram.
Definition: ib_mad.h:610
FILE_LICENCE(GPL2_OR_LATER_OR_UBDL)
#define IB_MGMT_BASE_VERSION
Definition: ib_mad.h:552
uint32_t attr_mod
Definition: ib_mad.h:548
uint8_t link_speed_supported
Link speed supported.
Definition: infiniband.h:433
struct ib_pkey_table pkey_table
Definition: ib_mad.h:185
uint16_t pkey
Partition key.
Definition: infiniband.h:449
static int ib_smc_get(struct ib_device *ibdev, ib_local_mad_t local_mad)
Get Infiniband parameters using SMC.
Definition: ib_smc.c:172
Infiniband Subnet Management Client.
A Partition Key Table attribute.
Definition: ib_mad.h:175
A GUID Information attribute.
Definition: ib_mad.h:96
String functions.
static int ib_smc_get_guid_info(struct ib_device *ibdev, ib_local_mad_t local_mad, union ib_mad *mad)
Get GUID information.
Definition: ib_smc.c:127
uint32_t attr_mod
Definition: ib_mad.h:20
A Port Information attribute.
Definition: ib_mad.h:104
#define htons(value)
Definition: byteswap.h:135
uint16_t attr_id
Definition: ib_mad.h:18
union ib_mad mad
Definition: arbel.h:12
void * memset(void *dest, int character, size_t len) __nonnull
struct ib_guid_info guid_info
Definition: ib_mad.h:13