Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp14564379rwb; Mon, 28 Nov 2022 02:34:18 -0800 (PST) X-Google-Smtp-Source: AA0mqf5tWsx8yy0NZjGBUo7Q1jrQXEYkAgyk00VUpKbJGq8RysDvLvt23rNwMVaeAG6i3jewDqC4 X-Received: by 2002:a17:906:9445:b0:7bb:7520:f168 with SMTP id z5-20020a170906944500b007bb7520f168mr17268025ejx.423.1669631658554; Mon, 28 Nov 2022 02:34:18 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669631658; cv=none; d=google.com; s=arc-20160816; b=eg9JcrVRuZoqys4kpqFfYA0/XKIo/V1aPJU+vxVyCrMOafSZ96w8bGfozdmOYGDhb2 yzWiCKsLaT9CGLtvK+RhWvnFZKWw+dZ1UPe/SCzpnwKLh0CzIcHSZEc7iDSX2uRRpSEt q/3sWT5BjBx8Ic8uc25gpJIpkNRWv+nQ0P8PIoPpRhFREtPCneM0Iv+/VrqJ+MjLBarl bpdupg7NRtbfzHr0kHc05lfWbiDk47UzD3jVBPG2cPzkEXn6IlqaSrnV88dumGYKY2zC +s/Pd+bgk2cFwmStwaDiYuQ1h1gsiKh67X+iXQjqmdojty5AjZFn4t/Cn1dYy8EdAnWi mBXA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:user-agent:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date; bh=CnkaEcoztC0UlzmrzLq2Oc1nR7EJzrRKcbUb0CxjEtE=; b=Zin6UEAHYR7laepk5U4KThOP/fmIYCWHOPRshI9HN/CI+Wrj2/lPuJ2+LgF0BpgEj5 1bLfNJMAvJ++2eXqk8r52vcy9HbCNjiC3ukUSodRV4lppuApg8HsI+8XKw3VXnBim2qh P0qcYr+x2ezh7nOaegYZQbB4u2HSTcV4arvib80kfbNssmfHOp9RoOZJV3dyscqqvjNa Kob+b2lfgkmhB7uVwXLIHbo/pgSQDC2+OsHdZcczxqXgEXazdCz4/rqM+lsH+CqhXWRF 76z41Ls3uMSrhtzUOvLyetun1MeuzSJudVwElO99krqEaHlSwLMtuRLdkfv3OQurh1Z7 cEfg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-wireless-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-wireless-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id t24-20020a056402241800b004699f3f2f6esi9089934eda.572.2022.11.28.02.34.00; Mon, 28 Nov 2022 02:34:18 -0800 (PST) Received-SPF: pass (google.com: domain of linux-wireless-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-wireless-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-wireless-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230033AbiK1KaN (ORCPT + 67 others); Mon, 28 Nov 2022 05:30:13 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60514 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229968AbiK1KaK (ORCPT ); Mon, 28 Nov 2022 05:30:10 -0500 Received: from metis.ext.pengutronix.de (metis.ext.pengutronix.de [IPv6:2001:67c:670:201:290:27ff:fe1d:cc33]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 11CD615FEC for ; Mon, 28 Nov 2022 02:30:05 -0800 (PST) Received: from ptx.hi.pengutronix.de ([2001:67c:670:100:1d::c0]) by metis.ext.pengutronix.de with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1ozbOl-0006ch-65; Mon, 28 Nov 2022 11:30:03 +0100 Received: from sha by ptx.hi.pengutronix.de with local (Exim 4.92) (envelope-from ) id 1ozbOi-0000Jf-Qm; Mon, 28 Nov 2022 11:30:00 +0100 Date: Mon, 28 Nov 2022 11:30:00 +0100 From: Sascha Hauer To: Ping-Ke Shih Cc: "linux-wireless@vger.kernel.org" , Neo Jou , Hans Ulli Kroll , Yan-Hsuan Chuang , Kalle Valo , "netdev@vger.kernel.org" , "linux-kernel@vger.kernel.org" , Martin Blumenstingl , "kernel@pengutronix.de" , Johannes Berg , Alexander Hochbaum , Da Xue , Bernie Huang , Viktor Petrenko , neo_jou Subject: Re: [PATCH v3 07/11] rtw88: Add common USB chip support Message-ID: <20221128103000.GC29728@pengutronix.de> References: <20221122145226.4065843-1-s.hauer@pengutronix.de> <20221122145226.4065843-8-s.hauer@pengutronix.de> <1f7aa964766c4f65b836f7e1d716a1e3@realtek.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1f7aa964766c4f65b836f7e1d716a1e3@realtek.com> X-Sent-From: Pengutronix Hildesheim X-URL: http://www.pengutronix.de/ X-Accept-Language: de,en X-Accept-Content-Type: text/plain User-Agent: Mutt/1.10.1 (2018-07-13) X-SA-Exim-Connect-IP: 2001:67c:670:100:1d::c0 X-SA-Exim-Mail-From: sha@pengutronix.de X-SA-Exim-Scanned: No (on metis.ext.pengutronix.de); SAEximRunCond expanded to false X-PTX-Original-Recipient: linux-wireless@vger.kernel.org X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-wireless@vger.kernel.org On Mon, Nov 28, 2022 at 02:00:54AM +0000, Ping-Ke Shih wrote: > > > > -----Original Message----- > > From: Sascha Hauer > > Sent: Tuesday, November 22, 2022 10:52 PM > > To: linux-wireless@vger.kernel.org > > Cc: Neo Jou ; Hans Ulli Kroll ; Ping-Ke Shih ; > > Yan-Hsuan Chuang ; Kalle Valo ; netdev@vger.kernel.org; > > linux-kernel@vger.kernel.org; Martin Blumenstingl ; > > kernel@pengutronix.de; Johannes Berg ; Alexander Hochbaum ; > > Da Xue ; Bernie Huang ; Viktor Petrenko ; > > Sascha Hauer ; neo_jou > > Subject: [PATCH v3 07/11] rtw88: Add common USB chip support > > > > Add the common bits and pieces to add USB support to the RTW88 driver. > > This is based on https://github.com/ulli-kroll/rtw88-usb.git which > > itself is first written by Neo Jou. > > > > Signed-off-by: neo_jou > > Signed-off-by: Hans Ulli Kroll > > Signed-off-by: Sascha Hauer > > --- > > > > Notes: > > Changes since v2: > > - Fix buffer length for aggregated tx packets > > - Increase maximum transmit buffer size to 20KiB as found in downstream drivers > > - Change register write functions to synchronous accesses instead of just firing > > a URB without waiting for its completion > > - requeue rx URBs directly in completion handler rather than having a workqueue > > for it. > > > > Changes since v1: > > - Make checkpatch.pl clean > > - Drop WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL flag > > - Use 'ret' as variable name for return values > > - Sort variable declarations in reverse Xmas tree order > > - Change potentially endless loop to a limited loop > > - Change locking to be more obviously correct > > - drop unnecessary check for !rtwdev > > - make sure the refill workqueue is not restarted again after we have > > cancelled it > > > > drivers/net/wireless/realtek/rtw88/Kconfig | 3 + > > drivers/net/wireless/realtek/rtw88/Makefile | 2 + > > drivers/net/wireless/realtek/rtw88/mac.c | 3 + > > drivers/net/wireless/realtek/rtw88/main.c | 4 + > > drivers/net/wireless/realtek/rtw88/main.h | 4 + > > drivers/net/wireless/realtek/rtw88/reg.h | 1 + > > drivers/net/wireless/realtek/rtw88/tx.h | 31 + > > drivers/net/wireless/realtek/rtw88/usb.c | 918 ++++++++++++++++++++ > > drivers/net/wireless/realtek/rtw88/usb.h | 107 +++ > > 9 files changed, 1073 insertions(+) > > create mode 100644 drivers/net/wireless/realtek/rtw88/usb.c > > create mode 100644 drivers/net/wireless/realtek/rtw88/usb.h > > > > diff --git a/drivers/net/wireless/realtek/rtw88/Kconfig b/drivers/net/wireless/realtek/rtw88/Kconfig > > index e3d7cb6c12902..1624c5db69bac 100644 > > --- a/drivers/net/wireless/realtek/rtw88/Kconfig > > +++ b/drivers/net/wireless/realtek/rtw88/Kconfig > > @@ -16,6 +16,9 @@ config RTW88_CORE > > config RTW88_PCI > > tristate > > > > +config RTW88_USB > > + tristate > > + > > config RTW88_8822B > > tristate > > > > diff --git a/drivers/net/wireless/realtek/rtw88/Makefile b/drivers/net/wireless/realtek/rtw88/Makefile > > index 834c66ec0af9e..9e095f8181483 100644 > > --- a/drivers/net/wireless/realtek/rtw88/Makefile > > +++ b/drivers/net/wireless/realtek/rtw88/Makefile > > @@ -45,4 +45,6 @@ obj-$(CONFIG_RTW88_8821CE) += rtw88_8821ce.o > > rtw88_8821ce-objs := rtw8821ce.o > > > > obj-$(CONFIG_RTW88_PCI) += rtw88_pci.o > > +obj-$(CONFIG_RTW88_USB) += rtw88_usb.o > > rtw88_pci-objs := pci.o > > +rtw88_usb-objs := usb.o > > nit: I prefer not interleaving with PCI. Ok. > > +static u32 rtw_usb_read(struct rtw_dev *rtwdev, u32 addr, u16 len) > > +{ > > + struct rtw_usb *rtwusb = rtw_get_usb_priv(rtwdev); > > + struct usb_device *udev = rtwusb->udev; > > + __le32 *data; > > + unsigned long flags; > > + int ret; > > + static int count; > > + > > + spin_lock_irqsave(&rtwusb->usb_lock, flags); > > + > > + rtwusb->usb_data_index++; > > + rtwusb->usb_data_index &= (RTW_USB_MAX_RXTX_COUNT - 1); > > + > > + spin_unlock_irqrestore(&rtwusb->usb_lock, flags); > > + > > + data = &rtwusb->usb_data[rtwusb->usb_data_index]; > > Don't you need to hold &rtwusb->usb_lock to access rtwusb->usb_data_index? > rtw_usb_write() has similar code. Right. Will rewrite to: spin_lock_irqsave(&rtwusb->usb_lock, flags); idx = rtwusb->usb_data_index; rtwusb->usb_data_index = (idx + 1) & (RTW_USB_MAX_RXTX_COUNT - 1); spin_unlock_irqrestore(&rtwusb->usb_lock, flags); data = &rtwusb->usb_data[idx]; > > +static void rtw_usb_write_port_tx_complete(struct urb *urb) > > +{ > > + struct rtw_usb_txcb *txcb = urb->context; > > + struct rtw_dev *rtwdev = txcb->rtwdev; > > + struct ieee80211_hw *hw = rtwdev->hw; > > + > > + while (true) { > > Is it possible to have a hard limit to prevent unexpected infinite loop? Yes, that would be possible, but do you think it's necessary? Each *txcb is used only once, It's allocated in rtw_usb_tx_agg_skb() and &txcb->tx_ack_queue is filled with a limited number of skbs there. These skbs is then iterated over in rtw_usb_write_port_tx_complete(), so I don't see a way how we could end up in an infinite loop here. It's not that &txcb->tx_ack_queue is filled in a concurrent thread while we try to catch up in rtw_usb_write_port_tx_complete(). > > + skb_head = dev_alloc_skb(RTW_USB_MAX_XMITBUF_SZ); > > + if (!skb_head) { > > + skb_head = skb_iter; > > + goto queue; > > + } > > + > > + data_ptr = skb_head->data; > > + > > + while (skb_iter) { > > + unsigned long flags; > > + > > + memcpy(data_ptr, skb_iter->data, skb_iter->len); > > + skb_put(skb_head, skb_iter->len + align_next); > > skb_put(skb_head, align_next); > skb_put_data(skb_head, skb_iter->data, skb_iter->len); > > Then, don't need to maintain 'data_ptr'. Right. Looks much better this way. > > + error = usb_submit_urb(rxcb->rx_urb, GFP_ATOMIC); > > + if (error) { > > + kfree_skb(rxcb->rx_skb); > > + if (error != -ENODEV) > > + rtw_err(rtwdev, "Err sending rx data urb %d\n", > > + error); > > nit: straighten rtw_err() Ok. Sascha -- Pengutronix e.K. | | Steuerwalder Str. 21 | http://www.pengutronix.de/ | 31137 Hildesheim, Germany | Phone: +49-5121-206917-0 | Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 |