diff mbox series

[net-next] r8169: improve RTL8411b phy-down fixup

Message ID f1a5f918-e9fd-48e6-8956-2c79648e563e@gmail.com (mailing list archive)
State Accepted
Commit 055dd7511f675d26fa283b35bb3dadfc7f77ed97
Delegated to: Netdev Maintainers
Headers show
Series [net-next] r8169: improve RTL8411b phy-down fixup | expand

Checks

Context Check Description
netdev/series_format success Single patches do not need cover letters
netdev/tree_selection success Clearly marked for net-next
netdev/fixes_present success Fixes tag not required for -next series
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 1134 this patch: 1134
netdev/cc_maintainers success CCed 6 of 6 maintainers
netdev/build_clang success Errors and warnings before: 1161 this patch: 1161
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/deprecated_api success None detected
netdev/check_selftest success No net selftest shell script
netdev/verify_fixes success No Fixes tag
netdev/build_allmodconfig_warn success Errors and warnings before: 1161 this patch: 1161
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 151 lines checked
netdev/build_clang_rust success No Rust files in patch. Skipping build
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0

Commit Message

Heiner Kallweit Nov. 13, 2023, 7:13 p.m. UTC
Mirsad proposed a patch to reduce the number of spinlock lock/unlock
operations and the function code size. This can be further improved
because the function sets a consecutive register block.

Suggested-by: Mirsad Todorovac <mirsad.todorovac@alu.unizg.hr>
Signed-off-by: Heiner Kallweit <hkallweit1@gmail.com>
---
 drivers/net/ethernet/realtek/r8169_main.c | 139 +++++-----------------
 1 file changed, 28 insertions(+), 111 deletions(-)

Comments

Simon Horman Nov. 15, 2023, 5:35 p.m. UTC | #1
On Mon, Nov 13, 2023 at 08:13:26PM +0100, Heiner Kallweit wrote:
> Mirsad proposed a patch to reduce the number of spinlock lock/unlock
> operations and the function code size. This can be further improved
> because the function sets a consecutive register block.
> 
> Suggested-by: Mirsad Todorovac <mirsad.todorovac@alu.unizg.hr>
> Signed-off-by: Heiner Kallweit <hkallweit1@gmail.com>
> ---
>  drivers/net/ethernet/realtek/r8169_main.c | 139 +++++-----------------
>  1 file changed, 28 insertions(+), 111 deletions(-)

Nice. Less code and fewer locks.

I manually verified that fix_data matches the code it replaces.

Reviewed-by: Simon Horman <horms@kernel.org>
Mirsad Todorovac Nov. 15, 2023, 10:17 p.m. UTC | #2
On 11/13/23 20:13, Heiner Kallweit wrote:
> Mirsad proposed a patch to reduce the number of spinlock lock/unlock
> operations and the function code size. This can be further improved
> because the function sets a consecutive register block.
> 
> Suggested-by: Mirsad Todorovac <mirsad.todorovac@alu.unizg.hr>
> Signed-off-by: Heiner Kallweit <hkallweit1@gmail.com>
> ---
>   drivers/net/ethernet/realtek/r8169_main.c | 139 +++++-----------------
>   1 file changed, 28 insertions(+), 111 deletions(-)
> 
> diff --git a/drivers/net/ethernet/realtek/r8169_main.c b/drivers/net/ethernet/realtek/r8169_main.c
> index 93929d835..e883db468 100644
> --- a/drivers/net/ethernet/realtek/r8169_main.c
> +++ b/drivers/net/ethernet/realtek/r8169_main.c
> @@ -3084,6 +3084,33 @@ static void rtl_hw_start_8168g_2(struct rtl8169_private *tp)
>   	rtl_ephy_init(tp, e_info_8168g_2);
>   }
>   
> +static void rtl8411b_fix_phy_down(struct rtl8169_private *tp)
> +{
> +	static const u16 fix_data[] = {
> +/* 0xf800 */ 0xe008, 0xe00a, 0xe00c, 0xe00e, 0xe027, 0xe04f, 0xe05e, 0xe065,
> +/* 0xf810 */ 0xc602, 0xbe00, 0x0000, 0xc502, 0xbd00, 0x074c, 0xc302, 0xbb00,
> +/* 0xf820 */ 0x080a, 0x6420, 0x48c2, 0x8c20, 0xc516, 0x64a4, 0x49c0, 0xf009,
> +/* 0xf830 */ 0x74a2, 0x8ca5, 0x74a0, 0xc50e, 0x9ca2, 0x1c11, 0x9ca0, 0xe006,
> +/* 0xf840 */ 0x74f8, 0x48c4, 0x8cf8, 0xc404, 0xbc00, 0xc403, 0xbc00, 0x0bf2,
> +/* 0xf850 */ 0x0c0a, 0xe434, 0xd3c0, 0x49d9, 0xf01f, 0xc526, 0x64a5, 0x1400,
> +/* 0xf860 */ 0xf007, 0x0c01, 0x8ca5, 0x1c15, 0xc51b, 0x9ca0, 0xe013, 0xc519,
> +/* 0xf870 */ 0x74a0, 0x48c4, 0x8ca0, 0xc516, 0x74a4, 0x48c8, 0x48ca, 0x9ca4,
> +/* 0xf880 */ 0xc512, 0x1b00, 0x9ba0, 0x1b1c, 0x483f, 0x9ba2, 0x1b04, 0xc508,
> +/* 0xf890 */ 0x9ba0, 0xc505, 0xbd00, 0xc502, 0xbd00, 0x0300, 0x051e, 0xe434,
> +/* 0xf8a0 */ 0xe018, 0xe092, 0xde20, 0xd3c0, 0xc50f, 0x76a4, 0x49e3, 0xf007,
> +/* 0xf8b0 */ 0x49c0, 0xf103, 0xc607, 0xbe00, 0xc606, 0xbe00, 0xc602, 0xbe00,
> +/* 0xf8c0 */ 0x0c4c, 0x0c28, 0x0c2c, 0xdc00, 0xc707, 0x1d00, 0x8de2, 0x48c1,
> +/* 0xf8d0 */ 0xc502, 0xbd00, 0x00aa, 0xe0c0, 0xc502, 0xbd00, 0x0132
> +	};
> +	unsigned long flags;
> +	int i;
> +
> +	raw_spin_lock_irqsave(&tp->mac_ocp_lock, flags);
> +	for (i = 0; i < ARRAY_SIZE(fix_data); i++)
> +		__r8168_mac_ocp_write(tp, 0xf800 + 2 * i, fix_data[i]);
> +	raw_spin_unlock_irqrestore(&tp->mac_ocp_lock, flags);
> +}
> +

