From patchwork Fri Mar 3 20:48:41 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Gmeiner X-Patchwork-Id: 1751631 X-Patchwork-Delegate: rfried.dev@gmail.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=2a01:238:438b:c500:173d:9f52:ddab:ee01; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20210112 header.b=S2ft/q09; dkim-atps=neutral Received: from phobos.denx.de (phobos.denx.de [IPv6:2a01:238:438b:c500:173d:9f52:ddab:ee01]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4PT0Sw6QQgz1yWx for ; Sat, 4 Mar 2023 07:49:19 +1100 (AEDT) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id ECC4385D81; Fri, 3 Mar 2023 21:49:07 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="S2ft/q09"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 7E55C85D84; Fri, 3 Mar 2023 21:49:06 +0100 (CET) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,SPF_HELO_NONE, SPF_PASS autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-ed1-x531.google.com (mail-ed1-x531.google.com [IPv6:2a00:1450:4864:20::531]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 1945485935 for ; Fri, 3 Mar 2023 21:49:04 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=christian.gmeiner@gmail.com Received: by mail-ed1-x531.google.com with SMTP id g3so15351611eda.1 for ; Fri, 03 Mar 2023 12:49:04 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; t=1677876543; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=Kunwg2YUGtCoD3aFVaTfFHB5PAF9n4+3il2eaczZ0jQ=; b=S2ft/q09C+2lE5C1JPEwTsULRTL4kIXlFcvLrC2czNSrSMfpRmOvataEY4yepJU7gx 8fgFfoXz9ODSC22rEFNxScJgIvew7UL4P9V5R58GcEzFBFStgO2fMAtsoSNM9e314Lu3 W5N1wh7kG+6wZcMiPnU5XQ6uPd1TU7vErj9DLE5OzQZ5sylT6YPX3eZgLjmtfHoloNtN aCAyPaXHhd3GjhMFmk7uQcwcyZaveaEPFDRZIzsv0p96HkAaiVUOYyej2vIXWBBLZ31R ksEfJYFdgBVGDxgawOrySZFLXdTqq1/tW1YBP/HDWrbVpsitDU/6o6Omb8C3flXLXsAL rKTA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1677876543; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=Kunwg2YUGtCoD3aFVaTfFHB5PAF9n4+3il2eaczZ0jQ=; b=tpNSbkXZ2ohnLx2XseCDwTUs/YRbz06lmHkiRYiyn42h9WC6go+svS9Urcbs/g50k6 OzGxClONxNRLcKdpd9Q4Csxl7pne5kiumiL9jc18zJACWFZUYldg3QMl6LldVSNq+CVc 5Dc5tGu6vQsHFAJ+a8BDOzieBhcyi+W8Ciw1/1AU8Zc5kCi6FqTfKmqmH+bUApWBz2yd IlLAnZeP4KvOtVHDH62BEeJcFmV7I70imiuuJSoJcsClHlVH3MUx/5s0f5grWVP2XMUu 4RbjY7qD6lzFs9Wfh0WkCJBsQLhsZ1OUvQwb5ucs922Gj3RL2TlcJuNVIUtmV7lJU8an UVeQ== X-Gm-Message-State: AO0yUKXXrpStdmVHl+3hhLA0L88RUpkS0QT+31l8xrMJAhAaxFbjJEUy 8IP/D3acHMClnYQ8IA6wsa4= X-Google-Smtp-Source: AK7set8+EexXDw6EoVEwx7DuruG2n8wy471i0CfY8JrOzONPdEiHeF3QQk18KLhcOG6rxyXfu5McHw== X-Received: by 2002:a17:906:1412:b0:8b1:7ac6:3186 with SMTP id p18-20020a170906141200b008b17ac63186mr3054140ejc.68.1677876543394; Fri, 03 Mar 2023 12:49:03 -0800 (PST) Received: from localhost.localdomain (80-108-76-242.cable.dynamic.surfer.at. [80.108.76.242]) by smtp.gmail.com with ESMTPSA id v15-20020a50954f000000b004c09527d62dsm1600015eda.30.2023.03.03.12.49.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 03 Mar 2023 12:49:02 -0800 (PST) From: Christian Gmeiner To: Joe Hershberger , Ramon Fried , u-boot@lists.denx.de (open list) Cc: Christian Gmeiner Subject: [PATCH 1/4] net: e1000: add and make use of NUM_RX_DESC macro Date: Fri, 3 Mar 2023 21:48:41 +0100 Message-Id: <20230303204844.112105-1-christian.gmeiner@gmail.com> X-Mailer: git-send-email 2.39.2 MIME-Version: 1.0 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.6 at phobos.denx.de X-Virus-Status: Clean The call to DEFINE_ALIGN_BUFFER for the rx_desc array conained an icnonsistency as 16 receive descriptors were allocated when the remaining code would only use 8 of them. Signed-off-by: Christian Gmeiner Reviewed-by: Ramon Fried --- drivers/net/e1000.c | 6 +++--- drivers/net/e1000.h | 2 ++ 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/drivers/net/e1000.c b/drivers/net/e1000.c index 41e6ba760e..8dccf29c7e 100644 --- a/drivers/net/e1000.c +++ b/drivers/net/e1000.c @@ -60,7 +60,7 @@ tested on both gig copper and gig fiber boards * move these buffers and the tx/rx pointers to struct e1000_hw. */ DEFINE_ALIGN_BUFFER(struct e1000_tx_desc, tx_base, 16, E1000_BUFFER_ALIGN); -DEFINE_ALIGN_BUFFER(struct e1000_rx_desc, rx_base, 16, E1000_BUFFER_ALIGN); +DEFINE_ALIGN_BUFFER(struct e1000_rx_desc, rx_base, NUM_RX_DESC, E1000_BUFFER_ALIGN); DEFINE_ALIGN_BUFFER(unsigned char, packet, 4096, E1000_BUFFER_ALIGN); static int tx_tail; @@ -5095,7 +5095,7 @@ fill_rx(struct e1000_hw *hw) rx_last = rx_tail; rd = rx_base + rx_tail; - rx_tail = (rx_tail + 1) % 8; + rx_tail = (rx_tail + 1) % NUM_RX_DESC; memset(rd, 0, 16); rd->buffer_addr = cpu_to_le64(virt_to_phys(packet)); @@ -5272,7 +5272,7 @@ e1000_configure_rx(struct e1000_hw *hw) E1000_WRITE_REG(hw, RDBAL, lower_32_bits(virt_to_phys(rx_base))); E1000_WRITE_REG(hw, RDBAH, upper_32_bits(virt_to_phys(rx_base))); - E1000_WRITE_REG(hw, RDLEN, 128); + E1000_WRITE_REG(hw, RDLEN, NUM_RX_DESC * sizeof(struct e1000_rx_desc)); /* Setup the HW Rx Head and Tail Descriptor Pointers */ E1000_WRITE_REG(hw, RDH, 0); diff --git a/drivers/net/e1000.h b/drivers/net/e1000.h index f788394da8..69882ba66f 100644 --- a/drivers/net/e1000.h +++ b/drivers/net/e1000.h @@ -42,6 +42,8 @@ #define DEBUGOUT(fmt, args...) do { } while (0) #endif +#define NUM_RX_DESC 8 + /* I/O wrapper functions */ #define E1000_WRITE_REG(a, reg, value) \ writel((value), ((a)->hw_addr + E1000_##reg)) From patchwork Fri Mar 3 20:48:42 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Gmeiner X-Patchwork-Id: 1751632 X-Patchwork-Delegate: rfried.dev@gmail.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=2a01:238:438b:c500:173d:9f52:ddab:ee01; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20210112 header.b=b9z5nI63; dkim-atps=neutral Received: from phobos.denx.de (phobos.denx.de [IPv6:2a01:238:438b:c500:173d:9f52:ddab:ee01]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4PT0T433hjz1yWx for ; Sat, 4 Mar 2023 07:49:28 +1100 (AEDT) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id AAC0A85CD0; Fri, 3 Mar 2023 21:49:10 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="b9z5nI63"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id E357F85D70; Fri, 3 Mar 2023 21:49:07 +0100 (CET) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,SPF_HELO_NONE, SPF_PASS autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-ed1-x529.google.com (mail-ed1-x529.google.com [IPv6:2a00:1450:4864:20::529]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 6C58685D70 for ; Fri, 3 Mar 2023 21:49:05 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=christian.gmeiner@gmail.com Received: by mail-ed1-x529.google.com with SMTP id i34so15227413eda.7 for ; Fri, 03 Mar 2023 12:49:05 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; t=1677876545; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=Hj4Bdes5+DRBQG1y25NATxthHBRZAro2cMUsj83Rng8=; b=b9z5nI63hyG6vELYlizzTTOZAlbrd11J+fY8NMex3tw8SIOFlnei4ZF3HfYm1dOIJS yPZTOHDp6B9MBGvOeI6GF3AZNabwFYnRuiEs/LcypOkjIK8vV8EAu0accb2FyQhRX/2W SLEeNwu3HNn5KsOZn5K6th74fj+3wFYfNpm/XkUDBaZYqGCSNXHGO5i6NQbWzUaSKL3H uwjnNyxedVnQHDESMg2hj3AkCAx3WyEYANBHxE4XcOljcpHuXG3kxU0EwrutJw5RJgR1 dgsp1DVw6af8YlET+kP8HBOUfxXfVgK4mPuQLMVDxVuc/gcl+MuAUZcklUy7bciJN8Xb Zlug== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1677876545; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Hj4Bdes5+DRBQG1y25NATxthHBRZAro2cMUsj83Rng8=; b=f/zD74hThNYDTBiSMBdMPbqzfItqIprnjBWuBLBQyd3r8lxLLDW1NchWk/H4sj5Zh+ dKDWgRdiNrN+zldik9KQPIL0FZuehsuDWVedGvALH7gCcgIRRTvEBxboG+jNpPlRAbjA 3stjEa1fgYW0HOYTo/yI3HrRMCcNBJRE7Igo5pKWIb/WszIzsXWxTahraFB5U3/J9ldd l5ZPS8TX5UEyTFGujzVxIoLQH3FQfpcxozAy2OtzidUlpSQ7fNYfanFjPZJOksI625f8 MfrCbPtt5pK3hGa6RMoOgkfU3wbChdrwJ84AnfL/Lot/1aS81Flo8y96QFicEvBusvHW 8fvg== X-Gm-Message-State: AO0yUKXP/ChQNmEuBui8ePf95nGpS9SglV0dH44s82BKxgSe3rOWSg/O 7Y0bbiGfIwsvTsbIfeWRmhY9ywX2pvM= X-Google-Smtp-Source: AK7set9eKrdGDv+0llX6po4/JCR1hi8TlnsC43uSMiQKFv6ufNQg3g7dK6ErDj/FG0J+UrEhpwtiaQ== X-Received: by 2002:aa7:d390:0:b0:4ac:bdeb:6dce with SMTP id x16-20020aa7d390000000b004acbdeb6dcemr2930576edq.39.1677876544825; Fri, 03 Mar 2023 12:49:04 -0800 (PST) Received: from localhost.localdomain (80-108-76-242.cable.dynamic.surfer.at. [80.108.76.242]) by smtp.gmail.com with ESMTPSA id v15-20020a50954f000000b004c09527d62dsm1600015eda.30.2023.03.03.12.49.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 03 Mar 2023 12:49:04 -0800 (PST) From: Christian Gmeiner To: Joe Hershberger , Ramon Fried , u-boot@lists.denx.de (open list) Cc: Christian Gmeiner Subject: [PATCH 2/4] net: e1000: move all rx data structures to hw instance Date: Fri, 3 Mar 2023 21:48:42 +0100 Message-Id: <20230303204844.112105-2-christian.gmeiner@gmail.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230303204844.112105-1-christian.gmeiner@gmail.com> References: <20230303204844.112105-1-christian.gmeiner@gmail.com> MIME-Version: 1.0 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.6 at phobos.denx.de X-Virus-Status: Clean Preparation for per driver instance allocated data structures. Signed-off-by: Christian Gmeiner --- drivers/net/e1000.c | 26 +++++++++++++++----------- drivers/net/e1000.h | 5 +++++ 2 files changed, 20 insertions(+), 11 deletions(-) diff --git a/drivers/net/e1000.c b/drivers/net/e1000.c index 8dccf29c7e..08c84ce3d1 100644 --- a/drivers/net/e1000.c +++ b/drivers/net/e1000.c @@ -61,10 +61,9 @@ tested on both gig copper and gig fiber boards */ DEFINE_ALIGN_BUFFER(struct e1000_tx_desc, tx_base, 16, E1000_BUFFER_ALIGN); DEFINE_ALIGN_BUFFER(struct e1000_rx_desc, rx_base, NUM_RX_DESC, E1000_BUFFER_ALIGN); -DEFINE_ALIGN_BUFFER(unsigned char, packet, 4096, E1000_BUFFER_ALIGN); +DEFINE_ALIGN_BUFFER(unsigned char, _packet, 4096, E1000_BUFFER_ALIGN); static int tx_tail; -static int rx_tail, rx_last; static int num_cards; /* Number of E1000 devices seen so far */ static struct pci_device_id e1000_supported[] = { @@ -5090,12 +5089,13 @@ e1000_sw_init(struct e1000_hw *hw) void fill_rx(struct e1000_hw *hw) { + unsigned char *packet = hw->rx_packet; struct e1000_rx_desc *rd; unsigned long flush_start, flush_end; - rx_last = rx_tail; - rd = rx_base + rx_tail; - rx_tail = (rx_tail + 1) % NUM_RX_DESC; + hw->rx_last = hw->rx_tail; + rd = hw->rx_base + hw->rx_tail; + hw->rx_tail = (hw->rx_tail + 1) % NUM_RX_DESC; memset(rd, 0, 16); rd->buffer_addr = cpu_to_le64(virt_to_phys(packet)); @@ -5111,7 +5111,7 @@ fill_rx(struct e1000_hw *hw) flush_end = flush_start + roundup(sizeof(*rd), ARCH_DMA_MINALIGN); flush_dcache_range(flush_start, flush_end); - E1000_WRITE_REG(hw, RDT, rx_tail); + E1000_WRITE_REG(hw, RDT, hw->rx_tail); } /** @@ -5248,7 +5248,7 @@ static void e1000_configure_rx(struct e1000_hw *hw) { unsigned long rctl, ctrl_ext; - rx_tail = 0; + hw->rx_tail = 0; /* make sure receives are disabled while setting up the descriptors */ rctl = E1000_READ_REG(hw, RCTL); @@ -5269,8 +5269,8 @@ e1000_configure_rx(struct e1000_hw *hw) E1000_WRITE_FLUSH(hw); } /* Setup the Base and Length of the Rx Descriptor Ring */ - E1000_WRITE_REG(hw, RDBAL, lower_32_bits(virt_to_phys(rx_base))); - E1000_WRITE_REG(hw, RDBAH, upper_32_bits(virt_to_phys(rx_base))); + E1000_WRITE_REG(hw, RDBAL, lower_32_bits(virt_to_phys(hw->rx_base))); + E1000_WRITE_REG(hw, RDBAH, upper_32_bits(virt_to_phys(hw->rx_base))); E1000_WRITE_REG(hw, RDLEN, NUM_RX_DESC * sizeof(struct e1000_rx_desc)); @@ -5298,12 +5298,13 @@ POLL - Wait for a frame static int _e1000_poll(struct e1000_hw *hw) { + unsigned char *packet = hw->rx_packet; struct e1000_rx_desc *rd; unsigned long inval_start, inval_end; uint32_t len; /* return true if there's an ethernet packet ready to read */ - rd = rx_base + rx_last; + rd = hw->rx_base + hw->rx_last; /* Re-load the descriptor from RAM. */ inval_start = ((unsigned long)rd) & ~(ARCH_DMA_MINALIGN - 1); @@ -5469,6 +5470,9 @@ static int e1000_init_one(struct e1000_hw *hw, int cardnum, return -EPERM; } + hw->rx_base = rx_base; + hw->rx_packet = _packet; + /* Are these variables needed? */ hw->fc = e1000_fc_default; hw->original_fc = e1000_fc_default; @@ -5663,7 +5667,7 @@ static int e1000_eth_recv(struct udevice *dev, int flags, uchar **packetp) len = _e1000_poll(hw); if (len) - *packetp = packet; + *packetp = hw->rx_packet; return len ? len : -EAGAIN; } diff --git a/drivers/net/e1000.h b/drivers/net/e1000.h index 69882ba66f..f83e3a0b33 100644 --- a/drivers/net/e1000.h +++ b/drivers/net/e1000.h @@ -1134,6 +1134,11 @@ struct e1000_hw { bool initialize_hw_bits_disable; e1000_smart_speed smart_speed; e1000_dsp_config dsp_config_state; + + struct e1000_rx_desc *rx_base; + unsigned char *rx_packet; + int rx_tail; + int rx_last; }; #define E1000_EEPROM_SWDPIN0 0x0001 /* SWDPIN 0 EEPROM Value */ From patchwork Fri Mar 3 20:48:43 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Gmeiner X-Patchwork-Id: 1751633 X-Patchwork-Delegate: rfried.dev@gmail.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=2a01:238:438b:c500:173d:9f52:ddab:ee01; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20210112 header.b=Mu/Y9yE7; dkim-atps=neutral Received: from phobos.denx.de (phobos.denx.de [IPv6:2a01:238:438b:c500:173d:9f52:ddab:ee01]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4PT0TL5cNTz1yWx for ; Sat, 4 Mar 2023 07:49:42 +1100 (AEDT) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 7F95185D8C; Fri, 3 Mar 2023 21:49:12 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="Mu/Y9yE7"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 3166E85C1A; Fri, 3 Mar 2023 21:49:09 +0100 (CET) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,SPF_HELO_NONE, SPF_PASS autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-ed1-x535.google.com (mail-ed1-x535.google.com [IPv6:2a00:1450:4864:20::535]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id A6CCB85935 for ; Fri, 3 Mar 2023 21:49:06 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=christian.gmeiner@gmail.com Received: by mail-ed1-x535.google.com with SMTP id u9so15339536edd.2 for ; Fri, 03 Mar 2023 12:49:06 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; t=1677876546; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=kdA3ouIMXAjVAOm9V8NrzsIop+D92s1L1s0Q1NyKym8=; b=Mu/Y9yE7I1LL4KDtMVyLHt+3V8CTS6Fi5vgIj5Q8v5dbasmxSfTp6rBxgFkZ8bv86c ADyY0ldfyV6eRjZ54B17Nxj9aAaOOQMb4QbPl5aERKZpC0GKt/12Rrf0DzA0r7RAHTyy suAvEppMqKwZIGpP3R/UI/R8CseIopCHmvlghHy7xSGGNPu4wMMJFh4LpgBdxsEsUHic JmdssPiSP1zrgx2Snp9ybiv4A7ZTyLEzeRpimJlveyMsrhTkhLkDKlYankqRTZDM8uyB GALjd9A+NY0zG08fMUegt7VgFVyXwi06PlnyYHEdOSnpaTf+Z4yL5vXUialGAUYxMtX6 415Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1677876546; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=kdA3ouIMXAjVAOm9V8NrzsIop+D92s1L1s0Q1NyKym8=; b=vC1LGs1ypSNi4DCnrLAYgrpP0fUt4U/Qx2wqerCoWilrdrAxrT3tjejS2tjRDk0ZTC u8OFyTuGrYGDCyBB0x++nMh7aZNKzyRTEX5z1aLKC1s1wSm0wn/2zWagyRE7K7v33bRq aBWdyKG+uHYWjy3HmiN6XkUhYp34PeYMlJ8FrZx3gm+v5G/0HL8dbWUu8XQeQgFvpP2n Ip3pz4O9EClqm4/7YXTwvK9tX5gdRQX+1Ee5+PGJpbiF9O8fLkykePYuUKdcMCHqOmrA wXZuh9M1ot86k/B8Ip+QxMh/KtVQiskf4Bzoc1k7T1Kqawuz/M3Gi5egALXzXtY8GDHY N8EA== X-Gm-Message-State: AO0yUKUQsh6pvolwhTOP1oD0JUrGgWcWk7jejutpYG0UBqIHurT9NBSz MpSq7JEDyzn4Xfwa2XiWYZE= X-Google-Smtp-Source: AK7set8mJEEW1NDTjX5StY7WTS5fx/JHk1KBGPmbJ8zNSdRQLWOkzQ0p8mGkH4eO3I7VTGoBWKtcQQ== X-Received: by 2002:a50:ee18:0:b0:4af:69b8:52af with SMTP id g24-20020a50ee18000000b004af69b852afmr3018777eds.24.1677876546260; Fri, 03 Mar 2023 12:49:06 -0800 (PST) Received: from localhost.localdomain (80-108-76-242.cable.dynamic.surfer.at. [80.108.76.242]) by smtp.gmail.com with ESMTPSA id v15-20020a50954f000000b004c09527d62dsm1600015eda.30.2023.03.03.12.49.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 03 Mar 2023 12:49:05 -0800 (PST) From: Christian Gmeiner To: Joe Hershberger , Ramon Fried , u-boot@lists.denx.de (open list) Cc: Christian Gmeiner Subject: [PATCH 3/4] net: e1000: dynamically allocate rx data buffers per instance Date: Fri, 3 Mar 2023 21:48:43 +0100 Message-Id: <20230303204844.112105-3-christian.gmeiner@gmail.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230303204844.112105-1-christian.gmeiner@gmail.com> References: <20230303204844.112105-1-christian.gmeiner@gmail.com> MIME-Version: 1.0 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.6 at phobos.denx.de X-Virus-Status: Clean Signed-off-by: Christian Gmeiner --- drivers/net/e1000.c | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/drivers/net/e1000.c b/drivers/net/e1000.c index 08c84ce3d1..ea9ca76917 100644 --- a/drivers/net/e1000.c +++ b/drivers/net/e1000.c @@ -54,14 +54,11 @@ tested on both gig copper and gig fiber boards #define E1000_BUFFER_ALIGN 128 /* - * TODO(sjg@chromium.org): Even with driver model we share these buffers. - * Concurrent receiving on multiple active Ethernet devices will not work. - * Normally U-Boot does not support this anyway. To fix it in this driver, - * move these buffers and the tx/rx pointers to struct e1000_hw. + * TODO(sjg@chromium.org): Even with driver model we share tx buffer. + * To fix it in this driver, move these buffer and the tx pointers to + * struct e1000_hw. */ DEFINE_ALIGN_BUFFER(struct e1000_tx_desc, tx_base, 16, E1000_BUFFER_ALIGN); -DEFINE_ALIGN_BUFFER(struct e1000_rx_desc, rx_base, NUM_RX_DESC, E1000_BUFFER_ALIGN); -DEFINE_ALIGN_BUFFER(unsigned char, _packet, 4096, E1000_BUFFER_ALIGN); static int tx_tail; static int num_cards; /* Number of E1000 devices seen so far */ @@ -5442,6 +5439,12 @@ void e1000_get_bus_type(struct e1000_hw *hw) } } +static inline void * +e1000_alloc(size_t size) +{ + return memalign(E1000_BUFFER_ALIGN, size); +} + static int e1000_init_one(struct e1000_hw *hw, int cardnum, struct udevice *devno, unsigned char enetaddr[6]) { @@ -5470,8 +5473,14 @@ static int e1000_init_one(struct e1000_hw *hw, int cardnum, return -EPERM; } - hw->rx_base = rx_base; - hw->rx_packet = _packet; + hw->rx_base = e1000_alloc(NUM_RX_DESC * sizeof(struct e1000_rx_desc)); + hw->rx_packet = e1000_alloc(4096); + + if (!hw->rx_base || !hw->rx_packet) { + free(hw->rx_base); + free(hw->rx_packet); + return -ENOMEM; + } /* Are these variables needed? */ hw->fc = e1000_fc_default; From patchwork Fri Mar 3 20:48:44 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Gmeiner X-Patchwork-Id: 1751634 X-Patchwork-Delegate: rfried.dev@gmail.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=2a01:238:438b:c500:173d:9f52:ddab:ee01; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20210112 header.b=VGQTCBb2; dkim-atps=neutral Received: from phobos.denx.de (phobos.denx.de [IPv6:2a01:238:438b:c500:173d:9f52:ddab:ee01]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4PT0Tc6NXHz1yWx for ; Sat, 4 Mar 2023 07:49:56 +1100 (AEDT) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id C6AF885D91; Fri, 3 Mar 2023 21:49:14 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="VGQTCBb2"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 0699785D87; Fri, 3 Mar 2023 21:49:11 +0100 (CET) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,SPF_HELO_NONE, SPF_PASS autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-ed1-x52c.google.com (mail-ed1-x52c.google.com [IPv6:2a00:1450:4864:20::52c]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 4B97085D87 for ; Fri, 3 Mar 2023 21:49:08 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=christian.gmeiner@gmail.com Received: by mail-ed1-x52c.google.com with SMTP id cw28so15274326edb.5 for ; Fri, 03 Mar 2023 12:49:08 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; t=1677876548; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=fn5Fwvf4/bEpcP/rkAQys7e8LQt5UizLs32IB+5wCFs=; b=VGQTCBb2ezKkl8r2OmdkqVTcpTTHaaC5ViBRhSoHAKWD3VpGgTB9dOdGk9PG6Pyztq lQHvjatjg2K5OPzbn2lL3Gjt9rwiquW8u4O2Bv4j1zK0WOIEl28bP55+keuf4zpUJqLq 39myr06a/m7CI1EwK0UAvTnM0HVrMv82ewD1dM63UbXgrjCGMT212Ckhw+2ZVuN4NLgy vz+KkZ0kbSNZ40eC4dPoC+o7317DYY+39/ZeAqWChcIwtwOdKRXoNngU3PoZH79TSkez VNqgrP7PvCrKA7pw3cfNJreHnRIDlsuuLye/A9p6UD/ocLiy06FXfs38c4lOknkIfSas BZMw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1677876548; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=fn5Fwvf4/bEpcP/rkAQys7e8LQt5UizLs32IB+5wCFs=; b=4BP17UNG/SFSR8xIrFymue9NPHLB/FRoTXiqSpsZDUvvIcsJN95RmWMtLSojOmk3xt Ki1FRlUxnoAw/vGoAwH5SpOM6oMe0rIfFZBeaqKUTmiIVu0KXNfNyaMfn8YTwNc8NR0C OGyp5Ma4l4amoIqJKfhEbj0VIl/jiPVIil6qB3q5tbPql2yS0Rg2l/to9F7BgKTHHl0x PWBpNDo+Q8u5G4jFXT70gZ6ZhG+/K/R+zSUziXILUr6h3Kr0FOsWI0v/MiWNEehZT3+z TIjpCxJmvzFP4IwOqag2vcZmcBCBg589bTeVFi8izdJ6G8aSABC8w5r5pjEBTo9BahYE gknA== X-Gm-Message-State: AO0yUKWH7KCDEgkGnnyG5SRDAdf+tCHmR77QT6AAjxU2jLGb7KhXYRSk G2Mu6vGgPDbtvSxZrHUSz5o= X-Google-Smtp-Source: AK7set8yCpl90pc22GIp7TVMm6mvUnrzpSOl1TW0XLZ/SX3fgsBn/zMFbiGd0R6eIY0p+q4YALOgig== X-Received: by 2002:aa7:d684:0:b0:4ac:c68d:88c7 with SMTP id d4-20020aa7d684000000b004acc68d88c7mr2960512edr.0.1677876547596; Fri, 03 Mar 2023 12:49:07 -0800 (PST) Received: from localhost.localdomain (80-108-76-242.cable.dynamic.surfer.at. [80.108.76.242]) by smtp.gmail.com with ESMTPSA id v15-20020a50954f000000b004c09527d62dsm1600015eda.30.2023.03.03.12.49.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 03 Mar 2023 12:49:07 -0800 (PST) From: Christian Gmeiner To: Joe Hershberger , Ramon Fried , u-boot@lists.denx.de (open list) Cc: Christian Gmeiner Subject: [PATCH 4/4] net: e1000: make use of multiple rx packets Date: Fri, 3 Mar 2023 21:48:44 +0100 Message-Id: <20230303204844.112105-4-christian.gmeiner@gmail.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230303204844.112105-1-christian.gmeiner@gmail.com> References: <20230303204844.112105-1-christian.gmeiner@gmail.com> MIME-Version: 1.0 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.6 at phobos.denx.de X-Virus-Status: Clean When facing a very busy network, the single rx packet buffer was oftentimes overwritten before a desired response packet (e.g. a Ping reply) could have been processed. This change improves resistance to this by utilising multiple buffers. Signed-off-by: Christian Gmeiner --- drivers/net/e1000.c | 30 ++++++++++++++++++++++-------- drivers/net/e1000.h | 2 +- 2 files changed, 23 insertions(+), 9 deletions(-) diff --git a/drivers/net/e1000.c b/drivers/net/e1000.c index ea9ca76917..86300898af 100644 --- a/drivers/net/e1000.c +++ b/drivers/net/e1000.c @@ -5086,7 +5086,7 @@ e1000_sw_init(struct e1000_hw *hw) void fill_rx(struct e1000_hw *hw) { - unsigned char *packet = hw->rx_packet; + unsigned char *packet = hw->rx_packet[hw->rx_tail]; struct e1000_rx_desc *rd; unsigned long flush_start, flush_end; @@ -5284,6 +5284,9 @@ e1000_configure_rx(struct e1000_hw *hw) mdelay(20); } + for (int i = 0; i < NUM_RX_DESC; i++) + memset(&hw->rx_base[i], 0, 16); + E1000_WRITE_REG(hw, RCTL, rctl); fill_rx(hw); @@ -5295,9 +5298,9 @@ POLL - Wait for a frame static int _e1000_poll(struct e1000_hw *hw) { - unsigned char *packet = hw->rx_packet; struct e1000_rx_desc *rd; unsigned long inval_start, inval_end; + unsigned char *packet; uint32_t len; /* return true if there's an ethernet packet ready to read */ @@ -5310,6 +5313,9 @@ _e1000_poll(struct e1000_hw *hw) if (!(rd->status & E1000_RXD_STAT_DD)) return 0; + + packet = (unsigned char *)rd->buffer_addr; + /* DEBUGOUT("recv: packet len=%d\n", rd->length); */ /* Packet received, make sure the data are re-loaded from RAM. */ len = le16_to_cpu(rd->length); @@ -5403,8 +5409,8 @@ _e1000_init(struct e1000_hw *hw, unsigned char enetaddr[6]) return ret_val; } e1000_configure_tx(hw); - e1000_setup_rctl(hw); e1000_configure_rx(hw); + e1000_setup_rctl(hw); return 0; } @@ -5474,12 +5480,14 @@ static int e1000_init_one(struct e1000_hw *hw, int cardnum, } hw->rx_base = e1000_alloc(NUM_RX_DESC * sizeof(struct e1000_rx_desc)); - hw->rx_packet = e1000_alloc(4096); - if (!hw->rx_base || !hw->rx_packet) { - free(hw->rx_base); - free(hw->rx_packet); + if (!hw->rx_base) return -ENOMEM; + + for (int i = 0; i < NUM_RX_DESC; i++) { + hw->rx_packet[i] = e1000_alloc(4096); + if (!hw->rx_packet[i]) + goto out_alloc_fail; } /* Are these variables needed? */ @@ -5529,6 +5537,12 @@ static int e1000_init_one(struct e1000_hw *hw, int cardnum, #endif return 0; + +out_alloc_fail: + for (int i = 0; i < NUM_RX_DESC; i++) + free(hw->rx_packet[i]); + + return -ENOMEM; } /* Put the name of a device in a string */ @@ -5676,7 +5690,7 @@ static int e1000_eth_recv(struct udevice *dev, int flags, uchar **packetp) len = _e1000_poll(hw); if (len) - *packetp = hw->rx_packet; + *packetp = hw->rx_packet[hw->rx_last]; return len ? len : -EAGAIN; } diff --git a/drivers/net/e1000.h b/drivers/net/e1000.h index f83e3a0b33..be3fce4bb6 100644 --- a/drivers/net/e1000.h +++ b/drivers/net/e1000.h @@ -1136,7 +1136,7 @@ struct e1000_hw { e1000_dsp_config dsp_config_state; struct e1000_rx_desc *rx_base; - unsigned char *rx_packet; + unsigned char *rx_packet[NUM_RX_DESC]; int rx_tail; int rx_last; };