From: Mika Westerberg <mika.westerberg@linux.intel.com>
To: Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
"David S . Miller" <davem@davemloft.net>
Cc: Andreas Noever <andreas.noever@gmail.com>,
Michael Jamet <michael.jamet@intel.com>,
Yehezkel Bernat <yehezkel.bernat@intel.com>,
Amir Levy <amir.jer.levy@intel.com>,
Mario.Limonciello@dell.com, Lukas Wunner <lukas@wunner.de>,
Andy Shevchenko <andriy.shevchenko@linux.intel.com>,
Andrew Lunn <andrew@lunn.ch>,
Mika Westerberg <mika.westerberg@linux.intel.com>,
linux-kernel@vger.kernel.org, netdev@vger.kernel.org
Subject: [PATCH v2 15/16] thunderbolt: Allocate ring HopID automatically if requested
Date: Mon, 25 Sep 2017 14:07:37 +0300 [thread overview]
Message-ID: <20170925110738.68382-16-mika.westerberg@linux.intel.com> (raw)
In-Reply-To: <20170925110738.68382-1-mika.westerberg@linux.intel.com>
Thunderbolt services should not care which HopID (ring) they use for
sending and receiving packets over the high-speed DMA path, so make
tb_ring_alloc_rx() and tb_ring_alloc_tx() accept negative HopID. This
means that the NHI will allocate next available HopID for the caller
automatically.
These HopIDs will be allocated from the range which is not reserved for
the Thunderbolt protocol (8 .. hop_count - 1).
The allocated HopID can be retrieved from ring->hop field after the ring
has been allocated successfully if needed.
Signed-off-by: Mika Westerberg <mika.westerberg@linux.intel.com>
Reviewed-by: Michael Jamet <michael.jamet@intel.com>
Reviewed-by: Yehezkel Bernat <yehezkel.bernat@intel.com>
---
drivers/thunderbolt/nhi.c | 78 ++++++++++++++++++++++++++++++++++++-----------
1 file changed, 60 insertions(+), 18 deletions(-)
diff --git a/drivers/thunderbolt/nhi.c b/drivers/thunderbolt/nhi.c
index 5bc3f77cc1f3..b9e3980aa4fc 100644
--- a/drivers/thunderbolt/nhi.c
+++ b/drivers/thunderbolt/nhi.c
@@ -26,6 +26,8 @@
* use this ring for anything else.
*/
#define RING_E2E_UNUSED_HOPID 2
+/* HopIDs 0-7 are reserved by the Thunderbolt protocol */
+#define RING_FIRST_USABLE_HOPID 8
/*
* Minimal number of vectors when we use MSI-X. Two for control channel
@@ -411,6 +413,62 @@ static void ring_release_msix(struct tb_ring *ring)
ring->irq = 0;
}
+static int nhi_alloc_hop(struct tb_nhi *nhi, struct tb_ring *ring)
+{
+ int ret = 0;
+
+ spin_lock_irq(&nhi->lock);
+
+ if (ring->hop < 0) {
+ unsigned int i;
+
+ /*
+ * Automatically allocate HopID from the non-reserved
+ * range 8 .. hop_count - 1.
+ */
+ for (i = RING_FIRST_USABLE_HOPID; i < nhi->hop_count; i++) {
+ if (ring->is_tx) {
+ if (!nhi->tx_rings[i]) {
+ ring->hop = i;
+ break;
+ }
+ } else {
+ if (!nhi->rx_rings[i]) {
+ ring->hop = i;
+ break;
+ }
+ }
+ }
+ }
+
+ if (ring->hop < 0 || ring->hop >= nhi->hop_count) {
+ dev_warn(&nhi->pdev->dev, "invalid hop: %d\n", ring->hop);
+ ret = -EINVAL;
+ goto err_unlock;
+ }
+ if (ring->is_tx && nhi->tx_rings[ring->hop]) {
+ dev_warn(&nhi->pdev->dev, "TX hop %d already allocated\n",
+ ring->hop);
+ ret = -EBUSY;
+ goto err_unlock;
+ } else if (!ring->is_tx && nhi->rx_rings[ring->hop]) {
+ dev_warn(&nhi->pdev->dev, "RX hop %d already allocated\n",
+ ring->hop);
+ ret = -EBUSY;
+ goto err_unlock;
+ }
+
+ if (ring->is_tx)
+ nhi->tx_rings[ring->hop] = ring;
+ else
+ nhi->rx_rings[ring->hop] = ring;
+
+err_unlock:
+ spin_unlock_irq(&nhi->lock);
+
+ return ret;
+}
+
static struct tb_ring *tb_ring_alloc(struct tb_nhi *nhi, u32 hop, int size,
bool transmit, unsigned int flags,
u16 sof_mask, u16 eof_mask,
@@ -456,28 +514,12 @@ static struct tb_ring *tb_ring_alloc(struct tb_nhi *nhi, u32 hop, int size,
if (ring_request_msix(ring, flags & RING_FLAG_NO_SUSPEND))
goto err_free_descs;
- spin_lock_irq(&nhi->lock);
- if (hop >= nhi->hop_count) {
- dev_WARN(&nhi->pdev->dev, "invalid hop: %d\n", hop);
+ if (nhi_alloc_hop(nhi, ring))
goto err_release_msix;
- }
- if (transmit && nhi->tx_rings[hop]) {
- dev_WARN(&nhi->pdev->dev, "TX hop %d already allocated\n", hop);
- goto err_release_msix;
- } else if (!transmit && nhi->rx_rings[hop]) {
- dev_WARN(&nhi->pdev->dev, "RX hop %d already allocated\n", hop);
- goto err_release_msix;
- }
- if (transmit)
- nhi->tx_rings[hop] = ring;
- else
- nhi->rx_rings[hop] = ring;
- spin_unlock_irq(&nhi->lock);
return ring;
err_release_msix:
- spin_unlock_irq(&nhi->lock);
ring_release_msix(ring);
err_free_descs:
dma_free_coherent(&ring->nhi->pdev->dev,
@@ -506,7 +548,7 @@ EXPORT_SYMBOL_GPL(tb_ring_alloc_tx);
/**
* tb_ring_alloc_rx() - Allocate DMA ring for receive
* @nhi: Pointer to the NHI the ring is to be allocated
- * @hop: HopID (ring) to allocate
+ * @hop: HopID (ring) to allocate. Pass %-1 for automatic allocation.
* @size: Number of entries in the ring
* @flags: Flags for the ring
* @sof_mask: Mask of PDF values that start a frame
--
2.14.1
next prev parent reply other threads:[~2017-09-25 11:07 UTC|newest]
Thread overview: 28+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-09-25 11:07 [PATCH v2 00/16] Thunderbolt networking Mika Westerberg
2017-09-25 11:07 ` [PATCH v2 01/16] byteorder: Move {cpu_to_be32,be32_to_cpu}_array() from Thunderbolt to core Mika Westerberg
2017-09-25 11:07 ` [PATCH v2 02/16] thunderbolt: Add support for XDomain properties Mika Westerberg
2017-09-27 4:33 ` David Miller
2017-09-27 11:32 ` Mika Westerberg
2017-09-27 16:06 ` David Laight
2017-09-27 16:22 ` David Miller
2017-09-25 11:07 ` [PATCH v2 03/16] thunderbolt: Move enum tb_cfg_pkg_type to thunderbolt.h Mika Westerberg
2017-09-25 11:07 ` [PATCH v2 04/16] thunderbolt: Move thunderbolt domain structure " Mika Westerberg
2017-09-25 11:07 ` [PATCH v2 05/16] thunderbolt: Move tb_switch_phy_port_from_link() " Mika Westerberg
2017-09-25 11:07 ` [PATCH v2 06/16] thunderbolt: Add support for XDomain discovery protocol Mika Westerberg
2017-09-27 4:35 ` David Miller
2017-09-25 11:07 ` [PATCH v2 07/16] thunderbolt: Configure interrupt throttling for all interrupts Mika Westerberg
2017-09-25 11:07 ` [PATCH v2 08/16] thunderbolt: Add support for frame mode Mika Westerberg
2017-09-25 11:07 ` [PATCH v2 09/16] thunderbolt: Export ring handling functions to modules Mika Westerberg
2017-09-25 11:07 ` [PATCH v2 10/16] thunderbolt: Move ring descriptor flags to thunderbolt.h Mika Westerberg
2017-09-25 11:07 ` [PATCH v2 11/16] thunderbolt: Use spinlock in ring serialization Mika Westerberg
2017-09-25 11:07 ` [PATCH v2 12/16] thunderbolt: Use spinlock in NHI serialization Mika Westerberg
2017-09-25 11:07 ` [PATCH v2 13/16] thunderbolt: Add polling mode for rings Mika Westerberg
2017-09-25 11:07 ` [PATCH v2 14/16] thunderbolt: Add function to retrieve DMA device for the ring Mika Westerberg
2017-09-25 11:07 ` Mika Westerberg [this message]
2017-09-25 11:07 ` [PATCH v2 16/16] net: Add support for networking over Thunderbolt cable Mika Westerberg
2017-09-27 4:47 ` David Miller
2017-09-27 13:42 ` Mika Westerberg
2017-09-27 16:27 ` David Miller
2017-09-27 17:27 ` Mika Westerberg
2017-09-27 18:23 ` David Miller
2017-09-26 17:37 ` [PATCH v2 00/16] Thunderbolt networking Andy Shevchenko
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=20170925110738.68382-16-mika.westerberg@linux.intel.com \
--to=mika.westerberg@linux.intel.com \
--cc=Mario.Limonciello@dell.com \
--cc=amir.jer.levy@intel.com \
--cc=andreas.noever@gmail.com \
--cc=andrew@lunn.ch \
--cc=andriy.shevchenko@linux.intel.com \
--cc=davem@davemloft.net \
--cc=gregkh@linuxfoundation.org \
--cc=linux-kernel@vger.kernel.org \
--cc=lukas@wunner.de \
--cc=michael.jamet@intel.com \
--cc=netdev@vger.kernel.org \
--cc=yehezkel.bernat@intel.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).