wifi: rtw89: 8852c: support hw_scan
authorPo-Hao Huang <phhuang@realtek.com>
Thu, 8 Sep 2022 05:12:56 +0000 (13:12 +0800)
committerKalle Valo <kvalo@kernel.org>
Mon, 12 Sep 2022 11:52:33 +0000 (14:52 +0300)
This enables hw_scan function for 52c. The mechanism is similar to 52a
except that it adds modifications required for 6G channels and extends the
command length to make driver compatible to both newer and existing
firmware.

Signed-off-by: Po-Hao Huang <phhuang@realtek.com>
Signed-off-by: Ping-Ke Shih <pkshih@realtek.com>
Signed-off-by: Kalle Valo <kvalo@kernel.org>
Link: https://lore.kernel.org/r/20220908051257.25353-9-pkshih@realtek.com
drivers/net/wireless/realtek/rtw89/core.h
drivers/net/wireless/realtek/rtw89/fw.c
drivers/net/wireless/realtek/rtw89/fw.h
drivers/net/wireless/realtek/rtw89/mac.c

index b68ac1a..c223fcc 100644 (file)
@@ -3788,6 +3788,20 @@ enum nl80211_band rtw89_hw_to_nl80211_band(enum rtw89_band hw_band)
 }
 
 static inline
