ethtool.c 48 KB

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