From patchwork Tue Apr 11 19:21:01 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luiz Augusto von Dentz X-Patchwork-Id: 9676001 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id A482E60231 for ; Tue, 11 Apr 2017 19:21:15 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 949612856C for ; Tue, 11 Apr 2017 19:21:15 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 87620285A1; Tue, 11 Apr 2017 19:21:15 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0DD1B2859E for ; Tue, 11 Apr 2017 19:21:15 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753353AbdDKTVM (ORCPT ); Tue, 11 Apr 2017 15:21:12 -0400 Received: from mail-lf0-f66.google.com ([209.85.215.66]:35924 "EHLO mail-lf0-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753227AbdDKTVL (ORCPT ); Tue, 11 Apr 2017 15:21:11 -0400 Received: by mail-lf0-f66.google.com with SMTP id 75so801055lfs.3; Tue, 11 Apr 2017 12:21:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=x/uo8EFdpf9k0PpB916SthJoB6gXA8XHilRQVQ8tbrU=; b=bsDQYQs+IkjW/5OUU3KL0VSbBDFWS4TvZPSW/ztMJJxZzP78Nemvze0Y7B2IEEwdO5 lifQavyBkyesss9+TQCObgq/qzh5Amv9IJnJB37mmAuycmtmNFEoHHIa/3U3BzBdnLoJ 33dNTKqkCsMpD16GAEWtY3D8spRBMOkwT1mNPLmQunquMMnQkisaAJYc/PisJLxnROgH ikR1iWHeAh8yEYX9kA8oTKvrpNte8Wl8GNSfaRdkGJfwYabkToO1/uAHChutRysJAJzj GrcUcLO1ZPfWwcvlrhPT6z/C8aaf886+j86txX3rsdBNAK504O7fbY0C/9Oe9SEELRvx ljKQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=x/uo8EFdpf9k0PpB916SthJoB6gXA8XHilRQVQ8tbrU=; b=nTBKyoOX+GhkVOYom/XU8RPju0QtTFcyi3gglUoWhqMHx7xf69y5kF/FyvrcdyXfcP pM1mNgIw50oHp7YJ+3YuOfSYj4w7ICwqCaQi29XyexYM+2teqAAaRGLziA0nHSFaHdIy KdvTQU+V2/h6tyg7eAN4MI8RA7r127rF697eMuobQ0nCI3bLrnoMt09lN+y6Uc6JrtCF 0OjC+dRCJldcwO055a8DeOKXXpGhotsfd50glJo5fphgbKnRBzo1aIBEcxksfuQdMNaR eCdUqhHSv07le+80TFMgZwvwAeXSl/Fga9PTgL8GynvsRdikWv2c+YYOPkBfIn88z47D aHRw== X-Gm-Message-State: AN3rC/7bCvbtjol7kiKvvWiuIuV3DKdmUR332VDZbw8L9u7wlaUvrGQcHOxmK+S0whtFaw== X-Received: by 10.25.215.205 with SMTP id q74mr1907139lfi.101.1491938469226; Tue, 11 Apr 2017 12:21:09 -0700 (PDT) Received: from vudentzs-t460s.pp.htv.fi (89-27-7-11.bb.dnainternet.fi. [89.27.7.11]) by smtp.gmail.com with ESMTPSA id c1sm3604962lfc.55.2017.04.11.12.21.08 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 11 Apr 2017 12:21:08 -0700 (PDT) From: Luiz Augusto von Dentz To: linux-bluetooth@vger.kernel.org Cc: patrik.flykt@linux.intel.com, aar@pengutronix.de, jukka.rissanen@linux.intel.com, linux-wpan@vger.kernel.org Subject: [PATCH 4/6] Bluetooth: L2CAP: Add l2cap_le_flowctl_send Date: Tue, 11 Apr 2017 22:21:01 +0300 Message-Id: <20170411192103.3209-4-luiz.dentz@gmail.com> X-Mailer: git-send-email 2.9.3 In-Reply-To: <20170411192103.3209-1-luiz.dentz@gmail.com> References: <20170411192103.3209-1-luiz.dentz@gmail.com> Sender: linux-wpan-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-wpan@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Luiz Augusto von Dentz Consolidate code sending data to LE CoC channels and adds proper accounting of packets sent, the remaining credits and how many packets are queued. Signed-off-by: Luiz Augusto von Dentz Acked-by: Jukka Rissanen --- net/bluetooth/l2cap_core.c | 27 +++++++++++++++++++-------- 1 file changed, 19 insertions(+), 8 deletions(-) diff --git a/net/bluetooth/l2cap_core.c b/net/bluetooth/l2cap_core.c index 3a202b0..f88ac995 100644 --- a/net/bluetooth/l2cap_core.c +++ b/net/bluetooth/l2cap_core.c @@ -2425,6 +2425,22 @@ static int l2cap_segment_le_sdu(struct l2cap_chan *chan, return 0; } +static void l2cap_le_flowctl_send(struct l2cap_chan *chan) +{ + int sent = 0; + + BT_DBG("chan %p", chan); + + while (chan->tx_credits && !skb_queue_empty(&chan->tx_q)) { + l2cap_do_send(chan, skb_dequeue(&chan->tx_q)); + chan->tx_credits--; + sent++; + } + + BT_DBG("Sent %d credits %u queued %u", sent, chan->tx_credits, + skb_queue_len(&chan->tx_q)); +} + int l2cap_chan_send(struct l2cap_chan *chan, struct msghdr *msg, size_t len) { struct sk_buff *skb; @@ -2472,10 +2488,7 @@ int l2cap_chan_send(struct l2cap_chan *chan, struct msghdr *msg, size_t len) skb_queue_splice_tail_init(&seg_queue, &chan->tx_q); - while (chan->tx_credits && !skb_queue_empty(&chan->tx_q)) { - l2cap_do_send(chan, skb_dequeue(&chan->tx_q)); - chan->tx_credits--; - } + l2cap_le_flowctl_send(chan); if (!chan->tx_credits) chan->ops->suspend(chan); @@ -5567,10 +5580,8 @@ static inline int l2cap_le_credits(struct l2cap_conn *conn, chan->tx_credits += credits; - while (chan->tx_credits && !skb_queue_empty(&chan->tx_q)) { - l2cap_do_send(chan, skb_dequeue(&chan->tx_q)); - chan->tx_credits--; - } + /* Resume sending */ + l2cap_le_flowctl_send(chan); if (chan->tx_credits) chan->ops->resume(chan);