a2eaba1a1e6808584fe2ba36aebc8ed473e9bee6
[openwrt/openwrt.git] / target / linux / ar71xx / files / drivers / net / ethernet / atheros / ag71xx / ag71xx_ethtool.c
1 /*
2 * Atheros AR71xx built-in ethernet mac driver
3 *
4 * Copyright (C) 2008-2010 Gabor Juhos <juhosg@openwrt.org>
5 * Copyright (C) 2008 Imre Kaloz <kaloz@openwrt.org>
6 *
7 * Based on Atheros' AG7100 driver
8 *
9 * This program is free software; you can redistribute it and/or modify it
10 * under the terms of the GNU General Public License version 2 as published
11 * by the Free Software Foundation.
12 */
13
14 #include "ag71xx.h"
15 #include <linux/version.h>
16
17 static int ag71xx_ethtool_get_settings(struct net_device *dev,
18 struct ethtool_cmd *cmd)
19 {
20 struct ag71xx *ag = netdev_priv(dev);
21 struct phy_device *phydev = ag->phy_dev;
22
23 if (!phydev)
24 return -ENODEV;
25
26 #if LINUX_VERSION_CODE < KERNEL_VERSION(4,14,0)
27 return phy_ethtool_gset(phydev, cmd);
28 #else
29 return phy_ethtool_ioctl(phydev, cmd);
30 #endif
31 }
32
33 static int ag71xx_ethtool_set_settings(struct net_device *dev,
34 struct ethtool_cmd *cmd)
35 {
36 struct ag71xx *ag = netdev_priv(dev);
37 struct phy_device *phydev = ag->phy_dev;
38
39 if (!phydev)
40 return -ENODEV;
41
42 #if LINUX_VERSION_CODE < KERNEL_VERSION(4,14,0)
43 return phy_ethtool_sset(phydev, cmd);
44 #else
45 return phy_ethtool_ioctl(phydev, cmd);
46 #endif
47 }
48
49 static void ag71xx_ethtool_get_drvinfo(struct net_device *dev,
50 struct ethtool_drvinfo *info)
51 {
52 struct ag71xx *ag = netdev_priv(dev);
53
54 strcpy(info->driver, ag->pdev->dev.driver->name);
55 strcpy(info->version, AG71XX_DRV_VERSION);
56 strcpy(info->bus_info, dev_name(&ag->pdev->dev));
57 }
58
59 static u32 ag71xx_ethtool_get_msglevel(struct net_device *dev)
60 {
61 struct ag71xx *ag = netdev_priv(dev);
62
63 return ag->msg_enable;
64 }
65
66 static void ag71xx_ethtool_set_msglevel(struct net_device *dev, u32 msg_level)
67 {
68 struct ag71xx *ag = netdev_priv(dev);
69
70 ag->msg_enable = msg_level;
71 }
72
73 static void ag71xx_ethtool_get_ringparam(struct net_device *dev,
74 struct ethtool_ringparam *er)
75 {
76 struct ag71xx *ag = netdev_priv(dev);
77
78 er->tx_max_pending = AG71XX_TX_RING_SIZE_MAX;
79 er->rx_max_pending = AG71XX_RX_RING_SIZE_MAX;
80 er->rx_mini_max_pending = 0;
81 er->rx_jumbo_max_pending = 0;
82
83 er->tx_pending = BIT(ag->tx_ring.order);
84 er->rx_pending = BIT(ag->rx_ring.order);
85 er->rx_mini_pending = 0;
86 er->rx_jumbo_pending = 0;
87
88 if (ag->tx_ring.desc_split)
89 er->tx_pending /= AG71XX_TX_RING_DS_PER_PKT;
90 }
91
92 static int ag71xx_ethtool_set_ringparam(struct net_device *dev,
93 struct ethtool_ringparam *er)
94 {
95 struct ag71xx *ag = netdev_priv(dev);
96 unsigned tx_size;
97 unsigned rx_size;
98 int err = 0;
99
100 if (er->rx_mini_pending != 0||
101 er->rx_jumbo_pending != 0 ||
102 er->rx_pending == 0 ||
103 er->tx_pending == 0)
104 return -EINVAL;
105
106 tx_size = er->tx_pending < AG71XX_TX_RING_SIZE_MAX ?
107 er->tx_pending : AG71XX_TX_RING_SIZE_MAX;
108
109 rx_size = er->rx_pending < AG71XX_RX_RING_SIZE_MAX ?
110 er->rx_pending : AG71XX_RX_RING_SIZE_MAX;
111
112 if (netif_running(dev)) {
113 err = dev->netdev_ops->ndo_stop(dev);
114 if (err)
115 return err;
116 }
117
118 if (ag->tx_ring.desc_split)
119 tx_size *= AG71XX_TX_RING_DS_PER_PKT;
120
121 ag->tx_ring.order = ag71xx_ring_size_order(tx_size);
122 ag->rx_ring.order = ag71xx_ring_size_order(rx_size);
123
124 if (netif_running(dev))
125 err = dev->netdev_ops->ndo_open(dev);
126
127 return err;
128 }
129
130 struct ethtool_ops ag71xx_ethtool_ops = {
131 .set_settings = ag71xx_ethtool_set_settings,
132 .get_settings = ag71xx_ethtool_get_settings,
133 .get_drvinfo = ag71xx_ethtool_get_drvinfo,
134 .get_msglevel = ag71xx_ethtool_get_msglevel,
135 .set_msglevel = ag71xx_ethtool_set_msglevel,
136 .get_ringparam = ag71xx_ethtool_get_ringparam,
137 .set_ringparam = ag71xx_ethtool_set_ringparam,
138 .get_link = ethtool_op_get_link,
139 .get_ts_info = ethtool_op_get_ts_info,
140 };