linux-usb.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Hayes Wang <hayeswang@realtek.com>
To: <netdev@vger.kernel.org>
Cc: <nic_swsd@realtek.com>, <linux-kernel@vger.kernel.org>,
	<linux-usb@vger.kernel.org>, Hayes Wang <hayeswang@realtek.com>
Subject: [PATCH net-next 3/5] r8152: use alloc_pages for rx buffer
Date: Tue, 6 Aug 2019 19:18:02 +0800	[thread overview]
Message-ID: <1394712342-15778-292-albertk@realtek.com> (raw)
In-Reply-To: <1394712342-15778-289-albertk@realtek.com>

Replace kmalloc_node() with alloc_pages() for rx buffer.

Signed-off-by: Hayes Wang <hayeswang@realtek.com>
---
 drivers/net/usb/r8152.c | 31 +++++++++++--------------------
 1 file changed, 11 insertions(+), 20 deletions(-)

diff --git a/drivers/net/usb/r8152.c b/drivers/net/usb/r8152.c
index 44d832ceb516..401e56112365 100644
--- a/drivers/net/usb/r8152.c
+++ b/drivers/net/usb/r8152.c
@@ -698,8 +698,8 @@ struct rx_agg {
 	struct list_head list, info_list;
 	struct urb *urb;
 	struct r8152 *context;
+	struct page *page;
 	void *buffer;
-	void *head;
 };
 
 struct tx_agg {
@@ -1476,7 +1476,7 @@ static void free_rx_agg(struct r8152 *tp, struct rx_agg *agg)
 	list_del(&agg->info_list);
 
 	usb_free_urb(agg->urb);
-	kfree(agg->buffer);
+	__free_pages(agg->page, get_order(tp->rx_buf_sz));
 	kfree(agg);
 
 	atomic_dec(&tp->rx_count);
@@ -1487,26 +1487,17 @@ static struct rx_agg *alloc_rx_agg(struct r8152 *tp, gfp_t mflags)
 	struct net_device *netdev = tp->netdev;
 	int node = netdev->dev.parent ? dev_to_node(netdev->dev.parent) : -1;
 	struct rx_agg *rx_agg;
+	unsigned int order = get_order(tp->rx_buf_sz);
 
 	rx_agg = kmalloc_node(sizeof(*rx_agg), mflags, node);
 	if (rx_agg) {
 		unsigned long flags;
-		u8 *buf;
 
-		buf = kmalloc_node(tp->rx_buf_sz, mflags, node);
-		if (!buf)
+		rx_agg->page = alloc_pages(mflags, order);
+		if (!rx_agg->page)
 			goto free_rx;
 
-		if (buf != rx_agg_align(buf)) {
-			kfree(buf);
-			buf = kmalloc_node(tp->rx_buf_sz + RX_ALIGN, mflags,
-					   node);
-			if (!buf)
-				goto free_rx;
-		}
-
-		rx_agg->buffer = buf;
-		rx_agg->head = rx_agg_align(buf);
+		rx_agg->buffer = page_address(rx_agg->page);
 
 		rx_agg->urb = usb_alloc_urb(0, mflags);
 		if (!rx_agg->urb)
@@ -1526,7 +1517,7 @@ static struct rx_agg *alloc_rx_agg(struct r8152 *tp, gfp_t mflags)
 	return rx_agg;
 
 free_buf:
-	kfree(rx_agg->buffer);
+	__free_pages(rx_agg->page, order);
 free_rx:
 	kfree(rx_agg);
 	return NULL;
@@ -2007,8 +1998,8 @@ static int rx_bottom(struct r8152 *tp, int budget)
 		if (urb->actual_length < ETH_ZLEN)
 			goto submit;
 
-		rx_desc = agg->head;
-		rx_data = agg->head;
+		rx_desc = agg->buffer;
+		rx_data = agg->buffer;
 		len_used += sizeof(struct rx_desc);
 
 		while (urb->actual_length > len_used) {
@@ -2055,7 +2046,7 @@ static int rx_bottom(struct r8152 *tp, int budget)
 find_next_rx:
 			rx_data = rx_agg_align(rx_data + pkt_len + ETH_FCS_LEN);
 			rx_desc = (struct rx_desc *)rx_data;
-			len_used = (int)(rx_data - (u8 *)agg->head);
+			len_used = (int)(rx_data - (u8 *)agg->buffer);
 			len_used += sizeof(struct rx_desc);
 		}
 
@@ -2166,7 +2157,7 @@ int r8152_submit_rx(struct r8152 *tp, struct rx_agg *agg, gfp_t mem_flags)
 		return 0;
 
 	usb_fill_bulk_urb(agg->urb, tp->udev, usb_rcvbulkpipe(tp->udev, 1),
-			  agg->head, tp->rx_buf_sz,
+			  agg->buffer, tp->rx_buf_sz,
 			  (usb_complete_t)read_bulk_callback, agg);
 
 	ret = usb_submit_urb(agg->urb, mem_flags);
-- 
2.21.0


  parent reply	other threads:[~2019-08-06 11:19 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-08-06 11:17 [PATCH net-next 0/5] RX improve Hayes Wang
2019-08-06 11:18 ` [PATCH net-next 1/5] r8152: separate the rx buffer size Hayes Wang
2019-08-06 11:18 ` [PATCH net-next 2/5] r8152: replace array with linking list for rx information Hayes Wang
2019-08-06 19:53   ` Jakub Kicinski
2019-08-06 21:40     ` Jakub Kicinski
2019-08-07  4:34     ` Hayes Wang
2019-08-07 18:21       ` Jakub Kicinski
2019-08-06 11:18 ` Hayes Wang [this message]
2019-08-06 11:18 ` [PATCH net-next 4/5] r8152: support skb_add_rx_frag Hayes Wang
2019-08-06 22:08   ` Jakub Kicinski
2019-08-07  4:34     ` Hayes Wang
2019-08-06 11:18 ` [PATCH net-next 5/5] r8152: change rx_frag_head_sz and rx_max_agg_num dynamically Hayes Wang
2019-08-06 22:10   ` Jakub Kicinski
2019-08-07  7:12     ` Hayes Wang
2019-08-07 12:43       ` Maciej Fijalkowski
2019-08-08  1:40         ` Hayes Wang
2019-08-08  8:52     ` Hayes Wang
2019-08-08 11:49       ` Maciej Fijalkowski
2019-08-08 12:16         ` Hayes Wang
2019-08-08 18:43           ` Jakub Kicinski
2019-08-09  3:38             ` Hayes Wang
2019-08-09  4:51               ` David Miller

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1394712342-15778-292-albertk@realtek.com \
    --to=hayeswang@realtek.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-usb@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=nic_swsd@realtek.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).