Merge branch 'for-upstream' of git://git.kernel.org/pub/scm/linux/kernel/git/bluetoot...
authorDavid S. Miller <davem@davemloft.net>
Mon, 2 Mar 2015 19:47:12 +0000 (14:47 -0500)
committerDavid S. Miller <davem@davemloft.net>
Mon, 2 Mar 2015 19:47:12 +0000 (14:47 -0500)
Johan Hedberg says:

====================
pull request: bluetooth-next 2015-03-02

Here's the first bluetooth-next pull request targeting the 4.1 kernel:

 - ieee802154/6lowpan cleanups
 - SCO routing to host interface support for the btmrvl driver
 - AMP code cleanups
 - Fixes to AMP HCI init sequence
 - Refactoring of the HCI callback mechanism
 - Added shutdown routine for Intel controllers in the btusb driver
 - New config option to enable/disable Bluetooth debugfs information
 - Fix for early data reception on L2CAP fixed channels

Please let me know if there are any issues pulling. Thanks.
====================

Signed-off-by: David S. Miller <davem@davemloft.net>
1  2 
net/bluetooth/hci_core.c
net/bluetooth/hci_event.c
net/bluetooth/hci_sock.c
net/bluetooth/sco.c

diff --combined net/bluetooth/hci_core.c
index 80f40e859d7de80b704039e609c341e6a237cdff,dbd26bcb921062f423d3c1b0624b2aca2ab6d62f..bba4c344c6e06a21004b1c7af9ecefaae612ce39
@@@ -51,7 -51,7 +51,7 @@@ DEFINE_RWLOCK(hci_dev_list_lock)
  
  /* HCI callback list */
  LIST_HEAD(hci_cb_list);
- DEFINE_RWLOCK(hci_cb_list_lock);
+ DEFINE_MUTEX(hci_cb_list_lock);
  
  /* HCI ID Numbering */
  static DEFINE_IDA(hci_index_ida);
@@@ -390,7 -390,7 +390,7 @@@ static void bredr_init(struct hci_reque
        hci_req_add(req, HCI_OP_READ_BD_ADDR, 0, NULL);
  }
  
- static void amp_init(struct hci_request *req)
+ static void amp_init1(struct hci_request *req)
  {
        req->hdev->flow_ctl_mode = HCI_FLOW_CTL_MODE_BLOCK_BASED;
  
        /* Read Local Supported Commands */
        hci_req_add(req, HCI_OP_READ_LOCAL_COMMANDS, 0, NULL);
  
-       /* Read Local Supported Features */
-       hci_req_add(req, HCI_OP_READ_LOCAL_FEATURES, 0, NULL);
        /* Read Local AMP Info */
        hci_req_add(req, HCI_OP_READ_LOCAL_AMP_INFO, 0, NULL);
  
        hci_req_add(req, HCI_OP_READ_LOCATION_DATA, 0, NULL);
  }
  
