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