From patchwork Tue Nov 27 22:21:08 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lorenzo Bianconi X-Patchwork-Id: 10701543 X-Patchwork-Delegate: johannes@sipsolutions.net Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id C616113AD for ; Tue, 27 Nov 2018 22:21:29 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B555F2C637 for ; Tue, 27 Nov 2018 22:21:29 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id A91812CA87; Tue, 27 Nov 2018 22:21:29 +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=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI 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 3D4982C637 for ; Tue, 27 Nov 2018 22:21:29 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726830AbeK1JUt (ORCPT ); Wed, 28 Nov 2018 04:20:49 -0500 Received: from mail-wm1-f68.google.com ([209.85.128.68]:39970 "EHLO mail-wm1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726277AbeK1JUt (ORCPT ); Wed, 28 Nov 2018 04:20:49 -0500 Received: by mail-wm1-f68.google.com with SMTP id q26so579889wmf.5 for ; Tue, 27 Nov 2018 14:21:27 -0800 (PST) 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:mime-version:content-transfer-encoding; bh=3KVk3rBJcueAUCmvfsxxWAFckXyALr6UVsUu1XYDUXM=; b=SF2a9pOXuzEl9d5v5A5Ba5rmZMEC8pghpIk26ikSehtnqDyERh07qBx36qAaoU9c5o eA5a/eCJnuqa7HCjju8d+DZbfJAnYHOFoWgyptf2wngyBTVTH35BFo/H5oHccimyX9qn 3hIZ/t2V1HYDPAFlmEnrqDNPY9CDBfW9LStEFYHUDMXR/E5Of7DoAEnsR2AOK/bXOcbR lXWRbc4NiDm1jjeQEKQoi9oZzdjfQAytxCp8xzLa4MjtKkjXKMAUn6IKz9Jx8y3eGrMd nT9b9lAksF/UMAEWcqqutw0cgexrxD411XJI711gnIGWwtFrsEIQSB8xklIFAGlAKb0W pBSg== X-Gm-Message-State: AA+aEWZo6yjkg23mrS0kXU85ncXIp67/q+xA1RZq99XzbkXuGuUetS7w 2TtmQdPuT1K0We51K+NW3bTy25ySda0= X-Google-Smtp-Source: AFSGD/VnAI5qxXwELf5YfDKwMToFCr0731np4VKTlqLS+UfLw/fkFtVUBVDgTUSS2crQp3L2/Tfzkw== X-Received: by 2002:a1c:ddc3:: with SMTP id u186mr543649wmg.110.1543357286295; Tue, 27 Nov 2018 14:21:26 -0800 (PST) Received: from localhost.lan ([151.21.135.68]) by smtp.gmail.com with ESMTPSA id 142sm866245wmw.27.2018.11.27.14.21.25 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 27 Nov 2018 14:21:25 -0800 (PST) From: Lorenzo Bianconi To: linux-wireless@vger.kernel.org Cc: nbd@nbd.name Subject: [RFC 1/5] mac80211: introduce ieee80211_xdp handler Date: Tue, 27 Nov 2018 23:21:08 +0100 Message-Id: <35462be4a802b03c82d0312726e8421dadfa22a1.1543343124.git.lorenzo.bianconi@redhat.com> X-Mailer: git-send-email 2.19.1 In-Reply-To: References: MIME-Version: 1.0 Sender: linux-wireless-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-wireless@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Initialize net_device_ops ndo_bpf callback with ieee80211_xdp routine in order to load a bpf program into low level driver XDP rx hook Signed-off-by: Lorenzo Bianconi --- include/net/mac80211.h | 2 ++ net/mac80211/driver-ops.h | 11 +++++++++++ net/mac80211/iface.c | 14 ++++++++++++++ 3 files changed, 27 insertions(+) diff --git a/include/net/mac80211.h b/include/net/mac80211.h index 71985e95d2d9..a91f1733ce43 100644 --- a/include/net/mac80211.h +++ b/include/net/mac80211.h @@ -3623,6 +3623,7 @@ enum ieee80211_reconfig_type { * skb is always a real frame, head may or may not be an A-MSDU. * @get_ftm_responder_stats: Retrieve FTM responder statistics, if available. * Statistics should be cumulative, currently no way to reset is provided. + * @xdp: main XDP handler */ struct ieee80211_ops { void (*tx)(struct ieee80211_hw *hw, @@ -3911,6 +3912,7 @@ struct ieee80211_ops { int (*get_ftm_responder_stats)(struct ieee80211_hw *hw, struct ieee80211_vif *vif, struct cfg80211_ftm_responder_stats *ftm_stats); + int (*xdp)(struct ieee80211_hw *hw, struct netdev_bpf *xdp); }; /** diff --git a/net/mac80211/driver-ops.h b/net/mac80211/driver-ops.h index 0b1747a2313d..48cad0ae0593 100644 --- a/net/mac80211/driver-ops.h +++ b/net/mac80211/driver-ops.h @@ -1278,4 +1278,15 @@ static inline void drv_del_nan_func(struct ieee80211_local *local, trace_drv_return_void(local); } +static inline int drv_xdp(struct ieee80211_local *local, + struct netdev_bpf *xdp) +{ + might_sleep(); + + if (!local->ops->xdp) + return -EOPNOTSUPP; + + return local->ops->xdp(&local->hw, xdp); +} + #endif /* __MAC80211_DRIVER_OPS */ diff --git a/net/mac80211/iface.c b/net/mac80211/iface.c index 5836ddeac9e3..e21971f7c652 100644 --- a/net/mac80211/iface.c +++ b/net/mac80211/iface.c @@ -1163,6 +1163,19 @@ ieee80211_get_stats64(struct net_device *dev, struct rtnl_link_stats64 *stats) } } +static int ieee80211_xdp(struct net_device *dev, struct netdev_bpf *xdp) +{ + struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); + + switch (xdp->command) { + case XDP_QUERY_PROG: + case XDP_SETUP_PROG: + return drv_xdp(sdata->local, xdp); + default: + return -EINVAL; + } +} + static const struct net_device_ops ieee80211_dataif_ops = { .ndo_open = ieee80211_open, .ndo_stop = ieee80211_stop, @@ -1172,6 +1185,7 @@ static const struct net_device_ops ieee80211_dataif_ops = { .ndo_set_mac_address = ieee80211_change_mac, .ndo_select_queue = ieee80211_netdev_select_queue, .ndo_get_stats64 = ieee80211_get_stats64, + .ndo_bpf = ieee80211_xdp, }; static u16 ieee80211_monitor_select_queue(struct net_device *dev, From patchwork Tue Nov 27 22:21:09 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lorenzo Bianconi X-Patchwork-Id: 10701545 X-Patchwork-Delegate: johannes@sipsolutions.net Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 7AAD013AD for ; Tue, 27 Nov 2018 22:21:31 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6AE3C2C637 for ; Tue, 27 Nov 2018 22:21:31 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 5C28C2CA87; Tue, 27 Nov 2018 22:21:31 +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=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI 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 0D1C52C637 for ; Tue, 27 Nov 2018 22:21:31 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726952AbeK1JUv (ORCPT ); Wed, 28 Nov 2018 04:20:51 -0500 Received: from mail-wm1-f66.google.com ([209.85.128.66]:52378 "EHLO mail-wm1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726277AbeK1JUu (ORCPT ); Wed, 28 Nov 2018 04:20:50 -0500 Received: by mail-wm1-f66.google.com with SMTP id r11-v6so595374wmb.2 for ; Tue, 27 Nov 2018 14:21:29 -0800 (PST) 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:mime-version:content-transfer-encoding; bh=5CUm4jo49q+OhNI4lrqwZgcdY8NIHMuZwO/W934glvY=; b=QDpRRuvfidfDKuUSitns4m+x143QWiuBguEW53XCu214Mi3KFdbd3vxb+OKDcU2gb8 kJac78rR1QV8UOpIdUerQTeWL+9XBMN9BBGuwiSkmLdrSeClvk9TVKVNE3CG8WGXsgmt L10qGoTngYQhW2NzEL99jubW7a6pUX4PEPheEfB2gquoGwWewvXXOX/E/BYoqGUnGCve 4oYcC4LadxqttzedRk+Za20LhhtvgKRov4QrAgEEQ6h9OKv0yZW61xoN6+PA8A31IdGl VmhbDmal/Q9ZuIrGcUrPQvUGGZNjtlwG9xS7HReH4snGHJNPt95CFPsZtE3z9lsyLVjm 5s8g== X-Gm-Message-State: AA+aEWaa4J3A1W2yZtHngsa0pRy0+bMsfn0CbF84/vp0ddsmPsTJ2st8 hx25sFNwBuiBP1ds7K9KFiL6uaETH58= X-Google-Smtp-Source: AFSGD/WG2YD08cWZFjxrSJFhaOrHRWLPpdcqw92ui2ErMauWHiFWD3zGY0syaQEm4FUk+MZF1FP4XQ== X-Received: by 2002:a1c:414:: with SMTP id 20mr544585wme.67.1543357288096; Tue, 27 Nov 2018 14:21:28 -0800 (PST) Received: from localhost.lan ([151.21.135.68]) by smtp.gmail.com with ESMTPSA id 142sm866245wmw.27.2018.11.27.14.21.27 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 27 Nov 2018 14:21:27 -0800 (PST) From: Lorenzo Bianconi To: linux-wireless@vger.kernel.org Cc: nbd@nbd.name Subject: [RFC 2/5] mac80211: introduce ieee80211_vif_to_netdev routine Date: Tue, 27 Nov 2018 23:21:09 +0100 Message-Id: <0db1977129e87685d66b2e9d6ddd821fe8d9fcf7.1543343124.git.lorenzo.bianconi@redhat.com> X-Mailer: git-send-email 2.19.1 In-Reply-To: References: MIME-Version: 1.0 Sender: linux-wireless-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-wireless@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Add ieee80211_vif_to_netdev utility routine to get the netdevice pointer related to ieee80211_vif one even if the sdata has not been inserted in the driver or running yet. ieee80211_vif_to_netdev will be used by mt76 to properly configure xdp_rxq_info data structure adding vif to the driver Signed-off-by: Lorenzo Bianconi --- include/net/mac80211.h | 2 ++ net/mac80211/util.c | 12 ++++++++++++ 2 files changed, 14 insertions(+) diff --git a/include/net/mac80211.h b/include/net/mac80211.h index a91f1733ce43..f2784b36f2e2 100644 --- a/include/net/mac80211.h +++ b/include/net/mac80211.h @@ -1603,6 +1603,8 @@ struct ieee80211_vif *wdev_to_ieee80211_vif(struct wireless_dev *wdev); */ struct wireless_dev *ieee80211_vif_to_wdev(struct ieee80211_vif *vif); +struct net_device *ieee80211_vif_to_netdev(struct ieee80211_vif *vif); + /** * enum ieee80211_key_flags - key flags * diff --git a/net/mac80211/util.c b/net/mac80211/util.c index bec424316ea4..a98293d71818 100644 --- a/net/mac80211/util.c +++ b/net/mac80211/util.c @@ -827,6 +827,18 @@ struct wireless_dev *ieee80211_vif_to_wdev(struct ieee80211_vif *vif) } EXPORT_SYMBOL_GPL(ieee80211_vif_to_wdev); +struct net_device *ieee80211_vif_to_netdev(struct ieee80211_vif *vif) +{ + struct ieee80211_sub_if_data *sdata; + + if (!vif) + return NULL; + + sdata = vif_to_sdata(vif); + return sdata->dev; +} +EXPORT_SYMBOL_GPL(ieee80211_vif_to_netdev); + /* * Nothing should have been stuffed into the workqueue during * the suspend->resume cycle. Since we can't check each caller From patchwork Tue Nov 27 22:21:10 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lorenzo Bianconi X-Patchwork-Id: 10701547 X-Patchwork-Delegate: johannes@sipsolutions.net Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 5D9A514BD for ; Tue, 27 Nov 2018 22:21:33 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4F6442C637 for ; Tue, 27 Nov 2018 22:21:33 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 4394E2CA81; Tue, 27 Nov 2018 22:21:33 +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=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI 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 D19992C637 for ; Tue, 27 Nov 2018 22:21:32 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726994AbeK1JUw (ORCPT ); Wed, 28 Nov 2018 04:20:52 -0500 Received: from mail-wm1-f66.google.com ([209.85.128.66]:36464 "EHLO mail-wm1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726843AbeK1JUw (ORCPT ); Wed, 28 Nov 2018 04:20:52 -0500 Received: by mail-wm1-f66.google.com with SMTP id s11so608075wmh.1 for ; Tue, 27 Nov 2018 14:21:30 -0800 (PST) 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:mime-version:content-transfer-encoding; bh=X6w3SuAxSKkd36jG9DGNNXl3ocLr1IIniQlgkOxd9IE=; b=KYwsGf3MXNpKxL77xNpcSAnJrtiM6/QHOfs2Hmn/tmQTwqYWCKo6O3eNRfad1vVZT0 Ktd8Jj8hAxGw00IWWFw5FnyTcZ2RQ67QTuDlEV3+DI9UZhV0dzVVxqORL7igxCG9gbh+ h8Ov+gzeReGlHQvvRz42QMxA+EffI43iKzAsCcXJgL08v5Dt764VYqKyvfARXmXKKKHr u/CnYvHs6J55uTwyQHpJYoKB4NRdgNyDpB3o1LGKSAEagZZQkk75XwfYioY7lC6+jaAy KzoHuyIKojfpqpmh37yshK5M7iD8gN03Z2OUuFH8zpLUo2Fp2T/RAMSL1Rm4/nTulgy5 Wh1Q== X-Gm-Message-State: AA+aEWbOw9/yEGyADw3rXM0A2KA4kFyY46kiRvqPVAqqO6PJ6XYXBOpc AH9RimTytMbeo1gSIaPSsp/irvZm64w= X-Google-Smtp-Source: AFSGD/VTyhZqyEpwybprNH1zzBXjB0LK03ztayN66dSy5GqTvJAto+l2tvEUhKLk4Qk9Zai1mBMPLg== X-Received: by 2002:a1c:1286:: with SMTP id 128mr601850wms.70.1543357289658; Tue, 27 Nov 2018 14:21:29 -0800 (PST) Received: from localhost.lan ([151.21.135.68]) by smtp.gmail.com with ESMTPSA id 142sm866245wmw.27.2018.11.27.14.21.28 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 27 Nov 2018 14:21:29 -0800 (PST) From: Lorenzo Bianconi To: linux-wireless@vger.kernel.org Cc: nbd@nbd.name Subject: [RFC 3/5] mt76: split mt76_dma_rx_reset in init_rx_reset and complete_rx_reset Date: Tue, 27 Nov 2018 23:21:10 +0100 Message-Id: <095486ed9b97ef4a81758859dbeb2c95856dfa30.1543343124.git.lorenzo.bianconi@redhat.com> X-Mailer: git-send-email 2.19.1 In-Reply-To: References: MIME-Version: 1.0 Sender: linux-wireless-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-wireless@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP This is a preliminary patch to add XDP support to mt76 driver. In order to reset the rx dma buffers with a proper buffer_size (XDP does not support fragmented frames and requires one packet per memory page) split mt76_dma_rx_reset routine in mt76_dma_init_rx_reset where we free allocated memory and mt76_dma_complete_rx_reset used to allocate dma memory with a proper size according to the working mode (standard or xdp) Signed-off-by: Lorenzo Bianconi --- drivers/net/wireless/mediatek/mt76/dma.c | 12 ++++++++++-- drivers/net/wireless/mediatek/mt76/mt76.h | 6 ++++-- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/drivers/net/wireless/mediatek/mt76/dma.c b/drivers/net/wireless/mediatek/mt76/dma.c index e2ba26378575..efa0eab7cf01 100644 --- a/drivers/net/wireless/mediatek/mt76/dma.c +++ b/drivers/net/wireless/mediatek/mt76/dma.c @@ -382,7 +382,7 @@ mt76_dma_rx_cleanup(struct mt76_dev *dev, struct mt76_queue *q) } static void -mt76_dma_rx_reset(struct mt76_dev *dev, enum mt76_rxq_id qid) +mt76_dma_init_rx_reset(struct mt76_dev *dev, enum mt76_rxq_id qid) { struct mt76_queue *q = &dev->q_rx[qid]; int i; @@ -392,6 +392,13 @@ mt76_dma_rx_reset(struct mt76_dev *dev, enum mt76_rxq_id qid) mt76_dma_rx_cleanup(dev, q); mt76_dma_sync_idx(dev, q); +} + +static void +mt76_dma_complete_rx_reset(struct mt76_dev *dev, enum mt76_rxq_id qid) +{ + struct mt76_queue *q = &dev->q_rx[qid]; + mt76_dma_rx_fill(dev, q, false); } @@ -518,7 +525,8 @@ static const struct mt76_queue_ops mt76_dma_ops = { .add_buf = mt76_dma_add_buf, .tx_queue_skb = mt76_dma_tx_queue_skb, .tx_cleanup = mt76_dma_tx_cleanup, - .rx_reset = mt76_dma_rx_reset, + .init_rx_reset = mt76_dma_init_rx_reset, + .complete_rx_reset = mt76_dma_complete_rx_reset, .kick = mt76_dma_kick_queue, }; diff --git a/drivers/net/wireless/mediatek/mt76/mt76.h b/drivers/net/wireless/mediatek/mt76/mt76.h index 5cd508a68609..70924792d870 100644 --- a/drivers/net/wireless/mediatek/mt76/mt76.h +++ b/drivers/net/wireless/mediatek/mt76/mt76.h @@ -159,7 +159,8 @@ struct mt76_queue_ops { void *(*dequeue)(struct mt76_dev *dev, struct mt76_queue *q, bool flush, int *len, u32 *info, bool *more); - void (*rx_reset)(struct mt76_dev *dev, enum mt76_rxq_id qid); + void (*init_rx_reset)(struct mt76_dev *dev, enum mt76_rxq_id qid); + void (*complete_rx_reset)(struct mt76_dev *dev, enum mt76_rxq_id qid); void (*tx_cleanup)(struct mt76_dev *dev, enum mt76_txq_id qid, bool flush); @@ -552,9 +553,10 @@ static inline u16 mt76_rev(struct mt76_dev *dev) #define mt76_init_queues(dev) (dev)->mt76.queue_ops->init(&((dev)->mt76)) #define mt76_queue_alloc(dev, ...) (dev)->mt76.queue_ops->alloc(&((dev)->mt76), __VA_ARGS__) #define mt76_queue_add_buf(dev, ...) (dev)->mt76.queue_ops->add_buf(&((dev)->mt76), __VA_ARGS__) -#define mt76_queue_rx_reset(dev, ...) (dev)->mt76.queue_ops->rx_reset(&((dev)->mt76), __VA_ARGS__) #define mt76_queue_tx_cleanup(dev, ...) (dev)->mt76.queue_ops->tx_cleanup(&((dev)->mt76), __VA_ARGS__) #define mt76_queue_kick(dev, ...) (dev)->mt76.queue_ops->kick(&((dev)->mt76), __VA_ARGS__) +#define mt76_queue_init_rx_reset(dev, ...) (dev)->mt76.queue_ops->init_rx_reset(&((dev)->mt76), __VA_ARGS__) +#define mt76_queue_complete_rx_reset(dev, ...) (dev)->mt76.queue_ops->complete_rx_reset(&((dev)->mt76), __VA_ARGS__) static inline struct mt76_channel_state * mt76_channel_state(struct mt76_dev *dev, struct ieee80211_channel *c) From patchwork Tue Nov 27 22:21:11 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lorenzo Bianconi X-Patchwork-Id: 10701549 X-Patchwork-Delegate: johannes@sipsolutions.net Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 5140314BD for ; Tue, 27 Nov 2018 22:21:35 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 432792C637 for ; Tue, 27 Nov 2018 22:21:35 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 375702CA81; Tue, 27 Nov 2018 22:21:35 +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=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI 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 CA6392C637 for ; Tue, 27 Nov 2018 22:21:34 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726989AbeK1JUy (ORCPT ); Wed, 28 Nov 2018 04:20:54 -0500 Received: from mail-wm1-f68.google.com ([209.85.128.68]:39472 "EHLO mail-wm1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726843AbeK1JUy (ORCPT ); Wed, 28 Nov 2018 04:20:54 -0500 Received: by mail-wm1-f68.google.com with SMTP id n133so590903wmd.4 for ; Tue, 27 Nov 2018 14:21:32 -0800 (PST) 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:mime-version:content-transfer-encoding; bh=lLKcb/dymw4IB1miLLQVpvbaLD6dtDDBdL4yRV/de0I=; b=CMPb6UzYS5wDRDxwwJHfWlUVsXdOAKvo2E21mGZ6kf+MTkzgseIxgvKANLegfhAHZA 1YeUx7iphkEbzr4eLEnY8IN5wnwwj+zJ07g4eiCoJbz1sDYZAFEmIa79w77/Ff5+Xe+s RU4L2tA/f+VfyrO5f1xTdYXVy8Q8Hx5uKCOhtCeF/VAj05QrWM7N+1K+yRFlQZfb8uAa MGyDg8TTk/88lKm+mcRkyg9pZ3INkDJ0gT159TY732FSLYwT3sWYuD/v5vvRCL3DVcWq AgJrZUh0nYlmQPVsn3jiaWxu4Hmt2YMnPt0tqjjiJquFC6wvch0VwuHUR8El2DAb1IqI THTA== X-Gm-Message-State: AA+aEWZO39accXt0Ao1i3tHa+RgyPPSF0OMbqgyDYx8kYoiJarz06cPW Dyi4btcGnak//Jas4dVjGoR5RThgmjI= X-Google-Smtp-Source: AFSGD/XEX5tMiJ9K6iEw0dAriLeoA77VxpEQ0frsgQMdz05+yUYdq0scM+RDzmyrCwrz0X0FToAgDQ== X-Received: by 2002:a1c:aa92:: with SMTP id t140mr571649wme.36.1543357291390; Tue, 27 Nov 2018 14:21:31 -0800 (PST) Received: from localhost.lan ([151.21.135.68]) by smtp.gmail.com with ESMTPSA id 142sm866245wmw.27.2018.11.27.14.21.30 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 27 Nov 2018 14:21:30 -0800 (PST) From: Lorenzo Bianconi To: linux-wireless@vger.kernel.org Cc: nbd@nbd.name Subject: [RFC 4/5] mt76: make mt76x02_vif_init return int Date: Tue, 27 Nov 2018 23:21:11 +0100 Message-Id: <413e8a1835934ac1aa1e02b7ecbdb4718592e5bb.1543343124.git.lorenzo.bianconi@redhat.com> X-Mailer: git-send-email 2.19.1 In-Reply-To: References: MIME-Version: 1.0 Sender: linux-wireless-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-wireless@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP This is a preliminary patch to add xdp support to mt76 driver since mt76x02_vif_init will be used to xdp_rxq_info data structure and can return an error code Signed-off-by: Lorenzo Bianconi --- drivers/net/wireless/mediatek/mt76/mt76x02.h | 4 ++-- drivers/net/wireless/mediatek/mt76/mt76x02_util.c | 9 +++++---- drivers/net/wireless/mediatek/mt76/mt76x2/usb_main.c | 3 +-- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/drivers/net/wireless/mediatek/mt76/mt76x02.h b/drivers/net/wireless/mediatek/mt76/mt76x02.h index b1d83dd34204..3922854ffa06 100644 --- a/drivers/net/wireless/mediatek/mt76/mt76x02.h +++ b/drivers/net/wireless/mediatek/mt76/mt76x02.h @@ -116,8 +116,8 @@ void mt76x02_sta_remove(struct mt76_dev *mdev, struct ieee80211_vif *vif, struct ieee80211_sta *sta); void mt76x02_config_mac_addr_list(struct mt76x02_dev *dev); -void mt76x02_vif_init(struct mt76x02_dev *dev, struct ieee80211_vif *vif, - unsigned int idx); +int mt76x02_vif_init(struct mt76x02_dev *dev, struct ieee80211_vif *vif, + unsigned int idx); int mt76x02_add_interface(struct ieee80211_hw *hw, struct ieee80211_vif *vif); void mt76x02_remove_interface(struct ieee80211_hw *hw, diff --git a/drivers/net/wireless/mediatek/mt76/mt76x02_util.c b/drivers/net/wireless/mediatek/mt76/mt76x02_util.c index 3a70e5bf7d42..87195076cf62 100644 --- a/drivers/net/wireless/mediatek/mt76/mt76x02_util.c +++ b/drivers/net/wireless/mediatek/mt76/mt76x02_util.c @@ -207,8 +207,8 @@ void mt76x02_sta_remove(struct mt76_dev *mdev, struct ieee80211_vif *vif, } EXPORT_SYMBOL_GPL(mt76x02_sta_remove); -void mt76x02_vif_init(struct mt76x02_dev *dev, struct ieee80211_vif *vif, - unsigned int idx) +int mt76x02_vif_init(struct mt76x02_dev *dev, struct ieee80211_vif *vif, + unsigned int idx) { struct mt76x02_vif *mvif = (struct mt76x02_vif *)vif->drv_priv; struct mt76_txq *mtxq; @@ -220,6 +220,8 @@ void mt76x02_vif_init(struct mt76x02_dev *dev, struct ieee80211_vif *vif, mtxq->wcid = &mvif->group_wcid; mt76_txq_init(&dev->mt76, vif->txq); + + return 0; } EXPORT_SYMBOL_GPL(mt76x02_vif_init); @@ -248,8 +250,7 @@ mt76x02_add_interface(struct ieee80211_hw *hw, struct ieee80211_vif *vif) if (vif->type == NL80211_IFTYPE_STATION) idx += 8; - mt76x02_vif_init(dev, vif, idx); - return 0; + return mt76x02_vif_init(dev, vif, idx); } EXPORT_SYMBOL_GPL(mt76x02_add_interface); diff --git a/drivers/net/wireless/mediatek/mt76/mt76x2/usb_main.c b/drivers/net/wireless/mediatek/mt76/mt76x2/usb_main.c index 2b48cc51a30d..61768c76e5d0 100644 --- a/drivers/net/wireless/mediatek/mt76/mt76x2/usb_main.c +++ b/drivers/net/wireless/mediatek/mt76/mt76x2/usb_main.c @@ -55,8 +55,7 @@ static int mt76x2u_add_interface(struct ieee80211_hw *hw, if (!ether_addr_equal(dev->mt76.macaddr, vif->addr)) mt76x02_mac_setaddr(dev, vif->addr); - mt76x02_vif_init(dev, vif, idx); - return 0; + return mt76x02_vif_init(dev, vif, idx); } static int From patchwork Tue Nov 27 22:21:12 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lorenzo Bianconi X-Patchwork-Id: 10701551 X-Patchwork-Delegate: johannes@sipsolutions.net Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 6500813AD for ; Tue, 27 Nov 2018 22:21:38 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 54C9F2C637 for ; Tue, 27 Nov 2018 22:21:38 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 469802CA81; Tue, 27 Nov 2018 22:21:38 +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=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI 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 645B62C637 for ; Tue, 27 Nov 2018 22:21:37 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726995AbeK1JU5 (ORCPT ); Wed, 28 Nov 2018 04:20:57 -0500 Received: from mail-wr1-f68.google.com ([209.85.221.68]:46267 "EHLO mail-wr1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726843AbeK1JU5 (ORCPT ); Wed, 28 Nov 2018 04:20:57 -0500 Received: by mail-wr1-f68.google.com with SMTP id l9so24312768wrt.13 for ; Tue, 27 Nov 2018 14:21:34 -0800 (PST) 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:mime-version:content-transfer-encoding; bh=x8UKj3zKEna90EfBWJDMTE/PMbBTYoInNryE+FRnSWo=; b=pZLdWz1r9I/n6FVqN2WAuffR6tbN6HtQcQ3A91TDIJyDP8I1Xhx9Alr/GJYPoc1/Mx oTXZF29yjSrqyYiBwVr9XMsAzFP23qvduZBbB1LkMWciQOTN8WOrs+7G8DXnBOoiX+JT R5ShjWAVFUXEysCsXYdODYR+OfRXIifKpUgKd6zXLquO+cyOzhAZlSLpX7XKsYt8gYyS PQkkSJ8XlBgE5rEWKvWOrhm4WQgKXrNOseoEDhCEHn6Gr0EYLgJJ9b/MUPtcpB2Sm6j2 OwSRK/MjOvBbtT/fUCmdN3YKGDMRrtR9B7A8qJwtgzrslttDtGA6v9JA5PpeI8Wfvhpg MgFw== X-Gm-Message-State: AA+aEWYSpxTy6DMu5GyzkhkTnxuV3GpX1JrJrj+YPE9o3CkOUZOPOIki q0+ZV239KaQsUPq0SZVash6S+CLwuMA= X-Google-Smtp-Source: AFSGD/VyKrGU16VBvRmteyhdN3BCwn9RpnAGVJR4obkC3Kofwwl/QjdzsbQiVjnX2xeJb5THTjVysw== X-Received: by 2002:adf:a393:: with SMTP id l19mr29614116wrb.110.1543357293109; Tue, 27 Nov 2018 14:21:33 -0800 (PST) Received: from localhost.lan ([151.21.135.68]) by smtp.gmail.com with ESMTPSA id 142sm866245wmw.27.2018.11.27.14.21.31 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 27 Nov 2018 14:21:32 -0800 (PST) From: Lorenzo Bianconi To: linux-wireless@vger.kernel.org Cc: nbd@nbd.name Subject: [RFC 5/5] mt76: add XDP support Date: Tue, 27 Nov 2018 23:21:12 +0100 Message-Id: <2aeaeea1d3aa7d690c80000c0748d77f05552a9d.1543343124.git.lorenzo.bianconi@redhat.com> X-Mailer: git-send-email 2.19.1 In-Reply-To: References: MIME-Version: 1.0 Sender: linux-wireless-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-wireless@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Introduce XDP in mt76 driver. Add mt76_xdp and mt76x02_xdp_setup routines in order to initialize xdp rx driver hook with the bpf program received from mac80211. Introduce the mt76_dma_rx_xdp routine in order to run the attached bpf program and parse the action result. Currently supported actions are: - XDP_PASS - XDP_ABORTED - XDP_DROP Signed-off-by: Lorenzo Bianconi --- drivers/net/wireless/mediatek/mt76/dma.c | 46 ++++++++++ drivers/net/wireless/mediatek/mt76/mac80211.c | 18 ++++ drivers/net/wireless/mediatek/mt76/mt76.h | 6 ++ .../net/wireless/mediatek/mt76/mt76x0/pci.c | 3 + drivers/net/wireless/mediatek/mt76/mt76x02.h | 3 + .../net/wireless/mediatek/mt76/mt76x02_mac.h | 1 + .../net/wireless/mediatek/mt76/mt76x02_mmio.c | 90 +++++++++++++++++++ .../net/wireless/mediatek/mt76/mt76x02_util.c | 10 ++- .../wireless/mediatek/mt76/mt76x2/pci_init.c | 2 + .../wireless/mediatek/mt76/mt76x2/pci_main.c | 1 + 10 files changed, 179 insertions(+), 1 deletion(-) diff --git a/drivers/net/wireless/mediatek/mt76/dma.c b/drivers/net/wireless/mediatek/mt76/dma.c index efa0eab7cf01..b735849799e3 100644 --- a/drivers/net/wireless/mediatek/mt76/dma.c +++ b/drivers/net/wireless/mediatek/mt76/dma.c @@ -15,6 +15,7 @@ */ #include +#include #include "mt76.h" #include "dma.h" @@ -421,6 +422,44 @@ mt76_add_fragment(struct mt76_dev *dev, struct mt76_queue *q, void *data, dev->drv->rx_skb(dev, q - dev->q_rx, skb); } +static bool +mt76_dma_rx_xdp(struct mt76_dev *dev, unsigned char *data, + int *len) +{ + struct page *page = virt_to_head_page(data); + struct xdp_buff xdp; + u32 action; + + if (!dev->drv->xdp_rxq_info_lookup || + dev->drv->xdp_rxq_info_lookup(dev, data, &xdp) < 0) + return false; + + xdp.data_hard_start = page_address(page); + xdp.data = (void *)data; + xdp_set_data_meta_invalid(&xdp); + xdp.data_end = xdp.data + *len; + + action = bpf_prog_run_xdp(dev->xdp_prog, &xdp); + /* bpf program chan modify the original frame */ + *len = xdp.data_end - xdp.data; + data = xdp.data; + + switch (action) { + case XDP_PASS: + return false; + default: + bpf_warn_invalid_xdp_action(action); + /* fall through */ + case XDP_ABORTED: + trace_xdp_exception(xdp.rxq->dev, dev->xdp_prog, action); + /* fall through */ + case XDP_DROP: + /* XXX: we can reuse the buffer here */ + skb_free_frag(data); + return true; + } +} + static int mt76_dma_rx_process(struct mt76_dev *dev, struct mt76_queue *q, int budget) { @@ -437,6 +476,13 @@ mt76_dma_rx_process(struct mt76_dev *dev, struct mt76_queue *q, int budget) if (!data) break; + /* xdp does not support fragmentes frames */ + if (dev->xdp_prog && !more && + mt76_dma_rx_xdp(dev, data, &len)) { + done++; + continue; + } + if (q->rx_head) { mt76_add_fragment(dev, q, data, len, more); continue; diff --git a/drivers/net/wireless/mediatek/mt76/mac80211.c b/drivers/net/wireless/mediatek/mt76/mac80211.c index b33074cf7e00..387c6bba80ca 100644 --- a/drivers/net/wireless/mediatek/mt76/mac80211.c +++ b/drivers/net/wireless/mediatek/mt76/mac80211.c @@ -707,3 +707,21 @@ int mt76_sta_state(struct ieee80211_hw *hw, struct ieee80211_vif *vif, return 0; } EXPORT_SYMBOL_GPL(mt76_sta_state); + +int mt76_xdp(struct ieee80211_hw *hw, struct netdev_bpf *xdp) +{ + struct mt76_dev *dev = hw->priv; + + switch (xdp->command) { + case XDP_SETUP_PROG: + if (!dev->drv->xdp_setup) + return -ENOTSUPP; + return dev->drv->xdp_setup(dev, xdp->prog); + case XDP_QUERY_PROG: + xdp->prog_id = dev->xdp_prog ? dev->xdp_prog->aux->id : 0; + return 0; + default: + return -EINVAL; + } +} +EXPORT_SYMBOL_GPL(mt76_xdp); diff --git a/drivers/net/wireless/mediatek/mt76/mt76.h b/drivers/net/wireless/mediatek/mt76/mt76.h index 70924792d870..b46e162dbb80 100644 --- a/drivers/net/wireless/mediatek/mt76/mt76.h +++ b/drivers/net/wireless/mediatek/mt76/mt76.h @@ -295,6 +295,9 @@ struct mt76_driver_ops { void (*sta_remove)(struct mt76_dev *dev, struct ieee80211_vif *vif, struct ieee80211_sta *sta); + int (*xdp_setup)(struct mt76_dev *dev, struct bpf_prog *prog); + int (*xdp_rxq_info_lookup)(struct mt76_dev *dev, unsigned char *data, + struct xdp_buff *xdp); }; struct mt76_channel_state { @@ -461,6 +464,8 @@ struct mt76_dev { struct mt76_mmio mmio; struct mt76_usb usb; }; + + struct bpf_prog *xdp_prog; }; enum mt76_phy_type { @@ -737,5 +742,6 @@ void mt76u_queues_deinit(struct mt76_dev *dev); void mt76u_mcu_complete_urb(struct urb *urb); int mt76u_mcu_init_rx(struct mt76_dev *dev); void mt76u_mcu_deinit(struct mt76_dev *dev); +int mt76_xdp(struct ieee80211_hw *hw, struct netdev_bpf *xdp); #endif diff --git a/drivers/net/wireless/mediatek/mt76/mt76x0/pci.c b/drivers/net/wireless/mediatek/mt76/mt76x0/pci.c index d895b6f3dc44..38272593f839 100644 --- a/drivers/net/wireless/mediatek/mt76/mt76x0/pci.c +++ b/drivers/net/wireless/mediatek/mt76/mt76x0/pci.c @@ -105,6 +105,7 @@ static const struct ieee80211_ops mt76x0e_ops = { .release_buffered_frames = mt76_release_buffered_frames, .set_coverage_class = mt76x02_set_coverage_class, .set_rts_threshold = mt76x02_set_rts_threshold, + .xdp = mt76_xdp, }; static int mt76x0e_register_device(struct mt76x02_dev *dev) @@ -163,6 +164,8 @@ mt76x0e_probe(struct pci_dev *pdev, const struct pci_device_id *id) .sta_ps = mt76x02_sta_ps, .sta_add = mt76x02_sta_add, .sta_remove = mt76x02_sta_remove, + .xdp_setup = mt76x02_xdp_setup, + .xdp_rxq_info_lookup = mt76x02_xdp_rxq_info_lookup, }; struct mt76x02_dev *dev; int ret; diff --git a/drivers/net/wireless/mediatek/mt76/mt76x02.h b/drivers/net/wireless/mediatek/mt76/mt76x02.h index 3922854ffa06..c32185f226c3 100644 --- a/drivers/net/wireless/mediatek/mt76/mt76x02.h +++ b/drivers/net/wireless/mediatek/mt76/mt76x02.h @@ -170,6 +170,9 @@ extern const u16 mt76x02_beacon_offsets[16]; void mt76x02_init_beacon_config(struct mt76x02_dev *dev); void mt76x02_set_irq_mask(struct mt76x02_dev *dev, u32 clear, u32 set); void mt76x02_mac_start(struct mt76x02_dev *dev); +int mt76x02_xdp_setup(struct mt76_dev *mdev, struct bpf_prog *prog); +int mt76x02_xdp_rxq_info_lookup(struct mt76_dev *mdev, unsigned char *data, + struct xdp_buff *xdp); void mt76x02_init_debugfs(struct mt76x02_dev *dev); diff --git a/drivers/net/wireless/mediatek/mt76/mt76x02_mac.h b/drivers/net/wireless/mediatek/mt76/mt76x02_mac.h index 4e597004c445..176625d23fb6 100644 --- a/drivers/net/wireless/mediatek/mt76/mt76x02_mac.h +++ b/drivers/net/wireless/mediatek/mt76/mt76x02_mac.h @@ -38,6 +38,7 @@ struct mt76x02_tx_status { struct mt76x02_vif { struct mt76_wcid group_wcid; /* must be first */ + struct xdp_rxq_info xdp_rxq; u8 idx; }; diff --git a/drivers/net/wireless/mediatek/mt76/mt76x02_mmio.c b/drivers/net/wireless/mediatek/mt76/mt76x02_mmio.c index 66315410aebe..76fbf136d415 100644 --- a/drivers/net/wireless/mediatek/mt76/mt76x02_mmio.c +++ b/drivers/net/wireless/mediatek/mt76/mt76x02_mmio.c @@ -27,6 +27,12 @@ struct beacon_bc_data { struct sk_buff *tail[8]; }; +struct xdp_iter_data { + struct ieee80211_hdr *hdr; + struct mt76x02_dev *dev; + struct xdp_rxq_info **rxq_info; +}; + static void mt76x02_update_beacon_iter(void *priv, u8 *mac, struct ieee80211_vif *vif) { @@ -384,3 +390,87 @@ void mt76x02_mac_start(struct mt76x02_dev *dev) MT_INT_TX_STAT); } EXPORT_SYMBOL_GPL(mt76x02_mac_start); + +int mt76x02_xdp_setup(struct mt76_dev *mdev, struct bpf_prog *prog) +{ + struct bpf_prog *old_prog; + struct mt76x02_dev *dev; + bool reset; + + if (prog) { + prog = bpf_prog_add(prog, 1); + if (IS_ERR(prog)) + return -EINVAL; + } + + mutex_lock(&mdev->mutex); + + reset = (!!mdev->xdp_prog ^ !!prog); + dev = container_of(mdev, struct mt76x02_dev, mt76); + + if (reset) { + mt76_clear(dev, MT_MAC_SYS_CTRL, MT_MAC_SYS_CTRL_ENABLE_RX); + napi_disable(&mdev->napi[MT_RXQ_MAIN]); + mt76_queue_init_rx_reset(dev, MT_RXQ_MAIN); + } + + /* attach BPF program */ + old_prog = xchg(&mdev->xdp_prog, prog); + if (old_prog) + bpf_prog_put(old_prog); + + if (reset) { + struct mt76_queue *q = &mdev->q_rx[MT_RXQ_MAIN]; + + if (mdev->xdp_prog) + q->buf_size = PAGE_SIZE + XDP_PACKET_HEADROOM + + SKB_DATA_ALIGN(sizeof(struct skb_shared_info)); + else + q->buf_size = MT_RX_BUF_SIZE; + + mt76_queue_complete_rx_reset(dev, MT_RXQ_MAIN); + napi_enable(&mdev->napi[MT_RXQ_MAIN]); + mt76_set(dev, MT_MAC_SYS_CTRL, MT_MAC_SYS_CTRL_ENABLE_RX); + } + + mutex_unlock(&mdev->mutex); + + return 0; +} +EXPORT_SYMBOL_GPL(mt76x02_xdp_setup); + +static void +mt76x02_xdp_iter(void *priv, u8 *mac, struct ieee80211_vif *vif) +{ + struct xdp_iter_data *data = (struct xdp_iter_data *)priv; + + if (ether_addr_equal(mac, data->hdr->addr1) || + (!data->rxq_info && is_multicast_ether_addr(data->hdr->addr1))) { + struct mt76x02_vif *mvif; + + mvif = (struct mt76x02_vif *)vif->drv_priv; + *data->rxq_info = &mvif->xdp_rxq; + } +} + +int mt76x02_xdp_rxq_info_lookup(struct mt76_dev *mdev, unsigned char *data, + struct xdp_buff *xdp) +{ + struct xdp_iter_data xdp_data = {}; + struct ieee80211_hdr *hdr; + struct mt76x02_dev *dev; + + hdr = (struct ieee80211_hdr *)(data + sizeof(struct mt76x02_rxwi)); + dev = container_of(mdev, struct mt76x02_dev, mt76); + + xdp_data.rxq_info = &xdp->rxq; + xdp_data.dev = dev; + xdp_data.hdr = hdr; + + ieee80211_iterate_active_interfaces_atomic(mt76_hw(dev), + IEEE80211_IFACE_ITER_RESUME_ALL, + mt76x02_xdp_iter, &xdp_data); + + return 0; +} +EXPORT_SYMBOL_GPL(mt76x02_xdp_rxq_info_lookup); diff --git a/drivers/net/wireless/mediatek/mt76/mt76x02_util.c b/drivers/net/wireless/mediatek/mt76/mt76x02_util.c index 87195076cf62..0270f7ef3002 100644 --- a/drivers/net/wireless/mediatek/mt76/mt76x02_util.c +++ b/drivers/net/wireless/mediatek/mt76/mt76x02_util.c @@ -211,6 +211,7 @@ int mt76x02_vif_init(struct mt76x02_dev *dev, struct ieee80211_vif *vif, unsigned int idx) { struct mt76x02_vif *mvif = (struct mt76x02_vif *)vif->drv_priv; + struct net_device *ndev = ieee80211_vif_to_netdev(vif); struct mt76_txq *mtxq; mvif->idx = idx; @@ -221,7 +222,7 @@ int mt76x02_vif_init(struct mt76x02_dev *dev, struct ieee80211_vif *vif, mt76_txq_init(&dev->mt76, vif->txq); - return 0; + return ndev ? xdp_rxq_info_reg(&mvif->xdp_rxq, ndev, 0) : 0; } EXPORT_SYMBOL_GPL(mt76x02_vif_init); @@ -257,9 +258,16 @@ EXPORT_SYMBOL_GPL(mt76x02_add_interface); void mt76x02_remove_interface(struct ieee80211_hw *hw, struct ieee80211_vif *vif) { + struct net_device *ndev = ieee80211_vif_to_netdev(vif); struct mt76x02_dev *dev = hw->priv; mt76_txq_remove(&dev->mt76, vif->txq); + if (ndev) { + struct mt76x02_vif *mvif; + + mvif = (struct mt76x02_vif *)vif->drv_priv; + xdp_rxq_info_unreg(&mvif->xdp_rxq); + } } EXPORT_SYMBOL_GPL(mt76x02_remove_interface); diff --git a/drivers/net/wireless/mediatek/mt76/mt76x2/pci_init.c b/drivers/net/wireless/mediatek/mt76/mt76x2/pci_init.c index 6eaab156387a..c6a60d6809f0 100644 --- a/drivers/net/wireless/mediatek/mt76/mt76x2/pci_init.c +++ b/drivers/net/wireless/mediatek/mt76/mt76x2/pci_init.c @@ -325,6 +325,8 @@ struct mt76x02_dev *mt76x2_alloc_device(struct device *pdev) .sta_ps = mt76x02_sta_ps, .sta_add = mt76x02_sta_add, .sta_remove = mt76x02_sta_remove, + .xdp_setup = mt76x02_xdp_setup, + .xdp_rxq_info_lookup = mt76x02_xdp_rxq_info_lookup, }; struct mt76x02_dev *dev; struct mt76_dev *mdev; diff --git a/drivers/net/wireless/mediatek/mt76/mt76x2/pci_main.c b/drivers/net/wireless/mediatek/mt76/mt76x2/pci_main.c index b54a32397486..6898f134e3fe 100644 --- a/drivers/net/wireless/mediatek/mt76/mt76x2/pci_main.c +++ b/drivers/net/wireless/mediatek/mt76/mt76x2/pci_main.c @@ -199,5 +199,6 @@ const struct ieee80211_ops mt76x2_ops = { .set_antenna = mt76x2_set_antenna, .get_antenna = mt76x2_get_antenna, .set_rts_threshold = mt76x02_set_rts_threshold, + .xdp = mt76_xdp, };