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
38 * Implementation of osm_req_t.
39 * This object represents the generic attribute requester.
40 * This object is part of the opensm family of objects.
45 Next available error code: 0x300
50 #endif /* HAVE_CONFIG_H */
52 #ifdef OSM_VENDOR_INTF_UMADT
59 #include <complib/cl_qlist.h>
60 #include <complib/cl_thread.h>
61 #include <complib/cl_timer.h>
62 #include <iba/ib_types.h>
63 #include <opensm/osm_madw.h>
64 #include <opensm/osm_log.h>
65 #include <opensm/osm_mad_pool.h>
67 #include <vendor/osm_vendor_umadt.h>
68 #include <vendor/osm_umadt.h>
73 #include "statustext.h"
75 /* //////////////////////////////////////////////////////////////////////// */
76 /* //////////////////////////////////////////////////////////////////////// */
77 /* //////////////////////////////////////////////////////////////////////// */
78 /* //////////////////////////////////////////////////////////////////////// */
79 /* //////////////////////////////////////////////////////////////////////// */
83 /* //////////////////////////////////////////////////////////////////////// */
84 /* //////////////////////////////////////////////////////////////////////// */
85 /* //////////////////////////////////////////////////////////////////////// */
86 /* //////////////////////////////////////////////////////////////////////// */
87 /* //////////////////////////////////////////////////////////////////////// */
89 /* //////////////////// */
91 /* //////////////////// */
92 typedef struct _ib_sa_mad_vM3 {
107 ib_net32_t payload_len;
111 ib_net16_t attr_offset;
114 ib_net64_t comp_mask;
116 uint8_t data[IB_SA_DATA_SIZE];
118 #define DEFAULT_TIMER_INTERVAL_MSEC 500 /* 500msec timer interval */
120 void __mad_recv_processor(void *context);
122 boolean_t __valid_mad_handle(IN mad_bind_info_t * p_mad_bind_info);
125 __match_tid_context(const cl_list_item_t * const p_list_item, void *context);
126 void __osm_vendor_timer_callback(IN void *context);
128 osm_vendor_t *osm_vendor_new(IN osm_log_t * const p_log,
129 IN const uint32_t timeout)
131 ib_api_status_t status;
132 umadt_obj_t *p_umadt_obj;
134 OSM_LOG_ENTER(p_log);
136 p_umadt_obj = malloc(sizeof(umadt_obj_t));
138 memset(p_umadt_obj, 0, sizeof(umadt_obj_t));
140 status = osm_vendor_init((osm_vendor_t *) p_umadt_obj, p_log,
142 if (status != IB_SUCCESS) {
143 osm_vendor_delete((osm_vendor_t **) & p_umadt_obj);
147 ("osm_vendor_construct: ERROR! Unable to create Umadt object!\n");
152 return ((osm_vendor_t *) p_umadt_obj);
155 void osm_vendor_delete(IN osm_vendor_t ** const pp_vend)
157 umadt_obj_t *p_umadt_obj = (umadt_obj_t *) * pp_vend;
158 cl_list_item_t *p_list_item;
160 mad_bind_info_t *p_mad_bind_info;
162 OSM_LOG_ENTER(p_umadt_obj->p_log);
164 cl_spinlock_acquire(&p_umadt_obj->register_lock);
166 (mad_bind_info_t *) cl_qlist_head(&p_umadt_obj->register_list);
167 count = cl_qlist_count(&p_umadt_obj->register_list);
168 cl_spinlock_release(&p_umadt_obj->register_lock);
169 for (i = 0; i < count; i++) {
170 cl_spinlock_acquire(&p_umadt_obj->register_lock);
171 p_list_item = cl_qlist_next(&p_mad_bind_info->list_item);
172 cl_spinlock_release(&p_umadt_obj->register_lock);
173 /* Unbind this handle */
174 /* osm_vendor_ubind also removesd the item from the list */
175 /* osm_vendor_unbind takes the list lock so release it here */
176 osm_vendor_unbind((osm_bind_handle_t) p_mad_bind_info);
177 p_mad_bind_info = (mad_bind_info_t *) p_list_item;
179 dlclose(p_umadt_obj->umadt_handle);
183 OSM_LOG_EXIT(p_umadt_obj->p_log);
186 /* //////////////////////////////////////////////////////////////////////// */
187 /* See VendorAbstractMadIntf.h for info */
188 /* //////////////////////////////////////////////////////////////////////// */
191 osm_vendor_init(IN osm_vendor_t * const p_vend,
192 IN osm_log_t * const p_log, IN const uint32_t timeout)
195 PUMADT_GET_INTERFACE uMadtGetInterface;
197 umadt_obj_t *p_umadt_obj = (umadt_obj_t *) p_vend;
199 OSM_LOG_ENTER(p_log);
201 p_umadt_obj->p_log = p_log;
202 p_umadt_obj->timeout = timeout;
204 p_umadt_obj->umadt_handle = dlopen("libibt.so", RTLD_NOW);
206 if (!p_umadt_obj->umadt_handle) {
207 printf("Could not load libibt.so <%s>\n", dlerror());
211 dlsym(p_umadt_obj->umadt_handle, "uMadtGetInterface");
212 if ((error = dlerror()) != NULL) {
213 printf("Could not resolve symbol uMadtGetInterface ERROR<%s>\n",
218 Status = (*uMadtGetInterface) (&p_umadt_obj->uMadtInterface);
219 if (Status != FSUCCESS) {
220 printf(" Error in getting uMADT interface ERROR<%d>\n", Status);
224 /* Initialize the register list and register list lock */
225 cl_qlist_init(&p_umadt_obj->register_list);
227 cl_spinlock_construct(&p_umadt_obj->register_lock);
228 CL_ASSERT(cl_spinlock_init(&p_umadt_obj->register_lock) == CL_SUCCESS);
229 p_umadt_obj->init_done = TRUE;
230 printf("*****SUCCESS*****\n");
237 /* //////////////////////////////////////////////////////////////////////// */
238 /* See VendorAbstractMadIntf.h for info */
239 /* //////////////////////////////////////////////////////////////////////// */
241 osm_vendor_get_ports(IN osm_vendor_t * const p_vend,
242 IN ib_net64_t * const p_guids,
243 IN uint32_t * const p_num_guids)
246 PIBT_GET_INTERFACE pfnIbtGetInterface;
247 PIBT_INIT pfnIbtInitFunc;
250 uint32_t caCount, caGuidCount;
251 IB_CA_ATTRIBUTES caAttributes;
254 IB_PORT_ATTRIBUTES *pPortAttributesList;
255 EUI64 CaGuidArray[8];
257 uint64_t *p_port_guid;
260 umadt_obj_t *p_umadt_obj = (umadt_obj_t *) p_vend;
262 OSM_LOG_ENTER(p_umadt_obj->p_log);
265 CL_ASSERT(p_num_guids);
268 (PIBT_INIT) dlsym(p_umadt_obj->umadt_handle, "IbtInit");
270 if (!pfnIbtInitFunc) {
271 printf("Error getting IbtInit function address.\n");
275 (*pfnIbtInitFunc) ();
278 (PIBT_GET_INTERFACE) dlsym(p_umadt_obj->umadt_handle,
281 if (!pfnIbtGetInterface || (error = dlerror()) != NULL) {
282 printf("Error getting IbtGetInterface function address.<%s>\n",
286 (*pfnIbtGetInterface) (&p_umadt_obj->IbtInterface);
290 p_umadt_obj->IbtInterface.GetCaGuidArray(&caGuidCount,
293 if ((Status != FSUCCESS) || (caGuidCount == 0)) {
297 free_guids = *p_num_guids;
298 p_port_guid = p_guids;
300 /* query each ca & copy its info into callers buffer */
301 for (caCount = 0; caCount < caGuidCount; caCount++) {
302 memset(&caAttributes, 0, sizeof(IB_CA_ATTRIBUTES));
305 Status = p_umadt_obj->IbtInterface.Vpi.OpenCA(CaGuidArray[caCount], NULL, /* CACompletionCallback */
306 NULL, /* AsyncEventCallback */
308 if (Status != FSUCCESS) {
312 Status = p_umadt_obj->IbtInterface.Vpi.QueryCA(caHandle,
316 if (Status != FSUCCESS) {
317 p_umadt_obj->IbtInterface.Vpi.CloseCA(caHandle);
321 if (caAttributes.Ports > free_guids) {
323 memset(p_guids, 0, (*p_num_guids) * sizeof(uint64_t));
324 return IB_INSUFFICIENT_MEMORY;
327 pPortAttributesList =
328 (IB_PORT_ATTRIBUTES *) malloc(caAttributes.
329 PortAttributesListSize);
331 if (pPortAttributesList == NULL) {
332 p_umadt_obj->IbtInterface.Vpi.CloseCA(caHandle);
334 memset(p_guids, 0, (*p_num_guids) * sizeof(uint64_t));
335 return IB_INSUFFICIENT_MEMORY;
338 memset(pPortAttributesList, 0,
339 caAttributes.PortAttributesListSize);
341 caAttributes.PortAttributesList = pPortAttributesList;
343 Status = p_umadt_obj->IbtInterface.Vpi.QueryCA(caHandle,
347 if (Status != FSUCCESS) {
348 p_umadt_obj->IbtInterface.Vpi.CloseCA(caHandle);
350 memset(p_guids, 0, (*p_num_guids) * sizeof(uint64_t));
354 pPortAttributesList = caAttributes.PortAttributesList;
356 for (i = 0; i < caAttributes.Ports; i++) {
358 cl_hton64((uint64_t) pPortAttributesList->GUID);
359 pPortAttributesList = pPortAttributesList->Next;
362 free(caAttributes.PortAttributesList);
363 p_umadt_obj->IbtInterface.Vpi.CloseCA(caHandle);
365 free_guids = free_guids - caAttributes.Ports;
368 *p_num_guids = *p_num_guids - free_guids;
372 /* //////////////////////////////////////////////////////////////////////// */
373 /* See VendorAbstractMadIntf.h for info */
374 /* //////////////////////////////////////////////////////////////////////// */
375 ib_mad_t *osm_vendor_get(IN osm_bind_handle_t h_bind,
376 IN const uint32_t mad_size,
377 IN osm_vend_wrap_t * p_vend_wrap)
379 /* FSTATUS Status; */
380 /* uint32_t mad_count = 0; */
381 /* MadtStruct *p_madt_struct; */
382 mad_bind_info_t *p_mad_bind_info = (mad_bind_info_t *) h_bind;
383 umadt_obj_t *p_umadt_obj = p_mad_bind_info->p_umadt_obj;
385 OSM_LOG_ENTER(p_umadt_obj->p_log);
389 p_umadt_obj = p_mad_bind_info->p_umadt_obj;
392 CL_ASSERT(p_umadt_obj->init_done);
393 CL_ASSERT(p_vend_wrap);
394 CL_ASSERT(__valid_mad_handle(p_mad_bind_info));
399 p_umadt_obj->uMadtInterface.uMadtGetSendMad(p_mad_bind_info->
404 if (Status != FSUCCESS || p_madt_struct == NULL) {
405 p_vend_wrap->p_madt_struct = NULL;
408 p_vend_wrap->p_madt_struct = p_madt_struct;
409 p_vend_wrap->direction = SEND;
410 return ((ib_mad_t *) & p_madt_struct->IBMad);
412 p_mad = (ib_mad_t *) malloc(mad_size);
414 p_vend_wrap->p_madt_struct = NULL;
418 memset(p_mad, 0, mad_size);
420 p_vend_wrap->p_madt_struct = NULL;
421 p_vend_wrap->direction = SEND;
422 p_vend_wrap->size = mad_size;
427 /* //////////////////////////////////////////////////////////////////////// */
428 /* See VendorAbstractMadIntf.h for info */
429 /* //////////////////////////////////////////////////////////////////////// */
431 osm_vendor_put(IN osm_bind_handle_t h_bind,
432 IN osm_vend_wrap_t * const p_vend_wrap,
433 IN ib_mad_t * const p_mad)
438 mad_bind_info_t *p_mad_bind_info;
439 umadt_obj_t *p_umadt_obj;
442 /* Validate the vendor mad transport handle */
445 p_mad_bind_info = (mad_bind_info_t *) h_bind;
446 p_umadt_obj = p_mad_bind_info->p_umadt_obj;
449 CL_ASSERT(p_umadt_obj->init_done);
451 CL_ASSERT(__valid_mad_handle(p_mad_bind_info));
452 CL_ASSERT(p_vend_wrap);
453 /* CL_ASSERT( (ib_mad_t*)&p_vend_wrap->p_madt_struct->IBMad == p_mad ); */
455 /* Release the MAD based on the direction of the MAD */
456 if (p_vend_wrap->direction == SEND) {
458 /* For a send the PostSend released the MAD with Umadt. Simply dealloacte the */
459 /* local memory that was allocated on the osm_vendor_get() call. */
464 p_umadt_obj->uMadtInterface.
465 uMadtReleaseSendMad(p_mad_bind_info->umadt_handle,
466 p_vend_wrap->p_madt_struct);
467 if (Status != FSUCCESS) {
468 /* printf("uMadtReleaseSendMad: Status = <%d>\n", Status); */
472 } else if (p_vend_wrap->direction == RECEIVE) {
473 CL_ASSERT((ib_mad_t *) & p_vend_wrap->p_madt_struct->IBMad ==
476 p_umadt_obj->uMadtInterface.
477 uMadtReleaseRecvMad(p_mad_bind_info->umadt_handle,
478 p_vend_wrap->p_madt_struct);
479 if (Status != FSUCCESS) {
480 /* printf("uMadtReleaseRecvMad Status=<%d>\n", Status); */
489 /* //////////////////////////////////////////////////////////////////////// */
490 /* See VendorAbstractMadIntf.h for info */
491 /* //////////////////////////////////////////////////////////////////////// */
493 osm_vendor_send(IN osm_bind_handle_t h_bind,
494 IN osm_vend_wrap_t * const p_vend_wrap,
495 IN osm_mad_addr_t * const p_mad_addr,
496 IN ib_mad_t * const p_mad,
497 IN void *transaction_context, IN boolean_t const resp_expected)
501 MadAddrStruct destAddr = { 0 };
503 mad_bind_info_t *p_mad_bind_info;
504 trans_context_t *p_trans_context;
506 umadt_obj_t *p_umadt_obj = NULL;
508 uint32_t mad_count = 0;
509 MadtStruct *p_madt_struct = NULL;
511 uint32_t num_mads = 0;
512 uint32_t seg_num = 0;
513 uint8_t *p_frag_data = NULL;
514 ib_sa_mad_t_vM3 *p_sa_mad = NULL;
517 p_mad_bind_info = (mad_bind_info_t *) h_bind;
518 p_umadt_obj = p_mad_bind_info->p_umadt_obj;
521 CL_ASSERT(p_umadt_obj);
522 CL_ASSERT(p_umadt_obj->init_done);
523 CL_ASSERT(__valid_mad_handle(p_mad_bind_info));
524 CL_ASSERT(p_vend_wrap);
525 CL_ASSERT(p_mad_addr);
527 /* CL_ASSERT( (ib_mad_t*)&p_vend_wrap->p_madt_struct->IBMad == p_mad ); */
530 /* based on the class, fill out the address info */
532 destAddr.DestLid = p_mad_addr->dest_lid;
533 destAddr.PathBits = p_mad_addr->path_bits;
534 destAddr.StaticRate = p_mad_addr->static_rate;
536 if (p_mad_bind_info->umadt_reg_class.ClassId == IB_MCLASS_SUBN_LID ||
537 p_mad_bind_info->umadt_reg_class.ClassId == IB_MCLASS_SUBN_DIR) {
538 CL_ASSERT(p_mad_addr->addr_type.smi.source_lid);
539 destAddr.AddrType.Smi.SourceLid =
540 p_mad_addr->addr_type.smi.source_lid;
542 destAddr.AddrType.Gsi.RemoteQpNumber =
543 p_mad_addr->addr_type.gsi.remote_qp;
544 destAddr.AddrType.Gsi.RemoteQkey =
545 p_mad_addr->addr_type.gsi.remote_qkey;
546 destAddr.AddrType.Gsi.PKey = OSM_DEFAULT_PKEY;
547 destAddr.AddrType.Gsi.ServiceLevel =
548 p_mad_addr->addr_type.gsi.service_level;
549 destAddr.AddrType.Gsi.GlobalRoute =
550 p_mad_addr->addr_type.gsi.global_route;
551 /* destAddr.AddrType.Gsi.GRHInfo = p_mad_addr->addr_type.gsi.grh_info; */
553 p_mad->trans_id = cl_ntoh64(p_mad->trans_id) << 24;
556 /* Create a transaction context for this send and save the TID and client context. */
560 p_trans_context = malloc(sizeof(trans_context_t));
561 CL_ASSERT(p_trans_context);
563 memset(p_trans_context, 0, sizeof(trans_context_t));
564 p_trans_context->trans_id = p_mad->trans_id;
565 p_trans_context->context = transaction_context;
566 p_trans_context->sent_time = cl_get_time_stamp();
568 cl_spinlock_acquire(&p_mad_bind_info->trans_ctxt_lock);
569 cl_qlist_insert_tail(&p_mad_bind_info->trans_ctxt_list,
570 &p_trans_context->list_item);
571 cl_spinlock_release(&p_mad_bind_info->trans_ctxt_lock);
574 if (p_mad_bind_info->umadt_reg_class.ClassId == IB_MCLASS_SUBN_LID ||
575 p_mad_bind_info->umadt_reg_class.ClassId == IB_MCLASS_SUBN_DIR) {
576 /* Get one mad from uMadt */
579 p_umadt_obj->uMadtInterface.
580 uMadtGetSendMad(p_mad_bind_info->umadt_handle, &mad_count,
583 if (Status != FSUCCESS || p_madt_struct == NULL) {
587 /* No Segmentation required */
588 memcpy(&p_madt_struct->IBMad, p_mad, MAD_BLOCK_SIZE);
593 p_umadt_obj->uMadtInterface.uMadtPostSend(p_mad_bind_info->
597 if (Status != FSUCCESS) {
598 printf("uMadtPostSendMad: Status = <%d>\n", Status);
602 /* Release send MAD */
604 p_umadt_obj->uMadtInterface.
605 uMadtReleaseSendMad(p_mad_bind_info->umadt_handle,
607 if (Status != FSUCCESS) {
608 printf("uMadtReleaseSendMad: Status = <%d>\n", Status);
614 /* Segment the MAD, get the required send mads from uMadt and post the MADs. */
616 uint32_t payload_len;
619 cl_ntoh32(((ib_sa_mad_t_vM3 *) p_mad)->payload_len);
620 num_mads = payload_len / IB_SA_DATA_SIZE;
621 if (payload_len % IB_SA_DATA_SIZE != 0) {
622 num_mads++; /* Get one additional mad for the remainder */
624 for (i = 0; i < num_mads; i++) {
625 /* Get one mad from uMadt */
628 p_umadt_obj->uMadtInterface.
629 uMadtGetSendMad(p_mad_bind_info->umadt_handle,
630 &mad_count, &p_madt_struct);
632 if (Status != FSUCCESS || p_madt_struct == NULL) {
635 /* Copy client MAD into uMadt's MAD. */
636 if (i == 0) { /* First Packet */
637 /* Since this is the first MAD, copy the entire MAD_SIZE */
638 memcpy(&p_madt_struct->IBMad, p_mad,
642 (uint8_t *) p_mad + MAD_BLOCK_SIZE;
645 (ib_sa_mad_t_vM3 *) & p_madt_struct->IBMad;
646 if (num_mads == 1) { /* Only one Packet */
647 p_sa_mad->seg_num = 0;
648 p_sa_mad->frag_flag = 5; /* Set bit 0 for first pkt and b4 for last pkt */
649 /* the payload length gets copied with the mad header above */
650 } else { /* More than one packet in this response */
654 cl_ntoh32(seg_num++);
655 p_sa_mad->frag_flag = 1; /* Set bit 0 for first pkt */
656 /* the payload length gets copied with the mad header above */
659 } else if (i < num_mads - 1) { /* Not last packet */
660 /* First copy only the header */
661 memcpy(&p_madt_struct->IBMad, p_mad,
663 /* Set the relevant fields in the SA_MAD_HEADER */
665 (ib_sa_mad_t_vM3 *) & p_madt_struct->IBMad;
666 p_sa_mad->payload_len =
667 cl_ntoh32(IB_SA_DATA_SIZE);
668 p_sa_mad->seg_num = cl_ntoh32(seg_num++);
669 p_sa_mad->frag_flag = 0;
670 /* Now copy the fragmented data */
671 memcpy(((uint8_t *) & p_madt_struct->IBMad) +
672 IB_SA_MAD_HDR_SIZE, p_frag_data,
674 p_frag_data = p_frag_data + IB_SA_DATA_SIZE;
676 } else if (i == num_mads - 1) { /* Last packet */
677 /* First copy only the header */
678 memcpy(&p_madt_struct->IBMad, p_mad,
680 /* Set the relevant fields in the SA_MAD_HEADER */
682 (ib_sa_mad_t_vM3 *) & p_madt_struct->IBMad;
683 p_sa_mad->seg_num = cl_ntoh32(seg_num++);
684 p_sa_mad->frag_flag = 4; /* Set Bit 2 for last pkt */
685 p_sa_mad->payload_len =
687 (((ib_sa_mad_t_vM3 *) p_mad)->
688 payload_len) % IB_SA_DATA_SIZE);
689 /* Now copy the fragmented data */
690 memcpy((((uint8_t *) & p_madt_struct->IBMad)) +
691 IB_SA_MAD_HDR_SIZE, p_frag_data,
692 cl_ntoh32(p_sa_mad->payload_len));
693 p_frag_data = p_frag_data + IB_SA_DATA_SIZE;
698 p_umadt_obj->uMadtInterface.
699 uMadtPostSend(p_mad_bind_info->umadt_handle,
700 p_madt_struct, &destAddr);
701 if (Status != FSUCCESS) {
702 printf("uMadtPostSendMad: Status = <%d>\n",
707 /* Release send MAD */
709 p_umadt_obj->uMadtInterface.
710 uMadtReleaseSendMad(p_mad_bind_info->umadt_handle,
712 if (Status != FSUCCESS) {
713 printf("uMadtReleaseSendMad: Status = <%d>\n",
722 /* //////////////////////////////////////////////////////////////////////// */
723 /* See VendorAbstractMadIntf.h for info */
724 /* //////////////////////////////////////////////////////////////////////// */
727 osm_vendor_bind(IN osm_vendor_t * const p_vend,
728 IN osm_bind_info_t * const p_osm_bind_info,
729 IN osm_mad_pool_t * const p_mad_pool,
730 IN osm_vend_mad_recv_callback_t mad_recv_callback,
733 cl_status_t cl_status;
734 FSTATUS Status; /* GEN1 Status for Umadt */
736 mad_bind_info_t *p_mad_bind_info;
737 RegisterClassStruct *p_umadt_reg_class;
739 umadt_obj_t *p_umadt_obj;
740 OSM_LOG_ENTER(((umadt_obj_t *) p_vend)->p_log);
744 p_umadt_obj = (umadt_obj_t *) p_vend;
747 CL_ASSERT(p_umadt_obj->init_done);
748 CL_ASSERT(p_osm_bind_info);
749 CL_ASSERT(p_mad_pool);
750 CL_ASSERT(mad_recv_callback);
752 /* Allocate memory for registering the handle. */
753 p_mad_bind_info = (mad_bind_info_t *) malloc(sizeof(*p_mad_bind_info));
754 if (p_mad_bind_info) {
755 memset(p_mad_bind_info, 0, sizeof(*p_mad_bind_info));
756 p_umadt_reg_class = &p_mad_bind_info->umadt_reg_class;
758 p_umadt_reg_class->PortGuid = cl_ntoh64(p_osm_bind_info->port_guid);
759 p_umadt_reg_class->ClassId = p_osm_bind_info->mad_class;
760 p_umadt_reg_class->ClassVersion = p_osm_bind_info->class_version;
761 p_umadt_reg_class->isResponder = p_osm_bind_info->is_responder;
762 p_umadt_reg_class->isTrapProcessor = p_osm_bind_info->is_trap_processor;
763 p_umadt_reg_class->isReportProcessor =
764 p_osm_bind_info->is_report_processor;
765 p_umadt_reg_class->SendQueueSize = p_osm_bind_info->send_q_size;
766 p_umadt_reg_class->RecvQueueSize = p_osm_bind_info->recv_q_size;
767 p_umadt_reg_class->NotifySendCompletion = TRUE;
769 p_mad_bind_info->p_umadt_obj = p_umadt_obj;
770 p_mad_bind_info->p_mad_pool = p_mad_pool;
771 p_mad_bind_info->mad_recv_callback = mad_recv_callback;
772 p_mad_bind_info->client_context = context;
774 /* register with Umadt for MAD interface */
775 Status = p_umadt_obj->uMadtInterface.uMadtRegister(p_umadt_reg_class,
778 if (Status != FSUCCESS) {
779 free(p_mad_bind_info);
780 OSM_LOG_EXIT(p_umadt_obj->p_log);
781 return (OSM_BIND_INVALID_HANDLE);
783 CL_ASSERT(p_mad_bind_info->umadt_handle);
785 /* Start a worker thread to process receives. */
787 cl_thread_construct(&p_mad_bind_info->recv_processor_thread);
788 cl_status = cl_thread_init(&p_mad_bind_info->recv_processor_thread,
789 __mad_recv_processor,
790 (void *)p_mad_bind_info, "mad_recv_worker");
791 CL_ASSERT(cl_status == CL_SUCCESS);
793 cl_qlist_init(&p_mad_bind_info->trans_ctxt_list);
794 cl_spinlock_construct(&p_mad_bind_info->trans_ctxt_lock);
795 cl_spinlock_init(&p_mad_bind_info->trans_ctxt_lock);
796 cl_spinlock_construct(&p_mad_bind_info->timeout_list_lock);
797 cl_spinlock_init(&p_mad_bind_info->timeout_list_lock);
799 cl_status = cl_timer_init(&p_mad_bind_info->timeout_timer,
800 __osm_vendor_timer_callback,
801 (void *)p_mad_bind_info);
802 CL_ASSERT(cl_status == CL_SUCCESS);
803 cl_qlist_init(&p_mad_bind_info->timeout_list);
805 /* Insert the mad_reg_struct in list and return pointer to it as the handle */
807 cl_spinlock_acquire(&p_umadt_obj->register_lock);
809 cl_qlist_insert_head(&p_umadt_obj->register_list,
810 &p_mad_bind_info->list_item);
812 cl_spinlock_release(&p_umadt_obj->register_lock);
815 A timeout value of 0 means disable timeouts.
817 if (p_umadt_obj->timeout) {
818 cl_timer_start(&p_mad_bind_info->timeout_timer,
819 DEFAULT_TIMER_INTERVAL_MSEC);
822 OSM_LOG_EXIT(p_umadt_obj->p_log);
823 return ((osm_bind_handle_t) p_mad_bind_info);
826 /**********************************************************************
827 **********************************************************************/
828 void osm_vendor_unbind(IN osm_bind_handle_t h_bind)
830 mad_bind_info_t *p_mad_bind_info;
831 umadt_obj_t *p_umadt_obj;
832 cl_list_item_t *p_list_item, *p_next_list_item;
835 p_mad_bind_info = (mad_bind_info_t *) h_bind;
836 p_umadt_obj = p_mad_bind_info->p_umadt_obj;
839 CL_ASSERT(p_umadt_obj);
840 CL_ASSERT(p_umadt_obj->init_done);
841 CL_ASSERT(__valid_mad_handle(p_mad_bind_info));
843 p_umadt_obj->uMadtInterface.uMadtDestroy(&p_mad_bind_info->
845 cl_timer_destroy(&p_mad_bind_info->timeout_timer);
846 cl_thread_destroy(&p_mad_bind_info->recv_processor_thread);
848 cl_spinlock_acquire(&p_mad_bind_info->trans_ctxt_lock);
849 p_list_item = cl_qlist_head(&p_mad_bind_info->trans_ctxt_list);
850 while (p_list_item != cl_qlist_end(&p_mad_bind_info->trans_ctxt_list)) {
851 p_next_list_item = cl_qlist_next(p_list_item);
852 cl_qlist_remove_item(&p_mad_bind_info->trans_ctxt_list,
855 p_list_item = p_next_list_item;
857 cl_spinlock_release(&p_mad_bind_info->trans_ctxt_lock);
859 cl_spinlock_acquire(&p_mad_bind_info->timeout_list_lock);
860 p_list_item = cl_qlist_head(&p_mad_bind_info->timeout_list);
861 while (p_list_item != cl_qlist_end(&p_mad_bind_info->timeout_list)) {
862 p_next_list_item = cl_qlist_next(p_list_item);
863 cl_qlist_remove_item(&p_mad_bind_info->timeout_list,
866 p_list_item = p_next_list_item;
868 cl_spinlock_release(&p_mad_bind_info->timeout_list_lock);
870 free(p_mad_bind_info);
873 /**********************************************************************
874 **********************************************************************/
875 void __mad_recv_processor(IN void *context)
877 mad_bind_info_t *p_mad_bind_info = (mad_bind_info_t *) context;
878 umadt_obj_t *p_umadt_obj;
879 osm_madw_t *p_osm_madw = NULL;
880 osm_vend_wrap_t *p_vend_wrap = NULL;
881 osm_mad_addr_t osm_mad_addr = { 0 };
882 cl_list_item_t *p_list_item;
883 void *transaction_context;
886 MadtStruct *pRecvMad = NULL;
887 MadWorkCompletion *pRecvCmp = NULL;
891 p_mad_bind_info = (mad_bind_info_t *) context;
892 p_umadt_obj = p_mad_bind_info->p_umadt_obj;
893 /* PollFor a completion */
894 /* if FNOTFOND, then wait for a completion then again poll and return the MAD */
897 p_umadt_obj->uMadtInterface.
898 uMadtPollForRecvCompletion(p_mad_bind_info->umadt_handle,
899 &pRecvMad, &pRecvCmp);
900 if (Status != FSUCCESS) {
901 if (Status == FNOT_FOUND) {
902 /* Wait for a completion */
903 Status = p_umadt_obj->uMadtInterface.uMadtWaitForAnyCompletion(p_mad_bind_info->umadt_handle, RECV_COMPLETION, 0x5000); /* 5 sec timeout */
905 if (Status == FTIMEOUT) {
908 CL_ASSERT(Status == FSUCCESS);
911 p_umadt_obj->uMadtInterface.
912 uMadtPollForRecvCompletion(p_mad_bind_info->
916 if (Status != FSUCCESS) {
918 (" mad_recv_worker: Error in PollForRecv returning <%x>\n",
924 ("uMadtPollForRecvCompletion Status=<%x>\n",
932 if (((ib_sa_mad_t_vM3 *) (&pRecvMad->IBMad))->frag_flag & 0x20) {
933 /* Ignore the ACK packet */
935 p_umadt_obj->uMadtInterface.
936 uMadtReleaseRecvMad(p_mad_bind_info->umadt_handle,
941 /* Extract the return address to pass it on to the client */
943 osm_mad_addr.dest_lid = pRecvCmp->AddressInfo.DestLid;
944 osm_mad_addr.path_bits = pRecvCmp->AddressInfo.PathBits;
945 osm_mad_addr.static_rate = pRecvCmp->AddressInfo.StaticRate;
947 if (p_mad_bind_info->umadt_reg_class.ClassId ==
949 || p_mad_bind_info->umadt_reg_class.ClassId ==
950 IB_MCLASS_SUBN_DIR) {
951 osm_mad_addr.addr_type.smi.source_lid =
952 pRecvCmp->AddressInfo.AddrType.Smi.SourceLid;
953 /* osm_mad_addr.addr_type.smi.port_num = pRecvCmp->AddressInfo.AddrType.Smi.PortNumber; */
955 osm_mad_addr.addr_type.gsi.remote_qp =
956 pRecvCmp->AddressInfo.AddrType.Gsi.RemoteQpNumber;
957 osm_mad_addr.addr_type.gsi.remote_qkey =
958 pRecvCmp->AddressInfo.AddrType.Gsi.RemoteQkey;
959 osm_mad_addr.addr_type.gsi.pkey_ix = 0;
960 osm_mad_addr.addr_type.gsi.service_level =
961 pRecvCmp->AddressInfo.AddrType.Gsi.ServiceLevel;
962 osm_mad_addr.addr_type.gsi.global_route =
963 pRecvCmp->AddressInfo.AddrType.Gsi.GlobalRoute;
964 /* osm_mad_addr.addr_type.gsi.grh_info = pRecvCmp->AddressInfo.AddrType.Gsi.GRHInfo; */
967 osm_mad_pool_get_wrapper(p_mad_bind_info->p_mad_pool,
968 p_mad_bind_info, MAD_BLOCK_SIZE,
969 (ib_mad_t *) & pRecvMad->IBMad,
971 CL_ASSERT(p_osm_madw);
972 p_vend_wrap = osm_madw_get_vend_ptr(p_osm_madw);
973 CL_ASSERT(p_vend_wrap);
974 p_vend_wrap->p_madt_struct = pRecvMad;
975 p_vend_wrap->direction = RECEIVE;
977 osm_log(p_mad_bind_info->p_umadt_obj->p_log, OSM_LOG_DEBUG,
978 "__mad_recv_processor: "
979 "Received data p_osm_madw[0x%p].\n", p_osm_madw);
982 /* Do TID Processing. */
984 /* If R bit is set swap the TID */
986 cl_spinlock_acquire(&p_mad_bind_info->trans_ctxt_lock);
988 cl_qlist_find_from_head(&p_mad_bind_info->trans_ctxt_list,
990 &p_osm_madw->p_mad->trans_id);
993 cl_qlist_end(&p_mad_bind_info->trans_ctxt_list)) {
994 transaction_context = NULL;
996 transaction_context =
997 ((trans_context_t *) p_list_item)->context;
998 cl_qlist_remove_item(&p_mad_bind_info->trans_ctxt_list,
1002 cl_spinlock_release(&p_mad_bind_info->trans_ctxt_lock);
1003 ((ib_mad_t *) p_osm_madw->p_mad)->trans_id =
1004 cl_ntoh64(p_osm_madw->p_mad->trans_id >> 24);
1005 osm_log(p_mad_bind_info->p_umadt_obj->p_log, OSM_LOG_DEBUG,
1006 "__mad_recv_processor: "
1007 "Received data p_osm_madw [0x%p]" "\n\t\t\t\tTID[0x%"
1008 PRIx64 ", context[%p]. \n", p_osm_madw,
1009 ((ib_mad_t *) p_osm_madw->p_mad)->trans_id,
1010 transaction_context);
1012 (*(p_mad_bind_info->mad_recv_callback)) (p_osm_madw,
1015 transaction_context);
1020 /**********************************************************************
1021 **********************************************************************/
1024 __match_tid_context(const cl_list_item_t * const p_list_item, void *context)
1026 if (((trans_context_t *) p_list_item)->trans_id ==
1027 *((uint64_t *) context))
1029 return CL_NOT_FOUND;
1032 /**********************************************************************
1033 **********************************************************************/
1035 boolean_t __valid_mad_handle(IN mad_bind_info_t * p_mad_bind_info)
1038 umadt_obj_t *p_umadt_obj;
1040 p_umadt_obj = p_mad_bind_info->p_umadt_obj;
1042 cl_spinlock_acquire(&p_umadt_obj->register_lock);
1043 if (!cl_is_item_in_qlist(&p_umadt_obj->register_list,
1044 &p_mad_bind_info->list_item)) {
1045 cl_spinlock_release(&p_umadt_obj->register_lock);
1048 cl_spinlock_release(&p_umadt_obj->register_lock);
1052 void __osm_vendor_timer_callback(IN void *context)
1054 uint64_t current_time;
1055 mad_bind_info_t *p_mad_bind_info;
1056 umadt_obj_t *p_umadt_obj;
1059 cl_list_item_t *p_list_item, *p_next_list_item;
1063 p_mad_bind_info = (mad_bind_info_t *) context;
1064 p_umadt_obj = p_mad_bind_info->p_umadt_obj;
1065 timeout = p_umadt_obj->timeout * 1000;
1067 current_time = cl_get_time_stamp();
1069 cl_spinlock_acquire(&p_mad_bind_info->trans_ctxt_lock);
1071 p_list_item = cl_qlist_head(&p_mad_bind_info->trans_ctxt_list);
1072 while (p_list_item != cl_qlist_end(&p_mad_bind_info->trans_ctxt_list)) {
1074 p_next_list_item = cl_qlist_next(p_list_item);
1076 /* DEFAULT_PKT_TIMEOUT is in milli seconds */
1077 if (current_time - ((trans_context_t *) p_list_item)->sent_time
1079 /* Add this transaction to the timeout_list */
1080 cl_qlist_remove_item(&p_mad_bind_info->trans_ctxt_list,
1082 cl_qlist_insert_tail(&p_mad_bind_info->timeout_list,
1086 p_list_item = p_next_list_item;
1089 cl_spinlock_release(&p_mad_bind_info->trans_ctxt_lock);
1091 p_list_item = cl_qlist_head(&p_mad_bind_info->timeout_list);
1092 while (p_list_item != cl_qlist_end(&p_mad_bind_info->timeout_list)) {
1093 osm_log(p_mad_bind_info->p_umadt_obj->p_log, OSM_LOG_DEBUG,
1094 "__osm_vendor_timer_callback: "
1095 "Timing out transaction context [0x%p].\n",
1096 ((trans_context_t *) p_list_item)->context);
1098 (*(p_mad_bind_info->mad_recv_callback)) (NULL,
1101 ((trans_context_t *)
1105 p_next_list_item = cl_qlist_next(p_list_item);
1106 cl_qlist_remove_item(&p_mad_bind_info->timeout_list,
1109 p_list_item = p_next_list_item;
1112 cl_timer_start(&p_mad_bind_info->timeout_timer,
1113 DEFAULT_TIMER_INTERVAL_MSEC);
1117 #endif /* OSM_VENDOR_INTF_UMADT */