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