miibus + USB = problem
Hans Petter Selasky
hselasky at c2i.net
Thu Aug 3 12:44:42 UTC 2006
On Thursday 03 August 2006 04:25, Pyun YongHyeon wrote:
> On Wed, Aug 02, 2006 at 02:37:55PM +0200, Hans Petter Selasky wrote:
> > Hi,
> >
> > I am currently in the progress of porting "if_aue.c" to my new USB API,
> > and have hit a problem that needs to be solved. The problem is that the
> > USB system sleeps under "miibus_xxx". Questions are:
> >
> > Is this allowed?
> >
> > What locks are held when these functions are called ?
> >
> > Reference:
> >
> > /* MII interface */
> > DEVMETHOD(miibus_readreg, aue_miibus_readreg),
> > DEVMETHOD(miibus_writereg, aue_miibus_writereg),
> > DEVMETHOD(miibus_statchg, aue_miibus_statchg),
>
> AFAIK there is no locks held when MII layer calls above methods but
> it _is_ called with a driver lock from its ioctl handler.
Ok.
> It seems that aue(4) needs to access its register space whilst
> serving above MII methods.
...
> But I think sleeping is not a good way in the MII methods as it would
> confuse MII layers. See below.
>
Yes, "mii_tick()" can suddenly be executed while "mii_mediachg()" is being
executed.
But can I assume that everytime something inside the "mii" layer is called, it
goes through my driver, "if_aue".
From what I can see, there are only three entry points into the MII layer:
mii_mediachg(mii);
mii_pollstat(mii);
mii_tick(mii);
The idea is to call these from a separate thread, that can sleep. But then
comes the next question:
Can I safely "kthread_exit" from the "miibus_xxx()" functions ? I can probably
find the answer by looking at the sourcecode, but maybe someone already
knows?
/* MII interface */
DEVMETHOD(miibus_readreg, aue_miibus_readreg),
DEVMETHOD(miibus_writereg, aue_miibus_writereg),
DEVMETHOD(miibus_statchg, aue_miibus_statchg),
>
>
> I think you can immediately return from register read/write routines
> without DELAY() if you know the hardware was gone.
>
> > 2) pre-read all read registers regularly. How can I do this with
> > "miibus"?
>
> Because you have a aue_tick() which is called every hz you can cache
> several registers regularly. Your MII methods can copy the value
> without accessing registers with proper locks. However, this may
> confuse MII layers because it needs successive register accesses to
> read/write media related settings and that defeats use of cached
> contents of the registers.
I just have to cache the result:
ifmr->ifm_active = mii->mii_media_active;
ifmr->ifm_status = mii->mii_media_status;
Thanks for any comments.
--HPS
More information about the freebsd-hackers
mailing list