From: Pavel Machek <pavel@ucw.cz>
To: Marcel Holtmann <marcel@holtmann.org>
Cc: "Pali Rohár" <pali.rohar@gmail.com>,
"Ивайло Димитров" <freemangordon@abv.bg>,
"Gustavo F. Padovan" <gustavo@padovan.org>,
"Johan Hedberg" <johan.hedberg@gmail.com>,
linux-kernel <linux-kernel@vger.kernel.org>,
"linux-bluetooth@vger.kernel.org development"
<linux-bluetooth@vger.kernel.org>,
"Ville Tervo" <ville.tervo@nokia.com>,
"Sebastian Reichel" <sre@ring0.de>
Subject: Re: [PATCH v2] Bluetooth: Add hci_h4p driver
Date: Wed, 1 Jan 2014 21:09:27 +0100 [thread overview]
Message-ID: <20140101200927.GA16417@amd.pavel.ucw.cz> (raw)
In-Reply-To: <E7C15C38-8E0E-4D49-9E93-5E3DAF77E252@holtmann.org>
Hi!
> >>> +static struct task_struct *h4p_thread;
> >>
> >> Can’t this be done using a work queue. You are looking at a 3.14
> >> kernel the earliest. We have way better primitives these days.
> >
> > I tried to convert it to work queue, but was not too
> > succesfull. Workqueue is not really good match for what this is trying
> > to do... Nokia code relies on sleeping, than timing those sleeps for
> > signaling. I'm still trying to wrap my head around it.
> >
> > Ok, I guess I could convert it to one big workqueue task, and leave
> > the logic alone. Was that what you wanted?
>
> the Bluetooth subsystem moved away from tasklets and uses workqueues for everything. So this should be just fine for this driver as well. I do not know about what timings are required, but they should only matter during initial device setup. The HCI traffic is actually driven by the Bluetooth core.
>
I actually tried to convert it to workqueue... result is below but I
was not successful.
h4p driver actually has one long-running, mostly sleeping, thread and
communicates with it by sending it wakeups; the thread toggles some
power management options based on activity. (No, I don't like that
design). That is not something that can be easily converted to
workqueue, AFAICT.
I don't think other Bluetooth drivers do anything similar.
Pavel
diff --git a/drivers/bluetooth/hci_h4p.h b/drivers/bluetooth/hci_h4p.h
index a2174ea..5dcbaa1 100644
--- a/drivers/bluetooth/hci_h4p.h
+++ b/drivers/bluetooth/hci_h4p.h
@@ -19,12 +19,13 @@
*
*/
+#ifndef __DRIVERS_BLUETOOTH_HCI_H4P_H
+#define __DRIVERS_BLUETOOTH_HCI_H4P_H
+
#include <net/bluetooth/bluetooth.h>
#include <net/bluetooth/hci_core.h>
#include <net/bluetooth/hci.h>
-
-#ifndef __DRIVERS_BLUETOOTH_HCI_H4P_H
-#define __DRIVERS_BLUETOOTH_HCI_H4P_H
+#include <linux/workqueue.h>
#define FW_NAME_TI1271_PRELE "ti1273_prele.bin"
#define FW_NAME_TI1271_LE "ti1273_le.bin"
@@ -103,6 +104,13 @@ struct hci_h4p_info {
u16 ier;
u16 mdr1;
u16 efr;
+
+#if 1
+ struct work_struct work;
+ struct workqueue_struct work_queue; /* FIXME: init me */
+ unsigned long last_transfer_jiffies;
+ unsigned long transfer_timeout;
+#endif
};
struct hci_h4p_radio_hdr {
diff --git a/drivers/bluetooth/nokia_core.c b/drivers/bluetooth/nokia_core.c
index 07761a3..6e37866 100644
--- a/drivers/bluetooth/nokia_core.c
+++ b/drivers/bluetooth/nokia_core.c
@@ -35,7 +35,6 @@
#include <linux/interrupt.h>
#include <linux/gpio.h>
#include <linux/timer.h>
-#include <linux/kthread.h>
#include <net/bluetooth/bluetooth.h>
#include <net/bluetooth/hci_core.h>
@@ -45,8 +44,6 @@
#include "hci_h4p.h"
-static struct task_struct *h4p_thread;
-
/* This should be used in function that cannot release clocks */
static void hci_h4p_set_clk(struct hci_h4p_info *info, int *clock, int enable)
{
@@ -103,13 +100,11 @@ void hci_h4p_smart_idle(struct hci_h4p_info *info, bool enable)
static inline void h4p_schedule_pm(struct hci_h4p_info *info)
{
- if (unlikely(!h4p_thread))
- return;
-
set_bit(H4P_SCHED_TRANSFER_MODE, &info->pm_flags);
if (unlikely(!test_bit(H4P_TRANSFER_MODE, &info->pm_flags)))
- wake_up_process(h4p_thread);
+ /* FIXME */
+ /* wake_up_process(h4p_thread) */ ;
}
static void hci_h4p_disable_tx(struct hci_h4p_info *info)
@@ -723,18 +718,18 @@ static inline void hci_h4p_set_pm_limits(struct hci_h4p_info *info, bool set)
BT_DBG("pm constraints remains: %s", sset);
}
-static int h4p_run(void *data)
+static int h4p_run(struct work_struct *work)
{
#define TIMEOUT_MIN msecs_to_jiffies(100)
#define TIMEOUT_MAX msecs_to_jiffies(2000)
- struct hci_h4p_info *info = data;
+ struct hci_h4p_info *info = container_of(work, struct hci_h4p_info, work);
unsigned long last_jiffies = jiffies;
unsigned long timeout = TIMEOUT_MIN;
unsigned long elapsed;
BT_DBG("");
set_user_nice(current, -10);
- while (!kthread_should_stop()) {
+ while (1) {
set_current_state(TASK_INTERRUPTIBLE);
if (!test_bit(H4P_SCHED_TRANSFER_MODE, &info->pm_flags)) {
if (timeout != TIMEOUT_MIN) {
@@ -998,7 +993,8 @@ static int hci_h4p_hci_close(struct hci_dev *hdev)
return 0;
/* Wake up h4p_thread which removes pm constraints */
- wake_up_process(h4p_thread);
+ /* FIXME */
+// wake_up_process(h4p_thread);
hci_h4p_hci_flush(hdev);
hci_h4p_set_clk(info, &info->tx_clocks_en, 1);
@@ -1272,12 +1268,11 @@ static int hci_h4p_probe(struct platform_device *pdev)
goto cleanup_irq;
}
- h4p_thread = kthread_run(h4p_run, info, "h4p_pm");
- if (IS_ERR(h4p_thread)) {
- err = PTR_ERR(h4p_thread);
- goto cleanup_irq;
- }
+ INIT_WORK(&info->work, h4p_run);
+// schedule_work(&info->work);
+// info->work_queue = init_work
+ queue_work(info->work_queue, &info->work);
return 0;
cleanup_irq:
@@ -1300,7 +1295,7 @@ static int hci_h4p_remove(struct platform_device *pdev)
info = platform_get_drvdata(pdev);
- kthread_stop(h4p_thread);
+ cancel_work_sync(&info->work);
hci_h4p_sysfs_remove_files(info->dev);
hci_h4p_hci_close(info->hdev);
--
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
next prev parent reply other threads:[~2014-01-01 20:09 UTC|newest]
Thread overview: 53+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-09-20 19:01 [PATCH] Bluetooth: Add hci_h4p driver Pali Rohár
2013-10-17 20:25 ` Pali Rohár
2013-10-17 22:11 ` Marcel Holtmann
[not found] ` <201310180739.47841@pali>
2013-10-18 8:56 ` Marcel Holtmann
2013-10-18 10:30 ` Pali Rohár
2013-10-24 16:41 ` Pali Rohár
2013-10-24 18:41 ` Joe Perches
2013-10-26 19:28 ` Pali Rohár
2013-12-27 11:02 ` [PATCH v2] " Pali Rohár
2013-12-27 11:34 ` Pali Rohár
2013-12-28 1:21 ` Marcel Holtmann
2013-12-30 12:13 ` Pavel Machek
2013-12-30 12:25 ` Pavel Machek
2013-12-30 13:19 ` Sebastian Reichel
2013-12-30 14:04 ` Pali Rohár
2013-12-30 13:54 ` Pali Rohár
2013-12-30 12:23 ` Pavel Machek
2013-12-30 14:31 ` Pali Rohár
2013-12-30 14:52 ` Sebastian Reichel
2013-12-30 23:42 ` Sebastian Reichel
2014-01-08 21:36 ` Pali Rohár
2014-02-13 15:33 ` Pali Rohár
2014-02-14 17:28 ` Sebastian Reichel
2014-02-15 22:30 ` Pavel Machek
2014-02-19 1:12 ` Ben Hutchings
2013-12-30 22:18 ` Pavel Machek
2013-12-30 22:19 ` [PATCH] wilink: mention name of module in help text Pavel Machek
2013-12-30 22:28 ` [PATCH v2] Bluetooth: Add hci_h4p driver Pavel Machek
2013-12-30 22:48 ` Pavel Machek
2013-12-31 22:12 ` Pavel Machek
2013-12-31 23:23 ` Marcel Holtmann
2014-01-01 20:09 ` Pavel Machek [this message]
2014-01-02 16:18 ` [PATCH v3] " Pavel Machek
2014-01-02 16:34 ` Marcel Holtmann
2014-01-03 0:17 ` [PATCH v4] " Pavel Machek
2014-01-03 1:05 ` Sebastian Reichel
2014-01-05 22:32 ` Pavel Machek
2014-01-05 23:01 ` Sebastian Reichel
2014-01-06 0:27 ` Pavel Machek
2014-01-03 1:36 ` Sebastian Reichel
2014-01-09 23:38 ` Pavel Machek
2014-01-10 0:32 ` Sebastian Reichel
2014-01-10 12:18 ` Pavel Machek
2014-01-10 13:44 ` Sebastian Reichel
2014-01-10 14:49 ` Pavel Machek
2014-01-10 14:52 ` [PATCH v5] " Pavel Machek
2014-01-10 17:33 ` Joe Perches
2014-01-11 0:19 ` Pavel Machek
2014-01-11 0:28 ` [PATCH v6] " Pavel Machek
2014-01-16 0:22 ` Pavel Machek
2014-01-16 3:01 ` Marcel Holtmann
2014-01-17 12:14 ` Pavel Machek
2014-01-17 13:29 ` [PATCH v7] staging/bluetooth: " Pavel Machek
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=20140101200927.GA16417@amd.pavel.ucw.cz \
--to=pavel@ucw.cz \
--cc=freemangordon@abv.bg \
--cc=gustavo@padovan.org \
--cc=johan.hedberg@gmail.com \
--cc=linux-bluetooth@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=marcel@holtmann.org \
--cc=pali.rohar@gmail.com \
--cc=sre@ring0.de \
--cc=ville.tervo@nokia.com \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).