ucc_geth_ethtool.c 10 KB

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