ethtool.c 48 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017
  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 = NULL;
  733. if (reglen) {
  734. regbuf = vzalloc(reglen);
  735. if (!regbuf)
  736. return -ENOMEM;
  737. }
  738. ops->get_regs(dev, &regs, regbuf);
  739. ret = -EFAULT;
  740. if (copy_to_user(useraddr, &regs, sizeof(regs)))
  741. goto out;
  742. useraddr += offsetof(struct ethtool_regs, data);
  743. if (regbuf && copy_to_user(useraddr, regbuf, regs.len))
  744. goto out;
  745. ret = 0;
  746. out:
  747. vfree(regbuf);
  748. return ret;
  749. }
  750. static int ethtool_reset(struct net_device *dev, char __user *useraddr)
  751. {
  752. struct ethtool_value reset;
  753. int ret;
  754. if (!dev->ethtool_ops->reset)
  755. return -EOPNOTSUPP;
  756. if (copy_from_user(&reset, useraddr, sizeof(reset)))
  757. return -EFAULT;
  758. ret = dev->ethtool_ops->reset(dev, &reset.data);
  759. if (ret)
  760. return ret;
  761. if (copy_to_user(useraddr, &reset, sizeof(reset)))
  762. return -EFAULT;
  763. return 0;
  764. }
  765. static int ethtool_get_wol(struct net_device *dev, char __user *useraddr)
  766. {
  767. struct ethtool_wolinfo wol = { .cmd = ETHTOOL_GWOL };
  768. if (!dev->ethtool_ops->get_wol)
  769. return -EOPNOTSUPP;
  770. dev->ethtool_ops->get_wol(dev, &wol);
  771. if (copy_to_user(useraddr, &wol, sizeof(wol)))
  772. return -EFAULT;
  773. return 0;
  774. }
  775. static int ethtool_set_wol(struct net_device *dev, char __user *useraddr)
  776. {
  777. struct ethtool_wolinfo wol;
  778. if (!dev->ethtool_ops->set_wol)
  779. return -EOPNOTSUPP;
  780. if (copy_from_user(&wol, useraddr, sizeof(wol)))
  781. return -EFAULT;
  782. return dev->ethtool_ops->set_wol(dev, &wol);
  783. }
  784. static int ethtool_get_eee(struct net_device *dev, char __user *useraddr)
  785. {
  786. struct ethtool_eee edata;
  787. int rc;
  788. if (!dev->ethtool_ops->get_eee)
  789. return -EOPNOTSUPP;
  790. memset(&edata, 0, sizeof(struct ethtool_eee));
  791. edata.cmd = ETHTOOL_GEEE;
  792. rc = dev->ethtool_ops->get_eee(dev, &edata);
  793. if (rc)
  794. return rc;
  795. if (copy_to_user(useraddr, &edata, sizeof(edata)))
  796. return -EFAULT;
  797. return 0;
  798. }
  799. static int ethtool_set_eee(struct net_device *dev, char __user *useraddr)
  800. {
  801. struct ethtool_eee edata;
  802. if (!dev->ethtool_ops->set_eee)
  803. return -EOPNOTSUPP;
  804. if (copy_from_user(&edata, useraddr, sizeof(edata)))
  805. return -EFAULT;
  806. return dev->ethtool_ops->set_eee(dev, &edata);
  807. }
  808. static int ethtool_nway_reset(struct net_device *dev)
  809. {
  810. if (!dev->ethtool_ops->nway_reset)
  811. return -EOPNOTSUPP;
  812. return dev->ethtool_ops->nway_reset(dev);
  813. }
  814. static int ethtool_get_link(struct net_device *dev, char __user *useraddr)
  815. {
  816. struct ethtool_value edata = { .cmd = ETHTOOL_GLINK };
  817. if (!dev->ethtool_ops->get_link)
  818. return -EOPNOTSUPP;
  819. edata.data = netif_running(dev) && dev->ethtool_ops->get_link(dev);
  820. if (copy_to_user(useraddr, &edata, sizeof(edata)))
  821. return -EFAULT;
  822. return 0;
  823. }
  824. static int ethtool_get_any_eeprom(struct net_device *dev, void __user *useraddr,
  825. int (*getter)(struct net_device *,
  826. struct ethtool_eeprom *, u8 *),
  827. u32 total_len)
  828. {
  829. struct ethtool_eeprom eeprom;
  830. void __user *userbuf = useraddr + sizeof(eeprom);
  831. u32 bytes_remaining;
  832. u8 *data;
  833. int ret = 0;
  834. if (copy_from_user(&eeprom, useraddr, sizeof(eeprom)))
  835. return -EFAULT;
  836. /* Check for wrap and zero */
  837. if (eeprom.offset + eeprom.len <= eeprom.offset)
  838. return -EINVAL;
  839. /* Check for exceeding total eeprom len */
  840. if (eeprom.offset + eeprom.len > total_len)
  841. return -EINVAL;
  842. data = kmalloc(PAGE_SIZE, GFP_USER);
  843. if (!data)
  844. return -ENOMEM;
  845. bytes_remaining = eeprom.len;
  846. while (bytes_remaining > 0) {
  847. eeprom.len = min(bytes_remaining, (u32)PAGE_SIZE);
  848. ret = getter(dev, &eeprom, data);
  849. if (ret)
  850. break;
  851. if (copy_to_user(userbuf, data, eeprom.len)) {
  852. ret = -EFAULT;
  853. break;
  854. }
  855. userbuf += eeprom.len;
  856. eeprom.offset += eeprom.len;
  857. bytes_remaining -= eeprom.len;
  858. }
  859. eeprom.len = userbuf - (useraddr + sizeof(eeprom));
  860. eeprom.offset -= eeprom.len;
  861. if (copy_to_user(useraddr, &eeprom, sizeof(eeprom)))
  862. ret = -EFAULT;
  863. kfree(data);
  864. return ret;
  865. }
  866. static int ethtool_get_eeprom(struct net_device *dev, void __user *useraddr)
  867. {
  868. const struct ethtool_ops *ops = dev->ethtool_ops;
  869. if (!ops->get_eeprom || !ops->get_eeprom_len ||
  870. !ops->get_eeprom_len(dev))
  871. return -EOPNOTSUPP;
  872. return ethtool_get_any_eeprom(dev, useraddr, ops->get_eeprom,
  873. ops->get_eeprom_len(dev));
  874. }
  875. static int ethtool_set_eeprom(struct net_device *dev, void __user *useraddr)
  876. {
  877. struct ethtool_eeprom eeprom;
  878. const struct ethtool_ops *ops = dev->ethtool_ops;
  879. void __user *userbuf = useraddr + sizeof(eeprom);
  880. u32 bytes_remaining;
  881. u8 *data;
  882. int ret = 0;
  883. if (!ops->set_eeprom || !ops->get_eeprom_len ||
  884. !ops->get_eeprom_len(dev))
  885. return -EOPNOTSUPP;
  886. if (copy_from_user(&eeprom, useraddr, sizeof(eeprom)))
  887. return -EFAULT;
  888. /* Check for wrap and zero */
  889. if (eeprom.offset + eeprom.len <= eeprom.offset)
  890. return -EINVAL;
  891. /* Check for exceeding total eeprom len */
  892. if (eeprom.offset + eeprom.len > ops->get_eeprom_len(dev))
  893. return -EINVAL;
  894. data = kmalloc(PAGE_SIZE, GFP_USER);
  895. if (!data)
  896. return -ENOMEM;
  897. bytes_remaining = eeprom.len;
  898. while (bytes_remaining > 0) {
  899. eeprom.len = min(bytes_remaining, (u32)PAGE_SIZE);
  900. if (copy_from_user(data, userbuf, eeprom.len)) {
  901. ret = -EFAULT;
  902. break;
  903. }
  904. ret = ops->set_eeprom(dev, &eeprom, data);
  905. if (ret)
  906. break;
  907. userbuf += eeprom.len;
  908. eeprom.offset += eeprom.len;
  909. bytes_remaining -= eeprom.len;
  910. }
  911. kfree(data);
  912. return ret;
  913. }
  914. static noinline_for_stack int ethtool_get_coalesce(struct net_device *dev,
  915. void __user *useraddr)
  916. {
  917. struct ethtool_coalesce coalesce = { .cmd = ETHTOOL_GCOALESCE };
  918. if (!dev->ethtool_ops->get_coalesce)
  919. return -EOPNOTSUPP;
  920. dev->ethtool_ops->get_coalesce(dev, &coalesce);
  921. if (copy_to_user(useraddr, &coalesce, sizeof(coalesce)))
  922. return -EFAULT;
  923. return 0;
  924. }
  925. static noinline_for_stack int ethtool_set_coalesce(struct net_device *dev,
  926. void __user *useraddr)
  927. {
  928. struct ethtool_coalesce coalesce;
  929. if (!dev->ethtool_ops->set_coalesce)
  930. return -EOPNOTSUPP;
  931. if (copy_from_user(&coalesce, useraddr, sizeof(coalesce)))
  932. return -EFAULT;
  933. return dev->ethtool_ops->set_coalesce(dev, &coalesce);
  934. }
  935. static int ethtool_get_ringparam(struct net_device *dev, void __user *useraddr)
  936. {
  937. struct ethtool_ringparam ringparam = { .cmd = ETHTOOL_GRINGPARAM };
  938. if (!dev->ethtool_ops->get_ringparam)
  939. return -EOPNOTSUPP;
  940. dev->ethtool_ops->get_ringparam(dev, &ringparam);
  941. if (copy_to_user(useraddr, &ringparam, sizeof(ringparam)))
  942. return -EFAULT;
  943. return 0;
  944. }
  945. static int ethtool_set_ringparam(struct net_device *dev, void __user *useraddr)
  946. {
  947. struct ethtool_ringparam ringparam;
  948. if (!dev->ethtool_ops->set_ringparam)
  949. return -EOPNOTSUPP;
  950. if (copy_from_user(&ringparam, useraddr, sizeof(ringparam)))
  951. return -EFAULT;
  952. return dev->ethtool_ops->set_ringparam(dev, &ringparam);
  953. }
  954. static noinline_for_stack int ethtool_get_channels(struct net_device *dev,
  955. void __user *useraddr)
  956. {
  957. struct ethtool_channels channels = { .cmd = ETHTOOL_GCHANNELS };
  958. if (!dev->ethtool_ops->get_channels)
  959. return -EOPNOTSUPP;
  960. dev->ethtool_ops->get_channels(dev, &channels);
  961. if (copy_to_user(useraddr, &channels, sizeof(channels)))
  962. return -EFAULT;
  963. return 0;
  964. }
  965. static noinline_for_stack int ethtool_set_channels(struct net_device *dev,
  966. void __user *useraddr)
  967. {
  968. struct ethtool_channels channels;
  969. if (!dev->ethtool_ops->set_channels)
  970. return -EOPNOTSUPP;
  971. if (copy_from_user(&channels, useraddr, sizeof(channels)))
  972. return -EFAULT;
  973. return dev->ethtool_ops->set_channels(dev, &channels);
  974. }
  975. static int ethtool_get_pauseparam(struct net_device *dev, void __user *useraddr)
  976. {
  977. struct ethtool_pauseparam pauseparam = { ETHTOOL_GPAUSEPARAM };
  978. if (!dev->ethtool_ops->get_pauseparam)
  979. return -EOPNOTSUPP;
  980. dev->ethtool_ops->get_pauseparam(dev, &pauseparam);
  981. if (copy_to_user(useraddr, &pauseparam, sizeof(pauseparam)))
  982. return -EFAULT;
  983. return 0;
  984. }
  985. static int ethtool_set_pauseparam(struct net_device *dev, void __user *useraddr)
  986. {
  987. struct ethtool_pauseparam pauseparam;
  988. if (!dev->ethtool_ops->set_pauseparam)
  989. return -EOPNOTSUPP;
  990. if (copy_from_user(&pauseparam, useraddr, sizeof(pauseparam)))
  991. return -EFAULT;
  992. return dev->ethtool_ops->set_pauseparam(dev, &pauseparam);
  993. }
  994. static int ethtool_self_test(struct net_device *dev, char __user *useraddr)
  995. {
  996. struct ethtool_test test;
  997. const struct ethtool_ops *ops = dev->ethtool_ops;
  998. u64 *data;
  999. int ret, test_len;
  1000. if (!ops->self_test || !ops->get_sset_count)
  1001. return -EOPNOTSUPP;
  1002. test_len = ops->get_sset_count(dev, ETH_SS_TEST);
  1003. if (test_len < 0)
  1004. return test_len;
  1005. WARN_ON(test_len == 0);
  1006. if (copy_from_user(&test, useraddr, sizeof(test)))
  1007. return -EFAULT;
  1008. test.len = test_len;
  1009. data = kmalloc(test_len * sizeof(u64), GFP_USER);
  1010. if (!data)
  1011. return -ENOMEM;
  1012. ops->self_test(dev, &test, data);
  1013. ret = -EFAULT;
  1014. if (copy_to_user(useraddr, &test, sizeof(test)))
  1015. goto out;
  1016. useraddr += sizeof(test);
  1017. if (copy_to_user(useraddr, data, test.len * sizeof(u64)))
  1018. goto out;
  1019. ret = 0;
  1020. out:
  1021. kfree(data);
  1022. return ret;
  1023. }
  1024. static int ethtool_get_strings(struct net_device *dev, void __user *useraddr)
  1025. {
  1026. struct ethtool_gstrings gstrings;
  1027. u8 *data;
  1028. int ret;
  1029. if (copy_from_user(&gstrings, useraddr, sizeof(gstrings)))
  1030. return -EFAULT;
  1031. ret = __ethtool_get_sset_count(dev, gstrings.string_set);
  1032. if (ret < 0)
  1033. return ret;
  1034. gstrings.len = ret;
  1035. if (gstrings.len) {
  1036. data = kcalloc(gstrings.len, ETH_GSTRING_LEN, GFP_USER);
  1037. if (!data)
  1038. return -ENOMEM;
  1039. __ethtool_get_strings(dev, gstrings.string_set, data);
  1040. } else {
  1041. data = NULL;
  1042. }
  1043. ret = -EFAULT;
  1044. if (copy_to_user(useraddr, &gstrings, sizeof(gstrings)))
  1045. goto out;
  1046. useraddr += sizeof(gstrings);
  1047. if (gstrings.len &&
  1048. copy_to_user(useraddr, data, gstrings.len * ETH_GSTRING_LEN))
  1049. goto out;
  1050. ret = 0;
  1051. out:
  1052. kfree(data);
  1053. return ret;
  1054. }
  1055. static int ethtool_phys_id(struct net_device *dev, void __user *useraddr)
  1056. {
  1057. struct ethtool_value id;
  1058. static bool busy;
  1059. const struct ethtool_ops *ops = dev->ethtool_ops;
  1060. int rc;
  1061. if (!ops->set_phys_id)
  1062. return -EOPNOTSUPP;
  1063. if (busy)
  1064. return -EBUSY;
  1065. if (copy_from_user(&id, useraddr, sizeof(id)))
  1066. return -EFAULT;
  1067. rc = ops->set_phys_id(dev, ETHTOOL_ID_ACTIVE);
  1068. if (rc < 0)
  1069. return rc;
  1070. /* Drop the RTNL lock while waiting, but prevent reentry or
  1071. * removal of the device.
  1072. */
  1073. busy = true;
  1074. dev_hold(dev);
  1075. rtnl_unlock();
  1076. if (rc == 0) {
  1077. /* Driver will handle this itself */
  1078. schedule_timeout_interruptible(
  1079. id.data ? (id.data * HZ) : MAX_SCHEDULE_TIMEOUT);
  1080. } else {
  1081. /* Driver expects to be called at twice the frequency in rc */
  1082. int n = rc * 2, i, interval = HZ / n;
  1083. /* Count down seconds */
  1084. do {
  1085. /* Count down iterations per second */
  1086. i = n;
  1087. do {
  1088. rtnl_lock();
  1089. rc = ops->set_phys_id(dev,
  1090. (i & 1) ? ETHTOOL_ID_OFF : ETHTOOL_ID_ON);
  1091. rtnl_unlock();
  1092. if (rc)
  1093. break;
  1094. schedule_timeout_interruptible(interval);
  1095. } while (!signal_pending(current) && --i != 0);
  1096. } while (!signal_pending(current) &&
  1097. (id.data == 0 || --id.data != 0));
  1098. }
  1099. rtnl_lock();
  1100. dev_put(dev);
  1101. busy = false;
  1102. (void) ops->set_phys_id(dev, ETHTOOL_ID_INACTIVE);
  1103. return rc;
  1104. }
  1105. static int ethtool_get_stats(struct net_device *dev, void __user *useraddr)
  1106. {
  1107. struct ethtool_stats stats;
  1108. const struct ethtool_ops *ops = dev->ethtool_ops;
  1109. u64 *data;
  1110. int ret, n_stats;
  1111. if (!ops->get_ethtool_stats || !ops->get_sset_count)
  1112. return -EOPNOTSUPP;
  1113. n_stats = ops->get_sset_count(dev, ETH_SS_STATS);
  1114. if (n_stats < 0)
  1115. return n_stats;
  1116. WARN_ON(n_stats == 0);
  1117. if (copy_from_user(&stats, useraddr, sizeof(stats)))
  1118. return -EFAULT;
  1119. stats.n_stats = n_stats;
  1120. if (n_stats) {
  1121. data = kmalloc(n_stats * sizeof(u64), GFP_USER);
  1122. if (!data)
  1123. return -ENOMEM;
  1124. ops->get_ethtool_stats(dev, &stats, data);
  1125. } else {
  1126. data = NULL;
  1127. }
  1128. ret = -EFAULT;
  1129. if (copy_to_user(useraddr, &stats, sizeof(stats)))
  1130. goto out;
  1131. useraddr += sizeof(stats);
  1132. if (n_stats && copy_to_user(useraddr, data, n_stats * sizeof(u64)))
  1133. goto out;
  1134. ret = 0;
  1135. out:
  1136. kfree(data);
  1137. return ret;
  1138. }
  1139. static int ethtool_get_perm_addr(struct net_device *dev, void __user *useraddr)
  1140. {
  1141. struct ethtool_perm_addr epaddr;
  1142. if (copy_from_user(&epaddr, useraddr, sizeof(epaddr)))
  1143. return -EFAULT;
  1144. if (epaddr.size < dev->addr_len)
  1145. return -ETOOSMALL;
  1146. epaddr.size = dev->addr_len;
  1147. if (copy_to_user(useraddr, &epaddr, sizeof(epaddr)))
  1148. return -EFAULT;
  1149. useraddr += sizeof(epaddr);
  1150. if (copy_to_user(useraddr, dev->perm_addr, epaddr.size))
  1151. return -EFAULT;
  1152. return 0;
  1153. }
  1154. static int ethtool_get_value(struct net_device *dev, char __user *useraddr,
  1155. u32 cmd, u32 (*actor)(struct net_device *))
  1156. {
  1157. struct ethtool_value edata = { .cmd = cmd };
  1158. if (!actor)
  1159. return -EOPNOTSUPP;
  1160. edata.data = actor(dev);
  1161. if (copy_to_user(useraddr, &edata, sizeof(edata)))
  1162. return -EFAULT;
  1163. return 0;
  1164. }
  1165. static int ethtool_set_value_void(struct net_device *dev, char __user *useraddr,
  1166. void (*actor)(struct net_device *, u32))
  1167. {
  1168. struct ethtool_value edata;
  1169. if (!actor)
  1170. return -EOPNOTSUPP;
  1171. if (copy_from_user(&edata, useraddr, sizeof(edata)))
  1172. return -EFAULT;
  1173. actor(dev, edata.data);
  1174. return 0;
  1175. }
  1176. static int ethtool_set_value(struct net_device *dev, char __user *useraddr,
  1177. int (*actor)(struct net_device *, u32))
  1178. {
  1179. struct ethtool_value edata;
  1180. if (!actor)
  1181. return -EOPNOTSUPP;
  1182. if (copy_from_user(&edata, useraddr, sizeof(edata)))
  1183. return -EFAULT;
  1184. return actor(dev, edata.data);
  1185. }
  1186. static noinline_for_stack int ethtool_flash_device(struct net_device *dev,
  1187. char __user *useraddr)
  1188. {
  1189. struct ethtool_flash efl;
  1190. if (copy_from_user(&efl, useraddr, sizeof(efl)))
  1191. return -EFAULT;
  1192. if (!dev->ethtool_ops->flash_device)
  1193. return -EOPNOTSUPP;
  1194. efl.data[ETHTOOL_FLASH_MAX_FILENAME - 1] = 0;
  1195. return dev->ethtool_ops->flash_device(dev, &efl);
  1196. }
  1197. static int ethtool_set_dump(struct net_device *dev,
  1198. void __user *useraddr)
  1199. {
  1200. struct ethtool_dump dump;
  1201. if (!dev->ethtool_ops->set_dump)
  1202. return -EOPNOTSUPP;
  1203. if (copy_from_user(&dump, useraddr, sizeof(dump)))
  1204. return -EFAULT;
  1205. return dev->ethtool_ops->set_dump(dev, &dump);
  1206. }
  1207. static int ethtool_get_dump_flag(struct net_device *dev,
  1208. void __user *useraddr)
  1209. {
  1210. int ret;
  1211. struct ethtool_dump dump;
  1212. const struct ethtool_ops *ops = dev->ethtool_ops;
  1213. if (!ops->get_dump_flag)
  1214. return -EOPNOTSUPP;
  1215. if (copy_from_user(&dump, useraddr, sizeof(dump)))
  1216. return -EFAULT;
  1217. ret = ops->get_dump_flag(dev, &dump);
  1218. if (ret)
  1219. return ret;
  1220. if (copy_to_user(useraddr, &dump, sizeof(dump)))
  1221. return -EFAULT;
  1222. return 0;
  1223. }
  1224. static int ethtool_get_dump_data(struct net_device *dev,
  1225. void __user *useraddr)
  1226. {
  1227. int ret;
  1228. __u32 len;
  1229. struct ethtool_dump dump, tmp;
  1230. const struct ethtool_ops *ops = dev->ethtool_ops;
  1231. void *data = NULL;
  1232. if (!ops->get_dump_data || !ops->get_dump_flag)
  1233. return -EOPNOTSUPP;
  1234. if (copy_from_user(&dump, useraddr, sizeof(dump)))
  1235. return -EFAULT;
  1236. memset(&tmp, 0, sizeof(tmp));
  1237. tmp.cmd = ETHTOOL_GET_DUMP_FLAG;
  1238. ret = ops->get_dump_flag(dev, &tmp);
  1239. if (ret)
  1240. return ret;
  1241. len = min(tmp.len, dump.len);
  1242. if (!len)
  1243. return -EFAULT;
  1244. /* Don't ever let the driver think there's more space available
  1245. * than it requested with .get_dump_flag().
  1246. */
  1247. dump.len = len;
  1248. /* Always allocate enough space to hold the whole thing so that the
  1249. * driver does not need to check the length and bother with partial
  1250. * dumping.
  1251. */
  1252. data = vzalloc(tmp.len);
  1253. if (!data)
  1254. return -ENOMEM;
  1255. ret = ops->get_dump_data(dev, &dump, data);
  1256. if (ret)
  1257. goto out;
  1258. /* There are two sane possibilities:
  1259. * 1. The driver's .get_dump_data() does not touch dump.len.
  1260. * 2. Or it may set dump.len to how much it really writes, which
  1261. * should be tmp.len (or len if it can do a partial dump).
  1262. * In any case respond to userspace with the actual length of data
  1263. * it's receiving.
  1264. */
  1265. WARN_ON(dump.len != len && dump.len != tmp.len);
  1266. dump.len = len;
  1267. if (copy_to_user(useraddr, &dump, sizeof(dump))) {
  1268. ret = -EFAULT;
  1269. goto out;
  1270. }
  1271. useraddr += offsetof(struct ethtool_dump, data);
  1272. if (copy_to_user(useraddr, data, len))
  1273. ret = -EFAULT;
  1274. out:
  1275. vfree(data);
  1276. return ret;
  1277. }
  1278. static int ethtool_get_ts_info(struct net_device *dev, void __user *useraddr)
  1279. {
  1280. int err = 0;
  1281. struct ethtool_ts_info info;
  1282. const struct ethtool_ops *ops = dev->ethtool_ops;
  1283. struct phy_device *phydev = dev->phydev;
  1284. memset(&info, 0, sizeof(info));
  1285. info.cmd = ETHTOOL_GET_TS_INFO;
  1286. if (phydev && phydev->drv && phydev->drv->ts_info) {
  1287. err = phydev->drv->ts_info(phydev, &info);
  1288. } else if (ops->get_ts_info) {
  1289. err = ops->get_ts_info(dev, &info);
  1290. } else {
  1291. info.so_timestamping =
  1292. SOF_TIMESTAMPING_RX_SOFTWARE |
  1293. SOF_TIMESTAMPING_SOFTWARE;
  1294. info.phc_index = -1;
  1295. }
  1296. if (err)
  1297. return err;
  1298. if (copy_to_user(useraddr, &info, sizeof(info)))
  1299. err = -EFAULT;
  1300. return err;
  1301. }
  1302. static int __ethtool_get_module_info(struct net_device *dev,
  1303. struct ethtool_modinfo *modinfo)
  1304. {
  1305. const struct ethtool_ops *ops = dev->ethtool_ops;
  1306. struct phy_device *phydev = dev->phydev;
  1307. if (phydev && phydev->drv && phydev->drv->module_info)
  1308. return phydev->drv->module_info(phydev, modinfo);
  1309. if (ops->get_module_info)
  1310. return ops->get_module_info(dev, modinfo);
  1311. return -EOPNOTSUPP;
  1312. }
  1313. static int ethtool_get_module_info(struct net_device *dev,
  1314. void __user *useraddr)
  1315. {
  1316. int ret;
  1317. struct ethtool_modinfo modinfo;
  1318. if (copy_from_user(&modinfo, useraddr, sizeof(modinfo)))
  1319. return -EFAULT;
  1320. ret = __ethtool_get_module_info(dev, &modinfo);
  1321. if (ret)
  1322. return ret;
  1323. if (copy_to_user(useraddr, &modinfo, sizeof(modinfo)))
  1324. return -EFAULT;
  1325. return 0;
  1326. }
  1327. static int __ethtool_get_module_eeprom(struct net_device *dev,
  1328. struct ethtool_eeprom *ee, u8 *data)
  1329. {
  1330. const struct ethtool_ops *ops = dev->ethtool_ops;
  1331. struct phy_device *phydev = dev->phydev;
  1332. if (phydev && phydev->drv && phydev->drv->module_eeprom)
  1333. return phydev->drv->module_eeprom(phydev, ee, data);
  1334. if (ops->get_module_eeprom)
  1335. return ops->get_module_eeprom(dev, ee, data);
  1336. return -EOPNOTSUPP;
  1337. }
  1338. static int ethtool_get_module_eeprom(struct net_device *dev,
  1339. void __user *useraddr)
  1340. {
  1341. int ret;
  1342. struct ethtool_modinfo modinfo;
  1343. ret = __ethtool_get_module_info(dev, &modinfo);
  1344. if (ret)
  1345. return ret;
  1346. return ethtool_get_any_eeprom(dev, useraddr,
  1347. __ethtool_get_module_eeprom,
  1348. modinfo.eeprom_len);
  1349. }
  1350. static int ethtool_tunable_valid(const struct ethtool_tunable *tuna)
  1351. {
  1352. switch (tuna->id) {
  1353. case ETHTOOL_RX_COPYBREAK:
  1354. case ETHTOOL_TX_COPYBREAK:
  1355. if (tuna->len != sizeof(u32) ||
  1356. tuna->type_id != ETHTOOL_TUNABLE_U32)
  1357. return -EINVAL;
  1358. break;
  1359. default:
  1360. return -EINVAL;
  1361. }
  1362. return 0;
  1363. }
  1364. static int ethtool_get_tunable(struct net_device *dev, void __user *useraddr)
  1365. {
  1366. int ret;
  1367. struct ethtool_tunable tuna;
  1368. const struct ethtool_ops *ops = dev->ethtool_ops;
  1369. void *data;
  1370. if (!ops->get_tunable)
  1371. return -EOPNOTSUPP;
  1372. if (copy_from_user(&tuna, useraddr, sizeof(tuna)))
  1373. return -EFAULT;
  1374. ret = ethtool_tunable_valid(&tuna);
  1375. if (ret)
  1376. return ret;
  1377. data = kmalloc(tuna.len, GFP_USER);
  1378. if (!data)
  1379. return -ENOMEM;
  1380. ret = ops->get_tunable(dev, &tuna, data);
  1381. if (ret)
  1382. goto out;
  1383. useraddr += sizeof(tuna);
  1384. ret = -EFAULT;
  1385. if (copy_to_user(useraddr, data, tuna.len))
  1386. goto out;
  1387. ret = 0;
  1388. out:
  1389. kfree(data);
  1390. return ret;
  1391. }
  1392. static int ethtool_set_tunable(struct net_device *dev, void __user *useraddr)
  1393. {
  1394. int ret;
  1395. struct ethtool_tunable tuna;
  1396. const struct ethtool_ops *ops = dev->ethtool_ops;
  1397. void *data;
  1398. if (!ops->set_tunable)
  1399. return -EOPNOTSUPP;
  1400. if (copy_from_user(&tuna, useraddr, sizeof(tuna)))
  1401. return -EFAULT;
  1402. ret = ethtool_tunable_valid(&tuna);
  1403. if (ret)
  1404. return ret;
  1405. data = kmalloc(tuna.len, GFP_USER);
  1406. if (!data)
  1407. return -ENOMEM;
  1408. useraddr += sizeof(tuna);
  1409. ret = -EFAULT;
  1410. if (copy_from_user(data, useraddr, tuna.len))
  1411. goto out;
  1412. ret = ops->set_tunable(dev, &tuna, data);
  1413. out:
  1414. kfree(data);
  1415. return ret;
  1416. }
  1417. /* The main entry point in this file. Called from net/core/dev_ioctl.c */
  1418. int dev_ethtool(struct net *net, struct ifreq *ifr)
  1419. {
  1420. struct net_device *dev = __dev_get_by_name(net, ifr->ifr_name);
  1421. void __user *useraddr = ifr->ifr_data;
  1422. u32 ethcmd;
  1423. int rc;
  1424. netdev_features_t old_features;
  1425. if (!dev || !netif_device_present(dev))
  1426. return -ENODEV;
  1427. if (copy_from_user(&ethcmd, useraddr, sizeof(ethcmd)))
  1428. return -EFAULT;
  1429. /* Allow some commands to be done by anyone */
  1430. switch (ethcmd) {
  1431. case ETHTOOL_GSET:
  1432. case ETHTOOL_GDRVINFO:
  1433. case ETHTOOL_GMSGLVL:
  1434. case ETHTOOL_GLINK:
  1435. case ETHTOOL_GCOALESCE:
  1436. case ETHTOOL_GRINGPARAM:
  1437. case ETHTOOL_GPAUSEPARAM:
  1438. case ETHTOOL_GRXCSUM:
  1439. case ETHTOOL_GTXCSUM:
  1440. case ETHTOOL_GSG:
  1441. case ETHTOOL_GSSET_INFO:
  1442. case ETHTOOL_GSTRINGS:
  1443. case ETHTOOL_GSTATS:
  1444. case ETHTOOL_GTSO:
  1445. case ETHTOOL_GPERMADDR:
  1446. case ETHTOOL_GUFO:
  1447. case ETHTOOL_GGSO:
  1448. case ETHTOOL_GGRO:
  1449. case ETHTOOL_GFLAGS:
  1450. case ETHTOOL_GPFLAGS:
  1451. case ETHTOOL_GRXFH:
  1452. case ETHTOOL_GRXRINGS:
  1453. case ETHTOOL_GRXCLSRLCNT:
  1454. case ETHTOOL_GRXCLSRULE:
  1455. case ETHTOOL_GRXCLSRLALL:
  1456. case ETHTOOL_GRXFHINDIR:
  1457. case ETHTOOL_GRSSH:
  1458. case ETHTOOL_GFEATURES:
  1459. case ETHTOOL_GCHANNELS:
  1460. case ETHTOOL_GET_TS_INFO:
  1461. case ETHTOOL_GEEE:
  1462. case ETHTOOL_GTUNABLE:
  1463. break;
  1464. default:
  1465. if (!ns_capable(net->user_ns, CAP_NET_ADMIN))
  1466. return -EPERM;
  1467. }
  1468. if (dev->ethtool_ops->begin) {
  1469. rc = dev->ethtool_ops->begin(dev);
  1470. if (rc < 0)
  1471. return rc;
  1472. }
  1473. old_features = dev->features;
  1474. switch (ethcmd) {
  1475. case ETHTOOL_GSET:
  1476. rc = ethtool_get_settings(dev, useraddr);
  1477. break;
  1478. case ETHTOOL_SSET:
  1479. rc = ethtool_set_settings(dev, useraddr);
  1480. break;
  1481. case ETHTOOL_GDRVINFO:
  1482. rc = ethtool_get_drvinfo(dev, useraddr);
  1483. break;
  1484. case ETHTOOL_GREGS:
  1485. rc = ethtool_get_regs(dev, useraddr);
  1486. break;
  1487. case ETHTOOL_GWOL:
  1488. rc = ethtool_get_wol(dev, useraddr);
  1489. break;
  1490. case ETHTOOL_SWOL:
  1491. rc = ethtool_set_wol(dev, useraddr);
  1492. break;
  1493. case ETHTOOL_GMSGLVL:
  1494. rc = ethtool_get_value(dev, useraddr, ethcmd,
  1495. dev->ethtool_ops->get_msglevel);
  1496. break;
  1497. case ETHTOOL_SMSGLVL:
  1498. rc = ethtool_set_value_void(dev, useraddr,
  1499. dev->ethtool_ops->set_msglevel);
  1500. break;
  1501. case ETHTOOL_GEEE:
  1502. rc = ethtool_get_eee(dev, useraddr);
  1503. break;
  1504. case ETHTOOL_SEEE:
  1505. rc = ethtool_set_eee(dev, useraddr);
  1506. break;
  1507. case ETHTOOL_NWAY_RST:
  1508. rc = ethtool_nway_reset(dev);
  1509. break;
  1510. case ETHTOOL_GLINK:
  1511. rc = ethtool_get_link(dev, useraddr);
  1512. break;
  1513. case ETHTOOL_GEEPROM:
  1514. rc = ethtool_get_eeprom(dev, useraddr);
  1515. break;
  1516. case ETHTOOL_SEEPROM:
  1517. rc = ethtool_set_eeprom(dev, useraddr);
  1518. break;
  1519. case ETHTOOL_GCOALESCE:
  1520. rc = ethtool_get_coalesce(dev, useraddr);
  1521. break;
  1522. case ETHTOOL_SCOALESCE:
  1523. rc = ethtool_set_coalesce(dev, useraddr);
  1524. break;
  1525. case ETHTOOL_GRINGPARAM:
  1526. rc = ethtool_get_ringparam(dev, useraddr);
  1527. break;
  1528. case ETHTOOL_SRINGPARAM:
  1529. rc = ethtool_set_ringparam(dev, useraddr);
  1530. break;
  1531. case ETHTOOL_GPAUSEPARAM:
  1532. rc = ethtool_get_pauseparam(dev, useraddr);
  1533. break;
  1534. case ETHTOOL_SPAUSEPARAM:
  1535. rc = ethtool_set_pauseparam(dev, useraddr);
  1536. break;
  1537. case ETHTOOL_TEST:
  1538. rc = ethtool_self_test(dev, useraddr);
  1539. break;
  1540. case ETHTOOL_GSTRINGS:
  1541. rc = ethtool_get_strings(dev, useraddr);
  1542. break;
  1543. case ETHTOOL_PHYS_ID:
  1544. rc = ethtool_phys_id(dev, useraddr);
  1545. break;
  1546. case ETHTOOL_GSTATS:
  1547. rc = ethtool_get_stats(dev, useraddr);
  1548. break;
  1549. case ETHTOOL_GPERMADDR:
  1550. rc = ethtool_get_perm_addr(dev, useraddr);
  1551. break;
  1552. case ETHTOOL_GFLAGS:
  1553. rc = ethtool_get_value(dev, useraddr, ethcmd,
  1554. __ethtool_get_flags);
  1555. break;
  1556. case ETHTOOL_SFLAGS:
  1557. rc = ethtool_set_value(dev, useraddr, __ethtool_set_flags);
  1558. break;
  1559. case ETHTOOL_GPFLAGS:
  1560. rc = ethtool_get_value(dev, useraddr, ethcmd,
  1561. dev->ethtool_ops->get_priv_flags);
  1562. break;
  1563. case ETHTOOL_SPFLAGS:
  1564. rc = ethtool_set_value(dev, useraddr,
  1565. dev->ethtool_ops->set_priv_flags);
  1566. break;
  1567. case ETHTOOL_GRXFH:
  1568. case ETHTOOL_GRXRINGS:
  1569. case ETHTOOL_GRXCLSRLCNT:
  1570. case ETHTOOL_GRXCLSRULE:
  1571. case ETHTOOL_GRXCLSRLALL:
  1572. rc = ethtool_get_rxnfc(dev, ethcmd, useraddr);
  1573. break;
  1574. case ETHTOOL_SRXFH:
  1575. case ETHTOOL_SRXCLSRLDEL:
  1576. case ETHTOOL_SRXCLSRLINS:
  1577. rc = ethtool_set_rxnfc(dev, ethcmd, useraddr);
  1578. break;
  1579. case ETHTOOL_FLASHDEV:
  1580. rc = ethtool_flash_device(dev, useraddr);
  1581. break;
  1582. case ETHTOOL_RESET:
  1583. rc = ethtool_reset(dev, useraddr);
  1584. break;
  1585. case ETHTOOL_GSSET_INFO:
  1586. rc = ethtool_get_sset_info(dev, useraddr);
  1587. break;
  1588. case ETHTOOL_GRXFHINDIR:
  1589. rc = ethtool_get_rxfh_indir(dev, useraddr);
  1590. break;
  1591. case ETHTOOL_SRXFHINDIR:
  1592. rc = ethtool_set_rxfh_indir(dev, useraddr);
  1593. break;
  1594. case ETHTOOL_GRSSH:
  1595. rc = ethtool_get_rxfh(dev, useraddr);
  1596. break;
  1597. case ETHTOOL_SRSSH:
  1598. rc = ethtool_set_rxfh(dev, useraddr);
  1599. break;
  1600. case ETHTOOL_GFEATURES:
  1601. rc = ethtool_get_features(dev, useraddr);
  1602. break;
  1603. case ETHTOOL_SFEATURES:
  1604. rc = ethtool_set_features(dev, useraddr);
  1605. break;
  1606. case ETHTOOL_GTXCSUM:
  1607. case ETHTOOL_GRXCSUM:
  1608. case ETHTOOL_GSG:
  1609. case ETHTOOL_GTSO:
  1610. case ETHTOOL_GUFO:
  1611. case ETHTOOL_GGSO:
  1612. case ETHTOOL_GGRO:
  1613. rc = ethtool_get_one_feature(dev, useraddr, ethcmd);
  1614. break;
  1615. case ETHTOOL_STXCSUM:
  1616. case ETHTOOL_SRXCSUM:
  1617. case ETHTOOL_SSG:
  1618. case ETHTOOL_STSO:
  1619. case ETHTOOL_SUFO:
  1620. case ETHTOOL_SGSO:
  1621. case ETHTOOL_SGRO:
  1622. rc = ethtool_set_one_feature(dev, useraddr, ethcmd);
  1623. break;
  1624. case ETHTOOL_GCHANNELS:
  1625. rc = ethtool_get_channels(dev, useraddr);
  1626. break;
  1627. case ETHTOOL_SCHANNELS:
  1628. rc = ethtool_set_channels(dev, useraddr);
  1629. break;
  1630. case ETHTOOL_SET_DUMP:
  1631. rc = ethtool_set_dump(dev, useraddr);
  1632. break;
  1633. case ETHTOOL_GET_DUMP_FLAG:
  1634. rc = ethtool_get_dump_flag(dev, useraddr);
  1635. break;
  1636. case ETHTOOL_GET_DUMP_DATA:
  1637. rc = ethtool_get_dump_data(dev, useraddr);
  1638. break;
  1639. case ETHTOOL_GET_TS_INFO:
  1640. rc = ethtool_get_ts_info(dev, useraddr);
  1641. break;
  1642. case ETHTOOL_GMODULEINFO:
  1643. rc = ethtool_get_module_info(dev, useraddr);
  1644. break;
  1645. case ETHTOOL_GMODULEEEPROM:
  1646. rc = ethtool_get_module_eeprom(dev, useraddr);
  1647. break;
  1648. case ETHTOOL_GTUNABLE:
  1649. rc = ethtool_get_tunable(dev, useraddr);
  1650. break;
  1651. case ETHTOOL_STUNABLE:
  1652. rc = ethtool_set_tunable(dev, useraddr);
  1653. break;
  1654. default:
  1655. rc = -EOPNOTSUPP;
  1656. }
  1657. if (dev->ethtool_ops->complete)
  1658. dev->ethtool_ops->complete(dev);
  1659. if (old_features != dev->features)
  1660. netdev_features_change(dev);
  1661. return rc;
  1662. }