wifi: rtlwifi: rtl_usb: Store the endpoint addresses
authorBitterblue Smith <rtl8821cerfe2@gmail.com>
Tue, 13 Feb 2024 14:33:11 +0000 (16:33 +0200)
committerKalle Valo <kvalo@kernel.org>
Thu, 15 Feb 2024 11:11:10 +0000 (13:11 +0200)
And use the stored addresses in rtl8192cu instead of hardcoding them.

This is what the vendor drivers do.

Perhaps this is not strictly necessary for RTL8192CU devices. However,
the dual mac version of RTL8192DU has two USB interfaces, each with its
own set of endpoints. Hardcoding their addresses in the upcoming
rtl8192du driver would require making some assumptions which I'm not
qualified to make.

Signed-off-by: Bitterblue Smith <rtl8821cerfe2@gmail.com>
Acked-by: Ping-Ke Shih <pkshih@realtek.com>
Signed-off-by: Kalle Valo <kvalo@kernel.org>
Link: https://msgid.link/7b6a602a-6101-4bab-958d-bcff4d565b40@gmail.com
drivers/net/wireless/realtek/rtlwifi/rtl8192cu/sw.c
drivers/net/wireless/realtek/rtlwifi/rtl8192cu/trx.c
drivers/net/wireless/realtek/rtlwifi/rtl8192cu/trx.h
drivers/net/wireless/realtek/rtlwifi/usb.c
drivers/net/wireless/realtek/rtlwifi/usb.h
drivers/net/wireless/realtek/rtlwifi/wifi.h

