All of lore.kernel.org
 help / color / mirror / Atom feed
From: Loic Poulain <loic.poulain@intel.com>
To: Marcel Holtmann <marcel@holtmann.org>
Cc: linux-bluetooth@vger.kernel.org
Subject: Re: btattach: Add auto attach/detach
Date: Thu, 17 Sep 2015 12:25:05 +0200	[thread overview]
Message-ID: <55FA9501.3010009@intel.com> (raw)
In-Reply-To: <9BF6835F-CCFF-40BF-9E6C-895FFA14D85B@holtmann.org>

Hi Marcel,

>> I wonder if adding a dynamic attach/detach to btattach could be a good idea.
>>
>> Since most HCI UART drivers power on/off the Bluetooth controller on proto/ldisc open/close.
>> It could be interesting to attach/detach the line discipline depending Bluetooth usage.
>>
>> A way to do that could be to track rfkill events via the /dev/rfkill device.
>> I can propose two solutions:
>>
>> - btattach monitors a specific rfkill node whose index is a passed as argument
>> and ldisc is attached/detached accordingly.
>>
>> - An other solution could be to create a rfkill node from btattach so that if
>> something blocks/unblocks the node, HCI ldisc is detached/attached automatically.
>> Problem is that we can't create a rfkill node from user-space, but I think we can
>> easily add this support to the rfkill device driver.
>>
>> On my laptop, the Thinkpad acpi driver exports a rfkill nodes which disconnects/reconnects
>> the USB embedded Bluetooth controller. This is what I would like to reproduce for UART here.
> I do not think this is a good behavior to duplicated. The laptops that kill the USB lines are actually a pain to support properly. That is the reason why RFKILL_CHANGE_ALL exists. Since you can never map the platform rfkill switch to the actual device it kills. It is a real mess.
>
> Bluetooth subsystem has currently the concept of a soft rfkill switch that gets exposed every time you register a new device (so attaching the ldisc will create one) and that maps to hdev->close. It allows to force something similar to flight mode that kills all radios.
>
> For a hard rfkill switch, we would need way more knowledge to facility this correctly. However WiFi has done something like that where each driver can provide a hard rfkill switch callback that gets linked correctly together with the soft rfkill switch. We could do something similar.
>
> However what you need to asked yourself is if hdev->close is actually any different than detaching ldisc. From where I am standing it should not be. Attaching ldisc is telling the kernel about the UART and nothing else. It is not meant for power control. It is meant to tell the kernel that this UART is actually a BT chip. The power control should happen via hdev->open and hdev->close. Since we introduced the hdev->setup stage keeping the ldisc attached is actually favorable for latency reason. Otherwise you end up loading the firmware over and over again.
>
> I know that for some ACPI exposed BT devices, we have the generic rfkill-gpio driver to claim them. This needs to be reverted as soon as the kernel supports power control for these within the hci_uart driver. This listening to /dev/rfkill and execute hciattach on it that has been done in Edison is a bad design. It is racy and error prone.
>
> For the Broadcom support, we have taking the ACPI ID out of the rfkill-gpio driver and now hci_uart owns it. So attaching the ldisc means we are taking over control. Once that happened, you have the soft rfkill switch attached to the hci0 device.
>
> Do you really need a hard rfkill switch as well. Normally the hard rfkill switch means that there is physical button on the system that does something. None of this is a physical button. And having two soft rfkill switches is not really helpful. It is actually confusing and will not bring you any extra benefit.

OK, btattach should stay a minimal attacher.

Meaning that in a normal case, The HCI line discipline should stay 
attached for all system uptime. So, all the power stuff has to be 
managed by the HCI UART driver.

I don't know what is the real gain to power off the chip instead of keep 
it idle, and maybe it's overkill in many case.

In case of mobile platforms (Android+Bluedroid), all vendor 
implementations tend to power-off the BT controller when bluetooth is 
disabled (broadcom, rtk...).
This is something that bluez 'should' propose as well.

However, I'm OK that powering off/on the bluetooth controller on 
hdev->open/hdev->close is not a good solution, since we will have to 
upload the firmware on each hdev->open. We don't want having latency on 
hci up/down.

Having new callbacks could be a solution. For example 
hdev->start/hdev->stop triggered by the bluetooth rfkill hw switch or by 
a management command.
A hdev->shutdown callback already exist, but is only used as a pre-close 
HCI epilog callback (btusb intel).

An other point is that detaching the ldisc (by closing tty fd) also 
releases The UART port which in turn can be put in low power state.
However it's more a UART driver issue here, and its seems to be 
partially fixed with the fine grained pm runtime support in the 8250 
serial driver (d74d5d1b7288f).

Regards,
Loic

-- 
Intel Open Source Technology Center
http://oss.intel.com/

  reply	other threads:[~2015-09-17 10:25 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-09-15 14:00 btattach: Add auto attach/detach Loic Poulain
2015-09-16  9:15 ` Marcel Holtmann
2015-09-17 10:25   ` Loic Poulain [this message]
2015-09-17 11:16     ` Marcel Holtmann
2015-09-17 13:53       ` Loic Poulain

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=55FA9501.3010009@intel.com \
    --to=loic.poulain@intel.com \
    --cc=linux-bluetooth@vger.kernel.org \
    --cc=marcel@holtmann.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.