Files
kernel/kernel-modules/bnxt_en/centos/bnxt_en.spec
M. Vefa Bicakci 0ae9f6bd53 Add Broadcom NetXtreme-E drivers
This commit introduces Broadcom's bnxt_en and bnxt_re out-of-tree
drivers, version 220.0.13.0, to StarlingX, and disables the in-tree
bnxt_en driver. (For clarity, the main driver package file name is
"bcm_220.0.83.0.tar.gz".)

There is a need to build Broadcom's driver against the version of the
Infiniband/RDMA code base bundled with Mellanox OFED (OpenFabrics
Enterprise Distribution), because the in-tree kernel Infiniband/RDMA
modules are disabled, and Mellanox OFED's out-of-tree Infiniband/RDMA
modules replace the in-tree versions.

A custom spec file was used, despite the fact that the Broadcom device
driver package includes a source RPM file. This was necessary due to two
reasons:

- The source RPM file has whitespace between its field labels (such as
  Name, Version, Release, and so on) and the values of these fields.
  (Example: "Name   :  bnxt_en") This unfortunately breaks "build-pkgs
  --edit", which cannot handle the whitespace during the extraction of
  the source RPM.

- More importantly, the spec file included by Broadcom has the following
  lines in its %prep section, which does not use the %setup macro:

  %prep
  #%setup
  mkdir -p source
  tar -xzvf %{SOURCE0} -C source/
  mv -f source/netxtreme-%name-%{version}-220.0.13.0/* source/
  rm -rf source/netxtreme-%name-%{version}-220.0.13.0/
  cp ./source/%{bnxt_re_driver}/README.TXT
  ./source/%{bnxt_re_driver}/%{bnxt_re_driver}_README.TXT
  cp ./source/%{bnxt_en_driver}/README.TXT
  ./source/%{bnxt_en_driver}/%{bnxt_en_driver}_README.TXT
  mkdir -p obj

  This is problematic, because the "build-pkgs --edit" procedure
  extracts the source RPM multiple times into the same directory to
  ensure that the extraction is stable. However, the %prep section
  quoted above does not remove the 'source' directory before attempting
  to populate it. (Unfortunately, this issue is not patchable using a
  meta-patch, because the extraction occurs even before the application
  of meta-patches.) This in turn triggers the following errors:

  + mv -f source/netxtreme-bnxt_en-1.10.2-220.0.13.0/Makefile \
    source/netxtreme-bnxt_en-1.10.2-220.0.13.0/bnxt_en \
    source/netxtreme-bnxt_en-1.10.2-220.0.13.0/bnxt_en-1.10.2-220.0.13.0 \
    source/netxtreme-bnxt_en-1.10.2-220.0.13.0/bnxt_re \
    source/netxtreme-bnxt_en-1.10.2-220.0.13.0/bnxt_re-220.0.12.0 \
    source/
  mv: cannot move 'source/netxtreme-bnxt_en-1.10.2-220.0.13.0/bnxt_en-1.10.2-220.0.13.0' \
    to 'source/bnxt_en-1.10.2-220.0.13.0': Directory not empty
  mv: cannot move 'source/netxtreme-bnxt_en-1.10.2-220.0.13.0/bnxt_re-220.0.12.0' \
    to 'source/bnxt_re-220.0.12.0': Directory not empty
  error: Bad exit status from .../std/srpm_work/bnxt_en/var/tmp/rpm-tmp.cDTpOP (%prep)
      Bad exit status from .../std/srpm_work/bnxt_en/var/tmp/rpm-tmp.cDTpOP (%prep)

The changes made to the spec file are as follows:

- Reliance on Red Hat's kernel module packaging RPM spec macros (such as
  %kernel_module_package) is removed, because the aforementioned macros
  make use of the kmodtool helper program, which automatically generates
  an RPM post-installation and post-uninstallation sections making use
  of the weak-modules utility, which StarlingX does not use/support. It
  is not possible to disable this behaviour of the kmodtool script
  ("/usr/lib/rpm/redhat/kmodtool") with a command line option or an
  environment variable.

- The spec file is reorganized to build the kernel module against only a
  single kernel "flavour", as StarlingX does not use the kernel flavour
  concept.

- The %build process is modified so that instead of using the top-level
  makefile (which does not take certain variables as arguments), the
  bnxt_en- and bnxt_re-specific makefiles are called with make
  separately. This allows passing KDIR, KVER and OFED_VERSION make
  variables as command line arguments to make.

- The use of the devtoolset-8 software collection was added to align to
  the kernel's build toolchain.

- The spec file is modified to detect the OFED version and pass the
  version to the bnxt_re makefile as the OFED_VERSION environment
  variable. This is necessary to automatically adapt to the version of
  OFED installed in the build environment.

- The %post and %postun scriptlets are modified to make them similar to
  the ones used by i40e, which passes the target kernel's version to
  depmod. The original %post only had 'depmod -a', which can be
  problematic when installing the package for a kernel that is not
  currently running.

- Kernel module signing was added to %install. This shell snippet was
  adapted from i40e.

- Finally, retpolines were enabled by default, given that StarlingX
  enables retpolines in its kernel packages as well.

In terms of source code modifications, the following changes were made
to bnxt_en and bnxt_re:

- The bnxt_en and bnxt_re kernel modules are patched to make use of the
  irq_update_affinity_hint function instead of the irq_set_affinity_hint
  function, so that the irqaffinity= kernel command line option takes
  effect for the affinities of the IRQs managed by the two drivers.

  However, it should be noted the changes in bnxt_en are not truly
  necessary, because pre-existing conditional compilation directives
  leave out the modified code when targeting kernels >= v4.15 or kernels
  that have the "IRQ matrix allocator" feature. The changes are kept for
  completeness, nevertheless.

  For further details, please see the patch description.

- A compilation failure caused by the definition of a placeholder macro
  aimed to stand in for the bpf_warn_invalid_xdp_action function in the
  kernel tree is resolved by removing the macro definition.

Testing:
- An ISO image was successfully built with a monolithic incremental
  build procedure.

- Using a virtual machine in All-in-One simplex configuration, the
  bnxt_en and bnxt_re kernel modules were confirmed to be successfully
  loaded manually using, for example, "modprobe -v -a bnxt_en bnxt_re".
  Runtime tests for these drivers were unfortunately very limited,
  because the necessary hardware has not yet been acquired. We intend to
  resolve integration issues when hardware is acquired.

Story: 2009915
Task: 44762

Depends-On: https://review.opendev.org/c/starlingx/kernel/+/833463
Depends-On: https://review.opendev.org/c/starlingx/tools/+/833462

Change-Id: Ieb4147335410160a781382b0b6b01e2015468a3b
Signed-off-by: M. Vefa Bicakci <vefa.bicakci@windriver.com>
2022-03-23 10:21:10 -04:00

136 lines
4.2 KiB
RPMSpec

%if "%{?_tis_build_type}" == "rt"
%define bt_ext -rt
%else
%undefine bt_ext
%endif
%define kmod_name bnxt_en
%define upstream_release 220.0.13.0
## Condition to check if retpolines are needed.
## Default: retpolines are enabled.
%bcond_without retpoline
%define kernel_module_package_buildreqs kernel%{?bt_ext}-devel
# Disable the building of debug package(s).
%define debug_package %{nil}
Name: kmod-%{kmod_name}%{?bt_ext}
Version: 1.10.2
Release: %{upstream_release}%{?_tis_dist}.%{tis_patch_ver}
Group: System Environment/Base
Packager: StarlingX Community
Vendor: Broadcom Inc
URL: https://www.broadcom.com/support/download-search?pg=&pf=&pn=&pa=&po=&dk=bnxt_en&pl=
License: GPLv2
Summary: Broadcom NetXtreme Gigabit Ethernet Driver
Provides: %{kmod_name}-kmod = %{?epoch:%{epoch}:}%{version}-%{release}
BuildRequires: devtoolset-8-build
BuildRequires: devtoolset-8-binutils
BuildRequires: devtoolset-8-gcc
BuildRequires: devtoolset-8-make
BuildRequires: kernel%{?bt_ext}-devel findutils
BuildRequires: mlnx-ofa_kernel%{?bt_ext}-devel mlnx-ofa_kernel%{?bt_ext}-source
Requires: mlnx-ofa_kernel%{?bt_ext}-modules
Requires(post): /usr/sbin/depmod
Requires(postun): /usr/sbin/depmod
Source0: netxtreme-%{kmod_name}-%{version}-%{upstream_release}.tar.gz
Patch0001: 0001-bnxt_re-Makefile-Adapt-to-mlnx-ofa_kernel-for-Starli.patch
Patch0002: 0002-bnxt_en-bnxt_compat.h-Fix-up-a-build-failure.patch
Patch0003: 0003-bnxt_en-bnxt_re-Use-irq_update_affinity_hint.patch
#define some build variables required
%define bnxt_en_driver bnxt_en
%define bnxt_re_driver bnxt_re
%define kversion %(rpm -q kernel%{?bt_ext}-devel | sort --version-sort | tail -1 | sed 's/kernel%{?bt_ext}-devel-//')
%description
This package provides the %{bnxt_en_driver} and %{bnxt_re_driver} kernel
modules built for the Linux kernel for the %{_target_cpu} family of processors.
%prep
%autosetup -p 1 -n netxtreme-%{kmod_name}-%{version}-%{upstream_release}
cp %{bnxt_re_driver}/README.TXT %{bnxt_re_driver}/%{bnxt_re_driver}_README.TXT
cp %{bnxt_en_driver}/README.TXT %{bnxt_en_driver}/%{bnxt_en_driver}_README.TXT
%build
%if 0%{?rhel} == 7
source scl_source enable devtoolset-8 || :
%endif
export EXTRA_CFLAGS+='-DVERSION=\"%{version}\"'
%if %{with retpoline}
find . -name *.c -print0 | xargs -0 sed -i '/MODULE_LICENSE(/a MODULE_INFO(retpoline, "Y");'
%endif
# Regenerate MANIFEST HASH
if [ -e bnxt_en/MANIFEST ]; then
pushd bnxt_en >/dev/null
sha512sum $(cat MANIFEST | cut -c 131-) > MANIFEST
popd >/dev/null
fi
%{__make} %{_smp_mflags} -C bnxt_en \
KVER=%{kversion} \
KDIR=%{_usrsrc}/kernels/%{kversion}
OFED_VERSION="$(ls -1vd %{_usrsrc}/ofa_kernel-* | xargs -r -n1 basename | \
sed -e 's@^ofa_kernel-@@' | sort --version-sort | tail -n1)"
if test -z "${OFED_VERSION}"; then
echo "Error: Could not detect the OFED version"
exit 1
fi
%{__make} %{_smp_mflags} -C bnxt_re \
KVER=%{kversion} \
KDIR=%{_usrsrc}/kernels/%{kversion} \
OFED_VERSION="${OFED_VERSION}"
%install
export KVER=%{kversion}
dest_dir_bnxt_en=${RPM_BUILD_ROOT}/lib/modules/${KVER}/extra/%{kmod_name}/
src_dir_bnxt_en=$(find . -name %{bnxt_en_driver}.ko)
dest_dir_bnxt_re=${RPM_BUILD_ROOT}/lib/modules/${KVER}/extra/%{kmod_name}/drivers/infiniband/hw/%{bnxt_re_driver}/
src_dir_bnxt_re=$(find . -name %{bnxt_re_driver}.ko)
mkdir -p ${dest_dir_bnxt_en}
mkdir -p ${dest_dir_bnxt_re}
install -m 744 ${src_dir_bnxt_en} ${dest_dir_bnxt_en}
install -m 744 ${src_dir_bnxt_re} ${dest_dir_bnxt_re}
### Adapted from i40e
# Strip the modules(s).
find %{buildroot} -type f -name \*.ko -exec %{__strip} --strip-debug \{\} \;
# Always Sign the modules(s).
# If the module signing keys are not defined, define them here.
%{!?privkey: %define privkey /usr/src/kernels/%{kversion}/signing_key.pem}
%{!?pubkey: %define pubkey /usr/src/kernels/%{kversion}/signing_key.x509}
for module in $(find %{buildroot} -type f -name \*.ko);
do /usr/src/kernels/%{kversion}/scripts/sign-file \
sha256 %{privkey} %{pubkey} $module;
done
%files
%defattr(644,root,root,755)
/lib/modules/%{kversion}/extra/%{kmod_name}/
%post
if [ -e "/boot/System.map-%{kversion}" ]; then
/usr/sbin/depmod -aeF "/boot/System.map-%{kversion}" "%{kversion}" > /dev/null || :
fi
%postun
/usr/sbin/depmod -a >/dev/null 2>&1 || true
%clean
rm -rf %{buildroot}
%changelog