From patchwork Tue Jul 25 07:30:49 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hayes Wang X-Patchwork-Id: 125385 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:9010:0:b0:3e4:2afc:c1 with SMTP id l16csp2300639vqg; Tue, 25 Jul 2023 00:40:07 -0700 (PDT) X-Google-Smtp-Source: APBJJlFcTrguW4HsSodpc2btAMKbqjqZ4nUelw6U7dcovpr7X0v35DnPzfI3GgwM6nfCI9lr9676 X-Received: by 2002:a50:ee07:0:b0:521:a4bb:374f with SMTP id g7-20020a50ee07000000b00521a4bb374fmr10329504eds.5.1690270807510; Tue, 25 Jul 2023 00:40:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1690270807; cv=none; d=google.com; s=arc-20160816; b=lI8SvsPx/RjITMzP+xV+T1tx304QamlzBbN2nJglB/j3K8m+9EPv2B6A08tWM2aMw+ dqQjWJceaux4dN2UNqfv7ARTU+nLOGmGmxeU9juecqww3uLXN89J4dAJ3l43/XjynjIc EKDroSsThiCfBsbPfJ2jJ5WBZal7bA14nzatMKH/dKmtdxgZAdgKsP3Bdzi05sZne7LJ FOfQsedYqCkWascmL6Tgn9QJf8pjQ0nRK4uCPa7oNmvSfwhzb4dvWxPokveYXtj+1Sf+ 0PMneQ6UZ+mhD6jbVpVNb5cbCmYy4dId4388qhR6UuVQwQ/3/kOOqpLiJqkaPaFAABgS QSKg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :authenticated-by; bh=gEtAxB9sHpY7ACXQrhmr43Ol3McOKVEPRYKlKY6iju4=; fh=q9cLQonAfV/WNLezu8/aPFdhVajKMg7lBtPBnvx15GA=; b=A+sZjpR/gj/WbMEkqdvYOoajnfFluPhxSWFflIUX+3wsVCNzIbaafC/rCSfoCkToym QTSoBApwNPWHC7UFbAmxsSJ7tVsMdKmDln/xcO5kGQKkyV6l9qOGJRxdDVTR38LaHAMt cxnhgKa1Ak7ByB7e1Q8DGNK+Vv4yAv7FPttRGd3PvjA//zVAPqqbksqAjrgrqMATwTaH 5Q+7CGnFpEw2muf/CCqYrpNvUgzeJuOOFO1BYJl9c7iA/H0AfXuxxaFHev5EAXJfUhQA jZuIBHrokaY4D3HsHnLc3rxTCDpAgFswDbfUq88scXAhl4CtQXxWipK6h0PtlDqueAvX I60g== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id p25-20020aa7d319000000b005223ae98947si1833069edq.116.2023.07.25.00.39.43; Tue, 25 Jul 2023 00:40:07 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-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-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232536AbjGYHec (ORCPT + 99 others); Tue, 25 Jul 2023 03:34:32 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49870 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231825AbjGYHd6 (ORCPT ); Tue, 25 Jul 2023 03:33:58 -0400 Received: from rtits2.realtek.com.tw (rtits2.realtek.com [211.75.126.72]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 582BAE5; Tue, 25 Jul 2023 00:31:31 -0700 (PDT) Authenticated-By: X-SpamFilter-By: ArmorX SpamTrap 5.77 with qID 36P7V0No8028318, This message is accepted by code: ctloc85258 Received: from mail.realtek.com (rtexh36505.realtek.com.tw[172.21.6.25]) by rtits2.realtek.com.tw (8.15.2/2.81/5.90) with ESMTPS id 36P7V0No8028318 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128 verify=FAIL); Tue, 25 Jul 2023 15:31:00 +0800 Received: from RTEXMBS04.realtek.com.tw (172.21.6.97) by RTEXH36505.realtek.com.tw (172.21.6.25) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.32; Tue, 25 Jul 2023 15:31:11 +0800 Received: from fc38.localdomain (172.22.228.98) by RTEXMBS04.realtek.com.tw (172.21.6.97) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.7; Tue, 25 Jul 2023 15:31:10 +0800 From: Hayes Wang To: , CC: , , , , Hayes Wang Subject: [PATCH net-next 1/2] r8152: adjust generic_ocp_write function Date: Tue, 25 Jul 2023 15:30:49 +0800 Message-ID: <20230725073051.5150-415-nic_swsd@realtek.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230725073051.5150-414-nic_swsd@realtek.com> References: <20230725073051.5150-414-nic_swsd@realtek.com> MIME-Version: 1.0 X-Originating-IP: [172.22.228.98] X-ClientProxiedBy: RTEXH36506.realtek.com.tw (172.21.6.27) To RTEXMBS04.realtek.com.tw (172.21.6.97) X-KSE-ServerInfo: RTEXMBS04.realtek.com.tw, 9 X-KSE-AntiSpam-Interceptor-Info: fallback X-KSE-Antivirus-Interceptor-Info: fallback X-KSE-AntiSpam-Interceptor-Info: fallback X-KSE-ServerInfo: RTEXH36505.realtek.com.tw, 9 X-KSE-AntiSpam-Interceptor-Info: fallback X-KSE-Antivirus-Interceptor-Info: fallback X-KSE-AntiSpam-Interceptor-Info: fallback X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE 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-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1772377402106655084 X-GMAIL-MSGID: 1772377402106655084 Reduce the control transfer if all bytes of first or the last DWORD are writed. The original method is to split the control transfer into three parts (the first DWORD, middle continuous data, and the last DWORD). However, they could be combined if whole bytes of the first DWORD or last DWORD are writed. That is, the first DWORD or the last DWORD could be combined with the middle continuous data, if the byte_en is 0xff. Signed-off-by: Hayes Wang --- drivers/net/usb/r8152.c | 29 ++++++++++++++++++----------- 1 file changed, 18 insertions(+), 11 deletions(-) diff --git a/drivers/net/usb/r8152.c b/drivers/net/usb/r8152.c index 0738baa5b82e..f6578a99dbac 100644 --- a/drivers/net/usb/r8152.c +++ b/drivers/net/usb/r8152.c @@ -1314,16 +1314,24 @@ static int generic_ocp_write(struct r8152 *tp, u16 index, u16 byteen, byteen_end = byteen & BYTE_EN_END_MASK; byen = byteen_start | (byteen_start << 4); - ret = set_registers(tp, index, type | byen, 4, data); - if (ret < 0) - goto error1; - index += 4; - data += 4; - size -= 4; + /* Split the first DWORD if the byte_en is not 0xff */ + if (byen != BYTE_EN_DWORD) { + ret = set_registers(tp, index, type | byen, 4, data); + if (ret < 0) + goto error1; - if (size) { + index += 4; + data += 4; size -= 4; + } + + if (size) { + byen = byteen_end | (byteen_end >> 4); + + /* Split the last DWORD if the byte_en is not 0xff */ + if (byen != BYTE_EN_DWORD) + size -= 4; while (size) { if (size > limit) { @@ -1350,10 +1358,9 @@ static int generic_ocp_write(struct r8152 *tp, u16 index, u16 byteen, } } - byen = byteen_end | (byteen_end >> 4); - ret = set_registers(tp, index, type | byen, 4, data); - if (ret < 0) - goto error1; + /* Set the last DWORD */ + if (byen != BYTE_EN_DWORD) + ret = set_registers(tp, index, type | byen, 4, data); } error1: From patchwork Tue Jul 25 07:30:50 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hayes Wang X-Patchwork-Id: 125386 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:9010:0:b0:3e4:2afc:c1 with SMTP id l16csp2301023vqg; Tue, 25 Jul 2023 00:41:10 -0700 (PDT) X-Google-Smtp-Source: APBJJlGZveJynSXfYvPEVqQ1RrNo7nHXXF8/OP2KIpo/EK426uJOnFcYGxcMzAaRR7HJvdw0fNZ3 X-Received: by 2002:a17:90b:8d:b0:265:780e:5edc with SMTP id bb13-20020a17090b008d00b00265780e5edcmr2289744pjb.10.1690270870099; Tue, 25 Jul 2023 00:41:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1690270870; cv=none; d=google.com; s=arc-20160816; b=ifXVXm/WpTpiqElGgOY0qF7B4LQp7/E7IDd2LxNvPxHhjH+LBQQyy1fvGiI/Zj/lH2 RLJ41mWSECibRuhqLUYfMjOcsXrJwaU69bea7mDngIl3DLAyH1oKSFoxxKN+/4ihKsw9 8b79U2dLppKqf8S4+rcT7GnBqrFXa3gBI3xAQp1koGTckgJzec54u4xshOKsrXyAHV+x duIwpiT59yOiY37bdquayKbrbmQOp9uHxMi90iO2fLnKWk9TYvJqpVWFXTrYRhDXSoTq +PpFAdXVDtpYA/UxkZi5XF2unYnadg7mh3jVaYnrcgNboNZ2NOyXOXmH3MB5nuMDp5g+ TS0Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :authenticated-by; bh=hHMjBcTk6ReVvzMXfLI8jrYr1lUYm/Zn115Po1dS0m0=; fh=q9cLQonAfV/WNLezu8/aPFdhVajKMg7lBtPBnvx15GA=; b=prCb4Jb4K4U9G4Z0cQYuNkL8oCqYzdp0l+x3XtoLF4tqCTPF5Smnkd0liqP7o0x7lm TXqMAuC4eCjqfooNoPr3wEd05jT5Wr/SYQrhe8e+Pzd6dfl/hb+xA+EMn4gMImF9B5jU UgFV1tzSgvEpqmsw7MFSDdPzLVHAHBfIjLVRqSl9ofw13MkNwah6aS68Fgs81f79dWYw FxNKNYTWq605PJMTylLdCzxdbp8bpirLugbcP4Y+f+A6CxMx7PBsPLmVWDyJoXt/QSSm CXjK0PHAFjBvU13XxBVTxpnoQLtr4JSwIrtHrVZT/fFUa3OToo2VxsabD+Bk0gOiM0Vw 4CLg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id m15-20020a17090a158f00b0024769a264fcsi13072972pja.10.2023.07.25.00.40.55; Tue, 25 Jul 2023 00:41:10 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-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-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232165AbjGYHef (ORCPT + 99 others); Tue, 25 Jul 2023 03:34:35 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49728 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231840AbjGYHd6 (ORCPT ); Tue, 25 Jul 2023 03:33:58 -0400 Received: from rtits2.realtek.com.tw (rtits2.realtek.com [211.75.126.72]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id BD5DC18D; Tue, 25 Jul 2023 00:31:31 -0700 (PDT) Authenticated-By: X-SpamFilter-By: ArmorX SpamTrap 5.77 with qID 36P7V1Ni8028318, This message is accepted by code: ctloc85258 Received: from mail.realtek.com (rtexh36505.realtek.com.tw[172.21.6.25]) by rtits2.realtek.com.tw (8.15.2/2.81/5.90) with ESMTPS id 36P7V1Ni8028318 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128 verify=FAIL); Tue, 25 Jul 2023 15:31:01 +0800 Received: from RTEXMBS04.realtek.com.tw (172.21.6.97) by RTEXH36505.realtek.com.tw (172.21.6.25) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.32; Tue, 25 Jul 2023 15:31:12 +0800 Received: from fc38.localdomain (172.22.228.98) by RTEXMBS04.realtek.com.tw (172.21.6.97) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.7; Tue, 25 Jul 2023 15:31:10 +0800 From: Hayes Wang To: , CC: , , , , Hayes Wang Subject: [PATCH net-next 2/2] r8152: set bp in bulk Date: Tue, 25 Jul 2023 15:30:50 +0800 Message-ID: <20230725073051.5150-416-nic_swsd@realtek.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230725073051.5150-414-nic_swsd@realtek.com> References: <20230725073051.5150-414-nic_swsd@realtek.com> MIME-Version: 1.0 X-Originating-IP: [172.22.228.98] X-ClientProxiedBy: RTEXH36506.realtek.com.tw (172.21.6.27) To RTEXMBS04.realtek.com.tw (172.21.6.97) X-KSE-ServerInfo: RTEXMBS04.realtek.com.tw, 9 X-KSE-AntiSpam-Interceptor-Info: fallback X-KSE-Antivirus-Interceptor-Info: fallback X-KSE-AntiSpam-Interceptor-Info: fallback X-KSE-ServerInfo: RTEXH36505.realtek.com.tw, 9 X-KSE-AntiSpam-Interceptor-Info: fallback X-KSE-Antivirus-Interceptor-Info: fallback X-KSE-AntiSpam-Interceptor-Info: fallback X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE 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-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1772377467514812502 X-GMAIL-MSGID: 1772377467514812502 PLA_BP_0 ~ PLA_BP_15 (0xfc28 ~ 0xfc46) are continuous registers, so we could combine the control transfers into one control transfer. Signed-off-by: Hayes Wang --- drivers/net/usb/r8152.c | 75 ++++++++++++++--------------------------- 1 file changed, 25 insertions(+), 50 deletions(-) diff --git a/drivers/net/usb/r8152.c b/drivers/net/usb/r8152.c index f6578a99dbac..db9897e825b4 100644 --- a/drivers/net/usb/r8152.c +++ b/drivers/net/usb/r8152.c @@ -3978,29 +3978,10 @@ static void rtl_reset_bmu(struct r8152 *tp) /* Clear the bp to stop the firmware before loading a new one */ static void rtl_clear_bp(struct r8152 *tp, u16 type) { - switch (tp->version) { - case RTL_VER_01: - case RTL_VER_02: - case RTL_VER_07: - break; - case RTL_VER_03: - case RTL_VER_04: - case RTL_VER_05: - case RTL_VER_06: - ocp_write_byte(tp, type, PLA_BP_EN, 0); - break; - case RTL_VER_14: - ocp_write_word(tp, type, USB_BP2_EN, 0); + u16 bp[16] = {0}; + u16 bp_num; - ocp_write_word(tp, type, USB_BP_8, 0); - ocp_write_word(tp, type, USB_BP_9, 0); - ocp_write_word(tp, type, USB_BP_10, 0); - ocp_write_word(tp, type, USB_BP_11, 0); - ocp_write_word(tp, type, USB_BP_12, 0); - ocp_write_word(tp, type, USB_BP_13, 0); - ocp_write_word(tp, type, USB_BP_14, 0); - ocp_write_word(tp, type, USB_BP_15, 0); - break; + switch (tp->version) { case RTL_VER_08: case RTL_VER_09: case RTL_VER_10: @@ -4008,32 +3989,31 @@ static void rtl_clear_bp(struct r8152 *tp, u16 type) case RTL_VER_12: case RTL_VER_13: case RTL_VER_15: - default: if (type == MCU_TYPE_USB) { ocp_write_word(tp, MCU_TYPE_USB, USB_BP2_EN, 0); - - ocp_write_word(tp, MCU_TYPE_USB, USB_BP_8, 0); - ocp_write_word(tp, MCU_TYPE_USB, USB_BP_9, 0); - ocp_write_word(tp, MCU_TYPE_USB, USB_BP_10, 0); - ocp_write_word(tp, MCU_TYPE_USB, USB_BP_11, 0); - ocp_write_word(tp, MCU_TYPE_USB, USB_BP_12, 0); - ocp_write_word(tp, MCU_TYPE_USB, USB_BP_13, 0); - ocp_write_word(tp, MCU_TYPE_USB, USB_BP_14, 0); - ocp_write_word(tp, MCU_TYPE_USB, USB_BP_15, 0); - } else { - ocp_write_byte(tp, MCU_TYPE_PLA, PLA_BP_EN, 0); + bp_num = 16; + break; } + fallthrough; + case RTL_VER_03: + case RTL_VER_04: + case RTL_VER_05: + case RTL_VER_06: + ocp_write_byte(tp, type, PLA_BP_EN, 0); + fallthrough; + case RTL_VER_01: + case RTL_VER_02: + case RTL_VER_07: + bp_num = 8; + break; + case RTL_VER_14: + default: + ocp_write_word(tp, type, USB_BP2_EN, 0); + bp_num = 16; break; } - ocp_write_word(tp, type, PLA_BP_0, 0); - ocp_write_word(tp, type, PLA_BP_1, 0); - ocp_write_word(tp, type, PLA_BP_2, 0); - ocp_write_word(tp, type, PLA_BP_3, 0); - ocp_write_word(tp, type, PLA_BP_4, 0); - ocp_write_word(tp, type, PLA_BP_5, 0); - ocp_write_word(tp, type, PLA_BP_6, 0); - ocp_write_word(tp, type, PLA_BP_7, 0); + generic_ocp_write(tp, PLA_BP_0, BYTE_EN_DWORD, bp_num << 1, bp, type); /* wait 3 ms to make sure the firmware is stopped */ usleep_range(3000, 6000); @@ -5007,10 +4987,9 @@ static void rtl8152_fw_phy_nc_apply(struct r8152 *tp, struct fw_phy_nc *phy) static void rtl8152_fw_mac_apply(struct r8152 *tp, struct fw_mac *mac) { - u16 bp_en_addr, bp_index, type, bp_num, fw_ver_reg; + u16 bp_en_addr, type, fw_ver_reg; u32 length; u8 *data; - int i; switch (__le32_to_cpu(mac->blk_hdr.type)) { case RTL_FW_PLA: @@ -5052,12 +5031,8 @@ static void rtl8152_fw_mac_apply(struct r8152 *tp, struct fw_mac *mac) ocp_write_word(tp, type, __le16_to_cpu(mac->bp_ba_addr), __le16_to_cpu(mac->bp_ba_value)); - bp_index = __le16_to_cpu(mac->bp_start); - bp_num = __le16_to_cpu(mac->bp_num); - for (i = 0; i < bp_num; i++) { - ocp_write_word(tp, type, bp_index, __le16_to_cpu(mac->bp[i])); - bp_index += 2; - } + generic_ocp_write(tp, __le16_to_cpu(mac->bp_start), BYTE_EN_DWORD, + __le16_to_cpu(mac->bp_num) << 1, mac->bp, type); bp_en_addr = __le16_to_cpu(mac->bp_en_addr); if (bp_en_addr)