ethtool.c 47 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970
  1. /*
  2. * net/core/ethtool.c - Ethtool ioctl handler
  3. * Copyright (c) 2003 Matthew Wilcox <matthew@wil.cx>
  4. *
  5. * This file is where we call all the ethtool_ops commands to get
  6. * the information ethtool needs.
  7. *
  8. * This program is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation; either version 2 of the License, or
  11. * (at your option) any later version.
  12. */
  13. #include <linux/module.h>
  14. #include <linux/types.h>
  15. #include <linux/capability.h>
  16. #include <linux/errno.h>
  17. #include <linux/ethtool.h>
  18. #include <linux/netdevice.h>
  19. #include <linux/net_tstamp.h>
  20. #include <linux/phy.h>
  21. #include <linux/bitops.h>
  22. #include <linux/uaccess.h>
  23. #include <linux/vmalloc.h>
  24. #include <linux/slab.h>
  25. #include <linux/rtnetlink.h>
  26. #include <linux/sched.h>
  27. #include <linux/net.h>
  28. /*
  29. * Some useful ethtool_ops methods that're device independent.
  30. * If we find that all drivers want to do the same thing here,
  31. * we can turn these into dev_() function calls.
  32. */
  33. u32 ethtool_op_get_link(struct net_device *dev)
  34. {
  35. return netif_carrier_ok(dev) ? 1 : 0;
  36. }
  37. EXPORT_SYMBOL(ethtool_op_get_link);
  38. int ethtool_op_get_ts_info(struct net_device *dev, struct ethtool_ts_info *info)
  39. {
  40. info->so_timestamping =
  41. SOF_TIMESTAMPING_TX_SOFTWARE |
  42. SOF_TIMESTAMPING_RX_SOFTWARE |
  43. SOF_TIMESTAMPING_SOFTWARE;
  44. info->phc_index = -1;
  45. return 0;
  46. }
  47. EXPORT_SYMBOL(ethtool_op_get_ts_info);
  48. /* Handlers for each ethtool command */
  49. #define ETHTOOL_DEV_FEATURE_WORDS ((NETDEV_FEATURE_COUNT + 31) / 32)
  50. static const char netdev_features_strings[NETDEV_FEATURE_COUNT][ETH_GSTRING_LEN] = {
  51. [NETIF_F_SG_BIT] = "tx-scatter-gather",
  52. [NETIF_F_IP_CSUM_BIT] = "tx-checksum-ipv4",
  53. [NETIF_F_HW_CSUM_BIT] = "tx-checksum-ip-generic",
  54. [NETIF_F_IPV6_CSUM_BIT] = "tx-checksum-ipv6",
  55. [NETIF_F_HIGHDMA_BIT] = "highdma",
  56. [NETIF_F_FRAGLIST_BIT] = "tx-scatter-gather-fraglist",
  57. [NETIF_F_HW_VLAN_CTAG_TX_BIT] = "tx-vlan-hw-insert",
  58. [NETIF_F_HW_VLAN_CTAG_RX_BIT] = "rx-vlan-hw-parse",
  59. [NETIF_F_HW_VLAN_CTAG_FILTER_BIT] = "rx-vlan-filter",
  60. [NETIF_F_HW_VLAN_STAG_TX_BIT] = "tx-vlan-stag-hw-insert",
  61. [NETIF_F_HW_VLAN_STAG_RX_BIT] = "rx-vlan-stag-hw-parse",
  62. [NETIF_F_HW_VLAN_STAG_FILTER_BIT] = "rx-vlan-stag-filter",
  63. [NETIF_F_VLAN_CHALLENGED_BIT] = "vlan-challenged",
  64. [NETIF_F_GSO_BIT] = "tx-generic-segmentation",
  65. [NETIF_F_LLTX_BIT] = "tx-lockless",
  66. [NETIF_F_NETNS_LOCAL_BIT] = "netns-local",
  67. [NETIF_F_GRO_BIT] = "rx-gro",
  68. [NETIF_F_LRO_BIT] = "rx-lro",
  69. [NETIF_F_TSO_BIT] = "tx-tcp-segmentation",
  70. [NETIF_F_UFO_BIT] = "tx-udp-fragmentation",
  71. [NETIF_F_GSO_ROBUST_BIT] = "tx-gso-robust",
  72. [NETIF_F_TSO_ECN_BIT] = "tx-tcp-ecn-segmentation",
  73. [NETIF_F_TSO6_BIT] = "tx-tcp6-segmentation",
  74. [NETIF_F_FSO_BIT] = "tx-fcoe-segmentation",
  75. [NETIF_F_GSO_GRE_BIT] = "tx-gre-segmentation",
  76. [NETIF_F_GSO_IPIP_BIT] = "tx-ipip-segmentation",
  77. [NETIF_F_GSO_SIT_BIT] = "tx-sit-segmentation",
  78. [NETIF_F_GSO_UDP_TUNNEL_BIT] = "tx-udp_tnl-segmentation",
  79. [NETIF_F_FCOE_CRC_BIT] = "tx-checksum-fcoe-crc",
  80. [NETIF_F_SCTP_CSUM_BIT] = "tx-checksum-sctp",
  81. [NETIF_F_FCOE_MTU_BIT] = "fcoe-mtu",
  82. [NETIF_F_NTUPLE_BIT] = "rx-ntuple-filter",
  83. [NETIF_F_RXHASH_BIT] = "rx-hashing",
  84. [NETIF_F_RXCSUM_BIT] = "rx-checksum",
  85. [NETIF_F_NOCACHE_COPY_BIT] = "tx-nocache-copy",
  86. [NETIF_F_LOOPBACK_BIT] = "loopback",
  87. [NETIF_F_RXFCS_BIT] = "rx-fcs",
  88. [NETIF_F_RXALL_BIT] = "rx-all",
  89. [NETIF_F_HW_L2FW_DOFFLOAD_BIT] = "l2-fwd-offload",
  90. [NETIF_F_BUSY_POLL_BIT] = "busy-poll",
  91. };
  92. static const char
  93. rss_hash_func_strings[ETH_RSS_HASH_FUNCS_COUNT][ETH_GSTRING_LEN] = {
  94. [ETH_RSS_HASH_TOP_BIT] = "toeplitz",
  95. [ETH_RSS_HASH_XOR_BIT] = "xor",
  96. };
  97. static int ethtool_get_features(struct net_device *dev, void __user *useraddr)
  98. {
  99. struct ethtool_gfeatures cmd = {
  100. .cmd = ETHTOOL_GFEATURES,
  101. .size = ETHTOOL_DEV_FEATURE_WORDS,
  102. };
  103. struct ethtool_get_features_block features[ETHTOOL_DEV_FEATURE_WORDS];
  104. u32 __user *sizeaddr;
  105. u32 copy_size;
  106. int i;
  107. /* in case feature bits run out again */
  108. BUILD_BUG_ON(ETHTOOL_DEV_FEATURE_WORDS * sizeof(u32) > sizeof(netdev_features_t));
  109. for (i = 0; i < ETHTOOL_DEV_FEATURE_WORDS; ++i) {
  110. features[i].available = (u32)(dev->hw_features >> (32 * i));
  111. features[i].requested = (u32)(dev->wanted_features >> (32 * i));
  112. features[i].active = (u32)(dev->features >> (32 * i));
  113. features[i].never_changed =
  114. (u32)(NETIF_F_NEVER_CHANGE >> (32 * i));
  115. }
  116. sizeaddr = useraddr + offsetof(struct ethtool_gfeatures, size);
  117. if (get_user(copy_size, sizeaddr))
  118. return -EFAULT;
  119. if (copy_size > ETHTOOL_DEV_FEATURE_WORDS)
  120. copy_size = ETHTOOL_DEV_FEATURE_WORDS;
  121. if (copy_to_user(useraddr, &cmd, sizeof(cmd)))
  122. return -EFAULT;
  123. useraddr += sizeof(cmd);
  124. if (copy_to_user(useraddr, features, copy_size * sizeof(*features)))
  125. return -EFAULT;
  126. return 0;
  127. }
  128. static int ethtool_set_features(struct net_device *dev, void __user *useraddr)
  129. {
  130. struct ethtool_sfeatures cmd;
  131. struct ethtool_set_features_block features[ETHTOOL_DEV_FEATURE_WORDS];
  132. netdev_features_t wanted = 0, valid = 0;
  133. int i, ret = 0;
  134. if (copy_from_user(&cmd, useraddr, sizeof(cmd)))
  135. return -EFAULT;
  136. useraddr += sizeof(cmd);
  137. if (cmd.size != ETHTOOL_DEV_FEATURE_WORDS)
  138. return -EINVAL;
  139. if (copy_from_user(features, useraddr, sizeof(features)))
  140. return -EFAULT;
  141. for (i = 0; i < ETHTOOL_DEV_FEATURE_WORDS; ++i) {
  142. valid |= (netdev_features_t)features[i].valid << (32 * i);
  143. wanted |= (netdev_features_t)features[i].requested << (32 * i);
  144. }
  145. if (valid & ~NETIF_F_ETHTOOL_BITS)
  146. return -EINVAL;
  147. if (valid & ~dev->hw_features) {
  148. valid &= dev->hw_features;
  149. ret |= ETHTOOL_F_UNSUPPORTED;
  150. }
  151. dev->wanted_features &= ~valid;
  152. dev->wanted_features |= wanted & valid;
  153. __netdev_update_features(dev);
  154. if ((dev->wanted_features ^ dev->features) & valid)
  155. ret |= ETHTOOL_F_WISH;
  156. return ret;
  157. }
  158. static int __ethtool_get_sset_count(struct net_device *dev, int sset)
  159. {
  160. const struct ethtool_ops *ops = dev->ethtool_ops;
  161. if (sset == ETH_SS_FEATURES)
  162. return ARRAY_SIZE(netdev_features_strings);
  163. if (sset == ETH_SS_RSS_HASH_FUNCS)
  164. return ARRAY_SIZE(rss_hash_func_strings);
  165. if (ops->get_sset_count && ops->get_strings)
  166. return ops->get_sset_count(dev, sset);
  167. else
  168. return -EOPNOTSUPP;
  169. }
  170. static void __ethtool_get_strings(struct net_device *dev,
  171. u32 stringset, u8 *data)
  172. {
  173. const struct ethtool_ops *ops = dev->ethtool_ops;
  174. if (stringset == ETH_SS_FEATURES)
  175. memcpy(data, netdev_features_strings,
  176. sizeof(netdev_features_strings));
  177. else if (stringset == ETH_SS_RSS_HASH_FUNCS)
  178. memcpy(data, rss_hash_func_strings,
  179. sizeof(rss_hash_func_strings));
  180. else
  181. /* ops->get_strings is valid because checked earlier */
  182. ops->get_strings(dev, stringset, data);
  183. }
  184. static netdev_features_t ethtool_get_feature_mask(u32 eth_cmd)
  185. {
  186. /* feature masks of legacy discrete ethtool ops */
  187. switch (eth_cmd) {
  188. case ETHTOOL_GTXCSUM:
  189. case ETHTOOL_STXCSUM:
  190. return NETIF_F_ALL_CSUM | NETIF_F_SCTP_CSUM;
  191. case ETHTOOL_GRXCSUM:
  192. case ETHTOOL_SRXCSUM:
  193. return NETIF_F_RXCSUM;
  194. case ETHTOOL_GSG:
  195. case ETHTOOL_SSG:
  196. return NETIF_F_SG;
  197. case ETHTOOL_GTSO:
  198. case ETHTOOL_STSO:
  199. return NETIF_F_ALL_TSO;
  200. case ETHTOOL_GUFO:
  201. case ETHTOOL_SUFO:
  202. return NETIF_F_UFO;
  203. case ETHTOOL_GGSO:
  204. case ETHTOOL_SGSO:
  205. return NETIF_F_GSO;
  206. case ETHTOOL_GGRO:
  207. case ETHTOOL_SGRO:
  208. return NETIF_F_GRO;
  209. default:
  210. BUG();
  211. }
  212. }
  213. static int ethtool_get_one_feature(struct net_device *dev,
  214. char __user *useraddr, u32 ethcmd)
  215. {
  216. netdev_features_t mask = ethtool_get_feature_mask(ethcmd);
  217. struct ethtool_value edata = {
  218. .cmd = ethcmd,
  219. .data = !!(dev->features & mask),
  220. };
  221. if (copy_to_user(useraddr, &edata, sizeof(edata)))
  222. return -EFAULT;
  223. return 0;
  224. }
  225. static int ethtool_set_one_feature(struct net_device *dev,
  226. void __user *useraddr, u32 ethcmd)
  227. {
  228. struct ethtool_value edata;
  229. netdev_features_t mask;
  230. if (copy_from_user(&edata, useraddr, sizeof(edata)))
  231. return -EFAULT;
  232. mask = ethtool_get_feature_mask(ethcmd);
  233. mask &= dev->hw_features;
  234. if (!mask)
  235. return -EOPNOTSUPP;
  236. if (edata.data)
  237. dev->wanted_features |= mask;
  238. else
  239. dev->wanted_features &= ~mask;
  240. __netdev_update_features(dev);
  241. return 0;
  242. }
  243. #define ETH_ALL_FLAGS (ETH_FLAG_LRO | ETH_FLAG_RXVLAN | ETH_FLAG_TXVLAN | \
  244. ETH_FLAG_NTUPLE | ETH_FLAG_RXHASH)
  245. #define ETH_ALL_FEATURES (NETIF_F_LRO | NETIF_F_HW_VLAN_CTAG_RX | \
  246. NETIF_F_HW_VLAN_CTAG_TX | NETIF_F_NTUPLE | \
  247. NETIF_F_RXHASH)
  248. static u32 __ethtool_get_flags(struct net_device *dev)
  249. {
  250. u32 flags = 0;
  251. if (dev->features & NETIF_F_LRO)
  252. flags |= ETH_FLAG_LRO;
  253. if (dev->features & NETIF_F_HW_VLAN_CTAG_RX)
  254. flags |= ETH_FLAG_RXVLAN;
  255. if (dev->features & NETIF_F_HW_VLAN_CTAG_TX)
  256. flags |= ETH_FLAG_TXVLAN;
  257. if (dev->features & NETIF_F_NTUPLE)
  258. flags |= ETH_FLAG_NTUPLE;
  259. if (dev->features & NETIF_F_RXHASH)
  260. flags |= ETH_FLAG_RXHASH;
  261. return flags;
  262. }
  263. static int __ethtool_set_flags(struct net_device *dev, u32 data)
  264. {
  265. netdev_features_t features = 0, changed;
  266. if (data & ~ETH_ALL_FLAGS)
  267. return -EINVAL;
  268. if (data & ETH_FLAG_LRO)
  269. features |= NETIF_F_LRO;
  270. if (data & ETH_FLAG_RXVLAN)
  271. features |= NETIF_F_HW_VLAN_CTAG_RX;
  272. if (data & ETH_FLAG_TXVLAN)
  273. features |= NETIF_F_HW_VLAN_CTAG_TX;
  274. if (data & ETH_FLAG_NTUPLE)
  275. features |= NETIF_F_NTUPLE;
  276. if (data & ETH_FLAG_RXHASH)
  277. features |= NETIF_F_RXHASH;
  278. /* allow changing only bits set in hw_features */
  279. changed = (features ^ dev->features) & ETH_ALL_FEATURES;
  280. if (changed & ~dev->hw_features)
  281. return (changed & dev->hw_features) ? -EINVAL : -EOPNOTSUPP;
  282. dev->wanted_features =
  283. (dev->wanted_features & ~changed) | (features & changed);
  284. __netdev_update_features(dev);
  285. return 0;
  286. }
  287. int __ethtool_get_settings(struct net_device *dev, struct ethtool_cmd *cmd)
  288. {
  289. ASSERT_RTNL();
  290. if (!dev->ethtool_ops->get_settings)
  291. return -EOPNOTSUPP;
  292. memset(cmd, 0, sizeof(struct ethtool_cmd));
  293. cmd->cmd = ETHTOOL_GSET;
  294. return dev->ethtool_ops->get_settings(dev, cmd);
  295. }
  296. EXPORT_SYMBOL(__ethtool_get_settings);
  297. static int ethtool_get_settings(struct net_device *dev, void __user *useraddr)
  298. {
  299. int err;
  300. struct ethtool_cmd cmd;
  301. err = __ethtool_get_settings(dev, &cmd);
  302. if (err < 0)
  303. return err;
  304. if (copy_to_user(useraddr, &cmd, sizeof(cmd)))
  305. return -EFAULT;
  306. return 0;
  307. }
  308. static int ethtool_set_settings(struct net_device *dev, void __user *useraddr)
  309. {
  310. struct ethtool_cmd cmd;
  311. if (!dev->ethtool_ops->set_settings)
  312. return -EOPNOTSUPP;
  313. if (copy_from_user(&cmd, useraddr, sizeof(cmd)))
  314. return -EFAULT;
  315. return dev->ethtool_ops->set_settings(dev, &cmd);
  316. }
  317. static noinline_for_stack int ethtool_get_drvinfo(struct net_device *dev,
  318. void __user *useraddr)
  319. {
  320. struct ethtool_drvinfo info;
  321. const struct ethtool_ops *ops = dev->ethtool_ops;
  322. memset(&info, 0, sizeof(info));
  323. info.cmd = ETHTOOL_GDRVINFO;
  324. if (ops->get_drvinfo) {
  325. ops->get_drvinfo(dev, &info);
  326. } else if (dev->dev.parent && dev->dev.parent->driver) {
  327. strlcpy(info.bus_info, dev_name(dev->dev.parent),
  328. sizeof(info.bus_info));
  329. strlcpy(info.driver, dev->dev.parent->driver->name,
  330. sizeof(info.driver));
  331. } else {
  332. return -EOPNOTSUPP;
  333. }
  334. /*
  335. * this method of obtaining string set info is deprecated;
  336. * Use ETHTOOL_GSSET_INFO instead.
  337. */
  338. if (ops->get_sset_count) {
  339. int rc;
  340. rc = ops->get_sset_count(dev, ETH_SS_TEST);
  341. if (rc >= 0)
  342. info.testinfo_len = rc;
  343. rc = ops->get_sset_count(dev, ETH_SS_STATS);
  344. if (rc >= 0)
  345. info.n_stats = rc;
  346. rc = ops->get_sset_count(dev, ETH_SS_PRIV_FLAGS);
  347. if (rc >= 0)
  348. info.n_priv_flags = rc;
  349. }
  350. if (ops->get_regs_len)
  351. info.regdump_len = ops->get_regs_len(dev);
  352. if (ops->get_eeprom_len)
  353. info.eedump_len = ops->get_eeprom_len(dev);
  354. if (copy_to_user(useraddr, &info, sizeof(info)))
  355. return -EFAULT;
  356. return 0;
  357. }
  358. static noinline_for_stack int ethtool_get_sset_info(struct net_device *dev,
  359. void __user *useraddr)
  360. {
  361. struct ethtool_sset_info info;
  362. u64 sset_mask;
  363. int i, idx = 0, n_bits = 0, ret, rc;
  364. u32 *info_buf = NULL;
  365. if (copy_from_user(&info, useraddr, sizeof(info)))
  366. return -EFAULT;
  367. /* store copy of mask, because we zero struct later on */
  368. sset_mask = info.sset_mask;
  369. if (!sset_mask)
  370. return 0;
  371. /* calculate size of return buffer */
  372. n_bits = hweight64(sset_mask);
  373. memset(&info, 0, sizeof(info));
  374. info.cmd = ETHTOOL_GSSET_INFO;
  375. info_buf = kzalloc(n_bits * sizeof(u32), GFP_USER);
  376. if (!info_buf)
  377. return -ENOMEM;
  378. /*
  379. * fill return buffer based on input bitmask and successful
  380. * get_sset_count return
  381. */
  382. for (i = 0; i < 64; i++) {
  383. if (!(sset_mask & (1ULL << i)))
  384. continue;
  385. rc = __ethtool_get_sset_count(dev, i);
  386. if (rc >= 0) {
  387. info.sset_mask |= (1ULL << i);
  388. info_buf[idx++] = rc;
  389. }
  390. }
  391. ret = -EFAULT;
  392. if (copy_to_user(useraddr, &info, sizeof(info)))
  393. goto out;
  394. useraddr += offsetof(struct ethtool_sset_info, data);
  395. if (copy_to_user(useraddr, info_buf, idx * sizeof(u32)))
  396. goto out;
  397. ret = 0;
  398. out:
  399. kfree(info_buf);
  400. return ret;
  401. }
  402. static noinline_for_stack int ethtool_set_rxnfc(struct net_device *dev,
  403. u32 cmd, void __user *useraddr)
  404. {
  405. struct ethtool_rxnfc info;
  406. size_t info_size = sizeof(info);
  407. int rc;
  408. if (!dev->ethtool_ops->set_rxnfc)
  409. return -EOPNOTSUPP;
  410. /* struct ethtool_rxnfc was originally defined for
  411. * ETHTOOL_{G,S}RXFH with only the cmd, flow_type and data
  412. * members. User-space might still be using that
  413. * definition. */
  414. if (cmd == ETHTOOL_SRXFH)
  415. info_size = (offsetof(struct ethtool_rxnfc, data) +
  416. sizeof(info.data));
  417. if (copy_from_user(&info, useraddr, info_size))
  418. return -EFAULT;
  419. rc = dev->ethtool_ops->set_rxnfc(dev, &info);
  420. if (rc)
  421. return rc;
  422. if (cmd == ETHTOOL_SRXCLSRLINS &&
  423. copy_to_user(useraddr, &info, info_size))
  424. return -EFAULT;
  425. return 0;
  426. }
  427. static noinline_for_stack int ethtool_get_rxnfc(struct net_device *dev,
  428. u32 cmd, void __user *useraddr)
  429. {
  430. struct ethtool_rxnfc info;
  431. size_t info_size = sizeof(info);
  432. const struct ethtool_ops *ops = dev->ethtool_ops;
  433. int ret;
  434. void *rule_buf = NULL;
  435. if (!ops->get_rxnfc)
  436. return -EOPNOTSUPP;
  437. /* struct ethtool_rxnfc was originally defined for
  438. * ETHTOOL_{G,S}RXFH with only the cmd, flow_type and data
  439. * members. User-space might still be using that
  440. * definition. */
  441. if (cmd == ETHTOOL_GRXFH)
  442. info_size = (offsetof(struct ethtool_rxnfc, data) +
  443. sizeof(info.data));
  444. if (copy_from_user(&info, useraddr, info_size))
  445. return -EFAULT;
  446. if (info.cmd == ETHTOOL_GRXCLSRLALL) {
  447. if (info.rule_cnt > 0) {
  448. if (info.rule_cnt <= KMALLOC_MAX_SIZE / sizeof(u32))
  449. rule_buf = kzalloc(info.rule_cnt * sizeof(u32),
  450. GFP_USER);
  451. if (!rule_buf)
  452. return -ENOMEM;
  453. }
  454. }
  455. ret = ops->get_rxnfc(dev, &info, rule_buf);
  456. if (ret < 0)
  457. goto err_out;
  458. ret = -EFAULT;
  459. if (copy_to_user(useraddr, &info, info_size))
  460. goto err_out;
  461. if (rule_buf) {
  462. useraddr += offsetof(struct ethtool_rxnfc, rule_locs);
  463. if (copy_to_user(useraddr, rule_buf,
  464. info.rule_cnt * sizeof(u32)))
  465. goto err_out;
  466. }
  467. ret = 0;
  468. err_out:
  469. kfree(rule_buf);
  470. return ret;
  471. }
  472. static int ethtool_copy_validate_indir(u32 *indir, void __user *useraddr,
  473. struct ethtool_rxnfc *rx_rings,
  474. u32 size)
  475. {
  476. int i;
  477. if (copy_from_user(indir, useraddr, size * sizeof(indir[0])))
  478. return -EFAULT;
  479. /* Validate ring indices */
  480. for (i = 0; i < size; i++)
  481. if (indir[i] >= rx_rings->data)
  482. return -EINVAL;
  483. return 0;
  484. }
  485. u8 netdev_rss_key[NETDEV_RSS_KEY_LEN];
  486. void netdev_rss_key_fill(void *buffer, size_t len)
  487. {
  488. BUG_ON(len > sizeof(netdev_rss_key));
  489. net_get_random_once(netdev_rss_key, sizeof(netdev_rss_key));
  490. memcpy(buffer, netdev_rss_key, len);
  491. }
  492. EXPORT_SYMBOL(netdev_rss_key_fill);
  493. static noinline_for_stack int ethtool_get_rxfh_indir(struct net_device *dev,
  494. void __user *useraddr)
  495. {
  496. u32 user_size, dev_size;
  497. u32 *indir;
  498. int ret;
  499. if (!dev->ethtool_ops->get_rxfh_indir_size ||
  500. !dev->ethtool_ops->get_rxfh)
  501. return -EOPNOTSUPP;
  502. dev_size = dev->ethtool_ops->get_rxfh_indir_size(dev);
  503. if (dev_size == 0)
  504. return -EOPNOTSUPP;
  505. if (copy_from_user(&user_size,
  506. useraddr + offsetof(struct ethtool_rxfh_indir, size),
  507. sizeof(user_size)))
  508. return -EFAULT;
  509. if (copy_to_user(useraddr + offsetof(struct ethtool_rxfh_indir, size),
  510. &dev_size, sizeof(dev_size)))
  511. return -EFAULT;
  512. /* If the user buffer size is 0, this is just a query for the
  513. * device table size. Otherwise, if it's smaller than the
  514. * device table size it's an error.
  515. */
  516. if (user_size < dev_size)
  517. return user_size == 0 ? 0 : -EINVAL;
  518. indir = kcalloc(dev_size, sizeof(indir[0]), GFP_USER);
  519. if (!indir)
  520. return -ENOMEM;
  521. ret = dev->ethtool_ops->get_rxfh(dev, indir, NULL, NULL);
  522. if (ret)
  523. goto out;
  524. if (copy_to_user(useraddr +
  525. offsetof(struct ethtool_rxfh_indir, ring_index[0]),
  526. indir, dev_size * sizeof(indir[0])))
  527. ret = -EFAULT;
  528. out:
  529. kfree(indir);
  530. return ret;
  531. }
  532. static noinline_for_stack int ethtool_set_rxfh_indir(struct net_device *dev,
  533. void __user *useraddr)
  534. {
  535. struct ethtool_rxnfc rx_rings;
  536. u32 user_size, dev_size, i;
  537. u32 *indir;
  538. const struct ethtool_ops *ops = dev->ethtool_ops;
  539. int ret;
  540. u32 ringidx_offset = offsetof(struct ethtool_rxfh_indir, ring_index[0]);
  541. if (!ops->get_rxfh_indir_size || !ops->set_rxfh ||
  542. !ops->get_rxnfc)
  543. return -EOPNOTSUPP;
  544. dev_size = ops->get_rxfh_indir_size(dev);
  545. if (dev_size == 0)
  546. return -EOPNOTSUPP;
  547. if (copy_from_user(&user_size,
  548. useraddr + offsetof(struct ethtool_rxfh_indir, size),
  549. sizeof(user_size)))
  550. return -EFAULT;
  551. if (user_size != 0 && user_size != dev_size)
  552. return -EINVAL;
  553. indir = kcalloc(dev_size, sizeof(indir[0]), GFP_USER);
  554. if (!indir)
  555. return -ENOMEM;
  556. rx_rings.cmd = ETHTOOL_GRXRINGS;
  557. ret = ops->get_rxnfc(dev, &rx_rings, NULL);
  558. if (ret)
  559. goto out;
  560. if (user_size == 0) {
  561. for (i = 0; i < dev_size; i++)
  562. indir[i] = ethtool_rxfh_indir_default(i, rx_rings.data);
  563. } else {
  564. ret = ethtool_copy_validate_indir(indir,
  565. useraddr + ringidx_offset,
  566. &rx_rings,
  567. dev_size);
  568. if (ret)
  569. goto out;
  570. }
  571. ret = ops->set_rxfh(dev, indir, NULL, ETH_RSS_HASH_NO_CHANGE);
  572. out:
  573. kfree(indir);
  574. return ret;
  575. }
  576. static noinline_for_stack int ethtool_get_rxfh(struct net_device *dev,
  577. void __user *useraddr)
  578. {
  579. int ret;
  580. const struct ethtool_ops *ops = dev->ethtool_ops;
  581. u32 user_indir_size, user_key_size;
  582. u32 dev_indir_size = 0, dev_key_size = 0;
  583. struct ethtool_rxfh rxfh;
  584. u32 total_size;
  585. u32 indir_bytes;
  586. u32 *indir = NULL;
  587. u8 dev_hfunc = 0;
  588. u8 *hkey = NULL;
  589. u8 *rss_config;
  590. if (!ops->get_rxfh)
  591. return -EOPNOTSUPP;
  592. if (ops->get_rxfh_indir_size)
  593. dev_indir_size = ops->get_rxfh_indir_size(dev);
  594. if (ops->get_rxfh_key_size)
  595. dev_key_size = ops->get_rxfh_key_size(dev);
  596. if (copy_from_user(&rxfh, useraddr, sizeof(rxfh)))
  597. return -EFAULT;
  598. user_indir_size = rxfh.indir_size;
  599. user_key_size = rxfh.key_size;
  600. /* Check that reserved fields are 0 for now */
  601. if (rxfh.rss_context || rxfh.rsvd8[0] || rxfh.rsvd8[1] ||
  602. rxfh.rsvd8[2] || rxfh.rsvd32)
  603. return -EINVAL;
  604. rxfh.indir_size = dev_indir_size;
  605. rxfh.key_size = dev_key_size;
  606. if (copy_to_user(useraddr, &rxfh, sizeof(rxfh)))
  607. return -EFAULT;
  608. if ((user_indir_size && (user_indir_size != dev_indir_size)) ||
  609. (user_key_size && (user_key_size != dev_key_size)))
  610. return -EINVAL;
  611. indir_bytes = user_indir_size * sizeof(indir[0]);
  612. total_size = indir_bytes + user_key_size;
  613. rss_config = kzalloc(total_size, GFP_USER);
  614. if (!rss_config)
  615. return -ENOMEM;
  616. if (user_indir_size)
  617. indir = (u32 *)rss_config;
  618. if (user_key_size)
  619. hkey = rss_config + indir_bytes;
  620. ret = dev->ethtool_ops->get_rxfh(dev, indir, hkey, &dev_hfunc);
  621. if (ret)
  622. goto out;
  623. if (copy_to_user(useraddr + offsetof(struct ethtool_rxfh, hfunc),
  624. &dev_hfunc, sizeof(rxfh.hfunc))) {
  625. ret = -EFAULT;
  626. } else if (copy_to_user(useraddr +
  627. offsetof(struct ethtool_rxfh, rss_config[0]),
  628. rss_config, total_size)) {
  629. ret = -EFAULT;
  630. }
  631. out:
  632. kfree(rss_config);
  633. return ret;
  634. }
  635. static noinline_for_stack int ethtool_set_rxfh(struct net_device *dev,
  636. void __user *useraddr)
  637. {
  638. int ret;
  639. const struct ethtool_ops *ops = dev->ethtool_ops;
  640. struct ethtool_rxnfc rx_rings;
  641. struct ethtool_rxfh rxfh;
  642. u32 dev_indir_size = 0, dev_key_size = 0, i;
  643. u32 *indir = NULL, indir_bytes = 0;
  644. u8 *hkey = NULL;
  645. u8 *rss_config;
  646. u32 rss_cfg_offset = offsetof(struct ethtool_rxfh, rss_config[0]);
  647. if (!ops->get_rxnfc || !ops->set_rxfh)
  648. return -EOPNOTSUPP;
  649. if (ops->get_rxfh_indir_size)
  650. dev_indir_size = ops->get_rxfh_indir_size(dev);
  651. if (ops->get_rxfh_key_size)
  652. dev_key_size = dev->ethtool_ops->get_rxfh_key_size(dev);
  653. if (copy_from_user(&rxfh, useraddr, sizeof(rxfh)))
  654. return -EFAULT;
  655. /* Check that reserved fields are 0 for now */
  656. if (rxfh.rss_context || rxfh.rsvd8[0] || rxfh.rsvd8[1] ||
  657. rxfh.rsvd8[2] || rxfh.rsvd32)
  658. return -EINVAL;
  659. /* If either indir, hash key or function is valid, proceed further.
  660. * Must request at least one change: indir size, hash key or function.
  661. */
  662. if ((rxfh.indir_size &&
  663. rxfh.indir_size != ETH_RXFH_INDIR_NO_CHANGE &&
  664. rxfh.indir_size != dev_indir_size) ||
  665. (rxfh.key_size && (rxfh.key_size != dev_key_size)) ||
  666. (rxfh.indir_size == ETH_RXFH_INDIR_NO_CHANGE &&
  667. rxfh.key_size == 0 && rxfh.hfunc == ETH_RSS_HASH_NO_CHANGE))
  668. return -EINVAL;
  669. if (rxfh.indir_size != ETH_RXFH_INDIR_NO_CHANGE)
  670. indir_bytes = dev_indir_size * sizeof(indir[0]);
  671. rss_config = kzalloc(indir_bytes + rxfh.key_size, GFP_USER);
  672. if (!rss_config)
  673. return -ENOMEM;
  674. rx_rings.cmd = ETHTOOL_GRXRINGS;
  675. ret = ops->get_rxnfc(dev, &rx_rings, NULL);
  676. if (ret)
  677. goto out;
  678. /* rxfh.indir_size == 0 means reset the indir table to default.
  679. * rxfh.indir_size == ETH_RXFH_INDIR_NO_CHANGE means leave it unchanged.
  680. */
  681. if (rxfh.indir_size &&
  682. rxfh.indir_size != ETH_RXFH_INDIR_NO_CHANGE) {
  683. indir = (u32 *)rss_config;
  684. ret = ethtool_copy_validate_indir(indir,
  685. useraddr + rss_cfg_offset,
  686. &rx_rings,
  687. rxfh.indir_size);
  688. if (ret)
  689. goto out;
  690. } else if (rxfh.indir_size == 0) {
  691. indir = (u32 *)rss_config;
  692. for (i = 0; i < dev_indir_size; i++)
  693. indir[i] = ethtool_rxfh_indir_default(i, rx_rings.data);
  694. }
  695. if (rxfh.key_size) {
  696. hkey = rss_config + indir_bytes;
  697. if (copy_from_user(hkey,
  698. useraddr + rss_cfg_offset + indir_bytes,
  699. rxfh.key_size)) {
  700. ret = -EFAULT;
  701. goto out;
  702. }
  703. }
  704. ret = ops->set_rxfh(dev, indir, hkey, rxfh.hfunc);
  705. out:
  706. kfree(rss_config);
  707. return ret;
  708. }
  709. static int ethtool_get_regs(struct net_device *dev, char __user *useraddr)
  710. {
  711. struct ethtool_regs regs;
  712. const struct ethtool_ops *ops = dev->ethtool_ops;
  713. void *regbuf;
  714. int reglen, ret;
  715. if (!ops->get_regs || !ops->get_regs_len)
  716. return -EOPNOTSUPP;
  717. if (copy_from_user(&regs, useraddr, sizeof(regs)))
  718. return -EFAULT;
  719. reglen = ops->get_regs_len(dev);
  720. if (regs.len > reglen)
  721. regs.len = reglen;
  722. regbuf = vzalloc(reglen);
  723. if (reglen && !regbuf)
  724. return -ENOMEM;
  725. ops->get_regs(dev, &regs, regbuf);
  726. ret = -EFAULT;
  727. if (copy_to_user(useraddr, &regs, sizeof(regs)))
  728. goto out;
  729. useraddr += offsetof(struct ethtool_regs, data);
  730. if (regbuf && copy_to_user(useraddr, regbuf, regs.len))
  731. goto out;
  732. ret = 0;
  733. out:
  734. vfree(regbuf);
  735. return ret;
  736. }
  737. static int ethtool_reset(struct net_device *dev, char __user *useraddr)
  738. {
  739. struct ethtool_value reset;
  740. int ret;
  741. if (!dev->ethtool_ops->reset)
  742. return -EOPNOTSUPP;
  743. if (copy_from_user(&reset, useraddr, sizeof(reset)))
  744. return -EFAULT;
  745. ret = dev->ethtool_ops->reset(dev, &reset.data);
  746. if (ret)
  747. return ret;
  748. if (copy_to_user(useraddr, &reset, sizeof(reset)))
  749. return -EFAULT;
  750. return 0;
  751. }
  752. static int ethtool_get_wol(struct net_device *dev, char __user *useraddr)
  753. {
  754. struct ethtool_wolinfo wol = { .cmd = ETHTOOL_GWOL };
  755. if (!dev->ethtool_ops->get_wol)
  756. return -EOPNOTSUPP;
  757. dev->ethtool_ops->get_wol(dev, &wol);
  758. if (copy_to_user(useraddr, &wol, sizeof(wol)))
  759. return -EFAULT;
  760. return 0;
  761. }
  762. static int ethtool_set_wol(struct net_device *dev, char __user *useraddr)
  763. {
  764. struct ethtool_wolinfo wol;
  765. if (!dev->ethtool_ops->set_wol)
  766. return -EOPNOTSUPP;
  767. if (copy_from_user(&wol, useraddr, sizeof(wol)))
  768. return -EFAULT;
  769. return dev->ethtool_ops->set_wol(dev, &wol);
  770. }
  771. static int ethtool_get_eee(struct net_device *dev, char __user *useraddr)
  772. {
  773. struct ethtool_eee edata;
  774. int rc;
  775. if (!dev->ethtool_ops->get_eee)
  776. return -EOPNOTSUPP;
  777. memset(&edata, 0, sizeof(struct ethtool_eee));
  778. edata.cmd = ETHTOOL_GEEE;
  779. rc = dev->ethtool_ops->get_eee(dev, &edata);
  780. if (rc)
  781. return rc;
  782. if (copy_to_user(useraddr, &edata, sizeof(edata)))
  783. return -EFAULT;
  784. return 0;
  785. }
  786. static int ethtool_set_eee(struct net_device *dev, char __user *useraddr)
  787. {
  788. struct ethtool_eee edata;
  789. if (!dev->ethtool_ops->set_eee)
  790. return -EOPNOTSUPP;
  791. if (copy_from_user(&edata, useraddr, sizeof(edata)))
  792. return -EFAULT;
  793. return dev->ethtool_ops->set_eee(dev, &edata);
  794. }
  795. static int ethtool_nway_reset(struct net_device *dev)
  796. {
  797. if (!dev->ethtool_ops->nway_reset)
  798. return -EOPNOTSUPP;
  799. return dev->ethtool_ops->nway_reset(dev);
  800. }
  801. static int ethtool_get_link(struct net_device *dev, char __user *useraddr)
  802. {
  803. struct ethtool_value edata = { .cmd = ETHTOOL_GLINK };
  804. if (!dev->ethtool_ops->get_link)
  805. return -EOPNOTSUPP;
  806. edata.data = netif_running(dev) && dev->ethtool_ops->get_link(dev);
  807. if (copy_to_user(useraddr, &edata, sizeof(edata)))
  808. return -EFAULT;
  809. return 0;
  810. }
  811. static int ethtool_get_any_eeprom(struct net_device *dev, void __user *useraddr,
  812. int (*getter)(struct net_device *,
  813. struct ethtool_eeprom *, u8 *),
  814. u32 total_len)
  815. {
  816. struct ethtool_eeprom eeprom;
  817. void __user *userbuf = useraddr + sizeof(eeprom);
  818. u32 bytes_remaining;
  819. u8 *data;
  820. int ret = 0;
  821. if (copy_from_user(&eeprom, useraddr, sizeof(eeprom)))
  822. return -EFAULT;
  823. /* Check for wrap and zero */
  824. if (eeprom.offset + eeprom.len <= eeprom.offset)
  825. return -EINVAL;
  826. /* Check for exceeding total eeprom len */
  827. if (eeprom.offset + eeprom.len > total_len)
  828. return -EINVAL;
  829. data = kmalloc(PAGE_SIZE, GFP_USER);
  830. if (!data)
  831. return -ENOMEM;
  832. bytes_remaining = eeprom.len;
  833. while (bytes_remaining > 0) {
  834. eeprom.len = min(bytes_remaining, (u32)PAGE_SIZE);
  835. ret = getter(dev, &eeprom, data);
  836. if (ret)
  837. break;
  838. if (copy_to_user(userbuf, data, eeprom.len)) {
  839. ret = -EFAULT;
  840. break;
  841. }
  842. userbuf += eeprom.len;
  843. eeprom.offset += eeprom.len;
  844. bytes_remaining -= eeprom.len;
  845. }
  846. eeprom.len = userbuf - (useraddr + sizeof(eeprom));
  847. eeprom.offset -= eeprom.len;
  848. if (copy_to_user(useraddr, &eeprom, sizeof(eeprom)))
  849. ret = -EFAULT;
  850. kfree(data);
  851. return ret;
  852. }
  853. static int ethtool_get_eeprom(struct net_device *dev, void __user *useraddr)
  854. {
  855. const struct ethtool_ops *ops = dev->ethtool_ops;
  856. if (!ops->get_eeprom || !ops->get_eeprom_len ||
  857. !ops->get_eeprom_len(dev))
  858. return -EOPNOTSUPP;
  859. return ethtool_get_any_eeprom(dev, useraddr, ops->get_eeprom,
  860. ops->get_eeprom_len(dev));
  861. }
  862. static int ethtool_set_eeprom(struct net_device *dev, void __user *useraddr)
  863. {
  864. struct ethtool_eeprom eeprom;
  865. const struct ethtool_ops *ops = dev->ethtool_ops;
  866. void __user *userbuf = useraddr + sizeof(eeprom);
  867. u32 bytes_remaining;
  868. u8 *data;
  869. int ret = 0;
  870. if (!ops->set_eeprom || !ops->get_eeprom_len ||
  871. !ops->get_eeprom_len(dev))
  872. return -EOPNOTSUPP;
  873. if (copy_from_user(&eeprom, useraddr, sizeof(eeprom)))
  874. return -EFAULT;
  875. /* Check for wrap and zero */
  876. if (eeprom.offset + eeprom.len <= eeprom.offset)
  877. return -EINVAL;
  878. /* Check for exceeding total eeprom len */
  879. if (eeprom.offset + eeprom.len > ops->get_eeprom_len(dev))
  880. return -EINVAL;
  881. data = kmalloc(PAGE_SIZE, GFP_USER);
  882. if (!data)
  883. return -ENOMEM;
  884. bytes_remaining = eeprom.len;
  885. while (bytes_remaining > 0) {
  886. eeprom.len = min(bytes_remaining, (u32)PAGE_SIZE);
  887. if (copy_from_user(data, userbuf, eeprom.len)) {
  888. ret = -EFAULT;
  889. break;
  890. }
  891. ret = ops->set_eeprom(dev, &eeprom, data);
  892. if (ret)
  893. break;
  894. userbuf += eeprom.len;
  895. eeprom.offset += eeprom.len;
  896. bytes_remaining -= eeprom.len;
  897. }
  898. kfree(data);
  899. return ret;
  900. }
  901. static noinline_for_stack int ethtool_get_coalesce(struct net_device *dev,
  902. void __user *useraddr)
  903. {
  904. struct ethtool_coalesce coalesce = { .cmd = ETHTOOL_GCOALESCE };
  905. if (!dev->ethtool_ops->get_coalesce)
  906. return -EOPNOTSUPP;
  907. dev->ethtool_ops->get_coalesce(dev, &coalesce);
  908. if (copy_to_user(useraddr, &coalesce, sizeof(coalesce)))
  909. return -EFAULT;
  910. return 0;
  911. }
  912. static noinline_for_stack int ethtool_set_coalesce(struct net_device *dev,
  913. void __user *useraddr)
  914. {
  915. struct ethtool_coalesce coalesce;
  916. if (!dev->ethtool_ops->set_coalesce)
  917. return -EOPNOTSUPP;
  918. if (copy_from_user(&coalesce, useraddr, sizeof(coalesce)))
  919. return -EFAULT;
  920. return dev->ethtool_ops->set_coalesce(dev, &coalesce);
  921. }
  922. static int ethtool_get_ringparam(struct net_device *dev, void __user *useraddr)
  923. {
  924. struct ethtool_ringparam ringparam = { .cmd = ETHTOOL_GRINGPARAM };
  925. if (!dev->ethtool_ops->get_ringparam)
  926. return -EOPNOTSUPP;
  927. dev->ethtool_ops->get_ringparam(dev, &ringparam);
  928. if (copy_to_user(useraddr, &ringparam, sizeof(ringparam)))
  929. return -EFAULT;
  930. return 0;
  931. }
  932. static int ethtool_set_ringparam(struct net_device *dev, void __user *useraddr)
  933. {
  934. struct ethtool_ringparam ringparam;
  935. if (!dev->ethtool_ops->set_ringparam)
  936. return -EOPNOTSUPP;
  937. if (copy_from_user(&ringparam, useraddr, sizeof(ringparam)))
  938. return -EFAULT;
  939. return dev->ethtool_ops->set_ringparam(dev, &ringparam);
  940. }
  941. static noinline_for_stack int ethtool_get_channels(struct net_device *dev,
  942. void __user *useraddr)
  943. {
  944. struct ethtool_channels channels = { .cmd = ETHTOOL_GCHANNELS };
  945. if (!dev->ethtool_ops->get_channels)
  946. return -EOPNOTSUPP;
  947. dev->ethtool_ops->get_channels(dev, &channels);
  948. if (copy_to_user(useraddr, &channels, sizeof(channels)))
  949. return -EFAULT;
  950. return 0;
  951. }
  952. static noinline_for_stack int ethtool_set_channels(struct net_device *dev,
  953. void __user *useraddr)
  954. {
  955. struct ethtool_channels channels;
  956. if (!dev->ethtool_ops->set_channels)
  957. return -EOPNOTSUPP;
  958. if (copy_from_user(&channels, useraddr, sizeof(channels)))
  959. return -EFAULT;
  960. return dev->ethtool_ops->set_channels(dev, &channels);
  961. }
  962. static int ethtool_get_pauseparam(struct net_device *dev, void __user *useraddr)
  963. {
  964. struct ethtool_pauseparam pauseparam = { ETHTOOL_GPAUSEPARAM };
  965. if (!dev->ethtool_ops->get_pauseparam)
  966. return -EOPNOTSUPP;
  967. dev->ethtool_ops->get_pauseparam(dev, &pauseparam);
  968. if (copy_to_user(useraddr, &pauseparam, sizeof(pauseparam)))
  969. return -EFAULT;
  970. return 0;
  971. }
  972. static int ethtool_set_pauseparam(struct net_device *dev, void __user *useraddr)
  973. {
  974. struct ethtool_pauseparam pauseparam;
  975. if (!dev->ethtool_ops->set_pauseparam)
  976. return -EOPNOTSUPP;
  977. if (copy_from_user(&pauseparam, useraddr, sizeof(pauseparam)))
  978. return -EFAULT;
  979. return dev->ethtool_ops->set_pauseparam(dev, &pauseparam);
  980. }
  981. static int ethtool_self_test(struct net_device *dev, char __user *useraddr)
  982. {
  983. struct ethtool_test test;
  984. const struct ethtool_ops *ops = dev->ethtool_ops;
  985. u64 *data;
  986. int ret, test_len;
  987. if (!ops->self_test || !ops->get_sset_count)
  988. return -EOPNOTSUPP;
  989. test_len = ops->get_sset_count(dev, ETH_SS_TEST);
  990. if (test_len < 0)
  991. return test_len;
  992. WARN_ON(test_len == 0);
  993. if (copy_from_user(&test, useraddr, sizeof(test)))
  994. return -EFAULT;
  995. test.len = test_len;
  996. data = kmalloc(test_len * sizeof(u64), GFP_USER);
  997. if (!data)
  998. return -ENOMEM;
  999. ops->self_test(dev, &test, data);
  1000. ret = -EFAULT;
  1001. if (copy_to_user(useraddr, &test, sizeof(test)))
  1002. goto out;
  1003. useraddr += sizeof(test);
  1004. if (copy_to_user(useraddr, data, test.len * sizeof(u64)))
  1005. goto out;
  1006. ret = 0;
  1007. out:
  1008. kfree(data);
  1009. return ret;
  1010. }
  1011. static int ethtool_get_strings(struct net_device *dev, void __user *useraddr)
  1012. {
  1013. struct ethtool_gstrings gstrings;
  1014. u8 *data;
  1015. int ret;
  1016. if (copy_from_user(&gstrings, useraddr, sizeof(gstrings)))
  1017. return -EFAULT;
  1018. ret = __ethtool_get_sset_count(dev, gstrings.string_set);
  1019. if (ret < 0)
  1020. return ret;
  1021. gstrings.len = ret;
  1022. data = kmalloc(gstrings.len * ETH_GSTRING_LEN, GFP_USER);
  1023. if (!data)
  1024. return -ENOMEM;
  1025. __ethtool_get_strings(dev, gstrings.string_set, data);
  1026. ret = -EFAULT;
  1027. if (copy_to_user(useraddr, &gstrings, sizeof(gstrings)))
  1028. goto out;
  1029. useraddr += sizeof(gstrings);
  1030. if (copy_to_user(useraddr, data, gstrings.len * ETH_GSTRING_LEN))
  1031. goto out;
  1032. ret = 0;
  1033. out:
  1034. kfree(data);
  1035. return ret;
  1036. }
  1037. static int ethtool_phys_id(struct net_device *dev, void __user *useraddr)
  1038. {
  1039. struct ethtool_value id;
  1040. static bool busy;
  1041. const struct ethtool_ops *ops = dev->ethtool_ops;
  1042. int rc;
  1043. if (!ops->set_phys_id)
  1044. return -EOPNOTSUPP;
  1045. if (busy)
  1046. return -EBUSY;
  1047. if (copy_from_user(&id, useraddr, sizeof(id)))
  1048. return -EFAULT;
  1049. rc = ops->set_phys_id(dev, ETHTOOL_ID_ACTIVE);
  1050. if (rc < 0)
  1051. return rc;
  1052. /* Drop the RTNL lock while waiting, but prevent reentry or
  1053. * removal of the device.
  1054. */
  1055. busy = true;
  1056. dev_hold(dev);
  1057. rtnl_unlock();
  1058. if (rc == 0) {
  1059. /* Driver will handle this itself */
  1060. schedule_timeout_interruptible(
  1061. id.data ? (id.data * HZ) : MAX_SCHEDULE_TIMEOUT);
  1062. } else {
  1063. /* Driver expects to be called at twice the frequency in rc */
  1064. int n = rc * 2, i, interval = HZ / n;
  1065. /* Count down seconds */
  1066. do {
  1067. /* Count down iterations per second */
  1068. i = n;
  1069. do {
  1070. rtnl_lock();
  1071. rc = ops->set_phys_id(dev,
  1072. (i & 1) ? ETHTOOL_ID_OFF : ETHTOOL_ID_ON);
  1073. rtnl_unlock();
  1074. if (rc)
  1075. break;
  1076. schedule_timeout_interruptible(interval);
  1077. } while (!signal_pending(current) && --i != 0);
  1078. } while (!signal_pending(current) &&
  1079. (id.data == 0 || --id.data != 0));
  1080. }
  1081. rtnl_lock();
  1082. dev_put(dev);
  1083. busy = false;
  1084. (void) ops->set_phys_id(dev, ETHTOOL_ID_INACTIVE);
  1085. return rc;
  1086. }
  1087. static int ethtool_get_stats(struct net_device *dev, void __user *useraddr)
  1088. {
  1089. struct ethtool_stats stats;
  1090. const struct ethtool_ops *ops = dev->ethtool_ops;
  1091. u64 *data;
  1092. int ret, n_stats;
  1093. if (!ops->get_ethtool_stats || !ops->get_sset_count)
  1094. return -EOPNOTSUPP;
  1095. n_stats = ops->get_sset_count(dev, ETH_SS_STATS);
  1096. if (n_stats < 0)
  1097. return n_stats;
  1098. WARN_ON(n_stats == 0);
  1099. if (copy_from_user(&stats, useraddr, sizeof(stats)))
  1100. return -EFAULT;
  1101. stats.n_stats = n_stats;
  1102. data = kmalloc(n_stats * sizeof(u64), GFP_USER);
  1103. if (!data)
  1104. return -ENOMEM;
  1105. ops->get_ethtool_stats(dev, &stats, data);
  1106. ret = -EFAULT;
  1107. if (copy_to_user(useraddr, &stats, sizeof(stats)))
  1108. goto out;
  1109. useraddr += sizeof(stats);
  1110. if (copy_to_user(useraddr, data, stats.n_stats * sizeof(u64)))
  1111. goto out;
  1112. ret = 0;
  1113. out:
  1114. kfree(data);
  1115. return ret;
  1116. }
  1117. static int ethtool_get_perm_addr(struct net_device *dev, void __user *useraddr)
  1118. {
  1119. struct ethtool_perm_addr epaddr;
  1120. if (copy_from_user(&epaddr, useraddr, sizeof(epaddr)))
  1121. return -EFAULT;
  1122. if (epaddr.size < dev->addr_len)
  1123. return -ETOOSMALL;
  1124. epaddr.size = dev->addr_len;
  1125. if (copy_to_user(useraddr, &epaddr, sizeof(epaddr)))
  1126. return -EFAULT;
  1127. useraddr += sizeof(epaddr);
  1128. if (copy_to_user(useraddr, dev->perm_addr, epaddr.size))
  1129. return -EFAULT;
  1130. return 0;
  1131. }
  1132. static int ethtool_get_value(struct net_device *dev, char __user *useraddr,
  1133. u32 cmd, u32 (*actor)(struct net_device *))
  1134. {
  1135. struct ethtool_value edata = { .cmd = cmd };
  1136. if (!actor)
  1137. return -EOPNOTSUPP;
  1138. edata.data = actor(dev);
  1139. if (copy_to_user(useraddr, &edata, sizeof(edata)))
  1140. return -EFAULT;
  1141. return 0;
  1142. }
  1143. static int ethtool_set_value_void(struct net_device *dev, char __user *useraddr,
  1144. void (*actor)(struct net_device *, u32))
  1145. {
  1146. struct ethtool_value edata;
  1147. if (!actor)
  1148. return -EOPNOTSUPP;
  1149. if (copy_from_user(&edata, useraddr, sizeof(edata)))
  1150. return -EFAULT;
  1151. actor(dev, edata.data);
  1152. return 0;
  1153. }
  1154. static int ethtool_set_value(struct net_device *dev, char __user *useraddr,
  1155. int (*actor)(struct net_device *, u32))
  1156. {
  1157. struct ethtool_value edata;
  1158. if (!actor)
  1159. return -EOPNOTSUPP;
  1160. if (copy_from_user(&edata, useraddr, sizeof(edata)))
  1161. return -EFAULT;
  1162. return actor(dev, edata.data);
  1163. }
  1164. static noinline_for_stack int ethtool_flash_device(struct net_device *dev,
  1165. char __user *useraddr)
  1166. {
  1167. struct ethtool_flash efl;
  1168. if (copy_from_user(&efl, useraddr, sizeof(efl)))
  1169. return -EFAULT;
  1170. if (!dev->ethtool_ops->flash_device)
  1171. return -EOPNOTSUPP;
  1172. efl.data[ETHTOOL_FLASH_MAX_FILENAME - 1] = 0;
  1173. return dev->ethtool_ops->flash_device(dev, &efl);
  1174. }
  1175. static int ethtool_set_dump(struct net_device *dev,
  1176. void __user *useraddr)
  1177. {
  1178. struct ethtool_dump dump;
  1179. if (!dev->ethtool_ops->set_dump)
  1180. return -EOPNOTSUPP;
  1181. if (copy_from_user(&dump, useraddr, sizeof(dump)))
  1182. return -EFAULT;
  1183. return dev->ethtool_ops->set_dump(dev, &dump);
  1184. }
  1185. static int ethtool_get_dump_flag(struct net_device *dev,
  1186. void __user *useraddr)
  1187. {
  1188. int ret;
  1189. struct ethtool_dump dump;
  1190. const struct ethtool_ops *ops = dev->ethtool_ops;
  1191. if (!ops->get_dump_flag)
  1192. return -EOPNOTSUPP;
  1193. if (copy_from_user(&dump, useraddr, sizeof(dump)))
  1194. return -EFAULT;
  1195. ret = ops->get_dump_flag(dev, &dump);
  1196. if (ret)
  1197. return ret;
  1198. if (copy_to_user(useraddr, &dump, sizeof(dump)))
  1199. return -EFAULT;
  1200. return 0;
  1201. }
  1202. static int ethtool_get_dump_data(struct net_device *dev,
  1203. void __user *useraddr)
  1204. {
  1205. int ret;
  1206. __u32 len;
  1207. struct ethtool_dump dump, tmp;
  1208. const struct ethtool_ops *ops = dev->ethtool_ops;
  1209. void *data = NULL;
  1210. if (!ops->get_dump_data || !ops->get_dump_flag)
  1211. return -EOPNOTSUPP;
  1212. if (copy_from_user(&dump, useraddr, sizeof(dump)))
  1213. return -EFAULT;
  1214. memset(&tmp, 0, sizeof(tmp));
  1215. tmp.cmd = ETHTOOL_GET_DUMP_FLAG;
  1216. ret = ops->get_dump_flag(dev, &tmp);
  1217. if (ret)
  1218. return ret;
  1219. len = min(tmp.len, dump.len);
  1220. if (!len)
  1221. return -EFAULT;
  1222. /* Don't ever let the driver think there's more space available
  1223. * than it requested with .get_dump_flag().
  1224. */
  1225. dump.len = len;
  1226. /* Always allocate enough space to hold the whole thing so that the
  1227. * driver does not need to check the length and bother with partial
  1228. * dumping.
  1229. */
  1230. data = vzalloc(tmp.len);
  1231. if (!data)
  1232. return -ENOMEM;
  1233. ret = ops->get_dump_data(dev, &dump, data);
  1234. if (ret)
  1235. goto out;
  1236. /* There are two sane possibilities:
  1237. * 1. The driver's .get_dump_data() does not touch dump.len.
  1238. * 2. Or it may set dump.len to how much it really writes, which
  1239. * should be tmp.len (or len if it can do a partial dump).
  1240. * In any case respond to userspace with the actual length of data
  1241. * it's receiving.
  1242. */
  1243. WARN_ON(dump.len != len && dump.len != tmp.len);
  1244. dump.len = len;
  1245. if (copy_to_user(useraddr, &dump, sizeof(dump))) {
  1246. ret = -EFAULT;
  1247. goto out;
  1248. }
  1249. useraddr += offsetof(struct ethtool_dump, data);
  1250. if (copy_to_user(useraddr, data, len))
  1251. ret = -EFAULT;
  1252. out:
  1253. vfree(data);
  1254. return ret;
  1255. }
  1256. static int ethtool_get_ts_info(struct net_device *dev, void __user *useraddr)
  1257. {
  1258. int err = 0;
  1259. struct ethtool_ts_info info;
  1260. const struct ethtool_ops *ops = dev->ethtool_ops;
  1261. struct phy_device *phydev = dev->phydev;
  1262. memset(&info, 0, sizeof(info));
  1263. info.cmd = ETHTOOL_GET_TS_INFO;
  1264. if (phydev && phydev->drv && phydev->drv->ts_info) {
  1265. err = phydev->drv->ts_info(phydev, &info);
  1266. } else if (ops->get_ts_info) {
  1267. err = ops->get_ts_info(dev, &info);
  1268. } else {
  1269. info.so_timestamping =
  1270. SOF_TIMESTAMPING_RX_SOFTWARE |
  1271. SOF_TIMESTAMPING_SOFTWARE;
  1272. info.phc_index = -1;
  1273. }
  1274. if (err)
  1275. return err;
  1276. if (copy_to_user(useraddr, &info, sizeof(info)))
  1277. err = -EFAULT;
  1278. return err;
  1279. }
  1280. static int ethtool_get_module_info(struct net_device *dev,
  1281. void __user *useraddr)
  1282. {
  1283. int ret;
  1284. struct ethtool_modinfo modinfo;
  1285. const struct ethtool_ops *ops = dev->ethtool_ops;
  1286. if (!ops->get_module_info)
  1287. return -EOPNOTSUPP;
  1288. if (copy_from_user(&modinfo, useraddr, sizeof(modinfo)))
  1289. return -EFAULT;
  1290. ret = ops->get_module_info(dev, &modinfo);
  1291. if (ret)
  1292. return ret;
  1293. if (copy_to_user(useraddr, &modinfo, sizeof(modinfo)))
  1294. return -EFAULT;
  1295. return 0;
  1296. }
  1297. static int ethtool_get_module_eeprom(struct net_device *dev,
  1298. void __user *useraddr)
  1299. {
  1300. int ret;
  1301. struct ethtool_modinfo modinfo;
  1302. const struct ethtool_ops *ops = dev->ethtool_ops;
  1303. if (!ops->get_module_info || !ops->get_module_eeprom)
  1304. return -EOPNOTSUPP;
  1305. ret = ops->get_module_info(dev, &modinfo);
  1306. if (ret)
  1307. return ret;
  1308. return ethtool_get_any_eeprom(dev, useraddr, ops->get_module_eeprom,
  1309. modinfo.eeprom_len);
  1310. }
  1311. static int ethtool_tunable_valid(const struct ethtool_tunable *tuna)
  1312. {
  1313. switch (tuna->id) {
  1314. case ETHTOOL_RX_COPYBREAK:
  1315. case ETHTOOL_TX_COPYBREAK:
  1316. if (tuna->len != sizeof(u32) ||
  1317. tuna->type_id != ETHTOOL_TUNABLE_U32)
  1318. return -EINVAL;
  1319. break;
  1320. default:
  1321. return -EINVAL;
  1322. }
  1323. return 0;
  1324. }
  1325. static int ethtool_get_tunable(struct net_device *dev, void __user *useraddr)
  1326. {
  1327. int ret;
  1328. struct ethtool_tunable tuna;
  1329. const struct ethtool_ops *ops = dev->ethtool_ops;
  1330. void *data;
  1331. if (!ops->get_tunable)
  1332. return -EOPNOTSUPP;
  1333. if (copy_from_user(&tuna, useraddr, sizeof(tuna)))
  1334. return -EFAULT;
  1335. ret = ethtool_tunable_valid(&tuna);
  1336. if (ret)
  1337. return ret;
  1338. data = kmalloc(tuna.len, GFP_USER);
  1339. if (!data)
  1340. return -ENOMEM;
  1341. ret = ops->get_tunable(dev, &tuna, data);
  1342. if (ret)
  1343. goto out;
  1344. useraddr += sizeof(tuna);
  1345. ret = -EFAULT;
  1346. if (copy_to_user(useraddr, data, tuna.len))
  1347. goto out;
  1348. ret = 0;
  1349. out:
  1350. kfree(data);
  1351. return ret;
  1352. }
  1353. static int ethtool_set_tunable(struct net_device *dev, void __user *useraddr)
  1354. {
  1355. int ret;
  1356. struct ethtool_tunable tuna;
  1357. const struct ethtool_ops *ops = dev->ethtool_ops;
  1358. void *data;
  1359. if (!ops->set_tunable)
  1360. return -EOPNOTSUPP;
  1361. if (copy_from_user(&tuna, useraddr, sizeof(tuna)))
  1362. return -EFAULT;
  1363. ret = ethtool_tunable_valid(&tuna);
  1364. if (ret)
  1365. return ret;
  1366. data = kmalloc(tuna.len, GFP_USER);
  1367. if (!data)
  1368. return -ENOMEM;
  1369. useraddr += sizeof(tuna);
  1370. ret = -EFAULT;
  1371. if (copy_from_user(data, useraddr, tuna.len))
  1372. goto out;
  1373. ret = ops->set_tunable(dev, &tuna, data);
  1374. out:
  1375. kfree(data);
  1376. return ret;
  1377. }
  1378. /* The main entry point in this file. Called from net/core/dev_ioctl.c */
  1379. int dev_ethtool(struct net *net, struct ifreq *ifr)
  1380. {
  1381. struct net_device *dev = __dev_get_by_name(net, ifr->ifr_name);
  1382. void __user *useraddr = ifr->ifr_data;
  1383. u32 ethcmd;
  1384. int rc;
  1385. netdev_features_t old_features;
  1386. if (!dev || !netif_device_present(dev))
  1387. return -ENODEV;
  1388. if (copy_from_user(&ethcmd, useraddr, sizeof(ethcmd)))
  1389. return -EFAULT;
  1390. /* Allow some commands to be done by anyone */
  1391. switch (ethcmd) {
  1392. case ETHTOOL_GSET:
  1393. case ETHTOOL_GDRVINFO:
  1394. case ETHTOOL_GMSGLVL:
  1395. case ETHTOOL_GLINK:
  1396. case ETHTOOL_GCOALESCE:
  1397. case ETHTOOL_GRINGPARAM:
  1398. case ETHTOOL_GPAUSEPARAM:
  1399. case ETHTOOL_GRXCSUM:
  1400. case ETHTOOL_GTXCSUM:
  1401. case ETHTOOL_GSG:
  1402. case ETHTOOL_GSSET_INFO:
  1403. case ETHTOOL_GSTRINGS:
  1404. case ETHTOOL_GSTATS:
  1405. case ETHTOOL_GTSO:
  1406. case ETHTOOL_GPERMADDR:
  1407. case ETHTOOL_GUFO:
  1408. case ETHTOOL_GGSO:
  1409. case ETHTOOL_GGRO:
  1410. case ETHTOOL_GFLAGS:
  1411. case ETHTOOL_GPFLAGS:
  1412. case ETHTOOL_GRXFH:
  1413. case ETHTOOL_GRXRINGS:
  1414. case ETHTOOL_GRXCLSRLCNT:
  1415. case ETHTOOL_GRXCLSRULE:
  1416. case ETHTOOL_GRXCLSRLALL:
  1417. case ETHTOOL_GRXFHINDIR:
  1418. case ETHTOOL_GRSSH:
  1419. case ETHTOOL_GFEATURES:
  1420. case ETHTOOL_GCHANNELS:
  1421. case ETHTOOL_GET_TS_INFO:
  1422. case ETHTOOL_GEEE:
  1423. case ETHTOOL_GTUNABLE:
  1424. break;
  1425. default:
  1426. if (!ns_capable(net->user_ns, CAP_NET_ADMIN))
  1427. return -EPERM;
  1428. }
  1429. if (dev->ethtool_ops->begin) {
  1430. rc = dev->ethtool_ops->begin(dev);
  1431. if (rc < 0)
  1432. return rc;
  1433. }
  1434. old_features = dev->features;
  1435. switch (ethcmd) {
  1436. case ETHTOOL_GSET:
  1437. rc = ethtool_get_settings(dev, useraddr);
  1438. break;
  1439. case ETHTOOL_SSET:
  1440. rc = ethtool_set_settings(dev, useraddr);
  1441. break;
  1442. case ETHTOOL_GDRVINFO:
  1443. rc = ethtool_get_drvinfo(dev, useraddr);
  1444. break;
  1445. case ETHTOOL_GREGS:
  1446. rc = ethtool_get_regs(dev, useraddr);
  1447. break;
  1448. case ETHTOOL_GWOL:
  1449. rc = ethtool_get_wol(dev, useraddr);
  1450. break;
  1451. case ETHTOOL_SWOL:
  1452. rc = ethtool_set_wol(dev, useraddr);
  1453. break;
  1454. case ETHTOOL_GMSGLVL:
  1455. rc = ethtool_get_value(dev, useraddr, ethcmd,
  1456. dev->ethtool_ops->get_msglevel);
  1457. break;
  1458. case ETHTOOL_SMSGLVL:
  1459. rc = ethtool_set_value_void(dev, useraddr,
  1460. dev->ethtool_ops->set_msglevel);
  1461. break;
  1462. case ETHTOOL_GEEE:
  1463. rc = ethtool_get_eee(dev, useraddr);
  1464. break;
  1465. case ETHTOOL_SEEE:
  1466. rc = ethtool_set_eee(dev, useraddr);
  1467. break;
  1468. case ETHTOOL_NWAY_RST:
  1469. rc = ethtool_nway_reset(dev);
  1470. break;
  1471. case ETHTOOL_GLINK:
  1472. rc = ethtool_get_link(dev, useraddr);
  1473. break;
  1474. case ETHTOOL_GEEPROM:
  1475. rc = ethtool_get_eeprom(dev, useraddr);
  1476. break;
  1477. case ETHTOOL_SEEPROM:
  1478. rc = ethtool_set_eeprom(dev, useraddr);
  1479. break;
  1480. case ETHTOOL_GCOALESCE:
  1481. rc = ethtool_get_coalesce(dev, useraddr);
  1482. break;
  1483. case ETHTOOL_SCOALESCE:
  1484. rc = ethtool_set_coalesce(dev, useraddr);
  1485. break;
  1486. case ETHTOOL_GRINGPARAM:
  1487. rc = ethtool_get_ringparam(dev, useraddr);
  1488. break;
  1489. case ETHTOOL_SRINGPARAM:
  1490. rc = ethtool_set_ringparam(dev, useraddr);
  1491. break;
  1492. case ETHTOOL_GPAUSEPARAM:
  1493. rc = ethtool_get_pauseparam(dev, useraddr);
  1494. break;
  1495. case ETHTOOL_SPAUSEPARAM:
  1496. rc = ethtool_set_pauseparam(dev, useraddr);
  1497. break;
  1498. case ETHTOOL_TEST:
  1499. rc = ethtool_self_test(dev, useraddr);
  1500. break;
  1501. case ETHTOOL_GSTRINGS:
  1502. rc = ethtool_get_strings(dev, useraddr);
  1503. break;
  1504. case ETHTOOL_PHYS_ID:
  1505. rc = ethtool_phys_id(dev, useraddr);
  1506. break;
  1507. case ETHTOOL_GSTATS:
  1508. rc = ethtool_get_stats(dev, useraddr);
  1509. break;
  1510. case ETHTOOL_GPERMADDR:
  1511. rc = ethtool_get_perm_addr(dev, useraddr);
  1512. break;
  1513. case ETHTOOL_GFLAGS:
  1514. rc = ethtool_get_value(dev, useraddr, ethcmd,
  1515. __ethtool_get_flags);
  1516. break;
  1517. case ETHTOOL_SFLAGS:
  1518. rc = ethtool_set_value(dev, useraddr, __ethtool_set_flags);
  1519. break;
  1520. case ETHTOOL_GPFLAGS:
  1521. rc = ethtool_get_value(dev, useraddr, ethcmd,
  1522. dev->ethtool_ops->get_priv_flags);
  1523. break;
  1524. case ETHTOOL_SPFLAGS:
  1525. rc = ethtool_set_value(dev, useraddr,
  1526. dev->ethtool_ops->set_priv_flags);
  1527. break;
  1528. case ETHTOOL_GRXFH:
  1529. case ETHTOOL_GRXRINGS:
  1530. case ETHTOOL_GRXCLSRLCNT:
  1531. case ETHTOOL_GRXCLSRULE:
  1532. case ETHTOOL_GRXCLSRLALL:
  1533. rc = ethtool_get_rxnfc(dev, ethcmd, useraddr);
  1534. break;
  1535. case ETHTOOL_SRXFH:
  1536. case ETHTOOL_SRXCLSRLDEL:
  1537. case ETHTOOL_SRXCLSRLINS:
  1538. rc = ethtool_set_rxnfc(dev, ethcmd, useraddr);
  1539. break;
  1540. case ETHTOOL_FLASHDEV:
  1541. rc = ethtool_flash_device(dev, useraddr);
  1542. break;
  1543. case ETHTOOL_RESET:
  1544. rc = ethtool_reset(dev, useraddr);
  1545. break;
  1546. case ETHTOOL_GSSET_INFO:
  1547. rc = ethtool_get_sset_info(dev, useraddr);
  1548. break;
  1549. case ETHTOOL_GRXFHINDIR:
  1550. rc = ethtool_get_rxfh_indir(dev, useraddr);
  1551. break;
  1552. case ETHTOOL_SRXFHINDIR:
  1553. rc = ethtool_set_rxfh_indir(dev, useraddr);
  1554. break;
  1555. case ETHTOOL_GRSSH:
  1556. rc = ethtool_get_rxfh(dev, useraddr);
  1557. break;
  1558. case ETHTOOL_SRSSH:
  1559. rc = ethtool_set_rxfh(dev, useraddr);
  1560. break;
  1561. case ETHTOOL_GFEATURES:
  1562. rc = ethtool_get_features(dev, useraddr);
  1563. break;
  1564. case ETHTOOL_SFEATURES:
  1565. rc = ethtool_set_features(dev, useraddr);
  1566. break;
  1567. case ETHTOOL_GTXCSUM:
  1568. case ETHTOOL_GRXCSUM:
  1569. case ETHTOOL_GSG:
  1570. case ETHTOOL_GTSO:
  1571. case ETHTOOL_GUFO:
  1572. case ETHTOOL_GGSO:
  1573. case ETHTOOL_GGRO:
  1574. rc = ethtool_get_one_feature(dev, useraddr, ethcmd);
  1575. break;
  1576. case ETHTOOL_STXCSUM:
  1577. case ETHTOOL_SRXCSUM:
  1578. case ETHTOOL_SSG:
  1579. case ETHTOOL_STSO:
  1580. case ETHTOOL_SUFO:
  1581. case ETHTOOL_SGSO:
  1582. case ETHTOOL_SGRO:
  1583. rc = ethtool_set_one_feature(dev, useraddr, ethcmd);
  1584. break;
  1585. case ETHTOOL_GCHANNELS:
  1586. rc = ethtool_get_channels(dev, useraddr);
  1587. break;
  1588. case ETHTOOL_SCHANNELS:
  1589. rc = ethtool_set_channels(dev, useraddr);
  1590. break;
  1591. case ETHTOOL_SET_DUMP:
  1592. rc = ethtool_set_dump(dev, useraddr);
  1593. break;
  1594. case ETHTOOL_GET_DUMP_FLAG:
  1595. rc = ethtool_get_dump_flag(dev, useraddr);
  1596. break;
  1597. case ETHTOOL_GET_DUMP_DATA:
  1598. rc = ethtool_get_dump_data(dev, useraddr);
  1599. break;
  1600. case ETHTOOL_GET_TS_INFO:
  1601. rc = ethtool_get_ts_info(dev, useraddr);
  1602. break;
  1603. case ETHTOOL_GMODULEINFO:
  1604. rc = ethtool_get_module_info(dev, useraddr);
  1605. break;
  1606. case ETHTOOL_GMODULEEEPROM:
  1607. rc = ethtool_get_module_eeprom(dev, useraddr);
  1608. break;
  1609. case ETHTOOL_GTUNABLE:
  1610. rc = ethtool_get_tunable(dev, useraddr);
  1611. break;
  1612. case ETHTOOL_STUNABLE:
  1613. rc = ethtool_set_tunable(dev, useraddr);
  1614. break;
  1615. default:
  1616. rc = -EOPNOTSUPP;
  1617. }
  1618. if (dev->ethtool_ops->complete)
  1619. dev->ethtool_ops->complete(dev);
  1620. if (old_features != dev->features)
  1621. netdev_features_change(dev);
  1622. return rc;
  1623. }