18c2ecf20Sopenharmony_ci/* 28c2ecf20Sopenharmony_ci * net/tipc/ib_media.c: Infiniband bearer support for TIPC 38c2ecf20Sopenharmony_ci * 48c2ecf20Sopenharmony_ci * Copyright (c) 2013 Patrick McHardy <kaber@trash.net> 58c2ecf20Sopenharmony_ci * 68c2ecf20Sopenharmony_ci * Based on eth_media.c, which carries the following copyright notice: 78c2ecf20Sopenharmony_ci * 88c2ecf20Sopenharmony_ci * Copyright (c) 2001-2007, Ericsson AB 98c2ecf20Sopenharmony_ci * Copyright (c) 2005-2008, 2011, Wind River Systems 108c2ecf20Sopenharmony_ci * All rights reserved. 118c2ecf20Sopenharmony_ci * 128c2ecf20Sopenharmony_ci * Redistribution and use in source and binary forms, with or without 138c2ecf20Sopenharmony_ci * modification, are permitted provided that the following conditions are met: 148c2ecf20Sopenharmony_ci * 158c2ecf20Sopenharmony_ci * 1. Redistributions of source code must retain the above copyright 168c2ecf20Sopenharmony_ci * notice, this list of conditions and the following disclaimer. 178c2ecf20Sopenharmony_ci * 2. Redistributions in binary form must reproduce the above copyright 188c2ecf20Sopenharmony_ci * notice, this list of conditions and the following disclaimer in the 198c2ecf20Sopenharmony_ci * documentation and/or other materials provided with the distribution. 208c2ecf20Sopenharmony_ci * 3. Neither the names of the copyright holders nor the names of its 218c2ecf20Sopenharmony_ci * contributors may be used to endorse or promote products derived from 228c2ecf20Sopenharmony_ci * this software without specific prior written permission. 238c2ecf20Sopenharmony_ci * 248c2ecf20Sopenharmony_ci * Alternatively, this software may be distributed under the terms of the 258c2ecf20Sopenharmony_ci * GNU General Public License ("GPL") version 2 as published by the Free 268c2ecf20Sopenharmony_ci * Software Foundation. 278c2ecf20Sopenharmony_ci * 288c2ecf20Sopenharmony_ci * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 298c2ecf20Sopenharmony_ci * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 308c2ecf20Sopenharmony_ci * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 318c2ecf20Sopenharmony_ci * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 328c2ecf20Sopenharmony_ci * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 338c2ecf20Sopenharmony_ci * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 348c2ecf20Sopenharmony_ci * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 358c2ecf20Sopenharmony_ci * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 368c2ecf20Sopenharmony_ci * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 378c2ecf20Sopenharmony_ci * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 388c2ecf20Sopenharmony_ci * POSSIBILITY OF SUCH DAMAGE. 398c2ecf20Sopenharmony_ci */ 408c2ecf20Sopenharmony_ci 418c2ecf20Sopenharmony_ci#include <linux/if_infiniband.h> 428c2ecf20Sopenharmony_ci#include "core.h" 438c2ecf20Sopenharmony_ci#include "bearer.h" 448c2ecf20Sopenharmony_ci 458c2ecf20Sopenharmony_ci#define TIPC_MAX_IB_LINK_WIN 500 468c2ecf20Sopenharmony_ci 478c2ecf20Sopenharmony_ci/* convert InfiniBand address (media address format) media address to string */ 488c2ecf20Sopenharmony_cistatic int tipc_ib_addr2str(struct tipc_media_addr *a, char *str_buf, 498c2ecf20Sopenharmony_ci int str_size) 508c2ecf20Sopenharmony_ci{ 518c2ecf20Sopenharmony_ci if (str_size < 60) /* 60 = 19 * strlen("xx:") + strlen("xx\0") */ 528c2ecf20Sopenharmony_ci return 1; 538c2ecf20Sopenharmony_ci 548c2ecf20Sopenharmony_ci sprintf(str_buf, "%20phC", a->value); 558c2ecf20Sopenharmony_ci 568c2ecf20Sopenharmony_ci return 0; 578c2ecf20Sopenharmony_ci} 588c2ecf20Sopenharmony_ci 598c2ecf20Sopenharmony_ci/* Convert from media address format to discovery message addr format */ 608c2ecf20Sopenharmony_cistatic int tipc_ib_addr2msg(char *msg, struct tipc_media_addr *addr) 618c2ecf20Sopenharmony_ci{ 628c2ecf20Sopenharmony_ci memset(msg, 0, TIPC_MEDIA_INFO_SIZE); 638c2ecf20Sopenharmony_ci memcpy(msg, addr->value, INFINIBAND_ALEN); 648c2ecf20Sopenharmony_ci return 0; 658c2ecf20Sopenharmony_ci} 668c2ecf20Sopenharmony_ci 678c2ecf20Sopenharmony_ci/* Convert raw InfiniBand address format to media addr format */ 688c2ecf20Sopenharmony_cistatic int tipc_ib_raw2addr(struct tipc_bearer *b, 698c2ecf20Sopenharmony_ci struct tipc_media_addr *addr, 708c2ecf20Sopenharmony_ci char *msg) 718c2ecf20Sopenharmony_ci{ 728c2ecf20Sopenharmony_ci memset(addr, 0, sizeof(*addr)); 738c2ecf20Sopenharmony_ci memcpy(addr->value, msg, INFINIBAND_ALEN); 748c2ecf20Sopenharmony_ci addr->media_id = TIPC_MEDIA_TYPE_IB; 758c2ecf20Sopenharmony_ci addr->broadcast = !memcmp(msg, b->bcast_addr.value, 768c2ecf20Sopenharmony_ci INFINIBAND_ALEN); 778c2ecf20Sopenharmony_ci return 0; 788c2ecf20Sopenharmony_ci} 798c2ecf20Sopenharmony_ci 808c2ecf20Sopenharmony_ci/* Convert discovery msg addr format to InfiniBand media addr format */ 818c2ecf20Sopenharmony_cistatic int tipc_ib_msg2addr(struct tipc_bearer *b, 828c2ecf20Sopenharmony_ci struct tipc_media_addr *addr, 838c2ecf20Sopenharmony_ci char *msg) 848c2ecf20Sopenharmony_ci{ 858c2ecf20Sopenharmony_ci return tipc_ib_raw2addr(b, addr, msg); 868c2ecf20Sopenharmony_ci} 878c2ecf20Sopenharmony_ci 888c2ecf20Sopenharmony_ci/* InfiniBand media registration info */ 898c2ecf20Sopenharmony_cistruct tipc_media ib_media_info = { 908c2ecf20Sopenharmony_ci .send_msg = tipc_l2_send_msg, 918c2ecf20Sopenharmony_ci .enable_media = tipc_enable_l2_media, 928c2ecf20Sopenharmony_ci .disable_media = tipc_disable_l2_media, 938c2ecf20Sopenharmony_ci .addr2str = tipc_ib_addr2str, 948c2ecf20Sopenharmony_ci .addr2msg = tipc_ib_addr2msg, 958c2ecf20Sopenharmony_ci .msg2addr = tipc_ib_msg2addr, 968c2ecf20Sopenharmony_ci .raw2addr = tipc_ib_raw2addr, 978c2ecf20Sopenharmony_ci .priority = TIPC_DEF_LINK_PRI, 988c2ecf20Sopenharmony_ci .tolerance = TIPC_DEF_LINK_TOL, 998c2ecf20Sopenharmony_ci .min_win = TIPC_DEF_LINK_WIN, 1008c2ecf20Sopenharmony_ci .max_win = TIPC_MAX_IB_LINK_WIN, 1018c2ecf20Sopenharmony_ci .type_id = TIPC_MEDIA_TYPE_IB, 1028c2ecf20Sopenharmony_ci .hwaddr_len = INFINIBAND_ALEN, 1038c2ecf20Sopenharmony_ci .name = "ib" 1048c2ecf20Sopenharmony_ci}; 105