ethtool.c 45 KB

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