1 /*******************************************************************************
3 Copyright (c) 2013 - 2015, Intel Corporation
6 Redistribution and use in source and binary forms, with or without
7 modification, are permitted provided that the following conditions are met:
9 1. Redistributions of source code must retain the above copyright notice,
10 this list of conditions and the following disclaimer.
12 2. Redistributions in binary form must reproduce the above copyright
13 notice, this list of conditions and the following disclaimer in the
14 documentation and/or other materials provided with the distribution.
16 3. Neither the name of the Intel Corporation nor the names of its
17 contributors may be used to endorse or promote products derived from
18 this software without specific prior written permission.
20 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23 ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
24 LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25 CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26 SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27 INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28 CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29 ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30 POSSIBILITY OF SUCH DAMAGE.
32 ***************************************************************************/
34 #ifndef _IAVF_ADMINQ_H_
35 #define _IAVF_ADMINQ_H_
37 #include "iavf_osdep.h"
38 #include "iavf_status.h"
39 #include "iavf_adminq_cmd.h"
41 #define IAVF_ADMINQ_DESC(R, i) \
42 (&(((struct iavf_aq_desc *)((R).desc_buf.va))[i]))
44 #define IAVF_ADMINQ_DESC_ALIGNMENT 4096
46 struct iavf_adminq_ring {
47 struct iavf_virt_mem dma_head; /* space for dma structures */
48 struct iavf_dma_mem desc_buf; /* descriptor ring memory */
49 struct iavf_virt_mem cmd_buf; /* command buffer memory */
52 struct iavf_dma_mem *asq_bi;
53 struct iavf_dma_mem *arq_bi;
56 u16 count; /* Number of descriptors */
57 u16 rx_buf_len; /* Admin Receive Queue buffer length */
59 /* used for interrupt processing */
63 /* used for queue tracking */
71 /* ASQ transaction details */
72 struct iavf_asq_cmd_details {
73 void *callback; /* cast from type IAVF_ADMINQ_CALLBACK */
79 struct iavf_aq_desc *wb_desc;
82 #define IAVF_ADMINQ_DETAILS(R, i) \
83 (&(((struct iavf_asq_cmd_details *)((R).cmd_buf.va))[i]))
85 /* ARQ event information */
86 struct iavf_arq_event_info {
87 struct iavf_aq_desc desc;
93 /* Admin Queue information */
94 struct iavf_adminq_info {
95 struct iavf_adminq_ring arq; /* receive queue */
96 struct iavf_adminq_ring asq; /* send queue */
97 u32 asq_cmd_timeout; /* send queue cmd write back timeout*/
98 u16 num_arq_entries; /* receive queue depth */
99 u16 num_asq_entries; /* send queue depth */
100 u16 arq_buf_size; /* receive queue buffer size */
101 u16 asq_buf_size; /* send queue buffer size */
102 u16 fw_maj_ver; /* firmware major version */
103 u16 fw_min_ver; /* firmware minor version */
104 u32 fw_build; /* firmware build number */
105 u16 api_maj_ver; /* api major version */
106 u16 api_min_ver; /* api minor version */
108 struct iavf_spinlock asq_spinlock; /* Send queue spinlock */
109 struct iavf_spinlock arq_spinlock; /* Receive queue spinlock */
111 /* last status values on send and receive queues */
112 enum iavf_admin_queue_err asq_last_status;
113 enum iavf_admin_queue_err arq_last_status;
117 * iavf_aq_rc_to_posix - convert errors to user-land codes
118 * aq_ret: AdminQ handler error code can override aq_rc
119 * aq_rc: AdminQ firmware error code to convert
121 STATIC INLINE int iavf_aq_rc_to_posix(int aq_ret, int aq_rc)
123 int aq_to_posix[] = {
124 0, /* IAVF_AQ_RC_OK */
125 -EPERM, /* IAVF_AQ_RC_EPERM */
126 -ENOENT, /* IAVF_AQ_RC_ENOENT */
127 -ESRCH, /* IAVF_AQ_RC_ESRCH */
128 -EINTR, /* IAVF_AQ_RC_EINTR */
129 -EIO, /* IAVF_AQ_RC_EIO */
130 -ENXIO, /* IAVF_AQ_RC_ENXIO */
131 -E2BIG, /* IAVF_AQ_RC_E2BIG */
132 -EAGAIN, /* IAVF_AQ_RC_EAGAIN */
133 -ENOMEM, /* IAVF_AQ_RC_ENOMEM */
134 -EACCES, /* IAVF_AQ_RC_EACCES */
135 -EFAULT, /* IAVF_AQ_RC_EFAULT */
136 -EBUSY, /* IAVF_AQ_RC_EBUSY */
137 -EEXIST, /* IAVF_AQ_RC_EEXIST */
138 -EINVAL, /* IAVF_AQ_RC_EINVAL */
139 -ENOTTY, /* IAVF_AQ_RC_ENOTTY */
140 -ENOSPC, /* IAVF_AQ_RC_ENOSPC */
141 -ENOSYS, /* IAVF_AQ_RC_ENOSYS */
142 -ERANGE, /* IAVF_AQ_RC_ERANGE */
143 -EPIPE, /* IAVF_AQ_RC_EFLUSHED */
144 -ESPIPE, /* IAVF_AQ_RC_BAD_ADDR */
145 -EROFS, /* IAVF_AQ_RC_EMODE */
146 -EFBIG, /* IAVF_AQ_RC_EFBIG */
149 /* aq_rc is invalid if AQ timed out */
150 if (aq_ret == IAVF_ERR_ADMIN_QUEUE_TIMEOUT)
153 if (!((u32)aq_rc < (sizeof(aq_to_posix) / sizeof((aq_to_posix)[0]))))
156 return aq_to_posix[aq_rc];
159 /* general information */
160 #define IAVF_AQ_LARGE_BUF 512
161 #define IAVF_ASQ_CMD_TIMEOUT 250000 /* usecs */
163 void iavf_fill_default_direct_cmd_desc(struct iavf_aq_desc *desc,
166 #endif /* _IAVF_ADMINQ_H_ */