ethtool.c 35 KB

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