Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   1) /***********************license start***************
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2)  * Author: Cavium Networks
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  * Contact: support@caviumnetworks.com
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5)  * This file is part of the OCTEON SDK
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7)  * Copyright (c) 2003-2008 Cavium Networks
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9)  * This file is free software; you can redistribute it and/or modify
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10)  * it under the terms of the GNU General Public License, Version 2, as
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11)  * published by the Free Software Foundation.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13)  * This file is distributed in the hope that it will be useful, but
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14)  * AS-IS and WITHOUT ANY WARRANTY; without even the implied warranty
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15)  * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE, TITLE, or
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16)  * NONINFRINGEMENT.  See the GNU General Public License for more
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17)  * details.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19)  * You should have received a copy of the GNU General Public License
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20)  * along with this file; if not, write to the Free Software
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21)  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22)  * or visit http://www.gnu.org/licenses/.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24)  * This file may also be available under a different license from Cavium.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25)  * Contact Cavium Networks for more information
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26)  ***********************license end**************************************/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29)  * Support functions for managing command queues used for
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30)  * various hardware blocks.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) #include <linux/kernel.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) #include <asm/octeon/octeon.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) #include <asm/octeon/cvmx-config.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) #include <asm/octeon/cvmx-fpa.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) #include <asm/octeon/cvmx-cmd-queue.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) #include <asm/octeon/cvmx-npei-defs.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) #include <asm/octeon/cvmx-pexp-defs.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) #include <asm/octeon/cvmx-pko-defs.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46)  * This application uses this pointer to access the global queue
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47)  * state. It points to a bootmem named block.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) __cvmx_cmd_queue_all_state_t *__cvmx_cmd_queue_state_ptr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) EXPORT_SYMBOL_GPL(__cvmx_cmd_queue_state_ptr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53)  * Initialize the Global queue state pointer.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55)  * Returns CVMX_CMD_QUEUE_SUCCESS or a failure code
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) static cvmx_cmd_queue_result_t __cvmx_cmd_queue_init_state_ptr(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) 	char *alloc_name = "cvmx_cmd_queues";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) #if defined(CONFIG_CAVIUM_RESERVE32) && CONFIG_CAVIUM_RESERVE32
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) 	extern uint64_t octeon_reserve32_memory;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) 	if (likely(__cvmx_cmd_queue_state_ptr))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) 		return CVMX_CMD_QUEUE_SUCCESS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) #if defined(CONFIG_CAVIUM_RESERVE32) && CONFIG_CAVIUM_RESERVE32
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) 	if (octeon_reserve32_memory)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) 		__cvmx_cmd_queue_state_ptr =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) 		    cvmx_bootmem_alloc_named_range(sizeof(*__cvmx_cmd_queue_state_ptr),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) 						   octeon_reserve32_memory,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) 						   octeon_reserve32_memory +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) 						   (CONFIG_CAVIUM_RESERVE32 <<
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) 						    20) - 1, 128, alloc_name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) 		__cvmx_cmd_queue_state_ptr =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) 		    cvmx_bootmem_alloc_named(sizeof(*__cvmx_cmd_queue_state_ptr),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) 					    128,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) 					    alloc_name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) 	if (__cvmx_cmd_queue_state_ptr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) 		memset(__cvmx_cmd_queue_state_ptr, 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) 		       sizeof(*__cvmx_cmd_queue_state_ptr));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) 	else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) 		struct cvmx_bootmem_named_block_desc *block_desc =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) 		    cvmx_bootmem_find_named_block(alloc_name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) 		if (block_desc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) 			__cvmx_cmd_queue_state_ptr =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) 			    cvmx_phys_to_ptr(block_desc->base_addr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) 		else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) 			cvmx_dprintf
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) 			    ("ERROR: cvmx_cmd_queue_initialize: Unable to get named block %s.\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) 			     alloc_name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) 			return CVMX_CMD_QUEUE_NO_MEMORY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) 	return CVMX_CMD_QUEUE_SUCCESS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101)  * Initialize a command queue for use. The initial FPA buffer is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102)  * allocated and the hardware unit is configured to point to the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103)  * new command queue.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105)  * @queue_id:  Hardware command queue to initialize.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106)  * @max_depth: Maximum outstanding commands that can be queued.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107)  * @fpa_pool:  FPA pool the command queues should come from.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108)  * @pool_size: Size of each buffer in the FPA pool (bytes)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110)  * Returns CVMX_CMD_QUEUE_SUCCESS or a failure code
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) cvmx_cmd_queue_result_t cvmx_cmd_queue_initialize(cvmx_cmd_queue_id_t queue_id,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) 						  int max_depth, int fpa_pool,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) 						  int pool_size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) 	__cvmx_cmd_queue_state_t *qstate;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) 	cvmx_cmd_queue_result_t result = __cvmx_cmd_queue_init_state_ptr();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) 	if (result != CVMX_CMD_QUEUE_SUCCESS)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) 		return result;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) 	qstate = __cvmx_cmd_queue_get_state(queue_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) 	if (qstate == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) 		return CVMX_CMD_QUEUE_INVALID_PARAM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) 	 * We artificially limit max_depth to 1<<20 words. It is an
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) 	 * arbitrary limit.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) 	if (CVMX_CMD_QUEUE_ENABLE_MAX_DEPTH) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) 		if ((max_depth < 0) || (max_depth > 1 << 20))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) 			return CVMX_CMD_QUEUE_INVALID_PARAM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) 	} else if (max_depth != 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) 		return CVMX_CMD_QUEUE_INVALID_PARAM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) 	if ((fpa_pool < 0) || (fpa_pool > 7))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) 		return CVMX_CMD_QUEUE_INVALID_PARAM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) 	if ((pool_size < 128) || (pool_size > 65536))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) 		return CVMX_CMD_QUEUE_INVALID_PARAM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) 	/* See if someone else has already initialized the queue */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) 	if (qstate->base_ptr_div128) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) 		if (max_depth != (int)qstate->max_depth) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) 			cvmx_dprintf("ERROR: cvmx_cmd_queue_initialize: "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) 				"Queue already initialized with different "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) 				"max_depth (%d).\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) 			     (int)qstate->max_depth);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) 			return CVMX_CMD_QUEUE_INVALID_PARAM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) 		if (fpa_pool != qstate->fpa_pool) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) 			cvmx_dprintf("ERROR: cvmx_cmd_queue_initialize: "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) 				"Queue already initialized with different "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) 				"FPA pool (%u).\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) 			     qstate->fpa_pool);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) 			return CVMX_CMD_QUEUE_INVALID_PARAM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) 		if ((pool_size >> 3) - 1 != qstate->pool_size_m1) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) 			cvmx_dprintf("ERROR: cvmx_cmd_queue_initialize: "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) 				"Queue already initialized with different "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) 				"FPA pool size (%u).\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) 			     (qstate->pool_size_m1 + 1) << 3);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) 			return CVMX_CMD_QUEUE_INVALID_PARAM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) 		CVMX_SYNCWS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) 		return CVMX_CMD_QUEUE_ALREADY_SETUP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) 		union cvmx_fpa_ctl_status status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) 		void *buffer;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) 		status.u64 = cvmx_read_csr(CVMX_FPA_CTL_STATUS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) 		if (!status.s.enb) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) 			cvmx_dprintf("ERROR: cvmx_cmd_queue_initialize: "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) 				     "FPA is not enabled.\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) 			return CVMX_CMD_QUEUE_NO_MEMORY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) 		buffer = cvmx_fpa_alloc(fpa_pool);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) 		if (buffer == NULL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) 			cvmx_dprintf("ERROR: cvmx_cmd_queue_initialize: "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) 				     "Unable to allocate initial buffer.\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) 			return CVMX_CMD_QUEUE_NO_MEMORY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) 		memset(qstate, 0, sizeof(*qstate));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) 		qstate->max_depth = max_depth;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) 		qstate->fpa_pool = fpa_pool;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) 		qstate->pool_size_m1 = (pool_size >> 3) - 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) 		qstate->base_ptr_div128 = cvmx_ptr_to_phys(buffer) / 128;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) 		 * We zeroed the now serving field so we need to also
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) 		 * zero the ticket.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) 		__cvmx_cmd_queue_state_ptr->
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) 		    ticket[__cvmx_cmd_queue_get_index(queue_id)] = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) 		CVMX_SYNCWS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) 		return CVMX_CMD_QUEUE_SUCCESS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199)  * Shutdown a queue a free it's command buffers to the FPA. The
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200)  * hardware connected to the queue must be stopped before this
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201)  * function is called.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203)  * @queue_id: Queue to shutdown
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205)  * Returns CVMX_CMD_QUEUE_SUCCESS or a failure code
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) cvmx_cmd_queue_result_t cvmx_cmd_queue_shutdown(cvmx_cmd_queue_id_t queue_id)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) 	__cvmx_cmd_queue_state_t *qptr = __cvmx_cmd_queue_get_state(queue_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) 	if (qptr == NULL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) 		cvmx_dprintf("ERROR: cvmx_cmd_queue_shutdown: Unable to "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) 			     "get queue information.\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) 		return CVMX_CMD_QUEUE_INVALID_PARAM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) 	if (cvmx_cmd_queue_length(queue_id) > 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) 		cvmx_dprintf("ERROR: cvmx_cmd_queue_shutdown: Queue still "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) 			     "has data in it.\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) 		return CVMX_CMD_QUEUE_FULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) 	__cvmx_cmd_queue_lock(queue_id, qptr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) 	if (qptr->base_ptr_div128) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) 		cvmx_fpa_free(cvmx_phys_to_ptr
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) 			      ((uint64_t) qptr->base_ptr_div128 << 7),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) 			      qptr->fpa_pool, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) 		qptr->base_ptr_div128 = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) 	__cvmx_cmd_queue_unlock(qptr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) 	return CVMX_CMD_QUEUE_SUCCESS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235)  * Return the number of command words pending in the queue. This
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236)  * function may be relatively slow for some hardware units.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238)  * @queue_id: Hardware command queue to query
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240)  * Returns Number of outstanding commands
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) int cvmx_cmd_queue_length(cvmx_cmd_queue_id_t queue_id)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) 	if (CVMX_ENABLE_PARAMETER_CHECKING) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) 		if (__cvmx_cmd_queue_get_state(queue_id) == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) 			return CVMX_CMD_QUEUE_INVALID_PARAM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) 	 * The cast is here so gcc with check that all values in the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) 	 * cvmx_cmd_queue_id_t enumeration are here.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) 	switch ((cvmx_cmd_queue_id_t) (queue_id & 0xff0000)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) 	case CVMX_CMD_QUEUE_PKO_BASE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) 		 * FIXME: Need atomic lock on
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) 		 * CVMX_PKO_REG_READ_IDX. Right now we are normally
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) 		 * called with the queue lock, so that is a SLIGHT
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) 		 * amount of protection.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) 		cvmx_write_csr(CVMX_PKO_REG_READ_IDX, queue_id & 0xffff);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) 		if (OCTEON_IS_MODEL(OCTEON_CN3XXX)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) 			union cvmx_pko_mem_debug9 debug9;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) 			debug9.u64 = cvmx_read_csr(CVMX_PKO_MEM_DEBUG9);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) 			return debug9.cn38xx.doorbell;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) 		} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) 			union cvmx_pko_mem_debug8 debug8;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) 			debug8.u64 = cvmx_read_csr(CVMX_PKO_MEM_DEBUG8);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) 			return debug8.cn50xx.doorbell;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) 	case CVMX_CMD_QUEUE_ZIP:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) 	case CVMX_CMD_QUEUE_DFA:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) 	case CVMX_CMD_QUEUE_RAID:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) 		/* FIXME: Implement other lengths */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) 	case CVMX_CMD_QUEUE_DMA_BASE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) 		{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) 			union cvmx_npei_dmax_counts dmax_counts;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) 			dmax_counts.u64 =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) 			    cvmx_read_csr(CVMX_PEXP_NPEI_DMAX_COUNTS
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) 					  (queue_id & 0x7));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) 			return dmax_counts.s.dbell;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) 	case CVMX_CMD_QUEUE_END:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) 		return CVMX_CMD_QUEUE_INVALID_PARAM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) 	return CVMX_CMD_QUEUE_INVALID_PARAM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291)  * Return the command buffer to be written to. The purpose of this
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292)  * function is to allow CVMX routine access t othe low level buffer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293)  * for initial hardware setup. User applications should not call this
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294)  * function directly.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296)  * @queue_id: Command queue to query
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298)  * Returns Command buffer or NULL on failure
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) void *cvmx_cmd_queue_buffer(cvmx_cmd_queue_id_t queue_id)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) 	__cvmx_cmd_queue_state_t *qptr = __cvmx_cmd_queue_get_state(queue_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) 	if (qptr && qptr->base_ptr_div128)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) 		return cvmx_phys_to_ptr((uint64_t) qptr->base_ptr_div128 << 7);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) 		return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) }