/*
 * Copyright (C) 2026-2026 Cornelis Networks.
 *
 * This software is available to you under a choice of one of two
 * licenses.  You may choose to be licensed under the terms of the GNU
 * General Public License (GPL) Version 2, available from the file
 * COPYING in the main directory of this source tree, or the
 * BSD license below:
 *
 *     Redistribution and use in source and binary forms, with or
 *     without modification, are permitted provided that the following
 *     conditions are met:
 *
 *      - Redistributions of source code must retain the above
 *        copyright notice, this list of conditions and the following
 *        disclaimer.
 *
 *      - Redistributions in binary form must reproduce the above
 *        copyright notice, this list of conditions and the following
 *        disclaimer in the documentation and/or other materials
 *        provided with the distribution.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 * SOFTWARE.
 */
#ifndef _OPX_TRACER_EVENTS_H_
#define _OPX_TRACER_EVENTS_H_

enum opx_trace_event_id {
	/* TX events */
	OPX_TRACE_EVENT_TX_INJECT = 0,
	OPX_TRACE_EVENT_TX_RZV_RTS,
	OPX_TRACE_EVENT_TX_RMA_RTS, /* RMA-initiated RTS (different arg format than TX_RZV_RTS) */
	OPX_TRACE_EVENT_TX_RZV_CTS,
	OPX_TRACE_EVENT_TX_RZV_DATA,
	OPX_TRACE_EVENT_TX_MP_EAGER_NTH,
	OPX_TRACE_EVENT_TX_CONNECT,
	OPX_TRACE_EVENT_TX_SEND,
	OPX_TRACE_EVENT_TX_INJECT_SHM,
	OPX_TRACE_EVENT_TX_INJECT_HFI,
	OPX_TRACE_EVENT_TX_EAGER_SHM,
	OPX_TRACE_EVENT_TX_EAGER_HFI,
	OPX_TRACE_EVENT_TX_SENDV_EAGER_SHM,
	OPX_TRACE_EVENT_TX_SENDV_EAGER_HFI,
	OPX_TRACE_EVENT_TX_MP_EAGER_FIRST_HFI,

	/* RX events */
	OPX_TRACE_EVENT_RX_INJECT,
	OPX_TRACE_EVENT_RX_EAGER,
	OPX_TRACE_EVENT_RX_RZV_RTS,
	OPX_TRACE_EVENT_RX_RZV_RTS_HFISVC,
	OPX_TRACE_EVENT_RX_MP_EAGER_FIRST,
	OPX_TRACE_EVENT_RX_MP_EAGER_NTH,
	OPX_TRACE_EVENT_RX_RZV_CTS_HFI,
	OPX_TRACE_EVENT_RX_RMA_RTS,
	OPX_TRACE_EVENT_RX_RZV_DATA_HFI_DPUT,
	OPX_TRACE_EVENT_RX_RZV_TID,
	OPX_TRACE_EVENT_RX_POST_RECV,
	OPX_TRACE_EVENT_RX_POST_RECVMSG,

	/* SDMA events */
	OPX_TRACE_EVENT_SDMA_HW_INFLIGHT,
	OPX_TRACE_EVENT_SDMA_ERROR,
	OPX_TRACE_EVENT_SDMA_WRITEV,
	OPX_TRACE_EVENT_SDMA_DPUT,
	OPX_TRACE_EVENT_SDMA_GET_PSNS,
	OPX_TRACE_EVENT_SDMA_GET_PSN_THROTTLE,
	OPX_TRACE_EVENT_SDMA_GET_IDLE_WE,
	OPX_TRACE_EVENT_SDMA_GET_REUSED_WE,
	OPX_TRACE_EVENT_SDMA_GET_NO_WE,
	OPX_TRACE_EVENT_SDMA_TX_FLOW_CREATE_FAIL,

	/* PIO events */
	OPX_TRACE_EVENT_PIO_SEND,
	OPX_TRACE_EVENT_PIO_COMPLETE,

	/* RELI events */
	OPX_TRACE_EVENT_RELI_ACK_SEND,
	OPX_TRACE_EVENT_RELI_ACK_RECV,
	OPX_TRACE_EVENT_RELI_NACK_SEND,
	OPX_TRACE_EVENT_RELI_NACK_RECV,
	OPX_TRACE_EVENT_RELI_PING,
	OPX_TRACE_EVENT_RELI_PING_RESPONSE,
	OPX_TRACE_EVENT_RELI_SEND_PRE_ACKS,
	OPX_TRACE_EVENT_RELI_PROCESS_PENDING,
	OPX_TRACE_EVENT_RELI_PIO_REPLAY,
	OPX_TRACE_EVENT_RELI_SDMA_REPLAY,
	OPX_TRACE_EVENT_RELI_SDMA_REPLAY_COMPLETE,

