get:
Show a patch.

patch:
Update a patch.

put:
Update a patch.

GET /api/patches/814980/?format=api
HTTP 200 OK
Allow: GET, PUT, PATCH, HEAD, OPTIONS
Content-Type: application/json
Vary: Accept

{
    "id": 814980,
    "url": "http://patchwork.ozlabs.org/api/patches/814980/?format=api",
    "web_url": "http://patchwork.ozlabs.org/project/netdev/patch/20170918153049.44185-10-mika.westerberg@linux.intel.com/",
    "project": {
        "id": 7,
        "url": "http://patchwork.ozlabs.org/api/projects/7/?format=api",
        "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": "<20170918153049.44185-10-mika.westerberg@linux.intel.com>",
    "list_archive_url": null,
    "date": "2017-09-18T15:30:42",
    "name": "[09/16] thunderbolt: Export ring handling functions to modules",
    "commit_ref": null,
    "pull_url": null,
    "state": "not-applicable",
    "archived": true,
    "hash": "3e80208d29018d5ce4d437a3caa3d387a4fd088f",
    "submitter": {
        "id": 14534,
        "url": "http://patchwork.ozlabs.org/api/people/14534/?format=api",
        "name": "Mika Westerberg",
        "email": "mika.westerberg@linux.intel.com"
    },
    "delegate": {
        "id": 34,
        "url": "http://patchwork.ozlabs.org/api/users/34/?format=api",
        "username": "davem",
        "first_name": "David",
        "last_name": "Miller",
        "email": "davem@davemloft.net"
    },
    "mbox": "http://patchwork.ozlabs.org/project/netdev/patch/20170918153049.44185-10-mika.westerberg@linux.intel.com/mbox/",
    "series": [
        {
            "id": 3664,
            "url": "http://patchwork.ozlabs.org/api/series/3664/?format=api",
            "web_url": "http://patchwork.ozlabs.org/project/netdev/list/?series=3664",
            "date": "2017-09-18T15:30:47",
            "name": "Thunderbolt networking",
            "version": 1,
            "mbox": "http://patchwork.ozlabs.org/series/3664/mbox/"
        }
    ],
    "comments": "http://patchwork.ozlabs.org/api/patches/814980/comments/",
    "check": "pending",
    "checks": "http://patchwork.ozlabs.org/api/patches/814980/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 3xwqmL24LVz9s78\n\tfor <patchwork-incoming@ozlabs.org>;\n\tTue, 19 Sep 2017 01:33:54 +1000 (AEST)",
            "(majordomo@vger.kernel.org) by vger.kernel.org via listexpand\n\tid S1755495AbdIRPbC (ORCPT <rfc822;patchwork-incoming@ozlabs.org>);\n\tMon, 18 Sep 2017 11:31:02 -0400",
            "from mga11.intel.com ([192.55.52.93]:27612 \"EHLO mga11.intel.com\"\n\trhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP\n\tid S1753735AbdIRPa6 (ORCPT <rfc822;netdev@vger.kernel.org>);\n\tMon, 18 Sep 2017 11:30:58 -0400",
            "from fmsmga004.fm.intel.com ([10.253.24.48])\n\tby fmsmga102.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384;\n\t18 Sep 2017 08:30:57 -0700",
            "from black.fi.intel.com ([10.237.72.28])\n\tby fmsmga004.fm.intel.com with ESMTP; 18 Sep 2017 08:30:54 -0700",
            "by black.fi.intel.com (Postfix, from userid 1001)\n\tid C6D8C5D7; Mon, 18 Sep 2017 18:30:49 +0300 (EEST)"
        ],
        "X-ExtLoop1": "1",
        "X-IronPort-AV": "E=Sophos;i=\"5.42,413,1500966000\"; d=\"scan'208\";a=\"312962535\"",
        "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\tMika Westerberg <mika.westerberg@linux.intel.com>,\n\tlinux-kernel@vger.kernel.org, netdev@vger.kernel.org",
        "Subject": "[PATCH 09/16] thunderbolt: Export ring handling functions to modules",
        "Date": "Mon, 18 Sep 2017 18:30:42 +0300",
        "Message-Id": "<20170918153049.44185-10-mika.westerberg@linux.intel.com>",
        "X-Mailer": "git-send-email 2.14.1",
        "In-Reply-To": "<20170918153049.44185-1-mika.westerberg@linux.intel.com>",
        "References": "<20170918153049.44185-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": "These are used by Thunderbolt services to send and receive frames over\nthe high-speed DMA rings.\n\nWe also put the functions to tb_ namespace to make sure we do not\ncollide with others and add missing kernel-doc comments for the exported\nfunctions.\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/ctl.c   |  20 +++---\n drivers/thunderbolt/nhi.c   |  62 +++++++++++------\n drivers/thunderbolt/nhi.h   | 147 +----------------------------------------\n include/linux/thunderbolt.h | 158 ++++++++++++++++++++++++++++++++++++++++++++\n 4 files changed, 211 insertions(+), 176 deletions(-)",
    "diff": "diff --git a/drivers/thunderbolt/ctl.c b/drivers/thunderbolt/ctl.c\nindex 05400b77dcd7..dd10789e1dbb 100644\n--- a/drivers/thunderbolt/ctl.c\n+++ b/drivers/thunderbolt/ctl.c\n@@ -359,7 +359,7 @@ static int tb_ctl_tx(struct tb_ctl *ctl, const void *data, size_t len,\n \tcpu_to_be32_array(pkg->buffer, data, len / 4);\n \t*(__be32 *) (pkg->buffer + len) = tb_crc(pkg->buffer, len);\n \n-\tres = ring_tx(ctl->tx, &pkg->frame);\n+\tres = tb_ring_tx(ctl->tx, &pkg->frame);\n \tif (res) /* ring is stopped */\n \t\ttb_ctl_pkg_free(pkg);\n \treturn res;\n@@ -376,7 +376,7 @@ static bool tb_ctl_handle_event(struct tb_ctl *ctl, enum tb_cfg_pkg_type type,\n \n static void tb_ctl_rx_submit(struct ctl_pkg *pkg)\n {\n-\tring_rx(pkg->ctl->rx, &pkg->frame); /*\n+\ttb_ring_rx(pkg->ctl->rx, &pkg->frame); /*\n \t\t\t\t\t     * We ignore failures during stop.\n \t\t\t\t\t     * All rx packets are referenced\n \t\t\t\t\t     * from ctl->rx_packets, so we do\n@@ -614,11 +614,11 @@ struct tb_ctl *tb_ctl_alloc(struct tb_nhi *nhi, event_cb cb, void *cb_data)\n \tif (!ctl->frame_pool)\n \t\tgoto err;\n \n-\tctl->tx = ring_alloc_tx(nhi, 0, 10, RING_FLAG_NO_SUSPEND);\n+\tctl->tx = tb_ring_alloc_tx(nhi, 0, 10, RING_FLAG_NO_SUSPEND);\n \tif (!ctl->tx)\n \t\tgoto err;\n \n-\tctl->rx = ring_alloc_rx(nhi, 0, 10, RING_FLAG_NO_SUSPEND, 0xffff,\n+\tctl->rx = tb_ring_alloc_rx(nhi, 0, 10, RING_FLAG_NO_SUSPEND, 0xffff,\n \t\t\t\t0xffff);\n \tif (!ctl->rx)\n \t\tgoto err;\n@@ -652,9 +652,9 @@ void tb_ctl_free(struct tb_ctl *ctl)\n \t\treturn;\n \n \tif (ctl->rx)\n-\t\tring_free(ctl->rx);\n+\t\ttb_ring_free(ctl->rx);\n \tif (ctl->tx)\n-\t\tring_free(ctl->tx);\n+\t\ttb_ring_free(ctl->tx);\n \n \t/* free RX packets */\n \tfor (i = 0; i < TB_CTL_RX_PKG_COUNT; i++)\n@@ -673,8 +673,8 @@ void tb_ctl_start(struct tb_ctl *ctl)\n {\n \tint i;\n \ttb_ctl_info(ctl, \"control channel starting...\\n\");\n-\tring_start(ctl->tx); /* is used to ack hotplug packets, start first */\n-\tring_start(ctl->rx);\n+\ttb_ring_start(ctl->tx); /* is used to ack hotplug packets, start first */\n+\ttb_ring_start(ctl->rx);\n \tfor (i = 0; i < TB_CTL_RX_PKG_COUNT; i++)\n \t\ttb_ctl_rx_submit(ctl->rx_packets[i]);\n \n@@ -695,8 +695,8 @@ void tb_ctl_stop(struct tb_ctl *ctl)\n \tctl->running = false;\n \tmutex_unlock(&ctl->request_queue_lock);\n \n-\tring_stop(ctl->rx);\n-\tring_stop(ctl->tx);\n+\ttb_ring_stop(ctl->rx);\n+\ttb_ring_stop(ctl->tx);\n \n \tif (!list_empty(&ctl->request_queue))\n \t\ttb_ctl_WARN(ctl, \"dangling request in request_queue\\n\");\ndiff --git a/drivers/thunderbolt/nhi.c b/drivers/thunderbolt/nhi.c\nindex cde8b6d46147..4704ccd20c84 100644\n--- a/drivers/thunderbolt/nhi.c\n+++ b/drivers/thunderbolt/nhi.c\n@@ -253,7 +253,7 @@ static void ring_work(struct work_struct *work)\n \t}\n }\n \n-int __ring_enqueue(struct tb_ring *ring, struct ring_frame *frame)\n+int __tb_ring_enqueue(struct tb_ring *ring, struct ring_frame *frame)\n {\n \tint ret = 0;\n \tmutex_lock(&ring->lock);\n@@ -266,6 +266,7 @@ int __ring_enqueue(struct tb_ring *ring, struct ring_frame *frame)\n \tmutex_unlock(&ring->lock);\n \treturn ret;\n }\n+EXPORT_SYMBOL_GPL(__tb_ring_enqueue);\n \n static irqreturn_t ring_msix(int irq, void *data)\n {\n@@ -309,9 +310,9 @@ static void ring_release_msix(struct tb_ring *ring)\n \tring->irq = 0;\n }\n \n-static struct tb_ring *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+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 {\n \tstruct tb_ring *ring = NULL;\n \tdev_info(&nhi->pdev->dev, \"allocating %s ring %d of size %d\\n\",\n@@ -377,24 +378,42 @@ static struct tb_ring *ring_alloc(struct tb_nhi *nhi, u32 hop, int size,\n \treturn NULL;\n }\n \n-struct tb_ring *ring_alloc_tx(struct tb_nhi *nhi, int hop, int size,\n-\t\t\t      unsigned int flags)\n+/**\n+ * tb_ring_alloc_tx() - Allocate DMA ring for transmit\n+ * @nhi: Pointer to the NHI the ring is to be allocated\n+ * @hop: HopID (ring) to allocate\n+ * @size: Number of entries in the ring\n+ * @flags: Flags for the ring\n+ */\n+struct tb_ring *tb_ring_alloc_tx(struct tb_nhi *nhi, int hop, int size,\n+\t\t\t\t unsigned int flags)\n {\n-\treturn ring_alloc(nhi, hop, size, true, flags, 0, 0);\n+\treturn tb_ring_alloc(nhi, hop, size, true, flags, 0, 0);\n }\n+EXPORT_SYMBOL_GPL(tb_ring_alloc_tx);\n \n-struct tb_ring *ring_alloc_rx(struct tb_nhi *nhi, int hop, int size,\n-\t\t\t      unsigned int flags, u16 sof_mask, u16 eof_mask)\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+ * @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+ * @eof_mask: Mask of PDF values that end a frame\n+ */\n+struct tb_ring *tb_ring_alloc_rx(struct tb_nhi *nhi, int hop, int size,\n+\t\t\t\t unsigned int flags, u16 sof_mask, u16 eof_mask)\n {\n-\treturn ring_alloc(nhi, hop, size, false, flags, sof_mask, eof_mask);\n+\treturn tb_ring_alloc(nhi, hop, size, false, flags, sof_mask, eof_mask);\n }\n+EXPORT_SYMBOL_GPL(tb_ring_alloc_rx);\n \n /**\n- * ring_start() - enable a ring\n+ * tb_ring_start() - enable a ring\n  *\n- * Must not be invoked in parallel with ring_stop().\n+ * Must not be invoked in parallel with tb_ring_stop().\n  */\n-void ring_start(struct tb_ring *ring)\n+void tb_ring_start(struct tb_ring *ring)\n {\n \tu16 frame_size;\n \tu32 flags;\n@@ -450,21 +469,22 @@ void ring_start(struct tb_ring *ring)\n \tmutex_unlock(&ring->lock);\n \tmutex_unlock(&ring->nhi->lock);\n }\n-\n+EXPORT_SYMBOL_GPL(tb_ring_start);\n \n /**\n- * ring_stop() - shutdown a ring\n+ * tb_ring_stop() - shutdown a ring\n  *\n  * Must not be invoked from a callback.\n  *\n- * This method will disable the ring. Further calls to ring_tx/ring_rx will\n- * return -ESHUTDOWN until ring_stop has been called.\n+ * This method will disable the ring. Further calls to\n+ * tb_ring_tx/tb_ring_rx will return -ESHUTDOWN until ring_stop has been\n+ * called.\n  *\n  * All enqueued frames will be canceled and their callbacks will be executed\n  * with frame->canceled set to true (on the callback thread). This method\n  * returns only after all callback invocations have finished.\n  */\n-void ring_stop(struct tb_ring *ring)\n+void tb_ring_stop(struct tb_ring *ring)\n {\n \tmutex_lock(&ring->nhi->lock);\n \tmutex_lock(&ring->lock);\n@@ -497,9 +517,10 @@ void ring_stop(struct tb_ring *ring)\n \tschedule_work(&ring->work);\n \tflush_work(&ring->work);\n }\n+EXPORT_SYMBOL_GPL(tb_ring_stop);\n \n /*\n- * ring_free() - free ring\n+ * tb_ring_free() - free ring\n  *\n  * When this method returns all invocations of ring->callback will have\n  * finished.\n@@ -508,7 +529,7 @@ void ring_stop(struct tb_ring *ring)\n  *\n  * Must NOT be called from ring_frame->callback!\n  */\n-void ring_free(struct tb_ring *ring)\n+void tb_ring_free(struct tb_ring *ring)\n {\n \tmutex_lock(&ring->nhi->lock);\n \t/*\n@@ -550,6 +571,7 @@ void ring_free(struct tb_ring *ring)\n \tmutex_destroy(&ring->lock);\n \tkfree(ring);\n }\n+EXPORT_SYMBOL_GPL(tb_ring_free);\n \n /**\n  * nhi_mailbox_cmd() - Send a command through NHI mailbox\ndiff --git a/drivers/thunderbolt/nhi.h b/drivers/thunderbolt/nhi.h\nindex 4503ddbeccb3..771d09ca5dc5 100644\n--- a/drivers/thunderbolt/nhi.h\n+++ b/drivers/thunderbolt/nhi.h\n@@ -7,152 +7,7 @@\n #ifndef DSL3510_H_\n #define DSL3510_H_\n \n-#include <linux/idr.h>\n-#include <linux/mutex.h>\n-#include <linux/workqueue.h>\n-\n-/**\n- * struct tb_nhi - thunderbolt native host interface\n- * @lock: Must be held during ring creation/destruction. Is acquired by\n- *\t  interrupt_work when dispatching interrupts to individual rings.\n- * @pdev: Pointer to the PCI device\n- * @iobase: MMIO space of the NHI\n- * @tx_rings: All Tx rings available on this host controller\n- * @rx_rings: All Rx rings available on this host controller\n- * @msix_ida: Used to allocate MSI-X vectors for rings\n- * @going_away: The host controller device is about to disappear so when\n- *\t\tthis flag is set, avoid touching the hardware anymore.\n- * @interrupt_work: Work scheduled to handle ring interrupt when no\n- *\t\t    MSI-X is used.\n- * @hop_count: Number of rings (end point hops) supported by NHI.\n- */\n-struct tb_nhi {\n-\tstruct mutex lock;\n-\tstruct pci_dev *pdev;\n-\tvoid __iomem *iobase;\n-\tstruct tb_ring **tx_rings;\n-\tstruct tb_ring **rx_rings;\n-\tstruct ida msix_ida;\n-\tbool going_away;\n-\tstruct work_struct interrupt_work;\n-\tu32 hop_count;\n-};\n-\n-/**\n- * struct tb_ring - thunderbolt TX or RX ring associated with a NHI\n- * @lock: Lock serializing actions to this ring. Must be acquired after\n- *\t  nhi->lock.\n- * @nhi: Pointer to the native host controller interface\n- * @size: Size of the ring\n- * @hop: Hop (DMA channel) associated with this ring\n- * @head: Head of the ring (write next descriptor here)\n- * @tail: Tail of the ring (complete next descriptor here)\n- * @descriptors: Allocated descriptors for this ring\n- * @queue: Queue holding frames to be transferred over this ring\n- * @in_flight: Queue holding frames that are currently in flight\n- * @work: Interrupt work structure\n- * @is_tx: Is the ring Tx or Rx\n- * @running: Is the ring running\n- * @irq: MSI-X irq number if the ring uses MSI-X. %0 otherwise.\n- * @vector: MSI-X vector number the ring uses (only set if @irq is > 0)\n- * @flags: Ring specific flags\n- * @sof_mask: Bit mask used to detect start of frame PDF\n- * @eof_mask: Bit mask used to detect end of frame PDF\n- */\n-struct tb_ring {\n-\tstruct mutex lock;\n-\tstruct tb_nhi *nhi;\n-\tint size;\n-\tint hop;\n-\tint head;\n-\tint tail;\n-\tstruct ring_desc *descriptors;\n-\tdma_addr_t descriptors_dma;\n-\tstruct list_head queue;\n-\tstruct list_head in_flight;\n-\tstruct work_struct work;\n-\tbool is_tx:1;\n-\tbool running:1;\n-\tint irq;\n-\tu8 vector;\n-\tunsigned int flags;\n-\tu16 sof_mask;\n-\tu16 eof_mask;\n-};\n-\n-/* Leave ring interrupt enabled on suspend */\n-#define RING_FLAG_NO_SUSPEND\tBIT(0)\n-/* Configure the ring to be in frame mode */\n-#define RING_FLAG_FRAME\t\tBIT(1)\n-/* Enable end-to-end flow control */\n-#define RING_FLAG_E2E\t\tBIT(2)\n-\n-struct ring_frame;\n-typedef void (*ring_cb)(struct tb_ring*, struct ring_frame*, bool canceled);\n-\n-/**\n- * struct ring_frame - for use with ring_rx/ring_tx\n- */\n-struct ring_frame {\n-\tdma_addr_t buffer_phy;\n-\tring_cb callback;\n-\tstruct list_head list;\n-\tu32 size:12; /* TX: in, RX: out*/\n-\tu32 flags:12; /* RX: out */\n-\tu32 eof:4; /* TX:in, RX: out */\n-\tu32 sof:4; /* TX:in, RX: out */\n-};\n-\n-#define TB_FRAME_SIZE 0x100    /* minimum size for ring_rx */\n-\n-struct tb_ring *ring_alloc_tx(struct tb_nhi *nhi, int hop, int size,\n-\t\t\t      unsigned int flags);\n-struct tb_ring *ring_alloc_rx(struct tb_nhi *nhi, int hop, int size,\n-\t\t\t      unsigned int flags, u16 sof_mask, u16 eof_mask);\n-void ring_start(struct tb_ring *ring);\n-void ring_stop(struct tb_ring *ring);\n-void ring_free(struct tb_ring *ring);\n-\n-int __ring_enqueue(struct tb_ring *ring, struct ring_frame *frame);\n-\n-/**\n- * ring_rx() - enqueue a frame on an RX ring\n- *\n- * frame->buffer, frame->buffer_phy and frame->callback have to be set. The\n- * buffer must contain at least TB_FRAME_SIZE bytes.\n- *\n- * frame->callback will be invoked with frame->size, frame->flags, frame->eof,\n- * frame->sof set once the frame has been received.\n- *\n- * If ring_stop is called after the packet has been enqueued frame->callback\n- * will be called with canceled set to true.\n- *\n- * Return: Returns ESHUTDOWN if ring_stop has been called. Zero otherwise.\n- */\n-static inline int ring_rx(struct tb_ring *ring, struct ring_frame *frame)\n-{\n-\tWARN_ON(ring->is_tx);\n-\treturn __ring_enqueue(ring, frame);\n-}\n-\n-/**\n- * ring_tx() - enqueue a frame on an TX ring\n- *\n- * frame->buffer, frame->buffer_phy, frame->callback, frame->size, frame->eof\n- * and frame->sof have to be set.\n- *\n- * frame->callback will be invoked with once the frame has been transmitted.\n- *\n- * If ring_stop is called after the packet has been enqueued frame->callback\n- * will be called with canceled set to true.\n- *\n- * Return: Returns ESHUTDOWN if ring_stop has been called. Zero otherwise.\n- */\n-static inline int ring_tx(struct tb_ring *ring, struct ring_frame *frame)\n-{\n-\tWARN_ON(!ring->is_tx);\n-\treturn __ring_enqueue(ring, frame);\n-}\n+#include <linux/thunderbolt.h>\n \n enum nhi_fw_mode {\n \tNHI_FW_SAFE_MODE,\ndiff --git a/include/linux/thunderbolt.h b/include/linux/thunderbolt.h\nindex 79abdaf1c296..1a376374c327 100644\n--- a/include/linux/thunderbolt.h\n+++ b/include/linux/thunderbolt.h\n@@ -15,10 +15,12 @@\n #define THUNDERBOLT_H_\n \n #include <linux/device.h>\n+#include <linux/idr.h>\n #include <linux/list.h>\n #include <linux/mutex.h>\n #include <linux/mod_devicetable.h>\n #include <linux/uuid.h>\n+#include <linux/workqueue.h>\n \n enum tb_cfg_pkg_type {\n \tTB_CFG_PKG_READ = 1,\n@@ -397,4 +399,160 @@ static inline struct tb_xdomain *tb_service_parent(struct tb_service *svc)\n \treturn tb_to_xdomain(svc->dev.parent);\n }\n \n+/**\n+ * struct tb_nhi - thunderbolt native host interface\n+ * @lock: Must be held during ring creation/destruction. Is acquired by\n+ *\t  interrupt_work when dispatching interrupts to individual rings.\n+ * @pdev: Pointer to the PCI device\n+ * @iobase: MMIO space of the NHI\n+ * @tx_rings: All Tx rings available on this host controller\n+ * @rx_rings: All Rx rings available on this host controller\n+ * @msix_ida: Used to allocate MSI-X vectors for rings\n+ * @going_away: The host controller device is about to disappear so when\n+ *\t\tthis flag is set, avoid touching the hardware anymore.\n+ * @interrupt_work: Work scheduled to handle ring interrupt when no\n+ *\t\t    MSI-X is used.\n+ * @hop_count: Number of rings (end point hops) supported by NHI.\n+ */\n+struct tb_nhi {\n+\tstruct mutex lock;\n+\tstruct pci_dev *pdev;\n+\tvoid __iomem *iobase;\n+\tstruct tb_ring **tx_rings;\n+\tstruct tb_ring **rx_rings;\n+\tstruct ida msix_ida;\n+\tbool going_away;\n+\tstruct work_struct interrupt_work;\n+\tu32 hop_count;\n+};\n+\n+/**\n+ * struct tb_ring - thunderbolt TX or RX ring associated with a NHI\n+ * @lock: Lock serializing actions to this ring. Must be acquired after\n+ *\t  nhi->lock.\n+ * @nhi: Pointer to the native host controller interface\n+ * @size: Size of the ring\n+ * @hop: Hop (DMA channel) associated with this ring\n+ * @head: Head of the ring (write next descriptor here)\n+ * @tail: Tail of the ring (complete next descriptor here)\n+ * @descriptors: Allocated descriptors for this ring\n+ * @queue: Queue holding frames to be transferred over this ring\n+ * @in_flight: Queue holding frames that are currently in flight\n+ * @work: Interrupt work structure\n+ * @is_tx: Is the ring Tx or Rx\n+ * @running: Is the ring running\n+ * @irq: MSI-X irq number if the ring uses MSI-X. %0 otherwise.\n+ * @vector: MSI-X vector number the ring uses (only set if @irq is > 0)\n+ * @flags: Ring specific flags\n+ * @sof_mask: Bit mask used to detect start of frame PDF\n+ * @eof_mask: Bit mask used to detect end of frame PDF\n+ */\n+struct tb_ring {\n+\tstruct mutex lock;\n+\tstruct tb_nhi *nhi;\n+\tint size;\n+\tint hop;\n+\tint head;\n+\tint tail;\n+\tstruct ring_desc *descriptors;\n+\tdma_addr_t descriptors_dma;\n+\tstruct list_head queue;\n+\tstruct list_head in_flight;\n+\tstruct work_struct work;\n+\tbool is_tx:1;\n+\tbool running:1;\n+\tint irq;\n+\tu8 vector;\n+\tunsigned int flags;\n+\tu16 sof_mask;\n+\tu16 eof_mask;\n+};\n+\n+/* Leave ring interrupt enabled on suspend */\n+#define RING_FLAG_NO_SUSPEND\tBIT(0)\n+/* Configure the ring to be in frame mode */\n+#define RING_FLAG_FRAME\t\tBIT(1)\n+/* Enable end-to-end flow control */\n+#define RING_FLAG_E2E\t\tBIT(2)\n+\n+struct ring_frame;\n+typedef void (*ring_cb)(struct tb_ring *, struct ring_frame *, bool canceled);\n+\n+/**\n+ * struct ring_frame - For use with ring_rx/ring_tx\n+ * @buffer_phy: DMA mapped address of the frame\n+ * @callback: Callback called when the frame is finished\n+ * @list: Frame is linked to a queue using this\n+ * @size: Size of the frame in bytes (%0 means %4096)\n+ * @flags: Flags for the frame (see &enum ring_desc_flags)\n+ * @eof: End of frame protocol defined field\n+ * @sof: Start of frame protocol defined field\n+ */\n+struct ring_frame {\n+\tdma_addr_t buffer_phy;\n+\tring_cb callback;\n+\tstruct list_head list;\n+\tu32 size:12;\n+\tu32 flags:12;\n+\tu32 eof:4;\n+\tu32 sof:4;\n+};\n+\n+/* Minimum size for ring_rx */\n+#define TB_FRAME_SIZE\t\t0x100\n+\n+struct tb_ring *tb_ring_alloc_tx(struct tb_nhi *nhi, int hop, int size,\n+\t\t\t\t unsigned int flags);\n+struct tb_ring *tb_ring_alloc_rx(struct tb_nhi *nhi, int hop, int size,\n+\t\t\t\t unsigned int flags, u16 sof_mask,\n+\t\t\t\t u16 eof_mask);\n+void tb_ring_start(struct tb_ring *ring);\n+void tb_ring_stop(struct tb_ring *ring);\n+void tb_ring_free(struct tb_ring *ring);\n+\n+int __tb_ring_enqueue(struct tb_ring *ring, struct ring_frame *frame);\n+\n+/**\n+ * tb_ring_rx() - enqueue a frame on an RX ring\n+ * @ring: Ring to enqueue the frame\n+ * @frame: Frame to enqueue\n+ *\n+ * @frame->buffer, @frame->buffer_phy and @frame->callback have to be set. The\n+ * buffer must contain at least %TB_FRAME_SIZE bytes.\n+ *\n+ * @frame->callback will be invoked with @frame->size, @frame->flags,\n+ * @frame->eof, @frame->sof set once the frame has been received.\n+ *\n+ * If ring_stop() is called after the packet has been enqueued\n+ * @frame->callback will be called with canceled set to true.\n+ *\n+ * Return: Returns %-ESHUTDOWN if ring_stop has been called. Zero otherwise.\n+ */\n+static inline int tb_ring_rx(struct tb_ring *ring, struct ring_frame *frame)\n+{\n+\tWARN_ON(ring->is_tx);\n+\treturn __tb_ring_enqueue(ring, frame);\n+}\n+\n+/**\n+ * tb_ring_tx() - enqueue a frame on an TX ring\n+ * @ring: Ring the enqueue the frame\n+ * @frame: Frame to enqueue\n+ *\n+ * @frame->buffer, @frame->buffer_phy, @frame->callback, @frame->size,\n+ * @frame->eof and @frame->sof have to be set.\n+ *\n+ * @frame->callback will be invoked with once the frame has been transmitted.\n+ *\n+ * If ring_stop() is called after the packet has been enqueued @frame->callback\n+ * will be called with canceled set to true.\n+ *\n+ * Return: Returns %-ESHUTDOWN if ring_stop has been called. Zero otherwise.\n+ */\n+static inline int tb_ring_tx(struct tb_ring *ring, struct ring_frame *frame)\n+{\n+\tWARN_ON(!ring->is_tx);\n+\treturn __tb_ring_enqueue(ring, frame);\n+}\n+\n #endif /* THUNDERBOLT_H_ */\n",
    "prefixes": [
        "09/16"
    ]
}