780-36-v6.16-r8169-refactor-chip-version-detection.patch 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401
  1. From 2b065c098c37a3ed28df7c3be59dca61b9da8402 Mon Sep 17 00:00:00 2001
  2. From: Heiner Kallweit <[email protected]>
  3. Date: Tue, 15 Apr 2025 21:29:34 +0200
  4. Subject: [PATCH] r8169: refactor chip version detection
  5. Refactor chip version detection and merge both configuration tables.
  6. Apart from reducing the code by a third, this paves the way for
  7. merging chip version handling if only difference is the firmware.
  8. Signed-off-by: Heiner Kallweit <[email protected]>
  9. Reviewed-by: Michal Swiatkowski <[email protected]>
  10. Link: https://patch.msgid.link/[email protected]
  11. Signed-off-by: Jakub Kicinski <[email protected]>
  12. ---
  13. drivers/net/ethernet/realtek/r8169_main.c | 325 +++++++++-------------
  14. 1 file changed, 128 insertions(+), 197 deletions(-)
  15. --- a/drivers/net/ethernet/realtek/r8169_main.c
  16. +++ b/drivers/net/ethernet/realtek/r8169_main.c
  17. @@ -91,61 +91,114 @@
  18. #define JUMBO_9K (9 * SZ_1K - VLAN_ETH_HLEN - ETH_FCS_LEN)
  19. #define JUMBO_16K (SZ_16K - VLAN_ETH_HLEN - ETH_FCS_LEN)
  20. -static const struct {
  21. +static const struct rtl_chip_info {
  22. + u16 mask;
  23. + u16 val;
  24. + enum mac_version mac_version;
  25. const char *name;
  26. const char *fw_name;
  27. } rtl_chip_infos[] = {
  28. - /* PCI devices. */
  29. - [RTL_GIGA_MAC_VER_02] = {"RTL8169s" },
  30. - [RTL_GIGA_MAC_VER_03] = {"RTL8110s" },
  31. - [RTL_GIGA_MAC_VER_04] = {"RTL8169sb/8110sb" },
  32. - [RTL_GIGA_MAC_VER_05] = {"RTL8169sc/8110sc" },
  33. - [RTL_GIGA_MAC_VER_06] = {"RTL8169sc/8110sc" },
  34. - /* PCI-E devices. */
  35. - [RTL_GIGA_MAC_VER_07] = {"RTL8102e" },
  36. - [RTL_GIGA_MAC_VER_08] = {"RTL8102e" },
  37. - [RTL_GIGA_MAC_VER_09] = {"RTL8102e/RTL8103e" },
  38. - [RTL_GIGA_MAC_VER_10] = {"RTL8101e/RTL8100e" },
  39. - [RTL_GIGA_MAC_VER_14] = {"RTL8401" },
  40. - [RTL_GIGA_MAC_VER_17] = {"RTL8168b/8111b" },
  41. - [RTL_GIGA_MAC_VER_18] = {"RTL8168cp/8111cp" },
  42. - [RTL_GIGA_MAC_VER_19] = {"RTL8168c/8111c" },
  43. - [RTL_GIGA_MAC_VER_20] = {"RTL8168c/8111c" },
  44. - [RTL_GIGA_MAC_VER_21] = {"RTL8168c/8111c" },
  45. - [RTL_GIGA_MAC_VER_22] = {"RTL8168c/8111c" },
  46. - [RTL_GIGA_MAC_VER_23] = {"RTL8168cp/8111cp" },
  47. - [RTL_GIGA_MAC_VER_24] = {"RTL8168cp/8111cp" },
  48. - [RTL_GIGA_MAC_VER_25] = {"RTL8168d/8111d", FIRMWARE_8168D_1},
  49. - [RTL_GIGA_MAC_VER_26] = {"RTL8168d/8111d", FIRMWARE_8168D_2},
  50. - [RTL_GIGA_MAC_VER_28] = {"RTL8168dp/8111dp" },
  51. - [RTL_GIGA_MAC_VER_29] = {"RTL8105e", FIRMWARE_8105E_1},
  52. - [RTL_GIGA_MAC_VER_30] = {"RTL8105e", FIRMWARE_8105E_1},
  53. - [RTL_GIGA_MAC_VER_31] = {"RTL8168dp/8111dp" },
  54. - [RTL_GIGA_MAC_VER_32] = {"RTL8168e/8111e", FIRMWARE_8168E_1},
  55. - [RTL_GIGA_MAC_VER_33] = {"RTL8168e/8111e", FIRMWARE_8168E_2},
  56. - [RTL_GIGA_MAC_VER_34] = {"RTL8168evl/8111evl", FIRMWARE_8168E_3},
  57. - [RTL_GIGA_MAC_VER_35] = {"RTL8168f/8111f", FIRMWARE_8168F_1},
  58. - [RTL_GIGA_MAC_VER_36] = {"RTL8168f/8111f", FIRMWARE_8168F_2},
  59. - [RTL_GIGA_MAC_VER_37] = {"RTL8402", FIRMWARE_8402_1 },
  60. - [RTL_GIGA_MAC_VER_38] = {"RTL8411", FIRMWARE_8411_1 },
  61. - [RTL_GIGA_MAC_VER_39] = {"RTL8106e", FIRMWARE_8106E_1},
  62. - [RTL_GIGA_MAC_VER_40] = {"RTL8168g/8111g", FIRMWARE_8168G_2},
  63. - [RTL_GIGA_MAC_VER_42] = {"RTL8168gu/8111gu", FIRMWARE_8168G_3},
  64. - [RTL_GIGA_MAC_VER_43] = {"RTL8106eus", FIRMWARE_8106E_2},
  65. - [RTL_GIGA_MAC_VER_44] = {"RTL8411b", FIRMWARE_8411_2 },
  66. - [RTL_GIGA_MAC_VER_46] = {"RTL8168h/8111h", FIRMWARE_8168H_2},
  67. - [RTL_GIGA_MAC_VER_48] = {"RTL8107e", FIRMWARE_8107E_2},
  68. - [RTL_GIGA_MAC_VER_51] = {"RTL8168ep/8111ep" },
  69. - [RTL_GIGA_MAC_VER_52] = {"RTL8168fp/RTL8117", FIRMWARE_8168FP_3},
  70. - [RTL_GIGA_MAC_VER_53] = {"RTL8168fp/RTL8117", },
  71. - [RTL_GIGA_MAC_VER_61] = {"RTL8125A", FIRMWARE_8125A_3},
  72. - /* reserve 62 for CFG_METHOD_4 in the vendor driver */
  73. - [RTL_GIGA_MAC_VER_63] = {"RTL8125B", FIRMWARE_8125B_2},
  74. - [RTL_GIGA_MAC_VER_64] = {"RTL8125D", FIRMWARE_8125D_1},
  75. - [RTL_GIGA_MAC_VER_65] = {"RTL8125D", FIRMWARE_8125D_2},
  76. - [RTL_GIGA_MAC_VER_66] = {"RTL8125BP", FIRMWARE_8125BP_2},
  77. - [RTL_GIGA_MAC_VER_70] = {"RTL8126A", FIRMWARE_8126A_2},
  78. - [RTL_GIGA_MAC_VER_71] = {"RTL8126A", FIRMWARE_8126A_3},
  79. + /* 8126A family. */
  80. + { 0x7cf, 0x64a, RTL_GIGA_MAC_VER_71, "RTL8126A", FIRMWARE_8126A_3 },
  81. + { 0x7cf, 0x649, RTL_GIGA_MAC_VER_70, "RTL8126A", FIRMWARE_8126A_2 },
  82. +
  83. + /* 8125BP family. */
  84. + { 0x7cf, 0x681, RTL_GIGA_MAC_VER_66, "RTL8125BP", FIRMWARE_8125BP_2 },
  85. +
  86. + /* 8125D family. */
  87. + { 0x7cf, 0x689, RTL_GIGA_MAC_VER_65, "RTL8125D", FIRMWARE_8125D_2 },
  88. + { 0x7cf, 0x688, RTL_GIGA_MAC_VER_64, "RTL8125D", FIRMWARE_8125D_1 },
  89. +
  90. + /* 8125B family. */
  91. + { 0x7cf, 0x641, RTL_GIGA_MAC_VER_63, "RTL8125B", FIRMWARE_8125B_2 },
  92. +
  93. + /* 8125A family. */
  94. + { 0x7cf, 0x609, RTL_GIGA_MAC_VER_61, "RTL8125A", FIRMWARE_8125A_3 },
  95. +
  96. + /* RTL8117 */
  97. + { 0x7cf, 0x54b, RTL_GIGA_MAC_VER_53, "RTL8168fp/RTL8117" },
  98. + { 0x7cf, 0x54a, RTL_GIGA_MAC_VER_52, "RTL8168fp/RTL8117",
  99. + FIRMWARE_8168FP_3 },
  100. +
  101. + /* 8168EP family. */
  102. + { 0x7cf, 0x502, RTL_GIGA_MAC_VER_51, "RTL8168ep/8111ep" },
  103. +
  104. + /* 8168H family. */
  105. + { 0x7cf, 0x541, RTL_GIGA_MAC_VER_46, "RTL8168h/8111h",
  106. + FIRMWARE_8168H_2 },
  107. + /* Realtek calls it RTL8168M, but it's handled like RTL8168H */
  108. + { 0x7cf, 0x6c0, RTL_GIGA_MAC_VER_46, "RTL8168M", FIRMWARE_8168H_2 },
  109. +
  110. + /* 8168G family. */
  111. + { 0x7cf, 0x5c8, RTL_GIGA_MAC_VER_44, "RTL8411b", FIRMWARE_8411_2 },
  112. + { 0x7cf, 0x509, RTL_GIGA_MAC_VER_42, "RTL8168gu/8111gu",
  113. + FIRMWARE_8168G_3 },
  114. + { 0x7cf, 0x4c0, RTL_GIGA_MAC_VER_40, "RTL8168g/8111g",
  115. + FIRMWARE_8168G_2 },
  116. +
  117. + /* 8168F family. */
  118. + { 0x7c8, 0x488, RTL_GIGA_MAC_VER_38, "RTL8411", FIRMWARE_8411_1 },
  119. + { 0x7cf, 0x481, RTL_GIGA_MAC_VER_36, "RTL8168f/8111f",
  120. + FIRMWARE_8168F_2 },
  121. + { 0x7cf, 0x480, RTL_GIGA_MAC_VER_35, "RTL8168f/8111f",
  122. + FIRMWARE_8168F_1 },
  123. +
  124. + /* 8168E family. */
  125. + { 0x7c8, 0x2c8, RTL_GIGA_MAC_VER_34, "RTL8168evl/8111evl",
  126. + FIRMWARE_8168E_3 },
  127. + { 0x7cf, 0x2c1, RTL_GIGA_MAC_VER_32, "RTL8168e/8111e",
  128. + FIRMWARE_8168E_1 },
  129. + { 0x7c8, 0x2c0, RTL_GIGA_MAC_VER_33, "RTL8168e/8111e",
  130. + FIRMWARE_8168E_2 },
  131. +
  132. + /* 8168D family. */
  133. + { 0x7cf, 0x281, RTL_GIGA_MAC_VER_25, "RTL8168d/8111d",
  134. + FIRMWARE_8168D_1 },
  135. + { 0x7c8, 0x280, RTL_GIGA_MAC_VER_26, "RTL8168d/8111d",
  136. + FIRMWARE_8168D_2 },
  137. +
  138. + /* 8168DP family. */
  139. + { 0x7cf, 0x28a, RTL_GIGA_MAC_VER_28, "RTL8168dp/8111dp" },
  140. + { 0x7cf, 0x28b, RTL_GIGA_MAC_VER_31, "RTL8168dp/8111dp" },
  141. +
  142. + /* 8168C family. */
  143. + { 0x7cf, 0x3c9, RTL_GIGA_MAC_VER_23, "RTL8168cp/8111cp" },
  144. + { 0x7cf, 0x3c8, RTL_GIGA_MAC_VER_18, "RTL8168cp/8111cp" },
  145. + { 0x7c8, 0x3c8, RTL_GIGA_MAC_VER_24, "RTL8168cp/8111cp" },
  146. + { 0x7cf, 0x3c0, RTL_GIGA_MAC_VER_19, "RTL8168c/8111c" },
  147. + { 0x7cf, 0x3c2, RTL_GIGA_MAC_VER_20, "RTL8168c/8111c" },
  148. + { 0x7cf, 0x3c3, RTL_GIGA_MAC_VER_21, "RTL8168c/8111c" },
  149. + { 0x7c8, 0x3c0, RTL_GIGA_MAC_VER_22, "RTL8168c/8111c" },
  150. +
  151. + /* 8168B family. */
  152. + { 0x7c8, 0x380, RTL_GIGA_MAC_VER_17, "RTL8168b/8111b" },
  153. + /* This one is very old and rare, support has been removed.
  154. + * { 0x7c8, 0x300, RTL_GIGA_MAC_VER_11, "RTL8168b/8111b" },
  155. + */
  156. +
  157. + /* 8101 family. */
  158. + { 0x7c8, 0x448, RTL_GIGA_MAC_VER_39, "RTL8106e", FIRMWARE_8106E_1 },
  159. + { 0x7c8, 0x440, RTL_GIGA_MAC_VER_37, "RTL8402", FIRMWARE_8402_1 },
  160. + { 0x7cf, 0x409, RTL_GIGA_MAC_VER_29, "RTL8105e", FIRMWARE_8105E_1 },
  161. + { 0x7c8, 0x408, RTL_GIGA_MAC_VER_30, "RTL8105e", FIRMWARE_8105E_1 },
  162. + { 0x7cf, 0x349, RTL_GIGA_MAC_VER_08, "RTL8102e" },
  163. + { 0x7cf, 0x249, RTL_GIGA_MAC_VER_08, "RTL8102e" },
  164. + { 0x7cf, 0x348, RTL_GIGA_MAC_VER_07, "RTL8102e" },
  165. + { 0x7cf, 0x248, RTL_GIGA_MAC_VER_07, "RTL8102e" },
  166. + { 0x7cf, 0x240, RTL_GIGA_MAC_VER_14, "RTL8401" },
  167. + { 0x7c8, 0x348, RTL_GIGA_MAC_VER_09, "RTL8102e/RTL8103e" },
  168. + { 0x7c8, 0x248, RTL_GIGA_MAC_VER_09, "RTL8102e/RTL8103e" },
  169. + { 0x7c8, 0x340, RTL_GIGA_MAC_VER_10, "RTL8101e/RTL8100e" },
  170. +
  171. + /* 8110 family. */
  172. + { 0xfc8, 0x980, RTL_GIGA_MAC_VER_06, "RTL8169sc/8110sc" },
  173. + { 0xfc8, 0x180, RTL_GIGA_MAC_VER_05, "RTL8169sc/8110sc" },
  174. + { 0xfc8, 0x100, RTL_GIGA_MAC_VER_04, "RTL8169sb/8110sb" },
  175. + { 0xfc8, 0x040, RTL_GIGA_MAC_VER_03, "RTL8110s" },
  176. + { 0xfc8, 0x008, RTL_GIGA_MAC_VER_02, "RTL8169s" },
  177. +
  178. + /* Catch-all */
  179. + { 0x000, 0x000, RTL_GIGA_MAC_NONE }
  180. };
  181. static const struct pci_device_id rtl8169_pci_tbl[] = {
  182. @@ -2265,151 +2318,30 @@ static const struct ethtool_ops rtl8169_
  183. .get_eth_ctrl_stats = rtl8169_get_eth_ctrl_stats,
  184. };
  185. -static enum mac_version rtl8169_get_mac_version(u16 xid, bool gmii)
  186. +static const struct rtl_chip_info *rtl8169_get_chip_version(u16 xid, bool gmii)
  187. {
  188. - /*
  189. - * The driver currently handles the 8168Bf and the 8168Be identically
  190. - * but they can be identified more specifically through the test below
  191. - * if needed:
  192. - *
  193. - * (RTL_R32(tp, TxConfig) & 0x700000) == 0x500000 ? 8168Bf : 8168Be
  194. - *
  195. - * Same thing for the 8101Eb and the 8101Ec:
  196. - *
  197. - * (RTL_R32(tp, TxConfig) & 0x700000) == 0x200000 ? 8101Eb : 8101Ec
  198. - */
  199. - static const struct rtl_mac_info {
  200. - u16 mask;
  201. - u16 val;
  202. - enum mac_version ver;
  203. - } mac_info[] = {
  204. - /* 8126A family. */
  205. - { 0x7cf, 0x64a, RTL_GIGA_MAC_VER_71 },
  206. - { 0x7cf, 0x649, RTL_GIGA_MAC_VER_70 },
  207. -
  208. - /* 8125BP family. */
  209. - { 0x7cf, 0x681, RTL_GIGA_MAC_VER_66 },
  210. -
  211. - /* 8125D family. */
  212. - { 0x7cf, 0x689, RTL_GIGA_MAC_VER_65 },
  213. - { 0x7cf, 0x688, RTL_GIGA_MAC_VER_64 },
  214. -
  215. - /* 8125B family. */
  216. - { 0x7cf, 0x641, RTL_GIGA_MAC_VER_63 },
  217. -
  218. - /* 8125A family. */
  219. - { 0x7cf, 0x609, RTL_GIGA_MAC_VER_61 },
  220. - /* It seems only XID 609 made it to the mass market.
  221. - * { 0x7cf, 0x608, RTL_GIGA_MAC_VER_60 },
  222. - * { 0x7c8, 0x608, RTL_GIGA_MAC_VER_61 },
  223. - */
  224. -
  225. - /* RTL8117 */
  226. - { 0x7cf, 0x54b, RTL_GIGA_MAC_VER_53 },
  227. - { 0x7cf, 0x54a, RTL_GIGA_MAC_VER_52 },
  228. -
  229. - /* 8168EP family. */
  230. - { 0x7cf, 0x502, RTL_GIGA_MAC_VER_51 },
  231. - /* It seems this chip version never made it to
  232. - * the wild. Let's disable detection.
  233. - * { 0x7cf, 0x501, RTL_GIGA_MAC_VER_50 },
  234. - * { 0x7cf, 0x500, RTL_GIGA_MAC_VER_49 },
  235. - */
  236. -
  237. - /* 8168H family. */
  238. - { 0x7cf, 0x541, RTL_GIGA_MAC_VER_46 },
  239. - /* It seems this chip version never made it to
  240. - * the wild. Let's disable detection.
  241. - * { 0x7cf, 0x540, RTL_GIGA_MAC_VER_45 },
  242. - */
  243. - /* Realtek calls it RTL8168M, but it's handled like RTL8168H */
  244. - { 0x7cf, 0x6c0, RTL_GIGA_MAC_VER_46 },
  245. -
  246. - /* 8168G family. */
  247. - { 0x7cf, 0x5c8, RTL_GIGA_MAC_VER_44 },
  248. - { 0x7cf, 0x509, RTL_GIGA_MAC_VER_42 },
  249. - /* It seems this chip version never made it to
  250. - * the wild. Let's disable detection.
  251. - * { 0x7cf, 0x4c1, RTL_GIGA_MAC_VER_41 },
  252. - */
  253. - { 0x7cf, 0x4c0, RTL_GIGA_MAC_VER_40 },
  254. -
  255. - /* 8168F family. */
  256. - { 0x7c8, 0x488, RTL_GIGA_MAC_VER_38 },
  257. - { 0x7cf, 0x481, RTL_GIGA_MAC_VER_36 },
  258. - { 0x7cf, 0x480, RTL_GIGA_MAC_VER_35 },
  259. -
  260. - /* 8168E family. */
  261. - { 0x7c8, 0x2c8, RTL_GIGA_MAC_VER_34 },
  262. - { 0x7cf, 0x2c1, RTL_GIGA_MAC_VER_32 },
  263. - { 0x7c8, 0x2c0, RTL_GIGA_MAC_VER_33 },
  264. -
  265. - /* 8168D family. */
  266. - { 0x7cf, 0x281, RTL_GIGA_MAC_VER_25 },
  267. - { 0x7c8, 0x280, RTL_GIGA_MAC_VER_26 },
  268. -
  269. - /* 8168DP family. */
  270. - /* It seems this early RTL8168dp version never made it to
  271. - * the wild. Support has been removed.
  272. - * { 0x7cf, 0x288, RTL_GIGA_MAC_VER_27 },
  273. - */
  274. - { 0x7cf, 0x28a, RTL_GIGA_MAC_VER_28 },
  275. - { 0x7cf, 0x28b, RTL_GIGA_MAC_VER_31 },
  276. -
  277. - /* 8168C family. */
  278. - { 0x7cf, 0x3c9, RTL_GIGA_MAC_VER_23 },
  279. - { 0x7cf, 0x3c8, RTL_GIGA_MAC_VER_18 },
  280. - { 0x7c8, 0x3c8, RTL_GIGA_MAC_VER_24 },
  281. - { 0x7cf, 0x3c0, RTL_GIGA_MAC_VER_19 },
  282. - { 0x7cf, 0x3c2, RTL_GIGA_MAC_VER_20 },
  283. - { 0x7cf, 0x3c3, RTL_GIGA_MAC_VER_21 },
  284. - { 0x7c8, 0x3c0, RTL_GIGA_MAC_VER_22 },
  285. -
  286. - /* 8168B family. */
  287. - { 0x7c8, 0x380, RTL_GIGA_MAC_VER_17 },
  288. - /* This one is very old and rare, support has been removed.
  289. - * { 0x7c8, 0x300, RTL_GIGA_MAC_VER_11 },
  290. - */
  291. -
  292. - /* 8101 family. */
  293. - { 0x7c8, 0x448, RTL_GIGA_MAC_VER_39 },
  294. - { 0x7c8, 0x440, RTL_GIGA_MAC_VER_37 },
  295. - { 0x7cf, 0x409, RTL_GIGA_MAC_VER_29 },
  296. - { 0x7c8, 0x408, RTL_GIGA_MAC_VER_30 },
  297. - { 0x7cf, 0x349, RTL_GIGA_MAC_VER_08 },
  298. - { 0x7cf, 0x249, RTL_GIGA_MAC_VER_08 },
  299. - { 0x7cf, 0x348, RTL_GIGA_MAC_VER_07 },
  300. - { 0x7cf, 0x248, RTL_GIGA_MAC_VER_07 },
  301. - { 0x7cf, 0x240, RTL_GIGA_MAC_VER_14 },
  302. - { 0x7c8, 0x348, RTL_GIGA_MAC_VER_09 },
  303. - { 0x7c8, 0x248, RTL_GIGA_MAC_VER_09 },
  304. - { 0x7c8, 0x340, RTL_GIGA_MAC_VER_10 },
  305. -
  306. - /* 8110 family. */
  307. - { 0xfc8, 0x980, RTL_GIGA_MAC_VER_06 },
  308. - { 0xfc8, 0x180, RTL_GIGA_MAC_VER_05 },
  309. - { 0xfc8, 0x100, RTL_GIGA_MAC_VER_04 },
  310. - { 0xfc8, 0x040, RTL_GIGA_MAC_VER_03 },
  311. - { 0xfc8, 0x008, RTL_GIGA_MAC_VER_02 },
  312. -
  313. - /* Catch-all */
  314. - { 0x000, 0x000, RTL_GIGA_MAC_NONE }
  315. + /* Chips combining a 1Gbps MAC with a 100Mbps PHY */
  316. + static const struct rtl_chip_info rtl8106eus_info = {
  317. + .mac_version = RTL_GIGA_MAC_VER_43,
  318. + .name = "RTL8106eus",
  319. + .fw_name = FIRMWARE_8106E_2,
  320. };
  321. - const struct rtl_mac_info *p = mac_info;
  322. - enum mac_version ver;
  323. + static const struct rtl_chip_info rtl8107e_info = {
  324. + .mac_version = RTL_GIGA_MAC_VER_48,
  325. + .name = "RTL8107e",
  326. + .fw_name = FIRMWARE_8107E_2,
  327. + };
  328. + const struct rtl_chip_info *p = rtl_chip_infos;
  329. while ((xid & p->mask) != p->val)
  330. p++;
  331. - ver = p->ver;
  332. - if (ver != RTL_GIGA_MAC_NONE && !gmii) {
  333. - if (ver == RTL_GIGA_MAC_VER_42)
  334. - ver = RTL_GIGA_MAC_VER_43;
  335. - else if (ver == RTL_GIGA_MAC_VER_46)
  336. - ver = RTL_GIGA_MAC_VER_48;
  337. - }
  338. + if (p->mac_version == RTL_GIGA_MAC_VER_42 && !gmii)
  339. + return &rtl8106eus_info;
  340. + if (p->mac_version == RTL_GIGA_MAC_VER_46 && !gmii)
  341. + return &rtl8107e_info;
  342. - return ver;
  343. + return p;
  344. }
  345. static void rtl_release_firmware(struct rtl8169_private *tp)
  346. @@ -5440,9 +5372,9 @@ static bool rtl_aspm_is_safe(struct rtl8
  347. static int rtl_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
  348. {
  349. + const struct rtl_chip_info *chip;
  350. struct rtl8169_private *tp;
  351. int jumbo_max, region, rc;
  352. - enum mac_version chipset;
  353. struct net_device *dev;
  354. u32 txconfig;
  355. u16 xid;
  356. @@ -5492,12 +5424,13 @@ static int rtl_init_one(struct pci_dev *
  357. xid = (txconfig >> 20) & 0xfcf;
  358. /* Identify chip attached to board */
  359. - chipset = rtl8169_get_mac_version(xid, tp->supports_gmii);
  360. - if (chipset == RTL_GIGA_MAC_NONE)
  361. + chip = rtl8169_get_chip_version(xid, tp->supports_gmii);
  362. + if (chip->mac_version == RTL_GIGA_MAC_NONE)
  363. return dev_err_probe(&pdev->dev, -ENODEV,
  364. "unknown chip XID %03x, contact r8169 maintainers (see MAINTAINERS file)\n",
  365. xid);
  366. - tp->mac_version = chipset;
  367. + tp->mac_version = chip->mac_version;
  368. + tp->fw_name = chip->fw_name;
  369. /* Disable ASPM L1 as that cause random device stop working
  370. * problems as well as full system hangs for some PCIe devices users.
  371. @@ -5602,8 +5535,6 @@ static int rtl_init_one(struct pci_dev *
  372. rtl_set_irq_mask(tp);
  373. - tp->fw_name = rtl_chip_infos[chipset].fw_name;
  374. -
  375. tp->counters = dmam_alloc_coherent (&pdev->dev, sizeof(*tp->counters),
  376. &tp->counters_phys_addr,
  377. GFP_KERNEL);
  378. @@ -5628,7 +5559,7 @@ static int rtl_init_one(struct pci_dev *
  379. }
  380. netdev_info(dev, "%s, %pM, XID %03x, IRQ %d\n",
  381. - rtl_chip_infos[chipset].name, dev->dev_addr, xid, tp->irq);
  382. + chip->name, dev->dev_addr, xid, tp->irq);
  383. if (jumbo_max)
  384. netdev_info(dev, "jumbo features [frames: %d bytes, tx checksumming: %s]\n",