ethtool.c 47 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965
  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 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. u8 netdev_rss_key[NETDEV_RSS_KEY_LEN];
  476. void netdev_rss_key_fill(void *buffer, size_t len)
  477. {
  478. BUG_ON(len > sizeof(netdev_rss_key));
  479. net_get_random_once(netdev_rss_key, sizeof(netdev_rss_key));
  480. memcpy(buffer, netdev_rss_key, len);
  481. }
  482. EXPORT_SYMBOL(netdev_rss_key_fill);
  483. static noinline_for_stack int ethtool_get_rxfh_indir(struct net_device *dev,
  484. void __user *useraddr)
  485. {
  486. u32 user_size, dev_size;
  487. u32 *indir;
  488. int ret;
  489. if (!dev->ethtool_ops->get_rxfh_indir_size ||
  490. !dev->ethtool_ops->get_rxfh)
  491. return -EOPNOTSUPP;
  492. dev_size = dev->ethtool_ops->get_rxfh_indir_size(dev);
  493. if (dev_size == 0)
  494. return -EOPNOTSUPP;
  495. if (copy_from_user(&user_size,
  496. useraddr + offsetof(struct ethtool_rxfh_indir, size),
  497. sizeof(user_size)))
  498. return -EFAULT;
  499. if (copy_to_user(useraddr + offsetof(struct ethtool_rxfh_indir, size),
  500. &dev_size, sizeof(dev_size)))
  501. return -EFAULT;
  502. /* If the user buffer size is 0, this is just a query for the
  503. * device table size. Otherwise, if it's smaller than the
  504. * device table size it's an error.
  505. */
  506. if (user_size < dev_size)
  507. return user_size == 0 ? 0 : -EINVAL;
  508. indir = kcalloc(dev_size, sizeof(indir[0]), GFP_USER);
  509. if (!indir)
  510. return -ENOMEM;
  511. ret = dev->ethtool_ops->get_rxfh(dev, indir, NULL);
  512. if (ret)
  513. goto out;
  514. if (copy_to_user(useraddr +
  515. offsetof(struct ethtool_rxfh_indir, ring_index[0]),
  516. indir, dev_size * sizeof(indir[0])))
  517. ret = -EFAULT;
  518. out:
  519. kfree(indir);
  520. return ret;
  521. }
  522. static noinline_for_stack int ethtool_set_rxfh_indir(struct net_device *dev,
  523. void __user *useraddr)
  524. {
  525. struct ethtool_rxnfc rx_rings;
  526. u32 user_size, dev_size, i;
  527. u32 *indir;
  528. const struct ethtool_ops *ops = dev->ethtool_ops;
  529. int ret;
  530. u32 ringidx_offset = offsetof(struct ethtool_rxfh_indir, ring_index[0]);
  531. if (!ops->get_rxfh_indir_size || !ops->set_rxfh ||
  532. !ops->get_rxnfc)
  533. return -EOPNOTSUPP;
  534. dev_size = ops->get_rxfh_indir_size(dev);
  535. if (dev_size == 0)
  536. return -EOPNOTSUPP;
  537. if (copy_from_user(&user_size,
  538. useraddr + offsetof(struct ethtool_rxfh_indir, size),
  539. sizeof(user_size)))
  540. return -EFAULT;
  541. if (user_size != 0 && user_size != dev_size)
  542. return -EINVAL;
  543. indir = kcalloc(dev_size, sizeof(indir[0]), GFP_USER);
  544. if (!indir)
  545. return -ENOMEM;
  546. rx_rings.cmd = ETHTOOL_GRXRINGS;
  547. ret = ops->get_rxnfc(dev, &rx_rings, NULL);
  548. if (ret)
  549. goto out;
  550. if (user_size == 0) {
  551. for (i = 0; i < dev_size; i++)
  552. indir[i] = ethtool_rxfh_indir_default(i, rx_rings.data);
  553. } else {
  554. ret = ethtool_copy_validate_indir(indir,
  555. useraddr + ringidx_offset,
  556. &rx_rings,
  557. dev_size);
  558. if (ret)
  559. goto out;
  560. }
  561. ret = ops->set_rxfh(dev, indir, NULL);
  562. out:
  563. kfree(indir);
  564. return ret;
  565. }
  566. static noinline_for_stack int ethtool_get_rxfh(struct net_device *dev,
  567. void __user *useraddr)
  568. {
  569. int ret;
  570. const struct ethtool_ops *ops = dev->ethtool_ops;
  571. u32 user_indir_size, user_key_size;
  572. u32 dev_indir_size = 0, dev_key_size = 0;
  573. struct ethtool_rxfh rxfh;
  574. u32 total_size;
  575. u32 indir_bytes;
  576. u32 *indir = NULL;
  577. u8 *hkey = NULL;
  578. u8 *rss_config;
  579. if (!(dev->ethtool_ops->get_rxfh_indir_size ||
  580. dev->ethtool_ops->get_rxfh_key_size) ||
  581. !dev->ethtool_ops->get_rxfh)
  582. return -EOPNOTSUPP;
  583. if (ops->get_rxfh_indir_size)
  584. dev_indir_size = ops->get_rxfh_indir_size(dev);
  585. if (ops->get_rxfh_key_size)
  586. dev_key_size = ops->get_rxfh_key_size(dev);
  587. if ((dev_key_size + dev_indir_size) == 0)
  588. return -EOPNOTSUPP;
  589. if (copy_from_user(&rxfh, useraddr, sizeof(rxfh)))
  590. return -EFAULT;
  591. user_indir_size = rxfh.indir_size;
  592. user_key_size = rxfh.key_size;
  593. /* Check that reserved fields are 0 for now */
  594. if (rxfh.rss_context || rxfh.rsvd[0] || rxfh.rsvd[1])
  595. return -EINVAL;
  596. rxfh.indir_size = dev_indir_size;
  597. rxfh.key_size = dev_key_size;
  598. if (copy_to_user(useraddr, &rxfh, sizeof(rxfh)))
  599. return -EFAULT;
  600. /* If the user buffer size is 0, this is just a query for the
  601. * device table size and key size. Otherwise, if the User size is
  602. * not equal to device table size or key size it's an error.
  603. */
  604. if (!user_indir_size && !user_key_size)
  605. return 0;
  606. if ((user_indir_size && (user_indir_size != dev_indir_size)) ||
  607. (user_key_size && (user_key_size != dev_key_size)))
  608. return -EINVAL;
  609. indir_bytes = user_indir_size * sizeof(indir[0]);
  610. total_size = indir_bytes + user_key_size;
  611. rss_config = kzalloc(total_size, GFP_USER);
  612. if (!rss_config)
  613. return -ENOMEM;
  614. if (user_indir_size)
  615. indir = (u32 *)rss_config;
  616. if (user_key_size)
  617. hkey = rss_config + indir_bytes;
  618. ret = dev->ethtool_ops->get_rxfh(dev, indir, hkey);
  619. if (!ret) {
  620. if (copy_to_user(useraddr +
  621. offsetof(struct ethtool_rxfh, rss_config[0]),
  622. rss_config, total_size))
  623. ret = -EFAULT;
  624. }
  625. kfree(rss_config);
  626. return ret;
  627. }
  628. static noinline_for_stack int ethtool_set_rxfh(struct net_device *dev,
  629. void __user *useraddr)
  630. {
  631. int ret;
  632. const struct ethtool_ops *ops = dev->ethtool_ops;
  633. struct ethtool_rxnfc rx_rings;
  634. struct ethtool_rxfh rxfh;
  635. u32 dev_indir_size = 0, dev_key_size = 0, i;
  636. u32 *indir = NULL, indir_bytes = 0;
  637. u8 *hkey = NULL;
  638. u8 *rss_config;
  639. u32 rss_cfg_offset = offsetof(struct ethtool_rxfh, rss_config[0]);
  640. if (!(ops->get_rxfh_indir_size || ops->get_rxfh_key_size) ||
  641. !ops->get_rxnfc || !ops->set_rxfh)
  642. return -EOPNOTSUPP;
  643. if (ops->get_rxfh_indir_size)
  644. dev_indir_size = ops->get_rxfh_indir_size(dev);
  645. if (ops->get_rxfh_key_size)
  646. dev_key_size = dev->ethtool_ops->get_rxfh_key_size(dev);
  647. if ((dev_key_size + dev_indir_size) == 0)
  648. return -EOPNOTSUPP;
  649. if (copy_from_user(&rxfh, useraddr, sizeof(rxfh)))
  650. return -EFAULT;
  651. /* Check that reserved fields are 0 for now */
  652. if (rxfh.rss_context || rxfh.rsvd[0] || rxfh.rsvd[1])
  653. return -EINVAL;
  654. /* If either indir or hash key is valid, proceed further.
  655. * It is not valid to request that both be unchanged.
  656. */
  657. if ((rxfh.indir_size &&
  658. rxfh.indir_size != ETH_RXFH_INDIR_NO_CHANGE &&
  659. rxfh.indir_size != dev_indir_size) ||
  660. (rxfh.key_size && (rxfh.key_size != dev_key_size)) ||
  661. (rxfh.indir_size == ETH_RXFH_INDIR_NO_CHANGE &&
  662. rxfh.key_size == 0))
  663. return -EINVAL;
  664. if (rxfh.indir_size != ETH_RXFH_INDIR_NO_CHANGE)
  665. indir_bytes = dev_indir_size * sizeof(indir[0]);
  666. rss_config = kzalloc(indir_bytes + rxfh.key_size, GFP_USER);
  667. if (!rss_config)
  668. return -ENOMEM;
  669. rx_rings.cmd = ETHTOOL_GRXRINGS;
  670. ret = ops->get_rxnfc(dev, &rx_rings, NULL);
  671. if (ret)
  672. goto out;
  673. /* rxfh.indir_size == 0 means reset the indir table to default.
  674. * rxfh.indir_size == ETH_RXFH_INDIR_NO_CHANGE means leave it unchanged.
  675. */
  676. if (rxfh.indir_size &&
  677. rxfh.indir_size != ETH_RXFH_INDIR_NO_CHANGE) {
  678. indir = (u32 *)rss_config;
  679. ret = ethtool_copy_validate_indir(indir,
  680. useraddr + rss_cfg_offset,
  681. &rx_rings,
  682. rxfh.indir_size);
  683. if (ret)
  684. goto out;
  685. } else if (rxfh.indir_size == 0) {
  686. indir = (u32 *)rss_config;
  687. for (i = 0; i < dev_indir_size; i++)
  688. indir[i] = ethtool_rxfh_indir_default(i, rx_rings.data);
  689. }
  690. if (rxfh.key_size) {
  691. hkey = rss_config + indir_bytes;
  692. if (copy_from_user(hkey,
  693. useraddr + rss_cfg_offset + indir_bytes,
  694. rxfh.key_size)) {
  695. ret = -EFAULT;
  696. goto out;
  697. }
  698. }
  699. ret = ops->set_rxfh(dev, indir, hkey);
  700. out:
  701. kfree(rss_config);
  702. return ret;
  703. }
  704. static int ethtool_get_regs(struct net_device *dev, char __user *useraddr)
  705. {
  706. struct ethtool_regs regs;
  707. const struct ethtool_ops *ops = dev->ethtool_ops;
  708. void *regbuf;
  709. int reglen, ret;
  710. if (!ops->get_regs || !ops->get_regs_len)
  711. return -EOPNOTSUPP;
  712. if (copy_from_user(&regs, useraddr, sizeof(regs)))
  713. return -EFAULT;
  714. reglen = ops->get_regs_len(dev);
  715. if (regs.len > reglen)
  716. regs.len = reglen;
  717. regbuf = vzalloc(reglen);
  718. if (reglen && !regbuf)
  719. return -ENOMEM;
  720. ops->get_regs(dev, &regs, regbuf);
  721. ret = -EFAULT;
  722. if (copy_to_user(useraddr, &regs, sizeof(regs)))
  723. goto out;
  724. useraddr += offsetof(struct ethtool_regs, data);
  725. if (regbuf && copy_to_user(useraddr, regbuf, regs.len))
  726. goto out;
  727. ret = 0;
  728. out:
  729. vfree(regbuf);
  730. return ret;
  731. }
  732. static int ethtool_reset(struct net_device *dev, char __user *useraddr)
  733. {
  734. struct ethtool_value reset;
  735. int ret;
  736. if (!dev->ethtool_ops->reset)
  737. return -EOPNOTSUPP;
  738. if (copy_from_user(&reset, useraddr, sizeof(reset)))
  739. return -EFAULT;
  740. ret = dev->ethtool_ops->reset(dev, &reset.data);
  741. if (ret)
  742. return ret;
  743. if (copy_to_user(useraddr, &reset, sizeof(reset)))
  744. return -EFAULT;
  745. return 0;
  746. }
  747. static int ethtool_get_wol(struct net_device *dev, char __user *useraddr)
  748. {
  749. struct ethtool_wolinfo wol = { .cmd = ETHTOOL_GWOL };
  750. if (!dev->ethtool_ops->get_wol)
  751. return -EOPNOTSUPP;
  752. dev->ethtool_ops->get_wol(dev, &wol);
  753. if (copy_to_user(useraddr, &wol, sizeof(wol)))
  754. return -EFAULT;
  755. return 0;
  756. }
  757. static int ethtool_set_wol(struct net_device *dev, char __user *useraddr)
  758. {
  759. struct ethtool_wolinfo wol;
  760. if (!dev->ethtool_ops->set_wol)
  761. return -EOPNOTSUPP;
  762. if (copy_from_user(&wol, useraddr, sizeof(wol)))
  763. return -EFAULT;
  764. return dev->ethtool_ops->set_wol(dev, &wol);
  765. }
  766. static int ethtool_get_eee(struct net_device *dev, char __user *useraddr)
  767. {
  768. struct ethtool_eee edata;
  769. int rc;
  770. if (!dev->ethtool_ops->get_eee)
  771. return -EOPNOTSUPP;
  772. memset(&edata, 0, sizeof(struct ethtool_eee));
  773. edata.cmd = ETHTOOL_GEEE;
  774. rc = dev->ethtool_ops->get_eee(dev, &edata);
  775. if (rc)
  776. return rc;
  777. if (copy_to_user(useraddr, &edata, sizeof(edata)))
  778. return -EFAULT;
  779. return 0;
  780. }
  781. static int ethtool_set_eee(struct net_device *dev, char __user *useraddr)
  782. {
  783. struct ethtool_eee edata;
  784. if (!dev->ethtool_ops->set_eee)
  785. return -EOPNOTSUPP;
  786. if (copy_from_user(&edata, useraddr, sizeof(edata)))
  787. return -EFAULT;
  788. return dev->ethtool_ops->set_eee(dev, &edata);
  789. }
  790. static int ethtool_nway_reset(struct net_device *dev)
  791. {
  792. if (!dev->ethtool_ops->nway_reset)
  793. return -EOPNOTSUPP;
  794. return dev->ethtool_ops->nway_reset(dev);
  795. }
  796. static int ethtool_get_link(struct net_device *dev, char __user *useraddr)
  797. {
  798. struct ethtool_value edata = { .cmd = ETHTOOL_GLINK };
  799. if (!dev->ethtool_ops->get_link)
  800. return -EOPNOTSUPP;
  801. edata.data = netif_running(dev) && dev->ethtool_ops->get_link(dev);
  802. if (copy_to_user(useraddr, &edata, sizeof(edata)))
  803. return -EFAULT;
  804. return 0;
  805. }
  806. static int ethtool_get_any_eeprom(struct net_device *dev, void __user *useraddr,
  807. int (*getter)(struct net_device *,
  808. struct ethtool_eeprom *, u8 *),
  809. u32 total_len)
  810. {
  811. struct ethtool_eeprom eeprom;
  812. void __user *userbuf = useraddr + sizeof(eeprom);
  813. u32 bytes_remaining;
  814. u8 *data;
  815. int ret = 0;
  816. if (copy_from_user(&eeprom, useraddr, sizeof(eeprom)))
  817. return -EFAULT;
  818. /* Check for wrap and zero */
  819. if (eeprom.offset + eeprom.len <= eeprom.offset)
  820. return -EINVAL;
  821. /* Check for exceeding total eeprom len */
  822. if (eeprom.offset + eeprom.len > total_len)
  823. return -EINVAL;
  824. data = kmalloc(PAGE_SIZE, GFP_USER);
  825. if (!data)
  826. return -ENOMEM;
  827. bytes_remaining = eeprom.len;
  828. while (bytes_remaining > 0) {
  829. eeprom.len = min(bytes_remaining, (u32)PAGE_SIZE);
  830. ret = getter(dev, &eeprom, data);
  831. if (ret)
  832. break;
  833. if (copy_to_user(userbuf, data, eeprom.len)) {
  834. ret = -EFAULT;
  835. break;
  836. }
  837. userbuf += eeprom.len;
  838. eeprom.offset += eeprom.len;
  839. bytes_remaining -= eeprom.len;
  840. }
  841. eeprom.len = userbuf - (useraddr + sizeof(eeprom));
  842. eeprom.offset -= eeprom.len;
  843. if (copy_to_user(useraddr, &eeprom, sizeof(eeprom)))
  844. ret = -EFAULT;
  845. kfree(data);
  846. return ret;
  847. }
  848. static int ethtool_get_eeprom(struct net_device *dev, void __user *useraddr)
  849. {
  850. const struct ethtool_ops *ops = dev->ethtool_ops;
  851. if (!ops->get_eeprom || !ops->get_eeprom_len ||
  852. !ops->get_eeprom_len(dev))
  853. return -EOPNOTSUPP;
  854. return ethtool_get_any_eeprom(dev, useraddr, ops->get_eeprom,
  855. ops->get_eeprom_len(dev));
  856. }
  857. static int ethtool_set_eeprom(struct net_device *dev, void __user *useraddr)
  858. {
  859. struct ethtool_eeprom eeprom;
  860. const struct ethtool_ops *ops = dev->ethtool_ops;
  861. void __user *userbuf = useraddr + sizeof(eeprom);
  862. u32 bytes_remaining;
  863. u8 *data;
  864. int ret = 0;
  865. if (!ops->set_eeprom || !ops->get_eeprom_len ||
  866. !ops->get_eeprom_len(dev))
  867. return -EOPNOTSUPP;
  868. if (copy_from_user(&eeprom, useraddr, sizeof(eeprom)))
  869. return -EFAULT;
  870. /* Check for wrap and zero */
  871. if (eeprom.offset + eeprom.len <= eeprom.offset)
  872. return -EINVAL;
  873. /* Check for exceeding total eeprom len */
  874. if (eeprom.offset + eeprom.len > ops->get_eeprom_len(dev))
  875. return -EINVAL;
  876. data = kmalloc(PAGE_SIZE, GFP_USER);
  877. if (!data)
  878. return -ENOMEM;
  879. bytes_remaining = eeprom.len;
  880. while (bytes_remaining > 0) {
  881. eeprom.len = min(bytes_remaining, (u32)PAGE_SIZE);
  882. if (copy_from_user(data, userbuf, eeprom.len)) {
  883. ret = -EFAULT;
  884. break;
  885. }
  886. ret = ops->set_eeprom(dev, &eeprom, data);
  887. if (ret)
  888. break;
  889. userbuf += eeprom.len;
  890. eeprom.offset += eeprom.len;
  891. bytes_remaining -= eeprom.len;
  892. }
  893. kfree(data);
  894. return ret;
  895. }
  896. static noinline_for_stack int ethtool_get_coalesce(struct net_device *dev,
  897. void __user *useraddr)
  898. {
  899. struct ethtool_coalesce coalesce = { .cmd = ETHTOOL_GCOALESCE };
  900. if (!dev->ethtool_ops->get_coalesce)
  901. return -EOPNOTSUPP;
  902. dev->ethtool_ops->get_coalesce(dev, &coalesce);
  903. if (copy_to_user(useraddr, &coalesce, sizeof(coalesce)))
  904. return -EFAULT;
  905. return 0;
  906. }
  907. static noinline_for_stack int ethtool_set_coalesce(struct net_device *dev,
  908. void __user *useraddr)
  909. {
  910. struct ethtool_coalesce coalesce;
  911. if (!dev->ethtool_ops->set_coalesce)
  912. return -EOPNOTSUPP;
  913. if (copy_from_user(&coalesce, useraddr, sizeof(coalesce)))
  914. return -EFAULT;
  915. return dev->ethtool_ops->set_coalesce(dev, &coalesce);
  916. }
  917. static int ethtool_get_ringparam(struct net_device *dev, void __user *useraddr)
  918. {
  919. struct ethtool_ringparam ringparam = { .cmd = ETHTOOL_GRINGPARAM };
  920. if (!dev->ethtool_ops->get_ringparam)
  921. return -EOPNOTSUPP;
  922. dev->ethtool_ops->get_ringparam(dev, &ringparam);
  923. if (copy_to_user(useraddr, &ringparam, sizeof(ringparam)))
  924. return -EFAULT;
  925. return 0;
  926. }
  927. static int ethtool_set_ringparam(struct net_device *dev, void __user *useraddr)
  928. {
  929. struct ethtool_ringparam ringparam;
  930. if (!dev->ethtool_ops->set_ringparam)
  931. return -EOPNOTSUPP;
  932. if (copy_from_user(&ringparam, useraddr, sizeof(ringparam)))
  933. return -EFAULT;
  934. return dev->ethtool_ops->set_ringparam(dev, &ringparam);
  935. }
  936. static noinline_for_stack int ethtool_get_channels(struct net_device *dev,
  937. void __user *useraddr)
  938. {
  939. struct ethtool_channels channels = { .cmd = ETHTOOL_GCHANNELS };
  940. if (!dev->ethtool_ops->get_channels)
  941. return -EOPNOTSUPP;
  942. dev->ethtool_ops->get_channels(dev, &channels);
  943. if (copy_to_user(useraddr, &channels, sizeof(channels)))
  944. return -EFAULT;
  945. return 0;
  946. }
  947. static noinline_for_stack int ethtool_set_channels(struct net_device *dev,
  948. void __user *useraddr)
  949. {
  950. struct ethtool_channels channels;
  951. if (!dev->ethtool_ops->set_channels)
  952. return -EOPNOTSUPP;
  953. if (copy_from_user(&channels, useraddr, sizeof(channels)))
  954. return -EFAULT;
  955. return dev->ethtool_ops->set_channels(dev, &channels);
  956. }
  957. static int ethtool_get_pauseparam(struct net_device *dev, void __user *useraddr)
  958. {
  959. struct ethtool_pauseparam pauseparam = { ETHTOOL_GPAUSEPARAM };
  960. if (!dev->ethtool_ops->get_pauseparam)
  961. return -EOPNOTSUPP;
  962. dev->ethtool_ops->get_pauseparam(dev, &pauseparam);
  963. if (copy_to_user(useraddr, &pauseparam, sizeof(pauseparam)))
  964. return -EFAULT;
  965. return 0;
  966. }
  967. static int ethtool_set_pauseparam(struct net_device *dev, void __user *useraddr)
  968. {
  969. struct ethtool_pauseparam pauseparam;
  970. if (!dev->ethtool_ops->set_pauseparam)
  971. return -EOPNOTSUPP;
  972. if (copy_from_user(&pauseparam, useraddr, sizeof(pauseparam)))
  973. return -EFAULT;
  974. return dev->ethtool_ops->set_pauseparam(dev, &pauseparam);
  975. }
  976. static int ethtool_self_test(struct net_device *dev, char __user *useraddr)
  977. {
  978. struct ethtool_test test;
  979. const struct ethtool_ops *ops = dev->ethtool_ops;
  980. u64 *data;
  981. int ret, test_len;
  982. if (!ops->self_test || !ops->get_sset_count)
  983. return -EOPNOTSUPP;
  984. test_len = ops->get_sset_count(dev, ETH_SS_TEST);
  985. if (test_len < 0)
  986. return test_len;
  987. WARN_ON(test_len == 0);
  988. if (copy_from_user(&test, useraddr, sizeof(test)))
  989. return -EFAULT;
  990. test.len = test_len;
  991. data = kmalloc(test_len * sizeof(u64), GFP_USER);
  992. if (!data)
  993. return -ENOMEM;
  994. ops->self_test(dev, &test, data);
  995. ret = -EFAULT;
  996. if (copy_to_user(useraddr, &test, sizeof(test)))
  997. goto out;
  998. useraddr += sizeof(test);
  999. if (copy_to_user(useraddr, data, test.len * sizeof(u64)))
  1000. goto out;
  1001. ret = 0;
  1002. out:
  1003. kfree(data);
  1004. return ret;
  1005. }
  1006. static int ethtool_get_strings(struct net_device *dev, void __user *useraddr)
  1007. {
  1008. struct ethtool_gstrings gstrings;
  1009. u8 *data;
  1010. int ret;
  1011. if (copy_from_user(&gstrings, useraddr, sizeof(gstrings)))
  1012. return -EFAULT;
  1013. ret = __ethtool_get_sset_count(dev, gstrings.string_set);
  1014. if (ret < 0)
  1015. return ret;
  1016. gstrings.len = ret;
  1017. data = kmalloc(gstrings.len * ETH_GSTRING_LEN, GFP_USER);
  1018. if (!data)
  1019. return -ENOMEM;
  1020. __ethtool_get_strings(dev, gstrings.string_set, data);
  1021. ret = -EFAULT;
  1022. if (copy_to_user(useraddr, &gstrings, sizeof(gstrings)))
  1023. goto out;
  1024. useraddr += sizeof(gstrings);
  1025. if (copy_to_user(useraddr, data, gstrings.len * ETH_GSTRING_LEN))
  1026. goto out;
  1027. ret = 0;
  1028. out:
  1029. kfree(data);
  1030. return ret;
  1031. }
  1032. static int ethtool_phys_id(struct net_device *dev, void __user *useraddr)
  1033. {
  1034. struct ethtool_value id;
  1035. static bool busy;
  1036. const struct ethtool_ops *ops = dev->ethtool_ops;
  1037. int rc;
  1038. if (!ops->set_phys_id)
  1039. return -EOPNOTSUPP;
  1040. if (busy)
  1041. return -EBUSY;
  1042. if (copy_from_user(&id, useraddr, sizeof(id)))
  1043. return -EFAULT;
  1044. rc = ops->set_phys_id(dev, ETHTOOL_ID_ACTIVE);
  1045. if (rc < 0)
  1046. return rc;
  1047. /* Drop the RTNL lock while waiting, but prevent reentry or
  1048. * removal of the device.
  1049. */
  1050. busy = true;
  1051. dev_hold(dev);
  1052. rtnl_unlock();
  1053. if (rc == 0) {
  1054. /* Driver will handle this itself */
  1055. schedule_timeout_interruptible(
  1056. id.data ? (id.data * HZ) : MAX_SCHEDULE_TIMEOUT);
  1057. } else {
  1058. /* Driver expects to be called at twice the frequency in rc */
  1059. int n = rc * 2, i, interval = HZ / n;
  1060. /* Count down seconds */
  1061. do {
  1062. /* Count down iterations per second */
  1063. i = n;
  1064. do {
  1065. rtnl_lock();
  1066. rc = ops->set_phys_id(dev,
  1067. (i & 1) ? ETHTOOL_ID_OFF : ETHTOOL_ID_ON);
  1068. rtnl_unlock();
  1069. if (rc)
  1070. break;
  1071. schedule_timeout_interruptible(interval);
  1072. } while (!signal_pending(current) && --i != 0);
  1073. } while (!signal_pending(current) &&
  1074. (id.data == 0 || --id.data != 0));
  1075. }
  1076. rtnl_lock();
  1077. dev_put(dev);
  1078. busy = false;
  1079. (void) ops->set_phys_id(dev, ETHTOOL_ID_INACTIVE);
  1080. return rc;
  1081. }
  1082. static int ethtool_get_stats(struct net_device *dev, void __user *useraddr)
  1083. {
  1084. struct ethtool_stats stats;
  1085. const struct ethtool_ops *ops = dev->ethtool_ops;
  1086. u64 *data;
  1087. int ret, n_stats;
  1088. if (!ops->get_ethtool_stats || !ops->get_sset_count)
  1089. return -EOPNOTSUPP;
  1090. n_stats = ops->get_sset_count(dev, ETH_SS_STATS);
  1091. if (n_stats < 0)
  1092. return n_stats;
  1093. WARN_ON(n_stats == 0);
  1094. if (copy_from_user(&stats, useraddr, sizeof(stats)))
  1095. return -EFAULT;
  1096. stats.n_stats = n_stats;
  1097. data = kmalloc(n_stats * sizeof(u64), GFP_USER);
  1098. if (!data)
  1099. return -ENOMEM;
  1100. ops->get_ethtool_stats(dev, &stats, data);
  1101. ret = -EFAULT;
  1102. if (copy_to_user(useraddr, &stats, sizeof(stats)))
  1103. goto out;
  1104. useraddr += sizeof(stats);
  1105. if (copy_to_user(useraddr, data, stats.n_stats * sizeof(u64)))
  1106. goto out;
  1107. ret = 0;
  1108. out:
  1109. kfree(data);
  1110. return ret;
  1111. }
  1112. static int ethtool_get_perm_addr(struct net_device *dev, void __user *useraddr)
  1113. {
  1114. struct ethtool_perm_addr epaddr;
  1115. if (copy_from_user(&epaddr, useraddr, sizeof(epaddr)))
  1116. return -EFAULT;
  1117. if (epaddr.size < dev->addr_len)
  1118. return -ETOOSMALL;
  1119. epaddr.size = dev->addr_len;
  1120. if (copy_to_user(useraddr, &epaddr, sizeof(epaddr)))
  1121. return -EFAULT;
  1122. useraddr += sizeof(epaddr);
  1123. if (copy_to_user(useraddr, dev->perm_addr, epaddr.size))
  1124. return -EFAULT;
  1125. return 0;
  1126. }
  1127. static int ethtool_get_value(struct net_device *dev, char __user *useraddr,
  1128. u32 cmd, u32 (*actor)(struct net_device *))
  1129. {
  1130. struct ethtool_value edata = { .cmd = cmd };
  1131. if (!actor)
  1132. return -EOPNOTSUPP;
  1133. edata.data = actor(dev);
  1134. if (copy_to_user(useraddr, &edata, sizeof(edata)))
  1135. return -EFAULT;
  1136. return 0;
  1137. }
  1138. static int ethtool_set_value_void(struct net_device *dev, char __user *useraddr,
  1139. void (*actor)(struct net_device *, u32))
  1140. {
  1141. struct ethtool_value edata;
  1142. if (!actor)
  1143. return -EOPNOTSUPP;
  1144. if (copy_from_user(&edata, useraddr, sizeof(edata)))
  1145. return -EFAULT;
  1146. actor(dev, edata.data);
  1147. return 0;
  1148. }
  1149. static int ethtool_set_value(struct net_device *dev, char __user *useraddr,
  1150. int (*actor)(struct net_device *, u32))
  1151. {
  1152. struct ethtool_value edata;
  1153. if (!actor)
  1154. return -EOPNOTSUPP;
  1155. if (copy_from_user(&edata, useraddr, sizeof(edata)))
  1156. return -EFAULT;
  1157. return actor(dev, edata.data);
  1158. }
  1159. static noinline_for_stack int ethtool_flash_device(struct net_device *dev,
  1160. char __user *useraddr)
  1161. {
  1162. struct ethtool_flash efl;
  1163. if (copy_from_user(&efl, useraddr, sizeof(efl)))
  1164. return -EFAULT;
  1165. if (!dev->ethtool_ops->flash_device)
  1166. return -EOPNOTSUPP;
  1167. efl.data[ETHTOOL_FLASH_MAX_FILENAME - 1] = 0;
  1168. return dev->ethtool_ops->flash_device(dev, &efl);
  1169. }
  1170. static int ethtool_set_dump(struct net_device *dev,
  1171. void __user *useraddr)
  1172. {
  1173. struct ethtool_dump dump;
  1174. if (!dev->ethtool_ops->set_dump)
  1175. return -EOPNOTSUPP;
  1176. if (copy_from_user(&dump, useraddr, sizeof(dump)))
  1177. return -EFAULT;
  1178. return dev->ethtool_ops->set_dump(dev, &dump);
  1179. }
  1180. static int ethtool_get_dump_flag(struct net_device *dev,
  1181. void __user *useraddr)
  1182. {
  1183. int ret;
  1184. struct ethtool_dump dump;
  1185. const struct ethtool_ops *ops = dev->ethtool_ops;
  1186. if (!ops->get_dump_flag)
  1187. return -EOPNOTSUPP;
  1188. if (copy_from_user(&dump, useraddr, sizeof(dump)))
  1189. return -EFAULT;
  1190. ret = ops->get_dump_flag(dev, &dump);
  1191. if (ret)
  1192. return ret;
  1193. if (copy_to_user(useraddr, &dump, sizeof(dump)))
  1194. return -EFAULT;
  1195. return 0;
  1196. }
  1197. static int ethtool_get_dump_data(struct net_device *dev,
  1198. void __user *useraddr)
  1199. {
  1200. int ret;
  1201. __u32 len;
  1202. struct ethtool_dump dump, tmp;
  1203. const struct ethtool_ops *ops = dev->ethtool_ops;
  1204. void *data = NULL;
  1205. if (!ops->get_dump_data || !ops->get_dump_flag)
  1206. return -EOPNOTSUPP;
  1207. if (copy_from_user(&dump, useraddr, sizeof(dump)))
  1208. return -EFAULT;
  1209. memset(&tmp, 0, sizeof(tmp));
  1210. tmp.cmd = ETHTOOL_GET_DUMP_FLAG;
  1211. ret = ops->get_dump_flag(dev, &tmp);
  1212. if (ret)
  1213. return ret;
  1214. len = min(tmp.len, dump.len);
  1215. if (!len)
  1216. return -EFAULT;
  1217. /* Don't ever let the driver think there's more space available
  1218. * than it requested with .get_dump_flag().
  1219. */
  1220. dump.len = len;
  1221. /* Always allocate enough space to hold the whole thing so that the
  1222. * driver does not need to check the length and bother with partial
  1223. * dumping.
  1224. */
  1225. data = vzalloc(tmp.len);
  1226. if (!data)
  1227. return -ENOMEM;
  1228. ret = ops->get_dump_data(dev, &dump, data);
  1229. if (ret)
  1230. goto out;
  1231. /* There are two sane possibilities:
  1232. * 1. The driver's .get_dump_data() does not touch dump.len.
  1233. * 2. Or it may set dump.len to how much it really writes, which
  1234. * should be tmp.len (or len if it can do a partial dump).
  1235. * In any case respond to userspace with the actual length of data
  1236. * it's receiving.
  1237. */
  1238. WARN_ON(dump.len != len && dump.len != tmp.len);
  1239. dump.len = len;
  1240. if (copy_to_user(useraddr, &dump, sizeof(dump))) {
  1241. ret = -EFAULT;
  1242. goto out;
  1243. }
  1244. useraddr += offsetof(struct ethtool_dump, data);
  1245. if (copy_to_user(useraddr, data, len))
  1246. ret = -EFAULT;
  1247. out:
  1248. vfree(data);
  1249. return ret;
  1250. }
  1251. static int ethtool_get_ts_info(struct net_device *dev, void __user *useraddr)
  1252. {
  1253. int err = 0;
  1254. struct ethtool_ts_info info;
  1255. const struct ethtool_ops *ops = dev->ethtool_ops;
  1256. struct phy_device *phydev = dev->phydev;
  1257. memset(&info, 0, sizeof(info));
  1258. info.cmd = ETHTOOL_GET_TS_INFO;
  1259. if (phydev && phydev->drv && phydev->drv->ts_info) {
  1260. err = phydev->drv->ts_info(phydev, &info);
  1261. } else if (ops->get_ts_info) {
  1262. err = ops->get_ts_info(dev, &info);
  1263. } else {
  1264. info.so_timestamping =
  1265. SOF_TIMESTAMPING_RX_SOFTWARE |
  1266. SOF_TIMESTAMPING_SOFTWARE;
  1267. info.phc_index = -1;
  1268. }
  1269. if (err)
  1270. return err;
  1271. if (copy_to_user(useraddr, &info, sizeof(info)))
  1272. err = -EFAULT;
  1273. return err;
  1274. }
  1275. static int ethtool_get_module_info(struct net_device *dev,
  1276. void __user *useraddr)
  1277. {
  1278. int ret;
  1279. struct ethtool_modinfo modinfo;
  1280. const struct ethtool_ops *ops = dev->ethtool_ops;
  1281. if (!ops->get_module_info)
  1282. return -EOPNOTSUPP;
  1283. if (copy_from_user(&modinfo, useraddr, sizeof(modinfo)))
  1284. return -EFAULT;
  1285. ret = ops->get_module_info(dev, &modinfo);
  1286. if (ret)
  1287. return ret;
  1288. if (copy_to_user(useraddr, &modinfo, sizeof(modinfo)))
  1289. return -EFAULT;
  1290. return 0;
  1291. }
  1292. static int ethtool_get_module_eeprom(struct net_device *dev,
  1293. void __user *useraddr)
  1294. {
  1295. int ret;
  1296. struct ethtool_modinfo modinfo;
  1297. const struct ethtool_ops *ops = dev->ethtool_ops;
  1298. if (!ops->get_module_info || !ops->get_module_eeprom)
  1299. return -EOPNOTSUPP;
  1300. ret = ops->get_module_info(dev, &modinfo);
  1301. if (ret)
  1302. return ret;
  1303. return ethtool_get_any_eeprom(dev, useraddr, ops->get_module_eeprom,
  1304. modinfo.eeprom_len);
  1305. }
  1306. static int ethtool_tunable_valid(const struct ethtool_tunable *tuna)
  1307. {
  1308. switch (tuna->id) {
  1309. case ETHTOOL_RX_COPYBREAK:
  1310. case ETHTOOL_TX_COPYBREAK:
  1311. if (tuna->len != sizeof(u32) ||
  1312. tuna->type_id != ETHTOOL_TUNABLE_U32)
  1313. return -EINVAL;
  1314. break;
  1315. default:
  1316. return -EINVAL;
  1317. }
  1318. return 0;
  1319. }
  1320. static int ethtool_get_tunable(struct net_device *dev, void __user *useraddr)
  1321. {
  1322. int ret;
  1323. struct ethtool_tunable tuna;
  1324. const struct ethtool_ops *ops = dev->ethtool_ops;
  1325. void *data;
  1326. if (!ops->get_tunable)
  1327. return -EOPNOTSUPP;
  1328. if (copy_from_user(&tuna, useraddr, sizeof(tuna)))
  1329. return -EFAULT;
  1330. ret = ethtool_tunable_valid(&tuna);
  1331. if (ret)
  1332. return ret;
  1333. data = kmalloc(tuna.len, GFP_USER);
  1334. if (!data)
  1335. return -ENOMEM;
  1336. ret = ops->get_tunable(dev, &tuna, data);
  1337. if (ret)
  1338. goto out;
  1339. useraddr += sizeof(tuna);
  1340. ret = -EFAULT;
  1341. if (copy_to_user(useraddr, data, tuna.len))
  1342. goto out;
  1343. ret = 0;
  1344. out:
  1345. kfree(data);
  1346. return ret;
  1347. }
  1348. static int ethtool_set_tunable(struct net_device *dev, void __user *useraddr)
  1349. {
  1350. int ret;
  1351. struct ethtool_tunable tuna;
  1352. const struct ethtool_ops *ops = dev->ethtool_ops;
  1353. void *data;
  1354. if (!ops->set_tunable)
  1355. return -EOPNOTSUPP;
  1356. if (copy_from_user(&tuna, useraddr, sizeof(tuna)))
  1357. return -EFAULT;
  1358. ret = ethtool_tunable_valid(&tuna);
  1359. if (ret)
  1360. return ret;
  1361. data = kmalloc(tuna.len, GFP_USER);
  1362. if (!data)
  1363. return -ENOMEM;
  1364. useraddr += sizeof(tuna);
  1365. ret = -EFAULT;
  1366. if (copy_from_user(data, useraddr, tuna.len))
  1367. goto out;
  1368. ret = ops->set_tunable(dev, &tuna, data);
  1369. out:
  1370. kfree(data);
  1371. return ret;
  1372. }
  1373. /* The main entry point in this file. Called from net/core/dev_ioctl.c */
  1374. int dev_ethtool(struct net *net, struct ifreq *ifr)
  1375. {
  1376. struct net_device *dev = __dev_get_by_name(net, ifr->ifr_name);
  1377. void __user *useraddr = ifr->ifr_data;
  1378. u32 ethcmd;
  1379. int rc;
  1380. netdev_features_t old_features;
  1381. if (!dev || !netif_device_present(dev))
  1382. return -ENODEV;
  1383. if (copy_from_user(&ethcmd, useraddr, sizeof(ethcmd)))
  1384. return -EFAULT;
  1385. /* Allow some commands to be done by anyone */
  1386. switch (ethcmd) {
  1387. case ETHTOOL_GSET:
  1388. case ETHTOOL_GDRVINFO:
  1389. case ETHTOOL_GMSGLVL:
  1390. case ETHTOOL_GLINK:
  1391. case ETHTOOL_GCOALESCE:
  1392. case ETHTOOL_GRINGPARAM:
  1393. case ETHTOOL_GPAUSEPARAM:
  1394. case ETHTOOL_GRXCSUM:
  1395. case ETHTOOL_GTXCSUM:
  1396. case ETHTOOL_GSG:
  1397. case ETHTOOL_GSSET_INFO:
  1398. case ETHTOOL_GSTRINGS:
  1399. case ETHTOOL_GSTATS:
  1400. case ETHTOOL_GTSO:
  1401. case ETHTOOL_GPERMADDR:
  1402. case ETHTOOL_GUFO:
  1403. case ETHTOOL_GGSO:
  1404. case ETHTOOL_GGRO:
  1405. case ETHTOOL_GFLAGS:
  1406. case ETHTOOL_GPFLAGS:
  1407. case ETHTOOL_GRXFH:
  1408. case ETHTOOL_GRXRINGS:
  1409. case ETHTOOL_GRXCLSRLCNT:
  1410. case ETHTOOL_GRXCLSRULE:
  1411. case ETHTOOL_GRXCLSRLALL:
  1412. case ETHTOOL_GRXFHINDIR:
  1413. case ETHTOOL_GRSSH:
  1414. case ETHTOOL_GFEATURES:
  1415. case ETHTOOL_GCHANNELS:
  1416. case ETHTOOL_GET_TS_INFO:
  1417. case ETHTOOL_GEEE:
  1418. case ETHTOOL_GTUNABLE:
  1419. break;
  1420. default:
  1421. if (!ns_capable(net->user_ns, CAP_NET_ADMIN))
  1422. return -EPERM;
  1423. }
  1424. if (dev->ethtool_ops->begin) {
  1425. rc = dev->ethtool_ops->begin(dev);
  1426. if (rc < 0)
  1427. return rc;
  1428. }
  1429. old_features = dev->features;
  1430. switch (ethcmd) {
  1431. case ETHTOOL_GSET:
  1432. rc = ethtool_get_settings(dev, useraddr);
  1433. break;
  1434. case ETHTOOL_SSET:
  1435. rc = ethtool_set_settings(dev, useraddr);
  1436. break;
  1437. case ETHTOOL_GDRVINFO:
  1438. rc = ethtool_get_drvinfo(dev, useraddr);
  1439. break;
  1440. case ETHTOOL_GREGS:
  1441. rc = ethtool_get_regs(dev, useraddr);
  1442. break;
  1443. case ETHTOOL_GWOL:
  1444. rc = ethtool_get_wol(dev, useraddr);
  1445. break;
  1446. case ETHTOOL_SWOL:
  1447. rc = ethtool_set_wol(dev, useraddr);
  1448. break;
  1449. case ETHTOOL_GMSGLVL:
  1450. rc = ethtool_get_value(dev, useraddr, ethcmd,
  1451. dev->ethtool_ops->get_msglevel);
  1452. break;
  1453. case ETHTOOL_SMSGLVL:
  1454. rc = ethtool_set_value_void(dev, useraddr,
  1455. dev->ethtool_ops->set_msglevel);
  1456. break;
  1457. case ETHTOOL_GEEE:
  1458. rc = ethtool_get_eee(dev, useraddr);
  1459. break;
  1460. case ETHTOOL_SEEE:
  1461. rc = ethtool_set_eee(dev, useraddr);
  1462. break;
  1463. case ETHTOOL_NWAY_RST:
  1464. rc = ethtool_nway_reset(dev);
  1465. break;
  1466. case ETHTOOL_GLINK:
  1467. rc = ethtool_get_link(dev, useraddr);
  1468. break;
  1469. case ETHTOOL_GEEPROM:
  1470. rc = ethtool_get_eeprom(dev, useraddr);
  1471. break;
  1472. case ETHTOOL_SEEPROM:
  1473. rc = ethtool_set_eeprom(dev, useraddr);
  1474. break;
  1475. case ETHTOOL_GCOALESCE:
  1476. rc = ethtool_get_coalesce(dev, useraddr);
  1477. break;
  1478. case ETHTOOL_SCOALESCE:
  1479. rc = ethtool_set_coalesce(dev, useraddr);
  1480. break;
  1481. case ETHTOOL_GRINGPARAM:
  1482. rc = ethtool_get_ringparam(dev, useraddr);
  1483. break;
  1484. case ETHTOOL_SRINGPARAM:
  1485. rc = ethtool_set_ringparam(dev, useraddr);
  1486. break;
  1487. case ETHTOOL_GPAUSEPARAM:
  1488. rc = ethtool_get_pauseparam(dev, useraddr);
  1489. break;
  1490. case ETHTOOL_SPAUSEPARAM:
  1491. rc = ethtool_set_pauseparam(dev, useraddr);
  1492. break;
  1493. case ETHTOOL_TEST:
  1494. rc = ethtool_self_test(dev, useraddr);
  1495. break;
  1496. case ETHTOOL_GSTRINGS:
  1497. rc = ethtool_get_strings(dev, useraddr);
  1498. break;
  1499. case ETHTOOL_PHYS_ID:
  1500. rc = ethtool_phys_id(dev, useraddr);
  1501. break;
  1502. case ETHTOOL_GSTATS:
  1503. rc = ethtool_get_stats(dev, useraddr);
  1504. break;
  1505. case ETHTOOL_GPERMADDR:
  1506. rc = ethtool_get_perm_addr(dev, useraddr);
  1507. break;
  1508. case ETHTOOL_GFLAGS:
  1509. rc = ethtool_get_value(dev, useraddr, ethcmd,
  1510. __ethtool_get_flags);
  1511. break;
  1512. case ETHTOOL_SFLAGS:
  1513. rc = ethtool_set_value(dev, useraddr, __ethtool_set_flags);
  1514. break;
  1515. case ETHTOOL_GPFLAGS:
  1516. rc = ethtool_get_value(dev, useraddr, ethcmd,
  1517. dev->ethtool_ops->get_priv_flags);
  1518. break;
  1519. case ETHTOOL_SPFLAGS:
  1520. rc = ethtool_set_value(dev, useraddr,
  1521. dev->ethtool_ops->set_priv_flags);
  1522. break;
  1523. case ETHTOOL_GRXFH:
  1524. case ETHTOOL_GRXRINGS:
  1525. case ETHTOOL_GRXCLSRLCNT:
  1526. case ETHTOOL_GRXCLSRULE:
  1527. case ETHTOOL_GRXCLSRLALL:
  1528. rc = ethtool_get_rxnfc(dev, ethcmd, useraddr);
  1529. break;
  1530. case ETHTOOL_SRXFH:
  1531. case ETHTOOL_SRXCLSRLDEL:
  1532. case ETHTOOL_SRXCLSRLINS:
  1533. rc = ethtool_set_rxnfc(dev, ethcmd, useraddr);
  1534. break;
  1535. case ETHTOOL_FLASHDEV:
  1536. rc = ethtool_flash_device(dev, useraddr);
  1537. break;
  1538. case ETHTOOL_RESET:
  1539. rc = ethtool_reset(dev, useraddr);
  1540. break;
  1541. case ETHTOOL_GSSET_INFO:
  1542. rc = ethtool_get_sset_info(dev, useraddr);
  1543. break;
  1544. case ETHTOOL_GRXFHINDIR:
  1545. rc = ethtool_get_rxfh_indir(dev, useraddr);
  1546. break;
  1547. case ETHTOOL_SRXFHINDIR:
  1548. rc = ethtool_set_rxfh_indir(dev, useraddr);
  1549. break;
  1550. case ETHTOOL_GRSSH:
  1551. rc = ethtool_get_rxfh(dev, useraddr);
  1552. break;
  1553. case ETHTOOL_SRSSH:
  1554. rc = ethtool_set_rxfh(dev, useraddr);
  1555. break;
  1556. case ETHTOOL_GFEATURES:
  1557. rc = ethtool_get_features(dev, useraddr);
  1558. break;
  1559. case ETHTOOL_SFEATURES:
  1560. rc = ethtool_set_features(dev, useraddr);
  1561. break;
  1562. case ETHTOOL_GTXCSUM:
  1563. case ETHTOOL_GRXCSUM:
  1564. case ETHTOOL_GSG:
  1565. case ETHTOOL_GTSO:
  1566. case ETHTOOL_GUFO:
  1567. case ETHTOOL_GGSO:
  1568. case ETHTOOL_GGRO:
  1569. rc = ethtool_get_one_feature(dev, useraddr, ethcmd);
  1570. break;
  1571. case ETHTOOL_STXCSUM:
  1572. case ETHTOOL_SRXCSUM:
  1573. case ETHTOOL_SSG:
  1574. case ETHTOOL_STSO:
  1575. case ETHTOOL_SUFO:
  1576. case ETHTOOL_SGSO:
  1577. case ETHTOOL_SGRO:
  1578. rc = ethtool_set_one_feature(dev, useraddr, ethcmd);
  1579. break;
  1580. case ETHTOOL_GCHANNELS:
  1581. rc = ethtool_get_channels(dev, useraddr);
  1582. break;
  1583. case ETHTOOL_SCHANNELS:
  1584. rc = ethtool_set_channels(dev, useraddr);
  1585. break;
  1586. case ETHTOOL_SET_DUMP:
  1587. rc = ethtool_set_dump(dev, useraddr);
  1588. break;
  1589. case ETHTOOL_GET_DUMP_FLAG:
  1590. rc = ethtool_get_dump_flag(dev, useraddr);
  1591. break;
  1592. case ETHTOOL_GET_DUMP_DATA:
  1593. rc = ethtool_get_dump_data(dev, useraddr);
  1594. break;
  1595. case ETHTOOL_GET_TS_INFO:
  1596. rc = ethtool_get_ts_info(dev, useraddr);
  1597. break;
  1598. case ETHTOOL_GMODULEINFO:
  1599. rc = ethtool_get_module_info(dev, useraddr);
  1600. break;
  1601. case ETHTOOL_GMODULEEEPROM:
  1602. rc = ethtool_get_module_eeprom(dev, useraddr);
  1603. break;
  1604. case ETHTOOL_GTUNABLE:
  1605. rc = ethtool_get_tunable(dev, useraddr);
  1606. break;
  1607. case ETHTOOL_STUNABLE:
  1608. rc = ethtool_set_tunable(dev, useraddr);
  1609. break;
  1610. default:
  1611. rc = -EOPNOTSUPP;
  1612. }
  1613. if (dev->ethtool_ops->complete)
  1614. dev->ethtool_ops->complete(dev);
  1615. if (old_features != dev->features)
  1616. netdev_features_change(dev);
  1617. return rc;
  1618. }