Re: [PATCH v4 4/6] i3c: master: cdns: add support for mastership request to Cadence I3C master driver.

Boris Brezillon
2019-05-18T07:34:26Z

On Mon, 29 Apr 2019 11:36:42 +0100
Przemyslaw Gaj <pgaj@cadence.com> wrote:

> Hi Boris,
>
> I'm sorry for my late response. I hope you remember this thread :-)

Unfortunately not :-/, and it's now my turn to apologize for the late
reply.

> I'm implementing this and have some questions.
>
> The 03/30/2019 16:44, Boris Brezillon wrote:
> > >
> > > @@ -1274,9 +1353,32 @@ static int cdns_i3c_master_bus_init(struct i3c_master_controller *m)
> > >
> > > cdns_i3c_master_enable(master);
> > >
> > > + if (m->secondary) {
> > > + i3c_bus_maintenance_lock(&master->base.bus);
> > > + cdns_i3c_master_update_devs(&master->base);
> > > + i3c_bus_maintenance_unlock(&master->base.bus);
> > > + }
> >
> > Okay, I changed my mind on this solution (it's not the first time that
> > happens, and unfortunately won't be the last time either :-)). I think
> > I don't like the idea of exposing the i3c_bus_maintenance_unlock/lock()
> > functions in the end.
>
> Ok :-)
>
> >
> > I'd like to reconsider what you initially proposed: having an
> > ->update_devs() hook that is called by the core, except I'd call it
> > ->populate_bus().
>
> Ok, we can back to previous approach.
>
> >
> > BTW, there's still something that's unclear to me. You seem to populate
> > the bus here and also when acquiring bus ownership. Is this correct?
>
> Yes, this is correct. I'm doing this here to register all the devices received
> by DEFSLVS on master initialization time. I'm also populating new devices when
> acquiring the bus because some device could join the bus dynamically and we
> want to register this new devices on our side also.

Hm, I don't get that part. I thought we were supposed to add devices as
soon as we know about them. In case of HJ and assuming your master is
not currently owning the bus, the active master should send you a
DEFSLVS which should serve as a trigger for registering new devs on all
non active masters. Since registering new devices will trigger a
mastership handover to query devs info (PID + other stuff) we should be
all good, right?

>
> > I'd expect it to be 'partially' populated at bus-init+defslvs time,
> > which would trigger a mastership request if I3C devices are present (as
> > we need to send a GETPID to know more about I3C devs).
>
> So, you want to allocate and attach devices and then, when possible get devices
> info and register them? I mean when mastership request is possible. If not,
> just leave devices allocated and register them when ENEC(MR) received, correct?

Kind of, yes. We can probably just have a "want_to_acquire_bus" flag
set, and the partially registered/discovered devices present in the
master list would be registered automatically every time the master
acquires bus ownership. This way we can re-use this logic for any
operation that requires the master to own the bus to do something
specific.

>
> Previously, I allocated and registered all the devices after successful
> mastership request. Which way is better in your opinion?

That's a solution too, but it feels like a lot of generic code is
open-coded in the driver if we do it this way. I know I'm the one who
suggested this approach, but now that I see the code, I realize I was
wrong (sorry about that).

>
> >
> > Also, what happens if i3c_master_add_i3c_dev_locked() fails? You
> > don't seem to handle that case at all.
>
> For now, I just skipped it silently.

We should at least print an error/warning.

>
> >
> > > +
> > > +static void cdns_i3c_master_mastership_takeover(struct cdns_i3c_master *master)
> > > +{
> > > + if (master->base.init_done) {
> >
> > Can this really happen that init_done is not set when you reach this
> > point.
>
> Yes, it was possible. Mastership was taken but master wasn't registered yet.
> With new approach I think this won't happen.

One more reason to switch to the new approach.

>
> >
> > > + i3c_bus_maintenance_lock(&master->base.bus);
> > > + cdns_i3c_master_update_devs(&master->base);
> > > + i3c_bus_maintenance_unlock(&master->base.bus);
> > > +
> > > + i3c_master_register_new_devs(&master->base);
> >
> > The core will somehow be informed that this master now owns the bus, so
> > it can call i3c_master_register_new_devs() for us, right?
>
> I think it can. I'm sure it worked like that before. When HC driver changed
> cur_master, new devices were populated.
>
> >
> > But as said above, I'm not even sure this is correct to do it from
> > here. I'd expect this to happen at DEFSLVS or BUS init time.
> >
>
> Ok. New(Previous) approach allows that.
>

Ok, good.