From: Bitterblue Smith <rtl8821cerfe2@gmail.com>
To: Ping-Ke Shih <pkshih@realtek.com>, "kvalo@kernel.org" <kvalo@kernel.org>
Cc: "linux-wireless@vger.kernel.org" <linux-wireless@vger.kernel.org>,
"Larry.Finger@lwfinger.net" <Larry.Finger@lwfinger.net>,
"s.l-h@gmx.de" <s.l-h@gmx.de>,
"chewitt@libreelec.tv" <chewitt@libreelec.tv>
Subject: Re: [PATCH v3 11/12] wifi: rtlwifi: Add rtl8192du/sw.{c,h}
Date: Thu, 28 Mar 2024 15:31:14 +0200 [thread overview]
Message-ID: <7873dee1-46a8-48a7-9059-bc300ac98c23@gmail.com> (raw)
In-Reply-To: <4672072ef782ae1200886a190c740e0f3ccec2c8.camel@realtek.com>
On 28/03/2024 03:46, Ping-Ke Shih wrote:
> On Thu, 2024-03-28 at 00:53 +0200, Bitterblue Smith wrote:
>>
>> On 27/03/2024 20:48, Kalle Valo wrote:
>>> Bitterblue Smith <rtl8821cerfe2@gmail.com> writes:
>>>
>>>> On 22/03/2024 08:04, Ping-Ke Shih wrote:
>>>>> On Wed, 2024-03-20 at 21:43 +0200, Bitterblue Smith wrote:
>>>>
>>>> [...]
>>>>
>>>>>> +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?
>>>>>
>>>>
>>>> I couldn't think of a sufficiently short name, like
>>>> "lock_mac0_2g_mac1_5g", so I used mutex_is_locked(). That's probably
>>>> a bad idea. It should be like this:
>>>>
>>>> /* Let the first starting mac load RF parameters and do LCK */
>>>> if (rtlhal->macphymode == DUALMAC_DUALPHY &&
>>>> ((rtlhal->interfaceindex == 0 && rtlhal->bandset == BAND_ON_2_4G) ||
>>>> (rtlhal->interfaceindex == 1 && rtlhal->bandset == BAND_ON_5G))) {
>>>> mutex_lock(&globalmutex_for_mac0_2g_mac1_5g);
>>>> lock_mac0_2g_mac1_5g = true;
>>>> }
>
> globalmutex_for_mac0_2g_mac1_5g is only used in rtl92du_hw_init(), and
> globalmutex_for_power_and_efuse does very similar thing. Can we combine them
> into one? Since both are only used in rtl92du_hw_init(), it would not be a
> problem to enlarge their critical section.
>
>
>>
>> * Dual MAC dual PHY: this I can't find to buy anymore. This
>> appears in the system as two Wifi devices, each working on
>> a different band. It has two USB interfaces. Two instances
>> of the driver access the same device. This is what the
>> mutexes are for.
>
> I traced the code, and found rules of two MAC/PHY are:
> 1. read efuse to decide single or two MAC/PHY
> 2.1. if single MAC/PHY, register_hw as 2T2R (done)
> 2.2. if dual MAC/PHY (to step 3)
> 3. read interface index (USB: from bInterfaceNumber; PCI: from PCI onfigure space)
> 4. register interface index 0 as 1T1R on 5 GHz band only.
> register interface index 1 as 1T1R on 2 GHz band only.
>
> This is the case two instances (netdev) access single one hardware device,
> so seemingly it is hard to avoid global locks to prevent racing between them.
> An alternative thought is to support only single MAC/PHY, but not sure if
> driver can override setting of efuse that programmed the card as two MAC/PHY.
>
>>
>> I said earlier that I think two devices can work at the same
>> time, even with the global mutexes, but now I remembered there
>> are two more global variables: curveindex_5g[] and
>> curveindex_2g[] in phy.c. One driver instance fills one array
>> during LC calibration, but the other driver instance reads
>> from the array when switching the channel. If I'm reading this
>> right. So two devices plugged in at the same time probably
>> won't work correctly.
>
> That should be a problem.
>
>>
>> How can you avoid this when the hardware is the way it is?
>> My one idea is to add a global map to hold the mutexes and
>> arrays, using the USB port number, etc as the key.
>
> Seemingly we need something like per device data.
>
I got another idea: if we have a guarantee that the two USB
interfaces are probed one at a time, then we can move the global
things into struct rtl_priv. The first probe call will allocate
the arrays and initialise the mutexes. The second probe call
will obtain those from the first struct rtl_priv:
int rtl_usb_probe(struct usb_interface *intf, ...) {
udev = interface_to_usbdev(intf);
struct ieee80211_hw *first_hw = usb_get_intfdata(udev->actconfig->interface[0]);
struct rtl_priv *first_rtlpriv = rtl_priv(first_hw);
Something like that.
I am having regrets...
next prev parent reply other threads:[~2024-03-28 13:31 UTC|newest]
Thread overview: 51+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-03-20 19:32 [PATCH v3 00/12] wifi: rtlwifi: Add new rtl8192du driver Bitterblue Smith
2024-03-20 19:33 ` [PATCH v3 01/12] wifi: rtlwifi: rtl8192de: Fix 5 GHz TX power Bitterblue Smith
2024-03-22 1:25 ` Ping-Ke Shih
2024-03-20 19:34 ` [PATCH v3 02/12] wifi: rtlwifi: Move code from rtl8192de to rtl8192d-common Bitterblue Smith
2024-03-22 2:14 ` Ping-Ke Shih
2024-03-26 13:02 ` Bitterblue Smith
2024-03-20 19:35 ` [PATCH v3 03/12] wifi: rtlwifi: Adjust rtl8192d-common for USB Bitterblue Smith
2024-03-22 3:41 ` Ping-Ke Shih
2024-03-20 19:36 ` [PATCH v3 04/12] wifi: rtlwifi: Add rtl8192du/table.{c,h} Bitterblue Smith
2024-03-22 3:46 ` Ping-Ke Shih
2024-03-26 17:30 ` Bitterblue Smith
2024-03-27 9:18 ` Kalle Valo
2024-03-27 9:30 ` Ping-Ke Shih
2024-03-27 12:36 ` Bitterblue Smith
2024-03-27 12:42 ` Ping-Ke Shih
2024-03-27 12:53 ` Kalle Valo
2024-03-27 16:34 ` Jeff Johnson
2024-03-20 19:37 ` [PATCH v3 05/12] wifi: rtlwifi: Add rtl8192du/hw.{c,h} Bitterblue Smith
2024-03-22 4:02 ` Ping-Ke Shih
2024-03-20 19:38 ` [PATCH v3 06/12] wifi: rtlwifi: Add rtl8192du/phy.{c,h} Bitterblue Smith
2024-03-22 5:22 ` Ping-Ke Shih
2024-03-26 22:13 ` Bitterblue Smith
2024-03-27 1:19 ` Ping-Ke Shih
2024-03-20 19:39 ` [PATCH v3 07/12] wifi: rtlwifi: Add rtl8192du/trx.{c,h} Bitterblue Smith
2024-03-22 5:32 ` Ping-Ke Shih
2024-03-20 19:40 ` [PATCH v3 08/12] wifi: rtlwifi: Add rtl8192du/rf.{c,h} Bitterblue Smith
2024-03-22 5:35 ` Ping-Ke Shih
2024-03-20 19:41 ` [PATCH v3 09/12] wifi: rtlwifi: Add rtl8192du/fw.{c,h} and rtl8192du/led.{c,h} Bitterblue Smith
2024-03-22 5:42 ` Ping-Ke Shih
2024-03-20 19:42 ` [PATCH v3 10/12] wifi: rtlwifi: Add rtl8192du/dm.{c,h} Bitterblue Smith
2024-03-22 5:48 ` Ping-Ke Shih
2024-03-20 19:43 ` [PATCH v3 11/12] wifi: rtlwifi: Add rtl8192du/sw.{c,h} Bitterblue Smith
2024-03-22 6:04 ` Ping-Ke Shih
2024-03-27 14:07 ` Bitterblue Smith
2024-03-27 18:48 ` Kalle Valo
2024-03-27 22:53 ` Bitterblue Smith
2024-03-28 1:46 ` Ping-Ke Shih
2024-03-28 13:31 ` Bitterblue Smith [this message]
2024-03-29 0:34 ` Ping-Ke Shih
2024-03-31 18:48 ` Bitterblue Smith
2024-04-01 1:21 ` Ping-Ke Shih
2024-04-07 12:03 ` Bitterblue Smith
2024-04-08 2:45 ` Ping-Ke Shih
2024-04-08 9:01 ` Bitterblue Smith
2024-04-09 0:27 ` Ping-Ke Shih
2024-04-09 11:16 ` Bitterblue Smith
2024-03-28 1:49 ` Ping-Ke Shih
2024-03-20 19:44 ` [PATCH v3 12/12] wifi: rtlwifi: Enable the new rtl8192du driver Bitterblue Smith
2024-03-22 6:06 ` Ping-Ke Shih
2024-03-21 1:10 ` [PATCH v3 00/12] wifi: rtlwifi: Add " Stefan Lippers-Hollmann
2024-03-22 6:13 ` [PATCH v3 01/12] wifi: rtlwifi: rtl8192de: Fix 5 GHz TX power Ping-Ke Shih
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=7873dee1-46a8-48a7-9059-bc300ac98c23@gmail.com \
--to=rtl8821cerfe2@gmail.com \
--cc=Larry.Finger@lwfinger.net \
--cc=chewitt@libreelec.tv \
--cc=kvalo@kernel.org \
--cc=linux-wireless@vger.kernel.org \
--cc=pkshih@realtek.com \
--cc=s.l-h@gmx.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).