034-net-mvneta-Add-naive-RSS-support.patch 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  1. From: Gregory CLEMENT <gregory.clement@free-electrons.com>
  2. Date: Wed, 9 Dec 2015 18:23:50 +0100
  3. Subject: [PATCH] net: mvneta: Add naive RSS support
  4. This patch adds the support for the RSS related ethtool
  5. function. Currently it only uses one entry in the indirection table which
  6. allows associating an mvneta interface to a given CPU.
  7. Signed-off-by: Gregory CLEMENT <gregory.clement@free-electrons.com>
  8. Tested-by: Marcin Wojtas <mw@semihalf.com>
  9. Signed-off-by: David S. Miller <davem@davemloft.net>
  10. ---
  11. --- a/drivers/net/ethernet/marvell/mvneta.c
  12. +++ b/drivers/net/ethernet/marvell/mvneta.c
  13. @@ -261,6 +261,11 @@
  14. #define MVNETA_TX_MTU_MAX 0x3ffff
  15. +/* The RSS lookup table actually has 256 entries but we do not use
  16. + * them yet
  17. + */
  18. +#define MVNETA_RSS_LU_TABLE_SIZE 1
  19. +
  20. /* TSO header size */
  21. #define TSO_HEADER_SIZE 128
  22. @@ -382,6 +387,8 @@ struct mvneta_port {
  23. unsigned int use_inband_status:1;
  24. u64 ethtool_stats[ARRAY_SIZE(mvneta_statistics)];
  25. +
  26. + u32 indir[MVNETA_RSS_LU_TABLE_SIZE];
  27. };
  28. /* The mvneta_tx_desc and mvneta_rx_desc structures describe the
  29. @@ -1067,7 +1074,7 @@ static void mvneta_defaults_set(struct m
  30. if ((rxq % max_cpu) == cpu)
  31. rxq_map |= MVNETA_CPU_RXQ_ACCESS(rxq);
  32. - if (cpu == rxq_def)
  33. + if (cpu == pp->rxq_def)
  34. txq_map = MVNETA_CPU_TXQ_ACCESS_ALL_MASK;
  35. mvreg_write(pp, MVNETA_CPU_MAP(cpu), rxq_map | txq_map);
  36. @@ -2508,6 +2515,18 @@ static void mvneta_percpu_unmask_interru
  37. MVNETA_MISCINTR_INTR_MASK);
  38. }
  39. +static void mvneta_percpu_mask_interrupt(void *arg)
  40. +{
  41. + struct mvneta_port *pp = arg;
  42. +
  43. + /* All the queue are masked, but actually only the ones
  44. + * maped to this CPU will be masked
  45. + */
  46. + mvreg_write(pp, MVNETA_INTR_NEW_MASK, 0);
  47. + mvreg_write(pp, MVNETA_INTR_OLD_MASK, 0);
  48. + mvreg_write(pp, MVNETA_INTR_MISC_MASK, 0);
  49. +}
  50. +
  51. static void mvneta_start_dev(struct mvneta_port *pp)
  52. {
  53. unsigned int cpu;
  54. @@ -3231,6 +3250,106 @@ static int mvneta_ethtool_get_sset_count
  55. return -EOPNOTSUPP;
  56. }
  57. +static u32 mvneta_ethtool_get_rxfh_indir_size(struct net_device *dev)
  58. +{
  59. + return MVNETA_RSS_LU_TABLE_SIZE;
  60. +}
  61. +
  62. +static int mvneta_ethtool_get_rxnfc(struct net_device *dev,
  63. + struct ethtool_rxnfc *info,
  64. + u32 *rules __always_unused)
  65. +{
  66. + switch (info->cmd) {
  67. + case ETHTOOL_GRXRINGS:
  68. + info->data = rxq_number;
  69. + return 0;
  70. + case ETHTOOL_GRXFH:
  71. + return -EOPNOTSUPP;
  72. + default:
  73. + return -EOPNOTSUPP;
  74. + }
  75. +}
  76. +
  77. +static int mvneta_config_rss(struct mvneta_port *pp)
  78. +{
  79. + int cpu;
  80. + u32 val;
  81. +
  82. + netif_tx_stop_all_queues(pp->dev);
  83. +
  84. + for_each_online_cpu(cpu)
  85. + smp_call_function_single(cpu, mvneta_percpu_mask_interrupt,
  86. + pp, true);
  87. +
  88. + /* We have to synchronise on the napi of each CPU */
  89. + for_each_online_cpu(cpu) {
  90. + struct mvneta_pcpu_port *pcpu_port =
  91. + per_cpu_ptr(pp->ports, cpu);
  92. +
  93. + napi_synchronize(&pcpu_port->napi);
  94. + napi_disable(&pcpu_port->napi);
  95. + }
  96. +
  97. + pp->rxq_def = pp->indir[0];
  98. +
  99. + /* Update unicast mapping */
  100. + mvneta_set_rx_mode(pp->dev);
  101. +
  102. + /* Update val of portCfg register accordingly with all RxQueue types */
  103. + val = MVNETA_PORT_CONFIG_DEFL_VALUE(pp->rxq_def);
  104. + mvreg_write(pp, MVNETA_PORT_CONFIG, val);
  105. +
  106. + /* Update the elected CPU matching the new rxq_def */
  107. + mvneta_percpu_elect(pp);
  108. +
  109. + /* We have to synchronise on the napi of each CPU */
  110. + for_each_online_cpu(cpu) {
  111. + struct mvneta_pcpu_port *pcpu_port =
  112. + per_cpu_ptr(pp->ports, cpu);
  113. +
  114. + napi_enable(&pcpu_port->napi);
  115. + }
  116. +
  117. + netif_tx_start_all_queues(pp->dev);
  118. +
  119. + return 0;
  120. +}
  121. +
  122. +static int mvneta_ethtool_set_rxfh(struct net_device *dev, const u32 *indir,
  123. + const u8 *key, const u8 hfunc)
  124. +{
  125. + struct mvneta_port *pp = netdev_priv(dev);
  126. + /* We require at least one supported parameter to be changed
  127. + * and no change in any of the unsupported parameters
  128. + */
  129. + if (key ||
  130. + (hfunc != ETH_RSS_HASH_NO_CHANGE && hfunc != ETH_RSS_HASH_TOP))
  131. + return -EOPNOTSUPP;
  132. +
  133. + if (!indir)
  134. + return 0;
  135. +
  136. + memcpy(pp->indir, indir, MVNETA_RSS_LU_TABLE_SIZE);
  137. +
  138. + return mvneta_config_rss(pp);
  139. +}
  140. +
  141. +static int mvneta_ethtool_get_rxfh(struct net_device *dev, u32 *indir, u8 *key,
  142. + u8 *hfunc)
  143. +{
  144. + struct mvneta_port *pp = netdev_priv(dev);
  145. +
  146. + if (hfunc)
  147. + *hfunc = ETH_RSS_HASH_TOP;
  148. +
  149. + if (!indir)
  150. + return 0;
  151. +
  152. + memcpy(indir, pp->indir, MVNETA_RSS_LU_TABLE_SIZE);
  153. +
  154. + return 0;
  155. +}
  156. +
  157. static const struct net_device_ops mvneta_netdev_ops = {
  158. .ndo_open = mvneta_open,
  159. .ndo_stop = mvneta_stop,
  160. @@ -3255,6 +3374,10 @@ const struct ethtool_ops mvneta_eth_tool
  161. .get_strings = mvneta_ethtool_get_strings,
  162. .get_ethtool_stats = mvneta_ethtool_get_stats,
  163. .get_sset_count = mvneta_ethtool_get_sset_count,
  164. + .get_rxfh_indir_size = mvneta_ethtool_get_rxfh_indir_size,
  165. + .get_rxnfc = mvneta_ethtool_get_rxnfc,
  166. + .get_rxfh = mvneta_ethtool_get_rxfh,
  167. + .set_rxfh = mvneta_ethtool_set_rxfh,
  168. };
  169. /* Initialize hw */
  170. @@ -3446,6 +3569,8 @@ static int mvneta_probe(struct platform_
  171. pp->rxq_def = rxq_def;
  172. + pp->indir[0] = rxq_def;
  173. +
  174. pp->clk = devm_clk_get(&pdev->dev, NULL);
  175. if (IS_ERR(pp->clk)) {
  176. err = PTR_ERR(pp->clk);