Received: by 2002:a05:6358:f14:b0:e5:3b68:ec04 with SMTP id b20csp84121rwj; Sat, 17 Dec 2022 04:43:45 -0800 (PST) X-Google-Smtp-Source: AA0mqf4xCDuqriaN0mRqe3EfTuRMEgJlPqKrHZToDgzA8aRU4cIYdKtGjOtvbSQRYHwDciTZD767 X-Received: by 2002:a05:6402:5486:b0:467:c3cb:49aa with SMTP id fg6-20020a056402548600b00467c3cb49aamr29797307edb.4.1671281025677; Sat, 17 Dec 2022 04:43:45 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1671281025; cv=none; d=google.com; s=arc-20160816; b=RD9fVbpq1ocA2R6cahxCZBcQi2IbnaNhrZyJTZ+8oL/kc7NKWsL4Nc0GYBbijAHVLs pDYYVKwQUSHCJL+RB5FUhFllwxn80r1afz6MVA+Xy1XTOBuWYBK4Ks3rHG7git8ERkPq K6bZkA3m6lp1Po2SSru8pWPGGrAqiQjAzTWj0fRqMAruvLOmV0REGM0Jp/tiSR1cb6El r2MCKM9EOVkxs4PbpGH1FSmXcjJ2NzhQHsT+F1jNmtSMAB1nhwAwLHM5kXIFqyZeESc9 wdYkm1olVoIChx0F+gVuLfjOnxW95m7OO0piRgvrz0vP4/idwFJH4Z51NlPRWYlyFUlK aHYw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :references:cc:to:content-language:subject:user-agent:mime-version :date:message-id:dkim-signature; bh=uC6J8Y5zcpkxG8FH54867HYko/hYc7OJziBCirqQMaI=; b=UgWf5MJxBm+WsgS+1wh/eiHDcjYwVzjaDmbH144POzxWBzyjqCmHYY+eA3jaQd0MIV 33U7gfpWfuFy7Wmhu1jGaM3hWCnWOkqlTOn4FOhim+1N9pn9umRbYOSppwJzc3pHsT92 9QG/CuqDABy2HO0RqiAdQblzQiXfOx/MxcFzlg9ImaXDH30JxTb2DWBOfwB94rwU6FX5 crHSD5zgc3faPB4s2U+9xP9LPxNVmrSsWQTpLEi9Z2MiLR62M8ryx0Ks6sG7RSj8gALX dP9+WXzRTW66Rn+BT+xobbb/XbF0E1R2IlnC04YHP2ThBHi0Pa7Rf9zD8tL2Kwaq0s90 M4vg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=PQlYQOHz; spf=pass (google.com: domain of linux-wireless-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-wireless-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id b11-20020a056402350b00b0046dbc9804fasi5496043edd.257.2022.12.17.04.43.29; Sat, 17 Dec 2022 04:43:45 -0800 (PST) Received-SPF: pass (google.com: domain of linux-wireless-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=PQlYQOHz; spf=pass (google.com: domain of linux-wireless-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-wireless-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229526AbiLQMn1 (ORCPT + 66 others); Sat, 17 Dec 2022 07:43:27 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52424 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229453AbiLQMnZ (ORCPT ); Sat, 17 Dec 2022 07:43:25 -0500 Received: from mail-wm1-x331.google.com (mail-wm1-x331.google.com [IPv6:2a00:1450:4864:20::331]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B166C14D23 for ; Sat, 17 Dec 2022 04:43:23 -0800 (PST) Received: by mail-wm1-x331.google.com with SMTP id o15so3509291wmr.4 for ; Sat, 17 Dec 2022 04:43:23 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=uC6J8Y5zcpkxG8FH54867HYko/hYc7OJziBCirqQMaI=; b=PQlYQOHzV7bfj8rLbSsA1euTuAksqnwRMHoKiVfabadxVkND7vWo6Ziw7bIx8O4DJh iiN7+8iWeZytCN3W76Hz3cXQOEPanxSGvZHMOP4fcWnUCbkNtqPBq2iuDGkvi6fF2q1x 7IR3pywewvVf4fTQLacQH4DqazWRUQzBh0p12ZSAUXM/Q50KEgbXMJFBjyEPJnVY46Rj Grsm+0Mgm1zL3X5XFFpl9p0NgubIlDIXTQxUS9xBpTZIf3OgVsIjT2lUUQBK4sjJ0R7J 0VaP0IRqukd93Nq6/Orjesw4u5IkF0S8slwIkhBTSEdxXIAj/4IAcvc4IBw4f5thuCNb 9A2Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=uC6J8Y5zcpkxG8FH54867HYko/hYc7OJziBCirqQMaI=; b=plVUUIGDH1+vhPcxrdLLl+2NevywqXofn+qllyg8rlzR3NHTIuym0MMI1qcJVON+J6 WiiuBwftNpHwgsceKtd2R4v0Tngx2PtyyM8IqjavGG0emCdmCr/L76XPja/9qTNJXWxL jJcSGp5AYnA6SH08F8xzKvCipJwoj4dxxB0CNsu92huKTvLQTq7rs3hKUTiodQ70VPWg EvyzfhRcCyisCmYIxxw2vAM8QyqewZEjdwdsyQ3aKOVeMS5mOxKGkefzfYvRT3Hi/DPp koaAQ+TtHWOy2XVrdvQaGttNPoDoeaSH8uJjOSBGdnApHGEa2mJyW1ZjcmIE/TjR32AB XwvA== X-Gm-Message-State: ANoB5pk7Q6ijMn38ommY2oH8GhaiHwWiO/+FegvmdmmwCG1gIfVmz3+l 5RJHcNCrdZRHWzP7Aqs3OEQ= X-Received: by 2002:a05:600c:3646:b0:3cf:6b1d:7bad with SMTP id y6-20020a05600c364600b003cf6b1d7badmr26762537wmq.33.1671281002046; Sat, 17 Dec 2022 04:43:22 -0800 (PST) Received: from [192.168.1.50] ([79.119.240.153]) by smtp.gmail.com with ESMTPSA id j9-20020a05600c190900b003b4cba4ef71sm14751861wmq.41.2022.12.17.04.43.20 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sat, 17 Dec 2022 04:43:21 -0800 (PST) Message-ID: Date: Sat, 17 Dec 2022 14:43:19 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.3.3 Subject: Re: [PATCH v2 5/5] wifi: rtl8xxxu: Add rate control code for RTL8188EU Content-Language: en-US To: Ping-Ke Shih , "linux-wireless@vger.kernel.org" Cc: "Jes.Sorensen@gmail.com" , "andrea.merello@gmail.com" , "ap420073@gmail.com" References: From: Bitterblue Smith In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_ENVFROM_END_DIGIT, FREEMAIL_FROM,NICE_REPLY_A,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-wireless@vger.kernel.org On 15/12/2022 15:14, Ping-Ke Shih wrote: > On Tue, 2022-12-13 at 19:33 +0200, Bitterblue Smith wrote: >> Copied from the newer vendor driver, v5.2.2.4. >> >> Signed-off-by: Bitterblue Smith >> --- >> v2: >> - Implement suggestions from Ping-Ke Shih: >> - Add missing break in two switch statements. >> - Remove unnecessary initialisation of idx in rtl8188e_set_tx_rpt_timing(). >> --- >> .../net/wireless/realtek/rtl8xxxu/rtl8xxxu.h | 39 ++ >> .../realtek/rtl8xxxu/rtl8xxxu_8188e.c | 601 +++++++++++++++++- >> .../wireless/realtek/rtl8xxxu/rtl8xxxu_core.c | 131 +++- >> 3 files changed, 741 insertions(+), 30 deletions(-) >> >> diff --git a/drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu.h >> b/drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu.h >> index 29f5dbee16b0..be9479f969b7 100644 >> --- a/drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu.h >> +++ b/drivers/net/wireless/realtek/rtl8xxxu/rtl8xxxu.h >> > > [...] > >> + >> +static void rtl8188e_power_training_try_state(struct rtl8xxxu_ra_info *ra) >> +{ >> + ra->pt_try_state = 0; >> + switch (ra->pt_mode_ss) { >> + case 3: >> + if (ra->decision_rate >= DESC_RATE_MCS13) >> + ra->pt_try_state = 1; >> + break; >> + case 2: >> + if (ra->decision_rate >= DESC_RATE_MCS5) >> + ra->pt_try_state = 1; >> + break; >> + case 1: >> + if (ra->decision_rate >= DESC_RATE_48M) >> + ra->pt_try_state = 1; >> + break; >> + case 0: >> + if (ra->decision_rate >= DESC_RATE_11M) >> + ra->pt_try_state = 1; >> + break; >> + default: >> + ra->pt_try_state = 0; > > It seems to be 0 already because of first statement of this function. > >> + break; >> + } >> + >> + if (ra->rssi_sta_ra < 48) { >> + ra->pt_stage = 0; >> + } else if (ra->pt_try_state == 1) { >> + if ((ra->pt_stop_count >= 10) || >> + (ra->pt_pre_rssi > ra->rssi_sta_ra + 5) || >> + (ra->pt_pre_rssi < ra->rssi_sta_ra - 5) || >> + (ra->decision_rate != ra->pt_pre_rate)) { >> + if (ra->pt_stage == 0) >> + ra->pt_stage = 1; >> + else if (ra->pt_stage == 1) >> + ra->pt_stage = 3; >> + else >> + ra->pt_stage = 5; >> + >> + ra->pt_pre_rssi = ra->rssi_sta_ra; >> + ra->pt_stop_count = 0; >> + } else { >> + ra->ra_stage = 0; >> + ra->pt_stop_count++; >> + } >> + } else { >> + ra->pt_stage = 0; >> + ra->ra_stage = 0; >> + } >> + >> + ra->pt_pre_rate = ra->decision_rate; >> + >> + /* TODO: implement the "false alarm" statistics for this */ >> + /* Disable power training when noisy environment */ >> + /* if (p_dm_odm->is_disable_power_training) { */ >> + if (1) { >> + ra->pt_stage = 0; >> + ra->ra_stage = 0; >> + ra->pt_stop_count = 0; >> + } >> +} >> + >> +static void rtl8188e_power_training_decision(struct rtl8xxxu_ra_info *ra) >> +{ >> + u8 temp_stage; >> + u32 numsc; >> + u32 num_total; >> + u8 stage_id; >> + u8 j; >> + >> + numsc = 0; >> + num_total = ra->total * pt_penalty[5]; >> + for (j = 0; j <= 4; j++) { >> + numsc += ra->retry[j] * pt_penalty[j]; >> + >> + if (numsc > num_total) >> + break; >> + } >> + >> + j = j >> 1; > > j >>= 1; > >> + temp_stage = (ra->pt_stage + 1) >> 1; >> + if (temp_stage > j) >> + stage_id = temp_stage - j; >> + else >> + stage_id = 0; >> + >> + ra->pt_smooth_factor = (ra->pt_smooth_factor >> 1) + >> + (ra->pt_smooth_factor >> 2) + >> + stage_id * 16 + 2; >> + if (ra->pt_smooth_factor > 192) >> + ra->pt_smooth_factor = 192; >> + stage_id = ra->pt_smooth_factor >> 6; >> + temp_stage = stage_id * 2; >> + if (temp_stage != 0) >> + temp_stage--; >> + if (ra->drop > 3) >> + temp_stage = 0; >> + ra->pt_stage = temp_stage; >> +} >> + >> +void rtl8188e_handle_ra_tx_report2(struct rtl8xxxu_priv *priv, struct sk_buff *skb) >> +{ >> + u32 *_rx_desc = (u32 *)(skb->data - sizeof(struct rtl8xxxu_rxdesc16)); >> + struct rtl8xxxu_rxdesc16 *rx_desc = (struct rtl8xxxu_rxdesc16 *)_rx_desc; >> + struct device *dev = &priv->udev->dev; >> + struct rtl8xxxu_ra_info *ra = &priv->ra_info; >> + > > no blank line in declaration part. > >> + u32 tx_rpt_len = rx_desc->pktlen & 0x3ff; >> + u32 items = tx_rpt_len / TX_RPT2_ITEM_SIZE; >> + u64 macid_valid = ((u64)_rx_desc[5] << 32) | _rx_desc[4]; >> + u32 macid; >> + u8 *rpt = skb->data; >> + bool valid; >> + u16 min_rpt_time = 0x927c; >> + >> + dev_dbg(dev, "%s: len: %d items: %d\n", __func__, tx_rpt_len, items); >> + >> + for (macid = 0; macid < items; macid++) { >> + valid = false; >> + >> + if (macid < 64) >> + valid = macid_valid & BIT(macid); >> + >> + if (valid) { >> + ra->retry[0] = le16_to_cpu(*(__le16 *)rpt); >> + ra->retry[1] = rpt[2]; >> + ra->retry[2] = rpt[3]; >> + ra->retry[3] = rpt[4]; >> + ra->retry[4] = rpt[5]; >> + ra->drop = rpt[6]; >> + ra->total = ra->retry[0] + ra->retry[1] + ra->retry[2] + >> + ra->retry[3] + ra->retry[4] + ra->drop; >> + >> + if (ra->total > 0) { >> + if (ra->ra_stage < 5) >> + rtl8188e_rate_decision(ra); >> + else if (ra->ra_stage == 5) >> + rtl8188e_power_training_try_state(ra); >> + else /* ra->ra_stage == 6 */ >> + rtl8188e_power_training_decision(ra); >> + >> + if (ra->ra_stage <= 5) >> + ra->ra_stage++; >> + else >> + ra->ra_stage = 0; >> + } >> + } else if (macid == 0) { >> + dev_warn(dev, "%s: TX report item 0 not valid\n", __func__); >> + } >> + >> + dev_dbg(dev, "%s: valid: %d retry: %d %d %d %d %d drop: %d\n", >> + __func__, valid, >> + ra->retry[0], ra->retry[1], ra->retry[2], >> + ra->retry[3], ra->retry[4], ra->drop); >> + >> + if (min_rpt_time > ra->rpt_time) >> + min_rpt_time = ra->rpt_time; >> + >> + rpt += TX_RPT2_ITEM_SIZE; >> + >> + /* >> + * We only use macid 0, so only the first item is relevant. >> + * AP mode will use more of them if it's ever implemented. >> + */ >> + break; >> + } >> + >> + if (min_rpt_time != ra->pre_min_rpt_time) { >> + rtl8xxxu_write16(priv, REG_TX_REPORT_TIME, min_rpt_time); >> + ra->pre_min_rpt_time = min_rpt_time; >> + } >> +} >> + > > [...] > >> + >> int rtl8xxxu_parse_rxdesc16(struct rtl8xxxu_priv *priv, struct sk_buff *skb) >> { >> struct ieee80211_hw *hw = priv->hw; >> @@ -5823,38 +5884,46 @@ int rtl8xxxu_parse_rxdesc16(struct rtl8xxxu_priv *priv, struct sk_buff >> *skb) >> >> skb_pull(skb, sizeof(struct rtl8xxxu_rxdesc16)); >> >> - phy_stats = (struct rtl8723au_phy_stats *)skb->data; >> + if (rx_desc->rpt_sel) { >> + skb_queue_tail(&priv->c2hcmd_queue, skb); >> + schedule_work(&priv->c2hcmd_work); >> + } else { >> + phy_stats = (struct rtl8723au_phy_stats *)skb->data; >> >> - skb_pull(skb, drvinfo_sz + desc_shift); >> + skb_pull(skb, drvinfo_sz + desc_shift); >> >> - skb_trim(skb, pkt_len); >> + skb_trim(skb, pkt_len); >> >> - if (rx_desc->phy_stats) >> - rtl8xxxu_rx_parse_phystats(priv, rx_status, phy_stats, >> - rx_desc->rxmcs, (struct ieee80211_hdr *)skb- >>> data, >> - rx_desc->crc32 || rx_desc->icverr); >> + if (rx_desc->phy_stats) >> + rtl8xxxu_rx_parse_phystats( >> + priv, rx_status, phy_stats, >> + rx_desc->rxmcs, >> + (struct ieee80211_hdr *)skb->data, >> + rx_desc->crc32 || rx_desc->icverr >> + ); > > squash this parenthesis to previous line. > >> >> - rx_status->mactime = rx_desc->tsfl; >> - rx_status->flag |= RX_FLAG_MACTIME_START; >> + rx_status->mactime = rx_desc->tsfl; >> + rx_status->flag |= RX_FLAG_MACTIME_START; >> >> - if (!rx_desc->swdec) >> - rx_status->flag |= RX_FLAG_DECRYPTED; >> - if (rx_desc->crc32) >> - rx_status->flag |= RX_FLAG_FAILED_FCS_CRC; >> - if (rx_desc->bw) >> - rx_status->bw = RATE_INFO_BW_40; >> + if (!rx_desc->swdec) >> + rx_status->flag |= RX_FLAG_DECRYPTED; >> + if (rx_desc->crc32) >> + rx_status->flag |= RX_FLAG_FAILED_FCS_CRC; >> + if (rx_desc->bw) >> + rx_status->bw = RATE_INFO_BW_40; >> >> - if (rx_desc->rxht) { >> - rx_status->encoding = RX_ENC_HT; >> - rx_status->rate_idx = rx_desc->rxmcs - DESC_RATE_MCS0; >> - } else { >> - rx_status->rate_idx = rx_desc->rxmcs; >> - } >> + if (rx_desc->rxht) { >> + rx_status->encoding = RX_ENC_HT; >> + rx_status->rate_idx = rx_desc->rxmcs - DESC_RATE_MCS0; >> + } else { >> + rx_status->rate_idx = rx_desc->rxmcs; >> + } >> >> - rx_status->freq = hw->conf.chandef.chan->center_freq; >> - rx_status->band = hw->conf.chandef.chan->band; >> + rx_status->freq = hw->conf.chandef.chan->center_freq; >> + rx_status->band = hw->conf.chandef.chan->band; >> >> - ieee80211_rx_irqsafe(hw, skb); >> + ieee80211_rx_irqsafe(hw, skb); >> + } >> >> skb = next_skb; >> if (skb) >> > > [...] > > Only some minor comments. > > Thank you for the patches. > -- > Ping-Ke > I'll make the changes. Thank you for reviewing.