linux-i2c.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Heiner Kallweit <hkallweit1@gmail.com>
To: Jean Delvare <jdelvare@suse.de>
Cc: linux-i2c@vger.kernel.org
Subject: Re: [PATCH 1/8] i2c: i801: improve interrupt handler
Date: Thu, 15 Dec 2022 23:15:25 +0100	[thread overview]
Message-ID: <5d1ef6c2-cd98-8946-e96f-1e82ee6aafd2@gmail.com> (raw)
In-Reply-To: <20220607143447.58058154@endymion.delvare>

On 07.06.2022 14:34, Jean Delvare wrote:
> Hi Heiner, 
> 
> On Fri, 15 Apr 2022 18:54:32 +0200, Heiner Kallweit wrote:
>> Not sure if it can happen, but better play safe: If SMBHSTSTS_BYTE_DONE
>> and an error flag is set, then don't trust the result and skip calling
>> i801_isr_byte_done(). In addition clear status bit SMBHSTSTS_BYTE_DONE
>> in the main interrupt handler, this allows to simplify the code a
>> little.
>>
>> Signed-off-by: Heiner Kallweit <hkallweit1@gmail.com>
>> ---
>>  drivers/i2c/busses/i2c-i801.c | 25 ++++++++-----------------
>>  1 file changed, 8 insertions(+), 17 deletions(-)
>>
>> diff --git a/drivers/i2c/busses/i2c-i801.c b/drivers/i2c/busses/i2c-i801.c
>> index ff706349b..c481f121d 100644
>> --- a/drivers/i2c/busses/i2c-i801.c
>> +++ b/drivers/i2c/busses/i2c-i801.c
>> @@ -556,9 +556,6 @@ static void i801_isr_byte_done(struct i801_priv *priv)
>>  		/* Write next byte, except for IRQ after last byte */
>>  		outb_p(priv->data[++priv->count], SMBBLKDAT(priv));
>>  	}
>> -
>> -	/* Clear BYTE_DONE to continue with next byte */
>> -	outb_p(SMBHSTSTS_BYTE_DONE, SMBHSTSTS(priv));
>>  }
>>  
>>  static irqreturn_t i801_host_notify_isr(struct i801_priv *priv)
>> @@ -588,7 +585,6 @@ static irqreturn_t i801_host_notify_isr(struct i801_priv *priv)
>>   *      BUS_ERR - SMI# transaction collision
>>   *      FAILED - transaction was canceled due to a KILL request
>>   *    When any of these occur, update ->status and signal completion.
>> - *    ->status must be cleared before kicking off the next transaction.
>>   *
>>   * 2) For byte-by-byte (I2C read/write) transactions, one BYTE_DONE interrupt
>>   *    occurs for each byte of a byte-by-byte to prepare the next byte.
>> @@ -613,23 +609,18 @@ static irqreturn_t i801_isr(int irq, void *dev_id)
>>  	}
>>  
>>  	status = inb_p(SMBHSTSTS(priv));
>> -	if (status & SMBHSTSTS_BYTE_DONE)
>> +	if ((status & SMBHSTSTS_BYTE_DONE) && !(status & STATUS_ERROR_FLAGS))
> 
> Isn't this better written
> 
> 	if ((status & (SMBHSTSTS_BYTE_DONE | STATUS_ERROR_FLAGS)) == SMBHSTSTS_BYTE_DONE)
> 
> ? At least my compiler generates smaller binary code.
> 
OK. Meanwhile I prefer readability over saving few bytes, but here IMO
the readability doesn't suffer.

