ethtool.c 48 KB

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