All of lore.kernel.org
 help / color / mirror / Atom feed
From: Ping-Ke Shih <pkshih@realtek.com>
To: Bitterblue Smith <rtl8821cerfe2@gmail.com>,
	"linux-wireless@vger.kernel.org" <linux-wireless@vger.kernel.org>
Cc: Larry Finger <Larry.Finger@lwfinger.net>,
	Stefan Lippers-Hollmann <s.l-h@gmx.de>,
	Christian Hewitt <chewitt@libreelec.tv>
Subject: RE: [PATCH v5 5/6] wifi: rtlwifi: Clean up rtl8192d-common a bit
Date: Wed, 17 Apr 2024 06:48:06 +0000	[thread overview]
Message-ID: <72bd1a7172154d4e9a79678e5151cdf3@realtek.com> (raw)
In-Reply-To: <4e47c56c-4b7f-4ae6-84b9-05f0cac97dac@gmail.com>

Bitterblue Smith <rtl8821cerfe2@gmail.com> wrote:

> Improve readability:
>  * add empty lines
>  * use abs_diff in rtl92d_dm_txpower_tracking_callback_thermalmeter
>  * roll up repeated statements into a for loop in
>    rtl92d_dm_txpower_tracking_callback_thermalmeter
>  * shorten lines by replacing many instances of "rtlpriv->dm" with "dm"
>    pointer in rtl92d_dm_txpower_tracking_callback_thermalmeter
>  * sort some declarations by length
>  * refactor _rtl92d_get_txpower_writeval_by_regulatory a little
> 
> Delete unused structs tag_dynamic_init_gain_operation_type_definition
> and swat.
> 
> Simplify rtl92d_fill_h2c_cmd a little and delete a pointless wrapper
> function.
> 

[...]

> @@ -137,16 +135,18 @@ static void rtl92d_dm_rxgain_tracking_thermalmeter(struct ieee80211_hw *hw)
>                 0x05, 0x04, 0x04, 0x03, 0x02
>         };
>         struct rtl_priv *rtlpriv = rtl_priv(hw);
> +       int i, idx;
>         u32 u4tmp;
> -       int i;
> 
> -       u4tmp = (index_mapping[(rtlpriv->efuse.eeprom_thermalmeter -
> -                               rtlpriv->dm.thermalvalue_rxgain)]) << 12;
> +       idx = rtlpriv->efuse.eeprom_thermalmeter - rtlpriv->dm.thermalvalue_rxgain;
> +       u4tmp = index_mapping[idx] << 12;
> +
>         rtl_dbg(rtlpriv, COMP_POWER_TRACKING, DBG_LOUD,
>                 "===> Rx Gain %x\n", u4tmp);
> +
>         for (i = RF90_PATH_A; i < rtlpriv->phy.num_total_rfpath; i++)
>                 rtl_set_rfreg(hw, i, 0x3C, RFREG_OFFSET_MASK,
> -                             (rtlpriv->phy.reg_rf3c[i] & (~(0xF000))) | u4tmp);
> +                             (rtlpriv->phy.reg_rf3c[i] & ~0xF000) | u4tmp);

There are similar instances like 'tmp1byte &= ~(BIT(0));'
Maybe, you can use coccinelle (spatch) as helper to convert all of them.

[...]

> @@ -713,22 +696,17 @@ void rtl92d_dm_false_alarm_counter_statistics(struct ieee80211_hw *hw)
>                 falsealm_cnt->cnt_cck_fail = 0;
>         }
> 
> -       /* reset false alarm counter registers */
> -       falsealm_cnt->cnt_all = falsealm_cnt->cnt_fast_fsync_fail +
> -                               falsealm_cnt->cnt_sb_search_fail +
> -                               falsealm_cnt->cnt_parity_fail +
> -                               falsealm_cnt->cnt_rate_illegal +
> -                               falsealm_cnt->cnt_crc8_fail +
> -                               falsealm_cnt->cnt_mcs_fail +
> +       falsealm_cnt->cnt_all = falsealm_cnt->cnt_ofdm_fail +
>                                 falsealm_cnt->cnt_cck_fail;

Not sure why you did this change.

