380-mac80211-introduce-aql_enable-node-in-debugfs.patch 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. From: Lorenzo Bianconi <[email protected]>
  2. Date: Sat, 9 Jan 2021 18:57:51 +0100
  3. Subject: [PATCH] mac80211: introduce aql_enable node in debugfs
  4. Introduce aql_enable node in debugfs in order to enable/disable aql.
  5. This is useful for debugging purpose.
  6. Signed-off-by: Lorenzo Bianconi <[email protected]>
  7. Link: https://lore.kernel.org/r/e7a934d5d84e4796c4f97ea5de4e66c824296b07.1610214851.git.lorenzo@kernel.org
  8. Signed-off-by: Johannes Berg <[email protected]>
  9. ---
  10. --- a/net/mac80211/debugfs.c
  11. +++ b/net/mac80211/debugfs.c
  12. @@ -281,6 +281,56 @@ static const struct file_operations aql_
  13. .llseek = default_llseek,
  14. };
  15. +static ssize_t aql_enable_read(struct file *file, char __user *user_buf,
  16. + size_t count, loff_t *ppos)
  17. +{
  18. + char buf[3];
  19. + int len;
  20. +
  21. + len = scnprintf(buf, sizeof(buf), "%d\n",
  22. + !static_key_false(&aql_disable.key));
  23. +
  24. + return simple_read_from_buffer(user_buf, count, ppos, buf, len);
  25. +}
  26. +
  27. +static ssize_t aql_enable_write(struct file *file, const char __user *user_buf,
  28. + size_t count, loff_t *ppos)
  29. +{
  30. + bool aql_disabled = static_key_false(&aql_disable.key);
  31. + char buf[3];
  32. + size_t len;
  33. +
  34. + if (count > sizeof(buf))
  35. + return -EINVAL;
  36. +
  37. + if (copy_from_user(buf, user_buf, count))
  38. + return -EFAULT;
  39. +
  40. + buf[sizeof(buf) - 1] = '\0';
  41. + len = strlen(buf);
  42. + if (len > 0 && buf[len - 1] == '\n')
  43. + buf[len - 1] = 0;
  44. +
  45. + if (buf[0] == '0' && buf[1] == '\0') {
  46. + if (!aql_disabled)
  47. + static_branch_inc(&aql_disable);
  48. + } else if (buf[0] == '1' && buf[1] == '\0') {
  49. + if (aql_disabled)
  50. + static_branch_dec(&aql_disable);
  51. + } else {
  52. + return -EINVAL;
  53. + }
  54. +
  55. + return count;
  56. +}
  57. +
  58. +static const struct file_operations aql_enable_ops = {
  59. + .write = aql_enable_write,
  60. + .read = aql_enable_read,
  61. + .open = simple_open,
  62. + .llseek = default_llseek,
  63. +};
  64. +
  65. static ssize_t force_tx_status_read(struct file *file,
  66. char __user *user_buf,
  67. size_t count,
  68. @@ -569,6 +619,7 @@ void debugfs_hw_add(struct ieee80211_loc
  69. DEBUGFS_ADD(power);
  70. DEBUGFS_ADD(hw_conf);
  71. DEBUGFS_ADD_MODE(force_tx_status, 0600);
  72. + DEBUGFS_ADD_MODE(aql_enable, 0600);
  73. if (local->ops->wake_tx_queue)
  74. DEBUGFS_ADD_MODE(aqm, 0600);
  75. --- a/net/mac80211/ieee80211_i.h
  76. +++ b/net/mac80211/ieee80211_i.h
  77. @@ -1140,6 +1140,8 @@ enum mac80211_scan_state {
  78. SCAN_ABORT,
  79. };
  80. +DECLARE_STATIC_KEY_FALSE(aql_disable);
  81. +
  82. struct ieee80211_local {
  83. /* embed the driver visible part.
  84. * don't cast (use the static inlines below), but we keep
  85. --- a/net/mac80211/tx.c
  86. +++ b/net/mac80211/tx.c
  87. @@ -3909,6 +3909,8 @@ void __ieee80211_schedule_txq(struct iee
  88. }
  89. EXPORT_SYMBOL(__ieee80211_schedule_txq);
  90. +DEFINE_STATIC_KEY_FALSE(aql_disable);
  91. +
  92. bool ieee80211_txq_airtime_check(struct ieee80211_hw *hw,
  93. struct ieee80211_txq *txq)
  94. {
  95. @@ -3918,6 +3920,9 @@ bool ieee80211_txq_airtime_check(struct
  96. if (!wiphy_ext_feature_isset(local->hw.wiphy, NL80211_EXT_FEATURE_AQL))
  97. return true;
  98. + if (static_branch_unlikely(&aql_disable))
  99. + return true;
  100. +
  101. if (!txq->sta)
  102. return true;