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