From: Mario Limonciello <mario.limonciello@amd.com>
To: Mika Westerberg <mika.westerberg@linux.intel.com>,
Sanath S <Sanath.S@amd.com>
Cc: andreas.noever@gmail.com, michael.jamet@intel.com,
YehezkelShB@gmail.com, linux-usb@vger.kernel.org,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH 1/2] thunderbolt: Introduce tb_switch_reset_ports(), tb_port_reset() and usb4_port_reset()
Date: Tue, 12 Dec 2023 09:32:03 -0600 [thread overview]
Message-ID: <c56a359b-d035-4557-84d2-6c8ddd600bff@amd.com> (raw)
In-Reply-To: <20231212152706.GG1074920@black.fi.intel.com>
On 12/12/2023 09:27, Mika Westerberg wrote:
> On Tue, Dec 12, 2023 at 07:30:46PM +0530, Sanath S wrote:
>> Introduce the tb_switch_reset_ports() function that resets the
>> downstream ports of a given switch. This helps us reset the USB4
>> links created by boot firmware during the init sequence.
>>
>> Introduce the tb_port_reset() helper function that resets the
>> given port.
>>
>> Introduce the usb4_port_reset() function that performs the DPR
>> of a given port. This function follows the CM guide specification 7.3
>>
>> Suggested-by: Mario Limonciello <mario.limonciello@amd.com>
>> Signed-off-by: Sanath S <Sanath.S@amd.com>
>> ---
>> drivers/thunderbolt/switch.c | 31 ++++++++++++++++++++++++++++
>> drivers/thunderbolt/tb.h | 2 ++
>> drivers/thunderbolt/tb_regs.h | 1 +
>> drivers/thunderbolt/usb4.c | 39 +++++++++++++++++++++++++++++++++++
>> 4 files changed, 73 insertions(+)
>>
>> diff --git a/drivers/thunderbolt/switch.c b/drivers/thunderbolt/switch.c
>> index 44e9b09de47a..26ad6cc1ee91 100644
>> --- a/drivers/thunderbolt/switch.c
>> +++ b/drivers/thunderbolt/switch.c
>> @@ -626,6 +626,19 @@ int tb_port_unlock(struct tb_port *port)
>> return 0;
>> }
>>
>> +/**
>> + * tb_port_reset() - Reset downstream port
>> + * @port: Port to reset
>> + *
>> + * Helps to reconfigure the USB4 link by resetting the downstream port.
>> + *
>> + * Return: Returns 0 on success or an error code on failure.
>> + */
>> +static int tb_port_reset(struct tb_port *port)
>> +{
>> + return usb4_port_reset(port);
>> +}
>> +
>> static int __tb_port_enable(struct tb_port *port, bool enable)
>> {
>> int ret;
>> @@ -1547,6 +1560,24 @@ static void tb_dump_switch(const struct tb *tb, const struct tb_switch *sw)
>> regs->__unknown1, regs->__unknown4);
>> }
>>
>> +/**
>> + * tb_switch_reset_ports() - Reset downstream ports of switch.
>> + * @sw: Switch whose ports need to be reset.
>> + *
>> + * Return: Returns 0 on success or an error code on failure.
>> + */
>> +int tb_switch_reset_ports(struct tb_switch *sw)
>> +{
>> + struct tb_port *port;
>> + int ret = -EINVAL;
>
> Why it returns -EINVAL? What if this is run for non-USB4 router?
This is a good point, but in the non USB4 case (default return) maybe
it's better to be -ENODEV and in patch 2 be careful about the caller.
>
>> +
>> + tb_switch_for_each_port(sw, port) {
>> + if (tb_port_is_null(port) && port->cap_usb4)
>> + ret = tb_port_reset(port);
>
> Should it stop here and return ret?
+1
>
>> + }
>> + return ret;
>> +}
>> +
>> /**
>> * tb_switch_reset() - reconfigure route, enable and send TB_CFG_PKG_RESET
>> * @sw: Switch to reset
>> diff --git a/drivers/thunderbolt/tb.h b/drivers/thunderbolt/tb.h
>> index e299e53473ae..f2687ec4ac53 100644
>> --- a/drivers/thunderbolt/tb.h
>> +++ b/drivers/thunderbolt/tb.h
>> @@ -797,6 +797,7 @@ void tb_switch_remove(struct tb_switch *sw);
>> void tb_switch_suspend(struct tb_switch *sw, bool runtime);
>> int tb_switch_resume(struct tb_switch *sw);
>> int tb_switch_reset(struct tb_switch *sw);
>> +int tb_switch_reset_ports(struct tb_switch *sw);
>> int tb_switch_wait_for_bit(struct tb_switch *sw, u32 offset, u32 bit,
>> u32 value, int timeout_msec);
>> void tb_sw_set_unplugged(struct tb_switch *sw);
>> @@ -1281,6 +1282,7 @@ struct tb_port *usb4_switch_map_usb3_down(struct tb_switch *sw,
>> int usb4_switch_add_ports(struct tb_switch *sw);
>> void usb4_switch_remove_ports(struct tb_switch *sw);
>>
>> +int usb4_port_reset(struct tb_port *port);
>> int usb4_port_unlock(struct tb_port *port);
>> int usb4_port_hotplug_enable(struct tb_port *port);
>> int usb4_port_configure(struct tb_port *port);
>> diff --git a/drivers/thunderbolt/tb_regs.h b/drivers/thunderbolt/tb_regs.h
>> index 87e4795275fe..d49530bc0d53 100644
>> --- a/drivers/thunderbolt/tb_regs.h
>> +++ b/drivers/thunderbolt/tb_regs.h
>> @@ -389,6 +389,7 @@ struct tb_regs_port_header {
>> #define PORT_CS_18_CSA BIT(22)
>> #define PORT_CS_18_TIP BIT(24)
>> #define PORT_CS_19 0x13
>> +#define PORT_CS_19_DPR BIT(0)
>> #define PORT_CS_19_PC BIT(3)
>> #define PORT_CS_19_PID BIT(4)
>> #define PORT_CS_19_WOC BIT(16)
>> diff --git a/drivers/thunderbolt/usb4.c b/drivers/thunderbolt/usb4.c
>> index 4277733d0021..55f7c163bf84 100644
>> --- a/drivers/thunderbolt/usb4.c
>> +++ b/drivers/thunderbolt/usb4.c
>> @@ -1073,6 +1073,45 @@ void usb4_switch_remove_ports(struct tb_switch *sw)
>> }
>> }
>>
>> +/**
>> + * usb4_port_reset() - Reset USB4 downsteam port
>> + * @port: USB4 port to reset.
>> + *
>> + * Helps to reconfigure USB4 link by resetting downstream port.
>> + *
>> + * Return: Returns 0 on success or an error code on failure.
>> + */
>> +int usb4_port_reset(struct tb_port *port)
>> +{
>> + int ret;
>> + u32 val = 0;
>
> Reverse christmas tree please:
>
> u32 val = 0;
> int ret;
>
>> +
>> + ret = tb_port_read(port, &val, TB_CFG_PORT,
>> + port->cap_usb4 + PORT_CS_19, 1);
>> + if (ret)
>> + return ret;
>> +
>> + val = val | PORT_CS_19_DPR;
>> + ret = tb_port_write(port, &val, TB_CFG_PORT,
>> + port->cap_usb4 + PORT_CS_19, 1);
>> + if (ret)
>> + return ret;
>> +
>> + /* Wait for 10ms after requesting downstream port reset */
>> + msleep(10);
>
> Probably good to add a couple of more ms just in case. Also
> usleep_range()? (or fsleep()).
Sanath had it at 20 but I had suggested to align to spec.
For the wiggle room maybe usleep_range(10000, 15000)?
>
>> +
>> + ret = tb_port_read(port, &val, TB_CFG_PORT,
>> + port->cap_usb4 + PORT_CS_19, 1);
>> + if (ret)
>> + return ret;
>> +
>> + val &= ~PORT_CS_19_DPR;
>> + ret = tb_port_write(port, &val, TB_CFG_PORT,
>> + port->cap_usb4 + PORT_CS_19, 1);
>> +
>> + return ret;
>> +}
>> +
>> /**
>> * usb4_port_unlock() - Unlock USB4 downstream port
>> * @port: USB4 port to unlock
>> --
>> 2.34.1
next prev parent reply other threads:[~2023-12-12 15:32 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-12-12 14:00 [PATCH 0/2] Add support for downstream port reset(DPR) Sanath S
2023-12-12 14:00 ` [PATCH 1/2] thunderbolt: Introduce tb_switch_reset_ports(), tb_port_reset() and usb4_port_reset() Sanath S
2023-12-12 15:27 ` Mika Westerberg
2023-12-12 15:32 ` Mario Limonciello [this message]
2023-12-12 15:41 ` Mika Westerberg
2023-12-12 14:00 ` [PATCH 2/2] thunderbolt: Teardown tunnels and reset downstream ports created by boot firmware Sanath S
2023-12-12 15:10 ` Mika Westerberg
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=c56a359b-d035-4557-84d2-6c8ddd600bff@amd.com \
--to=mario.limonciello@amd.com \
--cc=Sanath.S@amd.com \
--cc=YehezkelShB@gmail.com \
--cc=andreas.noever@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-usb@vger.kernel.org \
--cc=michael.jamet@intel.com \
--cc=mika.westerberg@linux.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