miibus + USB = problem

Hans Petter Selasky hselasky at c2i.net
Wed Aug 2 12:37:55 UTC 2006


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),

The problem with USB devices, is that the read-register process is very slow. 
It can take up to several milliseconds. And if the device is suddenly 
detached one has to think about adding exit code everywhere.

The solution I see with USB devices is something like this:

if (sc->device_gone) {

  exit mutexes ;

  kthread_exit(0);
} 

Of course I cannot "kthread_exit()" when the call comes from read/write/ioctl, 
because there is a stack, that expects a returning call. If the kernel code 
was objective C, then maybe one could throw an exception or do something 
alike so that the processor gets out of the USB-read procedure.


Solutions:

1) use USB hardware polling, not releasing any mutexes, simply using DELAY(), 
until read/writes complete.

2) pre-read all read registers regularly. How can I do this with "miibus"?


Anyone have any comments?

--HPS


More information about the freebsd-hackers mailing list