Patrick McHardy | a29a194 | 2013-04-17 06:18:28 +0000 | [diff] [blame] | 1 | /* |
| 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 | |
Jon Maloy | 16ad3f4 | 2019-12-10 00:52:46 +0100 | [diff] [blame] | 45 | #define TIPC_MAX_IB_LINK_WIN 500 |
| 46 | |
Jon Paul Maloy | 38504c2 | 2014-05-14 05:39:13 -0400 | [diff] [blame] | 47 | /* convert InfiniBand address (media address format) media address to string */ |
Ying Xue | e4d050c | 2013-12-10 20:45:43 -0800 | [diff] [blame] | 48 | static int tipc_ib_addr2str(struct tipc_media_addr *a, char *str_buf, |
| 49 | int str_size) |
Patrick McHardy | a29a194 | 2013-04-17 06:18:28 +0000 | [diff] [blame] | 50 | { |
| 51 | if (str_size < 60) /* 60 = 19 * strlen("xx:") + strlen("xx\0") */ |
| 52 | return 1; |
| 53 | |
Andy Shevchenko | d77e41e | 2013-07-10 17:30:34 +0300 | [diff] [blame] | 54 | sprintf(str_buf, "%20phC", a->value); |
Patrick McHardy | a29a194 | 2013-04-17 06:18:28 +0000 | [diff] [blame] | 55 | |
| 56 | return 0; |
| 57 | } |
| 58 | |
Jon Paul Maloy | 38504c2 | 2014-05-14 05:39:13 -0400 | [diff] [blame] | 59 | /* Convert from media address format to discovery message addr format */ |
| 60 | static int tipc_ib_addr2msg(char *msg, struct tipc_media_addr *addr) |
Patrick McHardy | a29a194 | 2013-04-17 06:18:28 +0000 | [diff] [blame] | 61 | { |
Erik Hugne | 91e2eb5 | 2015-02-27 08:56:57 +0100 | [diff] [blame] | 62 | memset(msg, 0, TIPC_MEDIA_INFO_SIZE); |
Jon Paul Maloy | 38504c2 | 2014-05-14 05:39:13 -0400 | [diff] [blame] | 63 | memcpy(msg, addr->value, INFINIBAND_ALEN); |
Patrick McHardy | a29a194 | 2013-04-17 06:18:28 +0000 | [diff] [blame] | 64 | return 0; |
| 65 | } |
| 66 | |
Jon Paul Maloy | 38504c2 | 2014-05-14 05:39:13 -0400 | [diff] [blame] | 67 | /* Convert raw InfiniBand address format to media addr format */ |
| 68 | static int tipc_ib_raw2addr(struct tipc_bearer *b, |
| 69 | struct tipc_media_addr *addr, |
Jakub Kicinski | 6cf8628 | 2021-10-12 08:58:39 -0700 | [diff] [blame] | 70 | const char *msg) |
Patrick McHardy | a29a194 | 2013-04-17 06:18:28 +0000 | [diff] [blame] | 71 | { |
Jon Paul Maloy | 38504c2 | 2014-05-14 05:39:13 -0400 | [diff] [blame] | 72 | memset(addr, 0, sizeof(*addr)); |
| 73 | memcpy(addr->value, msg, INFINIBAND_ALEN); |
| 74 | addr->media_id = TIPC_MEDIA_TYPE_IB; |
| 75 | addr->broadcast = !memcmp(msg, b->bcast_addr.value, |
| 76 | INFINIBAND_ALEN); |
Patrick McHardy | a29a194 | 2013-04-17 06:18:28 +0000 | [diff] [blame] | 77 | return 0; |
| 78 | } |
| 79 | |
Jon Paul Maloy | 38504c2 | 2014-05-14 05:39:13 -0400 | [diff] [blame] | 80 | /* Convert discovery msg addr format to InfiniBand media addr format */ |
| 81 | static int tipc_ib_msg2addr(struct tipc_bearer *b, |
| 82 | struct tipc_media_addr *addr, |
| 83 | char *msg) |
| 84 | { |
| 85 | return tipc_ib_raw2addr(b, addr, msg); |
| 86 | } |
| 87 | |
Ying Xue | e4d050c | 2013-12-10 20:45:43 -0800 | [diff] [blame] | 88 | /* InfiniBand media registration info */ |
Jon Paul Maloy | 5702dba | 2013-12-10 20:45:39 -0800 | [diff] [blame] | 89 | struct tipc_media ib_media_info = { |
Ying Xue | e4d050c | 2013-12-10 20:45:43 -0800 | [diff] [blame] | 90 | .send_msg = tipc_l2_send_msg, |
| 91 | .enable_media = tipc_enable_l2_media, |
| 92 | .disable_media = tipc_disable_l2_media, |
| 93 | .addr2str = tipc_ib_addr2str, |
| 94 | .addr2msg = tipc_ib_addr2msg, |
| 95 | .msg2addr = tipc_ib_msg2addr, |
Jon Paul Maloy | 38504c2 | 2014-05-14 05:39:13 -0400 | [diff] [blame] | 96 | .raw2addr = tipc_ib_raw2addr, |
Patrick McHardy | a29a194 | 2013-04-17 06:18:28 +0000 | [diff] [blame] | 97 | .priority = TIPC_DEF_LINK_PRI, |
| 98 | .tolerance = TIPC_DEF_LINK_TOL, |
Jon Maloy | 16ad3f4 | 2019-12-10 00:52:46 +0100 | [diff] [blame] | 99 | .min_win = TIPC_DEF_LINK_WIN, |
| 100 | .max_win = TIPC_MAX_IB_LINK_WIN, |
Patrick McHardy | a29a194 | 2013-04-17 06:18:28 +0000 | [diff] [blame] | 101 | .type_id = TIPC_MEDIA_TYPE_IB, |
Ying Xue | e4d050c | 2013-12-10 20:45:43 -0800 | [diff] [blame] | 102 | .hwaddr_len = INFINIBAND_ALEN, |
Patrick McHardy | a29a194 | 2013-04-17 06:18:28 +0000 | [diff] [blame] | 103 | .name = "ib" |
| 104 | }; |