From patchwork Sat Aug 25 10:40:44 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lorenzo Bianconi X-Patchwork-Id: 10576105 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 B588414BD for ; Sat, 25 Aug 2018 10:41:46 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A49B22AF1F for ; Sat, 25 Aug 2018 10:41:46 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 970522B009; Sat, 25 Aug 2018 10:41:46 +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=-2.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE autolearn=unavailable version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 306D22AFC2 for ; Sat, 25 Aug 2018 10:41:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:Message-Id:Date: Subject:To:From:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To: References:List-Owner; bh=Aj0qrUkJhrEfyhPmnYvONQn2vnujRamKcC0+24Xwvt4=; b=fEc Vtets5CaS/ujPLls0qK2QP16+j5hAWCOiGgmV9tFfqhmK8CKdwphycI5J9ziFFU/IahlLkuxr6snz rrBUvuGbRv0kvK28aktOntX4eEKYZjMiCGJZ+DV+E/if3Ir3W5NCoZIZIz3hu+J7q9k8Hz8ZbrukV ZyXamEo974e5Q7skBfmjq+HLrHiYIErC41ecNWIGCODuS6Fywvzupznv/4zuvBE2wEOm1CIri6Jhy 4D7iDrHawnYF7/WJvmkkSND6YU4gNP7lv6yKfPzgoz9bcEu27tjxmabevRx4gUyIJShktKJiXu7XZ 8xbOjX+MqhvqYdoAa8qWR0qLIepxikg==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1ftW0k-0005Au-SB for patchwork-linux-mediatek@patchwork.kernel.org; Sat, 25 Aug 2018 10:41:42 +0000 Received: from mail-wm0-f66.google.com ([74.125.82.66]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1ftW0L-0004vS-Ov for linux-mediatek@lists.infradead.org; Sat, 25 Aug 2018 10:41:20 +0000 Received: by mail-wm0-f66.google.com with SMTP id 207-v6so3837738wme.5 for ; Sat, 25 Aug 2018 03:41:07 -0700 (PDT) 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; bh=cuPjx6fHiUuYiqBIWfJSfSbgEbUs9jvLu/Sw8UmmEJI=; b=iObUAv/AaQv2D+g3V0VSBfg+FR+975IhstTFA3Dzh0RUCP4rFJVhVC3oyiOgC0S8Wd w3RLnzkZi9mHTT2NWabSMhNSTti5H/7zgkfmGHCF86o9oPzgJD1c43MAPVt0n7ao5P7F rc8X4TsO7LFtKwFpGBzVqagji0MhjIVZCVNtZId/oBVdCuvZkBwe0eTUvlPGSTcixrwP oY2RJvJW2WF/HJakzJGTdRCBjQU6hDK0dBMbWTsiGNjOpmwTKCkwQ549JZdQJTTUHvZT q+metIa1Rr/x6dU5fGkl43rYWQDGr5peIDYBXPvzhmSrufJKX3d05pAngcM8AMJ9VRLH s2QA== X-Gm-Message-State: APzg51DIZ6yalXXeMDc/S43SPFIyRifxLdAzfcSrXKfpJTcWks8u9rDN VbF3bsVPAjZBANqJEynRiESFEQ== X-Google-Smtp-Source: ANB0Vdab38aC+wAR8SzMpA/Xm+sC0AEXl0UOVcSTf+GioYv/JHX8Rs/2V3UZ2HAAFle0m7R4jwfnGQ== X-Received: by 2002:a1c:b6d6:: with SMTP id g205-v6mr957073wmf.17.1535193666100; Sat, 25 Aug 2018 03:41:06 -0700 (PDT) Received: from localhost.localdomain ([151.66.53.29]) by smtp.gmail.com with ESMTPSA id l18-v6sm16391708wru.75.2018.08.25.03.41.05 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 25 Aug 2018 03:41:05 -0700 (PDT) From: Lorenzo Bianconi To: nbd@nbd.name Subject: [PATCH 04/16] mt76: add multiple regs read support to usb_mcu layer Date: Sat, 25 Aug 2018 12:40:44 +0200 Message-Id: <20180825104056.9130-5-lorenzo.bianconi@redhat.com> X-Mailer: git-send-email 2.18.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20180825_034117_855171_9DE42770 X-CRM114-Status: GOOD ( 11.46 ) X-BeenThere: linux-mediatek@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linux-wireless@vger.kernel.org, linux-mediatek@lists.infradead.org, sgruszka@redhat.com MIME-Version: 1.0 Sender: "Linux-mediatek" Errors-To: linux-mediatek-bounces+patchwork-linux-mediatek=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP Introduce multiple regs read support to mcu layer in mt76-usb module. Multiple regs read will be reused by mt76x0 driver in usb mcu layer unification between mt76x0 and mt76x2u drivers Signed-off-by: Lorenzo Bianconi --- drivers/net/wireless/mediatek/mt76/mt76.h | 6 +++ drivers/net/wireless/mediatek/mt76/usb_mcu.c | 39 +++++++++++++++++++- 2 files changed, 44 insertions(+), 1 deletion(-) diff --git a/drivers/net/wireless/mediatek/mt76/mt76.h b/drivers/net/wireless/mediatek/mt76/mt76.h index f84f35c2e37a..e9e46612c7f3 100644 --- a/drivers/net/wireless/mediatek/mt76/mt76.h +++ b/drivers/net/wireless/mediatek/mt76/mt76.h @@ -312,6 +312,12 @@ struct mt76_usb { struct completion cmpl; struct mt76u_buf res; u32 msg_seq; + + /* multiple reads */ + struct mt76_reg_pair *rp; + int rp_len; + u32 base; + bool burst; } mcu; }; diff --git a/drivers/net/wireless/mediatek/mt76/usb_mcu.c b/drivers/net/wireless/mediatek/mt76/usb_mcu.c index 1edc5c3d637b..d80dbfafba6d 100644 --- a/drivers/net/wireless/mediatek/mt76/usb_mcu.c +++ b/drivers/net/wireless/mediatek/mt76/usb_mcu.c @@ -49,12 +49,44 @@ void mt76u_mcu_complete_urb(struct urb *urb) } EXPORT_SYMBOL_GPL(mt76u_mcu_complete_urb); +static void +mt76u_multiple_mcu_reads(struct mt76_dev *dev, u8 *data, + int len) +{ + struct mt76_usb *usb = &dev->usb; + u32 reg, val; + int i; + + if (usb->mcu.burst) { + WARN_ON_ONCE(len / 4 != usb->mcu.rp_len); + + reg = usb->mcu.rp[0].reg - usb->mcu.base; + for (i = 0; i < usb->mcu.rp_len; i++) { + val = get_unaligned_le32(data + 4 * i); + usb->mcu.rp[i].reg = reg++; + usb->mcu.rp[i].value = val; + } + } else { + WARN_ON_ONCE(len / 8 != usb->mcu.rp_len); + + for (i = 0; i < usb->mcu.rp_len; i++) { + reg = get_unaligned_le32(data + 8 * i) - + usb->mcu.base; + val = get_unaligned_le32(data + 8 * i + 4); + + WARN_ON_ONCE(usb->mcu.rp[i].reg != reg); + usb->mcu.rp[i].value = val; + } + } +} + static int mt76u_mcu_wait_resp(struct mt76_dev *dev, u8 seq) { struct mt76_usb *usb = &dev->usb; struct mt76u_buf *buf = &usb->mcu.res; int i, ret; u32 rxfce; + u8 *data; for (i = 0; i < 5; i++) { if (!wait_for_completion_timeout(&usb->mcu.cmpl, @@ -64,7 +96,12 @@ static int mt76u_mcu_wait_resp(struct mt76_dev *dev, u8 seq) if (buf->urb->status) return -EIO; - rxfce = get_unaligned_le32(sg_virt(&buf->urb->sg[0])); + data = sg_virt(&buf->urb->sg[0]); + if (usb->mcu.rp) + mt76u_multiple_mcu_reads(dev, data + 4, + buf->urb->actual_length - 8); + + rxfce = get_unaligned_le32(data); ret = mt76u_submit_buf(dev, USB_DIR_IN, MT_EP_IN_CMD_RESP, buf, GFP_KERNEL,