ucc_geth_ethtool.c 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389
  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-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. extern int init_flow_control_params(u32 automatic_flow_control_mode,
  104. int rx_flow_control_enable,
  105. int tx_flow_control_enable, u16 pause_period,
  106. u16 extension_field, volatile u32 *upsmr_register,
  107. volatile u32 *uempr_register, volatile u32 *maccfg1_register);
  108. static int
  109. uec_get_settings(struct net_device *netdev, struct ethtool_cmd *ecmd)
  110. {
  111. struct ucc_geth_private *ugeth = netdev_priv(netdev);
  112. struct phy_device *phydev = ugeth->phydev;
  113. struct ucc_geth_info *ug_info = ugeth->ug_info;
  114. if (!phydev)
  115. return -ENODEV;
  116. ecmd->maxtxpkt = 1;
  117. ecmd->maxrxpkt = ug_info->interruptcoalescingmaxvalue[0];
  118. return phy_ethtool_gset(phydev, ecmd);
  119. }
  120. static int
  121. uec_set_settings(struct net_device *netdev, struct ethtool_cmd *ecmd)
  122. {
  123. struct ucc_geth_private *ugeth = netdev_priv(netdev);
  124. struct phy_device *phydev = ugeth->phydev;
  125. if (!phydev)
  126. return -ENODEV;
  127. return phy_ethtool_sset(phydev, ecmd);
  128. }
  129. static void
  130. uec_get_pauseparam(struct net_device *netdev,
  131. struct ethtool_pauseparam *pause)
  132. {
  133. struct ucc_geth_private *ugeth = netdev_priv(netdev);
  134. pause->autoneg = ugeth->phydev->autoneg;
  135. if (ugeth->ug_info->receiveFlowControl)
  136. pause->rx_pause = 1;
  137. if (ugeth->ug_info->transmitFlowControl)
  138. pause->tx_pause = 1;
  139. }
  140. static int
  141. uec_set_pauseparam(struct net_device *netdev,
  142. struct ethtool_pauseparam *pause)
  143. {
  144. struct ucc_geth_private *ugeth = netdev_priv(netdev);
  145. int ret = 0;
  146. ugeth->ug_info->receiveFlowControl = pause->rx_pause;
  147. ugeth->ug_info->transmitFlowControl = pause->tx_pause;
  148. if (ugeth->phydev->autoneg) {
  149. if (netif_running(netdev)) {
  150. /* FIXME: automatically restart */
  151. printk(KERN_INFO
  152. "Please re-open the interface.\n");
  153. }
  154. } else {
  155. struct ucc_geth_info *ug_info = ugeth->ug_info;
  156. ret = init_flow_control_params(ug_info->aufc,
  157. ug_info->receiveFlowControl,
  158. ug_info->transmitFlowControl,
  159. ug_info->pausePeriod,
  160. ug_info->extensionField,
  161. &ugeth->uccf->uf_regs->upsmr,
  162. &ugeth->ug_regs->uempr,
  163. &ugeth->ug_regs->maccfg1);
  164. }
  165. return ret;
  166. }
  167. static uint32_t
  168. uec_get_msglevel(struct net_device *netdev)
  169. {
  170. struct ucc_geth_private *ugeth = netdev_priv(netdev);
  171. return ugeth->msg_enable;
  172. }
  173. static void
  174. uec_set_msglevel(struct net_device *netdev, uint32_t data)
  175. {
  176. struct ucc_geth_private *ugeth = netdev_priv(netdev);
  177. ugeth->msg_enable = data;
  178. }
  179. static int
  180. uec_get_regs_len(struct net_device *netdev)
  181. {
  182. return sizeof(struct ucc_geth);
  183. }
  184. static void
  185. uec_get_regs(struct net_device *netdev,
  186. struct ethtool_regs *regs, void *p)
  187. {
  188. int i;
  189. struct ucc_geth_private *ugeth = netdev_priv(netdev);
  190. u32 __iomem *ug_regs = (u32 __iomem *)ugeth->ug_regs;
  191. u32 *buff = p;
  192. for (i = 0; i < sizeof(struct ucc_geth) / sizeof(u32); i++)
  193. buff[i] = in_be32(&ug_regs[i]);
  194. }
  195. static void
  196. uec_get_ringparam(struct net_device *netdev,
  197. struct ethtool_ringparam *ring)
  198. {
  199. struct ucc_geth_private *ugeth = netdev_priv(netdev);
  200. struct ucc_geth_info *ug_info = ugeth->ug_info;
  201. int queue = 0;
  202. ring->rx_max_pending = UCC_GETH_BD_RING_SIZE_MAX;
  203. ring->rx_mini_max_pending = UCC_GETH_BD_RING_SIZE_MAX;
  204. ring->rx_jumbo_max_pending = UCC_GETH_BD_RING_SIZE_MAX;
  205. ring->tx_max_pending = UCC_GETH_BD_RING_SIZE_MAX;
  206. ring->rx_pending = ug_info->bdRingLenRx[queue];
  207. ring->rx_mini_pending = ug_info->bdRingLenRx[queue];
  208. ring->rx_jumbo_pending = ug_info->bdRingLenRx[queue];
  209. ring->tx_pending = ug_info->bdRingLenTx[queue];
  210. }
  211. static int
  212. uec_set_ringparam(struct net_device *netdev,
  213. struct ethtool_ringparam *ring)
  214. {
  215. struct ucc_geth_private *ugeth = netdev_priv(netdev);
  216. struct ucc_geth_info *ug_info = ugeth->ug_info;
  217. int queue = 0, ret = 0;
  218. if (ring->rx_pending < UCC_GETH_RX_BD_RING_SIZE_MIN) {
  219. printk("%s: RxBD ring size must be no smaller than %d.\n",
  220. netdev->name, UCC_GETH_RX_BD_RING_SIZE_MIN);
  221. return -EINVAL;
  222. }
  223. if (ring->rx_pending % UCC_GETH_RX_BD_RING_SIZE_ALIGNMENT) {
  224. printk("%s: RxBD ring size must be multiple of %d.\n",
  225. netdev->name, UCC_GETH_RX_BD_RING_SIZE_ALIGNMENT);
  226. return -EINVAL;
  227. }
  228. if (ring->tx_pending < UCC_GETH_TX_BD_RING_SIZE_MIN) {
  229. printk("%s: TxBD ring size must be no smaller than %d.\n",
  230. netdev->name, UCC_GETH_TX_BD_RING_SIZE_MIN);
  231. return -EINVAL;
  232. }
  233. ug_info->bdRingLenRx[queue] = ring->rx_pending;
  234. ug_info->bdRingLenTx[queue] = ring->tx_pending;
  235. if (netif_running(netdev)) {
  236. /* FIXME: restart automatically */
  237. printk(KERN_INFO
  238. "Please re-open the interface.\n");
  239. }
  240. return ret;
  241. }
  242. static int uec_get_sset_count(struct net_device *netdev, int sset)
  243. {
  244. struct ucc_geth_private *ugeth = netdev_priv(netdev);
  245. u32 stats_mode = ugeth->ug_info->statisticsMode;
  246. int len = 0;
  247. switch (sset) {
  248. case ETH_SS_STATS:
  249. if (stats_mode & UCC_GETH_STATISTICS_GATHERING_MODE_HARDWARE)
  250. len += UEC_HW_STATS_LEN;
  251. if (stats_mode & UCC_GETH_STATISTICS_GATHERING_MODE_FIRMWARE_TX)
  252. len += UEC_TX_FW_STATS_LEN;
  253. if (stats_mode & UCC_GETH_STATISTICS_GATHERING_MODE_FIRMWARE_RX)
  254. len += UEC_RX_FW_STATS_LEN;
  255. return len;
  256. default:
  257. return -EOPNOTSUPP;
  258. }
  259. }
  260. static void uec_get_strings(struct net_device *netdev, u32 stringset, u8 *buf)
  261. {
  262. struct ucc_geth_private *ugeth = netdev_priv(netdev);
  263. u32 stats_mode = ugeth->ug_info->statisticsMode;
  264. if (stats_mode & UCC_GETH_STATISTICS_GATHERING_MODE_HARDWARE) {
  265. memcpy(buf, hw_stat_gstrings, UEC_HW_STATS_LEN *
  266. ETH_GSTRING_LEN);
  267. buf += UEC_HW_STATS_LEN * ETH_GSTRING_LEN;
  268. }
  269. if (stats_mode & UCC_GETH_STATISTICS_GATHERING_MODE_FIRMWARE_TX) {
  270. memcpy(buf, tx_fw_stat_gstrings, UEC_TX_FW_STATS_LEN *
  271. ETH_GSTRING_LEN);
  272. buf += UEC_TX_FW_STATS_LEN * ETH_GSTRING_LEN;
  273. }
  274. if (stats_mode & UCC_GETH_STATISTICS_GATHERING_MODE_FIRMWARE_RX)
  275. memcpy(buf, tx_fw_stat_gstrings, UEC_RX_FW_STATS_LEN *
  276. ETH_GSTRING_LEN);
  277. }
  278. static void uec_get_ethtool_stats(struct net_device *netdev,
  279. struct ethtool_stats *stats, uint64_t *data)
  280. {
  281. struct ucc_geth_private *ugeth = netdev_priv(netdev);
  282. u32 stats_mode = ugeth->ug_info->statisticsMode;
  283. u32 __iomem *base;
  284. int i, j = 0;
  285. if (stats_mode & UCC_GETH_STATISTICS_GATHERING_MODE_HARDWARE) {
  286. base = (u32 __iomem *)&ugeth->ug_regs->tx64;
  287. for (i = 0; i < UEC_HW_STATS_LEN; i++)
  288. data[j++] = (u64)in_be32(&base[i]);
  289. }
  290. if (stats_mode & UCC_GETH_STATISTICS_GATHERING_MODE_FIRMWARE_TX) {
  291. base = (u32 __iomem *)ugeth->p_tx_fw_statistics_pram;
  292. for (i = 0; i < UEC_TX_FW_STATS_LEN; i++)
  293. data[j++] = (u64)in_be32(&base[i]);
  294. }
  295. if (stats_mode & UCC_GETH_STATISTICS_GATHERING_MODE_FIRMWARE_RX) {
  296. base = (u32 __iomem *)ugeth->p_rx_fw_statistics_pram;
  297. for (i = 0; i < UEC_RX_FW_STATS_LEN; i++)
  298. data[j++] = (u64)in_be32(&base[i]);
  299. }
  300. }
  301. static int uec_nway_reset(struct net_device *netdev)
  302. {
  303. struct ucc_geth_private *ugeth = netdev_priv(netdev);
  304. return phy_start_aneg(ugeth->phydev);
  305. }
  306. /* Report driver information */
  307. static void
  308. uec_get_drvinfo(struct net_device *netdev,
  309. struct ethtool_drvinfo *drvinfo)
  310. {
  311. strncpy(drvinfo->driver, DRV_NAME, 32);
  312. strncpy(drvinfo->version, DRV_VERSION, 32);
  313. strncpy(drvinfo->fw_version, "N/A", 32);
  314. strncpy(drvinfo->bus_info, "QUICC ENGINE", 32);
  315. drvinfo->eedump_len = 0;
  316. drvinfo->regdump_len = uec_get_regs_len(netdev);
  317. }
  318. static const struct ethtool_ops uec_ethtool_ops = {
  319. .get_settings = uec_get_settings,
  320. .set_settings = uec_set_settings,
  321. .get_drvinfo = uec_get_drvinfo,
  322. .get_regs_len = uec_get_regs_len,
  323. .get_regs = uec_get_regs,
  324. .get_msglevel = uec_get_msglevel,
  325. .set_msglevel = uec_set_msglevel,
  326. .nway_reset = uec_nway_reset,
  327. .get_link = ethtool_op_get_link,
  328. .get_ringparam = uec_get_ringparam,
  329. .set_ringparam = uec_set_ringparam,
  330. .get_pauseparam = uec_get_pauseparam,
  331. .set_pauseparam = uec_set_pauseparam,
  332. .set_sg = ethtool_op_set_sg,
  333. .get_sset_count = uec_get_sset_count,
  334. .get_strings = uec_get_strings,
  335. .get_ethtool_stats = uec_get_ethtool_stats,
  336. };
  337. void uec_set_ethtool_ops(struct net_device *netdev)
  338. {
  339. SET_ETHTOOL_OPS(netdev, &uec_ethtool_ops);
  340. }