Linux MIPS Architecture development
 help / color / mirror / Atom feed
diff for duplicates of <20171109192915.11912-5-david.daney@cavium.com>

diff --git a/a/1.txt b/N1/1.txt
index 5c27aff..50b5d62 100644
--- a/a/1.txt
+++ b/N1/1.txt
@@ -1,449 +1 @@
 From: Carlos Munoz <cmunoz@cavium.com>
-
-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."
-
-Signed-off-by: Carlos Munoz <cmunoz@cavium.com>
-Signed-off-by: Steven J. Hill <Steven.Hill@cavium.com>
-Signed-off-by: David Daney <david.daney@cavium.com>
----
- arch/mips/cavium-octeon/Kconfig       |   8 +
- arch/mips/cavium-octeon/Makefile      |   1 +
- arch/mips/cavium-octeon/octeon-fpa3.c | 364 ++++++++++++++++++++++++++++++++++
- arch/mips/include/asm/octeon/octeon.h |  15 ++
- 4 files changed, 388 insertions(+)
- create mode 100644 arch/mips/cavium-octeon/octeon-fpa3.c
-
-diff --git a/arch/mips/cavium-octeon/Kconfig b/arch/mips/cavium-octeon/Kconfig
-index 5c0b56203bae..4dffe78fe6b9 100644
---- a/arch/mips/cavium-octeon/Kconfig
-+++ b/arch/mips/cavium-octeon/Kconfig
-@@ -86,4 +86,12 @@ 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"
-+	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
-diff --git a/arch/mips/cavium-octeon/Makefile b/arch/mips/cavium-octeon/Makefile
-index 0a299ab8719f..0ef967399702 100644
---- a/arch/mips/cavium-octeon/Makefile
-+++ b/arch/mips/cavium-octeon/Makefile
-@@ -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
-diff --git a/arch/mips/cavium-octeon/octeon-fpa3.c b/arch/mips/cavium-octeon/octeon-fpa3.c
-new file mode 100644
-index 000000000000..a7c7decdbc9a
---- /dev/null
-+++ b/arch/mips/cavium-octeon/octeon-fpa3.c
-@@ -0,0 +1,364 @@
-+// SPDX-License-Identifier: GPL-2.0
-+/*
-+ * Driver for the Octeon III Free Pool Unit (fpa).
-+ *
-+ * This file is subject to the terms and conditions of the GNU General Public
-+ * License.  See the file "COPYING" in the main directory of this archive
-+ * for more details.
-+ *
-+ * Copyright (C) 2015-2017 Cavium, Inc.
-+ */
-+
-+#include <linux/module.h>
-+
-+#include <asm/octeon/octeon.h>
-+
-+
-+/* Registers are accessed via xkphys */
-+#define SET_XKPHYS			(1ull << 63)
-+#define NODE_OFFSET			0x1000000000ull
-+#define SET_NODE(node)			((node) * NODE_OFFSET)
-+
-+#define FPA_BASE			0x1280000000000ull
-+#define SET_FPA_BASE(node)		(SET_XKPHYS + SET_NODE(node) + FPA_BASE)
-+
-+#define FPA_GEN_CFG(n)			(SET_FPA_BASE(n)           + 0x00000050)
-+
-+#define FPA_POOLX_CFG(n, p)		(SET_FPA_BASE(n) + (p<<3)  + 0x10000000)
-+#define FPA_POOLX_START_ADDR(n, p)	(SET_FPA_BASE(n) + (p<<3)  + 0x10500000)
-+#define FPA_POOLX_END_ADDR(n, p)	(SET_FPA_BASE(n) + (p<<3)  + 0x10600000)
-+#define FPA_POOLX_STACK_BASE(n, p)	(SET_FPA_BASE(n) + (p<<3)  + 0x10700000)
-+#define FPA_POOLX_STACK_END(n, p)	(SET_FPA_BASE(n) + (p<<3)  + 0x10800000)
-+#define FPA_POOLX_STACK_ADDR(n, p)	(SET_FPA_BASE(n) + (p<<3)  + 0x10900000)
-+
-+#define FPA_AURAX_POOL(n, a)		(SET_FPA_BASE(n) + (a<<3)  + 0x20000000)
-+#define FPA_AURAX_CFG(n, a)		(SET_FPA_BASE(n) + (a<<3)  + 0x20100000)
-+#define FPA_AURAX_CNT(n, a)		(SET_FPA_BASE(n) + (a<<3)  + 0x20200000)
-+#define FPA_AURAX_CNT_LIMIT(n, a)	(SET_FPA_BASE(n) + (a<<3)  + 0x20400000)
-+#define FPA_AURAX_CNT_THRESHOLD(n, a)	(SET_FPA_BASE(n) + (a<<3)  + 0x20500000)
-+#define FPA_AURAX_POOL_LEVELS(n, a)	(SET_FPA_BASE(n) + (a<<3)  + 0x20700000)
-+#define FPA_AURAX_CNT_LEVELS(n, a)	(SET_FPA_BASE(n) + (a<<3)  + 0x20800000)
-+
-+static inline u64 oct_csr_read(u64 addr)
-+{
-+	return __raw_readq((void __iomem *)addr);
-+}
-+
-+static inline void oct_csr_write(u64 data, u64 addr)
-+{
-+	__raw_writeq(data, (void __iomem *)addr);
-+}
-+
-+static DEFINE_MUTEX(octeon_fpa3_lock);
-+
-+static int get_num_pools(void)
-+{
-+	if (OCTEON_IS_MODEL(OCTEON_CN78XX))
-+		return 64;
-+	if (OCTEON_IS_MODEL(OCTEON_CNF75XX) || OCTEON_IS_MODEL(OCTEON_CN73XX))
-+		return 32;
-+	return 0;
-+}
-+
-+static int get_num_auras(void)
-+{
-+	if (OCTEON_IS_MODEL(OCTEON_CN78XX))
-+		return 1024;
-+	if (OCTEON_IS_MODEL(OCTEON_CNF75XX) || OCTEON_IS_MODEL(OCTEON_CN73XX))
-+		return 512;
-+	return 0;
-+}
-+
-+/**
-+ * octeon_fpa3_init - Initialize the fpa to default values.
-+ * @node: Node of fpa to initialize.
-+ *
-+ * Returns 0 if successful.
-+ * Returns <0 for error codes.
-+ */
-+int octeon_fpa3_init(int node)
-+{
-+	static bool init_done[2];
-+	u64 data;
-+	int aura_cnt, i;
-+
-+	mutex_lock(&octeon_fpa3_lock);
-+
-+	if (init_done[node])
-+		goto done;
-+
-+	aura_cnt = get_num_auras();
-+	for (i = 0; i < aura_cnt; i++) {
-+		oct_csr_write(0x100000000ull, FPA_AURAX_CNT(node, i));
-+		oct_csr_write(0xfffffffffull, FPA_AURAX_CNT_LIMIT(node, i));
-+		oct_csr_write(0xffffffffeull, FPA_AURAX_CNT_THRESHOLD(node, i));
-+	}
-+
-+	data = oct_csr_read(FPA_GEN_CFG(node));
-+	data &= ~GENMASK_ULL(9, 4);
-+	data |= 3 << 4;
-+	oct_csr_write(data, FPA_GEN_CFG(node));
-+
-+	init_done[node] = 1;
-+ done:
-+	mutex_unlock(&octeon_fpa3_lock);
-+	return 0;
-+}
-+EXPORT_SYMBOL(octeon_fpa3_init);
-+
-+/**
-+ * octeon_fpa3_pool_init - Initialize a pool.
-+ * @node: Node to initialize pool on.
-+ * @pool_num: Requested pool number (-1 for don't care).
-+ * @pool: Updated with the initialized pool number.
-+ * @pool_stack: Updated with the base of the memory allocated for the pool
-+ *		stack.
-+ * @num_ptrs: Number of pointers to allocated on the stack.
-+ *
-+ * Returns 0 if successful.
-+ * Returns <0 for error codes.
-+ */
-+int octeon_fpa3_pool_init(int node, int pool_num, int *pool, void **pool_stack, int num_ptrs)
-+{
-+	struct global_resource_tag tag;
-+	char buf[16];
-+	u64 pool_stack_start, pool_stack_end, data;
-+	int stack_size, rc = 0;
-+
-+	mutex_lock(&octeon_fpa3_lock);
-+
-+	strncpy((char *)&tag.lo, "cvm_pool", 8);
-+	snprintf(buf, 16, "_%d......", node);
-+	memcpy(&tag.hi, buf, 8);
-+
-+	res_mgr_create_resource(tag, get_num_pools());
-+	*pool = res_mgr_alloc(tag, pool_num, true);
-+	if (*pool < 0) {
-+		rc = -ENODEV;
-+		goto error;
-+	}
-+
-+	oct_csr_write(0, FPA_POOLX_CFG(node, *pool));
-+	oct_csr_write(128, FPA_POOLX_START_ADDR(node, *pool));
-+	oct_csr_write(GENMASK_ULL(41, 7), FPA_POOLX_END_ADDR(node, *pool));
-+
-+	stack_size = (DIV_ROUND_UP(num_ptrs, 29) + 1) * 128;
-+	*pool_stack = kmalloc_node(stack_size, GFP_KERNEL, node);
-+	if (!*pool_stack) {
-+		pr_err("Failed to allocate pool stack memory pool=%d\n",
-+		       pool_num);
-+		rc = -ENOMEM;
-+		goto error_stack;
-+	}
-+
-+	pool_stack_start = virt_to_phys(*pool_stack);
-+	pool_stack_end = round_down(pool_stack_start + stack_size, 128);
-+	pool_stack_start = round_up(pool_stack_start, 128);
-+	oct_csr_write(pool_stack_start, FPA_POOLX_STACK_BASE(node, *pool));
-+	oct_csr_write(pool_stack_start, FPA_POOLX_STACK_ADDR(node, *pool));
-+	oct_csr_write(pool_stack_end, FPA_POOLX_STACK_END(node, *pool));
-+
-+	data = (2 << 3) | BIT(0);
-+	oct_csr_write(data, FPA_POOLX_CFG(node, *pool));
-+
-+	mutex_unlock(&octeon_fpa3_lock);
-+	return 0;
-+
-+error_stack:
-+	res_mgr_free(tag, *pool);
-+error:
-+	mutex_unlock(&octeon_fpa3_lock);
-+	return rc;
-+}
-+EXPORT_SYMBOL(octeon_fpa3_pool_init);
-+
-+/**
-+ * octeon_fpa3_release_pool - Release a pool.
-+ * @node: Node pool is on.
-+ * @pool: Pool to release.
-+ */
-+void octeon_fpa3_release_pool(int node, int pool)
-+{
-+	struct global_resource_tag tag;
-+	char buf[16];
-+
-+	mutex_lock(&octeon_fpa3_lock);
-+
-+	strncpy((char *)&tag.lo, "cvm_pool", 8);
-+	snprintf(buf, 16, "_%d......", node);
-+	memcpy(&tag.hi, buf, 8);
-+
-+	res_mgr_free(tag, pool);
-+
-+	mutex_unlock(&octeon_fpa3_lock);
-+}
-+EXPORT_SYMBOL(octeon_fpa3_release_pool);
-+
-+/**
-+ * octeon_fpa3_aura_init - Initialize an aura.
-+ * @node: Node to initialize aura on.
-+ * @pool: Pool the aura belongs to.
-+ * @aura_num: Requested aura number (-1 for don't care).
-+ * @aura: Updated with the initialized aura number.
-+ * @num_bufs: Number of buffers in the aura.
-+ * @limit: Limit for the aura.
-+ *
-+ * Returns 0 if successful.
-+ * Returns <0 for error codes.
-+ */
-+int octeon_fpa3_aura_init(int node, int pool, int aura_num, int *aura, int num_bufs, unsigned int limit)
-+{
-+	struct global_resource_tag tag;
-+	char buf[16];
-+	u64 data, shift;
-+	unsigned int drop, pass;
-+	int rc = 0;
-+
-+	mutex_lock(&octeon_fpa3_lock);
-+
-+	strncpy((char *)&tag.lo, "cvm_aura", 8);
-+	snprintf(buf, 16, "_%d......", node);
-+	memcpy(&tag.hi, buf, 8);
-+
-+	res_mgr_create_resource(tag, get_num_auras());
-+	*aura = res_mgr_alloc(tag, aura_num, true);
-+	if (*aura < 0) {
-+		rc = -ENODEV;
-+		goto error;
-+	}
-+
-+	oct_csr_write(0, FPA_AURAX_CFG(node, *aura));
-+
-+	/* Allow twice the limit before saturation at zero */
-+	limit *= 2;
-+	data = limit;
-+	oct_csr_write(data, FPA_AURAX_CNT_LIMIT(node, *aura));
-+	oct_csr_write(data, FPA_AURAX_CNT(node, *aura));
-+
-+	oct_csr_write(pool, FPA_AURAX_POOL(node, *aura));
-+
-+	/* No per-pool RED/Drop */
-+	oct_csr_write(0, FPA_AURAX_POOL_LEVELS(node, *aura));
-+
-+	shift = 0;
-+	while ((limit >> shift) > 255)
-+		shift++;
-+
-+	drop = (limit - num_bufs / 20) >> shift;	/* 95% */
-+	pass = (limit - (num_bufs * 3) / 20) >> shift;	/* 85% */
-+
-+	/* Enable per aura RED/drop */
-+	data = BIT(38) | (shift << 32) | (drop << 16) | (pass << 8);
-+	oct_csr_write(data, FPA_AURAX_CNT_LEVELS(node, *aura));
-+
-+error:
-+	mutex_unlock(&octeon_fpa3_lock);
-+	return rc;
-+}
-+EXPORT_SYMBOL(octeon_fpa3_aura_init);
-+
-+/**
-+ * octeon_fpa3_release_aura - Release an aura.
-+ * @node: Node to aura is on.
-+ * @aura: Aura to release.
-+ */
-+void octeon_fpa3_release_aura(int node, int aura)
-+{
-+	struct global_resource_tag tag;
-+	char buf[16];
-+
-+	mutex_lock(&octeon_fpa3_lock);
-+
-+	strncpy((char *)&tag.lo, "cvm_aura", 8);
-+	snprintf(buf, 16, "_%d......", node);
-+	memcpy(&tag.hi, buf, 8);
-+
-+	res_mgr_free(tag, aura);
-+
-+	mutex_unlock(&octeon_fpa3_lock);
-+}
-+EXPORT_SYMBOL(octeon_fpa3_release_aura);
-+
-+/**
-+ * octeon_fpa3_alloc - Get a buffer from a aura's pool.
-+ * @node: Node to free memory to.
-+ * @aura: Aura to free memory to.
-+ *
-+ * Returns allocated buffer pointer if successful
-+ * Returns NULL on error.
-+ */
-+void *octeon_fpa3_alloc(u64 node, int aura)
-+{
-+	u64 buf_phys, addr;
-+	void *buf = NULL;
-+
-+	/* Buffer pointers are obtained using load operations */
-+	addr = BIT(63) | BIT(48) | (0x29ull << 40) | (node << 36) |
-+		(aura << 16);
-+	buf_phys = *(u64 *)addr;
-+
-+	if (buf_phys)
-+		buf = phys_to_virt(buf_phys);
-+
-+	return buf;
-+}
-+EXPORT_SYMBOL(octeon_fpa3_alloc);
-+
-+/**
-+ * octeon_fpa3_free - Add a buffer back to the aura's pool.
-+ * @node: Node to free memory to.
-+ * @aura: Aura to free memory to.
-+ * @buf: Address of buffer to free to the aura's pool.
-+ */
-+void octeon_fpa3_free(u64 node, int aura, const void *buf)
-+{
-+	u64 buf_phys, addr;
-+
-+	buf_phys = virt_to_phys(buf);
-+
-+	/* Make sure that any previous writes to memory go out before we free
-+	 * this buffer. This also serves as a barrier to prevent GCC from
-+	 * reordering operations to after the free.
-+	 */
-+	wmb();
-+
-+	/* Buffers are added to fpa pools using store operations */
-+	addr = BIT(63) | BIT(48) | (0x29ull << 40) | (node << 36) | (aura << 16);
-+	*(u64 *)addr = buf_phys;
-+}
-+EXPORT_SYMBOL(octeon_fpa3_free);
-+
-+/**
-+ * octeon_fpa3_mem_fill - Add buffers to an aura.
-+ * @node: Node to get memory from.
-+ * @cache: Memory cache to allocate from.
-+ * @aura: Aura to add buffers to.
-+ * @num_bufs: Number of buffers to add to the aura.
-+ *
-+ * Returns 0 if successful.
-+ * Returns <0 for error codes.
-+ */
-+int octeon_fpa3_mem_fill(int node, struct kmem_cache *cache, int aura, int num_bufs)
-+{
-+	void *mem;
-+	int i, rc = 0;
-+
-+	mutex_lock(&octeon_fpa3_lock);
-+
-+	for (i = 0; i < num_bufs; i++) {
-+		mem = kmem_cache_alloc_node(cache, GFP_KERNEL, node);
-+		if (!mem) {
-+			pr_err("Failed to allocate memory for aura=%d\n", aura);
-+			rc = -ENOMEM;
-+			break;
-+		}
-+		octeon_fpa3_free(node, aura, mem);
-+	}
-+
-+	mutex_unlock(&octeon_fpa3_lock);
-+	return rc;
-+}
-+EXPORT_SYMBOL(octeon_fpa3_mem_fill);
-+
-+MODULE_LICENSE("GPL");
-+MODULE_DESCRIPTION("Cavium, Inc. Octeon III FPA manager.");
-diff --git a/arch/mips/include/asm/octeon/octeon.h b/arch/mips/include/asm/octeon/octeon.h
-index 0411efdb465c..d184592e6515 100644
---- a/arch/mips/include/asm/octeon/octeon.h
-+++ b/arch/mips/include/asm/octeon/octeon.h
-@@ -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
-  *
--- 
-2.13.6
diff --git a/a/content_digest b/N1/content_digest
index 27d3456..b32570c 100644
--- a/a/content_digest
+++ b/N1/content_digest
@@ -21,454 +21,6 @@
  " David Daney <david.daney@cavium.com>\0"
  "\00:1\0"
  "b\0"
