All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0/2] thunderbolt: Fix buffers allocation for device without DisplayPort adaptors
@ 2022-05-09 20:49 Gil Fine
  2022-05-09 20:49 ` [PATCH 1/2] " Gil Fine
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Gil Fine @ 2022-05-09 20:49 UTC (permalink / raw)
  To: andreas.noever, michael.jamet, mika.westerberg, YehezkelShB
  Cc: gil.fine, linux-usb, lukas

For the case of device without DP adaptors, we calculate incorrectly the
buffers allocation. Here we fix the calculation for this case.
In addition, we add a KUnit test for this case.

Gil Fine (2):
  thunderbolt: Fix buffers allocation for device without DisplayPort
    adaptors
  thunderbolt: Add KUnit test for buffer allocation for device without
    DisplayPort adaptors

 drivers/thunderbolt/test.c   | 92 ++++++++++++++++++++++++++++++++++++
 drivers/thunderbolt/tunnel.c |  7 ++-
 2 files changed, 97 insertions(+), 2 deletions(-)

-- 
2.17.1

---------------------------------------------------------------------
Intel Israel (74) Limited

This e-mail and any attachments may contain confidential material for
the sole use of the intended recipient(s). Any review or distribution
by others is strictly prohibited. If you are not the intended
recipient, please contact the sender and delete all copies.


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH 1/2] thunderbolt: Fix buffers allocation for device without DisplayPort adaptors
  2022-05-09 20:49 [PATCH 0/2] thunderbolt: Fix buffers allocation for device without DisplayPort adaptors Gil Fine
@ 2022-05-09 20:49 ` Gil Fine
  2022-05-09 20:49 ` [PATCH 2/2] thunderbolt: Add KUnit test for buffer " Gil Fine
  2022-05-12  6:27 ` [PATCH 0/2] thunderbolt: Fix buffers " Mika Westerberg
  2 siblings, 0 replies; 4+ messages in thread
From: Gil Fine @ 2022-05-09 20:49 UTC (permalink / raw)
  To: andreas.noever, michael.jamet, mika.westerberg, YehezkelShB
  Cc: gil.fine, linux-usb, lukas

For the case of device without DP adaptors, we calculate incorrectly the
buffers allocation. Here we fix the calculation for this case.

Signed-off-by: Gil Fine <gil.fine@intel.com>
---
 drivers/thunderbolt/tunnel.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/drivers/thunderbolt/tunnel.c b/drivers/thunderbolt/tunnel.c
index 8ccd70920b6a..2c3cf7fc3357 100644
--- a/drivers/thunderbolt/tunnel.c
+++ b/drivers/thunderbolt/tunnel.c
@@ -102,8 +102,11 @@ static unsigned int tb_available_credits(const struct tb_port *port,
 		 * Maximum number of DP streams possible through the
 		 * lane adapter.
 		 */
-		ndp = (credits - (usb3 + pcie + spare)) /
-		      (sw->min_dp_aux_credits + sw->min_dp_main_credits);
+		if (sw->min_dp_aux_credits + sw->min_dp_main_credits)
+			ndp = (credits - (usb3 + pcie + spare)) /
+			      (sw->min_dp_aux_credits + sw->min_dp_main_credits);
+		else
+			ndp = 0;
 	} else {
 		ndp = 0;
 	}
-- 
2.17.1

---------------------------------------------------------------------
Intel Israel (74) Limited

