From owner-freebsd-drivers@FreeBSD.ORG Wed Nov 2 16:31:22 2011 Return-Path: Delivered-To: freebsd-drivers@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 502FE1065670 for ; Wed, 2 Nov 2011 16:31:22 +0000 (UTC) (envelope-from sghctoma@gmail.com) Received: from mail-fx0-f54.google.com (mail-fx0-f54.google.com [209.85.161.54]) by mx1.freebsd.org (Postfix) with ESMTP id D81F58FC15 for ; Wed, 2 Nov 2011 16:31:21 +0000 (UTC) Received: by faar19 with SMTP id r19so903037faa.13 for ; Wed, 02 Nov 2011 09:31:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=date:from:to:subject:message-id:mime-version:content-type :content-disposition:user-agent; bh=RgIwHqOxpfvDV5d4svrlADXUDafy6ld93z0PYA70oSU=; b=CPpZVA2fojO1fxXO24ywJD82LhSwnvWMcLJ2pFSbX0QiZ1guxkl7ZIydU8lRTrZgb3 Vaa4x7ME7LXHhNzKqB4mVElxe/4S2B0/4p+ZpuX+2fLqX2NNPPtf7WPipmSid+v8Cp+8 Y1R4dXulbuU0L0pMPwOvWKojUCwplpzh331ho= Received: by 10.223.62.209 with SMTP id y17mr9365740fah.7.1320249708780; Wed, 02 Nov 2011 09:01:48 -0700 (PDT) Received: from localhost (mail.praudit.hu. [89.135.48.141]) by mx.google.com with ESMTPS id x19sm6202271fag.5.2011.11.02.09.01.45 (version=TLSv1/SSLv3 cipher=OTHER); Wed, 02 Nov 2011 09:01:46 -0700 (PDT) Date: Wed, 2 Nov 2011 17:01:44 +0100 From: Tamas Szakaly To: freebsd-drivers@freebsd.org Message-ID: <20111102160144.GA487@izebigyomicsoda.praudit.hu> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline User-Agent: Mutt/1.5.21 (2010-09-15) Subject: ThinkPad battery charge control X-BeenThere: freebsd-drivers@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Writing device drivers for FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 02 Nov 2011 16:31:22 -0000 Hi, Two weaks ago a conversation started at freebsd-mobile about battery charge limiting. During this weekend I had some time to look up the ThinkPad 770 Technical Reference Manual (http://support.lenovo.com/en_US/detail.page?LegacyDocID=PFAN-3tuQQD), the ThinkPad Power Manager for Windows XP, and the tp_smapi Linux driver (http://sourceforge.net/projects/tpctl/files/tp_smap). I managed to write a kernel module that exposes the ThinkPad SMAPI features via the following sysctls: - hw.thinkpad_smapi.batX.start_threshold: charge start threshold (0-100) - hw.thinkpad_smapi.batX.stop_threshold: charge stop threshold (0-100) - hw.thinkpad_smapi.batX.force_discharge: enable/disable force discharge (0,1) - hw.thinkpad_smapi.batX.inhibit_charge_minutes: inhibit charge for given minutes (0-65535) X can be 0 or 1. The module works OK, but I have very-very little experience with kernel programming (added some sysctls to psm.c to control TrackPoint behaviour a year ago), and I have some concerns about how this functionality should be implemented correctly: - Is the sysctl way OK? Or should I expose those features via ioctl or character device read/write functions? - To access SMAPI, one have to write two I/O ports, 0xb2 and 0x4f. My problem is the following: the code works without mapping/allocating those two I/O ports, but I think, they should be mapped/allocated nevertheless. Am I right? - I used the term map/allocate, because I don't know what function to use to achieve this. At first I was using bus_space_map/bus_space_unmap like this: bus_space_map(X86_BUS_SPACE_IO, port, 1, 0, &bsh1) bus_space_map(X86_BUS_SPACE_IO, SMAPI_PORT, 1, 0, &bsh2) ... bus_space_unmap(X86_BUS_SPACE_IO, bsh1, 1) bus_space_unmap(X86_BUS_SPACE_IO, bsh2, 2) But neither of the drivers I saw use this pair of functions. Every one of them uses bus_alloc_resource/bus_release_resource. So I tried those functions as well: in identify: bus_set_resource(child, SYS_RES_IOPORT, 0, port, 1); bus_set_resource(child, SYS_RES_IOPORT, 1, SMAPI_PORT, 1); in probe: if (bus_get_resource_start(dev, SYS_RES_IOPORT, 0) == 0) return(ENXIO); if (bus_get_resource_start(dev, SYS_RES_IOPORT, 1) == 0) return(ENXIO); in attach: sc->rid1 = 0; sc->res1 = bus_alloc_resource(dev, SYS_RES_IOPORT, &sc->rid1, port, port, 1, RF_ACTIVE); sc->rid2 = 1; sc->res2 = bus_alloc_resource(dev, SYS_RES_IOPORT, &sc->rid2, SMAPI_PORT, SMAPI_PORT, 1, RF_ACTIVE); But the allocation fails. devinfo -r tells me, that I/O port 0xb2 is already allocated by acpi. So I tried to make acpi my driver's parent: DRIVER_MODULE(thinkpad_smapi, acpi, ... After this the allocation works, devinfo -r tells, that 0xb2 and 0x4f is allocted by my driver. But when I unload the module, and try to load it again, it fails. Please note, that bus_release_resource is called upon unloading the module and devinfo -r shows that 0xb2 is allocated by acpi again. What am I doing wrong? Sorry for the overly-long mail, and the possibly newbie questions, but I have read lots of man(9) pages, mailing list threads, and sources of drivers, and I am still confused. Any help is well appreciated. Thank you in advance! Regards, sghctoma -- From owner-freebsd-drivers@FreeBSD.ORG Thu Nov 3 18:23:06 2011 Return-Path: Delivered-To: freebsd-drivers@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 765E61065672 for ; Thu, 3 Nov 2011 18:23:06 +0000 (UTC) (envelope-from adarsh.joshi@qlogic.com) Received: from AM1EHSOBE005.bigfish.com (am1ehsobe005.messaging.microsoft.com [213.199.154.208]) by mx1.freebsd.org (Postfix) with ESMTP id C27A08FC1B for ; Thu, 3 Nov 2011 18:23:05 +0000 (UTC) Received: from mail81-am1-R.bigfish.com (10.3.201.252) by AM1EHSOBE005.bigfish.com (10.3.204.25) with Microsoft SMTP Server id 14.1.225.22; Thu, 3 Nov 2011 18:22:48 +0000 Received: from mail81-am1 (localhost.localdomain [127.0.0.1]) by mail81-am1-R.bigfish.com (Postfix) with ESMTP id E6ACC8F837C for ; Thu, 3 Nov 2011 18:22:57 +0000 (UTC) X-SpamScore: 0 X-BigFish: VPS0(zzc85fhzz1202hzz8275bh8275dhz2fh2a8h668h839h61h) X-Spam-TCS-SCL: 0:0 X-Forefront-Antispam-Report: CIP:198.70.193.61; KIP:(null); UIP:(null); IPVD:NLI; H:avexcashub1.qlogic.com; RD:avexcashub1.qlogic.com; EFVD:NLI X-FB-SS: 0,0, Received-SPF: pass (mail81-am1: domain of qlogic.com designates 198.70.193.61 as permitted sender) client-ip=198.70.193.61; envelope-from=adarsh.joshi@qlogic.com; helo=avexcashub1.qlogic.com ; 1.qlogic.com ; Received: from mail81-am1 (localhost.localdomain [127.0.0.1]) by mail81-am1 (MessageSwitch) id 1320344546579883_23330; Thu, 3 Nov 2011 18:22:26 +0000 (UTC) Received: from AM1EHSMHS015.bigfish.com (unknown [10.3.201.243]) by mail81-am1.bigfish.com (Postfix) with ESMTP id 844901B20056 for ; Thu, 3 Nov 2011 18:22:26 +0000 (UTC) Received: from avexcashub1.qlogic.com (198.70.193.61) by AM1EHSMHS015.bigfish.com (10.3.207.153) with Microsoft SMTP Server (TLS) id 14.1.225.22; Thu, 3 Nov 2011 18:22:16 +0000 Received: from avexmb1.qlogic.org ([fe80::9545:3a4f:c131:467d]) by avexcashub1.qlogic.org ([::1]) with mapi; Thu, 3 Nov 2011 11:22:23 -0700 From: Adarsh Joshi To: "freebsd-drivers@freebsd.org" Date: Thu, 3 Nov 2011 11:22:22 -0700 Thread-Topic: Is it possible to change the log level of a device driver at runtime? Thread-Index: AcyaVN5U77ROL/apS6ihhhRu9S9roA== Message-ID: <5E4F49720D0BAD499EE1F01232234BA873C6F1A523@AVEXMB1.qlogic.org> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: acceptlanguage: en-US MIME-Version: 1.0 X-OriginatorOrg: qlogic.com Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable X-Content-Filtered-By: Mailman/MimeDel 2.1.5 Subject: Is it possible to change the log level of a device driver at runtime? X-BeenThere: freebsd-drivers@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Writing device drivers for FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 03 Nov 2011 18:23:06 -0000 Hi, Is it possible to change the log level of a device driver at runtime? I am trying to understand a network based device driver. It already has a n= umber of print messages which are only printed if the debug flag is 1. Is i= t possible to toggle the debug flag when the driver is loaded, at runtime w= ith some command? A detailed explanation on how to go about this would be very helpful. thanks Adarsh ________________________________ This message and any attached documents contain information from QLogic Cor= poration or its wholly-owned subsidiaries that may be confidential. If you = are not the intended recipient, you may not read, copy, distribute, or use = this information. If you have received this transmission in error, please n= otify the sender immediately by reply e-mail and then delete this message. From owner-freebsd-drivers@FreeBSD.ORG Thu Nov 3 18:42:30 2011 Return-Path: Delivered-To: freebsd-drivers@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id CA9761065670 for ; Thu, 3 Nov 2011 18:42:30 +0000 (UTC) (envelope-from adarsh.joshi@qlogic.com) Received: from VA3EHSOBE001.bigfish.com (va3ehsobe001.messaging.microsoft.com [216.32.180.11]) by mx1.freebsd.org (Postfix) with ESMTP id 7F7688FC1C for ; Thu, 3 Nov 2011 18:42:30 +0000 (UTC) Received: from mail117-va3-R.bigfish.com (10.7.14.235) by VA3EHSOBE001.bigfish.com (10.7.40.21) with Microsoft SMTP Server id 14.1.225.22; Thu, 3 Nov 2011 18:42:12 +0000 Received: from mail117-va3 (localhost [127.0.0.1]) by mail117-va3-R.bigfish.com (Postfix) with ESMTP id 19DAC6A00FA; Thu, 3 Nov 2011 18:42:17 +0000 (UTC) X-SpamScore: 1 X-BigFish: VPS1(zzzz1202hzzz2ei2a8h668h839h944h61h) X-Spam-TCS-SCL: 0:0 X-Forefront-Antispam-Report: CIP:198.70.193.64; KIP:(null); UIP:(null); IPV:NLI; H:avexcashub1.qlogic.com; RD:avexcashub2.qlogic.com; EFVD:NLI Received-SPF: neutral (mail117-va3: 198.70.193.64 is neither permitted nor denied by domain of qlogic.com) client-ip=198.70.193.64; envelope-from=adarsh.joshi@qlogic.com; helo=avexcashub1.qlogic.com ; 1.qlogic.com ; Received: from mail117-va3 (localhost.localdomain [127.0.0.1]) by mail117-va3 (MessageSwitch) id 1320345736884703_26628; Thu, 3 Nov 2011 18:42:16 +0000 (UTC) Received: from VA3EHSMHS022.bigfish.com (unknown [10.7.14.239]) by mail117-va3.bigfish.com (Postfix) with ESMTP id C6AFC600042; Thu, 3 Nov 2011 18:42:16 +0000 (UTC) Received: from avexcashub1.qlogic.com (198.70.193.64) by VA3EHSMHS022.bigfish.com (10.7.99.32) with Microsoft SMTP Server (TLS) id 14.1.225.22; Thu, 3 Nov 2011 18:42:11 +0000 Received: from avexmb1.qlogic.org ([fe80::9545:3a4f:c131:467d]) by avexcashub2.qlogic.org ([::1]) with mapi; Thu, 3 Nov 2011 11:42:20 -0700 From: Adarsh Joshi To: John-Mark Gurney Date: Thu, 3 Nov 2011 11:42:18 -0700 Thread-Topic: Is it possible to change the log level of a device driver at runtime? Thread-Index: AcyaV4a1ySouWMTVQJ2kGxcV9xu0MwAADKBQ Message-ID: <5E4F49720D0BAD499EE1F01232234BA873C6F1A540@AVEXMB1.qlogic.org> References: <5E4F49720D0BAD499EE1F01232234BA873C6F1A523@AVEXMB1.qlogic.org> <20111103183637.GD25601@funkthat.com> In-Reply-To: <20111103183637.GD25601@funkthat.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: acceptlanguage: en-US Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-OriginatorOrg: qlogic.com Cc: "freebsd-drivers@freebsd.org" Subject: RE: Is it possible to change the log level of a device driver at runtime? X-BeenThere: freebsd-drivers@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Writing device drivers for FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 03 Nov 2011 18:42:30 -0000 John, The driver is not yet in the tree. I am trying to implement the change of debug level at run time. Can you kin= dly explain how do I do it? ( by setting the sysctl as you mentioned) Thanks Adarsh This message and any attached documents contain information from QLogic Cor= poration or its wholly-owned subsidiaries that may be confidential. If you = are not the intended recipient, you may not read, copy, distribute, or use = this information. If you have received this transmission in error, please n= otify the sender immediately by reply e-mail and then delete this message. From owner-freebsd-drivers@FreeBSD.ORG Thu Nov 3 19:15:20 2011 Return-Path: Delivered-To: freebsd-drivers@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 6B1851065680 for ; Thu, 3 Nov 2011 19:15:20 +0000 (UTC) (envelope-from jmg@h2.funkthat.com) Received: from h2.funkthat.com (gate.funkthat.com [70.36.235.232]) by mx1.freebsd.org (Postfix) with ESMTP id D8B198FC19 for ; Thu, 3 Nov 2011 19:15:19 +0000 (UTC) Received: from h2.funkthat.com (localhost [127.0.0.1]) by h2.funkthat.com (8.14.3/8.14.3) with ESMTP id pA3Iabsj051308 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Thu, 3 Nov 2011 11:36:37 -0700 (PDT) (envelope-from jmg@h2.funkthat.com) Received: (from jmg@localhost) by h2.funkthat.com (8.14.3/8.14.3/Submit) id pA3Iab3K051307; Thu, 3 Nov 2011 11:36:37 -0700 (PDT) (envelope-from jmg) Date: Thu, 3 Nov 2011 11:36:37 -0700 From: John-Mark Gurney To: Adarsh Joshi Message-ID: <20111103183637.GD25601@funkthat.com> Mail-Followup-To: Adarsh Joshi , "freebsd-drivers@freebsd.org" References: <5E4F49720D0BAD499EE1F01232234BA873C6F1A523@AVEXMB1.qlogic.org> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <5E4F49720D0BAD499EE1F01232234BA873C6F1A523@AVEXMB1.qlogic.org> User-Agent: Mutt/1.4.2.3i X-Operating-System: FreeBSD 7.2-RELEASE 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 X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.2.2 (h2.funkthat.com [127.0.0.1]); Thu, 03 Nov 2011 11:36:38 -0700 (PDT) Cc: "freebsd-drivers@freebsd.org" Subject: Re: Is it possible to change the log level of a device driver at runtime? X-BeenThere: freebsd-drivers@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Writing device drivers for FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 03 Nov 2011 19:15:20 -0000 Adarsh Joshi wrote this message on Thu, Nov 03, 2011 at 11:22 -0700: > Is it possible to change the log level of a device driver at runtime? > > I am trying to understand a network based device driver. It already has a number of print messages which are only printed if the debug flag is 1. Is it possible to toggle the debug flag when the driver is loaded, at runtime with some command? > > A detailed explanation on how to go about this would be very helpful. Depends upon the driver. Some drivers allow you to set a sysctl to change the debug level, others do not. Which driver are we talking about? Is it in the tree, or is it a vendor supplied driver? -- John-Mark Gurney Voice: +1 415 225 5579 "All that I will do, has been done, All that I have, has not." From owner-freebsd-drivers@FreeBSD.ORG Fri Nov 4 04:11:59 2011 Return-Path: Delivered-To: freebsd-drivers@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 2B7FA106564A for ; Fri, 4 Nov 2011 04:11:59 +0000 (UTC) (envelope-from jmg@h2.funkthat.com) Received: from h2.funkthat.com (gate.funkthat.com [70.36.235.232]) by mx1.freebsd.org (Postfix) with ESMTP id 073F38FC1D for ; Fri, 4 Nov 2011 04:11:58 +0000 (UTC) Received: from h2.funkthat.com (localhost [127.0.0.1]) by h2.funkthat.com (8.14.3/8.14.3) with ESMTP id pA44Bw5L059663 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Thu, 3 Nov 2011 21:11:58 -0700 (PDT) (envelope-from jmg@h2.funkthat.com) Received: (from jmg@localhost) by h2.funkthat.com (8.14.3/8.14.3/Submit) id pA44Bwgb059662; Thu, 3 Nov 2011 21:11:58 -0700 (PDT) (envelope-from jmg) Date: Thu, 3 Nov 2011 21:11:58 -0700 From: John-Mark Gurney To: Adarsh Joshi Message-ID: <20111104041157.GG25601@funkthat.com> Mail-Followup-To: Adarsh Joshi , "freebsd-drivers@freebsd.org" References: <5E4F49720D0BAD499EE1F01232234BA873C6F1A523@AVEXMB1.qlogic.org> <20111103183637.GD25601@funkthat.com> <5E4F49720D0BAD499EE1F01232234BA873C6F1A540@AVEXMB1.qlogic.org> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <5E4F49720D0BAD499EE1F01232234BA873C6F1A540@AVEXMB1.qlogic.org> User-Agent: Mutt/1.4.2.3i X-Operating-System: FreeBSD 7.2-RELEASE 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 X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.2.2 (h2.funkthat.com [127.0.0.1]); Thu, 03 Nov 2011 21:11:58 -0700 (PDT) Cc: "freebsd-drivers@freebsd.org" Subject: Re: Is it possible to change the log level of a device driver at runtime? X-BeenThere: freebsd-drivers@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Writing device drivers for FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 04 Nov 2011 04:11:59 -0000 Adarsh Joshi wrote this message on Thu, Nov 03, 2011 at 11:42 -0700: > The driver is not yet in the tree. > > I am trying to implement the change of debug level at run time. Can you kindly explain how do I do it? ( by setting the sysctl as you mentioned) There are two different ways... If you want it to apply to all instances of your driver, take a look at the SYSCTL(9) manpage... You'll probably want to use SYSCTL_INT... If you want it to be on a per device basis, you can use device_get_sysctl_ctx to get the sysctl context for your driver, and use SYSCTL_ADD_xxx w/ that context... If you need to have it set at boot time, include a TUNABLE_INT... Hope this helps! And take a look at how other drivers do it... A driver like sys/dev/e1000/if_em.c has some good examples... -- John-Mark Gurney Voice: +1 415 225 5579 "All that I will do, has been done, All that I have, has not."