Skip to content

Commit cc6216b

Browse files
committed
Merge branch 'mvpp2-tx-flow-control'
Stefan Chulski says: ==================== net: mvpp2: Add TX Flow Control support 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 ==================== Signed-off-by: David S. Miller <[email protected]>
2 parents f2fa0e5 + 9ca5e76 commit cc6216b

File tree

4 files changed

+599
-49
lines changed

4 files changed

+599
-49
lines changed

Documentation/devicetree/bindings/net/marvell-pp2.txt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
* Marvell Armada 375 Ethernet Controller (PPv2.1)
22
Marvell Armada 7K/8K Ethernet Controller (PPv2.2)
3+
Marvell CN913X Ethernet Controller (PPv2.3)
34

45
Required properties:
56

@@ -12,10 +13,11 @@ Required properties:
1213
- common controller registers
1314
- LMS registers
1415
- one register area per Ethernet port
15-
For "marvell,armada-7k-pp2", must contain the following register
16+
For "marvell,armada-7k-pp2" used by 7K/8K and CN913X, must contain the following register
1617
sets:
1718
- packet processor registers
1819
- networking interfaces registers
20+
- CM3 address space used for TX Flow Control
1921

2022
- clocks: pointers to the reference clocks for this device, consequently:
2123
- main controller clock (for both armada-375-pp2 and armada-7k-pp2)
@@ -81,7 +83,7 @@ Example for marvell,armada-7k-pp2:
8183