- "From: Carlos Munoz <cmunoz@cavium.com>\n"
- "\n"
- "From the hardware user manual: \"The FPA is a unit that maintains\n"
- "pools of pointers to free L2/DRAM memory. To provide QoS, the pools\n"
- "are referenced indirectly through 1024 auras. Both core software\n"
- "and hardware units allocate and free pointers.\"\n"
- "\n"
- "Signed-off-by: Carlos Munoz <cmunoz@cavium.com>\n"
- "Signed-off-by: Steven J. Hill <Steven.Hill@cavium.com>\n"
- "Signed-off-by: David Daney <david.daney@cavium.com>\n"
- "---\n"
- " arch/mips/cavium-octeon/Kconfig       |   8 +\n"
- " arch/mips/cavium-octeon/Makefile      |   1 +\n"
- " arch/mips/cavium-octeon/octeon-fpa3.c | 364 ++++++++++++++++++++++++++++++++++\n"
- " arch/mips/include/asm/octeon/octeon.h |  15 ++\n"
- " 4 files changed, 388 insertions(+)\n"
- " create mode 100644 arch/mips/cavium-octeon/octeon-fpa3.c\n"
- "\n"
- "diff --git a/arch/mips/cavium-octeon/Kconfig b/arch/mips/cavium-octeon/Kconfig\n"
- "index 5c0b56203bae..4dffe78fe6b9 100644\n"
- "--- a/arch/mips/cavium-octeon/Kconfig\n"
- "+++ b/arch/mips/cavium-octeon/Kconfig\n"
- "@@ -86,4 +86,12 @@ config OCTEON_ILM\n"
- " \t  To compile this driver as a module, choose M here.  The module\n"
- " \t  will be called octeon-ilm\n"
- " \n"
- "+config OCTEON_FPA3\n"
- "+\ttristate \"Octeon III fpa driver\"\n"
- "+\thelp\n"
- "+\t  This option enables a Octeon III driver for the Free Pool Unit (FPA).\n"
- "+\t  The FPA is a hardware unit that manages pools of pointers to free\n"
- "+\t  L2/DRAM memory. This driver provides an interface to reserve,\n"
- "+\t  initialize, and fill fpa pools.\n"
- "+\n"
- " endif # CAVIUM_OCTEON_SOC\n"
- "diff --git a/arch/mips/cavium-octeon/Makefile b/arch/mips/cavium-octeon/Makefile\n"
- "index 0a299ab8719f..0ef967399702 100644\n"
- "--- a/arch/mips/cavium-octeon/Makefile\n"
- "+++ b/arch/mips/cavium-octeon/Makefile\n"
- "@@ -20,3 +20,4 @@ obj-$(CONFIG_MTD)\t\t      += flash_setup.o\n"
- " obj-$(CONFIG_SMP)\t\t      += smp.o\n"
- " obj-$(CONFIG_OCTEON_ILM)\t      += oct_ilm.o\n"
- " obj-$(CONFIG_USB)\t\t      += octeon-usb.o\n"
- "+obj-$(CONFIG_OCTEON_FPA3)\t      += octeon-fpa3.o\n"
- "diff --git a/arch/mips/cavium-octeon/octeon-fpa3.c b/arch/mips/cavium-octeon/octeon-fpa3.c\n"
- "new file mode 100644\n"
- "index 000000000000..a7c7decdbc9a\n"
- "--- /dev/null\n"
- "+++ b/arch/mips/cavium-octeon/octeon-fpa3.c\n"
- "@@ -0,0 +1,364 @@\n"
- "+// SPDX-License-Identifier: GPL-2.0\n"
- "+/*\n"
- "+ * Driver for the Octeon III Free Pool Unit (fpa).\n"
- "+ *\n"
- "+ * This file is subject to the terms and conditions of the GNU General Public\n"
- "+ * License.  See the file \"COPYING\" in the main directory of this archive\n"
- "+ * for more details.\n"
- "+ *\n"
- "+ * Copyright (C) 2015-2017 Cavium, Inc.\n"
- "+ */\n"
- "+\n"
- "+#include <linux/module.h>\n"
- "+\n"
- "+#include <asm/octeon/octeon.h>\n"
- "+\n"
- "+\n"
- "+/* Registers are accessed via xkphys */\n"
- "+#define SET_XKPHYS\t\t\t(1ull << 63)\n"
- "+#define NODE_OFFSET\t\t\t0x1000000000ull\n"
- "+#define SET_NODE(node)\t\t\t((node) * NODE_OFFSET)\n"
- "+\n"
- "+#define FPA_BASE\t\t\t0x1280000000000ull\n"
- "+#define SET_FPA_BASE(node)\t\t(SET_XKPHYS + SET_NODE(node) + FPA_BASE)\n"
- "+\n"
- "+#define FPA_GEN_CFG(n)\t\t\t(SET_FPA_BASE(n)           + 0x00000050)\n"
- "+\n"
- "+#define FPA_POOLX_CFG(n, p)\t\t(SET_FPA_BASE(n) + (p<<3)  + 0x10000000)\n"
- "+#define FPA_POOLX_START_ADDR(n, p)\t(SET_FPA_BASE(n) + (p<<3)  + 0x10500000)\n"
- "+#define FPA_POOLX_END_ADDR(n, p)\t(SET_FPA_BASE(n) + (p<<3)  + 0x10600000)\n"
- "+#define FPA_POOLX_STACK_BASE(n, p)\t(SET_FPA_BASE(n) + (p<<3)  + 0x10700000)\n"
- "+#define FPA_POOLX_STACK_END(n, p)\t(SET_FPA_BASE(n) + (p<<3)  + 0x10800000)\n"
- "+#define FPA_POOLX_STACK_ADDR(n, p)\t(SET_FPA_BASE(n) + (p<<3)  + 0x10900000)\n"
- "+\n"
- "+#define FPA_AURAX_POOL(n, a)\t\t(SET_FPA_BASE(n) + (a<<3)  + 0x20000000)\n"
- "+#define FPA_AURAX_CFG(n, a)\t\t(SET_FPA_BASE(n) + (a<<3)  + 0x20100000)\n"
- "+#define FPA_AURAX_CNT(n, a)\t\t(SET_FPA_BASE(n) + (a<<3)  + 0x20200000)\n"
- "+#define FPA_AURAX_CNT_LIMIT(n, a)\t(SET_FPA_BASE(n) + (a<<3)  + 0x20400000)\n"
- "+#define FPA_AURAX_CNT_THRESHOLD(n, a)\t(SET_FPA_BASE(n) + (a<<3)  + 0x20500000)\n"
- "+#define FPA_AURAX_POOL_LEVELS(n, a)\t(SET_FPA_BASE(n) + (a<<3)  + 0x20700000)\n"
- "+#define FPA_AURAX_CNT_LEVELS(n, a)\t(SET_FPA_BASE(n) + (a<<3)  + 0x20800000)\n"
- "+\n"
- "+static inline u64 oct_csr_read(u64 addr)\n"
- "+{\n"
- "+\treturn __raw_readq((void __iomem *)addr);\n"
- "+}\n"
- "+\n"
- "+static inline void oct_csr_write(u64 data, u64 addr)\n"
- "+{\n"
- "+\t__raw_writeq(data, (void __iomem *)addr);\n"
- "+}\n"
- "+\n"
- "+static DEFINE_MUTEX(octeon_fpa3_lock);\n"
- "+\n"
- "+static int get_num_pools(void)\n"
- "+{\n"
- "+\tif (OCTEON_IS_MODEL(OCTEON_CN78XX))\n"
- "+\t\treturn 64;\n"
- "+\tif (OCTEON_IS_MODEL(OCTEON_CNF75XX) || OCTEON_IS_MODEL(OCTEON_CN73XX))\n"
- "+\t\treturn 32;\n"
- "+\treturn 0;\n"
- "+}\n"
- "+\n"
- "+static int get_num_auras(void)\n"
- "+{\n"
- "+\tif (OCTEON_IS_MODEL(OCTEON_CN78XX))\n"
- "+\t\treturn 1024;\n"
- "+\tif (OCTEON_IS_MODEL(OCTEON_CNF75XX) || OCTEON_IS_MODEL(OCTEON_CN73XX))\n"
- "+\t\treturn 512;\n"
- "+\treturn 0;\n"
- "+}\n"
- "+\n"
- "+/**\n"
- "+ * octeon_fpa3_init - Initialize the fpa to default values.\n"
- "+ * @node: Node of fpa to initialize.\n"
- "+ *\n"
- "+ * Returns 0 if successful.\n"
- "+ * Returns <0 for error codes.\n"
- "+ */\n"
- "+int octeon_fpa3_init(int node)\n"
- "+{\n"
- "+\tstatic bool init_done[2];\n"
- "+\tu64 data;\n"
- "+\tint aura_cnt, i;\n"
- "+\n"
- "+\tmutex_lock(&octeon_fpa3_lock);\n"
- "+\n"
- "+\tif (init_done[node])\n"
- "+\t\tgoto done;\n"
- "+\n"
- "+\taura_cnt = get_num_auras();\n"
- "+\tfor (i = 0; i < aura_cnt; i++) {\n"
- "+\t\toct_csr_write(0x100000000ull, FPA_AURAX_CNT(node, i));\n"
- "+\t\toct_csr_write(0xfffffffffull, FPA_AURAX_CNT_LIMIT(node, i));\n"
- "+\t\toct_csr_write(0xffffffffeull, FPA_AURAX_CNT_THRESHOLD(node, i));\n"
- "+\t}\n"
- "+\n"
- "+\tdata = oct_csr_read(FPA_GEN_CFG(node));\n"
- "+\tdata &= ~GENMASK_ULL(9, 4);\n"
- "+\tdata |= 3 << 4;\n"
- "+\toct_csr_write(data, FPA_GEN_CFG(node));\n"
- "+\n"
- "+\tinit_done[node] = 1;\n"
- "+ done:\n"
- "+\tmutex_unlock(&octeon_fpa3_lock);\n"
- "+\treturn 0;\n"
- "+}\n"
- "+EXPORT_SYMBOL(octeon_fpa3_init);\n"
- "+\n"
- "+/**\n"
- "+ * octeon_fpa3_pool_init - Initialize a pool.\n"
- "+ * @node: Node to initialize pool on.\n"
- "+ * @pool_num: Requested pool number (-1 for don't care).\n"
- "+ * @pool: Updated with the initialized pool number.\n"
- "+ * @pool_stack: Updated with the base of the memory allocated for the pool\n"
- "+ *\t\tstack.\n"
- "+ * @num_ptrs: Number of pointers to allocated on the stack.\n"
- "+ *\n"
- "+ * Returns 0 if successful.\n"
- "+ * Returns <0 for error codes.\n"
- "+ */\n"
- "+int octeon_fpa3_pool_init(int node, int pool_num, int *pool, void **pool_stack, int num_ptrs)\n"
- "+{\n"
- "+\tstruct global_resource_tag tag;\n"
- "+\tchar buf[16];\n"
- "+\tu64 pool_stack_start, pool_stack_end, data;\n"
- "+\tint stack_size, rc = 0;\n"
- "+\n"
- "+\tmutex_lock(&octeon_fpa3_lock);\n"
- "+\n"
- "+\tstrncpy((char *)&tag.lo, \"cvm_pool\", 8);\n"
- "+\tsnprintf(buf, 16, \"_%d......\", node);\n"
- "+\tmemcpy(&tag.hi, buf, 8);\n"
- "+\n"
- "+\tres_mgr_create_resource(tag, get_num_pools());\n"
- "+\t*pool = res_mgr_alloc(tag, pool_num, true);\n"
- "+\tif (*pool < 0) {\n"
- "+\t\trc = -ENODEV;\n"
- "+\t\tgoto error;\n"
- "+\t}\n"
- "+\n"
- "+\toct_csr_write(0, FPA_POOLX_CFG(node, *pool));\n"
- "+\toct_csr_write(128, FPA_POOLX_START_ADDR(node, *pool));\n"
- "+\toct_csr_write(GENMASK_ULL(41, 7), FPA_POOLX_END_ADDR(node, *pool));\n"
- "+\n"
- "+\tstack_size = (DIV_ROUND_UP(num_ptrs, 29) + 1) * 128;\n"
- "+\t*pool_stack = kmalloc_node(stack_size, GFP_KERNEL, node);\n"
- "+\tif (!*pool_stack) {\n"
- "+\t\tpr_err(\"Failed to allocate pool stack memory pool=%d\\n\",\n"
- "+\t\t       pool_num);\n"
- "+\t\trc = -ENOMEM;\n"
- "+\t\tgoto error_stack;\n"
- "+\t}\n"
- "+\n"
- "+\tpool_stack_start = virt_to_phys(*pool_stack);\n"
- "+\tpool_stack_end = round_down(pool_stack_start + stack_size, 128);\n"
- "+\tpool_stack_start = round_up(pool_stack_start, 128);\n"
- "+\toct_csr_write(pool_stack_start, FPA_POOLX_STACK_BASE(node, *pool));\n"
- "+\toct_csr_write(pool_stack_start, FPA_POOLX_STACK_ADDR(node, *pool));\n"
- "+\toct_csr_write(pool_stack_end, FPA_POOLX_STACK_END(node, *pool));\n"
- "+\n"
- "+\tdata = (2 << 3) | BIT(0);\n"
- "+\toct_csr_write(data, FPA_POOLX_CFG(node, *pool));\n"
- "+\n"
- "+\tmutex_unlock(&octeon_fpa3_lock);\n"
- "+\treturn 0;\n"
- "+\n"
- "+error_stack:\n"
- "+\tres_mgr_free(tag, *pool);\n"
- "+error:\n"
- "+\tmutex_unlock(&octeon_fpa3_lock);\n"
- "+\treturn rc;\n"
- "+}\n"
- "+EXPORT_SYMBOL(octeon_fpa3_pool_init);\n"
- "+\n"
- "+/**\n"
- "+ * octeon_fpa3_release_pool - Release a pool.\n"
- "+ * @node: Node pool is on.\n"
- "+ * @pool: Pool to release.\n"
- "+ */\n"
- "+void octeon_fpa3_release_pool(int node, int pool)\n"
- "+{\n"
- "+\tstruct global_resource_tag tag;\n"
- "+\tchar buf[16];\n"
- "+\n"
- "+\tmutex_lock(&octeon_fpa3_lock);\n"
- "+\n"
- "+\tstrncpy((char *)&tag.lo, \"cvm_pool\", 8);\n"
- "+\tsnprintf(buf, 16, \"_%d......\", node);\n"
- "+\tmemcpy(&tag.hi, buf, 8);\n"
- "+\n"
- "+\tres_mgr_free(tag, pool);\n"
- "+\n"
- "+\tmutex_unlock(&octeon_fpa3_lock);\n"
- "+}\n"
- "+EXPORT_SYMBOL(octeon_fpa3_release_pool);\n"
- "+\n"
- "+/**\n"
- "+ * octeon_fpa3_aura_init - Initialize an aura.\n"
- "+ * @node: Node to initialize aura on.\n"
- "+ * @pool: Pool the aura belongs to.\n"
- "+ * @aura_num: Requested aura number (-1 for don't care).\n"
- "+ * @aura: Updated with the initialized aura number.\n"
- "+ * @num_bufs: Number of buffers in the aura.\n"
- "+ * @limit: Limit for the aura.\n"
- "+ *\n"
- "+ * Returns 0 if successful.\n"
- "+ * Returns <0 for error codes.\n"
- "+ */\n"
- "+int octeon_fpa3_aura_init(int node, int pool, int aura_num, int *aura, int num_bufs, unsigned int limit)\n"
- "+{\n"
- "+\tstruct global_resource_tag tag;\n"
- "+\tchar buf[16];\n"
- "+\tu64 data, shift;\n"
- "+\tunsigned int drop, pass;\n"
- "+\tint rc = 0;\n"
- "+\n"
- "+\tmutex_lock(&octeon_fpa3_lock);\n"
- "+\n"
- "+\tstrncpy((char *)&tag.lo, \"cvm_aura\", 8);\n"
- "+\tsnprintf(buf, 16, \"_%d......\", node);\n"
- "+\tmemcpy(&tag.hi, buf, 8);\n"
- "+\n"
- "+\tres_mgr_create_resource(tag, get_num_auras());\n"
- "+\t*aura = res_mgr_alloc(tag, aura_num, true);\n"
- "+\tif (*aura < 0) {\n"
- "+\t\trc = -ENODEV;\n"
- "+\t\tgoto error;\n"
- "+\t}\n"
- "+\n"
- "+\toct_csr_write(0, FPA_AURAX_CFG(node, *aura));\n"
- "+\n"
- "+\t/* Allow twice the limit before saturation at zero */\n"
- "+\tlimit *= 2;\n"
- "+\tdata = limit;\n"
- "+\toct_csr_write(data, FPA_AURAX_CNT_LIMIT(node, *aura));\n"
- "+\toct_csr_write(data, FPA_AURAX_CNT(node, *aura));\n"
- "+\n"
- "+\toct_csr_write(pool, FPA_AURAX_POOL(node, *aura));\n"
- "+\n"
- "+\t/* No per-pool RED/Drop */\n"
- "+\toct_csr_write(0, FPA_AURAX_POOL_LEVELS(node, *aura));\n"
- "+\n"
- "+\tshift = 0;\n"
- "+\twhile ((limit >> shift) > 255)\n"
- "+\t\tshift++;\n"
- "+\n"
- "+\tdrop = (limit - num_bufs / 20) >> shift;\t/* 95% */\n"
- "+\tpass = (limit - (num_bufs * 3) / 20) >> shift;\t/* 85% */\n"
- "+\n"
- "+\t/* Enable per aura RED/drop */\n"
- "+\tdata = BIT(38) | (shift << 32) | (drop << 16) | (pass << 8);\n"
- "+\toct_csr_write(data, FPA_AURAX_CNT_LEVELS(node, *aura));\n"
- "+\n"
- "+error:\n"
- "+\tmutex_unlock(&octeon_fpa3_lock);\n"
- "+\treturn rc;\n"
- "+}\n"
- "+EXPORT_SYMBOL(octeon_fpa3_aura_init);\n"
- "+\n"
- "+/**\n"
- "+ * octeon_fpa3_release_aura - Release an aura.\n"
- "+ * @node: Node to aura is on.\n"
- "+ * @aura: Aura to release.\n"
- "+ */\n"
- "+void octeon_fpa3_release_aura(int node, int aura)\n"
- "+{\n"
- "+\tstruct global_resource_tag tag;\n"
- "+\tchar buf[16];\n"
- "+\n"
- "+\tmutex_lock(&octeon_fpa3_lock);\n"
- "+\n"
- "+\tstrncpy((char *)&tag.lo, \"cvm_aura\", 8);\n"
- "+\tsnprintf(buf, 16, \"_%d......\", node);\n"
- "+\tmemcpy(&tag.hi, buf, 8);\n"
- "+\n"
- "+\tres_mgr_free(tag, aura);\n"
- "+\n"
- "+\tmutex_unlock(&octeon_fpa3_lock);\n"
- "+}\n"
- "+EXPORT_SYMBOL(octeon_fpa3_release_aura);\n"
- "+\n"
- "+/**\n"
- "+ * octeon_fpa3_alloc - Get a buffer from a aura's pool.\n"
- "+ * @node: Node to free memory to.\n"
- "+ * @aura: Aura to free memory to.\n"
- "+ *\n"
- "+ * Returns allocated buffer pointer if successful\n"
- "+ * Returns NULL on error.\n"
- "+ */\n"
- "+void *octeon_fpa3_alloc(u64 node, int aura)\n"
- "+{\n"
- "+\tu64 buf_phys, addr;\n"
- "+\tvoid *buf = NULL;\n"
- "+\n"
- "+\t/* Buffer pointers are obtained using load operations */\n"
- "+\taddr = BIT(63) | BIT(48) | (0x29ull << 40) | (node << 36) |\n"
- "+\t\t(aura << 16);\n"
- "+\tbuf_phys = *(u64 *)addr;\n"
- "+\n"
- "+\tif (buf_phys)\n"
- "+\t\tbuf = phys_to_virt(buf_phys);\n"
- "+\n"
- "+\treturn buf;\n"
- "+}\n"
- "+EXPORT_SYMBOL(octeon_fpa3_alloc);\n"
- "+\n"
- "+/**\n"
- "+ * octeon_fpa3_free - Add a buffer back to the aura's pool.\n"
- "+ * @node: Node to free memory to.\n"
- "+ * @aura: Aura to free memory to.\n"
- "+ * @buf: Address of buffer to free to the aura's pool.\n"
- "+ */\n"
- "+void octeon_fpa3_free(u64 node, int aura, const void *buf)\n"
- "+{\n"
- "+\tu64 buf_phys, addr;\n"
- "+\n"
- "+\tbuf_phys = virt_to_phys(buf);\n"
- "+\n"
- "+\t/* Make sure that any previous writes to memory go out before we free\n"
- "+\t * this buffer. This also serves as a barrier to prevent GCC from\n"
- "+\t * reordering operations to after the free.\n"
- "+\t */\n"
- "+\twmb();\n"
- "+\n"
- "+\t/* Buffers are added to fpa pools using store operations */\n"
- "+\taddr = BIT(63) | BIT(48) | (0x29ull << 40) | (node << 36) | (aura << 16);\n"
- "+\t*(u64 *)addr = buf_phys;\n"
- "+}\n"
- "+EXPORT_SYMBOL(octeon_fpa3_free);\n"
- "+\n"
- "+/**\n"
- "+ * octeon_fpa3_mem_fill - Add buffers to an aura.\n"
- "+ * @node: Node to get memory from.\n"
- "+ * @cache: Memory cache to allocate from.\n"
- "+ * @aura: Aura to add buffers to.\n"
- "+ * @num_bufs: Number of buffers to add to the aura.\n"
- "+ *\n"
- "+ * Returns 0 if successful.\n"
- "+ * Returns <0 for error codes.\n"
- "+ */\n"
- "+int octeon_fpa3_mem_fill(int node, struct kmem_cache *cache, int aura, int num_bufs)\n"
- "+{\n"
- "+\tvoid *mem;\n"
- "+\tint i, rc = 0;\n"
- "+\n"
- "+\tmutex_lock(&octeon_fpa3_lock);\n"
- "+\n"
- "+\tfor (i = 0; i < num_bufs; i++) {\n"
- "+\t\tmem = kmem_cache_alloc_node(cache, GFP_KERNEL, node);\n"
- "+\t\tif (!mem) {\n"
- "+\t\t\tpr_err(\"Failed to allocate memory for aura=%d\\n\", aura);\n"
- "+\t\t\trc = -ENOMEM;\n"
- "+\t\t\tbreak;\n"
- "+\t\t}\n"
- "+\t\tocteon_fpa3_free(node, aura, mem);\n"
- "+\t}\n"
- "+\n"
- "+\tmutex_unlock(&octeon_fpa3_lock);\n"
- "+\treturn rc;\n"
- "+}\n"
- "+EXPORT_SYMBOL(octeon_fpa3_mem_fill);\n"
- "+\n"
- "+MODULE_LICENSE(\"GPL\");\n"
- "+MODULE_DESCRIPTION(\"Cavium, Inc. Octeon III FPA manager.\");\n"
- "diff --git a/arch/mips/include/asm/octeon/octeon.h b/arch/mips/include/asm/octeon/octeon.h\n"
- "index 0411efdb465c..d184592e6515 100644\n"
- "--- a/arch/mips/include/asm/octeon/octeon.h\n"
- "+++ b/arch/mips/include/asm/octeon/octeon.h\n"
- "@@ -10,6 +10,7 @@\n"
- " \n"
- " #include <asm/octeon/cvmx.h>\n"
- " #include <asm/bitfield.h>\n"
- "+#include <linux/slab.h>\n"
- " \n"
- " extern uint64_t octeon_bootmem_alloc_range_phys(uint64_t size,\n"
- " \t\t\t\t\t\tuint64_t alignment,\n"
- "@@ -364,6 +365,20 @@ int res_mgr_alloc_range(struct global_resource_tag tag, int req_inst,\n"
- " \t\t\tint req_cnt, bool use_last_avail, int *inst);\n"
- " int res_mgr_create_resource(struct global_resource_tag tag, int inst_cnt);\n"
- " \n"
- "+#if IS_ENABLED(CONFIG_OCTEON_FPA3)\n"
- "+int octeon_fpa3_init(int node);\n"
- "+int octeon_fpa3_pool_init(int node, int pool_num, int *pool, void **pool_stack,\n"
- "+\t\t\t  int num_ptrs);\n"
- "+int octeon_fpa3_aura_init(int node, int pool, int aura_num, int *aura,\n"
- "+\t\t\t  int num_bufs, unsigned int limit);\n"
- "+int octeon_fpa3_mem_fill(int node, struct kmem_cache *cache, int aura,\n"
- "+\t\t\t int num_bufs);\n"
- "+void octeon_fpa3_free(u64 node, int aura, const void *buf);\n"
- "+void *octeon_fpa3_alloc(u64 node, int aura);\n"
- "+void octeon_fpa3_release_pool(int node, int pool);\n"
- "+void octeon_fpa3_release_aura(int node, int aura);\n"
- "+#endif\n"
- "+\n"
- " /**\n"
- "  * Read a 32bit value from the Octeon NPI register space\n"
- "  *\n"
- "-- \n"
- 2.13.6
+ From: Carlos Munoz <cmunoz@cavium.com>
 
-697e4c372f1bae3ae7cee7a56528677b43d390922232427060b2d077dad84f72
+65ebdd0da7a27d1e7b7e4ed60959de682cf3dd00c5cd64ba0ba4267e4c659c3b

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox