On Wed, 2024-03-20 at 21:43 +0200, Bitterblue Smith wrote: > > These contain the new module's entry point. > > Signed-off-by: Bitterblue Smith <rtl8821cerfe2@xxxxxxxxx> > --- > v3: > - Add USB ID 2001:330c found by Zenm Chen. > > v2: > - Patch is new in v2, split from patch 3/3 in v1. > --- > .../wireless/realtek/rtlwifi/rtl8192du/sw.c | 312 ++++++++++++++++++ > .../wireless/realtek/rtlwifi/rtl8192du/sw.h | 12 + > 2 files changed, 324 insertions(+) > create mode 100644 drivers/net/wireless/realtek/rtlwifi/rtl8192du/sw.c > create mode 100644 drivers/net/wireless/realtek/rtlwifi/rtl8192du/sw.h > > diff --git a/drivers/net/wireless/realtek/rtlwifi/rtl8192du/sw.c > b/drivers/net/wireless/realtek/rtlwifi/rtl8192du/sw.c > new file mode 100644 > index 000000000000..6d7f40e7add5 > --- /dev/null > +++ b/drivers/net/wireless/realtek/rtlwifi/rtl8192du/sw.c > @@ -0,0 +1,312 @@ > +// SPDX-License-Identifier: GPL-2.0 > +/* Copyright(c) 2009-2012 Realtek Corporation.*/ > + > +#include "../wifi.h" > +#include "../core.h" > +#include "../usb.h" > +#include "../base.h" > +#include "../rtl8192d/reg.h" > +#include "../rtl8192d/def.h" > +#include "../rtl8192d/fw_common.h" > +#include "../rtl8192d/hw_common.h" > +#include "../rtl8192d/phy_common.h" > +#include "../rtl8192d/trx_common.h" > +#include "phy.h" > +#include "dm.h" > +#include "fw.h" > +#include "hw.h" > +#include "sw.h" > +#include "trx.h" > +#include "led.h" > + > +#include <linux/module.h> > + > +static int rtl92du_init_sw_vars(struct ieee80211_hw *hw) > +{ > + const char *fw_name = "rtlwifi/rtl8192dufw.bin"; > + struct rtl_priv *rtlpriv = rtl_priv(hw); > + int err; > + > + rtlpriv->dm.dm_initialgain_enable = true; > + rtlpriv->dm.dm_flag = 0; > + rtlpriv->dm.disable_framebursting = false; > + rtlpriv->dm.thermalvalue = 0; > + rtlpriv->dm.useramask = true; > + > + /* dual mac */ > + if (rtlpriv->rtlhal.current_bandtype == BAND_ON_5G) > + rtlpriv->phy.current_channel = 36; > + else > + rtlpriv->phy.current_channel = 1; > + > + if (rtlpriv->rtlhal.macphymode != SINGLEMAC_SINGLEPHY) > + rtlpriv->rtlhal.disable_amsdu_8k = true; > + > + /* for LPS & IPS */ > + rtlpriv->psc.inactiveps = rtlpriv->cfg->mod_params->inactiveps; > + rtlpriv->psc.swctrl_lps = rtlpriv->cfg->mod_params->swctrl_lps; > + rtlpriv->psc.fwctrl_lps = rtlpriv->cfg->mod_params->fwctrl_lps; > + if (!rtlpriv->psc.inactiveps) > + pr_info("Inactive Power Save off (module option)\n"); > + > + /* for early mode */ > + rtlpriv->rtlhal.earlymode_enable = false; > + > + /* for firmware buf */ > + rtlpriv->rtlhal.pfirmware = kmalloc(0x8000, GFP_KERNEL); > + if (!rtlpriv->rtlhal.pfirmware) { > + pr_err("Can't alloc buffer for fw\n"); WARNING: Possible unnecessary 'out of memory' message #75: FILE: drivers/net/wireless/realtek/rtlwifi/rtl8192du/sw.c:58: + if (!rtlpriv->rtlhal.pfirmware) { + pr_err("Can't alloc buffer for fw\n"); > + return 1; returning standard error number will be better, but others have been there.... > + } > + > + rtlpriv->max_fw_size = 0x8000; > + pr_info("Driver for Realtek RTL8192DU WLAN interface\n"); > + pr_info("Loading firmware file %s\n", fw_name); > + > + /* request fw */ > + err = request_firmware_nowait(THIS_MODULE, 1, fw_name, > + rtlpriv->io.dev, GFP_KERNEL, hw, > + rtl_fw_cb); > + if (err) { > + pr_err("Failed to request firmware!\n"); > + kfree(rtlpriv->rtlhal.pfirmware); > + rtlpriv->rtlhal.pfirmware = NULL; > + return 1; > + } > + > + return 0; > +} > + > +static void rtl92du_deinit_sw_vars(struct ieee80211_hw *hw) > +{ > + struct rtl_priv *rtlpriv = rtl_priv(hw); > + > + kfree(rtlpriv->rtlhal.pfirmware); > + rtlpriv->rtlhal.pfirmware = NULL; > +} > + > +static struct rtl_hal_ops rtl8192du_hal_ops = { static const (also below tables) [...] > + > +MODULE_AUTHOR("lizhaoming <chaoming_li@xxxxxxxxxxxxxx>"); > +MODULE_AUTHOR("Realtek WlanFAE <wlanfae@xxxxxxxxxxx>"); > +MODULE_AUTHOR("Larry Finger <Larry.Finger@xxxxxxxxxxxx>"); Author should be you. > +MODULE_LICENSE("GPL"); > +MODULE_DESCRIPTION("Realtek 8192DU 802.11an Dual Mac USB wireless"); > +MODULE_FIRMWARE("rtlwifi/rtl8192dufw.bin"); Normally, we put MODULE_xxx at bottom of files. > + > +module_param_named(swenc, rtl92du_mod_params.sw_crypto, bool, 0444); > +module_param_named(debug_level, rtl92du_mod_params.debug_level, int, 0644); > +module_param_named(ips, rtl92du_mod_params.inactiveps, bool, 0444); > +module_param_named(swlps, rtl92du_mod_params.swctrl_lps, bool, 0444); > +module_param_named(debug_mask, rtl92du_mod_params.debug_mask, ullong, 0644); > +MODULE_PARM_DESC(swenc, "Set to 1 for software crypto (default 0)\n"); > +MODULE_PARM_DESC(ips, "Set to 0 to not use link power save (default 0)\n"); > +MODULE_PARM_DESC(swlps, "Set to 1 to use SW control power save (default 0)\n"); > +MODULE_PARM_DESC(debug_level, "Set debug level (0-5) (default 0)"); > +MODULE_PARM_DESC(debug_mask, "Set debug mask (default 0)"); > + > +/* Add global mutex to solve the problem that > + * dual mac register operation on the same time > + */ I see the reason now, it seems work. > +DEFINE_MUTEX(globalmutex_power); > +DEFINE_MUTEX(globalmutex_for_fwdownload); > +DEFINE_MUTEX(globalmutex_for_power_and_efuse); > +DEFINE_MUTEX(globalmutex_for_mac0_2g_mac1_5g); The consumers of globalmutex_for_mac0_2g_mac1_5g are complex. Why do they check mutex_is_locked()? Race conditions between two instances? > + > +#define USB_VENDOR_ID_REALTEK 0x0bda > + > +static const struct usb_device_id rtl8192d_usb_ids[] = { > + {RTL_USB_DEVICE(USB_VENDOR_ID_REALTEK, 0x8193, rtl92du_hal_cfg)}, > + {RTL_USB_DEVICE(USB_VENDOR_ID_REALTEK, 0x8194, rtl92du_hal_cfg)}, > + {RTL_USB_DEVICE(USB_VENDOR_ID_REALTEK, 0x8111, rtl92du_hal_cfg)}, > + {RTL_USB_DEVICE(USB_VENDOR_ID_REALTEK, 0x0193, rtl92du_hal_cfg)}, > + {RTL_USB_DEVICE(USB_VENDOR_ID_REALTEK, 0x8171, rtl92du_hal_cfg)}, > + {RTL_USB_DEVICE(USB_VENDOR_ID_REALTEK, 0xe194, rtl92du_hal_cfg)}, > + {RTL_USB_DEVICE(0x2019, 0xab2c, rtl92du_hal_cfg)}, > + {RTL_USB_DEVICE(0x2019, 0xab2d, rtl92du_hal_cfg)}, > + {RTL_USB_DEVICE(0x2019, 0x4903, rtl92du_hal_cfg)}, > + {RTL_USB_DEVICE(0x2019, 0x4904, rtl92du_hal_cfg)}, > + {RTL_USB_DEVICE(0x07b8, 0x8193, rtl92du_hal_cfg)}, > + {RTL_USB_DEVICE(0x20f4, 0x664b, rtl92du_hal_cfg)}, > + {RTL_USB_DEVICE(0x04dd, 0x954f, rtl92du_hal_cfg)}, > + {RTL_USB_DEVICE(0x04dd, 0x96a6, rtl92du_hal_cfg)}, > + {RTL_USB_DEVICE(0x050d, 0x110a, rtl92du_hal_cfg)}, > + {RTL_USB_DEVICE(0x050d, 0x1105, rtl92du_hal_cfg)}, > + {RTL_USB_DEVICE(0x050d, 0x120a, rtl92du_hal_cfg)}, > + {RTL_USB_DEVICE(0x1668, 0x8102, rtl92du_hal_cfg)}, > + {RTL_USB_DEVICE(0x0930, 0x0a0a, rtl92du_hal_cfg)}, > + {RTL_USB_DEVICE(0x2001, 0x330c, rtl92du_hal_cfg)}, > + {} > +}; > + > +MODULE_DEVICE_TABLE(usb, rtl8192d_usb_ids); > + > +static int rtl8192du_probe(struct usb_interface *intf, > + const struct usb_device_id *id) > +{ > + return rtl_usb_probe(intf, id, &rtl92du_hal_cfg); > +} > + > +static struct usb_driver rtl8192du_driver = { > + .name = "rtl8192du", > + .probe = rtl8192du_probe, > + .disconnect = rtl_usb_disconnect, > + .id_table = rtl8192d_usb_ids, > + .disable_hub_initiated_lpm = 1, > +}; > + > +module_usb_driver(rtl8192du_driver); > diff --git a/drivers/net/wireless/realtek/rtlwifi/rtl8192du/sw.h > b/drivers/net/wireless/realtek/rtlwifi/rtl8192du/sw.h > new file mode 100644 > index 000000000000..364d9a471dc0 > --- /dev/null > +++ b/drivers/net/wireless/realtek/rtlwifi/rtl8192du/sw.h > @@ -0,0 +1,12 @@ > +/* SPDX-License-Identifier: GPL-2.0 */ > +/* Copyright(c) 2009-2012 Realtek Corporation.*/ > + > +#ifndef __RTL92DE_SW_H__ > +#define __RTL92DE_SW_H__ 8192DU > + > +extern struct mutex globalmutex_power; > +extern struct mutex globalmutex_for_fwdownload; > +extern struct mutex globalmutex_for_power_and_efuse; > +extern struct mutex globalmutex_for_mac0_2g_mac1_5g; > + > +#endif > -- > 2.43.2