ice: remove circular header dependencies on ice.h
Jacob Keller authored

Several headers in the ice driver include ice.h even though they are
themselves included by that header. The most notable of these is
ice_common.h, but several other headers also do this.

Such a recursive inclusion is problematic as it forces headers to be
included in a strict order, otherwise compilation errors can result. The
circular inclusions do not trigger an endless loop due to standard
header inclusion guards, however other errors can occur.

For example, ice_flow.h defines ice_rss_hash_cfg, which is used by
ice_sriov.h as part of the definition of ice_vf_hash_ip_ctx.

ice_flow.h includes ice_acl.h, which includes ice_common.h, and which
finally includes ice.h. Since ice.h itself includes ice_sriov.h, this
creates a circular dependency.

The definition in ice_sriov.h requires things from ice_flow.h, but
ice_flow.h itself will lead to trying to load ice_sriov.h as part of its
process for expanding ice.h. The current code avoids this issue by
having an implicit dependency without the include of ice_flow.h.

If we were to fix that so that ice_sriov.h explicitly depends on
ice_flow.h the following pattern would occur:

  ice_flow.h -> ice_acl.h -> ice_common.h -> ice.h -> ice_sriov.h

At this point, during the expansion of, the header guard for ice_flow.h
is already set, so when ice_sriov.h attempts to load the ice_flow.h
header it is skipped. Then, we go on to begin including the rest of
ice_sriov.h, including structure definitions which depend on
ice_rss_hash_cfg. This produces a compiler warning because
ice_rss_hash_cfg hasn't yet been included. Remember, we're just at the
start of ice_flow.h!

If the order of headers is incorrect (ice_flow.h is not implicitly
loaded first in all files which include ice_sriov.h) then we get the
same failure.

Removing this recursive inclusion requires fixing a few cases where some
headers depended on the header inclusions from ice.h. In addition, a few
other changes are also required.

Most notably, ice_hw_to_dev is implemented as a macro in ice_osdep.h,
which is the likely reason that ice_common.h includes ice.h at all. This
macro implementation requires the full definition of ice_pf in order to
properly compile.

Fix this by moving it to a function declared in ice_main.c, so that we
do not require all files to depend on the layout of the ice_pf
structure.

Note that this change only fixes circular dependencies, but it does not
fully resolve all implicit dependencies where one header may depend on
the inclusion of another. I tried to fix as many of the implicit
dependencies as I noticed, but fixing them all requires a somewhat
tedious analysis of each header and attempting to compile it separately.
Signed-off-by: default avatarJacob Keller <jacob.e.keller@intel.com>
Tested-by: Gurucharan G <gurucharanx.g@intel.com> (A Contingent worker at Intel)
Signed-off-by: default avatarTony Nguyen <anthony.l.nguyen@intel.com>
649c87c6
Name Last commit Last update
Documentation dt-bindings: phy: add bindings for Lynx 28G PHY
LICENSES LICENSES/LGPL-2.1: Add LGPL-2.1-or-later as valid identifiers
arch arch: arm64: dts: lx2160a: describe the SerDes block #1
block block: fix blk_mq_attempt_bio_merge and rq_qos_throttle protection
certs certs: Fix build error when CONFIG_MODULE_SIG_KEY is empty
crypto crypto: af_alg - get rid of alg_memory_allocated
drivers ice: remove circular header dependencies on ice.h
fs Merge tag 'fuse-fixes-5.17-rc8' of git://git.kernel.org/pub/scm/linux/kernel/git/mszeredi/fuse
include net: disable preemption in dev_core_stats_XXX_inc() helpers
init Merge https://git.kernel.org/pub/scm/linux/kernel/git/bpf/bpf-next
ipc ipc/sem: do not sleep with a spin lock held
kernel Merge git://git.kernel.org/pub/scm/linux/kernel/git/netdev/net
lib Merge https://git.kernel.org/pub/scm/linux/kernel/git/bpf/bpf-next
mm mm: gup: make fault_in_safe_writeable() use fixup_user_fault()
net net: dsa: report and change port dscp priority using dcbnl
samples Merge git://git.kernel.org/pub/scm/linux/kernel/git/netdev/net
scripts scripts/pahole-flags.sh: Parse DWARF and generate BTF with multithreading.
security net: rtnetlink: Add RTM_SETSTATS
sound Merge git://git.kernel.org/pub/scm/linux/kernel/git/netdev/net
tools selftests: tc-testing: Increase timeout in tdc config file
usr kbuild: remove include/linux/cyclades.h from header file check
virt KVM: Fix lockdep false negative during host resume
.clang-format genirq/msi: Make interrupt allocation less convoluted
.cocciconfig scripts: add Linux .cocciconfig for coccinelle
.get_maintainer.ignore Opt out of scripts/get_maintainer.pl
.gitattributes
.gitignore
.mailmap
COPYING
CREDITS
Kbuild
Kconfig
MAINTAINERS
Makefile
README
Linux kernel
============

There are several guides for kernel developers and users. These guides can
be rendered in a number of formats, like HTML and PDF. Please read
Documentation/admin-guide/README.rst first.

In order to build the documentation, use ``make htmldocs`` or
``make pdfdocs``.  The formatted documentation can also be read online at:

    https://www.kernel.org/doc/html/latest/

There are various text files in the Documentation/ subdirectory,
several of them using the Restructured Text markup notation.

Please read the Documentation/process/changes.rst file, as it contains the
requirements for building and running the kernel, and information about
the problems which may result by upgrading your kernel.