File r8168.spec of Package r8168

#
# spec file for package r8168
#
# Copyright (c) 2019 Packman Team <packman@links2linux.de>
# Copyright (c) 2017 SUSE LINUX Products GmbH, Nuernberg, Germany.
#
# All modifications and additions to the file contributed by third parties
# remain the property of their copyright owners, unless otherwise agreed
# upon. The license for this file, and modifications and additions to the
# file, is the same license as for the pristine package itself (unless the
# license for the pristine package is not an Open Source License, in which
# case the license is the MIT License). An "Open Source License" is a
# license that conforms to the Open Source Definition (Version 1.9)
# published by the Open Source Initiative.

# Please submit bugfixes or comments via https://bugs.links2linux.org/
#

#!BuildIgnore: enough-build-resources
Name:           r8168
Version:        8.053.00
Release:        1699.2.pm.220
Summary:        Device driver for RealTek Gigabit Ethernet controllers
License:        GPL-2.0-or-later
Group:          System/Kernel
URL:            https://github.com/mtorromeo/r8168
Source0:        https://github.com/mtorromeo/r8168/archive/%{version}.tar.gz#/%{name}-%{version}.tar.gz
Source1:        preamble
Source2:        Module.supported
Source3:        https://github.com/mtorromeo/r8168/releases/download/%{version}/%{name}-%{version}.tar.gz.asc
Source4:        r8168.keyring
Patch0:         r8168-kernel_version.patch
Patch1:         r8168-configuration.patch
Patch2:         r8168-support-linux-5.19.patch
Patch3:         r8168-support-ethtool_keee.patch
Patch4:         r8168-support-dev0x8136.patch
Patch5:         r8168-support-linux-L15.5.patch
BuildRequires:  kernel-source
BuildRequires:  kernel-syms
BuildRequires:  libelf-devel
BuildRequires:  module-init-tools
BuildRequires:  %kernel_module_package_buildreqs
Requires:       r8168-kmp
ExclusiveArch:  %{ix86} x86_64
%kernel_module_package -p preamble

%description
This is the Linux device driver released for RealTek RTL8168B/8111B,
RTL8168C/8111C, RTL8168CP/8111CP, RTL8168D/8111D, RTL8168DP/8111DP,
and RTL8168E/8111E Gigabit Ethernet controllers with PCI-Express interface.

%package blacklist-r8169
Summary:        To favour r8168 blacklist the r8169 device driver
Group:          Hardware/Wifi
##BuildArch:      noarch
Requires:       %{name}-kmp = %{version}

%description blacklist-r8169
On many Realtek Ethernet controllers the old device driver r8169 does
not work reliably.  To solve this the r8169 kernel module has to be
blacklisted to enable the system to load the new device driver r8168.

%prep
version=$(readlink /usr/src/linux | sed -r 's/linux-//;s/-.*//;s/\./,/g')
[[ "$version" =~ [0-9]+,[0-9]+,[0-9]+ ]] || \
version=$(uname -r|sed -r 's/-.*//;s/\./,/g')
%setup -q
%patch -P 0 -b .p0
%patch -P 1 -b .p1
%patch -P 2 -p1 -b .p2
%patch -P 4 -p1 -b .p4
if test -e /usr/src/linux/include/linux/ethtool.h
then
    argc=$(sed -rn '/\*get_ringparam/,/;$/p' /usr/src/linux/include/linux/ethtool.h | wc -l)
    if test -n "$argc" -a "$argc" -eq 4
    then
%patch -P 5 -b .p5
    fi
    argc=$(sed -rn '/ethtool_keee/p' /usr/src/linux/include/linux/ethtool.h | wc -l)
    if test -n "$argc" -a "$argc" -eq 3
    then
%patch -P 3 -p1 -b .p3
	sed -ri "/KERNEL_VERSION/{s/\(6,9,0\)/(${version})/}" src/r8168_n.c
    fi
fi
if test -e /usr/src/linux/include/net/gso.h
then
    sed -ri "/KERNEL_VERSION/{s/\(6,4,10\)/(${version})/}" src/r8168_n.c
fi
cp %{S:1} .
cp %{S:2} .

%build
#
# SUSE kernel does include some patches/commits which do not increase
# the kernel's version, there we test here if the linux/pci-acpi.h exits
#
if test -e /usr/src/linux/include/linux/pci-aspm.h
then
    sed -ri '/#define HAS_PCI_ASPM_H/{ s/@ASPM@/1/ }' src/r8168_n.c
else
    sed -ri '/#define HAS_PCI_ASPM_H/{ s/@ASPM@/0/ }' src/r8168_n.c
fi
ln -sf $(type -p kmod) modinfo
mkdir obj
for flavor in %{flavors_to_build}
do
    rm   -rf obj/$flavor
    cp   -rp src obj/$flavor
    make V=1 -C %{kernel_source $flavor} M=$PWD/obj/$flavor modules
    ./modinfo -F alias $(find $PWD/obj/$flavor/ -name '%{name}.ko')
done

%install
export INSTALL_MOD_PATH=%{buildroot}
export INSTALL_MOD_DIR=updates
for flavor in %{flavors_to_build}
do
    make -C %{kernel_source $flavor} M=$PWD/obj/$flavor modules_install
done
mkdir -p %{buildroot}%{_sysconfdir}/modprobe.d/
cat > %{buildroot}%{_sysconfdir}/modprobe.d/50-blacklist-r8169.conf<<-'EOF'
	# On many Realtek Ethernet controllers the old device driver r8169 does
	# not work reliably.  To solve this the r8169 kernel module has to be
	# blacklisted to enable the system to load the new device driver r8168.
	blacklist r8169
	EOF

