ethtool.c 45 KB

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