Compiling a NIC kernel module - where to start?

I'm normally not compiling stuff from scratch but I need a driver for my nic (Aquantia AQC107).
I've Googled a lot about this and also compiled OpenWRT SDK etc but I still do not understand what I need to do. I thought I needed to get the OpenWRT running with the SDK/kernel headers present and then simply unpack the driver I downloaded and follow the instructions (make etc) but that didn't work.

What is the way to do this? All info I find seem to start in the middle of things or focus on how to compile OpenWRT with modules that already have src included.
I already have OpenWRT running on x86_64 hardware so I want to build a .ko file in a simple way.

I'm running Windows so I'm using Debian through VirtualBox.

So what is your suggestion?
Try to get in contact with the guy who are trying to submit it and ask him for a .ko file?
Try to understand how he does things, which is what I asked about to begin with?
Just wait until something happens and it might be integrated into a OpenWRT release?

based on the above. my suggestion is that you wait.

Copy the code from that pull request and see if it works for you

BTW, the result would likely be a standard openwrt kmod package in the .ipk format, not a .ko

I'm still not up to level on how to do this, in a general perspective.
I think I know what to do with the code in that pull-request but what about the actual source code from aquantia? I'm guessing that I need to put that somewhere as well.

It's not an out of tree driver. The code is part of the upstream kernel source, so it does not need to download anything

Here, try this. I haven't compile tested it, but it should work. Create a new folder package/kernel/aquantia and put it in there named Makefile

include $(TOPDIR)/rules.mk

PKG_NAME:=kmod-aquantia
PKG_VERSION:=1.0
PKG_RELEASE:=1

include $(INCLUDE_DIR)/kernel.mk
include $(INCLUDE_DIR)/package.mk

define KernelPackage/aquantia
  SUBMENU:=Network Devices
  TITLE:=aQuantia device support
  DEPENDS:=@PCI_SUPPORT @TARGET_x86_64 +kmod-i2c-core +kmod-i2c-algo-bit +kmod-ptp +kmod-hwmon-core +LINUX_5_4:kmod-libphy
  KCONFIG:=CONFIG_AQUANTIA_PHY
  FILES:=$(LINUX_DIR)/drivers/net/phy/aquantia.ko
  AUTOLOAD:=$(call AutoLoad,35,aquantia)
endef

define KernelPackage/aquantia/description
 Kernel modules for aQuantia Ethernet adapters.
endef

define KernelPackage/atlantic
  SUBMENU:=Network Devices
  TITLE:=aQuantia AQtion(tm) Support
  DEPENDS:=@PCI_SUPPORT @TARGET_x86_64 +kmod-i2c-core +kmod-i2c-algo-bit +kmod-ptp +kmod-aquantia
  KCONFIG:=CONFIG_AQTION
  FILES:=$(LINUX_DIR)/drivers/net/ethernet/aquantia/atlantic/atlantic.ko
  AUTOLOAD:=$(call AutoLoad,35,atlantic)
endef

define KernelPackage/atlantic/description
 Kernel modules for the aQuantia AQtion(tm) Ethernet card
endef

define Build/Prepare
    mkdir -p $(PKG_BUILD_DIR)
endef

define Build/Configure
endef

define Build/Compile
endef

$(eval $(call KernelPackage,aquantia))
$(eval $(call KernelPackage,atlantic))

Thanks for the info.
I got the .ipk packages by doing this:

git clone https://git.openwrt.org/openwrt/openwrt.git
cd openwrt

mkdir ./package/kernel/aquantia
nano ./package/kernel/aquantia/Makefile
# add makefile text in file

./scripts/feeds update -a
./scripts/feeds install -a

git fetch --tags
git tag -l
git checkout v19.07.1

make menuconfig
# Set Target/subtarget etc
# Kernel modules > Network Devices
# kmod-aquantia
# kmod-atlantic
make

Got the following:

ls -al bin/targets/x86/64/packages/
...
855 Jun 19 05:22 kmod-aquantia_4.14.167+1.0-1_x86_64.ipk
25306 Jun 19 05:22 kmod-atlantic_4.14.167+1.0-1_x86_64.ipk

I installed the packages but got this warning:

Collected errors:
 * satisfy_dependencies_for: Cannot satisfy the following dependencies for kmod-aquantia:
 *      kernel (= 4.14.167-1-943b6d01b96513d59198249849327200)
 * opkg_install_cmd: Cannot install package kmod-aquantia.

In my running OpenWRT system packages has either "4.14.167-1" or "4.14.167+4.19.98-1-1" but i got "4.14.167+1.0-1" ipk packages.
I was hoping for the best and force installed them anyway but it seems that the kmod isn't used for the device:

lspci -nk
...
00:1f.6 0200: 8086:15b8
        DeviceName: Onboard - Ethernet
        Subsystem: 1043:8672
        Kernel driver in use: e1000e
02:00.0 0280: 14e4:43c3 (rev 04)
        Subsystem: 1043:86fb
        Kernel driver in use: brcmfmac
