From patchwork Mon Jul 18 23:58:05 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Justin Chen X-Patchwork-Id: 12921875 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 58735C433EF for ; Mon, 18 Jul 2022 23:58:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235785AbiGRX6b (ORCPT ); Mon, 18 Jul 2022 19:58:31 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34082 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235784AbiGRX62 (ORCPT ); Mon, 18 Jul 2022 19:58:28 -0400 Received: from mail-pf1-x436.google.com (mail-pf1-x436.google.com [IPv6:2607:f8b0:4864:20::436]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0FBE033A1C; Mon, 18 Jul 2022 16:58:25 -0700 (PDT) Received: by mail-pf1-x436.google.com with SMTP id 70so12083781pfx.1; Mon, 18 Jul 2022 16:58:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=pG0N4u96Y3Q7sKNcYzJoKZvufudR9Bye3mfkiP/vITk=; b=kJ+gr77ByQwmateTKMuk5p5k71vr62WdcAA9xkjmgtQwT0pzA5TuWcLBw2I2r0SgtV tCuxix6GMCpaTAcHlglVWo3owYpTI+KGSyVklEuFc4ZfanV2Xti2/ct8KnENCb1Zc7UJ WbyPHcUtLkSaYD3E1u2k+t04VLkc3gyA5ErJjkJvppNJGhDs/E+BFVZ7gXr0s0uc6KEM 3SmYg7Rrd9Y/knZynGCHF0qbYHbu81uRZC0RohxYWY0C9B951I++J44Mw3/vz/IDipjt 5Sto2nHgMwUZmGmRFD0k6jXsRflSTHPW+B3eBNM8si7seVBIOdFAPzW6LEzyV+h7JAZm wZgg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=pG0N4u96Y3Q7sKNcYzJoKZvufudR9Bye3mfkiP/vITk=; b=VlcgYEdAs0i7HoKVpnCnrXdWYKkLWrem01kPa6xLhxCrPc8JYFLZusnkxj65eZy08B qynA6xgA0Ww7ad9H8uZwEZIQZBjQOwixogDDGVbC94w48xYRB3Qr3/gLheM1ds9BBdpM IBmrcRUgCU3n0mTp9bPbAd3qUaYRZ3cd6GJ3VwnW5HHU9Ar0BLwnMv+NONjQWKffdG8v 3tUwkjLxsyvKOi6qswU4zB0yGSymL814I9kW0JpV3jmzAEoQWVwz//iaJVu/01kiZczE RQouqtOgbbx/Y0BCHJ6PzQQk2CVBQkDCwAkuHwSwAOkahR5RrRKSC4hfRw5vAtDOqSuO GwJA== X-Gm-Message-State: AJIora/DtR45355ykCdJVn4XR3GFa7pb2C37zfdZPXfr9C/vWzq6SDOQ ZXbkT5UasjPAs8gDhXYS5oERuv+EukE= X-Google-Smtp-Source: AGRyM1sqfDpJP4Btxd2ClzkJbM/K+hAKokSVRpfHaBA4mY9VWvGMXYEXTssJhvAIlzIQcvFu96cGAw== X-Received: by 2002:a63:2b84:0:b0:412:5277:99dc with SMTP id r126-20020a632b84000000b00412527799dcmr26165686pgr.208.1658188703826; Mon, 18 Jul 2022 16:58:23 -0700 (PDT) Received: from stbirv-lnx-2.igp.broadcom.net ([192.19.223.252]) by smtp.gmail.com with ESMTPSA id j20-20020a170902759400b00161ccdc172dsm10027067pll.300.2022.07.18.16.58.22 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Mon, 18 Jul 2022 16:58:23 -0700 (PDT) From: justinpopo6@gmail.com To: linux-kernel@vger.kernel.org, netdev@vger.kernel.org, linux-usb@vger.kernel.org, jannh@google.com, jackychou@asix.com.tw, jesionowskigreg@gmail.com, joalonsof@gmail.com, justinpopo6@gmail.com, pabeni@redhat.com, kuba@kernel.org, edumazet@google.com, davem@davemloft.net, f.fainelli@gmail.com Cc: justin.chen@broadcom.com Subject: [PATCH 1/5] net: usb: ax88179_178a: remove redundant init code Date: Mon, 18 Jul 2022 16:58:05 -0700 Message-Id: <1658188689-30846-2-git-send-email-justinpopo6@gmail.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1658188689-30846-1-git-send-email-justinpopo6@gmail.com> References: <1658188689-30846-1-git-send-email-justinpopo6@gmail.com> Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org From: Justin Chen Bind and reset are basically doing the same thing. Remove the duplicate code and have bind call into reset. Signed-off-by: Justin Chen --- drivers/net/usb/ax88179_178a.c | 79 +++--------------------------------------- 1 file changed, 4 insertions(+), 75 deletions(-) diff --git a/drivers/net/usb/ax88179_178a.c b/drivers/net/usb/ax88179_178a.c index ac2d400..e0de98c 100644 --- a/drivers/net/usb/ax88179_178a.c +++ b/drivers/net/usb/ax88179_178a.c @@ -164,6 +164,8 @@ #define GMII_PHY_PGSEL_PAGE3 0x0003 #define GMII_PHY_PGSEL_PAGE5 0x0005 +static int ax88179_reset(struct usbnet *dev); + struct ax88179_data { u8 eee_enabled; u8 eee_active; @@ -1326,7 +1328,6 @@ static int ax88179_bind(struct usbnet *dev, struct usb_interface *intf) u16 *tmp16; u8 *tmp; struct ax88179_data *ax179_data = (struct ax88179_data *)dev->data; - struct ethtool_eee eee_data; usbnet_get_endpoints(dev, intf); @@ -1335,34 +1336,6 @@ static int ax88179_bind(struct usbnet *dev, struct usb_interface *intf) memset(ax179_data, 0, sizeof(*ax179_data)); - /* Power up ethernet PHY */ - *tmp16 = 0; - ax88179_write_cmd(dev, AX_ACCESS_MAC, AX_PHYPWR_RSTCTL, 2, 2, tmp16); - *tmp16 = AX_PHYPWR_RSTCTL_IPRL; - ax88179_write_cmd(dev, AX_ACCESS_MAC, AX_PHYPWR_RSTCTL, 2, 2, tmp16); - msleep(200); - - *tmp = AX_CLK_SELECT_ACS | AX_CLK_SELECT_BCS; - ax88179_write_cmd(dev, AX_ACCESS_MAC, AX_CLK_SELECT, 1, 1, tmp); - msleep(100); - - /* Read MAC address from DTB or asix chip */ - ax88179_get_mac_addr(dev); - memcpy(dev->net->perm_addr, dev->net->dev_addr, ETH_ALEN); - - /* RX bulk configuration */ - memcpy(tmp, &AX88179_BULKIN_SIZE[0], 5); - ax88179_write_cmd(dev, AX_ACCESS_MAC, AX_RX_BULKIN_QCTRL, 5, 5, tmp); - - dev->rx_urb_size = 1024 * 20; - - *tmp = 0x34; - ax88179_write_cmd(dev, AX_ACCESS_MAC, AX_PAUSE_WATERLVL_LOW, 1, 1, tmp); - - *tmp = 0x52; - ax88179_write_cmd(dev, AX_ACCESS_MAC, AX_PAUSE_WATERLVL_HIGH, - 1, 1, tmp); - dev->net->netdev_ops = &ax88179_netdev_ops; dev->net->ethtool_ops = &ax88179_ethtool_ops; dev->net->needed_headroom = 8; @@ -1384,46 +1357,7 @@ static int ax88179_bind(struct usbnet *dev, struct usb_interface *intf) netif_set_tso_max_size(dev->net, 16384); - /* Enable checksum offload */ - *tmp = AX_RXCOE_IP | AX_RXCOE_TCP | AX_RXCOE_UDP | - AX_RXCOE_TCPV6 | AX_RXCOE_UDPV6; - ax88179_write_cmd(dev, AX_ACCESS_MAC, AX_RXCOE_CTL, 1, 1, tmp); - - *tmp = AX_TXCOE_IP | AX_TXCOE_TCP | AX_TXCOE_UDP | - AX_TXCOE_TCPV6 | AX_TXCOE_UDPV6; - ax88179_write_cmd(dev, AX_ACCESS_MAC, AX_TXCOE_CTL, 1, 1, tmp); - - /* Configure RX control register => start operation */ - *tmp16 = AX_RX_CTL_DROPCRCERR | AX_RX_CTL_IPE | AX_RX_CTL_START | - AX_RX_CTL_AP | AX_RX_CTL_AMALL | AX_RX_CTL_AB; - ax88179_write_cmd(dev, AX_ACCESS_MAC, AX_RX_CTL, 2, 2, tmp16); - - *tmp = AX_MONITOR_MODE_PMETYPE | AX_MONITOR_MODE_PMEPOL | - AX_MONITOR_MODE_RWMP; - ax88179_write_cmd(dev, AX_ACCESS_MAC, AX_MONITOR_MOD, 1, 1, tmp); - - /* Configure default medium type => giga */ - *tmp16 = AX_MEDIUM_RECEIVE_EN | AX_MEDIUM_TXFLOW_CTRLEN | - AX_MEDIUM_RXFLOW_CTRLEN | AX_MEDIUM_FULL_DUPLEX | - AX_MEDIUM_GIGAMODE; - ax88179_write_cmd(dev, AX_ACCESS_MAC, AX_MEDIUM_STATUS_MODE, - 2, 2, tmp16); - - ax88179_led_setting(dev); - - ax179_data->eee_enabled = 0; - ax179_data->eee_active = 0; - - ax88179_disable_eee(dev); - - ax88179_ethtool_get_eee(dev, &eee_data); - eee_data.advertised = 0; - ax88179_ethtool_set_eee(dev, &eee_data); - - /* Restart autoneg */ - mii_nway_restart(&dev->mii); - - usbnet_link_change(dev, 0, 0); + ax88179_reset(dev); return 0; } @@ -1716,6 +1650,7 @@ static int ax88179_reset(struct usbnet *dev) /* Read MAC address from DTB or asix chip */ ax88179_get_mac_addr(dev); + memcpy(dev->net->perm_addr, dev->net->dev_addr, ETH_ALEN); /* RX bulk configuration */ memcpy(tmp, &AX88179_BULKIN_SIZE[0], 5); @@ -1730,12 +1665,6 @@ static int ax88179_reset(struct usbnet *dev) ax88179_write_cmd(dev, AX_ACCESS_MAC, AX_PAUSE_WATERLVL_HIGH, 1, 1, tmp); - dev->net->features |= NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM | - NETIF_F_RXCSUM; - - dev->net->hw_features |= NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM | - NETIF_F_RXCSUM; - /* Enable checksum offload */ *tmp = AX_RXCOE_IP | AX_RXCOE_TCP | AX_RXCOE_UDP | AX_RXCOE_TCPV6 | AX_RXCOE_UDPV6; From patchwork Mon Jul 18 23:58:06 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Justin Chen X-Patchwork-Id: 12921876 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 88644C43334 for ; Mon, 18 Jul 2022 23:58:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236092AbiGRX6m (ORCPT ); Mon, 18 Jul 2022 19:58:42 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34084 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235542AbiGRX6a (ORCPT ); Mon, 18 Jul 2022 19:58:30 -0400 Received: from mail-pg1-x533.google.com (mail-pg1-x533.google.com [IPv6:2607:f8b0:4864:20::533]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5FB2333A3F; Mon, 18 Jul 2022 16:58:28 -0700 (PDT) Received: by mail-pg1-x533.google.com with SMTP id s206so12046970pgs.3; Mon, 18 Jul 2022 16:58:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=dh9YpkxHkqlwFf+Eurq6TO8kGlIl0mkC3AKinE2qi70=; b=E1eqe3MIs1UMDmbZZUHK6ZeJdQnRvAMts2+sxA/CBC4FaTAtkMeLd5R5QAkc5RsRK/ R37g38d97aw6Ot6B4mdkubeFU4LZz1SMrr2/kUEV9Ir9e8XI/rXpAMLFyn9hR4DurZft 46HYFApeFe0OdJ3bTRsUtRlq3ymTBKusyiK+HxTn+bPSYsWyeOqRacn+GOhdBwx2jFSI w1X1uS0ldLNNcwJ/oUM1WmssCmosZ5PxxEYwrRQ+khIsqG0UhDpGP7MFLnpigxq6VTzX Klbrp32od4Z6W+6316WX83Ze/08owPlgZzlG2Q06DIIu0wqtYojloGSNjCPq4feX9Ffw +NgA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=dh9YpkxHkqlwFf+Eurq6TO8kGlIl0mkC3AKinE2qi70=; b=1P5iYSWtc80XiljduSpQKg71dD+QTdZy7nuJDn//vm7+F5dGQqp8HfIonQet0kVj0y Hq6GSglc4OHMkdrp9fOSeApojLWpWR7Q0EyjGi4ibB/PqicScIUUoBnOxnXBqSBzMJdq wgJ6NLY5jC2H+Sqt9Ep7/kL91jP2qMqGEUJoXfkglwcGvbsqzFKYAUjwL9n/fnkU0W1r qXAJRJphoSGWVRqBFivu7rs1z+ADf3L6urMQ3CZg2k44J15pO/ZM/i+lrTWDMlacFkK4 6VF93iTMQgkICbjxzxue+ndolkKILzQx5ncUNHJ492B/v01RXT2fTFOEY+VN+3jkVO/3 P7dg== X-Gm-Message-State: AJIora+RVCwkkER1szkfD4Gos0UgVVLCTnltmBtQcRd/zGk5rpZP6tlz 9YCEhvlnHbBDh3D4gPl9HTnqRyj9d7o= X-Google-Smtp-Source: AGRyM1t8xYu5jONOFyS5fFsmpI0nHTzKsLh8uTatSs2GETql2lqvCAftf1sPM0Q1yfROgLpHTWOp4w== X-Received: by 2002:a65:4685:0:b0:416:ce1:8d9b with SMTP id h5-20020a654685000000b004160ce18d9bmr25797233pgr.529.1658188707193; Mon, 18 Jul 2022 16:58:27 -0700 (PDT) Received: from stbirv-lnx-2.igp.broadcom.net ([192.19.223.252]) by smtp.gmail.com with ESMTPSA id j20-20020a170902759400b00161ccdc172dsm10027067pll.300.2022.07.18.16.58.25 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Mon, 18 Jul 2022 16:58:26 -0700 (PDT) From: justinpopo6@gmail.com To: linux-kernel@vger.kernel.org, netdev@vger.kernel.org, linux-usb@vger.kernel.org, jannh@google.com, jackychou@asix.com.tw, jesionowskigreg@gmail.com, joalonsof@gmail.com, justinpopo6@gmail.com, pabeni@redhat.com, kuba@kernel.org, edumazet@google.com, davem@davemloft.net, f.fainelli@gmail.com Cc: justin.chen@broadcom.com Subject: [PATCH 2/5] net: usb: ax88179_178a: clean up pm calls Date: Mon, 18 Jul 2022 16:58:06 -0700 Message-Id: <1658188689-30846-3-git-send-email-justinpopo6@gmail.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1658188689-30846-1-git-send-email-justinpopo6@gmail.com> References: <1658188689-30846-1-git-send-email-justinpopo6@gmail.com> Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org From: Justin Chen Instead of passing in_pm flags all over the place, use the private struct to handle in_pm mode. Signed-off-by: Justin Chen --- drivers/net/usb/ax88179_178a.c | 147 +++++++++++++++++------------------------ 1 file changed, 59 insertions(+), 88 deletions(-) diff --git a/drivers/net/usb/ax88179_178a.c b/drivers/net/usb/ax88179_178a.c index e0de98c..8ca12db 100644 --- a/drivers/net/usb/ax88179_178a.c +++ b/drivers/net/usb/ax88179_178a.c @@ -171,6 +171,7 @@ struct ax88179_data { u8 eee_active; u16 rxctl; u16 reserved; + u8 in_pm; }; struct ax88179_int_data { @@ -187,15 +188,29 @@ static const struct { {7, 0xcc, 0x4c, 0x18, 8}, }; +static void ax88179_set_pm_mode(struct usbnet *dev, bool pm_mode) +{ + struct ax88179_data *ax179_data = (struct ax88179_data *)dev->data; + + ax179_data->in_pm = pm_mode; +} + +static int ax88179_in_pm(struct usbnet *dev) +{ + struct ax88179_data *ax179_data = (struct ax88179_data *)dev->data; + + return ax179_data->in_pm; +} + static int __ax88179_read_cmd(struct usbnet *dev, u8 cmd, u16 value, u16 index, - u16 size, void *data, int in_pm) + u16 size, void *data) { int ret; int (*fn)(struct usbnet *, u8, u8, u16, u16, void *, u16); BUG_ON(!dev); - if (!in_pm) + if (!ax88179_in_pm(dev)) fn = usbnet_read_cmd; else fn = usbnet_read_cmd_nopm; @@ -211,14 +226,14 @@ static int __ax88179_read_cmd(struct usbnet *dev, u8 cmd, u16 value, u16 index, } static int __ax88179_write_cmd(struct usbnet *dev, u8 cmd, u16 value, u16 index, - u16 size, const void *data, int in_pm) + u16 size, const void *data) { int ret; int (*fn)(struct usbnet *, u8, u8, u16, u16, const void *, u16); BUG_ON(!dev); - if (!in_pm) + if (!ax88179_in_pm(dev)) fn = usbnet_write_cmd; else fn = usbnet_write_cmd_nopm; @@ -251,47 +266,6 @@ static void ax88179_write_cmd_async(struct usbnet *dev, u8 cmd, u16 value, } } -static int ax88179_read_cmd_nopm(struct usbnet *dev, u8 cmd, u16 value, - u16 index, u16 size, void *data) -{ - int ret; - - if (2 == size) { - u16 buf; - ret = __ax88179_read_cmd(dev, cmd, value, index, size, &buf, 1); - le16_to_cpus(&buf); - *((u16 *)data) = buf; - } else if (4 == size) { - u32 buf; - ret = __ax88179_read_cmd(dev, cmd, value, index, size, &buf, 1); - le32_to_cpus(&buf); - *((u32 *)data) = buf; - } else { - ret = __ax88179_read_cmd(dev, cmd, value, index, size, data, 1); - } - - return ret; -} - -static int ax88179_write_cmd_nopm(struct usbnet *dev, u8 cmd, u16 value, - u16 index, u16 size, const void *data) -{ - int ret; - - if (2 == size) { - u16 buf; - buf = *((u16 *)data); - cpu_to_le16s(&buf); - ret = __ax88179_write_cmd(dev, cmd, value, index, - size, &buf, 1); - } else { - ret = __ax88179_write_cmd(dev, cmd, value, index, - size, data, 1); - } - - return ret; -} - static int ax88179_read_cmd(struct usbnet *dev, u8 cmd, u16 value, u16 index, u16 size, void *data) { @@ -299,16 +273,16 @@ static int ax88179_read_cmd(struct usbnet *dev, u8 cmd, u16 value, u16 index, if (2 == size) { u16 buf = 0; - ret = __ax88179_read_cmd(dev, cmd, value, index, size, &buf, 0); + ret = __ax88179_read_cmd(dev, cmd, value, index, size, &buf); le16_to_cpus(&buf); *((u16 *)data) = buf; } else if (4 == size) { u32 buf = 0; - ret = __ax88179_read_cmd(dev, cmd, value, index, size, &buf, 0); + ret = __ax88179_read_cmd(dev, cmd, value, index, size, &buf); le32_to_cpus(&buf); *((u32 *)data) = buf; } else { - ret = __ax88179_read_cmd(dev, cmd, value, index, size, data, 0); + ret = __ax88179_read_cmd(dev, cmd, value, index, size, data); } return ret; @@ -324,10 +298,10 @@ static int ax88179_write_cmd(struct usbnet *dev, u8 cmd, u16 value, u16 index, buf = *((u16 *)data); cpu_to_le16s(&buf); ret = __ax88179_write_cmd(dev, cmd, value, index, - size, &buf, 0); + size, &buf); } else { ret = __ax88179_write_cmd(dev, cmd, value, index, - size, data, 0); + size, data); } return ret; @@ -430,52 +404,46 @@ static int ax88179_suspend(struct usb_interface *intf, pm_message_t message) u16 tmp16; u8 tmp8; + ax88179_set_pm_mode(dev, true); + usbnet_suspend(intf, message); /* Disable RX path */ - ax88179_read_cmd_nopm(dev, AX_ACCESS_MAC, AX_MEDIUM_STATUS_MODE, - 2, 2, &tmp16); + ax88179_read_cmd(dev, AX_ACCESS_MAC, AX_MEDIUM_STATUS_MODE, + 2, 2, &tmp16); tmp16 &= ~AX_MEDIUM_RECEIVE_EN; - ax88179_write_cmd_nopm(dev, AX_ACCESS_MAC, AX_MEDIUM_STATUS_MODE, - 2, 2, &tmp16); + ax88179_write_cmd(dev, AX_ACCESS_MAC, AX_MEDIUM_STATUS_MODE, + 2, 2, &tmp16); /* Force bulk-in zero length */ - ax88179_read_cmd_nopm(dev, AX_ACCESS_MAC, AX_PHYPWR_RSTCTL, - 2, 2, &tmp16); + ax88179_read_cmd(dev, AX_ACCESS_MAC, AX_PHYPWR_RSTCTL, + 2, 2, &tmp16); tmp16 |= AX_PHYPWR_RSTCTL_BZ | AX_PHYPWR_RSTCTL_IPRL; - ax88179_write_cmd_nopm(dev, AX_ACCESS_MAC, AX_PHYPWR_RSTCTL, - 2, 2, &tmp16); + ax88179_write_cmd(dev, AX_ACCESS_MAC, AX_PHYPWR_RSTCTL, + 2, 2, &tmp16); /* change clock */ tmp8 = 0; - ax88179_write_cmd_nopm(dev, AX_ACCESS_MAC, AX_CLK_SELECT, 1, 1, &tmp8); + ax88179_write_cmd(dev, AX_ACCESS_MAC, AX_CLK_SELECT, 1, 1, &tmp8); /* Configure RX control register => stop operation */ tmp16 = AX_RX_CTL_STOP; - ax88179_write_cmd_nopm(dev, AX_ACCESS_MAC, AX_RX_CTL, 2, 2, &tmp16); + ax88179_write_cmd(dev, AX_ACCESS_MAC, AX_RX_CTL, 2, 2, &tmp16); + + ax88179_set_pm_mode(dev, false); return 0; } /* This function is used to enable the autodetach function. */ /* This function is determined by offset 0x43 of EEPROM */ -static int ax88179_auto_detach(struct usbnet *dev, int in_pm) +static int ax88179_auto_detach(struct usbnet *dev) { u16 tmp16; u8 tmp8; - int (*fnr)(struct usbnet *, u8, u16, u16, u16, void *); - int (*fnw)(struct usbnet *, u8, u16, u16, u16, const void *); - - if (!in_pm) { - fnr = ax88179_read_cmd; - fnw = ax88179_write_cmd; - } else { - fnr = ax88179_read_cmd_nopm; - fnw = ax88179_write_cmd_nopm; - } - if (fnr(dev, AX_ACCESS_EEPROM, 0x43, 1, 2, &tmp16) < 0) + if (ax88179_read_cmd(dev, AX_ACCESS_EEPROM, 0x43, 1, 2, &tmp16) < 0) return 0; if ((tmp16 == 0xFFFF) || (!(tmp16 & 0x0100))) @@ -483,13 +451,13 @@ static int ax88179_auto_detach(struct usbnet *dev, int in_pm) /* Enable Auto Detach bit */ tmp8 = 0; - fnr(dev, AX_ACCESS_MAC, AX_CLK_SELECT, 1, 1, &tmp8); + ax88179_read_cmd(dev, AX_ACCESS_MAC, AX_CLK_SELECT, 1, 1, &tmp8); tmp8 |= AX_CLK_SELECT_ULR; - fnw(dev, AX_ACCESS_MAC, AX_CLK_SELECT, 1, 1, &tmp8); + ax88179_write_cmd(dev, AX_ACCESS_MAC, AX_CLK_SELECT, 1, 1, &tmp8); - fnr(dev, AX_ACCESS_MAC, AX_PHYPWR_RSTCTL, 2, 2, &tmp16); + ax88179_read_cmd(dev, AX_ACCESS_MAC, AX_PHYPWR_RSTCTL, 2, 2, &tmp16); tmp16 |= AX_PHYPWR_RSTCTL_AT; - fnw(dev, AX_ACCESS_MAC, AX_PHYPWR_RSTCTL, 2, 2, &tmp16); + ax88179_write_cmd(dev, AX_ACCESS_MAC, AX_PHYPWR_RSTCTL, 2, 2, &tmp16); return 0; } @@ -500,32 +468,36 @@ static int ax88179_resume(struct usb_interface *intf) u16 tmp16; u8 tmp8; + ax88179_set_pm_mode(dev, true); + usbnet_link_change(dev, 0, 0); /* Power up ethernet PHY */ tmp16 = 0; - ax88179_write_cmd_nopm(dev, AX_ACCESS_MAC, AX_PHYPWR_RSTCTL, - 2, 2, &tmp16); + ax88179_write_cmd(dev, AX_ACCESS_MAC, AX_PHYPWR_RSTCTL, + 2, 2, &tmp16); udelay(1000); tmp16 = AX_PHYPWR_RSTCTL_IPRL; - ax88179_write_cmd_nopm(dev, AX_ACCESS_MAC, AX_PHYPWR_RSTCTL, - 2, 2, &tmp16); + ax88179_write_cmd(dev, AX_ACCESS_MAC, AX_PHYPWR_RSTCTL, + 2, 2, &tmp16); msleep(200); /* Ethernet PHY Auto Detach*/ - ax88179_auto_detach(dev, 1); + ax88179_auto_detach(dev); /* Enable clock */ - ax88179_read_cmd_nopm(dev, AX_ACCESS_MAC, AX_CLK_SELECT, 1, 1, &tmp8); + ax88179_read_cmd(dev, AX_ACCESS_MAC, AX_CLK_SELECT, 1, 1, &tmp8); tmp8 |= AX_CLK_SELECT_ACS | AX_CLK_SELECT_BCS; - ax88179_write_cmd_nopm(dev, AX_ACCESS_MAC, AX_CLK_SELECT, 1, 1, &tmp8); + ax88179_write_cmd(dev, AX_ACCESS_MAC, AX_CLK_SELECT, 1, 1, &tmp8); msleep(100); /* Configure RX control register => start operation */ tmp16 = AX_RX_CTL_DROPCRCERR | AX_RX_CTL_IPE | AX_RX_CTL_START | AX_RX_CTL_AP | AX_RX_CTL_AMALL | AX_RX_CTL_AB; - ax88179_write_cmd_nopm(dev, AX_ACCESS_MAC, AX_RX_CTL, 2, 2, &tmp16); + ax88179_write_cmd(dev, AX_ACCESS_MAC, AX_RX_CTL, 2, 2, &tmp16); + + ax88179_set_pm_mode(dev, false); return usbnet_resume(intf); } @@ -601,8 +573,7 @@ ax88179_get_eeprom(struct net_device *net, struct ethtool_eeprom *eeprom, /* ax88179/178A returns 2 bytes from eeprom on read */ for (i = first_word; i <= last_word; i++) { ret = __ax88179_read_cmd(dev, AX_ACCESS_EEPROM, i, 1, 2, - &eeprom_buff[i - first_word], - 0); + &eeprom_buff[i - first_word]); if (ret < 0) { kfree(eeprom_buff); return -EIO; @@ -1071,7 +1042,7 @@ static int ax88179_check_eeprom(struct usbnet *dev) } while (buf & EEP_BUSY); __ax88179_read_cmd(dev, AX_ACCESS_MAC, AX_SROM_DATA_LOW, - 2, 2, &eeprom[i * 2], 0); + 2, 2, &eeprom[i * 2]); if ((i == 0) && (eeprom[0] == 0xFF)) return -EINVAL; @@ -1646,7 +1617,7 @@ static int ax88179_reset(struct usbnet *dev) msleep(100); /* Ethernet PHY Auto Detach*/ - ax88179_auto_detach(dev, 0); + ax88179_auto_detach(dev); /* Read MAC address from DTB or asix chip */ ax88179_get_mac_addr(dev); From patchwork Mon Jul 18 23:58:07 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Justin Chen X-Patchwork-Id: 12921877 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6D792C43334 for ; Mon, 18 Jul 2022 23:58:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236307AbiGRX6u (ORCPT ); Mon, 18 Jul 2022 19:58:50 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34314 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235787AbiGRX6d (ORCPT ); Mon, 18 Jul 2022 19:58:33 -0400 Received: from mail-pj1-x1032.google.com (mail-pj1-x1032.google.com [IPv6:2607:f8b0:4864:20::1032]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5EC0833A31; Mon, 18 Jul 2022 16:58:31 -0700 (PDT) Received: by mail-pj1-x1032.google.com with SMTP id s18-20020a17090aa11200b001f1e9e2438cso1312738pjp.2; Mon, 18 Jul 2022 16:58:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=3odTeuZgW9//om5ESxe8jjVhzsbpQ8xVlKfb9HhKoWg=; b=G78PbYgF3R5GWsuh20gQlO9CS5Ez7669OGnmIRkucuL1CS7z7c9hqqOHaoLzzB5hPx dIytDvfIR2F+6xggpLqCGuI8vTSqZvurxkyqxA9M4s2oKh1IATYAzbhqjNPkRUVul8Mj 9vDaeOX4NtlKe4RyB7FHQmiJeG0TwYrgnJTUtO++SeYhwi1OC7XzbR+yMw+WmrAzlYk0 5/tknDohZNk2XjFvC4wRQ/ySUzqn8dJkNBsDfF57nadL+biF+CJnMmFPNStgzcqSBlQQ 2TZkPSbptpAJ6a9VnaFlghiETveBiu3f4QXxubw5o34rBoqgNTPNviK1NwQzLcudyxmA wmGg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=3odTeuZgW9//om5ESxe8jjVhzsbpQ8xVlKfb9HhKoWg=; b=WxlNbvhqTemR1/l3G3/kU9kUzWGRbzY0QIfQmbW4u9lubrWTTe+hjjsY/pfWin/U4A ZsZhNi8LKU5Lt7tE+Q6WIY05z3mIPswT/EaZrGMMsEpfPwgDzbx9yuO2W5JjezwCUz0c DApdACh5GFiCpqvlff0mqWACPTR5i5rN7pi7I0TFelmqGaaVBcfthocHFN0hsXqucl+Z NqBxgtdiCcFUysY0YLm5Mrr24KQ1XrsDKjigOIcdJCEQh8gcDpQDpjB2sRB+wm7PiVV8 yOh7d/JcFCETsucfQ3dqCW/2zag+dXtJhXjnw31QOhRLX69S3c1jxN1UKIZ1YLiYxnIL FIfQ== X-Gm-Message-State: AJIora+RRmLymRl+D+r7O3xAOuXGTDo3IzKNTGwvxm5g1972tVeRb7om ztsjaOLqUW9J5Z/cuvwrZHlfw6xzlFk= X-Google-Smtp-Source: AGRyM1vUXBW6D46lFt62qLMlpQfbnFHLRnICpdbWZJ36IDQrz6R2xCuVqN8v/pJtB4kwzFkjuStK6Q== X-Received: by 2002:a17:902:f1cc:b0:16c:f039:94 with SMTP id e12-20020a170902f1cc00b0016cf0390094mr8037853plc.158.1658188709876; Mon, 18 Jul 2022 16:58:29 -0700 (PDT) Received: from stbirv-lnx-2.igp.broadcom.net ([192.19.223.252]) by smtp.gmail.com with ESMTPSA id j20-20020a170902759400b00161ccdc172dsm10027067pll.300.2022.07.18.16.58.28 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Mon, 18 Jul 2022 16:58:29 -0700 (PDT) From: justinpopo6@gmail.com To: linux-kernel@vger.kernel.org, netdev@vger.kernel.org, linux-usb@vger.kernel.org, jannh@google.com, jackychou@asix.com.tw, jesionowskigreg@gmail.com, joalonsof@gmail.com, justinpopo6@gmail.com, pabeni@redhat.com, kuba@kernel.org, edumazet@google.com, davem@davemloft.net, f.fainelli@gmail.com Cc: justin.chen@broadcom.com Subject: [PATCH 3/5] net: usb: ax88179_178a: restore state on resume Date: Mon, 18 Jul 2022 16:58:07 -0700 Message-Id: <1658188689-30846-4-git-send-email-justinpopo6@gmail.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1658188689-30846-1-git-send-email-justinpopo6@gmail.com> References: <1658188689-30846-1-git-send-email-justinpopo6@gmail.com> Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org From: Justin Chen The hardware state was only partially restored, which meant certain functionality was broken on resume. Do a full HW reset on resume to fix this. Signed-off-by: Justin Chen --- drivers/net/usb/ax88179_178a.c | 27 +-------------------------- 1 file changed, 1 insertion(+), 26 deletions(-) diff --git a/drivers/net/usb/ax88179_178a.c b/drivers/net/usb/ax88179_178a.c index 8ca12db..60742bb 100644 --- a/drivers/net/usb/ax88179_178a.c +++ b/drivers/net/usb/ax88179_178a.c @@ -465,37 +465,12 @@ static int ax88179_auto_detach(struct usbnet *dev) static int ax88179_resume(struct usb_interface *intf) { struct usbnet *dev = usb_get_intfdata(intf); - u16 tmp16; - u8 tmp8; ax88179_set_pm_mode(dev, true); usbnet_link_change(dev, 0, 0); - /* Power up ethernet PHY */ - tmp16 = 0; - ax88179_write_cmd(dev, AX_ACCESS_MAC, AX_PHYPWR_RSTCTL, - 2, 2, &tmp16); - udelay(1000); - - tmp16 = AX_PHYPWR_RSTCTL_IPRL; - ax88179_write_cmd(dev, AX_ACCESS_MAC, AX_PHYPWR_RSTCTL, - 2, 2, &tmp16); - msleep(200); - - /* Ethernet PHY Auto Detach*/ - ax88179_auto_detach(dev); - - /* Enable clock */ - ax88179_read_cmd(dev, AX_ACCESS_MAC, AX_CLK_SELECT, 1, 1, &tmp8); - tmp8 |= AX_CLK_SELECT_ACS | AX_CLK_SELECT_BCS; - ax88179_write_cmd(dev, AX_ACCESS_MAC, AX_CLK_SELECT, 1, 1, &tmp8); - msleep(100); - - /* Configure RX control register => start operation */ - tmp16 = AX_RX_CTL_DROPCRCERR | AX_RX_CTL_IPE | AX_RX_CTL_START | - AX_RX_CTL_AP | AX_RX_CTL_AMALL | AX_RX_CTL_AB; - ax88179_write_cmd(dev, AX_ACCESS_MAC, AX_RX_CTL, 2, 2, &tmp16); + ax88179_reset(dev); ax88179_set_pm_mode(dev, false); From patchwork Mon Jul 18 23:58:08 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Justin Chen X-Patchwork-Id: 12921878 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id F3925C43334 for ; Mon, 18 Jul 2022 23:58:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236439AbiGRX6z (ORCPT ); Mon, 18 Jul 2022 19:58:55 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34444 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235843AbiGRX6h (ORCPT ); Mon, 18 Jul 2022 19:58:37 -0400 Received: from mail-pj1-x102a.google.com (mail-pj1-x102a.google.com [IPv6:2607:f8b0:4864:20::102a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 89C3933A0F; Mon, 18 Jul 2022 16:58:34 -0700 (PDT) Received: by mail-pj1-x102a.google.com with SMTP id x18-20020a17090a8a9200b001ef83b332f5so19793497pjn.0; Mon, 18 Jul 2022 16:58:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=/pC+NXVrv1Rl0FFXYuHEZKAvudR99y67YQVF032RJmE=; b=TOxy2qVY7aLuiK8wYDzU8CfNpylGUJ3N9bKs/fCkt5weQ7GkIAlfnUh47QhBwEYgMf xZn7bWLLTYZgroVMs6A4U9LFjbMdfTAVGGFkeyxsHgOolzr6E1PDAMB3bauWxgBq8aiK JbAYJrsBiyK9kdz03UA3MIQu90xPHuFv02e7F/YMk25B8I4wFWWkHgjStnQAZ6+vkykK norF+jvoyzyVR1LWV9ZMGq98wYBvTeOmTzVB9n7ujpySJ4v2UycgodcJy+/ymYkgAVk4 /9vdc/gfLcpXDPDC7hgm6GfBxyrkPLebsk+oRb15n/LQ0+T2RiIW6e34NWMBRyxDYwv8 dktg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=/pC+NXVrv1Rl0FFXYuHEZKAvudR99y67YQVF032RJmE=; b=z2OICKTsXmOlGiby+NDxeee+sLhTJf9HKvtIgeP7SobgNfKfhFV0ddYQ8fj3a8CFdz lmfO1brDvmqu4W9AL/m7215a+7XUVfHUbkkNjkzjfs+fgcHLSJPO6y0S9h2Dqq1ViKcS qE5wsgAiMtQlF9KX7ncT8/OmXVipfxDb+F2Og2VdsvDtYbrdooIROHSDsfy4wgNIh2+E Geus3DJtVJLEe+Igg3e/1ZaB9f8ILdnElEX0TxZ/mh4XWhRyW+bTPHAQPfp+lGPZebCw OS/HC5ola0uOsge9U2yXF+itUCcX9V3BPefJL3UaugbEzTfC7+9K94Ipzelnz7w0r+ed oXig== X-Gm-Message-State: AJIora8TzsH0FL2wZcgAMTfy9zkReA5xF7NX7KG5TNAvfdjdwCg88/uO gUltCfCexy+J+eSn5SD1J+9JtwKST2M= X-Google-Smtp-Source: AGRyM1vdZnQUarWLdr0E7axzh1ZwxrEJHg8EOB2GSqpKiDWX1aEeggLVMzGMp42zUJCmjYgFM6fUAw== X-Received: by 2002:a17:902:ba91:b0:16c:6b8e:cd06 with SMTP id k17-20020a170902ba9100b0016c6b8ecd06mr30056876pls.33.1658188713399; Mon, 18 Jul 2022 16:58:33 -0700 (PDT) Received: from stbirv-lnx-2.igp.broadcom.net ([192.19.223.252]) by smtp.gmail.com with ESMTPSA id j20-20020a170902759400b00161ccdc172dsm10027067pll.300.2022.07.18.16.58.31 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Mon, 18 Jul 2022 16:58:32 -0700 (PDT) From: justinpopo6@gmail.com To: linux-kernel@vger.kernel.org, netdev@vger.kernel.org, linux-usb@vger.kernel.org, jannh@google.com, jackychou@asix.com.tw, jesionowskigreg@gmail.com, joalonsof@gmail.com, justinpopo6@gmail.com, pabeni@redhat.com, kuba@kernel.org, edumazet@google.com, davem@davemloft.net, f.fainelli@gmail.com Cc: justin.chen@broadcom.com Subject: [PATCH 4/5] net: usb: ax88179_178a: move priv to driver_priv Date: Mon, 18 Jul 2022 16:58:08 -0700 Message-Id: <1658188689-30846-5-git-send-email-justinpopo6@gmail.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1658188689-30846-1-git-send-email-justinpopo6@gmail.com> References: <1658188689-30846-1-git-send-email-justinpopo6@gmail.com> Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org From: Justin Chen We need more space to save WoL context. So lets allocate memory for ax88179_data instead of using struct usbnet data field which only supports 5 words. We continue to use the struct usbnet data field for multicast filters. However since we no longer have the private data stored there, we can shift it to the beginning. Signed-off-by: Justin Chen --- drivers/net/usb/ax88179_178a.c | 31 +++++++++++++++++++------------ 1 file changed, 19 insertions(+), 12 deletions(-) diff --git a/drivers/net/usb/ax88179_178a.c b/drivers/net/usb/ax88179_178a.c index 60742bb..cb7b89f 100644 --- a/drivers/net/usb/ax88179_178a.c +++ b/drivers/net/usb/ax88179_178a.c @@ -170,7 +170,6 @@ struct ax88179_data { u8 eee_enabled; u8 eee_active; u16 rxctl; - u16 reserved; u8 in_pm; }; @@ -190,14 +189,14 @@ static const struct { static void ax88179_set_pm_mode(struct usbnet *dev, bool pm_mode) { - struct ax88179_data *ax179_data = (struct ax88179_data *)dev->data; + struct ax88179_data *ax179_data = dev->driver_priv; ax179_data->in_pm = pm_mode; } static int ax88179_in_pm(struct usbnet *dev) { - struct ax88179_data *ax179_data = (struct ax88179_data *)dev->data; + struct ax88179_data *ax179_data = dev->driver_priv; return ax179_data->in_pm; } @@ -693,7 +692,7 @@ ax88179_ethtool_set_eee(struct usbnet *dev, struct ethtool_eee *data) static int ax88179_chk_eee(struct usbnet *dev) { struct ethtool_cmd ecmd = { .cmd = ETHTOOL_GSET }; - struct ax88179_data *priv = (struct ax88179_data *)dev->data; + struct ax88179_data *priv = dev->driver_priv; mii_ethtool_gset(&dev->mii, &ecmd); @@ -796,7 +795,7 @@ static void ax88179_enable_eee(struct usbnet *dev) static int ax88179_get_eee(struct net_device *net, struct ethtool_eee *edata) { struct usbnet *dev = netdev_priv(net); - struct ax88179_data *priv = (struct ax88179_data *)dev->data; + struct ax88179_data *priv = dev->driver_priv; edata->eee_enabled = priv->eee_enabled; edata->eee_active = priv->eee_active; @@ -807,7 +806,7 @@ static int ax88179_get_eee(struct net_device *net, struct ethtool_eee *edata) static int ax88179_set_eee(struct net_device *net, struct ethtool_eee *edata) { struct usbnet *dev = netdev_priv(net); - struct ax88179_data *priv = (struct ax88179_data *)dev->data; + struct ax88179_data *priv = dev->driver_priv; int ret; priv->eee_enabled = edata->eee_enabled; @@ -858,8 +857,8 @@ static const struct ethtool_ops ax88179_ethtool_ops = { static void ax88179_set_multicast(struct net_device *net) { struct usbnet *dev = netdev_priv(net); - struct ax88179_data *data = (struct ax88179_data *)dev->data; - u8 *m_filter = ((u8 *)dev->data) + 12; + struct ax88179_data *data = dev->driver_priv; + u8 *m_filter = ((u8 *)dev->data); data->rxctl = (AX_RX_CTL_START | AX_RX_CTL_AB | AX_RX_CTL_IPE); @@ -871,7 +870,7 @@ static void ax88179_set_multicast(struct net_device *net) } else if (netdev_mc_empty(net)) { /* just broadcast and directed */ } else { - /* We use the 20 byte dev->data for our 8 byte filter buffer + /* We use dev->data for our 8 byte filter buffer * to avoid allocating memory that is tricky to free later */ u32 crc_bits; @@ -1273,10 +1272,15 @@ static int ax88179_bind(struct usbnet *dev, struct usb_interface *intf) u8 buf[5]; u16 *tmp16; u8 *tmp; - struct ax88179_data *ax179_data = (struct ax88179_data *)dev->data; + struct ax88179_data *ax179_data; usbnet_get_endpoints(dev, intf); + ax179_data = kzalloc(sizeof(*ax179_data), GFP_KERNEL); + if (!ax179_data) + return -ENOMEM; + + dev->driver_priv = ax179_data; tmp16 = (u16 *)buf; tmp = (u8 *)buf; @@ -1310,6 +1314,7 @@ static int ax88179_bind(struct usbnet *dev, struct usb_interface *intf) static void ax88179_unbind(struct usbnet *dev, struct usb_interface *intf) { + struct ax88179_data *ax179_data = dev->driver_priv; u16 tmp16; /* Configure RX control register => stop operation */ @@ -1322,6 +1327,8 @@ static void ax88179_unbind(struct usbnet *dev, struct usb_interface *intf) /* Power down ethernet PHY */ tmp16 = 0; ax88179_write_cmd(dev, AX_ACCESS_MAC, AX_PHYPWR_RSTCTL, 2, 2, &tmp16); + + kfree(ax179_data); } static void @@ -1498,7 +1505,7 @@ ax88179_tx_fixup(struct usbnet *dev, struct sk_buff *skb, gfp_t flags) static int ax88179_link_reset(struct usbnet *dev) { - struct ax88179_data *ax179_data = (struct ax88179_data *)dev->data; + struct ax88179_data *ax179_data = dev->driver_priv; u8 tmp[5], link_sts; u16 mode, tmp16, delay = HZ / 10; u32 tmp32 = 0x40000000; @@ -1573,7 +1580,7 @@ static int ax88179_reset(struct usbnet *dev) u8 buf[5]; u16 *tmp16; u8 *tmp; - struct ax88179_data *ax179_data = (struct ax88179_data *)dev->data; + struct ax88179_data *ax179_data = dev->driver_priv; struct ethtool_eee eee_data; tmp16 = (u16 *)buf; From patchwork Mon Jul 18 23:58:09 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Justin Chen X-Patchwork-Id: 12921879 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id B53A9C433EF for ; Mon, 18 Jul 2022 23:59:10 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235542AbiGRX7J (ORCPT ); Mon, 18 Jul 2022 19:59:09 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34762 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236256AbiGRX6o (ORCPT ); Mon, 18 Jul 2022 19:58:44 -0400 Received: from mail-pj1-x1032.google.com (mail-pj1-x1032.google.com [IPv6:2607:f8b0:4864:20::1032]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AEDFF33E2B; Mon, 18 Jul 2022 16:58:37 -0700 (PDT) Received: by mail-pj1-x1032.google.com with SMTP id u7-20020a17090a3fc700b001f1efc76be2so977889pjm.1; Mon, 18 Jul 2022 16:58:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=kEb4hoOhi8CD/XwbMaUD4a9U4Omjx9rjALTJdXy2eYk=; b=T5W7pqEHmAyucMxobeaee1znTp86VUbOMIWRgD3+x5jIjgppq/RlguxsrqF5uxSRYT VpPjM5hBxcY4wY0D/EeghBLfW1K9svmx/jZAyqtD+AmLPn2Y5TwgdltU+lQ9v1Zio+BL xgTIj7SxZcub+VXqtLHFWGU2hXe0TX+5KCVbi0gqNng4CY6prFj83aWEzO+gGTk365No tiWYAMftoA0MPP9bQqemXQKBl2T9rXcTDoyPbFWc9+e+b2rNJe27iz19BXnBWuZWIwtj jxR52oXRL9e0Fb57yvPOKvDnunU0yS2UeXb/VsR6gX/tOUDqYgJjrn7cEDN9jELjuSyP ARFA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=kEb4hoOhi8CD/XwbMaUD4a9U4Omjx9rjALTJdXy2eYk=; b=wMD3pDR8+hPcACC5IfpMSn0sWBmklSKyYnFQSkl5M0p7K9hJnrbWXci5Qwhz4sWIa7 X5rHfTngXKJOLS3bMDMKo4Awvztr4wNlaAEcHf9AlzlbWikQPy71yHIgK4QwVXs1EF+o IAAlV2VoLn3kAC6uh4e6nlFvi/wpZe6429HDBqM6fx14vgnCO77ra7Xiar/M6Gk2I74y eMjO/RQlFV2YE4oTFAhTIyDab2wmxtXJ9+NSQfGhcqv3pDhjhQa8j1aLYiQ69AgMtOY8 p6rwoptrc3zEO7oMArH7AO4hq5leazXFD2hDEoii9HoSSK1UQ5jA8Ui4/NZWHyDvBgCh cUBA== X-Gm-Message-State: AJIora/PGyzhyoglRULCuwRFehYDGE661WPd7Fzy5c7v/HSD40zMk759 gg+nq5kXnVISOs50d2+ukNqiKQhIaUk= X-Google-Smtp-Source: AGRyM1t21sRhvd9eziBz44wABhsJy/t2Ze2/Aos/o9F+2g3bhjFZ+hN2v2iPqyTPzN/7Hs4me5/UTw== X-Received: by 2002:a17:902:d54b:b0:16b:f246:e32e with SMTP id z11-20020a170902d54b00b0016bf246e32emr30177743plf.4.1658188716191; Mon, 18 Jul 2022 16:58:36 -0700 (PDT) Received: from stbirv-lnx-2.igp.broadcom.net ([192.19.223.252]) by smtp.gmail.com with ESMTPSA id j20-20020a170902759400b00161ccdc172dsm10027067pll.300.2022.07.18.16.58.34 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Mon, 18 Jul 2022 16:58:35 -0700 (PDT) From: justinpopo6@gmail.com To: linux-kernel@vger.kernel.org, netdev@vger.kernel.org, linux-usb@vger.kernel.org, jannh@google.com, jackychou@asix.com.tw, jesionowskigreg@gmail.com, joalonsof@gmail.com, justinpopo6@gmail.com, pabeni@redhat.com, kuba@kernel.org, edumazet@google.com, davem@davemloft.net, f.fainelli@gmail.com Cc: justin.chen@broadcom.com Subject: [PATCH 5/5] net: usb: ax88179_178a: wol optimizations Date: Mon, 18 Jul 2022 16:58:09 -0700 Message-Id: <1658188689-30846-6-git-send-email-justinpopo6@gmail.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1658188689-30846-1-git-send-email-justinpopo6@gmail.com> References: <1658188689-30846-1-git-send-email-justinpopo6@gmail.com> Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org From: Justin Chen - Check if wol is supported on reset instead of everytime get_wol is called. - Save wolopts in private data instead of relying on the HW to save it. - Defer enabling WoL until suspend instead of enabling it everytime set_wol is called. Signed-off-by: Justin Chen --- drivers/net/usb/ax88179_178a.c | 52 +++++++++++++++++++++++------------------- 1 file changed, 28 insertions(+), 24 deletions(-) diff --git a/drivers/net/usb/ax88179_178a.c b/drivers/net/usb/ax88179_178a.c index cb7b89f..757c1d9b 100644 --- a/drivers/net/usb/ax88179_178a.c +++ b/drivers/net/usb/ax88179_178a.c @@ -171,6 +171,8 @@ struct ax88179_data { u8 eee_active; u16 rxctl; u8 in_pm; + u32 wol_supported; + u32 wolopts; }; struct ax88179_int_data { @@ -400,6 +402,7 @@ ax88179_phy_write_mmd_indirect(struct usbnet *dev, u16 prtad, u16 devad, static int ax88179_suspend(struct usb_interface *intf, pm_message_t message) { struct usbnet *dev = usb_get_intfdata(intf); + struct ax88179_data *priv = dev->driver_priv; u16 tmp16; u8 tmp8; @@ -407,6 +410,19 @@ static int ax88179_suspend(struct usb_interface *intf, pm_message_t message) usbnet_suspend(intf, message); + /* Enable WoL */ + if (priv->wolopts) { + ax88179_read_cmd(dev, AX_ACCESS_MAC, AX_MONITOR_MOD, + 1, 1, &tmp8); + if (priv->wolopts & WAKE_PHY) + tmp8 |= AX_MONITOR_MODE_RWLC; + if (priv->wolopts & WAKE_MAGIC) + tmp8 |= AX_MONITOR_MODE_RWMP; + + ax88179_write_cmd(dev, AX_ACCESS_MAC, AX_MONITOR_MOD, + 1, 1, &tmp8); + } + /* Disable RX path */ ax88179_read_cmd(dev, AX_ACCESS_MAC, AX_MEDIUM_STATUS_MODE, 2, 2, &tmp16); @@ -480,40 +496,22 @@ static void ax88179_get_wol(struct net_device *net, struct ethtool_wolinfo *wolinfo) { struct usbnet *dev = netdev_priv(net); - u8 opt; - - if (ax88179_read_cmd(dev, AX_ACCESS_MAC, AX_MONITOR_MOD, - 1, 1, &opt) < 0) { - wolinfo->supported = 0; - wolinfo->wolopts = 0; - return; - } + struct ax88179_data *priv = dev->driver_priv; - wolinfo->supported = WAKE_PHY | WAKE_MAGIC; - wolinfo->wolopts = 0; - if (opt & AX_MONITOR_MODE_RWLC) - wolinfo->wolopts |= WAKE_PHY; - if (opt & AX_MONITOR_MODE_RWMP) - wolinfo->wolopts |= WAKE_MAGIC; + wolinfo->supported = priv->wol_supported; + wolinfo->wolopts = priv->wolopts; } static int ax88179_set_wol(struct net_device *net, struct ethtool_wolinfo *wolinfo) { struct usbnet *dev = netdev_priv(net); - u8 opt = 0; + struct ax88179_data *priv = dev->driver_priv; - if (wolinfo->wolopts & ~(WAKE_PHY | WAKE_MAGIC)) + if (wolinfo->wolopts & ~(priv->wol_supported)) return -EINVAL; - if (wolinfo->wolopts & WAKE_PHY) - opt |= AX_MONITOR_MODE_RWLC; - if (wolinfo->wolopts & WAKE_MAGIC) - opt |= AX_MONITOR_MODE_RWMP; - - if (ax88179_write_cmd(dev, AX_ACCESS_MAC, AX_MONITOR_MOD, - 1, 1, &opt) < 0) - return -EINVAL; + priv->wolopts = wolinfo->wolopts; return 0; } @@ -1643,6 +1641,12 @@ static int ax88179_reset(struct usbnet *dev) ax88179_write_cmd(dev, AX_ACCESS_MAC, AX_MEDIUM_STATUS_MODE, 2, 2, tmp16); + /* Check if WoL is supported */ + ax179_data->wol_supported = 0; + if (ax88179_read_cmd(dev, AX_ACCESS_MAC, AX_MONITOR_MOD, + 1, 1, &tmp) > 0) + ax179_data->wol_supported = WAKE_MAGIC | WAKE_PHY; + ax88179_led_setting(dev); ax179_data->eee_enabled = 0;