Back to home page

OSCL-LXR

 
 

    


0001 /*
0002  * net/tipc/ib_media.c: Infiniband bearer support for TIPC
0003  *
0004  * Copyright (c) 2013 Patrick McHardy <kaber@trash.net>
0005  *
0006  * Based on eth_media.c, which carries the following copyright notice:
0007  *
0008  * Copyright (c) 2001-2007, Ericsson AB
0009  * Copyright (c) 2005-2008, 2011, Wind River Systems
0010  * All rights reserved.
0011  *
0012  * Redistribution and use in source and binary forms, with or without
0013  * modification, are permitted provided that the following conditions are met:
0014  *
0015  * 1. Redistributions of source code must retain the above copyright
0016  *    notice, this list of conditions and the following disclaimer.
0017  * 2. Redistributions in binary form must reproduce the above copyright
0018  *    notice, this list of conditions and the following disclaimer in the
0019  *    documentation and/or other materials provided with the distribution.
0020  * 3. Neither the names of the copyright holders nor the names of its
0021  *    contributors may be used to endorse or promote products derived from
0022  *    this software without specific prior written permission.
0023  *
0024  * Alternatively, this software may be distributed under the terms of the
0025  * GNU General Public License ("GPL") version 2 as published by the Free
0026  * Software Foundation.
0027  *
0028  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
0029  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
0030  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
0031  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
0032  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
0033  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
0034  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
0035  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
0036  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
0037  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
0038  * POSSIBILITY OF SUCH DAMAGE.
0039  */
0040 
0041 #include <linux/if_infiniband.h>
0042 #include "core.h"
0043 #include "bearer.h"
0044 
0045 #define TIPC_MAX_IB_LINK_WIN 500
0046 
0047 /* convert InfiniBand address (media address format) media address to string */
0048 static int tipc_ib_addr2str(struct tipc_media_addr *a, char *str_buf,
0049                 int str_size)
0050 {
0051     if (str_size < 60)  /* 60 = 19 * strlen("xx:") + strlen("xx\0") */
0052         return 1;
0053 
0054     sprintf(str_buf, "%20phC", a->value);
0055 
0056     return 0;
0057 }
0058 
0059 /* Convert from media address format to discovery message addr format */
0060 static int tipc_ib_addr2msg(char *msg, struct tipc_media_addr *addr)
0061 {
0062     memset(msg, 0, TIPC_MEDIA_INFO_SIZE);
0063     memcpy(msg, addr->value, INFINIBAND_ALEN);
0064     return 0;
0065 }
0066 
0067 /* Convert raw InfiniBand address format to media addr format */
0068 static int tipc_ib_raw2addr(struct tipc_bearer *b,
0069                 struct tipc_media_addr *addr,
0070                 const char *msg)
0071 {
0072     memset(addr, 0, sizeof(*addr));
0073     memcpy(addr->value, msg, INFINIBAND_ALEN);
0074     addr->media_id = TIPC_MEDIA_TYPE_IB;
0075     addr->broadcast = !memcmp(msg, b->bcast_addr.value,
0076                   INFINIBAND_ALEN);
0077     return 0;
0078 }
0079 
0080 /* Convert discovery msg addr format to InfiniBand media addr format */
0081 static int tipc_ib_msg2addr(struct tipc_bearer *b,
0082                 struct tipc_media_addr *addr,
0083                 char *msg)
0084 {
0085     return tipc_ib_raw2addr(b, addr, msg);
0086 }
0087 
0088 /* InfiniBand media registration info */
0089 struct tipc_media ib_media_info = {
0090     .send_msg   = tipc_l2_send_msg,
0091     .enable_media   = tipc_enable_l2_media,
0092     .disable_media  = tipc_disable_l2_media,
0093     .addr2str   = tipc_ib_addr2str,
0094     .addr2msg   = tipc_ib_addr2msg,
0095     .msg2addr   = tipc_ib_msg2addr,
0096     .raw2addr   = tipc_ib_raw2addr,
0097     .priority   = TIPC_DEF_LINK_PRI,
0098     .tolerance  = TIPC_DEF_LINK_TOL,
0099     .min_win    = TIPC_DEF_LINK_WIN,
0100     .max_win    = TIPC_MAX_IB_LINK_WIN,
0101     .type_id    = TIPC_MEDIA_TYPE_IB,
0102     .hwaddr_len = INFINIBAND_ALEN,
0103     .name       = "ib"
0104 };