ethtool.c 35 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496
  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 <asm/uaccess.h>
  20. /*
  21. * Some useful ethtool_ops methods that're device independent.
  22. * If we find that all drivers want to do the same thing here,
  23. * we can turn these into dev_() function calls.
  24. */
  25. u32 ethtool_op_get_link(struct net_device *dev)
  26. {
  27. return netif_carrier_ok(dev) ? 1 : 0;
  28. }
  29. u32 ethtool_op_get_rx_csum(struct net_device *dev)
  30. {
  31. return (dev->features & NETIF_F_ALL_CSUM) != 0;
  32. }
  33. EXPORT_SYMBOL(ethtool_op_get_rx_csum);
  34. u32 ethtool_op_get_tx_csum(struct net_device *dev)
  35. {
  36. return (dev->features & NETIF_F_ALL_CSUM) != 0;
  37. }
  38. EXPORT_SYMBOL(ethtool_op_get_tx_csum);
  39. int ethtool_op_set_tx_csum(struct net_device *dev, u32 data)
  40. {
  41. if (data)
  42. dev->features |= NETIF_F_IP_CSUM;
  43. else
  44. dev->features &= ~NETIF_F_IP_CSUM;
  45. return 0;
  46. }
  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. int ethtool_op_set_tx_ipv6_csum(struct net_device *dev, u32 data)
  56. {
  57. if (data)
  58. dev->features |= NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM;
  59. else
  60. dev->features &= ~(NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM);
  61. return 0;
  62. }
  63. u32 ethtool_op_get_sg(struct net_device *dev)
  64. {
  65. return (dev->features & NETIF_F_SG) != 0;
  66. }
  67. int ethtool_op_set_sg(struct net_device *dev, u32 data)
  68. {
  69. if (data)
  70. dev->features |= NETIF_F_SG;
  71. else
  72. dev->features &= ~NETIF_F_SG;
  73. return 0;
  74. }
  75. u32 ethtool_op_get_tso(struct net_device *dev)
  76. {
  77. return (dev->features & NETIF_F_TSO) != 0;
  78. }
  79. int ethtool_op_set_tso(struct net_device *dev, u32 data)
  80. {
  81. if (data)
  82. dev->features |= NETIF_F_TSO;
  83. else
  84. dev->features &= ~NETIF_F_TSO;
  85. return 0;
  86. }
  87. u32 ethtool_op_get_ufo(struct net_device *dev)
  88. {
  89. return (dev->features & NETIF_F_UFO) != 0;
  90. }
  91. int ethtool_op_set_ufo(struct net_device *dev, u32 data)
  92. {
  93. if (data)
  94. dev->features |= NETIF_F_UFO;
  95. else
  96. dev->features &= ~NETIF_F_UFO;
  97. return 0;
  98. }
  99. /* the following list of flags are the same as their associated
  100. * NETIF_F_xxx values in include/linux/netdevice.h
  101. */
  102. static const u32 flags_dup_features =
  103. (ETH_FLAG_LRO | ETH_FLAG_NTUPLE);
  104. u32 ethtool_op_get_flags(struct net_device *dev)
  105. {
  106. /* in the future, this function will probably contain additional
  107. * handling for flags which are not so easily handled
  108. * by a simple masking operation
  109. */
  110. return dev->features & flags_dup_features;
  111. }
  112. int ethtool_op_set_flags(struct net_device *dev, u32 data)
  113. {
  114. const struct ethtool_ops *ops = dev->ethtool_ops;
  115. if (data & ETH_FLAG_LRO)
  116. dev->features |= NETIF_F_LRO;
  117. else
  118. dev->features &= ~NETIF_F_LRO;
  119. if (data & ETH_FLAG_NTUPLE) {
  120. if (!ops->set_rx_ntuple)
  121. return -EOPNOTSUPP;
  122. dev->features |= NETIF_F_NTUPLE;
  123. } else {
  124. /* safe to clear regardless */
  125. dev->features &= ~NETIF_F_NTUPLE;
  126. }
  127. return 0;
  128. }
  129. void ethtool_ntuple_flush(struct net_device *dev)
  130. {
  131. struct ethtool_rx_ntuple_flow_spec_container *fsc, *f;
  132. list_for_each_entry_safe(fsc, f, &dev->ethtool_ntuple_list.list, list) {
  133. list_del(&fsc->list);
  134. kfree(fsc);
  135. }
  136. dev->ethtool_ntuple_list.count = 0;
  137. }
  138. EXPORT_SYMBOL(ethtool_ntuple_flush);
  139. /* Handlers for each ethtool command */
  140. static int ethtool_get_settings(struct net_device *dev, void __user *useraddr)
  141. {
  142. struct ethtool_cmd cmd = { .cmd = ETHTOOL_GSET };
  143. int err;
  144. if (!dev->ethtool_ops->get_settings)
  145. return -EOPNOTSUPP;
  146. err = dev->ethtool_ops->get_settings(dev, &cmd);
  147. if (err < 0)
  148. return err;
  149. if (copy_to_user(useraddr, &cmd, sizeof(cmd)))
  150. return -EFAULT;
  151. return 0;
  152. }
  153. static int ethtool_set_settings(struct net_device *dev, void __user *useraddr)
  154. {
  155. struct ethtool_cmd cmd;
  156. if (!dev->ethtool_ops->set_settings)
  157. return -EOPNOTSUPP;
  158. if (copy_from_user(&cmd, useraddr, sizeof(cmd)))
  159. return -EFAULT;
  160. return dev->ethtool_ops->set_settings(dev, &cmd);
  161. }
  162. /*
  163. * noinline attribute so that gcc doesnt use too much stack in dev_ethtool()
  164. */
  165. static noinline int ethtool_get_drvinfo(struct net_device *dev, void __user *useraddr)
  166. {
  167. struct ethtool_drvinfo info;
  168. const struct ethtool_ops *ops = dev->ethtool_ops;
  169. if (!ops->get_drvinfo)
  170. return -EOPNOTSUPP;
  171. memset(&info, 0, sizeof(info));
  172. info.cmd = ETHTOOL_GDRVINFO;
  173. ops->get_drvinfo(dev, &info);
  174. if (ops->get_sset_count) {
  175. int rc;
  176. rc = ops->get_sset_count(dev, ETH_SS_TEST);
  177. if (rc >= 0)
  178. info.testinfo_len = rc;
  179. rc = ops->get_sset_count(dev, ETH_SS_STATS);
  180. if (rc >= 0)
  181. info.n_stats = rc;
  182. rc = ops->get_sset_count(dev, ETH_SS_PRIV_FLAGS);
  183. if (rc >= 0)
  184. info.n_priv_flags = rc;
  185. }
  186. if (ops->get_regs_len)
  187. info.regdump_len = ops->get_regs_len(dev);
  188. if (ops->get_eeprom_len)
  189. info.eedump_len = ops->get_eeprom_len(dev);
  190. if (copy_to_user(useraddr, &info, sizeof(info)))
  191. return -EFAULT;
  192. return 0;
  193. }
  194. /*
  195. * noinline attribute so that gcc doesnt use too much stack in dev_ethtool()
  196. */
  197. static noinline int ethtool_set_rxnfc(struct net_device *dev, void __user *useraddr)
  198. {
  199. struct ethtool_rxnfc cmd;
  200. if (!dev->ethtool_ops->set_rxnfc)
  201. return -EOPNOTSUPP;
  202. if (copy_from_user(&cmd, useraddr, sizeof(cmd)))
  203. return -EFAULT;
  204. return dev->ethtool_ops->set_rxnfc(dev, &cmd);
  205. }
  206. /*
  207. * noinline attribute so that gcc doesnt use too much stack in dev_ethtool()
  208. */
  209. static noinline int ethtool_get_rxnfc(struct net_device *dev, void __user *useraddr)
  210. {
  211. struct ethtool_rxnfc info;
  212. const struct ethtool_ops *ops = dev->ethtool_ops;
  213. int ret;
  214. void *rule_buf = NULL;
  215. if (!ops->get_rxnfc)
  216. return -EOPNOTSUPP;
  217. if (copy_from_user(&info, useraddr, sizeof(info)))
  218. return -EFAULT;
  219. if (info.cmd == ETHTOOL_GRXCLSRLALL) {
  220. if (info.rule_cnt > 0) {
  221. rule_buf = kmalloc(info.rule_cnt * sizeof(u32),
  222. GFP_USER);
  223. if (!rule_buf)
  224. return -ENOMEM;
  225. }
  226. }
  227. ret = ops->get_rxnfc(dev, &info, rule_buf);
  228. if (ret < 0)
  229. goto err_out;
  230. ret = -EFAULT;
  231. if (copy_to_user(useraddr, &info, sizeof(info)))
  232. goto err_out;
  233. if (rule_buf) {
  234. useraddr += offsetof(struct ethtool_rxnfc, rule_locs);
  235. if (copy_to_user(useraddr, rule_buf,
  236. info.rule_cnt * sizeof(u32)))
  237. goto err_out;
  238. }
  239. ret = 0;
  240. err_out:
  241. kfree(rule_buf);
  242. return ret;
  243. }
  244. static void __rx_ntuple_filter_add(struct ethtool_rx_ntuple_list *list,
  245. struct ethtool_rx_ntuple_flow_spec *spec,
  246. struct ethtool_rx_ntuple_flow_spec_container *fsc)
  247. {
  248. /* don't add filters forever */
  249. if (list->count >= ETHTOOL_MAX_NTUPLE_LIST_ENTRY) {
  250. /* free the container */
  251. kfree(fsc);
  252. return;
  253. }
  254. /* Copy the whole filter over */
  255. fsc->fs.flow_type = spec->flow_type;
  256. memcpy(&fsc->fs.h_u, &spec->h_u, sizeof(spec->h_u));
  257. memcpy(&fsc->fs.m_u, &spec->m_u, sizeof(spec->m_u));
  258. fsc->fs.vlan_tag = spec->vlan_tag;
  259. fsc->fs.vlan_tag_mask = spec->vlan_tag_mask;
  260. fsc->fs.data = spec->data;
  261. fsc->fs.data_mask = spec->data_mask;
  262. fsc->fs.action = spec->action;
  263. /* add to the list */
  264. list_add_tail_rcu(&fsc->list, &list->list);
  265. list->count++;
  266. }
  267. /*
  268. * noinline attribute so that gcc doesnt use too much stack in dev_ethtool()
  269. */
  270. static noinline int ethtool_set_rx_ntuple(struct net_device *dev, void __user *useraddr)
  271. {
  272. struct ethtool_rx_ntuple cmd;
  273. const struct ethtool_ops *ops = dev->ethtool_ops;
  274. struct ethtool_rx_ntuple_flow_spec_container *fsc = NULL;
  275. int ret;
  276. if (!(dev->features & NETIF_F_NTUPLE))
  277. return -EINVAL;
  278. if (copy_from_user(&cmd, useraddr, sizeof(cmd)))
  279. return -EFAULT;
  280. /*
  281. * Cache filter in dev struct for GET operation only if
  282. * the underlying driver doesn't have its own GET operation, and
  283. * only if the filter was added successfully. First make sure we
  284. * can allocate the filter, then continue if successful.
  285. */
  286. if (!ops->get_rx_ntuple) {
  287. fsc = kmalloc(sizeof(*fsc), GFP_ATOMIC);
  288. if (!fsc)
  289. return -ENOMEM;
  290. }
  291. ret = ops->set_rx_ntuple(dev, &cmd);
  292. if (ret) {
  293. kfree(fsc);
  294. return ret;
  295. }
  296. if (!ops->get_rx_ntuple)
  297. __rx_ntuple_filter_add(&dev->ethtool_ntuple_list, &cmd.fs, fsc);
  298. return ret;
  299. }
  300. static int ethtool_get_rx_ntuple(struct net_device *dev, void __user *useraddr)
  301. {
  302. struct ethtool_gstrings gstrings;
  303. const struct ethtool_ops *ops = dev->ethtool_ops;
  304. struct ethtool_rx_ntuple_flow_spec_container *fsc;
  305. u8 *data;
  306. char *p;
  307. int ret, i, num_strings = 0;
  308. if (!ops->get_sset_count)
  309. return -EOPNOTSUPP;
  310. if (copy_from_user(&gstrings, useraddr, sizeof(gstrings)))
  311. return -EFAULT;
  312. ret = ops->get_sset_count(dev, gstrings.string_set);
  313. if (ret < 0)
  314. return ret;
  315. gstrings.len = ret;
  316. data = kmalloc(gstrings.len * ETH_GSTRING_LEN, GFP_USER);
  317. if (!data)
  318. return -ENOMEM;
  319. if (ops->get_rx_ntuple) {
  320. /* driver-specific filter grab */
  321. ret = ops->get_rx_ntuple(dev, gstrings.string_set, data);
  322. goto copy;
  323. }
  324. /* default ethtool filter grab */
  325. i = 0;
  326. p = (char *)data;
  327. list_for_each_entry(fsc, &dev->ethtool_ntuple_list.list, list) {
  328. sprintf(p, "Filter %d:\n", i);
  329. p += ETH_GSTRING_LEN;
  330. num_strings++;
  331. switch (fsc->fs.flow_type) {
  332. case TCP_V4_FLOW:
  333. sprintf(p, "\tFlow Type: TCP\n");
  334. p += ETH_GSTRING_LEN;
  335. num_strings++;
  336. break;
  337. case UDP_V4_FLOW:
  338. sprintf(p, "\tFlow Type: UDP\n");
  339. p += ETH_GSTRING_LEN;
  340. num_strings++;
  341. break;
  342. case SCTP_V4_FLOW:
  343. sprintf(p, "\tFlow Type: SCTP\n");
  344. p += ETH_GSTRING_LEN;
  345. num_strings++;
  346. break;
  347. case AH_ESP_V4_FLOW:
  348. sprintf(p, "\tFlow Type: AH ESP\n");
  349. p += ETH_GSTRING_LEN;
  350. num_strings++;
  351. break;
  352. case ESP_V4_FLOW:
  353. sprintf(p, "\tFlow Type: ESP\n");
  354. p += ETH_GSTRING_LEN;
  355. num_strings++;
  356. break;
  357. case IP_USER_FLOW:
  358. sprintf(p, "\tFlow Type: Raw IP\n");
  359. p += ETH_GSTRING_LEN;
  360. num_strings++;
  361. break;
  362. case IPV4_FLOW:
  363. sprintf(p, "\tFlow Type: IPv4\n");
  364. p += ETH_GSTRING_LEN;
  365. num_strings++;
  366. break;
  367. default:
  368. sprintf(p, "\tFlow Type: Unknown\n");
  369. p += ETH_GSTRING_LEN;
  370. num_strings++;
  371. goto unknown_filter;
  372. };
  373. /* now the rest of the filters */
  374. switch (fsc->fs.flow_type) {
  375. case TCP_V4_FLOW:
  376. case UDP_V4_FLOW:
  377. case SCTP_V4_FLOW:
  378. sprintf(p, "\tSrc IP addr: 0x%x\n",
  379. fsc->fs.h_u.tcp_ip4_spec.ip4src);
  380. p += ETH_GSTRING_LEN;
  381. num_strings++;
  382. sprintf(p, "\tSrc IP mask: 0x%x\n",
  383. fsc->fs.m_u.tcp_ip4_spec.ip4src);
  384. p += ETH_GSTRING_LEN;
  385. num_strings++;
  386. sprintf(p, "\tDest IP addr: 0x%x\n",
  387. fsc->fs.h_u.tcp_ip4_spec.ip4dst);
  388. p += ETH_GSTRING_LEN;
  389. num_strings++;
  390. sprintf(p, "\tDest IP mask: 0x%x\n",
  391. fsc->fs.m_u.tcp_ip4_spec.ip4dst);
  392. p += ETH_GSTRING_LEN;
  393. num_strings++;
  394. sprintf(p, "\tSrc Port: %d, mask: 0x%x\n",
  395. fsc->fs.h_u.tcp_ip4_spec.psrc,
  396. fsc->fs.m_u.tcp_ip4_spec.psrc);
  397. p += ETH_GSTRING_LEN;
  398. num_strings++;
  399. sprintf(p, "\tDest Port: %d, mask: 0x%x\n",
  400. fsc->fs.h_u.tcp_ip4_spec.pdst,
  401. fsc->fs.m_u.tcp_ip4_spec.pdst);
  402. p += ETH_GSTRING_LEN;
  403. num_strings++;
  404. sprintf(p, "\tTOS: %d, mask: 0x%x\n",
  405. fsc->fs.h_u.tcp_ip4_spec.tos,
  406. fsc->fs.m_u.tcp_ip4_spec.tos);
  407. p += ETH_GSTRING_LEN;
  408. num_strings++;
  409. break;
  410. case AH_ESP_V4_FLOW:
  411. case ESP_V4_FLOW:
  412. sprintf(p, "\tSrc IP addr: 0x%x\n",
  413. fsc->fs.h_u.ah_ip4_spec.ip4src);
  414. p += ETH_GSTRING_LEN;
  415. num_strings++;
  416. sprintf(p, "\tSrc IP mask: 0x%x\n",
  417. fsc->fs.m_u.ah_ip4_spec.ip4src);
  418. p += ETH_GSTRING_LEN;
  419. num_strings++;
  420. sprintf(p, "\tDest IP addr: 0x%x\n",
  421. fsc->fs.h_u.ah_ip4_spec.ip4dst);
  422. p += ETH_GSTRING_LEN;
  423. num_strings++;
  424. sprintf(p, "\tDest IP mask: 0x%x\n",
  425. fsc->fs.m_u.ah_ip4_spec.ip4dst);
  426. p += ETH_GSTRING_LEN;
  427. num_strings++;
  428. sprintf(p, "\tSPI: %d, mask: 0x%x\n",
  429. fsc->fs.h_u.ah_ip4_spec.spi,
  430. fsc->fs.m_u.ah_ip4_spec.spi);
  431. p += ETH_GSTRING_LEN;
  432. num_strings++;
  433. sprintf(p, "\tTOS: %d, mask: 0x%x\n",
  434. fsc->fs.h_u.ah_ip4_spec.tos,
  435. fsc->fs.m_u.ah_ip4_spec.tos);
  436. p += ETH_GSTRING_LEN;
  437. num_strings++;
  438. break;
  439. case IP_USER_FLOW:
  440. sprintf(p, "\tSrc IP addr: 0x%x\n",
  441. fsc->fs.h_u.raw_ip4_spec.ip4src);
  442. p += ETH_GSTRING_LEN;
  443. num_strings++;
  444. sprintf(p, "\tSrc IP mask: 0x%x\n",
  445. fsc->fs.m_u.raw_ip4_spec.ip4src);
  446. p += ETH_GSTRING_LEN;
  447. num_strings++;
  448. sprintf(p, "\tDest IP addr: 0x%x\n",
  449. fsc->fs.h_u.raw_ip4_spec.ip4dst);
  450. p += ETH_GSTRING_LEN;
  451. num_strings++;
  452. sprintf(p, "\tDest IP mask: 0x%x\n",
  453. fsc->fs.m_u.raw_ip4_spec.ip4dst);
  454. p += ETH_GSTRING_LEN;
  455. num_strings++;
  456. break;
  457. case IPV4_FLOW:
  458. sprintf(p, "\tSrc IP addr: 0x%x\n",
  459. fsc->fs.h_u.usr_ip4_spec.ip4src);
  460. p += ETH_GSTRING_LEN;
  461. num_strings++;
  462. sprintf(p, "\tSrc IP mask: 0x%x\n",
  463. fsc->fs.m_u.usr_ip4_spec.ip4src);
  464. p += ETH_GSTRING_LEN;
  465. num_strings++;
  466. sprintf(p, "\tDest IP addr: 0x%x\n",
  467. fsc->fs.h_u.usr_ip4_spec.ip4dst);
  468. p += ETH_GSTRING_LEN;
  469. num_strings++;
  470. sprintf(p, "\tDest IP mask: 0x%x\n",
  471. fsc->fs.m_u.usr_ip4_spec.ip4dst);
  472. p += ETH_GSTRING_LEN;
  473. num_strings++;
  474. sprintf(p, "\tL4 bytes: 0x%x, mask: 0x%x\n",
  475. fsc->fs.h_u.usr_ip4_spec.l4_4_bytes,
  476. fsc->fs.m_u.usr_ip4_spec.l4_4_bytes);
  477. p += ETH_GSTRING_LEN;
  478. num_strings++;
  479. sprintf(p, "\tTOS: %d, mask: 0x%x\n",
  480. fsc->fs.h_u.usr_ip4_spec.tos,
  481. fsc->fs.m_u.usr_ip4_spec.tos);
  482. p += ETH_GSTRING_LEN;
  483. num_strings++;
  484. sprintf(p, "\tIP Version: %d, mask: 0x%x\n",
  485. fsc->fs.h_u.usr_ip4_spec.ip_ver,
  486. fsc->fs.m_u.usr_ip4_spec.ip_ver);
  487. p += ETH_GSTRING_LEN;
  488. num_strings++;
  489. sprintf(p, "\tProtocol: %d, mask: 0x%x\n",
  490. fsc->fs.h_u.usr_ip4_spec.proto,
  491. fsc->fs.m_u.usr_ip4_spec.proto);
  492. p += ETH_GSTRING_LEN;
  493. num_strings++;
  494. break;
  495. };
  496. sprintf(p, "\tVLAN: %d, mask: 0x%x\n",
  497. fsc->fs.vlan_tag, fsc->fs.vlan_tag_mask);
  498. p += ETH_GSTRING_LEN;
  499. num_strings++;
  500. sprintf(p, "\tUser-defined: 0x%Lx\n", fsc->fs.data);
  501. p += ETH_GSTRING_LEN;
  502. num_strings++;
  503. sprintf(p, "\tUser-defined mask: 0x%Lx\n", fsc->fs.data_mask);
  504. p += ETH_GSTRING_LEN;
  505. num_strings++;
  506. if (fsc->fs.action == ETHTOOL_RXNTUPLE_ACTION_DROP)
  507. sprintf(p, "\tAction: Drop\n");
  508. else
  509. sprintf(p, "\tAction: Direct to queue %d\n",
  510. fsc->fs.action);
  511. p += ETH_GSTRING_LEN;
  512. num_strings++;
  513. unknown_filter:
  514. i++;
  515. }
  516. copy:
  517. /* indicate to userspace how many strings we actually have */
  518. gstrings.len = num_strings;
  519. ret = -EFAULT;
  520. if (copy_to_user(useraddr, &gstrings, sizeof(gstrings)))
  521. goto out;
  522. useraddr += sizeof(gstrings);
  523. if (copy_to_user(useraddr, data, gstrings.len * ETH_GSTRING_LEN))
  524. goto out;
  525. ret = 0;
  526. out:
  527. kfree(data);
  528. return ret;
  529. }
  530. static int ethtool_get_regs(struct net_device *dev, char __user *useraddr)
  531. {
  532. struct ethtool_regs regs;
  533. const struct ethtool_ops *ops = dev->ethtool_ops;
  534. void *regbuf;
  535. int reglen, ret;
  536. if (!ops->get_regs || !ops->get_regs_len)
  537. return -EOPNOTSUPP;
  538. if (copy_from_user(&regs, useraddr, sizeof(regs)))
  539. return -EFAULT;
  540. reglen = ops->get_regs_len(dev);
  541. if (regs.len > reglen)
  542. regs.len = reglen;
  543. regbuf = kmalloc(reglen, GFP_USER);
  544. if (!regbuf)
  545. return -ENOMEM;
  546. ops->get_regs(dev, &regs, regbuf);
  547. ret = -EFAULT;
  548. if (copy_to_user(useraddr, &regs, sizeof(regs)))
  549. goto out;
  550. useraddr += offsetof(struct ethtool_regs, data);
  551. if (copy_to_user(useraddr, regbuf, regs.len))
  552. goto out;
  553. ret = 0;
  554. out:
  555. kfree(regbuf);
  556. return ret;
  557. }
  558. static int ethtool_reset(struct net_device *dev, char __user *useraddr)
  559. {
  560. struct ethtool_value reset;
  561. int ret;
  562. if (!dev->ethtool_ops->reset)
  563. return -EOPNOTSUPP;
  564. if (copy_from_user(&reset, useraddr, sizeof(reset)))
  565. return -EFAULT;
  566. ret = dev->ethtool_ops->reset(dev, &reset.data);
  567. if (ret)
  568. return ret;
  569. if (copy_to_user(useraddr, &reset, sizeof(reset)))
  570. return -EFAULT;
  571. return 0;
  572. }
  573. static int ethtool_get_wol(struct net_device *dev, char __user *useraddr)
  574. {
  575. struct ethtool_wolinfo wol = { .cmd = ETHTOOL_GWOL };
  576. if (!dev->ethtool_ops->get_wol)
  577. return -EOPNOTSUPP;
  578. dev->ethtool_ops->get_wol(dev, &wol);
  579. if (copy_to_user(useraddr, &wol, sizeof(wol)))
  580. return -EFAULT;
  581. return 0;
  582. }
  583. static int ethtool_set_wol(struct net_device *dev, char __user *useraddr)
  584. {
  585. struct ethtool_wolinfo wol;
  586. if (!dev->ethtool_ops->set_wol)
  587. return -EOPNOTSUPP;
  588. if (copy_from_user(&wol, useraddr, sizeof(wol)))
  589. return -EFAULT;
  590. return dev->ethtool_ops->set_wol(dev, &wol);
  591. }
  592. static int ethtool_nway_reset(struct net_device *dev)
  593. {
  594. if (!dev->ethtool_ops->nway_reset)
  595. return -EOPNOTSUPP;
  596. return dev->ethtool_ops->nway_reset(dev);
  597. }
  598. static int ethtool_get_eeprom(struct net_device *dev, void __user *useraddr)
  599. {
  600. struct ethtool_eeprom eeprom;
  601. const struct ethtool_ops *ops = dev->ethtool_ops;
  602. void __user *userbuf = useraddr + sizeof(eeprom);
  603. u32 bytes_remaining;
  604. u8 *data;
  605. int ret = 0;
  606. if (!ops->get_eeprom || !ops->get_eeprom_len)
  607. return -EOPNOTSUPP;
  608. if (copy_from_user(&eeprom, useraddr, sizeof(eeprom)))
  609. return -EFAULT;
  610. /* Check for wrap and zero */
  611. if (eeprom.offset + eeprom.len <= eeprom.offset)
  612. return -EINVAL;
  613. /* Check for exceeding total eeprom len */
  614. if (eeprom.offset + eeprom.len > ops->get_eeprom_len(dev))
  615. return -EINVAL;
  616. data = kmalloc(PAGE_SIZE, GFP_USER);
  617. if (!data)
  618. return -ENOMEM;
  619. bytes_remaining = eeprom.len;
  620. while (bytes_remaining > 0) {
  621. eeprom.len = min(bytes_remaining, (u32)PAGE_SIZE);
  622. ret = ops->get_eeprom(dev, &eeprom, data);
  623. if (ret)
  624. break;
  625. if (copy_to_user(userbuf, data, eeprom.len)) {
  626. ret = -EFAULT;
  627. break;
  628. }
  629. userbuf += eeprom.len;
  630. eeprom.offset += eeprom.len;
  631. bytes_remaining -= eeprom.len;
  632. }
  633. eeprom.len = userbuf - (useraddr + sizeof(eeprom));
  634. eeprom.offset -= eeprom.len;
  635. if (copy_to_user(useraddr, &eeprom, sizeof(eeprom)))
  636. ret = -EFAULT;
  637. kfree(data);
  638. return ret;
  639. }
  640. static int ethtool_set_eeprom(struct net_device *dev, void __user *useraddr)
  641. {
  642. struct ethtool_eeprom eeprom;
  643. const struct ethtool_ops *ops = dev->ethtool_ops;
  644. void __user *userbuf = useraddr + sizeof(eeprom);
  645. u32 bytes_remaining;
  646. u8 *data;
  647. int ret = 0;
  648. if (!ops->set_eeprom || !ops->get_eeprom_len)
  649. return -EOPNOTSUPP;
  650. if (copy_from_user(&eeprom, useraddr, sizeof(eeprom)))
  651. return -EFAULT;
  652. /* Check for wrap and zero */
  653. if (eeprom.offset + eeprom.len <= eeprom.offset)
  654. return -EINVAL;
  655. /* Check for exceeding total eeprom len */
  656. if (eeprom.offset + eeprom.len > ops->get_eeprom_len(dev))
  657. return -EINVAL;
  658. data = kmalloc(PAGE_SIZE, GFP_USER);
  659. if (!data)
  660. return -ENOMEM;
  661. bytes_remaining = eeprom.len;
  662. while (bytes_remaining > 0) {
  663. eeprom.len = min(bytes_remaining, (u32)PAGE_SIZE);
  664. if (copy_from_user(data, userbuf, eeprom.len)) {
  665. ret = -EFAULT;
  666. break;
  667. }
  668. ret = ops->set_eeprom(dev, &eeprom, data);
  669. if (ret)
  670. break;
  671. userbuf += eeprom.len;
  672. eeprom.offset += eeprom.len;
  673. bytes_remaining -= eeprom.len;
  674. }
  675. kfree(data);
  676. return ret;
  677. }
  678. /*
  679. * noinline attribute so that gcc doesnt use too much stack in dev_ethtool()
  680. */
  681. static noinline int ethtool_get_coalesce(struct net_device *dev, void __user *useraddr)
  682. {
  683. struct ethtool_coalesce coalesce = { .cmd = ETHTOOL_GCOALESCE };
  684. if (!dev->ethtool_ops->get_coalesce)
  685. return -EOPNOTSUPP;
  686. dev->ethtool_ops->get_coalesce(dev, &coalesce);
  687. if (copy_to_user(useraddr, &coalesce, sizeof(coalesce)))
  688. return -EFAULT;
  689. return 0;
  690. }
  691. /*
  692. * noinline attribute so that gcc doesnt use too much stack in dev_ethtool()
  693. */
  694. static noinline int ethtool_set_coalesce(struct net_device *dev, void __user *useraddr)
  695. {
  696. struct ethtool_coalesce coalesce;
  697. if (!dev->ethtool_ops->set_coalesce)
  698. return -EOPNOTSUPP;
  699. if (copy_from_user(&coalesce, useraddr, sizeof(coalesce)))
  700. return -EFAULT;
  701. return dev->ethtool_ops->set_coalesce(dev, &coalesce);
  702. }
  703. static int ethtool_get_ringparam(struct net_device *dev, void __user *useraddr)
  704. {
  705. struct ethtool_ringparam ringparam = { .cmd = ETHTOOL_GRINGPARAM };
  706. if (!dev->ethtool_ops->get_ringparam)
  707. return -EOPNOTSUPP;
  708. dev->ethtool_ops->get_ringparam(dev, &ringparam);
  709. if (copy_to_user(useraddr, &ringparam, sizeof(ringparam)))
  710. return -EFAULT;
  711. return 0;
  712. }
  713. static int ethtool_set_ringparam(struct net_device *dev, void __user *useraddr)
  714. {
  715. struct ethtool_ringparam ringparam;
  716. if (!dev->ethtool_ops->set_ringparam)
  717. return -EOPNOTSUPP;
  718. if (copy_from_user(&ringparam, useraddr, sizeof(ringparam)))
  719. return -EFAULT;
  720. return dev->ethtool_ops->set_ringparam(dev, &ringparam);
  721. }
  722. static int ethtool_get_pauseparam(struct net_device *dev, void __user *useraddr)
  723. {
  724. struct ethtool_pauseparam pauseparam = { ETHTOOL_GPAUSEPARAM };
  725. if (!dev->ethtool_ops->get_pauseparam)
  726. return -EOPNOTSUPP;
  727. dev->ethtool_ops->get_pauseparam(dev, &pauseparam);
  728. if (copy_to_user(useraddr, &pauseparam, sizeof(pauseparam)))
  729. return -EFAULT;
  730. return 0;
  731. }
  732. static int ethtool_set_pauseparam(struct net_device *dev, void __user *useraddr)
  733. {
  734. struct ethtool_pauseparam pauseparam;
  735. if (!dev->ethtool_ops->set_pauseparam)
  736. return -EOPNOTSUPP;
  737. if (copy_from_user(&pauseparam, useraddr, sizeof(pauseparam)))
  738. return -EFAULT;
  739. return dev->ethtool_ops->set_pauseparam(dev, &pauseparam);
  740. }
  741. static int __ethtool_set_sg(struct net_device *dev, u32 data)
  742. {
  743. int err;
  744. if (!data && dev->ethtool_ops->set_tso) {
  745. err = dev->ethtool_ops->set_tso(dev, 0);
  746. if (err)
  747. return err;
  748. }
  749. if (!data && dev->ethtool_ops->set_ufo) {
  750. err = dev->ethtool_ops->set_ufo(dev, 0);
  751. if (err)
  752. return err;
  753. }
  754. return dev->ethtool_ops->set_sg(dev, data);
  755. }
  756. static int ethtool_set_tx_csum(struct net_device *dev, char __user *useraddr)
  757. {
  758. struct ethtool_value edata;
  759. int err;
  760. if (!dev->ethtool_ops->set_tx_csum)
  761. return -EOPNOTSUPP;
  762. if (copy_from_user(&edata, useraddr, sizeof(edata)))
  763. return -EFAULT;
  764. if (!edata.data && dev->ethtool_ops->set_sg) {
  765. err = __ethtool_set_sg(dev, 0);
  766. if (err)
  767. return err;
  768. }
  769. return dev->ethtool_ops->set_tx_csum(dev, edata.data);
  770. }
  771. static int ethtool_set_rx_csum(struct net_device *dev, char __user *useraddr)
  772. {
  773. struct ethtool_value edata;
  774. if (!dev->ethtool_ops->set_rx_csum)
  775. return -EOPNOTSUPP;
  776. if (copy_from_user(&edata, useraddr, sizeof(edata)))
  777. return -EFAULT;
  778. if (!edata.data && dev->ethtool_ops->set_sg)
  779. dev->features &= ~NETIF_F_GRO;
  780. return dev->ethtool_ops->set_rx_csum(dev, edata.data);
  781. }
  782. static int ethtool_set_sg(struct net_device *dev, char __user *useraddr)
  783. {
  784. struct ethtool_value edata;
  785. if (!dev->ethtool_ops->set_sg)
  786. return -EOPNOTSUPP;
  787. if (copy_from_user(&edata, useraddr, sizeof(edata)))
  788. return -EFAULT;
  789. if (edata.data &&
  790. !(dev->features & NETIF_F_ALL_CSUM))
  791. return -EINVAL;
  792. return __ethtool_set_sg(dev, edata.data);
  793. }
  794. static int ethtool_set_tso(struct net_device *dev, char __user *useraddr)
  795. {
  796. struct ethtool_value edata;
  797. if (!dev->ethtool_ops->set_tso)
  798. return -EOPNOTSUPP;
  799. if (copy_from_user(&edata, useraddr, sizeof(edata)))
  800. return -EFAULT;
  801. if (edata.data && !(dev->features & NETIF_F_SG))
  802. return -EINVAL;
  803. return dev->ethtool_ops->set_tso(dev, edata.data);
  804. }
  805. static int ethtool_set_ufo(struct net_device *dev, char __user *useraddr)
  806. {
  807. struct ethtool_value edata;
  808. if (!dev->ethtool_ops->set_ufo)
  809. return -EOPNOTSUPP;
  810. if (copy_from_user(&edata, useraddr, sizeof(edata)))
  811. return -EFAULT;
  812. if (edata.data && !(dev->features & NETIF_F_SG))
  813. return -EINVAL;
  814. if (edata.data && !(dev->features & NETIF_F_HW_CSUM))
  815. return -EINVAL;
  816. return dev->ethtool_ops->set_ufo(dev, edata.data);
  817. }
  818. static int ethtool_get_gso(struct net_device *dev, char __user *useraddr)
  819. {
  820. struct ethtool_value edata = { ETHTOOL_GGSO };
  821. edata.data = dev->features & NETIF_F_GSO;
  822. if (copy_to_user(useraddr, &edata, sizeof(edata)))
  823. return -EFAULT;
  824. return 0;
  825. }
  826. static int ethtool_set_gso(struct net_device *dev, char __user *useraddr)
  827. {
  828. struct ethtool_value edata;
  829. if (copy_from_user(&edata, useraddr, sizeof(edata)))
  830. return -EFAULT;
  831. if (edata.data)
  832. dev->features |= NETIF_F_GSO;
  833. else
  834. dev->features &= ~NETIF_F_GSO;
  835. return 0;
  836. }
  837. static int ethtool_get_gro(struct net_device *dev, char __user *useraddr)
  838. {
  839. struct ethtool_value edata = { ETHTOOL_GGRO };
  840. edata.data = dev->features & NETIF_F_GRO;
  841. if (copy_to_user(useraddr, &edata, sizeof(edata)))
  842. return -EFAULT;
  843. return 0;
  844. }
  845. static int ethtool_set_gro(struct net_device *dev, char __user *useraddr)
  846. {
  847. struct ethtool_value edata;
  848. if (copy_from_user(&edata, useraddr, sizeof(edata)))
  849. return -EFAULT;
  850. if (edata.data) {
  851. if (!dev->ethtool_ops->get_rx_csum ||
  852. !dev->ethtool_ops->get_rx_csum(dev))
  853. return -EINVAL;
  854. dev->features |= NETIF_F_GRO;
  855. } else
  856. dev->features &= ~NETIF_F_GRO;
  857. return 0;
  858. }
  859. static int ethtool_self_test(struct net_device *dev, char __user *useraddr)
  860. {
  861. struct ethtool_test test;
  862. const struct ethtool_ops *ops = dev->ethtool_ops;
  863. u64 *data;
  864. int ret, test_len;
  865. if (!ops->self_test || !ops->get_sset_count)
  866. return -EOPNOTSUPP;
  867. test_len = ops->get_sset_count(dev, ETH_SS_TEST);
  868. if (test_len < 0)
  869. return test_len;
  870. WARN_ON(test_len == 0);
  871. if (copy_from_user(&test, useraddr, sizeof(test)))
  872. return -EFAULT;
  873. test.len = test_len;
  874. data = kmalloc(test_len * sizeof(u64), GFP_USER);
  875. if (!data)
  876. return -ENOMEM;
  877. ops->self_test(dev, &test, data);
  878. ret = -EFAULT;
  879. if (copy_to_user(useraddr, &test, sizeof(test)))
  880. goto out;
  881. useraddr += sizeof(test);
  882. if (copy_to_user(useraddr, data, test.len * sizeof(u64)))
  883. goto out;
  884. ret = 0;
  885. out:
  886. kfree(data);
  887. return ret;
  888. }
  889. static int ethtool_get_strings(struct net_device *dev, void __user *useraddr)
  890. {
  891. struct ethtool_gstrings gstrings;
  892. const struct ethtool_ops *ops = dev->ethtool_ops;
  893. u8 *data;
  894. int ret;
  895. if (!ops->get_strings || !ops->get_sset_count)
  896. return -EOPNOTSUPP;
  897. if (copy_from_user(&gstrings, useraddr, sizeof(gstrings)))
  898. return -EFAULT;
  899. ret = ops->get_sset_count(dev, gstrings.string_set);
  900. if (ret < 0)
  901. return ret;
  902. gstrings.len = ret;
  903. data = kmalloc(gstrings.len * ETH_GSTRING_LEN, GFP_USER);
  904. if (!data)
  905. return -ENOMEM;
  906. ops->get_strings(dev, gstrings.string_set, data);
  907. ret = -EFAULT;
  908. if (copy_to_user(useraddr, &gstrings, sizeof(gstrings)))
  909. goto out;
  910. useraddr += sizeof(gstrings);
  911. if (copy_to_user(useraddr, data, gstrings.len * ETH_GSTRING_LEN))
  912. goto out;
  913. ret = 0;
  914. out:
  915. kfree(data);
  916. return ret;
  917. }
  918. static int ethtool_phys_id(struct net_device *dev, void __user *useraddr)
  919. {
  920. struct ethtool_value id;
  921. if (!dev->ethtool_ops->phys_id)
  922. return -EOPNOTSUPP;
  923. if (copy_from_user(&id, useraddr, sizeof(id)))
  924. return -EFAULT;
  925. return dev->ethtool_ops->phys_id(dev, id.data);
  926. }
  927. static int ethtool_get_stats(struct net_device *dev, void __user *useraddr)
  928. {
  929. struct ethtool_stats stats;
  930. const struct ethtool_ops *ops = dev->ethtool_ops;
  931. u64 *data;
  932. int ret, n_stats;
  933. if (!ops->get_ethtool_stats || !ops->get_sset_count)
  934. return -EOPNOTSUPP;
  935. n_stats = ops->get_sset_count(dev, ETH_SS_STATS);
  936. if (n_stats < 0)
  937. return n_stats;
  938. WARN_ON(n_stats == 0);
  939. if (copy_from_user(&stats, useraddr, sizeof(stats)))
  940. return -EFAULT;
  941. stats.n_stats = n_stats;
  942. data = kmalloc(n_stats * sizeof(u64), GFP_USER);
  943. if (!data)
  944. return -ENOMEM;
  945. ops->get_ethtool_stats(dev, &stats, data);
  946. ret = -EFAULT;
  947. if (copy_to_user(useraddr, &stats, sizeof(stats)))
  948. goto out;
  949. useraddr += sizeof(stats);
  950. if (copy_to_user(useraddr, data, stats.n_stats * sizeof(u64)))
  951. goto out;
  952. ret = 0;
  953. out:
  954. kfree(data);
  955. return ret;
  956. }
  957. static int ethtool_get_perm_addr(struct net_device *dev, void __user *useraddr)
  958. {
  959. struct ethtool_perm_addr epaddr;
  960. if (copy_from_user(&epaddr, useraddr, sizeof(epaddr)))
  961. return -EFAULT;
  962. if (epaddr.size < dev->addr_len)
  963. return -ETOOSMALL;
  964. epaddr.size = dev->addr_len;
  965. if (copy_to_user(useraddr, &epaddr, sizeof(epaddr)))
  966. return -EFAULT;
  967. useraddr += sizeof(epaddr);
  968. if (copy_to_user(useraddr, dev->perm_addr, epaddr.size))
  969. return -EFAULT;
  970. return 0;
  971. }
  972. static int ethtool_get_value(struct net_device *dev, char __user *useraddr,
  973. u32 cmd, u32 (*actor)(struct net_device *))
  974. {
  975. struct ethtool_value edata = { .cmd = cmd };
  976. if (!actor)
  977. return -EOPNOTSUPP;
  978. edata.data = actor(dev);
  979. if (copy_to_user(useraddr, &edata, sizeof(edata)))
  980. return -EFAULT;
  981. return 0;
  982. }
  983. static int ethtool_set_value_void(struct net_device *dev, char __user *useraddr,
  984. void (*actor)(struct net_device *, u32))
  985. {
  986. struct ethtool_value edata;
  987. if (!actor)
  988. return -EOPNOTSUPP;
  989. if (copy_from_user(&edata, useraddr, sizeof(edata)))
  990. return -EFAULT;
  991. actor(dev, edata.data);
  992. return 0;
  993. }
  994. static int ethtool_set_value(struct net_device *dev, char __user *useraddr,
  995. int (*actor)(struct net_device *, u32))
  996. {
  997. struct ethtool_value edata;
  998. if (!actor)
  999. return -EOPNOTSUPP;
  1000. if (copy_from_user(&edata, useraddr, sizeof(edata)))
  1001. return -EFAULT;
  1002. return actor(dev, edata.data);
  1003. }
  1004. /*
  1005. * noinline attribute so that gcc doesnt use too much stack in dev_ethtool()
  1006. */
  1007. static noinline int ethtool_flash_device(struct net_device *dev, char __user *useraddr)
  1008. {
  1009. struct ethtool_flash efl;
  1010. if (copy_from_user(&efl, useraddr, sizeof(efl)))
  1011. return -EFAULT;
  1012. if (!dev->ethtool_ops->flash_device)
  1013. return -EOPNOTSUPP;
  1014. return dev->ethtool_ops->flash_device(dev, &efl);
  1015. }
  1016. /* The main entry point in this file. Called from net/core/dev.c */
  1017. int dev_ethtool(struct net *net, struct ifreq *ifr)
  1018. {
  1019. struct net_device *dev = __dev_get_by_name(net, ifr->ifr_name);
  1020. void __user *useraddr = ifr->ifr_data;
  1021. u32 ethcmd;
  1022. int rc;
  1023. unsigned long old_features;
  1024. if (!dev || !netif_device_present(dev))
  1025. return -ENODEV;
  1026. if (!dev->ethtool_ops)
  1027. return -EOPNOTSUPP;
  1028. if (copy_from_user(&ethcmd, useraddr, sizeof (ethcmd)))
  1029. return -EFAULT;
  1030. /* Allow some commands to be done by anyone */
  1031. switch(ethcmd) {
  1032. case ETHTOOL_GDRVINFO:
  1033. case ETHTOOL_GMSGLVL:
  1034. case ETHTOOL_GCOALESCE:
  1035. case ETHTOOL_GRINGPARAM:
  1036. case ETHTOOL_GPAUSEPARAM:
  1037. case ETHTOOL_GRXCSUM:
  1038. case ETHTOOL_GTXCSUM:
  1039. case ETHTOOL_GSG:
  1040. case ETHTOOL_GSTRINGS:
  1041. case ETHTOOL_GTSO:
  1042. case ETHTOOL_GPERMADDR:
  1043. case ETHTOOL_GUFO:
  1044. case ETHTOOL_GGSO:
  1045. case ETHTOOL_GGRO:
  1046. case ETHTOOL_GFLAGS:
  1047. case ETHTOOL_GPFLAGS:
  1048. case ETHTOOL_GRXFH:
  1049. case ETHTOOL_GRXRINGS:
  1050. case ETHTOOL_GRXCLSRLCNT:
  1051. case ETHTOOL_GRXCLSRULE:
  1052. case ETHTOOL_GRXCLSRLALL:
  1053. break;
  1054. default:
  1055. if (!capable(CAP_NET_ADMIN))
  1056. return -EPERM;
  1057. }
  1058. if (dev->ethtool_ops->begin)
  1059. if ((rc = dev->ethtool_ops->begin(dev)) < 0)
  1060. return rc;
  1061. old_features = dev->features;
  1062. switch (ethcmd) {
  1063. case ETHTOOL_GSET:
  1064. rc = ethtool_get_settings(dev, useraddr);
  1065. break;
  1066. case ETHTOOL_SSET:
  1067. rc = ethtool_set_settings(dev, useraddr);
  1068. break;
  1069. case ETHTOOL_GDRVINFO:
  1070. rc = ethtool_get_drvinfo(dev, useraddr);
  1071. break;
  1072. case ETHTOOL_GREGS:
  1073. rc = ethtool_get_regs(dev, useraddr);
  1074. break;
  1075. case ETHTOOL_GWOL:
  1076. rc = ethtool_get_wol(dev, useraddr);
  1077. break;
  1078. case ETHTOOL_SWOL:
  1079. rc = ethtool_set_wol(dev, useraddr);
  1080. break;
  1081. case ETHTOOL_GMSGLVL:
  1082. rc = ethtool_get_value(dev, useraddr, ethcmd,
  1083. dev->ethtool_ops->get_msglevel);
  1084. break;
  1085. case ETHTOOL_SMSGLVL:
  1086. rc = ethtool_set_value_void(dev, useraddr,
  1087. dev->ethtool_ops->set_msglevel);
  1088. break;
  1089. case ETHTOOL_NWAY_RST:
  1090. rc = ethtool_nway_reset(dev);
  1091. break;
  1092. case ETHTOOL_GLINK:
  1093. rc = ethtool_get_value(dev, useraddr, ethcmd,
  1094. dev->ethtool_ops->get_link);
  1095. break;
  1096. case ETHTOOL_GEEPROM:
  1097. rc = ethtool_get_eeprom(dev, useraddr);
  1098. break;
  1099. case ETHTOOL_SEEPROM:
  1100. rc = ethtool_set_eeprom(dev, useraddr);
  1101. break;
  1102. case ETHTOOL_GCOALESCE:
  1103. rc = ethtool_get_coalesce(dev, useraddr);
  1104. break;
  1105. case ETHTOOL_SCOALESCE:
  1106. rc = ethtool_set_coalesce(dev, useraddr);
  1107. break;
  1108. case ETHTOOL_GRINGPARAM:
  1109. rc = ethtool_get_ringparam(dev, useraddr);
  1110. break;
  1111. case ETHTOOL_SRINGPARAM:
  1112. rc = ethtool_set_ringparam(dev, useraddr);
  1113. break;
  1114. case ETHTOOL_GPAUSEPARAM:
  1115. rc = ethtool_get_pauseparam(dev, useraddr);
  1116. break;
  1117. case ETHTOOL_SPAUSEPARAM:
  1118. rc = ethtool_set_pauseparam(dev, useraddr);
  1119. break;
  1120. case ETHTOOL_GRXCSUM:
  1121. rc = ethtool_get_value(dev, useraddr, ethcmd,
  1122. (dev->ethtool_ops->get_rx_csum ?
  1123. dev->ethtool_ops->get_rx_csum :
  1124. ethtool_op_get_rx_csum));
  1125. break;
  1126. case ETHTOOL_SRXCSUM:
  1127. rc = ethtool_set_rx_csum(dev, useraddr);
  1128. break;
  1129. case ETHTOOL_GTXCSUM:
  1130. rc = ethtool_get_value(dev, useraddr, ethcmd,
  1131. (dev->ethtool_ops->get_tx_csum ?
  1132. dev->ethtool_ops->get_tx_csum :
  1133. ethtool_op_get_tx_csum));
  1134. break;
  1135. case ETHTOOL_STXCSUM:
  1136. rc = ethtool_set_tx_csum(dev, useraddr);
  1137. break;
  1138. case ETHTOOL_GSG:
  1139. rc = ethtool_get_value(dev, useraddr, ethcmd,
  1140. (dev->ethtool_ops->get_sg ?
  1141. dev->ethtool_ops->get_sg :
  1142. ethtool_op_get_sg));
  1143. break;
  1144. case ETHTOOL_SSG:
  1145. rc = ethtool_set_sg(dev, useraddr);
  1146. break;
  1147. case ETHTOOL_GTSO:
  1148. rc = ethtool_get_value(dev, useraddr, ethcmd,
  1149. (dev->ethtool_ops->get_tso ?
  1150. dev->ethtool_ops->get_tso :
  1151. ethtool_op_get_tso));
  1152. break;
  1153. case ETHTOOL_STSO:
  1154. rc = ethtool_set_tso(dev, useraddr);
  1155. break;
  1156. case ETHTOOL_TEST:
  1157. rc = ethtool_self_test(dev, useraddr);
  1158. break;
  1159. case ETHTOOL_GSTRINGS:
  1160. rc = ethtool_get_strings(dev, useraddr);
  1161. break;
  1162. case ETHTOOL_PHYS_ID:
  1163. rc = ethtool_phys_id(dev, useraddr);
  1164. break;
  1165. case ETHTOOL_GSTATS:
  1166. rc = ethtool_get_stats(dev, useraddr);
  1167. break;
  1168. case ETHTOOL_GPERMADDR:
  1169. rc = ethtool_get_perm_addr(dev, useraddr);
  1170. break;
  1171. case ETHTOOL_GUFO:
  1172. rc = ethtool_get_value(dev, useraddr, ethcmd,
  1173. (dev->ethtool_ops->get_ufo ?
  1174. dev->ethtool_ops->get_ufo :
  1175. ethtool_op_get_ufo));
  1176. break;
  1177. case ETHTOOL_SUFO:
  1178. rc = ethtool_set_ufo(dev, useraddr);
  1179. break;
  1180. case ETHTOOL_GGSO:
  1181. rc = ethtool_get_gso(dev, useraddr);
  1182. break;
  1183. case ETHTOOL_SGSO:
  1184. rc = ethtool_set_gso(dev, useraddr);
  1185. break;
  1186. case ETHTOOL_GFLAGS:
  1187. rc = ethtool_get_value(dev, useraddr, ethcmd,
  1188. (dev->ethtool_ops->get_flags ?
  1189. dev->ethtool_ops->get_flags :
  1190. ethtool_op_get_flags));
  1191. break;
  1192. case ETHTOOL_SFLAGS:
  1193. rc = ethtool_set_value(dev, useraddr,
  1194. dev->ethtool_ops->set_flags);
  1195. break;
  1196. case ETHTOOL_GPFLAGS:
  1197. rc = ethtool_get_value(dev, useraddr, ethcmd,
  1198. dev->ethtool_ops->get_priv_flags);
  1199. break;
  1200. case ETHTOOL_SPFLAGS:
  1201. rc = ethtool_set_value(dev, useraddr,
  1202. dev->ethtool_ops->set_priv_flags);
  1203. break;
  1204. case ETHTOOL_GRXFH:
  1205. case ETHTOOL_GRXRINGS:
  1206. case ETHTOOL_GRXCLSRLCNT:
  1207. case ETHTOOL_GRXCLSRULE:
  1208. case ETHTOOL_GRXCLSRLALL:
  1209. rc = ethtool_get_rxnfc(dev, useraddr);
  1210. break;
  1211. case ETHTOOL_SRXFH:
  1212. case ETHTOOL_SRXCLSRLDEL:
  1213. case ETHTOOL_SRXCLSRLINS:
  1214. rc = ethtool_set_rxnfc(dev, useraddr);
  1215. break;
  1216. case ETHTOOL_GGRO:
  1217. rc = ethtool_get_gro(dev, useraddr);
  1218. break;
  1219. case ETHTOOL_SGRO:
  1220. rc = ethtool_set_gro(dev, useraddr);
  1221. break;
  1222. case ETHTOOL_FLASHDEV:
  1223. rc = ethtool_flash_device(dev, useraddr);
  1224. break;
  1225. case ETHTOOL_RESET:
  1226. rc = ethtool_reset(dev, useraddr);
  1227. break;
  1228. case ETHTOOL_SRXNTUPLE:
  1229. rc = ethtool_set_rx_ntuple(dev, useraddr);
  1230. break;
  1231. case ETHTOOL_GRXNTUPLE:
  1232. rc = ethtool_get_rx_ntuple(dev, useraddr);
  1233. break;
  1234. default:
  1235. rc = -EOPNOTSUPP;
  1236. }
  1237. if (dev->ethtool_ops->complete)
  1238. dev->ethtool_ops->complete(dev);
  1239. if (old_features != dev->features)
  1240. netdev_features_change(dev);
  1241. return rc;
  1242. }
  1243. EXPORT_SYMBOL(ethtool_op_get_link);
  1244. EXPORT_SYMBOL(ethtool_op_get_sg);
  1245. EXPORT_SYMBOL(ethtool_op_get_tso);
  1246. EXPORT_SYMBOL(ethtool_op_set_sg);
  1247. EXPORT_SYMBOL(ethtool_op_set_tso);
  1248. EXPORT_SYMBOL(ethtool_op_set_tx_csum);
  1249. EXPORT_SYMBOL(ethtool_op_set_tx_hw_csum);
  1250. EXPORT_SYMBOL(ethtool_op_set_tx_ipv6_csum);
  1251. EXPORT_SYMBOL(ethtool_op_set_ufo);
  1252. EXPORT_SYMBOL(ethtool_op_get_ufo);
  1253. EXPORT_SYMBOL(ethtool_op_set_flags);
  1254. EXPORT_SYMBOL(ethtool_op_get_flags);