xref: /freebsd/sys/dev/ixl/i40e_adminq.h (revision 8ef24a0d4b28fe230e20637f56869cc4148cd2ca)
1 /******************************************************************************
2 
3   Copyright (c) 2013-2015, Intel Corporation
4   All rights reserved.
5 
6   Redistribution and use in source and binary forms, with or without
7   modification, are permitted provided that the following conditions are met:
8 
9    1. Redistributions of source code must retain the above copyright notice,
10       this list of conditions and the following disclaimer.
11 
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.
15 
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.
19 
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.
31 
32 ******************************************************************************/
33 /*$FreeBSD$*/
34 
35 #ifndef _I40E_ADMINQ_H_
36 #define _I40E_ADMINQ_H_
37 
38 #include "i40e_osdep.h"
39 #include "i40e_status.h"
40 #include "i40e_adminq_cmd.h"
41 
42 #define I40E_ADMINQ_DESC(R, i)   \
43 	(&(((struct i40e_aq_desc *)((R).desc_buf.va))[i]))
44 
45 #define I40E_ADMINQ_DESC_ALIGNMENT 4096
46 
47 struct i40e_adminq_ring {
48 	struct i40e_virt_mem dma_head;	/* space for dma structures */
49 	struct i40e_dma_mem desc_buf;	/* descriptor ring memory */
50 	struct i40e_virt_mem cmd_buf;	/* command buffer memory */
51 
52 	union {
53 		struct i40e_dma_mem *asq_bi;
54 		struct i40e_dma_mem *arq_bi;
55 	} r;
56 
57 	u16 count;		/* Number of descriptors */
58 	u16 rx_buf_len;		/* Admin Receive Queue buffer length */
59 
60 	/* used for interrupt processing */
61 	u16 next_to_use;
62 	u16 next_to_clean;
63 
64 	/* used for queue tracking */
65 	u32 head;
66 	u32 tail;
67 	u32 len;
68 	u32 bah;
69 	u32 bal;
70 };
71 
72 /* ASQ transaction details */
73 struct i40e_asq_cmd_details {
74 	void *callback; /* cast from type I40E_ADMINQ_CALLBACK */
75 	u64 cookie;
76 	u16 flags_ena;
77 	u16 flags_dis;
78 	bool async;
79 	bool postpone;
80 	struct i40e_aq_desc *wb_desc;
81 };
82 
83 #define I40E_ADMINQ_DETAILS(R, i)   \
84 	(&(((struct i40e_asq_cmd_details *)((R).cmd_buf.va))[i]))
85 
86 /* ARQ event information */
87 struct i40e_arq_event_info {
88 	struct i40e_aq_desc desc;
89 	u16 msg_len;
90 	u16 buf_len;
91 	u8 *msg_buf;
92 };
93 
94 /* Admin Queue information */
95 struct i40e_adminq_info {
96 	struct i40e_adminq_ring arq;    /* receive queue */
97 	struct i40e_adminq_ring asq;    /* send queue */
98 	u32 asq_cmd_timeout;            /* send queue cmd write back timeout*/
99 	u16 num_arq_entries;            /* receive queue depth */
100 	u16 num_asq_entries;            /* send queue depth */
101 	u16 arq_buf_size;               /* receive queue buffer size */
102 	u16 asq_buf_size;               /* send queue buffer size */
103 	u16 fw_maj_ver;                 /* firmware major version */
104 	u16 fw_min_ver;                 /* firmware minor version */
105 	u32 fw_build;                   /* firmware build number */
106 	u16 api_maj_ver;                /* api major version */
107 	u16 api_min_ver;                /* api minor version */
108 	bool nvm_release_on_done;
109 
110 	struct i40e_spinlock asq_spinlock; /* Send queue spinlock */
111 	struct i40e_spinlock arq_spinlock; /* Receive queue spinlock */
112 
113 	/* last status values on send and receive queues */
114 	enum i40e_admin_queue_err asq_last_status;
115 	enum i40e_admin_queue_err arq_last_status;
116 };
117 
118 /**
119  * i40e_aq_rc_to_posix - convert errors to user-land codes
120  * aq_ret: AdminQ handler error code can override aq_rc
121  * aq_rc: AdminQ firmware error code to convert
122  **/
123 static INLINE int i40e_aq_rc_to_posix(int aq_ret, int aq_rc)
124 {
125 	int aq_to_posix[] = {
126 		0,           /* I40E_AQ_RC_OK */
127 		-EPERM,      /* I40E_AQ_RC_EPERM */
128 		-ENOENT,     /* I40E_AQ_RC_ENOENT */
129 		-ESRCH,      /* I40E_AQ_RC_ESRCH */
130 		-EINTR,      /* I40E_AQ_RC_EINTR */
131 		-EIO,        /* I40E_AQ_RC_EIO */
132 		-ENXIO,      /* I40E_AQ_RC_ENXIO */
133 		-E2BIG,      /* I40E_AQ_RC_E2BIG */
134 		-EAGAIN,     /* I40E_AQ_RC_EAGAIN */
135 		-ENOMEM,     /* I40E_AQ_RC_ENOMEM */
136 		-EACCES,     /* I40E_AQ_RC_EACCES */
137 		-EFAULT,     /* I40E_AQ_RC_EFAULT */
138 		-EBUSY,      /* I40E_AQ_RC_EBUSY */
139 		-EEXIST,     /* I40E_AQ_RC_EEXIST */
140 		-EINVAL,     /* I40E_AQ_RC_EINVAL */
141 		-ENOTTY,     /* I40E_AQ_RC_ENOTTY */
142 		-ENOSPC,     /* I40E_AQ_RC_ENOSPC */
143 		-ENOSYS,     /* I40E_AQ_RC_ENOSYS */
144 		-ERANGE,     /* I40E_AQ_RC_ERANGE */
145 		-EPIPE,      /* I40E_AQ_RC_EFLUSHED */
146 		-ESPIPE,     /* I40E_AQ_RC_BAD_ADDR */
147 		-EROFS,      /* I40E_AQ_RC_EMODE */
148 		-EFBIG,      /* I40E_AQ_RC_EFBIG */
149 	};
150 
151 	/* aq_rc is invalid if AQ timed out */
152 	if (aq_ret == I40E_ERR_ADMIN_QUEUE_TIMEOUT)
153 		return -EAGAIN;
154 
155 	if (!((u32)aq_rc < (sizeof(aq_to_posix) / sizeof((aq_to_posix)[0]))))
156 		return -ERANGE;
157 
158 	return aq_to_posix[aq_rc];
159 }
160 
161 /* general information */
162 #define I40E_AQ_LARGE_BUF	512
163 #define I40E_ASQ_CMD_TIMEOUT	250  /* msecs */
164 
165 void i40e_fill_default_direct_cmd_desc(struct i40e_aq_desc *desc,
166 				       u16 opcode);
167 
168 #endif /* _I40E_ADMINQ_H_ */
169