xref: /openbmc/linux/drivers/net/ethernet/intel/i40e/i40e_adminq.h (revision 6e4f6b5eac461867471b3f368699097b31843d23)
1ae06c70bSJeff Kirsher /* SPDX-License-Identifier: GPL-2.0 */
251dce24bSJeff Kirsher /* Copyright(c) 2013 - 2018 Intel Corporation. */
356a62fc8SJesse Brandeburg 
456a62fc8SJesse Brandeburg #ifndef _I40E_ADMINQ_H_
556a62fc8SJesse Brandeburg #define _I40E_ADMINQ_H_
656a62fc8SJesse Brandeburg 
7*59a9de1aSIvan Vecera #include <linux/mutex.h>
82ee5326dSIvan Vecera #include "i40e_alloc.h"
956a62fc8SJesse Brandeburg #include "i40e_adminq_cmd.h"
1056a62fc8SJesse Brandeburg 
1156a62fc8SJesse Brandeburg #define I40E_ADMINQ_DESC(R, i)   \
1290bb776aSDavid Cassard 	(&(((struct i40e_aq_desc *)((R).desc_buf.va))[i]))
1356a62fc8SJesse Brandeburg 
1456a62fc8SJesse Brandeburg #define I40E_ADMINQ_DESC_ALIGNMENT 4096
1556a62fc8SJesse Brandeburg 
1656a62fc8SJesse Brandeburg struct i40e_adminq_ring {
1790bb776aSDavid Cassard 	struct i40e_virt_mem dma_head;	/* space for dma structures */
1890bb776aSDavid Cassard 	struct i40e_dma_mem desc_buf;	/* descriptor ring memory */
1990bb776aSDavid Cassard 	struct i40e_virt_mem cmd_buf;	/* command buffer memory */
2056a62fc8SJesse Brandeburg 
2156a62fc8SJesse Brandeburg 	union {
2256a62fc8SJesse Brandeburg 		struct i40e_dma_mem *asq_bi;
2356a62fc8SJesse Brandeburg 		struct i40e_dma_mem *arq_bi;
2456a62fc8SJesse Brandeburg 	} r;
2556a62fc8SJesse Brandeburg 
2656a62fc8SJesse Brandeburg 	u16 count;		/* Number of descriptors */
2756a62fc8SJesse Brandeburg 	u16 rx_buf_len;		/* Admin Receive Queue buffer length */
2856a62fc8SJesse Brandeburg 
2956a62fc8SJesse Brandeburg 	/* used for interrupt processing */
3056a62fc8SJesse Brandeburg 	u16 next_to_use;
3156a62fc8SJesse Brandeburg 	u16 next_to_clean;
3256a62fc8SJesse Brandeburg 
3356a62fc8SJesse Brandeburg 	/* used for queue tracking */
3456a62fc8SJesse Brandeburg 	u32 head;
3556a62fc8SJesse Brandeburg 	u32 tail;
3617e6a845SShannon Nelson 	u32 len;
3787dc3464SShannon Nelson 	u32 bah;
3887dc3464SShannon Nelson 	u32 bal;
3956a62fc8SJesse Brandeburg };
4056a62fc8SJesse Brandeburg 
4156a62fc8SJesse Brandeburg /* ASQ transaction details */
4256a62fc8SJesse Brandeburg struct i40e_asq_cmd_details {
4356a62fc8SJesse Brandeburg 	void *callback; /* cast from type I40E_ADMINQ_CALLBACK */
4456a62fc8SJesse Brandeburg 	u64 cookie;
4556a62fc8SJesse Brandeburg 	u16 flags_ena;
4656a62fc8SJesse Brandeburg 	u16 flags_dis;
4756a62fc8SJesse Brandeburg 	bool async;
4856a62fc8SJesse Brandeburg 	bool postpone;
4987db27a9SShannon Nelson 	struct i40e_aq_desc *wb_desc;
5056a62fc8SJesse Brandeburg };
5156a62fc8SJesse Brandeburg 
5256a62fc8SJesse Brandeburg #define I40E_ADMINQ_DETAILS(R, i)   \
5390bb776aSDavid Cassard 	(&(((struct i40e_asq_cmd_details *)((R).cmd_buf.va))[i]))
5456a62fc8SJesse Brandeburg 
5556a62fc8SJesse Brandeburg /* ARQ event information */
5656a62fc8SJesse Brandeburg struct i40e_arq_event_info {
5756a62fc8SJesse Brandeburg 	struct i40e_aq_desc desc;
581001dc37SMitch Williams 	u16 msg_len;
591001dc37SMitch Williams 	u16 buf_len;
6056a62fc8SJesse Brandeburg 	u8 *msg_buf;
6156a62fc8SJesse Brandeburg };
6256a62fc8SJesse Brandeburg 
6356a62fc8SJesse Brandeburg /* Admin Queue information */
6456a62fc8SJesse Brandeburg struct i40e_adminq_info {
6556a62fc8SJesse Brandeburg 	struct i40e_adminq_ring arq;    /* receive queue */
6656a62fc8SJesse Brandeburg 	struct i40e_adminq_ring asq;    /* send queue */
6709c4e56bSKamil Krawczyk 	u32 asq_cmd_timeout;            /* send queue cmd write back timeout*/
6856a62fc8SJesse Brandeburg 	u16 num_arq_entries;            /* receive queue depth */
6956a62fc8SJesse Brandeburg 	u16 num_asq_entries;            /* send queue depth */
7056a62fc8SJesse Brandeburg 	u16 arq_buf_size;               /* receive queue buffer size */
7156a62fc8SJesse Brandeburg 	u16 asq_buf_size;               /* send queue buffer size */
7256a62fc8SJesse Brandeburg 	u16 fw_maj_ver;                 /* firmware major version */
7356a62fc8SJesse Brandeburg 	u16 fw_min_ver;                 /* firmware minor version */
747edf810cSShannon Nelson 	u32 fw_build;                   /* firmware build number */
7556a62fc8SJesse Brandeburg 	u16 api_maj_ver;                /* api major version */
7656a62fc8SJesse Brandeburg 	u16 api_min_ver;                /* api minor version */
7756a62fc8SJesse Brandeburg 
7856a62fc8SJesse Brandeburg 	struct mutex asq_mutex; /* Send queue lock */
7956a62fc8SJesse Brandeburg 	struct mutex arq_mutex; /* Receive queue lock */
8056a62fc8SJesse Brandeburg 
8156a62fc8SJesse Brandeburg 	/* last status values on send and receive queues */
8256a62fc8SJesse Brandeburg 	enum i40e_admin_queue_err asq_last_status;
8356a62fc8SJesse Brandeburg 	enum i40e_admin_queue_err arq_last_status;
8456a62fc8SJesse Brandeburg };
8556a62fc8SJesse Brandeburg 
86cd552cb4SShannon Nelson /**
87cd552cb4SShannon Nelson  * i40e_aq_rc_to_posix - convert errors to user-land codes
88b50f7bcaSJesse Brandeburg  * @aq_ret: AdminQ handler error code can override aq_rc
89b50f7bcaSJesse Brandeburg  * @aq_rc: AdminQ firmware error code to convert
90cd552cb4SShannon Nelson  **/
i40e_aq_rc_to_posix(int aq_ret,int aq_rc)911fa89a4bSShannon Nelson static inline int i40e_aq_rc_to_posix(int aq_ret, int aq_rc)
92cd552cb4SShannon Nelson {
93cd552cb4SShannon Nelson 	int aq_to_posix[] = {
94cd552cb4SShannon Nelson 		0,           /* I40E_AQ_RC_OK */
95cd552cb4SShannon Nelson 		-EPERM,      /* I40E_AQ_RC_EPERM */
96cd552cb4SShannon Nelson 		-ENOENT,     /* I40E_AQ_RC_ENOENT */
97cd552cb4SShannon Nelson 		-ESRCH,      /* I40E_AQ_RC_ESRCH */
98cd552cb4SShannon Nelson 		-EINTR,      /* I40E_AQ_RC_EINTR */
99cd552cb4SShannon Nelson 		-EIO,        /* I40E_AQ_RC_EIO */
100cd552cb4SShannon Nelson 		-ENXIO,      /* I40E_AQ_RC_ENXIO */
101cd552cb4SShannon Nelson 		-E2BIG,      /* I40E_AQ_RC_E2BIG */
102cd552cb4SShannon Nelson 		-EAGAIN,     /* I40E_AQ_RC_EAGAIN */
103cd552cb4SShannon Nelson 		-ENOMEM,     /* I40E_AQ_RC_ENOMEM */
104cd552cb4SShannon Nelson 		-EACCES,     /* I40E_AQ_RC_EACCES */
105cd552cb4SShannon Nelson 		-EFAULT,     /* I40E_AQ_RC_EFAULT */
106cd552cb4SShannon Nelson 		-EBUSY,      /* I40E_AQ_RC_EBUSY */
107cd552cb4SShannon Nelson 		-EEXIST,     /* I40E_AQ_RC_EEXIST */
108cd552cb4SShannon Nelson 		-EINVAL,     /* I40E_AQ_RC_EINVAL */
109cd552cb4SShannon Nelson 		-ENOTTY,     /* I40E_AQ_RC_ENOTTY */
110cd552cb4SShannon Nelson 		-ENOSPC,     /* I40E_AQ_RC_ENOSPC */
111cd552cb4SShannon Nelson 		-ENOSYS,     /* I40E_AQ_RC_ENOSYS */
112cd552cb4SShannon Nelson 		-ERANGE,     /* I40E_AQ_RC_ERANGE */
113cd552cb4SShannon Nelson 		-EPIPE,      /* I40E_AQ_RC_EFLUSHED */
114cd552cb4SShannon Nelson 		-ESPIPE,     /* I40E_AQ_RC_BAD_ADDR */
115cd552cb4SShannon Nelson 		-EROFS,      /* I40E_AQ_RC_EMODE */
116cd552cb4SShannon Nelson 		-EFBIG,      /* I40E_AQ_RC_EFBIG */
117cd552cb4SShannon Nelson 	};
118cd552cb4SShannon Nelson 
119df08fd4dSShannon Nelson 	if (!((u32)aq_rc < (sizeof(aq_to_posix) / sizeof((aq_to_posix)[0]))))
12043477d2bSShannon Nelson 		return -ERANGE;
1211fa89a4bSShannon Nelson 
122cd552cb4SShannon Nelson 	return aq_to_posix[aq_rc];
123cd552cb4SShannon Nelson }
124cd552cb4SShannon Nelson 
12556a62fc8SJesse Brandeburg /* general information */
12656a62fc8SJesse Brandeburg #define I40E_AQ_LARGE_BUF	512
1279e3f23f4SJacob Keller #define I40E_ASQ_CMD_TIMEOUT	250000  /* usecs */
12856a62fc8SJesse Brandeburg 
12956a62fc8SJesse Brandeburg void i40e_fill_default_direct_cmd_desc(struct i40e_aq_desc *desc,
13056a62fc8SJesse Brandeburg 				       u16 opcode);
13156a62fc8SJesse Brandeburg 
13256a62fc8SJesse Brandeburg #endif /* _I40E_ADMINQ_H_ */
133