ethtool.c 44 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829
  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/bitops.h>
  20. #include <linux/uaccess.h>
  21. #include <linux/vmalloc.h>
  22. #include <linux/slab.h>
  23. /*
  24. * Some useful ethtool_ops methods that're device independent.
  25. * If we find that all drivers want to do the same thing here,
  26. * we can turn these into dev_() function calls.
  27. */
  28. u32 ethtool_op_get_link(struct net_device *dev)
  29. {
  30. return netif_carrier_ok(dev) ? 1 : 0;
  31. }
  32. EXPORT_SYMBOL(ethtool_op_get_link);
  33. u32 ethtool_op_get_rx_csum(struct net_device *dev)
  34. {
  35. return (dev->features & NETIF_F_ALL_CSUM) != 0;
  36. }
  37. EXPORT_SYMBOL(ethtool_op_get_rx_csum);
  38. u32 ethtool_op_get_tx_csum(struct net_device *dev)
  39. {
  40. return (dev->features & NETIF_F_ALL_CSUM) != 0;
  41. }
  42. EXPORT_SYMBOL(ethtool_op_get_tx_csum);
  43. int ethtool_op_set_tx_csum(struct net_device *dev, u32 data)
  44. {
  45. if (data)
  46. dev->features |= NETIF_F_IP_CSUM;
  47. else
  48. dev->features &= ~NETIF_F_IP_CSUM;
  49. return 0;
  50. }
  51. EXPORT_SYMBOL(ethtool_op_set_tx_csum);
  52. int ethtool_op_set_tx_hw_csum(struct net_device *dev, u32 data)
  53. {
  54. if (data)
  55. dev->features |= NETIF_F_HW_CSUM;
  56. else
  57. dev->features &= ~NETIF_F_HW_CSUM;
  58. return 0;
  59. }
  60. EXPORT_SYMBOL(ethtool_op_set_tx_hw_csum);
  61. int ethtool_op_set_tx_ipv6_csum(struct net_device *dev, u32 data)
  62. {
  63. if (data)
  64. dev->features |= NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM;
  65. else
  66. dev->features &= ~(NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM);
  67. return 0;
  68. }
  69. EXPORT_SYMBOL(ethtool_op_set_tx_ipv6_csum);
  70. u32 ethtool_op_get_sg(struct net_device *dev)
  71. {
  72. return (dev->features & NETIF_F_SG) != 0;
  73. }
  74. EXPORT_SYMBOL(ethtool_op_get_sg);
  75. int ethtool_op_set_sg(struct net_device *dev, u32 data)
  76. {
  77. if (data)
  78. dev->features |= NETIF_F_SG;
  79. else
  80. dev->features &= ~NETIF_F_SG;
  81. return 0;
  82. }
  83. EXPORT_SYMBOL(ethtool_op_set_sg);
  84. u32 ethtool_op_get_tso(struct net_device *dev)
  85. {
  86. return (dev->features & NETIF_F_TSO) != 0;
  87. }
  88. EXPORT_SYMBOL(ethtool_op_get_tso);
  89. int ethtool_op_set_tso(struct net_device *dev, u32 data)
  90. {
  91. if (data)
  92. dev->features |= NETIF_F_TSO;
  93. else
  94. dev->features &= ~NETIF_F_TSO;
  95. return 0;
  96. }
  97. EXPORT_SYMBOL(ethtool_op_set_tso);
  98. u32 ethtool_op_get_ufo(struct net_device *dev)
  99. {
  100. return (dev->features & NETIF_F_UFO) != 0;
  101. }
  102. EXPORT_SYMBOL(ethtool_op_get_ufo);
  103. int ethtool_op_set_ufo(struct net_device *dev, u32 data)
  104. {
  105. if (data)
  106. dev->features |= NETIF_F_UFO;
  107. else
  108. dev->features &= ~NETIF_F_UFO;
  109. return 0;
  110. }
  111. EXPORT_SYMBOL(ethtool_op_set_ufo);
  112. /* the following list of flags are the same as their associated
  113. * NETIF_F_xxx values in include/linux/netdevice.h
  114. */
  115. static const u32 flags_dup_features =
  116. (ETH_FLAG_LRO | ETH_FLAG_RXVLAN | ETH_FLAG_TXVLAN | ETH_FLAG_NTUPLE |
  117. ETH_FLAG_RXHASH);
  118. u32 ethtool_op_get_flags(struct net_device *dev)
  119. {
  120. /* in the future, this function will probably contain additional
  121. * handling for flags which are not so easily handled
  122. * by a simple masking operation
  123. */
  124. return dev->features & flags_dup_features;
  125. }
  126. EXPORT_SYMBOL(ethtool_op_get_flags);
  127. int ethtool_op_set_flags(struct net_device *dev, u32 data, u32 supported)
  128. {
  129. if (data & ~supported)
  130. return -EINVAL;
  131. dev->features = ((dev->features & ~flags_dup_features) |
  132. (data & flags_dup_features));
  133. return 0;
  134. }
  135. EXPORT_SYMBOL(ethtool_op_set_flags);
  136. void ethtool_ntuple_flush(struct net_device *dev)
  137. {
  138. struct ethtool_rx_ntuple_flow_spec_container *fsc, *f;
  139. list_for_each_entry_safe(fsc, f, &dev->ethtool_ntuple_list.list, list) {
  140. list_del(&fsc->list);
  141. kfree(fsc);
  142. }
  143. dev->ethtool_ntuple_list.count = 0;
  144. }
  145. EXPORT_SYMBOL(ethtool_ntuple_flush);
  146. /* Handlers for each ethtool command */
  147. #define ETHTOOL_DEV_FEATURE_WORDS 1
  148. static int ethtool_get_features(struct net_device *dev, void __user *useraddr)
  149. {
  150. struct ethtool_gfeatures cmd = {
  151. .cmd = ETHTOOL_GFEATURES,
  152. .size = ETHTOOL_DEV_FEATURE_WORDS,
  153. };
  154. struct ethtool_get_features_block features[ETHTOOL_DEV_FEATURE_WORDS] = {
  155. {
  156. .available = dev->hw_features,
  157. .requested = dev->wanted_features,
  158. .active = dev->features,
  159. .never_changed = NETIF_F_NEVER_CHANGE,
  160. },
  161. };
  162. u32 __user *sizeaddr;
  163. u32 copy_size;
  164. sizeaddr = useraddr + offsetof(struct ethtool_gfeatures, size);
  165. if (get_user(copy_size, sizeaddr))
  166. return -EFAULT;
  167. if (copy_size > ETHTOOL_DEV_FEATURE_WORDS)
  168. copy_size = ETHTOOL_DEV_FEATURE_WORDS;
  169. if (copy_to_user(useraddr, &cmd, sizeof(cmd)))
  170. return -EFAULT;
  171. useraddr += sizeof(cmd);
  172. if (copy_to_user(useraddr, features, copy_size * sizeof(*features)))
  173. return -EFAULT;
  174. return 0;
  175. }
  176. static int ethtool_set_features(struct net_device *dev, void __user *useraddr)
  177. {
  178. struct ethtool_sfeatures cmd;
  179. struct ethtool_set_features_block features[ETHTOOL_DEV_FEATURE_WORDS];
  180. int ret = 0;
  181. if (copy_from_user(&cmd, useraddr, sizeof(cmd)))
  182. return -EFAULT;
  183. useraddr += sizeof(cmd);
  184. if (cmd.size != ETHTOOL_DEV_FEATURE_WORDS)
  185. return -EINVAL;
  186. if (copy_from_user(features, useraddr, sizeof(features)))
  187. return -EFAULT;
  188. if (features[0].valid & ~NETIF_F_ETHTOOL_BITS)
  189. return -EINVAL;
  190. if (features[0].valid & ~dev->hw_features) {
  191. features[0].valid &= dev->hw_features;
  192. ret |= ETHTOOL_F_UNSUPPORTED;
  193. }
  194. dev->wanted_features &= ~features[0].valid;
  195. dev->wanted_features |= features[0].valid & features[0].requested;
  196. netdev_update_features(dev);
  197. if ((dev->wanted_features ^ dev->features) & features[0].valid)
  198. ret |= ETHTOOL_F_WISH;
  199. return ret;
  200. }
  201. static const char netdev_features_strings[ETHTOOL_DEV_FEATURE_WORDS * 32][ETH_GSTRING_LEN] = {
  202. /* NETIF_F_SG */ "tx-scatter-gather",
  203. /* NETIF_F_IP_CSUM */ "tx-checksum-ipv4",
  204. /* NETIF_F_NO_CSUM */ "tx-checksum-unneeded",
  205. /* NETIF_F_HW_CSUM */ "tx-checksum-ip-generic",
  206. /* NETIF_F_IPV6_CSUM */ "tx_checksum-ipv6",
  207. /* NETIF_F_HIGHDMA */ "highdma",
  208. /* NETIF_F_FRAGLIST */ "tx-scatter-gather-fraglist",
  209. /* NETIF_F_HW_VLAN_TX */ "tx-vlan-hw-insert",
  210. /* NETIF_F_HW_VLAN_RX */ "rx-vlan-hw-parse",
  211. /* NETIF_F_HW_VLAN_FILTER */ "rx-vlan-filter",
  212. /* NETIF_F_VLAN_CHALLENGED */ "vlan-challenged",
  213. /* NETIF_F_GSO */ "tx-generic-segmentation",
  214. /* NETIF_F_LLTX */ "tx-lockless",
  215. /* NETIF_F_NETNS_LOCAL */ "netns-local",
  216. /* NETIF_F_GRO */ "rx-gro",
  217. /* NETIF_F_LRO */ "rx-lro",
  218. /* NETIF_F_TSO */ "tx-tcp-segmentation",
  219. /* NETIF_F_UFO */ "tx-udp-fragmentation",
  220. /* NETIF_F_GSO_ROBUST */ "tx-gso-robust",
  221. /* NETIF_F_TSO_ECN */ "tx-tcp-ecn-segmentation",
  222. /* NETIF_F_TSO6 */ "tx-tcp6-segmentation",
  223. /* NETIF_F_FSO */ "tx-fcoe-segmentation",
  224. "",
  225. "",
  226. /* NETIF_F_FCOE_CRC */ "tx-checksum-fcoe-crc",
  227. /* NETIF_F_SCTP_CSUM */ "tx-checksum-sctp",
  228. /* NETIF_F_FCOE_MTU */ "fcoe-mtu",
  229. /* NETIF_F_NTUPLE */ "rx-ntuple-filter",
  230. /* NETIF_F_RXHASH */ "rx-hashing",
  231. "",
  232. "",
  233. "",
  234. };
  235. static int __ethtool_get_sset_count(struct net_device *dev, int sset)
  236. {
  237. const struct ethtool_ops *ops = dev->ethtool_ops;
  238. if (sset == ETH_SS_FEATURES)
  239. return ARRAY_SIZE(netdev_features_strings);
  240. if (ops && ops->get_sset_count && ops->get_strings)
  241. return ops->get_sset_count(dev, sset);
  242. else
  243. return -EOPNOTSUPP;
  244. }
  245. static void __ethtool_get_strings(struct net_device *dev,
  246. u32 stringset, u8 *data)
  247. {
  248. const struct ethtool_ops *ops = dev->ethtool_ops;
  249. if (stringset == ETH_SS_FEATURES)
  250. memcpy(data, netdev_features_strings,
  251. sizeof(netdev_features_strings));
  252. else
  253. /* ops->get_strings is valid because checked earlier */
  254. ops->get_strings(dev, stringset, data);
  255. }
  256. static u32 ethtool_get_feature_mask(u32 eth_cmd)
  257. {
  258. /* feature masks of legacy discrete ethtool ops */
  259. switch (eth_cmd) {
  260. case ETHTOOL_GTXCSUM:
  261. case ETHTOOL_STXCSUM:
  262. return NETIF_F_ALL_CSUM | NETIF_F_SCTP_CSUM;
  263. case ETHTOOL_GSG:
  264. case ETHTOOL_SSG:
  265. return NETIF_F_SG;
  266. case ETHTOOL_GTSO:
  267. case ETHTOOL_STSO:
  268. return NETIF_F_ALL_TSO;
  269. case ETHTOOL_GUFO:
  270. case ETHTOOL_SUFO:
  271. return NETIF_F_UFO;
  272. case ETHTOOL_GGSO:
  273. case ETHTOOL_SGSO:
  274. return NETIF_F_GSO;
  275. case ETHTOOL_GGRO:
  276. case ETHTOOL_SGRO:
  277. return NETIF_F_GRO;
  278. default:
  279. BUG();
  280. }
  281. }
  282. static void *__ethtool_get_one_feature_actor(struct net_device *dev, u32 ethcmd)
  283. {
  284. const struct ethtool_ops *ops = dev->ethtool_ops;
  285. if (!ops)
  286. return NULL;
  287. switch (ethcmd) {
  288. case ETHTOOL_GTXCSUM:
  289. return ops->get_tx_csum;
  290. case ETHTOOL_SSG:
  291. return ops->get_sg;
  292. case ETHTOOL_STSO:
  293. return ops->get_tso;
  294. case ETHTOOL_SUFO:
  295. return ops->get_ufo;
  296. default:
  297. return NULL;
  298. }
  299. }
  300. static int ethtool_get_one_feature(struct net_device *dev,
  301. char __user *useraddr, u32 ethcmd)
  302. {
  303. struct ethtool_value edata = {
  304. .cmd = ethcmd,
  305. .data = !!(dev->features & ethtool_get_feature_mask(ethcmd)),
  306. };
  307. u32 (*actor)(struct net_device *);
  308. actor = __ethtool_get_one_feature_actor(dev, ethcmd);
  309. if (actor)
  310. edata.data = actor(dev);
  311. if (copy_to_user(useraddr, &edata, sizeof(edata)))
  312. return -EFAULT;
  313. return 0;
  314. }
  315. static int __ethtool_set_tx_csum(struct net_device *dev, u32 data);
  316. static int __ethtool_set_sg(struct net_device *dev, u32 data);
  317. static int __ethtool_set_tso(struct net_device *dev, u32 data);
  318. static int __ethtool_set_ufo(struct net_device *dev, u32 data);
  319. static int ethtool_set_one_feature(struct net_device *dev,
  320. void __user *useraddr, u32 ethcmd)
  321. {
  322. struct ethtool_value edata;
  323. u32 mask;
  324. if (copy_from_user(&edata, useraddr, sizeof(edata)))
  325. return -EFAULT;
  326. switch (ethcmd) {
  327. case ETHTOOL_STXCSUM:
  328. return __ethtool_set_tx_csum(dev, edata.data);
  329. case ETHTOOL_SSG:
  330. return __ethtool_set_sg(dev, edata.data);
  331. case ETHTOOL_STSO:
  332. return __ethtool_set_tso(dev, edata.data);
  333. case ETHTOOL_SUFO:
  334. return __ethtool_set_ufo(dev, edata.data);
  335. case ETHTOOL_SGSO:
  336. case ETHTOOL_SGRO:
  337. mask = ethtool_get_feature_mask(ethcmd);
  338. if (edata.data)
  339. dev->features |= mask;
  340. else
  341. dev->features &= ~mask;
  342. return 0;
  343. default:
  344. return -EOPNOTSUPP;
  345. }
  346. }
  347. static int ethtool_get_settings(struct net_device *dev, void __user *useraddr)
  348. {
  349. struct ethtool_cmd cmd = { .cmd = ETHTOOL_GSET };
  350. int err;
  351. if (!dev->ethtool_ops->get_settings)
  352. return -EOPNOTSUPP;
  353. err = dev->ethtool_ops->get_settings(dev, &cmd);
  354. if (err < 0)
  355. return err;
  356. if (copy_to_user(useraddr, &cmd, sizeof(cmd)))
  357. return -EFAULT;
  358. return 0;
  359. }
  360. static int ethtool_set_settings(struct net_device *dev, void __user *useraddr)
  361. {
  362. struct ethtool_cmd cmd;
  363. if (!dev->ethtool_ops->set_settings)
  364. return -EOPNOTSUPP;
  365. if (copy_from_user(&cmd, useraddr, sizeof(cmd)))
  366. return -EFAULT;
  367. return dev->ethtool_ops->set_settings(dev, &cmd);
  368. }
  369. static noinline_for_stack int ethtool_get_drvinfo(struct net_device *dev,
  370. void __user *useraddr)
  371. {
  372. struct ethtool_drvinfo info;
  373. const struct ethtool_ops *ops = dev->ethtool_ops;
  374. memset(&info, 0, sizeof(info));
  375. info.cmd = ETHTOOL_GDRVINFO;
  376. if (ops && ops->get_drvinfo) {
  377. ops->get_drvinfo(dev, &info);
  378. } else if (dev->dev.parent && dev->dev.parent->driver) {
  379. strlcpy(info.bus_info, dev_name(dev->dev.parent),
  380. sizeof(info.bus_info));
  381. strlcpy(info.driver, dev->dev.parent->driver->name,
  382. sizeof(info.driver));
  383. } else {
  384. return -EOPNOTSUPP;
  385. }
  386. /*
  387. * this method of obtaining string set info is deprecated;
  388. * Use ETHTOOL_GSSET_INFO instead.
  389. */
  390. if (ops && ops->get_sset_count) {
  391. int rc;
  392. rc = ops->get_sset_count(dev, ETH_SS_TEST);
  393. if (rc >= 0)
  394. info.testinfo_len = rc;
  395. rc = ops->get_sset_count(dev, ETH_SS_STATS);
  396. if (rc >= 0)
  397. info.n_stats = rc;
  398. rc = ops->get_sset_count(dev, ETH_SS_PRIV_FLAGS);
  399. if (rc >= 0)
  400. info.n_priv_flags = rc;
  401. }
  402. if (ops && ops->get_regs_len)
  403. info.regdump_len = ops->get_regs_len(dev);
  404. if (ops && ops->get_eeprom_len)
  405. info.eedump_len = ops->get_eeprom_len(dev);
  406. if (copy_to_user(useraddr, &info, sizeof(info)))
  407. return -EFAULT;
  408. return 0;
  409. }
  410. static noinline_for_stack int ethtool_get_sset_info(struct net_device *dev,
  411. void __user *useraddr)
  412. {
  413. struct ethtool_sset_info info;
  414. u64 sset_mask;
  415. int i, idx = 0, n_bits = 0, ret, rc;
  416. u32 *info_buf = NULL;
  417. if (copy_from_user(&info, useraddr, sizeof(info)))
  418. return -EFAULT;
  419. /* store copy of mask, because we zero struct later on */
  420. sset_mask = info.sset_mask;
  421. if (!sset_mask)
  422. return 0;
  423. /* calculate size of return buffer */
  424. n_bits = hweight64(sset_mask);
  425. memset(&info, 0, sizeof(info));
  426. info.cmd = ETHTOOL_GSSET_INFO;
  427. info_buf = kzalloc(n_bits * sizeof(u32), GFP_USER);
  428. if (!info_buf)
  429. return -ENOMEM;
  430. /*
  431. * fill return buffer based on input bitmask and successful
  432. * get_sset_count return
  433. */
  434. for (i = 0; i < 64; i++) {
  435. if (!(sset_mask & (1ULL << i)))
  436. continue;
  437. rc = __ethtool_get_sset_count(dev, i);
  438. if (rc >= 0) {
  439. info.sset_mask |= (1ULL << i);
  440. info_buf[idx++] = rc;
  441. }
  442. }
  443. ret = -EFAULT;
  444. if (copy_to_user(useraddr, &info, sizeof(info)))
  445. goto out;
  446. useraddr += offsetof(struct ethtool_sset_info, data);
  447. if (copy_to_user(useraddr, info_buf, idx * sizeof(u32)))
  448. goto out;
  449. ret = 0;
  450. out:
  451. kfree(info_buf);
  452. return ret;
  453. }
  454. static noinline_for_stack int ethtool_set_rxnfc(struct net_device *dev,
  455. u32 cmd, void __user *useraddr)
  456. {
  457. struct ethtool_rxnfc info;
  458. size_t info_size = sizeof(info);
  459. if (!dev->ethtool_ops->set_rxnfc)
  460. return -EOPNOTSUPP;
  461. /* struct ethtool_rxnfc was originally defined for
  462. * ETHTOOL_{G,S}RXFH with only the cmd, flow_type and data
  463. * members. User-space might still be using that
  464. * definition. */
  465. if (cmd == ETHTOOL_SRXFH)
  466. info_size = (offsetof(struct ethtool_rxnfc, data) +
  467. sizeof(info.data));
  468. if (copy_from_user(&info, useraddr, info_size))
  469. return -EFAULT;
  470. return dev->ethtool_ops->set_rxnfc(dev, &info);
  471. }
  472. static noinline_for_stack int ethtool_get_rxnfc(struct net_device *dev,
  473. u32 cmd, void __user *useraddr)
  474. {
  475. struct ethtool_rxnfc info;
  476. size_t info_size = sizeof(info);
  477. const struct ethtool_ops *ops = dev->ethtool_ops;
  478. int ret;
  479. void *rule_buf = NULL;
  480. if (!ops->get_rxnfc)
  481. return -EOPNOTSUPP;
  482. /* struct ethtool_rxnfc was originally defined for
  483. * ETHTOOL_{G,S}RXFH with only the cmd, flow_type and data
  484. * members. User-space might still be using that
  485. * definition. */
  486. if (cmd == ETHTOOL_GRXFH)
  487. info_size = (offsetof(struct ethtool_rxnfc, data) +
  488. sizeof(info.data));
  489. if (copy_from_user(&info, useraddr, info_size))
  490. return -EFAULT;
  491. if (info.cmd == ETHTOOL_GRXCLSRLALL) {
  492. if (info.rule_cnt > 0) {
  493. if (info.rule_cnt <= KMALLOC_MAX_SIZE / sizeof(u32))
  494. rule_buf = kzalloc(info.rule_cnt * sizeof(u32),
  495. GFP_USER);
  496. if (!rule_buf)
  497. return -ENOMEM;
  498. }
  499. }
  500. ret = ops->get_rxnfc(dev, &info, rule_buf);
  501. if (ret < 0)
  502. goto err_out;
  503. ret = -EFAULT;
  504. if (copy_to_user(useraddr, &info, info_size))
  505. goto err_out;
  506. if (rule_buf) {
  507. useraddr += offsetof(struct ethtool_rxnfc, rule_locs);
  508. if (copy_to_user(useraddr, rule_buf,
  509. info.rule_cnt * sizeof(u32)))
  510. goto err_out;
  511. }
  512. ret = 0;
  513. err_out:
  514. kfree(rule_buf);
  515. return ret;
  516. }
  517. static noinline_for_stack int ethtool_get_rxfh_indir(struct net_device *dev,
  518. void __user *useraddr)
  519. {
  520. struct ethtool_rxfh_indir *indir;
  521. u32 table_size;
  522. size_t full_size;
  523. int ret;
  524. if (!dev->ethtool_ops->get_rxfh_indir)
  525. return -EOPNOTSUPP;
  526. if (copy_from_user(&table_size,
  527. useraddr + offsetof(struct ethtool_rxfh_indir, size),
  528. sizeof(table_size)))
  529. return -EFAULT;
  530. if (table_size >
  531. (KMALLOC_MAX_SIZE - sizeof(*indir)) / sizeof(*indir->ring_index))
  532. return -ENOMEM;
  533. full_size = sizeof(*indir) + sizeof(*indir->ring_index) * table_size;
  534. indir = kzalloc(full_size, GFP_USER);
  535. if (!indir)
  536. return -ENOMEM;
  537. indir->cmd = ETHTOOL_GRXFHINDIR;
  538. indir->size = table_size;
  539. ret = dev->ethtool_ops->get_rxfh_indir(dev, indir);
  540. if (ret)
  541. goto out;
  542. if (copy_to_user(useraddr, indir, full_size))
  543. ret = -EFAULT;
  544. out:
  545. kfree(indir);
  546. return ret;
  547. }
  548. static noinline_for_stack int ethtool_set_rxfh_indir(struct net_device *dev,
  549. void __user *useraddr)
  550. {
  551. struct ethtool_rxfh_indir *indir;
  552. u32 table_size;
  553. size_t full_size;
  554. int ret;
  555. if (!dev->ethtool_ops->set_rxfh_indir)
  556. return -EOPNOTSUPP;
  557. if (copy_from_user(&table_size,
  558. useraddr + offsetof(struct ethtool_rxfh_indir, size),
  559. sizeof(table_size)))
  560. return -EFAULT;
  561. if (table_size >
  562. (KMALLOC_MAX_SIZE - sizeof(*indir)) / sizeof(*indir->ring_index))
  563. return -ENOMEM;
  564. full_size = sizeof(*indir) + sizeof(*indir->ring_index) * table_size;
  565. indir = kmalloc(full_size, GFP_USER);
  566. if (!indir)
  567. return -ENOMEM;
  568. if (copy_from_user(indir, useraddr, full_size)) {
  569. ret = -EFAULT;
  570. goto out;
  571. }
  572. ret = dev->ethtool_ops->set_rxfh_indir(dev, indir);
  573. out:
  574. kfree(indir);
  575. return ret;
  576. }
  577. static void __rx_ntuple_filter_add(struct ethtool_rx_ntuple_list *list,
  578. struct ethtool_rx_ntuple_flow_spec *spec,
  579. struct ethtool_rx_ntuple_flow_spec_container *fsc)
  580. {
  581. /* don't add filters forever */
  582. if (list->count >= ETHTOOL_MAX_NTUPLE_LIST_ENTRY) {
  583. /* free the container */
  584. kfree(fsc);
  585. return;
  586. }
  587. /* Copy the whole filter over */
  588. fsc->fs.flow_type = spec->flow_type;
  589. memcpy(&fsc->fs.h_u, &spec->h_u, sizeof(spec->h_u));
  590. memcpy(&fsc->fs.m_u, &spec->m_u, sizeof(spec->m_u));
  591. fsc->fs.vlan_tag = spec->vlan_tag;
  592. fsc->fs.vlan_tag_mask = spec->vlan_tag_mask;
  593. fsc->fs.data = spec->data;
  594. fsc->fs.data_mask = spec->data_mask;
  595. fsc->fs.action = spec->action;
  596. /* add to the list */
  597. list_add_tail_rcu(&fsc->list, &list->list);
  598. list->count++;
  599. }
  600. /*
  601. * ethtool does not (or did not) set masks for flow parameters that are
  602. * not specified, so if both value and mask are 0 then this must be
  603. * treated as equivalent to a mask with all bits set. Implement that
  604. * here rather than in drivers.
  605. */
  606. static void rx_ntuple_fix_masks(struct ethtool_rx_ntuple_flow_spec *fs)
  607. {
  608. struct ethtool_tcpip4_spec *entry = &fs->h_u.tcp_ip4_spec;
  609. struct ethtool_tcpip4_spec *mask = &fs->m_u.tcp_ip4_spec;
  610. if (fs->flow_type != TCP_V4_FLOW &&
  611. fs->flow_type != UDP_V4_FLOW &&
  612. fs->flow_type != SCTP_V4_FLOW)
  613. return;
  614. if (!(entry->ip4src | mask->ip4src))
  615. mask->ip4src = htonl(0xffffffff);
  616. if (!(entry->ip4dst | mask->ip4dst))
  617. mask->ip4dst = htonl(0xffffffff);
  618. if (!(entry->psrc | mask->psrc))
  619. mask->psrc = htons(0xffff);
  620. if (!(entry->pdst | mask->pdst))
  621. mask->pdst = htons(0xffff);
  622. if (!(entry->tos | mask->tos))
  623. mask->tos = 0xff;
  624. if (!(fs->vlan_tag | fs->vlan_tag_mask))
  625. fs->vlan_tag_mask = 0xffff;
  626. if (!(fs->data | fs->data_mask))
  627. fs->data_mask = 0xffffffffffffffffULL;
  628. }
  629. static noinline_for_stack int ethtool_set_rx_ntuple(struct net_device *dev,
  630. void __user *useraddr)
  631. {
  632. struct ethtool_rx_ntuple cmd;
  633. const struct ethtool_ops *ops = dev->ethtool_ops;
  634. struct ethtool_rx_ntuple_flow_spec_container *fsc = NULL;
  635. int ret;
  636. if (!(dev->features & NETIF_F_NTUPLE))
  637. return -EINVAL;
  638. if (copy_from_user(&cmd, useraddr, sizeof(cmd)))
  639. return -EFAULT;
  640. rx_ntuple_fix_masks(&cmd.fs);
  641. /*
  642. * Cache filter in dev struct for GET operation only if
  643. * the underlying driver doesn't have its own GET operation, and
  644. * only if the filter was added successfully. First make sure we
  645. * can allocate the filter, then continue if successful.
  646. */
  647. if (!ops->get_rx_ntuple) {
  648. fsc = kmalloc(sizeof(*fsc), GFP_ATOMIC);
  649. if (!fsc)
  650. return -ENOMEM;
  651. }
  652. ret = ops->set_rx_ntuple(dev, &cmd);
  653. if (ret) {
  654. kfree(fsc);
  655. return ret;
  656. }
  657. if (!ops->get_rx_ntuple)
  658. __rx_ntuple_filter_add(&dev->ethtool_ntuple_list, &cmd.fs, fsc);
  659. return ret;
  660. }
  661. static int ethtool_get_rx_ntuple(struct net_device *dev, void __user *useraddr)
  662. {
  663. struct ethtool_gstrings gstrings;
  664. const struct ethtool_ops *ops = dev->ethtool_ops;
  665. struct ethtool_rx_ntuple_flow_spec_container *fsc;
  666. u8 *data;
  667. char *p;
  668. int ret, i, num_strings = 0;
  669. if (!ops->get_sset_count)
  670. return -EOPNOTSUPP;
  671. if (copy_from_user(&gstrings, useraddr, sizeof(gstrings)))
  672. return -EFAULT;
  673. ret = ops->get_sset_count(dev, gstrings.string_set);
  674. if (ret < 0)
  675. return ret;
  676. gstrings.len = ret;
  677. data = kzalloc(gstrings.len * ETH_GSTRING_LEN, GFP_USER);
  678. if (!data)
  679. return -ENOMEM;
  680. if (ops->get_rx_ntuple) {
  681. /* driver-specific filter grab */
  682. ret = ops->get_rx_ntuple(dev, gstrings.string_set, data);
  683. goto copy;
  684. }
  685. /* default ethtool filter grab */
  686. i = 0;
  687. p = (char *)data;
  688. list_for_each_entry(fsc, &dev->ethtool_ntuple_list.list, list) {
  689. sprintf(p, "Filter %d:\n", i);
  690. p += ETH_GSTRING_LEN;
  691. num_strings++;
  692. switch (fsc->fs.flow_type) {
  693. case TCP_V4_FLOW:
  694. sprintf(p, "\tFlow Type: TCP\n");
  695. p += ETH_GSTRING_LEN;
  696. num_strings++;
  697. break;
  698. case UDP_V4_FLOW:
  699. sprintf(p, "\tFlow Type: UDP\n");
  700. p += ETH_GSTRING_LEN;
  701. num_strings++;
  702. break;
  703. case SCTP_V4_FLOW:
  704. sprintf(p, "\tFlow Type: SCTP\n");
  705. p += ETH_GSTRING_LEN;
  706. num_strings++;
  707. break;
  708. case AH_ESP_V4_FLOW:
  709. sprintf(p, "\tFlow Type: AH ESP\n");
  710. p += ETH_GSTRING_LEN;
  711. num_strings++;
  712. break;
  713. case ESP_V4_FLOW:
  714. sprintf(p, "\tFlow Type: ESP\n");
  715. p += ETH_GSTRING_LEN;
  716. num_strings++;
  717. break;
  718. case IP_USER_FLOW:
  719. sprintf(p, "\tFlow Type: Raw IP\n");
  720. p += ETH_GSTRING_LEN;
  721. num_strings++;
  722. break;
  723. case IPV4_FLOW:
  724. sprintf(p, "\tFlow Type: IPv4\n");
  725. p += ETH_GSTRING_LEN;
  726. num_strings++;
  727. break;
  728. default:
  729. sprintf(p, "\tFlow Type: Unknown\n");
  730. p += ETH_GSTRING_LEN;
  731. num_strings++;
  732. goto unknown_filter;
  733. }
  734. /* now the rest of the filters */
  735. switch (fsc->fs.flow_type) {
  736. case TCP_V4_FLOW:
  737. case UDP_V4_FLOW:
  738. case SCTP_V4_FLOW:
  739. sprintf(p, "\tSrc IP addr: 0x%x\n",
  740. fsc->fs.h_u.tcp_ip4_spec.ip4src);
  741. p += ETH_GSTRING_LEN;
  742. num_strings++;
  743. sprintf(p, "\tSrc IP mask: 0x%x\n",
  744. fsc->fs.m_u.tcp_ip4_spec.ip4src);
  745. p += ETH_GSTRING_LEN;
  746. num_strings++;
  747. sprintf(p, "\tDest IP addr: 0x%x\n",
  748. fsc->fs.h_u.tcp_ip4_spec.ip4dst);
  749. p += ETH_GSTRING_LEN;
  750. num_strings++;
  751. sprintf(p, "\tDest IP mask: 0x%x\n",
  752. fsc->fs.m_u.tcp_ip4_spec.ip4dst);
  753. p += ETH_GSTRING_LEN;
  754. num_strings++;
  755. sprintf(p, "\tSrc Port: %d, mask: 0x%x\n",
  756. fsc->fs.h_u.tcp_ip4_spec.psrc,
  757. fsc->fs.m_u.tcp_ip4_spec.psrc);
  758. p += ETH_GSTRING_LEN;
  759. num_strings++;
  760. sprintf(p, "\tDest Port: %d, mask: 0x%x\n",
  761. fsc->fs.h_u.tcp_ip4_spec.pdst,
  762. fsc->fs.m_u.tcp_ip4_spec.pdst);
  763. p += ETH_GSTRING_LEN;
  764. num_strings++;
  765. sprintf(p, "\tTOS: %d, mask: 0x%x\n",
  766. fsc->fs.h_u.tcp_ip4_spec.tos,
  767. fsc->fs.m_u.tcp_ip4_spec.tos);
  768. p += ETH_GSTRING_LEN;
  769. num_strings++;
  770. break;
  771. case AH_ESP_V4_FLOW:
  772. case ESP_V4_FLOW:
  773. sprintf(p, "\tSrc IP addr: 0x%x\n",
  774. fsc->fs.h_u.ah_ip4_spec.ip4src);
  775. p += ETH_GSTRING_LEN;
  776. num_strings++;
  777. sprintf(p, "\tSrc IP mask: 0x%x\n",
  778. fsc->fs.m_u.ah_ip4_spec.ip4src);
  779. p += ETH_GSTRING_LEN;
  780. num_strings++;
  781. sprintf(p, "\tDest IP addr: 0x%x\n",
  782. fsc->fs.h_u.ah_ip4_spec.ip4dst);
  783. p += ETH_GSTRING_LEN;
  784. num_strings++;
  785. sprintf(p, "\tDest IP mask: 0x%x\n",
  786. fsc->fs.m_u.ah_ip4_spec.ip4dst);
  787. p += ETH_GSTRING_LEN;
  788. num_strings++;
  789. sprintf(p, "\tSPI: %d, mask: 0x%x\n",
  790. fsc->fs.h_u.ah_ip4_spec.spi,
  791. fsc->fs.m_u.ah_ip4_spec.spi);
  792. p += ETH_GSTRING_LEN;
  793. num_strings++;
  794. sprintf(p, "\tTOS: %d, mask: 0x%x\n",
  795. fsc->fs.h_u.ah_ip4_spec.tos,
  796. fsc->fs.m_u.ah_ip4_spec.tos);
  797. p += ETH_GSTRING_LEN;
  798. num_strings++;
  799. break;
  800. case IP_USER_FLOW:
  801. sprintf(p, "\tSrc IP addr: 0x%x\n",
  802. fsc->fs.h_u.usr_ip4_spec.ip4src);
  803. p += ETH_GSTRING_LEN;
  804. num_strings++;
  805. sprintf(p, "\tSrc IP mask: 0x%x\n",
  806. fsc->fs.m_u.usr_ip4_spec.ip4src);
  807. p += ETH_GSTRING_LEN;
  808. num_strings++;
  809. sprintf(p, "\tDest IP addr: 0x%x\n",
  810. fsc->fs.h_u.usr_ip4_spec.ip4dst);
  811. p += ETH_GSTRING_LEN;
  812. num_strings++;
  813. sprintf(p, "\tDest IP mask: 0x%x\n",
  814. fsc->fs.m_u.usr_ip4_spec.ip4dst);
  815. p += ETH_GSTRING_LEN;
  816. num_strings++;
  817. break;
  818. case IPV4_FLOW:
  819. sprintf(p, "\tSrc IP addr: 0x%x\n",
  820. fsc->fs.h_u.usr_ip4_spec.ip4src);
  821. p += ETH_GSTRING_LEN;
  822. num_strings++;
  823. sprintf(p, "\tSrc IP mask: 0x%x\n",
  824. fsc->fs.m_u.usr_ip4_spec.ip4src);
  825. p += ETH_GSTRING_LEN;
  826. num_strings++;
  827. sprintf(p, "\tDest IP addr: 0x%x\n",
  828. fsc->fs.h_u.usr_ip4_spec.ip4dst);
  829. p += ETH_GSTRING_LEN;
  830. num_strings++;
  831. sprintf(p, "\tDest IP mask: 0x%x\n",
  832. fsc->fs.m_u.usr_ip4_spec.ip4dst);
  833. p += ETH_GSTRING_LEN;
  834. num_strings++;
  835. sprintf(p, "\tL4 bytes: 0x%x, mask: 0x%x\n",
  836. fsc->fs.h_u.usr_ip4_spec.l4_4_bytes,
  837. fsc->fs.m_u.usr_ip4_spec.l4_4_bytes);
  838. p += ETH_GSTRING_LEN;
  839. num_strings++;
  840. sprintf(p, "\tTOS: %d, mask: 0x%x\n",
  841. fsc->fs.h_u.usr_ip4_spec.tos,
  842. fsc->fs.m_u.usr_ip4_spec.tos);
  843. p += ETH_GSTRING_LEN;
  844. num_strings++;
  845. sprintf(p, "\tIP Version: %d, mask: 0x%x\n",
  846. fsc->fs.h_u.usr_ip4_spec.ip_ver,
  847. fsc->fs.m_u.usr_ip4_spec.ip_ver);
  848. p += ETH_GSTRING_LEN;
  849. num_strings++;
  850. sprintf(p, "\tProtocol: %d, mask: 0x%x\n",
  851. fsc->fs.h_u.usr_ip4_spec.proto,
  852. fsc->fs.m_u.usr_ip4_spec.proto);
  853. p += ETH_GSTRING_LEN;
  854. num_strings++;
  855. break;
  856. }
  857. sprintf(p, "\tVLAN: %d, mask: 0x%x\n",
  858. fsc->fs.vlan_tag, fsc->fs.vlan_tag_mask);
  859. p += ETH_GSTRING_LEN;
  860. num_strings++;
  861. sprintf(p, "\tUser-defined: 0x%Lx\n", fsc->fs.data);
  862. p += ETH_GSTRING_LEN;
  863. num_strings++;
  864. sprintf(p, "\tUser-defined mask: 0x%Lx\n", fsc->fs.data_mask);
  865. p += ETH_GSTRING_LEN;
  866. num_strings++;
  867. if (fsc->fs.action == ETHTOOL_RXNTUPLE_ACTION_DROP)
  868. sprintf(p, "\tAction: Drop\n");
  869. else
  870. sprintf(p, "\tAction: Direct to queue %d\n",
  871. fsc->fs.action);
  872. p += ETH_GSTRING_LEN;
  873. num_strings++;
  874. unknown_filter:
  875. i++;
  876. }
  877. copy:
  878. /* indicate to userspace how many strings we actually have */
  879. gstrings.len = num_strings;
  880. ret = -EFAULT;
  881. if (copy_to_user(useraddr, &gstrings, sizeof(gstrings)))
  882. goto out;
  883. useraddr += sizeof(gstrings);
  884. if (copy_to_user(useraddr, data, gstrings.len * ETH_GSTRING_LEN))
  885. goto out;
  886. ret = 0;
  887. out:
  888. kfree(data);
  889. return ret;
  890. }
  891. static int ethtool_get_regs(struct net_device *dev, char __user *useraddr)
  892. {
  893. struct ethtool_regs regs;
  894. const struct ethtool_ops *ops = dev->ethtool_ops;
  895. void *regbuf;
  896. int reglen, ret;
  897. if (!ops->get_regs || !ops->get_regs_len)
  898. return -EOPNOTSUPP;
  899. if (copy_from_user(&regs, useraddr, sizeof(regs)))
  900. return -EFAULT;
  901. reglen = ops->get_regs_len(dev);
  902. if (regs.len > reglen)
  903. regs.len = reglen;
  904. regbuf = vzalloc(reglen);
  905. if (!regbuf)
  906. return -ENOMEM;
  907. ops->get_regs(dev, &regs, regbuf);
  908. ret = -EFAULT;
  909. if (copy_to_user(useraddr, &regs, sizeof(regs)))
  910. goto out;
  911. useraddr += offsetof(struct ethtool_regs, data);
  912. if (copy_to_user(useraddr, regbuf, regs.len))
  913. goto out;
  914. ret = 0;
  915. out:
  916. vfree(regbuf);
  917. return ret;
  918. }
  919. static int ethtool_reset(struct net_device *dev, char __user *useraddr)
  920. {
  921. struct ethtool_value reset;
  922. int ret;
  923. if (!dev->ethtool_ops->reset)
  924. return -EOPNOTSUPP;
  925. if (copy_from_user(&reset, useraddr, sizeof(reset)))
  926. return -EFAULT;
  927. ret = dev->ethtool_ops->reset(dev, &reset.data);
  928. if (ret)
  929. return ret;
  930. if (copy_to_user(useraddr, &reset, sizeof(reset)))
  931. return -EFAULT;
  932. return 0;
  933. }
  934. static int ethtool_get_wol(struct net_device *dev, char __user *useraddr)
  935. {
  936. struct ethtool_wolinfo wol = { .cmd = ETHTOOL_GWOL };
  937. if (!dev->ethtool_ops->get_wol)
  938. return -EOPNOTSUPP;
  939. dev->ethtool_ops->get_wol(dev, &wol);
  940. if (copy_to_user(useraddr, &wol, sizeof(wol)))
  941. return -EFAULT;
  942. return 0;
  943. }
  944. static int ethtool_set_wol(struct net_device *dev, char __user *useraddr)
  945. {
  946. struct ethtool_wolinfo wol;
  947. if (!dev->ethtool_ops->set_wol)
  948. return -EOPNOTSUPP;
  949. if (copy_from_user(&wol, useraddr, sizeof(wol)))
  950. return -EFAULT;
  951. return dev->ethtool_ops->set_wol(dev, &wol);
  952. }
  953. static int ethtool_nway_reset(struct net_device *dev)
  954. {
  955. if (!dev->ethtool_ops->nway_reset)
  956. return -EOPNOTSUPP;
  957. return dev->ethtool_ops->nway_reset(dev);
  958. }
  959. static int ethtool_get_link(struct net_device *dev, char __user *useraddr)
  960. {
  961. struct ethtool_value edata = { .cmd = ETHTOOL_GLINK };
  962. if (!dev->ethtool_ops->get_link)
  963. return -EOPNOTSUPP;
  964. edata.data = netif_running(dev) && dev->ethtool_ops->get_link(dev);
  965. if (copy_to_user(useraddr, &edata, sizeof(edata)))
  966. return -EFAULT;
  967. return 0;
  968. }
  969. static int ethtool_get_eeprom(struct net_device *dev, void __user *useraddr)
  970. {
  971. struct ethtool_eeprom eeprom;
  972. const struct ethtool_ops *ops = dev->ethtool_ops;
  973. void __user *userbuf = useraddr + sizeof(eeprom);
  974. u32 bytes_remaining;
  975. u8 *data;
  976. int ret = 0;
  977. if (!ops->get_eeprom || !ops->get_eeprom_len)
  978. return -EOPNOTSUPP;
  979. if (copy_from_user(&eeprom, useraddr, sizeof(eeprom)))
  980. return -EFAULT;
  981. /* Check for wrap and zero */
  982. if (eeprom.offset + eeprom.len <= eeprom.offset)
  983. return -EINVAL;
  984. /* Check for exceeding total eeprom len */
  985. if (eeprom.offset + eeprom.len > ops->get_eeprom_len(dev))
  986. return -EINVAL;
  987. data = kmalloc(PAGE_SIZE, GFP_USER);
  988. if (!data)
  989. return -ENOMEM;
  990. bytes_remaining = eeprom.len;
  991. while (bytes_remaining > 0) {
  992. eeprom.len = min(bytes_remaining, (u32)PAGE_SIZE);
  993. ret = ops->get_eeprom(dev, &eeprom, data);
  994. if (ret)
  995. break;
  996. if (copy_to_user(userbuf, data, eeprom.len)) {
  997. ret = -EFAULT;
  998. break;
  999. }
  1000. userbuf += eeprom.len;
  1001. eeprom.offset += eeprom.len;
  1002. bytes_remaining -= eeprom.len;
  1003. }
  1004. eeprom.len = userbuf - (useraddr + sizeof(eeprom));
  1005. eeprom.offset -= eeprom.len;
  1006. if (copy_to_user(useraddr, &eeprom, sizeof(eeprom)))
  1007. ret = -EFAULT;
  1008. kfree(data);
  1009. return ret;
  1010. }
  1011. static int ethtool_set_eeprom(struct net_device *dev, void __user *useraddr)
  1012. {
  1013. struct ethtool_eeprom eeprom;
  1014. const struct ethtool_ops *ops = dev->ethtool_ops;
  1015. void __user *userbuf = useraddr + sizeof(eeprom);
  1016. u32 bytes_remaining;
  1017. u8 *data;
  1018. int ret = 0;
  1019. if (!ops->set_eeprom || !ops->get_eeprom_len)
  1020. return -EOPNOTSUPP;
  1021. if (copy_from_user(&eeprom, useraddr, sizeof(eeprom)))
  1022. return -EFAULT;
  1023. /* Check for wrap and zero */
  1024. if (eeprom.offset + eeprom.len <= eeprom.offset)
  1025. return -EINVAL;
  1026. /* Check for exceeding total eeprom len */
  1027. if (eeprom.offset + eeprom.len > ops->get_eeprom_len(dev))
  1028. return -EINVAL;
  1029. data = kmalloc(PAGE_SIZE, GFP_USER);
  1030. if (!data)
  1031. return -ENOMEM;
  1032. bytes_remaining = eeprom.len;
  1033. while (bytes_remaining > 0) {
  1034. eeprom.len = min(bytes_remaining, (u32)PAGE_SIZE);
  1035. if (copy_from_user(data, userbuf, eeprom.len)) {
  1036. ret = -EFAULT;
  1037. break;
  1038. }
  1039. ret = ops->set_eeprom(dev, &eeprom, data);
  1040. if (ret)
  1041. break;
  1042. userbuf += eeprom.len;
  1043. eeprom.offset += eeprom.len;
  1044. bytes_remaining -= eeprom.len;
  1045. }
  1046. kfree(data);
  1047. return ret;
  1048. }
  1049. static noinline_for_stack int ethtool_get_coalesce(struct net_device *dev,
  1050. void __user *useraddr)
  1051. {
  1052. struct ethtool_coalesce coalesce = { .cmd = ETHTOOL_GCOALESCE };
  1053. if (!dev->ethtool_ops->get_coalesce)
  1054. return -EOPNOTSUPP;
  1055. dev->ethtool_ops->get_coalesce(dev, &coalesce);
  1056. if (copy_to_user(useraddr, &coalesce, sizeof(coalesce)))
  1057. return -EFAULT;
  1058. return 0;
  1059. }
  1060. static noinline_for_stack int ethtool_set_coalesce(struct net_device *dev,
  1061. void __user *useraddr)
  1062. {
  1063. struct ethtool_coalesce coalesce;
  1064. if (!dev->ethtool_ops->set_coalesce)
  1065. return -EOPNOTSUPP;
  1066. if (copy_from_user(&coalesce, useraddr, sizeof(coalesce)))
  1067. return -EFAULT;
  1068. return dev->ethtool_ops->set_coalesce(dev, &coalesce);
  1069. }
  1070. static int ethtool_get_ringparam(struct net_device *dev, void __user *useraddr)
  1071. {
  1072. struct ethtool_ringparam ringparam = { .cmd = ETHTOOL_GRINGPARAM };
  1073. if (!dev->ethtool_ops->get_ringparam)
  1074. return -EOPNOTSUPP;
  1075. dev->ethtool_ops->get_ringparam(dev, &ringparam);
  1076. if (copy_to_user(useraddr, &ringparam, sizeof(ringparam)))
  1077. return -EFAULT;
  1078. return 0;
  1079. }
  1080. static int ethtool_set_ringparam(struct net_device *dev, void __user *useraddr)
  1081. {
  1082. struct ethtool_ringparam ringparam;
  1083. if (!dev->ethtool_ops->set_ringparam)
  1084. return -EOPNOTSUPP;
  1085. if (copy_from_user(&ringparam, useraddr, sizeof(ringparam)))
  1086. return -EFAULT;
  1087. return dev->ethtool_ops->set_ringparam(dev, &ringparam);
  1088. }
  1089. static int ethtool_get_pauseparam(struct net_device *dev, void __user *useraddr)
  1090. {
  1091. struct ethtool_pauseparam pauseparam = { ETHTOOL_GPAUSEPARAM };
  1092. if (!dev->ethtool_ops->get_pauseparam)
  1093. return -EOPNOTSUPP;
  1094. dev->ethtool_ops->get_pauseparam(dev, &pauseparam);
  1095. if (copy_to_user(useraddr, &pauseparam, sizeof(pauseparam)))
  1096. return -EFAULT;
  1097. return 0;
  1098. }
  1099. static int ethtool_set_pauseparam(struct net_device *dev, void __user *useraddr)
  1100. {
  1101. struct ethtool_pauseparam pauseparam;
  1102. if (!dev->ethtool_ops->set_pauseparam)
  1103. return -EOPNOTSUPP;
  1104. if (copy_from_user(&pauseparam, useraddr, sizeof(pauseparam)))
  1105. return -EFAULT;
  1106. return dev->ethtool_ops->set_pauseparam(dev, &pauseparam);
  1107. }
  1108. static int __ethtool_set_sg(struct net_device *dev, u32 data)
  1109. {
  1110. int err;
  1111. if (data && !(dev->features & NETIF_F_ALL_CSUM))
  1112. return -EINVAL;
  1113. if (!data && dev->ethtool_ops->set_tso) {
  1114. err = dev->ethtool_ops->set_tso(dev, 0);
  1115. if (err)
  1116. return err;
  1117. }
  1118. if (!data && dev->ethtool_ops->set_ufo) {
  1119. err = dev->ethtool_ops->set_ufo(dev, 0);
  1120. if (err)
  1121. return err;
  1122. }
  1123. return dev->ethtool_ops->set_sg(dev, data);
  1124. }
  1125. static int __ethtool_set_tx_csum(struct net_device *dev, u32 data)
  1126. {
  1127. int err;
  1128. if (!dev->ethtool_ops->set_tx_csum)
  1129. return -EOPNOTSUPP;
  1130. if (!data && dev->ethtool_ops->set_sg) {
  1131. err = __ethtool_set_sg(dev, 0);
  1132. if (err)
  1133. return err;
  1134. }
  1135. return dev->ethtool_ops->set_tx_csum(dev, data);
  1136. }
  1137. static int ethtool_set_rx_csum(struct net_device *dev, char __user *useraddr)
  1138. {
  1139. struct ethtool_value edata;
  1140. if (!dev->ethtool_ops->set_rx_csum)
  1141. return -EOPNOTSUPP;
  1142. if (copy_from_user(&edata, useraddr, sizeof(edata)))
  1143. return -EFAULT;
  1144. if (!edata.data && dev->ethtool_ops->set_sg)
  1145. dev->features &= ~NETIF_F_GRO;
  1146. return dev->ethtool_ops->set_rx_csum(dev, edata.data);
  1147. }
  1148. static int __ethtool_set_tso(struct net_device *dev, u32 data)
  1149. {
  1150. if (!dev->ethtool_ops->set_tso)
  1151. return -EOPNOTSUPP;
  1152. if (data && !(dev->features & NETIF_F_SG))
  1153. return -EINVAL;
  1154. return dev->ethtool_ops->set_tso(dev, data);
  1155. }
  1156. static int __ethtool_set_ufo(struct net_device *dev, u32 data)
  1157. {
  1158. if (!dev->ethtool_ops->set_ufo)
  1159. return -EOPNOTSUPP;
  1160. if (data && !(dev->features & NETIF_F_SG))
  1161. return -EINVAL;
  1162. if (data && !((dev->features & NETIF_F_GEN_CSUM) ||
  1163. (dev->features & (NETIF_F_IP_CSUM|NETIF_F_IPV6_CSUM))
  1164. == (NETIF_F_IP_CSUM|NETIF_F_IPV6_CSUM)))
  1165. return -EINVAL;
  1166. return dev->ethtool_ops->set_ufo(dev, data);
  1167. }
  1168. static int ethtool_self_test(struct net_device *dev, char __user *useraddr)
  1169. {
  1170. struct ethtool_test test;
  1171. const struct ethtool_ops *ops = dev->ethtool_ops;
  1172. u64 *data;
  1173. int ret, test_len;
  1174. if (!ops->self_test || !ops->get_sset_count)
  1175. return -EOPNOTSUPP;
  1176. test_len = ops->get_sset_count(dev, ETH_SS_TEST);
  1177. if (test_len < 0)
  1178. return test_len;
  1179. WARN_ON(test_len == 0);
  1180. if (copy_from_user(&test, useraddr, sizeof(test)))
  1181. return -EFAULT;
  1182. test.len = test_len;
  1183. data = kmalloc(test_len * sizeof(u64), GFP_USER);
  1184. if (!data)
  1185. return -ENOMEM;
  1186. ops->self_test(dev, &test, data);
  1187. ret = -EFAULT;
  1188. if (copy_to_user(useraddr, &test, sizeof(test)))
  1189. goto out;
  1190. useraddr += sizeof(test);
  1191. if (copy_to_user(useraddr, data, test.len * sizeof(u64)))
  1192. goto out;
  1193. ret = 0;
  1194. out:
  1195. kfree(data);
  1196. return ret;
  1197. }
  1198. static int ethtool_get_strings(struct net_device *dev, void __user *useraddr)
  1199. {
  1200. struct ethtool_gstrings gstrings;
  1201. u8 *data;
  1202. int ret;
  1203. if (copy_from_user(&gstrings, useraddr, sizeof(gstrings)))
  1204. return -EFAULT;
  1205. ret = __ethtool_get_sset_count(dev, gstrings.string_set);
  1206. if (ret < 0)
  1207. return ret;
  1208. gstrings.len = ret;
  1209. data = kmalloc(gstrings.len * ETH_GSTRING_LEN, GFP_USER);
  1210. if (!data)
  1211. return -ENOMEM;
  1212. __ethtool_get_strings(dev, gstrings.string_set, data);
  1213. ret = -EFAULT;
  1214. if (copy_to_user(useraddr, &gstrings, sizeof(gstrings)))
  1215. goto out;
  1216. useraddr += sizeof(gstrings);
  1217. if (copy_to_user(useraddr, data, gstrings.len * ETH_GSTRING_LEN))
  1218. goto out;
  1219. ret = 0;
  1220. out:
  1221. kfree(data);
  1222. return ret;
  1223. }
  1224. static int ethtool_phys_id(struct net_device *dev, void __user *useraddr)
  1225. {
  1226. struct ethtool_value id;
  1227. if (!dev->ethtool_ops->phys_id)
  1228. return -EOPNOTSUPP;
  1229. if (copy_from_user(&id, useraddr, sizeof(id)))
  1230. return -EFAULT;
  1231. return dev->ethtool_ops->phys_id(dev, id.data);
  1232. }
  1233. static int ethtool_get_stats(struct net_device *dev, void __user *useraddr)
  1234. {
  1235. struct ethtool_stats stats;
  1236. const struct ethtool_ops *ops = dev->ethtool_ops;
  1237. u64 *data;
  1238. int ret, n_stats;
  1239. if (!ops->get_ethtool_stats || !ops->get_sset_count)
  1240. return -EOPNOTSUPP;
  1241. n_stats = ops->get_sset_count(dev, ETH_SS_STATS);
  1242. if (n_stats < 0)
  1243. return n_stats;
  1244. WARN_ON(n_stats == 0);
  1245. if (copy_from_user(&stats, useraddr, sizeof(stats)))
  1246. return -EFAULT;
  1247. stats.n_stats = n_stats;
  1248. data = kmalloc(n_stats * sizeof(u64), GFP_USER);
  1249. if (!data)
  1250. return -ENOMEM;
  1251. ops->get_ethtool_stats(dev, &stats, data);
  1252. ret = -EFAULT;
  1253. if (copy_to_user(useraddr, &stats, sizeof(stats)))
  1254. goto out;
  1255. useraddr += sizeof(stats);
  1256. if (copy_to_user(useraddr, data, stats.n_stats * sizeof(u64)))
  1257. goto out;
  1258. ret = 0;
  1259. out:
  1260. kfree(data);
  1261. return ret;
  1262. }
  1263. static int ethtool_get_perm_addr(struct net_device *dev, void __user *useraddr)
  1264. {
  1265. struct ethtool_perm_addr epaddr;
  1266. if (copy_from_user(&epaddr, useraddr, sizeof(epaddr)))
  1267. return -EFAULT;
  1268. if (epaddr.size < dev->addr_len)
  1269. return -ETOOSMALL;
  1270. epaddr.size = dev->addr_len;
  1271. if (copy_to_user(useraddr, &epaddr, sizeof(epaddr)))
  1272. return -EFAULT;
  1273. useraddr += sizeof(epaddr);
  1274. if (copy_to_user(useraddr, dev->perm_addr, epaddr.size))
  1275. return -EFAULT;
  1276. return 0;
  1277. }
  1278. static int ethtool_get_value(struct net_device *dev, char __user *useraddr,
  1279. u32 cmd, u32 (*actor)(struct net_device *))
  1280. {
  1281. struct ethtool_value edata = { .cmd = cmd };
  1282. if (!actor)
  1283. return -EOPNOTSUPP;
  1284. edata.data = actor(dev);
  1285. if (copy_to_user(useraddr, &edata, sizeof(edata)))
  1286. return -EFAULT;
  1287. return 0;
  1288. }
  1289. static int ethtool_set_value_void(struct net_device *dev, char __user *useraddr,
  1290. void (*actor)(struct net_device *, u32))
  1291. {
  1292. struct ethtool_value edata;
  1293. if (!actor)
  1294. return -EOPNOTSUPP;
  1295. if (copy_from_user(&edata, useraddr, sizeof(edata)))
  1296. return -EFAULT;
  1297. actor(dev, edata.data);
  1298. return 0;
  1299. }
  1300. static int ethtool_set_value(struct net_device *dev, char __user *useraddr,
  1301. int (*actor)(struct net_device *, u32))
  1302. {
  1303. struct ethtool_value edata;
  1304. if (!actor)
  1305. return -EOPNOTSUPP;
  1306. if (copy_from_user(&edata, useraddr, sizeof(edata)))
  1307. return -EFAULT;
  1308. return actor(dev, edata.data);
  1309. }
  1310. static noinline_for_stack int ethtool_flash_device(struct net_device *dev,
  1311. char __user *useraddr)
  1312. {
  1313. struct ethtool_flash efl;
  1314. if (copy_from_user(&efl, useraddr, sizeof(efl)))
  1315. return -EFAULT;
  1316. if (!dev->ethtool_ops->flash_device)
  1317. return -EOPNOTSUPP;
  1318. return dev->ethtool_ops->flash_device(dev, &efl);
  1319. }
  1320. /* The main entry point in this file. Called from net/core/dev.c */
  1321. int dev_ethtool(struct net *net, struct ifreq *ifr)
  1322. {
  1323. struct net_device *dev = __dev_get_by_name(net, ifr->ifr_name);
  1324. void __user *useraddr = ifr->ifr_data;
  1325. u32 ethcmd;
  1326. int rc;
  1327. u32 old_features;
  1328. if (!dev || !netif_device_present(dev))
  1329. return -ENODEV;
  1330. if (copy_from_user(&ethcmd, useraddr, sizeof(ethcmd)))
  1331. return -EFAULT;
  1332. if (!dev->ethtool_ops) {
  1333. /* ETHTOOL_GDRVINFO does not require any driver support.
  1334. * It is also unprivileged and does not change anything,
  1335. * so we can take a shortcut to it. */
  1336. if (ethcmd == ETHTOOL_GDRVINFO)
  1337. return ethtool_get_drvinfo(dev, useraddr);
  1338. else
  1339. return -EOPNOTSUPP;
  1340. }
  1341. /* Allow some commands to be done by anyone */
  1342. switch (ethcmd) {
  1343. case ETHTOOL_GSET:
  1344. case ETHTOOL_GDRVINFO:
  1345. case ETHTOOL_GMSGLVL:
  1346. case ETHTOOL_GCOALESCE:
  1347. case ETHTOOL_GRINGPARAM:
  1348. case ETHTOOL_GPAUSEPARAM:
  1349. case ETHTOOL_GRXCSUM:
  1350. case ETHTOOL_GTXCSUM:
  1351. case ETHTOOL_GSG:
  1352. case ETHTOOL_GSTRINGS:
  1353. case ETHTOOL_GTSO:
  1354. case ETHTOOL_GPERMADDR:
  1355. case ETHTOOL_GUFO:
  1356. case ETHTOOL_GGSO:
  1357. case ETHTOOL_GGRO:
  1358. case ETHTOOL_GFLAGS:
  1359. case ETHTOOL_GPFLAGS:
  1360. case ETHTOOL_GRXFH:
  1361. case ETHTOOL_GRXRINGS:
  1362. case ETHTOOL_GRXCLSRLCNT:
  1363. case ETHTOOL_GRXCLSRULE:
  1364. case ETHTOOL_GRXCLSRLALL:
  1365. case ETHTOOL_GFEATURES:
  1366. break;
  1367. default:
  1368. if (!capable(CAP_NET_ADMIN))
  1369. return -EPERM;
  1370. }
  1371. if (dev->ethtool_ops->begin) {
  1372. rc = dev->ethtool_ops->begin(dev);
  1373. if (rc < 0)
  1374. return rc;
  1375. }
  1376. old_features = dev->features;
  1377. switch (ethcmd) {
  1378. case ETHTOOL_GSET:
  1379. rc = ethtool_get_settings(dev, useraddr);
  1380. break;
  1381. case ETHTOOL_SSET:
  1382. rc = ethtool_set_settings(dev, useraddr);
  1383. break;
  1384. case ETHTOOL_GDRVINFO:
  1385. rc = ethtool_get_drvinfo(dev, useraddr);
  1386. break;
  1387. case ETHTOOL_GREGS:
  1388. rc = ethtool_get_regs(dev, useraddr);
  1389. break;
  1390. case ETHTOOL_GWOL:
  1391. rc = ethtool_get_wol(dev, useraddr);
  1392. break;
  1393. case ETHTOOL_SWOL:
  1394. rc = ethtool_set_wol(dev, useraddr);
  1395. break;
  1396. case ETHTOOL_GMSGLVL:
  1397. rc = ethtool_get_value(dev, useraddr, ethcmd,
  1398. dev->ethtool_ops->get_msglevel);
  1399. break;
  1400. case ETHTOOL_SMSGLVL:
  1401. rc = ethtool_set_value_void(dev, useraddr,
  1402. dev->ethtool_ops->set_msglevel);
  1403. break;
  1404. case ETHTOOL_NWAY_RST:
  1405. rc = ethtool_nway_reset(dev);
  1406. break;
  1407. case ETHTOOL_GLINK:
  1408. rc = ethtool_get_link(dev, useraddr);
  1409. break;
  1410. case ETHTOOL_GEEPROM:
  1411. rc = ethtool_get_eeprom(dev, useraddr);
  1412. break;
  1413. case ETHTOOL_SEEPROM:
  1414. rc = ethtool_set_eeprom(dev, useraddr);
  1415. break;
  1416. case ETHTOOL_GCOALESCE:
  1417. rc = ethtool_get_coalesce(dev, useraddr);
  1418. break;
  1419. case ETHTOOL_SCOALESCE:
  1420. rc = ethtool_set_coalesce(dev, useraddr);
  1421. break;
  1422. case ETHTOOL_GRINGPARAM:
  1423. rc = ethtool_get_ringparam(dev, useraddr);
  1424. break;
  1425. case ETHTOOL_SRINGPARAM:
  1426. rc = ethtool_set_ringparam(dev, useraddr);
  1427. break;
  1428. case ETHTOOL_GPAUSEPARAM:
  1429. rc = ethtool_get_pauseparam(dev, useraddr);
  1430. break;
  1431. case ETHTOOL_SPAUSEPARAM:
  1432. rc = ethtool_set_pauseparam(dev, useraddr);
  1433. break;
  1434. case ETHTOOL_GRXCSUM:
  1435. rc = ethtool_get_value(dev, useraddr, ethcmd,
  1436. (dev->ethtool_ops->get_rx_csum ?
  1437. dev->ethtool_ops->get_rx_csum :
  1438. ethtool_op_get_rx_csum));
  1439. break;
  1440. case ETHTOOL_SRXCSUM:
  1441. rc = ethtool_set_rx_csum(dev, useraddr);
  1442. break;
  1443. case ETHTOOL_TEST:
  1444. rc = ethtool_self_test(dev, useraddr);
  1445. break;
  1446. case ETHTOOL_GSTRINGS:
  1447. rc = ethtool_get_strings(dev, useraddr);
  1448. break;
  1449. case ETHTOOL_PHYS_ID:
  1450. rc = ethtool_phys_id(dev, useraddr);
  1451. break;
  1452. case ETHTOOL_GSTATS:
  1453. rc = ethtool_get_stats(dev, useraddr);
  1454. break;
  1455. case ETHTOOL_GPERMADDR:
  1456. rc = ethtool_get_perm_addr(dev, useraddr);
  1457. break;
  1458. case ETHTOOL_GFLAGS:
  1459. rc = ethtool_get_value(dev, useraddr, ethcmd,
  1460. (dev->ethtool_ops->get_flags ?
  1461. dev->ethtool_ops->get_flags :
  1462. ethtool_op_get_flags));
  1463. break;
  1464. case ETHTOOL_SFLAGS:
  1465. rc = ethtool_set_value(dev, useraddr,
  1466. dev->ethtool_ops->set_flags);
  1467. break;
  1468. case ETHTOOL_GPFLAGS:
  1469. rc = ethtool_get_value(dev, useraddr, ethcmd,
  1470. dev->ethtool_ops->get_priv_flags);
  1471. break;
  1472. case ETHTOOL_SPFLAGS:
  1473. rc = ethtool_set_value(dev, useraddr,
  1474. dev->ethtool_ops->set_priv_flags);
  1475. break;
  1476. case ETHTOOL_GRXFH:
  1477. case ETHTOOL_GRXRINGS:
  1478. case ETHTOOL_GRXCLSRLCNT:
  1479. case ETHTOOL_GRXCLSRULE:
  1480. case ETHTOOL_GRXCLSRLALL:
  1481. rc = ethtool_get_rxnfc(dev, ethcmd, useraddr);
  1482. break;
  1483. case ETHTOOL_SRXFH:
  1484. case ETHTOOL_SRXCLSRLDEL:
  1485. case ETHTOOL_SRXCLSRLINS:
  1486. rc = ethtool_set_rxnfc(dev, ethcmd, useraddr);
  1487. break;
  1488. case ETHTOOL_FLASHDEV:
  1489. rc = ethtool_flash_device(dev, useraddr);
  1490. break;
  1491. case ETHTOOL_RESET:
  1492. rc = ethtool_reset(dev, useraddr);
  1493. break;
  1494. case ETHTOOL_SRXNTUPLE:
  1495. rc = ethtool_set_rx_ntuple(dev, useraddr);
  1496. break;
  1497. case ETHTOOL_GRXNTUPLE:
  1498. rc = ethtool_get_rx_ntuple(dev, useraddr);
  1499. break;
  1500. case ETHTOOL_GSSET_INFO:
  1501. rc = ethtool_get_sset_info(dev, useraddr);
  1502. break;
  1503. case ETHTOOL_GRXFHINDIR:
  1504. rc = ethtool_get_rxfh_indir(dev, useraddr);
  1505. break;
  1506. case ETHTOOL_SRXFHINDIR:
  1507. rc = ethtool_set_rxfh_indir(dev, useraddr);
  1508. break;
  1509. case ETHTOOL_GFEATURES:
  1510. rc = ethtool_get_features(dev, useraddr);
  1511. break;
  1512. case ETHTOOL_SFEATURES:
  1513. rc = ethtool_set_features(dev, useraddr);
  1514. break;
  1515. case ETHTOOL_GTXCSUM:
  1516. case ETHTOOL_GSG:
  1517. case ETHTOOL_GTSO:
  1518. case ETHTOOL_GUFO:
  1519. case ETHTOOL_GGSO:
  1520. case ETHTOOL_GGRO:
  1521. rc = ethtool_get_one_feature(dev, useraddr, ethcmd);
  1522. break;
  1523. case ETHTOOL_STXCSUM:
  1524. case ETHTOOL_SSG:
  1525. case ETHTOOL_STSO:
  1526. case ETHTOOL_SUFO:
  1527. case ETHTOOL_SGSO:
  1528. case ETHTOOL_SGRO:
  1529. rc = ethtool_set_one_feature(dev, useraddr, ethcmd);
  1530. break;
  1531. default:
  1532. rc = -EOPNOTSUPP;
  1533. }
  1534. if (dev->ethtool_ops->complete)
  1535. dev->ethtool_ops->complete(dev);
  1536. if (old_features != dev->features)
  1537. netdev_features_change(dev);
  1538. return rc;
  1539. }