Merge branch 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/jikos/hid
[deliverable/linux.git] / drivers / net / wireless / libertas / ethtool.c
CommitLineData
a6b7a407 1#include <linux/hardirq.h>
876c9d3a
MT
2#include <linux/netdevice.h>
3#include <linux/ethtool.h>
4#include <linux/delay.h>
5
876c9d3a 6#include "decl.h"
506e9025 7#include "cmd.h"
49fee692 8#include "mesh.h"
506e9025 9
876c9d3a 10
10078321 11static void lbs_ethtool_get_drvinfo(struct net_device *dev,
876c9d3a
MT
12 struct ethtool_drvinfo *info)
13{
ab65f649 14 struct lbs_private *priv = dev->ml_priv;
876c9d3a 15
1f80c230
RJ
16 snprintf(info->fw_version, sizeof(info->fw_version),
17 "%u.%u.%u.p%u",
fb14a7e0
HS
18 priv->fwrelease >> 24 & 0xff,
19 priv->fwrelease >> 16 & 0xff,
20 priv->fwrelease >> 8 & 0xff,
21 priv->fwrelease & 0xff);
1f80c230
RJ
22 strlcpy(info->driver, "libertas", sizeof(info->driver));
23 strlcpy(info->version, lbs_driver_version, sizeof(info->version));
876c9d3a
MT
24}
25
8973a6e7
RD
26/*
27 * All 8388 parts have 16KiB EEPROM size at the time of writing.
876c9d3a
MT
28 * In case that changes this needs fixing.
29 */
10078321 30#define LBS_EEPROM_LEN 16384
876c9d3a 31
10078321 32static int lbs_ethtool_get_eeprom_len(struct net_device *dev)
876c9d3a 33{
10078321 34 return LBS_EEPROM_LEN;
876c9d3a
MT
35}
36
10078321 37static int lbs_ethtool_get_eeprom(struct net_device *dev,
876c9d3a
MT
38 struct ethtool_eeprom *eeprom, u8 * bytes)
39{
ab65f649 40 struct lbs_private *priv = dev->ml_priv;
7460f5a6 41 struct cmd_ds_802_11_eeprom_access cmd;
876c9d3a
MT
42 int ret;
43
7460f5a6 44 lbs_deb_enter(LBS_DEB_ETHTOOL);
876c9d3a 45
7460f5a6
HS
46 if (eeprom->offset + eeprom->len > LBS_EEPROM_LEN ||
47 eeprom->len > LBS_EEPROM_READ_LEN) {
48 ret = -EINVAL;
49 goto out;
876c9d3a
MT
50 }
51
7460f5a6
HS
52 cmd.hdr.size = cpu_to_le16(sizeof(struct cmd_ds_802_11_eeprom_access) -
53 LBS_EEPROM_READ_LEN + eeprom->len);
54 cmd.action = cpu_to_le16(CMD_ACT_GET);
55 cmd.offset = cpu_to_le16(eeprom->offset);
56 cmd.len = cpu_to_le16(eeprom->len);
57 ret = lbs_cmd_with_response(priv, CMD_802_11_EEPROM_ACCESS, &cmd);
58 if (!ret)
59 memcpy(bytes, cmd.value, eeprom->len);
60
61out:
62 lbs_deb_leave_args(LBS_DEB_ETHTOOL, "ret %d", ret);
9012b28a 63 return ret;
876c9d3a
MT
64}
65
506e9025
DW
66static void lbs_ethtool_get_wol(struct net_device *dev,
67 struct ethtool_wolinfo *wol)
68{
ab65f649 69 struct lbs_private *priv = dev->ml_priv;
506e9025 70
506e9025
DW
71 wol->supported = WAKE_UCAST|WAKE_MCAST|WAKE_BCAST|WAKE_PHY;
72
84efa0e7
SS
73 if (priv->wol_criteria == EHS_REMOVE_WAKEUP)
74 return;
75
506e9025
DW
76 if (priv->wol_criteria & EHS_WAKE_ON_UNICAST_DATA)
77 wol->wolopts |= WAKE_UCAST;
78 if (priv->wol_criteria & EHS_WAKE_ON_MULTICAST_DATA)
79 wol->wolopts |= WAKE_MCAST;
80 if (priv->wol_criteria & EHS_WAKE_ON_BROADCAST_DATA)
81 wol->wolopts |= WAKE_BCAST;
82 if (priv->wol_criteria & EHS_WAKE_ON_MAC_EVENT)
83 wol->wolopts |= WAKE_PHY;
84}
85
86static int lbs_ethtool_set_wol(struct net_device *dev,
87 struct ethtool_wolinfo *wol)
88{
ab65f649 89 struct lbs_private *priv = dev->ml_priv;
506e9025 90
506e9025
DW
91 if (wol->wolopts & ~(WAKE_UCAST|WAKE_MCAST|WAKE_BCAST|WAKE_PHY))
92 return -EOPNOTSUPP;
93
66fceb69 94 priv->wol_criteria = 0;
866d4700 95 if (wol->wolopts & WAKE_UCAST)
66fceb69 96 priv->wol_criteria |= EHS_WAKE_ON_UNICAST_DATA;
866d4700 97 if (wol->wolopts & WAKE_MCAST)
66fceb69 98 priv->wol_criteria |= EHS_WAKE_ON_MULTICAST_DATA;
866d4700 99 if (wol->wolopts & WAKE_BCAST)
66fceb69 100 priv->wol_criteria |= EHS_WAKE_ON_BROADCAST_DATA;
866d4700 101 if (wol->wolopts & WAKE_PHY)
66fceb69 102 priv->wol_criteria |= EHS_WAKE_ON_MAC_EVENT;
c3b866ad 103 if (wol->wolopts == 0)
66fceb69
AK
104 priv->wol_criteria |= EHS_REMOVE_WAKEUP;
105 return 0;
506e9025
DW
106}
107
0fc0b732 108const struct ethtool_ops lbs_ethtool_ops = {
10078321
HS
109 .get_drvinfo = lbs_ethtool_get_drvinfo,
110 .get_eeprom = lbs_ethtool_get_eeprom,
111 .get_eeprom_len = lbs_ethtool_get_eeprom_len,
4143a23d 112#ifdef CONFIG_LIBERTAS_MESH
c7fe64cf
HS
113 .get_sset_count = lbs_mesh_ethtool_get_sset_count,
114 .get_ethtool_stats = lbs_mesh_ethtool_get_stats,
115 .get_strings = lbs_mesh_ethtool_get_strings,
4143a23d 116#endif
506e9025
DW
117 .get_wol = lbs_ethtool_get_wol,
118 .set_wol = lbs_ethtool_set_wol,
876c9d3a
MT
119};
120
This page took 0.751931 seconds and 5 git commands to generate.