netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Paul Gortmaker <paul.gortmaker@windriver.com>
To: davem@davemloft.net
Cc: netdev@vger.kernel.org, allan.stephens@windriver.com,
	ying.xue@windriver.com,
	Paul Gortmaker <paul.gortmaker@windriver.com>
Subject: [PATCH net-next 02/23] tipc: Register new media using pre-compiled structure
Date: Tue, 27 Dec 2011 12:39:21 -0500	[thread overview]
Message-ID: <1325007582-31610-3-git-send-email-paul.gortmaker@windriver.com> (raw)
In-Reply-To: <1325007582-31610-1-git-send-email-paul.gortmaker@windriver.com>

From: Allan Stephens <allan.stephens@windriver.com>

Speeds up the registration of TIPC media types by passing in a structure
containing the required information, rather than by passing in the various
fields describing the media type individually.

Signed-off-by: Allan Stephens <allan.stephens@windriver.com>
Signed-off-by: Paul Gortmaker <paul.gortmaker@windriver.com>
---
 net/tipc/bearer.c    |   70 ++++++++++++++++++--------------------------------
 net/tipc/bearer.h    |   11 +-------
 net/tipc/eth_media.c |   30 +++++++++++++--------
 3 files changed, 45 insertions(+), 66 deletions(-)

diff --git a/net/tipc/bearer.c b/net/tipc/bearer.c
index e2202de..75af271 100644
--- a/net/tipc/bearer.c
+++ b/net/tipc/bearer.c
@@ -86,21 +86,8 @@ static struct media *media_find(const char *name)
  * Bearers for this media type must be activated separately at a later stage.
  */
 
