2 * Copyright (c) 2004-2008 Voltaire, Inc. All rights reserved.
3 * Copyright (c) 2002-2005 Mellanox Technologies LTD. All rights reserved.
4 * Copyright (c) 1996-2003 Intel Corporation. All rights reserved.
6 * This software is available to you under a choice of one of two
7 * licenses. You may choose to be licensed under the terms of the GNU
8 * General Public License (GPL) Version 2, available from the file
9 * COPYING in the main directory of this source tree, or the
10 * OpenIB.org BSD license below:
12 * Redistribution and use in source and binary forms, with or
13 * without modification, are permitted provided that the following
16 * - Redistributions of source code must retain the above
17 * copyright notice, this list of conditions and the following
20 * - Redistributions in binary form must reproduce the above
21 * copyright notice, this list of conditions and the following
22 * disclaimer in the documentation and/or other materials
23 * provided with the distribution.
25 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
26 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
27 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
28 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
29 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
30 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
31 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
36 /* AUTHOR Eitan Zahavi
39 * The lower-level MAD transport interface implementation
40 * that allows sending a single MAD/receiving a callback
41 * when a single MAD is received.
46 #endif /* HAVE_CONFIG_H */
48 #include <sys/types.h>
50 #include <sys/ioctl.h>
56 #include <vendor/osm_vendor_api.h>
57 #include <vendor/osm_vendor_mlx_transport.h>
58 #include <vendor/osm_vendor_mlx_dispatcher.h>
59 #include <vendor/osm_vendor_mlx_svc.h>
60 #include <complib/cl_thread.h>
62 /* the simulator messages definition */
63 #include <ibmgtsim/ibms_client_api.h>
65 typedef struct _osmv_ibms_transport_mgr {
66 ibms_conn_handle_t conHdl; /* the connection handle we talk to */
67 ibms_bind_msg_t filter; /* the bind message defining the filtering */
68 cl_thread_t receiver; /* the thread waiting for incomming messages */
69 } osmv_ibms_transport_mgr_t;
72 __osmv_ibms_mad_addr_to_osm_addr(IN osm_vendor_t const *p_vend,
73 IN struct _ibms_mad_addr *p_ibms_addr,
75 OUT osm_mad_addr_t * p_osm_addr);
78 __osmv_ibms_osm_addr_to_mad_addr(IN const osm_mad_addr_t * p_osm_addr,
80 OUT struct _ibms_mad_addr *p_ibms_addr);
82 /* this is the callback function the "server" will call on incoming
84 void __osmv_ibms_receiver_callback(void *p_ctx, ibms_mad_msg_t * p_mad)
86 osm_mad_addr_t mad_addr;
87 osmv_bind_obj_t *const p_bo = (osmv_bind_obj_t *) p_ctx;
88 ib_api_status_t status = IB_SUCCESS;
90 /* Make sure the p_bo object is still relevant */
91 if ((p_bo->magic_ptr != p_bo) || p_bo->is_closing)
95 OSM_LOG_ENTER(p_bo->p_vendor->p_log);
98 osm_log(p_bo->p_vendor->p_log, OSM_LOG_DEBUG,
99 "__osmv_ibms_receiver_callback: "
100 "MAD QPN:%d SLID:0x%04x class:0x%02x "
101 "method:0x%02x attr:0x%04x status:0x%04x "
102 "tid:0x%016" PRIx64 "\n",
104 cl_ntoh16(p_mad->addr.slid),
105 p_mad->header.mgmt_class,
106 p_mad->header.method,
107 cl_ntoh16(p_mad->header.attr_id),
108 cl_ntoh16(p_mad->header.status),
109 cl_ntoh64(p_mad->header.trans_id));
111 /* first arrange an address */
112 __osmv_ibms_mad_addr_to_osm_addr(p_bo->p_vendor,
114 (((ib_mad_t *) & p_mad->
115 header)->mgmt_class ==
118 (((ib_mad_t *) & p_mad->
119 header)->mgmt_class ==
123 /* call the receiver callback */
126 osmv_dispatch_mad((osm_bind_handle_t) p_bo,
127 (void *)&p_mad->header, &mad_addr);
129 OSM_LOG_EXIT(p_bo->p_vendor->p_log);
134 osm_vendor_get_guid_by_ca_and_port(IN osm_vendor_t * const p_vend,
136 IN uint32_t port_num,
137 OUT uint64_t * p_port_guid);
141 * osmv_transport_init
144 * Setup the MAD transport infrastructure (filters, callbacks etc).
148 osmv_transport_init(IN osm_bind_info_t * p_info,
149 IN char hca_id[VENDOR_HCA_MAXNAMES],
150 IN uint8_t hca_idx, IN osmv_bind_obj_t * p_bo)
152 ibms_conn_handle_t conHdl; /* the connection we talk to the simulator through */
153 osmv_ibms_transport_mgr_t *p_mgr =
154 malloc(sizeof(osmv_ibms_transport_mgr_t));
160 return IB_INSUFFICIENT_MEMORY;
163 memset(p_mgr, 0, sizeof(osmv_ibms_transport_mgr_t));
165 /* create the client socket connected to the simulator */
166 /* also perform the "connect" message - such that we
167 validate the target guid */
168 if (osm_vendor_get_guid_by_ca_and_port
169 (p_bo->p_vendor, hca_id, p_bo->port_num, &port_guid)) {
170 return IB_INVALID_GUID;
174 ibms_connect(port_guid, __osmv_ibms_receiver_callback,
177 printf("fail to connect to the server.\n");
182 * Create the MAD filter on this file handle.
185 p_mgr->filter.port = p_bo->port_num;
186 p_mgr->filter.only_input = 1;
188 IBMS_BIND_MASK_PORT |
189 IBMS_BIND_MASK_INPUT | IBMS_BIND_MASK_QP | IBMS_BIND_MASK_CLASS;
191 switch (p_info->mad_class) {
192 case IB_MCLASS_SUBN_LID:
193 case IB_MCLASS_SUBN_DIR:
195 p_mgr->filter.qpn = qpn;
196 p_mgr->filter.mgt_class = IB_MCLASS_SUBN_LID;
197 ibms_status = ibms_bind(conHdl, &p_mgr->filter);
202 p_mgr->filter.mgt_class = IB_MCLASS_SUBN_DIR;
203 ibms_status = ibms_bind(conHdl, &p_mgr->filter);
210 case IB_MCLASS_SUBN_ADM:
213 p_mgr->filter.qpn = qpn;
214 p_mgr->filter.mgt_class = p_info->mad_class;
215 ibms_status = ibms_bind(conHdl, &p_mgr->filter);
222 p_mgr->conHdl = conHdl;
224 p_bo->p_transp_mgr = p_mgr;
226 /* Initialize the magic_ptr to the pointer of the p_bo info.
227 This will be used to signal when the object is being destroyed, so no
228 real action will be done then. */
229 p_bo->magic_ptr = p_bo;
236 * osmv_transport_send_mad
239 * Send a single MAD (256 byte)
243 osmv_transport_mad_send(IN const osm_bind_handle_t h_bind,
244 IN void *p_mad, IN const osm_mad_addr_t * p_mad_addr)
247 osmv_bind_obj_t *p_bo = (osmv_bind_obj_t *) h_bind;
248 osm_vendor_t const *p_vend = p_bo->p_vendor;
250 ibms_mad_msg_t mad_msg;
251 ib_api_status_t status;
253 const ib_mad_t *p_mad_hdr = p_mad;
255 OSM_LOG_ENTER(p_vend->p_log);
257 memset(&mad_msg, 0, sizeof(mad_msg));
259 /* Make sure the p_bo object is still relevant */
260 if ((p_bo->magic_ptr != p_bo) || p_bo->is_closing)
261 return IB_INVALID_CALLBACK;
264 * Copy the MAD over to the sent mad
266 memcpy(&mad_msg.header, p_mad_hdr, MAD_BLOCK_SIZE);
269 * For all sends other than directed route SM MADs,
270 * acquire an address vector for the destination.
272 if (p_mad_hdr->mgmt_class != IB_MCLASS_SUBN_DIR) {
274 __osmv_ibms_osm_addr_to_mad_addr(p_mad_addr,
275 p_mad_hdr->mgmt_class ==
279 /* is a directed route - we need to construct a permissive address */
280 /* we do not need port number since it is part of the mad_hndl */
281 mad_msg.addr.dlid = IB_LID_PERMISSIVE;
282 mad_msg.addr.slid = IB_LID_PERMISSIVE;
283 mad_msg.addr.sqpn = 0;
284 mad_msg.addr.dqpn = 0;
287 osm_log(p_bo->p_vendor->p_log, OSM_LOG_DEBUG,
288 "osmv_transport_mad_send: "
289 "Sending QPN:%d DLID:0x%04x class:0x%02x "
290 "method:0x%02x attr:0x%04x status:0x%04x "
291 "tid:0x%016" PRIx64 "\n",
293 cl_ntoh16(mad_msg.addr.dlid),
294 mad_msg.header.mgmt_class,
295 mad_msg.header.method,
296 cl_ntoh16(mad_msg.header.attr_id),
297 cl_ntoh16(mad_msg.header.status),
298 cl_ntoh64(mad_msg.header.trans_id)
303 ibms_send(((osmv_ibms_transport_mgr_t *) (p_bo->p_transp_mgr))->
306 osm_log(p_vend->p_log, OSM_LOG_ERROR,
307 "osmv_transport_mad_send: ERR 5304: "
308 "Error sending mad (%d).\n", ret);
316 OSM_LOG_EXIT(p_vend->p_log);
320 void osmv_transport_done(IN const osm_bind_handle_t h_bind)
322 osmv_bind_obj_t *p_bo = (osmv_bind_obj_t *) h_bind;
323 osmv_ibms_transport_mgr_t *p_tpot_mgr =
324 (osmv_ibms_transport_mgr_t *) (p_bo->p_transp_mgr);
328 /* First of all - zero out the magic_ptr, so if a callback is called -
329 it'll know that we are currently closing down, and will not handle the
332 /* usleep(3000000); */
334 ibms_disconnect(p_tpot_mgr->conHdl);
336 /* seems the only way to abort a blocking read is to make it read something */
341 __osmv_ibms_osm_addr_to_mad_addr(IN const osm_mad_addr_t * p_osm_addr,
343 OUT struct _ibms_mad_addr *p_ibms_addr)
346 /* For global destination or Multicast address: */
347 p_ibms_addr->dlid = cl_ntoh16(p_osm_addr->dest_lid);
348 p_ibms_addr->sl = p_osm_addr->addr_type.gsi.service_level;
350 p_ibms_addr->sqpn = 0;
351 p_ibms_addr->dqpn = 0;
353 p_ibms_addr->sqpn = 1;
355 cl_ntoh32(p_osm_addr->addr_type.gsi.remote_qp);
358 HACK we limit to the first PKey Index assuming it will
359 always be the default PKey
361 p_ibms_addr->pkey_index = 0;
365 __osmv_ibms_mad_addr_to_osm_addr(IN osm_vendor_t const *p_vend,
366 IN struct _ibms_mad_addr *p_ibms_addr,
368 OUT osm_mad_addr_t * p_osm_addr)
370 memset(p_osm_addr, 0, sizeof(osm_mad_addr_t));
371 p_osm_addr->dest_lid = cl_hton16(p_ibms_addr->slid);
372 p_osm_addr->static_rate = 0;
373 p_osm_addr->path_bits = 0;
376 p_osm_addr->addr_type.smi.source_lid =
377 cl_hton16(p_ibms_addr->slid);
378 p_osm_addr->addr_type.smi.port_num = 1; /* TODO add if required p_ibms_addr->port; */
381 p_osm_addr->addr_type.gsi.remote_qp =
382 cl_ntoh32(p_ibms_addr->sqpn);
383 p_osm_addr->addr_type.gsi.remote_qkey = IB_QP1_WELL_KNOWN_Q_KEY;
384 p_osm_addr->addr_type.gsi.pkey_ix = p_ibms_addr->pkey_index;
385 p_osm_addr->addr_type.gsi.service_level = p_ibms_addr->sl;
387 p_osm_addr->addr_type.gsi.global_route = FALSE;
388 /* copy the GRH data if relevant - TopSpin imp doesnt relate to GRH!!! */
390 if (p_osm_addr->addr_type.gsi.global_route)
392 p_osm_addr->addr_type.gsi.grh_info.ver_class_flow =
393 ib_grh_set_ver_class_flow(p_rcv_desc->grh.IP_version,
394 p_rcv_desc->grh.traffic_class,
395 p_rcv_desc->grh.flow_label);
396 p_osm_addr->addr_type.gsi.grh_info.hop_limit = p_rcv_desc->grh.hop_limit;
397 memcpy(&p_osm_addr->addr_type.gsi.grh_info.src_gid.raw,
398 &p_rcv_desc->grh.sgid, sizeof(ib_net64_t));
399 memcpy(&p_osm_addr->addr_type.gsi.grh_info.dest_gid.raw,
400 p_rcv_desc->grh.dgid, sizeof(ib_net64_t));
407 * NAME osm_vendor_set_sm
409 * DESCRIPTION Modifies the port info for the bound port to set the "IS_SM" bit
410 * according to the value given (TRUE or FALSE).
413 void osm_vendor_set_sm(IN osm_bind_handle_t h_bind, IN boolean_t is_sm_val)
415 osmv_bind_obj_t *p_bo = (osmv_bind_obj_t *) h_bind;
416 osm_vendor_t const *p_vend = p_bo->p_vendor;
418 ibms_cap_msg_t cap_msg;
420 OSM_LOG_ENTER(p_vend->p_log);
422 cap_msg.mask = IB_PORT_CAP_IS_SM;
424 cap_msg.capabilities = IB_PORT_CAP_IS_SM;
426 cap_msg.capabilities = 0;
428 ret = ibms_set_cap(((osmv_ibms_transport_mgr_t *) (p_bo->
433 osm_log(p_vend->p_log, OSM_LOG_ERROR,
434 "osm_vendor_set_sm: ERR 5312: "
435 "Unable set 'IS_SM' bit to:%u in port attributes.\n",
438 OSM_LOG_EXIT(p_vend->p_log);