]> Pileus Git - ~andy/linux/blobdiff - net/bluetooth/hci_core.c
Bluetooth: move hci_task_lock to mutex
[~andy/linux] / net / bluetooth / hci_core.c
index ce3727ecc0c40b80d9d7d5681fafbf5efbf3f7ef..36763aa59ea1ff7b73871d802acd4e4bff178f9f 100644 (file)
 
 int enable_hs;
 
+static void hci_rx_work(struct work_struct *work);
 static void hci_cmd_task(unsigned long arg);
-static void hci_rx_task(unsigned long arg);
 static void hci_tx_task(unsigned long arg);
 
-static DEFINE_RWLOCK(hci_task_lock);
+static DEFINE_MUTEX(hci_task_lock);
 
 /* HCI device list */
 LIST_HEAD(hci_dev_list);
@@ -433,14 +433,14 @@ int hci_inquiry(void __user *arg)
        if (!hdev)
                return -ENODEV;
 
-       hci_dev_lock_bh(hdev);
+       hci_dev_lock(hdev);
        if (inquiry_cache_age(hdev) > INQUIRY_CACHE_AGE_MAX ||
                                inquiry_cache_empty(hdev) ||
                                ir.flags & IREQ_CACHE_FLUSH) {
                inquiry_cache_flush(hdev);
                do_inquiry = 1;
        }
-       hci_dev_unlock_bh(hdev);
+       hci_dev_unlock(hdev);
 
        timeo = ir.length * msecs_to_jiffies(2000);
 
@@ -462,9 +462,9 @@ int hci_inquiry(void __user *arg)
                goto done;
        }
 
-       hci_dev_lock_bh(hdev);
+       hci_dev_lock(hdev);
        ir.num_rsp = inquiry_cache_dump(hdev, max_rsp, buf);
-       hci_dev_unlock_bh(hdev);
+       hci_dev_unlock(hdev);
 
        BT_DBG("num_rsp %d", ir.num_rsp);
 
@@ -541,15 +541,15 @@ int hci_dev_open(__u16 dev)
                set_bit(HCI_UP, &hdev->flags);
                hci_notify(hdev, HCI_DEV_UP);
                if (!test_bit(HCI_SETUP, &hdev->flags)) {
-                       hci_dev_lock_bh(hdev);
+                       hci_dev_lock(hdev);
                        mgmt_powered(hdev, 1);
-                       hci_dev_unlock_bh(hdev);
+                       hci_dev_unlock(hdev);
                }
        } else {
                /* Init failed, cleanup */
-               tasklet_kill(&hdev->rx_task);
                tasklet_kill(&hdev->tx_task);
                tasklet_kill(&hdev->cmd_task);
+               flush_work(&hdev->rx_work);
 
                skb_queue_purge(&hdev->cmd_q);
                skb_queue_purge(&hdev->rx_q);
@@ -586,8 +586,8 @@ static int hci_dev_do_close(struct hci_dev *hdev)
        }
 
        /* Kill RX and TX tasks */
-       tasklet_kill(&hdev->rx_task);
        tasklet_kill(&hdev->tx_task);
+       flush_work(&hdev->rx_work);
 
        if (hdev->discov_timeout > 0) {
                cancel_delayed_work(&hdev->discov_off);
@@ -597,10 +597,10 @@ static int hci_dev_do_close(struct hci_dev *hdev)
        if (test_and_clear_bit(HCI_AUTO_OFF, &hdev->flags))
                cancel_delayed_work(&hdev->power_off);
 
-       hci_dev_lock_bh(hdev);
+       hci_dev_lock(hdev);
        inquiry_cache_flush(hdev);
        hci_conn_hash_flush(hdev);
-       hci_dev_unlock_bh(hdev);
+       hci_dev_unlock(hdev);
 
        hci_notify(hdev, HCI_DEV_DOWN);
 
@@ -636,9 +636,9 @@ static int hci_dev_do_close(struct hci_dev *hdev)
         * and no tasks are scheduled. */
        hdev->close(hdev);
 
-       hci_dev_lock_bh(hdev);
+       hci_dev_lock(hdev);
        mgmt_powered(hdev, 0);
-       hci_dev_unlock_bh(hdev);
+       hci_dev_unlock(hdev);
 
        /* Clear flags */
        hdev->flags = 0;
@@ -681,10 +681,10 @@ int hci_dev_reset(__u16 dev)
        skb_queue_purge(&hdev->rx_q);
        skb_queue_purge(&hdev->cmd_q);
 
-       hci_dev_lock_bh(hdev);
+       hci_dev_lock(hdev);
        inquiry_cache_flush(hdev);
        hci_conn_hash_flush(hdev);
-       hci_dev_unlock_bh(hdev);
+       hci_dev_unlock(hdev);
 
        if (hdev->flush)
                hdev->flush(hdev);
@@ -967,13 +967,13 @@ static void hci_discov_off(struct work_struct *work)
 
        BT_DBG("%s", hdev->name);
 
-       hci_dev_lock_bh(hdev);
+       hci_dev_lock(hdev);
 
        hci_send_cmd(hdev, HCI_OP_WRITE_SCAN_ENABLE, sizeof(scan), &scan);
 
        hdev->discov_timeout = 0;
 
-       hci_dev_unlock_bh(hdev);
+       hci_dev_unlock(hdev);
 }
 
 int hci_uuids_clear(struct hci_dev *hdev)
