ethtool.c 47 KB

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