morrownr / 8821au-20210708

Linux Driver for USB WiFi Adapters that are based on the RTL8811AU and RTL8821AU Chipsets - v5.12.5.2
Other
733 stars 109 forks source link

Build failure alma 9.4 #141

Open zenonp opened 5 months ago

zenonp commented 5 months ago

kernel, kernel-devel and kernel-headers 5.14.0-427.20.1, dkms 3.0.13-1 gcc and kernel gcc matching 11.4.1 20231218. Build log attached.

make.log screen.log

morrownr commented 5 months ago

Hi @zenonp

From the README:

Note: Red Hat Enterprise Linux (RHEL) and distros based on RHEL are supported by Red Hat devs due to the way kernel patches are handled in Red Hat. I support knowledgable RHEL developers if they want to merge the required support and keep it current. I reserve the right to delete this support without notice if it causes any problems.

Current RHEL maintainer: none

zenonp commented 5 months ago

Hi

The problems start in osdep_service.c at this point:

if (LINUX_VERSION_CODE >= KERNEL_VERSION(5, 17, 0))

    kthread_complete_and_exit(comp, 0);

else

    complete_and_exit(comp, 0);

endif

And we know that RH kernels include quite a lot of backports, so what RH calls "5.14.0" is likely a mishmash of 5.14 and various later kernels. I tried #if (LINUX_VERSION_CODE >= KERNEL_VERSION(5, 14, 0)) and osdep_service.o was built successfully, only for the build to break a bit later at

os_intfs.c:2142:9: error: too many arguments to function ‘netif_napi_add’ 2142 | netif_napi_add(ndev, &adapter->napi, rtw_recv_napi_poll, RTL_NAPI_WEIGHT);

Now, I can keep testing until I weed out all the errors, but I'm not a developer and I don't know how to patch your code with the right "if rhel then this, else that"-conditionals. Would you be willing to do that part?

Edit: On second thought it might be better to just fork to something that works on this specific kernel, rather than having a moving target for each and every RH kernel update. I'll start the weeding and then see where I get.

morrownr commented 5 months ago

@zenonp

I can offer suggestions if you want usb wireless.

  1. The 88x2bu driver here at this site has a RHEL maintainer so you could use it as an example if you want to fork the 8821au driver:

https://github.com/morrownr/88x2bu-20210702

  1. We could take a look at the files that Alma includes to see what usb wifi adapters are already supported or can be easily supported with some installed files. This is likely the easiest solution and I would like to know myself so I can help you dig for this info.

  2. I am working with a team to upstream a standards compliant driver for the 8821au. It is almost ready but may require some mods like you would see in the 88x2bu driver... that I would be willing to help with.

Think about it and let me know what option or options you want to explore.

zenonp commented 4 months ago

I'll start the weeding and then see where I get.

I've been a bit overwhelmed by other stuff, so it took time. But it's done. With the patch below the module compiles and works with a 2357:0120 TP-Link Archer T2U PLUS [RTL8821AU]. In fact I'm posting this through the T2U running on the modified 8821au-20210708 that I just compiled.

So now we know what kernel version(s) a Redhat 5.14.0-427.20.1 really is. From there on, it would take someone with more knowledge of RH kernels and more dedication than myself, to create and maintain an el9-compatible version of the code.

We could take a look at the files that Alma includes to see what usb wifi adapters are already supported

I needed a driver for the T2U. I bought it by mistake, thinking that it had in-kernel support, and ended up here instead. It was only €15, I could have put it in the pile of "things that might be useful some other day", but making it work was not so far away and it was definitely more satisfactory.

Edit 2024-08-23: I just found out that the patch below was incomplete. Now it is complete.

====

diff -Nur 8821au-20210708/os_dep/linux/ioctl_cfg80211.c 8821au-20210708-el9fixed/os_dep/linux/ioctl_cfg80211.c
--- 8821au-20210708/os_dep/linux/ioctl_cfg80211.c       2024-08-23 15:56:16.591534454 +0300
+++ 8821au-20210708-el9fixed/os_dep/linux/ioctl_cfg80211.c      2024-08-23 15:30:29.226504042 +0300
@@ -471,7 +471,8 @@
                cfg80211_ch_switch_started_notify(adapter->pnetdev, &chdef, 0, 0, false);
 #endif
 #else
