slcan-ethtool.c 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /* Copyright (c) 2022 Amarula Solutions, Dario Binacchi <[email protected]>
  3. *
  4. */
  5. #include <linux/can/dev.h>
  6. #include <linux/ethtool.h>
  7. #include <linux/kernel.h>
  8. #include <linux/netdevice.h>
  9. #include <linux/platform_device.h>
  10. #include "slcan.h"
  11. static const char slcan_priv_flags_strings[][ETH_GSTRING_LEN] = {
  12. #define SLCAN_PRIV_FLAGS_ERR_RST_ON_OPEN BIT(0)
  13. "err-rst-on-open",
  14. };
  15. static void slcan_get_strings(struct net_device *ndev, u32 stringset, u8 *data)
  16. {
  17. switch (stringset) {
  18. case ETH_SS_PRIV_FLAGS:
  19. memcpy(data, slcan_priv_flags_strings,
  20. sizeof(slcan_priv_flags_strings));
  21. }
  22. }
  23. static u32 slcan_get_priv_flags(struct net_device *ndev)
  24. {
  25. u32 flags = 0;
  26. if (slcan_err_rst_on_open(ndev))
  27. flags |= SLCAN_PRIV_FLAGS_ERR_RST_ON_OPEN;
  28. return flags;
  29. }
  30. static int slcan_set_priv_flags(struct net_device *ndev, u32 flags)
  31. {
  32. bool err_rst_op_open = !!(flags & SLCAN_PRIV_FLAGS_ERR_RST_ON_OPEN);
  33. return slcan_enable_err_rst_on_open(ndev, err_rst_op_open);
  34. }
  35. static int slcan_get_sset_count(struct net_device *netdev, int sset)
  36. {
  37. switch (sset) {
  38. case ETH_SS_PRIV_FLAGS:
  39. return ARRAY_SIZE(slcan_priv_flags_strings);
  40. default:
  41. return -EOPNOTSUPP;
  42. }
  43. }
  44. const struct ethtool_ops slcan_ethtool_ops = {
  45. .get_strings = slcan_get_strings,
  46. .get_priv_flags = slcan_get_priv_flags,
  47. .set_priv_flags = slcan_set_priv_flags,
  48. .get_sset_count = slcan_get_sset_count,
  49. .get_ts_info = ethtool_op_get_ts_info,
  50. };