Re: [PATCH v2 1/4] i2c: smbus: add core function handling SMBus host-notify

From: Alain Volmat
Date: Thu Jul 02 2020 - 07:23:28 EST


Hi Wolfram,

> Okay, now I got it to work, I also noted a few more issues.
>
> First, I'd suggest s/i2c_smbus_host_notify/i2c_slave_host_notify/g for
> all occurences in this patch. This makes a stronger distinction between
> the generic HostNotify support and the slave specific one.

Ok with that.

> Also, I wonder if this shouldn't go to i2c-smbus.c instead but I haven't
> checked if we end up in dependency hell then. Second best thought: at
> least move to i2c-core-slave.c, then we could save the #ifdeffery in the
> c-file?

I have actually difficulties to understand clearly what should go within
i2c-smbus.c vs i2c-core-smbus or i2c-core-slave. My feeling is that
i2c-core-slave is more about the registering of a slave rather than one usage
of the slave mechanism. Hence I am not sure those functions/cb belong there.
But at the same time, I don't know about i2c-smbus vs i2c-core-smbus. I putted
it within i2c-core-smbus considering that the creation of the alert device
is also done there.

....

> > +{
> > + struct i2c_smbus_host_notify_status *status = client->dev.platform_data;
> > + int ret;
> > +
> > + switch (event) {
> > + case I2C_SLAVE_WRITE_REQUESTED:
> > + status->notify_start = true;
> > + break;
> > + case I2C_SLAVE_WRITE_RECEIVED:
> > + /* We only retrieve the first byte received (addr)
> > + * since there is currently no support to retrieve the data
> > + * parameter from the client.
> > + */
> > + if (!status->notify_start)
> > + break;
> > + status->addr = *val;
> > + status->notify_start = false;
>
> So, we are safe if the message is too short. Otherwise, we capture the
> first byte (== address) only, right. Further bytes until STOP are
> discarded. So, we don't check if the message is too long and contains
> more than the status word. Maybe we should add that?

Yes I modified that.

> > + break;
> > + case I2C_SLAVE_STOP:
> > + /* In case of incomplete write, don't handle host-notify */
> > + if (status->notify_start) {
> > + status->notify_start = false;
> > + break;
> > + }
> > +
> > + ret = i2c_handle_smbus_host_notify(client->adapter,
> > + status->addr);
> > + if (ret < 0)
> > + return ret;
> > + break;
> > + default:
>
> The missing cases are mandatory. From my testunit driver:
>
> case I2C_SLAVE_READ_REQUESTED:
> case I2C_SLAVE_READ_PROCESSED:
> *val = 0xff;
> break;

Ok, done as well.

> > --- a/include/linux/i2c-smbus.h
> > +++ b/include/linux/i2c-smbus.h
> > @@ -38,6 +38,8 @@ static inline int of_i2c_setup_smbus_alert(struct i2c_adapter *adap)
> > return 0;
> > }
> > #endif
> > +struct i2c_client *i2c_new_smbus_host_notify_device(struct i2c_adapter *adapter);
> > +void i2c_free_smbus_host_notify_device(struct i2c_client *client);
>
> Those need to be guarded with I2C_SLAVE as well. And an #else branch
> with empty/successful placeholders.

Ok understood.