1 #include <linux/netdevice.h>
2 #include <linux/ethtool.h>
3 #include <linux/delay.h>
14 static void lbs_ethtool_get_drvinfo(struct net_device
*dev
,
15 struct ethtool_drvinfo
*info
)
17 struct lbs_private
*priv
= dev
->ml_priv
;
19 snprintf(info
->fw_version
, 32, "%u.%u.%u.p%u",
20 priv
->fwrelease
>> 24 & 0xff,
21 priv
->fwrelease
>> 16 & 0xff,
22 priv
->fwrelease
>> 8 & 0xff,
23 priv
->fwrelease
& 0xff);
24 strcpy(info
->driver
, "libertas");
25 strcpy(info
->version
, lbs_driver_version
);
28 /* All 8388 parts have 16KiB EEPROM size at the time of writing.
29 * In case that changes this needs fixing.
31 #define LBS_EEPROM_LEN 16384
33 static int lbs_ethtool_get_eeprom_len(struct net_device
*dev
)
35 return LBS_EEPROM_LEN
;
38 static int lbs_ethtool_get_eeprom(struct net_device
*dev
,
39 struct ethtool_eeprom
*eeprom
, u8
* bytes
)
41 struct lbs_private
*priv
= dev
->ml_priv
;
42 struct cmd_ds_802_11_eeprom_access cmd
;
45 lbs_deb_enter(LBS_DEB_ETHTOOL
);
47 if (eeprom
->offset
+ eeprom
->len
> LBS_EEPROM_LEN
||
48 eeprom
->len
> LBS_EEPROM_READ_LEN
) {
53 cmd
.hdr
.size
= cpu_to_le16(sizeof(struct cmd_ds_802_11_eeprom_access
) -
54 LBS_EEPROM_READ_LEN
+ eeprom
->len
);
55 cmd
.action
= cpu_to_le16(CMD_ACT_GET
);
56 cmd
.offset
= cpu_to_le16(eeprom
->offset
);
57 cmd
.len
= cpu_to_le16(eeprom
->len
);
58 ret
= lbs_cmd_with_response(priv
, CMD_802_11_EEPROM_ACCESS
, &cmd
);
60 memcpy(bytes
, cmd
.value
, eeprom
->len
);
63 lbs_deb_leave_args(LBS_DEB_ETHTOOL
, "ret %d", ret
);
67 static void lbs_ethtool_get_wol(struct net_device
*dev
,
68 struct ethtool_wolinfo
*wol
)
70 struct lbs_private
*priv
= dev
->ml_priv
;
72 if (priv
->wol_criteria
== 0xffffffff) {
73 /* Interface driver didn't configure wake */
74 wol
->supported
= wol
->wolopts
= 0;
78 wol
->supported
= WAKE_UCAST
|WAKE_MCAST
|WAKE_BCAST
|WAKE_PHY
;
80 if (priv
->wol_criteria
& EHS_WAKE_ON_UNICAST_DATA
)
81 wol
->wolopts
|= WAKE_UCAST
;
82 if (priv
->wol_criteria
& EHS_WAKE_ON_MULTICAST_DATA
)
83 wol
->wolopts
|= WAKE_MCAST
;
84 if (priv
->wol_criteria
& EHS_WAKE_ON_BROADCAST_DATA
)
85 wol
->wolopts
|= WAKE_BCAST
;
86 if (priv
->wol_criteria
& EHS_WAKE_ON_MAC_EVENT
)
87 wol
->wolopts
|= WAKE_PHY
;
90 static int lbs_ethtool_set_wol(struct net_device
*dev
,
91 struct ethtool_wolinfo
*wol
)
93 struct lbs_private
*priv
= dev
->ml_priv
;
94 uint32_t criteria
= 0;
96 if (wol
->wolopts
& ~(WAKE_UCAST
|WAKE_MCAST
|WAKE_BCAST
|WAKE_PHY
))
99 if (wol
->wolopts
& WAKE_UCAST
)
100 criteria
|= EHS_WAKE_ON_UNICAST_DATA
;
101 if (wol
->wolopts
& WAKE_MCAST
)
102 criteria
|= EHS_WAKE_ON_MULTICAST_DATA
;
103 if (wol
->wolopts
& WAKE_BCAST
)
104 criteria
|= EHS_WAKE_ON_BROADCAST_DATA
;
105 if (wol
->wolopts
& WAKE_PHY
)
106 criteria
|= EHS_WAKE_ON_MAC_EVENT
;
107 if (wol
->wolopts
== 0)
108 criteria
|= EHS_REMOVE_WAKEUP
;
110 return lbs_host_sleep_cfg(priv
, criteria
, (struct wol_config
*)NULL
);
113 const struct ethtool_ops lbs_ethtool_ops
= {
114 .get_drvinfo
= lbs_ethtool_get_drvinfo
,
115 .get_eeprom
= lbs_ethtool_get_eeprom
,
116 .get_eeprom_len
= lbs_ethtool_get_eeprom_len
,
117 #ifdef CONFIG_LIBERTAS_MESH
118 .get_sset_count
= lbs_mesh_ethtool_get_sset_count
,
119 .get_ethtool_stats
= lbs_mesh_ethtool_get_stats
,
120 .get_strings
= lbs_mesh_ethtool_get_strings
,
122 .get_wol
= lbs_ethtool_get_wol
,
123 .set_wol
= lbs_ethtool_set_wol
,