ucc_geth_ethtool.c 10 KB

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