[...]

> @@ -228,35 +238,25 @@ static void _rtl92d_fill_h2c_command(struct ieee80211_hw *hw,
>                         break;
>                 }
>         }
> +
>         while (!bwrite_success) {
>                 wait_writeh2c_limmit--;
>                 if (wait_writeh2c_limmit == 0) {
>                         pr_err("Write H2C fail because no trigger for FW INT!\n");
>                         break;
>                 }
> +
>                 boxnum = rtlhal->last_hmeboxnum;
>                 switch (boxnum) {
> -               case 0:
> -                       box_reg = REG_HMEBOX_0;
> -                       box_extreg = REG_HMEBOX_EXT_0;
> -                       break;
> -               case 1:
> -                       box_reg = REG_HMEBOX_1;
> -                       box_extreg = REG_HMEBOX_EXT_1;
> -                       break;
> -               case 2:
> -                       box_reg = REG_HMEBOX_2;
> -                       box_extreg = REG_HMEBOX_EXT_2;
> -                       break;
> -               case 3:
> -                       box_reg = REG_HMEBOX_3;
> -                       box_extreg = REG_HMEBOX_EXT_3;
> +               case 0 ... 3:
> +                       box_reg = REG_HMEBOX_0 + boxnum * 4;
> +                       box_extreg = REG_HMEBOX_EXT_0 + boxnum * 2;

Should be "* 4" as well?

box_extreg = REG_HMEBOX_EXT_0 + boxnum * 4;

>                         break;
>                 default:
> -                       pr_err("switch case %#x not processed\n",
> -                              boxnum);
> +                       pr_err("switch case %#x not processed\n", boxnum);
>                         break;
>                 }
> +
>                 isfw_read = _rtl92d_check_fw_read_last_h2c(hw, boxnum);
>                 while (!isfw_read) {
>                         wait_h2c_limmit--;
> @@ -266,78 +266,63 @@ static void _rtl92d_fill_h2c_command(struct ieee80211_hw *hw,
>                                         boxnum);
>                                 break;
>                         }
> +
>                         udelay(10);
> +
>                         isfw_read = _rtl92d_check_fw_read_last_h2c(hw, boxnum);
>                         u1b_tmp = rtl_read_byte(rtlpriv, 0x1BF);
>                         rtl_dbg(rtlpriv, COMP_CMD, DBG_LOUD,
>                                 "Waiting for FW read clear HMEBox(%d)!!! 0x1BF = %2x\n",
>                                 boxnum, u1b_tmp);
>                 }
> +
>                 if (!isfw_read) {
>                         rtl_dbg(rtlpriv, COMP_CMD, DBG_LOUD,
>                                 "Write H2C register BOX[%d] fail!!!!! Fw do not read.\n",
>                                 boxnum);
>                         break;
>                 }
> +
>                 memset(boxcontent, 0, sizeof(boxcontent));
>                 memset(boxextcontent, 0, sizeof(boxextcontent));
>                 boxcontent[0] = element_id;
> +
>                 rtl_dbg(rtlpriv, COMP_CMD, DBG_LOUD,
>                         "Write element_id box_reg(%4x) = %2x\n",
>                         box_reg, element_id);
> +
>                 switch (cmd_len) {
> -               case 1:
> -                       boxcontent[0] &= ~(BIT(7));
> -                       memcpy(boxcontent + 1, cmdbuffer + buf_index, 1);
> -                       for (idx = 0; idx < 4; idx++)
> -                               rtl_write_byte(rtlpriv, box_reg + idx,
> -                                              boxcontent[idx]);
> -                       break;
> -               case 2:
> -                       boxcontent[0] &= ~(BIT(7));
> -                       memcpy(boxcontent + 1, cmdbuffer + buf_index, 2);
> -                       for (idx = 0; idx < 4; idx++)
> -                               rtl_write_byte(rtlpriv, box_reg + idx,
> -                                              boxcontent[idx]);
> -                       break;
> -               case 3:
> -                       boxcontent[0] &= ~(BIT(7));
> -                       memcpy(boxcontent + 1, cmdbuffer + buf_index, 3);
> -                       for (idx = 0; idx < 4; idx++)
> -                               rtl_write_byte(rtlpriv, box_reg + idx,
> -                                              boxcontent[idx]);
> -                       break;
> -               case 4:
> -                       boxcontent[0] |= (BIT(7));
> -                       memcpy(boxextcontent, cmdbuffer + buf_index, 2);
> -                       memcpy(boxcontent + 1, cmdbuffer + buf_index + 2, 2);
> -                       for (idx = 0; idx < 2; idx++)
> -                               rtl_write_byte(rtlpriv, box_extreg + idx,
> -                                              boxextcontent[idx]);
> +               case 1 ... 3:
> +                       boxcontent[0] &= ~BIT(7);
> +                       memcpy(boxcontent + 1, cmdbuffer, cmd_len);
> +
>                         for (idx = 0; idx < 4; idx++)
>                                 rtl_write_byte(rtlpriv, box_reg + idx,
>                                                boxcontent[idx]);
>                         break;
> -               case 5:
> -                       boxcontent[0] |= (BIT(7));
> -                       memcpy(boxextcontent, cmdbuffer + buf_index, 2);
> -                       memcpy(boxcontent + 1, cmdbuffer + buf_index + 2, 3);
> +               case 4 ... 5:
> +                       boxcontent[0] |= BIT(7);
> +                       memcpy(boxextcontent, cmdbuffer, 2);
> +                       memcpy(boxcontent + 1, cmdbuffer + 2, cmd_len - 2);

After reading these statements of "case 4...5", I eventually know how BIT(7) works.
With BIT(7) additional two command buffers are introduced, and argument[0...1] are
put into the new buffers. Maybe, we can add a comment to help people to understand
this part.

case 1...3
  BOX:      | ID | A0 | A1 | A2 |
  BOX_EXT:  --- N/A ------

case 4...5
  * ID ext = ID | BIT(7)
  BOX:      | ID ext | A2 | A3 | A4 |
  BOX_EXT:  | A0     | A1 |

[...]



  reply	other threads:[~2024-04-17  6:48 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-04-15 20:23 [PATCH v5 0/6] wifi: rtlwifi: Move common code from rtl8192de to rtl8192d-common Bitterblue Smith
2024-04-15 20:24 ` [PATCH v5 1/6] wifi: rtlwifi: rtl8192de: Fix 5 GHz TX power Bitterblue Smith
2024-04-15 20:24 ` [PATCH v5 2/6] wifi: rtlwifi: rtl8192de: Fix low speed with WPA3-SAE Bitterblue Smith
2024-04-15 20:26 ` [PATCH v5 3/6] wifi: rtlwifi: rtl8192de: Fix endianness issue in RX path Bitterblue Smith
2024-04-17  2:30   ` Ping-Ke Shih
2024-04-15 20:27 ` [PATCH v5 4/6] wifi: rtlwifi: Move code from rtl8192de to rtl8192d-common Bitterblue Smith
2024-04-17  4:04   ` Ping-Ke Shih
2024-04-17 16:43     ` Bitterblue Smith
2024-04-18  0:42       ` Ping-Ke Shih
2024-04-18 11:40         ` Bitterblue Smith
2024-04-15 20:29 ` [PATCH v5 5/6] wifi: rtlwifi: Clean up rtl8192d-common a bit Bitterblue Smith
2024-04-17  6:48   ` Ping-Ke Shih [this message]
2024-04-17 17:13     ` Bitterblue Smith
2024-04-18  0:49       ` Ping-Ke Shih
2024-04-18 12:22         ` Bitterblue Smith
2024-04-15 20:29 ` [PATCH v5 6/6] wifi: rtlwifi: Adjust rtl8192d-common for USB Bitterblue Smith
2024-04-17  7:33   ` Ping-Ke Shih
2024-04-17 17:29     ` Bitterblue Smith

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=72bd1a7172154d4e9a79678e5151cdf3@realtek.com \
    --to=pkshih@realtek.com \
    --cc=Larry.Finger@lwfinger.net \
    --cc=chewitt@libreelec.tv \
    --cc=linux-wireless@vger.kernel.org \
    --cc=rtl8821cerfe2@gmail.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.