From owner-freebsd-net@FreeBSD.ORG Tue Sep 4 01:46:13 2007 Return-Path: Delivered-To: freebsd-net@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 52B3316A417 for ; Tue, 4 Sep 2007 01:46:13 +0000 (UTC) (envelope-from jmg@hydrogen.funkthat.com) Received: from hydrogen.funkthat.com (gate.funkthat.com [69.17.45.168]) by mx1.freebsd.org (Postfix) with ESMTP id 180EA13C45E for ; Tue, 4 Sep 2007 01:46:13 +0000 (UTC) (envelope-from jmg@hydrogen.funkthat.com) Received: from hydrogen.funkthat.com (9kyquabcmqfiuahp@localhost.funkthat.com [127.0.0.1]) by hydrogen.funkthat.com (8.13.6/8.13.3) with ESMTP id l841kC61053984; Mon, 3 Sep 2007 18:46:12 -0700 (PDT) (envelope-from jmg@hydrogen.funkthat.com) Received: (from jmg@localhost) by hydrogen.funkthat.com (8.13.6/8.13.3/Submit) id l841k9cD053983; Mon, 3 Sep 2007 18:46:09 -0700 (PDT) (envelope-from jmg) Date: Mon, 3 Sep 2007 18:46:09 -0700 From: John-Mark Gurney To: Prahar Shah Message-ID: <20070904014609.GG977@funkthat.com> Mail-Followup-To: Prahar Shah , freebsd-net@freebsd.org References: Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.4.2.1i X-Operating-System: FreeBSD 5.4-RELEASE-p6 i386 X-Files: The truth is out there X-URL: http://resnet.uoregon.edu/~gurney_j/ X-Resume: http://resnet.uoregon.edu/~gurney_j/resume.html Cc: freebsd-net@freebsd.org Subject: Re: Accessing device memory from user-land application process X-BeenThere: freebsd-net@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list Reply-To: John-Mark Gurney List-Id: Networking and TCP/IP with FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 04 Sep 2007 01:46:13 -0000 Prahar Shah wrote this message on Fri, Aug 31, 2007 at 10:30 +0530: > I am writing a device driver in user-land process. I do a contigmalloc() to > allocate the descriptor memory, do a vtophys() on it and mmap that memory in > the user-land application process. I allocate buffers again using You should be using bus_dma(9) instead of vtophys... With bus_dma, you won't have to restrict your driver to i386 and other platforms that provide vtophys... > contigmalloc(), and mmap it within the same process. I pass on a buffer each > to the device descriptor. And my packet reception works fine. > While processing packets, once i reset the device (all device registers and > related memory), and repopulate buffers into the descriptors, I > occasionally find that while receiving a packet after reset, the buffer > address that I read from the first descriptor is not the one that I gave to > the descriptor after the reset. Instead, it turns out to be an older buffer > address which as allocated to a descriptor which was supposed to be read > next, prior to the reset. > My doubt is, could this be a cache-coherency issue? Or could there be a > chance that the device might be caching the buffer address available with > the descriptors, and re-writing back to the descriptor after receiving the > packet, and somehow these cached address are not flushed during a device > reset? Probably a cache issue... If you use bus_dma, you can call bus_dmamap_sync to deal w/ the cache issue... > If i've missed any details, kindly let me know. > Any help would be greatly appriciated Good luck! Hope this helps... -- John-Mark Gurney Voice: +1 415 225 5579 "All that I will do, has been done, All that I have, has not."