-               cfg80211_ch_switch_started_notify(adapter->pnetdev, &chdef, 0, false);
+               cfg80211_ch_switch_started_notify(adapter->pnetdev, &chdef, 0, 0, false, 0);
+//             cfg80211_ch_switch_started_notify(adapter->pnetdev, &chdef, 0, false);
 #endif
 #else
                cfg80211_ch_switch_started_notify(adapter->pnetdev, &chdef, 0);
@@ -490,7 +491,8 @@
        cfg80211_ch_switch_notify(adapter->pnetdev, &chdef, 0);
 #endif
 #else
-       cfg80211_ch_switch_notify(adapter->pnetdev, &chdef);
+//     cfg80211_ch_switch_notify(adapter->pnetdev, &chdef);
+       cfg80211_ch_switch_notify(adapter->pnetdev, &chdef, 0, 0);
 #endif

 #else
@@ -1162,7 +1164,8 @@
 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(6, 0, 0))
                roam_info.links[0].bssid = cur_network->network.MacAddress;
 #else
-               roam_info.bssid = cur_network->network.MacAddress;
+//             roam_info.bssid = cur_network->network.MacAddress;
+               roam_info.links[0].bssid = cur_network->network.MacAddress;
 #endif
                roam_info.req_ie = pmlmepriv->assoc_req + sizeof(struct rtw_ieee80211_hdr_3addr) + 2;
                roam_info.req_ie_len = pmlmepriv->assoc_req_len - sizeof(struct rtw_ieee80211_hdr_3addr) - 2;
@@ -1923,9 +1926,9 @@
 }

 static int cfg80211_rtw_add_key(struct wiphy *wiphy, struct net_device *ndev
-#if (LINUX_VERSION_CODE >= KERNEL_VERSION(6, 1, 0))
+//#if (LINUX_VERSION_CODE >= KERNEL_VERSION(6, 1, 0))
        , int link_id
-#endif
+//#endif
        , u8 key_index
 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 37)) || defined(COMPAT_KERNEL_RELEASE)
        , bool pairwise
@@ -2088,9 +2091,9 @@
 }

 static int cfg80211_rtw_get_key(struct wiphy *wiphy, struct net_device *ndev
-#if (LINUX_VERSION_CODE >= KERNEL_VERSION(6, 1, 0))
+//#if (LINUX_VERSION_CODE >= KERNEL_VERSION(6, 1, 0))
        , int link_id
-#endif
+//#endif
        , u8 keyid
 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 37)) || defined(COMPAT_KERNEL_RELEASE)
        , bool pairwise
@@ -2279,9 +2282,9 @@
 }

 static int cfg80211_rtw_del_key(struct wiphy *wiphy, struct net_device *ndev,
-#if (LINUX_VERSION_CODE >= KERNEL_VERSION(6, 1, 0))
+//#if (LINUX_VERSION_CODE >= KERNEL_VERSION(6, 1, 0))
        int link_id,
-#endif
+//#endif
 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 37)) || defined(COMPAT_KERNEL_RELEASE)
                                u8 key_index, bool pairwise, const u8 *mac_addr)
 #else  /* (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 37)) */
@@ -2303,9 +2306,9 @@

 static int cfg80211_rtw_set_default_key(struct wiphy *wiphy,
        struct net_device *ndev,
-#if (LINUX_VERSION_CODE >= KERNEL_VERSION(6, 1, 0))
+//#if (LINUX_VERSION_CODE >= KERNEL_VERSION(6, 1, 0))
        int link_id,
-#endif
+//#endif
        u8 key_index
        #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 38)) || defined(COMPAT_KERNEL_RELEASE)
        , bool unicast, bool multicast
@@ -2355,9 +2358,9 @@
 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 30))
 int cfg80211_rtw_set_default_mgmt_key(struct wiphy *wiphy,
        struct net_device *ndev,
-#if (LINUX_VERSION_CODE >= KERNEL_VERSION(6, 1, 0))
+//#if (LINUX_VERSION_CODE >= KERNEL_VERSION(6, 1, 0))
        int link_id,
-#endif
+//#endif
        u8 key_index)
 {
 #define SET_DEF_KEY_PARAM_FMT " key_index=%d"
@@ -5408,32 +5411,32 @@
 }

 static int cfg80211_rtw_change_beacon(struct wiphy *wiphy, struct net_device *ndev,
-#if (LINUX_VERSION_CODE >= KERNEL_VERSION(6, 7, 0))
+//#if (LINUX_VERSION_CODE >= KERNEL_VERSION(6, 7, 0))
                struct cfg80211_ap_update *info)
