[PATCH V2 net-next] net: mvpp2: Add parsing support for different IPv4 IHL values

2021-04-16 Thread stefanc
From: Stefan Chulski 

Add parser entries for different IPv4 IHL values.
Each entry will set the L4 header offset according to the IPv4 IHL field.
L3 header offset will set during the parsing of the IPv4 protocol.

Because of missed parser support for IP header length > 20, RX IPv4 checksum HW 
offload fails
and skb->ip_summed set to CHECKSUM_NONE(checksum done by Network stack). 
This patch adds RX IPv4 checksum HW offload capability for frames with IP 
header length > 20.

v1 --> v2
- Improve commit message.

Suggested-by: Dana Vardi 
Signed-off-by: Stefan Chulski 
---
 drivers/net/ethernet/marvell/mvpp2/mvpp2_prs.c | 107 
 drivers/net/ethernet/marvell/mvpp2/mvpp2_prs.h |   3 +-
 2 files changed, 43 insertions(+), 67 deletions(-)

diff --git a/drivers/net/ethernet/marvell/mvpp2/mvpp2_prs.c 
b/drivers/net/ethernet/marvell/mvpp2/mvpp2_prs.c
index 4812cdb..7cc7d72 100644
--- a/drivers/net/ethernet/marvell/mvpp2/mvpp2_prs.c
+++ b/drivers/net/ethernet/marvell/mvpp2/mvpp2_prs.c
@@ -918,9 +918,8 @@ static int mvpp2_prs_ip4_proto(struct mvpp2 *priv, unsigned 
short proto,
mvpp2_prs_sram_next_lu_set(&pe, MVPP2_PRS_LU_FLOWS);
mvpp2_prs_sram_bits_set(&pe, MVPP2_PRS_SRAM_LU_GEN_BIT, 1);
 
-   /* Set L4 offset */
-   mvpp2_prs_sram_offset_set(&pe, MVPP2_PRS_SRAM_UDF_TYPE_L4,
- sizeof(struct iphdr) - 4,
+   /* Set L3 offset */
+   mvpp2_prs_sram_offset_set(&pe, MVPP2_PRS_SRAM_UDF_TYPE_L3, -4,
  MVPP2_PRS_SRAM_OP_SEL_UDF_ADD);
mvpp2_prs_sram_ai_update(&pe, 0, MVPP2_PRS_IPV4_DIP_AI_BIT);
mvpp2_prs_sram_ri_update(&pe, ri, ri_mask | MVPP2_PRS_RI_IP_FRAG_MASK);
@@ -1335,7 +1334,7 @@ static void mvpp2_prs_vid_init(struct mvpp2 *priv)
 static int mvpp2_prs_etype_init(struct mvpp2 *priv)
 {
struct mvpp2_prs_entry pe;
-   int tid;
+   int tid, ihl;
 
/* Ethertype: PPPoE */
tid = mvpp2_prs_tcam_first_free(priv, MVPP2_PE_FIRST_FREE_TID,
@@ -1427,67 +1426,43 @@ static int mvpp2_prs_etype_init(struct mvpp2 *priv)
MVPP2_PRS_RI_UDF3_MASK);
mvpp2_prs_hw_write(priv, &pe);
 
-   /* Ethertype: IPv4 without options */
-   tid = mvpp2_prs_tcam_first_free(priv, MVPP2_PE_FIRST_FREE_TID,
-   MVPP2_PE_LAST_FREE_TID);
-   if (tid < 0)
-   return tid;
-
-   memset(&pe, 0, sizeof(pe));
-   mvpp2_prs_tcam_lu_set(&pe, MVPP2_PRS_LU_L2);
-   pe.index = tid;
-
-   mvpp2_prs_match_etype(&pe, 0, ETH_P_IP);
-   mvpp2_prs_tcam_data_byte_set(&pe, MVPP2_ETH_TYPE_LEN,
-MVPP2_PRS_IPV4_HEAD | MVPP2_PRS_IPV4_IHL,
-MVPP2_PRS_IPV4_HEAD_MASK |
-MVPP2_PRS_IPV4_IHL_MASK);
-
-   mvpp2_prs_sram_next_lu_set(&pe, MVPP2_PRS_LU_IP4);
-   mvpp2_prs_sram_ri_update(&pe, MVPP2_PRS_RI_L3_IP4,
-MVPP2_PRS_RI_L3_PROTO_MASK);
-   /* goto ipv4 dest-address (skip eth_type + IP-header-size - 4) */
-   mvpp2_prs_sram_shift_set(&pe, MVPP2_ETH_TYPE_LEN +
-sizeof(struct iphdr) - 4,
-MVPP2_PRS_SRAM_OP_SEL_SHIFT_ADD);
-   /* Set L3 offset */
-   mvpp2_prs_sram_offset_set(&pe, MVPP2_PRS_SRAM_UDF_TYPE_L3,
- MVPP2_ETH_TYPE_LEN,
- MVPP2_PRS_SRAM_OP_SEL_UDF_ADD);
-
-   /* Update shadow table and hw entry */
-   mvpp2_prs_shadow_set(priv, pe.index, MVPP2_PRS_LU_L2);
-   priv->prs_shadow[pe.index].udf = MVPP2_PRS_UDF_L2_DEF;
-   priv->prs_shadow[pe.index].finish = false;
-   mvpp2_prs_shadow_ri_set(priv, pe.index, MVPP2_PRS_RI_L3_IP4,
-   MVPP2_PRS_RI_L3_PROTO_MASK);
-   mvpp2_prs_hw_write(priv, &pe);
-
-   /* Ethertype: IPv4 with options */
-   tid = mvpp2_prs_tcam_first_free(priv, MVPP2_PE_FIRST_FREE_TID,
-   MVPP2_PE_LAST_FREE_TID);
-   if (tid < 0)
-   return tid;
-
-   pe.index = tid;
+   /* Ethertype: IPv4 with header length >= 5 */
+   for (ihl = MVPP2_PRS_IPV4_IHL_MIN; ihl <= MVPP2_PRS_IPV4_IHL_MAX; 
ihl++) {
+   tid = mvpp2_prs_tcam_first_free(priv, MVPP2_PE_FIRST_FREE_TID,
+   MVPP2_PE_LAST_FREE_TID);
+   if (tid < 0)
+   return tid;
 
-   mvpp2_prs_tcam_data_byte_set(&pe, MVPP2_ETH_TYPE_LEN,
-MVPP2_PRS_IPV4_HEAD,
-MVPP2_PRS_IPV4_HEAD_MASK);
+   memset(&pe, 0, sizeof(pe));
+   mvpp2_prs_tcam_lu_set(&pe, MVPP2_PRS_LU_L2);
+   pe.index = tid;
 
-   /* Clear ri before updating */
-   pe.sram[MVPP2_PRS_SRAM_RI_WORD] = 0x0;
-   pe.sram[MVPP2_PRS_SRAM_RI_CTRL_WORD] = 0x0;
-   mvpp2_prs_sram_ri

[PATCH net-next] net: mvpp2: Add parsing support for different IPv4 IHL values

2021-04-13 Thread stefanc
From: Stefan Chulski 

Add parser entries for different IPv4 IHL values.
Each entry will set the L4 header offset according to the IPv4 IHL field.
L3 header offset will set during the parsing of the IPv4 protocol.

Suggested-by: Dana Vardi 
Signed-off-by: Stefan Chulski 
---
 drivers/net/ethernet/marvell/mvpp2/mvpp2_prs.c | 107 
 drivers/net/ethernet/marvell/mvpp2/mvpp2_prs.h |   3 +-
 2 files changed, 43 insertions(+), 67 deletions(-)

diff --git a/drivers/net/ethernet/marvell/mvpp2/mvpp2_prs.c 
b/drivers/net/ethernet/marvell/mvpp2/mvpp2_prs.c
index 4812cdb..7cc7d72 100644
--- a/drivers/net/ethernet/marvell/mvpp2/mvpp2_prs.c
+++ b/drivers/net/ethernet/marvell/mvpp2/mvpp2_prs.c
@@ -918,9 +918,8 @@ static int mvpp2_prs_ip4_proto(struct mvpp2 *priv, unsigned 
short proto,
mvpp2_prs_sram_next_lu_set(&pe, MVPP2_PRS_LU_FLOWS);
mvpp2_prs_sram_bits_set(&pe, MVPP2_PRS_SRAM_LU_GEN_BIT, 1);
 
-   /* Set L4 offset */
-   mvpp2_prs_sram_offset_set(&pe, MVPP2_PRS_SRAM_UDF_TYPE_L4,
- sizeof(struct iphdr) - 4,
+   /* Set L3 offset */
+   mvpp2_prs_sram_offset_set(&pe, MVPP2_PRS_SRAM_UDF_TYPE_L3, -4,
  MVPP2_PRS_SRAM_OP_SEL_UDF_ADD);
mvpp2_prs_sram_ai_update(&pe, 0, MVPP2_PRS_IPV4_DIP_AI_BIT);
mvpp2_prs_sram_ri_update(&pe, ri, ri_mask | MVPP2_PRS_RI_IP_FRAG_MASK);
@@ -1335,7 +1334,7 @@ static void mvpp2_prs_vid_init(struct mvpp2 *priv)
 static int mvpp2_prs_etype_init(struct mvpp2 *priv)
 {
struct mvpp2_prs_entry pe;
-   int tid;
+   int tid, ihl;
 
/* Ethertype: PPPoE */
tid = mvpp2_prs_tcam_first_free(priv, MVPP2_PE_FIRST_FREE_TID,
@@ -1427,67 +1426,43 @@ static int mvpp2_prs_etype_init(struct mvpp2 *priv)
MVPP2_PRS_RI_UDF3_MASK);
mvpp2_prs_hw_write(priv, &pe);
 
-   /* Ethertype: IPv4 without options */
-   tid = mvpp2_prs_tcam_first_free(priv, MVPP2_PE_FIRST_FREE_TID,
-   MVPP2_PE_LAST_FREE_TID);
-   if (tid < 0)
-   return tid;
-
-   memset(&pe, 0, sizeof(pe));
-   mvpp2_prs_tcam_lu_set(&pe, MVPP2_PRS_LU_L2);
-   pe.index = tid;
-
-   mvpp2_prs_match_etype(&pe, 0, ETH_P_IP);
-   mvpp2_prs_tcam_data_byte_set(&pe, MVPP2_ETH_TYPE_LEN,
-MVPP2_PRS_IPV4_HEAD | MVPP2_PRS_IPV4_IHL,
-MVPP2_PRS_IPV4_HEAD_MASK |
-MVPP2_PRS_IPV4_IHL_MASK);
-
-   mvpp2_prs_sram_next_lu_set(&pe, MVPP2_PRS_LU_IP4);
-   mvpp2_prs_sram_ri_update(&pe, MVPP2_PRS_RI_L3_IP4,
-MVPP2_PRS_RI_L3_PROTO_MASK);
-   /* goto ipv4 dest-address (skip eth_type + IP-header-size - 4) */
-   mvpp2_prs_sram_shift_set(&pe, MVPP2_ETH_TYPE_LEN +
-sizeof(struct iphdr) - 4,
-MVPP2_PRS_SRAM_OP_SEL_SHIFT_ADD);
-   /* Set L3 offset */
-   mvpp2_prs_sram_offset_set(&pe, MVPP2_PRS_SRAM_UDF_TYPE_L3,
- MVPP2_ETH_TYPE_LEN,
- MVPP2_PRS_SRAM_OP_SEL_UDF_ADD);
-
-   /* Update shadow table and hw entry */
-   mvpp2_prs_shadow_set(priv, pe.index, MVPP2_PRS_LU_L2);
-   priv->prs_shadow[pe.index].udf = MVPP2_PRS_UDF_L2_DEF;
-   priv->prs_shadow[pe.index].finish = false;
-   mvpp2_prs_shadow_ri_set(priv, pe.index, MVPP2_PRS_RI_L3_IP4,
-   MVPP2_PRS_RI_L3_PROTO_MASK);
-   mvpp2_prs_hw_write(priv, &pe);
-
-   /* Ethertype: IPv4 with options */
-   tid = mvpp2_prs_tcam_first_free(priv, MVPP2_PE_FIRST_FREE_TID,
-   MVPP2_PE_LAST_FREE_TID);
-   if (tid < 0)
-   return tid;
-
-   pe.index = tid;
+   /* Ethertype: IPv4 with header length >= 5 */
+   for (ihl = MVPP2_PRS_IPV4_IHL_MIN; ihl <= MVPP2_PRS_IPV4_IHL_MAX; 
ihl++) {
+   tid = mvpp2_prs_tcam_first_free(priv, MVPP2_PE_FIRST_FREE_TID,
+   MVPP2_PE_LAST_FREE_TID);
+   if (tid < 0)
+   return tid;
 
-   mvpp2_prs_tcam_data_byte_set(&pe, MVPP2_ETH_TYPE_LEN,
-MVPP2_PRS_IPV4_HEAD,
-MVPP2_PRS_IPV4_HEAD_MASK);
+   memset(&pe, 0, sizeof(pe));
+   mvpp2_prs_tcam_lu_set(&pe, MVPP2_PRS_LU_L2);
+   pe.index = tid;
 
-   /* Clear ri before updating */
-   pe.sram[MVPP2_PRS_SRAM_RI_WORD] = 0x0;
-   pe.sram[MVPP2_PRS_SRAM_RI_CTRL_WORD] = 0x0;
-   mvpp2_prs_sram_ri_update(&pe, MVPP2_PRS_RI_L3_IP4_OPT,
-MVPP2_PRS_RI_L3_PROTO_MASK);
+   mvpp2_prs_match_etype(&pe, 0, ETH_P_IP);
+   mvpp2_prs_tcam_data_byte_set(&pe, MVPP2_ETH_TYPE_LEN,
+MVPP2_PRS_IPV4_HEAD | ihl,
+  

[V2 net-next] net: mvpp2: Add reserved port private flag configuration

2021-03-11 Thread stefanc
From: Stefan Chulski 

According to Armada SoC architecture and design, all the PPv2 ports
which are populated on the same communication processor silicon die
(CP11x) share the same Classifier and Parser engines.

Armada is an embedded platform and therefore there is a need to reserve
some of the PPv2 ports for different use cases.

For example, a port can be reserved for a CM3 CPU running FreeRTOS for
management purposes or by user-space data plane application.

During port reservation all common configurations are preserved and
only RXQ, TXQ, and interrupt vectors are disabled.
Since TXQ's are disabled, the Kernel won't transmit any packet
from this port, and to due the closed RXQ interrupts, the Kernel won't
receive any packet.
The port MAC address and administrative UP/DOWN state can still
be changed.
The only permitted configuration in this mode is MTU change.
The driver's .ndo_change_mtu callback has logic that switches between
percpu_pools and shared pools buffer mode, since the buffer management
not done by Kernel this should be permitted.

v1 --> v2
- Rename existing mvpp2_ethtool_get_strings and helper _priv function
- Add more info to commit message

Signed-off-by: Stefan Chulski 
---
 drivers/net/ethernet/marvell/mvpp2/mvpp2.h  |   4 +
 drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c | 248 ++--
 2 files changed, 228 insertions(+), 24 deletions(-)

diff --git a/drivers/net/ethernet/marvell/mvpp2/mvpp2.h 
b/drivers/net/ethernet/marvell/mvpp2/mvpp2.h
index 8edba5e..e2f8eec 100644
--- a/drivers/net/ethernet/marvell/mvpp2/mvpp2.h
+++ b/drivers/net/ethernet/marvell/mvpp2/mvpp2.h
@@ -865,6 +865,7 @@
 /* Port flags */
 #define MVPP2_F_LOOPBACK   BIT(0)
 #define MVPP2_F_DT_COMPAT  BIT(1)
+#define MVPP22_F_IF_RESERVED   BIT(2)
 
 /* Marvell tag types */
 enum mvpp2_tag_type {
@@ -1251,6 +1252,9 @@ struct mvpp2_port {
 
/* Firmware TX flow control */
bool tx_fc;
+
+   /* private storage, allocated/used by Reserved/Normal mode toggling */
+   void *res_cfg;
 };
 
 /* The mvpp2_tx_desc and mvpp2_rx_desc structures describe the
diff --git a/drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c 
b/drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c
index d415447..7406724 100644
--- a/drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c
+++ b/drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c
@@ -55,6 +55,14 @@ enum mvpp2_bm_pool_log_num {
int buf_num;
 } mvpp2_pools[MVPP2_BM_POOLS_NUM];
 
+struct mvpp2_port_port_cfg {
+   unsigned int nqvecs;
+   unsigned int nrxqs;
+   unsigned int ntxqs;
+   int mtu;
+   bool rxhash_en;
+};
+
 /* The prototype is added here to be used in start_dev when using ACPI. This
  * will be removed once phylink is used for all modes (dt+ACPI).
  */
@@ -1431,6 +1439,9 @@ static void mvpp2_interrupts_unmask(void *arg)
if (cpu >= port->priv->nthreads)
return;
 
+   if (port->flags & MVPP22_F_IF_RESERVED)
+   return;
+
thread = mvpp2_cpu_to_thread(port->priv, cpu);
 
val = MVPP2_CAUSE_MISC_SUM_MASK |
@@ -1942,15 +1953,23 @@ static u32 mvpp2_read_index(struct mvpp2 *priv, u32 
index, u32 reg)
 
(ARRAY_SIZE(mvpp2_ethtool_rxq_regs) * (nrxqs)) + \
 ARRAY_SIZE(mvpp2_ethtool_xdp))
 
-static void mvpp2_ethtool_get_strings(struct net_device *netdev, u32 sset,
- u8 *data)
+static const char mvpp22_priv_flags_strings[][ETH_GSTRING_LEN] = {
+   "reserved",
+};
+
+#define MVPP22_F_IF_RESERVED_PRIV  BIT(0)
+
+static void mvpp2_ethtool_get_strings_priv(u8 *data)
+{
+   memcpy(data, mvpp22_priv_flags_strings,
+  ARRAY_SIZE(mvpp22_priv_flags_strings) * ETH_GSTRING_LEN);
+}
+
+static void mvpp2_ethtool_get_strings_stats(struct net_device *netdev, u8 
*data)
 {
struct mvpp2_port *port = netdev_priv(netdev);
int i, q;
 
-   if (sset != ETH_SS_STATS)
-   return;
-
for (i = 0; i < ARRAY_SIZE(mvpp2_ethtool_mib_regs); i++) {
strscpy(data, mvpp2_ethtool_mib_regs[i].string,
ETH_GSTRING_LEN);
@@ -1987,6 +2006,18 @@ static void mvpp2_ethtool_get_strings(struct net_device 
*netdev, u32 sset,
}
 }
 
+static void mvpp2_ethtool_get_strings(struct net_device *netdev, u32 sset,
+ u8 *data)
+{
+   switch (sset) {
+   case ETH_SS_STATS:
+   mvpp2_ethtool_get_strings_stats(netdev, data);
+   break;
+   case ETH_SS_PRIV_FLAGS:
+   mvpp2_ethtool_get_strings_priv(data);
+   }
+}
+
 static void
 mvpp2_get_xdp_stats(struct mvpp2_port *port, struct mvpp2_pcpu_stats 
*xdp_stats)
 {
@@ -2130,8 +2161,13 @@ static int mvpp2_ethtool_get_sset_count(struct 
net_device *dev, int sset)
 {
struct mvpp2_port *port = netdev_priv(dev);
 
-   if (sset == ETH_SS_STAT

[net-next] net: mvpp2: Add reserved port private flag configuration

2021-03-10 Thread stefanc
From: Stefan Chulski 

According to Armada SoC architecture and design, all the PPv2 ports
which are populated on the same communication processor silicon die
(CP11x) share the same Classifier and Parser engines.

Armada is an embedded platform and therefore there is a need to reserve
some of the PPv2 ports for different use cases.

For example, a port can be reserved for a CM3 CPU running FreeRTOS for
management purposes or by user-space data plane application.

During port reservation all common configurations are preserved and
only RXQ, TXQ, and interrupt vectors are disabled.

Signed-off-by: Stefan Chulski 
---
 drivers/net/ethernet/marvell/mvpp2/mvpp2.h  |   4 +
 drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c | 286 
 2 files changed, 242 insertions(+), 48 deletions(-)

diff --git a/drivers/net/ethernet/marvell/mvpp2/mvpp2.h 
b/drivers/net/ethernet/marvell/mvpp2/mvpp2.h
index 8edba5e..e2f8eec 100644
--- a/drivers/net/ethernet/marvell/mvpp2/mvpp2.h
+++ b/drivers/net/ethernet/marvell/mvpp2/mvpp2.h
@@ -865,6 +865,7 @@
 /* Port flags */
 #define MVPP2_F_LOOPBACK   BIT(0)
 #define MVPP2_F_DT_COMPAT  BIT(1)
+#define MVPP22_F_IF_RESERVED   BIT(2)
 
 /* Marvell tag types */
 enum mvpp2_tag_type {
@@ -1251,6 +1252,9 @@ struct mvpp2_port {
 
/* Firmware TX flow control */
bool tx_fc;
+
+   /* private storage, allocated/used by Reserved/Normal mode toggling */
+   void *res_cfg;
 };
 
 /* The mvpp2_tx_desc and mvpp2_rx_desc structures describe the
diff --git a/drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c 
b/drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c
index d415447..80ddf1c 100644
--- a/drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c
+++ b/drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c
@@ -55,6 +55,14 @@ enum mvpp2_bm_pool_log_num {
int buf_num;
 } mvpp2_pools[MVPP2_BM_POOLS_NUM];
 
+struct mvpp2_port_port_cfg {
+   unsigned int nqvecs;
+   unsigned int nrxqs;
+   unsigned int ntxqs;
+   int mtu;
+   bool rxhash_en;
+};
+
 /* The prototype is added here to be used in start_dev when using ACPI. This
  * will be removed once phylink is used for all modes (dt+ACPI).
  */
@@ -1431,6 +1439,9 @@ static void mvpp2_interrupts_unmask(void *arg)
if (cpu >= port->priv->nthreads)
return;
 
+   if (port->flags & MVPP22_F_IF_RESERVED)
+   return;
+
thread = mvpp2_cpu_to_thread(port->priv, cpu);
 
val = MVPP2_CAUSE_MISC_SUM_MASK |
@@ -1942,48 +1953,58 @@ static u32 mvpp2_read_index(struct mvpp2 *priv, u32 
index, u32 reg)
 
(ARRAY_SIZE(mvpp2_ethtool_rxq_regs) * (nrxqs)) + \
 ARRAY_SIZE(mvpp2_ethtool_xdp))
 
+static const char mvpp22_priv_flags_strings[][ETH_GSTRING_LEN] = {
+   "reserved",
+};
+
+#define MVPP22_F_IF_RESERVED_PRIV  BIT(0)
+
 static void mvpp2_ethtool_get_strings(struct net_device *netdev, u32 sset,
  u8 *data)
 {
struct mvpp2_port *port = netdev_priv(netdev);
int i, q;
 
-   if (sset != ETH_SS_STATS)
-   return;
+   switch (sset) {
+   case ETH_SS_STATS:
+   for (i = 0; i < ARRAY_SIZE(mvpp2_ethtool_mib_regs); i++) {
+   strscpy(data, mvpp2_ethtool_mib_regs[i].string,
+   ETH_GSTRING_LEN);
+   data += ETH_GSTRING_LEN;
+   }
 
-   for (i = 0; i < ARRAY_SIZE(mvpp2_ethtool_mib_regs); i++) {
-   strscpy(data, mvpp2_ethtool_mib_regs[i].string,
-   ETH_GSTRING_LEN);
-   data += ETH_GSTRING_LEN;
-   }
+   for (i = 0; i < ARRAY_SIZE(mvpp2_ethtool_port_regs); i++) {
+   strscpy(data, mvpp2_ethtool_port_regs[i].string,
+   ETH_GSTRING_LEN);
+   data += ETH_GSTRING_LEN;
+   }
 
-   for (i = 0; i < ARRAY_SIZE(mvpp2_ethtool_port_regs); i++) {
-   strscpy(data, mvpp2_ethtool_port_regs[i].string,
-   ETH_GSTRING_LEN);
-   data += ETH_GSTRING_LEN;
-   }
+   for (q = 0; q < port->ntxqs; q++) {
+   for (i = 0; i < ARRAY_SIZE(mvpp2_ethtool_txq_regs); 
i++) {
+   snprintf(data, ETH_GSTRING_LEN,
+mvpp2_ethtool_txq_regs[i].string, q);
+   data += ETH_GSTRING_LEN;
+   }
+   }
 
-   for (q = 0; q < port->ntxqs; q++) {
-   for (i = 0; i < ARRAY_SIZE(mvpp2_ethtool_txq_regs); i++) {
-   snprintf(data, ETH_GSTRING_LEN,
-mvpp2_ethtool_txq_regs[i].string, q);
-   data += ETH_GSTRING_LEN;
+   for (q = 0; q < port->nrxqs; q++) {
+   for (i = 

[net-next] net: mvpp2: skip RSS configurations on loopback port

2021-02-18 Thread stefanc
From: Stefan Chulski 

PPv2 loopback port doesn't support RSS, so we should
skip RSS configurations for this port.

Signed-off-by: Stefan Chulski 
---
 drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c | 25 +++-
 1 file changed, 14 insertions(+), 11 deletions(-)

diff --git a/drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c 
b/drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c
index 10c17d1..d415447 100644
--- a/drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c
+++ b/drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c
@@ -4699,9 +4699,10 @@ static void mvpp2_irqs_deinit(struct mvpp2_port *port)
}
 }
 
-static bool mvpp22_rss_is_supported(void)
+static bool mvpp22_rss_is_supported(struct mvpp2_port *port)
 {
-   return queue_mode == MVPP2_QDIST_MULTI_MODE;
+   return (queue_mode == MVPP2_QDIST_MULTI_MODE) &&
+   !(port->flags & MVPP2_F_LOOPBACK);
 }
 
 static int mvpp2_open(struct net_device *dev)
@@ -5513,7 +5514,7 @@ static int mvpp2_ethtool_get_rxnfc(struct net_device *dev,
struct mvpp2_port *port = netdev_priv(dev);
int ret = 0, i, loc = 0;
 
-   if (!mvpp22_rss_is_supported())
+   if (!mvpp22_rss_is_supported(port))
return -EOPNOTSUPP;
 
switch (info->cmd) {
@@ -5548,7 +5549,7 @@ static int mvpp2_ethtool_set_rxnfc(struct net_device *dev,
struct mvpp2_port *port = netdev_priv(dev);
int ret = 0;
 
-   if (!mvpp22_rss_is_supported())
+   if (!mvpp22_rss_is_supported(port))
return -EOPNOTSUPP;
 
switch (info->cmd) {
@@ -5569,7 +5570,9 @@ static int mvpp2_ethtool_set_rxnfc(struct net_device *dev,
 
 static u32 mvpp2_ethtool_get_rxfh_indir_size(struct net_device *dev)
 {
-   return mvpp22_rss_is_supported() ? MVPP22_RSS_TABLE_ENTRIES : 0;
+   struct mvpp2_port *port = netdev_priv(dev);
+
+   return mvpp22_rss_is_supported(port) ? MVPP22_RSS_TABLE_ENTRIES : 0;
 }
 
 static int mvpp2_ethtool_get_rxfh(struct net_device *dev, u32 *indir, u8 *key,
@@ -5578,7 +5581,7 @@ static int mvpp2_ethtool_get_rxfh(struct net_device *dev, 
u32 *indir, u8 *key,
struct mvpp2_port *port = netdev_priv(dev);
int ret = 0;
 
-   if (!mvpp22_rss_is_supported())
+   if (!mvpp22_rss_is_supported(port))
return -EOPNOTSUPP;
 
if (indir)
@@ -5596,7 +5599,7 @@ static int mvpp2_ethtool_set_rxfh(struct net_device *dev, 
const u32 *indir,
struct mvpp2_port *port = netdev_priv(dev);
int ret = 0;
 
-   if (!mvpp22_rss_is_supported())
+   if (!mvpp22_rss_is_supported(port))
return -EOPNOTSUPP;
 
if (hfunc != ETH_RSS_HASH_NO_CHANGE && hfunc != ETH_RSS_HASH_CRC32)
@@ -5617,7 +5620,7 @@ static int mvpp2_ethtool_get_rxfh_context(struct 
net_device *dev, u32 *indir,
struct mvpp2_port *port = netdev_priv(dev);
int ret = 0;
 
-   if (!mvpp22_rss_is_supported())
+   if (!mvpp22_rss_is_supported(port))
return -EOPNOTSUPP;
if (rss_context >= MVPP22_N_RSS_TABLES)
return -EINVAL;
@@ -5639,7 +5642,7 @@ static int mvpp2_ethtool_set_rxfh_context(struct 
net_device *dev,
struct mvpp2_port *port = netdev_priv(dev);
int ret;
 
-   if (!mvpp22_rss_is_supported())
+   if (!mvpp22_rss_is_supported(port))
return -EOPNOTSUPP;
 
if (hfunc != ETH_RSS_HASH_NO_CHANGE && hfunc != ETH_RSS_HASH_CRC32)
@@ -5956,7 +5959,7 @@ static int mvpp2_port_init(struct mvpp2_port *port)
mvpp2_cls_oversize_rxq_set(port);
mvpp2_cls_port_config(port);
 
-   if (mvpp22_rss_is_supported())
+   if (mvpp22_rss_is_supported(port))
mvpp22_port_rss_init(port);
 
/* Provide an initial Rx packet size */
@@ -6861,7 +6864,7 @@ static int mvpp2_port_probe(struct platform_device *pdev,
dev->hw_features |= features | NETIF_F_RXCSUM | NETIF_F_GRO |
NETIF_F_HW_VLAN_CTAG_FILTER;
 
-   if (mvpp22_rss_is_supported()) {
+   if (mvpp22_rss_is_supported(port)) {
dev->hw_features |= NETIF_F_RXHASH;
dev->features |= NETIF_F_NTUPLE;
}
-- 
1.9.1



[net-next] net: mvpp2: Add TX flow control support for jumbo frames

2021-02-15 Thread stefanc
From: Stefan Chulski 

With MTU less than 1500B on all ports, the driver uses per CPU pool mode.
If one of the ports set to jumbo frame MTU size, all ports move
to shared pools mode.
Here, buffer manager TX Flow Control reconfigured on all ports.

Signed-off-by: Stefan Chulski 
---
 drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c | 26 
 1 file changed, 26 insertions(+)

diff --git a/drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c 
b/drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c
index 222e9a3..10c17d1 100644
--- a/drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c
+++ b/drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c
@@ -924,6 +924,25 @@ static void mvpp2_bm_pool_update_fc(struct mvpp2_port 
*port,
spin_unlock_irqrestore(&port->priv->mss_spinlock, flags);
 }
 
+/* disable/enable flow control for BM pool on all ports */
+static void mvpp2_bm_pool_update_priv_fc(struct mvpp2 *priv, bool en)
+{
+   struct mvpp2_port *port;
+   int i;
+
+   for (i = 0; i < priv->port_count; i++) {
+   port = priv->port_list[i];
+   if (port->priv->percpu_pools) {
+   for (i = 0; i < port->nrxqs; i++)
+   mvpp2_bm_pool_update_fc(port, 
&port->priv->bm_pools[i],
+   port->tx_fc & en);
+   } else {
+   mvpp2_bm_pool_update_fc(port, port->pool_long, 
port->tx_fc & en);
+   mvpp2_bm_pool_update_fc(port, port->pool_short, 
port->tx_fc & en);
+   }
+   }
+}
+
 static int mvpp2_enable_global_fc(struct mvpp2 *priv)
 {
int val, timeout = 0;
@@ -4913,6 +4932,7 @@ static int mvpp2_set_mac_address(struct net_device *dev, 
void *p)
  */
 static int mvpp2_bm_switch_buffers(struct mvpp2 *priv, bool percpu)
 {
+   bool change_percpu = (percpu != priv->percpu_pools);
int numbufs = MVPP2_BM_POOLS_NUM, i;
struct mvpp2_port *port = NULL;
bool status[MVPP2_MAX_PORTS];
@@ -4928,6 +4948,9 @@ static int mvpp2_bm_switch_buffers(struct mvpp2 *priv, 
bool percpu)
if (priv->percpu_pools)
numbufs = port->nrxqs * 2;
 
+   if (change_percpu)
+   mvpp2_bm_pool_update_priv_fc(priv, false);
+
for (i = 0; i < numbufs; i++)
mvpp2_bm_pool_destroy(port->dev->dev.parent, priv, 
&priv->bm_pools[i]);
 
@@ -4942,6 +4965,9 @@ static int mvpp2_bm_switch_buffers(struct mvpp2 *priv, 
bool percpu)
mvpp2_open(port->dev);
}
 
+   if (change_percpu)
+   mvpp2_bm_pool_update_priv_fc(priv, true);
+
return 0;
 }
 
-- 
1.9.1



[net-next] net: mvpp2: reduce tx-fifo for loopback port

2021-02-14 Thread stefanc
From: Stefan Chulski 

1KB is enough for loopback port, so 2KB can be distributed
between other ports.

Signed-off-by: Stefan Chulski 
---
 drivers/net/ethernet/marvell/mvpp2/mvpp2.h  |  4 ++--
 drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c | 10 +-
 2 files changed, 7 insertions(+), 7 deletions(-)

diff --git a/drivers/net/ethernet/marvell/mvpp2/mvpp2.h 
b/drivers/net/ethernet/marvell/mvpp2/mvpp2.h
index 373ede3..8edba5e 100644
--- a/drivers/net/ethernet/marvell/mvpp2/mvpp2.h
+++ b/drivers/net/ethernet/marvell/mvpp2/mvpp2.h
@@ -763,9 +763,9 @@
 #define MVPP2_RX_FIFO_PORT_MIN_PKT 0x80
 
 /* TX FIFO constants */
-#define MVPP22_TX_FIFO_DATA_SIZE_16KB  16
+#define MVPP22_TX_FIFO_DATA_SIZE_18KB  18
 #define MVPP22_TX_FIFO_DATA_SIZE_10KB  10
-#define MVPP22_TX_FIFO_DATA_SIZE_3KB   3
+#define MVPP22_TX_FIFO_DATA_SIZE_1KB   1
 #define MVPP2_TX_FIFO_THRESHOLD_MIN256 /* Bytes */
 #define MVPP2_TX_FIFO_THRESHOLD(kb)\
((kb) * 1024 - MVPP2_TX_FIFO_THRESHOLD_MIN)
diff --git a/drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c 
b/drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c
index 9d56ea4..222e9a3 100644
--- a/drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c
+++ b/drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c
@@ -7093,8 +7093,8 @@ static void mvpp22_tx_fifo_set_hw(struct mvpp2 *priv, int 
port, int size)
 }
 
 /* Initialize TX FIFO's: the total FIFO size is 19kB on PPv2.2 and PPv2.3.
- * 3kB fixed space must be assigned for the loopback port.
- * Redistribute remaining avialable 16kB space among all active ports.
+ * 1kB fixed space must be assigned for the loopback port.
+ * Redistribute remaining avialable 18kB space among all active ports.
  * The 10G interface should use 10kB (which is maximum possible size
  * per single port).
  */
@@ -7105,9 +7105,9 @@ static void mvpp22_tx_fifo_init(struct mvpp2 *priv)
int size_remainder;
int port, size;
 
-   /* The loopback requires fixed 3kB of the FIFO space assignment. */
+   /* The loopback requires fixed 1kB of the FIFO space assignment. */
mvpp22_tx_fifo_set_hw(priv, MVPP2_LOOPBACK_PORT_INDEX,
- MVPP22_TX_FIFO_DATA_SIZE_3KB);
+ MVPP22_TX_FIFO_DATA_SIZE_1KB);
port_map = priv->port_map & ~BIT(MVPP2_LOOPBACK_PORT_INDEX);
 
/* Set TX FIFO size to 0 for inactive ports. */
@@ -7115,7 +7115,7 @@ static void mvpp22_tx_fifo_init(struct mvpp2 *priv)
mvpp22_tx_fifo_set_hw(priv, port, 0);
 
/* Assign remaining TX FIFO space among all active ports. */
-   size_remainder = MVPP22_TX_FIFO_DATA_SIZE_16KB;
+   size_remainder = MVPP22_TX_FIFO_DATA_SIZE_18KB;
remaining_ports_count = hweight_long(port_map);
 
for_each_set_bit(port, &port_map, MVPP2_LOOPBACK_PORT_INDEX) {
-- 
1.9.1



[net-next 2/4] net: mvpp2: improve Packet Processor version check

2021-02-14 Thread stefanc
From: Stefan Chulski 

Use >= MVPP22 instead of != MVPP21.
Non functional change.

Signed-off-by: Stefan Chulski 
---
 drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c | 36 ++--
 1 file changed, 18 insertions(+), 18 deletions(-)

diff --git a/drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c 
b/drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c
index 9127dc2..4e1a24c 100644
--- a/drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c
+++ b/drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c
@@ -329,7 +329,7 @@ static int mvpp2_get_nrxqs(struct mvpp2 *priv)
 {
unsigned int nrxqs;
 
-   if (priv->hw_version != MVPP21 && queue_mode == MVPP2_QDIST_SINGLE_MODE)
+   if (priv->hw_version >= MVPP22 && queue_mode == MVPP2_QDIST_SINGLE_MODE)
return 1;
 
/* According to the PPv2.2 datasheet and our experiments on
@@ -469,7 +469,7 @@ static void mvpp2_bm_bufs_get_addrs(struct device *dev, 
struct mvpp2 *priv,
  MVPP2_BM_PHY_ALLOC_REG(bm_pool->id));
*phys_addr = mvpp2_thread_read(priv, thread, MVPP2_BM_VIRT_ALLOC_REG);
 
-   if (priv->hw_version != MVPP21) {
+   if (priv->hw_version >= MVPP22) {
u32 val;
u32 dma_addr_highbits, phys_addr_highbits;
 
@@ -963,7 +963,7 @@ static inline void mvpp2_bm_pool_put(struct mvpp2_port 
*port, int pool,
if (test_bit(thread, &port->priv->lock_map))
spin_lock_irqsave(&port->bm_lock[thread], flags);
 
-   if (port->priv->hw_version != MVPP21) {
+   if (port->priv->hw_version >= MVPP22) {
u32 val = 0;
 
if (sizeof(dma_addr_t) == 8)
@@ -1462,7 +1462,7 @@ static bool mvpp2_port_supports_xlg(struct mvpp2_port 
*port)
 
 static bool mvpp2_port_supports_rgmii(struct mvpp2_port *port)
 {
-   return !(port->priv->hw_version != MVPP21 && port->gop_id == 0);
+   return !(port->priv->hw_version >= MVPP22 && port->gop_id == 0);
 }
 
 /* Port configuration routines */
@@ -2125,7 +2125,7 @@ static void mvpp2_mac_reset_assert(struct mvpp2_port 
*port)
  MVPP2_GMAC_PORT_RESET_MASK;
writel(val, port->base + MVPP2_GMAC_CTRL_2_REG);
 
-   if (port->priv->hw_version != MVPP21 && port->gop_id == 0) {
+   if (port->priv->hw_version >= MVPP22 && port->gop_id == 0) {
val = readl(port->base + MVPP22_XLG_CTRL0_REG) &
  ~MVPP22_XLG_CTRL0_MAC_RESET_DIS;
writel(val, port->base + MVPP22_XLG_CTRL0_REG);
@@ -4016,7 +4016,7 @@ static void mvpp2_txdesc_clear_ptp(struct mvpp2_port 
*port,
   struct mvpp2_tx_desc *desc)
 {
/* We only need to clear the low bits */
-   if (port->priv->hw_version != MVPP21)
+   if (port->priv->hw_version >= MVPP22)
desc->pp22.ptp_descriptor &=
cpu_to_le32(~MVPP22_PTP_DESC_MASK_LOW);
 }
@@ -4528,7 +4528,7 @@ static void mvpp2_start_dev(struct mvpp2_port *port)
/* Enable interrupts on all threads */
mvpp2_interrupts_enable(port);
 
-   if (port->priv->hw_version != MVPP21)
+   if (port->priv->hw_version >= MVPP22)
mvpp22_mode_reconfigure(port);
 
if (port->phylink) {
@@ -4746,7 +4746,7 @@ static int mvpp2_open(struct net_device *dev)
valid = true;
}
 
-   if (priv->hw_version != MVPP21 && port->port_irq) {
+   if (priv->hw_version >= MVPP22 && port->port_irq) {
err = request_irq(port->port_irq, mvpp2_port_isr, 0,
  dev->name, port);
if (err) {
@@ -6399,7 +6399,7 @@ static int mvpp2__mac_prepare(struct phylink_config 
*config, unsigned int mode,
 MVPP2_GMAC_PORT_RESET_MASK,
 MVPP2_GMAC_PORT_RESET_MASK);
 
-   if (port->priv->hw_version != MVPP21) {
+   if (port->priv->hw_version >= MVPP22) {
mvpp22_gop_mask_irq(port);
 
phy_power_off(port->comphy);
@@ -6453,7 +6453,7 @@ static int mvpp2_mac_finish(struct phylink_config 
*config, unsigned int mode,
 {
struct mvpp2_port *port = mvpp2_phylink_to_port(config);
 
-   if (port->priv->hw_version != MVPP21 &&
+   if (port->priv->hw_version >= MVPP22 &&
port->phy_interface != interface) {
port->phy_interface = interface;
 
@@ -7200,7 +7200,7 @@ static int mvpp2_init(struct platform_device *pdev, 
struct mvpp2 *priv)
if (dram_target_info)
mvpp2_conf_mbus_windows(dram_target_info, priv);
 
-   if (priv->hw_version != MVPP21)
+   if (priv->hw_version >= MVPP22)
mvpp2_axi_init(priv);
 
/* Disable HW PHY polling */
@@ -7350,7 +7350,7 @@ static int mvpp2_probe(struct platform_device *pdev)
priv->global_tx_fc = true;
}
 
-   if (priv->hw_version != MVPP21 && dev_of_node(&pdev->dev)) {
+   if (priv->

[net-next 3/4] net: mvpp2: improve mvpp2_get_sram return

2021-02-14 Thread stefanc
From: Stefan Chulski 

Use PTR_ERR_OR_ZERO instead of IS_ERR and PTR_ERR.
Non functional change.

Signed-off-by: Stefan Chulski 
---
 drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

diff --git a/drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c 
b/drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c
index 4e1a24c..bc98f52 100644
--- a/drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c
+++ b/drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c
@@ -7277,10 +7277,8 @@ static int mvpp2_get_sram(struct platform_device *pdev,
}
 
priv->cm3_base = devm_ioremap_resource(&pdev->dev, res);
-   if (IS_ERR(priv->cm3_base))
-   return PTR_ERR(priv->cm3_base);
 
-   return 0;
+   return PTR_ERR_OR_ZERO(priv->cm3_base);
 }
 
 static int mvpp2_probe(struct platform_device *pdev)
-- 
1.9.1



[net-next 4/4] net: mvpp2: improve Networking Complex Control register naming

2021-02-14 Thread stefanc
From: Stefan Chulski 

GENCONF_CTRL0_PORTX naming improved.
Non functional change.

Signed-off-by: Stefan Chulski 
---
 drivers/net/ethernet/marvell/mvpp2/mvpp2.h  | 6 +++---
 drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c | 8 
 2 files changed, 7 insertions(+), 7 deletions(-)

diff --git a/drivers/net/ethernet/marvell/mvpp2/mvpp2.h 
b/drivers/net/ethernet/marvell/mvpp2/mvpp2.h
index da87152..373ede3 100644
--- a/drivers/net/ethernet/marvell/mvpp2/mvpp2.h
+++ b/drivers/net/ethernet/marvell/mvpp2/mvpp2.h
@@ -673,9 +673,9 @@
 #define GENCONF_PORT_CTRL1_EN(p)   BIT(p)
 #define GENCONF_PORT_CTRL1_RESET(p)(BIT(p) << 28)
 #define GENCONF_CTRL0  0x1120
-#define GENCONF_CTRL0_PORT0_RGMII  BIT(0)
-#define GENCONF_CTRL0_PORT1_RGMII_MII  BIT(1)
-#define GENCONF_CTRL0_PORT1_RGMII  BIT(2)
+#define GENCONF_CTRL0_PORT2_RGMII  BIT(0)
+#define GENCONF_CTRL0_PORT3_RGMII_MII  BIT(1)
+#define GENCONF_CTRL0_PORT3_RGMII  BIT(2)
 
 /* Various constants */
 
diff --git a/drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c 
b/drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c
index bc98f52..d167cfd 100644
--- a/drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c
+++ b/drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c
@@ -1494,9 +1494,9 @@ static void mvpp22_gop_init_rgmii(struct mvpp2_port *port)
 
regmap_read(priv->sysctrl_base, GENCONF_CTRL0, &val);
if (port->gop_id == 2)
-   val |= GENCONF_CTRL0_PORT0_RGMII;
+   val |= GENCONF_CTRL0_PORT2_RGMII;
else if (port->gop_id == 3)
-   val |= GENCONF_CTRL0_PORT1_RGMII_MII;
+   val |= GENCONF_CTRL0_PORT3_RGMII_MII;
regmap_write(priv->sysctrl_base, GENCONF_CTRL0, val);
 }
 
@@ -1513,9 +1513,9 @@ static void mvpp22_gop_init_sgmii(struct mvpp2_port *port)
if (port->gop_id > 1) {
regmap_read(priv->sysctrl_base, GENCONF_CTRL0, &val);
if (port->gop_id == 2)
-   val &= ~GENCONF_CTRL0_PORT0_RGMII;
+   val &= ~GENCONF_CTRL0_PORT2_RGMII;
else if (port->gop_id == 3)
-   val &= ~GENCONF_CTRL0_PORT1_RGMII_MII;
+   val &= ~GENCONF_CTRL0_PORT3_RGMII_MII;
regmap_write(priv->sysctrl_base, GENCONF_CTRL0, val);
}
 }
-- 
1.9.1



[net-next 1/4] net: mvpp2: simplify PPv2 version ID read

2021-02-14 Thread stefanc
From: Stefan Chulski 

PPv2.1 contain 0 in Version ID register, priv->hw_version check
can be removed.

Signed-off-by: Stefan Chulski 
---
 drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c | 6 ++
 1 file changed, 2 insertions(+), 4 deletions(-)

diff --git a/drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c 
b/drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c
index e88272f..9127dc2 100644
--- a/drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c
+++ b/drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c
@@ -7469,10 +7469,8 @@ static int mvpp2_probe(struct platform_device *pdev)
priv->port_map |= BIT(i);
}
 
-   if (priv->hw_version != MVPP21) {
-   if (mvpp2_read(priv, MVPP2_VER_ID_REG) == MVPP2_VER_PP23)
-   priv->hw_version = MVPP23;
-   }
+   if (mvpp2_read(priv, MVPP2_VER_ID_REG) == MVPP2_VER_PP23)
+   priv->hw_version = MVPP23;
 
/* Init mss lock */
spin_lock_init(&priv->mss_spinlock);
-- 
1.9.1



[net-next 0/4] net: mvpp2: Minor non functional driver code improvements

2021-02-14 Thread stefanc
From: Stefan Chulski 

The patch series contains minor code improvements and did not change any 
functionality.

Stefan Chulski (4):
  net: mvpp2: simplify PPv2 version ID read
  net: mvpp2: improve Packet Processor version check
  net: mvpp2: improve mvpp2_get_sram return
  net: mvpp2: improve Networking Complex Control register naming

 drivers/net/ethernet/marvell/mvpp2/mvpp2.h  |  6 +--
 drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c | 52 +---
 2 files changed, 27 insertions(+), 31 deletions(-)

-- 
1.9.1



[net-next] net: mvpp2: fix interrupt mask/unmask skip condition

2021-02-11 Thread stefanc
From: Stefan Chulski 

The condition should be skipped if CPU ID equal to nthreads.
The patch doesn't fix any actual issue since
nthreads = min_t(unsigned int, num_present_cpus(), MVPP2_MAX_THREADS).
On all current Armada platforms, the number of CPU's is
less than MVPP2_MAX_THREADS.

Fixes: e531f76757eb ("net: mvpp2: handle cases where more CPUs are available 
than s/w threads")
Reported-by: Russell King 
Signed-off-by: Stefan Chulski 
---
 drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c 
b/drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c
index a07cf60..74613d3 100644
--- a/drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c
+++ b/drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c
@@ -1135,7 +1135,7 @@ static void mvpp2_interrupts_mask(void *arg)
struct mvpp2_port *port = arg;
 
/* If the thread isn't used, don't do anything */
-   if (smp_processor_id() > port->priv->nthreads)
+   if (smp_processor_id() >= port->priv->nthreads)
return;
 
mvpp2_thread_write(port->priv,
@@ -1153,7 +1153,7 @@ static void mvpp2_interrupts_unmask(void *arg)
u32 val;
 
/* If the thread isn't used, don't do anything */
-   if (smp_processor_id() > port->priv->nthreads)
+   if (smp_processor_id() >= port->priv->nthreads)
return;
 
val = MVPP2_CAUSE_MISC_SUM_MASK |
-- 
1.9.1



[PATCH v13 net-next 04/15] net: mvpp2: always compare hw-version vs MVPP21

2021-02-11 Thread stefanc
From: Stefan Chulski 

Currently we have PP2v1 and PP2v2 hw-versions, with some different
handlers depending upon condition hw_version = MVPP21/MVPP22.
In a future there will be also PP2v3. Let's use now the generic
"if equal/notEqual MVPP21" for all cases instead of "if MVPP22".

This patch does not change any functionality.
It is not intended to introduce PP2v3.
It just modifies MVPP21/MVPP22 check-condition
bringing it to generic and unified form correct for new-code
introducing and PP2v3 net-next generation.

Signed-off-by: Stefan Chulski 
Acked-by: Marcin Wojtas 
---
 drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c | 38 ++--
 1 file changed, 19 insertions(+), 19 deletions(-)

diff --git a/drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c 
b/drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c
index eec3796..17cd161 100644
--- a/drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c
+++ b/drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c
@@ -319,7 +319,7 @@ static int mvpp2_get_nrxqs(struct mvpp2 *priv)
 {
unsigned int nrxqs;
 
-   if (priv->hw_version == MVPP22 && queue_mode == MVPP2_QDIST_SINGLE_MODE)
+   if (priv->hw_version != MVPP21 && queue_mode == MVPP2_QDIST_SINGLE_MODE)
return 1;
 
/* According to the PPv2.2 datasheet and our experiments on
@@ -446,7 +446,7 @@ static void mvpp2_bm_bufs_get_addrs(struct device *dev, 
struct mvpp2 *priv,
  MVPP2_BM_PHY_ALLOC_REG(bm_pool->id));
*phys_addr = mvpp2_thread_read(priv, thread, MVPP2_BM_VIRT_ALLOC_REG);
 
-   if (priv->hw_version == MVPP22) {
+   if (priv->hw_version != MVPP21) {
u32 val;
u32 dma_addr_highbits, phys_addr_highbits;
 
@@ -742,7 +742,7 @@ static inline void mvpp2_bm_pool_put(struct mvpp2_port 
*port, int pool,
if (test_bit(thread, &port->priv->lock_map))
spin_lock_irqsave(&port->bm_lock[thread], flags);
 
-   if (port->priv->hw_version == MVPP22) {
+   if (port->priv->hw_version != MVPP21) {
u32 val = 0;
 
if (sizeof(dma_addr_t) == 8)
@@ -1172,7 +1172,7 @@ static void mvpp2_interrupts_unmask(void *arg)
u32 val;
int i;
 
-   if (port->priv->hw_version != MVPP22)
+   if (port->priv->hw_version == MVPP21)
return;
 
if (mask)
@@ -1199,7 +1199,7 @@ static bool mvpp2_port_supports_xlg(struct mvpp2_port 
*port)
 
 static bool mvpp2_port_supports_rgmii(struct mvpp2_port *port)
 {
-   return !(port->priv->hw_version == MVPP22 && port->gop_id == 0);
+   return !(port->priv->hw_version != MVPP21 && port->gop_id == 0);
 }
 
 /* Port configuration routines */
@@ -1817,7 +1817,7 @@ static void mvpp2_mac_reset_assert(struct mvpp2_port 
*port)
  MVPP2_GMAC_PORT_RESET_MASK;
writel(val, port->base + MVPP2_GMAC_CTRL_2_REG);
 
-   if (port->priv->hw_version == MVPP22 && port->gop_id == 0) {
+   if (port->priv->hw_version != MVPP21 && port->gop_id == 0) {
val = readl(port->base + MVPP22_XLG_CTRL0_REG) &
  ~MVPP22_XLG_CTRL0_MAC_RESET_DIS;
writel(val, port->base + MVPP22_XLG_CTRL0_REG);
@@ -1830,7 +1830,7 @@ static void mvpp22_pcs_reset_assert(struct mvpp2_port 
*port)
void __iomem *mpcs, *xpcs;
u32 val;
 
-   if (port->priv->hw_version != MVPP22 || port->gop_id != 0)
+   if (port->priv->hw_version == MVPP21 || port->gop_id != 0)
return;
 
mpcs = priv->iface_base + MVPP22_MPCS_BASE(port->gop_id);
@@ -1851,7 +1851,7 @@ static void mvpp22_pcs_reset_deassert(struct mvpp2_port 
*port)
void __iomem *mpcs, *xpcs;
u32 val;
 
-   if (port->priv->hw_version != MVPP22 || port->gop_id != 0)
+   if (port->priv->hw_version == MVPP21 || port->gop_id != 0)
return;
 
mpcs = priv->iface_base + MVPP22_MPCS_BASE(port->gop_id);
@@ -4188,7 +4188,7 @@ static void mvpp2_start_dev(struct mvpp2_port *port)
/* Enable interrupts on all threads */
mvpp2_interrupts_enable(port);
 
-   if (port->priv->hw_version == MVPP22)
+   if (port->priv->hw_version != MVPP21)
mvpp22_mode_reconfigure(port);
 
if (port->phylink) {
@@ -4404,7 +4404,7 @@ static int mvpp2_open(struct net_device *dev)
valid = true;
}
 
-   if (priv->hw_version == MVPP22 && port->port_irq) {
+   if (priv->hw_version != MVPP21 && port->port_irq) {
err = request_irq(port->port_irq, mvpp2_port_isr, 0,
  dev->name, port);
if (err) {
@@ -6052,7 +6052,7 @@ static int mvpp2__mac_prepare(struct phylink_config 
*config, unsigned int mode,
 MVPP2_GMAC_PORT_RESET_MASK,
 MVPP2_GMAC_PORT_RESET_MASK);
 
-   if (port->priv->hw_version == MVPP22) {
+   if (port->priv->hw_version != MVPP21) {
  

[PATCH v13 net-next 13/15] net: mvpp2: add PPv23 RX FIFO flow control

2021-02-11 Thread stefanc
From: Stefan Chulski 

New FIFO flow control feature was added in PPv23.
PPv2 FIFO polled by HW and trigger pause frame if FIFO
fill level is below threshold.
FIFO HW flow control enabled with CM3 RXQ&BM flow
control with ethtool.
Current  FIFO thresholds is:
9KB for port with maximum speed 10Gb/s port
4KB for port with maximum speed 5Gb/s port
2KB for port with maximum speed 1Gb/s port

Signed-off-by: Stefan Chulski 
Acked-by: Marcin Wojtas 
---
 drivers/net/ethernet/marvell/mvpp2/mvpp2.h  | 15 ++
 drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c | 53 
 2 files changed, 68 insertions(+)

diff --git a/drivers/net/ethernet/marvell/mvpp2/mvpp2.h 
b/drivers/net/ethernet/marvell/mvpp2/mvpp2.h
index 9b525b60..b61a1ba 100644
--- a/drivers/net/ethernet/marvell/mvpp2/mvpp2.h
+++ b/drivers/net/ethernet/marvell/mvpp2/mvpp2.h
@@ -770,6 +770,18 @@
 #define MVPP2_TX_FIFO_THRESHOLD(kb)\
((kb) * 1024 - MVPP2_TX_FIFO_THRESHOLD_MIN)
 
+/* RX FIFO threshold in 1KB granularity */
+#define MVPP23_PORT0_FIFO_TRSH (9 * 1024)
+#define MVPP23_PORT1_FIFO_TRSH (4 * 1024)
+#define MVPP23_PORT2_FIFO_TRSH (2 * 1024)
+
+/* RX Flow Control Registers */
+#define MVPP2_RX_FC_REG(port)  (0x150 + 4 * (port))
+#define MVPP2_RX_FC_EN BIT(24)
+#define MVPP2_RX_FC_TRSH_OFFS  16
+#define MVPP2_RX_FC_TRSH_MASK  (0xFF << MVPP2_RX_FC_TRSH_OFFS)
+#define MVPP2_RX_FC_TRSH_UNIT  256
+
 /* MSS Flow control */
 #define MSS_FC_COM_REG 0
 #define FLOW_CONTROL_ENABLE_BITBIT(0)
@@ -1498,6 +1510,8 @@ struct mvpp2_bm_pool {
 
 void mvpp2_dbgfs_cleanup(struct mvpp2 *priv);
 
+void mvpp23_rx_fifo_fc_en(struct mvpp2 *priv, int port, bool en);
+
 #ifdef CONFIG_MVPP2_PTP
 int mvpp22_tai_probe(struct device *dev, struct mvpp2 *priv);
 void mvpp22_tai_tstamp(struct mvpp2_tai *tai, u32 tstamp,
@@ -1530,4 +1544,5 @@ static inline bool mvpp22_rx_hwtstamping(struct 
mvpp2_port *port)
 {
return IS_ENABLED(CONFIG_MVPP2_PTP) && port->rx_hwtstamp;
 }
+
 #endif
diff --git a/drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c 
b/drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c
index 9226d2f..e646151 100644
--- a/drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c
+++ b/drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c
@@ -6529,6 +6529,8 @@ static void mvpp2_mac_link_up(struct phylink_config 
*config,
mvpp2_bm_pool_update_fc(port, port->pool_long, 
tx_pause);
mvpp2_bm_pool_update_fc(port, port->pool_short, 
tx_pause);
}
+   if (port->priv->hw_version == MVPP23)
+   mvpp23_rx_fifo_fc_en(port->priv, port->id, tx_pause);
}
 
mvpp2_port_enable(port);
@@ -6997,6 +6999,55 @@ static void mvpp22_rx_fifo_init(struct mvpp2 *priv)
mvpp2_write(priv, MVPP2_RX_FIFO_INIT_REG, 0x1);
 }
 
+/* Configure Rx FIFO Flow control thresholds */
+static void mvpp23_rx_fifo_fc_set_tresh(struct mvpp2 *priv)
+{
+   int port, val;
+
+   /* Port 0: maximum speed -10Gb/s port
+* required by spec RX FIFO threshold 9KB
+* Port 1: maximum speed -5Gb/s port
+* required by spec RX FIFO threshold 4KB
+* Port 2: maximum speed -1Gb/s port
+* required by spec RX FIFO threshold 2KB
+*/
+
+   /* Without loopback port */
+   for (port = 0; port < (MVPP2_MAX_PORTS - 1); port++) {
+   if (port == 0) {
+   val = (MVPP23_PORT0_FIFO_TRSH / MVPP2_RX_FC_TRSH_UNIT)
+   << MVPP2_RX_FC_TRSH_OFFS;
+   val &= MVPP2_RX_FC_TRSH_MASK;
+   mvpp2_write(priv, MVPP2_RX_FC_REG(port), val);
+   } else if (port == 1) {
+   val = (MVPP23_PORT1_FIFO_TRSH / MVPP2_RX_FC_TRSH_UNIT)
+   << MVPP2_RX_FC_TRSH_OFFS;
+   val &= MVPP2_RX_FC_TRSH_MASK;
+   mvpp2_write(priv, MVPP2_RX_FC_REG(port), val);
+   } else {
+   val = (MVPP23_PORT2_FIFO_TRSH / MVPP2_RX_FC_TRSH_UNIT)
+   << MVPP2_RX_FC_TRSH_OFFS;
+   val &= MVPP2_RX_FC_TRSH_MASK;
+   mvpp2_write(priv, MVPP2_RX_FC_REG(port), val);
+   }
+   }
+}
+
+/* Configure Rx FIFO Flow control thresholds */
+void mvpp23_rx_fifo_fc_en(struct mvpp2 *priv, int port, bool en)
+{
+   int val;
+
+   val = mvpp2_read(priv, MVPP2_RX_FC_REG(port));
+
+   if (en)
+   val |= MVPP2_RX_FC_EN;
+   else
+   val &= ~MVPP2_RX_FC_EN;
+
+   mvpp2_write(priv, MVPP2_RX_FC_REG(port), val);
+}
+
 static void mvpp22_tx_fifo_set_hw(struct mvpp2 *priv, int port, int size)
 {
int threshold = MVPP2_TX_FIFO_THRESHOLD(size);
@@ -7148,6 +7199,8 @@ static int mvpp2_init(struct platform_device *pdev, 
struct mvpp2 *priv)
} else {
mvp

[PATCH v13 net-next 10/15] net: mvpp2: add RXQ flow control configurations

2021-02-11 Thread stefanc
From: Stefan Chulski 

This patch adds RXQ flow control configurations.
Flow control disabled by default.
Minimum ring size limited to 1024 descriptors.

Signed-off-by: Stefan Chulski 
Acked-by: Marcin Wojtas 
---
 drivers/net/ethernet/marvell/mvpp2/mvpp2.h  |  35 +-
 drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c | 116 
 2 files changed, 150 insertions(+), 1 deletion(-)

diff --git a/drivers/net/ethernet/marvell/mvpp2/mvpp2.h 
b/drivers/net/ethernet/marvell/mvpp2/mvpp2.h
index 8945fb9..0010a3e9 100644
--- a/drivers/net/ethernet/marvell/mvpp2/mvpp2.h
+++ b/drivers/net/ethernet/marvell/mvpp2/mvpp2.h
@@ -765,9 +765,36 @@
 /* MSS Flow control */
 #define MSS_FC_COM_REG 0
 #define FLOW_CONTROL_ENABLE_BITBIT(0)
+#define FLOW_CONTROL_UPDATE_COMMAND_BITBIT(31)
 #define FC_QUANTA  0x
 #define FC_CLK_DIVIDER 100
-#define MSS_THRESHOLD_STOP 768
+
+#define MSS_RXQ_TRESH_BASE 0x200
+#define MSS_RXQ_TRESH_OFFS 4
+#define MSS_RXQ_TRESH_REG(q, fq)   (MSS_RXQ_TRESH_BASE + (((q) + (fq)) \
+   * MSS_RXQ_TRESH_OFFS))
+
+#define MSS_RXQ_TRESH_START_MASK   0x
+#define MSS_RXQ_TRESH_STOP_MASK(0x << 
MSS_RXQ_TRESH_STOP_OFFS)
+#define MSS_RXQ_TRESH_STOP_OFFS16
+
+#define MSS_RXQ_ASS_BASE   0x80
+#define MSS_RXQ_ASS_OFFS   4
+#define MSS_RXQ_ASS_PER_REG4
+#define MSS_RXQ_ASS_PER_OFFS   8
+#define MSS_RXQ_ASS_PORTID_OFFS0
+#define MSS_RXQ_ASS_PORTID_MASK0x3
+#define MSS_RXQ_ASS_HOSTID_OFFS2
+#define MSS_RXQ_ASS_HOSTID_MASK0x3F
+
+#define MSS_RXQ_ASS_Q_BASE(q, fq) q) + (fq)) % MSS_RXQ_ASS_PER_REG)
 \
+ * MSS_RXQ_ASS_PER_OFFS)
+#define MSS_RXQ_ASS_PQ_BASE(q, fq) q) + (fq)) / MSS_RXQ_ASS_PER_REG) \
+  * MSS_RXQ_ASS_OFFS)
+#define MSS_RXQ_ASS_REG(q, fq) (MSS_RXQ_ASS_BASE + MSS_RXQ_ASS_PQ_BASE(q, fq))
+
+#define MSS_THRESHOLD_STOP 768
+#define MSS_THRESHOLD_START1024
 
 /* RX buffer constants */
 #define MVPP2_SKB_SHINFO_SIZE \
@@ -1022,6 +1049,9 @@ struct mvpp2 {
 
/* Global TX Flow Control config */
bool global_tx_fc;
+
+   /* Spinlocks for CM3 shared memory configuration */
+   spinlock_t mss_spinlock;
 };
 
 struct mvpp2_pcpu_stats {
@@ -1184,6 +1214,9 @@ struct mvpp2_port {
bool rx_hwtstamp;
enum hwtstamp_tx_types tx_hwtstamp_type;
struct mvpp2_hwtstamp_queue tx_hwtstamp_queue[2];
+
+   /* Firmware TX flow control */
+   bool tx_fc;
 };
 
 /* The mvpp2_tx_desc and mvpp2_rx_desc structures describe the
diff --git a/drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c 
b/drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c
index 027101b..f1770e5 100644
--- a/drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c
+++ b/drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c
@@ -741,6 +741,110 @@ static void *mvpp2_buf_alloc(struct mvpp2_port *port,
return data;
 }
 
+/* Routine enable flow control for RXQs condition */
+static void mvpp2_rxq_enable_fc(struct mvpp2_port *port)
+{
+   int val, cm3_state, host_id, q;
+   int fq = port->first_rxq;
+   unsigned long flags;
+
+   spin_lock_irqsave(&port->priv->mss_spinlock, flags);
+
+   /* Remove Flow control enable bit to prevent race between FW and Kernel
+* If Flow control was enabled, it would be re-enabled.
+*/
+   val = mvpp2_cm3_read(port->priv, MSS_FC_COM_REG);
+   cm3_state = (val & FLOW_CONTROL_ENABLE_BIT);
+   val &= ~FLOW_CONTROL_ENABLE_BIT;
+   mvpp2_cm3_write(port->priv, MSS_FC_COM_REG, val);
+
+   /* Set same Flow control for all RXQs */
+   for (q = 0; q < port->nrxqs; q++) {
+   /* Set stop and start Flow control RXQ thresholds */
+   val = MSS_THRESHOLD_START;
+   val |= (MSS_THRESHOLD_STOP << MSS_RXQ_TRESH_STOP_OFFS);
+   mvpp2_cm3_write(port->priv, MSS_RXQ_TRESH_REG(q, fq), val);
+
+   val = mvpp2_cm3_read(port->priv, MSS_RXQ_ASS_REG(q, fq));
+   /* Set RXQ port ID */
+   val &= ~(MSS_RXQ_ASS_PORTID_MASK << MSS_RXQ_ASS_Q_BASE(q, fq));
+   val |= (port->id << MSS_RXQ_ASS_Q_BASE(q, fq));
+   val &= ~(MSS_RXQ_ASS_HOSTID_MASK << (MSS_RXQ_ASS_Q_BASE(q, fq)
+   + MSS_RXQ_ASS_HOSTID_OFFS));
+
+   /* Calculate RXQ host ID:
+* In Single queue mode: Host ID equal to Host ID used for
+*   shared RX interrupt
+* In Multi queue mode: Host ID equal to number of
+*  RXQ ID / number of CoS queues
+* In Single resource mode: Host ID always equal to 0
+*/
+   if (queue_mode == MVPP2_QDIST_SINGLE_MODE)
+   host_id = port->nqvecs;
+

[PATCH v13 net-next 12/15] net: mvpp2: add BM protection underrun feature support

2021-02-11 Thread stefanc
From: Stefan Chulski 

The PP2v23 hardware supports a feature allowing to double the
size of BPPI by decreasing number of pools from 16 to 8.
Increasing of BPPI size protect BM drop from BPPI underrun.
Underrun could occurred due to stress on DDR and as result slow buffer
transition from BPPE to BPPI.
New BPPI threshold recommended by spec is:
BPPI low threshold - 640 buffers
BPPI high threshold - 832 buffers
Supported only in PPv23.

Signed-off-by: Stefan Chulski 
Acked-by: Marcin Wojtas 
---
 drivers/net/ethernet/marvell/mvpp2/mvpp2.h  |  8 ++
 drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c | 26 
 2 files changed, 34 insertions(+)

diff --git a/drivers/net/ethernet/marvell/mvpp2/mvpp2.h 
b/drivers/net/ethernet/marvell/mvpp2/mvpp2.h
index 0731dc7..9b525b60 100644
--- a/drivers/net/ethernet/marvell/mvpp2/mvpp2.h
+++ b/drivers/net/ethernet/marvell/mvpp2/mvpp2.h
@@ -324,6 +324,10 @@
 #define MVPP2_BM_HIGH_THRESH_MASK  0x7f
 #define MVPP2_BM_HIGH_THRESH_VALUE(val)((val) << \
MVPP2_BM_HIGH_THRESH_OFFS)
+#define MVPP2_BM_BPPI_HIGH_THRESH  0x1E
+#define MVPP2_BM_BPPI_LOW_THRESH   0x1C
+#define MVPP23_BM_BPPI_HIGH_THRESH 0x34
+#define MVPP23_BM_BPPI_LOW_THRESH  0x28
 #define MVPP2_BM_INTR_CAUSE_REG(pool)  (0x6240 + ((pool) * 4))
 #define MVPP2_BM_RELEASED_DELAY_MASK   BIT(0)
 #define MVPP2_BM_ALLOC_FAILED_MASK BIT(1)
@@ -352,6 +356,10 @@
 #define MVPP2_OVERRUN_ETH_DROP 0x7000
 #define MVPP2_CLS_ETH_DROP 0x7020
 
+#define MVPP22_BM_POOL_BASE_ADDR_HIGH_REG  0x6310
+#define MVPP22_BM_POOL_BASE_ADDR_HIGH_MASK 0xff
+#define MVPP23_BM_8POOL_MODE   BIT(8)
+
 /* Hit counters registers */
 #define MVPP2_CTRS_IDX 0x7040
 #define MVPP22_CTRS_TX_CTR(port, txq)  ((txq) | ((port) << 3) | BIT(7))
diff --git a/drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c 
b/drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c
index 90c9265..9226d2f 100644
--- a/drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c
+++ b/drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c
@@ -423,6 +423,19 @@ static int mvpp2_bm_pool_create(struct device *dev, struct 
mvpp2 *priv,
 
val = mvpp2_read(priv, MVPP2_BM_POOL_CTRL_REG(bm_pool->id));
val |= MVPP2_BM_START_MASK;
+
+   val &= ~MVPP2_BM_LOW_THRESH_MASK;
+   val &= ~MVPP2_BM_HIGH_THRESH_MASK;
+
+   /* Set 8 Pools BPPI threshold for MVPP23 */
+   if (priv->hw_version == MVPP23) {
+   val |= MVPP2_BM_LOW_THRESH_VALUE(MVPP23_BM_BPPI_LOW_THRESH);
+   val |= MVPP2_BM_HIGH_THRESH_VALUE(MVPP23_BM_BPPI_HIGH_THRESH);
+   } else {
+   val |= MVPP2_BM_LOW_THRESH_VALUE(MVPP2_BM_BPPI_LOW_THRESH);
+   val |= MVPP2_BM_HIGH_THRESH_VALUE(MVPP2_BM_BPPI_HIGH_THRESH);
+   }
+
mvpp2_write(priv, MVPP2_BM_POOL_CTRL_REG(bm_pool->id), val);
 
bm_pool->size = size;
@@ -591,6 +604,16 @@ static int mvpp2_bm_pools_init(struct device *dev, struct 
mvpp2 *priv)
return err;
 }
 
+/* Routine enable PPv23 8 pool mode */
+static void mvpp23_bm_set_8pool_mode(struct mvpp2 *priv)
+{
+   int val;
+
+   val = mvpp2_read(priv, MVPP22_BM_POOL_BASE_ADDR_HIGH_REG);
+   val |= MVPP23_BM_8POOL_MODE;
+   mvpp2_write(priv, MVPP22_BM_POOL_BASE_ADDR_HIGH_REG, val);
+}
+
 static int mvpp2_bm_init(struct device *dev, struct mvpp2 *priv)
 {
enum dma_data_direction dma_dir = DMA_FROM_DEVICE;
@@ -644,6 +667,9 @@ static int mvpp2_bm_init(struct device *dev, struct mvpp2 
*priv)
if (!priv->bm_pools)
return -ENOMEM;
 
+   if (priv->hw_version == MVPP23)
+   mvpp23_bm_set_8pool_mode(priv);
+
err = mvpp2_bm_pools_init(dev, priv);
if (err < 0)
return err;
-- 
1.9.1



[PATCH v13 net-next 15/15] net: mvpp2: add TX FC firmware check

2021-02-11 Thread stefanc
From: Stefan Chulski 

Patch check that TX FC firmware is running in CM3.
If not, global TX FC would be disabled.

Signed-off-by: Stefan Chulski 
Acked-by: Marcin Wojtas 
---
 drivers/net/ethernet/marvell/mvpp2/mvpp2.h  |  1 +
 drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c | 39 
 2 files changed, 33 insertions(+), 7 deletions(-)

diff --git a/drivers/net/ethernet/marvell/mvpp2/mvpp2.h 
b/drivers/net/ethernet/marvell/mvpp2/mvpp2.h
index b61a1ba..da87152 100644
--- a/drivers/net/ethernet/marvell/mvpp2/mvpp2.h
+++ b/drivers/net/ethernet/marvell/mvpp2/mvpp2.h
@@ -828,6 +828,7 @@
 
 #define MSS_THRESHOLD_STOP 768
 #define MSS_THRESHOLD_START1024
+#define MSS_FC_MAX_TIMEOUT 5000
 
 /* RX buffer constants */
 #define MVPP2_SKB_SHINFO_SIZE \
diff --git a/drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c 
b/drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c
index 883d742..4ff195a 100644
--- a/drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c
+++ b/drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c
@@ -924,6 +924,34 @@ static void mvpp2_bm_pool_update_fc(struct mvpp2_port 
*port,
spin_unlock_irqrestore(&port->priv->mss_spinlock, flags);
 }
 
+static int mvpp2_enable_global_fc(struct mvpp2 *priv)
+{
+   int val, timeout = 0;
+
+   /* Enable global flow control. In this stage global
+* flow control enabled, but still disabled per port.
+*/
+   val = mvpp2_cm3_read(priv, MSS_FC_COM_REG);
+   val |= FLOW_CONTROL_ENABLE_BIT;
+   mvpp2_cm3_write(priv, MSS_FC_COM_REG, val);
+
+   /* Check if Firmware running and disable FC if not*/
+   val |= FLOW_CONTROL_UPDATE_COMMAND_BIT;
+   mvpp2_cm3_write(priv, MSS_FC_COM_REG, val);
+
+   while (timeout < MSS_FC_MAX_TIMEOUT) {
+   val = mvpp2_cm3_read(priv, MSS_FC_COM_REG);
+
+   if (!(val & FLOW_CONTROL_UPDATE_COMMAND_BIT))
+   return 0;
+   usleep_range(10, 20);
+   timeout++;
+   }
+
+   priv->global_tx_fc = false;
+   return -EOPNOTSUPP;
+}
+
 /* Release buffer to BM */
 static inline void mvpp2_bm_pool_put(struct mvpp2_port *port, int pool,
 dma_addr_t buf_dma_addr,
@@ -7256,7 +7284,7 @@ static int mvpp2_probe(struct platform_device *pdev)
struct resource *res;
void __iomem *base;
int i, shared;
-   int err, val;
+   int err;
 
priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL);
if (!priv)
@@ -7480,13 +7508,10 @@ static int mvpp2_probe(struct platform_device *pdev)
goto err_port_probe;
}
 
-   /* Enable global flow control. In this stage global
-* flow control enabled, but still disabled per port.
-*/
if (priv->global_tx_fc && priv->hw_version != MVPP21) {
-   val = mvpp2_cm3_read(priv, MSS_FC_COM_REG);
-   val |= FLOW_CONTROL_ENABLE_BIT;
-   mvpp2_cm3_write(priv, MSS_FC_COM_REG, val);
+   err = mvpp2_enable_global_fc(priv);
+   if (err)
+   dev_warn(&pdev->dev, "Minimum of CM3 firmware 18.09 and 
chip revision B0 required for flow control\n");
}
 
mvpp2_dbgfs_init(priv, pdev->name);
-- 
1.9.1



[PATCH v13 net-next 14/15] net: mvpp2: set 802.3x GoP Flow Control mode

2021-02-11 Thread stefanc
From: Stefan Chulski 

This patch fix GMAC TX flow control autoneg.
Flow control autoneg wrongly were disabled with enabled TX
flow control.

Signed-off-by: Stefan Chulski 
Acked-by: Marcin Wojtas 
---
 drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c 
b/drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c
index e646151..883d742 100644
--- a/drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c
+++ b/drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c
@@ -6276,7 +6276,7 @@ static void mvpp2_gmac_config(struct mvpp2_port *port, 
unsigned int mode,
old_ctrl4 = ctrl4 = readl(port->base + MVPP22_GMAC_CTRL_4_REG);
 
ctrl0 &= ~MVPP2_GMAC_PORT_TYPE_MASK;
-   ctrl2 &= ~(MVPP2_GMAC_INBAND_AN_MASK | MVPP2_GMAC_PCS_ENABLE_MASK);
+   ctrl2 &= ~(MVPP2_GMAC_INBAND_AN_MASK | MVPP2_GMAC_PCS_ENABLE_MASK | 
MVPP2_GMAC_FLOW_CTRL_MASK);
 
/* Configure port type */
if (phy_interface_mode_is_8023z(state->interface)) {
-- 
1.9.1



[PATCH v13 net-next 11/15] net: mvpp2: add ethtool flow control configuration support

2021-02-11 Thread stefanc
From: Stefan Chulski 

This patch add ethtool flow control configuration support.

Tx flow control retrieved correctly by ethtool get function.
FW per port ethtool configuration capability added.

Patch also takes care about mtu change procedure, if PPv2 switch
BM pools during mtu change.

Signed-off-by: Stefan Chulski 
Acked-by: Marcin Wojtas 
---
 drivers/net/ethernet/marvell/mvpp2/mvpp2.h  | 13 +++
 drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c | 98 
 2 files changed, 111 insertions(+)

diff --git a/drivers/net/ethernet/marvell/mvpp2/mvpp2.h 
b/drivers/net/ethernet/marvell/mvpp2/mvpp2.h
index 0010a3e9..0731dc7 100644
--- a/drivers/net/ethernet/marvell/mvpp2/mvpp2.h
+++ b/drivers/net/ethernet/marvell/mvpp2/mvpp2.h
@@ -774,6 +774,19 @@
 #define MSS_RXQ_TRESH_REG(q, fq)   (MSS_RXQ_TRESH_BASE + (((q) + (fq)) \
* MSS_RXQ_TRESH_OFFS))
 
+#define MSS_BUF_POOL_BASE  0x40
+#define MSS_BUF_POOL_OFFS  4
+#define MSS_BUF_POOL_REG(id)   (MSS_BUF_POOL_BASE  \
+   + (id) * MSS_BUF_POOL_OFFS)
+
+#define MSS_BUF_POOL_STOP_MASK 0xFFF
+#define MSS_BUF_POOL_START_MASK(0xFFF << 
MSS_BUF_POOL_START_OFFS)
+#define MSS_BUF_POOL_START_OFFS12
+#define MSS_BUF_POOL_PORTS_MASK(0xF << MSS_BUF_POOL_PORTS_OFFS)
+#define MSS_BUF_POOL_PORTS_OFFS24
+#define MSS_BUF_POOL_PORT_OFFS(id) (0x1 << \
+   ((id) + MSS_BUF_POOL_PORTS_OFFS))
+
 #define MSS_RXQ_TRESH_START_MASK   0x
 #define MSS_RXQ_TRESH_STOP_MASK(0x << 
MSS_RXQ_TRESH_STOP_OFFS)
 #define MSS_RXQ_TRESH_STOP_OFFS16
diff --git a/drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c 
b/drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c
index f1770e5..90c9265 100644
--- a/drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c
+++ b/drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c
@@ -845,6 +845,59 @@ static void mvpp2_rxq_disable_fc(struct mvpp2_port *port)
spin_unlock_irqrestore(&port->priv->mss_spinlock, flags);
 }
 
+/* Routine disable/enable flow control for BM pool condition */
+static void mvpp2_bm_pool_update_fc(struct mvpp2_port *port,
+   struct mvpp2_bm_pool *pool,
+   bool en)
+{
+   int val, cm3_state;
+   unsigned long flags;
+
+   spin_lock_irqsave(&port->priv->mss_spinlock, flags);
+
+   /* Remove Flow control enable bit to prevent race between FW and Kernel
+* If Flow control were enabled, it would be re-enabled.
+*/
+   val = mvpp2_cm3_read(port->priv, MSS_FC_COM_REG);
+   cm3_state = (val & FLOW_CONTROL_ENABLE_BIT);
+   val &= ~FLOW_CONTROL_ENABLE_BIT;
+   mvpp2_cm3_write(port->priv, MSS_FC_COM_REG, val);
+
+   /* Check if BM pool should be enabled/disable */
+   if (en) {
+   /* Set BM pool start and stop thresholds per port */
+   val = mvpp2_cm3_read(port->priv, MSS_BUF_POOL_REG(pool->id));
+   val |= MSS_BUF_POOL_PORT_OFFS(port->id);
+   val &= ~MSS_BUF_POOL_START_MASK;
+   val |= (MSS_THRESHOLD_START << MSS_BUF_POOL_START_OFFS);
+   val &= ~MSS_BUF_POOL_STOP_MASK;
+   val |= MSS_THRESHOLD_STOP;
+   mvpp2_cm3_write(port->priv, MSS_BUF_POOL_REG(pool->id), val);
+   } else {
+   /* Remove BM pool from the port */
+   val = mvpp2_cm3_read(port->priv, MSS_BUF_POOL_REG(pool->id));
+   val &= ~MSS_BUF_POOL_PORT_OFFS(port->id);
+
+   /* Zero BM pool start and stop thresholds to disable pool
+* flow control if pool empty (not used by any port)
+*/
+   if (!pool->buf_num) {
+   val &= ~MSS_BUF_POOL_START_MASK;
+   val &= ~MSS_BUF_POOL_STOP_MASK;
+   }
+
+   mvpp2_cm3_write(port->priv, MSS_BUF_POOL_REG(pool->id), val);
+   }
+
+   /* Notify Firmware that Flow control config space ready for update */
+   val = mvpp2_cm3_read(port->priv, MSS_FC_COM_REG);
+   val |= FLOW_CONTROL_UPDATE_COMMAND_BIT;
+   val |= cm3_state;
+   mvpp2_cm3_write(port->priv, MSS_FC_COM_REG, val);
+
+   spin_unlock_irqrestore(&port->priv->mss_spinlock, flags);
+}
+
 /* Release buffer to BM */
 static inline void mvpp2_bm_pool_put(struct mvpp2_port *port, int pool,
 dma_addr_t buf_dma_addr,
@@ -1175,6 +1228,16 @@ static int mvpp2_bm_update_mtu(struct net_device *dev, 
int mtu)
new_long_pool = MVPP2_BM_LONG;
 
if (new_long_pool != port->pool_long->id) {
+   if (port->tx_fc) {
+   if (pkt_size > MVPP2_BM_LONG_PKT_SIZE)
+   mvpp2_bm_pool_update_fc(port,
+  

[PATCH v13 net-next 09/15] net: mvpp2: enable global flow control

2021-02-11 Thread stefanc
From: Stefan Chulski 

This patch enables global flow control in FW and in the phylink validate mask.

Signed-off-by: Stefan Chulski 
Acked-by: Marcin Wojtas 
---
 drivers/net/ethernet/marvell/mvpp2/mvpp2.h  | 11 +--
 drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c | 30 +++-
 2 files changed, 37 insertions(+), 4 deletions(-)

diff --git a/drivers/net/ethernet/marvell/mvpp2/mvpp2.h 
b/drivers/net/ethernet/marvell/mvpp2/mvpp2.h
index d2cc513c..8945fb9 100644
--- a/drivers/net/ethernet/marvell/mvpp2/mvpp2.h
+++ b/drivers/net/ethernet/marvell/mvpp2/mvpp2.h
@@ -763,9 +763,11 @@
((kb) * 1024 - MVPP2_TX_FIFO_THRESHOLD_MIN)
 
 /* MSS Flow control */
-#define FC_QUANTA  0x
-#define FC_CLK_DIVIDER 100
-#define MSS_THRESHOLD_STOP 768
+#define MSS_FC_COM_REG 0
+#define FLOW_CONTROL_ENABLE_BITBIT(0)
+#define FC_QUANTA  0x
+#define FC_CLK_DIVIDER 100
+#define MSS_THRESHOLD_STOP 768
 
 /* RX buffer constants */
 #define MVPP2_SKB_SHINFO_SIZE \
@@ -1017,6 +1019,9 @@ struct mvpp2 {
 
/* page_pool allocator */
struct page_pool *page_pool[MVPP2_PORT_MAX_RXQ];
+
+   /* Global TX Flow Control config */
+   bool global_tx_fc;
 };
 
 struct mvpp2_pcpu_stats {
diff --git a/drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c 
b/drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c
index 8b4073c..027101b 100644
--- a/drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c
+++ b/drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c
@@ -91,6 +91,16 @@ static inline u32 mvpp2_cpu_to_thread(struct mvpp2 *priv, 
int cpu)
return cpu % priv->nthreads;
 }
 
+static void mvpp2_cm3_write(struct mvpp2 *priv, u32 offset, u32 data)
+{
+   writel(data, priv->cm3_base + offset);
+}
+
+static u32 mvpp2_cm3_read(struct mvpp2 *priv, u32 offset)
+{
+   return readl(priv->cm3_base + offset);
+}
+
 static struct page_pool *
 mvpp2_create_page_pool(struct device *dev, int num, int len,
   enum dma_data_direction dma_dir)
@@ -5950,6 +5960,11 @@ static void mvpp2_phylink_validate(struct phylink_config 
*config,
phylink_set(mask, Autoneg);
phylink_set_port_modes(mask);
 
+   if (port->priv->global_tx_fc) {
+   phylink_set(mask, Pause);
+   phylink_set(mask, Asym_Pause);
+   }
+
switch (state->interface) {
case PHY_INTERFACE_MODE_10GBASER:
case PHY_INTERFACE_MODE_XAUI:
@@ -6951,7 +6966,7 @@ static int mvpp2_probe(struct platform_device *pdev)
struct resource *res;
void __iomem *base;
int i, shared;
-   int err;
+   int err, val;
 
priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL);
if (!priv)
@@ -7003,6 +7018,10 @@ static int mvpp2_probe(struct platform_device *pdev)
err = mvpp2_get_sram(pdev, priv);
if (err)
dev_warn(&pdev->dev, "Fail to alloc CM3 SRAM\n");
+
+   /* Enable global Flow Control only if handler to SRAM not NULL 
*/
+   if (priv->cm3_base)
+   priv->global_tx_fc = true;
}
 
if (priv->hw_version != MVPP21 && dev_of_node(&pdev->dev)) {
@@ -7168,6 +7187,15 @@ static int mvpp2_probe(struct platform_device *pdev)
goto err_port_probe;
}
 
+   /* Enable global flow control. In this stage global
+* flow control enabled, but still disabled per port.
+*/
+   if (priv->global_tx_fc && priv->hw_version != MVPP21) {
+   val = mvpp2_cm3_read(priv, MSS_FC_COM_REG);
+   val |= FLOW_CONTROL_ENABLE_BIT;
+   mvpp2_cm3_write(priv, MSS_FC_COM_REG, val);
+   }
+
mvpp2_dbgfs_init(priv, pdev->name);
 
platform_set_drvdata(pdev, priv);
-- 
1.9.1



[PATCH v13 net-next 08/15] net: mvpp2: add FCA RXQ non occupied descriptor threshold

2021-02-11 Thread stefanc
From: Stefan Chulski 

The firmware needs to monitor the RX Non-occupied descriptor
bits for flow control to move to XOFF mode.
These bits need to be unmasked to be functional, but they will
not raise interrupts as we leave the RX exception summary
bit in MVPP2_ISR_RX_TX_MASK_REG clear.

Signed-off-by: Stefan Chulski 
Acked-by: Marcin Wojtas 
---
 drivers/net/ethernet/marvell/mvpp2/mvpp2.h  |  3 ++
 drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c | 44 
 2 files changed, 40 insertions(+), 7 deletions(-)

diff --git a/drivers/net/ethernet/marvell/mvpp2/mvpp2.h 
b/drivers/net/ethernet/marvell/mvpp2/mvpp2.h
index 9239d80..d2cc513c 100644
--- a/drivers/net/ethernet/marvell/mvpp2/mvpp2.h
+++ b/drivers/net/ethernet/marvell/mvpp2/mvpp2.h
@@ -295,6 +295,8 @@
 #define MVPP2_PON_CAUSE_TXP_OCCUP_DESC_ALL_MASK0x3fc0
 #define MVPP2_PON_CAUSE_MISC_SUM_MASK  BIT(31)
 #define MVPP2_ISR_MISC_CAUSE_REG   0x55b0
+#define MVPP2_ISR_RX_ERR_CAUSE_REG(port)   (0x5520 + 4 * (port))
+#define MVPP2_ISR_RX_ERR_CAUSE_NONOCC_MASK 0x00ff
 
 /* Buffer Manager registers */
 #define MVPP2_BM_POOL_BASE_REG(pool)   (0x6000 + ((pool) * 4))
@@ -763,6 +765,7 @@
 /* MSS Flow control */
 #define FC_QUANTA  0x
 #define FC_CLK_DIVIDER 100
+#define MSS_THRESHOLD_STOP 768
 
 /* RX buffer constants */
 #define MVPP2_SKB_SHINFO_SIZE \
diff --git a/drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c 
b/drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c
index 761f745..8b4073c 100644
--- a/drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c
+++ b/drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c
@@ -1133,14 +1133,19 @@ static inline void mvpp2_qvec_interrupt_disable(struct 
mvpp2_queue_vector *qvec)
 static void mvpp2_interrupts_mask(void *arg)
 {
struct mvpp2_port *port = arg;
+   int cpu = smp_processor_id();
+   u32 thread;
 
/* If the thread isn't used, don't do anything */
-   if (smp_processor_id() > port->priv->nthreads)
+   if (cpu > port->priv->nthreads)
return;
 
-   mvpp2_thread_write(port->priv,
-  mvpp2_cpu_to_thread(port->priv, smp_processor_id()),
+   thread = mvpp2_cpu_to_thread(port->priv, cpu);
+
+   mvpp2_thread_write(port->priv, thread,
   MVPP2_ISR_RX_TX_MASK_REG(port->id), 0);
+   mvpp2_thread_write(port->priv, thread,
+  MVPP2_ISR_RX_ERR_CAUSE_REG(port->id), 0);
 }
 
 /* Unmask the current thread's Rx/Tx interrupts.
@@ -1150,20 +1155,25 @@ static void mvpp2_interrupts_mask(void *arg)
 static void mvpp2_interrupts_unmask(void *arg)
 {
struct mvpp2_port *port = arg;
-   u32 val;
+   int cpu = smp_processor_id();
+   u32 val, thread;
 
/* If the thread isn't used, don't do anything */
-   if (smp_processor_id() > port->priv->nthreads)
+   if (cpu > port->priv->nthreads)
return;
 
+   thread = mvpp2_cpu_to_thread(port->priv, cpu);
+
val = MVPP2_CAUSE_MISC_SUM_MASK |
MVPP2_CAUSE_RXQ_OCCUP_DESC_ALL_MASK(port->priv->hw_version);
if (port->has_tx_irqs)
val |= MVPP2_CAUSE_TXQ_OCCUP_DESC_ALL_MASK;
 
-   mvpp2_thread_write(port->priv,
-  mvpp2_cpu_to_thread(port->priv, smp_processor_id()),
+   mvpp2_thread_write(port->priv, thread,
   MVPP2_ISR_RX_TX_MASK_REG(port->id), val);
+   mvpp2_thread_write(port->priv, thread,
+  MVPP2_ISR_RX_ERR_CAUSE_REG(port->id),
+  MVPP2_ISR_RX_ERR_CAUSE_NONOCC_MASK);
 }
 
 static void
@@ -1188,6 +1198,9 @@ static void mvpp2_interrupts_unmask(void *arg)
 
mvpp2_thread_write(port->priv, v->sw_thread_id,
   MVPP2_ISR_RX_TX_MASK_REG(port->id), val);
+   mvpp2_thread_write(port->priv, v->sw_thread_id,
+  MVPP2_ISR_RX_ERR_CAUSE_REG(port->id),
+  MVPP2_ISR_RX_ERR_CAUSE_NONOCC_MASK);
}
 }
 
@@ -2393,6 +2406,20 @@ static void mvpp2_txp_max_tx_size_set(struct mvpp2_port 
*port)
}
 }
 
+/* Set the number of non-occupied descriptors threshold */
+static void mvpp2_set_rxq_free_tresh(struct mvpp2_port *port,
+struct mvpp2_rx_queue *rxq)
+{
+   u32 val;
+
+   mvpp2_write(port->priv, MVPP2_RXQ_NUM_REG, rxq->id);
+
+   val = mvpp2_read(port->priv, MVPP2_RXQ_THRESH_REG);
+   val &= ~MVPP2_RXQ_NON_OCCUPIED_MASK;
+   val |= MSS_THRESHOLD_STOP << MVPP2_RXQ_NON_OCCUPIED_OFFSET;
+   mvpp2_write(port->priv, MVPP2_RXQ_THRESH_REG, val);
+}
+
 /* Set the number of packets that will be received before Rx interrupt
  * will be generated by HW.
  */
@@ -2648,6 +2675,9 @@ static int mvpp2_rxq_init(struct mvpp2_port *port,
mvpp2_rx_pkts_coal_set(port, rxq);
mvpp2_rx_time_coal_set(port, rxq);
 
+  

[PATCH v13 net-next 07/15] net: mvpp2: add FCA periodic timer configurations

2021-02-11 Thread stefanc
From: Stefan Chulski 

Flow Control periodic timer would be used if port in
XOFF to transmit periodic XOFF frames.

Signed-off-by: Stefan Chulski 
Acked-by: Marcin Wojtas 
---
 drivers/net/ethernet/marvell/mvpp2/mvpp2.h  | 13 ++
 drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c | 45 
 2 files changed, 58 insertions(+)

diff --git a/drivers/net/ethernet/marvell/mvpp2/mvpp2.h 
b/drivers/net/ethernet/marvell/mvpp2/mvpp2.h
index e7bbf0a..9239d80 100644
--- a/drivers/net/ethernet/marvell/mvpp2/mvpp2.h
+++ b/drivers/net/ethernet/marvell/mvpp2/mvpp2.h
@@ -596,6 +596,15 @@
 #define MVPP22_MPCS_CLK_RESET_DIV_RATIO(n) ((n) << 4)
 #define MVPP22_MPCS_CLK_RESET_DIV_SET  BIT(11)
 
+/* FCA registers. PPv2.2 and PPv2.3 */
+#define MVPP22_FCA_BASE(port)  (0x7600 + (port) * 0x1000)
+#define MVPP22_FCA_REG_SIZE16
+#define MVPP22_FCA_REG_MASK0x
+#define MVPP22_FCA_CONTROL_REG 0x0
+#define MVPP22_FCA_ENABLE_PERIODIC BIT(11)
+#define MVPP22_PERIODIC_COUNTER_LSB_REG(0x110)
+#define MVPP22_PERIODIC_COUNTER_MSB_REG(0x114)
+
 /* XPCS registers. PPv2.2 and PPv2.3 */
 #define MVPP22_XPCS_BASE(port) (0x7400 + (port) * 0x1000)
 #define MVPP22_XPCS_CFG0   0x0
@@ -751,6 +760,10 @@
 #define MVPP2_TX_FIFO_THRESHOLD(kb)\
((kb) * 1024 - MVPP2_TX_FIFO_THRESHOLD_MIN)
 
+/* MSS Flow control */
+#define FC_QUANTA  0x
+#define FC_CLK_DIVIDER 100
+
 /* RX buffer constants */
 #define MVPP2_SKB_SHINFO_SIZE \
SKB_DATA_ALIGN(sizeof(struct skb_shared_info))
diff --git a/drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c 
b/drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c
index 5730900..761f745 100644
--- a/drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c
+++ b/drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c
@@ -1280,6 +1280,49 @@ static void mvpp22_gop_init_10gkr(struct mvpp2_port 
*port)
writel(val, mpcs + MVPP22_MPCS_CLK_RESET);
 }
 
+static void mvpp22_gop_fca_enable_periodic(struct mvpp2_port *port, bool en)
+{
+   struct mvpp2 *priv = port->priv;
+   void __iomem *fca = priv->iface_base + MVPP22_FCA_BASE(port->gop_id);
+   u32 val;
+
+   val = readl(fca + MVPP22_FCA_CONTROL_REG);
+   val &= ~MVPP22_FCA_ENABLE_PERIODIC;
+   if (en)
+   val |= MVPP22_FCA_ENABLE_PERIODIC;
+   writel(val, fca + MVPP22_FCA_CONTROL_REG);
+}
+
+static void mvpp22_gop_fca_set_timer(struct mvpp2_port *port, u32 timer)
+{
+   struct mvpp2 *priv = port->priv;
+   void __iomem *fca = priv->iface_base + MVPP22_FCA_BASE(port->gop_id);
+   u32 lsb, msb;
+
+   lsb = timer & MVPP22_FCA_REG_MASK;
+   msb = timer >> MVPP22_FCA_REG_SIZE;
+
+   writel(lsb, fca + MVPP22_PERIODIC_COUNTER_LSB_REG);
+   writel(msb, fca + MVPP22_PERIODIC_COUNTER_MSB_REG);
+}
+
+/* Set Flow Control timer x100 faster than pause quanta to ensure that link
+ * partner won't send traffic if port is in XOFF mode.
+ */
+static void mvpp22_gop_fca_set_periodic_timer(struct mvpp2_port *port)
+{
+   u32 timer;
+
+   timer = (port->priv->tclk / (USEC_PER_SEC * FC_CLK_DIVIDER))
+   * FC_QUANTA;
+
+   mvpp22_gop_fca_enable_periodic(port, false);
+
+   mvpp22_gop_fca_set_timer(port, timer);
+
+   mvpp22_gop_fca_enable_periodic(port, true);
+}
+
 static int mvpp22_gop_init(struct mvpp2_port *port)
 {
struct mvpp2 *priv = port->priv;
@@ -1324,6 +1367,8 @@ static int mvpp22_gop_init(struct mvpp2_port *port)
val |= GENCONF_SOFT_RESET1_GOP;
regmap_write(priv->sysctrl_base, GENCONF_SOFT_RESET1, val);
 
+   mvpp22_gop_fca_set_periodic_timer(port);
+
 unsupported_conf:
return 0;
 
-- 
1.9.1



[PATCH v13 net-next 06/15] net: mvpp2: increase BM pool and RXQ size

2021-02-11 Thread stefanc
From: Stefan Chulski 

BM pool and RXQ size increased to support Firmware Flow Control.
Minimum depletion thresholds to support FC are 1024 buffers.
BM pool size increased to 2048 to have some 1024 buffers
space between depletion thresholds and BM pool size.

Jumbo frames require a 9888B buffer, so memory requirements
for data buffers increased from 7MB to 24MB.

Signed-off-by: Stefan Chulski 
Acked-by: Marcin Wojtas 
---
 drivers/net/ethernet/marvell/mvpp2/mvpp2.h | 8 
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/drivers/net/ethernet/marvell/mvpp2/mvpp2.h 
b/drivers/net/ethernet/marvell/mvpp2/mvpp2.h
index ce08086..e7bbf0a 100644
--- a/drivers/net/ethernet/marvell/mvpp2/mvpp2.h
+++ b/drivers/net/ethernet/marvell/mvpp2/mvpp2.h
@@ -715,8 +715,8 @@
 #define MVPP2_PORT_MAX_RXQ 32
 
 /* Max number of Rx descriptors */
-#define MVPP2_MAX_RXD_MAX  1024
-#define MVPP2_MAX_RXD_DFLT 128
+#define MVPP2_MAX_RXD_MAX  2048
+#define MVPP2_MAX_RXD_DFLT 1024
 
 /* Max number of Tx descriptors */
 #define MVPP2_MAX_TXD_MAX  2048
@@ -848,8 +848,8 @@ enum mvpp22_ptp_packet_format {
 #define MVPP22_PTP_TIMESTAMPQUEUESELECTBIT(18)
 
 /* BM constants */
-#define MVPP2_BM_JUMBO_BUF_NUM 512
-#define MVPP2_BM_LONG_BUF_NUM  1024
+#define MVPP2_BM_JUMBO_BUF_NUM 2048
+#define MVPP2_BM_LONG_BUF_NUM  2048
 #define MVPP2_BM_SHORT_BUF_NUM 2048
 #define MVPP2_BM_POOL_SIZE_MAX (16*1024 - MVPP2_BM_POOL_PTR_ALIGN/4)
 #define MVPP2_BM_POOL_PTR_ALIGN128
-- 
1.9.1



[PATCH v13 net-next 05/15] net: mvpp2: add PPv23 version definition

2021-02-11 Thread stefanc
From: Stefan Chulski 

This patch add PPv23 version definition.
PPv23 is new packet processor in CP115.
Everything that supported by PPv22, also supported by PPv23.
No functional changes in this stage.

Signed-off-by: Stefan Chulski 
Acked-by: Marcin Wojtas 
---
 drivers/net/ethernet/marvell/mvpp2/mvpp2.h  | 24 
 drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c | 15 
 2 files changed, 24 insertions(+), 15 deletions(-)

diff --git a/drivers/net/ethernet/marvell/mvpp2/mvpp2.h 
b/drivers/net/ethernet/marvell/mvpp2/mvpp2.h
index 56e90ab..ce08086 100644
--- a/drivers/net/ethernet/marvell/mvpp2/mvpp2.h
+++ b/drivers/net/ethernet/marvell/mvpp2/mvpp2.h
@@ -60,6 +60,9 @@
 /* Top Registers */
 #define MVPP2_MH_REG(port) (0x5040 + 4 * (port))
 #define MVPP2_DSA_EXTENDED BIT(5)
+#define MVPP2_VER_ID_REG   0x50b0
+#define MVPP2_VER_PP22 0x10
+#define MVPP2_VER_PP23 0x11
 
 /* Parser Registers */
 #define MVPP2_PRS_INIT_LOOKUP_REG  0x1000
@@ -469,7 +472,7 @@
 #define MVPP22_GMAC_INT_SUM_MASK_LINK_STAT BIT(1)
 #defineMVPP22_GMAC_INT_SUM_MASK_PTPBIT(2)
 
-/* Per-port XGMAC registers. PPv2.2 only, only for GOP port 0,
+/* Per-port XGMAC registers. PPv2.2 and PPv2.3, only for GOP port 0,
  * relative to port->base.
  */
 #define MVPP22_XLG_CTRL0_REG   0x100
@@ -506,7 +509,7 @@
 #define MVPP22_XLG_CTRL4_MACMODSELECT_GMAC BIT(12)
 #define MVPP22_XLG_CTRL4_EN_IDLE_CHECK BIT(14)
 
-/* SMI registers. PPv2.2 only, relative to priv->iface_base. */
+/* SMI registers. PPv2.2 and PPv2.3, relative to priv->iface_base. */
 #define MVPP22_SMI_MISC_CFG_REG0x1204
 #define MVPP22_SMI_POLLING_EN  BIT(10)
 
@@ -582,7 +585,7 @@
 #define MVPP2_QUEUE_NEXT_DESC(q, index) \
(((index) < (q)->last_desc) ? ((index) + 1) : 0)
 
-/* XPCS registers. PPv2.2 only */
+/* XPCS registers.PPv2.2 and PPv2.3 */
 #define MVPP22_MPCS_BASE(port) (0x7000 + (port) * 0x1000)
 #define MVPP22_MPCS_CTRL   0x14
 #define MVPP22_MPCS_CTRL_FWD_ERR_CONN  BIT(10)
@@ -593,7 +596,7 @@
 #define MVPP22_MPCS_CLK_RESET_DIV_RATIO(n) ((n) << 4)
 #define MVPP22_MPCS_CLK_RESET_DIV_SET  BIT(11)
 
-/* XPCS registers. PPv2.2 only */
+/* XPCS registers. PPv2.2 and PPv2.3 */
 #define MVPP22_XPCS_BASE(port) (0x7400 + (port) * 0x1000)
 #define MVPP22_XPCS_CFG0   0x0
 #define MVPP22_XPCS_CFG0_RESET_DIS BIT(0)
@@ -927,15 +930,16 @@ struct mvpp2 {
void __iomem *iface_base;
void __iomem *cm3_base;
 
-   /* On PPv2.2, each "software thread" can access the base
+   /* On PPv2.2 and PPv2.3, each "software thread" can access the base
 * register through a separate address space, each 64 KB apart
 * from each other. Typically, such address spaces will be
 * used per CPU.
 */
void __iomem *swth_base[MVPP2_MAX_THREADS];
 
-   /* On PPv2.2, some port control registers are located into the system
-* controller space. These registers are accessible through a regmap.
+   /* On PPv2.2 and PPv2.3, some port control registers are located into
+* the system controller space. These registers are accessible
+* through a regmap.
 */
struct regmap *sysctrl_base;
 
@@ -977,7 +981,7 @@ struct mvpp2 {
u32 tclk;
 
/* HW version */
-   enum { MVPP21, MVPP22 } hw_version;
+   enum { MVPP21, MVPP22, MVPP23 } hw_version;
 
/* Maximum number of RXQs per port */
unsigned int max_port_rxqs;
@@ -1221,7 +1225,7 @@ struct mvpp21_rx_desc {
__le32 reserved8;
 };
 
-/* HW TX descriptor for PPv2.2 */
+/* HW TX descriptor for PPv2.2 and PPv2.3 */
 struct mvpp22_tx_desc {
__le32 command;
u8  packet_offset;
@@ -1233,7 +1237,7 @@ struct mvpp22_tx_desc {
__le64 buf_cookie_misc;
 };
 
-/* HW RX descriptor for PPv2.2 */
+/* HW RX descriptor for PPv2.2 and PPv2.3 */
 struct mvpp22_rx_desc {
__le32 status;
__le16 reserved1;
diff --git a/drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c 
b/drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c
index 17cd161..5730900 100644
--- a/drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c
+++ b/drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c
@@ -384,7 +384,7 @@ static int mvpp2_bm_pool_create(struct device *dev, struct 
mvpp2 *priv,
if (!IS_ALIGNED(size, 16))
return -EINVAL;
 
-   /* PPv2.1 needs 8 bytes per buffer pointer, PPv2.2 needs 16
+   /* PPv2.1 needs 8 bytes per buffer pointer, PPv2.2 and PPv2.3 needs 16
 * bytes per buffer pointer
 */
if (priv->hw_version == MVPP21)
@@ -5456,7 +5456,7 @@ static void mvpp2_rx_irqs_setup(struct mvpp2_port *port)
return;
}
 
-   /* Handle the

[PATCH v13 net-next 03/15] net: mvpp2: add CM3 SRAM memory map

2021-02-11 Thread stefanc
From: Stefan Chulski 

This patch adds CM3 memory map.

Signed-off-by: Stefan Chulski 
Reviewed-by: Andrew Lunn 
Acked-by: Marcin Wojtas 
---
 drivers/net/ethernet/marvell/mvpp2/mvpp2.h  |  1 +
 drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c | 26 
 2 files changed, 27 insertions(+)

diff --git a/drivers/net/ethernet/marvell/mvpp2/mvpp2.h 
b/drivers/net/ethernet/marvell/mvpp2/mvpp2.h
index 6bd7e40..56e90ab 100644
--- a/drivers/net/ethernet/marvell/mvpp2/mvpp2.h
+++ b/drivers/net/ethernet/marvell/mvpp2/mvpp2.h
@@ -925,6 +925,7 @@ struct mvpp2 {
/* Shared registers' base addresses */
void __iomem *lms_base;
void __iomem *iface_base;
+   void __iomem *cm3_base;
 
/* On PPv2.2, each "software thread" can access the base
 * register through a separate address space, each 64 KB apart
diff --git a/drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c 
b/drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c
index a07cf60..eec3796 100644
--- a/drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c
+++ b/drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c
@@ -6846,6 +6846,27 @@ static int mvpp2_init(struct platform_device *pdev, 
struct mvpp2 *priv)
return 0;
 }
 
+static int mvpp2_get_sram(struct platform_device *pdev,
+ struct mvpp2 *priv)
+{
+   struct resource *res;
+
+   res = platform_get_resource(pdev, IORESOURCE_MEM, 2);
+   if (!res) {
+   if (has_acpi_companion(&pdev->dev))
+   dev_warn(&pdev->dev, "ACPI is too old, Flow control not 
supported\n");
+   else
+   dev_warn(&pdev->dev, "DT is too old, Flow control not 
supported\n");
+   return 0;
+   }
+
+   priv->cm3_base = devm_ioremap_resource(&pdev->dev, res);
+   if (IS_ERR(priv->cm3_base))
+   return PTR_ERR(priv->cm3_base);
+
+   return 0;
+}
+
 static int mvpp2_probe(struct platform_device *pdev)
 {
const struct acpi_device_id *acpi_id;
@@ -6902,6 +6923,11 @@ static int mvpp2_probe(struct platform_device *pdev)
priv->iface_base = devm_ioremap_resource(&pdev->dev, res);
if (IS_ERR(priv->iface_base))
return PTR_ERR(priv->iface_base);
+
+   /* Map CM3 SRAM */
+   err = mvpp2_get_sram(pdev, priv);
+   if (err)
+   dev_warn(&pdev->dev, "Fail to alloc CM3 SRAM\n");
}
 
if (priv->hw_version == MVPP22 && dev_of_node(&pdev->dev)) {
-- 
1.9.1



[PATCH v13 net-next 02/15] dts: marvell: add CM3 SRAM memory to cp11x ethernet device tree

2021-02-11 Thread stefanc
From: Konstantin Porotchkin 

CM3 SRAM address space will be used for Flow Control configuration.

Signed-off-by: Stefan Chulski 
Signed-off-by: Konstantin Porotchkin 
Acked-by: Marcin Wojtas 
Acked-by: Rob Herring 
---
 arch/arm64/boot/dts/marvell/armada-cp11x.dtsi | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/arm64/boot/dts/marvell/armada-cp11x.dtsi 
b/arch/arm64/boot/dts/marvell/armada-cp11x.dtsi
index 9dcf16b..6fe0d26 100644
--- a/arch/arm64/boot/dts/marvell/armada-cp11x.dtsi
+++ b/arch/arm64/boot/dts/marvell/armada-cp11x.dtsi
@@ -59,7 +59,7 @@
 
CP11X_LABEL(ethernet): ethernet@0 {
compatible = "marvell,armada-7k-pp22";
-   reg = <0x0 0x10>, <0x129000 0xb000>;
+   reg = <0x0 0x10>, <0x129000 0xb000>, <0x22 
0x800>;
clocks = <&CP11X_LABEL(clk) 1 3>, <&CP11X_LABEL(clk) 1 
9>,
 <&CP11X_LABEL(clk) 1 5>, <&CP11X_LABEL(clk) 1 
6>,
 <&CP11X_LABEL(clk) 1 18>;
-- 
1.9.1



[PATCH v13 net-next 01/15] doc: marvell: add CM3 address space and PPv2.3 description

2021-02-11 Thread stefanc
From: Stefan Chulski 

Patch adds CM3 address space and PPv2.3 description.

Signed-off-by: Stefan Chulski 
Acked-by: Marcin Wojtas 
---
 Documentation/devicetree/bindings/net/marvell-pp2.txt | 6 --
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/Documentation/devicetree/bindings/net/marvell-pp2.txt 
b/Documentation/devicetree/bindings/net/marvell-pp2.txt
index b783976..ce15c17 100644
--- a/Documentation/devicetree/bindings/net/marvell-pp2.txt
+++ b/Documentation/devicetree/bindings/net/marvell-pp2.txt
@@ -1,5 +1,6 @@
 * Marvell Armada 375 Ethernet Controller (PPv2.1)
   Marvell Armada 7K/8K Ethernet Controller (PPv2.2)
+  Marvell CN913X Ethernet Controller (PPv2.3)
 
 Required properties:
 
@@ -12,10 +13,11 @@ Required properties:
- common controller registers
- LMS registers
- one register area per Ethernet port
-  For "marvell,armada-7k-pp2", must contain the following register
+  For "marvell,armada-7k-pp2" used by 7K/8K and CN913X, must contain the 
following register
   sets:
- packet processor registers
- networking interfaces registers
+   - CM3 address space used for TX Flow Control
 
 - clocks: pointers to the reference clocks for this device, consequently:
- main controller clock (for both armada-375-pp2 and armada-7k-pp2)
@@ -81,7 +83,7 @@ Example for marvell,armada-7k-pp2:
 
 cpm_ethernet: ethernet@0 {
compatible = "marvell,armada-7k-pp22";
-   reg = <0x0 0x10>, <0x129000 0xb000>;
+   reg = <0x0 0x10>, <0x129000 0xb000>, <0x22 0x800>;
clocks = <&cpm_syscon0 1 3>, <&cpm_syscon0 1 9>,
 <&cpm_syscon0 1 5>, <&cpm_syscon0 1 6>, <&cpm_syscon0 1 18>;
clock-names = "pp_clk", "gop_clk", "mg_clk", "mg_core_clk", "axi_clk";
-- 
1.9.1



[PATCH v13 net-next 00/15] net: mvpp2: Add TX Flow Control support

2021-02-11 Thread stefanc
From: Stefan Chulski 

Armada hardware has a pause generation mechanism in GOP (MAC).
The GOP generate flow control frames based on an indication programmed in Ports 
Control 0 Register. There is a bit per port.
However assertion of the PortX Pause bits in the ports control 0 register only 
sends a one time pause.
To complement the function the GOP has a mechanism to periodically send pause 
control messages based on periodic counters.
This mechanism ensures that the pause is effective as long as the Appropriate 
PortX Pause is asserted.

Problem is that Packet Processor that actually can drop packets due to lack of 
resources not connected to the GOP flow control generation mechanism.
To solve this issue Armada has firmware running on CM3 CPU dedicated for Flow 
Control support.
Firmware monitors Packet Processor resources and asserts XON/XOFF by writing to 
Ports Control 0 Register.

MSS shared SRAM memory used to communicate between CM3 firmware and PP2 driver.
During init PP2 driver informs firmware about used BM pools, RXQs, congestion 
and depletion thresholds.

The pause frames are generated whenever congestion or depletion in resources is 
detected.
The back pressure is stopped when the resource reaches a sufficient level.
So the congestion/depletion and sufficient level implement a hysteresis that 
reduces the XON/XOFF toggle frequency.

Packet Processor v23 hardware introduces support for RX FIFO fill level monitor.
Patch "add PPv23 version definition" to differ between v23 and v22 hardware.
Patch "add TX FC firmware check" verifies that CM3 firmware supports Flow 
Control monitoring.

v12 --> v13
- Remove bm_underrun_protect module_param

v11 --> v12
- Improve warning message in "net: mvpp2: add TX FC firmware check" patch

v10 --> v11
- Improve "net: mvpp2: add CM3 SRAM memory map" comment
- Move condition check to 'net: mvpp2: always compare hw-version vs MVPP21' 
patch

v9 --> v10
- Add CM3 SRAM description to PPv2 documentation

v8 --> v9
- Replace generic pool allocation with devm_ioremap_resource

v7 --> v8
- Reorder "always compare hw-version vs MVPP21" and "add PPv23 version 
definition" commits
- Typo fixes
- Remove condition fix from "add RXQ flow control configurations"

v6 --> v7
- Reduce patch set from 18 to 15 patches
 - Documentation change combined into a single patch
 - RXQ and BM size change combined into a single patch
 - Ring size change check moved into "add RXQ flow control configurations" 
commit

v5 --> v6
- No change

v4 --> v5
- Add missed Signed-off
- Fix warnings in patches 3 and 12
- Add revision requirement to warning message
- Move mss_spinlock into RXQ flow control configurations patch
- Improve FCA RXQ non occupied descriptor threshold commit message

v3 --> v4
- Remove RFC tag

v2 --> v3
- Remove inline functions
- Add PPv2.3 description into marvell-pp2.txt
- Improve mvpp2_interrupts_mask/unmask procedure
- Improve FC enable/disable procedure
- Add priv->sram_pool check
- Remove gen_pool_destroy call
- Reduce Flow Control timer to x100 faster

v1 --> v2
- Add memory requirements information
- Add EPROBE_DEFER if of_gen_pool_get return NULL
- Move Flow control configuration to mvpp2_mac_link_up callback
- Add firmware version info with Flow control support

Konstantin Porotchkin (1):
  dts: marvell: add CM3 SRAM memory to cp11x ethernet device tree

Stefan Chulski (14):
  doc: marvell: add CM3 address space and PPv2.3 description
  net: mvpp2: add CM3 SRAM memory map
  net: mvpp2: always compare hw-version vs MVPP21
  net: mvpp2: add PPv23 version definition
  net: mvpp2: increase BM pool and RXQ size
  net: mvpp2: add FCA periodic timer configurations
  net: mvpp2: add FCA RXQ non occupied descriptor threshold
  net: mvpp2: enable global flow control
  net: mvpp2: add RXQ flow control configurations
  net: mvpp2: add ethtool flow control configuration support
  net: mvpp2: add BM protection underrun feature support
  net: mvpp2: add PPv23 RX FIFO flow control
  net: mvpp2: set 802.3x GoP Flow Control mode
  net: mvpp2: add TX FC firmware check

 Documentation/devicetree/bindings/net/marvell-pp2.txt |   6 +-
 arch/arm64/boot/dts/marvell/armada-cp11x.dtsi |   2 +-
 drivers/net/ethernet/marvell/mvpp2/mvpp2.h| 124 -
 drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c   | 516 
++--
 4 files changed, 599 insertions(+), 49 deletions(-)

-- 
1.9.1



[net-next] net: mvpp2: add an entry to skip parser

2021-02-10 Thread stefanc
From: Stefan Chulski 

This entry used when skipping the parser needed,
for example, the custom header pretended to ethernet header.

Suggested-by: Liron Himi 
Signed-off-by: Stefan Chulski 
---
 drivers/net/ethernet/marvell/mvpp2/mvpp2_prs.c | 15 +++
 drivers/net/ethernet/marvell/mvpp2/mvpp2_prs.h |  3 ++-
 2 files changed, 17 insertions(+), 1 deletion(-)

diff --git a/drivers/net/ethernet/marvell/mvpp2/mvpp2_prs.c 
b/drivers/net/ethernet/marvell/mvpp2/mvpp2_prs.c
index 0b2ff08..b968a20 100644
--- a/drivers/net/ethernet/marvell/mvpp2/mvpp2_prs.c
+++ b/drivers/net/ethernet/marvell/mvpp2/mvpp2_prs.c
@@ -1173,6 +1173,21 @@ static void mvpp2_prs_mh_init(struct mvpp2 *priv)
/* Update shadow table and hw entry */
mvpp2_prs_shadow_set(priv, pe.index, MVPP2_PRS_LU_MH);
mvpp2_prs_hw_write(priv, &pe);
+
+   /* Set MH entry that skip parser */
+   pe.index = MVPP2_PE_MH_SKIP_PRS;
+   mvpp2_prs_tcam_lu_set(&pe, MVPP2_PRS_LU_MH);
+   mvpp2_prs_sram_shift_set(&pe, MVPP2_MH_SIZE,
+MVPP2_PRS_SRAM_OP_SEL_SHIFT_ADD);
+   mvpp2_prs_sram_bits_set(&pe, MVPP2_PRS_SRAM_LU_GEN_BIT, 1);
+   mvpp2_prs_sram_next_lu_set(&pe, MVPP2_PRS_LU_FLOWS);
+
+   /* Mask all ports */
+   mvpp2_prs_tcam_port_map_set(&pe, 0);
+
+   /* Update shadow table and hw entry */
+   mvpp2_prs_shadow_set(priv, pe.index, MVPP2_PRS_LU_MH);
+   mvpp2_prs_hw_write(priv, &pe);
 }
 
 /* Set default entires (place holder) for promiscuous, non-promiscuous and
diff --git a/drivers/net/ethernet/marvell/mvpp2/mvpp2_prs.h 
b/drivers/net/ethernet/marvell/mvpp2/mvpp2_prs.h
index 4b68dd3..c16e5b9 100644
--- a/drivers/net/ethernet/marvell/mvpp2/mvpp2_prs.h
+++ b/drivers/net/ethernet/marvell/mvpp2/mvpp2_prs.h
@@ -103,10 +103,11 @@
 #define MVPP2_PE_MAC_RANGE_START   (MVPP2_PE_MAC_RANGE_END - \
MVPP2_PRS_MAC_RANGE_SIZE + 1)
 /* VLAN filtering range */
-#define MVPP2_PE_VID_FILT_RANGE_END (MVPP2_PRS_TCAM_SRAM_SIZE - 31)
+#define MVPP2_PE_VID_FILT_RANGE_END (MVPP2_PRS_TCAM_SRAM_SIZE - 32)
 #define MVPP2_PE_VID_FILT_RANGE_START   (MVPP2_PE_VID_FILT_RANGE_END - \
 MVPP2_PRS_VLAN_FILT_RANGE_SIZE + 1)
 #define MVPP2_PE_LAST_FREE_TID  (MVPP2_PE_MAC_RANGE_START - 1)
+#define MVPP2_PE_MH_SKIP_PRS   (MVPP2_PRS_TCAM_SRAM_SIZE - 31)
 #define MVPP2_PE_IP6_EXT_PROTO_UN  (MVPP2_PRS_TCAM_SRAM_SIZE - 30)
 #define MVPP2_PE_IP6_ADDR_UN   (MVPP2_PRS_TCAM_SRAM_SIZE - 29)
 #define MVPP2_PE_IP4_ADDR_UN   (MVPP2_PRS_TCAM_SRAM_SIZE - 28)
-- 
1.9.1



[PATCH v12 net-next 15/15] net: mvpp2: add TX FC firmware check

2021-02-10 Thread stefanc
From: Stefan Chulski 

Patch check that TX FC firmware is running in CM3.
If not, global TX FC would be disabled.

Signed-off-by: Stefan Chulski 
Acked-by: Marcin Wojtas 
---
 drivers/net/ethernet/marvell/mvpp2/mvpp2.h  |  1 +
 drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c | 39 
 2 files changed, 33 insertions(+), 7 deletions(-)

diff --git a/drivers/net/ethernet/marvell/mvpp2/mvpp2.h 
b/drivers/net/ethernet/marvell/mvpp2/mvpp2.h
index b61a1ba..da87152 100644
--- a/drivers/net/ethernet/marvell/mvpp2/mvpp2.h
+++ b/drivers/net/ethernet/marvell/mvpp2/mvpp2.h
@@ -828,6 +828,7 @@
 
 #define MSS_THRESHOLD_STOP 768
 #define MSS_THRESHOLD_START1024
+#define MSS_FC_MAX_TIMEOUT 5000
 
 /* RX buffer constants */
 #define MVPP2_SKB_SHINFO_SIZE \
diff --git a/drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c 
b/drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c
index 4d0a398..ac2f442 100644
--- a/drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c
+++ b/drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c
@@ -931,6 +931,34 @@ static void mvpp2_bm_pool_update_fc(struct mvpp2_port 
*port,
spin_unlock_irqrestore(&port->priv->mss_spinlock, flags);
 }
 
+static int mvpp2_enable_global_fc(struct mvpp2 *priv)
+{
+   int val, timeout = 0;
+
+   /* Enable global flow control. In this stage global
+* flow control enabled, but still disabled per port.
+*/
+   val = mvpp2_cm3_read(priv, MSS_FC_COM_REG);
+   val |= FLOW_CONTROL_ENABLE_BIT;
+   mvpp2_cm3_write(priv, MSS_FC_COM_REG, val);
+
+   /* Check if Firmware running and disable FC if not*/
+   val |= FLOW_CONTROL_UPDATE_COMMAND_BIT;
+   mvpp2_cm3_write(priv, MSS_FC_COM_REG, val);
+
+   while (timeout < MSS_FC_MAX_TIMEOUT) {
+   val = mvpp2_cm3_read(priv, MSS_FC_COM_REG);
+
+   if (!(val & FLOW_CONTROL_UPDATE_COMMAND_BIT))
+   return 0;
+   usleep_range(10, 20);
+   timeout++;
+   }
+
+   priv->global_tx_fc = false;
+   return -EOPNOTSUPP;
+}
+
 /* Release buffer to BM */
 static inline void mvpp2_bm_pool_put(struct mvpp2_port *port, int pool,
 dma_addr_t buf_dma_addr,
@@ -7263,7 +7291,7 @@ static int mvpp2_probe(struct platform_device *pdev)
struct resource *res;
void __iomem *base;
int i, shared;
-   int err, val;
+   int err;
 
priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL);
if (!priv)
@@ -7487,13 +7515,10 @@ static int mvpp2_probe(struct platform_device *pdev)
goto err_port_probe;
}
 
-   /* Enable global flow control. In this stage global
-* flow control enabled, but still disabled per port.
-*/
if (priv->global_tx_fc && priv->hw_version != MVPP21) {
-   val = mvpp2_cm3_read(priv, MSS_FC_COM_REG);
-   val |= FLOW_CONTROL_ENABLE_BIT;
-   mvpp2_cm3_write(priv, MSS_FC_COM_REG, val);
+   err = mvpp2_enable_global_fc(priv);
+   if (err)
+   dev_warn(&pdev->dev, "Minimum of CM3 firmware 18.09 and 
chip revision B0 required for flow control\n");
}
 
mvpp2_dbgfs_init(priv, pdev->name);
-- 
1.9.1



[PATCH v12 net-next 14/15] net: mvpp2: set 802.3x GoP Flow Control mode

2021-02-10 Thread stefanc
From: Stefan Chulski 

This patch fix GMAC TX flow control autoneg.
Flow control autoneg wrongly were disabled with enabled TX
flow control.

Signed-off-by: Stefan Chulski 
Acked-by: Marcin Wojtas 
---
 drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c 
b/drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c
index a472125..4d0a398 100644
--- a/drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c
+++ b/drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c
@@ -6283,7 +6283,7 @@ static void mvpp2_gmac_config(struct mvpp2_port *port, 
unsigned int mode,
old_ctrl4 = ctrl4 = readl(port->base + MVPP22_GMAC_CTRL_4_REG);
 
ctrl0 &= ~MVPP2_GMAC_PORT_TYPE_MASK;
-   ctrl2 &= ~(MVPP2_GMAC_INBAND_AN_MASK | MVPP2_GMAC_PCS_ENABLE_MASK);
+   ctrl2 &= ~(MVPP2_GMAC_INBAND_AN_MASK | MVPP2_GMAC_PCS_ENABLE_MASK | 
MVPP2_GMAC_FLOW_CTRL_MASK);
 
/* Configure port type */
if (phy_interface_mode_is_8023z(state->interface)) {
-- 
1.9.1



[PATCH v12 net-next 12/15] net: mvpp2: add BM protection underrun feature support

2021-02-10 Thread stefanc
From: Stefan Chulski 

The PP2v23 hardware supports a feature allowing to double the
size of BPPI by decreasing number of pools from 16 to 8.
Increasing of BPPI size protect BM drop from BPPI underrun.
Underrun could occurred due to stress on DDR and as result slow buffer
transition from BPPE to BPPI.
New BPPI threshold recommended by spec is:
BPPI low threshold - 640 buffers
BPPI high threshold - 832 buffers
Supported only in PPv23.

Signed-off-by: Stefan Chulski 
Acked-by: Marcin Wojtas 
---
 drivers/net/ethernet/marvell/mvpp2/mvpp2.h  |  8 +
 drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c | 35 +++-
 2 files changed, 42 insertions(+), 1 deletion(-)

diff --git a/drivers/net/ethernet/marvell/mvpp2/mvpp2.h 
b/drivers/net/ethernet/marvell/mvpp2/mvpp2.h
index 0731dc7..9b525b60 100644
--- a/drivers/net/ethernet/marvell/mvpp2/mvpp2.h
+++ b/drivers/net/ethernet/marvell/mvpp2/mvpp2.h
@@ -324,6 +324,10 @@
 #define MVPP2_BM_HIGH_THRESH_MASK  0x7f
 #define MVPP2_BM_HIGH_THRESH_VALUE(val)((val) << \
MVPP2_BM_HIGH_THRESH_OFFS)
+#define MVPP2_BM_BPPI_HIGH_THRESH  0x1E
+#define MVPP2_BM_BPPI_LOW_THRESH   0x1C
+#define MVPP23_BM_BPPI_HIGH_THRESH 0x34
+#define MVPP23_BM_BPPI_LOW_THRESH  0x28
 #define MVPP2_BM_INTR_CAUSE_REG(pool)  (0x6240 + ((pool) * 4))
 #define MVPP2_BM_RELEASED_DELAY_MASK   BIT(0)
 #define MVPP2_BM_ALLOC_FAILED_MASK BIT(1)
@@ -352,6 +356,10 @@
 #define MVPP2_OVERRUN_ETH_DROP 0x7000
 #define MVPP2_CLS_ETH_DROP 0x7020
 
+#define MVPP22_BM_POOL_BASE_ADDR_HIGH_REG  0x6310
+#define MVPP22_BM_POOL_BASE_ADDR_HIGH_MASK 0xff
+#define MVPP23_BM_8POOL_MODE   BIT(8)
+
 /* Hit counters registers */
 #define MVPP2_CTRS_IDX 0x7040
 #define MVPP22_CTRS_TX_CTR(port, txq)  ((txq) | ((port) << 3) | BIT(7))
diff --git a/drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c 
b/drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c
index 90c9265..3faad04 100644
--- a/drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c
+++ b/drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c
@@ -69,6 +69,11 @@ enum mvpp2_bm_pool_log_num {
 module_param(queue_mode, int, 0444);
 MODULE_PARM_DESC(queue_mode, "Set queue_mode (single=0, multi=1)");
 
+static int bm_underrun_protect = 1;
+
+module_param(bm_underrun_protect, int, 0444);
+MODULE_PARM_DESC(bm_underrun_protect, "Set BM underrun protect feature (0-1), 
def=1");
+
 /* Utility/helper methods */
 
 void mvpp2_write(struct mvpp2 *priv, u32 offset, u32 data)
@@ -423,6 +428,21 @@ static int mvpp2_bm_pool_create(struct device *dev, struct 
mvpp2 *priv,
 
val = mvpp2_read(priv, MVPP2_BM_POOL_CTRL_REG(bm_pool->id));
val |= MVPP2_BM_START_MASK;
+
+   val &= ~MVPP2_BM_LOW_THRESH_MASK;
+   val &= ~MVPP2_BM_HIGH_THRESH_MASK;
+
+   /* Set 8 Pools BPPI threshold if BM underrun protection feature
+* was enabled
+*/
+   if (priv->hw_version == MVPP23 && bm_underrun_protect) {
+   val |= MVPP2_BM_LOW_THRESH_VALUE(MVPP23_BM_BPPI_LOW_THRESH);
+   val |= MVPP2_BM_HIGH_THRESH_VALUE(MVPP23_BM_BPPI_HIGH_THRESH);
+   } else {
+   val |= MVPP2_BM_LOW_THRESH_VALUE(MVPP2_BM_BPPI_LOW_THRESH);
+   val |= MVPP2_BM_HIGH_THRESH_VALUE(MVPP2_BM_BPPI_HIGH_THRESH);
+   }
+
mvpp2_write(priv, MVPP2_BM_POOL_CTRL_REG(bm_pool->id), val);
 
bm_pool->size = size;
@@ -591,6 +611,16 @@ static int mvpp2_bm_pools_init(struct device *dev, struct 
mvpp2 *priv)
return err;
 }
 
+/* Routine enable PPv23 8 pool mode */
+static void mvpp23_bm_set_8pool_mode(struct mvpp2 *priv)
+{
+   int val;
+
+   val = mvpp2_read(priv, MVPP22_BM_POOL_BASE_ADDR_HIGH_REG);
+   val |= MVPP23_BM_8POOL_MODE;
+   mvpp2_write(priv, MVPP22_BM_POOL_BASE_ADDR_HIGH_REG, val);
+}
+
 static int mvpp2_bm_init(struct device *dev, struct mvpp2 *priv)
 {
enum dma_data_direction dma_dir = DMA_FROM_DEVICE;
@@ -644,6 +674,9 @@ static int mvpp2_bm_init(struct device *dev, struct mvpp2 
*priv)
if (!priv->bm_pools)
return -ENOMEM;
 
+   if (priv->hw_version == MVPP23 && bm_underrun_protect)
+   mvpp23_bm_set_8pool_mode(priv);
+
err = mvpp2_bm_pools_init(dev, priv);
if (err < 0)
return err;
@@ -6490,7 +6523,7 @@ static void mvpp2_mac_link_up(struct phylink_config 
*config,
 val);
}
 
-   if (port->priv->global_tx_fc) {
+   if (port->priv->global_tx_fc && bm_underrun_protect) {
port->tx_fc = tx_pause;
if (tx_pause)
mvpp2_rxq_enable_fc(port);
-- 
1.9.1



[PATCH v12 net-next 13/15] net: mvpp2: add PPv23 RX FIFO flow control

2021-02-10 Thread stefanc
From: Stefan Chulski 

New FIFO flow control feature was added in PPv23.
PPv2 FIFO polled by HW and trigger pause frame if FIFO
fill level is below threshold.
FIFO HW flow control enabled with CM3 RXQ&BM flow
control with ethtool.
Current  FIFO thresholds is:
9KB for port with maximum speed 10Gb/s port
4KB for port with maximum speed 5Gb/s port
2KB for port with maximum speed 1Gb/s port

Signed-off-by: Stefan Chulski 
Acked-by: Marcin Wojtas 
---
 drivers/net/ethernet/marvell/mvpp2/mvpp2.h  | 15 ++
 drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c | 53 
 2 files changed, 68 insertions(+)

diff --git a/drivers/net/ethernet/marvell/mvpp2/mvpp2.h 
b/drivers/net/ethernet/marvell/mvpp2/mvpp2.h
index 9b525b60..b61a1ba 100644
--- a/drivers/net/ethernet/marvell/mvpp2/mvpp2.h
+++ b/drivers/net/ethernet/marvell/mvpp2/mvpp2.h
@@ -770,6 +770,18 @@
 #define MVPP2_TX_FIFO_THRESHOLD(kb)\
((kb) * 1024 - MVPP2_TX_FIFO_THRESHOLD_MIN)
 
+/* RX FIFO threshold in 1KB granularity */
+#define MVPP23_PORT0_FIFO_TRSH (9 * 1024)
+#define MVPP23_PORT1_FIFO_TRSH (4 * 1024)
+#define MVPP23_PORT2_FIFO_TRSH (2 * 1024)
+
+/* RX Flow Control Registers */
+#define MVPP2_RX_FC_REG(port)  (0x150 + 4 * (port))
+#define MVPP2_RX_FC_EN BIT(24)
+#define MVPP2_RX_FC_TRSH_OFFS  16
+#define MVPP2_RX_FC_TRSH_MASK  (0xFF << MVPP2_RX_FC_TRSH_OFFS)
+#define MVPP2_RX_FC_TRSH_UNIT  256
+
 /* MSS Flow control */
 #define MSS_FC_COM_REG 0
 #define FLOW_CONTROL_ENABLE_BITBIT(0)
@@ -1498,6 +1510,8 @@ struct mvpp2_bm_pool {
 
 void mvpp2_dbgfs_cleanup(struct mvpp2 *priv);
 
+void mvpp23_rx_fifo_fc_en(struct mvpp2 *priv, int port, bool en);
+
 #ifdef CONFIG_MVPP2_PTP
 int mvpp22_tai_probe(struct device *dev, struct mvpp2 *priv);
 void mvpp22_tai_tstamp(struct mvpp2_tai *tai, u32 tstamp,
@@ -1530,4 +1544,5 @@ static inline bool mvpp22_rx_hwtstamping(struct 
mvpp2_port *port)
 {
return IS_ENABLED(CONFIG_MVPP2_PTP) && port->rx_hwtstamp;
 }
+
 #endif
diff --git a/drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c 
b/drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c
index 3faad04..a472125 100644
--- a/drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c
+++ b/drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c
@@ -6536,6 +6536,8 @@ static void mvpp2_mac_link_up(struct phylink_config 
*config,
mvpp2_bm_pool_update_fc(port, port->pool_long, 
tx_pause);
mvpp2_bm_pool_update_fc(port, port->pool_short, 
tx_pause);
}
+   if (port->priv->hw_version == MVPP23)
+   mvpp23_rx_fifo_fc_en(port->priv, port->id, tx_pause);
}
 
mvpp2_port_enable(port);
@@ -7004,6 +7006,55 @@ static void mvpp22_rx_fifo_init(struct mvpp2 *priv)
mvpp2_write(priv, MVPP2_RX_FIFO_INIT_REG, 0x1);
 }
 
+/* Configure Rx FIFO Flow control thresholds */
+static void mvpp23_rx_fifo_fc_set_tresh(struct mvpp2 *priv)
+{
+   int port, val;
+
+   /* Port 0: maximum speed -10Gb/s port
+* required by spec RX FIFO threshold 9KB
+* Port 1: maximum speed -5Gb/s port
+* required by spec RX FIFO threshold 4KB
+* Port 2: maximum speed -1Gb/s port
+* required by spec RX FIFO threshold 2KB
+*/
+
+   /* Without loopback port */
+   for (port = 0; port < (MVPP2_MAX_PORTS - 1); port++) {
+   if (port == 0) {
+   val = (MVPP23_PORT0_FIFO_TRSH / MVPP2_RX_FC_TRSH_UNIT)
+   << MVPP2_RX_FC_TRSH_OFFS;
+   val &= MVPP2_RX_FC_TRSH_MASK;
+   mvpp2_write(priv, MVPP2_RX_FC_REG(port), val);
+   } else if (port == 1) {
+   val = (MVPP23_PORT1_FIFO_TRSH / MVPP2_RX_FC_TRSH_UNIT)
+   << MVPP2_RX_FC_TRSH_OFFS;
+   val &= MVPP2_RX_FC_TRSH_MASK;
+   mvpp2_write(priv, MVPP2_RX_FC_REG(port), val);
+   } else {
+   val = (MVPP23_PORT2_FIFO_TRSH / MVPP2_RX_FC_TRSH_UNIT)
+   << MVPP2_RX_FC_TRSH_OFFS;
+   val &= MVPP2_RX_FC_TRSH_MASK;
+   mvpp2_write(priv, MVPP2_RX_FC_REG(port), val);
+   }
+   }
+}
+
+/* Configure Rx FIFO Flow control thresholds */
+void mvpp23_rx_fifo_fc_en(struct mvpp2 *priv, int port, bool en)
+{
+   int val;
+
+   val = mvpp2_read(priv, MVPP2_RX_FC_REG(port));
+
+   if (en)
+   val |= MVPP2_RX_FC_EN;
+   else
+   val &= ~MVPP2_RX_FC_EN;
+
+   mvpp2_write(priv, MVPP2_RX_FC_REG(port), val);
+}
+
 static void mvpp22_tx_fifo_set_hw(struct mvpp2 *priv, int port, int size)
 {
int threshold = MVPP2_TX_FIFO_THRESHOLD(size);
@@ -7155,6 +7206,8 @@ static int mvpp2_init(struct platform_device *pdev, 
struct mvpp2 *priv)
} else {
mvp

[PATCH v12 net-next 11/15] net: mvpp2: add ethtool flow control configuration support

2021-02-10 Thread stefanc
From: Stefan Chulski 

This patch add ethtool flow control configuration support.

Tx flow control retrieved correctly by ethtool get function.
FW per port ethtool configuration capability added.

Patch also takes care about mtu change procedure, if PPv2 switch
BM pools during mtu change.

Signed-off-by: Stefan Chulski 
Acked-by: Marcin Wojtas 
---
 drivers/net/ethernet/marvell/mvpp2/mvpp2.h  | 13 +++
 drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c | 98 
 2 files changed, 111 insertions(+)

diff --git a/drivers/net/ethernet/marvell/mvpp2/mvpp2.h 
b/drivers/net/ethernet/marvell/mvpp2/mvpp2.h
index 0010a3e9..0731dc7 100644
--- a/drivers/net/ethernet/marvell/mvpp2/mvpp2.h
+++ b/drivers/net/ethernet/marvell/mvpp2/mvpp2.h
@@ -774,6 +774,19 @@
 #define MSS_RXQ_TRESH_REG(q, fq)   (MSS_RXQ_TRESH_BASE + (((q) + (fq)) \
* MSS_RXQ_TRESH_OFFS))
 
+#define MSS_BUF_POOL_BASE  0x40
+#define MSS_BUF_POOL_OFFS  4
+#define MSS_BUF_POOL_REG(id)   (MSS_BUF_POOL_BASE  \
+   + (id) * MSS_BUF_POOL_OFFS)
+
+#define MSS_BUF_POOL_STOP_MASK 0xFFF
+#define MSS_BUF_POOL_START_MASK(0xFFF << 
MSS_BUF_POOL_START_OFFS)
+#define MSS_BUF_POOL_START_OFFS12
+#define MSS_BUF_POOL_PORTS_MASK(0xF << MSS_BUF_POOL_PORTS_OFFS)
+#define MSS_BUF_POOL_PORTS_OFFS24
+#define MSS_BUF_POOL_PORT_OFFS(id) (0x1 << \
+   ((id) + MSS_BUF_POOL_PORTS_OFFS))
+
 #define MSS_RXQ_TRESH_START_MASK   0x
 #define MSS_RXQ_TRESH_STOP_MASK(0x << 
MSS_RXQ_TRESH_STOP_OFFS)
 #define MSS_RXQ_TRESH_STOP_OFFS16
diff --git a/drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c 
b/drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c
index f1770e5..90c9265 100644
--- a/drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c
+++ b/drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c
@@ -845,6 +845,59 @@ static void mvpp2_rxq_disable_fc(struct mvpp2_port *port)
spin_unlock_irqrestore(&port->priv->mss_spinlock, flags);
 }
 
+/* Routine disable/enable flow control for BM pool condition */
+static void mvpp2_bm_pool_update_fc(struct mvpp2_port *port,
+   struct mvpp2_bm_pool *pool,
+   bool en)
+{
+   int val, cm3_state;
+   unsigned long flags;
+
+   spin_lock_irqsave(&port->priv->mss_spinlock, flags);
+
+   /* Remove Flow control enable bit to prevent race between FW and Kernel
+* If Flow control were enabled, it would be re-enabled.
+*/
+   val = mvpp2_cm3_read(port->priv, MSS_FC_COM_REG);
+   cm3_state = (val & FLOW_CONTROL_ENABLE_BIT);
+   val &= ~FLOW_CONTROL_ENABLE_BIT;
+   mvpp2_cm3_write(port->priv, MSS_FC_COM_REG, val);
+
+   /* Check if BM pool should be enabled/disable */
+   if (en) {
+   /* Set BM pool start and stop thresholds per port */
+   val = mvpp2_cm3_read(port->priv, MSS_BUF_POOL_REG(pool->id));
+   val |= MSS_BUF_POOL_PORT_OFFS(port->id);
+   val &= ~MSS_BUF_POOL_START_MASK;
+   val |= (MSS_THRESHOLD_START << MSS_BUF_POOL_START_OFFS);
+   val &= ~MSS_BUF_POOL_STOP_MASK;
+   val |= MSS_THRESHOLD_STOP;
+   mvpp2_cm3_write(port->priv, MSS_BUF_POOL_REG(pool->id), val);
+   } else {
+   /* Remove BM pool from the port */
+   val = mvpp2_cm3_read(port->priv, MSS_BUF_POOL_REG(pool->id));
+   val &= ~MSS_BUF_POOL_PORT_OFFS(port->id);
+
+   /* Zero BM pool start and stop thresholds to disable pool
+* flow control if pool empty (not used by any port)
+*/
+   if (!pool->buf_num) {
+   val &= ~MSS_BUF_POOL_START_MASK;
+   val &= ~MSS_BUF_POOL_STOP_MASK;
+   }
+
+   mvpp2_cm3_write(port->priv, MSS_BUF_POOL_REG(pool->id), val);
+   }
+
+   /* Notify Firmware that Flow control config space ready for update */
+   val = mvpp2_cm3_read(port->priv, MSS_FC_COM_REG);
+   val |= FLOW_CONTROL_UPDATE_COMMAND_BIT;
+   val |= cm3_state;
+   mvpp2_cm3_write(port->priv, MSS_FC_COM_REG, val);
+
+   spin_unlock_irqrestore(&port->priv->mss_spinlock, flags);
+}
+
 /* Release buffer to BM */
 static inline void mvpp2_bm_pool_put(struct mvpp2_port *port, int pool,
 dma_addr_t buf_dma_addr,
@@ -1175,6 +1228,16 @@ static int mvpp2_bm_update_mtu(struct net_device *dev, 
int mtu)
new_long_pool = MVPP2_BM_LONG;
 
if (new_long_pool != port->pool_long->id) {
+   if (port->tx_fc) {
+   if (pkt_size > MVPP2_BM_LONG_PKT_SIZE)
+   mvpp2_bm_pool_update_fc(port,
+  

[PATCH v12 net-next 10/15] net: mvpp2: add RXQ flow control configurations

2021-02-10 Thread stefanc
From: Stefan Chulski 

This patch adds RXQ flow control configurations.
Flow control disabled by default.
Minimum ring size limited to 1024 descriptors.

Signed-off-by: Stefan Chulski 
Acked-by: Marcin Wojtas 
---
 drivers/net/ethernet/marvell/mvpp2/mvpp2.h  |  35 +-
 drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c | 116 
 2 files changed, 150 insertions(+), 1 deletion(-)

diff --git a/drivers/net/ethernet/marvell/mvpp2/mvpp2.h 
b/drivers/net/ethernet/marvell/mvpp2/mvpp2.h
index 8945fb9..0010a3e9 100644
--- a/drivers/net/ethernet/marvell/mvpp2/mvpp2.h
+++ b/drivers/net/ethernet/marvell/mvpp2/mvpp2.h
@@ -765,9 +765,36 @@
 /* MSS Flow control */
 #define MSS_FC_COM_REG 0
 #define FLOW_CONTROL_ENABLE_BITBIT(0)
+#define FLOW_CONTROL_UPDATE_COMMAND_BITBIT(31)
 #define FC_QUANTA  0x
 #define FC_CLK_DIVIDER 100
-#define MSS_THRESHOLD_STOP 768
+
+#define MSS_RXQ_TRESH_BASE 0x200
+#define MSS_RXQ_TRESH_OFFS 4
+#define MSS_RXQ_TRESH_REG(q, fq)   (MSS_RXQ_TRESH_BASE + (((q) + (fq)) \
+   * MSS_RXQ_TRESH_OFFS))
+
+#define MSS_RXQ_TRESH_START_MASK   0x
+#define MSS_RXQ_TRESH_STOP_MASK(0x << 
MSS_RXQ_TRESH_STOP_OFFS)
+#define MSS_RXQ_TRESH_STOP_OFFS16
+
+#define MSS_RXQ_ASS_BASE   0x80
+#define MSS_RXQ_ASS_OFFS   4
+#define MSS_RXQ_ASS_PER_REG4
+#define MSS_RXQ_ASS_PER_OFFS   8
+#define MSS_RXQ_ASS_PORTID_OFFS0
+#define MSS_RXQ_ASS_PORTID_MASK0x3
+#define MSS_RXQ_ASS_HOSTID_OFFS2
+#define MSS_RXQ_ASS_HOSTID_MASK0x3F
+
+#define MSS_RXQ_ASS_Q_BASE(q, fq) q) + (fq)) % MSS_RXQ_ASS_PER_REG)
 \
+ * MSS_RXQ_ASS_PER_OFFS)
+#define MSS_RXQ_ASS_PQ_BASE(q, fq) q) + (fq)) / MSS_RXQ_ASS_PER_REG) \
+  * MSS_RXQ_ASS_OFFS)
+#define MSS_RXQ_ASS_REG(q, fq) (MSS_RXQ_ASS_BASE + MSS_RXQ_ASS_PQ_BASE(q, fq))
+
+#define MSS_THRESHOLD_STOP 768
+#define MSS_THRESHOLD_START1024
 
 /* RX buffer constants */
 #define MVPP2_SKB_SHINFO_SIZE \
@@ -1022,6 +1049,9 @@ struct mvpp2 {
 
/* Global TX Flow Control config */
bool global_tx_fc;
+
+   /* Spinlocks for CM3 shared memory configuration */
+   spinlock_t mss_spinlock;
 };
 
 struct mvpp2_pcpu_stats {
@@ -1184,6 +1214,9 @@ struct mvpp2_port {
bool rx_hwtstamp;
enum hwtstamp_tx_types tx_hwtstamp_type;
struct mvpp2_hwtstamp_queue tx_hwtstamp_queue[2];
+
+   /* Firmware TX flow control */
+   bool tx_fc;
 };
 
 /* The mvpp2_tx_desc and mvpp2_rx_desc structures describe the
diff --git a/drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c 
b/drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c
index 027101b..f1770e5 100644
--- a/drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c
+++ b/drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c
@@ -741,6 +741,110 @@ static void *mvpp2_buf_alloc(struct mvpp2_port *port,
return data;
 }
 
+/* Routine enable flow control for RXQs condition */
+static void mvpp2_rxq_enable_fc(struct mvpp2_port *port)
+{
+   int val, cm3_state, host_id, q;
+   int fq = port->first_rxq;
+   unsigned long flags;
+
+   spin_lock_irqsave(&port->priv->mss_spinlock, flags);
+
+   /* Remove Flow control enable bit to prevent race between FW and Kernel
+* If Flow control was enabled, it would be re-enabled.
+*/
+   val = mvpp2_cm3_read(port->priv, MSS_FC_COM_REG);
+   cm3_state = (val & FLOW_CONTROL_ENABLE_BIT);
+   val &= ~FLOW_CONTROL_ENABLE_BIT;
+   mvpp2_cm3_write(port->priv, MSS_FC_COM_REG, val);
+
+   /* Set same Flow control for all RXQs */
+   for (q = 0; q < port->nrxqs; q++) {
+   /* Set stop and start Flow control RXQ thresholds */
+   val = MSS_THRESHOLD_START;
+   val |= (MSS_THRESHOLD_STOP << MSS_RXQ_TRESH_STOP_OFFS);
+   mvpp2_cm3_write(port->priv, MSS_RXQ_TRESH_REG(q, fq), val);
+
+   val = mvpp2_cm3_read(port->priv, MSS_RXQ_ASS_REG(q, fq));
+   /* Set RXQ port ID */
+   val &= ~(MSS_RXQ_ASS_PORTID_MASK << MSS_RXQ_ASS_Q_BASE(q, fq));
+   val |= (port->id << MSS_RXQ_ASS_Q_BASE(q, fq));
+   val &= ~(MSS_RXQ_ASS_HOSTID_MASK << (MSS_RXQ_ASS_Q_BASE(q, fq)
+   + MSS_RXQ_ASS_HOSTID_OFFS));
+
+   /* Calculate RXQ host ID:
+* In Single queue mode: Host ID equal to Host ID used for
+*   shared RX interrupt
+* In Multi queue mode: Host ID equal to number of
+*  RXQ ID / number of CoS queues
+* In Single resource mode: Host ID always equal to 0
+*/
+   if (queue_mode == MVPP2_QDIST_SINGLE_MODE)
+   host_id = port->nqvecs;
+

[PATCH v12 net-next 09/15] net: mvpp2: enable global flow control

2021-02-10 Thread stefanc
From: Stefan Chulski 

This patch enables global flow control in FW and in the phylink validate mask.

Signed-off-by: Stefan Chulski 
Acked-by: Marcin Wojtas 
---
 drivers/net/ethernet/marvell/mvpp2/mvpp2.h  | 11 +--
 drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c | 30 +++-
 2 files changed, 37 insertions(+), 4 deletions(-)

diff --git a/drivers/net/ethernet/marvell/mvpp2/mvpp2.h 
b/drivers/net/ethernet/marvell/mvpp2/mvpp2.h
index d2cc513c..8945fb9 100644
--- a/drivers/net/ethernet/marvell/mvpp2/mvpp2.h
+++ b/drivers/net/ethernet/marvell/mvpp2/mvpp2.h
@@ -763,9 +763,11 @@
((kb) * 1024 - MVPP2_TX_FIFO_THRESHOLD_MIN)
 
 /* MSS Flow control */
-#define FC_QUANTA  0x
-#define FC_CLK_DIVIDER 100
-#define MSS_THRESHOLD_STOP 768
+#define MSS_FC_COM_REG 0
+#define FLOW_CONTROL_ENABLE_BITBIT(0)
+#define FC_QUANTA  0x
+#define FC_CLK_DIVIDER 100
+#define MSS_THRESHOLD_STOP 768
 
 /* RX buffer constants */
 #define MVPP2_SKB_SHINFO_SIZE \
@@ -1017,6 +1019,9 @@ struct mvpp2 {
 
/* page_pool allocator */
struct page_pool *page_pool[MVPP2_PORT_MAX_RXQ];
+
+   /* Global TX Flow Control config */
+   bool global_tx_fc;
 };
 
 struct mvpp2_pcpu_stats {
diff --git a/drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c 
b/drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c
index 8b4073c..027101b 100644
--- a/drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c
+++ b/drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c
@@ -91,6 +91,16 @@ static inline u32 mvpp2_cpu_to_thread(struct mvpp2 *priv, 
int cpu)
return cpu % priv->nthreads;
 }
 
+static void mvpp2_cm3_write(struct mvpp2 *priv, u32 offset, u32 data)
+{
+   writel(data, priv->cm3_base + offset);
+}
+
+static u32 mvpp2_cm3_read(struct mvpp2 *priv, u32 offset)
+{
+   return readl(priv->cm3_base + offset);
+}
+
 static struct page_pool *
 mvpp2_create_page_pool(struct device *dev, int num, int len,
   enum dma_data_direction dma_dir)
@@ -5950,6 +5960,11 @@ static void mvpp2_phylink_validate(struct phylink_config 
*config,
phylink_set(mask, Autoneg);
phylink_set_port_modes(mask);
 
+   if (port->priv->global_tx_fc) {
+   phylink_set(mask, Pause);
+   phylink_set(mask, Asym_Pause);
+   }
+
switch (state->interface) {
case PHY_INTERFACE_MODE_10GBASER:
case PHY_INTERFACE_MODE_XAUI:
@@ -6951,7 +6966,7 @@ static int mvpp2_probe(struct platform_device *pdev)
struct resource *res;
void __iomem *base;
int i, shared;
-   int err;
+   int err, val;
 
priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL);
if (!priv)
@@ -7003,6 +7018,10 @@ static int mvpp2_probe(struct platform_device *pdev)
err = mvpp2_get_sram(pdev, priv);
if (err)
dev_warn(&pdev->dev, "Fail to alloc CM3 SRAM\n");
+
+   /* Enable global Flow Control only if handler to SRAM not NULL 
*/
+   if (priv->cm3_base)
+   priv->global_tx_fc = true;
}
 
if (priv->hw_version != MVPP21 && dev_of_node(&pdev->dev)) {
@@ -7168,6 +7187,15 @@ static int mvpp2_probe(struct platform_device *pdev)
goto err_port_probe;
}
 
+   /* Enable global flow control. In this stage global
+* flow control enabled, but still disabled per port.
+*/
+   if (priv->global_tx_fc && priv->hw_version != MVPP21) {
+   val = mvpp2_cm3_read(priv, MSS_FC_COM_REG);
+   val |= FLOW_CONTROL_ENABLE_BIT;
+   mvpp2_cm3_write(priv, MSS_FC_COM_REG, val);
+   }
+
mvpp2_dbgfs_init(priv, pdev->name);
 
platform_set_drvdata(pdev, priv);
-- 
1.9.1



[PATCH v12 net-next 07/15] net: mvpp2: add FCA periodic timer configurations

2021-02-10 Thread stefanc
From: Stefan Chulski 

Flow Control periodic timer would be used if port in
XOFF to transmit periodic XOFF frames.

Signed-off-by: Stefan Chulski 
Acked-by: Marcin Wojtas 
---
 drivers/net/ethernet/marvell/mvpp2/mvpp2.h  | 13 ++
 drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c | 45 
 2 files changed, 58 insertions(+)

diff --git a/drivers/net/ethernet/marvell/mvpp2/mvpp2.h 
b/drivers/net/ethernet/marvell/mvpp2/mvpp2.h
index e7bbf0a..9239d80 100644
--- a/drivers/net/ethernet/marvell/mvpp2/mvpp2.h
+++ b/drivers/net/ethernet/marvell/mvpp2/mvpp2.h
@@ -596,6 +596,15 @@
 #define MVPP22_MPCS_CLK_RESET_DIV_RATIO(n) ((n) << 4)
 #define MVPP22_MPCS_CLK_RESET_DIV_SET  BIT(11)
 
+/* FCA registers. PPv2.2 and PPv2.3 */
+#define MVPP22_FCA_BASE(port)  (0x7600 + (port) * 0x1000)
+#define MVPP22_FCA_REG_SIZE16
+#define MVPP22_FCA_REG_MASK0x
+#define MVPP22_FCA_CONTROL_REG 0x0
+#define MVPP22_FCA_ENABLE_PERIODIC BIT(11)
+#define MVPP22_PERIODIC_COUNTER_LSB_REG(0x110)
+#define MVPP22_PERIODIC_COUNTER_MSB_REG(0x114)
+
 /* XPCS registers. PPv2.2 and PPv2.3 */
 #define MVPP22_XPCS_BASE(port) (0x7400 + (port) * 0x1000)
 #define MVPP22_XPCS_CFG0   0x0
@@ -751,6 +760,10 @@
 #define MVPP2_TX_FIFO_THRESHOLD(kb)\
((kb) * 1024 - MVPP2_TX_FIFO_THRESHOLD_MIN)
 
+/* MSS Flow control */
+#define FC_QUANTA  0x
+#define FC_CLK_DIVIDER 100
+
 /* RX buffer constants */
 #define MVPP2_SKB_SHINFO_SIZE \
SKB_DATA_ALIGN(sizeof(struct skb_shared_info))
diff --git a/drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c 
b/drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c
index 5730900..761f745 100644
--- a/drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c
+++ b/drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c
@@ -1280,6 +1280,49 @@ static void mvpp22_gop_init_10gkr(struct mvpp2_port 
*port)
writel(val, mpcs + MVPP22_MPCS_CLK_RESET);
 }
 
+static void mvpp22_gop_fca_enable_periodic(struct mvpp2_port *port, bool en)
+{
+   struct mvpp2 *priv = port->priv;
+   void __iomem *fca = priv->iface_base + MVPP22_FCA_BASE(port->gop_id);
+   u32 val;
+
+   val = readl(fca + MVPP22_FCA_CONTROL_REG);
+   val &= ~MVPP22_FCA_ENABLE_PERIODIC;
+   if (en)
+   val |= MVPP22_FCA_ENABLE_PERIODIC;
+   writel(val, fca + MVPP22_FCA_CONTROL_REG);
+}
+
+static void mvpp22_gop_fca_set_timer(struct mvpp2_port *port, u32 timer)
+{
+   struct mvpp2 *priv = port->priv;
+   void __iomem *fca = priv->iface_base + MVPP22_FCA_BASE(port->gop_id);
+   u32 lsb, msb;
+
+   lsb = timer & MVPP22_FCA_REG_MASK;
+   msb = timer >> MVPP22_FCA_REG_SIZE;
+
+   writel(lsb, fca + MVPP22_PERIODIC_COUNTER_LSB_REG);
+   writel(msb, fca + MVPP22_PERIODIC_COUNTER_MSB_REG);
+}
+
+/* Set Flow Control timer x100 faster than pause quanta to ensure that link
+ * partner won't send traffic if port is in XOFF mode.
+ */
+static void mvpp22_gop_fca_set_periodic_timer(struct mvpp2_port *port)
+{
+   u32 timer;
+
+   timer = (port->priv->tclk / (USEC_PER_SEC * FC_CLK_DIVIDER))
+   * FC_QUANTA;
+
+   mvpp22_gop_fca_enable_periodic(port, false);
+
+   mvpp22_gop_fca_set_timer(port, timer);
+
+   mvpp22_gop_fca_enable_periodic(port, true);
+}
+
 static int mvpp22_gop_init(struct mvpp2_port *port)
 {
struct mvpp2 *priv = port->priv;
@@ -1324,6 +1367,8 @@ static int mvpp22_gop_init(struct mvpp2_port *port)
val |= GENCONF_SOFT_RESET1_GOP;
regmap_write(priv->sysctrl_base, GENCONF_SOFT_RESET1, val);
 
+   mvpp22_gop_fca_set_periodic_timer(port);
+
 unsupported_conf:
return 0;
 
-- 
1.9.1



[PATCH v12 net-next 08/15] net: mvpp2: add FCA RXQ non occupied descriptor threshold

2021-02-10 Thread stefanc
From: Stefan Chulski 

The firmware needs to monitor the RX Non-occupied descriptor
bits for flow control to move to XOFF mode.
These bits need to be unmasked to be functional, but they will
not raise interrupts as we leave the RX exception summary
bit in MVPP2_ISR_RX_TX_MASK_REG clear.

Signed-off-by: Stefan Chulski 
Acked-by: Marcin Wojtas 
---
 drivers/net/ethernet/marvell/mvpp2/mvpp2.h  |  3 ++
 drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c | 44 
 2 files changed, 40 insertions(+), 7 deletions(-)

diff --git a/drivers/net/ethernet/marvell/mvpp2/mvpp2.h 
b/drivers/net/ethernet/marvell/mvpp2/mvpp2.h
index 9239d80..d2cc513c 100644
--- a/drivers/net/ethernet/marvell/mvpp2/mvpp2.h
+++ b/drivers/net/ethernet/marvell/mvpp2/mvpp2.h
@@ -295,6 +295,8 @@
 #define MVPP2_PON_CAUSE_TXP_OCCUP_DESC_ALL_MASK0x3fc0
 #define MVPP2_PON_CAUSE_MISC_SUM_MASK  BIT(31)
 #define MVPP2_ISR_MISC_CAUSE_REG   0x55b0
+#define MVPP2_ISR_RX_ERR_CAUSE_REG(port)   (0x5520 + 4 * (port))
+#define MVPP2_ISR_RX_ERR_CAUSE_NONOCC_MASK 0x00ff
 
 /* Buffer Manager registers */
 #define MVPP2_BM_POOL_BASE_REG(pool)   (0x6000 + ((pool) * 4))
@@ -763,6 +765,7 @@
 /* MSS Flow control */
 #define FC_QUANTA  0x
 #define FC_CLK_DIVIDER 100
+#define MSS_THRESHOLD_STOP 768
 
 /* RX buffer constants */
 #define MVPP2_SKB_SHINFO_SIZE \
diff --git a/drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c 
b/drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c
index 761f745..8b4073c 100644
--- a/drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c
+++ b/drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c
@@ -1133,14 +1133,19 @@ static inline void mvpp2_qvec_interrupt_disable(struct 
mvpp2_queue_vector *qvec)
 static void mvpp2_interrupts_mask(void *arg)
 {
struct mvpp2_port *port = arg;
+   int cpu = smp_processor_id();
+   u32 thread;
 
/* If the thread isn't used, don't do anything */
-   if (smp_processor_id() > port->priv->nthreads)
+   if (cpu > port->priv->nthreads)
return;
 
-   mvpp2_thread_write(port->priv,
-  mvpp2_cpu_to_thread(port->priv, smp_processor_id()),
+   thread = mvpp2_cpu_to_thread(port->priv, cpu);
+
+   mvpp2_thread_write(port->priv, thread,
   MVPP2_ISR_RX_TX_MASK_REG(port->id), 0);
+   mvpp2_thread_write(port->priv, thread,
+  MVPP2_ISR_RX_ERR_CAUSE_REG(port->id), 0);
 }
 
 /* Unmask the current thread's Rx/Tx interrupts.
@@ -1150,20 +1155,25 @@ static void mvpp2_interrupts_mask(void *arg)
 static void mvpp2_interrupts_unmask(void *arg)
 {
struct mvpp2_port *port = arg;
-   u32 val;
+   int cpu = smp_processor_id();
+   u32 val, thread;
 
/* If the thread isn't used, don't do anything */
-   if (smp_processor_id() > port->priv->nthreads)
+   if (cpu > port->priv->nthreads)
return;
 
+   thread = mvpp2_cpu_to_thread(port->priv, cpu);
+
val = MVPP2_CAUSE_MISC_SUM_MASK |
MVPP2_CAUSE_RXQ_OCCUP_DESC_ALL_MASK(port->priv->hw_version);
if (port->has_tx_irqs)
val |= MVPP2_CAUSE_TXQ_OCCUP_DESC_ALL_MASK;
 
-   mvpp2_thread_write(port->priv,
-  mvpp2_cpu_to_thread(port->priv, smp_processor_id()),
+   mvpp2_thread_write(port->priv, thread,
   MVPP2_ISR_RX_TX_MASK_REG(port->id), val);
+   mvpp2_thread_write(port->priv, thread,
+  MVPP2_ISR_RX_ERR_CAUSE_REG(port->id),
+  MVPP2_ISR_RX_ERR_CAUSE_NONOCC_MASK);
 }
 
 static void
@@ -1188,6 +1198,9 @@ static void mvpp2_interrupts_unmask(void *arg)
 
mvpp2_thread_write(port->priv, v->sw_thread_id,
   MVPP2_ISR_RX_TX_MASK_REG(port->id), val);
+   mvpp2_thread_write(port->priv, v->sw_thread_id,
+  MVPP2_ISR_RX_ERR_CAUSE_REG(port->id),
+  MVPP2_ISR_RX_ERR_CAUSE_NONOCC_MASK);
}
 }
 
@@ -2393,6 +2406,20 @@ static void mvpp2_txp_max_tx_size_set(struct mvpp2_port 
*port)
}
 }
 
+/* Set the number of non-occupied descriptors threshold */
+static void mvpp2_set_rxq_free_tresh(struct mvpp2_port *port,
+struct mvpp2_rx_queue *rxq)
+{
+   u32 val;
+
+   mvpp2_write(port->priv, MVPP2_RXQ_NUM_REG, rxq->id);
+
+   val = mvpp2_read(port->priv, MVPP2_RXQ_THRESH_REG);
+   val &= ~MVPP2_RXQ_NON_OCCUPIED_MASK;
+   val |= MSS_THRESHOLD_STOP << MVPP2_RXQ_NON_OCCUPIED_OFFSET;
+   mvpp2_write(port->priv, MVPP2_RXQ_THRESH_REG, val);
+}
+
 /* Set the number of packets that will be received before Rx interrupt
  * will be generated by HW.
  */
@@ -2648,6 +2675,9 @@ static int mvpp2_rxq_init(struct mvpp2_port *port,
mvpp2_rx_pkts_coal_set(port, rxq);
mvpp2_rx_time_coal_set(port, rxq);
 
+  

[PATCH v12 net-next 06/15] net: mvpp2: increase BM pool and RXQ size

2021-02-10 Thread stefanc
From: Stefan Chulski 

BM pool and RXQ size increased to support Firmware Flow Control.
Minimum depletion thresholds to support FC are 1024 buffers.
BM pool size increased to 2048 to have some 1024 buffers
space between depletion thresholds and BM pool size.

Jumbo frames require a 9888B buffer, so memory requirements
for data buffers increased from 7MB to 24MB.

Signed-off-by: Stefan Chulski 
Acked-by: Marcin Wojtas 
---
 drivers/net/ethernet/marvell/mvpp2/mvpp2.h | 8 
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/drivers/net/ethernet/marvell/mvpp2/mvpp2.h 
b/drivers/net/ethernet/marvell/mvpp2/mvpp2.h
index ce08086..e7bbf0a 100644
--- a/drivers/net/ethernet/marvell/mvpp2/mvpp2.h
+++ b/drivers/net/ethernet/marvell/mvpp2/mvpp2.h
@@ -715,8 +715,8 @@
 #define MVPP2_PORT_MAX_RXQ 32
 
 /* Max number of Rx descriptors */
-#define MVPP2_MAX_RXD_MAX  1024
-#define MVPP2_MAX_RXD_DFLT 128
+#define MVPP2_MAX_RXD_MAX  2048
+#define MVPP2_MAX_RXD_DFLT 1024
 
 /* Max number of Tx descriptors */
 #define MVPP2_MAX_TXD_MAX  2048
@@ -848,8 +848,8 @@ enum mvpp22_ptp_packet_format {
 #define MVPP22_PTP_TIMESTAMPQUEUESELECTBIT(18)
 
 /* BM constants */
-#define MVPP2_BM_JUMBO_BUF_NUM 512
-#define MVPP2_BM_LONG_BUF_NUM  1024
+#define MVPP2_BM_JUMBO_BUF_NUM 2048
+#define MVPP2_BM_LONG_BUF_NUM  2048
 #define MVPP2_BM_SHORT_BUF_NUM 2048
 #define MVPP2_BM_POOL_SIZE_MAX (16*1024 - MVPP2_BM_POOL_PTR_ALIGN/4)
 #define MVPP2_BM_POOL_PTR_ALIGN128
-- 
1.9.1



[PATCH v12 net-next 05/15] net: mvpp2: add PPv23 version definition

2021-02-10 Thread stefanc
From: Stefan Chulski 

This patch add PPv23 version definition.
PPv23 is new packet processor in CP115.
Everything that supported by PPv22, also supported by PPv23.
No functional changes in this stage.

Signed-off-by: Stefan Chulski 
Acked-by: Marcin Wojtas 
---
 drivers/net/ethernet/marvell/mvpp2/mvpp2.h  | 24 
 drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c | 15 
 2 files changed, 24 insertions(+), 15 deletions(-)

diff --git a/drivers/net/ethernet/marvell/mvpp2/mvpp2.h 
b/drivers/net/ethernet/marvell/mvpp2/mvpp2.h
index 56e90ab..ce08086 100644
--- a/drivers/net/ethernet/marvell/mvpp2/mvpp2.h
+++ b/drivers/net/ethernet/marvell/mvpp2/mvpp2.h
@@ -60,6 +60,9 @@
 /* Top Registers */
 #define MVPP2_MH_REG(port) (0x5040 + 4 * (port))
 #define MVPP2_DSA_EXTENDED BIT(5)
+#define MVPP2_VER_ID_REG   0x50b0
+#define MVPP2_VER_PP22 0x10
+#define MVPP2_VER_PP23 0x11
 
 /* Parser Registers */
 #define MVPP2_PRS_INIT_LOOKUP_REG  0x1000
@@ -469,7 +472,7 @@
 #define MVPP22_GMAC_INT_SUM_MASK_LINK_STAT BIT(1)
 #defineMVPP22_GMAC_INT_SUM_MASK_PTPBIT(2)
 
-/* Per-port XGMAC registers. PPv2.2 only, only for GOP port 0,
+/* Per-port XGMAC registers. PPv2.2 and PPv2.3, only for GOP port 0,
  * relative to port->base.
  */
 #define MVPP22_XLG_CTRL0_REG   0x100
@@ -506,7 +509,7 @@
 #define MVPP22_XLG_CTRL4_MACMODSELECT_GMAC BIT(12)
 #define MVPP22_XLG_CTRL4_EN_IDLE_CHECK BIT(14)
 
-/* SMI registers. PPv2.2 only, relative to priv->iface_base. */
+/* SMI registers. PPv2.2 and PPv2.3, relative to priv->iface_base. */
 #define MVPP22_SMI_MISC_CFG_REG0x1204
 #define MVPP22_SMI_POLLING_EN  BIT(10)
 
@@ -582,7 +585,7 @@
 #define MVPP2_QUEUE_NEXT_DESC(q, index) \
(((index) < (q)->last_desc) ? ((index) + 1) : 0)
 
-/* XPCS registers. PPv2.2 only */
+/* XPCS registers.PPv2.2 and PPv2.3 */
 #define MVPP22_MPCS_BASE(port) (0x7000 + (port) * 0x1000)
 #define MVPP22_MPCS_CTRL   0x14
 #define MVPP22_MPCS_CTRL_FWD_ERR_CONN  BIT(10)
@@ -593,7 +596,7 @@
 #define MVPP22_MPCS_CLK_RESET_DIV_RATIO(n) ((n) << 4)
 #define MVPP22_MPCS_CLK_RESET_DIV_SET  BIT(11)
 
-/* XPCS registers. PPv2.2 only */
+/* XPCS registers. PPv2.2 and PPv2.3 */
 #define MVPP22_XPCS_BASE(port) (0x7400 + (port) * 0x1000)
 #define MVPP22_XPCS_CFG0   0x0
 #define MVPP22_XPCS_CFG0_RESET_DIS BIT(0)
@@ -927,15 +930,16 @@ struct mvpp2 {
void __iomem *iface_base;
void __iomem *cm3_base;
 
-   /* On PPv2.2, each "software thread" can access the base
+   /* On PPv2.2 and PPv2.3, each "software thread" can access the base
 * register through a separate address space, each 64 KB apart
 * from each other. Typically, such address spaces will be
 * used per CPU.
 */
void __iomem *swth_base[MVPP2_MAX_THREADS];
 
-   /* On PPv2.2, some port control registers are located into the system
-* controller space. These registers are accessible through a regmap.
+   /* On PPv2.2 and PPv2.3, some port control registers are located into
+* the system controller space. These registers are accessible
+* through a regmap.
 */
struct regmap *sysctrl_base;
 
@@ -977,7 +981,7 @@ struct mvpp2 {
u32 tclk;
 
/* HW version */
-   enum { MVPP21, MVPP22 } hw_version;
+   enum { MVPP21, MVPP22, MVPP23 } hw_version;
 
/* Maximum number of RXQs per port */
unsigned int max_port_rxqs;
@@ -1221,7 +1225,7 @@ struct mvpp21_rx_desc {
__le32 reserved8;
 };
 
-/* HW TX descriptor for PPv2.2 */
+/* HW TX descriptor for PPv2.2 and PPv2.3 */
 struct mvpp22_tx_desc {
__le32 command;
u8  packet_offset;
@@ -1233,7 +1237,7 @@ struct mvpp22_tx_desc {
__le64 buf_cookie_misc;
 };
 
-/* HW RX descriptor for PPv2.2 */
+/* HW RX descriptor for PPv2.2 and PPv2.3 */
 struct mvpp22_rx_desc {
__le32 status;
__le16 reserved1;
diff --git a/drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c 
b/drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c
index 17cd161..5730900 100644
--- a/drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c
+++ b/drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c
@@ -384,7 +384,7 @@ static int mvpp2_bm_pool_create(struct device *dev, struct 
mvpp2 *priv,
if (!IS_ALIGNED(size, 16))
return -EINVAL;
 
-   /* PPv2.1 needs 8 bytes per buffer pointer, PPv2.2 needs 16
+   /* PPv2.1 needs 8 bytes per buffer pointer, PPv2.2 and PPv2.3 needs 16
 * bytes per buffer pointer
 */
if (priv->hw_version == MVPP21)
@@ -5456,7 +5456,7 @@ static void mvpp2_rx_irqs_setup(struct mvpp2_port *port)
return;
}
 
-   /* Handle the

[PATCH v12 net-next 04/15] net: mvpp2: always compare hw-version vs MVPP21

2021-02-10 Thread stefanc
From: Stefan Chulski 

Currently we have PP2v1 and PP2v2 hw-versions, with some different
handlers depending upon condition hw_version = MVPP21/MVPP22.
In a future there will be also PP2v3. Let's use now the generic
"if equal/notEqual MVPP21" for all cases instead of "if MVPP22".

This patch does not change any functionality.
It is not intended to introduce PP2v3.
It just modifies MVPP21/MVPP22 check-condition
bringing it to generic and unified form correct for new-code
introducing and PP2v3 net-next generation.

Signed-off-by: Stefan Chulski 
Acked-by: Marcin Wojtas 
---
 drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c | 38 ++--
 1 file changed, 19 insertions(+), 19 deletions(-)

diff --git a/drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c 
b/drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c
index eec3796..17cd161 100644
--- a/drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c
+++ b/drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c
@@ -319,7 +319,7 @@ static int mvpp2_get_nrxqs(struct mvpp2 *priv)
 {
unsigned int nrxqs;
 
-   if (priv->hw_version == MVPP22 && queue_mode == MVPP2_QDIST_SINGLE_MODE)
+   if (priv->hw_version != MVPP21 && queue_mode == MVPP2_QDIST_SINGLE_MODE)
return 1;
 
/* According to the PPv2.2 datasheet and our experiments on
@@ -446,7 +446,7 @@ static void mvpp2_bm_bufs_get_addrs(struct device *dev, 
struct mvpp2 *priv,
  MVPP2_BM_PHY_ALLOC_REG(bm_pool->id));
*phys_addr = mvpp2_thread_read(priv, thread, MVPP2_BM_VIRT_ALLOC_REG);
 
-   if (priv->hw_version == MVPP22) {
+   if (priv->hw_version != MVPP21) {
u32 val;
u32 dma_addr_highbits, phys_addr_highbits;
 
@@ -742,7 +742,7 @@ static inline void mvpp2_bm_pool_put(struct mvpp2_port 
*port, int pool,
if (test_bit(thread, &port->priv->lock_map))
spin_lock_irqsave(&port->bm_lock[thread], flags);
 
-   if (port->priv->hw_version == MVPP22) {
+   if (port->priv->hw_version != MVPP21) {
u32 val = 0;
 
if (sizeof(dma_addr_t) == 8)
@@ -1172,7 +1172,7 @@ static void mvpp2_interrupts_unmask(void *arg)
u32 val;
int i;
 
-   if (port->priv->hw_version != MVPP22)
+   if (port->priv->hw_version == MVPP21)
return;
 
if (mask)
@@ -1199,7 +1199,7 @@ static bool mvpp2_port_supports_xlg(struct mvpp2_port 
*port)
 
 static bool mvpp2_port_supports_rgmii(struct mvpp2_port *port)
 {
-   return !(port->priv->hw_version == MVPP22 && port->gop_id == 0);
+   return !(port->priv->hw_version != MVPP21 && port->gop_id == 0);
 }
 
 /* Port configuration routines */
@@ -1817,7 +1817,7 @@ static void mvpp2_mac_reset_assert(struct mvpp2_port 
*port)
  MVPP2_GMAC_PORT_RESET_MASK;
writel(val, port->base + MVPP2_GMAC_CTRL_2_REG);
 
-   if (port->priv->hw_version == MVPP22 && port->gop_id == 0) {
+   if (port->priv->hw_version != MVPP21 && port->gop_id == 0) {
val = readl(port->base + MVPP22_XLG_CTRL0_REG) &
  ~MVPP22_XLG_CTRL0_MAC_RESET_DIS;
writel(val, port->base + MVPP22_XLG_CTRL0_REG);
@@ -1830,7 +1830,7 @@ static void mvpp22_pcs_reset_assert(struct mvpp2_port 
*port)
void __iomem *mpcs, *xpcs;
u32 val;
 
-   if (port->priv->hw_version != MVPP22 || port->gop_id != 0)
+   if (port->priv->hw_version == MVPP21 || port->gop_id != 0)
return;
 
mpcs = priv->iface_base + MVPP22_MPCS_BASE(port->gop_id);
@@ -1851,7 +1851,7 @@ static void mvpp22_pcs_reset_deassert(struct mvpp2_port 
*port)
void __iomem *mpcs, *xpcs;
u32 val;
 
-   if (port->priv->hw_version != MVPP22 || port->gop_id != 0)
+   if (port->priv->hw_version == MVPP21 || port->gop_id != 0)
return;
 
mpcs = priv->iface_base + MVPP22_MPCS_BASE(port->gop_id);
@@ -4188,7 +4188,7 @@ static void mvpp2_start_dev(struct mvpp2_port *port)
/* Enable interrupts on all threads */
mvpp2_interrupts_enable(port);
 
-   if (port->priv->hw_version == MVPP22)
+   if (port->priv->hw_version != MVPP21)
mvpp22_mode_reconfigure(port);
 
if (port->phylink) {
@@ -4404,7 +4404,7 @@ static int mvpp2_open(struct net_device *dev)
valid = true;
}
 
-   if (priv->hw_version == MVPP22 && port->port_irq) {
+   if (priv->hw_version != MVPP21 && port->port_irq) {
err = request_irq(port->port_irq, mvpp2_port_isr, 0,
  dev->name, port);
if (err) {
@@ -6052,7 +6052,7 @@ static int mvpp2__mac_prepare(struct phylink_config 
*config, unsigned int mode,
 MVPP2_GMAC_PORT_RESET_MASK,
 MVPP2_GMAC_PORT_RESET_MASK);
 
-   if (port->priv->hw_version == MVPP22) {
+   if (port->priv->hw_version != MVPP21) {
  

[PATCH v12 net-next 03/15] net: mvpp2: add CM3 SRAM memory map

2021-02-10 Thread stefanc
From: Stefan Chulski 

This patch adds CM3 memory map.

Signed-off-by: Stefan Chulski 
Reviewed-by: Andrew Lunn 
Acked-by: Marcin Wojtas 
---
 drivers/net/ethernet/marvell/mvpp2/mvpp2.h  |  1 +
 drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c | 26 
 2 files changed, 27 insertions(+)

diff --git a/drivers/net/ethernet/marvell/mvpp2/mvpp2.h 
b/drivers/net/ethernet/marvell/mvpp2/mvpp2.h
index 6bd7e40..56e90ab 100644
--- a/drivers/net/ethernet/marvell/mvpp2/mvpp2.h
+++ b/drivers/net/ethernet/marvell/mvpp2/mvpp2.h
@@ -925,6 +925,7 @@ struct mvpp2 {
/* Shared registers' base addresses */
void __iomem *lms_base;
void __iomem *iface_base;
+   void __iomem *cm3_base;
 
/* On PPv2.2, each "software thread" can access the base
 * register through a separate address space, each 64 KB apart
diff --git a/drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c 
b/drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c
index a07cf60..eec3796 100644
--- a/drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c
+++ b/drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c
@@ -6846,6 +6846,27 @@ static int mvpp2_init(struct platform_device *pdev, 
struct mvpp2 *priv)
return 0;
 }
 
+static int mvpp2_get_sram(struct platform_device *pdev,
+ struct mvpp2 *priv)
+{
+   struct resource *res;
+
+   res = platform_get_resource(pdev, IORESOURCE_MEM, 2);
+   if (!res) {
+   if (has_acpi_companion(&pdev->dev))
+   dev_warn(&pdev->dev, "ACPI is too old, Flow control not 
supported\n");
+   else
+   dev_warn(&pdev->dev, "DT is too old, Flow control not 
supported\n");
+   return 0;
+   }
+
+   priv->cm3_base = devm_ioremap_resource(&pdev->dev, res);
+   if (IS_ERR(priv->cm3_base))
+   return PTR_ERR(priv->cm3_base);
+
+   return 0;
+}
+
 static int mvpp2_probe(struct platform_device *pdev)
 {
const struct acpi_device_id *acpi_id;
@@ -6902,6 +6923,11 @@ static int mvpp2_probe(struct platform_device *pdev)
priv->iface_base = devm_ioremap_resource(&pdev->dev, res);
if (IS_ERR(priv->iface_base))
return PTR_ERR(priv->iface_base);
+
+   /* Map CM3 SRAM */
+   err = mvpp2_get_sram(pdev, priv);
+   if (err)
+   dev_warn(&pdev->dev, "Fail to alloc CM3 SRAM\n");
}
 
if (priv->hw_version == MVPP22 && dev_of_node(&pdev->dev)) {
-- 
1.9.1



[PATCH v12 net-next 02/15] dts: marvell: add CM3 SRAM memory to cp11x ethernet device tree

2021-02-10 Thread stefanc
From: Konstantin Porotchkin 

CM3 SRAM address space will be used for Flow Control configuration.

Signed-off-by: Stefan Chulski 
Signed-off-by: Konstantin Porotchkin 
Acked-by: Marcin Wojtas 
---
 arch/arm64/boot/dts/marvell/armada-cp11x.dtsi | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/arm64/boot/dts/marvell/armada-cp11x.dtsi 
b/arch/arm64/boot/dts/marvell/armada-cp11x.dtsi
index 9dcf16b..6fe0d26 100644
--- a/arch/arm64/boot/dts/marvell/armada-cp11x.dtsi
+++ b/arch/arm64/boot/dts/marvell/armada-cp11x.dtsi
@@ -59,7 +59,7 @@
 
CP11X_LABEL(ethernet): ethernet@0 {
compatible = "marvell,armada-7k-pp22";
-   reg = <0x0 0x10>, <0x129000 0xb000>;
+   reg = <0x0 0x10>, <0x129000 0xb000>, <0x22 
0x800>;
clocks = <&CP11X_LABEL(clk) 1 3>, <&CP11X_LABEL(clk) 1 
9>,
 <&CP11X_LABEL(clk) 1 5>, <&CP11X_LABEL(clk) 1 
6>,
 <&CP11X_LABEL(clk) 1 18>;
-- 
1.9.1



[PATCH v12 net-next 01/15] doc: marvell: add CM3 address space and PPv2.3 description

2021-02-10 Thread stefanc
From: Stefan Chulski 

Patch adds CM3 address space and PPv2.3 description.

Signed-off-by: Stefan Chulski 
Acked-by: Marcin Wojtas 
---
 Documentation/devicetree/bindings/net/marvell-pp2.txt | 6 --
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/Documentation/devicetree/bindings/net/marvell-pp2.txt 
b/Documentation/devicetree/bindings/net/marvell-pp2.txt
index b783976..ce15c17 100644
--- a/Documentation/devicetree/bindings/net/marvell-pp2.txt
+++ b/Documentation/devicetree/bindings/net/marvell-pp2.txt
@@ -1,5 +1,6 @@
 * Marvell Armada 375 Ethernet Controller (PPv2.1)
   Marvell Armada 7K/8K Ethernet Controller (PPv2.2)
+  Marvell CN913X Ethernet Controller (PPv2.3)
 
 Required properties:
 
@@ -12,10 +13,11 @@ Required properties:
- common controller registers
- LMS registers
- one register area per Ethernet port
-  For "marvell,armada-7k-pp2", must contain the following register
+  For "marvell,armada-7k-pp2" used by 7K/8K and CN913X, must contain the 
following register
   sets:
- packet processor registers
- networking interfaces registers
+   - CM3 address space used for TX Flow Control
 
 - clocks: pointers to the reference clocks for this device, consequently:
- main controller clock (for both armada-375-pp2 and armada-7k-pp2)
@@ -81,7 +83,7 @@ Example for marvell,armada-7k-pp2:
 
 cpm_ethernet: ethernet@0 {
compatible = "marvell,armada-7k-pp22";
-   reg = <0x0 0x10>, <0x129000 0xb000>;
+   reg = <0x0 0x10>, <0x129000 0xb000>, <0x22 0x800>;
clocks = <&cpm_syscon0 1 3>, <&cpm_syscon0 1 9>,
 <&cpm_syscon0 1 5>, <&cpm_syscon0 1 6>, <&cpm_syscon0 1 18>;
clock-names = "pp_clk", "gop_clk", "mg_clk", "mg_core_clk", "axi_clk";
-- 
1.9.1



[PATCH v12 net-next 00/15] net: mvpp2: Add TX Flow Control support

2021-02-10 Thread stefanc
From: Stefan Chulski 

Armada hardware has a pause generation mechanism in GOP (MAC).
The GOP generate flow control frames based on an indication programmed in Ports 
Control 0 Register. There is a bit per port.
However assertion of the PortX Pause bits in the ports control 0 register only 
sends a one time pause.
To complement the function the GOP has a mechanism to periodically send pause 
control messages based on periodic counters.
This mechanism ensures that the pause is effective as long as the Appropriate 
PortX Pause is asserted.

Problem is that Packet Processor that actually can drop packets due to lack of 
resources not connected to the GOP flow control generation mechanism.
To solve this issue Armada has firmware running on CM3 CPU dedicated for Flow 
Control support.
Firmware monitors Packet Processor resources and asserts XON/XOFF by writing to 
Ports Control 0 Register.

MSS shared SRAM memory used to communicate between CM3 firmware and PP2 driver.
During init PP2 driver informs firmware about used BM pools, RXQs, congestion 
and depletion thresholds.

The pause frames are generated whenever congestion or depletion in resources is 
detected.
The back pressure is stopped when the resource reaches a sufficient level.
So the congestion/depletion and sufficient level implement a hysteresis that 
reduces the XON/XOFF toggle frequency.

Packet Processor v23 hardware introduces support for RX FIFO fill level monitor.
Patch "add PPv23 version definition" to differ between v23 and v22 hardware.
Patch "add TX FC firmware check" verifies that CM3 firmware supports Flow 
Control monitoring.

v11 --> v12
- Improve warning message in "net: mvpp2: add TX FC firmware check" patch

v10 --> v11
- Improve "net: mvpp2: add CM3 SRAM memory map" comment
- Move condition check to 'net: mvpp2: always compare hw-version vs MVPP21' 
patch

v9 --> v10
- Add CM3 SRAM description to PPv2 documentation

v8 --> v9
- Replace generic pool allocation with devm_ioremap_resource

v7 --> v8
- Reorder "always compare hw-version vs MVPP21" and "add PPv23 version 
definition" commits
- Typo fixes
- Remove condition fix from "add RXQ flow control configurations"

v6 --> v7
- Reduce patch set from 18 to 15 patches
 - Documentation change combined into a single patch
 - RXQ and BM size change combined into a single patch
 - Ring size change check moved into "add RXQ flow control configurations" 
commit

v5 --> v6
- No change

v4 --> v5
- Add missed Signed-off
- Fix warnings in patches 3 and 12
- Add revision requirement to warning message
- Move mss_spinlock into RXQ flow control configurations patch
- Improve FCA RXQ non occupied descriptor threshold commit message

v3 --> v4
- Remove RFC tag

v2 --> v3
- Remove inline functions
- Add PPv2.3 description into marvell-pp2.txt
- Improve mvpp2_interrupts_mask/unmask procedure
- Improve FC enable/disable procedure
- Add priv->sram_pool check
- Remove gen_pool_destroy call
- Reduce Flow Control timer to x100 faster

v1 --> v2
- Add memory requirements information
- Add EPROBE_DEFER if of_gen_pool_get return NULL
- Move Flow control configuration to mvpp2_mac_link_up callback
- Add firmware version info with Flow control support

Konstantin Porotchkin (1):
  dts: marvell: add CM3 SRAM memory to cp11x ethernet device tree

Stefan Chulski (14):
  doc: marvell: add CM3 address space and PPv2.3 description
  net: mvpp2: add CM3 SRAM memory map
  net: mvpp2: always compare hw-version vs MVPP21
  net: mvpp2: add PPv23 version definition
  net: mvpp2: increase BM pool and RXQ size
  net: mvpp2: add FCA periodic timer configurations
  net: mvpp2: add FCA RXQ non occupied descriptor threshold
  net: mvpp2: enable global flow control
  net: mvpp2: add RXQ flow control configurations
  net: mvpp2: add ethtool flow control configuration support
  net: mvpp2: add BM protection underrun feature support
  net: mvpp2: add PPv23 RX FIFO flow control
  net: mvpp2: set 802.3x GoP Flow Control mode
  net: mvpp2: add TX FC firmware check

 Documentation/devicetree/bindings/net/marvell-pp2.txt |   6 +-
 arch/arm64/boot/dts/marvell/armada-cp11x.dtsi |   2 +-
 drivers/net/ethernet/marvell/mvpp2/mvpp2.h| 124 -
 drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c   | 523 
++--
 4 files changed, 606 insertions(+), 49 deletions(-)

-- 
1.9.1



[PATCH v11 net-next 15/15] net: mvpp2: add TX FC firmware check

2021-02-09 Thread stefanc
From: Stefan Chulski 

Patch check that TX FC firmware is running in CM3.
If not, global TX FC would be disabled.

Signed-off-by: Stefan Chulski 
---
 drivers/net/ethernet/marvell/mvpp2/mvpp2.h  |  1 +
 drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c | 42 
 2 files changed, 36 insertions(+), 7 deletions(-)

diff --git a/drivers/net/ethernet/marvell/mvpp2/mvpp2.h 
b/drivers/net/ethernet/marvell/mvpp2/mvpp2.h
index b61a1ba..da87152 100644
--- a/drivers/net/ethernet/marvell/mvpp2/mvpp2.h
+++ b/drivers/net/ethernet/marvell/mvpp2/mvpp2.h
@@ -828,6 +828,7 @@
 
 #define MSS_THRESHOLD_STOP 768
 #define MSS_THRESHOLD_START1024
+#define MSS_FC_MAX_TIMEOUT 5000
 
 /* RX buffer constants */
 #define MVPP2_SKB_SHINFO_SIZE \
diff --git a/drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c 
b/drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c
index 4d0a398..fed4521 100644
--- a/drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c
+++ b/drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c
@@ -931,6 +931,34 @@ static void mvpp2_bm_pool_update_fc(struct mvpp2_port 
*port,
spin_unlock_irqrestore(&port->priv->mss_spinlock, flags);
 }
 
+static int mvpp2_enable_global_fc(struct mvpp2 *priv)
+{
+   int val, timeout = 0;
+
+   /* Enable global flow control. In this stage global
+* flow control enabled, but still disabled per port.
+*/
+   val = mvpp2_cm3_read(priv, MSS_FC_COM_REG);
+   val |= FLOW_CONTROL_ENABLE_BIT;
+   mvpp2_cm3_write(priv, MSS_FC_COM_REG, val);
+
+   /* Check if Firmware running and disable FC if not*/
+   val |= FLOW_CONTROL_UPDATE_COMMAND_BIT;
+   mvpp2_cm3_write(priv, MSS_FC_COM_REG, val);
+
+   while (timeout < MSS_FC_MAX_TIMEOUT) {
+   val = mvpp2_cm3_read(priv, MSS_FC_COM_REG);
+
+   if (!(val & FLOW_CONTROL_UPDATE_COMMAND_BIT))
+   return 0;
+   usleep_range(10, 20);
+   timeout++;
+   }
+
+   priv->global_tx_fc = false;
+   return -EOPNOTSUPP;
+}
+
 /* Release buffer to BM */
 static inline void mvpp2_bm_pool_put(struct mvpp2_port *port, int pool,
 dma_addr_t buf_dma_addr,
@@ -7263,7 +7291,7 @@ static int mvpp2_probe(struct platform_device *pdev)
struct resource *res;
void __iomem *base;
int i, shared;
-   int err, val;
+   int err;
 
priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL);
if (!priv)
@@ -7487,13 +7515,13 @@ static int mvpp2_probe(struct platform_device *pdev)
goto err_port_probe;
}
 
-   /* Enable global flow control. In this stage global
-* flow control enabled, but still disabled per port.
-*/
if (priv->global_tx_fc && priv->hw_version != MVPP21) {
-   val = mvpp2_cm3_read(priv, MSS_FC_COM_REG);
-   val |= FLOW_CONTROL_ENABLE_BIT;
-   mvpp2_cm3_write(priv, MSS_FC_COM_REG, val);
+   err = mvpp2_enable_global_fc(priv);
+   if (err) {
+   dev_warn(&pdev->dev, "CM3 firmware not running, version 
should be higher than 18.09 ");
+   dev_warn(&pdev->dev, "and chip revision B0\n");
+   dev_warn(&pdev->dev, "Flow control not supported\n");
+   }
}
 
mvpp2_dbgfs_init(priv, pdev->name);
-- 
1.9.1



[PATCH v11 net-next 14/15] net: mvpp2: set 802.3x GoP Flow Control mode

2021-02-09 Thread stefanc
From: Stefan Chulski 

This patch fix GMAC TX flow control autoneg.
Flow control autoneg wrongly were disabled with enabled TX
flow control.

Signed-off-by: Stefan Chulski 
---
 drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c 
b/drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c
index a472125..4d0a398 100644
--- a/drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c
+++ b/drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c
@@ -6283,7 +6283,7 @@ static void mvpp2_gmac_config(struct mvpp2_port *port, 
unsigned int mode,
old_ctrl4 = ctrl4 = readl(port->base + MVPP22_GMAC_CTRL_4_REG);
 
ctrl0 &= ~MVPP2_GMAC_PORT_TYPE_MASK;
-   ctrl2 &= ~(MVPP2_GMAC_INBAND_AN_MASK | MVPP2_GMAC_PCS_ENABLE_MASK);
+   ctrl2 &= ~(MVPP2_GMAC_INBAND_AN_MASK | MVPP2_GMAC_PCS_ENABLE_MASK | 
MVPP2_GMAC_FLOW_CTRL_MASK);
 
/* Configure port type */
if (phy_interface_mode_is_8023z(state->interface)) {
-- 
1.9.1



[PATCH v11 net-next 13/15] net: mvpp2: add PPv23 RX FIFO flow control

2021-02-09 Thread stefanc
From: Stefan Chulski 

New FIFO flow control feature was added in PPv23.
PPv2 FIFO polled by HW and trigger pause frame if FIFO
fill level is below threshold.
FIFO HW flow control enabled with CM3 RXQ&BM flow
control with ethtool.
Current  FIFO thresholds is:
9KB for port with maximum speed 10Gb/s port
4KB for port with maximum speed 5Gb/s port
2KB for port with maximum speed 1Gb/s port

Signed-off-by: Stefan Chulski 
---
 drivers/net/ethernet/marvell/mvpp2/mvpp2.h  | 15 ++
 drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c | 53 
 2 files changed, 68 insertions(+)

diff --git a/drivers/net/ethernet/marvell/mvpp2/mvpp2.h 
b/drivers/net/ethernet/marvell/mvpp2/mvpp2.h
index 9b525b60..b61a1ba 100644
--- a/drivers/net/ethernet/marvell/mvpp2/mvpp2.h
+++ b/drivers/net/ethernet/marvell/mvpp2/mvpp2.h
@@ -770,6 +770,18 @@
 #define MVPP2_TX_FIFO_THRESHOLD(kb)\
((kb) * 1024 - MVPP2_TX_FIFO_THRESHOLD_MIN)
 
+/* RX FIFO threshold in 1KB granularity */
+#define MVPP23_PORT0_FIFO_TRSH (9 * 1024)
+#define MVPP23_PORT1_FIFO_TRSH (4 * 1024)
+#define MVPP23_PORT2_FIFO_TRSH (2 * 1024)
+
+/* RX Flow Control Registers */
+#define MVPP2_RX_FC_REG(port)  (0x150 + 4 * (port))
+#define MVPP2_RX_FC_EN BIT(24)
+#define MVPP2_RX_FC_TRSH_OFFS  16
+#define MVPP2_RX_FC_TRSH_MASK  (0xFF << MVPP2_RX_FC_TRSH_OFFS)
+#define MVPP2_RX_FC_TRSH_UNIT  256
+
 /* MSS Flow control */
 #define MSS_FC_COM_REG 0
 #define FLOW_CONTROL_ENABLE_BITBIT(0)
@@ -1498,6 +1510,8 @@ struct mvpp2_bm_pool {
 
 void mvpp2_dbgfs_cleanup(struct mvpp2 *priv);
 
+void mvpp23_rx_fifo_fc_en(struct mvpp2 *priv, int port, bool en);
+
 #ifdef CONFIG_MVPP2_PTP
 int mvpp22_tai_probe(struct device *dev, struct mvpp2 *priv);
 void mvpp22_tai_tstamp(struct mvpp2_tai *tai, u32 tstamp,
@@ -1530,4 +1544,5 @@ static inline bool mvpp22_rx_hwtstamping(struct 
mvpp2_port *port)
 {
return IS_ENABLED(CONFIG_MVPP2_PTP) && port->rx_hwtstamp;
 }
+
 #endif
diff --git a/drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c 
b/drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c
index 3faad04..a472125 100644
--- a/drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c
+++ b/drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c
@@ -6536,6 +6536,8 @@ static void mvpp2_mac_link_up(struct phylink_config 
*config,
mvpp2_bm_pool_update_fc(port, port->pool_long, 
tx_pause);
mvpp2_bm_pool_update_fc(port, port->pool_short, 
tx_pause);
}
+   if (port->priv->hw_version == MVPP23)
+   mvpp23_rx_fifo_fc_en(port->priv, port->id, tx_pause);
}
 
mvpp2_port_enable(port);
@@ -7004,6 +7006,55 @@ static void mvpp22_rx_fifo_init(struct mvpp2 *priv)
mvpp2_write(priv, MVPP2_RX_FIFO_INIT_REG, 0x1);
 }
 
+/* Configure Rx FIFO Flow control thresholds */
+static void mvpp23_rx_fifo_fc_set_tresh(struct mvpp2 *priv)
+{
+   int port, val;
+
+   /* Port 0: maximum speed -10Gb/s port
+* required by spec RX FIFO threshold 9KB
+* Port 1: maximum speed -5Gb/s port
+* required by spec RX FIFO threshold 4KB
+* Port 2: maximum speed -1Gb/s port
+* required by spec RX FIFO threshold 2KB
+*/
+
+   /* Without loopback port */
+   for (port = 0; port < (MVPP2_MAX_PORTS - 1); port++) {
+   if (port == 0) {
+   val = (MVPP23_PORT0_FIFO_TRSH / MVPP2_RX_FC_TRSH_UNIT)
+   << MVPP2_RX_FC_TRSH_OFFS;
+   val &= MVPP2_RX_FC_TRSH_MASK;
+   mvpp2_write(priv, MVPP2_RX_FC_REG(port), val);
+   } else if (port == 1) {
+   val = (MVPP23_PORT1_FIFO_TRSH / MVPP2_RX_FC_TRSH_UNIT)
+   << MVPP2_RX_FC_TRSH_OFFS;
+   val &= MVPP2_RX_FC_TRSH_MASK;
+   mvpp2_write(priv, MVPP2_RX_FC_REG(port), val);
+   } else {
+   val = (MVPP23_PORT2_FIFO_TRSH / MVPP2_RX_FC_TRSH_UNIT)
+   << MVPP2_RX_FC_TRSH_OFFS;
+   val &= MVPP2_RX_FC_TRSH_MASK;
+   mvpp2_write(priv, MVPP2_RX_FC_REG(port), val);
+   }
+   }
+}
+
+/* Configure Rx FIFO Flow control thresholds */
+void mvpp23_rx_fifo_fc_en(struct mvpp2 *priv, int port, bool en)
+{
+   int val;
+
+   val = mvpp2_read(priv, MVPP2_RX_FC_REG(port));
+
+   if (en)
+   val |= MVPP2_RX_FC_EN;
+   else
+   val &= ~MVPP2_RX_FC_EN;
+
+   mvpp2_write(priv, MVPP2_RX_FC_REG(port), val);
+}
+
 static void mvpp22_tx_fifo_set_hw(struct mvpp2 *priv, int port, int size)
 {
int threshold = MVPP2_TX_FIFO_THRESHOLD(size);
@@ -7155,6 +7206,8 @@ static int mvpp2_init(struct platform_device *pdev, 
struct mvpp2 *priv)
} else {
mvpp22_rx_fifo_init(priv);
 

[PATCH v11 net-next 12/15] net: mvpp2: add BM protection underrun feature support

2021-02-09 Thread stefanc
From: Stefan Chulski 

The PP2v23 hardware supports a feature allowing to double the
size of BPPI by decreasing number of pools from 16 to 8.
Increasing of BPPI size protect BM drop from BPPI underrun.
Underrun could occurred due to stress on DDR and as result slow buffer
transition from BPPE to BPPI.
New BPPI threshold recommended by spec is:
BPPI low threshold - 640 buffers
BPPI high threshold - 832 buffers
Supported only in PPv23.

Signed-off-by: Stefan Chulski 
---
 drivers/net/ethernet/marvell/mvpp2/mvpp2.h  |  8 +
 drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c | 35 +++-
 2 files changed, 42 insertions(+), 1 deletion(-)

diff --git a/drivers/net/ethernet/marvell/mvpp2/mvpp2.h 
b/drivers/net/ethernet/marvell/mvpp2/mvpp2.h
index 0731dc7..9b525b60 100644
--- a/drivers/net/ethernet/marvell/mvpp2/mvpp2.h
+++ b/drivers/net/ethernet/marvell/mvpp2/mvpp2.h
@@ -324,6 +324,10 @@
 #define MVPP2_BM_HIGH_THRESH_MASK  0x7f
 #define MVPP2_BM_HIGH_THRESH_VALUE(val)((val) << \
MVPP2_BM_HIGH_THRESH_OFFS)
+#define MVPP2_BM_BPPI_HIGH_THRESH  0x1E
+#define MVPP2_BM_BPPI_LOW_THRESH   0x1C
+#define MVPP23_BM_BPPI_HIGH_THRESH 0x34
+#define MVPP23_BM_BPPI_LOW_THRESH  0x28
 #define MVPP2_BM_INTR_CAUSE_REG(pool)  (0x6240 + ((pool) * 4))
 #define MVPP2_BM_RELEASED_DELAY_MASK   BIT(0)
 #define MVPP2_BM_ALLOC_FAILED_MASK BIT(1)
@@ -352,6 +356,10 @@
 #define MVPP2_OVERRUN_ETH_DROP 0x7000
 #define MVPP2_CLS_ETH_DROP 0x7020
 
+#define MVPP22_BM_POOL_BASE_ADDR_HIGH_REG  0x6310
+#define MVPP22_BM_POOL_BASE_ADDR_HIGH_MASK 0xff
+#define MVPP23_BM_8POOL_MODE   BIT(8)
+
 /* Hit counters registers */
 #define MVPP2_CTRS_IDX 0x7040
 #define MVPP22_CTRS_TX_CTR(port, txq)  ((txq) | ((port) << 3) | BIT(7))
diff --git a/drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c 
b/drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c
index 90c9265..3faad04 100644
--- a/drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c
+++ b/drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c
@@ -69,6 +69,11 @@ enum mvpp2_bm_pool_log_num {
 module_param(queue_mode, int, 0444);
 MODULE_PARM_DESC(queue_mode, "Set queue_mode (single=0, multi=1)");
 
+static int bm_underrun_protect = 1;
+
+module_param(bm_underrun_protect, int, 0444);
+MODULE_PARM_DESC(bm_underrun_protect, "Set BM underrun protect feature (0-1), 
def=1");
+
 /* Utility/helper methods */
 
 void mvpp2_write(struct mvpp2 *priv, u32 offset, u32 data)
@@ -423,6 +428,21 @@ static int mvpp2_bm_pool_create(struct device *dev, struct 
mvpp2 *priv,
 
val = mvpp2_read(priv, MVPP2_BM_POOL_CTRL_REG(bm_pool->id));
val |= MVPP2_BM_START_MASK;
+
+   val &= ~MVPP2_BM_LOW_THRESH_MASK;
+   val &= ~MVPP2_BM_HIGH_THRESH_MASK;
+
+   /* Set 8 Pools BPPI threshold if BM underrun protection feature
+* was enabled
+*/
+   if (priv->hw_version == MVPP23 && bm_underrun_protect) {
+   val |= MVPP2_BM_LOW_THRESH_VALUE(MVPP23_BM_BPPI_LOW_THRESH);
+   val |= MVPP2_BM_HIGH_THRESH_VALUE(MVPP23_BM_BPPI_HIGH_THRESH);
+   } else {
+   val |= MVPP2_BM_LOW_THRESH_VALUE(MVPP2_BM_BPPI_LOW_THRESH);
+   val |= MVPP2_BM_HIGH_THRESH_VALUE(MVPP2_BM_BPPI_HIGH_THRESH);
+   }
+
mvpp2_write(priv, MVPP2_BM_POOL_CTRL_REG(bm_pool->id), val);
 
bm_pool->size = size;
@@ -591,6 +611,16 @@ static int mvpp2_bm_pools_init(struct device *dev, struct 
mvpp2 *priv)
return err;
 }
 
+/* Routine enable PPv23 8 pool mode */
+static void mvpp23_bm_set_8pool_mode(struct mvpp2 *priv)
+{
+   int val;
+
+   val = mvpp2_read(priv, MVPP22_BM_POOL_BASE_ADDR_HIGH_REG);
+   val |= MVPP23_BM_8POOL_MODE;
+   mvpp2_write(priv, MVPP22_BM_POOL_BASE_ADDR_HIGH_REG, val);
+}
+
 static int mvpp2_bm_init(struct device *dev, struct mvpp2 *priv)
 {
enum dma_data_direction dma_dir = DMA_FROM_DEVICE;
@@ -644,6 +674,9 @@ static int mvpp2_bm_init(struct device *dev, struct mvpp2 
*priv)
if (!priv->bm_pools)
return -ENOMEM;
 
+   if (priv->hw_version == MVPP23 && bm_underrun_protect)
+   mvpp23_bm_set_8pool_mode(priv);
+
err = mvpp2_bm_pools_init(dev, priv);
if (err < 0)
return err;
@@ -6490,7 +6523,7 @@ static void mvpp2_mac_link_up(struct phylink_config 
*config,
 val);
}
 
-   if (port->priv->global_tx_fc) {
+   if (port->priv->global_tx_fc && bm_underrun_protect) {
port->tx_fc = tx_pause;
if (tx_pause)
mvpp2_rxq_enable_fc(port);
-- 
1.9.1



[PATCH v11 net-next 11/15] net: mvpp2: add ethtool flow control configuration support

2021-02-09 Thread stefanc
From: Stefan Chulski 

This patch add ethtool flow control configuration support.

Tx flow control retrieved correctly by ethtool get function.
FW per port ethtool configuration capability added.

Patch also takes care about mtu change procedure, if PPv2 switch
BM pools during mtu change.

Signed-off-by: Stefan Chulski 
---
 drivers/net/ethernet/marvell/mvpp2/mvpp2.h  | 13 +++
 drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c | 98 
 2 files changed, 111 insertions(+)

diff --git a/drivers/net/ethernet/marvell/mvpp2/mvpp2.h 
b/drivers/net/ethernet/marvell/mvpp2/mvpp2.h
index 0010a3e9..0731dc7 100644
--- a/drivers/net/ethernet/marvell/mvpp2/mvpp2.h
+++ b/drivers/net/ethernet/marvell/mvpp2/mvpp2.h
@@ -774,6 +774,19 @@
 #define MSS_RXQ_TRESH_REG(q, fq)   (MSS_RXQ_TRESH_BASE + (((q) + (fq)) \
* MSS_RXQ_TRESH_OFFS))
 
+#define MSS_BUF_POOL_BASE  0x40
+#define MSS_BUF_POOL_OFFS  4
+#define MSS_BUF_POOL_REG(id)   (MSS_BUF_POOL_BASE  \
+   + (id) * MSS_BUF_POOL_OFFS)
+
+#define MSS_BUF_POOL_STOP_MASK 0xFFF
+#define MSS_BUF_POOL_START_MASK(0xFFF << 
MSS_BUF_POOL_START_OFFS)
+#define MSS_BUF_POOL_START_OFFS12
+#define MSS_BUF_POOL_PORTS_MASK(0xF << MSS_BUF_POOL_PORTS_OFFS)
+#define MSS_BUF_POOL_PORTS_OFFS24
+#define MSS_BUF_POOL_PORT_OFFS(id) (0x1 << \
+   ((id) + MSS_BUF_POOL_PORTS_OFFS))
+
 #define MSS_RXQ_TRESH_START_MASK   0x
 #define MSS_RXQ_TRESH_STOP_MASK(0x << 
MSS_RXQ_TRESH_STOP_OFFS)
 #define MSS_RXQ_TRESH_STOP_OFFS16
diff --git a/drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c 
b/drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c
index f1770e5..90c9265 100644
--- a/drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c
+++ b/drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c
@@ -845,6 +845,59 @@ static void mvpp2_rxq_disable_fc(struct mvpp2_port *port)
spin_unlock_irqrestore(&port->priv->mss_spinlock, flags);
 }
 
+/* Routine disable/enable flow control for BM pool condition */
+static void mvpp2_bm_pool_update_fc(struct mvpp2_port *port,
+   struct mvpp2_bm_pool *pool,
+   bool en)
+{
+   int val, cm3_state;
+   unsigned long flags;
+
+   spin_lock_irqsave(&port->priv->mss_spinlock, flags);
+
+   /* Remove Flow control enable bit to prevent race between FW and Kernel
+* If Flow control were enabled, it would be re-enabled.
+*/
+   val = mvpp2_cm3_read(port->priv, MSS_FC_COM_REG);
+   cm3_state = (val & FLOW_CONTROL_ENABLE_BIT);
+   val &= ~FLOW_CONTROL_ENABLE_BIT;
+   mvpp2_cm3_write(port->priv, MSS_FC_COM_REG, val);
+
+   /* Check if BM pool should be enabled/disable */
+   if (en) {
+   /* Set BM pool start and stop thresholds per port */
+   val = mvpp2_cm3_read(port->priv, MSS_BUF_POOL_REG(pool->id));
+   val |= MSS_BUF_POOL_PORT_OFFS(port->id);
+   val &= ~MSS_BUF_POOL_START_MASK;
+   val |= (MSS_THRESHOLD_START << MSS_BUF_POOL_START_OFFS);
+   val &= ~MSS_BUF_POOL_STOP_MASK;
+   val |= MSS_THRESHOLD_STOP;
+   mvpp2_cm3_write(port->priv, MSS_BUF_POOL_REG(pool->id), val);
+   } else {
+   /* Remove BM pool from the port */
+   val = mvpp2_cm3_read(port->priv, MSS_BUF_POOL_REG(pool->id));
+   val &= ~MSS_BUF_POOL_PORT_OFFS(port->id);
+
+   /* Zero BM pool start and stop thresholds to disable pool
+* flow control if pool empty (not used by any port)
+*/
+   if (!pool->buf_num) {
+   val &= ~MSS_BUF_POOL_START_MASK;
+   val &= ~MSS_BUF_POOL_STOP_MASK;
+   }
+
+   mvpp2_cm3_write(port->priv, MSS_BUF_POOL_REG(pool->id), val);
+   }
+
+   /* Notify Firmware that Flow control config space ready for update */
+   val = mvpp2_cm3_read(port->priv, MSS_FC_COM_REG);
+   val |= FLOW_CONTROL_UPDATE_COMMAND_BIT;
+   val |= cm3_state;
+   mvpp2_cm3_write(port->priv, MSS_FC_COM_REG, val);
+
+   spin_unlock_irqrestore(&port->priv->mss_spinlock, flags);
+}
+
 /* Release buffer to BM */
 static inline void mvpp2_bm_pool_put(struct mvpp2_port *port, int pool,
 dma_addr_t buf_dma_addr,
@@ -1175,6 +1228,16 @@ static int mvpp2_bm_update_mtu(struct net_device *dev, 
int mtu)
new_long_pool = MVPP2_BM_LONG;
 
if (new_long_pool != port->pool_long->id) {
+   if (port->tx_fc) {
+   if (pkt_size > MVPP2_BM_LONG_PKT_SIZE)
+   mvpp2_bm_pool_update_fc(port,
+   

[PATCH v11 net-next 10/15] net: mvpp2: add RXQ flow control configurations

2021-02-09 Thread stefanc
From: Stefan Chulski 

This patch adds RXQ flow control configurations.
Flow control disabled by default.
Minimum ring size limited to 1024 descriptors.

Signed-off-by: Stefan Chulski 
---
 drivers/net/ethernet/marvell/mvpp2/mvpp2.h  |  35 +-
 drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c | 116 
 2 files changed, 150 insertions(+), 1 deletion(-)

diff --git a/drivers/net/ethernet/marvell/mvpp2/mvpp2.h 
b/drivers/net/ethernet/marvell/mvpp2/mvpp2.h
index 8945fb9..0010a3e9 100644
--- a/drivers/net/ethernet/marvell/mvpp2/mvpp2.h
+++ b/drivers/net/ethernet/marvell/mvpp2/mvpp2.h
@@ -765,9 +765,36 @@
 /* MSS Flow control */
 #define MSS_FC_COM_REG 0
 #define FLOW_CONTROL_ENABLE_BITBIT(0)
+#define FLOW_CONTROL_UPDATE_COMMAND_BITBIT(31)
 #define FC_QUANTA  0x
 #define FC_CLK_DIVIDER 100
-#define MSS_THRESHOLD_STOP 768
+
+#define MSS_RXQ_TRESH_BASE 0x200
+#define MSS_RXQ_TRESH_OFFS 4
+#define MSS_RXQ_TRESH_REG(q, fq)   (MSS_RXQ_TRESH_BASE + (((q) + (fq)) \
+   * MSS_RXQ_TRESH_OFFS))
+
+#define MSS_RXQ_TRESH_START_MASK   0x
+#define MSS_RXQ_TRESH_STOP_MASK(0x << 
MSS_RXQ_TRESH_STOP_OFFS)
+#define MSS_RXQ_TRESH_STOP_OFFS16
+
+#define MSS_RXQ_ASS_BASE   0x80
+#define MSS_RXQ_ASS_OFFS   4
+#define MSS_RXQ_ASS_PER_REG4
+#define MSS_RXQ_ASS_PER_OFFS   8
+#define MSS_RXQ_ASS_PORTID_OFFS0
+#define MSS_RXQ_ASS_PORTID_MASK0x3
+#define MSS_RXQ_ASS_HOSTID_OFFS2
+#define MSS_RXQ_ASS_HOSTID_MASK0x3F
+
+#define MSS_RXQ_ASS_Q_BASE(q, fq) q) + (fq)) % MSS_RXQ_ASS_PER_REG)
 \
+ * MSS_RXQ_ASS_PER_OFFS)
+#define MSS_RXQ_ASS_PQ_BASE(q, fq) q) + (fq)) / MSS_RXQ_ASS_PER_REG) \
+  * MSS_RXQ_ASS_OFFS)
+#define MSS_RXQ_ASS_REG(q, fq) (MSS_RXQ_ASS_BASE + MSS_RXQ_ASS_PQ_BASE(q, fq))
+
+#define MSS_THRESHOLD_STOP 768
+#define MSS_THRESHOLD_START1024
 
 /* RX buffer constants */
 #define MVPP2_SKB_SHINFO_SIZE \
@@ -1022,6 +1049,9 @@ struct mvpp2 {
 
/* Global TX Flow Control config */
bool global_tx_fc;
+
+   /* Spinlocks for CM3 shared memory configuration */
+   spinlock_t mss_spinlock;
 };
 
 struct mvpp2_pcpu_stats {
@@ -1184,6 +1214,9 @@ struct mvpp2_port {
bool rx_hwtstamp;
enum hwtstamp_tx_types tx_hwtstamp_type;
struct mvpp2_hwtstamp_queue tx_hwtstamp_queue[2];
+
+   /* Firmware TX flow control */
+   bool tx_fc;
 };
 
 /* The mvpp2_tx_desc and mvpp2_rx_desc structures describe the
diff --git a/drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c 
b/drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c
index 027101b..f1770e5 100644
--- a/drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c
+++ b/drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c
@@ -741,6 +741,110 @@ static void *mvpp2_buf_alloc(struct mvpp2_port *port,
return data;
 }
 
+/* Routine enable flow control for RXQs condition */
+static void mvpp2_rxq_enable_fc(struct mvpp2_port *port)
+{
+   int val, cm3_state, host_id, q;
+   int fq = port->first_rxq;
+   unsigned long flags;
+
+   spin_lock_irqsave(&port->priv->mss_spinlock, flags);
+
+   /* Remove Flow control enable bit to prevent race between FW and Kernel
+* If Flow control was enabled, it would be re-enabled.
+*/
+   val = mvpp2_cm3_read(port->priv, MSS_FC_COM_REG);
+   cm3_state = (val & FLOW_CONTROL_ENABLE_BIT);
+   val &= ~FLOW_CONTROL_ENABLE_BIT;
+   mvpp2_cm3_write(port->priv, MSS_FC_COM_REG, val);
+
+   /* Set same Flow control for all RXQs */
+   for (q = 0; q < port->nrxqs; q++) {
+   /* Set stop and start Flow control RXQ thresholds */
+   val = MSS_THRESHOLD_START;
+   val |= (MSS_THRESHOLD_STOP << MSS_RXQ_TRESH_STOP_OFFS);
+   mvpp2_cm3_write(port->priv, MSS_RXQ_TRESH_REG(q, fq), val);
+
+   val = mvpp2_cm3_read(port->priv, MSS_RXQ_ASS_REG(q, fq));
+   /* Set RXQ port ID */
+   val &= ~(MSS_RXQ_ASS_PORTID_MASK << MSS_RXQ_ASS_Q_BASE(q, fq));
+   val |= (port->id << MSS_RXQ_ASS_Q_BASE(q, fq));
+   val &= ~(MSS_RXQ_ASS_HOSTID_MASK << (MSS_RXQ_ASS_Q_BASE(q, fq)
+   + MSS_RXQ_ASS_HOSTID_OFFS));
+
+   /* Calculate RXQ host ID:
+* In Single queue mode: Host ID equal to Host ID used for
+*   shared RX interrupt
+* In Multi queue mode: Host ID equal to number of
+*  RXQ ID / number of CoS queues
+* In Single resource mode: Host ID always equal to 0
+*/
+   if (queue_mode == MVPP2_QDIST_SINGLE_MODE)
+   host_id = port->nqvecs;
+   else if (queue

[PATCH v11 net-next 09/15] net: mvpp2: enable global flow control

2021-02-09 Thread stefanc
From: Stefan Chulski 

This patch enables global flow control in FW and in the phylink validate mask.

Signed-off-by: Stefan Chulski 
---
 drivers/net/ethernet/marvell/mvpp2/mvpp2.h  | 11 +--
 drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c | 30 +++-
 2 files changed, 37 insertions(+), 4 deletions(-)

diff --git a/drivers/net/ethernet/marvell/mvpp2/mvpp2.h 
b/drivers/net/ethernet/marvell/mvpp2/mvpp2.h
index d2cc513c..8945fb9 100644
--- a/drivers/net/ethernet/marvell/mvpp2/mvpp2.h
+++ b/drivers/net/ethernet/marvell/mvpp2/mvpp2.h
@@ -763,9 +763,11 @@
((kb) * 1024 - MVPP2_TX_FIFO_THRESHOLD_MIN)
 
 /* MSS Flow control */
-#define FC_QUANTA  0x
-#define FC_CLK_DIVIDER 100
-#define MSS_THRESHOLD_STOP 768
+#define MSS_FC_COM_REG 0
+#define FLOW_CONTROL_ENABLE_BITBIT(0)
+#define FC_QUANTA  0x
+#define FC_CLK_DIVIDER 100
+#define MSS_THRESHOLD_STOP 768
 
 /* RX buffer constants */
 #define MVPP2_SKB_SHINFO_SIZE \
@@ -1017,6 +1019,9 @@ struct mvpp2 {
 
/* page_pool allocator */
struct page_pool *page_pool[MVPP2_PORT_MAX_RXQ];
+
+   /* Global TX Flow Control config */
+   bool global_tx_fc;
 };
 
 struct mvpp2_pcpu_stats {
diff --git a/drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c 
b/drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c
index 8b4073c..027101b 100644
--- a/drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c
+++ b/drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c
@@ -91,6 +91,16 @@ static inline u32 mvpp2_cpu_to_thread(struct mvpp2 *priv, 
int cpu)
return cpu % priv->nthreads;
 }
 
+static void mvpp2_cm3_write(struct mvpp2 *priv, u32 offset, u32 data)
+{
+   writel(data, priv->cm3_base + offset);
+}
+
+static u32 mvpp2_cm3_read(struct mvpp2 *priv, u32 offset)
+{
+   return readl(priv->cm3_base + offset);
+}
+
 static struct page_pool *
 mvpp2_create_page_pool(struct device *dev, int num, int len,
   enum dma_data_direction dma_dir)
@@ -5950,6 +5960,11 @@ static void mvpp2_phylink_validate(struct phylink_config 
*config,
phylink_set(mask, Autoneg);
phylink_set_port_modes(mask);
 
+   if (port->priv->global_tx_fc) {
+   phylink_set(mask, Pause);
+   phylink_set(mask, Asym_Pause);
+   }
+
switch (state->interface) {
case PHY_INTERFACE_MODE_10GBASER:
case PHY_INTERFACE_MODE_XAUI:
@@ -6951,7 +6966,7 @@ static int mvpp2_probe(struct platform_device *pdev)
struct resource *res;
void __iomem *base;
int i, shared;
-   int err;
+   int err, val;
 
priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL);
if (!priv)
@@ -7003,6 +7018,10 @@ static int mvpp2_probe(struct platform_device *pdev)
err = mvpp2_get_sram(pdev, priv);
if (err)
dev_warn(&pdev->dev, "Fail to alloc CM3 SRAM\n");
+
+   /* Enable global Flow Control only if handler to SRAM not NULL 
*/
+   if (priv->cm3_base)
+   priv->global_tx_fc = true;
}
 
if (priv->hw_version != MVPP21 && dev_of_node(&pdev->dev)) {
@@ -7168,6 +7187,15 @@ static int mvpp2_probe(struct platform_device *pdev)
goto err_port_probe;
}
 
+   /* Enable global flow control. In this stage global
+* flow control enabled, but still disabled per port.
+*/
+   if (priv->global_tx_fc && priv->hw_version != MVPP21) {
+   val = mvpp2_cm3_read(priv, MSS_FC_COM_REG);
+   val |= FLOW_CONTROL_ENABLE_BIT;
+   mvpp2_cm3_write(priv, MSS_FC_COM_REG, val);
+   }
+
mvpp2_dbgfs_init(priv, pdev->name);
 
platform_set_drvdata(pdev, priv);
-- 
1.9.1



[PATCH v11 net-next 08/15] net: mvpp2: add FCA RXQ non occupied descriptor threshold

2021-02-09 Thread stefanc
From: Stefan Chulski 

The firmware needs to monitor the RX Non-occupied descriptor
bits for flow control to move to XOFF mode.
These bits need to be unmasked to be functional, but they will
not raise interrupts as we leave the RX exception summary
bit in MVPP2_ISR_RX_TX_MASK_REG clear.

Signed-off-by: Stefan Chulski 
---
 drivers/net/ethernet/marvell/mvpp2/mvpp2.h  |  3 ++
 drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c | 44 
 2 files changed, 40 insertions(+), 7 deletions(-)

diff --git a/drivers/net/ethernet/marvell/mvpp2/mvpp2.h 
b/drivers/net/ethernet/marvell/mvpp2/mvpp2.h
index 9239d80..d2cc513c 100644
--- a/drivers/net/ethernet/marvell/mvpp2/mvpp2.h
+++ b/drivers/net/ethernet/marvell/mvpp2/mvpp2.h
@@ -295,6 +295,8 @@
 #define MVPP2_PON_CAUSE_TXP_OCCUP_DESC_ALL_MASK0x3fc0
 #define MVPP2_PON_CAUSE_MISC_SUM_MASK  BIT(31)
 #define MVPP2_ISR_MISC_CAUSE_REG   0x55b0
+#define MVPP2_ISR_RX_ERR_CAUSE_REG(port)   (0x5520 + 4 * (port))
+#define MVPP2_ISR_RX_ERR_CAUSE_NONOCC_MASK 0x00ff
 
 /* Buffer Manager registers */
 #define MVPP2_BM_POOL_BASE_REG(pool)   (0x6000 + ((pool) * 4))
@@ -763,6 +765,7 @@
 /* MSS Flow control */
 #define FC_QUANTA  0x
 #define FC_CLK_DIVIDER 100
+#define MSS_THRESHOLD_STOP 768
 
 /* RX buffer constants */
 #define MVPP2_SKB_SHINFO_SIZE \
diff --git a/drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c 
b/drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c
index 761f745..8b4073c 100644
--- a/drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c
+++ b/drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c
@@ -1133,14 +1133,19 @@ static inline void mvpp2_qvec_interrupt_disable(struct 
mvpp2_queue_vector *qvec)
 static void mvpp2_interrupts_mask(void *arg)
 {
struct mvpp2_port *port = arg;
+   int cpu = smp_processor_id();
+   u32 thread;
 
/* If the thread isn't used, don't do anything */
-   if (smp_processor_id() > port->priv->nthreads)
+   if (cpu > port->priv->nthreads)
return;
 
-   mvpp2_thread_write(port->priv,
-  mvpp2_cpu_to_thread(port->priv, smp_processor_id()),
+   thread = mvpp2_cpu_to_thread(port->priv, cpu);
+
+   mvpp2_thread_write(port->priv, thread,
   MVPP2_ISR_RX_TX_MASK_REG(port->id), 0);
+   mvpp2_thread_write(port->priv, thread,
+  MVPP2_ISR_RX_ERR_CAUSE_REG(port->id), 0);
 }
 
 /* Unmask the current thread's Rx/Tx interrupts.
@@ -1150,20 +1155,25 @@ static void mvpp2_interrupts_mask(void *arg)
 static void mvpp2_interrupts_unmask(void *arg)
 {
struct mvpp2_port *port = arg;
-   u32 val;
+   int cpu = smp_processor_id();
+   u32 val, thread;
 
/* If the thread isn't used, don't do anything */
-   if (smp_processor_id() > port->priv->nthreads)
+   if (cpu > port->priv->nthreads)
return;
 
+   thread = mvpp2_cpu_to_thread(port->priv, cpu);
+
val = MVPP2_CAUSE_MISC_SUM_MASK |
MVPP2_CAUSE_RXQ_OCCUP_DESC_ALL_MASK(port->priv->hw_version);
if (port->has_tx_irqs)
val |= MVPP2_CAUSE_TXQ_OCCUP_DESC_ALL_MASK;
 
-   mvpp2_thread_write(port->priv,
-  mvpp2_cpu_to_thread(port->priv, smp_processor_id()),
+   mvpp2_thread_write(port->priv, thread,
   MVPP2_ISR_RX_TX_MASK_REG(port->id), val);
+   mvpp2_thread_write(port->priv, thread,
+  MVPP2_ISR_RX_ERR_CAUSE_REG(port->id),
+  MVPP2_ISR_RX_ERR_CAUSE_NONOCC_MASK);
 }
 
 static void
@@ -1188,6 +1198,9 @@ static void mvpp2_interrupts_unmask(void *arg)
 
mvpp2_thread_write(port->priv, v->sw_thread_id,
   MVPP2_ISR_RX_TX_MASK_REG(port->id), val);
+   mvpp2_thread_write(port->priv, v->sw_thread_id,
+  MVPP2_ISR_RX_ERR_CAUSE_REG(port->id),
+  MVPP2_ISR_RX_ERR_CAUSE_NONOCC_MASK);
}
 }
 
@@ -2393,6 +2406,20 @@ static void mvpp2_txp_max_tx_size_set(struct mvpp2_port 
*port)
}
 }
 
+/* Set the number of non-occupied descriptors threshold */
+static void mvpp2_set_rxq_free_tresh(struct mvpp2_port *port,
+struct mvpp2_rx_queue *rxq)
+{
+   u32 val;
+
+   mvpp2_write(port->priv, MVPP2_RXQ_NUM_REG, rxq->id);
+
+   val = mvpp2_read(port->priv, MVPP2_RXQ_THRESH_REG);
+   val &= ~MVPP2_RXQ_NON_OCCUPIED_MASK;
+   val |= MSS_THRESHOLD_STOP << MVPP2_RXQ_NON_OCCUPIED_OFFSET;
+   mvpp2_write(port->priv, MVPP2_RXQ_THRESH_REG, val);
+}
+
 /* Set the number of packets that will be received before Rx interrupt
  * will be generated by HW.
  */
@@ -2648,6 +2675,9 @@ static int mvpp2_rxq_init(struct mvpp2_port *port,
mvpp2_rx_pkts_coal_set(port, rxq);
mvpp2_rx_time_coal_set(port, rxq);
 
+   /* Set the number of

[PATCH v11 net-next 07/15] net: mvpp2: add FCA periodic timer configurations

2021-02-09 Thread stefanc
From: Stefan Chulski 

Flow Control periodic timer would be used if port in
XOFF to transmit periodic XOFF frames.

Signed-off-by: Stefan Chulski 
---
 drivers/net/ethernet/marvell/mvpp2/mvpp2.h  | 13 ++
 drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c | 45 
 2 files changed, 58 insertions(+)

diff --git a/drivers/net/ethernet/marvell/mvpp2/mvpp2.h 
b/drivers/net/ethernet/marvell/mvpp2/mvpp2.h
index e7bbf0a..9239d80 100644
--- a/drivers/net/ethernet/marvell/mvpp2/mvpp2.h
+++ b/drivers/net/ethernet/marvell/mvpp2/mvpp2.h
@@ -596,6 +596,15 @@
 #define MVPP22_MPCS_CLK_RESET_DIV_RATIO(n) ((n) << 4)
 #define MVPP22_MPCS_CLK_RESET_DIV_SET  BIT(11)
 
+/* FCA registers. PPv2.2 and PPv2.3 */
+#define MVPP22_FCA_BASE(port)  (0x7600 + (port) * 0x1000)
+#define MVPP22_FCA_REG_SIZE16
+#define MVPP22_FCA_REG_MASK0x
+#define MVPP22_FCA_CONTROL_REG 0x0
+#define MVPP22_FCA_ENABLE_PERIODIC BIT(11)
+#define MVPP22_PERIODIC_COUNTER_LSB_REG(0x110)
+#define MVPP22_PERIODIC_COUNTER_MSB_REG(0x114)
+
 /* XPCS registers. PPv2.2 and PPv2.3 */
 #define MVPP22_XPCS_BASE(port) (0x7400 + (port) * 0x1000)
 #define MVPP22_XPCS_CFG0   0x0
@@ -751,6 +760,10 @@
 #define MVPP2_TX_FIFO_THRESHOLD(kb)\
((kb) * 1024 - MVPP2_TX_FIFO_THRESHOLD_MIN)
 
+/* MSS Flow control */
+#define FC_QUANTA  0x
+#define FC_CLK_DIVIDER 100
+
 /* RX buffer constants */
 #define MVPP2_SKB_SHINFO_SIZE \
SKB_DATA_ALIGN(sizeof(struct skb_shared_info))
diff --git a/drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c 
b/drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c
index 5730900..761f745 100644
--- a/drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c
+++ b/drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c
@@ -1280,6 +1280,49 @@ static void mvpp22_gop_init_10gkr(struct mvpp2_port 
*port)
writel(val, mpcs + MVPP22_MPCS_CLK_RESET);
 }
 
+static void mvpp22_gop_fca_enable_periodic(struct mvpp2_port *port, bool en)
+{
+   struct mvpp2 *priv = port->priv;
+   void __iomem *fca = priv->iface_base + MVPP22_FCA_BASE(port->gop_id);
+   u32 val;
+
+   val = readl(fca + MVPP22_FCA_CONTROL_REG);
+   val &= ~MVPP22_FCA_ENABLE_PERIODIC;
+   if (en)
+   val |= MVPP22_FCA_ENABLE_PERIODIC;
+   writel(val, fca + MVPP22_FCA_CONTROL_REG);
+}
+
+static void mvpp22_gop_fca_set_timer(struct mvpp2_port *port, u32 timer)
+{
+   struct mvpp2 *priv = port->priv;
+   void __iomem *fca = priv->iface_base + MVPP22_FCA_BASE(port->gop_id);
+   u32 lsb, msb;
+
+   lsb = timer & MVPP22_FCA_REG_MASK;
+   msb = timer >> MVPP22_FCA_REG_SIZE;
+
+   writel(lsb, fca + MVPP22_PERIODIC_COUNTER_LSB_REG);
+   writel(msb, fca + MVPP22_PERIODIC_COUNTER_MSB_REG);
+}
+
+/* Set Flow Control timer x100 faster than pause quanta to ensure that link
+ * partner won't send traffic if port is in XOFF mode.
+ */
+static void mvpp22_gop_fca_set_periodic_timer(struct mvpp2_port *port)
+{
+   u32 timer;
+
+   timer = (port->priv->tclk / (USEC_PER_SEC * FC_CLK_DIVIDER))
+   * FC_QUANTA;
+
+   mvpp22_gop_fca_enable_periodic(port, false);
+
+   mvpp22_gop_fca_set_timer(port, timer);
+
+   mvpp22_gop_fca_enable_periodic(port, true);
+}
+
 static int mvpp22_gop_init(struct mvpp2_port *port)
 {
struct mvpp2 *priv = port->priv;
@@ -1324,6 +1367,8 @@ static int mvpp22_gop_init(struct mvpp2_port *port)
val |= GENCONF_SOFT_RESET1_GOP;
regmap_write(priv->sysctrl_base, GENCONF_SOFT_RESET1, val);
 
+   mvpp22_gop_fca_set_periodic_timer(port);
+
 unsupported_conf:
return 0;
 
-- 
1.9.1



[PATCH v11 net-next 06/15] net: mvpp2: increase BM pool and RXQ size

2021-02-09 Thread stefanc
From: Stefan Chulski 

BM pool and RXQ size increased to support Firmware Flow Control.
Minimum depletion thresholds to support FC are 1024 buffers.
BM pool size increased to 2048 to have some 1024 buffers
space between depletion thresholds and BM pool size.

Jumbo frames require a 9888B buffer, so memory requirements
for data buffers increased from 7MB to 24MB.

Signed-off-by: Stefan Chulski 
---
 drivers/net/ethernet/marvell/mvpp2/mvpp2.h | 8 
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/drivers/net/ethernet/marvell/mvpp2/mvpp2.h 
b/drivers/net/ethernet/marvell/mvpp2/mvpp2.h
index ce08086..e7bbf0a 100644
--- a/drivers/net/ethernet/marvell/mvpp2/mvpp2.h
+++ b/drivers/net/ethernet/marvell/mvpp2/mvpp2.h
@@ -715,8 +715,8 @@
 #define MVPP2_PORT_MAX_RXQ 32
 
 /* Max number of Rx descriptors */
-#define MVPP2_MAX_RXD_MAX  1024
-#define MVPP2_MAX_RXD_DFLT 128
+#define MVPP2_MAX_RXD_MAX  2048
+#define MVPP2_MAX_RXD_DFLT 1024
 
 /* Max number of Tx descriptors */
 #define MVPP2_MAX_TXD_MAX  2048
@@ -848,8 +848,8 @@ enum mvpp22_ptp_packet_format {
 #define MVPP22_PTP_TIMESTAMPQUEUESELECTBIT(18)
 
 /* BM constants */
-#define MVPP2_BM_JUMBO_BUF_NUM 512
-#define MVPP2_BM_LONG_BUF_NUM  1024
+#define MVPP2_BM_JUMBO_BUF_NUM 2048
+#define MVPP2_BM_LONG_BUF_NUM  2048
 #define MVPP2_BM_SHORT_BUF_NUM 2048
 #define MVPP2_BM_POOL_SIZE_MAX (16*1024 - MVPP2_BM_POOL_PTR_ALIGN/4)
 #define MVPP2_BM_POOL_PTR_ALIGN128
-- 
1.9.1



[PATCH v11 net-next 05/15] net: mvpp2: add PPv23 version definition

2021-02-09 Thread stefanc
From: Stefan Chulski 

This patch add PPv23 version definition.
PPv23 is new packet processor in CP115.
Everything that supported by PPv22, also supported by PPv23.
No functional changes in this stage.

Signed-off-by: Stefan Chulski 
---
 drivers/net/ethernet/marvell/mvpp2/mvpp2.h  | 24 
 drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c | 15 
 2 files changed, 24 insertions(+), 15 deletions(-)

diff --git a/drivers/net/ethernet/marvell/mvpp2/mvpp2.h 
b/drivers/net/ethernet/marvell/mvpp2/mvpp2.h
index 56e90ab..ce08086 100644
--- a/drivers/net/ethernet/marvell/mvpp2/mvpp2.h
+++ b/drivers/net/ethernet/marvell/mvpp2/mvpp2.h
@@ -60,6 +60,9 @@
 /* Top Registers */
 #define MVPP2_MH_REG(port) (0x5040 + 4 * (port))
 #define MVPP2_DSA_EXTENDED BIT(5)
+#define MVPP2_VER_ID_REG   0x50b0
+#define MVPP2_VER_PP22 0x10
+#define MVPP2_VER_PP23 0x11
 
 /* Parser Registers */
 #define MVPP2_PRS_INIT_LOOKUP_REG  0x1000
@@ -469,7 +472,7 @@
 #define MVPP22_GMAC_INT_SUM_MASK_LINK_STAT BIT(1)
 #defineMVPP22_GMAC_INT_SUM_MASK_PTPBIT(2)
 
-/* Per-port XGMAC registers. PPv2.2 only, only for GOP port 0,
+/* Per-port XGMAC registers. PPv2.2 and PPv2.3, only for GOP port 0,
  * relative to port->base.
  */
 #define MVPP22_XLG_CTRL0_REG   0x100
@@ -506,7 +509,7 @@
 #define MVPP22_XLG_CTRL4_MACMODSELECT_GMAC BIT(12)
 #define MVPP22_XLG_CTRL4_EN_IDLE_CHECK BIT(14)
 
-/* SMI registers. PPv2.2 only, relative to priv->iface_base. */
+/* SMI registers. PPv2.2 and PPv2.3, relative to priv->iface_base. */
 #define MVPP22_SMI_MISC_CFG_REG0x1204
 #define MVPP22_SMI_POLLING_EN  BIT(10)
 
@@ -582,7 +585,7 @@
 #define MVPP2_QUEUE_NEXT_DESC(q, index) \
(((index) < (q)->last_desc) ? ((index) + 1) : 0)
 
-/* XPCS registers. PPv2.2 only */
+/* XPCS registers.PPv2.2 and PPv2.3 */
 #define MVPP22_MPCS_BASE(port) (0x7000 + (port) * 0x1000)
 #define MVPP22_MPCS_CTRL   0x14
 #define MVPP22_MPCS_CTRL_FWD_ERR_CONN  BIT(10)
@@ -593,7 +596,7 @@
 #define MVPP22_MPCS_CLK_RESET_DIV_RATIO(n) ((n) << 4)
 #define MVPP22_MPCS_CLK_RESET_DIV_SET  BIT(11)
 
-/* XPCS registers. PPv2.2 only */
+/* XPCS registers. PPv2.2 and PPv2.3 */
 #define MVPP22_XPCS_BASE(port) (0x7400 + (port) * 0x1000)
 #define MVPP22_XPCS_CFG0   0x0
 #define MVPP22_XPCS_CFG0_RESET_DIS BIT(0)
@@ -927,15 +930,16 @@ struct mvpp2 {
void __iomem *iface_base;
void __iomem *cm3_base;
 
-   /* On PPv2.2, each "software thread" can access the base
+   /* On PPv2.2 and PPv2.3, each "software thread" can access the base
 * register through a separate address space, each 64 KB apart
 * from each other. Typically, such address spaces will be
 * used per CPU.
 */
void __iomem *swth_base[MVPP2_MAX_THREADS];
 
-   /* On PPv2.2, some port control registers are located into the system
-* controller space. These registers are accessible through a regmap.
+   /* On PPv2.2 and PPv2.3, some port control registers are located into
+* the system controller space. These registers are accessible
+* through a regmap.
 */
struct regmap *sysctrl_base;
 
@@ -977,7 +981,7 @@ struct mvpp2 {
u32 tclk;
 
/* HW version */
-   enum { MVPP21, MVPP22 } hw_version;
+   enum { MVPP21, MVPP22, MVPP23 } hw_version;
 
/* Maximum number of RXQs per port */
unsigned int max_port_rxqs;
@@ -1221,7 +1225,7 @@ struct mvpp21_rx_desc {
__le32 reserved8;
 };
 
-/* HW TX descriptor for PPv2.2 */
+/* HW TX descriptor for PPv2.2 and PPv2.3 */
 struct mvpp22_tx_desc {
__le32 command;
u8  packet_offset;
@@ -1233,7 +1237,7 @@ struct mvpp22_tx_desc {
__le64 buf_cookie_misc;
 };
 
-/* HW RX descriptor for PPv2.2 */
+/* HW RX descriptor for PPv2.2 and PPv2.3 */
 struct mvpp22_rx_desc {
__le32 status;
__le16 reserved1;
diff --git a/drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c 
b/drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c
index 17cd161..5730900 100644
--- a/drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c
+++ b/drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c
@@ -384,7 +384,7 @@ static int mvpp2_bm_pool_create(struct device *dev, struct 
mvpp2 *priv,
if (!IS_ALIGNED(size, 16))
return -EINVAL;
 
-   /* PPv2.1 needs 8 bytes per buffer pointer, PPv2.2 needs 16
+   /* PPv2.1 needs 8 bytes per buffer pointer, PPv2.2 and PPv2.3 needs 16
 * bytes per buffer pointer
 */
if (priv->hw_version == MVPP21)
@@ -5456,7 +5456,7 @@ static void mvpp2_rx_irqs_setup(struct mvpp2_port *port)
return;
}
 
-   /* Handle the more complicated PPv2.2 

[PATCH v11 net-next 04/15] net: mvpp2: always compare hw-version vs MVPP21

2021-02-09 Thread stefanc
From: Stefan Chulski 

Currently we have PP2v1 and PP2v2 hw-versions, with some different
handlers depending upon condition hw_version = MVPP21/MVPP22.
In a future there will be also PP2v3. Let's use now the generic
"if equal/notEqual MVPP21" for all cases instead of "if MVPP22".

This patch does not change any functionality.
It is not intended to introduce PP2v3.
It just modifies MVPP21/MVPP22 check-condition
bringing it to generic and unified form correct for new-code
introducing and PP2v3 net-next generation.

Signed-off-by: Stefan Chulski 
---
 drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c | 38 ++--
 1 file changed, 19 insertions(+), 19 deletions(-)

diff --git a/drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c 
b/drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c
index eec3796..17cd161 100644
--- a/drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c
+++ b/drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c
@@ -319,7 +319,7 @@ static int mvpp2_get_nrxqs(struct mvpp2 *priv)
 {
unsigned int nrxqs;
 
-   if (priv->hw_version == MVPP22 && queue_mode == MVPP2_QDIST_SINGLE_MODE)
+   if (priv->hw_version != MVPP21 && queue_mode == MVPP2_QDIST_SINGLE_MODE)
return 1;
 
/* According to the PPv2.2 datasheet and our experiments on
@@ -446,7 +446,7 @@ static void mvpp2_bm_bufs_get_addrs(struct device *dev, 
struct mvpp2 *priv,
  MVPP2_BM_PHY_ALLOC_REG(bm_pool->id));
*phys_addr = mvpp2_thread_read(priv, thread, MVPP2_BM_VIRT_ALLOC_REG);
 
-   if (priv->hw_version == MVPP22) {
+   if (priv->hw_version != MVPP21) {
u32 val;
u32 dma_addr_highbits, phys_addr_highbits;
 
@@ -742,7 +742,7 @@ static inline void mvpp2_bm_pool_put(struct mvpp2_port 
*port, int pool,
if (test_bit(thread, &port->priv->lock_map))
spin_lock_irqsave(&port->bm_lock[thread], flags);
 
-   if (port->priv->hw_version == MVPP22) {
+   if (port->priv->hw_version != MVPP21) {
u32 val = 0;
 
if (sizeof(dma_addr_t) == 8)
@@ -1172,7 +1172,7 @@ static void mvpp2_interrupts_unmask(void *arg)
u32 val;
int i;
 
-   if (port->priv->hw_version != MVPP22)
+   if (port->priv->hw_version == MVPP21)
return;
 
if (mask)
@@ -1199,7 +1199,7 @@ static bool mvpp2_port_supports_xlg(struct mvpp2_port 
*port)
 
 static bool mvpp2_port_supports_rgmii(struct mvpp2_port *port)
 {
-   return !(port->priv->hw_version == MVPP22 && port->gop_id == 0);
+   return !(port->priv->hw_version != MVPP21 && port->gop_id == 0);
 }
 
 /* Port configuration routines */
@@ -1817,7 +1817,7 @@ static void mvpp2_mac_reset_assert(struct mvpp2_port 
*port)
  MVPP2_GMAC_PORT_RESET_MASK;
writel(val, port->base + MVPP2_GMAC_CTRL_2_REG);
 
-   if (port->priv->hw_version == MVPP22 && port->gop_id == 0) {
+   if (port->priv->hw_version != MVPP21 && port->gop_id == 0) {
val = readl(port->base + MVPP22_XLG_CTRL0_REG) &
  ~MVPP22_XLG_CTRL0_MAC_RESET_DIS;
writel(val, port->base + MVPP22_XLG_CTRL0_REG);
@@ -1830,7 +1830,7 @@ static void mvpp22_pcs_reset_assert(struct mvpp2_port 
*port)
void __iomem *mpcs, *xpcs;
u32 val;
 
-   if (port->priv->hw_version != MVPP22 || port->gop_id != 0)
+   if (port->priv->hw_version == MVPP21 || port->gop_id != 0)
return;
 
mpcs = priv->iface_base + MVPP22_MPCS_BASE(port->gop_id);
@@ -1851,7 +1851,7 @@ static void mvpp22_pcs_reset_deassert(struct mvpp2_port 
*port)
void __iomem *mpcs, *xpcs;
u32 val;
 
-   if (port->priv->hw_version != MVPP22 || port->gop_id != 0)
+   if (port->priv->hw_version == MVPP21 || port->gop_id != 0)
return;
 
mpcs = priv->iface_base + MVPP22_MPCS_BASE(port->gop_id);
@@ -4188,7 +4188,7 @@ static void mvpp2_start_dev(struct mvpp2_port *port)
/* Enable interrupts on all threads */
mvpp2_interrupts_enable(port);
 
-   if (port->priv->hw_version == MVPP22)
+   if (port->priv->hw_version != MVPP21)
mvpp22_mode_reconfigure(port);
 
if (port->phylink) {
@@ -4404,7 +4404,7 @@ static int mvpp2_open(struct net_device *dev)
valid = true;
}
 
-   if (priv->hw_version == MVPP22 && port->port_irq) {
+   if (priv->hw_version != MVPP21 && port->port_irq) {
err = request_irq(port->port_irq, mvpp2_port_isr, 0,
  dev->name, port);
if (err) {
@@ -6052,7 +6052,7 @@ static int mvpp2__mac_prepare(struct phylink_config 
*config, unsigned int mode,
 MVPP2_GMAC_PORT_RESET_MASK,
 MVPP2_GMAC_PORT_RESET_MASK);
 
-   if (port->priv->hw_version == MVPP22) {
+   if (port->priv->hw_version != MVPP21) {
mvpp22_gop_mask_irq

[PATCH v11 net-next 03/15] net: mvpp2: add CM3 SRAM memory map

2021-02-09 Thread stefanc
From: Stefan Chulski 

This patch adds CM3 memory map.

Signed-off-by: Stefan Chulski 
Reviewed-by: Andrew Lunn 
---
 drivers/net/ethernet/marvell/mvpp2/mvpp2.h  |  1 +
 drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c | 26 
 2 files changed, 27 insertions(+)

diff --git a/drivers/net/ethernet/marvell/mvpp2/mvpp2.h 
b/drivers/net/ethernet/marvell/mvpp2/mvpp2.h
index 6bd7e40..56e90ab 100644
--- a/drivers/net/ethernet/marvell/mvpp2/mvpp2.h
+++ b/drivers/net/ethernet/marvell/mvpp2/mvpp2.h
@@ -925,6 +925,7 @@ struct mvpp2 {
/* Shared registers' base addresses */
void __iomem *lms_base;
void __iomem *iface_base;
+   void __iomem *cm3_base;
 
/* On PPv2.2, each "software thread" can access the base
 * register through a separate address space, each 64 KB apart
diff --git a/drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c 
b/drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c
index a07cf60..eec3796 100644
--- a/drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c
+++ b/drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c
@@ -6846,6 +6846,27 @@ static int mvpp2_init(struct platform_device *pdev, 
struct mvpp2 *priv)
return 0;
 }
 
+static int mvpp2_get_sram(struct platform_device *pdev,
+ struct mvpp2 *priv)
+{
+   struct resource *res;
+
+   res = platform_get_resource(pdev, IORESOURCE_MEM, 2);
+   if (!res) {
+   if (has_acpi_companion(&pdev->dev))
+   dev_warn(&pdev->dev, "ACPI is too old, Flow control not 
supported\n");
+   else
+   dev_warn(&pdev->dev, "DT is too old, Flow control not 
supported\n");
+   return 0;
+   }
+
+   priv->cm3_base = devm_ioremap_resource(&pdev->dev, res);
+   if (IS_ERR(priv->cm3_base))
+   return PTR_ERR(priv->cm3_base);
+
+   return 0;
+}
+
 static int mvpp2_probe(struct platform_device *pdev)
 {
const struct acpi_device_id *acpi_id;
@@ -6902,6 +6923,11 @@ static int mvpp2_probe(struct platform_device *pdev)
priv->iface_base = devm_ioremap_resource(&pdev->dev, res);
if (IS_ERR(priv->iface_base))
return PTR_ERR(priv->iface_base);
+
+   /* Map CM3 SRAM */
+   err = mvpp2_get_sram(pdev, priv);
+   if (err)
+   dev_warn(&pdev->dev, "Fail to alloc CM3 SRAM\n");
}
 
if (priv->hw_version == MVPP22 && dev_of_node(&pdev->dev)) {
-- 
1.9.1



[PATCH v11 net-next 02/15] dts: marvell: add CM3 SRAM memory to cp11x ethernet device tree

2021-02-09 Thread stefanc
From: Konstantin Porotchkin 

CM3 SRAM address space would be used for Flow Control configuration.

Signed-off-by: Stefan Chulski 
Signed-off-by: Konstantin Porotchkin 
---
 arch/arm64/boot/dts/marvell/armada-cp11x.dtsi | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/arm64/boot/dts/marvell/armada-cp11x.dtsi 
b/arch/arm64/boot/dts/marvell/armada-cp11x.dtsi
index 9dcf16b..6fe0d26 100644
--- a/arch/arm64/boot/dts/marvell/armada-cp11x.dtsi
+++ b/arch/arm64/boot/dts/marvell/armada-cp11x.dtsi
@@ -59,7 +59,7 @@
 
CP11X_LABEL(ethernet): ethernet@0 {
compatible = "marvell,armada-7k-pp22";
-   reg = <0x0 0x10>, <0x129000 0xb000>;
+   reg = <0x0 0x10>, <0x129000 0xb000>, <0x22 
0x800>;
clocks = <&CP11X_LABEL(clk) 1 3>, <&CP11X_LABEL(clk) 1 
9>,
 <&CP11X_LABEL(clk) 1 5>, <&CP11X_LABEL(clk) 1 
6>,
 <&CP11X_LABEL(clk) 1 18>;
-- 
1.9.1



[PATCH v11 net-next 01/15] doc: marvell: add CM3 address space and PPv2.3 description

2021-02-09 Thread stefanc
From: Stefan Chulski 

Patch adds CM3 address space and PPv2.3 description.

Signed-off-by: Stefan Chulski 
---
 Documentation/devicetree/bindings/net/marvell-pp2.txt | 6 --
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/Documentation/devicetree/bindings/net/marvell-pp2.txt 
b/Documentation/devicetree/bindings/net/marvell-pp2.txt
index b783976..ce15c17 100644
--- a/Documentation/devicetree/bindings/net/marvell-pp2.txt
+++ b/Documentation/devicetree/bindings/net/marvell-pp2.txt
@@ -1,5 +1,6 @@
 * Marvell Armada 375 Ethernet Controller (PPv2.1)
   Marvell Armada 7K/8K Ethernet Controller (PPv2.2)
+  Marvell CN913X Ethernet Controller (PPv2.3)
 
 Required properties:
 
@@ -12,10 +13,11 @@ Required properties:
- common controller registers
- LMS registers
- one register area per Ethernet port
-  For "marvell,armada-7k-pp2", must contain the following register
+  For "marvell,armada-7k-pp2" used by 7K/8K and CN913X, must contain the 
following register
   sets:
- packet processor registers
- networking interfaces registers
+   - CM3 address space used for TX Flow Control
 
 - clocks: pointers to the reference clocks for this device, consequently:
- main controller clock (for both armada-375-pp2 and armada-7k-pp2)
@@ -81,7 +83,7 @@ Example for marvell,armada-7k-pp2:
 
 cpm_ethernet: ethernet@0 {
compatible = "marvell,armada-7k-pp22";
-   reg = <0x0 0x10>, <0x129000 0xb000>;
+   reg = <0x0 0x10>, <0x129000 0xb000>, <0x22 0x800>;
clocks = <&cpm_syscon0 1 3>, <&cpm_syscon0 1 9>,
 <&cpm_syscon0 1 5>, <&cpm_syscon0 1 6>, <&cpm_syscon0 1 18>;
clock-names = "pp_clk", "gop_clk", "mg_clk", "mg_core_clk", "axi_clk";
-- 
1.9.1



[PATCH v11 net-next 00/15] net: mvpp2: Add TX Flow Control support

2021-02-09 Thread stefanc
From: Stefan Chulski 

Armada hardware has a pause generation mechanism in GOP (MAC).
The GOP generate flow control frames based on an indication programmed in Ports 
Control 0 Register. There is a bit per port.
However assertion of the PortX Pause bits in the ports control 0 register only 
sends a one time pause.
To complement the function the GOP has a mechanism to periodically send pause 
control messages based on periodic counters.
This mechanism ensures that the pause is effective as long as the Appropriate 
PortX Pause is asserted.

Problem is that Packet Processor that actually can drop packets due to lack of 
resources not connected to the GOP flow control generation mechanism.
To solve this issue Armada has firmware running on CM3 CPU dedicated for Flow 
Control support.
Firmware monitors Packet Processor resources and asserts XON/XOFF by writing to 
Ports Control 0 Register.

MSS shared SRAM memory used to communicate between CM3 firmware and PP2 driver.
During init PP2 driver informs firmware about used BM pools, RXQs, congestion 
and depletion thresholds.

The pause frames are generated whenever congestion or depletion in resources is 
detected.
The back pressure is stopped when the resource reaches a sufficient level.
So the congestion/depletion and sufficient level implement a hysteresis that 
reduces the XON/XOFF toggle frequency.

Packet Processor v23 hardware introduces support for RX FIFO fill level monitor.
Patch "add PPv23 version definition" to differ between v23 and v22 hardware.
Patch "add TX FC firmware check" verifies that CM3 firmware supports Flow 
Control monitoring.

v10 --> v11
- Improve "net: mvpp2: add CM3 SRAM memory map" comment
- Move condition check to 'net: mvpp2: always compare hw-version vs MVPP21' 
patch

v9 --> v10
- Add CM3 SRAM description to PPv2 documentation

v8 --> v9
- Replace generic pool allocation with devm_ioremap_resource

v7 --> v8
- Reorder "always compare hw-version vs MVPP21" and "add PPv23 version 
definition" commits
- Typo fixes
- Remove condition fix from "add RXQ flow control configurations"

v6 --> v7
- Reduce patch set from 18 to 15 patches
 - Documentation change combined into a single patch
 - RXQ and BM size change combined into a single patch
 - Ring size change check moved into "add RXQ flow control configurations" 
commit

v5 --> v6
- No change

v4 --> v5
- Add missed Signed-off
- Fix warnings in patches 3 and 12
- Add revision requirement to warning message
- Move mss_spinlock into RXQ flow control configurations patch
- Improve FCA RXQ non occupied descriptor threshold commit message

v3 --> v4
- Remove RFC tag

v2 --> v3
- Remove inline functions
- Add PPv2.3 description into marvell-pp2.txt
- Improve mvpp2_interrupts_mask/unmask procedure
- Improve FC enable/disable procedure
- Add priv->sram_pool check
- Remove gen_pool_destroy call
- Reduce Flow Control timer to x100 faster

v1 --> v2
- Add memory requirements information
- Add EPROBE_DEFER if of_gen_pool_get return NULL
- Move Flow control configuration to mvpp2_mac_link_up callback
- Add firmware version info with Flow control support

Konstantin Porotchkin (1):
  dts: marvell: add CM3 SRAM memory to cp11x ethernet device tree

Stefan Chulski (14):
  doc: marvell: add CM3 address space and PPv2.3 description
  net: mvpp2: add CM3 SRAM memory map
  net: mvpp2: always compare hw-version vs MVPP21
  net: mvpp2: add PPv23 version definition
  net: mvpp2: increase BM pool and RXQ size
  net: mvpp2: add FCA periodic timer configurations
  net: mvpp2: add FCA RXQ non occupied descriptor threshold
  net: mvpp2: enable global flow control
  net: mvpp2: add RXQ flow control configurations
  net: mvpp2: add ethtool flow control configuration support
  net: mvpp2: add BM protection underrun feature support
  net: mvpp2: add PPv23 RX FIFO flow control
  net: mvpp2: set 802.3x GoP Flow Control mode
  net: mvpp2: add TX FC firmware check

 Documentation/devicetree/bindings/net/marvell-pp2.txt |   6 +-
 arch/arm64/boot/dts/marvell/armada-cp11x.dtsi |   2 +-
 drivers/net/ethernet/marvell/mvpp2/mvpp2.h| 124 -
 drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c   | 526 
++--
 4 files changed, 609 insertions(+), 49 deletions(-)

-- 
1.9.1



[PATCH v10 net-next 11/15] net: mvpp2: add ethtool flow control configuration support

2021-02-08 Thread stefanc
From: Stefan Chulski 

This patch add ethtool flow control configuration support.

Tx flow control retrieved correctly by ethtool get function.
FW per port ethtool configuration capability added.

Patch also takes care about mtu change procedure, if PPv2 switch
BM pools during mtu change.

Signed-off-by: Stefan Chulski 
---
 drivers/net/ethernet/marvell/mvpp2/mvpp2.h  | 13 +++
 drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c | 98 
 2 files changed, 111 insertions(+)

diff --git a/drivers/net/ethernet/marvell/mvpp2/mvpp2.h 
b/drivers/net/ethernet/marvell/mvpp2/mvpp2.h
index 0010a3e9..0731dc7 100644
--- a/drivers/net/ethernet/marvell/mvpp2/mvpp2.h
+++ b/drivers/net/ethernet/marvell/mvpp2/mvpp2.h
@@ -774,6 +774,19 @@
 #define MSS_RXQ_TRESH_REG(q, fq)   (MSS_RXQ_TRESH_BASE + (((q) + (fq)) \
* MSS_RXQ_TRESH_OFFS))
 
+#define MSS_BUF_POOL_BASE  0x40
+#define MSS_BUF_POOL_OFFS  4
+#define MSS_BUF_POOL_REG(id)   (MSS_BUF_POOL_BASE  \
+   + (id) * MSS_BUF_POOL_OFFS)
+
+#define MSS_BUF_POOL_STOP_MASK 0xFFF
+#define MSS_BUF_POOL_START_MASK(0xFFF << 
MSS_BUF_POOL_START_OFFS)
+#define MSS_BUF_POOL_START_OFFS12
+#define MSS_BUF_POOL_PORTS_MASK(0xF << MSS_BUF_POOL_PORTS_OFFS)
+#define MSS_BUF_POOL_PORTS_OFFS24
+#define MSS_BUF_POOL_PORT_OFFS(id) (0x1 << \
+   ((id) + MSS_BUF_POOL_PORTS_OFFS))
+
 #define MSS_RXQ_TRESH_START_MASK   0x
 #define MSS_RXQ_TRESH_STOP_MASK(0x << 
MSS_RXQ_TRESH_STOP_OFFS)
 #define MSS_RXQ_TRESH_STOP_OFFS16
diff --git a/drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c 
b/drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c
index f1770e5..90c9265 100644
--- a/drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c
+++ b/drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c
@@ -845,6 +845,59 @@ static void mvpp2_rxq_disable_fc(struct mvpp2_port *port)
spin_unlock_irqrestore(&port->priv->mss_spinlock, flags);
 }
 
+/* Routine disable/enable flow control for BM pool condition */
+static void mvpp2_bm_pool_update_fc(struct mvpp2_port *port,
+   struct mvpp2_bm_pool *pool,
+   bool en)
+{
+   int val, cm3_state;
+   unsigned long flags;
+
+   spin_lock_irqsave(&port->priv->mss_spinlock, flags);
+
+   /* Remove Flow control enable bit to prevent race between FW and Kernel
+* If Flow control were enabled, it would be re-enabled.
+*/
+   val = mvpp2_cm3_read(port->priv, MSS_FC_COM_REG);
+   cm3_state = (val & FLOW_CONTROL_ENABLE_BIT);
+   val &= ~FLOW_CONTROL_ENABLE_BIT;
+   mvpp2_cm3_write(port->priv, MSS_FC_COM_REG, val);
+
+   /* Check if BM pool should be enabled/disable */
+   if (en) {
+   /* Set BM pool start and stop thresholds per port */
+   val = mvpp2_cm3_read(port->priv, MSS_BUF_POOL_REG(pool->id));
+   val |= MSS_BUF_POOL_PORT_OFFS(port->id);
+   val &= ~MSS_BUF_POOL_START_MASK;
+   val |= (MSS_THRESHOLD_START << MSS_BUF_POOL_START_OFFS);
+   val &= ~MSS_BUF_POOL_STOP_MASK;
+   val |= MSS_THRESHOLD_STOP;
+   mvpp2_cm3_write(port->priv, MSS_BUF_POOL_REG(pool->id), val);
+   } else {
+   /* Remove BM pool from the port */
+   val = mvpp2_cm3_read(port->priv, MSS_BUF_POOL_REG(pool->id));
+   val &= ~MSS_BUF_POOL_PORT_OFFS(port->id);
+
+   /* Zero BM pool start and stop thresholds to disable pool
+* flow control if pool empty (not used by any port)
+*/
+   if (!pool->buf_num) {
+   val &= ~MSS_BUF_POOL_START_MASK;
+   val &= ~MSS_BUF_POOL_STOP_MASK;
+   }
+
+   mvpp2_cm3_write(port->priv, MSS_BUF_POOL_REG(pool->id), val);
+   }
+
+   /* Notify Firmware that Flow control config space ready for update */
+   val = mvpp2_cm3_read(port->priv, MSS_FC_COM_REG);
+   val |= FLOW_CONTROL_UPDATE_COMMAND_BIT;
+   val |= cm3_state;
+   mvpp2_cm3_write(port->priv, MSS_FC_COM_REG, val);
+
+   spin_unlock_irqrestore(&port->priv->mss_spinlock, flags);
+}
+
 /* Release buffer to BM */
 static inline void mvpp2_bm_pool_put(struct mvpp2_port *port, int pool,
 dma_addr_t buf_dma_addr,
@@ -1175,6 +1228,16 @@ static int mvpp2_bm_update_mtu(struct net_device *dev, 
int mtu)
new_long_pool = MVPP2_BM_LONG;
 
if (new_long_pool != port->pool_long->id) {
+   if (port->tx_fc) {
+   if (pkt_size > MVPP2_BM_LONG_PKT_SIZE)
+   mvpp2_bm_pool_update_fc(port,
+   

[PATCH v10 net-next 14/15] net: mvpp2: set 802.3x GoP Flow Control mode

2021-02-08 Thread stefanc
From: Stefan Chulski 

This patch fix GMAC TX flow control autoneg.
Flow control autoneg wrongly were disabled with enabled TX
flow control.

Signed-off-by: Stefan Chulski 
---
 drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c 
b/drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c
index a472125..4d0a398 100644
--- a/drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c
+++ b/drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c
@@ -6283,7 +6283,7 @@ static void mvpp2_gmac_config(struct mvpp2_port *port, 
unsigned int mode,
old_ctrl4 = ctrl4 = readl(port->base + MVPP22_GMAC_CTRL_4_REG);
 
ctrl0 &= ~MVPP2_GMAC_PORT_TYPE_MASK;
-   ctrl2 &= ~(MVPP2_GMAC_INBAND_AN_MASK | MVPP2_GMAC_PCS_ENABLE_MASK);
+   ctrl2 &= ~(MVPP2_GMAC_INBAND_AN_MASK | MVPP2_GMAC_PCS_ENABLE_MASK | 
MVPP2_GMAC_FLOW_CTRL_MASK);
 
/* Configure port type */
if (phy_interface_mode_is_8023z(state->interface)) {
-- 
1.9.1



[PATCH v10 net-next 12/15] net: mvpp2: add BM protection underrun feature support

2021-02-08 Thread stefanc
From: Stefan Chulski 

The PP2v23 hardware supports a feature allowing to double the
size of BPPI by decreasing number of pools from 16 to 8.
Increasing of BPPI size protect BM drop from BPPI underrun.
Underrun could occurred due to stress on DDR and as result slow buffer
transition from BPPE to BPPI.
New BPPI threshold recommended by spec is:
BPPI low threshold - 640 buffers
BPPI high threshold - 832 buffers
Supported only in PPv23.

Signed-off-by: Stefan Chulski 
---
 drivers/net/ethernet/marvell/mvpp2/mvpp2.h  |  8 +
 drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c | 35 +++-
 2 files changed, 42 insertions(+), 1 deletion(-)

diff --git a/drivers/net/ethernet/marvell/mvpp2/mvpp2.h 
b/drivers/net/ethernet/marvell/mvpp2/mvpp2.h
index 0731dc7..9b525b60 100644
--- a/drivers/net/ethernet/marvell/mvpp2/mvpp2.h
+++ b/drivers/net/ethernet/marvell/mvpp2/mvpp2.h
@@ -324,6 +324,10 @@
 #define MVPP2_BM_HIGH_THRESH_MASK  0x7f
 #define MVPP2_BM_HIGH_THRESH_VALUE(val)((val) << \
MVPP2_BM_HIGH_THRESH_OFFS)
+#define MVPP2_BM_BPPI_HIGH_THRESH  0x1E
+#define MVPP2_BM_BPPI_LOW_THRESH   0x1C
+#define MVPP23_BM_BPPI_HIGH_THRESH 0x34
+#define MVPP23_BM_BPPI_LOW_THRESH  0x28
 #define MVPP2_BM_INTR_CAUSE_REG(pool)  (0x6240 + ((pool) * 4))
 #define MVPP2_BM_RELEASED_DELAY_MASK   BIT(0)
 #define MVPP2_BM_ALLOC_FAILED_MASK BIT(1)
@@ -352,6 +356,10 @@
 #define MVPP2_OVERRUN_ETH_DROP 0x7000
 #define MVPP2_CLS_ETH_DROP 0x7020
 
+#define MVPP22_BM_POOL_BASE_ADDR_HIGH_REG  0x6310
+#define MVPP22_BM_POOL_BASE_ADDR_HIGH_MASK 0xff
+#define MVPP23_BM_8POOL_MODE   BIT(8)
+
 /* Hit counters registers */
 #define MVPP2_CTRS_IDX 0x7040
 #define MVPP22_CTRS_TX_CTR(port, txq)  ((txq) | ((port) << 3) | BIT(7))
diff --git a/drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c 
b/drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c
index 90c9265..3faad04 100644
--- a/drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c
+++ b/drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c
@@ -69,6 +69,11 @@ enum mvpp2_bm_pool_log_num {
 module_param(queue_mode, int, 0444);
 MODULE_PARM_DESC(queue_mode, "Set queue_mode (single=0, multi=1)");
 
+static int bm_underrun_protect = 1;
+
+module_param(bm_underrun_protect, int, 0444);
+MODULE_PARM_DESC(bm_underrun_protect, "Set BM underrun protect feature (0-1), 
def=1");
+
 /* Utility/helper methods */
 
 void mvpp2_write(struct mvpp2 *priv, u32 offset, u32 data)
@@ -423,6 +428,21 @@ static int mvpp2_bm_pool_create(struct device *dev, struct 
mvpp2 *priv,
 
val = mvpp2_read(priv, MVPP2_BM_POOL_CTRL_REG(bm_pool->id));
val |= MVPP2_BM_START_MASK;
+
+   val &= ~MVPP2_BM_LOW_THRESH_MASK;
+   val &= ~MVPP2_BM_HIGH_THRESH_MASK;
+
+   /* Set 8 Pools BPPI threshold if BM underrun protection feature
+* was enabled
+*/
+   if (priv->hw_version == MVPP23 && bm_underrun_protect) {
+   val |= MVPP2_BM_LOW_THRESH_VALUE(MVPP23_BM_BPPI_LOW_THRESH);
+   val |= MVPP2_BM_HIGH_THRESH_VALUE(MVPP23_BM_BPPI_HIGH_THRESH);
+   } else {
+   val |= MVPP2_BM_LOW_THRESH_VALUE(MVPP2_BM_BPPI_LOW_THRESH);
+   val |= MVPP2_BM_HIGH_THRESH_VALUE(MVPP2_BM_BPPI_HIGH_THRESH);
+   }
+
mvpp2_write(priv, MVPP2_BM_POOL_CTRL_REG(bm_pool->id), val);
 
bm_pool->size = size;
@@ -591,6 +611,16 @@ static int mvpp2_bm_pools_init(struct device *dev, struct 
mvpp2 *priv)
return err;
 }
 
+/* Routine enable PPv23 8 pool mode */
+static void mvpp23_bm_set_8pool_mode(struct mvpp2 *priv)
+{
+   int val;
+
+   val = mvpp2_read(priv, MVPP22_BM_POOL_BASE_ADDR_HIGH_REG);
+   val |= MVPP23_BM_8POOL_MODE;
+   mvpp2_write(priv, MVPP22_BM_POOL_BASE_ADDR_HIGH_REG, val);
+}
+
 static int mvpp2_bm_init(struct device *dev, struct mvpp2 *priv)
 {
enum dma_data_direction dma_dir = DMA_FROM_DEVICE;
@@ -644,6 +674,9 @@ static int mvpp2_bm_init(struct device *dev, struct mvpp2 
*priv)
if (!priv->bm_pools)
return -ENOMEM;
 
+   if (priv->hw_version == MVPP23 && bm_underrun_protect)
+   mvpp23_bm_set_8pool_mode(priv);
+
err = mvpp2_bm_pools_init(dev, priv);
if (err < 0)
return err;
@@ -6490,7 +6523,7 @@ static void mvpp2_mac_link_up(struct phylink_config 
*config,
 val);
}
 
-   if (port->priv->global_tx_fc) {
+   if (port->priv->global_tx_fc && bm_underrun_protect) {
port->tx_fc = tx_pause;
if (tx_pause)
mvpp2_rxq_enable_fc(port);
-- 
1.9.1



[PATCH v10 net-next 15/15] net: mvpp2: add TX FC firmware check

2021-02-08 Thread stefanc
From: Stefan Chulski 

Patch check that TX FC firmware is running in CM3.
If not, global TX FC would be disabled.

Signed-off-by: Stefan Chulski 
---
 drivers/net/ethernet/marvell/mvpp2/mvpp2.h  |  1 +
 drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c | 42 
 2 files changed, 36 insertions(+), 7 deletions(-)

diff --git a/drivers/net/ethernet/marvell/mvpp2/mvpp2.h 
b/drivers/net/ethernet/marvell/mvpp2/mvpp2.h
index b61a1ba..da87152 100644
--- a/drivers/net/ethernet/marvell/mvpp2/mvpp2.h
+++ b/drivers/net/ethernet/marvell/mvpp2/mvpp2.h
@@ -828,6 +828,7 @@
 
 #define MSS_THRESHOLD_STOP 768
 #define MSS_THRESHOLD_START1024
+#define MSS_FC_MAX_TIMEOUT 5000
 
 /* RX buffer constants */
 #define MVPP2_SKB_SHINFO_SIZE \
diff --git a/drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c 
b/drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c
index 4d0a398..fed4521 100644
--- a/drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c
+++ b/drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c
@@ -931,6 +931,34 @@ static void mvpp2_bm_pool_update_fc(struct mvpp2_port 
*port,
spin_unlock_irqrestore(&port->priv->mss_spinlock, flags);
 }
 
+static int mvpp2_enable_global_fc(struct mvpp2 *priv)
+{
+   int val, timeout = 0;
+
+   /* Enable global flow control. In this stage global
+* flow control enabled, but still disabled per port.
+*/
+   val = mvpp2_cm3_read(priv, MSS_FC_COM_REG);
+   val |= FLOW_CONTROL_ENABLE_BIT;
+   mvpp2_cm3_write(priv, MSS_FC_COM_REG, val);
+
+   /* Check if Firmware running and disable FC if not*/
+   val |= FLOW_CONTROL_UPDATE_COMMAND_BIT;
+   mvpp2_cm3_write(priv, MSS_FC_COM_REG, val);
+
+   while (timeout < MSS_FC_MAX_TIMEOUT) {
+   val = mvpp2_cm3_read(priv, MSS_FC_COM_REG);
+
+   if (!(val & FLOW_CONTROL_UPDATE_COMMAND_BIT))
+   return 0;
+   usleep_range(10, 20);
+   timeout++;
+   }
+
+   priv->global_tx_fc = false;
+   return -EOPNOTSUPP;
+}
+
 /* Release buffer to BM */
 static inline void mvpp2_bm_pool_put(struct mvpp2_port *port, int pool,
 dma_addr_t buf_dma_addr,
@@ -7263,7 +7291,7 @@ static int mvpp2_probe(struct platform_device *pdev)
struct resource *res;
void __iomem *base;
int i, shared;
-   int err, val;
+   int err;
 
priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL);
if (!priv)
@@ -7487,13 +7515,13 @@ static int mvpp2_probe(struct platform_device *pdev)
goto err_port_probe;
}
 
-   /* Enable global flow control. In this stage global
-* flow control enabled, but still disabled per port.
-*/
if (priv->global_tx_fc && priv->hw_version != MVPP21) {
-   val = mvpp2_cm3_read(priv, MSS_FC_COM_REG);
-   val |= FLOW_CONTROL_ENABLE_BIT;
-   mvpp2_cm3_write(priv, MSS_FC_COM_REG, val);
+   err = mvpp2_enable_global_fc(priv);
+   if (err) {
+   dev_warn(&pdev->dev, "CM3 firmware not running, version 
should be higher than 18.09 ");
+   dev_warn(&pdev->dev, "and chip revision B0\n");
+   dev_warn(&pdev->dev, "Flow control not supported\n");
+   }
}
 
mvpp2_dbgfs_init(priv, pdev->name);
-- 
1.9.1



[PATCH v10 net-next 13/15] net: mvpp2: add PPv23 RX FIFO flow control

2021-02-08 Thread stefanc
From: Stefan Chulski 

New FIFO flow control feature was added in PPv23.
PPv2 FIFO polled by HW and trigger pause frame if FIFO
fill level is below threshold.
FIFO HW flow control enabled with CM3 RXQ&BM flow
control with ethtool.
Current  FIFO thresholds is:
9KB for port with maximum speed 10Gb/s port
4KB for port with maximum speed 5Gb/s port
2KB for port with maximum speed 1Gb/s port

Signed-off-by: Stefan Chulski 
---
 drivers/net/ethernet/marvell/mvpp2/mvpp2.h  | 15 ++
 drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c | 53 
 2 files changed, 68 insertions(+)

diff --git a/drivers/net/ethernet/marvell/mvpp2/mvpp2.h 
b/drivers/net/ethernet/marvell/mvpp2/mvpp2.h
index 9b525b60..b61a1ba 100644
--- a/drivers/net/ethernet/marvell/mvpp2/mvpp2.h
+++ b/drivers/net/ethernet/marvell/mvpp2/mvpp2.h
@@ -770,6 +770,18 @@
 #define MVPP2_TX_FIFO_THRESHOLD(kb)\
((kb) * 1024 - MVPP2_TX_FIFO_THRESHOLD_MIN)
 
+/* RX FIFO threshold in 1KB granularity */
+#define MVPP23_PORT0_FIFO_TRSH (9 * 1024)
+#define MVPP23_PORT1_FIFO_TRSH (4 * 1024)
+#define MVPP23_PORT2_FIFO_TRSH (2 * 1024)
+
+/* RX Flow Control Registers */
+#define MVPP2_RX_FC_REG(port)  (0x150 + 4 * (port))
+#define MVPP2_RX_FC_EN BIT(24)
+#define MVPP2_RX_FC_TRSH_OFFS  16
+#define MVPP2_RX_FC_TRSH_MASK  (0xFF << MVPP2_RX_FC_TRSH_OFFS)
+#define MVPP2_RX_FC_TRSH_UNIT  256
+
 /* MSS Flow control */
 #define MSS_FC_COM_REG 0
 #define FLOW_CONTROL_ENABLE_BITBIT(0)
@@ -1498,6 +1510,8 @@ struct mvpp2_bm_pool {
 
 void mvpp2_dbgfs_cleanup(struct mvpp2 *priv);
 
+void mvpp23_rx_fifo_fc_en(struct mvpp2 *priv, int port, bool en);
+
 #ifdef CONFIG_MVPP2_PTP
 int mvpp22_tai_probe(struct device *dev, struct mvpp2 *priv);
 void mvpp22_tai_tstamp(struct mvpp2_tai *tai, u32 tstamp,
@@ -1530,4 +1544,5 @@ static inline bool mvpp22_rx_hwtstamping(struct 
mvpp2_port *port)
 {
return IS_ENABLED(CONFIG_MVPP2_PTP) && port->rx_hwtstamp;
 }
+
 #endif
diff --git a/drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c 
b/drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c
index 3faad04..a472125 100644
--- a/drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c
+++ b/drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c
@@ -6536,6 +6536,8 @@ static void mvpp2_mac_link_up(struct phylink_config 
*config,
mvpp2_bm_pool_update_fc(port, port->pool_long, 
tx_pause);
mvpp2_bm_pool_update_fc(port, port->pool_short, 
tx_pause);
}
+   if (port->priv->hw_version == MVPP23)
+   mvpp23_rx_fifo_fc_en(port->priv, port->id, tx_pause);
}
 
mvpp2_port_enable(port);
@@ -7004,6 +7006,55 @@ static void mvpp22_rx_fifo_init(struct mvpp2 *priv)
mvpp2_write(priv, MVPP2_RX_FIFO_INIT_REG, 0x1);
 }
 
+/* Configure Rx FIFO Flow control thresholds */
+static void mvpp23_rx_fifo_fc_set_tresh(struct mvpp2 *priv)
+{
+   int port, val;
+
+   /* Port 0: maximum speed -10Gb/s port
+* required by spec RX FIFO threshold 9KB
+* Port 1: maximum speed -5Gb/s port
+* required by spec RX FIFO threshold 4KB
+* Port 2: maximum speed -1Gb/s port
+* required by spec RX FIFO threshold 2KB
+*/
+
+   /* Without loopback port */
+   for (port = 0; port < (MVPP2_MAX_PORTS - 1); port++) {
+   if (port == 0) {
+   val = (MVPP23_PORT0_FIFO_TRSH / MVPP2_RX_FC_TRSH_UNIT)
+   << MVPP2_RX_FC_TRSH_OFFS;
+   val &= MVPP2_RX_FC_TRSH_MASK;
+   mvpp2_write(priv, MVPP2_RX_FC_REG(port), val);
+   } else if (port == 1) {
+   val = (MVPP23_PORT1_FIFO_TRSH / MVPP2_RX_FC_TRSH_UNIT)
+   << MVPP2_RX_FC_TRSH_OFFS;
+   val &= MVPP2_RX_FC_TRSH_MASK;
+   mvpp2_write(priv, MVPP2_RX_FC_REG(port), val);
+   } else {
+   val = (MVPP23_PORT2_FIFO_TRSH / MVPP2_RX_FC_TRSH_UNIT)
+   << MVPP2_RX_FC_TRSH_OFFS;
+   val &= MVPP2_RX_FC_TRSH_MASK;
+   mvpp2_write(priv, MVPP2_RX_FC_REG(port), val);
+   }
+   }
+}
+
+/* Configure Rx FIFO Flow control thresholds */
+void mvpp23_rx_fifo_fc_en(struct mvpp2 *priv, int port, bool en)
+{
+   int val;
+
+   val = mvpp2_read(priv, MVPP2_RX_FC_REG(port));
+
+   if (en)
+   val |= MVPP2_RX_FC_EN;
+   else
+   val &= ~MVPP2_RX_FC_EN;
+
+   mvpp2_write(priv, MVPP2_RX_FC_REG(port), val);
+}
+
 static void mvpp22_tx_fifo_set_hw(struct mvpp2 *priv, int port, int size)
 {
int threshold = MVPP2_TX_FIFO_THRESHOLD(size);
@@ -7155,6 +7206,8 @@ static int mvpp2_init(struct platform_device *pdev, 
struct mvpp2 *priv)
} else {
mvpp22_rx_fifo_init(priv);
 

[PATCH v10 net-next 10/15] net: mvpp2: add RXQ flow control configurations

2021-02-08 Thread stefanc
From: Stefan Chulski 

This patch adds RXQ flow control configurations.
Flow control disabled by default.
Minimum ring size limited to 1024 descriptors.

Signed-off-by: Stefan Chulski 
---
 drivers/net/ethernet/marvell/mvpp2/mvpp2.h  |  35 +-
 drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c | 116 
 2 files changed, 150 insertions(+), 1 deletion(-)

diff --git a/drivers/net/ethernet/marvell/mvpp2/mvpp2.h 
b/drivers/net/ethernet/marvell/mvpp2/mvpp2.h
index 8945fb9..0010a3e9 100644
--- a/drivers/net/ethernet/marvell/mvpp2/mvpp2.h
+++ b/drivers/net/ethernet/marvell/mvpp2/mvpp2.h
@@ -765,9 +765,36 @@
 /* MSS Flow control */
 #define MSS_FC_COM_REG 0
 #define FLOW_CONTROL_ENABLE_BITBIT(0)
+#define FLOW_CONTROL_UPDATE_COMMAND_BITBIT(31)
 #define FC_QUANTA  0x
 #define FC_CLK_DIVIDER 100
-#define MSS_THRESHOLD_STOP 768
+
+#define MSS_RXQ_TRESH_BASE 0x200
+#define MSS_RXQ_TRESH_OFFS 4
+#define MSS_RXQ_TRESH_REG(q, fq)   (MSS_RXQ_TRESH_BASE + (((q) + (fq)) \
+   * MSS_RXQ_TRESH_OFFS))
+
+#define MSS_RXQ_TRESH_START_MASK   0x
+#define MSS_RXQ_TRESH_STOP_MASK(0x << 
MSS_RXQ_TRESH_STOP_OFFS)
+#define MSS_RXQ_TRESH_STOP_OFFS16
+
+#define MSS_RXQ_ASS_BASE   0x80
+#define MSS_RXQ_ASS_OFFS   4
+#define MSS_RXQ_ASS_PER_REG4
+#define MSS_RXQ_ASS_PER_OFFS   8
+#define MSS_RXQ_ASS_PORTID_OFFS0
+#define MSS_RXQ_ASS_PORTID_MASK0x3
+#define MSS_RXQ_ASS_HOSTID_OFFS2
+#define MSS_RXQ_ASS_HOSTID_MASK0x3F
+
+#define MSS_RXQ_ASS_Q_BASE(q, fq) q) + (fq)) % MSS_RXQ_ASS_PER_REG)
 \
+ * MSS_RXQ_ASS_PER_OFFS)
+#define MSS_RXQ_ASS_PQ_BASE(q, fq) q) + (fq)) / MSS_RXQ_ASS_PER_REG) \
+  * MSS_RXQ_ASS_OFFS)
+#define MSS_RXQ_ASS_REG(q, fq) (MSS_RXQ_ASS_BASE + MSS_RXQ_ASS_PQ_BASE(q, fq))
+
+#define MSS_THRESHOLD_STOP 768
+#define MSS_THRESHOLD_START1024
 
 /* RX buffer constants */
 #define MVPP2_SKB_SHINFO_SIZE \
@@ -1022,6 +1049,9 @@ struct mvpp2 {
 
/* Global TX Flow Control config */
bool global_tx_fc;
+
+   /* Spinlocks for CM3 shared memory configuration */
+   spinlock_t mss_spinlock;
 };
 
 struct mvpp2_pcpu_stats {
@@ -1184,6 +1214,9 @@ struct mvpp2_port {
bool rx_hwtstamp;
enum hwtstamp_tx_types tx_hwtstamp_type;
struct mvpp2_hwtstamp_queue tx_hwtstamp_queue[2];
+
+   /* Firmware TX flow control */
+   bool tx_fc;
 };
 
 /* The mvpp2_tx_desc and mvpp2_rx_desc structures describe the
diff --git a/drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c 
b/drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c
index 027101b..f1770e5 100644
--- a/drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c
+++ b/drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c
@@ -741,6 +741,110 @@ static void *mvpp2_buf_alloc(struct mvpp2_port *port,
return data;
 }
 
+/* Routine enable flow control for RXQs condition */
+static void mvpp2_rxq_enable_fc(struct mvpp2_port *port)
+{
+   int val, cm3_state, host_id, q;
+   int fq = port->first_rxq;
+   unsigned long flags;
+
+   spin_lock_irqsave(&port->priv->mss_spinlock, flags);
+
+   /* Remove Flow control enable bit to prevent race between FW and Kernel
+* If Flow control was enabled, it would be re-enabled.
+*/
+   val = mvpp2_cm3_read(port->priv, MSS_FC_COM_REG);
+   cm3_state = (val & FLOW_CONTROL_ENABLE_BIT);
+   val &= ~FLOW_CONTROL_ENABLE_BIT;
+   mvpp2_cm3_write(port->priv, MSS_FC_COM_REG, val);
+
+   /* Set same Flow control for all RXQs */
+   for (q = 0; q < port->nrxqs; q++) {
+   /* Set stop and start Flow control RXQ thresholds */
+   val = MSS_THRESHOLD_START;
+   val |= (MSS_THRESHOLD_STOP << MSS_RXQ_TRESH_STOP_OFFS);
+   mvpp2_cm3_write(port->priv, MSS_RXQ_TRESH_REG(q, fq), val);
+
+   val = mvpp2_cm3_read(port->priv, MSS_RXQ_ASS_REG(q, fq));
+   /* Set RXQ port ID */
+   val &= ~(MSS_RXQ_ASS_PORTID_MASK << MSS_RXQ_ASS_Q_BASE(q, fq));
+   val |= (port->id << MSS_RXQ_ASS_Q_BASE(q, fq));
+   val &= ~(MSS_RXQ_ASS_HOSTID_MASK << (MSS_RXQ_ASS_Q_BASE(q, fq)
+   + MSS_RXQ_ASS_HOSTID_OFFS));
+
+   /* Calculate RXQ host ID:
+* In Single queue mode: Host ID equal to Host ID used for
+*   shared RX interrupt
+* In Multi queue mode: Host ID equal to number of
+*  RXQ ID / number of CoS queues
+* In Single resource mode: Host ID always equal to 0
+*/
+   if (queue_mode == MVPP2_QDIST_SINGLE_MODE)
+   host_id = port->nqvecs;
+   else if (queue

[PATCH v10 net-next 09/15] net: mvpp2: enable global flow control

2021-02-08 Thread stefanc
From: Stefan Chulski 

This patch enables global flow control in FW and in the phylink validate mask.

Signed-off-by: Stefan Chulski 
---
 drivers/net/ethernet/marvell/mvpp2/mvpp2.h  | 11 +--
 drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c | 30 +++-
 2 files changed, 37 insertions(+), 4 deletions(-)

diff --git a/drivers/net/ethernet/marvell/mvpp2/mvpp2.h 
b/drivers/net/ethernet/marvell/mvpp2/mvpp2.h
index d2cc513c..8945fb9 100644
--- a/drivers/net/ethernet/marvell/mvpp2/mvpp2.h
+++ b/drivers/net/ethernet/marvell/mvpp2/mvpp2.h
@@ -763,9 +763,11 @@
((kb) * 1024 - MVPP2_TX_FIFO_THRESHOLD_MIN)
 
 /* MSS Flow control */
-#define FC_QUANTA  0x
-#define FC_CLK_DIVIDER 100
-#define MSS_THRESHOLD_STOP 768
+#define MSS_FC_COM_REG 0
+#define FLOW_CONTROL_ENABLE_BITBIT(0)
+#define FC_QUANTA  0x
+#define FC_CLK_DIVIDER 100
+#define MSS_THRESHOLD_STOP 768
 
 /* RX buffer constants */
 #define MVPP2_SKB_SHINFO_SIZE \
@@ -1017,6 +1019,9 @@ struct mvpp2 {
 
/* page_pool allocator */
struct page_pool *page_pool[MVPP2_PORT_MAX_RXQ];
+
+   /* Global TX Flow Control config */
+   bool global_tx_fc;
 };
 
 struct mvpp2_pcpu_stats {
diff --git a/drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c 
b/drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c
index 8b4073c..027101b 100644
--- a/drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c
+++ b/drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c
@@ -91,6 +91,16 @@ static inline u32 mvpp2_cpu_to_thread(struct mvpp2 *priv, 
int cpu)
return cpu % priv->nthreads;
 }
 
+static void mvpp2_cm3_write(struct mvpp2 *priv, u32 offset, u32 data)
+{
+   writel(data, priv->cm3_base + offset);
+}
+
+static u32 mvpp2_cm3_read(struct mvpp2 *priv, u32 offset)
+{
+   return readl(priv->cm3_base + offset);
+}
+
 static struct page_pool *
 mvpp2_create_page_pool(struct device *dev, int num, int len,
   enum dma_data_direction dma_dir)
@@ -5950,6 +5960,11 @@ static void mvpp2_phylink_validate(struct phylink_config 
*config,
phylink_set(mask, Autoneg);
phylink_set_port_modes(mask);
 
+   if (port->priv->global_tx_fc) {
+   phylink_set(mask, Pause);
+   phylink_set(mask, Asym_Pause);
+   }
+
switch (state->interface) {
case PHY_INTERFACE_MODE_10GBASER:
case PHY_INTERFACE_MODE_XAUI:
@@ -6951,7 +6966,7 @@ static int mvpp2_probe(struct platform_device *pdev)
struct resource *res;
void __iomem *base;
int i, shared;
-   int err;
+   int err, val;
 
priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL);
if (!priv)
@@ -7003,6 +7018,10 @@ static int mvpp2_probe(struct platform_device *pdev)
err = mvpp2_get_sram(pdev, priv);
if (err)
dev_warn(&pdev->dev, "Fail to alloc CM3 SRAM\n");
+
+   /* Enable global Flow Control only if handler to SRAM not NULL 
*/
+   if (priv->cm3_base)
+   priv->global_tx_fc = true;
}
 
if (priv->hw_version != MVPP21 && dev_of_node(&pdev->dev)) {
@@ -7168,6 +7187,15 @@ static int mvpp2_probe(struct platform_device *pdev)
goto err_port_probe;
}
 
+   /* Enable global flow control. In this stage global
+* flow control enabled, but still disabled per port.
+*/
+   if (priv->global_tx_fc && priv->hw_version != MVPP21) {
+   val = mvpp2_cm3_read(priv, MSS_FC_COM_REG);
+   val |= FLOW_CONTROL_ENABLE_BIT;
+   mvpp2_cm3_write(priv, MSS_FC_COM_REG, val);
+   }
+
mvpp2_dbgfs_init(priv, pdev->name);
 
platform_set_drvdata(pdev, priv);
-- 
1.9.1



[PATCH v10 net-next 07/15] net: mvpp2: add FCA periodic timer configurations

2021-02-08 Thread stefanc
From: Stefan Chulski 

Flow Control periodic timer would be used if port in
XOFF to transmit periodic XOFF frames.

Signed-off-by: Stefan Chulski 
---
 drivers/net/ethernet/marvell/mvpp2/mvpp2.h  | 13 ++
 drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c | 45 
 2 files changed, 58 insertions(+)

diff --git a/drivers/net/ethernet/marvell/mvpp2/mvpp2.h 
b/drivers/net/ethernet/marvell/mvpp2/mvpp2.h
index e7bbf0a..9239d80 100644
--- a/drivers/net/ethernet/marvell/mvpp2/mvpp2.h
+++ b/drivers/net/ethernet/marvell/mvpp2/mvpp2.h
@@ -596,6 +596,15 @@
 #define MVPP22_MPCS_CLK_RESET_DIV_RATIO(n) ((n) << 4)
 #define MVPP22_MPCS_CLK_RESET_DIV_SET  BIT(11)
 
+/* FCA registers. PPv2.2 and PPv2.3 */
+#define MVPP22_FCA_BASE(port)  (0x7600 + (port) * 0x1000)
+#define MVPP22_FCA_REG_SIZE16
+#define MVPP22_FCA_REG_MASK0x
+#define MVPP22_FCA_CONTROL_REG 0x0
+#define MVPP22_FCA_ENABLE_PERIODIC BIT(11)
+#define MVPP22_PERIODIC_COUNTER_LSB_REG(0x110)
+#define MVPP22_PERIODIC_COUNTER_MSB_REG(0x114)
+
 /* XPCS registers. PPv2.2 and PPv2.3 */
 #define MVPP22_XPCS_BASE(port) (0x7400 + (port) * 0x1000)
 #define MVPP22_XPCS_CFG0   0x0
@@ -751,6 +760,10 @@
 #define MVPP2_TX_FIFO_THRESHOLD(kb)\
((kb) * 1024 - MVPP2_TX_FIFO_THRESHOLD_MIN)
 
+/* MSS Flow control */
+#define FC_QUANTA  0x
+#define FC_CLK_DIVIDER 100
+
 /* RX buffer constants */
 #define MVPP2_SKB_SHINFO_SIZE \
SKB_DATA_ALIGN(sizeof(struct skb_shared_info))
diff --git a/drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c 
b/drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c
index 5730900..761f745 100644
--- a/drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c
+++ b/drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c
@@ -1280,6 +1280,49 @@ static void mvpp22_gop_init_10gkr(struct mvpp2_port 
*port)
writel(val, mpcs + MVPP22_MPCS_CLK_RESET);
 }
 
+static void mvpp22_gop_fca_enable_periodic(struct mvpp2_port *port, bool en)
+{
+   struct mvpp2 *priv = port->priv;
+   void __iomem *fca = priv->iface_base + MVPP22_FCA_BASE(port->gop_id);
+   u32 val;
+
+   val = readl(fca + MVPP22_FCA_CONTROL_REG);
+   val &= ~MVPP22_FCA_ENABLE_PERIODIC;
+   if (en)
+   val |= MVPP22_FCA_ENABLE_PERIODIC;
+   writel(val, fca + MVPP22_FCA_CONTROL_REG);
+}
+
+static void mvpp22_gop_fca_set_timer(struct mvpp2_port *port, u32 timer)
+{
+   struct mvpp2 *priv = port->priv;
+   void __iomem *fca = priv->iface_base + MVPP22_FCA_BASE(port->gop_id);
+   u32 lsb, msb;
+
+   lsb = timer & MVPP22_FCA_REG_MASK;
+   msb = timer >> MVPP22_FCA_REG_SIZE;
+
+   writel(lsb, fca + MVPP22_PERIODIC_COUNTER_LSB_REG);
+   writel(msb, fca + MVPP22_PERIODIC_COUNTER_MSB_REG);
+}
+
+/* Set Flow Control timer x100 faster than pause quanta to ensure that link
+ * partner won't send traffic if port is in XOFF mode.
+ */
+static void mvpp22_gop_fca_set_periodic_timer(struct mvpp2_port *port)
+{
+   u32 timer;
+
+   timer = (port->priv->tclk / (USEC_PER_SEC * FC_CLK_DIVIDER))
+   * FC_QUANTA;
+
+   mvpp22_gop_fca_enable_periodic(port, false);
+
+   mvpp22_gop_fca_set_timer(port, timer);
+
+   mvpp22_gop_fca_enable_periodic(port, true);
+}
+
 static int mvpp22_gop_init(struct mvpp2_port *port)
 {
struct mvpp2 *priv = port->priv;
@@ -1324,6 +1367,8 @@ static int mvpp22_gop_init(struct mvpp2_port *port)
val |= GENCONF_SOFT_RESET1_GOP;
regmap_write(priv->sysctrl_base, GENCONF_SOFT_RESET1, val);
 
+   mvpp22_gop_fca_set_periodic_timer(port);
+
 unsupported_conf:
return 0;
 
-- 
1.9.1



[PATCH v10 net-next 08/15] net: mvpp2: add FCA RXQ non occupied descriptor threshold

2021-02-08 Thread stefanc
From: Stefan Chulski 

The firmware needs to monitor the RX Non-occupied descriptor
bits for flow control to move to XOFF mode.
These bits need to be unmasked to be functional, but they will
not raise interrupts as we leave the RX exception summary
bit in MVPP2_ISR_RX_TX_MASK_REG clear.

Signed-off-by: Stefan Chulski 
---
 drivers/net/ethernet/marvell/mvpp2/mvpp2.h  |  3 ++
 drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c | 44 
 2 files changed, 40 insertions(+), 7 deletions(-)

diff --git a/drivers/net/ethernet/marvell/mvpp2/mvpp2.h 
b/drivers/net/ethernet/marvell/mvpp2/mvpp2.h
index 9239d80..d2cc513c 100644
--- a/drivers/net/ethernet/marvell/mvpp2/mvpp2.h
+++ b/drivers/net/ethernet/marvell/mvpp2/mvpp2.h
@@ -295,6 +295,8 @@
 #define MVPP2_PON_CAUSE_TXP_OCCUP_DESC_ALL_MASK0x3fc0
 #define MVPP2_PON_CAUSE_MISC_SUM_MASK  BIT(31)
 #define MVPP2_ISR_MISC_CAUSE_REG   0x55b0
+#define MVPP2_ISR_RX_ERR_CAUSE_REG(port)   (0x5520 + 4 * (port))
+#define MVPP2_ISR_RX_ERR_CAUSE_NONOCC_MASK 0x00ff
 
 /* Buffer Manager registers */
 #define MVPP2_BM_POOL_BASE_REG(pool)   (0x6000 + ((pool) * 4))
@@ -763,6 +765,7 @@
 /* MSS Flow control */
 #define FC_QUANTA  0x
 #define FC_CLK_DIVIDER 100
+#define MSS_THRESHOLD_STOP 768
 
 /* RX buffer constants */
 #define MVPP2_SKB_SHINFO_SIZE \
diff --git a/drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c 
b/drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c
index 761f745..8b4073c 100644
--- a/drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c
+++ b/drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c
@@ -1133,14 +1133,19 @@ static inline void mvpp2_qvec_interrupt_disable(struct 
mvpp2_queue_vector *qvec)
 static void mvpp2_interrupts_mask(void *arg)
 {
struct mvpp2_port *port = arg;
+   int cpu = smp_processor_id();
+   u32 thread;
 
/* If the thread isn't used, don't do anything */
-   if (smp_processor_id() > port->priv->nthreads)
+   if (cpu > port->priv->nthreads)
return;
 
-   mvpp2_thread_write(port->priv,
-  mvpp2_cpu_to_thread(port->priv, smp_processor_id()),
+   thread = mvpp2_cpu_to_thread(port->priv, cpu);
+
+   mvpp2_thread_write(port->priv, thread,
   MVPP2_ISR_RX_TX_MASK_REG(port->id), 0);
+   mvpp2_thread_write(port->priv, thread,
+  MVPP2_ISR_RX_ERR_CAUSE_REG(port->id), 0);
 }
 
 /* Unmask the current thread's Rx/Tx interrupts.
@@ -1150,20 +1155,25 @@ static void mvpp2_interrupts_mask(void *arg)
 static void mvpp2_interrupts_unmask(void *arg)
 {
struct mvpp2_port *port = arg;
-   u32 val;
+   int cpu = smp_processor_id();
+   u32 val, thread;
 
/* If the thread isn't used, don't do anything */
-   if (smp_processor_id() > port->priv->nthreads)
+   if (cpu > port->priv->nthreads)
return;
 
+   thread = mvpp2_cpu_to_thread(port->priv, cpu);
+
val = MVPP2_CAUSE_MISC_SUM_MASK |
MVPP2_CAUSE_RXQ_OCCUP_DESC_ALL_MASK(port->priv->hw_version);
if (port->has_tx_irqs)
val |= MVPP2_CAUSE_TXQ_OCCUP_DESC_ALL_MASK;
 
-   mvpp2_thread_write(port->priv,
-  mvpp2_cpu_to_thread(port->priv, smp_processor_id()),
+   mvpp2_thread_write(port->priv, thread,
   MVPP2_ISR_RX_TX_MASK_REG(port->id), val);
+   mvpp2_thread_write(port->priv, thread,
+  MVPP2_ISR_RX_ERR_CAUSE_REG(port->id),
+  MVPP2_ISR_RX_ERR_CAUSE_NONOCC_MASK);
 }
 
 static void
@@ -1188,6 +1198,9 @@ static void mvpp2_interrupts_unmask(void *arg)
 
mvpp2_thread_write(port->priv, v->sw_thread_id,
   MVPP2_ISR_RX_TX_MASK_REG(port->id), val);
+   mvpp2_thread_write(port->priv, v->sw_thread_id,
+  MVPP2_ISR_RX_ERR_CAUSE_REG(port->id),
+  MVPP2_ISR_RX_ERR_CAUSE_NONOCC_MASK);
}
 }
 
@@ -2393,6 +2406,20 @@ static void mvpp2_txp_max_tx_size_set(struct mvpp2_port 
*port)
}
 }
 
+/* Set the number of non-occupied descriptors threshold */
+static void mvpp2_set_rxq_free_tresh(struct mvpp2_port *port,
+struct mvpp2_rx_queue *rxq)
+{
+   u32 val;
+
+   mvpp2_write(port->priv, MVPP2_RXQ_NUM_REG, rxq->id);
+
+   val = mvpp2_read(port->priv, MVPP2_RXQ_THRESH_REG);
+   val &= ~MVPP2_RXQ_NON_OCCUPIED_MASK;
+   val |= MSS_THRESHOLD_STOP << MVPP2_RXQ_NON_OCCUPIED_OFFSET;
+   mvpp2_write(port->priv, MVPP2_RXQ_THRESH_REG, val);
+}
+
 /* Set the number of packets that will be received before Rx interrupt
  * will be generated by HW.
  */
@@ -2648,6 +2675,9 @@ static int mvpp2_rxq_init(struct mvpp2_port *port,
mvpp2_rx_pkts_coal_set(port, rxq);
mvpp2_rx_time_coal_set(port, rxq);
 
+   /* Set the number of

[PATCH v10 net-next 06/15] net: mvpp2: increase BM pool and RXQ size

2021-02-08 Thread stefanc
From: Stefan Chulski 

BM pool and RXQ size increased to support Firmware Flow Control.
Minimum depletion thresholds to support FC are 1024 buffers.
BM pool size increased to 2048 to have some 1024 buffers
space between depletion thresholds and BM pool size.

Jumbo frames require a 9888B buffer, so memory requirements
for data buffers increased from 7MB to 24MB.

Signed-off-by: Stefan Chulski 
---
 drivers/net/ethernet/marvell/mvpp2/mvpp2.h | 8 
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/drivers/net/ethernet/marvell/mvpp2/mvpp2.h 
b/drivers/net/ethernet/marvell/mvpp2/mvpp2.h
index ce08086..e7bbf0a 100644
--- a/drivers/net/ethernet/marvell/mvpp2/mvpp2.h
+++ b/drivers/net/ethernet/marvell/mvpp2/mvpp2.h
@@ -715,8 +715,8 @@
 #define MVPP2_PORT_MAX_RXQ 32
 
 /* Max number of Rx descriptors */
-#define MVPP2_MAX_RXD_MAX  1024
-#define MVPP2_MAX_RXD_DFLT 128
+#define MVPP2_MAX_RXD_MAX  2048
+#define MVPP2_MAX_RXD_DFLT 1024
 
 /* Max number of Tx descriptors */
 #define MVPP2_MAX_TXD_MAX  2048
@@ -848,8 +848,8 @@ enum mvpp22_ptp_packet_format {
 #define MVPP22_PTP_TIMESTAMPQUEUESELECTBIT(18)
 
 /* BM constants */
-#define MVPP2_BM_JUMBO_BUF_NUM 512
-#define MVPP2_BM_LONG_BUF_NUM  1024
+#define MVPP2_BM_JUMBO_BUF_NUM 2048
+#define MVPP2_BM_LONG_BUF_NUM  2048
 #define MVPP2_BM_SHORT_BUF_NUM 2048
 #define MVPP2_BM_POOL_SIZE_MAX (16*1024 - MVPP2_BM_POOL_PTR_ALIGN/4)
 #define MVPP2_BM_POOL_PTR_ALIGN128
-- 
1.9.1



[PATCH v10 net-next 04/15] net: mvpp2: always compare hw-version vs MVPP21

2021-02-08 Thread stefanc
From: Stefan Chulski 

Currently we have PP2v1 and PP2v2 hw-versions, with some different
handlers depending upon condition hw_version = MVPP21/MVPP22.
In a future there will be also PP2v3. Let's use now the generic
"if equal/notEqual MVPP21" for all cases instead of "if MVPP22".

This patch does not change any functionality.
It is not intended to introduce PP2v3.
It just modifies MVPP21/MVPP22 check-condition
bringing it to generic and unified form correct for new-code
introducing and PP2v3 net-next generation.

Signed-off-by: Stefan Chulski 
---
 drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c | 36 ++--
 1 file changed, 18 insertions(+), 18 deletions(-)

diff --git a/drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c 
b/drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c
index eec3796..e9c5916 100644
--- a/drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c
+++ b/drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c
@@ -319,7 +319,7 @@ static int mvpp2_get_nrxqs(struct mvpp2 *priv)
 {
unsigned int nrxqs;
 
-   if (priv->hw_version == MVPP22 && queue_mode == MVPP2_QDIST_SINGLE_MODE)
+   if (priv->hw_version != MVPP21 && queue_mode == MVPP2_QDIST_SINGLE_MODE)
return 1;
 
/* According to the PPv2.2 datasheet and our experiments on
@@ -446,7 +446,7 @@ static void mvpp2_bm_bufs_get_addrs(struct device *dev, 
struct mvpp2 *priv,
  MVPP2_BM_PHY_ALLOC_REG(bm_pool->id));
*phys_addr = mvpp2_thread_read(priv, thread, MVPP2_BM_VIRT_ALLOC_REG);
 
-   if (priv->hw_version == MVPP22) {
+   if (priv->hw_version != MVPP21) {
u32 val;
u32 dma_addr_highbits, phys_addr_highbits;
 
@@ -742,7 +742,7 @@ static inline void mvpp2_bm_pool_put(struct mvpp2_port 
*port, int pool,
if (test_bit(thread, &port->priv->lock_map))
spin_lock_irqsave(&port->bm_lock[thread], flags);
 
-   if (port->priv->hw_version == MVPP22) {
+   if (port->priv->hw_version != MVPP21) {
u32 val = 0;
 
if (sizeof(dma_addr_t) == 8)
@@ -1199,7 +1199,7 @@ static bool mvpp2_port_supports_xlg(struct mvpp2_port 
*port)
 
 static bool mvpp2_port_supports_rgmii(struct mvpp2_port *port)
 {
-   return !(port->priv->hw_version == MVPP22 && port->gop_id == 0);
+   return !(port->priv->hw_version != MVPP21 && port->gop_id == 0);
 }
 
 /* Port configuration routines */
@@ -1817,7 +1817,7 @@ static void mvpp2_mac_reset_assert(struct mvpp2_port 
*port)
  MVPP2_GMAC_PORT_RESET_MASK;
writel(val, port->base + MVPP2_GMAC_CTRL_2_REG);
 
-   if (port->priv->hw_version == MVPP22 && port->gop_id == 0) {
+   if (port->priv->hw_version != MVPP21 && port->gop_id == 0) {
val = readl(port->base + MVPP22_XLG_CTRL0_REG) &
  ~MVPP22_XLG_CTRL0_MAC_RESET_DIS;
writel(val, port->base + MVPP22_XLG_CTRL0_REG);
@@ -1830,7 +1830,7 @@ static void mvpp22_pcs_reset_assert(struct mvpp2_port 
*port)
void __iomem *mpcs, *xpcs;
u32 val;
 
-   if (port->priv->hw_version != MVPP22 || port->gop_id != 0)
+   if (port->priv->hw_version == MVPP21 || port->gop_id != 0)
return;
 
mpcs = priv->iface_base + MVPP22_MPCS_BASE(port->gop_id);
@@ -1851,7 +1851,7 @@ static void mvpp22_pcs_reset_deassert(struct mvpp2_port 
*port)
void __iomem *mpcs, *xpcs;
u32 val;
 
-   if (port->priv->hw_version != MVPP22 || port->gop_id != 0)
+   if (port->priv->hw_version == MVPP21 || port->gop_id != 0)
return;
 
mpcs = priv->iface_base + MVPP22_MPCS_BASE(port->gop_id);
@@ -4188,7 +4188,7 @@ static void mvpp2_start_dev(struct mvpp2_port *port)
/* Enable interrupts on all threads */
mvpp2_interrupts_enable(port);
 
-   if (port->priv->hw_version == MVPP22)
+   if (port->priv->hw_version != MVPP21)
mvpp22_mode_reconfigure(port);
 
if (port->phylink) {
@@ -4404,7 +4404,7 @@ static int mvpp2_open(struct net_device *dev)
valid = true;
}
 
-   if (priv->hw_version == MVPP22 && port->port_irq) {
+   if (priv->hw_version != MVPP21 && port->port_irq) {
err = request_irq(port->port_irq, mvpp2_port_isr, 0,
  dev->name, port);
if (err) {
@@ -6052,7 +6052,7 @@ static int mvpp2__mac_prepare(struct phylink_config 
*config, unsigned int mode,
 MVPP2_GMAC_PORT_RESET_MASK,
 MVPP2_GMAC_PORT_RESET_MASK);
 
-   if (port->priv->hw_version == MVPP22) {
+   if (port->priv->hw_version != MVPP21) {
mvpp22_gop_mask_irq(port);
 
phy_power_off(port->comphy);
@@ -6106,7 +6106,7 @@ static int mvpp2_mac_finish(struct phylink_config 
*config, unsigned int mode,
 {
struct mvpp2_port *port = mvpp2_phylink_to_port(config);
 
-

[PATCH v10 net-next 05/15] net: mvpp2: add PPv23 version definition

2021-02-08 Thread stefanc
From: Stefan Chulski 

This patch add PPv23 version definition.
PPv23 is new packet processor in CP115.
Everything that supported by PPv22, also supported by PPv23.
No functional changes in this stage.

Signed-off-by: Stefan Chulski 
---
 drivers/net/ethernet/marvell/mvpp2/mvpp2.h  | 24 
 drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c | 17 +-
 2 files changed, 25 insertions(+), 16 deletions(-)

diff --git a/drivers/net/ethernet/marvell/mvpp2/mvpp2.h 
b/drivers/net/ethernet/marvell/mvpp2/mvpp2.h
index 56e90ab..ce08086 100644
--- a/drivers/net/ethernet/marvell/mvpp2/mvpp2.h
+++ b/drivers/net/ethernet/marvell/mvpp2/mvpp2.h
@@ -60,6 +60,9 @@
 /* Top Registers */
 #define MVPP2_MH_REG(port) (0x5040 + 4 * (port))
 #define MVPP2_DSA_EXTENDED BIT(5)
+#define MVPP2_VER_ID_REG   0x50b0
+#define MVPP2_VER_PP22 0x10
+#define MVPP2_VER_PP23 0x11
 
 /* Parser Registers */
 #define MVPP2_PRS_INIT_LOOKUP_REG  0x1000
@@ -469,7 +472,7 @@
 #define MVPP22_GMAC_INT_SUM_MASK_LINK_STAT BIT(1)
 #defineMVPP22_GMAC_INT_SUM_MASK_PTPBIT(2)
 
-/* Per-port XGMAC registers. PPv2.2 only, only for GOP port 0,
+/* Per-port XGMAC registers. PPv2.2 and PPv2.3, only for GOP port 0,
  * relative to port->base.
  */
 #define MVPP22_XLG_CTRL0_REG   0x100
@@ -506,7 +509,7 @@
 #define MVPP22_XLG_CTRL4_MACMODSELECT_GMAC BIT(12)
 #define MVPP22_XLG_CTRL4_EN_IDLE_CHECK BIT(14)
 
-/* SMI registers. PPv2.2 only, relative to priv->iface_base. */
+/* SMI registers. PPv2.2 and PPv2.3, relative to priv->iface_base. */
 #define MVPP22_SMI_MISC_CFG_REG0x1204
 #define MVPP22_SMI_POLLING_EN  BIT(10)
 
@@ -582,7 +585,7 @@
 #define MVPP2_QUEUE_NEXT_DESC(q, index) \
(((index) < (q)->last_desc) ? ((index) + 1) : 0)
 
-/* XPCS registers. PPv2.2 only */
+/* XPCS registers.PPv2.2 and PPv2.3 */
 #define MVPP22_MPCS_BASE(port) (0x7000 + (port) * 0x1000)
 #define MVPP22_MPCS_CTRL   0x14
 #define MVPP22_MPCS_CTRL_FWD_ERR_CONN  BIT(10)
@@ -593,7 +596,7 @@
 #define MVPP22_MPCS_CLK_RESET_DIV_RATIO(n) ((n) << 4)
 #define MVPP22_MPCS_CLK_RESET_DIV_SET  BIT(11)
 
-/* XPCS registers. PPv2.2 only */
+/* XPCS registers. PPv2.2 and PPv2.3 */
 #define MVPP22_XPCS_BASE(port) (0x7400 + (port) * 0x1000)
 #define MVPP22_XPCS_CFG0   0x0
 #define MVPP22_XPCS_CFG0_RESET_DIS BIT(0)
@@ -927,15 +930,16 @@ struct mvpp2 {
void __iomem *iface_base;
void __iomem *cm3_base;
 
-   /* On PPv2.2, each "software thread" can access the base
+   /* On PPv2.2 and PPv2.3, each "software thread" can access the base
 * register through a separate address space, each 64 KB apart
 * from each other. Typically, such address spaces will be
 * used per CPU.
 */
void __iomem *swth_base[MVPP2_MAX_THREADS];
 
-   /* On PPv2.2, some port control registers are located into the system
-* controller space. These registers are accessible through a regmap.
+   /* On PPv2.2 and PPv2.3, some port control registers are located into
+* the system controller space. These registers are accessible
+* through a regmap.
 */
struct regmap *sysctrl_base;
 
@@ -977,7 +981,7 @@ struct mvpp2 {
u32 tclk;
 
/* HW version */
-   enum { MVPP21, MVPP22 } hw_version;
+   enum { MVPP21, MVPP22, MVPP23 } hw_version;
 
/* Maximum number of RXQs per port */
unsigned int max_port_rxqs;
@@ -1221,7 +1225,7 @@ struct mvpp21_rx_desc {
__le32 reserved8;
 };
 
-/* HW TX descriptor for PPv2.2 */
+/* HW TX descriptor for PPv2.2 and PPv2.3 */
 struct mvpp22_tx_desc {
__le32 command;
u8  packet_offset;
@@ -1233,7 +1237,7 @@ struct mvpp22_tx_desc {
__le64 buf_cookie_misc;
 };
 
-/* HW RX descriptor for PPv2.2 */
+/* HW RX descriptor for PPv2.2 and PPv2.3 */
 struct mvpp22_rx_desc {
__le32 status;
__le16 reserved1;
diff --git a/drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c 
b/drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c
index e9c5916..5730900 100644
--- a/drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c
+++ b/drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c
@@ -384,7 +384,7 @@ static int mvpp2_bm_pool_create(struct device *dev, struct 
mvpp2 *priv,
if (!IS_ALIGNED(size, 16))
return -EINVAL;
 
-   /* PPv2.1 needs 8 bytes per buffer pointer, PPv2.2 needs 16
+   /* PPv2.1 needs 8 bytes per buffer pointer, PPv2.2 and PPv2.3 needs 16
 * bytes per buffer pointer
 */
if (priv->hw_version == MVPP21)
@@ -1172,7 +1172,7 @@ static void mvpp2_interrupts_unmask(void *arg)
u32 val;
int i;
 
-   if (port->priv->hw_version != MVPP22)
+   if

[PATCH v10 net-next 02/15] dts: marvell: add CM3 SRAM memory to cp11x ethernet device tree

2021-02-08 Thread stefanc
From: Konstantin Porotchkin 

CM3 SRAM address space would be used for Flow Control configuration.

Signed-off-by: Stefan Chulski 
Signed-off-by: Konstantin Porotchkin 
---
 arch/arm64/boot/dts/marvell/armada-cp11x.dtsi | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/arm64/boot/dts/marvell/armada-cp11x.dtsi 
b/arch/arm64/boot/dts/marvell/armada-cp11x.dtsi
index 9dcf16b..6fe0d26 100644
--- a/arch/arm64/boot/dts/marvell/armada-cp11x.dtsi
+++ b/arch/arm64/boot/dts/marvell/armada-cp11x.dtsi
@@ -59,7 +59,7 @@
 
CP11X_LABEL(ethernet): ethernet@0 {
compatible = "marvell,armada-7k-pp22";
-   reg = <0x0 0x10>, <0x129000 0xb000>;
+   reg = <0x0 0x10>, <0x129000 0xb000>, <0x22 
0x800>;
clocks = <&CP11X_LABEL(clk) 1 3>, <&CP11X_LABEL(clk) 1 
9>,
 <&CP11X_LABEL(clk) 1 5>, <&CP11X_LABEL(clk) 1 
6>,
 <&CP11X_LABEL(clk) 1 18>;
-- 
1.9.1



[PATCH v10 net-next 03/15] net: mvpp2: add CM3 SRAM memory map

2021-02-08 Thread stefanc
From: Stefan Chulski 

This patch adds CM3 memory map and CM3 read/write callbacks.

Signed-off-by: Stefan Chulski 
Reviewed-by: Andrew Lunn 
---
 drivers/net/ethernet/marvell/mvpp2/mvpp2.h  |  1 +
 drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c | 26 
 2 files changed, 27 insertions(+)

diff --git a/drivers/net/ethernet/marvell/mvpp2/mvpp2.h 
b/drivers/net/ethernet/marvell/mvpp2/mvpp2.h
index 6bd7e40..56e90ab 100644
--- a/drivers/net/ethernet/marvell/mvpp2/mvpp2.h
+++ b/drivers/net/ethernet/marvell/mvpp2/mvpp2.h
@@ -925,6 +925,7 @@ struct mvpp2 {
/* Shared registers' base addresses */
void __iomem *lms_base;
void __iomem *iface_base;
+   void __iomem *cm3_base;
 
/* On PPv2.2, each "software thread" can access the base
 * register through a separate address space, each 64 KB apart
diff --git a/drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c 
b/drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c
index a07cf60..eec3796 100644
--- a/drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c
+++ b/drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c
@@ -6846,6 +6846,27 @@ static int mvpp2_init(struct platform_device *pdev, 
struct mvpp2 *priv)
return 0;
 }
 
+static int mvpp2_get_sram(struct platform_device *pdev,
+ struct mvpp2 *priv)
+{
+   struct resource *res;
+
+   res = platform_get_resource(pdev, IORESOURCE_MEM, 2);
+   if (!res) {
+   if (has_acpi_companion(&pdev->dev))
+   dev_warn(&pdev->dev, "ACPI is too old, Flow control not 
supported\n");
+   else
+   dev_warn(&pdev->dev, "DT is too old, Flow control not 
supported\n");
+   return 0;
+   }
+
+   priv->cm3_base = devm_ioremap_resource(&pdev->dev, res);
+   if (IS_ERR(priv->cm3_base))
+   return PTR_ERR(priv->cm3_base);
+
+   return 0;
+}
+
 static int mvpp2_probe(struct platform_device *pdev)
 {
const struct acpi_device_id *acpi_id;
@@ -6902,6 +6923,11 @@ static int mvpp2_probe(struct platform_device *pdev)
priv->iface_base = devm_ioremap_resource(&pdev->dev, res);
if (IS_ERR(priv->iface_base))
return PTR_ERR(priv->iface_base);
+
+   /* Map CM3 SRAM */
+   err = mvpp2_get_sram(pdev, priv);
+   if (err)
+   dev_warn(&pdev->dev, "Fail to alloc CM3 SRAM\n");
}
 
if (priv->hw_version == MVPP22 && dev_of_node(&pdev->dev)) {
-- 
1.9.1



[PATCH v10 net-next 01/15] doc: marvell: add CM3 address space and PPv2.3 description

2021-02-08 Thread stefanc
From: Stefan Chulski 

Patch adds CM3 address space and PPv2.3 description.

Signed-off-by: Stefan Chulski 
---
 Documentation/devicetree/bindings/net/marvell-pp2.txt | 6 --
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/Documentation/devicetree/bindings/net/marvell-pp2.txt 
b/Documentation/devicetree/bindings/net/marvell-pp2.txt
index b783976..ce15c17 100644
--- a/Documentation/devicetree/bindings/net/marvell-pp2.txt
+++ b/Documentation/devicetree/bindings/net/marvell-pp2.txt
@@ -1,5 +1,6 @@
 * Marvell Armada 375 Ethernet Controller (PPv2.1)
   Marvell Armada 7K/8K Ethernet Controller (PPv2.2)
+  Marvell CN913X Ethernet Controller (PPv2.3)
 
 Required properties:
 
@@ -12,10 +13,11 @@ Required properties:
- common controller registers
- LMS registers
- one register area per Ethernet port
-  For "marvell,armada-7k-pp2", must contain the following register
+  For "marvell,armada-7k-pp2" used by 7K/8K and CN913X, must contain the 
following register
   sets:
- packet processor registers
- networking interfaces registers
+   - CM3 address space used for TX Flow Control
 
 - clocks: pointers to the reference clocks for this device, consequently:
- main controller clock (for both armada-375-pp2 and armada-7k-pp2)
@@ -81,7 +83,7 @@ Example for marvell,armada-7k-pp2:
 
 cpm_ethernet: ethernet@0 {
compatible = "marvell,armada-7k-pp22";
-   reg = <0x0 0x10>, <0x129000 0xb000>;
+   reg = <0x0 0x10>, <0x129000 0xb000>, <0x22 0x800>;
clocks = <&cpm_syscon0 1 3>, <&cpm_syscon0 1 9>,
 <&cpm_syscon0 1 5>, <&cpm_syscon0 1 6>, <&cpm_syscon0 1 18>;
clock-names = "pp_clk", "gop_clk", "mg_clk", "mg_core_clk", "axi_clk";
-- 
1.9.1



[PATCH v10 net-next 00/15] net: mvpp2: Add TX Flow Control support

2021-02-08 Thread stefanc
From: Stefan Chulski 

Armada hardware has a pause generation mechanism in GOP (MAC).
The GOP generate flow control frames based on an indication programmed in Ports 
Control 0 Register. There is a bit per port.
However assertion of the PortX Pause bits in the ports control 0 register only 
sends a one time pause.
To complement the function the GOP has a mechanism to periodically send pause 
control messages based on periodic counters.
This mechanism ensures that the pause is effective as long as the Appropriate 
PortX Pause is asserted.

Problem is that Packet Processor that actually can drop packets due to lack of 
resources not connected to the GOP flow control generation mechanism.
To solve this issue Armada has firmware running on CM3 CPU dedicated for Flow 
Control support.
Firmware monitors Packet Processor resources and asserts XON/XOFF by writing to 
Ports Control 0 Register.

MSS shared SRAM memory used to communicate between CM3 firmware and PP2 driver.
During init PP2 driver informs firmware about used BM pools, RXQs, congestion 
and depletion thresholds.

The pause frames are generated whenever congestion or depletion in resources is 
detected.
The back pressure is stopped when the resource reaches a sufficient level.
So the congestion/depletion and sufficient level implement a hysteresis that 
reduces the XON/XOFF toggle frequency.

Packet Processor v23 hardware introduces support for RX FIFO fill level monitor.
Patch "add PPv23 version definition" to differ between v23 and v22 hardware.
Patch "add TX FC firmware check" verifies that CM3 firmware supports Flow 
Control monitoring.

v9 --> v10
- Add CM3 SRAM description to PPv2 documentation

v8 --> v9
- Replace generic pool allocation with devm_ioremap_resource

v7 --> v8
- Reorder "always compare hw-version vs MVPP21" and "add PPv23 version 
definition" commits
- Typo fixes
- Remove condition fix from "add RXQ flow control configurations"

v6 --> v7
- Reduce patch set from 18 to 15 patches
 - Documentation change combined into a single patch
 - RXQ and BM size change combined into a single patch
 - Ring size change check moved into "add RXQ flow control configurations" 
commit

v5 --> v6
- No change

v4 --> v5
- Add missed Signed-off
- Fix warnings in patches 3 and 12
- Add revision requirement to warning message
- Move mss_spinlock into RXQ flow control configurations patch
- Improve FCA RXQ non occupied descriptor threshold commit message

v3 --> v4
- Remove RFC tag

v2 --> v3
- Remove inline functions
- Add PPv2.3 description into marvell-pp2.txt
- Improve mvpp2_interrupts_mask/unmask procedure
- Improve FC enable/disable procedure
- Add priv->sram_pool check
- Remove gen_pool_destroy call
- Reduce Flow Control timer to x100 faster

v1 --> v2
- Add memory requirements information
- Add EPROBE_DEFER if of_gen_pool_get return NULL
- Move Flow control configuration to mvpp2_mac_link_up callback
- Add firmware version info with Flow control support

Konstantin Porotchkin (1):
  dts: marvell: add CM3 SRAM memory to cp11x ethernet device tree

Stefan Chulski (14):
  doc: marvell: add CM3 address space and PPv2.3 description
  net: mvpp2: add CM3 SRAM memory map
  net: mvpp2: always compare hw-version vs MVPP21
  net: mvpp2: add PPv23 version definition
  net: mvpp2: increase BM pool and RXQ size
  net: mvpp2: add FCA periodic timer configurations
  net: mvpp2: add FCA RXQ non occupied descriptor threshold
  net: mvpp2: enable global flow control
  net: mvpp2: add RXQ flow control configurations
  net: mvpp2: add ethtool flow control configuration support
  net: mvpp2: add BM protection underrun feature support
  net: mvpp2: add PPv23 RX FIFO flow control
  net: mvpp2: set 802.3x GoP Flow Control mode
  net: mvpp2: add TX FC firmware check

 Documentation/devicetree/bindings/net/marvell-pp2.txt |   6 +-
 arch/arm64/boot/dts/marvell/armada-cp11x.dtsi |   2 +-
 drivers/net/ethernet/marvell/mvpp2/mvpp2.h| 124 -
 drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c   | 526 
++--
 4 files changed, 609 insertions(+), 49 deletions(-)

-- 
1.9.1



[PATCH v9 net-next 15/15] net: mvpp2: add TX FC firmware check

2021-02-07 Thread stefanc
From: Stefan Chulski 

Patch check that TX FC firmware is running in CM3.
If not, global TX FC would be disabled.

Signed-off-by: Stefan Chulski 
---
 drivers/net/ethernet/marvell/mvpp2/mvpp2.h  |  1 +
 drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c | 42 
 2 files changed, 36 insertions(+), 7 deletions(-)

diff --git a/drivers/net/ethernet/marvell/mvpp2/mvpp2.h 
b/drivers/net/ethernet/marvell/mvpp2/mvpp2.h
index b61a1ba..da87152 100644
--- a/drivers/net/ethernet/marvell/mvpp2/mvpp2.h
+++ b/drivers/net/ethernet/marvell/mvpp2/mvpp2.h
@@ -828,6 +828,7 @@
 
 #define MSS_THRESHOLD_STOP 768
 #define MSS_THRESHOLD_START1024
+#define MSS_FC_MAX_TIMEOUT 5000
 
 /* RX buffer constants */
 #define MVPP2_SKB_SHINFO_SIZE \
diff --git a/drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c 
b/drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c
index 4d0a398..fed4521 100644
--- a/drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c
+++ b/drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c
@@ -931,6 +931,34 @@ static void mvpp2_bm_pool_update_fc(struct mvpp2_port 
*port,
spin_unlock_irqrestore(&port->priv->mss_spinlock, flags);
 }
 
+static int mvpp2_enable_global_fc(struct mvpp2 *priv)
+{
+   int val, timeout = 0;
+
+   /* Enable global flow control. In this stage global
+* flow control enabled, but still disabled per port.
+*/
+   val = mvpp2_cm3_read(priv, MSS_FC_COM_REG);
+   val |= FLOW_CONTROL_ENABLE_BIT;
+   mvpp2_cm3_write(priv, MSS_FC_COM_REG, val);
+
+   /* Check if Firmware running and disable FC if not*/
+   val |= FLOW_CONTROL_UPDATE_COMMAND_BIT;
+   mvpp2_cm3_write(priv, MSS_FC_COM_REG, val);
+
+   while (timeout < MSS_FC_MAX_TIMEOUT) {
+   val = mvpp2_cm3_read(priv, MSS_FC_COM_REG);
+
+   if (!(val & FLOW_CONTROL_UPDATE_COMMAND_BIT))
+   return 0;
+   usleep_range(10, 20);
+   timeout++;
+   }
+
+   priv->global_tx_fc = false;
+   return -EOPNOTSUPP;
+}
+
 /* Release buffer to BM */
 static inline void mvpp2_bm_pool_put(struct mvpp2_port *port, int pool,
 dma_addr_t buf_dma_addr,
@@ -7263,7 +7291,7 @@ static int mvpp2_probe(struct platform_device *pdev)
struct resource *res;
void __iomem *base;
int i, shared;
-   int err, val;
+   int err;
 
priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL);
if (!priv)
@@ -7487,13 +7515,13 @@ static int mvpp2_probe(struct platform_device *pdev)
goto err_port_probe;
}
 
-   /* Enable global flow control. In this stage global
-* flow control enabled, but still disabled per port.
-*/
if (priv->global_tx_fc && priv->hw_version != MVPP21) {
-   val = mvpp2_cm3_read(priv, MSS_FC_COM_REG);
-   val |= FLOW_CONTROL_ENABLE_BIT;
-   mvpp2_cm3_write(priv, MSS_FC_COM_REG, val);
+   err = mvpp2_enable_global_fc(priv);
+   if (err) {
+   dev_warn(&pdev->dev, "CM3 firmware not running, version 
should be higher than 18.09 ");
+   dev_warn(&pdev->dev, "and chip revision B0\n");
+   dev_warn(&pdev->dev, "Flow control not supported\n");
+   }
}
 
mvpp2_dbgfs_init(priv, pdev->name);
-- 
1.9.1



[PATCH v9 net-next 05/15] net: mvpp2: add PPv23 version definition

2021-02-07 Thread stefanc
From: Stefan Chulski 

This patch add PPv23 version definition.
PPv23 is new packet processor in CP115.
Everything that supported by PPv22, also supported by PPv23.
No functional changes in this stage.

Signed-off-by: Stefan Chulski 
---
 drivers/net/ethernet/marvell/mvpp2/mvpp2.h  | 24 
 drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c | 17 +-
 2 files changed, 25 insertions(+), 16 deletions(-)

diff --git a/drivers/net/ethernet/marvell/mvpp2/mvpp2.h 
b/drivers/net/ethernet/marvell/mvpp2/mvpp2.h
index 56e90ab..ce08086 100644
--- a/drivers/net/ethernet/marvell/mvpp2/mvpp2.h
+++ b/drivers/net/ethernet/marvell/mvpp2/mvpp2.h
@@ -60,6 +60,9 @@
 /* Top Registers */
 #define MVPP2_MH_REG(port) (0x5040 + 4 * (port))
 #define MVPP2_DSA_EXTENDED BIT(5)
+#define MVPP2_VER_ID_REG   0x50b0
+#define MVPP2_VER_PP22 0x10
+#define MVPP2_VER_PP23 0x11
 
 /* Parser Registers */
 #define MVPP2_PRS_INIT_LOOKUP_REG  0x1000
@@ -469,7 +472,7 @@
 #define MVPP22_GMAC_INT_SUM_MASK_LINK_STAT BIT(1)
 #defineMVPP22_GMAC_INT_SUM_MASK_PTPBIT(2)
 
-/* Per-port XGMAC registers. PPv2.2 only, only for GOP port 0,
+/* Per-port XGMAC registers. PPv2.2 and PPv2.3, only for GOP port 0,
  * relative to port->base.
  */
 #define MVPP22_XLG_CTRL0_REG   0x100
@@ -506,7 +509,7 @@
 #define MVPP22_XLG_CTRL4_MACMODSELECT_GMAC BIT(12)
 #define MVPP22_XLG_CTRL4_EN_IDLE_CHECK BIT(14)
 
-/* SMI registers. PPv2.2 only, relative to priv->iface_base. */
+/* SMI registers. PPv2.2 and PPv2.3, relative to priv->iface_base. */
 #define MVPP22_SMI_MISC_CFG_REG0x1204
 #define MVPP22_SMI_POLLING_EN  BIT(10)
 
@@ -582,7 +585,7 @@
 #define MVPP2_QUEUE_NEXT_DESC(q, index) \
(((index) < (q)->last_desc) ? ((index) + 1) : 0)
 
-/* XPCS registers. PPv2.2 only */
+/* XPCS registers.PPv2.2 and PPv2.3 */
 #define MVPP22_MPCS_BASE(port) (0x7000 + (port) * 0x1000)
 #define MVPP22_MPCS_CTRL   0x14
 #define MVPP22_MPCS_CTRL_FWD_ERR_CONN  BIT(10)
@@ -593,7 +596,7 @@
 #define MVPP22_MPCS_CLK_RESET_DIV_RATIO(n) ((n) << 4)
 #define MVPP22_MPCS_CLK_RESET_DIV_SET  BIT(11)
 
-/* XPCS registers. PPv2.2 only */
+/* XPCS registers. PPv2.2 and PPv2.3 */
 #define MVPP22_XPCS_BASE(port) (0x7400 + (port) * 0x1000)
 #define MVPP22_XPCS_CFG0   0x0
 #define MVPP22_XPCS_CFG0_RESET_DIS BIT(0)
@@ -927,15 +930,16 @@ struct mvpp2 {
void __iomem *iface_base;
void __iomem *cm3_base;
 
-   /* On PPv2.2, each "software thread" can access the base
+   /* On PPv2.2 and PPv2.3, each "software thread" can access the base
 * register through a separate address space, each 64 KB apart
 * from each other. Typically, such address spaces will be
 * used per CPU.
 */
void __iomem *swth_base[MVPP2_MAX_THREADS];
 
-   /* On PPv2.2, some port control registers are located into the system
-* controller space. These registers are accessible through a regmap.
+   /* On PPv2.2 and PPv2.3, some port control registers are located into
+* the system controller space. These registers are accessible
+* through a regmap.
 */
struct regmap *sysctrl_base;
 
@@ -977,7 +981,7 @@ struct mvpp2 {
u32 tclk;
 
/* HW version */
-   enum { MVPP21, MVPP22 } hw_version;
+   enum { MVPP21, MVPP22, MVPP23 } hw_version;
 
/* Maximum number of RXQs per port */
unsigned int max_port_rxqs;
@@ -1221,7 +1225,7 @@ struct mvpp21_rx_desc {
__le32 reserved8;
 };
 
-/* HW TX descriptor for PPv2.2 */
+/* HW TX descriptor for PPv2.2 and PPv2.3 */
 struct mvpp22_tx_desc {
__le32 command;
u8  packet_offset;
@@ -1233,7 +1237,7 @@ struct mvpp22_tx_desc {
__le64 buf_cookie_misc;
 };
 
-/* HW RX descriptor for PPv2.2 */
+/* HW RX descriptor for PPv2.2 and PPv2.3 */
 struct mvpp22_rx_desc {
__le32 status;
__le16 reserved1;
diff --git a/drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c 
b/drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c
index e9c5916..5730900 100644
--- a/drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c
+++ b/drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c
@@ -384,7 +384,7 @@ static int mvpp2_bm_pool_create(struct device *dev, struct 
mvpp2 *priv,
if (!IS_ALIGNED(size, 16))
return -EINVAL;
 
-   /* PPv2.1 needs 8 bytes per buffer pointer, PPv2.2 needs 16
+   /* PPv2.1 needs 8 bytes per buffer pointer, PPv2.2 and PPv2.3 needs 16
 * bytes per buffer pointer
 */
if (priv->hw_version == MVPP21)
@@ -1172,7 +1172,7 @@ static void mvpp2_interrupts_unmask(void *arg)
u32 val;
int i;
 
-   if (port->priv->hw_version != MVPP22)
+   if

[PATCH v9 net-next 14/15] net: mvpp2: set 802.3x GoP Flow Control mode

2021-02-07 Thread stefanc
From: Stefan Chulski 

This patch fix GMAC TX flow control autoneg.
Flow control autoneg wrongly were disabled with enabled TX
flow control.

Signed-off-by: Stefan Chulski 
---
 drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c 
b/drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c
index a472125..4d0a398 100644
--- a/drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c
+++ b/drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c
@@ -6283,7 +6283,7 @@ static void mvpp2_gmac_config(struct mvpp2_port *port, 
unsigned int mode,
old_ctrl4 = ctrl4 = readl(port->base + MVPP22_GMAC_CTRL_4_REG);
 
ctrl0 &= ~MVPP2_GMAC_PORT_TYPE_MASK;
-   ctrl2 &= ~(MVPP2_GMAC_INBAND_AN_MASK | MVPP2_GMAC_PCS_ENABLE_MASK);
+   ctrl2 &= ~(MVPP2_GMAC_INBAND_AN_MASK | MVPP2_GMAC_PCS_ENABLE_MASK | 
MVPP2_GMAC_FLOW_CTRL_MASK);
 
/* Configure port type */
if (phy_interface_mode_is_8023z(state->interface)) {
-- 
1.9.1



[PATCH v9 net-next 11/15] net: mvpp2: add ethtool flow control configuration support

2021-02-07 Thread stefanc
From: Stefan Chulski 

This patch add ethtool flow control configuration support.

Tx flow control retrieved correctly by ethtool get function.
FW per port ethtool configuration capability added.

Patch also takes care about mtu change procedure, if PPv2 switch
BM pools during mtu change.

Signed-off-by: Stefan Chulski 
---
 drivers/net/ethernet/marvell/mvpp2/mvpp2.h  | 13 +++
 drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c | 98 
 2 files changed, 111 insertions(+)

diff --git a/drivers/net/ethernet/marvell/mvpp2/mvpp2.h 
b/drivers/net/ethernet/marvell/mvpp2/mvpp2.h
index 0010a3e9..0731dc7 100644
--- a/drivers/net/ethernet/marvell/mvpp2/mvpp2.h
+++ b/drivers/net/ethernet/marvell/mvpp2/mvpp2.h
@@ -774,6 +774,19 @@
 #define MSS_RXQ_TRESH_REG(q, fq)   (MSS_RXQ_TRESH_BASE + (((q) + (fq)) \
* MSS_RXQ_TRESH_OFFS))
 
+#define MSS_BUF_POOL_BASE  0x40
+#define MSS_BUF_POOL_OFFS  4
+#define MSS_BUF_POOL_REG(id)   (MSS_BUF_POOL_BASE  \
+   + (id) * MSS_BUF_POOL_OFFS)
+
+#define MSS_BUF_POOL_STOP_MASK 0xFFF
+#define MSS_BUF_POOL_START_MASK(0xFFF << 
MSS_BUF_POOL_START_OFFS)
+#define MSS_BUF_POOL_START_OFFS12
+#define MSS_BUF_POOL_PORTS_MASK(0xF << MSS_BUF_POOL_PORTS_OFFS)
+#define MSS_BUF_POOL_PORTS_OFFS24
+#define MSS_BUF_POOL_PORT_OFFS(id) (0x1 << \
+   ((id) + MSS_BUF_POOL_PORTS_OFFS))
+
 #define MSS_RXQ_TRESH_START_MASK   0x
 #define MSS_RXQ_TRESH_STOP_MASK(0x << 
MSS_RXQ_TRESH_STOP_OFFS)
 #define MSS_RXQ_TRESH_STOP_OFFS16
diff --git a/drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c 
b/drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c
index f1770e5..90c9265 100644
--- a/drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c
+++ b/drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c
@@ -845,6 +845,59 @@ static void mvpp2_rxq_disable_fc(struct mvpp2_port *port)
spin_unlock_irqrestore(&port->priv->mss_spinlock, flags);
 }
 
+/* Routine disable/enable flow control for BM pool condition */
+static void mvpp2_bm_pool_update_fc(struct mvpp2_port *port,
+   struct mvpp2_bm_pool *pool,
+   bool en)
+{
+   int val, cm3_state;
+   unsigned long flags;
+
+   spin_lock_irqsave(&port->priv->mss_spinlock, flags);
+
+   /* Remove Flow control enable bit to prevent race between FW and Kernel
+* If Flow control were enabled, it would be re-enabled.
+*/
+   val = mvpp2_cm3_read(port->priv, MSS_FC_COM_REG);
+   cm3_state = (val & FLOW_CONTROL_ENABLE_BIT);
+   val &= ~FLOW_CONTROL_ENABLE_BIT;
+   mvpp2_cm3_write(port->priv, MSS_FC_COM_REG, val);
+
+   /* Check if BM pool should be enabled/disable */
+   if (en) {
+   /* Set BM pool start and stop thresholds per port */
+   val = mvpp2_cm3_read(port->priv, MSS_BUF_POOL_REG(pool->id));
+   val |= MSS_BUF_POOL_PORT_OFFS(port->id);
+   val &= ~MSS_BUF_POOL_START_MASK;
+   val |= (MSS_THRESHOLD_START << MSS_BUF_POOL_START_OFFS);
+   val &= ~MSS_BUF_POOL_STOP_MASK;
+   val |= MSS_THRESHOLD_STOP;
+   mvpp2_cm3_write(port->priv, MSS_BUF_POOL_REG(pool->id), val);
+   } else {
+   /* Remove BM pool from the port */
+   val = mvpp2_cm3_read(port->priv, MSS_BUF_POOL_REG(pool->id));
+   val &= ~MSS_BUF_POOL_PORT_OFFS(port->id);
+
+   /* Zero BM pool start and stop thresholds to disable pool
+* flow control if pool empty (not used by any port)
+*/
+   if (!pool->buf_num) {
+   val &= ~MSS_BUF_POOL_START_MASK;
+   val &= ~MSS_BUF_POOL_STOP_MASK;
+   }
+
+   mvpp2_cm3_write(port->priv, MSS_BUF_POOL_REG(pool->id), val);
+   }
+
+   /* Notify Firmware that Flow control config space ready for update */
+   val = mvpp2_cm3_read(port->priv, MSS_FC_COM_REG);
+   val |= FLOW_CONTROL_UPDATE_COMMAND_BIT;
+   val |= cm3_state;
+   mvpp2_cm3_write(port->priv, MSS_FC_COM_REG, val);
+
+   spin_unlock_irqrestore(&port->priv->mss_spinlock, flags);
+}
+
 /* Release buffer to BM */
 static inline void mvpp2_bm_pool_put(struct mvpp2_port *port, int pool,
 dma_addr_t buf_dma_addr,
@@ -1175,6 +1228,16 @@ static int mvpp2_bm_update_mtu(struct net_device *dev, 
int mtu)
new_long_pool = MVPP2_BM_LONG;
 
if (new_long_pool != port->pool_long->id) {
+   if (port->tx_fc) {
+   if (pkt_size > MVPP2_BM_LONG_PKT_SIZE)
+   mvpp2_bm_pool_update_fc(port,
+   

[PATCH v9 net-next 08/15] net: mvpp2: add FCA RXQ non occupied descriptor threshold

2021-02-07 Thread stefanc
From: Stefan Chulski 

The firmware needs to monitor the RX Non-occupied descriptor
bits for flow control to move to XOFF mode.
These bits need to be unmasked to be functional, but they will
not raise interrupts as we leave the RX exception summary
bit in MVPP2_ISR_RX_TX_MASK_REG clear.

Signed-off-by: Stefan Chulski 
---
 drivers/net/ethernet/marvell/mvpp2/mvpp2.h  |  3 ++
 drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c | 44 
 2 files changed, 40 insertions(+), 7 deletions(-)

diff --git a/drivers/net/ethernet/marvell/mvpp2/mvpp2.h 
b/drivers/net/ethernet/marvell/mvpp2/mvpp2.h
index 9239d80..d2cc513c 100644
--- a/drivers/net/ethernet/marvell/mvpp2/mvpp2.h
+++ b/drivers/net/ethernet/marvell/mvpp2/mvpp2.h
@@ -295,6 +295,8 @@
 #define MVPP2_PON_CAUSE_TXP_OCCUP_DESC_ALL_MASK0x3fc0
 #define MVPP2_PON_CAUSE_MISC_SUM_MASK  BIT(31)
 #define MVPP2_ISR_MISC_CAUSE_REG   0x55b0
+#define MVPP2_ISR_RX_ERR_CAUSE_REG(port)   (0x5520 + 4 * (port))
+#define MVPP2_ISR_RX_ERR_CAUSE_NONOCC_MASK 0x00ff
 
 /* Buffer Manager registers */
 #define MVPP2_BM_POOL_BASE_REG(pool)   (0x6000 + ((pool) * 4))
@@ -763,6 +765,7 @@
 /* MSS Flow control */
 #define FC_QUANTA  0x
 #define FC_CLK_DIVIDER 100
+#define MSS_THRESHOLD_STOP 768
 
 /* RX buffer constants */
 #define MVPP2_SKB_SHINFO_SIZE \
diff --git a/drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c 
b/drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c
index 761f745..8b4073c 100644
--- a/drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c
+++ b/drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c
@@ -1133,14 +1133,19 @@ static inline void mvpp2_qvec_interrupt_disable(struct 
mvpp2_queue_vector *qvec)
 static void mvpp2_interrupts_mask(void *arg)
 {
struct mvpp2_port *port = arg;
+   int cpu = smp_processor_id();
+   u32 thread;
 
/* If the thread isn't used, don't do anything */
-   if (smp_processor_id() > port->priv->nthreads)
+   if (cpu > port->priv->nthreads)
return;
 
-   mvpp2_thread_write(port->priv,
-  mvpp2_cpu_to_thread(port->priv, smp_processor_id()),
+   thread = mvpp2_cpu_to_thread(port->priv, cpu);
+
+   mvpp2_thread_write(port->priv, thread,
   MVPP2_ISR_RX_TX_MASK_REG(port->id), 0);
+   mvpp2_thread_write(port->priv, thread,
+  MVPP2_ISR_RX_ERR_CAUSE_REG(port->id), 0);
 }
 
 /* Unmask the current thread's Rx/Tx interrupts.
@@ -1150,20 +1155,25 @@ static void mvpp2_interrupts_mask(void *arg)
 static void mvpp2_interrupts_unmask(void *arg)
 {
struct mvpp2_port *port = arg;
-   u32 val;
+   int cpu = smp_processor_id();
+   u32 val, thread;
 
/* If the thread isn't used, don't do anything */
-   if (smp_processor_id() > port->priv->nthreads)
+   if (cpu > port->priv->nthreads)
return;
 
+   thread = mvpp2_cpu_to_thread(port->priv, cpu);
+
val = MVPP2_CAUSE_MISC_SUM_MASK |
MVPP2_CAUSE_RXQ_OCCUP_DESC_ALL_MASK(port->priv->hw_version);
if (port->has_tx_irqs)
val |= MVPP2_CAUSE_TXQ_OCCUP_DESC_ALL_MASK;
 
-   mvpp2_thread_write(port->priv,
-  mvpp2_cpu_to_thread(port->priv, smp_processor_id()),
+   mvpp2_thread_write(port->priv, thread,
   MVPP2_ISR_RX_TX_MASK_REG(port->id), val);
+   mvpp2_thread_write(port->priv, thread,
+  MVPP2_ISR_RX_ERR_CAUSE_REG(port->id),
+  MVPP2_ISR_RX_ERR_CAUSE_NONOCC_MASK);
 }
 
 static void
@@ -1188,6 +1198,9 @@ static void mvpp2_interrupts_unmask(void *arg)
 
mvpp2_thread_write(port->priv, v->sw_thread_id,
   MVPP2_ISR_RX_TX_MASK_REG(port->id), val);
+   mvpp2_thread_write(port->priv, v->sw_thread_id,
+  MVPP2_ISR_RX_ERR_CAUSE_REG(port->id),
+  MVPP2_ISR_RX_ERR_CAUSE_NONOCC_MASK);
}
 }
 
@@ -2393,6 +2406,20 @@ static void mvpp2_txp_max_tx_size_set(struct mvpp2_port 
*port)
}
 }
 
+/* Set the number of non-occupied descriptors threshold */
+static void mvpp2_set_rxq_free_tresh(struct mvpp2_port *port,
+struct mvpp2_rx_queue *rxq)
+{
+   u32 val;
+
+   mvpp2_write(port->priv, MVPP2_RXQ_NUM_REG, rxq->id);
+
+   val = mvpp2_read(port->priv, MVPP2_RXQ_THRESH_REG);
+   val &= ~MVPP2_RXQ_NON_OCCUPIED_MASK;
+   val |= MSS_THRESHOLD_STOP << MVPP2_RXQ_NON_OCCUPIED_OFFSET;
+   mvpp2_write(port->priv, MVPP2_RXQ_THRESH_REG, val);
+}
+
 /* Set the number of packets that will be received before Rx interrupt
  * will be generated by HW.
  */
@@ -2648,6 +2675,9 @@ static int mvpp2_rxq_init(struct mvpp2_port *port,
mvpp2_rx_pkts_coal_set(port, rxq);
mvpp2_rx_time_coal_set(port, rxq);
 
+   /* Set the number of

[PATCH v9 net-next 13/15] net: mvpp2: add PPv23 RX FIFO flow control

2021-02-07 Thread stefanc
From: Stefan Chulski 

New FIFO flow control feature was added in PPv23.
PPv2 FIFO polled by HW and trigger pause frame if FIFO
fill level is below threshold.
FIFO HW flow control enabled with CM3 RXQ&BM flow
control with ethtool.
Current  FIFO thresholds is:
9KB for port with maximum speed 10Gb/s port
4KB for port with maximum speed 5Gb/s port
2KB for port with maximum speed 1Gb/s port

Signed-off-by: Stefan Chulski 
---
 drivers/net/ethernet/marvell/mvpp2/mvpp2.h  | 15 ++
 drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c | 53 
 2 files changed, 68 insertions(+)

diff --git a/drivers/net/ethernet/marvell/mvpp2/mvpp2.h 
b/drivers/net/ethernet/marvell/mvpp2/mvpp2.h
index 9b525b60..b61a1ba 100644
--- a/drivers/net/ethernet/marvell/mvpp2/mvpp2.h
+++ b/drivers/net/ethernet/marvell/mvpp2/mvpp2.h
@@ -770,6 +770,18 @@
 #define MVPP2_TX_FIFO_THRESHOLD(kb)\
((kb) * 1024 - MVPP2_TX_FIFO_THRESHOLD_MIN)
 
+/* RX FIFO threshold in 1KB granularity */
+#define MVPP23_PORT0_FIFO_TRSH (9 * 1024)
+#define MVPP23_PORT1_FIFO_TRSH (4 * 1024)
+#define MVPP23_PORT2_FIFO_TRSH (2 * 1024)
+
+/* RX Flow Control Registers */
+#define MVPP2_RX_FC_REG(port)  (0x150 + 4 * (port))
+#define MVPP2_RX_FC_EN BIT(24)
+#define MVPP2_RX_FC_TRSH_OFFS  16
+#define MVPP2_RX_FC_TRSH_MASK  (0xFF << MVPP2_RX_FC_TRSH_OFFS)
+#define MVPP2_RX_FC_TRSH_UNIT  256
+
 /* MSS Flow control */
 #define MSS_FC_COM_REG 0
 #define FLOW_CONTROL_ENABLE_BITBIT(0)
@@ -1498,6 +1510,8 @@ struct mvpp2_bm_pool {
 
 void mvpp2_dbgfs_cleanup(struct mvpp2 *priv);
 
+void mvpp23_rx_fifo_fc_en(struct mvpp2 *priv, int port, bool en);
+
 #ifdef CONFIG_MVPP2_PTP
 int mvpp22_tai_probe(struct device *dev, struct mvpp2 *priv);
 void mvpp22_tai_tstamp(struct mvpp2_tai *tai, u32 tstamp,
@@ -1530,4 +1544,5 @@ static inline bool mvpp22_rx_hwtstamping(struct 
mvpp2_port *port)
 {
return IS_ENABLED(CONFIG_MVPP2_PTP) && port->rx_hwtstamp;
 }
+
 #endif
diff --git a/drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c 
b/drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c
index 3faad04..a472125 100644
--- a/drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c
+++ b/drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c
@@ -6536,6 +6536,8 @@ static void mvpp2_mac_link_up(struct phylink_config 
*config,
mvpp2_bm_pool_update_fc(port, port->pool_long, 
tx_pause);
mvpp2_bm_pool_update_fc(port, port->pool_short, 
tx_pause);
}
+   if (port->priv->hw_version == MVPP23)
+   mvpp23_rx_fifo_fc_en(port->priv, port->id, tx_pause);
}
 
mvpp2_port_enable(port);
@@ -7004,6 +7006,55 @@ static void mvpp22_rx_fifo_init(struct mvpp2 *priv)
mvpp2_write(priv, MVPP2_RX_FIFO_INIT_REG, 0x1);
 }
 
+/* Configure Rx FIFO Flow control thresholds */
+static void mvpp23_rx_fifo_fc_set_tresh(struct mvpp2 *priv)
+{
+   int port, val;
+
+   /* Port 0: maximum speed -10Gb/s port
+* required by spec RX FIFO threshold 9KB
+* Port 1: maximum speed -5Gb/s port
+* required by spec RX FIFO threshold 4KB
+* Port 2: maximum speed -1Gb/s port
+* required by spec RX FIFO threshold 2KB
+*/
+
+   /* Without loopback port */
+   for (port = 0; port < (MVPP2_MAX_PORTS - 1); port++) {
+   if (port == 0) {
+   val = (MVPP23_PORT0_FIFO_TRSH / MVPP2_RX_FC_TRSH_UNIT)
+   << MVPP2_RX_FC_TRSH_OFFS;
+   val &= MVPP2_RX_FC_TRSH_MASK;
+   mvpp2_write(priv, MVPP2_RX_FC_REG(port), val);
+   } else if (port == 1) {
+   val = (MVPP23_PORT1_FIFO_TRSH / MVPP2_RX_FC_TRSH_UNIT)
+   << MVPP2_RX_FC_TRSH_OFFS;
+   val &= MVPP2_RX_FC_TRSH_MASK;
+   mvpp2_write(priv, MVPP2_RX_FC_REG(port), val);
+   } else {
+   val = (MVPP23_PORT2_FIFO_TRSH / MVPP2_RX_FC_TRSH_UNIT)
+   << MVPP2_RX_FC_TRSH_OFFS;
+   val &= MVPP2_RX_FC_TRSH_MASK;
+   mvpp2_write(priv, MVPP2_RX_FC_REG(port), val);
+   }
+   }
+}
+
+/* Configure Rx FIFO Flow control thresholds */
+void mvpp23_rx_fifo_fc_en(struct mvpp2 *priv, int port, bool en)
+{
+   int val;
+
+   val = mvpp2_read(priv, MVPP2_RX_FC_REG(port));
+
+   if (en)
+   val |= MVPP2_RX_FC_EN;
+   else
+   val &= ~MVPP2_RX_FC_EN;
+
+   mvpp2_write(priv, MVPP2_RX_FC_REG(port), val);
+}
+
 static void mvpp22_tx_fifo_set_hw(struct mvpp2 *priv, int port, int size)
 {
int threshold = MVPP2_TX_FIFO_THRESHOLD(size);
@@ -7155,6 +7206,8 @@ static int mvpp2_init(struct platform_device *pdev, 
struct mvpp2 *priv)
} else {
mvpp22_rx_fifo_init(priv);
 

[PATCH v9 net-next 06/15] net: mvpp2: increase BM pool and RXQ size

2021-02-07 Thread stefanc
From: Stefan Chulski 

BM pool and RXQ size increased to support Firmware Flow Control.
Minimum depletion thresholds to support FC are 1024 buffers.
BM pool size increased to 2048 to have some 1024 buffers
space between depletion thresholds and BM pool size.

Jumbo frames require a 9888B buffer, so memory requirements
for data buffers increased from 7MB to 24MB.

Signed-off-by: Stefan Chulski 
---
 drivers/net/ethernet/marvell/mvpp2/mvpp2.h | 8 
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/drivers/net/ethernet/marvell/mvpp2/mvpp2.h 
b/drivers/net/ethernet/marvell/mvpp2/mvpp2.h
index ce08086..e7bbf0a 100644
--- a/drivers/net/ethernet/marvell/mvpp2/mvpp2.h
+++ b/drivers/net/ethernet/marvell/mvpp2/mvpp2.h
@@ -715,8 +715,8 @@
 #define MVPP2_PORT_MAX_RXQ 32
 
 /* Max number of Rx descriptors */
-#define MVPP2_MAX_RXD_MAX  1024
-#define MVPP2_MAX_RXD_DFLT 128
+#define MVPP2_MAX_RXD_MAX  2048
+#define MVPP2_MAX_RXD_DFLT 1024
 
 /* Max number of Tx descriptors */
 #define MVPP2_MAX_TXD_MAX  2048
@@ -848,8 +848,8 @@ enum mvpp22_ptp_packet_format {
 #define MVPP22_PTP_TIMESTAMPQUEUESELECTBIT(18)
 
 /* BM constants */
-#define MVPP2_BM_JUMBO_BUF_NUM 512
-#define MVPP2_BM_LONG_BUF_NUM  1024
+#define MVPP2_BM_JUMBO_BUF_NUM 2048
+#define MVPP2_BM_LONG_BUF_NUM  2048
 #define MVPP2_BM_SHORT_BUF_NUM 2048
 #define MVPP2_BM_POOL_SIZE_MAX (16*1024 - MVPP2_BM_POOL_PTR_ALIGN/4)
 #define MVPP2_BM_POOL_PTR_ALIGN128
-- 
1.9.1



[PATCH v9 net-next 12/15] net: mvpp2: add BM protection underrun feature support

2021-02-07 Thread stefanc
From: Stefan Chulski 

The PP2v23 hardware supports a feature allowing to double the
size of BPPI by decreasing number of pools from 16 to 8.
Increasing of BPPI size protect BM drop from BPPI underrun.
Underrun could occurred due to stress on DDR and as result slow buffer
transition from BPPE to BPPI.
New BPPI threshold recommended by spec is:
BPPI low threshold - 640 buffers
BPPI high threshold - 832 buffers
Supported only in PPv23.

Signed-off-by: Stefan Chulski 
---
 drivers/net/ethernet/marvell/mvpp2/mvpp2.h  |  8 +
 drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c | 35 +++-
 2 files changed, 42 insertions(+), 1 deletion(-)

diff --git a/drivers/net/ethernet/marvell/mvpp2/mvpp2.h 
b/drivers/net/ethernet/marvell/mvpp2/mvpp2.h
index 0731dc7..9b525b60 100644
--- a/drivers/net/ethernet/marvell/mvpp2/mvpp2.h
+++ b/drivers/net/ethernet/marvell/mvpp2/mvpp2.h
@@ -324,6 +324,10 @@
 #define MVPP2_BM_HIGH_THRESH_MASK  0x7f
 #define MVPP2_BM_HIGH_THRESH_VALUE(val)((val) << \
MVPP2_BM_HIGH_THRESH_OFFS)
+#define MVPP2_BM_BPPI_HIGH_THRESH  0x1E
+#define MVPP2_BM_BPPI_LOW_THRESH   0x1C
+#define MVPP23_BM_BPPI_HIGH_THRESH 0x34
+#define MVPP23_BM_BPPI_LOW_THRESH  0x28
 #define MVPP2_BM_INTR_CAUSE_REG(pool)  (0x6240 + ((pool) * 4))
 #define MVPP2_BM_RELEASED_DELAY_MASK   BIT(0)
 #define MVPP2_BM_ALLOC_FAILED_MASK BIT(1)
@@ -352,6 +356,10 @@
 #define MVPP2_OVERRUN_ETH_DROP 0x7000
 #define MVPP2_CLS_ETH_DROP 0x7020
 
+#define MVPP22_BM_POOL_BASE_ADDR_HIGH_REG  0x6310
+#define MVPP22_BM_POOL_BASE_ADDR_HIGH_MASK 0xff
+#define MVPP23_BM_8POOL_MODE   BIT(8)
+
 /* Hit counters registers */
 #define MVPP2_CTRS_IDX 0x7040
 #define MVPP22_CTRS_TX_CTR(port, txq)  ((txq) | ((port) << 3) | BIT(7))
diff --git a/drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c 
b/drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c
index 90c9265..3faad04 100644
--- a/drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c
+++ b/drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c
@@ -69,6 +69,11 @@ enum mvpp2_bm_pool_log_num {
 module_param(queue_mode, int, 0444);
 MODULE_PARM_DESC(queue_mode, "Set queue_mode (single=0, multi=1)");
 
+static int bm_underrun_protect = 1;
+
+module_param(bm_underrun_protect, int, 0444);
+MODULE_PARM_DESC(bm_underrun_protect, "Set BM underrun protect feature (0-1), 
def=1");
+
 /* Utility/helper methods */
 
 void mvpp2_write(struct mvpp2 *priv, u32 offset, u32 data)
@@ -423,6 +428,21 @@ static int mvpp2_bm_pool_create(struct device *dev, struct 
mvpp2 *priv,
 
val = mvpp2_read(priv, MVPP2_BM_POOL_CTRL_REG(bm_pool->id));
val |= MVPP2_BM_START_MASK;
+
+   val &= ~MVPP2_BM_LOW_THRESH_MASK;
+   val &= ~MVPP2_BM_HIGH_THRESH_MASK;
+
+   /* Set 8 Pools BPPI threshold if BM underrun protection feature
+* was enabled
+*/
+   if (priv->hw_version == MVPP23 && bm_underrun_protect) {
+   val |= MVPP2_BM_LOW_THRESH_VALUE(MVPP23_BM_BPPI_LOW_THRESH);
+   val |= MVPP2_BM_HIGH_THRESH_VALUE(MVPP23_BM_BPPI_HIGH_THRESH);
+   } else {
+   val |= MVPP2_BM_LOW_THRESH_VALUE(MVPP2_BM_BPPI_LOW_THRESH);
+   val |= MVPP2_BM_HIGH_THRESH_VALUE(MVPP2_BM_BPPI_HIGH_THRESH);
+   }
+
mvpp2_write(priv, MVPP2_BM_POOL_CTRL_REG(bm_pool->id), val);
 
bm_pool->size = size;
@@ -591,6 +611,16 @@ static int mvpp2_bm_pools_init(struct device *dev, struct 
mvpp2 *priv)
return err;
 }
 
+/* Routine enable PPv23 8 pool mode */
+static void mvpp23_bm_set_8pool_mode(struct mvpp2 *priv)
+{
+   int val;
+
+   val = mvpp2_read(priv, MVPP22_BM_POOL_BASE_ADDR_HIGH_REG);
+   val |= MVPP23_BM_8POOL_MODE;
+   mvpp2_write(priv, MVPP22_BM_POOL_BASE_ADDR_HIGH_REG, val);
+}
+
 static int mvpp2_bm_init(struct device *dev, struct mvpp2 *priv)
 {
enum dma_data_direction dma_dir = DMA_FROM_DEVICE;
@@ -644,6 +674,9 @@ static int mvpp2_bm_init(struct device *dev, struct mvpp2 
*priv)
if (!priv->bm_pools)
return -ENOMEM;
 
+   if (priv->hw_version == MVPP23 && bm_underrun_protect)
+   mvpp23_bm_set_8pool_mode(priv);
+
err = mvpp2_bm_pools_init(dev, priv);
if (err < 0)
return err;
@@ -6490,7 +6523,7 @@ static void mvpp2_mac_link_up(struct phylink_config 
*config,
 val);
}
 
-   if (port->priv->global_tx_fc) {
+   if (port->priv->global_tx_fc && bm_underrun_protect) {
port->tx_fc = tx_pause;
if (tx_pause)
mvpp2_rxq_enable_fc(port);
-- 
1.9.1



[PATCH v9 net-next 10/15] net: mvpp2: add RXQ flow control configurations

2021-02-07 Thread stefanc
From: Stefan Chulski 

This patch adds RXQ flow control configurations.
Flow control disabled by default.
Minimum ring size limited to 1024 descriptors.

Signed-off-by: Stefan Chulski 
---
 drivers/net/ethernet/marvell/mvpp2/mvpp2.h  |  35 +-
 drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c | 116 
 2 files changed, 150 insertions(+), 1 deletion(-)

diff --git a/drivers/net/ethernet/marvell/mvpp2/mvpp2.h 
b/drivers/net/ethernet/marvell/mvpp2/mvpp2.h
index 8945fb9..0010a3e9 100644
--- a/drivers/net/ethernet/marvell/mvpp2/mvpp2.h
+++ b/drivers/net/ethernet/marvell/mvpp2/mvpp2.h
@@ -765,9 +765,36 @@
 /* MSS Flow control */
 #define MSS_FC_COM_REG 0
 #define FLOW_CONTROL_ENABLE_BITBIT(0)
+#define FLOW_CONTROL_UPDATE_COMMAND_BITBIT(31)
 #define FC_QUANTA  0x
 #define FC_CLK_DIVIDER 100
-#define MSS_THRESHOLD_STOP 768
+
+#define MSS_RXQ_TRESH_BASE 0x200
+#define MSS_RXQ_TRESH_OFFS 4
+#define MSS_RXQ_TRESH_REG(q, fq)   (MSS_RXQ_TRESH_BASE + (((q) + (fq)) \
+   * MSS_RXQ_TRESH_OFFS))
+
+#define MSS_RXQ_TRESH_START_MASK   0x
+#define MSS_RXQ_TRESH_STOP_MASK(0x << 
MSS_RXQ_TRESH_STOP_OFFS)
+#define MSS_RXQ_TRESH_STOP_OFFS16
+
+#define MSS_RXQ_ASS_BASE   0x80
+#define MSS_RXQ_ASS_OFFS   4
+#define MSS_RXQ_ASS_PER_REG4
+#define MSS_RXQ_ASS_PER_OFFS   8
+#define MSS_RXQ_ASS_PORTID_OFFS0
+#define MSS_RXQ_ASS_PORTID_MASK0x3
+#define MSS_RXQ_ASS_HOSTID_OFFS2
+#define MSS_RXQ_ASS_HOSTID_MASK0x3F
+
+#define MSS_RXQ_ASS_Q_BASE(q, fq) q) + (fq)) % MSS_RXQ_ASS_PER_REG)
 \
+ * MSS_RXQ_ASS_PER_OFFS)
+#define MSS_RXQ_ASS_PQ_BASE(q, fq) q) + (fq)) / MSS_RXQ_ASS_PER_REG) \
+  * MSS_RXQ_ASS_OFFS)
+#define MSS_RXQ_ASS_REG(q, fq) (MSS_RXQ_ASS_BASE + MSS_RXQ_ASS_PQ_BASE(q, fq))
+
+#define MSS_THRESHOLD_STOP 768
+#define MSS_THRESHOLD_START1024
 
 /* RX buffer constants */
 #define MVPP2_SKB_SHINFO_SIZE \
@@ -1022,6 +1049,9 @@ struct mvpp2 {
 
/* Global TX Flow Control config */
bool global_tx_fc;
+
+   /* Spinlocks for CM3 shared memory configuration */
+   spinlock_t mss_spinlock;
 };
 
 struct mvpp2_pcpu_stats {
@@ -1184,6 +1214,9 @@ struct mvpp2_port {
bool rx_hwtstamp;
enum hwtstamp_tx_types tx_hwtstamp_type;
struct mvpp2_hwtstamp_queue tx_hwtstamp_queue[2];
+
+   /* Firmware TX flow control */
+   bool tx_fc;
 };
 
 /* The mvpp2_tx_desc and mvpp2_rx_desc structures describe the
diff --git a/drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c 
b/drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c
index 027101b..f1770e5 100644
--- a/drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c
+++ b/drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c
@@ -741,6 +741,110 @@ static void *mvpp2_buf_alloc(struct mvpp2_port *port,
return data;
 }
 
+/* Routine enable flow control for RXQs condition */
+static void mvpp2_rxq_enable_fc(struct mvpp2_port *port)
+{
+   int val, cm3_state, host_id, q;
+   int fq = port->first_rxq;
+   unsigned long flags;
+
+   spin_lock_irqsave(&port->priv->mss_spinlock, flags);
+
+   /* Remove Flow control enable bit to prevent race between FW and Kernel
+* If Flow control was enabled, it would be re-enabled.
+*/
+   val = mvpp2_cm3_read(port->priv, MSS_FC_COM_REG);
+   cm3_state = (val & FLOW_CONTROL_ENABLE_BIT);
+   val &= ~FLOW_CONTROL_ENABLE_BIT;
+   mvpp2_cm3_write(port->priv, MSS_FC_COM_REG, val);
+
+   /* Set same Flow control for all RXQs */
+   for (q = 0; q < port->nrxqs; q++) {
+   /* Set stop and start Flow control RXQ thresholds */
+   val = MSS_THRESHOLD_START;
+   val |= (MSS_THRESHOLD_STOP << MSS_RXQ_TRESH_STOP_OFFS);
+   mvpp2_cm3_write(port->priv, MSS_RXQ_TRESH_REG(q, fq), val);
+
+   val = mvpp2_cm3_read(port->priv, MSS_RXQ_ASS_REG(q, fq));
+   /* Set RXQ port ID */
+   val &= ~(MSS_RXQ_ASS_PORTID_MASK << MSS_RXQ_ASS_Q_BASE(q, fq));
+   val |= (port->id << MSS_RXQ_ASS_Q_BASE(q, fq));
+   val &= ~(MSS_RXQ_ASS_HOSTID_MASK << (MSS_RXQ_ASS_Q_BASE(q, fq)
+   + MSS_RXQ_ASS_HOSTID_OFFS));
+
+   /* Calculate RXQ host ID:
+* In Single queue mode: Host ID equal to Host ID used for
+*   shared RX interrupt
+* In Multi queue mode: Host ID equal to number of
+*  RXQ ID / number of CoS queues
+* In Single resource mode: Host ID always equal to 0
+*/
+   if (queue_mode == MVPP2_QDIST_SINGLE_MODE)
+   host_id = port->nqvecs;
+   else if (queue

[PATCH v9 net-next 09/15] net: mvpp2: enable global flow control

2021-02-07 Thread stefanc
From: Stefan Chulski 

This patch enables global flow control in FW and in the phylink validate mask.

Signed-off-by: Stefan Chulski 
---
 drivers/net/ethernet/marvell/mvpp2/mvpp2.h  | 11 +--
 drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c | 30 +++-
 2 files changed, 37 insertions(+), 4 deletions(-)

diff --git a/drivers/net/ethernet/marvell/mvpp2/mvpp2.h 
b/drivers/net/ethernet/marvell/mvpp2/mvpp2.h
index d2cc513c..8945fb9 100644
--- a/drivers/net/ethernet/marvell/mvpp2/mvpp2.h
+++ b/drivers/net/ethernet/marvell/mvpp2/mvpp2.h
@@ -763,9 +763,11 @@
((kb) * 1024 - MVPP2_TX_FIFO_THRESHOLD_MIN)
 
 /* MSS Flow control */
-#define FC_QUANTA  0x
-#define FC_CLK_DIVIDER 100
-#define MSS_THRESHOLD_STOP 768
+#define MSS_FC_COM_REG 0
+#define FLOW_CONTROL_ENABLE_BITBIT(0)
+#define FC_QUANTA  0x
+#define FC_CLK_DIVIDER 100
+#define MSS_THRESHOLD_STOP 768
 
 /* RX buffer constants */
 #define MVPP2_SKB_SHINFO_SIZE \
@@ -1017,6 +1019,9 @@ struct mvpp2 {
 
/* page_pool allocator */
struct page_pool *page_pool[MVPP2_PORT_MAX_RXQ];
+
+   /* Global TX Flow Control config */
+   bool global_tx_fc;
 };
 
 struct mvpp2_pcpu_stats {
diff --git a/drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c 
b/drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c
index 8b4073c..027101b 100644
--- a/drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c
+++ b/drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c
@@ -91,6 +91,16 @@ static inline u32 mvpp2_cpu_to_thread(struct mvpp2 *priv, 
int cpu)
return cpu % priv->nthreads;
 }
 
+static void mvpp2_cm3_write(struct mvpp2 *priv, u32 offset, u32 data)
+{
+   writel(data, priv->cm3_base + offset);
+}
+
+static u32 mvpp2_cm3_read(struct mvpp2 *priv, u32 offset)
+{
+   return readl(priv->cm3_base + offset);
+}
+
 static struct page_pool *
 mvpp2_create_page_pool(struct device *dev, int num, int len,
   enum dma_data_direction dma_dir)
@@ -5950,6 +5960,11 @@ static void mvpp2_phylink_validate(struct phylink_config 
*config,
phylink_set(mask, Autoneg);
phylink_set_port_modes(mask);
 
+   if (port->priv->global_tx_fc) {
+   phylink_set(mask, Pause);
+   phylink_set(mask, Asym_Pause);
+   }
+
switch (state->interface) {
case PHY_INTERFACE_MODE_10GBASER:
case PHY_INTERFACE_MODE_XAUI:
@@ -6951,7 +6966,7 @@ static int mvpp2_probe(struct platform_device *pdev)
struct resource *res;
void __iomem *base;
int i, shared;
-   int err;
+   int err, val;
 
priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL);
if (!priv)
@@ -7003,6 +7018,10 @@ static int mvpp2_probe(struct platform_device *pdev)
err = mvpp2_get_sram(pdev, priv);
if (err)
dev_warn(&pdev->dev, "Fail to alloc CM3 SRAM\n");
+
+   /* Enable global Flow Control only if handler to SRAM not NULL 
*/
+   if (priv->cm3_base)
+   priv->global_tx_fc = true;
}
 
if (priv->hw_version != MVPP21 && dev_of_node(&pdev->dev)) {
@@ -7168,6 +7187,15 @@ static int mvpp2_probe(struct platform_device *pdev)
goto err_port_probe;
}
 
+   /* Enable global flow control. In this stage global
+* flow control enabled, but still disabled per port.
+*/
+   if (priv->global_tx_fc && priv->hw_version != MVPP21) {
+   val = mvpp2_cm3_read(priv, MSS_FC_COM_REG);
+   val |= FLOW_CONTROL_ENABLE_BIT;
+   mvpp2_cm3_write(priv, MSS_FC_COM_REG, val);
+   }
+
mvpp2_dbgfs_init(priv, pdev->name);
 
platform_set_drvdata(pdev, priv);
-- 
1.9.1



[PATCH v9 net-next 07/15] net: mvpp2: add FCA periodic timer configurations

2021-02-07 Thread stefanc
From: Stefan Chulski 

Flow Control periodic timer would be used if port in
XOFF to transmit periodic XOFF frames.

Signed-off-by: Stefan Chulski 
---
 drivers/net/ethernet/marvell/mvpp2/mvpp2.h  | 13 ++
 drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c | 45 
 2 files changed, 58 insertions(+)

diff --git a/drivers/net/ethernet/marvell/mvpp2/mvpp2.h 
b/drivers/net/ethernet/marvell/mvpp2/mvpp2.h
index e7bbf0a..9239d80 100644
--- a/drivers/net/ethernet/marvell/mvpp2/mvpp2.h
+++ b/drivers/net/ethernet/marvell/mvpp2/mvpp2.h
@@ -596,6 +596,15 @@
 #define MVPP22_MPCS_CLK_RESET_DIV_RATIO(n) ((n) << 4)
 #define MVPP22_MPCS_CLK_RESET_DIV_SET  BIT(11)
 
+/* FCA registers. PPv2.2 and PPv2.3 */
+#define MVPP22_FCA_BASE(port)  (0x7600 + (port) * 0x1000)
+#define MVPP22_FCA_REG_SIZE16
+#define MVPP22_FCA_REG_MASK0x
+#define MVPP22_FCA_CONTROL_REG 0x0
+#define MVPP22_FCA_ENABLE_PERIODIC BIT(11)
+#define MVPP22_PERIODIC_COUNTER_LSB_REG(0x110)
+#define MVPP22_PERIODIC_COUNTER_MSB_REG(0x114)
+
 /* XPCS registers. PPv2.2 and PPv2.3 */
 #define MVPP22_XPCS_BASE(port) (0x7400 + (port) * 0x1000)
 #define MVPP22_XPCS_CFG0   0x0
@@ -751,6 +760,10 @@
 #define MVPP2_TX_FIFO_THRESHOLD(kb)\
((kb) * 1024 - MVPP2_TX_FIFO_THRESHOLD_MIN)
 
+/* MSS Flow control */
+#define FC_QUANTA  0x
+#define FC_CLK_DIVIDER 100
+
 /* RX buffer constants */
 #define MVPP2_SKB_SHINFO_SIZE \
SKB_DATA_ALIGN(sizeof(struct skb_shared_info))
diff --git a/drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c 
b/drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c
index 5730900..761f745 100644
--- a/drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c
+++ b/drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c
@@ -1280,6 +1280,49 @@ static void mvpp22_gop_init_10gkr(struct mvpp2_port 
*port)
writel(val, mpcs + MVPP22_MPCS_CLK_RESET);
 }
 
+static void mvpp22_gop_fca_enable_periodic(struct mvpp2_port *port, bool en)
+{
+   struct mvpp2 *priv = port->priv;
+   void __iomem *fca = priv->iface_base + MVPP22_FCA_BASE(port->gop_id);
+   u32 val;
+
+   val = readl(fca + MVPP22_FCA_CONTROL_REG);
+   val &= ~MVPP22_FCA_ENABLE_PERIODIC;
+   if (en)
+   val |= MVPP22_FCA_ENABLE_PERIODIC;
+   writel(val, fca + MVPP22_FCA_CONTROL_REG);
+}
+
+static void mvpp22_gop_fca_set_timer(struct mvpp2_port *port, u32 timer)
+{
+   struct mvpp2 *priv = port->priv;
+   void __iomem *fca = priv->iface_base + MVPP22_FCA_BASE(port->gop_id);
+   u32 lsb, msb;
+
+   lsb = timer & MVPP22_FCA_REG_MASK;
+   msb = timer >> MVPP22_FCA_REG_SIZE;
+
+   writel(lsb, fca + MVPP22_PERIODIC_COUNTER_LSB_REG);
+   writel(msb, fca + MVPP22_PERIODIC_COUNTER_MSB_REG);
+}
+
+/* Set Flow Control timer x100 faster than pause quanta to ensure that link
+ * partner won't send traffic if port is in XOFF mode.
+ */
+static void mvpp22_gop_fca_set_periodic_timer(struct mvpp2_port *port)
+{
+   u32 timer;
+
+   timer = (port->priv->tclk / (USEC_PER_SEC * FC_CLK_DIVIDER))
+   * FC_QUANTA;
+
+   mvpp22_gop_fca_enable_periodic(port, false);
+
+   mvpp22_gop_fca_set_timer(port, timer);
+
+   mvpp22_gop_fca_enable_periodic(port, true);
+}
+
 static int mvpp22_gop_init(struct mvpp2_port *port)
 {
struct mvpp2 *priv = port->priv;
@@ -1324,6 +1367,8 @@ static int mvpp22_gop_init(struct mvpp2_port *port)
val |= GENCONF_SOFT_RESET1_GOP;
regmap_write(priv->sysctrl_base, GENCONF_SOFT_RESET1, val);
 
+   mvpp22_gop_fca_set_periodic_timer(port);
+
 unsupported_conf:
return 0;
 
-- 
1.9.1



[PATCH v9 net-next 04/15] net: mvpp2: always compare hw-version vs MVPP21

2021-02-07 Thread stefanc
From: Stefan Chulski 

Currently we have PP2v1 and PP2v2 hw-versions, with some different
handlers depending upon condition hw_version = MVPP21/MVPP22.
In a future there will be also PP2v3. Let's use now the generic
"if equal/notEqual MVPP21" for all cases instead of "if MVPP22".

This patch does not change any functionality.
It is not intended to introduce PP2v3.
It just modifies MVPP21/MVPP22 check-condition
bringing it to generic and unified form correct for new-code
introducing and PP2v3 net-next generation.

Signed-off-by: Stefan Chulski 
---
 drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c | 36 ++--
 1 file changed, 18 insertions(+), 18 deletions(-)

diff --git a/drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c 
b/drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c
index eec3796..e9c5916 100644
--- a/drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c
+++ b/drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c
@@ -319,7 +319,7 @@ static int mvpp2_get_nrxqs(struct mvpp2 *priv)
 {
unsigned int nrxqs;
 
-   if (priv->hw_version == MVPP22 && queue_mode == MVPP2_QDIST_SINGLE_MODE)
+   if (priv->hw_version != MVPP21 && queue_mode == MVPP2_QDIST_SINGLE_MODE)
return 1;
 
/* According to the PPv2.2 datasheet and our experiments on
@@ -446,7 +446,7 @@ static void mvpp2_bm_bufs_get_addrs(struct device *dev, 
struct mvpp2 *priv,
  MVPP2_BM_PHY_ALLOC_REG(bm_pool->id));
*phys_addr = mvpp2_thread_read(priv, thread, MVPP2_BM_VIRT_ALLOC_REG);
 
-   if (priv->hw_version == MVPP22) {
+   if (priv->hw_version != MVPP21) {
u32 val;
u32 dma_addr_highbits, phys_addr_highbits;
 
@@ -742,7 +742,7 @@ static inline void mvpp2_bm_pool_put(struct mvpp2_port 
*port, int pool,
if (test_bit(thread, &port->priv->lock_map))
spin_lock_irqsave(&port->bm_lock[thread], flags);
 
-   if (port->priv->hw_version == MVPP22) {
+   if (port->priv->hw_version != MVPP21) {
u32 val = 0;
 
if (sizeof(dma_addr_t) == 8)
@@ -1199,7 +1199,7 @@ static bool mvpp2_port_supports_xlg(struct mvpp2_port 
*port)
 
 static bool mvpp2_port_supports_rgmii(struct mvpp2_port *port)
 {
-   return !(port->priv->hw_version == MVPP22 && port->gop_id == 0);
+   return !(port->priv->hw_version != MVPP21 && port->gop_id == 0);
 }
 
 /* Port configuration routines */
@@ -1817,7 +1817,7 @@ static void mvpp2_mac_reset_assert(struct mvpp2_port 
*port)
  MVPP2_GMAC_PORT_RESET_MASK;
writel(val, port->base + MVPP2_GMAC_CTRL_2_REG);
 
-   if (port->priv->hw_version == MVPP22 && port->gop_id == 0) {
+   if (port->priv->hw_version != MVPP21 && port->gop_id == 0) {
val = readl(port->base + MVPP22_XLG_CTRL0_REG) &
  ~MVPP22_XLG_CTRL0_MAC_RESET_DIS;
writel(val, port->base + MVPP22_XLG_CTRL0_REG);
@@ -1830,7 +1830,7 @@ static void mvpp22_pcs_reset_assert(struct mvpp2_port 
*port)
void __iomem *mpcs, *xpcs;
u32 val;
 
-   if (port->priv->hw_version != MVPP22 || port->gop_id != 0)
+   if (port->priv->hw_version == MVPP21 || port->gop_id != 0)
return;
 
mpcs = priv->iface_base + MVPP22_MPCS_BASE(port->gop_id);
@@ -1851,7 +1851,7 @@ static void mvpp22_pcs_reset_deassert(struct mvpp2_port 
*port)
void __iomem *mpcs, *xpcs;
u32 val;
 
-   if (port->priv->hw_version != MVPP22 || port->gop_id != 0)
+   if (port->priv->hw_version == MVPP21 || port->gop_id != 0)
return;
 
mpcs = priv->iface_base + MVPP22_MPCS_BASE(port->gop_id);
@@ -4188,7 +4188,7 @@ static void mvpp2_start_dev(struct mvpp2_port *port)
/* Enable interrupts on all threads */
mvpp2_interrupts_enable(port);
 
-   if (port->priv->hw_version == MVPP22)
+   if (port->priv->hw_version != MVPP21)
mvpp22_mode_reconfigure(port);
 
if (port->phylink) {
@@ -4404,7 +4404,7 @@ static int mvpp2_open(struct net_device *dev)
valid = true;
}
 
-   if (priv->hw_version == MVPP22 && port->port_irq) {
+   if (priv->hw_version != MVPP21 && port->port_irq) {
err = request_irq(port->port_irq, mvpp2_port_isr, 0,
  dev->name, port);
if (err) {
@@ -6052,7 +6052,7 @@ static int mvpp2__mac_prepare(struct phylink_config 
*config, unsigned int mode,
 MVPP2_GMAC_PORT_RESET_MASK,
 MVPP2_GMAC_PORT_RESET_MASK);
 
-   if (port->priv->hw_version == MVPP22) {
+   if (port->priv->hw_version != MVPP21) {
mvpp22_gop_mask_irq(port);
 
phy_power_off(port->comphy);
@@ -6106,7 +6106,7 @@ static int mvpp2_mac_finish(struct phylink_config 
*config, unsigned int mode,
 {
struct mvpp2_port *port = mvpp2_phylink_to_port(config);
 
-

[PATCH v9 net-next 03/15] net: mvpp2: add CM3 SRAM memory map

2021-02-07 Thread stefanc
From: Stefan Chulski 

This patch adds CM3 memory map and CM3 read/write callbacks.

Signed-off-by: Stefan Chulski 
---
 drivers/net/ethernet/marvell/mvpp2/mvpp2.h  |  1 +
 drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c | 26 
 2 files changed, 27 insertions(+)

diff --git a/drivers/net/ethernet/marvell/mvpp2/mvpp2.h 
b/drivers/net/ethernet/marvell/mvpp2/mvpp2.h
index 6bd7e40..56e90ab 100644
--- a/drivers/net/ethernet/marvell/mvpp2/mvpp2.h
+++ b/drivers/net/ethernet/marvell/mvpp2/mvpp2.h
@@ -925,6 +925,7 @@ struct mvpp2 {
/* Shared registers' base addresses */
void __iomem *lms_base;
void __iomem *iface_base;
+   void __iomem *cm3_base;
 
/* On PPv2.2, each "software thread" can access the base
 * register through a separate address space, each 64 KB apart
diff --git a/drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c 
b/drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c
index a07cf60..eec3796 100644
--- a/drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c
+++ b/drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c
@@ -6846,6 +6846,27 @@ static int mvpp2_init(struct platform_device *pdev, 
struct mvpp2 *priv)
return 0;
 }
 
+static int mvpp2_get_sram(struct platform_device *pdev,
+ struct mvpp2 *priv)
+{
+   struct resource *res;
+
+   res = platform_get_resource(pdev, IORESOURCE_MEM, 2);
+   if (!res) {
+   if (has_acpi_companion(&pdev->dev))
+   dev_warn(&pdev->dev, "ACPI is too old, Flow control not 
supported\n");
+   else
+   dev_warn(&pdev->dev, "DT is too old, Flow control not 
supported\n");
+   return 0;
+   }
+
+   priv->cm3_base = devm_ioremap_resource(&pdev->dev, res);
+   if (IS_ERR(priv->cm3_base))
+   return PTR_ERR(priv->cm3_base);
+
+   return 0;
+}
+
 static int mvpp2_probe(struct platform_device *pdev)
 {
const struct acpi_device_id *acpi_id;
@@ -6902,6 +6923,11 @@ static int mvpp2_probe(struct platform_device *pdev)
priv->iface_base = devm_ioremap_resource(&pdev->dev, res);
if (IS_ERR(priv->iface_base))
return PTR_ERR(priv->iface_base);
+
+   /* Map CM3 SRAM */
+   err = mvpp2_get_sram(pdev, priv);
+   if (err)
+   dev_warn(&pdev->dev, "Fail to alloc CM3 SRAM\n");
}
 
if (priv->hw_version == MVPP22 && dev_of_node(&pdev->dev)) {
-- 
1.9.1



[PATCH v9 net-next 02/15] dts: marvell: add CM3 SRAM memory to cp11x ethernet device tree

2021-02-07 Thread stefanc
From: Konstantin Porotchkin 

CM3 SRAM address space would be used for Flow Control configuration.

Signed-off-by: Stefan Chulski 
Signed-off-by: Konstantin Porotchkin 
---
 arch/arm64/boot/dts/marvell/armada-cp11x.dtsi | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/arm64/boot/dts/marvell/armada-cp11x.dtsi 
b/arch/arm64/boot/dts/marvell/armada-cp11x.dtsi
index 9dcf16b..6fe0d26 100644
--- a/arch/arm64/boot/dts/marvell/armada-cp11x.dtsi
+++ b/arch/arm64/boot/dts/marvell/armada-cp11x.dtsi
@@ -59,7 +59,7 @@
 
CP11X_LABEL(ethernet): ethernet@0 {
compatible = "marvell,armada-7k-pp22";
-   reg = <0x0 0x10>, <0x129000 0xb000>;
+   reg = <0x0 0x10>, <0x129000 0xb000>, <0x22 
0x800>;
clocks = <&CP11X_LABEL(clk) 1 3>, <&CP11X_LABEL(clk) 1 
9>,
 <&CP11X_LABEL(clk) 1 5>, <&CP11X_LABEL(clk) 1 
6>,
 <&CP11X_LABEL(clk) 1 18>;
-- 
1.9.1



[PATCH v9 net-next 01/15] doc: marvell: add CM3 address space and PPv2.3 description

2021-02-07 Thread stefanc
From: Stefan Chulski 

Patch adds CM3 address space PPv2.3 description.

Signed-off-by: Stefan Chulski 
---
 Documentation/devicetree/bindings/net/marvell-pp2.txt | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/Documentation/devicetree/bindings/net/marvell-pp2.txt 
b/Documentation/devicetree/bindings/net/marvell-pp2.txt
index b783976..1eb480a 100644
--- a/Documentation/devicetree/bindings/net/marvell-pp2.txt
+++ b/Documentation/devicetree/bindings/net/marvell-pp2.txt
@@ -1,5 +1,6 @@
 * Marvell Armada 375 Ethernet Controller (PPv2.1)
   Marvell Armada 7K/8K Ethernet Controller (PPv2.2)
+  Marvell CN913X Ethernet Controller (PPv2.3)
 
 Required properties:
 
@@ -12,7 +13,7 @@ Required properties:
- common controller registers
- LMS registers
- one register area per Ethernet port
-  For "marvell,armada-7k-pp2", must contain the following register
+  For "marvell,armada-7k-pp2" used by 7K/8K and CN913X, must contain the 
following register
   sets:
- packet processor registers
- networking interfaces registers
@@ -81,7 +82,7 @@ Example for marvell,armada-7k-pp2:
 
 cpm_ethernet: ethernet@0 {
compatible = "marvell,armada-7k-pp22";
-   reg = <0x0 0x10>, <0x129000 0xb000>;
+   reg = <0x0 0x10>, <0x129000 0xb000>, <0x22 0x800>;
clocks = <&cpm_syscon0 1 3>, <&cpm_syscon0 1 9>,
 <&cpm_syscon0 1 5>, <&cpm_syscon0 1 6>, <&cpm_syscon0 1 18>;
clock-names = "pp_clk", "gop_clk", "mg_clk", "mg_core_clk", "axi_clk";
-- 
1.9.1



[PATCH v9 net-next 00/15] net: mvpp2: Add TX Flow Control support

2021-02-07 Thread stefanc
From: Stefan Chulski 

Armada hardware has a pause generation mechanism in GOP (MAC).
The GOP generate flow control frames based on an indication programmed in Ports 
Control 0 Register. There is a bit per port.
However assertion of the PortX Pause bits in the ports control 0 register only 
sends a one time pause.
To complement the function the GOP has a mechanism to periodically send pause 
control messages based on periodic counters.
This mechanism ensures that the pause is effective as long as the Appropriate 
PortX Pause is asserted.

Problem is that Packet Processor that actually can drop packets due to lack of 
resources not connected to the GOP flow control generation mechanism.
To solve this issue Armada has firmware running on CM3 CPU dedicated for Flow 
Control support.
Firmware monitors Packet Processor resources and asserts XON/XOFF by writing to 
Ports Control 0 Register.

MSS shared SRAM memory used to communicate between CM3 firmware and PP2 driver.
During init PP2 driver informs firmware about used BM pools, RXQs, congestion 
and depletion thresholds.

The pause frames are generated whenever congestion or depletion in resources is 
detected.
The back pressure is stopped when the resource reaches a sufficient level.
So the congestion/depletion and sufficient level implement a hysteresis that 
reduces the XON/XOFF toggle frequency.

Packet Processor v23 hardware introduces support for RX FIFO fill level monitor.
Patch "add PPv23 version definition" to differ between v23 and v22 hardware.
Patch "add TX FC firmware check" verifies that CM3 firmware supports Flow 
Control monitoring.

v8 --> v9
- Replace generic pool allocation with devm_ioremap_resource

v7 --> v8
- Reorder "always compare hw-version vs MVPP21" and "add PPv23 version 
definition" commits
- Typo fixes
- Remove condition fix from "add RXQ flow control configurations"

v6 --> v7
- Reduce patch set from 18 to 15 patches
 - Documentation change combined into a single patch
 - RXQ and BM size change combined into a single patch
 - Ring size change check moved into "add RXQ flow control configurations" 
commit

v5 --> v6
- No change

v4 --> v5
- Add missed Signed-off
- Fix warnings in patches 3 and 12
- Add revision requirement to warning message
- Move mss_spinlock into RXQ flow control configurations patch
- Improve FCA RXQ non occupied descriptor threshold commit message

v3 --> v4
- Remove RFC tag

v2 --> v3
- Remove inline functions
- Add PPv2.3 description into marvell-pp2.txt
- Improve mvpp2_interrupts_mask/unmask procedure
- Improve FC enable/disable procedure
- Add priv->sram_pool check
- Remove gen_pool_destroy call
- Reduce Flow Control timer to x100 faster

v1 --> v2
- Add memory requirements information
- Add EPROBE_DEFER if of_gen_pool_get return NULL
- Move Flow control configuration to mvpp2_mac_link_up callback
- Add firmware version info with Flow control support

Konstantin Porotchkin (1):
  dts: marvell: add CM3 SRAM memory to cp11x ethernet device tree

Stefan Chulski (14):
  doc: marvell: add CM3 address space and PPv2.3 description
  net: mvpp2: add CM3 SRAM memory map
  net: mvpp2: always compare hw-version vs MVPP21
  net: mvpp2: add PPv23 version definition
  net: mvpp2: increase BM pool and RXQ size
  net: mvpp2: add FCA periodic timer configurations
  net: mvpp2: add FCA RXQ non occupied descriptor threshold
  net: mvpp2: enable global flow control
  net: mvpp2: add RXQ flow control configurations
  net: mvpp2: add ethtool flow control configuration support
  net: mvpp2: add BM protection underrun feature support
  net: mvpp2: add PPv23 RX FIFO flow control
  net: mvpp2: set 802.3x GoP Flow Control mode
  net: mvpp2: add TX FC firmware check

 Documentation/devicetree/bindings/net/marvell-pp2.txt |   5 +-
 arch/arm64/boot/dts/marvell/armada-cp11x.dtsi |   2 +-
 drivers/net/ethernet/marvell/mvpp2/mvpp2.h| 124 -
 drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c   | 526 
++--
 4 files changed, 608 insertions(+), 49 deletions(-)

-- 
1.9.1



[RESEND PATCH v8 net-next 15/15] net: mvpp2: add TX FC firmware check

2021-02-07 Thread stefanc
From: Stefan Chulski 

Patch check that TX FC firmware is running in CM3.
If not, global TX FC would be disabled.

Signed-off-by: Stefan Chulski 
---
 drivers/net/ethernet/marvell/mvpp2/mvpp2.h  |  1 +
 drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c | 42 
 2 files changed, 36 insertions(+), 7 deletions(-)

diff --git a/drivers/net/ethernet/marvell/mvpp2/mvpp2.h 
b/drivers/net/ethernet/marvell/mvpp2/mvpp2.h
index 9947385..25013a4 100644
--- a/drivers/net/ethernet/marvell/mvpp2/mvpp2.h
+++ b/drivers/net/ethernet/marvell/mvpp2/mvpp2.h
@@ -829,6 +829,7 @@
 
 #define MSS_THRESHOLD_STOP 768
 #define MSS_THRESHOLD_START1024
+#define MSS_FC_MAX_TIMEOUT 5000
 
 /* RX buffer constants */
 #define MVPP2_SKB_SHINFO_SIZE \
diff --git a/drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c 
b/drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c
index 5526214..dfc2e71 100644
--- a/drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c
+++ b/drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c
@@ -932,6 +932,34 @@ static void mvpp2_bm_pool_update_fc(struct mvpp2_port 
*port,
spin_unlock_irqrestore(&port->priv->mss_spinlock, flags);
 }
 
+static int mvpp2_enable_global_fc(struct mvpp2 *priv)
+{
+   int val, timeout = 0;
+
+   /* Enable global flow control. In this stage global
+* flow control enabled, but still disabled per port.
+*/
+   val = mvpp2_cm3_read(priv, MSS_FC_COM_REG);
+   val |= FLOW_CONTROL_ENABLE_BIT;
+   mvpp2_cm3_write(priv, MSS_FC_COM_REG, val);
+
+   /* Check if Firmware running and disable FC if not*/
+   val |= FLOW_CONTROL_UPDATE_COMMAND_BIT;
+   mvpp2_cm3_write(priv, MSS_FC_COM_REG, val);
+
+   while (timeout < MSS_FC_MAX_TIMEOUT) {
+   val = mvpp2_cm3_read(priv, MSS_FC_COM_REG);
+
+   if (!(val & FLOW_CONTROL_UPDATE_COMMAND_BIT))
+   return 0;
+   usleep_range(10, 20);
+   timeout++;
+   }
+
+   priv->global_tx_fc = false;
+   return -EOPNOTSUPP;
+}
+
 /* Release buffer to BM */
 static inline void mvpp2_bm_pool_put(struct mvpp2_port *port, int pool,
 dma_addr_t buf_dma_addr,
@@ -7281,7 +7309,7 @@ static int mvpp2_probe(struct platform_device *pdev)
struct resource *res;
void __iomem *base;
int i, shared;
-   int err, val;
+   int err;
 
priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL);
if (!priv)
@@ -7509,13 +7537,13 @@ static int mvpp2_probe(struct platform_device *pdev)
goto err_port_probe;
}
 
-   /* Enable global flow control. In this stage global
-* flow control enabled, but still disabled per port.
-*/
if (priv->global_tx_fc && priv->hw_version != MVPP21) {
-   val = mvpp2_cm3_read(priv, MSS_FC_COM_REG);
-   val |= FLOW_CONTROL_ENABLE_BIT;
-   mvpp2_cm3_write(priv, MSS_FC_COM_REG, val);
+   err = mvpp2_enable_global_fc(priv);
+   if (err) {
+   dev_warn(&pdev->dev, "CM3 firmware not running, version 
should be higher than 18.09 ");
+   dev_warn(&pdev->dev, "and chip revision B0\n");
+   dev_warn(&pdev->dev, "Flow control not supported\n");
+   }
}
 
mvpp2_dbgfs_init(priv, pdev->name);
-- 
1.9.1



[RESEND PATCH v8 net-next 14/15] net: mvpp2: set 802.3x GoP Flow Control mode

2021-02-07 Thread stefanc
From: Stefan Chulski 

This patch fix GMAC TX flow control autoneg.
Flow control autoneg wrongly were disabled with enabled TX
flow control.

Signed-off-by: Stefan Chulski 
---
 drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c 
b/drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c
index 5a51697..5526214 100644
--- a/drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c
+++ b/drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c
@@ -6284,7 +6284,7 @@ static void mvpp2_gmac_config(struct mvpp2_port *port, 
unsigned int mode,
old_ctrl4 = ctrl4 = readl(port->base + MVPP22_GMAC_CTRL_4_REG);
 
ctrl0 &= ~MVPP2_GMAC_PORT_TYPE_MASK;
-   ctrl2 &= ~(MVPP2_GMAC_INBAND_AN_MASK | MVPP2_GMAC_PCS_ENABLE_MASK);
+   ctrl2 &= ~(MVPP2_GMAC_INBAND_AN_MASK | MVPP2_GMAC_PCS_ENABLE_MASK | 
MVPP2_GMAC_FLOW_CTRL_MASK);
 
/* Configure port type */
if (phy_interface_mode_is_8023z(state->interface)) {
-- 
1.9.1



[RESEND PATCH v8 net-next 13/15] net: mvpp2: add PPv23 RX FIFO flow control

2021-02-07 Thread stefanc
From: Stefan Chulski 

New FIFO flow control feature was added in PPv23.
PPv2 FIFO polled by HW and trigger pause frame if FIFO
fill level is below threshold.
FIFO HW flow control enabled with CM3 RXQ&BM flow
control with ethtool.
Current  FIFO thresholds is:
9KB for port with maximum speed 10Gb/s port
4KB for port with maximum speed 5Gb/s port
2KB for port with maximum speed 1Gb/s port

Signed-off-by: Stefan Chulski 
---
 drivers/net/ethernet/marvell/mvpp2/mvpp2.h  | 15 ++
 drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c | 53 
 2 files changed, 68 insertions(+)

diff --git a/drivers/net/ethernet/marvell/mvpp2/mvpp2.h 
b/drivers/net/ethernet/marvell/mvpp2/mvpp2.h
index 1967493..9947385 100644
--- a/drivers/net/ethernet/marvell/mvpp2/mvpp2.h
+++ b/drivers/net/ethernet/marvell/mvpp2/mvpp2.h
@@ -770,6 +770,18 @@
 #define MVPP2_TX_FIFO_THRESHOLD(kb)\
((kb) * 1024 - MVPP2_TX_FIFO_THRESHOLD_MIN)
 
+/* RX FIFO threshold in 1KB granularity */
+#define MVPP23_PORT0_FIFO_TRSH (9 * 1024)
+#define MVPP23_PORT1_FIFO_TRSH (4 * 1024)
+#define MVPP23_PORT2_FIFO_TRSH (2 * 1024)
+
+/* RX Flow Control Registers */
+#define MVPP2_RX_FC_REG(port)  (0x150 + 4 * (port))
+#define MVPP2_RX_FC_EN BIT(24)
+#define MVPP2_RX_FC_TRSH_OFFS  16
+#define MVPP2_RX_FC_TRSH_MASK  (0xFF << MVPP2_RX_FC_TRSH_OFFS)
+#define MVPP2_RX_FC_TRSH_UNIT  256
+
 /* MSS Flow control */
 #define MSS_SRAM_SIZE  0x800
 #define MSS_FC_COM_REG 0
@@ -1502,6 +1514,8 @@ struct mvpp2_bm_pool {
 
 void mvpp2_dbgfs_cleanup(struct mvpp2 *priv);
 
+void mvpp23_rx_fifo_fc_en(struct mvpp2 *priv, int port, bool en);
+
 #ifdef CONFIG_MVPP2_PTP
 int mvpp22_tai_probe(struct device *dev, struct mvpp2 *priv);
 void mvpp22_tai_tstamp(struct mvpp2_tai *tai, u32 tstamp,
@@ -1534,4 +1548,5 @@ static inline bool mvpp22_rx_hwtstamping(struct 
mvpp2_port *port)
 {
return IS_ENABLED(CONFIG_MVPP2_PTP) && port->rx_hwtstamp;
 }
+
 #endif
diff --git a/drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c 
b/drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c
index e41b173..5a51697 100644
--- a/drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c
+++ b/drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c
@@ -6537,6 +6537,8 @@ static void mvpp2_mac_link_up(struct phylink_config 
*config,
mvpp2_bm_pool_update_fc(port, port->pool_long, 
tx_pause);
mvpp2_bm_pool_update_fc(port, port->pool_short, 
tx_pause);
}
+   if (port->priv->hw_version == MVPP23)
+   mvpp23_rx_fifo_fc_en(port->priv, port->id, tx_pause);
}
 
mvpp2_port_enable(port);
@@ -7005,6 +7007,55 @@ static void mvpp22_rx_fifo_init(struct mvpp2 *priv)
mvpp2_write(priv, MVPP2_RX_FIFO_INIT_REG, 0x1);
 }
 
+/* Configure Rx FIFO Flow control thresholds */
+static void mvpp23_rx_fifo_fc_set_tresh(struct mvpp2 *priv)
+{
+   int port, val;
+
+   /* Port 0: maximum speed -10Gb/s port
+* required by spec RX FIFO threshold 9KB
+* Port 1: maximum speed -5Gb/s port
+* required by spec RX FIFO threshold 4KB
+* Port 2: maximum speed -1Gb/s port
+* required by spec RX FIFO threshold 2KB
+*/
+
+   /* Without loopback port */
+   for (port = 0; port < (MVPP2_MAX_PORTS - 1); port++) {
+   if (port == 0) {
+   val = (MVPP23_PORT0_FIFO_TRSH / MVPP2_RX_FC_TRSH_UNIT)
+   << MVPP2_RX_FC_TRSH_OFFS;
+   val &= MVPP2_RX_FC_TRSH_MASK;
+   mvpp2_write(priv, MVPP2_RX_FC_REG(port), val);
+   } else if (port == 1) {
+   val = (MVPP23_PORT1_FIFO_TRSH / MVPP2_RX_FC_TRSH_UNIT)
+   << MVPP2_RX_FC_TRSH_OFFS;
+   val &= MVPP2_RX_FC_TRSH_MASK;
+   mvpp2_write(priv, MVPP2_RX_FC_REG(port), val);
+   } else {
+   val = (MVPP23_PORT2_FIFO_TRSH / MVPP2_RX_FC_TRSH_UNIT)
+   << MVPP2_RX_FC_TRSH_OFFS;
+   val &= MVPP2_RX_FC_TRSH_MASK;
+   mvpp2_write(priv, MVPP2_RX_FC_REG(port), val);
+   }
+   }
+}
+
+/* Configure Rx FIFO Flow control thresholds */
+void mvpp23_rx_fifo_fc_en(struct mvpp2 *priv, int port, bool en)
+{
+   int val;
+
+   val = mvpp2_read(priv, MVPP2_RX_FC_REG(port));
+
+   if (en)
+   val |= MVPP2_RX_FC_EN;
+   else
+   val &= ~MVPP2_RX_FC_EN;
+
+   mvpp2_write(priv, MVPP2_RX_FC_REG(port), val);
+}
+
 static void mvpp22_tx_fifo_set_hw(struct mvpp2 *priv, int port, int size)
 {
int threshold = MVPP2_TX_FIFO_THRESHOLD(size);
@@ -7156,6 +7207,8 @@ static int mvpp2_init(struct platform_device *pdev, 
struct mvpp2 *priv)
} else {
mvpp22_rx_fifo_init(priv);
   

[RESEND PATCH v8 net-next 12/15] net: mvpp2: add BM protection underrun feature support

2021-02-07 Thread stefanc
From: Stefan Chulski 

The PP2v23 hardware supports a feature allowing to double the
size of BPPI by decreasing number of pools from 16 to 8.
Increasing of BPPI size protect BM drop from BPPI underrun.
Underrun could occurred due to stress on DDR and as result slow buffer
transition from BPPE to BPPI.
New BPPI threshold recommended by spec is:
BPPI low threshold - 640 buffers
BPPI high threshold - 832 buffers
Supported only in PPv23.

Signed-off-by: Stefan Chulski 
---
 drivers/net/ethernet/marvell/mvpp2/mvpp2.h  |  8 +
 drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c | 35 +++-
 2 files changed, 42 insertions(+), 1 deletion(-)

diff --git a/drivers/net/ethernet/marvell/mvpp2/mvpp2.h 
b/drivers/net/ethernet/marvell/mvpp2/mvpp2.h
index 9071ab6..1967493 100644
--- a/drivers/net/ethernet/marvell/mvpp2/mvpp2.h
+++ b/drivers/net/ethernet/marvell/mvpp2/mvpp2.h
@@ -324,6 +324,10 @@
 #define MVPP2_BM_HIGH_THRESH_MASK  0x7f
 #define MVPP2_BM_HIGH_THRESH_VALUE(val)((val) << \
MVPP2_BM_HIGH_THRESH_OFFS)
+#define MVPP2_BM_BPPI_HIGH_THRESH  0x1E
+#define MVPP2_BM_BPPI_LOW_THRESH   0x1C
+#define MVPP23_BM_BPPI_HIGH_THRESH 0x34
+#define MVPP23_BM_BPPI_LOW_THRESH  0x28
 #define MVPP2_BM_INTR_CAUSE_REG(pool)  (0x6240 + ((pool) * 4))
 #define MVPP2_BM_RELEASED_DELAY_MASK   BIT(0)
 #define MVPP2_BM_ALLOC_FAILED_MASK BIT(1)
@@ -352,6 +356,10 @@
 #define MVPP2_OVERRUN_ETH_DROP 0x7000
 #define MVPP2_CLS_ETH_DROP 0x7020
 
+#define MVPP22_BM_POOL_BASE_ADDR_HIGH_REG  0x6310
+#define MVPP22_BM_POOL_BASE_ADDR_HIGH_MASK 0xff
+#define MVPP23_BM_8POOL_MODE   BIT(8)
+
 /* Hit counters registers */
 #define MVPP2_CTRS_IDX 0x7040
 #define MVPP22_CTRS_TX_CTR(port, txq)  ((txq) | ((port) << 3) | BIT(7))
diff --git a/drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c 
b/drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c
index 5d80c5e..e41b173 100644
--- a/drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c
+++ b/drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c
@@ -70,6 +70,11 @@ enum mvpp2_bm_pool_log_num {
 module_param(queue_mode, int, 0444);
 MODULE_PARM_DESC(queue_mode, "Set queue_mode (single=0, multi=1)");
 
+static int bm_underrun_protect = 1;
+
+module_param(bm_underrun_protect, int, 0444);
+MODULE_PARM_DESC(bm_underrun_protect, "Set BM underrun protect feature (0-1), 
def=1");
+
 /* Utility/helper methods */
 
 void mvpp2_write(struct mvpp2 *priv, u32 offset, u32 data)
@@ -424,6 +429,21 @@ static int mvpp2_bm_pool_create(struct device *dev, struct 
mvpp2 *priv,
 
val = mvpp2_read(priv, MVPP2_BM_POOL_CTRL_REG(bm_pool->id));
val |= MVPP2_BM_START_MASK;
+
+   val &= ~MVPP2_BM_LOW_THRESH_MASK;
+   val &= ~MVPP2_BM_HIGH_THRESH_MASK;
+
+   /* Set 8 Pools BPPI threshold if BM underrun protection feature
+* was enabled
+*/
+   if (priv->hw_version == MVPP23 && bm_underrun_protect) {
+   val |= MVPP2_BM_LOW_THRESH_VALUE(MVPP23_BM_BPPI_LOW_THRESH);
+   val |= MVPP2_BM_HIGH_THRESH_VALUE(MVPP23_BM_BPPI_HIGH_THRESH);
+   } else {
+   val |= MVPP2_BM_LOW_THRESH_VALUE(MVPP2_BM_BPPI_LOW_THRESH);
+   val |= MVPP2_BM_HIGH_THRESH_VALUE(MVPP2_BM_BPPI_HIGH_THRESH);
+   }
+
mvpp2_write(priv, MVPP2_BM_POOL_CTRL_REG(bm_pool->id), val);
 
bm_pool->size = size;
@@ -592,6 +612,16 @@ static int mvpp2_bm_pools_init(struct device *dev, struct 
mvpp2 *priv)
return err;
 }
 
+/* Routine enable PPv23 8 pool mode */
+static void mvpp23_bm_set_8pool_mode(struct mvpp2 *priv)
+{
+   int val;
+
+   val = mvpp2_read(priv, MVPP22_BM_POOL_BASE_ADDR_HIGH_REG);
+   val |= MVPP23_BM_8POOL_MODE;
+   mvpp2_write(priv, MVPP22_BM_POOL_BASE_ADDR_HIGH_REG, val);
+}
+
 static int mvpp2_bm_init(struct device *dev, struct mvpp2 *priv)
 {
enum dma_data_direction dma_dir = DMA_FROM_DEVICE;
@@ -645,6 +675,9 @@ static int mvpp2_bm_init(struct device *dev, struct mvpp2 
*priv)
if (!priv->bm_pools)
return -ENOMEM;
 
+   if (priv->hw_version == MVPP23 && bm_underrun_protect)
+   mvpp23_bm_set_8pool_mode(priv);
+
err = mvpp2_bm_pools_init(dev, priv);
if (err < 0)
return err;
@@ -6491,7 +6524,7 @@ static void mvpp2_mac_link_up(struct phylink_config 
*config,
 val);
}
 
-   if (port->priv->global_tx_fc) {
+   if (port->priv->global_tx_fc && bm_underrun_protect) {
port->tx_fc = tx_pause;
if (tx_pause)
mvpp2_rxq_enable_fc(port);
-- 
1.9.1



[RESEND PATCH v8 net-next 11/15] net: mvpp2: add ethtool flow control configuration support

2021-02-07 Thread stefanc
From: Stefan Chulski 

This patch add ethtool flow control configuration support.

Tx flow control retrieved correctly by ethtool get function.
FW per port ethtool configuration capability added.

Patch also takes care about mtu change procedure, if PPv2 switch
BM pools during mtu change.

Signed-off-by: Stefan Chulski 
---
 drivers/net/ethernet/marvell/mvpp2/mvpp2.h  | 13 +++
 drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c | 98 
 2 files changed, 111 insertions(+)

diff --git a/drivers/net/ethernet/marvell/mvpp2/mvpp2.h 
b/drivers/net/ethernet/marvell/mvpp2/mvpp2.h
index 0f27be0..9071ab6 100644
--- a/drivers/net/ethernet/marvell/mvpp2/mvpp2.h
+++ b/drivers/net/ethernet/marvell/mvpp2/mvpp2.h
@@ -775,6 +775,19 @@
 #define MSS_RXQ_TRESH_REG(q, fq)   (MSS_RXQ_TRESH_BASE + (((q) + (fq)) \
* MSS_RXQ_TRESH_OFFS))
 
+#define MSS_BUF_POOL_BASE  0x40
+#define MSS_BUF_POOL_OFFS  4
+#define MSS_BUF_POOL_REG(id)   (MSS_BUF_POOL_BASE  \
+   + (id) * MSS_BUF_POOL_OFFS)
+
+#define MSS_BUF_POOL_STOP_MASK 0xFFF
+#define MSS_BUF_POOL_START_MASK(0xFFF << 
MSS_BUF_POOL_START_OFFS)
+#define MSS_BUF_POOL_START_OFFS12
+#define MSS_BUF_POOL_PORTS_MASK(0xF << MSS_BUF_POOL_PORTS_OFFS)
+#define MSS_BUF_POOL_PORTS_OFFS24
+#define MSS_BUF_POOL_PORT_OFFS(id) (0x1 << \
+   ((id) + MSS_BUF_POOL_PORTS_OFFS))
+
 #define MSS_RXQ_TRESH_START_MASK   0x
 #define MSS_RXQ_TRESH_STOP_MASK(0x << 
MSS_RXQ_TRESH_STOP_OFFS)
 #define MSS_RXQ_TRESH_STOP_OFFS16
diff --git a/drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c 
b/drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c
index 29ba62a..5d80c5e 100644
--- a/drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c
+++ b/drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c
@@ -846,6 +846,59 @@ static void mvpp2_rxq_disable_fc(struct mvpp2_port *port)
spin_unlock_irqrestore(&port->priv->mss_spinlock, flags);
 }
 
+/* Routine disable/enable flow control for BM pool condition */
+static void mvpp2_bm_pool_update_fc(struct mvpp2_port *port,
+   struct mvpp2_bm_pool *pool,
+   bool en)
+{
+   int val, cm3_state;
+   unsigned long flags;
+
+   spin_lock_irqsave(&port->priv->mss_spinlock, flags);
+
+   /* Remove Flow control enable bit to prevent race between FW and Kernel
+* If Flow control were enabled, it would be re-enabled.
+*/
+   val = mvpp2_cm3_read(port->priv, MSS_FC_COM_REG);
+   cm3_state = (val & FLOW_CONTROL_ENABLE_BIT);
+   val &= ~FLOW_CONTROL_ENABLE_BIT;
+   mvpp2_cm3_write(port->priv, MSS_FC_COM_REG, val);
+
+   /* Check if BM pool should be enabled/disable */
+   if (en) {
+   /* Set BM pool start and stop thresholds per port */
+   val = mvpp2_cm3_read(port->priv, MSS_BUF_POOL_REG(pool->id));
+   val |= MSS_BUF_POOL_PORT_OFFS(port->id);
+   val &= ~MSS_BUF_POOL_START_MASK;
+   val |= (MSS_THRESHOLD_START << MSS_BUF_POOL_START_OFFS);
+   val &= ~MSS_BUF_POOL_STOP_MASK;
+   val |= MSS_THRESHOLD_STOP;
+   mvpp2_cm3_write(port->priv, MSS_BUF_POOL_REG(pool->id), val);
+   } else {
+   /* Remove BM pool from the port */
+   val = mvpp2_cm3_read(port->priv, MSS_BUF_POOL_REG(pool->id));
+   val &= ~MSS_BUF_POOL_PORT_OFFS(port->id);
+
+   /* Zero BM pool start and stop thresholds to disable pool
+* flow control if pool empty (not used by any port)
+*/
+   if (!pool->buf_num) {
+   val &= ~MSS_BUF_POOL_START_MASK;
+   val &= ~MSS_BUF_POOL_STOP_MASK;
+   }
+
+   mvpp2_cm3_write(port->priv, MSS_BUF_POOL_REG(pool->id), val);
+   }
+
+   /* Notify Firmware that Flow control config space ready for update */
+   val = mvpp2_cm3_read(port->priv, MSS_FC_COM_REG);
+   val |= FLOW_CONTROL_UPDATE_COMMAND_BIT;
+   val |= cm3_state;
+   mvpp2_cm3_write(port->priv, MSS_FC_COM_REG, val);
+
+   spin_unlock_irqrestore(&port->priv->mss_spinlock, flags);
+}
+
 /* Release buffer to BM */
 static inline void mvpp2_bm_pool_put(struct mvpp2_port *port, int pool,
 dma_addr_t buf_dma_addr,
@@ -1176,6 +1229,16 @@ static int mvpp2_bm_update_mtu(struct net_device *dev, 
int mtu)
new_long_pool = MVPP2_BM_LONG;
 
if (new_long_pool != port->pool_long->id) {
+   if (port->tx_fc) {
+   if (pkt_size > MVPP2_BM_LONG_PKT_SIZE)
+   mvpp2_bm_pool_update_fc(port,
+

[RESEND PATCH v8 net-next 10/15] net: mvpp2: add RXQ flow control configurations

2021-02-07 Thread stefanc
From: Stefan Chulski 

This patch adds RXQ flow control configurations.
Flow control disabled by default.
Minimum ring size limited to 1024 descriptors.

Signed-off-by: Stefan Chulski 
---
 drivers/net/ethernet/marvell/mvpp2/mvpp2.h  |  35 +-
 drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c | 116 
 2 files changed, 150 insertions(+), 1 deletion(-)

diff --git a/drivers/net/ethernet/marvell/mvpp2/mvpp2.h 
b/drivers/net/ethernet/marvell/mvpp2/mvpp2.h
index e010410..0f27be0 100644
--- a/drivers/net/ethernet/marvell/mvpp2/mvpp2.h
+++ b/drivers/net/ethernet/marvell/mvpp2/mvpp2.h
@@ -766,9 +766,36 @@
 #define MSS_SRAM_SIZE  0x800
 #define MSS_FC_COM_REG 0
 #define FLOW_CONTROL_ENABLE_BITBIT(0)
+#define FLOW_CONTROL_UPDATE_COMMAND_BITBIT(31)
 #define FC_QUANTA  0x
 #define FC_CLK_DIVIDER 100
-#define MSS_THRESHOLD_STOP 768
+
+#define MSS_RXQ_TRESH_BASE 0x200
+#define MSS_RXQ_TRESH_OFFS 4
+#define MSS_RXQ_TRESH_REG(q, fq)   (MSS_RXQ_TRESH_BASE + (((q) + (fq)) \
+   * MSS_RXQ_TRESH_OFFS))
+
+#define MSS_RXQ_TRESH_START_MASK   0x
+#define MSS_RXQ_TRESH_STOP_MASK(0x << 
MSS_RXQ_TRESH_STOP_OFFS)
+#define MSS_RXQ_TRESH_STOP_OFFS16
+
+#define MSS_RXQ_ASS_BASE   0x80
+#define MSS_RXQ_ASS_OFFS   4
+#define MSS_RXQ_ASS_PER_REG4
+#define MSS_RXQ_ASS_PER_OFFS   8
+#define MSS_RXQ_ASS_PORTID_OFFS0
+#define MSS_RXQ_ASS_PORTID_MASK0x3
+#define MSS_RXQ_ASS_HOSTID_OFFS2
+#define MSS_RXQ_ASS_HOSTID_MASK0x3F
+
+#define MSS_RXQ_ASS_Q_BASE(q, fq) q) + (fq)) % MSS_RXQ_ASS_PER_REG)
 \
+ * MSS_RXQ_ASS_PER_OFFS)
+#define MSS_RXQ_ASS_PQ_BASE(q, fq) q) + (fq)) / MSS_RXQ_ASS_PER_REG) \
+  * MSS_RXQ_ASS_OFFS)
+#define MSS_RXQ_ASS_REG(q, fq) (MSS_RXQ_ASS_BASE + MSS_RXQ_ASS_PQ_BASE(q, fq))
+
+#define MSS_THRESHOLD_STOP 768
+#define MSS_THRESHOLD_START1024
 
 /* RX buffer constants */
 #define MVPP2_SKB_SHINFO_SIZE \
@@ -1026,6 +1053,9 @@ struct mvpp2 {
 
/* Global TX Flow Control config */
bool global_tx_fc;
+
+   /* Spinlocks for CM3 shared memory configuration */
+   spinlock_t mss_spinlock;
 };
 
 struct mvpp2_pcpu_stats {
@@ -1188,6 +1218,9 @@ struct mvpp2_port {
bool rx_hwtstamp;
enum hwtstamp_tx_types tx_hwtstamp_type;
struct mvpp2_hwtstamp_queue tx_hwtstamp_queue[2];
+
+   /* Firmware TX flow control */
+   bool tx_fc;
 };
 
 /* The mvpp2_tx_desc and mvpp2_rx_desc structures describe the
diff --git a/drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c 
b/drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c
index fec1c81..29ba62a 100644
--- a/drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c
+++ b/drivers/net/ethernet/marvell/mvpp2/mvpp2_main.c
@@ -742,6 +742,110 @@ static void *mvpp2_buf_alloc(struct mvpp2_port *port,
return data;
 }
 
+/* Routine enable flow control for RXQs condition */
+static void mvpp2_rxq_enable_fc(struct mvpp2_port *port)
+{
+   int val, cm3_state, host_id, q;
+   int fq = port->first_rxq;
+   unsigned long flags;
+
+   spin_lock_irqsave(&port->priv->mss_spinlock, flags);
+
+   /* Remove Flow control enable bit to prevent race between FW and Kernel
+* If Flow control was enabled, it would be re-enabled.
+*/
+   val = mvpp2_cm3_read(port->priv, MSS_FC_COM_REG);
+   cm3_state = (val & FLOW_CONTROL_ENABLE_BIT);
+   val &= ~FLOW_CONTROL_ENABLE_BIT;
+   mvpp2_cm3_write(port->priv, MSS_FC_COM_REG, val);
+
+   /* Set same Flow control for all RXQs */
+   for (q = 0; q < port->nrxqs; q++) {
+   /* Set stop and start Flow control RXQ thresholds */
+   val = MSS_THRESHOLD_START;
+   val |= (MSS_THRESHOLD_STOP << MSS_RXQ_TRESH_STOP_OFFS);
+   mvpp2_cm3_write(port->priv, MSS_RXQ_TRESH_REG(q, fq), val);
+
+   val = mvpp2_cm3_read(port->priv, MSS_RXQ_ASS_REG(q, fq));
+   /* Set RXQ port ID */
+   val &= ~(MSS_RXQ_ASS_PORTID_MASK << MSS_RXQ_ASS_Q_BASE(q, fq));
+   val |= (port->id << MSS_RXQ_ASS_Q_BASE(q, fq));
+   val &= ~(MSS_RXQ_ASS_HOSTID_MASK << (MSS_RXQ_ASS_Q_BASE(q, fq)
+   + MSS_RXQ_ASS_HOSTID_OFFS));
+
+   /* Calculate RXQ host ID:
+* In Single queue mode: Host ID equal to Host ID used for
+*   shared RX interrupt
+* In Multi queue mode: Host ID equal to number of
+*  RXQ ID / number of CoS queues
+* In Single resource mode: Host ID always equal to 0
+*/
+   if (queue_mode == MVPP2_QDIST_SINGLE_MODE)
+   host_id = port->nqvecs;
+

  1   2   3   >