@@ -1340,9 +1340,10 @@ int hci_blacklist_del(struct hci_dev *hdev, bdaddr_t *bdaddr)
        return mgmt_device_unblocked(hdev, bdaddr);
 }
 
-static void hci_clear_adv_cache(unsigned long arg)
+static void hci_clear_adv_cache(struct work_struct *work)
 {
-       struct hci_dev *hdev = (void *) arg;
+       struct hci_dev *hdev = container_of(work, struct hci_dev,
+                                                       adv_work.work);
 
        hci_dev_lock(hdev);
 
@@ -1443,7 +1444,7 @@ int hci_register_dev(struct hci_dev *hdev)
        list_add_tail(&hdev->list, head);
 
        atomic_set(&hdev->refcnt, 1);
-       spin_lock_init(&hdev->lock);
+       mutex_init(&hdev->lock);
 
        hdev->flags = 0;
        hdev->dev_flags = 0;
@@ -1456,8 +1457,9 @@ int hci_register_dev(struct hci_dev *hdev)
        hdev->sniff_max_interval = 800;
        hdev->sniff_min_interval = 80;
 
-       tasklet_init(&hdev->cmd_task, hci_cmd_task, (unsigned long) hdev);
-       tasklet_init(&hdev->rx_task, hci_rx_task, (unsigned long) hdev);
+       INIT_WORK(&hdev->rx_work, hci_rx_work);
+
+       tasklet_init(&hdev->cmd_task, hci_cmd_task,(unsigned long) hdev);
        tasklet_init(&hdev->tx_task, hci_tx_task, (unsigned long) hdev);
 
        skb_queue_head_init(&hdev->rx_q);
@@ -1487,9 +1489,8 @@ int hci_register_dev(struct hci_dev *hdev)
        INIT_LIST_HEAD(&hdev->remote_oob_data);
 
        INIT_LIST_HEAD(&hdev->adv_entries);
-       setup_timer(&hdev->adv_timer, hci_clear_adv_cache,
-                                               (unsigned long) hdev);
 
+       INIT_DELAYED_WORK(&hdev->adv_work, hci_clear_adv_cache);
        INIT_WORK(&hdev->power_on, hci_power_on);
        INIT_DELAYED_WORK(&hdev->power_off, hci_power_off);
 
@@ -1557,9 +1558,9 @@ void hci_unregister_dev(struct hci_dev *hdev)
 
        if (!test_bit(HCI_INIT, &hdev->flags) &&
                                        !test_bit(HCI_SETUP, &hdev->flags)) {
-               hci_dev_lock_bh(hdev);
+               hci_dev_lock(hdev);
                mgmt_index_removed(hdev);
-               hci_dev_unlock_bh(hdev);
+               hci_dev_unlock(hdev);
        }
 
        /* mgmt_index_removed should take care of emptying the
@@ -1575,17 +1576,17 @@ void hci_unregister_dev(struct hci_dev *hdev)
 
        hci_del_sysfs(hdev);
 
-       del_timer(&hdev->adv_timer);
+       cancel_delayed_work_sync(&hdev->adv_work);
 
        destroy_workqueue(hdev->workqueue);
 
-       hci_dev_lock_bh(hdev);
+       hci_dev_lock(hdev);
        hci_blacklist_clear(hdev);
        hci_uuids_clear(hdev);
        hci_link_keys_clear(hdev);
        hci_remote_oob_data_clear(hdev);
        hci_adv_entries_clear(hdev);
-       hci_dev_unlock_bh(hdev);
+       hci_dev_unlock(hdev);
 
        __hci_dev_put(hdev);
 }
@@ -1623,9 +1624,8 @@ int hci_recv_frame(struct sk_buff *skb)
        /* Time stamp */
        __net_timestamp(skb);
 
-       /* Queue frame for rx task */
        skb_queue_tail(&hdev->rx_q, skb);
-       tasklet_schedule(&hdev->rx_task);
+       queue_work(hdev->workqueue, &hdev->rx_work);
 
        return 0;
 }
