public inbox for linux-i3c@lists.infradead.org
 help / color / mirror / Atom feed
From: Miquel Raynal <miquel.raynal@bootlin.com>
To: Joshua Yeong <joshua.yeong@starfivetech.com>
Cc: <alexandre.belloni@bootlin.com>, <linux-i3c@lists.infradead.org>,
	<linux-kernel@vger.kernel.org>
Subject: Re: [PATCH 1/1] i3c: Add fallback method for GETMXDS CCC
Date: Tue, 12 Sep 2023 13:08:21 +0200	[thread overview]
Message-ID: <20230912130821.21edfafc@xps-13> (raw)
In-Reply-To: <20230911082456.23239-2-joshua.yeong@starfivetech.com>

Hi Joshua,

joshua.yeong@starfivetech.com wrote on Mon, 11 Sep 2023 16:24:56 +0800:

> Some I3C hardware will report error when incorrect length is received from
> device. GETMXDS CCC are availble in 2 formats; without turnaround time (format
> 1) and with turnaround time (format 2). There is no mechanics to determine which
> format is supported by device. In case sending GETMXDS CCC format 2 resulted
> failure, try sending GETMXDS CCC format 1 instead.
> 
> Signed-off-by: Joshua Yeong <joshua.yeong@starfivetech.com>
> ---
>  drivers/i3c/master.c    | 33 ++++++++++++++++++++++++++++-----
>  include/linux/i3c/ccc.h | 17 +++++++++++++++--
>  2 files changed, 43 insertions(+), 7 deletions(-)
> 
> diff --git a/drivers/i3c/master.c b/drivers/i3c/master.c
> index 87283e4a4607..084f64bef155 100644
> --- a/drivers/i3c/master.c
> +++ b/drivers/i3c/master.c
> @@ -1088,10 +1088,37 @@ static int i3c_master_getmxds_locked(struct i3c_master_controller *master,
>  				     struct i3c_device_info *info)
>  {
>  	struct i3c_ccc_getmxds *getmaxds;
> +	struct i3c_ccc_getmxds_turnaround *getmaxds_ta;
>  	struct i3c_ccc_cmd_dest dest;
>  	struct i3c_ccc_cmd cmd;
>  	int ret;
>  
> +	getmaxds_ta = i3c_ccc_cmd_dest_init(&dest, info->dyn_addr,
> +					 sizeof(*getmaxds_ta));
> +	if (!getmaxds_ta)
> +		return -ENOMEM;
> +
> +	i3c_ccc_cmd_init(&cmd, true, I3C_CCC_GETMXDS, &dest, 1);
> +	ret = i3c_master_send_ccc_cmd_locked(master, &cmd);
> +	if (ret) {
> +		goto alternative;
> +	}
> +
> +	if (dest.payload.len != 2 && dest.payload.len != 5) {

Can len be 2 here?

> +		ret = -EIO;
> +		goto out;
> +	}
> +
> +	info->max_read_ds = getmaxds_ta->maxrd;
> +	info->max_write_ds = getmaxds_ta->maxwr;
> +	if (dest.payload.len == 5)
> +		info->max_read_turnaround = getmaxds_ta->maxrdturn[0] |
> +					    ((u32)getmaxds_ta->maxrdturn[1] << 8) |
> +					    ((u32)getmaxds_ta->maxrdturn[2] << 16);

Don't you want to avoid the "alternative" if it worked?

> +
> +alternative:

I would expect a comment somewhere to explain the subtlety.

> +	i3c_ccc_cmd_dest_cleanup(&dest);
> +
>  	getmaxds = i3c_ccc_cmd_dest_init(&dest, info->dyn_addr,
>  					 sizeof(*getmaxds));
>  	if (!getmaxds)
> @@ -1102,17 +1129,13 @@ static int i3c_master_getmxds_locked(struct i3c_master_controller *master,
>  	if (ret)
>  		goto out;
>  
> -	if (dest.payload.len != 2 && dest.payload.len != 5) {
> +	if (dest.payload.len != 2) {
>  		ret = -EIO;
>  		goto out;
>  	}
>  
>  	info->max_read_ds = getmaxds->maxrd;
>  	info->max_write_ds = getmaxds->maxwr;
> -	if (dest.payload.len == 5)
> -		info->max_read_turnaround = getmaxds->maxrdturn[0] |
> -					    ((u32)getmaxds->maxrdturn[1] << 8) |
> -					    ((u32)getmaxds->maxrdturn[2] << 16);
>  
>  out:
>  	i3c_ccc_cmd_dest_cleanup(&dest);
> diff --git a/include/linux/i3c/ccc.h b/include/linux/i3c/ccc.h
> index ad59a4ae60d1..50ed41d4d5a1 100644
> --- a/include/linux/i3c/ccc.h
> +++ b/include/linux/i3c/ccc.h
> @@ -269,14 +269,27 @@ enum i3c_tsco {
>  #define I3C_CCC_MAX_SDR_FSCL(x)		((x) & I3C_CCC_MAX_SDR_FSCL_MASK)
>  
>  /**
> - * struct i3c_ccc_getmxds - payload passed to GETMXDS CCC
> + * struct i3c_ccc_getmxds - payload passed to GETMXDS CCC without turnaround
> + * (format 1)
> + *
> + * @maxwr: write limitations
> + * @maxrd: read limitations
> + */
> +struct i3c_ccc_getmxds {
> +	u8 maxwr;
> +	u8 maxrd;
> +} __packed;
> +
> +/**
> + * struct i3c_ccc_getmxds_ta - payload passed to GETMXDS CCC with turnaround
> + * (format 2)
>   *
>   * @maxwr: write limitations
>   * @maxrd: read limitations
>   * @maxrdturn: maximum read turn-around expressed micro-seconds and
>   *	       little-endian formatted
>   */
> -struct i3c_ccc_getmxds {
> +struct i3c_ccc_getmxds_turnaround {
>  	u8 maxwr;
>  	u8 maxrd;
>  	u8 maxrdturn[3];


Thanks,
Miquèl

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

  reply	other threads:[~2023-09-12 11:08 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-09-11  8:24 [PATCH 0/1] Fallback mechanism for GETMXDS CCC Joshua Yeong
2023-09-11  8:24 ` [PATCH 1/1] i3c: Add fallback method " Joshua Yeong
2023-09-12 11:08   ` Miquel Raynal [this message]
2023-09-13  5:58     ` Joshua Yeong

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=20230912130821.21edfafc@xps-13 \
    --to=miquel.raynal@bootlin.com \
    --cc=alexandre.belloni@bootlin.com \
    --cc=joshua.yeong@starfivetech.com \
    --cc=linux-i3c@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    /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