ethtool.c 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  1. #include <linux/netdevice.h>
  2. #include <linux/ethtool.h>
  3. #include <linux/delay.h>
  4. #include "host.h"
  5. #include "decl.h"
  6. #include "defs.h"
  7. #include "dev.h"
  8. #include "wext.h"
  9. #include "cmd.h"
  10. static const char * mesh_stat_strings[]= {
  11. "drop_duplicate_bcast",
  12. "drop_ttl_zero",
  13. "drop_no_fwd_route",
  14. "drop_no_buffers",
  15. "fwded_unicast_cnt",
  16. "fwded_bcast_cnt",
  17. "drop_blind_table",
  18. "tx_failed_cnt"
  19. };
  20. static void lbs_ethtool_get_drvinfo(struct net_device *dev,
  21. struct ethtool_drvinfo *info)
  22. {
  23. struct lbs_private *priv = (struct lbs_private *) dev->priv;
  24. snprintf(info->fw_version, 32, "%u.%u.%u.p%u",
  25. priv->fwrelease >> 24 & 0xff,
  26. priv->fwrelease >> 16 & 0xff,
  27. priv->fwrelease >> 8 & 0xff,
  28. priv->fwrelease & 0xff);
  29. strcpy(info->driver, "libertas");
  30. strcpy(info->version, lbs_driver_version);
  31. }
  32. /* All 8388 parts have 16KiB EEPROM size at the time of writing.
  33. * In case that changes this needs fixing.
  34. */
  35. #define LBS_EEPROM_LEN 16384
  36. static int lbs_ethtool_get_eeprom_len(struct net_device *dev)
  37. {
  38. return LBS_EEPROM_LEN;
  39. }
  40. static int lbs_ethtool_get_eeprom(struct net_device *dev,
  41. struct ethtool_eeprom *eeprom, u8 * bytes)
  42. {
  43. struct lbs_private *priv = (struct lbs_private *) dev->priv;
  44. struct cmd_ds_802_11_eeprom_access cmd;
  45. int ret;
  46. lbs_deb_enter(LBS_DEB_ETHTOOL);
  47. if (eeprom->offset + eeprom->len > LBS_EEPROM_LEN ||
  48. eeprom->len > LBS_EEPROM_READ_LEN) {
  49. ret = -EINVAL;
  50. goto out;
  51. }
  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. out:
  61. lbs_deb_leave_args(LBS_DEB_ETHTOOL, "ret %d", ret);
  62. return ret;
  63. }
  64. static void lbs_ethtool_get_stats(struct net_device * dev,
  65. struct ethtool_stats * stats, u64 * data)
  66. {
  67. struct lbs_private *priv = dev->priv;
  68. struct cmd_ds_mesh_access mesh_access;
  69. int ret;
  70. lbs_deb_enter(LBS_DEB_ETHTOOL);
  71. /* Get Mesh Statistics */
  72. ret = lbs_prepare_and_send_command(priv,
  73. CMD_MESH_ACCESS, CMD_ACT_MESH_GET_STATS,
  74. CMD_OPTION_WAITFORRSP, 0, &mesh_access);
  75. if (ret)
  76. return;
  77. priv->mstats.fwd_drop_rbt = le32_to_cpu(mesh_access.data[0]);
  78. priv->mstats.fwd_drop_ttl = le32_to_cpu(mesh_access.data[1]);
  79. priv->mstats.fwd_drop_noroute = le32_to_cpu(mesh_access.data[2]);
  80. priv->mstats.fwd_drop_nobuf = le32_to_cpu(mesh_access.data[3]);
  81. priv->mstats.fwd_unicast_cnt = le32_to_cpu(mesh_access.data[4]);
  82. priv->mstats.fwd_bcast_cnt = le32_to_cpu(mesh_access.data[5]);
  83. priv->mstats.drop_blind = le32_to_cpu(mesh_access.data[6]);
  84. priv->mstats.tx_failed_cnt = le32_to_cpu(mesh_access.data[7]);
  85. data[0] = priv->mstats.fwd_drop_rbt;
  86. data[1] = priv->mstats.fwd_drop_ttl;
  87. data[2] = priv->mstats.fwd_drop_noroute;
  88. data[3] = priv->mstats.fwd_drop_nobuf;
  89. data[4] = priv->mstats.fwd_unicast_cnt;
  90. data[5] = priv->mstats.fwd_bcast_cnt;
  91. data[6] = priv->mstats.drop_blind;
  92. data[7] = priv->mstats.tx_failed_cnt;
  93. lbs_deb_enter(LBS_DEB_ETHTOOL);
  94. }
  95. static int lbs_ethtool_get_sset_count(struct net_device * dev, int sset)
  96. {
  97. switch (sset) {
  98. case ETH_SS_STATS:
  99. return MESH_STATS_NUM;
  100. default:
  101. return -EOPNOTSUPP;
  102. }
  103. }
  104. static void lbs_ethtool_get_strings(struct net_device *dev,
  105. u32 stringset,
  106. u8 * s)
  107. {
  108. int i;
  109. lbs_deb_enter(LBS_DEB_ETHTOOL);
  110. switch (stringset) {
  111. case ETH_SS_STATS:
  112. for (i=0; i < MESH_STATS_NUM; i++) {
  113. memcpy(s + i * ETH_GSTRING_LEN,
  114. mesh_stat_strings[i],
  115. ETH_GSTRING_LEN);
  116. }
  117. break;
  118. }
  119. lbs_deb_enter(LBS_DEB_ETHTOOL);
  120. }
  121. static void lbs_ethtool_get_wol(struct net_device *dev,
  122. struct ethtool_wolinfo *wol)
  123. {
  124. struct lbs_private *priv = dev->priv;
  125. if (priv->wol_criteria == 0xffffffff) {
  126. /* Interface driver didn't configure wake */
  127. wol->supported = wol->wolopts = 0;
  128. return;
  129. }
  130. wol->supported = WAKE_UCAST|WAKE_MCAST|WAKE_BCAST|WAKE_PHY;
  131. if (priv->wol_criteria & EHS_WAKE_ON_UNICAST_DATA)
  132. wol->wolopts |= WAKE_UCAST;
  133. if (priv->wol_criteria & EHS_WAKE_ON_MULTICAST_DATA)
  134. wol->wolopts |= WAKE_MCAST;
  135. if (priv->wol_criteria & EHS_WAKE_ON_BROADCAST_DATA)
  136. wol->wolopts |= WAKE_BCAST;
  137. if (priv->wol_criteria & EHS_WAKE_ON_MAC_EVENT)
  138. wol->wolopts |= WAKE_PHY;
  139. }
  140. static int lbs_ethtool_set_wol(struct net_device *dev,
  141. struct ethtool_wolinfo *wol)
  142. {
  143. struct lbs_private *priv = dev->priv;
  144. uint32_t criteria = 0;
  145. if (priv->wol_criteria == 0xffffffff && wol->wolopts)
  146. return -EOPNOTSUPP;
  147. if (wol->wolopts & ~(WAKE_UCAST|WAKE_MCAST|WAKE_BCAST|WAKE_PHY))
  148. return -EOPNOTSUPP;
  149. if (wol->wolopts & WAKE_UCAST) criteria |= EHS_WAKE_ON_UNICAST_DATA;
  150. if (wol->wolopts & WAKE_MCAST) criteria |= EHS_WAKE_ON_MULTICAST_DATA;
  151. if (wol->wolopts & WAKE_BCAST) criteria |= EHS_WAKE_ON_BROADCAST_DATA;
  152. if (wol->wolopts & WAKE_PHY) criteria |= EHS_WAKE_ON_MAC_EVENT;
  153. return lbs_host_sleep_cfg(priv, criteria);
  154. }
  155. struct ethtool_ops lbs_ethtool_ops = {
  156. .get_drvinfo = lbs_ethtool_get_drvinfo,
  157. .get_eeprom = lbs_ethtool_get_eeprom,
  158. .get_eeprom_len = lbs_ethtool_get_eeprom_len,
  159. .get_sset_count = lbs_ethtool_get_sset_count,
  160. .get_ethtool_stats = lbs_ethtool_get_stats,
  161. .get_strings = lbs_ethtool_get_strings,
  162. .get_wol = lbs_ethtool_get_wol,
  163. .set_wol = lbs_ethtool_set_wol,
  164. };