ethtool.c 45 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871
  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. return -EOPNOTSUPP;
  845. return ethtool_get_any_eeprom(dev, useraddr, ops->get_eeprom,
  846. ops->get_eeprom_len(dev));
  847. }
  848. static int ethtool_set_eeprom(struct net_device *dev, void __user *useraddr)
  849. {
  850. struct ethtool_eeprom eeprom;
  851. const struct ethtool_ops *ops = dev->ethtool_ops;
  852. void __user *userbuf = useraddr + sizeof(eeprom);
  853. u32 bytes_remaining;
  854. u8 *data;
  855. int ret = 0;
  856. if (!ops->set_eeprom || !ops->get_eeprom_len)
  857. return -EOPNOTSUPP;
  858. if (copy_from_user(&eeprom, useraddr, sizeof(eeprom)))
  859. return -EFAULT;
  860. /* Check for wrap and zero */
  861. if (eeprom.offset + eeprom.len <= eeprom.offset)
  862. return -EINVAL;
  863. /* Check for exceeding total eeprom len */
  864. if (eeprom.offset + eeprom.len > ops->get_eeprom_len(dev))
  865. return -EINVAL;
  866. data = kmalloc(PAGE_SIZE, GFP_USER);
  867. if (!data)
  868. return -ENOMEM;
  869. bytes_remaining = eeprom.len;
  870. while (bytes_remaining > 0) {
  871. eeprom.len = min(bytes_remaining, (u32)PAGE_SIZE);
  872. if (copy_from_user(data, userbuf, eeprom.len)) {
  873. ret = -EFAULT;
  874. break;
  875. }
  876. ret = ops->set_eeprom(dev, &eeprom, data);
  877. if (ret)
  878. break;
  879. userbuf += eeprom.len;
  880. eeprom.offset += eeprom.len;
  881. bytes_remaining -= eeprom.len;
  882. }
  883. kfree(data);
  884. return ret;
  885. }
  886. static noinline_for_stack int ethtool_get_coalesce(struct net_device *dev,
  887. void __user *useraddr)
  888. {
  889. struct ethtool_coalesce coalesce = { .cmd = ETHTOOL_GCOALESCE };
  890. if (!dev->ethtool_ops->get_coalesce)
  891. return -EOPNOTSUPP;
  892. dev->ethtool_ops->get_coalesce(dev, &coalesce);
  893. if (copy_to_user(useraddr, &coalesce, sizeof(coalesce)))
  894. return -EFAULT;
  895. return 0;
  896. }
  897. static noinline_for_stack int ethtool_set_coalesce(struct net_device *dev,
  898. void __user *useraddr)
  899. {
  900. struct ethtool_coalesce coalesce;
  901. if (!dev->ethtool_ops->set_coalesce)
  902. return -EOPNOTSUPP;
  903. if (copy_from_user(&coalesce, useraddr, sizeof(coalesce)))
  904. return -EFAULT;
  905. return dev->ethtool_ops->set_coalesce(dev, &coalesce);
  906. }
  907. static int ethtool_get_ringparam(struct net_device *dev, void __user *useraddr)
  908. {
  909. struct ethtool_ringparam ringparam = { .cmd = ETHTOOL_GRINGPARAM };
  910. if (!dev->ethtool_ops->get_ringparam)
  911. return -EOPNOTSUPP;
  912. dev->ethtool_ops->get_ringparam(dev, &ringparam);
  913. if (copy_to_user(useraddr, &ringparam, sizeof(ringparam)))
  914. return -EFAULT;
  915. return 0;
  916. }
  917. static int ethtool_set_ringparam(struct net_device *dev, void __user *useraddr)
  918. {
  919. struct ethtool_ringparam ringparam;
  920. if (!dev->ethtool_ops->set_ringparam)
  921. return -EOPNOTSUPP;
  922. if (copy_from_user(&ringparam, useraddr, sizeof(ringparam)))
  923. return -EFAULT;
  924. return dev->ethtool_ops->set_ringparam(dev, &ringparam);
  925. }
  926. static noinline_for_stack int ethtool_get_channels(struct net_device *dev,
  927. void __user *useraddr)
  928. {
  929. struct ethtool_channels channels = { .cmd = ETHTOOL_GCHANNELS };
  930. if (!dev->ethtool_ops->get_channels)
  931. return -EOPNOTSUPP;
  932. dev->ethtool_ops->get_channels(dev, &channels);
  933. if (copy_to_user(useraddr, &channels, sizeof(channels)))
  934. return -EFAULT;
  935. return 0;
  936. }
  937. static noinline_for_stack int ethtool_set_channels(struct net_device *dev,
  938. void __user *useraddr)
  939. {
  940. struct ethtool_channels channels;
  941. if (!dev->ethtool_ops->set_channels)
  942. return -EOPNOTSUPP;
  943. if (copy_from_user(&channels, useraddr, sizeof(channels)))
  944. return -EFAULT;
  945. return dev->ethtool_ops->set_channels(dev, &channels);
  946. }
  947. static int ethtool_get_pauseparam(struct net_device *dev, void __user *useraddr)
  948. {
  949. struct ethtool_pauseparam pauseparam = { ETHTOOL_GPAUSEPARAM };
  950. if (!dev->ethtool_ops->get_pauseparam)
  951. return -EOPNOTSUPP;
  952. dev->ethtool_ops->get_pauseparam(dev, &pauseparam);
  953. if (copy_to_user(useraddr, &pauseparam, sizeof(pauseparam)))
  954. return -EFAULT;
  955. return 0;
  956. }
  957. static int ethtool_set_pauseparam(struct net_device *dev, void __user *useraddr)
  958. {
  959. struct ethtool_pauseparam pauseparam;
  960. if (!dev->ethtool_ops->set_pauseparam)
  961. return -EOPNOTSUPP;
  962. if (copy_from_user(&pauseparam, useraddr, sizeof(pauseparam)))
  963. return -EFAULT;
  964. return dev->ethtool_ops->set_pauseparam(dev, &pauseparam);
  965. }
  966. static int ethtool_self_test(struct net_device *dev, char __user *useraddr)
  967. {
  968. struct ethtool_test test;
  969. const struct ethtool_ops *ops = dev->ethtool_ops;
  970. u64 *data;
  971. int ret, test_len;
  972. if (!ops->self_test || !ops->get_sset_count)
  973. return -EOPNOTSUPP;
  974. test_len = ops->get_sset_count(dev, ETH_SS_TEST);
  975. if (test_len < 0)
  976. return test_len;
  977. WARN_ON(test_len == 0);
  978. if (copy_from_user(&test, useraddr, sizeof(test)))
  979. return -EFAULT;
  980. test.len = test_len;
  981. data = kmalloc(test_len * sizeof(u64), GFP_USER);
  982. if (!data)
  983. return -ENOMEM;
  984. ops->self_test(dev, &test, data);
  985. ret = -EFAULT;
  986. if (copy_to_user(useraddr, &test, sizeof(test)))
  987. goto out;
  988. useraddr += sizeof(test);
  989. if (copy_to_user(useraddr, data, test.len * sizeof(u64)))
  990. goto out;
  991. ret = 0;
  992. out:
  993. kfree(data);
  994. return ret;
  995. }
  996. static int ethtool_get_strings(struct net_device *dev, void __user *useraddr)
  997. {
  998. struct ethtool_gstrings gstrings;
  999. u8 *data;
  1000. int ret;
  1001. if (copy_from_user(&gstrings, useraddr, sizeof(gstrings)))
  1002. return -EFAULT;
  1003. ret = __ethtool_get_sset_count(dev, gstrings.string_set);
  1004. if (ret < 0)
  1005. return ret;
  1006. gstrings.len = ret;
  1007. data = kmalloc(gstrings.len * ETH_GSTRING_LEN, GFP_USER);
  1008. if (!data)
  1009. return -ENOMEM;
  1010. __ethtool_get_strings(dev, gstrings.string_set, data);
  1011. ret = -EFAULT;
  1012. if (copy_to_user(useraddr, &gstrings, sizeof(gstrings)))
  1013. goto out;
  1014. useraddr += sizeof(gstrings);
  1015. if (copy_to_user(useraddr, data, gstrings.len * ETH_GSTRING_LEN))
  1016. goto out;
  1017. ret = 0;
  1018. out:
  1019. kfree(data);
  1020. return ret;
  1021. }
  1022. static int ethtool_phys_id(struct net_device *dev, void __user *useraddr)
  1023. {
  1024. struct ethtool_value id;
  1025. static bool busy;
  1026. const struct ethtool_ops *ops = dev->ethtool_ops;
  1027. int rc;
  1028. if (!ops->set_phys_id)
  1029. return -EOPNOTSUPP;
  1030. if (busy)
  1031. return -EBUSY;
  1032. if (copy_from_user(&id, useraddr, sizeof(id)))
  1033. return -EFAULT;
  1034. rc = ops->set_phys_id(dev, ETHTOOL_ID_ACTIVE);
  1035. if (rc < 0)
  1036. return rc;
  1037. /* Drop the RTNL lock while waiting, but prevent reentry or
  1038. * removal of the device.
  1039. */
  1040. busy = true;
  1041. dev_hold(dev);
  1042. rtnl_unlock();
  1043. if (rc == 0) {
  1044. /* Driver will handle this itself */
  1045. schedule_timeout_interruptible(
  1046. id.data ? (id.data * HZ) : MAX_SCHEDULE_TIMEOUT);
  1047. } else {
  1048. /* Driver expects to be called at twice the frequency in rc */
  1049. int n = rc * 2, i, interval = HZ / n;
  1050. /* Count down seconds */
  1051. do {
  1052. /* Count down iterations per second */
  1053. i = n;
  1054. do {
  1055. rtnl_lock();
  1056. rc = ops->set_phys_id(dev,
  1057. (i & 1) ? ETHTOOL_ID_OFF : ETHTOOL_ID_ON);
  1058. rtnl_unlock();
  1059. if (rc)
  1060. break;
  1061. schedule_timeout_interruptible(interval);
  1062. } while (!signal_pending(current) && --i != 0);
  1063. } while (!signal_pending(current) &&
  1064. (id.data == 0 || --id.data != 0));
  1065. }
  1066. rtnl_lock();
  1067. dev_put(dev);
  1068. busy = false;
  1069. (void) ops->set_phys_id(dev, ETHTOOL_ID_INACTIVE);
  1070. return rc;
  1071. }
  1072. static int ethtool_get_stats(struct net_device *dev, void __user *useraddr)
  1073. {
  1074. struct ethtool_stats stats;
  1075. const struct ethtool_ops *ops = dev->ethtool_ops;
  1076. u64 *data;
  1077. int ret, n_stats;
  1078. if (!ops->get_ethtool_stats || !ops->get_sset_count)
  1079. return -EOPNOTSUPP;
  1080. n_stats = ops->get_sset_count(dev, ETH_SS_STATS);
  1081. if (n_stats < 0)
  1082. return n_stats;
  1083. WARN_ON(n_stats == 0);
  1084. if (copy_from_user(&stats, useraddr, sizeof(stats)))
  1085. return -EFAULT;
  1086. stats.n_stats = n_stats;
  1087. data = kmalloc(n_stats * sizeof(u64), GFP_USER);
  1088. if (!data)
  1089. return -ENOMEM;
  1090. ops->get_ethtool_stats(dev, &stats, data);
  1091. ret = -EFAULT;
  1092. if (copy_to_user(useraddr, &stats, sizeof(stats)))
  1093. goto out;
  1094. useraddr += sizeof(stats);
  1095. if (copy_to_user(useraddr, data, stats.n_stats * sizeof(u64)))
  1096. goto out;
  1097. ret = 0;
  1098. out:
  1099. kfree(data);
  1100. return ret;
  1101. }
  1102. static int ethtool_get_perm_addr(struct net_device *dev, void __user *useraddr)
  1103. {
  1104. struct ethtool_perm_addr epaddr;
  1105. if (copy_from_user(&epaddr, useraddr, sizeof(epaddr)))
  1106. return -EFAULT;
  1107. if (epaddr.size < dev->addr_len)
  1108. return -ETOOSMALL;
  1109. epaddr.size = dev->addr_len;
  1110. if (copy_to_user(useraddr, &epaddr, sizeof(epaddr)))
  1111. return -EFAULT;
  1112. useraddr += sizeof(epaddr);
  1113. if (copy_to_user(useraddr, dev->perm_addr, epaddr.size))
  1114. return -EFAULT;
  1115. return 0;
  1116. }
  1117. static int ethtool_get_value(struct net_device *dev, char __user *useraddr,
  1118. u32 cmd, u32 (*actor)(struct net_device *))
  1119. {
  1120. struct ethtool_value edata = { .cmd = cmd };
  1121. if (!actor)
  1122. return -EOPNOTSUPP;
  1123. edata.data = actor(dev);
  1124. if (copy_to_user(useraddr, &edata, sizeof(edata)))
  1125. return -EFAULT;
  1126. return 0;
  1127. }
  1128. static int ethtool_set_value_void(struct net_device *dev, char __user *useraddr,
  1129. void (*actor)(struct net_device *, u32))
  1130. {
  1131. struct ethtool_value edata;
  1132. if (!actor)
  1133. return -EOPNOTSUPP;
  1134. if (copy_from_user(&edata, useraddr, sizeof(edata)))
  1135. return -EFAULT;
  1136. actor(dev, edata.data);
  1137. return 0;
  1138. }
  1139. static int ethtool_set_value(struct net_device *dev, char __user *useraddr,
  1140. int (*actor)(struct net_device *, u32))
  1141. {
  1142. struct ethtool_value edata;
  1143. if (!actor)
  1144. return -EOPNOTSUPP;
  1145. if (copy_from_user(&edata, useraddr, sizeof(edata)))
  1146. return -EFAULT;
  1147. return actor(dev, edata.data);
  1148. }
  1149. static noinline_for_stack int ethtool_flash_device(struct net_device *dev,
  1150. char __user *useraddr)
  1151. {
  1152. struct ethtool_flash efl;
  1153. if (copy_from_user(&efl, useraddr, sizeof(efl)))
  1154. return -EFAULT;
  1155. if (!dev->ethtool_ops->flash_device)
  1156. return -EOPNOTSUPP;
  1157. efl.data[ETHTOOL_FLASH_MAX_FILENAME - 1] = 0;
  1158. return dev->ethtool_ops->flash_device(dev, &efl);
  1159. }
  1160. static int ethtool_set_dump(struct net_device *dev,
  1161. void __user *useraddr)
  1162. {
  1163. struct ethtool_dump dump;
  1164. if (!dev->ethtool_ops->set_dump)
  1165. return -EOPNOTSUPP;
  1166. if (copy_from_user(&dump, useraddr, sizeof(dump)))
  1167. return -EFAULT;
  1168. return dev->ethtool_ops->set_dump(dev, &dump);
  1169. }
  1170. static int ethtool_get_dump_flag(struct net_device *dev,
  1171. void __user *useraddr)
  1172. {
  1173. int ret;
  1174. struct ethtool_dump dump;
  1175. const struct ethtool_ops *ops = dev->ethtool_ops;
  1176. if (!ops->get_dump_flag)
  1177. return -EOPNOTSUPP;
  1178. if (copy_from_user(&dump, useraddr, sizeof(dump)))
  1179. return -EFAULT;
  1180. ret = ops->get_dump_flag(dev, &dump);
  1181. if (ret)
  1182. return ret;
  1183. if (copy_to_user(useraddr, &dump, sizeof(dump)))
  1184. return -EFAULT;
  1185. return 0;
  1186. }
  1187. static int ethtool_get_dump_data(struct net_device *dev,
  1188. void __user *useraddr)
  1189. {
  1190. int ret;
  1191. __u32 len;
  1192. struct ethtool_dump dump, tmp;
  1193. const struct ethtool_ops *ops = dev->ethtool_ops;
  1194. void *data = NULL;
  1195. if (!ops->get_dump_data || !ops->get_dump_flag)
  1196. return -EOPNOTSUPP;
  1197. if (copy_from_user(&dump, useraddr, sizeof(dump)))
  1198. return -EFAULT;
  1199. memset(&tmp, 0, sizeof(tmp));
  1200. tmp.cmd = ETHTOOL_GET_DUMP_FLAG;
  1201. ret = ops->get_dump_flag(dev, &tmp);
  1202. if (ret)
  1203. return ret;
  1204. len = min(tmp.len, dump.len);
  1205. if (!len)
  1206. return -EFAULT;
  1207. /* Don't ever let the driver think there's more space available
  1208. * than it requested with .get_dump_flag().
  1209. */
  1210. dump.len = len;
  1211. /* Always allocate enough space to hold the whole thing so that the
  1212. * driver does not need to check the length and bother with partial
  1213. * dumping.
  1214. */
  1215. data = vzalloc(tmp.len);
  1216. if (!data)
  1217. return -ENOMEM;
  1218. ret = ops->get_dump_data(dev, &dump, data);
  1219. if (ret)
  1220. goto out;
  1221. /* There are two sane possibilities:
  1222. * 1. The driver's .get_dump_data() does not touch dump.len.
  1223. * 2. Or it may set dump.len to how much it really writes, which
  1224. * should be tmp.len (or len if it can do a partial dump).
  1225. * In any case respond to userspace with the actual length of data
  1226. * it's receiving.
  1227. */
  1228. WARN_ON(dump.len != len && dump.len != tmp.len);
  1229. dump.len = len;
  1230. if (copy_to_user(useraddr, &dump, sizeof(dump))) {
  1231. ret = -EFAULT;
  1232. goto out;
  1233. }
  1234. useraddr += offsetof(struct ethtool_dump, data);
  1235. if (copy_to_user(useraddr, data, len))
  1236. ret = -EFAULT;
  1237. out:
  1238. vfree(data);
  1239. return ret;
  1240. }
  1241. static int ethtool_get_ts_info(struct net_device *dev, void __user *useraddr)
  1242. {
  1243. int err = 0;
  1244. struct ethtool_ts_info info;
  1245. const struct ethtool_ops *ops = dev->ethtool_ops;
  1246. struct phy_device *phydev = dev->phydev;
  1247. memset(&info, 0, sizeof(info));
  1248. info.cmd = ETHTOOL_GET_TS_INFO;
  1249. if (phydev && phydev->drv && phydev->drv->ts_info) {
  1250. err = phydev->drv->ts_info(phydev, &info);
  1251. } else if (ops->get_ts_info) {
  1252. err = ops->get_ts_info(dev, &info);
  1253. } else {
  1254. info.so_timestamping =
  1255. SOF_TIMESTAMPING_RX_SOFTWARE |
  1256. SOF_TIMESTAMPING_SOFTWARE;
  1257. info.phc_index = -1;
  1258. }
  1259. if (err)
  1260. return err;
  1261. if (copy_to_user(useraddr, &info, sizeof(info)))
  1262. err = -EFAULT;
  1263. return err;
  1264. }
  1265. static int ethtool_get_module_info(struct net_device *dev,
  1266. void __user *useraddr)
  1267. {
  1268. int ret;
  1269. struct ethtool_modinfo modinfo;
  1270. const struct ethtool_ops *ops = dev->ethtool_ops;
  1271. if (!ops->get_module_info)
  1272. return -EOPNOTSUPP;
  1273. if (copy_from_user(&modinfo, useraddr, sizeof(modinfo)))
  1274. return -EFAULT;
  1275. ret = ops->get_module_info(dev, &modinfo);
  1276. if (ret)
  1277. return ret;
  1278. if (copy_to_user(useraddr, &modinfo, sizeof(modinfo)))
  1279. return -EFAULT;
  1280. return 0;
  1281. }
  1282. static int ethtool_get_module_eeprom(struct net_device *dev,
  1283. void __user *useraddr)
  1284. {
  1285. int ret;
  1286. struct ethtool_modinfo modinfo;
  1287. const struct ethtool_ops *ops = dev->ethtool_ops;
  1288. if (!ops->get_module_info || !ops->get_module_eeprom)
  1289. return -EOPNOTSUPP;
  1290. ret = ops->get_module_info(dev, &modinfo);
  1291. if (ret)
  1292. return ret;
  1293. return ethtool_get_any_eeprom(dev, useraddr, ops->get_module_eeprom,
  1294. modinfo.eeprom_len);
  1295. }
  1296. /* The main entry point in this file. Called from net/core/dev_ioctl.c */
  1297. int dev_ethtool(struct net *net, struct ifreq *ifr)
  1298. {
  1299. struct net_device *dev = __dev_get_by_name(net, ifr->ifr_name);
  1300. void __user *useraddr = ifr->ifr_data;
  1301. u32 ethcmd;
  1302. int rc;
  1303. netdev_features_t old_features;
  1304. if (!dev || !netif_device_present(dev))
  1305. return -ENODEV;
  1306. if (copy_from_user(&ethcmd, useraddr, sizeof(ethcmd)))
  1307. return -EFAULT;
  1308. /* Allow some commands to be done by anyone */
  1309. switch (ethcmd) {
  1310. case ETHTOOL_GSET:
  1311. case ETHTOOL_GDRVINFO:
  1312. case ETHTOOL_GMSGLVL:
  1313. case ETHTOOL_GLINK:
  1314. case ETHTOOL_GCOALESCE:
  1315. case ETHTOOL_GRINGPARAM:
  1316. case ETHTOOL_GPAUSEPARAM:
  1317. case ETHTOOL_GRXCSUM:
  1318. case ETHTOOL_GTXCSUM:
  1319. case ETHTOOL_GSG:
  1320. case ETHTOOL_GSSET_INFO:
  1321. case ETHTOOL_GSTRINGS:
  1322. case ETHTOOL_GSTATS:
  1323. case ETHTOOL_GTSO:
  1324. case ETHTOOL_GPERMADDR:
  1325. case ETHTOOL_GUFO:
  1326. case ETHTOOL_GGSO:
  1327. case ETHTOOL_GGRO:
  1328. case ETHTOOL_GFLAGS:
  1329. case ETHTOOL_GPFLAGS:
  1330. case ETHTOOL_GRXFH:
  1331. case ETHTOOL_GRXRINGS:
  1332. case ETHTOOL_GRXCLSRLCNT:
  1333. case ETHTOOL_GRXCLSRULE:
  1334. case ETHTOOL_GRXCLSRLALL:
  1335. case ETHTOOL_GRXFHINDIR:
  1336. case ETHTOOL_GRSSH:
  1337. case ETHTOOL_GFEATURES:
  1338. case ETHTOOL_GCHANNELS:
  1339. case ETHTOOL_GET_TS_INFO:
  1340. case ETHTOOL_GEEE:
  1341. break;
  1342. default:
  1343. if (!ns_capable(net->user_ns, CAP_NET_ADMIN))
  1344. return -EPERM;
  1345. }
  1346. if (dev->ethtool_ops->begin) {
  1347. rc = dev->ethtool_ops->begin(dev);
  1348. if (rc < 0)
  1349. return rc;
  1350. }
  1351. old_features = dev->features;
  1352. switch (ethcmd) {
  1353. case ETHTOOL_GSET:
  1354. rc = ethtool_get_settings(dev, useraddr);
  1355. break;
  1356. case ETHTOOL_SSET:
  1357. rc = ethtool_set_settings(dev, useraddr);
  1358. break;
  1359. case ETHTOOL_GDRVINFO:
  1360. rc = ethtool_get_drvinfo(dev, useraddr);
  1361. break;
  1362. case ETHTOOL_GREGS:
  1363. rc = ethtool_get_regs(dev, useraddr);
  1364. break;
  1365. case ETHTOOL_GWOL:
  1366. rc = ethtool_get_wol(dev, useraddr);
  1367. break;
  1368. case ETHTOOL_SWOL:
  1369. rc = ethtool_set_wol(dev, useraddr);
  1370. break;
  1371. case ETHTOOL_GMSGLVL:
  1372. rc = ethtool_get_value(dev, useraddr, ethcmd,
  1373. dev->ethtool_ops->get_msglevel);
  1374. break;
  1375. case ETHTOOL_SMSGLVL:
  1376. rc = ethtool_set_value_void(dev, useraddr,
  1377. dev->ethtool_ops->set_msglevel);
  1378. break;
  1379. case ETHTOOL_GEEE:
  1380. rc = ethtool_get_eee(dev, useraddr);
  1381. break;
  1382. case ETHTOOL_SEEE:
  1383. rc = ethtool_set_eee(dev, useraddr);
  1384. break;
  1385. case ETHTOOL_NWAY_RST:
  1386. rc = ethtool_nway_reset(dev);
  1387. break;
  1388. case ETHTOOL_GLINK:
  1389. rc = ethtool_get_link(dev, useraddr);
  1390. break;
  1391. case ETHTOOL_GEEPROM:
  1392. rc = ethtool_get_eeprom(dev, useraddr);
  1393. break;
  1394. case ETHTOOL_SEEPROM:
  1395. rc = ethtool_set_eeprom(dev, useraddr);
  1396. break;
  1397. case ETHTOOL_GCOALESCE:
  1398. rc = ethtool_get_coalesce(dev, useraddr);
  1399. break;
  1400. case ETHTOOL_SCOALESCE:
  1401. rc = ethtool_set_coalesce(dev, useraddr);
  1402. break;
  1403. case ETHTOOL_GRINGPARAM:
  1404. rc = ethtool_get_ringparam(dev, useraddr);
  1405. break;
  1406. case ETHTOOL_SRINGPARAM:
  1407. rc = ethtool_set_ringparam(dev, useraddr);
  1408. break;
  1409. case ETHTOOL_GPAUSEPARAM:
  1410. rc = ethtool_get_pauseparam(dev, useraddr);
  1411. break;
  1412. case ETHTOOL_SPAUSEPARAM:
  1413. rc = ethtool_set_pauseparam(dev, useraddr);
  1414. break;
  1415. case ETHTOOL_TEST:
  1416. rc = ethtool_self_test(dev, useraddr);
  1417. break;
  1418. case ETHTOOL_GSTRINGS:
  1419. rc = ethtool_get_strings(dev, useraddr);
  1420. break;
  1421. case ETHTOOL_PHYS_ID:
  1422. rc = ethtool_phys_id(dev, useraddr);
  1423. break;
  1424. case ETHTOOL_GSTATS:
  1425. rc = ethtool_get_stats(dev, useraddr);
  1426. break;
  1427. case ETHTOOL_GPERMADDR:
  1428. rc = ethtool_get_perm_addr(dev, useraddr);
  1429. break;
  1430. case ETHTOOL_GFLAGS:
  1431. rc = ethtool_get_value(dev, useraddr, ethcmd,
  1432. __ethtool_get_flags);
  1433. break;
  1434. case ETHTOOL_SFLAGS:
  1435. rc = ethtool_set_value(dev, useraddr, __ethtool_set_flags);
  1436. break;
  1437. case ETHTOOL_GPFLAGS:
  1438. rc = ethtool_get_value(dev, useraddr, ethcmd,
  1439. dev->ethtool_ops->get_priv_flags);
  1440. break;
  1441. case ETHTOOL_SPFLAGS:
  1442. rc = ethtool_set_value(dev, useraddr,
  1443. dev->ethtool_ops->set_priv_flags);
  1444. break;
  1445. case ETHTOOL_GRXFH:
  1446. case ETHTOOL_GRXRINGS:
  1447. case ETHTOOL_GRXCLSRLCNT:
  1448. case ETHTOOL_GRXCLSRULE:
  1449. case ETHTOOL_GRXCLSRLALL:
  1450. rc = ethtool_get_rxnfc(dev, ethcmd, useraddr);
  1451. break;
  1452. case ETHTOOL_SRXFH:
  1453. case ETHTOOL_SRXCLSRLDEL:
  1454. case ETHTOOL_SRXCLSRLINS:
  1455. rc = ethtool_set_rxnfc(dev, ethcmd, useraddr);
  1456. break;
  1457. case ETHTOOL_FLASHDEV:
  1458. rc = ethtool_flash_device(dev, useraddr);
  1459. break;
  1460. case ETHTOOL_RESET:
  1461. rc = ethtool_reset(dev, useraddr);
  1462. break;
  1463. case ETHTOOL_GSSET_INFO:
  1464. rc = ethtool_get_sset_info(dev, useraddr);
  1465. break;
  1466. case ETHTOOL_GRXFHINDIR:
  1467. rc = ethtool_get_rxfh_indir(dev, useraddr);
  1468. break;
  1469. case ETHTOOL_SRXFHINDIR:
  1470. rc = ethtool_set_rxfh_indir(dev, useraddr);
  1471. break;
  1472. case ETHTOOL_GRSSH:
  1473. rc = ethtool_get_rxfh(dev, useraddr);
  1474. break;
  1475. case ETHTOOL_SRSSH:
  1476. rc = ethtool_set_rxfh(dev, useraddr);
  1477. break;
  1478. case ETHTOOL_GFEATURES:
  1479. rc = ethtool_get_features(dev, useraddr);
  1480. break;
  1481. case ETHTOOL_SFEATURES:
  1482. rc = ethtool_set_features(dev, useraddr);
  1483. break;
  1484. case ETHTOOL_GTXCSUM:
  1485. case ETHTOOL_GRXCSUM:
  1486. case ETHTOOL_GSG:
  1487. case ETHTOOL_GTSO:
  1488. case ETHTOOL_GUFO:
  1489. case ETHTOOL_GGSO:
  1490. case ETHTOOL_GGRO:
  1491. rc = ethtool_get_one_feature(dev, useraddr, ethcmd);
  1492. break;
  1493. case ETHTOOL_STXCSUM:
  1494. case ETHTOOL_SRXCSUM:
  1495. case ETHTOOL_SSG:
  1496. case ETHTOOL_STSO:
  1497. case ETHTOOL_SUFO:
  1498. case ETHTOOL_SGSO:
  1499. case ETHTOOL_SGRO:
  1500. rc = ethtool_set_one_feature(dev, useraddr, ethcmd);
  1501. break;
  1502. case ETHTOOL_GCHANNELS:
  1503. rc = ethtool_get_channels(dev, useraddr);
  1504. break;
  1505. case ETHTOOL_SCHANNELS:
  1506. rc = ethtool_set_channels(dev, useraddr);
  1507. break;
  1508. case ETHTOOL_SET_DUMP:
  1509. rc = ethtool_set_dump(dev, useraddr);
  1510. break;
  1511. case ETHTOOL_GET_DUMP_FLAG:
  1512. rc = ethtool_get_dump_flag(dev, useraddr);
  1513. break;
  1514. case ETHTOOL_GET_DUMP_DATA:
  1515. rc = ethtool_get_dump_data(dev, useraddr);
  1516. break;
  1517. case ETHTOOL_GET_TS_INFO:
  1518. rc = ethtool_get_ts_info(dev, useraddr);
  1519. break;
  1520. case ETHTOOL_GMODULEINFO:
  1521. rc = ethtool_get_module_info(dev, useraddr);
  1522. break;
  1523. case ETHTOOL_GMODULEEEPROM:
  1524. rc = ethtool_get_module_eeprom(dev, useraddr);
  1525. break;
  1526. default:
  1527. rc = -EOPNOTSUPP;
  1528. }
  1529. if (dev->ethtool_ops->complete)
  1530. dev->ethtool_ops->complete(dev);
  1531. if (old_features != dev->features)
  1532. netdev_features_change(dev);
  1533. return rc;
  1534. }