From owner-freebsd-hackers@FreeBSD.ORG Wed Aug 2 12:37:55 2006 Return-Path: X-Original-To: freebsd-hackers@freebsd.org Delivered-To: freebsd-hackers@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 2790916A4DD for ; Wed, 2 Aug 2006 12:37:55 +0000 (UTC) (envelope-from hselasky@c2i.net) Received: from swip.net (mailfe03.swip.net [212.247.154.65]) by mx1.FreeBSD.org (Postfix) with ESMTP id 0C2D343D4C for ; Wed, 2 Aug 2006 12:37:50 +0000 (GMT) (envelope-from hselasky@c2i.net) X-T2-Posting-ID: 1rcm8C/pG43AzMhanPJHZA== X-Cloudmark-Score: 0.000000 [] Received: from [193.216.121.206] (HELO [10.0.0.249]) by mailfe03.swip.net (CommuniGate Pro SMTP 5.0.8) with ESMTP id 253186996 for freebsd-hackers@freebsd.org; Wed, 02 Aug 2006 14:37:47 +0200 From: Hans Petter Selasky To: freebsd-hackers@freebsd.org Date: Wed, 2 Aug 2006 14:37:55 +0200 User-Agent: KMail/1.7 MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Content-Disposition: inline Message-Id: <200608021437.55500.hselasky@c2i.net> Subject: miibus + USB = problem X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 02 Aug 2006 12:37:55 -0000 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