410-net-phy-allow-settings-table-to-support-more-than-32.patch 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. From: Russell King <[email protected]>
  2. Date: Thu, 5 Jan 2017 16:32:14 +0000
  3. Subject: [PATCH] net: phy: allow settings table to support more than 32
  4. link modes
  5. Allow the phy settings table to support more than 32 link modes by
  6. switching to the ethtool link mode bit number representation, rather
  7. than storing the mask. This will allow phylink and other ethtool
  8. code to share the settings table to look up settings.
  9. Signed-off-by: Russell King <[email protected]>
  10. ---
  11. --- a/drivers/net/phy/phy.c
  12. +++ b/drivers/net/phy/phy.c
  13. @@ -175,7 +175,7 @@ static inline int phy_aneg_done(struct p
  14. struct phy_setting {
  15. int speed;
  16. int duplex;
  17. - u32 setting;
  18. + int bit;
  19. };
  20. /* A mapping of all SUPPORTED settings to speed/duplex. This table
  21. @@ -185,57 +185,57 @@ static const struct phy_setting settings
  22. {
  23. .speed = SPEED_10000,
  24. .duplex = DUPLEX_FULL,
  25. - .setting = SUPPORTED_10000baseKR_Full,
  26. + .bit = ETHTOOL_LINK_MODE_10000baseKR_Full_BIT,
  27. },
  28. {
  29. .speed = SPEED_10000,
  30. .duplex = DUPLEX_FULL,
  31. - .setting = SUPPORTED_10000baseKX4_Full,
  32. + .bit = ETHTOOL_LINK_MODE_10000baseKX4_Full_BIT,
  33. },
  34. {
  35. .speed = SPEED_10000,
  36. .duplex = DUPLEX_FULL,
  37. - .setting = SUPPORTED_10000baseT_Full,
  38. + .bit = ETHTOOL_LINK_MODE_10000baseT_Full_BIT,
  39. },
  40. {
  41. .speed = SPEED_2500,
  42. .duplex = DUPLEX_FULL,
  43. - .setting = SUPPORTED_2500baseX_Full,
  44. + .bit = ETHTOOL_LINK_MODE_2500baseX_Full_BIT,
  45. },
  46. {
  47. .speed = SPEED_1000,
  48. .duplex = DUPLEX_FULL,
  49. - .setting = SUPPORTED_1000baseKX_Full,
  50. + .bit = ETHTOOL_LINK_MODE_1000baseKX_Full_BIT,
  51. },
  52. {
  53. .speed = SPEED_1000,
  54. .duplex = DUPLEX_FULL,
  55. - .setting = SUPPORTED_1000baseT_Full,
  56. + .bit = ETHTOOL_LINK_MODE_1000baseT_Full_BIT,
  57. },
  58. {
  59. .speed = SPEED_1000,
  60. .duplex = DUPLEX_HALF,
  61. - .setting = SUPPORTED_1000baseT_Half,
  62. + .bit = ETHTOOL_LINK_MODE_1000baseT_Half_BIT,
  63. },
  64. {
  65. .speed = SPEED_100,
  66. .duplex = DUPLEX_FULL,
  67. - .setting = SUPPORTED_100baseT_Full,
  68. + .bit = ETHTOOL_LINK_MODE_100baseT_Full_BIT,
  69. },
  70. {
  71. .speed = SPEED_100,
  72. .duplex = DUPLEX_HALF,
  73. - .setting = SUPPORTED_100baseT_Half,
  74. + .bit = ETHTOOL_LINK_MODE_100baseT_Half_BIT,
  75. },
  76. {
  77. .speed = SPEED_10,
  78. .duplex = DUPLEX_FULL,
  79. - .setting = SUPPORTED_10baseT_Full,
  80. + .bit = ETHTOOL_LINK_MODE_10baseT_Full_BIT,
  81. },
  82. {
  83. .speed = SPEED_10,
  84. .duplex = DUPLEX_HALF,
  85. - .setting = SUPPORTED_10baseT_Half,
  86. + .bit = ETHTOOL_LINK_MODE_10baseT_Half_BIT,
  87. },
  88. };
  89. @@ -243,7 +243,8 @@ static const struct phy_setting settings
  90. * phy_lookup_setting - lookup a PHY setting
  91. * @speed: speed to match
  92. * @duplex: duplex to match
  93. - * @feature: allowed link modes
  94. + * @mask: allowed link modes
  95. + * @maxbit: bit size of link modes
  96. * @exact: an exact match is required
  97. *
  98. * Search the settings array for a setting that matches the speed and
  99. @@ -257,13 +258,14 @@ static const struct phy_setting settings
  100. * they all fail, %NULL will be returned.
  101. */
  102. static const struct phy_setting *
  103. -phy_lookup_setting(int speed, int duplex, u32 features, bool exact)
  104. +phy_lookup_setting(int speed, int duplex, const unsigned long *mask,
  105. + size_t maxbit, bool exact)
  106. {
  107. const struct phy_setting *p, *match = NULL, *last = NULL;
  108. int i;
  109. for (i = 0, p = settings; i < ARRAY_SIZE(settings); i++, p++) {
  110. - if (p->setting & features) {
  111. + if (p->bit < maxbit && test_bit(p->bit, mask)) {
  112. last = p;
  113. if (p->speed == speed && p->duplex == duplex) {
  114. /* Exact match for speed and duplex */
  115. @@ -302,7 +304,9 @@ phy_lookup_setting(int speed, int duplex
  116. static const struct phy_setting *
  117. phy_find_valid(int speed, int duplex, u32 supported)
  118. {
  119. - return phy_lookup_setting(speed, duplex, supported, false);
  120. + unsigned long mask = supported;
  121. +
  122. + return phy_lookup_setting(speed, duplex, &mask, BITS_PER_LONG, false);
  123. }
  124. /**
  125. @@ -316,7 +320,9 @@ phy_find_valid(int speed, int duplex, u3
  126. */
  127. static inline bool phy_check_valid(int speed, int duplex, u32 features)
  128. {
  129. - return !!phy_lookup_setting(speed, duplex, features, true);
  130. + unsigned long mask = features;
  131. +
  132. + return !!phy_lookup_setting(speed, duplex, &mask, BITS_PER_LONG, true);
  133. }
  134. /**