200-r8127-print-link-speed-and-duplex-mode.patch 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. From 5ca1d47e065c0318774a946ffdf76010c78cc164 Mon Sep 17 00:00:00 2001
  2. From: Chukun Pan <[email protected]>
  3. Date: Sat, 10 Aug 2024 20:16:32 +0800
  4. Subject: [PATCH] r8127: print link speed and duplex mode
  5. MIME-Version: 1.0
  6. Content-Type: text/plain; charset=UTF-8
  7. Content-Transfer-Encoding: 8bit
  8. Like other Ethernet drivers, print link speed and duplex mode
  9. when the interface is up. Formatting output at the same time.
  10. Signed-off-by: Chukun Pan <[email protected]>
  11. Signed-off-by: Álvaro Fernández Rojas <[email protected]>
  12. ---
  13. src/r8127.h | 2 ++
  14. src/r8127_n.c | 48 +++++++++++++++++++++++++++++++++++++++++++++---
  15. 2 files changed, 47 insertions(+), 3 deletions(-)
  16. --- a/src/r8127.h
  17. +++ b/src/r8127.h
  18. @@ -1753,6 +1753,11 @@ enum RTL8127_register_content {
  19. LinkStatus = 0x02,
  20. FullDup = 0x01,
  21. +#define RTL8127_FULL_DUPLEX_MASK (_10000bpsF | _5000bpsF | _2500bpsF | _1000bpsF | FullDup)
  22. +#define RTL8127_SPEED_1000_MASK (_1000bpsF | _1000bpsL | _2500bpsL)
  23. +#define RTL8127_SPEED_2500_MASK (_2500bpsF | _5000bpsL)
  24. +#define RTL8127_SPEED_5000_MASK (_5000bpsF | _10000bpsL)
  25. +
  26. /* DBG_reg */
  27. Fix_Nak_1 = (1 << 4),
  28. Fix_Nak_2 = (1 << 3),
  29. --- a/src/r8127_n.c
  30. +++ b/src/r8127_n.c
  31. @@ -39,6 +39,7 @@
  32. #include <linux/module.h>
  33. #include <linux/version.h>
  34. #include <linux/pci.h>
  35. +#include <linux/phy.h>
  36. #include <linux/netdevice.h>
  37. #include <linux/etherdevice.h>
  38. #include <linux/delay.h>
  39. @@ -4746,6 +4747,42 @@ rtl8127_link_down_patch(struct net_devic
  40. #endif
  41. }
  42. +static unsigned int rtl8127_phy_duplex(u32 status)
  43. +{
  44. + unsigned int duplex = DUPLEX_UNKNOWN;
  45. +
  46. + if (status & LinkStatus) {
  47. + if (status & RTL8127_FULL_DUPLEX_MASK)
  48. + duplex = DUPLEX_FULL;
  49. + else
  50. + duplex = DUPLEX_HALF;
  51. + }
  52. +
  53. + return duplex;
  54. +}
  55. +
  56. +static int rtl8127_phy_speed(u32 status)
  57. +{
  58. + int speed = SPEED_UNKNOWN;
  59. +
  60. + if (status & LinkStatus) {
  61. + if (status & _10000bpsF)
  62. + speed = SPEED_10000;
  63. + else if (status & RTL8127_SPEED_5000_MASK)
  64. + speed = SPEED_5000;
  65. + else if (status & RTL8127_SPEED_2500_MASK)
  66. + speed = SPEED_2500;
  67. + else if (status & RTL8127_SPEED_1000_MASK)
  68. + speed = SPEED_1000;
  69. + else if (status & _100bps)
  70. + speed = SPEED_100;
  71. + else if (status & _10bps)
  72. + speed = SPEED_10;
  73. + }
  74. +
  75. + return speed;
  76. +}
  77. +
  78. static void
  79. _rtl8127_check_link_status(struct net_device *dev, unsigned int link_state)
  80. {
  81. @@ -4758,11 +4795,18 @@ _rtl8127_check_link_status(struct net_de
  82. if (link_state == R8127_LINK_STATE_ON) {
  83. rtl8127_link_on_patch(dev);
  84. - if (netif_msg_ifup(tp))
  85. - printk(KERN_INFO PFX "%s: link up\n", dev->name);
  86. + if (netif_msg_ifup(tp)) {
  87. + const u32 phy_status = RTL_R32(tp, PHYstatus);
  88. + const unsigned int phy_duplex = rtl8127_phy_duplex(phy_status);
  89. + const int phy_speed = rtl8127_phy_speed(phy_status);
  90. + printk(KERN_INFO PFX "%s: Link is Up - %s/%s\n",
  91. + dev->name,
  92. + phy_speed_to_str(phy_speed),
  93. + phy_duplex_to_str(phy_duplex));
  94. + }
  95. } else {
  96. if (netif_msg_ifdown(tp))
  97. - printk(KERN_INFO PFX "%s: link down\n", dev->name);
  98. + printk(KERN_INFO PFX "%s: Link is Down\n", dev->name);
  99. rtl8127_link_down_patch(dev);
  100. }