blob: b16fc03ab00c967e3759429947105112f34bc5a9 [file] [log] [blame]
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00001/*******************************************************************************
2 *
3 * Intel Ethernet Controller XL710 Family Linux Driver
Greg Rosedc641b72013-12-18 13:45:51 +00004 * Copyright(c) 2013 - 2014 Intel Corporation.
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00005 *
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms and conditions of the GNU General Public License,
8 * version 2, as published by the Free Software Foundation.
9 *
10 * This program is distributed in the hope it will be useful, but WITHOUT
11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
13 * more details.
14 *
Greg Rosedc641b72013-12-18 13:45:51 +000015 * You should have received a copy of the GNU General Public License along
16 * with this program. If not, see <http://www.gnu.org/licenses/>.
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +000017 *
18 * The full GNU General Public License is included in this distribution in
19 * the file called "COPYING".
20 *
21 * Contact Information:
22 * e1000-devel Mailing List <e1000-devel@lists.sourceforge.net>
23 * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
24 *
25 ******************************************************************************/
26
27#include "i40e_type.h"
28#include "i40e_adminq.h"
29#include "i40e_prototype.h"
30#include "i40e_virtchnl.h"
31
32/**
33 * i40e_set_mac_type - Sets MAC type
34 * @hw: pointer to the HW structure
35 *
36 * This function sets the mac type of the adapter based on the
37 * vendor ID and device ID stored in the hw structure.
38 **/
39static i40e_status i40e_set_mac_type(struct i40e_hw *hw)
40{
41 i40e_status status = 0;
42
43 if (hw->vendor_id == PCI_VENDOR_ID_INTEL) {
44 switch (hw->device_id) {
Shannon Nelsonab600852014-01-17 15:36:39 -080045 case I40E_DEV_ID_SFP_XL710:
Shannon Nelsonab600852014-01-17 15:36:39 -080046 case I40E_DEV_ID_QEMU:
47 case I40E_DEV_ID_KX_A:
48 case I40E_DEV_ID_KX_B:
49 case I40E_DEV_ID_KX_C:
Shannon Nelsonab600852014-01-17 15:36:39 -080050 case I40E_DEV_ID_QSFP_A:
51 case I40E_DEV_ID_QSFP_B:
52 case I40E_DEV_ID_QSFP_C:
Mitch Williams5960d332014-09-13 07:40:47 +000053 case I40E_DEV_ID_10G_BASE_T:
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +000054 hw->mac.type = I40E_MAC_XL710;
55 break;
Shannon Nelsonab600852014-01-17 15:36:39 -080056 case I40E_DEV_ID_VF:
57 case I40E_DEV_ID_VF_HV:
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +000058 hw->mac.type = I40E_MAC_VF;
59 break;
60 default:
61 hw->mac.type = I40E_MAC_GENERIC;
62 break;
63 }
64 } else {
65 status = I40E_ERR_DEVICE_NOT_SUPPORTED;
66 }
67
68 hw_dbg(hw, "i40e_set_mac_type found mac: %d, returns: %d\n",
69 hw->mac.type, status);
70 return status;
71}
72
73/**
74 * i40e_debug_aq
75 * @hw: debug mask related to admin queue
Jeff Kirsher98d44382013-12-21 05:44:42 +000076 * @mask: debug mask
77 * @desc: pointer to admin queue descriptor
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +000078 * @buffer: pointer to command buffer
Shannon Nelsonf905dd62014-07-10 07:58:20 +000079 * @buf_len: max length of buffer
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +000080 *
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,
Shannon Nelsonf905dd62014-07-10 07:58:20 +000084 void *buffer, u16 buf_len)
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +000085{
86 struct i40e_aq_desc *aq_desc = (struct i40e_aq_desc *)desc;
Shannon Nelsonf905dd62014-07-10 07:58:20 +000087 u16 len = le16_to_cpu(aq_desc->datalen);
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +000088 u8 *aq_buffer = (u8 *)buffer;
89 u32 data[4];
90 u32 i = 0;
91
92 if ((!(mask & hw->debug_mask)) || (desc == NULL))
93 return;
94
95 i40e_debug(hw, mask,
96 "AQ CMD: opcode 0x%04X, flags 0x%04X, datalen 0x%04X, retval 0x%04X\n",
97 aq_desc->opcode, aq_desc->flags, aq_desc->datalen,
98 aq_desc->retval);
99 i40e_debug(hw, mask, "\tcookie (h,l) 0x%08X 0x%08X\n",
100 aq_desc->cookie_high, aq_desc->cookie_low);
101 i40e_debug(hw, mask, "\tparam (0,1) 0x%08X 0x%08X\n",
102 aq_desc->params.internal.param0,
103 aq_desc->params.internal.param1);
104 i40e_debug(hw, mask, "\taddr (h,l) 0x%08X 0x%08X\n",
105 aq_desc->params.external.addr_high,
106 aq_desc->params.external.addr_low);
107
108 if ((buffer != NULL) && (aq_desc->datalen != 0)) {
109 memset(data, 0, sizeof(data));
110 i40e_debug(hw, mask, "AQ CMD Buffer:\n");
Shannon Nelsonf905dd62014-07-10 07:58:20 +0000111 if (buf_len < len)
112 len = buf_len;
113 for (i = 0; i < len; i++) {
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +0000114 data[((i % 16) / 4)] |=
115 ((u32)aq_buffer[i]) << (8 * (i % 4));
116 if ((i % 16) == 15) {
117 i40e_debug(hw, mask,
118 "\t0x%04X %08X %08X %08X %08X\n",
119 i - 15, data[0], data[1], data[2],
120 data[3]);
121 memset(data, 0, sizeof(data));
122 }
123 }
124 if ((i % 16) != 0)
125 i40e_debug(hw, mask, "\t0x%04X %08X %08X %08X %08X\n",
126 i - (i % 16), data[0], data[1], data[2],
127 data[3]);
128 }
129}
130
131/**
Anjali Singhai Jaine1860d82013-11-28 06:39:45 +0000132 * i40e_check_asq_alive
133 * @hw: pointer to the hw struct
134 *
135 * Returns true if Queue is enabled else false.
136 **/
137bool i40e_check_asq_alive(struct i40e_hw *hw)
138{
Kevin Scott8b833b42014-04-09 05:58:54 +0000139 if (hw->aq.asq.len)
140 return !!(rd32(hw, hw->aq.asq.len) &
141 I40E_PF_ATQLEN_ATQENABLE_MASK);
142 else
143 return false;
Anjali Singhai Jaine1860d82013-11-28 06:39:45 +0000144}
145
146/**
147 * i40e_aq_queue_shutdown
148 * @hw: pointer to the hw struct
149 * @unloading: is the driver unloading itself
150 *
151 * Tell the Firmware that we're shutting down the AdminQ and whether
152 * or not the driver is unloading as well.
153 **/
154i40e_status i40e_aq_queue_shutdown(struct i40e_hw *hw,
155 bool unloading)
156{
157 struct i40e_aq_desc desc;
158 struct i40e_aqc_queue_shutdown *cmd =
159 (struct i40e_aqc_queue_shutdown *)&desc.params.raw;
160 i40e_status status;
161
162 i40e_fill_default_direct_cmd_desc(&desc,
163 i40e_aqc_opc_queue_shutdown);
164
165 if (unloading)
166 cmd->driver_unloading = cpu_to_le32(I40E_AQ_DRIVER_UNLOADING);
167 status = i40e_asq_send_command(hw, &desc, NULL, 0, NULL);
168
169 return status;
170}
171
Jesse Brandeburg206812b2014-02-12 01:45:33 +0000172/* The i40e_ptype_lookup table is used to convert from the 8-bit ptype in the
173 * hardware to a bit-field that can be used by SW to more easily determine the
174 * packet type.
175 *
176 * Macros are used to shorten the table lines and make this table human
177 * readable.
178 *
179 * We store the PTYPE in the top byte of the bit field - this is just so that
180 * we can check that the table doesn't have a row missing, as the index into
181 * the table should be the PTYPE.
182 *
183 * Typical work flow:
184 *
185 * IF NOT i40e_ptype_lookup[ptype].known
186 * THEN
187 * Packet is unknown
188 * ELSE IF i40e_ptype_lookup[ptype].outer_ip == I40E_RX_PTYPE_OUTER_IP
189 * Use the rest of the fields to look at the tunnels, inner protocols, etc
190 * ELSE
191 * Use the enum i40e_rx_l2_ptype to decode the packet type
192 * ENDIF
193 */
194
195/* macro to make the table lines short */
196#define I40E_PTT(PTYPE, OUTER_IP, OUTER_IP_VER, OUTER_FRAG, T, TE, TEF, I, PL)\
197 { PTYPE, \
198 1, \
199 I40E_RX_PTYPE_OUTER_##OUTER_IP, \
200 I40E_RX_PTYPE_OUTER_##OUTER_IP_VER, \
201 I40E_RX_PTYPE_##OUTER_FRAG, \
202 I40E_RX_PTYPE_TUNNEL_##T, \
203 I40E_RX_PTYPE_TUNNEL_END_##TE, \
204 I40E_RX_PTYPE_##TEF, \
205 I40E_RX_PTYPE_INNER_PROT_##I, \
206 I40E_RX_PTYPE_PAYLOAD_LAYER_##PL }
207
208#define I40E_PTT_UNUSED_ENTRY(PTYPE) \
209 { PTYPE, 0, 0, 0, 0, 0, 0, 0, 0, 0 }
210
211/* shorter macros makes the table fit but are terse */
212#define I40E_RX_PTYPE_NOF I40E_RX_PTYPE_NOT_FRAG
213#define I40E_RX_PTYPE_FRG I40E_RX_PTYPE_FRAG
214#define I40E_RX_PTYPE_INNER_PROT_TS I40E_RX_PTYPE_INNER_PROT_TIMESYNC
215
216/* Lookup table mapping the HW PTYPE to the bit field for decoding */
217struct i40e_rx_ptype_decoded i40e_ptype_lookup[] = {
218 /* L2 Packet types */
219 I40E_PTT_UNUSED_ENTRY(0),
220 I40E_PTT(1, L2, NONE, NOF, NONE, NONE, NOF, NONE, PAY2),
221 I40E_PTT(2, L2, NONE, NOF, NONE, NONE, NOF, TS, PAY2),
222 I40E_PTT(3, L2, NONE, NOF, NONE, NONE, NOF, NONE, PAY2),
223 I40E_PTT_UNUSED_ENTRY(4),
224 I40E_PTT_UNUSED_ENTRY(5),
225 I40E_PTT(6, L2, NONE, NOF, NONE, NONE, NOF, NONE, PAY2),
226 I40E_PTT(7, L2, NONE, NOF, NONE, NONE, NOF, NONE, PAY2),
227 I40E_PTT_UNUSED_ENTRY(8),
228 I40E_PTT_UNUSED_ENTRY(9),
229 I40E_PTT(10, L2, NONE, NOF, NONE, NONE, NOF, NONE, PAY2),
230 I40E_PTT(11, L2, NONE, NOF, NONE, NONE, NOF, NONE, NONE),
231 I40E_PTT(12, L2, NONE, NOF, NONE, NONE, NOF, NONE, PAY3),
232 I40E_PTT(13, L2, NONE, NOF, NONE, NONE, NOF, NONE, PAY3),
233 I40E_PTT(14, L2, NONE, NOF, NONE, NONE, NOF, NONE, PAY3),
234 I40E_PTT(15, L2, NONE, NOF, NONE, NONE, NOF, NONE, PAY3),
235 I40E_PTT(16, L2, NONE, NOF, NONE, NONE, NOF, NONE, PAY3),
236 I40E_PTT(17, L2, NONE, NOF, NONE, NONE, NOF, NONE, PAY3),
237 I40E_PTT(18, L2, NONE, NOF, NONE, NONE, NOF, NONE, PAY3),
238 I40E_PTT(19, L2, NONE, NOF, NONE, NONE, NOF, NONE, PAY3),
239 I40E_PTT(20, L2, NONE, NOF, NONE, NONE, NOF, NONE, PAY3),
240 I40E_PTT(21, L2, NONE, NOF, NONE, NONE, NOF, NONE, PAY3),
241
242 /* Non Tunneled IPv4 */
243 I40E_PTT(22, IP, IPV4, FRG, NONE, NONE, NOF, NONE, PAY3),
244 I40E_PTT(23, IP, IPV4, NOF, NONE, NONE, NOF, NONE, PAY3),
245 I40E_PTT(24, IP, IPV4, NOF, NONE, NONE, NOF, UDP, PAY4),
246 I40E_PTT_UNUSED_ENTRY(25),
247 I40E_PTT(26, IP, IPV4, NOF, NONE, NONE, NOF, TCP, PAY4),
248 I40E_PTT(27, IP, IPV4, NOF, NONE, NONE, NOF, SCTP, PAY4),
249 I40E_PTT(28, IP, IPV4, NOF, NONE, NONE, NOF, ICMP, PAY4),
250
251 /* IPv4 --> IPv4 */
252 I40E_PTT(29, IP, IPV4, NOF, IP_IP, IPV4, FRG, NONE, PAY3),
253 I40E_PTT(30, IP, IPV4, NOF, IP_IP, IPV4, NOF, NONE, PAY3),
254 I40E_PTT(31, IP, IPV4, NOF, IP_IP, IPV4, NOF, UDP, PAY4),
255 I40E_PTT_UNUSED_ENTRY(32),
256 I40E_PTT(33, IP, IPV4, NOF, IP_IP, IPV4, NOF, TCP, PAY4),
257 I40E_PTT(34, IP, IPV4, NOF, IP_IP, IPV4, NOF, SCTP, PAY4),
258 I40E_PTT(35, IP, IPV4, NOF, IP_IP, IPV4, NOF, ICMP, PAY4),
259
260 /* IPv4 --> IPv6 */
261 I40E_PTT(36, IP, IPV4, NOF, IP_IP, IPV6, FRG, NONE, PAY3),
262 I40E_PTT(37, IP, IPV4, NOF, IP_IP, IPV6, NOF, NONE, PAY3),
263 I40E_PTT(38, IP, IPV4, NOF, IP_IP, IPV6, NOF, UDP, PAY4),
264 I40E_PTT_UNUSED_ENTRY(39),
265 I40E_PTT(40, IP, IPV4, NOF, IP_IP, IPV6, NOF, TCP, PAY4),
266 I40E_PTT(41, IP, IPV4, NOF, IP_IP, IPV6, NOF, SCTP, PAY4),
267 I40E_PTT(42, IP, IPV4, NOF, IP_IP, IPV6, NOF, ICMP, PAY4),
268
269 /* IPv4 --> GRE/NAT */
270 I40E_PTT(43, IP, IPV4, NOF, IP_GRENAT, NONE, NOF, NONE, PAY3),
271
272 /* IPv4 --> GRE/NAT --> IPv4 */
273 I40E_PTT(44, IP, IPV4, NOF, IP_GRENAT, IPV4, FRG, NONE, PAY3),
274 I40E_PTT(45, IP, IPV4, NOF, IP_GRENAT, IPV4, NOF, NONE, PAY3),
275 I40E_PTT(46, IP, IPV4, NOF, IP_GRENAT, IPV4, NOF, UDP, PAY4),
276 I40E_PTT_UNUSED_ENTRY(47),
277 I40E_PTT(48, IP, IPV4, NOF, IP_GRENAT, IPV4, NOF, TCP, PAY4),
278 I40E_PTT(49, IP, IPV4, NOF, IP_GRENAT, IPV4, NOF, SCTP, PAY4),
279 I40E_PTT(50, IP, IPV4, NOF, IP_GRENAT, IPV4, NOF, ICMP, PAY4),
280
281 /* IPv4 --> GRE/NAT --> IPv6 */
282 I40E_PTT(51, IP, IPV4, NOF, IP_GRENAT, IPV6, FRG, NONE, PAY3),
283 I40E_PTT(52, IP, IPV4, NOF, IP_GRENAT, IPV6, NOF, NONE, PAY3),
284 I40E_PTT(53, IP, IPV4, NOF, IP_GRENAT, IPV6, NOF, UDP, PAY4),
285 I40E_PTT_UNUSED_ENTRY(54),
286 I40E_PTT(55, IP, IPV4, NOF, IP_GRENAT, IPV6, NOF, TCP, PAY4),
287 I40E_PTT(56, IP, IPV4, NOF, IP_GRENAT, IPV6, NOF, SCTP, PAY4),
288 I40E_PTT(57, IP, IPV4, NOF, IP_GRENAT, IPV6, NOF, ICMP, PAY4),
289
290 /* IPv4 --> GRE/NAT --> MAC */
291 I40E_PTT(58, IP, IPV4, NOF, IP_GRENAT_MAC, NONE, NOF, NONE, PAY3),
292
293 /* IPv4 --> GRE/NAT --> MAC --> IPv4 */
294 I40E_PTT(59, IP, IPV4, NOF, IP_GRENAT_MAC, IPV4, FRG, NONE, PAY3),
295 I40E_PTT(60, IP, IPV4, NOF, IP_GRENAT_MAC, IPV4, NOF, NONE, PAY3),
296 I40E_PTT(61, IP, IPV4, NOF, IP_GRENAT_MAC, IPV4, NOF, UDP, PAY4),
297 I40E_PTT_UNUSED_ENTRY(62),
298 I40E_PTT(63, IP, IPV4, NOF, IP_GRENAT_MAC, IPV4, NOF, TCP, PAY4),
299 I40E_PTT(64, IP, IPV4, NOF, IP_GRENAT_MAC, IPV4, NOF, SCTP, PAY4),
300 I40E_PTT(65, IP, IPV4, NOF, IP_GRENAT_MAC, IPV4, NOF, ICMP, PAY4),
301
302 /* IPv4 --> GRE/NAT -> MAC --> IPv6 */
303 I40E_PTT(66, IP, IPV4, NOF, IP_GRENAT_MAC, IPV6, FRG, NONE, PAY3),
304 I40E_PTT(67, IP, IPV4, NOF, IP_GRENAT_MAC, IPV6, NOF, NONE, PAY3),
305 I40E_PTT(68, IP, IPV4, NOF, IP_GRENAT_MAC, IPV6, NOF, UDP, PAY4),
306 I40E_PTT_UNUSED_ENTRY(69),
307 I40E_PTT(70, IP, IPV4, NOF, IP_GRENAT_MAC, IPV6, NOF, TCP, PAY4),
308 I40E_PTT(71, IP, IPV4, NOF, IP_GRENAT_MAC, IPV6, NOF, SCTP, PAY4),
309 I40E_PTT(72, IP, IPV4, NOF, IP_GRENAT_MAC, IPV6, NOF, ICMP, PAY4),
310
311 /* IPv4 --> GRE/NAT --> MAC/VLAN */
312 I40E_PTT(73, IP, IPV4, NOF, IP_GRENAT_MAC_VLAN, NONE, NOF, NONE, PAY3),
313
314 /* IPv4 ---> GRE/NAT -> MAC/VLAN --> IPv4 */
315 I40E_PTT(74, IP, IPV4, NOF, IP_GRENAT_MAC_VLAN, IPV4, FRG, NONE, PAY3),
316 I40E_PTT(75, IP, IPV4, NOF, IP_GRENAT_MAC_VLAN, IPV4, NOF, NONE, PAY3),
317 I40E_PTT(76, IP, IPV4, NOF, IP_GRENAT_MAC_VLAN, IPV4, NOF, UDP, PAY4),
318 I40E_PTT_UNUSED_ENTRY(77),
319 I40E_PTT(78, IP, IPV4, NOF, IP_GRENAT_MAC_VLAN, IPV4, NOF, TCP, PAY4),
320 I40E_PTT(79, IP, IPV4, NOF, IP_GRENAT_MAC_VLAN, IPV4, NOF, SCTP, PAY4),
321 I40E_PTT(80, IP, IPV4, NOF, IP_GRENAT_MAC_VLAN, IPV4, NOF, ICMP, PAY4),
322
323 /* IPv4 -> GRE/NAT -> MAC/VLAN --> IPv6 */
324 I40E_PTT(81, IP, IPV4, NOF, IP_GRENAT_MAC_VLAN, IPV6, FRG, NONE, PAY3),
325 I40E_PTT(82, IP, IPV4, NOF, IP_GRENAT_MAC_VLAN, IPV6, NOF, NONE, PAY3),
326 I40E_PTT(83, IP, IPV4, NOF, IP_GRENAT_MAC_VLAN, IPV6, NOF, UDP, PAY4),
327 I40E_PTT_UNUSED_ENTRY(84),
328 I40E_PTT(85, IP, IPV4, NOF, IP_GRENAT_MAC_VLAN, IPV6, NOF, TCP, PAY4),
329 I40E_PTT(86, IP, IPV4, NOF, IP_GRENAT_MAC_VLAN, IPV6, NOF, SCTP, PAY4),
330 I40E_PTT(87, IP, IPV4, NOF, IP_GRENAT_MAC_VLAN, IPV6, NOF, ICMP, PAY4),
331
332 /* Non Tunneled IPv6 */
333 I40E_PTT(88, IP, IPV6, FRG, NONE, NONE, NOF, NONE, PAY3),
334 I40E_PTT(89, IP, IPV6, NOF, NONE, NONE, NOF, NONE, PAY3),
335 I40E_PTT(90, IP, IPV6, NOF, NONE, NONE, NOF, UDP, PAY3),
336 I40E_PTT_UNUSED_ENTRY(91),
337 I40E_PTT(92, IP, IPV6, NOF, NONE, NONE, NOF, TCP, PAY4),
338 I40E_PTT(93, IP, IPV6, NOF, NONE, NONE, NOF, SCTP, PAY4),
339 I40E_PTT(94, IP, IPV6, NOF, NONE, NONE, NOF, ICMP, PAY4),
340
341 /* IPv6 --> IPv4 */
342 I40E_PTT(95, IP, IPV6, NOF, IP_IP, IPV4, FRG, NONE, PAY3),
343 I40E_PTT(96, IP, IPV6, NOF, IP_IP, IPV4, NOF, NONE, PAY3),
344 I40E_PTT(97, IP, IPV6, NOF, IP_IP, IPV4, NOF, UDP, PAY4),
345 I40E_PTT_UNUSED_ENTRY(98),
346 I40E_PTT(99, IP, IPV6, NOF, IP_IP, IPV4, NOF, TCP, PAY4),
347 I40E_PTT(100, IP, IPV6, NOF, IP_IP, IPV4, NOF, SCTP, PAY4),
348 I40E_PTT(101, IP, IPV6, NOF, IP_IP, IPV4, NOF, ICMP, PAY4),
349
350 /* IPv6 --> IPv6 */
351 I40E_PTT(102, IP, IPV6, NOF, IP_IP, IPV6, FRG, NONE, PAY3),
352 I40E_PTT(103, IP, IPV6, NOF, IP_IP, IPV6, NOF, NONE, PAY3),
353 I40E_PTT(104, IP, IPV6, NOF, IP_IP, IPV6, NOF, UDP, PAY4),
354 I40E_PTT_UNUSED_ENTRY(105),
355 I40E_PTT(106, IP, IPV6, NOF, IP_IP, IPV6, NOF, TCP, PAY4),
356 I40E_PTT(107, IP, IPV6, NOF, IP_IP, IPV6, NOF, SCTP, PAY4),
357 I40E_PTT(108, IP, IPV6, NOF, IP_IP, IPV6, NOF, ICMP, PAY4),
358
359 /* IPv6 --> GRE/NAT */
360 I40E_PTT(109, IP, IPV6, NOF, IP_GRENAT, NONE, NOF, NONE, PAY3),
361
362 /* IPv6 --> GRE/NAT -> IPv4 */
363 I40E_PTT(110, IP, IPV6, NOF, IP_GRENAT, IPV4, FRG, NONE, PAY3),
364 I40E_PTT(111, IP, IPV6, NOF, IP_GRENAT, IPV4, NOF, NONE, PAY3),
365 I40E_PTT(112, IP, IPV6, NOF, IP_GRENAT, IPV4, NOF, UDP, PAY4),
366 I40E_PTT_UNUSED_ENTRY(113),
367 I40E_PTT(114, IP, IPV6, NOF, IP_GRENAT, IPV4, NOF, TCP, PAY4),
368 I40E_PTT(115, IP, IPV6, NOF, IP_GRENAT, IPV4, NOF, SCTP, PAY4),
369 I40E_PTT(116, IP, IPV6, NOF, IP_GRENAT, IPV4, NOF, ICMP, PAY4),
370
371 /* IPv6 --> GRE/NAT -> IPv6 */
372 I40E_PTT(117, IP, IPV6, NOF, IP_GRENAT, IPV6, FRG, NONE, PAY3),
373 I40E_PTT(118, IP, IPV6, NOF, IP_GRENAT, IPV6, NOF, NONE, PAY3),
374 I40E_PTT(119, IP, IPV6, NOF, IP_GRENAT, IPV6, NOF, UDP, PAY4),
375 I40E_PTT_UNUSED_ENTRY(120),
376 I40E_PTT(121, IP, IPV6, NOF, IP_GRENAT, IPV6, NOF, TCP, PAY4),
377 I40E_PTT(122, IP, IPV6, NOF, IP_GRENAT, IPV6, NOF, SCTP, PAY4),
378 I40E_PTT(123, IP, IPV6, NOF, IP_GRENAT, IPV6, NOF, ICMP, PAY4),
379
380 /* IPv6 --> GRE/NAT -> MAC */
381 I40E_PTT(124, IP, IPV6, NOF, IP_GRENAT_MAC, NONE, NOF, NONE, PAY3),
382
383 /* IPv6 --> GRE/NAT -> MAC -> IPv4 */
384 I40E_PTT(125, IP, IPV6, NOF, IP_GRENAT_MAC, IPV4, FRG, NONE, PAY3),
385 I40E_PTT(126, IP, IPV6, NOF, IP_GRENAT_MAC, IPV4, NOF, NONE, PAY3),
386 I40E_PTT(127, IP, IPV6, NOF, IP_GRENAT_MAC, IPV4, NOF, UDP, PAY4),
387 I40E_PTT_UNUSED_ENTRY(128),
388 I40E_PTT(129, IP, IPV6, NOF, IP_GRENAT_MAC, IPV4, NOF, TCP, PAY4),
389 I40E_PTT(130, IP, IPV6, NOF, IP_GRENAT_MAC, IPV4, NOF, SCTP, PAY4),
390 I40E_PTT(131, IP, IPV6, NOF, IP_GRENAT_MAC, IPV4, NOF, ICMP, PAY4),
391
392 /* IPv6 --> GRE/NAT -> MAC -> IPv6 */
393 I40E_PTT(132, IP, IPV6, NOF, IP_GRENAT_MAC, IPV6, FRG, NONE, PAY3),
394 I40E_PTT(133, IP, IPV6, NOF, IP_GRENAT_MAC, IPV6, NOF, NONE, PAY3),
395 I40E_PTT(134, IP, IPV6, NOF, IP_GRENAT_MAC, IPV6, NOF, UDP, PAY4),
396 I40E_PTT_UNUSED_ENTRY(135),
397 I40E_PTT(136, IP, IPV6, NOF, IP_GRENAT_MAC, IPV6, NOF, TCP, PAY4),
398 I40E_PTT(137, IP, IPV6, NOF, IP_GRENAT_MAC, IPV6, NOF, SCTP, PAY4),
399 I40E_PTT(138, IP, IPV6, NOF, IP_GRENAT_MAC, IPV6, NOF, ICMP, PAY4),
400
401 /* IPv6 --> GRE/NAT -> MAC/VLAN */
402 I40E_PTT(139, IP, IPV6, NOF, IP_GRENAT_MAC_VLAN, NONE, NOF, NONE, PAY3),
403
404 /* IPv6 --> GRE/NAT -> MAC/VLAN --> IPv4 */
405 I40E_PTT(140, IP, IPV6, NOF, IP_GRENAT_MAC_VLAN, IPV4, FRG, NONE, PAY3),
406 I40E_PTT(141, IP, IPV6, NOF, IP_GRENAT_MAC_VLAN, IPV4, NOF, NONE, PAY3),
407 I40E_PTT(142, IP, IPV6, NOF, IP_GRENAT_MAC_VLAN, IPV4, NOF, UDP, PAY4),
408 I40E_PTT_UNUSED_ENTRY(143),
409 I40E_PTT(144, IP, IPV6, NOF, IP_GRENAT_MAC_VLAN, IPV4, NOF, TCP, PAY4),
410 I40E_PTT(145, IP, IPV6, NOF, IP_GRENAT_MAC_VLAN, IPV4, NOF, SCTP, PAY4),
411 I40E_PTT(146, IP, IPV6, NOF, IP_GRENAT_MAC_VLAN, IPV4, NOF, ICMP, PAY4),
412
413 /* IPv6 --> GRE/NAT -> MAC/VLAN --> IPv6 */
414 I40E_PTT(147, IP, IPV6, NOF, IP_GRENAT_MAC_VLAN, IPV6, FRG, NONE, PAY3),
415 I40E_PTT(148, IP, IPV6, NOF, IP_GRENAT_MAC_VLAN, IPV6, NOF, NONE, PAY3),
416 I40E_PTT(149, IP, IPV6, NOF, IP_GRENAT_MAC_VLAN, IPV6, NOF, UDP, PAY4),
417 I40E_PTT_UNUSED_ENTRY(150),
418 I40E_PTT(151, IP, IPV6, NOF, IP_GRENAT_MAC_VLAN, IPV6, NOF, TCP, PAY4),
419 I40E_PTT(152, IP, IPV6, NOF, IP_GRENAT_MAC_VLAN, IPV6, NOF, SCTP, PAY4),
420 I40E_PTT(153, IP, IPV6, NOF, IP_GRENAT_MAC_VLAN, IPV6, NOF, ICMP, PAY4),
421
422 /* unused entries */
423 I40E_PTT_UNUSED_ENTRY(154),
424 I40E_PTT_UNUSED_ENTRY(155),
425 I40E_PTT_UNUSED_ENTRY(156),
426 I40E_PTT_UNUSED_ENTRY(157),
427 I40E_PTT_UNUSED_ENTRY(158),
428 I40E_PTT_UNUSED_ENTRY(159),
429
430 I40E_PTT_UNUSED_ENTRY(160),
431 I40E_PTT_UNUSED_ENTRY(161),
432 I40E_PTT_UNUSED_ENTRY(162),
433 I40E_PTT_UNUSED_ENTRY(163),
434 I40E_PTT_UNUSED_ENTRY(164),
435 I40E_PTT_UNUSED_ENTRY(165),
436 I40E_PTT_UNUSED_ENTRY(166),
437 I40E_PTT_UNUSED_ENTRY(167),
438 I40E_PTT_UNUSED_ENTRY(168),
439 I40E_PTT_UNUSED_ENTRY(169),
440
441 I40E_PTT_UNUSED_ENTRY(170),
442 I40E_PTT_UNUSED_ENTRY(171),
443 I40E_PTT_UNUSED_ENTRY(172),
444 I40E_PTT_UNUSED_ENTRY(173),
445 I40E_PTT_UNUSED_ENTRY(174),
446 I40E_PTT_UNUSED_ENTRY(175),
447 I40E_PTT_UNUSED_ENTRY(176),
448 I40E_PTT_UNUSED_ENTRY(177),
449 I40E_PTT_UNUSED_ENTRY(178),
450 I40E_PTT_UNUSED_ENTRY(179),
451
452 I40E_PTT_UNUSED_ENTRY(180),
453 I40E_PTT_UNUSED_ENTRY(181),
454 I40E_PTT_UNUSED_ENTRY(182),
455 I40E_PTT_UNUSED_ENTRY(183),
456 I40E_PTT_UNUSED_ENTRY(184),
457 I40E_PTT_UNUSED_ENTRY(185),
458 I40E_PTT_UNUSED_ENTRY(186),
459 I40E_PTT_UNUSED_ENTRY(187),
460 I40E_PTT_UNUSED_ENTRY(188),
461 I40E_PTT_UNUSED_ENTRY(189),
462
463 I40E_PTT_UNUSED_ENTRY(190),
464 I40E_PTT_UNUSED_ENTRY(191),
465 I40E_PTT_UNUSED_ENTRY(192),
466 I40E_PTT_UNUSED_ENTRY(193),
467 I40E_PTT_UNUSED_ENTRY(194),
468 I40E_PTT_UNUSED_ENTRY(195),
469 I40E_PTT_UNUSED_ENTRY(196),
470 I40E_PTT_UNUSED_ENTRY(197),
471 I40E_PTT_UNUSED_ENTRY(198),
472 I40E_PTT_UNUSED_ENTRY(199),
473
474 I40E_PTT_UNUSED_ENTRY(200),
475 I40E_PTT_UNUSED_ENTRY(201),
476 I40E_PTT_UNUSED_ENTRY(202),
477 I40E_PTT_UNUSED_ENTRY(203),
478 I40E_PTT_UNUSED_ENTRY(204),
479 I40E_PTT_UNUSED_ENTRY(205),
480 I40E_PTT_UNUSED_ENTRY(206),
481 I40E_PTT_UNUSED_ENTRY(207),
482 I40E_PTT_UNUSED_ENTRY(208),
483 I40E_PTT_UNUSED_ENTRY(209),
484
485 I40E_PTT_UNUSED_ENTRY(210),
486 I40E_PTT_UNUSED_ENTRY(211),
487 I40E_PTT_UNUSED_ENTRY(212),
488 I40E_PTT_UNUSED_ENTRY(213),
489 I40E_PTT_UNUSED_ENTRY(214),
490 I40E_PTT_UNUSED_ENTRY(215),
491 I40E_PTT_UNUSED_ENTRY(216),
492 I40E_PTT_UNUSED_ENTRY(217),
493 I40E_PTT_UNUSED_ENTRY(218),
494 I40E_PTT_UNUSED_ENTRY(219),
495
496 I40E_PTT_UNUSED_ENTRY(220),
497 I40E_PTT_UNUSED_ENTRY(221),
498 I40E_PTT_UNUSED_ENTRY(222),
499 I40E_PTT_UNUSED_ENTRY(223),
500 I40E_PTT_UNUSED_ENTRY(224),
501 I40E_PTT_UNUSED_ENTRY(225),
502 I40E_PTT_UNUSED_ENTRY(226),
503 I40E_PTT_UNUSED_ENTRY(227),
504 I40E_PTT_UNUSED_ENTRY(228),
505 I40E_PTT_UNUSED_ENTRY(229),
506
507 I40E_PTT_UNUSED_ENTRY(230),
508 I40E_PTT_UNUSED_ENTRY(231),
509 I40E_PTT_UNUSED_ENTRY(232),
510 I40E_PTT_UNUSED_ENTRY(233),
511 I40E_PTT_UNUSED_ENTRY(234),
512 I40E_PTT_UNUSED_ENTRY(235),
513 I40E_PTT_UNUSED_ENTRY(236),
514 I40E_PTT_UNUSED_ENTRY(237),
515 I40E_PTT_UNUSED_ENTRY(238),
516 I40E_PTT_UNUSED_ENTRY(239),
517
518 I40E_PTT_UNUSED_ENTRY(240),
519 I40E_PTT_UNUSED_ENTRY(241),
520 I40E_PTT_UNUSED_ENTRY(242),
521 I40E_PTT_UNUSED_ENTRY(243),
522 I40E_PTT_UNUSED_ENTRY(244),
523 I40E_PTT_UNUSED_ENTRY(245),
524 I40E_PTT_UNUSED_ENTRY(246),
525 I40E_PTT_UNUSED_ENTRY(247),
526 I40E_PTT_UNUSED_ENTRY(248),
527 I40E_PTT_UNUSED_ENTRY(249),
528
529 I40E_PTT_UNUSED_ENTRY(250),
530 I40E_PTT_UNUSED_ENTRY(251),
531 I40E_PTT_UNUSED_ENTRY(252),
532 I40E_PTT_UNUSED_ENTRY(253),
533 I40E_PTT_UNUSED_ENTRY(254),
534 I40E_PTT_UNUSED_ENTRY(255)
535};
536
537
Anjali Singhai Jaine1860d82013-11-28 06:39:45 +0000538/**
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +0000539 * i40e_init_shared_code - Initialize the shared code
540 * @hw: pointer to hardware structure
541 *
542 * This assigns the MAC type and PHY code and inits the NVM.
543 * Does not touch the hardware. This function must be called prior to any
544 * other function in the shared code. The i40e_hw structure should be
545 * memset to 0 prior to calling this function. The following fields in
546 * hw structure should be filled in prior to calling this function:
547 * hw_addr, back, device_id, vendor_id, subsystem_device_id,
548 * subsystem_vendor_id, and revision_id
549 **/
550i40e_status i40e_init_shared_code(struct i40e_hw *hw)
551{
552 i40e_status status = 0;
Shannon Nelson5fb11d72014-11-13 03:06:19 +0000553 u32 port, ari, func_rid;
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +0000554
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +0000555 i40e_set_mac_type(hw);
556
557 switch (hw->mac.type) {
558 case I40E_MAC_XL710:
559 break;
560 default:
561 return I40E_ERR_DEVICE_NOT_SUPPORTED;
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +0000562 }
563
Shannon Nelsonaf89d26c2013-12-11 08:17:14 +0000564 hw->phy.get_link_info = true;
565
Shannon Nelson5fb11d72014-11-13 03:06:19 +0000566 /* Determine port number and PF number*/
567 port = (rd32(hw, I40E_PFGEN_PORTNUM) & I40E_PFGEN_PORTNUM_PORT_NUM_MASK)
568 >> I40E_PFGEN_PORTNUM_PORT_NUM_SHIFT;
569 hw->port = (u8)port;
570 ari = (rd32(hw, I40E_GLPCI_CAPSUP) & I40E_GLPCI_CAPSUP_ARI_EN_MASK) >>
571 I40E_GLPCI_CAPSUP_ARI_EN_SHIFT;
572 func_rid = rd32(hw, I40E_PF_FUNC_RID);
573 if (ari)
574 hw->pf_id = (u8)(func_rid & 0xff);
Shannon Nelson5f9116a2013-12-11 08:17:13 +0000575 else
Shannon Nelson5fb11d72014-11-13 03:06:19 +0000576 hw->pf_id = (u8)(func_rid & 0x7);
Shannon Nelson5f9116a2013-12-11 08:17:13 +0000577
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +0000578 status = i40e_init_nvm(hw);
579 return status;
580}
581
582/**
583 * i40e_aq_mac_address_read - Retrieve the MAC addresses
584 * @hw: pointer to the hw struct
585 * @flags: a return indicator of what addresses were added to the addr store
586 * @addrs: the requestor's mac addr store
587 * @cmd_details: pointer to command details structure or NULL
588 **/
589static i40e_status i40e_aq_mac_address_read(struct i40e_hw *hw,
590 u16 *flags,
591 struct i40e_aqc_mac_address_read_data *addrs,
592 struct i40e_asq_cmd_details *cmd_details)
593{
594 struct i40e_aq_desc desc;
595 struct i40e_aqc_mac_address_read *cmd_data =
596 (struct i40e_aqc_mac_address_read *)&desc.params.raw;
597 i40e_status status;
598
599 i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_mac_address_read);
600 desc.flags |= cpu_to_le16(I40E_AQ_FLAG_BUF);
601
602 status = i40e_asq_send_command(hw, &desc, addrs,
603 sizeof(*addrs), cmd_details);
604 *flags = le16_to_cpu(cmd_data->command_flags);
605
606 return status;
607}
608
609/**
610 * i40e_aq_mac_address_write - Change the MAC addresses
611 * @hw: pointer to the hw struct
612 * @flags: indicates which MAC to be written
613 * @mac_addr: address to write
614 * @cmd_details: pointer to command details structure or NULL
615 **/
616i40e_status i40e_aq_mac_address_write(struct i40e_hw *hw,
617 u16 flags, u8 *mac_addr,
618 struct i40e_asq_cmd_details *cmd_details)
619{
620 struct i40e_aq_desc desc;
621 struct i40e_aqc_mac_address_write *cmd_data =
622 (struct i40e_aqc_mac_address_write *)&desc.params.raw;
623 i40e_status status;
624
625 i40e_fill_default_direct_cmd_desc(&desc,
626 i40e_aqc_opc_mac_address_write);
627 cmd_data->command_flags = cpu_to_le16(flags);
Kamil Krawczyk55c29c32013-12-18 13:45:52 +0000628 cmd_data->mac_sah = cpu_to_le16((u16)mac_addr[0] << 8 | mac_addr[1]);
629 cmd_data->mac_sal = cpu_to_le32(((u32)mac_addr[2] << 24) |
630 ((u32)mac_addr[3] << 16) |
631 ((u32)mac_addr[4] << 8) |
632 mac_addr[5]);
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +0000633
634 status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
635
636 return status;
637}
638
639/**
640 * i40e_get_mac_addr - get MAC address
641 * @hw: pointer to the HW structure
642 * @mac_addr: pointer to MAC address
643 *
644 * Reads the adapter's MAC address from register
645 **/
646i40e_status i40e_get_mac_addr(struct i40e_hw *hw, u8 *mac_addr)
647{
648 struct i40e_aqc_mac_address_read_data addrs;
649 i40e_status status;
650 u16 flags = 0;
651
652 status = i40e_aq_mac_address_read(hw, &flags, &addrs, NULL);
653
654 if (flags & I40E_AQC_LAN_ADDR_VALID)
655 memcpy(mac_addr, &addrs.pf_lan_mac, sizeof(addrs.pf_lan_mac));
656
657 return status;
658}
659
660/**
Neerav Parikh1f224ad2014-02-12 01:45:31 +0000661 * i40e_get_port_mac_addr - get Port MAC address
662 * @hw: pointer to the HW structure
663 * @mac_addr: pointer to Port MAC address
664 *
665 * Reads the adapter's Port MAC address
666 **/
667i40e_status i40e_get_port_mac_addr(struct i40e_hw *hw, u8 *mac_addr)
668{
669 struct i40e_aqc_mac_address_read_data addrs;
670 i40e_status status;
671 u16 flags = 0;
672
673 status = i40e_aq_mac_address_read(hw, &flags, &addrs, NULL);
674 if (status)
675 return status;
676
677 if (flags & I40E_AQC_PORT_ADDR_VALID)
678 memcpy(mac_addr, &addrs.port_mac, sizeof(addrs.port_mac));
679 else
680 status = I40E_ERR_INVALID_MAC_ADDR;
681
682 return status;
683}
684
685/**
Matt Jared351499ab2014-04-23 04:50:03 +0000686 * i40e_pre_tx_queue_cfg - pre tx queue configure
687 * @hw: pointer to the HW structure
688 * @queue: target pf queue index
689 * @enable: state change request
690 *
691 * Handles hw requirement to indicate intention to enable
692 * or disable target queue.
693 **/
694void i40e_pre_tx_queue_cfg(struct i40e_hw *hw, u32 queue, bool enable)
695{
Shannon Nelsondfb699f2014-05-22 06:32:28 +0000696 u32 abs_queue_idx = hw->func_caps.base_queue + queue;
Matt Jared351499ab2014-04-23 04:50:03 +0000697 u32 reg_block = 0;
Shannon Nelsondfb699f2014-05-22 06:32:28 +0000698 u32 reg_val;
Matt Jared351499ab2014-04-23 04:50:03 +0000699
Christopher Pau24a768c2014-06-04 20:41:59 +0000700 if (abs_queue_idx >= 128) {
Matt Jared351499ab2014-04-23 04:50:03 +0000701 reg_block = abs_queue_idx / 128;
Christopher Pau24a768c2014-06-04 20:41:59 +0000702 abs_queue_idx %= 128;
703 }
Matt Jared351499ab2014-04-23 04:50:03 +0000704
705 reg_val = rd32(hw, I40E_GLLAN_TXPRE_QDIS(reg_block));
706 reg_val &= ~I40E_GLLAN_TXPRE_QDIS_QINDX_MASK;
707 reg_val |= (abs_queue_idx << I40E_GLLAN_TXPRE_QDIS_QINDX_SHIFT);
708
709 if (enable)
710 reg_val |= I40E_GLLAN_TXPRE_QDIS_CLEAR_QDIS_MASK;
711 else
712 reg_val |= I40E_GLLAN_TXPRE_QDIS_SET_QDIS_MASK;
713
714 wr32(hw, I40E_GLLAN_TXPRE_QDIS(reg_block), reg_val);
715}
Vasu Dev38e00432014-08-01 13:27:03 -0700716#ifdef I40E_FCOE
717
718/**
719 * i40e_get_san_mac_addr - get SAN MAC address
720 * @hw: pointer to the HW structure
721 * @mac_addr: pointer to SAN MAC address
722 *
723 * Reads the adapter's SAN MAC address from NVM
724 **/
725i40e_status i40e_get_san_mac_addr(struct i40e_hw *hw, u8 *mac_addr)
726{
727 struct i40e_aqc_mac_address_read_data addrs;
728 i40e_status status;
729 u16 flags = 0;
730
731 status = i40e_aq_mac_address_read(hw, &flags, &addrs, NULL);
732 if (status)
733 return status;
734
735 if (flags & I40E_AQC_SAN_ADDR_VALID)
736 memcpy(mac_addr, &addrs.pf_san_mac, sizeof(addrs.pf_san_mac));
737 else
738 status = I40E_ERR_INVALID_MAC_ADDR;
739
740 return status;
741}
742#endif
Matt Jared351499ab2014-04-23 04:50:03 +0000743
744/**
Jesse Brandeburgbe405eb2013-11-20 10:02:50 +0000745 * i40e_get_media_type - Gets media type
746 * @hw: pointer to the hardware structure
747 **/
748static enum i40e_media_type i40e_get_media_type(struct i40e_hw *hw)
749{
750 enum i40e_media_type media;
751
752 switch (hw->phy.link_info.phy_type) {
753 case I40E_PHY_TYPE_10GBASE_SR:
754 case I40E_PHY_TYPE_10GBASE_LR:
Catherine Sullivan124ed152014-07-12 07:28:12 +0000755 case I40E_PHY_TYPE_1000BASE_SX:
756 case I40E_PHY_TYPE_1000BASE_LX:
Jesse Brandeburgbe405eb2013-11-20 10:02:50 +0000757 case I40E_PHY_TYPE_40GBASE_SR4:
758 case I40E_PHY_TYPE_40GBASE_LR4:
759 media = I40E_MEDIA_TYPE_FIBER;
760 break;
761 case I40E_PHY_TYPE_100BASE_TX:
762 case I40E_PHY_TYPE_1000BASE_T:
763 case I40E_PHY_TYPE_10GBASE_T:
764 media = I40E_MEDIA_TYPE_BASET;
765 break;
766 case I40E_PHY_TYPE_10GBASE_CR1_CU:
767 case I40E_PHY_TYPE_40GBASE_CR4_CU:
768 case I40E_PHY_TYPE_10GBASE_CR1:
769 case I40E_PHY_TYPE_40GBASE_CR4:
770 case I40E_PHY_TYPE_10GBASE_SFPP_CU:
771 media = I40E_MEDIA_TYPE_DA;
772 break;
773 case I40E_PHY_TYPE_1000BASE_KX:
774 case I40E_PHY_TYPE_10GBASE_KX4:
775 case I40E_PHY_TYPE_10GBASE_KR:
776 case I40E_PHY_TYPE_40GBASE_KR4:
777 media = I40E_MEDIA_TYPE_BACKPLANE;
778 break;
779 case I40E_PHY_TYPE_SGMII:
780 case I40E_PHY_TYPE_XAUI:
781 case I40E_PHY_TYPE_XFI:
782 case I40E_PHY_TYPE_XLAUI:
783 case I40E_PHY_TYPE_XLPPI:
784 default:
785 media = I40E_MEDIA_TYPE_UNKNOWN;
786 break;
787 }
788
789 return media;
790}
791
Jesse Brandeburg7134f9c2013-11-26 08:56:05 +0000792#define I40E_PF_RESET_WAIT_COUNT_A0 200
Kevin Scottb9a81b22014-11-13 03:06:13 +0000793#define I40E_PF_RESET_WAIT_COUNT 110
Jesse Brandeburgbe405eb2013-11-20 10:02:50 +0000794/**
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +0000795 * i40e_pf_reset - Reset the PF
796 * @hw: pointer to the hardware structure
797 *
798 * Assuming someone else has triggered a global reset,
799 * assure the global reset is complete and then reset the PF
800 **/
801i40e_status i40e_pf_reset(struct i40e_hw *hw)
802{
Jesse Brandeburg7134f9c2013-11-26 08:56:05 +0000803 u32 cnt = 0;
Shannon Nelson42794bd2013-12-11 08:17:10 +0000804 u32 cnt1 = 0;
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +0000805 u32 reg = 0;
806 u32 grst_del;
807
808 /* Poll for Global Reset steady state in case of recent GRST.
809 * The grst delay value is in 100ms units, and we'll wait a
810 * couple counts longer to be sure we don't just miss the end.
811 */
812 grst_del = rd32(hw, I40E_GLGEN_RSTCTL) & I40E_GLGEN_RSTCTL_GRSTDEL_MASK
813 >> I40E_GLGEN_RSTCTL_GRSTDEL_SHIFT;
Jesse Brandeburg7134f9c2013-11-26 08:56:05 +0000814 for (cnt = 0; cnt < grst_del + 2; cnt++) {
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +0000815 reg = rd32(hw, I40E_GLGEN_RSTAT);
816 if (!(reg & I40E_GLGEN_RSTAT_DEVSTATE_MASK))
817 break;
818 msleep(100);
819 }
820 if (reg & I40E_GLGEN_RSTAT_DEVSTATE_MASK) {
821 hw_dbg(hw, "Global reset polling failed to complete.\n");
822 return I40E_ERR_RESET_FAILED;
823 }
824
Shannon Nelson42794bd2013-12-11 08:17:10 +0000825 /* Now Wait for the FW to be ready */
826 for (cnt1 = 0; cnt1 < I40E_PF_RESET_WAIT_COUNT; cnt1++) {
827 reg = rd32(hw, I40E_GLNVM_ULD);
828 reg &= (I40E_GLNVM_ULD_CONF_CORE_DONE_MASK |
829 I40E_GLNVM_ULD_CONF_GLOBAL_DONE_MASK);
830 if (reg == (I40E_GLNVM_ULD_CONF_CORE_DONE_MASK |
831 I40E_GLNVM_ULD_CONF_GLOBAL_DONE_MASK)) {
832 hw_dbg(hw, "Core and Global modules ready %d\n", cnt1);
833 break;
834 }
835 usleep_range(10000, 20000);
836 }
837 if (!(reg & (I40E_GLNVM_ULD_CONF_CORE_DONE_MASK |
838 I40E_GLNVM_ULD_CONF_GLOBAL_DONE_MASK))) {
839 hw_dbg(hw, "wait for FW Reset complete timedout\n");
840 hw_dbg(hw, "I40E_GLNVM_ULD = 0x%x\n", reg);
841 return I40E_ERR_RESET_FAILED;
842 }
843
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +0000844 /* If there was a Global Reset in progress when we got here,
845 * we don't need to do the PF Reset
846 */
Jesse Brandeburg7134f9c2013-11-26 08:56:05 +0000847 if (!cnt) {
848 if (hw->revision_id == 0)
849 cnt = I40E_PF_RESET_WAIT_COUNT_A0;
850 else
851 cnt = I40E_PF_RESET_WAIT_COUNT;
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +0000852 reg = rd32(hw, I40E_PFGEN_CTRL);
853 wr32(hw, I40E_PFGEN_CTRL,
854 (reg | I40E_PFGEN_CTRL_PFSWR_MASK));
Jesse Brandeburg7134f9c2013-11-26 08:56:05 +0000855 for (; cnt; cnt--) {
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +0000856 reg = rd32(hw, I40E_PFGEN_CTRL);
857 if (!(reg & I40E_PFGEN_CTRL_PFSWR_MASK))
858 break;
859 usleep_range(1000, 2000);
860 }
861 if (reg & I40E_PFGEN_CTRL_PFSWR_MASK) {
862 hw_dbg(hw, "PF reset polling failed to complete.\n");
863 return I40E_ERR_RESET_FAILED;
864 }
865 }
866
867 i40e_clear_pxe_mode(hw);
Shannon Nelson922680b2013-12-18 05:29:17 +0000868
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +0000869 return 0;
870}
871
872/**
Shannon Nelson838d41d2014-06-04 20:41:27 +0000873 * i40e_clear_hw - clear out any left over hw state
874 * @hw: pointer to the hw struct
875 *
876 * Clear queues and interrupts, typically called at init time,
877 * but after the capabilities have been found so we know how many
878 * queues and msix vectors have been allocated.
879 **/
880void i40e_clear_hw(struct i40e_hw *hw)
881{
882 u32 num_queues, base_queue;
883 u32 num_pf_int;
884 u32 num_vf_int;
885 u32 num_vfs;
886 u32 i, j;
887 u32 val;
888 u32 eol = 0x7ff;
889
890 /* get number of interrupts, queues, and vfs */
891 val = rd32(hw, I40E_GLPCI_CNF2);
892 num_pf_int = (val & I40E_GLPCI_CNF2_MSI_X_PF_N_MASK) >>
893 I40E_GLPCI_CNF2_MSI_X_PF_N_SHIFT;
894 num_vf_int = (val & I40E_GLPCI_CNF2_MSI_X_VF_N_MASK) >>
895 I40E_GLPCI_CNF2_MSI_X_VF_N_SHIFT;
896
897 val = rd32(hw, I40E_PFLAN_QALLOC);
898 base_queue = (val & I40E_PFLAN_QALLOC_FIRSTQ_MASK) >>
899 I40E_PFLAN_QALLOC_FIRSTQ_SHIFT;
900 j = (val & I40E_PFLAN_QALLOC_LASTQ_MASK) >>
901 I40E_PFLAN_QALLOC_LASTQ_SHIFT;
902 if (val & I40E_PFLAN_QALLOC_VALID_MASK)
903 num_queues = (j - base_queue) + 1;
904 else
905 num_queues = 0;
906
907 val = rd32(hw, I40E_PF_VT_PFALLOC);
908 i = (val & I40E_PF_VT_PFALLOC_FIRSTVF_MASK) >>
909 I40E_PF_VT_PFALLOC_FIRSTVF_SHIFT;
910 j = (val & I40E_PF_VT_PFALLOC_LASTVF_MASK) >>
911 I40E_PF_VT_PFALLOC_LASTVF_SHIFT;
912 if (val & I40E_PF_VT_PFALLOC_VALID_MASK)
913 num_vfs = (j - i) + 1;
914 else
915 num_vfs = 0;
916
917 /* stop all the interrupts */
918 wr32(hw, I40E_PFINT_ICR0_ENA, 0);
919 val = 0x3 << I40E_PFINT_DYN_CTLN_ITR_INDX_SHIFT;
920 for (i = 0; i < num_pf_int - 2; i++)
921 wr32(hw, I40E_PFINT_DYN_CTLN(i), val);
922
923 /* Set the FIRSTQ_INDX field to 0x7FF in PFINT_LNKLSTx */
924 val = eol << I40E_PFINT_LNKLST0_FIRSTQ_INDX_SHIFT;
925 wr32(hw, I40E_PFINT_LNKLST0, val);
926 for (i = 0; i < num_pf_int - 2; i++)
927 wr32(hw, I40E_PFINT_LNKLSTN(i), val);
928 val = eol << I40E_VPINT_LNKLST0_FIRSTQ_INDX_SHIFT;
929 for (i = 0; i < num_vfs; i++)
930 wr32(hw, I40E_VPINT_LNKLST0(i), val);
931 for (i = 0; i < num_vf_int - 2; i++)
932 wr32(hw, I40E_VPINT_LNKLSTN(i), val);
933
934 /* warn the HW of the coming Tx disables */
935 for (i = 0; i < num_queues; i++) {
936 u32 abs_queue_idx = base_queue + i;
937 u32 reg_block = 0;
938
939 if (abs_queue_idx >= 128) {
940 reg_block = abs_queue_idx / 128;
941 abs_queue_idx %= 128;
942 }
943
944 val = rd32(hw, I40E_GLLAN_TXPRE_QDIS(reg_block));
945 val &= ~I40E_GLLAN_TXPRE_QDIS_QINDX_MASK;
946 val |= (abs_queue_idx << I40E_GLLAN_TXPRE_QDIS_QINDX_SHIFT);
947 val |= I40E_GLLAN_TXPRE_QDIS_SET_QDIS_MASK;
948
949 wr32(hw, I40E_GLLAN_TXPRE_QDIS(reg_block), val);
950 }
951 udelay(400);
952
953 /* stop all the queues */
954 for (i = 0; i < num_queues; i++) {
955 wr32(hw, I40E_QINT_TQCTL(i), 0);
956 wr32(hw, I40E_QTX_ENA(i), 0);
957 wr32(hw, I40E_QINT_RQCTL(i), 0);
958 wr32(hw, I40E_QRX_ENA(i), 0);
959 }
960
961 /* short wait for all queue disables to settle */
962 udelay(50);
963}
964
965/**
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +0000966 * i40e_clear_pxe_mode - clear pxe operations mode
967 * @hw: pointer to the hw struct
968 *
969 * Make sure all PXE mode settings are cleared, including things
970 * like descriptor fetch/write-back mode.
971 **/
972void i40e_clear_pxe_mode(struct i40e_hw *hw)
973{
974 u32 reg;
975
Shannon Nelsonc9b9b0a2014-04-09 05:59:05 +0000976 if (i40e_check_asq_alive(hw))
977 i40e_aq_clear_pxe_mode(hw, NULL);
978
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +0000979 /* Clear single descriptor fetch/write-back mode */
980 reg = rd32(hw, I40E_GLLAN_RCTL_0);
Jesse Brandeburg7134f9c2013-11-26 08:56:05 +0000981
982 if (hw->revision_id == 0) {
983 /* As a work around clear PXE_MODE instead of setting it */
984 wr32(hw, I40E_GLLAN_RCTL_0, (reg & (~I40E_GLLAN_RCTL_0_PXE_MODE_MASK)));
985 } else {
986 wr32(hw, I40E_GLLAN_RCTL_0, (reg | I40E_GLLAN_RCTL_0_PXE_MODE_MASK));
987 }
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +0000988}
989
990/**
Jesse Brandeburg0556a9e2013-11-28 06:39:33 +0000991 * i40e_led_is_mine - helper to find matching led
992 * @hw: pointer to the hw struct
993 * @idx: index into GPIO registers
994 *
995 * returns: 0 if no match, otherwise the value of the GPIO_CTL register
996 */
997static u32 i40e_led_is_mine(struct i40e_hw *hw, int idx)
998{
999 u32 gpio_val = 0;
1000 u32 port;
1001
1002 if (!hw->func_caps.led[idx])
1003 return 0;
1004
1005 gpio_val = rd32(hw, I40E_GLGEN_GPIO_CTL(idx));
1006 port = (gpio_val & I40E_GLGEN_GPIO_CTL_PRT_NUM_MASK) >>
1007 I40E_GLGEN_GPIO_CTL_PRT_NUM_SHIFT;
1008
1009 /* if PRT_NUM_NA is 1 then this LED is not port specific, OR
1010 * if it is not our port then ignore
1011 */
1012 if ((gpio_val & I40E_GLGEN_GPIO_CTL_PRT_NUM_NA_MASK) ||
1013 (port != hw->port))
1014 return 0;
1015
1016 return gpio_val;
1017}
1018
1019#define I40E_LED0 22
1020#define I40E_LINK_ACTIVITY 0xC
1021
1022/**
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00001023 * i40e_led_get - return current on/off mode
1024 * @hw: pointer to the hw struct
1025 *
1026 * The value returned is the 'mode' field as defined in the
1027 * GPIO register definitions: 0x0 = off, 0xf = on, and other
1028 * values are variations of possible behaviors relating to
1029 * blink, link, and wire.
1030 **/
1031u32 i40e_led_get(struct i40e_hw *hw)
1032{
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00001033 u32 mode = 0;
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00001034 int i;
1035
Jesse Brandeburg0556a9e2013-11-28 06:39:33 +00001036 /* as per the documentation GPIO 22-29 are the LED
1037 * GPIO pins named LED0..LED7
1038 */
1039 for (i = I40E_LED0; i <= I40E_GLGEN_GPIO_CTL_MAX_INDEX; i++) {
1040 u32 gpio_val = i40e_led_is_mine(hw, i);
1041
1042 if (!gpio_val)
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00001043 continue;
1044
Jesse Brandeburg0556a9e2013-11-28 06:39:33 +00001045 mode = (gpio_val & I40E_GLGEN_GPIO_CTL_LED_MODE_MASK) >>
1046 I40E_GLGEN_GPIO_CTL_LED_MODE_SHIFT;
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00001047 break;
1048 }
1049
1050 return mode;
1051}
1052
1053/**
1054 * i40e_led_set - set new on/off mode
1055 * @hw: pointer to the hw struct
Jesse Brandeburg0556a9e2013-11-28 06:39:33 +00001056 * @mode: 0=off, 0xf=on (else see manual for mode details)
1057 * @blink: true if the LED should blink when on, false if steady
1058 *
1059 * if this function is used to turn on the blink it should
1060 * be used to disable the blink when restoring the original state.
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00001061 **/
Jesse Brandeburg0556a9e2013-11-28 06:39:33 +00001062void i40e_led_set(struct i40e_hw *hw, u32 mode, bool blink)
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00001063{
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00001064 int i;
1065
Jesse Brandeburg0556a9e2013-11-28 06:39:33 +00001066 if (mode & 0xfffffff0)
1067 hw_dbg(hw, "invalid mode passed in %X\n", mode);
1068
1069 /* as per the documentation GPIO 22-29 are the LED
1070 * GPIO pins named LED0..LED7
1071 */
1072 for (i = I40E_LED0; i <= I40E_GLGEN_GPIO_CTL_MAX_INDEX; i++) {
1073 u32 gpio_val = i40e_led_is_mine(hw, i);
1074
1075 if (!gpio_val)
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00001076 continue;
1077
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00001078 gpio_val &= ~I40E_GLGEN_GPIO_CTL_LED_MODE_MASK;
Jesse Brandeburg0556a9e2013-11-28 06:39:33 +00001079 /* this & is a bit of paranoia, but serves as a range check */
1080 gpio_val |= ((mode << I40E_GLGEN_GPIO_CTL_LED_MODE_SHIFT) &
1081 I40E_GLGEN_GPIO_CTL_LED_MODE_MASK);
1082
1083 if (mode == I40E_LINK_ACTIVITY)
1084 blink = false;
1085
1086 gpio_val |= (blink ? 1 : 0) <<
1087 I40E_GLGEN_GPIO_CTL_LED_BLINK_SHIFT;
1088
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00001089 wr32(hw, I40E_GLGEN_GPIO_CTL(i), gpio_val);
Jesse Brandeburg0556a9e2013-11-28 06:39:33 +00001090 break;
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00001091 }
1092}
1093
1094/* Admin command wrappers */
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00001095
1096/**
Catherine Sullivan8109e122014-06-04 08:45:24 +00001097 * i40e_aq_get_phy_capabilities
1098 * @hw: pointer to the hw struct
1099 * @abilities: structure for PHY capabilities to be filled
1100 * @qualified_modules: report Qualified Modules
1101 * @report_init: report init capabilities (active are default)
1102 * @cmd_details: pointer to command details structure or NULL
1103 *
1104 * Returns the various PHY abilities supported on the Port.
1105 **/
1106i40e_status i40e_aq_get_phy_capabilities(struct i40e_hw *hw,
1107 bool qualified_modules, bool report_init,
1108 struct i40e_aq_get_phy_abilities_resp *abilities,
1109 struct i40e_asq_cmd_details *cmd_details)
1110{
1111 struct i40e_aq_desc desc;
1112 i40e_status status;
1113 u16 abilities_size = sizeof(struct i40e_aq_get_phy_abilities_resp);
1114
1115 if (!abilities)
1116 return I40E_ERR_PARAM;
1117
1118 i40e_fill_default_direct_cmd_desc(&desc,
1119 i40e_aqc_opc_get_phy_abilities);
1120
1121 desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_BUF);
1122 if (abilities_size > I40E_AQ_LARGE_BUF)
1123 desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_LB);
1124
1125 if (qualified_modules)
1126 desc.params.external.param0 |=
1127 cpu_to_le32(I40E_AQ_PHY_REPORT_QUALIFIED_MODULES);
1128
1129 if (report_init)
1130 desc.params.external.param0 |=
1131 cpu_to_le32(I40E_AQ_PHY_REPORT_INITIAL_VALUES);
1132
1133 status = i40e_asq_send_command(hw, &desc, abilities, abilities_size,
1134 cmd_details);
1135
1136 if (hw->aq.asq_last_status == I40E_AQ_RC_EIO)
1137 status = I40E_ERR_UNKNOWN_PHY;
1138
1139 return status;
1140}
1141
1142/**
Catherine Sullivanc56999f2014-06-04 08:45:26 +00001143 * i40e_aq_set_phy_config
1144 * @hw: pointer to the hw struct
1145 * @config: structure with PHY configuration to be set
1146 * @cmd_details: pointer to command details structure or NULL
1147 *
1148 * Set the various PHY configuration parameters
1149 * supported on the Port.One or more of the Set PHY config parameters may be
1150 * ignored in an MFP mode as the PF may not have the privilege to set some
1151 * of the PHY Config parameters. This status will be indicated by the
1152 * command response.
1153 **/
1154enum i40e_status_code i40e_aq_set_phy_config(struct i40e_hw *hw,
1155 struct i40e_aq_set_phy_config *config,
1156 struct i40e_asq_cmd_details *cmd_details)
1157{
1158 struct i40e_aq_desc desc;
1159 struct i40e_aq_set_phy_config *cmd =
1160 (struct i40e_aq_set_phy_config *)&desc.params.raw;
1161 enum i40e_status_code status;
1162
1163 if (!config)
1164 return I40E_ERR_PARAM;
1165
1166 i40e_fill_default_direct_cmd_desc(&desc,
1167 i40e_aqc_opc_set_phy_config);
1168
1169 *cmd = *config;
1170
1171 status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
1172
1173 return status;
1174}
1175
1176/**
1177 * i40e_set_fc
1178 * @hw: pointer to the hw struct
1179 *
1180 * Set the requested flow control mode using set_phy_config.
1181 **/
1182enum i40e_status_code i40e_set_fc(struct i40e_hw *hw, u8 *aq_failures,
1183 bool atomic_restart)
1184{
1185 enum i40e_fc_mode fc_mode = hw->fc.requested_mode;
1186 struct i40e_aq_get_phy_abilities_resp abilities;
1187 struct i40e_aq_set_phy_config config;
1188 enum i40e_status_code status;
1189 u8 pause_mask = 0x0;
1190
1191 *aq_failures = 0x0;
1192
1193 switch (fc_mode) {
1194 case I40E_FC_FULL:
1195 pause_mask |= I40E_AQ_PHY_FLAG_PAUSE_TX;
1196 pause_mask |= I40E_AQ_PHY_FLAG_PAUSE_RX;
1197 break;
1198 case I40E_FC_RX_PAUSE:
1199 pause_mask |= I40E_AQ_PHY_FLAG_PAUSE_RX;
1200 break;
1201 case I40E_FC_TX_PAUSE:
1202 pause_mask |= I40E_AQ_PHY_FLAG_PAUSE_TX;
1203 break;
1204 default:
1205 break;
1206 }
1207
1208 /* Get the current phy config */
1209 status = i40e_aq_get_phy_capabilities(hw, false, false, &abilities,
1210 NULL);
1211 if (status) {
1212 *aq_failures |= I40E_SET_FC_AQ_FAIL_GET;
1213 return status;
1214 }
1215
1216 memset(&config, 0, sizeof(struct i40e_aq_set_phy_config));
1217 /* clear the old pause settings */
1218 config.abilities = abilities.abilities & ~(I40E_AQ_PHY_FLAG_PAUSE_TX) &
1219 ~(I40E_AQ_PHY_FLAG_PAUSE_RX);
1220 /* set the new abilities */
1221 config.abilities |= pause_mask;
1222 /* If the abilities have changed, then set the new config */
1223 if (config.abilities != abilities.abilities) {
1224 /* Auto restart link so settings take effect */
1225 if (atomic_restart)
1226 config.abilities |= I40E_AQ_PHY_ENABLE_ATOMIC_LINK;
1227 /* Copy over all the old settings */
1228 config.phy_type = abilities.phy_type;
1229 config.link_speed = abilities.link_speed;
1230 config.eee_capability = abilities.eee_capability;
1231 config.eeer = abilities.eeer_val;
1232 config.low_power_ctrl = abilities.d3_lpan;
1233 status = i40e_aq_set_phy_config(hw, &config, NULL);
1234
1235 if (status)
1236 *aq_failures |= I40E_SET_FC_AQ_FAIL_SET;
1237 }
1238 /* Update the link info */
1239 status = i40e_update_link_info(hw, true);
1240 if (status) {
1241 /* Wait a little bit (on 40G cards it sometimes takes a really
1242 * long time for link to come back from the atomic reset)
1243 * and try once more
1244 */
1245 msleep(1000);
1246 status = i40e_update_link_info(hw, true);
1247 }
1248 if (status)
1249 *aq_failures |= I40E_SET_FC_AQ_FAIL_UPDATE;
1250
1251 return status;
1252}
1253
1254/**
Shannon Nelsonc9b9b0a2014-04-09 05:59:05 +00001255 * i40e_aq_clear_pxe_mode
1256 * @hw: pointer to the hw struct
1257 * @cmd_details: pointer to command details structure or NULL
1258 *
1259 * Tell the firmware that the driver is taking over from PXE
1260 **/
1261i40e_status i40e_aq_clear_pxe_mode(struct i40e_hw *hw,
1262 struct i40e_asq_cmd_details *cmd_details)
1263{
1264 i40e_status status;
1265 struct i40e_aq_desc desc;
1266 struct i40e_aqc_clear_pxe *cmd =
1267 (struct i40e_aqc_clear_pxe *)&desc.params.raw;
1268
1269 i40e_fill_default_direct_cmd_desc(&desc,
1270 i40e_aqc_opc_clear_pxe_mode);
1271
1272 cmd->rx_cnt = 0x2;
1273
1274 status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
1275
1276 wr32(hw, I40E_GLLAN_RCTL_0, 0x1);
1277
1278 return status;
1279}
1280
1281/**
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00001282 * i40e_aq_set_link_restart_an
1283 * @hw: pointer to the hw struct
Catherine Sullivan1ac978a2014-06-04 01:23:20 +00001284 * @enable_link: if true: enable link, if false: disable link
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00001285 * @cmd_details: pointer to command details structure or NULL
1286 *
1287 * Sets up the link and restarts the Auto-Negotiation over the link.
1288 **/
1289i40e_status i40e_aq_set_link_restart_an(struct i40e_hw *hw,
Catherine Sullivan1ac978a2014-06-04 01:23:20 +00001290 bool enable_link,
1291 struct i40e_asq_cmd_details *cmd_details)
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00001292{
1293 struct i40e_aq_desc desc;
1294 struct i40e_aqc_set_link_restart_an *cmd =
1295 (struct i40e_aqc_set_link_restart_an *)&desc.params.raw;
1296 i40e_status status;
1297
1298 i40e_fill_default_direct_cmd_desc(&desc,
1299 i40e_aqc_opc_set_link_restart_an);
1300
1301 cmd->command = I40E_AQ_PHY_RESTART_AN;
Catherine Sullivan1ac978a2014-06-04 01:23:20 +00001302 if (enable_link)
1303 cmd->command |= I40E_AQ_PHY_LINK_ENABLE;
1304 else
1305 cmd->command &= ~I40E_AQ_PHY_LINK_ENABLE;
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00001306
1307 status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
1308
1309 return status;
1310}
1311
1312/**
1313 * i40e_aq_get_link_info
1314 * @hw: pointer to the hw struct
1315 * @enable_lse: enable/disable LinkStatusEvent reporting
1316 * @link: pointer to link status structure - optional
1317 * @cmd_details: pointer to command details structure or NULL
1318 *
1319 * Returns the link status of the adapter.
1320 **/
1321i40e_status i40e_aq_get_link_info(struct i40e_hw *hw,
1322 bool enable_lse, struct i40e_link_status *link,
1323 struct i40e_asq_cmd_details *cmd_details)
1324{
1325 struct i40e_aq_desc desc;
1326 struct i40e_aqc_get_link_status *resp =
1327 (struct i40e_aqc_get_link_status *)&desc.params.raw;
1328 struct i40e_link_status *hw_link_info = &hw->phy.link_info;
1329 i40e_status status;
Catherine Sullivanc56999f2014-06-04 08:45:26 +00001330 bool tx_pause, rx_pause;
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00001331 u16 command_flags;
1332
1333 i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_get_link_status);
1334
1335 if (enable_lse)
1336 command_flags = I40E_AQ_LSE_ENABLE;
1337 else
1338 command_flags = I40E_AQ_LSE_DISABLE;
1339 resp->command_flags = cpu_to_le16(command_flags);
1340
1341 status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
1342
1343 if (status)
1344 goto aq_get_link_info_exit;
1345
1346 /* save off old link status information */
Mitch Williamsc36bd4a72013-12-18 13:46:04 +00001347 hw->phy.link_info_old = *hw_link_info;
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00001348
1349 /* update link status */
1350 hw_link_info->phy_type = (enum i40e_aq_phy_type)resp->phy_type;
Jesse Brandeburgbe405eb2013-11-20 10:02:50 +00001351 hw->phy.media_type = i40e_get_media_type(hw);
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00001352 hw_link_info->link_speed = (enum i40e_aq_link_speed)resp->link_speed;
1353 hw_link_info->link_info = resp->link_info;
1354 hw_link_info->an_info = resp->an_info;
1355 hw_link_info->ext_info = resp->ext_info;
Kamil Krawczyk639dc372013-11-20 10:03:07 +00001356 hw_link_info->loopback = resp->loopback;
Neerav Parikh6bb3f232014-04-01 07:11:56 +00001357 hw_link_info->max_frame_size = le16_to_cpu(resp->max_frame_size);
1358 hw_link_info->pacing = resp->config & I40E_AQ_CONFIG_PACING_MASK;
1359
Catherine Sullivanc56999f2014-06-04 08:45:26 +00001360 /* update fc info */
1361 tx_pause = !!(resp->an_info & I40E_AQ_LINK_PAUSE_TX);
1362 rx_pause = !!(resp->an_info & I40E_AQ_LINK_PAUSE_RX);
1363 if (tx_pause & rx_pause)
1364 hw->fc.current_mode = I40E_FC_FULL;
1365 else if (tx_pause)
1366 hw->fc.current_mode = I40E_FC_TX_PAUSE;
1367 else if (rx_pause)
1368 hw->fc.current_mode = I40E_FC_RX_PAUSE;
1369 else
1370 hw->fc.current_mode = I40E_FC_NONE;
1371
Neerav Parikh6bb3f232014-04-01 07:11:56 +00001372 if (resp->config & I40E_AQ_CONFIG_CRC_ENA)
1373 hw_link_info->crc_enable = true;
1374 else
1375 hw_link_info->crc_enable = false;
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00001376
1377 if (resp->command_flags & cpu_to_le16(I40E_AQ_LSE_ENABLE))
1378 hw_link_info->lse_enable = true;
1379 else
1380 hw_link_info->lse_enable = false;
1381
1382 /* save link status information */
1383 if (link)
Jesse Brandeburgd7595a22013-09-13 08:23:22 +00001384 *link = *hw_link_info;
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00001385
1386 /* flag cleared so helper functions don't call AQ again */
1387 hw->phy.get_link_info = false;
1388
1389aq_get_link_info_exit:
1390 return status;
1391}
1392
1393/**
Catherine Sullivan8109e122014-06-04 08:45:24 +00001394 * i40e_update_link_info
1395 * @hw: pointer to the hw struct
1396 * @enable_lse: enable/disable LinkStatusEvent reporting
1397 *
1398 * Returns the link status of the adapter
1399 **/
1400i40e_status i40e_update_link_info(struct i40e_hw *hw, bool enable_lse)
1401{
1402 struct i40e_aq_get_phy_abilities_resp abilities;
1403 i40e_status status;
1404
1405 status = i40e_aq_get_link_info(hw, enable_lse, NULL, NULL);
1406 if (status)
1407 return status;
1408
1409 status = i40e_aq_get_phy_capabilities(hw, false, false,
1410 &abilities, NULL);
1411 if (status)
1412 return status;
1413
1414 if (abilities.abilities & I40E_AQ_PHY_AN_ENABLED)
1415 hw->phy.link_info.an_enabled = true;
1416 else
1417 hw->phy.link_info.an_enabled = false;
1418
1419 return status;
1420}
1421
1422/**
Jesse Brandeburg7e2453f2014-09-13 07:40:41 +00001423 * i40e_aq_set_phy_int_mask
1424 * @hw: pointer to the hw struct
1425 * @mask: interrupt mask to be set
1426 * @cmd_details: pointer to command details structure or NULL
1427 *
1428 * Set link interrupt mask.
1429 **/
1430i40e_status i40e_aq_set_phy_int_mask(struct i40e_hw *hw,
1431 u16 mask,
1432 struct i40e_asq_cmd_details *cmd_details)
1433{
1434 struct i40e_aq_desc desc;
1435 struct i40e_aqc_set_phy_int_mask *cmd =
1436 (struct i40e_aqc_set_phy_int_mask *)&desc.params.raw;
1437 i40e_status status;
1438
1439 i40e_fill_default_direct_cmd_desc(&desc,
1440 i40e_aqc_opc_set_phy_int_mask);
1441
1442 cmd->event_mask = cpu_to_le16(mask);
1443
1444 status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
1445
1446 return status;
1447}
1448
1449/**
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00001450 * i40e_aq_add_vsi
1451 * @hw: pointer to the hw struct
Jeff Kirsher98d44382013-12-21 05:44:42 +00001452 * @vsi_ctx: pointer to a vsi context struct
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00001453 * @cmd_details: pointer to command details structure or NULL
1454 *
1455 * Add a VSI context to the hardware.
1456**/
1457i40e_status i40e_aq_add_vsi(struct i40e_hw *hw,
1458 struct i40e_vsi_context *vsi_ctx,
1459 struct i40e_asq_cmd_details *cmd_details)
1460{
1461 struct i40e_aq_desc desc;
1462 struct i40e_aqc_add_get_update_vsi *cmd =
1463 (struct i40e_aqc_add_get_update_vsi *)&desc.params.raw;
1464 struct i40e_aqc_add_get_update_vsi_completion *resp =
1465 (struct i40e_aqc_add_get_update_vsi_completion *)
1466 &desc.params.raw;
1467 i40e_status status;
1468
1469 i40e_fill_default_direct_cmd_desc(&desc,
1470 i40e_aqc_opc_add_vsi);
1471
1472 cmd->uplink_seid = cpu_to_le16(vsi_ctx->uplink_seid);
1473 cmd->connection_type = vsi_ctx->connection_type;
1474 cmd->vf_id = vsi_ctx->vf_num;
1475 cmd->vsi_flags = cpu_to_le16(vsi_ctx->flags);
1476
1477 desc.flags |= cpu_to_le16((u16)(I40E_AQ_FLAG_BUF | I40E_AQ_FLAG_RD));
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00001478
1479 status = i40e_asq_send_command(hw, &desc, &vsi_ctx->info,
1480 sizeof(vsi_ctx->info), cmd_details);
1481
1482 if (status)
1483 goto aq_add_vsi_exit;
1484
1485 vsi_ctx->seid = le16_to_cpu(resp->seid);
1486 vsi_ctx->vsi_number = le16_to_cpu(resp->vsi_number);
1487 vsi_ctx->vsis_allocated = le16_to_cpu(resp->vsi_used);
1488 vsi_ctx->vsis_unallocated = le16_to_cpu(resp->vsi_free);
1489
1490aq_add_vsi_exit:
1491 return status;
1492}
1493
1494/**
1495 * i40e_aq_set_vsi_unicast_promiscuous
1496 * @hw: pointer to the hw struct
1497 * @seid: vsi number
1498 * @set: set unicast promiscuous enable/disable
1499 * @cmd_details: pointer to command details structure or NULL
1500 **/
1501i40e_status i40e_aq_set_vsi_unicast_promiscuous(struct i40e_hw *hw,
Mitch Williams885552a2013-12-21 05:44:41 +00001502 u16 seid, bool set,
1503 struct i40e_asq_cmd_details *cmd_details)
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00001504{
1505 struct i40e_aq_desc desc;
1506 struct i40e_aqc_set_vsi_promiscuous_modes *cmd =
1507 (struct i40e_aqc_set_vsi_promiscuous_modes *)&desc.params.raw;
1508 i40e_status status;
1509 u16 flags = 0;
1510
1511 i40e_fill_default_direct_cmd_desc(&desc,
1512 i40e_aqc_opc_set_vsi_promiscuous_modes);
1513
1514 if (set)
1515 flags |= I40E_AQC_SET_VSI_PROMISC_UNICAST;
1516
1517 cmd->promiscuous_flags = cpu_to_le16(flags);
1518
1519 cmd->valid_flags = cpu_to_le16(I40E_AQC_SET_VSI_PROMISC_UNICAST);
1520
1521 cmd->seid = cpu_to_le16(seid);
1522 status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
1523
1524 return status;
1525}
1526
1527/**
1528 * i40e_aq_set_vsi_multicast_promiscuous
1529 * @hw: pointer to the hw struct
1530 * @seid: vsi number
1531 * @set: set multicast promiscuous enable/disable
1532 * @cmd_details: pointer to command details structure or NULL
1533 **/
1534i40e_status i40e_aq_set_vsi_multicast_promiscuous(struct i40e_hw *hw,
1535 u16 seid, bool set, struct i40e_asq_cmd_details *cmd_details)
1536{
1537 struct i40e_aq_desc desc;
1538 struct i40e_aqc_set_vsi_promiscuous_modes *cmd =
1539 (struct i40e_aqc_set_vsi_promiscuous_modes *)&desc.params.raw;
1540 i40e_status status;
1541 u16 flags = 0;
1542
1543 i40e_fill_default_direct_cmd_desc(&desc,
1544 i40e_aqc_opc_set_vsi_promiscuous_modes);
1545
1546 if (set)
1547 flags |= I40E_AQC_SET_VSI_PROMISC_MULTICAST;
1548
1549 cmd->promiscuous_flags = cpu_to_le16(flags);
1550
1551 cmd->valid_flags = cpu_to_le16(I40E_AQC_SET_VSI_PROMISC_MULTICAST);
1552
1553 cmd->seid = cpu_to_le16(seid);
1554 status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
1555
1556 return status;
1557}
1558
1559/**
1560 * i40e_aq_set_vsi_broadcast
1561 * @hw: pointer to the hw struct
1562 * @seid: vsi number
1563 * @set_filter: true to set filter, false to clear filter
1564 * @cmd_details: pointer to command details structure or NULL
1565 *
1566 * Set or clear the broadcast promiscuous flag (filter) for a given VSI.
1567 **/
1568i40e_status i40e_aq_set_vsi_broadcast(struct i40e_hw *hw,
1569 u16 seid, bool set_filter,
1570 struct i40e_asq_cmd_details *cmd_details)
1571{
1572 struct i40e_aq_desc desc;
1573 struct i40e_aqc_set_vsi_promiscuous_modes *cmd =
1574 (struct i40e_aqc_set_vsi_promiscuous_modes *)&desc.params.raw;
1575 i40e_status status;
1576
1577 i40e_fill_default_direct_cmd_desc(&desc,
1578 i40e_aqc_opc_set_vsi_promiscuous_modes);
1579
1580 if (set_filter)
1581 cmd->promiscuous_flags
1582 |= cpu_to_le16(I40E_AQC_SET_VSI_PROMISC_BROADCAST);
1583 else
1584 cmd->promiscuous_flags
1585 &= cpu_to_le16(~I40E_AQC_SET_VSI_PROMISC_BROADCAST);
1586
1587 cmd->valid_flags = cpu_to_le16(I40E_AQC_SET_VSI_PROMISC_BROADCAST);
1588 cmd->seid = cpu_to_le16(seid);
1589 status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
1590
1591 return status;
1592}
1593
1594/**
1595 * i40e_get_vsi_params - get VSI configuration info
1596 * @hw: pointer to the hw struct
Jeff Kirsher98d44382013-12-21 05:44:42 +00001597 * @vsi_ctx: pointer to a vsi context struct
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00001598 * @cmd_details: pointer to command details structure or NULL
1599 **/
1600i40e_status i40e_aq_get_vsi_params(struct i40e_hw *hw,
1601 struct i40e_vsi_context *vsi_ctx,
1602 struct i40e_asq_cmd_details *cmd_details)
1603{
1604 struct i40e_aq_desc desc;
Shannon Nelsonf5ac8572013-11-28 06:39:43 +00001605 struct i40e_aqc_add_get_update_vsi *cmd =
1606 (struct i40e_aqc_add_get_update_vsi *)&desc.params.raw;
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00001607 struct i40e_aqc_add_get_update_vsi_completion *resp =
1608 (struct i40e_aqc_add_get_update_vsi_completion *)
1609 &desc.params.raw;
1610 i40e_status status;
1611
1612 i40e_fill_default_direct_cmd_desc(&desc,
1613 i40e_aqc_opc_get_vsi_parameters);
1614
Shannon Nelsonf5ac8572013-11-28 06:39:43 +00001615 cmd->uplink_seid = cpu_to_le16(vsi_ctx->seid);
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00001616
1617 desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_BUF);
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00001618
1619 status = i40e_asq_send_command(hw, &desc, &vsi_ctx->info,
1620 sizeof(vsi_ctx->info), NULL);
1621
1622 if (status)
1623 goto aq_get_vsi_params_exit;
1624
1625 vsi_ctx->seid = le16_to_cpu(resp->seid);
1626 vsi_ctx->vsi_number = le16_to_cpu(resp->vsi_number);
1627 vsi_ctx->vsis_allocated = le16_to_cpu(resp->vsi_used);
1628 vsi_ctx->vsis_unallocated = le16_to_cpu(resp->vsi_free);
1629
1630aq_get_vsi_params_exit:
1631 return status;
1632}
1633
1634/**
1635 * i40e_aq_update_vsi_params
1636 * @hw: pointer to the hw struct
Jeff Kirsher98d44382013-12-21 05:44:42 +00001637 * @vsi_ctx: pointer to a vsi context struct
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00001638 * @cmd_details: pointer to command details structure or NULL
1639 *
1640 * Update a VSI context.
1641 **/
1642i40e_status i40e_aq_update_vsi_params(struct i40e_hw *hw,
1643 struct i40e_vsi_context *vsi_ctx,
1644 struct i40e_asq_cmd_details *cmd_details)
1645{
1646 struct i40e_aq_desc desc;
Shannon Nelsonf5ac8572013-11-28 06:39:43 +00001647 struct i40e_aqc_add_get_update_vsi *cmd =
1648 (struct i40e_aqc_add_get_update_vsi *)&desc.params.raw;
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00001649 i40e_status status;
1650
1651 i40e_fill_default_direct_cmd_desc(&desc,
1652 i40e_aqc_opc_update_vsi_parameters);
Shannon Nelsonf5ac8572013-11-28 06:39:43 +00001653 cmd->uplink_seid = cpu_to_le16(vsi_ctx->seid);
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00001654
1655 desc.flags |= cpu_to_le16((u16)(I40E_AQ_FLAG_BUF | I40E_AQ_FLAG_RD));
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00001656
1657 status = i40e_asq_send_command(hw, &desc, &vsi_ctx->info,
1658 sizeof(vsi_ctx->info), cmd_details);
1659
1660 return status;
1661}
1662
1663/**
1664 * i40e_aq_get_switch_config
1665 * @hw: pointer to the hardware structure
1666 * @buf: pointer to the result buffer
1667 * @buf_size: length of input buffer
1668 * @start_seid: seid to start for the report, 0 == beginning
1669 * @cmd_details: pointer to command details structure or NULL
1670 *
1671 * Fill the buf with switch configuration returned from AdminQ command
1672 **/
1673i40e_status i40e_aq_get_switch_config(struct i40e_hw *hw,
1674 struct i40e_aqc_get_switch_config_resp *buf,
1675 u16 buf_size, u16 *start_seid,
1676 struct i40e_asq_cmd_details *cmd_details)
1677{
1678 struct i40e_aq_desc desc;
1679 struct i40e_aqc_switch_seid *scfg =
1680 (struct i40e_aqc_switch_seid *)&desc.params.raw;
1681 i40e_status status;
1682
1683 i40e_fill_default_direct_cmd_desc(&desc,
1684 i40e_aqc_opc_get_switch_config);
1685 desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_BUF);
1686 if (buf_size > I40E_AQ_LARGE_BUF)
1687 desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_LB);
1688 scfg->seid = cpu_to_le16(*start_seid);
1689
1690 status = i40e_asq_send_command(hw, &desc, buf, buf_size, cmd_details);
1691 *start_seid = le16_to_cpu(scfg->seid);
1692
1693 return status;
1694}
1695
1696/**
1697 * i40e_aq_get_firmware_version
1698 * @hw: pointer to the hw struct
1699 * @fw_major_version: firmware major version
1700 * @fw_minor_version: firmware minor version
1701 * @api_major_version: major queue version
1702 * @api_minor_version: minor queue version
1703 * @cmd_details: pointer to command details structure or NULL
1704 *
1705 * Get the firmware version from the admin queue commands
1706 **/
1707i40e_status i40e_aq_get_firmware_version(struct i40e_hw *hw,
1708 u16 *fw_major_version, u16 *fw_minor_version,
1709 u16 *api_major_version, u16 *api_minor_version,
1710 struct i40e_asq_cmd_details *cmd_details)
1711{
1712 struct i40e_aq_desc desc;
1713 struct i40e_aqc_get_version *resp =
1714 (struct i40e_aqc_get_version *)&desc.params.raw;
1715 i40e_status status;
1716
1717 i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_get_version);
1718
1719 status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
1720
1721 if (!status) {
1722 if (fw_major_version != NULL)
1723 *fw_major_version = le16_to_cpu(resp->fw_major);
1724 if (fw_minor_version != NULL)
1725 *fw_minor_version = le16_to_cpu(resp->fw_minor);
1726 if (api_major_version != NULL)
1727 *api_major_version = le16_to_cpu(resp->api_major);
1728 if (api_minor_version != NULL)
1729 *api_minor_version = le16_to_cpu(resp->api_minor);
1730 }
1731
1732 return status;
1733}
1734
1735/**
1736 * i40e_aq_send_driver_version
1737 * @hw: pointer to the hw struct
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00001738 * @dv: driver's major, minor version
1739 * @cmd_details: pointer to command details structure or NULL
1740 *
1741 * Send the driver version to the firmware
1742 **/
1743i40e_status i40e_aq_send_driver_version(struct i40e_hw *hw,
1744 struct i40e_driver_version *dv,
1745 struct i40e_asq_cmd_details *cmd_details)
1746{
1747 struct i40e_aq_desc desc;
1748 struct i40e_aqc_driver_version *cmd =
1749 (struct i40e_aqc_driver_version *)&desc.params.raw;
1750 i40e_status status;
Kevin Scott9d2f98e2014-04-01 07:11:52 +00001751 u16 len;
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00001752
1753 if (dv == NULL)
1754 return I40E_ERR_PARAM;
1755
1756 i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_driver_version);
1757
1758 desc.flags |= cpu_to_le16(I40E_AQ_FLAG_SI);
1759 cmd->driver_major_ver = dv->major_version;
1760 cmd->driver_minor_ver = dv->minor_version;
1761 cmd->driver_build_ver = dv->build_version;
1762 cmd->driver_subbuild_ver = dv->subbuild_version;
Shannon Nelsond2466012014-04-01 07:11:45 +00001763
1764 len = 0;
1765 while (len < sizeof(dv->driver_string) &&
1766 (dv->driver_string[len] < 0x80) &&
1767 dv->driver_string[len])
1768 len++;
1769 status = i40e_asq_send_command(hw, &desc, dv->driver_string,
1770 len, cmd_details);
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00001771
1772 return status;
1773}
1774
1775/**
1776 * i40e_get_link_status - get status of the HW network link
1777 * @hw: pointer to the hw struct
1778 *
1779 * Returns true if link is up, false if link is down.
1780 *
1781 * Side effect: LinkStatusEvent reporting becomes enabled
1782 **/
1783bool i40e_get_link_status(struct i40e_hw *hw)
1784{
1785 i40e_status status = 0;
1786 bool link_status = false;
1787
1788 if (hw->phy.get_link_info) {
1789 status = i40e_aq_get_link_info(hw, true, NULL, NULL);
1790
1791 if (status)
1792 goto i40e_get_link_status_exit;
1793 }
1794
1795 link_status = hw->phy.link_info.link_info & I40E_AQ_LINK_UP;
1796
1797i40e_get_link_status_exit:
1798 return link_status;
1799}
1800
1801/**
1802 * i40e_aq_add_veb - Insert a VEB between the VSI and the MAC
1803 * @hw: pointer to the hw struct
1804 * @uplink_seid: the MAC or other gizmo SEID
1805 * @downlink_seid: the VSI SEID
1806 * @enabled_tc: bitmap of TCs to be enabled
1807 * @default_port: true for default port VSI, false for control port
Kevin Scotte1c51b952013-11-20 10:02:51 +00001808 * @enable_l2_filtering: true to add L2 filter table rules to regular forwarding rules for cloud support
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00001809 * @veb_seid: pointer to where to put the resulting VEB SEID
1810 * @cmd_details: pointer to command details structure or NULL
1811 *
1812 * This asks the FW to add a VEB between the uplink and downlink
1813 * elements. If the uplink SEID is 0, this will be a floating VEB.
1814 **/
1815i40e_status i40e_aq_add_veb(struct i40e_hw *hw, u16 uplink_seid,
1816 u16 downlink_seid, u8 enabled_tc,
Kevin Scotte1c51b952013-11-20 10:02:51 +00001817 bool default_port, bool enable_l2_filtering,
1818 u16 *veb_seid,
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00001819 struct i40e_asq_cmd_details *cmd_details)
1820{
1821 struct i40e_aq_desc desc;
1822 struct i40e_aqc_add_veb *cmd =
1823 (struct i40e_aqc_add_veb *)&desc.params.raw;
1824 struct i40e_aqc_add_veb_completion *resp =
1825 (struct i40e_aqc_add_veb_completion *)&desc.params.raw;
1826 i40e_status status;
1827 u16 veb_flags = 0;
1828
1829 /* SEIDs need to either both be set or both be 0 for floating VEB */
1830 if (!!uplink_seid != !!downlink_seid)
1831 return I40E_ERR_PARAM;
1832
1833 i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_add_veb);
1834
1835 cmd->uplink_seid = cpu_to_le16(uplink_seid);
1836 cmd->downlink_seid = cpu_to_le16(downlink_seid);
1837 cmd->enable_tcs = enabled_tc;
1838 if (!uplink_seid)
1839 veb_flags |= I40E_AQC_ADD_VEB_FLOATING;
1840 if (default_port)
1841 veb_flags |= I40E_AQC_ADD_VEB_PORT_TYPE_DEFAULT;
1842 else
1843 veb_flags |= I40E_AQC_ADD_VEB_PORT_TYPE_DATA;
Kevin Scotte1c51b952013-11-20 10:02:51 +00001844
1845 if (enable_l2_filtering)
1846 veb_flags |= I40E_AQC_ADD_VEB_ENABLE_L2_FILTER;
1847
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00001848 cmd->veb_flags = cpu_to_le16(veb_flags);
1849
1850 status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
1851
1852 if (!status && veb_seid)
1853 *veb_seid = le16_to_cpu(resp->veb_seid);
1854
1855 return status;
1856}
1857
1858/**
1859 * i40e_aq_get_veb_parameters - Retrieve VEB parameters
1860 * @hw: pointer to the hw struct
1861 * @veb_seid: the SEID of the VEB to query
1862 * @switch_id: the uplink switch id
Jeff Kirsher98d44382013-12-21 05:44:42 +00001863 * @floating: set to true if the VEB is floating
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00001864 * @statistic_index: index of the stats counter block for this VEB
1865 * @vebs_used: number of VEB's used by function
Jeff Kirsher98d44382013-12-21 05:44:42 +00001866 * @vebs_free: total VEB's not reserved by any function
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00001867 * @cmd_details: pointer to command details structure or NULL
1868 *
1869 * This retrieves the parameters for a particular VEB, specified by
1870 * uplink_seid, and returns them to the caller.
1871 **/
1872i40e_status i40e_aq_get_veb_parameters(struct i40e_hw *hw,
1873 u16 veb_seid, u16 *switch_id,
1874 bool *floating, u16 *statistic_index,
1875 u16 *vebs_used, u16 *vebs_free,
1876 struct i40e_asq_cmd_details *cmd_details)
1877{
1878 struct i40e_aq_desc desc;
1879 struct i40e_aqc_get_veb_parameters_completion *cmd_resp =
1880 (struct i40e_aqc_get_veb_parameters_completion *)
1881 &desc.params.raw;
1882 i40e_status status;
1883
1884 if (veb_seid == 0)
1885 return I40E_ERR_PARAM;
1886
1887 i40e_fill_default_direct_cmd_desc(&desc,
1888 i40e_aqc_opc_get_veb_parameters);
1889 cmd_resp->seid = cpu_to_le16(veb_seid);
1890
1891 status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
1892 if (status)
1893 goto get_veb_exit;
1894
1895 if (switch_id)
1896 *switch_id = le16_to_cpu(cmd_resp->switch_id);
1897 if (statistic_index)
1898 *statistic_index = le16_to_cpu(cmd_resp->statistic_index);
1899 if (vebs_used)
1900 *vebs_used = le16_to_cpu(cmd_resp->vebs_used);
1901 if (vebs_free)
1902 *vebs_free = le16_to_cpu(cmd_resp->vebs_free);
1903 if (floating) {
1904 u16 flags = le16_to_cpu(cmd_resp->veb_flags);
1905 if (flags & I40E_AQC_ADD_VEB_FLOATING)
1906 *floating = true;
1907 else
1908 *floating = false;
1909 }
1910
1911get_veb_exit:
1912 return status;
1913}
1914
1915/**
1916 * i40e_aq_add_macvlan
1917 * @hw: pointer to the hw struct
1918 * @seid: VSI for the mac address
1919 * @mv_list: list of macvlans to be added
1920 * @count: length of the list
1921 * @cmd_details: pointer to command details structure or NULL
1922 *
1923 * Add MAC/VLAN addresses to the HW filtering
1924 **/
1925i40e_status i40e_aq_add_macvlan(struct i40e_hw *hw, u16 seid,
1926 struct i40e_aqc_add_macvlan_element_data *mv_list,
1927 u16 count, struct i40e_asq_cmd_details *cmd_details)
1928{
1929 struct i40e_aq_desc desc;
1930 struct i40e_aqc_macvlan *cmd =
1931 (struct i40e_aqc_macvlan *)&desc.params.raw;
1932 i40e_status status;
1933 u16 buf_size;
1934
1935 if (count == 0 || !mv_list || !hw)
1936 return I40E_ERR_PARAM;
1937
1938 buf_size = count * sizeof(struct i40e_aqc_add_macvlan_element_data);
1939
1940 /* prep the rest of the request */
1941 i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_add_macvlan);
1942 cmd->num_addresses = cpu_to_le16(count);
1943 cmd->seid[0] = cpu_to_le16(I40E_AQC_MACVLAN_CMD_SEID_VALID | seid);
1944 cmd->seid[1] = 0;
1945 cmd->seid[2] = 0;
1946
1947 desc.flags |= cpu_to_le16((u16)(I40E_AQ_FLAG_BUF | I40E_AQ_FLAG_RD));
1948 if (buf_size > I40E_AQ_LARGE_BUF)
1949 desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_LB);
1950
1951 status = i40e_asq_send_command(hw, &desc, mv_list, buf_size,
1952 cmd_details);
1953
1954 return status;
1955}
1956
1957/**
1958 * i40e_aq_remove_macvlan
1959 * @hw: pointer to the hw struct
1960 * @seid: VSI for the mac address
1961 * @mv_list: list of macvlans to be removed
1962 * @count: length of the list
1963 * @cmd_details: pointer to command details structure or NULL
1964 *
1965 * Remove MAC/VLAN addresses from the HW filtering
1966 **/
1967i40e_status i40e_aq_remove_macvlan(struct i40e_hw *hw, u16 seid,
1968 struct i40e_aqc_remove_macvlan_element_data *mv_list,
1969 u16 count, struct i40e_asq_cmd_details *cmd_details)
1970{
1971 struct i40e_aq_desc desc;
1972 struct i40e_aqc_macvlan *cmd =
1973 (struct i40e_aqc_macvlan *)&desc.params.raw;
1974 i40e_status status;
1975 u16 buf_size;
1976
1977 if (count == 0 || !mv_list || !hw)
1978 return I40E_ERR_PARAM;
1979
1980 buf_size = count * sizeof(struct i40e_aqc_remove_macvlan_element_data);
1981
1982 /* prep the rest of the request */
1983 i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_remove_macvlan);
1984 cmd->num_addresses = cpu_to_le16(count);
1985 cmd->seid[0] = cpu_to_le16(I40E_AQC_MACVLAN_CMD_SEID_VALID | seid);
1986 cmd->seid[1] = 0;
1987 cmd->seid[2] = 0;
1988
1989 desc.flags |= cpu_to_le16((u16)(I40E_AQ_FLAG_BUF | I40E_AQ_FLAG_RD));
1990 if (buf_size > I40E_AQ_LARGE_BUF)
1991 desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_LB);
1992
1993 status = i40e_asq_send_command(hw, &desc, mv_list, buf_size,
1994 cmd_details);
1995
1996 return status;
1997}
1998
1999/**
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00002000 * i40e_aq_send_msg_to_vf
2001 * @hw: pointer to the hardware structure
2002 * @vfid: vf id to send msg
Jeff Kirsher98d44382013-12-21 05:44:42 +00002003 * @v_opcode: opcodes for VF-PF communication
2004 * @v_retval: return error code
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00002005 * @msg: pointer to the msg buffer
2006 * @msglen: msg length
2007 * @cmd_details: pointer to command details
2008 *
2009 * send msg to vf
2010 **/
2011i40e_status i40e_aq_send_msg_to_vf(struct i40e_hw *hw, u16 vfid,
2012 u32 v_opcode, u32 v_retval, u8 *msg, u16 msglen,
2013 struct i40e_asq_cmd_details *cmd_details)
2014{
2015 struct i40e_aq_desc desc;
2016 struct i40e_aqc_pf_vf_message *cmd =
2017 (struct i40e_aqc_pf_vf_message *)&desc.params.raw;
2018 i40e_status status;
2019
2020 i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_send_msg_to_vf);
2021 cmd->id = cpu_to_le32(vfid);
2022 desc.cookie_high = cpu_to_le32(v_opcode);
2023 desc.cookie_low = cpu_to_le32(v_retval);
2024 desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_SI);
2025 if (msglen) {
2026 desc.flags |= cpu_to_le16((u16)(I40E_AQ_FLAG_BUF |
2027 I40E_AQ_FLAG_RD));
2028 if (msglen > I40E_AQ_LARGE_BUF)
2029 desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_LB);
2030 desc.datalen = cpu_to_le16(msglen);
2031 }
2032 status = i40e_asq_send_command(hw, &desc, msg, msglen, cmd_details);
2033
2034 return status;
2035}
2036
2037/**
Shannon Nelson9fee9db2014-12-11 07:06:30 +00002038 * i40e_aq_debug_read_register
2039 * @hw: pointer to the hw struct
2040 * @reg_addr: register address
2041 * @reg_val: register value
2042 * @cmd_details: pointer to command details structure or NULL
2043 *
2044 * Read the register using the admin queue commands
2045 **/
2046i40e_status i40e_aq_debug_read_register(struct i40e_hw *hw,
2047 u32 reg_addr, u64 *reg_val,
2048 struct i40e_asq_cmd_details *cmd_details)
2049{
2050 struct i40e_aq_desc desc;
2051 struct i40e_aqc_debug_reg_read_write *cmd_resp =
2052 (struct i40e_aqc_debug_reg_read_write *)&desc.params.raw;
2053 i40e_status status;
2054
2055 if (reg_val == NULL)
2056 return I40E_ERR_PARAM;
2057
2058 i40e_fill_default_direct_cmd_desc(&desc,
2059 i40e_aqc_opc_debug_read_reg);
2060
2061 cmd_resp->address = cpu_to_le32(reg_addr);
2062
2063 status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
2064
2065 if (!status) {
2066 *reg_val = ((u64)cmd_resp->value_high << 32) |
2067 (u64)cmd_resp->value_low;
2068 *reg_val = le64_to_cpu(*reg_val);
2069 }
2070
2071 return status;
2072}
2073
2074/**
Shannon Nelson53db45c2014-08-01 13:27:05 -07002075 * i40e_aq_debug_write_register
2076 * @hw: pointer to the hw struct
2077 * @reg_addr: register address
2078 * @reg_val: register value
2079 * @cmd_details: pointer to command details structure or NULL
2080 *
2081 * Write to a register using the admin queue commands
2082 **/
2083i40e_status i40e_aq_debug_write_register(struct i40e_hw *hw,
2084 u32 reg_addr, u64 reg_val,
2085 struct i40e_asq_cmd_details *cmd_details)
2086{
2087 struct i40e_aq_desc desc;
2088 struct i40e_aqc_debug_reg_read_write *cmd =
2089 (struct i40e_aqc_debug_reg_read_write *)&desc.params.raw;
2090 i40e_status status;
2091
2092 i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_debug_write_reg);
2093
2094 cmd->address = cpu_to_le32(reg_addr);
2095 cmd->value_high = cpu_to_le32((u32)(reg_val >> 32));
2096 cmd->value_low = cpu_to_le32((u32)(reg_val & 0xFFFFFFFF));
2097
2098 status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
2099
2100 return status;
2101}
2102
2103/**
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00002104 * i40e_aq_set_hmc_resource_profile
2105 * @hw: pointer to the hw struct
2106 * @profile: type of profile the HMC is to be set as
2107 * @pe_vf_enabled_count: the number of PE enabled VFs the system has
2108 * @cmd_details: pointer to command details structure or NULL
2109 *
2110 * set the HMC profile of the device.
2111 **/
2112i40e_status i40e_aq_set_hmc_resource_profile(struct i40e_hw *hw,
2113 enum i40e_aq_hmc_profile profile,
2114 u8 pe_vf_enabled_count,
2115 struct i40e_asq_cmd_details *cmd_details)
2116{
2117 struct i40e_aq_desc desc;
2118 struct i40e_aq_get_set_hmc_resource_profile *cmd =
2119 (struct i40e_aq_get_set_hmc_resource_profile *)&desc.params.raw;
2120 i40e_status status;
2121
2122 i40e_fill_default_direct_cmd_desc(&desc,
2123 i40e_aqc_opc_set_hmc_resource_profile);
2124
2125 cmd->pm_profile = (u8)profile;
2126 cmd->pe_vf_enabled = pe_vf_enabled_count;
2127
2128 status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
2129
2130 return status;
2131}
2132
2133/**
2134 * i40e_aq_request_resource
2135 * @hw: pointer to the hw struct
2136 * @resource: resource id
2137 * @access: access type
2138 * @sdp_number: resource number
2139 * @timeout: the maximum time in ms that the driver may hold the resource
2140 * @cmd_details: pointer to command details structure or NULL
2141 *
2142 * requests common resource using the admin queue commands
2143 **/
2144i40e_status i40e_aq_request_resource(struct i40e_hw *hw,
2145 enum i40e_aq_resources_ids resource,
2146 enum i40e_aq_resource_access_type access,
2147 u8 sdp_number, u64 *timeout,
2148 struct i40e_asq_cmd_details *cmd_details)
2149{
2150 struct i40e_aq_desc desc;
2151 struct i40e_aqc_request_resource *cmd_resp =
2152 (struct i40e_aqc_request_resource *)&desc.params.raw;
2153 i40e_status status;
2154
2155 i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_request_resource);
2156
2157 cmd_resp->resource_id = cpu_to_le16(resource);
2158 cmd_resp->access_type = cpu_to_le16(access);
2159 cmd_resp->resource_number = cpu_to_le32(sdp_number);
2160
2161 status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
2162 /* The completion specifies the maximum time in ms that the driver
2163 * may hold the resource in the Timeout field.
2164 * If the resource is held by someone else, the command completes with
2165 * busy return value and the timeout field indicates the maximum time
2166 * the current owner of the resource has to free it.
2167 */
2168 if (!status || hw->aq.asq_last_status == I40E_AQ_RC_EBUSY)
2169 *timeout = le32_to_cpu(cmd_resp->timeout);
2170
2171 return status;
2172}
2173
2174/**
2175 * i40e_aq_release_resource
2176 * @hw: pointer to the hw struct
2177 * @resource: resource id
2178 * @sdp_number: resource number
2179 * @cmd_details: pointer to command details structure or NULL
2180 *
2181 * release common resource using the admin queue commands
2182 **/
2183i40e_status i40e_aq_release_resource(struct i40e_hw *hw,
2184 enum i40e_aq_resources_ids resource,
2185 u8 sdp_number,
2186 struct i40e_asq_cmd_details *cmd_details)
2187{
2188 struct i40e_aq_desc desc;
2189 struct i40e_aqc_request_resource *cmd =
2190 (struct i40e_aqc_request_resource *)&desc.params.raw;
2191 i40e_status status;
2192
2193 i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_release_resource);
2194
2195 cmd->resource_id = cpu_to_le16(resource);
2196 cmd->resource_number = cpu_to_le32(sdp_number);
2197
2198 status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
2199
2200 return status;
2201}
2202
2203/**
2204 * i40e_aq_read_nvm
2205 * @hw: pointer to the hw struct
2206 * @module_pointer: module pointer location in words from the NVM beginning
2207 * @offset: byte offset from the module beginning
2208 * @length: length of the section to be read (in bytes from the offset)
2209 * @data: command buffer (size [bytes] = length)
2210 * @last_command: tells if this is the last command in a series
2211 * @cmd_details: pointer to command details structure or NULL
2212 *
2213 * Read the NVM using the admin queue commands
2214 **/
2215i40e_status i40e_aq_read_nvm(struct i40e_hw *hw, u8 module_pointer,
2216 u32 offset, u16 length, void *data,
2217 bool last_command,
2218 struct i40e_asq_cmd_details *cmd_details)
2219{
2220 struct i40e_aq_desc desc;
2221 struct i40e_aqc_nvm_update *cmd =
2222 (struct i40e_aqc_nvm_update *)&desc.params.raw;
2223 i40e_status status;
2224
2225 /* In offset the highest byte must be zeroed. */
2226 if (offset & 0xFF000000) {
2227 status = I40E_ERR_PARAM;
2228 goto i40e_aq_read_nvm_exit;
2229 }
2230
2231 i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_nvm_read);
2232
2233 /* If this is the last command in a series, set the proper flag. */
2234 if (last_command)
2235 cmd->command_flags |= I40E_AQ_NVM_LAST_CMD;
2236 cmd->module_pointer = module_pointer;
2237 cmd->offset = cpu_to_le32(offset);
2238 cmd->length = cpu_to_le16(length);
2239
2240 desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_BUF);
2241 if (length > I40E_AQ_LARGE_BUF)
2242 desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_LB);
2243
2244 status = i40e_asq_send_command(hw, &desc, data, length, cmd_details);
2245
2246i40e_aq_read_nvm_exit:
2247 return status;
2248}
2249
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00002250/**
2251 * i40e_aq_erase_nvm
2252 * @hw: pointer to the hw struct
2253 * @module_pointer: module pointer location in words from the NVM beginning
2254 * @offset: offset in the module (expressed in 4 KB from module's beginning)
2255 * @length: length of the section to be erased (expressed in 4 KB)
2256 * @last_command: tells if this is the last command in a series
2257 * @cmd_details: pointer to command details structure or NULL
2258 *
2259 * Erase the NVM sector using the admin queue commands
2260 **/
2261i40e_status i40e_aq_erase_nvm(struct i40e_hw *hw, u8 module_pointer,
2262 u32 offset, u16 length, bool last_command,
2263 struct i40e_asq_cmd_details *cmd_details)
2264{
2265 struct i40e_aq_desc desc;
2266 struct i40e_aqc_nvm_update *cmd =
2267 (struct i40e_aqc_nvm_update *)&desc.params.raw;
2268 i40e_status status;
2269
2270 /* In offset the highest byte must be zeroed. */
2271 if (offset & 0xFF000000) {
2272 status = I40E_ERR_PARAM;
2273 goto i40e_aq_erase_nvm_exit;
2274 }
2275
2276 i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_nvm_erase);
2277
2278 /* If this is the last command in a series, set the proper flag. */
2279 if (last_command)
2280 cmd->command_flags |= I40E_AQ_NVM_LAST_CMD;
2281 cmd->module_pointer = module_pointer;
2282 cmd->offset = cpu_to_le32(offset);
2283 cmd->length = cpu_to_le16(length);
2284
2285 status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
2286
2287i40e_aq_erase_nvm_exit:
2288 return status;
2289}
2290
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00002291#define I40E_DEV_FUNC_CAP_SWITCH_MODE 0x01
2292#define I40E_DEV_FUNC_CAP_MGMT_MODE 0x02
2293#define I40E_DEV_FUNC_CAP_NPAR 0x03
2294#define I40E_DEV_FUNC_CAP_OS2BMC 0x04
2295#define I40E_DEV_FUNC_CAP_VALID_FUNC 0x05
2296#define I40E_DEV_FUNC_CAP_SRIOV_1_1 0x12
2297#define I40E_DEV_FUNC_CAP_VF 0x13
2298#define I40E_DEV_FUNC_CAP_VMDQ 0x14
2299#define I40E_DEV_FUNC_CAP_802_1_QBG 0x15
2300#define I40E_DEV_FUNC_CAP_802_1_QBH 0x16
2301#define I40E_DEV_FUNC_CAP_VSI 0x17
2302#define I40E_DEV_FUNC_CAP_DCB 0x18
2303#define I40E_DEV_FUNC_CAP_FCOE 0x21
2304#define I40E_DEV_FUNC_CAP_RSS 0x40
2305#define I40E_DEV_FUNC_CAP_RX_QUEUES 0x41
2306#define I40E_DEV_FUNC_CAP_TX_QUEUES 0x42
2307#define I40E_DEV_FUNC_CAP_MSIX 0x43
2308#define I40E_DEV_FUNC_CAP_MSIX_VF 0x44
2309#define I40E_DEV_FUNC_CAP_FLOW_DIRECTOR 0x45
2310#define I40E_DEV_FUNC_CAP_IEEE_1588 0x46
2311#define I40E_DEV_FUNC_CAP_MFP_MODE_1 0xF1
2312#define I40E_DEV_FUNC_CAP_CEM 0xF2
2313#define I40E_DEV_FUNC_CAP_IWARP 0x51
2314#define I40E_DEV_FUNC_CAP_LED 0x61
2315#define I40E_DEV_FUNC_CAP_SDP 0x62
2316#define I40E_DEV_FUNC_CAP_MDIO 0x63
2317
2318/**
2319 * i40e_parse_discover_capabilities
2320 * @hw: pointer to the hw struct
2321 * @buff: pointer to a buffer containing device/function capability records
2322 * @cap_count: number of capability records in the list
2323 * @list_type_opc: type of capabilities list to parse
2324 *
2325 * Parse the device/function capabilities list.
2326 **/
2327static void i40e_parse_discover_capabilities(struct i40e_hw *hw, void *buff,
2328 u32 cap_count,
2329 enum i40e_admin_queue_opc list_type_opc)
2330{
2331 struct i40e_aqc_list_capabilities_element_resp *cap;
Shannon Nelson9fee9db2014-12-11 07:06:30 +00002332 u32 valid_functions, num_functions;
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00002333 u32 number, logical_id, phys_id;
2334 struct i40e_hw_capabilities *p;
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00002335 u32 i = 0;
2336 u16 id;
2337
2338 cap = (struct i40e_aqc_list_capabilities_element_resp *) buff;
2339
2340 if (list_type_opc == i40e_aqc_opc_list_dev_capabilities)
Joe Perchesb58f2f72014-03-25 04:30:32 +00002341 p = &hw->dev_caps;
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00002342 else if (list_type_opc == i40e_aqc_opc_list_func_capabilities)
Joe Perchesb58f2f72014-03-25 04:30:32 +00002343 p = &hw->func_caps;
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00002344 else
2345 return;
2346
2347 for (i = 0; i < cap_count; i++, cap++) {
2348 id = le16_to_cpu(cap->id);
2349 number = le32_to_cpu(cap->number);
2350 logical_id = le32_to_cpu(cap->logical_id);
2351 phys_id = le32_to_cpu(cap->phys_id);
2352
2353 switch (id) {
2354 case I40E_DEV_FUNC_CAP_SWITCH_MODE:
2355 p->switch_mode = number;
2356 break;
2357 case I40E_DEV_FUNC_CAP_MGMT_MODE:
2358 p->management_mode = number;
2359 break;
2360 case I40E_DEV_FUNC_CAP_NPAR:
2361 p->npar_enable = number;
2362 break;
2363 case I40E_DEV_FUNC_CAP_OS2BMC:
2364 p->os2bmc = number;
2365 break;
2366 case I40E_DEV_FUNC_CAP_VALID_FUNC:
2367 p->valid_functions = number;
2368 break;
2369 case I40E_DEV_FUNC_CAP_SRIOV_1_1:
2370 if (number == 1)
2371 p->sr_iov_1_1 = true;
2372 break;
2373 case I40E_DEV_FUNC_CAP_VF:
2374 p->num_vfs = number;
2375 p->vf_base_id = logical_id;
2376 break;
2377 case I40E_DEV_FUNC_CAP_VMDQ:
2378 if (number == 1)
2379 p->vmdq = true;
2380 break;
2381 case I40E_DEV_FUNC_CAP_802_1_QBG:
2382 if (number == 1)
2383 p->evb_802_1_qbg = true;
2384 break;
2385 case I40E_DEV_FUNC_CAP_802_1_QBH:
2386 if (number == 1)
2387 p->evb_802_1_qbh = true;
2388 break;
2389 case I40E_DEV_FUNC_CAP_VSI:
2390 p->num_vsis = number;
2391 break;
2392 case I40E_DEV_FUNC_CAP_DCB:
2393 if (number == 1) {
2394 p->dcb = true;
2395 p->enabled_tcmap = logical_id;
2396 p->maxtc = phys_id;
2397 }
2398 break;
2399 case I40E_DEV_FUNC_CAP_FCOE:
2400 if (number == 1)
2401 p->fcoe = true;
2402 break;
2403 case I40E_DEV_FUNC_CAP_RSS:
2404 p->rss = true;
Carolyn Wybornye157ea32014-06-03 23:50:22 +00002405 p->rss_table_size = number;
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00002406 p->rss_table_entry_width = logical_id;
2407 break;
2408 case I40E_DEV_FUNC_CAP_RX_QUEUES:
2409 p->num_rx_qp = number;
2410 p->base_queue = phys_id;
2411 break;
2412 case I40E_DEV_FUNC_CAP_TX_QUEUES:
2413 p->num_tx_qp = number;
2414 p->base_queue = phys_id;
2415 break;
2416 case I40E_DEV_FUNC_CAP_MSIX:
2417 p->num_msix_vectors = number;
2418 break;
2419 case I40E_DEV_FUNC_CAP_MSIX_VF:
2420 p->num_msix_vectors_vf = number;
2421 break;
2422 case I40E_DEV_FUNC_CAP_MFP_MODE_1:
2423 if (number == 1)
2424 p->mfp_mode_1 = true;
2425 break;
2426 case I40E_DEV_FUNC_CAP_CEM:
2427 if (number == 1)
2428 p->mgmt_cem = true;
2429 break;
2430 case I40E_DEV_FUNC_CAP_IWARP:
2431 if (number == 1)
2432 p->iwarp = true;
2433 break;
2434 case I40E_DEV_FUNC_CAP_LED:
2435 if (phys_id < I40E_HW_CAP_MAX_GPIO)
2436 p->led[phys_id] = true;
2437 break;
2438 case I40E_DEV_FUNC_CAP_SDP:
2439 if (phys_id < I40E_HW_CAP_MAX_GPIO)
2440 p->sdp[phys_id] = true;
2441 break;
2442 case I40E_DEV_FUNC_CAP_MDIO:
2443 if (number == 1) {
2444 p->mdio_port_num = phys_id;
2445 p->mdio_port_mode = logical_id;
2446 }
2447 break;
2448 case I40E_DEV_FUNC_CAP_IEEE_1588:
2449 if (number == 1)
2450 p->ieee_1588 = true;
2451 break;
2452 case I40E_DEV_FUNC_CAP_FLOW_DIRECTOR:
2453 p->fd = true;
2454 p->fd_filters_guaranteed = number;
2455 p->fd_filters_best_effort = logical_id;
2456 break;
2457 default:
2458 break;
2459 }
2460 }
2461
Vasu Dev566bb852014-04-09 05:59:06 +00002462 /* Software override ensuring FCoE is disabled if npar or mfp
2463 * mode because it is not supported in these modes.
2464 */
2465 if (p->npar_enable || p->mfp_mode_1)
2466 p->fcoe = false;
2467
Shannon Nelson9fee9db2014-12-11 07:06:30 +00002468 /* count the enabled ports (aka the "not disabled" ports) */
2469 hw->num_ports = 0;
2470 for (i = 0; i < 4; i++) {
2471 u32 port_cfg_reg = I40E_PRTGEN_CNF + (4 * i);
2472 u64 port_cfg = 0;
2473
2474 /* use AQ read to get the physical register offset instead
2475 * of the port relative offset
2476 */
2477 i40e_aq_debug_read_register(hw, port_cfg_reg, &port_cfg, NULL);
2478 if (!(port_cfg & I40E_PRTGEN_CNF_PORT_DIS_MASK))
2479 hw->num_ports++;
2480 }
2481
2482 valid_functions = p->valid_functions;
2483 num_functions = 0;
2484 while (valid_functions) {
2485 if (valid_functions & 1)
2486 num_functions++;
2487 valid_functions >>= 1;
2488 }
2489
2490 /* partition id is 1-based, and functions are evenly spread
2491 * across the ports as partitions
2492 */
2493 hw->partition_id = (hw->pf_id / hw->num_ports) + 1;
2494 hw->num_partitions = num_functions / hw->num_ports;
2495
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00002496 /* additional HW specific goodies that might
2497 * someday be HW version specific
2498 */
2499 p->rx_buf_chain_len = I40E_MAX_CHAINED_RX_BUFFERS;
2500}
2501
2502/**
2503 * i40e_aq_discover_capabilities
2504 * @hw: pointer to the hw struct
2505 * @buff: a virtual buffer to hold the capabilities
2506 * @buff_size: Size of the virtual buffer
2507 * @data_size: Size of the returned data, or buff size needed if AQ err==ENOMEM
2508 * @list_type_opc: capabilities type to discover - pass in the command opcode
2509 * @cmd_details: pointer to command details structure or NULL
2510 *
2511 * Get the device capabilities descriptions from the firmware
2512 **/
2513i40e_status i40e_aq_discover_capabilities(struct i40e_hw *hw,
2514 void *buff, u16 buff_size, u16 *data_size,
2515 enum i40e_admin_queue_opc list_type_opc,
2516 struct i40e_asq_cmd_details *cmd_details)
2517{
2518 struct i40e_aqc_list_capabilites *cmd;
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00002519 struct i40e_aq_desc desc;
Jesse Brandeburg8fb905b2014-01-17 15:36:33 -08002520 i40e_status status = 0;
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00002521
2522 cmd = (struct i40e_aqc_list_capabilites *)&desc.params.raw;
2523
2524 if (list_type_opc != i40e_aqc_opc_list_func_capabilities &&
2525 list_type_opc != i40e_aqc_opc_list_dev_capabilities) {
2526 status = I40E_ERR_PARAM;
2527 goto exit;
2528 }
2529
2530 i40e_fill_default_direct_cmd_desc(&desc, list_type_opc);
2531
2532 desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_BUF);
2533 if (buff_size > I40E_AQ_LARGE_BUF)
2534 desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_LB);
2535
2536 status = i40e_asq_send_command(hw, &desc, buff, buff_size, cmd_details);
2537 *data_size = le16_to_cpu(desc.datalen);
2538
2539 if (status)
2540 goto exit;
2541
2542 i40e_parse_discover_capabilities(hw, buff, le32_to_cpu(cmd->count),
2543 list_type_opc);
2544
2545exit:
2546 return status;
2547}
2548
2549/**
Shannon Nelsoncd552cb2014-07-09 07:46:09 +00002550 * i40e_aq_update_nvm
2551 * @hw: pointer to the hw struct
2552 * @module_pointer: module pointer location in words from the NVM beginning
2553 * @offset: byte offset from the module beginning
2554 * @length: length of the section to be written (in bytes from the offset)
2555 * @data: command buffer (size [bytes] = length)
2556 * @last_command: tells if this is the last command in a series
2557 * @cmd_details: pointer to command details structure or NULL
2558 *
2559 * Update the NVM using the admin queue commands
2560 **/
2561i40e_status i40e_aq_update_nvm(struct i40e_hw *hw, u8 module_pointer,
2562 u32 offset, u16 length, void *data,
2563 bool last_command,
2564 struct i40e_asq_cmd_details *cmd_details)
2565{
2566 struct i40e_aq_desc desc;
2567 struct i40e_aqc_nvm_update *cmd =
2568 (struct i40e_aqc_nvm_update *)&desc.params.raw;
2569 i40e_status status;
2570
2571 /* In offset the highest byte must be zeroed. */
2572 if (offset & 0xFF000000) {
2573 status = I40E_ERR_PARAM;
2574 goto i40e_aq_update_nvm_exit;
2575 }
2576
2577 i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_nvm_update);
2578
2579 /* If this is the last command in a series, set the proper flag. */
2580 if (last_command)
2581 cmd->command_flags |= I40E_AQ_NVM_LAST_CMD;
2582 cmd->module_pointer = module_pointer;
2583 cmd->offset = cpu_to_le32(offset);
2584 cmd->length = cpu_to_le16(length);
2585
2586 desc.flags |= cpu_to_le16((u16)(I40E_AQ_FLAG_BUF | I40E_AQ_FLAG_RD));
2587 if (length > I40E_AQ_LARGE_BUF)
2588 desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_LB);
2589
2590 status = i40e_asq_send_command(hw, &desc, data, length, cmd_details);
2591
2592i40e_aq_update_nvm_exit:
2593 return status;
2594}
2595
2596/**
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00002597 * i40e_aq_get_lldp_mib
2598 * @hw: pointer to the hw struct
2599 * @bridge_type: type of bridge requested
2600 * @mib_type: Local, Remote or both Local and Remote MIBs
2601 * @buff: pointer to a user supplied buffer to store the MIB block
2602 * @buff_size: size of the buffer (in bytes)
2603 * @local_len : length of the returned Local LLDP MIB
2604 * @remote_len: length of the returned Remote LLDP MIB
2605 * @cmd_details: pointer to command details structure or NULL
2606 *
2607 * Requests the complete LLDP MIB (entire packet).
2608 **/
2609i40e_status i40e_aq_get_lldp_mib(struct i40e_hw *hw, u8 bridge_type,
2610 u8 mib_type, void *buff, u16 buff_size,
2611 u16 *local_len, u16 *remote_len,
2612 struct i40e_asq_cmd_details *cmd_details)
2613{
2614 struct i40e_aq_desc desc;
2615 struct i40e_aqc_lldp_get_mib *cmd =
2616 (struct i40e_aqc_lldp_get_mib *)&desc.params.raw;
2617 struct i40e_aqc_lldp_get_mib *resp =
2618 (struct i40e_aqc_lldp_get_mib *)&desc.params.raw;
2619 i40e_status status;
2620
2621 if (buff_size == 0 || !buff)
2622 return I40E_ERR_PARAM;
2623
2624 i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_lldp_get_mib);
2625 /* Indirect Command */
2626 desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_BUF);
2627
2628 cmd->type = mib_type & I40E_AQ_LLDP_MIB_TYPE_MASK;
2629 cmd->type |= ((bridge_type << I40E_AQ_LLDP_BRIDGE_TYPE_SHIFT) &
2630 I40E_AQ_LLDP_BRIDGE_TYPE_MASK);
2631
2632 desc.datalen = cpu_to_le16(buff_size);
2633
2634 desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_BUF);
2635 if (buff_size > I40E_AQ_LARGE_BUF)
2636 desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_LB);
2637
2638 status = i40e_asq_send_command(hw, &desc, buff, buff_size, cmd_details);
2639 if (!status) {
2640 if (local_len != NULL)
2641 *local_len = le16_to_cpu(resp->local_len);
2642 if (remote_len != NULL)
2643 *remote_len = le16_to_cpu(resp->remote_len);
2644 }
2645
2646 return status;
2647}
2648
2649/**
2650 * i40e_aq_cfg_lldp_mib_change_event
2651 * @hw: pointer to the hw struct
2652 * @enable_update: Enable or Disable event posting
2653 * @cmd_details: pointer to command details structure or NULL
2654 *
2655 * Enable or Disable posting of an event on ARQ when LLDP MIB
2656 * associated with the interface changes
2657 **/
2658i40e_status i40e_aq_cfg_lldp_mib_change_event(struct i40e_hw *hw,
2659 bool enable_update,
2660 struct i40e_asq_cmd_details *cmd_details)
2661{
2662 struct i40e_aq_desc desc;
2663 struct i40e_aqc_lldp_update_mib *cmd =
2664 (struct i40e_aqc_lldp_update_mib *)&desc.params.raw;
2665 i40e_status status;
2666
2667 i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_lldp_update_mib);
2668
2669 if (!enable_update)
2670 cmd->command |= I40E_AQ_LLDP_MIB_UPDATE_DISABLE;
2671
2672 status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
2673
2674 return status;
2675}
2676
2677/**
2678 * i40e_aq_stop_lldp
2679 * @hw: pointer to the hw struct
2680 * @shutdown_agent: True if LLDP Agent needs to be Shutdown
2681 * @cmd_details: pointer to command details structure or NULL
2682 *
2683 * Stop or Shutdown the embedded LLDP Agent
2684 **/
2685i40e_status i40e_aq_stop_lldp(struct i40e_hw *hw, bool shutdown_agent,
2686 struct i40e_asq_cmd_details *cmd_details)
2687{
2688 struct i40e_aq_desc desc;
2689 struct i40e_aqc_lldp_stop *cmd =
2690 (struct i40e_aqc_lldp_stop *)&desc.params.raw;
2691 i40e_status status;
2692
2693 i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_lldp_stop);
2694
2695 if (shutdown_agent)
2696 cmd->command |= I40E_AQ_LLDP_AGENT_SHUTDOWN;
2697
2698 status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
2699
2700 return status;
2701}
2702
2703/**
2704 * i40e_aq_start_lldp
2705 * @hw: pointer to the hw struct
2706 * @cmd_details: pointer to command details structure or NULL
2707 *
2708 * Start the embedded LLDP Agent on all ports.
2709 **/
2710i40e_status i40e_aq_start_lldp(struct i40e_hw *hw,
2711 struct i40e_asq_cmd_details *cmd_details)
2712{
2713 struct i40e_aq_desc desc;
2714 struct i40e_aqc_lldp_start *cmd =
2715 (struct i40e_aqc_lldp_start *)&desc.params.raw;
2716 i40e_status status;
2717
2718 i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_lldp_start);
2719
2720 cmd->command = I40E_AQ_LLDP_AGENT_START;
2721
2722 status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
2723
2724 return status;
2725}
2726
2727/**
Neerav Parikh9fa61dd2014-11-12 00:18:25 +00002728 * i40e_aq_get_cee_dcb_config
2729 * @hw: pointer to the hw struct
2730 * @buff: response buffer that stores CEE operational configuration
2731 * @buff_size: size of the buffer passed
2732 * @cmd_details: pointer to command details structure or NULL
2733 *
2734 * Get CEE DCBX mode operational configuration from firmware
2735 **/
2736i40e_status i40e_aq_get_cee_dcb_config(struct i40e_hw *hw,
2737 void *buff, u16 buff_size,
2738 struct i40e_asq_cmd_details *cmd_details)
2739{
2740 struct i40e_aq_desc desc;
2741 i40e_status status;
2742
2743 if (buff_size == 0 || !buff)
2744 return I40E_ERR_PARAM;
2745
2746 i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_get_cee_dcb_cfg);
2747
2748 desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_BUF);
2749 status = i40e_asq_send_command(hw, &desc, (void *)buff, buff_size,
2750 cmd_details);
2751
2752 return status;
2753}
2754
2755/**
Jeff Kirshera1c9a9d2013-12-28 07:32:18 +00002756 * i40e_aq_add_udp_tunnel
2757 * @hw: pointer to the hw struct
2758 * @udp_port: the UDP port to add
2759 * @header_len: length of the tunneling header length in DWords
2760 * @protocol_index: protocol index type
Jeff Kirsher98d44382013-12-21 05:44:42 +00002761 * @filter_index: pointer to filter index
Jeff Kirshera1c9a9d2013-12-28 07:32:18 +00002762 * @cmd_details: pointer to command details structure or NULL
2763 **/
2764i40e_status i40e_aq_add_udp_tunnel(struct i40e_hw *hw,
Kevin Scottf4f94b92014-04-05 07:46:10 +00002765 u16 udp_port, u8 protocol_index,
2766 u8 *filter_index,
Jeff Kirshera1c9a9d2013-12-28 07:32:18 +00002767 struct i40e_asq_cmd_details *cmd_details)
2768{
2769 struct i40e_aq_desc desc;
2770 struct i40e_aqc_add_udp_tunnel *cmd =
2771 (struct i40e_aqc_add_udp_tunnel *)&desc.params.raw;
2772 struct i40e_aqc_del_udp_tunnel_completion *resp =
2773 (struct i40e_aqc_del_udp_tunnel_completion *)&desc.params.raw;
2774 i40e_status status;
2775
2776 i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_add_udp_tunnel);
2777
2778 cmd->udp_port = cpu_to_le16(udp_port);
Shannon Nelson981b7542013-12-11 08:17:11 +00002779 cmd->protocol_type = protocol_index;
Jeff Kirshera1c9a9d2013-12-28 07:32:18 +00002780
2781 status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
2782
2783 if (!status)
2784 *filter_index = resp->index;
2785
2786 return status;
2787}
2788
2789/**
2790 * i40e_aq_del_udp_tunnel
2791 * @hw: pointer to the hw struct
2792 * @index: filter index
2793 * @cmd_details: pointer to command details structure or NULL
2794 **/
2795i40e_status i40e_aq_del_udp_tunnel(struct i40e_hw *hw, u8 index,
2796 struct i40e_asq_cmd_details *cmd_details)
2797{
2798 struct i40e_aq_desc desc;
2799 struct i40e_aqc_remove_udp_tunnel *cmd =
2800 (struct i40e_aqc_remove_udp_tunnel *)&desc.params.raw;
2801 i40e_status status;
2802
2803 i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_del_udp_tunnel);
2804
2805 cmd->index = index;
2806
2807 status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
2808
2809 return status;
2810}
2811
2812/**
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00002813 * i40e_aq_delete_element - Delete switch element
2814 * @hw: pointer to the hw struct
2815 * @seid: the SEID to delete from the switch
2816 * @cmd_details: pointer to command details structure or NULL
2817 *
2818 * This deletes a switch element from the switch.
2819 **/
2820i40e_status i40e_aq_delete_element(struct i40e_hw *hw, u16 seid,
2821 struct i40e_asq_cmd_details *cmd_details)
2822{
2823 struct i40e_aq_desc desc;
2824 struct i40e_aqc_switch_seid *cmd =
2825 (struct i40e_aqc_switch_seid *)&desc.params.raw;
2826 i40e_status status;
2827
2828 if (seid == 0)
2829 return I40E_ERR_PARAM;
2830
2831 i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_delete_element);
2832
2833 cmd->seid = cpu_to_le16(seid);
2834
2835 status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
2836
2837 return status;
2838}
2839
2840/**
Neerav Parikhafb3ff02014-01-17 15:36:36 -08002841 * i40e_aq_dcb_updated - DCB Updated Command
2842 * @hw: pointer to the hw struct
2843 * @cmd_details: pointer to command details structure or NULL
2844 *
2845 * EMP will return when the shared RPB settings have been
2846 * recomputed and modified. The retval field in the descriptor
2847 * will be set to 0 when RPB is modified.
2848 **/
2849i40e_status i40e_aq_dcb_updated(struct i40e_hw *hw,
2850 struct i40e_asq_cmd_details *cmd_details)
2851{
2852 struct i40e_aq_desc desc;
2853 i40e_status status;
2854
2855 i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_dcb_updated);
2856
2857 status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
2858
2859 return status;
2860}
2861
2862/**
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00002863 * i40e_aq_tx_sched_cmd - generic Tx scheduler AQ command handler
2864 * @hw: pointer to the hw struct
2865 * @seid: seid for the physical port/switching component/vsi
2866 * @buff: Indirect buffer to hold data parameters and response
2867 * @buff_size: Indirect buffer size
2868 * @opcode: Tx scheduler AQ command opcode
2869 * @cmd_details: pointer to command details structure or NULL
2870 *
2871 * Generic command handler for Tx scheduler AQ commands
2872 **/
2873static i40e_status i40e_aq_tx_sched_cmd(struct i40e_hw *hw, u16 seid,
2874 void *buff, u16 buff_size,
2875 enum i40e_admin_queue_opc opcode,
2876 struct i40e_asq_cmd_details *cmd_details)
2877{
2878 struct i40e_aq_desc desc;
2879 struct i40e_aqc_tx_sched_ind *cmd =
2880 (struct i40e_aqc_tx_sched_ind *)&desc.params.raw;
2881 i40e_status status;
2882 bool cmd_param_flag = false;
2883
2884 switch (opcode) {
2885 case i40e_aqc_opc_configure_vsi_ets_sla_bw_limit:
2886 case i40e_aqc_opc_configure_vsi_tc_bw:
2887 case i40e_aqc_opc_enable_switching_comp_ets:
2888 case i40e_aqc_opc_modify_switching_comp_ets:
2889 case i40e_aqc_opc_disable_switching_comp_ets:
2890 case i40e_aqc_opc_configure_switching_comp_ets_bw_limit:
2891 case i40e_aqc_opc_configure_switching_comp_bw_config:
2892 cmd_param_flag = true;
2893 break;
2894 case i40e_aqc_opc_query_vsi_bw_config:
2895 case i40e_aqc_opc_query_vsi_ets_sla_config:
2896 case i40e_aqc_opc_query_switching_comp_ets_config:
2897 case i40e_aqc_opc_query_port_ets_config:
2898 case i40e_aqc_opc_query_switching_comp_bw_config:
2899 cmd_param_flag = false;
2900 break;
2901 default:
2902 return I40E_ERR_PARAM;
2903 }
2904
2905 i40e_fill_default_direct_cmd_desc(&desc, opcode);
2906
2907 /* Indirect command */
2908 desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_BUF);
2909 if (cmd_param_flag)
2910 desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_RD);
2911 if (buff_size > I40E_AQ_LARGE_BUF)
2912 desc.flags |= cpu_to_le16((u16)I40E_AQ_FLAG_LB);
2913
2914 desc.datalen = cpu_to_le16(buff_size);
2915
2916 cmd->vsi_seid = cpu_to_le16(seid);
2917
2918 status = i40e_asq_send_command(hw, &desc, buff, buff_size, cmd_details);
2919
2920 return status;
2921}
2922
2923/**
Mitch Williams6b192892014-03-06 09:02:29 +00002924 * i40e_aq_config_vsi_bw_limit - Configure VSI BW Limit
2925 * @hw: pointer to the hw struct
2926 * @seid: VSI seid
2927 * @credit: BW limit credits (0 = disabled)
2928 * @max_credit: Max BW limit credits
2929 * @cmd_details: pointer to command details structure or NULL
2930 **/
2931i40e_status i40e_aq_config_vsi_bw_limit(struct i40e_hw *hw,
2932 u16 seid, u16 credit, u8 max_credit,
2933 struct i40e_asq_cmd_details *cmd_details)
2934{
2935 struct i40e_aq_desc desc;
2936 struct i40e_aqc_configure_vsi_bw_limit *cmd =
2937 (struct i40e_aqc_configure_vsi_bw_limit *)&desc.params.raw;
2938 i40e_status status;
2939
2940 i40e_fill_default_direct_cmd_desc(&desc,
2941 i40e_aqc_opc_configure_vsi_bw_limit);
2942
2943 cmd->vsi_seid = cpu_to_le16(seid);
2944 cmd->credit = cpu_to_le16(credit);
2945 cmd->max_credit = max_credit;
2946
2947 status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
2948
2949 return status;
2950}
2951
2952/**
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00002953 * i40e_aq_config_vsi_tc_bw - Config VSI BW Allocation per TC
2954 * @hw: pointer to the hw struct
2955 * @seid: VSI seid
2956 * @bw_data: Buffer holding enabled TCs, relative TC BW limit/credits
2957 * @cmd_details: pointer to command details structure or NULL
2958 **/
2959i40e_status i40e_aq_config_vsi_tc_bw(struct i40e_hw *hw,
2960 u16 seid,
2961 struct i40e_aqc_configure_vsi_tc_bw_data *bw_data,
2962 struct i40e_asq_cmd_details *cmd_details)
2963{
2964 return i40e_aq_tx_sched_cmd(hw, seid, (void *)bw_data, sizeof(*bw_data),
2965 i40e_aqc_opc_configure_vsi_tc_bw,
2966 cmd_details);
2967}
2968
2969/**
Neerav Parikhafb3ff02014-01-17 15:36:36 -08002970 * i40e_aq_config_switch_comp_ets - Enable/Disable/Modify ETS on the port
2971 * @hw: pointer to the hw struct
2972 * @seid: seid of the switching component connected to Physical Port
2973 * @ets_data: Buffer holding ETS parameters
2974 * @cmd_details: pointer to command details structure or NULL
2975 **/
2976i40e_status i40e_aq_config_switch_comp_ets(struct i40e_hw *hw,
2977 u16 seid,
2978 struct i40e_aqc_configure_switching_comp_ets_data *ets_data,
2979 enum i40e_admin_queue_opc opcode,
2980 struct i40e_asq_cmd_details *cmd_details)
2981{
2982 return i40e_aq_tx_sched_cmd(hw, seid, (void *)ets_data,
2983 sizeof(*ets_data), opcode, cmd_details);
2984}
2985
2986/**
2987 * i40e_aq_config_switch_comp_bw_config - Config Switch comp BW Alloc per TC
2988 * @hw: pointer to the hw struct
2989 * @seid: seid of the switching component
2990 * @bw_data: Buffer holding enabled TCs, relative/absolute TC BW limit/credits
2991 * @cmd_details: pointer to command details structure or NULL
2992 **/
2993i40e_status i40e_aq_config_switch_comp_bw_config(struct i40e_hw *hw,
2994 u16 seid,
2995 struct i40e_aqc_configure_switching_comp_bw_config_data *bw_data,
2996 struct i40e_asq_cmd_details *cmd_details)
2997{
2998 return i40e_aq_tx_sched_cmd(hw, seid, (void *)bw_data, sizeof(*bw_data),
2999 i40e_aqc_opc_configure_switching_comp_bw_config,
3000 cmd_details);
3001}
3002
3003/**
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00003004 * i40e_aq_query_vsi_bw_config - Query VSI BW configuration
3005 * @hw: pointer to the hw struct
3006 * @seid: seid of the VSI
3007 * @bw_data: Buffer to hold VSI BW configuration
3008 * @cmd_details: pointer to command details structure or NULL
3009 **/
3010i40e_status i40e_aq_query_vsi_bw_config(struct i40e_hw *hw,
3011 u16 seid,
3012 struct i40e_aqc_query_vsi_bw_config_resp *bw_data,
3013 struct i40e_asq_cmd_details *cmd_details)
3014{
3015 return i40e_aq_tx_sched_cmd(hw, seid, (void *)bw_data, sizeof(*bw_data),
3016 i40e_aqc_opc_query_vsi_bw_config,
3017 cmd_details);
3018}
3019
3020/**
3021 * i40e_aq_query_vsi_ets_sla_config - Query VSI BW configuration per TC
3022 * @hw: pointer to the hw struct
3023 * @seid: seid of the VSI
3024 * @bw_data: Buffer to hold VSI BW configuration per TC
3025 * @cmd_details: pointer to command details structure or NULL
3026 **/
3027i40e_status i40e_aq_query_vsi_ets_sla_config(struct i40e_hw *hw,
3028 u16 seid,
3029 struct i40e_aqc_query_vsi_ets_sla_config_resp *bw_data,
3030 struct i40e_asq_cmd_details *cmd_details)
3031{
3032 return i40e_aq_tx_sched_cmd(hw, seid, (void *)bw_data, sizeof(*bw_data),
3033 i40e_aqc_opc_query_vsi_ets_sla_config,
3034 cmd_details);
3035}
3036
3037/**
3038 * i40e_aq_query_switch_comp_ets_config - Query Switch comp BW config per TC
3039 * @hw: pointer to the hw struct
3040 * @seid: seid of the switching component
3041 * @bw_data: Buffer to hold switching component's per TC BW config
3042 * @cmd_details: pointer to command details structure or NULL
3043 **/
3044i40e_status i40e_aq_query_switch_comp_ets_config(struct i40e_hw *hw,
3045 u16 seid,
3046 struct i40e_aqc_query_switching_comp_ets_config_resp *bw_data,
3047 struct i40e_asq_cmd_details *cmd_details)
3048{
3049 return i40e_aq_tx_sched_cmd(hw, seid, (void *)bw_data, sizeof(*bw_data),
3050 i40e_aqc_opc_query_switching_comp_ets_config,
3051 cmd_details);
3052}
3053
3054/**
3055 * i40e_aq_query_port_ets_config - Query Physical Port ETS configuration
3056 * @hw: pointer to the hw struct
3057 * @seid: seid of the VSI or switching component connected to Physical Port
3058 * @bw_data: Buffer to hold current ETS configuration for the Physical Port
3059 * @cmd_details: pointer to command details structure or NULL
3060 **/
3061i40e_status i40e_aq_query_port_ets_config(struct i40e_hw *hw,
3062 u16 seid,
3063 struct i40e_aqc_query_port_ets_config_resp *bw_data,
3064 struct i40e_asq_cmd_details *cmd_details)
3065{
3066 return i40e_aq_tx_sched_cmd(hw, seid, (void *)bw_data, sizeof(*bw_data),
3067 i40e_aqc_opc_query_port_ets_config,
3068 cmd_details);
3069}
3070
3071/**
3072 * i40e_aq_query_switch_comp_bw_config - Query Switch comp BW configuration
3073 * @hw: pointer to the hw struct
3074 * @seid: seid of the switching component
3075 * @bw_data: Buffer to hold switching component's BW configuration
3076 * @cmd_details: pointer to command details structure or NULL
3077 **/
3078i40e_status i40e_aq_query_switch_comp_bw_config(struct i40e_hw *hw,
3079 u16 seid,
3080 struct i40e_aqc_query_switching_comp_bw_config_resp *bw_data,
3081 struct i40e_asq_cmd_details *cmd_details)
3082{
3083 return i40e_aq_tx_sched_cmd(hw, seid, (void *)bw_data, sizeof(*bw_data),
3084 i40e_aqc_opc_query_switching_comp_bw_config,
3085 cmd_details);
3086}
3087
3088/**
3089 * i40e_validate_filter_settings
3090 * @hw: pointer to the hardware structure
3091 * @settings: Filter control settings
3092 *
3093 * Check and validate the filter control settings passed.
3094 * The function checks for the valid filter/context sizes being
3095 * passed for FCoE and PE.
3096 *
3097 * Returns 0 if the values passed are valid and within
3098 * range else returns an error.
3099 **/
3100static i40e_status i40e_validate_filter_settings(struct i40e_hw *hw,
3101 struct i40e_filter_control_settings *settings)
3102{
3103 u32 fcoe_cntx_size, fcoe_filt_size;
3104 u32 pe_cntx_size, pe_filt_size;
Anjali Singhai Jain467d7292014-05-10 04:49:02 +00003105 u32 fcoe_fmax;
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00003106 u32 val;
3107
3108 /* Validate FCoE settings passed */
3109 switch (settings->fcoe_filt_num) {
3110 case I40E_HASH_FILTER_SIZE_1K:
3111 case I40E_HASH_FILTER_SIZE_2K:
3112 case I40E_HASH_FILTER_SIZE_4K:
3113 case I40E_HASH_FILTER_SIZE_8K:
3114 case I40E_HASH_FILTER_SIZE_16K:
3115 case I40E_HASH_FILTER_SIZE_32K:
3116 fcoe_filt_size = I40E_HASH_FILTER_BASE_SIZE;
3117 fcoe_filt_size <<= (u32)settings->fcoe_filt_num;
3118 break;
3119 default:
3120 return I40E_ERR_PARAM;
3121 }
3122
3123 switch (settings->fcoe_cntx_num) {
3124 case I40E_DMA_CNTX_SIZE_512:
3125 case I40E_DMA_CNTX_SIZE_1K:
3126 case I40E_DMA_CNTX_SIZE_2K:
3127 case I40E_DMA_CNTX_SIZE_4K:
3128 fcoe_cntx_size = I40E_DMA_CNTX_BASE_SIZE;
3129 fcoe_cntx_size <<= (u32)settings->fcoe_cntx_num;
3130 break;
3131 default:
3132 return I40E_ERR_PARAM;
3133 }
3134
3135 /* Validate PE settings passed */
3136 switch (settings->pe_filt_num) {
3137 case I40E_HASH_FILTER_SIZE_1K:
3138 case I40E_HASH_FILTER_SIZE_2K:
3139 case I40E_HASH_FILTER_SIZE_4K:
3140 case I40E_HASH_FILTER_SIZE_8K:
3141 case I40E_HASH_FILTER_SIZE_16K:
3142 case I40E_HASH_FILTER_SIZE_32K:
3143 case I40E_HASH_FILTER_SIZE_64K:
3144 case I40E_HASH_FILTER_SIZE_128K:
3145 case I40E_HASH_FILTER_SIZE_256K:
3146 case I40E_HASH_FILTER_SIZE_512K:
3147 case I40E_HASH_FILTER_SIZE_1M:
3148 pe_filt_size = I40E_HASH_FILTER_BASE_SIZE;
3149 pe_filt_size <<= (u32)settings->pe_filt_num;
3150 break;
3151 default:
3152 return I40E_ERR_PARAM;
3153 }
3154
3155 switch (settings->pe_cntx_num) {
3156 case I40E_DMA_CNTX_SIZE_512:
3157 case I40E_DMA_CNTX_SIZE_1K:
3158 case I40E_DMA_CNTX_SIZE_2K:
3159 case I40E_DMA_CNTX_SIZE_4K:
3160 case I40E_DMA_CNTX_SIZE_8K:
3161 case I40E_DMA_CNTX_SIZE_16K:
3162 case I40E_DMA_CNTX_SIZE_32K:
3163 case I40E_DMA_CNTX_SIZE_64K:
3164 case I40E_DMA_CNTX_SIZE_128K:
3165 case I40E_DMA_CNTX_SIZE_256K:
3166 pe_cntx_size = I40E_DMA_CNTX_BASE_SIZE;
3167 pe_cntx_size <<= (u32)settings->pe_cntx_num;
3168 break;
3169 default:
3170 return I40E_ERR_PARAM;
3171 }
3172
3173 /* FCHSIZE + FCDSIZE should not be greater than PMFCOEFMAX */
3174 val = rd32(hw, I40E_GLHMC_FCOEFMAX);
3175 fcoe_fmax = (val & I40E_GLHMC_FCOEFMAX_PMFCOEFMAX_MASK)
3176 >> I40E_GLHMC_FCOEFMAX_PMFCOEFMAX_SHIFT;
3177 if (fcoe_filt_size + fcoe_cntx_size > fcoe_fmax)
3178 return I40E_ERR_INVALID_SIZE;
3179
Jesse Brandeburg56a62fc2013-09-11 08:40:12 +00003180 return 0;
3181}
3182
3183/**
3184 * i40e_set_filter_control
3185 * @hw: pointer to the hardware structure
3186 * @settings: Filter control settings
3187 *
3188 * Set the Queue Filters for PE/FCoE and enable filters required
3189 * for a single PF. It is expected that these settings are programmed
3190 * at the driver initialization time.
3191 **/
3192i40e_status i40e_set_filter_control(struct i40e_hw *hw,
3193 struct i40e_filter_control_settings *settings)
3194{
3195 i40e_status ret = 0;
3196 u32 hash_lut_size = 0;
3197 u32 val;
3198
3199 if (!settings)
3200 return I40E_ERR_PARAM;
3201
3202 /* Validate the input settings */
3203 ret = i40e_validate_filter_settings(hw, settings);
3204 if (ret)
3205 return ret;
3206
3207 /* Read the PF Queue Filter control register */
3208 val = rd32(hw, I40E_PFQF_CTL_0);
3209
3210 /* Program required PE hash buckets for the PF */
3211 val &= ~I40E_PFQF_CTL_0_PEHSIZE_MASK;
3212 val |= ((u32)settings->pe_filt_num << I40E_PFQF_CTL_0_PEHSIZE_SHIFT) &
3213 I40E_PFQF_CTL_0_PEHSIZE_MASK;
3214 /* Program required PE contexts for the PF */
3215 val &= ~I40E_PFQF_CTL_0_PEDSIZE_MASK;
3216 val |= ((u32)settings->pe_cntx_num << I40E_PFQF_CTL_0_PEDSIZE_SHIFT) &
3217 I40E_PFQF_CTL_0_PEDSIZE_MASK;
3218
3219 /* Program required FCoE hash buckets for the PF */
3220 val &= ~I40E_PFQF_CTL_0_PFFCHSIZE_MASK;
3221 val |= ((u32)settings->fcoe_filt_num <<
3222 I40E_PFQF_CTL_0_PFFCHSIZE_SHIFT) &
3223 I40E_PFQF_CTL_0_PFFCHSIZE_MASK;
3224 /* Program required FCoE DDP contexts for the PF */
3225 val &= ~I40E_PFQF_CTL_0_PFFCDSIZE_MASK;
3226 val |= ((u32)settings->fcoe_cntx_num <<
3227 I40E_PFQF_CTL_0_PFFCDSIZE_SHIFT) &
3228 I40E_PFQF_CTL_0_PFFCDSIZE_MASK;
3229
3230 /* Program Hash LUT size for the PF */
3231 val &= ~I40E_PFQF_CTL_0_HASHLUTSIZE_MASK;
3232 if (settings->hash_lut_size == I40E_HASH_LUT_SIZE_512)
3233 hash_lut_size = 1;
3234 val |= (hash_lut_size << I40E_PFQF_CTL_0_HASHLUTSIZE_SHIFT) &
3235 I40E_PFQF_CTL_0_HASHLUTSIZE_MASK;
3236
3237 /* Enable FDIR, Ethertype and MACVLAN filters for PF and VFs */
3238 if (settings->enable_fdir)
3239 val |= I40E_PFQF_CTL_0_FD_ENA_MASK;
3240 if (settings->enable_ethtype)
3241 val |= I40E_PFQF_CTL_0_ETYPE_ENA_MASK;
3242 if (settings->enable_macvlan)
3243 val |= I40E_PFQF_CTL_0_MACVLAN_ENA_MASK;
3244
3245 wr32(hw, I40E_PFQF_CTL_0, val);
3246
3247 return 0;
3248}
Neerav Parikhafb3ff02014-01-17 15:36:36 -08003249
3250/**
3251 * i40e_aq_add_rem_control_packet_filter - Add or Remove Control Packet Filter
3252 * @hw: pointer to the hw struct
3253 * @mac_addr: MAC address to use in the filter
3254 * @ethtype: Ethertype to use in the filter
3255 * @flags: Flags that needs to be applied to the filter
3256 * @vsi_seid: seid of the control VSI
3257 * @queue: VSI queue number to send the packet to
3258 * @is_add: Add control packet filter if True else remove
3259 * @stats: Structure to hold information on control filter counts
3260 * @cmd_details: pointer to command details structure or NULL
3261 *
3262 * This command will Add or Remove control packet filter for a control VSI.
3263 * In return it will update the total number of perfect filter count in
3264 * the stats member.
3265 **/
3266i40e_status i40e_aq_add_rem_control_packet_filter(struct i40e_hw *hw,
3267 u8 *mac_addr, u16 ethtype, u16 flags,
3268 u16 vsi_seid, u16 queue, bool is_add,
3269 struct i40e_control_filter_stats *stats,
3270 struct i40e_asq_cmd_details *cmd_details)
3271{
3272 struct i40e_aq_desc desc;
3273 struct i40e_aqc_add_remove_control_packet_filter *cmd =
3274 (struct i40e_aqc_add_remove_control_packet_filter *)
3275 &desc.params.raw;
3276 struct i40e_aqc_add_remove_control_packet_filter_completion *resp =
3277 (struct i40e_aqc_add_remove_control_packet_filter_completion *)
3278 &desc.params.raw;
3279 i40e_status status;
3280
3281 if (vsi_seid == 0)
3282 return I40E_ERR_PARAM;
3283
3284 if (is_add) {
3285 i40e_fill_default_direct_cmd_desc(&desc,
3286 i40e_aqc_opc_add_control_packet_filter);
3287 cmd->queue = cpu_to_le16(queue);
3288 } else {
3289 i40e_fill_default_direct_cmd_desc(&desc,
3290 i40e_aqc_opc_remove_control_packet_filter);
3291 }
3292
3293 if (mac_addr)
3294 memcpy(cmd->mac, mac_addr, ETH_ALEN);
3295
3296 cmd->etype = cpu_to_le16(ethtype);
3297 cmd->flags = cpu_to_le16(flags);
3298 cmd->seid = cpu_to_le16(vsi_seid);
3299
3300 status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
3301
3302 if (!status && stats) {
3303 stats->mac_etype_used = le16_to_cpu(resp->mac_etype_used);
3304 stats->etype_used = le16_to_cpu(resp->etype_used);
3305 stats->mac_etype_free = le16_to_cpu(resp->mac_etype_free);
3306 stats->etype_free = le16_to_cpu(resp->etype_free);
3307 }
3308
3309 return status;
3310}
3311
Catherine Sullivand4dfb812013-11-28 06:39:21 +00003312/**
Neerav Parikh2fd75f32014-11-12 00:18:20 +00003313 * i40e_aq_resume_port_tx
3314 * @hw: pointer to the hardware structure
3315 * @cmd_details: pointer to command details structure or NULL
3316 *
3317 * Resume port's Tx traffic
3318 **/
3319i40e_status i40e_aq_resume_port_tx(struct i40e_hw *hw,
3320 struct i40e_asq_cmd_details *cmd_details)
3321{
3322 struct i40e_aq_desc desc;
3323 i40e_status status;
3324
3325 i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_resume_port_tx);
3326
3327 status = i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details);
3328
3329 return status;
3330}
3331
3332/**
Catherine Sullivand4dfb812013-11-28 06:39:21 +00003333 * i40e_set_pci_config_data - store PCI bus info
3334 * @hw: pointer to hardware structure
3335 * @link_status: the link status word from PCI config space
3336 *
3337 * Stores the PCI bus info (speed, width, type) within the i40e_hw structure
3338 **/
3339void i40e_set_pci_config_data(struct i40e_hw *hw, u16 link_status)
3340{
3341 hw->bus.type = i40e_bus_type_pci_express;
3342
3343 switch (link_status & PCI_EXP_LNKSTA_NLW) {
3344 case PCI_EXP_LNKSTA_NLW_X1:
3345 hw->bus.width = i40e_bus_width_pcie_x1;
3346 break;
3347 case PCI_EXP_LNKSTA_NLW_X2:
3348 hw->bus.width = i40e_bus_width_pcie_x2;
3349 break;
3350 case PCI_EXP_LNKSTA_NLW_X4:
3351 hw->bus.width = i40e_bus_width_pcie_x4;
3352 break;
3353 case PCI_EXP_LNKSTA_NLW_X8:
3354 hw->bus.width = i40e_bus_width_pcie_x8;
3355 break;
3356 default:
3357 hw->bus.width = i40e_bus_width_unknown;
3358 break;
3359 }
3360
3361 switch (link_status & PCI_EXP_LNKSTA_CLS) {
3362 case PCI_EXP_LNKSTA_CLS_2_5GB:
3363 hw->bus.speed = i40e_bus_speed_2500;
3364 break;
3365 case PCI_EXP_LNKSTA_CLS_5_0GB:
3366 hw->bus.speed = i40e_bus_speed_5000;
3367 break;
3368 case PCI_EXP_LNKSTA_CLS_8_0GB:
3369 hw->bus.speed = i40e_bus_speed_8000;
3370 break;
3371 default:
3372 hw->bus.speed = i40e_bus_speed_unknown;
3373 break;
3374 }
3375}