From owner-freebsd-hackers@FreeBSD.ORG Mon May 3 05:10:51 2004 Return-Path: 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 5993716A4CE for ; Mon, 3 May 2004 05:10:51 -0700 (PDT) Received: from srv1.cosmo-project.de (srv1.cosmo-project.de [213.83.6.106]) by mx1.FreeBSD.org (Postfix) with ESMTP id 492F143D46 for ; Mon, 3 May 2004 05:10:50 -0700 (PDT) (envelope-from ticso@cicely12.cicely.de) Received: from cicely5.cicely.de (cicely5.cicely.de [IPv6:3ffe:400:8d0:301:200:92ff:fe9b:20e7]) (authenticated bits=0) i43C8uDv081705 (version=TLSv1/SSLv3 cipher=EDH-RSA-DES-CBC3-SHA bits=168 verify=OK); Mon, 3 May 2004 14:09:25 +0200 (CEST) (envelope-from ticso@cicely12.cicely.de) Received: from cicely12.cicely.de (cicely12.cicely.de [IPv6:3ffe:400:8d0:301::12]) by cicely5.cicely.de (8.12.10/8.12.10) with ESMTP id i43C8QUi082867 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Mon, 3 May 2004 14:08:27 +0200 (CEST) (envelope-from ticso@cicely12.cicely.de) Received: from cicely12.cicely.de (localhost [127.0.0.1]) by cicely12.cicely.de (8.12.11/8.12.11) with ESMTP id i43C8QrJ042697; Mon, 3 May 2004 14:08:26 +0200 (CEST) (envelope-from ticso@cicely12.cicely.de) Received: (from ticso@localhost) by cicely12.cicely.de (8.12.11/8.12.11/Submit) id i43C8P31042696; Mon, 3 May 2004 14:08:25 +0200 (CEST) (envelope-from ticso) Date: Mon, 3 May 2004 14:08:25 +0200 From: Bernd Walter To: Rita Lin Message-ID: <20040503120824.GG38488@cicely12.cicely.de> References: <004c01c43053$2a775920$9402a8c0@emachine> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <004c01c43053$2a775920$9402a8c0@emachine> X-Operating-System: FreeBSD cicely12.cicely.de 5.2-CURRENT alpha User-Agent: Mutt/1.5.6i X-Spam-Status: No, hits=-4.9 required=3.0 tests=BAYES_00 autolearn=ham version=2.63 X-Spam-Report: * -4.9 BAYES_00 BODY: Bayesian spam probability is 0 to 1% * [score: 0.0000] X-Spam-Checker-Version: SpamAssassin 2.63 (2004-01-11) on cicely12.cicely.de cc: freebsd-hackers@freebsd.org Subject: Re: USB device driver question: timeout() and usbd_do_request() X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list Reply-To: ticso@cicely.de List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 03 May 2004 12:10:51 -0000 On Sun, May 02, 2004 at 10:38:42AM -0400, Rita Lin wrote: > Hello, > > I'm writing a USB driver for a device that does not have any interrupt. It only has Bulk-in and Bulk-out. A periodic polling status from default pipe is required to have a smooth data transfer. I used timeout() routine to call usbd_do_request() for polling. I thought maybe timeout() is called under interrupt context, since usbd_do_request() access system I/O, it crashes. However, by adding this timeout() in ucomstart(), it didn't crash until the third call to timeout(). Removing usbd_do_request() allows the timeout() to work without any problem. From the USB analyzer, I could see that even if the system crashed, a request was sent to the USB device correctly. There are two crashdump messages printed out to the screen, I could only catch the second one. The first one scrolled off the screen too fast. By counting the byte and the instruction pointer, the routine crashed in acquire_lock(). I 'greped' the kernel source code, didn't see this routine. > > I know I'm missing some important FreeBSD concept since I'm new to it, by reading related document did not reveal anything that might help me. If usbd_do_request() should never be used in timeout() as a callback routine, what other options do I have, to implement a status-polling scheme? You can't use usbd_do_request in timeout as it requires memory allocation, etc... But I don't understand the whole issue you have. Just schedule a request and wait for the device to ack. The Host controller does the polling for you as long as the request is queued and the timeout value supplied with the request did not time out. That has nothing to do with FreeBSD - it's how things work with USB in general. PS: please break lines -- B.Walter BWCT http://www.bwct.de bernd@bwct.de info@bwct.de