ethtool.c 34 KB

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