From 6239191835366eac2a80a4426bb4312d2b67e7b3 Mon Sep 17 00:00:00 2001 From: Rodrigo Arias Mallo Date: Thu, 5 Sep 2024 07:41:54 +0200 Subject: [PATCH] Add custom Ethernet module --- ethernet-driver-build.patch | 21 ++++++++++++ ethernet-driver-kbuild.patch | 7 ++++ ethernet-driver-poll.patch | 23 +++++++++++++ lagarto-ox.nix | 65 +++++++++++++++++++++++------------- 4 files changed, 92 insertions(+), 24 deletions(-) create mode 100644 ethernet-driver-build.patch create mode 100644 ethernet-driver-kbuild.patch create mode 100644 ethernet-driver-poll.patch diff --git a/ethernet-driver-build.patch b/ethernet-driver-build.patch new file mode 100644 index 0000000..a0736a2 --- /dev/null +++ b/ethernet-driver-build.patch @@ -0,0 +1,21 @@ +diff --git a/drivers/xxvnet_carv.c b/drivers/xxvnet_carv.c +index d3f60f9..9fd4c21 100644 +--- a/drivers/xxvnet_carv.c ++++ b/drivers/xxvnet_carv.c +@@ -36,6 +36,7 @@ + #include + #include + #include ++#include + + #include "xxvnet_carv.h" + +@@ -1511,7 +1512,7 @@ axienet_dma_probe(struct platform_device *pdev, struct net_device *ndev) + spin_lock_init(&q->tx_lock); + spin_lock_init(&q->rx_lock); + +- netif_napi_add(ndev, &lp->napi, axienet_rx_poll, AXIENET_NAPI_WEIGHT); ++ netif_napi_add(ndev, &lp->napi, axienet_rx_poll); + + return 0; + } diff --git a/ethernet-driver-kbuild.patch b/ethernet-driver-kbuild.patch new file mode 100644 index 0000000..32fa1af --- /dev/null +++ b/ethernet-driver-kbuild.patch @@ -0,0 +1,7 @@ +diff --git a/drivers/Kbuild b/drivers/Kbuild +index 28d6c0f..7f02860 100644 +--- a/drivers/Kbuild ++++ b/drivers/Kbuild +@@ -1,2 +1 @@ + obj-m := xxvnet_carv.o +-obj-m := xilinx_dma.o diff --git a/ethernet-driver-poll.patch b/ethernet-driver-poll.patch new file mode 100644 index 0000000..db2b8a9 --- /dev/null +++ b/ethernet-driver-poll.patch @@ -0,0 +1,23 @@ +diff --git a/drivers/xxvnet_carv.c b/drivers/xxvnet_carv.c +index eb664bb..d3f60f9 100644 +--- a/drivers/xxvnet_carv.c ++++ b/drivers/xxvnet_carv.c +@@ -1435,12 +1435,12 @@ static void axienet_poll_controller(struct net_device *ndev) + { + struct axienet_local *lp = netdev_priv(ndev); + +- disable_irq(lp->tx_irq); +- disable_irq(lp->rx_irq); +- axienet_rx_irq(lp->tx_irq, ndev); +- axienet_tx_irq(lp->rx_irq, ndev); +- enable_irq(lp->tx_irq); +- enable_irq(lp->rx_irq); ++ disable_irq(lp->dq->tx_irq); ++ disable_irq(lp->dq->rx_irq); ++ axienet_rx_irq(lp->dq->tx_irq, ndev); ++ axienet_tx_irq(lp->dq->rx_irq, ndev); ++ enable_irq(lp->dq->tx_irq); ++ enable_irq(lp->dq->rx_irq); + } + #endif + diff --git a/lagarto-ox.nix b/lagarto-ox.nix index 02fedcd..8ac9b50 100644 --- a/lagarto-ox.nix +++ b/lagarto-ox.nix @@ -74,6 +74,14 @@ boot.kernelPackages = pkgs.linuxPackages_latest; boot = { + extraModulePackages = [ + # Add the custom Ethernet module + pkgs.xilinx-axienet-carv + ]; + kernelModules = [ + # Load the Ethernet module by default + "xilinx_axienet_carv" + ]; kernelPatches = [ { name = assert false; "sbi-early-console"; @@ -418,29 +426,38 @@ #./ox-alveo-platform-plic.patch ]; }); -# opensbi = prev.opensbi.overrideAttrs (old: { -# #NIX_DEBUG=5; -# # Compile dts to dtb form -# #nativeBuildInputs = (old.nativeBuildInputs or []) ++ [ prev.buildPackages.dtc ]; -# #preBuild = '' -# # dtc -O dtb -o ox.dtb ${./ox.dts} -# #''; -# makeFlags = old.makeFlags ++ [ -# "PLATFORM=fpga/sargantana_alveo" -# #"PLATFORM_RISCV_ISA=rv64imafd" # No compressed instructions -# "PLATFORM_RISCV_ISA=rv64g" # No compressed instructions -# #"PLATFORM_RISCV_ABI=lp64d" -# "FW_PAYLOAD_PATH=${final.uboot}/u-boot-nodtb.bin" -# #"FW_FDT_PATH=ox.dtb" -# ]; -# patches = [ ./alveo-uart-sbi-hack.patch ]; -# }); -# opensbi = prev.opensbi.overrideAttrs (old: { -# makeFlags = old.makeFlags ++ [ -# "PLATFORM=fpga/openpiton" -# "FW_PAYLOAD_PATH=${final.uboot}/u-boot-nodtb.bin" -# ]; -# patches = [ ./opensbi-lagarto-hun.patch ]; -# }); + + # Custom kernel driver for the Ethernet + xilinx-axienet-carv = let + kernel = config.boot.kernelPackages.kernel; + in prev.stdenv.mkDerivation rec { + pname = "xilinx-axienet-carv"; + version = src.shortRev; + src = builtins.fetchGit { + url = "git@gitlab-internal.bsc.es:meep/meep-os/lagarto-openpiton-sdk.git"; + rev = "d2ae2e788bf1cc60676599184a9ec1128cc81d81"; + ref = "master"; + }; + patches = [ + ./ethernet-driver-poll.patch + ./ethernet-driver-build.patch + ./ethernet-driver-kbuild.patch + ]; + preConfigure = '' + export sourceRoot=$PWD/drivers + cd drivers + #rm Makefile + ''; + + nativeBuildInputs = kernel.moduleBuildDependencies; + makeFlags = kernel.makeFlags ++ [ + "-C" + "${kernel.dev}/lib/modules/${kernel.modDirVersion}/build" + "M=$(PWD)" + ]; + buildFlags = [ "modules" ]; + installFlags = [ "INSTALL_MOD_PATH=${placeholder "out"}" ]; + installTargets = [ "modules_install" ]; + }; }) ]; }