This e-mail and any attachments may contain confidential material for
the sole use of the intended recipient(s). Any review or distribution
by others is strictly prohibited. If you are not the intended
recipient, please contact the sender and delete all copies.


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PATCH 2/2] thunderbolt: Add KUnit test for buffer allocation for device without DisplayPort adaptors
  2022-05-09 20:49 [PATCH 0/2] thunderbolt: Fix buffers allocation for device without DisplayPort adaptors Gil Fine
  2022-05-09 20:49 ` [PATCH 1/2] " Gil Fine
@ 2022-05-09 20:49 ` Gil Fine
  2022-05-12  6:27 ` [PATCH 0/2] thunderbolt: Fix buffers " Mika Westerberg
  2 siblings, 0 replies; 4+ messages in thread
From: Gil Fine @ 2022-05-09 20:49 UTC (permalink / raw)
  To: andreas.noever, michael.jamet, mika.westerberg, YehezkelShB
  Cc: gil.fine, linux-usb, lukas

Here we add KUnit test to test the buffer allocation for device without DP adaptors.

Signed-off-by: Gil Fine <gil.fine@intel.com>
---
 drivers/thunderbolt/test.c | 92 ++++++++++++++++++++++++++++++++++++++
 1 file changed, 92 insertions(+)

diff --git a/drivers/thunderbolt/test.c b/drivers/thunderbolt/test.c
index 66b6e665e96f..99b30f2624fc 100644
--- a/drivers/thunderbolt/test.c
+++ b/drivers/thunderbolt/test.c
@@ -341,6 +341,47 @@ static struct tb_switch *alloc_dev_with_dpin(struct kunit *test,
 	return sw;
 }
 
+static struct tb_switch *alloc_dev_without_dp(struct kunit *test,
+					      struct tb_switch *parent,
+					      u64 route, bool bonded)
+{
+	struct tb_switch *sw;
+	int i;
+
+	sw = alloc_dev_default(test, parent, route, bonded);
+	if (!sw)
+		return NULL;
+	/*
+	 * Device with:
+	 * 2x USB4 Adapters (adapters 1,2 and 3,4),
+	 * 1x PCIe Upstream (adapter 9),
+	 * 1x PCIe Downstream (adapter 10),
+	 * 1x USB3 Upstream (adapter 16),
+	 * 1x USB3 Downstream (adapter 17)
+	 */
+	for (i = 5; i <= 8; i++)
+		sw->ports[i].disabled = true;
+
+	for (i = 11; i <= 14; i++)
+		sw->ports[i].disabled = true;
+
+	sw->ports[13].cap_adap = 0;
+	sw->ports[14].cap_adap = 0;
+
+	for (i = 18; i <= 19; i++)
+		sw->ports[i].disabled = true;
+
+	sw->generation = 4;
+	sw->credit_allocation = true;
+	sw->max_usb3_credits = 109;
+	sw->min_dp_aux_credits = 0;
+	sw->min_dp_main_credits = 0;
+	sw->max_pcie_credits = 30;
+	sw->max_dma_credits = 1;
+
+	return sw;
+}
+
 static struct tb_switch *alloc_dev_usb4(struct kunit *test,
 					struct tb_switch *parent,
 					u64 route, bool bonded)
@@ -1996,6 +2037,56 @@ static void tb_test_credit_alloc_pcie(struct kunit *test)
 	tb_tunnel_free(tunnel);
 }
 
+static void tb_test_credit_alloc_without_dp(struct kunit *test)
+{
+	struct tb_switch *host, *dev;
+	struct tb_port *up, *down;
+	struct tb_tunnel *tunnel;
+	struct tb_path *path;
+
+	host = alloc_host_usb4(test);
+	dev = alloc_dev_without_dp(test, host, 0x1, true);
+
+	/*
+	 * The device has no DP therefore baMinDPmain = baMinDPaux = 0
+	 *
+	 * Create PCIe path with buffers less than baMaxPCIe.
+	 *
+	 * For a device with buffers configurations:
+	 * baMaxUSB3 = 109
+	 * baMinDPaux = 0
+	 * baMinDPmain = 0
+	 * baMaxPCIe = 30
+	 * baMaxHI = 1
+	 * Remaining Buffers = Total - (CP + DP) = 120 - (2 + 0) = 118
+	 * PCIe Credits = Max(6, Min(baMaxPCIe, Remaining Buffers - baMaxUSB3)
+	 *		= Max(6, Min(30, 9) = 9
+	 */
+	down = &host->ports[8];
+	up = &dev->ports[9];
+	tunnel = tb_tunnel_alloc_pci(NULL, up, down);
+	KUNIT_ASSERT_TRUE(test, tunnel != NULL);
+	KUNIT_ASSERT_EQ(test, tunnel->npaths, (size_t)2);
+
+	/* PCIe downstream path */
+	path = tunnel->paths[0];
+	KUNIT_ASSERT_EQ(test, path->path_length, 2);
+	KUNIT_EXPECT_EQ(test, path->hops[0].nfc_credits, 0U);
+	KUNIT_EXPECT_EQ(test, path->hops[0].initial_credits, 7U);
+	KUNIT_EXPECT_EQ(test, path->hops[1].nfc_credits, 0U);
+	KUNIT_EXPECT_EQ(test, path->hops[1].initial_credits, 9U);
+
+	/* PCIe upstream path */
+	path = tunnel->paths[1];
+	KUNIT_ASSERT_EQ(test, path->path_length, 2);
+	KUNIT_EXPECT_EQ(test, path->hops[0].nfc_credits, 0U);
+	KUNIT_EXPECT_EQ(test, path->hops[0].initial_credits, 7U);
+	KUNIT_EXPECT_EQ(test, path->hops[1].nfc_credits, 0U);
+	KUNIT_EXPECT_EQ(test, path->hops[1].initial_credits, 64U);
+
+	tb_tunnel_free(tunnel);
+}
+
 static void tb_test_credit_alloc_dp(struct kunit *test)
 {
 	struct tb_switch *host, *dev;
@@ -2709,6 +2800,7 @@ static struct kunit_case tb_test_cases[] = {
 	KUNIT_CASE(tb_test_credit_alloc_legacy_not_bonded),
 	KUNIT_CASE(tb_test_credit_alloc_legacy_bonded),
 	KUNIT_CASE(tb_test_credit_alloc_pcie),
+	KUNIT_CASE(tb_test_credit_alloc_without_dp),
 	KUNIT_CASE(tb_test_credit_alloc_dp),
 	KUNIT_CASE(tb_test_credit_alloc_usb3),
 	KUNIT_CASE(tb_test_credit_alloc_dma),
-- 
2.17.1

---------------------------------------------------------------------
Intel Israel (74) Limited

This e-mail and any attachments may contain confidential material for
the sole use of the intended recipient(s). Any review or distribution
by others is strictly prohibited. If you are not the intended
recipient, please contact the sender and delete all copies.


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH 0/2] thunderbolt: Fix buffers allocation for device without DisplayPort adaptors
  2022-05-09 20:49 [PATCH 0/2] thunderbolt: Fix buffers allocation for device without DisplayPort adaptors Gil Fine
  2022-05-09 20:49 ` [PATCH 1/2] " Gil Fine
  2022-05-09 20:49 ` [PATCH 2/2] thunderbolt: Add KUnit test for buffer " Gil Fine
@ 2022-05-12  6:27 ` Mika Westerberg
  2 siblings, 0 replies; 4+ messages in thread
From: Mika Westerberg @ 2022-05-12  6:27 UTC (permalink / raw)
  To: Gil Fine; +Cc: andreas.noever, michael.jamet, YehezkelShB, linux-usb, lukas

Hi Gil,

On Mon, May 09, 2022 at 11:49:02PM +0300, Gil Fine wrote:
> For the case of device without DP adaptors, we calculate incorrectly the
> buffers allocation. Here we fix the calculation for this case.
> In addition, we add a KUnit test for this case.
> 
> Gil Fine (2):
>   thunderbolt: Fix buffers allocation for device without DisplayPort
>     adaptors
>   thunderbolt: Add KUnit test for buffer allocation for device without
>     DisplayPort adaptors

Both applied to thunderbolt.git/next, thanks!

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2022-05-12  6:27 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-05-09 20:49 [PATCH 0/2] thunderbolt: Fix buffers allocation for device without DisplayPort adaptors Gil Fine
2022-05-09 20:49 ` [PATCH 1/2] " Gil Fine
2022-05-09 20:49 ` [PATCH 2/2] thunderbolt: Add KUnit test for buffer " Gil Fine
2022-05-12  6:27 ` [PATCH 0/2] thunderbolt: Fix buffers " Mika Westerberg

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.