Bluetooth: Don't disable tasklets to call hdev->notify()
[GitHub/mt8127/android_kernel_alcatel_ttab.git] / net / bluetooth / hci_core.c
index fb3feeb185d7098359bdd71b0156fa8a67d0157f..de923ee600937db9e5938f9f38725b7e57a4fc7f 100644 (file)
 
 #define AUTO_OFF_TIMEOUT 2000
 
+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);
@@ -228,18 +230,6 @@ static void hci_init_req(struct hci_dev *hdev, unsigned long opt)
        /* Read Buffer Size (ACL mtu, max pkt, etc.) */
        hci_send_cmd(hdev, HCI_OP_READ_BUFFER_SIZE, 0, NULL);
 
-#if 0
-       /* Host buffer size */
-       {
-               struct hci_cp_host_buffer_size cp;
-               cp.acl_mtu = cpu_to_le16(HCI_MAX_ACL_SIZE);
-               cp.sco_mtu = HCI_MAX_SCO_SIZE;
-               cp.acl_max_pkt = cpu_to_le16(0xffff);
-               cp.sco_max_pkt = cpu_to_le16(0xffff);
-               hci_send_cmd(hdev, HCI_OP_HOST_BUFFER_SIZE, sizeof(cp), &cp);
-       }
-#endif
-
        /* Read BD Address */
        hci_send_cmd(hdev, HCI_OP_READ_BD_ADDR, 0, NULL);
 
@@ -443,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);
 
@@ -472,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);
 
@@ -521,8 +511,9 @@ int hci_dev_open(__u16 dev)
        if (test_bit(HCI_QUIRK_RAW_DEVICE, &hdev->quirks))
                set_bit(HCI_RAW, &hdev->flags);
 
-       /* Treat all non BR/EDR controllers as raw devices for now */
-       if (hdev->dev_type != HCI_BREDR)
+       /* Treat all non BR/EDR controllers as raw devices if
+          enable_hs is not set */
+       if (hdev->dev_type != HCI_BREDR && !enable_hs)
                set_bit(HCI_RAW, &hdev->flags);
 
        if (hdev->open(hdev)) {
@@ -550,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);
@@ -595,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);
@@ -606,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);
 
@@ -645,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;
@@ -690,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);
@@ -976,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)
@@ -1336,14 +1327,12 @@ int hci_blacklist_del(struct hci_dev *hdev, bdaddr_t *bdaddr)
 {
        struct bdaddr_list *entry;
 
-       if (bacmp(bdaddr, BDADDR_ANY) == 0) {
+       if (bacmp(bdaddr, BDADDR_ANY) == 0)
                return hci_blacklist_clear(hdev);
-       }
 
        entry = hci_blacklist_lookup(hdev, bdaddr);
-       if (!entry) {
+       if (!entry)
                return -ENOENT;
-       }
 
        list_del(&entry->list);
        kfree(entry);
@@ -1351,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);
 
@@ -1451,12 +1441,13 @@ int hci_register_dev(struct hci_dev *hdev)
 
        sprintf(hdev->name, "hci%d", id);
        hdev->id = id;
-       list_add(&hdev->list, head);
+       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;
        hdev->pkt_type  = (HCI_DM1 | HCI_DH1 | HCI_HV1);
        hdev->esco_type = (ESCO_HV1);
        hdev->link_mode = (HCI_LM_ACCEPT);
@@ -1466,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);
@@ -1497,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);
 
@@ -1567,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
@@ -1585,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);
 }
@@ -1633,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;
 }
@@ -1818,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;
 }
@@ -1840,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;
 }
@@ -2060,7 +2050,10 @@ static inline struct hci_conn *hci_low_sent(struct hci_dev *hdev, __u8 type, int
 
        /* We don't have to lock device here. Connections are always
         * added and removed with TX task disabled. */
-       list_for_each_entry(c, &h->list, list) {
+
+       rcu_read_lock();
+
+       list_for_each_entry_rcu(c, &h->list, list) {
                if (c->type != type || skb_queue_empty(&c->data_q))
                        continue;
 
@@ -2078,6 +2071,8 @@ static inline struct hci_conn *hci_low_sent(struct hci_dev *hdev, __u8 type, int
                        break;
        }
 
+       rcu_read_unlock();
+
        if (conn) {
                int cnt, q;
 
@@ -2113,14 +2108,18 @@ static inline void hci_link_tx_to(struct hci_dev *hdev, __u8 type)
 
        BT_ERR("%s link tx timeout", hdev->name);
 
+       rcu_read_lock();
+
        /* Kill stalled connections */
-       list_for_each_entry(c, &h->list, list) {
+       list_for_each_entry_rcu(c, &h->list, list) {
                if (c->type == type && c->sent) {
                        BT_ERR("%s killing stalled connection %s",
                                hdev->name, batostr(&c->dst));
                        hci_acl_disconn(c, 0x13);
                }
        }
+
+       rcu_read_unlock();
 }
 
 static inline struct hci_chan *hci_chan_sent(struct hci_dev *hdev, __u8 type,
@@ -2134,8 +2133,9 @@ 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;
+       rcu_read_lock();
+
+       list_for_each_entry_rcu(conn, &h->list, list) {
                struct hci_chan *tmp;
 
                if (conn->type != type)
@@ -2146,9 +2146,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_rcu(tmp, &conn->chan_list, list) {
                        struct sk_buff *skb;
 
                        if (skb_queue_empty(&tmp->data_q))
@@ -2176,6 +2174,8 @@ static inline struct hci_chan *hci_chan_sent(struct hci_dev *hdev, __u8 type,
                        break;
        }
 
+       rcu_read_unlock();
+
        if (!chan)
                return NULL;
 
@@ -2209,8 +2209,9 @@ 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;
+       rcu_read_lock();
+
+       list_for_each_entry_rcu(conn, &h->list, list) {
                struct hci_chan *chan;
 
                if (conn->type != type)
@@ -2221,8 +2222,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_rcu(chan, &conn->chan_list, list) {
                        struct sk_buff *skb;
 
                        if (chan->sent) {
@@ -2246,6 +2246,9 @@ static void hci_prio_recalculate(struct hci_dev *hdev, __u8 type)
                if (hci_conn_num(hdev, type) == num)
                        break;
        }
+
+       rcu_read_unlock();
+
 }
 
 static inline void hci_sched_acl(struct hci_dev *hdev)
@@ -2401,7 +2404,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);
@@ -2420,7 +2423,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) ----- */
@@ -2501,14 +2504,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)) {
@@ -2534,6 +2537,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;
 
@@ -2553,7 +2557,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)
@@ -2614,3 +2618,6 @@ int hci_cancel_inquiry(struct hci_dev *hdev)
 
        return hci_send_cmd(hdev, HCI_OP_INQUIRY_CANCEL, 0, NULL);
 }
+
+module_param(enable_hs, bool, 0644);
+MODULE_PARM_DESC(enable_hs, "Enable High Speed");