%files blacklist-r8169
%config %{_sysconfdir}/modprobe.d/50-blacklist-r8169.conf

%changelog
* Mon Nov 25 2024 Dr. Werner Fink <werner@suse.de>
- Make it build below SLE-15-SP7 even if kernel version 6.4
  includes a feature for ethtool from kernel version 6.9
* Tue May 21 2024 Dr. Werner Fink <werner@suse.de>
- Update to new version r8168-8.053.00
- Remove patches now upstream
  * r8168-gcc14.patch
- Port patches
  * r8168-kernel_version.patch
  * r8168-support-dev0x8136.patch
  * r8168-support-linux-5.19.patch
- Add patch r8168-support-ethtool_keee.patch
  * Port struct ethtool_eee to new kernel struct ethtool_eee
    and hopefully this works
* Thu Mar 28 2024 Dr. Werner Fink <werner@suse.de>
- Use kernel version of the include diretory instead of the used
  kernel
* Wed Mar 13 2024 Dr. Werner Fink <werner@suse.de>
- Update to new version r8168-8.052.01
- Remove patches now upstream
  * skb_gso_segment.patch
  * r8168-support-linux-6.1.0.patch
- Port patches
  * r8168-configuration.patch
  * r8168-kernel_version.patch
  * r8168-support-dev0x8136.patch
  * r8168-support-linux-5.19.patch
  * r8168-support-linux-L15.5.patch
- Add r8168.keyring and signature of tar ball to check tar ball
- Add patch r8168-gcc14.patch
  * Avoid gcc14 trouble
  * Switch from deprecated strlcpy() to strscpy()
* Wed Mar 13 2024 Dr. Werner Fink <werner@suse.de>
- Use %%patch -P N instead of deprecated %%patchN.
* Thu Oct 19 2023 Dr. Werner Fink <werner@suse.de>
- Dynamic adaption of patch skb_gso_segment.patch means if net/gso.h
  exists correct kernel version check
  Mon Aug 14 11:23:04 UTC 2023 - https://www.suse.com/
- Add patch skb_gso_segment.patch to make it build with latest 6.4
  Wed May 10 10:55:42 UTC 2023 - https://www.suse.com/
- For Leap 15.5 the kernel 5.14.0 behaves like a 5.17.0 at ethtool.h
* Wed Dec 14 2022 Dr. Werner Fink <werner@suse.de>
- Update to new version r8168-8.051.02
- Delete patch r8168-kernel_5.18.patch now upstream
- Add patch r8168-support-linux-6.1.0.patch
- Add patch r8168-support-dev0x8136.patch to support
  Realtek Semiconductor Co.,
  Ltd. RTL810xE PCI Express Fast Ethernet controller [10ec:8136] (rev 05)
* Tue Dec  6 2022 Werner Fink <werner.fink@opensuse.org>
- Switch over to build require %%kernel_module_package_buildreqs macro
* Mon Dec  5 2022 Dr. Werner Fink <werner@suse.de>
- Also pre require suse-module-tools-scriptlets
* Fri Dec  2 2022 Dr. Werner Fink <werner@suse.de>
- Pre require suse-module-tools
* Fri Aug  5 2022 Dr. Werner Fink <werner@suse.de>
- Update to new version 8.050.03
- Add patch r8168-support-linux-5.19.patch to get it build with 5.19
* Tue May 24 2022 Dr. Werner Fink <werner@suse.de>
- Add upstream patch r8168-kernel_5.18.patch
  * Make it build with kernel 5.18+
* Tue May 10 2022 Werner Fink <werner@suse.de>
- Update to new version 8.050.00
- Port patches r8168-kernel_version.patch and r8168-configuration.patch
* Thu Jan 21 2021 Werner Fink <werner@suse.de>
- Now we change to github for basic download
- Configure exisxtence of linux/pci-aspm.h on the fly
* Tue Jun  2 2020 Luigi Baldoni <aloisio@gmx.com>
- Update to version 8.048.03
- Drop 83b957b4.patch (fixed upstream)
* Tue Mar 31 2020 Werner Fink <werner@suse.de>
- Add patch 83b957b4.patch to get it build for kernel 5.6
* Mon Feb 10 2020 Werner Fink <werner@suse.de>
- Update to new version 8.048.00
- Modify patch r8168-kernel_version.patch as upstream now supports 5.4
* Tue Nov 26 2019 Werner Fink <werner@suse.de>
- Update to new version 8.047.05
- Modify patch r8168-kernel_version.patch to let it build with 5.4
* Thu Oct 24 2019 Werner Fink <werner@suse.de>
- (Re)add #!BuildIgnore: enough-build-resources
* Tue Oct 22 2019 Werner Fink <werner@suse.de>
- Update to new version 8.047.04
* Wed Jun  5 2019 Luigi Baldoni <aloisio@gmx.com>
- Spec cleanup
* Fri May 24 2019 Werner Fink <werner@suse.de>
- Update to new version 8.047.01
- Remove patch r8168-kernel-4.15-2.patch as now upstream
- Modify patch kernel_version.patch
* Sun Feb  4 2018 werner.fink@opensuse.org
- Add patch r8168-kernel-4.15-2.patch to be prepared for kernel
  4.15+, dropped setup_timer
* Wed Jan 10 2018 werner.fink@opensuse.org
- Update to version r8168-8.045.08
* Thu Aug 10 2017 werner@suse.de
- Rework build of module, that is use obj directory
* Thu Aug  3 2017 werner@suse.de
- Initial package for missing kernel device driver r8168 8.044.02
openSUSE Build Service is sponsored by