8284
cpm_ethernet: ethernet@0 {
8385
compatible = "marvell,armada-7k-pp22";
84-
reg = <0x0 0x100000>, <0x129000 0xb000>;
86+
reg = <0x0 0x100000>, <0x129000 0xb000>, <0x220000 0x800>;
8587
clocks = <&cpm_syscon0 1 3>, <&cpm_syscon0 1 9>,
8688
<&cpm_syscon0 1 5>, <&cpm_syscon0 1 6>, <&cpm_syscon0 1 18>;
8789
clock-names = "pp_clk", "gop_clk", "mg_clk", "mg_core_clk", "axi_clk";

arch/arm64/boot/dts/marvell/armada-cp11x.dtsi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@
5959

6060
CP11X_LABEL(ethernet): ethernet@0 {
6161
compatible = "marvell,armada-7k-pp22";
62-
reg = <0x0 0x100000>, <0x129000 0xb000>;
62+
reg = <0x0 0x100000>, <0x129000 0xb000>, <0x220000 0x800>;
6363
clocks = <&CP11X_LABEL(clk) 1 3>, <&CP11X_LABEL(clk) 1 9>,
6464
<&CP11X_LABEL(clk) 1 5>, <&CP11X_LABEL(clk) 1 6>,
6565
<&CP11X_LABEL(clk) 1 18>;

drivers/net/ethernet/marvell/mvpp2/mvpp2.h

Lines changed: 110 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,9 @@
6060
/* Top Registers */
6161
#define MVPP2_MH_REG(port) (0x5040 + 4 * (port))
6262
#define MVPP2_DSA_EXTENDED BIT(5)
63+
#define MVPP2_VER_ID_REG 0x50b0
64+
#define MVPP2_VER_PP22 0x10
65+
#define MVPP2_VER_PP23 0x11
6366

6467
/* Parser Registers */
6568
#define MVPP2_PRS_INIT_LOOKUP_REG 0x1000
@@ -292,6 +295,8 @@
292295
#define MVPP2_PON_CAUSE_TXP_OCCUP_DESC_ALL_MASK 0x3fc00000
293296
#define MVPP2_PON_CAUSE_MISC_SUM_MASK BIT(31)
294297
#define MVPP2_ISR_MISC_CAUSE_REG 0x55b0
298+
#define MVPP2_ISR_RX_ERR_CAUSE_REG(port) (0x5520 + 4 * (port))
299+
#define MVPP2_ISR_RX_ERR_CAUSE_NONOCC_MASK 0x00ff
295300

296301
/* Buffer Manager registers */
297302
#define MVPP2_BM_POOL_BASE_REG(pool) (0x6000 + ((pool) * 4))
@@ -319,6 +324,10 @@
319324
#define MVPP2_BM_HIGH_THRESH_MASK 0x7f0000
320325
#define MVPP2_BM_HIGH_THRESH_VALUE(val) ((val) << \
321326
MVPP2_BM_HIGH_THRESH_OFFS)
327+
#define MVPP2_BM_BPPI_HIGH_THRESH 0x1E
328+
#define MVPP2_BM_BPPI_LOW_THRESH 0x1C
329+
#define MVPP23_BM_BPPI_HIGH_THRESH 0x34
330+
#define MVPP23_BM_BPPI_LOW_THRESH 0x28
322331
#define MVPP2_BM_INTR_CAUSE_REG(pool) (0x6240 + ((pool) * 4))
323332
#define MVPP2_BM_RELEASED_DELAY_MASK BIT(0)
324333
#define MVPP2_BM_ALLOC_FAILED_MASK BIT(1)
@@ -347,6 +356,10 @@
347356
#define MVPP2_OVERRUN_ETH_DROP 0x7000
348357
#define MVPP2_CLS_ETH_DROP 0x7020
349358

359+
#define MVPP22_BM_POOL_BASE_ADDR_HIGH_REG 0x6310
360+
#define MVPP22_BM_POOL_BASE_ADDR_HIGH_MASK 0xff
361+
#define MVPP23_BM_8POOL_MODE BIT(8)
362+
350363
/* Hit counters registers */
351364
#define MVPP2_CTRS_IDX 0x7040
352365
#define MVPP22_CTRS_TX_CTR(port, txq) ((txq) | ((port) << 3) | BIT(7))
@@ -469,7 +482,7 @@
469482
#define MVPP22_GMAC_INT_SUM_MASK_LINK_STAT BIT(1)
470483
#define MVPP22_GMAC_INT_SUM_MASK_PTP BIT(2)
471484

472-
/* Per-port XGMAC registers. PPv2.2 only, only for GOP port 0,
485+
/* Per-port XGMAC registers. PPv2.2 and PPv2.3, only for GOP port 0,
473486
* relative to port->base.
474487
*/
475488
#define MVPP22_XLG_CTRL0_REG 0x100
@@ -506,7 +519,7 @@
506519
#define MVPP22_XLG_CTRL4_MACMODSELECT_GMAC BIT(12)
507520
#define MVPP22_XLG_CTRL4_EN_IDLE_CHECK BIT(14)
508521

509-
/* SMI registers. PPv2.2 only, relative to priv->iface_base. */
522+
/* SMI registers. PPv2.2 and PPv2.3, relative to priv->iface_base. */
510523
#define MVPP22_SMI_MISC_CFG_REG 0x1204
511524
#define MVPP22_SMI_POLLING_EN BIT(10)
512525

@@ -582,7 +595,7 @@
582595
#define MVPP2_QUEUE_NEXT_DESC(q, index) \
583596
(((index) < (q)->last_desc) ? ((index) + 1) : 0)
584597

585-
/* XPCS registers. PPv2.2 only */
598+
/* XPCS registers.PPv2.2 and PPv2.3 */
586599
#define MVPP22_MPCS_BASE(port) (0x7000 + (port) * 0x1000)
587600
#define MVPP22_MPCS_CTRL 0x14
588601
#define MVPP22_MPCS_CTRL_FWD_ERR_CONN BIT(10)
@@ -593,7 +606,16 @@
593606
#define MVPP22_MPCS_CLK_RESET_DIV_RATIO(n) ((n) << 4)
594607
#define MVPP22_MPCS_CLK_RESET_DIV_SET BIT(11)
595608

596-
/* XPCS registers. PPv2.2 only */
609+
/* FCA registers. PPv2.2 and PPv2.3 */
610+
#define MVPP22_FCA_BASE(port) (0x7600 + (port) * 0x1000)
611+
#define MVPP22_FCA_REG_SIZE 16
612+
#define MVPP22_FCA_REG_MASK 0xFFFF
613+
#define MVPP22_FCA_CONTROL_REG 0x0
614+
#define MVPP22_FCA_ENABLE_PERIODIC BIT(11)
615+
#define MVPP22_PERIODIC_COUNTER_LSB_REG (0x110)
616+
#define MVPP22_PERIODIC_COUNTER_MSB_REG (0x114)
617+
618+
/* XPCS registers. PPv2.2 and PPv2.3 */
597619
#define MVPP22_XPCS_BASE(port) (0x7400 + (port) * 0x1000)
598620
#define MVPP22_XPCS_CFG0 0x0
599621
#define MVPP22_XPCS_CFG0_RESET_DIS BIT(0)
@@ -712,8 +734,8 @@
712734
#define MVPP2_PORT_MAX_RXQ 32
713735

714736
/* Max number of Rx descriptors */
715-
#define MVPP2_MAX_RXD_MAX 1024
716-
#define MVPP2_MAX_RXD_DFLT 128
737+
#define MVPP2_MAX_RXD_MAX 2048
738+
#define MVPP2_MAX_RXD_DFLT 1024
717739

718740
/* Max number of Tx descriptors */
719741
#define MVPP2_MAX_TXD_MAX 2048
@@ -748,6 +770,66 @@
748770
#define MVPP2_TX_FIFO_THRESHOLD(kb) \
749771
((kb) * 1024 - MVPP2_TX_FIFO_THRESHOLD_MIN)
750772

773+
/* RX FIFO threshold in 1KB granularity */
774+
#define MVPP23_PORT0_FIFO_TRSH (9 * 1024)
775+
#define MVPP23_PORT1_FIFO_TRSH (4 * 1024)
776+
#define MVPP23_PORT2_FIFO_TRSH (2 * 1024)
777+
778+
/* RX Flow Control Registers */
779+
#define MVPP2_RX_FC_REG(port) (0x150 + 4 * (port))
780+
#define MVPP2_RX_FC_EN BIT(24)
781+
#define MVPP2_RX_FC_TRSH_OFFS 16
782+
#define MVPP2_RX_FC_TRSH_MASK (0xFF << MVPP2_RX_FC_TRSH_OFFS)
783+
#define MVPP2_RX_FC_TRSH_UNIT 256
784+
785+
/* MSS Flow control */
786+
#define MSS_FC_COM_REG 0
787+
#define FLOW_CONTROL_ENABLE_BIT BIT(0)
788+
#define FLOW_CONTROL_UPDATE_COMMAND_BIT BIT(31)
789+
#define FC_QUANTA 0xFFFF
790+
#define FC_CLK_DIVIDER 100
791+
792+
#define MSS_RXQ_TRESH_BASE 0x200
793+
#define MSS_RXQ_TRESH_OFFS 4
794+
#define MSS_RXQ_TRESH_REG(q, fq) (MSS_RXQ_TRESH_BASE + (((q) + (fq)) \
795+
* MSS_RXQ_TRESH_OFFS))
796+
797+
#define MSS_BUF_POOL_BASE 0x40
798+
#define MSS_BUF_POOL_OFFS 4
799+
#define MSS_BUF_POOL_REG(id) (MSS_BUF_POOL_BASE \
800+
+ (id) * MSS_BUF_POOL_OFFS)
801+
802+
#define MSS_BUF_POOL_STOP_MASK 0xFFF
803+
#define MSS_BUF_POOL_START_MASK (0xFFF << MSS_BUF_POOL_START_OFFS)
804+
#define MSS_BUF_POOL_START_OFFS 12
805+
#define MSS_BUF_POOL_PORTS_MASK (0xF << MSS_BUF_POOL_PORTS_OFFS)
806+
#define MSS_BUF_POOL_PORTS_OFFS 24
807+
#define MSS_BUF_POOL_PORT_OFFS(id) (0x1 << \
808+
((id) + MSS_BUF_POOL_PORTS_OFFS))
809+
810+
#define MSS_RXQ_TRESH_START_MASK 0xFFFF
811+
#define MSS_RXQ_TRESH_STOP_MASK (0xFFFF << MSS_RXQ_TRESH_STOP_OFFS)
812+
#define MSS_RXQ_TRESH_STOP_OFFS 16
813+
814+
#define MSS_RXQ_ASS_BASE 0x80
815+
#define MSS_RXQ_ASS_OFFS 4
816+
#define MSS_RXQ_ASS_PER_REG 4
817+
#define MSS_RXQ_ASS_PER_OFFS 8
818+
#define MSS_RXQ_ASS_PORTID_OFFS 0
819+
#define MSS_RXQ_ASS_PORTID_MASK 0x3
820+
#define MSS_RXQ_ASS_HOSTID_OFFS 2
821+
#define MSS_RXQ_ASS_HOSTID_MASK 0x3F
822+
823+
#define MSS_RXQ_ASS_Q_BASE(q, fq) ((((q) + (fq)) % MSS_RXQ_ASS_PER_REG) \
824+
* MSS_RXQ_ASS_PER_OFFS)
825+
#define MSS_RXQ_ASS_PQ_BASE(q, fq) ((((q) + (fq)) / MSS_RXQ_ASS_PER_REG) \
826+
* MSS_RXQ_ASS_OFFS)
827+
#define MSS_RXQ_ASS_REG(q, fq) (MSS_RXQ_ASS_BASE + MSS_RXQ_ASS_PQ_BASE(q, fq))
828+
829+
#define MSS_THRESHOLD_STOP 768
830+
#define MSS_THRESHOLD_START 1024
831+
#define MSS_FC_MAX_TIMEOUT 5000
832+
751833
/* RX buffer constants */
752834
#define MVPP2_SKB_SHINFO_SIZE \
753835
SKB_DATA_ALIGN(sizeof(struct skb_shared_info))
@@ -845,8 +927,8 @@ enum mvpp22_ptp_packet_format {
845927
#define MVPP22_PTP_TIMESTAMPQUEUESELECT BIT(18)
846928

847929
/* BM constants */
848-
#define MVPP2_BM_JUMBO_BUF_NUM 512
849-
#define MVPP2_BM_LONG_BUF_NUM 1024
930+
#define MVPP2_BM_JUMBO_BUF_NUM 2048
931+
#define MVPP2_BM_LONG_BUF_NUM 2048
850932
#define MVPP2_BM_SHORT_BUF_NUM 2048
851933
#define MVPP2_BM_POOL_SIZE_MAX (16*1024 - MVPP2_BM_POOL_PTR_ALIGN/4)
852934
#define MVPP2_BM_POOL_PTR_ALIGN 128
@@ -925,16 +1007,18 @@ struct mvpp2 {
9251007
/* Shared registers' base addresses */
9261008
void __iomem *lms_base;
9271009
void __iomem *iface_base;
1010+
void __iomem *cm3_base;
9281011

929-
/* On PPv2.2, each "software thread" can access the base
1012+
/* On PPv2.2 and PPv2.3, each "software thread" can access the base
9301013
* register through a separate address space, each 64 KB apart
9311014
* from each other. Typically, such address spaces will be
9321015
* used per CPU.
9331016
*/
9341017
void __iomem *swth_base[MVPP2_MAX_THREADS];
9351018

936-
/* On PPv2.2, some port control registers are located into the system
937-
* controller space. These registers are accessible through a regmap.
1019+
/* On PPv2.2 and PPv2.3, some port control registers are located into
1020+
* the system controller space. These registers are accessible
1021+
* through a regmap.
9381022
*/
9391023
struct regmap *sysctrl_base;
9401024

@@ -976,7 +1060,7 @@ struct mvpp2 {
9761060
u32 tclk;
9771061

9781062
/* HW version */
979-
enum { MVPP21, MVPP22 } hw_version;
1063+
enum { MVPP21, MVPP22, MVPP23 } hw_version;
9801064

9811065
/* Maximum number of RXQs per port */
9821066
unsigned int max_port_rxqs;
@@ -996,6 +1080,12 @@ struct mvpp2 {
9961080

9971081
/* page_pool allocator */
9981082
struct page_pool *page_pool[MVPP2_PORT_MAX_RXQ];
1083+
1084+
/* Global TX Flow Control config */
1085+
bool global_tx_fc;
1086+
1087+
/* Spinlocks for CM3 shared memory configuration */
1088+
spinlock_t mss_spinlock;
9991089
};
10001090

10011091
struct mvpp2_pcpu_stats {
@@ -1158,6 +1248,9 @@ struct mvpp2_port {
11581248
bool rx_hwtstamp;
11591249
enum hwtstamp_tx_types tx_hwtstamp_type;
11601250
struct mvpp2_hwtstamp_queue tx_hwtstamp_queue[2];
1251+
1252+
/* Firmware TX flow control */
1253+
bool tx_fc;
11611254
};
11621255

11631256
/* The mvpp2_tx_desc and mvpp2_rx_desc structures describe the
@@ -1220,7 +1313,7 @@ struct mvpp21_rx_desc {
12201313
__le32 reserved8;
12211314
};
12221315

1223-
/* HW TX descriptor for PPv2.2 */
1316+
/* HW TX descriptor for PPv2.2 and PPv2.3 */
12241317
struct mvpp22_tx_desc {
12251318
__le32 command;
12261319
u8 packet_offset;
@@ -1232,7 +1325,7 @@ struct mvpp22_tx_desc {
12321325
__le64 buf_cookie_misc;
12331326
};
12341327

1235-
/* HW RX descriptor for PPv2.2 */
1328+
/* HW RX descriptor for PPv2.2 and PPv2.3 */
12361329
struct mvpp22_rx_desc {
12371330
__le32 status;
12381331
__le16 reserved1;
@@ -1418,6 +1511,8 @@ void mvpp2_dbgfs_init(struct mvpp2 *priv, const char *name);
14181511

14191512
void mvpp2_dbgfs_cleanup(struct mvpp2 *priv);
14201513

1514+
void mvpp23_rx_fifo_fc_en(struct mvpp2 *priv, int port, bool en);
1515+
14211516
#ifdef CONFIG_MVPP2_PTP
14221517
int mvpp22_tai_probe(struct device *dev, struct mvpp2 *priv);
14231518
void mvpp22_tai_tstamp(struct mvpp2_tai *tai, u32 tstamp,
@@ -1450,4 +1545,5 @@ static inline bool mvpp22_rx_hwtstamping(struct mvpp2_port *port)
14501545
{
14511546
return IS_ENABLED(CONFIG_MVPP2_PTP) && port->rx_hwtstamp;
14521547
}
1548+
14531549
#endif

0 commit comments

Comments
 (0)