netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jiri Pirko <jiri@resnulli.us>
To: netdev@vger.kernel.org
Cc: davem@davemloft.net, sfeldma@gmail.com, idosch@mellanox.com,
	eladr@mellanox.com, tgraf@suug.ch, David.Laight@ACULAB.COM,
	john.fastabend@gmail.com, alexei.starovoitov@gmail.com,
	daniel@iogearbox.net, prem@barefootnetworks.com
Subject: [patch net-next 09/13] rocker: pre-allocate wait structures during cmd ring init
Date: Tue, 16 Feb 2016 13:55:34 +0100	[thread overview]
Message-ID: <1455627338-9872-10-git-send-email-jiri@resnulli.us> (raw)
In-Reply-To: <1455627338-9872-1-git-send-email-jiri@resnulli.us>

From: Jiri Pirko <jiri@mellanox.com>

This avoids need to alloc/free wait structure for every command call.

Signed-off-by: Jiri Pirko <jiri@mellanox.com>
---
 drivers/net/ethernet/rocker/rocker_main.c | 87 +++++++++++++++++++++++--------
 1 file changed, 66 insertions(+), 21 deletions(-)

diff --git a/drivers/net/ethernet/rocker/rocker_main.c b/drivers/net/ethernet/rocker/rocker_main.c
index 0015dcb..8585d98 100644
--- a/drivers/net/ethernet/rocker/rocker_main.c
+++ b/drivers/net/ethernet/rocker/rocker_main.c
@@ -338,23 +338,19 @@ static void rocker_wait_init(struct rocker_wait *wait)
 	rocker_wait_reset(wait);
 }
 
-static struct rocker_wait *rocker_wait_create(struct rocker_port *rocker_port,
-					      struct switchdev_trans *trans,
-					      int flags)
+static struct rocker_wait *rocker_wait_create(void)
 {
 	struct rocker_wait *wait;
 
-	wait = rocker_kzalloc(trans, flags, sizeof(*wait));
+	wait = kzalloc(sizeof(*wait), GFP_KERNEL);
 	if (!wait)
 		return NULL;
-	rocker_wait_init(wait);
 	return wait;
 }
 
-static void rocker_wait_destroy(struct switchdev_trans *trans,
-				struct rocker_wait *wait)
+static void rocker_wait_destroy(struct rocker_wait *wait)
 {
-	rocker_kfree(trans, wait);
+	kfree(wait);
 }
 
 static bool rocker_wait_event_timeout(struct rocker_wait *wait,
@@ -831,6 +827,53 @@ static void rocker_dma_ring_bufs_free(const struct rocker *rocker,
 	}
 }
 
+static int rocker_dma_cmd_ring_wait_alloc(struct rocker_desc_info *desc_info)
+{
+	struct rocker_wait *wait;
+
+	wait = rocker_wait_create();
+	if (!wait)
+		return -ENOMEM;
+	rocker_desc_cookie_ptr_set(desc_info, wait);
+	return 0;
+}
+
+static void
+rocker_dma_cmd_ring_wait_free(const struct rocker_desc_info *desc_info)
+{
+	struct rocker_wait *wait = rocker_desc_cookie_ptr_get(desc_info);
+
+	rocker_wait_destroy(wait);
+}
+
+static int rocker_dma_cmd_ring_waits_alloc(const struct rocker *rocker)
+{
+	const struct rocker_dma_ring_info *cmd_ring = &rocker->cmd_ring;
+	int i;
+	int err;
+
+	for (i = 0; i < cmd_ring->size; i++) {
+		err = rocker_dma_cmd_ring_wait_alloc(&cmd_ring->desc_info[i]);
+		if (err)
+			goto rollback;
+	}
+	return 0;
+
+rollback:
+	for (i--; i >= 0; i--)
+		rocker_dma_cmd_ring_wait_free(&cmd_ring->desc_info[i]);
+	return err;
+}
+
+static void rocker_dma_cmd_ring_waits_free(const struct rocker *rocker)
+{
+	const struct rocker_dma_ring_info *cmd_ring = &rocker->cmd_ring;
+	int i;
+
+	for (i = 0; i < cmd_ring->size; i++)
+		rocker_dma_cmd_ring_wait_free(&cmd_ring->desc_info[i]);
+}
+
 static int rocker_dma_rings_init(struct rocker *rocker)
 {
 	const struct pci_dev *pdev = rocker->pdev;
@@ -853,6 +896,12 @@ static int rocker_dma_rings_init(struct rocker *rocker)
 		goto err_dma_cmd_ring_bufs_alloc;
 	}
 
+	err = rocker_dma_cmd_ring_waits_alloc(rocker);
+	if (err) {
+		dev_err(&pdev->dev, "failed to alloc command dma ring waits\n");
+		goto err_dma_cmd_ring_waits_alloc;
+	}
+
 	err = rocker_dma_ring_create(rocker, ROCKER_DMA_EVENT,
 				     ROCKER_DMA_EVENT_DEFAULT_SIZE,
 				     &rocker->event_ring);
@@ -875,6 +924,8 @@ err_dma_event_ring_bufs_alloc:
 err_dma_event_ring_create:
 	rocker_dma_ring_bufs_free(rocker, &rocker->cmd_ring,
 				  PCI_DMA_BIDIRECTIONAL);
