ethtool.c 47 KB

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