blob: bbace40bd114caa38ba369367df2692bb97f6c0a [file] [log] [blame]
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00001/*******************************************************************************
2 *
3 * Intel Ethernet Controller XL710 Family Linux Driver
Greg Rosedc641b72013-12-18 13:45:51 +00004 * Copyright(c) 2013 - 2014 Intel Corporation.
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00005 *
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms and conditions of the GNU General Public License,
8 * version 2, as published by the Free Software Foundation.
9 *
10 * This program is distributed in the hope it will be useful, but WITHOUT
11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
13 * more details.
14 *
Greg Rosedc641b72013-12-18 13:45:51 +000015 * You should have received a copy of the GNU General Public License along
16 * with this program. If not, see <http://www.gnu.org/licenses/>.
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +000017 *
18 * The full GNU General Public License is included in this distribution in
19 * the file called "COPYING".
20 *
21 * Contact Information:
22 * e1000-devel Mailing List <e1000-devel@lists.sourceforge.net>
23 * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
24 *
25 ******************************************************************************/
26
27#include "i40e_type.h"
28#include "i40e_adminq.h"
29#include "i40e_prototype.h"
30#include "i40e_virtchnl.h"
31
32/**
33 * i40e_set_mac_type - Sets MAC type
34 * @hw: pointer to the HW structure
35 *
36 * This function sets the mac type of the adapter based on the
37 * vendor ID and device ID stored in the hw structure.
38 **/
39static i40e_status i40e_set_mac_type(struct i40e_hw *hw)
40{
41 i40e_status status = 0;
42
43 if (hw->vendor_id == PCI_VENDOR_ID_INTEL) {
44 switch (hw->device_id) {
Shannon Nelsonab600852014-01-17 15:36:39 -080045 case I40E_DEV_ID_SFP_XL710:
Shannon Nelsonab600852014-01-17 15:36:39 -080046 case I40E_DEV_ID_QEMU:
47 case I40E_DEV_ID_KX_A:
48 case I40E_DEV_ID_KX_B:
49 case I40E_DEV_ID_KX_C:
Shannon Nelsonab600852014-01-17 15:36:39 -080050 case I40E_DEV_ID_QSFP_A:
51 case I40E_DEV_ID_QSFP_B:
52 case I40E_DEV_ID_QSFP_C:
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +000053 hw->mac.type = I40E_MAC_XL710;
54 break;
Shannon Nelsonab600852014-01-17 15:36:39 -080055 case I40E_DEV_ID_VF:
56 case I40E_DEV_ID_VF_HV:
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +000057 hw->mac.type = I40E_MAC_VF;
58 break;
59 default:
60 hw->mac.type = I40E_MAC_GENERIC;
61 break;
62 }
63 } else {
64 status = I40E_ERR_DEVICE_NOT_SUPPORTED;
65 }
66
67 hw_dbg(hw, "i40e_set_mac_type found mac: %d, returns: %d\n",
68 hw->mac.type, status);
69 return status;
70}
71
72/**
73 * i40e_debug_aq
74 * @hw: debug mask related to admin queue
Jeff Kirsher98d44382013-12-21 05:44:42 +000075 * @mask: debug mask
76 * @desc: pointer to admin queue descriptor
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +000077 * @buffer: pointer to command buffer
78 *
79 * Dumps debug log about adminq command with descriptor contents.
80 **/
81void i40e_debug_aq(struct i40e_hw *hw, enum i40e_debug_mask mask, void *desc,
82 void *buffer)
83{
84 struct i40e_aq_desc *aq_desc = (struct i40e_aq_desc *)desc;
85 u8 *aq_buffer = (u8 *)buffer;
86 u32 data[4];
87 u32 i = 0;
88
89 if ((!(mask & hw->debug_mask)) || (desc == NULL))
90 return;
91
92 i40e_debug(hw, mask,
93 "AQ CMD: opcode 0x%04X, flags 0x%04X, datalen 0x%04X, retval 0x%04X\n",
94 aq_desc->opcode, aq_desc->flags, aq_desc->datalen,
95 aq_desc->retval);
96 i40e_debug(hw, mask, "\tcookie (h,l) 0x%08X 0x%08X\n",
97 aq_desc->cookie_high, aq_desc->cookie_low);
98 i40e_debug(hw, mask, "\tparam (0,1) 0x%08X 0x%08X\n",
99 aq_desc->params.internal.param0,
100 aq_desc->params.internal.param1);
101 i40e_debug(hw, mask, "\taddr (h,l) 0x%08X 0x%08X\n",
102 aq_desc->params.external.addr_high,
103 aq_desc->params.external.addr_low);
104
105 if ((buffer != NULL) && (aq_desc->datalen != 0)) {
106 memset(data, 0, sizeof(data));
107 i40e_debug(hw, mask, "AQ CMD Buffer:\n");
108 for (i = 0; i < le16_to_cpu(aq_desc->datalen); i++) {
109 data[((i % 16) / 4)] |=
110 ((u32)aq_buffer[i]) << (8 * (i % 4));
111 if ((i % 16) == 15) {
112 i40e_debug(hw, mask,
113 "\t0x%04X %08X %08X %08X %08X\n",
114 i - 15, data[0], data[1], data[2],
115 data[3]);
116 memset(data, 0, sizeof(data));
117 }
118 }
119 if ((i % 16) != 0)
120 i40e_debug(hw, mask, "\t0x%04X %08X %08X %08X %08X\n",
121 i - (i % 16), data[0], data[1], data[2],
122 data[3]);
123 }
124}
125
126/**
Anjali Singhai Jaine1860d82013-11-28 06:39:45 +0000127 * i40e_check_asq_alive
128 * @hw: pointer to the hw struct
129 *
130 * Returns true if Queue is enabled else false.
131 **/
132bool i40e_check_asq_alive(struct i40e_hw *hw)
133{
Kevin Scott8b833b42014-04-09 05:58:54 +0000134 if (hw->aq.asq.len)
135 return !!(rd32(hw, hw->aq.asq.len) &
136 I40E_PF_ATQLEN_ATQENABLE_MASK);
137 else
138 return false;
Anjali Singhai Jaine1860d82013-11-28 06:39:45 +0000139}
140
141/**
142 * i40e_aq_queue_shutdown
143 * @hw: pointer to the hw struct
144 * @unloading: is the driver unloading itself
145 *
146 * Tell the Firmware that we're shutting down the AdminQ and whether
147 * or not the driver is unloading as well.
148 **/
149i40e_status i40e_aq_queue_shutdown(struct i40e_hw *hw,
150 bool unloading)
151{
152 struct i40e_aq_desc desc;
153 struct i40e_aqc_queue_shutdown *cmd =
154 (struct i40e_aqc_queue_shutdown *)&desc.params.raw;
155 i40e_status status;
156
157 i40e_fill_default_direct_cmd_desc(&desc,
158 i40e_aqc_opc_queue_shutdown);
159
160 if (unloading)
161 cmd->driver_unloading = cpu_to_le32(I40E_AQ_DRIVER_UNLOADING);
162 status = i40e_asq_send_command(hw, &desc, NULL, 0, NULL);
163
164 return status;
165}
166
Jesse Brandeburg206812b2014-02-12 01:45:33 +0000167/* The i40e_ptype_lookup table is used to convert from the 8-bit ptype in the
168 * hardware to a bit-field that can be used by SW to more easily determine the
169 * packet type.
170 *
171 * Macros are used to shorten the table lines and make this table human
172 * readable.
173 *
174 * We store the PTYPE in the top byte of the bit field - this is just so that
175 * we can check that the table doesn't have a row missing, as the index into
176 * the table should be the PTYPE.
177 *
178 * Typical work flow:
179 *
180 * IF NOT i40e_ptype_lookup[ptype].known
181 * THEN
182 * Packet is unknown
183 * ELSE IF i40e_ptype_lookup[ptype].outer_ip == I40E_RX_PTYPE_OUTER_IP
184 * Use the rest of the fields to look at the tunnels, inner protocols, etc
185 * ELSE
186 * Use the enum i40e_rx_l2_ptype to decode the packet type
187 * ENDIF
188 */
189
190/* macro to make the table lines short */
191#define I40E_PTT(PTYPE, OUTER_IP, OUTER_IP_VER, OUTER_FRAG, T, TE, TEF, I, PL)\
192 { PTYPE, \
193 1, \
194 I40E_RX_PTYPE_OUTER_##OUTER_IP, \
195 I40E_RX_PTYPE_OUTER_##OUTER_IP_VER, \
196 I40E_RX_PTYPE_##OUTER_FRAG, \
197 I40E_RX_PTYPE_TUNNEL_##T, \
198 I40E_RX_PTYPE_TUNNEL_END_##TE, \
199 I40E_RX_PTYPE_##TEF, \
200 I40E_RX_PTYPE_INNER_PROT_##I, \
201 I40E_RX_PTYPE_PAYLOAD_LAYER_##PL }
202
203#define I40E_PTT_UNUSED_ENTRY(PTYPE) \
204 { PTYPE, 0, 0, 0, 0, 0, 0, 0, 0, 0 }
205
206/* shorter macros makes the table fit but are terse */
207#define I40E_RX_PTYPE_NOF I40E_RX_PTYPE_NOT_FRAG
208#define I40E_RX_PTYPE_FRG I40E_RX_PTYPE_FRAG
209#define I40E_RX_PTYPE_INNER_PROT_TS I40E_RX_PTYPE_INNER_PROT_TIMESYNC
210
211/* Lookup table mapping the HW PTYPE to the bit field for decoding */
212struct i40e_rx_ptype_decoded i40e_ptype_lookup[] = {
213 /* L2 Packet types */
214 I40E_PTT_UNUSED_ENTRY(0),
215 I40E_PTT(1, L2, NONE, NOF, NONE, NONE, NOF, NONE, PAY2),
216 I40E_PTT(2, L2, NONE, NOF, NONE, NONE, NOF, TS, PAY2),
217 I40E_PTT(3, L2, NONE, NOF, NONE, NONE, NOF, NONE, PAY2),
218 I40E_PTT_UNUSED_ENTRY(4),
219 I40E_PTT_UNUSED_ENTRY(5),
220 I40E_PTT(6, L2, NONE, NOF, NONE, NONE, NOF, NONE, PAY2),
221 I40E_PTT(7, L2, NONE, NOF, NONE, NONE, NOF, NONE, PAY2),
222 I40E_PTT_UNUSED_ENTRY(8),
223 I40E_PTT_UNUSED_ENTRY(9),
224 I40E_PTT(10, L2, NONE, NOF, NONE, NONE, NOF, NONE, PAY2),
225 I40E_PTT(11, L2, NONE, NOF, NONE, NONE, NOF, NONE, NONE),
226 I40E_PTT(12, L2, NONE, NOF, NONE, NONE, NOF, NONE, PAY3),
227 I40E_PTT(13, L2, NONE, NOF, NONE, NONE, NOF, NONE, PAY3),
228 I40E_PTT(14, L2, NONE, NOF, NONE, NONE, NOF, NONE, PAY3),
229 I40E_PTT(15, L2, NONE, NOF, NONE, NONE, NOF, NONE, PAY3),
230 I40E_PTT(16, L2, NONE, NOF, NONE, NONE, NOF, NONE, PAY3),
231 I40E_PTT(17, L2, NONE, NOF, NONE, NONE, NOF, NONE, PAY3),
232 I40E_PTT(18, L2, NONE, NOF, NONE, NONE, NOF, NONE, PAY3),
233 I40E_PTT(19, L2, NONE, NOF, NONE, NONE, NOF, NONE, PAY3),
234 I40E_PTT(20, L2, NONE, NOF, NONE, NONE, NOF, NONE, PAY3),
235 I40E_PTT(21, L2, NONE, NOF, NONE, NONE, NOF, NONE, PAY3),
236
237 /* Non Tunneled IPv4 */
238 I40E_PTT(22, IP, IPV4, FRG, NONE, NONE, NOF, NONE, PAY3),
239 I40E_PTT(23, IP, IPV4, NOF, NONE, NONE, NOF, NONE, PAY3),
240 I40E_PTT(24, IP, IPV4, NOF, NONE, NONE, NOF, UDP, PAY4),
241 I40E_PTT_UNUSED_ENTRY(25),
242 I40E_PTT(26, IP, IPV4, NOF, NONE, NONE, NOF, TCP, PAY4),
243 I40E_PTT(27, IP, IPV4, NOF, NONE, NONE, NOF, SCTP, PAY4),
244 I40E_PTT(28, IP, IPV4, NOF, NONE, NONE, NOF, ICMP, PAY4),
245
246 /* IPv4 --> IPv4 */
247 I40E_PTT(29, IP, IPV4, NOF, IP_IP, IPV4, FRG, NONE, PAY3),
248 I40E_PTT(30, IP, IPV4, NOF, IP_IP, IPV4, NOF, NONE, PAY3),
249 I40E_PTT(31, IP, IPV4, NOF, IP_IP, IPV4, NOF, UDP, PAY4),
250 I40E_PTT_UNUSED_ENTRY(32),
251 I40E_PTT(33, IP, IPV4, NOF, IP_IP, IPV4, NOF, TCP, PAY4),
252 I40E_PTT(34, IP, IPV4, NOF, IP_IP, IPV4, NOF, SCTP, PAY4),
253 I40E_PTT(35, IP, IPV4, NOF, IP_IP, IPV4, NOF, ICMP, PAY4),
254
255 /* IPv4 --> IPv6 */
256 I40E_PTT(36, IP, IPV4, NOF, IP_IP, IPV6, FRG, NONE, PAY3),
257 I40E_PTT(37, IP, IPV4, NOF, IP_IP, IPV6, NOF, NONE, PAY3),
258 I40E_PTT(38, IP, IPV4, NOF, IP_IP, IPV6, NOF, UDP, PAY4),
259 I40E_PTT_UNUSED_ENTRY(39),
260 I40E_PTT(40, IP, IPV4, NOF, IP_IP, IPV6, NOF, TCP, PAY4),
261 I40E_PTT(41, IP, IPV4, NOF, IP_IP, IPV6, NOF, SCTP, PAY4),
262 I40E_PTT(42, IP, IPV4, NOF, IP_IP, IPV6, NOF, ICMP, PAY4),
263
264 /* IPv4 --> GRE/NAT */
265 I40E_PTT(43, IP, IPV4, NOF, IP_GRENAT, NONE, NOF, NONE, PAY3),
266
267 /* IPv4 --> GRE/NAT --> IPv4 */
268 I40E_PTT(44, IP, IPV4, NOF, IP_GRENAT, IPV4, FRG, NONE, PAY3),
269 I40E_PTT(45, IP, IPV4, NOF, IP_GRENAT, IPV4, NOF, NONE, PAY3),
270 I40E_PTT(46, IP, IPV4, NOF, IP_GRENAT, IPV4, NOF, UDP, PAY4),
271 I40E_PTT_UNUSED_ENTRY(47),
272 I40E_PTT(48, IP, IPV4, NOF, IP_GRENAT, IPV4, NOF, TCP, PAY4),
273 I40E_PTT(49, IP, IPV4, NOF, IP_GRENAT, IPV4, NOF, SCTP, PAY4),
274 I40E_PTT(50, IP, IPV4, NOF, IP_GRENAT, IPV4, NOF, ICMP, PAY4),
275
276 /* IPv4 --> GRE/NAT --> IPv6 */
277 I40E_PTT(51, IP, IPV4, NOF, IP_GRENAT, IPV6, FRG, NONE, PAY3),
278 I40E_PTT(52, IP, IPV4, NOF, IP_GRENAT, IPV6, NOF, NONE, PAY3),
279 I40E_PTT(53, IP, IPV4, NOF, IP_GRENAT, IPV6, NOF, UDP, PAY4),
280 I40E_PTT_UNUSED_ENTRY(54),
281 I40E_PTT(55, IP, IPV4, NOF, IP_GRENAT, IPV6, NOF, TCP, PAY4),
282 I40E_PTT(56, IP, IPV4, NOF, IP_GRENAT, IPV6, NOF, SCTP, PAY4),
283 I40E_PTT(57, IP, IPV4, NOF, IP_GRENAT, IPV6, NOF, ICMP, PAY4),
284
285 /* IPv4 --> GRE/NAT --> MAC */
286 I40E_PTT(58, IP, IPV4, NOF, IP_GRENAT_MAC, NONE, NOF, NONE, PAY3),
287
288 /* IPv4 --> GRE/NAT --> MAC --> IPv4 */
289 I40E_PTT(59, IP, IPV4, NOF, IP_GRENAT_MAC, IPV4, FRG, NONE, PAY3),
290 I40E_PTT(60, IP, IPV4, NOF, IP_GRENAT_MAC, IPV4, NOF, NONE, PAY3),
291 I40E_PTT(61, IP, IPV4, NOF, IP_GRENAT_MAC, IPV4, NOF, UDP, PAY4),
292 I40E_PTT_UNUSED_ENTRY(62),
293 I40E_PTT(63, IP, IPV4, NOF, IP_GRENAT_MAC, IPV4, NOF, TCP, PAY4),
294 I40E_PTT(64, IP, IPV4, NOF, IP_GRENAT_MAC, IPV4, NOF, SCTP, PAY4),
295 I40E_PTT(65, IP, IPV4, NOF, IP_GRENAT_MAC, IPV4, NOF, ICMP, PAY4),
296
297 /* IPv4 --> GRE/NAT -> MAC --> IPv6 */
298 I40E_PTT(66, IP, IPV4, NOF, IP_GRENAT_MAC, IPV6, FRG, NONE, PAY3),
299 I40E_PTT(67, IP, IPV4, NOF, IP_GRENAT_MAC, IPV6, NOF, NONE, PAY3),
300 I40E_PTT(68, IP, IPV4, NOF, IP_GRENAT_MAC, IPV6, NOF, UDP, PAY4),
301 I40E_PTT_UNUSED_ENTRY(69),
302 I40E_PTT(70, IP, IPV4, NOF, IP_GRENAT_MAC, IPV6, NOF, TCP, PAY4),
303 I40E_PTT(71, IP, IPV4, NOF, IP_GRENAT_MAC, IPV6, NOF, SCTP, PAY4),
304 I40E_PTT(72, IP, IPV4, NOF, IP_GRENAT_MAC, IPV6, NOF, ICMP, PAY4),
305
306 /* IPv4 --> GRE/NAT --> MAC/VLAN */
307 I40E_PTT(73, IP, IPV4, NOF, IP_GRENAT_MAC_VLAN, NONE, NOF, NONE, PAY3),
308
309 /* IPv4 ---> GRE/NAT -> MAC/VLAN --> IPv4 */
310 I40E_PTT(74, IP, IPV4, NOF, IP_GRENAT_MAC_VLAN, IPV4, FRG, NONE, PAY3),
311 I40E_PTT(75, IP, IPV4, NOF, IP_GRENAT_MAC_VLAN, IPV4, NOF, NONE, PAY3),
312 I40E_PTT(76, IP, IPV4, NOF, IP_GRENAT_MAC_VLAN, IPV4, NOF, UDP, PAY4),
313 I40E_PTT_UNUSED_ENTRY(77),
314 I40E_PTT(78, IP, IPV4, NOF, IP_GRENAT_MAC_VLAN, IPV4, NOF, TCP, PAY4),
315 I40E_PTT(79, IP, IPV4, NOF, IP_GRENAT_MAC_VLAN, IPV4, NOF, SCTP, PAY4),
316 I40E_PTT(80, IP, IPV4, NOF, IP_GRENAT_MAC_VLAN, IPV4, NOF, ICMP, PAY4),
317
318 /* IPv4 -> GRE/NAT -> MAC/VLAN --> IPv6 */
319 I40E_PTT(81, IP, IPV4, NOF, IP_GRENAT_MAC_VLAN, IPV6, FRG, NONE, PAY3),
320 I40E_PTT(82, IP, IPV4, NOF, IP_GRENAT_MAC_VLAN, IPV6, NOF, NONE, PAY3),
321 I40E_PTT(83, IP, IPV4, NOF, IP_GRENAT_MAC_VLAN, IPV6, NOF, UDP, PAY4),
322 I40E_PTT_UNUSED_ENTRY(84),
323 I40E_PTT(85, IP, IPV4, NOF, IP_GRENAT_MAC_VLAN, IPV6, NOF, TCP, PAY4),
324 I40E_PTT(86, IP, IPV4, NOF, IP_GRENAT_MAC_VLAN, IPV6, NOF, SCTP, PAY4),
325 I40E_PTT(87, IP, IPV4, NOF, IP_GRENAT_MAC_VLAN, IPV6, NOF, ICMP, PAY4),
326
327 /* Non Tunneled IPv6 */
328 I40E_PTT(88, IP, IPV6, FRG, NONE, NONE, NOF, NONE, PAY3),
329 I40E_PTT(89, IP, IPV6, NOF, NONE, NONE, NOF, NONE, PAY3),
330 I40E_PTT(90, IP, IPV6, NOF, NONE, NONE, NOF, UDP, PAY3),
331 I40E_PTT_UNUSED_ENTRY(91),
332 I40E_PTT(92, IP, IPV6, NOF, NONE, NONE, NOF, TCP, PAY4),
333 I40E_PTT(93, IP, IPV6, NOF, NONE, NONE, NOF, SCTP, PAY4),
334 I40E_PTT(94, IP, IPV6, NOF, NONE, NONE, NOF, ICMP, PAY4),
335
336 /* IPv6 --> IPv4 */
337 I40E_PTT(95, IP, IPV6, NOF, IP_IP, IPV4, FRG, NONE, PAY3),
338 I40E_PTT(96, IP, IPV6, NOF, IP_IP, IPV4, NOF, NONE, PAY3),
339 I40E_PTT(97, IP, IPV6, NOF, IP_IP, IPV4, NOF, UDP, PAY4),
340 I40E_PTT_UNUSED_ENTRY(98),
341 I40E_PTT(99, IP, IPV6, NOF, IP_IP, IPV4, NOF, TCP, PAY4),
342 I40E_PTT(100, IP, IPV6, NOF, IP_IP, IPV4, NOF, SCTP, PAY4),
343 I40E_PTT(101, IP, IPV6, NOF, IP_IP, IPV4, NOF, ICMP, PAY4),
344
345 /* IPv6 --> IPv6 */
346 I40E_PTT(102, IP, IPV6, NOF, IP_IP, IPV6, FRG, NONE, PAY3),
347 I40E_PTT(103, IP, IPV6, NOF, IP_IP, IPV6, NOF, NONE, PAY3),
348 I40E_PTT(104, IP, IPV6, NOF, IP_IP, IPV6, NOF, UDP, PAY4),
349 I40E_PTT_UNUSED_ENTRY(105),
350 I40E_PTT(106, IP, IPV6, NOF, IP_IP, IPV6, NOF, TCP, PAY4),
351 I40E_PTT(107, IP, IPV6, NOF, IP_IP, IPV6, NOF, SCTP, PAY4),
352 I40E_PTT(108, IP, IPV6, NOF, IP_IP, IPV6, NOF, ICMP, PAY4),
353
354 /* IPv6 --> GRE/NAT */
355 I40E_PTT(109, IP, IPV6, NOF, IP_GRENAT, NONE, NOF, NONE, PAY3),
356
357 /* IPv6 --> GRE/NAT -> IPv4 */
358 I40E_PTT(110, IP, IPV6, NOF, IP_GRENAT, IPV4, FRG, NONE, PAY3),
359 I40E_PTT(111, IP, IPV6, NOF, IP_GRENAT, IPV4, NOF, NONE, PAY3),
360 I40E_PTT(112, IP, IPV6, NOF, IP_GRENAT, IPV4, NOF, UDP, PAY4),
361 I40E_PTT_UNUSED_ENTRY(113),
362 I40E_PTT(114, IP, IPV6, NOF, IP_GRENAT, IPV4, NOF, TCP, PAY4),
363 I40E_PTT(115, IP, IPV6, NOF, IP_GRENAT, IPV4, NOF, SCTP, PAY4),
364 I40E_PTT(116, IP, IPV6, NOF, IP_GRENAT, IPV4, NOF, ICMP, PAY4),
365
366 /* IPv6 --> GRE/NAT -> IPv6 */
367 I40E_PTT(117, IP, IPV6, NOF, IP_GRENAT, IPV6, FRG, NONE, PAY3),
368 I40E_PTT(118, IP, IPV6, NOF, IP_GRENAT, IPV6, NOF, NONE, PAY3),
369 I40E_PTT(119, IP, IPV6, NOF, IP_GRENAT, IPV6, NOF, UDP, PAY4),
370 I40E_PTT_UNUSED_ENTRY(120),
371 I40E_PTT(121, IP, IPV6, NOF, IP_GRENAT, IPV6, NOF, TCP, PAY4),
372 I40E_PTT(122, IP, IPV6, NOF, IP_GRENAT, IPV6, NOF, SCTP, PAY4),
373 I40E_PTT(123, IP, IPV6, NOF, IP_GRENAT, IPV6, NOF, ICMP, PAY4),
374
375 /* IPv6 --> GRE/NAT -> MAC */
376 I40E_PTT(124, IP, IPV6, NOF, IP_GRENAT_MAC, NONE, NOF, NONE, PAY3),
377
378 /* IPv6 --> GRE/NAT -> MAC -> IPv4 */
379 I40E_PTT(125, IP, IPV6, NOF, IP_GRENAT_MAC, IPV4, FRG, NONE, PAY3),
380 I40E_PTT(126, IP, IPV6, NOF, IP_GRENAT_MAC, IPV4, NOF, NONE, PAY3),
381 I40E_PTT(127, IP, IPV6, NOF, IP_GRENAT_MAC, IPV4, NOF, UDP, PAY4),
382 I40E_PTT_UNUSED_ENTRY(128),
383 I40E_PTT(129, IP, IPV6, NOF, IP_GRENAT_MAC, IPV4, NOF, TCP, PAY4),
384 I40E_PTT(130, IP, IPV6, NOF, IP_GRENAT_MAC, IPV4, NOF, SCTP, PAY4),
385 I40E_PTT(131, IP, IPV6, NOF, IP_GRENAT_MAC, IPV4, NOF, ICMP, PAY4),
386
387 /* IPv6 --> GRE/NAT -> MAC -> IPv6 */
388 I40E_PTT(132, IP, IPV6, NOF, IP_GRENAT_MAC, IPV6, FRG, NONE, PAY3),
389 I40E_PTT(133, IP, IPV6, NOF, IP_GRENAT_MAC, IPV6, NOF, NONE, PAY3),
390 I40E_PTT(134, IP, IPV6, NOF, IP_GRENAT_MAC, IPV6, NOF, UDP, PAY4),
391 I40E_PTT_UNUSED_ENTRY(135),
392 I40E_PTT(136, IP, IPV6, NOF, IP_GRENAT_MAC, IPV6, NOF, TCP, PAY4),
393 I40E_PTT(137, IP, IPV6, NOF, IP_GRENAT_MAC, IPV6, NOF, SCTP, PAY4),
394 I40E_PTT(138, IP, IPV6, NOF, IP_GRENAT_MAC, IPV6, NOF, ICMP, PAY4),
395
396 /* IPv6 --> GRE/NAT -> MAC/VLAN */
397 I40E_PTT(139, IP, IPV6, NOF, IP_GRENAT_MAC_VLAN, NONE, NOF, NONE, PAY3),
398
399 /* IPv6 --> GRE/NAT -> MAC/VLAN --> IPv4 */
400 I40E_PTT(140, IP, IPV6, NOF, IP_GRENAT_MAC_VLAN, IPV4, FRG, NONE, PAY3),
401 I40E_PTT(141, IP, IPV6, NOF, IP_GRENAT_MAC_VLAN, IPV4, NOF, NONE, PAY3),
402 I40E_PTT(142, IP, IPV6, NOF, IP_GRENAT_MAC_VLAN, IPV4, NOF, UDP, PAY4),
403 I40E_PTT_UNUSED_ENTRY(143),
404 I40E_PTT(144, IP, IPV6, NOF, IP_GRENAT_MAC_VLAN, IPV4, NOF, TCP, PAY4),
405 I40E_PTT(145, IP, IPV6, NOF, IP_GRENAT_MAC_VLAN, IPV4, NOF, SCTP, PAY4),
406 I40E_PTT(146, IP, IPV6, NOF, IP_GRENAT_MAC_VLAN, IPV4, NOF, ICMP, PAY4),
407
408 /* IPv6 --> GRE/NAT -> MAC/VLAN --> IPv6 */
409 I40E_PTT(147, IP, IPV6, NOF, IP_GRENAT_MAC_VLAN, IPV6, FRG, NONE, PAY3),
410 I40E_PTT(148, IP, IPV6, NOF, IP_GRENAT_MAC_VLAN, IPV6, NOF, NONE, PAY3),
411 I40E_PTT(149, IP, IPV6, NOF, IP_GRENAT_MAC_VLAN, IPV6, NOF, UDP, PAY4),
412 I40E_PTT_UNUSED_ENTRY(150),
413 I40E_PTT(151, IP, IPV6, NOF, IP_GRENAT_MAC_VLAN, IPV6, NOF, TCP, PAY4),
414 I40E_PTT(152, IP, IPV6, NOF, IP_GRENAT_MAC_VLAN, IPV6, NOF, SCTP, PAY4),
415 I40E_PTT(153, IP, IPV6, NOF, IP_GRENAT_MAC_VLAN, IPV6, NOF, ICMP, PAY4),
416
417 /* unused entries */
418 I40E_PTT_UNUSED_ENTRY(154),
419 I40E_PTT_UNUSED_ENTRY(155),
420 I40E_PTT_UNUSED_ENTRY(156),
421 I40E_PTT_UNUSED_ENTRY(157),
422 I40E_PTT_UNUSED_ENTRY(158),
423 I40E_PTT_UNUSED_ENTRY(159),
424
425 I40E_PTT_UNUSED_ENTRY(160),
426 I40E_PTT_UNUSED_ENTRY(161),
427 I40E_PTT_UNUSED_ENTRY(162),
428 I40E_PTT_UNUSED_ENTRY(163),
429 I40E_PTT_UNUSED_ENTRY(164),
430 I40E_PTT_UNUSED_ENTRY(165),
431 I40E_PTT_UNUSED_ENTRY(166),
432 I40E_PTT_UNUSED_ENTRY(167),
433 I40E_PTT_UNUSED_ENTRY(168),
434 I40E_PTT_UNUSED_ENTRY(169),
435
436 I40E_PTT_UNUSED_ENTRY(170),
437 I40E_PTT_UNUSED_ENTRY(171),
438 I40E_PTT_UNUSED_ENTRY(172),
439 I40E_PTT_UNUSED_ENTRY(173),
440 I40E_PTT_UNUSED_ENTRY(174),
441 I40E_PTT_UNUSED_ENTRY(175),
442 I40E_PTT_UNUSED_ENTRY(176),
443 I40E_PTT_UNUSED_ENTRY(177),
444 I40E_PTT_UNUSED_ENTRY(178),
445 I40E_PTT_UNUSED_ENTRY(179),
446
447 I40E_PTT_UNUSED_ENTRY(180),
448 I40E_PTT_UNUSED_ENTRY(181),
449 I40E_PTT_UNUSED_ENTRY(182),
450 I40E_PTT_UNUSED_ENTRY(183),
451 I40E_PTT_UNUSED_ENTRY(184),
452 I40E_PTT_UNUSED_ENTRY(185),
453 I40E_PTT_UNUSED_ENTRY(186),
454 I40E_PTT_UNUSED_ENTRY(187),
455 I40E_PTT_UNUSED_ENTRY(188),
456 I40E_PTT_UNUSED_ENTRY(189),
457
458 I40E_PTT_UNUSED_ENTRY(190),
459 I40E_PTT_UNUSED_ENTRY(191),
460 I40E_PTT_UNUSED_ENTRY(192),
461 I40E_PTT_UNUSED_ENTRY(193),
462 I40E_PTT_UNUSED_ENTRY(194),
463 I40E_PTT_UNUSED_ENTRY(195),
464 I40E_PTT_UNUSED_ENTRY(196),
465 I40E_PTT_UNUSED_ENTRY(197),
466 I40E_PTT_UNUSED_ENTRY(198),
467 I40E_PTT_UNUSED_ENTRY(199),
468
469 I40E_PTT_UNUSED_ENTRY(200),
470 I40E_PTT_UNUSED_ENTRY(201),
471 I40E_PTT_UNUSED_ENTRY(202),
472 I40E_PTT_UNUSED_ENTRY(203),
473 I40E_PTT_UNUSED_ENTRY(204),
474 I40E_PTT_UNUSED_ENTRY(205),
475 I40E_PTT_UNUSED_ENTRY(206),
476 I40E_PTT_UNUSED_ENTRY(207),
477 I40E_PTT_UNUSED_ENTRY(208),
478 I40E_PTT_UNUSED_ENTRY(209),
479
480 I40E_PTT_UNUSED_ENTRY(210),
481 I40E_PTT_UNUSED_ENTRY(211),
482 I40E_PTT_UNUSED_ENTRY(212),
483 I40E_PTT_UNUSED_ENTRY(213),
484 I40E_PTT_UNUSED_ENTRY(214),
485 I40E_PTT_UNUSED_ENTRY(215),
486 I40E_PTT_UNUSED_ENTRY(216),
487 I40E_PTT_UNUSED_ENTRY(217),
488 I40E_PTT_UNUSED_ENTRY(218),
489 I40E_PTT_UNUSED_ENTRY(219),
490
491 I40E_PTT_UNUSED_ENTRY(220),
492 I40E_PTT_UNUSED_ENTRY(221),
493 I40E_PTT_UNUSED_ENTRY(222),
494 I40E_PTT_UNUSED_ENTRY(223),
495 I40E_PTT_UNUSED_ENTRY(224),
496 I40E_PTT_UNUSED_ENTRY(225),
497 I40E_PTT_UNUSED_ENTRY(226),
498 I40E_PTT_UNUSED_ENTRY(227),
499 I40E_PTT_UNUSED_ENTRY(228),
500 I40E_PTT_UNUSED_ENTRY(229),
501
502 I40E_PTT_UNUSED_ENTRY(230),
503 I40E_PTT_UNUSED_ENTRY(231),
504 I40E_PTT_UNUSED_ENTRY(232),
505 I40E_PTT_UNUSED_ENTRY(233),
506 I40E_PTT_UNUSED_ENTRY(234),
507 I40E_PTT_UNUSED_ENTRY(235),
508 I40E_PTT_UNUSED_ENTRY(236),
509 I40E_PTT_UNUSED_ENTRY(237),
510 I40E_PTT_UNUSED_ENTRY(238),
511 I40E_PTT_UNUSED_ENTRY(239),
512
513 I40E_PTT_UNUSED_ENTRY(240),
514 I40E_PTT_UNUSED_ENTRY(241),
515 I40E_PTT_UNUSED_ENTRY(242),
516 I40E_PTT_UNUSED_ENTRY(243),
517 I40E_PTT_UNUSED_ENTRY(244),
518 I40E_PTT_UNUSED_ENTRY(245),
519 I40E_PTT_UNUSED_ENTRY(246),
520 I40E_PTT_UNUSED_ENTRY(247),
521 I40E_PTT_UNUSED_ENTRY(248),
522 I40E_PTT_UNUSED_ENTRY(249),
523
524 I40E_PTT_UNUSED_ENTRY(250),
525 I40E_PTT_UNUSED_ENTRY(251),
526 I40E_PTT_UNUSED_ENTRY(252),
527 I40E_PTT_UNUSED_ENTRY(253),
528 I40E_PTT_UNUSED_ENTRY(254),
529 I40E_PTT_UNUSED_ENTRY(255)
530};
531
532
Anjali Singhai Jaine1860d82013-11-28 06:39:45 +0000533/**
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +0000534 * i40e_init_shared_code - Initialize the shared code
535 * @hw: pointer to hardware structure
536 *
537 * This assigns the MAC type and PHY code and inits the NVM.
538 * Does not touch the hardware. This function must be called prior to any
539 * other function in the shared code. The i40e_hw structure should be
540 * memset to 0 prior to calling this function. The following fields in
541 * hw structure should be filled in prior to calling this function:
542 * hw_addr, back, device_id, vendor_id, subsystem_device_id,
543 * subsystem_vendor_id, and revision_id
544 **/
545i40e_status i40e_init_shared_code(struct i40e_hw *hw)
546{
547 i40e_status status = 0;
548 u32 reg;
549
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +0000550 i40e_set_mac_type(hw);
551
552 switch (hw->mac.type) {
553 case I40E_MAC_XL710:
554 break;
555 default:
556 return I40E_ERR_DEVICE_NOT_SUPPORTED;
557 break;
558 }
559
Shannon Nelsonaf89d26c2013-12-11 08:17:14 +0000560 hw->phy.get_link_info = true;
561
562 /* Determine port number */
563 reg = rd32(hw, I40E_PFGEN_PORTNUM);
564 reg = ((reg & I40E_PFGEN_PORTNUM_PORT_NUM_MASK) >>
565 I40E_PFGEN_PORTNUM_PORT_NUM_SHIFT);
566 hw->port = (u8)reg;
567
Shannon Nelson5f9116a2013-12-11 08:17:13 +0000568 /* Determine the PF number based on the PCI fn */
569 reg = rd32(hw, I40E_GLPCI_CAPSUP);
570 if (reg & I40E_GLPCI_CAPSUP_ARI_EN_MASK)
571 hw->pf_id = (u8)((hw->bus.device << 3) | hw->bus.func);
572 else
573 hw->pf_id = (u8)hw->bus.func;
574
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +0000575 status = i40e_init_nvm(hw);
576 return status;
577}
578
579/**
580 * i40e_aq_mac_address_read - Retrieve the MAC addresses
581 * @hw: pointer to the hw struct
582 * @flags: a return indicator of what addresses were added to the addr store
583 * @addrs: the requestor's mac addr store
584 * @cmd_details: pointer to command details structure or NULL
585 **/
586static i40e_status i40e_aq_mac_address_read(struct i40e_hw *hw,
587 u16 *flags,
588 struct i40e_aqc_mac_address_read_data *addrs,
589 struct i40e_asq_cmd_details *cmd_details)
590{
591 struct i40e_aq_desc desc;
592 struct i40e_aqc_mac_address_read *cmd_data =
593 (struct i40e_aqc_mac_address_read *)&desc.params.raw;
594 i40e_status status;
595
596 i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_mac_address_read);
597 desc.flags |= cpu_to_le16(I40E_AQ_FLAG_BUF);
598
599 status = i40e_asq_send_command(hw, &desc, addrs,
600 sizeof(*addrs), cmd_details);
601 *flags = le16_to_cpu(cmd_data->command_flags);
602
603 return status;
604}
605
606/**
607 * i40e_aq_mac_address_write - Change the MAC addresses
608 * @hw: pointer to the hw struct
609 * @flags: indicates which MAC to be written
610 * @mac_addr: address to write
611 * @cmd_details: pointer to command details structure or NULL
612 **/
613i40e_status i40e_aq_mac_address_write(struct i40e_hw *hw,
614 u16 flags, u8 *mac_addr,
615 struct i40e_asq_cmd_details *cmd_details)
616{
617 struct i40e_aq_desc desc;
618 struct i40e_aqc_mac_address_write *cmd_data =
619 (struct i40e_aqc_mac_address_write *)&desc.params.raw;
620 i40e_status status;
621
622 i40e_fill_default_direct_cmd_desc(&desc,
623 i40e_aqc_opc_mac_address_write);
624 cmd_data->command_flags = cpu_to_le16(flags);
Kamil Krawczyk55c29c32013-12-18 13:45:52 +0000625 cmd_data->mac_sah = cpu_to_le16((u16)mac_addr[0] << 8 | mac_addr[1]);
626 cmd_data->mac_sal = cpu_to_le32(((u32)mac_addr[2] << 24) |
627 ((u32)mac_addr[3] << 16) |
628 ((u32)mac_addr[4] << 8) |
629 mac_addr[5]);
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +0000630
631 status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
632
633 return status;
634}
635
636/**
637 * i40e_get_mac_addr - get MAC address
638 * @hw: pointer to the HW structure
639 * @mac_addr: pointer to MAC address
640 *
641 * Reads the adapter's MAC address from register
642 **/
643i40e_status i40e_get_mac_addr(struct i40e_hw *hw, u8 *mac_addr)
644{
645 struct i40e_aqc_mac_address_read_data addrs;
646 i40e_status status;
647 u16 flags = 0;
648
649 status = i40e_aq_mac_address_read(hw, &flags, &addrs, NULL);
650
651 if (flags & I40E_AQC_LAN_ADDR_VALID)
652 memcpy(mac_addr, &addrs.pf_lan_mac, sizeof(addrs.pf_lan_mac));
653
654 return status;
655}
656
657/**
Matt Jared351499ab2014-04-23 04:50:03 +0000658 * i40e_pre_tx_queue_cfg - pre tx queue configure
659 * @hw: pointer to the HW structure
660 * @queue: target pf queue index
661 * @enable: state change request
662 *
663 * Handles hw requirement to indicate intention to enable
664 * or disable target queue.
665 **/
666void i40e_pre_tx_queue_cfg(struct i40e_hw *hw, u32 queue, bool enable)
667{
Shannon Nelsondfb699f2014-05-22 06:32:28 +0000668 u32 abs_queue_idx = hw->func_caps.base_queue + queue;
Matt Jared351499ab2014-04-23 04:50:03 +0000669 u32 reg_block = 0;
Shannon Nelsondfb699f2014-05-22 06:32:28 +0000670 u32 reg_val;
Matt Jared351499ab2014-04-23 04:50:03 +0000671
672 if (abs_queue_idx >= 128)
673 reg_block = abs_queue_idx / 128;
674
675 reg_val = rd32(hw, I40E_GLLAN_TXPRE_QDIS(reg_block));
676 reg_val &= ~I40E_GLLAN_TXPRE_QDIS_QINDX_MASK;
677 reg_val |= (abs_queue_idx << I40E_GLLAN_TXPRE_QDIS_QINDX_SHIFT);
678
679 if (enable)
680 reg_val |= I40E_GLLAN_TXPRE_QDIS_CLEAR_QDIS_MASK;
681 else
682 reg_val |= I40E_GLLAN_TXPRE_QDIS_SET_QDIS_MASK;
683
684 wr32(hw, I40E_GLLAN_TXPRE_QDIS(reg_block), reg_val);
685}
686
687/**
Jesse Brandeburgbe405eb2013-11-20 10:02:50 +0000688 * i40e_get_media_type - Gets media type
689 * @hw: pointer to the hardware structure
690 **/
691static enum i40e_media_type i40e_get_media_type(struct i40e_hw *hw)
692{
693 enum i40e_media_type media;
694
695 switch (hw->phy.link_info.phy_type) {
696 case I40E_PHY_TYPE_10GBASE_SR:
697 case I40E_PHY_TYPE_10GBASE_LR:
698 case I40E_PHY_TYPE_40GBASE_SR4:
699 case I40E_PHY_TYPE_40GBASE_LR4:
700 media = I40E_MEDIA_TYPE_FIBER;
701 break;
702 case I40E_PHY_TYPE_100BASE_TX:
703 case I40E_PHY_TYPE_1000BASE_T:
704 case I40E_PHY_TYPE_10GBASE_T:
705 media = I40E_MEDIA_TYPE_BASET;
706 break;
707 case I40E_PHY_TYPE_10GBASE_CR1_CU:
708 case I40E_PHY_TYPE_40GBASE_CR4_CU:
709 case I40E_PHY_TYPE_10GBASE_CR1:
710 case I40E_PHY_TYPE_40GBASE_CR4:
711 case I40E_PHY_TYPE_10GBASE_SFPP_CU:
712 media = I40E_MEDIA_TYPE_DA;
713 break;
714 case I40E_PHY_TYPE_1000BASE_KX:
715 case I40E_PHY_TYPE_10GBASE_KX4:
716 case I40E_PHY_TYPE_10GBASE_KR:
717 case I40E_PHY_TYPE_40GBASE_KR4:
718 media = I40E_MEDIA_TYPE_BACKPLANE;
719 break;
720 case I40E_PHY_TYPE_SGMII:
721 case I40E_PHY_TYPE_XAUI:
722 case I40E_PHY_TYPE_XFI:
723 case I40E_PHY_TYPE_XLAUI:
724 case I40E_PHY_TYPE_XLPPI:
725 default:
726 media = I40E_MEDIA_TYPE_UNKNOWN;
727 break;
728 }
729
730 return media;
731}
732
Jesse Brandeburg7134f9c2013-11-26 08:56:05 +0000733#define I40E_PF_RESET_WAIT_COUNT_A0 200
Shannon Nelsond0ff5682014-04-23 04:50:06 +0000734#define I40E_PF_RESET_WAIT_COUNT 100
Jesse Brandeburgbe405eb2013-11-20 10:02:50 +0000735/**
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +0000736 * i40e_pf_reset - Reset the PF
737 * @hw: pointer to the hardware structure
738 *
739 * Assuming someone else has triggered a global reset,
740 * assure the global reset is complete and then reset the PF
741 **/
742i40e_status i40e_pf_reset(struct i40e_hw *hw)
743{
Jesse Brandeburg7134f9c2013-11-26 08:56:05 +0000744 u32 cnt = 0;
Shannon Nelson42794bd2013-12-11 08:17:10 +0000745 u32 cnt1 = 0;
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +0000746 u32 reg = 0;
747 u32 grst_del;
748
749 /* Poll for Global Reset steady state in case of recent GRST.
750 * The grst delay value is in 100ms units, and we'll wait a
751 * couple counts longer to be sure we don't just miss the end.
752 */
753 grst_del = rd32(hw, I40E_GLGEN_RSTCTL) & I40E_GLGEN_RSTCTL_GRSTDEL_MASK
754 >> I40E_GLGEN_RSTCTL_GRSTDEL_SHIFT;
Jesse Brandeburg7134f9c2013-11-26 08:56:05 +0000755 for (cnt = 0; cnt < grst_del + 2; cnt++) {
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +0000756 reg = rd32(hw, I40E_GLGEN_RSTAT);
757 if (!(reg & I40E_GLGEN_RSTAT_DEVSTATE_MASK))
758 break;
759 msleep(100);
760 }
761 if (reg & I40E_GLGEN_RSTAT_DEVSTATE_MASK) {
762 hw_dbg(hw, "Global reset polling failed to complete.\n");
763 return I40E_ERR_RESET_FAILED;
764 }
765
Shannon Nelson42794bd2013-12-11 08:17:10 +0000766 /* Now Wait for the FW to be ready */
767 for (cnt1 = 0; cnt1 < I40E_PF_RESET_WAIT_COUNT; cnt1++) {
768 reg = rd32(hw, I40E_GLNVM_ULD);
769 reg &= (I40E_GLNVM_ULD_CONF_CORE_DONE_MASK |
770 I40E_GLNVM_ULD_CONF_GLOBAL_DONE_MASK);
771 if (reg == (I40E_GLNVM_ULD_CONF_CORE_DONE_MASK |
772 I40E_GLNVM_ULD_CONF_GLOBAL_DONE_MASK)) {
773 hw_dbg(hw, "Core and Global modules ready %d\n", cnt1);
774 break;
775 }
776 usleep_range(10000, 20000);
777 }
778 if (!(reg & (I40E_GLNVM_ULD_CONF_CORE_DONE_MASK |
779 I40E_GLNVM_ULD_CONF_GLOBAL_DONE_MASK))) {
780 hw_dbg(hw, "wait for FW Reset complete timedout\n");
781 hw_dbg(hw, "I40E_GLNVM_ULD = 0x%x\n", reg);
782 return I40E_ERR_RESET_FAILED;
783 }
784
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +0000785 /* If there was a Global Reset in progress when we got here,
786 * we don't need to do the PF Reset
787 */
Jesse Brandeburg7134f9c2013-11-26 08:56:05 +0000788 if (!cnt) {
789 if (hw->revision_id == 0)
790 cnt = I40E_PF_RESET_WAIT_COUNT_A0;
791 else
792 cnt = I40E_PF_RESET_WAIT_COUNT;
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +0000793 reg = rd32(hw, I40E_PFGEN_CTRL);
794 wr32(hw, I40E_PFGEN_CTRL,
795 (reg | I40E_PFGEN_CTRL_PFSWR_MASK));
Jesse Brandeburg7134f9c2013-11-26 08:56:05 +0000796 for (; cnt; cnt--) {
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +0000797 reg = rd32(hw, I40E_PFGEN_CTRL);
798 if (!(reg & I40E_PFGEN_CTRL_PFSWR_MASK))
799 break;
800 usleep_range(1000, 2000);
801 }
802 if (reg & I40E_PFGEN_CTRL_PFSWR_MASK) {
803 hw_dbg(hw, "PF reset polling failed to complete.\n");
804 return I40E_ERR_RESET_FAILED;
805 }
806 }
807
808 i40e_clear_pxe_mode(hw);
Shannon Nelson922680b2013-12-18 05:29:17 +0000809
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +0000810 return 0;
811}
812
813/**
814 * i40e_clear_pxe_mode - clear pxe operations mode
815 * @hw: pointer to the hw struct
816 *
817 * Make sure all PXE mode settings are cleared, including things
818 * like descriptor fetch/write-back mode.
819 **/
820void i40e_clear_pxe_mode(struct i40e_hw *hw)
821{
822 u32 reg;
823
Shannon Nelsonc9b9b0a2014-04-09 05:59:05 +0000824 if (i40e_check_asq_alive(hw))
825 i40e_aq_clear_pxe_mode(hw, NULL);
826
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +0000827 /* Clear single descriptor fetch/write-back mode */
828 reg = rd32(hw, I40E_GLLAN_RCTL_0);
Jesse Brandeburg7134f9c2013-11-26 08:56:05 +0000829
830 if (hw->revision_id == 0) {
831 /* As a work around clear PXE_MODE instead of setting it */
832 wr32(hw, I40E_GLLAN_RCTL_0, (reg & (~I40E_GLLAN_RCTL_0_PXE_MODE_MASK)));
833 } else {
834 wr32(hw, I40E_GLLAN_RCTL_0, (reg | I40E_GLLAN_RCTL_0_PXE_MODE_MASK));
835 }
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +0000836}
837
838/**
Jesse Brandeburg0556a9e2013-11-28 06:39:33 +0000839 * i40e_led_is_mine - helper to find matching led
840 * @hw: pointer to the hw struct
841 * @idx: index into GPIO registers
842 *
843 * returns: 0 if no match, otherwise the value of the GPIO_CTL register
844 */
845static u32 i40e_led_is_mine(struct i40e_hw *hw, int idx)
846{
847 u32 gpio_val = 0;
848 u32 port;
849
850 if (!hw->func_caps.led[idx])
851 return 0;
852
853 gpio_val = rd32(hw, I40E_GLGEN_GPIO_CTL(idx));
854 port = (gpio_val & I40E_GLGEN_GPIO_CTL_PRT_NUM_MASK) >>
855 I40E_GLGEN_GPIO_CTL_PRT_NUM_SHIFT;
856
857 /* if PRT_NUM_NA is 1 then this LED is not port specific, OR
858 * if it is not our port then ignore
859 */
860 if ((gpio_val & I40E_GLGEN_GPIO_CTL_PRT_NUM_NA_MASK) ||
861 (port != hw->port))
862 return 0;
863
864 return gpio_val;
865}
866
867#define I40E_LED0 22
868#define I40E_LINK_ACTIVITY 0xC
869
870/**
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +0000871 * i40e_led_get - return current on/off mode
872 * @hw: pointer to the hw struct
873 *
874 * The value returned is the 'mode' field as defined in the
875 * GPIO register definitions: 0x0 = off, 0xf = on, and other
876 * values are variations of possible behaviors relating to
877 * blink, link, and wire.
878 **/
879u32 i40e_led_get(struct i40e_hw *hw)
880{
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +0000881 u32 mode = 0;
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +0000882 int i;
883
Jesse Brandeburg0556a9e2013-11-28 06:39:33 +0000884 /* as per the documentation GPIO 22-29 are the LED
885 * GPIO pins named LED0..LED7
886 */
887 for (i = I40E_LED0; i <= I40E_GLGEN_GPIO_CTL_MAX_INDEX; i++) {
888 u32 gpio_val = i40e_led_is_mine(hw, i);
889
890 if (!gpio_val)
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +0000891 continue;
892
Jesse Brandeburg0556a9e2013-11-28 06:39:33 +0000893 mode = (gpio_val & I40E_GLGEN_GPIO_CTL_LED_MODE_MASK) >>
894 I40E_GLGEN_GPIO_CTL_LED_MODE_SHIFT;
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +0000895 break;
896 }
897
898 return mode;
899}
900
901/**
902 * i40e_led_set - set new on/off mode
903 * @hw: pointer to the hw struct
Jesse Brandeburg0556a9e2013-11-28 06:39:33 +0000904 * @mode: 0=off, 0xf=on (else see manual for mode details)
905 * @blink: true if the LED should blink when on, false if steady
906 *
907 * if this function is used to turn on the blink it should
908 * be used to disable the blink when restoring the original state.
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +0000909 **/
Jesse Brandeburg0556a9e2013-11-28 06:39:33 +0000910void i40e_led_set(struct i40e_hw *hw, u32 mode, bool blink)
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +0000911{
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +0000912 int i;
913
Jesse Brandeburg0556a9e2013-11-28 06:39:33 +0000914 if (mode & 0xfffffff0)
915 hw_dbg(hw, "invalid mode passed in %X\n", mode);
916
917 /* as per the documentation GPIO 22-29 are the LED
918 * GPIO pins named LED0..LED7
919 */
920 for (i = I40E_LED0; i <= I40E_GLGEN_GPIO_CTL_MAX_INDEX; i++) {
921 u32 gpio_val = i40e_led_is_mine(hw, i);
922
923 if (!gpio_val)
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +0000924 continue;
925
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +0000926 gpio_val &= ~I40E_GLGEN_GPIO_CTL_LED_MODE_MASK;
Jesse Brandeburg0556a9e2013-11-28 06:39:33 +0000927 /* this & is a bit of paranoia, but serves as a range check */
928 gpio_val |= ((mode << I40E_GLGEN_GPIO_CTL_LED_MODE_SHIFT) &
929 I40E_GLGEN_GPIO_CTL_LED_MODE_MASK);
930
931 if (mode == I40E_LINK_ACTIVITY)
932 blink = false;
933
934 gpio_val |= (blink ? 1 : 0) <<
935 I40E_GLGEN_GPIO_CTL_LED_BLINK_SHIFT;
936
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +0000937 wr32(hw, I40E_GLGEN_GPIO_CTL(i), gpio_val);
Jesse Brandeburg0556a9e2013-11-28 06:39:33 +0000938 break;
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +0000939 }
940}
941
942/* Admin command wrappers */
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +0000943
944/**
Shannon Nelsonc9b9b0a2014-04-09 05:59:05 +0000945 * i40e_aq_clear_pxe_mode
946 * @hw: pointer to the hw struct
947 * @cmd_details: pointer to command details structure or NULL
948 *
949 * Tell the firmware that the driver is taking over from PXE
950 **/
951i40e_status i40e_aq_clear_pxe_mode(struct i40e_hw *hw,
952 struct i40e_asq_cmd_details *cmd_details)
953{
954 i40e_status status;
955 struct i40e_aq_desc desc;
956 struct i40e_aqc_clear_pxe *cmd =
957 (struct i40e_aqc_clear_pxe *)&desc.params.raw;
958
959 i40e_fill_default_direct_cmd_desc(&desc,
960 i40e_aqc_opc_clear_pxe_mode);
961
962 cmd->rx_cnt = 0x2;
963
964 status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
965
966 wr32(hw, I40E_GLLAN_RCTL_0, 0x1);
967
968 return status;
969}
970
971/**
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +0000972 * i40e_aq_set_link_restart_an
973 * @hw: pointer to the hw struct
Catherine Sullivan1ac978a2014-06-04 01:23:20 +0000974 * @enable_link: if true: enable link, if false: disable link
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +0000975 * @cmd_details: pointer to command details structure or NULL
976 *
977 * Sets up the link and restarts the Auto-Negotiation over the link.
978 **/
979i40e_status i40e_aq_set_link_restart_an(struct i40e_hw *hw,
Catherine Sullivan1ac978a2014-06-04 01:23:20 +0000980 bool enable_link,
981 struct i40e_asq_cmd_details *cmd_details)
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +0000982{
983 struct i40e_aq_desc desc;
984 struct i40e_aqc_set_link_restart_an *cmd =
985 (struct i40e_aqc_set_link_restart_an *)&desc.params.raw;
986 i40e_status status;
987
988 i40e_fill_default_direct_cmd_desc(&desc,
989 i40e_aqc_opc_set_link_restart_an);
990
991 cmd->command = I40E_AQ_PHY_RESTART_AN;
Catherine Sullivan1ac978a2014-06-04 01:23:20 +0000992 if (enable_link)
993 cmd->command |= I40E_AQ_PHY_LINK_ENABLE;
994 else
995 cmd->command &= ~I40E_AQ_PHY_LINK_ENABLE;
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +0000996
997 status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
998
999 return status;
1000}
1001
1002/**
1003 * i40e_aq_get_link_info
1004 * @hw: pointer to the hw struct
1005 * @enable_lse: enable/disable LinkStatusEvent reporting
1006 * @link: pointer to link status structure - optional
1007 * @cmd_details: pointer to command details structure or NULL
1008 *
1009 * Returns the link status of the adapter.
1010 **/
1011i40e_status i40e_aq_get_link_info(struct i40e_hw *hw,
1012 bool enable_lse, struct i40e_link_status *link,
1013 struct i40e_asq_cmd_details *cmd_details)
1014{
1015 struct i40e_aq_desc desc;
1016 struct i40e_aqc_get_link_status *resp =
1017 (struct i40e_aqc_get_link_status *)&desc.params.raw;
1018 struct i40e_link_status *hw_link_info = &hw->phy.link_info;
1019 i40e_status status;
1020 u16 command_flags;
1021
1022 i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_get_link_status);
1023
1024 if (enable_lse)
1025 command_flags = I40E_AQ_LSE_ENABLE;
1026 else
1027 command_flags = I40E_AQ_LSE_DISABLE;
1028 resp->command_flags = cpu_to_le16(command_flags);
1029
1030 status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
1031
1032 if (status)
1033 goto aq_get_link_info_exit;
1034
1035 /* save off old link status information */
Mitch Williamsc36bd4a72013-12-18 13:46:04 +00001036 hw->phy.link_info_old = *hw_link_info;
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00001037
1038 /* update link status */
1039 hw_link_info->phy_type = (enum i40e_aq_phy_type)resp->phy_type;
Jesse Brandeburgbe405eb2013-11-20 10:02:50 +00001040 hw->phy.media_type = i40e_get_media_type(hw);
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00001041 hw_link_info->link_speed = (enum i40e_aq_link_speed)resp->link_speed;
1042 hw_link_info->link_info = resp->link_info;
1043 hw_link_info->an_info = resp->an_info;
1044 hw_link_info->ext_info = resp->ext_info;
Kamil Krawczyk639dc372013-11-20 10:03:07 +00001045 hw_link_info->loopback = resp->loopback;
Neerav Parikh6bb3f232014-04-01 07:11:56 +00001046 hw_link_info->max_frame_size = le16_to_cpu(resp->max_frame_size);
1047 hw_link_info->pacing = resp->config & I40E_AQ_CONFIG_PACING_MASK;
1048
1049 if (resp->config & I40E_AQ_CONFIG_CRC_ENA)
1050 hw_link_info->crc_enable = true;
1051 else
1052 hw_link_info->crc_enable = false;
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00001053
1054 if (resp->command_flags & cpu_to_le16(I40E_AQ_LSE_ENABLE))
1055 hw_link_info->lse_enable = true;
1056 else
1057 hw_link_info->lse_enable = false;
1058
1059 /* save link status information */
1060 if (link)
Jesse Brandeburgd7595a22013-09-13 08:23:22 +00001061 *link = *hw_link_info;
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00001062
1063 /* flag cleared so helper functions don't call AQ again */
1064 hw->phy.get_link_info = false;
1065
1066aq_get_link_info_exit:
1067 return status;
1068}
1069
1070/**
1071 * i40e_aq_add_vsi
1072 * @hw: pointer to the hw struct
Jeff Kirsher98d44382013-12-21 05:44:42 +00001073 * @vsi_ctx: pointer to a vsi context struct
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00001074 * @cmd_details: pointer to command details structure or NULL
1075 *
1076 * Add a VSI context to the hardware.
1077**/
1078i40e_status i40e_aq_add_vsi(struct i40e_hw *hw,
1079 struct i40e_vsi_context *vsi_ctx,
1080 struct i40e_asq_cmd_details *cmd_details)
1081{
1082 struct i40e_aq_desc desc;
1083 struct i40e_aqc_add_get_update_vsi *cmd =
1084 (struct i40e_aqc_add_get_update_vsi *)&desc.params.raw;
1085 struct i40e_aqc_add_get_update_vsi_completion *resp =
1086 (struct i40e_aqc_add_get_update_vsi_completion *)
1087 &desc.params.raw;
1088 i40e_status status;
1089
1090 i40e_fill_default_direct_cmd_desc(&desc,
1091 i40e_aqc_opc_add_vsi);
1092
1093 cmd->uplink_seid = cpu_to_le16(vsi_ctx->uplink_seid);
1094 cmd->connection_type = vsi_ctx->connection_type;
1095 cmd->vf_id = vsi_ctx->vf_num;
1096 cmd->vsi_flags = cpu_to_le16(vsi_ctx->flags);
1097
1098 desc.flags |= cpu_to_le16((u16)(I40E_AQ_FLAG_BUF | I40E_AQ_FLAG_RD));
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00001099
1100 status = i40e_asq_send_command(hw, &desc, &vsi_ctx->info,
1101 sizeof(vsi_ctx->info), cmd_details);
1102
1103 if (status)
1104 goto aq_add_vsi_exit;
1105
1106 vsi_ctx->seid = le16_to_cpu(resp->seid);
1107 vsi_ctx->vsi_number = le16_to_cpu(resp->vsi_number);
1108 vsi_ctx->vsis_allocated = le16_to_cpu(resp->vsi_used);
1109 vsi_ctx->vsis_unallocated = le16_to_cpu(resp->vsi_free);
1110
1111aq_add_vsi_exit:
1112 return status;
1113}
1114
1115/**
1116 * i40e_aq_set_vsi_unicast_promiscuous
1117 * @hw: pointer to the hw struct
1118 * @seid: vsi number
1119 * @set: set unicast promiscuous enable/disable
1120 * @cmd_details: pointer to command details structure or NULL
1121 **/
1122i40e_status i40e_aq_set_vsi_unicast_promiscuous(struct i40e_hw *hw,
Mitch Williams885552a2013-12-21 05:44:41 +00001123 u16 seid, bool set,
1124 struct i40e_asq_cmd_details *cmd_details)
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00001125{
1126 struct i40e_aq_desc desc;
1127 struct i40e_aqc_set_vsi_promiscuous_modes *cmd =
1128 (struct i40e_aqc_set_vsi_promiscuous_modes *)&desc.params.raw;
1129 i40e_status status;
1130 u16 flags = 0;
1131
1132 i40e_fill_default_direct_cmd_desc(&desc,
1133 i40e_aqc_opc_set_vsi_promiscuous_modes);
1134
1135 if (set)
1136 flags |= I40E_AQC_SET_VSI_PROMISC_UNICAST;
1137
1138 cmd->promiscuous_flags = cpu_to_le16(flags);
1139
1140 cmd->valid_flags = cpu_to_le16(I40E_AQC_SET_VSI_PROMISC_UNICAST);
1141
1142 cmd->seid = cpu_to_le16(seid);
1143 status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
1144
1145 return status;
1146}
1147
1148/**
1149 * i40e_aq_set_vsi_multicast_promiscuous
1150 * @hw: pointer to the hw struct
1151 * @seid: vsi number
1152 * @set: set multicast promiscuous enable/disable
1153 * @cmd_details: pointer to command details structure or NULL
1154 **/
1155i40e_status i40e_aq_set_vsi_multicast_promiscuous(struct i40e_hw *hw,
1156 u16 seid, bool set, struct i40e_asq_cmd_details *cmd_details)
1157{
1158 struct i40e_aq_desc desc;
1159 struct i40e_aqc_set_vsi_promiscuous_modes *cmd =
1160 (struct i40e_aqc_set_vsi_promiscuous_modes *)&desc.params.raw;
1161 i40e_status status;
1162 u16 flags = 0;
1163
1164 i40e_fill_default_direct_cmd_desc(&desc,
1165 i40e_aqc_opc_set_vsi_promiscuous_modes);
1166
1167 if (set)
1168 flags |= I40E_AQC_SET_VSI_PROMISC_MULTICAST;
1169
1170 cmd->promiscuous_flags = cpu_to_le16(flags);
1171
1172 cmd->valid_flags = cpu_to_le16(I40E_AQC_SET_VSI_PROMISC_MULTICAST);
1173
1174 cmd->seid = cpu_to_le16(seid);
1175 status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
1176
1177 return status;
1178}
1179
1180/**
1181 * i40e_aq_set_vsi_broadcast
1182 * @hw: pointer to the hw struct
1183 * @seid: vsi number
1184 * @set_filter: true to set filter, false to clear filter
1185 * @cmd_details: pointer to command details structure or NULL
1186 *
1187 * Set or clear the broadcast promiscuous flag (filter) for a given VSI.
1188 **/
1189i40e_status i40e_aq_set_vsi_broadcast(struct i40e_hw *hw,
1190 u16 seid, bool set_filter,
1191 struct i40e_asq_cmd_details *cmd_details)
1192{
1193 struct i40e_aq_desc desc;
1194 struct i40e_aqc_set_vsi_promiscuous_modes *cmd =
1195 (struct i40e_aqc_set_vsi_promiscuous_modes *)&desc.params.raw;
1196 i40e_status status;
1197
1198 i40e_fill_default_direct_cmd_desc(&desc,
1199 i40e_aqc_opc_set_vsi_promiscuous_modes);
1200
1201 if (set_filter)
1202 cmd->promiscuous_flags
1203 |= cpu_to_le16(I40E_AQC_SET_VSI_PROMISC_BROADCAST);
1204 else
1205 cmd->promiscuous_flags
1206 &= cpu_to_le16(~I40E_AQC_SET_VSI_PROMISC_BROADCAST);
1207
1208 cmd->valid_flags = cpu_to_le16(I40E_AQC_SET_VSI_PROMISC_BROADCAST);
1209 cmd->seid = cpu_to_le16(seid);
1210 status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
1211
1212 return status;
1213}
1214
1215/**
1216 * i40e_get_vsi_params - get VSI configuration info
1217 * @hw: pointer to the hw struct
Jeff Kirsher98d44382013-12-21 05:44:42 +00001218 * @vsi_ctx: pointer to a vsi context struct
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00001219 * @cmd_details: pointer to command details structure or NULL
1220 **/
1221i40e_status i40e_aq_get_vsi_params(struct i40e_hw *hw,
1222 struct i40e_vsi_context *vsi_ctx,
1223 struct i40e_asq_cmd_details *cmd_details)
1224{
1225 struct i40e_aq_desc desc;
Shannon Nelsonf5ac8572013-11-28 06:39:43 +00001226 struct i40e_aqc_add_get_update_vsi *cmd =
1227 (struct i40e_aqc_add_get_update_vsi *)&desc.params.raw;
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00001228 struct i40e_aqc_add_get_update_vsi_completion *resp =
1229 (struct i40e_aqc_add_get_update_vsi_completion *)
1230 &desc.params.raw;
1231 i40e_status status;
1232
1233 i40e_fill_default_direct_cmd_desc(&desc,
1234 i40e_aqc_opc_get_vsi_parameters);
1235
Shannon Nelsonf5ac8572013-11-28 06:39:43 +00001236 cmd->uplink_seid = cpu_to_le16(vsi_ctx->seid);
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00001237
1238 desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_BUF);
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00001239
1240 status = i40e_asq_send_command(hw, &desc, &vsi_ctx->info,
1241 sizeof(vsi_ctx->info), NULL);
1242
1243 if (status)
1244 goto aq_get_vsi_params_exit;
1245
1246 vsi_ctx->seid = le16_to_cpu(resp->seid);
1247 vsi_ctx->vsi_number = le16_to_cpu(resp->vsi_number);
1248 vsi_ctx->vsis_allocated = le16_to_cpu(resp->vsi_used);
1249 vsi_ctx->vsis_unallocated = le16_to_cpu(resp->vsi_free);
1250
1251aq_get_vsi_params_exit:
1252 return status;
1253}
1254
1255/**
1256 * i40e_aq_update_vsi_params
1257 * @hw: pointer to the hw struct
Jeff Kirsher98d44382013-12-21 05:44:42 +00001258 * @vsi_ctx: pointer to a vsi context struct
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00001259 * @cmd_details: pointer to command details structure or NULL
1260 *
1261 * Update a VSI context.
1262 **/
1263i40e_status i40e_aq_update_vsi_params(struct i40e_hw *hw,
1264 struct i40e_vsi_context *vsi_ctx,
1265 struct i40e_asq_cmd_details *cmd_details)
1266{
1267 struct i40e_aq_desc desc;
Shannon Nelsonf5ac8572013-11-28 06:39:43 +00001268 struct i40e_aqc_add_get_update_vsi *cmd =
1269 (struct i40e_aqc_add_get_update_vsi *)&desc.params.raw;
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00001270 i40e_status status;
1271
1272 i40e_fill_default_direct_cmd_desc(&desc,
1273 i40e_aqc_opc_update_vsi_parameters);
Shannon Nelsonf5ac8572013-11-28 06:39:43 +00001274 cmd->uplink_seid = cpu_to_le16(vsi_ctx->seid);
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00001275
1276 desc.flags |= cpu_to_le16((u16)(I40E_AQ_FLAG_BUF | I40E_AQ_FLAG_RD));
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00001277
1278 status = i40e_asq_send_command(hw, &desc, &vsi_ctx->info,
1279 sizeof(vsi_ctx->info), cmd_details);
1280
1281 return status;
1282}
1283
1284/**
1285 * i40e_aq_get_switch_config
1286 * @hw: pointer to the hardware structure
1287 * @buf: pointer to the result buffer
1288 * @buf_size: length of input buffer
1289 * @start_seid: seid to start for the report, 0 == beginning
1290 * @cmd_details: pointer to command details structure or NULL
1291 *
1292 * Fill the buf with switch configuration returned from AdminQ command
1293 **/
1294i40e_status i40e_aq_get_switch_config(struct i40e_hw *hw,
1295 struct i40e_aqc_get_switch_config_resp *buf,
1296 u16 buf_size, u16 *start_seid,
1297 struct i40e_asq_cmd_details *cmd_details)
1298{
1299 struct i40e_aq_desc desc;
1300 struct i40e_aqc_switch_seid *scfg =
1301 (struct i40e_aqc_switch_seid *)&desc.params.raw;
1302 i40e_status status;
1303
1304 i40e_fill_default_direct_cmd_desc(&desc,
1305 i40e_aqc_opc_get_switch_config);
1306 desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_BUF);
1307 if (buf_size > I40E_AQ_LARGE_BUF)
1308 desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_LB);
1309 scfg->seid = cpu_to_le16(*start_seid);
1310
1311 status = i40e_asq_send_command(hw, &desc, buf, buf_size, cmd_details);
1312 *start_seid = le16_to_cpu(scfg->seid);
1313
1314 return status;
1315}
1316
1317/**
1318 * i40e_aq_get_firmware_version
1319 * @hw: pointer to the hw struct
1320 * @fw_major_version: firmware major version
1321 * @fw_minor_version: firmware minor version
1322 * @api_major_version: major queue version
1323 * @api_minor_version: minor queue version
1324 * @cmd_details: pointer to command details structure or NULL
1325 *
1326 * Get the firmware version from the admin queue commands
1327 **/
1328i40e_status i40e_aq_get_firmware_version(struct i40e_hw *hw,
1329 u16 *fw_major_version, u16 *fw_minor_version,
1330 u16 *api_major_version, u16 *api_minor_version,
1331 struct i40e_asq_cmd_details *cmd_details)
1332{
1333 struct i40e_aq_desc desc;
1334 struct i40e_aqc_get_version *resp =
1335 (struct i40e_aqc_get_version *)&desc.params.raw;
1336 i40e_status status;
1337
1338 i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_get_version);
1339
1340 status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
1341
1342 if (!status) {
1343 if (fw_major_version != NULL)
1344 *fw_major_version = le16_to_cpu(resp->fw_major);
1345 if (fw_minor_version != NULL)
1346 *fw_minor_version = le16_to_cpu(resp->fw_minor);
1347 if (api_major_version != NULL)
1348 *api_major_version = le16_to_cpu(resp->api_major);
1349 if (api_minor_version != NULL)
1350 *api_minor_version = le16_to_cpu(resp->api_minor);
1351 }
1352
1353 return status;
1354}
1355
1356/**
1357 * i40e_aq_send_driver_version
1358 * @hw: pointer to the hw struct
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00001359 * @dv: driver's major, minor version
1360 * @cmd_details: pointer to command details structure or NULL
1361 *
1362 * Send the driver version to the firmware
1363 **/
1364i40e_status i40e_aq_send_driver_version(struct i40e_hw *hw,
1365 struct i40e_driver_version *dv,
1366 struct i40e_asq_cmd_details *cmd_details)
1367{
1368 struct i40e_aq_desc desc;
1369 struct i40e_aqc_driver_version *cmd =
1370 (struct i40e_aqc_driver_version *)&desc.params.raw;
1371 i40e_status status;
Kevin Scott9d2f98e2014-04-01 07:11:52 +00001372 u16 len;
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00001373
1374 if (dv == NULL)
1375 return I40E_ERR_PARAM;
1376
1377 i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_driver_version);
1378
1379 desc.flags |= cpu_to_le16(I40E_AQ_FLAG_SI);
1380 cmd->driver_major_ver = dv->major_version;
1381 cmd->driver_minor_ver = dv->minor_version;
1382 cmd->driver_build_ver = dv->build_version;
1383 cmd->driver_subbuild_ver = dv->subbuild_version;
Shannon Nelsond2466012014-04-01 07:11:45 +00001384
1385 len = 0;
1386 while (len < sizeof(dv->driver_string) &&
1387 (dv->driver_string[len] < 0x80) &&
1388 dv->driver_string[len])
1389 len++;
1390 status = i40e_asq_send_command(hw, &desc, dv->driver_string,
1391 len, cmd_details);
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00001392
1393 return status;
1394}
1395
1396/**
1397 * i40e_get_link_status - get status of the HW network link
1398 * @hw: pointer to the hw struct
1399 *
1400 * Returns true if link is up, false if link is down.
1401 *
1402 * Side effect: LinkStatusEvent reporting becomes enabled
1403 **/
1404bool i40e_get_link_status(struct i40e_hw *hw)
1405{
1406 i40e_status status = 0;
1407 bool link_status = false;
1408
1409 if (hw->phy.get_link_info) {
1410 status = i40e_aq_get_link_info(hw, true, NULL, NULL);
1411
1412 if (status)
1413 goto i40e_get_link_status_exit;
1414 }
1415
1416 link_status = hw->phy.link_info.link_info & I40E_AQ_LINK_UP;
1417
1418i40e_get_link_status_exit:
1419 return link_status;
1420}
1421
1422/**
1423 * i40e_aq_add_veb - Insert a VEB between the VSI and the MAC
1424 * @hw: pointer to the hw struct
1425 * @uplink_seid: the MAC or other gizmo SEID
1426 * @downlink_seid: the VSI SEID
1427 * @enabled_tc: bitmap of TCs to be enabled
1428 * @default_port: true for default port VSI, false for control port
Kevin Scotte1c51b952013-11-20 10:02:51 +00001429 * @enable_l2_filtering: true to add L2 filter table rules to regular forwarding rules for cloud support
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00001430 * @veb_seid: pointer to where to put the resulting VEB SEID
1431 * @cmd_details: pointer to command details structure or NULL
1432 *
1433 * This asks the FW to add a VEB between the uplink and downlink
1434 * elements. If the uplink SEID is 0, this will be a floating VEB.
1435 **/
1436i40e_status i40e_aq_add_veb(struct i40e_hw *hw, u16 uplink_seid,
1437 u16 downlink_seid, u8 enabled_tc,
Kevin Scotte1c51b952013-11-20 10:02:51 +00001438 bool default_port, bool enable_l2_filtering,
1439 u16 *veb_seid,
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00001440 struct i40e_asq_cmd_details *cmd_details)
1441{
1442 struct i40e_aq_desc desc;
1443 struct i40e_aqc_add_veb *cmd =
1444 (struct i40e_aqc_add_veb *)&desc.params.raw;
1445 struct i40e_aqc_add_veb_completion *resp =
1446 (struct i40e_aqc_add_veb_completion *)&desc.params.raw;
1447 i40e_status status;
1448 u16 veb_flags = 0;
1449
1450 /* SEIDs need to either both be set or both be 0 for floating VEB */
1451 if (!!uplink_seid != !!downlink_seid)
1452 return I40E_ERR_PARAM;
1453
1454 i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_add_veb);
1455
1456 cmd->uplink_seid = cpu_to_le16(uplink_seid);
1457 cmd->downlink_seid = cpu_to_le16(downlink_seid);
1458 cmd->enable_tcs = enabled_tc;
1459 if (!uplink_seid)
1460 veb_flags |= I40E_AQC_ADD_VEB_FLOATING;
1461 if (default_port)
1462 veb_flags |= I40E_AQC_ADD_VEB_PORT_TYPE_DEFAULT;
1463 else
1464 veb_flags |= I40E_AQC_ADD_VEB_PORT_TYPE_DATA;
Kevin Scotte1c51b952013-11-20 10:02:51 +00001465
1466 if (enable_l2_filtering)
1467 veb_flags |= I40E_AQC_ADD_VEB_ENABLE_L2_FILTER;
1468
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00001469 cmd->veb_flags = cpu_to_le16(veb_flags);
1470
1471 status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
1472
1473 if (!status && veb_seid)
1474 *veb_seid = le16_to_cpu(resp->veb_seid);
1475
1476 return status;
1477}
1478
1479/**
1480 * i40e_aq_get_veb_parameters - Retrieve VEB parameters
1481 * @hw: pointer to the hw struct
1482 * @veb_seid: the SEID of the VEB to query
1483 * @switch_id: the uplink switch id
Jeff Kirsher98d44382013-12-21 05:44:42 +00001484 * @floating: set to true if the VEB is floating
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00001485 * @statistic_index: index of the stats counter block for this VEB
1486 * @vebs_used: number of VEB's used by function
Jeff Kirsher98d44382013-12-21 05:44:42 +00001487 * @vebs_free: total VEB's not reserved by any function
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00001488 * @cmd_details: pointer to command details structure or NULL
1489 *
1490 * This retrieves the parameters for a particular VEB, specified by
1491 * uplink_seid, and returns them to the caller.
1492 **/
1493i40e_status i40e_aq_get_veb_parameters(struct i40e_hw *hw,
1494 u16 veb_seid, u16 *switch_id,
1495 bool *floating, u16 *statistic_index,
1496 u16 *vebs_used, u16 *vebs_free,
1497 struct i40e_asq_cmd_details *cmd_details)
1498{
1499 struct i40e_aq_desc desc;
1500 struct i40e_aqc_get_veb_parameters_completion *cmd_resp =
1501 (struct i40e_aqc_get_veb_parameters_completion *)
1502 &desc.params.raw;
1503 i40e_status status;
1504
1505 if (veb_seid == 0)
1506 return I40E_ERR_PARAM;
1507
1508 i40e_fill_default_direct_cmd_desc(&desc,
1509 i40e_aqc_opc_get_veb_parameters);
1510 cmd_resp->seid = cpu_to_le16(veb_seid);
1511
1512 status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
1513 if (status)
1514 goto get_veb_exit;
1515
1516 if (switch_id)
1517 *switch_id = le16_to_cpu(cmd_resp->switch_id);
1518 if (statistic_index)
1519 *statistic_index = le16_to_cpu(cmd_resp->statistic_index);
1520 if (vebs_used)
1521 *vebs_used = le16_to_cpu(cmd_resp->vebs_used);
1522 if (vebs_free)
1523 *vebs_free = le16_to_cpu(cmd_resp->vebs_free);
1524 if (floating) {
1525 u16 flags = le16_to_cpu(cmd_resp->veb_flags);
1526 if (flags & I40E_AQC_ADD_VEB_FLOATING)
1527 *floating = true;
1528 else
1529 *floating = false;
1530 }
1531
1532get_veb_exit:
1533 return status;
1534}
1535
1536/**
1537 * i40e_aq_add_macvlan
1538 * @hw: pointer to the hw struct
1539 * @seid: VSI for the mac address
1540 * @mv_list: list of macvlans to be added
1541 * @count: length of the list
1542 * @cmd_details: pointer to command details structure or NULL
1543 *
1544 * Add MAC/VLAN addresses to the HW filtering
1545 **/
1546i40e_status i40e_aq_add_macvlan(struct i40e_hw *hw, u16 seid,
1547 struct i40e_aqc_add_macvlan_element_data *mv_list,
1548 u16 count, struct i40e_asq_cmd_details *cmd_details)
1549{
1550 struct i40e_aq_desc desc;
1551 struct i40e_aqc_macvlan *cmd =
1552 (struct i40e_aqc_macvlan *)&desc.params.raw;
1553 i40e_status status;
1554 u16 buf_size;
1555
1556 if (count == 0 || !mv_list || !hw)
1557 return I40E_ERR_PARAM;
1558
1559 buf_size = count * sizeof(struct i40e_aqc_add_macvlan_element_data);
1560
1561 /* prep the rest of the request */
1562 i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_add_macvlan);
1563 cmd->num_addresses = cpu_to_le16(count);
1564 cmd->seid[0] = cpu_to_le16(I40E_AQC_MACVLAN_CMD_SEID_VALID | seid);
1565 cmd->seid[1] = 0;
1566 cmd->seid[2] = 0;
1567
1568 desc.flags |= cpu_to_le16((u16)(I40E_AQ_FLAG_BUF | I40E_AQ_FLAG_RD));
1569 if (buf_size > I40E_AQ_LARGE_BUF)
1570 desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_LB);
1571
1572 status = i40e_asq_send_command(hw, &desc, mv_list, buf_size,
1573 cmd_details);
1574
1575 return status;
1576}
1577
1578/**
1579 * i40e_aq_remove_macvlan
1580 * @hw: pointer to the hw struct
1581 * @seid: VSI for the mac address
1582 * @mv_list: list of macvlans to be removed
1583 * @count: length of the list
1584 * @cmd_details: pointer to command details structure or NULL
1585 *
1586 * Remove MAC/VLAN addresses from the HW filtering
1587 **/
1588i40e_status i40e_aq_remove_macvlan(struct i40e_hw *hw, u16 seid,
1589 struct i40e_aqc_remove_macvlan_element_data *mv_list,
1590 u16 count, struct i40e_asq_cmd_details *cmd_details)
1591{
1592 struct i40e_aq_desc desc;
1593 struct i40e_aqc_macvlan *cmd =
1594 (struct i40e_aqc_macvlan *)&desc.params.raw;
1595 i40e_status status;
1596 u16 buf_size;
1597
1598 if (count == 0 || !mv_list || !hw)
1599 return I40E_ERR_PARAM;
1600
1601 buf_size = count * sizeof(struct i40e_aqc_remove_macvlan_element_data);
1602
1603 /* prep the rest of the request */
1604 i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_remove_macvlan);
1605 cmd->num_addresses = cpu_to_le16(count);
1606 cmd->seid[0] = cpu_to_le16(I40E_AQC_MACVLAN_CMD_SEID_VALID | seid);
1607 cmd->seid[1] = 0;
1608 cmd->seid[2] = 0;
1609
1610 desc.flags |= cpu_to_le16((u16)(I40E_AQ_FLAG_BUF | I40E_AQ_FLAG_RD));
1611 if (buf_size > I40E_AQ_LARGE_BUF)
1612 desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_LB);
1613
1614 status = i40e_asq_send_command(hw, &desc, mv_list, buf_size,
1615 cmd_details);
1616
1617 return status;
1618}
1619
1620/**
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00001621 * i40e_aq_send_msg_to_vf
1622 * @hw: pointer to the hardware structure
1623 * @vfid: vf id to send msg
Jeff Kirsher98d44382013-12-21 05:44:42 +00001624 * @v_opcode: opcodes for VF-PF communication
1625 * @v_retval: return error code
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00001626 * @msg: pointer to the msg buffer
1627 * @msglen: msg length
1628 * @cmd_details: pointer to command details
1629 *
1630 * send msg to vf
1631 **/
1632i40e_status i40e_aq_send_msg_to_vf(struct i40e_hw *hw, u16 vfid,
1633 u32 v_opcode, u32 v_retval, u8 *msg, u16 msglen,
1634 struct i40e_asq_cmd_details *cmd_details)
1635{
1636 struct i40e_aq_desc desc;
1637 struct i40e_aqc_pf_vf_message *cmd =
1638 (struct i40e_aqc_pf_vf_message *)&desc.params.raw;
1639 i40e_status status;
1640
1641 i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_send_msg_to_vf);
1642 cmd->id = cpu_to_le32(vfid);
1643 desc.cookie_high = cpu_to_le32(v_opcode);
1644 desc.cookie_low = cpu_to_le32(v_retval);
1645 desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_SI);
1646 if (msglen) {
1647 desc.flags |= cpu_to_le16((u16)(I40E_AQ_FLAG_BUF |
1648 I40E_AQ_FLAG_RD));
1649 if (msglen > I40E_AQ_LARGE_BUF)
1650 desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_LB);
1651 desc.datalen = cpu_to_le16(msglen);
1652 }
1653 status = i40e_asq_send_command(hw, &desc, msg, msglen, cmd_details);
1654
1655 return status;
1656}
1657
1658/**
1659 * i40e_aq_set_hmc_resource_profile
1660 * @hw: pointer to the hw struct
1661 * @profile: type of profile the HMC is to be set as
1662 * @pe_vf_enabled_count: the number of PE enabled VFs the system has
1663 * @cmd_details: pointer to command details structure or NULL
1664 *
1665 * set the HMC profile of the device.
1666 **/
1667i40e_status i40e_aq_set_hmc_resource_profile(struct i40e_hw *hw,
1668 enum i40e_aq_hmc_profile profile,
1669 u8 pe_vf_enabled_count,
1670 struct i40e_asq_cmd_details *cmd_details)
1671{
1672 struct i40e_aq_desc desc;
1673 struct i40e_aq_get_set_hmc_resource_profile *cmd =
1674 (struct i40e_aq_get_set_hmc_resource_profile *)&desc.params.raw;
1675 i40e_status status;
1676
1677 i40e_fill_default_direct_cmd_desc(&desc,
1678 i40e_aqc_opc_set_hmc_resource_profile);
1679
1680 cmd->pm_profile = (u8)profile;
1681 cmd->pe_vf_enabled = pe_vf_enabled_count;
1682
1683 status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
1684
1685 return status;
1686}
1687
1688/**
1689 * i40e_aq_request_resource
1690 * @hw: pointer to the hw struct
1691 * @resource: resource id
1692 * @access: access type
1693 * @sdp_number: resource number
1694 * @timeout: the maximum time in ms that the driver may hold the resource
1695 * @cmd_details: pointer to command details structure or NULL
1696 *
1697 * requests common resource using the admin queue commands
1698 **/
1699i40e_status i40e_aq_request_resource(struct i40e_hw *hw,
1700 enum i40e_aq_resources_ids resource,
1701 enum i40e_aq_resource_access_type access,
1702 u8 sdp_number, u64 *timeout,
1703 struct i40e_asq_cmd_details *cmd_details)
1704{
1705 struct i40e_aq_desc desc;
1706 struct i40e_aqc_request_resource *cmd_resp =
1707 (struct i40e_aqc_request_resource *)&desc.params.raw;
1708 i40e_status status;
1709
1710 i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_request_resource);
1711
1712 cmd_resp->resource_id = cpu_to_le16(resource);
1713 cmd_resp->access_type = cpu_to_le16(access);
1714 cmd_resp->resource_number = cpu_to_le32(sdp_number);
1715
1716 status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
1717 /* The completion specifies the maximum time in ms that the driver
1718 * may hold the resource in the Timeout field.
1719 * If the resource is held by someone else, the command completes with
1720 * busy return value and the timeout field indicates the maximum time
1721 * the current owner of the resource has to free it.
1722 */
1723 if (!status || hw->aq.asq_last_status == I40E_AQ_RC_EBUSY)
1724 *timeout = le32_to_cpu(cmd_resp->timeout);
1725
1726 return status;
1727}
1728
1729/**
1730 * i40e_aq_release_resource
1731 * @hw: pointer to the hw struct
1732 * @resource: resource id
1733 * @sdp_number: resource number
1734 * @cmd_details: pointer to command details structure or NULL
1735 *
1736 * release common resource using the admin queue commands
1737 **/
1738i40e_status i40e_aq_release_resource(struct i40e_hw *hw,
1739 enum i40e_aq_resources_ids resource,
1740 u8 sdp_number,
1741 struct i40e_asq_cmd_details *cmd_details)
1742{
1743 struct i40e_aq_desc desc;
1744 struct i40e_aqc_request_resource *cmd =
1745 (struct i40e_aqc_request_resource *)&desc.params.raw;
1746 i40e_status status;
1747
1748 i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_release_resource);
1749
1750 cmd->resource_id = cpu_to_le16(resource);
1751 cmd->resource_number = cpu_to_le32(sdp_number);
1752
1753 status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
1754
1755 return status;
1756}
1757
1758/**
1759 * i40e_aq_read_nvm
1760 * @hw: pointer to the hw struct
1761 * @module_pointer: module pointer location in words from the NVM beginning
1762 * @offset: byte offset from the module beginning
1763 * @length: length of the section to be read (in bytes from the offset)
1764 * @data: command buffer (size [bytes] = length)
1765 * @last_command: tells if this is the last command in a series
1766 * @cmd_details: pointer to command details structure or NULL
1767 *
1768 * Read the NVM using the admin queue commands
1769 **/
1770i40e_status i40e_aq_read_nvm(struct i40e_hw *hw, u8 module_pointer,
1771 u32 offset, u16 length, void *data,
1772 bool last_command,
1773 struct i40e_asq_cmd_details *cmd_details)
1774{
1775 struct i40e_aq_desc desc;
1776 struct i40e_aqc_nvm_update *cmd =
1777 (struct i40e_aqc_nvm_update *)&desc.params.raw;
1778 i40e_status status;
1779
1780 /* In offset the highest byte must be zeroed. */
1781 if (offset & 0xFF000000) {
1782 status = I40E_ERR_PARAM;
1783 goto i40e_aq_read_nvm_exit;
1784 }
1785
1786 i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_nvm_read);
1787
1788 /* If this is the last command in a series, set the proper flag. */
1789 if (last_command)
1790 cmd->command_flags |= I40E_AQ_NVM_LAST_CMD;
1791 cmd->module_pointer = module_pointer;
1792 cmd->offset = cpu_to_le32(offset);
1793 cmd->length = cpu_to_le16(length);
1794
1795 desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_BUF);
1796 if (length > I40E_AQ_LARGE_BUF)
1797 desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_LB);
1798
1799 status = i40e_asq_send_command(hw, &desc, data, length, cmd_details);
1800
1801i40e_aq_read_nvm_exit:
1802 return status;
1803}
1804
1805#define I40E_DEV_FUNC_CAP_SWITCH_MODE 0x01
1806#define I40E_DEV_FUNC_CAP_MGMT_MODE 0x02
1807#define I40E_DEV_FUNC_CAP_NPAR 0x03
1808#define I40E_DEV_FUNC_CAP_OS2BMC 0x04
1809#define I40E_DEV_FUNC_CAP_VALID_FUNC 0x05
1810#define I40E_DEV_FUNC_CAP_SRIOV_1_1 0x12
1811#define I40E_DEV_FUNC_CAP_VF 0x13
1812#define I40E_DEV_FUNC_CAP_VMDQ 0x14
1813#define I40E_DEV_FUNC_CAP_802_1_QBG 0x15
1814#define I40E_DEV_FUNC_CAP_802_1_QBH 0x16
1815#define I40E_DEV_FUNC_CAP_VSI 0x17
1816#define I40E_DEV_FUNC_CAP_DCB 0x18
1817#define I40E_DEV_FUNC_CAP_FCOE 0x21
1818#define I40E_DEV_FUNC_CAP_RSS 0x40
1819#define I40E_DEV_FUNC_CAP_RX_QUEUES 0x41
1820#define I40E_DEV_FUNC_CAP_TX_QUEUES 0x42
1821#define I40E_DEV_FUNC_CAP_MSIX 0x43
1822#define I40E_DEV_FUNC_CAP_MSIX_VF 0x44
1823#define I40E_DEV_FUNC_CAP_FLOW_DIRECTOR 0x45
1824#define I40E_DEV_FUNC_CAP_IEEE_1588 0x46
1825#define I40E_DEV_FUNC_CAP_MFP_MODE_1 0xF1
1826#define I40E_DEV_FUNC_CAP_CEM 0xF2
1827#define I40E_DEV_FUNC_CAP_IWARP 0x51
1828#define I40E_DEV_FUNC_CAP_LED 0x61
1829#define I40E_DEV_FUNC_CAP_SDP 0x62
1830#define I40E_DEV_FUNC_CAP_MDIO 0x63
1831
1832/**
1833 * i40e_parse_discover_capabilities
1834 * @hw: pointer to the hw struct
1835 * @buff: pointer to a buffer containing device/function capability records
1836 * @cap_count: number of capability records in the list
1837 * @list_type_opc: type of capabilities list to parse
1838 *
1839 * Parse the device/function capabilities list.
1840 **/
1841static void i40e_parse_discover_capabilities(struct i40e_hw *hw, void *buff,
1842 u32 cap_count,
1843 enum i40e_admin_queue_opc list_type_opc)
1844{
1845 struct i40e_aqc_list_capabilities_element_resp *cap;
1846 u32 number, logical_id, phys_id;
1847 struct i40e_hw_capabilities *p;
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00001848 u32 i = 0;
1849 u16 id;
1850
1851 cap = (struct i40e_aqc_list_capabilities_element_resp *) buff;
1852
1853 if (list_type_opc == i40e_aqc_opc_list_dev_capabilities)
Joe Perchesb58f2f72014-03-25 04:30:32 +00001854 p = &hw->dev_caps;
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00001855 else if (list_type_opc == i40e_aqc_opc_list_func_capabilities)
Joe Perchesb58f2f72014-03-25 04:30:32 +00001856 p = &hw->func_caps;
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00001857 else
1858 return;
1859
1860 for (i = 0; i < cap_count; i++, cap++) {
1861 id = le16_to_cpu(cap->id);
1862 number = le32_to_cpu(cap->number);
1863 logical_id = le32_to_cpu(cap->logical_id);
1864 phys_id = le32_to_cpu(cap->phys_id);
1865
1866 switch (id) {
1867 case I40E_DEV_FUNC_CAP_SWITCH_MODE:
1868 p->switch_mode = number;
1869 break;
1870 case I40E_DEV_FUNC_CAP_MGMT_MODE:
1871 p->management_mode = number;
1872 break;
1873 case I40E_DEV_FUNC_CAP_NPAR:
1874 p->npar_enable = number;
1875 break;
1876 case I40E_DEV_FUNC_CAP_OS2BMC:
1877 p->os2bmc = number;
1878 break;
1879 case I40E_DEV_FUNC_CAP_VALID_FUNC:
1880 p->valid_functions = number;
1881 break;
1882 case I40E_DEV_FUNC_CAP_SRIOV_1_1:
1883 if (number == 1)
1884 p->sr_iov_1_1 = true;
1885 break;
1886 case I40E_DEV_FUNC_CAP_VF:
1887 p->num_vfs = number;
1888 p->vf_base_id = logical_id;
1889 break;
1890 case I40E_DEV_FUNC_CAP_VMDQ:
1891 if (number == 1)
1892 p->vmdq = true;
1893 break;
1894 case I40E_DEV_FUNC_CAP_802_1_QBG:
1895 if (number == 1)
1896 p->evb_802_1_qbg = true;
1897 break;
1898 case I40E_DEV_FUNC_CAP_802_1_QBH:
1899 if (number == 1)
1900 p->evb_802_1_qbh = true;
1901 break;
1902 case I40E_DEV_FUNC_CAP_VSI:
1903 p->num_vsis = number;
1904 break;
1905 case I40E_DEV_FUNC_CAP_DCB:
1906 if (number == 1) {
1907 p->dcb = true;
1908 p->enabled_tcmap = logical_id;
1909 p->maxtc = phys_id;
1910 }
1911 break;
1912 case I40E_DEV_FUNC_CAP_FCOE:
1913 if (number == 1)
1914 p->fcoe = true;
1915 break;
1916 case I40E_DEV_FUNC_CAP_RSS:
1917 p->rss = true;
Carolyn Wybornye157ea32014-06-03 23:50:22 +00001918 p->rss_table_size = number;
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00001919 p->rss_table_entry_width = logical_id;
1920 break;
1921 case I40E_DEV_FUNC_CAP_RX_QUEUES:
1922 p->num_rx_qp = number;
1923 p->base_queue = phys_id;
1924 break;
1925 case I40E_DEV_FUNC_CAP_TX_QUEUES:
1926 p->num_tx_qp = number;
1927 p->base_queue = phys_id;
1928 break;
1929 case I40E_DEV_FUNC_CAP_MSIX:
1930 p->num_msix_vectors = number;
1931 break;
1932 case I40E_DEV_FUNC_CAP_MSIX_VF:
1933 p->num_msix_vectors_vf = number;
1934 break;
1935 case I40E_DEV_FUNC_CAP_MFP_MODE_1:
1936 if (number == 1)
1937 p->mfp_mode_1 = true;
1938 break;
1939 case I40E_DEV_FUNC_CAP_CEM:
1940 if (number == 1)
1941 p->mgmt_cem = true;
1942 break;
1943 case I40E_DEV_FUNC_CAP_IWARP:
1944 if (number == 1)
1945 p->iwarp = true;
1946 break;
1947 case I40E_DEV_FUNC_CAP_LED:
1948 if (phys_id < I40E_HW_CAP_MAX_GPIO)
1949 p->led[phys_id] = true;
1950 break;
1951 case I40E_DEV_FUNC_CAP_SDP:
1952 if (phys_id < I40E_HW_CAP_MAX_GPIO)
1953 p->sdp[phys_id] = true;
1954 break;
1955 case I40E_DEV_FUNC_CAP_MDIO:
1956 if (number == 1) {
1957 p->mdio_port_num = phys_id;
1958 p->mdio_port_mode = logical_id;
1959 }
1960 break;
1961 case I40E_DEV_FUNC_CAP_IEEE_1588:
1962 if (number == 1)
1963 p->ieee_1588 = true;
1964 break;
1965 case I40E_DEV_FUNC_CAP_FLOW_DIRECTOR:
1966 p->fd = true;
1967 p->fd_filters_guaranteed = number;
1968 p->fd_filters_best_effort = logical_id;
1969 break;
1970 default:
1971 break;
1972 }
1973 }
1974
Vasu Dev566bb852014-04-09 05:59:06 +00001975 /* Software override ensuring FCoE is disabled if npar or mfp
1976 * mode because it is not supported in these modes.
1977 */
1978 if (p->npar_enable || p->mfp_mode_1)
1979 p->fcoe = false;
1980
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00001981 /* additional HW specific goodies that might
1982 * someday be HW version specific
1983 */
1984 p->rx_buf_chain_len = I40E_MAX_CHAINED_RX_BUFFERS;
1985}
1986
1987/**
1988 * i40e_aq_discover_capabilities
1989 * @hw: pointer to the hw struct
1990 * @buff: a virtual buffer to hold the capabilities
1991 * @buff_size: Size of the virtual buffer
1992 * @data_size: Size of the returned data, or buff size needed if AQ err==ENOMEM
1993 * @list_type_opc: capabilities type to discover - pass in the command opcode
1994 * @cmd_details: pointer to command details structure or NULL
1995 *
1996 * Get the device capabilities descriptions from the firmware
1997 **/
1998i40e_status i40e_aq_discover_capabilities(struct i40e_hw *hw,
1999 void *buff, u16 buff_size, u16 *data_size,
2000 enum i40e_admin_queue_opc list_type_opc,
2001 struct i40e_asq_cmd_details *cmd_details)
2002{
2003 struct i40e_aqc_list_capabilites *cmd;
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00002004 struct i40e_aq_desc desc;
Jesse Brandeburg8fb905b2014-01-17 15:36:33 -08002005 i40e_status status = 0;
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00002006
2007 cmd = (struct i40e_aqc_list_capabilites *)&desc.params.raw;
2008
2009 if (list_type_opc != i40e_aqc_opc_list_func_capabilities &&
2010 list_type_opc != i40e_aqc_opc_list_dev_capabilities) {
2011 status = I40E_ERR_PARAM;
2012 goto exit;
2013 }
2014
2015 i40e_fill_default_direct_cmd_desc(&desc, list_type_opc);
2016
2017 desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_BUF);
2018 if (buff_size > I40E_AQ_LARGE_BUF)
2019 desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_LB);
2020
2021 status = i40e_asq_send_command(hw, &desc, buff, buff_size, cmd_details);
2022 *data_size = le16_to_cpu(desc.datalen);
2023
2024 if (status)
2025 goto exit;
2026
2027 i40e_parse_discover_capabilities(hw, buff, le32_to_cpu(cmd->count),
2028 list_type_opc);
2029
2030exit:
2031 return status;
2032}
2033
2034/**
2035 * i40e_aq_get_lldp_mib
2036 * @hw: pointer to the hw struct
2037 * @bridge_type: type of bridge requested
2038 * @mib_type: Local, Remote or both Local and Remote MIBs
2039 * @buff: pointer to a user supplied buffer to store the MIB block
2040 * @buff_size: size of the buffer (in bytes)
2041 * @local_len : length of the returned Local LLDP MIB
2042 * @remote_len: length of the returned Remote LLDP MIB
2043 * @cmd_details: pointer to command details structure or NULL
2044 *
2045 * Requests the complete LLDP MIB (entire packet).
2046 **/
2047i40e_status i40e_aq_get_lldp_mib(struct i40e_hw *hw, u8 bridge_type,
2048 u8 mib_type, void *buff, u16 buff_size,
2049 u16 *local_len, u16 *remote_len,
2050 struct i40e_asq_cmd_details *cmd_details)
2051{
2052 struct i40e_aq_desc desc;
2053 struct i40e_aqc_lldp_get_mib *cmd =
2054 (struct i40e_aqc_lldp_get_mib *)&desc.params.raw;
2055 struct i40e_aqc_lldp_get_mib *resp =
2056 (struct i40e_aqc_lldp_get_mib *)&desc.params.raw;
2057 i40e_status status;
2058
2059 if (buff_size == 0 || !buff)
2060 return I40E_ERR_PARAM;
2061
2062 i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_lldp_get_mib);
2063 /* Indirect Command */
2064 desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_BUF);
2065
2066 cmd->type = mib_type & I40E_AQ_LLDP_MIB_TYPE_MASK;
2067 cmd->type |= ((bridge_type << I40E_AQ_LLDP_BRIDGE_TYPE_SHIFT) &
2068 I40E_AQ_LLDP_BRIDGE_TYPE_MASK);
2069
2070 desc.datalen = cpu_to_le16(buff_size);
2071
2072 desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_BUF);
2073 if (buff_size > I40E_AQ_LARGE_BUF)
2074 desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_LB);
2075
2076 status = i40e_asq_send_command(hw, &desc, buff, buff_size, cmd_details);
2077 if (!status) {
2078 if (local_len != NULL)
2079 *local_len = le16_to_cpu(resp->local_len);
2080 if (remote_len != NULL)
2081 *remote_len = le16_to_cpu(resp->remote_len);
2082 }
2083
2084 return status;
2085}
2086
2087/**
2088 * i40e_aq_cfg_lldp_mib_change_event
2089 * @hw: pointer to the hw struct
2090 * @enable_update: Enable or Disable event posting
2091 * @cmd_details: pointer to command details structure or NULL
2092 *
2093 * Enable or Disable posting of an event on ARQ when LLDP MIB
2094 * associated with the interface changes
2095 **/
2096i40e_status i40e_aq_cfg_lldp_mib_change_event(struct i40e_hw *hw,
2097 bool enable_update,
2098 struct i40e_asq_cmd_details *cmd_details)
2099{
2100 struct i40e_aq_desc desc;
2101 struct i40e_aqc_lldp_update_mib *cmd =
2102 (struct i40e_aqc_lldp_update_mib *)&desc.params.raw;
2103 i40e_status status;
2104
2105 i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_lldp_update_mib);
2106
2107 if (!enable_update)
2108 cmd->command |= I40E_AQ_LLDP_MIB_UPDATE_DISABLE;
2109
2110 status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
2111
2112 return status;
2113}
2114
2115/**
2116 * i40e_aq_stop_lldp
2117 * @hw: pointer to the hw struct
2118 * @shutdown_agent: True if LLDP Agent needs to be Shutdown
2119 * @cmd_details: pointer to command details structure or NULL
2120 *
2121 * Stop or Shutdown the embedded LLDP Agent
2122 **/
2123i40e_status i40e_aq_stop_lldp(struct i40e_hw *hw, bool shutdown_agent,
2124 struct i40e_asq_cmd_details *cmd_details)
2125{
2126 struct i40e_aq_desc desc;
2127 struct i40e_aqc_lldp_stop *cmd =
2128 (struct i40e_aqc_lldp_stop *)&desc.params.raw;
2129 i40e_status status;
2130
2131 i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_lldp_stop);
2132
2133 if (shutdown_agent)
2134 cmd->command |= I40E_AQ_LLDP_AGENT_SHUTDOWN;
2135
2136 status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
2137
2138 return status;
2139}
2140
2141/**
2142 * i40e_aq_start_lldp
2143 * @hw: pointer to the hw struct
2144 * @cmd_details: pointer to command details structure or NULL
2145 *
2146 * Start the embedded LLDP Agent on all ports.
2147 **/
2148i40e_status i40e_aq_start_lldp(struct i40e_hw *hw,
2149 struct i40e_asq_cmd_details *cmd_details)
2150{
2151 struct i40e_aq_desc desc;
2152 struct i40e_aqc_lldp_start *cmd =
2153 (struct i40e_aqc_lldp_start *)&desc.params.raw;
2154 i40e_status status;
2155
2156 i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_lldp_start);
2157
2158 cmd->command = I40E_AQ_LLDP_AGENT_START;
2159
2160 status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
2161
2162 return status;
2163}
2164
2165/**
Jeff Kirshera1c9a9d2013-12-28 07:32:18 +00002166 * i40e_aq_add_udp_tunnel
2167 * @hw: pointer to the hw struct
2168 * @udp_port: the UDP port to add
2169 * @header_len: length of the tunneling header length in DWords
2170 * @protocol_index: protocol index type
Jeff Kirsher98d44382013-12-21 05:44:42 +00002171 * @filter_index: pointer to filter index
Jeff Kirshera1c9a9d2013-12-28 07:32:18 +00002172 * @cmd_details: pointer to command details structure or NULL
2173 **/
2174i40e_status i40e_aq_add_udp_tunnel(struct i40e_hw *hw,
Kevin Scottf4f94b92014-04-05 07:46:10 +00002175 u16 udp_port, u8 protocol_index,
2176 u8 *filter_index,
Jeff Kirshera1c9a9d2013-12-28 07:32:18 +00002177 struct i40e_asq_cmd_details *cmd_details)
2178{
2179 struct i40e_aq_desc desc;
2180 struct i40e_aqc_add_udp_tunnel *cmd =
2181 (struct i40e_aqc_add_udp_tunnel *)&desc.params.raw;
2182 struct i40e_aqc_del_udp_tunnel_completion *resp =
2183 (struct i40e_aqc_del_udp_tunnel_completion *)&desc.params.raw;
2184 i40e_status status;
2185
2186 i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_add_udp_tunnel);
2187
2188 cmd->udp_port = cpu_to_le16(udp_port);
Shannon Nelson981b7542013-12-11 08:17:11 +00002189 cmd->protocol_type = protocol_index;
Jeff Kirshera1c9a9d2013-12-28 07:32:18 +00002190
2191 status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
2192
2193 if (!status)
2194 *filter_index = resp->index;
2195
2196 return status;
2197}
2198
2199/**
2200 * i40e_aq_del_udp_tunnel
2201 * @hw: pointer to the hw struct
2202 * @index: filter index
2203 * @cmd_details: pointer to command details structure or NULL
2204 **/
2205i40e_status i40e_aq_del_udp_tunnel(struct i40e_hw *hw, u8 index,
2206 struct i40e_asq_cmd_details *cmd_details)
2207{
2208 struct i40e_aq_desc desc;
2209 struct i40e_aqc_remove_udp_tunnel *cmd =
2210 (struct i40e_aqc_remove_udp_tunnel *)&desc.params.raw;
2211 i40e_status status;
2212
2213 i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_del_udp_tunnel);
2214
2215 cmd->index = index;
2216
2217 status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
2218
2219 return status;
2220}
2221
2222/**
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00002223 * i40e_aq_delete_element - Delete switch element
2224 * @hw: pointer to the hw struct
2225 * @seid: the SEID to delete from the switch
2226 * @cmd_details: pointer to command details structure or NULL
2227 *
2228 * This deletes a switch element from the switch.
2229 **/
2230i40e_status i40e_aq_delete_element(struct i40e_hw *hw, u16 seid,
2231 struct i40e_asq_cmd_details *cmd_details)
2232{
2233 struct i40e_aq_desc desc;
2234 struct i40e_aqc_switch_seid *cmd =
2235 (struct i40e_aqc_switch_seid *)&desc.params.raw;
2236 i40e_status status;
2237
2238 if (seid == 0)
2239 return I40E_ERR_PARAM;
2240
2241 i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_delete_element);
2242
2243 cmd->seid = cpu_to_le16(seid);
2244
2245 status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
2246
2247 return status;
2248}
2249
2250/**
Neerav Parikhafb3ff02014-01-17 15:36:36 -08002251 * i40e_aq_dcb_updated - DCB Updated Command
2252 * @hw: pointer to the hw struct
2253 * @cmd_details: pointer to command details structure or NULL
2254 *
2255 * EMP will return when the shared RPB settings have been
2256 * recomputed and modified. The retval field in the descriptor
2257 * will be set to 0 when RPB is modified.
2258 **/
2259i40e_status i40e_aq_dcb_updated(struct i40e_hw *hw,
2260 struct i40e_asq_cmd_details *cmd_details)
2261{
2262 struct i40e_aq_desc desc;
2263 i40e_status status;
2264
2265 i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_dcb_updated);
2266
2267 status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
2268
2269 return status;
2270}
2271
2272/**
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00002273 * i40e_aq_tx_sched_cmd - generic Tx scheduler AQ command handler
2274 * @hw: pointer to the hw struct
2275 * @seid: seid for the physical port/switching component/vsi
2276 * @buff: Indirect buffer to hold data parameters and response
2277 * @buff_size: Indirect buffer size
2278 * @opcode: Tx scheduler AQ command opcode
2279 * @cmd_details: pointer to command details structure or NULL
2280 *
2281 * Generic command handler for Tx scheduler AQ commands
2282 **/
2283static i40e_status i40e_aq_tx_sched_cmd(struct i40e_hw *hw, u16 seid,
2284 void *buff, u16 buff_size,
2285 enum i40e_admin_queue_opc opcode,
2286 struct i40e_asq_cmd_details *cmd_details)
2287{
2288 struct i40e_aq_desc desc;
2289 struct i40e_aqc_tx_sched_ind *cmd =
2290 (struct i40e_aqc_tx_sched_ind *)&desc.params.raw;
2291 i40e_status status;
2292 bool cmd_param_flag = false;
2293
2294 switch (opcode) {
2295 case i40e_aqc_opc_configure_vsi_ets_sla_bw_limit:
2296 case i40e_aqc_opc_configure_vsi_tc_bw:
2297 case i40e_aqc_opc_enable_switching_comp_ets:
2298 case i40e_aqc_opc_modify_switching_comp_ets:
2299 case i40e_aqc_opc_disable_switching_comp_ets:
2300 case i40e_aqc_opc_configure_switching_comp_ets_bw_limit:
2301 case i40e_aqc_opc_configure_switching_comp_bw_config:
2302 cmd_param_flag = true;
2303 break;
2304 case i40e_aqc_opc_query_vsi_bw_config:
2305 case i40e_aqc_opc_query_vsi_ets_sla_config:
2306 case i40e_aqc_opc_query_switching_comp_ets_config:
2307 case i40e_aqc_opc_query_port_ets_config:
2308 case i40e_aqc_opc_query_switching_comp_bw_config:
2309 cmd_param_flag = false;
2310 break;
2311 default:
2312 return I40E_ERR_PARAM;
2313 }
2314
2315 i40e_fill_default_direct_cmd_desc(&desc, opcode);
2316
2317 /* Indirect command */
2318 desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_BUF);
2319 if (cmd_param_flag)
2320 desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_RD);
2321 if (buff_size > I40E_AQ_LARGE_BUF)
2322 desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_LB);
2323
2324 desc.datalen = cpu_to_le16(buff_size);
2325
2326 cmd->vsi_seid = cpu_to_le16(seid);
2327
2328 status = i40e_asq_send_command(hw, &desc, buff, buff_size, cmd_details);
2329
2330 return status;
2331}
2332
2333/**
Mitch Williams6b192892014-03-06 09:02:29 +00002334 * i40e_aq_config_vsi_bw_limit - Configure VSI BW Limit
2335 * @hw: pointer to the hw struct
2336 * @seid: VSI seid
2337 * @credit: BW limit credits (0 = disabled)
2338 * @max_credit: Max BW limit credits
2339 * @cmd_details: pointer to command details structure or NULL
2340 **/
2341i40e_status i40e_aq_config_vsi_bw_limit(struct i40e_hw *hw,
2342 u16 seid, u16 credit, u8 max_credit,
2343 struct i40e_asq_cmd_details *cmd_details)
2344{
2345 struct i40e_aq_desc desc;
2346 struct i40e_aqc_configure_vsi_bw_limit *cmd =
2347 (struct i40e_aqc_configure_vsi_bw_limit *)&desc.params.raw;
2348 i40e_status status;
2349
2350 i40e_fill_default_direct_cmd_desc(&desc,
2351 i40e_aqc_opc_configure_vsi_bw_limit);
2352
2353 cmd->vsi_seid = cpu_to_le16(seid);
2354 cmd->credit = cpu_to_le16(credit);
2355 cmd->max_credit = max_credit;
2356
2357 status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
2358
2359 return status;
2360}
2361
2362/**
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00002363 * i40e_aq_config_vsi_tc_bw - Config VSI BW Allocation per TC
2364 * @hw: pointer to the hw struct
2365 * @seid: VSI seid
2366 * @bw_data: Buffer holding enabled TCs, relative TC BW limit/credits
2367 * @cmd_details: pointer to command details structure or NULL
2368 **/
2369i40e_status i40e_aq_config_vsi_tc_bw(struct i40e_hw *hw,
2370 u16 seid,
2371 struct i40e_aqc_configure_vsi_tc_bw_data *bw_data,
2372 struct i40e_asq_cmd_details *cmd_details)
2373{
2374 return i40e_aq_tx_sched_cmd(hw, seid, (void *)bw_data, sizeof(*bw_data),
2375 i40e_aqc_opc_configure_vsi_tc_bw,
2376 cmd_details);
2377}
2378
2379/**
Neerav Parikhafb3ff02014-01-17 15:36:36 -08002380 * i40e_aq_config_switch_comp_ets - Enable/Disable/Modify ETS on the port
2381 * @hw: pointer to the hw struct
2382 * @seid: seid of the switching component connected to Physical Port
2383 * @ets_data: Buffer holding ETS parameters
2384 * @cmd_details: pointer to command details structure or NULL
2385 **/
2386i40e_status i40e_aq_config_switch_comp_ets(struct i40e_hw *hw,
2387 u16 seid,
2388 struct i40e_aqc_configure_switching_comp_ets_data *ets_data,
2389 enum i40e_admin_queue_opc opcode,
2390 struct i40e_asq_cmd_details *cmd_details)
2391{
2392 return i40e_aq_tx_sched_cmd(hw, seid, (void *)ets_data,
2393 sizeof(*ets_data), opcode, cmd_details);
2394}
2395
2396/**
2397 * i40e_aq_config_switch_comp_bw_config - Config Switch comp BW Alloc per TC
2398 * @hw: pointer to the hw struct
2399 * @seid: seid of the switching component
2400 * @bw_data: Buffer holding enabled TCs, relative/absolute TC BW limit/credits
2401 * @cmd_details: pointer to command details structure or NULL
2402 **/
2403i40e_status i40e_aq_config_switch_comp_bw_config(struct i40e_hw *hw,
2404 u16 seid,
2405 struct i40e_aqc_configure_switching_comp_bw_config_data *bw_data,
2406 struct i40e_asq_cmd_details *cmd_details)
2407{
2408 return i40e_aq_tx_sched_cmd(hw, seid, (void *)bw_data, sizeof(*bw_data),
2409 i40e_aqc_opc_configure_switching_comp_bw_config,
2410 cmd_details);
2411}
2412
2413/**
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00002414 * i40e_aq_query_vsi_bw_config - Query VSI BW configuration
2415 * @hw: pointer to the hw struct
2416 * @seid: seid of the VSI
2417 * @bw_data: Buffer to hold VSI BW configuration
2418 * @cmd_details: pointer to command details structure or NULL
2419 **/
2420i40e_status i40e_aq_query_vsi_bw_config(struct i40e_hw *hw,
2421 u16 seid,
2422 struct i40e_aqc_query_vsi_bw_config_resp *bw_data,
2423 struct i40e_asq_cmd_details *cmd_details)
2424{
2425 return i40e_aq_tx_sched_cmd(hw, seid, (void *)bw_data, sizeof(*bw_data),
2426 i40e_aqc_opc_query_vsi_bw_config,
2427 cmd_details);
2428}
2429
2430/**
2431 * i40e_aq_query_vsi_ets_sla_config - Query VSI BW configuration per TC
2432 * @hw: pointer to the hw struct
2433 * @seid: seid of the VSI
2434 * @bw_data: Buffer to hold VSI BW configuration per TC
2435 * @cmd_details: pointer to command details structure or NULL
2436 **/
2437i40e_status i40e_aq_query_vsi_ets_sla_config(struct i40e_hw *hw,
2438 u16 seid,
2439 struct i40e_aqc_query_vsi_ets_sla_config_resp *bw_data,
2440 struct i40e_asq_cmd_details *cmd_details)
2441{
2442 return i40e_aq_tx_sched_cmd(hw, seid, (void *)bw_data, sizeof(*bw_data),
2443 i40e_aqc_opc_query_vsi_ets_sla_config,
2444 cmd_details);
2445}
2446
2447/**
2448 * i40e_aq_query_switch_comp_ets_config - Query Switch comp BW config per TC
2449 * @hw: pointer to the hw struct
2450 * @seid: seid of the switching component
2451 * @bw_data: Buffer to hold switching component's per TC BW config
2452 * @cmd_details: pointer to command details structure or NULL
2453 **/
2454i40e_status i40e_aq_query_switch_comp_ets_config(struct i40e_hw *hw,
2455 u16 seid,
2456 struct i40e_aqc_query_switching_comp_ets_config_resp *bw_data,
2457 struct i40e_asq_cmd_details *cmd_details)
2458{
2459 return i40e_aq_tx_sched_cmd(hw, seid, (void *)bw_data, sizeof(*bw_data),
2460 i40e_aqc_opc_query_switching_comp_ets_config,
2461 cmd_details);
2462}
2463
2464/**
2465 * i40e_aq_query_port_ets_config - Query Physical Port ETS configuration
2466 * @hw: pointer to the hw struct
2467 * @seid: seid of the VSI or switching component connected to Physical Port
2468 * @bw_data: Buffer to hold current ETS configuration for the Physical Port
2469 * @cmd_details: pointer to command details structure or NULL
2470 **/
2471i40e_status i40e_aq_query_port_ets_config(struct i40e_hw *hw,
2472 u16 seid,
2473 struct i40e_aqc_query_port_ets_config_resp *bw_data,
2474 struct i40e_asq_cmd_details *cmd_details)
2475{
2476 return i40e_aq_tx_sched_cmd(hw, seid, (void *)bw_data, sizeof(*bw_data),
2477 i40e_aqc_opc_query_port_ets_config,
2478 cmd_details);
2479}
2480
2481/**
2482 * i40e_aq_query_switch_comp_bw_config - Query Switch comp BW configuration
2483 * @hw: pointer to the hw struct
2484 * @seid: seid of the switching component
2485 * @bw_data: Buffer to hold switching component's BW configuration
2486 * @cmd_details: pointer to command details structure or NULL
2487 **/
2488i40e_status i40e_aq_query_switch_comp_bw_config(struct i40e_hw *hw,
2489 u16 seid,
2490 struct i40e_aqc_query_switching_comp_bw_config_resp *bw_data,
2491 struct i40e_asq_cmd_details *cmd_details)
2492{
2493 return i40e_aq_tx_sched_cmd(hw, seid, (void *)bw_data, sizeof(*bw_data),
2494 i40e_aqc_opc_query_switching_comp_bw_config,
2495 cmd_details);
2496}
2497
2498/**
2499 * i40e_validate_filter_settings
2500 * @hw: pointer to the hardware structure
2501 * @settings: Filter control settings
2502 *
2503 * Check and validate the filter control settings passed.
2504 * The function checks for the valid filter/context sizes being
2505 * passed for FCoE and PE.
2506 *
2507 * Returns 0 if the values passed are valid and within
2508 * range else returns an error.
2509 **/
2510static i40e_status i40e_validate_filter_settings(struct i40e_hw *hw,
2511 struct i40e_filter_control_settings *settings)
2512{
2513 u32 fcoe_cntx_size, fcoe_filt_size;
2514 u32 pe_cntx_size, pe_filt_size;
Anjali Singhai Jain467d7292014-05-10 04:49:02 +00002515 u32 fcoe_fmax;
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00002516 u32 val;
2517
2518 /* Validate FCoE settings passed */
2519 switch (settings->fcoe_filt_num) {
2520 case I40E_HASH_FILTER_SIZE_1K:
2521 case I40E_HASH_FILTER_SIZE_2K:
2522 case I40E_HASH_FILTER_SIZE_4K:
2523 case I40E_HASH_FILTER_SIZE_8K:
2524 case I40E_HASH_FILTER_SIZE_16K:
2525 case I40E_HASH_FILTER_SIZE_32K:
2526 fcoe_filt_size = I40E_HASH_FILTER_BASE_SIZE;
2527 fcoe_filt_size <<= (u32)settings->fcoe_filt_num;
2528 break;
2529 default:
2530 return I40E_ERR_PARAM;
2531 }
2532
2533 switch (settings->fcoe_cntx_num) {
2534 case I40E_DMA_CNTX_SIZE_512:
2535 case I40E_DMA_CNTX_SIZE_1K:
2536 case I40E_DMA_CNTX_SIZE_2K:
2537 case I40E_DMA_CNTX_SIZE_4K:
2538 fcoe_cntx_size = I40E_DMA_CNTX_BASE_SIZE;
2539 fcoe_cntx_size <<= (u32)settings->fcoe_cntx_num;
2540 break;
2541 default:
2542 return I40E_ERR_PARAM;
2543 }
2544
2545 /* Validate PE settings passed */
2546 switch (settings->pe_filt_num) {
2547 case I40E_HASH_FILTER_SIZE_1K:
2548 case I40E_HASH_FILTER_SIZE_2K:
2549 case I40E_HASH_FILTER_SIZE_4K:
2550 case I40E_HASH_FILTER_SIZE_8K:
2551 case I40E_HASH_FILTER_SIZE_16K:
2552 case I40E_HASH_FILTER_SIZE_32K:
2553 case I40E_HASH_FILTER_SIZE_64K:
2554 case I40E_HASH_FILTER_SIZE_128K:
2555 case I40E_HASH_FILTER_SIZE_256K:
2556 case I40E_HASH_FILTER_SIZE_512K:
2557 case I40E_HASH_FILTER_SIZE_1M:
2558 pe_filt_size = I40E_HASH_FILTER_BASE_SIZE;
2559 pe_filt_size <<= (u32)settings->pe_filt_num;
2560 break;
2561 default:
2562 return I40E_ERR_PARAM;
2563 }
2564
2565 switch (settings->pe_cntx_num) {
2566 case I40E_DMA_CNTX_SIZE_512:
2567 case I40E_DMA_CNTX_SIZE_1K:
2568 case I40E_DMA_CNTX_SIZE_2K:
2569 case I40E_DMA_CNTX_SIZE_4K:
2570 case I40E_DMA_CNTX_SIZE_8K:
2571 case I40E_DMA_CNTX_SIZE_16K:
2572 case I40E_DMA_CNTX_SIZE_32K:
2573 case I40E_DMA_CNTX_SIZE_64K:
2574 case I40E_DMA_CNTX_SIZE_128K:
2575 case I40E_DMA_CNTX_SIZE_256K:
2576 pe_cntx_size = I40E_DMA_CNTX_BASE_SIZE;
2577 pe_cntx_size <<= (u32)settings->pe_cntx_num;
2578 break;
2579 default:
2580 return I40E_ERR_PARAM;
2581 }
2582
2583 /* FCHSIZE + FCDSIZE should not be greater than PMFCOEFMAX */
2584 val = rd32(hw, I40E_GLHMC_FCOEFMAX);
2585 fcoe_fmax = (val & I40E_GLHMC_FCOEFMAX_PMFCOEFMAX_MASK)
2586 >> I40E_GLHMC_FCOEFMAX_PMFCOEFMAX_SHIFT;
2587 if (fcoe_filt_size + fcoe_cntx_size > fcoe_fmax)
2588 return I40E_ERR_INVALID_SIZE;
2589
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00002590 return 0;
2591}
2592
2593/**
2594 * i40e_set_filter_control
2595 * @hw: pointer to the hardware structure
2596 * @settings: Filter control settings
2597 *
2598 * Set the Queue Filters for PE/FCoE and enable filters required
2599 * for a single PF. It is expected that these settings are programmed
2600 * at the driver initialization time.
2601 **/
2602i40e_status i40e_set_filter_control(struct i40e_hw *hw,
2603 struct i40e_filter_control_settings *settings)
2604{
2605 i40e_status ret = 0;
2606 u32 hash_lut_size = 0;
2607 u32 val;
2608
2609 if (!settings)
2610 return I40E_ERR_PARAM;
2611
2612 /* Validate the input settings */
2613 ret = i40e_validate_filter_settings(hw, settings);
2614 if (ret)
2615 return ret;
2616
2617 /* Read the PF Queue Filter control register */
2618 val = rd32(hw, I40E_PFQF_CTL_0);
2619
2620 /* Program required PE hash buckets for the PF */
2621 val &= ~I40E_PFQF_CTL_0_PEHSIZE_MASK;
2622 val |= ((u32)settings->pe_filt_num << I40E_PFQF_CTL_0_PEHSIZE_SHIFT) &
2623 I40E_PFQF_CTL_0_PEHSIZE_MASK;
2624 /* Program required PE contexts for the PF */
2625 val &= ~I40E_PFQF_CTL_0_PEDSIZE_MASK;
2626 val |= ((u32)settings->pe_cntx_num << I40E_PFQF_CTL_0_PEDSIZE_SHIFT) &
2627 I40E_PFQF_CTL_0_PEDSIZE_MASK;
2628
2629 /* Program required FCoE hash buckets for the PF */
2630 val &= ~I40E_PFQF_CTL_0_PFFCHSIZE_MASK;
2631 val |= ((u32)settings->fcoe_filt_num <<
2632 I40E_PFQF_CTL_0_PFFCHSIZE_SHIFT) &
2633 I40E_PFQF_CTL_0_PFFCHSIZE_MASK;
2634 /* Program required FCoE DDP contexts for the PF */
2635 val &= ~I40E_PFQF_CTL_0_PFFCDSIZE_MASK;
2636 val |= ((u32)settings->fcoe_cntx_num <<
2637 I40E_PFQF_CTL_0_PFFCDSIZE_SHIFT) &
2638 I40E_PFQF_CTL_0_PFFCDSIZE_MASK;
2639
2640 /* Program Hash LUT size for the PF */
2641 val &= ~I40E_PFQF_CTL_0_HASHLUTSIZE_MASK;
2642 if (settings->hash_lut_size == I40E_HASH_LUT_SIZE_512)
2643 hash_lut_size = 1;
2644 val |= (hash_lut_size << I40E_PFQF_CTL_0_HASHLUTSIZE_SHIFT) &
2645 I40E_PFQF_CTL_0_HASHLUTSIZE_MASK;
2646
2647 /* Enable FDIR, Ethertype and MACVLAN filters for PF and VFs */
2648 if (settings->enable_fdir)
2649 val |= I40E_PFQF_CTL_0_FD_ENA_MASK;
2650 if (settings->enable_ethtype)
2651 val |= I40E_PFQF_CTL_0_ETYPE_ENA_MASK;
2652 if (settings->enable_macvlan)
2653 val |= I40E_PFQF_CTL_0_MACVLAN_ENA_MASK;
2654
2655 wr32(hw, I40E_PFQF_CTL_0, val);
2656
2657 return 0;
2658}
Neerav Parikhafb3ff02014-01-17 15:36:36 -08002659
2660/**
2661 * i40e_aq_add_rem_control_packet_filter - Add or Remove Control Packet Filter
2662 * @hw: pointer to the hw struct
2663 * @mac_addr: MAC address to use in the filter
2664 * @ethtype: Ethertype to use in the filter
2665 * @flags: Flags that needs to be applied to the filter
2666 * @vsi_seid: seid of the control VSI
2667 * @queue: VSI queue number to send the packet to
2668 * @is_add: Add control packet filter if True else remove
2669 * @stats: Structure to hold information on control filter counts
2670 * @cmd_details: pointer to command details structure or NULL
2671 *
2672 * This command will Add or Remove control packet filter for a control VSI.
2673 * In return it will update the total number of perfect filter count in
2674 * the stats member.
2675 **/
2676i40e_status i40e_aq_add_rem_control_packet_filter(struct i40e_hw *hw,
2677 u8 *mac_addr, u16 ethtype, u16 flags,
2678 u16 vsi_seid, u16 queue, bool is_add,
2679 struct i40e_control_filter_stats *stats,
2680 struct i40e_asq_cmd_details *cmd_details)
2681{
2682 struct i40e_aq_desc desc;
2683 struct i40e_aqc_add_remove_control_packet_filter *cmd =
2684 (struct i40e_aqc_add_remove_control_packet_filter *)
2685 &desc.params.raw;
2686 struct i40e_aqc_add_remove_control_packet_filter_completion *resp =
2687 (struct i40e_aqc_add_remove_control_packet_filter_completion *)
2688 &desc.params.raw;
2689 i40e_status status;
2690
2691 if (vsi_seid == 0)
2692 return I40E_ERR_PARAM;
2693
2694 if (is_add) {
2695 i40e_fill_default_direct_cmd_desc(&desc,
2696 i40e_aqc_opc_add_control_packet_filter);
2697 cmd->queue = cpu_to_le16(queue);
2698 } else {
2699 i40e_fill_default_direct_cmd_desc(&desc,
2700 i40e_aqc_opc_remove_control_packet_filter);
2701 }
2702
2703 if (mac_addr)
2704 memcpy(cmd->mac, mac_addr, ETH_ALEN);
2705
2706 cmd->etype = cpu_to_le16(ethtype);
2707 cmd->flags = cpu_to_le16(flags);
2708 cmd->seid = cpu_to_le16(vsi_seid);
2709
2710 status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
2711
2712 if (!status && stats) {
2713 stats->mac_etype_used = le16_to_cpu(resp->mac_etype_used);
2714 stats->etype_used = le16_to_cpu(resp->etype_used);
2715 stats->mac_etype_free = le16_to_cpu(resp->mac_etype_free);
2716 stats->etype_free = le16_to_cpu(resp->etype_free);
2717 }
2718
2719 return status;
2720}
2721
Catherine Sullivand4dfb812013-11-28 06:39:21 +00002722/**
2723 * i40e_set_pci_config_data - store PCI bus info
2724 * @hw: pointer to hardware structure
2725 * @link_status: the link status word from PCI config space
2726 *
2727 * Stores the PCI bus info (speed, width, type) within the i40e_hw structure
2728 **/
2729void i40e_set_pci_config_data(struct i40e_hw *hw, u16 link_status)
2730{
2731 hw->bus.type = i40e_bus_type_pci_express;
2732
2733 switch (link_status & PCI_EXP_LNKSTA_NLW) {
2734 case PCI_EXP_LNKSTA_NLW_X1:
2735 hw->bus.width = i40e_bus_width_pcie_x1;
2736 break;
2737 case PCI_EXP_LNKSTA_NLW_X2:
2738 hw->bus.width = i40e_bus_width_pcie_x2;
2739 break;
2740 case PCI_EXP_LNKSTA_NLW_X4:
2741 hw->bus.width = i40e_bus_width_pcie_x4;
2742 break;
2743 case PCI_EXP_LNKSTA_NLW_X8:
2744 hw->bus.width = i40e_bus_width_pcie_x8;
2745 break;
2746 default:
2747 hw->bus.width = i40e_bus_width_unknown;
2748 break;
2749 }
2750
2751 switch (link_status & PCI_EXP_LNKSTA_CLS) {
2752 case PCI_EXP_LNKSTA_CLS_2_5GB:
2753 hw->bus.speed = i40e_bus_speed_2500;
2754 break;
2755 case PCI_EXP_LNKSTA_CLS_5_0GB:
2756 hw->bus.speed = i40e_bus_speed_5000;
2757 break;
2758 case PCI_EXP_LNKSTA_CLS_8_0GB:
2759 hw->bus.speed = i40e_bus_speed_8000;
2760 break;
2761 default:
2762 hw->bus.speed = i40e_bus_speed_unknown;
2763 break;
2764 }
2765}