2
0

make_ethtool_modes_h.sh 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. #!/bin/sh
  2. CC="$1"
  3. [ -n "$TARGET_CC_NOCACHE" ] && CC="$TARGET_CC_NOCACHE"
  4. cat <<EOF
  5. #include <linux/ethtool.h>
  6. #define ETHTOOL_MODE_FULL(_speed, _mode) { \\
  7. .speed = (_speed), \\
  8. .bit_half = -1, \\
  9. .bit_full = ETHTOOL_LINK_MODE_ ## _speed ## base ## _mode ## _Full_BIT, \\
  10. .name = #_speed "base" #_mode, \\
  11. }
  12. #define ETHTOOL_MODE_HALF(_speed, _mode) { \\
  13. .speed = (_speed), \\
  14. .bit_half = ETHTOOL_LINK_MODE_ ## _speed ## base ## _mode ## _Half_BIT, \\
  15. .bit_full = -1, \\
  16. .name = #_speed "base" #_mode, \\
  17. }
  18. #define ETHTOOL_MODE_BOTH(_speed, _mode) { \\
  19. .speed = (_speed), \\
  20. .bit_half = ETHTOOL_LINK_MODE_ ## _speed ## base ## _mode ## _Half_BIT, \\
  21. .bit_full = ETHTOOL_LINK_MODE_ ## _speed ## base ## _mode ## _Full_BIT, \\
  22. .name = #_speed "base" #_mode, \\
  23. }
  24. static const struct {
  25. unsigned int speed;
  26. int bit_half;
  27. int bit_full;
  28. const char *name;
  29. } ethtool_modes[] = {
  30. EOF
  31. echo "#include <linux/ethtool.h>" | "$CC" -E - | \
  32. grep "ETHTOOL_LINK_MODE_[0-9]*base[A-Za-z0-9]*_...._BIT.*" | \
  33. sed -r 's/.*ETHTOOL_LINK_MODE_([0-9]*)base([A-Za-z0-9]*)_(....)_BIT.*/\1 \2 \3/' | \
  34. sort -u | LC_ALL=C sort -r -g | ( gothalf=0 ; while read -r speed mode duplex; do
  35. if [ "$duplex" = "Half" ]; then
  36. if [ "$gothalf" = "1" ]; then
  37. printf "%s" "$speed \tETHTOOL_MODE_HALF($p_speed, $p_mode),\n"
  38. fi
  39. gothalf=1
  40. elif [ "$duplex" = "Full" ]; then
  41. if [ "$gothalf" = "1" ]; then
  42. if [ "$p_speed" = "$speed" ] && [ "$p_mode" = "$mode" ]; then
  43. printf "%d \t%s\n" "$speed" "ETHTOOL_MODE_BOTH($speed, $mode),"
  44. else
  45. printf "%d \t%s\n" "$p_speed" "ETHTOOL_MODE_HALF($p_speed, $p_mode),"
  46. printf "%d \t%s\n" "$speed" "ETHTOOL_MODE_FULL($speed, $mode),"
  47. fi
  48. gothalf=0
  49. else
  50. printf "%d \t%s\n" "$speed" "ETHTOOL_MODE_FULL($speed, $mode),"
  51. fi
  52. else
  53. continue
  54. fi
  55. p_speed="$speed"
  56. p_mode="$mode"
  57. done ; [ "$gothalf" = "1" ] && printf "%d \t%s\n" "$p_speed" "ETHTOOL_MODE_HALF($p_speed, $p_mode)," ) | \
  58. LC_ALL=C sort -g | sed -r 's/[0-9]* (.*)/\1/'
  59. echo "};"