+enum rtw89_band rtw89_nl80211_to_hw_band(enum nl80211_band nl_band)
+{
+       switch (nl_band) {
+       default:
+       case NL80211_BAND_2GHZ:
+               return RTW89_BAND_2G;
+       case NL80211_BAND_5GHZ:
+               return RTW89_BAND_5G;
+       case NL80211_BAND_6GHZ:
+               return RTW89_BAND_6G;
+       }
+}
+
+static inline
 enum rtw89_bandwidth nl_to_rtw89_bandwidth(enum nl80211_chan_width width)
 {
        switch (width) {
index bda4b11..1dfb470 100644 (file)
@@ -227,6 +227,7 @@ static const struct __fw_feat_cfg fw_feat_tbl[] = {
        __CFG_FW_FEAT(RTL8852A, ge, 0, 13, 36, 0, CRASH_TRIGGER),
        __CFG_FW_FEAT(RTL8852C, le, 0, 27, 33, 0, NO_DEEP_PS),
        __CFG_FW_FEAT(RTL8852C, ge, 0, 27, 34, 0, TX_WAKE),
+       __CFG_FW_FEAT(RTL8852C, ge, 0, 27, 36, 0, SCAN_OFFLOAD),
 };
 
 static void rtw89_fw_recognize_features(struct rtw89_dev *rtwdev)
@@ -1941,7 +1942,7 @@ fail:
        return -EBUSY;
 }
 
-#define H2C_LEN_SCAN_OFFLOAD 20
+#define H2C_LEN_SCAN_OFFLOAD 28
 int rtw89_fw_h2c_scan_offload(struct rtw89_dev *rtwdev,
                              struct rtw89_scan_option *option,
                              struct rtw89_vif *rtwvif)
@@ -1972,6 +1973,8 @@ int rtw89_fw_h2c_scan_offload(struct rtw89_dev *rtwdev,
                                                       scan_info->op_pri_ch);
                RTW89_SET_FWCMD_SCANOFLD_TARGET_CENTRAL_CH(cmd,
                                                           scan_info->op_chan);
+               RTW89_SET_FWCMD_SCANOFLD_TARGET_CH_BAND(cmd,
+                                                       scan_info->op_band);
        }
 
        rtw89_h2c_pkt_set_hdr(rtwdev, skb, FWCMD_TYPE_H2C,
@@ -2406,7 +2409,7 @@ static void rtw89_hw_scan_add_chan(struct rtw89_dev *rtwdev, int chan_type,
 
        if (ssid_num) {
                ch_info->num_pkt = ssid_num;
-               band = ch_info->ch_band;
+               band = rtw89_hw_to_nl80211_band(ch_info->ch_band);
 
                list_for_each_entry(info, &scan_info->pkt_list[band], list) {
                        ch_info->probe_id = info->id;
@@ -2463,7 +2466,7 @@ static int rtw89_hw_scan_add_chan_list(struct rtw89_dev *rtwdev,
 
                ch_info->period = req->duration_mandatory ?
                                  req->duration : RTW89_CHANNEL_TIME;
-               ch_info->ch_band = channel->band;
+               ch_info->ch_band = rtw89_nl80211_to_hw_band(channel->band);
                ch_info->central_ch = channel->hw_value;
                ch_info->pri_ch = channel->hw_value;
                ch_info->rand_seq_num = random_seq;
index 2746aac..fc968e2 100644 (file)
@@ -197,7 +197,7 @@ struct rtw89_h2creg_sch_tx_en {
 #define RTW89_SCANOFLD_MAX_IE_LEN 512
 #define RTW89_SCANOFLD_PKT_NONE 0xFF
 #define RTW89_SCANOFLD_DEBUG_MASK 0x1F
-#define RTW89_MAC_CHINFO_SIZE 20
+#define RTW89_MAC_CHINFO_SIZE 24
 
 struct rtw89_mac_chinfo {
        u8 period;
@@ -2467,6 +2467,8 @@ static inline void RTW89_SET_FWCMD_SCANOFLD_TSF_SLOW(void *cmd, u32 val)
        le32_get_bits(*((const __le32 *)(c2h) + 2), GENMASK(19, 16))
 #define RTW89_GET_MAC_C2H_SCANOFLD_STATUS(c2h) \
        le32_get_bits(*((const __le32 *)(c2h) + 2), GENMASK(23, 20))
+#define RTW89_GET_MAC_C2H_ACTUAL_PERIOD(c2h) \
+       le32_get_bits(*((const __le32 *)(c2h) + 2), GENMASK(31, 24))
 #define RTW89_GET_MAC_C2H_SCANOFLD_TX_FAIL(c2h) \
        le32_get_bits(*((const __le32 *)(c2h) + 5), GENMASK(3, 0))
 #define RTW89_GET_MAC_C2H_SCANOFLD_AIR_DENSITY(c2h) \
index bda60e7..667ac3f 100644 (file)
@@ -3735,7 +3735,7 @@ rtw89_mac_c2h_scanofld_rsp(struct rtw89_dev *rtwdev, struct sk_buff *c2h,
 {
        struct ieee80211_vif *vif = rtwdev->scan_info.scanning_vif;
        struct rtw89_chan new;
-       u8 reason, status, tx_fail, band;
+       u8 reason, status, tx_fail, band, actual_period;
        u16 chan;
 
        tx_fail = RTW89_GET_MAC_C2H_SCANOFLD_TX_FAIL(c2h->data);
@@ -3743,13 +3743,14 @@ rtw89_mac_c2h_scanofld_rsp(struct rtw89_dev *rtwdev, struct sk_buff *c2h,
        chan = RTW89_GET_MAC_C2H_SCANOFLD_PRI_CH(c2h->data);
        reason = RTW89_GET_MAC_C2H_SCANOFLD_RSP(c2h->data);
        band = RTW89_GET_MAC_C2H_SCANOFLD_BAND(c2h->data);
+       actual_period = RTW89_GET_MAC_C2H_ACTUAL_PERIOD(c2h->data);
 
        if (!(rtwdev->chip->support_bands & BIT(NL80211_BAND_6GHZ)))
                band = chan > 14 ? RTW89_BAND_5G : RTW89_BAND_2G;
 
        rtw89_debug(rtwdev, RTW89_DBG_HW_SCAN,
-                   "band: %d, chan: %d, reason: %d, status: %d, tx_fail: %d\n",
-                   band, chan, reason, status, tx_fail);
+                   "band: %d, chan: %d, reason: %d, status: %d, tx_fail: %d, actual: %d\n",
+                   band, chan, reason, status, tx_fail, actual_period);
 
        switch (reason) {
        case RTW89_SCAN_LEAVE_CH_NOTIFY: