ucc_geth_ethtool.c 10 KB

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