18c2ecf20Sopenharmony_ci/*
28c2ecf20Sopenharmony_ci * NXP Wireless LAN device driver: ethtool
38c2ecf20Sopenharmony_ci *
48c2ecf20Sopenharmony_ci * Copyright 2011-2020 NXP
58c2ecf20Sopenharmony_ci *
68c2ecf20Sopenharmony_ci * This software file (the "File") is distributed by NXP
78c2ecf20Sopenharmony_ci * under the terms of the GNU General Public License Version 2, June 1991
88c2ecf20Sopenharmony_ci * (the "License").  You may use, redistribute and/or modify this File in
98c2ecf20Sopenharmony_ci * accordance with the terms and conditions of the License, a copy of which
108c2ecf20Sopenharmony_ci * is available by writing to the Free Software Foundation, Inc.,
118c2ecf20Sopenharmony_ci * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA or on the
128c2ecf20Sopenharmony_ci * worldwide web at http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt.
138c2ecf20Sopenharmony_ci *
148c2ecf20Sopenharmony_ci * THE FILE IS DISTRIBUTED AS-IS, WITHOUT WARRANTY OF ANY KIND, AND THE
158c2ecf20Sopenharmony_ci * IMPLIED WARRANTIES OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE
168c2ecf20Sopenharmony_ci * ARE EXPRESSLY DISCLAIMED.  The License provides additional details about
178c2ecf20Sopenharmony_ci * this warranty disclaimer.
188c2ecf20Sopenharmony_ci */
198c2ecf20Sopenharmony_ci
208c2ecf20Sopenharmony_ci#include "main.h"
218c2ecf20Sopenharmony_ci
228c2ecf20Sopenharmony_cistatic void mwifiex_ethtool_get_wol(struct net_device *dev,
238c2ecf20Sopenharmony_ci				    struct ethtool_wolinfo *wol)
248c2ecf20Sopenharmony_ci{
258c2ecf20Sopenharmony_ci	struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
268c2ecf20Sopenharmony_ci	u32 conditions = le32_to_cpu(priv->adapter->hs_cfg.conditions);
278c2ecf20Sopenharmony_ci
288c2ecf20Sopenharmony_ci	wol->supported = WAKE_UCAST|WAKE_MCAST|WAKE_BCAST|WAKE_PHY;
298c2ecf20Sopenharmony_ci
308c2ecf20Sopenharmony_ci	if (conditions == HS_CFG_COND_DEF)
318c2ecf20Sopenharmony_ci		return;
328c2ecf20Sopenharmony_ci
338c2ecf20Sopenharmony_ci	if (conditions & HS_CFG_COND_UNICAST_DATA)
348c2ecf20Sopenharmony_ci		wol->wolopts |= WAKE_UCAST;
358c2ecf20Sopenharmony_ci	if (conditions & HS_CFG_COND_MULTICAST_DATA)
368c2ecf20Sopenharmony_ci		wol->wolopts |= WAKE_MCAST;
378c2ecf20Sopenharmony_ci	if (conditions & HS_CFG_COND_BROADCAST_DATA)
388c2ecf20Sopenharmony_ci		wol->wolopts |= WAKE_BCAST;
398c2ecf20Sopenharmony_ci	if (conditions & HS_CFG_COND_MAC_EVENT)
408c2ecf20Sopenharmony_ci		wol->wolopts |= WAKE_PHY;
418c2ecf20Sopenharmony_ci}
428c2ecf20Sopenharmony_ci
438c2ecf20Sopenharmony_cistatic int mwifiex_ethtool_set_wol(struct net_device *dev,
448c2ecf20Sopenharmony_ci				   struct ethtool_wolinfo *wol)
458c2ecf20Sopenharmony_ci{
468c2ecf20Sopenharmony_ci	struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
478c2ecf20Sopenharmony_ci	u32 conditions = 0;
488c2ecf20Sopenharmony_ci
498c2ecf20Sopenharmony_ci	if (wol->wolopts & ~(WAKE_UCAST|WAKE_MCAST|WAKE_BCAST|WAKE_PHY))
508c2ecf20Sopenharmony_ci		return -EOPNOTSUPP;
518c2ecf20Sopenharmony_ci
528c2ecf20Sopenharmony_ci	if (wol->wolopts & WAKE_UCAST)
538c2ecf20Sopenharmony_ci		conditions |= HS_CFG_COND_UNICAST_DATA;
548c2ecf20Sopenharmony_ci	if (wol->wolopts & WAKE_MCAST)
558c2ecf20Sopenharmony_ci		conditions |= HS_CFG_COND_MULTICAST_DATA;
568c2ecf20Sopenharmony_ci	if (wol->wolopts & WAKE_BCAST)
578c2ecf20Sopenharmony_ci		conditions |= HS_CFG_COND_BROADCAST_DATA;
588c2ecf20Sopenharmony_ci	if (wol->wolopts & WAKE_PHY)
598c2ecf20Sopenharmony_ci		conditions |= HS_CFG_COND_MAC_EVENT;
608c2ecf20Sopenharmony_ci	if (wol->wolopts == 0)
618c2ecf20Sopenharmony_ci		conditions |= HS_CFG_COND_DEF;
628c2ecf20Sopenharmony_ci	priv->adapter->hs_cfg.conditions = cpu_to_le32(conditions);
638c2ecf20Sopenharmony_ci
648c2ecf20Sopenharmony_ci	return 0;
658c2ecf20Sopenharmony_ci}
668c2ecf20Sopenharmony_ci
678c2ecf20Sopenharmony_ciconst struct ethtool_ops mwifiex_ethtool_ops = {
688c2ecf20Sopenharmony_ci	.get_wol = mwifiex_ethtool_get_wol,
698c2ecf20Sopenharmony_ci	.set_wol = mwifiex_ethtool_set_wol,
708c2ecf20Sopenharmony_ci};
71