-#else
-               struct cfg80211_beacon_data *info)
-#endif
+//#else
+//             struct cfg80211_beacon_data *info)
+//#endif
 {
        int ret = 0;
        _adapter *adapter = (_adapter *)rtw_netdev_priv(ndev);

        RTW_INFO(FUNC_NDEV_FMT"\n", FUNC_NDEV_ARG(ndev));

-#if (LINUX_VERSION_CODE >= KERNEL_VERSION(6, 7, 0))
+//#if (LINUX_VERSION_CODE >= KERNEL_VERSION(6, 7, 0))
        ret = rtw_add_beacon(adapter, info->beacon.head, info->beacon.head_len, info->beacon.tail, info->beacon.tail_len);
-#else
-       ret = rtw_add_beacon(adapter, info->head, info->head_len, info->tail, info->tail_len);
-#endif
+//#else
+//     ret = rtw_add_beacon(adapter, info->head, info->head_len, info->tail, info->tail_len);
+//#endif

        return ret;
 }

-#if (LINUX_VERSION_CODE >= KERNEL_VERSION(5, 19, 2))
+//#if (LINUX_VERSION_CODE >= KERNEL_VERSION(5, 19, 2))
 static int cfg80211_rtw_stop_ap(struct wiphy *wiphy, struct net_device *ndev,
                unsigned int link_id)