@@ -1808,14 +1808,14 @@ int hci_register_proto(struct hci_proto *hp)
        if (hp->id >= HCI_MAX_PROTO)
                return -EINVAL;
 
-       write_lock_bh(&hci_task_lock);
+       mutex_lock(&hci_task_lock);
 
        if (!hci_proto[hp->id])
                hci_proto[hp->id] = hp;
        else
                err = -EEXIST;
 
-       write_unlock_bh(&hci_task_lock);
+       mutex_unlock(&hci_task_lock);
 
        return err;
 }
@@ -1830,14 +1830,14 @@ int hci_unregister_proto(struct hci_proto *hp)
        if (hp->id >= HCI_MAX_PROTO)
                return -EINVAL;
 
-       write_lock_bh(&hci_task_lock);
+       mutex_lock(&hci_task_lock);
 
        if (hci_proto[hp->id])
                hci_proto[hp->id] = NULL;
        else
                err = -ENOENT;
 
-       write_unlock_bh(&hci_task_lock);
+       mutex_unlock(&hci_task_lock);
 
        return err;
 }
@@ -2125,7 +2125,6 @@ static inline struct hci_chan *hci_chan_sent(struct hci_dev *hdev, __u8 type,
        BT_DBG("%s", hdev->name);
 
        list_for_each_entry(conn, &h->list, list) {
-               struct hci_chan_hash *ch;
                struct hci_chan *tmp;
 
                if (conn->type != type)
@@ -2136,9 +2135,7 @@ static inline struct hci_chan *hci_chan_sent(struct hci_dev *hdev, __u8 type,
 
                conn_num++;
 
-               ch = &conn->chan_hash;
-
-               list_for_each_entry(tmp, &ch->list, list) {
+               list_for_each_entry(tmp, &conn->chan_list, list) {
                        struct sk_buff *skb;
 
                        if (skb_queue_empty(&tmp->data_q))
@@ -2200,7 +2197,6 @@ static void hci_prio_recalculate(struct hci_dev *hdev, __u8 type)
        BT_DBG("%s", hdev->name);
 
        list_for_each_entry(conn, &h->list, list) {
-               struct hci_chan_hash *ch;
                struct hci_chan *chan;
 
                if (conn->type != type)
@@ -2211,8 +2207,7 @@ static void hci_prio_recalculate(struct hci_dev *hdev, __u8 type)
 
                num++;
 
-               ch = &conn->chan_hash;
-               list_for_each_entry(chan, &ch->list, list) {
+               list_for_each_entry(chan, &conn->chan_list, list) {
                        struct sk_buff *skb;
 
                        if (chan->sent) {
@@ -2391,7 +2386,7 @@ static void hci_tx_task(unsigned long arg)
        struct hci_dev *hdev = (struct hci_dev *) arg;
        struct sk_buff *skb;
 
-       read_lock(&hci_task_lock);
+       mutex_lock(&hci_task_lock);
 
        BT_DBG("%s acl %d sco %d le %d", hdev->name, hdev->acl_cnt,
                hdev->sco_cnt, hdev->le_cnt);
@@ -2410,7 +2405,7 @@ static void hci_tx_task(unsigned long arg)
        while ((skb = skb_dequeue(&hdev->raw_q)))
                hci_send_frame(skb);
 
-       read_unlock(&hci_task_lock);
+       mutex_unlock(&hci_task_lock);
 }
 
 /* ----- HCI RX task (incoming data processing) ----- */
@@ -2491,14 +2486,14 @@ static inline void hci_scodata_packet(struct hci_dev *hdev, struct sk_buff *skb)
        kfree_skb(skb);
 }
 
-static void hci_rx_task(unsigned long arg)
+static void hci_rx_work(struct work_struct *work)
 {
-       struct hci_dev *hdev = (struct hci_dev *) arg;
+       struct hci_dev *hdev = container_of(work, struct hci_dev, rx_work);
        struct sk_buff *skb;
 
        BT_DBG("%s", hdev->name);
 
-       read_lock(&hci_task_lock);
+       mutex_lock(&hci_task_lock);
 
        while ((skb = skb_dequeue(&hdev->rx_q))) {
                if (atomic_read(&hdev->promisc)) {
@@ -2524,6 +2519,7 @@ static void hci_rx_task(unsigned long arg)
                /* Process frame */
                switch (bt_cb(skb)->pkt_type) {
                case HCI_EVENT_PKT:
+                       BT_DBG("%s Event packet", hdev->name);
                        hci_event_packet(hdev, skb);
                        break;
 
@@ -2543,7 +2539,7 @@ static void hci_rx_task(unsigned long arg)
                }
        }
 
-       read_unlock(&hci_task_lock);
+       mutex_unlock(&hci_task_lock);
 }
 
 static void hci_cmd_task(unsigned long arg)