1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
|
// SPDX-License-Identifier: GPL-2.0
#define pr_fmt(fmt) "bcmasp_ethtool: " fmt
#include <linux/ethtool.h>
#include <linux/netdevice.h>
#include <linux/platform_device.h>
#include "bcmasp.h"
#include "bcmasp_intf_defs.h"
static void bcmasp_get_drvinfo(struct net_device *dev,
struct ethtool_drvinfo *info)
{
strscpy(info->driver, "bcmasp", sizeof(info->driver));
strscpy(info->bus_info, dev_name(dev->dev.parent),
sizeof(info->bus_info));
}
static u32 bcmasp_get_msglevel(struct net_device *dev)
{
struct bcmasp_intf *intf = netdev_priv(dev);
return intf->msg_enable;
}
static void bcmasp_set_msglevel(struct net_device *dev, u32 level)
{
struct bcmasp_intf *intf = netdev_priv(dev);
intf->msg_enable = level;
}
#define BCMASP_SUPPORTED_WAKE (WAKE_MAGIC | WAKE_MAGICSECURE | WAKE_FILTER)
static void bcmasp_get_wol(struct net_device *dev, struct ethtool_wolinfo *wol)
{
struct bcmasp_intf *intf = netdev_priv(dev);
wol->supported = BCMASP_SUPPORTED_WAKE;
wol->wolopts = intf->wolopts;
memset(wol->sopass, 0, sizeof(wol->sopass));
if (wol->wolopts & WAKE_MAGICSECURE)
memcpy(wol->sopass, intf->sopass, sizeof(intf->sopass));
}
static int bcmasp_set_wol(struct net_device *dev, struct ethtool_wolinfo *wol)
{
struct bcmasp_intf *intf = netdev_priv(dev);
struct bcmasp_priv *priv = intf->parent;
struct device *kdev = &priv->pdev->dev;
if (!device_can_wakeup(kdev))
return -EOPNOTSUPP;
/* Interface Specific */
intf->wolopts = wol->wolopts;
if (intf->wolopts & WAKE_MAGICSECURE)
memcpy(intf->sopass, wol->sopass, sizeof(wol->sopass));
mutex_lock(&priv->wol_lock);
priv->enable_wol(intf, !!intf->wolopts);
mutex_unlock(&priv->wol_lock);
return 0;
}
static int bcmasp_flow_insert(struct net_device *dev, struct ethtool_rxnfc *cmd)
{
struct bcmasp_intf *intf = netdev_priv(dev);
struct bcmasp_net_filter *nfilter;
u32 loc = cmd->fs.location;
bool wake = false;
if (cmd->fs.ring_cookie == RX_CLS_FLOW_WAKE)
wake = true;
/* Currently only supports WAKE filters */
if (!wake)
return -EOPNOTSUPP;
switch (cmd->fs.flow_type & ~(FLOW_EXT | FLOW_MAC_EXT)) {
case ETHER_FLOW:
case IP_USER_FLOW:
case TCP_V4_FLOW:
case UDP_V4_FLOW:
case TCP_V6_FLOW:
case UDP_V6_FLOW:
break;
default:
return -EOPNOTSUPP;
}
/* Check if filter already exists */
if (bcmasp_netfilt_check_dup(intf, &cmd->fs))
return -EINVAL;
nfilter = bcmasp_netfilt_get_init(intf, loc, wake, true);
if (IS_ERR(nfilter))
return PTR_ERR(nfilter);
/* Return the location where we did insert the filter */
cmd->fs.location = nfilter->hw_index;
memcpy(&nfilter->fs, &cmd->fs, sizeof(struct ethtool_rx_flow_spec));
/* Since we only support wake filters, defer register programming till
* suspend time.
*/
return 0;
}
static int bcmasp_flow_delete(struct net_device *dev, struct ethtool_rxnfc *cmd)
{
struct bcmasp_intf *intf = netdev_priv(dev);
struct bcmasp_net_filter *nfilter;
nfilter = bcmasp_netfilt_get_init(intf, cmd->fs.location, false, false);
if (IS_ERR(nfilter))
return PTR_ERR(nfilter);
bcmasp_netfilt_release(intf, nfilter);
return 0;
}
static int bcmasp_flow_get(struct bcmasp_intf *intf, struct ethtool_rxnfc *cmd)
{
struct bcmasp_net_filter *nfilter;
nfilter = bcmasp_netfilt_get_init(intf, cmd->fs.location, false, false);
if (IS_ERR(nfilter))
return PTR_ERR(nfilter);
memcpy(&cmd->fs, &nfilter->fs, sizeof(nfilter->fs));
cmd->data = NUM_NET_FILTERS;
return 0;
}
static int bcmasp_set_rxnfc(struct net_device *dev, struct ethtool_rxnfc *cmd)
{
struct bcmasp_intf *intf = netdev_priv(dev);
int ret = -EOPNOTSUPP;
mutex_lock(&intf->parent->net_lock);
switch (cmd->cmd) {
case ETHTOOL_SRXCLSRLINS:
ret = bcmasp_flow_insert(dev, cmd);
break;
case ETHTOOL_SRXCLSRLDEL:
ret = bcmasp_flow_delete(dev, cmd);
break;
default:
break;
}
mutex_unlock(&intf->parent->net_lock);
return ret;
}
static int bcmasp_get_rxnfc(struct net_device *dev, struct ethtool_rxnfc *cmd,
u32 *rule_locs)
{
struct bcmasp_intf *intf = netdev_priv(dev);
int err = 0;
mutex_lock(&intf->parent->net_lock);
switch (cmd->cmd) {
case ETHTOOL_GRXCLSRLCNT:
cmd->rule_cnt = bcmasp_netfilt_get_active(intf);
/* We support specifying rule locations */
cmd->data |= RX_CLS_LOC_SPECIAL;
break;
case ETHTOOL_GRXCLSRULE:
err = bcmasp_flow_get(intf, cmd);
break;
case ETHTOOL_GRXCLSRLALL:
bcmasp_netfilt_get_all_active(intf, rule_locs, &cmd->rule_cnt);
cmd->data = NUM_NET_FILTERS;
break;
default:
err = -EOPNOTSUPP;
break;
}
mutex_unlock(&intf->parent->net_lock);
return err;
}
void bcmasp_eee_enable_set(struct bcmasp_intf *intf, bool enable)
{
u32 reg;
reg = umac_rl(intf, UMC_EEE_CTRL);
if (enable)
reg |= EEE_EN;
else
reg &= ~EEE_EN;
umac_wl(intf, reg, UMC_EEE_CTRL);
intf->eee.eee_enabled = enable;
intf->eee.eee_active = enable;
}
static int bcmasp_get_eee(struct net_device *dev, struct ethtool_eee *e)
{
struct bcmasp_intf *intf = netdev_priv(dev);
struct ethtool_eee *p = &intf->eee;
if (!dev->phydev)
return -ENODEV;
e->eee_enabled = p->eee_enabled;
e->eee_active = p->eee_active;
e->tx_lpi_enabled = p->tx_lpi_enabled;
e->tx_lpi_timer = umac_rl(intf, UMC_EEE_LPI_TIMER);
return phy_ethtool_get_eee(dev->phydev, e);
}
static int bcmasp_set_eee(struct net_device *dev, struct ethtool_eee *e)
{
struct bcmasp_intf *intf = netdev_priv(dev);
struct ethtool_eee *p = &intf->eee;
int ret;
if (!dev->phydev)
return -ENODEV;
if (!p->eee_enabled) {
bcmasp_eee_enable_set(intf, false);
} else {
ret = phy_init_eee(dev->phydev, 0);
if (ret) {
netif_err(intf, hw, dev,
"EEE initialization failed: %d\n", ret);
return ret;
}
umac_wl(intf, e->tx_lpi_timer, UMC_EEE_LPI_TIMER);
intf->eee.eee_active = ret >= 0;
intf->eee.tx_lpi_enabled = e->tx_lpi_enabled;
bcmasp_eee_enable_set(intf, true);
}
return phy_ethtool_set_eee(dev->phydev, e);
}
const struct ethtool_ops bcmasp_ethtool_ops = {
.get_drvinfo = bcmasp_get_drvinfo,
.get_link = ethtool_op_get_link,
.get_link_ksettings = phy_ethtool_get_link_ksettings,
.set_link_ksettings = phy_ethtool_set_link_ksettings,
.get_msglevel = bcmasp_get_msglevel,
.set_msglevel = bcmasp_set_msglevel,
.get_wol = bcmasp_get_wol,
.set_wol = bcmasp_set_wol,
.get_rxnfc = bcmasp_get_rxnfc,
.set_rxnfc = bcmasp_set_rxnfc,
.set_eee = bcmasp_set_eee,
.get_eee = bcmasp_get_eee,
};
|