All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Billy Tsai" <billy_tsai@aspeedtech.com>
Cc: linux-i3c@lists.infradead.org, devicetree@vger.kernel.org,
	robh@kernel.org, conor+dt@kernel.org, Frank.Li@kernel.org,
	"Alexandre Belloni" <alexandre.belloni@bootlin.com>
Subject: Re: [PATCH v3 07/10] i3c: mipi-i3c-hci: Add support for the AST2700 I3C controller
Date: Thu, 03 Dec 2026 03:22:56 +0000	[thread overview]
Message-ID: <sashiko-outbox-247088@kernel.org> (raw)
In-Reply-To: <20261203-b4-i3c-hci-ast2700-v3-7-e8b9553560ed@aspeedtech.com>

Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Low] i3c: mipi-i3c-hci: aspeed: unclamped 11-bit PHY SCL counters in
  aspeed_i3c_phy_init()
--

commit 0be57fae36882fda6191e1917476e0f3fd47ef61
Author: Billy Tsai <billy_tsai@aspeedtech.com>

i3c: mipi-i3c-hci: Add support for the AST2700 I3C controller

This commit adds vendor extended capability handling, PHY timing
configuration, interrupt summary dispatch, and DAA index setup for the
ASPEED AST2700 MIPI I3C HCI controller.

> diff --git a/drivers/i3c/master/mipi-i3c-hci/aspeed.c b/drivers/i3c/master/mipi-i3c-hci/aspeed.c
> new file mode 100644
> index 0000000000000..c7abce4f2f990
> --- /dev/null
> +++ b/drivers/i3c/master/mipi-i3c-hci/aspeed.c
> @@ -0,0 +1,357 @@

[ ... ]

> +static u16 aspeed_i3c_ns_to_cnt(unsigned int ns, unsigned long period_ns)
> +{
> +	unsigned long cycles = DIV_ROUND_CLOSEST(ns, period_ns);
> +
> +	/* All PHY counter fields are 11 bits wide */
> +	return min(max(cycles, 1) - 1, ASPEED_I3C_PHY_CNT_MAX);
> +}

[ ... ]

> +int aspeed_i3c_phy_init(struct i3c_hci *hci)
> +{
> +	u16 hcnt, lcnt, total_cnt, min_tbit_cnt, cas_lcnt, cas_cnt, cbp_cnt;
> +	u32 pp_sda_hold = 0, cas_ns = 0, cbp_ns = 0, sr_p_low = 0;
> +	struct i3c_bus *bus = i3c_master_get_bus(&hci->master);
> +	u32 pp_high = 0, pp_low = 0, od_high = 0, od_low = 0;
> +	struct device_node *np = hci->master.dev.of_node;
> +	u32 sdr_ctrl0_reg, ctrl0, ctrl1, ctrl2;
> +	unsigned long core_rate, period_ns;

[ ... ]

> +	of_property_read_u32(np, "i3c-pp-scl-high-period-ns", &pp_high);
> +	of_property_read_u32(np, "i3c-pp-scl-low-period-ns", &pp_low);
> +	if (pp_high && pp_low) {
> +		hcnt = aspeed_i3c_ns_to_cnt(pp_high, period_ns);
> +		lcnt = aspeed_i3c_ns_to_cnt(pp_low, period_ns);
> +	} else {
> +		/*
> +		 * Each of hcnt/lcnt is programmed as N-1 (the PHY counts N
> +		 * cycles for a stored value of N-1), so pre-subtract 2 here
> +		 * to cancel the two implicit +1s and match the requested SCL
> +		 * period exactly. Clamp the pre-subtraction value so
> +		 * total_cnt cannot underflow when an unrealistically high
> +		 * scl_rate leaves less than 3 cycles per period.
> +		 */
> +		unsigned long cycles_per_scl = DIV_ROUND_UP(core_rate, bus->scl_rate.i3c);
> +
> +		total_cnt = max_t(unsigned long, cycles_per_scl, 3) - 2;
> +		if (hci->master.bus.mode == I3C_BUS_MODE_PURE) {
> +			hcnt = DIV_ROUND_DOWN_ULL(total_cnt * 2, 5);
> +			lcnt = total_cnt - hcnt;
> +		} else {
> +			hcnt = DIV_ROUND_UP(I3C_BUS_THIGH_MIXED_MAX_NS,
> +					    period_ns) - 1;
> +			lcnt = total_cnt - hcnt;
> +		}
> +	}
> +
> +	ctrl0 = FIELD_PREP(ASPEED_I3C_PHY_I3C_CTRL0_SCL_H, hcnt) |
> +		FIELD_PREP(ASPEED_I3C_PHY_I3C_CTRL0_SCL_L, lcnt);

[Severity: Low]
Can lcnt and hcnt exceed the 11-bit ASPEED_I3C_PHY_CNT_MAX limit when
derived from bus->scl_rate.i3c?

Unlike aspeed_i3c_ns_to_cnt(), the fallback branch does not clamp hcnt
or lcnt to ASPEED_I3C_PHY_CNT_MAX (2047) and stores cycles_per_scl - 2
in a u16 total_cnt.  For example, a 100 kHz I2C bus in
I3C_BUS_MODE_MIXED_SLOW sets bus->scl_rate.i3c to 100 kHz; at a 250 MHz
core clock, lcnt is 2488, which FIELD_PREP() truncates to 440, driving
SCL at roughly 555 kHz instead of 100 kHz.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261203-b4-i3c-hci-ast2700-v3-0-e8b9553560ed@aspeedtech.com?part=7

-- 
linux-i3c mailing list
linux-i3c@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-i3c

WARNING: multiple messages have this Message-ID (diff)
From: sashiko-bot@kernel.org
To: "Billy Tsai" <billy_tsai@aspeedtech.com>
Cc: linux-i3c@lists.infradead.org, devicetree@vger.kernel.org,
	robh@kernel.org, conor+dt@kernel.org, Frank.Li@kernel.org,
	"Alexandre Belloni" <alexandre.belloni@bootlin.com>
Subject: Re: [PATCH v3 07/10] i3c: mipi-i3c-hci: Add support for the AST2700 I3C controller
Date: Thu, 03 Dec 2026 03:22:56 +0000	[thread overview]
Message-ID: <sashiko-outbox-247088@kernel.org> (raw)
In-Reply-To: <20261203-b4-i3c-hci-ast2700-v3-7-e8b9553560ed@aspeedtech.com>

Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Low] i3c: mipi-i3c-hci: aspeed: unclamped 11-bit PHY SCL counters in
  aspeed_i3c_phy_init()
