ucc_geth_ethtool.c 11 KB

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