162306a36Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0-only
262306a36Sopenharmony_ci/*
362306a36Sopenharmony_ci * NXP Wireless LAN device driver: ethtool
462306a36Sopenharmony_ci *
562306a36Sopenharmony_ci * Copyright 2011-2020 NXP
662306a36Sopenharmony_ci */
762306a36Sopenharmony_ci
862306a36Sopenharmony_ci#include "main.h"
962306a36Sopenharmony_ci
1062306a36Sopenharmony_cistatic void mwifiex_ethtool_get_wol(struct net_device *dev,
1162306a36Sopenharmony_ci				    struct ethtool_wolinfo *wol)
1262306a36Sopenharmony_ci{
1362306a36Sopenharmony_ci	struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
1462306a36Sopenharmony_ci	u32 conditions = le32_to_cpu(priv->adapter->hs_cfg.conditions);
1562306a36Sopenharmony_ci
1662306a36Sopenharmony_ci	wol->supported = WAKE_UCAST|WAKE_MCAST|WAKE_BCAST|WAKE_PHY;
1762306a36Sopenharmony_ci
1862306a36Sopenharmony_ci	if (conditions == HS_CFG_COND_DEF)
1962306a36Sopenharmony_ci		return;
2062306a36Sopenharmony_ci
2162306a36Sopenharmony_ci	if (conditions & HS_CFG_COND_UNICAST_DATA)
2262306a36Sopenharmony_ci		wol->wolopts |= WAKE_UCAST;
2362306a36Sopenharmony_ci	if (conditions & HS_CFG_COND_MULTICAST_DATA)
2462306a36Sopenharmony_ci		wol->wolopts |= WAKE_MCAST;
2562306a36Sopenharmony_ci	if (conditions & HS_CFG_COND_BROADCAST_DATA)
2662306a36Sopenharmony_ci		wol->wolopts |= WAKE_BCAST;
2762306a36Sopenharmony_ci	if (conditions & HS_CFG_COND_MAC_EVENT)
2862306a36Sopenharmony_ci		wol->wolopts |= WAKE_PHY;
2962306a36Sopenharmony_ci}
3062306a36Sopenharmony_ci
3162306a36Sopenharmony_cistatic int mwifiex_ethtool_set_wol(struct net_device *dev,
3262306a36Sopenharmony_ci				   struct ethtool_wolinfo *wol)
3362306a36Sopenharmony_ci{
3462306a36Sopenharmony_ci	struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
3562306a36Sopenharmony_ci	u32 conditions = 0;
3662306a36Sopenharmony_ci
3762306a36Sopenharmony_ci	if (wol->wolopts & ~(WAKE_UCAST|WAKE_MCAST|WAKE_BCAST|WAKE_PHY))
3862306a36Sopenharmony_ci		return -EOPNOTSUPP;
3962306a36Sopenharmony_ci
4062306a36Sopenharmony_ci	if (wol->wolopts & WAKE_UCAST)
4162306a36Sopenharmony_ci		conditions |= HS_CFG_COND_UNICAST_DATA;
4262306a36Sopenharmony_ci	if (wol->wolopts & WAKE_MCAST)
4362306a36Sopenharmony_ci		conditions |= HS_CFG_COND_MULTICAST_DATA;
4462306a36Sopenharmony_ci	if (wol->wolopts & WAKE_BCAST)
4562306a36Sopenharmony_ci		conditions |= HS_CFG_COND_BROADCAST_DATA;
4662306a36Sopenharmony_ci	if (wol->wolopts & WAKE_PHY)
4762306a36Sopenharmony_ci		conditions |= HS_CFG_COND_MAC_EVENT;
4862306a36Sopenharmony_ci	if (wol->wolopts == 0)
4962306a36Sopenharmony_ci		conditions |= HS_CFG_COND_DEF;
5062306a36Sopenharmony_ci	priv->adapter->hs_cfg.conditions = cpu_to_le32(conditions);
5162306a36Sopenharmony_ci
5262306a36Sopenharmony_ci	return 0;
5362306a36Sopenharmony_ci}
5462306a36Sopenharmony_ci
5562306a36Sopenharmony_ciconst struct ethtool_ops mwifiex_ethtool_ops = {
5662306a36Sopenharmony_ci	.get_wol = mwifiex_ethtool_get_wol,
5762306a36Sopenharmony_ci	.set_wol = mwifiex_ethtool_set_wol,
5862306a36Sopenharmony_ci};
59