764-08-v5.17-net-next-net-dsa-qca8k-add-additional-MIB-counter-and-.patch 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. From c126f118b330ccf0db0dda4a4bd6c729865a205f Mon Sep 17 00:00:00 2001
  2. From: Ansuel Smith <[email protected]>
  3. Date: Mon, 22 Nov 2021 16:23:45 +0100
  4. Subject: net: dsa: qca8k: add additional MIB counter and make it dynamic
  5. We are currently missing 2 additionals MIB counter present in QCA833x
  6. switch.
  7. QC832x switch have 39 MIB counter and QCA833X have 41 MIB counter.
  8. Add the additional MIB counter and rework the MIB function to print the
  9. correct supported counter from the match_data struct.
  10. Signed-off-by: Ansuel Smith <[email protected]>
  11. Reviewed-by: Vladimir Oltean <[email protected]>
  12. Signed-off-by: David S. Miller <[email protected]>
  13. ---
  14. drivers/net/dsa/qca8k.c | 23 ++++++++++++++++++++---
  15. drivers/net/dsa/qca8k.h | 4 ++++
  16. 2 files changed, 24 insertions(+), 3 deletions(-)
  17. --- a/drivers/net/dsa/qca8k.c
  18. +++ b/drivers/net/dsa/qca8k.c
  19. @@ -70,6 +70,8 @@ static const struct qca8k_mib_desc ar832
  20. MIB_DESC(1, 0x9c, "TxExcDefer"),
  21. MIB_DESC(1, 0xa0, "TxDefer"),
  22. MIB_DESC(1, 0xa4, "TxLateCol"),
  23. + MIB_DESC(1, 0xa8, "RXUnicast"),
  24. + MIB_DESC(1, 0xac, "TXUnicast"),
  25. };
  26. /* The 32bit switch registers are accessed indirectly. To achieve this we need
  27. @@ -1605,12 +1607,16 @@ qca8k_phylink_mac_link_up(struct dsa_swi
  28. static void
  29. qca8k_get_strings(struct dsa_switch *ds, int port, u32 stringset, uint8_t *data)
  30. {
  31. + const struct qca8k_match_data *match_data;
  32. + struct qca8k_priv *priv = ds->priv;
  33. int i;
  34. if (stringset != ETH_SS_STATS)
  35. return;
  36. - for (i = 0; i < ARRAY_SIZE(ar8327_mib); i++)
  37. + match_data = of_device_get_match_data(priv->dev);
  38. +
  39. + for (i = 0; i < match_data->mib_count; i++)
  40. strncpy(data + i * ETH_GSTRING_LEN, ar8327_mib[i].name,
  41. ETH_GSTRING_LEN);
  42. }
  43. @@ -1620,12 +1626,15 @@ qca8k_get_ethtool_stats(struct dsa_switc
  44. uint64_t *data)
  45. {
  46. struct qca8k_priv *priv = (struct qca8k_priv *)ds->priv;
  47. + const struct qca8k_match_data *match_data;
  48. const struct qca8k_mib_desc *mib;
  49. u32 reg, i, val;
  50. u32 hi = 0;
  51. int ret;
  52. - for (i = 0; i < ARRAY_SIZE(ar8327_mib); i++) {
  53. + match_data = of_device_get_match_data(priv->dev);
  54. +
  55. + for (i = 0; i < match_data->mib_count; i++) {
  56. mib = &ar8327_mib[i];
  57. reg = QCA8K_PORT_MIB_COUNTER(port) + mib->offset;
  58. @@ -1648,10 +1657,15 @@ qca8k_get_ethtool_stats(struct dsa_switc
  59. static int
  60. qca8k_get_sset_count(struct dsa_switch *ds, int port, int sset)
  61. {
  62. + const struct qca8k_match_data *match_data;
  63. + struct qca8k_priv *priv = ds->priv;
  64. +
  65. if (sset != ETH_SS_STATS)
  66. return 0;
  67. - return ARRAY_SIZE(ar8327_mib);
  68. + match_data = of_device_get_match_data(priv->dev);
  69. +
  70. + return match_data->mib_count;
  71. }
  72. static int
  73. @@ -2173,14 +2187,17 @@ static SIMPLE_DEV_PM_OPS(qca8k_pm_ops,
  74. static const struct qca8k_match_data qca8327 = {
  75. .id = QCA8K_ID_QCA8327,
  76. .reduced_package = true,
  77. + .mib_count = QCA8K_QCA832X_MIB_COUNT,
  78. };
  79. static const struct qca8k_match_data qca8328 = {
  80. .id = QCA8K_ID_QCA8327,
  81. + .mib_count = QCA8K_QCA832X_MIB_COUNT,
  82. };
  83. static const struct qca8k_match_data qca833x = {
  84. .id = QCA8K_ID_QCA8337,
  85. + .mib_count = QCA8K_QCA833X_MIB_COUNT,
  86. };
  87. static const struct of_device_id qca8k_of_match[] = {
  88. --- a/drivers/net/dsa/qca8k.h
  89. +++ b/drivers/net/dsa/qca8k.h
  90. @@ -21,6 +21,9 @@
  91. #define PHY_ID_QCA8337 0x004dd036
  92. #define QCA8K_ID_QCA8337 0x13
  93. +#define QCA8K_QCA832X_MIB_COUNT 39
  94. +#define QCA8K_QCA833X_MIB_COUNT 41
  95. +
  96. #define QCA8K_BUSY_WAIT_TIMEOUT 2000
  97. #define QCA8K_NUM_FDB_RECORDS 2048
  98. @@ -279,6 +282,7 @@ struct ar8xxx_port_status {
  99. struct qca8k_match_data {
  100. u8 id;
  101. bool reduced_package;
  102. + u8 mib_count;
  103. };
  104. enum {