From patchwork Tue Jan 15 12:33:42 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lorenzo Bianconi X-Patchwork-Id: 10764449 X-Patchwork-Delegate: kvalo@adurom.com 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 3859713A4 for ; Tue, 15 Jan 2019 12:34:05 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 285C01FFF9 for ; Tue, 15 Jan 2019 12:34:05 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 1C5C129C5D; Tue, 15 Jan 2019 12:34:05 +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 AD3791FFF9 for ; Tue, 15 Jan 2019 12:34:04 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729028AbfAOMd4 (ORCPT ); Tue, 15 Jan 2019 07:33:56 -0500 Received: from mail-wm1-f67.google.com ([209.85.128.67]:40558 "EHLO mail-wm1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729562AbfAOMdz (ORCPT ); Tue, 15 Jan 2019 07:33:55 -0500 Received: by mail-wm1-f67.google.com with SMTP id f188so2995923wmf.5 for ; Tue, 15 Jan 2019 04:33:54 -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=RuJ/WWpRTTiu4D5Hs2UAEtWpz2NJs3J/QjjiVzy6IdM=; b=ssbva0i+RTYZTYf7zAd6hJWEUX0RAZ0Ucu5AjQ6Bg2ubDJ0hyoW6PgfGM9xdqoPNP7 3LYDzJKAPMkuT5A8Cws5IAMzVNtkrtiwECh3MtEXA0+Lc5giXNJaGjLeTtBQABkcSePF PjEXxM5r1k3l8HEs7yTz3iG/g4YTc8+i/ZysJf1RbbUTjP6UgmKyS2it9u2+9dx6BbfB YTiqyqea8a6omKah6Pt9FF08IFo0uCD9GIFf3viapV6/GiJLQLuqpV2nUzBCl31Xvgo1 8OfWCD5BYHXzNdAvhMSZC7GAyRMHbJiKbG/bE+1nK23xauPLv/mwR6ZT33I3+f/dgWkR qd+g== X-Gm-Message-State: AJcUukcmTdETUbDkV6aknmYYLCYr45QK7+CTYve6xaT7ZXyT9foW9xVz ODS3eIF+prgFslCtROwAdhNRSA== X-Google-Smtp-Source: ALg8bN4Ncy9hsIGWp8EuzZzSmsQHK4QItqsHjCBcxXkibaSSz6xq/KX/0rUMiG0XtqCZuoXxI6Gypw== X-Received: by 2002:a1c:f613:: with SMTP id w19mr3250699wmc.0.1547555633192; Tue, 15 Jan 2019 04:33:53 -0800 (PST) Received: from localhost.localdomain.com (nat-pool-mxp-t.redhat.com. [149.6.153.186]) by smtp.gmail.com with ESMTPSA id a6sm28218186wmh.10.2019.01.15.04.33.52 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 15 Jan 2019 04:33:52 -0800 (PST) From: Lorenzo Bianconi To: nbd@nbd.name Cc: linux-wireless@vger.kernel.org, rosenp@gmail.com, sgruszka@redhat.com Subject: [RFC 1/4] mt76: usb: move mt76u_check_sg in usb.c Date: Tue, 15 Jan 2019 13:33:42 +0100 Message-Id: X-Mailer: git-send-email 2.20.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 Move mt76u_check_sg routine in usb.c and introduce sg_en variable in mt76_usb in order to check if scatter-gather is supported by mt76u layer Signed-off-by: Lorenzo Bianconi --- drivers/net/wireless/mediatek/mt76/mt76.h | 11 +---------- drivers/net/wireless/mediatek/mt76/mt76x0/usb.c | 2 +- .../net/wireless/mediatek/mt76/mt76x2/usb_init.c | 2 +- drivers/net/wireless/mediatek/mt76/usb.c | 14 +++++++++++++- 4 files changed, 16 insertions(+), 13 deletions(-) diff --git a/drivers/net/wireless/mediatek/mt76/mt76.h b/drivers/net/wireless/mediatek/mt76/mt76.h index 8ef430d8afc4..d31681f90ff2 100644 --- a/drivers/net/wireless/mediatek/mt76/mt76.h +++ b/drivers/net/wireless/mediatek/mt76/mt76.h @@ -368,6 +368,7 @@ struct mt76_usb { u16 out_max_packet; u8 in_ep[__MT_EP_IN_MAX]; u16 in_max_packet; + bool sg_en; struct mt76u_mcu { struct mutex mutex; @@ -704,16 +705,6 @@ static inline u8 q2ep(u8 qid) return qid + 1; } -static inline bool mt76u_check_sg(struct mt76_dev *dev) -{ - struct usb_interface *intf = to_usb_interface(dev->dev); - struct usb_device *udev = interface_to_usbdev(intf); - - return (udev->bus->sg_tablesize > 0 && - (udev->bus->no_sg_constraint || - udev->speed == USB_SPEED_WIRELESS)); -} - int mt76u_vendor_request(struct mt76_dev *dev, u8 req, u8 req_type, u16 val, u16 offset, void *buf, size_t len); diff --git a/drivers/net/wireless/mediatek/mt76/mt76x0/usb.c b/drivers/net/wireless/mediatek/mt76/mt76x0/usb.c index 0e6b43bb4678..2c140f411972 100644 --- a/drivers/net/wireless/mediatek/mt76/mt76x0/usb.c +++ b/drivers/net/wireless/mediatek/mt76/mt76x0/usb.c @@ -196,7 +196,7 @@ static int mt76x0u_register_device(struct mt76x02_dev *dev) goto out_err; /* check hw sg support in order to enable AMSDU */ - if (mt76u_check_sg(&dev->mt76)) + if (dev->mt76.usb.sg_en) hw->max_tx_fragments = MT_SG_MAX_SIZE; else hw->max_tx_fragments = 1; diff --git a/drivers/net/wireless/mediatek/mt76/mt76x2/usb_init.c b/drivers/net/wireless/mediatek/mt76/mt76x2/usb_init.c index 0be3784f44fb..e39bd876b040 100644 --- a/drivers/net/wireless/mediatek/mt76/mt76x2/usb_init.c +++ b/drivers/net/wireless/mediatek/mt76/mt76x2/usb_init.c @@ -256,7 +256,7 @@ int mt76x2u_register_device(struct mt76x02_dev *dev) goto fail; /* check hw sg support in order to enable AMSDU */ - if (mt76u_check_sg(&dev->mt76)) + if (dev->mt76.usb.sg_en) hw->max_tx_fragments = MT_SG_MAX_SIZE; else hw->max_tx_fragments = 1; diff --git a/drivers/net/wireless/mediatek/mt76/usb.c b/drivers/net/wireless/mediatek/mt76/usb.c index 6a2507524c6c..44e9f5d66326 100644 --- a/drivers/net/wireless/mediatek/mt76/usb.c +++ b/drivers/net/wireless/mediatek/mt76/usb.c @@ -241,6 +241,16 @@ mt76u_rd_rp(struct mt76_dev *dev, u32 base, return mt76u_req_rd_rp(dev, base, data, n); } +static bool mt76u_check_sg(struct mt76_dev *dev) +{ + struct usb_interface *intf = to_usb_interface(dev->dev); + struct usb_device *udev = interface_to_usbdev(intf); + + return (udev->bus->sg_tablesize > 0 && + (udev->bus->no_sg_constraint || + udev->speed == USB_SPEED_WIRELESS)); +} + static int mt76u_set_endpoints(struct usb_interface *intf, struct mt76_usb *usb) @@ -530,7 +540,7 @@ static int mt76u_alloc_rx(struct mt76_dev *dev) if (!q->entry) return -ENOMEM; - if (mt76u_check_sg(dev)) { + if (dev->usb.sg_en) { q->buf_size = MT_RX_BUF_SIZE; nsgs = MT_SG_MAX_SIZE; } else { @@ -882,6 +892,8 @@ int mt76u_init(struct mt76_dev *dev, dev->bus = &mt76u_ops; dev->queue_ops = &usb_queue_ops; + usb->sg_en = mt76u_check_sg(dev); + return mt76u_set_endpoints(intf, usb); } EXPORT_SYMBOL_GPL(mt76u_init); From patchwork Tue Jan 15 12:33:43 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lorenzo Bianconi X-Patchwork-Id: 10764445 X-Patchwork-Delegate: kvalo@adurom.com 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 4C98391E for ; Tue, 15 Jan 2019 12:34:03 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3AB311FFF9 for ; Tue, 15 Jan 2019 12:34:03 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 2DD4129C5D; Tue, 15 Jan 2019 12:34:03 +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 927991FFF9 for ; Tue, 15 Jan 2019 12:34:02 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729592AbfAOMeB (ORCPT ); Tue, 15 Jan 2019 07:34:01 -0500 Received: from mail-wm1-f47.google.com ([209.85.128.47]:40754 "EHLO mail-wm1-f47.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729572AbfAOMd5 (ORCPT ); Tue, 15 Jan 2019 07:33:57 -0500 Received: by mail-wm1-f47.google.com with SMTP id f188so2996012wmf.5 for ; Tue, 15 Jan 2019 04:33:55 -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=hl3Tn8m7qsr/gOSYjz12EGooAhsaerhrKDCZP32QUtg=; b=UnJCYWZy3eVD0TBEjYQqaicTaqvUgfnbYaBFyy1YGxWrN2BtNd2aj5xx6+eoaybVGY IvPTrseydIvv4DZHNs3+2M28YSIj0vz9UQu0cS9w1KDhbK0/GVDD+HsjkAV3cHirjF4g 81aI/Rbq9eRtc9c/ajAvBgOPUbuS5P26rqsHS3xde/zDr5f7e0sXXBxYhQ75lyTy0nKy bkgiCjEBXzc1TcCmYJl1wu4Br1tBFO/WYEb4ZOc2zto8lwSxtHXjAzBS5ab+SBVVLqrP LZRntHIvR8zmT8jqjo247f17MvBarUoyeb+gX+QLnn8YLLGhVhzikCSd3SH3/ENRIpBO xOFA== X-Gm-Message-State: AJcUukduD7UL/DEkrnTbuUBfE5Lmuz2Ili1NCX0hZmUhK5Tpp7gbV/sL QJi8lHkivBSyH+/XmFVSo/ozJw== X-Google-Smtp-Source: ALg8bN7alPz9ODWlgwYLdD9z1WQGc/gzmlUIqLtOUHdIZkSWYtpJzcCMLDa1Q35BW1JmxhjxaStn+g== X-Received: by 2002:a1c:a401:: with SMTP id n1mr3364452wme.101.1547555634480; Tue, 15 Jan 2019 04:33:54 -0800 (PST) Received: from localhost.localdomain.com (nat-pool-mxp-t.redhat.com. [149.6.153.186]) by smtp.gmail.com with ESMTPSA id a6sm28218186wmh.10.2019.01.15.04.33.53 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 15 Jan 2019 04:33:53 -0800 (PST) From: Lorenzo Bianconi To: nbd@nbd.name Cc: linux-wireless@vger.kernel.org, rosenp@gmail.com, sgruszka@redhat.com Subject: [RFC 2/4] mt76: usb: do not use sg buffer for fw upload Date: Tue, 15 Jan 2019 13:33:43 +0100 Message-Id: X-Mailer: git-send-email 2.20.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 Do not use scatter-gather buffers for fw uploading. Introduce mt76u_buf_alloc and mt76u_buf_alloc_sg routines. mt76u_buf_alloc will be reused by mt76u for buffer allocation if scatter-gather is not supported Signed-off-by: Lorenzo Bianconi --- drivers/net/wireless/mediatek/mt76/mt76.h | 3 +- .../wireless/mediatek/mt76/mt76x02_usb_mcu.c | 9 ++--- drivers/net/wireless/mediatek/mt76/usb.c | 37 +++++++++++++++---- drivers/net/wireless/mediatek/mt76/usb_mcu.c | 5 +-- 4 files changed, 38 insertions(+), 16 deletions(-) diff --git a/drivers/net/wireless/mediatek/mt76/mt76.h b/drivers/net/wireless/mediatek/mt76/mt76.h index d31681f90ff2..05ab6672a154 100644 --- a/drivers/net/wireless/mediatek/mt76/mt76.h +++ b/drivers/net/wireless/mediatek/mt76/mt76.h @@ -86,6 +86,7 @@ struct mt76u_buf { struct mt76_dev *dev; struct urb *urb; size_t len; + void *buf; bool done; }; @@ -713,7 +714,7 @@ void mt76u_single_wr(struct mt76_dev *dev, const u8 req, int mt76u_init(struct mt76_dev *dev, struct usb_interface *intf); void mt76u_deinit(struct mt76_dev *dev); int mt76u_buf_alloc(struct mt76_dev *dev, struct mt76u_buf *buf, - int nsgs, int len, int sglen, gfp_t gfp); + int len, int data_len, gfp_t gfp); void mt76u_buf_free(struct mt76u_buf *buf); int mt76u_submit_buf(struct mt76_dev *dev, int dir, int index, struct mt76u_buf *buf, gfp_t gfp, diff --git a/drivers/net/wireless/mediatek/mt76/mt76x02_usb_mcu.c b/drivers/net/wireless/mediatek/mt76/mt76x02_usb_mcu.c index 6db789f90269..925aeee56a3e 100644 --- a/drivers/net/wireless/mediatek/mt76/mt76x02_usb_mcu.c +++ b/drivers/net/wireless/mediatek/mt76/mt76x02_usb_mcu.c @@ -78,9 +78,9 @@ static int mt76x02u_mcu_wait_resp(struct mt76_dev *dev, u8 seq) struct mt76_usb *usb = &dev->usb; struct mt76u_buf *buf = &usb->mcu.res; struct urb *urb = buf->urb; + u8 *data = buf->buf; int i, ret; u32 rxfce; - u8 *data; for (i = 0; i < 5; i++) { if (!wait_for_completion_timeout(&usb->mcu.cmpl, @@ -90,7 +90,6 @@ static int mt76x02u_mcu_wait_resp(struct mt76_dev *dev, u8 seq) if (urb->status) return -EIO; - data = sg_virt(&urb->sg[0]); if (usb->mcu.rp) mt76x02u_multiple_mcu_reads(dev, data + 4, urb->actual_length - 8); @@ -271,8 +270,8 @@ static int __mt76x02u_mcu_fw_send_data(struct mt76x02_dev *dev, struct mt76u_buf *buf, const void *fw_data, int len, u32 dst_addr) { - u8 *data = sg_virt(&buf->urb->sg[0]); DECLARE_COMPLETION_ONSTACK(cmpl); + u8 *data = buf->buf; __le32 info; u32 val; int err; @@ -325,8 +324,8 @@ int mt76x02u_mcu_fw_send_data(struct mt76x02_dev *dev, const void *data, int err, len, pos = 0, max_len = max_payload - 8; struct mt76u_buf buf; - err = mt76u_buf_alloc(&dev->mt76, &buf, 1, max_payload, max_payload, - GFP_KERNEL); + err = mt76u_buf_alloc(&dev->mt76, &buf, max_payload, + max_payload, GFP_KERNEL); if (err < 0) return err; diff --git a/drivers/net/wireless/mediatek/mt76/usb.c b/drivers/net/wireless/mediatek/mt76/usb.c index 44e9f5d66326..4dc288e86fd1 100644 --- a/drivers/net/wireless/mediatek/mt76/usb.c +++ b/drivers/net/wireless/mediatek/mt76/usb.c @@ -320,7 +320,28 @@ mt76u_fill_rx_sg(struct mt76_dev *dev, struct mt76u_buf *buf, } int mt76u_buf_alloc(struct mt76_dev *dev, struct mt76u_buf *buf, - int nsgs, int len, int sglen, gfp_t gfp) + int len, int data_len, gfp_t gfp) +{ + struct mt76_queue *q = &dev->q_rx[MT_RXQ_MAIN]; + + buf->urb = usb_alloc_urb(0, gfp); + if (!buf->urb) + return -ENOMEM; + + buf->buf = page_frag_alloc(&q->rx_page, len, gfp); + if (!buf->buf) + return -ENOMEM; + + buf->len = data_len; + buf->dev = dev; + + return 0; +} +EXPORT_SYMBOL_GPL(mt76u_buf_alloc); + +static int +mt76u_buf_alloc_sg(struct mt76_dev *dev, struct mt76u_buf *buf, + int nsgs, int len, int sglen, gfp_t gfp) { buf->urb = usb_alloc_urb(0, gfp); if (!buf->urb) @@ -336,7 +357,6 @@ int mt76u_buf_alloc(struct mt76_dev *dev, struct mt76u_buf *buf, return mt76u_fill_rx_sg(dev, buf, nsgs, len, sglen); } -EXPORT_SYMBOL_GPL(mt76u_buf_alloc); void mt76u_buf_free(struct mt76u_buf *buf) { @@ -345,6 +365,8 @@ void mt76u_buf_free(struct mt76u_buf *buf) for (i = 0; i < urb->num_sgs; i++) skb_free_frag(sg_virt(&urb->sg[i])); + if (buf->buf) + skb_free_frag(buf->buf); usb_free_urb(buf->urb); } EXPORT_SYMBOL_GPL(mt76u_buf_free); @@ -355,6 +377,7 @@ int mt76u_submit_buf(struct mt76_dev *dev, int dir, int index, { struct usb_interface *intf = to_usb_interface(dev->dev); struct usb_device *udev = interface_to_usbdev(intf); + u8 *data = buf->urb->num_sgs ? NULL : buf->buf; unsigned int pipe; if (dir == USB_DIR_IN) @@ -362,7 +385,7 @@ int mt76u_submit_buf(struct mt76_dev *dev, int dir, int index, else pipe = usb_sndbulkpipe(udev, dev->usb.out_ep[index]); - usb_fill_bulk_urb(buf->urb, udev, pipe, NULL, buf->len, + usb_fill_bulk_urb(buf->urb, udev, pipe, data, buf->len, complete_fn, context); trace_submit_urb(dev, buf->urb); @@ -549,10 +572,10 @@ static int mt76u_alloc_rx(struct mt76_dev *dev) } for (i = 0; i < MT_NUM_RX_ENTRIES; i++) { - err = mt76u_buf_alloc(dev, &q->entry[i].ubuf, - nsgs, q->buf_size, - SKB_WITH_OVERHEAD(q->buf_size), - GFP_KERNEL); + err = mt76u_buf_alloc_sg(dev, &q->entry[i].ubuf, + nsgs, q->buf_size, + SKB_WITH_OVERHEAD(q->buf_size), + GFP_KERNEL); if (err < 0) return err; } diff --git a/drivers/net/wireless/mediatek/mt76/usb_mcu.c b/drivers/net/wireless/mediatek/mt76/usb_mcu.c index 036be4163e69..e14e82a9e7c0 100644 --- a/drivers/net/wireless/mediatek/mt76/usb_mcu.c +++ b/drivers/net/wireless/mediatek/mt76/usb_mcu.c @@ -29,9 +29,8 @@ int mt76u_mcu_init_rx(struct mt76_dev *dev) struct mt76_usb *usb = &dev->usb; int err; - err = mt76u_buf_alloc(dev, &usb->mcu.res, 1, - MCU_RESP_URB_SIZE, MCU_RESP_URB_SIZE, - GFP_KERNEL); + err = mt76u_buf_alloc(dev, &usb->mcu.res, MCU_RESP_URB_SIZE, + MCU_RESP_URB_SIZE, GFP_KERNEL); if (err < 0) return err; From patchwork Tue Jan 15 12:33:44 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lorenzo Bianconi X-Patchwork-Id: 10764447 X-Patchwork-Delegate: kvalo@adurom.com 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 71DD391E for ; Tue, 15 Jan 2019 12:34:04 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 600151FFF9 for ; Tue, 15 Jan 2019 12:34:04 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 5402129C5D; Tue, 15 Jan 2019 12:34:04 +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 C17B81FFF9 for ; Tue, 15 Jan 2019 12:34:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729590AbfAOMeB (ORCPT ); Tue, 15 Jan 2019 07:34:01 -0500 Received: from mail-wm1-f68.google.com ([209.85.128.68]:37298 "EHLO mail-wm1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729562AbfAOMd5 (ORCPT ); Tue, 15 Jan 2019 07:33:57 -0500 Received: by mail-wm1-f68.google.com with SMTP id g67so3018223wmd.2 for ; Tue, 15 Jan 2019 04:33:56 -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=+UGhwTaubaVTZoqPzgQYfWu2x839nH8fbhXUm/EzEO4=; b=DF09B/MaZpsj7x3Uyn8WEtydtsJUd/bgz+A17KYA5HYFGPHFoP2THi9Sf9bUqqgAHN nxC/+t6brubLL4Ye+tJbZ5TWcVcJJ+6Uol+ZpvwMGMxl80MudV1mN6GZRdE+g9DEj21o f6fMi41z2QLqoQhjvbQbf+WehPzucep/IJ6RpABIHIUdcDbu6vtIy7OeOC/qQZp7fM3S Q8oL/xaRpFnwwG0BrxmIqYcPnNleGCVhJm7SRyGN3AtbkgHqzyBN8Kp9zePUcfPSSybp lkG02QsLAyCC0ZfP4teArXKx6ug1UV5uxY8szCEJzojM0hHFGfC1iww02vMm2r/AUQjm pRPw== X-Gm-Message-State: AJcUukdOIHWLec3cztyxWW817G98AWGhHpOrkJ9wbWYbvmpibOfocp5l lBZTI2qG0wGa7mKxncPw32OYGw== X-Google-Smtp-Source: ALg8bN48QeIp2pQrZ4isv8Bh7GZgKu71DS1hZ5/DH7wDykwY7ZERbfRaNGMTk4uJxfNvt2SQcxipCQ== X-Received: by 2002:a1c:c44c:: with SMTP id u73mr3351935wmf.45.1547555635499; Tue, 15 Jan 2019 04:33:55 -0800 (PST) Received: from localhost.localdomain.com (nat-pool-mxp-t.redhat.com. [149.6.153.186]) by smtp.gmail.com with ESMTPSA id a6sm28218186wmh.10.2019.01.15.04.33.54 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 15 Jan 2019 04:33:54 -0800 (PST) From: Lorenzo Bianconi To: nbd@nbd.name Cc: linux-wireless@vger.kernel.org, rosenp@gmail.com, sgruszka@redhat.com Subject: [RFC 3/4] mt76: usb: use a linear buffer for tx/rx datapath if sg is not supported Date: Tue, 15 Jan 2019 13:33:44 +0100 Message-Id: <34f057f93935e28e9586a9a53331db27d3cc75f1.1547549771.git.lorenzo.bianconi@redhat.com> X-Mailer: git-send-email 2.20.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 Use linear fragment and not a single usb scatter-gather buffer in mt76u {tx,rx} datapath if the usb controller has sg data length constraints Signed-off-by: Lorenzo Bianconi --- drivers/net/wireless/mediatek/mt76/usb.c | 87 +++++++++++++++--------- 1 file changed, 54 insertions(+), 33 deletions(-) diff --git a/drivers/net/wireless/mediatek/mt76/usb.c b/drivers/net/wireless/mediatek/mt76/usb.c index 4dc288e86fd1..491b17756ccd 100644 --- a/drivers/net/wireless/mediatek/mt76/usb.c +++ b/drivers/net/wireless/mediatek/mt76/usb.c @@ -426,10 +426,11 @@ static int mt76u_get_rx_entry_len(u8 *data, u32 data_len) } static int -mt76u_process_rx_entry(struct mt76_dev *dev, struct urb *urb) +mt76u_process_rx_entry(struct mt76_dev *dev, struct mt76u_buf *buf) { struct mt76_queue *q = &dev->q_rx[MT_RXQ_MAIN]; - u8 *data = sg_virt(&urb->sg[0]); + struct urb *urb = buf->urb; + u8 *data = urb->num_sgs ? sg_virt(&urb->sg[0]) : buf->buf; int data_len, len, nsgs = 1; struct sk_buff *skb; @@ -440,7 +441,8 @@ mt76u_process_rx_entry(struct mt76_dev *dev, struct urb *urb) if (len < 0) return 0; - data_len = min_t(int, len, urb->sg[0].length - MT_DMA_HDR_LEN); + data_len = urb->num_sgs ? urb->sg[0].length : buf->len; + data_len = min_t(int, len, data_len - MT_DMA_HDR_LEN); if (MT_DMA_HDR_LEN + data_len > SKB_WITH_OVERHEAD(q->buf_size)) return 0; @@ -452,7 +454,7 @@ mt76u_process_rx_entry(struct mt76_dev *dev, struct urb *urb) __skb_put(skb, data_len); len -= data_len; - while (len > 0) { + while (len > 0 && urb->num_sgs) { data_len = min_t(int, len, urb->sg[nsgs].length); skb_add_rx_frag(skb, skb_shinfo(skb)->nr_frags, sg_page(&urb->sg[nsgs]), @@ -497,12 +499,26 @@ static void mt76u_complete_rx(struct urb *urb) spin_unlock_irqrestore(&q->lock, flags); } +static int +mt76u_refill_rx(struct mt76_dev *dev, struct mt76_queue *q, + struct mt76u_buf *buf, int nsgs) +{ + if (dev->usb.sg_en) { + return mt76u_fill_rx_sg(dev, buf, nsgs, q->buf_size, + SKB_WITH_OVERHEAD(q->buf_size)); + } else { + buf->buf = page_frag_alloc(&q->rx_page, q->buf_size, + GFP_ATOMIC); + return buf->buf ? 0 : -ENOMEM; + } +} + static void mt76u_rx_tasklet(unsigned long data) { struct mt76_dev *dev = (struct mt76_dev *)data; struct mt76_queue *q = &dev->q_rx[MT_RXQ_MAIN]; - int err, nsgs, buf_len = q->buf_size; struct mt76u_buf *buf; + int err, count; rcu_read_lock(); @@ -511,11 +527,9 @@ static void mt76u_rx_tasklet(unsigned long data) if (!buf) break; - nsgs = mt76u_process_rx_entry(dev, buf->urb); - if (nsgs > 0) { - err = mt76u_fill_rx_sg(dev, buf, nsgs, - buf_len, - SKB_WITH_OVERHEAD(buf_len)); + count = mt76u_process_rx_entry(dev, buf); + if (count > 0) { + err = mt76u_refill_rx(dev, q, buf, count); if (err < 0) break; } @@ -553,7 +567,7 @@ EXPORT_SYMBOL_GPL(mt76u_submit_rx_buffers); static int mt76u_alloc_rx(struct mt76_dev *dev) { struct mt76_queue *q = &dev->q_rx[MT_RXQ_MAIN]; - int i, err, nsgs; + int i, err; spin_lock_init(&q->rx_page_lock); spin_lock_init(&q->lock); @@ -563,19 +577,18 @@ static int mt76u_alloc_rx(struct mt76_dev *dev) if (!q->entry) return -ENOMEM; - if (dev->usb.sg_en) { - q->buf_size = MT_RX_BUF_SIZE; - nsgs = MT_SG_MAX_SIZE; - } else { - q->buf_size = PAGE_SIZE; - nsgs = 1; - } - + q->buf_size = dev->usb.sg_en ? MT_RX_BUF_SIZE : PAGE_SIZE; for (i = 0; i < MT_NUM_RX_ENTRIES; i++) { - err = mt76u_buf_alloc_sg(dev, &q->entry[i].ubuf, - nsgs, q->buf_size, - SKB_WITH_OVERHEAD(q->buf_size), - GFP_KERNEL); + if (dev->usb.sg_en) + err = mt76u_buf_alloc_sg(dev, &q->entry[i].ubuf, + MT_SG_MAX_SIZE, q->buf_size, + SKB_WITH_OVERHEAD(q->buf_size), + GFP_KERNEL); + else + err = mt76u_buf_alloc(dev, &q->entry[i].ubuf, + q->buf_size, + SKB_WITH_OVERHEAD(q->buf_size), + GFP_KERNEL); if (err < 0) return err; } @@ -724,7 +737,7 @@ mt76u_tx_queue_skb(struct mt76_dev *dev, struct mt76_queue *q, { struct usb_interface *intf = to_usb_interface(dev->dev); struct usb_device *udev = interface_to_usbdev(intf); - u8 ep = q2ep(q->hw_idx); + u8 *data = NULL, ep = q2ep(q->hw_idx); struct mt76u_buf *buf; u16 idx = q->tail; unsigned int pipe; @@ -741,12 +754,16 @@ mt76u_tx_queue_skb(struct mt76_dev *dev, struct mt76_queue *q, buf = &q->entry[idx].ubuf; buf->done = false; - err = mt76u_tx_build_sg(skb, buf->urb); - if (err < 0) - return err; + if (dev->usb.sg_en) { + err = mt76u_tx_build_sg(skb, buf->urb); + if (err < 0) + return err; + } else { + data = skb->data; + } pipe = usb_sndbulkpipe(udev, dev->usb.out_ep[ep]); - usb_fill_bulk_urb(buf->urb, udev, pipe, NULL, skb->len, + usb_fill_bulk_urb(buf->urb, udev, pipe, data, skb->len, mt76u_complete_tx, buf); q->tail = (q->tail + 1) % q->ndesc; @@ -782,10 +799,8 @@ static int mt76u_alloc_tx(struct mt76_dev *dev) { struct mt76u_buf *buf; struct mt76_queue *q; - size_t size; int i, j; - size = MT_SG_MAX_SIZE * sizeof(struct scatterlist); for (i = 0; i < IEEE80211_NUM_ACS; i++) { q = &dev->q_tx[i]; spin_lock_init(&q->lock); @@ -807,9 +822,15 @@ static int mt76u_alloc_tx(struct mt76_dev *dev) if (!buf->urb) return -ENOMEM; - buf->urb->sg = devm_kzalloc(dev->dev, size, GFP_KERNEL); - if (!buf->urb->sg) - return -ENOMEM; + if (dev->usb.sg_en) { + size_t size = MT_SG_MAX_SIZE * + sizeof(struct scatterlist); + + buf->urb->sg = devm_kzalloc(dev->dev, size, + GFP_KERNEL); + if (!buf->urb->sg) + return -ENOMEM; + } } } return 0; From patchwork Tue Jan 15 12:33:45 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lorenzo Bianconi X-Patchwork-Id: 10764451 X-Patchwork-Delegate: kvalo@adurom.com 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 AB56B184E for ; Tue, 15 Jan 2019 12:34:05 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9A8D91FFF9 for ; Tue, 15 Jan 2019 12:34:05 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 8EF57294DA; Tue, 15 Jan 2019 12:34:05 +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 BD2AF284E8 for ; Tue, 15 Jan 2019 12:34:02 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729594AbfAOMeC (ORCPT ); Tue, 15 Jan 2019 07:34:02 -0500 Received: from mail-wm1-f65.google.com ([209.85.128.65]:51838 "EHLO mail-wm1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729589AbfAOMd7 (ORCPT ); Tue, 15 Jan 2019 07:33:59 -0500 Received: by mail-wm1-f65.google.com with SMTP id b11so3118649wmj.1 for ; Tue, 15 Jan 2019 04:33:57 -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=tQeLfaozPhgc59Xi4Vf5R9yOu4XoYgDRdqqXgKx448A=; b=Biv6yEcKYRi/ji6aFdVdRMLm0gim8AhbjeAzN+tnECL6tSHuxuglpI77J9H8F5KTzG 9rYbTYzHaTKrdMw0v6t4ywhVYwgnoudTJBnfNBKGT2QvXiBfiyAkWsQNFArjLU731s/k oyT9MHcvb57GJVuhpb6cqvFBnrlh7YHcVzVZ+LlXPE3KuTvo0lHDV0KyOEy2Paber3c0 2g6jJ08IfXQDS9t5nbkcwG7fF6uur/50vil64KlvmQXqZqaDEORmeKNGdO52vDinx6b6 0jq+ECMWAhAkgql2uilhubYBsVaRJ76qTkRdyIsUDBQITdg6CTFQuDGupgtbLHQmWsa5 uqlw== X-Gm-Message-State: AJcUuke0qwTt3LKpZJudjbY8lsVwdckNIgwEqa2KZ1qMgrtDsJo8isYs N+2mfLXGECRBpWpT+FVq088o/g== X-Google-Smtp-Source: ALg8bN6P5QIHMe14mRGrJ9nxbQRt9f0J/2lNB4QRF9MCwdsB1A5v+HOjYlJZKjQufsyHh7sxYngTug== X-Received: by 2002:a1c:2686:: with SMTP id m128mr3112662wmm.52.1547555637232; Tue, 15 Jan 2019 04:33:57 -0800 (PST) Received: from localhost.localdomain.com (nat-pool-mxp-t.redhat.com. [149.6.153.186]) by smtp.gmail.com with ESMTPSA id a6sm28218186wmh.10.2019.01.15.04.33.55 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 15 Jan 2019 04:33:55 -0800 (PST) From: Lorenzo Bianconi To: nbd@nbd.name Cc: linux-wireless@vger.kernel.org, rosenp@gmail.com, sgruszka@redhat.com Subject: [RFC 4/4] mt76: usb: introduce disable_usb_sg parameter Date: Tue, 15 Jan 2019 13:33:45 +0100 Message-Id: <99a03acbc5ba45920b3ec08083d2533c1e114baf.1547549771.git.lorenzo.bianconi@redhat.com> X-Mailer: git-send-email 2.20.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 disable_usb_sg module parameter to disable scatter-gather on demand Signed-off-by: Lorenzo Bianconi --- drivers/net/wireless/mediatek/mt76/usb.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/drivers/net/wireless/mediatek/mt76/usb.c b/drivers/net/wireless/mediatek/mt76/usb.c index 491b17756ccd..0b056f04630f 100644 --- a/drivers/net/wireless/mediatek/mt76/usb.c +++ b/drivers/net/wireless/mediatek/mt76/usb.c @@ -22,6 +22,10 @@ #define MT_VEND_REQ_MAX_RETRY 10 #define MT_VEND_REQ_TOUT_MS 300 +static bool disable_usb_sg; +module_param_named(disable_usb_sg, disable_usb_sg, bool, 0644); +MODULE_PARM_DESC(disable_usb_sg, "Disable usb scatter-gather support"); + /* should be called with usb_ctrl_mtx locked */ static int __mt76u_vendor_request(struct mt76_dev *dev, u8 req, u8 req_type, u16 val, u16 offset, @@ -246,7 +250,7 @@ static bool mt76u_check_sg(struct mt76_dev *dev) struct usb_interface *intf = to_usb_interface(dev->dev); struct usb_device *udev = interface_to_usbdev(intf); - return (udev->bus->sg_tablesize > 0 && + return (!disable_usb_sg && udev->bus->sg_tablesize > 0 && (udev->bus->no_sg_constraint || udev->speed == USB_SPEED_WIRELESS)); }