From patchwork Sat Mar 11 21:46:55 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Geoff Levand X-Patchwork-Id: 13171001 X-Patchwork-Delegate: kuba@kernel.org 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 CAF14C6FD1F for ; Sat, 11 Mar 2023 21:47:10 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229807AbjCKVrJ (ORCPT ); Sat, 11 Mar 2023 16:47:09 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54264 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229711AbjCKVrE (ORCPT ); Sat, 11 Mar 2023 16:47:04 -0500 Received: from merlin.infradead.org (merlin.infradead.org [IPv6:2001:8b0:10b:1234::107]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 75B9E67825 for ; Sat, 11 Mar 2023 13:47:02 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=merlin.20170209; h=Date:Cc:To:Subject:From:References: In-Reply-To:Message-Id:Sender:Reply-To:MIME-Version:Content-Type: Content-Transfer-Encoding:Content-ID:Content-Description; bh=Ivps6JGBoMKJIOOQKDnl88/uwUjXiPnZBLwgtKNiuuE=; b=jgLVIgyxiIbdOAvwdM7ADJj0V0 HB0Me2RKRJr0j2wUDL1ACoXK05EYsbXmNg8NFqnMO7xfT6qjoEocGZgBMDVDbeiit6EvVfADCuhxu HXahldiPbPHGA6hziLomxYa4LerBim8aqbJJuRflaQIIdHblOJAnxAaxNAMajO0j3IAS2AZmGgxnR 7JbOqZS5DhY+D/Zd+iTHJe+nzvuwbX5HSi+Ed6C7XB6n0YFzVAPo3z8o3xkWx2GFtaRlYGTRnSywr diryrXJrDOCA8qHLc4J7tkGoRuwNep3i86e4+kCh6ZrpguoyAvEfnLUJQI8jElNz+Km80cIfzy3b+ 1Qo7SDkA==; Received: from geoff by merlin.infradead.org with local (Exim 4.94.2 #2 (Red Hat Linux)) id 1pb73H-007lAJ-OF; Sat, 11 Mar 2023 21:46:56 +0000 Message-Id: <4581be2478ecc3292a3864e24fe9a42dac533b89.1678570942.git.geoff@infradead.org> In-Reply-To: References: From: Geoff Levand Patch-Date: Sat, 11 Mar 2023 13:39:11 -0800 Subject: [PATCH net v8 1/2] net/ps3_gelic_net: Fix RX sk_buff length To: netdev@vger.kernel.org, Jakub Kicinski , "David S. Miller" Cc: Alexander Lobakin , Alexander Duyck , Paolo Abeni Date: Sat, 11 Mar 2023 21:46:55 +0000 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org The Gelic Ethernet device needs to have the RX sk_buffs aligned to GELIC_NET_RXBUF_ALIGN, and also 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. Also, correct the maximum and minimum MTU sizes, and add a new preprocessor macro for the maximum frame size, GELIC_NET_MAX_FRAME. Fixes various randomly occurring runtime network errors. Fixes: 02c1889166b4 ("ps3: gigabit ethernet driver for PS3, take3") Signed-off-by: Geoff Levand --- drivers/net/ethernet/toshiba/ps3_gelic_net.c | 21 +++++++++++--------- drivers/net/ethernet/toshiba/ps3_gelic_net.h | 5 +++-- 2 files changed, 15 insertions(+), 11 deletions(-) diff --git a/drivers/net/ethernet/toshiba/ps3_gelic_net.c b/drivers/net/ethernet/toshiba/ps3_gelic_net.c index cf8de8a7a8a1..56557fc8d18a 100644 --- a/drivers/net/ethernet/toshiba/ps3_gelic_net.c +++ b/drivers/net/ethernet/toshiba/ps3_gelic_net.c @@ -44,6 +44,14 @@ MODULE_AUTHOR("SCE Inc."); MODULE_DESCRIPTION("Gelic Network driver"); MODULE_LICENSE("GPL"); +/** + * 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 const unsigned int gelic_rx_skb_size = + ALIGN(GELIC_NET_MAX_FRAME, GELIC_NET_RXBUF_ALIGN) + + GELIC_NET_RXBUF_ALIGN - 1; /* set irq_mask */ int gelic_card_set_irq_mask(struct gelic_card *card, u64 mask) @@ -370,21 +378,16 @@ static int gelic_descr_prepare_rx(struct gelic_card *card, struct gelic_descr *descr) { int offset; - unsigned int bufsize; 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); + descr->skb = netdev_alloc_skb(*card->netdev, gelic_rx_skb_size); if (!descr->skb) { descr->buf_addr = 0; /* tell DMAC don't touch memory */ return -ENOMEM; } - descr->buf_size = cpu_to_be32(bufsize); + descr->buf_size = cpu_to_be32(gelic_rx_skb_size); descr->dmac_cmd_status = 0; descr->result_size = 0; descr->valid_size = 0; @@ -397,7 +400,7 @@ static int gelic_descr_prepare_rx(struct gelic_card *card, /* io-mmu-map the skb */ descr->buf_addr = cpu_to_be32(dma_map_single(ctodev(card), descr->skb->data, - GELIC_NET_MAX_MTU, + gelic_rx_skb_size, DMA_FROM_DEVICE)); if (!descr->buf_addr) { dev_kfree_skb_any(descr->skb); @@ -915,7 +918,7 @@ static void gelic_net_pass_skb_up(struct gelic_descr *descr, data_error = be32_to_cpu(descr->data_error); /* unmap skb buffer */ dma_unmap_single(ctodev(card), be32_to_cpu(descr->buf_addr), - GELIC_NET_MAX_MTU, + gelic_rx_skb_size, DMA_FROM_DEVICE); skb_put(skb, be32_to_cpu(descr->valid_size)? diff --git a/drivers/net/ethernet/toshiba/ps3_gelic_net.h b/drivers/net/ethernet/toshiba/ps3_gelic_net.h index 68f324ed4eaf..0d98defb011e 100644 --- a/drivers/net/ethernet/toshiba/ps3_gelic_net.h +++ b/drivers/net/ethernet/toshiba/ps3_gelic_net.h @@ -19,8 +19,9 @@ #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_MIN_MTU VLAN_ETH_ZLEN +#define GELIC_NET_MAX_FRAME 2312 +#define GELIC_NET_MAX_MTU 2294 +#define GELIC_NET_MIN_MTU 64 #define GELIC_NET_RXBUF_ALIGN 128 #define GELIC_CARD_RX_CSUM_DEFAULT 1 /* hw chksum */ #define GELIC_NET_WATCHDOG_TIMEOUT 5*HZ From patchwork Sat Mar 11 21:46:59 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Geoff Levand X-Patchwork-Id: 13171002 X-Patchwork-Delegate: kuba@kernel.org 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 29C97C74A44 for ; Sat, 11 Mar 2023 21:47:12 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229703AbjCKVrK (ORCPT ); Sat, 11 Mar 2023 16:47:10 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54304 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229722AbjCKVrF (ORCPT ); Sat, 11 Mar 2023 16:47:05 -0500 Received: from merlin.infradead.org (merlin.infradead.org [IPv6:2001:8b0:10b:1234::107]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6B73A6A040 for ; Sat, 11 Mar 2023 13:47:03 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=merlin.20170209; h=Date:Cc:To:Subject:From:References: In-Reply-To:Message-Id:Sender:Reply-To:MIME-Version:Content-Type: Content-Transfer-Encoding:Content-ID:Content-Description; bh=PKtd2Zt2zgGDKLoKzJ9Ss25cGsnhzolsoWX/YGBuyJM=; b=WQDobXS5iW7hFVCIBRCgBsP1SN uYude24ctcWOJU8e2kyCsDQ/2/DT6/9qDl55aVlsV9l0Tw3HUbpENkWJv2E0Ga6Bw6GjkILJEBXfy pYQ+Mqay0TMAI39w2esfXMWBCCVg1iybrxJ4gZt00TZFgchsCeNr2vC0jJiCVbosjwtPRL7YCbt1+ FRZT3t/QClOV+Bi5hyA5OiQqi1rmnug/moJpRvAGvkcv1MZH291BQh5HWGkcDIMK7K5idU55lVEep QgUQpEc+C+9CT2Y2mQ9r5OXjGvNTVJs9UoH9IcmetkrNc9QQind4AbNWy/1EFweRx8VZtnB4mkBbT VZAY6vPQ==; Received: from geoff by merlin.infradead.org with local (Exim 4.94.2 #2 (Red Hat Linux)) id 1pb73L-007lAN-IF; Sat, 11 Mar 2023 21:47:00 +0000 Message-Id: <642c56a7da025406c36862464f5a15aba3e5340e.1678570942.git.geoff@infradead.org> In-Reply-To: References: From: Geoff Levand Patch-Date: Sat, 11 Mar 2023 13:39:11 -0800 Subject: [PATCH net v8 2/2] net/ps3_gelic_net: Use dma_mapping_error To: netdev@vger.kernel.org, Jakub Kicinski , "David S. Miller" Cc: Alexander Lobakin , Alexander Duyck , Paolo Abeni Date: Sat, 11 Mar 2023 21:46:59 +0000 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org The current Gelic Etherenet driver was checking the return value of its dma_map_single call, and not using the dma_mapping_error() routine. Fixes runtime problems like these: DMA-API: ps3_gelic_driver sb_05: device driver failed to check map error WARNING: CPU: 0 PID: 0 at kernel/dma/debug.c:1027 .check_unmap+0x888/0x8dc Fixes: 02c1889166b4 ("ps3: gigabit ethernet driver for PS3, take3") Signed-off-by: Geoff Levand Reviewed-by: Alexander Duyck --- drivers/net/ethernet/toshiba/ps3_gelic_net.c | 24 +++++++++++--------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/drivers/net/ethernet/toshiba/ps3_gelic_net.c b/drivers/net/ethernet/toshiba/ps3_gelic_net.c index 56557fc8d18a..87d3c768286e 100644 --- a/drivers/net/ethernet/toshiba/ps3_gelic_net.c +++ b/drivers/net/ethernet/toshiba/ps3_gelic_net.c @@ -325,15 +325,17 @@ static int gelic_card_init_chain(struct gelic_card *card, /* set up the hardware pointers in each descriptor */ for (i = 0; i < no; i++, descr++) { + dma_addr_t cpu_addr; + gelic_descr_set_status(descr, GELIC_DESCR_DMA_NOT_IN_USE); - descr->bus_addr = - dma_map_single(ctodev(card), descr, - GELIC_DESCR_SIZE, - DMA_BIDIRECTIONAL); - if (!descr->bus_addr) + cpu_addr = dma_map_single(ctodev(card), descr, + GELIC_DESCR_SIZE, DMA_BIDIRECTIONAL); + + if (dma_mapping_error(ctodev(card), cpu_addr)) goto iommu_error; + descr->bus_addr = cpu_to_be32(cpu_addr); descr->next = descr + 1; descr->prev = descr - 1; } @@ -377,6 +379,7 @@ static int gelic_card_init_chain(struct gelic_card *card, static int gelic_descr_prepare_rx(struct gelic_card *card, struct gelic_descr *descr) { + dma_addr_t cpu_addr; int offset; if (gelic_descr_get_status(descr) != GELIC_DESCR_DMA_NOT_IN_USE) @@ -398,11 +401,10 @@ static int gelic_descr_prepare_rx(struct gelic_card *card, 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_rx_skb_size, - DMA_FROM_DEVICE)); - if (!descr->buf_addr) { + cpu_addr = dma_map_single(ctodev(card), descr->skb->data, + gelic_rx_skb_size, DMA_FROM_DEVICE); + descr->buf_addr = cpu_to_be32(cpu_addr); + if (dma_mapping_error(ctodev(card), cpu_addr)) { dev_kfree_skb_any(descr->skb); descr->skb = NULL; dev_info(ctodev(card), @@ -782,7 +784,7 @@ static int gelic_descr_prepare_tx(struct gelic_card *card, buf = dma_map_single(ctodev(card), skb->data, skb->len, DMA_TO_DEVICE); - if (!buf) { + if (dma_mapping_error(ctodev(card), buf)) { dev_err(ctodev(card), "dma map 2 failed (%p, %i). Dropping packet\n", skb->data, skb->len);