• [PATCH v3 09/19] thunderbolt: Add support for frame mode

    From Mika Westerberg@21:1/5 to All on Mon Oct 2 12:50:02 2017
    When high-speed DMA paths are used to transfer arbitrary data over a Thunderbolt link, DMA rings should be in frame mode instead of raw mode.
    The latter is used by the control channel (ring 0). In frame mode each
    data frame can hold up to 4kB payload.

    This patch modifies the DMA ring code to allow configuring a ring to be
    in frame mode by passing a new flag (RING_FLAG_FRAME) to the ring when
    it is allocated. In addition there might be need to enable end-to-end
    (E2E) workaround for the ring to prevent losing Rx frames in certain situations. We add another flag (RING_FLAG_E2E) that can be used for
    this purpose.

    This code is based on the work done by Amir Levy and Michael Jamet.

    Signed-off-by: Michael Jamet <michael.jamet@intel.com>
    Signed-off-by: Mika Westerberg <mika.westerberg@linux.intel.com>
    Reviewed-by: Yehezkel Bernat <yehezkel.bernat@intel.com>
    Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
    ---
    drivers/thunderbolt/ctl.c | 3 +-
    drivers/thunderbolt/nhi.c | 76 ++++++++++++++++++++++++++----------------
    drivers/thunderbolt/nhi.h | 10 +++++-
    drivers/thunderbolt/nhi_regs.h | 2 ++
    4 files changed, 61 insertions(+), 30 deletions(-)

    diff --git a/drivers/thunderbolt/ctl.c b/drivers/thunderbolt/ctl.c
    index 46e393c5fd1d..05400b77dcd7 100644
    --- a/drivers/thunderbolt/ctl.c
    +++ b/drivers/thunderbolt/ctl.c
    @@ -618,7 +618,8 @@ struct tb_ctl *tb_ctl_alloc(struct tb_nhi *nhi, event_cb cb, void *cb_data)
    if (!ctl->tx)
    goto err;

    - ctl->rx = ring_alloc_rx(nhi, 0, 10, RING_FLAG_NO_SUSPEND);
    + ctl->rx = ring_alloc_rx(nhi, 0, 10, RING_FLAG_NO_SUSPEND, 0xffff,
    + 0xffff);
    if (!ctl->rx)
    goto err;

    diff --git a/drivers/thunderbolt/nhi.c b/drivers/thunderbolt/nhi.c
    index 8a7a3d0133f9..bebcad3d2c1f 100644
    --- a/drivers/thunderbolt/nhi.c
    +++ b/drivers/thunderbolt/nhi.c
    @@ -21,6 +21,12 @@

    #define RING_TYPE(ring) ((ring)->is_tx ? "TX ring" : "RX ring")

    +/*
    +