+ static void amp_init2(struct hci_request *req)
+ {
+       /* Read Local Supported Features. Not all AMP controllers
+        * support this so it's placed conditionally in the second
+        * stage init.
+        */
+       if (req->hdev->commands[14] & 0x20)
+               hci_req_add(req, HCI_OP_READ_LOCAL_FEATURES, 0, NULL);
+ }
  static void hci_init1_req(struct hci_request *req, unsigned long opt)
  {
        struct hci_dev *hdev = req->hdev;
                break;
  
        case HCI_AMP:
-               amp_init(req);
+               amp_init1(req);
                break;
  
        default:
@@@ -578,6 -585,9 +585,9 @@@ static void hci_init2_req(struct hci_re
  {
        struct hci_dev *hdev = req->hdev;
  
+       if (hdev->dev_type == HCI_AMP)
+               return amp_init2(req);
        if (lmp_bredr_capable(hdev))
                bredr_setup(req);
        else
@@@ -896,17 -906,17 +906,17 @@@ static int __hci_init(struct hci_dev *h
                                    &dut_mode_fops);
        }
  
+       err = __hci_req_sync(hdev, hci_init2_req, 0, HCI_INIT_TIMEOUT);
+       if (err < 0)
+               return err;
        /* HCI_BREDR covers both single-mode LE, BR/EDR and dual-mode
         * BR/EDR/LE type controllers. AMP controllers only need the
-        * first stage init.
+        * first two stages of init.
         */
        if (hdev->dev_type != HCI_BREDR)
                return 0;
  
-       err = __hci_req_sync(hdev, hci_init2_req, 0, HCI_INIT_TIMEOUT);
-       if (err < 0)
-               return err;
        err = __hci_req_sync(hdev, hci_init3_req, 0, HCI_INIT_TIMEOUT);
        if (err < 0)
                return err;
@@@ -1591,6 -1601,12 +1601,12 @@@ static int hci_dev_do_close(struct hci_
  {
        BT_DBG("%s %p", hdev->name, hdev);
  
+       if (!test_bit(HCI_UNREGISTER, &hdev->dev_flags)) {
+               /* Execute vendor specific shutdown routine */
+               if (hdev->shutdown)
+                       hdev->shutdown(hdev);
+       }
        cancel_delayed_work(&hdev->power_off);
  
        hci_req_cancel(hdev, ENODEV);
@@@ -3448,9 -3464,9 +3464,9 @@@ int hci_register_cb(struct hci_cb *cb
  {
        BT_DBG("%p name %s", cb, cb->name);
  
-       write_lock(&hci_cb_list_lock);
-       list_add(&cb->list, &hci_cb_list);
-       write_unlock(&hci_cb_list_lock);
+       mutex_lock(&hci_cb_list_lock);
+       list_add_tail(&cb->list, &hci_cb_list);
+       mutex_unlock(&hci_cb_list_lock);
  
        return 0;
  }
@@@ -3460,9 -3476,9 +3476,9 @@@ int hci_unregister_cb(struct hci_cb *cb
  {
        BT_DBG("%p name %s", cb, cb->name);
  
-       write_lock(&hci_cb_list_lock);
+       mutex_lock(&hci_cb_list_lock);
        list_del(&cb->list);
-       write_unlock(&hci_cb_list_lock);
+       mutex_unlock(&hci_cb_list_lock);
  
        return 0;
  }
@@@ -3517,7 -3533,7 +3533,7 @@@ int hci_send_cmd(struct hci_dev *hdev, 
        /* Stand-alone HCI commands must be flagged as
         * single-command requests.
         */
 -      bt_cb(skb)->req.start = true;
 +      bt_cb(skb)->req_start = 1;
  
        skb_queue_tail(&hdev->cmd_q, skb);
        queue_work(hdev->workqueue, &hdev->cmd_work);
@@@ -4195,7 -4211,7 +4211,7 @@@ static bool hci_req_is_complete(struct 
        if (!skb)
                return true;
  
 -      return bt_cb(skb)->req.start;
 +      return bt_cb(skb)->req_start;
  }
  
  static void hci_resend_last(struct hci_dev *hdev)
@@@ -4255,14 -4271,14 +4271,14 @@@ void hci_req_cmd_complete(struct hci_de
         * command queue (hdev->cmd_q).
         */
        if (hdev->sent_cmd) {
 -              req_complete = bt_cb(hdev->sent_cmd)->req.complete;
 +              req_complete = bt_cb(hdev->sent_cmd)->req_complete;
  
                if (req_complete) {
                        /* We must set the complete callback to NULL to
                         * avoid calling the callback more than once if
                         * this function gets called again.
                         */
 -                      bt_cb(hdev->sent_cmd)->req.complete = NULL;
 +                      bt_cb(hdev->sent_cmd)->req_complete = NULL;
  
                        goto call_complete;
                }
        /* Remove all pending commands belonging to this request */
        spin_lock_irqsave(&hdev->cmd_q.lock, flags);
        while ((skb = __skb_dequeue(&hdev->cmd_q))) {
 -              if (bt_cb(skb)->req.start) {
 +              if (bt_cb(skb)->req_start) {
                        __skb_queue_head(&hdev->cmd_q, skb);
                        break;
                }
  
 -              req_complete = bt_cb(skb)->req.complete;
 +              req_complete = bt_cb(skb)->req_complete;
                kfree_skb(skb);
        }
        spin_unlock_irqrestore(&hdev->cmd_q.lock, flags);
index 8e8c4334c379b8e6807575ad5e18c488e5ba4d82,e9b17b585ee8b79dd3dcf03a5b569fd32a29bf25..39653d46932b8298878a01680d3159b3dd70ece6
@@@ -1537,7 -1537,7 +1537,7 @@@ static void hci_cs_create_conn(struct h
                if (conn && conn->state == BT_CONNECT) {
                        if (status != 0x0c || conn->attempt > 2) {
                                conn->state = BT_CLOSED;
-                               hci_proto_connect_cfm(conn, status);
+                               hci_connect_cfm(conn, status);
                                hci_conn_del(conn);
                        } else
                                conn->state = BT_CONNECT2;
@@@ -1581,7 -1581,7 +1581,7 @@@ static void hci_cs_add_sco(struct hci_d
                if (sco) {
                        sco->state = BT_CLOSED;
  
-                       hci_proto_connect_cfm(sco, status);
+                       hci_connect_cfm(sco, status);
                        hci_conn_del(sco);
                }
        }
@@@ -1608,7 -1608,7 +1608,7 @@@ static void hci_cs_auth_requested(struc
        conn = hci_conn_hash_lookup_handle(hdev, __le16_to_cpu(cp->handle));
        if (conn) {
                if (conn->state == BT_CONFIG) {
-                       hci_proto_connect_cfm(conn, status);
+                       hci_connect_cfm(conn, status);
                        hci_conn_drop(conn);
                }
        }
@@@ -1635,7 -1635,7 +1635,7 @@@ static void hci_cs_set_conn_encrypt(str
        conn = hci_conn_hash_lookup_handle(hdev, __le16_to_cpu(cp->handle));
        if (conn) {
                if (conn->state == BT_CONFIG) {
-                       hci_proto_connect_cfm(conn, status);
+                       hci_connect_cfm(conn, status);
                        hci_conn_drop(conn);
                }
        }
@@@ -1811,7 -1811,7 +1811,7 @@@ static void hci_cs_read_remote_features
        conn = hci_conn_hash_lookup_handle(hdev, __le16_to_cpu(cp->handle));
        if (conn) {
                if (conn->state == BT_CONFIG) {
-                       hci_proto_connect_cfm(conn, status);
+                       hci_connect_cfm(conn, status);
                        hci_conn_drop(conn);
                }
        }
@@@ -1838,7 -1838,7 +1838,7 @@@ static void hci_cs_read_remote_ext_feat
        conn = hci_conn_hash_lookup_handle(hdev, __le16_to_cpu(cp->handle));
        if (conn) {
                if (conn->state == BT_CONFIG) {
-                       hci_proto_connect_cfm(conn, status);
+                       hci_connect_cfm(conn, status);
                        hci_conn_drop(conn);
                }
        }
@@@ -1873,7 -1873,7 +1873,7 @@@ static void hci_cs_setup_sync_conn(stru
                if (sco) {
                        sco->state = BT_CLOSED;
  
-                       hci_proto_connect_cfm(sco, status);
+                       hci_connect_cfm(sco, status);
                        hci_conn_del(sco);
                }
        }
@@@ -2255,10 -2255,10 +2255,10 @@@ static void hci_conn_complete_evt(struc
                hci_sco_setup(conn, ev->status);
  
        if (ev->status) {
-               hci_proto_connect_cfm(conn, ev->status);
+               hci_connect_cfm(conn, ev->status);
                hci_conn_del(conn);
        } else if (ev->link_type != ACL_LINK)
-               hci_proto_connect_cfm(conn, ev->status);
+               hci_connect_cfm(conn, ev->status);
  
  unlock:
        hci_dev_unlock(hdev);
@@@ -2366,7 -2366,7 +2366,7 @@@ static void hci_conn_request_evt(struc
                             &cp);
        } else {
                conn->state = BT_CONNECT2;
-               hci_proto_connect_cfm(conn, 0);
+               hci_connect_cfm(conn, 0);
        }
  }
  
@@@ -2444,7 -2444,7 +2444,7 @@@ static void hci_disconn_complete_evt(st
  
        type = conn->type;
  
-       hci_proto_disconn_cfm(conn, ev->reason);
+       hci_disconn_cfm(conn, ev->reason);
        hci_conn_del(conn);
  
        /* Re-enable advertising if necessary, since it might
@@@ -2501,7 -2501,7 +2501,7 @@@ static void hci_auth_complete_evt(struc
                                     &cp);
                } else {
                        conn->state = BT_CONNECTED;
-                       hci_proto_connect_cfm(conn, ev->status);
+                       hci_connect_cfm(conn, ev->status);
                        hci_conn_drop(conn);
                }
        } else {
@@@ -2629,12 -2629,12 +2629,12 @@@ static void hci_encrypt_change_evt(stru
                if (test_bit(HCI_SC_ONLY, &hdev->dev_flags) &&
                    (!test_bit(HCI_CONN_AES_CCM, &conn->flags) ||
                     conn->key_type != HCI_LK_AUTH_COMBINATION_P256)) {
-                       hci_proto_connect_cfm(conn, HCI_ERROR_AUTH_FAILURE);
+                       hci_connect_cfm(conn, HCI_ERROR_AUTH_FAILURE);
                        hci_conn_drop(conn);
                        goto unlock;
                }
  
-               hci_proto_connect_cfm(conn, ev->status);
+               hci_connect_cfm(conn, ev->status);
                hci_conn_drop(conn);
        } else
                hci_encrypt_cfm(conn, ev->status, ev->encrypt);
@@@ -2707,7 -2707,7 +2707,7 @@@ static void hci_remote_features_evt(str
  
        if (!hci_outgoing_auth_needed(hdev, conn)) {
                conn->state = BT_CONNECTED;
-               hci_proto_connect_cfm(conn, ev->status);
+               hci_connect_cfm(conn, ev->status);
                hci_conn_drop(conn);
        }
  
@@@ -3106,7 -3106,7 +3106,7 @@@ static void hci_cmd_status_evt(struct h
                cancel_delayed_work(&hdev->cmd_timer);
  
        if (ev->status ||
 -          (hdev->sent_cmd && !bt_cb(hdev->sent_cmd)->req.event))
 +          (hdev->sent_cmd && !bt_cb(hdev->sent_cmd)->req_event))
                hci_req_cmd_complete(hdev, opcode, ev->status);
  
        if (ev->ncmd && !test_bit(HCI_RESET, &hdev->flags)) {
@@@ -3679,7 -3679,7 +3679,7 @@@ static void hci_remote_ext_features_evt
  
        if (!hci_outgoing_auth_needed(hdev, conn)) {
                conn->state = BT_CONNECTED;
-               hci_proto_connect_cfm(conn, ev->status);
+               hci_connect_cfm(conn, ev->status);
                hci_conn_drop(conn);
        }
  
@@@ -3738,7 -3738,7 +3738,7 @@@ static void hci_sync_conn_complete_evt(
                break;
        }
  
-       hci_proto_connect_cfm(conn, ev->status);
+       hci_connect_cfm(conn, ev->status);
        if (ev->status)
                hci_conn_del(conn);
  
@@@ -3849,7 -3849,7 +3849,7 @@@ static void hci_key_refresh_complete_ev
                if (!ev->status)
                        conn->state = BT_CONNECTED;
  
-               hci_proto_connect_cfm(conn, ev->status);
+               hci_connect_cfm(conn, ev->status);
                hci_conn_drop(conn);
        } else {
                hci_auth_cfm(conn, ev->status);
@@@ -4512,7 -4512,7 +4512,7 @@@ static void hci_le_conn_complete_evt(st
        hci_debugfs_create_conn(conn);
        hci_conn_add_sysfs(conn);
  
-       hci_proto_connect_cfm(conn, ev->status);
+       hci_connect_cfm(conn, ev->status);
  
        params = hci_pend_le_action_lookup(&hdev->pend_le_conns, &conn->dst,
                                           conn->dst_type);
@@@ -5039,7 -5039,7 +5039,7 @@@ void hci_event_packet(struct hci_dev *h
  
        skb_pull(skb, HCI_EVENT_HDR_SIZE);
  
 -      if (hdev->sent_cmd && bt_cb(hdev->sent_cmd)->req.event == event) {
 +      if (hdev->sent_cmd && bt_cb(hdev->sent_cmd)->req_event == event) {
                struct hci_command_hdr *cmd_hdr = (void *) hdev->sent_cmd->data;
                u16 opcode = __le16_to_cpu(cmd_hdr->opcode);
  
diff --combined net/bluetooth/hci_sock.c
index aa8be4cb19a13894b6094fdb425654b8e718efcf,3f8f69239e4116b1f89a247161426c6c3e86485e..cb4bc488335078ce1d4a11f195512f1917554443
@@@ -46,9 -46,9 +46,9 @@@ struct hci_pinfo 
        unsigned short    channel;
  };
  
- static inline int hci_test_bit(int nr, void *addr)
+ static inline int hci_test_bit(int nr, const void *addr)
  {
-       return *((__u32 *) addr + (nr >> 5)) & ((__u32) 1 << (nr & 31));
+       return *((const __u32 *) addr + (nr >> 5)) & ((__u32) 1 << (nr & 31));
  }
  
  /* Security filter */
@@@ -183,12 -183,13 +183,13 @@@ void hci_send_to_sock(struct hci_dev *h
        kfree_skb(skb_copy);
  }
  
- /* Send frame to control socket */
- void hci_send_to_control(struct sk_buff *skb, struct sock *skip_sk)
+ /* Send frame to sockets with specific channel */
+ void hci_send_to_channel(unsigned short channel, struct sk_buff *skb,
+                        struct sock *skip_sk)
  {
        struct sock *sk;
  
-       BT_DBG("len %d", skb->len);
+       BT_DBG("channel %u len %d", channel, skb->len);
  
        read_lock(&hci_sk_list.lock);
  
                if (sk->sk_state != BT_BOUND)
                        continue;
  
-               if (hci_pi(sk)->channel != HCI_CHANNEL_CONTROL)
-                       continue;
-               nskb = skb_clone(skb, GFP_ATOMIC);
-               if (!nskb)
-                       continue;
-               if (sock_queue_rcv_skb(sk, nskb))
-                       kfree_skb(nskb);
-       }
-       read_unlock(&hci_sk_list.lock);
- }
- static void queue_monitor_skb(struct sk_buff *skb)
- {
-       struct sock *sk;
-       BT_DBG("len %d", skb->len);
-       read_lock(&hci_sk_list.lock);
-       sk_for_each(sk, &hci_sk_list.head) {
-               struct sk_buff *nskb;
-               if (sk->sk_state != BT_BOUND)
-                       continue;
-               if (hci_pi(sk)->channel != HCI_CHANNEL_MONITOR)
+               if (hci_pi(sk)->channel != channel)
                        continue;
  
                nskb = skb_clone(skb, GFP_ATOMIC);
@@@ -290,7 -263,7 +263,7 @@@ void hci_send_to_monitor(struct hci_de
        hdr->index = cpu_to_le16(hdev->id);
        hdr->len = cpu_to_le16(skb->len);
  
-       queue_monitor_skb(skb_copy);
+       hci_send_to_channel(HCI_CHANNEL_MONITOR, skb_copy, NULL);
        kfree_skb(skb_copy);
  }
  
@@@ -397,7 -370,7 +370,7 @@@ void hci_sock_dev_event(struct hci_dev 
  
                skb = create_monitor_event(hdev, event);
                if (skb) {
-                       queue_monitor_skb(skb);
+                       hci_send_to_channel(HCI_CHANNEL_MONITOR, skb, NULL);
                        kfree_skb(skb);
                }
        }
@@@ -826,8 -799,8 +799,8 @@@ static void hci_sock_cmsg(struct sock *
        }
  }
  
 -static int hci_sock_recvmsg(struct kiocb *iocb, struct socket *sock,
 -                          struct msghdr *msg, size_t len, int flags)
 +static int hci_sock_recvmsg(struct socket *sock, struct msghdr *msg, size_t len,
 +                          int flags)
  {
        int noblock = flags & MSG_DONTWAIT;
        struct sock *sk = sock->sk;
        return err ? : copied;
  }
  
 -static int hci_sock_sendmsg(struct kiocb *iocb, struct socket *sock,
 -                          struct msghdr *msg, size_t len)
 +static int hci_sock_sendmsg(struct socket *sock, struct msghdr *msg,
 +                          size_t len)
  {
        struct sock *sk = sock->sk;
        struct hci_dev *hdev;
                        /* Stand-alone HCI commands must be flagged as
                         * single-command requests.
                         */
 -                      bt_cb(skb)->req.start = true;
 +                      bt_cb(skb)->req_start = 1;
  
                        skb_queue_tail(&hdev->cmd_q, skb);
                        queue_work(hdev->workqueue, &hdev->cmd_work);
diff --combined net/bluetooth/sco.c
index 2bb7ef46bb9950e3991616dc3158d7b3d1b77f99,b94c3151896ecb2a3b9850848c782498dc6b1cff..54279ac28120c9356731b6fab29db007c6a412f4
@@@ -688,8 -688,8 +688,8 @@@ static int sco_sock_getname(struct sock
        return 0;
  }
  
 -static int sco_sock_sendmsg(struct kiocb *iocb, struct socket *sock,
 -                          struct msghdr *msg, size_t len)
 +static int sco_sock_sendmsg(struct socket *sock, struct msghdr *msg,
 +                          size_t len)
  {
        struct sock *sk = sock->sk;
        int err;
@@@ -758,8 -758,8 +758,8 @@@ static void sco_conn_defer_accept(struc
        }
  }
  
 -static int sco_sock_recvmsg(struct kiocb *iocb, struct socket *sock,
 -                          struct msghdr *msg, size_t len, int flags)
 +static int sco_sock_recvmsg(struct socket *sock, struct msghdr *msg,
 +                          size_t len, int flags)
  {
        struct sock *sk = sock->sk;
        struct sco_pinfo *pi = sco_pi(sk);
  
        release_sock(sk);
  
 -      return bt_sock_recvmsg(iocb, sock, msg, len, flags);
 +      return bt_sock_recvmsg(sock, msg, len, flags);
  }
  
  static int sco_sock_setsockopt(struct socket *sock, int level, int optname, char __user *optval, unsigned int optlen)
@@@ -1083,9 -1083,13 +1083,13 @@@ int sco_connect_ind(struct hci_dev *hde
        return lm;
  }
  
- void sco_connect_cfm(struct hci_conn *hcon, __u8 status)
static void sco_connect_cfm(struct hci_conn *hcon, __u8 status)
  {
+       if (hcon->type != SCO_LINK && hcon->type != ESCO_LINK)
+               return;
        BT_DBG("hcon %p bdaddr %pMR status %d", hcon, &hcon->dst, status);
        if (!status) {
                struct sco_conn *conn;
  
                sco_conn_del(hcon, bt_to_errno(status));
  }
  
- void sco_disconn_cfm(struct hci_conn *hcon, __u8 reason)
static void sco_disconn_cfm(struct hci_conn *hcon, __u8 reason)
  {
+       if (hcon->type != SCO_LINK && hcon->type != ESCO_LINK)
+               return;
        BT_DBG("hcon %p reason %d", hcon, reason);
  
        sco_conn_del(hcon, bt_to_errno(reason));
@@@ -1122,6 -1129,12 +1129,12 @@@ drop
        return 0;
  }
  
+ static struct hci_cb sco_cb = {
+       .name           = "SCO",
+       .connect_cfm    = sco_connect_cfm,
+       .disconn_cfm    = sco_disconn_cfm,
+ };
  static int sco_debugfs_show(struct seq_file *f, void *p)
  {
        struct sock *sk;
@@@ -1203,6 -1216,8 +1216,8 @@@ int __init sco_init(void
  
        BT_INFO("SCO socket layer initialized");
  
+       hci_register_cb(&sco_cb);
        if (IS_ERR_OR_NULL(bt_debugfs))
                return 0;
  
@@@ -1222,6 -1237,8 +1237,8 @@@ void __exit sco_exit(void
  
        debugfs_remove(sco_debugfs);
  
+       hci_unregister_cb(&sco_cb);
        bt_sock_unregister(BTPROTO_SCO);
  
        proto_unregister(&sco_proto);