Actually, this is much better than my patch proposal.

I was perhaps trying to make the function more (or too) general.

I made a small minimal program to programmatically test the table against the
r8168_mac_ocp_write() embedded values, and the table fix_data[] checks OK.

Unable to test w/o a physical rtl8411b.

To verify result, I am submitting the code:

--------------------------------------------------------------------------------------
#include <stdio.h>
#include <stdlib.h>

int main (int argc, char argv[])
{
         FILE *fp_ocp;
         char *line = NULL;
         size_t n = 0;
         int ln = 0;
         unsigned int addr, value, oldaddr;

         if ((fp_ocp = fopen("mac_ocp_bulk", "r")) == NULL)
                 perror("fopen");
         else
                 while (getline(&line, &n, fp_ocp) != -1) {

                         sscanf(line, "-%*s %x, %x", &addr, &value);
                         if (ln == 0)
                                 oldaddr = addr;
                         else if (addr - oldaddr != 2) {
                                 printf("%x %x not sequential!\n", oldaddr, addr);
                                 break;
                         }
                         oldaddr = addr;
                         if (ln != 0)
                                 if (ln % 8 == 0)
                                         printf(",\n");
                                 else
                                         printf(", ");
                         if (ln % 8 == 0)
                                 printf("/* 0x%04x */ 0x%04x", addr, value);
                         else
                                 printf("0x%04x", value);
                         ln ++;

                 }
         fclose(fp_ocp);
         printf("\n");
}
------------------------------------------------------------------------------------

Commands used:

  2086  cat fix_data | cut -c 2- > fix_cut
  2087  ./check
  2088  ./check > fix_cut_from_ocp
  2089  diff fix_cut fix_cut_from_ocp

Best regards,
Mirsad Todorovac

