1 /*
2  * NXP Wireless LAN device driver: ethtool
3  *
4  * Copyright 2011-2020 NXP
5  *
6  * This software file (the "File") is distributed by NXP
7  * under the terms of the GNU General Public License Version 2, June 1991
8  * (the "License").  You may use, redistribute and/or modify this File in
9  * accordance with the terms and conditions of the License, a copy of which
10  * is available by writing to the Free Software Foundation, Inc.,
11  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA or on the
12  * worldwide web at http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt.
13  *
14  * THE FILE IS DISTRIBUTED AS-IS, WITHOUT WARRANTY OF ANY KIND, AND THE
15  * IMPLIED WARRANTIES OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE
16  * ARE EXPRESSLY DISCLAIMED.  The License provides additional details about
17  * this warranty disclaimer.
18  */
19 
20 #include "main.h"
21 
22 static void mwifiex_ethtool_get_wol(struct net_device *dev,
23 				    struct ethtool_wolinfo *wol)
24 {
25 	struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
26 	u32 conditions = le32_to_cpu(priv->adapter->hs_cfg.conditions);
27 
28 	wol->supported = WAKE_UCAST|WAKE_MCAST|WAKE_BCAST|WAKE_PHY;
29 
30 	if (conditions == HS_CFG_COND_DEF)
31 		return;
32 
33 	if (conditions & HS_CFG_COND_UNICAST_DATA)
34 		wol->wolopts |= WAKE_UCAST;
35 	if (conditions & HS_CFG_COND_MULTICAST_DATA)
36 		wol->wolopts |= WAKE_MCAST;
37 	if (conditions & HS_CFG_COND_BROADCAST_DATA)
38 		wol->wolopts |= WAKE_BCAST;
39 	if (conditions & HS_CFG_COND_MAC_EVENT)
40 		wol->wolopts |= WAKE_PHY;
41 }
42 
43 static int mwifiex_ethtool_set_wol(struct net_device *dev,
44 				   struct ethtool_wolinfo *wol)
45 {
46 	struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
47 	u32 conditions = 0;
48 
49 	if (wol->wolopts & ~(WAKE_UCAST|WAKE_MCAST|WAKE_BCAST|WAKE_PHY))
50 		return -EOPNOTSUPP;
51 
52 	if (wol->wolopts & WAKE_UCAST)
53 		conditions |= HS_CFG_COND_UNICAST_DATA;
54 	if (wol->wolopts & WAKE_MCAST)
55 		conditions |= HS_CFG_COND_MULTICAST_DATA;
56 	if (wol->wolopts & WAKE_BCAST)
57 		conditions |= HS_CFG_COND_BROADCAST_DATA;
58 	if (wol->wolopts & WAKE_PHY)
59 		conditions |= HS_CFG_COND_MAC_EVENT;
60 	if (wol->wolopts == 0)
61 		conditions |= HS_CFG_COND_DEF;
62 	priv->adapter->hs_cfg.conditions = cpu_to_le32(conditions);
63 
64 	return 0;
65 }
66 
67 const struct ethtool_ops mwifiex_ethtool_ops = {
68 	.get_wol = mwifiex_ethtool_get_wol,
69 	.set_wol = mwifiex_ethtool_set_wol,
70 };
71