From nobody Fri Dec 19 18:28:22 2025 Received: from esa.microchip.iphmx.com (esa.microchip.iphmx.com [68.232.153.233]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 319241991B4; Thu, 5 Sep 2024 08:07:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=68.232.153.233 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725523670; cv=none; b=kMtZ8j2Q7pJdhKGTHdrBXl/s3LcgXBR3iOb6Z1RkpjlSJCsucGDv7EkNfI3IAvme0lG/VV9SI1i2C5zHEWiqYBBCe4biCQF2lbz/pJWdZqo+JV8zouHa608/WlhhfK2CxiuZlpCXDXsU9KsMD1znpokXbdHgRPHIiCFG6q9ZWK0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725523670; c=relaxed/simple; bh=GLt2F6bBkswP8PhABvzG/5XUJcLw1iB4PPTJQ6Ssxz0=; h=From:Date:Subject:MIME-Version:Content-Type:Message-ID:References: In-Reply-To:To:CC; b=iWRS/Y/afGSqbhHRnNQDrrIkOQ7tBTLAo6jPNum93ZhgA7SoRukAoGL8pxGOkpDcLHoqtQV6No0CrNibiviQr/70OwK9LBL5KuCYkFMJiUU7gLkmyTADLhCtRrXxcBIsjGr5nXJ7Ag65CkQin041aBOvExDAye7hbzbCzXEvyBQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=microchip.com; spf=pass smtp.mailfrom=microchip.com; dkim=pass (2048-bit key) header.d=microchip.com header.i=@microchip.com header.b=lkZWGFwR; arc=none smtp.client-ip=68.232.153.233 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=microchip.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=microchip.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=microchip.com header.i=@microchip.com header.b="lkZWGFwR" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=microchip.com; i=@microchip.com; q=dns/txt; s=mchp; t=1725523669; x=1757059669; h=from:date:subject:mime-version:content-transfer-encoding: message-id:references:in-reply-to:to:cc; bh=GLt2F6bBkswP8PhABvzG/5XUJcLw1iB4PPTJQ6Ssxz0=; b=lkZWGFwRrya0rh5I6bxBdjmsz2YPEJGsSDdFGy6cS6hKmT+IYYWcfGUC cRSQ6K4foki2R4YtXQoKpWCbqTVmQdUYfR06STyJHBvYrYl5bVjwvKdAB UEV+Cls1j3R1XzxE0xi/nbezKyFWXH50B5Xh1KnDeSaP89VyGf3Z9812s xM8c7YKZ4LCMveO6pQQDMcXYs7IQLM5bnspggdwdzZWiiSmESp5QGbgof KBGAcqB1Mh3NEuaMjnuhU/lLzzDliQTgbeO2sglQOFfBhCQ6xSco8CBo9 /Yb8XA6RH3yI91b6s9SprkWkQUjc7qZcF8zvCT8G/Nc4GucI2TEz90yJy Q==; X-CSE-ConnectionGUID: 7ewQ9CGBRIuJm60AkmofCw== X-CSE-MsgGUID: EPqxG7qeSDmyWDGl3k00kQ== X-IronPort-AV: E=Sophos;i="6.10,204,1719903600"; d="scan'208";a="34454185" X-Amp-Result: SKIPPED(no attachment in message) Received: from unknown (HELO email.microchip.com) ([170.129.1.10]) by esa1.microchip.iphmx.com with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 05 Sep 2024 01:07:47 -0700 Received: from chn-vm-ex02.mchp-main.com (10.10.85.144) by chn-vm-ex01.mchp-main.com (10.10.85.143) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.35; Thu, 5 Sep 2024 01:07:09 -0700 Received: from [10.205.21.108] (10.10.85.11) by chn-vm-ex02.mchp-main.com (10.10.85.144) with Microsoft SMTP Server id 15.1.2507.35 via Frontend Transport; Thu, 5 Sep 2024 01:07:07 -0700 From: Daniel Machon Date: Thu, 5 Sep 2024 10:06:35 +0200 Subject: [PATCH net-next 07/12] net: lan966x: use the FDMA library for allocation of tx buffers Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-ID: <20240905-fdma-lan966x-v1-7-e083f8620165@microchip.com> References: <20240905-fdma-lan966x-v1-0-e083f8620165@microchip.com> In-Reply-To: <20240905-fdma-lan966x-v1-0-e083f8620165@microchip.com> To: Horatiu Vultur , , "David S. Miller" , "Eric Dumazet" , Jakub Kicinski , Paolo Abeni , Alexei Starovoitov , Daniel Borkmann , Jesper Dangaard Brouer , "John Fastabend" CC: , , X-Mailer: b4 0.14-dev Use the two functions: fdma_alloc_phys() and fdma_dcb_init() for rx buffer allocation and use the new buffers throughout. In order to replace the old buffers with the new ones, we have to do the following refactoring: - use fdma_alloc_phys() and fdma_dcb_init() - replace the variables: tx->dma, tx->dcbs and tx->curr_entry with the equivalents from the FDMA struct. - add lan966x_fdma_tx_dataptr_cb callback for obtaining the dataptr. - Initialize FDMA struct values. Signed-off-by: Daniel Machon Reviewed-by: Horatiu Vultur --- .../net/ethernet/microchip/lan966x/lan966x_fdma.c | 75 ++++++++++--------= ---- .../net/ethernet/microchip/lan966x/lan966x_main.h | 16 ----- 2 files changed, 34 insertions(+), 57 deletions(-) diff --git a/drivers/net/ethernet/microchip/lan966x/lan966x_fdma.c b/driver= s/net/ethernet/microchip/lan966x/lan966x_fdma.c index 627806a10674..3afc6c4c68a4 100644 --- a/drivers/net/ethernet/microchip/lan966x/lan966x_fdma.c +++ b/drivers/net/ethernet/microchip/lan966x/lan966x_fdma.c @@ -23,6 +23,16 @@ static int lan966x_fdma_rx_dataptr_cb(struct fdma *fdma,= int dcb, int db, return 0; } =20 +static int lan966x_fdma_tx_dataptr_cb(struct fdma *fdma, int dcb, int db, + u64 *dataptr) +{ + struct lan966x *lan966x =3D (struct lan966x *)fdma->priv; + + *dataptr =3D lan966x->tx.dcbs_buf[dcb].dma_addr; + + return 0; +} + static int lan966x_fdma_channel_active(struct lan966x *lan966x) { return lan_rd(lan966x, FDMA_CH_ACTIVE); @@ -182,46 +192,22 @@ static void lan966x_fdma_rx_reload(struct lan966x_rx = *rx) lan966x, FDMA_CH_RELOAD); } =20 -static void lan966x_fdma_tx_add_dcb(struct lan966x_tx *tx, - struct lan966x_tx_dcb *dcb) -{ - dcb->nextptr =3D FDMA_DCB_INVALID_DATA; - dcb->info =3D 0; -} - static int lan966x_fdma_tx_alloc(struct lan966x_tx *tx) { struct lan966x *lan966x =3D tx->lan966x; struct fdma *fdma =3D &tx->fdma; - struct lan966x_tx_dcb *dcb; - struct lan966x_db *db; - int size; - int i, j; + int err; =20 tx->dcbs_buf =3D kcalloc(fdma->n_dcbs, sizeof(struct lan966x_tx_dcb_buf), GFP_KERNEL); if (!tx->dcbs_buf) return -ENOMEM; =20 - /* calculate how many pages are needed to allocate the dcbs */ - size =3D sizeof(struct lan966x_tx_dcb) * fdma->n_dcbs; - size =3D ALIGN(size, PAGE_SIZE); - tx->dcbs =3D dma_alloc_coherent(lan966x->dev, size, &tx->dma, GFP_KERNEL); - if (!tx->dcbs) + err =3D fdma_alloc_coherent(lan966x->dev, fdma); + if (err) goto out; =20 - /* Now for each dcb allocate the db */ - for (i =3D 0; i < fdma->n_dcbs; ++i) { - dcb =3D &tx->dcbs[i]; - - for (j =3D 0; j < fdma->n_dbs; ++j) { - db =3D &dcb->db[j]; - db->dataptr =3D 0; - db->status =3D 0; - } - - lan966x_fdma_tx_add_dcb(tx, dcb); - } + fdma_dcbs_init(fdma, 0, 0); =20 return 0; =20 @@ -238,7 +224,7 @@ static void lan966x_fdma_tx_free(struct lan966x_tx *tx) =20 kfree(tx->dcbs_buf); =20 - size =3D sizeof(struct lan966x_tx_dcb) * fdma->n_dcbs; + size =3D sizeof(struct fdma_dcb) * fdma->n_dcbs; size =3D ALIGN(size, PAGE_SIZE); dma_free_coherent(lan966x->dev, size, fdma->dcbs, fdma->dma); } @@ -252,9 +238,9 @@ static void lan966x_fdma_tx_activate(struct lan966x_tx = *tx) /* When activating a channel, first is required to write the first DCB * address and then to activate it */ - lan_wr(lower_32_bits((u64)tx->dma), lan966x, + lan_wr(lower_32_bits((u64)fdma->dma), lan966x, FDMA_DCB_LLP(fdma->channel_id)); - lan_wr(upper_32_bits((u64)tx->dma), lan966x, + lan_wr(upper_32_bits((u64)fdma->dma), lan966x, FDMA_DCB_LLP1(fdma->channel_id)); =20 lan_wr(FDMA_CH_CFG_CH_DCB_DB_CNT_SET(fdma->n_dbs) | @@ -349,22 +335,23 @@ static void lan966x_fdma_tx_clear_buf(struct lan966x = *lan966x, int weight) struct lan966x_tx *tx =3D &lan966x->tx; struct lan966x_rx *rx =3D &lan966x->rx; struct lan966x_tx_dcb_buf *dcb_buf; + struct fdma *fdma =3D &tx->fdma; struct xdp_frame_bulk bq; - struct lan966x_db *db; unsigned long flags; bool clear =3D false; + struct fdma_db *db; int i; =20 xdp_frame_bulk_init(&bq); =20 spin_lock_irqsave(&lan966x->tx_lock, flags); - for (i =3D 0; i < tx->fdma.n_dcbs; ++i) { + for (i =3D 0; i < fdma->n_dcbs; ++i) { dcb_buf =3D &tx->dcbs_buf[i]; =20 if (!dcb_buf->used) continue; =20 - db =3D &tx->dcbs[i].db[0]; + db =3D &fdma->dcbs[i].db[0]; if (!(db->status & FDMA_DCB_STATUS_DONE)) continue; =20 @@ -617,10 +604,10 @@ static void lan966x_fdma_tx_setup_dcb(struct lan966x_= tx *tx, int next_to_use, int len, dma_addr_t dma_addr) { - struct lan966x_tx_dcb *next_dcb; - struct lan966x_db *next_db; + struct fdma_dcb *next_dcb; + struct fdma_db *next_db; =20 - next_dcb =3D &tx->dcbs[next_to_use]; + next_dcb =3D &tx->fdma.dcbs[next_to_use]; next_dcb->nextptr =3D FDMA_DCB_INVALID_DATA; =20 next_db =3D &next_dcb->db[0]; @@ -635,13 +622,14 @@ static void lan966x_fdma_tx_setup_dcb(struct lan966x_= tx *tx, static void lan966x_fdma_tx_start(struct lan966x_tx *tx, int next_to_use) { struct lan966x *lan966x =3D tx->lan966x; - struct lan966x_tx_dcb *dcb; + struct fdma *fdma =3D &tx->fdma; + struct fdma_dcb *dcb; =20 if (likely(lan966x->tx.activated)) { /* Connect current dcb to the next db */ - dcb =3D &tx->dcbs[tx->last_in_use]; - dcb->nextptr =3D tx->dma + (next_to_use * - sizeof(struct lan966x_tx_dcb)); + dcb =3D &fdma->dcbs[tx->last_in_use]; + dcb->nextptr =3D fdma->dma + (next_to_use * + sizeof(struct fdma_dcb)); =20 lan966x_fdma_tx_reload(tx); } else { @@ -999,6 +987,11 @@ int lan966x_fdma_init(struct lan966x *lan966x) lan966x->tx.fdma.channel_id =3D FDMA_INJ_CHANNEL; lan966x->tx.fdma.n_dcbs =3D FDMA_DCB_MAX; lan966x->tx.fdma.n_dbs =3D FDMA_TX_DCB_MAX_DBS; + lan966x->tx.fdma.priv =3D lan966x; + lan966x->tx.fdma.size =3D fdma_get_size(&lan966x->tx.fdma); + lan966x->tx.fdma.db_size =3D PAGE_SIZE << lan966x->rx.page_order; + lan966x->tx.fdma.ops.nextptr_cb =3D &fdma_nextptr_cb; + lan966x->tx.fdma.ops.dataptr_cb =3D &lan966x_fdma_tx_dataptr_cb; lan966x->tx.last_in_use =3D -1; =20 err =3D lan966x_fdma_rx_alloc(&lan966x->rx); diff --git a/drivers/net/ethernet/microchip/lan966x/lan966x_main.h b/driver= s/net/ethernet/microchip/lan966x/lan966x_main.h index 8edb5ea484ee..99efc596c9e6 100644 --- a/drivers/net/ethernet/microchip/lan966x/lan966x_main.h +++ b/drivers/net/ethernet/microchip/lan966x/lan966x_main.h @@ -191,17 +191,6 @@ enum vcap_is1_port_sel_rt { =20 struct lan966x_port; =20 -struct lan966x_db { - u64 dataptr; - u64 status; -}; - -struct lan966x_tx_dcb { - u64 nextptr; - u64 info; - struct lan966x_db db[FDMA_TX_DCB_MAX_DBS]; -}; - struct lan966x_rx { struct lan966x *lan966x; =20 @@ -243,13 +232,8 @@ struct lan966x_tx { =20 struct fdma fdma; =20 - /* Pointer to the dcb list */ - struct lan966x_tx_dcb *dcbs; u16 last_in_use; =20 - /* Represents the DMA address to the first entry of the dcb entries. */ - dma_addr_t dma; - /* Array of dcbs that are given to the HW */ struct lan966x_tx_dcb_buf *dcbs_buf; =20 --=20 2.34.1