Skip to content

Commit

Permalink
Update kcompat generator
Browse files Browse the repository at this point in the history
  • Loading branch information
cardigliano committed Jan 10, 2024
1 parent 8a051a2 commit 0ee1a94
Show file tree
Hide file tree
Showing 2 changed files with 106 additions and 25 deletions.
88 changes: 70 additions & 18 deletions drivers/intel/ice/ice-1.12.7-zc/src/kcompat-generator.sh
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,12 @@ set -Eeuo pipefail
# Most of the implementation is in kcompat-lib.sh, here are actual 'gen' calls.

export LC_ALL=C
SCRIPT_DIR="$(dirname "${BASH_SOURCE[0]}")"
ORIG_CWD="$(pwd)"
trap 'rc=$?; echo >&2 "$(realpath "$ORIG_CWD/${BASH_SOURCE[0]}"):$LINENO: failed with rc: $rc"' ERR

# shellcheck source=kcompat-lib.sh
source "$ORIG_CWD"/kcompat-lib.sh
source "$SCRIPT_DIR"/kcompat-lib.sh

# DO NOT break gen calls below (via \), to make our compat code more grep-able,
# keep them also grouped, first by feature (like DEVLINK), then by .h filename
Expand All @@ -41,6 +42,27 @@ source "$ORIG_CWD"/kcompat-lib.sh
# handy line of DOC copy-pasted form kcompat-lib.sh:
# gen DEFINE if (KIND [METHOD of]) NAME [(matches|lacks) PATTERN|absent] in <list-of-files>

function gen-aux() {
ah='include/linux/auxiliary_bus.h'
mh='include/linux/mod_devicetable.h'
if config_has CONFIG_AUXILIARY_BUS; then
gen HAVE_AUXILIARY_DRIVER_INT_REMOVE if method remove of auxiliary_driver matches 'int' in "$ah"
fi

# generate HAVE_AUXILIARY_DEVICE_ID only for cases when it's disabled in .config
if ! config_has CONFIG_AUXILIARY_BUS; then
gen HAVE_AUXILIARY_DEVICE_ID if struct auxiliary_device_id in "$mh"
fi
}

function gen-bitfield() {
bf='include/linux/bitfield.h'
gen HAVE_INCLUDE_BITFIELD if macro FIELD_PREP in "$bf"
gen NEED_BITFIELD_FIELD_FIT if macro FIELD_FIT absent in "$bf"
gen NEED_BITFIELD_FIELD_MASK if fun field_mask absent in "$bf"
gen NEED_BITFIELD_FIELD_MAX if macro FIELD_MAX absent in "$bf"
}

