ethtool.c 48 KB

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