Received: by 2002:a25:b794:0:0:0:0:0 with SMTP id n20csp3968014ybh; Tue, 6 Aug 2019 04:20:05 -0700 (PDT) X-Google-Smtp-Source: APXvYqzgeAAzORjYx5Vezyen4g8OYoIQ7IK+QyORKJwhXOQyri8Oc35C5Wg5TE+WutNwYJ8hsA3N X-Received: by 2002:a63:394:: with SMTP id 142mr2596992pgd.43.1565090405752; Tue, 06 Aug 2019 04:20:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1565090405; cv=none; d=google.com; s=arc-20160816; b=n0lIyvnWL4104uuyr+KW47SjrGyhtOx2bMTyHmvOIgZW3GtMW/5FuPjkVXDmMLEd1M czBge6gY4lRp8YONuqQTGOQ5GUi5GSpbE/tFU6bv+WK6KZVv5Z8Pw9ZtDYq/Fj+cN6s5 RzeIzYJwTJDWky+Ni7SqZpX5HJVBeEqkRqfLdeQosEY6ZzezHZYXp+eaUoP9njGoUkl3 maCiUDFHQlekj/vnNfmmGlpuDMMzNNcqg4QJl+pk0u5F044Q+wlh39KupCmE78xR0Ngp 9pqsmi+wEA6IJU2aAu8S8P/RrVGtyEiP3qZci5cz5Bmw2+1VbjSC7FQSnKFDKsq9UVJw j4VQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :authenticated-by; bh=atS4mK4Egemf5YA74OfF0eQmzq9Z5/isnNTc5MuUy7M=; b=C2AOHJ9dG3YxoQxonX3+mpkCS99vLASE/IHR8WN0eSd0xThylQfdjGHrQepSOM0fSr i8fAqyhDFzwEZRVmT/v4Ad2d1LadpsNkBr3WSfCiE0YRLjNvHdzbzrXCeqACYSGHg6zA gRxPdGUHKVhUGdXdEayAbXqf+bmXi6UzosDXCZFrM7E4Lhogmg4af2tbpaSs0Tle1eJm 3NUOZANGHiBuN6SaY9XQbCOro2G5gj52s16hBfnc9QHTwu9fFTRhuCFqnGwC+s+zwzbG sh95HkeuZJu3adfte23a5PW6N4zIhHdRbCky/v4ovY7S3NR3Eb4IbpGxXBqdxaDlBRd/ UkqA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id c1si41735134plr.405.2019.08.06.04.19.50; Tue, 06 Aug 2019 04:20:05 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732851AbfHFLTH (ORCPT + 99 others); Tue, 6 Aug 2019 07:19:07 -0400 Received: from rtits2.realtek.com ([211.75.126.72]:57490 "EHLO rtits2.realtek.com.tw" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732800AbfHFLTE (ORCPT ); Tue, 6 Aug 2019 07:19:04 -0400 Authenticated-By: X-SpamFilter-By: BOX Solutions SpamTrap 5.62 with qID x76BJ2iW023734, This message is accepted by code: ctloc85258 Received: from mail.realtek.com (RTITCASV01.realtek.com.tw[172.21.6.18]) by rtits2.realtek.com.tw (8.15.2/2.57/5.78) with ESMTPS id x76BJ2iW023734 (version=TLSv1 cipher=DHE-RSA-AES256-SHA bits=256 verify=NOT); Tue, 6 Aug 2019 19:19:02 +0800 Received: from fc30.localdomain (172.21.177.138) by RTITCASV01.realtek.com.tw (172.21.6.18) with Microsoft SMTP Server id 14.3.439.0; Tue, 6 Aug 2019 19:19:00 +0800 From: Hayes Wang To: CC: , , , Hayes Wang Subject: [PATCH net-next 5/5] r8152: change rx_frag_head_sz and rx_max_agg_num dynamically Date: Tue, 6 Aug 2019 19:18:04 +0800 Message-ID: <1394712342-15778-294-albertk@realtek.com> X-Mailer: Microsoft Office Outlook 11 In-Reply-To: <1394712342-15778-289-albertk@realtek.com> References: <1394712342-15778-289-albertk@realtek.com> MIME-Version: 1.0 Content-Transfer-Encoding: 7BIT Content-Type: text/plain; charset=US-ASCII X-Originating-IP: [172.21.177.138] Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Let rx_frag_head_sz and rx_max_agg_num could be modified dynamically through the sysfs. Signed-off-by: Hayes Wang --- drivers/net/usb/r8152.c | 119 ++++++++++++++++++++++++++++++++++++++-- 1 file changed, 115 insertions(+), 4 deletions(-) diff --git a/drivers/net/usb/r8152.c b/drivers/net/usb/r8152.c index 1615900c8592..0b4d439f603a 100644 --- a/drivers/net/usb/r8152.c +++ b/drivers/net/usb/r8152.c @@ -26,7 +26,7 @@ #include /* Information for net-next */ -#define NETNEXT_VERSION "09" +#define NETNEXT_VERSION "10" /* Information for net */ #define NET_VERSION "10" @@ -756,6 +756,9 @@ struct r8152 { u32 tx_qlen; u32 coalesce; u32 rx_buf_sz; + u32 rx_frag_head_sz; + u32 rx_max_agg_num; + u16 ocp_base; u16 speed; u8 *intr_buff; @@ -1992,7 +1995,7 @@ static struct rx_agg *rtl_get_free_rx(struct r8152 *tp, gfp_t mflags) spin_unlock_irqrestore(&tp->rx_lock, flags); - if (!agg_free && atomic_read(&tp->rx_count) < RTL8152_MAX_RX_AGG) + if (!agg_free && atomic_read(&tp->rx_count) < tp->rx_max_agg_num) agg_free = alloc_rx_agg(tp, mflags); return agg_free; @@ -2072,10 +2075,10 @@ static int rx_bottom(struct r8152 *tp, int budget) pkt_len -= ETH_FCS_LEN; rx_data += sizeof(struct rx_desc); - if (!agg_next || RTL8152_RXFG_HEADSZ > pkt_len) + if (!agg_next || tp->rx_frag_head_sz > pkt_len) rx_frag_head_sz = pkt_len; else - rx_frag_head_sz = RTL8152_RXFG_HEADSZ; + rx_frag_head_sz = tp->rx_frag_head_sz; skb = napi_alloc_skb(napi, rx_frag_head_sz); if (!skb) { @@ -5383,6 +5386,101 @@ static u8 rtl_get_version(struct usb_interface *intf) return version; } +static ssize_t rx_frag_head_sz_show(struct device *dev, + struct device_attribute *attr, char *buf) +{ + struct usb_interface *intf = to_usb_interface(dev); + struct r8152 *tp = usb_get_intfdata(intf); + + sprintf(buf, "%u\n", tp->rx_frag_head_sz); + + return strlen(buf); +} + +static ssize_t rx_frag_head_sz_store(struct device *dev, + struct device_attribute *attr, + const char *buf, size_t count) +{ + struct usb_interface *intf; + u32 rx_frag_head_sz; + struct r8152 *tp; + + intf = to_usb_interface(dev); + tp = usb_get_intfdata(intf); + + if (sscanf(buf, "%u\n", &rx_frag_head_sz) != 1) + return -EINVAL; + + if (rx_frag_head_sz < ETH_ZLEN) + return -EINVAL; + + if (test_bit(RTL8152_UNPLUG, &tp->flags)) + return -ENODEV; + + if (tp->rx_frag_head_sz != rx_frag_head_sz) { + napi_disable(&tp->napi); + tp->rx_frag_head_sz = rx_frag_head_sz; + napi_enable(&tp->napi); + } + + return count; +} + +static DEVICE_ATTR_RW(rx_frag_head_sz); + +static ssize_t rx_max_agg_num_show(struct device *dev, + struct device_attribute *attr, char *buf) +{ + struct usb_interface *intf = to_usb_interface(dev); + struct r8152 *tp = usb_get_intfdata(intf); + + sprintf(buf, "%u\n", tp->rx_max_agg_num); + + return strlen(buf); +} + +static ssize_t rx_max_agg_num_store(struct device *dev, + struct device_attribute *attr, + const char *buf, size_t count) +{ + struct usb_interface *intf; + u32 rx_max_agg_num; + struct r8152 *tp; + + intf = to_usb_interface(dev); + tp = usb_get_intfdata(intf); + + if (sscanf(buf, "%u\n", &rx_max_agg_num) != 1) + return -EINVAL; + + if (rx_max_agg_num < (RTL8152_MAX_RX * 2)) + return -EINVAL; + + if (test_bit(RTL8152_UNPLUG, &tp->flags)) + return -ENODEV; + + if (tp->rx_max_agg_num != rx_max_agg_num) { + napi_disable(&tp->napi); + tp->rx_max_agg_num = rx_max_agg_num; + napi_enable(&tp->napi); + } + + return count; +} + +static DEVICE_ATTR_RW(rx_max_agg_num); + +static struct attribute *rtk_adv_attrs[] = { + &dev_attr_rx_frag_head_sz.attr, + &dev_attr_rx_max_agg_num.attr, + NULL +}; + +static struct attribute_group rtk_adv_grp = { + .name = "rtl_adv", + .attrs = rtk_adv_attrs, +}; + static int rtl8152_probe(struct usb_interface *intf, const struct usb_device_id *id) { @@ -5487,6 +5585,9 @@ static int rtl8152_probe(struct usb_interface *intf, tp->speed = tp->mii.supports_gmii ? SPEED_1000 : SPEED_100; tp->duplex = DUPLEX_FULL; + tp->rx_frag_head_sz = RTL8152_RXFG_HEADSZ; + tp->rx_max_agg_num = RTL8152_MAX_RX_AGG; + intf->needs_remote_wakeup = 1; tp->rtl_ops.init(tp); @@ -5513,8 +5614,16 @@ static int rtl8152_probe(struct usb_interface *intf, netif_info(tp, probe, netdev, "%s\n", DRIVER_VERSION); + ret = sysfs_create_group(&intf->dev.kobj, &rtk_adv_grp); + if (ret < 0) { + netif_err(tp, probe, netdev, "creat rtk_adv_grp fail\n"); + goto out2; + } + return 0; +out2: + unregister_netdev(netdev); out1: netif_napi_del(&tp->napi); usb_set_intfdata(intf, NULL); @@ -5527,6 +5636,8 @@ static void rtl8152_disconnect(struct usb_interface *intf) { struct r8152 *tp = usb_get_intfdata(intf); + sysfs_remove_group(&intf->dev.kobj, &rtk_adv_grp); + usb_set_intfdata(intf, NULL); if (tp) { rtl_set_unplug(tp); -- 2.21.0