From patchwork Tue Jan 11 17:14:17 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?SsOpcsO0bWUgUG91aWxsZXI=?= X-Patchwork-Id: 12710084 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4F464C4332F for ; Tue, 11 Jan 2022 17:16:44 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344338AbiAKRQn (ORCPT ); Tue, 11 Jan 2022 12:16:43 -0500 Received: from mail-co1nam11on2055.outbound.protection.outlook.com ([40.107.220.55]:7776 "EHLO NAM11-CO1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1343994AbiAKRPr (ORCPT ); Tue, 11 Jan 2022 12:15:47 -0500 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=FNS4/qrU7/am/kaOwylLa4Ibm91jH16mFrdXHXNHDt2D30K0yXlI6BaUy4JrotJUm0w1cpalCs3jo7flBM/EgXt7CAOJEljIKSeOCCZtGE587v4DOo11njf7zf78lQzDxho8rynvSYCyBQEuBQkOiBVOqTczCewdcXgIcToZjNrB83mKzuPt1B8iARxsTaeZTyOao31h25DBEMbEJAxN+wRsT1kqs+ITEV5tDbdG69GAtGVHMAeEE/y6jQvt4gr75K5y6QD2s2FLsU85PmtiLDD595P9CVVQqy7NJmuS/B23ZrsSlHM3ffm7ecXAx+/jKQ5kKXLChV+h4OmLeZKy+A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=YFggKABoXG4fFmhLOt6RbZE2kU6NMy/5RXFDbxZ6Ne0=; b=Uv43SAe2D8Qqlg3bqcXhf2jWbQlciUdkCAxYmiw+luuq9BhjZnqFFXEfO0lLMoNgnvzosBPyyq5zRKydQAjKxHtqSAKyzm0fGq1rMQxTs9fq4MXTZt4oY8K2kiwpcGDIhwDVTQiKZAEs2tBqQRADYS0ePFO9xqzXcENeMtILdU8eZ13gc+lfvTX7xIHC5Es4LrUcJtGC5TzI6hiVMdTdhhg9K2JzLJOB3ky7WmasGs+xa2VYIWUUYIcJB99cfjVRpYwtrlh9tw/33Oo+sR4GXfTTVo/vCWR7bEJ0Q+ny71yt6/JKtE8MYKpvvIMdQbivvK1T1FothpMgc9o4RwexUQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=silabs.com; dmarc=pass action=none header.from=silabs.com; dkim=pass header.d=silabs.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=silabs.onmicrosoft.com; s=selector2-silabs-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=YFggKABoXG4fFmhLOt6RbZE2kU6NMy/5RXFDbxZ6Ne0=; b=ilWLkabirAG1l/oHb6EK/3ozjOJ/SQ3og3Xjm1gDXyXJXKhQ2UAyjQfOhcknJhqPgGvS6+rKFOpemd3HgRTShkLVghr0wSLDudCSGaD3D75KzWrHndQQRtyh2596IAIKY4iqlmb5y6ET7SRFF65mwOYoCq8JFrNLikEVu0jfWA0= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=silabs.com; Received: from PH0PR11MB5657.namprd11.prod.outlook.com (2603:10b6:510:ee::19) by PH0PR11MB5657.namprd11.prod.outlook.com (2603:10b6:510:ee::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4867.11; Tue, 11 Jan 2022 17:15:30 +0000 Received: from PH0PR11MB5657.namprd11.prod.outlook.com ([fe80::d031:da9e:71a:73e4]) by PH0PR11MB5657.namprd11.prod.outlook.com ([fe80::d031:da9e:71a:73e4%6]) with mapi id 15.20.4867.012; Tue, 11 Jan 2022 17:15:30 +0000 From: Jerome Pouiller To: linux-wireless@vger.kernel.org, netdev@vger.kernel.org, Kalle Valo Cc: devel@driverdev.osuosl.org, linux-kernel@vger.kernel.org, Greg Kroah-Hartman , "David S . Miller" , devicetree@vger.kernel.org, Rob Herring , linux-mmc@vger.kernel.org, =?utf-8?q?Pali?= =?utf-8?q?_Roh=C3=A1r?= , Ulf Hansson , =?utf-8?b?SsOpcsO0bWUgUG91aWxsZXI=?= Subject: [PATCH v9 17/24] wfx: add queue.c/queue.h Date: Tue, 11 Jan 2022 18:14:17 +0100 Message-Id: <20220111171424.862764-18-Jerome.Pouiller@silabs.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220111171424.862764-1-Jerome.Pouiller@silabs.com> References: <20220111171424.862764-1-Jerome.Pouiller@silabs.com> X-ClientProxiedBy: SN1PR12CA0099.namprd12.prod.outlook.com (2603:10b6:802:21::34) To PH0PR11MB5657.namprd11.prod.outlook.com (2603:10b6:510:ee::19) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 95bfafd5-995d-4eb3-4c06-08d9d525f845 X-MS-TrafficTypeDiagnostic: PH0PR11MB5657:EE_ X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:4714; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: fnQr9yuMGn0jKsFsBAm5kLO+FKs8fdqbgez19u+PUP+XpFfHS5j7HAmJPfrHSS95lk1A9hiLhvq1/7CTvPk6jsIK86KYtJRa59N6QAMDNKyb/MUi/IYfEqYZQsyV3GrK6Zn6TJME6oafRglahirbN4hA/+mjSeBNIBI8DBDFjcHhLxjWWwl1Q3PBbNhK3Miq45WIlZYXYJkNcDjSKxhbqFiXqnLFdNmEY/Edh5X3WlcLc+lyE6dM0W/AY3tzsebv16i7D8aYKq4eiQrpdqHq7f9oQWiTcK1zUr/XsnYi59Bu1Mg1cXM5zQd2gKVK9Jo1m/283fKqPGCMg4Sv5T+krppX1zR6qircghlLv+7aysk+5JO2u4s6AgPlHQNUXEpIKuD9JlYnAfrnmNmppSt+x3auDDKN5o4q9qGaEWGXlEMqMERltZKbMcgC09TQoZ/YQ6Z7xnfLX1g0WbDtWh9o4K43gQBrjxaWIp/9BS8MkEQ+KVWAssBDDVeFQskH0LPjE/8y4GYntp3eoX/tPxizqIEzXnWvKMXkJELudTfAAMQ60tEsnECcPkH2jL84KMT0GmysyW6+q4CzZnsA70YozL5o/k7Hw9odMWkN27P04MmlxZUBJphnNcQDIZu097991MyWsRqkp8NZOH5e5y+k6A== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:PH0PR11MB5657.namprd11.prod.outlook.com;PTR:;CAT:NONE;SFS:(366004)(6506007)(66574015)(86362001)(5660300002)(8936002)(7416002)(6916009)(8676002)(83380400001)(1076003)(6486002)(36756003)(38100700002)(186003)(66946007)(6666004)(2616005)(4326008)(2906002)(316002)(107886003)(66556008)(66476007)(54906003)(6512007)(508600001)(30864003)(52116002);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?q?hQ+E24dsgZavvUGEAY0EgZ0fD9Xt?= =?utf-8?q?nPXv9nISJ09cbvYByvXNeZaNyan58bSo2W5OPM9V5N1mVzEQB6pT5+vlYfH4SUFIF?= =?utf-8?q?3dvHITdf59krmyPrxOh9COwz/vGCBrHXzibVjE+MnB62igCVkQuTHPWqoMIAGauyF?= =?utf-8?q?SR350wGErdams+oCXhPtXo9J6tFRSAjWbt75v1szp0kPI9zMjwPBgtj8tMPJIfPcl?= =?utf-8?q?niLh3xBh+3GFtOfMSqw41TYBbrBSnAaoLhcTvz9xXGIs1Ycfcp5MUQw58RGgxVyu9?= =?utf-8?q?7H6+gc1SAVSaOF2Ip2I2YxpN97Neufuyw5/om0q7ol3BoVk3T5vB9znqVgVLwFwDF?= =?utf-8?q?VIzNBRe5sf0rLNE3ISbDWSTcK8OymXK8KfNEhBkMjMVH3Y7Tkt8vGwIWsESzISPwn?= =?utf-8?q?b1nopVLDZOeqK7knzhVcwl3lbP1mdyoIbd26lRyasyBQFzJgP9RPDegR0aeMYhNFW?= =?utf-8?q?GX9udElyF4RSbOiaWUMIVKF6XyVTOwPwENqGxVYzE0SC9h/Ni+Um6wjQCB9gsTxh0?= =?utf-8?q?pYTJbEQjzrsqqq4eX9MnWRKzDLRd7/RBTv8PNzaDCsWhpbu0kkXkYLEXBR3husgpY?= =?utf-8?q?DvAr1s7SxJdGGDeHEVQCHklYz4fECcIRZ9tZXzRov/EScSxg0EKYJuJ3YRVcM54ps?= =?utf-8?q?62gtNMb/H25yQG4uHFwL9Ck2tEYrdZHv25tDfiX0n+9TA/0O/di4o1hdxD+5QRcSE?= =?utf-8?q?iD4EV8SWnicrR5jD+1xNKJ6zOFX3kMGlhVyL9kGA8X3Y16xod0xYL6EwgrAFiJVII?= =?utf-8?q?mmxD5o06y43jDH9nWntIH6Tp7iB8zOuKXH82HoI62nSd9AyykaCkjFLkcB2ePOGSy?= =?utf-8?q?QdEM4gqMubz02wNWys3MbjrmWGM8UsulDmLagw1SBXwhCesjGwGTM83KeM5Uy9b9E?= =?utf-8?q?1VO5Z7aedSRwSs4hy69aSdWzLbnjKpzbEcWyLYIxARScJ16y38ubLdMbNSMwZBNHq?= =?utf-8?q?GGSwXoWYMXpMpxoc9Y7b/Yw5tzH6R9wiw7zJtoC6zCCDw9EP1StSld//qozz+eme3?= =?utf-8?q?kcwb4SldSnpmJVdAC54b0Ygci1t9+sly4RC4c5GsPYC7rQGfywMTmkmZnnuZkZT1k?= =?utf-8?q?9f4DMi+F7pGOuzSNqp21ootLTFkQJ03yO4LLlYnfowZJyGEC9I4BGC3YLCM4+WzM7?= =?utf-8?q?NWEamz+0WnVuhNyWYVfgI/P4VVk9DPN1FC8TJlsxnxuz2CI+svWxtnd8vNMc0qRNp?= =?utf-8?q?otgBl6l4ALmmUfKXMyVo3cP50ps7KTYdeJ/aAXvAK8DYMI4X++mue636KAGMVTuBu?= =?utf-8?q?Mjd4NeksXKyZl3ast+AkTWKCY8Djvs5PouPTWL2iQSRs3uZygKjtkHasBNTH4N+PD?= =?utf-8?q?+YSoDRjfGn1dtiVWbI0LuUUW84ea0m+u/vRZ/0u4lAQYSY5FGgVJfbGeVTCT/W3az?= =?utf-8?q?/LsJfmL34WCFhvwm2DtAOJlJovtYgFeQEYCcSvL9C7KBy2vJw2Nq5PRhS4PbADLDs?= =?utf-8?q?k60gH9jzwrRvsnfQnnJV8VMlmMPtdWIjR818LcskF1eTEFyFQkOrRYG1kyZ7i2XGQ?= =?utf-8?q?0bLEmxRFH4DJOzAWUlnEGWnbQVpH14X5ylc80985LBIckl1u6wbsqGCqair/QU4Th?= =?utf-8?q?3UH9ryeNkkgqdKZ3/sXch7GGUiS70CfdjcHpkAh4jiEMh+7T3c43CA=3D?= X-OriginatorOrg: silabs.com X-MS-Exchange-CrossTenant-Network-Message-Id: 95bfafd5-995d-4eb3-4c06-08d9d525f845 X-MS-Exchange-CrossTenant-AuthSource: PH0PR11MB5657.namprd11.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 11 Jan 2022 17:15:30.7633 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 54dbd822-5231-4b20-944d-6f4abcd541fb X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: K8YFKi9yeh9/E1rQvgCecUTkjrxjQyQQHEjXuZburcyNtlinP4/PrboqgHt5K8FRabDFdT+o+r/AX/rx5mRpaQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH0PR11MB5657 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org From: Jérôme Pouiller Signed-off-by: Jérôme Pouiller --- drivers/net/wireless/silabs/wfx/queue.c | 298 ++++++++++++++++++++++++ drivers/net/wireless/silabs/wfx/queue.h | 44 ++++ 2 files changed, 342 insertions(+) create mode 100644 drivers/net/wireless/silabs/wfx/queue.c create mode 100644 drivers/net/wireless/silabs/wfx/queue.h diff --git a/drivers/net/wireless/silabs/wfx/queue.c b/drivers/net/wireless/silabs/wfx/queue.c new file mode 100644 index 000000000000..9186726ff07f --- /dev/null +++ b/drivers/net/wireless/silabs/wfx/queue.c @@ -0,0 +1,298 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* + * Queue between the tx operation and the bh workqueue. + * + * Copyright (c) 2017-2020, Silicon Laboratories, Inc. + * Copyright (c) 2010, ST-Ericsson + */ +#include +#include + +#include "queue.h" +#include "wfx.h" +#include "sta.h" +#include "data_tx.h" +#include "traces.h" + +void wfx_tx_lock(struct wfx_dev *wdev) +{ + atomic_inc(&wdev->tx_lock); +} + +void wfx_tx_unlock(struct wfx_dev *wdev) +{ + int tx_lock = atomic_dec_return(&wdev->tx_lock); + + WARN(tx_lock < 0, "inconsistent tx_lock value"); + if (!tx_lock) + wfx_bh_request_tx(wdev); +} + +void wfx_tx_flush(struct wfx_dev *wdev) +{ + int ret; + + /* Do not wait for any reply if chip is frozen */ + if (wdev->chip_frozen) + return; + + wfx_tx_lock(wdev); + mutex_lock(&wdev->hif_cmd.lock); + ret = wait_event_timeout(wdev->hif.tx_buffers_empty, !wdev->hif.tx_buffers_used, + msecs_to_jiffies(3000)); + if (!ret) { + dev_warn(wdev->dev, "cannot flush tx buffers (%d still busy)\n", + wdev->hif.tx_buffers_used); + wfx_pending_dump_old_frames(wdev, 3000); + /* FIXME: drop pending frames here */ + wdev->chip_frozen = true; + } + mutex_unlock(&wdev->hif_cmd.lock); + wfx_tx_unlock(wdev); +} + +void wfx_tx_lock_flush(struct wfx_dev *wdev) +{ + wfx_tx_lock(wdev); + wfx_tx_flush(wdev); +} + +void wfx_tx_queues_init(struct wfx_vif *wvif) +{ + /* The device is in charge to respect the details of the QoS parameters. The driver just + * ensure that it roughtly respect the priorities to avoid any shortage. + */ + const int priorities[IEEE80211_NUM_ACS] = { 1, 2, 64, 128 }; + int i; + + for (i = 0; i < IEEE80211_NUM_ACS; ++i) { + skb_queue_head_init(&wvif->tx_queue[i].normal); + skb_queue_head_init(&wvif->tx_queue[i].cab); + wvif->tx_queue[i].priority = priorities[i]; + } +} + +bool wfx_tx_queue_empty(struct wfx_vif *wvif, struct wfx_queue *queue) +{ + return skb_queue_empty_lockless(&queue->normal) && skb_queue_empty_lockless(&queue->cab); +} + +void wfx_tx_queues_check_empty(struct wfx_vif *wvif) +{ + int i; + + for (i = 0; i < IEEE80211_NUM_ACS; ++i) { + WARN_ON(atomic_read(&wvif->tx_queue[i].pending_frames)); + WARN_ON(!wfx_tx_queue_empty(wvif, &wvif->tx_queue[i])); + } +} + +static void __wfx_tx_queue_drop(struct wfx_vif *wvif, + struct sk_buff_head *skb_queue, struct sk_buff_head *dropped) +{ + struct sk_buff *skb, *tmp; + + spin_lock_bh(&skb_queue->lock); + skb_queue_walk_safe(skb_queue, skb, tmp) { + __skb_unlink(skb, skb_queue); + skb_queue_head(dropped, skb); + } + spin_unlock_bh(&skb_queue->lock); +} + +void wfx_tx_queue_drop(struct wfx_vif *wvif, struct wfx_queue *queue, + struct sk_buff_head *dropped) +{ + __wfx_tx_queue_drop(wvif, &queue->cab, dropped); + __wfx_tx_queue_drop(wvif, &queue->normal, dropped); + wake_up(&wvif->wdev->tx_dequeue); +} + +void wfx_tx_queues_put(struct wfx_vif *wvif, struct sk_buff *skb) +{ + struct wfx_queue *queue = &wvif->tx_queue[skb_get_queue_mapping(skb)]; + struct ieee80211_tx_info *tx_info = IEEE80211_SKB_CB(skb); + + if (tx_info->flags & IEEE80211_TX_CTL_SEND_AFTER_DTIM) + skb_queue_tail(&queue->cab, skb); + else + skb_queue_tail(&queue->normal, skb); +} + +void wfx_pending_drop(struct wfx_dev *wdev, struct sk_buff_head *dropped) +{ + struct wfx_queue *queue; + struct wfx_vif *wvif; + struct wfx_hif_msg *hif; + struct sk_buff *skb; + + WARN(!wdev->chip_frozen, "%s should only be used to recover a frozen device", __func__); + while ((skb = skb_dequeue(&wdev->tx_pending)) != NULL) { + hif = (struct wfx_hif_msg *)skb->data; + wvif = wdev_to_wvif(wdev, hif->interface); + if (wvif) { + queue = &wvif->tx_queue[skb_get_queue_mapping(skb)]; + WARN_ON(skb_get_queue_mapping(skb) > 3); + WARN_ON(!atomic_read(&queue->pending_frames)); + atomic_dec(&queue->pending_frames); + } + skb_queue_head(dropped, skb); + } +} + +struct sk_buff *wfx_pending_get(struct wfx_dev *wdev, u32 packet_id) +{ + struct wfx_queue *queue; + struct wfx_hif_req_tx *req; + struct wfx_vif *wvif; + struct wfx_hif_msg *hif; + struct sk_buff *skb; + + spin_lock_bh(&wdev->tx_pending.lock); + skb_queue_walk(&wdev->tx_pending, skb) { + hif = (struct wfx_hif_msg *)skb->data; + req = (struct wfx_hif_req_tx *)hif->body; + if (req->packet_id != packet_id) + continue; + spin_unlock_bh(&wdev->tx_pending.lock); + wvif = wdev_to_wvif(wdev, hif->interface); + if (wvif) { + queue = &wvif->tx_queue[skb_get_queue_mapping(skb)]; + WARN_ON(skb_get_queue_mapping(skb) > 3); + WARN_ON(!atomic_read(&queue->pending_frames)); + atomic_dec(&queue->pending_frames); + } + skb_unlink(skb, &wdev->tx_pending); + return skb; + } + spin_unlock_bh(&wdev->tx_pending.lock); + WARN(1, "cannot find packet in pending queue"); + return NULL; +} + +void wfx_pending_dump_old_frames(struct wfx_dev *wdev, unsigned int limit_ms) +{ + ktime_t now = ktime_get(); + struct wfx_tx_priv *tx_priv; + struct wfx_hif_req_tx *req; + struct sk_buff *skb; + bool first = true; + + spin_lock_bh(&wdev->tx_pending.lock); + skb_queue_walk(&wdev->tx_pending, skb) { + tx_priv = wfx_skb_tx_priv(skb); + req = wfx_skb_txreq(skb); + if (ktime_after(now, ktime_add_ms(tx_priv->xmit_timestamp, limit_ms))) { + if (first) { + dev_info(wdev->dev, "frames stuck in firmware since %dms or more:\n", + limit_ms); + first = false; + } + dev_info(wdev->dev, " id %08x sent %lldms ago\n", + req->packet_id, ktime_ms_delta(now, tx_priv->xmit_timestamp)); + } + } + spin_unlock_bh(&wdev->tx_pending.lock); +} + +unsigned int wfx_pending_get_pkt_us_delay(struct wfx_dev *wdev, struct sk_buff *skb) +{ + ktime_t now = ktime_get(); + struct wfx_tx_priv *tx_priv = wfx_skb_tx_priv(skb); + + return ktime_us_delta(now, tx_priv->xmit_timestamp); +} + +bool wfx_tx_queues_has_cab(struct wfx_vif *wvif) +{ + int i; + + if (wvif->vif->type != NL80211_IFTYPE_AP) + return false; + for (i = 0; i < IEEE80211_NUM_ACS; ++i) + /* Note: since only AP can have mcast frames in queue and only + * one vif can be AP, all queued frames has same interface id + */ + if (!skb_queue_empty_lockless(&wvif->tx_queue[i].cab)) + return true; + return false; +} + +static int wfx_tx_queue_get_weight(struct wfx_queue *queue) +{ + return atomic_read(&queue->pending_frames) * queue->priority; +} + +static struct sk_buff *wfx_tx_queues_get_skb(struct wfx_dev *wdev) +{ + struct wfx_queue *queues[IEEE80211_NUM_ACS * ARRAY_SIZE(wdev->vif)]; + int i, j, num_queues = 0; + struct wfx_vif *wvif; + struct wfx_hif_msg *hif; + struct sk_buff *skb; + + /* sort the queues */ + wvif = NULL; + while ((wvif = wvif_iterate(wdev, wvif)) != NULL) { + for (i = 0; i < IEEE80211_NUM_ACS; i++) { + WARN_ON(num_queues >= ARRAY_SIZE(queues)); + queues[num_queues] = &wvif->tx_queue[i]; + for (j = num_queues; j > 0; j--) + if (wfx_tx_queue_get_weight(queues[j]) < + wfx_tx_queue_get_weight(queues[j - 1])) + swap(queues[j - 1], queues[j]); + num_queues++; + } + } + + wvif = NULL; + while ((wvif = wvif_iterate(wdev, wvif)) != NULL) { + if (!wvif->after_dtim_tx_allowed) + continue; + for (i = 0; i < num_queues; i++) { + skb = skb_dequeue(&queues[i]->cab); + if (!skb) + continue; + /* Note: since only AP can have mcast frames in queue + * and only one vif can be AP, all queued frames has + * same interface id + */ + hif = (struct wfx_hif_msg *)skb->data; + WARN_ON(hif->interface != wvif->id); + WARN_ON(queues[i] != &wvif->tx_queue[skb_get_queue_mapping(skb)]); + atomic_inc(&queues[i]->pending_frames); + trace_queues_stats(wdev, queues[i]); + return skb; + } + /* No more multicast to sent */ + wvif->after_dtim_tx_allowed = false; + schedule_work(&wvif->update_tim_work); + } + + for (i = 0; i < num_queues; i++) { + skb = skb_dequeue(&queues[i]->normal); + if (skb) { + atomic_inc(&queues[i]->pending_frames); + trace_queues_stats(wdev, queues[i]); + return skb; + } + } + return NULL; +} + +struct wfx_hif_msg *wfx_tx_queues_get(struct wfx_dev *wdev) +{ + struct wfx_tx_priv *tx_priv; + struct sk_buff *skb; + + if (atomic_read(&wdev->tx_lock)) + return NULL; + skb = wfx_tx_queues_get_skb(wdev); + if (!skb) + return NULL; + skb_queue_tail(&wdev->tx_pending, skb); + wake_up(&wdev->tx_dequeue); + tx_priv = wfx_skb_tx_priv(skb); + tx_priv->xmit_timestamp = ktime_get(); + return (struct wfx_hif_msg *)skb->data; +} diff --git a/drivers/net/wireless/silabs/wfx/queue.h b/drivers/net/wireless/silabs/wfx/queue.h new file mode 100644 index 000000000000..4731debca93d --- /dev/null +++ b/drivers/net/wireless/silabs/wfx/queue.h @@ -0,0 +1,44 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +/* + * Queue between the tx operation and the bh workqueue. + * + * Copyright (c) 2017-2020, Silicon Laboratories, Inc. + * Copyright (c) 2010, ST-Ericsson + */ +#ifndef WFX_QUEUE_H +#define WFX_QUEUE_H + +#include +#include + +struct wfx_dev; +struct wfx_vif; + +struct wfx_queue { + struct sk_buff_head normal; + struct sk_buff_head cab; /* Content After (DTIM) Beacon */ + atomic_t pending_frames; + int priority; +}; + +void wfx_tx_lock(struct wfx_dev *wdev); +void wfx_tx_unlock(struct wfx_dev *wdev); +void wfx_tx_flush(struct wfx_dev *wdev); +void wfx_tx_lock_flush(struct wfx_dev *wdev); + +void wfx_tx_queues_init(struct wfx_vif *wvif); +void wfx_tx_queues_check_empty(struct wfx_vif *wvif); +bool wfx_tx_queues_has_cab(struct wfx_vif *wvif); +void wfx_tx_queues_put(struct wfx_vif *wvif, struct sk_buff *skb); +struct wfx_hif_msg *wfx_tx_queues_get(struct wfx_dev *wdev); + +bool wfx_tx_queue_empty(struct wfx_vif *wvif, struct wfx_queue *queue); +void wfx_tx_queue_drop(struct wfx_vif *wvif, struct wfx_queue *queue, + struct sk_buff_head *dropped); + +struct sk_buff *wfx_pending_get(struct wfx_dev *wdev, u32 packet_id); +void wfx_pending_drop(struct wfx_dev *wdev, struct sk_buff_head *dropped); +unsigned int wfx_pending_get_pkt_us_delay(struct wfx_dev *wdev, struct sk_buff *skb); +void wfx_pending_dump_old_frames(struct wfx_dev *wdev, unsigned int limit_ms); + +#endif