-#else
-static int cfg80211_rtw_stop_ap(struct wiphy *wiphy, struct net_device *ndev)
-#endif
+//#else
+//static int cfg80211_rtw_stop_ap(struct wiphy *wiphy, struct net_device *ndev)
+//#endif
 {
        _adapter *adapter = (_adapter *)rtw_netdev_priv(ndev);

@@ -6813,7 +6816,7 @@

 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 8, 0))
 static int cfg80211_rtw_get_channel(struct wiphy *wiphy,
-#if (LINUX_VERSION_CODE >= KERNEL_VERSION(5, 19, 2))
+#if (LINUX_VERSION_CODE >= KERNEL_VERSION(5, 14, 0))
        struct wireless_dev *wdev, unsigned int link_id,
 #else
        struct wireless_dev *wdev,
@@ -8458,7 +8461,7 @@
 #else
        u8 *peer,
 #endif
-#if (LINUX_VERSION_CODE >= KERNEL_VERSION(6, 5, 0))
+#if (LINUX_VERSION_CODE >= KERNEL_VERSION(5, 14, 0))
        int link_id,
 #endif
        u8 action_code,
@@ -10759,7 +10762,7 @@
        rtw_cfg80211_indicate_scan_done(adapter, _TRUE);

        #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 11, 0)) || defined(COMPAT_KERNEL_RELEASE)
-       #if (LINUX_VERSION_CODE >= KERNEL_VERSION(5, 19, 2))
+       #if (LINUX_VERSION_CODE >= KERNEL_VERSION(5, 14, 0))
        if (wdev->links[0].client.current_bss) {
        #else
        if (wdev->current_bss) {
diff -Nur 8821au-20210708/os_dep/linux/os_intfs.c 8821au-20210708-el9fixed/os_dep/linux/os_intfs.c
--- 8821au-20210708/os_dep/linux/os_intfs.c     2024-08-23 15:56:16.593534496 +0300
+++ 8821au-20210708-el9fixed/os_dep/linux/os_intfs.c    2024-08-21 19:08:03.436149560 +0300
@@ -2136,11 +2136,11 @@
        u8 rtnl_lock_needed = rtw_rtnl_lock_needed(dvobj);

 #ifdef CONFIG_RTW_NAPI
-#if (LINUX_VERSION_CODE >= KERNEL_VERSION(6, 1, 0))
+//#if (LINUX_VERSION_CODE >= KERNEL_VERSION(6, 1, 0))
        netif_napi_add_weight(ndev, &adapter->napi, rtw_recv_napi_poll, RTL_NAPI_WEIGHT);
-#else
-       netif_napi_add(ndev, &adapter->napi, rtw_recv_napi_poll, RTL_NAPI_WEIGHT);
-#endif
+//#else
+//     netif_napi_add(ndev, &adapter->napi, rtw_recv_napi_poll, RTL_NAPI_WEIGHT);
+//#endif
 #endif /* CONFIG_RTW_NAPI */

 #if defined(CONFIG_IOCTL_CFG80211)
diff -Nur 8821au-20210708/os_dep/linux/wifi_regd.c 8821au-20210708-el9fixed/os_dep/linux/wifi_regd.c
--- 8821au-20210708/os_dep/linux/wifi_regd.c    2024-08-23 15:56:16.595534539 +0300
+++ 8821au-20210708-el9fixed/os_dep/linux/wifi_regd.c   2024-08-21 19:09:37.597153394 +0300
@@ -405,9 +405,9 @@
        wiphy->regulatory_flags &= ~REGULATORY_DISABLE_BEACON_HINTS;
 #endif

-#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 19, 0)) && (LINUX_VERSION_CODE < KERNEL_VERSION(6, 1, 39))
-       wiphy->regulatory_flags |= REGULATORY_IGNORE_STALE_KICKOFF;
-#endif
+//#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 19, 0)) && (LINUX_VERSION_CODE < KERNEL_VERSION(6, 1, 39))
+//     wiphy->regulatory_flags |= REGULATORY_IGNORE_STALE_KICKOFF;
+//#endif

        return 0;
 }
diff -Nur 8821au-20210708/os_dep/osdep_service.c 8821au-20210708-el9fixed/os_dep/osdep_service.c
--- 8821au-20210708/os_dep/osdep_service.c      2024-08-23 15:56:16.595534539 +0300
+++ 8821au-20210708-el9fixed/os_dep/osdep_service.c     2024-08-23 15:09:08.459103564 +0300
@@ -1309,7 +1309,7 @@
 inline void thread_exit(_completion *comp)
 {
 #ifdef PLATFORM_LINUX
-#if (LINUX_VERSION_CODE >= KERNEL_VERSION(5, 17, 0))
+#if (LINUX_VERSION_CODE >= KERNEL_VERSION(5, 14, 0))
        kthread_complete_and_exit(comp, 0);
 #else
        complete_and_exit(comp, 0);
zenonp commented 4 months ago

The problem with RH kernels is that "(LINUX_VERSION_CODE >= KERNEL_VERSION(x, y, z))" means absolutely nothing and can never be trusted. So it occurs to me that the way to get around this, is to test directly for what some particular kernel expects. Say, with the very first code change above, test whether adapter-> expects four of five arguments and then do accordingly. I don't know whether this could be done, yet less how, but it would be universal and cover any kernel of any distribution, patched or not.

morrownr commented 4 months ago

Hey, I deal with api changes regularly so I understand the challenges... but then Red Hat comes along and mucks things up. If I were to try to support RHEL, it would take many additional hours of my time and I already do not have enough time to do what I want to do.

My suggestion is that we investigate what drivers for wifi chips are already being made available and look in that direction.

Run the following commands and then copy and paste the results here:

$ cd /usr/lib/modules/$(uname -r)/kernel/drivers/net/wireless/mediatek/mt76 $ ls -l

zenonp commented 4 months ago

There's a mix of files and directories there, so therefore

# pwd
/usr/lib/modules/5.14.0-427.20.1.el9_4.x86_64/kernel/drivers/net/wireless/mediatek/mt76

# find ./ -type f -exec ls -l {} \;
-rw-r--r--. 1 root root 31176 Jun 10 15:34 ./mt76x2/mt76x2u.ko.xz
-rw-r--r--. 1 root root 25600 Jun 10 15:34 ./mt76x2/mt76x2-common.ko.xz
-rw-r--r--. 1 root root 31916 Jun 10 15:34 ./mt76x2/mt76x2e.ko.xz
-rw-r--r--. 1 root root 33712 Jun 10 15:34 ./mt76x0/mt76x0-common.ko.xz
-rw-r--r--. 1 root root 26440 Jun 10 15:34 ./mt76x0/mt76x0e.ko.xz
-rw-r--r--. 1 root root 26080 Jun 10 15:34 ./mt76x0/mt76x0u.ko.xz
-rw-r--r--. 1 root root 23496 Jun 10 15:34 ./mt76x02-usb.ko.xz
-rw-r--r--. 1 root root 44048 Jun 10 15:34 ./mt792x-lib.ko.xz
-rw-r--r--. 1 root root 56808 Jun 10 15:34 ./mt76x02-lib.ko.xz
-rw-r--r--. 1 root root 67844 Jun 10 15:34 ./mt76.ko.xz
-rw-r--r--. 1 root root 30836 Jun 10 15:34 ./mt76-usb.ko.xz
-rw-r--r--. 1 root root 59532 Jun 10 15:34 ./mt7921/mt7921-common.ko.xz
-rw-r--r--. 1 root root 29320 Jun 10 15:34 ./mt7921/mt7921e.ko.xz
-rw-r--r--. 1 root root 75332 Jun 10 15:34 ./mt7925/mt7925-common.ko.xz
-rw-r--r--. 1 root root 29336 Jun 10 15:34 ./mt7925/mt7925e.ko.xz
-rw-r--r--. 1 root root 56452 Jun 10 15:34 ./mt76-connac-lib.ko.xz
zenonp commented 4 months ago

Red Hat comes along and mucks things up

Yes, but there must be some way to easily figure out what a kernel expects. For example my last edit above, kthread_complete_and_exit or complete_and_exit, could be picked up directly from System.map without knowing the kernel version. And it should be possible to find whether int link_id should be used or not by looking in cfg80211.h. Things like that.

The benefit of this method is not so much that it would support RH kernels (RH should do that themselves), but that it is version-independent and 100% fail-safe.

it would take many additional hours of my time

I understand that and I'm not asking you to do anything. I'm just putting forward ideas that could be picked up by you, by someone else, or even by myself, now or at some other point in time.

BTW, looking at install_driver.sh I just realised that I don't need to learn C to do this; I can probably do it in bash with a few grep and sed commands from install_driver.sh itself.

morrownr commented 4 months ago

/mt76x2/mt76x2u.ko.xz

There is a driver for the mt7612u AC1200 chip.

/mt76x0/mt76x0u.ko.xz

There is a driver for the mt7610u AC600 chip.

/mt7921/mt7921e.ko.xz

That is the pcie driver for the mt7921au AXE3000 chip. There is also a usb version of the driver. It is not clear why it is not being compiled.

So, you do have options. The Main Menu for this site is:

https://github.com/morrownr/USB-WiFi

Menu item 2 is the Plug and Play List. It has sections on the mt7612u and mt7610u based adapters.

There is also the option to investigate an effort to upstream a new 8821/11au driver:

https://github.com/morrownr/8821au-20210708/issues/133

The first message in that thread gives information on the project and points you to the repo where the code is being worked. It is a manual installation but that is just for testing. Once the driver is in the kernel, it will be plug and play. You may run into the same issues with this driver that you do with the driver in this repo that you are trying to compile. I can understand why Red Hat would have thought what they are doing to the kernel was a good idea at one time but it is no longer a good idea and just causes problems.

zenonp commented 4 months ago

There is a driver for the mt7612u AC1200 chip.

Thank you for the suggestions, I appreciate your effort.

On the downside, I am currently in Greece where none of these adapters seem to be on sale (or they're very hard to find because of a widespread indifference in this country towards giving exact technical specifications). I found them and I can get them from elsewhere in the EU, but then shipping gets pretty steep.

On the upside, my Archer T2U now works just fine. So my focus has shifted from getting the adapter to work, to getting this driver to compile and work no matter what.

I can understand why Red Hat would have thought what they are doing to the kernel was a good idea at one time but it is no longer a good idea and just causes problems.

I can see their point in phasing in changes gradually and conservatively, but after all these years they should at least have figured an easy way, even a fully-fledged ABI, to tell the user what code he is running.