ethtool.c 44 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848
  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. u32 mask = ethtool_get_feature_mask(ethcmd);
  304. struct ethtool_value edata = {
  305. .cmd = ethcmd,
  306. .data = !!(dev->features & mask),
  307. };
  308. /* compatibility with discrete get_ ops */
  309. if (!(dev->hw_features & mask)) {
  310. u32 (*actor)(struct net_device *);
  311. actor = __ethtool_get_one_feature_actor(dev, ethcmd);
  312. if (actor)
  313. edata.data = actor(dev);
  314. }
  315. if (copy_to_user(useraddr, &edata, sizeof(edata)))
  316. return -EFAULT;
  317. return 0;
  318. }
  319. static int __ethtool_set_tx_csum(struct net_device *dev, u32 data);
  320. static int __ethtool_set_sg(struct net_device *dev, u32 data);
  321. static int __ethtool_set_tso(struct net_device *dev, u32 data);
  322. static int __ethtool_set_ufo(struct net_device *dev, u32 data);
  323. static int ethtool_set_one_feature(struct net_device *dev,
  324. void __user *useraddr, u32 ethcmd)
  325. {
  326. struct ethtool_value edata;
  327. u32 mask;
  328. if (copy_from_user(&edata, useraddr, sizeof(edata)))
  329. return -EFAULT;
  330. mask = ethtool_get_feature_mask(ethcmd);
  331. mask &= dev->hw_features;
  332. if (mask) {
  333. if (edata.data)
  334. dev->wanted_features |= mask;
  335. else
  336. dev->wanted_features &= ~mask;
  337. netdev_update_features(dev);
  338. return 0;
  339. }
  340. /* Driver is not converted to ndo_fix_features or does not
  341. * support changing this offload. In the latter case it won't
  342. * have corresponding ethtool_ops field set.
  343. *
  344. * Following part is to be removed after all drivers advertise
  345. * their changeable features in netdev->hw_features and stop
  346. * using discrete offload setting ops.
  347. */
  348. switch (ethcmd) {
  349. case ETHTOOL_STXCSUM:
  350. return __ethtool_set_tx_csum(dev, edata.data);
  351. case ETHTOOL_SSG:
  352. return __ethtool_set_sg(dev, edata.data);
  353. case ETHTOOL_STSO:
  354. return __ethtool_set_tso(dev, edata.data);
  355. case ETHTOOL_SUFO:
  356. return __ethtool_set_ufo(dev, edata.data);
  357. default:
  358. return -EOPNOTSUPP;
  359. }
  360. }
  361. static int ethtool_get_settings(struct net_device *dev, void __user *useraddr)
  362. {
  363. struct ethtool_cmd cmd = { .cmd = ETHTOOL_GSET };
  364. int err;
  365. if (!dev->ethtool_ops->get_settings)
  366. return -EOPNOTSUPP;
  367. err = dev->ethtool_ops->get_settings(dev, &cmd);
  368. if (err < 0)
  369. return err;
  370. if (copy_to_user(useraddr, &cmd, sizeof(cmd)))
  371. return -EFAULT;
  372. return 0;
  373. }
  374. static int ethtool_set_settings(struct net_device *dev, void __user *useraddr)
  375. {
  376. struct ethtool_cmd cmd;
  377. if (!dev->ethtool_ops->set_settings)
  378. return -EOPNOTSUPP;
  379. if (copy_from_user(&cmd, useraddr, sizeof(cmd)))
  380. return -EFAULT;
  381. return dev->ethtool_ops->set_settings(dev, &cmd);
  382. }
  383. static noinline_for_stack int ethtool_get_drvinfo(struct net_device *dev,
  384. void __user *useraddr)
  385. {
  386. struct ethtool_drvinfo info;
  387. const struct ethtool_ops *ops = dev->ethtool_ops;
  388. memset(&info, 0, sizeof(info));
  389. info.cmd = ETHTOOL_GDRVINFO;
  390. if (ops && ops->get_drvinfo) {
  391. ops->get_drvinfo(dev, &info);
  392. } else if (dev->dev.parent && dev->dev.parent->driver) {
  393. strlcpy(info.bus_info, dev_name(dev->dev.parent),
  394. sizeof(info.bus_info));
  395. strlcpy(info.driver, dev->dev.parent->driver->name,
  396. sizeof(info.driver));
  397. } else {
  398. return -EOPNOTSUPP;
  399. }
  400. /*
  401. * this method of obtaining string set info is deprecated;
  402. * Use ETHTOOL_GSSET_INFO instead.
  403. */
  404. if (ops && ops->get_sset_count) {
  405. int rc;
  406. rc = ops->get_sset_count(dev, ETH_SS_TEST);
  407. if (rc >= 0)
  408. info.testinfo_len = rc;
  409. rc = ops->get_sset_count(dev, ETH_SS_STATS);
  410. if (rc >= 0)
  411. info.n_stats = rc;
  412. rc = ops->get_sset_count(dev, ETH_SS_PRIV_FLAGS);
  413. if (rc >= 0)
  414. info.n_priv_flags = rc;
  415. }
  416. if (ops && ops->get_regs_len)
  417. info.regdump_len = ops->get_regs_len(dev);
  418. if (ops && ops->get_eeprom_len)
  419. info.eedump_len = ops->get_eeprom_len(dev);
  420. if (copy_to_user(useraddr, &info, sizeof(info)))
  421. return -EFAULT;
  422. return 0;
  423. }
  424. static noinline_for_stack int ethtool_get_sset_info(struct net_device *dev,
  425. void __user *useraddr)
  426. {
  427. struct ethtool_sset_info info;
  428. u64 sset_mask;
  429. int i, idx = 0, n_bits = 0, ret, rc;
  430. u32 *info_buf = NULL;
  431. if (copy_from_user(&info, useraddr, sizeof(info)))
  432. return -EFAULT;
  433. /* store copy of mask, because we zero struct later on */
  434. sset_mask = info.sset_mask;
  435. if (!sset_mask)
  436. return 0;
  437. /* calculate size of return buffer */
  438. n_bits = hweight64(sset_mask);
  439. memset(&info, 0, sizeof(info));
  440. info.cmd = ETHTOOL_GSSET_INFO;
  441. info_buf = kzalloc(n_bits * sizeof(u32), GFP_USER);
  442. if (!info_buf)
  443. return -ENOMEM;
  444. /*
  445. * fill return buffer based on input bitmask and successful
  446. * get_sset_count return
  447. */
  448. for (i = 0; i < 64; i++) {
  449. if (!(sset_mask & (1ULL << i)))
  450. continue;
  451. rc = __ethtool_get_sset_count(dev, i);
  452. if (rc >= 0) {
  453. info.sset_mask |= (1ULL << i);
  454. info_buf[idx++] = rc;
  455. }
  456. }
  457. ret = -EFAULT;
  458. if (copy_to_user(useraddr, &info, sizeof(info)))
  459. goto out;
  460. useraddr += offsetof(struct ethtool_sset_info, data);
  461. if (copy_to_user(useraddr, info_buf, idx * sizeof(u32)))
  462. goto out;
  463. ret = 0;
  464. out:
  465. kfree(info_buf);
  466. return ret;
  467. }
  468. static noinline_for_stack int ethtool_set_rxnfc(struct net_device *dev,
  469. u32 cmd, void __user *useraddr)
  470. {
  471. struct ethtool_rxnfc info;
  472. size_t info_size = sizeof(info);
  473. if (!dev->ethtool_ops->set_rxnfc)
  474. return -EOPNOTSUPP;
  475. /* struct ethtool_rxnfc was originally defined for
  476. * ETHTOOL_{G,S}RXFH with only the cmd, flow_type and data
  477. * members. User-space might still be using that
  478. * definition. */
  479. if (cmd == ETHTOOL_SRXFH)
  480. info_size = (offsetof(struct ethtool_rxnfc, data) +
  481. sizeof(info.data));
  482. if (copy_from_user(&info, useraddr, info_size))
  483. return -EFAULT;
  484. return dev->ethtool_ops->set_rxnfc(dev, &info);
  485. }
  486. static noinline_for_stack int ethtool_get_rxnfc(struct net_device *dev,
  487. u32 cmd, void __user *useraddr)
  488. {
  489. struct ethtool_rxnfc info;
  490. size_t info_size = sizeof(info);
  491. const struct ethtool_ops *ops = dev->ethtool_ops;
  492. int ret;
  493. void *rule_buf = NULL;
  494. if (!ops->get_rxnfc)
  495. return -EOPNOTSUPP;
  496. /* struct ethtool_rxnfc was originally defined for
  497. * ETHTOOL_{G,S}RXFH with only the cmd, flow_type and data
  498. * members. User-space might still be using that
  499. * definition. */
  500. if (cmd == ETHTOOL_GRXFH)
  501. info_size = (offsetof(struct ethtool_rxnfc, data) +
  502. sizeof(info.data));
  503. if (copy_from_user(&info, useraddr, info_size))
  504. return -EFAULT;
  505. if (info.cmd == ETHTOOL_GRXCLSRLALL) {
  506. if (info.rule_cnt > 0) {
  507. if (info.rule_cnt <= KMALLOC_MAX_SIZE / sizeof(u32))
  508. rule_buf = kzalloc(info.rule_cnt * sizeof(u32),
  509. GFP_USER);
  510. if (!rule_buf)
  511. return -ENOMEM;
  512. }
  513. }
  514. ret = ops->get_rxnfc(dev, &info, rule_buf);
  515. if (ret < 0)
  516. goto err_out;
  517. ret = -EFAULT;
  518. if (copy_to_user(useraddr, &info, info_size))
  519. goto err_out;
  520. if (rule_buf) {
  521. useraddr += offsetof(struct ethtool_rxnfc, rule_locs);
  522. if (copy_to_user(useraddr, rule_buf,
  523. info.rule_cnt * sizeof(u32)))
  524. goto err_out;
  525. }
  526. ret = 0;
  527. err_out:
  528. kfree(rule_buf);
  529. return ret;
  530. }
  531. static noinline_for_stack int ethtool_get_rxfh_indir(struct net_device *dev,
  532. void __user *useraddr)
  533. {
  534. struct ethtool_rxfh_indir *indir;
  535. u32 table_size;
  536. size_t full_size;
  537. int ret;
  538. if (!dev->ethtool_ops->get_rxfh_indir)
  539. return -EOPNOTSUPP;
  540. if (copy_from_user(&table_size,
  541. useraddr + offsetof(struct ethtool_rxfh_indir, size),
  542. sizeof(table_size)))
  543. return -EFAULT;
  544. if (table_size >
  545. (KMALLOC_MAX_SIZE - sizeof(*indir)) / sizeof(*indir->ring_index))
  546. return -ENOMEM;
  547. full_size = sizeof(*indir) + sizeof(*indir->ring_index) * table_size;
  548. indir = kzalloc(full_size, GFP_USER);
  549. if (!indir)
  550. return -ENOMEM;
  551. indir->cmd = ETHTOOL_GRXFHINDIR;
  552. indir->size = table_size;
  553. ret = dev->ethtool_ops->get_rxfh_indir(dev, indir);
  554. if (ret)
  555. goto out;
  556. if (copy_to_user(useraddr, indir, full_size))
  557. ret = -EFAULT;
  558. out:
  559. kfree(indir);
  560. return ret;
  561. }
  562. static noinline_for_stack int ethtool_set_rxfh_indir(struct net_device *dev,
  563. void __user *useraddr)
  564. {
  565. struct ethtool_rxfh_indir *indir;
  566. u32 table_size;
  567. size_t full_size;
  568. int ret;
  569. if (!dev->ethtool_ops->set_rxfh_indir)
  570. return -EOPNOTSUPP;
  571. if (copy_from_user(&table_size,
  572. useraddr + offsetof(struct ethtool_rxfh_indir, size),
  573. sizeof(table_size)))
  574. return -EFAULT;
  575. if (table_size >
  576. (KMALLOC_MAX_SIZE - sizeof(*indir)) / sizeof(*indir->ring_index))
  577. return -ENOMEM;
  578. full_size = sizeof(*indir) + sizeof(*indir->ring_index) * table_size;
  579. indir = kmalloc(full_size, GFP_USER);
  580. if (!indir)
  581. return -ENOMEM;
  582. if (copy_from_user(indir, useraddr, full_size)) {
  583. ret = -EFAULT;
  584. goto out;
  585. }
  586. ret = dev->ethtool_ops->set_rxfh_indir(dev, indir);
  587. out:
  588. kfree(indir);
  589. return ret;
  590. }
  591. static void __rx_ntuple_filter_add(struct ethtool_rx_ntuple_list *list,
  592. struct ethtool_rx_ntuple_flow_spec *spec,
  593. struct ethtool_rx_ntuple_flow_spec_container *fsc)
  594. {
  595. /* don't add filters forever */
  596. if (list->count >= ETHTOOL_MAX_NTUPLE_LIST_ENTRY) {
  597. /* free the container */
  598. kfree(fsc);
  599. return;
  600. }
  601. /* Copy the whole filter over */
  602. fsc->fs.flow_type = spec->flow_type;
  603. memcpy(&fsc->fs.h_u, &spec->h_u, sizeof(spec->h_u));
  604. memcpy(&fsc->fs.m_u, &spec->m_u, sizeof(spec->m_u));
  605. fsc->fs.vlan_tag = spec->vlan_tag;
  606. fsc->fs.vlan_tag_mask = spec->vlan_tag_mask;
  607. fsc->fs.data = spec->data;
  608. fsc->fs.data_mask = spec->data_mask;
  609. fsc->fs.action = spec->action;
  610. /* add to the list */
  611. list_add_tail_rcu(&fsc->list, &list->list);
  612. list->count++;
  613. }
  614. /*
  615. * ethtool does not (or did not) set masks for flow parameters that are
  616. * not specified, so if both value and mask are 0 then this must be
  617. * treated as equivalent to a mask with all bits set. Implement that
  618. * here rather than in drivers.
  619. */
  620. static void rx_ntuple_fix_masks(struct ethtool_rx_ntuple_flow_spec *fs)
  621. {
  622. struct ethtool_tcpip4_spec *entry = &fs->h_u.tcp_ip4_spec;
  623. struct ethtool_tcpip4_spec *mask = &fs->m_u.tcp_ip4_spec;
  624. if (fs->flow_type != TCP_V4_FLOW &&
  625. fs->flow_type != UDP_V4_FLOW &&
  626. fs->flow_type != SCTP_V4_FLOW)
  627. return;
  628. if (!(entry->ip4src | mask->ip4src))
  629. mask->ip4src = htonl(0xffffffff);
  630. if (!(entry->ip4dst | mask->ip4dst))
  631. mask->ip4dst = htonl(0xffffffff);
  632. if (!(entry->psrc | mask->psrc))
  633. mask->psrc = htons(0xffff);
  634. if (!(entry->pdst | mask->pdst))
  635. mask->pdst = htons(0xffff);
  636. if (!(entry->tos | mask->tos))
  637. mask->tos = 0xff;
  638. if (!(fs->vlan_tag | fs->vlan_tag_mask))
  639. fs->vlan_tag_mask = 0xffff;
  640. if (!(fs->data | fs->data_mask))
  641. fs->data_mask = 0xffffffffffffffffULL;
  642. }
  643. static noinline_for_stack int ethtool_set_rx_ntuple(struct net_device *dev,
  644. void __user *useraddr)
  645. {
  646. struct ethtool_rx_ntuple cmd;
  647. const struct ethtool_ops *ops = dev->ethtool_ops;
  648. struct ethtool_rx_ntuple_flow_spec_container *fsc = NULL;
  649. int ret;
  650. if (!(dev->features & NETIF_F_NTUPLE))
  651. return -EINVAL;
  652. if (copy_from_user(&cmd, useraddr, sizeof(cmd)))
  653. return -EFAULT;
  654. rx_ntuple_fix_masks(&cmd.fs);
  655. /*
  656. * Cache filter in dev struct for GET operation only if
  657. * the underlying driver doesn't have its own GET operation, and
  658. * only if the filter was added successfully. First make sure we
  659. * can allocate the filter, then continue if successful.
  660. */
  661. if (!ops->get_rx_ntuple) {
  662. fsc = kmalloc(sizeof(*fsc), GFP_ATOMIC);
  663. if (!fsc)
  664. return -ENOMEM;
  665. }
  666. ret = ops->set_rx_ntuple(dev, &cmd);
  667. if (ret) {
  668. kfree(fsc);
  669. return ret;
  670. }
  671. if (!ops->get_rx_ntuple)
  672. __rx_ntuple_filter_add(&dev->ethtool_ntuple_list, &cmd.fs, fsc);
  673. return ret;
  674. }
  675. static int ethtool_get_rx_ntuple(struct net_device *dev, void __user *useraddr)
  676. {
  677. struct ethtool_gstrings gstrings;
  678. const struct ethtool_ops *ops = dev->ethtool_ops;
  679. struct ethtool_rx_ntuple_flow_spec_container *fsc;
  680. u8 *data;
  681. char *p;
  682. int ret, i, num_strings = 0;
  683. if (!ops->get_sset_count)
  684. return -EOPNOTSUPP;
  685. if (copy_from_user(&gstrings, useraddr, sizeof(gstrings)))
  686. return -EFAULT;
  687. ret = ops->get_sset_count(dev, gstrings.string_set);
  688. if (ret < 0)
  689. return ret;
  690. gstrings.len = ret;
  691. data = kzalloc(gstrings.len * ETH_GSTRING_LEN, GFP_USER);
  692. if (!data)
  693. return -ENOMEM;
  694. if (ops->get_rx_ntuple) {
  695. /* driver-specific filter grab */
  696. ret = ops->get_rx_ntuple(dev, gstrings.string_set, data);
  697. goto copy;
  698. }
  699. /* default ethtool filter grab */
  700. i = 0;
  701. p = (char *)data;
  702. list_for_each_entry(fsc, &dev->ethtool_ntuple_list.list, list) {
  703. sprintf(p, "Filter %d:\n", i);
  704. p += ETH_GSTRING_LEN;
  705. num_strings++;
  706. switch (fsc->fs.flow_type) {
  707. case TCP_V4_FLOW:
  708. sprintf(p, "\tFlow Type: TCP\n");
  709. p += ETH_GSTRING_LEN;
  710. num_strings++;
  711. break;
  712. case UDP_V4_FLOW:
  713. sprintf(p, "\tFlow Type: UDP\n");
  714. p += ETH_GSTRING_LEN;
  715. num_strings++;
  716. break;
  717. case SCTP_V4_FLOW:
  718. sprintf(p, "\tFlow Type: SCTP\n");
  719. p += ETH_GSTRING_LEN;
  720. num_strings++;
  721. break;
  722. case AH_ESP_V4_FLOW:
  723. sprintf(p, "\tFlow Type: AH ESP\n");
  724. p += ETH_GSTRING_LEN;
  725. num_strings++;
  726. break;
  727. case ESP_V4_FLOW:
  728. sprintf(p, "\tFlow Type: ESP\n");
  729. p += ETH_GSTRING_LEN;
  730. num_strings++;
  731. break;
  732. case IP_USER_FLOW:
  733. sprintf(p, "\tFlow Type: Raw IP\n");
  734. p += ETH_GSTRING_LEN;
  735. num_strings++;
  736. break;
  737. case IPV4_FLOW:
  738. sprintf(p, "\tFlow Type: IPv4\n");
  739. p += ETH_GSTRING_LEN;
  740. num_strings++;
  741. break;
  742. default:
  743. sprintf(p, "\tFlow Type: Unknown\n");
  744. p += ETH_GSTRING_LEN;
  745. num_strings++;
  746. goto unknown_filter;
  747. }
  748. /* now the rest of the filters */
  749. switch (fsc->fs.flow_type) {
  750. case TCP_V4_FLOW:
  751. case UDP_V4_FLOW:
  752. case SCTP_V4_FLOW:
  753. sprintf(p, "\tSrc IP addr: 0x%x\n",
  754. fsc->fs.h_u.tcp_ip4_spec.ip4src);
  755. p += ETH_GSTRING_LEN;
  756. num_strings++;
  757. sprintf(p, "\tSrc IP mask: 0x%x\n",
  758. fsc->fs.m_u.tcp_ip4_spec.ip4src);
  759. p += ETH_GSTRING_LEN;
  760. num_strings++;
  761. sprintf(p, "\tDest IP addr: 0x%x\n",
  762. fsc->fs.h_u.tcp_ip4_spec.ip4dst);
  763. p += ETH_GSTRING_LEN;
  764. num_strings++;
  765. sprintf(p, "\tDest IP mask: 0x%x\n",
  766. fsc->fs.m_u.tcp_ip4_spec.ip4dst);
  767. p += ETH_GSTRING_LEN;
  768. num_strings++;
  769. sprintf(p, "\tSrc Port: %d, mask: 0x%x\n",
  770. fsc->fs.h_u.tcp_ip4_spec.psrc,
  771. fsc->fs.m_u.tcp_ip4_spec.psrc);
  772. p += ETH_GSTRING_LEN;
  773. num_strings++;
  774. sprintf(p, "\tDest Port: %d, mask: 0x%x\n",
  775. fsc->fs.h_u.tcp_ip4_spec.pdst,
  776. fsc->fs.m_u.tcp_ip4_spec.pdst);
  777. p += ETH_GSTRING_LEN;
  778. num_strings++;
  779. sprintf(p, "\tTOS: %d, mask: 0x%x\n",
  780. fsc->fs.h_u.tcp_ip4_spec.tos,
  781. fsc->fs.m_u.tcp_ip4_spec.tos);
  782. p += ETH_GSTRING_LEN;
  783. num_strings++;
  784. break;
  785. case AH_ESP_V4_FLOW:
  786. case ESP_V4_FLOW:
  787. sprintf(p, "\tSrc IP addr: 0x%x\n",
  788. fsc->fs.h_u.ah_ip4_spec.ip4src);
  789. p += ETH_GSTRING_LEN;
  790. num_strings++;
  791. sprintf(p, "\tSrc IP mask: 0x%x\n",
  792. fsc->fs.m_u.ah_ip4_spec.ip4src);
  793. p += ETH_GSTRING_LEN;
  794. num_strings++;
  795. sprintf(p, "\tDest IP addr: 0x%x\n",
  796. fsc->fs.h_u.ah_ip4_spec.ip4dst);
  797. p += ETH_GSTRING_LEN;
  798. num_strings++;
  799. sprintf(p, "\tDest IP mask: 0x%x\n",
  800. fsc->fs.m_u.ah_ip4_spec.ip4dst);
  801. p += ETH_GSTRING_LEN;
  802. num_strings++;
  803. sprintf(p, "\tSPI: %d, mask: 0x%x\n",
  804. fsc->fs.h_u.ah_ip4_spec.spi,
  805. fsc->fs.m_u.ah_ip4_spec.spi);
  806. p += ETH_GSTRING_LEN;
  807. num_strings++;
  808. sprintf(p, "\tTOS: %d, mask: 0x%x\n",
  809. fsc->fs.h_u.ah_ip4_spec.tos,
  810. fsc->fs.m_u.ah_ip4_spec.tos);
  811. p += ETH_GSTRING_LEN;
  812. num_strings++;
  813. break;
  814. case IP_USER_FLOW:
  815. sprintf(p, "\tSrc IP addr: 0x%x\n",
  816. fsc->fs.h_u.usr_ip4_spec.ip4src);
  817. p += ETH_GSTRING_LEN;
  818. num_strings++;
  819. sprintf(p, "\tSrc IP mask: 0x%x\n",
  820. fsc->fs.m_u.usr_ip4_spec.ip4src);
  821. p += ETH_GSTRING_LEN;
  822. num_strings++;
  823. sprintf(p, "\tDest IP addr: 0x%x\n",
  824. fsc->fs.h_u.usr_ip4_spec.ip4dst);
  825. p += ETH_GSTRING_LEN;
  826. num_strings++;
  827. sprintf(p, "\tDest IP mask: 0x%x\n",
  828. fsc->fs.m_u.usr_ip4_spec.ip4dst);
  829. p += ETH_GSTRING_LEN;
  830. num_strings++;
  831. break;
  832. case IPV4_FLOW:
  833. sprintf(p, "\tSrc IP addr: 0x%x\n",
  834. fsc->fs.h_u.usr_ip4_spec.ip4src);
  835. p += ETH_GSTRING_LEN;
  836. num_strings++;
  837. sprintf(p, "\tSrc IP mask: 0x%x\n",
  838. fsc->fs.m_u.usr_ip4_spec.ip4src);
  839. p += ETH_GSTRING_LEN;
  840. num_strings++;
  841. sprintf(p, "\tDest IP addr: 0x%x\n",
  842. fsc->fs.h_u.usr_ip4_spec.ip4dst);
  843. p += ETH_GSTRING_LEN;
  844. num_strings++;
  845. sprintf(p, "\tDest IP mask: 0x%x\n",
  846. fsc->fs.m_u.usr_ip4_spec.ip4dst);
  847. p += ETH_GSTRING_LEN;
  848. num_strings++;
  849. sprintf(p, "\tL4 bytes: 0x%x, mask: 0x%x\n",
  850. fsc->fs.h_u.usr_ip4_spec.l4_4_bytes,
  851. fsc->fs.m_u.usr_ip4_spec.l4_4_bytes);
  852. p += ETH_GSTRING_LEN;
  853. num_strings++;
  854. sprintf(p, "\tTOS: %d, mask: 0x%x\n",
  855. fsc->fs.h_u.usr_ip4_spec.tos,
  856. fsc->fs.m_u.usr_ip4_spec.tos);
  857. p += ETH_GSTRING_LEN;
  858. num_strings++;
  859. sprintf(p, "\tIP Version: %d, mask: 0x%x\n",
  860. fsc->fs.h_u.usr_ip4_spec.ip_ver,
  861. fsc->fs.m_u.usr_ip4_spec.ip_ver);
  862. p += ETH_GSTRING_LEN;
  863. num_strings++;
  864. sprintf(p, "\tProtocol: %d, mask: 0x%x\n",
  865. fsc->fs.h_u.usr_ip4_spec.proto,
  866. fsc->fs.m_u.usr_ip4_spec.proto);
  867. p += ETH_GSTRING_LEN;
  868. num_strings++;
  869. break;
  870. }
  871. sprintf(p, "\tVLAN: %d, mask: 0x%x\n",
  872. fsc->fs.vlan_tag, fsc->fs.vlan_tag_mask);
  873. p += ETH_GSTRING_LEN;
  874. num_strings++;
  875. sprintf(p, "\tUser-defined: 0x%Lx\n", fsc->fs.data);
  876. p += ETH_GSTRING_LEN;
  877. num_strings++;
  878. sprintf(p, "\tUser-defined mask: 0x%Lx\n", fsc->fs.data_mask);
  879. p += ETH_GSTRING_LEN;
  880. num_strings++;
  881. if (fsc->fs.action == ETHTOOL_RXNTUPLE_ACTION_DROP)
  882. sprintf(p, "\tAction: Drop\n");
  883. else
  884. sprintf(p, "\tAction: Direct to queue %d\n",
  885. fsc->fs.action);
  886. p += ETH_GSTRING_LEN;
  887. num_strings++;
  888. unknown_filter:
  889. i++;
  890. }
  891. copy:
  892. /* indicate to userspace how many strings we actually have */
  893. gstrings.len = num_strings;
  894. ret = -EFAULT;
  895. if (copy_to_user(useraddr, &gstrings, sizeof(gstrings)))
  896. goto out;
  897. useraddr += sizeof(gstrings);
  898. if (copy_to_user(useraddr, data, gstrings.len * ETH_GSTRING_LEN))
  899. goto out;
  900. ret = 0;
  901. out:
  902. kfree(data);
  903. return ret;
  904. }
  905. static int ethtool_get_regs(struct net_device *dev, char __user *useraddr)
  906. {
  907. struct ethtool_regs regs;
  908. const struct ethtool_ops *ops = dev->ethtool_ops;
  909. void *regbuf;
  910. int reglen, ret;
  911. if (!ops->get_regs || !ops->get_regs_len)
  912. return -EOPNOTSUPP;
  913. if (copy_from_user(&regs, useraddr, sizeof(regs)))
  914. return -EFAULT;
  915. reglen = ops->get_regs_len(dev);
  916. if (regs.len > reglen)
  917. regs.len = reglen;
  918. regbuf = vzalloc(reglen);
  919. if (!regbuf)
  920. return -ENOMEM;
  921. ops->get_regs(dev, &regs, regbuf);
  922. ret = -EFAULT;
  923. if (copy_to_user(useraddr, &regs, sizeof(regs)))
  924. goto out;
  925. useraddr += offsetof(struct ethtool_regs, data);
  926. if (copy_to_user(useraddr, regbuf, regs.len))
  927. goto out;
  928. ret = 0;
  929. out:
  930. vfree(regbuf);
  931. return ret;
  932. }
  933. static int ethtool_reset(struct net_device *dev, char __user *useraddr)
  934. {
  935. struct ethtool_value reset;
  936. int ret;
  937. if (!dev->ethtool_ops->reset)
  938. return -EOPNOTSUPP;
  939. if (copy_from_user(&reset, useraddr, sizeof(reset)))
  940. return -EFAULT;
  941. ret = dev->ethtool_ops->reset(dev, &reset.data);
  942. if (ret)
  943. return ret;
  944. if (copy_to_user(useraddr, &reset, sizeof(reset)))
  945. return -EFAULT;
  946. return 0;
  947. }
  948. static int ethtool_get_wol(struct net_device *dev, char __user *useraddr)
  949. {
  950. struct ethtool_wolinfo wol = { .cmd = ETHTOOL_GWOL };
  951. if (!dev->ethtool_ops->get_wol)
  952. return -EOPNOTSUPP;
  953. dev->ethtool_ops->get_wol(dev, &wol);
  954. if (copy_to_user(useraddr, &wol, sizeof(wol)))
  955. return -EFAULT;
  956. return 0;
  957. }
  958. static int ethtool_set_wol(struct net_device *dev, char __user *useraddr)
  959. {
  960. struct ethtool_wolinfo wol;
  961. if (!dev->ethtool_ops->set_wol)
  962. return -EOPNOTSUPP;
  963. if (copy_from_user(&wol, useraddr, sizeof(wol)))
  964. return -EFAULT;
  965. return dev->ethtool_ops->set_wol(dev, &wol);
  966. }
  967. static int ethtool_nway_reset(struct net_device *dev)
  968. {
  969. if (!dev->ethtool_ops->nway_reset)
  970. return -EOPNOTSUPP;
  971. return dev->ethtool_ops->nway_reset(dev);
  972. }
  973. static int ethtool_get_link(struct net_device *dev, char __user *useraddr)
  974. {
  975. struct ethtool_value edata = { .cmd = ETHTOOL_GLINK };
  976. if (!dev->ethtool_ops->get_link)
  977. return -EOPNOTSUPP;
  978. edata.data = netif_running(dev) && dev->ethtool_ops->get_link(dev);
  979. if (copy_to_user(useraddr, &edata, sizeof(edata)))
  980. return -EFAULT;
  981. return 0;
  982. }
  983. static int ethtool_get_eeprom(struct net_device *dev, void __user *useraddr)
  984. {
  985. struct ethtool_eeprom eeprom;
  986. const struct ethtool_ops *ops = dev->ethtool_ops;
  987. void __user *userbuf = useraddr + sizeof(eeprom);
  988. u32 bytes_remaining;
  989. u8 *data;
  990. int ret = 0;
  991. if (!ops->get_eeprom || !ops->get_eeprom_len)
  992. return -EOPNOTSUPP;
  993. if (copy_from_user(&eeprom, useraddr, sizeof(eeprom)))
  994. return -EFAULT;
  995. /* Check for wrap and zero */
  996. if (eeprom.offset + eeprom.len <= eeprom.offset)
  997. return -EINVAL;
  998. /* Check for exceeding total eeprom len */
  999. if (eeprom.offset + eeprom.len > ops->get_eeprom_len(dev))
  1000. return -EINVAL;
  1001. data = kmalloc(PAGE_SIZE, GFP_USER);
  1002. if (!data)
  1003. return -ENOMEM;
  1004. bytes_remaining = eeprom.len;
  1005. while (bytes_remaining > 0) {
  1006. eeprom.len = min(bytes_remaining, (u32)PAGE_SIZE);
  1007. ret = ops->get_eeprom(dev, &eeprom, data);
  1008. if (ret)
  1009. break;
  1010. if (copy_to_user(userbuf, data, eeprom.len)) {
  1011. ret = -EFAULT;
  1012. break;
  1013. }
  1014. userbuf += eeprom.len;
  1015. eeprom.offset += eeprom.len;
  1016. bytes_remaining -= eeprom.len;
  1017. }
  1018. eeprom.len = userbuf - (useraddr + sizeof(eeprom));
  1019. eeprom.offset -= eeprom.len;
  1020. if (copy_to_user(useraddr, &eeprom, sizeof(eeprom)))
  1021. ret = -EFAULT;
  1022. kfree(data);
  1023. return ret;
  1024. }
  1025. static int ethtool_set_eeprom(struct net_device *dev, void __user *useraddr)
  1026. {
  1027. struct ethtool_eeprom eeprom;
  1028. const struct ethtool_ops *ops = dev->ethtool_ops;
  1029. void __user *userbuf = useraddr + sizeof(eeprom);
  1030. u32 bytes_remaining;
  1031. u8 *data;
  1032. int ret = 0;
  1033. if (!ops->set_eeprom || !ops->get_eeprom_len)
  1034. return -EOPNOTSUPP;
  1035. if (copy_from_user(&eeprom, useraddr, sizeof(eeprom)))
  1036. return -EFAULT;
  1037. /* Check for wrap and zero */
  1038. if (eeprom.offset + eeprom.len <= eeprom.offset)
  1039. return -EINVAL;
  1040. /* Check for exceeding total eeprom len */
  1041. if (eeprom.offset + eeprom.len > ops->get_eeprom_len(dev))
  1042. return -EINVAL;
  1043. data = kmalloc(PAGE_SIZE, GFP_USER);
  1044. if (!data)
  1045. return -ENOMEM;
  1046. bytes_remaining = eeprom.len;
  1047. while (bytes_remaining > 0) {
  1048. eeprom.len = min(bytes_remaining, (u32)PAGE_SIZE);
  1049. if (copy_from_user(data, userbuf, eeprom.len)) {
  1050. ret = -EFAULT;
  1051. break;
  1052. }
  1053. ret = ops->set_eeprom(dev, &eeprom, data);
  1054. if (ret)
  1055. break;
  1056. userbuf += eeprom.len;
  1057. eeprom.offset += eeprom.len;
  1058. bytes_remaining -= eeprom.len;
  1059. }
  1060. kfree(data);
  1061. return ret;
  1062. }
  1063. static noinline_for_stack int ethtool_get_coalesce(struct net_device *dev,
  1064. void __user *useraddr)
  1065. {
  1066. struct ethtool_coalesce coalesce = { .cmd = ETHTOOL_GCOALESCE };
  1067. if (!dev->ethtool_ops->get_coalesce)
  1068. return -EOPNOTSUPP;
  1069. dev->ethtool_ops->get_coalesce(dev, &coalesce);
  1070. if (copy_to_user(useraddr, &coalesce, sizeof(coalesce)))
  1071. return -EFAULT;
  1072. return 0;
  1073. }
  1074. static noinline_for_stack int ethtool_set_coalesce(struct net_device *dev,
  1075. void __user *useraddr)
  1076. {
  1077. struct ethtool_coalesce coalesce;
  1078. if (!dev->ethtool_ops->set_coalesce)
  1079. return -EOPNOTSUPP;
  1080. if (copy_from_user(&coalesce, useraddr, sizeof(coalesce)))
  1081. return -EFAULT;
  1082. return dev->ethtool_ops->set_coalesce(dev, &coalesce);
  1083. }
  1084. static int ethtool_get_ringparam(struct net_device *dev, void __user *useraddr)
  1085. {
  1086. struct ethtool_ringparam ringparam = { .cmd = ETHTOOL_GRINGPARAM };
  1087. if (!dev->ethtool_ops->get_ringparam)
  1088. return -EOPNOTSUPP;
  1089. dev->ethtool_ops->get_ringparam(dev, &ringparam);
  1090. if (copy_to_user(useraddr, &ringparam, sizeof(ringparam)))
  1091. return -EFAULT;
  1092. return 0;
  1093. }
  1094. static int ethtool_set_ringparam(struct net_device *dev, void __user *useraddr)
  1095. {
  1096. struct ethtool_ringparam ringparam;
  1097. if (!dev->ethtool_ops->set_ringparam)
  1098. return -EOPNOTSUPP;
  1099. if (copy_from_user(&ringparam, useraddr, sizeof(ringparam)))
  1100. return -EFAULT;
  1101. return dev->ethtool_ops->set_ringparam(dev, &ringparam);
  1102. }
  1103. static int ethtool_get_pauseparam(struct net_device *dev, void __user *useraddr)
  1104. {
  1105. struct ethtool_pauseparam pauseparam = { ETHTOOL_GPAUSEPARAM };
  1106. if (!dev->ethtool_ops->get_pauseparam)
  1107. return -EOPNOTSUPP;
  1108. dev->ethtool_ops->get_pauseparam(dev, &pauseparam);
  1109. if (copy_to_user(useraddr, &pauseparam, sizeof(pauseparam)))
  1110. return -EFAULT;
  1111. return 0;
  1112. }
  1113. static int ethtool_set_pauseparam(struct net_device *dev, void __user *useraddr)
  1114. {
  1115. struct ethtool_pauseparam pauseparam;
  1116. if (!dev->ethtool_ops->set_pauseparam)
  1117. return -EOPNOTSUPP;
  1118. if (copy_from_user(&pauseparam, useraddr, sizeof(pauseparam)))
  1119. return -EFAULT;
  1120. return dev->ethtool_ops->set_pauseparam(dev, &pauseparam);
  1121. }
  1122. static int __ethtool_set_sg(struct net_device *dev, u32 data)
  1123. {
  1124. int err;
  1125. if (data && !(dev->features & NETIF_F_ALL_CSUM))
  1126. return -EINVAL;
  1127. if (!data && dev->ethtool_ops->set_tso) {
  1128. err = dev->ethtool_ops->set_tso(dev, 0);
  1129. if (err)
  1130. return err;
  1131. }
  1132. if (!data && dev->ethtool_ops->set_ufo) {
  1133. err = dev->ethtool_ops->set_ufo(dev, 0);
  1134. if (err)
  1135. return err;
  1136. }
  1137. return dev->ethtool_ops->set_sg(dev, data);
  1138. }
  1139. static int __ethtool_set_tx_csum(struct net_device *dev, u32 data)
  1140. {
  1141. int err;
  1142. if (!dev->ethtool_ops->set_tx_csum)
  1143. return -EOPNOTSUPP;
  1144. if (!data && dev->ethtool_ops->set_sg) {
  1145. err = __ethtool_set_sg(dev, 0);
  1146. if (err)
  1147. return err;
  1148. }
  1149. return dev->ethtool_ops->set_tx_csum(dev, data);
  1150. }
  1151. static int ethtool_set_rx_csum(struct net_device *dev, char __user *useraddr)
  1152. {
  1153. struct ethtool_value edata;
  1154. if (!dev->ethtool_ops->set_rx_csum)
  1155. return -EOPNOTSUPP;
  1156. if (copy_from_user(&edata, useraddr, sizeof(edata)))
  1157. return -EFAULT;
  1158. if (!edata.data && dev->ethtool_ops->set_sg)
  1159. dev->features &= ~NETIF_F_GRO;
  1160. return dev->ethtool_ops->set_rx_csum(dev, edata.data);
  1161. }
  1162. static int __ethtool_set_tso(struct net_device *dev, u32 data)
  1163. {
  1164. if (!dev->ethtool_ops->set_tso)
  1165. return -EOPNOTSUPP;
  1166. if (data && !(dev->features & NETIF_F_SG))
  1167. return -EINVAL;
  1168. return dev->ethtool_ops->set_tso(dev, data);
  1169. }
  1170. static int __ethtool_set_ufo(struct net_device *dev, u32 data)
  1171. {
  1172. if (!dev->ethtool_ops->set_ufo)
  1173. return -EOPNOTSUPP;
  1174. if (data && !(dev->features & NETIF_F_SG))
  1175. return -EINVAL;
  1176. if (data && !((dev->features & NETIF_F_GEN_CSUM) ||
  1177. (dev->features & (NETIF_F_IP_CSUM|NETIF_F_IPV6_CSUM))
  1178. == (NETIF_F_IP_CSUM|NETIF_F_IPV6_CSUM)))
  1179. return -EINVAL;
  1180. return dev->ethtool_ops->set_ufo(dev, data);
  1181. }
  1182. static int ethtool_self_test(struct net_device *dev, char __user *useraddr)
  1183. {
  1184. struct ethtool_test test;
  1185. const struct ethtool_ops *ops = dev->ethtool_ops;
  1186. u64 *data;
  1187. int ret, test_len;
  1188. if (!ops->self_test || !ops->get_sset_count)
  1189. return -EOPNOTSUPP;
  1190. test_len = ops->get_sset_count(dev, ETH_SS_TEST);
  1191. if (test_len < 0)
  1192. return test_len;
  1193. WARN_ON(test_len == 0);
  1194. if (copy_from_user(&test, useraddr, sizeof(test)))
  1195. return -EFAULT;
  1196. test.len = test_len;
  1197. data = kmalloc(test_len * sizeof(u64), GFP_USER);
  1198. if (!data)
  1199. return -ENOMEM;
  1200. ops->self_test(dev, &test, data);
  1201. ret = -EFAULT;
  1202. if (copy_to_user(useraddr, &test, sizeof(test)))
  1203. goto out;
  1204. useraddr += sizeof(test);
  1205. if (copy_to_user(useraddr, data, test.len * sizeof(u64)))
  1206. goto out;
  1207. ret = 0;
  1208. out:
  1209. kfree(data);
  1210. return ret;
  1211. }
  1212. static int ethtool_get_strings(struct net_device *dev, void __user *useraddr)
  1213. {
  1214. struct ethtool_gstrings gstrings;
  1215. u8 *data;
  1216. int ret;
  1217. if (copy_from_user(&gstrings, useraddr, sizeof(gstrings)))
  1218. return -EFAULT;
  1219. ret = __ethtool_get_sset_count(dev, gstrings.string_set);
  1220. if (ret < 0)
  1221. return ret;
  1222. gstrings.len = ret;
  1223. data = kmalloc(gstrings.len * ETH_GSTRING_LEN, GFP_USER);
  1224. if (!data)
  1225. return -ENOMEM;
  1226. __ethtool_get_strings(dev, gstrings.string_set, data);
  1227. ret = -EFAULT;
  1228. if (copy_to_user(useraddr, &gstrings, sizeof(gstrings)))
  1229. goto out;
  1230. useraddr += sizeof(gstrings);
  1231. if (copy_to_user(useraddr, data, gstrings.len * ETH_GSTRING_LEN))
  1232. goto out;
  1233. ret = 0;
  1234. out:
  1235. kfree(data);
  1236. return ret;
  1237. }
  1238. static int ethtool_phys_id(struct net_device *dev, void __user *useraddr)
  1239. {
  1240. struct ethtool_value id;
  1241. if (!dev->ethtool_ops->phys_id)
  1242. return -EOPNOTSUPP;
  1243. if (copy_from_user(&id, useraddr, sizeof(id)))
  1244. return -EFAULT;
  1245. return dev->ethtool_ops->phys_id(dev, id.data);
  1246. }
  1247. static int ethtool_get_stats(struct net_device *dev, void __user *useraddr)
  1248. {
  1249. struct ethtool_stats stats;
  1250. const struct ethtool_ops *ops = dev->ethtool_ops;
  1251. u64 *data;
  1252. int ret, n_stats;
  1253. if (!ops->get_ethtool_stats || !ops->get_sset_count)
  1254. return -EOPNOTSUPP;
  1255. n_stats = ops->get_sset_count(dev, ETH_SS_STATS);
  1256. if (n_stats < 0)
  1257. return n_stats;
  1258. WARN_ON(n_stats == 0);
  1259. if (copy_from_user(&stats, useraddr, sizeof(stats)))
  1260. return -EFAULT;
  1261. stats.n_stats = n_stats;
  1262. data = kmalloc(n_stats * sizeof(u64), GFP_USER);
  1263. if (!data)
  1264. return -ENOMEM;
  1265. ops->get_ethtool_stats(dev, &stats, data);
  1266. ret = -EFAULT;
  1267. if (copy_to_user(useraddr, &stats, sizeof(stats)))
  1268. goto out;
  1269. useraddr += sizeof(stats);
  1270. if (copy_to_user(useraddr, data, stats.n_stats * sizeof(u64)))
  1271. goto out;
  1272. ret = 0;
  1273. out:
  1274. kfree(data);
  1275. return ret;
  1276. }
  1277. static int ethtool_get_perm_addr(struct net_device *dev, void __user *useraddr)
  1278. {
  1279. struct ethtool_perm_addr epaddr;
  1280. if (copy_from_user(&epaddr, useraddr, sizeof(epaddr)))
  1281. return -EFAULT;
  1282. if (epaddr.size < dev->addr_len)
  1283. return -ETOOSMALL;
  1284. epaddr.size = dev->addr_len;
  1285. if (copy_to_user(useraddr, &epaddr, sizeof(epaddr)))
  1286. return -EFAULT;
  1287. useraddr += sizeof(epaddr);
  1288. if (copy_to_user(useraddr, dev->perm_addr, epaddr.size))
  1289. return -EFAULT;
  1290. return 0;
  1291. }
  1292. static int ethtool_get_value(struct net_device *dev, char __user *useraddr,
  1293. u32 cmd, u32 (*actor)(struct net_device *))
  1294. {
  1295. struct ethtool_value edata = { .cmd = cmd };
  1296. if (!actor)
  1297. return -EOPNOTSUPP;
  1298. edata.data = actor(dev);
  1299. if (copy_to_user(useraddr, &edata, sizeof(edata)))
  1300. return -EFAULT;
  1301. return 0;
  1302. }
  1303. static int ethtool_set_value_void(struct net_device *dev, char __user *useraddr,
  1304. void (*actor)(struct net_device *, u32))
  1305. {
  1306. struct ethtool_value edata;
  1307. if (!actor)
  1308. return -EOPNOTSUPP;
  1309. if (copy_from_user(&edata, useraddr, sizeof(edata)))
  1310. return -EFAULT;
  1311. actor(dev, edata.data);
  1312. return 0;
  1313. }
  1314. static int ethtool_set_value(struct net_device *dev, char __user *useraddr,
  1315. int (*actor)(struct net_device *, u32))
  1316. {
  1317. struct ethtool_value edata;
  1318. if (!actor)
  1319. return -EOPNOTSUPP;
  1320. if (copy_from_user(&edata, useraddr, sizeof(edata)))
  1321. return -EFAULT;
  1322. return actor(dev, edata.data);
  1323. }
  1324. static noinline_for_stack int ethtool_flash_device(struct net_device *dev,
  1325. char __user *useraddr)
  1326. {
  1327. struct ethtool_flash efl;
  1328. if (copy_from_user(&efl, useraddr, sizeof(efl)))
  1329. return -EFAULT;
  1330. if (!dev->ethtool_ops->flash_device)
  1331. return -EOPNOTSUPP;
  1332. return dev->ethtool_ops->flash_device(dev, &efl);
  1333. }
  1334. /* The main entry point in this file. Called from net/core/dev.c */
  1335. int dev_ethtool(struct net *net, struct ifreq *ifr)
  1336. {
  1337. struct net_device *dev = __dev_get_by_name(net, ifr->ifr_name);
  1338. void __user *useraddr = ifr->ifr_data;
  1339. u32 ethcmd;
  1340. int rc;
  1341. u32 old_features;
  1342. if (!dev || !netif_device_present(dev))
  1343. return -ENODEV;
  1344. if (copy_from_user(&ethcmd, useraddr, sizeof(ethcmd)))
  1345. return -EFAULT;
  1346. if (!dev->ethtool_ops) {
  1347. /* ETHTOOL_GDRVINFO does not require any driver support.
  1348. * It is also unprivileged and does not change anything,
  1349. * so we can take a shortcut to it. */
  1350. if (ethcmd == ETHTOOL_GDRVINFO)
  1351. return ethtool_get_drvinfo(dev, useraddr);
  1352. else
  1353. return -EOPNOTSUPP;
  1354. }
  1355. /* Allow some commands to be done by anyone */
  1356. switch (ethcmd) {
  1357. case ETHTOOL_GSET:
  1358. case ETHTOOL_GDRVINFO:
  1359. case ETHTOOL_GMSGLVL:
  1360. case ETHTOOL_GCOALESCE:
  1361. case ETHTOOL_GRINGPARAM:
  1362. case ETHTOOL_GPAUSEPARAM:
  1363. case ETHTOOL_GRXCSUM:
  1364. case ETHTOOL_GTXCSUM:
  1365. case ETHTOOL_GSG:
  1366. case ETHTOOL_GSTRINGS:
  1367. case ETHTOOL_GTSO:
  1368. case ETHTOOL_GPERMADDR:
  1369. case ETHTOOL_GUFO:
  1370. case ETHTOOL_GGSO:
  1371. case ETHTOOL_GGRO:
  1372. case ETHTOOL_GFLAGS:
  1373. case ETHTOOL_GPFLAGS:
  1374. case ETHTOOL_GRXFH:
  1375. case ETHTOOL_GRXRINGS:
  1376. case ETHTOOL_GRXCLSRLCNT:
  1377. case ETHTOOL_GRXCLSRULE:
  1378. case ETHTOOL_GRXCLSRLALL:
  1379. case ETHTOOL_GFEATURES:
  1380. break;
  1381. default:
  1382. if (!capable(CAP_NET_ADMIN))
  1383. return -EPERM;
  1384. }
  1385. if (dev->ethtool_ops->begin) {
  1386. rc = dev->ethtool_ops->begin(dev);
  1387. if (rc < 0)
  1388. return rc;
  1389. }
  1390. old_features = dev->features;
  1391. switch (ethcmd) {
  1392. case ETHTOOL_GSET:
  1393. rc = ethtool_get_settings(dev, useraddr);
  1394. break;
  1395. case ETHTOOL_SSET:
  1396. rc = ethtool_set_settings(dev, useraddr);
  1397. break;
  1398. case ETHTOOL_GDRVINFO:
  1399. rc = ethtool_get_drvinfo(dev, useraddr);
  1400. break;
  1401. case ETHTOOL_GREGS:
  1402. rc = ethtool_get_regs(dev, useraddr);
  1403. break;
  1404. case ETHTOOL_GWOL:
  1405. rc = ethtool_get_wol(dev, useraddr);
  1406. break;
  1407. case ETHTOOL_SWOL:
  1408. rc = ethtool_set_wol(dev, useraddr);
  1409. break;
  1410. case ETHTOOL_GMSGLVL:
  1411. rc = ethtool_get_value(dev, useraddr, ethcmd,
  1412. dev->ethtool_ops->get_msglevel);
  1413. break;
  1414. case ETHTOOL_SMSGLVL:
  1415. rc = ethtool_set_value_void(dev, useraddr,
  1416. dev->ethtool_ops->set_msglevel);
  1417. break;
  1418. case ETHTOOL_NWAY_RST:
  1419. rc = ethtool_nway_reset(dev);
  1420. break;
  1421. case ETHTOOL_GLINK:
  1422. rc = ethtool_get_link(dev, useraddr);
  1423. break;
  1424. case ETHTOOL_GEEPROM:
  1425. rc = ethtool_get_eeprom(dev, useraddr);
  1426. break;
  1427. case ETHTOOL_SEEPROM:
  1428. rc = ethtool_set_eeprom(dev, useraddr);
  1429. break;
  1430. case ETHTOOL_GCOALESCE:
  1431. rc = ethtool_get_coalesce(dev, useraddr);
  1432. break;
  1433. case ETHTOOL_SCOALESCE:
  1434. rc = ethtool_set_coalesce(dev, useraddr);
  1435. break;
  1436. case ETHTOOL_GRINGPARAM:
  1437. rc = ethtool_get_ringparam(dev, useraddr);
  1438. break;
  1439. case ETHTOOL_SRINGPARAM:
  1440. rc = ethtool_set_ringparam(dev, useraddr);
  1441. break;
  1442. case ETHTOOL_GPAUSEPARAM:
  1443. rc = ethtool_get_pauseparam(dev, useraddr);
  1444. break;
  1445. case ETHTOOL_SPAUSEPARAM:
  1446. rc = ethtool_set_pauseparam(dev, useraddr);
  1447. break;
  1448. case ETHTOOL_GRXCSUM:
  1449. rc = ethtool_get_value(dev, useraddr, ethcmd,
  1450. (dev->ethtool_ops->get_rx_csum ?
  1451. dev->ethtool_ops->get_rx_csum :
  1452. ethtool_op_get_rx_csum));
  1453. break;
  1454. case ETHTOOL_SRXCSUM:
  1455. rc = ethtool_set_rx_csum(dev, useraddr);
  1456. break;
  1457. case ETHTOOL_TEST:
  1458. rc = ethtool_self_test(dev, useraddr);
  1459. break;
  1460. case ETHTOOL_GSTRINGS:
  1461. rc = ethtool_get_strings(dev, useraddr);
  1462. break;
  1463. case ETHTOOL_PHYS_ID:
  1464. rc = ethtool_phys_id(dev, useraddr);
  1465. break;
  1466. case ETHTOOL_GSTATS:
  1467. rc = ethtool_get_stats(dev, useraddr);
  1468. break;
  1469. case ETHTOOL_GPERMADDR:
  1470. rc = ethtool_get_perm_addr(dev, useraddr);
  1471. break;
  1472. case ETHTOOL_GFLAGS:
  1473. rc = ethtool_get_value(dev, useraddr, ethcmd,
  1474. (dev->ethtool_ops->get_flags ?
  1475. dev->ethtool_ops->get_flags :
  1476. ethtool_op_get_flags));
  1477. break;
  1478. case ETHTOOL_SFLAGS:
  1479. rc = ethtool_set_value(dev, useraddr,
  1480. dev->ethtool_ops->set_flags);
  1481. break;
  1482. case ETHTOOL_GPFLAGS:
  1483. rc = ethtool_get_value(dev, useraddr, ethcmd,
  1484. dev->ethtool_ops->get_priv_flags);
  1485. break;
  1486. case ETHTOOL_SPFLAGS:
  1487. rc = ethtool_set_value(dev, useraddr,
  1488. dev->ethtool_ops->set_priv_flags);
  1489. break;
  1490. case ETHTOOL_GRXFH:
  1491. case ETHTOOL_GRXRINGS:
  1492. case ETHTOOL_GRXCLSRLCNT:
  1493. case ETHTOOL_GRXCLSRULE:
  1494. case ETHTOOL_GRXCLSRLALL:
  1495. rc = ethtool_get_rxnfc(dev, ethcmd, useraddr);
  1496. break;
  1497. case ETHTOOL_SRXFH:
  1498. case ETHTOOL_SRXCLSRLDEL:
  1499. case ETHTOOL_SRXCLSRLINS:
  1500. rc = ethtool_set_rxnfc(dev, ethcmd, useraddr);
  1501. break;
  1502. case ETHTOOL_FLASHDEV:
  1503. rc = ethtool_flash_device(dev, useraddr);
  1504. break;
  1505. case ETHTOOL_RESET:
  1506. rc = ethtool_reset(dev, useraddr);
  1507. break;
  1508. case ETHTOOL_SRXNTUPLE:
  1509. rc = ethtool_set_rx_ntuple(dev, useraddr);
  1510. break;
  1511. case ETHTOOL_GRXNTUPLE:
  1512. rc = ethtool_get_rx_ntuple(dev, useraddr);
  1513. break;
  1514. case ETHTOOL_GSSET_INFO:
  1515. rc = ethtool_get_sset_info(dev, useraddr);
  1516. break;
  1517. case ETHTOOL_GRXFHINDIR:
  1518. rc = ethtool_get_rxfh_indir(dev, useraddr);
  1519. break;
  1520. case ETHTOOL_SRXFHINDIR:
  1521. rc = ethtool_set_rxfh_indir(dev, useraddr);
  1522. break;
  1523. case ETHTOOL_GFEATURES:
  1524. rc = ethtool_get_features(dev, useraddr);
  1525. break;
  1526. case ETHTOOL_SFEATURES:
  1527. rc = ethtool_set_features(dev, useraddr);
  1528. break;
  1529. case ETHTOOL_GTXCSUM:
  1530. case ETHTOOL_GSG:
  1531. case ETHTOOL_GTSO:
  1532. case ETHTOOL_GUFO:
  1533. case ETHTOOL_GGSO:
  1534. case ETHTOOL_GGRO:
  1535. rc = ethtool_get_one_feature(dev, useraddr, ethcmd);
  1536. break;
  1537. case ETHTOOL_STXCSUM:
  1538. case ETHTOOL_SSG:
  1539. case ETHTOOL_STSO:
  1540. case ETHTOOL_SUFO:
  1541. case ETHTOOL_SGSO:
  1542. case ETHTOOL_SGRO:
  1543. rc = ethtool_set_one_feature(dev, useraddr, ethcmd);
  1544. break;
  1545. default:
  1546. rc = -EOPNOTSUPP;
  1547. }
  1548. if (dev->ethtool_ops->complete)
  1549. dev->ethtool_ops->complete(dev);
  1550. if (old_features != dev->features)
  1551. netdev_features_change(dev);
  1552. return rc;
  1553. }