>   static void rtl_hw_start_8411_2(struct rtl8169_private *tp)
>   {
>   	static const struct ephy_info e_info_8411_2[] = {
> @@ -3117,117 +3144,7 @@ static void rtl_hw_start_8411_2(struct rtl8169_private *tp)
>   	mdelay(3);
>   	r8168_mac_ocp_write(tp, 0xFC26, 0x0000);
>   
> -	r8168_mac_ocp_write(tp, 0xF800, 0xE008);
> -	r8168_mac_ocp_write(tp, 0xF802, 0xE00A);
> -	r8168_mac_ocp_write(tp, 0xF804, 0xE00C);
> -	r8168_mac_ocp_write(tp, 0xF806, 0xE00E);
> -	r8168_mac_ocp_write(tp, 0xF808, 0xE027);
> -	r8168_mac_ocp_write(tp, 0xF80A, 0xE04F);
> -	r8168_mac_ocp_write(tp, 0xF80C, 0xE05E);
> -	r8168_mac_ocp_write(tp, 0xF80E, 0xE065);
> -	r8168_mac_ocp_write(tp, 0xF810, 0xC602);
> -	r8168_mac_ocp_write(tp, 0xF812, 0xBE00);
> -	r8168_mac_ocp_write(tp, 0xF814, 0x0000);
> -	r8168_mac_ocp_write(tp, 0xF816, 0xC502);
> -	r8168_mac_ocp_write(tp, 0xF818, 0xBD00);
> -	r8168_mac_ocp_write(tp, 0xF81A, 0x074C);
> -	r8168_mac_ocp_write(tp, 0xF81C, 0xC302);
> -	r8168_mac_ocp_write(tp, 0xF81E, 0xBB00);
> -	r8168_mac_ocp_write(tp, 0xF820, 0x080A);
> -	r8168_mac_ocp_write(tp, 0xF822, 0x6420);
> -	r8168_mac_ocp_write(tp, 0xF824, 0x48C2);
> -	r8168_mac_ocp_write(tp, 0xF826, 0x8C20);
> -	r8168_mac_ocp_write(tp, 0xF828, 0xC516);
> -	r8168_mac_ocp_write(tp, 0xF82A, 0x64A4);
> -	r8168_mac_ocp_write(tp, 0xF82C, 0x49C0);
> -	r8168_mac_ocp_write(tp, 0xF82E, 0xF009);
> -	r8168_mac_ocp_write(tp, 0xF830, 0x74A2);
> -	r8168_mac_ocp_write(tp, 0xF832, 0x8CA5);
> -	r8168_mac_ocp_write(tp, 0xF834, 0x74A0);
> -	r8168_mac_ocp_write(tp, 0xF836, 0xC50E);
> -	r8168_mac_ocp_write(tp, 0xF838, 0x9CA2);
> -	r8168_mac_ocp_write(tp, 0xF83A, 0x1C11);
> -	r8168_mac_ocp_write(tp, 0xF83C, 0x9CA0);
> -	r8168_mac_ocp_write(tp, 0xF83E, 0xE006);
> -	r8168_mac_ocp_write(tp, 0xF840, 0x74F8);
> -	r8168_mac_ocp_write(tp, 0xF842, 0x48C4);
> -	r8168_mac_ocp_write(tp, 0xF844, 0x8CF8);
> -	r8168_mac_ocp_write(tp, 0xF846, 0xC404);
> -	r8168_mac_ocp_write(tp, 0xF848, 0xBC00);
> -	r8168_mac_ocp_write(tp, 0xF84A, 0xC403);
> -	r8168_mac_ocp_write(tp, 0xF84C, 0xBC00);
> -	r8168_mac_ocp_write(tp, 0xF84E, 0x0BF2);
> -	r8168_mac_ocp_write(tp, 0xF850, 0x0C0A);
> -	r8168_mac_ocp_write(tp, 0xF852, 0xE434);
> -	r8168_mac_ocp_write(tp, 0xF854, 0xD3C0);
> -	r8168_mac_ocp_write(tp, 0xF856, 0x49D9);
> -	r8168_mac_ocp_write(tp, 0xF858, 0xF01F);
> -	r8168_mac_ocp_write(tp, 0xF85A, 0xC526);
> -	r8168_mac_ocp_write(tp, 0xF85C, 0x64A5);
> -	r8168_mac_ocp_write(tp, 0xF85E, 0x1400);
> -	r8168_mac_ocp_write(tp, 0xF860, 0xF007);
> -	r8168_mac_ocp_write(tp, 0xF862, 0x0C01);
> -	r8168_mac_ocp_write(tp, 0xF864, 0x8CA5);
> -	r8168_mac_ocp_write(tp, 0xF866, 0x1C15);
> -	r8168_mac_ocp_write(tp, 0xF868, 0xC51B);
> -	r8168_mac_ocp_write(tp, 0xF86A, 0x9CA0);
> -	r8168_mac_ocp_write(tp, 0xF86C, 0xE013);
> -	r8168_mac_ocp_write(tp, 0xF86E, 0xC519);
> -	r8168_mac_ocp_write(tp, 0xF870, 0x74A0);
> -	r8168_mac_ocp_write(tp, 0xF872, 0x48C4);
> -	r8168_mac_ocp_write(tp, 0xF874, 0x8CA0);
> -	r8168_mac_ocp_write(tp, 0xF876, 0xC516);
> -	r8168_mac_ocp_write(tp, 0xF878, 0x74A4);
> -	r8168_mac_ocp_write(tp, 0xF87A, 0x48C8);
> -	r8168_mac_ocp_write(tp, 0xF87C, 0x48CA);
> -	r8168_mac_ocp_write(tp, 0xF87E, 0x9CA4);
> -	r8168_mac_ocp_write(tp, 0xF880, 0xC512);
> -	r8168_mac_ocp_write(tp, 0xF882, 0x1B00);
> -	r8168_mac_ocp_write(tp, 0xF884, 0x9BA0);
> -	r8168_mac_ocp_write(tp, 0xF886, 0x1B1C);
> -	r8168_mac_ocp_write(tp, 0xF888, 0x483F);
> -	r8168_mac_ocp_write(tp, 0xF88A, 0x9BA2);
> -	r8168_mac_ocp_write(tp, 0xF88C, 0x1B04);
> -	r8168_mac_ocp_write(tp, 0xF88E, 0xC508);
> -	r8168_mac_ocp_write(tp, 0xF890, 0x9BA0);
> -	r8168_mac_ocp_write(tp, 0xF892, 0xC505);
> -	r8168_mac_ocp_write(tp, 0xF894, 0xBD00);
> -	r8168_mac_ocp_write(tp, 0xF896, 0xC502);
> -	r8168_mac_ocp_write(tp, 0xF898, 0xBD00);
> -	r8168_mac_ocp_write(tp, 0xF89A, 0x0300);
> -	r8168_mac_ocp_write(tp, 0xF89C, 0x051E);
> -	r8168_mac_ocp_write(tp, 0xF89E, 0xE434);
> -	r8168_mac_ocp_write(tp, 0xF8A0, 0xE018);
> -	r8168_mac_ocp_write(tp, 0xF8A2, 0xE092);
> -	r8168_mac_ocp_write(tp, 0xF8A4, 0xDE20);
> -	r8168_mac_ocp_write(tp, 0xF8A6, 0xD3C0);
> -	r8168_mac_ocp_write(tp, 0xF8A8, 0xC50F);
> -	r8168_mac_ocp_write(tp, 0xF8AA, 0x76A4);
> -	r8168_mac_ocp_write(tp, 0xF8AC, 0x49E3);
> -	r8168_mac_ocp_write(tp, 0xF8AE, 0xF007);
> -	r8168_mac_ocp_write(tp, 0xF8B0, 0x49C0);
> -	r8168_mac_ocp_write(tp, 0xF8B2, 0xF103);
> -	r8168_mac_ocp_write(tp, 0xF8B4, 0xC607);
> -	r8168_mac_ocp_write(tp, 0xF8B6, 0xBE00);
> -	r8168_mac_ocp_write(tp, 0xF8B8, 0xC606);
> -	r8168_mac_ocp_write(tp, 0xF8BA, 0xBE00);
> -	r8168_mac_ocp_write(tp, 0xF8BC, 0xC602);
> -	r8168_mac_ocp_write(tp, 0xF8BE, 0xBE00);
> -	r8168_mac_ocp_write(tp, 0xF8C0, 0x0C4C);
> -	r8168_mac_ocp_write(tp, 0xF8C2, 0x0C28);
> -	r8168_mac_ocp_write(tp, 0xF8C4, 0x0C2C);
> -	r8168_mac_ocp_write(tp, 0xF8C6, 0xDC00);
> -	r8168_mac_ocp_write(tp, 0xF8C8, 0xC707);
> -	r8168_mac_ocp_write(tp, 0xF8CA, 0x1D00);
> -	r8168_mac_ocp_write(tp, 0xF8CC, 0x8DE2);
> -	r8168_mac_ocp_write(tp, 0xF8CE, 0x48C1);
> -	r8168_mac_ocp_write(tp, 0xF8D0, 0xC502);
> -	r8168_mac_ocp_write(tp, 0xF8D2, 0xBD00);
> -	r8168_mac_ocp_write(tp, 0xF8D4, 0x00AA);
> -	r8168_mac_ocp_write(tp, 0xF8D6, 0xE0C0);
> -	r8168_mac_ocp_write(tp, 0xF8D8, 0xC502);
> -	r8168_mac_ocp_write(tp, 0xF8DA, 0xBD00);
> -	r8168_mac_ocp_write(tp, 0xF8DC, 0x0132);
> +	rtl8411b_fix_phy_down(tp);
>   
>   	r8168_mac_ocp_write(tp, 0xFC26, 0x8000);
>
Mirsad Todorovac Nov. 16, 2023, 5:56 a.m. UTC | #3
On 15. 11. 2023. 23:17, Mirsad Todorovac wrote:
> On 11/13/23 20:13, Heiner Kallweit wrote:
>> Mirsad proposed a patch to reduce the number of spinlock lock/unlock
>> operations and the function code size. This can be further improved
>> because the function sets a consecutive register block.
>>
>> Suggested-by: Mirsad Todorovac <mirsad.todorovac@alu.unizg.hr>
>> Signed-off-by: Heiner Kallweit <hkallweit1@gmail.com>
>> ---
>>   drivers/net/ethernet/realtek/r8169_main.c | 139 +++++-----------------
>>   1 file changed, 28 insertions(+), 111 deletions(-)
>>
>> diff --git a/drivers/net/ethernet/realtek/r8169_main.c b/drivers/net/ethernet/realtek/r8169_main.c
>> index 93929d835..e883db468 100644
>> --- a/drivers/net/ethernet/realtek/r8169_main.c
>> +++ b/drivers/net/ethernet/realtek/r8169_main.c
>> @@ -3084,6 +3084,33 @@ static void rtl_hw_start_8168g_2(struct rtl8169_private *tp)
>>   	rtl_ephy_init(tp, e_info_8168g_2);
>>   }
>>   
>> +static void rtl8411b_fix_phy_down(struct rtl8169_private *tp)
>> +{
>> +	static const u16 fix_data[] = {
>> +/* 0xf800 */ 0xe008, 0xe00a, 0xe00c, 0xe00e, 0xe027, 0xe04f, 0xe05e, 0xe065,
>> +/* 0xf810 */ 0xc602, 0xbe00, 0x0000, 0xc502, 0xbd00, 0x074c, 0xc302, 0xbb00,
>> +/* 0xf820 */ 0x080a, 0x6420, 0x48c2, 0x8c20, 0xc516, 0x64a4, 0x49c0, 0xf009,
>> +/* 0xf830 */ 0x74a2, 0x8ca5, 0x74a0, 0xc50e, 0x9ca2, 0x1c11, 0x9ca0, 0xe006,
>> +/* 0xf840 */ 0x74f8, 0x48c4, 0x8cf8, 0xc404, 0xbc00, 0xc403, 0xbc00, 0x0bf2,
>> +/* 0xf850 */ 0x0c0a, 0xe434, 0xd3c0, 0x49d9, 0xf01f, 0xc526, 0x64a5, 0x1400,
>> +/* 0xf860 */ 0xf007, 0x0c01, 0x8ca5, 0x1c15, 0xc51b, 0x9ca0, 0xe013, 0xc519,
>> +/* 0xf870 */ 0x74a0, 0x48c4, 0x8ca0, 0xc516, 0x74a4, 0x48c8, 0x48ca, 0x9ca4,
>> +/* 0xf880 */ 0xc512, 0x1b00, 0x9ba0, 0x1b1c, 0x483f, 0x9ba2, 0x1b04, 0xc508,
>> +/* 0xf890 */ 0x9ba0, 0xc505, 0xbd00, 0xc502, 0xbd00, 0x0300, 0x051e, 0xe434,
>> +/* 0xf8a0 */ 0xe018, 0xe092, 0xde20, 0xd3c0, 0xc50f, 0x76a4, 0x49e3, 0xf007,
>> +/* 0xf8b0 */ 0x49c0, 0xf103, 0xc607, 0xbe00, 0xc606, 0xbe00, 0xc602, 0xbe00,
>> +/* 0xf8c0 */ 0x0c4c, 0x0c28, 0x0c2c, 0xdc00, 0xc707, 0x1d00, 0x8de2, 0x48c1,
>> +/* 0xf8d0 */ 0xc502, 0xbd00, 0x00aa, 0xe0c0, 0xc502, 0xbd00, 0x0132
>> +	};
>> +	unsigned long flags;
>> +	int i;
>> +
>> +	raw_spin_lock_irqsave(&tp->mac_ocp_lock, flags);
>> +	for (i = 0; i < ARRAY_SIZE(fix_data); i++)
>> +		__r8168_mac_ocp_write(tp, 0xf800 + 2 * i, fix_data[i]);
>> +	raw_spin_unlock_irqrestore(&tp->mac_ocp_lock, flags);
>> +}
>> +
> 
> Actually, this is much better than my patch proposal.
> 
> I was perhaps trying to make the function more (or too) general.
> 
> I made a small minimal program to programmatically test the table against the
> r8168_mac_ocp_write() embedded values, and the table fix_data[] checks OK.
> 
> Unable to test w/o a physical rtl8411b.
> 
> To verify result, I am submitting the code:
> 
> --------------------------------------------------------------------------------------
> #include <stdio.h>
> #include <stdlib.h>
> 
> int main (int argc, char argv[])
> {
>          FILE *fp_ocp;
>          char *line = NULL;
>          size_t n = 0;
>          int ln = 0;
>          unsigned int addr, value, oldaddr;
> 
>          if ((fp_ocp = fopen("mac_ocp_bulk", "r")) == NULL)
>                  perror("fopen");
>          else
>                  while (getline(&line, &n, fp_ocp) != -1) {
> 
>                          sscanf(line, "-%*s %x, %x", &addr, &value);
>                          if (ln == 0)
>                                  oldaddr = addr;
>                          else if (addr - oldaddr != 2) {
>                                  printf("%x %x not sequential!\n", oldaddr, addr);
>                                  break;
>                          }
>                          oldaddr = addr;
>                          if (ln != 0)
>                                  if (ln % 8 == 0)
>                                          printf(",\n");
>                                  else
>                                          printf(", ");
>                          if (ln % 8 == 0)
>                                  printf("/* 0x%04x */ 0x%04x", addr, value);
>                          else
>                                  printf("0x%04x", value);
>                          ln ++;
> 
>                  }
>          fclose(fp_ocp);
>          printf("\n");
> }
> ------------------------------------------------------------------------------------
> 
> Commands used:
> 
>   2086  cat fix_data | cut -c 2- > fix_cut
>   2087  ./check
>   2088  ./check > fix_cut_from_ocp
>   2089  diff fix_cut fix_cut_from_ocp

Based on the programmatic proof of the correctness of fix_data table when compared
to r8168_mac_ocp_write() sequential calls, and a suggestion from the maintainer,
I am adding a Reviewed-by: tag:

Reviewed-by: Mirsad Todorovac <mirsad.todorovac@alu.unizg.hr>

>>   static void rtl_hw_start_8411_2(struct rtl8169_private *tp)
>>   {
>>   	static const struct ephy_info e_info_8411_2[] = {
>> @@ -3117,117 +3144,7 @@ static void rtl_hw_start_8411_2(struct rtl8169_private *tp)
>>   	mdelay(3);
>>   	r8168_mac_ocp_write(tp, 0xFC26, 0x0000);
>>   
>> -	r8168_mac_ocp_write(tp, 0xF800, 0xE008);
>> -	r8168_mac_ocp_write(tp, 0xF802, 0xE00A);
>> -	r8168_mac_ocp_write(tp, 0xF804, 0xE00C);
>> -	r8168_mac_ocp_write(tp, 0xF806, 0xE00E);
>> -	r8168_mac_ocp_write(tp, 0xF808, 0xE027);
>> -	r8168_mac_ocp_write(tp, 0xF80A, 0xE04F);
>> -	r8168_mac_ocp_write(tp, 0xF80C, 0xE05E);
>> -	r8168_mac_ocp_write(tp, 0xF80E, 0xE065);
>> -	r8168_mac_ocp_write(tp, 0xF810, 0xC602);
>> -	r8168_mac_ocp_write(tp, 0xF812, 0xBE00);
>> -	r8168_mac_ocp_write(tp, 0xF814, 0x0000);
>> -	r8168_mac_ocp_write(tp, 0xF816, 0xC502);
>> -	r8168_mac_ocp_write(tp, 0xF818, 0xBD00);
>> -	r8168_mac_ocp_write(tp, 0xF81A, 0x074C);
>> -	r8168_mac_ocp_write(tp, 0xF81C, 0xC302);
>> -	r8168_mac_ocp_write(tp, 0xF81E, 0xBB00);
>> -	r8168_mac_ocp_write(tp, 0xF820, 0x080A);
>> -	r8168_mac_ocp_write(tp, 0xF822, 0x6420);
>> -	r8168_mac_ocp_write(tp, 0xF824, 0x48C2);
>> -	r8168_mac_ocp_write(tp, 0xF826, 0x8C20);
>> -	r8168_mac_ocp_write(tp, 0xF828, 0xC516);
>> -	r8168_mac_ocp_write(tp, 0xF82A, 0x64A4);
>> -	r8168_mac_ocp_write(tp, 0xF82C, 0x49C0);
>> -	r8168_mac_ocp_write(tp, 0xF82E, 0xF009);
>> -	r8168_mac_ocp_write(tp, 0xF830, 0x74A2);
>> -	r8168_mac_ocp_write(tp, 0xF832, 0x8CA5);
>> -	r8168_mac_ocp_write(tp, 0xF834, 0x74A0);
>> -	r8168_mac_ocp_write(tp, 0xF836, 0xC50E);
>> -	r8168_mac_ocp_write(tp, 0xF838, 0x9CA2);
>> -	r8168_mac_ocp_write(tp, 0xF83A, 0x1C11);
>> -	r8168_mac_ocp_write(tp, 0xF83C, 0x9CA0);
>> -	r8168_mac_ocp_write(tp, 0xF83E, 0xE006);
>> -	r8168_mac_ocp_write(tp, 0xF840, 0x74F8);
>> -	r8168_mac_ocp_write(tp, 0xF842, 0x48C4);
>> -	r8168_mac_ocp_write(tp, 0xF844, 0x8CF8);
>> -	r8168_mac_ocp_write(tp, 0xF846, 0xC404);
>> -	r8168_mac_ocp_write(tp, 0xF848, 0xBC00);
>> -	r8168_mac_ocp_write(tp, 0xF84A, 0xC403);
>> -	r8168_mac_ocp_write(tp, 0xF84C, 0xBC00);
>> -	r8168_mac_ocp_write(tp, 0xF84E, 0x0BF2);
>> -	r8168_mac_ocp_write(tp, 0xF850, 0x0C0A);
>> -	r8168_mac_ocp_write(tp, 0xF852, 0xE434);
>> -	r8168_mac_ocp_write(tp, 0xF854, 0xD3C0);
>> -	r8168_mac_ocp_write(tp, 0xF856, 0x49D9);
>> -	r8168_mac_ocp_write(tp, 0xF858, 0xF01F);
>> -	r8168_mac_ocp_write(tp, 0xF85A, 0xC526);
>> -	r8168_mac_ocp_write(tp, 0xF85C, 0x64A5);
>> -	r8168_mac_ocp_write(tp, 0xF85E, 0x1400);
>> -	r8168_mac_ocp_write(tp, 0xF860, 0xF007);
>> -	r8168_mac_ocp_write(tp, 0xF862, 0x0C01);
>> -	r8168_mac_ocp_write(tp, 0xF864, 0x8CA5);
>> -	r8168_mac_ocp_write(tp, 0xF866, 0x1C15);
>> -	r8168_mac_ocp_write(tp, 0xF868, 0xC51B);
>> -	r8168_mac_ocp_write(tp, 0xF86A, 0x9CA0);
>> -	r8168_mac_ocp_write(tp, 0xF86C, 0xE013);
>> -	r8168_mac_ocp_write(tp, 0xF86E, 0xC519);
>> -	r8168_mac_ocp_write(tp, 0xF870, 0x74A0);
>> -	r8168_mac_ocp_write(tp, 0xF872, 0x48C4);
>> -	r8168_mac_ocp_write(tp, 0xF874, 0x8CA0);
>> -	r8168_mac_ocp_write(tp, 0xF876, 0xC516);
>> -	r8168_mac_ocp_write(tp, 0xF878, 0x74A4);
>> -	r8168_mac_ocp_write(tp, 0xF87A, 0x48C8);
>> -	r8168_mac_ocp_write(tp, 0xF87C, 0x48CA);
>> -	r8168_mac_ocp_write(tp, 0xF87E, 0x9CA4);
>> -	r8168_mac_ocp_write(tp, 0xF880, 0xC512);
>> -	r8168_mac_ocp_write(tp, 0xF882, 0x1B00);
>> -	r8168_mac_ocp_write(tp, 0xF884, 0x9BA0);
>> -	r8168_mac_ocp_write(tp, 0xF886, 0x1B1C);
>> -	r8168_mac_ocp_write(tp, 0xF888, 0x483F);
>> -	r8168_mac_ocp_write(tp, 0xF88A, 0x9BA2);
>> -	r8168_mac_ocp_write(tp, 0xF88C, 0x1B04);
>> -	r8168_mac_ocp_write(tp, 0xF88E, 0xC508);
>> -	r8168_mac_ocp_write(tp, 0xF890, 0x9BA0);
>> -	r8168_mac_ocp_write(tp, 0xF892, 0xC505);
>> -	r8168_mac_ocp_write(tp, 0xF894, 0xBD00);
>> -	r8168_mac_ocp_write(tp, 0xF896, 0xC502);
>> -	r8168_mac_ocp_write(tp, 0xF898, 0xBD00);
>> -	r8168_mac_ocp_write(tp, 0xF89A, 0x0300);
>> -	r8168_mac_ocp_write(tp, 0xF89C, 0x051E);
>> -	r8168_mac_ocp_write(tp, 0xF89E, 0xE434);
>> -	r8168_mac_ocp_write(tp, 0xF8A0, 0xE018);
>> -	r8168_mac_ocp_write(tp, 0xF8A2, 0xE092);
>> -	r8168_mac_ocp_write(tp, 0xF8A4, 0xDE20);
>> -	r8168_mac_ocp_write(tp, 0xF8A6, 0xD3C0);
>> -	r8168_mac_ocp_write(tp, 0xF8A8, 0xC50F);
>> -	r8168_mac_ocp_write(tp, 0xF8AA, 0x76A4);
>> -	r8168_mac_ocp_write(tp, 0xF8AC, 0x49E3);
>> -	r8168_mac_ocp_write(tp, 0xF8AE, 0xF007);
>> -	r8168_mac_ocp_write(tp, 0xF8B0, 0x49C0);
>> -	r8168_mac_ocp_write(tp, 0xF8B2, 0xF103);
>> -	r8168_mac_ocp_write(tp, 0xF8B4, 0xC607);
>> -	r8168_mac_ocp_write(tp, 0xF8B6, 0xBE00);
>> -	r8168_mac_ocp_write(tp, 0xF8B8, 0xC606);
>> -	r8168_mac_ocp_write(tp, 0xF8BA, 0xBE00);
>> -	r8168_mac_ocp_write(tp, 0xF8BC, 0xC602);
>> -	r8168_mac_ocp_write(tp, 0xF8BE, 0xBE00);
>> -	r8168_mac_ocp_write(tp, 0xF8C0, 0x0C4C);
>> -	r8168_mac_ocp_write(tp, 0xF8C2, 0x0C28);
>> -	r8168_mac_ocp_write(tp, 0xF8C4, 0x0C2C);
>> -	r8168_mac_ocp_write(tp, 0xF8C6, 0xDC00);
>> -	r8168_mac_ocp_write(tp, 0xF8C8, 0xC707);
>> -	r8168_mac_ocp_write(tp, 0xF8CA, 0x1D00);
>> -	r8168_mac_ocp_write(tp, 0xF8CC, 0x8DE2);
>> -	r8168_mac_ocp_write(tp, 0xF8CE, 0x48C1);
>> -	r8168_mac_ocp_write(tp, 0xF8D0, 0xC502);
>> -	r8168_mac_ocp_write(tp, 0xF8D2, 0xBD00);
>> -	r8168_mac_ocp_write(tp, 0xF8D4, 0x00AA);
>> -	r8168_mac_ocp_write(tp, 0xF8D6, 0xE0C0);
>> -	r8168_mac_ocp_write(tp, 0xF8D8, 0xC502);
>> -	r8168_mac_ocp_write(tp, 0xF8DA, 0xBD00);
>> -	r8168_mac_ocp_write(tp, 0xF8DC, 0x0132);
>> +	rtl8411b_fix_phy_down(tp);
>>   
>>   	r8168_mac_ocp_write(tp, 0xFC26, 0x8000);
>>
Heiner Kallweit Nov. 17, 2023, 6:43 a.m. UTC | #4
On 13.11.2023 20:13, Heiner Kallweit wrote:
> Mirsad proposed a patch to reduce the number of spinlock lock/unlock
> operations and the function code size. This can be further improved
> because the function sets a consecutive register block.
> 
> Suggested-by: Mirsad Todorovac <mirsad.todorovac@alu.unizg.hr>
> Signed-off-by: Heiner Kallweit <hkallweit1@gmail.com>
> ---
>  drivers/net/ethernet/realtek/r8169_main.c | 139 +++++-----------------
>  1 file changed, 28 insertions(+), 111 deletions(-)
> 
> diff --git a/drivers/net/ethernet/realtek/r8169_main.c b/drivers/net/ethernet/realtek/r8169_main.c
> index 93929d835..e883db468 100644
> --- a/drivers/net/ethernet/realtek/r8169_main.c
> +++ b/drivers/net/ethernet/realtek/r8169_main.c
> @@ -3084,6 +3084,33 @@ static void rtl_hw_start_8168g_2(struct rtl8169_private *tp)
>  	rtl_ephy_init(tp, e_info_8168g_2);
>  }
>  
Is there a specific reason why patch has status "Deferred" in patchwork?
Jakub Kicinski Nov. 18, 2023, 6:24 p.m. UTC | #5
On Fri, 17 Nov 2023 07:43:04 +0100 Heiner Kallweit wrote:
> Is there a specific reason why patch has status "Deferred" in patchwork?

No idea :S

pw-bot: new
patchwork-bot+netdevbpf@kernel.org Nov. 18, 2023, 10:30 p.m. UTC | #6
Hello:

This patch was applied to netdev/net-next.git (main)
by David S. Miller <davem@davemloft.net>:

On Mon, 13 Nov 2023 20:13:26 +0100 you wrote:
> Mirsad proposed a patch to reduce the number of spinlock lock/unlock
> operations and the function code size. This can be further improved
> because the function sets a consecutive register block.
> 
> Suggested-by: Mirsad Todorovac <mirsad.todorovac@alu.unizg.hr>
> Signed-off-by: Heiner Kallweit <hkallweit1@gmail.com>
> 
> [...]

Here is the summary with links:
  - [net-next] r8169: improve RTL8411b phy-down fixup
    https://git.kernel.org/netdev/net-next/c/055dd7511f67

You are awesome, thank you!
diff mbox series

Patch

diff --git a/drivers/net/ethernet/realtek/r8169_main.c b/drivers/net/ethernet/realtek/r8169_main.c
index 93929d835..e883db468 100644
--- a/drivers/net/ethernet/realtek/r8169_main.c
+++ b/drivers/net/ethernet/realtek/r8169_main.c
@@ -3084,6 +3084,33 @@  static void rtl_hw_start_8168g_2(struct rtl8169_private *tp)
 	rtl_ephy_init(tp, e_info_8168g_2);
 }
 
+static void rtl8411b_fix_phy_down(struct rtl8169_private *tp)
+{
+	static const u16 fix_data[] = {
+/* 0xf800 */ 0xe008, 0xe00a, 0xe00c, 0xe00e, 0xe027, 0xe04f, 0xe05e, 0xe065,
+/* 0xf810 */ 0xc602, 0xbe00, 0x0000, 0xc502, 0xbd00, 0x074c, 0xc302, 0xbb00,
+/* 0xf820 */ 0x080a, 0x6420, 0x48c2, 0x8c20, 0xc516, 0x64a4, 0x49c0, 0xf009,
+/* 0xf830 */ 0x74a2, 0x8ca5, 0x74a0, 0xc50e, 0x9ca2, 0x1c11, 0x9ca0, 0xe006,
+/* 0xf840 */ 0x74f8, 0x48c4, 0x8cf8, 0xc404, 0xbc00, 0xc403, 0xbc00, 0x0bf2,
+/* 0xf850 */ 0x0c0a, 0xe434, 0xd3c0, 0x49d9, 0xf01f, 0xc526, 0x64a5, 0x1400,
+/* 0xf860 */ 0xf007, 0x0c01, 0x8ca5, 0x1c15, 0xc51b, 0x9ca0, 0xe013, 0xc519,
+/* 0xf870 */ 0x74a0, 0x48c4, 0x8ca0, 0xc516, 0x74a4, 0x48c8, 0x48ca, 0x9ca4,
+/* 0xf880 */ 0xc512, 0x1b00, 0x9ba0, 0x1b1c, 0x483f, 0x9ba2, 0x1b04, 0xc508,
+/* 0xf890 */ 0x9ba0, 0xc505, 0xbd00, 0xc502, 0xbd00, 0x0300, 0x051e, 0xe434,
+/* 0xf8a0 */ 0xe018, 0xe092, 0xde20, 0xd3c0, 0xc50f, 0x76a4, 0x49e3, 0xf007,
+/* 0xf8b0 */ 0x49c0, 0xf103, 0xc607, 0xbe00, 0xc606, 0xbe00, 0xc602, 0xbe00,
+/* 0xf8c0 */ 0x0c4c, 0x0c28, 0x0c2c, 0xdc00, 0xc707, 0x1d00, 0x8de2, 0x48c1,
+/* 0xf8d0 */ 0xc502, 0xbd00, 0x00aa, 0xe0c0, 0xc502, 0xbd00, 0x0132
+	};
+	unsigned long flags;
+	int i;
+
+	raw_spin_lock_irqsave(&tp->mac_ocp_lock, flags);
+	for (i = 0; i < ARRAY_SIZE(fix_data); i++)
+		__r8168_mac_ocp_write(tp, 0xf800 + 2 * i, fix_data[i]);
+	raw_spin_unlock_irqrestore(&tp->mac_ocp_lock, flags);
+}
+
 static void rtl_hw_start_8411_2(struct rtl8169_private *tp)
 {
 	static const struct ephy_info e_info_8411_2[] = {
@@ -3117,117 +3144,7 @@  static void rtl_hw_start_8411_2(struct rtl8169_private *tp)
 	mdelay(3);
 	r8168_mac_ocp_write(tp, 0xFC26, 0x0000);
 
-	r8168_mac_ocp_write(tp, 0xF800, 0xE008);
-	r8168_mac_ocp_write(tp, 0xF802, 0xE00A);
-	r8168_mac_ocp_write(tp, 0xF804, 0xE00C);
-	r8168_mac_ocp_write(tp, 0xF806, 0xE00E);
-	r8168_mac_ocp_write(tp, 0xF808, 0xE027);
-	r8168_mac_ocp_write(tp, 0xF80A, 0xE04F);
-	r8168_mac_ocp_write(tp, 0xF80C, 0xE05E);
-	r8168_mac_ocp_write(tp, 0xF80E, 0xE065);
-	r8168_mac_ocp_write(tp, 0xF810, 0xC602);
-	r8168_mac_ocp_write(tp, 0xF812, 0xBE00);
-	r8168_mac_ocp_write(tp, 0xF814, 0x0000);
-	r8168_mac_ocp_write(tp, 0xF816, 0xC502);
-	r8168_mac_ocp_write(tp, 0xF818, 0xBD00);
-	r8168_mac_ocp_write(tp, 0xF81A, 0x074C);
-	r8168_mac_ocp_write(tp, 0xF81C, 0xC302);
-	r8168_mac_ocp_write(tp, 0xF81E, 0xBB00);
-	r8168_mac_ocp_write(tp, 0xF820, 0x080A);
-	r8168_mac_ocp_write(tp, 0xF822, 0x6420);
-	r8168_mac_ocp_write(tp, 0xF824, 0x48C2);
-	r8168_mac_ocp_write(tp, 0xF826, 0x8C20);
-	r8168_mac_ocp_write(tp, 0xF828, 0xC516);
-	r8168_mac_ocp_write(tp, 0xF82A, 0x64A4);
-	r8168_mac_ocp_write(tp, 0xF82C, 0x49C0);
-	r8168_mac_ocp_write(tp, 0xF82E, 0xF009);
-	r8168_mac_ocp_write(tp, 0xF830, 0x74A2);
-	r8168_mac_ocp_write(tp, 0xF832, 0x8CA5);
-	r8168_mac_ocp_write(tp, 0xF834, 0x74A0);
-	r8168_mac_ocp_write(tp, 0xF836, 0xC50E);
-	r8168_mac_ocp_write(tp, 0xF838, 0x9CA2);
-	r8168_mac_ocp_write(tp, 0xF83A, 0x1C11);
-	r8168_mac_ocp_write(tp, 0xF83C, 0x9CA0);
-	r8168_mac_ocp_write(tp, 0xF83E, 0xE006);
-	r8168_mac_ocp_write(tp, 0xF840, 0x74F8);
-	r8168_mac_ocp_write(tp, 0xF842, 0x48C4);
-	r8168_mac_ocp_write(tp, 0xF844, 0x8CF8);
-	r8168_mac_ocp_write(tp, 0xF846, 0xC404);
-	r8168_mac_ocp_write(tp, 0xF848, 0xBC00);
-	r8168_mac_ocp_write(tp, 0xF84A, 0xC403);
-	r8168_mac_ocp_write(tp, 0xF84C, 0xBC00);
-	r8168_mac_ocp_write(tp, 0xF84E, 0x0BF2);
-	r8168_mac_ocp_write(tp, 0xF850, 0x0C0A);
-	r8168_mac_ocp_write(tp, 0xF852, 0xE434);
-	r8168_mac_ocp_write(tp, 0xF854, 0xD3C0);
-	r8168_mac_ocp_write(tp, 0xF856, 0x49D9);
-	r8168_mac_ocp_write(tp, 0xF858, 0xF01F);
-	r8168_mac_ocp_write(tp, 0xF85A, 0xC526);
-	r8168_mac_ocp_write(tp, 0xF85C, 0x64A5);
-	r8168_mac_ocp_write(tp, 0xF85E, 0x1400);
-	r8168_mac_ocp_write(tp, 0xF860, 0xF007);
-	r8168_mac_ocp_write(tp, 0xF862, 0x0C01);
-	r8168_mac_ocp_write(tp, 0xF864, 0x8CA5);
-	r8168_mac_ocp_write(tp, 0xF866, 0x1C15);
-	r8168_mac_ocp_write(tp, 0xF868, 0xC51B);
-	r8168_mac_ocp_write(tp, 0xF86A, 0x9CA0);
-	r8168_mac_ocp_write(tp, 0xF86C, 0xE013);
-	r8168_mac_ocp_write(tp, 0xF86E, 0xC519);
-	r8168_mac_ocp_write(tp, 0xF870, 0x74A0);
-	r8168_mac_ocp_write(tp, 0xF872, 0x48C4);
-	r8168_mac_ocp_write(tp, 0xF874, 0x8CA0);
-	r8168_mac_ocp_write(tp, 0xF876, 0xC516);
-	r8168_mac_ocp_write(tp, 0xF878, 0x74A4);
-	r8168_mac_ocp_write(tp, 0xF87A, 0x48C8);
-	r8168_mac_ocp_write(tp, 0xF87C, 0x48CA);
-	r8168_mac_ocp_write(tp, 0xF87E, 0x9CA4);
-	r8168_mac_ocp_write(tp, 0xF880, 0xC512);
-	r8168_mac_ocp_write(tp, 0xF882, 0x1B00);
-	r8168_mac_ocp_write(tp, 0xF884, 0x9BA0);
-	r8168_mac_ocp_write(tp, 0xF886, 0x1B1C);
-	r8168_mac_ocp_write(tp, 0xF888, 0x483F);
-	r8168_mac_ocp_write(tp, 0xF88A, 0x9BA2);
-	r8168_mac_ocp_write(tp, 0xF88C, 0x1B04);
-	r8168_mac_ocp_write(tp, 0xF88E, 0xC508);
-	r8168_mac_ocp_write(tp, 0xF890, 0x9BA0);
-	r8168_mac_ocp_write(tp, 0xF892, 0xC505);
-	r8168_mac_ocp_write(tp, 0xF894, 0xBD00);
-	r8168_mac_ocp_write(tp, 0xF896, 0xC502);
-	r8168_mac_ocp_write(tp, 0xF898, 0xBD00);
-	r8168_mac_ocp_write(tp, 0xF89A, 0x0300);
-	r8168_mac_ocp_write(tp, 0xF89C, 0x051E);
-	r8168_mac_ocp_write(tp, 0xF89E, 0xE434);
-	r8168_mac_ocp_write(tp, 0xF8A0, 0xE018);
-	r8168_mac_ocp_write(tp, 0xF8A2, 0xE092);
-	r8168_mac_ocp_write(tp, 0xF8A4, 0xDE20);
-	r8168_mac_ocp_write(tp, 0xF8A6, 0xD3C0);
-	r8168_mac_ocp_write(tp, 0xF8A8, 0xC50F);
-	r8168_mac_ocp_write(tp, 0xF8AA, 0x76A4);
-	r8168_mac_ocp_write(tp, 0xF8AC, 0x49E3);
-	r8168_mac_ocp_write(tp, 0xF8AE, 0xF007);
-	r8168_mac_ocp_write(tp, 0xF8B0, 0x49C0);
-	r8168_mac_ocp_write(tp, 0xF8B2, 0xF103);
-	r8168_mac_ocp_write(tp, 0xF8B4, 0xC607);
-	r8168_mac_ocp_write(tp, 0xF8B6, 0xBE00);
-	r8168_mac_ocp_write(tp, 0xF8B8, 0xC606);
-	r8168_mac_ocp_write(tp, 0xF8BA, 0xBE00);
-	r8168_mac_ocp_write(tp, 0xF8BC, 0xC602);
-	r8168_mac_ocp_write(tp, 0xF8BE, 0xBE00);
-	r8168_mac_ocp_write(tp, 0xF8C0, 0x0C4C);
-	r8168_mac_ocp_write(tp, 0xF8C2, 0x0C28);
-	r8168_mac_ocp_write(tp, 0xF8C4, 0x0C2C);
-	r8168_mac_ocp_write(tp, 0xF8C6, 0xDC00);
-	r8168_mac_ocp_write(tp, 0xF8C8, 0xC707);
-	r8168_mac_ocp_write(tp, 0xF8CA, 0x1D00);
-	r8168_mac_ocp_write(tp, 0xF8CC, 0x8DE2);
-	r8168_mac_ocp_write(tp, 0xF8CE, 0x48C1);
-	r8168_mac_ocp_write(tp, 0xF8D0, 0xC502);
-	r8168_mac_ocp_write(tp, 0xF8D2, 0xBD00);
-	r8168_mac_ocp_write(tp, 0xF8D4, 0x00AA);
-	r8168_mac_ocp_write(tp, 0xF8D6, 0xE0C0);
-	r8168_mac_ocp_write(tp, 0xF8D8, 0xC502);
-	r8168_mac_ocp_write(tp, 0xF8DA, 0xBD00);
-	r8168_mac_ocp_write(tp, 0xF8DC, 0x0132);
+	rtl8411b_fix_phy_down(tp);
 
 	r8168_mac_ocp_write(tp, 0xFC26, 0x8000);