03:00.0 0200: 1d6a:07b1 (rev 02)
        Subsystem: 1043:8741

"03:00.0 0200" is the Aquantia Corp. AQC107, which says it's not using a kernel driver.

Because of the forced install might it be best to start over again and compile an image with everything in it and then install that into the router instead of only trying to compile the driver or at least update my router to the latest version and try again from there.

The image you're running has a kernel version that does not match the source code you're compiling from. This is why you're getting the error.

So yes, the only way to fix this is to compile and install a complete new image.

I compiled an new image but I got the same result.
The kernel driver isn't used.

Is there a way to load it manually or to try something to get it working?

I don't know this driver or what your system looks like, but perhaps it is conflicting with another driver that's already being used for this card?

These are kernel modules. What happens, if from the console, you do a

modprobe aquantia
modprobe atlantic

Oh, and look at the output of dmesg after trying to modprobe the kernel modules

modprobe atlantic:

atlantic is already loaded

modprobe aquantia:

failed to find a module named aquantia

dmesg doesn't say anything about them. It says it loaded the driver for the integrated nic in the motherboard correctly.

Well, there's your answer. Does the kmod-aquantia ipk actually contain an aquantia.ko module?

Is there such a module installed in /lib/modules/<kernel version>?

No, there is only atlantic.ko in /lib/modules/4.14.180/.
I wonder what went wrong in this and what the connection between aquantia and atlantic is?
Maybe something i missed in make menuconfig

Look in the build directory for the kernel. Is one being built?

there should be one in drivers/net/phy/aquantia.ko

Looking at the size of the generated ipk, it's probably empty

855 Jun 19 05:22 kmod-aquantia_4.14.167+1.0-1_x86_64.ipk

I'm trying to find it but fail to do so, I'm guessing it should be here:

openwrt/build_dir/target-x86_64_musl/linux-x86_64/linux-4.14.180/drivers/net/phy/

But that contains stuff like:

drwxr-xr-x  3 osboxes osboxes  4096 Jun 19 11:18 .
drwxr-xr-x 28 osboxes osboxes  4096 Jun 19 11:18 ..
-rw-r--r--  1 osboxes osboxes 27169 Jun 18 20:15 adm6996.c
-rw-r--r--  1 osboxes osboxes  6221 Jun 18 20:11 adm6996.h
-rw-r--r--  1 osboxes osboxes  2050 May 10 04:29 amd.c
-rw-r--r--  1 osboxes osboxes  5240 May 10 04:29 aquantia.c
-rw-r--r--  1 osboxes osboxes 69715 Jun 19 10:12 ar8216.c
-rw-r--r--  1 osboxes osboxes 21903 Jun 19 10:12 ar8216.h
-rw-r--r--  1 osboxes osboxes 37757 Jun 18 20:11 ar8327.c
-rw-r--r--  1 osboxes osboxes 12274 Jun 18 20:11 ar8327.h
-rw-r--r--  1 osboxes osboxes 15259 Jun 19 10:52 at803x.c
drwxr-xr-x  2 osboxes osboxes  4096 Jun 18 20:15 b53
-rw-r--r--  1 osboxes osboxes  2799 May 10 04:29 bcm63xx.c
-rw-r--r--  1 osboxes osboxes 19196 May 10 04:29 bcm7xxx.c
-rw-r--r--  1 osboxes osboxes  5035 May 10 04:29 bcm87xx.c
-rw-r--r--  1 osboxes osboxes  4094 May 10 04:29 bcm-cygnus.c
-rw-r--r--  1 osboxes osboxes  9587 May 10 04:29 bcm-phy-lib.c
-rw-r--r--  1 osboxes osboxes  1979 May 10 04:29 bcm-phy-lib.h
...

I search in the structure but can't find aquantia.ko, only atlantic.ko which is located in:

openwrt/build_dir/target-x86_64_musl/linux-x86_64/linux-4.14.180/drivers/net/ethernet/aquantia/atlantic

No trace of aquantia, except for the folder name in the path, there.

You're doing something wrong. I finally got around to compile testing this. It creates both modules for me and both ipk packages contain the required module. You can see below from the output of my make target/linux/compile that it builds both modules

