161ae650dSJack F Vogel /******************************************************************************
261ae650dSJack F Vogel
3*f4cc2d17SEric Joyner Copyright (c) 2013-2018, Intel Corporation
461ae650dSJack F Vogel All rights reserved.
561ae650dSJack F Vogel
661ae650dSJack F Vogel Redistribution and use in source and binary forms, with or without
761ae650dSJack F Vogel modification, are permitted provided that the following conditions are met:
861ae650dSJack F Vogel
961ae650dSJack F Vogel 1. Redistributions of source code must retain the above copyright notice,
1061ae650dSJack F Vogel this list of conditions and the following disclaimer.
1161ae650dSJack F Vogel
1261ae650dSJack F Vogel 2. Redistributions in binary form must reproduce the above copyright
1361ae650dSJack F Vogel notice, this list of conditions and the following disclaimer in the
1461ae650dSJack F Vogel documentation and/or other materials provided with the distribution.
1561ae650dSJack F Vogel
1661ae650dSJack F Vogel 3. Neither the name of the Intel Corporation nor the names of its
1761ae650dSJack F Vogel contributors may be used to endorse or promote products derived from
1861ae650dSJack F Vogel this software without specific prior written permission.
1961ae650dSJack F Vogel
2061ae650dSJack F Vogel THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
2161ae650dSJack F Vogel AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
2261ae650dSJack F Vogel IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
2361ae650dSJack F Vogel ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
2461ae650dSJack F Vogel LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
2561ae650dSJack F Vogel CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
2661ae650dSJack F Vogel SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
2761ae650dSJack F Vogel INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
2861ae650dSJack F Vogel CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
2961ae650dSJack F Vogel ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
3061ae650dSJack F Vogel POSSIBILITY OF SUCH DAMAGE.
3161ae650dSJack F Vogel
3261ae650dSJack F Vogel ******************************************************************************/
3361ae650dSJack F Vogel
3461ae650dSJack F Vogel #ifndef _I40E_ADMINQ_H_
3561ae650dSJack F Vogel #define _I40E_ADMINQ_H_
3661ae650dSJack F Vogel
3761ae650dSJack F Vogel #include "i40e_osdep.h"
38f247dc25SJack F Vogel #include "i40e_status.h"
3961ae650dSJack F Vogel #include "i40e_adminq_cmd.h"
4061ae650dSJack F Vogel
4161ae650dSJack F Vogel #define I40E_ADMINQ_DESC(R, i) \
4261ae650dSJack F Vogel (&(((struct i40e_aq_desc *)((R).desc_buf.va))[i]))
4361ae650dSJack F Vogel
4461ae650dSJack F Vogel #define I40E_ADMINQ_DESC_ALIGNMENT 4096
4561ae650dSJack F Vogel
4661ae650dSJack F Vogel struct i40e_adminq_ring {
4761ae650dSJack F Vogel struct i40e_virt_mem dma_head; /* space for dma structures */
4861ae650dSJack F Vogel struct i40e_dma_mem desc_buf; /* descriptor ring memory */
4961ae650dSJack F Vogel struct i40e_virt_mem cmd_buf; /* command buffer memory */
5061ae650dSJack F Vogel
5161ae650dSJack F Vogel union {
5261ae650dSJack F Vogel struct i40e_dma_mem *asq_bi;
5361ae650dSJack F Vogel struct i40e_dma_mem *arq_bi;
5461ae650dSJack F Vogel } r;
5561ae650dSJack F Vogel
5661ae650dSJack F Vogel u16 count; /* Number of descriptors */
5761ae650dSJack F Vogel u16 rx_buf_len; /* Admin Receive Queue buffer length */
5861ae650dSJack F Vogel
5961ae650dSJack F Vogel /* used for interrupt processing */
6061ae650dSJack F Vogel u16 next_to_use;
6161ae650dSJack F Vogel u16 next_to_clean;
6261ae650dSJack F Vogel
6361ae650dSJack F Vogel /* used for queue tracking */
6461ae650dSJack F Vogel u32 head;
6561ae650dSJack F Vogel u32 tail;
6661ae650dSJack F Vogel u32 len;
6761ae650dSJack F Vogel u32 bah;
6861ae650dSJack F Vogel u32 bal;
6961ae650dSJack F Vogel };
7061ae650dSJack F Vogel
7161ae650dSJack F Vogel /* ASQ transaction details */
7261ae650dSJack F Vogel struct i40e_asq_cmd_details {
7361ae650dSJack F Vogel void *callback; /* cast from type I40E_ADMINQ_CALLBACK */
7461ae650dSJack F Vogel u64 cookie;
7561ae650dSJack F Vogel u16 flags_ena;
7661ae650dSJack F Vogel u16 flags_dis;
7761ae650dSJack F Vogel bool async;
7861ae650dSJack F Vogel bool postpone;
79be771cdaSJack F Vogel struct i40e_aq_desc *wb_desc;
8061ae650dSJack F Vogel };
8161ae650dSJack F Vogel
8261ae650dSJack F Vogel #define I40E_ADMINQ_DETAILS(R, i) \
8361ae650dSJack F Vogel (&(((struct i40e_asq_cmd_details *)((R).cmd_buf.va))[i]))
8461ae650dSJack F Vogel
8561ae650dSJack F Vogel /* ARQ event information */
8661ae650dSJack F Vogel struct i40e_arq_event_info {
8761ae650dSJack F Vogel struct i40e_aq_desc desc;
8861ae650dSJack F Vogel u16 msg_len;
8961ae650dSJack F Vogel u16 buf_len;
9061ae650dSJack F Vogel u8 *msg_buf;
9161ae650dSJack F Vogel };
9261ae650dSJack F Vogel
9361ae650dSJack F Vogel /* Admin Queue information */
9461ae650dSJack F Vogel struct i40e_adminq_info {
9561ae650dSJack F Vogel struct i40e_adminq_ring arq; /* receive queue */
9661ae650dSJack F Vogel struct i40e_adminq_ring asq; /* send queue */
9761ae650dSJack F Vogel u32 asq_cmd_timeout; /* send queue cmd write back timeout*/
9861ae650dSJack F Vogel u16 num_arq_entries; /* receive queue depth */
9961ae650dSJack F Vogel u16 num_asq_entries; /* send queue depth */
10061ae650dSJack F Vogel u16 arq_buf_size; /* receive queue buffer size */
10161ae650dSJack F Vogel u16 asq_buf_size; /* send queue buffer size */
10261ae650dSJack F Vogel u16 fw_maj_ver; /* firmware major version */
10361ae650dSJack F Vogel u16 fw_min_ver; /* firmware minor version */
104f247dc25SJack F Vogel u32 fw_build; /* firmware build number */
10561ae650dSJack F Vogel u16 api_maj_ver; /* api major version */
10661ae650dSJack F Vogel u16 api_min_ver; /* api minor version */
10761ae650dSJack F Vogel
10861ae650dSJack F Vogel struct i40e_spinlock asq_spinlock; /* Send queue spinlock */
10961ae650dSJack F Vogel struct i40e_spinlock arq_spinlock; /* Receive queue spinlock */
11061ae650dSJack F Vogel
11161ae650dSJack F Vogel /* last status values on send and receive queues */
11261ae650dSJack F Vogel enum i40e_admin_queue_err asq_last_status;
11361ae650dSJack F Vogel enum i40e_admin_queue_err arq_last_status;
11461ae650dSJack F Vogel };
11561ae650dSJack F Vogel
116223d846dSEric Joyner /**
117223d846dSEric Joyner * i40e_aq_rc_to_posix - convert errors to user-land codes
118223d846dSEric Joyner * aq_ret: AdminQ handler error code can override aq_rc
119223d846dSEric Joyner * aq_rc: AdminQ firmware error code to convert
120223d846dSEric Joyner **/
i40e_aq_rc_to_posix(int aq_ret,int aq_rc)121223d846dSEric Joyner static INLINE int i40e_aq_rc_to_posix(int aq_ret, int aq_rc)
122223d846dSEric Joyner {
123223d846dSEric Joyner int aq_to_posix[] = {
124223d846dSEric Joyner 0, /* I40E_AQ_RC_OK */
125223d846dSEric Joyner -EPERM, /* I40E_AQ_RC_EPERM */
126223d846dSEric Joyner -ENOENT, /* I40E_AQ_RC_ENOENT */
127223d846dSEric Joyner -ESRCH, /* I40E_AQ_RC_ESRCH */
128223d846dSEric Joyner -EINTR, /* I40E_AQ_RC_EINTR */
129223d846dSEric Joyner -EIO, /* I40E_AQ_RC_EIO */
130223d846dSEric Joyner -ENXIO, /* I40E_AQ_RC_ENXIO */
131223d846dSEric Joyner -E2BIG, /* I40E_AQ_RC_E2BIG */
132223d846dSEric Joyner -EAGAIN, /* I40E_AQ_RC_EAGAIN */
133223d846dSEric Joyner -ENOMEM, /* I40E_AQ_RC_ENOMEM */
134223d846dSEric Joyner -EACCES, /* I40E_AQ_RC_EACCES */
135223d846dSEric Joyner -EFAULT, /* I40E_AQ_RC_EFAULT */
136223d846dSEric Joyner -EBUSY, /* I40E_AQ_RC_EBUSY */
137223d846dSEric Joyner -EEXIST, /* I40E_AQ_RC_EEXIST */
138223d846dSEric Joyner -EINVAL, /* I40E_AQ_RC_EINVAL */
139223d846dSEric Joyner -ENOTTY, /* I40E_AQ_RC_ENOTTY */
140223d846dSEric Joyner -ENOSPC, /* I40E_AQ_RC_ENOSPC */
141223d846dSEric Joyner -ENOSYS, /* I40E_AQ_RC_ENOSYS */
142223d846dSEric Joyner -ERANGE, /* I40E_AQ_RC_ERANGE */
143223d846dSEric Joyner -EPIPE, /* I40E_AQ_RC_EFLUSHED */
144223d846dSEric Joyner -ESPIPE, /* I40E_AQ_RC_BAD_ADDR */
145223d846dSEric Joyner -EROFS, /* I40E_AQ_RC_EMODE */
146223d846dSEric Joyner -EFBIG, /* I40E_AQ_RC_EFBIG */
147223d846dSEric Joyner };
148223d846dSEric Joyner
149223d846dSEric Joyner /* aq_rc is invalid if AQ timed out */
150223d846dSEric Joyner if (aq_ret == I40E_ERR_ADMIN_QUEUE_TIMEOUT)
151223d846dSEric Joyner return -EAGAIN;
152223d846dSEric Joyner
153223d846dSEric Joyner if (!((u32)aq_rc < (sizeof(aq_to_posix) / sizeof((aq_to_posix)[0]))))
154223d846dSEric Joyner return -ERANGE;
155223d846dSEric Joyner
156223d846dSEric Joyner return aq_to_posix[aq_rc];
157223d846dSEric Joyner }
158223d846dSEric Joyner
15961ae650dSJack F Vogel /* general information */
16061ae650dSJack F Vogel #define I40E_AQ_LARGE_BUF 512
161ceebc2f3SEric Joyner #define I40E_ASQ_CMD_TIMEOUT 250000 /* usecs */
16261ae650dSJack F Vogel
16361ae650dSJack F Vogel void i40e_fill_default_direct_cmd_desc(struct i40e_aq_desc *desc,
16461ae650dSJack F Vogel u16 opcode);
16561ae650dSJack F Vogel
16661ae650dSJack F Vogel #endif /* _I40E_ADMINQ_H_ */
167