From: Geoff Levand <geoff@infradead.org>
To: netdev@vger.kernel.org, Jakub Kicinski <kuba@kernel.org>,
"David S. Miller" <davem@davemloft.net>,
Alexander Lobakin <alexandr.lobakin@intel.com>,
Alexander Duyck <alexander.duyck@gmail.com>,
Paolo Abeni <pabeni@redhat.com>
Subject: [PATCH net v6 1/2] net/ps3_gelic_net: Fix RX sk_buff length
Date: Sun, 26 Feb 2023 02:25:42 +0000 [thread overview]
Message-ID: <1bf36b8e08deb3d16fafde3e88ae7cd761e4e7b3.1677377639.git.geoff@infradead.org> (raw)
In-Reply-To: <cover.1677377639.git.geoff@infradead.org>
The Gelic Ethernet device needs to have the RX sk_buffs aligned to
GELIC_NET_RXBUF_ALIGN and the length of the RX sk_buffs must be a
multiple of GELIC_NET_RXBUF_ALIGN.
The current Gelic Ethernet driver was not allocating sk_buffs large
enough to allow for this alignment.
Fixes various randomly occurring runtime network errors.
Fixes: 02c1889166b4 ("ps3: gigabit ethernet driver for PS3, take3")
Signed-off-by: Geoff Levand <geoff@infradead.org>
---
drivers/net/ethernet/toshiba/ps3_gelic_net.c | 66 +++++++++++---------
drivers/net/ethernet/toshiba/ps3_gelic_net.h | 2 +-
2 files changed, 39 insertions(+), 29 deletions(-)
diff --git a/drivers/net/ethernet/toshiba/ps3_gelic_net.c b/drivers/net/ethernet/toshiba/ps3_gelic_net.c
index cf8de8a7a8a1..7e12e041acd3 100644
--- a/drivers/net/ethernet/toshiba/ps3_gelic_net.c
+++ b/drivers/net/ethernet/toshiba/ps3_gelic_net.c
@@ -365,51 +365,61 @@ static int gelic_card_init_chain(struct gelic_card *card,
*
* allocates a new rx skb, iommu-maps it and attaches it to the descriptor.
* Activate the descriptor state-wise
+ *
+ * Gelic RX sk_buffs must be aligned to GELIC_NET_RXBUF_ALIGN and the length
+ * must be a multiple of GELIC_NET_RXBUF_ALIGN.
*/
static int gelic_descr_prepare_rx(struct gelic_card *card,
struct gelic_descr *descr)
{
- int offset;
- unsigned int bufsize;
+ struct device *dev = ctodev(card);
+ void *napi_buff;
if (gelic_descr_get_status(descr) != GELIC_DESCR_DMA_NOT_IN_USE)
dev_info(ctodev(card), "%s: ERROR status\n", __func__);
- /* we need to round up the buffer size to a multiple of 128 */
- bufsize = ALIGN(GELIC_NET_MAX_MTU, GELIC_NET_RXBUF_ALIGN);
-
- /* and we need to have it 128 byte aligned, therefore we allocate a
- * bit more */
- descr->skb = dev_alloc_skb(bufsize + GELIC_NET_RXBUF_ALIGN - 1);
- if (!descr->skb) {
- descr->buf_addr = 0; /* tell DMAC don't touch memory */
- return -ENOMEM;
- }
- descr->buf_size = cpu_to_be32(bufsize);
+
descr->dmac_cmd_status = 0;
descr->result_size = 0;
descr->valid_size = 0;
descr->data_error = 0;
+ descr->buf_size = cpu_to_be32(GELIC_NET_MAX_MTU);
+
+ napi_buff = napi_alloc_frag_align(GELIC_NET_MAX_MTU,
+ GELIC_NET_RXBUF_ALIGN);
+
+ if (unlikely(!napi_buff)) {
+ descr->skb = NULL;
+ descr->buf_addr = 0;
+ descr->buf_size = 0;
+ return -ENOMEM;
+ }
+
+ descr->skb = napi_build_skb(napi_buff, GELIC_NET_MAX_MTU);
+
+ if (unlikely(!descr->skb)) {
+ skb_free_frag(napi_buff);
+ descr->skb = NULL;
+ descr->buf_addr = 0;
+ descr->buf_size = 0;
+ return -ENOMEM;
+ }
+
+ descr->buf_addr = cpu_to_be32(dma_map_single(dev, napi_buff,
+ GELIC_NET_MAX_MTU, DMA_FROM_DEVICE));
- offset = ((unsigned long)descr->skb->data) &
- (GELIC_NET_RXBUF_ALIGN - 1);
- if (offset)
- skb_reserve(descr->skb, GELIC_NET_RXBUF_ALIGN - offset);
- /* io-mmu-map the skb */
- descr->buf_addr = cpu_to_be32(dma_map_single(ctodev(card),
- descr->skb->data,
- GELIC_NET_MAX_MTU,
- DMA_FROM_DEVICE));
if (!descr->buf_addr) {
- dev_kfree_skb_any(descr->skb);
+ skb_free_frag(napi_buff);
descr->skb = NULL;
- dev_info(ctodev(card),
- "%s:Could not iommu-map rx buffer\n", __func__);
+ descr->buf_addr = 0;
+ descr->buf_size = 0;
+ dev_err_once(dev, "%s:Could not iommu-map rx buffer\n",
+ __func__);
gelic_descr_set_status(descr, GELIC_DESCR_DMA_NOT_IN_USE);
return -ENOMEM;
- } else {
- gelic_descr_set_status(descr, GELIC_DESCR_DMA_CARDOWNED);
- return 0;
}
+
+ gelic_descr_set_status(descr, GELIC_DESCR_DMA_CARDOWNED);
+ return 0;
}
/**
diff --git a/drivers/net/ethernet/toshiba/ps3_gelic_net.h b/drivers/net/ethernet/toshiba/ps3_gelic_net.h
index 68f324ed4eaf..d3868eb7234c 100644
--- a/drivers/net/ethernet/toshiba/ps3_gelic_net.h
+++ b/drivers/net/ethernet/toshiba/ps3_gelic_net.h
@@ -19,7 +19,7 @@
#define GELIC_NET_RX_DESCRIPTORS 128 /* num of descriptors */
#define GELIC_NET_TX_DESCRIPTORS 128 /* num of descriptors */
-#define GELIC_NET_MAX_MTU VLAN_ETH_FRAME_LEN
+#define GELIC_NET_MAX_MTU 1920
#define GELIC_NET_MIN_MTU VLAN_ETH_ZLEN
#define GELIC_NET_RXBUF_ALIGN 128
#define GELIC_CARD_RX_CSUM_DEFAULT 1 /* hw chksum */
--
2.34.1
next prev parent reply other threads:[~2023-02-26 2:25 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-02-26 2:25 [PATCH net v6 0/2] net/ps3_gelic_net: DMA related fixes Geoff Levand
2023-02-26 2:25 ` Geoff Levand [this message]
2023-02-28 2:20 ` [PATCH net v6 1/2] net/ps3_gelic_net: Fix RX sk_buff length Jakub Kicinski
2023-02-28 15:47 ` Alexander Lobakin
2023-02-28 20:31 ` Jakub Kicinski
2023-03-05 2:07 ` Geoff Levand
2023-02-28 16:12 ` Alexander Lobakin
2023-03-26 20:38 ` Geoff Levand
2023-02-26 2:25 ` [PATCH net v6 2/2] net/ps3_gelic_net: Use dma_mapping_error Geoff Levand
2023-02-28 16:14 ` Alexander Lobakin
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=1bf36b8e08deb3d16fafde3e88ae7cd761e4e7b3.1677377639.git.geoff@infradead.org \
--to=geoff@infradead.org \
--cc=alexander.duyck@gmail.com \
--cc=alexandr.lobakin@intel.com \
--cc=davem@davemloft.net \
--cc=kuba@kernel.org \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.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).