From patchwork Thu Jul 21 00:28:12 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Justin Chen X-Patchwork-Id: 593268 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 55FBBCCA489 for ; Thu, 21 Jul 2022 00:28:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230408AbiGUA2a (ORCPT ); Wed, 20 Jul 2022 20:28:30 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58780 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229662AbiGUA22 (ORCPT ); Wed, 20 Jul 2022 20:28:28 -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 C4B3E6249D; Wed, 20 Jul 2022 17:28:26 -0700 (PDT) Received: by mail-pj1-x102a.google.com with SMTP id gn24so101829pjb.3; Wed, 20 Jul 2022 17:28:26 -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=X25xQ/eqdmK1FpQIMyTlSMdRWqqjHgGU7AOQyMO4Q7Y=; b=XdzeWtmGbMj5aPdFyVbx/Ko+XFLd4JTyIhXkdh6Mla7VBVgVl/9bGg61+n1rbG+EZn jRVNsYRR48J0qpPAerz48/Uoof1oHFN+idbmSRB+dnJcsDrfr7budLSVvZV6jbpXL5Kn FyIAJ+YODRr1hAIM50Ld5cnbWc9GC5ps0WoxefrI0CSrCSKHJSj8ea3eMkHUWaPtvBh0 +001pDp0ZRTBKb6XW+h03ECYWfDkCbIN3TlmSIeieq5UiuD4qbuUVxqpSrz/rCnLZm6c xVTEELslrAzAExtrXbe0Llc1DffyK3AotDv7ie/Reluu5pIKK5RRxturEZIxQQXWD7/O coew== 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=X25xQ/eqdmK1FpQIMyTlSMdRWqqjHgGU7AOQyMO4Q7Y=; b=hd7KPZmQn3BI41jVaHVPu89FjjpKgPWUxBDDUGRWSd1jXjkK/4QOKJxDq7e7emeMVb zLBLcRj3Lo6mjWGc6RAka0mm87lykBbkk6yZ8uWut2hEY8VfdmYqYWZKVl9cHPOfD01R ncgQ1gykeJvmZUh0Xgo0Bd2ZlVLeGcaIWJhMSKlCiggirkc5xYNXUB39MX9R1/6/M4Ac E/Usbxmc6UQXXKBT7bSpB7zgw43IQyzqvuxariDmn7ENIKQUFFrG9UVUvXlK9twQH8Eo ww3s2KhyCpUmeKXiHxQ/gsqH3Jm7MHJWLRQ+1ik21NZGR5hNcg2iaXHoA+raBZea2t+X G9bA== X-Gm-Message-State: AJIora/I5SyhLB6GQa15UgCys6754mbwPmkhiXZp3p2M9iDC9hsagh3/ E4LvMAnXqIAhxVUHVch8lYk= X-Google-Smtp-Source: AGRyM1vlYU0Ke4QzjR05zN7yjqDmle+chzqh0f+WQ6gBNIaoqCkdCccLWulLdO12A8XTiy40EcggyQ== X-Received: by 2002:a17:90b:4a83:b0:1f2:2f3:9774 with SMTP id lp3-20020a17090b4a8300b001f202f39774mr8527795pjb.1.1658363306145; Wed, 20 Jul 2022 17:28:26 -0700 (PDT) Received: from stbirv-lnx-2.igp.broadcom.net ([192.19.223.252]) by smtp.gmail.com with ESMTPSA id m5-20020a170902db0500b0016bc4a6ce28sm163226plx.98.2022.07.20.17.28.24 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Wed, 20 Jul 2022 17:28:25 -0700 (PDT) From: justinpopo6@gmail.com To: davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, joalonsof@gmail.com, jesionowskigreg@gmail.com, jackychou@asix.com.tw, jannh@google.com, linux-usb@vger.kernel.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org Cc: f.fainelli@gmail.com, justin.chen@broadcom.com, Justin Chen Subject: [PATCH v2 1/5] net: usb: ax88179_178a: remove redundant init code Date: Wed, 20 Jul 2022 17:28:12 -0700 Message-Id: <1658363296-15734-2-git-send-email-justinpopo6@gmail.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1658363296-15734-1-git-send-email-justinpopo6@gmail.com> References: <1658363296-15734-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 | 85 ++---------------------------------------- 1 file changed, 4 insertions(+), 81 deletions(-) diff --git a/drivers/net/usb/ax88179_178a.c b/drivers/net/usb/ax88179_178a.c index ac2d400..b7098688 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; @@ -1322,47 +1324,12 @@ static void ax88179_get_mac_addr(struct usbnet *dev) 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 ethtool_eee eee_data; usbnet_get_endpoints(dev, intf); - tmp16 = (u16 *)buf; - tmp = (u8 *)buf; - 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 +1351,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 +1644,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 +1659,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 Thu Jul 21 00:28:13 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Justin Chen X-Patchwork-Id: 592400 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 6B344C433EF for ; Thu, 21 Jul 2022 00:28:34 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230490AbiGUA2d (ORCPT ); Wed, 20 Jul 2022 20:28:33 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58802 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229540AbiGUA2a (ORCPT ); Wed, 20 Jul 2022 20:28:30 -0400 Received: from mail-pj1-x1034.google.com (mail-pj1-x1034.google.com [IPv6:2607:f8b0:4864:20::1034]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 609965A88B; Wed, 20 Jul 2022 17:28:29 -0700 (PDT) Received: by mail-pj1-x1034.google.com with SMTP id l14-20020a17090a72ce00b001f20ed3c55dso3792014pjk.5; Wed, 20 Jul 2022 17:28:29 -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=8H9ysJYrnrWkyl8HVfuoBPlJRCyj5PxyA79wuhjjui8=; b=n2R+rVdULpdrk+CQ5xOS2lc2elRYHRgbY7kQe+t/DfTvfaFM2s+/tj7p5CUnb49w2I Km/1dRrZAuECCJRYFm8do5inqCqJADaOl9FlehwjAOOCK7/zaEeHtpICHjXhqJpSwk+S eMcfmGOQtDZxNroLJM/JTODP6DaOgZkoQ+wles8BJL3aCZBlz/BVrELk9v5qPjqwYPDq 5qF7LR0wXAr55mk+5qyBRt75Gsvp8IF5dpN2s9IhTGbnFIX58fmHjFY4OISWjbOyPmnU MCaNvJRu41v8iJcC4zNUSYm8R6lY0f5fftLICf3A2Yswu7kQkq41rlhKUzqMp+S0QlNq ILhw== 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=8H9ysJYrnrWkyl8HVfuoBPlJRCyj5PxyA79wuhjjui8=; b=qCZKXh8cD2mxCE0KOHqikhPMGiZs9HyO2N5tAowtbjWbKrPovPoByIi7lf/jS2R36W yHBsxCjy1orGHRswD3RjPdnBNQTTudpe6SRLFHjtsIN8ho19mCyX4yD0SPspzLq3CTK0 ws9LiRF1JWYy6uP59BiCan0oeHYvkKFyINMgPI35GXdR6w6Ckno+FRoJZBcUBsEWDAjS 0AOFMwTiOgVYSOSv1g6e5bySHE1X2ZV1DpRGv7Tk/OxyLkNXOxBvAwvURqZAS/7VlQat qovy0CrWUIXX/TLFRer/x506edPkv+Q3oLDKskWdiRxMDMEfhTZcbW24Sy+DXRaoN6hx 0z2g== X-Gm-Message-State: AJIora+smNgMH3BAZYG7EMEpqTxWPAJz9IhrjkgkbHpQhoSSPmbQeVdJ xKNM3HLgioWNpkZBIKH1yeY= X-Google-Smtp-Source: AGRyM1vGGlvuYS+BI01TfP8dEcG/bXsRdc1DfPZ9lsSHsbNRA27OTeMzCPVuZlBmBFBZKRb0sinvQw== X-Received: by 2002:a17:90a:ea04:b0:1f2:242d:e2af with SMTP id w4-20020a17090aea0400b001f2242de2afmr4531929pjy.45.1658363308716; Wed, 20 Jul 2022 17:28:28 -0700 (PDT) Received: from stbirv-lnx-2.igp.broadcom.net ([192.19.223.252]) by smtp.gmail.com with ESMTPSA id m5-20020a170902db0500b0016bc4a6ce28sm163226plx.98.2022.07.20.17.28.27 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Wed, 20 Jul 2022 17:28:28 -0700 (PDT) From: justinpopo6@gmail.com To: davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, joalonsof@gmail.com, jesionowskigreg@gmail.com, jackychou@asix.com.tw, jannh@google.com, linux-usb@vger.kernel.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org Cc: f.fainelli@gmail.com, justin.chen@broadcom.com, Justin Chen Subject: [PATCH v2 2/5] net: usb: ax88179_178a: clean up pm calls Date: Wed, 20 Jul 2022 17:28:13 -0700 Message-Id: <1658363296-15734-3-git-send-email-justinpopo6@gmail.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1658363296-15734-1-git-send-email-justinpopo6@gmail.com> References: <1658363296-15734-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 b7098688..c641fd4 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; @@ -1640,7 +1611,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 Thu Jul 21 00:28:14 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Justin Chen X-Patchwork-Id: 593267 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 ADBBFCCA489 for ; Thu, 21 Jul 2022 00:28:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231148AbiGUA2d (ORCPT ); Wed, 20 Jul 2022 20:28:33 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58824 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230470AbiGUA2c (ORCPT ); Wed, 20 Jul 2022 20:28:32 -0400 Received: from mail-pl1-x635.google.com (mail-pl1-x635.google.com [IPv6:2607:f8b0:4864:20::635]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A6F8362A4C; Wed, 20 Jul 2022 17:28:31 -0700 (PDT) Received: by mail-pl1-x635.google.com with SMTP id w7so294491ply.12; Wed, 20 Jul 2022 17:28: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=oYqwhUvuzOKnMbHAPG9U5QnaJ2YWw3cAfEUA2j4IMXU=; b=QKoH+8Q6OhWT+Tc75DidMLHVOSVR8+BVWbfRGuVGxGEQ5I15+ifRAgExh0v8b+ucRx qikNa45KYWXZCvq/FPrMeZSAltEXWoVxZ/cXgfSOO6SJmY5X3due06l9FOPD2BZq2cZ+ 6MhrR8x/1FJMPRIKj4MZYZ4xnDddLgKdHx/EIl0wJK8Y0JahRa6leXTImVlhWIiHa2EX Vytll/bZQDvLhUUNB050D0IlJhYXVDkmFnyBMNfcux7+UnkhrWRggGJXF14jLnxf/OEC 4tMkSvhqManVS3lLwfhIcknh75Fb38leJZw8r7N078FcOGi0EBSKG/3GfS3pN1cUqwx0 DKJw== 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=oYqwhUvuzOKnMbHAPG9U5QnaJ2YWw3cAfEUA2j4IMXU=; b=IzvrhnwalR32pFP0mTDQCLOae2IPyvXLxXUSxcfAkfc+AE3sADpQaybUfb4RVbrfS8 VzxdyQ3uj3KN5Su6USrGNF1Nh97x0ddGtrdhsPvGVsSv3Jrmql1AWn9lD9j0rOMoil9w RdB13i7v37ImvXtpco/LIj2tpUKLJWeZuB+ZGGFO4uhgzmNoJTHjPDX4BAnfs0Zi22UA kanjLk0VRkMpurv0rw6bCjvbLLi3Vz5TWY7RprjJViVXkbQhJSEY/1ZIF+vTcDlH+0cv 5/TaTxlRULcxChJ2L1KgYQSXZ2zyFAdQGtKNhf58/yCV/BeEpnSjA7mqyr26/pj3M5/j Ce6Q== X-Gm-Message-State: AJIora/vKEr50/VaU2Rll0UNRnskDmaOLMDOJvPbvDNjW8ay0DrWa5Eo mOIU/3dMicf4nJmSc0UsTqM= X-Google-Smtp-Source: AGRyM1uDkhKrq02BurmxhTD3i5UOSOUwa4q36ylI1ri0aBH14wKU8Dh+8mgEq+mzZ653I5hdO4tunQ== X-Received: by 2002:a17:90b:4a47:b0:1f0:3f92:8c80 with SMTP id lb7-20020a17090b4a4700b001f03f928c80mr8188906pjb.199.1658363311120; Wed, 20 Jul 2022 17:28:31 -0700 (PDT) Received: from stbirv-lnx-2.igp.broadcom.net ([192.19.223.252]) by smtp.gmail.com with ESMTPSA id m5-20020a170902db0500b0016bc4a6ce28sm163226plx.98.2022.07.20.17.28.29 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Wed, 20 Jul 2022 17:28:30 -0700 (PDT) From: justinpopo6@gmail.com To: davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, joalonsof@gmail.com, jesionowskigreg@gmail.com, jackychou@asix.com.tw, jannh@google.com, linux-usb@vger.kernel.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org Cc: f.fainelli@gmail.com, justin.chen@broadcom.com, Justin Chen Subject: [PATCH v2 3/5] net: usb: ax88179_178a: restore state on resume Date: Wed, 20 Jul 2022 17:28:14 -0700 Message-Id: <1658363296-15734-4-git-send-email-justinpopo6@gmail.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1658363296-15734-1-git-send-email-justinpopo6@gmail.com> References: <1658363296-15734-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 c641fd4..1cc388a 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 Thu Jul 21 00:28:15 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Justin Chen X-Patchwork-Id: 592399 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 4699ACCA483 for ; Thu, 21 Jul 2022 00:28:42 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231255AbiGUA2j (ORCPT ); Wed, 20 Jul 2022 20:28:39 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58874 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231163AbiGUA2f (ORCPT ); Wed, 20 Jul 2022 20:28:35 -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 F0C3974E08; Wed, 20 Jul 2022 17:28:33 -0700 (PDT) Received: by mail-pj1-x102a.google.com with SMTP id gn24so102051pjb.3; Wed, 20 Jul 2022 17:28:33 -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=rh9YWokngbonE7Snp74VlZyhTT2Pt7ct+I3KRd5dUQE=; b=d+MVuRSQtzLWRPUnPXnw6UNv/OhZrSgzUgTCv05PcDVsh6TbUsMgWNzVH531ZHsKOy cU3KsYJbb3GMbWNVbDcminHsn97+JfrdtnV8iAqXxcISombKkAj9inpvaopHQBHERLbG CpW2mTdUu2olN/uocdig05kDVY0vEIVLhZEtjgpJeYXQLNuq1Bzx2ZAguyePqNfJ1Fy5 EcGdLBQS1zYVq7w6tV/QbVI77YkjE2yrv/I2z2hPMZ5A2Lwv0gy8GEAlI0OpYUcBFr19 NrhwtGWT1tCUFnzq3zdhjXjC/4XVpav4IPpQ/MH+RPkMd3pJ1C5YpAejYOxS5G7vJOqo xUcQ== 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=rh9YWokngbonE7Snp74VlZyhTT2Pt7ct+I3KRd5dUQE=; b=excQj4/KVDASMN+r9OLVLKiW47O+Q/mUT1tFnDC66Z5vVTg1TnSgnJNhp1I6IcnFx4 RaIe1tMNlOyqCjQnKeId8bPblVkJHRYydS5ufwZaApsOH7FtMYOfgdf27vFT2i7qiweb gsakrINDAXyWdMuk4Y8PKTI+1ayEUF9VmPaQMZzIEBpNMghhtfbetaOBC0reUcGcpUQq jAZr364MFDkfNHIyren2qR1cpG+QBjg9+vrlcfe1Tz4TizE1oDoixbpRRDBKK3PsMMFD CCDuwmjFuyeFqg5j6fOJxnFYf2633zeK1EGdFE34w3b+MXN5RMWpJ3atBrfn1IVH0K5P qbfQ== X-Gm-Message-State: AJIora92uQ+6OwL49MJa2jPYJRkB3qNeZfM4Lv8dYtWk5yEqcROG2N37 vXrVKgZRg6KapJ3QJzc9kYnVIofuiKXnhQ== X-Google-Smtp-Source: AGRyM1uv74DHeaL90aLfCekYVnCS2WieF/E0TUifD06s4vTNabLjKJy/T6RgiMFbEmg+LucblMhhyA== X-Received: by 2002:a17:90b:3507:b0:1f2:1b74:11d1 with SMTP id ls7-20020a17090b350700b001f21b7411d1mr6812127pjb.99.1658363313506; Wed, 20 Jul 2022 17:28:33 -0700 (PDT) Received: from stbirv-lnx-2.igp.broadcom.net ([192.19.223.252]) by smtp.gmail.com with ESMTPSA id m5-20020a170902db0500b0016bc4a6ce28sm163226plx.98.2022.07.20.17.28.32 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Wed, 20 Jul 2022 17:28:33 -0700 (PDT) From: justinpopo6@gmail.com To: davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, joalonsof@gmail.com, jesionowskigreg@gmail.com, jackychou@asix.com.tw, jannh@google.com, linux-usb@vger.kernel.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org Cc: f.fainelli@gmail.com, justin.chen@broadcom.com, Justin Chen Subject: [PATCH v2 4/5] net: usb: ax88179_178a: move priv to driver_priv Date: Wed, 20 Jul 2022 17:28:15 -0700 Message-Id: <1658363296-15734-5-git-send-email-justinpopo6@gmail.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1658363296-15734-1-git-send-email-justinpopo6@gmail.com> References: <1658363296-15734-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 | 32 +++++++++++++++++++------------- 1 file changed, 19 insertions(+), 13 deletions(-) diff --git a/drivers/net/usb/ax88179_178a.c b/drivers/net/usb/ax88179_178a.c index 1cc388a..d0cd986 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; @@ -1270,11 +1269,15 @@ static void ax88179_get_mac_addr(struct usbnet *dev) static int ax88179_bind(struct usbnet *dev, struct usb_interface *intf) { - struct ax88179_data *ax179_data = (struct ax88179_data *)dev->data; + struct ax88179_data *ax179_data; usbnet_get_endpoints(dev, intf); - memset(ax179_data, 0, sizeof(*ax179_data)); + ax179_data = kzalloc(sizeof(*ax179_data), GFP_KERNEL); + if (!ax179_data) + return -ENOMEM; + + dev->driver_priv = ax179_data; dev->net->netdev_ops = &ax88179_netdev_ops; dev->net->ethtool_ops = &ax88179_ethtool_ops; @@ -1304,6 +1307,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 */ @@ -1316,6 +1320,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 @@ -1492,7 +1498,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; @@ -1567,7 +1573,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 Thu Jul 21 00:28:16 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Justin Chen X-Patchwork-Id: 593266 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 9E3DFC433EF for ; Thu, 21 Jul 2022 00:28:42 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231308AbiGUA2l (ORCPT ); Wed, 20 Jul 2022 20:28:41 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58970 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231268AbiGUA2i (ORCPT ); Wed, 20 Jul 2022 20:28:38 -0400 Received: from mail-pl1-x629.google.com (mail-pl1-x629.google.com [IPv6:2607:f8b0:4864:20::629]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CB3286249D; Wed, 20 Jul 2022 17:28:36 -0700 (PDT) Received: by mail-pl1-x629.google.com with SMTP id d7so306510plr.9; Wed, 20 Jul 2022 17:28:36 -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=qHyW/zQGeHxiV8yKl6wtD5EU59PXEqMR+w3eh+TCFyE=; b=SsuaZEcuN5do3+2MU1oonViR5MxpkAeiLETraeHDU+jUrOSJAu6J9p3xgNiIvqmDT+ ei/82Wrx/LydCV6FW9oOzc0Sq+Grkd2f0UUTm8kOTfKjPaCeaA8T0Budlm8Ox0c1AEdD SWCU6W5hUo48z1rnXDDrar+YJdt8Mpr+ZDst6Lhym/YPpZB1lflP+KZeoNKEwtnHC8zq USJsHDigua9pVKcCD03+0W1/Q84tK6B9zdcog+qRIXvJK/Viag4Dl4SyiNS1N/LhPEBz pXz9RGfTgr9K7puvvGOjPpgmIChyqy3s4cbt7cdPmlmjrqFxQwf5IAmlQhi5JuwWLOQK cfYQ== 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=qHyW/zQGeHxiV8yKl6wtD5EU59PXEqMR+w3eh+TCFyE=; b=Fs6lvrjGwahaCII5Xz2yel+ZKQ1ZXc68sfsjG+icOBUc6rruYBjtbEwz7uxSuW4HhB r+eyAqJzKhyV6Tr6ilY5XpNXpGqmKwPEvoz6T/hInNva8Gjt6yCk97HRAuajmemc2bne 9si9qRQcaTFqDFe0m9VJTCb4yV15Dwxz4l6Yl85HDqb2KVzyssHMYkR2ol3UNmFJpq7E 8tf0yJNMAhPx/+0zUpGJSCysRVyI5LdpcHN06fSJBi8B8ZsuK4X+V5FXL2r6y4a3OBhG jbHRTTh1oPi5D1fYsblc7qTfp5T4odS9T8uJiK0VbpP1MH/iTEmLokPpQkksxGNIpk5S 8t3A== X-Gm-Message-State: AJIora+NG7WV/PBV80F+yCFmHxkpvjmJdGOzciuohx7VpeSCtreDtuQ2 eQE72qleGMgfYwea6cf1nEI= X-Google-Smtp-Source: AGRyM1tQVpAMPxmkuQ++lKXbIMF1xWaC4zknVeGb01qhRv1EyhtY+pCvWVk+DkpuQji1WGd3qXg5FA== X-Received: by 2002:a17:902:c945:b0:16c:49c9:7932 with SMTP id i5-20020a170902c94500b0016c49c97932mr41447676pla.80.1658363315963; Wed, 20 Jul 2022 17:28:35 -0700 (PDT) Received: from stbirv-lnx-2.igp.broadcom.net ([192.19.223.252]) by smtp.gmail.com with ESMTPSA id m5-20020a170902db0500b0016bc4a6ce28sm163226plx.98.2022.07.20.17.28.34 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Wed, 20 Jul 2022 17:28:35 -0700 (PDT) From: justinpopo6@gmail.com To: davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, joalonsof@gmail.com, jesionowskigreg@gmail.com, jackychou@asix.com.tw, jannh@google.com, linux-usb@vger.kernel.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org Cc: f.fainelli@gmail.com, justin.chen@broadcom.com, Justin Chen Subject: [PATCH v2 5/5] net: usb: ax88179_178a: wol optimizations Date: Wed, 20 Jul 2022 17:28:16 -0700 Message-Id: <1658363296-15734-6-git-send-email-justinpopo6@gmail.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1658363296-15734-1-git-send-email-justinpopo6@gmail.com> References: <1658363296-15734-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 d0cd986..3b0e8f9 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; } @@ -1636,6 +1634,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;