>>  		i801_isr_byte_done(priv);
>>  
>>  	/*
>> -	 * Clear remaining IRQ sources: Completion of last command, errors
>> -	 * and the SMB_ALERT signal. SMB_ALERT status is set after signal
>> -	 * assertion independently of the interrupt generation being blocked
>> -	 * or not so clear it always when the status is set.
>> -	 */
>> -	status &= SMBHSTSTS_INTR | STATUS_ERROR_FLAGS | SMBHSTSTS_SMBALERT_STS;
>> -	if (status)
>> -		outb_p(status, SMBHSTSTS(priv));
>> -	status &= ~SMBHSTSTS_SMBALERT_STS; /* SMB_ALERT not reported */
>> -	/*
>> -	 * Report transaction result.
>> -	 * ->status must be cleared before the next transaction is started.
>> +	 * Clear IRQ sources: SMB_ALERT status is set after signal assertion
>> +	 * independently of the interrupt generation being blocked or not
>> +	 * so clear it always when the status is set.
>>  	 */
>> +	status &= STATUS_FLAGS | SMBHSTSTS_SMBALERT_STS;
>> +	outb_p(status, SMBHSTSTS(priv));
> 
> You are making the call to outb_p() unconditional. Is this under the
> assumption that at least one of the bits must be set, so the condition
> was always met?
> 
So far we exclude here the case where SMBHSTSTS is written in
i801_isr_byte_done(). The patch allows to write SMBHSTSTS here only,
so we don't need the condition any longer.

>> +
>> +	status &= STATUS_ERROR_FLAGS | SMBHSTSTS_INTR;
>>  	if (status) {
>>  		priv->status = status;
>>  		complete(&priv->done);
> 
> Tested OK on my system, looks good overall, nice simplification.
> 


  reply	other threads:[~2022-12-15 22:15 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-04-15 16:53 [PATCH 0/8] i2c: i801: Series with minor improvements Heiner Kallweit
2022-04-15 16:54 ` [PATCH 1/8] i2c: i801: improve interrupt handler Heiner Kallweit
2022-06-07 12:34   ` Jean Delvare
2022-12-15 22:15     ` Heiner Kallweit [this message]
2022-04-15 16:55 ` [PATCH 2/8] i2c: i801: make FEATURE_HOST_NOTIFY dependent on FEATURE_IRQ Heiner Kallweit
2022-06-07 12:48   ` Jean Delvare
2022-12-16 20:23     ` Heiner Kallweit
2022-04-15 16:55 ` [PATCH 3/8] i2c: i801: make FEATURE_BLOCK_PROC dependent on FEATURE_BLOCK_BUFFER Heiner Kallweit
2022-06-07 14:13   ` Jean Delvare
2022-12-16 20:57     ` Heiner Kallweit
2022-04-15 16:56 ` [PATCH 4/8] i2c: i801: enable FEATURE_IRQ and FEATURE_I2C_BLOCK_READ on all chip versions Heiner Kallweit
2022-06-07 14:24   ` Jean Delvare
2022-06-13 17:08     ` Jean Delvare
2022-06-14 12:59       ` Jean Delvare
2022-12-16 21:36         ` Heiner Kallweit
2022-04-15 16:57 ` [PATCH 5/8] i2c: i801: add helper i801_set_hstadd() Heiner Kallweit
2022-06-09 13:53   ` Jean Delvare
2022-12-16 21:37     ` Heiner Kallweit
2022-04-15 16:58 ` [PATCH 6/8] i2c: i801: add i801_single_transaction(), complementing i801_block_transaction() Heiner Kallweit
2022-06-10 11:03   ` Jean Delvare
2022-12-17 17:07     ` Heiner Kallweit
2022-04-15 16:58 ` [PATCH 7/8] i2c: i801: call i801_check_pre() from i801_access() Heiner Kallweit
2022-06-10 13:52   ` Jean Delvare
2022-04-15 16:59 ` [PATCH 8/8] i2c: i801: call i801_check_post() " Heiner Kallweit
2022-06-10 14:31   ` Jean Delvare
2022-12-17 17:21     ` Heiner Kallweit

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=5d1ef6c2-cd98-8946-e96f-1e82ee6aafd2@gmail.com \
    --to=hkallweit1@gmail.com \
    --cc=jdelvare@suse.de \
    --cc=linux-i2c@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;
as well as URLs for NNTP newsgroup(s).