	/* CQ events */
	OPX_TRACE_EVENT_CQ_POLL,
	OPX_TRACE_EVENT_CQ_COMPLETE,
	OPX_TRACE_EVENT_CQ_READ,

	/* MR events */
	OPX_TRACE_EVENT_MR_REG,
	OPX_TRACE_EVENT_MR_DEREG,
	OPX_TRACE_EVENT_MR_CACHE_HIT,
	OPX_TRACE_EVENT_MR_CACHE_MISS,
	OPX_TRACE_EVENT_MR_CACHE_SEARCH,

	/* TID events */
	OPX_TRACE_EVENT_TID_UPDATE,
	OPX_TRACE_EVENT_TID_FREE,
	OPX_TRACE_EVENT_TID_CACHE_HIT,
	OPX_TRACE_EVENT_TID_CACHE_MISS,

	/* PROGRESS events */
	OPX_TRACE_EVENT_PROGRESS_POLL,
	OPX_TRACE_EVENT_PROGRESS_WORK,
	OPX_TRACE_EVENT_PROGRESS_IDLE,
	OPX_TRACE_EVENT_PROGRESS_DEFERRED_WORK,

	/* HMEM events */
	OPX_TRACE_EVENT_HMEM_COPY,
	OPX_TRACE_EVENT_HMEM_REG,
	OPX_TRACE_EVENT_HMEM_DETECT,
	OPX_TRACE_EVENT_HMEM_CACHE_INIT,
	OPX_TRACE_EVENT_HMEM_DEV_REGISTER,
	OPX_TRACE_EVENT_HMEM_DEV_UNREGISTER,
	OPX_TRACE_EVENT_HMEM_COPY_TO,
	OPX_TRACE_EVENT_HMEM_COPY_FROM,
	OPX_TRACE_EVENT_HMEM_GDRCOPY_TO_DEV,
	OPX_TRACE_EVENT_HMEM_GDRCOPY_FROM_DEV,
	OPX_TRACE_EVENT_HMEM_CUDAMEMCPY_TO,
	OPX_TRACE_EVENT_HMEM_CUDAMEMCPY_FROM,
	OPX_TRACE_EVENT_HMEM_AMD_DEV_REG_TO,
	OPX_TRACE_EVENT_HMEM_AMD_DEV_REG_FROM,
	OPX_TRACE_EVENT_HMEM_AMD_ROCR_TO,
	OPX_TRACE_EVENT_HMEM_AMD_ROCR_FROM,
	OPX_TRACE_EVENT_HMEM_OFI_COPY_TO,
	OPX_TRACE_EVENT_HMEM_OFI_COPY_FROM,

	/* ATOMIC events */
	OPX_TRACE_EVENT_ATOMIC_WRITE,
	OPX_TRACE_EVENT_ATOMIC_FETCH,
	OPX_TRACE_EVENT_ATOMIC_CSWAP,

	/* RMA events */
	OPX_TRACE_EVENT_RMA_READ,
	OPX_TRACE_EVENT_RMA_READV,
	OPX_TRACE_EVENT_RMA_READMSG,
	OPX_TRACE_EVENT_RMA_WRITE,
	OPX_TRACE_EVENT_RMA_WRITEV,
	OPX_TRACE_EVENT_RMA_WRITEMSG,
	OPX_TRACE_EVENT_RMA_INJECT_WRITE,
	OPX_TRACE_EVENT_RMA_DO_READV,
	OPX_TRACE_EVENT_RMA_READV_INTERNAL,
	OPX_TRACE_EVENT_RMA_WRITE_INTERNAL,

	/* LOCK events */
	OPX_TRACE_EVENT_LOCK_ACQUIRE,
	OPX_TRACE_EVENT_LOCK_RELEASE,
	OPX_TRACE_EVENT_LOCK_CONTENTION,
	OPX_TRACE_EVENT_LOCK_HELD,

	/* IPC events */
	OPX_TRACE_EVENT_IPC_RECV_SEND_CTS,
	OPX_TRACE_EVENT_IPC_SEND_PROCESS_CTS,

	/* HFISVC events */
	OPX_TRACE_EVENT_HFISVC_RZV_RTS,

