2 * Copyright (C) 2008 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 );
32 #include <ipxe/infiniband.h>
33 #include <ipxe/ib_smc.h>
38 * Infiniband Subnet Management Client
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
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,
58 memset ( mad, 0, sizeof ( *mad ) );
59 mad->hdr.base_version = IB_MGMT_BASE_VERSION;
60 mad->hdr.mgmt_class = IB_MGMT_CLASS_SUBN_LID_ROUTED;
61 mad->hdr.class_version = 1;
62 mad->hdr.method = IB_MGMT_METHOD_GET;
63 mad->hdr.attr_id = attr_id;
64 mad->hdr.attr_mod = attr_mod;
67 if ( ( rc = local_mad ( ibdev, mad ) ) != 0 )
74 * Get node information
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
81 static int ib_smc_get_node_info ( struct ib_device *ibdev,
82 ib_local_mad_t local_mad,
87 if ( ( rc = ib_smc_mad ( ibdev, htons ( IB_SMP_ATTR_NODE_INFO ), 0,
88 local_mad, mad ) ) != 0 ) {
89 DBGC ( ibdev, "IBDEV %p could not get node info: %s\n",
90 ibdev, strerror ( rc ) );
97 * Get port information
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
104 static int ib_smc_get_port_info ( struct ib_device *ibdev,
105 ib_local_mad_t local_mad,
106 union ib_mad *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 %p could not get port info: %s\n",
113 ibdev, strerror ( rc ) );
120 * Get GUID information
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
127 static int ib_smc_get_guid_info ( struct ib_device *ibdev,
128 ib_local_mad_t local_mad,
129 union ib_mad *mad ) {
133 if ( ( rc = ib_smc_mad ( ibdev, htons ( IB_SMP_ATTR_GUID_INFO ), 0,
134 local_mad, mad ) ) != 0 ) {
135 DBGC ( ibdev, "IBDEV %p could not get GUID info: %s\n",
136 ibdev, strerror ( rc ) );
143 * Get partition key table
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
150 static int ib_smc_get_pkey_table ( struct ib_device *ibdev,
151 ib_local_mad_t local_mad,
152 union ib_mad *mad ) {
156 if ( ( rc = ib_smc_mad ( ibdev, htons ( IB_SMP_ATTR_PKEY_TABLE ), 0,
157 local_mad, mad ) ) != 0 ) {
158 DBGC ( ibdev, "IBDEV %p could not get pkey table: %s\n",
159 ibdev, strerror ( rc ) );
166 * Get Infiniband parameters using SMC
168 * @v ibdev Infiniband device
169 * @v local_mad Method for issuing local MADs
170 * @ret rc Return status code
172 static int ib_smc_get ( struct ib_device *ibdev, ib_local_mad_t local_mad ) {
174 struct ib_node_info *node_info = &mad.smp.smp_data.node_info;
175 struct ib_port_info *port_info = &mad.smp.smp_data.port_info;
176 struct ib_guid_info *guid_info = &mad.smp.smp_data.guid_info;
177 struct ib_pkey_table *pkey_table = &mad.smp.smp_data.pkey_table;
180 /* Node info gives us the node GUID */
181 if ( ( rc = ib_smc_get_node_info ( ibdev, local_mad, &mad ) ) != 0 )
183 memcpy ( &ibdev->node_guid, &node_info->node_guid,
184 sizeof ( ibdev->node_guid ) );
186 /* Port info gives us the link state, the first half of the
187 * port GID and the SM LID.
189 if ( ( rc = ib_smc_get_port_info ( ibdev, local_mad, &mad ) ) != 0 )
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 );
195 ibdev->link_width_enabled = port_info->link_width_enabled;
196 ibdev->link_width_supported = port_info->link_width_supported;
197 ibdev->link_width_active = port_info->link_width_active;
198 ibdev->link_speed_supported =
199 ( port_info->link_speed_supported__port_state >> 4 );
201 ( port_info->link_speed_supported__port_state & 0xf );
202 ibdev->link_speed_active =
203 ( port_info->link_speed_active__link_speed_enabled >> 4 );
204 ibdev->link_speed_enabled =
205 ( port_info->link_speed_active__link_speed_enabled & 0xf );
206 ibdev->sm_sl = ( port_info->neighbour_mtu__mastersm_sl & 0xf );
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 )
211 memcpy ( &ibdev->gid.s.guid, guid_info->guid[0],
212 sizeof ( ibdev->gid.s.guid ) );
214 /* Get partition key */
215 if ( ( rc = ib_smc_get_pkey_table ( ibdev, local_mad, &mad ) ) != 0 )
217 ibdev->pkey = ntohs ( pkey_table->pkey[0] );
219 DBGC ( ibdev, "IBDEV %p port GID is " IB_GID_FMT "\n",
220 ibdev, IB_GID_ARGS ( &ibdev->gid ) );
226 * Initialise Infiniband parameters using SMC
228 * @v ibdev Infiniband device
229 * @v local_mad Method for issuing local MADs
230 * @ret rc Return status code
232 int ib_smc_init ( struct ib_device *ibdev, ib_local_mad_t local_mad ) {
235 /* Get MAD parameters */
236 if ( ( rc = ib_smc_get ( ibdev, local_mad ) ) != 0 )
243 * Update Infiniband parameters using SMC
245 * @v ibdev Infiniband device
246 * @v local_mad Method for issuing local MADs
247 * @ret rc Return status code
249 int ib_smc_update ( struct ib_device *ibdev, ib_local_mad_t local_mad ) {
252 /* Get MAD parameters */
253 if ( ( rc = ib_smc_get ( ibdev, local_mad ) ) != 0 )
256 /* Notify Infiniband core of potential link state change */
257 ib_link_state_changed ( ibdev );