* [PATCH RFC 0/5] tipc: add support for TIPC over InfiniBand @ 2013-04-03 12:43 Patrick McHardy 2013-04-03 12:43 ` [PATCH 2/5] tipc: move bcast_addr from struct tipc_media to struct tipc_bearer Patrick McHardy [not found] ` <1364993010-15515-1-git-send-email-kaber-dcUjhNyLwpNeoWH0uzbU5w@public.gmane.org> 0 siblings, 2 replies; 16+ messages in thread From: Patrick McHardy @ 2013-04-03 12:43 UTC (permalink / raw) To: jon.maloy Cc: allan.stephens, netdev, roland, sean.hefty, hal.rosenstock, linux-rdma The following patchset adds support for running TIPC over InfiniBand. The patchset consists of three parts (+ a minor fix for the ethernet media type): - Preparation: removal of an the unused str2addr callback and move of the bcast_addr from struct tipc_media to struct tipc_bearer. This is necessary because InfiniBand doesn't have a fixed broadcast address like ethernet, so it needs to be initialized with the device's broadcast address when the bearer is enabled - Introduction of a TIPC InfiniBand media type. A new media type is needed to deal with the different address sizes - Support for ETH_P_TIPC in IPoIB The last patch is something I'd like to discuss, I realize that this diverges from the IPoIB specification, however the alternative would be to implement something which would be pretty much identical to IPoIB with the only difference of handling a different ethertype in the xmit function. In fact I'd like to propose to remove all higher layer protocol knowledge from IPoIB except for ARP and RARP, which need special treatment. With the recent patch to manage neighbour entries in IPoIB itself, no further knowledge of higher layer protocols is required. The patchset is based on net-next. Comments welcome. ^ permalink raw reply [flat|nested] 16+ messages in thread
* [PATCH 2/5] tipc: move bcast_addr from struct tipc_media to struct tipc_bearer 2013-04-03 12:43 [PATCH RFC 0/5] tipc: add support for TIPC over InfiniBand Patrick McHardy @ 2013-04-03 12:43 ` Patrick McHardy [not found] ` <1364993010-15515-1-git-send-email-kaber-dcUjhNyLwpNeoWH0uzbU5w@public.gmane.org> 1 sibling, 0 replies; 16+ messages in thread From: Patrick McHardy @ 2013-04-03 12:43 UTC (permalink / raw) To: jon.maloy Cc: allan.stephens, netdev, roland, sean.hefty, hal.rosenstock, linux-rdma Some network protocols, like InfiniBand, don't have a fixed broadcast address but one that depends on the configuration. Move the bcast_addr to struct tipc_bearer and initialize it with the broadcast address of the network device when the bearer is enabled. Signed-off-by: Patrick McHardy <kaber@trash.net> --- net/tipc/bcast.c | 4 ++-- net/tipc/bearer.c | 5 +---- net/tipc/bearer.h | 5 +++-- net/tipc/discover.c | 2 +- net/tipc/eth_media.c | 18 +++++++++++------- 5 files changed, 18 insertions(+), 16 deletions(-) diff --git a/net/tipc/bcast.c b/net/tipc/bcast.c index 2655c9f..25e159c 100644 --- a/net/tipc/bcast.c +++ b/net/tipc/bcast.c @@ -620,10 +620,10 @@ static int tipc_bcbearer_send(struct sk_buff *buf, continue; /* bearer pair doesn't add anything */ if (!tipc_bearer_blocked(p)) - tipc_bearer_send(p, buf, &p->media->bcast_addr); + tipc_bearer_send(p, buf, &p->bcast_addr); else if (s && !tipc_bearer_blocked(s)) /* unable to send on primary bearer */ - tipc_bearer_send(s, buf, &s->media->bcast_addr); + tipc_bearer_send(s, buf, &s->bcast_addr); else /* unable to send on either bearer */ continue; diff --git a/net/tipc/bearer.c b/net/tipc/bearer.c index aa62f93..45d5398 100644 --- a/net/tipc/bearer.c +++ b/net/tipc/bearer.c @@ -89,9 +89,6 @@ int tipc_register_media(struct tipc_media *m_ptr) if ((strlen(m_ptr->name) + 1) > TIPC_MAX_MEDIA_NAME) goto exit; - if ((m_ptr->bcast_addr.media_id != m_ptr->type_id) || - !m_ptr->bcast_addr.broadcast) - goto exit; if (m_ptr->priority > TIPC_MAX_LINK_PRI) goto exit; if ((m_ptr->tolerance < TIPC_MIN_LINK_TOL) || @@ -407,7 +404,7 @@ restart: INIT_LIST_HEAD(&b_ptr->links); spin_lock_init(&b_ptr->lock); - res = tipc_disc_create(b_ptr, &m_ptr->bcast_addr, disc_domain); + res = tipc_disc_create(b_ptr, &b_ptr->bcast_addr, disc_domain); if (res) { bearer_disable(b_ptr); pr_warn("Bearer <%s> rejected, discovery object creation failed\n", diff --git a/net/tipc/bearer.h b/net/tipc/bearer.h index cc2d74e..3b3fa26 100644 --- a/net/tipc/bearer.h +++ b/net/tipc/bearer.h @@ -94,8 +94,8 @@ struct tipc_media { void (*disable_bearer)(struct tipc_bearer *b_ptr); int (*addr2str)(struct tipc_media_addr *a, char *str_buf, int str_size); int (*addr2msg)(struct tipc_media_addr *a, char *msg_area); - int (*msg2addr)(struct tipc_media_addr *a, char *msg_area); - struct tipc_media_addr bcast_addr; + int (*msg2addr)(const struct tipc_bearer *b_ptr, + struct tipc_media_addr *a, char *msg_area); u32 priority; u32 tolerance; u32 window; @@ -134,6 +134,7 @@ struct tipc_bearer { char name[TIPC_MAX_BEARER_NAME]; spinlock_t lock; struct tipc_media *media; + struct tipc_media_addr bcast_addr; u32 priority; u32 window; u32 tolerance; diff --git a/net/tipc/discover.c b/net/tipc/discover.c index 1074b95..eedff58 100644 --- a/net/tipc/discover.c +++ b/net/tipc/discover.c @@ -129,7 +129,7 @@ void tipc_disc_recv_msg(struct sk_buff *buf, struct tipc_bearer *b_ptr) int link_fully_up; media_addr.broadcast = 1; - b_ptr->media->msg2addr(&media_addr, msg_media_addr(msg)); + b_ptr->media->msg2addr(b_ptr, &media_addr, msg_media_addr(msg)); kfree_skb(buf); /* Ensure message from node is valid and communication is permitted */ diff --git a/net/tipc/eth_media.c b/net/tipc/eth_media.c index 1bdc6df..0648819 100644 --- a/net/tipc/eth_media.c +++ b/net/tipc/eth_media.c @@ -77,12 +77,13 @@ static struct notifier_block notifier = { * Media-dependent "value" field stores MAC address in first 6 bytes * and zeroes out the remaining bytes. */ -static void eth_media_addr_set(struct tipc_media_addr *a, char *mac) +static void eth_media_addr_set(const struct tipc_bearer *tb_ptr, + struct tipc_media_addr *a, char *mac) { memcpy(a->value, mac, ETH_ALEN); memset(a->value + ETH_ALEN, 0, sizeof(a->value) - ETH_ALEN); a->media_id = TIPC_MEDIA_TYPE_ETH; - a->broadcast = !memcmp(mac, eth_media_info.bcast_addr.value, ETH_ALEN); + a->broadcast = !memcmp(mac, tb_ptr->bcast_addr.value, ETH_ALEN); } /** @@ -201,9 +202,13 @@ static int enable_bearer(struct tipc_bearer *tb_ptr) /* Associate TIPC bearer with Ethernet bearer */ eb_ptr->bearer = tb_ptr; tb_ptr->usr_handle = (void *)eb_ptr; + memset(tb_ptr->bcast_addr.value, 0, sizeof(tb_ptr->bcast_addr.value)); + memcpy(tb_ptr->bcast_addr.value, dev->broadcast, ETH_ALEN); + tb_ptr->bcast_addr.media_id = TIPC_MEDIA_TYPE_ETH; + tb_ptr->bcast_addr.broadcast = 1; tb_ptr->mtu = dev->mtu; tb_ptr->blocked = 0; - eth_media_addr_set(&tb_ptr->addr, (char *)dev->dev_addr); + eth_media_addr_set(tb_ptr, &tb_ptr->addr, (char *)dev->dev_addr); return 0; } @@ -315,12 +320,13 @@ static int eth_addr2msg(struct tipc_media_addr *a, char *msg_area) /** * eth_str2addr - convert message header address format to Ethernet format */ -static int eth_msg2addr(struct tipc_media_addr *a, char *msg_area) +static int eth_msg2addr(const struct tipc_bearer *tb_ptr, + struct tipc_media_addr *a, char *msg_area) { if (msg_area[TIPC_MEDIA_TYPE_OFFSET] != TIPC_MEDIA_TYPE_ETH) return 1; - eth_media_addr_set(a, msg_area + ETH_ADDR_OFFSET); + eth_media_addr_set(tb_ptr, a, msg_area + ETH_ADDR_OFFSET); return 0; } @@ -334,8 +340,6 @@ static struct tipc_media eth_media_info = { .addr2str = eth_addr2str, .addr2msg = eth_addr2msg, .msg2addr = eth_msg2addr, - .bcast_addr = { { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff }, - TIPC_MEDIA_TYPE_ETH, 1 }, .priority = TIPC_DEF_LINK_PRI, .tolerance = TIPC_DEF_LINK_TOL, .window = TIPC_DEF_LINK_WIN, -- 1.8.1.4 ^ permalink raw reply related [flat|nested] 16+ messages in thread
[parent not found: <1364993010-15515-1-git-send-email-kaber-dcUjhNyLwpNeoWH0uzbU5w@public.gmane.org>]
* [PATCH 1/5] tipc: remove unused str2addr media callback [not found] ` <1364993010-15515-1-git-send-email-kaber-dcUjhNyLwpNeoWH0uzbU5w@public.gmane.org> @ 2013-04-03 12:43 ` Patrick McHardy 2013-04-03 12:43 ` [PATCH 3/5] tipc: set skb->protocol in eth_media packet transmission Patrick McHardy ` (3 subsequent siblings) 4 siblings, 0 replies; 16+ messages in thread From: Patrick McHardy @ 2013-04-03 12:43 UTC (permalink / raw) To: jon.maloy-IzeFyvvaP7pWk0Htik3J/w Cc: allan.stephens-CWA4WttNNZF54TAoqtyWWQ, netdev-u79uwXL29TY76Z2rM5mHXA, roland-DgEjT+Ai2ygdnm+yROfE0A, sean.hefty-ral2JQCrhuEAvxtiuMwx3w, hal.rosenstock-Re5JQEeQqe8AvxtiuMwx3w, linux-rdma-u79uwXL29TY76Z2rM5mHXA Signed-off-by: Patrick McHardy <kaber-dcUjhNyLwpNeoWH0uzbU5w@public.gmane.org> --- net/tipc/bearer.h | 2 -- net/tipc/eth_media.c | 20 -------------------- 2 files changed, 22 deletions(-) diff --git a/net/tipc/bearer.h b/net/tipc/bearer.h index 39f1192..cc2d74e 100644 --- a/net/tipc/bearer.h +++ b/net/tipc/bearer.h @@ -77,7 +77,6 @@ struct tipc_bearer; * @enable_bearer: routine which enables a bearer * @disable_bearer: routine which disables a bearer * @addr2str: routine which converts media address to string - * @str2addr: routine which converts media address from string * @addr2msg: routine which converts media address to protocol message area * @msg2addr: routine which converts media address from protocol message area * @bcast_addr: media address used in broadcasting @@ -94,7 +93,6 @@ struct tipc_media { int (*enable_bearer)(struct tipc_bearer *b_ptr); void (*disable_bearer)(struct tipc_bearer *b_ptr); int (*addr2str)(struct tipc_media_addr *a, char *str_buf, int str_size); - int (*str2addr)(struct tipc_media_addr *a, char *str_buf); int (*addr2msg)(struct tipc_media_addr *a, char *msg_area); int (*msg2addr)(struct tipc_media_addr *a, char *msg_area); struct tipc_media_addr bcast_addr; diff --git a/net/tipc/eth_media.c b/net/tipc/eth_media.c index 2132c1e..1bdc6df 100644 --- a/net/tipc/eth_media.c +++ b/net/tipc/eth_media.c @@ -302,25 +302,6 @@ static int eth_addr2str(struct tipc_media_addr *a, char *str_buf, int str_size) } /** - * eth_str2addr - convert string to Ethernet address - */ -static int eth_str2addr(struct tipc_media_addr *a, char *str_buf) -{ - char mac[ETH_ALEN]; - int r; - - r = sscanf(str_buf, "%02x:%02x:%02x:%02x:%02x:%02x", - (u32 *)&mac[0], (u32 *)&mac[1], (u32 *)&mac[2], - (u32 *)&mac[3], (u32 *)&mac[4], (u32 *)&mac[5]); - - if (r != ETH_ALEN) - return 1; - - eth_media_addr_set(a, mac); - return 0; -} - -/** * eth_str2addr - convert Ethernet address format to message header format */ static int eth_addr2msg(struct tipc_media_addr *a, char *msg_area) @@ -351,7 +332,6 @@ static struct tipc_media eth_media_info = { .enable_bearer = enable_bearer, .disable_bearer = disable_bearer, .addr2str = eth_addr2str, - .str2addr = eth_str2addr, .addr2msg = eth_addr2msg, .msg2addr = eth_msg2addr, .bcast_addr = { { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff }, -- 1.8.1.4 -- To unsubscribe from this list: send the line "unsubscribe linux-rdma" in the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org More majordomo info at http://vger.kernel.org/majordomo-info.html ^ permalink raw reply related [flat|nested] 16+ messages in thread
* [PATCH 3/5] tipc: set skb->protocol in eth_media packet transmission [not found] ` <1364993010-15515-1-git-send-email-kaber-dcUjhNyLwpNeoWH0uzbU5w@public.gmane.org> 2013-04-03 12:43 ` [PATCH 1/5] tipc: remove unused str2addr media callback Patrick McHardy @ 2013-04-03 12:43 ` Patrick McHardy 2013-04-03 12:43 ` [PATCH 4/5] tipc: add InfiniBand media type Patrick McHardy ` (2 subsequent siblings) 4 siblings, 0 replies; 16+ messages in thread From: Patrick McHardy @ 2013-04-03 12:43 UTC (permalink / raw) To: jon.maloy-IzeFyvvaP7pWk0Htik3J/w Cc: allan.stephens-CWA4WttNNZF54TAoqtyWWQ, netdev-u79uwXL29TY76Z2rM5mHXA, roland-DgEjT+Ai2ygdnm+yROfE0A, sean.hefty-ral2JQCrhuEAvxtiuMwx3w, hal.rosenstock-Re5JQEeQqe8AvxtiuMwx3w, linux-rdma-u79uwXL29TY76Z2rM5mHXA The skb->protocol field is used by packet classifiers and for AF_PACKET cooked format, TIPC needs to set it properly. Fixes packet classification and ethertype of 0x0000 in cooked captures: Out 20:c9:d0:43:12:d9 ethertype Unknown (0x0000), length 56: 0x0000: 5b50 0028 0000 30d4 0100 1000 0100 1001 [P.(..0......... 0x0010: 0000 03e8 0000 0001 20c9 d043 12d9 0000 ...........C.... 0x0020: 0000 0000 0000 0000 ........ Signed-off-by: Patrick McHardy <kaber-dcUjhNyLwpNeoWH0uzbU5w@public.gmane.org> --- net/tipc/eth_media.c | 1 + 1 file changed, 1 insertion(+) diff --git a/net/tipc/eth_media.c b/net/tipc/eth_media.c index 0648819..120a676 100644 --- a/net/tipc/eth_media.c +++ b/net/tipc/eth_media.c @@ -111,6 +111,7 @@ static int send_msg(struct sk_buff *buf, struct tipc_bearer *tb_ptr, skb_reset_network_header(clone); clone->dev = dev; + clone->protocol = htons(ETH_P_TIPC); dev_hard_header(clone, dev, ETH_P_TIPC, dest->value, dev->dev_addr, clone->len); dev_queue_xmit(clone); -- 1.8.1.4 -- To unsubscribe from this list: send the line "unsubscribe linux-rdma" in the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org More majordomo info at http://vger.kernel.org/majordomo-info.html ^ permalink raw reply related [flat|nested] 16+ messages in thread
* [PATCH 4/5] tipc: add InfiniBand media type [not found] ` <1364993010-15515-1-git-send-email-kaber-dcUjhNyLwpNeoWH0uzbU5w@public.gmane.org> 2013-04-03 12:43 ` [PATCH 1/5] tipc: remove unused str2addr media callback Patrick McHardy 2013-04-03 12:43 ` [PATCH 3/5] tipc: set skb->protocol in eth_media packet transmission Patrick McHardy @ 2013-04-03 12:43 ` Patrick McHardy 2013-04-03 14:41 ` Erik Hugne [not found] ` <1364993010-15515-5-git-send-email-kaber-dcUjhNyLwpNeoWH0uzbU5w@public.gmane.org> 2013-04-03 12:43 ` [PATCH 5/5] IPoIB: add support for TIPC protocol Patrick McHardy 2013-04-03 19:44 ` [PATCH RFC 0/5] tipc: add support for TIPC over InfiniBand Jon Maloy 4 siblings, 2 replies; 16+ messages in thread From: Patrick McHardy @ 2013-04-03 12:43 UTC (permalink / raw) To: jon.maloy-IzeFyvvaP7pWk0Htik3J/w Cc: allan.stephens-CWA4WttNNZF54TAoqtyWWQ, netdev-u79uwXL29TY76Z2rM5mHXA, roland-DgEjT+Ai2ygdnm+yROfE0A, sean.hefty-ral2JQCrhuEAvxtiuMwx3w, hal.rosenstock-Re5JQEeQqe8AvxtiuMwx3w, linux-rdma-u79uwXL29TY76Z2rM5mHXA Add InfiniBand media type based on the ethernet media type. The only real difference is that in case of InfiniBand, we need the entire 20 bytes of space reserved for media addresses, so the TIPC media type ID is not explicitly stored in the packet payload. Sample output of tipc-config: # tipc-config -v -addr -netid -nt=all -p -m -b -n -ls node address: <10.1.4> current network id: 4711 Type Lower Upper Port Identity Publication Scope 0 167776257 167776257 <10.1.1:1855512577> 1855512578 cluster 167776260 167776260 <10.1.4:1216454657> 1216454658 zone 1 1 1 <10.1.4:1216479235> 1216479236 node Ports: 1216479235: bound to {1,1} 1216454657: bound to {0,167776260} Media: eth ib Bearers: ib:ib0 Nodes known: <10.1.1>: up Link <broadcast-link> Window:20 packets RX packets:0 fragments:0/0 bundles:0/0 TX packets:0 fragments:0/0 bundles:0/0 RX naks:0 defs:0 dups:0 TX naks:0 acks:0 dups:0 Congestion bearer:0 link:0 Send queue max:0 avg:0 Link <10.1.4:ib0-10.1.1:ib0> ACTIVE MTU:2044 Priority:10 Tolerance:1500 ms Window:50 packets RX packets:80 fragments:0/0 bundles:0/0 TX packets:40 fragments:0/0 bundles:0/0 TX profile sample:22 packets average:54 octets 0-64:100% -256:0% -1024:0% -4096:0% -16384:0% -32768:0% -66000:0% RX states:410 probes:213 naks:0 defs:0 dups:0 TX states:410 probes:197 naks:0 acks:0 dups:0 Congestion bearer:0 link:0 Send queue max:1 avg:0 Signed-off-by: Patrick McHardy <kaber-dcUjhNyLwpNeoWH0uzbU5w@public.gmane.org> --- net/tipc/Kconfig | 7 + net/tipc/Makefile | 2 + net/tipc/bearer.c | 2 +- net/tipc/bearer.h | 9 ++ net/tipc/core.c | 14 +- net/tipc/ib_media.c | 387 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 6 files changed, 418 insertions(+), 3 deletions(-) create mode 100644 net/tipc/ib_media.c diff --git a/net/tipc/Kconfig b/net/tipc/Kconfig index 4f99600..900ee66 100644 --- a/net/tipc/Kconfig +++ b/net/tipc/Kconfig @@ -31,3 +31,10 @@ config TIPC_PORTS Setting this to a smaller value saves some memory, setting it to higher allows for more ports. + +config TIPC_MEDIA_IB + bool "InfiniBand media type support" + depends on INFINIBAND_IPOIB + help + Saying Y here will enable support for running TIPC on + IP-over-InfiniBand devices. diff --git a/net/tipc/Makefile b/net/tipc/Makefile index 6cd55d6..4df8e02 100644 --- a/net/tipc/Makefile +++ b/net/tipc/Makefile @@ -9,3 +9,5 @@ tipc-y += addr.o bcast.o bearer.o config.o \ name_distr.o subscr.o name_table.o net.o \ netlink.o node.o node_subscr.o port.o ref.o \ socket.o log.o eth_media.o + +tipc-$(CONFIG_TIPC_MEDIA_IB) += ib_media.o diff --git a/net/tipc/bearer.c b/net/tipc/bearer.c index 45d5398..cb29ef7 100644 --- a/net/tipc/bearer.c +++ b/net/tipc/bearer.c @@ -39,7 +39,7 @@ #include "bearer.h" #include "discover.h" -#define MAX_ADDR_STR 32 +#define MAX_ADDR_STR 60 static struct tipc_media *media_list[MAX_MEDIA]; static u32 media_count; diff --git a/net/tipc/bearer.h b/net/tipc/bearer.h index 3b3fa26..be68105 100644 --- a/net/tipc/bearer.h +++ b/net/tipc/bearer.h @@ -56,6 +56,7 @@ * Identifiers of supported TIPC media types */ #define TIPC_MEDIA_TYPE_ETH 1 +#define TIPC_MEDIA_TYPE_IB 2 /** * struct tipc_media_addr - destination address used by TIPC bearers @@ -174,6 +175,14 @@ int tipc_disable_bearer(const char *name); int tipc_eth_media_start(void); void tipc_eth_media_stop(void); +#ifdef CONFIG_TIPC_MEDIA_IB +int tipc_ib_media_start(void); +void tipc_ib_media_stop(void); +#else +int tipc_ib_media_start(void) { return 0; } +void tipc_ib_media_stop(void) { return; } +#endif + int tipc_media_set_priority(const char *name, u32 new_value); int tipc_media_set_window(const char *name, u32 new_value); void tipc_media_addr_printf(char *buf, int len, struct tipc_media_addr *a); diff --git a/net/tipc/core.c b/net/tipc/core.c index fc05cec..133aa4a 100644 --- a/net/tipc/core.c +++ b/net/tipc/core.c @@ -82,6 +82,7 @@ static void tipc_core_stop_net(void) { tipc_net_stop(); tipc_eth_media_stop(); + tipc_ib_media_stop(); } /** @@ -93,8 +94,17 @@ int tipc_core_start_net(unsigned long addr) tipc_net_start(addr); res = tipc_eth_media_start(); - if (res) - tipc_core_stop_net(); + if (res < 0) + goto err1; + res = tipc_ib_media_start(); + if (res < 0) + goto err2; + return res; + +err2: + tipc_eth_media_stop(); +err1: + tipc_core_stop_net(); return res; } diff --git a/net/tipc/ib_media.c b/net/tipc/ib_media.c new file mode 100644 index 0000000..2a2864c --- /dev/null +++ b/net/tipc/ib_media.c @@ -0,0 +1,387 @@ +/* + * net/tipc/ib_media.c: Infiniband bearer support for TIPC + * + * Copyright (c) 2013 Patrick McHardy <kaber-dcUjhNyLwpNeoWH0uzbU5w@public.gmane.org> + * + * Based on eth_media.c, which carries the following copyright notice: + * + * Copyright (c) 2001-2007, Ericsson AB + * Copyright (c) 2005-2008, 2011, Wind River Systems + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. 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. + * 3. Neither the names of the copyright holders nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * Alternatively, this software may be distributed under the terms of the + * GNU General Public License ("GPL") version 2 as published by the Free + * Software Foundation. + * + * 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 <linux/if_infiniband.h> +#include "core.h" +#include "bearer.h" + +#define MAX_IB_BEARERS MAX_BEARERS + +/** + * struct ib_bearer - Infiniband bearer data structure + * @bearer: ptr to associated "generic" bearer structure + * @dev: ptr to associated Infiniband network device + * @tipc_packet_type: used in binding TIPC to Infiniband driver + * @cleanup: work item used when disabling bearer + */ + +struct ib_bearer { + struct tipc_bearer *bearer; + struct net_device *dev; + struct packet_type tipc_packet_type; + struct work_struct setup; + struct work_struct cleanup; +}; + +static struct tipc_media ib_media_info; +static struct ib_bearer ib_bearers[MAX_IB_BEARERS]; +static int ib_started; + +/** + * ib_media_addr_set - initialize Infiniband media address structure + * + * Media-dependent "value" field stores MAC address in first 6 bytes + * and zeroes out the remaining bytes. + */ +static void ib_media_addr_set(const struct tipc_bearer *tb_ptr, + struct tipc_media_addr *a, char *mac) +{ + BUILD_BUG_ON(sizeof(a->value) < INFINIBAND_ALEN); + memcpy(a->value, mac, INFINIBAND_ALEN); + a->media_id = TIPC_MEDIA_TYPE_IB; + a->broadcast = !memcmp(mac, tb_ptr->bcast_addr.value, INFINIBAND_ALEN); +} + +/** + * send_msg - send a TIPC message out over an InfiniBand interface + */ +static int send_msg(struct sk_buff *buf, struct tipc_bearer *tb_ptr, + struct tipc_media_addr *dest) +{ + struct sk_buff *clone; + struct net_device *dev; + int delta; + + clone = skb_clone(buf, GFP_ATOMIC); + if (!clone) + return 0; + + dev = ((struct ib_bearer *)(tb_ptr->usr_handle))->dev; + delta = dev->hard_header_len - skb_headroom(buf); + + if ((delta > 0) && + pskb_expand_head(clone, SKB_DATA_ALIGN(delta), 0, GFP_ATOMIC)) { + kfree_skb(clone); + return 0; + } + + skb_reset_network_header(clone); + clone->dev = dev; + clone->protocol = htons(ETH_P_TIPC); + dev_hard_header(clone, dev, ETH_P_TIPC, dest->value, + dev->dev_addr, clone->len); + dev_queue_xmit(clone); + return 0; +} + +/** + * recv_msg - handle incoming TIPC message from an InfiniBand interface + * + * Accept only packets explicitly sent to this node, or broadcast packets; + * ignores packets sent using InfiniBand multicast, and traffic sent to other + * nodes (which can happen if interface is running in promiscuous mode). + */ +static int recv_msg(struct sk_buff *buf, struct net_device *dev, + struct packet_type *pt, struct net_device *orig_dev) +{ + struct ib_bearer *ib_ptr = (struct ib_bearer *)pt->af_packet_priv; + + if (!net_eq(dev_net(dev), &init_net)) { + kfree_skb(buf); + return 0; + } + + if (likely(ib_ptr->bearer)) { + if (likely(buf->pkt_type <= PACKET_BROADCAST)) { + buf->next = NULL; + tipc_recv_msg(buf, ib_ptr->bearer); + return 0; + } + } + kfree_skb(buf); + return 0; +} + +/** + * setup_bearer - setup association between InfiniBand bearer and interface + */ +static void setup_bearer(struct work_struct *work) +{ + struct ib_bearer *ib_ptr = + container_of(work, struct ib_bearer, setup); + + dev_add_pack(&ib_ptr->tipc_packet_type); +} + +/** + * enable_bearer - attach TIPC bearer to an InfiniBand interface + */ +static int enable_bearer(struct tipc_bearer *tb_ptr) +{ + struct net_device *dev = NULL; + struct net_device *pdev = NULL; + struct ib_bearer *ib_ptr = &ib_bearers[0]; + struct ib_bearer *stop = &ib_bearers[MAX_IB_BEARERS]; + char *driver_name = strchr((const char *)tb_ptr->name, ':') + 1; + int pending_dev = 0; + + /* Find unused InfiniBand bearer structure */ + while (ib_ptr->dev) { + if (!ib_ptr->bearer) + pending_dev++; + if (++ib_ptr == stop) + return pending_dev ? -EAGAIN : -EDQUOT; + } + + /* Find device with specified name */ + read_lock(&dev_base_lock); + for_each_netdev(&init_net, pdev) { + if (!strncmp(pdev->name, driver_name, IFNAMSIZ)) { + dev = pdev; + dev_hold(dev); + break; + } + } + read_unlock(&dev_base_lock); + if (!dev) + return -ENODEV; + + /* Create InfiniBand bearer for device */ + ib_ptr->dev = dev; + ib_ptr->tipc_packet_type.type = htons(ETH_P_TIPC); + ib_ptr->tipc_packet_type.dev = dev; + ib_ptr->tipc_packet_type.func = recv_msg; + ib_ptr->tipc_packet_type.af_packet_priv = ib_ptr; + INIT_LIST_HEAD(&(ib_ptr->tipc_packet_type.list)); + INIT_WORK(&ib_ptr->setup, setup_bearer); + schedule_work(&ib_ptr->setup); + + /* Associate TIPC bearer with InfiniBand bearer */ + ib_ptr->bearer = tb_ptr; + tb_ptr->usr_handle = (void *)ib_ptr; + memset(tb_ptr->bcast_addr.value, 0, sizeof(tb_ptr->bcast_addr.value)); + memcpy(tb_ptr->bcast_addr.value, dev->broadcast, INFINIBAND_ALEN); + tb_ptr->bcast_addr.media_id = TIPC_MEDIA_TYPE_IB; + tb_ptr->bcast_addr.broadcast = 1; + tb_ptr->mtu = dev->mtu; + tb_ptr->blocked = 0; + ib_media_addr_set(tb_ptr, &tb_ptr->addr, (char *)dev->dev_addr); + return 0; +} + +/** + * cleanup_bearer - break association between InfiniBand bearer and interface + * + * This routine must be invoked from a work queue because it can sleep. + */ +static void cleanup_bearer(struct work_struct *work) +{ + struct ib_bearer *ib_ptr = + container_of(work, struct ib_bearer, cleanup); + + dev_remove_pack(&ib_ptr->tipc_packet_type); + dev_put(ib_ptr->dev); + ib_ptr->dev = NULL; +} + +/** + * disable_bearer - detach TIPC bearer from an InfiniBand interface + * + * Mark InfiniBand bearer as inactive so that incoming buffers are thrown away, + * then get worker thread to complete bearer cleanup. (Can't do cleanup + * here because cleanup code needs to sleep and caller holds spinlocks.) + */ +static void disable_bearer(struct tipc_bearer *tb_ptr) +{ + struct ib_bearer *ib_ptr = (struct ib_bearer *)tb_ptr->usr_handle; + + ib_ptr->bearer = NULL; + INIT_WORK(&ib_ptr->cleanup, cleanup_bearer); + schedule_work(&ib_ptr->cleanup); +} + +/** + * recv_notification - handle device updates from OS + * + * Change the state of the InfiniBand bearer (if any) associated with the + * specified device. + */ +static int recv_notification(struct notifier_block *nb, unsigned long evt, + void *dv) +{ + struct net_device *dev = (struct net_device *)dv; + struct ib_bearer *ib_ptr = &ib_bearers[0]; + struct ib_bearer *stop = &ib_bearers[MAX_IB_BEARERS]; + + if (!net_eq(dev_net(dev), &init_net)) + return NOTIFY_DONE; + + while ((ib_ptr->dev != dev)) { + if (++ib_ptr == stop) + return NOTIFY_DONE; /* couldn't find device */ + } + if (!ib_ptr->bearer) + return NOTIFY_DONE; /* bearer had been disabled */ + + ib_ptr->bearer->mtu = dev->mtu; + + switch (evt) { + case NETDEV_CHANGE: + if (netif_carrier_ok(dev)) + tipc_continue(ib_ptr->bearer); + else + tipc_block_bearer(ib_ptr->bearer->name); + break; + case NETDEV_UP: + tipc_continue(ib_ptr->bearer); + break; + case NETDEV_DOWN: + tipc_block_bearer(ib_ptr->bearer->name); + break; + case NETDEV_CHANGEMTU: + case NETDEV_CHANGEADDR: + tipc_block_bearer(ib_ptr->bearer->name); + tipc_continue(ib_ptr->bearer); + break; + case NETDEV_UNREGISTER: + case NETDEV_CHANGENAME: + tipc_disable_bearer(ib_ptr->bearer->name); + break; + } + return NOTIFY_OK; +} + +static struct notifier_block notifier = { + .notifier_call = recv_notification, + .priority = 0, +}; + +/** + * ib_addr2str - convert InfiniBand address to string + */ +static int ib_addr2str(struct tipc_media_addr *a, char *str_buf, int str_size) +{ + if (str_size < 60) /* 60 = 19 * strlen("xx:") + strlen("xx\0") */ + return 1; + + sprintf(str_buf, "%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x:" + "%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x", + a->value[0], a->value[1], a->value[2], a->value[3], + a->value[4], a->value[5], a->value[6], a->value[7], + a->value[8], a->value[9], a->value[10], a->value[11], + a->value[12], a->value[13], a->value[14], a->value[15], + a->value[16], a->value[17], a->value[18], a->value[19]); + + return 0; +} + +/** + * ib_addr2msg - convert InfiniBand address format to message header format + */ +static int ib_addr2msg(struct tipc_media_addr *a, char *msg_area) +{ + memset(msg_area, 0, TIPC_MEDIA_ADDR_SIZE); + msg_area[TIPC_MEDIA_TYPE_OFFSET] = TIPC_MEDIA_TYPE_IB; + memcpy(msg_area, a->value, INFINIBAND_ALEN); + return 0; +} + +/** + * ib_msg2addr - convert message header address format to InfiniBand format + */ +static int ib_msg2addr(const struct tipc_bearer *tb_ptr, + struct tipc_media_addr *a, char *msg_area) +{ + ib_media_addr_set(tb_ptr, a, msg_area); + return 0; +} + +/* + * InfiniBand media registration info + */ +static struct tipc_media ib_media_info = { + .send_msg = send_msg, + .enable_bearer = enable_bearer, + .disable_bearer = disable_bearer, + .addr2str = ib_addr2str, + .addr2msg = ib_addr2msg, + .msg2addr = ib_msg2addr, + .priority = TIPC_DEF_LINK_PRI, + .tolerance = TIPC_DEF_LINK_TOL, + .window = TIPC_DEF_LINK_WIN, + .type_id = TIPC_MEDIA_TYPE_IB, + .name = "ib" +}; + +/** + * tipc_ib_media_start - activate InfiniBand bearer support + * + * Register InfiniBand media type with TIPC bearer code. Also register + * with OS for notifications about device state changes. + */ +int tipc_ib_media_start(void) +{ + int res; + + if (ib_started) + return -EINVAL; + + res = tipc_register_media(&ib_media_info); + if (res) + return res; + + res = register_netdevice_notifier(¬ifier); + if (!res) + ib_started = 1; + return res; +} + +/** + * tipc_ib_media_stop - deactivate InfiniBand bearer support + */ +void tipc_ib_media_stop(void) +{ + if (!ib_started) + return; + + flush_scheduled_work(); + unregister_netdevice_notifier(¬ifier); + ib_started = 0; +} -- 1.8.1.4 -- To unsubscribe from this list: send the line "unsubscribe linux-rdma" in the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org More majordomo info at http://vger.kernel.org/majordomo-info.html ^ permalink raw reply related [flat|nested] 16+ messages in thread
* Re: [PATCH 4/5] tipc: add InfiniBand media type 2013-04-03 12:43 ` [PATCH 4/5] tipc: add InfiniBand media type Patrick McHardy @ 2013-04-03 14:41 ` Erik Hugne 2013-04-03 14:49 ` Patrick McHardy [not found] ` <1364993010-15515-5-git-send-email-kaber-dcUjhNyLwpNeoWH0uzbU5w@public.gmane.org> 1 sibling, 1 reply; 16+ messages in thread From: Erik Hugne @ 2013-04-03 14:41 UTC (permalink / raw) To: Patrick McHardy Cc: jon.maloy, allan.stephens, netdev, roland, sean.hefty, hal.rosenstock, linux-rdma On Wed, Apr 03, 2013 at 02:43:29PM +0200, Patrick McHardy wrote: > diff --git a/net/tipc/Kconfig b/net/tipc/Kconfig > index 4f99600..900ee66 100644 > --- a/net/tipc/Kconfig > +++ b/net/tipc/Kconfig > @@ -31,3 +31,10 @@ config TIPC_PORTS > > Setting this to a smaller value saves some memory, > setting it to higher allows for more ports. > + > +config TIPC_MEDIA_IB > + bool "InfiniBand media type support" > + depends on INFINIBAND_IPOIB > + help > + Saying Y here will enable support for running TIPC on > + IP-over-InfiniBand devices. > diff --git a/net/tipc/Makefile b/net/tipc/Makefile > index 6cd55d6..4df8e02 100644 > --- a/net/tipc/Makefile > +++ b/net/tipc/Makefile > @@ -9,3 +9,5 @@ tipc-y += addr.o bcast.o bearer.o config.o \ > name_distr.o subscr.o name_table.o net.o \ > netlink.o node.o node_subscr.o port.o ref.o \ > socket.o log.o eth_media.o > + > +tipc-$(CONFIG_TIPC_MEDIA_IB) += ib_media.o The TIPC_MEDIA_IB option shows up directly under networking options, instead of under "TIPC". I think "depends on TIPC" is missing? //E ^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: [PATCH 4/5] tipc: add InfiniBand media type 2013-04-03 14:41 ` Erik Hugne @ 2013-04-03 14:49 ` Patrick McHardy 0 siblings, 0 replies; 16+ messages in thread From: Patrick McHardy @ 2013-04-03 14:49 UTC (permalink / raw) To: Erik Hugne Cc: jon.maloy, allan.stephens, netdev, roland, sean.hefty, hal.rosenstock, linux-rdma On Wed, Apr 03, 2013 at 04:41:40PM +0200, Erik Hugne wrote: > On Wed, Apr 03, 2013 at 02:43:29PM +0200, Patrick McHardy wrote: > > diff --git a/net/tipc/Kconfig b/net/tipc/Kconfig > > index 4f99600..900ee66 100644 > > --- a/net/tipc/Kconfig > > +++ b/net/tipc/Kconfig > > @@ -31,3 +31,10 @@ config TIPC_PORTS > > > > Setting this to a smaller value saves some memory, > > setting it to higher allows for more ports. > > + > > +config TIPC_MEDIA_IB > > + bool "InfiniBand media type support" > > + depends on INFINIBAND_IPOIB > > + help > > + Saying Y here will enable support for running TIPC on > > + IP-over-InfiniBand devices. > > diff --git a/net/tipc/Makefile b/net/tipc/Makefile > > index 6cd55d6..4df8e02 100644 > > --- a/net/tipc/Makefile > > +++ b/net/tipc/Makefile > > @@ -9,3 +9,5 @@ tipc-y += addr.o bcast.o bearer.o config.o \ > > name_distr.o subscr.o name_table.o net.o \ > > netlink.o node.o node_subscr.o port.o ref.o \ > > socket.o log.o eth_media.o > > + > > +tipc-$(CONFIG_TIPC_MEDIA_IB) += ib_media.o > > The TIPC_MEDIA_IB option shows up directly under networking options, > instead of under "TIPC". I think "depends on TIPC" is missing? Oops, I guess I messed that up during forward porting. I'll fix it up for the next submission, thanks. ^ permalink raw reply [flat|nested] 16+ messages in thread
[parent not found: <1364993010-15515-5-git-send-email-kaber-dcUjhNyLwpNeoWH0uzbU5w@public.gmane.org>]
* Re: [PATCH 4/5] tipc: add InfiniBand media type [not found] ` <1364993010-15515-5-git-send-email-kaber-dcUjhNyLwpNeoWH0uzbU5w@public.gmane.org> @ 2013-04-07 9:07 ` Ying Xue [not found] ` <51613740.6050501-CWA4WttNNZF54TAoqtyWWQ@public.gmane.org> 2013-04-07 9:19 ` Bart Van Assche 1 sibling, 1 reply; 16+ messages in thread From: Ying Xue @ 2013-04-07 9:07 UTC (permalink / raw) To: Patrick McHardy Cc: jon.maloy-IzeFyvvaP7pWk0Htik3J/w, allan.stephens-CWA4WttNNZF54TAoqtyWWQ, netdev-u79uwXL29TY76Z2rM5mHXA, roland-DgEjT+Ai2ygdnm+yROfE0A, sean.hefty-ral2JQCrhuEAvxtiuMwx3w, hal.rosenstock-Re5JQEeQqe8AvxtiuMwx3w, linux-rdma-u79uwXL29TY76Z2rM5mHXA > --- a/net/tipc/core.c > +++ b/net/tipc/core.c > @@ -82,6 +82,7 @@ static void tipc_core_stop_net(void) > { > tipc_net_stop(); > tipc_eth_media_stop(); > + tipc_ib_media_stop(); > } > > /** > @@ -93,8 +94,17 @@ int tipc_core_start_net(unsigned long addr) > > tipc_net_start(addr); > res = tipc_eth_media_start(); > - if (res) > - tipc_core_stop_net(); > + if (res < 0) > + goto err1; > + res = tipc_ib_media_start(); > + if (res < 0) > + goto err2; > + return res; > + > +err2: > + tipc_eth_media_stop(); Why do we need to call tipc_eth_media_stop() separately? In any failed case, we will finally invoke tipc_core_stop_net() which already places tipc_eth_media_stop(). > +err1: > + tipc_core_stop_net(); > return res; > } > Regards, Ying -- To unsubscribe from this list: send the line "unsubscribe linux-rdma" in the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org More majordomo info at http://vger.kernel.org/majordomo-info.html ^ permalink raw reply [flat|nested] 16+ messages in thread
[parent not found: <51613740.6050501-CWA4WttNNZF54TAoqtyWWQ@public.gmane.org>]
* Re: [PATCH 4/5] tipc: add InfiniBand media type [not found] ` <51613740.6050501-CWA4WttNNZF54TAoqtyWWQ@public.gmane.org> @ 2013-04-07 12:04 ` Patrick McHardy 0 siblings, 0 replies; 16+ messages in thread From: Patrick McHardy @ 2013-04-07 12:04 UTC (permalink / raw) To: Ying Xue Cc: jon.maloy-IzeFyvvaP7pWk0Htik3J/w, allan.stephens-CWA4WttNNZF54TAoqtyWWQ, netdev-u79uwXL29TY76Z2rM5mHXA, roland-DgEjT+Ai2ygdnm+yROfE0A, sean.hefty-ral2JQCrhuEAvxtiuMwx3w, hal.rosenstock-Re5JQEeQqe8AvxtiuMwx3w, linux-rdma-u79uwXL29TY76Z2rM5mHXA On Sun, Apr 07, 2013 at 05:07:12PM +0800, Ying Xue wrote: > > > --- a/net/tipc/core.c > > +++ b/net/tipc/core.c > > @@ -82,6 +82,7 @@ static void tipc_core_stop_net(void) > > { > > tipc_net_stop(); > > tipc_eth_media_stop(); > > + tipc_ib_media_stop(); > > } > > > > /** > > @@ -93,8 +94,17 @@ int tipc_core_start_net(unsigned long addr) > > > > tipc_net_start(addr); > > res = tipc_eth_media_start(); > > - if (res) > > - tipc_core_stop_net(); > > + if (res < 0) > > + goto err1; > > + res = tipc_ib_media_start(); > > + if (res < 0) > > + goto err2; > > + return res; > > + > > +err2: > > + tipc_eth_media_stop(); > > Why do we need to call tipc_eth_media_stop() separately? > In any failed case, we will finally invoke tipc_core_stop_net() which > already places tipc_eth_media_stop(). Right, that's not necessary, although I think its cleaner to do have error handling just be the opposite of initialization, IOW calling tipc_net_stop() instead of tipc_core_stop_net(). But I don't care much either way, will fix this up for the next submission, thanks. > > > +err1: > > + tipc_core_stop_net(); > > return res; > > } > > > > Regards, > Ying -- To unsubscribe from this list: send the line "unsubscribe linux-rdma" in the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org More majordomo info at http://vger.kernel.org/majordomo-info.html ^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: [PATCH 4/5] tipc: add InfiniBand media type [not found] ` <1364993010-15515-5-git-send-email-kaber-dcUjhNyLwpNeoWH0uzbU5w@public.gmane.org> 2013-04-07 9:07 ` Ying Xue @ 2013-04-07 9:19 ` Bart Van Assche 2013-04-07 9:43 ` Patrick McHardy 1 sibling, 1 reply; 16+ messages in thread From: Bart Van Assche @ 2013-04-07 9:19 UTC (permalink / raw) To: Patrick McHardy Cc: jon.maloy-IzeFyvvaP7pWk0Htik3J/w, allan.stephens-CWA4WttNNZF54TAoqtyWWQ, netdev-u79uwXL29TY76Z2rM5mHXA, roland-DgEjT+Ai2ygdnm+yROfE0A, sean.hefty-ral2JQCrhuEAvxtiuMwx3w, hal.rosenstock-Re5JQEeQqe8AvxtiuMwx3w, linux-rdma-u79uwXL29TY76Z2rM5mHXA On 04/03/13 14:43, Patrick McHardy wrote: > diff --git a/net/tipc/bearer.h b/net/tipc/bearer.h > +#ifdef CONFIG_TIPC_MEDIA_IB > +int tipc_ib_media_start(void); > +void tipc_ib_media_stop(void); > +#else > +int tipc_ib_media_start(void) { return 0; } > +void tipc_ib_media_stop(void) { return; } > +#endif Is the above a definition of a non-inline function pair in a header file ? I'm afraid that will cause trouble when including that header file in more than one source file. Bart. -- To unsubscribe from this list: send the line "unsubscribe linux-rdma" in the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org More majordomo info at http://vger.kernel.org/majordomo-info.html ^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: [PATCH 4/5] tipc: add InfiniBand media type 2013-04-07 9:19 ` Bart Van Assche @ 2013-04-07 9:43 ` Patrick McHardy 0 siblings, 0 replies; 16+ messages in thread From: Patrick McHardy @ 2013-04-07 9:43 UTC (permalink / raw) To: Bart Van Assche Cc: jon.maloy, allan.stephens, netdev, roland, sean.hefty, hal.rosenstock, linux-rdma On Sun, Apr 07, 2013 at 11:19:06AM +0200, Bart Van Assche wrote: > On 04/03/13 14:43, Patrick McHardy wrote: > >diff --git a/net/tipc/bearer.h b/net/tipc/bearer.h > >+#ifdef CONFIG_TIPC_MEDIA_IB > >+int tipc_ib_media_start(void); > >+void tipc_ib_media_stop(void); > >+#else > >+int tipc_ib_media_start(void) { return 0; } > >+void tipc_ib_media_stop(void) { return; } > >+#endif > > Is the above a definition of a non-inline function pair in a header > file ? I'm afraid that will cause trouble when including that header > file in more than one source file. Oops right, I'll fix that up. ^ permalink raw reply [flat|nested] 16+ messages in thread
* [PATCH 5/5] IPoIB: add support for TIPC protocol [not found] ` <1364993010-15515-1-git-send-email-kaber-dcUjhNyLwpNeoWH0uzbU5w@public.gmane.org> ` (2 preceding siblings ...) 2013-04-03 12:43 ` [PATCH 4/5] tipc: add InfiniBand media type Patrick McHardy @ 2013-04-03 12:43 ` Patrick McHardy [not found] ` <1364993010-15515-6-git-send-email-kaber-dcUjhNyLwpNeoWH0uzbU5w@public.gmane.org> 2013-04-03 19:44 ` [PATCH RFC 0/5] tipc: add support for TIPC over InfiniBand Jon Maloy 4 siblings, 1 reply; 16+ messages in thread From: Patrick McHardy @ 2013-04-03 12:43 UTC (permalink / raw) To: jon.maloy-IzeFyvvaP7pWk0Htik3J/w Cc: allan.stephens-CWA4WttNNZF54TAoqtyWWQ, netdev-u79uwXL29TY76Z2rM5mHXA, roland-DgEjT+Ai2ygdnm+yROfE0A, sean.hefty-ral2JQCrhuEAvxtiuMwx3w, hal.rosenstock-Re5JQEeQqe8AvxtiuMwx3w, linux-rdma-u79uwXL29TY76Z2rM5mHXA Support TIPC in the IPoIB driver. Since IPoIB now keeps track of its own neighbour entries and doesn't require the packet to have a dst_entry anymore, the only necessary changes are to: - not drop multicast TIPC packets because of the unknown ethernet type - handle unicast TIPC packets similar to IPv4/IPv6 unicast packets in ipoib_start_xmit(). An alternative would be to remove all ethertype limitations since they're not necessary anymore, all TIPC needs to know about is ARP and RARP since it wants to always perform "path find", even if a path is already known. Signed-off-by: Patrick McHardy <kaber-dcUjhNyLwpNeoWH0uzbU5w@public.gmane.org> --- drivers/infiniband/ulp/ipoib/ipoib_main.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/drivers/infiniband/ulp/ipoib/ipoib_main.c b/drivers/infiniband/ulp/ipoib/ipoib_main.c index 8534afd..554b906 100644 --- a/drivers/infiniband/ulp/ipoib/ipoib_main.c +++ b/drivers/infiniband/ulp/ipoib/ipoib_main.c @@ -730,7 +730,8 @@ static int ipoib_start_xmit(struct sk_buff *skb, struct net_device *dev) if ((header->proto != htons(ETH_P_IP)) && (header->proto != htons(ETH_P_IPV6)) && (header->proto != htons(ETH_P_ARP)) && - (header->proto != htons(ETH_P_RARP))) { + (header->proto != htons(ETH_P_RARP)) && + (header->proto != htons(ETH_P_TIPC))) { /* ethertype not supported by IPoIB */ ++dev->stats.tx_dropped; dev_kfree_skb_any(skb); @@ -751,6 +752,7 @@ static int ipoib_start_xmit(struct sk_buff *skb, struct net_device *dev) switch (header->proto) { case htons(ETH_P_IP): case htons(ETH_P_IPV6): + case htons(ETH_P_TIPC): neigh = ipoib_neigh_get(dev, cb->hwaddr); if (unlikely(!neigh)) { neigh_add_path(skb, cb->hwaddr, dev); -- 1.8.1.4 -- To unsubscribe from this list: send the line "unsubscribe linux-rdma" in the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org More majordomo info at http://vger.kernel.org/majordomo-info.html ^ permalink raw reply related [flat|nested] 16+ messages in thread
[parent not found: <1364993010-15515-6-git-send-email-kaber-dcUjhNyLwpNeoWH0uzbU5w@public.gmane.org>]
* Re: [PATCH 5/5] IPoIB: add support for TIPC protocol [not found] ` <1364993010-15515-6-git-send-email-kaber-dcUjhNyLwpNeoWH0uzbU5w@public.gmane.org> @ 2013-04-03 15:31 ` Or Gerlitz 2013-04-03 15:44 ` Patrick McHardy 0 siblings, 1 reply; 16+ messages in thread From: Or Gerlitz @ 2013-04-03 15:31 UTC (permalink / raw) To: Patrick McHardy Cc: jon.maloy-IzeFyvvaP7pWk0Htik3J/w, allan.stephens-CWA4WttNNZF54TAoqtyWWQ, netdev-u79uwXL29TY76Z2rM5mHXA, roland-DgEjT+Ai2ygdnm+yROfE0A, sean.hefty-ral2JQCrhuEAvxtiuMwx3w, hal.rosenstock-Re5JQEeQqe8AvxtiuMwx3w, linux-rdma-u79uwXL29TY76Z2rM5mHXA On 03/04/2013 15:43, Patrick McHardy wrote: > [...] all TIPC needs to know about is ARP and RARP since > it wants to always perform "path find", even if a path is already known. [...] Not sure to follow this part... did you mean "all IPoIB needs to know about is ARP or RARP", this makes sense indeed, since for arp/rarp we want to call unicast_arp_send which does path_find and looks also for the case the path isn't valid Or. -- To unsubscribe from this list: send the line "unsubscribe linux-rdma" in the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org More majordomo info at http://vger.kernel.org/majordomo-info.html ^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: [PATCH 5/5] IPoIB: add support for TIPC protocol 2013-04-03 15:31 ` Or Gerlitz @ 2013-04-03 15:44 ` Patrick McHardy 0 siblings, 0 replies; 16+ messages in thread From: Patrick McHardy @ 2013-04-03 15:44 UTC (permalink / raw) To: Or Gerlitz Cc: jon.maloy, allan.stephens, netdev, roland, sean.hefty, hal.rosenstock, linux-rdma On Wed, Apr 03, 2013 at 06:31:49PM +0300, Or Gerlitz wrote: > On 03/04/2013 15:43, Patrick McHardy wrote: > >[...] all TIPC needs to know about is ARP and RARP since > >it wants to always perform "path find", even if a path is already known. [...] > > Not sure to follow this part... did you mean "all IPoIB needs to > know about is ARP or RARP", this makes > sense indeed, since for arp/rarp we want to call unicast_arp_send > which does path_find and looks > also for the case the path isn't valid What I meant is that it doesn't require any knowledge about IPv4/IPv6 or other higher layer protocols anymore. At least almost none. We have protocol knowledge in ipoib_start_xmit(). For broadcast packets, it drops unknown protocols. For unicast packets, it handles ARP/RARP seperately because of the path find differences, IP/IPv6 are sent using the neigh, all others are dropped. ipoib_cm also has knowledge about IPv4/IPv6 in order to send ICMP errors. What we could do instead of adding TIPC to the broadcast-don't-drop list and to the send-using-neigh list in ipoib_start_xmit() is to only treat ARP/RARP special and send every other protocol using the neigh or ipoib_mcast_send(). Right now the supported protocols are artificially limited without a technical reason. ^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: [PATCH RFC 0/5] tipc: add support for TIPC over InfiniBand [not found] ` <1364993010-15515-1-git-send-email-kaber-dcUjhNyLwpNeoWH0uzbU5w@public.gmane.org> ` (3 preceding siblings ...) 2013-04-03 12:43 ` [PATCH 5/5] IPoIB: add support for TIPC protocol Patrick McHardy @ 2013-04-03 19:44 ` Jon Maloy 4 siblings, 0 replies; 16+ messages in thread From: Jon Maloy @ 2013-04-03 19:44 UTC (permalink / raw) To: Patrick McHardy Cc: allan.stephens-CWA4WttNNZF54TAoqtyWWQ, netdev-u79uwXL29TY76Z2rM5mHXA, roland-DgEjT+Ai2ygdnm+yROfE0A, sean.hefty-ral2JQCrhuEAvxtiuMwx3w, hal.rosenstock-Re5JQEeQqe8AvxtiuMwx3w, linux-rdma-u79uwXL29TY76Z2rM5mHXA, Paul.Gortmaker-CWA4WttNNZF54TAoqtyWWQ@public.gmane.org On 04/03/2013 08:43 AM, Patrick McHardy wrote: > The following patchset adds support for running TIPC over InfiniBand. > The patchset consists of three parts (+ a minor fix for the ethernet media > type): > > - Preparation: removal of an the unused str2addr callback and move of the > bcast_addr from struct tipc_media to struct tipc_bearer. This is necessary > because InfiniBand doesn't have a fixed broadcast address like ethernet, > so it needs to be initialized with the device's broadcast address when > the bearer is enabled > > - Introduction of a TIPC InfiniBand media type. A new media type is needed > to deal with the different address sizes > > - Support for ETH_P_TIPC in IPoIB > > The last patch is something I'd like to discuss, I realize that this diverges > from the IPoIB specification, however the alternative would be to implement > something which would be pretty much identical to IPoIB with the only > difference of handling a different ethertype in the xmit function. > > In fact I'd like to propose to remove all higher layer protocol knowledge > from IPoIB except for ARP and RARP, which need special treatment. With the > recent patch to manage neighbour entries in IPoIB itself, no further knowledge > of higher layer protocols is required. > > The patchset is based on net-next. > > Comments welcome. > Happy to see this initiative being taken. It seems to me that you have grasped our intentions for how to add a new bearer, so I really don't have much comments, except the one already made by Erik. To me it looks good. Regards ///jon -- To unsubscribe from this list: send the line "unsubscribe linux-rdma" in the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org More majordomo info at http://vger.kernel.org/majordomo-info.html ^ permalink raw reply [flat|nested] 16+ messages in thread
* [PATCH v2 0/5] tipc: add TIPC over Infiniband support @ 2013-04-17 16:18 Patrick McHardy 2013-04-17 16:18 ` [PATCH 4/5] tipc: add InfiniBand media type Patrick McHardy 0 siblings, 1 reply; 16+ messages in thread From: Patrick McHardy @ 2013-04-17 16:18 UTC (permalink / raw) To: jon.maloy-IzeFyvvaP7pWk0Htik3J/w Cc: davem-fT/PcQaiUtIeIZ0/mPfg9Q, allan.stephens-CWA4WttNNZF54TAoqtyWWQ, netdev-u79uwXL29TY76Z2rM5mHXA, roland-DgEjT+Ai2ygdnm+yROfE0A, sean.hefty-ral2JQCrhuEAvxtiuMwx3w, hal.rosenstock-Re5JQEeQqe8AvxtiuMwx3w, linux-rdma-u79uwXL29TY76Z2rM5mHXA The following patchset adds support for running TIPC over InfiniBand. The patchset consists of three parts (+ a minor fix for the ethernet media type): - Preparation: removal of an the unused str2addr callback and move of the bcast_addr from struct tipc_media to struct tipc_bearer. This is necessary because InfiniBand doesn't have a fixed broadcast address like ethernet, so it needs to be initialized with the device's broadcast address when the bearer is enabled - Introduction of a TIPC InfiniBand media type. A new media type is needed to deal with the different address sizes - Support for ETH_P_TIPC in IPoIB Since the last posting I've addressed all feedback I received and rebased to the current net-next tree. I consider these patches ready for merging. Since they mainly affect TIPC code, I'd propose to have them either go through the TIPC tree or through Dave directly (not sure how TIPC patches are managed). -- To unsubscribe from this list: send the line "unsubscribe linux-rdma" in the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org More majordomo info at http://vger.kernel.org/majordomo-info.html ^ permalink raw reply [flat|nested] 16+ messages in thread
* [PATCH 4/5] tipc: add InfiniBand media type 2013-04-17 16:18 [PATCH v2 0/5] tipc: add TIPC over Infiniband support Patrick McHardy @ 2013-04-17 16:18 ` Patrick McHardy 0 siblings, 0 replies; 16+ messages in thread From: Patrick McHardy @ 2013-04-17 16:18 UTC (permalink / raw) To: jon.maloy Cc: davem, allan.stephens, netdev, roland, sean.hefty, hal.rosenstock, linux-rdma Add InfiniBand media type based on the ethernet media type. The only real difference is that in case of InfiniBand, we need the entire 20 bytes of space reserved for media addresses, so the TIPC media type ID is not explicitly stored in the packet payload. Sample output of tipc-config: # tipc-config -v -addr -netid -nt=all -p -m -b -n -ls node address: <10.1.4> current network id: 4711 Type Lower Upper Port Identity Publication Scope 0 167776257 167776257 <10.1.1:1855512577> 1855512578 cluster 167776260 167776260 <10.1.4:1216454657> 1216454658 zone 1 1 1 <10.1.4:1216479235> 1216479236 node Ports: 1216479235: bound to {1,1} 1216454657: bound to {0,167776260} Media: eth ib Bearers: ib:ib0 Nodes known: <10.1.1>: up Link <broadcast-link> Window:20 packets RX packets:0 fragments:0/0 bundles:0/0 TX packets:0 fragments:0/0 bundles:0/0 RX naks:0 defs:0 dups:0 TX naks:0 acks:0 dups:0 Congestion bearer:0 link:0 Send queue max:0 avg:0 Link <10.1.4:ib0-10.1.1:ib0> ACTIVE MTU:2044 Priority:10 Tolerance:1500 ms Window:50 packets RX packets:80 fragments:0/0 bundles:0/0 TX packets:40 fragments:0/0 bundles:0/0 TX profile sample:22 packets average:54 octets 0-64:100% -256:0% -1024:0% -4096:0% -16384:0% -32768:0% -66000:0% RX states:410 probes:213 naks:0 defs:0 dups:0 TX states:410 probes:197 naks:0 acks:0 dups:0 Congestion bearer:0 link:0 Send queue max:1 avg:0 Signed-off-by: Patrick McHardy <kaber@trash.net> --- net/tipc/Kconfig | 7 + net/tipc/Makefile | 2 + net/tipc/bearer.c | 2 +- net/tipc/bearer.h | 9 ++ net/tipc/core.c | 12 +- net/tipc/ib_media.c | 387 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 6 files changed, 416 insertions(+), 3 deletions(-) create mode 100644 net/tipc/ib_media.c diff --git a/net/tipc/Kconfig b/net/tipc/Kconfig index 4f99600..c890848 100644 --- a/net/tipc/Kconfig +++ b/net/tipc/Kconfig @@ -31,3 +31,10 @@ config TIPC_PORTS Setting this to a smaller value saves some memory, setting it to higher allows for more ports. + +config TIPC_MEDIA_IB + bool "InfiniBand media type support" + depends on TIPC && INFINIBAND_IPOIB + help + Saying Y here will enable support for running TIPC on + IP-over-InfiniBand devices. diff --git a/net/tipc/Makefile b/net/tipc/Makefile index 6cd55d6..4df8e02 100644 --- a/net/tipc/Makefile +++ b/net/tipc/Makefile @@ -9,3 +9,5 @@ tipc-y += addr.o bcast.o bearer.o config.o \ name_distr.o subscr.o name_table.o net.o \ netlink.o node.o node_subscr.o port.o ref.o \ socket.o log.o eth_media.o + +tipc-$(CONFIG_TIPC_MEDIA_IB) += ib_media.o diff --git a/net/tipc/bearer.c b/net/tipc/bearer.c index 45d5398..cb29ef7 100644 --- a/net/tipc/bearer.c +++ b/net/tipc/bearer.c @@ -39,7 +39,7 @@ #include "bearer.h" #include "discover.h" -#define MAX_ADDR_STR 32 +#define MAX_ADDR_STR 60 static struct tipc_media *media_list[MAX_MEDIA]; static u32 media_count; diff --git a/net/tipc/bearer.h b/net/tipc/bearer.h index 3b3fa26..09c869a 100644 --- a/net/tipc/bearer.h +++ b/net/tipc/bearer.h @@ -56,6 +56,7 @@ * Identifiers of supported TIPC media types */ #define TIPC_MEDIA_TYPE_ETH 1 +#define TIPC_MEDIA_TYPE_IB 2 /** * struct tipc_media_addr - destination address used by TIPC bearers @@ -174,6 +175,14 @@ int tipc_disable_bearer(const char *name); int tipc_eth_media_start(void); void tipc_eth_media_stop(void); +#ifdef CONFIG_TIPC_MEDIA_IB +int tipc_ib_media_start(void); +void tipc_ib_media_stop(void); +#else +static inline int tipc_ib_media_start(void) { return 0; } +static inline void tipc_ib_media_stop(void) { return; } +#endif + int tipc_media_set_priority(const char *name, u32 new_value); int tipc_media_set_window(const char *name, u32 new_value); void tipc_media_addr_printf(char *buf, int len, struct tipc_media_addr *a); diff --git a/net/tipc/core.c b/net/tipc/core.c index fc05cec..7ec2c1e 100644 --- a/net/tipc/core.c +++ b/net/tipc/core.c @@ -82,6 +82,7 @@ static void tipc_core_stop_net(void) { tipc_net_stop(); tipc_eth_media_stop(); + tipc_ib_media_stop(); } /** @@ -93,8 +94,15 @@ int tipc_core_start_net(unsigned long addr) tipc_net_start(addr); res = tipc_eth_media_start(); - if (res) - tipc_core_stop_net(); + if (res < 0) + goto err; + res = tipc_ib_media_start(); + if (res < 0) + goto err; + return res; + +err: + tipc_core_stop_net(); return res; } diff --git a/net/tipc/ib_media.c b/net/tipc/ib_media.c new file mode 100644 index 0000000..2a2864c --- /dev/null +++ b/net/tipc/ib_media.c @@ -0,0 +1,387 @@ +/* + * net/tipc/ib_media.c: Infiniband bearer support for TIPC + * + * Copyright (c) 2013 Patrick McHardy <kaber@trash.net> + * + * Based on eth_media.c, which carries the following copyright notice: + * + * Copyright (c) 2001-2007, Ericsson AB + * Copyright (c) 2005-2008, 2011, Wind River Systems + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. 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. + * 3. Neither the names of the copyright holders nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * Alternatively, this software may be distributed under the terms of the + * GNU General Public License ("GPL") version 2 as published by the Free + * Software Foundation. + * + * 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 <linux/if_infiniband.h> +#include "core.h" +#include "bearer.h" + +#define MAX_IB_BEARERS MAX_BEARERS + +/** + * struct ib_bearer - Infiniband bearer data structure + * @bearer: ptr to associated "generic" bearer structure + * @dev: ptr to associated Infiniband network device + * @tipc_packet_type: used in binding TIPC to Infiniband driver + * @cleanup: work item used when disabling bearer + */ + +struct ib_bearer { + struct tipc_bearer *bearer; + struct net_device *dev; + struct packet_type tipc_packet_type; + struct work_struct setup; + struct work_struct cleanup; +}; + +static struct tipc_media ib_media_info; +static struct ib_bearer ib_bearers[MAX_IB_BEARERS]; +static int ib_started; + +/** + * ib_media_addr_set - initialize Infiniband media address structure + * + * Media-dependent "value" field stores MAC address in first 6 bytes + * and zeroes out the remaining bytes. + */ +static void ib_media_addr_set(const struct tipc_bearer *tb_ptr, + struct tipc_media_addr *a, char *mac) +{ + BUILD_BUG_ON(sizeof(a->value) < INFINIBAND_ALEN); + memcpy(a->value, mac, INFINIBAND_ALEN); + a->media_id = TIPC_MEDIA_TYPE_IB; + a->broadcast = !memcmp(mac, tb_ptr->bcast_addr.value, INFINIBAND_ALEN); +} + +/** + * send_msg - send a TIPC message out over an InfiniBand interface + */ +static int send_msg(struct sk_buff *buf, struct tipc_bearer *tb_ptr, + struct tipc_media_addr *dest) +{ + struct sk_buff *clone; + struct net_device *dev; + int delta; + + clone = skb_clone(buf, GFP_ATOMIC); + if (!clone) + return 0; + + dev = ((struct ib_bearer *)(tb_ptr->usr_handle))->dev; + delta = dev->hard_header_len - skb_headroom(buf); + + if ((delta > 0) && + pskb_expand_head(clone, SKB_DATA_ALIGN(delta), 0, GFP_ATOMIC)) { + kfree_skb(clone); + return 0; + } + + skb_reset_network_header(clone); + clone->dev = dev; + clone->protocol = htons(ETH_P_TIPC); + dev_hard_header(clone, dev, ETH_P_TIPC, dest->value, + dev->dev_addr, clone->len); + dev_queue_xmit(clone); + return 0; +} + +/** + * recv_msg - handle incoming TIPC message from an InfiniBand interface + * + * Accept only packets explicitly sent to this node, or broadcast packets; + * ignores packets sent using InfiniBand multicast, and traffic sent to other + * nodes (which can happen if interface is running in promiscuous mode). + */ +static int recv_msg(struct sk_buff *buf, struct net_device *dev, + struct packet_type *pt, struct net_device *orig_dev) +{ + struct ib_bearer *ib_ptr = (struct ib_bearer *)pt->af_packet_priv; + + if (!net_eq(dev_net(dev), &init_net)) { + kfree_skb(buf); + return 0; + } + + if (likely(ib_ptr->bearer)) { + if (likely(buf->pkt_type <= PACKET_BROADCAST)) { + buf->next = NULL; + tipc_recv_msg(buf, ib_ptr->bearer); + return 0; + } + } + kfree_skb(buf); + return 0; +} + +/** + * setup_bearer - setup association between InfiniBand bearer and interface + */ +static void setup_bearer(struct work_struct *work) +{ + struct ib_bearer *ib_ptr = + container_of(work, struct ib_bearer, setup); + + dev_add_pack(&ib_ptr->tipc_packet_type); +} + +/** + * enable_bearer - attach TIPC bearer to an InfiniBand interface + */ +static int enable_bearer(struct tipc_bearer *tb_ptr) +{ + struct net_device *dev = NULL; + struct net_device *pdev = NULL; + struct ib_bearer *ib_ptr = &ib_bearers[0]; + struct ib_bearer *stop = &ib_bearers[MAX_IB_BEARERS]; + char *driver_name = strchr((const char *)tb_ptr->name, ':') + 1; + int pending_dev = 0; + + /* Find unused InfiniBand bearer structure */ + while (ib_ptr->dev) { + if (!ib_ptr->bearer) + pending_dev++; + if (++ib_ptr == stop) + return pending_dev ? -EAGAIN : -EDQUOT; + } + + /* Find device with specified name */ + read_lock(&dev_base_lock); + for_each_netdev(&init_net, pdev) { + if (!strncmp(pdev->name, driver_name, IFNAMSIZ)) { + dev = pdev; + dev_hold(dev); + break; + } + } + read_unlock(&dev_base_lock); + if (!dev) + return -ENODEV; + + /* Create InfiniBand bearer for device */ + ib_ptr->dev = dev; + ib_ptr->tipc_packet_type.type = htons(ETH_P_TIPC); + ib_ptr->tipc_packet_type.dev = dev; + ib_ptr->tipc_packet_type.func = recv_msg; + ib_ptr->tipc_packet_type.af_packet_priv = ib_ptr; + INIT_LIST_HEAD(&(ib_ptr->tipc_packet_type.list)); + INIT_WORK(&ib_ptr->setup, setup_bearer); + schedule_work(&ib_ptr->setup); + + /* Associate TIPC bearer with InfiniBand bearer */ + ib_ptr->bearer = tb_ptr; + tb_ptr->usr_handle = (void *)ib_ptr; + memset(tb_ptr->bcast_addr.value, 0, sizeof(tb_ptr->bcast_addr.value)); + memcpy(tb_ptr->bcast_addr.value, dev->broadcast, INFINIBAND_ALEN); + tb_ptr->bcast_addr.media_id = TIPC_MEDIA_TYPE_IB; + tb_ptr->bcast_addr.broadcast = 1; + tb_ptr->mtu = dev->mtu; + tb_ptr->blocked = 0; + ib_media_addr_set(tb_ptr, &tb_ptr->addr, (char *)dev->dev_addr); + return 0; +} + +/** + * cleanup_bearer - break association between InfiniBand bearer and interface + * + * This routine must be invoked from a work queue because it can sleep. + */ +static void cleanup_bearer(struct work_struct *work) +{ + struct ib_bearer *ib_ptr = + container_of(work, struct ib_bearer, cleanup); + + dev_remove_pack(&ib_ptr->tipc_packet_type); + dev_put(ib_ptr->dev); + ib_ptr->dev = NULL; +} + +/** + * disable_bearer - detach TIPC bearer from an InfiniBand interface + * + * Mark InfiniBand bearer as inactive so that incoming buffers are thrown away, + * then get worker thread to complete bearer cleanup. (Can't do cleanup + * here because cleanup code needs to sleep and caller holds spinlocks.) + */ +static void disable_bearer(struct tipc_bearer *tb_ptr) +{ + struct ib_bearer *ib_ptr = (struct ib_bearer *)tb_ptr->usr_handle; + + ib_ptr->bearer = NULL; + INIT_WORK(&ib_ptr->cleanup, cleanup_bearer); + schedule_work(&ib_ptr->cleanup); +} + +/** + * recv_notification - handle device updates from OS + * + * Change the state of the InfiniBand bearer (if any) associated with the + * specified device. + */ +static int recv_notification(struct notifier_block *nb, unsigned long evt, + void *dv) +{ + struct net_device *dev = (struct net_device *)dv; + struct ib_bearer *ib_ptr = &ib_bearers[0]; + struct ib_bearer *stop = &ib_bearers[MAX_IB_BEARERS]; + + if (!net_eq(dev_net(dev), &init_net)) + return NOTIFY_DONE; + + while ((ib_ptr->dev != dev)) { + if (++ib_ptr == stop) + return NOTIFY_DONE; /* couldn't find device */ + } + if (!ib_ptr->bearer) + return NOTIFY_DONE; /* bearer had been disabled */ + + ib_ptr->bearer->mtu = dev->mtu; + + switch (evt) { + case NETDEV_CHANGE: + if (netif_carrier_ok(dev)) + tipc_continue(ib_ptr->bearer); + else + tipc_block_bearer(ib_ptr->bearer->name); + break; + case NETDEV_UP: + tipc_continue(ib_ptr->bearer); + break; + case NETDEV_DOWN: + tipc_block_bearer(ib_ptr->bearer->name); + break; + case NETDEV_CHANGEMTU: + case NETDEV_CHANGEADDR: + tipc_block_bearer(ib_ptr->bearer->name); + tipc_continue(ib_ptr->bearer); + break; + case NETDEV_UNREGISTER: + case NETDEV_CHANGENAME: + tipc_disable_bearer(ib_ptr->bearer->name); + break; + } + return NOTIFY_OK; +} + +static struct notifier_block notifier = { + .notifier_call = recv_notification, + .priority = 0, +}; + +/** + * ib_addr2str - convert InfiniBand address to string + */ +static int ib_addr2str(struct tipc_media_addr *a, char *str_buf, int str_size) +{ + if (str_size < 60) /* 60 = 19 * strlen("xx:") + strlen("xx\0") */ + return 1; + + sprintf(str_buf, "%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x:" + "%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x", + a->value[0], a->value[1], a->value[2], a->value[3], + a->value[4], a->value[5], a->value[6], a->value[7], + a->value[8], a->value[9], a->value[10], a->value[11], + a->value[12], a->value[13], a->value[14], a->value[15], + a->value[16], a->value[17], a->value[18], a->value[19]); + + return 0; +} + +/** + * ib_addr2msg - convert InfiniBand address format to message header format + */ +static int ib_addr2msg(struct tipc_media_addr *a, char *msg_area) +{ + memset(msg_area, 0, TIPC_MEDIA_ADDR_SIZE); + msg_area[TIPC_MEDIA_TYPE_OFFSET] = TIPC_MEDIA_TYPE_IB; + memcpy(msg_area, a->value, INFINIBAND_ALEN); + return 0; +} + +/** + * ib_msg2addr - convert message header address format to InfiniBand format + */ +static int ib_msg2addr(const struct tipc_bearer *tb_ptr, + struct tipc_media_addr *a, char *msg_area) +{ + ib_media_addr_set(tb_ptr, a, msg_area); + return 0; +} + +/* + * InfiniBand media registration info + */ +static struct tipc_media ib_media_info = { + .send_msg = send_msg, + .enable_bearer = enable_bearer, + .disable_bearer = disable_bearer, + .addr2str = ib_addr2str, + .addr2msg = ib_addr2msg, + .msg2addr = ib_msg2addr, + .priority = TIPC_DEF_LINK_PRI, + .tolerance = TIPC_DEF_LINK_TOL, + .window = TIPC_DEF_LINK_WIN, + .type_id = TIPC_MEDIA_TYPE_IB, + .name = "ib" +}; + +/** + * tipc_ib_media_start - activate InfiniBand bearer support + * + * Register InfiniBand media type with TIPC bearer code. Also register + * with OS for notifications about device state changes. + */ +int tipc_ib_media_start(void) +{ + int res; + + if (ib_started) + return -EINVAL; + + res = tipc_register_media(&ib_media_info); + if (res) + return res; + + res = register_netdevice_notifier(¬ifier); + if (!res) + ib_started = 1; + return res; +} + +/** + * tipc_ib_media_stop - deactivate InfiniBand bearer support + */ +void tipc_ib_media_stop(void) +{ + if (!ib_started) + return; + + flush_scheduled_work(); + unregister_netdevice_notifier(¬ifier); + ib_started = 0; +} -- 1.8.1.4 ^ permalink raw reply related [flat|nested] 16+ messages in thread
end of thread, other threads:[~2013-04-17 16:19 UTC | newest] Thread overview: 16+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2013-04-03 12:43 [PATCH RFC 0/5] tipc: add support for TIPC over InfiniBand Patrick McHardy 2013-04-03 12:43 ` [PATCH 2/5] tipc: move bcast_addr from struct tipc_media to struct tipc_bearer Patrick McHardy [not found] ` <1364993010-15515-1-git-send-email-kaber-dcUjhNyLwpNeoWH0uzbU5w@public.gmane.org> 2013-04-03 12:43 ` [PATCH 1/5] tipc: remove unused str2addr media callback Patrick McHardy 2013-04-03 12:43 ` [PATCH 3/5] tipc: set skb->protocol in eth_media packet transmission Patrick McHardy 2013-04-03 12:43 ` [PATCH 4/5] tipc: add InfiniBand media type Patrick McHardy 2013-04-03 14:41 ` Erik Hugne 2013-04-03 14:49 ` Patrick McHardy [not found] ` <1364993010-15515-5-git-send-email-kaber-dcUjhNyLwpNeoWH0uzbU5w@public.gmane.org> 2013-04-07 9:07 ` Ying Xue [not found] ` <51613740.6050501-CWA4WttNNZF54TAoqtyWWQ@public.gmane.org> 2013-04-07 12:04 ` Patrick McHardy 2013-04-07 9:19 ` Bart Van Assche 2013-04-07 9:43 ` Patrick McHardy 2013-04-03 12:43 ` [PATCH 5/5] IPoIB: add support for TIPC protocol Patrick McHardy [not found] ` <1364993010-15515-6-git-send-email-kaber-dcUjhNyLwpNeoWH0uzbU5w@public.gmane.org> 2013-04-03 15:31 ` Or Gerlitz 2013-04-03 15:44 ` Patrick McHardy 2013-04-03 19:44 ` [PATCH RFC 0/5] tipc: add support for TIPC over InfiniBand Jon Maloy -- strict thread matches above, loose matches on Subject: below -- 2013-04-17 16:18 [PATCH v2 0/5] tipc: add TIPC over Infiniband support Patrick McHardy 2013-04-17 16:18 ` [PATCH 4/5] tipc: add InfiniBand media type Patrick McHardy
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for NNTP newsgroup(s).