ethtool.c 18 KB

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