ethtool.c 47 KB

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