make[4]: Entering directory '/opt/openwrt/build_dir/target-x86_64_glibc/linux-x86_64/linux-5.4.42'
scripts/kconfig/conf  --syncconfig Kconfig
  DESCEND  objtool
  CALL    scripts/atomic/check-atomics.sh
  CALL    scripts/checksyscalls.sh
  GZIP    kernel/config_data.gz
  CC [M]  kernel/configs.o
  CC [M]  drivers/net/ethernet/aquantia/atlantic/aq_main.o
  CC [M]  drivers/net/ethernet/aquantia/atlantic/aq_nic.o
  CC [M]  drivers/net/ethernet/aquantia/atlantic/aq_pci_func.o
  CC [M]  drivers/net/ethernet/aquantia/atlantic/aq_vec.o
  CC [M]  drivers/net/ethernet/aquantia/atlantic/aq_ring.o
  CC [M]  drivers/net/ethernet/aquantia/atlantic/aq_hw_utils.o
  CC [M]  drivers/net/phy/aquantia_main.o
  CC [M]  drivers/net/ethernet/aquantia/atlantic/aq_ethtool.o
  CC [M]  drivers/net/ethernet/aquantia/atlantic/aq_drvinfo.o
  CC [M]  drivers/net/ethernet/aquantia/atlantic/aq_filters.o
  CC [M]  drivers/net/ethernet/aquantia/atlantic/hw_atl/hw_atl_a0.o
  CC [M]  drivers/net/phy/aquantia_hwmon.o
  CC [M]  drivers/net/ethernet/aquantia/atlantic/hw_atl/hw_atl_b0.o
  CC [M]  drivers/net/ethernet/aquantia/atlantic/hw_atl/hw_atl_utils.o
  LD [M]  drivers/net/phy/aquantia.o
  CC [M]  drivers/net/ethernet/aquantia/atlantic/hw_atl/hw_atl_utils_fw2x.o
  CC [M]  drivers/net/ethernet/aquantia/atlantic/hw_atl/hw_atl_llh.o
  LD [M]  drivers/net/ethernet/aquantia/atlantic/atlantic.o
  Building modules, stage 2.
  MODPOST 107 modules
  LD [M]  kernel/configs.ko
  CC [M]  drivers/net/ethernet/aquantia/atlantic/atlantic.mod.o
  CC [M]  drivers/net/phy/aquantia.mod.o
  LD [M]  drivers/net/ethernet/aquantia/atlantic/atlantic.ko
  LD [M]  drivers/net/phy/aquantia.ko
make[4]: Leaving directory '/opt/openwrt/build_dir/target-x86_64_glibc/linux-x86_64/linux-5.4.42'

and here's the find . listing of the package install folder

/opt/openwrt/build_dir/target-x86_64_glibc/linux-x86_64/kmod-aquantia-1.0/ipkg-x86_64$ find . -print
.
./kmod-atlantic
./kmod-atlantic/CONTROL
./kmod-atlantic/CONTROL/control
./kmod-atlantic/CONTROL/postinst
./kmod-atlantic/CONTROL/prerm
./kmod-atlantic/etc
./kmod-atlantic/etc/modules.d
./kmod-atlantic/etc/modules.d/35-atlantic
./kmod-atlantic/lib
./kmod-atlantic/lib/modules
./kmod-atlantic/lib/modules/5.4.42
./kmod-atlantic/lib/modules/5.4.42/atlantic.ko
./kmod-aquantia
./kmod-aquantia/CONTROL
./kmod-aquantia/CONTROL/control
./kmod-aquantia/CONTROL/postinst
./kmod-aquantia/CONTROL/prerm
./kmod-aquantia/etc
./kmod-aquantia/etc/modules.d
./kmod-aquantia/etc/modules.d/35-aquantia
./kmod-aquantia/lib
./kmod-aquantia/lib/modules
./kmod-aquantia/lib/modules/5.4.42
./kmod-aquantia/lib/modules/5.4.42/aquantia.ko

This Makefile is a little cleaner, but both the original one I posted and this one should work to produce two ipk files containing the relevant kernel modules.

include $(TOPDIR)/rules.mk
  
PKG_NAME:=kmod-aquantia
PKG_VERSION:=1.0
PKG_RELEASE:=1

include $(INCLUDE_DIR)/kernel.mk
include $(INCLUDE_DIR)/package.mk

define KernelPackage/aquantia
  SUBMENU:=Network Devices
  TITLE:=aQuantia device support
  DEPENDS:=@PCI_SUPPORT @TARGET_x86_64 +kmod-i2c-core +kmod-i2c-algo-bit +kmod-ptp +kmod-hwmon-core +LINUX_5_4:kmod-libphy
  KCONFIG:=CONFIG_AQUANTIA_PHY
  HIDDEN:=1
  FILES:=$(LINUX_DIR)/drivers/net/phy/aquantia.ko
  AUTOLOAD:=$(call AutoLoad,35,aquantia)
endef

define KernelPackage/aquantia/description
 Kernel modules for aQuantia Ethernet adapters.
endef

define KernelPackage/atlantic
  SUBMENU:=Network Devices
  TITLE:=aQuantia AQtion(tm) Support
  DEPENDS:=@PCI_SUPPORT @TARGET_x86_64 +kmod-i2c-core +kmod-i2c-algo-bit +kmod-ptp +kmod-aquantia
  KCONFIG:=CONFIG_AQTION
  FILES:=$(LINUX_DIR)/drivers/net/ethernet/aquantia/atlantic/atlantic.ko
  AUTOLOAD:=$(call AutoLoad,35,atlantic)
endef

define KernelPackage/atlantic/description
 Kernel modules for the aQuantia AQtion(tm) Ethernet card
endef

define Build/Compile
endef

$(eval $(call KernelPackage,aquantia))
$(eval $(call KernelPackage,atlantic))

I think try a make target/linux/clean before doing a make -j9 V=s