blob: 844a77e2582856ae8cff4618c5e1de23f4220e0b [file] [log] [blame]
Patrick McHardya29a1942013-04-17 06:18:28 +00001/*
2 * net/tipc/ib_media.c: Infiniband bearer support for TIPC
3 *
4 * Copyright (c) 2013 Patrick McHardy <kaber@trash.net>
5 *
6 * Based on eth_media.c, which carries the following copyright notice:
7 *
8 * Copyright (c) 2001-2007, Ericsson AB
9 * Copyright (c) 2005-2008, 2011, Wind River Systems
10 * All rights reserved.
11 *
12 * Redistribution and use in source and binary forms, with or without
13 * modification, are permitted provided that the following conditions are met:
14 *
15 * 1. Redistributions of source code must retain the above copyright
16 * notice, this list of conditions and the following disclaimer.
17 * 2. Redistributions in binary form must reproduce the above copyright
18 * notice, this list of conditions and the following disclaimer in the
19 * documentation and/or other materials provided with the distribution.
20 * 3. Neither the names of the copyright holders nor the names of its
21 * contributors may be used to endorse or promote products derived from
22 * this software without specific prior written permission.
23 *
24 * Alternatively, this software may be distributed under the terms of the
25 * GNU General Public License ("GPL") version 2 as published by the Free
26 * Software Foundation.
27 *
28 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
29 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
30 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
31 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
32 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
33 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
34 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
35 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
36 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
37 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
38 * POSSIBILITY OF SUCH DAMAGE.
39 */
40
41#include <linux/if_infiniband.h>
42#include "core.h"
43#include "bearer.h"
44
Ying Xuee4d050c2013-12-10 20:45:43 -080045/* convert InfiniBand address to string */
46static int tipc_ib_addr2str(struct tipc_media_addr *a, char *str_buf,
47 int str_size)
Patrick McHardya29a1942013-04-17 06:18:28 +000048{
49 if (str_size < 60) /* 60 = 19 * strlen("xx:") + strlen("xx\0") */
50 return 1;
51
Andy Shevchenkod77e41e2013-07-10 17:30:34 +030052 sprintf(str_buf, "%20phC", a->value);
Patrick McHardya29a1942013-04-17 06:18:28 +000053
54 return 0;
55}
56
Ying Xuee4d050c2013-12-10 20:45:43 -080057/* convert InfiniBand address format to message header format */
58static int tipc_ib_addr2msg(struct tipc_media_addr *a, char *msg_area)
Patrick McHardya29a1942013-04-17 06:18:28 +000059{
60 memset(msg_area, 0, TIPC_MEDIA_ADDR_SIZE);
61 msg_area[TIPC_MEDIA_TYPE_OFFSET] = TIPC_MEDIA_TYPE_IB;
62 memcpy(msg_area, a->value, INFINIBAND_ALEN);
63 return 0;
64}
65
Ying Xuee4d050c2013-12-10 20:45:43 -080066/* convert message header address format to InfiniBand format */
67static int tipc_ib_msg2addr(const struct tipc_bearer *tb_ptr,
68 struct tipc_media_addr *a, char *msg_area)
Patrick McHardya29a1942013-04-17 06:18:28 +000069{
Ying Xuee4d050c2013-12-10 20:45:43 -080070 tipc_l2_media_addr_set(tb_ptr, a, msg_area);
Patrick McHardya29a1942013-04-17 06:18:28 +000071 return 0;
72}
73
Ying Xuee4d050c2013-12-10 20:45:43 -080074/* InfiniBand media registration info */
Jon Paul Maloy5702dba2013-12-10 20:45:39 -080075struct tipc_media ib_media_info = {
Ying Xuee4d050c2013-12-10 20:45:43 -080076 .send_msg = tipc_l2_send_msg,
77 .enable_media = tipc_enable_l2_media,
78 .disable_media = tipc_disable_l2_media,
79 .addr2str = tipc_ib_addr2str,
80 .addr2msg = tipc_ib_addr2msg,
81 .msg2addr = tipc_ib_msg2addr,
Patrick McHardya29a1942013-04-17 06:18:28 +000082 .priority = TIPC_DEF_LINK_PRI,
83 .tolerance = TIPC_DEF_LINK_TOL,
84 .window = TIPC_DEF_LINK_WIN,
85 .type_id = TIPC_MEDIA_TYPE_IB,
Ying Xuee4d050c2013-12-10 20:45:43 -080086 .hwaddr_len = INFINIBAND_ALEN,
Patrick McHardya29a1942013-04-17 06:18:28 +000087 .name = "ib"
88};
89