ethtool.c 44 KB

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