--

commit 0be57fae36882fda6191e1917476e0f3fd47ef61
Author: Billy Tsai <billy_tsai@aspeedtech.com>

i3c: mipi-i3c-hci: Add support for the AST2700 I3C controller

This commit adds vendor extended capability handling, PHY timing
configuration, interrupt summary dispatch, and DAA index setup for the
ASPEED AST2700 MIPI I3C HCI controller.

> diff --git a/drivers/i3c/master/mipi-i3c-hci/aspeed.c b/drivers/i3c/master/mipi-i3c-hci/aspeed.c
> new file mode 100644
> index 0000000000000..c7abce4f2f990
> --- /dev/null
> +++ b/drivers/i3c/master/mipi-i3c-hci/aspeed.c
> @@ -0,0 +1,357 @@

[ ... ]

> +static u16 aspeed_i3c_ns_to_cnt(unsigned int ns, unsigned long period_ns)
> +{
> +	unsigned long cycles = DIV_ROUND_CLOSEST(ns, period_ns);
> +
> +	/* All PHY counter fields are 11 bits wide */
> +	return min(max(cycles, 1) - 1, ASPEED_I3C_PHY_CNT_MAX);
> +}

[ ... ]

> +int aspeed_i3c_phy_init(struct i3c_hci *hci)
> +{
> +	u16 hcnt, lcnt, total_cnt, min_tbit_cnt, cas_lcnt, cas_cnt, cbp_cnt;
> +	u32 pp_sda_hold = 0, cas_ns = 0, cbp_ns = 0, sr_p_low = 0;
> +	struct i3c_bus *bus = i3c_master_get_bus(&hci->master);
> +	u32 pp_high = 0, pp_low = 0, od_high = 0, od_low = 0;
> +	struct device_node *np = hci->master.dev.of_node;
> +	u32 sdr_ctrl0_reg, ctrl0, ctrl1, ctrl2;
> +	unsigned long core_rate, period_ns;

[ ... ]

> +	of_property_read_u32(np, "i3c-pp-scl-high-period-ns", &pp_high);
> +	of_property_read_u32(np, "i3c-pp-scl-low-period-ns", &pp_low);
> +	if (pp_high && pp_low) {
> +		hcnt = aspeed_i3c_ns_to_cnt(pp_high, period_ns);
> +		lcnt = aspeed_i3c_ns_to_cnt(pp_low, period_ns);
> +	} else {
> +		/*
> +		 * Each of hcnt/lcnt is programmed as N-1 (the PHY counts N
> +		 * cycles for a stored value of N-1), so pre-subtract 2 here
> +		 * to cancel the two implicit +1s and match the requested SCL
> +		 * period exactly. Clamp the pre-subtraction value so
> +		 * total_cnt cannot underflow when an unrealistically high
> +		 * scl_rate leaves less than 3 cycles per period.
> +		 */
> +		unsigned long cycles_per_scl = DIV_ROUND_UP(core_rate, bus->scl_rate.i3c);
> +
> +		total_cnt = max_t(unsigned long, cycles_per_scl, 3) - 2;
> +		if (hci->master.bus.mode == I3C_BUS_MODE_PURE) {
> +			hcnt = DIV_ROUND_DOWN_ULL(total_cnt * 2, 5);
> +			lcnt = total_cnt - hcnt;
> +		} else {
> +			hcnt = DIV_ROUND_UP(I3C_BUS_THIGH_MIXED_MAX_NS,
> +					    period_ns) - 1;
> +			lcnt = total_cnt - hcnt;
> +		}
> +	}
> +
> +	ctrl0 = FIELD_PREP(ASPEED_I3C_PHY_I3C_CTRL0_SCL_H, hcnt) |
> +		FIELD_PREP(ASPEED_I3C_PHY_I3C_CTRL0_SCL_L, lcnt);

[Severity: Low]
Can lcnt and hcnt exceed the 11-bit ASPEED_I3C_PHY_CNT_MAX limit when
derived from bus->scl_rate.i3c?

Unlike aspeed_i3c_ns_to_cnt(), the fallback branch does not clamp hcnt
or lcnt to ASPEED_I3C_PHY_CNT_MAX (2047) and stores cycles_per_scl - 2
in a u16 total_cnt.  For example, a 100 kHz I2C bus in
I3C_BUS_MODE_MIXED_SLOW sets bus->scl_rate.i3c to 100 kHz; at a 250 MHz
core clock, lcnt is 2488, which FIELD_PREP() truncates to 440, driving
SCL at roughly 555 kHz instead of 100 kHz.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261203-b4-i3c-hci-ast2700-v3-0-e8b9553560ed@aspeedtech.com?part=7

  reply	other threads:[~2026-12-03  3:22 UTC|newest]

Thread overview: 28+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-03  3:07 [PATCH v3 00/10] i3c: mipi-i3c-hci: Add Aspeed AST2700 support Billy Tsai
2026-12-03  3:07 ` Billy Tsai
2026-12-03  3:07 ` [PATCH v3 01/10] dt-bindings: i3c: Document generic bus timing properties Billy Tsai
2026-12-03  3:07   ` Billy Tsai
2026-12-03  3:15   ` sashiko-bot
2026-12-03  3:15     ` sashiko-bot
2026-12-03  3:07 ` [PATCH v3 02/10] dt-bindings: i3c: Document the AST2700 I3C controller Billy Tsai
2026-12-03  3:07   ` Billy Tsai
2026-12-03  3:14   ` sashiko-bot
2026-12-03  3:14     ` sashiko-bot
2026-12-03  3:07 ` [PATCH v3 03/10] i3c: mipi-i3c-hci: Support address-indexed DAT slots Billy Tsai
2026-12-03  3:07   ` Billy Tsai
2026-12-03  3:07 ` [PATCH v3 04/10] i3c: mipi-i3c-hci: Add a quirk for 64-bit DMA addressing Billy Tsai
2026-12-03  3:07   ` Billy Tsai
2026-12-03  3:07 ` [PATCH v3 05/10] i3c: mipi-i3c-hci: Add a quirk to clear the TX start threshold Billy Tsai
2026-12-03  3:07   ` Billy Tsai
2026-12-03  3:07 ` [PATCH v3 06/10] i3c: mipi-i3c-hci: Split the core IRQ handling into its own function Billy Tsai
2026-12-03  3:07   ` Billy Tsai
2026-12-03  3:07 ` [PATCH v3 07/10] i3c: mipi-i3c-hci: Add support for the AST2700 I3C controller Billy Tsai
2026-12-03  3:07   ` Billy Tsai
2026-12-03  3:22   ` sashiko-bot [this message]
2026-12-03  3:22     ` sashiko-bot
2026-12-03  3:07 ` [PATCH v3 08/10] i3c: mipi-i3c-hci: Program AST2700 IBI termination threshold Billy Tsai
2026-12-03  3:07   ` Billy Tsai
2026-12-03  3:07 ` [PATCH v3 09/10] i3c: mipi-i3c-hci: Improve AST2700 PIO TX queue utilization Billy Tsai
2026-12-03  3:07   ` Billy Tsai
2026-12-03  3:07 ` [PATCH v3 10/10] i3c: mipi-i3c-hci: Support the AST2700 internal pull-ups Billy Tsai
2026-12-03  3:07   ` Billy Tsai

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=sashiko-outbox-247088@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=Frank.Li@kernel.org \
    --cc=alexandre.belloni@bootlin.com \
    --cc=billy_tsai@aspeedtech.com \
    --cc=conor+dt@kernel.org \
    --cc=devicetree@vger.kernel.org \
    --cc=linux-i3c@lists.infradead.org \
    --cc=robh@kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    /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 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.