ucc_geth_ethtool.c 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424
  1. /*
  2. * Copyright (c) 2007 Freescale Semiconductor, Inc. All rights reserved.
  3. *
  4. * Description: QE UCC Gigabit Ethernet Ethtool API Set
  5. *
  6. * Author: Li Yang <leoli@freescale.com>
  7. *
  8. * Limitation:
  9. * Can only get/set settings of the first queue.
  10. * Need to re-open the interface manually after changing some parameters.
  11. *
  12. * This program is free software; you can redistribute it and/or modify it
  13. * under the terms of the GNU General Public License as published by the
  14. * Free Software Foundation; either version 2 of the License, or (at your
  15. * option) any later version.
  16. */
  17. #include <linux/kernel.h>
  18. #include <linux/init.h>
  19. #include <linux/errno.h>
  20. #include <linux/stddef.h>
  21. #include <linux/interrupt.h>
  22. #include <linux/netdevice.h>
  23. #include <linux/etherdevice.h>
  24. #include <linux/skbuff.h>
  25. #include <linux/spinlock.h>
  26. #include <linux/mm.h>
  27. #include <linux/delay.h>
  28. #include <linux/dma-mapping.h>
  29. #include <linux/ethtool.h>
  30. #include <linux/mii.h>
  31. #include <linux/phy.h>
  32. #include <asm/io.h>
  33. #include <asm/irq.h>
  34. #include <asm/uaccess.h>
  35. #include <asm/types.h>
  36. #include "ucc_geth.h"
  37. static char hw_stat_gstrings[][ETH_GSTRING_LEN] = {
  38. "tx-64-frames",
  39. "tx-65-127-frames",
  40. "tx-128-255-frames",
  41. "rx-64-frames",
  42. "rx-65-127-frames",
  43. "rx-128-255-frames",
  44. "tx-bytes-ok",
  45. "tx-pause-frames",
  46. "tx-multicast-frames",
  47. "tx-broadcast-frames",
  48. "rx-frames",
  49. "rx-bytes-ok",
  50. "rx-bytes-all",
  51. "rx-multicast-frames",
  52. "rx-broadcast-frames",
  53. "stats-counter-carry",
  54. "stats-counter-mask",
  55. "rx-dropped-frames",
  56. };
  57. static char tx_fw_stat_gstrings[][ETH_GSTRING_LEN] = {
  58. "tx-single-collision",
  59. "tx-multiple-collision",
  60. "tx-late-collsion",
  61. "tx-aborted-frames",
  62. "tx-lost-frames",
  63. "tx-carrier-sense-errors",
  64. "tx-frames-ok",
  65. "tx-excessive-differ-frames",
  66. "tx-256-511-frames",
  67. "tx-512-1023-frames",
  68. "tx-1024-1518-frames",
  69. "tx-jumbo-frames",
  70. };
  71. static char rx_fw_stat_gstrings[][ETH_GSTRING_LEN] = {
  72. "rx-crc-errors",
  73. "rx-alignment-errors",
  74. "rx-in-range-length-errors",
  75. "rx-out-of-range-length-errors",
  76. "rx-too-long-frames",
  77. "rx-runt",
  78. "rx-very-long-event",
  79. "rx-symbol-errors",
  80. "rx-busy-drop-frames",
  81. "reserved",
  82. "reserved",
  83. "rx-mismatch-drop-frames",
  84. "rx-small-than-64",
  85. "rx-256-511-frames",
  86. "rx-512-1023-frames",
  87. "rx-1024-1518-frames",
  88. "rx-jumbo-frames",
  89. "rx-mac-error-loss",
  90. "rx-pause-frames",
  91. "reserved",
  92. "rx-vlan-removed",
  93. "rx-vlan-replaced",
  94. "rx-vlan-inserted",
  95. "rx-ip-checksum-errors",
  96. };
  97. #define UEC_HW_STATS_LEN ARRAY_SIZE(hw_stat_gstrings)
  98. #define UEC_TX_FW_STATS_LEN ARRAY_SIZE(tx_fw_stat_gstrings)
  99. #define UEC_RX_FW_STATS_LEN ARRAY_SIZE(rx_fw_stat_gstrings)
  100. static int
  101. uec_get_settings(struct net_device *netdev, struct ethtool_cmd *ecmd)
  102. {
  103. struct ucc_geth_private *ugeth = netdev_priv(netdev);
  104. struct phy_device *phydev = ugeth->phydev;
  105. struct ucc_geth_info *ug_info = ugeth->ug_info;
  106. if (!phydev)
  107. return -ENODEV;
  108. ecmd->maxtxpkt = 1;
  109. ecmd->maxrxpkt = ug_info->interruptcoalescingmaxvalue[0];
  110. return phy_ethtool_gset(phydev, ecmd);
  111. }
  112. static int
  113. uec_set_settings(struct net_device *netdev, struct ethtool_cmd *ecmd)
  114. {
  115. struct ucc_geth_private *ugeth = netdev_priv(netdev);
  116. struct phy_device *phydev = ugeth->phydev;
  117. if (!phydev)
  118. return -ENODEV;
  119. return phy_ethtool_sset(phydev, ecmd);
  120. }
  121. static void
  122. uec_get_pauseparam(struct net_device *netdev,
  123. struct ethtool_pauseparam *pause)
  124. {
  125. struct ucc_geth_private *ugeth = netdev_priv(netdev);
  126. pause->autoneg = ugeth->phydev->autoneg;
  127. if (ugeth->ug_info->receiveFlowControl)
  128. pause->rx_pause = 1;
  129. if (ugeth->ug_info->transmitFlowControl)
  130. pause->tx_pause = 1;
  131. }
  132. static int
  133. uec_set_pauseparam(struct net_device *netdev,
  134. struct ethtool_pauseparam *pause)
  135. {
  136. struct ucc_geth_private *ugeth = netdev_priv(netdev);
  137. int ret = 0;
  138. ugeth->ug_info->receiveFlowControl = pause->rx_pause;
  139. ugeth->ug_info->transmitFlowControl = pause->tx_pause;
  140. if (ugeth->phydev->autoneg) {
  141. if (netif_running(netdev)) {
  142. /* FIXME: automatically restart */
  143. printk(KERN_INFO
  144. "Please re-open the interface.\n");
  145. }
  146. } else {
  147. struct ucc_geth_info *ug_info = ugeth->ug_info;
  148. ret = init_flow_control_params(ug_info->aufc,
  149. ug_info->receiveFlowControl,
  150. ug_info->transmitFlowControl,
  151. ug_info->pausePeriod,
  152. ug_info->extensionField,
  153. &ugeth->uccf->uf_regs->upsmr,
  154. &ugeth->ug_regs->uempr,
  155. &ugeth->ug_regs->maccfg1);
  156. }
  157. return ret;
  158. }
  159. static uint32_t
  160. uec_get_msglevel(struct net_device *netdev)
  161. {
  162. struct ucc_geth_private *ugeth = netdev_priv(netdev);
  163. return ugeth->msg_enable;
  164. }
  165. static void
  166. uec_set_msglevel(struct net_device *netdev, uint32_t data)
  167. {
  168. struct ucc_geth_private *ugeth = netdev_priv(netdev);
  169. ugeth->msg_enable = data;
  170. }
  171. static int
  172. uec_get_regs_len(struct net_device *netdev)
  173. {
  174. return sizeof(struct ucc_geth);
  175. }
  176. static void
  177. uec_get_regs(struct net_device *netdev,
  178. struct ethtool_regs *regs, void *p)
  179. {
  180. int i;
  181. struct ucc_geth_private *ugeth = netdev_priv(netdev);
  182. u32 __iomem *ug_regs = (u32 __iomem *)ugeth->ug_regs;
  183. u32 *buff = p;
  184. for (i = 0; i < sizeof(struct ucc_geth) / sizeof(u32); i++)
  185. buff[i] = in_be32(&ug_regs[i]);
  186. }
  187. static void
  188. uec_get_ringparam(struct net_device *netdev,
  189. struct ethtool_ringparam *ring)
  190. {
  191. struct ucc_geth_private *ugeth = netdev_priv(netdev);
  192. struct ucc_geth_info *ug_info = ugeth->ug_info;
  193. int queue = 0;
  194. ring->rx_max_pending = UCC_GETH_BD_RING_SIZE_MAX;
  195. ring->rx_mini_max_pending = UCC_GETH_BD_RING_SIZE_MAX;
  196. ring->rx_jumbo_max_pending = UCC_GETH_BD_RING_SIZE_MAX;
  197. ring->tx_max_pending = UCC_GETH_BD_RING_SIZE_MAX;
  198. ring->rx_pending = ug_info->bdRingLenRx[queue];
  199. ring->rx_mini_pending = ug_info->bdRingLenRx[queue];
  200. ring->rx_jumbo_pending = ug_info->bdRingLenRx[queue];
  201. ring->tx_pending = ug_info->bdRingLenTx[queue];
  202. }
  203. static int
  204. uec_set_ringparam(struct net_device *netdev,
  205. struct ethtool_ringparam *ring)
  206. {
  207. struct ucc_geth_private *ugeth = netdev_priv(netdev);
  208. struct ucc_geth_info *ug_info = ugeth->ug_info;
  209. int queue = 0, ret = 0;
  210. if (ring->rx_pending < UCC_GETH_RX_BD_RING_SIZE_MIN) {
  211. printk("%s: RxBD ring size must be no smaller than %d.\n",
  212. netdev->name, UCC_GETH_RX_BD_RING_SIZE_MIN);
  213. return -EINVAL;
  214. }
  215. if (ring->rx_pending % UCC_GETH_RX_BD_RING_SIZE_ALIGNMENT) {
  216. printk("%s: RxBD ring size must be multiple of %d.\n",
  217. netdev->name, UCC_GETH_RX_BD_RING_SIZE_ALIGNMENT);
  218. return -EINVAL;
  219. }
  220. if (ring->tx_pending < UCC_GETH_TX_BD_RING_SIZE_MIN) {
  221. printk("%s: TxBD ring size must be no smaller than %d.\n",
  222. netdev->name, UCC_GETH_TX_BD_RING_SIZE_MIN);
  223. return -EINVAL;
  224. }
  225. ug_info->bdRingLenRx[queue] = ring->rx_pending;
  226. ug_info->bdRingLenTx[queue] = ring->tx_pending;
  227. if (netif_running(netdev)) {
  228. /* FIXME: restart automatically */
  229. printk(KERN_INFO
  230. "Please re-open the interface.\n");
  231. }
  232. return ret;
  233. }
  234. static int uec_get_sset_count(struct net_device *netdev, int sset)
  235. {
  236. struct ucc_geth_private *ugeth = netdev_priv(netdev);
  237. u32 stats_mode = ugeth->ug_info->statisticsMode;
  238. int len = 0;
  239. switch (sset) {
  240. case ETH_SS_STATS:
  241. if (stats_mode & UCC_GETH_STATISTICS_GATHERING_MODE_HARDWARE)
  242. len += UEC_HW_STATS_LEN;
  243. if (stats_mode & UCC_GETH_STATISTICS_GATHERING_MODE_FIRMWARE_TX)
  244. len += UEC_TX_FW_STATS_LEN;
  245. if (stats_mode & UCC_GETH_STATISTICS_GATHERING_MODE_FIRMWARE_RX)
  246. len += UEC_RX_FW_STATS_LEN;
  247. return len;
  248. default:
  249. return -EOPNOTSUPP;
  250. }
  251. }
  252. static void uec_get_strings(struct net_device *netdev, u32 stringset, u8 *buf)
  253. {
  254. struct ucc_geth_private *ugeth = netdev_priv(netdev);
  255. u32 stats_mode = ugeth->ug_info->statisticsMode;
  256. if (stats_mode & UCC_GETH_STATISTICS_GATHERING_MODE_HARDWARE) {
  257. memcpy(buf, hw_stat_gstrings, UEC_HW_STATS_LEN *
  258. ETH_GSTRING_LEN);
  259. buf += UEC_HW_STATS_LEN * ETH_GSTRING_LEN;
  260. }
  261. if (stats_mode & UCC_GETH_STATISTICS_GATHERING_MODE_FIRMWARE_TX) {
  262. memcpy(buf, tx_fw_stat_gstrings, UEC_TX_FW_STATS_LEN *
  263. ETH_GSTRING_LEN);
  264. buf += UEC_TX_FW_STATS_LEN * ETH_GSTRING_LEN;
  265. }
  266. if (stats_mode & UCC_GETH_STATISTICS_GATHERING_MODE_FIRMWARE_RX)
  267. memcpy(buf, rx_fw_stat_gstrings, UEC_RX_FW_STATS_LEN *
  268. ETH_GSTRING_LEN);
  269. }
  270. static void uec_get_ethtool_stats(struct net_device *netdev,
  271. struct ethtool_stats *stats, uint64_t *data)
  272. {
  273. struct ucc_geth_private *ugeth = netdev_priv(netdev);
  274. u32 stats_mode = ugeth->ug_info->statisticsMode;
  275. u32 __iomem *base;
  276. int i, j = 0;
  277. if (stats_mode & UCC_GETH_STATISTICS_GATHERING_MODE_HARDWARE) {
  278. if (ugeth->ug_regs)
  279. base = (u32 __iomem *)&ugeth->ug_regs->tx64;
  280. else
  281. base = NULL;
  282. for (i = 0; i < UEC_HW_STATS_LEN; i++)
  283. data[j++] = base ? in_be32(&base[i]) : 0;
  284. }
  285. if (stats_mode & UCC_GETH_STATISTICS_GATHERING_MODE_FIRMWARE_TX) {
  286. base = (u32 __iomem *)ugeth->p_tx_fw_statistics_pram;
  287. for (i = 0; i < UEC_TX_FW_STATS_LEN; i++)
  288. data[j++] = base ? in_be32(&base[i]) : 0;
  289. }
  290. if (stats_mode & UCC_GETH_STATISTICS_GATHERING_MODE_FIRMWARE_RX) {
  291. base = (u32 __iomem *)ugeth->p_rx_fw_statistics_pram;
  292. for (i = 0; i < UEC_RX_FW_STATS_LEN; i++)
  293. data[j++] = base ? in_be32(&base[i]) : 0;
  294. }
  295. }
  296. static int uec_nway_reset(struct net_device *netdev)
  297. {
  298. struct ucc_geth_private *ugeth = netdev_priv(netdev);
  299. return phy_start_aneg(ugeth->phydev);
  300. }
  301. /* Report driver information */
  302. static void
  303. uec_get_drvinfo(struct net_device *netdev,
  304. struct ethtool_drvinfo *drvinfo)
  305. {
  306. strncpy(drvinfo->driver, DRV_NAME, 32);
  307. strncpy(drvinfo->version, DRV_VERSION, 32);
  308. strncpy(drvinfo->fw_version, "N/A", 32);
  309. strncpy(drvinfo->bus_info, "QUICC ENGINE", 32);
  310. drvinfo->eedump_len = 0;
  311. drvinfo->regdump_len = uec_get_regs_len(netdev);
  312. }
  313. #ifdef CONFIG_PM
  314. static void uec_get_wol(struct net_device *netdev, struct ethtool_wolinfo *wol)
  315. {
  316. struct ucc_geth_private *ugeth = netdev_priv(netdev);
  317. struct phy_device *phydev = ugeth->phydev;
  318. if (phydev && phydev->irq)
  319. wol->supported |= WAKE_PHY;
  320. if (qe_alive_during_sleep())
  321. wol->supported |= WAKE_MAGIC;
  322. wol->wolopts = ugeth->wol_en;
  323. }
  324. static int uec_set_wol(struct net_device *netdev, struct ethtool_wolinfo *wol)
  325. {
  326. struct ucc_geth_private *ugeth = netdev_priv(netdev);
  327. struct phy_device *phydev = ugeth->phydev;
  328. if (wol->wolopts & ~(WAKE_PHY | WAKE_MAGIC))
  329. return -EINVAL;
  330. else if (wol->wolopts & WAKE_PHY && (!phydev || !phydev->irq))
  331. return -EINVAL;
  332. else if (wol->wolopts & WAKE_MAGIC && !qe_alive_during_sleep())
  333. return -EINVAL;
  334. ugeth->wol_en = wol->wolopts;
  335. device_set_wakeup_enable(&netdev->dev, ugeth->wol_en);
  336. return 0;
  337. }
  338. #else
  339. #define uec_get_wol NULL
  340. #define uec_set_wol NULL
  341. #endif /* CONFIG_PM */
  342. static const struct ethtool_ops uec_ethtool_ops = {
  343. .get_settings = uec_get_settings,
  344. .set_settings = uec_set_settings,
  345. .get_drvinfo = uec_get_drvinfo,
  346. .get_regs_len = uec_get_regs_len,
  347. .get_regs = uec_get_regs,
  348. .get_msglevel = uec_get_msglevel,
  349. .set_msglevel = uec_set_msglevel,
  350. .nway_reset = uec_nway_reset,
  351. .get_link = ethtool_op_get_link,
  352. .get_ringparam = uec_get_ringparam,
  353. .set_ringparam = uec_set_ringparam,
  354. .get_pauseparam = uec_get_pauseparam,
  355. .set_pauseparam = uec_set_pauseparam,
  356. .get_sset_count = uec_get_sset_count,
  357. .get_strings = uec_get_strings,
  358. .get_ethtool_stats = uec_get_ethtool_stats,
  359. .get_wol = uec_get_wol,
  360. .set_wol = uec_set_wol,
  361. };
  362. void uec_set_ethtool_ops(struct net_device *netdev)
  363. {
  364. SET_ETHTOOL_OPS(netdev, &uec_ethtool_ops);
  365. }