问题背景 移植 Linux-4.9 或之前的内核版本下的 wifi 驱动到 Linux-5.4 内核版本时会出现编译和运行错误,
该 FAQ 主要用于帮助开发人员解决驱动移植出现的问题。
问题分析
移植到 Linux-5.4 内核版本时出现如下编译错误:
- WARNING: <span class="hljs-built_in">module</span> <span class="hljs-number">8821</span>cu uses symbol kernel_read <span class="hljs-keyword">from</span> namespace VFS_internal_I_am_really_a_filesystem_and_am_NOT_a_driver, but does <span class="hljs-keyword">not</span> <span class="hljs-keyword">import</span> it.
复制代码
出现该 WANRING 的原因是内核版本升级后文件系统存在差异,驱动调用了 kernel_read()和 kernel_write() 函数,需要进行 import VFS_internal_I_am_really_a_filesystem_and_am_NOT_a_driver 处理。 移植到 Linux-5.4 内核版本时运行的错误:
出现该问题的原因是 Linux-5.3 及以后版本 cfg80211.h 里结构体 wiphy_vendor_command 新增了变量 policy 和 maxattr。
解决方案 出现编译错误时解决方案如下:
- diff --git a/drivers/net/wireless/rtl8821cu/os_dep/linux/os_intfs.c b/drivers/net/wireless/rtl8821cu/os_dep/linux/os_intfs.c
- <span class="hljs-keyword">index</span> c4b515763ac8..<span class="hljs-number">466</span>a3b27f521 <span class="hljs-number">100644</span>
- --- a/drivers/net/wireless/rtl8821cu/os_dep/linux/os_intfs.c
- +++ b/drivers/net/wireless/rtl8821cu/os_dep/linux/os_intfs.c
- [url=home.php?mod=space&uid=1999721]@@[/url] -<span class="hljs-number">28</span>,<span class="hljs-number">6</span> +<span class="hljs-number">28</span>,<span class="hljs-number">8</span> @@ MODULE_LICENSE(<span class="hljs-string">"GPL"</span>);
- MODULE_DESCRIPtiON(<span class="hljs-string">"Realtek Wireless Lan Driver"</span>);
- MODULE_AUTHOR(<span class="hljs-string">"Realtek Semiconductor Corp."</span>);
- MODULE_VERSION(DRIVERVERSION);
- +MODULE_IMPORT_NS(VFS_internal_I_am_really_a_filesystem_and_am_NOT_a_driver);
复制代码
出现运行错误时解决方案为遍历驱动里所有使用 wiphy_vendor_command 结构体并修改如下:
- diff --git a/drivers/net/wireless/rtl8821cu/os_dep/linux/rtw_cfgvendor.c b/drivers/net/wireless/rtl8821cu/os_dep/linux/rtw_cfgvendor.c
- index 6bac27d37766..09e24dcc9480 100644
- <span class="hljs-comment">--- a/drivers/net/wireless/rtl8821cu/os_dep/linux/rtw_cfgvendor.c</span>
- <span class="hljs-comment">+++ b/drivers/net/wireless/rtl8821cu/os_dep/linux/rtw_cfgvendor.c</span>
- @@ -1756,6 +1756,11 @@ static const struct wiphy_vendor_command rtw_vendor_cmds[] = {
- },
- .flags = WIPHY_VENDOR_CMD_NEED_WDEV | WIPHY_VENDOR_CMD_NEED_NETDEV,
- .doit = rtw_cfgvendor_gscan_get_capabilities
- <span class="hljs-addition">+#if (LINUX_VERSION_CODE >= KERNEL_VERSION(5, 3, 0))</span>
- <span class="hljs-addition">+ ,</span>
- <span class="hljs-addition">+ .policy = VENDOR_CMD_RAW_DATA,</span>
- <span class="hljs-addition">+ .maxattr = 1</span>
- <span class="hljs-addition">+#endif</span>
- },
复制代码
|