+err_dma_cmd_ring_waits_alloc:
+	rocker_dma_cmd_ring_waits_free(rocker);
 err_dma_cmd_ring_bufs_alloc:
 	rocker_dma_ring_destroy(rocker, &rocker->cmd_ring);
 	return err;
@@ -885,6 +936,7 @@ static void rocker_dma_rings_fini(struct rocker *rocker)
 	rocker_dma_ring_bufs_free(rocker, &rocker->event_ring,
 				  PCI_DMA_BIDIRECTIONAL);
 	rocker_dma_ring_destroy(rocker, &rocker->event_ring);
+	rocker_dma_cmd_ring_waits_free(rocker);
 	rocker_dma_ring_bufs_free(rocker, &rocker->cmd_ring,
 				  PCI_DMA_BIDIRECTIONAL);
 	rocker_dma_ring_destroy(rocker, &rocker->cmd_ring);
@@ -1106,7 +1158,6 @@ static irqreturn_t rocker_cmd_irq_handler(int irq, void *dev_id)
 		wait = rocker_desc_cookie_ptr_get(desc_info);
 		if (wait->nowait) {
 			rocker_desc_gen_clear(desc_info);
-			rocker_wait_destroy(NULL, wait);
 		} else {
 			rocker_wait_wake_up(wait);
 		}
@@ -1298,28 +1349,24 @@ static int rocker_cmd_exec(struct rocker_port *rocker_port,
 	unsigned long lock_flags;
 	int err;
 
-	wait = rocker_wait_create(rocker_port, trans, flags);
-	if (!wait)
-		return -ENOMEM;
-	wait->nowait = nowait;
-
 	spin_lock_irqsave(&rocker->cmd_ring_lock, lock_flags);
 
 	desc_info = rocker_desc_head_get(&rocker->cmd_ring);
 	if (!desc_info) {
 		spin_unlock_irqrestore(&rocker->cmd_ring_lock, lock_flags);
-		err = -EAGAIN;
-		goto out;
+		return -EAGAIN;
 	}
 
+	wait = rocker_desc_cookie_ptr_get(desc_info);
+	rocker_wait_init(wait);
+	wait->nowait = nowait;
+
 	err = prepare(rocker_port, desc_info, prepare_priv);
 	if (err) {
 		spin_unlock_irqrestore(&rocker->cmd_ring_lock, lock_flags);
-		goto out;
+		return err;
 	}
 
-	rocker_desc_cookie_ptr_set(desc_info, wait);
-
 	if (!switchdev_trans_ph_prepare(trans))
 		rocker_desc_head_set(rocker, &rocker->cmd_ring, desc_info);
 
@@ -1340,8 +1387,6 @@ static int rocker_cmd_exec(struct rocker_port *rocker_port,
 		err = process(rocker_port, desc_info, process_priv);
 
 	rocker_desc_gen_clear(desc_info);
-out:
-	rocker_wait_destroy(trans, wait);
 	return err;
 }
 
-- 
1.9.3

  parent reply	other threads:[~2016-02-16 12:55 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-02-16 12:55 [patch net-next 00/13] rocker: do world split Jiri Pirko
2016-02-16 12:55 ` [patch net-next 01/13] rocker: remove unused rocker_port param from alloc funcs and shorten their names Jiri Pirko
2016-02-16 12:55 ` [patch net-next 02/13] rocker: rename rocker.h to rocker_hw.h Jiri Pirko
2016-02-16 12:55 ` [patch net-next 03/13] rocker: rename rocker.c to rocker_main.c Jiri Pirko
2016-02-16 12:55 ` [patch net-next 04/13] rocker: push tlv processing into separate files Jiri Pirko
2016-02-16 12:55 ` [patch net-next 05/13] rocker: implement get settings mode command Jiri Pirko
2016-02-16 12:55 ` [patch net-next 06/13] rocker: move rocker and rocker_port structs into header Jiri Pirko
2016-02-16 12:55 ` [patch net-next 07/13] rocker: introduce worlds infrastructure Jiri Pirko
2016-02-16 12:55 ` [patch net-next 08/13] rocker: pass "learning" value as a parameter to rocker_port_set_learning Jiri Pirko
2016-02-16 12:55 ` Jiri Pirko [this message]
2016-02-16 12:55 ` [patch net-next 10/13] rocker: remove trans parameter to rocker_cmd_exec function Jiri Pirko
2016-02-16 12:55 ` [patch net-next 11/13] rocker: call rocker_cmd_exec function with "nowait" boolean instead of flags Jiri Pirko
2016-02-16 12:55 ` [patch net-next 12/13] rocker: move OF-DPA stuff into separate file Jiri Pirko
2016-02-16 12:55 ` [patch net-next 13/13] rocker: return -EOPNOTSUPP for undefined world ops Jiri Pirko
2016-02-16 14:13 ` [patch net-next 00/13] rocker: do world split Jiri Pirko

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=1455627338-9872-10-git-send-email-jiri@resnulli.us \
    --to=jiri@resnulli.us \
    --cc=David.Laight@ACULAB.COM \
    --cc=alexei.starovoitov@gmail.com \
    --cc=daniel@iogearbox.net \
    --cc=davem@davemloft.net \
    --cc=eladr@mellanox.com \
    --cc=idosch@mellanox.com \
    --cc=john.fastabend@gmail.com \
    --cc=netdev@vger.kernel.org \
    --cc=prem@barefootnetworks.com \
    --cc=sfeldma@gmail.com \
    --cc=tgraf@suug.ch \
    /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).