function gen-device() {
dh='include/linux/device.h'
dph='include/linux/dev_printk.h'
Expand All @@ -59,13 +81,14 @@ function gen-devlink() {
gen HAVE_DEVLINK_FLASH_UPDATE_PARAMS_FW if struct devlink_flash_update_params matches 'struct firmware \\*fw' in "$dh"
gen HAVE_DEVLINK_HEALTH if enum devlink_health_reporter_state in "$dh"
gen HAVE_DEVLINK_HEALTH_DEFAULT_AUTO_RECOVER if fun devlink_health_reporter_create lacks auto_recover in "$dh"
gen HAVE_DEVLINK_HEALTH_OPS_EXTACK if method dump of devlink_health_reporter_ops matches ext_ack in "$dh"
gen HAVE_DEVLINK_HEALTH_OPS_EXTACK if method dump of devlink_health_reporter_ops matches extack in "$dh"
gen HAVE_DEVLINK_INFO_DRIVER_NAME_PUT if fun devlink_info_driver_name_put in "$dh"
gen HAVE_DEVLINK_PARAMS if method validate of devlink_param matches ext_ack in "$dh"
gen HAVE_DEVLINK_PARAMS if method validate of devlink_param matches extack in "$dh"
gen HAVE_DEVLINK_PARAMS_PUBLISH if fun devlink_params_publish in "$dh"
gen HAVE_DEVLINK_PORT_NEW if method port_new of devlink_ops in "$dh"
gen HAVE_DEVLINK_PORT_OPS if struct devlink_port_ops in "$dh"
gen HAVE_DEVLINK_PORT_SPLIT if method port_split of devlink_ops in "$dh"
gen HAVE_DEVLINK_PORT_SPLIT_EXTACK if method port_split of devlink_ops matches netlink_ext_ack in "$dh"
gen HAVE_DEVLINK_PORT_SPLIT_EXTACK if method port_split of devlink_ops matches extack in "$dh"
gen HAVE_DEVLINK_PORT_SPLIT_PORT_STRUCT if method port_split of devlink_ops matches devlink_port in "$dh"
gen HAVE_DEVLINK_PORT_TYPE_ETH_HAS_NETDEV if fun devlink_port_type_eth_set matches 'struct net_device' in "$dh"
gen HAVE_DEVLINK_RATE_NODE_CREATE if fun devl_rate_node_create in "$dh"
Expand All @@ -80,27 +103,27 @@ function gen-devlink() {
gen HAVE_DEVLINK_RELOAD_ENABLE_DISABLE if fun devlink_reload_enable in "$dh"
gen HAVE_DEVLINK_SET_FEATURES if fun devlink_set_features in "$dh"
gen HAVE_DEVL_PORT_REGISTER if fun devl_port_register in "$dh"

gen HAVE_DEVLINK_PORT_FLAVOUR_PCI_SF if enum devlink_port_flavour matches DEVLINK_PORT_FLAVOUR_PCI_SF in include/uapi/linux/devlink.h
gen HAVE_DEVLINK_RELOAD_ACTION_AND_LIMIT if enum devlink_reload_action matches DEVLINK_RELOAD_ACTION_FW_ACTIVATE in include/uapi/linux/devlink.h

gen NEED_DEVLINK_RESOURCES_UNREGISTER_NO_RESOURCE if fun devlink_resources_unregister matches 'struct devlink_resource \\*' in "$dh"
gen NEED_DEVLINK_TO_DEV if fun devlink_to_dev absent in "$dh"
gen NEED_DEVLINK_UNLOCKED_RESOURCE if fun devl_resource_size_get absent in "$dh"

gen HAVE_DEVLINK_PORT_FLAVOUR_PCI_SF if enum devlink_port_flavour matches DEVLINK_PORT_FLAVOUR_PCI_SF in include/uapi/linux/devlink.h
gen HAVE_DEVLINK_RELOAD_ACTION_AND_LIMIT if enum devlink_reload_action matches DEVLINK_RELOAD_ACTION_FW_ACTIVATE in include/uapi/linux/devlink.h
}

function gen-ethtool() {
eth='include/linux/ethtool.h'
ueth='include/uapi/linux/ethtool.h'
gen HAVE_ETHTOOL_COALESCE_EXTACK if method get_coalesce of ethtool_ops matches 'struct kernel_ethtool_coalesce \\*' in "$eth"
gen HAVE_ETHTOOL_EXTENDED_RINGPARAMS if method get_ringparam of ethtool_ops matches 'struct kernel_ethtool_ringparam \\*' in "$eth"
gen NEED_ETHTOOL_SPRINTF if fun ethtool_sprintf absent in "$eth"
gen HAVE_ETHTOOL_FLOW_RSS if macro FLOW_RSS in "$ueth"
}

function gen-filter() {
fh='include/linux/filter.h'
gen HAVE_XDP_DO_FLUSH if fun xdp_do_flush_map in "$fh"
gen NEED_NO_NETDEV_PROG_XDP_WARN_ACTION if fun bpf_warn_invalid_xdp_action lacks 'struct net_device \\*' in "$fh"
gen NEED_XDP_DO_FLUSH if fun xdp_do_flush absent in "$fh"
}

function gen-flow-dissector() {
Expand All @@ -119,29 +142,34 @@ function gen-gnss() {
fh='include/linux/fs.h'

gen HAVE_CDEV_DEVICE if fun cdev_device_add in "$cdh"
gen HAVE_DEV_UEVENT_CONST if method dev_uevent of class matches 'const struct device' in "$clh"
gen HAVE_POLL_T if typedef __poll_t in "$th"
gen HAVE_DEV_UEVENT_CONST if method dev_uevent of class matches '(const|RH_KABI_CONST) struct device' in "$clh" "$dh"
gen HAVE_STREAM_OPEN if fun stream_open in "$fh"
# There can be either macro class_create or a function
gen NEED_CLASS_CREATE_WITH_MODULE_PARAM if fun class_create matches 'owner' in "$clh" "$dh"
gen NEED_CLASS_CREATE_WITH_MODULE_PARAM if macro class_create in "$clh" "$dh"

if ! grep -qE CONFIG_SUSE_KERNEL.+1 "$CONFFILE"; then
if ! config_has CONFIG_SUSE_KERNEL; then
gen HAVE_GNSS_MODULE if struct gnss_device in "$gh"
fi

gen HAVE_POLL_T if typedef __poll_t in "$th"
}

function gen-netdevice() {
ndh='include/linux/netdevice.h'
gen HAVE_NDO_ETH_IOCTL if fun ndo_eth_ioctl in "$ndh"
gen HAVE_NDO_EXTENDED_SET_TX_MAXRATE if method ndo_set_tx_maxrate of net_device_ops_extended in "$ndh"
gen HAVE_NDO_FDB_ADD_VID if method ndo_fdb_del of net_device_ops matches 'u16 vid' in "$ndh"
gen HAVE_NDO_FDB_DEL_EXTACK if method ndo_fdb_del of net_device_ops matches ext_ack in "$ndh"
gen HAVE_NDO_FDB_DEL_EXTACK if method ndo_fdb_del of net_device_ops matches extack in "$ndh"
gen HAVE_NDO_GET_DEVLINK_PORT if method ndo_get_devlink_port of net_device_ops in "$ndh"
gen HAVE_NDO_UDP_TUNNEL_CALLBACK if method ndo_udp_tunnel_add of net_device_ops in "$ndh"
gen HAVE_NETDEV_EXTENDED_MIN_MAX_MTU if struct net_device_extended matches min_mtu in "$ndh"
gen HAVE_NETDEV_MIN_MAX_MTU if struct net_device matches min_mtu in "$ndh"
gen HAVE_NETIF_SET_TSO_MAX if fun netif_set_tso_max_size in "$ndh"
gen HAVE_SET_NETDEV_DEVLINK_PORT if macro SET_NETDEV_DEVLINK_PORT in "$ndh"
gen NEED_NETIF_NAPI_ADD_NO_WEIGHT if fun netif_napi_add matches 'int weight' in "$ndh"
gen NEED_NET_PREFETCH if fun net_prefetch absent in "$ndh"
gen NEED_XDP_FEATURES if enum netdev_xdp_act absent in include/uapi/linux/netdev.h
}

function gen-pci() {
Expand All @@ -151,52 +179,73 @@ function gen-pci() {
gen HAVE_PCI_MSIX_FREE_IRQ if fun pci_msix_free_irq in "$pcih"
gen HAVE_PER_VF_MSIX_SYSFS if method sriov_set_msix_vec_count of pci_driver in "$pcih"
gen HAVE_STRUCT_PCI_DEV_PTM_ENABLED if struct pci_dev matches ptm_enabled in "$pcih"
gen NEED_PCIE_FLR if fun pcie_flr absent in "$pcih"
gen NEED_PCIE_FLR_RETVAL if fun pcie_flr lacks 'int pcie_flr' in "$pcih"
gen NEED_PCIE_PTM_ENABLED if fun pcie_ptm_enabled absent in "$pcih"
gen NEED_PCI_ENABLE_PTM if fun pci_enable_ptm absent in "$pcih"
}

function gen-other() {
gen NEED_PCI_AER_CLEAR_NONFATAL_STATUS if fun pci_aer_clear_nonfatal_status absent in include/linux/aer.h
pciaerh='include/linux/aer.h'
ush='include/linux/u64_stats_sync.h'
gen NEED_PCI_AER_CLEAR_NONFATAL_STATUS if fun pci_aer_clear_nonfatal_status absent in "$pciaerh"
gen NEED_PCI_ENABLE_PCIE_ERROR_REPORTING if fun pci_enable_pcie_error_reporting absent in "$pciaerh"
gen NEED_BITMAP_COPY_CLEAR_TAIL if fun bitmap_copy_clear_tail absent in include/linux/bitmap.h
gen NEED_BITMAP_FROM_ARR32 if fun bitmap_from_arr32 absent in include/linux/bitmap.h
gen NEED_BITMAP_TO_ARR32 if fun bitmap_to_arr32 absent in include/linux/bitmap.h
gen NEED_ASSIGN_BIT if fun assign_bit absent in include/linux/bitops.h
gen HAVE_COMPLETION_RAW_SPINLOCK if struct completion matches 'struct swait_queue_head' in include/linux/completion.h
gen NEED_IS_CONSTEXPR if macro __is_constexpr absent in include/linux/const.h include/linux/minmax.h include/linux/kernel.h
gen NEED_DEBUGFS_LOOKUP if fun debugfs_lookup absent in include/linux/debugfs.h
gen NEED_DEBUGFS_LOOKUP_AND_REMOVE if fun debugfs_lookup_and_remove absent in include/linux/debugfs.h
gen NEED_ETH_HW_ADDR_SET if fun eth_hw_addr_set absent in include/linux/etherdevice.h
gen NEED_FIND_NEXT_BIT_WRAP if fun find_next_bit_wrap absent in include/linux/find.h
gen HAVE_HWMON_DEVICE_REGISTER_WITH_INFO if fun hwmon_device_register_with_info in include/linux/hwmon.h
gen NEED_HWMON_CHANNEL_INFO if macro HWMON_CHANNEL_INFO absent in include/linux/hwmon.h
gen HAVE_IOMMU_DEV_FEAT_AUX if enum iommu_dev_features matches IOMMU_DEV_FEAT_AUX in include/linux/iommu.h
gen NEED_DEFINE_STATIC_KEY_FALSE if macro DEFINE_STATIC_KEY_FALSE absent in include/linux/jump_label.h
gen NEED_STATIC_BRANCH_LIKELY if macro static_branch_likely absent in include/linux/jump_label.h
gen HAVE_STRUCT_STATIC_KEY_FALSE if struct static_key_false in include/linux/jump_label.h include/linux/jump_label_type.h
gen NEED_DECLARE_STATIC_KEY_FALSE if macro DECLARE_STATIC_KEY_FALSE absent in include/linux/jump_label.h include/linux/jump_label_type.h
gen NEED_LOWER_16_BITS if macro lower_16_bits absent in include/linux/kernel.h
gen NEED_UPPER_16_BITS if macro upper_16_bits absent in include/linux/kernel.h
gen NEED_MUL_U64_U64_DIV_U64 if fun mul_u64_u64_div_u64 absent in include/linux/math64.h
gen HAVE_MDEV_GET_DRVDATA if fun mdev_get_drvdata in include/linux/mdev.h
gen HAVE_MDEV_REGISTER_PARENT if fun mdev_register_parent in include/linux/mdev.h
gen NEED_DEV_PM_DOMAIN_ATTACH if fun dev_pm_domain_attach absent in include/linux/pm_domain.h include/linux/pm.h
gen NEED_DEV_PM_DOMAIN_DETACH if fun dev_pm_domain_detach absent in include/linux/pm_domain.h include/linux/pm.h
gen NEED_PTP_CLASSIFY_RAW if fun ptp_classify_raw absent in include/linux/ptp_classify.h
gen NEED_PTP_PARSE_HEADER if fun ptp_parse_header absent in include/linux/ptp_classify.h
gen HAVE_PTP_CLOCK_INFO_ADJFINE if method adjfine of ptp_clock_info in include/linux/ptp_clock_kernel.h
gen NEED_DIFF_BY_SCALED_PPM if fun diff_by_scaled_ppm absent in include/linux/ptp_clock_kernel.h
gen NEED_PTP_SYSTEM_TIMESTAMP if fun ptp_read_system_prets absent in include/linux/ptp_clock_kernel.h
gen NEED_DEV_PAGE_IS_REUSABLE if fun dev_page_is_reusable absent in include/linux/skbuff.h
gen NEED_NAPI_BUILD_SKB if fun napi_build_skb absent in include/linux/skbuff.h
gen NEED_KREALLOC_ARRAY if fun krealloc_array absent in include/linux/slab.h
gen NEED_DECLARE_FLEX_ARRAY if macro DECLARE_FLEX_ARRAY absent in include/linux/stddef.h
gen NEED_SYSFS_EMIT if fun sysfs_emit absent in include/linux/sysfs.h
gen HAVE_TRACE_ENABLED_SUPPORT if implementation of macro __DECLARE_TRACE matches 'trace_##name##_enabled' in include/linux/tracepoint.h
gen HAVE_U64_STATS_FETCH_BEGIN_IRQ if fun u64_stats_fetch_begin_irq in include/linux/u64_stats_sync.h
gen HAVE_U64_STATS_FETCH_RETRY_IRQ if fun u64_stats_fetch_retry_irq in include/linux/u64_stats_sync.h
gen HAVE_TTY_OP_WRITE_SIZE_T if method write of tty_operations matches size_t in include/linux/tty_driver.h
gen HAVE_U64_STATS_FETCH_BEGIN_IRQ if fun u64_stats_fetch_begin_irq in "$ush"
gen HAVE_U64_STATS_FETCH_RETRY_IRQ if fun u64_stats_fetch_retry_irq in "$ush"
gen NEED_U64_STATS_READ if fun u64_stats_read absent in "$ush"
gen NEED_U64_STATS_SET if fun u64_stats_set absent in "$ush"
gen HAVE_LMV1_SUPPORT if macro VFIO_REGION_TYPE_MIGRATION in include/uapi/linux/vfio.h
}

# all the generations, extracted from main() to keep normal code and various
# prep separated
function gen-all() {
if grep -qE CONFIG_NET_DEVLINK.+1 "$CONFFILE"; then
if config_has CONFIG_NET_DEVLINK; then
gen-devlink
fi
gen-netdevice
# code above is covered by unit_tests/test_gold.sh
if [ -n "${JUST_UNIT_TESTING-}" ]; then
return
fi
gen-aux
gen-bitfield
gen-device
gen-ethtool
gen-filter
Expand Down Expand Up @@ -236,14 +285,17 @@ function main() {
exit 8
fi

# we need just CONFIG_NET_DEVLINK so far, but it's in .config, required
# we need some flags from .config or (autoconf.h), required
if [ ! -f "${CONFFILE-}" ]; then
echo >&2 ".config should be passed as env CONFFILE
(and it's not set or not a file)"
exit 9
fi

echo "#ifndef _KCOMPAT_GENERATED_DEFS_H_"
echo "#define _KCOMPAT_GENERATED_DEFS_H_"
gen-all
echo "#endif /* _KCOMPAT_GENERATED_DEFS_H_ */"

if [ -n "${OUT-}" ]; then
cd "$ORIG_CWD"
Expand Down
43 changes: 36 additions & 7 deletions drivers/intel/ice/ice-1.12.7-zc/src/kcompat-lib.sh
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,6 @@ function filter-out-bad-files() {
fi
local any=0 diagmsgs=/dev/stderr re=$'[\t \n]'
[ -n "${QUIET_COMPAT-}" ] && diagmsgs=/dev/null

# HAVE_PF_RING
diagmsgs=/dev/null

for x in "$@"; do
if [ -e "$x" ]; then
if [[ "$x" =~ $re ]]; then
Expand Down Expand Up @@ -196,7 +192,7 @@ function find-typedef-decl() {
# <list-of-files> is just space-separate list of files to look in,
# single (-) for stdin.
#
# PATTERN is awk pattern, will be wrapped by two slashes (/)
# PATTERN is an awk pattern, will be wrapped by two slashes (/)
function gen() {
test $# -ge 6 || die 20 "too few arguments, $# given, at least 6 needed"
local define if_kw kind name in_kw # mandatory
Expand Down Expand Up @@ -258,7 +254,7 @@ function gen() {

local first_decl=
if [ "$kind" = method ]; then
first_decl="$(find-struct-decl "$name" "$@")" || exit 28
first_decl="$(find-struct-decl "$name" "$@")" || exit 40
# prepare params for next lookup phase
set -- - # overwrite $@ to be single dash (-)
name="$method_name"
Expand All @@ -270,8 +266,23 @@ function gen() {

# lookup the NAME
local body
body="$(find-$kind-decl "$name" "$@" <<< "$first_decl")" || exit 29
body="$(find-$kind-decl "$name" "$@" <<< "$first_decl")" || exit 41
awk -v define="$define" -v pattern="$pattern" -v "$operator"=1 '
BEGIN {
# prepend "identifier boundary" to pattern, also append
# it, but only for patterns not ending with such already
#
# eg: "foo" -> "\bfoo\b"
# "struct foo *" -> "\bstruct foo *"
# Note that mawk does not support "\b", so we have our
# own approximation, NI
NI = "[^A-Za-z0-9_]" # "Not an Indentifier"
if (!match(pattern, NI "$"))
pattern = pattern "(" NI "|$)"
pattern = "(^|" NI ")" pattern
}
/./ { not_empty = 1 }
$0 ~ pattern { found = 1 }
END {
Expand All @@ -280,3 +291,21 @@ function gen() {
}
' <<< "$body"
}

# tell if given flag is enabled in .config
# return 0 if given flag is enabled, 1 otherwise
# inputs:
# $1 - flag to check (whole word, without _MODULE suffix)
# env flag $CONFFILE
#
# there are two "config" formats supported, to ease up integrators lifes
# .config (without leading #~ prefix):
#~ # CONFIG_ACPI_EC_DEBUGFS is not set
#~ CONFIG_ACPI_AC=y
#~ CONFIG_ACPI_VIDEO=m
# and autoconf.h, which would be:
#~ #define CONFIG_ACPI_AC 1
#~ #define CONFIG_ACPI_VIDEO_MODULE 1
function config_has() {
grep -qE "^(#define )?$1((_MODULE)? 1|=m|=y)$" "$CONFFILE"
}

0 comments on commit 0ee1a94

Please sign in to comment.