• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Marvell Wireless LAN device driver: ethtool
3  *
4  * Copyright (C) 2013-2014, Marvell International Ltd.
5  *
6  * This software file (the "File") is distributed by Marvell International
7  * Ltd. 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 
mwifiex_ethtool_get_wol(struct net_device * dev,struct ethtool_wolinfo * wol)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 
mwifiex_ethtool_set_wol(struct net_device * dev,struct ethtool_wolinfo * wol)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 static int
mwifiex_get_dump_flag(struct net_device * dev,struct ethtool_dump * dump)68 mwifiex_get_dump_flag(struct net_device *dev, struct ethtool_dump *dump)
69 {
70 	struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
71 	struct mwifiex_adapter *adapter = priv->adapter;
72 	struct memory_type_mapping *entry;
73 
74 	if (!adapter->if_ops.fw_dump)
75 		return -ENOTSUPP;
76 
77 	dump->flag = adapter->curr_mem_idx;
78 	dump->version = 1;
79 	if (adapter->curr_mem_idx != MWIFIEX_FW_DUMP_IDX) {
80 		entry = &adapter->mem_type_mapping_tbl[adapter->curr_mem_idx];
81 		dump->len = entry->mem_size;
82 	} else {
83 		dump->len = 0;
84 	}
85 
86 	return 0;
87 }
88 
89 static int
mwifiex_get_dump_data(struct net_device * dev,struct ethtool_dump * dump,void * buffer)90 mwifiex_get_dump_data(struct net_device *dev, struct ethtool_dump *dump,
91 		      void *buffer)
92 {
93 	u8 *p = buffer;
94 	struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
95 	struct mwifiex_adapter *adapter = priv->adapter;
96 	struct memory_type_mapping *entry;
97 
98 	if (!adapter->if_ops.fw_dump)
99 		return -ENOTSUPP;
100 
101 	if (adapter->curr_mem_idx == MWIFIEX_FW_DUMP_IDX) {
102 		dev_err(adapter->dev, "firmware dump in progress!!\n");
103 		return -EBUSY;
104 	}
105 
106 	entry = &adapter->mem_type_mapping_tbl[adapter->curr_mem_idx];
107 
108 	if (!entry->mem_ptr)
109 		return -EFAULT;
110 
111 	memcpy(p, entry->mem_ptr, entry->mem_size);
112 
113 	entry->mem_size = 0;
114 	vfree(entry->mem_ptr);
115 	entry->mem_ptr = NULL;
116 
117 	return 0;
118 }
119 
mwifiex_set_dump(struct net_device * dev,struct ethtool_dump * val)120 static int mwifiex_set_dump(struct net_device *dev, struct ethtool_dump *val)
121 {
122 	struct mwifiex_private *priv = mwifiex_netdev_get_priv(dev);
123 	struct mwifiex_adapter *adapter = priv->adapter;
124 
125 	if (!adapter->if_ops.fw_dump)
126 		return -ENOTSUPP;
127 
128 	if (adapter->curr_mem_idx == MWIFIEX_FW_DUMP_IDX) {
129 		dev_err(adapter->dev, "firmware dump in progress!!\n");
130 		return -EBUSY;
131 	}
132 
133 	if (val->flag == MWIFIEX_FW_DUMP_IDX) {
134 		adapter->curr_mem_idx = val->flag;
135 		adapter->if_ops.fw_dump(adapter);
136 		return 0;
137 	}
138 
139 	if (val->flag < 0 || val->flag >= adapter->num_mem_types)
140 		return -EINVAL;
141 
142 	adapter->curr_mem_idx = val->flag;
143 
144 	return 0;
145 }
146 
147 const struct ethtool_ops mwifiex_ethtool_ops = {
148 	.get_wol = mwifiex_ethtool_get_wol,
149 	.set_wol = mwifiex_ethtool_set_wol,
150 	.get_dump_flag = mwifiex_get_dump_flag,
151 	.get_dump_data = mwifiex_get_dump_data,
152 	.set_dump = mwifiex_set_dump,
153 };
154