From patchwork Sat Aug 25 10:40:55 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lorenzo Bianconi X-Patchwork-Id: 10576119 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 53EEC14BD for ; Sat, 25 Aug 2018 10:42:07 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 43A002AF1F for ; Sat, 25 Aug 2018 10:42:07 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 378842B113; Sat, 25 Aug 2018 10:42:07 +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 CA0062AF1F for ; Sat, 25 Aug 2018 10:42:06 +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=V6LWjFMKpUcYlHGD+OeCsj2zRrp6IjwkqIHn2ofWw9E=; b=OhA +jI8Ktodxi5Z+A6FupZeENyVd3HE1xdm8b70jkc5lbNUMZFxGCQGpX3qu6mdJafIEcd4KLvNEiWC2 Wmtg/RI5JRCok+9lg/nqmXnGPrjZMFDYW0yaIodSCbz28R1ybLnYvn3OxUYG8QUg5RKwG4/EkV1Xr r5ABk3zSoo6ohRQGWywyd6KHq22ILD/z41zY+33hYkb/sTgOkbR3X7H5FxR0Btp89bbsE6h6jdoRX a4JLWw/2OYyhzb3voLdUjk8VaWNBpFwaVJACJPxNcDV6qjeX5VcX29mpVV65lU7Jeu2LRt/r0+NpU kOa+gVC9jip7eV3oKkwYKMZTZBrB/gg==; 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 1ftW15-0005Oi-Pd for patchwork-linux-mediatek@patchwork.kernel.org; Sat, 25 Aug 2018 10:42:03 +0000 Received: from mail-wr1-f66.google.com ([209.85.221.66]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1ftW0O-0004z5-Ah for linux-mediatek@lists.infradead.org; Sat, 25 Aug 2018 10:41:26 +0000 Received: by mail-wr1-f66.google.com with SMTP id g33-v6so9452445wrd.1 for ; Sat, 25 Aug 2018 03:41:20 -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=PMtvMx4oYmIrd4qh0lbAJFdbUY2wLqCNWB/IW0VFeUI=; b=mie5AMoCQaR2Cz5l6rJFBFnATuE9OeK+pn3RUHV1Dg0y1uHs5b69bfP1sHc2xG/UAQ S4gElUYEEl232Ib61o//Gl683r/bMUcg6npingMvlnjzvLXXZaS4aepcTCGSeZl8QKer tnhMVbE19d8g+hZIJke0GIn/ZQc0nHAzCE9mRbZU6BRcmHl0L52EXl++Ai9BYSpz1ofP ewu/VLluAXSdGs5ccgjatWxa8AheDOeqURUWSgWtwN2iQW1NYLx/14LK8hY1v23Vcz1n ppelPtU87Y1ciJzFM+oTfSimUvgl+VpbdvThU67Fws/PbHtxqukFN57ePqf2Nt+iSBez PiVg== X-Gm-Message-State: APzg51BC6slEmEm5NdZ2PabAmUhMiyF/JSxGG1smy3Z55UujxrouZrdO iKbbOPSk/9OsNQJaRwlG7DNQxw== X-Google-Smtp-Source: ANB0VdZEaxUA2IGoXYgUYFwd3/E42nmslMjcGV7NI6EuVopOG+wh1XR1Iyw4Ucs9DCSB0EgeZ1bIYQ== X-Received: by 2002:adf:9ccb:: with SMTP id h11-v6mr3517147wre.11.1535193678741; Sat, 25 Aug 2018 03:41:18 -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.17 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 25 Aug 2018 03:41:17 -0700 (PDT) From: Lorenzo Bianconi To: nbd@nbd.name Subject: [PATCH 15/16] mt76x0: use mt76u_mcu_fw_send_data for fw uploading Date: Sat, 25 Aug 2018 12:40:55 +0200 Message-Id: <20180825104056.9130-16-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_034120_429964_EEFDBB72 X-CRM114-Status: GOOD ( 11.92 ) 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 Use mt76u_mcu_fw_send_data utility routine for firmware uploading and remove unused __mt76x0_dma_fw/mt76x0_dma_fw functions Signed-off-by: Lorenzo Bianconi --- .../net/wireless/mediatek/mt76/mt76x0/mcu.c | 88 ++----------------- 1 file changed, 6 insertions(+), 82 deletions(-) diff --git a/drivers/net/wireless/mediatek/mt76/mt76x0/mcu.c b/drivers/net/wireless/mediatek/mt76/mt76x0/mcu.c index d49557834658..0a0deaf1c65d 100644 --- a/drivers/net/wireless/mediatek/mt76/mt76x0/mcu.c +++ b/drivers/net/wireless/mediatek/mt76/mt76x0/mcu.c @@ -239,83 +239,9 @@ struct mt76_fw { u8 ilm[]; }; -static int __mt76x0_dma_fw(struct mt76x0_dev *dev, - const struct mt76x0_dma_buf *dma_buf, - const void *data, u32 len, u32 dst_addr) -{ - DECLARE_COMPLETION_ONSTACK(cmpl); - struct mt76x0_dma_buf buf = *dma_buf; /* we need to fake length */ - __le32 reg; - u32 val; - int ret; - - reg = cpu_to_le32(FIELD_PREP(MT_TXD_INFO_TYPE, DMA_COMMAND) | - FIELD_PREP(MT_TXD_INFO_D_PORT, CPU_TX_PORT) | - FIELD_PREP(MT_TXD_INFO_LEN, len)); - memcpy(buf.buf, ®, sizeof(reg)); - memcpy(buf.buf + sizeof(reg), data, len); - memset(buf.buf + sizeof(reg) + len, 0, 8); - - mt76u_single_wr(&dev->mt76, MT_VEND_WRITE_FCE, MT_FCE_DMA_ADDR, - dst_addr); - - len = roundup(len, 4); - mt76u_single_wr(&dev->mt76, MT_VEND_WRITE_FCE, MT_FCE_DMA_LEN, - len << 16); - - buf.len = MT_DMA_HDR_LEN + len + 4; - ret = mt76x0_usb_submit_buf(dev, USB_DIR_OUT, MT_EP_OUT_INBAND_CMD, - &buf, GFP_KERNEL, - mt76u_mcu_complete_urb, &cmpl); - if (ret) - return ret; - - if (!wait_for_completion_timeout(&cmpl, msecs_to_jiffies(1000))) { - dev_err(dev->mt76.dev, "Error: firmware upload timed out\n"); - usb_kill_urb(buf.urb); - return -ETIMEDOUT; - } - if (mt76x0_urb_has_error(buf.urb)) { - dev_err(dev->mt76.dev, "Error: firmware upload urb failed:%d\n", - buf.urb->status); - return buf.urb->status; - } - - val = mt76_rr(dev, MT_TX_CPU_FROM_FCE_CPU_DESC_IDX); - val++; - mt76_wr(dev, MT_TX_CPU_FROM_FCE_CPU_DESC_IDX, val); - - msleep(5); - - return 0; -} - -static int -mt76x0_dma_fw(struct mt76x0_dev *dev, struct mt76x0_dma_buf *dma_buf, - const void *data, int len, u32 dst_addr) -{ - int n, ret; - - if (len == 0) - return 0; - - n = min(MCU_FW_URB_MAX_PAYLOAD, len); - ret = __mt76x0_dma_fw(dev, dma_buf, data, n, dst_addr); - if (ret) - return ret; - -#if 0 - if (!mt76_poll_msec(dev, MT_MCU_COM_REG1, BIT(31), BIT(31), 500)) - return -ETIMEDOUT; -#endif - - return mt76x0_dma_fw(dev, dma_buf, data + n, len - n, dst_addr + n); -} - static int mt76x0_upload_firmware(struct mt76x0_dev *dev, const struct mt76_fw *fw) { - struct mt76x0_dma_buf dma_buf; void *ivb; u32 ilm_len, dlm_len; int i, ret; @@ -323,22 +249,21 @@ mt76x0_upload_firmware(struct mt76x0_dev *dev, const struct mt76_fw *fw) ivb = kmemdup(fw->ivb, sizeof(fw->ivb), GFP_KERNEL); if (!ivb) return -ENOMEM; - if (mt76x0_usb_alloc_buf(dev, MCU_FW_URB_SIZE, &dma_buf)) { - ret = -ENOMEM; - goto error; - } ilm_len = le32_to_cpu(fw->hdr.ilm_len) - sizeof(fw->ivb); dev_dbg(dev->mt76.dev, "loading FW - ILM %u + IVB %zu\n", ilm_len, sizeof(fw->ivb)); - ret = mt76x0_dma_fw(dev, &dma_buf, fw->ilm, ilm_len, sizeof(fw->ivb)); + ret = mt76u_mcu_fw_send_data(&dev->mt76, fw->ilm, ilm_len, + MCU_FW_URB_MAX_PAYLOAD, + sizeof(fw->ivb)); if (ret) goto error; dlm_len = le32_to_cpu(fw->hdr.dlm_len); dev_dbg(dev->mt76.dev, "loading FW - DLM %u\n", dlm_len); - ret = mt76x0_dma_fw(dev, &dma_buf, fw->ilm + ilm_len, - dlm_len, MT_MCU_DLM_OFFSET); + ret = mt76u_mcu_fw_send_data(&dev->mt76, fw->ilm + ilm_len, + dlm_len, MCU_FW_URB_MAX_PAYLOAD, + MT_MCU_DLM_OFFSET); if (ret) goto error; @@ -359,7 +284,6 @@ mt76x0_upload_firmware(struct mt76x0_dev *dev, const struct mt76_fw *fw) dev_dbg(dev->mt76.dev, "Firmware running!\n"); error: kfree(ivb); - mt76x0_usb_free_buf(dev, &dma_buf); return ret; }