1 #include <linux/netdevice.h>
2 #include <linux/ethtool.h>
3 #include <linux/delay.h>
4
5 #include "decl.h"
6 #include "cmd.h"
7
8
lbs_ethtool_get_drvinfo(struct net_device * dev,struct ethtool_drvinfo * info)9 static void lbs_ethtool_get_drvinfo(struct net_device *dev,
10 struct ethtool_drvinfo *info)
11 {
12 struct lbs_private *priv = dev->ml_priv;
13
14 snprintf(info->fw_version, 32, "%u.%u.%u.p%u",
15 priv->fwrelease >> 24 & 0xff,
16 priv->fwrelease >> 16 & 0xff,
17 priv->fwrelease >> 8 & 0xff,
18 priv->fwrelease & 0xff);
19 strcpy(info->driver, "libertas");
20 strcpy(info->version, lbs_driver_version);
21 }
22
23 /* All 8388 parts have 16KiB EEPROM size at the time of writing.
24 * In case that changes this needs fixing.
25 */
26 #define LBS_EEPROM_LEN 16384
27
lbs_ethtool_get_eeprom_len(struct net_device * dev)28 static int lbs_ethtool_get_eeprom_len(struct net_device *dev)
29 {
30 return LBS_EEPROM_LEN;
31 }
32
lbs_ethtool_get_eeprom(struct net_device * dev,struct ethtool_eeprom * eeprom,u8 * bytes)33 static int lbs_ethtool_get_eeprom(struct net_device *dev,
34 struct ethtool_eeprom *eeprom, u8 * bytes)
35 {
36 struct lbs_private *priv = dev->ml_priv;
37 struct cmd_ds_802_11_eeprom_access cmd;
38 int ret;
39
40 lbs_deb_enter(LBS_DEB_ETHTOOL);
41
42 if (eeprom->offset + eeprom->len > LBS_EEPROM_LEN ||
43 eeprom->len > LBS_EEPROM_READ_LEN) {
44 ret = -EINVAL;
45 goto out;
46 }
47
48 cmd.hdr.size = cpu_to_le16(sizeof(struct cmd_ds_802_11_eeprom_access) -
49 LBS_EEPROM_READ_LEN + eeprom->len);
50 cmd.action = cpu_to_le16(CMD_ACT_GET);
51 cmd.offset = cpu_to_le16(eeprom->offset);
52 cmd.len = cpu_to_le16(eeprom->len);
53 ret = lbs_cmd_with_response(priv, CMD_802_11_EEPROM_ACCESS, &cmd);
54 if (!ret)
55 memcpy(bytes, cmd.value, eeprom->len);
56
57 out:
58 lbs_deb_leave_args(LBS_DEB_ETHTOOL, "ret %d", ret);
59 return ret;
60 }
61
lbs_ethtool_get_wol(struct net_device * dev,struct ethtool_wolinfo * wol)62 static void lbs_ethtool_get_wol(struct net_device *dev,
63 struct ethtool_wolinfo *wol)
64 {
65 struct lbs_private *priv = dev->ml_priv;
66
67 wol->supported = WAKE_UCAST|WAKE_MCAST|WAKE_BCAST|WAKE_PHY;
68
69 if (priv->wol_criteria == EHS_REMOVE_WAKEUP)
70 return;
71
72 if (priv->wol_criteria & EHS_WAKE_ON_UNICAST_DATA)
73 wol->wolopts |= WAKE_UCAST;
74 if (priv->wol_criteria & EHS_WAKE_ON_MULTICAST_DATA)
75 wol->wolopts |= WAKE_MCAST;
76 if (priv->wol_criteria & EHS_WAKE_ON_BROADCAST_DATA)
77 wol->wolopts |= WAKE_BCAST;
78 if (priv->wol_criteria & EHS_WAKE_ON_MAC_EVENT)
79 wol->wolopts |= WAKE_PHY;
80 }
81
lbs_ethtool_set_wol(struct net_device * dev,struct ethtool_wolinfo * wol)82 static int lbs_ethtool_set_wol(struct net_device *dev,
83 struct ethtool_wolinfo *wol)
84 {
85 struct lbs_private *priv = dev->ml_priv;
86
87 if (wol->wolopts & ~(WAKE_UCAST|WAKE_MCAST|WAKE_BCAST|WAKE_PHY))
88 return -EOPNOTSUPP;
89
90 priv->wol_criteria = 0;
91 if (wol->wolopts & WAKE_UCAST)
92 priv->wol_criteria |= EHS_WAKE_ON_UNICAST_DATA;
93 if (wol->wolopts & WAKE_MCAST)
94 priv->wol_criteria |= EHS_WAKE_ON_MULTICAST_DATA;
95 if (wol->wolopts & WAKE_BCAST)
96 priv->wol_criteria |= EHS_WAKE_ON_BROADCAST_DATA;
97 if (wol->wolopts & WAKE_PHY)
98 priv->wol_criteria |= EHS_WAKE_ON_MAC_EVENT;
99 if (wol->wolopts == 0)
100 priv->wol_criteria |= EHS_REMOVE_WAKEUP;
101 return 0;
102 }
103
104 const struct ethtool_ops lbs_ethtool_ops = {
105 .get_drvinfo = lbs_ethtool_get_drvinfo,
106 .get_eeprom = lbs_ethtool_get_eeprom,
107 .get_eeprom_len = lbs_ethtool_get_eeprom_len,
108 #ifdef CONFIG_LIBERTAS_MESH
109 .get_sset_count = lbs_mesh_ethtool_get_sset_count,
110 .get_ethtool_stats = lbs_mesh_ethtool_get_stats,
111 .get_strings = lbs_mesh_ethtool_get_strings,
112 #endif
113 .get_wol = lbs_ethtool_get_wol,
114 .set_wol = lbs_ethtool_set_wol,
115 };
116
117