{"id":818190,"url":"http://patchwork.ozlabs.org/api/patches/818190/?format=json","web_url":"http://patchwork.ozlabs.org/project/netdev/patch/20170925110738.68382-16-mika.westerberg@linux.intel.com/","project":{"id":7,"url":"http://patchwork.ozlabs.org/api/projects/7/?format=json","name":"Linux network development","link_name":"netdev","list_id":"netdev.vger.kernel.org","list_email":"netdev@vger.kernel.org","web_url":null,"scm_url":null,"webscm_url":null,"list_archive_url":"","list_archive_url_format":"","commit_url_format":""},"msgid":"<20170925110738.68382-16-mika.westerberg@linux.intel.com>","list_archive_url":null,"date":"2017-09-25T11:07:37","name":"[v2,15/16] thunderbolt: Allocate ring HopID automatically if requested","commit_ref":null,"pull_url":null,"state":"changes-requested","archived":true,"hash":"aa2f87ead40a3c12f1f003bde4066c930e0c9fbd","submitter":{"id":14534,"url":"http://patchwork.ozlabs.org/api/people/14534/?format=json","name":"Mika Westerberg","email":"mika.westerberg@linux.intel.com"},"delegate":{"id":34,"url":"http://patchwork.ozlabs.org/api/users/34/?format=json","username":"davem","first_name":"David","last_name":"Miller","email":"davem@davemloft.net"},"mbox":"http://patchwork.ozlabs.org/project/netdev/patch/20170925110738.68382-16-mika.westerberg@linux.intel.com/mbox/","series":[{"id":4937,"url":"http://patchwork.ozlabs.org/api/series/4937/?format=json","web_url":"http://patchwork.ozlabs.org/project/netdev/list/?series=4937","date":"2017-09-25T11:07:27","name":"Thunderbolt networking","version":2,"mbox":"http://patchwork.ozlabs.org/series/4937/mbox/"}],"comments":"http://patchwork.ozlabs.org/api/patches/818190/comments/","check":"pending","checks":"http://patchwork.ozlabs.org/api/patches/818190/checks/","tags":{},"related":[],"headers":{"Return-Path":"<netdev-owner@vger.kernel.org>","X-Original-To":"patchwork-incoming@ozlabs.org","Delivered-To":"patchwork-incoming@ozlabs.org","Authentication-Results":"ozlabs.org;\n\tspf=none (mailfrom) smtp.mailfrom=vger.kernel.org\n\t(client-ip=209.132.180.67; helo=vger.kernel.org;\n\tenvelope-from=netdev-owner@vger.kernel.org;\n\treceiver=<UNKNOWN>)","Received":["from vger.kernel.org (vger.kernel.org [209.132.180.67])\n\tby ozlabs.org (Postfix) with ESMTP id 3y11bY5QM8z9sPk\n\tfor <patchwork-incoming@ozlabs.org>;\n\tMon, 25 Sep 2017 21:10:49 +1000 (AEST)","(majordomo@vger.kernel.org) by vger.kernel.org via listexpand\n\tid S934207AbdIYLJ5 (ORCPT <rfc822;patchwork-incoming@ozlabs.org>);\n\tMon, 25 Sep 2017 07:09:57 -0400","from mga06.intel.com ([134.134.136.31]:20472 \"EHLO mga06.intel.com\"\n\trhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP\n\tid S934924AbdIYLHu (ORCPT <rfc822;netdev@vger.kernel.org>);\n\tMon, 25 Sep 2017 07:07:50 -0400","from fmsmga002.fm.intel.com ([10.253.24.26])\n\tby orsmga104.jf.intel.com with ESMTP; 25 Sep 2017 04:07:50 -0700","from black.fi.intel.com ([10.237.72.28])\n\tby fmsmga002.fm.intel.com with ESMTP; 25 Sep 2017 04:07:46 -0700","by black.fi.intel.com (Postfix, from userid 1001)\n\tid 22177467; Mon, 25 Sep 2017 14:07:39 +0300 (EEST)"],"X-ExtLoop1":"1","X-IronPort-AV":"E=Sophos;i=\"5.42,435,1500966000\"; d=\"scan'208\";a=\"1223333785\"","From":"Mika Westerberg <mika.westerberg@linux.intel.com>","To":"Greg Kroah-Hartman <gregkh@linuxfoundation.org>,\n\t\"David S . Miller\" <davem@davemloft.net>","Cc":"Andreas Noever <andreas.noever@gmail.com>,\n\tMichael Jamet <michael.jamet@intel.com>,\n\tYehezkel Bernat <yehezkel.bernat@intel.com>,\n\tAmir Levy <amir.jer.levy@intel.com>,\n\tMario.Limonciello@dell.com, Lukas Wunner <lukas@wunner.de>,\n\tAndy Shevchenko <andriy.shevchenko@linux.intel.com>,\n\tAndrew Lunn <andrew@lunn.ch>,\n\tMika Westerberg <mika.westerberg@linux.intel.com>,\n\tlinux-kernel@vger.kernel.org, netdev@vger.kernel.org","Subject":"[PATCH v2 15/16] thunderbolt: Allocate ring HopID automatically if\n\trequested","Date":"Mon, 25 Sep 2017 14:07:37 +0300","Message-Id":"<20170925110738.68382-16-mika.westerberg@linux.intel.com>","X-Mailer":"git-send-email 2.14.1","In-Reply-To":"<20170925110738.68382-1-mika.westerberg@linux.intel.com>","References":"<20170925110738.68382-1-mika.westerberg@linux.intel.com>","Sender":"netdev-owner@vger.kernel.org","Precedence":"bulk","List-ID":"<netdev.vger.kernel.org>","X-Mailing-List":"netdev@vger.kernel.org"},"content":"Thunderbolt services should not care which HopID (ring) they use for\nsending and receiving packets over the high-speed DMA path, so make\ntb_ring_alloc_rx() and tb_ring_alloc_tx() accept negative HopID. This\nmeans that the NHI will allocate next available HopID for the caller\nautomatically.\n\nThese HopIDs will be allocated from the range which is not reserved for\nthe Thunderbolt protocol (8 .. hop_count - 1).\n\nThe allocated HopID can be retrieved from ring->hop field after the ring\nhas been allocated successfully if needed.\n\nSigned-off-by: Mika Westerberg <mika.westerberg@linux.intel.com>\nReviewed-by: Michael Jamet <michael.jamet@intel.com>\nReviewed-by: Yehezkel Bernat <yehezkel.bernat@intel.com>\n---\n drivers/thunderbolt/nhi.c | 78 ++++++++++++++++++++++++++++++++++++-----------\n 1 file changed, 60 insertions(+), 18 deletions(-)","diff":"diff --git a/drivers/thunderbolt/nhi.c b/drivers/thunderbolt/nhi.c\nindex 5bc3f77cc1f3..b9e3980aa4fc 100644\n--- a/drivers/thunderbolt/nhi.c\n+++ b/drivers/thunderbolt/nhi.c\n@@ -26,6 +26,8 @@\n  * use this ring for anything else.\n  */\n #define RING_E2E_UNUSED_HOPID\t2\n+/* HopIDs 0-7 are reserved by the Thunderbolt protocol */\n+#define RING_FIRST_USABLE_HOPID\t8\n \n /*\n  * Minimal number of vectors when we use MSI-X. Two for control channel\n@@ -411,6 +413,62 @@ static void ring_release_msix(struct tb_ring *ring)\n \tring->irq = 0;\n }\n \n+static int nhi_alloc_hop(struct tb_nhi *nhi, struct tb_ring *ring)\n+{\n+\tint ret = 0;\n+\n+\tspin_lock_irq(&nhi->lock);\n+\n+\tif (ring->hop < 0) {\n+\t\tunsigned int i;\n+\n+\t\t/*\n+\t\t * Automatically allocate HopID from the non-reserved\n+\t\t * range 8 .. hop_count - 1.\n+\t\t */\n+\t\tfor (i = RING_FIRST_USABLE_HOPID; i < nhi->hop_count; i++) {\n+\t\t\tif (ring->is_tx) {\n+\t\t\t\tif (!nhi->tx_rings[i]) {\n+\t\t\t\t\tring->hop = i;\n+\t\t\t\t\tbreak;\n+\t\t\t\t}\n+\t\t\t} else {\n+\t\t\t\tif (!nhi->rx_rings[i]) {\n+\t\t\t\t\tring->hop = i;\n+\t\t\t\t\tbreak;\n+\t\t\t\t}\n+\t\t\t}\n+\t\t}\n+\t}\n+\n+\tif (ring->hop < 0 || ring->hop >= nhi->hop_count) {\n+\t\tdev_warn(&nhi->pdev->dev, \"invalid hop: %d\\n\", ring->hop);\n+\t\tret = -EINVAL;\n+\t\tgoto err_unlock;\n+\t}\n+\tif (ring->is_tx && nhi->tx_rings[ring->hop]) {\n+\t\tdev_warn(&nhi->pdev->dev, \"TX hop %d already allocated\\n\",\n+\t\t\t ring->hop);\n+\t\tret = -EBUSY;\n+\t\tgoto err_unlock;\n+\t} else if (!ring->is_tx && nhi->rx_rings[ring->hop]) {\n+\t\tdev_warn(&nhi->pdev->dev, \"RX hop %d already allocated\\n\",\n+\t\t\t ring->hop);\n+\t\tret = -EBUSY;\n+\t\tgoto err_unlock;\n+\t}\n+\n+\tif (ring->is_tx)\n+\t\tnhi->tx_rings[ring->hop] = ring;\n+\telse\n+\t\tnhi->rx_rings[ring->hop] = ring;\n+\n+err_unlock:\n+\tspin_unlock_irq(&nhi->lock);\n+\n+\treturn ret;\n+}\n+\n static struct tb_ring *tb_ring_alloc(struct tb_nhi *nhi, u32 hop, int size,\n \t\t\t\t     bool transmit, unsigned int flags,\n \t\t\t\t     u16 sof_mask, u16 eof_mask,\n@@ -456,28 +514,12 @@ static struct tb_ring *tb_ring_alloc(struct tb_nhi *nhi, u32 hop, int size,\n \tif (ring_request_msix(ring, flags & RING_FLAG_NO_SUSPEND))\n \t\tgoto err_free_descs;\n \n-\tspin_lock_irq(&nhi->lock);\n-\tif (hop >= nhi->hop_count) {\n-\t\tdev_WARN(&nhi->pdev->dev, \"invalid hop: %d\\n\", hop);\n+\tif (nhi_alloc_hop(nhi, ring))\n \t\tgoto err_release_msix;\n-\t}\n-\tif (transmit && nhi->tx_rings[hop]) {\n-\t\tdev_WARN(&nhi->pdev->dev, \"TX hop %d already allocated\\n\", hop);\n-\t\tgoto err_release_msix;\n-\t} else if (!transmit && nhi->rx_rings[hop]) {\n-\t\tdev_WARN(&nhi->pdev->dev, \"RX hop %d already allocated\\n\", hop);\n-\t\tgoto err_release_msix;\n-\t}\n-\tif (transmit)\n-\t\tnhi->tx_rings[hop] = ring;\n-\telse\n-\t\tnhi->rx_rings[hop] = ring;\n-\tspin_unlock_irq(&nhi->lock);\n \n \treturn ring;\n \n err_release_msix:\n-\tspin_unlock_irq(&nhi->lock);\n \tring_release_msix(ring);\n err_free_descs:\n \tdma_free_coherent(&ring->nhi->pdev->dev,\n@@ -506,7 +548,7 @@ EXPORT_SYMBOL_GPL(tb_ring_alloc_tx);\n /**\n  * tb_ring_alloc_rx() - Allocate DMA ring for receive\n  * @nhi: Pointer to the NHI the ring is to be allocated\n- * @hop: HopID (ring) to allocate\n+ * @hop: HopID (ring) to allocate. Pass %-1 for automatic allocation.\n  * @size: Number of entries in the ring\n  * @flags: Flags for the ring\n  * @sof_mask: Mask of PDF values that start a frame\n","prefixes":["v2","15/16"]}