-int  tipc_register_media(u32 media_type,
-			 char *name,
-			 int (*enable)(struct tipc_bearer *),
-			 void (*disable)(struct tipc_bearer *),
-			 int (*send_msg)(struct sk_buff *,
-					 struct tipc_bearer *,
-					 struct tipc_media_addr *),
-			 char *(*addr2str)(struct tipc_media_addr *a,
-					   char *str_buf, int str_size),
-			 struct tipc_media_addr *bcast_addr,
-			 const u32 bearer_priority,
-			 const u32 link_tolerance,  /* [ms] */
-			 const u32 send_window_limit)
+int  tipc_register_media(struct media *m_ptr)
 {
-	struct media *m_ptr;
 	u32 media_id;
 	u32 i;
 	int res = -EINVAL;
@@ -108,62 +95,55 @@ int  tipc_register_media(u32 media_type,
 	write_lock_bh(&tipc_net_lock);
 
 	if (tipc_mode != TIPC_NET_MODE) {
-		warn("Media <%s> rejected, not in networked mode yet\n", name);
+		warn("Media <%s> rejected, not in networked mode yet\n",
+		     m_ptr->name);
 		goto exit;
 	}
-	if (!media_name_valid(name)) {
-		warn("Media <%s> rejected, illegal name\n", name);
+	if (!media_name_valid(m_ptr->name)) {
+		warn("Media <%s> rejected, illegal name\n", m_ptr->name);
 		goto exit;
 	}
-	if (!bcast_addr) {
-		warn("Media <%s> rejected, no broadcast address\n", name);
+	if (m_ptr->bcast_addr.type != htonl(m_ptr->type_id)) {
+		warn("Media <%s> rejected, illegal broadcast address\n",
+		     m_ptr->name);
 		goto exit;
 	}
-	if ((bearer_priority < TIPC_MIN_LINK_PRI) ||
-	    (bearer_priority > TIPC_MAX_LINK_PRI)) {
-		warn("Media <%s> rejected, illegal priority (%u)\n", name,
-		     bearer_priority);
+	if ((m_ptr->priority < TIPC_MIN_LINK_PRI) ||
+	    (m_ptr->priority > TIPC_MAX_LINK_PRI)) {
+		warn("Media <%s> rejected, illegal priority (%u)\n",
+		     m_ptr->name, m_ptr->priority);
 		goto exit;
 	}
-	if ((link_tolerance < TIPC_MIN_LINK_TOL) ||
-	    (link_tolerance > TIPC_MAX_LINK_TOL)) {
-		warn("Media <%s> rejected, illegal tolerance (%u)\n", name,
-		     link_tolerance);
+	if ((m_ptr->tolerance < TIPC_MIN_LINK_TOL) ||
+	    (m_ptr->tolerance > TIPC_MAX_LINK_TOL)) {
+		warn("Media <%s> rejected, illegal tolerance (%u)\n",
+		     m_ptr->name, m_ptr->tolerance);
 		goto exit;
 	}
 
 	media_id = media_count++;
 	if (media_id >= MAX_MEDIA) {
-		warn("Media <%s> rejected, media limit reached (%u)\n", name,
-		     MAX_MEDIA);
+		warn("Media <%s> rejected, media limit reached (%u)\n",
+		     m_ptr->name, MAX_MEDIA);
 		media_count--;
 		goto exit;
 	}
 	for (i = 0; i < media_id; i++) {
-		if (media_list[i].type_id == media_type) {
-			warn("Media <%s> rejected, duplicate type (%u)\n", name,
-			     media_type);
+		if (media_list[i].type_id == m_ptr->type_id) {
+			warn("Media <%s> rejected, duplicate type (%u)\n",
+			     m_ptr->name, m_ptr->type_id);
 			media_count--;
 			goto exit;
 		}
-		if (!strcmp(name, media_list[i].name)) {
-			warn("Media <%s> rejected, duplicate name\n", name);
+		if (!strcmp(m_ptr->name, media_list[i].name)) {
+			warn("Media <%s> rejected, duplicate name\n",
+			     m_ptr->name);
 			media_count--;
 			goto exit;
 		}
 	}
 
-	m_ptr = &media_list[media_id];
-	m_ptr->type_id = media_type;
-	m_ptr->send_msg = send_msg;
-	m_ptr->enable_bearer = enable;
-	m_ptr->disable_bearer = disable;
-	m_ptr->addr2str = addr2str;
-	memcpy(&m_ptr->bcast_addr, bcast_addr, sizeof(*bcast_addr));
-	strcpy(m_ptr->name, name);
-	m_ptr->priority = bearer_priority;
-	m_ptr->tolerance = link_tolerance;
-	m_ptr->window = send_window_limit;
+	media_list[media_id] = *m_ptr;
 	res = 0;
 exit:
 	write_unlock_bh(&tipc_net_lock);
diff --git a/net/tipc/bearer.h b/net/tipc/bearer.h
index d696f9e..148ed04 100644
--- a/net/tipc/bearer.h
+++ b/net/tipc/bearer.h
@@ -145,16 +145,7 @@ extern struct tipc_bearer tipc_bearers[];
 /*
  * TIPC routines available to supported media types
  */
-int tipc_register_media(u32 media_type,
-		 char *media_name, int (*enable)(struct tipc_bearer *),
-		 void (*disable)(struct tipc_bearer *),
-		 int (*send_msg)(struct sk_buff *,
-			struct tipc_bearer *, struct tipc_media_addr *),
-		 char *(*addr2str)(struct tipc_media_addr *a,
-			char *str_buf, int str_size),
-		 struct tipc_media_addr *bcast_addr, const u32 bearer_priority,
-		 const u32 link_tolerance,  /* [ms] */
-		 const u32 send_window_limit);
+int tipc_register_media(struct media *m_ptr);
 
 void tipc_recv_msg(struct sk_buff *buf, struct tipc_bearer *tb_ptr);
 
diff --git a/net/tipc/eth_media.c b/net/tipc/eth_media.c
index e728d4c..15c685b 100644
--- a/net/tipc/eth_media.c
+++ b/net/tipc/eth_media.c
@@ -38,9 +38,6 @@
 #include "bearer.h"
 
 #define MAX_ETH_BEARERS		MAX_BEARERS
-#define ETH_LINK_PRIORITY	TIPC_DEF_LINK_PRI
-#define ETH_LINK_TOLERANCE	TIPC_DEF_LINK_TOL
-#define ETH_LINK_WINDOW		TIPC_DEF_LINK_WIN
 
 /**
  * struct eth_bearer - Ethernet bearer data structure
@@ -257,6 +254,24 @@ static char *eth_addr2str(struct tipc_media_addr *a, char *str_buf, int str_size
 	return str_buf;
 }
 
+/*
+ * Ethernet media registration info
+ */
+
+static struct media eth_media_info = {
+	.send_msg	= send_msg,
+	.enable_bearer	= enable_bearer,
+	.disable_bearer	= disable_bearer,
+	.addr2str	= eth_addr2str,
+	.bcast_addr	= { htonl(TIPC_MEDIA_TYPE_ETH),
+			    { {0xff, 0xff, 0xff, 0xff, 0xff, 0xff} } },
+	.priority	= TIPC_DEF_LINK_PRI,
+	.tolerance	= TIPC_DEF_LINK_TOL,
+	.window		= TIPC_DEF_LINK_WIN,
+	.type_id	= TIPC_MEDIA_TYPE_ETH,
+	.name		= "eth"
+};
+
 /**
  * tipc_eth_media_start - activate Ethernet bearer support
  *
@@ -266,21 +281,14 @@ static char *eth_addr2str(struct tipc_media_addr *a, char *str_buf, int str_size
 
 int tipc_eth_media_start(void)
 {
-	struct tipc_media_addr bcast_addr;
 	int res;
 
 	if (eth_started)
 		return -EINVAL;
 
-	bcast_addr.type = htonl(TIPC_MEDIA_TYPE_ETH);
-	memset(&bcast_addr.dev_addr, 0xff, ETH_ALEN);
-
 	memset(eth_bearers, 0, sizeof(eth_bearers));
 
-	res = tipc_register_media(TIPC_MEDIA_TYPE_ETH, "eth",
-				  enable_bearer, disable_bearer, send_msg,
-				  eth_addr2str, &bcast_addr, ETH_LINK_PRIORITY,
-				  ETH_LINK_TOLERANCE, ETH_LINK_WINDOW);
+	res = tipc_register_media(&eth_media_info);
 	if (res)
 		return res;
 
-- 
1.7.4.4

  parent reply	other threads:[~2011-12-27 17:39 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-12-27 17:39 [PATCH net-next 00/23] TIPC: Updates for what will be v3.3 Paul Gortmaker
2011-12-27 17:39 ` [PATCH net-next 01/23] tipc: Enable use by containers having their own network namespace Paul Gortmaker
2011-12-27 17:39 ` Paul Gortmaker [this message]
2011-12-27 17:39 ` [PATCH net-next 03/23] tipc: Optimize detection of duplicate media registration Paul Gortmaker
2011-12-27 17:39 ` [PATCH net-next 04/23] tipc: Eliminate duplication of media structures Paul Gortmaker
2011-12-27 17:39 ` [PATCH net-next 05/23] tipc: Streamline media registration error checking Paul Gortmaker
2011-12-27 17:39 ` [PATCH net-next 06/23] tipc: Improve handling of media address printing errors Paul Gortmaker
2011-12-27 17:39 ` [PATCH net-next 07/23] tipc: Add new address conversion routines for Ethernet media Paul Gortmaker
2011-12-27 17:39 ` [PATCH net-next 08/23] tipc: Hide media-specific addressing details from generic bearer code Paul Gortmaker
2011-12-27 17:39 ` [PATCH net-next 09/23] tipc: Ignore neighbor discovery messages containing invalid address Paul Gortmaker
2011-12-27 17:39 ` [PATCH net-next 10/23] tipc: Allow run-time alteration of default link settings Paul Gortmaker
2011-12-27 17:39 ` [PATCH net-next 11/23] tipc: Revise comment justifying release of configuration spinlock Paul Gortmaker
2011-12-27 17:39 ` [PATCH net-next 12/23] tipc: Minor optimization to deactivation of Ethernet media suppot Paul Gortmaker
2011-12-27 17:39 ` [PATCH net-next 13/23] tipc: Do timely cleanup of disabled Ethernet bearer resources Paul Gortmaker
2011-12-27 17:39 ` [PATCH net-next 14/23] tipc: Eliminate useless memset operations in Ethernet media support Paul Gortmaker
2011-12-27 17:39 ` [PATCH net-next 15/23] tipc: Minor correction to TIPC module unloading Paul Gortmaker
2011-12-27 17:39 ` [PATCH net-next 16/23] tipc: Eliminate useless check when network address is assigned Paul Gortmaker
2011-12-27 17:39 ` [PATCH net-next 17/23] tipc: Eliminate dynamic allocation of broadcast link data structures Paul Gortmaker
2011-12-27 17:39 ` [PATCH net-next 18/23] tipc: Ensure broadcast link spinlock is held when updating node map Paul Gortmaker
2011-12-27 17:39 ` [PATCH net-next 19/23] tipc: Handle broadcast attempt when no neighboring nodes exist Paul Gortmaker
2011-12-27 17:39 ` [PATCH net-next 20/23] tipc: Minor optimization of broadcast link transmit queue statistic Paul Gortmaker
2011-12-27 17:39 ` [PATCH net-next 21/23] tipc: Flush unsent broadcast messages when contact with last node is lost Paul Gortmaker
2011-12-27 17:39 ` [PATCH net-next 22/23] tipc: Ignore broadcast acknowledgements that are out-of-range Paul Gortmaker
2011-12-27 17:39 ` [PATCH net-next 23/23] tipc: Allow use of buf_seqno() helper routine by unicast links Paul Gortmaker
2011-12-27 18:08 ` [PATCH net-next 00/23] TIPC: Updates for what will be v3.3 David Miller
2011-12-28  2:16   ` Paul Gortmaker

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1325007582-31610-3-git-send-email-paul.gortmaker@windriver.com \
    --to=paul.gortmaker@windriver.com \
    --cc=allan.stephens@windriver.com \
    --cc=davem@davemloft.net \
    --cc=netdev@vger.kernel.org \
    --cc=ying.xue@windriver.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).