	/* INTERNAL events - always last */
	OPX_TRACE_EVENT_FLUSH,

	OPX_TRACE_EVENT_COUNT
};

/*
 * Event names array - maps event IDs to human-readable names
 * These names are written to the binary trace file header and used by the parser
 *
 * Note: Argument names are NOT stored in the binary file to minimize file size.
 * The parser applies semantic argument names based on the event type at parse time.
 * See EVENT_ARG_NAMES in opx_trace_parse.py for the argument name mappings.
 */
static const char *opx_trace_event_names[] __attribute__((unused)) = {
	/* TX events */
	[OPX_TRACE_EVENT_TX_INJECT]		= "TX_INJECT",
	[OPX_TRACE_EVENT_TX_RZV_RTS]		= "TX_RZV_RTS",
	[OPX_TRACE_EVENT_TX_RMA_RTS]		= "TX_RMA_RTS",
	[OPX_TRACE_EVENT_TX_RZV_CTS]		= "TX_RZV_CTS",
	[OPX_TRACE_EVENT_TX_RZV_DATA]		= "TX_RZV_DATA",
	[OPX_TRACE_EVENT_TX_MP_EAGER_NTH]	= "TX_MP_EAGER_NTH",
	[OPX_TRACE_EVENT_TX_CONNECT]		= "TX_CONNECT",
	[OPX_TRACE_EVENT_TX_SEND]		= "TX_SEND",
	[OPX_TRACE_EVENT_TX_INJECT_SHM]		= "TX_INJECT_SHM",
	[OPX_TRACE_EVENT_TX_INJECT_HFI]		= "TX_INJECT_HFI",
	[OPX_TRACE_EVENT_TX_EAGER_SHM]		= "TX_EAGER_SHM",
	[OPX_TRACE_EVENT_TX_EAGER_HFI]		= "TX_EAGER_HFI",
	[OPX_TRACE_EVENT_TX_SENDV_EAGER_SHM]	= "TX_SENDV_EAGER_SHM",
	[OPX_TRACE_EVENT_TX_SENDV_EAGER_HFI]	= "TX_SENDV_EAGER_HFI",
	[OPX_TRACE_EVENT_TX_MP_EAGER_FIRST_HFI] = "TX_MP_EAGER_FIRST_HFI",

	/* RX events */
	[OPX_TRACE_EVENT_RX_INJECT]	       = "RX_INJECT",
	[OPX_TRACE_EVENT_RX_EAGER]	       = "RX_EAGER",
	[OPX_TRACE_EVENT_RX_RZV_RTS]	       = "RX_RZV_RTS",
	[OPX_TRACE_EVENT_RX_RZV_RTS_HFISVC]    = "RX_RZV_RTS_HFISVC",
	[OPX_TRACE_EVENT_RX_MP_EAGER_FIRST]    = "RX_MP_EAGER_FIRST",
	[OPX_TRACE_EVENT_RX_MP_EAGER_NTH]      = "RX_MP_EAGER_NTH",
	[OPX_TRACE_EVENT_RX_RZV_CTS_HFI]       = "RX_RZV_CTS_HFI",
	[OPX_TRACE_EVENT_RX_RMA_RTS]	       = "RX_RMA_RTS",
	[OPX_TRACE_EVENT_RX_RZV_DATA_HFI_DPUT] = "RX_RZV_DATA_HFI_DPUT",
	[OPX_TRACE_EVENT_RX_RZV_TID]	       = "RX_RZV_TID",
	[OPX_TRACE_EVENT_RX_POST_RECV]	       = "RX_POST_RECV",
	[OPX_TRACE_EVENT_RX_POST_RECVMSG]      = "RX_POST_RECVMSG",

	/* SDMA events */
	[OPX_TRACE_EVENT_SDMA_HW_INFLIGHT]	   = "SDMA_HW_INFLIGHT",
	[OPX_TRACE_EVENT_SDMA_ERROR]		   = "SDMA_ERROR",
	[OPX_TRACE_EVENT_SDMA_WRITEV]		   = "SDMA_WRITEV",
	[OPX_TRACE_EVENT_SDMA_DPUT]		   = "SDMA_DPUT",
	[OPX_TRACE_EVENT_SDMA_GET_PSNS]		   = "SDMA_GET_PSNS",
	[OPX_TRACE_EVENT_SDMA_GET_PSN_THROTTLE]	   = "SDMA_GET_PSN_THROTTLE",
	[OPX_TRACE_EVENT_SDMA_GET_IDLE_WE]	   = "SDMA_GET_IDLE_WE",
	[OPX_TRACE_EVENT_SDMA_GET_REUSED_WE]	   = "SDMA_GET_REUSED_WE",
	[OPX_TRACE_EVENT_SDMA_GET_NO_WE]	   = "SDMA_GET_NO_WE",
	[OPX_TRACE_EVENT_SDMA_TX_FLOW_CREATE_FAIL] = "SDMA_TX_FLOW_CREATE_FAIL",

	/* PIO events */
	[OPX_TRACE_EVENT_PIO_SEND]     = "PIO_SEND",
	[OPX_TRACE_EVENT_PIO_COMPLETE] = "PIO_COMPLETE",

	/* RELI events */
	[OPX_TRACE_EVENT_RELI_ACK_SEND]		    = "RELI_ACK_SEND",
	[OPX_TRACE_EVENT_RELI_ACK_RECV]		    = "RELI_ACK_RECV",
	[OPX_TRACE_EVENT_RELI_NACK_SEND]	    = "RELI_NACK_SEND",
	[OPX_TRACE_EVENT_RELI_NACK_RECV]	    = "RELI_NACK_RECV",
	[OPX_TRACE_EVENT_RELI_PING]		    = "RELI_PING",
	[OPX_TRACE_EVENT_RELI_PING_RESPONSE]	    = "RELI_PING_RESPONSE",
	[OPX_TRACE_EVENT_RELI_SEND_PRE_ACKS]	    = "RELI_SEND_PRE_ACKS",
	[OPX_TRACE_EVENT_RELI_PROCESS_PENDING]	    = "RELI_PROCESS_PENDING",
	[OPX_TRACE_EVENT_RELI_PIO_REPLAY]	    = "RELI_PIO_REPLAY",
	[OPX_TRACE_EVENT_RELI_SDMA_REPLAY]	    = "RELI_SDMA_REPLAY",
	[OPX_TRACE_EVENT_RELI_SDMA_REPLAY_COMPLETE] = "RELI_SDMA_REPLAY_COMPLETE",

	/* CQ events */
	[OPX_TRACE_EVENT_CQ_POLL]     = "CQ_POLL",
	[OPX_TRACE_EVENT_CQ_COMPLETE] = "CQ_COMPLETE",
	[OPX_TRACE_EVENT_CQ_READ]     = "CQ_READ",

	/* MR events */
	[OPX_TRACE_EVENT_MR_REG]	  = "MR_REG",
	[OPX_TRACE_EVENT_MR_DEREG]	  = "MR_DEREG",
	[OPX_TRACE_EVENT_MR_CACHE_HIT]	  = "MR_CACHE_HIT",
	[OPX_TRACE_EVENT_MR_CACHE_MISS]	  = "MR_CACHE_MISS",
	[OPX_TRACE_EVENT_MR_CACHE_SEARCH] = "MR_CACHE_SEARCH",

	/* TID events */
	[OPX_TRACE_EVENT_TID_UPDATE]	 = "TID_UPDATE",
	[OPX_TRACE_EVENT_TID_FREE]	 = "TID_FREE",
	[OPX_TRACE_EVENT_TID_CACHE_HIT]	 = "TID_CACHE_HIT",
	[OPX_TRACE_EVENT_TID_CACHE_MISS] = "TID_CACHE_MISS",

	/* PROGRESS events */
	[OPX_TRACE_EVENT_PROGRESS_POLL]		 = "PROGRESS_POLL",
	[OPX_TRACE_EVENT_PROGRESS_WORK]		 = "PROGRESS_WORK",
	[OPX_TRACE_EVENT_PROGRESS_IDLE]		 = "PROGRESS_IDLE",
	[OPX_TRACE_EVENT_PROGRESS_DEFERRED_WORK] = "PROGRESS_DEFERRED_WORK",

	/* HMEM events */
	[OPX_TRACE_EVENT_HMEM_COPY]		= "HMEM_COPY",
	[OPX_TRACE_EVENT_HMEM_REG]		= "HMEM_REG",
	[OPX_TRACE_EVENT_HMEM_DETECT]		= "HMEM_DETECT",
	[OPX_TRACE_EVENT_HMEM_CACHE_INIT]	= "HMEM_CACHE_INIT",
	[OPX_TRACE_EVENT_HMEM_DEV_REGISTER]	= "HMEM_DEV_REGISTER",
	[OPX_TRACE_EVENT_HMEM_DEV_UNREGISTER]	= "HMEM_DEV_UNREGISTER",
	[OPX_TRACE_EVENT_HMEM_COPY_TO]		= "HMEM_COPY_TO",
	[OPX_TRACE_EVENT_HMEM_COPY_FROM]	= "HMEM_COPY_FROM",
	[OPX_TRACE_EVENT_HMEM_GDRCOPY_TO_DEV]	= "HMEM_GDRCOPY_TO_DEV",
	[OPX_TRACE_EVENT_HMEM_GDRCOPY_FROM_DEV] = "HMEM_GDRCOPY_FROM_DEV",
	[OPX_TRACE_EVENT_HMEM_CUDAMEMCPY_TO]	= "HMEM_CUDAMEMCPY_TO",
	[OPX_TRACE_EVENT_HMEM_CUDAMEMCPY_FROM]	= "HMEM_CUDAMEMCPY_FROM",
	[OPX_TRACE_EVENT_HMEM_AMD_DEV_REG_TO]	= "HMEM_AMD_DEV_REG_TO",
	[OPX_TRACE_EVENT_HMEM_AMD_DEV_REG_FROM] = "HMEM_AMD_DEV_REG_FROM",
	[OPX_TRACE_EVENT_HMEM_AMD_ROCR_TO]	= "HMEM_AMD_ROCR_TO",
	[OPX_TRACE_EVENT_HMEM_AMD_ROCR_FROM]	= "HMEM_AMD_ROCR_FROM",
	[OPX_TRACE_EVENT_HMEM_OFI_COPY_TO]	= "HMEM_OFI_COPY_TO",
	[OPX_TRACE_EVENT_HMEM_OFI_COPY_FROM]	= "HMEM_OFI_COPY_FROM",

	/* ATOMIC events */
	[OPX_TRACE_EVENT_ATOMIC_WRITE] = "ATOMIC_WRITE",
	[OPX_TRACE_EVENT_ATOMIC_FETCH] = "ATOMIC_FETCH",
	[OPX_TRACE_EVENT_ATOMIC_CSWAP] = "ATOMIC_CSWAP",

	/* RMA events */
	[OPX_TRACE_EVENT_RMA_READ]	     = "RMA_READ",
	[OPX_TRACE_EVENT_RMA_READV]	     = "RMA_READV",
	[OPX_TRACE_EVENT_RMA_READMSG]	     = "RMA_READMSG",
	[OPX_TRACE_EVENT_RMA_WRITE]	     = "RMA_WRITE",
	[OPX_TRACE_EVENT_RMA_WRITEV]	     = "RMA_WRITEV",
	[OPX_TRACE_EVENT_RMA_WRITEMSG]	     = "RMA_WRITEMSG",
	[OPX_TRACE_EVENT_RMA_INJECT_WRITE]   = "RMA_INJECT_WRITE",
	[OPX_TRACE_EVENT_RMA_DO_READV]	     = "RMA_DO_READV",
	[OPX_TRACE_EVENT_RMA_READV_INTERNAL] = "RMA_READV_INTERNAL",
	[OPX_TRACE_EVENT_RMA_WRITE_INTERNAL] = "RMA_WRITE_INTERNAL",

	/* LOCK events */
	[OPX_TRACE_EVENT_LOCK_ACQUIRE]	  = "LOCK_ACQUIRE",
	[OPX_TRACE_EVENT_LOCK_RELEASE]	  = "LOCK_RELEASE",
	[OPX_TRACE_EVENT_LOCK_CONTENTION] = "LOCK_CONTENTION",
	[OPX_TRACE_EVENT_LOCK_HELD]	  = "LOCK_HELD",

	/* IPC events */
	[OPX_TRACE_EVENT_IPC_RECV_SEND_CTS]    = "IPC_RECV_SEND_CTS",
	[OPX_TRACE_EVENT_IPC_SEND_PROCESS_CTS] = "IPC_SEND_PROCESS_CTS",

	/* HFISVC events */
	[OPX_TRACE_EVENT_HFISVC_RZV_RTS] = "HFISVC_RZV_RTS",

	/* INTERNAL events */
	[OPX_TRACE_EVENT_FLUSH] = "TRACER_FLUSH",
};

_Static_assert(sizeof(opx_trace_event_names) / sizeof(opx_trace_event_names[0]) == OPX_TRACE_EVENT_COUNT,
	       "opx_trace_event_names array size must match OPX_TRACE_EVENT_COUNT");

#endif /* _OPX_TRACER_EVENTS_H_ */
