| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561 |
- /*
- * Copyright (c) 2009-2012 Red Hat, Inc.
- *
- * All rights reserved.
- *
- * Author: Steven Dake (sdake@redhat.com)
- * This software licensed under BSD license, the text of which follows:
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- *
- * - Redistributions of source code must retain the above copyright notice,
- * this list of conditions and the following disclaimer.
- * - Redistributions in binary form must reproduce the above copyright notice,
- * this list of conditions and the following disclaimer in the documentation
- * and/or other materials provided with the distribution.
- * - Neither the name of the MontaVista Software, Inc. nor the names of its
- * contributors may be used to endorse or promote products derived from this
- * software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
- * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
- * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
- * THE POSSIBILITY OF SUCH DAMAGE.
- */
- #include <config.h>
- #include <assert.h>
- #include <pthread.h>
- #include <sys/mman.h>
- #include <sys/types.h>
- #include <sys/stat.h>
- #include <sys/socket.h>
- #include <netdb.h>
- #include <sys/un.h>
- #include <sys/ioctl.h>
- #include <sys/param.h>
- #include <netinet/in.h>
- #include <arpa/inet.h>
- #include <unistd.h>
- #include <fcntl.h>
- #include <stdlib.h>
- #include <stdio.h>
- #include <errno.h>
- #include <sched.h>
- #include <time.h>
- #include <sys/time.h>
- #include <sys/poll.h>
- #include <limits.h>
- #include <stdio.h>
- #include <string.h>
- #include <stdlib.h>
- #include <sys/types.h>
- #include <sys/socket.h>
- #include <netdb.h>
- #include <rdma/rdma_cma.h>
- #include <assert.h>
- #include <errno.h>
- #include <corosync/sq.h>
- #include <corosync/list.h>
- #include <corosync/hdb.h>
- #include <corosync/swab.h>
- #include <qb/qbdefs.h>
- #include <qb/qbloop.h>
- #define LOGSYS_UTILS_ONLY 1
- #include <corosync/logsys.h>
- #include "totemiba.h"
- #define COMPLETION_QUEUE_ENTRIES 100
- #define TOTAL_READ_POSTS 100
- #define MAX_MTU_SIZE 4096
- struct totemiba_instance {
- struct sockaddr bind_addr;
- struct sockaddr send_token_bind_addr;
- struct sockaddr mcast_addr;
- struct sockaddr token_addr;
- struct sockaddr local_mcast_bind_addr;
- struct totem_interface *totem_interface;
- struct totem_config *totem_config;
- void (*totemiba_iface_change_fn) (
- void *context,
- const struct totem_ip_address *iface_address);
- void (*totemiba_deliver_fn) (
- void *context,
- const void *msg,
- unsigned int msg_len);
- void (*totemiba_target_set_completed) (
- void *context);
- void *rrp_context;
- qb_loop_timer_handle timer_netif_check_timeout;
- qb_loop_t *totemiba_poll_handle;
- struct totem_ip_address my_id;
- struct rdma_event_channel *mcast_channel;
- struct rdma_cm_id *mcast_cma_id;
- struct ibv_pd *mcast_pd;
- struct sockaddr mcast_dest_addr;
- uint32_t mcast_qpn;
- uint32_t mcast_qkey;
- struct ibv_ah *mcast_ah;
- struct ibv_comp_channel *mcast_send_completion_channel;
- struct ibv_comp_channel *mcast_recv_completion_channel;
- struct ibv_cq *mcast_send_cq;
- struct ibv_cq *mcast_recv_cq;
- int recv_token_accepted;
- struct rdma_event_channel *recv_token_channel;
- struct rdma_event_channel *listen_recv_token_channel;
- struct rdma_cm_id *listen_recv_token_cma_id;
- struct rdma_cm_id *recv_token_cma_id;
- struct ibv_pd *recv_token_pd;
- struct sockaddr recv_token_dest_addr;
- struct ibv_comp_channel *recv_token_send_completion_channel;
- struct ibv_comp_channel *recv_token_recv_completion_channel;
- struct ibv_cq *recv_token_send_cq;
- struct ibv_cq *recv_token_recv_cq;
- int send_token_bound;
- struct rdma_event_channel *send_token_channel;
- struct rdma_cm_id *send_token_cma_id;
- struct ibv_pd *send_token_pd;
- struct sockaddr send_token_dest_addr;
- uint32_t send_token_qpn;
- uint32_t send_token_qkey;
- struct ibv_ah *send_token_ah;
- struct ibv_comp_channel *send_token_send_completion_channel;
- struct ibv_comp_channel *send_token_recv_completion_channel;
- struct ibv_cq *send_token_send_cq;
- struct ibv_cq *send_token_recv_cq;
- void (*totemiba_log_printf) (
- int level,
- int subsys,
- const char *function,
- const char *file,
- int line,
- const char *format,
- ...)__attribute__((format(printf, 6, 7)));
- int totemiba_subsys_id;
- struct list_head mcast_send_buf_free;
- struct list_head token_send_buf_free;
- struct list_head mcast_send_buf_head;
- struct list_head token_send_buf_head;
- struct list_head recv_token_recv_buf_head;
- };
- union u {
- uint64_t wr_id;
- void *v;
- };
- #define log_printf(level, format, args...) \
- do { \
- instance->totemiba_log_printf ( \
- level, \
- instance->totemiba_subsys_id, \
- __FUNCTION__, __FILE__, __LINE__, \
- (const char *)format, ##args); \
- } while (0);
- struct recv_buf {
- struct list_head list_all;
- struct ibv_recv_wr recv_wr;
- struct ibv_sge sge;
- struct ibv_mr *mr;
- char buffer[MAX_MTU_SIZE];
- };
- struct send_buf {
- struct list_head list_free;
- struct list_head list_all;
- struct ibv_mr *mr;
- char buffer[MAX_MTU_SIZE];
- };
- static hdb_handle_t
- void2wrid (void *v) { union u u; u.v = v; return u.wr_id; }
- static void *
- wrid2void (uint64_t wr_id) { union u u; u.wr_id = wr_id; return u.v; }
- static void totemiba_instance_initialize (struct totemiba_instance *instance)
- {
- memset (instance, 0, sizeof (struct totemiba_instance));
- list_init (&instance->mcast_send_buf_free);
- list_init (&instance->token_send_buf_free);
- list_init (&instance->mcast_send_buf_head);
- list_init (&instance->token_send_buf_head);
- list_init (&instance->recv_token_recv_buf_head);
- }
- static inline struct send_buf *mcast_send_buf_get (
- struct totemiba_instance *instance)
- {
- struct send_buf *send_buf;
- if (list_empty (&instance->mcast_send_buf_free) == 0) {
- send_buf = list_entry (instance->mcast_send_buf_free.next, struct send_buf, list_free);
- list_del (&send_buf->list_free);
- return (send_buf);
- }
- send_buf = malloc (sizeof (struct send_buf));
- if (send_buf == NULL) {
- return (NULL);
- }
- send_buf->mr = ibv_reg_mr (instance->mcast_pd,
- send_buf->buffer,
- 2048, IBV_ACCESS_LOCAL_WRITE);
- if (send_buf->mr == NULL) {
- log_printf (LOGSYS_LEVEL_ERROR, "couldn't register memory range");
- free (send_buf);
- return (NULL);
- }
- list_init (&send_buf->list_all);
- list_add_tail (&send_buf->list_all, &instance->mcast_send_buf_head);
-
- return (send_buf);
- }
- static inline void mcast_send_buf_put (
- struct totemiba_instance *instance,
- struct send_buf *send_buf)
- {
- list_init (&send_buf->list_free);
- list_add_tail (&send_buf->list_free, &instance->mcast_send_buf_free);
- }
- static inline struct send_buf *token_send_buf_get (
- struct totemiba_instance *instance)
- {
- struct send_buf *send_buf;
- if (list_empty (&instance->token_send_buf_free) == 0) {
- send_buf = list_entry (instance->token_send_buf_free.next, struct send_buf, list_free);
- list_del (&send_buf->list_free);
- return (send_buf);
- }
- send_buf = malloc (sizeof (struct send_buf));
- if (send_buf == NULL) {
- return (NULL);
- }
- send_buf->mr = ibv_reg_mr (instance->send_token_pd,
- send_buf->buffer,
- 2048, IBV_ACCESS_LOCAL_WRITE);
- if (send_buf->mr == NULL) {
- log_printf (LOGSYS_LEVEL_ERROR, "couldn't register memory range");
- free (send_buf);
- return (NULL);
- }
- list_init (&send_buf->list_all);
- list_add_tail (&send_buf->list_all, &instance->token_send_buf_head);
-
- return (send_buf);
- }
- static inline void token_send_buf_destroy (struct totemiba_instance *instance)
- {
- struct list_head *list;
- struct send_buf *send_buf;
- for (list = instance->token_send_buf_head.next; list != &instance->token_send_buf_head;) {
- send_buf = list_entry (list, struct send_buf, list_all);
- list = list->next;
- ibv_dereg_mr (send_buf->mr);
- free (send_buf);
- }
- list_init (&instance->token_send_buf_free);
- list_init (&instance->token_send_buf_head);
- }
- static inline void token_send_buf_put (
- struct totemiba_instance *instance,
- struct send_buf *send_buf)
- {
- list_init (&send_buf->list_free);
- list_add_tail (&send_buf->list_free, &instance->token_send_buf_free);
- }
- static inline struct recv_buf *recv_token_recv_buf_create (
- struct totemiba_instance *instance)
- {
- struct recv_buf *recv_buf;
- recv_buf = malloc (sizeof (struct recv_buf));
- if (recv_buf == NULL) {
- return (NULL);
- }
- recv_buf->mr = ibv_reg_mr (instance->recv_token_pd, &recv_buf->buffer,
- 2048,
- IBV_ACCESS_LOCAL_WRITE);
- recv_buf->recv_wr.next = NULL;
- recv_buf->recv_wr.sg_list = &recv_buf->sge;
- recv_buf->recv_wr.num_sge = 1;
- recv_buf->recv_wr.wr_id = (uintptr_t)recv_buf;
- recv_buf->sge.length = 2048;
- recv_buf->sge.lkey = recv_buf->mr->lkey;
- recv_buf->sge.addr = (uintptr_t)recv_buf->buffer;
- list_init (&recv_buf->list_all);
- list_add (&recv_buf->list_all, &instance->recv_token_recv_buf_head);
- return (recv_buf);
- }
- static inline int recv_token_recv_buf_post (struct totemiba_instance *instance, struct recv_buf *recv_buf)
- {
- struct ibv_recv_wr *fail_recv;
- int res;
- res = ibv_post_recv (instance->recv_token_cma_id->qp, &recv_buf->recv_wr, &fail_recv);
- return (res);
- }
- static inline void recv_token_recv_buf_post_initial (struct totemiba_instance *instance)
- {
- struct recv_buf *recv_buf;
- unsigned int i;
- for (i = 0; i < TOTAL_READ_POSTS; i++) {
- recv_buf = recv_token_recv_buf_create (instance);
- recv_token_recv_buf_post (instance, recv_buf);
- }
- }
- static inline void recv_token_recv_buf_post_destroy (
- struct totemiba_instance *instance)
- {
- struct recv_buf *recv_buf;
- struct list_head *list;
- for (list = instance->recv_token_recv_buf_head.next;
- list != &instance->recv_token_recv_buf_head;) {
- recv_buf = list_entry (list, struct recv_buf, list_all);
- list = list->next;
- ibv_dereg_mr (recv_buf->mr);
- free (recv_buf);
- }
- list_init (&instance->recv_token_recv_buf_head);
- }
- static inline struct recv_buf *mcast_recv_buf_create (struct totemiba_instance *instance)
- {
- struct recv_buf *recv_buf;
- struct ibv_mr *mr;
- recv_buf = malloc (sizeof (struct recv_buf));
- if (recv_buf == NULL) {
- return (NULL);
- }
- mr = ibv_reg_mr (instance->mcast_pd, &recv_buf->buffer,
- 2048,
- IBV_ACCESS_LOCAL_WRITE);
- recv_buf->recv_wr.next = NULL;
- recv_buf->recv_wr.sg_list = &recv_buf->sge;
- recv_buf->recv_wr.num_sge = 1;
- recv_buf->recv_wr.wr_id = (uintptr_t)recv_buf;
- recv_buf->sge.length = 2048;
- recv_buf->sge.lkey = mr->lkey;
- recv_buf->sge.addr = (uintptr_t)recv_buf->buffer;
- return (recv_buf);
- }
- static inline int mcast_recv_buf_post (struct totemiba_instance *instance, struct recv_buf *recv_buf)
- {
- struct ibv_recv_wr *fail_recv;
- int res;
- res = ibv_post_recv (instance->mcast_cma_id->qp, &recv_buf->recv_wr, &fail_recv);
- return (res);
- }
- static inline void mcast_recv_buf_post_initial (struct totemiba_instance *instance)
- {
- struct recv_buf *recv_buf;
- unsigned int i;
- for (i = 0; i < TOTAL_READ_POSTS; i++) {
- recv_buf = mcast_recv_buf_create (instance);
- mcast_recv_buf_post (instance, recv_buf);
- }
- }
- static inline void iba_deliver_fn (struct totemiba_instance *instance, uint64_t wr_id, uint32_t bytes)
- {
- const char *addr;
- const struct recv_buf *recv_buf;
- recv_buf = wrid2void(wr_id);
- addr = &recv_buf->buffer[sizeof (struct ibv_grh)];
- instance->totemiba_deliver_fn (instance->rrp_context, addr, bytes);
- }
- static int mcast_cq_send_event_fn (int events, int suck, void *context)
- {
- struct totemiba_instance *instance = (struct totemiba_instance *)context;
- struct ibv_wc wc[32];
- struct ibv_cq *ev_cq;
- void *ev_ctx;
- int res;
- int i;
- ibv_get_cq_event (instance->mcast_send_completion_channel, &ev_cq, &ev_ctx);
- ibv_ack_cq_events (ev_cq, 1);
- res = ibv_req_notify_cq (ev_cq, 0);
- res = ibv_poll_cq (instance->mcast_send_cq, 32, wc);
- if (res > 0) {
- for (i = 0; i < res; i++) {
- mcast_send_buf_put (instance, wrid2void(wc[i].wr_id));
- }
- }
- return (0);
- }
- static int mcast_cq_recv_event_fn (int events, int suck, void *context)
- {
- struct totemiba_instance *instance = (struct totemiba_instance *)context;
- struct ibv_wc wc[64];
- struct ibv_cq *ev_cq;
- void *ev_ctx;
- int res;
- int i;
- ibv_get_cq_event (instance->mcast_recv_completion_channel, &ev_cq, &ev_ctx);
- ibv_ack_cq_events (ev_cq, 1);
- res = ibv_req_notify_cq (ev_cq, 0);
- res = ibv_poll_cq (instance->mcast_recv_cq, 64, wc);
- if (res > 0) {
- for (i = 0; i < res; i++) {
- iba_deliver_fn (instance, wc[i].wr_id, wc[i].byte_len);
- mcast_recv_buf_post (instance, wrid2void(wc[i].wr_id));
- }
- }
- return (0);
- }
- static int mcast_rdma_event_fn (int events, int suck, void *context)
- {
- struct totemiba_instance *instance = (struct totemiba_instance *)context;
- struct rdma_cm_event *event;
- int res;
- res = rdma_get_cm_event (instance->mcast_channel, &event);
- if (res != 0) {
- return (0);
- }
- switch (event->event) {
- /*
- * occurs when we resolve the multicast address
- */
- case RDMA_CM_EVENT_ADDR_RESOLVED:
- rdma_join_multicast (instance->mcast_cma_id, &instance->mcast_addr, instance);
- break;
- /*
- * occurs when the CM joins the multicast group
- */
- case RDMA_CM_EVENT_MULTICAST_JOIN:
- instance->mcast_qpn = event->param.ud.qp_num;
- instance->mcast_qkey = event->param.ud.qkey;
- instance->mcast_ah = ibv_create_ah (instance->mcast_pd, &event->param.ud.ah_attr);
- instance->totemiba_iface_change_fn (instance->rrp_context, &instance->my_id);
- break;
- case RDMA_CM_EVENT_ADDR_ERROR:
- case RDMA_CM_EVENT_ROUTE_ERROR:
- case RDMA_CM_EVENT_MULTICAST_ERROR:
- log_printf (LOGSYS_LEVEL_ERROR, "multicast error");
- break;
- case RDMA_CM_EVENT_DEVICE_REMOVAL:
- break;
- default:
- log_printf (LOGSYS_LEVEL_ERROR, "default %d", event->event);
- break;
- }
- rdma_ack_cm_event (event);
- return (0);
- }
- static int recv_token_cq_send_event_fn (
- int fd,
- int revents,
- void *context)
- {
- struct totemiba_instance *instance = (struct totemiba_instance *)context;
- struct ibv_wc wc[32];
- struct ibv_cq *ev_cq;
- void *ev_ctx;
- int res;
- int i;
- ibv_get_cq_event (instance->recv_token_send_completion_channel, &ev_cq, &ev_ctx);
- ibv_ack_cq_events (ev_cq, 1);
- res = ibv_req_notify_cq (ev_cq, 0);
- res = ibv_poll_cq (instance->recv_token_send_cq, 32, wc);
- if (res > 0) {
- for (i = 0; i < res; i++) {
- iba_deliver_fn (instance, wc[i].wr_id, wc[i].byte_len);
- ibv_dereg_mr (wrid2void(wc[i].wr_id));
- }
- }
- return (0);
- }
- static int recv_token_cq_recv_event_fn (int events, int suck, void *context)
- {
- struct totemiba_instance *instance = (struct totemiba_instance *)context;
- struct ibv_wc wc[32];
- struct ibv_cq *ev_cq;
- void *ev_ctx;
- int res;
- int i;
- ibv_get_cq_event (instance->recv_token_recv_completion_channel, &ev_cq, &ev_ctx);
- ibv_ack_cq_events (ev_cq, 1);
- res = ibv_req_notify_cq (ev_cq, 0);
- res = ibv_poll_cq (instance->recv_token_recv_cq, 32, wc);
- if (res > 0) {
- for (i = 0; i < res; i++) {
- iba_deliver_fn (instance, wc[i].wr_id, wc[i].byte_len);
- recv_token_recv_buf_post (instance, wrid2void(wc[i].wr_id));
- }
- }
- return (0);
- }
- static int recv_token_accept_destroy (struct totemiba_instance *instance)
- {
- if (instance->recv_token_accepted == 0) {
- return (0);
- }
- rdma_destroy_qp (instance->recv_token_cma_id);
- recv_token_recv_buf_post_destroy (instance);
- ibv_destroy_cq (instance->recv_token_send_cq);
- ibv_destroy_cq (instance->recv_token_recv_cq);
- ibv_destroy_comp_channel (instance->recv_token_send_completion_channel);
- ibv_destroy_comp_channel (instance->recv_token_recv_completion_channel);
- ibv_dealloc_pd (instance->recv_token_pd);
- rdma_destroy_id (instance->recv_token_cma_id);
- qb_loop_poll_del (
- instance->totemiba_poll_handle,
- instance->recv_token_recv_completion_channel->fd);
- qb_loop_poll_del (
- instance->totemiba_poll_handle,
- instance->recv_token_send_completion_channel->fd);
- return (0);
- }
- static int recv_token_accept_setup (struct totemiba_instance *instance)
- {
- struct ibv_qp_init_attr init_qp_attr;
- int res = 0;
- /*
- * Allocate the protection domain
- */
- instance->recv_token_pd = ibv_alloc_pd (instance->recv_token_cma_id->verbs);
- /*
- * Create a completion channel
- */
- instance->recv_token_recv_completion_channel = ibv_create_comp_channel (instance->recv_token_cma_id->verbs);
- if (instance->recv_token_recv_completion_channel == NULL) {
- log_printf (LOGSYS_LEVEL_ERROR, "couldn't create completion channel");
- return (-1);
- }
- /*
- * Create the completion queue
- */
- instance->recv_token_recv_cq = ibv_create_cq (instance->recv_token_cma_id->verbs,
- COMPLETION_QUEUE_ENTRIES, instance,
- instance->recv_token_recv_completion_channel, 0);
- if (instance->recv_token_recv_cq == NULL) {
- log_printf (LOGSYS_LEVEL_ERROR, "couldn't create completion queue");
- return (-1);
- }
- res = ibv_req_notify_cq (instance->recv_token_recv_cq, 0);
- if (res != 0) {
- log_printf (LOGSYS_LEVEL_ERROR, "couldn't request notifications of the completion queue");
- return (-1);
- }
- /*
- * Create a completion channel
- */
- instance->recv_token_send_completion_channel = ibv_create_comp_channel (instance->recv_token_cma_id->verbs);
- if (instance->recv_token_send_completion_channel == NULL) {
- log_printf (LOGSYS_LEVEL_ERROR, "couldn't create completion channel");
- return (-1);
- }
- /*
- * Create the completion queue
- */
- instance->recv_token_send_cq = ibv_create_cq (instance->recv_token_cma_id->verbs,
- COMPLETION_QUEUE_ENTRIES, instance,
- instance->recv_token_send_completion_channel, 0);
- if (instance->recv_token_send_cq == NULL) {
- log_printf (LOGSYS_LEVEL_ERROR, "couldn't create completion queue");
- return (-1);
- }
- res = ibv_req_notify_cq (instance->recv_token_send_cq, 0);
- if (res != 0) {
- log_printf (LOGSYS_LEVEL_ERROR, "couldn't request notifications of the completion queue");
- return (-1);
- }
- memset (&init_qp_attr, 0, sizeof (struct ibv_qp_init_attr));
- init_qp_attr.cap.max_send_wr = 50;
- init_qp_attr.cap.max_recv_wr = TOTAL_READ_POSTS;
- init_qp_attr.cap.max_send_sge = 1;
- init_qp_attr.cap.max_recv_sge = 1;
- init_qp_attr.qp_context = instance;
- init_qp_attr.sq_sig_all = 0;
- init_qp_attr.qp_type = IBV_QPT_UD;
- init_qp_attr.send_cq = instance->recv_token_send_cq;
- init_qp_attr.recv_cq = instance->recv_token_recv_cq;
- res = rdma_create_qp (instance->recv_token_cma_id, instance->recv_token_pd,
- &init_qp_attr);
- if (res != 0) {
- log_printf (LOGSYS_LEVEL_ERROR, "couldn't create queue pair");
- return (-1);
- }
-
- recv_token_recv_buf_post_initial (instance);
- qb_loop_poll_add (
- instance->totemiba_poll_handle,
- QB_LOOP_MED,
- instance->recv_token_recv_completion_channel->fd,
- POLLIN, instance, recv_token_cq_recv_event_fn);
- qb_loop_poll_add (
- instance->totemiba_poll_handle,
- QB_LOOP_MED,
- instance->recv_token_send_completion_channel->fd,
- POLLIN, instance, recv_token_cq_send_event_fn);
- instance->recv_token_accepted = 1;
- return (res);
- };
- static int recv_token_rdma_event_fn (int events, int suck, void *context)
- {
- struct totemiba_instance *instance = (struct totemiba_instance *)context;
- struct rdma_cm_event *event;
- struct rdma_conn_param conn_param;
- int res;
- res = rdma_get_cm_event (instance->listen_recv_token_channel, &event);
- if (res != 0) {
- return (0);
- }
- switch (event->event) {
- case RDMA_CM_EVENT_CONNECT_REQUEST:
- recv_token_accept_destroy (instance);
- instance->recv_token_cma_id = event->id;
- recv_token_accept_setup (instance);
- memset (&conn_param, 0, sizeof (struct rdma_conn_param));
- conn_param.qp_num = instance->recv_token_cma_id->qp->qp_num;
- res = rdma_accept (instance->recv_token_cma_id, &conn_param);
- break;
- default:
- log_printf (LOGSYS_LEVEL_ERROR, "default %d", event->event);
- break;
- }
- res = rdma_ack_cm_event (event);
- return (0);
- }
- static int send_token_cq_send_event_fn (int events, int suck, void *context)
- {
- struct totemiba_instance *instance = (struct totemiba_instance *)context;
- struct ibv_wc wc[32];
- struct ibv_cq *ev_cq;
- void *ev_ctx;
- int res;
- int i;
- ibv_get_cq_event (instance->send_token_send_completion_channel, &ev_cq, &ev_ctx);
- ibv_ack_cq_events (ev_cq, 1);
- res = ibv_req_notify_cq (ev_cq, 0);
- res = ibv_poll_cq (instance->send_token_send_cq, 32, wc);
- if (res > 0) {
- for (i = 0; i < res; i++) {
- token_send_buf_put (instance, wrid2void(wc[i].wr_id));
- }
- }
- return (0);
- }
- static int send_token_cq_recv_event_fn (int events, int suck, void *context)
- {
- struct totemiba_instance *instance = (struct totemiba_instance *)context;
- struct ibv_wc wc[32];
- struct ibv_cq *ev_cq;
- void *ev_ctx;
- int res;
- int i;
- ibv_get_cq_event (instance->send_token_recv_completion_channel, &ev_cq, &ev_ctx);
- ibv_ack_cq_events (ev_cq, 1);
- res = ibv_req_notify_cq (ev_cq, 0);
- res = ibv_poll_cq (instance->send_token_recv_cq, 32, wc);
- if (res > 0) {
- for (i = 0; i < res; i++) {
- iba_deliver_fn (instance, wc[i].wr_id, wc[i].byte_len);
- }
- }
- return (0);
- }
- static int send_token_rdma_event_fn (int events, int suck, void *context)
- {
- struct totemiba_instance *instance = (struct totemiba_instance *)context;
- struct rdma_cm_event *event;
- struct rdma_conn_param conn_param;
- int res;
- res = rdma_get_cm_event (instance->send_token_channel, &event);
- if (res != 0) {
- return (0);
- }
- switch (event->event) {
- /*
- * occurs when we resolve the multicast address
- */
- case RDMA_CM_EVENT_ADDR_RESOLVED:
- res = rdma_resolve_route (instance->send_token_cma_id, 2000);
- break;
- /*
- * occurs when the CM joins the multicast group
- */
- case RDMA_CM_EVENT_ROUTE_RESOLVED:
- memset (&conn_param, 0, sizeof (struct rdma_conn_param));
- conn_param.private_data = NULL;
- conn_param.private_data_len = 0;
- res = rdma_connect (instance->send_token_cma_id, &conn_param);
- break;
- case RDMA_CM_EVENT_ESTABLISHED:
- instance->send_token_qpn = event->param.ud.qp_num;
- instance->send_token_qkey = event->param.ud.qkey;
- instance->send_token_ah = ibv_create_ah (instance->send_token_pd, &event->param.ud.ah_attr);
- instance->totemiba_target_set_completed (instance->rrp_context);
- break;
- case RDMA_CM_EVENT_ADDR_ERROR:
- case RDMA_CM_EVENT_ROUTE_ERROR:
- case RDMA_CM_EVENT_MULTICAST_ERROR:
- log_printf (LOGSYS_LEVEL_ERROR,
- "send_token_rdma_event_fn multicast error");
- break;
- case RDMA_CM_EVENT_DEVICE_REMOVAL:
- break;
- case RDMA_CM_EVENT_UNREACHABLE:
- log_printf (LOGSYS_LEVEL_ERROR,
- "send_token_rdma_event_fn unreachable");
- break;
- default:
- log_printf (LOGSYS_LEVEL_ERROR,
- "send_token_rdma_event_fn unknown event %d",
- event->event);
- break;
- }
- rdma_ack_cm_event (event);
- return (0);
- }
- static int send_token_bind (struct totemiba_instance *instance)
- {
- int res;
- struct ibv_qp_init_attr init_qp_attr;
- instance->send_token_channel = rdma_create_event_channel();
- if (instance->send_token_channel == NULL) {
- log_printf (LOGSYS_LEVEL_ERROR, "couldn't create rdma channel");
- return (-1);
- }
- res = rdma_create_id (instance->send_token_channel,
- &instance->send_token_cma_id, NULL, RDMA_PS_UDP);
- if (res) {
- log_printf (LOGSYS_LEVEL_ERROR, "error creating send_token_cma_id");
- return (-1);
- }
- res = rdma_bind_addr (instance->send_token_cma_id,
- &instance->send_token_bind_addr);
- if (res) {
- log_printf (LOGSYS_LEVEL_ERROR, "error doing rdma_bind_addr for send token");
- return (-1);
- }
- /*
- * Resolve the send_token address into a GUID
- */
- res = rdma_resolve_addr (instance->send_token_cma_id,
- &instance->bind_addr, &instance->token_addr, 2000);
- if (res) {
- log_printf (LOGSYS_LEVEL_ERROR, "error resolving send token address %d %d", res, errno);
- return (-1);
- }
- /*
- * Allocate the protection domain
- */
- instance->send_token_pd = ibv_alloc_pd (instance->send_token_cma_id->verbs);
-
- /*
- * Create a completion channel
- */
- instance->send_token_recv_completion_channel = ibv_create_comp_channel (instance->send_token_cma_id->verbs);
- if (instance->send_token_recv_completion_channel == NULL) {
- log_printf (LOGSYS_LEVEL_ERROR, "couldn't create completion channel");
- return (-1);
- }
- /*
- * Create the completion queue
- */
- instance->send_token_recv_cq = ibv_create_cq (instance->send_token_cma_id->verbs,
- COMPLETION_QUEUE_ENTRIES, instance,
- instance->send_token_recv_completion_channel, 0);
- if (instance->send_token_recv_cq == NULL) {
- log_printf (LOGSYS_LEVEL_ERROR, "couldn't create completion queue");
- return (-1);
- }
- res = ibv_req_notify_cq (instance->send_token_recv_cq, 0);
- if (res != 0) {
- log_printf (LOGSYS_LEVEL_ERROR,
- "couldn't request notifications of the completion queue");
- return (-1);
- }
- /*
- * Create a completion channel
- */
- instance->send_token_send_completion_channel =
- ibv_create_comp_channel (instance->send_token_cma_id->verbs);
- if (instance->send_token_send_completion_channel == NULL) {
- log_printf (LOGSYS_LEVEL_ERROR, "couldn't create completion channel");
- return (-1);
- }
-
- /*
- * Create the completion queue
- */
- instance->send_token_send_cq = ibv_create_cq (
- instance->send_token_cma_id->verbs,
- COMPLETION_QUEUE_ENTRIES, instance,
- instance->send_token_send_completion_channel, 0);
- if (instance->send_token_send_cq == NULL) {
- log_printf (LOGSYS_LEVEL_ERROR, "couldn't create completion queue");
- return (-1);
- }
- res = ibv_req_notify_cq (instance->send_token_send_cq, 0);
- if (res != 0) {
- log_printf (LOGSYS_LEVEL_ERROR,
- "couldn't request notifications of the completion queue");
- return (-1);
- }
- memset (&init_qp_attr, 0, sizeof (struct ibv_qp_init_attr));
- init_qp_attr.cap.max_send_wr = 50;
- init_qp_attr.cap.max_recv_wr = TOTAL_READ_POSTS;
- init_qp_attr.cap.max_send_sge = 1;
- init_qp_attr.cap.max_recv_sge = 1;
- init_qp_attr.qp_context = instance;
- init_qp_attr.sq_sig_all = 0;
- init_qp_attr.qp_type = IBV_QPT_UD;
- init_qp_attr.send_cq = instance->send_token_send_cq;
- init_qp_attr.recv_cq = instance->send_token_recv_cq;
- res = rdma_create_qp (instance->send_token_cma_id,
- instance->send_token_pd, &init_qp_attr);
- if (res != 0) {
- log_printf (LOGSYS_LEVEL_ERROR, "couldn't create queue pair");
- return (-1);
- }
-
- qb_loop_poll_add (
- instance->totemiba_poll_handle,
- QB_LOOP_MED,
- instance->send_token_recv_completion_channel->fd,
- POLLIN, instance, send_token_cq_recv_event_fn);
- qb_loop_poll_add (
- instance->totemiba_poll_handle,
- QB_LOOP_MED,
- instance->send_token_send_completion_channel->fd,
- POLLIN, instance, send_token_cq_send_event_fn);
- qb_loop_poll_add (
- instance->totemiba_poll_handle,
- QB_LOOP_MED,
- instance->send_token_channel->fd,
- POLLIN, instance, send_token_rdma_event_fn);
- instance->send_token_bound = 1;
- return (0);
- }
- static int send_token_unbind (struct totemiba_instance *instance)
- {
- if (instance->send_token_bound == 0) {
- return (0);
- }
- qb_loop_poll_del (
- instance->totemiba_poll_handle,
- instance->send_token_recv_completion_channel->fd);
- qb_loop_poll_del (
- instance->totemiba_poll_handle,
- instance->send_token_send_completion_channel->fd);
- qb_loop_poll_del (
- instance->totemiba_poll_handle,
- instance->send_token_channel->fd);
- rdma_destroy_qp (instance->send_token_cma_id);
- ibv_destroy_cq (instance->send_token_send_cq);
- ibv_destroy_cq (instance->send_token_recv_cq);
- ibv_destroy_comp_channel (instance->send_token_send_completion_channel);
- ibv_destroy_comp_channel (instance->send_token_recv_completion_channel);
- token_send_buf_destroy (instance);
- ibv_dealloc_pd (instance->send_token_pd);
- rdma_destroy_id (instance->send_token_cma_id);
- rdma_destroy_event_channel (instance->send_token_channel);
- return (0);
- }
- static int recv_token_bind (struct totemiba_instance *instance)
- {
- int res;
- instance->listen_recv_token_channel = rdma_create_event_channel();
- if (instance->listen_recv_token_channel == NULL) {
- log_printf (LOGSYS_LEVEL_ERROR, "couldn't create rdma channel");
- return (-1);
- }
- res = rdma_create_id (instance->listen_recv_token_channel,
- &instance->listen_recv_token_cma_id, NULL, RDMA_PS_UDP);
- if (res) {
- log_printf (LOGSYS_LEVEL_ERROR, "error creating recv_token_cma_id");
- return (-1);
- }
- res = rdma_bind_addr (instance->listen_recv_token_cma_id,
- &instance->bind_addr);
- if (res) {
- log_printf (LOGSYS_LEVEL_ERROR, "error doing rdma_bind_addr for recv token");
- return (-1);
- }
- /*
- * Resolve the recv_token address into a GUID
- */
- res = rdma_listen (instance->listen_recv_token_cma_id, 10);
- if (res) {
- log_printf (LOGSYS_LEVEL_ERROR, "error listening %d %d", res, errno);
- return (-1);
- }
- qb_loop_poll_add (
- instance->totemiba_poll_handle,
- QB_LOOP_MED,
- instance->listen_recv_token_channel->fd,
- POLLIN, instance, recv_token_rdma_event_fn);
- return (0);
- }
- static int mcast_bind (struct totemiba_instance *instance)
- {
- int res;
- struct ibv_qp_init_attr init_qp_attr;
- instance->mcast_channel = rdma_create_event_channel();
- if (instance->mcast_channel == NULL) {
- log_printf (LOGSYS_LEVEL_ERROR, "couldn't create rdma channel");
- return (-1);
- }
- res = rdma_create_id (instance->mcast_channel, &instance->mcast_cma_id, NULL, RDMA_PS_UDP);
- if (res) {
- log_printf (LOGSYS_LEVEL_ERROR, "error creating mcast_cma_id");
- return (-1);
- }
- res = rdma_bind_addr (instance->mcast_cma_id, &instance->local_mcast_bind_addr);
- if (res) {
- log_printf (LOGSYS_LEVEL_ERROR, "error doing rdma_bind_addr for mcast");
- return (-1);
- }
- /*
- * Resolve the multicast address into a GUID
- */
- res = rdma_resolve_addr (instance->mcast_cma_id, &instance->local_mcast_bind_addr,
- &instance->mcast_addr, 5000);
- if (res) {
- log_printf (LOGSYS_LEVEL_ERROR, "error resolving multicast address %d %d", res, errno);
- return (-1);
- }
- /*
- * Allocate the protection domain
- */
- instance->mcast_pd = ibv_alloc_pd (instance->mcast_cma_id->verbs);
-
- /*
- * Create a completion channel
- */
- instance->mcast_recv_completion_channel = ibv_create_comp_channel (instance->mcast_cma_id->verbs);
- if (instance->mcast_recv_completion_channel == NULL) {
- log_printf (LOGSYS_LEVEL_ERROR, "couldn't create completion channel");
- return (-1);
- }
- /*
- * Create the completion queue
- */
- instance->mcast_recv_cq = ibv_create_cq (instance->mcast_cma_id->verbs,
- COMPLETION_QUEUE_ENTRIES, instance,
- instance->mcast_recv_completion_channel, 0);
- if (instance->mcast_recv_cq == NULL) {
- log_printf (LOGSYS_LEVEL_ERROR, "couldn't create completion queue");
- return (-1);
- }
- res = ibv_req_notify_cq (instance->mcast_recv_cq, 0);
- if (res != 0) {
- log_printf (LOGSYS_LEVEL_ERROR, "couldn't request notifications of the completion queue");
- return (-1);
- }
- /*
- * Create a completion channel
- */
- instance->mcast_send_completion_channel = ibv_create_comp_channel (instance->mcast_cma_id->verbs);
- if (instance->mcast_send_completion_channel == NULL) {
- log_printf (LOGSYS_LEVEL_ERROR, "couldn't create completion channel");
- return (-1);
- }
- /*
- * Create the completion queue
- */
- instance->mcast_send_cq = ibv_create_cq (instance->mcast_cma_id->verbs,
- COMPLETION_QUEUE_ENTRIES, instance,
- instance->mcast_send_completion_channel, 0);
- if (instance->mcast_send_cq == NULL) {
- log_printf (LOGSYS_LEVEL_ERROR, "couldn't create completion queue");
- return (-1);
- }
- res = ibv_req_notify_cq (instance->mcast_send_cq, 0);
- if (res != 0) {
- log_printf (LOGSYS_LEVEL_ERROR, "couldn't request notifications of the completion queue");
- return (-1);
- }
- memset (&init_qp_attr, 0, sizeof (struct ibv_qp_init_attr));
- init_qp_attr.cap.max_send_wr = 50;
- init_qp_attr.cap.max_recv_wr = TOTAL_READ_POSTS;
- init_qp_attr.cap.max_send_sge = 1;
- init_qp_attr.cap.max_recv_sge = 1;
- init_qp_attr.qp_context = instance;
- init_qp_attr.sq_sig_all = 0;
- init_qp_attr.qp_type = IBV_QPT_UD;
- init_qp_attr.send_cq = instance->mcast_send_cq;
- init_qp_attr.recv_cq = instance->mcast_recv_cq;
- res = rdma_create_qp (instance->mcast_cma_id, instance->mcast_pd,
- &init_qp_attr);
- if (res != 0) {
- log_printf (LOGSYS_LEVEL_ERROR, "couldn't create queue pair");
- return (-1);
- }
-
- mcast_recv_buf_post_initial (instance);
- qb_loop_poll_add (
- instance->totemiba_poll_handle,
- QB_LOOP_MED,
- instance->mcast_recv_completion_channel->fd,
- POLLIN, instance, mcast_cq_recv_event_fn);
- qb_loop_poll_add (
- instance->totemiba_poll_handle,
- QB_LOOP_MED,
- instance->mcast_send_completion_channel->fd,
- POLLIN, instance, mcast_cq_send_event_fn);
- qb_loop_poll_add (
- instance->totemiba_poll_handle,
- QB_LOOP_MED,
- instance->mcast_channel->fd,
- POLLIN, instance, mcast_rdma_event_fn);
- return (0);
- }
- static void timer_function_netif_check_timeout (
- void *data)
- {
- struct totemiba_instance *instance = (struct totemiba_instance *)data;
- int res;
- int interface_up;
- int interface_num;
- int addr_len;
- totemip_iface_check (&instance->totem_interface->bindnet,
- &instance->totem_interface->boundto, &interface_up, &interface_num, instance->totem_config->clear_node_high_bit);
- totemip_totemip_to_sockaddr_convert(&instance->totem_interface->boundto,
- instance->totem_interface->ip_port, (struct sockaddr_storage *)&instance->bind_addr,
- &addr_len);
- totemip_totemip_to_sockaddr_convert(&instance->totem_interface->boundto,
- 0, (struct sockaddr_storage *)&instance->send_token_bind_addr,
- &addr_len);
- totemip_totemip_to_sockaddr_convert(&instance->totem_interface->boundto,
- 0, (struct sockaddr_storage *)&instance->local_mcast_bind_addr,
- &addr_len);
- totemip_totemip_to_sockaddr_convert(&instance->totem_interface->boundto,
- instance->totem_interface->ip_port, (struct sockaddr_storage *)&instance->my_id,
- &addr_len);
- totemip_sockaddr_to_totemip_convert(
- (const struct sockaddr_storage *)&instance->bind_addr,
- &instance->my_id);
- memcpy (&instance->my_id, &instance->totem_interface->boundto,
- sizeof (struct totem_ip_address));
- totemip_totemip_to_sockaddr_convert(&instance->totem_interface->mcast_addr,
- instance->totem_interface->ip_port,
- (struct sockaddr_storage *)&instance->mcast_addr, &addr_len);
- res = recv_token_bind (instance);
- res = mcast_bind (instance);
- }
- int totemiba_crypto_set (
- void *iba_context,
- unsigned int type)
- {
- struct totemiba_instance *instance = (struct totemiba_instance *)iba_context;
- int res = 0;
- instance = NULL;
- return (res);
- }
- int totemiba_finalize (
- void *iba_context)
- {
- struct totemiba_instance *instance = (struct totemiba_instance *)iba_context;
- int res = 0;
- instance = NULL;
- return (res);
- }
- /*
- * Create an instance
- */
- int totemiba_initialize (
- qb_loop_t *qb_poll_handle,
- void **iba_context,
- struct totem_config *totem_config,
- int interface_no,
- void *context,
- void (*deliver_fn) (
- void *context,
- const void *msg,
- unsigned int msg_len),
- void (*iface_change_fn) (
- void *context,
- const struct totem_ip_address *iface_address),
- void (*target_set_completed) (
- void *context))
- {
- struct totemiba_instance *instance;
- int res = 0;
- instance = malloc (sizeof (struct totemiba_instance));
- if (instance == NULL) {
- return (-1);
- }
- totemiba_instance_initialize (instance);
- instance->totem_interface = &totem_config->interfaces[interface_no];
- instance->totemiba_poll_handle = qb_poll_handle;
- instance->totemiba_deliver_fn = deliver_fn;
- instance->totemiba_target_set_completed = target_set_completed;
- instance->totemiba_iface_change_fn = iface_change_fn;
- instance->totem_config = totem_config;
- instance->rrp_context = context;
- qb_loop_timer_add (instance->totemiba_poll_handle,
- QB_LOOP_MED,
- 100*QB_TIME_NS_IN_MSEC,
- (void *)instance,
- timer_function_netif_check_timeout,
- &instance->timer_netif_check_timeout);
- instance->totemiba_subsys_id = totem_config->totem_logging_configuration.log_subsys_id;
- instance->totemiba_log_printf = totem_config->totem_logging_configuration.log_printf;
- *iba_context = instance;
- return (res);
- }
- void *totemiba_buffer_alloc (void)
- {
- return malloc (MAX_MTU_SIZE);
- }
- void totemiba_buffer_release (void *ptr)
- {
- return free (ptr);
- }
- int totemiba_processor_count_set (
- void *iba_context,
- int processor_count)
- {
- struct totemiba_instance *instance = (struct totemiba_instance *)iba_context;
- int res = 0;
- instance = NULL;
- return (res);
- }
- int totemiba_recv_flush (void *iba_context)
- {
- struct totemiba_instance *instance = (struct totemiba_instance *)iba_context;
- int res = 0;
- instance = NULL;
- return (res);
- }
- int totemiba_send_flush (void *iba_context)
- {
- struct totemiba_instance *instance = (struct totemiba_instance *)iba_context;
- int res = 0;
- instance = NULL;
- return (res);
- }
- int totemiba_token_send (
- void *iba_context,
- const void *ms,
- unsigned int msg_len)
- {
- struct totemiba_instance *instance = (struct totemiba_instance *)iba_context;
- int res = 0;
- struct ibv_send_wr send_wr, *failed_send_wr;
- struct ibv_sge sge;
- void *msg;
- struct send_buf *send_buf;
- send_buf = token_send_buf_get (instance);
- if (send_buf == NULL) {
- return (-1);
- }
- msg = send_buf->buffer;
- memcpy (msg, ms, msg_len);
- send_wr.next = NULL;
- send_wr.sg_list = &sge;
- send_wr.num_sge = 1;
- send_wr.opcode = IBV_WR_SEND;
- send_wr.send_flags = IBV_SEND_SIGNALED;
- send_wr.wr_id = void2wrid(send_buf);
- send_wr.imm_data = 0;
- send_wr.wr.ud.ah = instance->send_token_ah;
- send_wr.wr.ud.remote_qpn = instance->send_token_qpn;
- send_wr.wr.ud.remote_qkey = instance->send_token_qkey;
- sge.length = msg_len;
- sge.lkey = send_buf->mr->lkey;
- sge.addr = (uintptr_t)msg;
- res = ibv_post_send (instance->send_token_cma_id->qp, &send_wr, &failed_send_wr);
- return (res);
- }
- int totemiba_mcast_flush_send (
- void *iba_context,
- const void *ms,
- unsigned int msg_len)
- {
- struct totemiba_instance *instance = (struct totemiba_instance *)iba_context;
- int res = 0;
- struct ibv_send_wr send_wr, *failed_send_wr;
- struct ibv_sge sge;
- void *msg;
- struct send_buf *send_buf;
- send_buf = mcast_send_buf_get (instance);
- if (send_buf == NULL) {
- return (-1);
- }
- msg = send_buf->buffer;
- memcpy (msg, ms, msg_len);
- send_wr.next = NULL;
- send_wr.sg_list = &sge;
- send_wr.num_sge = 1;
- send_wr.opcode = IBV_WR_SEND;
- send_wr.send_flags = IBV_SEND_SIGNALED;
- send_wr.wr_id = void2wrid(send_buf);
- send_wr.imm_data = 0;
- send_wr.wr.ud.ah = instance->mcast_ah;
- send_wr.wr.ud.remote_qpn = instance->mcast_qpn;
- send_wr.wr.ud.remote_qkey = instance->mcast_qkey;
- sge.length = msg_len;
- sge.lkey = send_buf->mr->lkey;
- sge.addr = (uintptr_t)msg;
- res = ibv_post_send (instance->mcast_cma_id->qp, &send_wr, &failed_send_wr);
- return (res);
- }
- int totemiba_mcast_noflush_send (
- void *iba_context,
- const void *ms,
- unsigned int msg_len)
- {
- struct totemiba_instance *instance = (struct totemiba_instance *)iba_context;
- int res = 0;
- struct ibv_send_wr send_wr, *failed_send_wr;
- struct ibv_sge sge;
- void *msg;
- struct send_buf *send_buf;
- send_buf = mcast_send_buf_get (instance);
- if (send_buf == NULL) {
- return (-1);
- }
- msg = send_buf->buffer;
- memcpy (msg, ms, msg_len);
- send_wr.next = NULL;
- send_wr.sg_list = &sge;
- send_wr.num_sge = 1;
- send_wr.opcode = IBV_WR_SEND;
- send_wr.send_flags = IBV_SEND_SIGNALED;
- send_wr.wr_id = void2wrid(send_buf);
- send_wr.imm_data = 0;
- send_wr.wr.ud.ah = instance->mcast_ah;
- send_wr.wr.ud.remote_qpn = instance->mcast_qpn;
- send_wr.wr.ud.remote_qkey = instance->mcast_qkey;
- sge.length = msg_len;
- sge.lkey = send_buf->mr->lkey;
- sge.addr = (uintptr_t)msg;
- res = ibv_post_send (instance->mcast_cma_id->qp, &send_wr, &failed_send_wr);
- return (res);
- }
- extern int totemiba_iface_check (void *iba_context)
- {
- struct totemiba_instance *instance = (struct totemiba_instance *)iba_context;
- int res = 0;
- instance = NULL;
- return (res);
- }
- extern void totemiba_net_mtu_adjust (void *iba_context, struct totem_config *totem_config)
- {
- struct totemiba_instance *instance = (struct totemiba_instance *)iba_context;
- instance = NULL;
- }
- const char *totemiba_iface_print (void *iba_context) {
- struct totemiba_instance *instance = (struct totemiba_instance *)iba_context;
- const char *ret_char;
- ret_char = totemip_print (&instance->my_id);
- return (ret_char);
- }
- int totemiba_iface_get (
- void *iba_context,
- struct totem_ip_address *addr)
- {
- struct totemiba_instance *instance = (struct totemiba_instance *)iba_context;
- int res = 0;
- memcpy (addr, &instance->my_id, sizeof (struct totem_ip_address));
- return (res);
- }
- int totemiba_token_target_set (
- void *iba_context,
- const struct totem_ip_address *token_target)
- {
- struct totemiba_instance *instance = (struct totemiba_instance *)iba_context;
- int res = 0;
- int addr_len = 16;
- totemip_totemip_to_sockaddr_convert((struct totem_ip_address *)token_target,
- instance->totem_interface->ip_port, (struct sockaddr_storage *)&instance->token_addr,
- &addr_len);
- res = send_token_unbind (instance);
- res = send_token_bind (instance);
- return (res);
- }
- extern int totemiba_recv_mcast_empty (
- void *iba_context)
- {
- struct totemiba_instance *instance = (struct totemiba_instance *)iba_context;
- int res = 0;
- instance = NULL;
- return (res);
- }
|