index 9f4cf09090d63e80d40a5e3a41a936b5cb486649..48be7e346efcc1ad613fda7cc06195050af5abbc 100644 (file)
@@ -145,7 +145,6 @@ MODULE_PARM_DESC(debug_mask, "Set debug mask (default 0)");
 
 static struct rtl_hal_usbint_cfg rtl92cu_interface_cfg = {
        /* rx */
-       .in_ep_num = RTL92C_USB_BULK_IN_NUM,
        .rx_urb_num = RTL92C_NUM_RX_URBS,
        .rx_max_size = RTL92C_SIZE_MAX_RX_BUFFER,
        .usb_rx_hdl = rtl8192cu_rx_hdl,
index e5c81c1c63c056822615aa0c70915c78e9487e80..4856ed40005b0408f51dc42ef390dbc701ca3896 100644 (file)
@@ -79,68 +79,75 @@ static int configvernoutep(struct ieee80211_hw *hw)
 static void twooutepmapping(struct ieee80211_hw *hw, bool is_chip8,
                             bool  bwificfg, struct rtl_ep_map *ep_map)
 {
+       struct rtl_usb_priv *usb_priv = rtl_usbpriv(hw);
+       struct rtl_usb *rtlusb = rtl_usbdev(usb_priv);
        struct rtl_priv *rtlpriv = rtl_priv(hw);
 
        if (bwificfg) { /* for WMM */
                rtl_dbg(rtlpriv, COMP_INIT, DBG_DMESG,
                        "USB Chip-B & WMM Setting.....\n");
-               ep_map->ep_mapping[RTL_TXQ_BE]  = 2;
-               ep_map->ep_mapping[RTL_TXQ_BK]  = 3;
-               ep_map->ep_mapping[RTL_TXQ_VI]  = 3;
-               ep_map->ep_mapping[RTL_TXQ_VO] = 2;
-               ep_map->ep_mapping[RTL_TXQ_MGT] = 2;
-               ep_map->ep_mapping[RTL_TXQ_BCN] = 2;
-               ep_map->ep_mapping[RTL_TXQ_HI]  = 2;
+               ep_map->ep_mapping[RTL_TXQ_BE]  = rtlusb->out_eps[0];
+               ep_map->ep_mapping[RTL_TXQ_BK]  = rtlusb->out_eps[1];
+               ep_map->ep_mapping[RTL_TXQ_VI]  = rtlusb->out_eps[1];
+               ep_map->ep_mapping[RTL_TXQ_VO]  = rtlusb->out_eps[0];
+               ep_map->ep_mapping[RTL_TXQ_MGT] = rtlusb->out_eps[0];
+               ep_map->ep_mapping[RTL_TXQ_BCN] = rtlusb->out_eps[0];
+               ep_map->ep_mapping[RTL_TXQ_HI]  = rtlusb->out_eps[0];
        } else { /* typical setting */
                rtl_dbg(rtlpriv, COMP_INIT, DBG_DMESG,
                        "USB typical Setting.....\n");
-               ep_map->ep_mapping[RTL_TXQ_BE]  = 3;
-               ep_map->ep_mapping[RTL_TXQ_BK]  = 3;
-               ep_map->ep_mapping[RTL_TXQ_VI]  = 2;
-               ep_map->ep_mapping[RTL_TXQ_VO]  = 2;
-               ep_map->ep_mapping[RTL_TXQ_MGT] = 2;
-               ep_map->ep_mapping[RTL_TXQ_BCN] = 2;
-               ep_map->ep_mapping[RTL_TXQ_HI]  = 2;
+               ep_map->ep_mapping[RTL_TXQ_BE]  = rtlusb->out_eps[1];
+               ep_map->ep_mapping[RTL_TXQ_BK]  = rtlusb->out_eps[1];
+               ep_map->ep_mapping[RTL_TXQ_VI]  = rtlusb->out_eps[0];
+               ep_map->ep_mapping[RTL_TXQ_VO]  = rtlusb->out_eps[0];
+               ep_map->ep_mapping[RTL_TXQ_MGT] = rtlusb->out_eps[0];
+               ep_map->ep_mapping[RTL_TXQ_BCN] = rtlusb->out_eps[0];
+               ep_map->ep_mapping[RTL_TXQ_HI]  = rtlusb->out_eps[0];
        }
 }
 
 static void threeoutepmapping(struct ieee80211_hw *hw, bool  bwificfg,
                               struct rtl_ep_map *ep_map)
 {
+       struct rtl_usb_priv *usb_priv = rtl_usbpriv(hw);
+       struct rtl_usb *rtlusb = rtl_usbdev(usb_priv);
        struct rtl_priv *rtlpriv = rtl_priv(hw);
 
        if (bwificfg) { /* for WMM */
                rtl_dbg(rtlpriv, COMP_INIT, DBG_DMESG,
                        "USB 3EP Setting for WMM.....\n");
-               ep_map->ep_mapping[RTL_TXQ_BE]  = 5;
-               ep_map->ep_mapping[RTL_TXQ_BK]  = 3;
-               ep_map->ep_mapping[RTL_TXQ_VI]  = 3;
-               ep_map->ep_mapping[RTL_TXQ_VO]  = 2;
-               ep_map->ep_mapping[RTL_TXQ_MGT] = 2;
-               ep_map->ep_mapping[RTL_TXQ_BCN] = 2;
-               ep_map->ep_mapping[RTL_TXQ_HI]  = 2;
+               ep_map->ep_mapping[RTL_TXQ_BE]  = rtlusb->out_eps[2];
+               ep_map->ep_mapping[RTL_TXQ_BK]  = rtlusb->out_eps[1];
+               ep_map->ep_mapping[RTL_TXQ_VI]  = rtlusb->out_eps[1];
+               ep_map->ep_mapping[RTL_TXQ_VO]  = rtlusb->out_eps[0];
+               ep_map->ep_mapping[RTL_TXQ_MGT] = rtlusb->out_eps[0];
+               ep_map->ep_mapping[RTL_TXQ_BCN] = rtlusb->out_eps[0];
+               ep_map->ep_mapping[RTL_TXQ_HI]  = rtlusb->out_eps[0];
        } else { /* typical setting */
                rtl_dbg(rtlpriv, COMP_INIT, DBG_DMESG,
                        "USB 3EP Setting for typical.....\n");
-               ep_map->ep_mapping[RTL_TXQ_BE]  = 5;
-               ep_map->ep_mapping[RTL_TXQ_BK]  = 5;
-               ep_map->ep_mapping[RTL_TXQ_VI]  = 3;
-               ep_map->ep_mapping[RTL_TXQ_VO]  = 2;
-               ep_map->ep_mapping[RTL_TXQ_MGT] = 2;
-               ep_map->ep_mapping[RTL_TXQ_BCN] = 2;
-               ep_map->ep_mapping[RTL_TXQ_HI]  = 2;
+               ep_map->ep_mapping[RTL_TXQ_BE]  = rtlusb->out_eps[2];
+               ep_map->ep_mapping[RTL_TXQ_BK]  = rtlusb->out_eps[2];
+               ep_map->ep_mapping[RTL_TXQ_VI]  = rtlusb->out_eps[1];
+               ep_map->ep_mapping[RTL_TXQ_VO]  = rtlusb->out_eps[0];
+               ep_map->ep_mapping[RTL_TXQ_MGT] = rtlusb->out_eps[0];
+               ep_map->ep_mapping[RTL_TXQ_BCN] = rtlusb->out_eps[0];
+               ep_map->ep_mapping[RTL_TXQ_HI]  = rtlusb->out_eps[0];
        }
 }
 
 static void oneoutepmapping(struct ieee80211_hw *hw, struct rtl_ep_map *ep_map)
 {
-       ep_map->ep_mapping[RTL_TXQ_BE]  = 2;
-       ep_map->ep_mapping[RTL_TXQ_BK]  = 2;
-       ep_map->ep_mapping[RTL_TXQ_VI]  = 2;
-       ep_map->ep_mapping[RTL_TXQ_VO] = 2;
-       ep_map->ep_mapping[RTL_TXQ_MGT] = 2;
-       ep_map->ep_mapping[RTL_TXQ_BCN] = 2;
-       ep_map->ep_mapping[RTL_TXQ_HI]  = 2;
+       struct rtl_usb_priv *usb_priv = rtl_usbpriv(hw);
+       struct rtl_usb *rtlusb = rtl_usbdev(usb_priv);
+
+       ep_map->ep_mapping[RTL_TXQ_BE]  = rtlusb->out_eps[0];
+       ep_map->ep_mapping[RTL_TXQ_BK]  = rtlusb->out_eps[0];
+       ep_map->ep_mapping[RTL_TXQ_VI]  = rtlusb->out_eps[0];
+       ep_map->ep_mapping[RTL_TXQ_VO]  = rtlusb->out_eps[0];
+       ep_map->ep_mapping[RTL_TXQ_MGT] = rtlusb->out_eps[0];
+       ep_map->ep_mapping[RTL_TXQ_BCN] = rtlusb->out_eps[0];
+       ep_map->ep_mapping[RTL_TXQ_HI]  = rtlusb->out_eps[0];
 }
 
 static int _out_ep_mapping(struct ieee80211_hw *hw)
index 5f81cab205ccc0342b1c539ecba673ee97029af4..8678fa0043f436ded51f1774f4be514e9035c58a 100644 (file)
@@ -4,7 +4,6 @@
 #ifndef __RTL92CU_TRX_H__
 #define __RTL92CU_TRX_H__
 
-#define RTL92C_USB_BULK_IN_NUM                 1
 #define RTL92C_NUM_RX_URBS                     8
 #define RTL92C_NUM_TX_URBS                     32
 
index 1fc480fe18ad4da8bd0c1a533d885a75784a4fe7..6e8c87a2fae420745dc9e9c48d00ea8b9f075d38 100644 (file)
@@ -216,7 +216,6 @@ static int _rtl_usb_init_rx(struct ieee80211_hw *hw)
 
        rtlusb->rx_max_size = rtlpriv->cfg->usb_interface_cfg->rx_max_size;
        rtlusb->rx_urb_num = rtlpriv->cfg->usb_interface_cfg->rx_urb_num;
-       rtlusb->in_ep = rtlpriv->cfg->usb_interface_cfg->in_ep_num;
        rtlusb->usb_rx_hdl = rtlpriv->cfg->usb_interface_cfg->usb_rx_hdl;
        rtlusb->usb_rx_segregate_hdl =
                rtlpriv->cfg->usb_interface_cfg->usb_rx_segregate_hdl;
@@ -248,20 +247,38 @@ static int _rtl_usb_init(struct ieee80211_hw *hw)
 
                pep_desc = &usb_intf->cur_altsetting->endpoint[epidx].desc;
 
-               if (usb_endpoint_dir_in(pep_desc))
+               if (usb_endpoint_dir_in(pep_desc)) {
+                       if (usb_endpoint_xfer_bulk(pep_desc)) {
+                               /* The vendor drivers assume there is only one
+                                * bulk in ep and that it's the first in ep.
+                                */
+                               if (rtlusb->in_ep_nums == 0)
+                                       rtlusb->in_ep = usb_endpoint_num(pep_desc);
+                               else
+                                       pr_warn("%s: bulk in endpoint is not the first in endpoint\n",
+                                               __func__);
+                       }
+
                        rtlusb->in_ep_nums++;
-               else if (usb_endpoint_dir_out(pep_desc))
+               } else if (usb_endpoint_dir_out(pep_desc)) {
+                       if (rtlusb->out_ep_nums < RTL_USB_MAX_BULKOUT_NUM) {
+                               if (usb_endpoint_xfer_bulk(pep_desc))
+                                       rtlusb->out_eps[rtlusb->out_ep_nums] =
+                                                       usb_endpoint_num(pep_desc);
+                       } else {
+                               pr_warn("%s: found more bulk out endpoints than the expected %d\n",
+                                       __func__, RTL_USB_MAX_BULKOUT_NUM);
+                       }
+
                        rtlusb->out_ep_nums++;
+               }
 
                rtl_dbg(rtlpriv, COMP_INIT, DBG_DMESG,
                        "USB EP(0x%02x), MaxPacketSize=%d, Interval=%d\n",
                        pep_desc->bEndpointAddress, pep_desc->wMaxPacketSize,
                        pep_desc->bInterval);
        }
