]> git.karo-electronics.de Git - karo-tx-linux.git/blobdiff - net/bluetooth/l2cap_core.c
rps: NUMA flow limit allocations
[karo-tx-linux.git] / net / bluetooth / l2cap_core.c
index 8e9e883874ce86b6042cfd063ed077d3ab0aad8c..b6bca64b320d23ba786573598174e7d0a8b73d32 100644 (file)
@@ -498,18 +498,16 @@ void l2cap_chan_set_defaults(struct l2cap_chan *chan)
        set_bit(FLAG_FORCE_ACTIVE, &chan->flags);
 }
 
-void l2cap_le_flowctl_init(struct l2cap_chan *chan)
+static void l2cap_le_flowctl_init(struct l2cap_chan *chan)
 {
-       chan->imtu = L2CAP_DEFAULT_MTU;
-       chan->omtu = L2CAP_LE_MIN_MTU;
-       chan->mode = L2CAP_MODE_LE_FLOWCTL;
+       chan->sdu = NULL;
+       chan->sdu_last_frag = NULL;
+       chan->sdu_len = 0;
        chan->tx_credits = 0;
        chan->rx_credits = le_max_credits;
+       chan->mps = min_t(u16, chan->imtu, L2CAP_LE_DEFAULT_MPS);
 
-       if (chan->imtu < L2CAP_LE_DEFAULT_MPS)
-               chan->mps = chan->imtu;
-       else
-               chan->mps = L2CAP_LE_DEFAULT_MPS;
+       skb_queue_head_init(&chan->tx_q);
 }
 
 void __l2cap_chan_add(struct l2cap_conn *conn, struct l2cap_chan *chan)
@@ -1208,31 +1206,14 @@ static void l2cap_move_done(struct l2cap_chan *chan)
        }
 }
 
-static void l2cap_le_flowctl_start(struct l2cap_chan *chan)
-{
-       chan->sdu = NULL;
-       chan->sdu_last_frag = NULL;
-       chan->sdu_len = 0;
-
-       if (chan->imtu < L2CAP_LE_DEFAULT_MPS)
-               chan->mps = chan->imtu;
-       else
-               chan->mps = le_default_mps;
-
-       skb_queue_head_init(&chan->tx_q);
-
-       if (!chan->tx_credits)
-               chan->ops->suspend(chan);
-}
-
 static void l2cap_chan_ready(struct l2cap_chan *chan)
 {
        /* This clears all conf flags, including CONF_NOT_COMPLETE */
        chan->conf_state = 0;
        __clear_chan_timer(chan);
 
-       if (chan->mode == L2CAP_MODE_LE_FLOWCTL)
-               l2cap_le_flowctl_start(chan);
+       if (chan->mode == L2CAP_MODE_LE_FLOWCTL && !chan->tx_credits)
+               chan->ops->suspend(chan);
 
        chan->state = BT_CONNECTED;
 
@@ -1870,7 +1851,7 @@ static bool is_valid_psm(u16 psm, u8 dst_type)
                return false;
 
        if (bdaddr_type_is_le(dst_type))
-               return (psm < 0x00ff);
+               return (psm <= 0x00ff);
 
        /* PSM must be odd and lsb of upper byte must be 0 */
        return ((psm & 0x0101) == 0x0001);
@@ -1909,7 +1890,9 @@ int l2cap_chan_connect(struct l2cap_chan *chan, __le16 psm, u16 cid,
 
        switch (chan->mode) {
        case L2CAP_MODE_BASIC:
+               break;
        case L2CAP_MODE_LE_FLOWCTL:
+               l2cap_le_flowctl_init(chan);
                break;
        case L2CAP_MODE_ERTM:
        case L2CAP_MODE_STREAMING:
@@ -5663,6 +5646,8 @@ static int l2cap_le_connect_req(struct l2cap_conn *conn,
                goto response_unlock;
        }
 
+       l2cap_le_flowctl_init(chan);
+
        bacpy(&chan->src, &conn->hcon->src);
        bacpy(&chan->dst, &conn->hcon->dst);
        chan->src_type = bdaddr_type(conn->hcon, conn->hcon->src_type);
@@ -5751,6 +5736,31 @@ static inline int l2cap_le_credits(struct l2cap_conn *conn,
        return 0;
 }
 
+static inline int l2cap_le_command_rej(struct l2cap_conn *conn,
+                                      struct l2cap_cmd_hdr *cmd, u16 cmd_len,
+                                      u8 *data)
+{
+       struct l2cap_cmd_rej_unk *rej = (struct l2cap_cmd_rej_unk *) data;
+       struct l2cap_chan *chan;
+
+       if (cmd_len < sizeof(*rej))
+               return -EPROTO;
+
+       mutex_lock(&conn->chan_lock);
+
+       chan = __l2cap_get_chan_by_ident(conn, cmd->ident);
+       if (!chan)
+               goto done;
+
+       l2cap_chan_lock(chan);
+       l2cap_chan_del(chan, ECONNREFUSED);
+       l2cap_chan_unlock(chan);
+
+done:
+       mutex_unlock(&conn->chan_lock);
+       return 0;
+}
+
 static inline int l2cap_le_sig_cmd(struct l2cap_conn *conn,
                                   struct l2cap_cmd_hdr *cmd, u16 cmd_len,
                                   u8 *data)
@@ -5770,6 +5780,7 @@ static inline int l2cap_le_sig_cmd(struct l2cap_conn *conn,
 
        switch (cmd->code) {
        case L2CAP_COMMAND_REJ:
+               l2cap_le_command_rej(conn, cmd, cmd_len, data);
                break;
 
        case L2CAP_CONN_PARAM_UPDATE_REQ: