Skip to contentSkip to conversation

Cavium OCTEON-III network driver.

PATCH Superseded David Daney 6 participants 31 messages Nov 2, 2017 – Nov 5, 2017

Subsystems (4)

v1 of 8 Superseded Latest is v8 →

lore
Share & tools
lore
#0 lore raw

cover Cavium OCTEON-III network driver.

We are adding the Cavium OCTEON-III network driver. But since interacting with the input and output queues is done via special CPU local memory, we also need to add support to the MIPS/Octeon architecture code. Aren't SoCs nice in this way?

The first five patches add the SoC support needed by the driver, the last two add the driver and an entry in MAINTAINERS.

Since these touch several subsystems, I would propose merging via netdev, but defer to the maintainers if they think something else would work better.

A separate pull request was recently done by Steven Hill for the firmware required by the driver.

Carlos Munoz (5):
dt-bindings: Add Cavium Octeon Common Ethernet Interface.
MIPS: Octeon: Enable LMTDMA/LMTST operations.
MIPS: Octeon: Add a global resource manager.
MIPS: Octeon: Add Free Pointer Unit (FPA) support.
netdev: octeon-ethernet: Add Cavium Octeon III support.

David Daney (2):
MIPS: Octeon: Automatically provision CVMSEG space.
MAINTAINERS: Add entry for
drivers/net/ethernet/cavium/octeon/octeon3-*

 .../devicetree/bindings/net/cavium-bgx.txt         |   59 +
 MAINTAINERS                                        |    6 +
 arch/mips/cavium-octeon/Kconfig                    |   37 +-
 arch/mips/cavium-octeon/Makefile                   |    4 +-
 arch/mips/cavium-octeon/octeon-fpa3.c              |  363 ++++
 arch/mips/cavium-octeon/resource-mgr.c             |  362 ++++
 arch/mips/cavium-octeon/setup.c                    |   22 +-
 .../asm/mach-cavium-octeon/kernel-entry-init.h     |   20 +-
 arch/mips/include/asm/mipsregs.h                   |    2 +
 arch/mips/include/asm/octeon/octeon.h              |   47 +-
 arch/mips/include/asm/processor.h                  |    2 +-
 arch/mips/kernel/octeon_switch.S                   |    2 -
 arch/mips/kernel/unaligned.c                       |    3 +
 arch/mips/mm/tlbex.c                               |   29 +-
 drivers/net/ethernet/cavium/Kconfig                |   28 +-
 drivers/net/ethernet/cavium/octeon/Makefile        |    6 +
 .../net/ethernet/cavium/octeon/octeon3-bgx-nexus.c |  698 +++++++
 .../net/ethernet/cavium/octeon/octeon3-bgx-port.c  | 2023 +++++++++++++++++++
 drivers/net/ethernet/cavium/octeon/octeon3-core.c  | 2075 ++++++++++++++++++++
 drivers/net/ethernet/cavium/octeon/octeon3-pki.c   |  833 ++++++++
 drivers/net/ethernet/cavium/octeon/octeon3-pko.c   | 1719 ++++++++++++++++
 drivers/net/ethernet/cavium/octeon/octeon3-sso.c   |  309 +++
 drivers/net/ethernet/cavium/octeon/octeon3.h       |  411 ++++
 23 files changed, 9005 insertions(+), 55 deletions(-)
 create mode 100644 Documentation/devicetree/bindings/net/cavium-bgx.txt
 create mode 100644 arch/mips/cavium-octeon/octeon-fpa3.c
 create mode 100644 arch/mips/cavium-octeon/resource-mgr.c
 create mode 100644 drivers/net/ethernet/cavium/octeon/octeon3-bgx-nexus.c
 create mode 100644 drivers/net/ethernet/cavium/octeon/octeon3-bgx-port.c
 create mode 100644 drivers/net/ethernet/cavium/octeon/octeon3-core.c
 create mode 100644 drivers/net/ethernet/cavium/octeon/octeon3-pki.c
 create mode 100644 drivers/net/ethernet/cavium/octeon/octeon3-pko.c
 create mode 100644 drivers/net/ethernet/cavium/octeon/octeon3-sso.c
 create mode 100644 drivers/net/ethernet/cavium/octeon/octeon3.h
Signature · 1 line
2.13.6
#1 lore raw

PATCH 1/7 dt-bindings: Add Cavium Octeon Common Ethernet Interface.

From: Carlos Munoz <[email protected]>

Add bindings for Common Ethernet Interface (BGX) block.

---
 .../devicetree/bindings/net/cavium-bgx.txt         | 59 ++++++++++++++++++++++
 1 file changed, 59 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/net/cavium-bgx.txt
Documentation/devicetree/bindings/net/cavium-bgx.txt new file +59 -0
new file mode 100644
index 000000000000..9fb79f8bc17f
@@ -0,0 +1,59 @@
+* Common Ethernet Interface (BGX) block
+
+Properties:
+
+- compatible: "cavium,octeon-7890-bgx": Compatibility with all cn7xxx SOCs.
+
+- reg: The base address of the BGX block.
+
+- #address-cells: Must be <1>.
+
+- #size-cells: Must be <0>.  BGX addresses have no size component.
+
+Typically a BGX block has several children each representing an
+Ethernet interface.
+
+Example:
+
+	ethernet-mac-nexus@11800e0000000 {
+		compatible = "cavium,octeon-7890-bgx";
+		reg = <0x00011800 0xe0000000 0x00000000 0x01000000>;
+		#address-cells = <1>;
+		#size-cells = <0>;
+
+		ethernet-mac@0 {
+			...
+			reg = <0>;
+		};
+	};
+
+
+* Ethernet Interface (BGX port) connects to PKI/PKO
+
+Properties:
+
+- compatible: "cavium,octeon-7890-bgx-port": Compatibility with all cn7xxx
+  SOCs.
+
+- reg: The index of the interface within the BGX block.
+
+- local-mac-address: Mac address for the interface.
+
+- phy-handle: phandle to the phy node connected to the interface.
+
+
+* Ethernet Interface (BGX port) connects to XCV
+
+
+Properties:
+
+- compatible: "cavium,octeon-7360-xcv": Compatibility with cn73xx SOCs.
+
+- reg: The index of the interface within the BGX block.
+
+- local-mac-address: Mac address for the interface.
+
+- phy-handle: phandle to the phy node connected to the interface.
+
+- cavium,rx-clk-delay-bypass: Set to <1> to bypass the rx clock delay setting.
+  Needed by the Micrel PHY.
Signature · 1 line
2.13.6
#6 lore raw

PATCH 2/7 MIPS: Octeon: Enable LMTDMA/LMTST operations.

In reply to David Daney

From: Carlos Munoz <cmunoz-YGCgFSpz5w/[email protected]>

LMTDMA/LMTST operations move data between cores and I/O devices:

* LMTST operations can send an address and a variable length (up to 128 bytes) of data to an I/O device.
* LMTDMA operations can send an address and a variable length (up to 128) of data to the I/O device and then return a variable length (up to 128 bytes) response from the IOI device.

---
 arch/mips/cavium-octeon/setup.c       |  6 ++++++
 arch/mips/include/asm/octeon/octeon.h | 12 ++++++++++--
 2 files changed, 16 insertions(+), 2 deletions(-)
arch/mips/cavium-octeon/setup.c +6 -0
index a8034d0dcade..99e6a68bc652 100644
@@ -609,6 +609,12 @@ void octeon_user_io_init(void)
 #else
 	cvmmemctl.s.cvmsegenak = 0;
 #endif
+	if (OCTEON_IS_OCTEON3()) {
+		/* Enable LMTDMA */
+		cvmmemctl.s.lmtena = 1;
+		/* Scratch line to use for LMT operation */
+		cvmmemctl.s.lmtline = 2;
+	}
 	/* R/W If set, CVMSEG is available for loads/stores in
 	 * supervisor mode. */
 	cvmmemctl.s.cvmsegenas = 0;
arch/mips/include/asm/octeon/octeon.h +10 -2
index c99c4b6a79f4..92a17d67c1fa 100644
@@ -179,7 +179,15 @@ union octeon_cvmemctl {
 		/* RO 1 = BIST fail, 0 = BIST pass */
 		__BITFIELD_FIELD(uint64_t wbfbist:1,
 		/* Reserved */
-		__BITFIELD_FIELD(uint64_t reserved:17,
+		__BITFIELD_FIELD(uint64_t reserved_52_57:6,
+		/* When set, LMTDMA/LMTST operations are permitted */
+		__BITFIELD_FIELD(uint64_t lmtena:1,
+		/* Selects the CVMSEG LM cacheline used by LMTDMA
+		 * LMTST and wide atomic store operations.
+		 */
+		__BITFIELD_FIELD(uint64_t lmtline:6,
+		/* Reserved */
+		__BITFIELD_FIELD(uint64_t reserved_41_44:4,
 		/* OCTEON II - TLB replacement policy: 0 = bitmask LRU; 1 = NLU.
 		 * This field selects between the TLB replacement policies:
 		 * bitmask LRU or NLU. Bitmask LRU maintains a mask of
@@ -275,7 +283,7 @@ union octeon_cvmemctl {
 		/* R/W Size of local memory in cache blocks, 54 (6912
 		 * bytes) is max legal value. */
 		__BITFIELD_FIELD(uint64_t lmemsz:6,
-		;)))))))))))))))))))))))))))))))))
+		;))))))))))))))))))))))))))))))))))))
 	} s;
 };
 
Signature · 6 lines
2.13.6

--
To unsubscribe from this list: send the line "unsubscribe devicetree" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
#7 lore raw

PATCH 3/7 MIPS: Octeon: Add a global resource manager.

In reply to David Daney

From: Carlos Munoz <[email protected]>

Add a global resource manager to manage tagged pointers within bootmem allocated memory. This is used by various functional blocks in the Octeon core like the FPA, Ethernet nexus, etc.

---
 arch/mips/cavium-octeon/Makefile       |   3 +-
 arch/mips/cavium-octeon/resource-mgr.c | 362 +++++++++++++++++++++++++++++++++
 arch/mips/include/asm/octeon/octeon.h  |  18 ++
 3 files changed, 382 insertions(+), 1 deletion(-)
 create mode 100644 arch/mips/cavium-octeon/resource-mgr.c
arch/mips/cavium-octeon/Makefile +2 -1
index 7c02e542959a..0a299ab8719f 100644
@@ -9,7 +9,8 @@
 # Copyright (C) 2005-2009 Cavium Networks
 #
 
-obj-y := cpu.o setup.o octeon-platform.o octeon-irq.o csrc-octeon.o
+obj-y := cpu.o setup.o octeon-platform.o octeon-irq.o csrc-octeon.o \
+	 resource-mgr.o
 obj-y += dma-octeon.o
 obj-y += octeon-memcpy.o
 obj-y += executive/
arch/mips/cavium-octeon/resource-mgr.c new file +362 -0

362 lines not on this page · raw message

arch/mips/include/asm/octeon/octeon.h +18 -0
index 92a17d67c1fa..0411efdb465c 100644
@@ -346,6 +346,24 @@ void octeon_mult_restore3_end(void);
 void octeon_mult_restore2(void);
 void octeon_mult_restore2_end(void);
 
+/*
+ * This definition must be kept in sync with the one in
+ * cvmx-global-resources.c
+ */
+struct global_resource_tag {
+	uint64_t lo;
+	uint64_t hi;
+};
+
+void res_mgr_free(struct global_resource_tag tag, int inst);
+void res_mgr_free_range(struct global_resource_tag tag, const int *inst,
+			int req_cnt);
+int res_mgr_alloc(struct global_resource_tag tag, int req_inst,
+		  bool use_last_avail);
+int res_mgr_alloc_range(struct global_resource_tag tag, int req_inst,
+			int req_cnt, bool use_last_avail, int *inst);
+int res_mgr_create_resource(struct global_resource_tag tag, int inst_cnt);
+
 /**
  * Read a 32bit value from the Octeon NPI register space
  *
Signature · 1 line
2.13.6
#11 lore raw

PATCH 4/7 MIPS: Octeon: Add Free Pointer Unit (FPA) support.

In reply to David Daney

From: Carlos Munoz <cmunoz-YGCgFSpz5w/[email protected]>

Quoted 1 line

From the hardware user manual: "The FPA is a unit that maintains

pools of pointers to free L2/DRAM memory. To provide QoS, the pools are referenced indirectly through 1024 auras. Both core software and hardware units allocate and free pointers."

---
 arch/mips/cavium-octeon/Kconfig       |  10 +
 arch/mips/cavium-octeon/Makefile      |   1 +
 arch/mips/cavium-octeon/octeon-fpa3.c | 363 ++++++++++++++++++++++++++++++++++
 arch/mips/include/asm/octeon/octeon.h |  15 ++
 4 files changed, 389 insertions(+)
 create mode 100644 arch/mips/cavium-octeon/octeon-fpa3.c
arch/mips/cavium-octeon/Kconfig +10 -0
index 5c0b56203bae..211ef5b57214 100644
@@ -86,4 +86,14 @@ config OCTEON_ILM
 	  To compile this driver as a module, choose M here.  The module
 	  will be called octeon-ilm
 
+config OCTEON_FPA3
+	tristate "Octeon III fpa driver"
+	default "n"
+	depends on CPU_CAVIUM_OCTEON
+	help
+	  This option enables a Octeon III driver for the Free Pool Unit (FPA).
+	  The FPA is a hardware unit that manages pools of pointers to free
+	  L2/DRAM memory. This driver provides an interface to reserve,
+	  initialize, and fill fpa pools.
+
 endif # CAVIUM_OCTEON_SOC
arch/mips/cavium-octeon/Makefile +1 -0
index 0a299ab8719f..0ef967399702 100644
@@ -20,3 +20,4 @@ obj-$(CONFIG_MTD)		      += flash_setup.o
 obj-$(CONFIG_SMP)		      += smp.o
 obj-$(CONFIG_OCTEON_ILM)	      += oct_ilm.o
 obj-$(CONFIG_USB)		      += octeon-usb.o
+obj-$(CONFIG_OCTEON_FPA3)	      += octeon-fpa3.o
arch/mips/cavium-octeon/octeon-fpa3.c new file +363 -0

363 lines not on this page · raw message

arch/mips/include/asm/octeon/octeon.h +15 -0
index 0411efdb465c..d184592e6515 100644
@@ -10,6 +10,7 @@
 
 #include <asm/octeon/cvmx.h>
 #include <asm/bitfield.h>
+#include <linux/slab.h>
 
 extern uint64_t octeon_bootmem_alloc_range_phys(uint64_t size,
 						uint64_t alignment,
@@ -364,6 +365,20 @@ int res_mgr_alloc_range(struct global_resource_tag tag, int req_inst,
 			int req_cnt, bool use_last_avail, int *inst);
 int res_mgr_create_resource(struct global_resource_tag tag, int inst_cnt);
 
+#if IS_ENABLED(CONFIG_OCTEON_FPA3)
+int octeon_fpa3_init(int node);
+int octeon_fpa3_pool_init(int node, int pool_num, int *pool, void **pool_stack,
+			  int num_ptrs);
+int octeon_fpa3_aura_init(int node, int pool, int aura_num, int *aura,
+			  int num_bufs, unsigned int limit);
+int octeon_fpa3_mem_fill(int node, struct kmem_cache *cache, int aura,
+			 int num_bufs);
+void octeon_fpa3_free(u64 node, int aura, const void *buf);
+void *octeon_fpa3_alloc(u64 node, int aura);
+void octeon_fpa3_release_pool(int node, int pool);
+void octeon_fpa3_release_aura(int node, int aura);
+#endif
+
 /**
  * Read a 32bit value from the Octeon NPI register space
  *
Signature · 6 lines
2.13.6

--
To unsubscribe from this list: send the line "unsubscribe devicetree" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
#17 lore raw

PATCH 5/7 MIPS: Octeon: Automatically provision CVMSEG space.

In reply to David Daney

Remove CONFIG_CAVIUM_OCTEON_CVMSEG_SIZE and automatically calculate the amount of CVMSEG space needed.

1st 128-bytes: Use by IOBDMA
2nd 128-bytes: Reserved by kernel for scratch/TLS emulation. 3rd 128-bytes: OCTEON-III LMTLINE

New config variable CONFIG_CAVIUM_OCTEON_EXTRA_CVMSEG provisions additional lines, defaults to zero.

---
 arch/mips/cavium-octeon/Kconfig                    | 27 ++++++++++++--------
 arch/mips/cavium-octeon/setup.c                    | 16 ++++++------
 .../asm/mach-cavium-octeon/kernel-entry-init.h     | 20 +++++++++------
 arch/mips/include/asm/mipsregs.h                   |  2 ++
 arch/mips/include/asm/octeon/octeon.h              |  2 ++
 arch/mips/include/asm/processor.h                  |  2 +-
 arch/mips/kernel/octeon_switch.S                   |  2 --
 arch/mips/kernel/unaligned.c                       |  3 +++
 arch/mips/mm/tlbex.c                               | 29 ++++++----------------
 9 files changed, 52 insertions(+), 51 deletions(-)
arch/mips/cavium-octeon/Kconfig +16 -11
index 211ef5b57214..fc6a1b44605b 100644
@@ -10,21 +10,26 @@ config CAVIUM_CN63XXP1
 	  non-CN63XXP1 hardware, so it is recommended to select "n"
 	  unless it is known the workarounds are needed.
 
-config CAVIUM_OCTEON_CVMSEG_SIZE
-	int "Number of L1 cache lines reserved for CVMSEG memory"
-	range 0 54
-	default 1
-	help
-	  CVMSEG LM is a segment that accesses portions of the dcache as a
-	  local memory; the larger CVMSEG is, the smaller the cache is.
-	  This selects the size of CVMSEG LM, which is in cache blocks. The
-	  legally range is from zero to 54 cache blocks (i.e. CVMSEG LM is
-	  between zero and 6192 bytes).
-
 endif # CPU_CAVIUM_OCTEON
 
 if CAVIUM_OCTEON_SOC
 
+config CAVIUM_OCTEON_EXTRA_CVMSEG
+	int "Number of extra L1 cache lines reserved for CVMSEG memory"
+	range 0 50
+	default 0
+	help
+	  CVMSEG LM is a segment that accesses portions of the dcache
+	  as a local memory; the larger CVMSEG is, the smaller the
+	  cache is.  The kernel uses two or three blocks (one for TLB
+	  exception handlers, one for driver IOBDMA operations, and on
+	  models that need it, one for LMTDMA operations). This
+	  selects an optional extra number of CVMSEG lines for use by
+	  other software.
+
+	  Normally no extra lines are required, and this parameter
+	  should be set to zero.
+
 config CAVIUM_OCTEON_LOCK_L2
 	bool "Lock often used kernel code in the L2"
 	default "y"
arch/mips/cavium-octeon/setup.c +9 -7
index 99e6a68bc652..51c4d3c3cada 100644
@@ -68,6 +68,12 @@ extern void pci_console_init(const char *arg);
 static unsigned long long max_memory = ULLONG_MAX;
 static unsigned long long reserve_low_mem;
 
+/*
+ * modified in hernel-entry-init.h, must have an initial value to keep
+ * it from being clobbered when bss is zeroed.
+ */
+u32 octeon_cvmseg_lines = 2;
+
 DEFINE_SEMAPHORE(octeon_bootbus_sem);
 EXPORT_SYMBOL(octeon_bootbus_sem);
 
@@ -604,11 +610,7 @@ void octeon_user_io_init(void)
 
 	/* R/W If set, CVMSEG is available for loads/stores in
 	 * kernel/debug mode. */
-#if CONFIG_CAVIUM_OCTEON_CVMSEG_SIZE > 0
 	cvmmemctl.s.cvmsegenak = 1;
-#else
-	cvmmemctl.s.cvmsegenak = 0;
-#endif
 	if (OCTEON_IS_OCTEON3()) {
 		/* Enable LMTDMA */
 		cvmmemctl.s.lmtena = 1;
@@ -626,9 +628,9 @@ void octeon_user_io_init(void)
 
 	/* Setup of CVMSEG is done in kernel-entry-init.h */
 	if (smp_processor_id() == 0)
-		pr_notice("CVMSEG size: %d cache lines (%d bytes)\n",
-			  CONFIG_CAVIUM_OCTEON_CVMSEG_SIZE,
-			  CONFIG_CAVIUM_OCTEON_CVMSEG_SIZE * 128);
+		pr_notice("CVMSEG size: %u cache lines (%u bytes)\n",
+			  octeon_cvmseg_lines,
+			  octeon_cvmseg_lines * 128);
 
 	if (octeon_has_feature(OCTEON_FEATURE_FAU)) {
 		union cvmx_iob_fau_timeout fau_timeout;
arch/mips/include/asm/mach-cavium-octeon/kernel-entry-init.h +12 -8
index c38b38ce5a3d..cdcca60978a2 100644
@@ -26,11 +26,18 @@
 	# a3 = address of boot descriptor block
 	.set push
 	.set arch=octeon
+	mfc0	v1, CP0_PRID_REG
+	andi	v1, 0xff00
+	li	v0, 0x9500		# cn78XX or later
+	subu	v1, v1, v0
+	li	t2, 2 + CONFIG_CAVIUM_OCTEON_EXTRA_CVMSEG
+	bltz	v1, 1f
+	addiu	t2, 1			# t2 has cvmseg_size
+1:
 	# Read the cavium mem control register
 	dmfc0	v0, CP0_CVMMEMCTL_REG
 	# Clear the lower 6 bits, the CVMSEG size
-	dins	v0, $0, 0, 6
-	ori	v0, CONFIG_CAVIUM_OCTEON_CVMSEG_SIZE
+	dins	v0, t2, 0, 6
 	dmtc0	v0, CP0_CVMMEMCTL_REG	# Write the cavium mem control register
 	dmfc0	v0, CP0_CVMCTL_REG	# Read the cavium control register
 	# Disable unaligned load/store support but leave HW fixup enabled
@@ -70,7 +77,7 @@
 	# Flush dcache after config change
 	cache	9, 0($0)
 	# Zero all of CVMSEG to make sure parity is correct
-	dli	v0, CONFIG_CAVIUM_OCTEON_CVMSEG_SIZE
+	move	v0, t2
 	dsll	v0, 7
 	beqz	v0, 2f
 1:	dsubu	v0, 8
@@ -126,12 +133,7 @@
 	LONG_L	sp, (t0)
 	# Set the SP global variable to zero so the master knows we've started
 	LONG_S	zero, (t0)
-#ifdef __OCTEON__
-	syncw
-	syncw
-#else
 	sync
-#endif
 	# Jump to the normal Linux SMP entry point
 	j   smp_bootstrap
 	nop
@@ -148,6 +150,8 @@
 
 #endif /* CONFIG_SMP */
 octeon_main_processor:
+	dla	v0, octeon_cvmseg_lines
+	sw	t2, 0(v0)
 	.set pop
 .endm
 
arch/mips/include/asm/mipsregs.h +2 -0
index a6810923b3f0..df7654d7333d 100644
@@ -1126,6 +1126,8 @@
 #define FPU_CSR_RD	0x3	/* towards -Infinity */
 
 
+#define CAVIUM_OCTEON_SCRATCH_OFFSET (2 * 128 - 16 - 32768)
+
 #ifndef __ASSEMBLY__
 
 /*
arch/mips/include/asm/octeon/octeon.h +2 -0
index d184592e6515..02eb194b2cdc 100644
@@ -392,6 +392,8 @@ static inline uint32_t octeon_npi_read32(uint64_t address)
 
 extern struct cvmx_bootinfo *octeon_bootinfo;
 
+extern u32 octeon_cvmseg_lines;
+
 extern uint64_t octeon_bootloader_entry_addr;
 
 extern void (*octeon_irq_setup_secondary)(void);
arch/mips/include/asm/processor.h +1 -1
index 95b8c471f572..3d264008afcb 100644
@@ -216,7 +216,7 @@ struct octeon_cop2_state {
 	.cp2			= {0,},
 
 struct octeon_cvmseg_state {
-	unsigned long cvmseg[CONFIG_CAVIUM_OCTEON_CVMSEG_SIZE]
+	unsigned long cvmseg[CONFIG_CAVIUM_OCTEON_EXTRA_CVMSEG + 3]
 			    [cpu_dcache_line_size() / sizeof(unsigned long)];
 };
 
arch/mips/kernel/octeon_switch.S +0 -2
index e42113fe2762..4f56902d5ee7 100644
@@ -29,7 +29,6 @@
 	cpu_save_nonscratch a0
 	LONG_S	ra, THREAD_REG31(a0)
 
-#if CONFIG_CAVIUM_OCTEON_CVMSEG_SIZE > 0
 	/* Check if we need to store CVMSEG state */
 	dmfc0	t0, $11,7	/* CvmMemCtl */
 	bbit0	t0, 6, 3f	/* Is user access enabled? */
@@ -58,7 +57,6 @@
 	dmfc0	t0, $11,7	/* CvmMemCtl */
 	xori	t0, t0, 0x40	/* Bit 6 is CVMSEG user enable */
 	dmtc0	t0, $11,7	/* CvmMemCtl */
-#endif
 3:
 
 #if defined(CONFIG_CC_STACKPROTECTOR) && !defined(CONFIG_SMP)
arch/mips/kernel/unaligned.c +3 -0
index 2d0b912f9e3e..610f9b4ccdae 100644
@@ -2281,6 +2281,9 @@ static void emulate_load_store_MIPS16e(struct pt_regs *regs, void __user * addr)
 	force_sig(SIGILL, current);
 }
 
+#ifdef CONFIG_CPU_CAVIUM_OCTEON
+#include <asm/octeon/octeon.h>
+#endif
 asmlinkage void do_ade(struct pt_regs *regs)
 {
 	enum ctx_state prev_state;
arch/mips/mm/tlbex.c +7 -22
index 79b9f2ad3ff5..3d3dfba465ae 100644
@@ -115,33 +115,17 @@ static int use_lwx_insns(void)
 		return 0;
 	}
 }
-#if defined(CONFIG_CAVIUM_OCTEON_CVMSEG_SIZE) && \
-    CONFIG_CAVIUM_OCTEON_CVMSEG_SIZE > 0
-static bool scratchpad_available(void)
-{
-	return true;
-}
-static int scratchpad_offset(int i)
-{
-	/*
-	 * CVMSEG starts at address -32768 and extends for
-	 * CAVIUM_OCTEON_CVMSEG_SIZE 128 byte cache lines.
-	 */
-	i += 1; /* Kernel use starts at the top and works down. */
-	return CONFIG_CAVIUM_OCTEON_CVMSEG_SIZE * 128 - (8 * i) - 32768;
-}
-#else
-static bool scratchpad_available(void)
-{
-	return false;
-}
+
 static int scratchpad_offset(int i)
 {
+	if (IS_ENABLED(CONFIG_CPU_CAVIUM_OCTEON))
+		return (CAVIUM_OCTEON_SCRATCH_OFFSET - (8 * i));
+
 	BUG();
 	/* Really unreachable, but evidently some GCC want this. */
 	return 0;
 }
-#endif
+
 /*
  * Found by experiment: At least some revisions of the 4kc throw under
  * some circumstances a machine check exception, triggered by invalid
@@ -1302,7 +1286,8 @@ static void build_r4000_tlb_refill_handler(void)
 	memset(relocs, 0, sizeof(relocs));
 	memset(final_handler, 0, sizeof(final_handler));
 
-	if (IS_ENABLED(CONFIG_64BIT) && (scratch_reg >= 0 || scratchpad_available()) && use_bbit_insns()) {
+	if (IS_ENABLED(CONFIG_64BIT) && use_bbit_insns() &&
+	   (scratch_reg >= 0 || IS_ENABLED(CONFIG_CPU_CAVIUM_OCTEON))) {
 		htlb_info = build_fast_tlb_refill_handler(&p, &l, &r, K0, K1,
 							  scratch_reg);
 		vmalloc_mode = refill_scratch;
Signature · 1 line
2.13.6
#19 lore raw

PATCH 6/7 netdev: octeon-ethernet: Add Cavium Octeon III support.

In reply to David Daney

From: Carlos Munoz <[email protected]>

The Cavium OCTEON cn78xx and cn73xx SoCs have network packet I/O hardware that is significantly different from previous generations of the family.

Add a new driver for this hardware. The Ethernet MAC is called BGX on these devices. Common code for the MAC is in octeon3-bgx-port.c. Four of these BGX MACs are grouped together and managed as a group by octeon3-bgx-nexus.c. Ingress packet classification is done by the PKI unit initialized in octeon3-pki.c. Queue management is done in the SSO, initialized by octeon3-sso.c. Egress is handled by the PKO, initialized in octeon3-pko.c.

---
 drivers/net/ethernet/cavium/Kconfig                |   28 +-
 drivers/net/ethernet/cavium/octeon/Makefile        |    6 +
 .../net/ethernet/cavium/octeon/octeon3-bgx-nexus.c |  698 +++++++
 .../net/ethernet/cavium/octeon/octeon3-bgx-port.c  | 2023 +++++++++++++++++++
 drivers/net/ethernet/cavium/octeon/octeon3-core.c  | 2075 ++++++++++++++++++++
 drivers/net/ethernet/cavium/octeon/octeon3-pki.c   |  833 ++++++++
 drivers/net/ethernet/cavium/octeon/octeon3-pko.c   | 1719 ++++++++++++++++
 drivers/net/ethernet/cavium/octeon/octeon3-sso.c   |  309 +++
 drivers/net/ethernet/cavium/octeon/octeon3.h       |  411 ++++
 9 files changed, 8101 insertions(+), 1 deletion(-)
 create mode 100644 drivers/net/ethernet/cavium/octeon/octeon3-bgx-nexus.c
 create mode 100644 drivers/net/ethernet/cavium/octeon/octeon3-bgx-port.c
 create mode 100644 drivers/net/ethernet/cavium/octeon/octeon3-core.c
 create mode 100644 drivers/net/ethernet/cavium/octeon/octeon3-pki.c
 create mode 100644 drivers/net/ethernet/cavium/octeon/octeon3-pko.c
 create mode 100644 drivers/net/ethernet/cavium/octeon/octeon3-sso.c
 create mode 100644 drivers/net/ethernet/cavium/octeon/octeon3.h
drivers/net/ethernet/cavium/Kconfig +27 -1
index 63be75eb34d2..366c0b238b76 100644
@@ -4,7 +4,7 @@
 
 config NET_VENDOR_CAVIUM
 	bool "Cavium ethernet drivers"
-	depends on PCI
+	depends on PCI || CAVIUM_OCTEON_SOC
 	default y
 	---help---
 	  Select this option if you want enable Cavium network support.
@@ -87,4 +87,30 @@ config LIQUIDIO_VF
 	  will be called liquidio_vf. MSI-X interrupt support is required
 	  for this driver to work correctly
 
+config OCTEON3_BGX_NEXUS
+	tristate
+	depends on CAVIUM_OCTEON_SOC
+
+config OCTEON3_BGX_PORT
+	tristate "Cavium Octeon III BGX port support"
+	depends on CAVIUM_OCTEON_SOC
+	select OCTEON3_BGX_NEXUS
+	select OCTEON3_COMMON_NEXUS
+	---help---
+	  This driver adds support for Cavium Octeon III BGX ports. BGX ports
+	  support sgmii, rgmii, xaui, rxaui, xlaui, xfi, 10KR and 40KR modes.
+
+	  Say Y to use the management port on Octeon III boards or to use
+	  any other ethernet port.
+
+config OCTEON3_ETHERNET
+	tristate "Cavium OCTEON III PKI/PKO Ethernet support"
+	depends on CAVIUM_OCTEON_SOC
+	select OCTEON_BGX_PORT
+	select OCTEON_FPA3
+	select FW_LOADER
+	---help---
+	  Support for 'BGX' Ethernet via PKI/PKO units.  No support
+	  for cn70xx chips (use OCTEON_ETHERNET for cn70xx).
+
 endif # NET_VENDOR_CAVIUM
drivers/net/ethernet/cavium/octeon/Makefile +6 -0
index efa41c1d91c5..1eacab1d8dad 100644
@@ -3,3 +3,9 @@
 #
 
 obj-$(CONFIG_OCTEON_MGMT_ETHERNET)	+= octeon_mgmt.o
+obj-$(CONFIG_OCTEON3_BGX_PORT)		+= octeon3-bgx-port.o
+obj-$(CONFIG_OCTEON3_BGX_NEXUS)		+= octeon3-bgx-nexus.o
+obj-$(CONFIG_OCTEON3_ETHERNET)		+= octeon3-ethernet.o
+
+octeon3-ethernet-objs += octeon3-core.o octeon3-pki.o octeon3-sso.o \
+			 octeon3-pko.o
drivers/net/ethernet/cavium/octeon/octeon3-bgx-nexus.c new file +698 -0

698 lines not on this page · raw message

drivers/net/ethernet/cavium/octeon/octeon3-bgx-port.c new file +2023 -0

2,023 lines not on this page · raw message

drivers/net/ethernet/cavium/octeon/octeon3-core.c new file +2075 -0

232 lines not on this page · raw message

drivers/net/ethernet/cavium/octeon/octeon3-pki.c new file +833 -0

833 lines not on this page · raw message

drivers/net/ethernet/cavium/octeon/octeon3-pko.c new file +1719 -0

1,719 lines not on this page · raw message

drivers/net/ethernet/cavium/octeon/octeon3-sso.c new file +309 -0

309 lines not on this page · raw message

drivers/net/ethernet/cavium/octeon/octeon3.h new file +411 -0

411 lines not on this page · raw message

The rest of this diff is not shown. View the raw message.

Signature · 1 line
2.13.6

Part of the diff is not shown here. View the raw message.

#30 lore raw

PATCH 7/7 MAINTAINERS: Add entry for drivers/net/ethernet/cavium/octeon/octeon3-*

In reply to David Daney
---
 MAINTAINERS | 6 ++++++
 1 file changed, 6 insertions(+)
MAINTAINERS +6 -0
index 9a24f56e0451..142af33adc35 100644
@@ -3212,6 +3212,12 @@ W:	http://www.cavium.com
 S:	Supported
 F:	drivers/mmc/host/cavium*
 
+CAVIUM OCTEON-III NETWORK DRIVER
+M:	David Daney <[email protected]>
+L:	[email protected]
+S:	Supported
+F:	drivers/net/ethernet/cavium/octeon/octeon3-*
+
 CAVIUM OCTEON-TX CRYPTO DRIVER
 M:	George Cherian <[email protected]>
 L:	[email protected]
Signature · 1 line
2.13.6
#2 lore raw

Re: [PATCH 1/7] dt-bindings: Add Cavium Octeon Common Ethernet Interface.

In reply to David Daney
Quoted 8 lines · David Daney

From: Carlos Munoz <[email protected]>

Add bindings for Common Ethernet Interface (BGX) block.

---

[snip]

Documentation/devicetree/bindings/net/cavium-bgx.txt line 59

Quoted 12 lines
Documentation/devicetree/bindings/net/cavium-bgx.txt new file +12 -0
+Properties:
+
+- compatible: "cavium,octeon-7360-xcv": Compatibility with cn73xx SOCs.
+
+- reg: The index of the interface within the BGX block.
+
+- local-mac-address: Mac address for the interface.
+
+- phy-handle: phandle to the phy node connected to the interface.
+
+- cavium,rx-clk-delay-bypass: Set to <1> to bypass the rx clock delay setting.
+  Needed by the Micrel PHY.

Is not that implied by an appropriate "phy-mode" property already?

Signature · 1 line
Florian
#3 lore raw

Re: [PATCH 1/7] dt-bindings: Add Cavium Octeon Common Ethernet Interface.

Quoted 10 lines · Florian Fainelli
Quoted 8 lines · David Daney

From: Carlos Munoz <[email protected]>

Add bindings for Common Ethernet Interface (BGX) block.

---

[snip]

Quoted 14 lines

Documentation/devicetree/bindings/net/cavium-bgx.txt line 59

Quoted 12 lines
Documentation/devicetree/bindings/net/cavium-bgx.txt new file +12 -0
+Properties:
+
+- compatible: "cavium,octeon-7360-xcv": Compatibility with cn73xx SOCs.
+
+- reg: The index of the interface within the BGX block.
+
+- local-mac-address: Mac address for the interface.
+
+- phy-handle: phandle to the phy node connected to the interface.
+
+- cavium,rx-clk-delay-bypass: Set to <1> to bypass the rx clock delay setting.
+  Needed by the Micrel PHY.

Is not that implied by an appropriate "phy-mode" property already?

I think you are correct. That string never appears in the source code, so I am going to remove that property from the binding document for the next revision of the patch set.

Thanks,
David Daney

#12 lore raw

Re: [PATCH 4/7] MIPS: Octeon: Add Free Pointer Unit (FPA) support.

In reply to David Daney

Le 11/01/17 à 17:36, David Daney a écrit :

Quoted 6 lines

From: Carlos Munoz <[email protected]>

From the hardware user manual: "The FPA is a unit that maintains pools of pointers to free L2/DRAM memory. To provide QoS, the pools are referenced indirectly through 1024 auras. Both core software and hardware units allocate and free pointers."

This looks like a possibly similar implement to what drivers/net/ethernet/marvell/mvneta_bm.c, can you see if you can make any use of genpool_* and include/net/hwbm.h here as well?

Signature · 1 line
Florian
#8 lore raw

Re: [PATCH 3/7] MIPS: Octeon: Add a global resource manager.

In reply to David Daney
Quoted 23 lines
arch/mips/cavium-octeon/resource-mgr.c new file +23 -0
+static void res_mgr_lock(void)
+{
+	unsigned int tmp;
+	u64 lock = (u64)&res_mgr_info->rlock;
+
+	__asm__ __volatile__(
+		".set noreorder\n"
+		"1: ll   %[tmp], 0(%[addr])\n"
+		"   bnez %[tmp], 1b\n"
+		"   li   %[tmp], 1\n"
+		"   sc   %[tmp], 0(%[addr])\n"
+		"   beqz %[tmp], 1b\n"
+		"   nop\n"
+		".set reorder\n" :
+		[tmp] "=&r"(tmp) :
+		[addr] "r"(lock) :
+		"memory");
+}
+
+static void res_mgr_unlock(void)
+{
+	u64 lock = (u64)&res_mgr_info->rlock;
+

arch/mips/cavium-octeon/resource-mgr.c line 73

Quoted 10 lines
arch/mips/cavium-octeon/resource-mgr.c new file +10 -0
+	/* Wait until all resource operations finish before unlocking. */
+	mb();
+	__asm__ __volatile__(
+		"sw $0, 0(%[addr])\n" : :
+		[addr] "r"(lock) :
+		"memory");
+
+	/* Force a write buffer flush. */
+	mb();
+}

It would be good to add some justification for using your own locks, rather than standard linux locks.

Is there anything specific to your hardware in this resource manager? I'm just wondering if this should be generic, put somewhere in lib. Or maybe there is already something generic, and you should be using it, not re-inventing the wheel again.

Andrew
--
To unsubscribe from this list: send the line "unsubscribe devicetree" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html

#20 lore raw

Re: [PATCH 6/7] netdev: octeon-ethernet: Add Cavium Octeon III support.

In reply to David Daney
Quoted 48 lines
drivers/net/ethernet/cavium/octeon/octeon3-bgx-nexus.c new file +48 -0
+static int bgx_probe(struct platform_device *pdev)
+{
+	struct mac_platform_data platform_data;
+	const __be32 *reg;
+	u32 port;
+	u64 addr;
+	struct device_node *child;
+	struct platform_device *new_dev;
+	struct platform_device *pki_dev;
+	int numa_node, interface;
+	int i;
+	int r = 0;
+	char id[64];
+	u64 data;
+
+	reg = of_get_property(pdev->dev.of_node, "reg", NULL);
+	addr = of_translate_address(pdev->dev.of_node, reg);
+	interface = (addr >> 24) & 0xf;
+	numa_node = (addr >> 36) & 0x7;
+
+	/* Assign 8 CAM entries per LMAC */
+	for (i = 0; i < 32; i++) {
+		data = i >> 3;
+		oct_csr_write(data, BGX_CMR_RX_ADRX_CAM(numa_node, interface, i));
+	}
+
+	for_each_available_child_of_node(pdev->dev.of_node, child) {
+		snprintf(id, sizeof(id), "%llx.%u.ethernet-mac",
+			 (unsigned long long)addr, port);
+		new_dev = of_platform_device_create(child, id, &pdev->dev);
+		if (!new_dev) {
+			dev_err(&pdev->dev, "Error creating %s\n", id);
+			continue;
+		}
+		platform_data.mac_type = BGX_MAC;
+		platform_data.numa_node = numa_node;
+		platform_data.interface = interface;
+		platform_data.port = port;
+		if (is_xcv)
+			platform_data.src_type = XCV;
+		else
+			platform_data.src_type = QLM;
+
+		/* Add device to the list of created devices so we can remove it
+		 * on exit.
+		 */
+		pdev_item = kmalloc(sizeof(*pdev_item), GFP_KERNEL);
+		pdev_item->pdev = new_dev;

drivers/net/ethernet/cavium/octeon/octeon3-bgx-nexus.c line 210

Quoted 10 lines
drivers/net/ethernet/cavium/octeon/octeon3-bgx-nexus.c new file +10 -0
+		mutex_lock(&pdev_list_lock);
+		list_add(&pdev_item->list, &pdev_list);
+		mutex_unlock(&pdev_list_lock);
+
+		i = atomic_inc_return(&pki_id);
+		pki_dev = platform_device_register_data(&new_dev->dev,
+							is_mix ? "octeon_mgmt" : "ethernet-mac-pki",
+							i, &platform_data, sizeof(platform_data));
+		dev_info(&pdev->dev, "Created %s %u: %p\n",
+			 is_mix ? "MIX" : "PKI", pki_dev->id, pki_dev);

Is there any change of these ethernet ports being used to connect to an Ethernet switch. We have had issues in the past with these sort of platform devices combined with DSA.

Andrew

#4 lore raw

Re: [PATCH 1/7] dt-bindings: Add Cavium Octeon Common Ethernet Interface.

In reply to Florian Fainelli
Quoted 10 lines · Florian Fainelli
Quoted 8 lines · David Daney

From: Carlos Munoz <cmunoz-YGCgFSpz5w/[email protected]>

Add bindings for Common Ethernet Interface (BGX) block.

---

[snip]

Quoted 14 lines

Documentation/devicetree/bindings/net/cavium-bgx.txt line 59

Quoted 12 lines
Documentation/devicetree/bindings/net/cavium-bgx.txt new file +12 -0
+Properties:
+
+- compatible: "cavium,octeon-7360-xcv": Compatibility with cn73xx SOCs.
+
+- reg: The index of the interface within the BGX block.
+
+- local-mac-address: Mac address for the interface.
+
+- phy-handle: phandle to the phy node connected to the interface.
+
+- cavium,rx-clk-delay-bypass: Set to <1> to bypass the rx clock delay setting.
+  Needed by the Micrel PHY.

Is not that implied by an appropriate "phy-mode" property already?

Hi Florian

Looking at the driver patch, phy-mode is not used at all. of_phy_connect() passes a hard coded SGMII value!

David, you need to fix this.

Andrew
--
To unsubscribe from this list: send the line "unsubscribe devicetree" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html

#16 lore raw

Re: [PATCH 4/7] MIPS: Octeon: Add Free Pointer Unit (FPA) support.

In reply to David Daney

arch/mips/cavium-octeon/Kconfig config OCTEON_ILM · line 91

Quoted 11 lines · David Daney
arch/mips/cavium-octeon/Kconfig +3 -0
index 5c0b56203bae..211ef5b57214 100644
@@ -86,4 +86,14 @@ config OCTEON_ILM
 	  To compile this driver as a module, choose M here.  The module
 	  will be called octeon-ilm
 
+config OCTEON_FPA3
+	tristate "Octeon III fpa driver"
+	default "n"

n is the default default so I think this line is redundant.

arch/mips/cavium-octeon/Kconfig config OCTEON_ILM · line 99

Quoted 8 lines
arch/mips/cavium-octeon/Kconfig +7 -0
+	depends on CPU_CAVIUM_OCTEON
+	help
+	  This option enables a Octeon III driver for the Free Pool Unit (FPA).
+	  The FPA is a hardware unit that manages pools of pointers to free
+	  L2/DRAM memory. This driver provides an interface to reserve,
+	  initialize, and fill fpa pools.
+
 endif # CAVIUM_OCTEON_SOC

Cheers
James

#21 lore raw

Re: [PATCH 6/7] netdev: octeon-ethernet: Add Cavium Octeon III support.

In reply to Andrew Lunn

On 11/02/2017 05:43 AM, Andrew Lunn wrote:
[...]

Quoted 12 lines

drivers/net/ethernet/cavium/octeon/octeon3-bgx-nexus.c line 210

Quoted 7 lines
drivers/net/ethernet/cavium/octeon/octeon3-bgx-nexus.c new file +7 -0
+
+		i = atomic_inc_return(&pki_id);
+		pki_dev = platform_device_register_data(&new_dev->dev,
+							is_mix ? "octeon_mgmt" : "ethernet-mac-pki",
+							i, &platform_data, sizeof(platform_data));
+		dev_info(&pdev->dev, "Created %s %u: %p\n",
+			 is_mix ? "MIX" : "PKI", pki_dev->id, pki_dev);

Is there any change of these ethernet ports being used to connect to an Ethernet switch. We have had issues in the past with these sort of platform devices combined with DSA.

There are only two possibilities. The BGX MACs have a multiplexer that allows them to be connected to either the "octeon_mgmt" MIX packet processor, or to the "ethernet-mac-pki" PKI/PKO packet processor. The SoCs supported by these drivers do not contain any hardware that would be considered an "Ethernet switch".

I'm not sure I fully understand what your question is though, so I may not have answered it.

David Daney

--
To unsubscribe from this list: send the line "unsubscribe devicetree" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html

#9 lore raw

Re: [PATCH 3/7] MIPS: Octeon: Add a global resource manager.

In reply to Andrew Lunn
Quoted 28 lines · Andrew Lunn
Quoted 28 lines
arch/mips/cavium-octeon/resource-mgr.c new file +28 -0
+static void res_mgr_lock(void)
+{
+	unsigned int tmp;
+	u64 lock = (u64)&res_mgr_info->rlock;
+
+	__asm__ __volatile__(
+		".set noreorder\n"
+		"1: ll   %[tmp], 0(%[addr])\n"
+		"   bnez %[tmp], 1b\n"
+		"   li   %[tmp], 1\n"
+		"   sc   %[tmp], 0(%[addr])\n"
+		"   beqz %[tmp], 1b\n"
+		"   nop\n"
+		".set reorder\n" :
+		[tmp] "=&r"(tmp) :
+		[addr] "r"(lock) :
+		"memory");
+}
+
+static void res_mgr_unlock(void)
+{
+	u64 lock = (u64)&res_mgr_info->rlock;
+
+	/* Wait until all resource operations finish before unlocking. */
+	mb();
+	__asm__ __volatile__(
+		"sw $0, 0(%[addr])\n" : :
+		[addr] "r"(lock) :
Quoted 8 lines

arch/mips/cavium-octeon/resource-mgr.c line 73

Quoted 5 lines
arch/mips/cavium-octeon/resource-mgr.c new file +5 -0
+		"memory");
+
+	/* Force a write buffer flush. */
+	mb();
+}

It would be good to add some justification for using your own locks, rather than standard linux locks.

Yes, I will add that.

Quoted 5 lines

Is there anything specific to your hardware in this resource manager? I'm just wondering if this should be generic, put somewhere in lib. Or maybe there is already something generic, and you should be using it, not re-inventing the wheel again.

The systems built around this hardware may have other software running on CPUs that are not running the Linux kernel. The data structures used to arbitrate usage of shared system hardware resources use exactly these locking primitives, so they cannot be changed to use the Linux locking implementation de jour.

#5 lore raw

Re: [PATCH 1/7] dt-bindings: Add Cavium Octeon Common Ethernet Interface.

In reply to Andrew Lunn
Quoted 26 lines · Andrew Lunn
Quoted 10 lines · Florian Fainelli
Quoted 8 lines · David Daney

From: Carlos Munoz <cmunoz-YGCgFSpz5w/[email protected]>

Add bindings for Common Ethernet Interface (BGX) block.

---

[snip]

Quoted 14 lines

Documentation/devicetree/bindings/net/cavium-bgx.txt line 59

Quoted 12 lines
Documentation/devicetree/bindings/net/cavium-bgx.txt new file +12 -0
+Properties:
+
+- compatible: "cavium,octeon-7360-xcv": Compatibility with cn73xx SOCs.
+
+- reg: The index of the interface within the BGX block.
+
+- local-mac-address: Mac address for the interface.
+
+- phy-handle: phandle to the phy node connected to the interface.
+
+- cavium,rx-clk-delay-bypass: Set to <1> to bypass the rx clock delay setting.
+  Needed by the Micrel PHY.

Is not that implied by an appropriate "phy-mode" property already?

Quoted 7 lines

Hi Florian

Looking at the driver patch, phy-mode is not used at all. of_phy_connect() passes a hard coded SGMII value!

David, you need to fix this.

Yes, I think you are correct.

Thanks for reviewing this,

David Daney
--
To unsubscribe from this list: send the line "unsubscribe devicetree" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html

#22 lore raw

Re: [PATCH 6/7] netdev: octeon-ethernet: Add Cavium Octeon III support.

In reply to David Daney
Quoted 15 lines · David Daney

On 11/02/2017 05:43 AM, Andrew Lunn wrote:
[...]

Quoted 12 lines

drivers/net/ethernet/cavium/octeon/octeon3-bgx-nexus.c line 210

Quoted 7 lines
drivers/net/ethernet/cavium/octeon/octeon3-bgx-nexus.c new file +7 -0
+
+		i = atomic_inc_return(&pki_id);
+		pki_dev = platform_device_register_data(&new_dev->dev,
+							is_mix ? "octeon_mgmt" : "ethernet-mac-pki",
+							i, &platform_data, sizeof(platform_data));
+		dev_info(&pdev->dev, "Created %s %u: %p\n",
+			 is_mix ? "MIX" : "PKI", pki_dev->id, pki_dev);

Is there any change of these ethernet ports being used to connect to an Ethernet switch. We have had issues in the past with these sort of platform devices combined with DSA.

Quoted 5 lines

There are only two possibilities. The BGX MACs have a multiplexer that allows them to be connected to either the "octeon_mgmt" MIX packet processor, or to the "ethernet-mac-pki" PKI/PKO packet processor. The SoCs supported by these drivers do not contain any hardware that would be considered an "Ethernet switch".

Hi David

I was thinking of an external Ethernet switch. You generally connect via RGMII to a port of the switch.

http://elixir.free-electrons.com/linux/v4.9.60/source/Documentation/networking/dsa/dsa.txt

Andrew

#13 lore raw

Re: [PATCH 4/7] MIPS: Octeon: Add Free Pointer Unit (FPA) support.

In reply to Florian Fainelli
Quoted 11 lines · Florian Fainelli

Le 11/01/17 à 17:36, David Daney a écrit :

Quoted 6 lines

From: Carlos Munoz <[email protected]>

From the hardware user manual: "The FPA is a unit that maintains
pools of pointers to free L2/DRAM memory. To provide QoS, the pools are referenced indirectly through 1024 auras. Both core software and hardware units allocate and free pointers."

This looks like a possibly similar implement to what drivers/net/ethernet/marvell/mvneta_bm.c, can you see if you can make any use of genpool_* and include/net/hwbm.h here as well?

Yikes! Is it permitted to put function definitions that are not "static inline" in header files?

The driver currently doesn't use page fragments, so I don't think that the hwbm thing can be used.

Also the FPA unit is used to control RED and back pressure in the PKI (packet input processor), which are features that are features not considered in hwbm.

The OCTEON-III hardware also uses the FPA for non-packet-buffer memory allocations. So for those, it seems that hwbm is also not a good fit.

David Daney

#23 lore raw

Re: [PATCH 6/7] netdev: octeon-ethernet: Add Cavium Octeon III support.

In reply to Andrew Lunn
Quoted 22 lines · Andrew Lunn
Quoted 15 lines · David Daney

On 11/02/2017 05:43 AM, Andrew Lunn wrote:
[...]

Quoted 12 lines

drivers/net/ethernet/cavium/octeon/octeon3-bgx-nexus.c line 210

Quoted 7 lines
drivers/net/ethernet/cavium/octeon/octeon3-bgx-nexus.c new file +7 -0
+
+		i = atomic_inc_return(&pki_id);
+		pki_dev = platform_device_register_data(&new_dev->dev,
+							is_mix ? "octeon_mgmt" : "ethernet-mac-pki",
+							i, &platform_data, sizeof(platform_data));
+		dev_info(&pdev->dev, "Created %s %u: %p\n",
+			 is_mix ? "MIX" : "PKI", pki_dev->id, pki_dev);

Is there any change of these ethernet ports being used to connect to an Ethernet switch. We have had issues in the past with these sort of platform devices combined with DSA.

Quoted 5 lines

There are only two possibilities. The BGX MACs have a multiplexer that allows them to be connected to either the "octeon_mgmt" MIX packet processor, or to the "ethernet-mac-pki" PKI/PKO packet processor. The SoCs supported by these drivers do not contain any hardware that would be considered an "Ethernet switch".

Quoted 5 lines

Hi David

I was thinking of an external Ethernet switch. You generally connect via RGMII to a port of the switch.

OK, now I think I understand. Yes, the MAC can be hardwired to a switch. In fact, there are system designs that do exactly that.

We try to handle this case by not having a "phy-handle" property in the device tree. The link to the remote device (switch IC in this case) is brought up on ndo_open()

There may be opportunities to improve how this works in the future, but the current code is serviceable.

Quoted 4 lines

http://elixir.free-electrons.com/linux/v4.9.60/source/Documentation/networking/dsa/dsa.txt

Andrew

--
To unsubscribe from this list: send the line "unsubscribe devicetree" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html

#24 lore raw

Re: [PATCH 6/7] netdev: octeon-ethernet: Add Cavium Octeon III support.

Quoted 6 lines

OK, now I think I understand. Yes, the MAC can be hardwired to a switch. In fact, there are system designs that do exactly that.

We try to handle this case by not having a "phy-handle" property in the device tree. The link to the remote device (switch IC in this case) is brought up on ndo_open()

O.K, so you totally ignore the Linux way of doing this and hack together your own proprietary solution.

Quoted 2 lines

There may be opportunities to improve how this works in the future, but the current code is serviceable.

It might be serviceable, but it will never get into mainline. For mainline, you need to use DSA.

http://elixir.free-electrons.com/linux/v4.9.60/source/Documentation/networking/dsa/dsa.txt

Getting back to my original point, having these platform devices can cause issues for DSA. Freescale FMAN has a similar architecture, and it took a while to restructure it to make DSA work.

https://www.spinics.net/lists/netdev/msg459394.html

Andrew
--
To unsubscribe from this list: send the line "unsubscribe devicetree" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html

#10 lore raw

Re: [PATCH 3/7] MIPS: Octeon: Add a global resource manager.

In reply to David Daney
Quoted 47 lines · David Daney
Quoted 28 lines · Andrew Lunn
Quoted 28 lines
arch/mips/cavium-octeon/resource-mgr.c new file +28 -0
+static void res_mgr_lock(void)
+{
+    unsigned int tmp;
+    u64 lock = (u64)&res_mgr_info->rlock;
+
+    __asm__ __volatile__(
+        ".set noreorder\n"
+        "1: ll   %[tmp], 0(%[addr])\n"
+        "   bnez %[tmp], 1b\n"
+        "   li   %[tmp], 1\n"
+        "   sc   %[tmp], 0(%[addr])\n"
+        "   beqz %[tmp], 1b\n"
+        "   nop\n"
+        ".set reorder\n" :
+        [tmp] "=&r"(tmp) :
+        [addr] "r"(lock) :
+        "memory");
+}
+
+static void res_mgr_unlock(void)
+{
+    u64 lock = (u64)&res_mgr_info->rlock;
+
+    /* Wait until all resource operations finish before unlocking. */
+    mb();
+    __asm__ __volatile__(
+        "sw $0, 0(%[addr])\n" : :
+        [addr] "r"(lock) :
Quoted 8 lines

arch/mips/cavium-octeon/resource-mgr.c line 73

Quoted 5 lines
arch/mips/cavium-octeon/resource-mgr.c new file +5 -0
+        "memory");
+
+    /* Force a write buffer flush. */
+    mb();
+}

It would be good to add some justification for using your own locks, rather than standard linux locks.

Yes, I will add that.

Quoted 5 lines

Is there anything specific to your hardware in this resource manager? I'm just wondering if this should be generic, put somewhere in lib. Or maybe there is already something generic, and you should be using it, not re-inventing the wheel again.

Quoted 5 lines

The systems built around this hardware may have other software running on CPUs that are not running the Linux kernel. The data structures used to arbitrate usage of shared system hardware resources use exactly these locking primitives, so they cannot be changed to use the Linux locking implementation de jour.

Would hwspinlock be a possible option so this is abstracted on the Linux side using these locking primitives through the hwspinlock layer which in turn does exactly what is above?

Signature · 5 lines
Florian
--
To unsubscribe from this list: send the line "unsubscribe devicetree" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
#14 lore raw

Re: [PATCH 4/7] MIPS: Octeon: Add Free Pointer Unit (FPA) support.

In reply to David Daney
Quoted 9 lines · David Daney
Quoted 8 lines · Florian Fainelli
Quoted 6 lines · David Daney

From: Carlos Munoz <cmunoz-YGCgFSpz5w/[email protected]>

From the hardware user manual: "The FPA is a unit that maintains
pools of pointers to free L2/DRAM memory. To provide QoS, the pools are referenced indirectly through 1024 auras. Both core software and hardware units allocate and free pointers."

Quoted 6 lines
Quoted 3 lines

This looks like a possibly similar implement to what drivers/net/ethernet/marvell/mvneta_bm.c, can you see if you can make any use of genpool_* and include/net/hwbm.h here as well?

Yikes! Is it permitted to put function definitions that are not "static inline" in header files?

Meh well, this is not even ressembling what we initially discussed, so I was hoping we could build more interesting features on top of this.

Quoted 10 lines

The driver currently doesn't use page fragments, so I don't think that the hwbm thing can be used.

Also the FPA unit is used to control RED and back pressure in the PKI (packet input processor), which are features that are features not considered in hwbm.

The OCTEON-III hardware also uses the FPA for non-packet-buffer memory allocations. So for those, it seems that hwbm is also not a good fit.

OK, let me see if I understand how FPA works, can we say that this is more or less a buffer tokenizer in that, you give it a buffer physical address and it returns an unique identifier that the FPA uses for actual packet passing, transmission and other manipulations?

There were a few funky things in the network driver, I will comment there. --
Florian
--
To unsubscribe from this list: send the line "unsubscribe devicetree" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html

#25 lore raw

Re: [PATCH 6/7] netdev: octeon-ethernet: Add Cavium Octeon III support.

In reply to Andrew Lunn
Quoted 9 lines · Andrew Lunn
Quoted 6 lines

OK, now I think I understand. Yes, the MAC can be hardwired to a switch. In fact, there are system designs that do exactly that.

We try to handle this case by not having a "phy-handle" property in the device tree. The link to the remote device (switch IC in this case) is brought up on ndo_open()

O.K, so you totally ignore the Linux way of doing this and hack together your own proprietary solution.

I am going to add handling of the "phy-mode" property, but other than that I don't know what the "Linux way" of specifying a hard MAC-to-MAC connection with no intervening phy devices is. Wether the remote MAC is a switch, or something else, would seem to be irrelevant. All we are concerned about in this code is putting the thing into a state where data flows in both directions through the MAC.

A pointer to an existing device tree binding for an Ethernet device that has no (or an optional) phy device would be useful, we can try to do the same.

Quoted 8 lines
Quoted 3 lines

There may be opportunities to improve how this works in the future, but the current code is serviceable.

It might be serviceable, but it will never get into mainline. For mainline, you need to use DSA.

http://elixir.free-electrons.com/linux/v4.9.60/source/Documentation/networking/dsa/dsa.txt

I am truly at a loss here. That DSA document states:

Master network devices are regular, unmodified Linux network device drivers for the CPU/management Ethernet interface.

What modification do you suggest I make?

Quoted 9 lines

Getting back to my original point, having these platform devices can cause issues for DSA. Freescale FMAN has a similar architecture, and it took a while to restructure it to make DSA work.

https://www.spinics.net/lists/netdev/msg459394.html

Andrew

#26 lore raw

Re: [PATCH 6/7] netdev: octeon-ethernet: Add Cavium Octeon III support.

Quoted 12 lines · David Daney
Quoted 10 lines · Andrew Lunn
Quoted 7 lines

OK, now I think I understand. Yes, the MAC can be hardwired to a switch.
In fact, there are system designs that do exactly that.

We try to handle this case by not having a "phy-handle" property in the device tree. The link to the remote device (switch IC in this case) is brought up on ndo_open()

O.K, so you totally ignore the Linux way of doing this and hack together your own proprietary solution.

Quoted 6 lines

I am going to add handling of the "phy-mode" property, but other than that I don't know what the "Linux way" of specifying a hard MAC-to-MAC connection with no intervening phy devices is. Wether the remote MAC is a switch, or something else, would seem to be irrelevant. All we are concerned about in this code is putting the thing into a state where data flows in both directions through the MAC.

The canonical way to support that type of connections is to use use a fixed-link property describing the link between the two MACs, ideally putting the same fixed-link property on both sides.

Quoted 18 lines

A pointer to an existing device tree binding for an Ethernet device that has no (or an optional) phy device would be useful, we can try to do the same.

Quoted 10 lines
Quoted 4 lines

There may be opportunities to improve how this works in the future, but the
current code is serviceable.

It might be serviceable, but it will never get into mainline. For mainline, you need to use DSA.

http://elixir.free-electrons.com/linux/v4.9.60/source/Documentation/networking/dsa/dsa.txt

Quoted 7 lines

I am truly at a loss here. That DSA document states:

Master network devices are regular, unmodified Linux network device drivers for the CPU/management Ethernet interface.

What modification do you suggest I make?

If you support normal phy_device and fixed-link devices, you should be good as far as using PHYLIB and interfacing with Ethernet switchses using DSA for instance. What Andrew is asking you though is to make sure that the platform device dance between the bgx drivers and the other modules preserves the Device Tree parenting, of_node pointers such that a DSA switch, which needs to reference a CPU/management port, has a chance to successfully look up that node via of_find_net_device_by_node().

Quoted 16 lines
Quoted 11 lines

Getting back to my original point, having these platform devices can cause issues for DSA. Freescale FMAN has a similar architecture, and it took a while to restructure it to make DSA work.

https://www.spinics.net/lists/netdev/msg459394.html

Andrew

Signature · 3 lines
To unsubscribe from this list: send the line "unsubscribe devicetree" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Signature · 5 lines
Florian
--
To unsubscribe from this list: send the line "unsubscribe devicetree" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
#15 lore raw

Re: [PATCH 4/7] MIPS: Octeon: Add Free Pointer Unit (FPA) support.

In reply to Florian Fainelli
Quoted 28 lines · Florian Fainelli
Quoted 9 lines · David Daney
Quoted 8 lines · Florian Fainelli
Quoted 6 lines · David Daney

From: Carlos Munoz <[email protected]>

From the hardware user manual: "The FPA is a unit that maintains
pools of pointers to free L2/DRAM memory. To provide QoS, the pools are referenced indirectly through 1024 auras. Both core software and hardware units allocate and free pointers."

Quoted 6 lines
Quoted 3 lines

This looks like a possibly similar implement to what drivers/net/ethernet/marvell/mvneta_bm.c, can you see if you can make any use of genpool_* and include/net/hwbm.h here as well?

Yikes! Is it permitted to put function definitions that are not "static inline" in header files?

Meh well, this is not even ressembling what we initially discussed, so I was hoping we could build more interesting features on top of this.

Quoted 8 lines

The driver currently doesn't use page fragments, so I don't think that the hwbm thing can be used.

Also the FPA unit is used to control RED and back pressure in the PKI (packet input processor), which are features that are features not considered in hwbm.

Quoted 7 lines
Quoted 2 lines

The OCTEON-III hardware also uses the FPA for non-packet-buffer memory allocations. So for those, it seems that hwbm is also not a good fit.

OK, let me see if I understand how FPA works, can we say that this is more or less a buffer tokenizer in that, you give it a buffer physical address and it returns an unique identifier that the FPA uses for actual packet passing, transmission and other manipulations?

At a high level, think of the FPA as a FIFO containing DMA addresses used by hardware. The FIFO property is not guaranteed, so it is best to consider it as a pool of buffer addresses.

Software pushes pointers into the FPA, and the hardware RX unit (PKI) pops them off when it needs an RX buffer. The TX unit (PKO) and input queue (SSO) also use memory obtained from the FPA as backing store for their internal queues.

In addition to obtaining buffers, the PKI uses the number of entries in an FPA pool to control RED and back pressure.

There are other features not used by the driver like threshold interrupts, and pointer alignment so you don't have to calculate the buffer address from a pointer to the middle of the buffer when freeing.

Quoted 5 lines

There were a few funky things in the network driver, I will comment there. --
Florian

#27 lore raw

Re: [PATCH 6/7] netdev: octeon-ethernet: Add Cavium Octeon III support.

In reply to David Daney
Quoted 19 lines · David Daney

From: Carlos Munoz <[email protected]>

The Cavium OCTEON cn78xx and cn73xx SoCs have network packet I/O hardware that is significantly different from previous generations of the family.

Add a new driver for this hardware. The Ethernet MAC is called BGX on these devices. Common code for the MAC is in octeon3-bgx-port.c. Four of these BGX MACs are grouped together and managed as a group by octeon3-bgx-nexus.c. Ingress packet classification is done by the PKI unit initialized in octeon3-pki.c. Queue management is done in the SSO, initialized by octeon3-sso.c. Egress is handled by the PKO, initialized in octeon3-pko.c.

---

drivers/net/ethernet/cavium/octeon/octeon3-bgx-nexus.c line 24

Quoted 3 lines
drivers/net/ethernet/cavium/octeon/octeon3-bgx-nexus.c new file +3 -0
+static char *mix_port;
+module_param(mix_port, charp, 0444);
+MODULE_PARM_DESC(mix_port, "Specifies which ports connect to MIX interfaces.");

Can you derive this from Device Tree /platform data configuration?

drivers/net/ethernet/cavium/octeon/octeon3-bgx-nexus.c line 28

Quoted 4 lines
drivers/net/ethernet/cavium/octeon/octeon3-bgx-nexus.c new file +4 -0
+
+static char *pki_port;
+module_param(pki_port, charp, 0444);
+MODULE_PARM_DESC(pki_port, "Specifies which ports connect to the PKI.");

Likewise

Quoted 24 lines
drivers/net/ethernet/cavium/octeon/octeon3-bgx-nexus.c new file +24 -0
+
+#define MAX_MIX_PER_NODE	2
+
+#define MAX_MIX			(MAX_NODES * MAX_MIX_PER_NODE)
+
+/**
+ * struct mix_port_lmac - Describes a lmac that connects to a mix
+ *			  port. The lmac must be on the same node as
+ *			  the mix.
+ * @node:	Node of the lmac.
+ * @bgx:	Bgx of the lmac.
+ * @lmac:	Lmac index.
+ */
+struct mix_port_lmac {
+	int	node;
+	int	bgx;
+	int	lmac;
+};
+
+/* mix_ports_lmacs contains all the lmacs connected to mix ports */
+static struct mix_port_lmac mix_port_lmacs[MAX_MIX];
+
+/* pki_ports keeps track of the lmacs connected to the pki */
+static bool pki_ports[MAX_NODES][MAX_BGX_PER_NODE][MAX_LMAC_PER_BGX];

drivers/net/ethernet/cavium/octeon/octeon3-bgx-nexus.c line 62

Quoted 10 lines
drivers/net/ethernet/cavium/octeon/octeon3-bgx-nexus.c new file +10 -0
+
+/* Created platform devices get added to this list */
+static struct list_head pdev_list;
+static struct mutex pdev_list_lock;
+
+/* Created platform device use this structure to add themselves to the list */
+struct pdev_list_item {
+	struct list_head	list;
+	struct platform_device	*pdev;
+};

Don't you have a top-level platform device that you could use which would hold this data instead of having it here?

[snip]

Quoted 4 lines
drivers/net/ethernet/cavium/octeon/octeon3-core.c new file +4 -0
+/* Registers are accessed via xkphys */
+#define SSO_BASE			0x1670000000000ull
+#define SSO_ADDR(node)			(SET_XKPHYS + NODE_OFFSET(node) +      \
+					 SSO_BASE)

drivers/net/ethernet/cavium/octeon/octeon3-core.c line 149

Quoted 10 lines
drivers/net/ethernet/cavium/octeon/octeon3-core.c new file +10 -0
+#define GRP_OFFSET(grp)			((grp) << 16)
+#define GRP_ADDR(n, g)			(SSO_ADDR(n) + GRP_OFFSET(g))
+#define SSO_GRP_AQ_CNT(n, g)		(GRP_ADDR(n, g)		   + 0x20000700)
+
+#define MIO_PTP_BASE			0x1070000000000ull
+#define MIO_PTP_ADDR(node)		(SET_XKPHYS + NODE_OFFSET(node) +      \
+					 MIO_PTP_BASE)
+#define MIO_PTP_CLOCK_CFG(node)		(MIO_PTP_ADDR(node)		+ 0xf00)
+#define MIO_PTP_CLOCK_HI(node)		(MIO_PTP_ADDR(node)		+ 0xf10)
+#define MIO_PTP_CLOCK_COMP(node)	(MIO_PTP_ADDR(node)		+ 0xf18)

I am sure this will work great on anything but MIPS64 ;)

Quoted 36 lines
drivers/net/ethernet/cavium/octeon/octeon3-core.c new file +36 -0
+
+struct octeon3_ethernet;
+
+struct octeon3_rx {
+	struct napi_struct	napi;
+	struct octeon3_ethernet *parent;
+	int rx_grp;
+	int rx_irq;
+	cpumask_t rx_affinity_hint;
+} ____cacheline_aligned_in_smp;
+
+struct octeon3_ethernet {
+	struct bgx_port_netdev_priv bgx_priv; /* Must be first element. */
+	struct list_head list;
+	struct net_device *netdev;
+	enum octeon3_mac_type mac_type;
+	struct octeon3_rx rx_cxt[MAX_RX_QUEUES];
+	struct ptp_clock_info ptp_info;
+	struct ptp_clock *ptp_clock;
+	struct cyclecounter cc;
+	struct timecounter tc;
+	spinlock_t ptp_lock;		/* Serialize ptp clock adjustments */
+	int num_rx_cxt;
+	int pki_aura;
+	int pknd;
+	int pko_queue;
+	int node;
+	int interface;
+	int index;
+	int rx_buf_count;
+	int tx_complete_grp;
+	int rx_timestamp_hw:1;
+	int tx_timestamp_hw:1;
+	spinlock_t stat_lock;		/* Protects stats counters */
+	u64 last_packets;
+	u64 last_octets;

drivers/net/ethernet/cavium/octeon/octeon3-core.c line 195

Quoted 10 lines
drivers/net/ethernet/cavium/octeon/octeon3-core.c new file +10 -0
+	u64 last_dropped;
+	atomic64_t rx_packets;
+	atomic64_t rx_octets;
+	atomic64_t rx_dropped;
+	atomic64_t rx_errors;
+	atomic64_t rx_length_errors;
+	atomic64_t rx_crc_errors;
+	atomic64_t tx_packets;
+	atomic64_t tx_octets;
+	atomic64_t tx_dropped;

Do you really need those to be truly atomic64_t types, can't you use u64 and use the helpers from u64_stats_sync.h? That should be good enough?

Quoted 37 lines
drivers/net/ethernet/cavium/octeon/octeon3-core.c new file +37 -0
+	/* The following two fields need to be on a different cache line as
+	 * they are updated by pko which invalidates the cache every time it
+	 * updates them. The idea is to prevent other fields from being
+	 * invalidated unnecessarily.
+	 */
+	char cacheline_pad1[CVMX_CACHE_LINE_SIZE];
+	atomic64_t buffers_needed;
+	atomic64_t tx_backlog;
+	char cacheline_pad2[CVMX_CACHE_LINE_SIZE];
+};
+
+static DEFINE_MUTEX(octeon3_eth_init_mutex);
+
+struct octeon3_ethernet_node;
+
+struct octeon3_ethernet_worker {
+	wait_queue_head_t queue;
+	struct task_struct *task;
+	struct octeon3_ethernet_node *oen;
+	atomic_t kick;
+	int order;
+};
+
+struct octeon3_ethernet_node {
+	bool init_done;
+	int next_cpu_irq_affinity;
+	int node;
+	int pki_packet_pool;
+	int sso_pool;
+	int pko_pool;
+	void *sso_pool_stack;
+	void *pko_pool_stack;
+	void *pki_packet_pool_stack;
+	int sso_aura;
+	int pko_aura;
+	int tx_complete_grp;
+	int tx_irq;

drivers/net/ethernet/cavium/octeon/octeon3-core.c line 242

Quoted 10 lines
drivers/net/ethernet/cavium/octeon/octeon3-core.c new file +10 -0
+	cpumask_t tx_affinity_hint;
+	struct octeon3_ethernet_worker workers[8];
+	struct mutex device_list_lock;	/* Protects the device list */
+	struct list_head device_list;
+	spinlock_t napi_alloc_lock;	/* Protects napi allocations */
+};
+
+static int wait_pko_response;
+module_param(wait_pko_response, int, 0644);
+MODULE_PARM_DESC(wait_pko_response, "Wait for response after each pko command.");

Under which circumstances is this used?

drivers/net/ethernet/cavium/octeon/octeon3-core.c line 247

Quoted 5 lines
drivers/net/ethernet/cavium/octeon/octeon3-core.c new file +5 -0
+
+static int num_packet_buffers = 768;
+module_param(num_packet_buffers, int, 0444);
+MODULE_PARM_DESC(num_packet_buffers,
+		 "Number of packet buffers to allocate per port.");

Consider implementing ethtool -g/G for this.

drivers/net/ethernet/cavium/octeon/octeon3-core.c line 251

Quoted 4 lines
drivers/net/ethernet/cavium/octeon/octeon3-core.c new file +4 -0
+
+static int packet_buffer_size = 2048;
+module_param(packet_buffer_size, int, 0444);
+MODULE_PARM_DESC(packet_buffer_size, "Size of each RX packet buffer.");

How is that different from adjusting the network device's MTU?

drivers/net/ethernet/cavium/octeon/octeon3-core.c line 255

Quoted 4 lines
drivers/net/ethernet/cavium/octeon/octeon3-core.c new file +4 -0
+
+static int rx_queues = 1;
+module_param(rx_queues, int, 0444);
+MODULE_PARM_DESC(rx_queues, "Number of RX threads per port.");

Same thing, can you consider using an ethtool knob for that?

Quoted 13 lines
drivers/net/ethernet/cavium/octeon/octeon3-core.c new file +13 -0
+
+int ilk0_lanes = 1;
+module_param(ilk0_lanes, int, 0444);
+MODULE_PARM_DESC(ilk0_lanes, "Number of SerDes lanes used by ILK link 0.");
+
+int ilk1_lanes = 1;
+module_param(ilk1_lanes, int, 0444);
+MODULE_PARM_DESC(ilk1_lanes, "Number of SerDes lanes used by ILK link 1.");
+
+static struct octeon3_ethernet_node octeon3_eth_node[MAX_NODES];
+static struct kmem_cache *octeon3_eth_sso_pko_cache;
+
+/**

drivers/net/ethernet/cavium/octeon/octeon3-core.c line 278

Quoted 10 lines
drivers/net/ethernet/cavium/octeon/octeon3-core.c new file +10 -0
+ * Reads a 64 bit value from the processor local scratchpad memory.
+ *
+ * @param offset byte offset into scratch pad to read
+ *
+ * @return value read
+ */
+static inline u64 scratch_read64(u64 offset)
+{
+	return *(u64 *)((long)SCRATCH_BASE + offset);
+}

No barriers needed whatsoever?

Quoted 75 lines
drivers/net/ethernet/cavium/octeon/octeon3-core.c new file +75 -0
+
+/**
+ * Write a 64 bit value to the processor local scratchpad memory.
+ *
+ * @param offset byte offset into scratch pad to write
+ @ @praram value to write
+ */
+static inline void scratch_write64(u64 offset, u64 value)
+{
+	*(u64 *)((long)SCRATCH_BASE + offset) = value;
+}
+
+static int get_pki_chan(int node, int interface, int index)
+{
+	int	pki_chan;
+
+	pki_chan = node << 12;
+
+	if (OCTEON_IS_MODEL(OCTEON_CNF75XX) &&
+	    (interface == 1 || interface == 2)) {
+		/* SRIO */
+		pki_chan |= 0x240 + (2 * (interface - 1)) + index;
+	} else {
+		/* BGX */
+		pki_chan |= 0x800 + (0x100 * interface) + (0x10 * index);
+	}
+
+	return pki_chan;
+}
+
+/* Map auras to the field priv->buffers_needed. Used to speed up packet
+ * transmission.
+ */
+static void *aura2bufs_needed[MAX_NODES][FPA3_NUM_AURAS];
+
+static int octeon3_eth_lgrp_to_ggrp(int node, int grp)
+{
+	return (node << 8) | grp;
+}
+
+static void octeon3_eth_gen_affinity(int node, cpumask_t *mask)
+{
+	int cpu;
+
+	do {
+		cpu = cpumask_next(octeon3_eth_node[node].next_cpu_irq_affinity, cpu_online_mask);
+		octeon3_eth_node[node].next_cpu_irq_affinity++;
+		if (cpu >= nr_cpu_ids) {
+			octeon3_eth_node[node].next_cpu_irq_affinity = -1;
+			continue;
+		}
+	} while (false);
+	cpumask_clear(mask);
+	cpumask_set_cpu(cpu, mask);
+}
+
+struct wr_ret {
+	void *work;
+	u16 grp;
+};
+
+static inline struct wr_ret octeon3_core_get_work_sync(int grp)
+{
+	u64		node = cvmx_get_node_num();
+	u64		addr;
+	u64		response;
+	struct wr_ret	r;
+
+	/* See SSO_GET_WORK_LD_S for the address to read */
+	addr = 1ull << 63;
+	addr |= BIT(48);
+	addr |= DID_TAG_SWTAG << 40;
+	addr |= node << 36;
+	addr |= BIT(30);
+	addr |= BIT(29);

drivers/net/ethernet/cavium/octeon/octeon3-core.c line 363

Quoted 10 lines
drivers/net/ethernet/cavium/octeon/octeon3-core.c new file +10 -0
+	addr |= octeon3_eth_lgrp_to_ggrp(node, grp) << 4;
+	addr |= SSO_NO_WAIT << 3;
+	response = __raw_readq((void __iomem *)addr);
+
+	/* See SSO_GET_WORK_RTN_S for the format of the response */
+	r.grp = (response & GENMASK_ULL(57, 48)) >> 48;
+	if (response & BIT(63))
+		r.work = NULL;
+	else
+		r.work = phys_to_virt(response & GENMASK_ULL(41, 0));

There are quite a lot of phys_to_virt() and virt_to_phys() uses throughout this driver, this will likely not work on anything but MIPS64, so there should be a better way, abstracted to do this, see below.

Quoted 56 lines
drivers/net/ethernet/cavium/octeon/octeon3-core.c new file +56 -0
+
+	return r;
+}
+
+/**
+ * octeon3_core_get_work_async - Request work via a iobdma command. Doesn't wait
+ *				 for the response.
+ *
+ * @grp: Group to request work for.
+ */
+static inline void octeon3_core_get_work_async(unsigned int grp)
+{
+	u64	data;
+	u64	node = cvmx_get_node_num();
+
+	/* See SSO_GET_WORK_DMA_S for the command structure */
+	data = SCR_SCRATCH << 56;
+	data |= 1ull << 48;
+	data |= DID_TAG_SWTAG << 40;
+	data |= node << 36;
+	data |= 1ull << 30;
+	data |= 1ull << 29;
+	data |= octeon3_eth_lgrp_to_ggrp(node, grp) << 4;
+	data |= SSO_NO_WAIT << 3;
+
+	__raw_writeq(data, (void __iomem *)IOBDMA_SENDSINGLE);
+}
+
+/**
+ * octeon3_core_get_response_async - Read the request work response. Must be
+ *				     called after calling
+ *				     octeon3_core_get_work_async().
+ *
+ * Returns work queue entry.
+ */
+static inline struct wr_ret octeon3_core_get_response_async(void)
+{
+	struct wr_ret	r;
+	u64		response;
+
+	CVMX_SYNCIOBDMA;
+	response = scratch_read64(SCR_SCRATCH);
+
+	/* See SSO_GET_WORK_RTN_S for the format of the response */
+	r.grp = (response & GENMASK_ULL(57, 48)) >> 48;
+	if (response & BIT(63))
+		r.work = NULL;
+	else
+		r.work = phys_to_virt(response & GENMASK_ULL(41, 0));
+
+	return r;
+}
+
+static void octeon3_eth_replenish_rx(struct octeon3_ethernet *priv, int count)
+{
+	struct sk_buff *skb;

drivers/net/ethernet/cavium/octeon/octeon3-core.c line 429

Quoted 10 lines
drivers/net/ethernet/cavium/octeon/octeon3-core.c new file +10 -0
+	int i;
+
+	for (i = 0; i < count; i++) {
+		void **buf;
+
+		skb = __alloc_skb(packet_buffer_size, GFP_ATOMIC, 0, priv->node);
+		if (!skb)
+			break;
+		buf = (void **)PTR_ALIGN(skb->head, 128);
+		buf[SKB_PTR_OFFSET] = skb;

Can you use build_skb()?

Quoted 4 lines
drivers/net/ethernet/cavium/octeon/octeon3-core.c new file +4 -0
+		octeon_fpa3_free(priv->node, priv->pki_aura, buf);
+	}
+}
+

[snip]

Quoted 8 lines
drivers/net/ethernet/cavium/octeon/octeon3-core.c new file +8 -0
+static int octeon3_eth_tx_complete_worker(void *data)
+{
+	struct octeon3_ethernet_worker *worker = data;
+	struct octeon3_ethernet_node *oen = worker->oen;
+	int backlog;
+	int order = worker->order;
+	int tx_complete_stop_thresh = order * 100;
+	int backlog_stop_thresh = order == 0 ? 31 : order * 80;

drivers/net/ethernet/cavium/octeon/octeon3-core.c line 491

Quoted 10 lines
drivers/net/ethernet/cavium/octeon/octeon3-core.c new file +10 -0
+	u64 aq_cnt;
+	int i;
+
+	while (!kthread_should_stop()) {
+		wait_event_interruptible(worker->queue, octeon3_eth_tx_complete_runnable(worker));
+		atomic_dec_if_positive(&worker->kick); /* clear the flag */
+
+		do {
+			backlog = octeon3_eth_replenish_all(oen);
+			for (i = 0; i < 100; i++) {

Do you really want to bound your TX reclamation worker, all other network drivers never bound their napi TX completion task and instead reclaim every transmitted buffers.

Quoted 9 lines
drivers/net/ethernet/cavium/octeon/octeon3-core.c new file +9 -0
+				void **work;
+				struct net_device *tx_netdev;
+				struct octeon3_ethernet *tx_priv;
+				struct sk_buff *skb;
+				struct wr_ret r;
+
+				r = octeon3_core_get_work_sync(oen->tx_complete_grp);
+				work = r.work;
+				if (!work)

drivers/net/ethernet/cavium/octeon/octeon3-core.c line 510

Quoted 10 lines
drivers/net/ethernet/cavium/octeon/octeon3-core.c new file +10 -0
+					break;
+				tx_netdev = work[0];
+				tx_priv = netdev_priv(tx_netdev);
+				if (unlikely(netif_queue_stopped(tx_netdev)) &&
+				    atomic64_read(&tx_priv->tx_backlog) < MAX_TX_QUEUE_DEPTH)
+					netif_wake_queue(tx_netdev);
+				skb = container_of((void *)work, struct sk_buff, cb);
+				if (unlikely(tx_priv->tx_timestamp_hw) &&
+				    unlikely(skb_shinfo(skb)->tx_flags & SKBTX_IN_PROGRESS))
+					octeon3_eth_tx_complete_hwtstamp(tx_priv, skb);

This is where you should be incremeting the TX bytes and packets statistcs, not in your ndo_start_xmit() like you are currently doing.

Review

Quoted 1 line
(quoted diff) +1 -0
+				dev_kfree_skb(skb);

Consider using dev_consume_skb() to be drop-monitor friendly.

Quoted 19 lines
drivers/net/ethernet/cavium/octeon/octeon3-core.c new file +19 -0
+			}
+
+			aq_cnt = oct_csr_read(SSO_GRP_AQ_CNT(oen->node, oen->tx_complete_grp));
+			aq_cnt &= GENMASK_ULL(32, 0);
+			if ((backlog > backlog_stop_thresh || aq_cnt > tx_complete_stop_thresh) &&
+			    order < ARRAY_SIZE(oen->workers) - 1) {
+				atomic_set(&oen->workers[order + 1].kick, 1);
+				wake_up(&oen->workers[order + 1].queue);
+			}
+		} while (!need_resched() &&
+			 (backlog > backlog_stop_thresh ||
+			  aq_cnt > tx_complete_stop_thresh));
+
+		cond_resched();
+
+		if (!octeon3_eth_tx_complete_runnable(worker))
+			octeon3_sso_irq_set(oen->node, oen->tx_complete_grp, true);
+	}
+

drivers/net/ethernet/cavium/octeon/octeon3-core.c line 540

Quoted 10 lines
drivers/net/ethernet/cavium/octeon/octeon3-core.c new file +10 -0
+	return 0;
+}
+
+static irqreturn_t octeon3_eth_tx_handler(int irq, void *info)
+{
+	struct octeon3_ethernet_node *oen = info;
+	/* Disarm the irq. */
+	octeon3_sso_irq_set(oen->node, oen->tx_complete_grp, false);
+	atomic_set(&oen->workers[0].kick, 1);
+	wake_up(&oen->workers[0].queue);

Can you move the whole worker to a NAPI context/softirq context?

Quoted 288 lines
drivers/net/ethernet/cavium/octeon/octeon3-core.c new file +288 -0
+	return IRQ_HANDLED;
+}
+
+static int octeon3_eth_global_init(unsigned int node,
+				   struct platform_device *pdev)
+{
+	int i;
+	int rv = 0;
+	unsigned int sso_intsn;
+	struct octeon3_ethernet_node *oen;
+
+	mutex_lock(&octeon3_eth_init_mutex);
+
+	oen = octeon3_eth_node + node;
+
+	if (oen->init_done)
+		goto done;
+
+	/* CN78XX-P1.0 cannot un-initialize PKO, so get a module
+	 * reference to prevent it from being unloaded.
+	 */
+	if (OCTEON_IS_MODEL(OCTEON_CN78XX_PASS1_0))
+		if (!try_module_get(THIS_MODULE))
+			dev_err(&pdev->dev,
+				"ERROR: Could not obtain module reference for CN78XX-P1.0\n");
+
+	INIT_LIST_HEAD(&oen->device_list);
+	mutex_init(&oen->device_list_lock);
+	spin_lock_init(&oen->napi_alloc_lock);
+
+	oen->node = node;
+
+	octeon_fpa3_init(node);
+	rv = octeon_fpa3_pool_init(node, -1, &oen->sso_pool,
+				   &oen->sso_pool_stack, 40960);
+	if (rv)
+		goto done;
+
+	rv = octeon_fpa3_pool_init(node, -1, &oen->pko_pool,
+				   &oen->pko_pool_stack, 40960);
+	if (rv)
+		goto done;
+
+	rv = octeon_fpa3_pool_init(node, -1, &oen->pki_packet_pool,
+				   &oen->pki_packet_pool_stack, 64 * num_packet_buffers);
+	if (rv)
+		goto done;
+
+	rv = octeon_fpa3_aura_init(node, oen->sso_pool, -1,
+				   &oen->sso_aura, num_packet_buffers, 20480);
+	if (rv)
+		goto done;
+
+	rv = octeon_fpa3_aura_init(node, oen->pko_pool, -1,
+				   &oen->pko_aura, num_packet_buffers, 20480);
+	if (rv)
+		goto done;
+
+	dev_info(&pdev->dev, "SSO:%d:%d, PKO:%d:%d\n", oen->sso_pool,
+		 oen->sso_aura, oen->pko_pool, oen->pko_aura);
+
+	if (!octeon3_eth_sso_pko_cache) {
+		octeon3_eth_sso_pko_cache = kmem_cache_create("sso_pko", 4096, 128, 0, NULL);
+		if (!octeon3_eth_sso_pko_cache) {
+			rv = -ENOMEM;
+			goto done;
+		}
+	}
+
+	rv = octeon_fpa3_mem_fill(node, octeon3_eth_sso_pko_cache,
+				  oen->sso_aura, 1024);
+	if (rv)
+		goto done;
+
+	rv = octeon_fpa3_mem_fill(node, octeon3_eth_sso_pko_cache,
+				  oen->pko_aura, 1024);
+	if (rv)
+		goto done;
+
+	rv = octeon3_sso_init(node, oen->sso_aura);
+	if (rv)
+		goto done;
+
+	oen->tx_complete_grp = octeon3_sso_alloc_grp(node, -1);
+	if (oen->tx_complete_grp < 0)
+		goto done;
+
+	sso_intsn = SSO_INTSN_EXE << 12 | oen->tx_complete_grp;
+	oen->tx_irq = irq_create_mapping(NULL, sso_intsn);
+	if (!oen->tx_irq) {
+		rv = -ENODEV;
+		goto done;
+	}
+
+	rv = octeon3_pko_init_global(node, oen->pko_aura);
+	if (rv) {
+		rv = -ENODEV;
+		goto done;
+	}
+
+	octeon3_pki_vlan_init(node);
+	octeon3_pki_cluster_init(node, pdev);
+	octeon3_pki_ltype_init(node);
+	octeon3_pki_enable(node);
+
+	for (i = 0; i < ARRAY_SIZE(oen->workers); i++) {
+		oen->workers[i].oen = oen;
+		init_waitqueue_head(&oen->workers[i].queue);
+		oen->workers[i].order = i;
+	}
+	for (i = 0; i < ARRAY_SIZE(oen->workers); i++) {
+		oen->workers[i].task = kthread_create_on_node(octeon3_eth_tx_complete_worker,
+							      oen->workers + i, node,
+							      "oct3_eth/%d:%d", node, i);
+		if (IS_ERR(oen->workers[i].task)) {
+			rv = PTR_ERR(oen->workers[i].task);
+			goto done;
+		} else {
+#ifdef CONFIG_NUMA
+			set_cpus_allowed_ptr(oen->workers[i].task, cpumask_of_node(node));
+#endif
+			wake_up_process(oen->workers[i].task);
+		}
+	}
+
+	if (OCTEON_IS_MODEL(OCTEON_CN78XX_PASS1_X))
+		octeon3_sso_pass1_limit(node, oen->tx_complete_grp);
+
+	rv = request_irq(oen->tx_irq, octeon3_eth_tx_handler,
+			 IRQ_TYPE_EDGE_RISING, "oct3_eth_tx_done", oen);
+	if (rv)
+		goto done;
+	octeon3_eth_gen_affinity(node, &oen->tx_affinity_hint);
+	irq_set_affinity_hint(oen->tx_irq, &oen->tx_affinity_hint);
+
+	octeon3_sso_irq_set(node, oen->tx_complete_grp, true);
+
+	oen->init_done = true;
+done:
+	mutex_unlock(&octeon3_eth_init_mutex);
+	return rv;
+}
+
+static struct sk_buff *octeon3_eth_work_to_skb(void *w)
+{
+	struct sk_buff *skb;
+	void **f = w;
+
+	skb = f[-16];
+	return skb;
+}
+
+/* Receive one packet.
+ * returns the number of RX buffers consumed.
+ */
+static int octeon3_eth_rx_one(struct octeon3_rx *rx, bool is_async, bool req_next)
+{
+	int segments;
+	int ret;
+	unsigned int packet_len;
+	struct wqe *work;
+	u8 *data;
+	int len_remaining;
+	struct sk_buff *skb;
+	union buf_ptr packet_ptr;
+	struct wr_ret r;
+	struct octeon3_ethernet *priv = rx->parent;
+
+	if (is_async)
+		r = octeon3_core_get_response_async();
+	else
+		r = octeon3_core_get_work_sync(rx->rx_grp);
+	work = r.work;
+	if (!work)
+		return 0;
+
+	/* Request the next work so it'll be ready when we need it */
+	if (is_async && req_next)
+		octeon3_core_get_work_async(rx->rx_grp);
+
+	skb = octeon3_eth_work_to_skb(work);
+
+	segments = work->word0.bufs;
+	ret = segments;
+	packet_ptr = work->packet_ptr;
+	if (unlikely(work->word2.err_level <= PKI_ERRLEV_LA &&
+		     work->word2.err_code != PKI_OPCODE_NONE)) {
+		atomic64_inc(&priv->rx_errors);
+		switch (work->word2.err_code) {
+		case PKI_OPCODE_JABBER:
+			atomic64_inc(&priv->rx_length_errors);
+			break;
+		case PKI_OPCODE_FCS:
+			atomic64_inc(&priv->rx_crc_errors);
+			break;
+		}
+		data = phys_to_virt(packet_ptr.addr);
+		for (;;) {
+			dev_kfree_skb_any(skb);
+			segments--;
+			if (segments <= 0)
+				break;
+			packet_ptr.u64 = *(u64 *)(data - 8);
+#ifndef __LITTLE_ENDIAN
+			if (OCTEON_IS_MODEL(OCTEON_CN78XX_PASS1_X)) {
+				/* PKI_BUFLINK_S's are endian-swapped */
+				packet_ptr.u64 = swab64(packet_ptr.u64);
+			}
+#endif
+			data = phys_to_virt(packet_ptr.addr);
+			skb = octeon3_eth_work_to_skb((void *)round_down((unsigned long)data, 128ull));
+		}
+		goto out;
+	}
+
+	packet_len = work->word1.len;
+	data = phys_to_virt(packet_ptr.addr);
+	skb->data = data;
+	skb->len = packet_len;
+	len_remaining = packet_len;
+	if (segments == 1) {
+		/* Strip the ethernet fcs */
+		skb->len -= 4;
+		skb_set_tail_pointer(skb, skb->len);
+	} else {
+		bool first_frag = true;
+		struct sk_buff *current_skb = skb;
+		struct sk_buff *next_skb = NULL;
+		unsigned int segment_size;
+
+		skb_frag_list_init(skb);
+		for (;;) {
+			segment_size = (segments == 1) ? len_remaining : packet_ptr.size;
+			len_remaining -= segment_size;
+			if (!first_frag) {
+				current_skb->len = segment_size;
+				skb->data_len += segment_size;
+				skb->truesize += current_skb->truesize;
+			}
+			skb_set_tail_pointer(current_skb, segment_size);
+			segments--;
+			if (segments == 0)
+				break;
+			packet_ptr.u64 = *(u64 *)(data - 8);
+#ifndef __LITTLE_ENDIAN
+			if (OCTEON_IS_MODEL(OCTEON_CN78XX_PASS1_X)) {
+				/* PKI_BUFLINK_S's are endian-swapped */
+				packet_ptr.u64 = swab64(packet_ptr.u64);
+			}
+#endif
+			data = phys_to_virt(packet_ptr.addr);
+			next_skb = octeon3_eth_work_to_skb((void *)round_down((unsigned long)data, 128ull));
+			if (first_frag) {
+				next_skb->next = skb_shinfo(current_skb)->frag_list;
+				skb_shinfo(current_skb)->frag_list = next_skb;
+			} else {
+				current_skb->next = next_skb;
+				next_skb->next = NULL;
+			}
+			current_skb = next_skb;
+			first_frag = false;
+			current_skb->data = data;
+		}
+
+		/* Strip the ethernet fcs */
+		pskb_trim(skb, skb->len - 4);
+	}
+
+	if (likely(priv->netdev->flags & IFF_UP)) {
+		skb_checksum_none_assert(skb);
+		if (unlikely(priv->rx_timestamp_hw)) {
+			/* The first 8 bytes are the timestamp */
+			u64 hwts = *(u64 *)skb->data;
+			u64 ns;
+			struct skb_shared_hwtstamps *shts;
+
+			ns = timecounter_cyc2time(&priv->tc, hwts);
+			shts = skb_hwtstamps(skb);
+			memset(shts, 0, sizeof(*shts));
+			shts->hwtstamp = ns_to_ktime(ns);
+			__skb_pull(skb, 8);
+		}
+
+		skb->protocol = eth_type_trans(skb, priv->netdev);
+		skb->dev = priv->netdev;
+		if (priv->netdev->features & NETIF_F_RXCSUM) {
+			if ((work->word2.lc_hdr_type == PKI_LTYPE_IP4 ||
+			     work->word2.lc_hdr_type == PKI_LTYPE_IP6) &&

drivers/net/ethernet/cavium/octeon/octeon3-core.c line 838

Quoted 10 lines
drivers/net/ethernet/cavium/octeon/octeon3-core.c new file +10 -0
+			    (work->word2.lf_hdr_type == PKI_LTYPE_TCP ||
+			     work->word2.lf_hdr_type == PKI_LTYPE_UDP ||
+			     work->word2.lf_hdr_type == PKI_LTYPE_SCTP))
+				if (work->word2.err_code == 0)
+					skb->ip_summed = CHECKSUM_UNNECESSARY;
+		}
+
+		napi_gro_receive(&rx->napi, skb);
+	} else {
+		/* Drop any packet received for a device that isn't up */

If that happens, is not that a blatant indication that there is a bug in how the interface is brought down?

Quoted 72 lines
drivers/net/ethernet/cavium/octeon/octeon3-core.c new file +72 -0
+		atomic64_inc(&priv->rx_dropped);
+		dev_kfree_skb_any(skb);
+	}
+out:
+	return ret;
+}
+
+static int octeon3_eth_napi(struct napi_struct *napi, int budget)
+{
+	int rx_count = 0;
+	struct octeon3_rx *cxt;
+	struct octeon3_ethernet *priv;
+	u64 aq_cnt;
+	int n = 0;
+	int n_bufs = 0;
+	u64 old_scratch;
+
+	cxt = container_of(napi, struct octeon3_rx, napi);
+	priv = cxt->parent;
+
+	/* Get the amount of work pending */
+	aq_cnt = oct_csr_read(SSO_GRP_AQ_CNT(priv->node, cxt->rx_grp));
+	aq_cnt &= GENMASK_ULL(32, 0);
+
+	if (likely(USE_ASYNC_IOBDMA)) {
+		/* Save scratch in case userspace is using it */
+		CVMX_SYNCIOBDMA;
+		old_scratch = scratch_read64(SCR_SCRATCH);
+
+		octeon3_core_get_work_async(cxt->rx_grp);
+	}
+
+	while (rx_count < budget) {
+		n = 0;
+
+		if (likely(USE_ASYNC_IOBDMA)) {
+			bool req_next = rx_count < (budget - 1) ? true : false;
+
+			n = octeon3_eth_rx_one(cxt, true, req_next);
+		} else {
+			n = octeon3_eth_rx_one(cxt, false, false);
+		}
+
+		if (n == 0)
+			break;
+
+		n_bufs += n;
+		rx_count++;
+	}
+
+	/* Wake up worker threads */
+	n_bufs = atomic64_add_return(n_bufs, &priv->buffers_needed);
+	if (n_bufs >= 32) {
+		struct octeon3_ethernet_node *oen;
+
+		oen = octeon3_eth_node + priv->node;
+		atomic_set(&oen->workers[0].kick, 1);
+		wake_up(&oen->workers[0].queue);
+	}
+
+	/* Stop the thread when no work is pending */
+	if (rx_count < budget) {
+		napi_complete(napi);
+		octeon3_sso_irq_set(cxt->parent->node, cxt->rx_grp, true);
+	}
+
+	if (likely(USE_ASYNC_IOBDMA)) {
+		/* Restore the scratch area */
+		scratch_write64(SCR_SCRATCH, old_scratch);
+	}
+
+	return rx_count;

drivers/net/ethernet/cavium/octeon/octeon3-core.c line 920

Quoted 10 lines
drivers/net/ethernet/cavium/octeon/octeon3-core.c new file +10 -0
+}
+
+#undef BROKEN_SIMULATOR_CSUM
+
+static void ethtool_get_drvinfo(struct net_device *netdev,
+				struct ethtool_drvinfo *info)
+{
+	strcpy(info->driver, "octeon3-ethernet");
+	strcpy(info->version, "1.0");
+	strcpy(info->bus_info, "Builtin");

I believe the correct way to specify that type of bus is to use "platform".

[snip]

drivers/net/ethernet/cavium/octeon/octeon3-core.c line 1225

Quoted 10 lines
drivers/net/ethernet/cavium/octeon/octeon3-core.c new file +10 -0
+static int octeon3_eth_common_ndo_stop(struct net_device *netdev)
+{
+	struct octeon3_ethernet *priv = netdev_priv(netdev);
+	void **w;
+	struct sk_buff *skb;
+	struct octeon3_rx *rx;
+	int i;
+
+	/* Allow enough time for ingress in transit packets to be drained */
+	msleep(20);

Can you find a better way to do that? You can put a hard disable on the hardware, and then wait until a particular condition to indicate full drainage?

[snip]

Quoted 5 lines
drivers/net/ethernet/cavium/octeon/octeon3-core.c new file +5 -0
+static int octeon3_eth_ndo_start_xmit(struct sk_buff *skb,
+				      struct net_device *netdev)
+{
+	struct sk_buff *skb_tmp;
+	struct octeon3_ethernet *priv = netdev_priv(netdev);

drivers/net/ethernet/cavium/octeon/octeon3-core.c line 1436

Quoted 10 lines
drivers/net/ethernet/cavium/octeon/octeon3-core.c new file +10 -0
+	u64 scr_off = LMTDMA_SCR_OFFSET;
+	u64 pko_send_desc;
+	u64 lmtdma_data;
+	u64 aq_cnt = 0;
+	struct octeon3_ethernet_node *oen;
+	long backlog;
+	int frag_count;
+	u64 head_len;
+	int i;
+	u64 *dma_addr;

dma_addr_t?

Quoted 16 lines
drivers/net/ethernet/cavium/octeon/octeon3-core.c new file +16 -0
+	void **work;
+	unsigned int mss;
+	int grp;
+
+	frag_count = 0;
+	if (skb_has_frag_list(skb))
+		skb_walk_frags(skb, skb_tmp)
+			frag_count++;
+
+	/* Stop the queue if pko or sso are not keeping up */
+	oen = octeon3_eth_node + priv->node;
+	aq_cnt = oct_csr_read(SSO_GRP_AQ_CNT(oen->node, oen->tx_complete_grp));
+	aq_cnt &= GENMASK_ULL(32, 0);
+	backlog = atomic64_inc_return(&priv->tx_backlog);
+	if (unlikely(backlog > MAX_TX_QUEUE_DEPTH || aq_cnt > 100000))
+		netif_stop_queue(netdev);

drivers/net/ethernet/cavium/octeon/octeon3-core.c line 1462

Quoted 10 lines
drivers/net/ethernet/cavium/octeon/octeon3-core.c new file +10 -0
+
+	/* We have space for 11 segment pointers, If there will be
+	 * more than that, we must linearize.  The count is: 1 (base
+	 * SKB) + frag_count + nr_frags.
+	 */
+	if (unlikely(skb_shinfo(skb)->nr_frags + frag_count > 10)) {
+		if (unlikely(__skb_linearize(skb)))
+			goto skip_xmit;
+		frag_count = 0;
+	}

What's so special about 10? The maximum the network stack could pass is SKB_MAX_FRAGS, what would happen in that case?

drivers/net/ethernet/cavium/octeon/octeon3-core.c line 1470

Quoted 8 lines
drivers/net/ethernet/cavium/octeon/octeon3-core.c new file +8 -0
+
+	work = (void **)skb->cb;
+	work[0] = netdev;
+	work[1] = NULL;
+
+	/* Adjust the port statistics. */
+	atomic64_inc(&priv->tx_packets);
+	atomic64_add(skb->len, &priv->tx_octets);

Do this in the TX completion worker, there is no guarantee the packet will be transmitted that early in this function.

drivers/net/ethernet/cavium/octeon/octeon3-core.c line 1475

Quoted 5 lines
drivers/net/ethernet/cavium/octeon/octeon3-core.c new file +5 -0
+
+	/* Make sure packet data writes are committed before
+	 * submitting the command below
+	 */
+	wmb();

That seems just wrong here, if your goal is to make sure that e.g:
skb_linearize() did finish its pending writes to DRAM, you need to use DMA-API towards that goal. If the device is cache coherent, DMA-API will know that and do nothing.

drivers/net/ethernet/cavium/octeon/octeon3-core.c line 1479

Quoted 4 lines
drivers/net/ethernet/cavium/octeon/octeon3-core.c new file +4 -0
+
+	/* Build the pko command */
+	pko_send_desc = build_pko_send_hdr_desc(skb);
+	preempt_disable();

Why do you disable preemption here?

Quoted 85 lines
drivers/net/ethernet/cavium/octeon/octeon3-core.c new file +85 -0
+	scratch_write64(scr_off, pko_send_desc);
+	scr_off += sizeof(pko_send_desc);
+
+	/* Request packet to be ptp timestamped */
+	if ((unlikely(skb_shinfo(skb)->tx_flags & SKBTX_HW_TSTAMP)) &&
+	    unlikely(priv->tx_timestamp_hw)) {
+		pko_send_desc = build_pko_send_ext_desc(skb);
+		scratch_write64(scr_off, pko_send_desc);
+		scr_off += sizeof(pko_send_desc);
+	}
+
+	/* Add the tso descriptor if needed */
+	mss = skb_shinfo(skb)->gso_size;
+	if (unlikely(mss)) {
+		pko_send_desc = build_pko_send_tso(skb, netdev->mtu);
+		scratch_write64(scr_off, pko_send_desc);
+		scr_off += sizeof(pko_send_desc);
+	}
+
+	/* Add a gather descriptor for each segment. See PKO_SEND_GATHER_S for
+	 * the send gather descriptor format.
+	 */
+	pko_send_desc = 0;
+	pko_send_desc |= (u64)PKO_SENDSUBDC_GATHER << 45;
+	head_len = skb_headlen(skb);
+	if (head_len > 0) {
+		pko_send_desc |= head_len << 48;
+		pko_send_desc |= virt_to_phys(skb->data);
+		scratch_write64(scr_off, pko_send_desc);
+		scr_off += sizeof(pko_send_desc);
+	}
+	for (i = 1; i <= skb_shinfo(skb)->nr_frags; i++) {
+		struct skb_frag_struct *fs = skb_shinfo(skb)->frags + i - 1;
+
+		pko_send_desc &= ~(GENMASK_ULL(63, 48) | GENMASK_ULL(41, 0));
+		pko_send_desc |= (u64)fs->size << 48;
+		pko_send_desc |= virt_to_phys((u8 *)page_address(fs->page.p) + fs->page_offset);
+		scratch_write64(scr_off, pko_send_desc);
+		scr_off += sizeof(pko_send_desc);
+	}
+	skb_walk_frags(skb, skb_tmp) {
+		pko_send_desc &= ~(GENMASK_ULL(63, 48) | GENMASK_ULL(41, 0));
+		pko_send_desc |= (u64)skb_tmp->len << 48;
+		pko_send_desc |= virt_to_phys(skb_tmp->data);
+		scratch_write64(scr_off, pko_send_desc);
+		scr_off += sizeof(pko_send_desc);
+	}
+
+	/* Subtract 1 from the tx_backlog. */
+	pko_send_desc = build_pko_send_mem_sub(virt_to_phys(&priv->tx_backlog));
+	scratch_write64(scr_off, pko_send_desc);
+	scr_off += sizeof(pko_send_desc);
+
+	/* Write the ptp timestamp in the skb itself */
+	if ((unlikely(skb_shinfo(skb)->tx_flags & SKBTX_HW_TSTAMP)) &&
+	    unlikely(priv->tx_timestamp_hw)) {
+		pko_send_desc = build_pko_send_mem_ts(virt_to_phys(&work[1]));
+		scratch_write64(scr_off, pko_send_desc);
+		scr_off += sizeof(pko_send_desc);
+	}
+
+	/* Send work when finished with the packet. */
+	grp = octeon3_eth_lgrp_to_ggrp(priv->node, priv->tx_complete_grp);
+	pko_send_desc = build_pko_send_work(grp, virt_to_phys(work));
+	scratch_write64(scr_off, pko_send_desc);
+	scr_off += sizeof(pko_send_desc);
+
+	/* See PKO_SEND_DMA_S in the HRM for the lmtdam data format */
+	lmtdma_data = 0;
+	lmtdma_data |= (u64)(LMTDMA_SCR_OFFSET >> 3) << 56;
+	if (wait_pko_response)
+		lmtdma_data |= 1ull << 48;
+	lmtdma_data |= 0x51ull << 40;
+	lmtdma_data |= (u64)priv->node << 36;
+	lmtdma_data |= priv->pko_queue << 16;
+
+	dma_addr = (u64 *)(LMTDMA_ORDERED_IO_ADDR | ((scr_off & 0x78) - 8));
+	*dma_addr = lmtdma_data;
+
+	preempt_enable();
+
+	if (wait_pko_response) {
+		u64	query_rtn;
+
+		CVMX_SYNCIOBDMA;

drivers/net/ethernet/cavium/octeon/octeon3-core.c line 1574

Quoted 10 lines
drivers/net/ethernet/cavium/octeon/octeon3-core.c new file +10 -0
+
+		/* See PKO_QUERY_RTN_S in the HRM for the return format */
+		query_rtn = scratch_read64(LMTDMA_SCR_OFFSET);
+		query_rtn >>= 60;
+		if (unlikely(query_rtn != PKO_DQSTATUS_PASS)) {
+			netdev_err(netdev, "PKO enqueue failed %llx\n",
+				   (unsigned long long)query_rtn);
+			dev_kfree_skb_any(skb);
+		}
+	}

So I am not sure I fully understand how sending packets works, although it seems to be like you are building a work element (pko_send_desc) which references either a full-size Ethernet frame, or that frame and its fragments (multiple pko_send_desc). In that case, I don't see why you can't juse dma_map_single()/dma_unmap_single() against skb->data and its potential fragments instead of using virt_to_phys() like you currently do, which is absolutely not portable.

dma_map_single() on the kernel linear address space should be equivalent to virt_to_phys() anyway, and you would get the nice things about DMA-API like its portability.

I could imagine that, for coherency purposes, there may be a requirement to keep tskb->data and frieds to be within XKSEG0/1, if that's the case, DMA-API should know that too.

I might be completely off, but using virt_to_phys() sure does sound non portable here.

Quoted 6 lines
drivers/net/ethernet/cavium/octeon/octeon3-core.c new file +6 -0
+
+	return NETDEV_TX_OK;
+skip_xmit:
+	atomic64_inc(&priv->tx_dropped);
+	dev_kfree_skb_any(skb);
+	return NETDEV_TX_OK;

drivers/net/ethernet/cavium/octeon/octeon3-core.c line 1590

Quoted 10 lines
drivers/net/ethernet/cavium/octeon/octeon3-core.c new file +10 -0
+}
+
+static void octeon3_eth_ndo_get_stats64(struct net_device *netdev,
+					struct rtnl_link_stats64 *s)
+{
+	struct octeon3_ethernet *priv = netdev_priv(netdev);
+	u64 packets, octets, dropped;
+	u64 delta_packets, delta_octets, delta_dropped;
+
+	spin_lock(&priv->stat_lock);

Consider using u64_stats_sync to get rid of this lock...

Quoted 6 lines
drivers/net/ethernet/cavium/octeon/octeon3-core.c new file +6 -0
+
+	octeon3_pki_get_stats(priv->node, priv->pknd, &packets, &octets, &dropped);
+
+	delta_packets = (packets - priv->last_packets) & ((1ull << 48) - 1);
+	delta_octets = (octets - priv->last_octets) & ((1ull << 48) - 1);
+	delta_dropped = (dropped - priv->last_dropped) & ((1ull << 48) - 1);

drivers/net/ethernet/cavium/octeon/octeon3-core.c line 1606

Quoted 10 lines
drivers/net/ethernet/cavium/octeon/octeon3-core.c new file +10 -0
+
+	priv->last_packets = packets;
+	priv->last_octets = octets;
+	priv->last_dropped = dropped;
+
+	spin_unlock(&priv->stat_lock);
+
+	atomic64_add(delta_packets, &priv->rx_packets);
+	atomic64_add(delta_octets, &priv->rx_octets);
+	atomic64_add(delta_dropped, &priv->rx_dropped);

and summing up these things as well.

Quoted 12 lines
drivers/net/ethernet/cavium/octeon/octeon3-core.c new file +12 -0
+
+	s->rx_packets = atomic64_read(&priv->rx_packets);
+	s->rx_bytes = atomic64_read(&priv->rx_octets);
+	s->rx_dropped = atomic64_read(&priv->rx_dropped);
+	s->rx_errors = atomic64_read(&priv->rx_errors);
+	s->rx_length_errors = atomic64_read(&priv->rx_length_errors);
+	s->rx_crc_errors = atomic64_read(&priv->rx_crc_errors);
+
+	s->tx_packets = atomic64_read(&priv->tx_packets);
+	s->tx_bytes = atomic64_read(&priv->tx_octets);
+	s->tx_dropped = atomic64_read(&priv->tx_dropped);
+}

[snip]

drivers/net/ethernet/cavium/octeon/octeon3.h line 318

Quoted 11 lines
drivers/net/ethernet/cavium/octeon/octeon3.h new file +11 -0
+enum port_mode {
+	PORT_MODE_DISABLED,
+	PORT_MODE_SGMII,
+	PORT_MODE_RGMII,
+	PORT_MODE_XAUI,
+	PORT_MODE_RXAUI,
+	PORT_MODE_XLAUI,
+	PORT_MODE_XFI,
+	PORT_MODE_10G_KR,
+	PORT_MODE_40G_KR4
+};

Can you use phy_interface_t values for this?

Quoted 11 lines
drivers/net/ethernet/cavium/octeon/octeon3.h new file +11 -0
+
+enum lane_mode {
+	R_25G_REFCLK100,
+	R_5G_REFCLK100,
+	R_8G_REFCLK100,
+	R_125G_REFCLK15625_KX,
+	R_3125G_REFCLK15625_XAUI,
+	R_103125G_REFCLK15625_KR,
+	R_125G_REFCLK15625_SGMII,
+	R_5G_REFCLK15625_QSGMII,
+	R_625G_REFCLK15625_RXAUI,

drivers/net/ethernet/cavium/octeon/octeon3.h line 339

Quoted 10 lines
drivers/net/ethernet/cavium/octeon/octeon3.h new file +10 -0
+	R_25G_REFCLK125,
+	R_5G_REFCLK125,
+	R_8G_REFCLK125
+};
+
+struct port_status {
+	int	link;
+	int	duplex;
+	int	speed;
+};

Likewise, using phy_device would give you this information.

Signature · 1 line
Florian
#28 lore raw

Re: [PATCH 6/7] netdev: octeon-ethernet: Add Cavium Octeon III support.

Quoted 26 lines · Florian Fainelli
Quoted 19 lines · David Daney

From: Carlos Munoz <cmunoz-YGCgFSpz5w/[email protected]>

The Cavium OCTEON cn78xx and cn73xx SoCs have network packet I/O hardware that is significantly different from previous generations of the family.

Add a new driver for this hardware. The Ethernet MAC is called BGX on these devices. Common code for the MAC is in octeon3-bgx-port.c. Four of these BGX MACs are grouped together and managed as a group by octeon3-bgx-nexus.c. Ingress packet classification is done by the PKI unit initialized in octeon3-pki.c. Queue management is done in the SSO, initialized by octeon3-sso.c. Egress is handled by the PKO, initialized in octeon3-pko.c.

---

drivers/net/ethernet/cavium/octeon/octeon3-bgx-nexus.c line 24

Quoted 3 lines
drivers/net/ethernet/cavium/octeon/octeon3-bgx-nexus.c new file +3 -0
+static char *mix_port;
+module_param(mix_port, charp, 0444);
+MODULE_PARM_DESC(mix_port, "Specifies which ports connect to MIX interfaces.");

Can you derive this from Device Tree /platform data configuration?

Quoted 6 lines

drivers/net/ethernet/cavium/octeon/octeon3-bgx-nexus.c line 28

Quoted 4 lines
drivers/net/ethernet/cavium/octeon/octeon3-bgx-nexus.c new file +4 -0
+
+static char *pki_port;
+module_param(pki_port, charp, 0444);
+MODULE_PARM_DESC(pki_port, "Specifies which ports connect to the PKI.");

Likewise

The SoC is flexible in how it is configured. Technically the device tree should only be used to specify information about the physical configuration of the system that cannot be probed for, and this is about policy rather that physical wiring. That said, we do take the default configuration from the device tree, but give the option here to override via the module command line.

Quoted 30 lines
Quoted 30 lines
drivers/net/ethernet/cavium/octeon/octeon3-bgx-nexus.c new file +29 -0
+
+#define MAX_MIX_PER_NODE	2
+
+#define MAX_MIX			(MAX_NODES * MAX_MIX_PER_NODE)
+
+/**
+ * struct mix_port_lmac - Describes a lmac that connects to a mix
+ *			  port. The lmac must be on the same node as
+ *			  the mix.
+ * @node:	Node of the lmac.
+ * @bgx:	Bgx of the lmac.
+ * @lmac:	Lmac index.
+ */
+struct mix_port_lmac {
+	int	node;
+	int	bgx;
+	int	lmac;
+};
+
+/* mix_ports_lmacs contains all the lmacs connected to mix ports */
+static struct mix_port_lmac mix_port_lmacs[MAX_MIX];
+
+/* pki_ports keeps track of the lmacs connected to the pki */
+static bool pki_ports[MAX_NODES][MAX_BGX_PER_NODE][MAX_LMAC_PER_BGX];
+
+/* Created platform devices get added to this list */
+static struct list_head pdev_list;
+static struct mutex pdev_list_lock;
+
Quoted 8 lines

drivers/net/ethernet/cavium/octeon/octeon3-bgx-nexus.c line 62

Quoted 5 lines
drivers/net/ethernet/cavium/octeon/octeon3-bgx-nexus.c new file +5 -0
+/* Created platform device use this structure to add themselves to the list */
+struct pdev_list_item {
+	struct list_head	list;
+	struct platform_device	*pdev;
+};

Don't you have a top-level platform device that you could use which would hold this data instead of having it here?

This is the top-level platform device.

Quoted 19 lines

[snip]

Quoted 4 lines
drivers/net/ethernet/cavium/octeon/octeon3-core.c new file +4 -0
+/* Registers are accessed via xkphys */
+#define SSO_BASE			0x1670000000000ull
+#define SSO_ADDR(node)			(SET_XKPHYS + NODE_OFFSET(node) +      \
+					 SSO_BASE)

drivers/net/ethernet/cavium/octeon/octeon3-core.c line 149

Quoted 10 lines
drivers/net/ethernet/cavium/octeon/octeon3-core.c new file +10 -0
+#define GRP_OFFSET(grp)			((grp) << 16)
+#define GRP_ADDR(n, g)			(SSO_ADDR(n) + GRP_OFFSET(g))
+#define SSO_GRP_AQ_CNT(n, g)		(GRP_ADDR(n, g)		   + 0x20000700)
+
+#define MIO_PTP_BASE			0x1070000000000ull
+#define MIO_PTP_ADDR(node)		(SET_XKPHYS + NODE_OFFSET(node) +      \
+					 MIO_PTP_BASE)
+#define MIO_PTP_CLOCK_CFG(node)		(MIO_PTP_ADDR(node)		+ 0xf00)
+#define MIO_PTP_CLOCK_HI(node)		(MIO_PTP_ADDR(node)		+ 0xf10)
+#define MIO_PTP_CLOCK_COMP(node)	(MIO_PTP_ADDR(node)		+ 0xf18)

I am sure this will work great on anything but MIPS64 ;)

Sarcasm duly noted.

That said, by definition it is exactly an OCTEON-III/MIPS64, and can never be anything else. It is known a priori that the hardware and this driver will never be used anywhere else.

Quoted 42 lines
Quoted 42 lines
drivers/net/ethernet/cavium/octeon/octeon3-core.c new file +41 -0
+
+struct octeon3_ethernet;
+
+struct octeon3_rx {
+	struct napi_struct	napi;
+	struct octeon3_ethernet *parent;
+	int rx_grp;
+	int rx_irq;
+	cpumask_t rx_affinity_hint;
+} ____cacheline_aligned_in_smp;
+
+struct octeon3_ethernet {
+	struct bgx_port_netdev_priv bgx_priv; /* Must be first element. */
+	struct list_head list;
+	struct net_device *netdev;
+	enum octeon3_mac_type mac_type;
+	struct octeon3_rx rx_cxt[MAX_RX_QUEUES];
+	struct ptp_clock_info ptp_info;
+	struct ptp_clock *ptp_clock;
+	struct cyclecounter cc;
+	struct timecounter tc;
+	spinlock_t ptp_lock;		/* Serialize ptp clock adjustments */
+	int num_rx_cxt;
+	int pki_aura;
+	int pknd;
+	int pko_queue;
+	int node;
+	int interface;
+	int index;
+	int rx_buf_count;
+	int tx_complete_grp;
+	int rx_timestamp_hw:1;
+	int tx_timestamp_hw:1;
+	spinlock_t stat_lock;		/* Protects stats counters */
+	u64 last_packets;
+	u64 last_octets;
+	u64 last_dropped;
+	atomic64_t rx_packets;
+	atomic64_t rx_octets;
+	atomic64_t rx_dropped;
+	atomic64_t rx_errors;
Quoted 8 lines

drivers/net/ethernet/cavium/octeon/octeon3-core.c line 195

Quoted 5 lines
drivers/net/ethernet/cavium/octeon/octeon3-core.c new file +5 -0
+	atomic64_t rx_length_errors;
+	atomic64_t rx_crc_errors;
+	atomic64_t tx_packets;
+	atomic64_t tx_octets;
+	atomic64_t tx_dropped;

Do you really need those to be truly atomic64_t types, can't you use u64 and use the helpers from u64_stats_sync.h? That should be good enough?

There is room for improvement here. We probably need to keep statistics per queue, and then the atomic business would be unnecessary.

Quoted 42 lines
Quoted 42 lines
drivers/net/ethernet/cavium/octeon/octeon3-core.c new file +41 -0
+	/* The following two fields need to be on a different cache line as
+	 * they are updated by pko which invalidates the cache every time it
+	 * updates them. The idea is to prevent other fields from being
+	 * invalidated unnecessarily.
+	 */
+	char cacheline_pad1[CVMX_CACHE_LINE_SIZE];
+	atomic64_t buffers_needed;
+	atomic64_t tx_backlog;
+	char cacheline_pad2[CVMX_CACHE_LINE_SIZE];
+};
+
+static DEFINE_MUTEX(octeon3_eth_init_mutex);
+
+struct octeon3_ethernet_node;
+
+struct octeon3_ethernet_worker {
+	wait_queue_head_t queue;
+	struct task_struct *task;
+	struct octeon3_ethernet_node *oen;
+	atomic_t kick;
+	int order;
+};
+
+struct octeon3_ethernet_node {
+	bool init_done;
+	int next_cpu_irq_affinity;
+	int node;
+	int pki_packet_pool;
+	int sso_pool;
+	int pko_pool;
+	void *sso_pool_stack;
+	void *pko_pool_stack;
+	void *pki_packet_pool_stack;
+	int sso_aura;
+	int pko_aura;
+	int tx_complete_grp;
+	int tx_irq;
+	cpumask_t tx_affinity_hint;
+	struct octeon3_ethernet_worker workers[8];
+	struct mutex device_list_lock;	/* Protects the device list */
+	struct list_head device_list;
Quoted 8 lines

drivers/net/ethernet/cavium/octeon/octeon3-core.c line 242

Quoted 6 lines
drivers/net/ethernet/cavium/octeon/octeon3-core.c new file +6 -0
+	spinlock_t napi_alloc_lock;	/* Protects napi allocations */
+};
+
+static int wait_pko_response;
+module_param(wait_pko_response, int, 0644);
+MODULE_PARM_DESC(wait_pko_response, "Wait for response after each pko command.");

Under which circumstances is this used?

Rarely if ever, I think I will remove it.

Quoted 8 lines

drivers/net/ethernet/cavium/octeon/octeon3-core.c line 247

Quoted 6 lines
drivers/net/ethernet/cavium/octeon/octeon3-core.c new file +5 -0
+
+static int num_packet_buffers = 768;
+module_param(num_packet_buffers, int, 0444);
+MODULE_PARM_DESC(num_packet_buffers,
+		 "Number of packet buffers to allocate per port.");

Consider implementing ethtool -g/G for this.

That may be work for a follow-on patch.

Quoted 7 lines

drivers/net/ethernet/cavium/octeon/octeon3-core.c line 251

Quoted 5 lines
drivers/net/ethernet/cavium/octeon/octeon3-core.c new file +4 -0
+
+static int packet_buffer_size = 2048;
+module_param(packet_buffer_size, int, 0444);
+MODULE_PARM_DESC(packet_buffer_size, "Size of each RX packet buffer.");

How is that different from adjusting the network device's MTU?

Multiple buffers may be linked together creating a fragmented packet for MTU greater than packet_buffer_size.

MTU controls which packets are rejected because they are too large. packet_buffer_size is the size of the RX buffers.

Quoted 7 lines

drivers/net/ethernet/cavium/octeon/octeon3-core.c line 255

Quoted 5 lines
drivers/net/ethernet/cavium/octeon/octeon3-core.c new file +4 -0
+
+static int rx_queues = 1;
+module_param(rx_queues, int, 0444);
+MODULE_PARM_DESC(rx_queues, "Number of RX threads per port.");

Same thing, can you consider using an ethtool knob for that?

Also may be work for a follow-on patch.

Quoted 18 lines
Quoted 18 lines
drivers/net/ethernet/cavium/octeon/octeon3-core.c new file +17 -0
+
+int ilk0_lanes = 1;
+module_param(ilk0_lanes, int, 0444);
+MODULE_PARM_DESC(ilk0_lanes, "Number of SerDes lanes used by ILK link 0.");
+
+int ilk1_lanes = 1;
+module_param(ilk1_lanes, int, 0444);
+MODULE_PARM_DESC(ilk1_lanes, "Number of SerDes lanes used by ILK link 1.");
+
+static struct octeon3_ethernet_node octeon3_eth_node[MAX_NODES];
+static struct kmem_cache *octeon3_eth_sso_pko_cache;
+
+/**
+ * Reads a 64 bit value from the processor local scratchpad memory.
+ *
+ * @param offset byte offset into scratch pad to read
+ *
Quoted 8 lines

drivers/net/ethernet/cavium/octeon/octeon3-core.c line 278

Quoted 6 lines

+ * @return value read
+ */

drivers/net/ethernet/cavium/octeon/octeon3-core.c new file +4 -0
+static inline u64 scratch_read64(u64 offset)
+{
+	return *(u64 *)((long)SCRATCH_BASE + offset);
+}

No barriers needed whatsoever?

Nope.

Quoted 82 lines
Quoted 82 lines
drivers/net/ethernet/cavium/octeon/octeon3-core.c new file +81 -0
+
+/**
+ * Write a 64 bit value to the processor local scratchpad memory.
+ *
+ * @param offset byte offset into scratch pad to write
+ @ @praram value to write
+ */
+static inline void scratch_write64(u64 offset, u64 value)
+{
+	*(u64 *)((long)SCRATCH_BASE + offset) = value;
+}
+
+static int get_pki_chan(int node, int interface, int index)
+{
+	int	pki_chan;
+
+	pki_chan = node << 12;
+
+	if (OCTEON_IS_MODEL(OCTEON_CNF75XX) &&
+	    (interface == 1 || interface == 2)) {
+		/* SRIO */
+		pki_chan |= 0x240 + (2 * (interface - 1)) + index;
+	} else {
+		/* BGX */
+		pki_chan |= 0x800 + (0x100 * interface) + (0x10 * index);
+	}
+
+	return pki_chan;
+}
+
+/* Map auras to the field priv->buffers_needed. Used to speed up packet
+ * transmission.
+ */
+static void *aura2bufs_needed[MAX_NODES][FPA3_NUM_AURAS];
+
+static int octeon3_eth_lgrp_to_ggrp(int node, int grp)
+{
+	return (node << 8) | grp;
+}
+
+static void octeon3_eth_gen_affinity(int node, cpumask_t *mask)
+{
+	int cpu;
+
+	do {
+		cpu = cpumask_next(octeon3_eth_node[node].next_cpu_irq_affinity, cpu_online_mask);
+		octeon3_eth_node[node].next_cpu_irq_affinity++;
+		if (cpu >= nr_cpu_ids) {
+			octeon3_eth_node[node].next_cpu_irq_affinity = -1;
+			continue;
+		}
+	} while (false);
+	cpumask_clear(mask);
+	cpumask_set_cpu(cpu, mask);
+}
+
+struct wr_ret {
+	void *work;
+	u16 grp;
+};
+
+static inline struct wr_ret octeon3_core_get_work_sync(int grp)
+{
+	u64		node = cvmx_get_node_num();
+	u64		addr;
+	u64		response;
+	struct wr_ret	r;
+
+	/* See SSO_GET_WORK_LD_S for the address to read */
+	addr = 1ull << 63;
+	addr |= BIT(48);
+	addr |= DID_TAG_SWTAG << 40;
+	addr |= node << 36;
+	addr |= BIT(30);
+	addr |= BIT(29);
+	addr |= octeon3_eth_lgrp_to_ggrp(node, grp) << 4;
+	addr |= SSO_NO_WAIT << 3;
+	response = __raw_readq((void __iomem *)addr);
+
+	/* See SSO_GET_WORK_RTN_S for the format of the response */
+	r.grp = (response & GENMASK_ULL(57, 48)) >> 48;
Quoted 8 lines

drivers/net/ethernet/cavium/octeon/octeon3-core.c line 363

Quoted 4 lines
drivers/net/ethernet/cavium/octeon/octeon3-core.c new file +4 -0
+	if (response & BIT(63))
+		r.work = NULL;
+	else
+		r.work = phys_to_virt(response & GENMASK_ULL(41, 0));

There are quite a lot of phys_to_virt() and virt_to_phys() uses throughout this driver, this will likely not work on anything but MIPS64, so there should be a better way, abstracted to do this, see below.

See above, this is OCTEON-III/MIPS64 only. More abstractions don't solve any problems, and may introduce function calls in the hot path with their associated pipeline stalls and branch mispredictions.

Quoted 61 lines
Quoted 61 lines
drivers/net/ethernet/cavium/octeon/octeon3-core.c new file +60 -0
+
+	return r;
+}
+
+/**
+ * octeon3_core_get_work_async - Request work via a iobdma command. Doesn't wait
+ *				 for the response.
+ *
+ * @grp: Group to request work for.
+ */
+static inline void octeon3_core_get_work_async(unsigned int grp)
+{
+	u64	data;
+	u64	node = cvmx_get_node_num();
+
+	/* See SSO_GET_WORK_DMA_S for the command structure */
+	data = SCR_SCRATCH << 56;
+	data |= 1ull << 48;
+	data |= DID_TAG_SWTAG << 40;
+	data |= node << 36;
+	data |= 1ull << 30;
+	data |= 1ull << 29;
+	data |= octeon3_eth_lgrp_to_ggrp(node, grp) << 4;
+	data |= SSO_NO_WAIT << 3;
+
+	__raw_writeq(data, (void __iomem *)IOBDMA_SENDSINGLE);
+}
+
+/**
+ * octeon3_core_get_response_async - Read the request work response. Must be
+ *				     called after calling
+ *				     octeon3_core_get_work_async().
+ *
+ * Returns work queue entry.
+ */
+static inline struct wr_ret octeon3_core_get_response_async(void)
+{
+	struct wr_ret	r;
+	u64		response;
+
+	CVMX_SYNCIOBDMA;
+	response = scratch_read64(SCR_SCRATCH);
+
+	/* See SSO_GET_WORK_RTN_S for the format of the response */
+	r.grp = (response & GENMASK_ULL(57, 48)) >> 48;
+	if (response & BIT(63))
+		r.work = NULL;
+	else
+		r.work = phys_to_virt(response & GENMASK_ULL(41, 0));
+
+	return r;
+}
+
+static void octeon3_eth_replenish_rx(struct octeon3_ethernet *priv, int count)
+{
+	struct sk_buff *skb;
+	int i;
+
+	for (i = 0; i < count; i++) {
+		void **buf;
Quoted 8 lines

drivers/net/ethernet/cavium/octeon/octeon3-core.c line 429

Quoted 6 lines
drivers/net/ethernet/cavium/octeon/octeon3-core.c new file +6 -0
+
+		skb = __alloc_skb(packet_buffer_size, GFP_ATOMIC, 0, priv->node);
+		if (!skb)
+			break;
+		buf = (void **)PTR_ALIGN(skb->head, 128);
+		buf[SKB_PTR_OFFSET] = skb;

Can you use build_skb()?

In theory we could, but that would require changing the architecture of the driver to use page fragments. For better or worse, the choice was made to use __alloc_skb() instead.

Quoted 22 lines
Quoted 5 lines
drivers/net/ethernet/cavium/octeon/octeon3-core.c new file +4 -0
+		octeon_fpa3_free(priv->node, priv->pki_aura, buf);
+	}
+}
+

[snip]

Quoted 14 lines
drivers/net/ethernet/cavium/octeon/octeon3-core.c new file +14 -0
+static int octeon3_eth_tx_complete_worker(void *data)
+{
+	struct octeon3_ethernet_worker *worker = data;
+	struct octeon3_ethernet_node *oen = worker->oen;
+	int backlog;
+	int order = worker->order;
+	int tx_complete_stop_thresh = order * 100;
+	int backlog_stop_thresh = order == 0 ? 31 : order * 80;
+	u64 aq_cnt;
+	int i;
+
+	while (!kthread_should_stop()) {
+		wait_event_interruptible(worker->queue, octeon3_eth_tx_complete_runnable(worker));
+		atomic_dec_if_positive(&worker->kick); /* clear the flag */
Quoted 8 lines

drivers/net/ethernet/cavium/octeon/octeon3-core.c line 491

Quoted 4 lines
drivers/net/ethernet/cavium/octeon/octeon3-core.c new file +4 -0
+
+		do {
+			backlog = octeon3_eth_replenish_all(oen);
+			for (i = 0; i < 100; i++) {

Do you really want to bound your TX reclamation worker, all other network drivers never bound their napi TX completion task and instead reclaim every transmitted buffers.

They are not bounded, just chunked. Note the outer do loop.

Quoted 15 lines
Quoted 15 lines
drivers/net/ethernet/cavium/octeon/octeon3-core.c new file +14 -0
+				void **work;
+				struct net_device *tx_netdev;
+				struct octeon3_ethernet *tx_priv;
+				struct sk_buff *skb;
+				struct wr_ret r;
+
+				r = octeon3_core_get_work_sync(oen->tx_complete_grp);
+				work = r.work;
+				if (!work)
+					break;
+				tx_netdev = work[0];
+				tx_priv = netdev_priv(tx_netdev);
+				if (unlikely(netif_queue_stopped(tx_netdev)) &&
+				    atomic64_read(&tx_priv->tx_backlog) < MAX_TX_QUEUE_DEPTH)
Quoted 8 lines

drivers/net/ethernet/cavium/octeon/octeon3-core.c line 510

Quoted 5 lines
drivers/net/ethernet/cavium/octeon/octeon3-core.c new file +5 -0
+					netif_wake_queue(tx_netdev);
+				skb = container_of((void *)work, struct sk_buff, cb);
+				if (unlikely(tx_priv->tx_timestamp_hw) &&
+				    unlikely(skb_shinfo(skb)->tx_flags & SKBTX_IN_PROGRESS))
+					octeon3_eth_tx_complete_hwtstamp(tx_priv, skb);

This is where you should be incremeting the TX bytes and packets statistcs, not in your ndo_start_xmit() like you are currently doing.

See below...

Quoted 4 lines

Review

Quoted 2 lines
(quoted diff) +1 -0
+				dev_kfree_skb(skb);

Consider using dev_consume_skb() to be drop-monitor friendly.

I will look at that.

Quoted 24 lines
Quoted 24 lines
drivers/net/ethernet/cavium/octeon/octeon3-core.c new file +23 -0
+			}
+
+			aq_cnt = oct_csr_read(SSO_GRP_AQ_CNT(oen->node, oen->tx_complete_grp));
+			aq_cnt &= GENMASK_ULL(32, 0);
+			if ((backlog > backlog_stop_thresh || aq_cnt > tx_complete_stop_thresh) &&
+			    order < ARRAY_SIZE(oen->workers) - 1) {
+				atomic_set(&oen->workers[order + 1].kick, 1);
+				wake_up(&oen->workers[order + 1].queue);
+			}
+		} while (!need_resched() &&
+			 (backlog > backlog_stop_thresh ||
+			  aq_cnt > tx_complete_stop_thresh));
+
+		cond_resched();
+
+		if (!octeon3_eth_tx_complete_runnable(worker))
+			octeon3_sso_irq_set(oen->node, oen->tx_complete_grp, true);
+	}
+
+	return 0;
+}
+
+static irqreturn_t octeon3_eth_tx_handler(int irq, void *info)
Quoted 8 lines

drivers/net/ethernet/cavium/octeon/octeon3-core.c line 540

Quoted 6 lines
drivers/net/ethernet/cavium/octeon/octeon3-core.c new file +6 -0
+{
+	struct octeon3_ethernet_node *oen = info;
+	/* Disarm the irq. */
+	octeon3_sso_irq_set(oen->node, oen->tx_complete_grp, false);
+	atomic_set(&oen->workers[0].kick, 1);
+	wake_up(&oen->workers[0].queue);

Can you move the whole worker to a NAPI context/softirq context?

This could be an enhancement.

Quoted 4 lines
Quoted 4 lines
drivers/net/ethernet/cavium/octeon/octeon3-core.c new file +3 -0
+	return IRQ_HANDLED;
+}
+

[...]

Quoted 30 lines
Quoted 30 lines
drivers/net/ethernet/cavium/octeon/octeon3-core.c new file +30 -0
+
+		/* Strip the ethernet fcs */
+		pskb_trim(skb, skb->len - 4);
+	}
+
+	if (likely(priv->netdev->flags & IFF_UP)) {
+		skb_checksum_none_assert(skb);
+		if (unlikely(priv->rx_timestamp_hw)) {
+			/* The first 8 bytes are the timestamp */
+			u64 hwts = *(u64 *)skb->data;
+			u64 ns;
+			struct skb_shared_hwtstamps *shts;
+
+			ns = timecounter_cyc2time(&priv->tc, hwts);
+			shts = skb_hwtstamps(skb);
+			memset(shts, 0, sizeof(*shts));
+			shts->hwtstamp = ns_to_ktime(ns);
+			__skb_pull(skb, 8);
+		}
+
+		skb->protocol = eth_type_trans(skb, priv->netdev);
+		skb->dev = priv->netdev;
+		if (priv->netdev->features & NETIF_F_RXCSUM) {
+			if ((work->word2.lc_hdr_type == PKI_LTYPE_IP4 ||
+			     work->word2.lc_hdr_type == PKI_LTYPE_IP6) &&
+			    (work->word2.lf_hdr_type == PKI_LTYPE_TCP ||
+			     work->word2.lf_hdr_type == PKI_LTYPE_UDP ||
+			     work->word2.lf_hdr_type == PKI_LTYPE_SCTP))
+				if (work->word2.err_code == 0)
+					skb->ip_summed = CHECKSUM_UNNECESSARY;
Quoted 8 lines

drivers/net/ethernet/cavium/octeon/octeon3-core.c line 838

Quoted 5 lines
drivers/net/ethernet/cavium/octeon/octeon3-core.c new file +5 -0
+		}
+
+		napi_gro_receive(&rx->napi, skb);
+	} else {
+		/* Drop any packet received for a device that isn't up */

If that happens, is not that a blatant indication that there is a bug in how the interface is brought down?

Yes. I think we can remove this bit.

Quoted 77 lines
Quoted 77 lines
drivers/net/ethernet/cavium/octeon/octeon3-core.c new file +76 -0
+		atomic64_inc(&priv->rx_dropped);
+		dev_kfree_skb_any(skb);
+	}
+out:
+	return ret;
+}
+
+static int octeon3_eth_napi(struct napi_struct *napi, int budget)
+{
+	int rx_count = 0;
+	struct octeon3_rx *cxt;
+	struct octeon3_ethernet *priv;
+	u64 aq_cnt;
+	int n = 0;
+	int n_bufs = 0;
+	u64 old_scratch;
+
+	cxt = container_of(napi, struct octeon3_rx, napi);
+	priv = cxt->parent;
+
+	/* Get the amount of work pending */
+	aq_cnt = oct_csr_read(SSO_GRP_AQ_CNT(priv->node, cxt->rx_grp));
+	aq_cnt &= GENMASK_ULL(32, 0);
+
+	if (likely(USE_ASYNC_IOBDMA)) {
+		/* Save scratch in case userspace is using it */
+		CVMX_SYNCIOBDMA;
+		old_scratch = scratch_read64(SCR_SCRATCH);
+
+		octeon3_core_get_work_async(cxt->rx_grp);
+	}
+
+	while (rx_count < budget) {
+		n = 0;
+
+		if (likely(USE_ASYNC_IOBDMA)) {
+			bool req_next = rx_count < (budget - 1) ? true : false;
+
+			n = octeon3_eth_rx_one(cxt, true, req_next);
+		} else {
+			n = octeon3_eth_rx_one(cxt, false, false);
+		}
+
+		if (n == 0)
+			break;
+
+		n_bufs += n;
+		rx_count++;
+	}
+
+	/* Wake up worker threads */
+	n_bufs = atomic64_add_return(n_bufs, &priv->buffers_needed);
+	if (n_bufs >= 32) {
+		struct octeon3_ethernet_node *oen;
+
+		oen = octeon3_eth_node + priv->node;
+		atomic_set(&oen->workers[0].kick, 1);
+		wake_up(&oen->workers[0].queue);
+	}
+
+	/* Stop the thread when no work is pending */
+	if (rx_count < budget) {
+		napi_complete(napi);
+		octeon3_sso_irq_set(cxt->parent->node, cxt->rx_grp, true);
+	}
+
+	if (likely(USE_ASYNC_IOBDMA)) {
+		/* Restore the scratch area */
+		scratch_write64(SCR_SCRATCH, old_scratch);
+	}
+
+	return rx_count;
+}
+
+#undef BROKEN_SIMULATOR_CSUM
+
Quoted 8 lines

drivers/net/ethernet/cavium/octeon/octeon3-core.c line 920

Quoted 6 lines
drivers/net/ethernet/cavium/octeon/octeon3-core.c new file +6 -0
+static void ethtool_get_drvinfo(struct net_device *netdev,
+				struct ethtool_drvinfo *info)
+{
+	strcpy(info->driver, "octeon3-ethernet");
+	strcpy(info->version, "1.0");
+	strcpy(info->bus_info, "Builtin");

I believe the correct way to specify that type of bus is to use "platform".

OK.

Quoted 17 lines

[snip]

drivers/net/ethernet/cavium/octeon/octeon3-core.c line 1225

Quoted 10 lines
drivers/net/ethernet/cavium/octeon/octeon3-core.c new file +10 -0
+static int octeon3_eth_common_ndo_stop(struct net_device *netdev)
+{
+	struct octeon3_ethernet *priv = netdev_priv(netdev);
+	void **w;
+	struct sk_buff *skb;
+	struct octeon3_rx *rx;
+	int i;
+
+	/* Allow enough time for ingress in transit packets to be drained */
+	msleep(20);

Can you find a better way to do that? You can put a hard disable on the hardware, and then wait until a particular condition to indicate full drainage?

We are doing the "hard disable", we must wait a non-zero (but bounded) abount of time before we can reliably do the polling for the backlog to reach zero. Perhaps the comment is all that needs improving.

Quoted 12 lines

[snip]

Quoted 9 lines
drivers/net/ethernet/cavium/octeon/octeon3-core.c new file +9 -0
+static int octeon3_eth_ndo_start_xmit(struct sk_buff *skb,
+				      struct net_device *netdev)
+{
+	struct sk_buff *skb_tmp;
+	struct octeon3_ethernet *priv = netdev_priv(netdev);
+	u64 scr_off = LMTDMA_SCR_OFFSET;
+	u64 pko_send_desc;
+	u64 lmtdma_data;
+	u64 aq_cnt = 0;
Quoted 8 lines

drivers/net/ethernet/cavium/octeon/octeon3-core.c line 1436

Quoted 6 lines
drivers/net/ethernet/cavium/octeon/octeon3-core.c new file +6 -0
+	struct octeon3_ethernet_node *oen;
+	long backlog;
+	int frag_count;
+	u64 head_len;
+	int i;
+	u64 *dma_addr;

dma_addr_t?

Nope.

Perhaps we should rename the variable to:

u64 *lmtdma_addr;

It is a very special virtual address that must have the command word written into it.

Quoted 22 lines
Quoted 22 lines
drivers/net/ethernet/cavium/octeon/octeon3-core.c new file +21 -0
+	void **work;
+	unsigned int mss;
+	int grp;
+
+	frag_count = 0;
+	if (skb_has_frag_list(skb))
+		skb_walk_frags(skb, skb_tmp)
+			frag_count++;
+
+	/* Stop the queue if pko or sso are not keeping up */
+	oen = octeon3_eth_node + priv->node;
+	aq_cnt = oct_csr_read(SSO_GRP_AQ_CNT(oen->node, oen->tx_complete_grp));
+	aq_cnt &= GENMASK_ULL(32, 0);
+	backlog = atomic64_inc_return(&priv->tx_backlog);
+	if (unlikely(backlog > MAX_TX_QUEUE_DEPTH || aq_cnt > 100000))
+		netif_stop_queue(netdev);
+
+	/* We have space for 11 segment pointers, If there will be
+	 * more than that, we must linearize.  The count is: 1 (base
+	 * SKB) + frag_count + nr_frags.
+	 */
Quoted 8 lines

drivers/net/ethernet/cavium/octeon/octeon3-core.c line 1462

Quoted 5 lines
drivers/net/ethernet/cavium/octeon/octeon3-core.c new file +5 -0
+	if (unlikely(skb_shinfo(skb)->nr_frags + frag_count > 10)) {
+		if (unlikely(__skb_linearize(skb)))
+			goto skip_xmit;
+		frag_count = 0;
+	}

What's so special about 10? The maximum the network stack could pass is SKB_MAX_FRAGS, what would happen in that case?

The comment attempts to answer this question.

The command block to the PKO consists of between 1 and 16 64-bit command words. 5 of these command words are needed for non-segment-pointer use, leaving 11 available for segment pointers.

Quoted 12 lines

drivers/net/ethernet/cavium/octeon/octeon3-core.c line 1470

Quoted 9 lines
drivers/net/ethernet/cavium/octeon/octeon3-core.c new file +8 -0
+
+	work = (void **)skb->cb;
+	work[0] = netdev;
+	work[1] = NULL;
+
+	/* Adjust the port statistics. */
+	atomic64_inc(&priv->tx_packets);
+	atomic64_add(skb->len, &priv->tx_octets);

Do this in the TX completion worker, there is no guarantee the packet will be transmitted that early in this function.

When we start doing XDP based forwarding, there is no TX completion event to software, so the simplest thing to do is account for things here.

Quoted 11 lines

drivers/net/ethernet/cavium/octeon/octeon3-core.c line 1475

Quoted 6 lines
drivers/net/ethernet/cavium/octeon/octeon3-core.c new file +5 -0
+
+	/* Make sure packet data writes are committed before
+	 * submitting the command below
+	 */
+	wmb();

That seems just wrong here, if your goal is to make sure that e.g:
skb_linearize() did finish its pending writes to DRAM, you need to use DMA-API towards that goal. If the device is cache coherent, DMA-API will know that and do nothing.

It is a problem of write ordering, not cache coherency (OCTEON is fully coherent). That said, the DMA-API does take care of ordering also.

This is really an optimization that skips a bunch of function calls in the hot path.

Quoted 7 lines

drivers/net/ethernet/cavium/octeon/octeon3-core.c line 1479

Quoted 5 lines
drivers/net/ethernet/cavium/octeon/octeon3-core.c new file +4 -0
+
+	/* Build the pko command */
+	pko_send_desc = build_pko_send_hdr_desc(skb);
+	preempt_disable();

Why do you disable preemption here?

So we don't have the overhead of having to save and restore the CPU local memory on each interrupt and task switch.

Quoted 109 lines
Quoted 86 lines
drivers/net/ethernet/cavium/octeon/octeon3-core.c new file +85 -0
+	scratch_write64(scr_off, pko_send_desc);
+	scr_off += sizeof(pko_send_desc);
+
+	/* Request packet to be ptp timestamped */
+	if ((unlikely(skb_shinfo(skb)->tx_flags & SKBTX_HW_TSTAMP)) &&
+	    unlikely(priv->tx_timestamp_hw)) {
+		pko_send_desc = build_pko_send_ext_desc(skb);
+		scratch_write64(scr_off, pko_send_desc);
+		scr_off += sizeof(pko_send_desc);
+	}
+
+	/* Add the tso descriptor if needed */
+	mss = skb_shinfo(skb)->gso_size;
+	if (unlikely(mss)) {
+		pko_send_desc = build_pko_send_tso(skb, netdev->mtu);
+		scratch_write64(scr_off, pko_send_desc);
+		scr_off += sizeof(pko_send_desc);
+	}
+
+	/* Add a gather descriptor for each segment. See PKO_SEND_GATHER_S for
+	 * the send gather descriptor format.
+	 */
+	pko_send_desc = 0;
+	pko_send_desc |= (u64)PKO_SENDSUBDC_GATHER << 45;
+	head_len = skb_headlen(skb);
+	if (head_len > 0) {
+		pko_send_desc |= head_len << 48;
+		pko_send_desc |= virt_to_phys(skb->data);
+		scratch_write64(scr_off, pko_send_desc);
+		scr_off += sizeof(pko_send_desc);
+	}
+	for (i = 1; i <= skb_shinfo(skb)->nr_frags; i++) {
+		struct skb_frag_struct *fs = skb_shinfo(skb)->frags + i - 1;
+
+		pko_send_desc &= ~(GENMASK_ULL(63, 48) | GENMASK_ULL(41, 0));
+		pko_send_desc |= (u64)fs->size << 48;
+		pko_send_desc |= virt_to_phys((u8 *)page_address(fs->page.p) + fs->page_offset);
+		scratch_write64(scr_off, pko_send_desc);
+		scr_off += sizeof(pko_send_desc);
+	}
+	skb_walk_frags(skb, skb_tmp) {
+		pko_send_desc &= ~(GENMASK_ULL(63, 48) | GENMASK_ULL(41, 0));
+		pko_send_desc |= (u64)skb_tmp->len << 48;
+		pko_send_desc |= virt_to_phys(skb_tmp->data);
+		scratch_write64(scr_off, pko_send_desc);
+		scr_off += sizeof(pko_send_desc);
+	}
+
+	/* Subtract 1 from the tx_backlog. */
+	pko_send_desc = build_pko_send_mem_sub(virt_to_phys(&priv->tx_backlog));
+	scratch_write64(scr_off, pko_send_desc);
+	scr_off += sizeof(pko_send_desc);
+
+	/* Write the ptp timestamp in the skb itself */
+	if ((unlikely(skb_shinfo(skb)->tx_flags & SKBTX_HW_TSTAMP)) &&
+	    unlikely(priv->tx_timestamp_hw)) {
+		pko_send_desc = build_pko_send_mem_ts(virt_to_phys(&work[1]));
+		scratch_write64(scr_off, pko_send_desc);
+		scr_off += sizeof(pko_send_desc);
+	}
+
+	/* Send work when finished with the packet. */
+	grp = octeon3_eth_lgrp_to_ggrp(priv->node, priv->tx_complete_grp);
+	pko_send_desc = build_pko_send_work(grp, virt_to_phys(work));
+	scratch_write64(scr_off, pko_send_desc);
+	scr_off += sizeof(pko_send_desc);
+
+	/* See PKO_SEND_DMA_S in the HRM for the lmtdam data format */
+	lmtdma_data = 0;
+	lmtdma_data |= (u64)(LMTDMA_SCR_OFFSET >> 3) << 56;
+	if (wait_pko_response)
+		lmtdma_data |= 1ull << 48;
+	lmtdma_data |= 0x51ull << 40;
+	lmtdma_data |= (u64)priv->node << 36;
+	lmtdma_data |= priv->pko_queue << 16;
+
+	dma_addr = (u64 *)(LMTDMA_ORDERED_IO_ADDR | ((scr_off & 0x78) - 8));
+	*dma_addr = lmtdma_data;
+
+	preempt_enable();
+
+	if (wait_pko_response) {
+		u64	query_rtn;
+
+		CVMX_SYNCIOBDMA;

drivers/net/ethernet/cavium/octeon/octeon3-core.c line 1574

Quoted 10 lines
drivers/net/ethernet/cavium/octeon/octeon3-core.c new file +10 -0
+
+		/* See PKO_QUERY_RTN_S in the HRM for the return format */
+		query_rtn = scratch_read64(LMTDMA_SCR_OFFSET);
+		query_rtn >>= 60;
+		if (unlikely(query_rtn != PKO_DQSTATUS_PASS)) {
+			netdev_err(netdev, "PKO enqueue failed %llx\n",
+				   (unsigned long long)query_rtn);
+			dev_kfree_skb_any(skb);
+		}
+	}

So I am not sure I fully understand how sending packets works, although it seems to be like you are building a work element (pko_send_desc) which references either a full-size Ethernet frame, or that frame and its fragments (multiple pko_send_desc). In that case, I don't see why you can't juse dma_map_single()/dma_unmap_single() against skb->data and its potential fragments instead of using virt_to_phys() like you currently do, which is absolutely not portable.

dma_map_single() on the kernel linear address space should be equivalent to virt_to_phys() anyway, and you would get the nice things about DMA-API like its portability.

Quoted 6 lines

I could imagine that, for coherency purposes, there may be a requirement to keep tskb->data and frieds to be within XKSEG0/1, if that's the case, DMA-API should know that too.

I might be completely off, but using virt_to_phys() sure does sound non portable here.

The PKO command block with all of its gather dma pointers is written into a special CPU local memory region. The whole thing it atomically transmitted via a store to a special CPU local address window.

We need to keep everything on a single CPU, thus the preempt disable/enable.

The whole mechanism is highly OCTEON specific, and as such it works to use the wmb() and virt_to_phys() macros instead of calling all the dma_map_*() funcitons. Would it be more clear to use dma_map_*()? Perhaps. Would it be slower? Yes.

Quoted 11 lines
Quoted 11 lines
drivers/net/ethernet/cavium/octeon/octeon3-core.c new file +10 -0
+
+	return NETDEV_TX_OK;
+skip_xmit:
+	atomic64_inc(&priv->tx_dropped);
+	dev_kfree_skb_any(skb);
+	return NETDEV_TX_OK;
+}
+
+static void octeon3_eth_ndo_get_stats64(struct net_device *netdev,
+					struct rtnl_link_stats64 *s)
Quoted 8 lines

drivers/net/ethernet/cavium/octeon/octeon3-core.c line 1590

Quoted 6 lines
drivers/net/ethernet/cavium/octeon/octeon3-core.c new file +6 -0
+{
+	struct octeon3_ethernet *priv = netdev_priv(netdev);
+	u64 packets, octets, dropped;
+	u64 delta_packets, delta_octets, delta_dropped;
+
+	spin_lock(&priv->stat_lock);

Consider using u64_stats_sync to get rid of this lock...

My timer went missing. This also has to be called periodically from a timer to catch wraparound in the 48 bit counters.

Locking is still necessary to synchronize between the timer and calls to the get_stat function.

I will sort this out.

Quoted 35 lines
Quoted 7 lines
drivers/net/ethernet/cavium/octeon/octeon3-core.c new file +6 -0
+
+	octeon3_pki_get_stats(priv->node, priv->pknd, &packets, &octets, &dropped);
+
+	delta_packets = (packets - priv->last_packets) & ((1ull << 48) - 1);
+	delta_octets = (octets - priv->last_octets) & ((1ull << 48) - 1);
+	delta_dropped = (dropped - priv->last_dropped) & ((1ull << 48) - 1);

drivers/net/ethernet/cavium/octeon/octeon3-core.c line 1606

Quoted 10 lines
drivers/net/ethernet/cavium/octeon/octeon3-core.c new file +10 -0
+
+	priv->last_packets = packets;
+	priv->last_octets = octets;
+	priv->last_dropped = dropped;
+
+	spin_unlock(&priv->stat_lock);
+
+	atomic64_add(delta_packets, &priv->rx_packets);
+	atomic64_add(delta_octets, &priv->rx_octets);
+	atomic64_add(delta_dropped, &priv->rx_dropped);

and summing up these things as well.

Quoted 12 lines
drivers/net/ethernet/cavium/octeon/octeon3-core.c new file +12 -0
+
+	s->rx_packets = atomic64_read(&priv->rx_packets);
+	s->rx_bytes = atomic64_read(&priv->rx_octets);
+	s->rx_dropped = atomic64_read(&priv->rx_dropped);
+	s->rx_errors = atomic64_read(&priv->rx_errors);
+	s->rx_length_errors = atomic64_read(&priv->rx_length_errors);
+	s->rx_crc_errors = atomic64_read(&priv->rx_crc_errors);
+
+	s->tx_packets = atomic64_read(&priv->tx_packets);
+	s->tx_bytes = atomic64_read(&priv->tx_octets);
+	s->tx_dropped = atomic64_read(&priv->tx_dropped);
+}

[snip]

Quoted 13 lines

drivers/net/ethernet/cavium/octeon/octeon3.h line 318

Quoted 11 lines
drivers/net/ethernet/cavium/octeon/octeon3.h new file +11 -0
+enum port_mode {
+	PORT_MODE_DISABLED,
+	PORT_MODE_SGMII,
+	PORT_MODE_RGMII,
+	PORT_MODE_XAUI,
+	PORT_MODE_RXAUI,
+	PORT_MODE_XLAUI,
+	PORT_MODE_XFI,
+	PORT_MODE_10G_KR,
+	PORT_MODE_40G_KR4
+};

Can you use phy_interface_t values for this?

They have many of the same names, but this enum contains only things we support, and maps to values in register fields. using phy_interface_t might falsly imply we support everything in there.

Quoted 16 lines
Quoted 16 lines
drivers/net/ethernet/cavium/octeon/octeon3.h new file +15 -0
+
+enum lane_mode {
+	R_25G_REFCLK100,
+	R_5G_REFCLK100,
+	R_8G_REFCLK100,
+	R_125G_REFCLK15625_KX,
+	R_3125G_REFCLK15625_XAUI,
+	R_103125G_REFCLK15625_KR,
+	R_125G_REFCLK15625_SGMII,
+	R_5G_REFCLK15625_QSGMII,
+	R_625G_REFCLK15625_RXAUI,
+	R_25G_REFCLK125,
+	R_5G_REFCLK125,
+	R_8G_REFCLK125
+};
Quoted 8 lines

drivers/net/ethernet/cavium/octeon/octeon3.h line 339

Quoted 6 lines
drivers/net/ethernet/cavium/octeon/octeon3.h new file +6 -0
+
+struct port_status {
+	int	link;
+	int	duplex;
+	int	speed;
+};

Likewise, using phy_device would give you this information.

I will look at doing that.

Quoted 1 line

--
To unsubscribe from this list: send the line "unsubscribe devicetree" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html

#29 lore raw

Re: [PATCH 6/7] netdev: octeon-ethernet: Add Cavium Octeon III support.

Quoted 13 lines
Quoted 6 lines

drivers/net/ethernet/cavium/octeon/octeon3-bgx-nexus.c line 24

Quoted 3 lines
drivers/net/ethernet/cavium/octeon/octeon3-bgx-nexus.c new file +3 -0
+static char *mix_port;
+module_param(mix_port, charp, 0444);
+MODULE_PARM_DESC(mix_port, "Specifies which ports connect to MIX interfaces.");

Can you derive this from Device Tree /platform data configuration?

Quoted 6 lines

drivers/net/ethernet/cavium/octeon/octeon3-bgx-nexus.c line 28

Quoted 4 lines
drivers/net/ethernet/cavium/octeon/octeon3-bgx-nexus.c new file +4 -0
+
+static char *pki_port;
+module_param(pki_port, charp, 0444);
+MODULE_PARM_DESC(pki_port, "Specifies which ports connect to the PKI.");

Likewise

Quoted 6 lines

The SoC is flexible in how it is configured. Technically the device tree should only be used to specify information about the physical configuration of the system that cannot be probed for, and this is about policy rather that physical wiring. That said, we do take the default configuration from the device tree, but give the option here to override via the module command line.

Module parameters are pretty much frowned upon.

You should really try to remove them all, if possible.

Quoted 17 lines
Quoted 8 lines
Quoted 8 lines
drivers/net/ethernet/cavium/octeon/octeon3-core.c new file +8 -0
+/* Registers are accessed via xkphys */
+#define SSO_BASE			0x1670000000000ull
+#define SSO_ADDR(node)			(SET_XKPHYS + NODE_OFFSET(node) +      \
+					 SSO_BASE)
+#define GRP_OFFSET(grp)			((grp) << 16)
+#define GRP_ADDR(n, g)			(SSO_ADDR(n) + GRP_OFFSET(g))
+#define SSO_GRP_AQ_CNT(n, g)		(GRP_ADDR(n, g)		   + 0x20000700)
+
Quoted 8 lines

drivers/net/ethernet/cavium/octeon/octeon3-core.c line 149

Quoted 6 lines
drivers/net/ethernet/cavium/octeon/octeon3-core.c new file +6 -0
+#define MIO_PTP_BASE			0x1070000000000ull
+#define MIO_PTP_ADDR(node)		(SET_XKPHYS + NODE_OFFSET(node) +      \
+					 MIO_PTP_BASE)
+#define MIO_PTP_CLOCK_CFG(node)		(MIO_PTP_ADDR(node)		+ 0xf00)
+#define MIO_PTP_CLOCK_HI(node)		(MIO_PTP_ADDR(node)		+ 0xf10)
+#define MIO_PTP_CLOCK_COMP(node)	(MIO_PTP_ADDR(node)		+ 0xf18)

I am sure this will work great on anything but MIPS64 ;)

Quoted 5 lines

Sarcasm duly noted.

That said, by definition it is exactly an OCTEON-III/MIPS64, and can never be anything else. It is known a priori that the hardware and this driver will never be used anywhere else.

Please make sure your Kconfig really enforces this. Generally, we suggest allowing the driver to be compiled when COMPILE_TEST is set. That gives you better compiler test coverage. But it seems like this driver won't compile under such conditions.

Quoted 8 lines
Quoted 6 lines

drivers/net/ethernet/cavium/octeon/octeon3-core.c line 247

Quoted 4 lines
drivers/net/ethernet/cavium/octeon/octeon3-core.c new file +4 -0
+static int num_packet_buffers = 768;
+module_param(num_packet_buffers, int, 0444);
+MODULE_PARM_DESC(num_packet_buffers,
+		 "Number of packet buffers to allocate per port.");

Consider implementing ethtool -g/G for this.

That may be work for a follow-on patch.

Then please remove the module parameter now.

Quoted 7 lines
Quoted 5 lines

drivers/net/ethernet/cavium/octeon/octeon3-core.c line 255

Quoted 3 lines
drivers/net/ethernet/cavium/octeon/octeon3-core.c new file +3 -0
+static int rx_queues = 1;
+module_param(rx_queues, int, 0444);
+MODULE_PARM_DESC(rx_queues, "Number of RX threads per port.");

Same thing, can you consider using an ethtool knob for that?

Also may be work for a follow-on patch.

Ditto

Quoted 14 lines
Quoted 5 lines
Quoted 5 lines

+/**
+ * Reads a 64 bit value from the processor local scratchpad memory.
+ *
+ * @param offset byte offset into scratch pad to read
+ *

Quoted 8 lines

drivers/net/ethernet/cavium/octeon/octeon3-core.c line 278

Quoted 6 lines

+ * @return value read
+ */

drivers/net/ethernet/cavium/octeon/octeon3-core.c new file +4 -0
+static inline u64 scratch_read64(u64 offset)
+{
+	return *(u64 *)((long)SCRATCH_BASE + offset);
+}

No barriers needed whatsoever?

Quoted 1 line

Nope.

Then it would be good to add a comment about why no barrier is needed. Otherwise people are going to ask why there is no barrier, submit patches adding barriers, etc.

Andrew
--
To unsubscribe from this list: send the line "unsubscribe devicetree" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html

#18 lore raw

Re: [PATCH 5/7] MIPS: Octeon: Automatically provision CVMSEG space.

In reply to David Daney
I love your patch! Yet something to improve:

Hi David,

I love your patch! Yet something to improve:

[auto build test ERROR on linus/master]
[also build test ERROR on v4.14-rc7]
[if your patch is applied to the wrong git tree, please drop us a note to help improve the system]

url: https://github.com/0day-ci/linux/commits/David-Daney/Cavium-OCTEON-III-network-driver/20171105-012026
config: mips-cavium_octeon_defconfig (attached as .config)
compiler: mips64-linux-gnuabi64-gcc (Debian 6.1.1-9) 6.1.1 20160705
reproduce:
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross
# save the attached .config to linux build tree
make.cross ARCH=mips

All error/warnings (new ones prefixed by >>):

In file included from drivers/staging/octeon/ethernet-rx.c:31:0:
drivers/staging/octeon/ethernet-rx.c: In function 'cvm_oct_poll':

>> drivers/staging/octeon/ethernet-defines.h:35:38: error: 'CONFIG_CAVIUM_OCTEON_CVMSEG_SIZE' undeclared (first use in this function)
    #define USE_ASYNC_IOBDMA            (CONFIG_CAVIUM_OCTEON_CVMSEG_SIZE > 0)
                                         ^
>> drivers/staging/octeon/ethernet-rx.c:204:6: note: in expansion of macro 'USE_ASYNC_IOBDMA'
     if (USE_ASYNC_IOBDMA) {
         ^~~~~~~~~~~~~~~~
   drivers/staging/octeon/ethernet-defines.h:35:38: note: each undeclared identifier is reported only once for each function it appears in
    #define USE_ASYNC_IOBDMA            (CONFIG_CAVIUM_OCTEON_CVMSEG_SIZE > 0)
                                         ^
>> drivers/staging/octeon/ethernet-rx.c:204:6: note: in expansion of macro 'USE_ASYNC_IOBDMA'
     if (USE_ASYNC_IOBDMA) {
         ^~~~~~~~~~~~~~~~
--
   In file included from drivers/staging/octeon/ethernet-tx.c:30:0:
   drivers/staging/octeon/ethernet-tx.c: In function 'cvm_oct_xmit':
>> drivers/staging/octeon/ethernet-defines.h:35:38: error: 'CONFIG_CAVIUM_OCTEON_CVMSEG_SIZE' undeclared (first use in this function)
    #define USE_ASYNC_IOBDMA            (CONFIG_CAVIUM_OCTEON_CVMSEG_SIZE > 0)
                                         ^
>> drivers/staging/octeon/ethernet-tx.c:182:6: note: in expansion of macro 'USE_ASYNC_IOBDMA'
     if (USE_ASYNC_IOBDMA) {
         ^~~~~~~~~~~~~~~~
   drivers/staging/octeon/ethernet-defines.h:35:38: note: each undeclared identifier is reported only once for each function it appears in
    #define USE_ASYNC_IOBDMA            (CONFIG_CAVIUM_OCTEON_CVMSEG_SIZE > 0)
                                         ^
>> drivers/staging/octeon/ethernet-tx.c:182:6: note: in expansion of macro 'USE_ASYNC_IOBDMA'
     if (USE_ASYNC_IOBDMA) {
         ^~~~~~~~~~~~~~~~

vim +/CONFIG_CAVIUM_OCTEON_CVMSEG_SIZE +35 drivers/staging/octeon/ethernet-defines.h

80ff0fd3 David Daney 2009-05-05 34
80ff0fd3 David Daney 2009-05-05 @35 #define USE_ASYNC_IOBDMA (CONFIG_CAVIUM_OCTEON_CVMSEG_SIZE > 0)
80ff0fd3 David Daney 2009-05-05 36

:::::: The code at line 35 was first introduced by commit
:::::: 80ff0fd3ab6451407a20c19b80c1643c4a6d6434 Staging: Add octeon-ethernet driver files.

:::::: TO: David Daney <[email protected]> :::::: CC: Ralf Baechle <[email protected]>

---
0-DAY kernel test infrastructure Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all Intel Corporation