From owner-freebsd-wireless@FreeBSD.ORG Sun Mar 30 08:31:26 2014 Return-Path: Delivered-To: freebsd-wireless@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id C5266755 for ; Sun, 30 Mar 2014 08:31:26 +0000 (UTC) Received: from mail-qg0-x22f.google.com (mail-qg0-x22f.google.com [IPv6:2607:f8b0:400d:c04::22f]) (using TLSv1 with cipher ECDHE-RSA-RC4-SHA (128/128 bits)) (Client CN "smtp.gmail.com", Issuer "Google Internet Authority G2" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 88368174 for ; Sun, 30 Mar 2014 08:31:26 +0000 (UTC) Received: by mail-qg0-f47.google.com with SMTP id 63so6169758qgz.34 for ; Sun, 30 Mar 2014 01:31:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:sender:date:message-id:subject:from:to:content-type; bh=LUVGkXhhunU+iUWzmOJ2HdQGkWqkKK2CJc9YYzcXwcI=; b=vkbRHT2Ci1DObsYzu5SLqJw13T5pXbwG4USSQZ4LNRxYz+xbrF5YXsc2st8Tdc5YlZ LJb1z/TPuugEkjRsZcrbxU8hS4t1Y2xYOdoGTPaBCdZsaqt3sVAOB3/5q8+5khQDL1vT 4Jrn+oglixLGmy1r/7EK8taCyGwoy/pDhJ0KIILNHqORKRbF85q9USbjYZqkee3CekTk t4La1JnYWbCbX8TTLfe4QWfE8dmVVFW4qh7PpUiRa2OwYJ6TIsP49MViB2XOqSOBIpkO ZhHzc4FFtWvB6ipEx7ol7eKGuYOHpBzDasKZcBTk+v9cdFc2MwexbiMFEYK99qdb2lcS 6wbQ== MIME-Version: 1.0 X-Received: by 10.224.119.141 with SMTP id z13mr20044685qaq.48.1396168285687; Sun, 30 Mar 2014 01:31:25 -0700 (PDT) Sender: adrian.chadd@gmail.com Received: by 10.224.50.143 with HTTP; Sun, 30 Mar 2014 01:31:25 -0700 (PDT) Date: Sun, 30 Mar 2014 01:31:25 -0700 X-Google-Sender-Auth: 9-I9TsN02AmKLWkykMrdHY3qKVs Message-ID: Subject: [rft] ath(4) and preparations for power save support in STA mode From: Adrian Chadd To: "freebsd-wireless@freebsd.org" Content-Type: text/plain; charset=ISO-8859-1 X-BeenThere: freebsd-wireless@freebsd.org X-Mailman-Version: 2.1.17 Precedence: list List-Id: "Discussions of 802.11 stack, tools device driver development." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 30 Mar 2014 08:31:26 -0000 Hi, I've been working towards supporting basic power save support in ath(4). Now, this patch implements the basic driver hooks required to attempt to do this. It's only been lightly tested on the AR5416. I haven't tested it on any other hardware so if you do try this, it may just blow up in your face. http://people.freebsd.org/~adrian/ath/20140330-ath-powersave-1.diff However, it's also supposed to be a no-op during normal driver use. So what's it do? Firstly, the hardware has three main states. "full sleep" is the lowest power mode. "force awake" is "being forced fully awake, regardless of whether we need to be." Finally, and the most interesting one, is "network sleep." This is where the MAC powers down bits and pieces of things until each beacon interval when it wakes up to receive the beacon, check if the station AID is set in the TIM (or ATIM for later hardware, if in IBSS mode) and if so, stays awake long enough to receive further frames before going to sleep. Now for the gruesome details. * The hardware has to be woken up for things like calibration and DMA work. * The hardware can go into network sleep until each beacon interval (but, see below.) * Only some registers can be read - for the AR5416 family, it's the RTC (clock programming and power mode), the host interface (GPIO, LED and PCI/PCIe interface, including SYNC interrupts), and the EEPROM interface. So in order to ensure everything else is valid, one must force the device awake if the pending-interrupts check shows there's something to handle. * .. and it should also be forced awake for the TX, RX and TX completion path * .. as well as reset, channel programming, etc. * The hardware may decide to go to sleep once the reason(s) for it to be awake are gone, so it's best to force it awake to do whatever's needed and then put it back to network sleep once it's done. * The AR5416 at least will stay awake if you start a transmit and then let it go back to network sleep. Ie, you don't have to keep the hardware set as "force awake" when doing a transmit - which greatly simplifies the transmit logic. However, I've no idea if this holds true for all the other various chips out there. So, the patch as posted actually seems to work well enough if I force the hardware to network sleep - I'm not programming the TX or RX registers inappropriately or trying to do calibration whilst the NIC is asleep. However, it won't stay associated because, and this is totally expected - none of the net80211 station powersave framework is hooked in. Specifically: * The frames being transmitted whilst the NIC is asleep don't have the FC1 PWR_MGT bit set to 1, so the AP doesn't try buffering things, and * There's nothing comprehensive to hook into the receive path to tell the AP that we're now awake. It turns out there's a powersave state (IEEE80211_S_SLEEP) which is mostly implemented. There's also the STA powersave stuff that's used by the bgscan code that also is useful for exactly this. It will correctly buffer outbound frames until we come out of powersave and it'll send NULL frames appropriately to the AP to bring it in and out of powersave. What's however missing is: * if a beacon is received with the TIM bit for us set to 1, we need to either kick off a ps-poll (which we have no support for transmitting yet) or wake the VAP up. Otherwise we'll just stay asleep until we force ourselves back to RUN. * There's no actual sleep management code for station mode operation. Ie, nothing tracks ic_lastdata or anything else and decides to transition the VAP to SLEEP, neither does it have any logic to transition it back to RUN after a timeout (ie, being asleep too long.) I'm going to take a crack at sorting out the missing power-save hooks in net80211 so we can do explicit power save if the NIC requires it. iwn(4) doesn't, so the IEEE80211_S_SLEEP stuff just plain won't be used there. Given all of this, I'd appreciate it if people would try the above patch out with AH_DEBUG and ATH_DEBUG compiled in. Let me know if it complains about anything. Thanks, -a