i40e/base: add new interfaces
[dpdk.git] / lib / librte_pmd_i40e / i40e / i40e_common.c
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
34 #include "i40e_type.h"
35 #include "i40e_adminq.h"
36 #include "i40e_prototype.h"
37 #include "i40e_virtchnl.h"
38
39 /**
40  * i40e_set_mac_type - Sets MAC type
41  * @hw: pointer to the HW structure
42  *
43  * This function sets the mac type of the adapter based on the
44  * vendor ID and device ID stored in the hw structure.
45  **/
46 #if defined(INTEGRATED_VF) || defined(VF_DRIVER)
47 enum i40e_status_code i40e_set_mac_type(struct i40e_hw *hw)
48 #else
49 STATIC enum i40e_status_code i40e_set_mac_type(struct i40e_hw *hw)
50 #endif
51 {
52         enum i40e_status_code status = I40E_SUCCESS;
53
54         DEBUGFUNC("i40e_set_mac_type\n");
55
56         if (hw->vendor_id == I40E_INTEL_VENDOR_ID) {
57                 switch (hw->device_id) {
58                 case I40E_DEV_ID_SFP_XL710:
59                 case I40E_DEV_ID_QEMU:
60                 case I40E_DEV_ID_KX_A:
61                 case I40E_DEV_ID_KX_B:
62                 case I40E_DEV_ID_KX_C:
63                 case I40E_DEV_ID_QSFP_A:
64                 case I40E_DEV_ID_QSFP_B:
65                 case I40E_DEV_ID_QSFP_C:
66                 case I40E_DEV_ID_10G_BASE_T:
67                         hw->mac.type = I40E_MAC_XL710;
68                         break;
69                 case I40E_DEV_ID_VF:
70                 case I40E_DEV_ID_VF_HV:
71                         hw->mac.type = I40E_MAC_VF;
72                         break;
73                 default:
74                         hw->mac.type = I40E_MAC_GENERIC;
75                         break;
76                 }
77         } else {
78                 status = I40E_ERR_DEVICE_NOT_SUPPORTED;
79         }
80
81         DEBUGOUT2("i40e_set_mac_type found mac: %d, returns: %d\n",
82                   hw->mac.type, status);
83         return status;
84 }
85
86 /**
87  * i40e_debug_aq
88  * @hw: debug mask related to admin queue
89  * @mask: debug mask
90  * @desc: pointer to admin queue descriptor
91  * @buffer: pointer to command buffer
92  * @buf_len: max length of buffer
93  *
94  * Dumps debug log about adminq command with descriptor contents.
95  **/
96 void i40e_debug_aq(struct i40e_hw *hw, enum i40e_debug_mask mask, void *desc,
97                    void *buffer, u16 buf_len)
98 {
99         struct i40e_aq_desc *aq_desc = (struct i40e_aq_desc *)desc;
100         u16 len = LE16_TO_CPU(aq_desc->datalen);
101         u8 *buf = (u8 *)buffer;
102         u16 i = 0;
103
104         if ((!(mask & hw->debug_mask)) || (desc == NULL))
105                 return;
106
107         i40e_debug(hw, mask,
108                    "AQ CMD: opcode 0x%04X, flags 0x%04X, datalen 0x%04X, retval 0x%04X\n",
109                    LE16_TO_CPU(aq_desc->opcode),
110                    LE16_TO_CPU(aq_desc->flags),
111                    LE16_TO_CPU(aq_desc->datalen),
112                    LE16_TO_CPU(aq_desc->retval));
113         i40e_debug(hw, mask, "\tcookie (h,l) 0x%08X 0x%08X\n",
114                    LE32_TO_CPU(aq_desc->cookie_high),
115                    LE32_TO_CPU(aq_desc->cookie_low));
116         i40e_debug(hw, mask, "\tparam (0,1)  0x%08X 0x%08X\n",
117                    LE32_TO_CPU(aq_desc->params.internal.param0),
118                    LE32_TO_CPU(aq_desc->params.internal.param1));
119         i40e_debug(hw, mask, "\taddr (h,l)   0x%08X 0x%08X\n",
120                    LE32_TO_CPU(aq_desc->params.external.addr_high),
121                    LE32_TO_CPU(aq_desc->params.external.addr_low));
122
123         if ((buffer != NULL) && (aq_desc->datalen != 0)) {
124                 i40e_debug(hw, mask, "AQ CMD Buffer:\n");
125                 if (buf_len < len)
126                         len = buf_len;
127                 /* write the full 16-byte chunks */
128                 for (i = 0; i < (len - 16); i += 16)
129                         i40e_debug(hw, mask,
130                                    "\t0x%04X  %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X\n",
131                                    i, buf[i], buf[i+1], buf[i+2], buf[i+3],
132                                    buf[i+4], buf[i+5], buf[i+6], buf[i+7],
133                                    buf[i+8], buf[i+9], buf[i+10], buf[i+11],
134                                    buf[i+12], buf[i+13], buf[i+14], buf[i+15]);
135                 /* write whatever's left over without overrunning the buffer */
136                 if (i < len) {
137                         char d_buf[80];
138                         int j = 0;
139
140                         memset(d_buf, 0, sizeof(d_buf));
141                         j += sprintf(d_buf, "\t0x%04X ", i);
142                         while (i < len)
143                                 j += sprintf(&d_buf[j], " %02X", buf[i++]);
144                         i40e_debug(hw, mask, "%s\n", d_buf);
145                 }
146         }
147 }
148
149 /**
150  * i40e_check_asq_alive
151  * @hw: pointer to the hw struct
152  *
153  * Returns true if Queue is enabled else false.
154  **/
155 bool i40e_check_asq_alive(struct i40e_hw *hw)
156 {
157         if (hw->aq.asq.len)
158                 return !!(rd32(hw, hw->aq.asq.len) & I40E_PF_ATQLEN_ATQENABLE_MASK);
159         else
160                 return false;
161 }
162
163 /**
164  * i40e_aq_queue_shutdown
165  * @hw: pointer to the hw struct
166  * @unloading: is the driver unloading itself
167  *
168  * Tell the Firmware that we're shutting down the AdminQ and whether
169  * or not the driver is unloading as well.
170  **/
171 enum i40e_status_code i40e_aq_queue_shutdown(struct i40e_hw *hw,
172                                              bool unloading)
173 {
174         struct i40e_aq_desc desc;
175         struct i40e_aqc_queue_shutdown *cmd =
176                 (struct i40e_aqc_queue_shutdown *)&desc.params.raw;
177         enum i40e_status_code status;
178
179         i40e_fill_default_direct_cmd_desc(&desc,
180                                           i40e_aqc_opc_queue_shutdown);
181
182         if (unloading)
183                 cmd->driver_unloading = CPU_TO_LE32(I40E_AQ_DRIVER_UNLOADING);
184         status = i40e_asq_send_command(hw, &desc, NULL, 0, NULL);
185
186         return status;
187 }
188
189 /* The i40e_ptype_lookup table is used to convert from the 8-bit ptype in the
190  * hardware to a bit-field that can be used by SW to more easily determine the
191  * packet type.
192  *
193  * Macros are used to shorten the table lines and make this table human
194  * readable.
195  *
196  * We store the PTYPE in the top byte of the bit field - this is just so that
197  * we can check that the table doesn't have a row missing, as the index into
198  * the table should be the PTYPE.
199  *
200  * Typical work flow:
201  *
202  * IF NOT i40e_ptype_lookup[ptype].known
203  * THEN
204  *      Packet is unknown
205  * ELSE IF i40e_ptype_lookup[ptype].outer_ip == I40E_RX_PTYPE_OUTER_IP
206  *      Use the rest of the fields to look at the tunnels, inner protocols, etc
207  * ELSE
208  *      Use the enum i40e_rx_l2_ptype to decode the packet type
209  * ENDIF
210  */
211
212 /* macro to make the table lines short */
213 #define I40E_PTT(PTYPE, OUTER_IP, OUTER_IP_VER, OUTER_FRAG, T, TE, TEF, I, PL)\
214         {       PTYPE, \
215                 1, \
216                 I40E_RX_PTYPE_OUTER_##OUTER_IP, \
217                 I40E_RX_PTYPE_OUTER_##OUTER_IP_VER, \
218                 I40E_RX_PTYPE_##OUTER_FRAG, \
219                 I40E_RX_PTYPE_TUNNEL_##T, \
220                 I40E_RX_PTYPE_TUNNEL_END_##TE, \
221                 I40E_RX_PTYPE_##TEF, \
222                 I40E_RX_PTYPE_INNER_PROT_##I, \
223                 I40E_RX_PTYPE_PAYLOAD_LAYER_##PL }
224
225 #define I40E_PTT_UNUSED_ENTRY(PTYPE) \
226                 { PTYPE, 0, 0, 0, 0, 0, 0, 0, 0, 0 }
227
228 /* shorter macros makes the table fit but are terse */
229 #define I40E_RX_PTYPE_NOF               I40E_RX_PTYPE_NOT_FRAG
230 #define I40E_RX_PTYPE_FRG               I40E_RX_PTYPE_FRAG
231 #define I40E_RX_PTYPE_INNER_PROT_TS     I40E_RX_PTYPE_INNER_PROT_TIMESYNC
232
233 /* Lookup table mapping the HW PTYPE to the bit field for decoding */
234 struct i40e_rx_ptype_decoded i40e_ptype_lookup[] = {
235         /* L2 Packet types */
236         I40E_PTT_UNUSED_ENTRY(0),
237         I40E_PTT(1,  L2, NONE, NOF, NONE, NONE, NOF, NONE, PAY2),
238         I40E_PTT(2,  L2, NONE, NOF, NONE, NONE, NOF, TS,   PAY2),
239         I40E_PTT(3,  L2, NONE, NOF, NONE, NONE, NOF, NONE, PAY2),
240         I40E_PTT_UNUSED_ENTRY(4),
241         I40E_PTT_UNUSED_ENTRY(5),
242         I40E_PTT(6,  L2, NONE, NOF, NONE, NONE, NOF, NONE, PAY2),
243         I40E_PTT(7,  L2, NONE, NOF, NONE, NONE, NOF, NONE, PAY2),
244         I40E_PTT_UNUSED_ENTRY(8),
245         I40E_PTT_UNUSED_ENTRY(9),
246         I40E_PTT(10, L2, NONE, NOF, NONE, NONE, NOF, NONE, PAY2),
247         I40E_PTT(11, L2, NONE, NOF, NONE, NONE, NOF, NONE, NONE),
248         I40E_PTT(12, L2, NONE, NOF, NONE, NONE, NOF, NONE, PAY3),
249         I40E_PTT(13, L2, NONE, NOF, NONE, NONE, NOF, NONE, PAY3),
250         I40E_PTT(14, L2, NONE, NOF, NONE, NONE, NOF, NONE, PAY3),
251         I40E_PTT(15, L2, NONE, NOF, NONE, NONE, NOF, NONE, PAY3),
252         I40E_PTT(16, L2, NONE, NOF, NONE, NONE, NOF, NONE, PAY3),
253         I40E_PTT(17, L2, NONE, NOF, NONE, NONE, NOF, NONE, PAY3),
254         I40E_PTT(18, L2, NONE, NOF, NONE, NONE, NOF, NONE, PAY3),
255         I40E_PTT(19, L2, NONE, NOF, NONE, NONE, NOF, NONE, PAY3),
256         I40E_PTT(20, L2, NONE, NOF, NONE, NONE, NOF, NONE, PAY3),
257         I40E_PTT(21, L2, NONE, NOF, NONE, NONE, NOF, NONE, PAY3),
258
259         /* Non Tunneled IPv4 */
260         I40E_PTT(22, IP, IPV4, FRG, NONE, NONE, NOF, NONE, PAY3),
261         I40E_PTT(23, IP, IPV4, NOF, NONE, NONE, NOF, NONE, PAY3),
262         I40E_PTT(24, IP, IPV4, NOF, NONE, NONE, NOF, UDP,  PAY4),
263         I40E_PTT_UNUSED_ENTRY(25),
264         I40E_PTT(26, IP, IPV4, NOF, NONE, NONE, NOF, TCP,  PAY4),
265         I40E_PTT(27, IP, IPV4, NOF, NONE, NONE, NOF, SCTP, PAY4),
266         I40E_PTT(28, IP, IPV4, NOF, NONE, NONE, NOF, ICMP, PAY4),
267
268         /* IPv4 --> IPv4 */
269         I40E_PTT(29, IP, IPV4, NOF, IP_IP, IPV4, FRG, NONE, PAY3),
270         I40E_PTT(30, IP, IPV4, NOF, IP_IP, IPV4, NOF, NONE, PAY3),
271         I40E_PTT(31, IP, IPV4, NOF, IP_IP, IPV4, NOF, UDP,  PAY4),
272         I40E_PTT_UNUSED_ENTRY(32),
273         I40E_PTT(33, IP, IPV4, NOF, IP_IP, IPV4, NOF, TCP,  PAY4),
274         I40E_PTT(34, IP, IPV4, NOF, IP_IP, IPV4, NOF, SCTP, PAY4),
275         I40E_PTT(35, IP, IPV4, NOF, IP_IP, IPV4, NOF, ICMP, PAY4),
276
277         /* IPv4 --> IPv6 */
278         I40E_PTT(36, IP, IPV4, NOF, IP_IP, IPV6, FRG, NONE, PAY3),
279         I40E_PTT(37, IP, IPV4, NOF, IP_IP, IPV6, NOF, NONE, PAY3),
280         I40E_PTT(38, IP, IPV4, NOF, IP_IP, IPV6, NOF, UDP,  PAY4),
281         I40E_PTT_UNUSED_ENTRY(39),
282         I40E_PTT(40, IP, IPV4, NOF, IP_IP, IPV6, NOF, TCP,  PAY4),
283         I40E_PTT(41, IP, IPV4, NOF, IP_IP, IPV6, NOF, SCTP, PAY4),
284         I40E_PTT(42, IP, IPV4, NOF, IP_IP, IPV6, NOF, ICMP, PAY4),
285
286         /* IPv4 --> GRE/NAT */
287         I40E_PTT(43, IP, IPV4, NOF, IP_GRENAT, NONE, NOF, NONE, PAY3),
288
289         /* IPv4 --> GRE/NAT --> IPv4 */
290         I40E_PTT(44, IP, IPV4, NOF, IP_GRENAT, IPV4, FRG, NONE, PAY3),
291         I40E_PTT(45, IP, IPV4, NOF, IP_GRENAT, IPV4, NOF, NONE, PAY3),
292         I40E_PTT(46, IP, IPV4, NOF, IP_GRENAT, IPV4, NOF, UDP,  PAY4),
293         I40E_PTT_UNUSED_ENTRY(47),
294         I40E_PTT(48, IP, IPV4, NOF, IP_GRENAT, IPV4, NOF, TCP,  PAY4),
295         I40E_PTT(49, IP, IPV4, NOF, IP_GRENAT, IPV4, NOF, SCTP, PAY4),
296         I40E_PTT(50, IP, IPV4, NOF, IP_GRENAT, IPV4, NOF, ICMP, PAY4),
297
298         /* IPv4 --> GRE/NAT --> IPv6 */
299         I40E_PTT(51, IP, IPV4, NOF, IP_GRENAT, IPV6, FRG, NONE, PAY3),
300         I40E_PTT(52, IP, IPV4, NOF, IP_GRENAT, IPV6, NOF, NONE, PAY3),
301         I40E_PTT(53, IP, IPV4, NOF, IP_GRENAT, IPV6, NOF, UDP,  PAY4),
302         I40E_PTT_UNUSED_ENTRY(54),
303         I40E_PTT(55, IP, IPV4, NOF, IP_GRENAT, IPV6, NOF, TCP,  PAY4),
304         I40E_PTT(56, IP, IPV4, NOF, IP_GRENAT, IPV6, NOF, SCTP, PAY4),
305         I40E_PTT(57, IP, IPV4, NOF, IP_GRENAT, IPV6, NOF, ICMP, PAY4),
306
307         /* IPv4 --> GRE/NAT --> MAC */
308         I40E_PTT(58, IP, IPV4, NOF, IP_GRENAT_MAC, NONE, NOF, NONE, PAY3),
309
310         /* IPv4 --> GRE/NAT --> MAC --> IPv4 */
311         I40E_PTT(59, IP, IPV4, NOF, IP_GRENAT_MAC, IPV4, FRG, NONE, PAY3),
312         I40E_PTT(60, IP, IPV4, NOF, IP_GRENAT_MAC, IPV4, NOF, NONE, PAY3),
313         I40E_PTT(61, IP, IPV4, NOF, IP_GRENAT_MAC, IPV4, NOF, UDP,  PAY4),
314         I40E_PTT_UNUSED_ENTRY(62),
315         I40E_PTT(63, IP, IPV4, NOF, IP_GRENAT_MAC, IPV4, NOF, TCP,  PAY4),
316         I40E_PTT(64, IP, IPV4, NOF, IP_GRENAT_MAC, IPV4, NOF, SCTP, PAY4),
317         I40E_PTT(65, IP, IPV4, NOF, IP_GRENAT_MAC, IPV4, NOF, ICMP, PAY4),
318
319         /* IPv4 --> GRE/NAT -> MAC --> IPv6 */
320         I40E_PTT(66, IP, IPV4, NOF, IP_GRENAT_MAC, IPV6, FRG, NONE, PAY3),
321         I40E_PTT(67, IP, IPV4, NOF, IP_GRENAT_MAC, IPV6, NOF, NONE, PAY3),
322         I40E_PTT(68, IP, IPV4, NOF, IP_GRENAT_MAC, IPV6, NOF, UDP,  PAY4),
323         I40E_PTT_UNUSED_ENTRY(69),
324         I40E_PTT(70, IP, IPV4, NOF, IP_GRENAT_MAC, IPV6, NOF, TCP,  PAY4),
325         I40E_PTT(71, IP, IPV4, NOF, IP_GRENAT_MAC, IPV6, NOF, SCTP, PAY4),
326         I40E_PTT(72, IP, IPV4, NOF, IP_GRENAT_MAC, IPV6, NOF, ICMP, PAY4),
327
328         /* IPv4 --> GRE/NAT --> MAC/VLAN */
329         I40E_PTT(73, IP, IPV4, NOF, IP_GRENAT_MAC_VLAN, NONE, NOF, NONE, PAY3),
330
331         /* IPv4 ---> GRE/NAT -> MAC/VLAN --> IPv4 */
332         I40E_PTT(74, IP, IPV4, NOF, IP_GRENAT_MAC_VLAN, IPV4, FRG, NONE, PAY3),
333         I40E_PTT(75, IP, IPV4, NOF, IP_GRENAT_MAC_VLAN, IPV4, NOF, NONE, PAY3),
334         I40E_PTT(76, IP, IPV4, NOF, IP_GRENAT_MAC_VLAN, IPV4, NOF, UDP,  PAY4),
335         I40E_PTT_UNUSED_ENTRY(77),
336         I40E_PTT(78, IP, IPV4, NOF, IP_GRENAT_MAC_VLAN, IPV4, NOF, TCP,  PAY4),
337         I40E_PTT(79, IP, IPV4, NOF, IP_GRENAT_MAC_VLAN, IPV4, NOF, SCTP, PAY4),
338         I40E_PTT(80, IP, IPV4, NOF, IP_GRENAT_MAC_VLAN, IPV4, NOF, ICMP, PAY4),
339
340         /* IPv4 -> GRE/NAT -> MAC/VLAN --> IPv6 */
341         I40E_PTT(81, IP, IPV4, NOF, IP_GRENAT_MAC_VLAN, IPV6, FRG, NONE, PAY3),
342         I40E_PTT(82, IP, IPV4, NOF, IP_GRENAT_MAC_VLAN, IPV6, NOF, NONE, PAY3),
343         I40E_PTT(83, IP, IPV4, NOF, IP_GRENAT_MAC_VLAN, IPV6, NOF, UDP,  PAY4),
344         I40E_PTT_UNUSED_ENTRY(84),
345         I40E_PTT(85, IP, IPV4, NOF, IP_GRENAT_MAC_VLAN, IPV6, NOF, TCP,  PAY4),
346         I40E_PTT(86, IP, IPV4, NOF, IP_GRENAT_MAC_VLAN, IPV6, NOF, SCTP, PAY4),
347         I40E_PTT(87, IP, IPV4, NOF, IP_GRENAT_MAC_VLAN, IPV6, NOF, ICMP, PAY4),
348
349         /* Non Tunneled IPv6 */
350         I40E_PTT(88, IP, IPV6, FRG, NONE, NONE, NOF, NONE, PAY3),
351         I40E_PTT(89, IP, IPV6, NOF, NONE, NONE, NOF, NONE, PAY3),
352         I40E_PTT(90, IP, IPV6, NOF, NONE, NONE, NOF, UDP,  PAY3),
353         I40E_PTT_UNUSED_ENTRY(91),
354         I40E_PTT(92, IP, IPV6, NOF, NONE, NONE, NOF, TCP,  PAY4),
355         I40E_PTT(93, IP, IPV6, NOF, NONE, NONE, NOF, SCTP, PAY4),
356         I40E_PTT(94, IP, IPV6, NOF, NONE, NONE, NOF, ICMP, PAY4),
357
358         /* IPv6 --> IPv4 */
359         I40E_PTT(95,  IP, IPV6, NOF, IP_IP, IPV4, FRG, NONE, PAY3),
360         I40E_PTT(96,  IP, IPV6, NOF, IP_IP, IPV4, NOF, NONE, PAY3),
361         I40E_PTT(97,  IP, IPV6, NOF, IP_IP, IPV4, NOF, UDP,  PAY4),
362         I40E_PTT_UNUSED_ENTRY(98),
363         I40E_PTT(99,  IP, IPV6, NOF, IP_IP, IPV4, NOF, TCP,  PAY4),
364         I40E_PTT(100, IP, IPV6, NOF, IP_IP, IPV4, NOF, SCTP, PAY4),
365         I40E_PTT(101, IP, IPV6, NOF, IP_IP, IPV4, NOF, ICMP, PAY4),
366
367         /* IPv6 --> IPv6 */
368         I40E_PTT(102, IP, IPV6, NOF, IP_IP, IPV6, FRG, NONE, PAY3),
369         I40E_PTT(103, IP, IPV6, NOF, IP_IP, IPV6, NOF, NONE, PAY3),
370         I40E_PTT(104, IP, IPV6, NOF, IP_IP, IPV6, NOF, UDP,  PAY4),
371         I40E_PTT_UNUSED_ENTRY(105),
372         I40E_PTT(106, IP, IPV6, NOF, IP_IP, IPV6, NOF, TCP,  PAY4),
373         I40E_PTT(107, IP, IPV6, NOF, IP_IP, IPV6, NOF, SCTP, PAY4),
374         I40E_PTT(108, IP, IPV6, NOF, IP_IP, IPV6, NOF, ICMP, PAY4),
375
376         /* IPv6 --> GRE/NAT */
377         I40E_PTT(109, IP, IPV6, NOF, IP_GRENAT, NONE, NOF, NONE, PAY3),
378
379         /* IPv6 --> GRE/NAT -> IPv4 */
380         I40E_PTT(110, IP, IPV6, NOF, IP_GRENAT, IPV4, FRG, NONE, PAY3),
381         I40E_PTT(111, IP, IPV6, NOF, IP_GRENAT, IPV4, NOF, NONE, PAY3),
382         I40E_PTT(112, IP, IPV6, NOF, IP_GRENAT, IPV4, NOF, UDP,  PAY4),
383         I40E_PTT_UNUSED_ENTRY(113),
384         I40E_PTT(114, IP, IPV6, NOF, IP_GRENAT, IPV4, NOF, TCP,  PAY4),
385         I40E_PTT(115, IP, IPV6, NOF, IP_GRENAT, IPV4, NOF, SCTP, PAY4),
386         I40E_PTT(116, IP, IPV6, NOF, IP_GRENAT, IPV4, NOF, ICMP, PAY4),
387
388         /* IPv6 --> GRE/NAT -> IPv6 */
389         I40E_PTT(117, IP, IPV6, NOF, IP_GRENAT, IPV6, FRG, NONE, PAY3),
390         I40E_PTT(118, IP, IPV6, NOF, IP_GRENAT, IPV6, NOF, NONE, PAY3),
391         I40E_PTT(119, IP, IPV6, NOF, IP_GRENAT, IPV6, NOF, UDP,  PAY4),
392         I40E_PTT_UNUSED_ENTRY(120),
393         I40E_PTT(121, IP, IPV6, NOF, IP_GRENAT, IPV6, NOF, TCP,  PAY4),
394         I40E_PTT(122, IP, IPV6, NOF, IP_GRENAT, IPV6, NOF, SCTP, PAY4),
395         I40E_PTT(123, IP, IPV6, NOF, IP_GRENAT, IPV6, NOF, ICMP, PAY4),
396
397         /* IPv6 --> GRE/NAT -> MAC */
398         I40E_PTT(124, IP, IPV6, NOF, IP_GRENAT_MAC, NONE, NOF, NONE, PAY3),
399
400         /* IPv6 --> GRE/NAT -> MAC -> IPv4 */
401         I40E_PTT(125, IP, IPV6, NOF, IP_GRENAT_MAC, IPV4, FRG, NONE, PAY3),
402         I40E_PTT(126, IP, IPV6, NOF, IP_GRENAT_MAC, IPV4, NOF, NONE, PAY3),
403         I40E_PTT(127, IP, IPV6, NOF, IP_GRENAT_MAC, IPV4, NOF, UDP,  PAY4),
404         I40E_PTT_UNUSED_ENTRY(128),
405         I40E_PTT(129, IP, IPV6, NOF, IP_GRENAT_MAC, IPV4, NOF, TCP,  PAY4),
406         I40E_PTT(130, IP, IPV6, NOF, IP_GRENAT_MAC, IPV4, NOF, SCTP, PAY4),
407         I40E_PTT(131, IP, IPV6, NOF, IP_GRENAT_MAC, IPV4, NOF, ICMP, PAY4),
408
409         /* IPv6 --> GRE/NAT -> MAC -> IPv6 */
410         I40E_PTT(132, IP, IPV6, NOF, IP_GRENAT_MAC, IPV6, FRG, NONE, PAY3),
411         I40E_PTT(133, IP, IPV6, NOF, IP_GRENAT_MAC, IPV6, NOF, NONE, PAY3),
412         I40E_PTT(134, IP, IPV6, NOF, IP_GRENAT_MAC, IPV6, NOF, UDP,  PAY4),
413         I40E_PTT_UNUSED_ENTRY(135),
414         I40E_PTT(136, IP, IPV6, NOF, IP_GRENAT_MAC, IPV6, NOF, TCP,  PAY4),
415         I40E_PTT(137, IP, IPV6, NOF, IP_GRENAT_MAC, IPV6, NOF, SCTP, PAY4),
416         I40E_PTT(138, IP, IPV6, NOF, IP_GRENAT_MAC, IPV6, NOF, ICMP, PAY4),
417
418         /* IPv6 --> GRE/NAT -> MAC/VLAN */
419         I40E_PTT(139, IP, IPV6, NOF, IP_GRENAT_MAC_VLAN, NONE, NOF, NONE, PAY3),
420
421         /* IPv6 --> GRE/NAT -> MAC/VLAN --> IPv4 */
422         I40E_PTT(140, IP, IPV6, NOF, IP_GRENAT_MAC_VLAN, IPV4, FRG, NONE, PAY3),
423         I40E_PTT(141, IP, IPV6, NOF, IP_GRENAT_MAC_VLAN, IPV4, NOF, NONE, PAY3),
424         I40E_PTT(142, IP, IPV6, NOF, IP_GRENAT_MAC_VLAN, IPV4, NOF, UDP,  PAY4),
425         I40E_PTT_UNUSED_ENTRY(143),
426         I40E_PTT(144, IP, IPV6, NOF, IP_GRENAT_MAC_VLAN, IPV4, NOF, TCP,  PAY4),
427         I40E_PTT(145, IP, IPV6, NOF, IP_GRENAT_MAC_VLAN, IPV4, NOF, SCTP, PAY4),
428         I40E_PTT(146, IP, IPV6, NOF, IP_GRENAT_MAC_VLAN, IPV4, NOF, ICMP, PAY4),
429
430         /* IPv6 --> GRE/NAT -> MAC/VLAN --> IPv6 */
431         I40E_PTT(147, IP, IPV6, NOF, IP_GRENAT_MAC_VLAN, IPV6, FRG, NONE, PAY3),
432         I40E_PTT(148, IP, IPV6, NOF, IP_GRENAT_MAC_VLAN, IPV6, NOF, NONE, PAY3),
433         I40E_PTT(149, IP, IPV6, NOF, IP_GRENAT_MAC_VLAN, IPV6, NOF, UDP,  PAY4),
434         I40E_PTT_UNUSED_ENTRY(150),
435         I40E_PTT(151, IP, IPV6, NOF, IP_GRENAT_MAC_VLAN, IPV6, NOF, TCP,  PAY4),
436         I40E_PTT(152, IP, IPV6, NOF, IP_GRENAT_MAC_VLAN, IPV6, NOF, SCTP, PAY4),
437         I40E_PTT(153, IP, IPV6, NOF, IP_GRENAT_MAC_VLAN, IPV6, NOF, ICMP, PAY4),
438
439         /* unused entries */
440         I40E_PTT_UNUSED_ENTRY(154),
441         I40E_PTT_UNUSED_ENTRY(155),
442         I40E_PTT_UNUSED_ENTRY(156),
443         I40E_PTT_UNUSED_ENTRY(157),
444         I40E_PTT_UNUSED_ENTRY(158),
445         I40E_PTT_UNUSED_ENTRY(159),
446
447         I40E_PTT_UNUSED_ENTRY(160),
448         I40E_PTT_UNUSED_ENTRY(161),
449         I40E_PTT_UNUSED_ENTRY(162),
450         I40E_PTT_UNUSED_ENTRY(163),
451         I40E_PTT_UNUSED_ENTRY(164),
452         I40E_PTT_UNUSED_ENTRY(165),
453         I40E_PTT_UNUSED_ENTRY(166),
454         I40E_PTT_UNUSED_ENTRY(167),
455         I40E_PTT_UNUSED_ENTRY(168),
456         I40E_PTT_UNUSED_ENTRY(169),
457
458         I40E_PTT_UNUSED_ENTRY(170),
459         I40E_PTT_UNUSED_ENTRY(171),
460         I40E_PTT_UNUSED_ENTRY(172),
461         I40E_PTT_UNUSED_ENTRY(173),
462         I40E_PTT_UNUSED_ENTRY(174),
463         I40E_PTT_UNUSED_ENTRY(175),
464         I40E_PTT_UNUSED_ENTRY(176),
465         I40E_PTT_UNUSED_ENTRY(177),
466         I40E_PTT_UNUSED_ENTRY(178),
467         I40E_PTT_UNUSED_ENTRY(179),
468
469         I40E_PTT_UNUSED_ENTRY(180),
470         I40E_PTT_UNUSED_ENTRY(181),
471         I40E_PTT_UNUSED_ENTRY(182),
472         I40E_PTT_UNUSED_ENTRY(183),
473         I40E_PTT_UNUSED_ENTRY(184),
474         I40E_PTT_UNUSED_ENTRY(185),
475         I40E_PTT_UNUSED_ENTRY(186),
476         I40E_PTT_UNUSED_ENTRY(187),
477         I40E_PTT_UNUSED_ENTRY(188),
478         I40E_PTT_UNUSED_ENTRY(189),
479
480         I40E_PTT_UNUSED_ENTRY(190),
481         I40E_PTT_UNUSED_ENTRY(191),
482         I40E_PTT_UNUSED_ENTRY(192),
483         I40E_PTT_UNUSED_ENTRY(193),
484         I40E_PTT_UNUSED_ENTRY(194),
485         I40E_PTT_UNUSED_ENTRY(195),
486         I40E_PTT_UNUSED_ENTRY(196),
487         I40E_PTT_UNUSED_ENTRY(197),
488         I40E_PTT_UNUSED_ENTRY(198),
489         I40E_PTT_UNUSED_ENTRY(199),
490
491         I40E_PTT_UNUSED_ENTRY(200),
492         I40E_PTT_UNUSED_ENTRY(201),
493         I40E_PTT_UNUSED_ENTRY(202),
494         I40E_PTT_UNUSED_ENTRY(203),
495         I40E_PTT_UNUSED_ENTRY(204),
496         I40E_PTT_UNUSED_ENTRY(205),
497         I40E_PTT_UNUSED_ENTRY(206),
498         I40E_PTT_UNUSED_ENTRY(207),
499         I40E_PTT_UNUSED_ENTRY(208),
500         I40E_PTT_UNUSED_ENTRY(209),
501
502         I40E_PTT_UNUSED_ENTRY(210),
503         I40E_PTT_UNUSED_ENTRY(211),
504         I40E_PTT_UNUSED_ENTRY(212),
505         I40E_PTT_UNUSED_ENTRY(213),
506         I40E_PTT_UNUSED_ENTRY(214),
507         I40E_PTT_UNUSED_ENTRY(215),
508         I40E_PTT_UNUSED_ENTRY(216),
509         I40E_PTT_UNUSED_ENTRY(217),
510         I40E_PTT_UNUSED_ENTRY(218),
511         I40E_PTT_UNUSED_ENTRY(219),
512
513         I40E_PTT_UNUSED_ENTRY(220),
514         I40E_PTT_UNUSED_ENTRY(221),
515         I40E_PTT_UNUSED_ENTRY(222),
516         I40E_PTT_UNUSED_ENTRY(223),
517         I40E_PTT_UNUSED_ENTRY(224),
518         I40E_PTT_UNUSED_ENTRY(225),
519         I40E_PTT_UNUSED_ENTRY(226),
520         I40E_PTT_UNUSED_ENTRY(227),
521         I40E_PTT_UNUSED_ENTRY(228),
522         I40E_PTT_UNUSED_ENTRY(229),
523
524         I40E_PTT_UNUSED_ENTRY(230),
525         I40E_PTT_UNUSED_ENTRY(231),
526         I40E_PTT_UNUSED_ENTRY(232),
527         I40E_PTT_UNUSED_ENTRY(233),
528         I40E_PTT_UNUSED_ENTRY(234),
529         I40E_PTT_UNUSED_ENTRY(235),
530         I40E_PTT_UNUSED_ENTRY(236),
531         I40E_PTT_UNUSED_ENTRY(237),
532         I40E_PTT_UNUSED_ENTRY(238),
533         I40E_PTT_UNUSED_ENTRY(239),
534
535         I40E_PTT_UNUSED_ENTRY(240),
536         I40E_PTT_UNUSED_ENTRY(241),
537         I40E_PTT_UNUSED_ENTRY(242),
538         I40E_PTT_UNUSED_ENTRY(243),
539         I40E_PTT_UNUSED_ENTRY(244),
540         I40E_PTT_UNUSED_ENTRY(245),
541         I40E_PTT_UNUSED_ENTRY(246),
542         I40E_PTT_UNUSED_ENTRY(247),
543         I40E_PTT_UNUSED_ENTRY(248),
544         I40E_PTT_UNUSED_ENTRY(249),
545
546         I40E_PTT_UNUSED_ENTRY(250),
547         I40E_PTT_UNUSED_ENTRY(251),
548         I40E_PTT_UNUSED_ENTRY(252),
549         I40E_PTT_UNUSED_ENTRY(253),
550         I40E_PTT_UNUSED_ENTRY(254),
551         I40E_PTT_UNUSED_ENTRY(255)
552 };
553
554
555 /**
556  * i40e_validate_mac_addr - Validate unicast MAC address
557  * @mac_addr: pointer to MAC address
558  *
559  * Tests a MAC address to ensure it is a valid Individual Address
560  **/
561 enum i40e_status_code i40e_validate_mac_addr(u8 *mac_addr)
562 {
563         enum i40e_status_code status = I40E_SUCCESS;
564
565         DEBUGFUNC("i40e_validate_mac_addr");
566
567         /* Broadcast addresses ARE multicast addresses
568          * Make sure it is not a multicast address
569          * Reject the zero address
570          */
571         if (I40E_IS_MULTICAST(mac_addr) ||
572             (mac_addr[0] == 0 && mac_addr[1] == 0 && mac_addr[2] == 0 &&
573               mac_addr[3] == 0 && mac_addr[4] == 0 && mac_addr[5] == 0))
574                 status = I40E_ERR_INVALID_MAC_ADDR;
575
576         return status;
577 }
578 #ifdef PF_DRIVER
579
580 /**
581  * i40e_init_shared_code - Initialize the shared code
582  * @hw: pointer to hardware structure
583  *
584  * This assigns the MAC type and PHY code and inits the NVM.
585  * Does not touch the hardware. This function must be called prior to any
586  * other function in the shared code. The i40e_hw structure should be
587  * memset to 0 prior to calling this function.  The following fields in
588  * hw structure should be filled in prior to calling this function:
589  * hw_addr, back, device_id, vendor_id, subsystem_device_id,
590  * subsystem_vendor_id, and revision_id
591  **/
592 enum i40e_status_code i40e_init_shared_code(struct i40e_hw *hw)
593 {
594         enum i40e_status_code status = I40E_SUCCESS;
595         u32 port, ari, func_rid;
596
597         DEBUGFUNC("i40e_init_shared_code");
598
599         i40e_set_mac_type(hw);
600
601         switch (hw->mac.type) {
602         case I40E_MAC_XL710:
603                 break;
604         default:
605                 return I40E_ERR_DEVICE_NOT_SUPPORTED;
606         }
607
608         hw->phy.get_link_info = true;
609
610         /* Determine port number and PF number*/
611         port = (rd32(hw, I40E_PFGEN_PORTNUM) & I40E_PFGEN_PORTNUM_PORT_NUM_MASK)
612                                            >> I40E_PFGEN_PORTNUM_PORT_NUM_SHIFT;
613         hw->port = (u8)port;
614         ari = (rd32(hw, I40E_GLPCI_CAPSUP) & I40E_GLPCI_CAPSUP_ARI_EN_MASK) >>
615                                                  I40E_GLPCI_CAPSUP_ARI_EN_SHIFT;
616         func_rid = rd32(hw, I40E_PF_FUNC_RID);
617         if (ari)
618                 hw->pf_id = (u8)(func_rid & 0xff);
619         else
620                 hw->pf_id = (u8)(func_rid & 0x7);
621
622         status = i40e_init_nvm(hw);
623         return status;
624 }
625
626 /**
627  * i40e_aq_mac_address_read - Retrieve the MAC addresses
628  * @hw: pointer to the hw struct
629  * @flags: a return indicator of what addresses were added to the addr store
630  * @addrs: the requestor's mac addr store
631  * @cmd_details: pointer to command details structure or NULL
632  **/
633 STATIC enum i40e_status_code i40e_aq_mac_address_read(struct i40e_hw *hw,
634                                    u16 *flags,
635                                    struct i40e_aqc_mac_address_read_data *addrs,
636                                    struct i40e_asq_cmd_details *cmd_details)
637 {
638         struct i40e_aq_desc desc;
639         struct i40e_aqc_mac_address_read *cmd_data =
640                 (struct i40e_aqc_mac_address_read *)&desc.params.raw;
641         enum i40e_status_code status;
642
643         i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_mac_address_read);
644         desc.flags |= CPU_TO_LE16(I40E_AQ_FLAG_BUF);
645
646         status = i40e_asq_send_command(hw, &desc, addrs,
647                                        sizeof(*addrs), cmd_details);
648         *flags = LE16_TO_CPU(cmd_data->command_flags);
649
650         return status;
651 }
652
653 /**
654  * i40e_aq_mac_address_write - Change the MAC addresses
655  * @hw: pointer to the hw struct
656  * @flags: indicates which MAC to be written
657  * @mac_addr: address to write
658  * @cmd_details: pointer to command details structure or NULL
659  **/
660 enum i40e_status_code i40e_aq_mac_address_write(struct i40e_hw *hw,
661                                     u16 flags, u8 *mac_addr,
662                                     struct i40e_asq_cmd_details *cmd_details)
663 {
664         struct i40e_aq_desc desc;
665         struct i40e_aqc_mac_address_write *cmd_data =
666                 (struct i40e_aqc_mac_address_write *)&desc.params.raw;
667         enum i40e_status_code status;
668
669         i40e_fill_default_direct_cmd_desc(&desc,
670                                           i40e_aqc_opc_mac_address_write);
671         cmd_data->command_flags = CPU_TO_LE16(flags);
672         cmd_data->mac_sah = CPU_TO_LE16((u16)mac_addr[0] << 8 | mac_addr[1]);
673         cmd_data->mac_sal = CPU_TO_LE32(((u32)mac_addr[2] << 24) |
674                                         ((u32)mac_addr[3] << 16) |
675                                         ((u32)mac_addr[4] << 8) |
676                                         mac_addr[5]);
677
678         status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
679
680         return status;
681 }
682
683 /**
684  * i40e_get_mac_addr - get MAC address
685  * @hw: pointer to the HW structure
686  * @mac_addr: pointer to MAC address
687  *
688  * Reads the adapter's MAC address from register
689  **/
690 enum i40e_status_code i40e_get_mac_addr(struct i40e_hw *hw, u8 *mac_addr)
691 {
692         struct i40e_aqc_mac_address_read_data addrs;
693         enum i40e_status_code status;
694         u16 flags = 0;
695
696         status = i40e_aq_mac_address_read(hw, &flags, &addrs, NULL);
697
698         if (flags & I40E_AQC_LAN_ADDR_VALID)
699                 memcpy(mac_addr, &addrs.pf_lan_mac, sizeof(addrs.pf_lan_mac));
700
701         return status;
702 }
703
704 /**
705  * i40e_get_port_mac_addr - get Port MAC address
706  * @hw: pointer to the HW structure
707  * @mac_addr: pointer to Port MAC address
708  *
709  * Reads the adapter's Port MAC address
710  **/
711 enum i40e_status_code i40e_get_port_mac_addr(struct i40e_hw *hw, u8 *mac_addr)
712 {
713         struct i40e_aqc_mac_address_read_data addrs;
714         enum i40e_status_code status;
715         u16 flags = 0;
716
717         status = i40e_aq_mac_address_read(hw, &flags, &addrs, NULL);
718         if (status)
719                 return status;
720
721         if (flags & I40E_AQC_PORT_ADDR_VALID)
722                 memcpy(mac_addr, &addrs.port_mac, sizeof(addrs.port_mac));
723         else
724                 status = I40E_ERR_INVALID_MAC_ADDR;
725
726         return status;
727 }
728
729 /**
730  * i40e_pre_tx_queue_cfg - pre tx queue configure
731  * @hw: pointer to the HW structure
732  * @queue: target pf queue index
733  * @enable: state change request
734  *
735  * Handles hw requirement to indicate intention to enable
736  * or disable target queue.
737  **/
738 void i40e_pre_tx_queue_cfg(struct i40e_hw *hw, u32 queue, bool enable)
739 {
740         u32 abs_queue_idx = hw->func_caps.base_queue + queue;
741         u32 reg_block = 0;
742         u32 reg_val;
743
744         if (abs_queue_idx >= 128) {
745                 reg_block = abs_queue_idx / 128;
746                 abs_queue_idx %= 128;
747         }
748
749         reg_val = rd32(hw, I40E_GLLAN_TXPRE_QDIS(reg_block));
750         reg_val &= ~I40E_GLLAN_TXPRE_QDIS_QINDX_MASK;
751         reg_val |= (abs_queue_idx << I40E_GLLAN_TXPRE_QDIS_QINDX_SHIFT);
752
753         if (enable)
754                 reg_val |= I40E_GLLAN_TXPRE_QDIS_CLEAR_QDIS_MASK;
755         else
756                 reg_val |= I40E_GLLAN_TXPRE_QDIS_SET_QDIS_MASK;
757
758         wr32(hw, I40E_GLLAN_TXPRE_QDIS(reg_block), reg_val);
759 }
760
761 /**
762  *  i40e_read_pba_string - Reads part number string from EEPROM
763  *  @hw: pointer to hardware structure
764  *  @pba_num: stores the part number string from the EEPROM
765  *  @pba_num_size: part number string buffer length
766  *
767  *  Reads the part number string from the EEPROM.
768  **/
769 enum i40e_status_code i40e_read_pba_string(struct i40e_hw *hw, u8 *pba_num,
770                                             u32 pba_num_size)
771 {
772         enum i40e_status_code status = I40E_SUCCESS;
773         u16 pba_word = 0;
774         u16 pba_size = 0;
775         u16 pba_ptr = 0;
776         u16 i = 0;
777
778         status = i40e_read_nvm_word(hw, I40E_SR_PBA_FLAGS, &pba_word);
779         if ((status != I40E_SUCCESS) || (pba_word != 0xFAFA)) {
780                 DEBUGOUT("Failed to read PBA flags or flag is invalid.\n");
781                 return status;
782         }
783
784         status = i40e_read_nvm_word(hw, I40E_SR_PBA_BLOCK_PTR, &pba_ptr);
785         if (status != I40E_SUCCESS) {
786                 DEBUGOUT("Failed to read PBA Block pointer.\n");
787                 return status;
788         }
789
790         status = i40e_read_nvm_word(hw, pba_ptr, &pba_size);
791         if (status != I40E_SUCCESS) {
792                 DEBUGOUT("Failed to read PBA Block size.\n");
793                 return status;
794         }
795
796         /* Subtract one to get PBA word count (PBA Size word is included in
797          * total size)
798          */
799         pba_size--;
800         if (pba_num_size < (((u32)pba_size * 2) + 1)) {
801                 DEBUGOUT("Buffer to small for PBA data.\n");
802                 return I40E_ERR_PARAM;
803         }
804
805         for (i = 0; i < pba_size; i++) {
806                 status = i40e_read_nvm_word(hw, (pba_ptr + 1) + i, &pba_word);
807                 if (status != I40E_SUCCESS) {
808                         DEBUGOUT1("Failed to read PBA Block word %d.\n", i);
809                         return status;
810                 }
811
812                 pba_num[(i * 2)] = (pba_word >> 8) & 0xFF;
813                 pba_num[(i * 2) + 1] = pba_word & 0xFF;
814         }
815         pba_num[(pba_size * 2)] = '\0';
816
817         return status;
818 }
819
820 /**
821  * i40e_get_media_type - Gets media type
822  * @hw: pointer to the hardware structure
823  **/
824 STATIC enum i40e_media_type i40e_get_media_type(struct i40e_hw *hw)
825 {
826         enum i40e_media_type media;
827
828         switch (hw->phy.link_info.phy_type) {
829         case I40E_PHY_TYPE_10GBASE_SR:
830         case I40E_PHY_TYPE_10GBASE_LR:
831         case I40E_PHY_TYPE_1000BASE_SX:
832         case I40E_PHY_TYPE_1000BASE_LX:
833         case I40E_PHY_TYPE_40GBASE_SR4:
834         case I40E_PHY_TYPE_40GBASE_LR4:
835                 media = I40E_MEDIA_TYPE_FIBER;
836                 break;
837         case I40E_PHY_TYPE_100BASE_TX:
838         case I40E_PHY_TYPE_1000BASE_T:
839         case I40E_PHY_TYPE_10GBASE_T:
840                 media = I40E_MEDIA_TYPE_BASET;
841                 break;
842         case I40E_PHY_TYPE_10GBASE_CR1_CU:
843         case I40E_PHY_TYPE_40GBASE_CR4_CU:
844         case I40E_PHY_TYPE_10GBASE_CR1:
845         case I40E_PHY_TYPE_40GBASE_CR4:
846         case I40E_PHY_TYPE_10GBASE_SFPP_CU:
847         case I40E_PHY_TYPE_40GBASE_AOC:
848         case I40E_PHY_TYPE_10GBASE_AOC:
849                 media = I40E_MEDIA_TYPE_DA;
850                 break;
851         case I40E_PHY_TYPE_1000BASE_KX:
852         case I40E_PHY_TYPE_10GBASE_KX4:
853         case I40E_PHY_TYPE_10GBASE_KR:
854         case I40E_PHY_TYPE_40GBASE_KR4:
855                 media = I40E_MEDIA_TYPE_BACKPLANE;
856                 break;
857         case I40E_PHY_TYPE_SGMII:
858         case I40E_PHY_TYPE_XAUI:
859         case I40E_PHY_TYPE_XFI:
860         case I40E_PHY_TYPE_XLAUI:
861         case I40E_PHY_TYPE_XLPPI:
862         default:
863                 media = I40E_MEDIA_TYPE_UNKNOWN;
864                 break;
865         }
866
867         return media;
868 }
869
870 #define I40E_PF_RESET_WAIT_COUNT        100
871 /**
872  * i40e_pf_reset - Reset the PF
873  * @hw: pointer to the hardware structure
874  *
875  * Assuming someone else has triggered a global reset,
876  * assure the global reset is complete and then reset the PF
877  **/
878 enum i40e_status_code i40e_pf_reset(struct i40e_hw *hw)
879 {
880         u32 cnt = 0;
881         u32 cnt1 = 0;
882         u32 reg = 0;
883         u32 grst_del;
884
885         /* Poll for Global Reset steady state in case of recent GRST.
886          * The grst delay value is in 100ms units, and we'll wait a
887          * couple counts longer to be sure we don't just miss the end.
888          */
889         grst_del = rd32(hw, I40E_GLGEN_RSTCTL) & I40E_GLGEN_RSTCTL_GRSTDEL_MASK
890                         >> I40E_GLGEN_RSTCTL_GRSTDEL_SHIFT;
891         for (cnt = 0; cnt < grst_del + 2; cnt++) {
892                 reg = rd32(hw, I40E_GLGEN_RSTAT);
893                 if (!(reg & I40E_GLGEN_RSTAT_DEVSTATE_MASK))
894                         break;
895                 i40e_msec_delay(100);
896         }
897         if (reg & I40E_GLGEN_RSTAT_DEVSTATE_MASK) {
898                 DEBUGOUT("Global reset polling failed to complete.\n");
899                 return I40E_ERR_RESET_FAILED;
900         }
901
902         /* Now Wait for the FW to be ready */
903         for (cnt1 = 0; cnt1 < I40E_PF_RESET_WAIT_COUNT; cnt1++) {
904                 reg = rd32(hw, I40E_GLNVM_ULD);
905                 reg &= (I40E_GLNVM_ULD_CONF_CORE_DONE_MASK |
906                         I40E_GLNVM_ULD_CONF_GLOBAL_DONE_MASK);
907                 if (reg == (I40E_GLNVM_ULD_CONF_CORE_DONE_MASK |
908                             I40E_GLNVM_ULD_CONF_GLOBAL_DONE_MASK)) {
909                         DEBUGOUT1("Core and Global modules ready %d\n", cnt1);
910                         break;
911                 }
912                 i40e_msec_delay(10);
913         }
914         if (!(reg & (I40E_GLNVM_ULD_CONF_CORE_DONE_MASK |
915                      I40E_GLNVM_ULD_CONF_GLOBAL_DONE_MASK))) {
916                 DEBUGOUT("wait for FW Reset complete timedout\n");
917                 DEBUGOUT1("I40E_GLNVM_ULD = 0x%x\n", reg);
918                 return I40E_ERR_RESET_FAILED;
919         }
920
921         /* If there was a Global Reset in progress when we got here,
922          * we don't need to do the PF Reset
923          */
924         if (!cnt) {
925                 reg = rd32(hw, I40E_PFGEN_CTRL);
926                 wr32(hw, I40E_PFGEN_CTRL,
927                      (reg | I40E_PFGEN_CTRL_PFSWR_MASK));
928                 for (cnt = 0; cnt < I40E_PF_RESET_WAIT_COUNT; cnt++) {
929                         reg = rd32(hw, I40E_PFGEN_CTRL);
930                         if (!(reg & I40E_PFGEN_CTRL_PFSWR_MASK))
931                                 break;
932                         i40e_msec_delay(1);
933                 }
934                 if (reg & I40E_PFGEN_CTRL_PFSWR_MASK) {
935                         DEBUGOUT("PF reset polling failed to complete.\n");
936                         return I40E_ERR_RESET_FAILED;
937                 }
938         }
939
940         i40e_clear_pxe_mode(hw);
941
942
943         return I40E_SUCCESS;
944 }
945
946 /**
947  * i40e_clear_hw - clear out any left over hw state
948  * @hw: pointer to the hw struct
949  *
950  * Clear queues and interrupts, typically called at init time,
951  * but after the capabilities have been found so we know how many
952  * queues and msix vectors have been allocated.
953  **/
954 void i40e_clear_hw(struct i40e_hw *hw)
955 {
956         u32 num_queues, base_queue;
957         u32 num_pf_int;
958         u32 num_vf_int;
959         u32 num_vfs;
960         u32 i, j;
961         u32 val;
962         u32 eol = 0x7ff;
963
964         /* get number of interrupts, queues, and vfs */
965         val = rd32(hw, I40E_GLPCI_CNF2);
966         num_pf_int = (val & I40E_GLPCI_CNF2_MSI_X_PF_N_MASK) >>
967                         I40E_GLPCI_CNF2_MSI_X_PF_N_SHIFT;
968         num_vf_int = (val & I40E_GLPCI_CNF2_MSI_X_VF_N_MASK) >>
969                         I40E_GLPCI_CNF2_MSI_X_VF_N_SHIFT;
970
971         val = rd32(hw, I40E_PFLAN_QALLOC);
972         base_queue = (val & I40E_PFLAN_QALLOC_FIRSTQ_MASK) >>
973                         I40E_PFLAN_QALLOC_FIRSTQ_SHIFT;
974         j = (val & I40E_PFLAN_QALLOC_LASTQ_MASK) >>
975                         I40E_PFLAN_QALLOC_LASTQ_SHIFT;
976         if (val & I40E_PFLAN_QALLOC_VALID_MASK)
977                 num_queues = (j - base_queue) + 1;
978         else
979                 num_queues = 0;
980
981         val = rd32(hw, I40E_PF_VT_PFALLOC);
982         i = (val & I40E_PF_VT_PFALLOC_FIRSTVF_MASK) >>
983                         I40E_PF_VT_PFALLOC_FIRSTVF_SHIFT;
984         j = (val & I40E_PF_VT_PFALLOC_LASTVF_MASK) >>
985                         I40E_PF_VT_PFALLOC_LASTVF_SHIFT;
986         if (val & I40E_PF_VT_PFALLOC_VALID_MASK)
987                 num_vfs = (j - i) + 1;
988         else
989                 num_vfs = 0;
990
991         /* stop all the interrupts */
992         wr32(hw, I40E_PFINT_ICR0_ENA, 0);
993         val = 0x3 << I40E_PFINT_DYN_CTLN_ITR_INDX_SHIFT;
994         for (i = 0; i < num_pf_int - 2; i++)
995                 wr32(hw, I40E_PFINT_DYN_CTLN(i), val);
996
997         /* Set the FIRSTQ_INDX field to 0x7FF in PFINT_LNKLSTx */
998         val = eol << I40E_PFINT_LNKLST0_FIRSTQ_INDX_SHIFT;
999         wr32(hw, I40E_PFINT_LNKLST0, val);
1000         for (i = 0; i < num_pf_int - 2; i++)
1001                 wr32(hw, I40E_PFINT_LNKLSTN(i), val);
1002         val = eol << I40E_VPINT_LNKLST0_FIRSTQ_INDX_SHIFT;
1003         for (i = 0; i < num_vfs; i++)
1004                 wr32(hw, I40E_VPINT_LNKLST0(i), val);
1005         for (i = 0; i < num_vf_int - 2; i++)
1006                 wr32(hw, I40E_VPINT_LNKLSTN(i), val);
1007
1008         /* warn the HW of the coming Tx disables */
1009         for (i = 0; i < num_queues; i++) {
1010                 u32 abs_queue_idx = base_queue + i;
1011                 u32 reg_block = 0;
1012
1013                 if (abs_queue_idx >= 128) {
1014                         reg_block = abs_queue_idx / 128;
1015                         abs_queue_idx %= 128;
1016                 }
1017
1018                 val = rd32(hw, I40E_GLLAN_TXPRE_QDIS(reg_block));
1019                 val &= ~I40E_GLLAN_TXPRE_QDIS_QINDX_MASK;
1020                 val |= (abs_queue_idx << I40E_GLLAN_TXPRE_QDIS_QINDX_SHIFT);
1021                 val |= I40E_GLLAN_TXPRE_QDIS_SET_QDIS_MASK;
1022
1023                 wr32(hw, I40E_GLLAN_TXPRE_QDIS(reg_block), val);
1024         }
1025         i40e_usec_delay(400);
1026
1027         /* stop all the queues */
1028         for (i = 0; i < num_queues; i++) {
1029                 wr32(hw, I40E_QINT_TQCTL(i), 0);
1030                 wr32(hw, I40E_QTX_ENA(i), 0);
1031                 wr32(hw, I40E_QINT_RQCTL(i), 0);
1032                 wr32(hw, I40E_QRX_ENA(i), 0);
1033         }
1034
1035         /* short wait for all queue disables to settle */
1036         i40e_usec_delay(50);
1037 }
1038
1039 /**
1040  * i40e_clear_pxe_mode - clear pxe operations mode
1041  * @hw: pointer to the hw struct
1042  *
1043  * Make sure all PXE mode settings are cleared, including things
1044  * like descriptor fetch/write-back mode.
1045  **/
1046 void i40e_clear_pxe_mode(struct i40e_hw *hw)
1047 {
1048         if (i40e_check_asq_alive(hw))
1049                 i40e_aq_clear_pxe_mode(hw, NULL);
1050 }
1051
1052 /**
1053  * i40e_led_is_mine - helper to find matching led
1054  * @hw: pointer to the hw struct
1055  * @idx: index into GPIO registers
1056  *
1057  * returns: 0 if no match, otherwise the value of the GPIO_CTL register
1058  */
1059 static u32 i40e_led_is_mine(struct i40e_hw *hw, int idx)
1060 {
1061         u32 gpio_val = 0;
1062         u32 port;
1063
1064         if (!hw->func_caps.led[idx])
1065                 return 0;
1066
1067         gpio_val = rd32(hw, I40E_GLGEN_GPIO_CTL(idx));
1068         port = (gpio_val & I40E_GLGEN_GPIO_CTL_PRT_NUM_MASK) >>
1069                 I40E_GLGEN_GPIO_CTL_PRT_NUM_SHIFT;
1070
1071         /* if PRT_NUM_NA is 1 then this LED is not port specific, OR
1072          * if it is not our port then ignore
1073          */
1074         if ((gpio_val & I40E_GLGEN_GPIO_CTL_PRT_NUM_NA_MASK) ||
1075             (port != hw->port))
1076                 return 0;
1077
1078         return gpio_val;
1079 }
1080
1081 #define I40E_COMBINED_ACTIVITY 0xA
1082 #define I40E_FILTER_ACTIVITY 0xE
1083 #define I40E_LINK_ACTIVITY 0xC
1084 #define I40E_MAC_ACTIVITY 0xD
1085 #define I40E_LED0 22
1086
1087 /**
1088  * i40e_led_get - return current on/off mode
1089  * @hw: pointer to the hw struct
1090  *
1091  * The value returned is the 'mode' field as defined in the
1092  * GPIO register definitions: 0x0 = off, 0xf = on, and other
1093  * values are variations of possible behaviors relating to
1094  * blink, link, and wire.
1095  **/
1096 u32 i40e_led_get(struct i40e_hw *hw)
1097 {
1098         u32 current_mode = 0;
1099         u32 mode = 0;
1100         int i;
1101
1102         /* as per the documentation GPIO 22-29 are the LED
1103          * GPIO pins named LED0..LED7
1104          */
1105         for (i = I40E_LED0; i <= I40E_GLGEN_GPIO_CTL_MAX_INDEX; i++) {
1106                 u32 gpio_val = i40e_led_is_mine(hw, i);
1107
1108                 if (!gpio_val)
1109                         continue;
1110
1111                 /* ignore gpio LED src mode entries related to the activity LEDs */
1112                 current_mode = ((gpio_val & I40E_GLGEN_GPIO_CTL_LED_MODE_MASK) >>
1113                         I40E_GLGEN_GPIO_CTL_LED_MODE_SHIFT);
1114                 switch (current_mode) {
1115                 case I40E_COMBINED_ACTIVITY:
1116                 case I40E_FILTER_ACTIVITY:
1117                 case I40E_MAC_ACTIVITY:
1118                         continue;
1119                 default:
1120                         break;
1121                 }
1122
1123                 mode = (gpio_val & I40E_GLGEN_GPIO_CTL_LED_MODE_MASK) >>
1124                         I40E_GLGEN_GPIO_CTL_LED_MODE_SHIFT;
1125                 break;
1126         }
1127
1128         return mode;
1129 }
1130
1131 /**
1132  * i40e_led_set - set new on/off mode
1133  * @hw: pointer to the hw struct
1134  * @mode: 0=off, 0xf=on (else see manual for mode details)
1135  * @blink: true if the LED should blink when on, false if steady
1136  *
1137  * if this function is used to turn on the blink it should
1138  * be used to disable the blink when restoring the original state.
1139  **/
1140 void i40e_led_set(struct i40e_hw *hw, u32 mode, bool blink)
1141 {
1142         u32 current_mode = 0;
1143         int i;
1144
1145         if (mode & 0xfffffff0)
1146                 DEBUGOUT1("invalid mode passed in %X\n", mode);
1147
1148         /* as per the documentation GPIO 22-29 are the LED
1149          * GPIO pins named LED0..LED7
1150          */
1151         for (i = I40E_LED0; i <= I40E_GLGEN_GPIO_CTL_MAX_INDEX; i++) {
1152                 u32 gpio_val = i40e_led_is_mine(hw, i);
1153
1154                 if (!gpio_val)
1155                         continue;
1156
1157                 /* ignore gpio LED src mode entries related to the activity LEDs */
1158                 current_mode = ((gpio_val & I40E_GLGEN_GPIO_CTL_LED_MODE_MASK) >>
1159                         I40E_GLGEN_GPIO_CTL_LED_MODE_SHIFT);
1160                 switch (current_mode) {
1161                 case I40E_COMBINED_ACTIVITY:
1162                 case I40E_FILTER_ACTIVITY:
1163                 case I40E_MAC_ACTIVITY:
1164                         continue;
1165                 default:
1166                         break;
1167                 }
1168
1169                 gpio_val &= ~I40E_GLGEN_GPIO_CTL_LED_MODE_MASK;
1170                 /* this & is a bit of paranoia, but serves as a range check */
1171                 gpio_val |= ((mode << I40E_GLGEN_GPIO_CTL_LED_MODE_SHIFT) &
1172                              I40E_GLGEN_GPIO_CTL_LED_MODE_MASK);
1173
1174                 if (mode == I40E_LINK_ACTIVITY)
1175                         blink = false;
1176
1177                 if (blink)
1178                         gpio_val |= (1 << I40E_GLGEN_GPIO_CTL_LED_BLINK_SHIFT);
1179                 else
1180                         gpio_val &= ~(1 << I40E_GLGEN_GPIO_CTL_LED_BLINK_SHIFT);
1181
1182                 wr32(hw, I40E_GLGEN_GPIO_CTL(i), gpio_val);
1183                 break;
1184         }
1185 }
1186
1187 /* Admin command wrappers */
1188
1189 /**
1190  * i40e_aq_get_phy_capabilities
1191  * @hw: pointer to the hw struct
1192  * @abilities: structure for PHY capabilities to be filled
1193  * @qualified_modules: report Qualified Modules
1194  * @report_init: report init capabilities (active are default)
1195  * @cmd_details: pointer to command details structure or NULL
1196  *
1197  * Returns the various PHY abilities supported on the Port.
1198  **/
1199 enum i40e_status_code i40e_aq_get_phy_capabilities(struct i40e_hw *hw,
1200                         bool qualified_modules, bool report_init,
1201                         struct i40e_aq_get_phy_abilities_resp *abilities,
1202                         struct i40e_asq_cmd_details *cmd_details)
1203 {
1204         struct i40e_aq_desc desc;
1205         enum i40e_status_code status;
1206         u16 abilities_size = sizeof(struct i40e_aq_get_phy_abilities_resp);
1207
1208         if (!abilities)
1209                 return I40E_ERR_PARAM;
1210
1211         i40e_fill_default_direct_cmd_desc(&desc,
1212                                           i40e_aqc_opc_get_phy_abilities);
1213
1214         desc.flags |= CPU_TO_LE16((u16)I40E_AQ_FLAG_BUF);
1215         if (abilities_size > I40E_AQ_LARGE_BUF)
1216                 desc.flags |= CPU_TO_LE16((u16)I40E_AQ_FLAG_LB);
1217
1218         if (qualified_modules)
1219                 desc.params.external.param0 |=
1220                         CPU_TO_LE32(I40E_AQ_PHY_REPORT_QUALIFIED_MODULES);
1221
1222         if (report_init)
1223                 desc.params.external.param0 |=
1224                         CPU_TO_LE32(I40E_AQ_PHY_REPORT_INITIAL_VALUES);
1225
1226         status = i40e_asq_send_command(hw, &desc, abilities, abilities_size,
1227                                     cmd_details);
1228
1229         if (hw->aq.asq_last_status == I40E_AQ_RC_EIO)
1230                 status = I40E_ERR_UNKNOWN_PHY;
1231
1232         return status;
1233 }
1234
1235 /**
1236  * i40e_aq_set_phy_config
1237  * @hw: pointer to the hw struct
1238  * @config: structure with PHY configuration to be set
1239  * @cmd_details: pointer to command details structure or NULL
1240  *
1241  * Set the various PHY configuration parameters
1242  * supported on the Port.One or more of the Set PHY config parameters may be
1243  * ignored in an MFP mode as the PF may not have the privilege to set some
1244  * of the PHY Config parameters. This status will be indicated by the
1245  * command response.
1246  **/
1247 enum i40e_status_code i40e_aq_set_phy_config(struct i40e_hw *hw,
1248                                 struct i40e_aq_set_phy_config *config,
1249                                 struct i40e_asq_cmd_details *cmd_details)
1250 {
1251         struct i40e_aq_desc desc;
1252         struct i40e_aq_set_phy_config *cmd =
1253                 (struct i40e_aq_set_phy_config *)&desc.params.raw;
1254         enum i40e_status_code status;
1255
1256         if (!config)
1257                 return I40E_ERR_PARAM;
1258
1259         i40e_fill_default_direct_cmd_desc(&desc,
1260                                           i40e_aqc_opc_set_phy_config);
1261
1262         *cmd = *config;
1263
1264         status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
1265
1266         return status;
1267 }
1268
1269 /**
1270  * i40e_set_fc
1271  * @hw: pointer to the hw struct
1272  *
1273  * Set the requested flow control mode using set_phy_config.
1274  **/
1275 enum i40e_status_code i40e_set_fc(struct i40e_hw *hw, u8 *aq_failures,
1276                                   bool atomic_restart)
1277 {
1278         enum i40e_fc_mode fc_mode = hw->fc.requested_mode;
1279         struct i40e_aq_get_phy_abilities_resp abilities;
1280         struct i40e_aq_set_phy_config config;
1281         enum i40e_status_code status;
1282         u8 pause_mask = 0x0;
1283
1284         *aq_failures = 0x0;
1285
1286         switch (fc_mode) {
1287         case I40E_FC_FULL:
1288                 pause_mask |= I40E_AQ_PHY_FLAG_PAUSE_TX;
1289                 pause_mask |= I40E_AQ_PHY_FLAG_PAUSE_RX;
1290                 break;
1291         case I40E_FC_RX_PAUSE:
1292                 pause_mask |= I40E_AQ_PHY_FLAG_PAUSE_RX;
1293                 break;
1294         case I40E_FC_TX_PAUSE:
1295                 pause_mask |= I40E_AQ_PHY_FLAG_PAUSE_TX;
1296                 break;
1297         default:
1298                 break;
1299         }
1300
1301         /* Get the current phy config */
1302         status = i40e_aq_get_phy_capabilities(hw, false, false, &abilities,
1303                                               NULL);
1304         if (status) {
1305                 *aq_failures |= I40E_SET_FC_AQ_FAIL_GET;
1306                 return status;
1307         }
1308
1309         memset(&config, 0, sizeof(struct i40e_aq_set_phy_config));
1310         /* clear the old pause settings */
1311         config.abilities = abilities.abilities & ~(I40E_AQ_PHY_FLAG_PAUSE_TX) &
1312                            ~(I40E_AQ_PHY_FLAG_PAUSE_RX);
1313         /* set the new abilities */
1314         config.abilities |= pause_mask;
1315         /* If the abilities have changed, then set the new config */
1316         if (config.abilities != abilities.abilities) {
1317                 /* Auto restart link so settings take effect */
1318                 if (atomic_restart)
1319                         config.abilities |= I40E_AQ_PHY_ENABLE_ATOMIC_LINK;
1320                 /* Copy over all the old settings */
1321                 config.phy_type = abilities.phy_type;
1322                 config.link_speed = abilities.link_speed;
1323                 config.eee_capability = abilities.eee_capability;
1324                 config.eeer = abilities.eeer_val;
1325                 config.low_power_ctrl = abilities.d3_lpan;
1326                 status = i40e_aq_set_phy_config(hw, &config, NULL);
1327
1328                 if (status)
1329                         *aq_failures |= I40E_SET_FC_AQ_FAIL_SET;
1330         }
1331         /* Update the link info */
1332         status = i40e_aq_get_link_info(hw, true, NULL, NULL);
1333         if (status) {
1334                 /* Wait a little bit (on 40G cards it sometimes takes a really
1335                  * long time for link to come back from the atomic reset)
1336                  * and try once more
1337                  */
1338                 i40e_msec_delay(1000);
1339                 status = i40e_aq_get_link_info(hw, true, NULL, NULL);
1340         }
1341         if (status)
1342                 *aq_failures |= I40E_SET_FC_AQ_FAIL_UPDATE;
1343
1344         return status;
1345 }
1346
1347 /**
1348  * i40e_aq_set_mac_config
1349  * @hw: pointer to the hw struct
1350  * @max_frame_size: Maximum Frame Size to be supported by the port
1351  * @crc_en: Tell HW to append a CRC to outgoing frames
1352  * @pacing: Pacing configurations
1353  * @cmd_details: pointer to command details structure or NULL
1354  *
1355  * Configure MAC settings for frame size, jumbo frame support and the
1356  * addition of a CRC by the hardware.
1357  **/
1358 enum i40e_status_code i40e_aq_set_mac_config(struct i40e_hw *hw,
1359                                 u16 max_frame_size,
1360                                 bool crc_en, u16 pacing,
1361                                 struct i40e_asq_cmd_details *cmd_details)
1362 {
1363         struct i40e_aq_desc desc;
1364         struct i40e_aq_set_mac_config *cmd =
1365                 (struct i40e_aq_set_mac_config *)&desc.params.raw;
1366         enum i40e_status_code status;
1367
1368         if (max_frame_size == 0)
1369                 return I40E_ERR_PARAM;
1370
1371         i40e_fill_default_direct_cmd_desc(&desc,
1372                                           i40e_aqc_opc_set_mac_config);
1373
1374         cmd->max_frame_size = CPU_TO_LE16(max_frame_size);
1375         cmd->params = ((u8)pacing & 0x0F) << 3;
1376         if (crc_en)
1377                 cmd->params |= I40E_AQ_SET_MAC_CONFIG_CRC_EN;
1378
1379         status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
1380
1381         return status;
1382 }
1383
1384 /**
1385  * i40e_aq_clear_pxe_mode
1386  * @hw: pointer to the hw struct
1387  * @cmd_details: pointer to command details structure or NULL
1388  *
1389  * Tell the firmware that the driver is taking over from PXE
1390  **/
1391 enum i40e_status_code i40e_aq_clear_pxe_mode(struct i40e_hw *hw,
1392                         struct i40e_asq_cmd_details *cmd_details)
1393 {
1394         enum i40e_status_code status;
1395         struct i40e_aq_desc desc;
1396         struct i40e_aqc_clear_pxe *cmd =
1397                 (struct i40e_aqc_clear_pxe *)&desc.params.raw;
1398
1399         i40e_fill_default_direct_cmd_desc(&desc,
1400                                           i40e_aqc_opc_clear_pxe_mode);
1401
1402         cmd->rx_cnt = 0x2;
1403
1404         status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
1405
1406         wr32(hw, I40E_GLLAN_RCTL_0, 0x1);
1407
1408         return status;
1409 }
1410
1411 /**
1412  * i40e_aq_set_link_restart_an
1413  * @hw: pointer to the hw struct
1414  * @enable_link: if true: enable link, if false: disable link
1415  * @cmd_details: pointer to command details structure or NULL
1416  *
1417  * Sets up the link and restarts the Auto-Negotiation over the link.
1418  **/
1419 enum i40e_status_code i40e_aq_set_link_restart_an(struct i40e_hw *hw,
1420                 bool enable_link, struct i40e_asq_cmd_details *cmd_details)
1421 {
1422         struct i40e_aq_desc desc;
1423         struct i40e_aqc_set_link_restart_an *cmd =
1424                 (struct i40e_aqc_set_link_restart_an *)&desc.params.raw;
1425         enum i40e_status_code status;
1426
1427         i40e_fill_default_direct_cmd_desc(&desc,
1428                                           i40e_aqc_opc_set_link_restart_an);
1429
1430         cmd->command = I40E_AQ_PHY_RESTART_AN;
1431         if (enable_link)
1432                 cmd->command |= I40E_AQ_PHY_LINK_ENABLE;
1433         else
1434                 cmd->command &= ~I40E_AQ_PHY_LINK_ENABLE;
1435
1436         status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
1437
1438         return status;
1439 }
1440
1441 /**
1442  * i40e_aq_get_link_info
1443  * @hw: pointer to the hw struct
1444  * @enable_lse: enable/disable LinkStatusEvent reporting
1445  * @link: pointer to link status structure - optional
1446  * @cmd_details: pointer to command details structure or NULL
1447  *
1448  * Returns the link status of the adapter.
1449  **/
1450 enum i40e_status_code i40e_aq_get_link_info(struct i40e_hw *hw,
1451                                 bool enable_lse, struct i40e_link_status *link,
1452                                 struct i40e_asq_cmd_details *cmd_details)
1453 {
1454         struct i40e_aq_desc desc;
1455         struct i40e_aqc_get_link_status *resp =
1456                 (struct i40e_aqc_get_link_status *)&desc.params.raw;
1457         struct i40e_link_status *hw_link_info = &hw->phy.link_info;
1458         enum i40e_status_code status;
1459         bool tx_pause, rx_pause;
1460         u16 command_flags;
1461
1462         i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_get_link_status);
1463
1464         if (enable_lse)
1465                 command_flags = I40E_AQ_LSE_ENABLE;
1466         else
1467                 command_flags = I40E_AQ_LSE_DISABLE;
1468         resp->command_flags = CPU_TO_LE16(command_flags);
1469
1470         status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
1471
1472         if (status != I40E_SUCCESS)
1473                 goto aq_get_link_info_exit;
1474
1475         /* save off old link status information */
1476         i40e_memcpy(&hw->phy.link_info_old, hw_link_info,
1477                     sizeof(struct i40e_link_status), I40E_NONDMA_TO_NONDMA);
1478
1479         /* update link status */
1480         hw_link_info->phy_type = (enum i40e_aq_phy_type)resp->phy_type;
1481         hw->phy.media_type = i40e_get_media_type(hw);
1482         hw_link_info->link_speed = (enum i40e_aq_link_speed)resp->link_speed;
1483         hw_link_info->link_info = resp->link_info;
1484         hw_link_info->an_info = resp->an_info;
1485         hw_link_info->ext_info = resp->ext_info;
1486         hw_link_info->loopback = resp->loopback;
1487         hw_link_info->max_frame_size = LE16_TO_CPU(resp->max_frame_size);
1488         hw_link_info->pacing = resp->config & I40E_AQ_CONFIG_PACING_MASK;
1489
1490         /* update fc info */
1491         tx_pause = !!(resp->an_info & I40E_AQ_LINK_PAUSE_TX);
1492         rx_pause = !!(resp->an_info & I40E_AQ_LINK_PAUSE_RX);
1493         if (tx_pause & rx_pause)
1494                 hw->fc.current_mode = I40E_FC_FULL;
1495         else if (tx_pause)
1496                 hw->fc.current_mode = I40E_FC_TX_PAUSE;
1497         else if (rx_pause)
1498                 hw->fc.current_mode = I40E_FC_RX_PAUSE;
1499         else
1500                 hw->fc.current_mode = I40E_FC_NONE;
1501
1502         if (resp->config & I40E_AQ_CONFIG_CRC_ENA)
1503                 hw_link_info->crc_enable = true;
1504         else
1505                 hw_link_info->crc_enable = false;
1506
1507         if (resp->command_flags & CPU_TO_LE16(I40E_AQ_LSE_ENABLE))
1508                 hw_link_info->lse_enable = true;
1509         else
1510                 hw_link_info->lse_enable = false;
1511
1512         if ((hw->aq.fw_maj_ver < 4 || (hw->aq.fw_maj_ver == 4 &&
1513              hw->aq.fw_min_ver < 40)) && hw_link_info->phy_type == 0xE)
1514                 hw_link_info->phy_type = I40E_PHY_TYPE_10GBASE_SFPP_CU;
1515
1516         /* save link status information */
1517         if (link)
1518                 i40e_memcpy(link, hw_link_info, sizeof(struct i40e_link_status),
1519                             I40E_NONDMA_TO_NONDMA);
1520
1521         /* flag cleared so helper functions don't call AQ again */
1522         hw->phy.get_link_info = false;
1523
1524 aq_get_link_info_exit:
1525         return status;
1526 }
1527
1528 /**
1529  * i40e_aq_set_phy_int_mask
1530  * @hw: pointer to the hw struct
1531  * @mask: interrupt mask to be set
1532  * @cmd_details: pointer to command details structure or NULL
1533  *
1534  * Set link interrupt mask.
1535  **/
1536 enum i40e_status_code i40e_aq_set_phy_int_mask(struct i40e_hw *hw,
1537                                 u16 mask,
1538                                 struct i40e_asq_cmd_details *cmd_details)
1539 {
1540         struct i40e_aq_desc desc;
1541         struct i40e_aqc_set_phy_int_mask *cmd =
1542                 (struct i40e_aqc_set_phy_int_mask *)&desc.params.raw;
1543         enum i40e_status_code status;
1544
1545         i40e_fill_default_direct_cmd_desc(&desc,
1546                                           i40e_aqc_opc_set_phy_int_mask);
1547
1548         cmd->event_mask = CPU_TO_LE16(mask);
1549
1550         status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
1551
1552         return status;
1553 }
1554
1555 /**
1556  * i40e_aq_get_local_advt_reg
1557  * @hw: pointer to the hw struct
1558  * @advt_reg: local AN advertisement register value
1559  * @cmd_details: pointer to command details structure or NULL
1560  *
1561  * Get the Local AN advertisement register value.
1562  **/
1563 enum i40e_status_code i40e_aq_get_local_advt_reg(struct i40e_hw *hw,
1564                                 u64 *advt_reg,
1565                                 struct i40e_asq_cmd_details *cmd_details)
1566 {
1567         struct i40e_aq_desc desc;
1568         struct i40e_aqc_an_advt_reg *resp =
1569                 (struct i40e_aqc_an_advt_reg *)&desc.params.raw;
1570         enum i40e_status_code status;
1571
1572         i40e_fill_default_direct_cmd_desc(&desc,
1573                                           i40e_aqc_opc_get_local_advt_reg);
1574
1575         status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
1576
1577         if (status != I40E_SUCCESS)
1578                 goto aq_get_local_advt_reg_exit;
1579
1580         *advt_reg = (u64)(LE16_TO_CPU(resp->local_an_reg1)) << 32;
1581         *advt_reg |= LE32_TO_CPU(resp->local_an_reg0);
1582
1583 aq_get_local_advt_reg_exit:
1584         return status;
1585 }
1586
1587 /**
1588  * i40e_aq_set_local_advt_reg
1589  * @hw: pointer to the hw struct
1590  * @advt_reg: local AN advertisement register value
1591  * @cmd_details: pointer to command details structure or NULL
1592  *
1593  * Get the Local AN advertisement register value.
1594  **/
1595 enum i40e_status_code i40e_aq_set_local_advt_reg(struct i40e_hw *hw,
1596                                 u64 advt_reg,
1597                                 struct i40e_asq_cmd_details *cmd_details)
1598 {
1599         struct i40e_aq_desc desc;
1600         struct i40e_aqc_an_advt_reg *cmd =
1601                 (struct i40e_aqc_an_advt_reg *)&desc.params.raw;
1602         enum i40e_status_code status;
1603
1604         i40e_fill_default_direct_cmd_desc(&desc,
1605                                           i40e_aqc_opc_get_local_advt_reg);
1606
1607         cmd->local_an_reg0 = CPU_TO_LE32(I40E_LO_DWORD(advt_reg));
1608         cmd->local_an_reg1 = CPU_TO_LE16(I40E_HI_DWORD(advt_reg));
1609
1610         status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
1611
1612         return status;
1613 }
1614
1615 /**
1616  * i40e_aq_get_partner_advt
1617  * @hw: pointer to the hw struct
1618  * @advt_reg: AN partner advertisement register value
1619  * @cmd_details: pointer to command details structure or NULL
1620  *
1621  * Get the link partner AN advertisement register value.
1622  **/
1623 enum i40e_status_code i40e_aq_get_partner_advt(struct i40e_hw *hw,
1624                                 u64 *advt_reg,
1625                                 struct i40e_asq_cmd_details *cmd_details)
1626 {
1627         struct i40e_aq_desc desc;
1628         struct i40e_aqc_an_advt_reg *resp =
1629                 (struct i40e_aqc_an_advt_reg *)&desc.params.raw;
1630         enum i40e_status_code status;
1631
1632         i40e_fill_default_direct_cmd_desc(&desc,
1633                                           i40e_aqc_opc_get_partner_advt);
1634
1635         status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
1636
1637         if (status != I40E_SUCCESS)
1638                 goto aq_get_partner_advt_exit;
1639
1640         *advt_reg = (u64)(LE16_TO_CPU(resp->local_an_reg1)) << 32;
1641         *advt_reg |= LE32_TO_CPU(resp->local_an_reg0);
1642
1643 aq_get_partner_advt_exit:
1644         return status;
1645 }
1646
1647 /**
1648  * i40e_aq_set_lb_modes
1649  * @hw: pointer to the hw struct
1650  * @lb_modes: loopback mode to be set
1651  * @cmd_details: pointer to command details structure or NULL
1652  *
1653  * Sets loopback modes.
1654  **/
1655 enum i40e_status_code i40e_aq_set_lb_modes(struct i40e_hw *hw,
1656                                 u16 lb_modes,
1657                                 struct i40e_asq_cmd_details *cmd_details)
1658 {
1659         struct i40e_aq_desc desc;
1660         struct i40e_aqc_set_lb_mode *cmd =
1661                 (struct i40e_aqc_set_lb_mode *)&desc.params.raw;
1662         enum i40e_status_code status;
1663
1664         i40e_fill_default_direct_cmd_desc(&desc,
1665                                           i40e_aqc_opc_set_lb_modes);
1666
1667         cmd->lb_mode = CPU_TO_LE16(lb_modes);
1668
1669         status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
1670
1671         return status;
1672 }
1673
1674 /**
1675  * i40e_aq_set_phy_debug
1676  * @hw: pointer to the hw struct
1677  * @cmd_flags: debug command flags
1678  * @cmd_details: pointer to command details structure or NULL
1679  *
1680  * Reset the external PHY.
1681  **/
1682 enum i40e_status_code i40e_aq_set_phy_debug(struct i40e_hw *hw, u8 cmd_flags,
1683                                 struct i40e_asq_cmd_details *cmd_details)
1684 {
1685         struct i40e_aq_desc desc;
1686         struct i40e_aqc_set_phy_debug *cmd =
1687                 (struct i40e_aqc_set_phy_debug *)&desc.params.raw;
1688         enum i40e_status_code status;
1689
1690         i40e_fill_default_direct_cmd_desc(&desc,
1691                                           i40e_aqc_opc_set_phy_debug);
1692
1693         cmd->command_flags = cmd_flags;
1694
1695         status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
1696
1697         return status;
1698 }
1699
1700 /**
1701  * i40e_aq_add_vsi
1702  * @hw: pointer to the hw struct
1703  * @vsi_ctx: pointer to a vsi context struct
1704  * @cmd_details: pointer to command details structure or NULL
1705  *
1706  * Add a VSI context to the hardware.
1707 **/
1708 enum i40e_status_code i40e_aq_add_vsi(struct i40e_hw *hw,
1709                                 struct i40e_vsi_context *vsi_ctx,
1710                                 struct i40e_asq_cmd_details *cmd_details)
1711 {
1712         struct i40e_aq_desc desc;
1713         struct i40e_aqc_add_get_update_vsi *cmd =
1714                 (struct i40e_aqc_add_get_update_vsi *)&desc.params.raw;
1715         struct i40e_aqc_add_get_update_vsi_completion *resp =
1716                 (struct i40e_aqc_add_get_update_vsi_completion *)
1717                 &desc.params.raw;
1718         enum i40e_status_code status;
1719
1720         i40e_fill_default_direct_cmd_desc(&desc,
1721                                           i40e_aqc_opc_add_vsi);
1722
1723         cmd->uplink_seid = CPU_TO_LE16(vsi_ctx->uplink_seid);
1724         cmd->connection_type = vsi_ctx->connection_type;
1725         cmd->vf_id = vsi_ctx->vf_num;
1726         cmd->vsi_flags = CPU_TO_LE16(vsi_ctx->flags);
1727
1728         desc.flags |= CPU_TO_LE16((u16)(I40E_AQ_FLAG_BUF | I40E_AQ_FLAG_RD));
1729
1730         status = i40e_asq_send_command(hw, &desc, &vsi_ctx->info,
1731                                     sizeof(vsi_ctx->info), cmd_details);
1732
1733         if (status != I40E_SUCCESS)
1734                 goto aq_add_vsi_exit;
1735
1736         vsi_ctx->seid = LE16_TO_CPU(resp->seid);
1737         vsi_ctx->vsi_number = LE16_TO_CPU(resp->vsi_number);
1738         vsi_ctx->vsis_allocated = LE16_TO_CPU(resp->vsi_used);
1739         vsi_ctx->vsis_unallocated = LE16_TO_CPU(resp->vsi_free);
1740
1741 aq_add_vsi_exit:
1742         return status;
1743 }
1744
1745 /**
1746  * i40e_aq_set_default_vsi
1747  * @hw: pointer to the hw struct
1748  * @seid: vsi number
1749  * @cmd_details: pointer to command details structure or NULL
1750  **/
1751 enum i40e_status_code i40e_aq_set_default_vsi(struct i40e_hw *hw,
1752                                 u16 seid,
1753                                 struct i40e_asq_cmd_details *cmd_details)
1754 {
1755         struct i40e_aq_desc desc;
1756         struct i40e_aqc_set_vsi_promiscuous_modes *cmd =
1757                 (struct i40e_aqc_set_vsi_promiscuous_modes *)
1758                 &desc.params.raw;
1759         enum i40e_status_code status;
1760
1761         i40e_fill_default_direct_cmd_desc(&desc,
1762                                         i40e_aqc_opc_set_vsi_promiscuous_modes);
1763
1764         cmd->promiscuous_flags = CPU_TO_LE16(I40E_AQC_SET_VSI_DEFAULT);
1765         cmd->valid_flags = CPU_TO_LE16(I40E_AQC_SET_VSI_DEFAULT);
1766         cmd->seid = CPU_TO_LE16(seid);
1767
1768         status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
1769
1770         return status;
1771 }
1772
1773 /**
1774  * i40e_aq_set_vsi_unicast_promiscuous
1775  * @hw: pointer to the hw struct
1776  * @seid: vsi number
1777  * @set: set unicast promiscuous enable/disable
1778  * @cmd_details: pointer to command details structure or NULL
1779  **/
1780 enum i40e_status_code i40e_aq_set_vsi_unicast_promiscuous(struct i40e_hw *hw,
1781                                 u16 seid, bool set,
1782                                 struct i40e_asq_cmd_details *cmd_details)
1783 {
1784         struct i40e_aq_desc desc;
1785         struct i40e_aqc_set_vsi_promiscuous_modes *cmd =
1786                 (struct i40e_aqc_set_vsi_promiscuous_modes *)&desc.params.raw;
1787         enum i40e_status_code status;
1788         u16 flags = 0;
1789
1790         i40e_fill_default_direct_cmd_desc(&desc,
1791                                         i40e_aqc_opc_set_vsi_promiscuous_modes);
1792
1793         if (set)
1794                 flags |= I40E_AQC_SET_VSI_PROMISC_UNICAST;
1795
1796         cmd->promiscuous_flags = CPU_TO_LE16(flags);
1797
1798         cmd->valid_flags = CPU_TO_LE16(I40E_AQC_SET_VSI_PROMISC_UNICAST);
1799
1800         cmd->seid = CPU_TO_LE16(seid);
1801         status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
1802
1803         return status;
1804 }
1805
1806 /**
1807  * i40e_aq_set_vsi_multicast_promiscuous
1808  * @hw: pointer to the hw struct
1809  * @seid: vsi number
1810  * @set: set multicast promiscuous enable/disable
1811  * @cmd_details: pointer to command details structure or NULL
1812  **/
1813 enum i40e_status_code i40e_aq_set_vsi_multicast_promiscuous(struct i40e_hw *hw,
1814                                 u16 seid, bool set, struct i40e_asq_cmd_details *cmd_details)
1815 {
1816         struct i40e_aq_desc desc;
1817         struct i40e_aqc_set_vsi_promiscuous_modes *cmd =
1818                 (struct i40e_aqc_set_vsi_promiscuous_modes *)&desc.params.raw;
1819         enum i40e_status_code status;
1820         u16 flags = 0;
1821
1822         i40e_fill_default_direct_cmd_desc(&desc,
1823                                         i40e_aqc_opc_set_vsi_promiscuous_modes);
1824
1825         if (set)
1826                 flags |= I40E_AQC_SET_VSI_PROMISC_MULTICAST;
1827
1828         cmd->promiscuous_flags = CPU_TO_LE16(flags);
1829
1830         cmd->valid_flags = CPU_TO_LE16(I40E_AQC_SET_VSI_PROMISC_MULTICAST);
1831
1832         cmd->seid = CPU_TO_LE16(seid);
1833         status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
1834
1835         return status;
1836 }
1837
1838 /**
1839  * i40e_aq_set_vsi_broadcast
1840  * @hw: pointer to the hw struct
1841  * @seid: vsi number
1842  * @set_filter: true to set filter, false to clear filter
1843  * @cmd_details: pointer to command details structure or NULL
1844  *
1845  * Set or clear the broadcast promiscuous flag (filter) for a given VSI.
1846  **/
1847 enum i40e_status_code i40e_aq_set_vsi_broadcast(struct i40e_hw *hw,
1848                                 u16 seid, bool set_filter,
1849                                 struct i40e_asq_cmd_details *cmd_details)
1850 {
1851         struct i40e_aq_desc desc;
1852         struct i40e_aqc_set_vsi_promiscuous_modes *cmd =
1853                 (struct i40e_aqc_set_vsi_promiscuous_modes *)&desc.params.raw;
1854         enum i40e_status_code status;
1855
1856         i40e_fill_default_direct_cmd_desc(&desc,
1857                                         i40e_aqc_opc_set_vsi_promiscuous_modes);
1858
1859         if (set_filter)
1860                 cmd->promiscuous_flags
1861                             |= CPU_TO_LE16(I40E_AQC_SET_VSI_PROMISC_BROADCAST);
1862         else
1863                 cmd->promiscuous_flags
1864                             &= CPU_TO_LE16(~I40E_AQC_SET_VSI_PROMISC_BROADCAST);
1865
1866         cmd->valid_flags = CPU_TO_LE16(I40E_AQC_SET_VSI_PROMISC_BROADCAST);
1867         cmd->seid = CPU_TO_LE16(seid);
1868         status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
1869
1870         return status;
1871 }
1872
1873 /**
1874  * i40e_get_vsi_params - get VSI configuration info
1875  * @hw: pointer to the hw struct
1876  * @vsi_ctx: pointer to a vsi context struct
1877  * @cmd_details: pointer to command details structure or NULL
1878  **/
1879 enum i40e_status_code i40e_aq_get_vsi_params(struct i40e_hw *hw,
1880                                 struct i40e_vsi_context *vsi_ctx,
1881                                 struct i40e_asq_cmd_details *cmd_details)
1882 {
1883         struct i40e_aq_desc desc;
1884         struct i40e_aqc_add_get_update_vsi *cmd =
1885                 (struct i40e_aqc_add_get_update_vsi *)&desc.params.raw;
1886         struct i40e_aqc_add_get_update_vsi_completion *resp =
1887                 (struct i40e_aqc_add_get_update_vsi_completion *)
1888                 &desc.params.raw;
1889         enum i40e_status_code status;
1890
1891         UNREFERENCED_1PARAMETER(cmd_details);
1892         i40e_fill_default_direct_cmd_desc(&desc,
1893                                           i40e_aqc_opc_get_vsi_parameters);
1894
1895         cmd->uplink_seid = CPU_TO_LE16(vsi_ctx->seid);
1896
1897         desc.flags |= CPU_TO_LE16((u16)I40E_AQ_FLAG_BUF);
1898
1899         status = i40e_asq_send_command(hw, &desc, &vsi_ctx->info,
1900                                     sizeof(vsi_ctx->info), NULL);
1901
1902         if (status != I40E_SUCCESS)
1903                 goto aq_get_vsi_params_exit;
1904
1905         vsi_ctx->seid = LE16_TO_CPU(resp->seid);
1906         vsi_ctx->vsi_number = LE16_TO_CPU(resp->vsi_number);
1907         vsi_ctx->vsis_allocated = LE16_TO_CPU(resp->vsi_used);
1908         vsi_ctx->vsis_unallocated = LE16_TO_CPU(resp->vsi_free);
1909
1910 aq_get_vsi_params_exit:
1911         return status;
1912 }
1913
1914 /**
1915  * i40e_aq_update_vsi_params
1916  * @hw: pointer to the hw struct
1917  * @vsi_ctx: pointer to a vsi context struct
1918  * @cmd_details: pointer to command details structure or NULL
1919  *
1920  * Update a VSI context.
1921  **/
1922 enum i40e_status_code i40e_aq_update_vsi_params(struct i40e_hw *hw,
1923                                 struct i40e_vsi_context *vsi_ctx,
1924                                 struct i40e_asq_cmd_details *cmd_details)
1925 {
1926         struct i40e_aq_desc desc;
1927         struct i40e_aqc_add_get_update_vsi *cmd =
1928                 (struct i40e_aqc_add_get_update_vsi *)&desc.params.raw;
1929         enum i40e_status_code status;
1930
1931         i40e_fill_default_direct_cmd_desc(&desc,
1932                                           i40e_aqc_opc_update_vsi_parameters);
1933         cmd->uplink_seid = CPU_TO_LE16(vsi_ctx->seid);
1934
1935         desc.flags |= CPU_TO_LE16((u16)(I40E_AQ_FLAG_BUF | I40E_AQ_FLAG_RD));
1936
1937         status = i40e_asq_send_command(hw, &desc, &vsi_ctx->info,
1938                                     sizeof(vsi_ctx->info), cmd_details);
1939
1940         return status;
1941 }
1942
1943 /**
1944  * i40e_aq_get_switch_config
1945  * @hw: pointer to the hardware structure
1946  * @buf: pointer to the result buffer
1947  * @buf_size: length of input buffer
1948  * @start_seid: seid to start for the report, 0 == beginning
1949  * @cmd_details: pointer to command details structure or NULL
1950  *
1951  * Fill the buf with switch configuration returned from AdminQ command
1952  **/
1953 enum i40e_status_code i40e_aq_get_switch_config(struct i40e_hw *hw,
1954                                 struct i40e_aqc_get_switch_config_resp *buf,
1955                                 u16 buf_size, u16 *start_seid,
1956                                 struct i40e_asq_cmd_details *cmd_details)
1957 {
1958         struct i40e_aq_desc desc;
1959         struct i40e_aqc_switch_seid *scfg =
1960                 (struct i40e_aqc_switch_seid *)&desc.params.raw;
1961         enum i40e_status_code status;
1962
1963         i40e_fill_default_direct_cmd_desc(&desc,
1964                                           i40e_aqc_opc_get_switch_config);
1965         desc.flags |= CPU_TO_LE16((u16)I40E_AQ_FLAG_BUF);
1966         if (buf_size > I40E_AQ_LARGE_BUF)
1967                 desc.flags |= CPU_TO_LE16((u16)I40E_AQ_FLAG_LB);
1968         scfg->seid = CPU_TO_LE16(*start_seid);
1969
1970         status = i40e_asq_send_command(hw, &desc, buf, buf_size, cmd_details);
1971         *start_seid = LE16_TO_CPU(scfg->seid);
1972
1973         return status;
1974 }
1975
1976 /**
1977  * i40e_aq_get_firmware_version
1978  * @hw: pointer to the hw struct
1979  * @fw_major_version: firmware major version
1980  * @fw_minor_version: firmware minor version
1981  * @fw_build: firmware build number
1982  * @api_major_version: major queue version
1983  * @api_minor_version: minor queue version
1984  * @cmd_details: pointer to command details structure or NULL
1985  *
1986  * Get the firmware version from the admin queue commands
1987  **/
1988 enum i40e_status_code i40e_aq_get_firmware_version(struct i40e_hw *hw,
1989                                 u16 *fw_major_version, u16 *fw_minor_version,
1990                                 u32 *fw_build,
1991                                 u16 *api_major_version, u16 *api_minor_version,
1992                                 struct i40e_asq_cmd_details *cmd_details)
1993 {
1994         struct i40e_aq_desc desc;
1995         struct i40e_aqc_get_version *resp =
1996                 (struct i40e_aqc_get_version *)&desc.params.raw;
1997         enum i40e_status_code status;
1998
1999         i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_get_version);
2000
2001         status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
2002
2003         if (status == I40E_SUCCESS) {
2004                 if (fw_major_version != NULL)
2005                         *fw_major_version = LE16_TO_CPU(resp->fw_major);
2006                 if (fw_minor_version != NULL)
2007                         *fw_minor_version = LE16_TO_CPU(resp->fw_minor);
2008                 if (fw_build != NULL)
2009                         *fw_build = LE32_TO_CPU(resp->fw_build);
2010                 if (api_major_version != NULL)
2011                         *api_major_version = LE16_TO_CPU(resp->api_major);
2012                 if (api_minor_version != NULL)
2013                         *api_minor_version = LE16_TO_CPU(resp->api_minor);
2014
2015                 /* A workaround to fix the API version in SW */
2016                 if (api_major_version && api_minor_version &&
2017                     fw_major_version && fw_minor_version &&
2018                     ((*api_major_version == 1) && (*api_minor_version == 1)) &&
2019                     (((*fw_major_version == 4) && (*fw_minor_version >= 2)) ||
2020                      (*fw_major_version > 4)))
2021                         *api_minor_version = 2;
2022         }
2023
2024         return status;
2025 }
2026
2027 /**
2028  * i40e_aq_send_driver_version
2029  * @hw: pointer to the hw struct
2030  * @dv: driver's major, minor version
2031  * @cmd_details: pointer to command details structure or NULL
2032  *
2033  * Send the driver version to the firmware
2034  **/
2035 enum i40e_status_code i40e_aq_send_driver_version(struct i40e_hw *hw,
2036                                 struct i40e_driver_version *dv,
2037                                 struct i40e_asq_cmd_details *cmd_details)
2038 {
2039         struct i40e_aq_desc desc;
2040         struct i40e_aqc_driver_version *cmd =
2041                 (struct i40e_aqc_driver_version *)&desc.params.raw;
2042         enum i40e_status_code status;
2043         u16 len;
2044
2045         if (dv == NULL)
2046                 return I40E_ERR_PARAM;
2047
2048         i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_driver_version);
2049
2050         desc.flags |= CPU_TO_LE16(I40E_AQ_FLAG_BUF | I40E_AQ_FLAG_RD);
2051         cmd->driver_major_ver = dv->major_version;
2052         cmd->driver_minor_ver = dv->minor_version;
2053         cmd->driver_build_ver = dv->build_version;
2054         cmd->driver_subbuild_ver = dv->subbuild_version;
2055
2056         len = 0;
2057         while (len < sizeof(dv->driver_string) &&
2058                (dv->driver_string[len] < 0x80) &&
2059                dv->driver_string[len])
2060                 len++;
2061         status = i40e_asq_send_command(hw, &desc, dv->driver_string,
2062                                        len, cmd_details);
2063
2064         return status;
2065 }
2066
2067 /**
2068  * i40e_get_link_status - get status of the HW network link
2069  * @hw: pointer to the hw struct
2070  *
2071  * Returns true if link is up, false if link is down.
2072  *
2073  * Side effect: LinkStatusEvent reporting becomes enabled
2074  **/
2075 bool i40e_get_link_status(struct i40e_hw *hw)
2076 {
2077         enum i40e_status_code status = I40E_SUCCESS;
2078         bool link_status = false;
2079
2080         if (hw->phy.get_link_info) {
2081                 status = i40e_aq_get_link_info(hw, true, NULL, NULL);
2082
2083                 if (status != I40E_SUCCESS)
2084                         goto i40e_get_link_status_exit;
2085         }
2086
2087         link_status = hw->phy.link_info.link_info & I40E_AQ_LINK_UP;
2088
2089 i40e_get_link_status_exit:
2090         return link_status;
2091 }
2092
2093 /**
2094  * i40e_get_link_speed
2095  * @hw: pointer to the hw struct
2096  *
2097  * Returns the link speed of the adapter.
2098  **/
2099 enum i40e_aq_link_speed i40e_get_link_speed(struct i40e_hw *hw)
2100 {
2101         enum i40e_aq_link_speed speed = I40E_LINK_SPEED_UNKNOWN;
2102         enum i40e_status_code status = I40E_SUCCESS;
2103
2104         if (hw->phy.get_link_info) {
2105                 status = i40e_aq_get_link_info(hw, true, NULL, NULL);
2106
2107                 if (status != I40E_SUCCESS)
2108                         goto i40e_link_speed_exit;
2109         }
2110
2111         speed = hw->phy.link_info.link_speed;
2112
2113 i40e_link_speed_exit:
2114         return speed;
2115 }
2116
2117 /**
2118  * i40e_aq_add_veb - Insert a VEB between the VSI and the MAC
2119  * @hw: pointer to the hw struct
2120  * @uplink_seid: the MAC or other gizmo SEID
2121  * @downlink_seid: the VSI SEID
2122  * @enabled_tc: bitmap of TCs to be enabled
2123  * @default_port: true for default port VSI, false for control port
2124  * @enable_l2_filtering: true to add L2 filter table rules to regular forwarding rules for cloud support
2125  * @veb_seid: pointer to where to put the resulting VEB SEID
2126  * @cmd_details: pointer to command details structure or NULL
2127  *
2128  * This asks the FW to add a VEB between the uplink and downlink
2129  * elements.  If the uplink SEID is 0, this will be a floating VEB.
2130  **/
2131 enum i40e_status_code i40e_aq_add_veb(struct i40e_hw *hw, u16 uplink_seid,
2132                                 u16 downlink_seid, u8 enabled_tc,
2133                                 bool default_port, bool enable_l2_filtering,
2134                                 u16 *veb_seid,
2135                                 struct i40e_asq_cmd_details *cmd_details)
2136 {
2137         struct i40e_aq_desc desc;
2138         struct i40e_aqc_add_veb *cmd =
2139                 (struct i40e_aqc_add_veb *)&desc.params.raw;
2140         struct i40e_aqc_add_veb_completion *resp =
2141                 (struct i40e_aqc_add_veb_completion *)&desc.params.raw;
2142         enum i40e_status_code status;
2143         u16 veb_flags = 0;
2144
2145         /* SEIDs need to either both be set or both be 0 for floating VEB */
2146         if (!!uplink_seid != !!downlink_seid)
2147                 return I40E_ERR_PARAM;
2148
2149         i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_add_veb);
2150
2151         cmd->uplink_seid = CPU_TO_LE16(uplink_seid);
2152         cmd->downlink_seid = CPU_TO_LE16(downlink_seid);
2153         cmd->enable_tcs = enabled_tc;
2154         if (!uplink_seid)
2155                 veb_flags |= I40E_AQC_ADD_VEB_FLOATING;
2156         if (default_port)
2157                 veb_flags |= I40E_AQC_ADD_VEB_PORT_TYPE_DEFAULT;
2158         else
2159                 veb_flags |= I40E_AQC_ADD_VEB_PORT_TYPE_DATA;
2160
2161         if (enable_l2_filtering)
2162                 veb_flags |= I40E_AQC_ADD_VEB_ENABLE_L2_FILTER;
2163
2164         cmd->veb_flags = CPU_TO_LE16(veb_flags);
2165
2166         status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
2167
2168         if (!status && veb_seid)
2169                 *veb_seid = LE16_TO_CPU(resp->veb_seid);
2170
2171         return status;
2172 }
2173
2174 /**
2175  * i40e_aq_get_veb_parameters - Retrieve VEB parameters
2176  * @hw: pointer to the hw struct
2177  * @veb_seid: the SEID of the VEB to query
2178  * @switch_id: the uplink switch id
2179  * @floating: set to true if the VEB is floating
2180  * @statistic_index: index of the stats counter block for this VEB
2181  * @vebs_used: number of VEB's used by function
2182  * @vebs_free: total VEB's not reserved by any function
2183  * @cmd_details: pointer to command details structure or NULL
2184  *
2185  * This retrieves the parameters for a particular VEB, specified by
2186  * uplink_seid, and returns them to the caller.
2187  **/
2188 enum i40e_status_code i40e_aq_get_veb_parameters(struct i40e_hw *hw,
2189                                 u16 veb_seid, u16 *switch_id,
2190                                 bool *floating, u16 *statistic_index,
2191                                 u16 *vebs_used, u16 *vebs_free,
2192                                 struct i40e_asq_cmd_details *cmd_details)
2193 {
2194         struct i40e_aq_desc desc;
2195         struct i40e_aqc_get_veb_parameters_completion *cmd_resp =
2196                 (struct i40e_aqc_get_veb_parameters_completion *)
2197                 &desc.params.raw;
2198         enum i40e_status_code status;
2199
2200         if (veb_seid == 0)
2201                 return I40E_ERR_PARAM;
2202
2203         i40e_fill_default_direct_cmd_desc(&desc,
2204                                           i40e_aqc_opc_get_veb_parameters);
2205         cmd_resp->seid = CPU_TO_LE16(veb_seid);
2206
2207         status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
2208         if (status)
2209                 goto get_veb_exit;
2210
2211         if (switch_id)
2212                 *switch_id = LE16_TO_CPU(cmd_resp->switch_id);
2213         if (statistic_index)
2214                 *statistic_index = LE16_TO_CPU(cmd_resp->statistic_index);
2215         if (vebs_used)
2216                 *vebs_used = LE16_TO_CPU(cmd_resp->vebs_used);
2217         if (vebs_free)
2218                 *vebs_free = LE16_TO_CPU(cmd_resp->vebs_free);
2219         if (floating) {
2220                 u16 flags = LE16_TO_CPU(cmd_resp->veb_flags);
2221                 if (flags & I40E_AQC_ADD_VEB_FLOATING)
2222                         *floating = true;
2223                 else
2224                         *floating = false;
2225         }
2226
2227 get_veb_exit:
2228         return status;
2229 }
2230
2231 /**
2232  * i40e_aq_add_macvlan
2233  * @hw: pointer to the hw struct
2234  * @seid: VSI for the mac address
2235  * @mv_list: list of macvlans to be added
2236  * @count: length of the list
2237  * @cmd_details: pointer to command details structure or NULL
2238  *
2239  * Add MAC/VLAN addresses to the HW filtering
2240  **/
2241 enum i40e_status_code i40e_aq_add_macvlan(struct i40e_hw *hw, u16 seid,
2242                         struct i40e_aqc_add_macvlan_element_data *mv_list,
2243                         u16 count, struct i40e_asq_cmd_details *cmd_details)
2244 {
2245         struct i40e_aq_desc desc;
2246         struct i40e_aqc_macvlan *cmd =
2247                 (struct i40e_aqc_macvlan *)&desc.params.raw;
2248         enum i40e_status_code status;
2249         u16 buf_size;
2250
2251         if (count == 0 || !mv_list || !hw)
2252                 return I40E_ERR_PARAM;
2253
2254         buf_size = count * sizeof(struct i40e_aqc_add_macvlan_element_data);
2255
2256         /* prep the rest of the request */
2257         i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_add_macvlan);
2258         cmd->num_addresses = CPU_TO_LE16(count);
2259         cmd->seid[0] = CPU_TO_LE16(I40E_AQC_MACVLAN_CMD_SEID_VALID | seid);
2260         cmd->seid[1] = 0;
2261         cmd->seid[2] = 0;
2262
2263         desc.flags |= CPU_TO_LE16((u16)(I40E_AQ_FLAG_BUF | I40E_AQ_FLAG_RD));
2264         if (buf_size > I40E_AQ_LARGE_BUF)
2265                 desc.flags |= CPU_TO_LE16((u16)I40E_AQ_FLAG_LB);
2266
2267         status = i40e_asq_send_command(hw, &desc, mv_list, buf_size,
2268                                     cmd_details);
2269
2270         return status;
2271 }
2272
2273 /**
2274  * i40e_aq_remove_macvlan
2275  * @hw: pointer to the hw struct
2276  * @seid: VSI for the mac address
2277  * @mv_list: list of macvlans to be removed
2278  * @count: length of the list
2279  * @cmd_details: pointer to command details structure or NULL
2280  *
2281  * Remove MAC/VLAN addresses from the HW filtering
2282  **/
2283 enum i40e_status_code i40e_aq_remove_macvlan(struct i40e_hw *hw, u16 seid,
2284                         struct i40e_aqc_remove_macvlan_element_data *mv_list,
2285                         u16 count, struct i40e_asq_cmd_details *cmd_details)
2286 {
2287         struct i40e_aq_desc desc;
2288         struct i40e_aqc_macvlan *cmd =
2289                 (struct i40e_aqc_macvlan *)&desc.params.raw;
2290         enum i40e_status_code status;
2291         u16 buf_size;
2292
2293         if (count == 0 || !mv_list || !hw)
2294                 return I40E_ERR_PARAM;
2295
2296         buf_size = count * sizeof(struct i40e_aqc_remove_macvlan_element_data);
2297
2298         /* prep the rest of the request */
2299         i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_remove_macvlan);
2300         cmd->num_addresses = CPU_TO_LE16(count);
2301         cmd->seid[0] = CPU_TO_LE16(I40E_AQC_MACVLAN_CMD_SEID_VALID | seid);
2302         cmd->seid[1] = 0;
2303         cmd->seid[2] = 0;
2304
2305         desc.flags |= CPU_TO_LE16((u16)(I40E_AQ_FLAG_BUF | I40E_AQ_FLAG_RD));
2306         if (buf_size > I40E_AQ_LARGE_BUF)
2307                 desc.flags |= CPU_TO_LE16((u16)I40E_AQ_FLAG_LB);
2308
2309         status = i40e_asq_send_command(hw, &desc, mv_list, buf_size,
2310                                        cmd_details);
2311
2312         return status;
2313 }
2314
2315 /**
2316  * i40e_aq_add_vlan - Add VLAN ids to the HW filtering
2317  * @hw: pointer to the hw struct
2318  * @seid: VSI for the vlan filters
2319  * @v_list: list of vlan filters to be added
2320  * @count: length of the list
2321  * @cmd_details: pointer to command details structure or NULL
2322  **/
2323 enum i40e_status_code i40e_aq_add_vlan(struct i40e_hw *hw, u16 seid,
2324                         struct i40e_aqc_add_remove_vlan_element_data *v_list,
2325                         u8 count, struct i40e_asq_cmd_details *cmd_details)
2326 {
2327         struct i40e_aq_desc desc;
2328         struct i40e_aqc_macvlan *cmd =
2329                 (struct i40e_aqc_macvlan *)&desc.params.raw;
2330         enum i40e_status_code status;
2331         u16 buf_size;
2332
2333         if (count == 0 || !v_list || !hw)
2334                 return I40E_ERR_PARAM;
2335
2336         buf_size = count * sizeof(struct i40e_aqc_add_remove_vlan_element_data);
2337
2338         /* prep the rest of the request */
2339         i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_add_vlan);
2340         cmd->num_addresses = CPU_TO_LE16(count);
2341         cmd->seid[0] = CPU_TO_LE16(seid | I40E_AQC_MACVLAN_CMD_SEID_VALID);
2342         cmd->seid[1] = 0;
2343         cmd->seid[2] = 0;
2344
2345         desc.flags |= CPU_TO_LE16((u16)(I40E_AQ_FLAG_BUF | I40E_AQ_FLAG_RD));
2346         if (buf_size > I40E_AQ_LARGE_BUF)
2347                 desc.flags |= CPU_TO_LE16((u16)I40E_AQ_FLAG_LB);
2348
2349         status = i40e_asq_send_command(hw, &desc, v_list, buf_size,
2350                                        cmd_details);
2351
2352         return status;
2353 }
2354
2355 /**
2356  * i40e_aq_remove_vlan - Remove VLANs from the HW filtering
2357  * @hw: pointer to the hw struct
2358  * @seid: VSI for the vlan filters
2359  * @v_list: list of macvlans to be removed
2360  * @count: length of the list
2361  * @cmd_details: pointer to command details structure or NULL
2362  **/
2363 enum i40e_status_code i40e_aq_remove_vlan(struct i40e_hw *hw, u16 seid,
2364                         struct i40e_aqc_add_remove_vlan_element_data *v_list,
2365                         u8 count, struct i40e_asq_cmd_details *cmd_details)
2366 {
2367         struct i40e_aq_desc desc;
2368         struct i40e_aqc_macvlan *cmd =
2369                 (struct i40e_aqc_macvlan *)&desc.params.raw;
2370         enum i40e_status_code status;
2371         u16 buf_size;
2372
2373         if (count == 0 || !v_list || !hw)
2374                 return I40E_ERR_PARAM;
2375
2376         buf_size = count * sizeof(struct i40e_aqc_add_remove_vlan_element_data);
2377
2378         /* prep the rest of the request */
2379         i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_remove_vlan);
2380         cmd->num_addresses = CPU_TO_LE16(count);
2381         cmd->seid[0] = CPU_TO_LE16(seid | I40E_AQC_MACVLAN_CMD_SEID_VALID);
2382         cmd->seid[1] = 0;
2383         cmd->seid[2] = 0;
2384
2385         desc.flags |= CPU_TO_LE16((u16)(I40E_AQ_FLAG_BUF | I40E_AQ_FLAG_RD));
2386         if (buf_size > I40E_AQ_LARGE_BUF)
2387                 desc.flags |= CPU_TO_LE16((u16)I40E_AQ_FLAG_LB);
2388
2389         status = i40e_asq_send_command(hw, &desc, v_list, buf_size,
2390                                        cmd_details);
2391
2392         return status;
2393 }
2394
2395 /**
2396  * i40e_aq_send_msg_to_vf
2397  * @hw: pointer to the hardware structure
2398  * @vfid: vf id to send msg
2399  * @v_opcode: opcodes for VF-PF communication
2400  * @v_retval: return error code
2401  * @msg: pointer to the msg buffer
2402  * @msglen: msg length
2403  * @cmd_details: pointer to command details
2404  *
2405  * send msg to vf
2406  **/
2407 enum i40e_status_code i40e_aq_send_msg_to_vf(struct i40e_hw *hw, u16 vfid,
2408                                 u32 v_opcode, u32 v_retval, u8 *msg, u16 msglen,
2409                                 struct i40e_asq_cmd_details *cmd_details)
2410 {
2411         struct i40e_aq_desc desc;
2412         struct i40e_aqc_pf_vf_message *cmd =
2413                 (struct i40e_aqc_pf_vf_message *)&desc.params.raw;
2414         enum i40e_status_code status;
2415
2416         i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_send_msg_to_vf);
2417         cmd->id = CPU_TO_LE32(vfid);
2418         desc.cookie_high = CPU_TO_LE32(v_opcode);
2419         desc.cookie_low = CPU_TO_LE32(v_retval);
2420         desc.flags |= CPU_TO_LE16((u16)I40E_AQ_FLAG_SI);
2421         if (msglen) {
2422                 desc.flags |= CPU_TO_LE16((u16)(I40E_AQ_FLAG_BUF |
2423                                                 I40E_AQ_FLAG_RD));
2424                 if (msglen > I40E_AQ_LARGE_BUF)
2425                         desc.flags |= CPU_TO_LE16((u16)I40E_AQ_FLAG_LB);
2426                 desc.datalen = CPU_TO_LE16(msglen);
2427         }
2428         status = i40e_asq_send_command(hw, &desc, msg, msglen, cmd_details);
2429
2430         return status;
2431 }
2432
2433 /**
2434  * i40e_aq_debug_read_register
2435  * @hw: pointer to the hw struct
2436  * @reg_addr: register address
2437  * @reg_val: register value
2438  * @cmd_details: pointer to command details structure or NULL
2439  *
2440  * Read the register using the admin queue commands
2441  **/
2442 enum i40e_status_code i40e_aq_debug_read_register(struct i40e_hw *hw,
2443                                 u32 reg_addr, u64 *reg_val,
2444                                 struct i40e_asq_cmd_details *cmd_details)
2445 {
2446         struct i40e_aq_desc desc;
2447         struct i40e_aqc_debug_reg_read_write *cmd_resp =
2448                 (struct i40e_aqc_debug_reg_read_write *)&desc.params.raw;
2449         enum i40e_status_code status;
2450
2451         if (reg_val == NULL)
2452                 return I40E_ERR_PARAM;
2453
2454         i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_debug_read_reg);
2455
2456         cmd_resp->address = CPU_TO_LE32(reg_addr);
2457
2458         status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
2459
2460         if (status == I40E_SUCCESS) {
2461                 *reg_val = ((u64)LE32_TO_CPU(cmd_resp->value_high) << 32) |
2462                            (u64)LE32_TO_CPU(cmd_resp->value_low);
2463         }
2464
2465         return status;
2466 }
2467
2468 /**
2469  * i40e_aq_debug_write_register
2470  * @hw: pointer to the hw struct
2471  * @reg_addr: register address
2472  * @reg_val: register value
2473  * @cmd_details: pointer to command details structure or NULL
2474  *
2475  * Write to a register using the admin queue commands
2476  **/
2477 enum i40e_status_code i40e_aq_debug_write_register(struct i40e_hw *hw,
2478                                 u32 reg_addr, u64 reg_val,
2479                                 struct i40e_asq_cmd_details *cmd_details)
2480 {
2481         struct i40e_aq_desc desc;
2482         struct i40e_aqc_debug_reg_read_write *cmd =
2483                 (struct i40e_aqc_debug_reg_read_write *)&desc.params.raw;
2484         enum i40e_status_code status;
2485
2486         i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_debug_write_reg);
2487
2488         cmd->address = CPU_TO_LE32(reg_addr);
2489         cmd->value_high = CPU_TO_LE32((u32)(reg_val >> 32));
2490         cmd->value_low = CPU_TO_LE32((u32)(reg_val & 0xFFFFFFFF));
2491
2492         status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
2493
2494         return status;
2495 }
2496
2497 /**
2498  * i40e_aq_get_hmc_resource_profile
2499  * @hw: pointer to the hw struct
2500  * @profile: type of profile the HMC is to be set as
2501  * @pe_vf_enabled_count: the number of PE enabled VFs the system has
2502  * @cmd_details: pointer to command details structure or NULL
2503  *
2504  * query the HMC profile of the device.
2505  **/
2506 enum i40e_status_code i40e_aq_get_hmc_resource_profile(struct i40e_hw *hw,
2507                                 enum i40e_aq_hmc_profile *profile,
2508                                 u8 *pe_vf_enabled_count,
2509                                 struct i40e_asq_cmd_details *cmd_details)
2510 {
2511         struct i40e_aq_desc desc;
2512         struct i40e_aq_get_set_hmc_resource_profile *resp =
2513                 (struct i40e_aq_get_set_hmc_resource_profile *)&desc.params.raw;
2514         enum i40e_status_code status;
2515
2516         i40e_fill_default_direct_cmd_desc(&desc,
2517                                 i40e_aqc_opc_query_hmc_resource_profile);
2518         status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
2519
2520         *profile = (enum i40e_aq_hmc_profile)(resp->pm_profile &
2521                    I40E_AQ_GET_HMC_RESOURCE_PROFILE_PM_MASK);
2522         *pe_vf_enabled_count = resp->pe_vf_enabled &
2523                                I40E_AQ_GET_HMC_RESOURCE_PROFILE_COUNT_MASK;
2524
2525         return status;
2526 }
2527
2528 /**
2529  * i40e_aq_set_hmc_resource_profile
2530  * @hw: pointer to the hw struct
2531  * @profile: type of profile the HMC is to be set as
2532  * @pe_vf_enabled_count: the number of PE enabled VFs the system has
2533  * @cmd_details: pointer to command details structure or NULL
2534  *
2535  * set the HMC profile of the device.
2536  **/
2537 enum i40e_status_code i40e_aq_set_hmc_resource_profile(struct i40e_hw *hw,
2538                                 enum i40e_aq_hmc_profile profile,
2539                                 u8 pe_vf_enabled_count,
2540                                 struct i40e_asq_cmd_details *cmd_details)
2541 {
2542         struct i40e_aq_desc desc;
2543         struct i40e_aq_get_set_hmc_resource_profile *cmd =
2544                 (struct i40e_aq_get_set_hmc_resource_profile *)&desc.params.raw;
2545         enum i40e_status_code status;
2546
2547         i40e_fill_default_direct_cmd_desc(&desc,
2548                                         i40e_aqc_opc_set_hmc_resource_profile);
2549
2550         cmd->pm_profile = (u8)profile;
2551         cmd->pe_vf_enabled = pe_vf_enabled_count;
2552
2553         status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
2554
2555         return status;
2556 }
2557
2558 /**
2559  * i40e_aq_request_resource
2560  * @hw: pointer to the hw struct
2561  * @resource: resource id
2562  * @access: access type
2563  * @sdp_number: resource number
2564  * @timeout: the maximum time in ms that the driver may hold the resource
2565  * @cmd_details: pointer to command details structure or NULL
2566  *
2567  * requests common resource using the admin queue commands
2568  **/
2569 enum i40e_status_code i40e_aq_request_resource(struct i40e_hw *hw,
2570                                 enum i40e_aq_resources_ids resource,
2571                                 enum i40e_aq_resource_access_type access,
2572                                 u8 sdp_number, u64 *timeout,
2573                                 struct i40e_asq_cmd_details *cmd_details)
2574 {
2575         struct i40e_aq_desc desc;
2576         struct i40e_aqc_request_resource *cmd_resp =
2577                 (struct i40e_aqc_request_resource *)&desc.params.raw;
2578         enum i40e_status_code status;
2579
2580         DEBUGFUNC("i40e_aq_request_resource");
2581
2582         i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_request_resource);
2583
2584         cmd_resp->resource_id = CPU_TO_LE16(resource);
2585         cmd_resp->access_type = CPU_TO_LE16(access);
2586         cmd_resp->resource_number = CPU_TO_LE32(sdp_number);
2587
2588         status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
2589         /* The completion specifies the maximum time in ms that the driver
2590          * may hold the resource in the Timeout field.
2591          * If the resource is held by someone else, the command completes with
2592          * busy return value and the timeout field indicates the maximum time
2593          * the current owner of the resource has to free it.
2594          */
2595         if (status == I40E_SUCCESS || hw->aq.asq_last_status == I40E_AQ_RC_EBUSY)
2596                 *timeout = LE32_TO_CPU(cmd_resp->timeout);
2597
2598         return status;
2599 }
2600
2601 /**
2602  * i40e_aq_release_resource
2603  * @hw: pointer to the hw struct
2604  * @resource: resource id
2605  * @sdp_number: resource number
2606  * @cmd_details: pointer to command details structure or NULL
2607  *
2608  * release common resource using the admin queue commands
2609  **/
2610 enum i40e_status_code i40e_aq_release_resource(struct i40e_hw *hw,
2611                                 enum i40e_aq_resources_ids resource,
2612                                 u8 sdp_number,
2613                                 struct i40e_asq_cmd_details *cmd_details)
2614 {
2615         struct i40e_aq_desc desc;
2616         struct i40e_aqc_request_resource *cmd =
2617                 (struct i40e_aqc_request_resource *)&desc.params.raw;
2618         enum i40e_status_code status;
2619
2620         DEBUGFUNC("i40e_aq_release_resource");
2621
2622         i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_release_resource);
2623
2624         cmd->resource_id = CPU_TO_LE16(resource);
2625         cmd->resource_number = CPU_TO_LE32(sdp_number);
2626
2627         status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
2628
2629         return status;
2630 }
2631
2632 /**
2633  * i40e_aq_read_nvm
2634  * @hw: pointer to the hw struct
2635  * @module_pointer: module pointer location in words from the NVM beginning
2636  * @offset: byte offset from the module beginning
2637  * @length: length of the section to be read (in bytes from the offset)
2638  * @data: command buffer (size [bytes] = length)
2639  * @last_command: tells if this is the last command in a series
2640  * @cmd_details: pointer to command details structure or NULL
2641  *
2642  * Read the NVM using the admin queue commands
2643  **/
2644 enum i40e_status_code i40e_aq_read_nvm(struct i40e_hw *hw, u8 module_pointer,
2645                                 u32 offset, u16 length, void *data,
2646                                 bool last_command,
2647                                 struct i40e_asq_cmd_details *cmd_details)
2648 {
2649         struct i40e_aq_desc desc;
2650         struct i40e_aqc_nvm_update *cmd =
2651                 (struct i40e_aqc_nvm_update *)&desc.params.raw;
2652         enum i40e_status_code status;
2653
2654         DEBUGFUNC("i40e_aq_read_nvm");
2655
2656         /* In offset the highest byte must be zeroed. */
2657         if (offset & 0xFF000000) {
2658                 status = I40E_ERR_PARAM;
2659                 goto i40e_aq_read_nvm_exit;
2660         }
2661
2662         i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_nvm_read);
2663
2664         /* If this is the last command in a series, set the proper flag. */
2665         if (last_command)
2666                 cmd->command_flags |= I40E_AQ_NVM_LAST_CMD;
2667         cmd->module_pointer = module_pointer;
2668         cmd->offset = CPU_TO_LE32(offset);
2669         cmd->length = CPU_TO_LE16(length);
2670
2671         desc.flags |= CPU_TO_LE16((u16)I40E_AQ_FLAG_BUF);
2672         if (length > I40E_AQ_LARGE_BUF)
2673                 desc.flags |= CPU_TO_LE16((u16)I40E_AQ_FLAG_LB);
2674
2675         status = i40e_asq_send_command(hw, &desc, data, length, cmd_details);
2676
2677 i40e_aq_read_nvm_exit:
2678         return status;
2679 }
2680
2681 /**
2682  * i40e_aq_read_nvm_config - read an nvm config block
2683  * @hw: pointer to the hw struct
2684  * @cmd_flags: NVM access admin command bits
2685  * @field_id: field or feature id
2686  * @data: buffer for result
2687  * @buf_size: buffer size
2688  * @element_count: pointer to count of elements read by FW
2689  * @cmd_details: pointer to command details structure or NULL
2690  **/
2691 enum i40e_status_code i40e_aq_read_nvm_config(struct i40e_hw *hw,
2692                                 u8 cmd_flags, u32 field_id, void *data,
2693                                 u16 buf_size, u16 *element_count,
2694                                 struct i40e_asq_cmd_details *cmd_details)
2695 {
2696         struct i40e_aq_desc desc;
2697         struct i40e_aqc_nvm_config_read *cmd =
2698                 (struct i40e_aqc_nvm_config_read *)&desc.params.raw;
2699         enum i40e_status_code status;
2700
2701         i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_nvm_config_read);
2702         desc.flags |= CPU_TO_LE16((u16)(I40E_AQ_FLAG_BUF));
2703         if (buf_size > I40E_AQ_LARGE_BUF)
2704                 desc.flags |= CPU_TO_LE16((u16)I40E_AQ_FLAG_LB);
2705
2706         cmd->cmd_flags = CPU_TO_LE16(cmd_flags);
2707         cmd->element_id = CPU_TO_LE16((u16)(0xffff & field_id));
2708         if (cmd_flags & I40E_AQ_ANVM_FEATURE_OR_IMMEDIATE_MASK)
2709                 cmd->element_id_msw = CPU_TO_LE16((u16)(field_id >> 16));
2710         else
2711                 cmd->element_id_msw = 0;
2712
2713         status = i40e_asq_send_command(hw, &desc, data, buf_size, cmd_details);
2714
2715         if (!status && element_count)
2716                 *element_count = LE16_TO_CPU(cmd->element_count);
2717
2718         return status;
2719 }
2720
2721 /**
2722  * i40e_aq_write_nvm_config - write an nvm config block
2723  * @hw: pointer to the hw struct
2724  * @cmd_flags: NVM access admin command bits
2725  * @data: buffer for result
2726  * @buf_size: buffer size
2727  * @element_count: count of elements to be written
2728  * @cmd_details: pointer to command details structure or NULL
2729  **/
2730 enum i40e_status_code i40e_aq_write_nvm_config(struct i40e_hw *hw,
2731                                 u8 cmd_flags, void *data, u16 buf_size,
2732                                 u16 element_count,
2733                                 struct i40e_asq_cmd_details *cmd_details)
2734 {
2735         struct i40e_aq_desc desc;
2736         struct i40e_aqc_nvm_config_write *cmd =
2737                 (struct i40e_aqc_nvm_config_write *)&desc.params.raw;
2738         enum i40e_status_code status;
2739
2740         i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_nvm_config_write);
2741         desc.flags |= CPU_TO_LE16((u16)(I40E_AQ_FLAG_BUF | I40E_AQ_FLAG_RD));
2742         if (buf_size > I40E_AQ_LARGE_BUF)
2743                 desc.flags |= CPU_TO_LE16((u16)I40E_AQ_FLAG_LB);
2744
2745         cmd->element_count = CPU_TO_LE16(element_count);
2746         cmd->cmd_flags = CPU_TO_LE16(cmd_flags);
2747         status = i40e_asq_send_command(hw, &desc, data, buf_size, cmd_details);
2748
2749         return status;
2750 }
2751
2752 /**
2753  * i40e_aq_erase_nvm
2754  * @hw: pointer to the hw struct
2755  * @module_pointer: module pointer location in words from the NVM beginning
2756  * @offset: offset in the module (expressed in 4 KB from module's beginning)
2757  * @length: length of the section to be erased (expressed in 4 KB)
2758  * @last_command: tells if this is the last command in a series
2759  * @cmd_details: pointer to command details structure or NULL
2760  *
2761  * Erase the NVM sector using the admin queue commands
2762  **/
2763 enum i40e_status_code i40e_aq_erase_nvm(struct i40e_hw *hw, u8 module_pointer,
2764                                 u32 offset, u16 length, bool last_command,
2765                                 struct i40e_asq_cmd_details *cmd_details)
2766 {
2767         struct i40e_aq_desc desc;
2768         struct i40e_aqc_nvm_update *cmd =
2769                 (struct i40e_aqc_nvm_update *)&desc.params.raw;
2770         enum i40e_status_code status;
2771
2772         DEBUGFUNC("i40e_aq_erase_nvm");
2773
2774         /* In offset the highest byte must be zeroed. */
2775         if (offset & 0xFF000000) {
2776                 status = I40E_ERR_PARAM;
2777                 goto i40e_aq_erase_nvm_exit;
2778         }
2779
2780         i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_nvm_erase);
2781
2782         /* If this is the last command in a series, set the proper flag. */
2783         if (last_command)
2784                 cmd->command_flags |= I40E_AQ_NVM_LAST_CMD;
2785         cmd->module_pointer = module_pointer;
2786         cmd->offset = CPU_TO_LE32(offset);
2787         cmd->length = CPU_TO_LE16(length);
2788
2789         status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
2790
2791 i40e_aq_erase_nvm_exit:
2792         return status;
2793 }
2794
2795 #define I40E_DEV_FUNC_CAP_SWITCH_MODE   0x01
2796 #define I40E_DEV_FUNC_CAP_MGMT_MODE     0x02
2797 #define I40E_DEV_FUNC_CAP_NPAR          0x03
2798 #define I40E_DEV_FUNC_CAP_OS2BMC        0x04
2799 #define I40E_DEV_FUNC_CAP_VALID_FUNC    0x05
2800 #define I40E_DEV_FUNC_CAP_SRIOV_1_1     0x12
2801 #define I40E_DEV_FUNC_CAP_VF            0x13
2802 #define I40E_DEV_FUNC_CAP_VMDQ          0x14
2803 #define I40E_DEV_FUNC_CAP_802_1_QBG     0x15
2804 #define I40E_DEV_FUNC_CAP_802_1_QBH     0x16
2805 #define I40E_DEV_FUNC_CAP_VSI           0x17
2806 #define I40E_DEV_FUNC_CAP_DCB           0x18
2807 #define I40E_DEV_FUNC_CAP_FCOE          0x21
2808 #define I40E_DEV_FUNC_CAP_ISCSI         0x22
2809 #define I40E_DEV_FUNC_CAP_RSS           0x40
2810 #define I40E_DEV_FUNC_CAP_RX_QUEUES     0x41
2811 #define I40E_DEV_FUNC_CAP_TX_QUEUES     0x42
2812 #define I40E_DEV_FUNC_CAP_MSIX          0x43
2813 #define I40E_DEV_FUNC_CAP_MSIX_VF       0x44
2814 #define I40E_DEV_FUNC_CAP_FLOW_DIRECTOR 0x45
2815 #define I40E_DEV_FUNC_CAP_IEEE_1588     0x46
2816 #define I40E_DEV_FUNC_CAP_MFP_MODE_1    0xF1
2817 #define I40E_DEV_FUNC_CAP_CEM           0xF2
2818 #define I40E_DEV_FUNC_CAP_IWARP         0x51
2819 #define I40E_DEV_FUNC_CAP_LED           0x61
2820 #define I40E_DEV_FUNC_CAP_SDP           0x62
2821 #define I40E_DEV_FUNC_CAP_MDIO          0x63
2822
2823 /**
2824  * i40e_parse_discover_capabilities
2825  * @hw: pointer to the hw struct
2826  * @buff: pointer to a buffer containing device/function capability records
2827  * @cap_count: number of capability records in the list
2828  * @list_type_opc: type of capabilities list to parse
2829  *
2830  * Parse the device/function capabilities list.
2831  **/
2832 STATIC void i40e_parse_discover_capabilities(struct i40e_hw *hw, void *buff,
2833                                      u32 cap_count,
2834                                      enum i40e_admin_queue_opc list_type_opc)
2835 {
2836         struct i40e_aqc_list_capabilities_element_resp *cap;
2837         u32 valid_functions, num_functions;
2838         u32 number, logical_id, phys_id;
2839         struct i40e_hw_capabilities *p;
2840         u32 i = 0;
2841         u16 id;
2842
2843         cap = (struct i40e_aqc_list_capabilities_element_resp *) buff;
2844
2845         if (list_type_opc == i40e_aqc_opc_list_dev_capabilities)
2846                 p = (struct i40e_hw_capabilities *)&hw->dev_caps;
2847         else if (list_type_opc == i40e_aqc_opc_list_func_capabilities)
2848                 p = (struct i40e_hw_capabilities *)&hw->func_caps;
2849         else
2850                 return;
2851
2852         for (i = 0; i < cap_count; i++, cap++) {
2853                 id = LE16_TO_CPU(cap->id);
2854                 number = LE32_TO_CPU(cap->number);
2855                 logical_id = LE32_TO_CPU(cap->logical_id);
2856                 phys_id = LE32_TO_CPU(cap->phys_id);
2857
2858                 switch (id) {
2859                 case I40E_DEV_FUNC_CAP_SWITCH_MODE:
2860                         p->switch_mode = number;
2861                         break;
2862                 case I40E_DEV_FUNC_CAP_MGMT_MODE:
2863                         p->management_mode = number;
2864                         break;
2865                 case I40E_DEV_FUNC_CAP_NPAR:
2866                         p->npar_enable = number;
2867                         break;
2868                 case I40E_DEV_FUNC_CAP_OS2BMC:
2869                         p->os2bmc = number;
2870                         break;
2871                 case I40E_DEV_FUNC_CAP_VALID_FUNC:
2872                         p->valid_functions = number;
2873                         break;
2874                 case I40E_DEV_FUNC_CAP_SRIOV_1_1:
2875                         if (number == 1)
2876                                 p->sr_iov_1_1 = true;
2877                         break;
2878                 case I40E_DEV_FUNC_CAP_VF:
2879                         p->num_vfs = number;
2880                         p->vf_base_id = logical_id;
2881                         break;
2882                 case I40E_DEV_FUNC_CAP_VMDQ:
2883                         if (number == 1)
2884                                 p->vmdq = true;
2885                         break;
2886                 case I40E_DEV_FUNC_CAP_802_1_QBG:
2887                         if (number == 1)
2888                                 p->evb_802_1_qbg = true;
2889                         break;
2890                 case I40E_DEV_FUNC_CAP_802_1_QBH:
2891                         if (number == 1)
2892                                 p->evb_802_1_qbh = true;
2893                         break;
2894                 case I40E_DEV_FUNC_CAP_VSI:
2895                         p->num_vsis = number;
2896                         break;
2897                 case I40E_DEV_FUNC_CAP_DCB:
2898                         if (number == 1) {
2899                                 p->dcb = true;
2900                                 p->enabled_tcmap = logical_id;
2901                                 p->maxtc = phys_id;
2902                         }
2903                         break;
2904                 case I40E_DEV_FUNC_CAP_FCOE:
2905                         if (number == 1)
2906                                 p->fcoe = true;
2907                         break;
2908                 case I40E_DEV_FUNC_CAP_ISCSI:
2909                         if (number == 1)
2910                                 p->iscsi = true;
2911                         break;
2912                 case I40E_DEV_FUNC_CAP_RSS:
2913                         p->rss = true;
2914                         p->rss_table_size = number;
2915                         p->rss_table_entry_width = logical_id;
2916                         break;
2917                 case I40E_DEV_FUNC_CAP_RX_QUEUES:
2918                         p->num_rx_qp = number;
2919                         p->base_queue = phys_id;
2920                         break;
2921                 case I40E_DEV_FUNC_CAP_TX_QUEUES:
2922                         p->num_tx_qp = number;
2923                         p->base_queue = phys_id;
2924                         break;
2925                 case I40E_DEV_FUNC_CAP_MSIX:
2926                         p->num_msix_vectors = number;
2927                         break;
2928                 case I40E_DEV_FUNC_CAP_MSIX_VF:
2929                         p->num_msix_vectors_vf = number;
2930                         break;
2931                 case I40E_DEV_FUNC_CAP_MFP_MODE_1:
2932                         if (number == 1)
2933                                 p->mfp_mode_1 = true;
2934                         break;
2935                 case I40E_DEV_FUNC_CAP_CEM:
2936                         if (number == 1)
2937                                 p->mgmt_cem = true;
2938                         break;
2939                 case I40E_DEV_FUNC_CAP_IWARP:
2940                         if (number == 1)
2941                                 p->iwarp = true;
2942                         break;
2943                 case I40E_DEV_FUNC_CAP_LED:
2944                         if (phys_id < I40E_HW_CAP_MAX_GPIO)
2945                                 p->led[phys_id] = true;
2946                         break;
2947                 case I40E_DEV_FUNC_CAP_SDP:
2948                         if (phys_id < I40E_HW_CAP_MAX_GPIO)
2949                                 p->sdp[phys_id] = true;
2950                         break;
2951                 case I40E_DEV_FUNC_CAP_MDIO:
2952                         if (number == 1) {
2953                                 p->mdio_port_num = phys_id;
2954                                 p->mdio_port_mode = logical_id;
2955                         }
2956                         break;
2957                 case I40E_DEV_FUNC_CAP_IEEE_1588:
2958                         if (number == 1)
2959                                 p->ieee_1588 = true;
2960                         break;
2961                 case I40E_DEV_FUNC_CAP_FLOW_DIRECTOR:
2962                         p->fd = true;
2963                         p->fd_filters_guaranteed = number;
2964                         p->fd_filters_best_effort = logical_id;
2965                         break;
2966                 default:
2967                         break;
2968                 }
2969         }
2970
2971 #ifdef I40E_FCOE_ENA
2972         /* Software override ensuring FCoE is disabled if npar or mfp
2973          * mode because it is not supported in these modes.
2974          */
2975         if (p->npar_enable || p->mfp_mode_1)
2976                 p->fcoe = false;
2977 #else
2978         /* Always disable FCoE if compiled without the I40E_FCOE_ENA flag */
2979         p->fcoe = false;
2980 #endif
2981
2982         /* count the enabled ports (aka the "not disabled" ports) */
2983         hw->num_ports = 0;
2984         for (i = 0; i < 4; i++) {
2985                 u32 port_cfg_reg = I40E_PRTGEN_CNF + (4 * i);
2986                 u64 port_cfg = 0;
2987
2988                 /* use AQ read to get the physical register offset instead
2989                  * of the port relative offset
2990                  */
2991                 i40e_aq_debug_read_register(hw, port_cfg_reg, &port_cfg, NULL);
2992                 if (!(port_cfg & I40E_PRTGEN_CNF_PORT_DIS_MASK))
2993                         hw->num_ports++;
2994         }
2995
2996         valid_functions = p->valid_functions;
2997         num_functions = 0;
2998         while (valid_functions) {
2999                 if (valid_functions & 1)
3000                         num_functions++;
3001                 valid_functions >>= 1;
3002         }
3003
3004         /* partition id is 1-based, and functions are evenly spread
3005          * across the ports as partitions
3006          */
3007         hw->partition_id = (hw->pf_id / hw->num_ports) + 1;
3008         hw->num_partitions = num_functions / hw->num_ports;
3009
3010         /* additional HW specific goodies that might
3011          * someday be HW version specific
3012          */
3013         p->rx_buf_chain_len = I40E_MAX_CHAINED_RX_BUFFERS;
3014 }
3015
3016 /**
3017  * i40e_aq_discover_capabilities
3018  * @hw: pointer to the hw struct
3019  * @buff: a virtual buffer to hold the capabilities
3020  * @buff_size: Size of the virtual buffer
3021  * @data_size: Size of the returned data, or buff size needed if AQ err==ENOMEM
3022  * @list_type_opc: capabilities type to discover - pass in the command opcode
3023  * @cmd_details: pointer to command details structure or NULL
3024  *
3025  * Get the device capabilities descriptions from the firmware
3026  **/
3027 enum i40e_status_code i40e_aq_discover_capabilities(struct i40e_hw *hw,
3028                                 void *buff, u16 buff_size, u16 *data_size,
3029                                 enum i40e_admin_queue_opc list_type_opc,
3030                                 struct i40e_asq_cmd_details *cmd_details)
3031 {
3032         struct i40e_aqc_list_capabilites *cmd;
3033         struct i40e_aq_desc desc;
3034         enum i40e_status_code status = I40E_SUCCESS;
3035
3036         cmd = (struct i40e_aqc_list_capabilites *)&desc.params.raw;
3037
3038         if (list_type_opc != i40e_aqc_opc_list_func_capabilities &&
3039                 list_type_opc != i40e_aqc_opc_list_dev_capabilities) {
3040                 status = I40E_ERR_PARAM;
3041                 goto exit;
3042         }
3043
3044         i40e_fill_default_direct_cmd_desc(&desc, list_type_opc);
3045
3046         desc.flags |= CPU_TO_LE16((u16)I40E_AQ_FLAG_BUF);
3047         if (buff_size > I40E_AQ_LARGE_BUF)
3048                 desc.flags |= CPU_TO_LE16((u16)I40E_AQ_FLAG_LB);
3049
3050         status = i40e_asq_send_command(hw, &desc, buff, buff_size, cmd_details);
3051         *data_size = LE16_TO_CPU(desc.datalen);
3052
3053         if (status)
3054                 goto exit;
3055
3056         i40e_parse_discover_capabilities(hw, buff, LE32_TO_CPU(cmd->count),
3057                                          list_type_opc);
3058
3059 exit:
3060         return status;
3061 }
3062
3063 /**
3064  * i40e_aq_update_nvm
3065  * @hw: pointer to the hw struct
3066  * @module_pointer: module pointer location in words from the NVM beginning
3067  * @offset: byte offset from the module beginning
3068  * @length: length of the section to be written (in bytes from the offset)
3069  * @data: command buffer (size [bytes] = length)
3070  * @last_command: tells if this is the last command in a series
3071  * @cmd_details: pointer to command details structure or NULL
3072  *
3073  * Update the NVM using the admin queue commands
3074  **/
3075 enum i40e_status_code i40e_aq_update_nvm(struct i40e_hw *hw, u8 module_pointer,
3076                                 u32 offset, u16 length, void *data,
3077                                 bool last_command,
3078                                 struct i40e_asq_cmd_details *cmd_details)
3079 {
3080         struct i40e_aq_desc desc;
3081         struct i40e_aqc_nvm_update *cmd =
3082                 (struct i40e_aqc_nvm_update *)&desc.params.raw;
3083         enum i40e_status_code status;
3084
3085         DEBUGFUNC("i40e_aq_update_nvm");
3086
3087         /* In offset the highest byte must be zeroed. */
3088         if (offset & 0xFF000000) {
3089                 status = I40E_ERR_PARAM;
3090                 goto i40e_aq_update_nvm_exit;
3091         }
3092
3093         i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_nvm_update);
3094
3095         /* If this is the last command in a series, set the proper flag. */
3096         if (last_command)
3097                 cmd->command_flags |= I40E_AQ_NVM_LAST_CMD;
3098         cmd->module_pointer = module_pointer;
3099         cmd->offset = CPU_TO_LE32(offset);
3100         cmd->length = CPU_TO_LE16(length);
3101
3102         desc.flags |= CPU_TO_LE16((u16)(I40E_AQ_FLAG_BUF | I40E_AQ_FLAG_RD));
3103         if (length > I40E_AQ_LARGE_BUF)
3104                 desc.flags |= CPU_TO_LE16((u16)I40E_AQ_FLAG_LB);
3105
3106         status = i40e_asq_send_command(hw, &desc, data, length, cmd_details);
3107
3108 i40e_aq_update_nvm_exit:
3109         return status;
3110 }
3111
3112 /**
3113  * i40e_aq_get_lldp_mib
3114  * @hw: pointer to the hw struct
3115  * @bridge_type: type of bridge requested
3116  * @mib_type: Local, Remote or both Local and Remote MIBs
3117  * @buff: pointer to a user supplied buffer to store the MIB block
3118  * @buff_size: size of the buffer (in bytes)
3119  * @local_len : length of the returned Local LLDP MIB
3120  * @remote_len: length of the returned Remote LLDP MIB
3121  * @cmd_details: pointer to command details structure or NULL
3122  *
3123  * Requests the complete LLDP MIB (entire packet).
3124  **/
3125 enum i40e_status_code i40e_aq_get_lldp_mib(struct i40e_hw *hw, u8 bridge_type,
3126                                 u8 mib_type, void *buff, u16 buff_size,
3127                                 u16 *local_len, u16 *remote_len,
3128                                 struct i40e_asq_cmd_details *cmd_details)
3129 {
3130         struct i40e_aq_desc desc;
3131         struct i40e_aqc_lldp_get_mib *cmd =
3132                 (struct i40e_aqc_lldp_get_mib *)&desc.params.raw;
3133         struct i40e_aqc_lldp_get_mib *resp =
3134                 (struct i40e_aqc_lldp_get_mib *)&desc.params.raw;
3135         enum i40e_status_code status;
3136
3137         if (buff_size == 0 || !buff)
3138                 return I40E_ERR_PARAM;
3139
3140         i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_lldp_get_mib);
3141         /* Indirect Command */
3142         desc.flags |= CPU_TO_LE16((u16)I40E_AQ_FLAG_BUF);
3143
3144         cmd->type = mib_type & I40E_AQ_LLDP_MIB_TYPE_MASK;
3145         cmd->type |= ((bridge_type << I40E_AQ_LLDP_BRIDGE_TYPE_SHIFT) &
3146                        I40E_AQ_LLDP_BRIDGE_TYPE_MASK);
3147
3148         desc.datalen = CPU_TO_LE16(buff_size);
3149
3150         desc.flags |= CPU_TO_LE16((u16)I40E_AQ_FLAG_BUF);
3151         if (buff_size > I40E_AQ_LARGE_BUF)
3152                 desc.flags |= CPU_TO_LE16((u16)I40E_AQ_FLAG_LB);
3153
3154         status = i40e_asq_send_command(hw, &desc, buff, buff_size, cmd_details);
3155         if (!status) {
3156                 if (local_len != NULL)
3157                         *local_len = LE16_TO_CPU(resp->local_len);
3158                 if (remote_len != NULL)
3159                         *remote_len = LE16_TO_CPU(resp->remote_len);
3160         }
3161
3162         return status;
3163 }
3164
3165 /**
3166  * i40e_aq_set_lldp_mib - Set the LLDP MIB
3167  * @hw: pointer to the hw struct
3168  * @mib_type: Local, Remote or both Local and Remote MIBs
3169  * @buff: pointer to a user supplied buffer to store the MIB block
3170  * @buff_size: size of the buffer (in bytes)
3171  * @cmd_details: pointer to command details structure or NULL
3172  *
3173  * Set the LLDP MIB.
3174  **/
3175 enum i40e_status_code i40e_aq_set_lldp_mib(struct i40e_hw *hw,
3176                                 u8 mib_type, void *buff, u16 buff_size,
3177                                 struct i40e_asq_cmd_details *cmd_details)
3178 {
3179         struct i40e_aq_desc desc;
3180         struct i40e_aqc_lldp_set_local_mib *cmd =
3181                 (struct i40e_aqc_lldp_set_local_mib *)&desc.params.raw;
3182         enum i40e_status_code status;
3183
3184         if (buff_size == 0 || !buff)
3185                 return I40E_ERR_PARAM;
3186
3187         i40e_fill_default_direct_cmd_desc(&desc,
3188                                 i40e_aqc_opc_lldp_set_local_mib);
3189         /* Indirect Command */
3190         desc.flags |= CPU_TO_LE16((u16)(I40E_AQ_FLAG_BUF | I40E_AQ_FLAG_RD));
3191         if (buff_size > I40E_AQ_LARGE_BUF)
3192                 desc.flags |= CPU_TO_LE16((u16)I40E_AQ_FLAG_LB);
3193         desc.datalen = CPU_TO_LE16(buff_size);
3194
3195         cmd->type = mib_type;
3196         cmd->length = CPU_TO_LE16(buff_size);
3197         cmd->address_high = CPU_TO_LE32(I40E_HI_WORD((u64)buff));
3198         cmd->address_low =  CPU_TO_LE32(I40E_LO_DWORD((u64)buff));
3199
3200         status = i40e_asq_send_command(hw, &desc, buff, buff_size, cmd_details);
3201         return status;
3202 }
3203
3204 /**
3205  * i40e_aq_cfg_lldp_mib_change_event
3206  * @hw: pointer to the hw struct
3207  * @enable_update: Enable or Disable event posting
3208  * @cmd_details: pointer to command details structure or NULL
3209  *
3210  * Enable or Disable posting of an event on ARQ when LLDP MIB
3211  * associated with the interface changes
3212  **/
3213 enum i40e_status_code i40e_aq_cfg_lldp_mib_change_event(struct i40e_hw *hw,
3214                                 bool enable_update,
3215                                 struct i40e_asq_cmd_details *cmd_details)
3216 {
3217         struct i40e_aq_desc desc;
3218         struct i40e_aqc_lldp_update_mib *cmd =
3219                 (struct i40e_aqc_lldp_update_mib *)&desc.params.raw;
3220         enum i40e_status_code status;
3221
3222         i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_lldp_update_mib);
3223
3224         if (!enable_update)
3225                 cmd->command |= I40E_AQ_LLDP_MIB_UPDATE_DISABLE;
3226
3227         status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
3228
3229         return status;
3230 }
3231
3232 /**
3233  * i40e_aq_add_lldp_tlv
3234  * @hw: pointer to the hw struct
3235  * @bridge_type: type of bridge
3236  * @buff: buffer with TLV to add
3237  * @buff_size: length of the buffer
3238  * @tlv_len: length of the TLV to be added
3239  * @mib_len: length of the LLDP MIB returned in response
3240  * @cmd_details: pointer to command details structure or NULL
3241  *
3242  * Add the specified TLV to LLDP Local MIB for the given bridge type,
3243  * it is responsibility of the caller to make sure that the TLV is not
3244  * already present in the LLDPDU.
3245  * In return firmware will write the complete LLDP MIB with the newly
3246  * added TLV in the response buffer.
3247  **/
3248 enum i40e_status_code i40e_aq_add_lldp_tlv(struct i40e_hw *hw, u8 bridge_type,
3249                                 void *buff, u16 buff_size, u16 tlv_len,
3250                                 u16 *mib_len,
3251                                 struct i40e_asq_cmd_details *cmd_details)
3252 {
3253         struct i40e_aq_desc desc;
3254         struct i40e_aqc_lldp_add_tlv *cmd =
3255                 (struct i40e_aqc_lldp_add_tlv *)&desc.params.raw;
3256         enum i40e_status_code status;
3257
3258         if (buff_size == 0 || !buff || tlv_len == 0)
3259                 return I40E_ERR_PARAM;
3260
3261         i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_lldp_add_tlv);
3262
3263         /* Indirect Command */
3264         desc.flags |= CPU_TO_LE16((u16)(I40E_AQ_FLAG_BUF | I40E_AQ_FLAG_RD));
3265         if (buff_size > I40E_AQ_LARGE_BUF)
3266                 desc.flags |= CPU_TO_LE16((u16)I40E_AQ_FLAG_LB);
3267         desc.datalen = CPU_TO_LE16(buff_size);
3268
3269         cmd->type = ((bridge_type << I40E_AQ_LLDP_BRIDGE_TYPE_SHIFT) &
3270                       I40E_AQ_LLDP_BRIDGE_TYPE_MASK);
3271         cmd->len = CPU_TO_LE16(tlv_len);
3272
3273         status = i40e_asq_send_command(hw, &desc, buff, buff_size, cmd_details);
3274         if (!status) {
3275                 if (mib_len != NULL)
3276                         *mib_len = LE16_TO_CPU(desc.datalen);
3277         }
3278
3279         return status;
3280 }
3281
3282 /**
3283  * i40e_aq_update_lldp_tlv
3284  * @hw: pointer to the hw struct
3285  * @bridge_type: type of bridge
3286  * @buff: buffer with TLV to update
3287  * @buff_size: size of the buffer holding original and updated TLVs
3288  * @old_len: Length of the Original TLV
3289  * @new_len: Length of the Updated TLV
3290  * @offset: offset of the updated TLV in the buff
3291  * @mib_len: length of the returned LLDP MIB
3292  * @cmd_details: pointer to command details structure or NULL
3293  *
3294  * Update the specified TLV to the LLDP Local MIB for the given bridge type.
3295  * Firmware will place the complete LLDP MIB in response buffer with the
3296  * updated TLV.
3297  **/
3298 enum i40e_status_code i40e_aq_update_lldp_tlv(struct i40e_hw *hw,
3299                                 u8 bridge_type, void *buff, u16 buff_size,
3300                                 u16 old_len, u16 new_len, u16 offset,
3301                                 u16 *mib_len,
3302                                 struct i40e_asq_cmd_details *cmd_details)
3303 {
3304         struct i40e_aq_desc desc;
3305         struct i40e_aqc_lldp_update_tlv *cmd =
3306                 (struct i40e_aqc_lldp_update_tlv *)&desc.params.raw;
3307         enum i40e_status_code status;
3308
3309         if (buff_size == 0 || !buff || offset == 0 ||
3310             old_len == 0 || new_len == 0)
3311                 return I40E_ERR_PARAM;
3312
3313         i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_lldp_update_tlv);
3314
3315         /* Indirect Command */
3316         desc.flags |= CPU_TO_LE16((u16)(I40E_AQ_FLAG_BUF | I40E_AQ_FLAG_RD));
3317         if (buff_size > I40E_AQ_LARGE_BUF)
3318                 desc.flags |= CPU_TO_LE16((u16)I40E_AQ_FLAG_LB);
3319         desc.datalen = CPU_TO_LE16(buff_size);
3320
3321         cmd->type = ((bridge_type << I40E_AQ_LLDP_BRIDGE_TYPE_SHIFT) &
3322                       I40E_AQ_LLDP_BRIDGE_TYPE_MASK);
3323         cmd->old_len = CPU_TO_LE16(old_len);
3324         cmd->new_offset = CPU_TO_LE16(offset);
3325         cmd->new_len = CPU_TO_LE16(new_len);
3326
3327         status = i40e_asq_send_command(hw, &desc, buff, buff_size, cmd_details);
3328         if (!status) {
3329                 if (mib_len != NULL)
3330                         *mib_len = LE16_TO_CPU(desc.datalen);
3331         }
3332
3333         return status;
3334 }
3335
3336 /**
3337  * i40e_aq_delete_lldp_tlv
3338  * @hw: pointer to the hw struct
3339  * @bridge_type: type of bridge
3340  * @buff: pointer to a user supplied buffer that has the TLV
3341  * @buff_size: length of the buffer
3342  * @tlv_len: length of the TLV to be deleted
3343  * @mib_len: length of the returned LLDP MIB
3344  * @cmd_details: pointer to command details structure or NULL
3345  *
3346  * Delete the specified TLV from LLDP Local MIB for the given bridge type.
3347  * The firmware places the entire LLDP MIB in the response buffer.
3348  **/
3349 enum i40e_status_code i40e_aq_delete_lldp_tlv(struct i40e_hw *hw,
3350                                 u8 bridge_type, void *buff, u16 buff_size,
3351                                 u16 tlv_len, u16 *mib_len,
3352                                 struct i40e_asq_cmd_details *cmd_details)
3353 {
3354         struct i40e_aq_desc desc;
3355         struct i40e_aqc_lldp_add_tlv *cmd =
3356                 (struct i40e_aqc_lldp_add_tlv *)&desc.params.raw;
3357         enum i40e_status_code status;
3358
3359         if (buff_size == 0 || !buff)
3360                 return I40E_ERR_PARAM;
3361
3362         i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_lldp_delete_tlv);
3363
3364         /* Indirect Command */
3365         desc.flags |= CPU_TO_LE16((u16)(I40E_AQ_FLAG_BUF | I40E_AQ_FLAG_RD));
3366         if (buff_size > I40E_AQ_LARGE_BUF)
3367                 desc.flags |= CPU_TO_LE16((u16)I40E_AQ_FLAG_LB);
3368         desc.datalen = CPU_TO_LE16(buff_size);
3369         cmd->len = CPU_TO_LE16(tlv_len);
3370         cmd->type = ((bridge_type << I40E_AQ_LLDP_BRIDGE_TYPE_SHIFT) &
3371                       I40E_AQ_LLDP_BRIDGE_TYPE_MASK);
3372
3373         status = i40e_asq_send_command(hw, &desc, buff, buff_size, cmd_details);
3374         if (!status) {
3375                 if (mib_len != NULL)
3376                         *mib_len = LE16_TO_CPU(desc.datalen);
3377         }
3378
3379         return status;
3380 }
3381
3382 /**
3383  * i40e_aq_stop_lldp
3384  * @hw: pointer to the hw struct
3385  * @shutdown_agent: True if LLDP Agent needs to be Shutdown
3386  * @cmd_details: pointer to command details structure or NULL
3387  *
3388  * Stop or Shutdown the embedded LLDP Agent
3389  **/
3390 enum i40e_status_code i40e_aq_stop_lldp(struct i40e_hw *hw, bool shutdown_agent,
3391                                 struct i40e_asq_cmd_details *cmd_details)
3392 {
3393         struct i40e_aq_desc desc;
3394         struct i40e_aqc_lldp_stop *cmd =
3395                 (struct i40e_aqc_lldp_stop *)&desc.params.raw;
3396         enum i40e_status_code status;
3397
3398         i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_lldp_stop);
3399
3400         if (shutdown_agent)
3401                 cmd->command |= I40E_AQ_LLDP_AGENT_SHUTDOWN;
3402
3403         status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
3404
3405         return status;
3406 }
3407
3408 /**
3409  * i40e_aq_start_lldp
3410  * @hw: pointer to the hw struct
3411  * @cmd_details: pointer to command details structure or NULL
3412  *
3413  * Start the embedded LLDP Agent on all ports.
3414  **/
3415 enum i40e_status_code i40e_aq_start_lldp(struct i40e_hw *hw,
3416                                 struct i40e_asq_cmd_details *cmd_details)
3417 {
3418         struct i40e_aq_desc desc;
3419         struct i40e_aqc_lldp_start *cmd =
3420                 (struct i40e_aqc_lldp_start *)&desc.params.raw;
3421         enum i40e_status_code status;
3422
3423         i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_lldp_start);
3424
3425         cmd->command = I40E_AQ_LLDP_AGENT_START;
3426
3427         status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
3428
3429         return status;
3430 }
3431
3432 /**
3433  * i40e_aq_get_cee_dcb_config
3434  * @hw: pointer to the hw struct
3435  * @buff: response buffer that stores CEE operational configuration
3436  * @buff_size: size of the buffer passed
3437  * @cmd_details: pointer to command details structure or NULL
3438  *
3439  * Get CEE DCBX mode operational configuration from firmware
3440  **/
3441 enum i40e_status_code i40e_aq_get_cee_dcb_config(struct i40e_hw *hw,
3442                                 void *buff, u16 buff_size,
3443                                 struct i40e_asq_cmd_details *cmd_details)
3444 {
3445         struct i40e_aq_desc desc;
3446         enum i40e_status_code status;
3447
3448         if (buff_size == 0 || !buff)
3449                 return I40E_ERR_PARAM;
3450
3451         i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_get_cee_dcb_cfg);
3452
3453         desc.flags |= CPU_TO_LE16((u16)I40E_AQ_FLAG_BUF);
3454         status = i40e_asq_send_command(hw, &desc, (void *)buff, buff_size,
3455                                        cmd_details);
3456
3457         return status;
3458 }
3459
3460 /**
3461  * i40e_aq_start_stop_dcbx - Start/Stop DCBx service in FW
3462  * @hw: pointer to the hw struct
3463  * @start_agent: True if DCBx Agent needs to be Started
3464  *                              False if DCBx Agent needs to be Stopped
3465  * @cmd_details: pointer to command details structure or NULL
3466  *
3467  * Start/Stop the embedded dcbx Agent
3468  **/
3469 enum i40e_status_code i40e_aq_start_stop_dcbx(struct i40e_hw *hw,
3470                                 bool start_agent,
3471                                 struct i40e_asq_cmd_details *cmd_details)
3472 {
3473         struct i40e_aq_desc desc;
3474         struct i40e_aqc_lldp_stop_start_specific_agent *cmd =
3475                 (struct i40e_aqc_lldp_stop_start_specific_agent *)
3476                                 &desc.params.raw;
3477         enum i40e_status_code status;
3478
3479         i40e_fill_default_direct_cmd_desc(&desc,
3480                                 i40e_aqc_opc_lldp_stop_start_spec_agent);
3481
3482         if (start_agent)
3483                 cmd->command = I40E_AQC_START_SPECIFIC_AGENT_MASK;
3484
3485         status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
3486
3487         return status;
3488 }
3489
3490 /**
3491  * i40e_aq_add_udp_tunnel
3492  * @hw: pointer to the hw struct
3493  * @udp_port: the UDP port to add
3494  * @header_len: length of the tunneling header length in DWords
3495  * @protocol_index: protocol index type
3496  * @filter_index: pointer to filter index
3497  * @cmd_details: pointer to command details structure or NULL
3498  **/
3499 enum i40e_status_code i40e_aq_add_udp_tunnel(struct i40e_hw *hw,
3500                                 u16 udp_port, u8 protocol_index,
3501                                 u8 *filter_index,
3502                                 struct i40e_asq_cmd_details *cmd_details)
3503 {
3504         struct i40e_aq_desc desc;
3505         struct i40e_aqc_add_udp_tunnel *cmd =
3506                 (struct i40e_aqc_add_udp_tunnel *)&desc.params.raw;
3507         struct i40e_aqc_del_udp_tunnel_completion *resp =
3508                 (struct i40e_aqc_del_udp_tunnel_completion *)&desc.params.raw;
3509         enum i40e_status_code status;
3510
3511         i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_add_udp_tunnel);
3512
3513         cmd->udp_port = CPU_TO_LE16(udp_port);
3514         cmd->protocol_type = protocol_index;
3515
3516         status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
3517
3518         if (!status)
3519                 *filter_index = resp->index;
3520
3521         return status;
3522 }
3523
3524 /**
3525  * i40e_aq_del_udp_tunnel
3526  * @hw: pointer to the hw struct
3527  * @index: filter index
3528  * @cmd_details: pointer to command details structure or NULL
3529  **/
3530 enum i40e_status_code i40e_aq_del_udp_tunnel(struct i40e_hw *hw, u8 index,
3531                                 struct i40e_asq_cmd_details *cmd_details)
3532 {
3533         struct i40e_aq_desc desc;
3534         struct i40e_aqc_remove_udp_tunnel *cmd =
3535                 (struct i40e_aqc_remove_udp_tunnel *)&desc.params.raw;
3536         enum i40e_status_code status;
3537
3538         i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_del_udp_tunnel);
3539
3540         cmd->index = index;
3541
3542         status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
3543
3544         return status;
3545 }
3546
3547 /**
3548  * i40e_aq_get_switch_resource_alloc (0x0204)
3549  * @hw: pointer to the hw struct
3550  * @num_entries: pointer to u8 to store the number of resource entries returned
3551  * @buf: pointer to a user supplied buffer.  This buffer must be large enough
3552  *        to store the resource information for all resource types.  Each
3553  *        resource type is a i40e_aqc_switch_resource_alloc_data structure.
3554  * @count: size, in bytes, of the buffer provided
3555  * @cmd_details: pointer to command details structure or NULL
3556  *
3557  * Query the resources allocated to a function.
3558  **/
3559 enum i40e_status_code i40e_aq_get_switch_resource_alloc(struct i40e_hw *hw,
3560                         u8 *num_entries,
3561                         struct i40e_aqc_switch_resource_alloc_element_resp *buf,
3562                         u16 count,
3563                         struct i40e_asq_cmd_details *cmd_details)
3564 {
3565         struct i40e_aq_desc desc;
3566         struct i40e_aqc_get_switch_resource_alloc *cmd_resp =
3567                 (struct i40e_aqc_get_switch_resource_alloc *)&desc.params.raw;
3568         enum i40e_status_code status;
3569         u16 length = count
3570                    * sizeof(struct i40e_aqc_switch_resource_alloc_element_resp);
3571
3572         i40e_fill_default_direct_cmd_desc(&desc,
3573                                         i40e_aqc_opc_get_switch_resource_alloc);
3574
3575         desc.flags |= CPU_TO_LE16((u16)I40E_AQ_FLAG_BUF);
3576         if (length > I40E_AQ_LARGE_BUF)
3577                 desc.flags |= CPU_TO_LE16((u16)I40E_AQ_FLAG_LB);
3578
3579         status = i40e_asq_send_command(hw, &desc, buf, length, cmd_details);
3580
3581         if (!status)
3582                 *num_entries = cmd_resp->num_entries;
3583
3584         return status;
3585 }
3586
3587 /**
3588  * i40e_aq_delete_element - Delete switch element
3589  * @hw: pointer to the hw struct
3590  * @seid: the SEID to delete from the switch
3591  * @cmd_details: pointer to command details structure or NULL
3592  *
3593  * This deletes a switch element from the switch.
3594  **/
3595 enum i40e_status_code i40e_aq_delete_element(struct i40e_hw *hw, u16 seid,
3596                                 struct i40e_asq_cmd_details *cmd_details)
3597 {
3598         struct i40e_aq_desc desc;
3599         struct i40e_aqc_switch_seid *cmd =
3600                 (struct i40e_aqc_switch_seid *)&desc.params.raw;
3601         enum i40e_status_code status;
3602
3603         if (seid == 0)
3604                 return I40E_ERR_PARAM;
3605
3606         i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_delete_element);
3607
3608         cmd->seid = CPU_TO_LE16(seid);
3609
3610         status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
3611
3612         return status;
3613 }
3614
3615 /**
3616  * i40_aq_add_pvirt - Instantiate a Port Virtualizer on a port
3617  * @hw: pointer to the hw struct
3618  * @flags: component flags
3619  * @mac_seid: uplink seid (MAC SEID)
3620  * @vsi_seid: connected vsi seid
3621  * @ret_seid: seid of create pv component
3622  *
3623  * This instantiates an i40e port virtualizer with specified flags.
3624  * Depending on specified flags the port virtualizer can act as a
3625  * 802.1Qbr port virtualizer or a 802.1Qbg S-component.
3626  */
3627 enum i40e_status_code i40e_aq_add_pvirt(struct i40e_hw *hw, u16 flags,
3628                                        u16 mac_seid, u16 vsi_seid,
3629                                        u16 *ret_seid)
3630 {
3631         struct i40e_aq_desc desc;
3632         struct i40e_aqc_add_update_pv *cmd =
3633                 (struct i40e_aqc_add_update_pv *)&desc.params.raw;
3634         struct i40e_aqc_add_update_pv_completion *resp =
3635                 (struct i40e_aqc_add_update_pv_completion *)&desc.params.raw;
3636         enum i40e_status_code status;
3637
3638         if (vsi_seid == 0)
3639                 return I40E_ERR_PARAM;
3640
3641         i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_add_pv);
3642         cmd->command_flags = CPU_TO_LE16(flags);
3643         cmd->uplink_seid = CPU_TO_LE16(mac_seid);
3644         cmd->connected_seid = CPU_TO_LE16(vsi_seid);
3645
3646         status = i40e_asq_send_command(hw, &desc, NULL, 0, NULL);
3647         if (!status && ret_seid)
3648                 *ret_seid = LE16_TO_CPU(resp->pv_seid);
3649
3650         return status;
3651 }
3652
3653 /**
3654  * i40e_aq_add_tag - Add an S/E-tag
3655  * @hw: pointer to the hw struct
3656  * @direct_to_queue: should s-tag direct flow to a specific queue
3657  * @vsi_seid: VSI SEID to use this tag
3658  * @tag: value of the tag
3659  * @queue_num: queue number, only valid is direct_to_queue is true
3660  * @tags_used: return value, number of tags in use by this PF
3661  * @tags_free: return value, number of unallocated tags
3662  * @cmd_details: pointer to command details structure or NULL
3663  *
3664  * This associates an S- or E-tag to a VSI in the switch complex.  It returns
3665  * the number of tags allocated by the PF, and the number of unallocated
3666  * tags available.
3667  **/
3668 enum i40e_status_code i40e_aq_add_tag(struct i40e_hw *hw, bool direct_to_queue,
3669                                 u16 vsi_seid, u16 tag, u16 queue_num,
3670                                 u16 *tags_used, u16 *tags_free,
3671                                 struct i40e_asq_cmd_details *cmd_details)
3672 {
3673         struct i40e_aq_desc desc;
3674         struct i40e_aqc_add_tag *cmd =
3675                 (struct i40e_aqc_add_tag *)&desc.params.raw;
3676         struct i40e_aqc_add_remove_tag_completion *resp =
3677                 (struct i40e_aqc_add_remove_tag_completion *)&desc.params.raw;
3678         enum i40e_status_code status;
3679
3680         if (vsi_seid == 0)
3681                 return I40E_ERR_PARAM;
3682
3683         i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_add_tag);
3684
3685         cmd->seid = CPU_TO_LE16(vsi_seid);
3686         cmd->tag = CPU_TO_LE16(tag);
3687         if (direct_to_queue) {
3688                 cmd->flags = CPU_TO_LE16(I40E_AQC_ADD_TAG_FLAG_TO_QUEUE);
3689                 cmd->queue_number = CPU_TO_LE16(queue_num);
3690         }
3691
3692         status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
3693
3694         if (!status) {
3695                 if (tags_used != NULL)
3696                         *tags_used = LE16_TO_CPU(resp->tags_used);
3697                 if (tags_free != NULL)
3698                         *tags_free = LE16_TO_CPU(resp->tags_free);
3699         }
3700
3701         return status;
3702 }
3703
3704 /**
3705  * i40e_aq_remove_tag - Remove an S- or E-tag
3706  * @hw: pointer to the hw struct
3707  * @vsi_seid: VSI SEID this tag is associated with
3708  * @tag: value of the S-tag to delete
3709  * @tags_used: return value, number of tags in use by this PF
3710  * @tags_free: return value, number of unallocated tags
3711  * @cmd_details: pointer to command details structure or NULL
3712  *
3713  * This deletes an S- or E-tag from a VSI in the switch complex.  It returns
3714  * the number of tags allocated by the PF, and the number of unallocated
3715  * tags available.
3716  **/
3717 enum i40e_status_code i40e_aq_remove_tag(struct i40e_hw *hw, u16 vsi_seid,
3718                                 u16 tag, u16 *tags_used, u16 *tags_free,
3719                                 struct i40e_asq_cmd_details *cmd_details)
3720 {
3721         struct i40e_aq_desc desc;
3722         struct i40e_aqc_remove_tag *cmd =
3723                 (struct i40e_aqc_remove_tag *)&desc.params.raw;
3724         struct i40e_aqc_add_remove_tag_completion *resp =
3725                 (struct i40e_aqc_add_remove_tag_completion *)&desc.params.raw;
3726         enum i40e_status_code status;
3727
3728         if (vsi_seid == 0)
3729                 return I40E_ERR_PARAM;
3730
3731         i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_remove_tag);
3732
3733         cmd->seid = CPU_TO_LE16(vsi_seid);
3734         cmd->tag = CPU_TO_LE16(tag);
3735
3736         status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
3737
3738         if (!status) {
3739                 if (tags_used != NULL)
3740                         *tags_used = LE16_TO_CPU(resp->tags_used);
3741                 if (tags_free != NULL)
3742                         *tags_free = LE16_TO_CPU(resp->tags_free);
3743         }
3744
3745         return status;
3746 }
3747
3748 /**
3749  * i40e_aq_add_mcast_etag - Add a multicast E-tag
3750  * @hw: pointer to the hw struct
3751  * @pv_seid: Port Virtualizer of this SEID to associate E-tag with
3752  * @etag: value of E-tag to add
3753  * @num_tags_in_buf: number of unicast E-tags in indirect buffer
3754  * @buf: address of indirect buffer
3755  * @tags_used: return value, number of E-tags in use by this port
3756  * @tags_free: return value, number of unallocated M-tags
3757  * @cmd_details: pointer to command details structure or NULL
3758  *
3759  * This associates a multicast E-tag to a port virtualizer.  It will return
3760  * the number of tags allocated by the PF, and the number of unallocated
3761  * tags available.
3762  *
3763  * The indirect buffer pointed to by buf is a list of 2-byte E-tags,
3764  * num_tags_in_buf long.
3765  **/
3766 enum i40e_status_code i40e_aq_add_mcast_etag(struct i40e_hw *hw, u16 pv_seid,
3767                                 u16 etag, u8 num_tags_in_buf, void *buf,
3768                                 u16 *tags_used, u16 *tags_free,
3769                                 struct i40e_asq_cmd_details *cmd_details)
3770 {
3771         struct i40e_aq_desc desc;
3772         struct i40e_aqc_add_remove_mcast_etag *cmd =
3773                 (struct i40e_aqc_add_remove_mcast_etag *)&desc.params.raw;
3774         struct i40e_aqc_add_remove_mcast_etag_completion *resp =
3775            (struct i40e_aqc_add_remove_mcast_etag_completion *)&desc.params.raw;
3776         enum i40e_status_code status;
3777         u16 length = sizeof(u16) * num_tags_in_buf;
3778
3779         if ((pv_seid == 0) || (buf == NULL) || (num_tags_in_buf == 0))
3780                 return I40E_ERR_PARAM;
3781
3782         i40e_fill_default_direct_cmd_desc(&desc,
3783                                           i40e_aqc_opc_add_multicast_etag);
3784
3785         cmd->pv_seid = CPU_TO_LE16(pv_seid);
3786         cmd->etag = CPU_TO_LE16(etag);
3787         cmd->num_unicast_etags = num_tags_in_buf;
3788
3789         desc.flags |= CPU_TO_LE16((u16)(I40E_AQ_FLAG_BUF | I40E_AQ_FLAG_RD));
3790         if (length > I40E_AQ_LARGE_BUF)
3791                 desc.flags |= CPU_TO_LE16((u16)I40E_AQ_FLAG_LB);
3792
3793         status = i40e_asq_send_command(hw, &desc, buf, length, cmd_details);
3794
3795         if (!status) {
3796                 if (tags_used != NULL)
3797                         *tags_used = LE16_TO_CPU(resp->mcast_etags_used);
3798                 if (tags_free != NULL)
3799                         *tags_free = LE16_TO_CPU(resp->mcast_etags_free);
3800         }
3801
3802         return status;
3803 }
3804
3805 /**
3806  * i40e_aq_remove_mcast_etag - Remove a multicast E-tag
3807  * @hw: pointer to the hw struct
3808  * @pv_seid: Port Virtualizer SEID this M-tag is associated with
3809  * @etag: value of the E-tag to remove
3810  * @tags_used: return value, number of tags in use by this port
3811  * @tags_free: return value, number of unallocated tags
3812  * @cmd_details: pointer to command details structure or NULL
3813  *
3814  * This deletes an E-tag from the port virtualizer.  It will return
3815  * the number of tags allocated by the port, and the number of unallocated
3816  * tags available.
3817  **/
3818 enum i40e_status_code i40e_aq_remove_mcast_etag(struct i40e_hw *hw, u16 pv_seid,
3819                                 u16 etag, u16 *tags_used, u16 *tags_free,
3820                                 struct i40e_asq_cmd_details *cmd_details)
3821 {
3822         struct i40e_aq_desc desc;
3823         struct i40e_aqc_add_remove_mcast_etag *cmd =
3824                 (struct i40e_aqc_add_remove_mcast_etag *)&desc.params.raw;
3825         struct i40e_aqc_add_remove_mcast_etag_completion *resp =
3826            (struct i40e_aqc_add_remove_mcast_etag_completion *)&desc.params.raw;
3827         enum i40e_status_code status;
3828
3829
3830         if (pv_seid == 0)
3831                 return I40E_ERR_PARAM;
3832
3833         i40e_fill_default_direct_cmd_desc(&desc,
3834                                           i40e_aqc_opc_remove_multicast_etag);
3835
3836         cmd->pv_seid = CPU_TO_LE16(pv_seid);
3837         cmd->etag = CPU_TO_LE16(etag);
3838
3839         status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
3840
3841         if (!status) {
3842                 if (tags_used != NULL)
3843                         *tags_used = LE16_TO_CPU(resp->mcast_etags_used);
3844                 if (tags_free != NULL)
3845                         *tags_free = LE16_TO_CPU(resp->mcast_etags_free);
3846         }
3847
3848         return status;
3849 }
3850
3851 /**
3852  * i40e_aq_update_tag - Update an S/E-tag
3853  * @hw: pointer to the hw struct
3854  * @vsi_seid: VSI SEID using this S-tag
3855  * @old_tag: old tag value
3856  * @new_tag: new tag value
3857  * @tags_used: return value, number of tags in use by this PF
3858  * @tags_free: return value, number of unallocated tags
3859  * @cmd_details: pointer to command details structure or NULL
3860  *
3861  * This updates the value of the tag currently attached to this VSI
3862  * in the switch complex.  It will return the number of tags allocated
3863  * by the PF, and the number of unallocated tags available.
3864  **/
3865 enum i40e_status_code i40e_aq_update_tag(struct i40e_hw *hw, u16 vsi_seid,
3866                                 u16 old_tag, u16 new_tag, u16 *tags_used,
3867                                 u16 *tags_free,
3868                                 struct i40e_asq_cmd_details *cmd_details)
3869 {
3870         struct i40e_aq_desc desc;
3871         struct i40e_aqc_update_tag *cmd =
3872                 (struct i40e_aqc_update_tag *)&desc.params.raw;
3873         struct i40e_aqc_update_tag_completion *resp =
3874                 (struct i40e_aqc_update_tag_completion *)&desc.params.raw;
3875         enum i40e_status_code status;
3876
3877         if (vsi_seid == 0)
3878                 return I40E_ERR_PARAM;
3879
3880         i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_update_tag);
3881
3882         cmd->seid = CPU_TO_LE16(vsi_seid);
3883         cmd->old_tag = CPU_TO_LE16(old_tag);
3884         cmd->new_tag = CPU_TO_LE16(new_tag);
3885
3886         status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
3887
3888         if (!status) {
3889                 if (tags_used != NULL)
3890                         *tags_used = LE16_TO_CPU(resp->tags_used);
3891                 if (tags_free != NULL)
3892                         *tags_free = LE16_TO_CPU(resp->tags_free);
3893         }
3894
3895         return status;
3896 }
3897
3898 /**
3899  * i40e_aq_dcb_ignore_pfc - Ignore PFC for given TCs
3900  * @hw: pointer to the hw struct
3901  * @tcmap: TC map for request/release any ignore PFC condition
3902  * @request: request or release ignore PFC condition
3903  * @tcmap_ret: return TCs for which PFC is currently ignored
3904  * @cmd_details: pointer to command details structure or NULL
3905  *
3906  * This sends out request/release to ignore PFC condition for a TC.
3907  * It will return the TCs for which PFC is currently ignored.
3908  **/
3909 enum i40e_status_code i40e_aq_dcb_ignore_pfc(struct i40e_hw *hw, u8 tcmap,
3910                                 bool request, u8 *tcmap_ret,
3911                                 struct i40e_asq_cmd_details *cmd_details)
3912 {
3913         struct i40e_aq_desc desc;
3914         struct i40e_aqc_pfc_ignore *cmd_resp =
3915                 (struct i40e_aqc_pfc_ignore *)&desc.params.raw;
3916         enum i40e_status_code status;
3917
3918         i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_dcb_ignore_pfc);
3919
3920         if (request)
3921                 cmd_resp->command_flags = I40E_AQC_PFC_IGNORE_SET;
3922
3923         cmd_resp->tc_bitmap = tcmap;
3924
3925         status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
3926
3927         if (!status) {
3928                 if (tcmap_ret != NULL)
3929                         *tcmap_ret = cmd_resp->tc_bitmap;
3930         }
3931
3932         return status;
3933 }
3934
3935 /**
3936  * i40e_aq_dcb_updated - DCB Updated Command
3937  * @hw: pointer to the hw struct
3938  * @cmd_details: pointer to command details structure or NULL
3939  *
3940  * When LLDP is handled in PF this command is used by the PF
3941  * to notify EMP that a DCB setting is modified.
3942  * When LLDP is handled in EMP this command is used by the PF
3943  * to notify EMP whenever one of the following parameters get
3944  * modified:
3945  *   - PFCLinkDelayAllowance in PRTDCB_GENC.PFCLDA
3946  *   - PCIRTT in PRTDCB_GENC.PCIRTT
3947  *   - Maximum Frame Size for non-FCoE TCs set by PRTDCB_TDPUC.MAX_TXFRAME.
3948  * EMP will return when the shared RPB settings have been
3949  * recomputed and modified. The retval field in the descriptor
3950  * will be set to 0 when RPB is modified.
3951  **/
3952 enum i40e_status_code i40e_aq_dcb_updated(struct i40e_hw *hw,
3953                                 struct i40e_asq_cmd_details *cmd_details)
3954 {
3955         struct i40e_aq_desc desc;
3956         enum i40e_status_code status;
3957
3958         i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_dcb_updated);
3959
3960         status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
3961
3962         return status;
3963 }
3964
3965 /**
3966  * i40e_aq_add_statistics - Add a statistics block to a VLAN in a switch.
3967  * @hw: pointer to the hw struct
3968  * @seid: defines the SEID of the switch for which the stats are requested
3969  * @vlan_id: the VLAN ID for which the statistics are requested
3970  * @stat_index: index of the statistics counters block assigned to this VLAN
3971  * @cmd_details: pointer to command details structure or NULL
3972  *
3973  * XL710 supports 128 smonVlanStats counters.This command is used to
3974  * allocate a set of smonVlanStats counters to a specific VLAN in a specific
3975  * switch.
3976  **/
3977 enum i40e_status_code i40e_aq_add_statistics(struct i40e_hw *hw, u16 seid,
3978                                 u16 vlan_id, u16 *stat_index,
3979                                 struct i40e_asq_cmd_details *cmd_details)
3980 {
3981         struct i40e_aq_desc desc;
3982         struct i40e_aqc_add_remove_statistics *cmd_resp =
3983                 (struct i40e_aqc_add_remove_statistics *)&desc.params.raw;
3984         enum i40e_status_code status;
3985
3986         if ((seid == 0) || (stat_index == NULL))
3987                 return I40E_ERR_PARAM;
3988
3989         i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_add_statistics);
3990
3991         cmd_resp->seid = CPU_TO_LE16(seid);
3992         cmd_resp->vlan = CPU_TO_LE16(vlan_id);
3993
3994         status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
3995
3996         if (!status)
3997                 *stat_index = LE16_TO_CPU(cmd_resp->stat_index);
3998
3999         return status;
4000 }
4001
4002 /**
4003  * i40e_aq_remove_statistics - Remove a statistics block to a VLAN in a switch.
4004  * @hw: pointer to the hw struct
4005  * @seid: defines the SEID of the switch for which the stats are requested
4006  * @vlan_id: the VLAN ID for which the statistics are requested
4007  * @stat_index: index of the statistics counters block assigned to this VLAN
4008  * @cmd_details: pointer to command details structure or NULL
4009  *
4010  * XL710 supports 128 smonVlanStats counters.This command is used to
4011  * deallocate a set of smonVlanStats counters to a specific VLAN in a specific
4012  * switch.
4013  **/
4014 enum i40e_status_code i40e_aq_remove_statistics(struct i40e_hw *hw, u16 seid,
4015                                 u16 vlan_id, u16 stat_index,
4016                                 struct i40e_asq_cmd_details *cmd_details)
4017 {
4018         struct i40e_aq_desc desc;
4019         struct i40e_aqc_add_remove_statistics *cmd =
4020                 (struct i40e_aqc_add_remove_statistics *)&desc.params.raw;
4021         enum i40e_status_code status;
4022
4023         if (seid == 0)
4024                 return I40E_ERR_PARAM;
4025
4026         i40e_fill_default_direct_cmd_desc(&desc,
4027                                           i40e_aqc_opc_remove_statistics);
4028
4029         cmd->seid = CPU_TO_LE16(seid);
4030         cmd->vlan  = CPU_TO_LE16(vlan_id);
4031         cmd->stat_index = CPU_TO_LE16(stat_index);
4032
4033         status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
4034
4035         return status;
4036 }
4037
4038 /**
4039  * i40e_aq_set_port_parameters - set physical port parameters.
4040  * @hw: pointer to the hw struct
4041  * @bad_frame_vsi: defines the VSI to which bad frames are forwarded
4042  * @save_bad_pac: if set packets with errors are forwarded to the bad frames VSI
4043  * @pad_short_pac: if set transmit packets smaller than 60 bytes are padded
4044  * @double_vlan: if set double VLAN is enabled
4045  * @cmd_details: pointer to command details structure or NULL
4046  **/
4047 enum i40e_status_code i40e_aq_set_port_parameters(struct i40e_hw *hw,
4048                                 u16 bad_frame_vsi, bool save_bad_pac,
4049                                 bool pad_short_pac, bool double_vlan,
4050                                 struct i40e_asq_cmd_details *cmd_details)
4051 {
4052         struct i40e_aqc_set_port_parameters *cmd;
4053         enum i40e_status_code status;
4054         struct i40e_aq_desc desc;
4055         u16 command_flags = 0;
4056
4057         cmd = (struct i40e_aqc_set_port_parameters *)&desc.params.raw;
4058
4059         i40e_fill_default_direct_cmd_desc(&desc,
4060                                           i40e_aqc_opc_set_port_parameters);
4061
4062         cmd->bad_frame_vsi = CPU_TO_LE16(bad_frame_vsi);
4063         if (save_bad_pac)
4064                 command_flags |= I40E_AQ_SET_P_PARAMS_SAVE_BAD_PACKETS;
4065         if (pad_short_pac)
4066                 command_flags |= I40E_AQ_SET_P_PARAMS_PAD_SHORT_PACKETS;
4067         if (double_vlan)
4068                 command_flags |= I40E_AQ_SET_P_PARAMS_DOUBLE_VLAN_ENA;
4069         cmd->command_flags = CPU_TO_LE16(command_flags);
4070
4071         status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
4072
4073         return status;
4074 }
4075
4076 /**
4077  * i40e_aq_tx_sched_cmd - generic Tx scheduler AQ command handler
4078  * @hw: pointer to the hw struct
4079  * @seid: seid for the physical port/switching component/vsi
4080  * @buff: Indirect buffer to hold data parameters and response
4081  * @buff_size: Indirect buffer size
4082  * @opcode: Tx scheduler AQ command opcode
4083  * @cmd_details: pointer to command details structure or NULL
4084  *
4085  * Generic command handler for Tx scheduler AQ commands
4086  **/
4087 static enum i40e_status_code i40e_aq_tx_sched_cmd(struct i40e_hw *hw, u16 seid,
4088                                 void *buff, u16 buff_size,
4089                                  enum i40e_admin_queue_opc opcode,
4090                                 struct i40e_asq_cmd_details *cmd_details)
4091 {
4092         struct i40e_aq_desc desc;
4093         struct i40e_aqc_tx_sched_ind *cmd =
4094                 (struct i40e_aqc_tx_sched_ind *)&desc.params.raw;
4095         enum i40e_status_code status;
4096         bool cmd_param_flag = false;
4097
4098         switch (opcode) {
4099         case i40e_aqc_opc_configure_vsi_ets_sla_bw_limit:
4100         case i40e_aqc_opc_configure_vsi_tc_bw:
4101         case i40e_aqc_opc_enable_switching_comp_ets:
4102         case i40e_aqc_opc_modify_switching_comp_ets:
4103         case i40e_aqc_opc_disable_switching_comp_ets:
4104         case i40e_aqc_opc_configure_switching_comp_ets_bw_limit:
4105         case i40e_aqc_opc_configure_switching_comp_bw_config:
4106                 cmd_param_flag = true;
4107                 break;
4108         case i40e_aqc_opc_query_vsi_bw_config:
4109         case i40e_aqc_opc_query_vsi_ets_sla_config:
4110         case i40e_aqc_opc_query_switching_comp_ets_config:
4111         case i40e_aqc_opc_query_port_ets_config:
4112         case i40e_aqc_opc_query_switching_comp_bw_config:
4113                 cmd_param_flag = false;
4114                 break;
4115         default:
4116                 return I40E_ERR_PARAM;
4117         }
4118
4119         i40e_fill_default_direct_cmd_desc(&desc, opcode);
4120
4121         /* Indirect command */
4122         desc.flags |= CPU_TO_LE16((u16)I40E_AQ_FLAG_BUF);
4123         if (cmd_param_flag)
4124                 desc.flags |= CPU_TO_LE16((u16)I40E_AQ_FLAG_RD);
4125         if (buff_size > I40E_AQ_LARGE_BUF)
4126                 desc.flags |= CPU_TO_LE16((u16)I40E_AQ_FLAG_LB);
4127
4128         desc.datalen = CPU_TO_LE16(buff_size);
4129
4130         cmd->vsi_seid = CPU_TO_LE16(seid);
4131
4132         status = i40e_asq_send_command(hw, &desc, buff, buff_size, cmd_details);
4133
4134         return status;
4135 }
4136
4137 /**
4138  * i40e_aq_config_vsi_bw_limit - Configure VSI BW Limit
4139  * @hw: pointer to the hw struct
4140  * @seid: VSI seid
4141  * @credit: BW limit credits (0 = disabled)
4142  * @max_credit: Max BW limit credits
4143  * @cmd_details: pointer to command details structure or NULL
4144  **/
4145 enum i40e_status_code i40e_aq_config_vsi_bw_limit(struct i40e_hw *hw,
4146                                 u16 seid, u16 credit, u8 max_credit,
4147                                 struct i40e_asq_cmd_details *cmd_details)
4148 {
4149         struct i40e_aq_desc desc;
4150         struct i40e_aqc_configure_vsi_bw_limit *cmd =
4151                 (struct i40e_aqc_configure_vsi_bw_limit *)&desc.params.raw;
4152         enum i40e_status_code status;
4153
4154         i40e_fill_default_direct_cmd_desc(&desc,
4155                                           i40e_aqc_opc_configure_vsi_bw_limit);
4156
4157         cmd->vsi_seid = CPU_TO_LE16(seid);
4158         cmd->credit = CPU_TO_LE16(credit);
4159         cmd->max_credit = max_credit;
4160
4161         status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
4162
4163         return status;
4164 }
4165
4166 /**
4167  * i40e_aq_config_switch_comp_bw_limit - Configure Switching component BW Limit
4168  * @hw: pointer to the hw struct
4169  * @seid: switching component seid
4170  * @credit: BW limit credits (0 = disabled)
4171  * @max_bw: Max BW limit credits
4172  * @cmd_details: pointer to command details structure or NULL
4173  **/
4174 enum i40e_status_code i40e_aq_config_switch_comp_bw_limit(struct i40e_hw *hw,
4175                                 u16 seid, u16 credit, u8 max_bw,
4176                                 struct i40e_asq_cmd_details *cmd_details)
4177 {
4178         struct i40e_aq_desc desc;
4179         struct i40e_aqc_configure_switching_comp_bw_limit *cmd =
4180           (struct i40e_aqc_configure_switching_comp_bw_limit *)&desc.params.raw;
4181         enum i40e_status_code status;
4182
4183         i40e_fill_default_direct_cmd_desc(&desc,
4184                                 i40e_aqc_opc_configure_switching_comp_bw_limit);
4185
4186         cmd->seid = CPU_TO_LE16(seid);
4187         cmd->credit = CPU_TO_LE16(credit);
4188         cmd->max_bw = max_bw;
4189
4190         status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
4191
4192         return status;
4193 }
4194
4195 /**
4196  * i40e_aq_config_vsi_ets_sla_bw_limit - Config VSI BW Limit per TC
4197  * @hw: pointer to the hw struct
4198  * @seid: VSI seid
4199  * @bw_data: Buffer holding enabled TCs, per TC BW limit/credits
4200  * @cmd_details: pointer to command details structure or NULL
4201  **/
4202 enum i40e_status_code i40e_aq_config_vsi_ets_sla_bw_limit(struct i40e_hw *hw,
4203                         u16 seid,
4204                         struct i40e_aqc_configure_vsi_ets_sla_bw_data *bw_data,
4205                         struct i40e_asq_cmd_details *cmd_details)
4206 {
4207         return i40e_aq_tx_sched_cmd(hw, seid, (void *)bw_data, sizeof(*bw_data),
4208                                     i40e_aqc_opc_configure_vsi_ets_sla_bw_limit,
4209                                     cmd_details);
4210 }
4211
4212 /**
4213  * i40e_aq_config_vsi_tc_bw - Config VSI BW Allocation per TC
4214  * @hw: pointer to the hw struct
4215  * @seid: VSI seid
4216  * @bw_data: Buffer holding enabled TCs, relative TC BW limit/credits
4217  * @cmd_details: pointer to command details structure or NULL
4218  **/
4219 enum i40e_status_code i40e_aq_config_vsi_tc_bw(struct i40e_hw *hw,
4220                         u16 seid,
4221                         struct i40e_aqc_configure_vsi_tc_bw_data *bw_data,
4222                         struct i40e_asq_cmd_details *cmd_details)
4223 {
4224         return i40e_aq_tx_sched_cmd(hw, seid, (void *)bw_data, sizeof(*bw_data),
4225                                     i40e_aqc_opc_configure_vsi_tc_bw,
4226                                     cmd_details);
4227 }
4228
4229 /**
4230  * i40e_aq_config_switch_comp_ets_bw_limit - Config Switch comp BW Limit per TC
4231  * @hw: pointer to the hw struct
4232  * @seid: seid of the switching component
4233  * @bw_data: Buffer holding enabled TCs, per TC BW limit/credits
4234  * @cmd_details: pointer to command details structure or NULL
4235  **/
4236 enum i40e_status_code i40e_aq_config_switch_comp_ets_bw_limit(
4237         struct i40e_hw *hw, u16 seid,
4238         struct i40e_aqc_configure_switching_comp_ets_bw_limit_data *bw_data,
4239         struct i40e_asq_cmd_details *cmd_details)
4240 {
4241         return i40e_aq_tx_sched_cmd(hw, seid, (void *)bw_data, sizeof(*bw_data),
4242                             i40e_aqc_opc_configure_switching_comp_ets_bw_limit,
4243                             cmd_details);
4244 }
4245
4246 /**
4247  * i40e_aq_query_vsi_bw_config - Query VSI BW configuration
4248  * @hw: pointer to the hw struct
4249  * @seid: seid of the VSI
4250  * @bw_data: Buffer to hold VSI BW configuration
4251  * @cmd_details: pointer to command details structure or NULL
4252  **/
4253 enum i40e_status_code i40e_aq_query_vsi_bw_config(struct i40e_hw *hw,
4254                         u16 seid,
4255                         struct i40e_aqc_query_vsi_bw_config_resp *bw_data,
4256                         struct i40e_asq_cmd_details *cmd_details)
4257 {
4258         return i40e_aq_tx_sched_cmd(hw, seid, (void *)bw_data, sizeof(*bw_data),
4259                                     i40e_aqc_opc_query_vsi_bw_config,
4260                                     cmd_details);
4261 }
4262
4263 /**
4264  * i40e_aq_query_vsi_ets_sla_config - Query VSI BW configuration per TC
4265  * @hw: pointer to the hw struct
4266  * @seid: seid of the VSI
4267  * @bw_data: Buffer to hold VSI BW configuration per TC
4268  * @cmd_details: pointer to command details structure or NULL
4269  **/
4270 enum i40e_status_code i40e_aq_query_vsi_ets_sla_config(struct i40e_hw *hw,
4271                         u16 seid,
4272                         struct i40e_aqc_query_vsi_ets_sla_config_resp *bw_data,
4273                         struct i40e_asq_cmd_details *cmd_details)
4274 {
4275         return i40e_aq_tx_sched_cmd(hw, seid, (void *)bw_data, sizeof(*bw_data),
4276                                     i40e_aqc_opc_query_vsi_ets_sla_config,
4277                                     cmd_details);
4278 }
4279
4280 /**
4281  * i40e_aq_query_switch_comp_ets_config - Query Switch comp BW config per TC
4282  * @hw: pointer to the hw struct
4283  * @seid: seid of the switching component
4284  * @bw_data: Buffer to hold switching component's per TC BW config
4285  * @cmd_details: pointer to command details structure or NULL
4286  **/
4287 enum i40e_status_code i40e_aq_query_switch_comp_ets_config(struct i40e_hw *hw,
4288                 u16 seid,
4289                 struct i40e_aqc_query_switching_comp_ets_config_resp *bw_data,
4290                 struct i40e_asq_cmd_details *cmd_details)
4291 {
4292         return i40e_aq_tx_sched_cmd(hw, seid, (void *)bw_data, sizeof(*bw_data),
4293                                    i40e_aqc_opc_query_switching_comp_ets_config,
4294                                    cmd_details);
4295 }
4296
4297 /**
4298  * i40e_aq_query_port_ets_config - Query Physical Port ETS configuration
4299  * @hw: pointer to the hw struct
4300  * @seid: seid of the VSI or switching component connected to Physical Port
4301  * @bw_data: Buffer to hold current ETS configuration for the Physical Port
4302  * @cmd_details: pointer to command details structure or NULL
4303  **/
4304 enum i40e_status_code i40e_aq_query_port_ets_config(struct i40e_hw *hw,
4305                         u16 seid,
4306                         struct i40e_aqc_query_port_ets_config_resp *bw_data,
4307                         struct i40e_asq_cmd_details *cmd_details)
4308 {
4309         return i40e_aq_tx_sched_cmd(hw, seid, (void *)bw_data, sizeof(*bw_data),
4310                                     i40e_aqc_opc_query_port_ets_config,
4311                                     cmd_details);
4312 }
4313
4314 /**
4315  * i40e_aq_query_switch_comp_bw_config - Query Switch comp BW configuration
4316  * @hw: pointer to the hw struct
4317  * @seid: seid of the switching component
4318  * @bw_data: Buffer to hold switching component's BW configuration
4319  * @cmd_details: pointer to command details structure or NULL
4320  **/
4321 enum i40e_status_code i40e_aq_query_switch_comp_bw_config(struct i40e_hw *hw,
4322                 u16 seid,
4323                 struct i40e_aqc_query_switching_comp_bw_config_resp *bw_data,
4324                 struct i40e_asq_cmd_details *cmd_details)
4325 {
4326         return i40e_aq_tx_sched_cmd(hw, seid, (void *)bw_data, sizeof(*bw_data),
4327                                     i40e_aqc_opc_query_switching_comp_bw_config,
4328                                     cmd_details);
4329 }
4330
4331 /**
4332  * i40e_validate_filter_settings
4333  * @hw: pointer to the hardware structure
4334  * @settings: Filter control settings
4335  *
4336  * Check and validate the filter control settings passed.
4337  * The function checks for the valid filter/context sizes being
4338  * passed for FCoE and PE.
4339  *
4340  * Returns I40E_SUCCESS if the values passed are valid and within
4341  * range else returns an error.
4342  **/
4343 STATIC enum i40e_status_code i40e_validate_filter_settings(struct i40e_hw *hw,
4344                                 struct i40e_filter_control_settings *settings)
4345 {
4346         u32 fcoe_cntx_size, fcoe_filt_size;
4347         u32 pe_cntx_size, pe_filt_size;
4348         u32 fcoe_fmax;
4349
4350         u32 val;
4351
4352         /* Validate FCoE settings passed */
4353         switch (settings->fcoe_filt_num) {
4354         case I40E_HASH_FILTER_SIZE_1K:
4355         case I40E_HASH_FILTER_SIZE_2K:
4356         case I40E_HASH_FILTER_SIZE_4K:
4357         case I40E_HASH_FILTER_SIZE_8K:
4358         case I40E_HASH_FILTER_SIZE_16K:
4359         case I40E_HASH_FILTER_SIZE_32K:
4360                 fcoe_filt_size = I40E_HASH_FILTER_BASE_SIZE;
4361                 fcoe_filt_size <<= (u32)settings->fcoe_filt_num;
4362                 break;
4363         default:
4364                 return I40E_ERR_PARAM;
4365         }
4366
4367         switch (settings->fcoe_cntx_num) {
4368         case I40E_DMA_CNTX_SIZE_512:
4369         case I40E_DMA_CNTX_SIZE_1K:
4370         case I40E_DMA_CNTX_SIZE_2K:
4371         case I40E_DMA_CNTX_SIZE_4K:
4372                 fcoe_cntx_size = I40E_DMA_CNTX_BASE_SIZE;
4373                 fcoe_cntx_size <<= (u32)settings->fcoe_cntx_num;
4374                 break;
4375         default:
4376                 return I40E_ERR_PARAM;
4377         }
4378
4379         /* Validate PE settings passed */
4380         switch (settings->pe_filt_num) {
4381         case I40E_HASH_FILTER_SIZE_1K:
4382         case I40E_HASH_FILTER_SIZE_2K:
4383         case I40E_HASH_FILTER_SIZE_4K:
4384         case I40E_HASH_FILTER_SIZE_8K:
4385         case I40E_HASH_FILTER_SIZE_16K:
4386         case I40E_HASH_FILTER_SIZE_32K:
4387         case I40E_HASH_FILTER_SIZE_64K:
4388         case I40E_HASH_FILTER_SIZE_128K:
4389         case I40E_HASH_FILTER_SIZE_256K:
4390         case I40E_HASH_FILTER_SIZE_512K:
4391         case I40E_HASH_FILTER_SIZE_1M:
4392                 pe_filt_size = I40E_HASH_FILTER_BASE_SIZE;
4393                 pe_filt_size <<= (u32)settings->pe_filt_num;
4394                 break;
4395         default:
4396                 return I40E_ERR_PARAM;
4397         }
4398
4399         switch (settings->pe_cntx_num) {
4400         case I40E_DMA_CNTX_SIZE_512:
4401         case I40E_DMA_CNTX_SIZE_1K:
4402         case I40E_DMA_CNTX_SIZE_2K:
4403         case I40E_DMA_CNTX_SIZE_4K:
4404         case I40E_DMA_CNTX_SIZE_8K:
4405         case I40E_DMA_CNTX_SIZE_16K:
4406         case I40E_DMA_CNTX_SIZE_32K:
4407         case I40E_DMA_CNTX_SIZE_64K:
4408         case I40E_DMA_CNTX_SIZE_128K:
4409         case I40E_DMA_CNTX_SIZE_256K:
4410                 pe_cntx_size = I40E_DMA_CNTX_BASE_SIZE;
4411                 pe_cntx_size <<= (u32)settings->pe_cntx_num;
4412                 break;
4413         default:
4414                 return I40E_ERR_PARAM;
4415         }
4416
4417         /* FCHSIZE + FCDSIZE should not be greater than PMFCOEFMAX */
4418         val = rd32(hw, I40E_GLHMC_FCOEFMAX);
4419         fcoe_fmax = (val & I40E_GLHMC_FCOEFMAX_PMFCOEFMAX_MASK)
4420                      >> I40E_GLHMC_FCOEFMAX_PMFCOEFMAX_SHIFT;
4421         if (fcoe_filt_size + fcoe_cntx_size >  fcoe_fmax)
4422                 return I40E_ERR_INVALID_SIZE;
4423
4424         return I40E_SUCCESS;
4425 }
4426
4427 /**
4428  * i40e_set_filter_control
4429  * @hw: pointer to the hardware structure
4430  * @settings: Filter control settings
4431  *
4432  * Set the Queue Filters for PE/FCoE and enable filters required
4433  * for a single PF. It is expected that these settings are programmed
4434  * at the driver initialization time.
4435  **/
4436 enum i40e_status_code i40e_set_filter_control(struct i40e_hw *hw,
4437                                 struct i40e_filter_control_settings *settings)
4438 {
4439         enum i40e_status_code ret = I40E_SUCCESS;
4440         u32 hash_lut_size = 0;
4441         u32 val;
4442
4443         if (!settings)
4444                 return I40E_ERR_PARAM;
4445
4446         /* Validate the input settings */
4447         ret = i40e_validate_filter_settings(hw, settings);
4448         if (ret)
4449                 return ret;
4450
4451         /* Read the PF Queue Filter control register */
4452         val = rd32(hw, I40E_PFQF_CTL_0);
4453
4454         /* Program required PE hash buckets for the PF */
4455         val &= ~I40E_PFQF_CTL_0_PEHSIZE_MASK;
4456         val |= ((u32)settings->pe_filt_num << I40E_PFQF_CTL_0_PEHSIZE_SHIFT) &
4457                 I40E_PFQF_CTL_0_PEHSIZE_MASK;
4458         /* Program required PE contexts for the PF */
4459         val &= ~I40E_PFQF_CTL_0_PEDSIZE_MASK;
4460         val |= ((u32)settings->pe_cntx_num << I40E_PFQF_CTL_0_PEDSIZE_SHIFT) &
4461                 I40E_PFQF_CTL_0_PEDSIZE_MASK;
4462
4463         /* Program required FCoE hash buckets for the PF */
4464         val &= ~I40E_PFQF_CTL_0_PFFCHSIZE_MASK;
4465         val |= ((u32)settings->fcoe_filt_num <<
4466                         I40E_PFQF_CTL_0_PFFCHSIZE_SHIFT) &
4467                 I40E_PFQF_CTL_0_PFFCHSIZE_MASK;
4468         /* Program required FCoE DDP contexts for the PF */
4469         val &= ~I40E_PFQF_CTL_0_PFFCDSIZE_MASK;
4470         val |= ((u32)settings->fcoe_cntx_num <<
4471                         I40E_PFQF_CTL_0_PFFCDSIZE_SHIFT) &
4472                 I40E_PFQF_CTL_0_PFFCDSIZE_MASK;
4473
4474         /* Program Hash LUT size for the PF */
4475         val &= ~I40E_PFQF_CTL_0_HASHLUTSIZE_MASK;
4476         if (settings->hash_lut_size == I40E_HASH_LUT_SIZE_512)
4477                 hash_lut_size = 1;
4478         val |= (hash_lut_size << I40E_PFQF_CTL_0_HASHLUTSIZE_SHIFT) &
4479                 I40E_PFQF_CTL_0_HASHLUTSIZE_MASK;
4480
4481         /* Enable FDIR, Ethertype and MACVLAN filters for PF and VFs */
4482         if (settings->enable_fdir)
4483                 val |= I40E_PFQF_CTL_0_FD_ENA_MASK;
4484         if (settings->enable_ethtype)
4485                 val |= I40E_PFQF_CTL_0_ETYPE_ENA_MASK;
4486         if (settings->enable_macvlan)
4487                 val |= I40E_PFQF_CTL_0_MACVLAN_ENA_MASK;
4488
4489         wr32(hw, I40E_PFQF_CTL_0, val);
4490
4491         return I40E_SUCCESS;
4492 }
4493
4494 /**
4495  * i40e_aq_add_rem_control_packet_filter - Add or Remove Control Packet Filter
4496  * @hw: pointer to the hw struct
4497  * @mac_addr: MAC address to use in the filter
4498  * @ethtype: Ethertype to use in the filter
4499  * @flags: Flags that needs to be applied to the filter
4500  * @vsi_seid: seid of the control VSI
4501  * @queue: VSI queue number to send the packet to
4502  * @is_add: Add control packet filter if True else remove
4503  * @stats: Structure to hold information on control filter counts
4504  * @cmd_details: pointer to command details structure or NULL
4505  *
4506  * This command will Add or Remove control packet filter for a control VSI.
4507  * In return it will update the total number of perfect filter count in
4508  * the stats member.
4509  **/
4510 enum i40e_status_code i40e_aq_add_rem_control_packet_filter(struct i40e_hw *hw,
4511                                 u8 *mac_addr, u16 ethtype, u16 flags,
4512                                 u16 vsi_seid, u16 queue, bool is_add,
4513                                 struct i40e_control_filter_stats *stats,
4514                                 struct i40e_asq_cmd_details *cmd_details)
4515 {
4516         struct i40e_aq_desc desc;
4517         struct i40e_aqc_add_remove_control_packet_filter *cmd =
4518                 (struct i40e_aqc_add_remove_control_packet_filter *)
4519                 &desc.params.raw;
4520         struct i40e_aqc_add_remove_control_packet_filter_completion *resp =
4521                 (struct i40e_aqc_add_remove_control_packet_filter_completion *)
4522                 &desc.params.raw;
4523         enum i40e_status_code status;
4524
4525         if (vsi_seid == 0)
4526                 return I40E_ERR_PARAM;
4527
4528         if (is_add) {
4529                 i40e_fill_default_direct_cmd_desc(&desc,
4530                                 i40e_aqc_opc_add_control_packet_filter);
4531                 cmd->queue = CPU_TO_LE16(queue);
4532         } else {
4533                 i40e_fill_default_direct_cmd_desc(&desc,
4534                                 i40e_aqc_opc_remove_control_packet_filter);
4535         }
4536
4537         if (mac_addr)
4538                 i40e_memcpy(cmd->mac, mac_addr, I40E_ETH_LENGTH_OF_ADDRESS,
4539                             I40E_NONDMA_TO_NONDMA);
4540
4541         cmd->etype = CPU_TO_LE16(ethtype);
4542         cmd->flags = CPU_TO_LE16(flags);
4543         cmd->seid = CPU_TO_LE16(vsi_seid);
4544
4545         status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
4546
4547         if (!status && stats) {
4548                 stats->mac_etype_used = LE16_TO_CPU(resp->mac_etype_used);
4549                 stats->etype_used = LE16_TO_CPU(resp->etype_used);
4550                 stats->mac_etype_free = LE16_TO_CPU(resp->mac_etype_free);
4551                 stats->etype_free = LE16_TO_CPU(resp->etype_free);
4552         }
4553
4554         return status;
4555 }
4556
4557 /**
4558  * i40e_aq_add_cloud_filters
4559  * @hw: pointer to the hardware structure
4560  * @seid: VSI seid to add cloud filters from
4561  * @filters: Buffer which contains the filters to be added
4562  * @filter_count: number of filters contained in the buffer
4563  *
4564  * Set the cloud filters for a given VSI.  The contents of the
4565  * i40e_aqc_add_remove_cloud_filters_element_data are filled
4566  * in by the caller of the function.
4567  *
4568  **/
4569 enum i40e_status_code i40e_aq_add_cloud_filters(struct i40e_hw *hw,
4570         u16 seid,
4571         struct i40e_aqc_add_remove_cloud_filters_element_data *filters,
4572         u8 filter_count)
4573 {
4574         struct i40e_aq_desc desc;
4575         struct i40e_aqc_add_remove_cloud_filters *cmd =
4576         (struct i40e_aqc_add_remove_cloud_filters *)&desc.params.raw;
4577         u16 buff_len;
4578         enum i40e_status_code status;
4579
4580         i40e_fill_default_direct_cmd_desc(&desc,
4581                                           i40e_aqc_opc_add_cloud_filters);
4582
4583         buff_len = sizeof(struct i40e_aqc_add_remove_cloud_filters_element_data) *
4584                           filter_count;
4585         desc.datalen = CPU_TO_LE16(buff_len);
4586         desc.flags |= CPU_TO_LE16((u16)(I40E_AQ_FLAG_BUF | I40E_AQ_FLAG_RD));
4587         cmd->num_filters = filter_count;
4588         cmd->seid = CPU_TO_LE16(seid);
4589
4590         status = i40e_asq_send_command(hw, &desc, filters, buff_len, NULL);
4591
4592         return status;
4593 }
4594
4595 /**
4596  * i40e_aq_remove_cloud_filters
4597  * @hw: pointer to the hardware structure
4598  * @seid: VSI seid to remove cloud filters from
4599  * @filters: Buffer which contains the filters to be removed
4600  * @filter_count: number of filters contained in the buffer
4601  *
4602  * Remove the cloud filters for a given VSI.  The contents of the
4603  * i40e_aqc_add_remove_cloud_filters_element_data are filled
4604  * in by the caller of the function.
4605  *
4606  **/
4607 enum i40e_status_code i40e_aq_remove_cloud_filters(struct i40e_hw *hw,
4608                 u16 seid,
4609                 struct i40e_aqc_add_remove_cloud_filters_element_data *filters,
4610                 u8 filter_count)
4611 {
4612         struct i40e_aq_desc desc;
4613         struct i40e_aqc_add_remove_cloud_filters *cmd =
4614         (struct i40e_aqc_add_remove_cloud_filters *)&desc.params.raw;
4615         enum i40e_status_code status;
4616         u16 buff_len;
4617
4618         i40e_fill_default_direct_cmd_desc(&desc,
4619                                           i40e_aqc_opc_remove_cloud_filters);
4620
4621         buff_len = sizeof(struct i40e_aqc_add_remove_cloud_filters_element_data) *
4622                 filter_count;
4623         desc.datalen = CPU_TO_LE16(buff_len);
4624         desc.flags |= CPU_TO_LE16((u16)(I40E_AQ_FLAG_BUF | I40E_AQ_FLAG_RD));
4625         cmd->num_filters = filter_count;
4626         cmd->seid = CPU_TO_LE16(seid);
4627
4628         status = i40e_asq_send_command(hw, &desc, filters, buff_len, NULL);
4629
4630         return status;
4631 }
4632
4633 /**
4634  * i40e_aq_alternate_write
4635  * @hw: pointer to the hardware structure
4636  * @reg_addr0: address of first dword to be read
4637  * @reg_val0: value to be written under 'reg_addr0'
4638  * @reg_addr1: address of second dword to be read
4639  * @reg_val1: value to be written under 'reg_addr1'
4640  *
4641  * Write one or two dwords to alternate structure. Fields are indicated
4642  * by 'reg_addr0' and 'reg_addr1' register numbers.
4643  *
4644  **/
4645 enum i40e_status_code i40e_aq_alternate_write(struct i40e_hw *hw,
4646                                 u32 reg_addr0, u32 reg_val0,
4647                                 u32 reg_addr1, u32 reg_val1)
4648 {
4649         struct i40e_aq_desc desc;
4650         struct i40e_aqc_alternate_write *cmd_resp =
4651                 (struct i40e_aqc_alternate_write *)&desc.params.raw;
4652         enum i40e_status_code status;
4653
4654         i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_alternate_write);
4655         cmd_resp->address0 = CPU_TO_LE32(reg_addr0);
4656         cmd_resp->address1 = CPU_TO_LE32(reg_addr1);
4657         cmd_resp->data0 = CPU_TO_LE32(reg_val0);
4658         cmd_resp->data1 = CPU_TO_LE32(reg_val1);
4659
4660         status = i40e_asq_send_command(hw, &desc, NULL, 0, NULL);
4661
4662         return status;
4663 }
4664
4665 /**
4666  * i40e_aq_alternate_write_indirect
4667  * @hw: pointer to the hardware structure
4668  * @addr: address of a first register to be modified
4669  * @dw_count: number of alternate structure fields to write
4670  * @buffer: pointer to the command buffer
4671  *
4672  * Write 'dw_count' dwords from 'buffer' to alternate structure
4673  * starting at 'addr'.
4674  *
4675  **/
4676 enum i40e_status_code i40e_aq_alternate_write_indirect(struct i40e_hw *hw,
4677                                 u32 addr, u32 dw_count, void *buffer)
4678 {
4679         struct i40e_aq_desc desc;
4680         struct i40e_aqc_alternate_ind_write *cmd_resp =
4681                 (struct i40e_aqc_alternate_ind_write *)&desc.params.raw;
4682         enum i40e_status_code status;
4683
4684         if (buffer == NULL)
4685                 return I40E_ERR_PARAM;
4686
4687         /* Indirect command */
4688         i40e_fill_default_direct_cmd_desc(&desc,
4689                                          i40e_aqc_opc_alternate_write_indirect);
4690
4691         desc.flags |= CPU_TO_LE16(I40E_AQ_FLAG_RD);
4692         desc.flags |= CPU_TO_LE16(I40E_AQ_FLAG_BUF);
4693         if (dw_count > (I40E_AQ_LARGE_BUF/4))
4694                 desc.flags |= CPU_TO_LE16((u16)I40E_AQ_FLAG_LB);
4695
4696         cmd_resp->address = CPU_TO_LE32(addr);
4697         cmd_resp->length = CPU_TO_LE32(dw_count);
4698         cmd_resp->addr_high = CPU_TO_LE32(I40E_HI_WORD((u64)buffer));
4699         cmd_resp->addr_low = CPU_TO_LE32(I40E_LO_DWORD((u64)buffer));
4700
4701         status = i40e_asq_send_command(hw, &desc, buffer,
4702                                        I40E_LO_DWORD(4*dw_count), NULL);
4703
4704         return status;
4705 }
4706
4707 /**
4708  * i40e_aq_alternate_read
4709  * @hw: pointer to the hardware structure
4710  * @reg_addr0: address of first dword to be read
4711  * @reg_val0: pointer for data read from 'reg_addr0'
4712  * @reg_addr1: address of second dword to be read
4713  * @reg_val1: pointer for data read from 'reg_addr1'
4714  *
4715  * Read one or two dwords from alternate structure. Fields are indicated
4716  * by 'reg_addr0' and 'reg_addr1' register numbers. If 'reg_val1' pointer
4717  * is not passed then only register at 'reg_addr0' is read.
4718  *
4719  **/
4720 enum i40e_status_code i40e_aq_alternate_read(struct i40e_hw *hw,
4721                                 u32 reg_addr0, u32 *reg_val0,
4722                                 u32 reg_addr1, u32 *reg_val1)
4723 {
4724         struct i40e_aq_desc desc;
4725         struct i40e_aqc_alternate_write *cmd_resp =
4726                 (struct i40e_aqc_alternate_write *)&desc.params.raw;
4727         enum i40e_status_code status;
4728
4729         if (reg_val0 == NULL)
4730                 return I40E_ERR_PARAM;
4731
4732         i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_alternate_read);
4733         cmd_resp->address0 = CPU_TO_LE32(reg_addr0);
4734         cmd_resp->address1 = CPU_TO_LE32(reg_addr1);
4735
4736         status = i40e_asq_send_command(hw, &desc, NULL, 0, NULL);
4737
4738         if (status == I40E_SUCCESS) {
4739                 *reg_val0 = LE32_TO_CPU(cmd_resp->data0);
4740
4741                 if (reg_val1 != NULL)
4742                         *reg_val1 = LE32_TO_CPU(cmd_resp->data1);
4743         }
4744
4745         return status;
4746 }
4747
4748 /**
4749  * i40e_aq_alternate_read_indirect
4750  * @hw: pointer to the hardware structure
4751  * @addr: address of the alternate structure field
4752  * @dw_count: number of alternate structure fields to read
4753  * @buffer: pointer to the command buffer
4754  *
4755  * Read 'dw_count' dwords from alternate structure starting at 'addr' and
4756  * place them in 'buffer'. The buffer should be allocated by caller.
4757  *
4758  **/
4759 enum i40e_status_code i40e_aq_alternate_read_indirect(struct i40e_hw *hw,
4760                                 u32 addr, u32 dw_count, void *buffer)
4761 {
4762         struct i40e_aq_desc desc;
4763         struct i40e_aqc_alternate_ind_write *cmd_resp =
4764                 (struct i40e_aqc_alternate_ind_write *)&desc.params.raw;
4765         enum i40e_status_code status;
4766
4767         if (buffer == NULL)
4768                 return I40E_ERR_PARAM;
4769
4770         /* Indirect command */
4771         i40e_fill_default_direct_cmd_desc(&desc,
4772                 i40e_aqc_opc_alternate_read_indirect);
4773
4774         desc.flags |= CPU_TO_LE16(I40E_AQ_FLAG_RD);
4775         desc.flags |= CPU_TO_LE16(I40E_AQ_FLAG_BUF);
4776         if (dw_count > (I40E_AQ_LARGE_BUF/4))
4777                 desc.flags |= CPU_TO_LE16((u16)I40E_AQ_FLAG_LB);
4778
4779         cmd_resp->address = CPU_TO_LE32(addr);
4780         cmd_resp->length = CPU_TO_LE32(dw_count);
4781         cmd_resp->addr_high = CPU_TO_LE32(I40E_HI_DWORD((u64)buffer));
4782         cmd_resp->addr_low = CPU_TO_LE32(I40E_LO_DWORD((u64)buffer));
4783
4784         status = i40e_asq_send_command(hw, &desc, buffer,
4785                                        I40E_LO_DWORD(4*dw_count), NULL);
4786
4787         return status;
4788 }
4789
4790 /**
4791  *  i40e_aq_alternate_clear
4792  *  @hw: pointer to the HW structure.
4793  *
4794  *  Clear the alternate structures of the port from which the function
4795  *  is called.
4796  *
4797  **/
4798 enum i40e_status_code i40e_aq_alternate_clear(struct i40e_hw *hw)
4799 {
4800         struct i40e_aq_desc desc;
4801         enum i40e_status_code status;
4802
4803         i40e_fill_default_direct_cmd_desc(&desc,
4804                                           i40e_aqc_opc_alternate_clear_port);
4805
4806         status = i40e_asq_send_command(hw, &desc, NULL, 0, NULL);
4807
4808         return status;
4809 }
4810
4811 /**
4812  *  i40e_aq_alternate_write_done
4813  *  @hw: pointer to the HW structure.
4814  *  @bios_mode: indicates whether the command is executed by UEFI or legacy BIOS
4815  *  @reset_needed: indicates the SW should trigger GLOBAL reset
4816  *
4817  *  Indicates to the FW that alternate structures have been changed.
4818  *
4819  **/
4820 enum i40e_status_code i40e_aq_alternate_write_done(struct i40e_hw *hw,
4821                 u8 bios_mode, bool *reset_needed)
4822 {
4823         struct i40e_aq_desc desc;
4824         struct i40e_aqc_alternate_write_done *cmd =
4825                 (struct i40e_aqc_alternate_write_done *)&desc.params.raw;
4826         enum i40e_status_code status;
4827
4828         if (reset_needed == NULL)
4829                 return I40E_ERR_PARAM;
4830
4831         i40e_fill_default_direct_cmd_desc(&desc,
4832                                           i40e_aqc_opc_alternate_write_done);
4833
4834         cmd->cmd_flags = CPU_TO_LE16(bios_mode);
4835
4836         status = i40e_asq_send_command(hw, &desc, NULL, 0, NULL);
4837         if (!status)
4838                 *reset_needed = ((LE16_TO_CPU(cmd->cmd_flags) &
4839                                  I40E_AQ_ALTERNATE_RESET_NEEDED) != 0);
4840
4841         return status;
4842 }
4843
4844 /**
4845  *  i40e_aq_set_oem_mode
4846  *  @hw: pointer to the HW structure.
4847  *  @oem_mode: the OEM mode to be used
4848  *
4849  *  Sets the device to a specific operating mode. Currently the only supported
4850  *  mode is no_clp, which causes FW to refrain from using Alternate RAM.
4851  *
4852  **/
4853 enum i40e_status_code i40e_aq_set_oem_mode(struct i40e_hw *hw,
4854                 u8 oem_mode)
4855 {
4856         struct i40e_aq_desc desc;
4857         struct i40e_aqc_alternate_write_done *cmd =
4858                 (struct i40e_aqc_alternate_write_done *)&desc.params.raw;
4859         enum i40e_status_code status;
4860
4861         i40e_fill_default_direct_cmd_desc(&desc,
4862                                           i40e_aqc_opc_alternate_set_mode);
4863
4864         cmd->cmd_flags = CPU_TO_LE16(oem_mode);
4865
4866         status = i40e_asq_send_command(hw, &desc, NULL, 0, NULL);
4867
4868         return status;
4869 }
4870
4871 /**
4872  * i40e_aq_resume_port_tx
4873  * @hw: pointer to the hardware structure
4874  * @cmd_details: pointer to command details structure or NULL
4875  *
4876  * Resume port's Tx traffic
4877  **/
4878 enum i40e_status_code i40e_aq_resume_port_tx(struct i40e_hw *hw,
4879                                 struct i40e_asq_cmd_details *cmd_details)
4880 {
4881         struct i40e_aq_desc desc;
4882         enum i40e_status_code status;
4883
4884         i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_resume_port_tx);
4885
4886         status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
4887
4888         return status;
4889 }
4890
4891 /**
4892  * i40e_set_pci_config_data - store PCI bus info
4893  * @hw: pointer to hardware structure
4894  * @link_status: the link status word from PCI config space
4895  *
4896  * Stores the PCI bus info (speed, width, type) within the i40e_hw structure
4897  **/
4898 void i40e_set_pci_config_data(struct i40e_hw *hw, u16 link_status)
4899 {
4900         hw->bus.type = i40e_bus_type_pci_express;
4901
4902         switch (link_status & I40E_PCI_LINK_WIDTH) {
4903         case I40E_PCI_LINK_WIDTH_1:
4904                 hw->bus.width = i40e_bus_width_pcie_x1;
4905                 break;
4906         case I40E_PCI_LINK_WIDTH_2:
4907                 hw->bus.width = i40e_bus_width_pcie_x2;
4908                 break;
4909         case I40E_PCI_LINK_WIDTH_4:
4910                 hw->bus.width = i40e_bus_width_pcie_x4;
4911                 break;
4912         case I40E_PCI_LINK_WIDTH_8:
4913                 hw->bus.width = i40e_bus_width_pcie_x8;
4914                 break;
4915         default:
4916                 hw->bus.width = i40e_bus_width_unknown;
4917                 break;
4918         }
4919
4920         switch (link_status & I40E_PCI_LINK_SPEED) {
4921         case I40E_PCI_LINK_SPEED_2500:
4922                 hw->bus.speed = i40e_bus_speed_2500;
4923                 break;
4924         case I40E_PCI_LINK_SPEED_5000:
4925                 hw->bus.speed = i40e_bus_speed_5000;
4926                 break;
4927         case I40E_PCI_LINK_SPEED_8000:
4928                 hw->bus.speed = i40e_bus_speed_8000;
4929                 break;
4930         default:
4931                 hw->bus.speed = i40e_bus_speed_unknown;
4932                 break;
4933         }
4934 }
4935
4936 /**
4937  * i40e_read_bw_from_alt_ram
4938  * @hw: pointer to the hardware structure
4939  * @max_bw: pointer for max_bw read
4940  * @min_bw: pointer for min_bw read
4941  * @min_valid: pointer for bool that is true if min_bw is a valid value
4942  * @max_valid: pointer for bool that is true if max_bw is a valid value
4943  *
4944  * Read bw from the alternate ram for the given pf
4945  **/
4946 enum i40e_status_code i40e_read_bw_from_alt_ram(struct i40e_hw *hw,
4947                                         u32 *max_bw, u32 *min_bw,
4948                                         bool *min_valid, bool *max_valid)
4949 {
4950         enum i40e_status_code status;
4951         u32 max_bw_addr, min_bw_addr;
4952
4953         /* Calculate the address of the min/max bw registers */
4954         max_bw_addr = I40E_ALT_STRUCT_FIRST_PF_OFFSET +
4955                 I40E_ALT_STRUCT_MAX_BW_OFFSET +
4956                 (I40E_ALT_STRUCT_DWORDS_PER_PF*hw->pf_id);
4957         min_bw_addr = I40E_ALT_STRUCT_FIRST_PF_OFFSET +
4958                 I40E_ALT_STRUCT_MIN_BW_OFFSET +
4959                 (I40E_ALT_STRUCT_DWORDS_PER_PF*hw->pf_id);
4960
4961         /* Read the bandwidths from alt ram */
4962         status = i40e_aq_alternate_read(hw, max_bw_addr, max_bw,
4963                                         min_bw_addr, min_bw);
4964
4965         if (*min_bw & I40E_ALT_BW_VALID_MASK)
4966                 *min_valid = true;
4967         else
4968                 *min_valid = false;
4969
4970         if (*max_bw & I40E_ALT_BW_VALID_MASK)
4971                 *max_valid = true;
4972         else
4973                 *max_valid = false;
4974
4975         return status;
4976 }
4977
4978 /**
4979  * i40e_aq_configure_partition_bw
4980  * @hw: pointer to the hardware structure
4981  * @bw_data: Buffer holding valid pfs and bw limits
4982  * @cmd_details: pointer to command details
4983  *
4984  * Configure partitions guaranteed/max bw
4985  **/
4986 enum i40e_status_code i40e_aq_configure_partition_bw(struct i40e_hw *hw,
4987                         struct i40e_aqc_configure_partition_bw_data *bw_data,
4988                         struct i40e_asq_cmd_details *cmd_details)
4989 {
4990         enum i40e_status_code status;
4991         struct i40e_aq_desc desc;
4992         u16 bwd_size = sizeof(struct i40e_aqc_configure_partition_bw_data);
4993
4994         i40e_fill_default_direct_cmd_desc(&desc,
4995                                 i40e_aqc_opc_configure_partition_bw);
4996
4997         /* Indirect command */
4998         desc.flags |= CPU_TO_LE16((u16)I40E_AQ_FLAG_BUF);
4999         desc.flags |= CPU_TO_LE16((u16)I40E_AQ_FLAG_RD);
5000
5001         if (bwd_size > I40E_AQ_LARGE_BUF)
5002                 desc.flags |= CPU_TO_LE16((u16)I40E_AQ_FLAG_LB);
5003
5004         desc.datalen = CPU_TO_LE16(bwd_size);
5005
5006         status = i40e_asq_send_command(hw, &desc, bw_data, bwd_size, cmd_details);
5007
5008         return status;
5009 }
5010 #endif /* PF_DRIVER */
5011 #ifdef VF_DRIVER
5012
5013 /**
5014  * i40e_aq_send_msg_to_pf
5015  * @hw: pointer to the hardware structure
5016  * @v_opcode: opcodes for VF-PF communication
5017  * @v_retval: return error code
5018  * @msg: pointer to the msg buffer
5019  * @msglen: msg length
5020  * @cmd_details: pointer to command details
5021  *
5022  * Send message to PF driver using admin queue. By default, this message
5023  * is sent asynchronously, i.e. i40e_asq_send_command() does not wait for
5024  * completion before returning.
5025  **/
5026 enum i40e_status_code i40e_aq_send_msg_to_pf(struct i40e_hw *hw,
5027                                 enum i40e_virtchnl_ops v_opcode,
5028                                 enum i40e_status_code v_retval,
5029                                 u8 *msg, u16 msglen,
5030                                 struct i40e_asq_cmd_details *cmd_details)
5031 {
5032         struct i40e_aq_desc desc;
5033         struct i40e_asq_cmd_details details;
5034         enum i40e_status_code status;
5035
5036         i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_send_msg_to_pf);
5037         desc.flags |= CPU_TO_LE16((u16)I40E_AQ_FLAG_SI);
5038         desc.cookie_high = CPU_TO_LE32(v_opcode);
5039         desc.cookie_low = CPU_TO_LE32(v_retval);
5040         if (msglen) {
5041                 desc.flags |= CPU_TO_LE16((u16)(I40E_AQ_FLAG_BUF
5042                                                 | I40E_AQ_FLAG_RD));
5043                 if (msglen > I40E_AQ_LARGE_BUF)
5044                         desc.flags |= CPU_TO_LE16((u16)I40E_AQ_FLAG_LB);
5045                 desc.datalen = CPU_TO_LE16(msglen);
5046         }
5047         if (!cmd_details) {
5048                 i40e_memset(&details, 0, sizeof(details), I40E_NONDMA_MEM);
5049                 details.async = true;
5050                 cmd_details = &details;
5051         }
5052         status = i40e_asq_send_command(hw, (struct i40e_aq_desc *)&desc, msg,
5053                                        msglen, cmd_details);
5054         return status;
5055 }
5056
5057 /**
5058  * i40e_vf_parse_hw_config
5059  * @hw: pointer to the hardware structure
5060  * @msg: pointer to the virtual channel VF resource structure
5061  *
5062  * Given a VF resource message from the PF, populate the hw struct
5063  * with appropriate information.
5064  **/
5065 void i40e_vf_parse_hw_config(struct i40e_hw *hw,
5066                              struct i40e_virtchnl_vf_resource *msg)
5067 {
5068         struct i40e_virtchnl_vsi_resource *vsi_res;
5069         int i;
5070
5071         vsi_res = &msg->vsi_res[0];
5072
5073         hw->dev_caps.num_vsis = msg->num_vsis;
5074         hw->dev_caps.num_rx_qp = msg->num_queue_pairs;
5075         hw->dev_caps.num_tx_qp = msg->num_queue_pairs;
5076         hw->dev_caps.num_msix_vectors_vf = msg->max_vectors;
5077         hw->dev_caps.dcb = msg->vf_offload_flags &
5078                            I40E_VIRTCHNL_VF_OFFLOAD_L2;
5079         hw->dev_caps.fcoe = (msg->vf_offload_flags &
5080                              I40E_VIRTCHNL_VF_OFFLOAD_FCOE) ? 1 : 0;
5081         hw->dev_caps.iwarp = (msg->vf_offload_flags &
5082                               I40E_VIRTCHNL_VF_OFFLOAD_IWARP) ? 1 : 0;
5083         for (i = 0; i < msg->num_vsis; i++) {
5084                 if (vsi_res->vsi_type == I40E_VSI_SRIOV) {
5085                         i40e_memcpy(hw->mac.perm_addr,
5086                                     vsi_res->default_mac_addr,
5087                                     I40E_ETH_LENGTH_OF_ADDRESS,
5088                                     I40E_NONDMA_TO_NONDMA);
5089                         i40e_memcpy(hw->mac.addr, vsi_res->default_mac_addr,
5090                                     I40E_ETH_LENGTH_OF_ADDRESS,
5091                                     I40E_NONDMA_TO_NONDMA);
5092                 }
5093                 vsi_res++;
5094         }
5095 }
5096
5097 /**
5098  * i40e_vf_reset
5099  * @hw: pointer to the hardware structure
5100  *
5101  * Send a VF_RESET message to the PF. Does not wait for response from PF
5102  * as none will be forthcoming. Immediately after calling this function,
5103  * the admin queue should be shut down and (optionally) reinitialized.
5104  **/
5105 enum i40e_status_code i40e_vf_reset(struct i40e_hw *hw)
5106 {
5107         return i40e_aq_send_msg_to_pf(hw, I40E_VIRTCHNL_OP_RESET_VF,
5108                                       I40E_SUCCESS, NULL, 0, NULL);
5109 }
5110 #endif /* VF_DRIVER */