-       if (rtlusb->in_ep_nums <  rtlpriv->cfg->usb_interface_cfg->in_ep_num) {
-               pr_err("Too few input end points found\n");
-               return -EINVAL;
-       }
+
        if (rtlusb->out_ep_nums == 0) {
                pr_err("No output end points found\n");
                return -EINVAL;
index 3bf85b23eec1a313aac77ab9587653a13631e707..12529afc0510b623d01ad3f8e7b4662256266304 100644 (file)
@@ -19,6 +19,7 @@
 
 #define RTL_USB_MAX_TXQ_NUM            4               /* max tx queue */
 #define RTL_USB_MAX_EP_NUM             6               /* max ep number */
+#define RTL_USB_MAX_BULKOUT_NUM                4
 #define RTL_USB_MAX_TX_URBS_NUM                8
 
 enum rtl_txq {
@@ -94,6 +95,7 @@ struct rtl_usb {
 
        /* Tx */
        u8 out_ep_nums ;
+       u8 out_eps[RTL_USB_MAX_BULKOUT_NUM];
        u8 out_queue_sel;
        struct rtl_ep_map ep_map;
 
index 3821f6e3144714f5b5d28eafc0ed808915b4cf1b..01df00a43cdb7e871877735fa587d6ea0dfebec8 100644 (file)
@@ -2356,7 +2356,6 @@ struct rtl_mod_params {
 
 struct rtl_hal_usbint_cfg {
        /* data - rx */
-       u32 in_ep_num;
        u32 rx_urb_num;
        u32 rx_max_size;