ethtool.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835
  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. We fall back to calling do_ioctl()
  7. * for drivers which haven't been converted to ethtool_ops yet.
  8. *
  9. * It's GPL, stupid.
  10. */
  11. #include <linux/module.h>
  12. #include <linux/types.h>
  13. #include <linux/errno.h>
  14. #include <linux/ethtool.h>
  15. #include <linux/netdevice.h>
  16. #include <asm/uaccess.h>
  17. /*
  18. * Some useful ethtool_ops methods that're device independent.
  19. * If we find that all drivers want to do the same thing here,
  20. * we can turn these into dev_() function calls.
  21. */
  22. u32 ethtool_op_get_link(struct net_device *dev)
  23. {
  24. return netif_carrier_ok(dev) ? 1 : 0;
  25. }
  26. u32 ethtool_op_get_tx_csum(struct net_device *dev)
  27. {
  28. return (dev->features & (NETIF_F_IP_CSUM | NETIF_F_HW_CSUM)) != 0;
  29. }
  30. int ethtool_op_set_tx_csum(struct net_device *dev, u32 data)
  31. {
  32. if (data)
  33. dev->features |= NETIF_F_IP_CSUM;
  34. else
  35. dev->features &= ~NETIF_F_IP_CSUM;
  36. return 0;
  37. }
  38. int ethtool_op_set_tx_hw_csum(struct net_device *dev, u32 data)
  39. {
  40. if (data)
  41. dev->features |= NETIF_F_HW_CSUM;
  42. else
  43. dev->features &= ~NETIF_F_HW_CSUM;
  44. return 0;
  45. }
  46. u32 ethtool_op_get_sg(struct net_device *dev)
  47. {
  48. return (dev->features & NETIF_F_SG) != 0;
  49. }
  50. int ethtool_op_set_sg(struct net_device *dev, u32 data)
  51. {
  52. if (data)
  53. dev->features |= NETIF_F_SG;
  54. else
  55. dev->features &= ~NETIF_F_SG;
  56. return 0;
  57. }
  58. u32 ethtool_op_get_tso(struct net_device *dev)
  59. {
  60. return (dev->features & NETIF_F_TSO) != 0;
  61. }
  62. int ethtool_op_set_tso(struct net_device *dev, u32 data)
  63. {
  64. if (data)
  65. dev->features |= NETIF_F_TSO;
  66. else
  67. dev->features &= ~NETIF_F_TSO;
  68. return 0;
  69. }
  70. /* Handlers for each ethtool command */
  71. static int ethtool_get_settings(struct net_device *dev, void __user *useraddr)
  72. {
  73. struct ethtool_cmd cmd = { ETHTOOL_GSET };
  74. int err;
  75. if (!dev->ethtool_ops->get_settings)
  76. return -EOPNOTSUPP;
  77. err = dev->ethtool_ops->get_settings(dev, &cmd);
  78. if (err < 0)
  79. return err;
  80. if (copy_to_user(useraddr, &cmd, sizeof(cmd)))
  81. return -EFAULT;
  82. return 0;
  83. }
  84. static int ethtool_set_settings(struct net_device *dev, void __user *useraddr)
  85. {
  86. struct ethtool_cmd cmd;
  87. if (!dev->ethtool_ops->set_settings)
  88. return -EOPNOTSUPP;
  89. if (copy_from_user(&cmd, useraddr, sizeof(cmd)))
  90. return -EFAULT;
  91. return dev->ethtool_ops->set_settings(dev, &cmd);
  92. }
  93. static int ethtool_get_drvinfo(struct net_device *dev, void __user *useraddr)
  94. {
  95. struct ethtool_drvinfo info;
  96. struct ethtool_ops *ops = dev->ethtool_ops;
  97. if (!ops->get_drvinfo)
  98. return -EOPNOTSUPP;
  99. memset(&info, 0, sizeof(info));
  100. info.cmd = ETHTOOL_GDRVINFO;
  101. ops->get_drvinfo(dev, &info);
  102. if (ops->self_test_count)
  103. info.testinfo_len = ops->self_test_count(dev);
  104. if (ops->get_stats_count)
  105. info.n_stats = ops->get_stats_count(dev);
  106. if (ops->get_regs_len)
  107. info.regdump_len = ops->get_regs_len(dev);
  108. if (ops->get_eeprom_len)
  109. info.eedump_len = ops->get_eeprom_len(dev);
  110. if (copy_to_user(useraddr, &info, sizeof(info)))
  111. return -EFAULT;
  112. return 0;
  113. }
  114. static int ethtool_get_regs(struct net_device *dev, char __user *useraddr)
  115. {
  116. struct ethtool_regs regs;
  117. struct ethtool_ops *ops = dev->ethtool_ops;
  118. void *regbuf;
  119. int reglen, ret;
  120. if (!ops->get_regs || !ops->get_regs_len)
  121. return -EOPNOTSUPP;
  122. if (copy_from_user(&regs, useraddr, sizeof(regs)))
  123. return -EFAULT;
  124. reglen = ops->get_regs_len(dev);
  125. if (regs.len > reglen)
  126. regs.len = reglen;
  127. regbuf = kmalloc(reglen, GFP_USER);
  128. if (!regbuf)
  129. return -ENOMEM;
  130. ops->get_regs(dev, &regs, regbuf);
  131. ret = -EFAULT;
  132. if (copy_to_user(useraddr, &regs, sizeof(regs)))
  133. goto out;
  134. useraddr += offsetof(struct ethtool_regs, data);
  135. if (copy_to_user(useraddr, regbuf, regs.len))
  136. goto out;
  137. ret = 0;
  138. out:
  139. kfree(regbuf);
  140. return ret;
  141. }
  142. static int ethtool_get_wol(struct net_device *dev, char __user *useraddr)
  143. {
  144. struct ethtool_wolinfo wol = { ETHTOOL_GWOL };
  145. if (!dev->ethtool_ops->get_wol)
  146. return -EOPNOTSUPP;
  147. dev->ethtool_ops->get_wol(dev, &wol);
  148. if (copy_to_user(useraddr, &wol, sizeof(wol)))
  149. return -EFAULT;
  150. return 0;
  151. }
  152. static int ethtool_set_wol(struct net_device *dev, char __user *useraddr)
  153. {
  154. struct ethtool_wolinfo wol;
  155. if (!dev->ethtool_ops->set_wol)
  156. return -EOPNOTSUPP;
  157. if (copy_from_user(&wol, useraddr, sizeof(wol)))
  158. return -EFAULT;
  159. return dev->ethtool_ops->set_wol(dev, &wol);
  160. }
  161. static int ethtool_get_msglevel(struct net_device *dev, char __user *useraddr)
  162. {
  163. struct ethtool_value edata = { ETHTOOL_GMSGLVL };
  164. if (!dev->ethtool_ops->get_msglevel)
  165. return -EOPNOTSUPP;
  166. edata.data = dev->ethtool_ops->get_msglevel(dev);
  167. if (copy_to_user(useraddr, &edata, sizeof(edata)))
  168. return -EFAULT;
  169. return 0;
  170. }
  171. static int ethtool_set_msglevel(struct net_device *dev, char __user *useraddr)
  172. {
  173. struct ethtool_value edata;
  174. if (!dev->ethtool_ops->set_msglevel)
  175. return -EOPNOTSUPP;
  176. if (copy_from_user(&edata, useraddr, sizeof(edata)))
  177. return -EFAULT;
  178. dev->ethtool_ops->set_msglevel(dev, edata.data);
  179. return 0;
  180. }
  181. static int ethtool_nway_reset(struct net_device *dev)
  182. {
  183. if (!dev->ethtool_ops->nway_reset)
  184. return -EOPNOTSUPP;
  185. return dev->ethtool_ops->nway_reset(dev);
  186. }
  187. static int ethtool_get_link(struct net_device *dev, void __user *useraddr)
  188. {
  189. struct ethtool_value edata = { ETHTOOL_GLINK };
  190. if (!dev->ethtool_ops->get_link)
  191. return -EOPNOTSUPP;
  192. edata.data = dev->ethtool_ops->get_link(dev);
  193. if (copy_to_user(useraddr, &edata, sizeof(edata)))
  194. return -EFAULT;
  195. return 0;
  196. }
  197. static int ethtool_get_eeprom(struct net_device *dev, void __user *useraddr)
  198. {
  199. struct ethtool_eeprom eeprom;
  200. struct ethtool_ops *ops = dev->ethtool_ops;
  201. u8 *data;
  202. int ret;
  203. if (!ops->get_eeprom || !ops->get_eeprom_len)
  204. return -EOPNOTSUPP;
  205. if (copy_from_user(&eeprom, useraddr, sizeof(eeprom)))
  206. return -EFAULT;
  207. /* Check for wrap and zero */
  208. if (eeprom.offset + eeprom.len <= eeprom.offset)
  209. return -EINVAL;
  210. /* Check for exceeding total eeprom len */
  211. if (eeprom.offset + eeprom.len > ops->get_eeprom_len(dev))
  212. return -EINVAL;
  213. data = kmalloc(eeprom.len, GFP_USER);
  214. if (!data)
  215. return -ENOMEM;
  216. ret = -EFAULT;
  217. if (copy_from_user(data, useraddr + sizeof(eeprom), eeprom.len))
  218. goto out;
  219. ret = ops->get_eeprom(dev, &eeprom, data);
  220. if (ret)
  221. goto out;
  222. ret = -EFAULT;
  223. if (copy_to_user(useraddr, &eeprom, sizeof(eeprom)))
  224. goto out;
  225. if (copy_to_user(useraddr + sizeof(eeprom), data, eeprom.len))
  226. goto out;
  227. ret = 0;
  228. out:
  229. kfree(data);
  230. return ret;
  231. }
  232. static int ethtool_set_eeprom(struct net_device *dev, void __user *useraddr)
  233. {
  234. struct ethtool_eeprom eeprom;
  235. struct ethtool_ops *ops = dev->ethtool_ops;
  236. u8 *data;
  237. int ret;
  238. if (!ops->set_eeprom || !ops->get_eeprom_len)
  239. return -EOPNOTSUPP;
  240. if (copy_from_user(&eeprom, useraddr, sizeof(eeprom)))
  241. return -EFAULT;
  242. /* Check for wrap and zero */
  243. if (eeprom.offset + eeprom.len <= eeprom.offset)
  244. return -EINVAL;
  245. /* Check for exceeding total eeprom len */
  246. if (eeprom.offset + eeprom.len > ops->get_eeprom_len(dev))
  247. return -EINVAL;
  248. data = kmalloc(eeprom.len, GFP_USER);
  249. if (!data)
  250. return -ENOMEM;
  251. ret = -EFAULT;
  252. if (copy_from_user(data, useraddr + sizeof(eeprom), eeprom.len))
  253. goto out;
  254. ret = ops->set_eeprom(dev, &eeprom, data);
  255. if (ret)
  256. goto out;
  257. if (copy_to_user(useraddr + sizeof(eeprom), data, eeprom.len))
  258. ret = -EFAULT;
  259. out:
  260. kfree(data);
  261. return ret;
  262. }
  263. static int ethtool_get_coalesce(struct net_device *dev, void __user *useraddr)
  264. {
  265. struct ethtool_coalesce coalesce = { ETHTOOL_GCOALESCE };
  266. if (!dev->ethtool_ops->get_coalesce)
  267. return -EOPNOTSUPP;
  268. dev->ethtool_ops->get_coalesce(dev, &coalesce);
  269. if (copy_to_user(useraddr, &coalesce, sizeof(coalesce)))
  270. return -EFAULT;
  271. return 0;
  272. }
  273. static int ethtool_set_coalesce(struct net_device *dev, void __user *useraddr)
  274. {
  275. struct ethtool_coalesce coalesce;
  276. if (!dev->ethtool_ops->set_coalesce)
  277. return -EOPNOTSUPP;
  278. if (copy_from_user(&coalesce, useraddr, sizeof(coalesce)))
  279. return -EFAULT;
  280. return dev->ethtool_ops->set_coalesce(dev, &coalesce);
  281. }
  282. static int ethtool_get_ringparam(struct net_device *dev, void __user *useraddr)
  283. {
  284. struct ethtool_ringparam ringparam = { ETHTOOL_GRINGPARAM };
  285. if (!dev->ethtool_ops->get_ringparam)
  286. return -EOPNOTSUPP;
  287. dev->ethtool_ops->get_ringparam(dev, &ringparam);
  288. if (copy_to_user(useraddr, &ringparam, sizeof(ringparam)))
  289. return -EFAULT;
  290. return 0;
  291. }
  292. static int ethtool_set_ringparam(struct net_device *dev, void __user *useraddr)
  293. {
  294. struct ethtool_ringparam ringparam;
  295. if (!dev->ethtool_ops->set_ringparam)
  296. return -EOPNOTSUPP;
  297. if (copy_from_user(&ringparam, useraddr, sizeof(ringparam)))
  298. return -EFAULT;
  299. return dev->ethtool_ops->set_ringparam(dev, &ringparam);
  300. }
  301. static int ethtool_get_pauseparam(struct net_device *dev, void __user *useraddr)
  302. {
  303. struct ethtool_pauseparam pauseparam = { ETHTOOL_GPAUSEPARAM };
  304. if (!dev->ethtool_ops->get_pauseparam)
  305. return -EOPNOTSUPP;
  306. dev->ethtool_ops->get_pauseparam(dev, &pauseparam);
  307. if (copy_to_user(useraddr, &pauseparam, sizeof(pauseparam)))
  308. return -EFAULT;
  309. return 0;
  310. }
  311. static int ethtool_set_pauseparam(struct net_device *dev, void __user *useraddr)
  312. {
  313. struct ethtool_pauseparam pauseparam;
  314. if (!dev->ethtool_ops->get_pauseparam)
  315. return -EOPNOTSUPP;
  316. if (copy_from_user(&pauseparam, useraddr, sizeof(pauseparam)))
  317. return -EFAULT;
  318. return dev->ethtool_ops->set_pauseparam(dev, &pauseparam);
  319. }
  320. static int ethtool_get_rx_csum(struct net_device *dev, char __user *useraddr)
  321. {
  322. struct ethtool_value edata = { ETHTOOL_GRXCSUM };
  323. if (!dev->ethtool_ops->get_rx_csum)
  324. return -EOPNOTSUPP;
  325. edata.data = dev->ethtool_ops->get_rx_csum(dev);
  326. if (copy_to_user(useraddr, &edata, sizeof(edata)))
  327. return -EFAULT;
  328. return 0;
  329. }
  330. static int ethtool_set_rx_csum(struct net_device *dev, char __user *useraddr)
  331. {
  332. struct ethtool_value edata;
  333. if (!dev->ethtool_ops->set_rx_csum)
  334. return -EOPNOTSUPP;
  335. if (copy_from_user(&edata, useraddr, sizeof(edata)))
  336. return -EFAULT;
  337. dev->ethtool_ops->set_rx_csum(dev, edata.data);
  338. return 0;
  339. }
  340. static int ethtool_get_tx_csum(struct net_device *dev, char __user *useraddr)
  341. {
  342. struct ethtool_value edata = { ETHTOOL_GTXCSUM };
  343. if (!dev->ethtool_ops->get_tx_csum)
  344. return -EOPNOTSUPP;
  345. edata.data = dev->ethtool_ops->get_tx_csum(dev);
  346. if (copy_to_user(useraddr, &edata, sizeof(edata)))
  347. return -EFAULT;
  348. return 0;
  349. }
  350. static int __ethtool_set_sg(struct net_device *dev, u32 data)
  351. {
  352. int err;
  353. if (!data && dev->ethtool_ops->set_tso) {
  354. err = dev->ethtool_ops->set_tso(dev, 0);
  355. if (err)
  356. return err;
  357. }
  358. return dev->ethtool_ops->set_sg(dev, data);
  359. }
  360. static int ethtool_set_tx_csum(struct net_device *dev, char __user *useraddr)
  361. {
  362. struct ethtool_value edata;
  363. int err;
  364. if (!dev->ethtool_ops->set_tx_csum)
  365. return -EOPNOTSUPP;
  366. if (copy_from_user(&edata, useraddr, sizeof(edata)))
  367. return -EFAULT;
  368. if (!edata.data && dev->ethtool_ops->set_sg) {
  369. err = __ethtool_set_sg(dev, 0);
  370. if (err)
  371. return err;
  372. }
  373. return dev->ethtool_ops->set_tx_csum(dev, edata.data);
  374. }
  375. static int ethtool_get_sg(struct net_device *dev, char __user *useraddr)
  376. {
  377. struct ethtool_value edata = { ETHTOOL_GSG };
  378. if (!dev->ethtool_ops->get_sg)
  379. return -EOPNOTSUPP;
  380. edata.data = dev->ethtool_ops->get_sg(dev);
  381. if (copy_to_user(useraddr, &edata, sizeof(edata)))
  382. return -EFAULT;
  383. return 0;
  384. }
  385. static int ethtool_set_sg(struct net_device *dev, char __user *useraddr)
  386. {
  387. struct ethtool_value edata;
  388. if (!dev->ethtool_ops->set_sg)
  389. return -EOPNOTSUPP;
  390. if (copy_from_user(&edata, useraddr, sizeof(edata)))
  391. return -EFAULT;
  392. if (edata.data &&
  393. !(dev->features & (NETIF_F_IP_CSUM |
  394. NETIF_F_NO_CSUM |
  395. NETIF_F_HW_CSUM)))
  396. return -EINVAL;
  397. return __ethtool_set_sg(dev, edata.data);
  398. }
  399. static int ethtool_get_tso(struct net_device *dev, char __user *useraddr)
  400. {
  401. struct ethtool_value edata = { ETHTOOL_GTSO };
  402. if (!dev->ethtool_ops->get_tso)
  403. return -EOPNOTSUPP;
  404. edata.data = dev->ethtool_ops->get_tso(dev);
  405. if (copy_to_user(useraddr, &edata, sizeof(edata)))
  406. return -EFAULT;
  407. return 0;
  408. }
  409. static int ethtool_set_tso(struct net_device *dev, char __user *useraddr)
  410. {
  411. struct ethtool_value edata;
  412. if (!dev->ethtool_ops->set_tso)
  413. return -EOPNOTSUPP;
  414. if (copy_from_user(&edata, useraddr, sizeof(edata)))
  415. return -EFAULT;
  416. if (edata.data && !(dev->features & NETIF_F_SG))
  417. return -EINVAL;
  418. return dev->ethtool_ops->set_tso(dev, edata.data);
  419. }
  420. static int ethtool_self_test(struct net_device *dev, char __user *useraddr)
  421. {
  422. struct ethtool_test test;
  423. struct ethtool_ops *ops = dev->ethtool_ops;
  424. u64 *data;
  425. int ret;
  426. if (!ops->self_test || !ops->self_test_count)
  427. return -EOPNOTSUPP;
  428. if (copy_from_user(&test, useraddr, sizeof(test)))
  429. return -EFAULT;
  430. test.len = ops->self_test_count(dev);
  431. data = kmalloc(test.len * sizeof(u64), GFP_USER);
  432. if (!data)
  433. return -ENOMEM;
  434. ops->self_test(dev, &test, data);
  435. ret = -EFAULT;
  436. if (copy_to_user(useraddr, &test, sizeof(test)))
  437. goto out;
  438. useraddr += sizeof(test);
  439. if (copy_to_user(useraddr, data, test.len * sizeof(u64)))
  440. goto out;
  441. ret = 0;
  442. out:
  443. kfree(data);
  444. return ret;
  445. }
  446. static int ethtool_get_strings(struct net_device *dev, void __user *useraddr)
  447. {
  448. struct ethtool_gstrings gstrings;
  449. struct ethtool_ops *ops = dev->ethtool_ops;
  450. u8 *data;
  451. int ret;
  452. if (!ops->get_strings)
  453. return -EOPNOTSUPP;
  454. if (copy_from_user(&gstrings, useraddr, sizeof(gstrings)))
  455. return -EFAULT;
  456. switch (gstrings.string_set) {
  457. case ETH_SS_TEST:
  458. if (!ops->self_test_count)
  459. return -EOPNOTSUPP;
  460. gstrings.len = ops->self_test_count(dev);
  461. break;
  462. case ETH_SS_STATS:
  463. if (!ops->get_stats_count)
  464. return -EOPNOTSUPP;
  465. gstrings.len = ops->get_stats_count(dev);
  466. break;
  467. default:
  468. return -EINVAL;
  469. }
  470. data = kmalloc(gstrings.len * ETH_GSTRING_LEN, GFP_USER);
  471. if (!data)
  472. return -ENOMEM;
  473. ops->get_strings(dev, gstrings.string_set, data);
  474. ret = -EFAULT;
  475. if (copy_to_user(useraddr, &gstrings, sizeof(gstrings)))
  476. goto out;
  477. useraddr += sizeof(gstrings);
  478. if (copy_to_user(useraddr, data, gstrings.len * ETH_GSTRING_LEN))
  479. goto out;
  480. ret = 0;
  481. out:
  482. kfree(data);
  483. return ret;
  484. }
  485. static int ethtool_phys_id(struct net_device *dev, void __user *useraddr)
  486. {
  487. struct ethtool_value id;
  488. if (!dev->ethtool_ops->phys_id)
  489. return -EOPNOTSUPP;
  490. if (copy_from_user(&id, useraddr, sizeof(id)))
  491. return -EFAULT;
  492. return dev->ethtool_ops->phys_id(dev, id.data);
  493. }
  494. static int ethtool_get_stats(struct net_device *dev, void __user *useraddr)
  495. {
  496. struct ethtool_stats stats;
  497. struct ethtool_ops *ops = dev->ethtool_ops;
  498. u64 *data;
  499. int ret;
  500. if (!ops->get_ethtool_stats || !ops->get_stats_count)
  501. return -EOPNOTSUPP;
  502. if (copy_from_user(&stats, useraddr, sizeof(stats)))
  503. return -EFAULT;
  504. stats.n_stats = ops->get_stats_count(dev);
  505. data = kmalloc(stats.n_stats * sizeof(u64), GFP_USER);
  506. if (!data)
  507. return -ENOMEM;
  508. ops->get_ethtool_stats(dev, &stats, data);
  509. ret = -EFAULT;
  510. if (copy_to_user(useraddr, &stats, sizeof(stats)))
  511. goto out;
  512. useraddr += sizeof(stats);
  513. if (copy_to_user(useraddr, data, stats.n_stats * sizeof(u64)))
  514. goto out;
  515. ret = 0;
  516. out:
  517. kfree(data);
  518. return ret;
  519. }
  520. /* The main entry point in this file. Called from net/core/dev.c */
  521. int dev_ethtool(struct ifreq *ifr)
  522. {
  523. struct net_device *dev = __dev_get_by_name(ifr->ifr_name);
  524. void __user *useraddr = ifr->ifr_data;
  525. u32 ethcmd;
  526. int rc;
  527. unsigned long old_features;
  528. /*
  529. * XXX: This can be pushed down into the ethtool_* handlers that
  530. * need it. Keep existing behaviour for the moment.
  531. */
  532. if (!capable(CAP_NET_ADMIN))
  533. return -EPERM;
  534. if (!dev || !netif_device_present(dev))
  535. return -ENODEV;
  536. if (!dev->ethtool_ops)
  537. goto ioctl;
  538. if (copy_from_user(&ethcmd, useraddr, sizeof (ethcmd)))
  539. return -EFAULT;
  540. if(dev->ethtool_ops->begin)
  541. if ((rc = dev->ethtool_ops->begin(dev)) < 0)
  542. return rc;
  543. old_features = dev->features;
  544. switch (ethcmd) {
  545. case ETHTOOL_GSET:
  546. rc = ethtool_get_settings(dev, useraddr);
  547. break;
  548. case ETHTOOL_SSET:
  549. rc = ethtool_set_settings(dev, useraddr);
  550. break;
  551. case ETHTOOL_GDRVINFO:
  552. rc = ethtool_get_drvinfo(dev, useraddr);
  553. break;
  554. case ETHTOOL_GREGS:
  555. rc = ethtool_get_regs(dev, useraddr);
  556. break;
  557. case ETHTOOL_GWOL:
  558. rc = ethtool_get_wol(dev, useraddr);
  559. break;
  560. case ETHTOOL_SWOL:
  561. rc = ethtool_set_wol(dev, useraddr);
  562. break;
  563. case ETHTOOL_GMSGLVL:
  564. rc = ethtool_get_msglevel(dev, useraddr);
  565. break;
  566. case ETHTOOL_SMSGLVL:
  567. rc = ethtool_set_msglevel(dev, useraddr);
  568. break;
  569. case ETHTOOL_NWAY_RST:
  570. rc = ethtool_nway_reset(dev);
  571. break;
  572. case ETHTOOL_GLINK:
  573. rc = ethtool_get_link(dev, useraddr);
  574. break;
  575. case ETHTOOL_GEEPROM:
  576. rc = ethtool_get_eeprom(dev, useraddr);
  577. break;
  578. case ETHTOOL_SEEPROM:
  579. rc = ethtool_set_eeprom(dev, useraddr);
  580. break;
  581. case ETHTOOL_GCOALESCE:
  582. rc = ethtool_get_coalesce(dev, useraddr);
  583. break;
  584. case ETHTOOL_SCOALESCE:
  585. rc = ethtool_set_coalesce(dev, useraddr);
  586. break;
  587. case ETHTOOL_GRINGPARAM:
  588. rc = ethtool_get_ringparam(dev, useraddr);
  589. break;
  590. case ETHTOOL_SRINGPARAM:
  591. rc = ethtool_set_ringparam(dev, useraddr);
  592. break;
  593. case ETHTOOL_GPAUSEPARAM:
  594. rc = ethtool_get_pauseparam(dev, useraddr);
  595. break;
  596. case ETHTOOL_SPAUSEPARAM:
  597. rc = ethtool_set_pauseparam(dev, useraddr);
  598. break;
  599. case ETHTOOL_GRXCSUM:
  600. rc = ethtool_get_rx_csum(dev, useraddr);
  601. break;
  602. case ETHTOOL_SRXCSUM:
  603. rc = ethtool_set_rx_csum(dev, useraddr);
  604. break;
  605. case ETHTOOL_GTXCSUM:
  606. rc = ethtool_get_tx_csum(dev, useraddr);
  607. break;
  608. case ETHTOOL_STXCSUM:
  609. rc = ethtool_set_tx_csum(dev, useraddr);
  610. break;
  611. case ETHTOOL_GSG:
  612. rc = ethtool_get_sg(dev, useraddr);
  613. break;
  614. case ETHTOOL_SSG:
  615. rc = ethtool_set_sg(dev, useraddr);
  616. break;
  617. case ETHTOOL_GTSO:
  618. rc = ethtool_get_tso(dev, useraddr);
  619. break;
  620. case ETHTOOL_STSO:
  621. rc = ethtool_set_tso(dev, useraddr);
  622. break;
  623. case ETHTOOL_TEST:
  624. rc = ethtool_self_test(dev, useraddr);
  625. break;
  626. case ETHTOOL_GSTRINGS:
  627. rc = ethtool_get_strings(dev, useraddr);
  628. break;
  629. case ETHTOOL_PHYS_ID:
  630. rc = ethtool_phys_id(dev, useraddr);
  631. break;
  632. case ETHTOOL_GSTATS:
  633. rc = ethtool_get_stats(dev, useraddr);
  634. break;
  635. default:
  636. rc = -EOPNOTSUPP;
  637. }
  638. if(dev->ethtool_ops->complete)
  639. dev->ethtool_ops->complete(dev);
  640. if (old_features != dev->features)
  641. netdev_features_change(dev);
  642. return rc;
  643. ioctl:
  644. if (dev->do_ioctl)
  645. return dev->do_ioctl(dev, ifr, SIOCETHTOOL);
  646. return -EOPNOTSUPP;
  647. }
  648. EXPORT_SYMBOL(dev_ethtool);
  649. EXPORT_SYMBOL(ethtool_op_get_link);
  650. EXPORT_SYMBOL(ethtool_op_get_sg);
  651. EXPORT_SYMBOL(ethtool_op_get_tso);
  652. EXPORT_SYMBOL(ethtool_op_get_tx_csum);
  653. EXPORT_SYMBOL(ethtool_op_set_sg);
  654. EXPORT_SYMBOL(ethtool_op_set_tso);
  655. EXPORT_SYMBOL(ethtool_op_set_tx_csum);
  656. EXPORT_SYMBOL(ethtool_op_set_tx_hw_csum);