New upstream version 16.11.9
[deb_dpdk.git] / lib / librte_eal / linuxapp / kni / kni_ethtool.c
1 /*-
2  * GPL LICENSE SUMMARY
3  *
4  *   Copyright(c) 2010-2014 Intel Corporation. All rights reserved.
5  *
6  *   This program is free software; you can redistribute it and/or modify
7  *   it under the terms of version 2 of the GNU General Public License as
8  *   published by the Free Software Foundation.
9  *
10  *   This program is distributed in the hope that it will be useful, but
11  *   WITHOUT ANY WARRANTY; without even the implied warranty of
12  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  *   General Public License for more details.
14  *
15  *   You should have received a copy of the GNU General Public License
16  *   along with this program; if not, write to the Free Software
17  *   Foundation, Inc., 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
18  *   The full GNU General Public License is included in this distribution
19  *   in the file called LICENSE.GPL.
20  *
21  *   Contact Information:
22  *   Intel Corporation
23  */
24
25 #include <linux/device.h>
26 #include <linux/netdevice.h>
27 #include <linux/ethtool.h>
28 #include "kni_dev.h"
29
30 static int
31 kni_check_if_running(struct net_device *dev)
32 {
33         struct kni_dev *priv = netdev_priv(dev);
34
35         if (priv->lad_dev)
36                 return 0;
37         else
38                 return -EOPNOTSUPP;
39 }
40
41 static void
42 kni_get_drvinfo(struct net_device *dev, struct ethtool_drvinfo *info)
43 {
44         struct kni_dev *priv = netdev_priv(dev);
45
46         priv->lad_dev->ethtool_ops->get_drvinfo(priv->lad_dev, info);
47 }
48
49 /* ETHTOOL_GLINKSETTINGS replaces ETHTOOL_GSET */
50 #ifndef ETHTOOL_GLINKSETTINGS
51 static int
52 kni_get_settings(struct net_device *dev, struct ethtool_cmd *ecmd)
53 {
54         struct kni_dev *priv = netdev_priv(dev);
55
56         return priv->lad_dev->ethtool_ops->get_settings(priv->lad_dev, ecmd);
57 }
58 #endif
59
60 /* ETHTOOL_SLINKSETTINGS replaces ETHTOOL_SSET */
61 #ifndef ETHTOOL_SLINKSETTINGS
62 static int
63 kni_set_settings(struct net_device *dev, struct ethtool_cmd *ecmd)
64 {
65         struct kni_dev *priv = netdev_priv(dev);
66
67         return priv->lad_dev->ethtool_ops->set_settings(priv->lad_dev, ecmd);
68 }
69 #endif
70
71 static void
72 kni_get_wol(struct net_device *dev, struct ethtool_wolinfo *wol)
73 {
74         struct kni_dev *priv = netdev_priv(dev);
75
76         priv->lad_dev->ethtool_ops->get_wol(priv->lad_dev, wol);
77 }
78
79 static int
80 kni_set_wol(struct net_device *dev, struct ethtool_wolinfo *wol)
81 {
82         struct kni_dev *priv = netdev_priv(dev);
83
84         return priv->lad_dev->ethtool_ops->set_wol(priv->lad_dev, wol);
85 }
86
87 static int
88 kni_nway_reset(struct net_device *dev)
89 {
90         struct kni_dev *priv = netdev_priv(dev);
91
92         return priv->lad_dev->ethtool_ops->nway_reset(priv->lad_dev);
93 }
94
95 static int
96 kni_get_eeprom_len(struct net_device *dev)
97 {
98         struct kni_dev *priv = netdev_priv(dev);
99
100         return priv->lad_dev->ethtool_ops->get_eeprom_len(priv->lad_dev);
101 }
102
103 static int
104 kni_get_eeprom(struct net_device *dev, struct ethtool_eeprom *eeprom,
105                                                         u8 *bytes)
106 {
107         struct kni_dev *priv = netdev_priv(dev);
108
109         return priv->lad_dev->ethtool_ops->get_eeprom(priv->lad_dev, eeprom,
110                                                                 bytes);
111 }
112
113 static int
114 kni_set_eeprom(struct net_device *dev, struct ethtool_eeprom *eeprom,
115                                                         u8 *bytes)
116 {
117         struct kni_dev *priv = netdev_priv(dev);
118
119         return priv->lad_dev->ethtool_ops->set_eeprom(priv->lad_dev, eeprom,
120                                                                 bytes);
121 }
122
123 static void
124 kni_get_ringparam(struct net_device *dev, struct ethtool_ringparam *ring)
125 {
126         struct kni_dev *priv = netdev_priv(dev);
127
128         priv->lad_dev->ethtool_ops->get_ringparam(priv->lad_dev, ring);
129 }
130
131 static int
132 kni_set_ringparam(struct net_device *dev, struct ethtool_ringparam *ring)
133 {
134         struct kni_dev *priv = netdev_priv(dev);
135
136         return priv->lad_dev->ethtool_ops->set_ringparam(priv->lad_dev, ring);
137 }
138
139 static void
140 kni_get_pauseparam(struct net_device *dev, struct ethtool_pauseparam *pause)
141 {
142         struct kni_dev *priv = netdev_priv(dev);
143
144         priv->lad_dev->ethtool_ops->get_pauseparam(priv->lad_dev, pause);
145 }
146
147 static int
148 kni_set_pauseparam(struct net_device *dev, struct ethtool_pauseparam *pause)
149 {
150         struct kni_dev *priv = netdev_priv(dev);
151
152         return priv->lad_dev->ethtool_ops->set_pauseparam(priv->lad_dev,
153                                                                 pause);
154 }
155
156 static u32
157 kni_get_msglevel(struct net_device *dev)
158 {
159         struct kni_dev *priv = netdev_priv(dev);
160
161         return priv->lad_dev->ethtool_ops->get_msglevel(priv->lad_dev);
162 }
163
164 static void
165 kni_set_msglevel(struct net_device *dev, u32 data)
166 {
167         struct kni_dev *priv = netdev_priv(dev);
168
169         priv->lad_dev->ethtool_ops->set_msglevel(priv->lad_dev, data);
170 }
171
172 static int
173 kni_get_regs_len(struct net_device *dev)
174 {
175         struct kni_dev *priv = netdev_priv(dev);
176
177         return priv->lad_dev->ethtool_ops->get_regs_len(priv->lad_dev);
178 }
179
180 static void
181 kni_get_regs(struct net_device *dev, struct ethtool_regs *regs, void *p)
182 {
183         struct kni_dev *priv = netdev_priv(dev);
184
185         priv->lad_dev->ethtool_ops->get_regs(priv->lad_dev, regs, p);
186 }
187
188 static void
189 kni_get_strings(struct net_device *dev, u32 stringset, u8 *data)
190 {
191         struct kni_dev *priv = netdev_priv(dev);
192
193         priv->lad_dev->ethtool_ops->get_strings(priv->lad_dev, stringset,
194                                                                 data);
195 }
196
197 static int
198 kni_get_sset_count(struct net_device *dev, int sset)
199 {
200         struct kni_dev *priv = netdev_priv(dev);
201
202         return priv->lad_dev->ethtool_ops->get_sset_count(priv->lad_dev, sset);
203 }
204
205 static void
206 kni_get_ethtool_stats(struct net_device *dev, struct ethtool_stats *stats,
207                                                                 u64 *data)
208 {
209         struct kni_dev *priv = netdev_priv(dev);
210
211         priv->lad_dev->ethtool_ops->get_ethtool_stats(priv->lad_dev, stats,
212                                                                 data);
213 }
214
215 struct ethtool_ops kni_ethtool_ops = {
216         .begin                  = kni_check_if_running,
217         .get_drvinfo            = kni_get_drvinfo,
218 #ifndef ETHTOOL_GLINKSETTINGS
219         .get_settings           = kni_get_settings,
220 #endif
221 #ifndef ETHTOOL_SLINKSETTINGS
222         .set_settings           = kni_set_settings,
223 #endif
224         .get_regs_len           = kni_get_regs_len,
225         .get_regs               = kni_get_regs,
226         .get_wol                = kni_get_wol,
227         .set_wol                = kni_set_wol,
228         .nway_reset             = kni_nway_reset,
229         .get_link               = ethtool_op_get_link,
230         .get_eeprom_len         = kni_get_eeprom_len,
231         .get_eeprom             = kni_get_eeprom,
232         .set_eeprom             = kni_set_eeprom,
233         .get_ringparam          = kni_get_ringparam,
234         .set_ringparam          = kni_set_ringparam,
235         .get_pauseparam         = kni_get_pauseparam,
236         .set_pauseparam         = kni_set_pauseparam,
237         .get_msglevel           = kni_get_msglevel,
238         .set_msglevel           = kni_set_msglevel,
239         .get_strings            = kni_get_strings,
240         .get_sset_count         = kni_get_sset_count,
241         .get_ethtool_stats      = kni_get_ethtool_stats,
242 };
243
244 void
245 kni_set_ethtool_ops(struct net_device *netdev)
246 {
247         netdev->ethtool_ops = &kni_ethtool_ops;
248 }