ucc_geth_ethtool.c 10 KB

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